]> granicus.if.org Git - clang/commitdiff
[libclang] Indexing API: fully index using decls and directives.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 10 Feb 2012 20:10:48 +0000 (20:10 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 10 Feb 2012 20:10:48 +0000 (20:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150268 91177308-0d34-0410-b5e6-96231b3b80d8

test/Index/index-refs.cpp
tools/libclang/IndexDecl.cpp

index 00767b061d0270a64bbd724b822f2d3ff97fac0a..be272f518d97e4b0d924285fb921d6dba253a634 100644 (file)
@@ -34,6 +34,16 @@ void foo2(S &s) {
   s(3);
 }
 
+namespace NS {
+  namespace Inn {}
+  typedef int Foo;
+}
+
+using namespace NS;
+using namespace NS::Inn;
+using NS::Foo;
+
+
 // RUN: c-index-test -index-file %s | FileCheck %s
 // CHECK:      [indexDeclaration]: kind: namespace | name: NS
 // CHECK-NEXT: [indexDeclaration]: kind: variable | name: gx
@@ -58,3 +68,9 @@ void foo2(S &s) {
 // CHECK-NEXT: [indexEntityReference]: kind: c++-instance-method | name: operator=
 // CHECK-NEXT: [indexEntityReference]: kind: c++-instance-method | name: operator!=
 // CHECK-NEXT: [indexEntityReference]: kind: c++-instance-method | name: operator()
+
+// CHECK:      [indexEntityReference]: kind: namespace | name: NS | {{.*}} | loc: 42:17
+// CHECK-NEXT: [indexEntityReference]: kind: namespace | name: NS | {{.*}} | loc: 43:17
+// CHECK-NEXT: [indexEntityReference]: kind: namespace | name: Inn | {{.*}} | loc: 43:21
+// CHECK-NEXT: [indexEntityReference]: kind: namespace | name: NS | {{.*}} | loc: 44:7
+// CHECK-NEXT: [indexEntityReference]: kind: typedef | name: Foo | {{.*}} | loc: 44:11
index 3e9266995e09e729e9370ce99de2e22b5e24b68b..55ae9e0afca9d6e6e019b01da43bd42c8a2e029c 100644 (file)
@@ -213,6 +213,29 @@ public:
     return true;
   }
 
+  bool VisitUsingDecl(UsingDecl *D) {
+    // FIXME: Parent for the following is CXIdxEntity_Unexposed with no USR,
+    // we should do better.
+
+    IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), D);
+    for (UsingDecl::shadow_iterator
+           I = D->shadow_begin(), E = D->shadow_end(); I != E; ++I) {
+      IndexCtx.handleReference((*I)->getUnderlyingDecl(), D->getLocation(),
+                               D, D->getLexicalDeclContext());
+    }
+    return true;
+  }
+
+  bool VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
+    // FIXME: Parent for the following is CXIdxEntity_Unexposed with no USR,
+    // we should do better.
+
+    IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), D);
+    IndexCtx.handleReference(D->getNominatedNamespaceAsWritten(),
+                             D->getLocation(), D, D->getLexicalDeclContext());
+    return true;
+  }
+
   bool VisitClassTemplateDecl(ClassTemplateDecl *D) {
     IndexCtx.handleClassTemplate(D);
     if (D->isThisDeclarationADefinition())