bifcl: Support multiple/alternate event prototype definitions

This commit is contained in:
Jon Siwek 2020-04-01 16:04:44 -07:00 committed by Tim Wojtulewicz
parent b6b094b43a
commit e5c62c01a4

View file

@ -32,6 +32,11 @@ string current_module = GLOBAL_MODULE_NAME;
int definition_type; int definition_type;
string type_name; string type_name;
// Alternate event prototypes are only written to the .zeek file, but
// don't need any further changes to C++ source/header files, so this
// set keeps track of whether the first event prototype information has
// already been defined/written to the C++ files.
static std::set<std::string> events;
enum { enum {
C_SEGMENT_DEF, C_SEGMENT_DEF,
@ -378,10 +383,14 @@ opt_func_attrs: attr_list opt_ws
event_def: event_prefix opt_ws plain_head opt_func_attrs event_def: event_prefix opt_ws plain_head opt_func_attrs
{ fprintf(fp_bro_init, "%s", $4); } end_of_head ';' { fprintf(fp_bro_init, "%s", $4); } end_of_head ';'
{
if ( events.find(decl.bro_fullname) == events.end() )
{ {
print_event_c_prototype(fp_func_h, true); print_event_c_prototype(fp_func_h, true);
print_event_c_prototype(fp_func_def, false); print_event_c_prototype(fp_func_def, false);
print_event_c_body(fp_func_def); print_event_c_body(fp_func_def);
events.insert(decl.bro_fullname);
}
} }
func_def: func_prefix opt_ws typed_head opt_func_attrs func_def: func_prefix opt_ws typed_head opt_func_attrs
@ -555,6 +564,8 @@ head_1: TOK_ID opt_ws arg_begin
record_bif_item(decl.bro_fullname.c_str(), "FUNCTION"); record_bif_item(decl.bro_fullname.c_str(), "FUNCTION");
} }
else if ( definition_type == EVENT_DEF ) else if ( definition_type == EVENT_DEF )
{
if ( events.find(decl.bro_fullname) == events.end() )
{ {
// TODO: add namespace for events here // TODO: add namespace for events here
fprintf(fp_netvar_h, fprintf(fp_netvar_h,
@ -570,11 +581,11 @@ head_1: TOK_ID opt_ws arg_begin
decl.c_fullname.c_str(), decl.bro_fullname.c_str()); decl.c_fullname.c_str(), decl.bro_fullname.c_str());
record_bif_item(decl.bro_fullname.c_str(), "EVENT"); record_bif_item(decl.bro_fullname.c_str(), "EVENT");
// C++ prototypes of bro_event_* functions will // C++ prototypes of bro_event_* functions will
// be generated later. // be generated later.
} }
} }
}
; ;
arg_begin: TOK_LPP arg_begin: TOK_LPP