Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Nov 25, 2024
1 parent 0ce4ebb commit d3a164d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
13 changes: 7 additions & 6 deletions vlib/v/gen/c/cgen.v
Original file line number Diff line number Diff line change
Expand Up @@ -1648,12 +1648,13 @@ pub fn (mut g Gen) write_alias_typesymbol_declaration(sym ast.TypeSymbol) {

mut parent_elem_info := parent_sym.info as ast.ArrayFixed
mut parent_elem_styp := g.styp(sym.info.parent_type)
mut out := ''
mut out := strings.new_builder(50)
for {
if mut elem_sym.info is ast.ArrayFixed {
out =
'typedef ${elem_sym.cname} ${parent_elem_styp} [${parent_elem_info.size}]; //\n' +
out
old := out.str()
out.clear()
out.writeln('typedef ${elem_sym.cname} ${parent_elem_styp} [${parent_elem_info.size}];')
out.writeln(old)
parent_elem_styp = elem_sym.cname
parent_elem_info = elem_sym.info as ast.ArrayFixed
elem_sym = g.table.sym(elem_sym.info.elem_type)
Expand All @@ -1662,8 +1663,8 @@ pub fn (mut g Gen) write_alias_typesymbol_declaration(sym ast.TypeSymbol) {
break
}
}
if out != '' {
g.type_definitions.writeln(out)
if out.len != 0 {
g.type_definitions.writeln(out.str())
}
}
}
Expand Down
20 changes: 11 additions & 9 deletions vlib/v/gen/c/struct.v
Original file line number Diff line number Diff line change
Expand Up @@ -305,16 +305,18 @@ fn (mut g Gen) struct_init(node ast.StructInit) {
g.write('.${field_name} = ')
if is_update_tmp_var {
g.write(tmp_update_var)
} else if g.table.final_sym(field.typ).kind == .array_fixed {
is_arr_fixed = true
arr_info := g.table.final_sym(field.typ).array_fixed_info()
g.fixed_array_update_expr_field(g.expr_string(node.update_expr), node.update_expr_type,
field.name, node.update_expr.is_auto_deref_var(), arr_info.elem_type,
arr_info.size)
} else {
g.write('(')
g.expr(node.update_expr)
g.write(')')
update_expr_sym := g.table.final_sym(field.typ)
if update_expr_sym.info is ast.ArrayFixed {
is_arr_fixed = true
g.fixed_array_update_expr_field(g.expr_string(node.update_expr),
node.update_expr_type, field.name, node.update_expr.is_auto_deref_var(),
update_expr_sym.info.elem_type, update_expr_sym.info.size)
} else {
g.write('(')
g.expr(node.update_expr)
g.write(')')
}
}
if !is_arr_fixed {
if node.update_expr_type.is_ptr() {
Expand Down

0 comments on commit d3a164d

Please sign in to comment.