Skip to content

Commit 8940cdc

Browse files
committed
Make all maybeMangleDeclName overrides return a std::string.
1 parent fa5df84 commit 8940cdc

File tree

4 files changed

+35
-29
lines changed

4 files changed

+35
-29
lines changed

include/cling/Utils/AST.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,23 @@ namespace utils {
6464

6565
///\brief Get the mangled name of a GlobalDecl.
6666
///
67-
///\param [in] GD - try to mangle this decl's name.
68-
///\param [out] mangledName - put the mangled name in here.
67+
///\param [in] GD - Try to mangle this decl's name.
6968
///
70-
void maybeMangleDeclName(const clang::GlobalDecl& GD,
71-
std::string& mangledName);
69+
///\returns The mangled or pure name (when ND should not be mangled) on
70+
/// success or an empty string on failure.
71+
///
72+
std::string maybeMangleDeclName(const clang::GlobalDecl& GD);
7273

73-
///\brief Get the mangled name of a clang::Decl subclass. FunctionDecls and
74-
/// VarDecls are currently supported.
74+
///\brief Get the mangled name of a clang::Decl subclass. FunctionDecl,
75+
/// VarDecl, ValueDecl, and NamedDecl are currently supported.
7576
///
76-
///\param [in] Decl - try to mangle this decl's name.
77-
///\param [out] mangledName - put the mangled name in here.
77+
///\param [in] Decl - Try to mangle this decl's name.
78+
///
79+
///\returns The mangled or pure name (when ND should not be mangled) on
80+
/// success or an empty string on failure.
7881
///
7982
template <typename T>
80-
void maybeMangleDeclName(const T* Decl, std::string& mangledName);
83+
std::string maybeMangleDeclName(const T* Decl);
8184

8285
///\brief Retrieves the last expression of a function body. If it was a
8386
/// DeclStmt with a variable declaration, creates DeclRefExpr and adds it to

lib/Interpreter/DeclUnloader.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -853,17 +853,16 @@ bool DeclUnloader::VisitRedeclarable(clang::Redeclarable<T>* R, DeclContext* DC)
853853
utils::DiagnosticsOverride IgnoreMangleErrors(m_Sema->getDiagnostics());
854854
#endif
855855
#endif
856-
utils::Analyze::maybeMangleDeclName(GD, mangledName);
856+
utils::Analyze::maybeMangleDeclName(GD).swap(mangledName);
857857
}
858858

859859
// Handle static locals. void func() { static int var; } is represented
860860
// in the llvm::Module is a global named @func.var
861861
if (const VarDecl* VD = dyn_cast<VarDecl>(GD.getDecl())) {
862862
if (VD->isStaticLocal()) {
863-
std::string functionMangledName;
864-
GlobalDecl FDGD(cast<FunctionDecl>(VD->getDeclContext()));
865-
utils::Analyze::maybeMangleDeclName(FDGD, functionMangledName);
866-
mangledName = functionMangledName + "." + mangledName;
863+
mangledName = utils::Analyze::maybeMangleDeclName(GlobalDecl(
864+
cast<FunctionDecl>(VD->getDeclContext()))) +
865+
"." + mangledName;
867866
}
868867
}
869868

lib/Interpreter/Interpreter.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -983,10 +983,8 @@ namespace cling {
983983
if (!FD)
984984
return kExeUnkownFunction;
985985

986-
std::string mangledNameIfNeeded;
987-
utils::Analyze::maybeMangleDeclName(FD, mangledNameIfNeeded);
988986
IncrementalExecutor::ExecutionResult ExeRes =
989-
m_Executor->executeWrapper(mangledNameIfNeeded, res);
987+
m_Executor->executeWrapper(utils::Analyze::maybeMangleDeclName(FD), res);
990988
return ConvertExecutionResult(ExeRes);
991989
}
992990

@@ -1550,9 +1548,7 @@ namespace cling {
15501548
void* Interpreter::getAddressOfGlobal(const GlobalDecl& GD,
15511549
bool* fromJIT /*=0*/) const {
15521550
// Return a symbol's address, and whether it was jitted.
1553-
std::string mangledName;
1554-
utils::Analyze::maybeMangleDeclName(GD, mangledName);
1555-
return getAddressOfGlobal(mangledName, fromJIT);
1551+
return getAddressOfGlobal(utils::Analyze::maybeMangleDeclName(GD), fromJIT);
15561552
}
15571553

15581554
void* Interpreter::getAddressOfGlobal(llvm::StringRef SymName,

lib/Utils/AST.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,21 +107,29 @@ namespace utils {
107107
}
108108
return RawStr.str();
109109
}
110-
111-
void maybeMangleDeclName(const GlobalDecl& GD, std::string& mangledName) {
112-
mangledName = maybeMangleDeclName(cast<NamedDecl>(GD.getDecl()), &GD);
110+
111+
std::string maybeMangleDeclName(const GlobalDecl& GD) {
112+
return maybeMangleDeclName(cast<NamedDecl>(GD.getDecl()), &GD);
113113
}
114114

115115
template <>
116-
void maybeMangleDeclName<FunctionDecl>(const FunctionDecl* FD,
117-
std::string& mangledName) {
118-
return maybeMangleDeclName(GlobalDecl(FD), mangledName);
116+
std::string maybeMangleDeclName<FunctionDecl>(const FunctionDecl* FD) {
117+
return maybeMangleDeclName(GlobalDecl(FD));
118+
}
119+
120+
template <>
121+
std::string maybeMangleDeclName<VarDecl>(const VarDecl* VD) {
122+
return maybeMangleDeclName(GlobalDecl(VD));
123+
}
124+
125+
template <>
126+
std::string maybeMangleDeclName<ValueDecl>(const ValueDecl* VD) {
127+
return maybeMangleDeclName(cast<NamedDecl>(VD), nullptr);
119128
}
120129

121130
template <>
122-
void maybeMangleDeclName<VarDecl>(const VarDecl* VD,
123-
std::string& mangledName) {
124-
return maybeMangleDeclName(GlobalDecl(VD), mangledName);
131+
std::string maybeMangleDeclName<NamedDecl>(const NamedDecl* ND) {
132+
return maybeMangleDeclName(ND, nullptr);
125133
}
126134
}
127135

0 commit comments

Comments
 (0)