diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/AST/DeclarationName.cpp | 8 | ||||
-rw-r--r-- | clang/lib/Index/IndexSymbol.cpp | 19 | ||||
-rw-r--r-- | clang/lib/Index/USRGeneration.cpp | 7 |
3 files changed, 32 insertions, 2 deletions
diff --git a/clang/lib/AST/DeclarationName.cpp b/clang/lib/AST/DeclarationName.cpp index f6d045b2dab..344a2389228 100644 --- a/clang/lib/AST/DeclarationName.cpp +++ b/clang/lib/AST/DeclarationName.cpp @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// #include "clang/AST/ASTContext.h" -#include "clang/AST/Decl.h" +#include "clang/AST/DeclCXX.h" #include "clang/AST/DeclarationName.h" #include "clang/AST/Type.h" #include "clang/AST/TypeLoc.h" @@ -140,6 +140,12 @@ static void printCXXConstructorDestructorName(QualType ClassType, OS << *ClassRec->getDecl(); return; } + if (Policy.SuppressTemplateArgsInCXXConstructors) { + if (auto *InjTy = ClassType->getAs<InjectedClassNameType>()) { + OS << *InjTy->getDecl(); + return; + } + } if (!Policy.LangOpts.CPlusPlus) { // Passed policy is the default one from operator <<, use a C++ policy. LangOptions LO; diff --git a/clang/lib/Index/IndexSymbol.cpp b/clang/lib/Index/IndexSymbol.cpp index 95ae9776826..010ccd42a4a 100644 --- a/clang/lib/Index/IndexSymbol.cpp +++ b/clang/lib/Index/IndexSymbol.cpp @@ -11,6 +11,7 @@ #include "clang/AST/DeclCXX.h" #include "clang/AST/DeclObjC.h" #include "clang/AST/DeclTemplate.h" +#include "clang/AST/PrettyPrinter.h" using namespace clang; using namespace clang::index; @@ -234,6 +235,24 @@ void index::printSymbolRoles(SymbolRoleSet Roles, raw_ostream &OS) { }); } +bool index::printSymbolName(const Decl *D, const LangOptions &LO, + raw_ostream &OS) { + if (auto *ND = dyn_cast<NamedDecl>(D)) { + PrintingPolicy Policy(LO); + // Forward references can have different template argument names. Suppress + // the template argument names in constructors to make their name more + // stable. + Policy.SuppressTemplateArgsInCXXConstructors = true; + DeclarationName DeclName = ND->getDeclName(); + if (DeclName.isEmpty()) + return true; + DeclName.print(OS, Policy); + return false; + } else { + return true; + } +} + StringRef index::getSymbolKindString(SymbolKind K) { switch (K) { case SymbolKind::Unknown: return "<unknown>"; diff --git a/clang/lib/Index/USRGeneration.cpp b/clang/lib/Index/USRGeneration.cpp index 3b2954f9770..c15838c76c6 100644 --- a/clang/lib/Index/USRGeneration.cpp +++ b/clang/lib/Index/USRGeneration.cpp @@ -210,7 +210,12 @@ void USRGenerator::VisitFunctionDecl(const FunctionDecl *D) { VisitTemplateParameterList(FunTmpl->getTemplateParameters()); } else Out << "@F@"; - D->printName(Out); + + PrintingPolicy Policy(Context->getLangOpts()); + // Forward references can have different template argument names. Suppress the + // template argument names in constructors to make their USR more stable. + Policy.SuppressTemplateArgsInCXXConstructors = true; + D->getDeclName().print(Out, Policy); ASTContext &Ctx = *Context; if (!Ctx.getLangOpts().CPlusPlus || D->isExternC()) |