Table defaults capture closures.

This commit is contained in:
Zeke Medley 2019-06-27 14:38:38 -07:00
parent d7a73c270d
commit 28253b24f9
13 changed files with 459 additions and 364 deletions

View file

@ -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;
}