mirror of
https://github.com/zeek/zeek.git
synced 2025-10-10 02:28:21 +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
44
src/Expr.cc
44
src/Expr.cc
|
@ -5478,6 +5478,50 @@ int check_and_promote_exprs(ListExpr*& elements, TypeList* types)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int check_and_promote_args(ListExpr*& args, RecordType* types)
|
||||
{
|
||||
expr_list& el = args->Exprs();
|
||||
int ntypes = types->NumFields();
|
||||
|
||||
// give variadic BIFs automatic pass
|
||||
if ( ntypes == 1 && types->FieldDecl(0)->type->Tag() == TYPE_ANY )
|
||||
return 1;
|
||||
|
||||
if ( el.length() < ntypes )
|
||||
{
|
||||
expr_list def_elements;
|
||||
|
||||
// Start from rightmost parameter, work backward to fill in missing
|
||||
// arguments using &default expressions.
|
||||
for ( int i = ntypes - 1; i >= el.length(); --i )
|
||||
{
|
||||
TypeDecl* td = types->FieldDecl(i);
|
||||
Attr* def_attr = td->attrs ? td->attrs->FindAttr(ATTR_DEFAULT) : 0;
|
||||
|
||||
if ( ! def_attr )
|
||||
{
|
||||
types->Error("parameter mismatch", args);
|
||||
return 0;
|
||||
}
|
||||
|
||||
def_elements.insert(def_attr->AttrExpr());
|
||||
}
|
||||
|
||||
loop_over_list(def_elements, i)
|
||||
el.append(def_elements[i]->Ref());
|
||||
}
|
||||
|
||||
TypeList* tl = new TypeList();
|
||||
|
||||
for ( int i = 0; i < types->NumFields(); ++i )
|
||||
tl->Append(types->FieldType(i)->Ref());
|
||||
|
||||
int rval = check_and_promote_exprs(args, tl);
|
||||
Unref(tl);
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
int check_and_promote_exprs_to_type(ListExpr*& elements, BroType* type)
|
||||
{
|
||||
expr_list& el = elements->Exprs();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue