bifcl: Deprecate names in BifConst, replace with zeek::BifConst

Some Val* types are also replaced with IntrusivePtr
This commit is contained in:
Jon Siwek 2020-05-13 23:37:48 -07:00 committed by Tim Wojtulewicz
parent 620680d878
commit d72884064a
4 changed files with 47 additions and 26 deletions

View file

@ -13,11 +13,13 @@ static struct {
const char* c_type;
const char* c_type_smart;
const char* accessor;
const char* accessor_smart;
const char* cast_smart;
const char* constructor;
const char* ctor_smart;
} builtin_func_arg_type[] = {
#define DEFINE_BIF_TYPE(id, bif_type, bro_type, c_type, c_type_smart, accessor, constructor, ctor_smart) \
{bif_type, bro_type, c_type, c_type_smart, accessor, constructor, ctor_smart},
#define DEFINE_BIF_TYPE(id, bif_type, bro_type, c_type, c_type_smart, accessor, accessor_smart, cast_smart, constructor, ctor_smart) \
{bif_type, bro_type, c_type, c_type_smart, accessor, accessor_smart, cast_smart, constructor, ctor_smart},
#include "bif_type.def"
#undef DEFINE_BIF_TYPE
};

View file

@ -165,11 +165,13 @@ static struct {
const char* c_type;
const char* c_type_smart;
const char* accessor;
const char* accessor_smart;
const char* cast_smart;
const char* constructor;
const char* ctor_smatr;
} builtin_types[] = {
#define DEFINE_BIF_TYPE(id, bif_type, bro_type, c_type, c_type_smart, accessor, constructor, ctor_smart) \
{bif_type, bro_type, c_type, c_type_smart, accessor, constructor, ctor_smart},
#define DEFINE_BIF_TYPE(id, bif_type, bro_type, c_type, c_type_smart, accessor, accessor_smart, cast_smart, constructor, ctor_smart) \
{bif_type, bro_type, c_type, c_type_smart, accessor, accessor_smart, cast_smart, constructor, ctor_smart},
#include "bif_type.def"
#undef DEFINE_BIF_TYPE
};
@ -512,21 +514,38 @@ const_def: TOK_CONST opt_ws TOK_ID opt_ws ':' opt_ws TOK_ID opt_ws ';'
set_decl_name($3);
int typeidx = get_type_index($7);
char accessor[1024];
char accessor_smart[1024];
snprintf(accessor, sizeof(accessor), builtin_types[typeidx].accessor, "");
snprintf(accessor_smart, sizeof(accessor_smart), builtin_types[typeidx].accessor_smart, "");
fprintf(fp_netvar_h, "%s extern %s %s; %s\n",
fprintf(fp_netvar_h, "namespace zeek { %s extern %s %s; %s }\n",
decl.c_namespace_start.c_str(),
builtin_types[typeidx].c_type_smart, decl.bare_name.c_str(),
decl.c_namespace_end.c_str());
fprintf(fp_netvar_h, "%s [[deprecated(\"Remove in v4.1. Use zeek::%s.\")]] extern %s %s; %s\n",
decl.c_namespace_start.c_str(), decl.c_fullname.c_str(),
builtin_types[typeidx].c_type, decl.bare_name.c_str(),
decl.c_namespace_end.c_str());
fprintf(fp_netvar_def, "namespace zeek { %s %s %s; %s }\n",
decl.c_namespace_start.c_str(),
builtin_types[typeidx].c_type_smart, decl.bare_name.c_str(),
decl.c_namespace_end.c_str());
fprintf(fp_netvar_def, "%s %s %s; %s\n",
decl.c_namespace_start.c_str(),
builtin_types[typeidx].c_type, decl.bare_name.c_str(),
decl.c_namespace_end.c_str());
fprintf(fp_netvar_init, "\t%s = zeek::id::lookup_const(\"%s\").get()%s;\n",
decl.c_fullname.c_str(), decl.bro_fullname.c_str(),
accessor);
fprintf(fp_netvar_init, "\t{\n");
fprintf(fp_netvar_init, "\tconst auto& v = zeek::id::lookup_const%s(\"%s\");\n",
builtin_types[typeidx].cast_smart, decl.bro_fullname.c_str());
fprintf(fp_netvar_init, "\tzeek::%s = v%s;\n",
decl.c_fullname.c_str(), accessor_smart);
fprintf(fp_netvar_init, "\t%s = v.get()%s;\n",
decl.c_fullname.c_str(), accessor);
fprintf(fp_netvar_init, "\t}\n");
record_bif_item(decl.bro_fullname.c_str(), "CONSTANT");
}

