|
@@ -22,17 +22,15 @@
|
|
|
#include "CXType.h"
|
|
|
#include "CursorVisitor.h"
|
|
|
#include "clang/AST/Attr.h"
|
|
|
-#include "clang/AST/Mangle.h"
|
|
|
#include "clang/AST/StmtVisitor.h"
|
|
|
-#include "clang/AST/VTableBuilder.h"
|
|
|
#include "clang/Basic/Diagnostic.h"
|
|
|
#include "clang/Basic/DiagnosticCategories.h"
|
|
|
#include "clang/Basic/DiagnosticIDs.h"
|
|
|
-#include "clang/Basic/TargetInfo.h"
|
|
|
#include "clang/Basic/Version.h"
|
|
|
#include "clang/Frontend/ASTUnit.h"
|
|
|
#include "clang/Frontend/CompilerInstance.h"
|
|
|
#include "clang/Frontend/FrontendDiagnostic.h"
|
|
|
+#include "clang/Index/CodegenNameGenerator.h"
|
|
|
#include "clang/Index/CommentToXML.h"
|
|
|
#include "clang/Lex/HeaderSearch.h"
|
|
|
#include "clang/Lex/Lexer.h"
|
|
@@ -43,8 +41,6 @@
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
|
|
#include "llvm/Config/llvm-config.h"
|
|
|
-#include "llvm/IR/DataLayout.h"
|
|
|
-#include "llvm/IR/Mangler.h"
|
|
|
#include "llvm/Support/Compiler.h"
|
|
|
#include "llvm/Support/CrashRecoveryContext.h"
|
|
|
#include "llvm/Support/Format.h"
|
|
@@ -3976,59 +3972,6 @@ static SourceLocation getLocationFromExpr(const Expr *E) {
|
|
|
return E->getLocStart();
|
|
|
}
|
|
|
|
|
|
-static std::string getMangledStructor(std::unique_ptr<MangleContext> &M,
|
|
|
- std::unique_ptr<llvm::DataLayout> &DL,
|
|
|
- const NamedDecl *ND,
|
|
|
- unsigned StructorType) {
|
|
|
- std::string FrontendBuf;
|
|
|
- llvm::raw_string_ostream FOS(FrontendBuf);
|
|
|
-
|
|
|
- if (const auto *CD = dyn_cast_or_null<CXXConstructorDecl>(ND))
|
|
|
- M->mangleCXXCtor(CD, static_cast<CXXCtorType>(StructorType), FOS);
|
|
|
- else if (const auto *DD = dyn_cast_or_null<CXXDestructorDecl>(ND))
|
|
|
- M->mangleCXXDtor(DD, static_cast<CXXDtorType>(StructorType), FOS);
|
|
|
-
|
|
|
- std::string BackendBuf;
|
|
|
- llvm::raw_string_ostream BOS(BackendBuf);
|
|
|
-
|
|
|
- llvm::Mangler::getNameWithPrefix(BOS, llvm::Twine(FOS.str()), *DL);
|
|
|
-
|
|
|
- return BOS.str();
|
|
|
-}
|
|
|
-
|
|
|
-static std::string getMangledName(std::unique_ptr<MangleContext> &M,
|
|
|
- std::unique_ptr<llvm::DataLayout> &DL,
|
|
|
- const NamedDecl *ND) {
|
|
|
- std::string FrontendBuf;
|
|
|
- llvm::raw_string_ostream FOS(FrontendBuf);
|
|
|
-
|
|
|
- M->mangleName(ND, FOS);
|
|
|
-
|
|
|
- std::string BackendBuf;
|
|
|
- llvm::raw_string_ostream BOS(BackendBuf);
|
|
|
-
|
|
|
- llvm::Mangler::getNameWithPrefix(BOS, llvm::Twine(FOS.str()), *DL);
|
|
|
-
|
|
|
- return BOS.str();
|
|
|
-}
|
|
|
-
|
|
|
-static std::string getMangledThunk(std::unique_ptr<MangleContext> &M,
|
|
|
- std::unique_ptr<llvm::DataLayout> &DL,
|
|
|
- const CXXMethodDecl *MD,
|
|
|
- const ThunkInfo &T) {
|
|
|
- std::string FrontendBuf;
|
|
|
- llvm::raw_string_ostream FOS(FrontendBuf);
|
|
|
-
|
|
|
- M->mangleThunk(MD, T, FOS);
|
|
|
-
|
|
|
- std::string BackendBuf;
|
|
|
- llvm::raw_string_ostream BOS(BackendBuf);
|
|
|
-
|
|
|
- llvm::Mangler::getNameWithPrefix(BOS, llvm::Twine(FOS.str()), *DL);
|
|
|
-
|
|
|
- return BOS.str();
|
|
|
-}
|
|
|
-
|
|
|
extern "C" {
|
|
|
|
|
|
unsigned clang_visitChildren(CXCursor parent,
|
|
@@ -4377,29 +4320,9 @@ CXString clang_Cursor_getMangling(CXCursor C) {
|
|
|
if (!D || !(isa<FunctionDecl>(D) || isa<VarDecl>(D)))
|
|
|
return cxstring::createEmpty();
|
|
|
|
|
|
- // First apply frontend mangling.
|
|
|
- const NamedDecl *ND = cast<NamedDecl>(D);
|
|
|
- ASTContext &Ctx = ND->getASTContext();
|
|
|
- std::unique_ptr<MangleContext> MC(Ctx.createMangleContext());
|
|
|
-
|
|
|
- std::string FrontendBuf;
|
|
|
- llvm::raw_string_ostream FrontendBufOS(FrontendBuf);
|
|
|
- if (MC->shouldMangleDeclName(ND)) {
|
|
|
- MC->mangleName(ND, FrontendBufOS);
|
|
|
- } else {
|
|
|
- ND->printName(FrontendBufOS);
|
|
|
- }
|
|
|
-
|
|
|
- // Now apply backend mangling.
|
|
|
- std::unique_ptr<llvm::DataLayout> DL(
|
|
|
- new llvm::DataLayout(Ctx.getTargetInfo().getDataLayoutString()));
|
|
|
-
|
|
|
- std::string FinalBuf;
|
|
|
- llvm::raw_string_ostream FinalBufOS(FinalBuf);
|
|
|
- llvm::Mangler::getNameWithPrefix(FinalBufOS, llvm::Twine(FrontendBufOS.str()),
|
|
|
- *DL);
|
|
|
-
|
|
|
- return cxstring::createDup(FinalBufOS.str());
|
|
|
+ ASTContext &Ctx = D->getASTContext();
|
|
|
+ index::CodegenNameGenerator CGNameGen(Ctx);
|
|
|
+ return cxstring::createDup(CGNameGen.getName(D));
|
|
|
}
|
|
|
|
|
|
CXStringSet *clang_Cursor_getCXXManglings(CXCursor C) {
|
|
@@ -4410,49 +4333,9 @@ CXStringSet *clang_Cursor_getCXXManglings(CXCursor C) {
|
|
|
if (!(isa<CXXRecordDecl>(D) || isa<CXXMethodDecl>(D)))
|
|
|
return nullptr;
|
|
|
|
|
|
- const NamedDecl *ND = cast<NamedDecl>(D);
|
|
|
-
|
|
|
- ASTContext &Ctx = ND->getASTContext();
|
|
|
- std::unique_ptr<MangleContext> M(Ctx.createMangleContext());
|
|
|
- std::unique_ptr<llvm::DataLayout> DL(
|
|
|
- new llvm::DataLayout(Ctx.getTargetInfo().getDataLayoutString()));
|
|
|
-
|
|
|
- std::vector<std::string> Manglings;
|
|
|
-
|
|
|
- auto hasDefaultCXXMethodCC = [](ASTContext &C, const CXXMethodDecl *MD) {
|
|
|
- auto DefaultCC = C.getDefaultCallingConvention(/*IsVariadic=*/false,
|
|
|
- /*IsCSSMethod=*/true);
|
|
|
- auto CC = MD->getType()->getAs<FunctionProtoType>()->getCallConv();
|
|
|
- return CC == DefaultCC;
|
|
|
- };
|
|
|
-
|
|
|
- if (const auto *CD = dyn_cast_or_null<CXXConstructorDecl>(ND)) {
|
|
|
- Manglings.emplace_back(getMangledStructor(M, DL, CD, Ctor_Base));
|
|
|
-
|
|
|
- if (Ctx.getTargetInfo().getCXXABI().isItaniumFamily())
|
|
|
- if (!CD->getParent()->isAbstract())
|
|
|
- Manglings.emplace_back(getMangledStructor(M, DL, CD, Ctor_Complete));
|
|
|
-
|
|
|
- if (Ctx.getTargetInfo().getCXXABI().isMicrosoft())
|
|
|
- if (CD->hasAttr<DLLExportAttr>() && CD->isDefaultConstructor())
|
|
|
- if (!(hasDefaultCXXMethodCC(Ctx, CD) && CD->getNumParams() == 0))
|
|
|
- Manglings.emplace_back(getMangledStructor(M, DL, CD,
|
|
|
- Ctor_DefaultClosure));
|
|
|
- } else if (const auto *DD = dyn_cast_or_null<CXXDestructorDecl>(ND)) {
|
|
|
- Manglings.emplace_back(getMangledStructor(M, DL, DD, Dtor_Base));
|
|
|
- if (Ctx.getTargetInfo().getCXXABI().isItaniumFamily()) {
|
|
|
- Manglings.emplace_back(getMangledStructor(M, DL, DD, Dtor_Complete));
|
|
|
- if (DD->isVirtual())
|
|
|
- Manglings.emplace_back(getMangledStructor(M, DL, DD, Dtor_Deleting));
|
|
|
- }
|
|
|
- } else if (const auto *MD = dyn_cast_or_null<CXXMethodDecl>(ND)) {
|
|
|
- Manglings.emplace_back(getMangledName(M, DL, ND));
|
|
|
- if (MD->isVirtual())
|
|
|
- if (const auto *TIV = Ctx.getVTableContext()->getThunkInfo(MD))
|
|
|
- for (const auto &T : *TIV)
|
|
|
- Manglings.emplace_back(getMangledThunk(M, DL, MD, T));
|
|
|
- }
|
|
|
-
|
|
|
+ ASTContext &Ctx = D->getASTContext();
|
|
|
+ index::CodegenNameGenerator CGNameGen(Ctx);
|
|
|
+ std::vector<std::string> Manglings = CGNameGen.getAllManglings(D);
|
|
|
return cxstring::createSet(Manglings);
|
|
|
}
|
|
|
|