From: Argyrios Kyrtzidis Date: Fri, 10 Feb 2012 20:10:48 +0000 (+0000) Subject: [libclang] Indexing API: fully index using decls and directives. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=911d717307e0d90980699cf75204c22e4462b45d;p=clang [libclang] Indexing API: fully index using decls and directives. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150268 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/Index/index-refs.cpp b/test/Index/index-refs.cpp index 00767b061d..be272f518d 100644 --- a/test/Index/index-refs.cpp +++ b/test/Index/index-refs.cpp @@ -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 diff --git a/tools/libclang/IndexDecl.cpp b/tools/libclang/IndexDecl.cpp index 3e9266995e..55ae9e0afc 100644 --- a/tools/libclang/IndexDecl.cpp +++ b/tools/libclang/IndexDecl.cpp @@ -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())