parent
9133671436
commit
bf15ed95af
|
@ -5449,9 +5449,13 @@ fn (mut g Gen) size_of(node ast.SizeOf) {
|
|||
if sym.language == .v && sym.kind in [.placeholder, .any] {
|
||||
g.error('unknown type `$sym.name`', node.pos)
|
||||
}
|
||||
if node.expr is ast.StringLiteral {
|
||||
g.write('sizeof("$node.expr.val")')
|
||||
} else {
|
||||
styp := g.typ(node_typ)
|
||||
g.write('sizeof(${util.no_dots(styp)})')
|
||||
}
|
||||
}
|
||||
|
||||
fn (mut g Gen) enum_val(node ast.EnumVal) {
|
||||
// g.write('${it.mod}${it.enum_name}_$it.val')
|
||||
|
|
|
@ -202,12 +202,17 @@ pub fn (mut p Parser) check_expr(precedence int) ?ast.Expr {
|
|||
p.next() // sizeof
|
||||
p.check(.lpar)
|
||||
pos := p.tok.pos()
|
||||
is_known_var := p.mark_var_as_used(p.tok.lit)
|
||||
mut is_known_var := p.mark_var_as_used(p.tok.lit)
|
||||
|| p.table.global_scope.known_const(p.mod + '.' + p.tok.lit)
|
||||
//|| p.table.known_fn(p.mod + '.' + p.tok.lit)
|
||||
// assume `mod.` prefix leads to a type
|
||||
is_type := p.known_import(p.tok.lit) || p.tok.kind.is_start_of_type()
|
||||
mut is_type := p.known_import(p.tok.lit) || p.tok.kind.is_start_of_type()
|
||||
|| (p.tok.lit.len > 0 && p.tok.lit[0].is_capital())
|
||||
|
||||
if p.tok.lit in ['c', 'r'] && p.peek_tok.kind == .string {
|
||||
is_known_var = false
|
||||
is_type = false
|
||||
}
|
||||
if is_known_var || !is_type {
|
||||
expr := p.expr(0)
|
||||
if is_reftype {
|
||||
|
|
|
@ -23,4 +23,7 @@ fn test_sizeof() {
|
|||
s := S2{}
|
||||
assert sizeof(s.i) == 4
|
||||
assert sizeof(flag.Flag) > 4
|
||||
|
||||
assert sizeof(c'hello') == 6
|
||||
assert sizeof(r'hello') == 6
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue