Skip to content

Commit

Permalink
Make all maybeMangleDeclName overrides return a std::string.
Browse files Browse the repository at this point in the history
  • Loading branch information
marsupial committed Aug 22, 2017
1 parent fa5df84 commit d14e9b4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 29 deletions.
21 changes: 12 additions & 9 deletions include/cling/Utils/AST.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,23 @@ namespace utils {

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

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

///\brief Retrieves the last expression of a function body. If it was a
/// DeclStmt with a variable declaration, creates DeclRefExpr and adds it to
Expand Down
9 changes: 4 additions & 5 deletions lib/Interpreter/DeclUnloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -853,17 +853,16 @@ bool DeclUnloader::VisitRedeclarable(clang::Redeclarable<T>* R, DeclContext* DC)
utils::DiagnosticsOverride IgnoreMangleErrors(m_Sema->getDiagnostics());
#endif
#endif
utils::Analyze::maybeMangleDeclName(GD, mangledName);
utils::Analyze::maybeMangleDeclName(GD).swap(mangledName);
}

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

Expand Down
8 changes: 2 additions & 6 deletions lib/Interpreter/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -983,10 +983,8 @@ namespace cling {
if (!FD)
return kExeUnkownFunction;

std::string mangledNameIfNeeded;
utils::Analyze::maybeMangleDeclName(FD, mangledNameIfNeeded);
IncrementalExecutor::ExecutionResult ExeRes =
m_Executor->executeWrapper(mangledNameIfNeeded, res);
m_Executor->executeWrapper(utils::Analyze::maybeMangleDeclName(FD), res);
return ConvertExecutionResult(ExeRes);
}

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

void* Interpreter::getAddressOfGlobal(llvm::StringRef SymName,
Expand Down
26 changes: 17 additions & 9 deletions lib/Utils/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,29 @@ namespace utils {
}
return RawStr.str();
}
void maybeMangleDeclName(const GlobalDecl& GD, std::string& mangledName) {
mangledName = maybeMangleDeclName(cast<NamedDecl>(GD.getDecl()), &GD);

std::string maybeMangleDeclName(const GlobalDecl& GD) {
return maybeMangleDeclName(cast<NamedDecl>(GD.getDecl()), &GD);
}

template <>
void maybeMangleDeclName<FunctionDecl>(const FunctionDecl* FD,
std::string& mangledName) {
return maybeMangleDeclName(GlobalDecl(FD), mangledName);
std::string maybeMangleDeclName<FunctionDecl>(const FunctionDecl* FD) {
return maybeMangleDeclName(GlobalDecl(FD));
}

template <>
std::string maybeMangleDeclName<VarDecl>(const VarDecl* VD) {
return maybeMangleDeclName(GlobalDecl(VD));
}

template <>
std::string maybeMangleDeclName<ValueDecl>(const ValueDecl* VD) {
return maybeMangleDeclName(cast<NamedDecl>(VD), nullptr);
}

template <>
void maybeMangleDeclName<VarDecl>(const VarDecl* VD,
std::string& mangledName) {
return maybeMangleDeclName(GlobalDecl(VD), mangledName);
std::string maybeMangleDeclName<NamedDecl>(const NamedDecl* ND) {
return maybeMangleDeclName(ND, nullptr);
}
}

Expand Down

0 comments on commit d14e9b4

Please sign in to comment.