cgen: fixed array index for translated code

pull/13938/head
Alexander Medvednikov 2022-04-04 12:09:17 +03:00
parent 725b472d37
commit 92bfd9b353
2 changed files with 3 additions and 2 deletions

View File

@ -189,6 +189,7 @@ fn (mut g Gen) gen_assign_stmt(node_ ast.AssignStmt) {
is_fixed_array_var := unaliased_right_sym.kind == .array_fixed && val !is ast.ArrayInit
&& (val in [ast.Ident, ast.IndexExpr, ast.CallExpr, ast.SelectorExpr]
|| (val is ast.CastExpr && (val as ast.CastExpr).expr !is ast.ArrayInit))
&& !g.pref.translated
g.is_assign_lhs = true
g.assign_op = node.op
if val_type.has_flag(.optional) {
@ -403,7 +404,7 @@ fn (mut g Gen) gen_assign_stmt(node_ ast.AssignStmt) {
}
g.is_shared = var_type.has_flag(.shared_f)
if !cloned {
if is_fixed_array_var && !g.pref.translated {
if is_fixed_array_var {
// TODO Instead of the translated check, check if it's a pointer already
// and don't generate memcpy &
typ_str := g.typ(val_type).trim('*')

View File

@ -336,7 +336,7 @@ fn (mut g Gen) index_of_fixed_array(node ast.IndexExpr, sym ast.TypeSymbol) {
}
g.write('[')
direct := g.fn_decl != 0 && g.fn_decl.is_direct_arr
if direct || node.index is ast.IntegerLiteral {
if (direct || node.index is ast.IntegerLiteral) || g.pref.translated {
g.expr(node.index)
} else {
// bounds check