mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
decluttered code by removing "std::" - no semantic changes
(also some whitespace fixes)
This commit is contained in:
parent
bbe5ab39f6
commit
72413f315c
18 changed files with 420 additions and 397 deletions
|
@ -5,6 +5,8 @@
|
|||
|
||||
namespace zeek::detail {
|
||||
|
||||
using namespace std;
|
||||
|
||||
void CPPCompile::RegisterAttributes(const AttributesPtr& attrs)
|
||||
{
|
||||
if ( ! attrs || attributes.HasKey(attrs) )
|
||||
|
@ -43,8 +45,8 @@ void CPPCompile::RegisterAttributes(const AttributesPtr& attrs)
|
|||
}
|
||||
}
|
||||
|
||||
void CPPCompile::BuildAttrs(const AttributesPtr& attrs, std::string& attr_tags,
|
||||
std::string& attr_vals)
|
||||
void CPPCompile::BuildAttrs(const AttributesPtr& attrs, string& attr_tags,
|
||||
string& attr_vals)
|
||||
{
|
||||
if ( attrs )
|
||||
{
|
||||
|
@ -67,8 +69,8 @@ void CPPCompile::BuildAttrs(const AttributesPtr& attrs, std::string& attr_tags,
|
|||
}
|
||||
}
|
||||
|
||||
attr_tags = std::string("{") + attr_tags + "}";
|
||||
attr_vals = std::string("{") + attr_vals + "}";
|
||||
attr_tags = string("{") + attr_tags + "}";
|
||||
attr_vals = string("{") + attr_vals + "}";
|
||||
}
|
||||
|
||||
void CPPCompile::GenAttrs(const AttributesPtr& attrs)
|
||||
|
@ -80,7 +82,7 @@ void CPPCompile::GenAttrs(const AttributesPtr& attrs)
|
|||
StartBlock();
|
||||
|
||||
const auto& avec = attrs->GetAttrs();
|
||||
Emit("auto attrs = std::vector<AttrPtr>();");
|
||||
Emit("auto attrs = vector<AttrPtr>();");
|
||||
|
||||
AddInit(attrs);
|
||||
|
||||
|
@ -99,7 +101,7 @@ void CPPCompile::GenAttrs(const AttributesPtr& attrs)
|
|||
NoteInitDependency(attrs, e);
|
||||
AddInit(e);
|
||||
|
||||
std::string e_arg;
|
||||
string e_arg;
|
||||
if ( IsSimpleInitExpr(e) )
|
||||
e_arg = GenAttrExpr(e);
|
||||
else
|
||||
|
@ -114,21 +116,21 @@ void CPPCompile::GenAttrs(const AttributesPtr& attrs)
|
|||
EndBlock();
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenAttrExpr(const ExprPtr& e)
|
||||
string CPPCompile::GenAttrExpr(const ExprPtr& e)
|
||||
{
|
||||
switch ( e->Tag() ) {
|
||||
case EXPR_CONST:
|
||||
return std::string("make_intrusive<ConstExpr>(") +
|
||||
return string("make_intrusive<ConstExpr>(") +
|
||||
GenExpr(e, GEN_VAL_PTR) + ")";
|
||||
|
||||
case EXPR_NAME:
|
||||
NoteInitDependency(e, e->AsNameExpr()->IdPtr());
|
||||
return std::string("make_intrusive<NameExpr>(") +
|
||||
return string("make_intrusive<NameExpr>(") +
|
||||
globals[e->AsNameExpr()->Id()->Name()] + ")";
|
||||
|
||||
case EXPR_RECORD_COERCE:
|
||||
NoteInitDependency(e, TypeRep(e->GetType()));
|
||||
return std::string("make_intrusive<RecordCoerceExpr>(make_intrusive<RecordConstructorExpr>(make_intrusive<ListExpr>()), cast_intrusive<RecordType>(") +
|
||||
return string("make_intrusive<RecordCoerceExpr>(make_intrusive<RecordConstructorExpr>(make_intrusive<ListExpr>()), cast_intrusive<RecordType>(") +
|
||||
GenTypeName(e->GetType()) + "))";
|
||||
|
||||
default:
|
||||
|
@ -137,7 +139,7 @@ std::string CPPCompile::GenAttrExpr(const ExprPtr& e)
|
|||
}
|
||||
}
|
||||
|
||||
std::string CPPCompile::AttrsName(const AttributesPtr& a)
|
||||
string CPPCompile::AttrsName(const AttributesPtr& a)
|
||||
{
|
||||
return attributes.KeyName(a) + "()";
|
||||
}
|
||||
|
|
|
@ -7,7 +7,9 @@
|
|||
|
||||
namespace zeek::detail {
|
||||
|
||||
std::string CPPCompile::BuildConstant(const Obj* parent, const ValPtr& vp)
|
||||
using namespace std;
|
||||
|
||||
string CPPCompile::BuildConstant(const Obj* parent, const ValPtr& vp)
|
||||
{
|
||||
if ( ! vp )
|
||||
return "nullptr";
|
||||
|
@ -55,7 +57,7 @@ bool CPPCompile::AddConstant(const ValPtr& vp)
|
|||
// Formulate a key that's unique per distinct constant.
|
||||
|
||||
const auto& t = v->GetType();
|
||||
std::string c_desc;
|
||||
string c_desc;
|
||||
|
||||
if ( t->Tag() == TYPE_STRING )
|
||||
{
|
||||
|
@ -63,7 +65,7 @@ bool CPPCompile::AddConstant(const ValPtr& vp)
|
|||
// escaping, sigh. Just use the raw string.
|
||||
auto s = v->AsString();
|
||||
auto b = (const char*)(s->Bytes());
|
||||
c_desc = std::string(b, s->Len()) + "string";
|
||||
c_desc = string(b, s->Len()) + "string";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -90,8 +92,7 @@ bool CPPCompile::AddConstant(const ValPtr& vp)
|
|||
}
|
||||
|
||||
// Need a C++ global for this constant.
|
||||
auto const_name = std::string("CPP__const__") +
|
||||
Fmt(int(constants.size()));
|
||||
auto const_name = string("CPP__const__") + Fmt(int(constants.size()));
|
||||
|
||||
const_vals[v] = constants[c_desc] = const_name;
|
||||
constants_to_vals[c_desc] = v;
|
||||
|
@ -134,7 +135,7 @@ bool CPPCompile::AddConstant(const ValPtr& vp)
|
|||
v->Describe(&d);
|
||||
|
||||
AddInit(v, const_name,
|
||||
std::string("make_intrusive<") + prefix +
|
||||
string("make_intrusive<") + prefix +
|
||||
"Val>(\"" + d.Description() + "\")");
|
||||
}
|
||||
break;
|
||||
|
@ -156,7 +157,7 @@ bool CPPCompile::AddConstant(const ValPtr& vp)
|
|||
auto f = cast_intrusive<FileVal>(vp)->Get();
|
||||
|
||||
AddInit(v, const_name,
|
||||
std::string("make_intrusive<FileVal>(") +
|
||||
string("make_intrusive<FileVal>(") +
|
||||
"make_intrusive<File>(\"" + f->Name() + "\", \"w\"))");
|
||||
}
|
||||
break;
|
||||
|
@ -168,7 +169,7 @@ bool CPPCompile::AddConstant(const ValPtr& vp)
|
|||
return true;
|
||||
}
|
||||
|
||||
void CPPCompile::AddStringConstant(const ValPtr& v, std::string& const_name)
|
||||
void CPPCompile::AddStringConstant(const ValPtr& v, string& const_name)
|
||||
{
|
||||
Emit("StringValPtr %s;", const_name);
|
||||
|
||||
|
@ -179,13 +180,13 @@ void CPPCompile::AddStringConstant(const ValPtr& v, std::string& const_name)
|
|||
AddInit(v, const_name, GenString(b, len));
|
||||
}
|
||||
|
||||
void CPPCompile::AddPatternConstant(const ValPtr& v, std::string& const_name)
|
||||
void CPPCompile::AddPatternConstant(const ValPtr& v, string& const_name)
|
||||
{
|
||||
Emit("PatternValPtr %s;", const_name);
|
||||
|
||||
auto re = v->AsPatternVal()->Get();
|
||||
|
||||
AddInit(v, std::string("{ auto re = new RE_Matcher(") +
|
||||
AddInit(v, string("{ auto re = new RE_Matcher(") +
|
||||
CPPEscape(re->OrigText()) + ");");
|
||||
|
||||
if ( re->IsCaseInsensitive() )
|
||||
|
@ -196,7 +197,7 @@ void CPPCompile::AddPatternConstant(const ValPtr& v, std::string& const_name)
|
|||
AddInit(v, "}");
|
||||
}
|
||||
|
||||
void CPPCompile::AddListConstant(const ValPtr& v, std::string& const_name)
|
||||
void CPPCompile::AddListConstant(const ValPtr& v, string& const_name)
|
||||
{
|
||||
Emit("ListValPtr %s;", const_name);
|
||||
|
||||
|
@ -204,7 +205,7 @@ void CPPCompile::AddListConstant(const ValPtr& v, std::string& const_name)
|
|||
// use the underlying TypeList. However, we *do* use the types of
|
||||
// the elements.
|
||||
|
||||
AddInit(v, const_name, std::string("make_intrusive<ListVal>(TYPE_ANY)"));
|
||||
AddInit(v, const_name, string("make_intrusive<ListVal>(TYPE_ANY)"));
|
||||
|
||||
auto lv = cast_intrusive<ListVal>(v);
|
||||
auto n = lv->Length();
|
||||
|
@ -218,7 +219,7 @@ void CPPCompile::AddListConstant(const ValPtr& v, std::string& const_name)
|
|||
}
|
||||
}
|
||||
|
||||
void CPPCompile::AddRecordConstant(const ValPtr& v, std::string& const_name)
|
||||
void CPPCompile::AddRecordConstant(const ValPtr& v, string& const_name)
|
||||
{
|
||||
const auto& t = v->GetType();
|
||||
|
||||
|
@ -226,7 +227,7 @@ void CPPCompile::AddRecordConstant(const ValPtr& v, std::string& const_name)
|
|||
|
||||
NoteInitDependency(v, TypeRep(t));
|
||||
|
||||
AddInit(v, const_name, std::string("make_intrusive<RecordVal>(") +
|
||||
AddInit(v, const_name, string("make_intrusive<RecordVal>(") +
|
||||
"cast_intrusive<RecordType>(" + GenTypeName(t) + "))");
|
||||
|
||||
auto r = cast_intrusive<RecordVal>(v);
|
||||
|
@ -245,7 +246,7 @@ void CPPCompile::AddRecordConstant(const ValPtr& v, std::string& const_name)
|
|||
}
|
||||
}
|
||||
|
||||
void CPPCompile::AddTableConstant(const ValPtr& v, std::string& const_name)
|
||||
void CPPCompile::AddTableConstant(const ValPtr& v, string& const_name)
|
||||
{
|
||||
const auto& t = v->GetType();
|
||||
|
||||
|
@ -253,7 +254,7 @@ void CPPCompile::AddTableConstant(const ValPtr& v, std::string& const_name)
|
|||
|
||||
NoteInitDependency(v, TypeRep(t));
|
||||
|
||||
AddInit(v, const_name, std::string("make_intrusive<TableVal>(") +
|
||||
AddInit(v, const_name, string("make_intrusive<TableVal>(") +
|
||||
"cast_intrusive<TableType>(" + GenTypeName(t) + "))");
|
||||
|
||||
auto tv = cast_intrusive<TableVal>(v);
|
||||
|
@ -267,7 +268,7 @@ void CPPCompile::AddTableConstant(const ValPtr& v, std::string& const_name)
|
|||
}
|
||||
}
|
||||
|
||||
void CPPCompile::AddVectorConstant(const ValPtr& v, std::string& const_name)
|
||||
void CPPCompile::AddVectorConstant(const ValPtr& v, string& const_name)
|
||||
{
|
||||
const auto& t = v->GetType();
|
||||
|
||||
|
@ -275,7 +276,7 @@ void CPPCompile::AddVectorConstant(const ValPtr& v, std::string& const_name)
|
|||
|
||||
NoteInitDependency(v, TypeRep(t));
|
||||
|
||||
AddInit(v, const_name, std::string("make_intrusive<VectorVal>(") +
|
||||
AddInit(v, const_name, string("make_intrusive<VectorVal>(") +
|
||||
"cast_intrusive<VectorType>(" + GenTypeName(t) + "))");
|
||||
|
||||
auto vv = cast_intrusive<VectorVal>(v);
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
|
||||
namespace zeek::detail {
|
||||
|
||||
using namespace std;
|
||||
|
||||
void CPPCompile::DeclareFunc(const FuncInfo& func)
|
||||
{
|
||||
if ( ! IsCompilable(func) )
|
||||
|
@ -41,7 +43,7 @@ void CPPCompile::DeclareLambda(const LambdaExpr* l, const ProfileFunc* pf)
|
|||
}
|
||||
|
||||
void CPPCompile::DeclareSubclass(const FuncTypePtr& ft, const ProfileFunc* pf,
|
||||
const std::string& fname,
|
||||
const string& fname,
|
||||
const StmtPtr& body, int priority,
|
||||
const LambdaExpr* l, FunctionFlavor flavor)
|
||||
{
|
||||
|
@ -59,8 +61,8 @@ void CPPCompile::DeclareSubclass(const FuncTypePtr& ft, const ProfileFunc* pf,
|
|||
|
||||
Emit("public:");
|
||||
|
||||
std::string addl_args; // captures passed in on construction
|
||||
std::string inits; // initializers for corresponding member vars
|
||||
string addl_args; // captures passed in on construction
|
||||
string inits; // initializers for corresponding member vars
|
||||
|
||||
if ( lambda_ids )
|
||||
{
|
||||
|
@ -131,13 +133,13 @@ void CPPCompile::DeclareSubclass(const FuncTypePtr& ft, const ProfileFunc* pf,
|
|||
body_hashes[fname] = h;
|
||||
body_priorities[fname] = priority;
|
||||
body_names.emplace(body.get(), fname);
|
||||
names_to_bodies.emplace(std::move(fname), body.get());
|
||||
names_to_bodies.emplace(move(fname), body.get());
|
||||
|
||||
total_hash = merge_p_hashes(total_hash, h);
|
||||
}
|
||||
|
||||
void CPPCompile::BuildLambda(const FuncTypePtr& ft, const ProfileFunc* pf,
|
||||
const std::string& fname, const StmtPtr& body,
|
||||
const string& fname, const StmtPtr& body,
|
||||
const LambdaExpr* l, const IDPList* lambda_ids)
|
||||
{
|
||||
// Declare the member variables for holding the captures.
|
||||
|
@ -149,14 +151,14 @@ void CPPCompile::BuildLambda(const FuncTypePtr& ft, const ProfileFunc* pf,
|
|||
}
|
||||
|
||||
// Generate initialization to create and register the lambda.
|
||||
auto literal_name = std::string("\"") + l->Name() + "\"";
|
||||
auto instantiate = std::string("make_intrusive<") + fname + "_cl>(" +
|
||||
auto literal_name = string("\"") + l->Name() + "\"";
|
||||
auto instantiate = string("make_intrusive<") + fname + "_cl>(" +
|
||||
literal_name + ")";
|
||||
|
||||
int nl = lambda_ids->length();
|
||||
auto h = Fmt(pf->HashVal());
|
||||
auto has_captures = nl > 0 ? "true" : "false";
|
||||
auto l_init = std::string("register_lambda__CPP(") + instantiate +
|
||||
auto l_init = string("register_lambda__CPP(") + instantiate +
|
||||
", " + h + ", \"" + l->Name() + "\", " +
|
||||
GenTypeName(ft) + ", " + has_captures + ");";
|
||||
|
||||
|
@ -178,7 +180,7 @@ void CPPCompile::BuildLambda(const FuncTypePtr& ft, const ProfileFunc* pf,
|
|||
{
|
||||
auto l_i = (*lambda_ids)[i];
|
||||
const auto& t_i = l_i->GetType();
|
||||
auto cap_i = std::string("f->GetElement(") + Fmt(i) + ")";
|
||||
auto cap_i = string("f->GetElement(") + Fmt(i) + ")";
|
||||
Emit("%s = %s;", lambda_names[l_i],
|
||||
GenericValPtrToGT(cap_i, t_i, GEN_NATIVE));
|
||||
}
|
||||
|
@ -206,17 +208,17 @@ void CPPCompile::BuildLambda(const FuncTypePtr& ft, const ProfileFunc* pf,
|
|||
EndBlock();
|
||||
}
|
||||
|
||||
std::string CPPCompile::BindArgs(const FuncTypePtr& ft, const IDPList* lambda_ids)
|
||||
string CPPCompile::BindArgs(const FuncTypePtr& ft, const IDPList* lambda_ids)
|
||||
{
|
||||
const auto& params = ft->Params();
|
||||
auto t = params->Types();
|
||||
|
||||
std::string res;
|
||||
string res;
|
||||
|
||||
int n = t ? t->size() : 0;
|
||||
for ( auto i = 0; i < n; ++i )
|
||||
{
|
||||
auto arg_i = std::string("f->GetElement(") + Fmt(i) + ")";
|
||||
auto arg_i = string("f->GetElement(") + Fmt(i) + ")";
|
||||
const auto& ft = params->GetFieldType(i);
|
||||
|
||||
if ( IsNativeType(ft) )
|
||||
|
@ -237,21 +239,20 @@ std::string CPPCompile::BindArgs(const FuncTypePtr& ft, const IDPList* lambda_id
|
|||
return res + "f";
|
||||
}
|
||||
|
||||
std::string CPPCompile::ParamDecl(const FuncTypePtr& ft,
|
||||
const IDPList* lambda_ids,
|
||||
const ProfileFunc* pf)
|
||||
string CPPCompile::ParamDecl(const FuncTypePtr& ft, const IDPList* lambda_ids,
|
||||
const ProfileFunc* pf)
|
||||
{
|
||||
const auto& params = ft->Params();
|
||||
int n = params->NumFields();
|
||||
|
||||
std::string decl;
|
||||
string decl;
|
||||
|
||||
for ( auto i = 0; i < n; ++i )
|
||||
{
|
||||
const auto& t = params->GetFieldType(i);
|
||||
auto tn = FullTypeName(t);
|
||||
auto param_id = FindParam(i, pf);
|
||||
std::string fn;
|
||||
string fn;
|
||||
|
||||
if ( param_id )
|
||||
{
|
||||
|
@ -260,7 +261,7 @@ std::string CPPCompile::ParamDecl(const FuncTypePtr& ft,
|
|||
// We'll need to translate the parameter
|
||||
// from its current representation to
|
||||
// type "any".
|
||||
fn = std::string("any_param__CPP_") + Fmt(i);
|
||||
fn = string("any_param__CPP_") + Fmt(i);
|
||||
else
|
||||
fn = LocalName(param_id);
|
||||
}
|
||||
|
@ -270,7 +271,7 @@ std::string CPPCompile::ParamDecl(const FuncTypePtr& ft,
|
|||
// name out of the function's declaration, we
|
||||
// explicitly name them to reflect that they're
|
||||
// unused.
|
||||
fn = std::string("unused_param__CPP_") + Fmt(i);
|
||||
fn = string("unused_param__CPP_") + Fmt(i);
|
||||
|
||||
if ( IsNativeType(t) )
|
||||
// Native types are always pass-by-value.
|
||||
|
|
|
@ -9,8 +9,10 @@
|
|||
|
||||
namespace zeek::detail {
|
||||
|
||||
using namespace std;
|
||||
|
||||
CPPCompile::CPPCompile(std::vector<FuncInfo>& _funcs, ProfileFuncs& _pfs,
|
||||
|
||||
CPPCompile::CPPCompile(vector<FuncInfo>& _funcs, ProfileFuncs& _pfs,
|
||||
const char* gen_name, CPPHashManager& _hm,
|
||||
bool _update, bool _standalone)
|
||||
: funcs(_funcs), pfs(_pfs), hm(_hm), update(_update), standalone(_standalone)
|
||||
|
@ -124,14 +126,14 @@ void CPPCompile::Compile()
|
|||
RegisterAttributes(g->GetAttrs());
|
||||
if ( g->HasVal() )
|
||||
{
|
||||
auto gn = std::string(g->Name());
|
||||
auto gn = string(g->Name());
|
||||
GenGlobalInit(g, globals[gn], g->GetVal());
|
||||
}
|
||||
}
|
||||
|
||||
for ( const auto& e : pfs.Events() )
|
||||
if ( AddGlobal(e, "gl", false) )
|
||||
Emit("EventHandlerPtr %s_ev;", globals[std::string(e)]);
|
||||
Emit("EventHandlerPtr %s_ev;", globals[string(e)]);
|
||||
|
||||
for ( const auto& t : pfs.RepTypes() )
|
||||
{
|
||||
|
@ -149,7 +151,7 @@ void CPPCompile::Compile()
|
|||
// LambdaExpr's can wind up referring to the same underlying lambda
|
||||
// if the bodies happen to be identical. In that case, we don't
|
||||
// want to generate the lambda twice.
|
||||
std::unordered_set<std::string> lambda_names;
|
||||
unordered_set<string> lambda_names;
|
||||
for ( const auto& l : pfs.Lambdas() )
|
||||
{
|
||||
const auto& n = l->Name();
|
||||
|
@ -202,13 +204,13 @@ void CPPCompile::GenProlog()
|
|||
NL();
|
||||
}
|
||||
|
||||
void CPPCompile::RegisterCompiledBody(const std::string& f)
|
||||
void CPPCompile::RegisterCompiledBody(const string& f)
|
||||
{
|
||||
auto h = body_hashes[f];
|
||||
auto p = body_priorities[f];
|
||||
|
||||
// Build up an initializer of the events relevant to the function.
|
||||
std::string events;
|
||||
string events;
|
||||
if ( body_events.count(f) > 0 )
|
||||
for ( auto e : body_events[f] )
|
||||
{
|
||||
|
@ -217,7 +219,7 @@ void CPPCompile::RegisterCompiledBody(const std::string& f)
|
|||
events = events + "\"" + e + "\"";
|
||||
}
|
||||
|
||||
events = std::string("{") + events + "}";
|
||||
events = string("{") + events + "}";
|
||||
|
||||
if ( addl_tag > 0 )
|
||||
// Hash in the location associated with this compilation
|
||||
|
@ -229,7 +231,7 @@ void CPPCompile::RegisterCompiledBody(const std::string& f)
|
|||
// same binary).
|
||||
h = merge_p_hashes(h, p_hash(cf_locs[f]));
|
||||
|
||||
auto init = std::string("register_body__CPP(make_intrusive<") +
|
||||
auto init = string("register_body__CPP(make_intrusive<") +
|
||||
f + "_cl>(\"" + f + "\"), " + Fmt(p) + ", " +
|
||||
Fmt(h) + ", " + events + ");";
|
||||
|
||||
|
@ -274,7 +276,7 @@ void CPPCompile::GenEpilog()
|
|||
|
||||
GenPreInits();
|
||||
|
||||
std::unordered_set<const Obj*> to_do;
|
||||
unordered_set<const Obj*> to_do;
|
||||
for ( const auto& oi : obj_inits )
|
||||
to_do.insert(oi.first);
|
||||
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
|
||||
namespace zeek::detail {
|
||||
|
||||
using namespace std;
|
||||
|
||||
void CPPCompile::StartBlock()
|
||||
{
|
||||
++block_level;
|
||||
|
@ -21,15 +23,15 @@ void CPPCompile::EndBlock(bool needs_semi)
|
|||
--block_level;
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenString(const char* b, int len) const
|
||||
string CPPCompile::GenString(const char* b, int len) const
|
||||
{
|
||||
return std::string("make_intrusive<StringVal>(") + Fmt(len) +
|
||||
", " + CPPEscape(b, len) + ")";
|
||||
return string("make_intrusive<StringVal>(") + Fmt(len) + ", " +
|
||||
CPPEscape(b, len) + ")";
|
||||
}
|
||||
|
||||
std::string CPPCompile::CPPEscape(const char* b, int len) const
|
||||
string CPPCompile::CPPEscape(const char* b, int len) const
|
||||
{
|
||||
std::string res = "\"";
|
||||
string res = "\"";
|
||||
|
||||
for ( int i = 0; i < len; ++i )
|
||||
{
|
||||
|
|
|
@ -11,21 +11,23 @@
|
|||
|
||||
namespace zeek::detail {
|
||||
|
||||
std::string CPPCompile::GenExprs(const Expr* e)
|
||||
using namespace std;
|
||||
|
||||
string CPPCompile::GenExprs(const Expr* e)
|
||||
{
|
||||
std::string gen;
|
||||
string gen;
|
||||
if ( e->Tag() == EXPR_LIST )
|
||||
gen = GenListExpr(e, GEN_VAL_PTR, true);
|
||||
else
|
||||
gen = GenExpr(e, GEN_VAL_PTR);
|
||||
|
||||
return std::string("{ ") + gen + " }";
|
||||
return string("{ ") + gen + " }";
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenListExpr(const Expr* e, GenType gt, bool nested)
|
||||
string CPPCompile::GenListExpr(const Expr* e, GenType gt, bool nested)
|
||||
{
|
||||
const auto& exprs = e->AsListExpr()->Exprs();
|
||||
std::string gen;
|
||||
string gen;
|
||||
|
||||
int n = exprs.size();
|
||||
|
||||
|
@ -36,7 +38,7 @@ std::string CPPCompile::GenListExpr(const Expr* e, GenType gt, bool nested)
|
|||
|
||||
if ( nested && e_i->Tag() == EXPR_LIST )
|
||||
// These are table or set indices.
|
||||
gen_i = std::string("index_val__CPP({") + gen_i + "})";
|
||||
gen_i = string("index_val__CPP({") + gen_i + "})";
|
||||
|
||||
gen += gen_i;
|
||||
|
||||
|
@ -47,9 +49,9 @@ std::string CPPCompile::GenListExpr(const Expr* e, GenType gt, bool nested)
|
|||
return gen;
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenExpr(const Expr* e, GenType gt, bool top_level)
|
||||
string CPPCompile::GenExpr(const Expr* e, GenType gt, bool top_level)
|
||||
{
|
||||
std::string gen;
|
||||
string gen;
|
||||
|
||||
switch ( e->Tag() ) {
|
||||
case EXPR_NAME: return GenNameExpr(e->AsNameExpr(), gt);
|
||||
|
@ -119,7 +121,7 @@ std::string CPPCompile::GenExpr(const Expr* e, GenType gt, bool top_level)
|
|||
ASSERT(0);
|
||||
|
||||
case EXPR_CAST:
|
||||
gen = std::string("cast_value_to_type__CPP(") +
|
||||
gen = string("cast_value_to_type__CPP(") +
|
||||
GenExpr(e->GetOp1(), GEN_VAL_PTR) + ", " +
|
||||
GenTypeName(e->GetType()) + ")";
|
||||
return GenericValPtrToGT(gen, e->GetType(), gt);
|
||||
|
@ -134,11 +136,11 @@ std::string CPPCompile::GenExpr(const Expr* e, GenType gt, bool top_level)
|
|||
default:
|
||||
// Intended to catch errors in overlooking the possible
|
||||
// expressions that might appear.
|
||||
return std::string("EXPR");
|
||||
return string("EXPR");
|
||||
}
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenNameExpr(const NameExpr* ne, GenType gt)
|
||||
string CPPCompile::GenNameExpr(const NameExpr* ne, GenType gt)
|
||||
{
|
||||
const auto& t = ne->GetType();
|
||||
auto n = ne->Id();
|
||||
|
@ -154,10 +156,10 @@ std::string CPPCompile::GenNameExpr(const NameExpr* ne, GenType gt)
|
|||
|
||||
if ( is_global_var )
|
||||
{
|
||||
std::string gen;
|
||||
string gen;
|
||||
|
||||
if ( n->IsType() )
|
||||
gen = std::string("make_intrusive<TypeVal>(") +
|
||||
gen = string("make_intrusive<TypeVal>(") +
|
||||
globals[n->Name()] +
|
||||
"->GetType(), true)";
|
||||
|
||||
|
@ -170,7 +172,7 @@ std::string CPPCompile::GenNameExpr(const NameExpr* ne, GenType gt)
|
|||
return NativeToGT(IDNameStr(n), t, gt);
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenConstExpr(const ConstExpr* c, GenType gt)
|
||||
string CPPCompile::GenConstExpr(const ConstExpr* c, GenType gt)
|
||||
{
|
||||
const auto& t = c->GetType();
|
||||
|
||||
|
@ -180,7 +182,7 @@ std::string CPPCompile::GenConstExpr(const ConstExpr* c, GenType gt)
|
|||
return NativeToGT(GenVal(c->ValuePtr()), t, gt);
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenIncrExpr(const Expr* e, GenType gt, bool is_incr, bool top_level)
|
||||
string CPPCompile::GenIncrExpr(const Expr* e, GenType gt, bool is_incr, bool top_level)
|
||||
{
|
||||
// For compound operands (table indexing, record fields),
|
||||
// Zeek's interpreter will actually evaluate the operand
|
||||
|
@ -214,7 +216,7 @@ std::string CPPCompile::GenIncrExpr(const Expr* e, GenType gt, bool is_incr, boo
|
|||
return gen;
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenCondExpr(const Expr* e, GenType gt)
|
||||
string CPPCompile::GenCondExpr(const Expr* e, GenType gt)
|
||||
{
|
||||
auto op1 = e->GetOp1();
|
||||
auto op2 = e->GetOp2();
|
||||
|
@ -225,14 +227,13 @@ std::string CPPCompile::GenCondExpr(const Expr* e, GenType gt)
|
|||
auto gen3 = GenExpr(op3, gt);
|
||||
|
||||
if ( op1->GetType()->Tag() == TYPE_VECTOR )
|
||||
return std::string("vector_select__CPP(") +
|
||||
gen1 + ", " + gen2 + ", " + gen3 + ")";
|
||||
return string("vector_select__CPP(") +
|
||||
gen1 + ", " + gen2 + ", " + gen3 + ")";
|
||||
|
||||
return std::string("(") + gen1 + ") ? (" +
|
||||
gen2 + ") : (" + gen3 + ")";
|
||||
return string("(") + gen1 + ") ? (" + gen2 + ") : (" + gen3 + ")";
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenCallExpr(const CallExpr* c, GenType gt)
|
||||
string CPPCompile::GenCallExpr(const CallExpr* c, GenType gt)
|
||||
{
|
||||
const auto& t = c->GetType();
|
||||
auto f = c->Func();
|
||||
|
@ -276,17 +277,15 @@ std::string CPPCompile::GenCallExpr(const CallExpr* c, GenType gt)
|
|||
else if ( pfs.Globals().count(f_id) > 0 )
|
||||
// The BiF version has an extra "_", per
|
||||
// AddBiF(..., true).
|
||||
gen = globals[std::string(id_name) + "_"];
|
||||
gen = globals[string(id_name) + "_"];
|
||||
}
|
||||
|
||||
else
|
||||
// Indirect call.
|
||||
gen = std::string("(") + gen + ")->AsFunc()";
|
||||
gen = string("(") + gen + ")->AsFunc()";
|
||||
|
||||
auto args_list = std::string(", {") +
|
||||
GenExpr(args_l, GEN_VAL_PTR) + "}";
|
||||
auto invoker = std::string("invoke__CPP(") +
|
||||
gen + args_list + ", f__CPP)";
|
||||
auto args_list = string(", {") + GenExpr(args_l, GEN_VAL_PTR) + "}";
|
||||
auto invoker = string("invoke__CPP(") + gen + args_list + ", f__CPP)";
|
||||
|
||||
if ( IsNativeType(t) && gt != GEN_VAL_PTR )
|
||||
return invoker + NativeAccessor(t);
|
||||
|
@ -294,7 +293,7 @@ std::string CPPCompile::GenCallExpr(const CallExpr* c, GenType gt)
|
|||
return GenericValPtrToGT(invoker, t, gt);
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenInExpr(const Expr* e, GenType gt)
|
||||
string CPPCompile::GenInExpr(const Expr* e, GenType gt)
|
||||
{
|
||||
auto op1 = e->GetOp1();
|
||||
auto op2 = e->GetOp2();
|
||||
|
@ -302,20 +301,20 @@ std::string CPPCompile::GenInExpr(const Expr* e, GenType gt)
|
|||
auto t1 = op1->GetType();
|
||||
auto t2 = op2->GetType();
|
||||
|
||||
std::string gen;
|
||||
string gen;
|
||||
|
||||
if ( t1->Tag() == TYPE_PATTERN )
|
||||
gen = std::string("(") + GenExpr(op1, GEN_DONT_CARE) +
|
||||
gen = string("(") + GenExpr(op1, GEN_DONT_CARE) +
|
||||
")->MatchAnywhere(" +
|
||||
GenExpr(op2, GEN_DONT_CARE) + "->AsString())";
|
||||
|
||||
else if ( t2->Tag() == TYPE_STRING )
|
||||
gen = std::string("str_in__CPP(") +
|
||||
gen = string("str_in__CPP(") +
|
||||
GenExpr(op1, GEN_DONT_CARE) + "->AsString(), " +
|
||||
GenExpr(op2, GEN_DONT_CARE) + "->AsString())";
|
||||
|
||||
else if ( t1->Tag() == TYPE_ADDR && t2->Tag() == TYPE_SUBNET )
|
||||
gen = std::string("(") + GenExpr(op2, GEN_DONT_CARE) +
|
||||
gen = string("(") + GenExpr(op2, GEN_DONT_CARE) +
|
||||
")->Contains(" + GenExpr(op1, GEN_VAL_PTR) + "->Get())";
|
||||
|
||||
else if ( t2->Tag() == TYPE_VECTOR )
|
||||
|
@ -323,47 +322,47 @@ std::string CPPCompile::GenInExpr(const Expr* e, GenType gt)
|
|||
GenExpr(op1, GEN_NATIVE) + ")";
|
||||
|
||||
else
|
||||
gen = std::string("(") + GenExpr(op2, GEN_DONT_CARE) +
|
||||
gen = string("(") + GenExpr(op2, GEN_DONT_CARE) +
|
||||
"->Find(index_val__CPP({" + GenExpr(op1, GEN_VAL_PTR) +
|
||||
"})) ? true : false)";
|
||||
|
||||
return NativeToGT(gen, e->GetType(), gt);
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenFieldExpr(const FieldExpr* fe, GenType gt)
|
||||
string CPPCompile::GenFieldExpr(const FieldExpr* fe, GenType gt)
|
||||
{
|
||||
auto r = fe->GetOp1();
|
||||
auto f = fe->Field();
|
||||
auto f_s = GenField(r, f);
|
||||
|
||||
auto gen = std::string("field_access__CPP(") +
|
||||
GenExpr(r, GEN_VAL_PTR) + ", " + f_s + ")";
|
||||
auto gen = string("field_access__CPP(") + GenExpr(r, GEN_VAL_PTR) +
|
||||
", " + f_s + ")";
|
||||
|
||||
return GenericValPtrToGT(gen, fe->GetType(), gt);
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenHasFieldExpr(const HasFieldExpr* hfe, GenType gt)
|
||||
string CPPCompile::GenHasFieldExpr(const HasFieldExpr* hfe, GenType gt)
|
||||
{
|
||||
auto r = hfe->GetOp1();
|
||||
auto f = hfe->Field();
|
||||
auto f_s = GenField(r, f);
|
||||
|
||||
// Need to use accessors for native types.
|
||||
auto gen = std::string("(") + GenExpr(r, GEN_DONT_CARE) +
|
||||
auto gen = string("(") + GenExpr(r, GEN_DONT_CARE) +
|
||||
"->GetField(" + f_s + ") != nullptr)";
|
||||
|
||||
return NativeToGT(gen, hfe->GetType(), gt);
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenIndexExpr(const Expr* e, GenType gt)
|
||||
string CPPCompile::GenIndexExpr(const Expr* e, GenType gt)
|
||||
{
|
||||
auto aggr = e->GetOp1();
|
||||
const auto& aggr_t = aggr->GetType();
|
||||
|
||||
std::string gen;
|
||||
string gen;
|
||||
|
||||
if ( aggr_t->Tag() == TYPE_TABLE )
|
||||
gen = std::string("index_table__CPP(") +
|
||||
gen = string("index_table__CPP(") +
|
||||
GenExpr(aggr, GEN_NATIVE) + ", {" +
|
||||
GenExpr(e->GetOp2(), GEN_VAL_PTR) + "})";
|
||||
|
||||
|
@ -379,26 +378,26 @@ std::string CPPCompile::GenIndexExpr(const Expr* e, GenType gt)
|
|||
auto& inds = op2->AsListExpr()->Exprs();
|
||||
auto first = inds[0];
|
||||
auto last = inds[1];
|
||||
gen = std::string("index_slice(") +
|
||||
gen = string("index_slice(") +
|
||||
GenExpr(aggr, GEN_VAL_PTR) + ".get(), " +
|
||||
GenExpr(first, GEN_NATIVE) + ", " +
|
||||
GenExpr(last, GEN_NATIVE) + ")";
|
||||
}
|
||||
else
|
||||
gen = std::string("index_vec__CPP(") +
|
||||
gen = string("index_vec__CPP(") +
|
||||
GenExpr(aggr, GEN_NATIVE) + ", " +
|
||||
GenExpr(e->GetOp2(), GEN_NATIVE) + ")";
|
||||
}
|
||||
|
||||
else if ( aggr_t->Tag() == TYPE_STRING )
|
||||
gen = std::string("index_string__CPP(") +
|
||||
gen = string("index_string__CPP(") +
|
||||
GenExpr(aggr, GEN_NATIVE) + ", {" +
|
||||
GenExpr(e->GetOp2(), GEN_VAL_PTR) + "})";
|
||||
|
||||
return GenericValPtrToGT(gen, e->GetType(), gt);
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenAssignExpr(const Expr* e, GenType gt, bool top_level)
|
||||
string CPPCompile::GenAssignExpr(const Expr* e, GenType gt, bool top_level)
|
||||
{
|
||||
auto op1 = e->GetOp1()->AsRefExprPtr()->GetOp1();
|
||||
auto op2 = e->GetOp2();
|
||||
|
@ -422,13 +421,13 @@ std::string CPPCompile::GenAssignExpr(const Expr* e, GenType gt, bool top_level)
|
|||
return GenAssign(op1, op2, rhs_native, rhs_val_ptr, gt, top_level);
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenAddToExpr(const Expr* e, GenType gt, bool top_level)
|
||||
string CPPCompile::GenAddToExpr(const Expr* e, GenType gt, bool top_level)
|
||||
{
|
||||
const auto& t = e->GetType();
|
||||
|
||||
if ( t->Tag() == TYPE_VECTOR )
|
||||
{
|
||||
auto gen = std::string("vector_append__CPP(") +
|
||||
auto gen = string("vector_append__CPP(") +
|
||||
GenExpr(e->GetOp1(), GEN_VAL_PTR) +
|
||||
", " + GenExpr(e->GetOp2(), GEN_VAL_PTR) + ")";
|
||||
return GenericValPtrToGT(gen, t, gt);
|
||||
|
@ -463,7 +462,7 @@ std::string CPPCompile::GenAddToExpr(const Expr* e, GenType gt, bool top_level)
|
|||
return GenBinary(e, gt, "+=");
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenSizeExpr(const Expr* e, GenType gt)
|
||||
string CPPCompile::GenSizeExpr(const Expr* e, GenType gt)
|
||||
{
|
||||
const auto& t = e->GetType();
|
||||
const auto& t1 = e->GetOp1()->GetType();
|
||||
|
@ -472,22 +471,22 @@ std::string CPPCompile::GenSizeExpr(const Expr* e, GenType gt)
|
|||
auto gen = GenExpr(e->GetOp1(), GEN_NATIVE);
|
||||
|
||||
if ( t1->Tag() == TYPE_BOOL )
|
||||
gen = std::string("((") + gen + ") ? 1 : 0)";
|
||||
gen = string("((") + gen + ") ? 1 : 0)";
|
||||
|
||||
else if ( it == TYPE_INTERNAL_UNSIGNED )
|
||||
// no-op
|
||||
;
|
||||
|
||||
else if ( it == TYPE_INTERNAL_INT )
|
||||
gen = std::string("iabs__CPP(") + gen + ")";
|
||||
gen = string("iabs__CPP(") + gen + ")";
|
||||
|
||||
else if ( it == TYPE_INTERNAL_DOUBLE )
|
||||
gen = std::string("fabs__CPP(") + gen + ")";
|
||||
gen = string("fabs__CPP(") + gen + ")";
|
||||
|
||||
else if ( it == TYPE_INTERNAL_INT || it == TYPE_INTERNAL_DOUBLE )
|
||||
{
|
||||
auto cast = (it == TYPE_INTERNAL_INT) ? "bro_int_t" : "double";
|
||||
gen = std::string("abs__CPP(") + cast + "(" + gen + "))";
|
||||
gen = string("abs__CPP(") + cast + "(" + gen + "))";
|
||||
}
|
||||
|
||||
else
|
||||
|
@ -496,51 +495,51 @@ std::string CPPCompile::GenSizeExpr(const Expr* e, GenType gt)
|
|||
return NativeToGT(gen, t, gt);
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenScheduleExpr(const Expr* e)
|
||||
string CPPCompile::GenScheduleExpr(const Expr* e)
|
||||
{
|
||||
auto s = static_cast<const ScheduleExpr*>(e);
|
||||
auto when = s->When();
|
||||
auto event = s->Event();
|
||||
std::string event_name(event->Handler()->Name());
|
||||
string event_name(event->Handler()->Name());
|
||||
|
||||
RegisterEvent(event_name);
|
||||
|
||||
std::string when_s = GenExpr(when, GEN_NATIVE);
|
||||
string when_s = GenExpr(when, GEN_NATIVE);
|
||||
if ( when->GetType()->Tag() == TYPE_INTERVAL )
|
||||
when_s += " + run_state::network_time";
|
||||
|
||||
return std::string("schedule__CPP(") + when_s +
|
||||
return string("schedule__CPP(") + when_s +
|
||||
", " + globals[event_name] + "_ev, { " +
|
||||
GenExpr(event->Args(), GEN_VAL_PTR) + " })";
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenLambdaExpr(const Expr* e)
|
||||
string CPPCompile::GenLambdaExpr(const Expr* e)
|
||||
{
|
||||
auto l = static_cast<const LambdaExpr*>(e);
|
||||
auto name = Canonicalize(l->Name().c_str()) + "_lb_cl";
|
||||
auto cl_args = std::string("\"") + name + "\"";
|
||||
auto cl_args = string("\"") + name + "\"";
|
||||
|
||||
if ( l->OuterIDs().size() > 0 )
|
||||
cl_args = cl_args + GenLambdaClone(l, false);
|
||||
|
||||
auto body = std::string("make_intrusive<") + name + ">(" + cl_args + ")";
|
||||
auto func = std::string("make_intrusive<CPPLambdaFunc>(\"") +
|
||||
auto body = string("make_intrusive<") + name + ">(" + cl_args + ")";
|
||||
auto func = string("make_intrusive<CPPLambdaFunc>(\"") +
|
||||
l->Name() + "\", cast_intrusive<FuncType>(" +
|
||||
GenTypeName(l->GetType()) + "), " + body + ")";
|
||||
return std::string("make_intrusive<FuncVal>(") + func + ")";
|
||||
return string("make_intrusive<FuncVal>(") + func + ")";
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenIsExpr(const Expr* e, GenType gt)
|
||||
string CPPCompile::GenIsExpr(const Expr* e, GenType gt)
|
||||
{
|
||||
auto ie = static_cast<const IsExpr*>(e);
|
||||
auto gen = std::string("can_cast_value_to_type(") +
|
||||
auto gen = string("can_cast_value_to_type(") +
|
||||
GenExpr(ie->GetOp1(), GEN_VAL_PTR) + ".get(), " +
|
||||
GenTypeName(ie->TestType()) + ".get())";
|
||||
|
||||
return NativeToGT(gen, ie->GetType(), gt);
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenArithCoerceExpr(const Expr* e, GenType gt)
|
||||
string CPPCompile::GenArithCoerceExpr(const Expr* e, GenType gt)
|
||||
{
|
||||
const auto& t = e->GetType();
|
||||
auto op = e->GetOp1();
|
||||
|
@ -552,7 +551,7 @@ std::string CPPCompile::GenArithCoerceExpr(const Expr* e, GenType gt)
|
|||
|
||||
auto coerce_t = is_vec ? t->Yield() : t;
|
||||
|
||||
std::string cast_name;
|
||||
string cast_name;
|
||||
|
||||
switch ( coerce_t->InternalType() ) {
|
||||
case TYPE_INTERNAL_INT: cast_name = "bro_int_t"; break;
|
||||
|
@ -564,14 +563,14 @@ std::string CPPCompile::GenArithCoerceExpr(const Expr* e, GenType gt)
|
|||
}
|
||||
|
||||
if ( is_vec )
|
||||
return std::string("vec_coerce_") + cast_name +
|
||||
return string("vec_coerce_") + cast_name +
|
||||
"__CPP(" + GenExpr(op, GEN_NATIVE) +
|
||||
", " + GenTypeName(t) + ")";
|
||||
|
||||
return NativeToGT(cast_name + "(" + GenExpr(op, GEN_NATIVE) + ")", t, gt);
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenRecordCoerceExpr(const Expr* e)
|
||||
string CPPCompile::GenRecordCoerceExpr(const Expr* e)
|
||||
{
|
||||
auto rc = static_cast<const RecordCoerceExpr*>(e);
|
||||
auto op1 = rc->GetOp1();
|
||||
|
@ -585,39 +584,39 @@ std::string CPPCompile::GenRecordCoerceExpr(const Expr* e)
|
|||
const auto& map = rc->Map();
|
||||
auto type_var = GenTypeName(to_type);
|
||||
|
||||
return std::string("coerce_to_record(cast_intrusive<RecordType>(") +
|
||||
return string("coerce_to_record(cast_intrusive<RecordType>(") +
|
||||
type_var + "), " + GenExpr(op1, GEN_VAL_PTR) + ".get(), " +
|
||||
GenIntVector(map) + ")";
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenTableCoerceExpr(const Expr* e)
|
||||
string CPPCompile::GenTableCoerceExpr(const Expr* e)
|
||||
{
|
||||
auto tc = static_cast<const TableCoerceExpr*>(e);
|
||||
const auto& t = tc->GetType();
|
||||
auto op1 = tc->GetOp1();
|
||||
|
||||
return std::string("table_coerce__CPP(") + GenExpr(op1, GEN_VAL_PTR) +
|
||||
return string("table_coerce__CPP(") + GenExpr(op1, GEN_VAL_PTR) +
|
||||
", " + GenTypeName(t) + ")";
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenVectorCoerceExpr(const Expr* e)
|
||||
string CPPCompile::GenVectorCoerceExpr(const Expr* e)
|
||||
{
|
||||
auto vc = static_cast<const VectorCoerceExpr*>(e);
|
||||
const auto& op = vc->GetOp1();
|
||||
const auto& t = vc->GetType<VectorType>();
|
||||
|
||||
return std::string("vector_coerce__CPP(" + GenExpr(op, GEN_VAL_PTR) +
|
||||
return string("vector_coerce__CPP(" + GenExpr(op, GEN_VAL_PTR) +
|
||||
", " + GenTypeName(t) + ")");
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenRecordConstructorExpr(const Expr* e)
|
||||
string CPPCompile::GenRecordConstructorExpr(const Expr* e)
|
||||
{
|
||||
auto rc = static_cast<const RecordConstructorExpr*>(e);
|
||||
const auto& t = rc->GetType();
|
||||
const auto& exprs = rc->Op()->AsListExpr()->Exprs();
|
||||
auto n = exprs.length();
|
||||
|
||||
std::string vals;
|
||||
string vals;
|
||||
|
||||
for ( auto i = 0; i < n; ++i )
|
||||
{
|
||||
|
@ -631,38 +630,38 @@ std::string CPPCompile::GenRecordConstructorExpr(const Expr* e)
|
|||
vals += ", ";
|
||||
}
|
||||
|
||||
return std::string("record_constructor__CPP({") + vals + "}, " +
|
||||
return string("record_constructor__CPP({") + vals + "}, " +
|
||||
"cast_intrusive<RecordType>(" + GenTypeName(t) + "))";
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenSetConstructorExpr(const Expr* e)
|
||||
string CPPCompile::GenSetConstructorExpr(const Expr* e)
|
||||
{
|
||||
auto sc = static_cast<const SetConstructorExpr*>(e);
|
||||
const auto& t = sc->GetType();
|
||||
auto attrs = sc->GetAttrs();
|
||||
|
||||
std::string attr_tags;
|
||||
std::string attr_vals;
|
||||
string attr_tags;
|
||||
string attr_vals;
|
||||
BuildAttrs(attrs, attr_tags, attr_vals);
|
||||
|
||||
return std::string("set_constructor__CPP(") +
|
||||
return string("set_constructor__CPP(") +
|
||||
GenExprs(sc->GetOp1().get()) + ", " +
|
||||
"cast_intrusive<TableType>(" + GenTypeName(t) + "), " +
|
||||
attr_tags + ", " + attr_vals + ")";
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenTableConstructorExpr(const Expr* e)
|
||||
string CPPCompile::GenTableConstructorExpr(const Expr* e)
|
||||
{
|
||||
auto tc = static_cast<const TableConstructorExpr*>(e);
|
||||
const auto& t = tc->GetType();
|
||||
auto attrs = tc->GetAttrs();
|
||||
|
||||
std::string attr_tags;
|
||||
std::string attr_vals;
|
||||
string attr_tags;
|
||||
string attr_vals;
|
||||
BuildAttrs(attrs, attr_tags, attr_vals);
|
||||
|
||||
std::string indices;
|
||||
std::string vals;
|
||||
string indices;
|
||||
string vals;
|
||||
|
||||
const auto& exprs = tc->GetOp1()->AsListExpr()->Exprs();
|
||||
auto n = exprs.length();
|
||||
|
@ -692,30 +691,30 @@ std::string CPPCompile::GenTableConstructorExpr(const Expr* e)
|
|||
}
|
||||
}
|
||||
|
||||
return std::string("table_constructor__CPP({") +
|
||||
return string("table_constructor__CPP({") +
|
||||
indices + "}, {" + vals + "}, " +
|
||||
"cast_intrusive<TableType>(" + GenTypeName(t) + "), " +
|
||||
attr_tags + ", " + attr_vals + ")";
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenVectorConstructorExpr(const Expr* e)
|
||||
string CPPCompile::GenVectorConstructorExpr(const Expr* e)
|
||||
{
|
||||
auto vc = static_cast<const VectorConstructorExpr*>(e);
|
||||
const auto& t = vc->GetType();
|
||||
|
||||
return std::string("vector_constructor__CPP({") +
|
||||
return string("vector_constructor__CPP({") +
|
||||
GenExpr(vc->GetOp1(), GEN_VAL_PTR) + "}, " +
|
||||
"cast_intrusive<VectorType>(" + GenTypeName(t) + "))";
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenVal(const ValPtr& v)
|
||||
string CPPCompile::GenVal(const ValPtr& v)
|
||||
{
|
||||
const auto& t = v->GetType();
|
||||
auto tag = t->Tag();
|
||||
auto it = t->InternalType();
|
||||
|
||||
if ( tag == TYPE_BOOL )
|
||||
return std::string(v->IsZero() ? "false" : "true");
|
||||
return string(v->IsZero() ? "false" : "true");
|
||||
|
||||
if ( tag == TYPE_ENUM )
|
||||
return GenEnum(t, v);
|
||||
|
@ -732,18 +731,18 @@ std::string CPPCompile::GenVal(const ValPtr& v)
|
|||
return d.Description();
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenUnary(const Expr* e, GenType gt,
|
||||
string CPPCompile::GenUnary(const Expr* e, GenType gt,
|
||||
const char* op, const char* vec_op)
|
||||
{
|
||||
if ( e->GetType()->Tag() == TYPE_VECTOR )
|
||||
return GenVectorOp(e, GenExpr(e->GetOp1(), GEN_NATIVE), vec_op);
|
||||
|
||||
return NativeToGT(std::string(op) + "(" +
|
||||
return NativeToGT(string(op) + "(" +
|
||||
GenExpr(e->GetOp1(), GEN_NATIVE) + ")",
|
||||
e->GetType(), gt);
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenBinary(const Expr* e, GenType gt,
|
||||
string CPPCompile::GenBinary(const Expr* e, GenType gt,
|
||||
const char* op, const char* vec_op)
|
||||
{
|
||||
const auto& op1 = e->GetOp1();
|
||||
|
@ -758,7 +757,7 @@ std::string CPPCompile::GenBinary(const Expr* e, GenType gt,
|
|||
if ( t->Tag() == TYPE_VECTOR &&
|
||||
t->Yield()->Tag() == TYPE_STRING &&
|
||||
op2->GetType()->Tag() == TYPE_VECTOR )
|
||||
return std::string("vec_str_op_") + vec_op + "__CPP(" +
|
||||
return string("vec_str_op_") + vec_op + "__CPP(" +
|
||||
gen1 + ", " + gen2 + ")";
|
||||
|
||||
return GenVectorOp(e, gen1, gen2, vec_op);
|
||||
|
@ -771,7 +770,7 @@ std::string CPPCompile::GenBinary(const Expr* e, GenType gt,
|
|||
// operations. For those, it holds the prefix we use to
|
||||
// distinguish different instances of inlined functions
|
||||
// employed to support an operation.
|
||||
std::string flavor;
|
||||
string flavor;
|
||||
|
||||
switch ( t->InternalType() ) {
|
||||
case TYPE_INTERNAL_INT: flavor = "i"; break;
|
||||
|
@ -791,7 +790,7 @@ std::string CPPCompile::GenBinary(const Expr* e, GenType gt,
|
|||
auto g1 = GenExpr(e->GetOp1(), GEN_NATIVE);
|
||||
auto g2 = GenExpr(e->GetOp2(), GEN_NATIVE);
|
||||
|
||||
std::string gen;
|
||||
string gen;
|
||||
|
||||
if ( e->Tag() == EXPR_DIVIDE )
|
||||
gen = flavor + "div__CPP(" + g1 + ", " + g2 + ")";
|
||||
|
@ -800,17 +799,17 @@ std::string CPPCompile::GenBinary(const Expr* e, GenType gt,
|
|||
gen = flavor + "mod__CPP(" + g1 + ", " + g2 + ")";
|
||||
|
||||
else
|
||||
gen = std::string("(") + g1 + ")" + op + "(" + g2 + ")";
|
||||
gen = string("(") + g1 + ")" + op + "(" + g2 + ")";
|
||||
|
||||
return NativeToGT(gen, e->GetType(), gt);
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenBinarySet(const Expr* e, GenType gt, const char* op)
|
||||
string CPPCompile::GenBinarySet(const Expr* e, GenType gt, const char* op)
|
||||
{
|
||||
auto v1 = GenExpr(e->GetOp1(), GEN_DONT_CARE) + "->AsTableVal()";
|
||||
auto v2 = GenExpr(e->GetOp2(), GEN_DONT_CARE) + "->AsTableVal()";
|
||||
|
||||
std::string res;
|
||||
string res;
|
||||
|
||||
switch ( e->Tag() ) {
|
||||
case EXPR_AND:
|
||||
|
@ -830,7 +829,7 @@ std::string CPPCompile::GenBinarySet(const Expr* e, GenType gt, const char* op)
|
|||
break;
|
||||
|
||||
case EXPR_NE:
|
||||
res = std::string("! ") + v1 + "->EqualTo(*" + v2 + ")";
|
||||
res = string("! ") + v1 + "->EqualTo(*" + v2 + ")";
|
||||
break;
|
||||
|
||||
case EXPR_LE:
|
||||
|
@ -838,7 +837,7 @@ std::string CPPCompile::GenBinarySet(const Expr* e, GenType gt, const char* op)
|
|||
break;
|
||||
|
||||
case EXPR_LT:
|
||||
res = std::string("(") + v1 + "->IsSubsetOf(*" + v2 + ") &&" +
|
||||
res = string("(") + v1 + "->IsSubsetOf(*" + v2 + ") &&" +
|
||||
v1 + "->Size() < " + v2 + "->Size())";
|
||||
break;
|
||||
|
||||
|
@ -849,23 +848,23 @@ std::string CPPCompile::GenBinarySet(const Expr* e, GenType gt, const char* op)
|
|||
return NativeToGT(res, e->GetType(), gt);
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenBinaryString(const Expr* e, GenType gt,
|
||||
string CPPCompile::GenBinaryString(const Expr* e, GenType gt,
|
||||
const char* op)
|
||||
{
|
||||
auto v1 = GenExpr(e->GetOp1(), GEN_DONT_CARE) + "->AsString()";
|
||||
auto v2 = GenExpr(e->GetOp2(), GEN_DONT_CARE) + "->AsString()";
|
||||
|
||||
std::string res;
|
||||
string res;
|
||||
|
||||
if ( e->Tag() == EXPR_ADD || e->Tag() == EXPR_ADD_TO )
|
||||
res = std::string("str_concat__CPP(") + v1 + ", " + v2 + ")";
|
||||
res = string("str_concat__CPP(") + v1 + ", " + v2 + ")";
|
||||
else
|
||||
res = std::string("(Bstr_cmp(") + v1 + ", " + v2 + ") " + op + " 0)";
|
||||
res = string("(Bstr_cmp(") + v1 + ", " + v2 + ") " + op + " 0)";
|
||||
|
||||
return NativeToGT(res, e->GetType(), gt);
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenBinaryPattern(const Expr* e, GenType gt,
|
||||
string CPPCompile::GenBinaryPattern(const Expr* e, GenType gt,
|
||||
const char* op)
|
||||
{
|
||||
auto v1 = GenExpr(e->GetOp1(), GEN_DONT_CARE) + "->AsPattern()";
|
||||
|
@ -874,17 +873,17 @@ std::string CPPCompile::GenBinaryPattern(const Expr* e, GenType gt,
|
|||
auto func = e->Tag() == EXPR_AND ?
|
||||
"RE_Matcher_conjunction" : "RE_Matcher_disjunction";
|
||||
|
||||
return NativeToGT(std::string("make_intrusive<PatternVal>(") +
|
||||
return NativeToGT(string("make_intrusive<PatternVal>(") +
|
||||
func + "(" + v1 + ", " + v2 + "))", e->GetType(), gt);
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenBinaryAddr(const Expr* e, GenType gt, const char* op)
|
||||
string CPPCompile::GenBinaryAddr(const Expr* e, GenType gt, const char* op)
|
||||
{
|
||||
auto v1 = GenExpr(e->GetOp1(), GEN_DONT_CARE) + "->AsAddr()";
|
||||
|
||||
if ( e->Tag() == EXPR_DIVIDE )
|
||||
{
|
||||
auto gen = std::string("addr_mask__CPP(") + v1 + ", " +
|
||||
auto gen = string("addr_mask__CPP(") + v1 + ", " +
|
||||
GenExpr(e->GetOp2(), GEN_NATIVE) + ")";
|
||||
|
||||
return NativeToGT(gen, e->GetType(), gt);
|
||||
|
@ -895,8 +894,7 @@ std::string CPPCompile::GenBinaryAddr(const Expr* e, GenType gt, const char* op)
|
|||
return NativeToGT(v1 + op + v2, e->GetType(), gt);
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenBinarySubNet(const Expr* e, GenType gt,
|
||||
const char* op)
|
||||
string CPPCompile::GenBinarySubNet(const Expr* e, GenType gt, const char* op)
|
||||
{
|
||||
auto v1 = GenExpr(e->GetOp1(), GEN_DONT_CARE) + "->AsSubNet()";
|
||||
auto v2 = GenExpr(e->GetOp2(), GEN_DONT_CARE) + "->AsSubNet()";
|
||||
|
@ -904,8 +902,8 @@ std::string CPPCompile::GenBinarySubNet(const Expr* e, GenType gt,
|
|||
return NativeToGT(v1 + op + v2, e->GetType(), gt);
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenEQ(const Expr* e, GenType gt,
|
||||
const char* op, const char* vec_op)
|
||||
string CPPCompile::GenEQ(const Expr* e, GenType gt,
|
||||
const char* op, const char* vec_op)
|
||||
{
|
||||
auto op1 = e->GetOp1();
|
||||
auto op2 = e->GetOp2();
|
||||
|
@ -918,7 +916,7 @@ std::string CPPCompile::GenEQ(const Expr* e, GenType gt,
|
|||
}
|
||||
|
||||
auto tag = op1->GetType()->Tag();
|
||||
std::string negated(e->Tag() == EXPR_EQ ? "" : "! ");
|
||||
string negated(e->Tag() == EXPR_EQ ? "" : "! ");
|
||||
|
||||
if ( tag == TYPE_PATTERN )
|
||||
return NativeToGT(negated + GenExpr(op1, GEN_DONT_CARE) +
|
||||
|
@ -934,7 +932,7 @@ std::string CPPCompile::GenEQ(const Expr* e, GenType gt,
|
|||
gen_f1 += "->AsFunc()";
|
||||
gen_f2 += "->AsFunc()";
|
||||
|
||||
auto gen = std::string("(") + gen_f1 + "==" + gen_f2 + ")";
|
||||
auto gen = string("(") + gen_f1 + "==" + gen_f2 + ")";
|
||||
|
||||
return NativeToGT(negated + gen, e->GetType(), gt);
|
||||
}
|
||||
|
@ -942,10 +940,10 @@ std::string CPPCompile::GenEQ(const Expr* e, GenType gt,
|
|||
return GenBinary(e, gt, op, vec_op);
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenAssign(const ExprPtr& lhs, const ExprPtr& rhs,
|
||||
const std::string& rhs_native,
|
||||
const std::string& rhs_val_ptr,
|
||||
GenType gt, bool top_level)
|
||||
string CPPCompile::GenAssign(const ExprPtr& lhs, const ExprPtr& rhs,
|
||||
const string& rhs_native,
|
||||
const string& rhs_val_ptr,
|
||||
GenType gt, bool top_level)
|
||||
{
|
||||
switch ( lhs->Tag() ) {
|
||||
case EXPR_NAME:
|
||||
|
@ -966,15 +964,14 @@ std::string CPPCompile::GenAssign(const ExprPtr& lhs, const ExprPtr& rhs,
|
|||
}
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenDirectAssign(const ExprPtr& lhs,
|
||||
const std::string& rhs_native,
|
||||
const std::string& rhs_val_ptr,
|
||||
GenType gt, bool top_level)
|
||||
string CPPCompile::GenDirectAssign(const ExprPtr& lhs, const string& rhs_native,
|
||||
const string& rhs_val_ptr, GenType gt,
|
||||
bool top_level)
|
||||
{
|
||||
auto n = lhs->AsNameExpr()->Id();
|
||||
auto name = IDNameStr(n);
|
||||
|
||||
std::string gen;
|
||||
string gen;
|
||||
|
||||
if ( n->IsGlobal() )
|
||||
{
|
||||
|
@ -984,7 +981,7 @@ std::string CPPCompile::GenDirectAssign(const ExprPtr& lhs,
|
|||
if ( t->Tag() == TYPE_FUNC &&
|
||||
t->AsFuncType()->Flavor() == FUNC_FLAVOR_EVENT )
|
||||
{
|
||||
gen = std::string("set_event__CPP(") + gn + ", " +
|
||||
gen = string("set_event__CPP(") + gn + ", " +
|
||||
rhs_val_ptr + ", " + gn + "_ev)";
|
||||
|
||||
if ( ! top_level )
|
||||
|
@ -996,7 +993,7 @@ std::string CPPCompile::GenDirectAssign(const ExprPtr& lhs,
|
|||
|
||||
else
|
||||
{
|
||||
gen = std::string("set_global__CPP(") +
|
||||
gen = string("set_global__CPP(") +
|
||||
gn + ", " + rhs_val_ptr + ")";
|
||||
gen = GenericValPtrToGT(gen, n->GetType(), gt);
|
||||
}
|
||||
|
@ -1007,11 +1004,11 @@ std::string CPPCompile::GenDirectAssign(const ExprPtr& lhs,
|
|||
return gen;
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenIndexAssign(const ExprPtr& lhs, const ExprPtr& rhs,
|
||||
const std::string& rhs_val_ptr,
|
||||
GenType gt, bool top_level)
|
||||
string CPPCompile::GenIndexAssign(const ExprPtr& lhs, const ExprPtr& rhs,
|
||||
const string& rhs_val_ptr,
|
||||
GenType gt, bool top_level)
|
||||
{
|
||||
auto gen = std::string("assign_to_index__CPP(");
|
||||
auto gen = string("assign_to_index__CPP(");
|
||||
|
||||
gen += GenExpr(lhs->GetOp1(), GEN_VAL_PTR) + ", " + "index_val__CPP({" +
|
||||
GenExpr(lhs->GetOp2(), GEN_VAL_PTR) + "}), " + rhs_val_ptr + ")";
|
||||
|
@ -1022,9 +1019,9 @@ std::string CPPCompile::GenIndexAssign(const ExprPtr& lhs, const ExprPtr& rhs,
|
|||
return gen;
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenFieldAssign(const ExprPtr& lhs, const ExprPtr& rhs,
|
||||
const std::string& rhs_val_ptr,
|
||||
GenType gt, bool top_level)
|
||||
string CPPCompile::GenFieldAssign(const ExprPtr& lhs, const ExprPtr& rhs,
|
||||
const string& rhs_val_ptr, GenType gt,
|
||||
bool top_level)
|
||||
{
|
||||
auto rec = lhs->GetOp1();
|
||||
auto rec_gen = GenExpr(rec, GEN_VAL_PTR);
|
||||
|
@ -1034,18 +1031,18 @@ std::string CPPCompile::GenFieldAssign(const ExprPtr& lhs, const ExprPtr& rhs,
|
|||
return rec_gen + "->Assign(" + field + ", " + rhs_val_ptr + ")";
|
||||
else
|
||||
{
|
||||
auto gen = std::string("assign_field__CPP(") + rec_gen +
|
||||
auto gen = string("assign_field__CPP(") + rec_gen +
|
||||
", " + field + ", " + rhs_val_ptr + ")";
|
||||
return GenericValPtrToGT(gen, rhs->GetType(), gt);
|
||||
}
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenListAssign(const ExprPtr& lhs, const ExprPtr& rhs)
|
||||
string CPPCompile::GenListAssign(const ExprPtr& lhs, const ExprPtr& rhs)
|
||||
{
|
||||
if ( rhs->Tag() != EXPR_NAME )
|
||||
reporter->InternalError("compound RHS expression in multi-assignment");
|
||||
|
||||
std::string gen;
|
||||
string gen;
|
||||
const auto& vars = lhs->AsListExpr()->Exprs();
|
||||
|
||||
auto n = vars.length();
|
||||
|
@ -1071,42 +1068,41 @@ std::string CPPCompile::GenListAssign(const ExprPtr& lhs, const ExprPtr& rhs)
|
|||
return "(" + gen + ")";
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenVectorOp(const Expr* e, std::string op,
|
||||
const char* vec_op)
|
||||
string CPPCompile::GenVectorOp(const Expr* e, string op, const char* vec_op)
|
||||
{
|
||||
auto gen = std::string("vec_op_") + vec_op + "__CPP(" + op + ")";
|
||||
auto gen = string("vec_op_") + vec_op + "__CPP(" + op + ")";
|
||||
|
||||
if ( ! IsArithmetic(e->GetType()->Yield()->Tag()) )
|
||||
gen = std::string("vector_coerce_to__CPP(") + gen + ", " +
|
||||
gen = string("vector_coerce_to__CPP(") + gen + ", " +
|
||||
GenTypeName(e->GetType()) + ")";
|
||||
|
||||
return gen;
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenVectorOp(const Expr* e, std::string op1,
|
||||
std::string op2, const char* vec_op)
|
||||
string CPPCompile::GenVectorOp(const Expr* e, string op1, string op2,
|
||||
const char* vec_op)
|
||||
{
|
||||
auto invoke = std::string(vec_op) + "__CPP(" + op1 + ", " + op2 + ")";
|
||||
auto invoke = string(vec_op) + "__CPP(" + op1 + ", " + op2 + ")";
|
||||
|
||||
if ( e->GetOp1()->GetType()->Yield()->Tag() == TYPE_STRING )
|
||||
return std::string("str_vec_op_") + invoke;
|
||||
return string("str_vec_op_") + invoke;
|
||||
|
||||
auto gen = std::string("vec_op_") + invoke;
|
||||
auto gen = string("vec_op_") + invoke;
|
||||
|
||||
auto yt = e->GetType()->Yield()->Tag();
|
||||
if ( ! IsArithmetic(yt) && yt != TYPE_STRING )
|
||||
gen = std::string("vector_coerce_to__CPP(") + gen + ", " +
|
||||
GenTypeName(e->GetType()) + ")";
|
||||
gen = string("vector_coerce_to__CPP(") + gen + ", " +
|
||||
GenTypeName(e->GetType()) + ")";
|
||||
|
||||
return gen;
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenLambdaClone(const LambdaExpr* l, bool all_deep)
|
||||
string CPPCompile::GenLambdaClone(const LambdaExpr* l, bool all_deep)
|
||||
{
|
||||
auto& ids = l->OuterIDs();
|
||||
const auto& captures = l->GetType<FuncType>()->GetCaptures();
|
||||
|
||||
std::string cl_args;
|
||||
string cl_args;
|
||||
|
||||
for ( const auto& id : ids )
|
||||
{
|
||||
|
@ -1117,7 +1113,7 @@ std::string CPPCompile::GenLambdaClone(const LambdaExpr* l, bool all_deep)
|
|||
{
|
||||
for ( const auto& c : *captures )
|
||||
if ( id == c.id && (c.deep_copy || all_deep) )
|
||||
arg = std::string("cast_intrusive<") + TypeName(id_t) + ">(" + arg + "->Clone())";
|
||||
arg = string("cast_intrusive<") + TypeName(id_t) + ">(" + arg + "->Clone())";
|
||||
}
|
||||
|
||||
cl_args = cl_args + ", " + arg;
|
||||
|
@ -1126,9 +1122,9 @@ std::string CPPCompile::GenLambdaClone(const LambdaExpr* l, bool all_deep)
|
|||
return cl_args;
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenIntVector(const std::vector<int>& vec)
|
||||
string CPPCompile::GenIntVector(const vector<int>& vec)
|
||||
{
|
||||
std::string res("{ ");
|
||||
string res("{ ");
|
||||
|
||||
for ( auto i = 0; i < vec.size(); ++i )
|
||||
{
|
||||
|
@ -1141,7 +1137,7 @@ std::string CPPCompile::GenIntVector(const std::vector<int>& vec)
|
|||
return res + " }";
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenField(const ExprPtr& rec, int field)
|
||||
string CPPCompile::GenField(const ExprPtr& rec, int field)
|
||||
{
|
||||
auto t = TypeRep(rec->GetType());
|
||||
auto rt = t->AsRecordType();
|
||||
|
@ -1163,8 +1159,8 @@ std::string CPPCompile::GenField(const ExprPtr& rec, int field)
|
|||
// New mapping.
|
||||
mapping_slot = num_rf_mappings++;
|
||||
|
||||
std::string field_name = rt->FieldName(field);
|
||||
field_decls.emplace_back(std::pair(rt, rt->FieldDecl(field)));
|
||||
string field_name = rt->FieldName(field);
|
||||
field_decls.emplace_back(pair(rt, rt->FieldDecl(field)));
|
||||
|
||||
if ( record_field_mappings.count(rt) > 0 )
|
||||
// We're already tracking this record.
|
||||
|
@ -1172,16 +1168,16 @@ std::string CPPCompile::GenField(const ExprPtr& rec, int field)
|
|||
else
|
||||
{
|
||||
// Need to start tracking this record.
|
||||
std::unordered_map<int, int> rt_mapping;
|
||||
unordered_map<int, int> rt_mapping;
|
||||
rt_mapping[field] = mapping_slot;
|
||||
record_field_mappings[rt] = rt_mapping;
|
||||
}
|
||||
}
|
||||
|
||||
return std::string("field_mapping[") + Fmt(mapping_slot) + "]";
|
||||
return string("field_mapping[") + Fmt(mapping_slot) + "]";
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenEnum(const TypePtr& t, const ValPtr& ev)
|
||||
string CPPCompile::GenEnum(const TypePtr& t, const ValPtr& ev)
|
||||
{
|
||||
auto et = TypeRep(t)->AsEnumType();
|
||||
auto v = ev->AsEnum();
|
||||
|
@ -1203,8 +1199,8 @@ std::string CPPCompile::GenEnum(const TypePtr& t, const ValPtr& ev)
|
|||
// New mapping.
|
||||
mapping_slot = num_ev_mappings++;
|
||||
|
||||
std::string enum_name = et->Lookup(v);
|
||||
enum_names.emplace_back(std::pair(et, std::move(enum_name)));
|
||||
string enum_name = et->Lookup(v);
|
||||
enum_names.emplace_back(pair(et, move(enum_name)));
|
||||
|
||||
if ( enum_val_mappings.count(et) > 0 )
|
||||
{
|
||||
|
@ -1214,13 +1210,13 @@ std::string CPPCompile::GenEnum(const TypePtr& t, const ValPtr& ev)
|
|||
else
|
||||
{
|
||||
// Need to start tracking this enum.
|
||||
std::unordered_map<int, int> et_mapping;
|
||||
unordered_map<int, int> et_mapping;
|
||||
et_mapping[v] = mapping_slot;
|
||||
enum_val_mappings[et] = et_mapping;
|
||||
}
|
||||
}
|
||||
|
||||
return std::string("enum_mapping[") + Fmt(mapping_slot) + "]";
|
||||
return string("enum_mapping[") + Fmt(mapping_slot) + "]";
|
||||
}
|
||||
|
||||
} // zeek::detail
|
||||
|
|
|
@ -9,9 +9,11 @@
|
|||
|
||||
namespace zeek::detail {
|
||||
|
||||
std::unordered_map<p_hash_type, CompiledScript> compiled_scripts;
|
||||
std::unordered_map<p_hash_type, void (*)()> standalone_callbacks;
|
||||
std::vector<void (*)()> standalone_activations;
|
||||
using namespace std;
|
||||
|
||||
unordered_map<p_hash_type, CompiledScript> compiled_scripts;
|
||||
unordered_map<p_hash_type, void (*)()> standalone_callbacks;
|
||||
vector<void (*)()> standalone_activations;
|
||||
|
||||
void CPPFunc::Describe(ODesc* d) const
|
||||
{
|
||||
|
@ -19,11 +21,10 @@ void CPPFunc::Describe(ODesc* d) const
|
|||
d->Add(name);
|
||||
}
|
||||
|
||||
CPPLambdaFunc::CPPLambdaFunc(std::string _name, FuncTypePtr ft,
|
||||
CPPStmtPtr _l_body)
|
||||
: ScriptFunc(std::move(_name), std::move(ft), {_l_body}, {0})
|
||||
CPPLambdaFunc::CPPLambdaFunc(string _name, FuncTypePtr ft, CPPStmtPtr _l_body)
|
||||
: ScriptFunc(move(_name), move(ft), {_l_body}, {0})
|
||||
{
|
||||
l_body = std::move(_l_body);
|
||||
l_body = move(_l_body);
|
||||
}
|
||||
|
||||
broker::expected<broker::data> CPPLambdaFunc::SerializeClosure() const
|
||||
|
@ -31,7 +32,7 @@ broker::expected<broker::data> CPPLambdaFunc::SerializeClosure() const
|
|||
auto vals = l_body->SerializeLambdaCaptures();
|
||||
|
||||
broker::vector rval;
|
||||
rval.emplace_back(std::string("CopyFrame"));
|
||||
rval.emplace_back(string("CopyFrame"));
|
||||
|
||||
broker::vector body;
|
||||
|
||||
|
@ -43,14 +44,14 @@ broker::expected<broker::data> CPPLambdaFunc::SerializeClosure() const
|
|||
return broker::ec::invalid_data;
|
||||
|
||||
TypeTag tag = val->GetType()->Tag();
|
||||
broker::vector val_tuple {std::move(*expected),
|
||||
broker::vector val_tuple {move(*expected),
|
||||
static_cast<broker::integer>(tag)};
|
||||
body.emplace_back(std::move(val_tuple));
|
||||
body.emplace_back(move(val_tuple));
|
||||
}
|
||||
|
||||
rval.emplace_back(std::move(body));
|
||||
rval.emplace_back(move(body));
|
||||
|
||||
return {std::move(rval)};
|
||||
return {move(rval)};
|
||||
}
|
||||
|
||||
void CPPLambdaFunc::SetCaptures(Frame* f)
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
|
||||
namespace zeek::detail {
|
||||
|
||||
using namespace std;
|
||||
|
||||
void CPPCompile::CompileFunc(const FuncInfo& func)
|
||||
{
|
||||
if ( ! IsCompilable(func) )
|
||||
|
@ -33,8 +35,8 @@ void CPPCompile::CompileLambda(const LambdaExpr* l, const ProfileFunc* pf)
|
|||
FUNC_FLAVOR_FUNCTION);
|
||||
}
|
||||
|
||||
void CPPCompile::GenInvokeBody(const std::string& fname, const TypePtr& t,
|
||||
const std::string& args)
|
||||
void CPPCompile::GenInvokeBody(const string& fname, const TypePtr& t,
|
||||
const string& args)
|
||||
{
|
||||
auto call = fname + "(" + args + ")";
|
||||
|
||||
|
@ -48,7 +50,7 @@ void CPPCompile::GenInvokeBody(const std::string& fname, const TypePtr& t,
|
|||
}
|
||||
|
||||
void CPPCompile::DefineBody(const FuncTypePtr& ft, const ProfileFunc* pf,
|
||||
const std::string& fname, const StmtPtr& body,
|
||||
const string& fname, const StmtPtr& body,
|
||||
const IDPList* lambda_ids, FunctionFlavor flavor)
|
||||
{
|
||||
locals.clear();
|
||||
|
@ -117,7 +119,7 @@ void CPPCompile::TranslateAnyParams(const FuncTypePtr& ft, const ProfileFunc* pf
|
|||
// It's already "any", nothing more to do.
|
||||
continue;
|
||||
|
||||
auto any_i = std::string("any_param__CPP_") + Fmt(i);
|
||||
auto any_i = string("any_param__CPP_") + Fmt(i);
|
||||
|
||||
Emit("%s %s = %s;", FullTypeName(pt), LocalName(param_id),
|
||||
GenericValPtrToGT(any_i, pt, GEN_NATIVE));
|
||||
|
@ -156,7 +158,7 @@ void CPPCompile::InitializeEvents(const ProfileFunc* pf)
|
|||
void CPPCompile::DeclareLocals(const ProfileFunc* pf, const IDPList* lambda_ids)
|
||||
{
|
||||
// It's handy to have a set of the lambda captures rather than a list.
|
||||
std::unordered_set<const ID*> lambda_set;
|
||||
unordered_set<const ID*> lambda_set;
|
||||
if ( lambda_ids )
|
||||
for ( auto li : *lambda_ids )
|
||||
lambda_set.insert(li);
|
||||
|
@ -189,11 +191,11 @@ void CPPCompile::DeclareLocals(const ProfileFunc* pf, const IDPList* lambda_ids)
|
|||
NL();
|
||||
}
|
||||
|
||||
std::string CPPCompile::BodyName(const FuncInfo& func)
|
||||
string CPPCompile::BodyName(const FuncInfo& func)
|
||||
{
|
||||
const auto& f = func.Func();
|
||||
const auto& bodies = f->GetBodies();
|
||||
std::string fname = f->Name();
|
||||
string fname = f->Name();
|
||||
|
||||
if ( bodies.size() == 1 )
|
||||
return fname;
|
||||
|
@ -212,10 +214,10 @@ std::string CPPCompile::BodyName(const FuncInfo& func)
|
|||
return fname + "__" + Fmt(i);
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenArgs(const RecordTypePtr& params, const Expr* e)
|
||||
string CPPCompile::GenArgs(const RecordTypePtr& params, const Expr* e)
|
||||
{
|
||||
const auto& exprs = e->AsListExpr()->Exprs();
|
||||
std::string gen;
|
||||
string gen;
|
||||
|
||||
int n = exprs.size();
|
||||
|
||||
|
|
|
@ -6,13 +6,15 @@
|
|||
|
||||
namespace zeek::detail {
|
||||
|
||||
using namespace std;
|
||||
|
||||
VarMapper compiled_items;
|
||||
|
||||
CPPHashManager::CPPHashManager(const char* hash_name_base, bool _append)
|
||||
{
|
||||
append = _append;
|
||||
|
||||
hash_name = std::string(hash_name_base) + ".dat";
|
||||
hash_name = string(hash_name_base) + ".dat";
|
||||
|
||||
if ( append )
|
||||
{
|
||||
|
@ -52,7 +54,7 @@ CPPHashManager::~CPPHashManager()
|
|||
|
||||
void CPPHashManager::LoadHashes(FILE* f)
|
||||
{
|
||||
std::string key;
|
||||
string key;
|
||||
|
||||
// The hash file format is inefficient but simple to scan.
|
||||
// It doesn't appear to pose a bottleneck, so until it does
|
||||
|
@ -60,7 +62,7 @@ void CPPHashManager::LoadHashes(FILE* f)
|
|||
|
||||
while ( GetLine(f, key) )
|
||||
{
|
||||
std::string line;
|
||||
string line;
|
||||
|
||||
RequireLine(f, line);
|
||||
|
||||
|
@ -133,7 +135,7 @@ void CPPHashManager::LoadHashes(FILE* f)
|
|||
}
|
||||
}
|
||||
|
||||
void CPPHashManager::RequireLine(FILE* f, std::string& line)
|
||||
void CPPHashManager::RequireLine(FILE* f, string& line)
|
||||
{
|
||||
if ( ! GetLine(f, line) )
|
||||
{
|
||||
|
@ -142,7 +144,7 @@ void CPPHashManager::RequireLine(FILE* f, std::string& line)
|
|||
}
|
||||
}
|
||||
|
||||
bool CPPHashManager::GetLine(FILE* f, std::string& line)
|
||||
bool CPPHashManager::GetLine(FILE* f, string& line)
|
||||
{
|
||||
char buf[8192];
|
||||
if ( ! fgets(buf, sizeof buf, f) )
|
||||
|
@ -156,7 +158,7 @@ bool CPPHashManager::GetLine(FILE* f, std::string& line)
|
|||
return true;
|
||||
}
|
||||
|
||||
void CPPHashManager::BadLine(std::string& line)
|
||||
void CPPHashManager::BadLine(string& line)
|
||||
{
|
||||
reporter->Error("bad %s hash file entry: %s",
|
||||
hash_name.c_str(), line.c_str());
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
|
||||
namespace zeek::detail {
|
||||
|
||||
using namespace std;
|
||||
|
||||
void CPPCompile::GenInitExpr(const ExprPtr& e)
|
||||
{
|
||||
NL();
|
||||
|
@ -18,7 +20,7 @@ void CPPCompile::GenInitExpr(const ExprPtr& e)
|
|||
auto ename = InitExprName(e);
|
||||
|
||||
// First, create a CPPFunc that we can compile to compute 'e'.
|
||||
auto name = std::string("wrapper_") + ename;
|
||||
auto name = string("wrapper_") + ename;
|
||||
|
||||
// Forward declaration of the function that computes 'e'.
|
||||
Emit("static %s %s(Frame* f__CPP);", FullTypeName(t), name);
|
||||
|
@ -58,7 +60,7 @@ void CPPCompile::GenInitExpr(const ExprPtr& e)
|
|||
Emit("CallExprPtr %s;", ename);
|
||||
|
||||
NoteInitDependency(e, TypeRep(t));
|
||||
AddInit(e, ename, std::string("make_intrusive<CallExpr>(make_intrusive<ConstExpr>(make_intrusive<FuncVal>(make_intrusive<") +
|
||||
AddInit(e, ename, string("make_intrusive<CallExpr>(make_intrusive<ConstExpr>(make_intrusive<FuncVal>(make_intrusive<") +
|
||||
name + "_cl>())), make_intrusive<ListExpr>(), false)");
|
||||
}
|
||||
|
||||
|
@ -87,12 +89,12 @@ bool CPPCompile::IsSimpleInitExpr(const ExprPtr& e) const
|
|||
}
|
||||
}
|
||||
|
||||
std::string CPPCompile::InitExprName(const ExprPtr& e)
|
||||
string CPPCompile::InitExprName(const ExprPtr& e)
|
||||
{
|
||||
return init_exprs.KeyName(e);
|
||||
}
|
||||
|
||||
void CPPCompile::GenGlobalInit(const ID* g, std::string& gl, const ValPtr& v)
|
||||
void CPPCompile::GenGlobalInit(const ID* g, string& gl, const ValPtr& v)
|
||||
{
|
||||
const auto& t = v->GetType();
|
||||
auto tag = t->Tag();
|
||||
|
@ -102,7 +104,7 @@ void CPPCompile::GenGlobalInit(const ID* g, std::string& gl, const ValPtr& v)
|
|||
// the function's body.
|
||||
return;
|
||||
|
||||
std::string init_val;
|
||||
string init_val;
|
||||
if ( tag == TYPE_OPAQUE )
|
||||
{
|
||||
// We can only generate these by reproducing the expression
|
||||
|
@ -127,7 +129,7 @@ void CPPCompile::GenGlobalInit(const ID* g, std::string& gl, const ValPtr& v)
|
|||
|
||||
auto& attrs = g->GetAttrs();
|
||||
|
||||
AddInit(g, std::string("if ( ! ") + gl + "->HasVal() )");
|
||||
AddInit(g, string("if ( ! ") + gl + "->HasVal() )");
|
||||
|
||||
if ( attrs )
|
||||
{
|
||||
|
@ -157,7 +159,7 @@ void CPPCompile::GenFuncVarInits()
|
|||
|
||||
const auto& bodies = f->GetBodies();
|
||||
|
||||
std::string hashes = "{";
|
||||
string hashes = "{";
|
||||
|
||||
for ( auto b : bodies )
|
||||
{
|
||||
|
@ -178,7 +180,7 @@ void CPPCompile::GenFuncVarInits()
|
|||
|
||||
hashes += "}";
|
||||
|
||||
auto init = std::string("lookup_func__CPP(\"") + fn +
|
||||
auto init = string("lookup_func__CPP(\"") + fn +
|
||||
"\", " + hashes + ", " + GenTypeName(ft) + ")";
|
||||
|
||||
AddInit(fv, const_name, init);
|
||||
|
@ -187,7 +189,7 @@ void CPPCompile::GenFuncVarInits()
|
|||
|
||||
void CPPCompile::GenPreInit(const Type* t)
|
||||
{
|
||||
std::string pre_init;
|
||||
string pre_init;
|
||||
|
||||
switch ( t->Tag() ) {
|
||||
case TYPE_ADDR:
|
||||
|
@ -204,43 +206,43 @@ void CPPCompile::GenPreInit(const Type* t)
|
|||
case TYPE_TIME:
|
||||
case TYPE_TIMER:
|
||||
case TYPE_VOID:
|
||||
pre_init = std::string("base_type(") + TypeTagName(t->Tag()) + ")";
|
||||
pre_init = string("base_type(") + TypeTagName(t->Tag()) + ")";
|
||||
break;
|
||||
|
||||
case TYPE_ENUM:
|
||||
pre_init = std::string("get_enum_type__CPP(\"") +
|
||||
pre_init = string("get_enum_type__CPP(\"") +
|
||||
t->GetName() + "\")";
|
||||
break;
|
||||
|
||||
case TYPE_SUBNET:
|
||||
pre_init = std::string("make_intrusive<SubNetType>()");
|
||||
pre_init = string("make_intrusive<SubNetType>()");
|
||||
break;
|
||||
|
||||
case TYPE_FILE:
|
||||
pre_init = std::string("make_intrusive<FileType>(") +
|
||||
pre_init = string("make_intrusive<FileType>(") +
|
||||
GenTypeName(t->AsFileType()->Yield()) + ")";
|
||||
break;
|
||||
|
||||
case TYPE_OPAQUE:
|
||||
pre_init = std::string("make_intrusive<OpaqueType>(\"") +
|
||||
pre_init = string("make_intrusive<OpaqueType>(\"") +
|
||||
t->AsOpaqueType()->Name() + "\")";
|
||||
break;
|
||||
|
||||
case TYPE_RECORD:
|
||||
{
|
||||
std::string name;
|
||||
string name;
|
||||
|
||||
if ( t->GetName() != "" )
|
||||
name = std::string("\"") + t->GetName() + std::string("\"");
|
||||
name = string("\"") + t->GetName() + string("\"");
|
||||
else
|
||||
name = "nullptr";
|
||||
|
||||
pre_init = std::string("get_record_type__CPP(") + name + ")";
|
||||
pre_init = string("get_record_type__CPP(") + name + ")";
|
||||
}
|
||||
break;
|
||||
|
||||
case TYPE_LIST:
|
||||
pre_init = std::string("make_intrusive<TypeList>()");
|
||||
pre_init = string("make_intrusive<TypeList>()");
|
||||
break;
|
||||
|
||||
case TYPE_TYPE:
|
||||
|
@ -268,7 +270,7 @@ void CPPCompile::GenPreInits()
|
|||
EndBlock();
|
||||
}
|
||||
|
||||
void CPPCompile::AddInit(const Obj* o, const std::string& init)
|
||||
void CPPCompile::AddInit(const Obj* o, const string& init)
|
||||
{
|
||||
obj_inits[o].emplace_back(init);
|
||||
}
|
||||
|
@ -277,7 +279,7 @@ void CPPCompile::AddInit(const Obj* o)
|
|||
{
|
||||
if ( obj_inits.count(o) == 0 )
|
||||
{
|
||||
std::vector<std::string> empty;
|
||||
vector<string> empty;
|
||||
obj_inits[o] = empty;
|
||||
}
|
||||
}
|
||||
|
@ -287,7 +289,7 @@ void CPPCompile::NoteInitDependency(const Obj* o1, const Obj* o2)
|
|||
obj_deps[o1].emplace(o2);
|
||||
}
|
||||
|
||||
void CPPCompile::CheckInitConsistency(std::unordered_set<const Obj*>& to_do)
|
||||
void CPPCompile::CheckInitConsistency(unordered_set<const Obj*>& to_do)
|
||||
{
|
||||
for ( const auto& od : obj_deps )
|
||||
{
|
||||
|
@ -312,7 +314,7 @@ void CPPCompile::CheckInitConsistency(std::unordered_set<const Obj*>& to_do)
|
|||
}
|
||||
}
|
||||
|
||||
int CPPCompile::GenDependentInits(std::unordered_set<const Obj*>& to_do)
|
||||
int CPPCompile::GenDependentInits(unordered_set<const Obj*>& to_do)
|
||||
{
|
||||
int n = 0;
|
||||
|
||||
|
@ -323,7 +325,7 @@ int CPPCompile::GenDependentInits(std::unordered_set<const Obj*>& to_do)
|
|||
// are no more to-do items.
|
||||
while ( to_do.size() > 0 )
|
||||
{
|
||||
std::unordered_set<const Obj*> cohort;
|
||||
unordered_set<const Obj*> cohort;
|
||||
|
||||
for ( const auto& o : to_do )
|
||||
{
|
||||
|
@ -361,7 +363,7 @@ int CPPCompile::GenDependentInits(std::unordered_set<const Obj*>& to_do)
|
|||
return n;
|
||||
}
|
||||
|
||||
void CPPCompile::GenInitCohort(int nc, std::unordered_set<const Obj*>& cohort)
|
||||
void CPPCompile::GenInitCohort(int nc, unordered_set<const Obj*>& cohort)
|
||||
{
|
||||
NL();
|
||||
Emit("void init_%s__CPP()", Fmt(nc));
|
||||
|
@ -430,7 +432,7 @@ void CPPCompile::InitializeEnumMappings()
|
|||
}
|
||||
|
||||
void CPPCompile::InitializeEnumMappings(const EnumType* et,
|
||||
const std::string& e_name, int index)
|
||||
const string& e_name, int index)
|
||||
{
|
||||
AddInit(et, "{");
|
||||
|
||||
|
@ -490,7 +492,7 @@ void CPPCompile::GenStandaloneActivation()
|
|||
// associated scripts.
|
||||
|
||||
// First, build up a list of per-hook/event handler bodies.
|
||||
std::unordered_map<const Func*, std::vector<p_hash_type>> func_bodies;
|
||||
unordered_map<const Func*, vector<p_hash_type>> func_bodies;
|
||||
|
||||
for ( const auto& func : funcs )
|
||||
{
|
||||
|
@ -517,7 +519,7 @@ void CPPCompile::GenStandaloneActivation()
|
|||
const auto fn = f->Name();
|
||||
const auto& ft = f->GetType();
|
||||
|
||||
std::string hashes;
|
||||
string hashes;
|
||||
for ( auto h : fb.second )
|
||||
{
|
||||
if ( hashes.size() > 0 )
|
||||
|
@ -540,7 +542,7 @@ void CPPCompile::GenLoad()
|
|||
{
|
||||
// First, generate a hash unique to this compilation.
|
||||
auto t = util::current_time();
|
||||
auto th = std::hash<double>{}(t);
|
||||
auto th = hash<double>{}(t);
|
||||
|
||||
total_hash = merge_p_hashes(total_hash, th);
|
||||
|
||||
|
|
|
@ -6,7 +6,9 @@
|
|||
|
||||
namespace zeek::detail {
|
||||
|
||||
std::vector<CPP_init_func> CPP_init_funcs;
|
||||
using namespace std;
|
||||
|
||||
vector<CPP_init_func> CPP_init_funcs;
|
||||
|
||||
// Calls all of the initialization hooks, in the order they were added.
|
||||
void init_CPPs()
|
||||
|
@ -29,9 +31,9 @@ static int dummy = flag_init_CPP();
|
|||
|
||||
|
||||
void register_body__CPP(CPPStmtPtr body, int priority, p_hash_type hash,
|
||||
std::vector<std::string> events)
|
||||
vector<string> events)
|
||||
{
|
||||
compiled_scripts[hash] = { std::move(body), priority, std::move(events) };
|
||||
compiled_scripts[hash] = { move(body), priority, move(events) };
|
||||
}
|
||||
|
||||
void register_lambda__CPP(CPPStmtPtr body, p_hash_type hash, const char* name,
|
||||
|
@ -44,8 +46,8 @@ void register_lambda__CPP(CPPStmtPtr body, p_hash_type hash, const char* name,
|
|||
auto func = make_intrusive<CPPLambdaFunc>(name, ft, body);
|
||||
func->SetName(name);
|
||||
|
||||
auto v = make_intrusive<FuncVal>(std::move(func));
|
||||
id->SetVal(std::move(v));
|
||||
auto v = make_intrusive<FuncVal>(move(func));
|
||||
id->SetVal(move(v));
|
||||
id->SetType(ft);
|
||||
|
||||
// Lambdas used in initializing global functions need to
|
||||
|
@ -65,8 +67,7 @@ void register_scripts__CPP(p_hash_type h, void (*callback)())
|
|||
standalone_callbacks[h] = callback;
|
||||
}
|
||||
|
||||
void activate_bodies__CPP(const char* fn, TypePtr t,
|
||||
std::vector<p_hash_type> hashes)
|
||||
void activate_bodies__CPP(const char* fn, TypePtr t, vector<p_hash_type> hashes)
|
||||
{
|
||||
auto ft = cast_intrusive<FuncType>(t);
|
||||
auto fg = lookup_ID(fn, GLOBAL_MODULE_NAME, false, false, false);
|
||||
|
@ -81,7 +82,7 @@ void activate_bodies__CPP(const char* fn, TypePtr t,
|
|||
const auto& bodies = f->GetBodies();
|
||||
|
||||
// Track hashes of compiled bodies already associated with f.
|
||||
std::unordered_set<p_hash_type> existing_CPP_bodies;
|
||||
unordered_set<p_hash_type> existing_CPP_bodies;
|
||||
for ( auto& b : bodies )
|
||||
{
|
||||
auto s = b.stmts;
|
||||
|
@ -93,12 +94,12 @@ void activate_bodies__CPP(const char* fn, TypePtr t,
|
|||
}
|
||||
|
||||
// Events we need to register.
|
||||
std::unordered_set<std::string> events;
|
||||
unordered_set<string> events;
|
||||
|
||||
if ( ft->Flavor() == FUNC_FLAVOR_EVENT )
|
||||
events.insert(fn);
|
||||
|
||||
std::vector<detail::IDPtr> no_inits; // empty initialization vector
|
||||
vector<detail::IDPtr> no_inits; // empty initialization vector
|
||||
int num_params = ft->Params()->NumFields();
|
||||
|
||||
for ( auto h : hashes )
|
||||
|
@ -144,13 +145,13 @@ Func* lookup_bif__CPP(const char* bif)
|
|||
return b ? b->GetVal()->AsFunc() : nullptr;
|
||||
}
|
||||
|
||||
FuncValPtr lookup_func__CPP(std::string name, std::vector<p_hash_type> hashes,
|
||||
FuncValPtr lookup_func__CPP(string name, vector<p_hash_type> hashes,
|
||||
const TypePtr& t)
|
||||
{
|
||||
auto ft = cast_intrusive<FuncType>(t);
|
||||
|
||||
std::vector<StmtPtr> bodies;
|
||||
std::vector<int> priorities;
|
||||
vector<StmtPtr> bodies;
|
||||
vector<int> priorities;
|
||||
|
||||
for ( auto h : hashes )
|
||||
{
|
||||
|
@ -170,11 +171,10 @@ FuncValPtr lookup_func__CPP(std::string name, std::vector<p_hash_type> hashes,
|
|||
}
|
||||
}
|
||||
|
||||
auto sf = make_intrusive<ScriptFunc>(std::move(name), std::move(ft),
|
||||
std::move(bodies),
|
||||
std::move(priorities));
|
||||
auto sf = make_intrusive<ScriptFunc>(move(name), move(ft), move(bodies),
|
||||
move(priorities));
|
||||
|
||||
return make_intrusive<FuncVal>(std::move(sf));
|
||||
return make_intrusive<FuncVal>(move(sf));
|
||||
}
|
||||
|
||||
|
||||
|
@ -190,7 +190,7 @@ RecordTypePtr get_record_type__CPP(const char* record_type_name)
|
|||
return make_intrusive<RecordType>(new type_decl_list());
|
||||
}
|
||||
|
||||
EnumTypePtr get_enum_type__CPP(const std::string& enum_type_name)
|
||||
EnumTypePtr get_enum_type__CPP(const string& enum_type_name)
|
||||
{
|
||||
auto existing_type = global_scope()->Find(enum_type_name);
|
||||
|
||||
|
@ -202,7 +202,7 @@ EnumTypePtr get_enum_type__CPP(const std::string& enum_type_name)
|
|||
|
||||
EnumValPtr make_enum__CPP(TypePtr t, int i)
|
||||
{
|
||||
auto et = cast_intrusive<EnumType>(std::move(t));
|
||||
auto et = cast_intrusive<EnumType>(move(t));
|
||||
return make_intrusive<EnumVal>(et, i);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,9 +8,11 @@
|
|||
|
||||
namespace zeek::detail {
|
||||
|
||||
using namespace std;
|
||||
|
||||
StringValPtr str_concat__CPP(const String* s1, const String* s2)
|
||||
{
|
||||
std::vector<const String*> strings(2);
|
||||
vector<const String*> strings(2);
|
||||
strings[0] = s1;
|
||||
strings[1] = s2;
|
||||
|
||||
|
@ -23,7 +25,7 @@ bool str_in__CPP(const String* s1, const String* s2)
|
|||
return util::strstr_n(s2->Len(), s2->Bytes(), s1->Len(), s) != -1;
|
||||
}
|
||||
|
||||
ListValPtr index_val__CPP(std::vector<ValPtr> indices)
|
||||
ListValPtr index_val__CPP(vector<ValPtr> indices)
|
||||
{
|
||||
auto ind_v = make_intrusive<ListVal>(TYPE_ANY);
|
||||
|
||||
|
@ -35,9 +37,9 @@ ListValPtr index_val__CPP(std::vector<ValPtr> indices)
|
|||
return ind_v;
|
||||
}
|
||||
|
||||
ValPtr index_table__CPP(const TableValPtr& t, std::vector<ValPtr> indices)
|
||||
ValPtr index_table__CPP(const TableValPtr& t, vector<ValPtr> indices)
|
||||
{
|
||||
auto v = t->FindOrDefault(index_val__CPP(std::move(indices)));
|
||||
auto v = t->FindOrDefault(index_val__CPP(move(indices)));
|
||||
if ( ! v )
|
||||
reporter->CPPRuntimeError("no such index");
|
||||
return v;
|
||||
|
@ -51,15 +53,15 @@ ValPtr index_vec__CPP(const VectorValPtr& vec, int index)
|
|||
return v;
|
||||
}
|
||||
|
||||
ValPtr index_string__CPP(const StringValPtr& svp, std::vector<ValPtr> indices)
|
||||
ValPtr index_string__CPP(const StringValPtr& svp, vector<ValPtr> indices)
|
||||
{
|
||||
return index_string(svp->AsString(),
|
||||
index_val__CPP(std::move(indices)).get());
|
||||
index_val__CPP(move(indices)).get());
|
||||
}
|
||||
|
||||
ValPtr set_event__CPP(IDPtr g, ValPtr v, EventHandlerPtr& gh)
|
||||
{
|
||||
g->SetVal(std::move(v));
|
||||
g->SetVal(move(v));
|
||||
gh = event_registry->Register(g->Name());
|
||||
return v;
|
||||
}
|
||||
|
@ -102,7 +104,7 @@ template <typename T>
|
|||
ValPtr assign_to_index__CPP(T v1, ValPtr v2, ValPtr v3)
|
||||
{
|
||||
bool iterators_invalidated = false;
|
||||
auto err_msg = assign_to_index(std::move(v1), std::move(v2), v3, iterators_invalidated);
|
||||
auto err_msg = assign_to_index(move(v1), move(v2), v3, iterators_invalidated);
|
||||
|
||||
check_iterators__CPP(iterators_invalidated);
|
||||
|
||||
|
@ -143,10 +145,10 @@ void remove_element__CPP(TableValPtr aggr, ListValPtr indices)
|
|||
// and values and returns a collective AttributesPtr corresponding to
|
||||
// those instantiated attributes. For attributes that don't have
|
||||
// associated expressions, the correspoinding value should be nil.
|
||||
static AttributesPtr build_attrs__CPP(std::vector<int> attr_tags,
|
||||
std::vector<ValPtr> attr_vals)
|
||||
static AttributesPtr build_attrs__CPP(vector<int> attr_tags,
|
||||
vector<ValPtr> attr_vals)
|
||||
{
|
||||
std::vector<AttrPtr> attrs;
|
||||
vector<AttrPtr> attrs;
|
||||
int nattrs = attr_tags.size();
|
||||
for ( auto i = 0; i < nattrs; ++i )
|
||||
{
|
||||
|
@ -160,46 +162,45 @@ static AttributesPtr build_attrs__CPP(std::vector<int> attr_tags,
|
|||
attrs.emplace_back(make_intrusive<Attr>(t_i, e));
|
||||
}
|
||||
|
||||
return make_intrusive<Attributes>(std::move(attrs), nullptr, false, false);
|
||||
return make_intrusive<Attributes>(move(attrs), nullptr, false, false);
|
||||
}
|
||||
|
||||
TableValPtr set_constructor__CPP(std::vector<ValPtr> elements, TableTypePtr t,
|
||||
std::vector<int> attr_tags,
|
||||
std::vector<ValPtr> attr_vals)
|
||||
TableValPtr set_constructor__CPP(vector<ValPtr> elements, TableTypePtr t,
|
||||
vector<int> attr_tags,
|
||||
vector<ValPtr> attr_vals)
|
||||
{
|
||||
auto attrs = build_attrs__CPP(std::move(attr_tags), std::move(attr_vals));
|
||||
auto aggr = make_intrusive<TableVal>(std::move(t), std::move(attrs));
|
||||
auto attrs = build_attrs__CPP(move(attr_tags), move(attr_vals));
|
||||
auto aggr = make_intrusive<TableVal>(move(t), move(attrs));
|
||||
|
||||
for ( const auto& elem : elements )
|
||||
aggr->Assign(std::move(elem), nullptr);
|
||||
aggr->Assign(move(elem), nullptr);
|
||||
|
||||
return aggr;
|
||||
}
|
||||
|
||||
TableValPtr table_constructor__CPP(std::vector<ValPtr> indices,
|
||||
std::vector<ValPtr> vals, TableTypePtr t,
|
||||
std::vector<int> attr_tags,
|
||||
std::vector<ValPtr> attr_vals)
|
||||
TableValPtr table_constructor__CPP(vector<ValPtr> indices, vector<ValPtr> vals,
|
||||
TableTypePtr t, vector<int> attr_tags,
|
||||
vector<ValPtr> attr_vals)
|
||||
{
|
||||
const auto& yt = t->Yield().get();
|
||||
auto n = indices.size();
|
||||
|
||||
auto attrs = build_attrs__CPP(std::move(attr_tags), std::move(attr_vals));
|
||||
auto aggr = make_intrusive<TableVal>(std::move(t), std::move(attrs));
|
||||
auto attrs = build_attrs__CPP(move(attr_tags), move(attr_vals));
|
||||
auto aggr = make_intrusive<TableVal>(move(t), move(attrs));
|
||||
|
||||
for ( auto i = 0; i < n; ++i )
|
||||
{
|
||||
auto v = check_and_promote(vals[i], yt, true);
|
||||
if ( v )
|
||||
aggr->Assign(std::move(indices[i]), std::move(v));
|
||||
aggr->Assign(move(indices[i]), move(v));
|
||||
}
|
||||
|
||||
return aggr;
|
||||
}
|
||||
|
||||
RecordValPtr record_constructor__CPP(std::vector<ValPtr> vals, RecordTypePtr t)
|
||||
RecordValPtr record_constructor__CPP(vector<ValPtr> vals, RecordTypePtr t)
|
||||
{
|
||||
auto rv = make_intrusive<RecordVal>(std::move(t));
|
||||
auto rv = make_intrusive<RecordVal>(move(t));
|
||||
auto n = vals.size();
|
||||
|
||||
rv->Reserve(n);
|
||||
|
@ -210,9 +211,9 @@ RecordValPtr record_constructor__CPP(std::vector<ValPtr> vals, RecordTypePtr t)
|
|||
return rv;
|
||||
}
|
||||
|
||||
VectorValPtr vector_constructor__CPP(std::vector<ValPtr> vals, VectorTypePtr t)
|
||||
VectorValPtr vector_constructor__CPP(vector<ValPtr> vals, VectorTypePtr t)
|
||||
{
|
||||
auto vv = make_intrusive<VectorVal>(std::move(t));
|
||||
auto vv = make_intrusive<VectorVal>(move(t));
|
||||
auto n = vals.size();
|
||||
|
||||
for ( auto i = 0; i < n; ++i )
|
||||
|
@ -221,10 +222,10 @@ VectorValPtr vector_constructor__CPP(std::vector<ValPtr> vals, VectorTypePtr t)
|
|||
return vv;
|
||||
}
|
||||
|
||||
ValPtr schedule__CPP(double dt, EventHandlerPtr event, std::vector<ValPtr> args)
|
||||
ValPtr schedule__CPP(double dt, EventHandlerPtr event, vector<ValPtr> args)
|
||||
{
|
||||
if ( ! run_state::terminating )
|
||||
timer_mgr->Add(new ScheduleTimer(event, std::move(args), dt));
|
||||
timer_mgr->Add(new ScheduleTimer(event, move(args), dt));
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
namespace zeek::detail {
|
||||
|
||||
using namespace std;
|
||||
|
||||
// Helper function for ensuring that two vectors have matching sizes.
|
||||
static bool check_vec_sizes__CPP(const VectorValPtr& v1, const VectorValPtr& v2)
|
||||
{
|
||||
|
@ -224,7 +226,7 @@ VectorValPtr vec_op_add__CPP(VectorValPtr v, int incr)
|
|||
|
||||
VectorValPtr vec_op_sub__CPP(VectorValPtr v, int i)
|
||||
{
|
||||
return vec_op_add__CPP(std::move(v), -i);
|
||||
return vec_op_add__CPP(move(v), -i);
|
||||
}
|
||||
|
||||
// This function provides the core functionality. The arguments
|
||||
|
@ -241,7 +243,7 @@ static VectorValPtr str_vec_op_str_vec_add__CPP(const StringValPtr& s1,
|
|||
|
||||
for ( unsigned int i = 0; i < n; ++i )
|
||||
{
|
||||
std::vector<const String*> strings;
|
||||
vector<const String*> strings;
|
||||
|
||||
auto v2_i = v2->ValAt(i);
|
||||
if ( ! v2_i )
|
||||
|
@ -354,7 +356,7 @@ VectorValPtr vector_select__CPP(const VectorValPtr& v1, VectorValPtr v2,
|
|||
for ( unsigned int i = 0; i < n; ++i )
|
||||
{
|
||||
auto vr_i = v1->BoolAt(i) ? v2->ValAt(i) : v3->ValAt(i);
|
||||
v_result->Assign(i, std::move(vr_i));
|
||||
v_result->Assign(i, move(vr_i));
|
||||
}
|
||||
|
||||
return v_result;
|
||||
|
@ -363,7 +365,7 @@ VectorValPtr vector_select__CPP(const VectorValPtr& v1, VectorValPtr v2,
|
|||
VectorValPtr vector_coerce_to__CPP(const VectorValPtr& v, const TypePtr& targ)
|
||||
{
|
||||
auto res_t = cast_intrusive<VectorType>(targ);
|
||||
auto v_result = make_intrusive<VectorVal>(std::move(res_t));
|
||||
auto v_result = make_intrusive<VectorVal>(move(res_t));
|
||||
auto n = v->Size();
|
||||
auto yt = targ->Yield();
|
||||
auto ytag = yt->Tag();
|
||||
|
@ -397,7 +399,7 @@ VectorValPtr vector_coerce_to__CPP(const VectorValPtr& v, const TypePtr& targ)
|
|||
reporter->InternalError("bad vector type in vector_coerce_to__CPP");
|
||||
}
|
||||
|
||||
v_result->Assign(i, std::move(r_i));
|
||||
v_result->Assign(i, move(r_i));
|
||||
}
|
||||
|
||||
return v_result;
|
||||
|
@ -406,7 +408,7 @@ VectorValPtr vector_coerce_to__CPP(const VectorValPtr& v, const TypePtr& targ)
|
|||
VectorValPtr vec_coerce_to_bro_int_t__CPP(const VectorValPtr& v, TypePtr targ)
|
||||
{
|
||||
auto res_t = cast_intrusive<VectorType>(targ);
|
||||
auto v_result = make_intrusive<VectorVal>(std::move(res_t));
|
||||
auto v_result = make_intrusive<VectorVal>(move(res_t));
|
||||
auto n = v->Size();
|
||||
|
||||
for ( unsigned int i = 0; i < n; ++i )
|
||||
|
@ -418,7 +420,7 @@ VectorValPtr vec_coerce_to_bro_int_t__CPP(const VectorValPtr& v, TypePtr targ)
|
|||
VectorValPtr vec_coerce_to_bro_uint_t__CPP(const VectorValPtr& v, TypePtr targ)
|
||||
{
|
||||
auto res_t = cast_intrusive<VectorType>(targ);
|
||||
auto v_result = make_intrusive<VectorVal>(std::move(res_t));
|
||||
auto v_result = make_intrusive<VectorVal>(move(res_t));
|
||||
auto n = v->Size();
|
||||
|
||||
for ( unsigned int i = 0; i < n; ++i )
|
||||
|
@ -430,7 +432,7 @@ VectorValPtr vec_coerce_to_bro_uint_t__CPP(const VectorValPtr& v, TypePtr targ)
|
|||
VectorValPtr vec_coerce_to_double__CPP(const VectorValPtr& v, TypePtr targ)
|
||||
{
|
||||
auto res_t = cast_intrusive<VectorType>(targ);
|
||||
auto v_result = make_intrusive<VectorVal>(std::move(res_t));
|
||||
auto v_result = make_intrusive<VectorVal>(move(res_t));
|
||||
auto n = v->Size();
|
||||
|
||||
for ( unsigned int i = 0; i < n; ++i )
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
namespace zeek::detail {
|
||||
|
||||
using namespace std;
|
||||
|
||||
void CPPCompile::GenStmt(const Stmt* s)
|
||||
{
|
||||
switch ( s->Tag() ) {
|
||||
|
@ -222,11 +224,11 @@ void CPPCompile::GenEventStmt(const EventStmt* ev)
|
|||
|
||||
if ( ev_e->Args()->Exprs().length() > 0 )
|
||||
Emit("event_mgr.Enqueue(%s_ev, %s);",
|
||||
globals[std::string(ev_n)],
|
||||
globals[string(ev_n)],
|
||||
GenExpr(ev_e->Args(), GEN_VAL_PTR));
|
||||
else
|
||||
Emit("event_mgr.Enqueue(%s_ev, Args{});",
|
||||
globals[std::string(ev_n)]);
|
||||
globals[string(ev_n)]);
|
||||
}
|
||||
|
||||
void CPPCompile::GenSwitchStmt(const SwitchStmt* sw)
|
||||
|
@ -239,12 +241,12 @@ void CPPCompile::GenSwitchStmt(const SwitchStmt* sw)
|
|||
bool is_uint = e_it == TYPE_INTERNAL_UNSIGNED;
|
||||
bool organic = is_int || is_uint;
|
||||
|
||||
std::string sw_val;
|
||||
string sw_val;
|
||||
|
||||
if ( organic )
|
||||
sw_val = GenExpr(e, GEN_NATIVE);
|
||||
else
|
||||
sw_val = std::string("p_hash(") + GenExpr(e, GEN_VAL_PTR) + ")";
|
||||
sw_val = string("p_hash(") + GenExpr(e, GEN_VAL_PTR) + ")";
|
||||
|
||||
Emit("switch ( %s ) {", sw_val.c_str());
|
||||
|
||||
|
@ -262,7 +264,7 @@ void CPPCompile::GenSwitchStmt(const SwitchStmt* sw)
|
|||
auto c_v = c_e->Eval(nullptr);
|
||||
ASSERT(c_v);
|
||||
|
||||
std::string c_v_rep;
|
||||
string c_v_rep;
|
||||
|
||||
if ( is_int )
|
||||
c_v_rep = Fmt(int(c_v->AsInt()));
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
|
||||
namespace zeek::detail {
|
||||
|
||||
using namespace std;
|
||||
|
||||
template<class T>
|
||||
void CPPTracker<T>::AddKey(IntrusivePtr<T> key, p_hash_type h)
|
||||
{
|
||||
|
@ -43,7 +45,7 @@ void CPPTracker<T>::AddKey(IntrusivePtr<T> key, p_hash_type h)
|
|||
}
|
||||
|
||||
template<class T>
|
||||
std::string CPPTracker<T>::KeyName(const T* key)
|
||||
string CPPTracker<T>::KeyName(const T* key)
|
||||
{
|
||||
ASSERT(HasKey(key));
|
||||
|
||||
|
@ -52,11 +54,11 @@ std::string CPPTracker<T>::KeyName(const T* key)
|
|||
|
||||
auto index = map2[hash];
|
||||
|
||||
std::string scope;
|
||||
string scope;
|
||||
if ( IsInherited(hash) )
|
||||
scope = scope_prefix(scope2[hash]);
|
||||
|
||||
return scope + std::string(base_name) + "_" + Fmt(index) + "__CPP";
|
||||
return scope + string(base_name) + "_" + Fmt(index) + "__CPP";
|
||||
}
|
||||
|
||||
template<class T>
|
||||
|
@ -77,8 +79,8 @@ p_hash_type CPPTracker<T>::Hash(IntrusivePtr<T> key) const
|
|||
ODesc d;
|
||||
d.SetDeterminism(true);
|
||||
key->Describe(&d);
|
||||
std::string desc = d.Description();
|
||||
auto h = std::hash<std::string>{}(base_name + desc);
|
||||
string desc = d.Description();
|
||||
auto h = hash<string>{}(base_name + desc);
|
||||
return p_hash_type(h);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
namespace zeek::detail {
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool CPPCompile::IsNativeType(const TypePtr& t) const
|
||||
{
|
||||
if ( ! t )
|
||||
|
@ -45,8 +47,7 @@ bool CPPCompile::IsNativeType(const TypePtr& t) const
|
|||
}
|
||||
}
|
||||
|
||||
std::string CPPCompile::NativeToGT(const std::string& expr, const TypePtr& t,
|
||||
GenType gt)
|
||||
string CPPCompile::NativeToGT(const string& expr, const TypePtr& t, GenType gt)
|
||||
{
|
||||
if ( gt == GEN_DONT_CARE )
|
||||
return expr;
|
||||
|
@ -60,34 +61,34 @@ std::string CPPCompile::NativeToGT(const std::string& expr, const TypePtr& t,
|
|||
return expr;
|
||||
|
||||
case TYPE_BOOL:
|
||||
return std::string("val_mgr->Bool(") + expr + ")";
|
||||
return string("val_mgr->Bool(") + expr + ")";
|
||||
|
||||
case TYPE_INT:
|
||||
return std::string("val_mgr->Int(") + expr + ")";
|
||||
return string("val_mgr->Int(") + expr + ")";
|
||||
|
||||
case TYPE_COUNT:
|
||||
return std::string("val_mgr->Count(") + expr + ")";
|
||||
return string("val_mgr->Count(") + expr + ")";
|
||||
|
||||
case TYPE_PORT:
|
||||
return std::string("val_mgr->Port(") + expr + ")";
|
||||
return string("val_mgr->Port(") + expr + ")";
|
||||
|
||||
case TYPE_ENUM:
|
||||
return std::string("make_enum__CPP(") + GenTypeName(t) + ", " +
|
||||
return string("make_enum__CPP(") + GenTypeName(t) + ", " +
|
||||
expr + ")";
|
||||
|
||||
default:
|
||||
return std::string("make_intrusive<") + IntrusiveVal(t) +
|
||||
return string("make_intrusive<") + IntrusiveVal(t) +
|
||||
">(" + expr + ")";
|
||||
}
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenericValPtrToGT(const std::string& expr,
|
||||
const TypePtr& t, GenType gt)
|
||||
string CPPCompile::GenericValPtrToGT(const string& expr, const TypePtr& t,
|
||||
GenType gt)
|
||||
{
|
||||
if ( gt != GEN_VAL_PTR && IsNativeType(t) )
|
||||
return expr + NativeAccessor(t);
|
||||
else
|
||||
return std::string("cast_intrusive<") + IntrusiveVal(t) +
|
||||
return string("cast_intrusive<") + IntrusiveVal(t) +
|
||||
">(" + expr + ")";
|
||||
}
|
||||
|
||||
|
@ -117,12 +118,12 @@ void CPPCompile::ExpandTypeVar(const TypePtr& t)
|
|||
break;
|
||||
|
||||
case TYPE_TYPE:
|
||||
AddInit(t, tn, std::string("make_intrusive<TypeType>(") +
|
||||
AddInit(t, tn, string("make_intrusive<TypeType>(") +
|
||||
GenTypeName(t->AsTypeType()->GetType()) + ")");
|
||||
break;
|
||||
|
||||
case TYPE_VECTOR:
|
||||
AddInit(t, tn, std::string("make_intrusive<VectorType>(") +
|
||||
AddInit(t, tn, string("make_intrusive<VectorType>(") +
|
||||
GenTypeName(t->AsVectorType()->Yield()) + ")");
|
||||
break;
|
||||
|
||||
|
@ -137,7 +138,7 @@ void CPPCompile::ExpandTypeVar(const TypePtr& t)
|
|||
AddInit(t);
|
||||
}
|
||||
|
||||
void CPPCompile::ExpandListTypeVar(const TypePtr& t, std::string& tn)
|
||||
void CPPCompile::ExpandListTypeVar(const TypePtr& t, string& tn)
|
||||
{
|
||||
auto tl = t->AsTypeList()->GetTypes();
|
||||
auto t_name = tn + "->AsTypeList()";
|
||||
|
@ -147,12 +148,12 @@ void CPPCompile::ExpandListTypeVar(const TypePtr& t, std::string& tn)
|
|||
GenTypeName(tl[i]) + ");");
|
||||
}
|
||||
|
||||
void CPPCompile::ExpandRecordTypeVar(const TypePtr& t, std::string& tn)
|
||||
void CPPCompile::ExpandRecordTypeVar(const TypePtr& t, string& tn)
|
||||
{
|
||||
auto r = t->AsRecordType()->Types();
|
||||
auto t_name = tn + "->AsRecordType()";
|
||||
|
||||
AddInit(t, std::string("if ( ") + t_name + "->NumFields() == 0 )");
|
||||
AddInit(t, string("if ( ") + t_name + "->NumFields() == 0 )");
|
||||
|
||||
AddInit(t, "{");
|
||||
AddInit(t, "type_decl_list tl;");
|
||||
|
@ -167,7 +168,7 @@ void CPPCompile::ExpandRecordTypeVar(const TypePtr& t, std::string& tn)
|
|||
AddInit(t, "}");
|
||||
}
|
||||
|
||||
void CPPCompile::ExpandEnumTypeVar(const TypePtr& t, std::string& tn)
|
||||
void CPPCompile::ExpandEnumTypeVar(const TypePtr& t, string& tn)
|
||||
{
|
||||
auto e_name = tn + "->AsEnumType()";
|
||||
auto et = t->AsEnumType();
|
||||
|
@ -177,14 +178,14 @@ void CPPCompile::ExpandEnumTypeVar(const TypePtr& t, std::string& tn)
|
|||
AddInit(t, "if ( et->Names().size() == 0 ) {");
|
||||
|
||||
for ( const auto& name_pair : et->Names() )
|
||||
AddInit(t, std::string("\tet->AddNameInternal(\"") +
|
||||
AddInit(t, string("\tet->AddNameInternal(\"") +
|
||||
name_pair.first + "\", " +
|
||||
Fmt(int(name_pair.second)) + ");");
|
||||
|
||||
AddInit(t, "}}");
|
||||
}
|
||||
|
||||
void CPPCompile::ExpandTableTypeVar(const TypePtr& t, std::string& tn)
|
||||
void CPPCompile::ExpandTableTypeVar(const TypePtr& t, string& tn)
|
||||
{
|
||||
auto tbl = t->AsTableType();
|
||||
|
||||
|
@ -193,23 +194,23 @@ void CPPCompile::ExpandTableTypeVar(const TypePtr& t, std::string& tn)
|
|||
|
||||
if ( tbl->IsSet() )
|
||||
AddInit(t, tn,
|
||||
std::string("make_intrusive<SetType>(cast_intrusive<TypeList>(") +
|
||||
string("make_intrusive<SetType>(cast_intrusive<TypeList>(") +
|
||||
GenTypeName(indices) + " ), nullptr)");
|
||||
else
|
||||
AddInit(t, tn,
|
||||
std::string("make_intrusive<TableType>(cast_intrusive<TypeList>(") +
|
||||
string("make_intrusive<TableType>(cast_intrusive<TypeList>(") +
|
||||
GenTypeName(indices) + "), " +
|
||||
GenTypeName(yield) + ")");
|
||||
}
|
||||
|
||||
void CPPCompile::ExpandFuncTypeVar(const TypePtr& t, std::string& tn)
|
||||
void CPPCompile::ExpandFuncTypeVar(const TypePtr& t, string& tn)
|
||||
{
|
||||
auto f = t->AsFuncType();
|
||||
|
||||
auto args_type_accessor = GenTypeName(f->Params());
|
||||
auto yt = f->Yield();
|
||||
|
||||
std::string yield_type_accessor;
|
||||
string yield_type_accessor;
|
||||
|
||||
if ( yt )
|
||||
yield_type_accessor += GenTypeName(yt);
|
||||
|
@ -218,7 +219,7 @@ void CPPCompile::ExpandFuncTypeVar(const TypePtr& t, std::string& tn)
|
|||
|
||||
auto fl = f->Flavor();
|
||||
|
||||
std::string fl_name;
|
||||
string fl_name;
|
||||
if ( fl == FUNC_FLAVOR_FUNCTION )
|
||||
fl_name = "FUNC_FLAVOR_FUNCTION";
|
||||
else if ( fl == FUNC_FLAVOR_EVENT )
|
||||
|
@ -226,29 +227,29 @@ void CPPCompile::ExpandFuncTypeVar(const TypePtr& t, std::string& tn)
|
|||
else if ( fl == FUNC_FLAVOR_HOOK )
|
||||
fl_name = "FUNC_FLAVOR_HOOK";
|
||||
|
||||
auto type_init = std::string("make_intrusive<FuncType>(cast_intrusive<RecordType>(") +
|
||||
auto type_init = string("make_intrusive<FuncType>(cast_intrusive<RecordType>(") +
|
||||
args_type_accessor + "), " +
|
||||
yield_type_accessor + ", " + fl_name + ")";
|
||||
|
||||
AddInit(t, tn, type_init);
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenTypeDecl(const TypeDecl* td)
|
||||
string CPPCompile::GenTypeDecl(const TypeDecl* td)
|
||||
{
|
||||
auto type_accessor = GenTypeName(td->type);
|
||||
|
||||
auto td_name = std::string("util::copy_string(\"") + td->id + "\")";
|
||||
auto td_name = string("util::copy_string(\"") + td->id + "\")";
|
||||
|
||||
if ( td->attrs )
|
||||
return std::string("tl.append(new TypeDecl(") +
|
||||
return string("tl.append(new TypeDecl(") +
|
||||
td_name + ", " + type_accessor +
|
||||
", " + AttrsName(td->attrs) +"));";
|
||||
|
||||
return std::string("tl.append(new TypeDecl(") + td_name + ", " +
|
||||
type_accessor +"));";
|
||||
return string("tl.append(new TypeDecl(") + td_name + ", " +
|
||||
type_accessor +"));";
|
||||
}
|
||||
|
||||
std::string CPPCompile::GenTypeName(const Type* t)
|
||||
string CPPCompile::GenTypeName(const Type* t)
|
||||
{
|
||||
return types.KeyName(TypeRep(t));
|
||||
}
|
||||
|
|
|
@ -8,7 +8,9 @@
|
|||
|
||||
namespace zeek::detail {
|
||||
|
||||
std::string Fmt(double d)
|
||||
using namespace std;
|
||||
|
||||
string Fmt(double d)
|
||||
{
|
||||
// Special hack to preserve the signed-ness of the magic -0.0.
|
||||
if ( d == 0.0 && signbit(d) )
|
||||
|
@ -21,14 +23,14 @@ std::string Fmt(double d)
|
|||
return buf;
|
||||
}
|
||||
|
||||
std::string scope_prefix(const std::string& scope)
|
||||
string scope_prefix(const string& scope)
|
||||
{
|
||||
return std::string("zeek::detail::CPP_") + scope + "::";
|
||||
return string("zeek::detail::CPP_") + scope + "::";
|
||||
}
|
||||
|
||||
std::string scope_prefix(int scope)
|
||||
string scope_prefix(int scope)
|
||||
{
|
||||
return scope_prefix(std::to_string(scope));
|
||||
return scope_prefix(to_string(scope));
|
||||
}
|
||||
|
||||
bool is_CPP_compilable(const ProfileFunc* pf)
|
||||
|
@ -42,7 +44,7 @@ bool is_CPP_compilable(const ProfileFunc* pf)
|
|||
return true;
|
||||
}
|
||||
|
||||
void lock_file(const std::string& fname, FILE* f)
|
||||
void lock_file(const string& fname, FILE* f)
|
||||
{
|
||||
if ( flock(fileno(f), LOCK_EX) < 0 )
|
||||
{
|
||||
|
@ -53,7 +55,7 @@ void lock_file(const std::string& fname, FILE* f)
|
|||
}
|
||||
}
|
||||
|
||||
void unlock_file(const std::string& fname, FILE* f)
|
||||
void unlock_file(const string& fname, FILE* f)
|
||||
{
|
||||
if ( flock(fileno(f), LOCK_UN) < 0 )
|
||||
{
|
||||
|
|
|
@ -10,11 +10,13 @@
|
|||
|
||||
namespace zeek::detail {
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool CPPCompile::CheckForCollisions()
|
||||
{
|
||||
for ( auto& g : pfs.AllGlobals() )
|
||||
{
|
||||
auto gn = std::string(g->Name());
|
||||
auto gn = string(g->Name());
|
||||
|
||||
if ( hm.HasGlobal(gn) )
|
||||
{
|
||||
|
@ -75,7 +77,7 @@ bool CPPCompile::CheckForCollisions()
|
|||
|
||||
void CPPCompile::CreateGlobal(const ID* g)
|
||||
{
|
||||
auto gn = std::string(g->Name());
|
||||
auto gn = string(g->Name());
|
||||
bool is_bif = pfs.BiFGlobals().count(g) > 0;
|
||||
|
||||
if ( pfs.Globals().count(g) == 0 )
|
||||
|
@ -108,7 +110,7 @@ void CPPCompile::CreateGlobal(const ID* g)
|
|||
NoteInitDependency(g, TypeRep(t));
|
||||
|
||||
AddInit(g, globals[gn],
|
||||
std::string("lookup_global__CPP(\"") + gn + "\", " +
|
||||
string("lookup_global__CPP(\"") + gn + "\", " +
|
||||
GenTypeName(t) + ")");
|
||||
}
|
||||
|
||||
|
@ -159,17 +161,17 @@ void CPPCompile::UpdateGlobalHashes()
|
|||
void CPPCompile::AddBiF(const ID* b, bool is_var)
|
||||
{
|
||||
auto bn = b->Name();
|
||||
auto n = std::string(bn);
|
||||
auto n = string(bn);
|
||||
if ( is_var )
|
||||
n = n + "_"; // make the name distinct
|
||||
|
||||
if ( AddGlobal(n, "bif", true) )
|
||||
Emit("Func* %s;", globals[n]);
|
||||
|
||||
AddInit(b, globals[n], std::string("lookup_bif__CPP(\"") + bn + "\")");
|
||||
AddInit(b, globals[n], string("lookup_bif__CPP(\"") + bn + "\")");
|
||||
}
|
||||
|
||||
bool CPPCompile::AddGlobal(const std::string& g, const char* suffix, bool track)
|
||||
bool CPPCompile::AddGlobal(const string& g, const char* suffix, bool track)
|
||||
{
|
||||
bool new_var = false;
|
||||
|
||||
|
@ -194,16 +196,16 @@ bool CPPCompile::AddGlobal(const std::string& g, const char* suffix, bool track)
|
|||
return new_var;
|
||||
}
|
||||
|
||||
void CPPCompile::RegisterEvent(std::string ev_name)
|
||||
void CPPCompile::RegisterEvent(string ev_name)
|
||||
{
|
||||
body_events[body_name].emplace_back(std::move(ev_name));
|
||||
body_events[body_name].emplace_back(move(ev_name));
|
||||
}
|
||||
|
||||
const std::string& CPPCompile::IDNameStr(const ID* id) const
|
||||
const string& CPPCompile::IDNameStr(const ID* id) const
|
||||
{
|
||||
if ( id->IsGlobal() )
|
||||
{
|
||||
auto g = std::string(id->Name());
|
||||
auto g = string(id->Name());
|
||||
ASSERT(globals.count(g) > 0);
|
||||
return ((CPPCompile*)(this))->globals[g];
|
||||
}
|
||||
|
@ -213,7 +215,7 @@ const std::string& CPPCompile::IDNameStr(const ID* id) const
|
|||
return ((CPPCompile*)(this))->locals[id];
|
||||
}
|
||||
|
||||
std::string CPPCompile::LocalName(const ID* l) const
|
||||
string CPPCompile::LocalName(const ID* l) const
|
||||
{
|
||||
auto n = l->Name();
|
||||
auto without_module = strstr(n, "::");
|
||||
|
@ -224,9 +226,9 @@ std::string CPPCompile::LocalName(const ID* l) const
|
|||
return Canonicalize(n);
|
||||
}
|
||||
|
||||
std::string CPPCompile::Canonicalize(const char* name) const
|
||||
string CPPCompile::Canonicalize(const char* name) const
|
||||
{
|
||||
std::string cname;
|
||||
string cname;
|
||||
|
||||
for ( int i = 0; name[i]; ++i )
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue