mirror of
https://github.com/zeek/zeek.git
synced 2025-10-16 21:48:21 +00:00
Delete operator for record fields.
"delete x$y" now resets record field "x" back to its original state if it is either &optional or has a &default. "delete" may not be used with non-optional/default fields.
This commit is contained in:
parent
964060c32f
commit
46b1fd9850
9 changed files with 70 additions and 18 deletions
12
src/Expr.cc
12
src/Expr.cc
|
@ -3113,9 +3113,14 @@ Expr* FieldExpr::Simplify(SimplifyType simp_type)
|
|||
return this;
|
||||
}
|
||||
|
||||
int FieldExpr::CanDel() const
|
||||
{
|
||||
return td->FindAttr(ATTR_DEFAULT) || td->FindAttr(ATTR_OPTIONAL);
|
||||
}
|
||||
|
||||
void FieldExpr::Assign(Frame* f, Val* v, Opcode opcode)
|
||||
{
|
||||
if ( IsError() || ! v )
|
||||
if ( IsError() )
|
||||
return;
|
||||
|
||||
if ( field < 0 )
|
||||
|
@ -3130,6 +3135,11 @@ void FieldExpr::Assign(Frame* f, Val* v, Opcode opcode)
|
|||
}
|
||||
}
|
||||
|
||||
void FieldExpr::Delete(Frame* f)
|
||||
{
|
||||
Assign(f, 0, OP_ASSIGN_IDX);
|
||||
}
|
||||
|
||||
Val* FieldExpr::Fold(Val* v) const
|
||||
{
|
||||
Val* result = v->AsRecordVal()->Lookup(field);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue