parent
81bb1ea71f
commit
5815ab8d00
|
@ -166,14 +166,14 @@ fn (mut g Gen) index_of_array(node ast.IndexExpr, sym ast.TypeSymbol) {
|
||||||
info := sym.info as ast.Array
|
info := sym.info as ast.Array
|
||||||
elem_type_str := g.typ(info.elem_type)
|
elem_type_str := g.typ(info.elem_type)
|
||||||
elem_type := 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`:
|
// `vals[i].field = x` is an exception and requires `array_get`:
|
||||||
// `(*(Val*)array_get(vals, i)).field = x;`
|
// `(*(Val*)array_get(vals, i)).field = x;`
|
||||||
is_selector := node.left is ast.SelectorExpr
|
is_selector := node.left is ast.SelectorExpr
|
||||||
if g.is_assign_lhs && !is_selector && node.is_setter {
|
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_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
|
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*' }
|
.function { 'voidptr*' }
|
||||||
else { '$elem_type_str*' }
|
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 need_wrapper {
|
||||||
if elem_typ.kind == .function {
|
if elem_sym.kind == .function {
|
||||||
g.write(', &(voidptr[]) { ')
|
g.write(', &(voidptr[]) { ')
|
||||||
} else {
|
} else {
|
||||||
g.write(', &($elem_type_str[]) { ')
|
g.write(', &($elem_type_str[]) { ')
|
||||||
|
@ -239,7 +239,7 @@ fn (mut g Gen) index_of_array(node ast.IndexExpr, sym ast.TypeSymbol) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
is_direct_array_access := (g.fn_decl != 0 && g.fn_decl.is_direct_arr) || node.is_direct
|
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*' }
|
.function { 'voidptr*' }
|
||||||
else { '$elem_type_str*' }
|
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(')
|
g.write('/*2*/string_clone(')
|
||||||
}
|
}
|
||||||
if g.is_fn_index_call {
|
if g.is_fn_index_call {
|
||||||
if elem_typ.info is ast.FnType {
|
if elem_sym.info is ast.FnType {
|
||||||
g.write('((')
|
g.write('((')
|
||||||
g.write_fn_ptr_decl(&elem_typ.info, '')
|
g.write_fn_ptr_decl(&elem_sym.info, '')
|
||||||
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) {
|
if left_is_ptr && !node.left_type.has_flag(.shared_f) {
|
||||||
g.write('*')
|
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 {
|
} else if is_direct_array_access {
|
||||||
g.write('(($array_ptr_type_str)')
|
g.write('(($array_ptr_type_str)')
|
||||||
} else {
|
} 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) {
|
if left_is_ptr && !node.left_type.has_flag(.shared_f) {
|
||||||
g.write('*')
|
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)
|
key_type_str := g.typ(info.key_type)
|
||||||
elem_type := info.value_type
|
elem_type := info.value_type
|
||||||
mut elem_type_str := g.typ(elem_type)
|
mut elem_type_str := g.typ(elem_type)
|
||||||
elem_typ := g.table.sym(elem_type)
|
elem_sym := g.table.sym(elem_type)
|
||||||
if elem_typ.kind == .function {
|
if elem_sym.kind == .function {
|
||||||
elem_type_str = 'voidptr'
|
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.is_assign_lhs && !g.is_arraymap_set && !get_and_set_types {
|
||||||
if g.assign_op == .assign || info.value_type == ast.string_type {
|
if g.assign_op == .assign || info.value_type == ast.string_type {
|
||||||
g.is_arraymap_set = true
|
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(')
|
g.write('$elem_type_str* $tmp_opt_ptr = ($elem_type_str*)/*ee elem_ptr_typ */(map_get_check(')
|
||||||
} else {
|
} else {
|
||||||
if g.is_fn_index_call {
|
if g.is_fn_index_call {
|
||||||
if elem_typ.info is ast.FnType {
|
if elem_sym.info is ast.FnType {
|
||||||
g.write('((')
|
g.write('((')
|
||||||
g.write_fn_ptr_decl(&elem_typ.info, '')
|
g.write_fn_ptr_decl(&elem_sym.info, '')
|
||||||
g.write(')(*(voidptr*)map_get(')
|
g.write(')(*(voidptr*)map_get(')
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue