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: minor cleanup in method_call() #22351

Merged
merged 2 commits into from
Sep 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions vlib/v/gen/c/fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -1572,22 +1572,20 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
}
left_sym := g.table.sym(left_type)
final_left_sym := g.table.final_sym(left_type)
if left_sym.kind == .array || (final_left_sym.kind == .array
&& node.name in ['filter', 'map', 'sort', 'sorted', 'contains', 'any', 'all', 'insert', 'prepend']) {
if final_left_sym.kind == .array && !(left_sym.kind == .alias && left_sym.has_method(node.name)) {
if g.gen_array_method_call(node, left_type) {
return
}
} else if left_sym.kind == .array_fixed && node.name == 'wait' {
g.gen_fixed_array_wait(node)
return
}

if final_left_sym.kind == .map {
if final_left_sym.kind == .map && !(left_sym.kind == .alias && left_sym.has_method(node.name)) {
if g.gen_map_method_call(node, left_type, final_left_sym) {
return
}
}

if left_sym.kind == .array_fixed && node.name == 'wait' {
g.gen_fixed_array_wait(node)
return
}
if left_sym.kind in [.sum_type, .interface_] {
prefix_name := if left_sym.kind == .sum_type { 'sumtype' } else { 'interface' }
match node.name {
Expand Down Expand Up @@ -1627,12 +1625,10 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
receiver_type_name = g.resolve_receiver_name(node, unwrapped_rec_type, final_left_sym,
left_sym, typ_sym)
if final_left_sym.kind == .array && !(left_sym.kind == .alias && left_sym.has_method(node.name))
&& node.name in ['clear', 'repeat', 'sort_with_compare', 'sorted_with_compare', 'free', 'push_many', 'trim', 'first', 'last', 'pop', 'clone', 'reverse', 'slice', 'pointers'] {
if node.name in ['last', 'first', 'pop'] {
return_type_str := g.typ(node.return_type)
cast_n++
g.write('(*(${return_type_str}*)')
}
&& node.name in ['last', 'first', 'pop'] {
return_type_str := g.typ(node.return_type)
cast_n++
g.write('(*(${return_type_str}*)')
}
mut name := util.no_dots('${receiver_type_name}_${node.name}')
mut array_depth := -1
Expand Down
Loading