[cfe-commits] r150517 - in /cfe/trunk: include/clang-c/Index.h test/Index/index-refs.cpp tools/libclang/IndexBody.cpp tools/libclang/IndexDecl.cpp tools/libclang/IndexTypeSourceInfo.cpp tools/libclang/Indexing.cpp tools/libclang/IndexingContext.cpp tools/libclang/IndexingContext.h
Argyrios Kyrtzidis
akyrtzi at gmail.com
Tue Feb 14 14:23:11 PST 2012
Author: akirtzidis
Date: Tue Feb 14 16:23:11 2012
New Revision: 150517
URL: http://llvm.org/viewvc/llvm-project?rev=150517&view=rev
Log:
[libclang] Indexing: only index implicit template instantiations via an opt-in indexing option.
Modified:
cfe/trunk/include/clang-c/Index.h
cfe/trunk/test/Index/index-refs.cpp
cfe/trunk/tools/libclang/IndexBody.cpp
cfe/trunk/tools/libclang/IndexDecl.cpp
cfe/trunk/tools/libclang/IndexTypeSourceInfo.cpp
cfe/trunk/tools/libclang/Indexing.cpp
cfe/trunk/tools/libclang/IndexingContext.cpp
cfe/trunk/tools/libclang/IndexingContext.h
Modified: cfe/trunk/include/clang-c/Index.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=150517&r1=150516&r2=150517&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Tue Feb 14 16:23:11 2012
@@ -4461,7 +4461,13 @@
* \brief Function-local symbols should be indexed. If this is not set
* function-local symbols will be ignored.
*/
- CXIndexOpt_IndexFunctionLocalSymbols = 0x2
+ CXIndexOpt_IndexFunctionLocalSymbols = 0x2,
+
+ /**
+ * \brief Implicit function/class template instantiations should be indexed.
+ * If this is not set, implicit instantiations will be ignored.
+ */
+ CXIndexOpt_IndexImplicitTemplateInstantiations = 0x4
} CXIndexOptFlags;
/**
Modified: cfe/trunk/test/Index/index-refs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/index-refs.cpp?rev=150517&r1=150516&r2=150517&view=diff
==============================================================================
--- cfe/trunk/test/Index/index-refs.cpp (original)
+++ cfe/trunk/test/Index/index-refs.cpp Tue Feb 14 16:23:11 2012
@@ -89,7 +89,12 @@
// CHECK: [indexDeclaration]: kind: c++-class-template | name: TS | {{.*}} | loc: 47:8
// CHECK-NEXT: [indexDeclaration]: kind: struct-template-partial-spec | name: TS | USR: c:@SP>1#T at TS>#t0.0#I | {{.*}} | loc: 50:8
// CHECK-NEXT: [indexDeclaration]: kind: typedef | name: MyInt | USR: c:index-refs.cpp at 593@SP>1#T at TS>#t0.0#I at T@MyInt | {{.*}} | loc: 51:15 | semantic-container: [TS:50:8] | lexical-container: [TS:50:8]
-// CHECK-NEXT: [indexDeclaration]: kind: struct-template-spec | name: TS | USR: c:@S at TS>#I | {{.*}} | loc: 50:8
-// CHECK-NEXT: [indexDeclaration]: kind: typedef | name: MyInt | USR: c:index-refs.cpp at 593@S at TS>#I at T@MyInt | {{.*}} | loc: 51:15 | semantic-container: [TS:50:8] | lexical-container: [TS:50:8]
+/* when indexing implicit instantiations
+ [indexDeclaration]: kind: struct-template-spec | name: TS | USR: c:@S at TS>#I | {{.*}} | loc: 50:8
+ [indexDeclaration]: kind: typedef | name: MyInt | USR: c:index-refs.cpp at 593@S at TS>#I at T@MyInt | {{.*}} | loc: 51:15 | semantic-container: [TS:50:8] | lexical-container: [TS:50:8]
+ */
// CHECK-NEXT: [indexDeclaration]: kind: function | name: foo3
-// CHECK-NEXT: [indexEntityReference]: kind: struct-template-spec | name: TS | USR: c:@S at TS>#I | {{.*}} | loc: 55:3
+/* when indexing implicit instantiations
+ [indexEntityReference]: kind: struct-template-spec | name: TS | USR: c:@S at TS>#I | {{.*}} | loc: 55:3
+*/
+// CHECK-NEXT: [indexEntityReference]: kind: c++-class-template | name: TS | USR: c:@ST>2#T#T at TS | {{.*}} | loc: 55:3
Modified: cfe/trunk/tools/libclang/IndexBody.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/IndexBody.cpp?rev=150517&r1=150516&r2=150517&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/IndexBody.cpp (original)
+++ cfe/trunk/tools/libclang/IndexBody.cpp Tue Feb 14 16:23:11 2012
@@ -97,7 +97,7 @@
}
bool VisitDeclStmt(DeclStmt *S) {
- if (IndexCtx.indexFunctionLocalSymbols())
+ if (IndexCtx.shouldIndexFunctionLocalSymbols())
IndexCtx.indexDeclGroupRef(S->getDeclGroup());
return true;
}
Modified: cfe/trunk/tools/libclang/IndexDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/IndexDecl.cpp?rev=150517&r1=150516&r2=150517&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/IndexDecl.cpp (original)
+++ cfe/trunk/tools/libclang/IndexDecl.cpp Tue Feb 14 16:23:11 2012
@@ -26,7 +26,7 @@
void handleDeclarator(DeclaratorDecl *D, const NamedDecl *Parent = 0) {
if (!Parent) Parent = D;
- if (!IndexCtx.indexFunctionLocalSymbols()) {
+ if (!IndexCtx.shouldIndexFunctionLocalSymbols()) {
IndexCtx.indexTypeSourceInfo(D->getTypeSourceInfo(), Parent);
IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), Parent);
} else {
@@ -245,9 +245,11 @@
bool VisitClassTemplateSpecializationDecl(
ClassTemplateSpecializationDecl *D) {
- // FIXME: Notify subsequent callbacks that info comes from implicit
+ // FIXME: Notify subsequent callbacks if info comes from implicit
// instantiation.
- if (D->isThisDeclarationADefinition())
+ if (D->isThisDeclarationADefinition() &&
+ (IndexCtx.shouldIndexImplicitTemplateInsts() ||
+ !IndexCtx.isTemplateImplicitInstantiation(D)))
IndexCtx.indexTagDecl(D);
return true;
}
Modified: cfe/trunk/tools/libclang/IndexTypeSourceInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/IndexTypeSourceInfo.cpp?rev=150517&r1=150516&r2=150517&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/IndexTypeSourceInfo.cpp (original)
+++ cfe/trunk/tools/libclang/IndexTypeSourceInfo.cpp Tue Feb 14 16:23:11 2012
@@ -73,9 +73,15 @@
bool VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc TL) {
if (const TemplateSpecializationType *T = TL.getTypePtr()) {
- if (CXXRecordDecl *RD = T->getAsCXXRecordDecl())
- IndexCtx.handleReference(RD, TL.getTemplateNameLoc(),
- Parent, ParentDC);
+ if (IndexCtx.shouldIndexImplicitTemplateInsts()) {
+ if (CXXRecordDecl *RD = T->getAsCXXRecordDecl())
+ IndexCtx.handleReference(RD, TL.getTemplateNameLoc(),
+ Parent, ParentDC);
+ } else {
+ if (const TemplateDecl *D = T->getTemplateName().getAsTemplateDecl())
+ IndexCtx.handleReference(D, TL.getTemplateNameLoc(),
+ Parent, ParentDC);
+ }
}
return true;
}
Modified: cfe/trunk/tools/libclang/Indexing.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/Indexing.cpp?rev=150517&r1=150516&r2=150517&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/Indexing.cpp (original)
+++ cfe/trunk/tools/libclang/Indexing.cpp Tue Feb 14 16:23:11 2012
@@ -137,11 +137,17 @@
virtual void HandleInterestingDecl(DeclGroupRef D) {}
virtual void HandleTagDeclDefinition(TagDecl *D) {
+ if (!IndexCtx.shouldIndexImplicitTemplateInsts())
+ return;
+
if (IndexCtx.isTemplateImplicitInstantiation(D))
IndexCtx.indexDecl(D);
}
virtual void HandleCXXImplicitFunctionInstantiation(FunctionDecl *D) {
+ if (!IndexCtx.shouldIndexImplicitTemplateInsts())
+ return;
+
IndexCtx.indexDecl(D);
}
};
@@ -194,7 +200,12 @@
indexDiagnostics(CXTU, IndexCtx);
}
- virtual TranslationUnitKind getTranslationUnitKind() { return TU_Complete; }
+ virtual TranslationUnitKind getTranslationUnitKind() {
+ if (IndexCtx.shouldIndexImplicitTemplateInsts())
+ return TU_Complete;
+ else
+ return TU_Prefix;
+ }
virtual bool hasCodeCompletionSupport() const { return false; }
};
Modified: cfe/trunk/tools/libclang/IndexingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/IndexingContext.cpp?rev=150517&r1=150516&r2=150517&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/IndexingContext.cpp (original)
+++ cfe/trunk/tools/libclang/IndexingContext.cpp Tue Feb 14 16:23:11 2012
@@ -35,7 +35,7 @@
IdxCtx.getIndexLoc(Loc) };
ProtInfos.push_back(ProtInfo);
- if (IdxCtx.suppressRefs())
+ if (IdxCtx.shouldSuppressRefs())
IdxCtx.markEntityOccurrenceInFile(PD, Loc);
}
@@ -265,11 +265,11 @@
ScratchAlloc SA(*this);
getEntityInfo(D, DInfo.EntInfo, SA);
- if ((!indexFunctionLocalSymbols() && !DInfo.EntInfo.USR)
+ if ((!shouldIndexFunctionLocalSymbols() && !DInfo.EntInfo.USR)
|| Loc.isInvalid())
return false;
- if (suppressRefs())
+ if (shouldSuppressRefs())
markEntityOccurrenceInFile(D, Loc);
DInfo.entityInfo = &DInfo.EntInfo;
@@ -357,7 +357,7 @@
bool IndexingContext::handleObjCInterface(const ObjCInterfaceDecl *D) {
// For @class forward declarations, suppress them the same way as references.
if (!D->isThisDeclarationADefinition()) {
- if (suppressRefs() && markEntityOccurrenceInFile(D, D->getLocation()))
+ if (shouldSuppressRefs() && markEntityOccurrenceInFile(D, D->getLocation()))
return false; // already occurred.
// FIXME: This seems like the wrong definition for redeclaration.
@@ -382,7 +382,7 @@
BaseClass.cursor = MakeCursorObjCSuperClassRef(SuperD, SuperLoc, CXTU);
BaseClass.loc = getIndexLoc(SuperLoc);
- if (suppressRefs())
+ if (shouldSuppressRefs())
markEntityOccurrenceInFile(SuperD, SuperLoc);
}
@@ -411,7 +411,7 @@
bool IndexingContext::handleObjCProtocol(const ObjCProtocolDecl *D) {
if (!D->isThisDeclarationADefinition()) {
- if (suppressRefs() && markEntityOccurrenceInFile(D, D->getLocation()))
+ if (shouldSuppressRefs() && markEntityOccurrenceInFile(D, D->getLocation()))
return false; // already occurred.
// FIXME: This seems like the wrong definition for redeclaration.
@@ -448,7 +448,7 @@
: D->getCategoryNameLoc();
getEntityInfo(IFaceD, ClassEntity, SA);
- if (suppressRefs())
+ if (shouldSuppressRefs())
markEntityOccurrenceInFile(IFaceD, ClassLoc);
ObjCProtocolListInfo ProtInfo(D->getReferencedProtocols(), *this, SA);
@@ -479,7 +479,7 @@
SourceLocation CategoryLoc = D->getCategoryNameLoc();
getEntityInfo(IFaceD, ClassEntity, SA);
- if (suppressRefs())
+ if (shouldSuppressRefs())
markEntityOccurrenceInFile(IFaceD, ClassLoc);
CatDInfo.ObjCCatDeclInfo.containerInfo = &CatDInfo.ObjCContDeclInfo;
@@ -573,14 +573,14 @@
return false;
if (Loc.isInvalid())
return false;
- if (!indexFunctionLocalSymbols() && D->getParentFunctionOrMethod())
+ if (!shouldIndexFunctionLocalSymbols() && D->getParentFunctionOrMethod())
return false;
if (isNotFromSourceFile(D->getLocation()))
return false;
if (D->isImplicit() && shouldIgnoreIfImplicit(D))
return false;
- if (suppressRefs()) {
+ if (shouldSuppressRefs()) {
if (markEntityOccurrenceInFile(D, Loc))
return false; // already occurred.
}
@@ -660,7 +660,7 @@
CXXDInfo.CXXClassInfo.bases = BaseList.getBases();
CXXDInfo.CXXClassInfo.numBases = BaseList.getNumBases();
- if (suppressRefs()) {
+ if (shouldSuppressRefs()) {
// Go through bases and mark them as referenced.
for (unsigned i = 0, e = BaseList.getNumBases(); i != e; ++i) {
const CXIdxBaseClassInfo *baseInfo = BaseList.getBases()[i];
Modified: cfe/trunk/tools/libclang/IndexingContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/IndexingContext.h?rev=150517&r1=150516&r2=150517&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/IndexingContext.h (original)
+++ cfe/trunk/tools/libclang/IndexingContext.h Tue Feb 14 16:23:11 2012
@@ -322,14 +322,18 @@
void setASTContext(ASTContext &ctx);
void setPreprocessor(Preprocessor &PP);
- bool suppressRefs() const {
+ bool shouldSuppressRefs() const {
return IndexOptions & CXIndexOpt_SuppressRedundantRefs;
}
- bool indexFunctionLocalSymbols() const {
+ bool shouldIndexFunctionLocalSymbols() const {
return IndexOptions & CXIndexOpt_IndexFunctionLocalSymbols;
}
+ bool shouldIndexImplicitTemplateInsts() const {
+ return IndexOptions & CXIndexOpt_IndexImplicitTemplateInstantiations;
+ }
+
bool shouldAbort();
bool hasDiagnosticCallback() const { return CB.diagnostic; }
More information about the cfe-commits
mailing list