aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/Index/index-decls.m13
-rw-r--r--tools/libclang/IndexBody.cpp14
-rw-r--r--tools/libclang/IndexDecl.cpp2
-rw-r--r--tools/libclang/IndexingContext.cpp22
-rw-r--r--tools/libclang/IndexingContext.h4
5 files changed, 51 insertions, 4 deletions
diff --git a/test/Index/index-decls.m b/test/Index/index-decls.m
index 46d37c4345..c6b14bb8fd 100644
--- a/test/Index/index-decls.m
+++ b/test/Index/index-decls.m
@@ -26,6 +26,13 @@ __attribute__((something)) @interface I2 @end
}
@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 @@ __attribute__((something)) @interface I2 @end
// 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
diff --git a/tools/libclang/IndexBody.cpp b/tools/libclang/IndexBody.cpp
index acf8838940..3614206dee 100644
--- a/tools/libclang/IndexBody.cpp
+++ b/tools/libclang/IndexBody.cpp
@@ -130,8 +130,20 @@ public:
}
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;
}
diff --git a/tools/libclang/IndexDecl.cpp b/tools/libclang/IndexDecl.cpp
index 4c78f5e1b5..53a98f111c 100644
--- a/tools/libclang/IndexDecl.cpp
+++ b/tools/libclang/IndexDecl.cpp
@@ -325,7 +325,7 @@ void IndexingContext::indexDeclContext(const DeclContext *DC) {
}
}
-void IndexingContext::indexTopLevelDecl(Decl *D) {
+void IndexingContext::indexTopLevelDecl(const Decl *D) {
if (isNotFromSourceFile(D->getLocation()))
return;
diff --git a/tools/libclang/IndexingContext.cpp b/tools/libclang/IndexingContext.cpp
index 6e1b04df57..210dc36d52 100644
--- a/tools/libclang/IndexingContext.cpp
+++ b/tools/libclang/IndexingContext.cpp
@@ -204,6 +204,26 @@ void IndexingContext::setPreprocessor(Preprocessor &PP) {
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 @@ bool IndexingContext::handleReference(const NamedDecl *D, SourceLocation Loc,
return false;
if (Loc.isInvalid())
return false;
- if (!shouldIndexFunctionLocalSymbols() && D->getParentFunctionOrMethod())
+ if (!shouldIndexFunctionLocalSymbols() && isFunctionLocalDecl(D))
return false;
if (isNotFromSourceFile(D->getLocation()))
return false;
diff --git a/tools/libclang/IndexingContext.h b/tools/libclang/IndexingContext.h
index 00e109644c..ef5ed07e36 100644
--- a/tools/libclang/IndexingContext.h
+++ b/tools/libclang/IndexingContext.h
@@ -370,6 +370,8 @@ public:
return IndexOptions & CXIndexOpt_IndexImplicitTemplateInstantiations;
}
+ static bool isFunctionLocalDecl(const Decl *D);
+
bool shouldAbort();
bool hasDiagnosticCallback() const { return CB.diagnostic; }
@@ -451,7 +453,7 @@ public:
bool isNotFromSourceFile(SourceLocation Loc) const;
- void indexTopLevelDecl(Decl *D);
+ void indexTopLevelDecl(const Decl *D);
void indexTUDeclsInObjCContainer();
void indexDeclGroupRef(DeclGroupRef DG);