mirror of
https://github.com/ran-j/PS2Recomp.git
synced 2026-09-26 08:51:05 -04:00
Handle dots in function names during sanitization
Replace dots with underscores in function names
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user