@@ -39,6 +39,21 @@ using namespace llvm;
39
39
namespace clang {
40
40
namespace tooling {
41
41
42
+ const NamedDecl *getCanonicalSymbolDeclaration (const NamedDecl *FoundDecl) {
43
+ // If FoundDecl is a constructor or destructor, we want to instead take
44
+ // the Decl of the corresponding class.
45
+ if (const auto *CtorDecl = dyn_cast<CXXConstructorDecl>(FoundDecl))
46
+ FoundDecl = CtorDecl->getParent ();
47
+ else if (const auto *DtorDecl = dyn_cast<CXXDestructorDecl>(FoundDecl))
48
+ FoundDecl = DtorDecl->getParent ();
49
+ // FIXME: (Alex L): Canonicalize implicit template instantions, just like
50
+ // the indexer does it.
51
+
52
+ // Note: please update the declaration's doc comment every time the
53
+ // canonicalization rules are changed.
54
+ return FoundDecl;
55
+ }
56
+
42
57
namespace {
43
58
// \brief NamedDeclFindingConsumer should delegate finding USRs of given Decl to
44
59
// AdditionalUSRFinder. AdditionalUSRFinder adds USRs of ctor and dtor if given
@@ -193,13 +208,7 @@ class NamedDeclFindingConsumer : public ASTConsumer {
193
208
return false ;
194
209
}
195
210
196
- // If FoundDecl is a constructor or destructor, we want to instead take
197
- // the Decl of the corresponding class.
198
- if (const auto *CtorDecl = dyn_cast<CXXConstructorDecl>(FoundDecl))
199
- FoundDecl = CtorDecl->getParent ();
200
- else if (const auto *DtorDecl = dyn_cast<CXXDestructorDecl>(FoundDecl))
201
- FoundDecl = DtorDecl->getParent ();
202
-
211
+ FoundDecl = getCanonicalSymbolDeclaration (FoundDecl);
203
212
SpellingNames.push_back (FoundDecl->getNameAsString ());
204
213
AdditionalUSRFinder Finder (FoundDecl, Context);
205
214
USRList.push_back (Finder.Find ());
0 commit comments