From 84304965579d3c8db0f8b43836ff8f5fe8b5ae32 Mon Sep 17 00:00:00 2001 From: DanielSvoboda Date: Wed, 28 Jan 2026 15:34:37 -0300 Subject: [PATCH] Handle dots in function names during sanitization Replace dots with underscores in function names --- ps2xRecomp/src/code_generator.cpp | 19 ++++++++++++------- ps2xRecomp/src/ps2_recompiler.cpp | 21 ++++++++++++++------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/ps2xRecomp/src/code_generator.cpp b/ps2xRecomp/src/code_generator.cpp index d605f96..95f0d94 100644 --- a/ps2xRecomp/src/code_generator.cpp +++ b/ps2xRecomp/src/code_generator.cpp @@ -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) diff --git a/ps2xRecomp/src/ps2_recompiler.cpp b/ps2xRecomp/src/ps2_recompiler.cpp index a86a5c0..6c8b354 100644 --- a/ps2xRecomp/src/ps2_recompiler.cpp +++ b/ps2xRecomp/src/ps2_recompiler.cpp @@ -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(name[1])))) + if (sanitized.size() >= 2 && + sanitized[0] == '_' && + (sanitized[1] == '_' || + std::isupper(static_cast(sanitized[1])))) { - return "ps2_" + name; + return "ps2_" + sanitized; } - return name; + + return sanitized; } }