Enable passing events into bifs.

When an event was globally decleared, previously it did not get
assigned a value initially until the first implementation body was
added. That then triggered an "not used" error when passing such an
event as argument into a bif. Now we always assign a function value
immediately, just without any body inititally.

When globally declaring an event, i
This commit is contained in:
Robin Sommer 2011-02-21 13:45:44 -08:00
parent 3fbb3c0fcd
commit c0cd62a5a5
2 changed files with 18 additions and 4 deletions

View file

@ -239,11 +239,15 @@ BroFunc::BroFunc(ID* arg_id, Stmt* arg_body, id_list* aggr_inits,
: Func(BRO_FUNC) : Func(BRO_FUNC)
{ {
id = arg_id; id = arg_id;
frame_size = arg_frame_size;
if ( arg_body )
{
Body b; Body b;
b.stmts = AddInits(arg_body, aggr_inits); b.stmts = AddInits(arg_body, aggr_inits);
b.priority = 0; b.priority = 0;
bodies.push_back(b); bodies.push_back(b);
frame_size = arg_frame_size; }
} }
BroFunc::~BroFunc() BroFunc::~BroFunc()

View file

@ -170,6 +170,16 @@ static void make_var(ID* id, BroType* t, init_class c, Expr* init,
} }
id->UpdateValAttrs(); id->UpdateValAttrs();
if ( t && t->Tag() == TYPE_FUNC && t->AsFuncType()->IsEvent() )
{
// For events, add a function value (without any body) here so that
// we can later access the ID even if no implementations have been
// defined.
Func* f = new BroFunc(id, 0, 0, 0);
id->SetVal(new Val(f));
id->SetConst();
}
} }