From 5815ab8d00d30ce067910ea3c7abfd59891868c4 Mon Sep 17 00:00:00 2001 From: yuyi Date: Mon, 21 Mar 2022 19:10:10 +0800 Subject: [PATCH] cgen: minor cleanup in index.v (#13788) --- vlib/v/gen/c/index.v | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/vlib/v/gen/c/index.v b/vlib/v/gen/c/index.v index b5027b68f0..85e6eca85b 100644 --- a/vlib/v/gen/c/index.v +++ b/vlib/v/gen/c/index.v @@ -166,14 +166,14 @@ fn (mut g Gen) index_of_array(node ast.IndexExpr, sym ast.TypeSymbol) { info := sym.info as ast.Array elem_type_str := g.typ(info.elem_type) elem_type := info.elem_type - elem_typ := g.table.sym(elem_type) + elem_sym := g.table.sym(elem_type) // `vals[i].field = x` is an exception and requires `array_get`: // `(*(Val*)array_get(vals, i)).field = x;` is_selector := node.left is ast.SelectorExpr if g.is_assign_lhs && !is_selector && node.is_setter { is_direct_array_access := (g.fn_decl != 0 && g.fn_decl.is_direct_arr) || node.is_direct is_op_assign := g.assign_op != .assign && info.elem_type != ast.string_type - array_ptr_type_str := match elem_typ.kind { + array_ptr_type_str := match elem_sym.kind { .function { 'voidptr*' } else { '$elem_type_str*' } } @@ -224,7 +224,7 @@ fn (mut g Gen) index_of_array(node ast.IndexExpr, sym ast.TypeSymbol) { } */ if need_wrapper { - if elem_typ.kind == .function { + if elem_sym.kind == .function { g.write(', &(voidptr[]) { ') } else { g.write(', &($elem_type_str[]) { ') @@ -239,7 +239,7 @@ fn (mut g Gen) index_of_array(node ast.IndexExpr, sym ast.TypeSymbol) { } } else { is_direct_array_access := (g.fn_decl != 0 && g.fn_decl.is_direct_arr) || node.is_direct - array_ptr_type_str := match elem_typ.kind { + array_ptr_type_str := match elem_sym.kind { .function { 'voidptr*' } else { '$elem_type_str*' } } @@ -263,10 +263,10 @@ fn (mut g Gen) index_of_array(node ast.IndexExpr, sym ast.TypeSymbol) { g.write('/*2*/string_clone(') } if g.is_fn_index_call { - if elem_typ.info is ast.FnType { + if elem_sym.info is ast.FnType { g.write('((') - g.write_fn_ptr_decl(&elem_typ.info, '') - g.write(')(*($array_ptr_type_str)/*ee elem_typ */array_get(') + g.write_fn_ptr_decl(&elem_sym.info, '') + g.write(')(*($array_ptr_type_str)/*ee elem_sym */array_get(') } if left_is_ptr && !node.left_type.has_flag(.shared_f) { g.write('*') @@ -274,7 +274,7 @@ fn (mut g Gen) index_of_array(node ast.IndexExpr, sym ast.TypeSymbol) { } else if is_direct_array_access { g.write('(($array_ptr_type_str)') } else { - g.write('(*($array_ptr_type_str)/*ee elem_typ */array_get(') + g.write('(*($array_ptr_type_str)/*ee elem_sym */array_get(') if left_is_ptr && !node.left_type.has_flag(.shared_f) { g.write('*') } @@ -366,11 +366,11 @@ fn (mut g Gen) index_of_map(node ast.IndexExpr, sym ast.TypeSymbol) { key_type_str := g.typ(info.key_type) elem_type := info.value_type mut elem_type_str := g.typ(elem_type) - elem_typ := g.table.sym(elem_type) - if elem_typ.kind == .function { + elem_sym := g.table.sym(elem_type) + if elem_sym.kind == .function { elem_type_str = 'voidptr' } - get_and_set_types := elem_typ.kind in [.struct_, .map] + get_and_set_types := elem_sym.kind in [.struct_, .map] if g.is_assign_lhs && !g.is_arraymap_set && !get_and_set_types { if g.assign_op == .assign || info.value_type == ast.string_type { g.is_arraymap_set = true @@ -444,9 +444,9 @@ fn (mut g Gen) index_of_map(node ast.IndexExpr, sym ast.TypeSymbol) { g.write('$elem_type_str* $tmp_opt_ptr = ($elem_type_str*)/*ee elem_ptr_typ */(map_get_check(') } else { if g.is_fn_index_call { - if elem_typ.info is ast.FnType { + if elem_sym.info is ast.FnType { g.write('((') - g.write_fn_ptr_decl(&elem_typ.info, '') + g.write_fn_ptr_decl(&elem_sym.info, '') g.write(')(*(voidptr*)map_get(') } } else {