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:
parent
440f1cf4c6
commit
95a1bd8470
|
@ -159,7 +159,10 @@ 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_ {
|
||||||
styp = 'struct $styp'
|
info := sym.info as table.Struct
|
||||||
|
if !info.is_typedef {
|
||||||
|
styp = 'struct $styp'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if table.type_is(t, .optional) {
|
if table.type_is(t, .optional) {
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
// that can be found in the LICENSE file.
|
// that can be found in the LICENSE file.
|
||||||
//
|
//
|
||||||
// Type layout information (32 bits)
|
// 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)
|
// pack: (int(flag)<<24) | (nr_muls<<16) | u16(idx)
|
||||||
// unpack:
|
// unpack:
|
||||||
// flag: (int(type)>>24) & 0xff
|
// flag: (int(type)>>24) & 0xff
|
||||||
|
@ -18,7 +18,7 @@ import (
|
||||||
|
|
||||||
pub type Type int
|
pub type Type int
|
||||||
|
|
||||||
pub type TypeInfo = Array | ArrayFixed | Map | Struct |
|
pub type TypeInfo = Array | ArrayFixed | Map | Struct |
|
||||||
MultiReturn | Alias | Enum | SumType | FnType
|
MultiReturn | Alias | Enum | SumType | FnType
|
||||||
|
|
||||||
pub struct TypeSymbol {
|
pub struct TypeSymbol {
|
||||||
|
@ -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 {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user