mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Clang-tidy fixes for recent IDPtr changes
This commit is contained in:
parent
e3b22cd21f
commit
26ea7cc655
18 changed files with 50 additions and 51 deletions
|
@ -4270,7 +4270,7 @@ LambdaExpr::LambdaExpr(LambdaExpr* orig) : Expr(EXPR_LAMBDA) {
|
|||
|
||||
// We need to have our own copies of the outer IDs and captures so
|
||||
// we can rename them when inlined.
|
||||
for ( auto i : orig->outer_ids )
|
||||
for ( auto& i : orig->outer_ids )
|
||||
outer_ids.emplace_back(i);
|
||||
|
||||
if ( orig->captures ) {
|
||||
|
@ -4325,7 +4325,7 @@ bool LambdaExpr::CheckCaptures(StmtPtr when_parent) {
|
|||
}
|
||||
}
|
||||
|
||||
for ( auto id : outer_ids )
|
||||
for ( const auto& id : outer_ids )
|
||||
if ( ! outer_is_matched.contains(id) ) {
|
||||
auto msg = util::fmt("%s is used inside %s but not captured", id->Name(), desc);
|
||||
if ( when_parent )
|
||||
|
|
|
@ -183,7 +183,7 @@ void Trigger::ReInit(std::vector<ValPtr> index_expr_results) {
|
|||
have_trigger_elems = true;
|
||||
}
|
||||
|
||||
for ( auto g : globals ) {
|
||||
for ( const auto& g : globals ) {
|
||||
Register(g.get());
|
||||
|
||||
auto& v = g->GetVal();
|
||||
|
@ -191,7 +191,7 @@ void Trigger::ReInit(std::vector<ValPtr> index_expr_results) {
|
|||
Register(v.get());
|
||||
}
|
||||
|
||||
for ( auto l : locals ) {
|
||||
for ( const auto& l : locals ) {
|
||||
ASSERT(! l->GetVal());
|
||||
}
|
||||
|
||||
|
|
|
@ -761,7 +761,7 @@ IDPList gather_outer_ids(ScopePtr scope, StmtPtr body) {
|
|||
IDPList idl;
|
||||
|
||||
for ( auto& id : cb.outer_id_references )
|
||||
idl.emplace_back(std::move(id));
|
||||
idl.emplace_back(id);
|
||||
|
||||
return idl;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ void CPPCompile::DeclareLambda(const LambdaExpr* l, const ProfileFunc* pf) {
|
|||
auto l_id = l->Ingredients()->GetID();
|
||||
auto& ids = l->OuterIDs();
|
||||
|
||||
for ( auto lid : ids ) {
|
||||
for ( const auto& lid : ids ) {
|
||||
if ( lambda_names.contains(lid) ) {
|
||||
ASSERT(lambda_names[lid] == CaptureName(lid));
|
||||
}
|
||||
|
@ -227,7 +227,7 @@ void CPPCompile::BuildLambda(const FuncTypePtr& ft, const ProfileFunc* pf, const
|
|||
Emit("void SetLambdaCaptures(Frame* f) override");
|
||||
StartBlock();
|
||||
for ( size_t i = 0; i < nl; ++i ) {
|
||||
auto l_i = (*lambda_ids)[i];
|
||||
const auto& l_i = (*lambda_ids)[i];
|
||||
const auto& t_i = l_i->GetType();
|
||||
auto cap_i = string("f->GetElement(") + Fmt(static_cast<int>(i)) + ")";
|
||||
Emit("%s = %s;", lambda_names[l_i], GenericValPtrToGT(cap_i, t_i, GEN_NATIVE));
|
||||
|
@ -239,7 +239,7 @@ void CPPCompile::BuildLambda(const FuncTypePtr& ft, const ProfileFunc* pf, const
|
|||
StartBlock();
|
||||
Emit("std::vector<ValPtr> vals;");
|
||||
for ( size_t i = 0; i < nl; ++i ) {
|
||||
auto l_i = (*lambda_ids)[i];
|
||||
const auto& l_i = (*lambda_ids)[i];
|
||||
const auto& t_i = l_i->GetType();
|
||||
Emit("vals.emplace_back(%s);", NativeToGT(lambda_names[l_i], t_i, GEN_VAL_PTR));
|
||||
}
|
||||
|
|
|
@ -145,7 +145,7 @@ void CPPCompile::DeclareLocals(const ProfileFunc* pf, const IDPList* lambda_ids)
|
|||
// latter can be inconsistent when inlining.
|
||||
set<string> capture_names;
|
||||
if ( lambda_ids )
|
||||
for ( auto li : *lambda_ids )
|
||||
for ( const auto& li : *lambda_ids )
|
||||
capture_names.insert(CaptureName(li));
|
||||
|
||||
const auto& ls = pf->Locals();
|
||||
|
|
|
@ -178,7 +178,7 @@ void CPPCompile::GenTypeSwitchStmt(const Expr* e, const case_list* cases) {
|
|||
for ( const auto& c : *cases ) {
|
||||
auto tc = c->TypeCases();
|
||||
if ( tc )
|
||||
for ( auto id : *tc )
|
||||
for ( const auto& id : *tc )
|
||||
Emit(Fmt(TypeOffset(id->GetType())) + ",");
|
||||
}
|
||||
EndBlock(true);
|
||||
|
@ -206,7 +206,7 @@ void CPPCompile::GenTypeSwitchStmt(const Expr* e, const case_list* cases) {
|
|||
auto tc = c->TypeCases();
|
||||
if ( tc ) {
|
||||
bool is_multi = tc->size() > 1;
|
||||
for ( auto id : *tc )
|
||||
for ( const auto& id : *tc )
|
||||
GenTypeSwitchCase(id, case_offset++, is_multi);
|
||||
}
|
||||
else
|
||||
|
@ -432,7 +432,7 @@ void CPPCompile::GenForOverTable(const ExprPtr& tbl, const IDPtr& value_var, con
|
|||
|
||||
int n = static_cast<int>(loop_vars->size());
|
||||
for ( int i = 0; i < n; ++i ) {
|
||||
auto var = (*loop_vars)[i];
|
||||
const auto& var = (*loop_vars)[i];
|
||||
if ( var->IsBlank() )
|
||||
continue;
|
||||
|
||||
|
@ -454,7 +454,7 @@ void CPPCompile::GenForOverVector(const ExprPtr& vec, const IDPtr& value_var, co
|
|||
|
||||
Emit("if ( ! vv__CPP->Has(i__CPP) ) continue;");
|
||||
|
||||
auto lv0 = (*loop_vars)[0];
|
||||
const auto& lv0 = (*loop_vars)[0];
|
||||
|
||||
if ( ! lv0->IsBlank() )
|
||||
Emit("%s = i__CPP;", IDName(lv0));
|
||||
|
@ -475,7 +475,7 @@ void CPPCompile::GenForOverString(const ExprPtr& str, const IDPList* loop_vars)
|
|||
|
||||
Emit("auto sv__CPP = make_intrusive<StringVal>(1, (const char*) sval__CPP->Bytes() + i__CPP);");
|
||||
|
||||
auto lv0 = (*loop_vars)[0];
|
||||
const auto& lv0 = (*loop_vars)[0];
|
||||
if ( ! lv0->IsBlank() )
|
||||
Emit("%s = std::move(sv__CPP);", IDName(lv0));
|
||||
}
|
||||
|
|
|
@ -212,7 +212,7 @@ TraversalCode CSE_ValidityChecker::PostExpr(const Expr* e) {
|
|||
}
|
||||
|
||||
bool CSE_ValidityChecker::CheckID(const IDPtr& id, bool ignore_orig) {
|
||||
for ( auto i : ids ) {
|
||||
for ( const auto& i : ids ) {
|
||||
if ( ignore_orig && i == ids.front() )
|
||||
continue;
|
||||
|
||||
|
@ -227,7 +227,7 @@ bool CSE_ValidityChecker::CheckAggrMod(const TypePtr& t) {
|
|||
if ( ! IsAggr(t) )
|
||||
return false;
|
||||
|
||||
for ( auto i : ids )
|
||||
for ( const auto& i : ids )
|
||||
if ( same_type(t, i->GetType()) )
|
||||
return Invalid();
|
||||
|
||||
|
@ -287,8 +287,8 @@ bool CSE_ValidityChecker::CheckSideEffects(const IDSet& non_local_ids, const Typ
|
|||
// This is far and away the most common case.
|
||||
return false;
|
||||
|
||||
for ( auto i : ids ) {
|
||||
for ( auto nli : non_local_ids )
|
||||
for ( const auto& i : ids ) {
|
||||
for ( const auto& nli : non_local_ids )
|
||||
if ( nli == i )
|
||||
return Invalid();
|
||||
|
||||
|
|
|
@ -426,7 +426,7 @@ void GenIDDefs::StartConfluenceBlock(const Stmt* s) {
|
|||
}
|
||||
|
||||
void GenIDDefs::EndConfluenceBlock(bool no_orig) {
|
||||
for ( auto id : modified_IDs.back() )
|
||||
for ( const auto& id : modified_IDs.back() )
|
||||
id->GetOptInfo()->ConfluenceBlockEndsAfter(last_stmt_traversed, no_orig);
|
||||
|
||||
confluence_blocks.pop_back();
|
||||
|
@ -434,12 +434,12 @@ void GenIDDefs::EndConfluenceBlock(bool no_orig) {
|
|||
}
|
||||
|
||||
void GenIDDefs::BranchBackTo(const Stmt* from, const Stmt* to, bool close_all) {
|
||||
for ( auto id : modified_IDs.back() )
|
||||
for ( const auto& id : modified_IDs.back() )
|
||||
id->GetOptInfo()->BranchBackTo(from, to, close_all);
|
||||
}
|
||||
|
||||
void GenIDDefs::BranchBeyond(const Stmt* from, const Stmt* to, bool close_all) {
|
||||
for ( auto id : modified_IDs.back() )
|
||||
for ( const auto& id : modified_IDs.back() )
|
||||
id->GetOptInfo()->BranchBeyond(from, to, close_all);
|
||||
|
||||
to->GetOptInfo()->contains_branch_beyond = true;
|
||||
|
@ -479,7 +479,7 @@ void GenIDDefs::ReturnAt(const Stmt* s) {
|
|||
// identifier as encountering a scope-ending "return" here. By avoiding
|
||||
// that, we're able to do optimization across catch-return blocks.
|
||||
if ( cr_active.empty() || cr_active.back() != confluence_blocks.size() )
|
||||
for ( auto id : modified_IDs.back() )
|
||||
for ( const auto& id : modified_IDs.back() )
|
||||
id->GetOptInfo()->ReturnAt(s);
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ ProfileFunc::ProfileFunc(const Func* func, const StmtPtr& body, bool _abs_rec_fi
|
|||
int offset = 0;
|
||||
|
||||
for ( auto& c : *fcaps ) {
|
||||
auto cid = c.Id();
|
||||
const auto& cid = c.Id();
|
||||
captures.insert(cid);
|
||||
captures_offsets[cid] = offset++;
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ ProfileFunc::ProfileFunc(const Func* func, const StmtPtr& body, bool _abs_rec_fi
|
|||
// declaration.
|
||||
num_params = profiled_func_t->Params()->NumFields();
|
||||
|
||||
for ( auto l : locals ) {
|
||||
for ( const auto& l : locals ) {
|
||||
if ( ! captures.contains(l) && l->Offset() < num_params )
|
||||
params.insert(l);
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ ProfileFunc::ProfileFunc(const Expr* e, bool _abs_rec_fields) {
|
|||
|
||||
int offset = 0;
|
||||
|
||||
for ( auto oid : func->OuterIDs() ) {
|
||||
for ( const auto& oid : func->OuterIDs() ) {
|
||||
captures.insert(oid);
|
||||
captures_offsets[oid] = offset++;
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ TraversalCode ProfileFunc::PreStmt(const Stmt* s) {
|
|||
auto w = s->AsWhenStmt();
|
||||
auto wi = w->Info();
|
||||
|
||||
for ( auto wl : wi->WhenNewLocals() )
|
||||
for ( const auto& wl : wi->WhenNewLocals() )
|
||||
when_locals.insert(wl);
|
||||
} break;
|
||||
|
||||
|
@ -139,7 +139,7 @@ TraversalCode ProfileFunc::PreStmt(const Stmt* s) {
|
|||
auto loop_vars = sf->LoopVars();
|
||||
auto value_var = sf->ValueVar();
|
||||
|
||||
for ( auto id : *loop_vars )
|
||||
for ( const auto& id : *loop_vars )
|
||||
locals.insert(id);
|
||||
|
||||
if ( value_var )
|
||||
|
@ -161,7 +161,7 @@ TraversalCode ProfileFunc::PreStmt(const Stmt* s) {
|
|||
for ( auto& c : *sw->Cases() ) {
|
||||
auto idl = c->TypeCases();
|
||||
if ( idl ) {
|
||||
for ( auto id : *idl )
|
||||
for ( const auto& id : *idl )
|
||||
// Make sure it's not a placeholder
|
||||
// identifier, used when there's
|
||||
// no explicit one.
|
||||
|
@ -541,7 +541,7 @@ void ProfileFunc::TrackID(const IDPtr id) {
|
|||
}
|
||||
|
||||
void ProfileFunc::TrackAssignment(const IDPtr id) {
|
||||
if ( assignees.count(id) > 0 )
|
||||
if ( assignees.contains(id) )
|
||||
++assignees[id];
|
||||
else
|
||||
assignees[id] = 1;
|
||||
|
@ -685,7 +685,7 @@ bool ProfileFuncs::GetCallSideEffects(const NameExpr* n, IDSet& non_local_ids, T
|
|||
|
||||
for ( auto a : seo->ModAggrs() )
|
||||
aggrs.insert(a);
|
||||
for ( auto nl : seo->ModNonLocals() )
|
||||
for ( const auto& nl : seo->ModNonLocals() )
|
||||
non_local_ids.insert(nl);
|
||||
|
||||
return true;
|
||||
|
@ -878,7 +878,7 @@ void ProfileFuncs::ComputeProfileHash(std::shared_ptr<ProfileFunc> pf) {
|
|||
h = merge_p_hashes(h, p_hash(i->Tag()));
|
||||
|
||||
h = merge_p_hashes(h, p_hash("ids"));
|
||||
for ( auto i : pf->OrderedIdentifiers() )
|
||||
for ( const auto& i : pf->OrderedIdentifiers() )
|
||||
h = merge_p_hashes(h, p_hash(i->Name()));
|
||||
|
||||
h = merge_p_hashes(h, p_hash("constants"));
|
||||
|
@ -1408,7 +1408,7 @@ bool ProfileFuncs::AssessSideEffects(const SideEffectsOp* se, SideEffectsOp::Acc
|
|||
|
||||
for ( auto a : se->ModAggrs() )
|
||||
aggrs.insert(a);
|
||||
for ( auto nl : se->ModNonLocals() )
|
||||
for ( const auto& nl : se->ModNonLocals() )
|
||||
non_local_ids.insert(nl);
|
||||
|
||||
return false;
|
||||
|
|
|
@ -322,7 +322,7 @@ bool Reducer::ID_IsReducedOrTopLevel(const IDPtr& id) {
|
|||
}
|
||||
|
||||
bool Reducer::ID_IsReduced(const IDPtr& id) const {
|
||||
return inline_block_level == 0 || tracked_ids.count(id) > 0 || id->IsGlobal() || IsTemporary(id);
|
||||
return inline_block_level == 0 || tracked_ids.contains(id) || id->IsGlobal() || IsTemporary(id);
|
||||
}
|
||||
|
||||
StmtPtr Reducer::GenParam(const IDPtr& id, ExprPtr rhs, bool is_modified) {
|
||||
|
@ -518,8 +518,7 @@ bool Reducer::ExprValid(const IDPtr& id, const Expr* e1, const Expr* e2) const {
|
|||
|
||||
// Tracks which ID's are germane for our analysis.
|
||||
std::vector<IDPtr> ids;
|
||||
|
||||
ids.push_back(std::move(id));
|
||||
ids.push_back(id);
|
||||
|
||||
// Identify variables involved in the expression.
|
||||
CheckIDs(e1->GetOp1(), ids);
|
||||
|
@ -550,7 +549,7 @@ void Reducer::CheckIDs(const ExprPtr& e, std::vector<IDPtr>& ids) const {
|
|||
}
|
||||
|
||||
bool Reducer::IsCSE(const AssignExpr* a, const NameExpr* lhs, const Expr* rhs) {
|
||||
auto lhs_id = lhs->IdPtr();
|
||||
const auto& lhs_id = lhs->IdPtr();
|
||||
auto lhs_tmp = FindTemporary(lhs_id); // nil if LHS not a temporary
|
||||
auto rhs_tmp = FindExprTmp(rhs, a, lhs_tmp);
|
||||
|
||||
|
@ -705,7 +704,7 @@ ExprPtr Reducer::UpdateExpr(ExprPtr e) {
|
|||
|
||||
StmtPtr Reducer::MergeStmts(const NameExpr* lhs, ExprPtr rhs, const StmtPtr& succ_stmt) {
|
||||
// First check for tmp=rhs.
|
||||
auto lhs_id = lhs->IdPtr();
|
||||
const auto& lhs_id = lhs->IdPtr();
|
||||
auto lhs_tmp = FindTemporary(lhs_id);
|
||||
|
||||
if ( ! lhs_tmp )
|
||||
|
|
|
@ -83,7 +83,7 @@ public:
|
|||
bool IsTemporary(const IDPtr& id) const { return FindTemporary(id) != nullptr; }
|
||||
bool IsParamTemp(const IDPtr& id) const { return param_temps.contains(id); }
|
||||
|
||||
bool IsConstantVar(const IDPtr& id) const { return constant_vars.find(id) != constant_vars.end(); }
|
||||
bool IsConstantVar(const IDPtr& id) const { return constant_vars.contains(id); }
|
||||
|
||||
// True if the Reducer is being used in the context of a second
|
||||
// pass over for AST optimization.
|
||||
|
|
|
@ -69,7 +69,7 @@ UsageAnalyzer::UsageAnalyzer(std::vector<FuncInfo>& funcs) {
|
|||
for ( auto& gpair : globals ) {
|
||||
auto& id = gpair.second;
|
||||
|
||||
if ( reachables.count(id) > 0 )
|
||||
if ( reachables.contains(id) )
|
||||
continue;
|
||||
|
||||
auto f = GetFuncIfAny(id);
|
||||
|
@ -119,7 +119,7 @@ public:
|
|||
TraversalCode PreID(const ID* raw_id) override {
|
||||
IDPtr id{NewRef{}, const_cast<ID*>(raw_id)};
|
||||
|
||||
if ( ids.count(id) > 0 )
|
||||
if ( ids.contains(id) )
|
||||
return TC_ABORTSTMT;
|
||||
|
||||
if ( attr_depth > 0 )
|
||||
|
@ -151,7 +151,7 @@ void UsageAnalyzer::FindSeeds(IDSet& seeds) const {
|
|||
auto f = GetFuncIfAny(id);
|
||||
|
||||
if ( f && id->GetType<FuncType>()->Flavor() == FUNC_FLAVOR_EVENT ) {
|
||||
if ( script_events.count(f->GetName()) == 0 )
|
||||
if ( ! script_events.contains(f->GetName()) )
|
||||
seeds.insert(id);
|
||||
|
||||
continue;
|
||||
|
@ -201,7 +201,7 @@ void UsageAnalyzer::FullyExpandReachables() {
|
|||
bool UsageAnalyzer::ExpandReachables(const IDSet& curr_r) {
|
||||
new_reachables.clear();
|
||||
|
||||
for ( auto r : curr_r )
|
||||
for ( const auto& r : curr_r )
|
||||
Expand(r);
|
||||
|
||||
return ! new_reachables.empty();
|
||||
|
@ -229,7 +229,7 @@ void UsageAnalyzer::Expand(const IDPtr& id) {
|
|||
TraversalCode UsageAnalyzer::PreID(const ID* raw_id) {
|
||||
IDPtr id{NewRef{}, const_cast<ID*>(raw_id)};
|
||||
|
||||
if ( analyzed_IDs.count(id) > 0 )
|
||||
if ( analyzed_IDs.contains(id) )
|
||||
// No need to repeat the analysis.
|
||||
return TC_ABORTSTMT;
|
||||
|
||||
|
|
|
@ -609,11 +609,11 @@ void UseDefs::FoldInUDs(UDs& main_UDs, const UDs& u1, const UDs& u2) {
|
|||
main_UDs->Replicate(old_main);
|
||||
|
||||
if ( u1 )
|
||||
for ( auto ud : u1->IterateOver() )
|
||||
for ( const auto& ud : u1->IterateOver() )
|
||||
main_UDs->Add(ud);
|
||||
|
||||
if ( u2 )
|
||||
for ( auto ud : u2->IterateOver() )
|
||||
for ( const auto& ud : u2->IterateOver() )
|
||||
main_UDs->Add(ud);
|
||||
}
|
||||
|
||||
|
@ -633,7 +633,7 @@ void UseDefs::UpdateUDs(const Stmt* s, const UDs& uds) {
|
|||
}
|
||||
|
||||
if ( uds ) {
|
||||
for ( auto u : uds->IterateOver() )
|
||||
for ( const auto& u : uds->IterateOver() )
|
||||
curr_uds->Add(u);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ public:
|
|||
|
||||
void Replicate(const UDs& from) { use_defs = from->use_defs; }
|
||||
|
||||
bool HasID(const IDPtr& id) { return use_defs.find(id) != use_defs.end(); }
|
||||
bool HasID(const IDPtr& id) const { return use_defs.contains(id); }
|
||||
|
||||
void Add(IDPtr id) { use_defs.insert(std::move(id)); }
|
||||
void Remove(const IDPtr& id) { use_defs.erase(id); }
|
||||
|
|
|
@ -510,7 +510,7 @@ void ZAMCompiler::ReMapFrame() {
|
|||
continue;
|
||||
|
||||
auto vars = inst_beginnings[inst];
|
||||
for ( auto v : vars ) {
|
||||
for ( const auto& v : vars ) {
|
||||
// Don't remap variables whose values aren't actually used.
|
||||
int slot = frame_layout1[v];
|
||||
if ( denizen_ending.contains(slot) )
|
||||
|
|
|
@ -77,7 +77,7 @@ void ZAMCompiler::InitArgs() {
|
|||
}
|
||||
|
||||
void ZAMCompiler::InitCaptures() {
|
||||
for ( auto c : pf->Captures() )
|
||||
for ( const auto& c : pf->Captures() )
|
||||
(void)AddToFrame(c);
|
||||
}
|
||||
|
||||
|
|
|
@ -528,7 +528,7 @@ const ZAMStmt ZAMCompiler::GenSwitch(const SwitchStmt* sw, int slot, InternalTyp
|
|||
// For type switches, we map them to consecutive numbers, and then use
|
||||
// a integer-valued switch on those.
|
||||
int tm_ctr = 0;
|
||||
for ( auto [_, index] : *sw->TypeMap() ) {
|
||||
for ( const auto& [_, index] : *sw->TypeMap() ) {
|
||||
auto case_body_start = case_start[index];
|
||||
new_int_cases[tm_ctr++] = case_body_start;
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ const ZAMStmt ZAMCompiler::LoadGlobal(const IDPtr& id) {
|
|||
|
||||
// We use the id_val for reporting used-but-not-set errors.
|
||||
z.aux = new ZInstAux(0);
|
||||
z.aux->id_val = std::move(id);
|
||||
z.aux->id_val = id;
|
||||
|
||||
return AddInst(z, true);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue