Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cgen: cleanup in array.v
Browse files Browse the repository at this point in the history
yuyi98 committed Nov 1, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 2c887e2 commit 136255a
Showing 1 changed file with 17 additions and 28 deletions.
45 changes: 17 additions & 28 deletions vlib/v/gen/c/array.v
Original file line number Diff line number Diff line change
@@ -1174,15 +1174,7 @@ fn (mut g Gen) gen_array_contains(left_type ast.Type, left ast.Expr, right_type
if g.table.sym(elem_typ).kind in [.interface, .sum_type] {
g.expr_with_cast(right, right_type, elem_typ)
} else if right is ast.ArrayInit {
if g.is_cc_msvc {
stmts := g.go_before_last_stmt().trim_space()
tmp_var := g.new_tmp_var()
g.write2('${g.styp(right_type)} ${tmp_var} = ${g.expr_string(right)};', stmts)
g.write(tmp_var)
} else {
g.write('(${g.styp(right.typ)})')
g.expr(right)
}
g.fixed_array_init_with_cast(right, right_type)
} else {
g.expr(right)
}
@@ -1329,16 +1321,7 @@ fn (mut g Gen) gen_array_index(node ast.CallExpr) {
if g.table.sym(elem_typ).kind in [.interface, .sum_type] {
g.expr_with_cast(node.args[0].expr, node.args[0].typ, elem_typ)
} else if node.args[0].expr is ast.ArrayInit {
if g.is_cc_msvc {
stmts := g.go_before_last_stmt().trim_space()
tmp_var := g.new_tmp_var()
g.write2('${g.styp(node.args[0].typ)} ${tmp_var} = ${g.expr_string(node.args[0].expr)};',
stmts)
g.write(tmp_var)
} else {
g.write('(${g.styp(node.args[0].typ)})')
g.expr(node.args[0].expr)
}
g.fixed_array_init_with_cast(node.args[0].expr, node.args[0].typ)
} else {
g.expr(node.args[0].expr)
}
@@ -1586,15 +1569,7 @@ fn (mut g Gen) write_prepared_tmp_value(tmp string, node &ast.CallExpr, tmp_styp
g.writeln('${left_styp} ${tmp}_orig;')
g.write('memcpy(&${tmp}_orig, &')
if node.left is ast.ArrayInit {
if g.is_cc_msvc {
stmts := g.go_before_last_stmt().trim_space()
tmp_var := g.new_tmp_var()
g.write2('${left_styp} ${tmp_var} = ${g.expr_string(node.left)};', stmts)
g.write(tmp_var)
} else {
g.write('(${left_styp})')
g.expr(node.left)
}
g.fixed_array_init_with_cast(node.left, node.left_type)
} else {
if !node.left_type.has_flag(.shared_f) && node.left_type.is_ptr() {
g.write('*')
@@ -1634,6 +1609,20 @@ fn (mut g Gen) write_prepared_var(var_name string, elem_type ast.Type, inp_elem_
}
}

fn (mut g Gen) fixed_array_init_with_cast(expr ast.ArrayInit, typ ast.Type) {
if g.is_cc_msvc {
stmts := g.go_before_last_stmt().trim_space()
tmp_var := g.new_tmp_var()
g.write('${g.styp(typ)} ${tmp_var} = ')
g.expr(expr)
g.writeln(';')
g.write2(stmts, tmp_var)
} else {
g.write('(${g.styp(typ)})')
g.expr(expr)
}
}

fn (mut g Gen) fixed_array_var_init(expr_str string, is_auto_deref bool, elem_type ast.Type, size int) {
elem_sym := g.table.sym(elem_type)
if !g.inside_array_fixed_struct {

0 comments on commit 136255a

Please sign in to comment.