From 2a9cbbe1579fd35f116a44b1cd9da2a5112c120e Mon Sep 17 00:00:00 2001 From: wilesun Date: Thu, 14 May 2020 23:14:59 +0800 Subject: [PATCH] cgen: handle sizeof(C.struct) --- vlib/v/gen/cgen.v | 8 ++++++++ vlib/v/parser/pratt.v | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index c30f3f3694..6e7cb157a0 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -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__') { diff --git a/vlib/v/parser/pratt.v b/vlib/v/parser/pratt.v index abcbfc1406..4001c093c9 100644 --- a/vlib/v/parser/pratt.v +++ b/vlib/v/parser/pratt.v @@ -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 }