mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
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:
parent
aaa81cae5d
commit
cea7c0ab46
7 changed files with 287 additions and 288 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue