aboutsummaryrefslogtreecommitdiff
path: root/tools/libclang/IndexingContext.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-11-12 02:16:30 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-11-12 02:16:30 +0000
commit6ec43adc39006a7fce94188956d0239bd54c0363 (patch)
tree76689d6b1d0528535ca34a1e44005a1f9fdba94e /tools/libclang/IndexingContext.cpp
parent23d29c861f2770fe9f99ba80cca2e7cf4ac675ea (diff)
[libclang] Further simplify the indexing API.
That stuff can be added later on if we need them. Also add some const goodness. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144446 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/libclang/IndexingContext.cpp')
-rw-r--r--tools/libclang/IndexingContext.cpp269
1 files changed, 86 insertions, 183 deletions
diff --git a/tools/libclang/IndexingContext.cpp b/tools/libclang/IndexingContext.cpp
index 3d3277210e..d612a3b213 100644
--- a/tools/libclang/IndexingContext.cpp
+++ b/tools/libclang/IndexingContext.cpp
@@ -18,6 +18,30 @@ using namespace clang;
using namespace cxindex;
using namespace cxcursor;
+IndexingContext::ObjCProtocolListInfo::ObjCProtocolListInfo(
+ const ObjCProtocolList &ProtList,
+ IndexingContext &IdxCtx,
+ StrAdapter &SA) {
+ ObjCInterfaceDecl::protocol_loc_iterator LI = ProtList.loc_begin();
+ for (ObjCInterfaceDecl::protocol_iterator
+ I = ProtList.begin(), E = ProtList.end(); I != E; ++I, ++LI) {
+ SourceLocation Loc = *LI;
+ ObjCProtocolDecl *PD = *I;
+ ProtEntities.push_back(CXIdxEntityInfo());
+ IdxCtx.getEntityInfo(PD, ProtEntities.back(), SA);
+ CXIdxObjCProtocolRefInfo ProtInfo = { 0,
+ MakeCursorObjCProtocolRef(PD, Loc, IdxCtx.CXTU),
+ IdxCtx.getIndexLoc(Loc) };
+ ProtInfos.push_back(ProtInfo);
+ }
+
+ for (unsigned i = 0, e = ProtInfos.size(); i != e; ++i)
+ ProtInfos[i].protocol = &ProtEntities[i];
+
+ for (unsigned i = 0, e = ProtInfos.size(); i != e; ++i)
+ Prots.push_back(&ProtInfos[i]);
+}
+
const char *IndexingContext::StrAdapter::toCStr(StringRef Str) {
if (Str.empty())
return "";
@@ -56,53 +80,13 @@ void IndexingContext::ppIncludedFile(SourceLocation hashLoc,
FileMap[File] = idxFile;
}
-void IndexingContext::ppMacroDefined(SourceLocation Loc, StringRef Name,
- SourceLocation DefBegin, unsigned Length,
- const void *OpaqueMacro) {
- if (!CB.ppMacroDefined)
- return;
-
- StrAdapter SA(*this);
- CXIdxMacroInfo MacroInfo = { getIndexLoc(Loc), SA.toCStr(Name) };
- CXIdxMacroDefinedInfo Info = { &MacroInfo,
- getIndexLoc(DefBegin), Length };
- CXIdxClientMacro idxMacro = CB.ppMacroDefined(ClientData, &Info);
- MacroMap[OpaqueMacro] = idxMacro;
-}
-
-void IndexingContext::ppMacroUndefined(SourceLocation Loc, StringRef Name,
- const void *OpaqueMacro) {
- if (!CB.ppMacroUndefined)
- return;
-
- StrAdapter SA(*this);
- CXIdxMacroUndefinedInfo Info = { getIndexLoc(Loc),
- SA.toCStr(Name), 0 };
- CB.ppMacroUndefined(ClientData, &Info);
-}
-
-void IndexingContext::ppMacroExpanded(SourceLocation Loc, StringRef Name,
- const void *OpaqueMacro) {
- if (!CB.ppMacroExpanded)
- return;
-
- StrAdapter SA(*this);
- CXIdxMacroExpandedInfo Info = { getIndexLoc(Loc),
- SA.toCStr(Name), 0 };
- CB.ppMacroExpanded(ClientData, &Info);
-}
-
-void IndexingContext::invokeStartedTranslationUnit() {
+void IndexingContext::startedTranslationUnit() {
CXIdxClientContainer idxCont = 0;
if (CB.startedTranslationUnit)
idxCont = CB.startedTranslationUnit(ClientData, 0);
addContainerInMap(Ctx->getTranslationUnitDecl(), idxCont);
}
-void IndexingContext::invokeFinishedTranslationUnit() {
- endContainer(Ctx->getTranslationUnitDecl());
-}
-
void IndexingContext::handleDiagnostic(const StoredDiagnostic &StoredDiag) {
if (!CB.diagnostic)
return;
@@ -114,6 +98,7 @@ void IndexingContext::handleDiagnostic(const StoredDiagnostic &StoredDiag) {
void IndexingContext::handleDecl(const NamedDecl *D,
SourceLocation Loc, CXCursor Cursor,
bool isRedeclaration, bool isDefinition,
+ bool isContainer,
DeclInfo &DInfo) {
if (!CB.indexDeclaration)
return;
@@ -127,11 +112,12 @@ void IndexingContext::handleDecl(const NamedDecl *D,
DInfo.isRedeclaration = isRedeclaration;
DInfo.isDefinition = isDefinition;
- CXIdxClientEntity
- clientEnt = CB.indexDeclaration(ClientData, &DInfo);
+ CXIdxClientContainer clientCont = 0;
+ CXIdxDeclOut DeclOut = { isContainer ? &clientCont : 0 };
+ CB.indexDeclaration(ClientData, &DInfo, &DeclOut);
- if (!isRedeclaration)
- addEntityInMap(D, clientEnt);
+ if (isContainer)
+ addContainerInMap(cast<DeclContext>(D), clientCont);
}
void IndexingContext::handleObjCContainer(const ObjCContainerDecl *D,
@@ -140,57 +126,59 @@ void IndexingContext::handleObjCContainer(const ObjCContainerDecl *D,
bool isRedeclaration,
bool isImplementation,
ObjCContainerDeclInfo &ContDInfo) {
- ContDInfo.CXObjCContDeclInfo.declInfo = &ContDInfo;
+ ContDInfo.ObjCContDeclInfo.declInfo = &ContDInfo;
if (isForwardRef)
- ContDInfo.CXObjCContDeclInfo.kind = CXIdxObjCContainer_ForwardRef;
+ ContDInfo.ObjCContDeclInfo.kind = CXIdxObjCContainer_ForwardRef;
else if (isImplementation)
- ContDInfo.CXObjCContDeclInfo.kind = CXIdxObjCContainer_Implementation;
+ ContDInfo.ObjCContDeclInfo.kind = CXIdxObjCContainer_Implementation;
else
- ContDInfo.CXObjCContDeclInfo.kind = CXIdxObjCContainer_Interface;
+ ContDInfo.ObjCContDeclInfo.kind = CXIdxObjCContainer_Interface;
handleDecl(D, Loc, Cursor,
- isRedeclaration, /*isDefinition=*/!isForwardRef, ContDInfo);
+ isRedeclaration, /*isDefinition=*/!isForwardRef,
+ /*isContainer=*/!isForwardRef, ContDInfo);
}
void IndexingContext::handleFunction(const FunctionDecl *D) {
DeclInfo DInfo;
handleDecl(D, D->getLocation(), getCursor(D),
!D->isFirstDeclaration(), D->isThisDeclarationADefinition(),
- DInfo);
+ D->isThisDeclarationADefinition(), DInfo);
}
void IndexingContext::handleVar(const VarDecl *D) {
DeclInfo DInfo;
handleDecl(D, D->getLocation(), getCursor(D),
!D->isFirstDeclaration(), D->isThisDeclarationADefinition(),
- DInfo);
+ /*isContainer=*/false, DInfo);
}
void IndexingContext::handleField(const FieldDecl *D) {
DeclInfo DInfo;
handleDecl(D, D->getLocation(), getCursor(D),
- /*isRedeclaration=*/false, /*isDefinition=*/false, DInfo);
+ /*isRedeclaration=*/false, /*isDefinition=*/true,
+ /*isContainer=*/false, DInfo);
}
void IndexingContext::handleEnumerator(const EnumConstantDecl *D) {
DeclInfo DInfo;
handleDecl(D, D->getLocation(), getCursor(D),
- /*isRedeclaration=*/false, /*isDefinition=*/true, DInfo);
+ /*isRedeclaration=*/false, /*isDefinition=*/true,
+ /*isContainer=*/false, DInfo);
}
void IndexingContext::handleTagDecl(const TagDecl *D) {
- TagDeclInfo TagDInfo;
- TagDInfo.CXTagDeclInfo.declInfo = &TagDInfo;
- TagDInfo.CXTagDeclInfo.isAnonymous = D->getIdentifier() == 0;
+ DeclInfo DInfo;
handleDecl(D, D->getLocation(), getCursor(D),
!D->isFirstDeclaration(), D->isThisDeclarationADefinition(),
- TagDInfo);
+ D->isThisDeclarationADefinition(), DInfo);
}
void IndexingContext::handleTypedef(const TypedefDecl *D) {
DeclInfo DInfo;
handleDecl(D, D->getLocation(), getCursor(D),
- !D->isFirstDeclaration(), /*isDefinition=*/true, DInfo);
+ !D->isFirstDeclaration(), /*isDefinition=*/true,
+ /*isContainer=*/false, DInfo);
}
void IndexingContext::handleObjCClass(const ObjCClassDecl *D) {
@@ -205,18 +193,38 @@ void IndexingContext::handleObjCClass(const ObjCClassDecl *D) {
}
void IndexingContext::handleObjCInterface(const ObjCInterfaceDecl *D) {
- ObjCContainerDeclInfo ContDInfo;
+ StrAdapter SA(*this);
+
+ CXIdxBaseClassInfo BaseClass;
+ CXIdxEntityInfo BaseEntity;
+ BaseClass.cursor = clang_getNullCursor();
+ if (ObjCInterfaceDecl *SuperD = D->getSuperClass()) {
+ getEntityInfo(SuperD, BaseEntity, SA);
+ SourceLocation SuperLoc = D->getSuperClassLoc();
+ BaseClass.base = &BaseEntity;
+ BaseClass.cursor = MakeCursorObjCSuperClassRef(SuperD, SuperLoc, CXTU);
+ BaseClass.loc = getIndexLoc(SuperLoc);
+ }
+
+ ObjCProtocolListInfo ProtInfo(D->getReferencedProtocols(), *this, SA);
+
+ ObjCInterfaceDeclInfo InterInfo;
+ InterInfo.ObjCInterDeclInfo.declInfo = &InterInfo;
+ InterInfo.ObjCInterDeclInfo.superInfo = D->getSuperClass() ? &BaseClass : 0;
+ InterInfo.ObjCInterDeclInfo.protocols = ProtInfo.getProtocolRefs();
+ InterInfo.ObjCInterDeclInfo.numProtocols = ProtInfo.getNumProtocols();
+
handleObjCContainer(D, D->getLocation(), getCursor(D),
/*isForwardRef=*/false,
/*isRedeclaration=*/D->isInitiallyForwardDecl(),
- /*isImplementation=*/false, ContDInfo);
+ /*isImplementation=*/false, InterInfo);
}
void IndexingContext::handleObjCImplementation(
const ObjCImplementationDecl *D) {
ObjCContainerDeclInfo ContDInfo;
const ObjCInterfaceDecl *Class = D->getClassInterface();
- handleObjCContainer(Class, D->getLocation(), getCursor(D),
+ handleObjCContainer(D, D->getLocation(), getCursor(D),
/*isForwardRef=*/false,
/*isRedeclaration=*/!Class->isImplicitInterfaceDecl(),
/*isImplementation=*/true, ContDInfo);
@@ -233,55 +241,18 @@ void IndexingContext::handleObjCForwardProtocol(const ObjCProtocolDecl *D,
}
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;
-
StrAdapter SA(*this);
- CXIdxObjCBaseClassInfo BaseClass;
- CXIdxEntityInfo BaseEntity;
- if (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;
- ProtEntities.push_back(CXIdxEntityInfo());
- getEntityInfo(PD, ProtEntities.back(), SA);
- CXIdxObjCProtocolRefInfo ProtInfo = { 0, getIndexLoc(Loc) };
- ProtInfos.push_back(ProtInfo);
- }
+ ObjCProtocolListInfo ProtListInfo(D->getReferencedProtocols(), *this, SA);
- for (unsigned i = 0, e = ProtInfos.size(); i != e; ++i)
- ProtInfos[i].protocol = &ProtEntities[i];
+ ObjCProtocolDeclInfo ProtInfo;
+ ProtInfo.ObjCProtoDeclInfo.declInfo = &ProtInfo;
+ ProtInfo.ObjCProtoDeclInfo.protocols = ProtListInfo.getProtocolRefs();
+ ProtInfo.ObjCProtoDeclInfo.numProtocols = ProtListInfo.getNumProtocols();
- 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),
- &ClassEntity,
- getIndexContainerForDC(D),
- D->getSuperClass() ? &BaseClass : 0,
- Prots.data(),
- static_cast<unsigned>(Prots.size()) };
- CB.defineObjCClass(ClientData, &Info);
+ handleObjCContainer(D, D->getLocation(), getCursor(D),
+ /*isForwardRef=*/false,
+ /*isRedeclaration=*/D->isInitiallyForwardDecl(),
+ /*isImplementation=*/false, ProtInfo);
}
void IndexingContext::handleObjCCategory(const ObjCCategoryDecl *D) {
@@ -290,8 +261,8 @@ void IndexingContext::handleObjCCategory(const ObjCCategoryDecl *D) {
StrAdapter SA(*this);
getEntityInfo(D->getClassInterface(), ClassEntity, SA);
- CatDInfo.CXObjCCatDeclInfo.containerInfo = &CatDInfo.CXObjCContDeclInfo;
- CatDInfo.CXObjCCatDeclInfo.objcClass = &ClassEntity;
+ CatDInfo.ObjCCatDeclInfo.containerInfo = &CatDInfo.ObjCContDeclInfo;
+ CatDInfo.ObjCCatDeclInfo.objcClass = &ClassEntity;
handleObjCContainer(D, D->getLocation(), getCursor(D),
/*isForwardRef=*/false,
/*isRedeclaration=*/false,
@@ -305,9 +276,9 @@ void IndexingContext::handleObjCCategoryImpl(const ObjCCategoryImplDecl *D) {
StrAdapter SA(*this);
getEntityInfo(CatD->getClassInterface(), ClassEntity, SA);
- CatDInfo.CXObjCCatDeclInfo.containerInfo = &CatDInfo.CXObjCContDeclInfo;
- CatDInfo.CXObjCCatDeclInfo.objcClass = &ClassEntity;
- handleObjCContainer(CatD, D->getLocation(), getCursor(D),
+ CatDInfo.ObjCCatDeclInfo.containerInfo = &CatDInfo.ObjCContDeclInfo;
+ CatDInfo.ObjCCatDeclInfo.objcClass = &ClassEntity;
+ handleObjCContainer(D, D->getLocation(), getCursor(D),
/*isForwardRef=*/false,
/*isRedeclaration=*/true,
/*isImplementation=*/true, CatDInfo);
@@ -317,14 +288,14 @@ void IndexingContext::handleObjCMethod(const ObjCMethodDecl *D) {
DeclInfo DInfo;
handleDecl(D, D->getLocation(), getCursor(D),
!D->isCanonicalDecl(), D->isThisDeclarationADefinition(),
- DInfo);
+ D->isThisDeclarationADefinition(), DInfo);
}
void IndexingContext::handleObjCProperty(const ObjCPropertyDecl *D) {
DeclInfo DInfo;
handleDecl(D, D->getLocation(), getCursor(D),
/*isRedeclaration=*/false, /*isDefinition=*/false,
- DInfo);
+ /*isContainer=*/false, DInfo);
}
void IndexingContext::handleReference(const NamedDecl *D, SourceLocation Loc,
@@ -356,35 +327,6 @@ void IndexingContext::handleReference(const NamedDecl *D, SourceLocation Loc,
CB.indexEntityReference(ClientData, &Info);
}
-void IndexingContext::startContainer(const NamedDecl *D, bool isStmtBody,
- const DeclContext *DC) {
- if (!CB.startedContainer)
- return;
-
- 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);
-
- CXIdxClientContainer clientCont = CB.startedContainer(ClientData, &Info);
- addContainerInMap(DC, clientCont);
-}
-
-void IndexingContext::endContainer(const DeclContext *DC) {
- if (CB.endedContainer) {
- CXIdxEndContainerInfo Info = { getIndexContainerForDC(DC),
- getIndexLoc(cast<Decl>(DC)->getLocEnd()) };
- CB.endedContainer(ClientData, &Info);
- }
-}
-
bool IndexingContext::isNotFromSourceFile(SourceLocation Loc) const {
if (Loc.isInvalid())
return true;
@@ -411,44 +353,6 @@ void IndexingContext::addContainerInMap(const DeclContext *DC,
ContainerMap.erase(I);
}
-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());
- if (entity || D->isFromASTFile())
- EntityMap[D] = entity;
-}
-
-CXIdxClientEntity IndexingContext::getClientEntity(const NamedDecl *D) {
- if (!D)
- return 0;
- D = getEntityDecl(D);
- EntityMapTy::const_iterator I = EntityMap.find(D);
- if (I != EntityMap.end())
- return I->second;
-
- if (!D->isFromASTFile()) {
- //assert(0 && "Entity not in map");
- return 0;
- }
-
- StrAdapter SA(*this);
-
- CXIdxClientEntity idxEntity = 0;
- if (CB.importedEntity) {
- CXIdxEntityInfo EntityInfo;
- getEntityInfo(D, EntityInfo, SA);
- CXIdxImportedEntityInfo Info = { &EntityInfo,
- getCursor(D),
- getIndexLoc(D->getLocation()),
- /*CXIdxASTFile*/0 };
- idxEntity = CB.importedEntity(ClientData, &Info);
- }
- addEntityInMap(D, idxEntity);
- return idxEntity;
-}
-
const NamedDecl *IndexingContext::getEntityDecl(const NamedDecl *D) const {
assert(D);
D = cast<NamedDecl>(D->getCanonicalDecl());
@@ -554,7 +458,6 @@ void IndexingContext::getEntityInfo(const NamedDecl *D,
StrAdapter &SA) {
D = getEntityDecl(D);
EntityInfo.kind = CXIdxEntity_Unexposed;
- EntityInfo.clientEntity = getClientEntity(D);
if (const TagDecl *TD = dyn_cast<TagDecl>(D)) {
switch (TD->getTagKind()) {