diff --git a/src/script_opt/CPP/Driver.cc b/src/script_opt/CPP/Driver.cc index d9d0081300..2c4f2fa6e7 100644 --- a/src/script_opt/CPP/Driver.cc +++ b/src/script_opt/CPP/Driver.cc @@ -15,7 +15,7 @@ using namespace std; CPPCompile::CPPCompile(vector& _funcs, ProfileFuncs& _pfs, const string& gen_name, const string& _addl_name, CPPHashManager& _hm, bool _update, bool _standalone, - bool report_uncompilable) + bool report_uncompilable) : funcs(_funcs), pfs(_pfs), hm(_hm), update(_update), standalone(_standalone) { diff --git a/src/script_opt/CPP/Inits.cc b/src/script_opt/CPP/Inits.cc index 7f22b349eb..a4f78242cd 100644 --- a/src/script_opt/CPP/Inits.cc +++ b/src/script_opt/CPP/Inits.cc @@ -280,10 +280,7 @@ void CPPCompile::AddInit(const Obj* o, const string& init) void CPPCompile::AddInit(const Obj* o) { if ( obj_inits.count(o) == 0 ) - { - vector empty; - obj_inits[o] = empty; - } + obj_inits[o] = {}; } void CPPCompile::NoteInitDependency(const Obj* o1, const Obj* o2) diff --git a/src/script_opt/GenIDDefs.cc b/src/script_opt/GenIDDefs.cc index 36137ffdcc..45ac43e3af 100644 --- a/src/script_opt/GenIDDefs.cc +++ b/src/script_opt/GenIDDefs.cc @@ -27,9 +27,7 @@ void GenIDDefs::TraverseFunction(const Func* f, ScopePtr scope, StmtPtr body) // Establish the outermost barrior and associated set of // identifiers. barrier_blocks.push_back(0); - - std::unordered_set empty_IDs; - modified_IDs.push_back(empty_IDs); + modified_IDs.push_back({}); for ( const auto& g : pf->Globals() ) { @@ -442,9 +440,7 @@ void GenIDDefs::StartConfluenceBlock(const Stmt* s) barrier_blocks.push_back(confluence_blocks.size()); confluence_blocks.push_back(s); - - std::unordered_set empty_IDs; - modified_IDs.push_back(empty_IDs); + modified_IDs.push_back({}); } void GenIDDefs::EndConfluenceBlock(bool no_orig) diff --git a/src/script_opt/GenRDs.cc b/src/script_opt/GenRDs.cc index 198fbdc447..7e62a276dd 100644 --- a/src/script_opt/GenRDs.cc +++ b/src/script_opt/GenRDs.cc @@ -11,7 +11,7 @@ namespace zeek::detail { RD_Decorate::RD_Decorate(std::shared_ptr _pf, const Func* f, - ScopePtr scope, StmtPtr body) + ScopePtr scope, StmtPtr body) : pf(std::move(_pf)) { TraverseFunction(f, scope, body); diff --git a/src/script_opt/IDOptInfo.cc b/src/script_opt/IDOptInfo.cc index 641225be82..76d730b4a5 100644 --- a/src/script_opt/IDOptInfo.cc +++ b/src/script_opt/IDOptInfo.cc @@ -257,8 +257,7 @@ void IDOptInfo::StartConfluenceBlock(const Stmt* s) } } - ConfluenceSet empty_set; - pending_confluences[s] = empty_set; + pending_confluences[s] = {}; confluence_stmts.push_back(s); block_has_orig_flow.push_back(s_oi->contains_branch_beyond); diff --git a/src/script_opt/ProfileFunc.h b/src/script_opt/ProfileFunc.h index c653281c7e..f183ad4ade 100644 --- a/src/script_opt/ProfileFunc.h +++ b/src/script_opt/ProfileFunc.h @@ -281,7 +281,7 @@ protected: // profile is compilable. Alternatively we could derive subclasses // from ProfileFuncs and use a virtual method for this, but that seems // heavier-weight for what's really a simple notion. -typedef bool (*is_compilable_pred)(const ProfileFunc*, const char** reason); +using is_compilable_pred = bool (*)(const ProfileFunc*, const char** reason); // Collectively profile an entire collection of functions. class ProfileFuncs { diff --git a/src/script_opt/ZAM/Branches.cc b/src/script_opt/ZAM/Branches.cc index 800a8232ae..330e5cbd0f 100644 --- a/src/script_opt/ZAM/Branches.cc +++ b/src/script_opt/ZAM/Branches.cc @@ -11,8 +11,7 @@ namespace zeek::detail { void ZAMCompiler::PushGoTos(GoToSets& gotos) { - std::vector vi; - gotos.push_back(vi); + gotos.push_back({}); } void ZAMCompiler::ResolveGoTos(GoToSets& gotos, const InstLabel l) diff --git a/src/script_opt/ZAM/Driver.cc b/src/script_opt/ZAM/Driver.cc index a37f228f98..c7edf982fd 100644 --- a/src/script_opt/ZAM/Driver.cc +++ b/src/script_opt/ZAM/Driver.cc @@ -79,7 +79,7 @@ void ZAMCompiler::InitArgs() push_existing_scope(scope); - for ( auto a : args ) + for ( auto& a : args ) { if ( --nparam < 0 ) break; @@ -369,7 +369,7 @@ void ZAMCompiler::ConcretizeSwitchTables(const CaseMapsI& abstract_cases, CaseMap cm; for ( auto& targ : targs ) cm[targ.first] = targ.second->inst_num; - concrete_cases.push_back(cm); + concrete_cases.emplace_back(cm); } } diff --git a/src/script_opt/ZAM/Gen-ZAM.cc b/src/script_opt/ZAM/Gen-ZAM.cc index 2c94b074c9..ce758edcf0 100644 --- a/src/script_opt/ZAM/Gen-ZAM.cc +++ b/src/script_opt/ZAM/Gen-ZAM.cc @@ -109,7 +109,7 @@ ArgsManager::ArgsManager(const vector& ot, ZAM_InstClass zc) int n = 0; bool add_field = false; - for ( auto ot_i : ot ) + for ( const auto& ot_i : ot ) { if ( ot_i == ZAM_OT_NONE ) { // it had better be the only operand type @@ -421,11 +421,10 @@ int ZAM_OpTemplate::ExtractTypeParam(const string& arg) if ( arg == "$$" ) return 1; - auto param_str = arg.c_str(); - if ( *param_str != '$' ) + if ( arg[0] != '$' ) g->Gripe("bad set-type parameter, should be $n", arg); - int param = atoi(¶m_str[1]); + int param = atoi(&arg[1]); if ( param <= 0 || param > 2 ) g->Gripe("bad set-type parameter, should be $1 or $2", arg); @@ -571,10 +570,7 @@ void ZAM_OpTemplate::InstantiateMethodCore(const vector& ot, } ArgsManager args(ot, zc); - - auto params = args.Params(); - - BuildInstruction(ot, params, full_suffix, zc); + BuildInstruction(ot, args.Params(), full_suffix, zc); auto tp = GetTypeParam(); if ( tp > 0 ) diff --git a/src/script_opt/ZAM/ZBody.cc b/src/script_opt/ZAM/ZBody.cc index 0d0c271b92..15adc3a974 100644 --- a/src/script_opt/ZAM/ZBody.cc +++ b/src/script_opt/ZAM/ZBody.cc @@ -316,7 +316,7 @@ ValPtr ZBody::DoExec(Frame* f, int start_pc, StmtFlowType& flow) if ( do_profile ) { double dt = curr_CPU_time() - profile_CPU; - (*inst_CPU)[profile_pc] += dt; + inst_CPU->at(profile_pc) += dt; ZOP_CPU[z.op] += dt; } #endif diff --git a/src/script_opt/ZAM/ZInst.cc b/src/script_opt/ZAM/ZInst.cc index 7040510d5c..a4c3b0f8ff 100644 --- a/src/script_opt/ZAM/ZInst.cc +++ b/src/script_opt/ZAM/ZInst.cc @@ -137,64 +137,76 @@ void ZInst::Dump(const string& id1, const string& id2, const string& id3, int ZInst::NumFrameSlots() const { switch ( op_type ) { - case OP_X: return 0; - case OP_V: return 1; - case OP_VV: return 2; - case OP_VVV: return 3; - case OP_VVVV: return 4; - case OP_VVVC: return 3; - case OP_C: return 0; - case OP_VC: return 1; - case OP_VVC: return 2; + case OP_X: + case OP_C: + case OP_V_I1: + case OP_VC_I1: + case OP_VV_I1_I2: + case OP_VVVC_I1_I2_I3: + return 0; - case OP_V_I1: return 0; - case OP_VC_I1: return 0; - case OP_VV_I1_I2: return 0; - case OP_VV_FRAME: return 1; - case OP_VV_I2: return 1; - case OP_VVC_I2: return 1; - case OP_VVV_I3: return 2; - case OP_VVV_I2_I3: return 1; + case OP_V: + case OP_VC: + case OP_VV_FRAME: + case OP_VV_I2: + case OP_VVC_I2: + case OP_VVV_I2_I3: + case OP_VVVC_I2_I3: + case OP_VVVV_I2_I3_I4: + return 1; - case OP_VVVV_I4: return 3; - case OP_VVVV_I3_I4: return 2; - case OP_VVVV_I2_I3_I4: return 1; - case OP_VVVC_I3: return 2; - case OP_VVVC_I2_I3: return 1; - case OP_VVVC_I1_I2_I3: return 0; + case OP_VV: + case OP_VVC: + case OP_VVV_I3: + case OP_VVVC_I3: + case OP_VVVV_I3_I4: + return 2; + + case OP_VVV: + case OP_VVVC: + case OP_VVVV_I4: + return 3; + + case OP_VVVV: + return 4; } } int ZInst::NumSlots() const { switch ( op_type ) { - case OP_X: return 0; - case OP_C: return 0; - case OP_V: return 1; - case OP_VC: return 1; - case OP_VV: return 2; - case OP_VVC: return 2; - case OP_VVV: return 3; - case OP_VVVC: return 3; - case OP_VVVV: return 4; + case OP_C: + case OP_X: + return 0; - case OP_V_I1: return 1; - case OP_VC_I1: return 1; + case OP_V: + case OP_V_I1: + case OP_VC: + case OP_VC_I1: + return 1; - case OP_VV_I1_I2: return 2; - case OP_VV_FRAME: return 2; - case OP_VV_I2: return 2; - case OP_VVC_I2: return 2; + case OP_VV: + case OP_VVC: + case OP_VV_FRAME: + case OP_VV_I2: + case OP_VVC_I2: + case OP_VV_I1_I2: + return 2; - case OP_VVV_I3: return 3; - case OP_VVV_I2_I3: return 3; - case OP_VVVC_I3: return 3; - case OP_VVVC_I2_I3: return 3; - case OP_VVVC_I1_I2_I3: return 3; + case OP_VVV: + case OP_VVV_I3: + case OP_VVV_I2_I3: + case OP_VVVC: + case OP_VVVC_I3: + case OP_VVVC_I2_I3: + case OP_VVVC_I1_I2_I3: + return 3; - case OP_VVVV_I4: return 4; - case OP_VVVV_I3_I4: return 4; - case OP_VVVV_I2_I3_I4: return 4; + case OP_VVVV: + case OP_VVVV_I4: + case OP_VVVV_I3_I4: + case OP_VVVV_I2_I3_I4: + return 4; } } diff --git a/src/script_opt/ZAM/ZOp.h b/src/script_opt/ZAM/ZOp.h index e0110e129b..8cda1f9d8c 100644 --- a/src/script_opt/ZAM/ZOp.h +++ b/src/script_opt/ZAM/ZOp.h @@ -7,10 +7,10 @@ namespace zeek::detail { // Opcodes associated with ZAM instructions. -typedef enum { +enum ZOp { #include "zeek/ZAM-OpsDefs.h" OP_NOP, -} ZOp; +}; // Possible types of instruction operands in terms of which fields they use. @@ -22,7 +22,7 @@ typedef enum { // I1/I2/I3/I4: the instruction's integer value, used directly (not as a slot) // FRAME: a slot in the (intrepreter) Frame object // X: no operands -typedef enum { +enum ZAMOpType { OP_X, OP_C, OP_V, OP_V_I1, OP_VC_I1, OP_VC, @@ -46,15 +46,15 @@ typedef enum { OP_VVVV_I3_I4, OP_VVVV_I2_I3_I4, -} ZAMOpType; +}; // Possible "flavors" for an operator's first slot. -typedef enum { +enum ZAMOp1Flavor { OP1_READ, // the slot is read, not modified OP1_WRITE, // the slot is modified, not read - the most common OP1_READ_WRITE, // the slot is both read and then modified, e.g. "++" OP1_INTERNAL, // we're doing some internal manipulation of the slot -} ZAMOp1Flavor; +}; // Maps an operand to its flavor. extern ZAMOp1Flavor op1_flavor[];