cgen/parser: fix unions
parent
cdcb8b6c06
commit
7ff0c3aaa9
|
@ -74,5 +74,5 @@ fn test_atof() {
|
|||
// DOUBLE_MINUS_ZERO
|
||||
f1=-0.0
|
||||
assert *ptr == u64(0x8000000000000000)
|
||||
//println("DONE!")
|
||||
println("DONE!")
|
||||
}
|
||||
|
|
|
@ -150,6 +150,7 @@ pub:
|
|||
pub_pos int // pub:
|
||||
pub_mut_pos int // pub mut:
|
||||
is_c bool
|
||||
is_union bool
|
||||
}
|
||||
|
||||
pub struct InterfaceDecl {
|
||||
|
|
|
@ -460,7 +460,12 @@ fn (g mut Gen) stmt(node ast.Stmt) {
|
|||
// g.writeln('\t$field_type_sym.name $field.name;')
|
||||
// }
|
||||
// g.writeln('} $name;')
|
||||
if !it.is_c {
|
||||
if it.is_c {
|
||||
return
|
||||
}
|
||||
if it.is_union {
|
||||
g.typedefs.writeln('typedef union $name $name;')
|
||||
} else {
|
||||
g.typedefs.writeln('typedef struct $name $name;')
|
||||
}
|
||||
}
|
||||
|
@ -2121,7 +2126,11 @@ fn (g mut Gen) write_types(types []table.TypeSymbol) {
|
|||
table.Struct {
|
||||
info := typ.info as table.Struct
|
||||
// g.definitions.writeln('typedef struct {')
|
||||
if info.is_union {
|
||||
g.definitions.writeln('union $name {')
|
||||
} else {
|
||||
g.definitions.writeln('struct $name {')
|
||||
}
|
||||
if info.fields.len > 0 {
|
||||
for field in info.fields {
|
||||
type_name := g.typ(field.typ)
|
||||
|
|
|
@ -1447,6 +1447,7 @@ fn (p mut Parser) struct_decl() ast.StructDecl {
|
|||
if is_pub {
|
||||
p.next()
|
||||
}
|
||||
is_union := p.tok.kind == .key_union
|
||||
if p.tok.kind == .key_struct {
|
||||
p.check(.key_struct)
|
||||
} else {
|
||||
|
@ -1535,6 +1536,7 @@ fn (p mut Parser) struct_decl() ast.StructDecl {
|
|||
info: table.Struct{
|
||||
fields: fields
|
||||
is_typedef: is_typedef
|
||||
is_union: is_union
|
||||
}
|
||||
}
|
||||
mut ret := 0
|
||||
|
@ -1558,6 +1560,7 @@ fn (p mut Parser) struct_decl() ast.StructDecl {
|
|||
pub_pos: pub_pos
|
||||
pub_mut_pos: pub_mut_pos
|
||||
is_c: is_c
|
||||
is_union: is_union
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -540,6 +540,7 @@ pub struct Struct {
|
|||
pub mut:
|
||||
fields []Field
|
||||
is_typedef bool // C. [typedef]
|
||||
is_union bool
|
||||
}
|
||||
|
||||
pub struct Enum {
|
||||
|
|
Loading…
Reference in New Issue