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

cgen: handle sizeof(C.struct)

This commit is contained in:
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
if it.type_name == '' {
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__') {

View File

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