forked from OSchip/llvm-project
[libclang] Do index 'extern' declarations inside functions.
rdar://12257073 llvm-svn: 163563
This commit is contained in:
parent
5446f4dfb1
commit
68e87e1360
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue