Merge pull request #25 from DanielSvoboda/main

Handle dots in function names during sanitization
This commit is contained in:
Ranieri
2026-01-28 16:09:14 -03:00
committed by GitHub
2 changed files with 26 additions and 14 deletions
+12 -7
View File
@@ -73,18 +73,23 @@ namespace ps2recomp
return kKeywords.find(name) != kKeywords.end();
}
static std::string sanitizeFunctionName(const std::string &name)
static std::string sanitizeFunctionName(const std::string& name)
{
std::string sanitized = name;
std::replace(sanitized.begin(), sanitized.end(), '.', '_');
// ugly but will do for now
if (name == "main")
if (sanitized == "main")
return "ps2_main";
if (isReservedCxxKeyword(name))
return "ps2_" + name;
if (isReservedCxxKeyword(sanitized))
return "ps2_" + sanitized;
if (!isReservedCxxIdentifier(name))
return name;
return "ps2_" + name;
if (!isReservedCxxIdentifier(sanitized))
return sanitized;
return "ps2_" + sanitized;
}
std::string CodeGenerator::getGeneratedFunctionName(const Function &function)
+14 -7
View File
@@ -714,22 +714,29 @@ namespace ps2recomp
return outputPath;
}
std::string PS2Recompiler::sanitizeFunctionName(const std::string &name) const
std::string PS2Recompiler::sanitizeFunctionName(const std::string& name) const
{
if (name == "main")
std::string sanitized = name;
std::replace(sanitized.begin(), sanitized.end(), '.', '_');
if (sanitized == "main")
{
return "ps2_main";
}
if (ps2recomp::kKeywords.find(name) != ps2recomp::kKeywords.end())
if (ps2recomp::kKeywords.find(sanitized) != ps2recomp::kKeywords.end())
{
return "ps2_" + name;
return "ps2_" + sanitized;
}
if (name.size() >= 2 && name[0] == '_' && (name[1] == '_' || std::isupper(static_cast<unsigned char>(name[1]))))
if (sanitized.size() >= 2 &&
sanitized[0] == '_' &&
(sanitized[1] == '_' ||
std::isupper(static_cast<unsigned char>(sanitized[1]))))
{
return "ps2_" + name;
return "ps2_" + sanitized;
}
return name;
return sanitized;
}
}