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:
Jon Siwek 2013-05-07 14:32:22 -05:00
parent 69c7363147
commit e2a1d4a233
14 changed files with 239 additions and 28 deletions

View file

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