Skip to content

Commit

Permalink
cgen: refactor to streamline gen_map_method_call() (#22356)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 authored Oct 1, 2024
1 parent e598db1 commit d2c5b19
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions vlib/v/gen/c/fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,11 @@ fn (mut g Gen) gen_arg_from_type(node_type ast.Type, node ast.Expr) {
} else {
if node_type.is_ptr() {
g.expr(node)
} else if !node.is_lvalue()
|| (node is ast.Ident && g.table.is_interface_smartcast(node.obj)) {
g.write('ADDR(${g.typ(node_type)}, ')
g.expr(node)
g.write(')')
} else {
g.write('&')
g.expr(node)
Expand Down Expand Up @@ -1017,6 +1022,11 @@ fn (mut g Gen) gen_map_method_call(node ast.CallExpr, left_type ast.Type, left_s
g.expr(node.args[0].expr)
g.write('})')
}
'keys', 'values' {
g.write('map_${node.name}(')
g.gen_arg_from_type(left_type, node.left)
g.write(')')
}
else {
return false
}
Expand Down Expand Up @@ -1678,8 +1688,6 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
mut name := util.no_dots('${receiver_type_name}_${node.name}')
if left_sym.kind == .chan && node.name in ['close', 'try_pop', 'try_push'] {
name = 'sync__Channel_${node.name}'
} else if final_left_sym.kind == .map && node.name in ['keys', 'values'] {
name = 'map_${node.name}'
}
if g.pref.obfuscate && g.cur_mod.name == 'main' && name.starts_with('main__')
&& node.name != 'str' {
Expand Down

0 comments on commit d2c5b19

Please sign in to comment.