mirror of
https://github.com/zeek/zeek.git
synced 2025-10-05 08:08:19 +00:00
Allow default function/hook/event parameters. Addresses #972.
And changed the endianness parameter of bytestring_to_count() BIF to default to false (big endian), mostly just to prove that the BIF parser doesn't choke on default parameters.
This commit is contained in:
parent
69c7363147
commit
e2a1d4a233
14 changed files with 239 additions and 28 deletions
28
src/Var.cc
28
src/Var.cc
|
@ -318,6 +318,29 @@ void add_type(ID* id, BroType* t, attr_list* attr, int /* is_event */)
|
|||
id->SetAttrs(new Attributes(attr, tnew, false));
|
||||
}
|
||||
|
||||
static void transfer_arg_defaults(RecordType* args, RecordType* recv)
|
||||
{
|
||||
for ( int i = 0; i < args->NumFields(); ++i )
|
||||
{
|
||||
TypeDecl* args_i = args->FieldDecl(i);
|
||||
TypeDecl* recv_i = recv->FieldDecl(i);
|
||||
|
||||
Attr* def = args_i->attrs ? args_i->attrs->FindAttr(ATTR_DEFAULT) : 0;
|
||||
|
||||
if ( ! def ) continue;
|
||||
|
||||
if ( ! recv_i->attrs )
|
||||
{
|
||||
attr_list* a = new attr_list();
|
||||
a->append(def);
|
||||
recv_i->attrs = new Attributes(a, recv_i->type, true);
|
||||
}
|
||||
|
||||
else if ( ! recv_i->attrs->FindAttr(ATTR_DEFAULT) )
|
||||
recv_i->attrs->AddAttr(def);
|
||||
}
|
||||
}
|
||||
|
||||
void begin_func(ID* id, const char* module_name, function_flavor flavor,
|
||||
int is_redef, FuncType* t)
|
||||
{
|
||||
|
@ -335,6 +358,11 @@ void begin_func(ID* id, const char* module_name, function_flavor flavor,
|
|||
{
|
||||
if ( ! same_type(id->Type(), t) )
|
||||
id->Type()->Error("incompatible types", t);
|
||||
|
||||
// If a previous declaration of the function had &default params,
|
||||
// automatically transfer any that are missing (convenience so that
|
||||
// implementations don't need to specify the &default expression again).
|
||||
transfer_arg_defaults(id->Type()->AsFuncType()->Args(), t->Args());
|
||||
}
|
||||
|
||||
else if ( is_redef )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue