Allow alternate event/hook prototype declarations

The alternates must be some subset of the canonical prototype (the one
that's first declared) and allows users to define handlers for any
such prototype.  Example:

    # Prototype declarations
    global my_event: event(s: string, c: count);
    global my_event: event(c: count);
    global my_event: event();

    # Handler definitions
    event my_event(s: string, c: count) { print s, c; }
    event my_event(c: count) { print c; }
    event my_event() { }

This allows handlers to consume a subset of the arguments or even
re-order them.  This makes it easier to either extend an existing
event/hook's arguments and/or deprecate usages of certain prototypes.
This commit is contained in:
Jon Siwek 2020-03-31 18:06:05 -07:00
parent eefafdc1e1
commit 8c0e8ecd28
12 changed files with 399 additions and 8 deletions

View file

@ -431,8 +431,42 @@ void ID::DescribeReST(ODesc* d, bool roles_only) const
d->Add("`");
}
else
{
type->DescribeReST(d, roles_only);
if ( IsFunc(type->Tag()) )
{
auto ft = type->AsFuncType();
if ( ft->Flavor() == FUNC_FLAVOR_EVENT ||
ft->Flavor() == FUNC_FLAVOR_HOOK )
{
const auto& protos = ft->Prototypes();
if ( protos.size() > 1 )
{
auto first = true;
for ( const auto& proto : protos )
{
if ( first )
{
first = false;
continue;
}
d->NL();
d->Add(":Type: :zeek:type:`");
d->Add(ft->FlavorString());
d->Add("` (");
proto.args->DescribeFieldsReST(d, true);
d->Add(")");
}
}
}
}
}
d->NL();
}