mirror of
https://github.com/zeek/zeek.git
synced 2025-10-14 12:38:20 +00:00
Allow delete statement for tables, sets and vectors
Relates to #3472. This allow "delete tbl" as an alternative for clear_table(tbl). Also works for vectors.
This commit is contained in:
parent
6d86a48a6a
commit
2f1893bc58
7 changed files with 68 additions and 0 deletions
18
src/Expr.cc
18
src/Expr.cc
|
@ -408,6 +408,24 @@ NameExpr::NameExpr(IDPtr arg_id, bool const_init) : Expr(EXPR_NAME), id(std::mov
|
|||
#pragma GCC diagnostic pop
|
||||
}
|
||||
|
||||
bool NameExpr::CanDel() const {
|
||||
if ( IsError() )
|
||||
return true; // avoid cascading the error report
|
||||
|
||||
return GetType()->Tag() == TYPE_TABLE || GetType()->Tag() == TYPE_VECTOR;
|
||||
}
|
||||
|
||||
void NameExpr::Delete(Frame* f) {
|
||||
if ( auto v = Eval(f) ) {
|
||||
if ( GetType()->Tag() == TYPE_TABLE )
|
||||
v->AsTableVal()->RemoveAll();
|
||||
else if ( GetType()->Tag() == TYPE_VECTOR )
|
||||
v->AsVectorVal()->Resize(0);
|
||||
else
|
||||
RuntimeError("delete unsupported");
|
||||
}
|
||||
}
|
||||
|
||||
// This isn't in-lined to avoid needing to pull in ID.h.
|
||||
const IDPtr& NameExpr::IdPtr() const { return id; }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue