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,7 +159,10 @@ pub fn (g mut Gen) typ(t table.Type) string {
if styp.starts_with('C__') {
styp = styp[3..]
if sym.kind == .struct_ {
styp = 'struct $styp'
info := sym.info as table.Struct
if !info.is_typedef {
styp = 'struct $styp'
}
}
}
if table.type_is(t, .optional) {

View File

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

View File

@ -3,7 +3,7 @@
// that can be found in the LICENSE file.
//
// Type layout information (32 bits)
// flag (8 bits) | nr_muls (8 bits) | idx (16 bits)
// flag (8 bits) | nr_muls (8 bits) | idx (16 bits)
// pack: (int(flag)<<24) | (nr_muls<<16) | u16(idx)
// unpack:
// flag: (int(type)>>24) & 0xff
@ -18,7 +18,7 @@ import (
pub type Type int
pub type TypeInfo = Array | ArrayFixed | Map | Struct |
pub type TypeInfo = Array | ArrayFixed | Map | Struct |
MultiReturn | Alias | Enum | SumType | FnType
pub struct TypeSymbol {
@ -539,6 +539,7 @@ pub fn (kinds []Kind) str() string {
pub struct Struct {
pub mut:
fields []Field
is_typedef bool // C. [typedef]
}
pub struct Enum {