mirror of
https://github.com/zeek/zeek.git
synced 2025-10-15 04:58:21 +00:00
Table defaults capture closures.
This commit is contained in:
parent
d7a73c270d
commit
28253b24f9
13 changed files with 459 additions and 364 deletions
27
src/Val.cc
27
src/Val.cc
|
@ -106,7 +106,6 @@ Val* Val::DoClone(CloneState* state)
|
|||
// Functions and files. There aren't any derived classes.
|
||||
if ( type->Tag() == TYPE_FUNC )
|
||||
return new Val(this->AsFunc()->DoClone());
|
||||
|
||||
if ( type->Tag() == TYPE_FILE )
|
||||
{
|
||||
// I think we can just ref the file here - it is unclear what else
|
||||
|
@ -1359,7 +1358,7 @@ Val* TableVal::Default(Val* index)
|
|||
}
|
||||
|
||||
else
|
||||
def_val = def_attr->AttrExpr()->Eval(0);
|
||||
def_val = def_attr->AttrExpr()->Eval(0);
|
||||
}
|
||||
|
||||
if ( ! def_val )
|
||||
|
@ -1755,6 +1754,28 @@ int TableVal::CheckAndAssign(Val* index, Val* new_val)
|
|||
return Assign(index, new_val);
|
||||
}
|
||||
|
||||
void TableVal::InitDefaultFunc(Frame* f)
|
||||
{
|
||||
// Value aready initialized.
|
||||
if ( def_val )
|
||||
return;
|
||||
|
||||
Attr* def_attr = FindAttr(ATTR_DEFAULT);
|
||||
if ( ! def_attr )
|
||||
return;
|
||||
|
||||
BroType* ytype = Type()->YieldType();
|
||||
BroType* dtype = def_attr->AttrExpr()->Type();
|
||||
|
||||
if ( dtype->Tag() == TYPE_RECORD && ytype->Tag() == TYPE_RECORD &&
|
||||
! same_type(dtype, ytype) &&
|
||||
record_promotion_compatible(dtype->AsRecordType(),
|
||||
ytype->AsRecordType()) )
|
||||
return; // TableVal::Default will handle this.
|
||||
|
||||
def_val = def_attr->AttrExpr()->Eval(f);
|
||||
}
|
||||
|
||||
void TableVal::InitTimer(double delay)
|
||||
{
|
||||
timer = new TableValTimer(this, network_time + delay);
|
||||
|
@ -1991,7 +2012,7 @@ Val* TableVal::DoClone(CloneState* state)
|
|||
tv->expire_func = expire_func->Ref();
|
||||
|
||||
if ( def_val )
|
||||
tv->def_val = def_val->Ref();
|
||||
tv->def_val = def_val->Clone();
|
||||
|
||||
return tv;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue