cgen: simplify struct_init()
parent
78efe72c4c
commit
6ff93f270c
|
@ -2121,15 +2121,7 @@ fn (mut g Gen) const_decl_init_later(name, val string, typ table.Type) {
|
|||
}
|
||||
|
||||
fn (mut g Gen) struct_init(struct_init ast.StructInit) {
|
||||
mut info := &table.Struct{}
|
||||
mut is_struct := false
|
||||
sym := g.table.get_type_symbol(struct_init.typ)
|
||||
if sym.kind == .struct_ {
|
||||
is_struct = true
|
||||
info = sym.info as table.Struct
|
||||
}
|
||||
// info := g.table.get_type_symbol(it.typ).info as table.Struct
|
||||
// println(info.fields.len)
|
||||
styp := g.typ(struct_init.typ)
|
||||
is_amp := g.is_amp
|
||||
if is_amp {
|
||||
|
@ -2159,7 +2151,8 @@ fn (mut g Gen) struct_init(struct_init ast.StructInit) {
|
|||
g.writeln(',')
|
||||
}
|
||||
// The rest of the fields are zeroed.
|
||||
if is_struct {
|
||||
if sym.kind == .struct_ {
|
||||
info := sym.info as table.Struct
|
||||
for field in info.fields {
|
||||
if field.name in inited_fields {
|
||||
continue
|
||||
|
@ -2177,10 +2170,10 @@ fn (mut g Gen) struct_init(struct_init ast.StructInit) {
|
|||
}
|
||||
g.writeln(',')
|
||||
}
|
||||
}
|
||||
if struct_init.fields.len == 0 && info.fields.len == 0 {
|
||||
g.write('0')
|
||||
}
|
||||
}
|
||||
g.write('}')
|
||||
if is_amp {
|
||||
g.write(', sizeof($styp))')
|
||||
|
@ -2539,11 +2532,7 @@ fn (mut g Gen) string_inter_literal(node ast.StringInterLiteral) {
|
|||
g.write('\\000')
|
||||
}
|
||||
}
|
||||
num_string_parts := if end_string {
|
||||
node.exprs.len+1
|
||||
} else {
|
||||
node.exprs.len
|
||||
}
|
||||
num_string_parts := if end_string { node.exprs.len + 1 } else { node.exprs.len }
|
||||
g.write('", $num_string_parts, ')
|
||||
// Build args
|
||||
for i, expr in node.exprs {
|
||||
|
|
|
@ -188,10 +188,12 @@ fn (mut g Gen) write_autofree_stmts_when_needed(r ast.Return) {
|
|||
// TODO: write_autofree_stmts_when_needed should not free the returned variables.
|
||||
// It may require rewriting g.return_statement to assign the expressions
|
||||
// to temporary variables, then protecting *them* from autofreeing ...
|
||||
/*
|
||||
g.writeln('/* autofreeings before return: -------')
|
||||
//g.write( g.autofree_scope_vars(r.pos.pos) )
|
||||
g.write( g.autofree_scope_vars(g.fn_decl.body_pos.pos) )
|
||||
g.writeln('--------------------------------------------------- */')
|
||||
*/
|
||||
}
|
||||
|
||||
fn (mut g Gen) write_defer_stmts_when_needed() {
|
||||
|
|
Loading…
Reference in New Issue