cgen: fix sizeof(&int)

pull/4349/head
Alexander Medvednikov 2020-04-11 16:24:21 +02:00
parent 61c1535199
commit 63d747042e
2 changed files with 5 additions and 8 deletions

View File

@ -447,7 +447,7 @@ pub fn (fs FlagParser) usage() string {
} }
} }
option_names := ' ' + onames.join(', ') option_names := ' ' + onames.join(', ')
xspace := '' mut xspace := ''
if option_names.len > space.len-2 { if option_names.len > space.len-2 {
xspace = '\n${space}' xspace = '\n${space}'
} else { } else {

View File

@ -1111,10 +1111,8 @@ fn (g mut Gen) expr(node ast.Expr) {
g.match_expr(it) g.match_expr(it)
} }
ast.MapInit { ast.MapInit {
key_typ_sym := g.table.get_type_symbol(it.key_type) key_typ_str := g.typ(it.key_type)
value_typ_sym := g.table.get_type_symbol(it.value_type) value_typ_str := g.typ(it.value_type)
key_typ_str := key_typ_sym.name.replace('.', '__')
value_typ_str := value_typ_sym.name.replace('.', '__')
size := it.vals.len size := it.vals.len
if size > 0 { if size > 0 {
g.write('new_map_init($size, sizeof($value_typ_str), (${key_typ_str}[$size]){') g.write('new_map_init($size, sizeof($value_typ_str), (${key_typ_str}[$size]){')
@ -1160,7 +1158,7 @@ fn (g mut Gen) expr(node ast.Expr) {
g.write('sizeof($it.type_name)') g.write('sizeof($it.type_name)')
} else { } else {
styp := g.typ(it.typ) styp := g.typ(it.typ)
g.write('sizeof($styp)') g.write('sizeof(/*typ*/$styp)')
} }
} }
ast.StringLiteral { ast.StringLiteral {
@ -2863,8 +2861,7 @@ fn (g Gen) type_default(typ table.Type) string {
return 'new_array(0, 1, sizeof($elem_type_str))' return 'new_array(0, 1, sizeof($elem_type_str))'
} }
if sym.kind == .map { if sym.kind == .map {
value_sym := g.table.get_type_symbol(sym.map_info().value_type) value_type_str := g.typ(sym.map_info().value_type)
value_type_str := value_sym.name.replace('.', '__')
return 'new_map(1, sizeof($value_type_str))' return 'new_map(1, sizeof($value_type_str))'
} }
// Always set pointers to 0 // Always set pointers to 0