cgen: handle sizeof(C.struct)

pull/4895/head
wilesun 2020-05-14 23:14:59 +08:00 committed by GitHub
parent 6d0b791ac8
commit 2a9cbbe157
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -1264,6 +1264,14 @@ fn (mut g Gen) expr(node ast.Expr) {
mut styp := it.type_name mut styp := it.type_name
if it.type_name == '' { if it.type_name == '' {
styp = g.typ(it.typ) styp = g.typ(it.typ)
} else {
sym := g.table.get_type_symbol(it.typ)
if sym.kind == .struct_ {
info := sym.info as table.Struct
if !info.is_typedef {
styp = 'struct ' + styp
}
}
} }
/* /*
if styp.starts_with('C__') { if styp.starts_with('C__') {

View File

@ -76,14 +76,15 @@ pub fn (mut p Parser) expr(precedence int) ast.Expr {
.key_sizeof { .key_sizeof {
p.next() // sizeof p.next() // sizeof
p.check(.lpar) p.check(.lpar)
sizeof_type := p.parse_type()
if p.tok.lit == 'C' { if p.tok.lit == 'C' {
p.next() p.next()
p.check(.dot) p.check(.dot)
node = ast.SizeOf{ node = ast.SizeOf{
type_name: p.check_name() type_name: p.check_name()
typ: sizeof_type
} }
} else { } else {
sizeof_type := p.parse_type()
node = ast.SizeOf{ node = ast.SizeOf{
typ: sizeof_type typ: sizeof_type
} }