From 71e9c8d436e10831f0e235ee5e36827c5316998c Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Fri, 27 Sep 2024 12:52:32 +0200 Subject: [PATCH] script_opt: Use Func::GetName() --- src/script_opt/CPP/DeclFunc.cc | 2 +- src/script_opt/CPP/Driver.cc | 8 ++++---- src/script_opt/CPP/GenFunc.cc | 2 +- src/script_opt/CPP/Inits.cc | 8 ++++---- src/script_opt/CPP/InitsInfo.cc | 2 +- src/script_opt/Inline.cc | 17 +++++++++-------- src/script_opt/ProfileFunc.cc | 8 ++++---- src/script_opt/ScriptOpt.cc | 14 +++++++------- src/script_opt/ScriptOpt.h | 2 +- src/script_opt/UsageAnalyzer.cc | 2 +- src/script_opt/ZAM/AM-Opt.cc | 4 ++-- src/script_opt/ZAM/BuiltIn.cc | 4 ++-- src/script_opt/ZAM/Driver.cc | 14 +++++++------- src/script_opt/ZAM/OPs/rel-exprs.op | 4 ++-- src/script_opt/ZAM/Stmt.cc | 2 +- src/script_opt/ZAM/ZInst.cc | 4 ++-- 16 files changed, 49 insertions(+), 48 deletions(-) diff --git a/src/script_opt/CPP/DeclFunc.cc b/src/script_opt/CPP/DeclFunc.cc index f76c8acf46..7e0845bc08 100644 --- a/src/script_opt/CPP/DeclFunc.cc +++ b/src/script_opt/CPP/DeclFunc.cc @@ -19,7 +19,7 @@ void CPPCompile::DeclareFunc(const FuncInfo& func) { CreateFunction(f->GetType(), pf, fname, body, priority, nullptr, f->Flavor()); if ( f->GetBodies().size() == 1 ) - compiled_simple_funcs[f->Name()] = fname; + compiled_simple_funcs[f->GetName()] = fname; } void CPPCompile::DeclareLambda(const LambdaExpr* l, const ProfileFunc* pf) { diff --git a/src/script_opt/CPP/Driver.cc b/src/script_opt/CPP/Driver.cc index 95061a1f7c..d9ac00203a 100644 --- a/src/script_opt/CPP/Driver.cc +++ b/src/script_opt/CPP/Driver.cc @@ -47,7 +47,7 @@ void CPPCompile::Compile(bool report_uncompilable) { if ( ! allow_cond && ! func.ShouldSkip() && ! ofiles.empty() && files_with_conditionals.count(fn) > 0 ) { if ( report_uncompilable ) reporter->Warning("%s cannot be compiled to C++ due to source file %s having conditional code", - f->Name(), fn.c_str()); + f->GetName().c_str(), fn.c_str()); else if ( filenames_reported_as_skipped.count(fn) == 0 ) { reporter->Warning("skipping compilation of files in %s due to presence of conditional code", @@ -60,7 +60,7 @@ void CPPCompile::Compile(bool report_uncompilable) { } if ( func.ShouldSkip() ) { - not_fully_compilable.insert(f->Name()); + not_fully_compilable.insert(f->GetName()); continue; } @@ -79,10 +79,10 @@ void CPPCompile::Compile(bool report_uncompilable) { else { if ( reason && report_uncompilable ) { had_to_skip = true; - reporter->Warning("%s cannot be compiled to C++ due to %s", f->Name(), reason); + reporter->Warning("%s cannot be compiled to C++ due to %s", f->GetName().c_str(), reason); } - not_fully_compilable.insert(f->Name()); + not_fully_compilable.insert(f->GetName()); } } diff --git a/src/script_opt/CPP/GenFunc.cc b/src/script_opt/CPP/GenFunc.cc index fc3dad0c48..7a36421766 100644 --- a/src/script_opt/CPP/GenFunc.cc +++ b/src/script_opt/CPP/GenFunc.cc @@ -177,7 +177,7 @@ void CPPCompile::DeclareLocals(const ProfileFunc* pf, const IDPList* lambda_ids) string CPPCompile::BodyName(const FuncInfo& func) { const auto& f = func.Func(); const auto& body = func.Body(); - string fname = f->Name(); + auto fname = f->GetName(); // Extend name with location information. auto loc = body->GetLocationInfo(); diff --git a/src/script_opt/CPP/Inits.cc b/src/script_opt/CPP/Inits.cc index ba30011745..e14bb21931 100644 --- a/src/script_opt/CPP/Inits.cc +++ b/src/script_opt/CPP/Inits.cc @@ -282,15 +282,15 @@ void CPPCompile::GenStandaloneActivation() { hashes = "{" + hashes + "}"; auto f = fb.first; - auto fn = f->Name(); + const auto& fn = f->GetName(); const auto& ft = f->GetType(); - auto var = extract_var_name(fn); - auto mod = extract_module_name(fn); + auto var = extract_var_name(fn.c_str()); + auto mod = extract_module_name(fn.c_str()); auto fid = lookup_ID(var.c_str(), mod.c_str(), false, true, false); if ( ! fid ) - reporter->InternalError("can't find identifier %s", fn); + reporter->InternalError("can't find identifier %s", fn.c_str()); auto exported = fid->IsExport() ? "true" : "false"; diff --git a/src/script_opt/CPP/InitsInfo.cc b/src/script_opt/CPP/InitsInfo.cc index 848c38e15b..8cd2039494 100644 --- a/src/script_opt/CPP/InitsInfo.cc +++ b/src/script_opt/CPP/InitsInfo.cc @@ -283,7 +283,7 @@ FuncConstInfo::FuncConstInfo(CPPCompile* _c, ValPtr v) : CompoundItemInfo(_c, v) void FuncConstInfo::InitializerVals(std::vector& ivs) const { auto f = fv->AsFunc(); - const auto& fn = f->Name(); + const auto& fn = f->GetName(); const auto& bodies = f->GetBodies(); ivs.emplace_back(Fmt(type)); diff --git a/src/script_opt/Inline.cc b/src/script_opt/Inline.cc index fb5c3fb61d..ad727dd908 100644 --- a/src/script_opt/Inline.cc +++ b/src/script_opt/Inline.cc @@ -32,12 +32,12 @@ void Inliner::Analyze() { // // We deal with cases where these defaults are overridden to refer // to some other function below, when we go through indirect functions. - if ( is_special_script_func(f.Func()->Name()) ) + if ( is_special_script_func(f.Func()->GetName()) ) continue; // If ZAM can replace the script, don't inline it, so its usage // remains visible during the AST reduction process. - if ( is_ZAM_replaceable_script_func(f.Func()->Name()) ) + if ( is_ZAM_replaceable_script_func(f.Func()->GetName()) ) continue; std::unordered_set cs; @@ -50,7 +50,7 @@ void Inliner::Analyze() { if ( func == f.Func() ) { if ( report_recursive ) - printf("%s is directly recursive\n", func->Name()); + printf("%s is directly recursive\n", func->GetName().c_str()); non_recursive_funcs.erase(func); } @@ -79,7 +79,7 @@ void Inliner::Analyze() { // for cutting down noise from the following recursion report. if ( report_recursive ) - printf("%s is used indirectly, and thus potentially recursively\n", sf->Name()); + printf("%s is used indirectly, and thus potentially recursively\n", sf->GetName().c_str()); non_recursive_funcs.erase(sf); } @@ -127,7 +127,8 @@ void Inliner::Analyze() { continue; if ( report_recursive ) - printf("%s is indirectly recursive, called by %s\n", c.first->Name(), cc->Name()); + printf("%s is indirectly recursive, called by %s\n", c.first->GetName().c_str(), + cc->GetName().c_str()); non_recursive_funcs.erase(c.first); non_recursive_funcs.erase(cc); @@ -193,7 +194,7 @@ void Inliner::CoalesceEventHandlers() { // it takes more time to compile it than to just run it via the // interpreter, it's a lose. static std::string zeek_init_name = "zeek_init"; - if ( func->Name() == zeek_init_name ) + if ( func->GetName() == zeek_init_name ) continue; const auto& body = f.Body(); @@ -286,12 +287,12 @@ void Inliner::CoalesceEventHandlers(ScriptFuncPtr func, const std::vectorSetScope(new_scope); // Replace the function for that EventHandler with the delegating one. - auto* eh = event_registry->Lookup(func->Name()); + auto* eh = event_registry->Lookup(func->GetName()); ASSERT(eh); eh->SetFunc(inlined_func); // Likewise, replace the value of the identifier. - auto fid = lookup_ID(func->Name(), GLOBAL_MODULE_NAME, false, false, false); + auto fid = lookup_ID(func->GetName().c_str(), GLOBAL_MODULE_NAME, false, false, false); ASSERT(fid); fid->SetVal(make_intrusive(inlined_func)); diff --git a/src/script_opt/ProfileFunc.cc b/src/script_opt/ProfileFunc.cc index 5d1f07ae09..96b1fa8961 100644 --- a/src/script_opt/ProfileFunc.cc +++ b/src/script_opt/ProfileFunc.cc @@ -656,7 +656,7 @@ bool ProfileFuncs::GetCallSideEffects(const NameExpr* n, IDSet& non_local_ids, T auto func = fv->AsFunc(); if ( func->GetKind() == Func::BUILTIN_FUNC ) { - if ( has_script_side_effects(func->Name()) ) + if ( has_script_side_effects(func->GetName()) ) is_unknown = true; return true; } @@ -1392,8 +1392,8 @@ bool ProfileFuncs::AssessSideEffects(const SideEffectsOp* se, SideEffectsOp::Acc } std::shared_ptr ProfileFuncs::GetCallSideEffects(const ScriptFunc* sf) { - if ( lambda_primaries.count(sf->Name()) > 0 ) - sf = lambda_primaries[sf->Name()]; + if ( lambda_primaries.count(sf->GetName()) > 0 ) + sf = lambda_primaries[sf->GetName()]; auto sf_se = func_side_effects.find(sf); if ( sf_se != func_side_effects.end() ) @@ -1502,7 +1502,7 @@ ASTBlockAnalyzer::ASTBlockAnalyzer(std::vector& funcs) { continue; auto func = f.Func(); - std::string fn = func->Name(); + auto fn = func->GetName(); auto body = f.Body(); // First get the line numbers all sorted out. diff --git a/src/script_opt/ScriptOpt.cc b/src/script_opt/ScriptOpt.cc index 56ebaf8f11..d6b2af16f9 100644 --- a/src/script_opt/ScriptOpt.cc +++ b/src/script_opt/ScriptOpt.cc @@ -110,7 +110,7 @@ bool should_analyze(const ScriptFuncPtr& f, const StmtPtr& body) { if ( ofiles.empty() && ofuncs.empty() ) return true; - auto fun = f->Name(); + const auto& fun = f->GetName(); for ( auto& o : ofuncs ) if ( std::regex_match(fun, o) ) @@ -165,7 +165,7 @@ static void optimize_func(ScriptFuncPtr f, std::shared_ptr pf, std: const char* reason; if ( ! is_ZAM_compilable(pf.get(), &reason) ) { if ( analysis_options.report_uncompilable ) - printf("Skipping compilation of %s due to %s\n", f->Name(), reason); + printf("Skipping compilation of %s due to %s\n", f->GetName().c_str(), reason); return; } @@ -184,10 +184,10 @@ static void optimize_func(ScriptFuncPtr f, std::shared_ptr pf, std: if ( ! new_body->IsReduced(rc.get()) ) { if ( non_reduced_perp ) - reporter->InternalError("Reduction inconsistency for %s: %s\n", f->Name(), + reporter->InternalError("Reduction inconsistency for %s: %s\n", f->GetName().c_str(), obj_desc(non_reduced_perp).c_str()); else - reporter->InternalError("Reduction inconsistency for %s\n", f->Name()); + reporter->InternalError("Reduction inconsistency for %s\n", f->GetName().c_str()); } checking_reduction = false; @@ -365,11 +365,11 @@ static void report_CPP() { std::unordered_set already_reported; for ( auto& f : funcs ) { - auto name = f.Func()->Name(); + const auto& name = f.Func()->GetName(); auto hash = f.Profile()->HashVal(); bool have = compiled_scripts.count(hash) > 0; - printf("script function %s (hash %llu): %s\n", name, hash, have ? "yes" : "no"); + printf("script function %s (hash %llu): %s\n", name.c_str(), hash, have ? "yes" : "no"); if ( have ) already_reported.insert(hash); @@ -409,7 +409,7 @@ static void use_CPP() { // we're using code compiled for standalone. if ( f.Body()->Tag() != STMT_CPP ) { auto func = f.Func(); - if ( added_bodies[func->Name()].count(hash) > 0 ) + if ( added_bodies[func->GetName()].count(hash) > 0 ) // We've already added the // replacement. Delete orig. func->ReplaceBody(f.Body(), nullptr); diff --git a/src/script_opt/ScriptOpt.h b/src/script_opt/ScriptOpt.h index 3ca64036e5..6967333e5c 100644 --- a/src/script_opt/ScriptOpt.h +++ b/src/script_opt/ScriptOpt.h @@ -187,7 +187,7 @@ protected: class CoalescedScriptFunc : public ScriptFunc { public: CoalescedScriptFunc(StmtPtr merged_body, ScopePtr scope, ScriptFuncPtr orig_func) - : ScriptFunc(orig_func->Name(), orig_func->GetType(), {std::move(merged_body)}, {0}), orig_func(orig_func) { + : ScriptFunc(orig_func->GetName(), orig_func->GetType(), {std::move(merged_body)}, {0}), orig_func(orig_func) { SetScope(std::move(scope)); }; diff --git a/src/script_opt/UsageAnalyzer.cc b/src/script_opt/UsageAnalyzer.cc index 4387086249..34360751e2 100644 --- a/src/script_opt/UsageAnalyzer.cc +++ b/src/script_opt/UsageAnalyzer.cc @@ -150,7 +150,7 @@ void UsageAnalyzer::FindSeeds(IDSet& seeds) const { auto f = GetFuncIfAny(id); if ( f && id->GetType()->Flavor() == FUNC_FLAVOR_EVENT ) { - if ( script_events.count(f->Name()) == 0 ) + if ( script_events.count(f->GetName()) == 0 ) seeds.insert(id.get()); continue; diff --git a/src/script_opt/ZAM/AM-Opt.cc b/src/script_opt/ZAM/AM-Opt.cc index f242affccc..47bbafd2cb 100644 --- a/src/script_opt/ZAM/AM-Opt.cc +++ b/src/script_opt/ZAM/AM-Opt.cc @@ -81,7 +81,7 @@ void ZAMCompiler::OptimizeInsts() { KillInst(i); if ( analysis_options.dump_ZAM ) { - printf("Original ZAM code for %s:\n", func->Name()); + printf("Original ZAM code for %s:\n", func->GetName().c_str()); DumpInsts1(nullptr); } @@ -915,7 +915,7 @@ zeek_uint_t ZAMCompiler::FirstLiveInst(zeek_uint_t i, bool follow_gotos) { if ( i0->live ) { if ( follow_gotos && i0->IsUnconditionalBranch() ) { if ( ++num_inspected > insts1.size() ) { - reporter->Error("%s contains an infinite loop", func->Name()); + reporter->Error("%s contains an infinite loop", func->GetName().c_str()); return i; } diff --git a/src/script_opt/ZAM/BuiltIn.cc b/src/script_opt/ZAM/BuiltIn.cc index bdc61b62d8..295ca19076 100644 --- a/src/script_opt/ZAM/BuiltIn.cc +++ b/src/script_opt/ZAM/BuiltIn.cc @@ -573,7 +573,7 @@ bool IsZAM_BuiltIn(ZAMCompiler* zam, const Expr* e) { if ( ! func ) return false; - std::string fn = func->Name(); + auto fn = func->GetName(); // It's useful to intercept any lingering calls to the script-level // Log::write as well as the Log::__write BiF. When inlining there can @@ -619,7 +619,7 @@ bool IsZAM_BuiltInCond(ZAMCompiler* zam, const CallExpr* c, int& branch_v) { if ( ! func ) return false; - auto b = builtins.find(func->Name()); + auto b = builtins.find(func->GetName()); if ( b == builtins.end() ) return false; diff --git a/src/script_opt/ZAM/Driver.cc b/src/script_opt/ZAM/Driver.cc index 2c43932755..2bdae1406b 100644 --- a/src/script_opt/ZAM/Driver.cc +++ b/src/script_opt/ZAM/Driver.cc @@ -28,7 +28,7 @@ ZAMCompiler::ZAMCompiler(ScriptFuncPtr f, std::shared_ptr _pfs, st ASSERT(loc->first_line != 0 || body->Tag() == STMT_NULL); auto loc_copy = std::make_shared(loc->filename, loc->first_line, loc->last_line, loc->first_column, loc->last_column); - ZAM::curr_func = func->Name(); + ZAM::curr_func = func->GetName(); ZAM::curr_loc = std::make_shared(ZAM::curr_func, std::move(loc_copy), nullptr); Init(); @@ -196,7 +196,7 @@ StmtPtr ZAMCompiler::CompileBody() { ConcretizeSwitches(); - std::string fname = func->Name(); + auto fname = func->GetName(); if ( func->Flavor() == FUNC_FLAVOR_FUNCTION ) fname = func_name_at_loc(fname, body->GetLocationInfo()); @@ -357,13 +357,13 @@ void ZAMCompiler::Dump() { bool remapped_frame = ! analysis_options.no_ZAM_opt; if ( remapped_frame ) - printf("Original frame for %s:\n", func->Name()); + printf("Original frame for %s:\n", func->GetName().c_str()); for ( const auto& elem : frame_layout1 ) printf("frame[%d] = %s\n", elem.second, elem.first->Name()); if ( remapped_frame ) { - printf("Final frame for %s:\n", func->Name()); + printf("Final frame for %s:\n", func->GetName().c_str()); for ( auto i = 0U; i < shared_frame_denizens.size(); ++i ) { printf("frame2[%d] =", i); @@ -374,14 +374,14 @@ void ZAMCompiler::Dump() { } if ( ! insts2.empty() ) - printf("Pre-removal of dead code for %s:\n", func->Name()); + printf("Pre-removal of dead code for %s:\n", func->GetName().c_str()); auto remappings = remapped_frame ? &shared_frame_denizens : nullptr; DumpInsts1(remappings); if ( ! insts2.empty() ) - printf("Final intermediary code for %s:\n", func->Name()); + printf("Final intermediary code for %s:\n", func->GetName().c_str()); remappings = remapped_frame ? &shared_frame_denizens_final : nullptr; @@ -403,7 +403,7 @@ void ZAMCompiler::Dump() { } if ( ! insts2.empty() ) - printf("Final code for %s:\n", func->Name()); + printf("Final code for %s:\n", func->GetName().c_str()); for ( auto i = 0U; i < insts2.size(); ++i ) { auto& inst = insts2[i]; diff --git a/src/script_opt/ZAM/OPs/rel-exprs.op b/src/script_opt/ZAM/OPs/rel-exprs.op index d8fdd4d94b..fd74886fb9 100644 --- a/src/script_opt/ZAM/OPs/rel-exprs.op +++ b/src/script_opt/ZAM/OPs/rel-exprs.op @@ -24,7 +24,7 @@ eval-type S Bstr_cmp($1->AsString(), $2->AsString()) == 0 eval-type T $1->EqualTo(*$2) eval-type A $1->AsAddr() == $2->AsAddr() eval-type N $1->AsSubNet() == $2->AsSubNet() -eval-type F util::streq($1->Name(), $2->Name()) +eval-type F $1->GetName() == $2->GetName() eval-mixed P S $1->MatchExactly($2->AsString()) rel-expr-op NE @@ -35,7 +35,7 @@ eval-type S Bstr_cmp($1->AsString(), $2->AsString()) != 0 eval-type T ! $1->EqualTo(*$2) eval-type A $1->AsAddr() != $2->AsAddr() eval-type N $1->AsSubNet() != $2->AsSubNet() -eval-type F ! util::streq($1->Name(), $2->Name()) +eval-type F $1->GetName() != $2->GetName() eval-mixed P S ! $1->MatchExactly($2->AsString()) # Note, canonicalization means that GE and GT shouldn't occur diff --git a/src/script_opt/ZAM/Stmt.cc b/src/script_opt/ZAM/Stmt.cc index d353827b68..d36402ef6c 100644 --- a/src/script_opt/ZAM/Stmt.cc +++ b/src/script_opt/ZAM/Stmt.cc @@ -932,7 +932,7 @@ const ZAMStmt ZAMCompiler::CompileCatchReturn(const CatchReturnStmt* cr) { auto hold_func = ZAM::curr_func; auto hold_loc = ZAM::curr_loc; - ZAM::curr_func = cr->Func()->Name(); + ZAM::curr_func = cr->Func()->GetName(); bool is_event_inline = (hold_func == ZAM::curr_func); diff --git a/src/script_opt/ZAM/ZInst.cc b/src/script_opt/ZAM/ZInst.cc index 1f0539a50b..3911f557dc 100644 --- a/src/script_opt/ZAM/ZInst.cc +++ b/src/script_opt/ZAM/ZInst.cc @@ -80,12 +80,12 @@ void ZInst::Dump(FILE* f, const string& prefix, const string& id1, const string& auto func = aux ? aux->func : nullptr; if ( func ) - fprintf(f, " (func %s)", func->Name()); + fprintf(f, " (func %s)", func->GetName().c_str()); if ( loc ) { auto l = loc->Describe(true); if ( func && (func->GetBodies().empty() || func->GetBodies()[0].stmts->Tag() != STMT_ZAM) ) - l = l + ";" + func->Name(); + l = l + ";" + func->GetName(); if ( ! prefix.empty() ) l = prefix + l; fprintf(f, " // %s", l.c_str());