1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: handle C typedefs

This commit is contained in:
Alexander Medvednikov 2020-04-04 14:32:42 +02:00
parent 440f1cf4c6
commit 95a1bd8470
3 changed files with 9 additions and 3 deletions

View File

@ -159,9 +159,12 @@ pub fn (g mut Gen) typ(t table.Type) string {
if styp.starts_with('C__') { if styp.starts_with('C__') {
styp = styp[3..] styp = styp[3..]
if sym.kind == .struct_ { if sym.kind == .struct_ {
info := sym.info as table.Struct
if !info.is_typedef {
styp = 'struct $styp' styp = 'struct $styp'
} }
} }
}
if table.type_is(t, .optional) { if table.type_is(t, .optional) {
styp = 'Option_' + styp styp = 'Option_' + styp
if !(styp in g.optionals) { if !(styp in g.optionals) {

View File

@ -1475,6 +1475,7 @@ fn (p mut Parser) struct_decl() ast.StructDecl {
p.next() // C p.next() // C
p.next() // . p.next() // .
} }
is_typedef := p.attr == 'typedef'
mut name := p.check_name() mut name := p.check_name()
mut default_exprs := []ast.Expr mut default_exprs := []ast.Expr
// println('struct decl $name') // println('struct decl $name')
@ -1544,6 +1545,7 @@ fn (p mut Parser) struct_decl() ast.StructDecl {
name: name name: name
info: table.Struct{ info: table.Struct{
fields: fields fields: fields
is_typedef: is_typedef
} }
} }
mut ret := 0 mut ret := 0

View File

@ -539,6 +539,7 @@ pub fn (kinds []Kind) str() string {
pub struct Struct { pub struct Struct {
pub mut: pub mut:
fields []Field fields []Field
is_typedef bool // C. [typedef]
} }
pub struct Enum { pub struct Enum {