Allow event/function definitions to be wrapped in directives.

This makes

@if (conditions)
event a(...)
@else
event b(...)
@endif

work, which threw an error in the past. This is useful when event
definition change in newer Bro version and code wants to accept both
kinds of events.
This commit is contained in:
Johanna Amann 2018-08-28 15:58:52 -07:00
parent 8d9408c795
commit fb95a7750e
3 changed files with 41 additions and 0 deletions

View file

@ -1142,9 +1142,16 @@ decl:
| func_hdr func_body
{ }
| func_hdr conditional_list func_body
{ }
| conditional
;
conditional_list:
conditional
| conditional conditional_list
conditional:
TOK_ATIF '(' expr ')'
{ do_atif($3); }

View file

@ -0,0 +1,3 @@
1
2
3

View file

@ -0,0 +1,31 @@
# @TEST-EXEC: bro -b %INPUT >out
# @TEST-EXEC: btest-diff out
# Check if @if can be used to alternative function/event definitions
@if ( 1==1 )
function test_case(msg: string)
@else
lalala
@endif
{
print msg;
}
@if ( 1==1 )
event bro_init()
@else
lalala
@endif
{
print "1";
test_case("2");
}
@if ( 1==0 )
lalala
@else
event bro_init()
@endif
{
print "3";
}