[cfe-commits] r163563 - in /cfe/trunk: test/Index/index-decls.m tools/libclang/IndexBody.cpp tools/libclang/IndexDecl.cpp tools/libclang/IndexingContext.cpp tools/libclang/IndexingContext.h

Argyrios Kyrtzidis akyrtzi at gmail.com
Mon Sep 10 15:58:04 PDT 2012


Author: akirtzidis
Date: Mon Sep 10 17:58:04 2012
New Revision: 163563

URL: http://llvm.org/viewvc/llvm-project?rev=163563&view=rev
Log:
[libclang] Do index 'extern' declarations inside functions.

rdar://12257073

Modified:
    cfe/trunk/test/Index/index-decls.m
    cfe/trunk/tools/libclang/IndexBody.cpp
    cfe/trunk/tools/libclang/IndexDecl.cpp
    cfe/trunk/tools/libclang/IndexingContext.cpp
    cfe/trunk/tools/libclang/IndexingContext.h

Modified: cfe/trunk/test/Index/index-decls.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/index-decls.m?rev=163563&r1=163562&r2=163563&view=diff
==============================================================================
--- cfe/trunk/test/Index/index-decls.m (original)
+++ cfe/trunk/test/Index/index-decls.m Mon Sep 10 17:58:04 2012
@@ -26,6 +26,13 @@
 }
 @end
 
+int test1() {
+  extern int extvar;
+  extvar = 2;
+  extern int extfn();
+  return extfn();
+}
+
 // RUN: c-index-test -index-file %s -target x86_64-apple-macosx10.7 > %t
 // RUN: FileCheck %s -input-file=%t
 // CHECK: [indexDeclaration]: kind: objc-class | name: I | {{.*}} | loc: 1:12
@@ -41,3 +48,9 @@
 
 // CHECK: [indexDeclaration]: kind: objc-ivar | name: _auto_prop | {{.*}} | loc: 20:33
 // CHECK: [indexEntityReference]: kind: objc-ivar | name: _auto_prop | {{.*}} | loc: 25:3
+
+// CHECK: [indexDeclaration]: kind: function | name: test1 | {{.*}} | loc: 29:5
+// CHECK: [indexDeclaration]: kind: variable | name: extvar | {{.*}} | loc: 30:14
+// CHECK: [indexEntityReference]: kind: variable | name: extvar | {{.*}} | loc: 31:3
+// CHECK: [indexDeclaration]: kind: function | name: extfn | {{.*}} | loc: 32:14
+// CHECK: [indexEntityReference]: kind: function | name: extfn | {{.*}} | loc: 33:10

Modified: cfe/trunk/tools/libclang/IndexBody.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/IndexBody.cpp?rev=163563&r1=163562&r2=163563&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/IndexBody.cpp (original)
+++ cfe/trunk/tools/libclang/IndexBody.cpp Mon Sep 10 17:58:04 2012
@@ -130,8 +130,20 @@
   }
 
   bool VisitDeclStmt(DeclStmt *S) {
-    if (IndexCtx.shouldIndexFunctionLocalSymbols())
+    if (IndexCtx.shouldIndexFunctionLocalSymbols()) {
       IndexCtx.indexDeclGroupRef(S->getDeclGroup());
+      return true;
+    }
+
+    DeclGroupRef DG = S->getDeclGroup();
+    for (DeclGroupRef::iterator I = DG.begin(), E = DG.end(); I != E; ++I) {
+      const Decl *D = *I;
+      if (!D)
+        continue;
+      if (!IndexCtx.isFunctionLocalDecl(D))
+        IndexCtx.indexTopLevelDecl(D);
+    }
+
     return true;
   }
 

Modified: cfe/trunk/tools/libclang/IndexDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/IndexDecl.cpp?rev=163563&r1=163562&r2=163563&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/IndexDecl.cpp (original)
+++ cfe/trunk/tools/libclang/IndexDecl.cpp Mon Sep 10 17:58:04 2012
@@ -325,7 +325,7 @@
   }
 }
 
-void IndexingContext::indexTopLevelDecl(Decl *D) {
+void IndexingContext::indexTopLevelDecl(const Decl *D) {
   if (isNotFromSourceFile(D->getLocation()))
     return;
 

Modified: cfe/trunk/tools/libclang/IndexingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/IndexingContext.cpp?rev=163563&r1=163562&r2=163563&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/IndexingContext.cpp (original)
+++ cfe/trunk/tools/libclang/IndexingContext.cpp Mon Sep 10 17:58:04 2012
@@ -204,6 +204,26 @@
   static_cast<ASTUnit*>(CXTU->TUData)->setPreprocessor(&PP);
 }
 
+bool IndexingContext::isFunctionLocalDecl(const Decl *D) {
+  assert(D);
+
+  if (!D->getParentFunctionOrMethod())
+    return false;
+
+  if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
+    switch (ND->getLinkage()) {
+    case NoLinkage:
+    case InternalLinkage:
+      return true;
+    case UniqueExternalLinkage:
+    case ExternalLinkage:
+      return false;
+    }
+  }
+
+  return true;
+}
+
 bool IndexingContext::shouldAbort() {
   if (!CB.abortQuery)
     return false;
@@ -590,7 +610,7 @@
     return false;
   if (Loc.isInvalid())
     return false;
-  if (!shouldIndexFunctionLocalSymbols() && D->getParentFunctionOrMethod())
+  if (!shouldIndexFunctionLocalSymbols() && isFunctionLocalDecl(D))
     return false;
   if (isNotFromSourceFile(D->getLocation()))
     return false;

Modified: cfe/trunk/tools/libclang/IndexingContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/IndexingContext.h?rev=163563&r1=163562&r2=163563&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/IndexingContext.h (original)
+++ cfe/trunk/tools/libclang/IndexingContext.h Mon Sep 10 17:58:04 2012
@@ -370,6 +370,8 @@
     return IndexOptions & CXIndexOpt_IndexImplicitTemplateInstantiations;
   }
 
+  static bool isFunctionLocalDecl(const Decl *D);
+
   bool shouldAbort();
 
   bool hasDiagnosticCallback() const { return CB.diagnostic; }
@@ -451,7 +453,7 @@
 
   bool isNotFromSourceFile(SourceLocation Loc) const;
 
-  void indexTopLevelDecl(Decl *D);
+  void indexTopLevelDecl(const Decl *D);
   void indexTUDeclsInObjCContainer();
   void indexDeclGroupRef(DeclGroupRef DG);
 





More information about the cfe-commits mailing list