[clang] a133cba - [clang][index] Index the injected class name types.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 22 01:08:04 PST 2020


Author: Haojian Wu
Date: 2020-01-22T10:07:54+01:00
New Revision: a133cbaad5b292aab7134e3a91e80c5b2dddbe7e

URL: https://github.com/llvm/llvm-project/commit/a133cbaad5b292aab7134e3a91e80c5b2dddbe7e
DIFF: https://github.com/llvm/llvm-project/commit/a133cbaad5b292aab7134e3a91e80c5b2dddbe7e.diff

LOG: [clang][index] Index the injected class name types.

Summary: Currently, we (clangd) are missing this kind of references.

Reviewers: kadircet

Subscribers: ilya-biryukov, arphaman, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D73109

Added: 
    

Modified: 
    clang/lib/Index/IndexTypeSourceInfo.cpp
    clang/unittests/Index/IndexTests.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Index/IndexTypeSourceInfo.cpp b/clang/lib/Index/IndexTypeSourceInfo.cpp
index 959d5f1197fe..b9fc90040cfc 100644
--- a/clang/lib/Index/IndexTypeSourceInfo.cpp
+++ b/clang/lib/Index/IndexTypeSourceInfo.cpp
@@ -170,6 +170,11 @@ class TypeIndexer : public RecursiveASTVisitor<TypeIndexer> {
     return true;
   }
 
+  bool VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) {
+    return IndexCtx.handleReference(TL.getDecl(), TL.getNameLoc(), Parent,
+                                    ParentDC, SymbolRoleSet(), Relations);
+  }
+
   bool VisitDependentNameTypeLoc(DependentNameTypeLoc TL) {
     const DependentNameType *DNT = TL.getTypePtr();
     const NestedNameSpecifier *NNS = DNT->getQualifier();

diff  --git a/clang/unittests/Index/IndexTests.cpp b/clang/unittests/Index/IndexTests.cpp
index 000cfe212505..3ccec68321b1 100644
--- a/clang/unittests/Index/IndexTests.cpp
+++ b/clang/unittests/Index/IndexTests.cpp
@@ -293,6 +293,27 @@ TEST(IndexTest, Constructors) {
                 WrittenAt(Position(4, 8)))));
 }
 
+TEST(IndexTest, InjecatedNameClass) {
+  std::string Code = R"cpp(
+    template <typename T>
+    class Foo {
+      void f(Foo x);
+    };
+  )cpp";
+  auto Index = std::make_shared<Indexer>();
+  IndexingOptions Opts;
+  tooling::runToolOnCode(std::make_unique<IndexAction>(Index, Opts), Code);
+  EXPECT_THAT(Index->Symbols,
+              UnorderedElementsAre(AllOf(QName("Foo"), Kind(SymbolKind::Class),
+                                         WrittenAt(Position(3, 11))),
+                                   AllOf(QName("Foo::f"),
+                                         Kind(SymbolKind::InstanceMethod),
+                                         WrittenAt(Position(4, 12))),
+                                   AllOf(QName("Foo"), Kind(SymbolKind::Class),
+                                         HasRole(SymbolRole::Reference),
+                                         WrittenAt(Position(4, 14)))));
+}
+
 } // namespace
 } // namespace index
 } // namespace clang


        


More information about the cfe-commits mailing list