Skip to content

Commit

Permalink
cgen: cleanup in struct_init_field() (#19259)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 committed Sep 2, 2023
1 parent 5848610 commit a8d2a99
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
6 changes: 3 additions & 3 deletions vlib/v/gen/c/array.v
Expand Up @@ -1313,13 +1313,13 @@ fn (mut g Gen) write_prepared_it(inp_info ast.Array, inp_elem_type string, tmp s

fn (mut g Gen) fixed_array_var_init(expr ast.Expr, size int) {
g.write('{')
for idx in 0 .. size {
for i in 0 .. size {
if expr.is_auto_deref_var() {
g.write('*')
}
g.expr(expr)
g.write('[${idx}]')
if idx != size - 1 {
g.write('[${i}]')
if i != size - 1 {
g.write(', ')
}
}
Expand Down
14 changes: 3 additions & 11 deletions vlib/v/gen/c/struct.v
Expand Up @@ -556,17 +556,9 @@ fn (mut g Gen) struct_init_field(sfield ast.StructInitField, language ast.Langua
inside_cast_in_heap := g.inside_cast_in_heap
g.inside_cast_in_heap = 0 // prevent use of pointers in child structs

if field_type_sym.kind == .array_fixed && sfield.expr is ast.Ident {
fixed_array_info := field_type_sym.info as ast.ArrayFixed
g.write('{')
for i in 0 .. fixed_array_info.size {
g.expr(sfield.expr)
g.write('[${i}]')
if i != fixed_array_info.size - 1 {
g.write(', ')
}
}
g.write('}')
if field_type_sym.kind == .array_fixed && sfield.expr in [ast.Ident, ast.SelectorExpr] {
info := field_type_sym.info as ast.ArrayFixed
g.fixed_array_var_init(sfield.expr, info.size)
} else {
if sfield.typ != ast.voidptr_type && sfield.typ != ast.nil_type
&& (sfield.expected_type.is_ptr() && !sfield.expected_type.has_flag(.shared_f))
Expand Down

0 comments on commit a8d2a99

Please sign in to comment.