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(', ')
xspace := ''
mut xspace := ''
if option_names.len > space.len-2 {
xspace = '\n${space}'
} else {

View File

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