SuppressUnwrittenScope(false), SuppressInitializers(false),
ConstantArraySizeAsWritten(false), AnonymousTagLocations(true),
SuppressStrongLifetime(false), SuppressLifetimeQualifiers(false),
+ SuppressTemplateArgsInCXXConstructors(false),
Bool(LO.Bool), TerseOutput(false), PolishForDeclaration(false),
Half(LO.Half), MSWChar(LO.MicrosoftExt && !LO.WChar),
IncludeNewlines(true), MSVCFormatting(false) { }
/// \brief When true, suppress printing of lifetime qualifier in
/// ARC.
unsigned SuppressLifetimeQualifiers : 1;
-
+
+ /// When true, suppresses printing template arguments in names of C++
+ /// constructors.
+ unsigned SuppressTemplateArgsInCXXConstructors : 1;
+
/// \brief Whether we can use 'bool' rather than '_Bool', even if the language
/// doesn't actually have 'bool' (because, e.g., it is defined as a macro).
unsigned Bool : 1;
namespace clang {
class Decl;
+ class LangOptions;
namespace index {
void applyForEachSymbolRole(SymbolRoleSet Roles,
llvm::function_ref<void(SymbolRole)> Fn);
void printSymbolRoles(SymbolRoleSet Roles, raw_ostream &OS);
+
+/// \returns true if no name was printed, false otherwise.
+bool printSymbolName(const Decl *D, const LangOptions &LO, raw_ostream &OS);
+
StringRef getSymbolKindString(SymbolKind K);
StringRef getTemplateKindStr(SymbolCXXTemplateKind TK);
StringRef getSymbolLanguageString(SymbolLanguage K);
//
//===----------------------------------------------------------------------===//
#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"
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;
#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;
});
}
+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>";
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())
--- /dev/null
+// RUN: c-index-test core -print-source-symbols -- %s -target x86_64-apple-macosx10.7 | FileCheck %s
+
+template <typename TemplArg>
+class TemplCls {
+// CHECK: [[@LINE-1]]:7 | c++-class/C++ | TemplCls | c:@ST>1#T@TemplCls | <no-cgname> | Def | rel: 0
+ TemplCls(int x);
+ // CHECK: [[@LINE-1]]:3 | constructor/C++ | TemplCls | c:@ST>1#T@TemplCls@F@TemplCls#I# | <no-cgname> | Decl/RelChild | rel: 1
+ // CHECK-NEXT: RelChild | TemplCls | c:@ST>1#T@TemplCls
+};
static void printSymbolNameAndUSR(const Decl *D, ASTContext &Ctx,
raw_ostream &OS) {
- if (auto *ND = dyn_cast<NamedDecl>(D)) {
- PrintingPolicy PrintPolicy(Ctx.getLangOpts());
- ND->getDeclName().print(OS, PrintPolicy);
- } else {
+ if (printSymbolName(D, Ctx.getLangOpts(), OS)) {
OS << "<no-name>";
}
OS << " | ";