[clang][Index] Visit UsingDecls and generate USRs for them

Summary:
Add indexing of UsingDecl itself.
Also enable generation of USRs for UsingDecls, using the qualified name of the
decl.

Reviewers: ilya-biryukov, akyrtzi

Subscribers: arphaman, cfe-commits

Tags: #clang

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

llvm-svn: 354878
diff --git a/clang/unittests/Index/IndexTests.cpp b/clang/unittests/Index/IndexTests.cpp
index 66cef88..97051c0 100644
--- a/clang/unittests/Index/IndexTests.cpp
+++ b/clang/unittests/Index/IndexTests.cpp
@@ -57,6 +57,7 @@
   std::string QName;
   Position WrittenPos;
   Position DeclPos;
+  SymbolInfo SymInfo;
   // FIXME: add more information.
 };
 
@@ -78,6 +79,7 @@
     if (!ND)
       return true;
     TestSymbol S;
+    S.SymInfo = getSymbolInfo(D);
     S.QName = ND->getQualifiedNameAsString();
     S.WrittenPos = Position::fromSourceLocation(Loc, AST->getSourceManager());
     S.DeclPos =
@@ -140,6 +142,7 @@
 MATCHER_P(QName, Name, "") { return arg.QName == Name; }
 MATCHER_P(WrittenAt, Pos, "") { return arg.WrittenPos == Pos; }
 MATCHER_P(DeclAt, Pos, "") { return arg.DeclPos == Pos; }
+MATCHER_P(Kind, SymKind, "") { return arg.SymInfo.Kind == SymKind; }
 
 TEST(IndexTest, Simple) {
   auto Index = std::make_shared<Indexer>();
@@ -240,6 +243,20 @@
                     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(AllOf(QName("std::foo"), Kind(SymbolKind::Using))));
+}
+
 } // namespace
 } // namespace index
 } // namespace clang