From 58d080a27c38222bf077f9e51c84ab8b8da0193e Mon Sep 17 00:00:00 2001 From: Aaron Jomy Date: Fri, 2 Jan 2026 23:27:45 +0100 Subject: [PATCH] fix common namespaces for public API and internals --- lib/CppInterOp/CXCppInterOp.cpp | 2 +- lib/CppInterOp/Compatibility.h | 10 +++---- lib/CppInterOp/CppInterOp.cpp | 10 +++---- lib/CppInterOp/CppInterOpInterpreter.h | 14 +++++----- lib/CppInterOp/DynamicLibraryManager.cpp | 13 +++++---- lib/CppInterOp/DynamicLibraryManager.h | 4 +-- .../DynamicLibraryManagerSymbol.cpp | 27 ++++++++++--------- lib/CppInterOp/Paths.cpp | 6 ++--- lib/CppInterOp/Paths.h | 11 ++++---- 9 files changed, 48 insertions(+), 49 deletions(-) diff --git a/lib/CppInterOp/CXCppInterOp.cpp b/lib/CppInterOp/CXCppInterOp.cpp index 00ecdf439..7f35f431b 100644 --- a/lib/CppInterOp/CXCppInterOp.cpp +++ b/lib/CppInterOp/CXCppInterOp.cpp @@ -543,7 +543,7 @@ bool clang_existsFunctionTemplate(const char* name, CXScope parent) { const auto* Within = llvm::dyn_cast(getDecl(parent)); auto& S = getInterpreter(parent)->getSema(); - auto* ND = Cpp::Cpp_utils::Lookup::Named(&S, name, Within); + auto* ND = CppInternal::utils::Lookup::Named(&S, name, Within); if (!ND) return false; diff --git a/lib/CppInterOp/Compatibility.h b/lib/CppInterOp/Compatibility.h index 0c029910e..c629b15e6 100644 --- a/lib/CppInterOp/Compatibility.h +++ b/lib/CppInterOp/Compatibility.h @@ -92,8 +92,8 @@ static inline char* GetEnv(const char* Var_Name) { #include #include -namespace Cpp { -namespace Cpp_utils = cling::utils; +namespace CppInternal { +namespace utils = cling::utils; } namespace compat { @@ -434,12 +434,8 @@ inline void codeComplete(std::vector& Results, #include "CppInterOpInterpreter.h" -namespace Cpp { -namespace Cpp_utils = Cpp::utils; -} - namespace compat { -using Interpreter = Cpp::Interpreter; +using Interpreter = CppInternal::Interpreter; class SynthesizingCodeRAII { private: diff --git a/lib/CppInterOp/CppInterOp.cpp b/lib/CppInterOp/CppInterOp.cpp index e88aae744..7fd8d4cb0 100755 --- a/lib/CppInterOp/CppInterOp.cpp +++ b/lib/CppInterOp/CppInterOp.cpp @@ -769,7 +769,7 @@ TCppScope_t GetNamed(const std::string& name, Within = llvm::dyn_cast(D); } - auto* ND = Cpp_utils::Lookup::Named(&getSema(), name, Within); + auto* ND = CppInternal::utils::Lookup::Named(&getSema(), name, Within); if (ND && ND != (clang::NamedDecl*)-1) { return (TCppScope_t)(ND->getCanonicalDecl()); } @@ -1025,7 +1025,7 @@ std::vector GetFunctionsUsingName(TCppScope_t scope, clang::LookupResult R(S, DName, SourceLocation(), Sema::LookupOrdinaryName, For_Visible_Redeclaration); - Cpp_utils::Lookup::Named(&S, R, Decl::castToDeclContext(D)); + CppInternal::utils::Lookup::Named(&S, R, Decl::castToDeclContext(D)); if (R.empty()) return funcs; @@ -1169,7 +1169,7 @@ bool ExistsFunctionTemplate(const std::string& name, TCppScope_t parent) { Within = llvm::dyn_cast(D); } - auto* ND = Cpp_utils::Lookup::Named(&getSema(), name, Within); + auto* ND = CppInternal::utils::Lookup::Named(&getSema(), name, Within); if ((intptr_t)ND == (intptr_t)0) return false; @@ -1214,7 +1214,7 @@ bool GetClassTemplatedMethods(const std::string& name, TCppScope_t parent, clang::LookupResult R(S, DName, SourceLocation(), Sema::LookupOrdinaryName, For_Visible_Redeclaration); auto* DC = clang::Decl::castToDeclContext(D); - Cpp_utils::Lookup::Named(&S, R, DC); + CppInternal::utils::Lookup::Named(&S, R, DC); if (R.getResultKind() == clang::LookupResult::NotFound && funcs.empty()) return false; @@ -1508,7 +1508,7 @@ TCppScope_t LookupDatamember(const std::string& name, TCppScope_t parent) { Within = llvm::dyn_cast(D); } - auto* ND = Cpp_utils::Lookup::Named(&getSema(), name, Within); + auto* ND = CppInternal::utils::Lookup::Named(&getSema(), name, Within); if (ND && ND != (clang::NamedDecl*)-1) { if (llvm::isa_and_nonnull(ND)) { return (TCppScope_t)ND; diff --git a/lib/CppInterOp/CppInterOpInterpreter.h b/lib/CppInterOp/CppInterOpInterpreter.h index 981c9420b..83f17df7d 100644 --- a/lib/CppInterOp/CppInterOpInterpreter.h +++ b/lib/CppInterOp/CppInterOpInterpreter.h @@ -67,7 +67,7 @@ template static D* LookupResult2Decl(clang::LookupResult& R) { } } // namespace -namespace Cpp { +namespace CppInternal { namespace utils { namespace Lookup { @@ -141,9 +141,9 @@ inline clang::NamedDecl* Named(clang::Sema* S, const char* Name, } // namespace Lookup } // namespace utils -} // namespace Cpp +} // namespace CppInternal -namespace Cpp { +namespace CppInternal { /// CppInterOp Interpreter /// @@ -494,7 +494,7 @@ class Interpreter { // Save the current number of entries size_t Idx = HOpts.UserEntries.size(); - Cpp::utils::AddIncludePaths(PathsStr, HOpts, Delim); + CppInternal::utils::AddIncludePaths(PathsStr, HOpts, Delim); clang::Preprocessor& PP = CI->getPreprocessor(); clang::SourceManager& SM = PP.getSourceManager(); @@ -532,8 +532,8 @@ class Interpreter { /// void GetIncludePaths(llvm::SmallVectorImpl& incpaths, bool withSystem, bool withFlags) const { - utils::CopyIncludePaths(getCI()->getHeaderSearchOpts(), incpaths, - withSystem, withFlags); + CppInternal::utils::CopyIncludePaths(getCI()->getHeaderSearchOpts(), + incpaths, withSystem, withFlags); } CompilationResult loadLibrary(const std::string& filename, bool lookup) { @@ -587,6 +587,6 @@ class Interpreter { } }; // Interpreter -} // namespace Cpp +} // namespace CppInternal #endif // CPPINTEROP_INTERPRETER_H diff --git a/lib/CppInterOp/DynamicLibraryManager.cpp b/lib/CppInterOp/DynamicLibraryManager.cpp index df579aa2c..a1ddd57ab 100644 --- a/lib/CppInterOp/DynamicLibraryManager.cpp +++ b/lib/CppInterOp/DynamicLibraryManager.cpp @@ -27,10 +27,9 @@ #include #include -namespace Cpp { +namespace CppInternal { -using namespace Cpp::utils::platform; -using namespace Cpp::utils; +using namespace utils; using namespace llvm; DynamicLibraryManager::DynamicLibraryManager() { @@ -55,8 +54,8 @@ DynamicLibraryManager::DynamicLibraryManager() { for (const char* Var : kSysLibraryEnv) { if (const char* Env = GetEnv(Var)) { SmallVector CurPaths; - SplitPaths(Env, CurPaths, utils::kPruneNonExistent, - Cpp::utils::platform::kEnvDelim); + SplitPaths(Env, CurPaths, SplitMode::kPruneNonExistent, + platform::kEnvDelim); for (const auto& Path : CurPaths) addSearchPath(Path); } @@ -66,7 +65,7 @@ DynamicLibraryManager::DynamicLibraryManager() { addSearchPath("."); SmallVector SysPaths; - Cpp::utils::platform::GetSystemLibraryPaths(SysPaths); + platform::GetSystemLibraryPaths(SysPaths); for (const std::string& P : SysPaths) addSearchPath(P, /*IsUser*/ false); @@ -506,4 +505,4 @@ bool DynamicLibraryManager::isSharedLibrary(StringRef libFullPath, return result; } -} // end namespace Cpp +} // end namespace CppInternal diff --git a/lib/CppInterOp/DynamicLibraryManager.h b/lib/CppInterOp/DynamicLibraryManager.h index e4adfa0f1..167bd0c7c 100644 --- a/lib/CppInterOp/DynamicLibraryManager.h +++ b/lib/CppInterOp/DynamicLibraryManager.h @@ -17,7 +17,7 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/Path.h" -namespace Cpp { +namespace CppInternal { class Dyld; class InterpreterCallbacks; @@ -219,6 +219,6 @@ class DynamicLibraryManager { static bool isSharedLibrary(llvm::StringRef libFullPath, bool* exists = nullptr); }; -} // end namespace Cpp +} // end namespace CppInternal #endif // CPPINTEROP_DYNAMIC_LIBRARY_MANAGER_H diff --git a/lib/CppInterOp/DynamicLibraryManagerSymbol.cpp b/lib/CppInterOp/DynamicLibraryManagerSymbol.cpp index 09d65be89..37ee36c2b 100644 --- a/lib/CppInterOp/DynamicLibraryManagerSymbol.cpp +++ b/lib/CppInterOp/DynamicLibraryManagerSymbol.cpp @@ -458,6 +458,8 @@ static bool MayExistInElfObjectFile(llvm::object::ObjectFile* soFile, } // namespace +namespace CppInternal { + // This function isn't referenced outside its translation unit, but it // can't use the "static" keyword because its address is used for // GetMainExecutable (since some platforms don't support taking the @@ -466,10 +468,9 @@ static bool MayExistInElfObjectFile(llvm::object::ObjectFile* soFile, std::string GetExecutablePath() { // This just needs to be some symbol in the binary; C++ doesn't // allow taking the address of ::main however. - return Cpp::DynamicLibraryManager::getSymbolLocation(&GetExecutablePath); + return DynamicLibraryManager::getSymbolLocation(&GetExecutablePath); } -namespace Cpp { class Dyld { struct BasePathHashFunction { size_t operator()(const BasePath& item) const { @@ -508,7 +509,7 @@ class Dyld { bool m_UseBloomFilter = true; bool m_UseHashTable = true; - const Cpp::DynamicLibraryManager& m_DynamicLibraryManager; + const DynamicLibraryManager& m_DynamicLibraryManager; /// The basename of `/home/.../lib/libA.so`, /// m_BasePaths will contain `/home/.../lib/` @@ -548,7 +549,7 @@ class Dyld { void dumpDebugInfo() const; public: - Dyld(const Cpp::DynamicLibraryManager& DLM, + Dyld(const DynamicLibraryManager& DLM, PermanentlyIgnoreCallbackProto shouldIgnore, StringRef execFormat) : m_DynamicLibraryManager(DLM), m_ShouldPermanentlyIgnoreCallback(shouldIgnore), @@ -594,12 +595,14 @@ void HandleDynTab(const ELFFile* Elf, StringRef FileName, Deps.push_back(Data + Dyn.d_un.d_val); break; case ELF::DT_RPATH: - SplitPaths(Data + Dyn.d_un.d_val, RPath, utils::kAllowNonExistent, - Cpp::utils::platform::kEnvDelim, false); + SplitPaths(Data + Dyn.d_un.d_val, RPath, + utils::SplitMode::kAllowNonExistent, + utils::platform::kEnvDelim, false); break; case ELF::DT_RUNPATH: - SplitPaths(Data + Dyn.d_un.d_val, RunPath, utils::kAllowNonExistent, - Cpp::utils::platform::kEnvDelim, false); + SplitPaths(Data + Dyn.d_un.d_val, RunPath, + utils::SplitMode::kAllowNonExistent, + utils::platform::kEnvDelim, false); break; case ELF::DT_FLAGS_1: // Check if this is not a pie executable. @@ -757,8 +760,8 @@ void Dyld::ScanForLibraries(bool searchSystemLibraries /* = false*/) { } else if (Command.C.cmd == MachO::LC_RPATH) { MachO::rpath_command rpathCmd = Obj->getRpathCommand(Command); SplitPaths(Command.Ptr + rpathCmd.path, RPath, - utils::kAllowNonExistent, - Cpp::utils::platform::kEnvDelim, false); + utils::SplitMode::kAllowNonExistent, + utils::platform::kEnvDelim, false); } } } else if (BinObjF->isCOFF()) { @@ -1112,7 +1115,7 @@ bool Dyld::ShouldPermanentlyIgnore(StringRef FileName) const { #define DEBUG_TYPE "Dyld:" assert(!m_ExecutableFormat.empty() && "Failed to find the object format!"); - if (!Cpp::DynamicLibraryManager::isSharedLibrary(FileName)) + if (!DynamicLibraryManager::isSharedLibrary(FileName)) return true; // No need to check linked libraries, as this function is only invoked @@ -1381,4 +1384,4 @@ std::string DynamicLibraryManager::getSymbolLocation(void* func) { #endif } -} // namespace Cpp +} // namespace CppInternal diff --git a/lib/CppInterOp/Paths.cpp b/lib/CppInterOp/Paths.cpp index 424d5f909..f3980c846 100644 --- a/lib/CppInterOp/Paths.cpp +++ b/lib/CppInterOp/Paths.cpp @@ -23,7 +23,7 @@ #include #endif -namespace Cpp { +namespace CppInternal { namespace utils { namespace platform { @@ -361,7 +361,7 @@ bool SplitPaths(llvm::StringRef PathStr, void AddIncludePaths( llvm::StringRef PathStr, clang::HeaderSearchOptions& HOpts, - const char* Delim /* = Cpp::utils::platform::kEnvDelim */) { + const char* Delim /* = CppInternal::utils::platform::kEnvDelim */) { #define DEBUG_TYPE "AddIncludePaths" llvm::SmallVector Paths; @@ -399,4 +399,4 @@ void AddIncludePaths( } } // namespace utils -} // namespace Cpp +} // namespace CppInternal diff --git a/lib/CppInterOp/Paths.h b/lib/CppInterOp/Paths.h index 0622fc9da..46948ae87 100644 --- a/lib/CppInterOp/Paths.h +++ b/lib/CppInterOp/Paths.h @@ -24,7 +24,7 @@ class HeaderSearchOptions; class FileManager; } // namespace clang -namespace Cpp { +namespace CppInternal { namespace utils { namespace platform { @@ -80,7 +80,7 @@ enum SplitMode { bool SplitPaths(llvm::StringRef PathStr, llvm::SmallVectorImpl& Paths, SplitMode Mode = kPruneNonExistent, - llvm::StringRef Delim = Cpp::utils::platform::kEnvDelim, + llvm::StringRef Delim = CppInternal::utils::platform::kEnvDelim, bool Verbose = false); ///\brief Adds multiple include paths separated by a delimiter into the @@ -92,8 +92,9 @@ bool SplitPaths(llvm::StringRef PathStr, ///\param[in] Opts - HeaderSearchOptions to add paths into ///\param[in] Delim - Delimiter to separate paths or NULL if a single path /// -void AddIncludePaths(llvm::StringRef PathStr, clang::HeaderSearchOptions& HOpts, - const char* Delim = Cpp::utils::platform::kEnvDelim); +void AddIncludePaths( + llvm::StringRef PathStr, clang::HeaderSearchOptions& HOpts, + const char* Delim = CppInternal::utils::platform::kEnvDelim); ///\brief Write to cling::errs that directory does not exist in a format /// matching what 'clang -v' would do @@ -117,6 +118,6 @@ void CopyIncludePaths(const clang::HeaderSearchOptions& Opts, bool WithSystem, bool WithFlags); } // namespace utils -} // namespace Cpp +} // namespace CppInternal #endif // CPPINTEROP_UTILS_PATHS_H