ID/Stmt: Introduce INIT_SKIP and use in ForStmt

Currently, loop vars are added to a function scope's inits and
initialized upon entering a function with default values. This
applies to vector, record and table types.

This is unnecessary for variables used in for loops as they are
guaranteed to be initialized while iterating.
This commit is contained in:
Arne Welzel 2023-09-01 19:14:54 +02:00
parent aaa81cae5d
commit cea7c0ab46
7 changed files with 287 additions and 288 deletions

View file

@ -1263,7 +1263,7 @@ ForStmt::ForStmt(IDPList* arg_loop_vars, ExprPtr loop_expr)
else
{
add_local({NewRef{}, lv}, ind_type, INIT_NONE, nullptr, nullptr, VAR_REGULAR);
add_local({NewRef{}, lv}, ind_type, INIT_SKIP, nullptr, nullptr, VAR_REGULAR);
}
}
}
@ -1284,7 +1284,7 @@ ForStmt::ForStmt(IDPList* arg_loop_vars, ExprPtr loop_expr)
// nop
}
else if ( ! t )
add_local({NewRef{}, lv}, base_type(TYPE_COUNT), INIT_NONE, nullptr, nullptr,
add_local({NewRef{}, lv}, base_type(TYPE_COUNT), INIT_SKIP, nullptr, nullptr,
VAR_REGULAR);
else if ( ! IsIntegral(t->Tag()) )
@ -1310,7 +1310,7 @@ ForStmt::ForStmt(IDPList* arg_loop_vars, ExprPtr loop_expr)
// nop
}
else if ( ! t )
add_local({NewRef{}, (*loop_vars)[0]}, base_type(TYPE_STRING), INIT_NONE, nullptr,
add_local({NewRef{}, (*loop_vars)[0]}, base_type(TYPE_STRING), INIT_SKIP, nullptr,
nullptr, VAR_REGULAR);
else if ( t->Tag() != TYPE_STRING )
@ -1353,7 +1353,7 @@ ForStmt::ForStmt(IDPList* arg_loop_vars, ExprPtr loop_expr, IDPtr val_var)
e->Error("type clash in iteration", value_var->GetType().get());
}
else
add_local(value_var, yield_type, INIT_NONE, nullptr, nullptr, VAR_REGULAR);
add_local(value_var, yield_type, INIT_SKIP, nullptr, nullptr, VAR_REGULAR);
}
ForStmt::~ForStmt()