mirror of
https://github.com/zeek/zeek.git
synced 2025-10-09 10:08:20 +00:00
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:
parent
eefafdc1e1
commit
8c0e8ecd28
12 changed files with 399 additions and 8 deletions
34
src/ID.cc
34
src/ID.cc
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue