[PATCH] D58340: [clang][Index] Visit UsingDecls and generate USRs for them

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 18 06:10:21 PST 2019


kadircet updated this revision to Diff 187236.
kadircet added a comment.

- Address comments


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58340/new/

https://reviews.llvm.org/D58340

Files:
  lib/Index/IndexDecl.cpp
  lib/Index/USRGeneration.cpp
  test/Index/usrs.cpp
  unittests/Index/IndexTests.cpp


Index: unittests/Index/IndexTests.cpp
===================================================================
--- unittests/Index/IndexTests.cpp
+++ unittests/Index/IndexTests.cpp
@@ -134,6 +134,19 @@
   EXPECT_THAT(Index->Symbols, Not(Contains(QName("bar"))));
 }
 
+TEST(IndexTest, UsingDecls) {
+  std::string Code = R"cpp(
+    void foo(int bar);
+    namespace std {
+      using ::foo;
+    }
+  )cpp";
+  auto Index = std::make_shared<Indexer>();
+  IndexingOptions Opts;
+  tooling::runToolOnCode(new IndexAction(Index, Opts), Code);
+  EXPECT_THAT(Index->Symbols, Contains(QName("std::foo")));
+}
+
 } // namespace
 } // namespace index
 } // namespace clang
Index: test/Index/usrs.cpp
===================================================================
--- test/Index/usrs.cpp
+++ test/Index/usrs.cpp
@@ -158,7 +158,7 @@
 // CHECK: usrs.cpp c:@NA at foo_alias
 // CHECK-NOT: foo
 // CHECK: usrs.cpp c:@NA at foo_alias2
-// CHECK-NOT: ClsB
+// CHECK: usrs.cpp c:@UD at ClsB Extent=[64:1 - 64:16]
 // CHECK: usrs.cpp c:@NA at foo_alias3
 // CHECK: usrs.cpp c:@aN Extent=[68:1 - 73:2]
 // CHECK: usrs.cpp c:usrs.cpp at aN@S at RDar9371763_Foo Extent=[69:1 - 72:2]
Index: lib/Index/USRGeneration.cpp
===================================================================
--- lib/Index/USRGeneration.cpp
+++ lib/Index/USRGeneration.cpp
@@ -111,7 +111,12 @@
   }
 
   void VisitUsingDecl(const UsingDecl *D) {
-    IgnoreResults = true;
+    VisitDeclContext(D->getDeclContext());
+    Out << "@UD@";
+
+    bool EmittedDeclName = !EmitDeclName(D);
+    assert(EmittedDeclName && "EmitDeclName can not fail for UsingDecls");
+    (void)EmittedDeclName;
   }
 
   bool ShouldGenerateLocation(const NamedDecl *D);
Index: lib/Index/IndexDecl.cpp
===================================================================
--- lib/Index/IndexDecl.cpp
+++ lib/Index/IndexDecl.cpp
@@ -580,9 +580,10 @@
   }
 
   bool VisitUsingDecl(const UsingDecl *D) {
+    IndexCtx.handleDecl(D);
+
     const DeclContext *DC = D->getDeclContext()->getRedeclContext();
     const NamedDecl *Parent = dyn_cast<NamedDecl>(DC);
-
     IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), Parent,
                                          D->getLexicalDeclContext());
     for (const auto *I : D->shadows())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58340.187236.patch
Type: text/x-patch
Size: 2261 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190218/83a561ae/attachment.bin>


More information about the cfe-commits mailing list