mirror of
https://github.com/zeek/zeek.git
synced 2025-10-06 16:48: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
18
src/Type.cc
18
src/Type.cc
|
@ -671,8 +671,24 @@ FuncType::FuncType(RecordType* arg_args, BroType* arg_yield, function_flavor arg
|
|||
|
||||
arg_types = new TypeList();
|
||||
|
||||
bool has_default_arg = false;
|
||||
|
||||
for ( int i = 0; i < args->NumFields(); ++i )
|
||||
{
|
||||
const TypeDecl* td = args->FieldDecl(i);
|
||||
|
||||
if ( td->attrs && td->attrs->FindAttr(ATTR_DEFAULT) )
|
||||
has_default_arg = true;
|
||||
|
||||
else if ( has_default_arg )
|
||||
{
|
||||
const char* err_str = fmt("required parameter '%s' must precede "
|
||||
"default parameters", td->id);
|
||||
args->Error(err_str);
|
||||
}
|
||||
|
||||
arg_types->Append(args->FieldType(i)->Ref());
|
||||
}
|
||||
}
|
||||
|
||||
string FuncType::FlavorString() const
|
||||
|
@ -708,7 +724,7 @@ BroType* FuncType::YieldType()
|
|||
|
||||
int FuncType::MatchesIndex(ListExpr*& index) const
|
||||
{
|
||||
return check_and_promote_exprs(index, arg_types) ?
|
||||
return check_and_promote_args(index, args) ?
|
||||
MATCHES_INDEX_SCALAR : DOES_NOT_MATCH_INDEX;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue