[AST/index] Introduce an option 'SuppressTemplateArgsInCXXConstructors' in printing policy.
Enable it for USRs and names when indexing.
Forward references can have different template argument names; including them
makes USRs and names unstable, since the name depends on whether we saw a forward reference or not.
llvm-svn: 260866
diff --git a/clang/lib/Index/IndexSymbol.cpp b/clang/lib/Index/IndexSymbol.cpp
index 95ae977..010ccd4 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 @@
});
}
+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>";