script optimization support for clearing tables/vectors using "delete"

This commit is contained in:
Vern Paxson 2024-03-02 14:21:22 -08:00 committed by Arne Welzel
parent ce6d77e2ce
commit 74d36eb759
6 changed files with 37 additions and 8 deletions

View file

@ -159,6 +159,15 @@ void CPPCompile::GenAddStmt(const ExprStmt* es) {
void CPPCompile::GenDeleteStmt(const ExprStmt* es) {
auto op = es->StmtExpr();
if ( op->Tag() == EXPR_NAME ) {
if ( op->GetType()->Tag() == TYPE_TABLE )
Emit("%s->RemoveAll();", GenExpr(op, GEN_VAL_PTR));
else
Emit("%s->Resize(0);", GenExpr(op, GEN_VAL_PTR));
return;
}
auto aggr = op->GetOp1();
auto aggr_gen = GenExpr(aggr, GEN_VAL_PTR);