switched CPPCompile::Canonicalize() to take std::string instead of const char*

This commit is contained in:
Vern Paxson 2024-11-04 08:22:37 -08:00
parent 84d8e74884
commit 519fec2592
6 changed files with 11 additions and 13 deletions

View file

@ -10,7 +10,7 @@ void CPPCompile::DeclareFunc(const FuncInfo& func) {
if ( ! IsCompilable(func) ) if ( ! IsCompilable(func) )
return; return;
auto fname = Canonicalize(BodyName(func).c_str()) + "_zf"; auto fname = Canonicalize(BodyName(func)) + "_zf";
auto pf = func.Profile(); auto pf = func.Profile();
auto f = func.Func(); auto f = func.Func();
const auto& body = func.Body(); const auto& body = func.Body();
@ -25,7 +25,7 @@ void CPPCompile::DeclareFunc(const FuncInfo& func) {
void CPPCompile::DeclareLambda(const LambdaExpr* l, const ProfileFunc* pf) { void CPPCompile::DeclareLambda(const LambdaExpr* l, const ProfileFunc* pf) {
ASSERT(is_CPP_compilable(pf)); ASSERT(is_CPP_compilable(pf));
auto lname = Canonicalize(l->Name().c_str()) + "_lb"; auto lname = Canonicalize(l->Name()) + "_lb";
auto body = l->Ingredients()->Body(); auto body = l->Ingredients()->Body();
auto l_id = l->Ingredients()->GetID(); auto l_id = l->Ingredients()->GetID();
auto& ids = l->OuterIDs(); auto& ids = l->OuterIDs();

View file

@ -646,7 +646,7 @@ string CPPCompile::GenLambdaExpr(const Expr* e) {
string CPPCompile::GenLambdaExpr(const Expr* e, string capture_args) { string CPPCompile::GenLambdaExpr(const Expr* e, string capture_args) {
auto l = static_cast<const LambdaExpr*>(e); auto l = static_cast<const LambdaExpr*>(e);
auto name = Canonicalize(l->Name().c_str()) + "_lb_cl"; auto name = Canonicalize(l->Name()) + "_lb_cl";
auto cl_args = string("\"") + name + "\"" + std::move(capture_args); auto cl_args = string("\"") + name + "\"" + std::move(capture_args);
auto body = string("make_intrusive<") + name + ">(" + cl_args + ")"; auto body = string("make_intrusive<") + name + ">(" + cl_args + ")";
auto func = string("make_intrusive<CPPLambdaFunc>(\"") + l->Name() + "\", cast_intrusive<FuncType>(" + auto func = string("make_intrusive<CPPLambdaFunc>(\"") + l->Name() + "\", cast_intrusive<FuncType>(" +

View file

@ -10,7 +10,7 @@ void CPPCompile::CompileFunc(const FuncInfo& func) {
if ( ! IsCompilable(func) ) if ( ! IsCompilable(func) )
return; return;
auto fname = Canonicalize(BodyName(func).c_str()) + "_zf"; auto fname = Canonicalize(BodyName(func)) + "_zf";
auto pf = func.Profile(); auto pf = func.Profile();
auto f = func.Func(); auto f = func.Func();
const auto& body = func.Body(); const auto& body = func.Body();
@ -19,7 +19,7 @@ void CPPCompile::CompileFunc(const FuncInfo& func) {
} }
void CPPCompile::CompileLambda(const LambdaExpr* l, const ProfileFunc* pf) { void CPPCompile::CompileLambda(const LambdaExpr* l, const ProfileFunc* pf) {
auto lname = Canonicalize(l->Name().c_str()) + "_lb"; auto lname = Canonicalize(l->Name()) + "_lb";
auto body = l->Ingredients()->Body(); auto body = l->Ingredients()->Body();
auto l_id = l->Ingredients()->GetID(); auto l_id = l->Ingredients()->GetID();
auto& ids = l->OuterIDs(); auto& ids = l->OuterIDs();

View file

@ -259,7 +259,7 @@ void CPPCompile::GenStandaloneActivation() {
auto f = func.Func(); auto f = func.Func();
auto fname = BodyName(func); auto fname = BodyName(func);
auto bname = Canonicalize(fname.c_str()) + "_zf"; auto bname = Canonicalize(fname) + "_zf";
if ( compiled_funcs.count(bname) == 0 ) if ( compiled_funcs.count(bname) == 0 )
// We didn't wind up compiling it. // We didn't wind up compiling it.

View file

@ -129,7 +129,7 @@ static string trim_name(const ID* id) {
return ns; return ns;
} }
string CPPCompile::LocalName(const ID* l) const { return Canonicalize(trim_name(l).c_str()); } string CPPCompile::LocalName(const ID* l) const { return Canonicalize(trim_name(l)); }
string CPPCompile::CaptureName(const ID* c) const { string CPPCompile::CaptureName(const ID* c) const {
// We want to strip both the module and any inlining appendage. // We want to strip both the module and any inlining appendage.
@ -139,15 +139,13 @@ string CPPCompile::CaptureName(const ID* c) const {
if ( appendage != string::npos ) if ( appendage != string::npos )
tn.erase(tn.begin() + appendage, tn.end()); tn.erase(tn.begin() + appendage, tn.end());
return Canonicalize(tn.c_str()); return Canonicalize(tn);
} }
string CPPCompile::Canonicalize(const char* name) const { string CPPCompile::Canonicalize(const std::string& name) const {
string cname; string cname;
for ( int i = 0; name[i]; ++i ) { for ( auto c : name ) {
auto c = name[i];
// Strip <>'s - these get introduced for lambdas. // Strip <>'s - these get introduced for lambdas.
if ( c == '<' || c == '>' ) if ( c == '<' || c == '>' )
continue; continue;

View file

@ -47,7 +47,7 @@ std::string CaptureName(const IDPtr& l) const { return CaptureName(l.get()); }
// Returns a canonicalized name, with various non-alphanumeric characters // Returns a canonicalized name, with various non-alphanumeric characters
// stripped or transformed, and guaranteed not to conflict with C++ keywords. // stripped or transformed, and guaranteed not to conflict with C++ keywords.
std::string Canonicalize(const char* name) const; std::string Canonicalize(const std::string& name) const;
// Returns the name of the global corresponding to an expression (which must // Returns the name of the global corresponding to an expression (which must
// be a EXPR_NAME). // be a EXPR_NAME).