View file

@ -3,7 +3,7 @@
#include <stdio.h>
enum builtin_func_arg_type {
#define DEFINE_BIF_TYPE(id, bif_type, bro_type, c_type, c_type_smart, accessor, constructor, ctor_smart) \
#define DEFINE_BIF_TYPE(id, bif_type, bro_type, c_type, c_type_smart, accessor, accessor_smart, cast_smart, constructor, ctor_smart) \
id,
#include "bif_type.def"
#undef DEFINE_BIF_TYPE

View file

@ -1,17 +1,17 @@
// (id, bif_type, bro_type, c_type, c_type_smart, accessor, constructor, ctor_smart)
DEFINE_BIF_TYPE(TYPE_ADDR, "addr", "addr", "AddrVal*", "IntrusivePtr<AddrVal>", "%s->AsAddrVal()", "IntrusivePtr{AdoptRef{}, %s}", "std::move(%s)")
DEFINE_BIF_TYPE(TYPE_ANY, "any", "any", "Val*", "IntrusivePtr<Val>", "%s", "IntrusivePtr{AdoptRef{}, %s}", "std::move(%s)")
DEFINE_BIF_TYPE(TYPE_BOOL, "bool", "bool", "int", "int", "%s->AsBool()", "val_mgr->Bool(%s)", "val_mgr->Bool(%s)")
DEFINE_BIF_TYPE(TYPE_CONN_ID, "conn_id", "conn_id", "Val*", "IntrusivePtr<Val>", "%s", "IntrusivePtr{AdoptRef{}, %s}", "std::move(%s)")
DEFINE_BIF_TYPE(TYPE_CONNECTION, "connection", "connection", "Connection*", "Connection*", "%s->AsRecordVal()->GetOrigin()", "%s->ConnVal()", "%s->ConnVal()")
DEFINE_BIF_TYPE(TYPE_COUNT, "count", "count", "bro_uint_t", "bro_uint_t", "%s->AsCount()", "val_mgr->Count(%s)", "val_mgr->Count(%s)")
DEFINE_BIF_TYPE(TYPE_DOUBLE, "double", "double", "double", "double", "%s->AsDouble()", "make_intrusive<Val>(%s, TYPE_DOUBLE)", "make_intrusive<Val>(%s, TYPE_DOUBLE)")
DEFINE_BIF_TYPE(TYPE_FILE, "file", "file", "BroFile*", "IntrusivePtr<Val>", "%s->AsFile()", "make_intrusive<Val>(%s)", "std::move(%s)")
DEFINE_BIF_TYPE(TYPE_INT, "int", "int", "bro_int_t", "bro_int_t", "%s->AsInt()", "val_mgr->Int(%s)", "val_mgr->Int(%s)")
DEFINE_BIF_TYPE(TYPE_INTERVAL, "interval", "interval", "double", "double", "%s->AsInterval()", "make_intrusive<IntervalVal>(%s, Seconds)", "make_intrusive<IntervalVal>(%s, Seconds)")
DEFINE_BIF_TYPE(TYPE_PATTERN, "pattern", "pattern", "RE_Matcher*", "IntrusivePtr<PatternVal>", "%s->AsPattern()", "make_intrusive<PatternVal>(%s)", "std::move(%s)")
DEFINE_BIF_TYPE(TYPE_PORT, "port", "port", "PortVal*", "IntrusivePtr<PortVal>", "%s->AsPortVal()", "IntrusivePtr{AdoptRef{}, %s}", "std::move(%s)")
DEFINE_BIF_TYPE(TYPE_STRING, "string", "string", "StringVal*", "IntrusivePtr<StringVal>", "%s->AsStringVal()", "IntrusivePtr{AdoptRef{}, %s}", "std::move(%s)")
DEFINE_BIF_TYPE(TYPE_SUBNET, "subnet", "subnet", "SubNetVal*", "IntrusivePtr<SubNetVal>", "%s->AsSubNetVal()", "IntrusivePtr{AdoptRef{}, %s}", "std::move(%s)")
DEFINE_BIF_TYPE(TYPE_TIME, "time", "time", "double", "double", "%s->AsTime()", "make_intrusive<Val>(%s, TYPE_TIME)", "make_intrusive<Val>(%s, TYPE_TIME)")
DEFINE_BIF_TYPE(TYPE_OTHER, "", "", "Val*", "IntrusivePtr<Val>", "%s", "IntrusivePtr{AdoptRef{}, %s}", "std::move(%s)")
// (id, bif_type, bro_type, c_type, c_type_smart, accessor, accessor_smart, cast_smart, constructor, ctor_smart)
DEFINE_BIF_TYPE(TYPE_ADDR, "addr", "addr", "AddrVal*", "IntrusivePtr<AddrVal>", "%s->AsAddrVal()", "%s", "<AddrVal>", "IntrusivePtr{AdoptRef{}, %s}", "std::move(%s)")
DEFINE_BIF_TYPE(TYPE_ANY, "any", "any", "Val*", "IntrusivePtr<Val>", "%s", "%s", "", "IntrusivePtr{AdoptRef{}, %s}", "std::move(%s)")
DEFINE_BIF_TYPE(TYPE_BOOL, "bool", "bool", "int", "int", "%s->AsBool()", "%s->AsBool()", "", "val_mgr->Bool(%s)", "val_mgr->Bool(%s)")
DEFINE_BIF_TYPE(TYPE_CONN_ID, "conn_id", "conn_id", "Val*", "IntrusivePtr<Val>", "%s", "%s", "", "IntrusivePtr{AdoptRef{}, %s}", "std::move(%s)")
DEFINE_BIF_TYPE(TYPE_CONNECTION, "connection", "connection", "Connection*", "Connection*", "%s->AsRecordVal()->GetOrigin()", "%s->AsRecordVal()->GetOrigin()", "", "%s->ConnVal()", "%s->ConnVal()")
DEFINE_BIF_TYPE(TYPE_COUNT, "count", "count", "bro_uint_t", "bro_uint_t", "%s->AsCount()", "%s->AsCount()", "", "val_mgr->Count(%s)", "val_mgr->Count(%s)")
DEFINE_BIF_TYPE(TYPE_DOUBLE, "double", "double", "double", "double", "%s->AsDouble()", "%s->AsDouble()", "", "make_intrusive<Val>(%s, TYPE_DOUBLE)", "make_intrusive<Val>(%s, TYPE_DOUBLE)")
DEFINE_BIF_TYPE(TYPE_FILE, "file", "file", "BroFile*", "IntrusivePtr<Val>", "%s->AsFile()", "%s", "", "make_intrusive<Val>(%s)", "std::move(%s)")
DEFINE_BIF_TYPE(TYPE_INT, "int", "int", "bro_int_t", "bro_int_t", "%s->AsInt()", "%s->AsInt()", "", "val_mgr->Int(%s)", "val_mgr->Int(%s)")
DEFINE_BIF_TYPE(TYPE_INTERVAL, "interval", "interval", "double", "double", "%s->AsInterval()", "%s->AsInterval()", "", "make_intrusive<IntervalVal>(%s, Seconds)", "make_intrusive<IntervalVal>(%s, Seconds)")
DEFINE_BIF_TYPE(TYPE_PATTERN, "pattern", "pattern", "RE_Matcher*", "IntrusivePtr<PatternVal>", "%s->AsPattern()", "%s", "<PatternVal>", "make_intrusive<PatternVal>(%s)", "std::move(%s)")
DEFINE_BIF_TYPE(TYPE_PORT, "port", "port", "PortVal*", "IntrusivePtr<PortVal>", "%s->AsPortVal()", "%s", "<PortVal>", "IntrusivePtr{AdoptRef{}, %s}", "std::move(%s)")
DEFINE_BIF_TYPE(TYPE_STRING, "string", "string", "StringVal*", "IntrusivePtr<StringVal>", "%s->AsStringVal()", "%s", "<StringVal>", "IntrusivePtr{AdoptRef{}, %s}", "std::move(%s)")
DEFINE_BIF_TYPE(TYPE_SUBNET, "subnet", "subnet", "SubNetVal*", "IntrusivePtr<SubNetVal>", "%s->AsSubNetVal()", "%s", "<SubNetVal>", "IntrusivePtr{AdoptRef{}, %s}", "std::move(%s)")
DEFINE_BIF_TYPE(TYPE_TIME, "time", "time", "double", "double", "%s->AsTime()", "%s->AsTime()", "", "make_intrusive<Val>(%s, TYPE_TIME)", "make_intrusive<Val>(%s, TYPE_TIME)")
DEFINE_BIF_TYPE(TYPE_OTHER, "", "", "Val*", "IntrusivePtr<Val>", "%s", "%s", "", "IntrusivePtr{AdoptRef{}, %s}", "std::move(%s)")