Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cgen: cleanup in struct_init_field() #19259

Merged
merged 1 commit into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions vlib/v/gen/c/array.v
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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