aboutsummaryrefslogtreecommitdiff
path: root/tools/libclang
diff options
context:
space:
mode:
Diffstat (limited to 'tools/libclang')
-rw-r--r--tools/libclang/IndexDecl.cpp67
-rw-r--r--tools/libclang/IndexTypeSourceInfo.cpp4
-rw-r--r--tools/libclang/Indexing.cpp54
-rw-r--r--tools/libclang/IndexingContext.cpp581
-rw-r--r--tools/libclang/IndexingContext.h102
-rw-r--r--tools/libclang/libclang.exports6
6 files changed, 412 insertions, 402 deletions
diff --git a/tools/libclang/IndexDecl.cpp b/tools/libclang/IndexDecl.cpp
index 5cf9f80263..5087355a8d 100644
--- a/tools/libclang/IndexDecl.cpp
+++ b/tools/libclang/IndexDecl.cpp
@@ -29,9 +29,9 @@ public:
if (D->isThisDeclarationADefinition()) {
const Stmt *Body = D->getBody();
if (Body) {
- IndexCtx.invokeStartedStatementBody(D, D);
+ IndexCtx.startContainer(D, /*isBody=*/true);
IndexCtx.indexBody(Body, D);
- IndexCtx.invokeEndedContainer(D);
+ IndexCtx.endContainer(D);
}
}
return true;
@@ -68,15 +68,7 @@ public:
}
bool VisitObjCClassDecl(ObjCClassDecl *D) {
- ObjCClassDecl::ObjCClassRef *Ref = D->getForwardDecl();
- if (Ref->getInterface()->getLocation() == Ref->getLocation()) {
- IndexCtx.handleObjCInterface(Ref->getInterface());
- } else {
- IndexCtx.handleReference(Ref->getInterface(),
- Ref->getLocation(),
- 0,
- Ref->getInterface()->getDeclContext());
- }
+ IndexCtx.handleObjCClass(D);
return true;
}
@@ -87,74 +79,71 @@ public:
SourceLocation Loc = *LI;
ObjCProtocolDecl *PD = *I;
- if (PD->getLocation() == Loc) {
- IndexCtx.handleObjCProtocol(PD);
- } else {
- IndexCtx.handleReference(PD, Loc, 0, PD->getDeclContext());
- }
+ bool isRedeclaration = PD->getLocation() != Loc;
+ IndexCtx.handleObjCForwardProtocol(PD, Loc, isRedeclaration);
}
return true;
}
bool VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
- // Only definitions are handled here.
+ // Forward decls are handled at VisitObjCClassDecl.
if (D->isForwardDecl())
return true;
- if (!D->isInitiallyForwardDecl())
- IndexCtx.handleObjCInterface(D);
+ IndexCtx.handleObjCInterface(D);
IndexCtx.indexTUDeclsInObjCContainer();
- IndexCtx.invokeStartedObjCContainer(D);
+ IndexCtx.startContainer(D);
IndexCtx.defineObjCInterface(D);
IndexCtx.indexDeclContext(D);
- IndexCtx.invokeEndedContainer(D);
+ IndexCtx.endContainer(D);
return true;
}
bool VisitObjCProtocolDecl(ObjCProtocolDecl *D) {
- // Only definitions are handled here.
+ // Forward decls are handled at VisitObjCForwardProtocolDecl.
if (D->isForwardDecl())
return true;
- if (!D->isInitiallyForwardDecl())
- IndexCtx.handleObjCProtocol(D);
+ IndexCtx.handleObjCProtocol(D);
IndexCtx.indexTUDeclsInObjCContainer();
- IndexCtx.invokeStartedObjCContainer(D);
+ IndexCtx.startContainer(D);
IndexCtx.indexDeclContext(D);
- IndexCtx.invokeEndedContainer(D);
+ IndexCtx.endContainer(D);
return true;
}
bool VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
- ObjCInterfaceDecl *Class = D->getClassInterface();
- if (Class->isImplicitInterfaceDecl())
- IndexCtx.handleObjCInterface(Class);
+ IndexCtx.handleObjCImplementation(D);
IndexCtx.indexTUDeclsInObjCContainer();
- IndexCtx.invokeStartedObjCContainer(D);
+ IndexCtx.startContainer(D);
IndexCtx.indexDeclContext(D);
- IndexCtx.invokeEndedContainer(D);
+ IndexCtx.endContainer(D);
return true;
}
bool VisitObjCCategoryDecl(ObjCCategoryDecl *D) {
- if (!D->IsClassExtension())
- IndexCtx.handleObjCCategory(D);
+ IndexCtx.handleObjCCategory(D);
IndexCtx.indexTUDeclsInObjCContainer();
- IndexCtx.invokeStartedObjCContainer(D);
+ IndexCtx.startContainer(D);
IndexCtx.indexDeclContext(D);
- IndexCtx.invokeEndedContainer(D);
+ IndexCtx.endContainer(D);
return true;
}
bool VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
+ if (D->getCategoryDecl()->getLocation().isInvalid())
+ return true;
+
+ IndexCtx.handleObjCCategoryImpl(D);
+
IndexCtx.indexTUDeclsInObjCContainer();
- IndexCtx.invokeStartedObjCContainer(D);
+ IndexCtx.startContainer(D);
IndexCtx.indexDeclContext(D);
- IndexCtx.invokeEndedContainer(D);
+ IndexCtx.endContainer(D);
return true;
}
@@ -168,9 +157,9 @@ public:
if (D->isThisDeclarationADefinition()) {
const Stmt *Body = D->getBody();
if (Body) {
- IndexCtx.invokeStartedStatementBody(D, D);
+ IndexCtx.startContainer(D, /*isBody=*/true);
IndexCtx.indexBody(Body, D);
- IndexCtx.invokeEndedContainer(D);
+ IndexCtx.endContainer(D);
}
}
return true;
diff --git a/tools/libclang/IndexTypeSourceInfo.cpp b/tools/libclang/IndexTypeSourceInfo.cpp
index 63446450f3..bba9dbb6e7 100644
--- a/tools/libclang/IndexTypeSourceInfo.cpp
+++ b/tools/libclang/IndexTypeSourceInfo.cpp
@@ -87,8 +87,8 @@ void IndexingContext::indexTypeLoc(TypeLoc TL,
void IndexingContext::indexTagDecl(const TagDecl *D) {
handleTagDecl(D);
if (D->isThisDeclarationADefinition()) {
- invokeStartedTagTypeDefinition(D);
+ startContainer(D);
indexDeclContext(D);
- invokeEndedContainer(D);
+ endContainer(D);
}
}
diff --git a/tools/libclang/Indexing.cpp b/tools/libclang/Indexing.cpp
index 7f296ae1d1..4bea88f8de 100644
--- a/tools/libclang/Indexing.cpp
+++ b/tools/libclang/Indexing.cpp
@@ -40,10 +40,25 @@ namespace {
class IndexPPCallbacks : public PPCallbacks {
Preprocessor &PP;
IndexingContext &IndexCtx;
+ bool IsMainFileEntered;
public:
IndexPPCallbacks(Preprocessor &PP, IndexingContext &indexCtx)
- : PP(PP), IndexCtx(indexCtx) { }
+ : PP(PP), IndexCtx(indexCtx), IsMainFileEntered(false) { }
+
+ virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason,
+ SrcMgr::CharacteristicKind FileType, FileID PrevFID) {
+ if (IsMainFileEntered)
+ return;
+
+ SourceManager &SM = PP.getSourceManager();
+ SourceLocation MainFileLoc = SM.getLocForStartOfFile(SM.getMainFileID());
+
+ if (Loc == MainFileLoc && Reason == PPCallbacks::EnterFile) {
+ IsMainFileEntered = true;
+ IndexCtx.enteredMainFile(SM.getFileEntryForID(SM.getMainFileID()));
+ }
+ }
virtual void InclusionDirective(SourceLocation HashLoc,
const Token &IncludeTok,
@@ -389,6 +404,41 @@ static void clang_indexTranslationUnit_Impl(void *UserData) {
extern "C" {
+int clang_index_isEntityTagKind(CXIdxEntityKind K) {
+ return CXIdxEntity_Enum <= K && K <= CXIdxEntity_CXXClass;
+}
+
+CXIdxTagDeclInfo *clang_index_getTagDeclInfo(CXIdxDeclInfo *DInfo) {
+ if (clang_index_isEntityTagKind(DInfo->entityInfo->kind))
+ return &static_cast<TagDeclInfo*>(DInfo)->CXTagDeclInfo;
+
+ return 0;
+}
+
+int clang_index_isEntityObjCContainerKind(CXIdxEntityKind K) {
+ return CXIdxEntity_ObjCClass <= K && K <= CXIdxEntity_ObjCCategory;
+}
+
+CXIdxObjCContainerDeclInfo *
+clang_index_getObjCContainerDeclInfo(CXIdxDeclInfo *DInfo) {
+ if (clang_index_isEntityObjCContainerKind(DInfo->entityInfo->kind))
+ return &static_cast<ObjCContainerDeclInfo*>(DInfo)->CXObjCContDeclInfo;
+
+ return 0;
+}
+
+int clang_index_isEntityObjCCategoryKind(CXIdxEntityKind K) {
+ return K == CXIdxEntity_ObjCCategory;
+}
+
+CXIdxObjCCategoryDeclInfo *
+clang_index_getObjCCategoryDeclInfo(CXIdxDeclInfo *DInfo){
+ if (clang_index_isEntityObjCCategoryKind(DInfo->entityInfo->kind))
+ return &static_cast<ObjCCategoryDeclInfo*>(DInfo)->CXObjCCatDeclInfo;
+
+ return 0;
+}
+
int clang_indexTranslationUnit(CXIndex CIdx,
CXClientData client_data,
IndexerCallbacks *index_callbacks,
@@ -445,7 +495,7 @@ int clang_indexTranslationUnit(CXIndex CIdx,
}
void clang_indexLoc_getFileLocation(CXIdxLoc location,
- CXIdxFile *indexFile,
+ CXIdxClientFile *indexFile,
CXFile *file,
unsigned *line,
unsigned *column,
diff --git a/tools/libclang/IndexingContext.cpp b/tools/libclang/IndexingContext.cpp
index 0f00bac948..3d3277210e 100644
--- a/tools/libclang/IndexingContext.cpp
+++ b/tools/libclang/IndexingContext.cpp
@@ -33,6 +33,13 @@ void IndexingContext::setASTContext(ASTContext &ctx) {
static_cast<ASTUnit*>(CXTU->TUData)->setASTContext(&ctx);
}
+void IndexingContext::enteredMainFile(const FileEntry *File) {
+ if (File && CB.enteredMainFile) {
+ CXIdxClientFile idxFile = CB.enteredMainFile(ClientData, (CXFile)File, 0);
+ FileMap[File] = idxFile;
+ }
+}
+
void IndexingContext::ppIncludedFile(SourceLocation hashLoc,
StringRef filename,
const FileEntry *File,
@@ -40,12 +47,13 @@ void IndexingContext::ppIncludedFile(SourceLocation hashLoc,
if (!CB.ppIncludedFile)
return;
- StrAdapter SA(this);
+ StrAdapter SA(*this);
CXIdxIncludedFileInfo Info = { getIndexLoc(hashLoc),
SA.toCStr(filename),
- getIndexFile(File),
+ (CXFile)File,
isImport, isAngled };
- CB.ppIncludedFile(ClientData, &Info);
+ CXIdxClientFile idxFile = CB.ppIncludedFile(ClientData, &Info);
+ FileMap[File] = idxFile;
}
void IndexingContext::ppMacroDefined(SourceLocation Loc, StringRef Name,
@@ -54,11 +62,11 @@ void IndexingContext::ppMacroDefined(SourceLocation Loc, StringRef Name,
if (!CB.ppMacroDefined)
return;
- StrAdapter SA(this);
+ StrAdapter SA(*this);
CXIdxMacroInfo MacroInfo = { getIndexLoc(Loc), SA.toCStr(Name) };
CXIdxMacroDefinedInfo Info = { &MacroInfo,
getIndexLoc(DefBegin), Length };
- CXIdxMacro idxMacro = CB.ppMacroDefined(ClientData, &Info);
+ CXIdxClientMacro idxMacro = CB.ppMacroDefined(ClientData, &Info);
MacroMap[OpaqueMacro] = idxMacro;
}
@@ -67,7 +75,7 @@ void IndexingContext::ppMacroUndefined(SourceLocation Loc, StringRef Name,
if (!CB.ppMacroUndefined)
return;
- StrAdapter SA(this);
+ StrAdapter SA(*this);
CXIdxMacroUndefinedInfo Info = { getIndexLoc(Loc),
SA.toCStr(Name), 0 };
CB.ppMacroUndefined(ClientData, &Info);
@@ -78,21 +86,21 @@ void IndexingContext::ppMacroExpanded(SourceLocation Loc, StringRef Name,
if (!CB.ppMacroExpanded)
return;
- StrAdapter SA(this);
+ StrAdapter SA(*this);
CXIdxMacroExpandedInfo Info = { getIndexLoc(Loc),
SA.toCStr(Name), 0 };
CB.ppMacroExpanded(ClientData, &Info);
}
void IndexingContext::invokeStartedTranslationUnit() {
- CXIdxContainer idxCont = 0;
+ CXIdxClientContainer idxCont = 0;
if (CB.startedTranslationUnit)
idxCont = CB.startedTranslationUnit(ClientData, 0);
addContainerInMap(Ctx->getTranslationUnitDecl(), idxCont);
}
void IndexingContext::invokeFinishedTranslationUnit() {
- invokeEndedContainer(Ctx->getTranslationUnitDecl());
+ endContainer(Ctx->getTranslationUnitDecl());
}
void IndexingContext::handleDiagnostic(const StoredDiagnostic &StoredDiag) {
@@ -103,197 +111,172 @@ void IndexingContext::handleDiagnostic(const StoredDiagnostic &StoredDiag) {
CB.diagnostic(ClientData, &CXDiag, 0);
}
-void IndexingContext::handleFunction(const FunctionDecl *D) {
- StrAdapter SA(this);
-
- if (D->isFirstDeclaration()) {
- CXIdxEntity idxEntity = 0;
- if (CB.indexFunction) {
- CXIdxEntityInfo EntityInfo;
- CXIdxIndexedDeclInfo DeclInfo;
- CXIdxIndexedEntityInfo IdxEntityInfo;
- getIndexedEntityInfo(D, IdxEntityInfo, EntityInfo, DeclInfo, SA);
- CXIdxFunctionInfo Info = { &IdxEntityInfo,
- D->isThisDeclarationADefinition() };
-
- idxEntity = CB.indexFunction(ClientData, &Info);
- }
+void IndexingContext::handleDecl(const NamedDecl *D,
+ SourceLocation Loc, CXCursor Cursor,
+ bool isRedeclaration, bool isDefinition,
+ DeclInfo &DInfo) {
+ if (!CB.indexDeclaration)
+ return;
- addEntityInMap(D, idxEntity);
+ StrAdapter SA(*this);
+ getEntityInfo(D, DInfo.CXEntInfo, SA);
+ DInfo.entityInfo = &DInfo.CXEntInfo;
+ DInfo.cursor = Cursor;
+ DInfo.loc = getIndexLoc(Loc);
+ DInfo.container = getIndexContainer(D);
+ DInfo.isRedeclaration = isRedeclaration;
+ DInfo.isDefinition = isDefinition;
+
+ CXIdxClientEntity
+ clientEnt = CB.indexDeclaration(ClientData, &DInfo);
+
+ if (!isRedeclaration)
+ addEntityInMap(D, clientEnt);
+}
+
+void IndexingContext::handleObjCContainer(const ObjCContainerDecl *D,
+ SourceLocation Loc, CXCursor Cursor,
+ bool isForwardRef,
+ bool isRedeclaration,
+ bool isImplementation,
+ ObjCContainerDeclInfo &ContDInfo) {
+ ContDInfo.CXObjCContDeclInfo.declInfo = &ContDInfo;
+ if (isForwardRef)
+ ContDInfo.CXObjCContDeclInfo.kind = CXIdxObjCContainer_ForwardRef;
+ else if (isImplementation)
+ ContDInfo.CXObjCContDeclInfo.kind = CXIdxObjCContainer_Implementation;
+ else
+ ContDInfo.CXObjCContDeclInfo.kind = CXIdxObjCContainer_Interface;
- } else {
- if (CB.indexFunctionRedeclaration) {
- CXIdxIndexedDeclInfo DeclInfo;
- CXIdxIndexedRedeclInfo RedeclInfo;
- getIndexedRedeclInfo(D, RedeclInfo, DeclInfo);
- CXIdxFunctionRedeclInfo Info = { &RedeclInfo,
- D->isThisDeclarationADefinition() };
-
- CB.indexFunctionRedeclaration(ClientData, &Info);
- }
- }
+ handleDecl(D, Loc, Cursor,
+ isRedeclaration, /*isDefinition=*/!isForwardRef, ContDInfo);
}
-void IndexingContext::handleVar(const VarDecl *D) {
- StrAdapter SA(this);
-
- if (D->isFirstDeclaration()) {
- CXIdxEntity idxEntity = 0;
- if (CB.indexVariable) {
- CXIdxEntityInfo EntityInfo;
- CXIdxIndexedDeclInfo DeclInfo;
- CXIdxIndexedEntityInfo IdxEntityInfo;
- getIndexedEntityInfo(D, IdxEntityInfo, EntityInfo, DeclInfo, SA);
- CXIdxVariableInfo Info = { &IdxEntityInfo,
- D->isThisDeclarationADefinition() };
-
- idxEntity = CB.indexVariable(ClientData, &Info);
- }
-
- addEntityInMap(D, idxEntity);
+void IndexingContext::handleFunction(const FunctionDecl *D) {
+ DeclInfo DInfo;
+ handleDecl(D, D->getLocation(), getCursor(D),
+ !D->isFirstDeclaration(), D->isThisDeclarationADefinition(),
+ DInfo);
+}
- } else {
- if (CB.indexVariableRedeclaration) {
- CXIdxIndexedDeclInfo DeclInfo;
- CXIdxIndexedRedeclInfo RedeclInfo;
- getIndexedRedeclInfo(D, RedeclInfo, DeclInfo);
- CXIdxVariableRedeclInfo Info = { &RedeclInfo,
- D->isThisDeclarationADefinition() };
-
- CB.indexVariableRedeclaration(ClientData, &Info);
- }
- }
+void IndexingContext::handleVar(const VarDecl *D) {
+ DeclInfo DInfo;
+ handleDecl(D, D->getLocation(), getCursor(D),
+ !D->isFirstDeclaration(), D->isThisDeclarationADefinition(),
+ DInfo);
}
void IndexingContext::handleField(const FieldDecl *D) {
- StrAdapter SA(this);
-
- CXIdxEntity idxEntity = 0;
- if (CB.indexTypedef) {
- CXIdxEntityInfo EntityInfo;
- CXIdxIndexedDeclInfo DeclInfo;
- CXIdxIndexedEntityInfo IdxEntityInfo;
- getIndexedEntityInfo(D, IdxEntityInfo, EntityInfo, DeclInfo, SA);
- CXIdxFieldInfo Info = { &IdxEntityInfo };
-
- idxEntity = CB.indexField(ClientData, &Info);
- }
-
- addEntityInMap(D, idxEntity);
+ DeclInfo DInfo;
+ handleDecl(D, D->getLocation(), getCursor(D),
+ /*isRedeclaration=*/false, /*isDefinition=*/false, DInfo);
}
void IndexingContext::handleEnumerator(const EnumConstantDecl *D) {
- StrAdapter SA(this);
-
- CXIdxEntity idxEntity = 0;
- if (CB.indexTypedef) {
- CXIdxEntityInfo EntityInfo;
- CXIdxIndexedDeclInfo DeclInfo;
- CXIdxIndexedEntityInfo IdxEntityInfo;
- getIndexedEntityInfo(D, IdxEntityInfo, EntityInfo, DeclInfo, SA);
- CXIdxEnumeratorInfo Info = { &IdxEntityInfo };
-
- idxEntity = CB.indexEnumerator(ClientData, &Info);
- }
-
- addEntityInMap(D, idxEntity);
+ DeclInfo DInfo;
+ handleDecl(D, D->getLocation(), getCursor(D),
+ /*isRedeclaration=*/false, /*isDefinition=*/true, DInfo);
}
void IndexingContext::handleTagDecl(const TagDecl *D) {
- StrAdapter SA(this);
-
- if (D->isFirstDeclaration()) {
- CXIdxEntity idxEntity = 0;
- if (CB.indexTagType) {
- CXIdxEntityInfo EntityInfo;
- CXIdxIndexedDeclInfo DeclInfo;
- CXIdxIndexedEntityInfo IdxEntityInfo;
- getIndexedEntityInfo(D, IdxEntityInfo, EntityInfo, DeclInfo, SA);
- CXIdxTagTypeInfo Info = { &IdxEntityInfo,
- D->isThisDeclarationADefinition(),
- D->getIdentifier() == 0};
-
- idxEntity = CB.indexTagType(ClientData, &Info);
- }
-
- addEntityInMap(D, idxEntity);
-
- } else {
- if (CB.indexTagTypeRedeclaration) {
- CXIdxIndexedDeclInfo DeclInfo;
- CXIdxIndexedRedeclInfo RedeclInfo;
- getIndexedRedeclInfo(D, RedeclInfo, DeclInfo);
- CXIdxTagTypeRedeclInfo Info = { &RedeclInfo,
- D->isThisDeclarationADefinition() };
-
- CB.indexTagTypeRedeclaration(ClientData, &Info);
- }
- }
+ TagDeclInfo TagDInfo;
+ TagDInfo.CXTagDeclInfo.declInfo = &TagDInfo;
+ TagDInfo.CXTagDeclInfo.isAnonymous = D->getIdentifier() == 0;
+ handleDecl(D, D->getLocation(), getCursor(D),
+ !D->isFirstDeclaration(), D->isThisDeclarationADefinition(),
+ TagDInfo);
}
void IndexingContext::handleTypedef(const TypedefDecl *D) {
- StrAdapter SA(this);
-
- CXIdxEntity idxEntity = 0;
- if (CB.indexTypedef) {
- CXIdxEntityInfo EntityInfo;
- CXIdxIndexedDeclInfo DeclInfo;
- CXIdxIndexedEntityInfo IdxEntityInfo;
- getIndexedEntityInfo(D, IdxEntityInfo, EntityInfo, DeclInfo, SA);
- CXIdxTypedefInfo Info = { &IdxEntityInfo };
-
- idxEntity = CB.indexTypedef(ClientData, &Info);
- }
+ DeclInfo DInfo;
+ handleDecl(D, D->getLocation(), getCursor(D),
+ !D->isFirstDeclaration(), /*isDefinition=*/true, DInfo);
+}
- addEntityInMap(D, idxEntity);
+void IndexingContext::handleObjCClass(const ObjCClassDecl *D) {
+ ObjCContainerDeclInfo ContDInfo;
+ const ObjCClassDecl::ObjCClassRef *Ref = D->getForwardDecl();
+ ObjCInterfaceDecl *IFaceD = Ref->getInterface();
+ SourceLocation Loc = Ref->getLocation();
+ bool isRedeclaration = IFaceD->getLocation() != Loc;
+ handleObjCContainer(IFaceD, Loc, MakeCursorObjCClassRef(IFaceD, Loc, CXTU),
+ /*isForwardRef=*/true, isRedeclaration,
+ /*isImplementation=*/false, ContDInfo);
}
void IndexingContext::handleObjCInterface(const ObjCInterfaceDecl *D) {
- StrAdapter SA(this);
+ ObjCContainerDeclInfo ContDInfo;
+ handleObjCContainer(D, D->getLocation(), getCursor(D),
+ /*isForwardRef=*/false,
+ /*isRedeclaration=*/D->isInitiallyForwardDecl(),
+ /*isImplementation=*/false, ContDInfo);
+}
- CXIdxEntity idxEntity = 0;
- if (CB.indexObjCClass) {
- CXIdxEntityInfo EntityInfo;
- CXIdxIndexedDeclInfo DeclInfo;
- CXIdxIndexedEntityInfo IdxEntityInfo;
- getIndexedEntityInfo(D, IdxEntityInfo, EntityInfo, DeclInfo, SA);
- CXIdxObjCClassInfo Info = { &IdxEntityInfo,
- D->isForwardDecl() };
+void IndexingContext::handleObjCImplementation(
+ const ObjCImplementationDecl *D) {
+ ObjCContainerDeclInfo ContDInfo;
+ const ObjCInterfaceDecl *Class = D->getClassInterface();
+ handleObjCContainer(Class, D->getLocation(), getCursor(D),
+ /*isForwardRef=*/false,
+ /*isRedeclaration=*/!Class->isImplicitInterfaceDecl(),
+ /*isImplementation=*/true, ContDInfo);
+}
- idxEntity = CB.indexObjCClass(ClientData, &Info);
- }
+void IndexingContext::handleObjCForwardProtocol(const ObjCProtocolDecl *D,
+ SourceLocation Loc,
+ bool isRedeclaration) {
+ ObjCContainerDeclInfo ContDInfo;
+ handleObjCContainer(D, Loc, MakeCursorObjCProtocolRef(D, Loc, CXTU),
+ /*isForwardRef=*/true,
+ isRedeclaration,
+ /*isImplementation=*/false, ContDInfo);
+}
- addEntityInMap(D, idxEntity);
+void IndexingContext::handleObjCProtocol(const ObjCProtocolDecl *D) {
+ ObjCContainerDeclInfo ContDInfo;
+ handleObjCContainer(D, D->getLocation(), getCursor(D),
+ /*isForwardRef=*/false,
+ /*isRedeclaration=*/D->isInitiallyForwardDecl(),
+ /*isImplementation=*/false, ContDInfo);
}
void IndexingContext::defineObjCInterface(const ObjCInterfaceDecl *D) {
if (!CB.defineObjCClass)
return;
- CXIdxObjCBaseClassInfo BaseClass = { getIndexEntity(D->getSuperClass()),
- getIndexLoc(D->getSuperClassLoc()) };
+ StrAdapter SA(*this);
+ CXIdxObjCBaseClassInfo BaseClass;
+ CXIdxEntityInfo BaseEntity;
if (D->getSuperClass()) {
- BaseClass.objcClass = getIndexEntity(D->getSuperClass());
+ getEntityInfo(D->getSuperClass(), BaseEntity, SA);
+ BaseClass.objcClass = &BaseEntity;
BaseClass.loc = getIndexLoc(D->getSuperClassLoc());
}
-
+
SmallVector<CXIdxObjCProtocolRefInfo, 4> ProtInfos;
+ SmallVector<CXIdxEntityInfo, 4> ProtEntities;
ObjCInterfaceDecl::protocol_loc_iterator LI = D->protocol_loc_begin();
for (ObjCInterfaceDecl::protocol_iterator
I = D->protocol_begin(), E = D->protocol_end(); I != E; ++I, ++LI) {
SourceLocation Loc = *LI;
ObjCProtocolDecl *PD = *I;
- CXIdxObjCProtocolRefInfo ProtInfo = { getIndexEntity(PD),
- getIndexLoc(Loc) };
+ ProtEntities.push_back(CXIdxEntityInfo());
+ getEntityInfo(PD, ProtEntities.back(), SA);
+ CXIdxObjCProtocolRefInfo ProtInfo = { 0, getIndexLoc(Loc) };
ProtInfos.push_back(ProtInfo);
}
+
+ for (unsigned i = 0, e = ProtInfos.size(); i != e; ++i)
+ ProtInfos[i].protocol = &ProtEntities[i];
SmallVector<CXIdxObjCProtocolRefInfo *, 4> Prots;
for (unsigned i = 0, e = Prots.size(); i != e; ++i)
Prots.push_back(&ProtInfos[i]);
+ CXIdxEntityInfo ClassEntity;
+ getEntityInfo(D, ClassEntity, SA);
CXIdxObjCClassDefineInfo Info = { getCursor(D),
- getIndexEntity(D),
+ &ClassEntity,
getIndexContainerForDC(D),
D->getSuperClass() ? &BaseClass : 0,
Prots.data(),
@@ -301,88 +284,47 @@ void IndexingContext::defineObjCInterface(const ObjCInterfaceDecl *D) {
CB.defineObjCClass(ClientData, &Info);
}
-void IndexingContext::handleObjCProtocol(const ObjCProtocolDecl *D) {
- StrAdapter SA(this);
-
- CXIdxEntity idxEntity = 0;
- if (CB.indexObjCProtocol) {
- CXIdxEntityInfo EntityInfo;
- CXIdxIndexedDeclInfo DeclInfo;
- CXIdxIndexedEntityInfo IdxEntityInfo;
- getIndexedEntityInfo(D, IdxEntityInfo, EntityInfo, DeclInfo, SA);
- CXIdxObjCProtocolInfo Info = { &IdxEntityInfo,
- D->isForwardDecl() };
-
- idxEntity = CB.indexObjCProtocol(ClientData, &Info);
- }
-
- addEntityInMap(D, idxEntity);
-}
-
void IndexingContext::handleObjCCategory(const ObjCCategoryDecl *D) {
- StrAdapter SA(this);
-
- CXIdxEntity idxEntity = 0;
- if (CB.indexObjCCategory) {
- CXIdxEntityInfo EntityInfo;
- CXIdxIndexedDeclInfo DeclInfo;
- CXIdxIndexedEntityInfo IdxEntityInfo;
- getIndexedEntityInfo(D, IdxEntityInfo, EntityInfo, DeclInfo, SA);
- CXIdxObjCCategoryInfo Info = { &IdxEntityInfo,
- getIndexEntity(D->getClassInterface()) };
-
- idxEntity = CB.indexObjCCategory(ClientData, &Info);
- }
-
- addEntityInMap(D, idxEntity);
+ ObjCCategoryDeclInfo CatDInfo;
+ CXIdxEntityInfo ClassEntity;
+ StrAdapter SA(*this);
+ getEntityInfo(D->getClassInterface(), ClassEntity, SA);
+
+ CatDInfo.CXObjCCatDeclInfo.containerInfo = &CatDInfo.CXObjCContDeclInfo;
+ CatDInfo.CXObjCCatDeclInfo.objcClass = &ClassEntity;
+ handleObjCContainer(D, D->getLocation(), getCursor(D),
+ /*isForwardRef=*/false,
+ /*isRedeclaration=*/false,
+ /*isImplementation=*/false, CatDInfo);
+}
+
+void IndexingContext::handleObjCCategoryImpl(const ObjCCategoryImplDecl *D) {
+ const ObjCCategoryDecl *CatD = D->getCategoryDecl();
+ ObjCCategoryDeclInfo CatDInfo;
+ CXIdxEntityInfo ClassEntity;
+ StrAdapter SA(*this);
+ getEntityInfo(CatD->getClassInterface(), ClassEntity, SA);
+
+ CatDInfo.CXObjCCatDeclInfo.containerInfo = &CatDInfo.CXObjCContDeclInfo;
+ CatDInfo.CXObjCCatDeclInfo.objcClass = &ClassEntity;
+ handleObjCContainer(CatD, D->getLocation(), getCursor(D),
+ /*isForwardRef=*/false,
+ /*isRedeclaration=*/true,
+ /*isImplementation=*/true, CatDInfo);
}
void IndexingContext::handleObjCMethod(const ObjCMethodDecl *D) {
- StrAdapter SA(this);
-
- if (D->isCanonicalDecl()) {
- CXIdxEntity idxEntity = 0;
- if (CB.indexObjCMethod) {
- CXIdxEntityInfo EntityInfo;
- CXIdxIndexedDeclInfo DeclInfo;
- CXIdxIndexedEntityInfo IdxEntityInfo;
- getIndexedEntityInfo(D, IdxEntityInfo, EntityInfo, DeclInfo, SA);
- CXIdxObjCMethodInfo Info = { &IdxEntityInfo,
- D->isThisDeclarationADefinition() };
-
- idxEntity = CB.indexObjCMethod(ClientData, &Info);
- }
-
- addEntityInMap(D, idxEntity);
-
- } else {
- if (CB.indexObjCMethodRedeclaration) {
- CXIdxIndexedRedeclInfo RedeclInfo;
- CXIdxIndexedDeclInfo DeclInfo;
- getIndexedRedeclInfo(D, RedeclInfo, DeclInfo);
- CXIdxObjCMethodRedeclInfo Info = { &RedeclInfo,
- D->isThisDeclarationADefinition() };
-
- CB.indexObjCMethodRedeclaration(ClientData, &Info);
- }
- }
+ DeclInfo DInfo;
+ handleDecl(D, D->getLocation(), getCursor(D),
+ !D->isCanonicalDecl(), D->isThisDeclarationADefinition(),
+ DInfo);
}
void IndexingContext::handleObjCProperty(const ObjCPropertyDecl *D) {
- StrAdapter SA(this);
-
- CXIdxEntity idxEntity = 0;
- if (CB.indexObjCProperty) {
- CXIdxEntityInfo EntityInfo;
- CXIdxIndexedDeclInfo DeclInfo;
- CXIdxIndexedEntityInfo IdxEntityInfo;
- getIndexedEntityInfo(D, IdxEntityInfo, EntityInfo, DeclInfo, SA);
- CXIdxObjCPropertyInfo Info = { &IdxEntityInfo };
-
- idxEntity = CB.indexObjCProperty(ClientData, &Info);
- }
-
- addEntityInMap(D, idxEntity);
+ DeclInfo DInfo;
+ handleDecl(D, D->getLocation(), getCursor(D),
+ /*isRedeclaration=*/false, /*isDefinition=*/false,
+ DInfo);
}
void IndexingContext::handleReference(const NamedDecl *D, SourceLocation Loc,
@@ -397,61 +339,45 @@ void IndexingContext::handleReference(const NamedDecl *D, SourceLocation Loc,
if (isNotFromSourceFile(D->getLocation()))
return;
+ StrAdapter SA(*this);
CXCursor Cursor = E ? MakeCXCursor(const_cast<Expr*>(E),
const_cast<Decl*>(cast<Decl>(DC)), CXTU)
: getRefCursor(D, Loc);
+ CXIdxEntityInfo RefEntity, ParentEntity;
+ getEntityInfo(D, RefEntity, SA);
+ getEntityInfo(Parent, ParentEntity, SA);
CXIdxEntityRefInfo Info = { Cursor,
getIndexLoc(Loc),
- getIndexEntity(D),
- getIndexEntity(Parent),
+ &RefEntity,
+ &ParentEntity,
getIndexContainerForDC(DC),
Kind };
CB.indexEntityReference(ClientData, &Info);
}
-void IndexingContext::invokeStartedStatementBody(const NamedDecl *D,
- const DeclContext *DC) {
- const Stmt *Body = cast<Decl>(DC)->getBody();
- assert(Body);
-
- CXIdxContainer idxCont = 0;
- if (CB.startedStatementBody) {
- CXIdxContainerInfo ContainerInfo;
- getContainerInfo(D, ContainerInfo);
- CXIdxStmtBodyInfo Info = { &ContainerInfo,
- getIndexLoc(Body->getLocStart()) };
-
- idxCont = CB.startedStatementBody(ClientData, &Info);
- }
- addContainerInMap(DC, idxCont);
-}
-
-void IndexingContext::invokeStartedTagTypeDefinition(const TagDecl *D) {
- CXIdxContainer idxCont = 0;
- if (CB.startedTagTypeDefinition) {
- CXIdxContainerInfo ContainerInfo;
- getContainerInfo(D, ContainerInfo);
- CXIdxTagTypeDefinitionInfo Info = { &ContainerInfo };
-
- idxCont = CB.startedTagTypeDefinition(ClientData, &Info);
- }
- addContainerInMap(D, idxCont);
-}
+void IndexingContext::startContainer(const NamedDecl *D, bool isStmtBody,
+ const DeclContext *DC) {
+ if (!CB.startedContainer)
+ return;
-void IndexingContext::invokeStartedObjCContainer(const ObjCContainerDecl *D) {
- CXIdxContainer idxCont = 0;
- if (CB.startedObjCContainer) {
- CXIdxContainerInfo ContainerInfo;
- getContainerInfo(D, ContainerInfo);
- CXIdxObjCContainerInfo Info = { &ContainerInfo };
+ if (!DC)
+ DC = cast<DeclContext>(D);
+
+ StrAdapter SA(*this);
+ CXIdxEntityInfo Entity;
+ getEntityInfo(D, Entity, SA);
+ CXIdxContainerInfo Info;
+ Info.entity = &Entity;
+ Info.cursor = getCursor(D);
+ Info.loc = getIndexLoc(D->getLocation());
+ Info.isObjCImpl = isa<ObjCImplDecl>(D);
- idxCont = CB.startedObjCContainer(ClientData, &Info);
- }
- addContainerInMap(D, idxCont);
+ CXIdxClientContainer clientCont = CB.startedContainer(ClientData, &Info);
+ addContainerInMap(DC, clientCont);
}
-void IndexingContext::invokeEndedContainer(const DeclContext *DC) {
+void IndexingContext::endContainer(const DeclContext *DC) {
if (CB.endedContainer) {
CXIdxEndContainerInfo Info = { getIndexContainerForDC(DC),
getIndexLoc(cast<Decl>(DC)->getLocEnd()) };
@@ -469,7 +395,7 @@ bool IndexingContext::isNotFromSourceFile(SourceLocation Loc) const {
}
void IndexingContext::addContainerInMap(const DeclContext *DC,
- CXIdxContainer container) {
+ CXIdxClientContainer container) {
assert(getScopedContext(DC) == DC);
ContainerMapTy::iterator I = ContainerMap.find(DC);
if (I == ContainerMap.end()) {
@@ -485,7 +411,8 @@ void IndexingContext::addContainerInMap(const DeclContext *DC,
ContainerMap.erase(I);
}
-void IndexingContext::addEntityInMap(const NamedDecl *D, CXIdxEntity entity) {
+void IndexingContext::addEntityInMap(const NamedDecl *D,
+ CXIdxClientEntity entity) {
assert(getEntityDecl(D) == D &&
"Tried to add a non-entity (canonical) decl");
assert(EntityMap.find(D) == EntityMap.end());
@@ -493,7 +420,7 @@ void IndexingContext::addEntityInMap(const NamedDecl *D, CXIdxEntity entity) {
EntityMap[D] = entity;
}
-CXIdxEntity IndexingContext::getIndexEntity(const NamedDecl *D) {
+CXIdxClientEntity IndexingContext::getClientEntity(const NamedDecl *D) {
if (!D)
return 0;
D = getEntityDecl(D);
@@ -506,9 +433,9 @@ CXIdxEntity IndexingContext::getIndexEntity(const NamedDecl *D) {
return 0;
}
- StrAdapter SA(this);
+ StrAdapter SA(*this);
- CXIdxEntity idxEntity = 0;
+ CXIdxClientEntity idxEntity = 0;
if (CB.importedEntity) {
CXIdxEntityInfo EntityInfo;
getEntityInfo(D, EntityInfo, SA);
@@ -562,7 +489,7 @@ IndexingContext::getScopedContext(const DeclContext *DC) const {
return DC->getRedeclContext();
}
-CXIdxContainer
+CXIdxClientContainer
IndexingContext::getIndexContainerForDC(const DeclContext *DC) const {
DC = getScopedContext(DC);
ContainerMapTy::const_iterator I = ContainerMap.find(DC);
@@ -571,19 +498,15 @@ IndexingContext::getIndexContainerForDC(const DeclContext *DC) const {
return I->second;
}
-CXIdxFile IndexingContext::getIndexFile(const FileEntry *File) {
+CXIdxClientFile IndexingContext::getIndexFile(const FileEntry *File) {
if (!File)
return 0;
- if (!CB.recordFile)
- return 0;
FileMapTy::iterator FI = FileMap.find(File);
if (FI != FileMap.end())
return FI->second;
- CXIdxFile idxFile = CB.recordFile(ClientData, (CXFile)File, 0);
- FileMap[File] = idxFile;
- return idxFile;
+ return 0;
}
CXIdxLoc IndexingContext::getIndexLoc(SourceLocation Loc) const {
@@ -597,7 +520,7 @@ CXIdxLoc IndexingContext::getIndexLoc(SourceLocation Loc) const {
}
void IndexingContext::translateLoc(SourceLocation Loc,
- CXIdxFile *indexFile, CXFile *file,
+ CXIdxClientFile *indexFile, CXFile *file,
unsigned *line, unsigned *column,
unsigned *offset) {
if (Loc.isInvalid())
@@ -626,47 +549,59 @@ void IndexingContext::translateLoc(SourceLocation Loc,
*offset = FileOffset;
}
-void IndexingContext::getIndexedEntityInfo(const NamedDecl *D,
- CXIdxIndexedEntityInfo &IdxEntityInfo,
- CXIdxEntityInfo &EntityInfo,
- CXIdxIndexedDeclInfo &IdxDeclInfo,
- StrAdapter &SA) {
- getEntityInfo(D, EntityInfo, SA);
- getIndexedDeclInfo(D, IdxDeclInfo);
- IdxEntityInfo.entityInfo = &EntityInfo;
- IdxEntityInfo.declInfo = &IdxDeclInfo;
-}
-
-void IndexingContext::getIndexedDeclInfo(const NamedDecl *D,
- CXIdxIndexedDeclInfo &IdxDeclInfo) {
- IdxDeclInfo.cursor = getCursor(D);
- IdxDeclInfo.loc = getIndexLoc(D->getLocation());
- IdxDeclInfo.container = getIndexContainer(D);
-}
-
-void IndexingContext::getIndexedRedeclInfo(const NamedDecl *D,
- CXIdxIndexedRedeclInfo &RedeclInfo,
- CXIdxIndexedDeclInfo &IdxDeclInfo) {
- getIndexedDeclInfo(D, IdxDeclInfo);
- RedeclInfo.declInfo = &IdxDeclInfo;
- RedeclInfo.entity = getIndexEntity(D);
-}
+void IndexingContext::getEntityInfo(const NamedDecl *D,
+ CXIdxEntityInfo &EntityInfo,
+ StrAdapter &SA) {
+ D = getEntityDecl(D);
+ EntityInfo.kind = CXIdxEntity_Unexposed;
+ EntityInfo.clientEntity = getClientEntity(D);
+
+