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

- Add SymbolSubKind for UsingDeclarations


Repository:
  rC Clang

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

https://reviews.llvm.org/D58340

Files:
  include/clang/Index/IndexSymbol.h
  lib/Index/IndexDecl.cpp
  lib/Index/IndexSymbol.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
@@ -240,6 +240,19 @@
                     Contains(QName("Foo::C")), Contains(QName("Foo::NoRef"))));
 }
 
+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@foo_alias
 // CHECK-NOT: foo
 // CHECK: usrs.cpp c:@NA@foo_alias2
-// CHECK-NOT: ClsB
+// CHECK: usrs.cpp c:@UD@ClsB Extent=[64:1 - 64:16]
 // CHECK: usrs.cpp c:@NA@foo_alias3
 // CHECK: usrs.cpp c:@aN Extent=[68:1 - 73:2]
 // CHECK: usrs.cpp c:usrs.cpp@aN@S@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/IndexSymbol.cpp
===================================================================
--- lib/Index/IndexSymbol.cpp
+++ lib/Index/IndexSymbol.cpp
@@ -316,6 +316,12 @@
       Info.Lang = SymbolLanguage::CXX;
       Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
       break;
+    case Decl::Using:
+      Info.Kind = SymbolKind::Using;
+      Info.SubKind = SymbolSubKind::UsingDeclaration;
+      Info.Lang = SymbolLanguage::CXX;
+      Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
+      break;
     case Decl::Binding:
       Info.Kind = SymbolKind::Variable;
       Info.Lang = SymbolLanguage::CXX;
@@ -490,6 +496,7 @@
   case SymbolSubKind::AccessorSetter: return "acc-set";
   case SymbolSubKind::UsingTypename: return "using-typename";
   case SymbolSubKind::UsingValue: return "using-value";
+  case SymbolSubKind::UsingDeclaration: return "using-declaration";
   }
   llvm_unreachable("invalid symbol subkind");
 }
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())
Index: include/clang/Index/IndexSymbol.h
===================================================================
--- include/clang/Index/IndexSymbol.h
+++ include/clang/Index/IndexSymbol.h
@@ -72,6 +72,7 @@
   AccessorSetter,
   UsingTypename,
   UsingValue,
+  UsingDeclaration,
 };
 
 typedef uint16_t SymbolPropertySet;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to