mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-13 19:24:21 +00:00
[libclang] Slight changes to the indexing API and bigger internal changes for it.
llvm-svn: 144577
This commit is contained in:
parent
45110fdf8d
commit
86acd72bd2
@ -4008,14 +4008,15 @@ typedef enum {
|
||||
CXIdxEntity_ObjCProtocol = 7,
|
||||
CXIdxEntity_ObjCCategory = 8,
|
||||
|
||||
CXIdxEntity_ObjCMethod = 9,
|
||||
CXIdxEntity_ObjCProperty = 10,
|
||||
CXIdxEntity_ObjCIvar = 11,
|
||||
CXIdxEntity_ObjCInstanceMethod = 9,
|
||||
CXIdxEntity_ObjCClassMethod = 10,
|
||||
CXIdxEntity_ObjCProperty = 11,
|
||||
CXIdxEntity_ObjCIvar = 12,
|
||||
|
||||
CXIdxEntity_Enum = 12,
|
||||
CXIdxEntity_Struct = 13,
|
||||
CXIdxEntity_Union = 14,
|
||||
CXIdxEntity_CXXClass = 15
|
||||
CXIdxEntity_Enum = 13,
|
||||
CXIdxEntity_Struct = 14,
|
||||
CXIdxEntity_Union = 15,
|
||||
CXIdxEntity_CXXClass = 16
|
||||
|
||||
} CXIdxEntityKind;
|
||||
|
||||
@ -4032,6 +4033,12 @@ typedef struct {
|
||||
CXIdxClientContainer container;
|
||||
int isRedeclaration;
|
||||
int isDefinition;
|
||||
int isContainer;
|
||||
/**
|
||||
* \brief Whether the declaration exists in code or was created implicitly
|
||||
* by the compiler, e.g. implicit objc methods for properties.
|
||||
*/
|
||||
int isImplicit;
|
||||
} CXIdxDeclInfo;
|
||||
|
||||
typedef struct {
|
||||
@ -4067,17 +4074,15 @@ typedef struct {
|
||||
} CXIdxObjCProtocolRefInfo;
|
||||
|
||||
typedef struct {
|
||||
const CXIdxDeclInfo *declInfo;
|
||||
const CXIdxBaseClassInfo *superInfo;
|
||||
const CXIdxObjCProtocolRefInfo *const *protocols;
|
||||
unsigned numProtocols;
|
||||
} CXIdxObjCInterfaceDeclInfo;
|
||||
} CXIdxObjCProtocolRefListInfo;
|
||||
|
||||
typedef struct {
|
||||
const CXIdxDeclInfo *declInfo;
|
||||
const CXIdxObjCProtocolRefInfo *const *protocols;
|
||||
unsigned numProtocols;
|
||||
} CXIdxObjCProtocolDeclInfo;
|
||||
const CXIdxObjCContainerDeclInfo *containerInfo;
|
||||
const CXIdxBaseClassInfo *superInfo;
|
||||
const CXIdxObjCProtocolRefListInfo *protocols;
|
||||
} CXIdxObjCInterfaceDeclInfo;
|
||||
|
||||
/**
|
||||
* \brief Data for \see indexEntityReference callback.
|
||||
@ -4185,8 +4190,8 @@ CINDEX_LINKAGE
|
||||
const CXIdxObjCCategoryDeclInfo *
|
||||
clang_index_getObjCCategoryDeclInfo(const CXIdxDeclInfo *);
|
||||
|
||||
CINDEX_LINKAGE const CXIdxObjCProtocolDeclInfo *
|
||||
clang_index_getObjCProtocolDeclInfo(const CXIdxDeclInfo *);
|
||||
CINDEX_LINKAGE const CXIdxObjCProtocolRefListInfo *
|
||||
clang_index_getObjCProtocolRefListInfo(const CXIdxDeclInfo *);
|
||||
|
||||
/**
|
||||
* \brief Index the given source file and the translation unit corresponding
|
||||
|
@ -1624,7 +1624,8 @@ static const char *getEntityKindString(CXIdxEntityKind kind) {
|
||||
case CXIdxEntity_ObjCClass: return "objc-class";
|
||||
case CXIdxEntity_ObjCProtocol: return "objc-protocol";
|
||||
case CXIdxEntity_ObjCCategory: return "objc-category";
|
||||
case CXIdxEntity_ObjCMethod: return "objc-method";
|
||||
case CXIdxEntity_ObjCInstanceMethod: return "objc-instance-method";
|
||||
case CXIdxEntity_ObjCClassMethod: return "objc-class-method";
|
||||
case CXIdxEntity_ObjCProperty: return "objc-property";
|
||||
case CXIdxEntity_ObjCIvar: return "objc-ivar";
|
||||
case CXIdxEntity_Enum: return "enum";
|
||||
@ -1653,6 +1654,20 @@ static void printEntityInfo(const char *cb,
|
||||
printf(" | USR: %s", info->USR);
|
||||
}
|
||||
|
||||
static void printProtocolList(const CXIdxObjCProtocolRefListInfo *ProtoInfo,
|
||||
CXClientData client_data) {
|
||||
unsigned i;
|
||||
for (i = 0; i < ProtoInfo->numProtocols; ++i) {
|
||||
printEntityInfo(" <protocol>", client_data,
|
||||
ProtoInfo->protocols[i]->protocol);
|
||||
printf(" | cursor: ");
|
||||
PrintCursor(ProtoInfo->protocols[i]->cursor);
|
||||
printf(" | loc: ");
|
||||
printCXIndexLoc(ProtoInfo->protocols[i]->loc);
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void index_diagnostic(CXClientData client_data,
|
||||
CXDiagnostic diag, void *reserved) {
|
||||
CXString str;
|
||||
@ -1717,8 +1732,7 @@ static void index_indexDeclaration(CXClientData client_data,
|
||||
IndexData *index_data;
|
||||
const CXIdxObjCCategoryDeclInfo *CatInfo;
|
||||
const CXIdxObjCInterfaceDeclInfo *InterInfo;
|
||||
const CXIdxObjCProtocolDeclInfo *ProtoInfo;
|
||||
unsigned i;
|
||||
const CXIdxObjCProtocolRefListInfo *ProtoInfo;
|
||||
index_data = (IndexData *)client_data;
|
||||
|
||||
printEntityInfo("[indexDeclaration]", client_data, info->entityInfo);
|
||||
@ -1729,7 +1743,9 @@ static void index_indexDeclaration(CXClientData client_data,
|
||||
printf(" | container: ");
|
||||
printCXIndexContainer(info->container);
|
||||
printf(" | isRedecl: %d", info->isRedeclaration);
|
||||
printf(" | isDef: %d\n", info->isDefinition);
|
||||
printf(" | isDef: %d", info->isDefinition);
|
||||
printf(" | isContainer: %d", info->isContainer);
|
||||
printf(" | isImplicit: %d\n", info->isImplicit);
|
||||
|
||||
if (clang_index_isEntityObjCContainerKind(info->entityInfo->kind)) {
|
||||
const char *kindName = 0;
|
||||
@ -1754,7 +1770,7 @@ static void index_indexDeclaration(CXClientData client_data,
|
||||
|
||||
if ((InterInfo = clang_index_getObjCInterfaceDeclInfo(info))) {
|
||||
if (InterInfo->superInfo) {
|
||||
printEntityInfo(" <ObjCInterfaceInfo>: base", client_data,
|
||||
printEntityInfo(" <base>", client_data,
|
||||
InterInfo->superInfo->base);
|
||||
printf(" | cursor: ");
|
||||
PrintCursor(InterInfo->superInfo->cursor);
|
||||
@ -1762,27 +1778,10 @@ static void index_indexDeclaration(CXClientData client_data,
|
||||
printCXIndexLoc(InterInfo->superInfo->loc);
|
||||
printf("\n");
|
||||
}
|
||||
for (i = 0; i < InterInfo->numProtocols; ++i) {
|
||||
printEntityInfo(" <ObjCInterfaceInfo>: protocol", client_data,
|
||||
InterInfo->protocols[i]->protocol);
|
||||
printf(" | cursor: ");
|
||||
PrintCursor(InterInfo->protocols[i]->cursor);
|
||||
printf(" | loc: ");
|
||||
printCXIndexLoc(InterInfo->protocols[i]->loc);
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
if ((ProtoInfo = clang_index_getObjCProtocolDeclInfo(info))) {
|
||||
for (i = 0; i < ProtoInfo->numProtocols; ++i) {
|
||||
printEntityInfo(" <ObjCProtocolInfo>: protocol", client_data,
|
||||
ProtoInfo->protocols[i]->protocol);
|
||||
printf(" | cursor: ");
|
||||
PrintCursor(ProtoInfo->protocols[i]->cursor);
|
||||
printf(" | loc: ");
|
||||
printCXIndexLoc(ProtoInfo->protocols[i]->loc);
|
||||
printf("\n");
|
||||
}
|
||||
if ((ProtoInfo = clang_index_getObjCProtocolRefListInfo(info))) {
|
||||
printProtocolList(ProtoInfo, client_data);
|
||||
}
|
||||
|
||||
if (outData->outContainer)
|
||||
@ -1799,7 +1798,7 @@ static void index_indexEntityReference(CXClientData client_data,
|
||||
printEntityInfo(" | <parent>:", client_data, info->parentEntity);
|
||||
printf(" | container: ");
|
||||
printCXIndexContainer(info->container);
|
||||
printf(" | kind: ");
|
||||
printf(" | refkind: ");
|
||||
switch (info->kind) {
|
||||
case CXIdxEntityRef_Direct: printf("direct"); break;
|
||||
case CXIdxEntityRef_ImplicitProperty: printf("implicit prop"); break;
|
||||
|
@ -381,46 +381,56 @@ clang_index_getObjCContainerDeclInfo(const CXIdxDeclInfo *DInfo) {
|
||||
if (!DInfo)
|
||||
return 0;
|
||||
|
||||
if (clang_index_isEntityObjCContainerKind(DInfo->entityInfo->kind))
|
||||
return &static_cast<const ObjCContainerDeclInfo*>(DInfo)->ObjCContDeclInfo;
|
||||
const DeclInfo *DI = static_cast<const DeclInfo *>(DInfo);
|
||||
if (const ObjCContainerDeclInfo *
|
||||
ContInfo = dyn_cast<ObjCContainerDeclInfo>(DI))
|
||||
return &ContInfo->ObjCContDeclInfo;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const CXIdxObjCInterfaceDeclInfo *
|
||||
clang_index_getObjCInterfaceDeclInfo(const CXIdxDeclInfo *DInfo) {
|
||||
if (!DInfo || DInfo->entityInfo->kind != CXIdxEntity_ObjCClass)
|
||||
if (!DInfo)
|
||||
return 0;
|
||||
|
||||
if (const CXIdxObjCContainerDeclInfo *
|
||||
ContInfo = clang_index_getObjCContainerDeclInfo(DInfo)) {
|
||||
if (ContInfo->kind == CXIdxObjCContainer_Interface)
|
||||
return &static_cast<const ObjCInterfaceDeclInfo*>(DInfo)->ObjCInterDeclInfo;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const CXIdxObjCProtocolDeclInfo *
|
||||
clang_index_getObjCProtocolDeclInfo(const CXIdxDeclInfo *DInfo) {
|
||||
if (!DInfo || DInfo->entityInfo->kind != CXIdxEntity_ObjCProtocol)
|
||||
return 0;
|
||||
|
||||
if (const CXIdxObjCContainerDeclInfo *
|
||||
ContInfo = clang_index_getObjCContainerDeclInfo(DInfo)) {
|
||||
if (ContInfo->kind == CXIdxObjCContainer_Interface)
|
||||
return &static_cast<const ObjCProtocolDeclInfo*>(DInfo)->ObjCProtoDeclInfo;
|
||||
}
|
||||
const DeclInfo *DI = static_cast<const DeclInfo *>(DInfo);
|
||||
if (const ObjCInterfaceDeclInfo *
|
||||
InterInfo = dyn_cast<ObjCInterfaceDeclInfo>(DI))
|
||||
return &InterInfo->ObjCInterDeclInfo;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const CXIdxObjCCategoryDeclInfo *
|
||||
clang_index_getObjCCategoryDeclInfo(const CXIdxDeclInfo *DInfo){
|
||||
if (!DInfo || DInfo->entityInfo->kind != CXIdxEntity_ObjCCategory)
|
||||
if (!DInfo)
|
||||
return 0;
|
||||
|
||||
return &static_cast<const ObjCCategoryDeclInfo*>(DInfo)->ObjCCatDeclInfo;
|
||||
const DeclInfo *DI = static_cast<const DeclInfo *>(DInfo);
|
||||
if (const ObjCCategoryDeclInfo *
|
||||
CatInfo = dyn_cast<ObjCCategoryDeclInfo>(DI))
|
||||
return &CatInfo->ObjCCatDeclInfo;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const CXIdxObjCProtocolRefListInfo *
|
||||
clang_index_getObjCProtocolRefListInfo(const CXIdxDeclInfo *DInfo) {
|
||||
if (!DInfo)
|
||||
return 0;
|
||||
|
||||
const DeclInfo *DI = static_cast<const DeclInfo *>(DInfo);
|
||||
|
||||
if (const ObjCInterfaceDeclInfo *
|
||||
InterInfo = dyn_cast<ObjCInterfaceDeclInfo>(DI))
|
||||
return InterInfo->ObjCInterDeclInfo.protocols;
|
||||
|
||||
if (const ObjCProtocolDeclInfo *
|
||||
ProtInfo = dyn_cast<ObjCProtocolDeclInfo>(DI))
|
||||
return &ProtInfo->ObjCProtoRefListInfo;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int clang_indexTranslationUnit(CXIndex CIdx,
|
||||
|
@ -97,8 +97,6 @@ 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;
|
||||
@ -109,87 +107,69 @@ void IndexingContext::handleDecl(const NamedDecl *D,
|
||||
DInfo.cursor = Cursor;
|
||||
DInfo.loc = getIndexLoc(Loc);
|
||||
DInfo.container = getIndexContainer(D);
|
||||
DInfo.isRedeclaration = isRedeclaration;
|
||||
DInfo.isDefinition = isDefinition;
|
||||
DInfo.isImplicit = D->isImplicit();
|
||||
|
||||
CXIdxClientContainer clientCont = 0;
|
||||
CXIdxDeclOut DeclOut = { isContainer ? &clientCont : 0 };
|
||||
CXIdxDeclOut DeclOut = { DInfo.isContainer ? &clientCont : 0 };
|
||||
CB.indexDeclaration(ClientData, &DInfo, &DeclOut);
|
||||
|
||||
if (isContainer)
|
||||
if (DInfo.isContainer)
|
||||
addContainerInMap(cast<DeclContext>(D), clientCont);
|
||||
}
|
||||
|
||||
void IndexingContext::handleObjCContainer(const ObjCContainerDecl *D,
|
||||
SourceLocation Loc, CXCursor Cursor,
|
||||
bool isForwardRef,
|
||||
bool isRedeclaration,
|
||||
bool isImplementation,
|
||||
ObjCContainerDeclInfo &ContDInfo) {
|
||||
ContDInfo.ObjCContDeclInfo.declInfo = &ContDInfo;
|
||||
if (isForwardRef)
|
||||
ContDInfo.ObjCContDeclInfo.kind = CXIdxObjCContainer_ForwardRef;
|
||||
else if (isImplementation)
|
||||
ContDInfo.ObjCContDeclInfo.kind = CXIdxObjCContainer_Implementation;
|
||||
else
|
||||
ContDInfo.ObjCContDeclInfo.kind = CXIdxObjCContainer_Interface;
|
||||
|
||||
handleDecl(D, Loc, Cursor,
|
||||
isRedeclaration, /*isDefinition=*/!isForwardRef,
|
||||
/*isContainer=*/!isForwardRef, ContDInfo);
|
||||
handleDecl(D, Loc, Cursor, ContDInfo);
|
||||
}
|
||||
|
||||
void IndexingContext::handleFunction(const FunctionDecl *D) {
|
||||
DeclInfo DInfo;
|
||||
handleDecl(D, D->getLocation(), getCursor(D),
|
||||
!D->isFirstDeclaration(), D->isThisDeclarationADefinition(),
|
||||
D->isThisDeclarationADefinition(), DInfo);
|
||||
DeclInfo DInfo(!D->isFirstDeclaration(), D->isThisDeclarationADefinition(),
|
||||
D->isThisDeclarationADefinition());
|
||||
handleDecl(D, D->getLocation(), getCursor(D), DInfo);
|
||||
}
|
||||
|
||||
void IndexingContext::handleVar(const VarDecl *D) {
|
||||
DeclInfo DInfo;
|
||||
handleDecl(D, D->getLocation(), getCursor(D),
|
||||
!D->isFirstDeclaration(), D->isThisDeclarationADefinition(),
|
||||
/*isContainer=*/false, DInfo);
|
||||
DeclInfo DInfo(!D->isFirstDeclaration(), D->isThisDeclarationADefinition(),
|
||||
/*isContainer=*/false);
|
||||
handleDecl(D, D->getLocation(), getCursor(D), DInfo);
|
||||
}
|
||||
|
||||
void IndexingContext::handleField(const FieldDecl *D) {
|
||||
DeclInfo DInfo;
|
||||
handleDecl(D, D->getLocation(), getCursor(D),
|
||||
/*isRedeclaration=*/false, /*isDefinition=*/true,
|
||||
/*isContainer=*/false, DInfo);
|
||||
DeclInfo DInfo(/*isRedeclaration=*/false, /*isDefinition=*/true,
|
||||
/*isContainer=*/false);
|
||||
handleDecl(D, D->getLocation(), getCursor(D), DInfo);
|
||||
}
|
||||
|
||||
void IndexingContext::handleEnumerator(const EnumConstantDecl *D) {
|
||||
DeclInfo DInfo;
|
||||
handleDecl(D, D->getLocation(), getCursor(D),
|
||||
/*isRedeclaration=*/false, /*isDefinition=*/true,
|
||||
/*isContainer=*/false, DInfo);
|
||||
DeclInfo DInfo(/*isRedeclaration=*/false, /*isDefinition=*/true,
|
||||
/*isContainer=*/false);
|
||||
handleDecl(D, D->getLocation(), getCursor(D), DInfo);
|
||||
}
|
||||
|
||||
void IndexingContext::handleTagDecl(const TagDecl *D) {
|
||||
DeclInfo DInfo;
|
||||
handleDecl(D, D->getLocation(), getCursor(D),
|
||||
!D->isFirstDeclaration(), D->isThisDeclarationADefinition(),
|
||||
D->isThisDeclarationADefinition(), DInfo);
|
||||
DeclInfo DInfo(!D->isFirstDeclaration(), D->isThisDeclarationADefinition(),
|
||||
D->isThisDeclarationADefinition());
|
||||
handleDecl(D, D->getLocation(), getCursor(D), DInfo);
|
||||
}
|
||||
|
||||
void IndexingContext::handleTypedef(const TypedefDecl *D) {
|
||||
DeclInfo DInfo;
|
||||
handleDecl(D, D->getLocation(), getCursor(D),
|
||||
!D->isFirstDeclaration(), /*isDefinition=*/true,
|
||||
/*isContainer=*/false, DInfo);
|
||||
DeclInfo DInfo(!D->isFirstDeclaration(), /*isDefinition=*/true,
|
||||
/*isContainer=*/false);
|
||||
handleDecl(D, D->getLocation(), getCursor(D), DInfo);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
ObjCContainerDeclInfo ContDInfo(/*isForwardRef=*/true, isRedeclaration,
|
||||
/*isImplementation=*/false);
|
||||
handleObjCContainer(IFaceD, Loc, MakeCursorObjCClassRef(IFaceD, Loc, CXTU),
|
||||
/*isForwardRef=*/true, isRedeclaration,
|
||||
/*isImplementation=*/false, ContDInfo);
|
||||
ContDInfo);
|
||||
}
|
||||
|
||||
void IndexingContext::handleObjCInterface(const ObjCInterfaceDecl *D) {
|
||||
@ -208,94 +188,77 @@ void IndexingContext::handleObjCInterface(const ObjCInterfaceDecl *D) {
|
||||
|
||||
ObjCProtocolListInfo ProtInfo(D->getReferencedProtocols(), *this, SA);
|
||||
|
||||
ObjCInterfaceDeclInfo InterInfo;
|
||||
InterInfo.ObjCInterDeclInfo.declInfo = &InterInfo;
|
||||
ObjCInterfaceDeclInfo InterInfo(D);
|
||||
InterInfo.ObjCProtoListInfo = ProtInfo.getListInfo();
|
||||
InterInfo.ObjCInterDeclInfo.containerInfo = &InterInfo.ObjCContDeclInfo;
|
||||
InterInfo.ObjCInterDeclInfo.superInfo = D->getSuperClass() ? &BaseClass : 0;
|
||||
InterInfo.ObjCInterDeclInfo.protocols = ProtInfo.getProtocolRefs();
|
||||
InterInfo.ObjCInterDeclInfo.numProtocols = ProtInfo.getNumProtocols();
|
||||
InterInfo.ObjCInterDeclInfo.protocols = &InterInfo.ObjCProtoListInfo;
|
||||
|
||||
handleObjCContainer(D, D->getLocation(), getCursor(D),
|
||||
/*isForwardRef=*/false,
|
||||
/*isRedeclaration=*/D->isInitiallyForwardDecl(),
|
||||
/*isImplementation=*/false, InterInfo);
|
||||
handleObjCContainer(D, D->getLocation(), getCursor(D), InterInfo);
|
||||
}
|
||||
|
||||
void IndexingContext::handleObjCImplementation(
|
||||
const ObjCImplementationDecl *D) {
|
||||
ObjCContainerDeclInfo ContDInfo;
|
||||
const ObjCInterfaceDecl *Class = D->getClassInterface();
|
||||
handleObjCContainer(D, D->getLocation(), getCursor(D),
|
||||
/*isForwardRef=*/false,
|
||||
ObjCContainerDeclInfo ContDInfo(/*isForwardRef=*/false,
|
||||
/*isRedeclaration=*/!Class->isImplicitInterfaceDecl(),
|
||||
/*isImplementation=*/true, ContDInfo);
|
||||
/*isImplementation=*/true);
|
||||
handleObjCContainer(D, D->getLocation(), getCursor(D), ContDInfo);
|
||||
}
|
||||
|
||||
void IndexingContext::handleObjCForwardProtocol(const ObjCProtocolDecl *D,
|
||||
SourceLocation Loc,
|
||||
bool isRedeclaration) {
|
||||
ObjCContainerDeclInfo ContDInfo;
|
||||
ObjCContainerDeclInfo ContDInfo(/*isForwardRef=*/true,
|
||||
isRedeclaration,
|
||||
/*isImplementation=*/false);
|
||||
handleObjCContainer(D, Loc, MakeCursorObjCProtocolRef(D, Loc, CXTU),
|
||||
/*isForwardRef=*/true,
|
||||
isRedeclaration,
|
||||
/*isImplementation=*/false, ContDInfo);
|
||||
ContDInfo);
|
||||
}
|
||||
|
||||
void IndexingContext::handleObjCProtocol(const ObjCProtocolDecl *D) {
|
||||
StrAdapter SA(*this);
|
||||
ObjCProtocolListInfo ProtListInfo(D->getReferencedProtocols(), *this, SA);
|
||||
|
||||
ObjCProtocolDeclInfo ProtInfo;
|
||||
ProtInfo.ObjCProtoDeclInfo.declInfo = &ProtInfo;
|
||||
ProtInfo.ObjCProtoDeclInfo.protocols = ProtListInfo.getProtocolRefs();
|
||||
ProtInfo.ObjCProtoDeclInfo.numProtocols = ProtListInfo.getNumProtocols();
|
||||
ObjCProtocolDeclInfo ProtInfo(D);
|
||||
ProtInfo.ObjCProtoRefListInfo = ProtListInfo.getListInfo();
|
||||
|
||||
handleObjCContainer(D, D->getLocation(), getCursor(D),
|
||||
/*isForwardRef=*/false,
|
||||
/*isRedeclaration=*/D->isInitiallyForwardDecl(),
|
||||
/*isImplementation=*/false, ProtInfo);
|
||||
handleObjCContainer(D, D->getLocation(), getCursor(D), ProtInfo);
|
||||
}
|
||||
|
||||
void IndexingContext::handleObjCCategory(const ObjCCategoryDecl *D) {
|
||||
ObjCCategoryDeclInfo CatDInfo;
|
||||
ObjCCategoryDeclInfo CatDInfo(/*isImplementation=*/false);
|
||||
CXIdxEntityInfo ClassEntity;
|
||||
StrAdapter SA(*this);
|
||||
getEntityInfo(D->getClassInterface(), ClassEntity, SA);
|
||||
|
||||
CatDInfo.ObjCCatDeclInfo.containerInfo = &CatDInfo.ObjCContDeclInfo;
|
||||
CatDInfo.ObjCCatDeclInfo.objcClass = &ClassEntity;
|
||||
handleObjCContainer(D, D->getLocation(), getCursor(D),
|
||||
/*isForwardRef=*/false,
|
||||
/*isRedeclaration=*/false,
|
||||
/*isImplementation=*/false, CatDInfo);
|
||||
handleObjCContainer(D, D->getLocation(), getCursor(D), CatDInfo);
|
||||
}
|
||||
|
||||
void IndexingContext::handleObjCCategoryImpl(const ObjCCategoryImplDecl *D) {
|
||||
const ObjCCategoryDecl *CatD = D->getCategoryDecl();
|
||||
ObjCCategoryDeclInfo CatDInfo;
|
||||
ObjCCategoryDeclInfo CatDInfo(/*isImplementation=*/true);
|
||||
CXIdxEntityInfo ClassEntity;
|
||||
StrAdapter SA(*this);
|
||||
getEntityInfo(CatD->getClassInterface(), ClassEntity, SA);
|
||||
|
||||
CatDInfo.ObjCCatDeclInfo.containerInfo = &CatDInfo.ObjCContDeclInfo;
|
||||
CatDInfo.ObjCCatDeclInfo.objcClass = &ClassEntity;
|
||||
handleObjCContainer(D, D->getLocation(), getCursor(D),
|
||||
/*isForwardRef=*/false,
|
||||
/*isRedeclaration=*/true,
|
||||
/*isImplementation=*/true, CatDInfo);
|
||||
handleObjCContainer(D, D->getLocation(), getCursor(D), CatDInfo);
|
||||
}
|
||||
|
||||
void IndexingContext::handleObjCMethod(const ObjCMethodDecl *D) {
|
||||
DeclInfo DInfo;
|
||||
handleDecl(D, D->getLocation(), getCursor(D),
|
||||
!D->isCanonicalDecl(), D->isThisDeclarationADefinition(),
|
||||
D->isThisDeclarationADefinition(), DInfo);
|
||||
DeclInfo DInfo(!D->isCanonicalDecl(), D->isThisDeclarationADefinition(),
|
||||
D->isThisDeclarationADefinition());
|
||||
handleDecl(D, D->getLocation(), getCursor(D), DInfo);
|
||||
}
|
||||
|
||||
void IndexingContext::handleObjCProperty(const ObjCPropertyDecl *D) {
|
||||
DeclInfo DInfo;
|
||||
handleDecl(D, D->getLocation(), getCursor(D),
|
||||
/*isRedeclaration=*/false, /*isDefinition=*/false,
|
||||
/*isContainer=*/false, DInfo);
|
||||
DeclInfo DInfo(/*isRedeclaration=*/false, /*isDefinition=*/false,
|
||||
/*isContainer=*/false);
|
||||
handleDecl(D, D->getLocation(), getCursor(D), DInfo);
|
||||
}
|
||||
|
||||
void IndexingContext::handleReference(const NamedDecl *D, SourceLocation Loc,
|
||||
@ -490,7 +453,11 @@ void IndexingContext::getEntityInfo(const NamedDecl *D,
|
||||
case Decl::ObjCCategory:
|
||||
EntityInfo.kind = CXIdxEntity_ObjCCategory; break;
|
||||
case Decl::ObjCMethod:
|
||||
EntityInfo.kind = CXIdxEntity_ObjCMethod; break;
|
||||
if (cast<ObjCMethodDecl>(D)->isInstanceMethod())
|
||||
EntityInfo.kind = CXIdxEntity_ObjCInstanceMethod;
|
||||
else
|
||||
EntityInfo.kind = CXIdxEntity_ObjCClassMethod;
|
||||
break;
|
||||
case Decl::ObjCProperty:
|
||||
EntityInfo.kind = CXIdxEntity_ObjCProperty; break;
|
||||
case Decl::ObjCIvar:
|
||||
|
@ -24,22 +24,113 @@ namespace cxindex {
|
||||
|
||||
struct DeclInfo : public CXIdxDeclInfo {
|
||||
CXIdxEntityInfo CXEntInfo;
|
||||
enum DInfoKind {
|
||||
Info_Decl,
|
||||
|
||||
Info_ObjCContainer,
|
||||
Info_ObjCInterface,
|
||||
Info_ObjCProtocol,
|
||||
Info_ObjCCategory
|
||||
};
|
||||
|
||||
DInfoKind Kind;
|
||||
|
||||
DeclInfo(bool isRedeclaration, bool isDefinition, bool isContainer)
|
||||
: Kind(Info_Decl) {
|
||||
this->isRedeclaration = isRedeclaration;
|
||||
this->isDefinition = isDefinition;
|
||||
this->isContainer = isContainer;
|
||||
}
|
||||
DeclInfo(DInfoKind K,
|
||||
bool isRedeclaration, bool isDefinition, bool isContainer)
|
||||
: Kind(K) {
|
||||
this->isRedeclaration = isRedeclaration;
|
||||
this->isDefinition = isDefinition;
|
||||
this->isContainer = isContainer;
|
||||
}
|
||||
|
||||
static bool classof(const DeclInfo *) { return true; }
|
||||
};
|
||||
|
||||
struct ObjCContainerDeclInfo : public DeclInfo {
|
||||
CXIdxObjCContainerDeclInfo ObjCContDeclInfo;
|
||||
|
||||
ObjCContainerDeclInfo(bool isForwardRef,
|
||||
bool isRedeclaration,
|
||||
bool isImplementation)
|
||||
: DeclInfo(Info_ObjCContainer, isRedeclaration,
|
||||
/*isDefinition=*/!isForwardRef, /*isContainer=*/!isForwardRef) {
|
||||
init(isForwardRef, isImplementation);
|
||||
}
|
||||
ObjCContainerDeclInfo(DInfoKind K,
|
||||
bool isForwardRef,
|
||||
bool isRedeclaration,
|
||||
bool isImplementation)
|
||||
: DeclInfo(K, isRedeclaration, /*isDefinition=*/!isForwardRef,
|
||||
/*isContainer=*/!isForwardRef) {
|
||||
init(isForwardRef, isImplementation);
|
||||
}
|
||||
|
||||
static bool classof(const DeclInfo *D) {
|
||||
return Info_ObjCContainer <= D->Kind && D->Kind <= Info_ObjCCategory;
|
||||
}
|
||||
static bool classof(const ObjCContainerDeclInfo *D) { return true; }
|
||||
|
||||
private:
|
||||
void init(bool isForwardRef, bool isImplementation) {
|
||||
if (isForwardRef)
|
||||
ObjCContDeclInfo.kind = CXIdxObjCContainer_ForwardRef;
|
||||
else if (isImplementation)
|
||||
ObjCContDeclInfo.kind = CXIdxObjCContainer_Implementation;
|
||||
else
|
||||
ObjCContDeclInfo.kind = CXIdxObjCContainer_Interface;
|
||||
}
|
||||
};
|
||||
|
||||
struct ObjCInterfaceDeclInfo : public ObjCContainerDeclInfo {
|
||||
CXIdxObjCInterfaceDeclInfo ObjCInterDeclInfo;
|
||||
CXIdxObjCProtocolRefListInfo ObjCProtoListInfo;
|
||||
|
||||
ObjCInterfaceDeclInfo(const ObjCInterfaceDecl *D)
|
||||
: ObjCContainerDeclInfo(Info_ObjCInterface,
|
||||
/*isForwardRef=*/false,
|
||||
/*isRedeclaration=*/D->isInitiallyForwardDecl(),
|
||||
/*isImplementation=*/false) { }
|
||||
|
||||
static bool classof(const DeclInfo *D) {
|
||||
return D->Kind == Info_ObjCInterface;
|
||||
}
|
||||
static bool classof(const ObjCInterfaceDeclInfo *D) { return true; }
|
||||
};
|
||||
|
||||
struct ObjCProtocolDeclInfo : public ObjCContainerDeclInfo {
|
||||
CXIdxObjCProtocolRefListInfo ObjCProtoRefListInfo;
|
||||
|
||||
ObjCProtocolDeclInfo(const ObjCProtocolDecl *D)
|
||||
: ObjCContainerDeclInfo(Info_ObjCProtocol,
|
||||
/*isForwardRef=*/false,
|
||||
/*isRedeclaration=*/D->isInitiallyForwardDecl(),
|
||||
/*isImplementation=*/false) { }
|
||||
|
||||
static bool classof(const DeclInfo *D) {
|
||||
return D->Kind == Info_ObjCProtocol;
|
||||
}
|
||||
static bool classof(const ObjCProtocolDeclInfo *D) { return true; }
|
||||
};
|
||||
|
||||
struct ObjCCategoryDeclInfo : public ObjCContainerDeclInfo {
|
||||
CXIdxObjCCategoryDeclInfo ObjCCatDeclInfo;
|
||||
};
|
||||
|
||||
struct ObjCInterfaceDeclInfo : public ObjCCategoryDeclInfo {
|
||||
CXIdxObjCInterfaceDeclInfo ObjCInterDeclInfo;
|
||||
};
|
||||
explicit ObjCCategoryDeclInfo(bool isImplementation)
|
||||
: ObjCContainerDeclInfo(Info_ObjCCategory,
|
||||
/*isForwardRef=*/false,
|
||||
/*isRedeclaration=*/isImplementation,
|
||||
/*isImplementation=*/isImplementation) { }
|
||||
|
||||
struct ObjCProtocolDeclInfo : public ObjCCategoryDeclInfo {
|
||||
CXIdxObjCProtocolDeclInfo ObjCProtoDeclInfo;
|
||||
static bool classof(const DeclInfo *D) {
|
||||
return D->Kind == Info_ObjCCategory;
|
||||
}
|
||||
static bool classof(const ObjCCategoryDeclInfo *D) { return true; }
|
||||
};
|
||||
|
||||
class IndexingContext {
|
||||
@ -92,8 +183,11 @@ class IndexingContext {
|
||||
SmallVector<CXIdxEntityInfo, 4> ProtEntities;
|
||||
SmallVector<CXIdxObjCProtocolRefInfo *, 4> Prots;
|
||||
|
||||
CXIdxObjCProtocolRefInfo **getProtocolRefs() { return Prots.data(); }
|
||||
unsigned getNumProtocols() { return (unsigned)Prots.size(); }
|
||||
CXIdxObjCProtocolRefListInfo getListInfo() {
|
||||
CXIdxObjCProtocolRefListInfo Info = { Prots.data(),
|
||||
(unsigned)Prots.size() };
|
||||
return Info;
|
||||
}
|
||||
|
||||
ObjCProtocolListInfo(const ObjCProtocolList &ProtList,
|
||||
IndexingContext &IdxCtx,
|
||||
@ -184,14 +278,10 @@ public:
|
||||
private:
|
||||
void handleDecl(const NamedDecl *D,
|
||||
SourceLocation Loc, CXCursor Cursor,
|
||||
bool isRedeclaration, bool isDefinition, bool isContainer,
|
||||
DeclInfo &DInfo);
|
||||
|
||||
void handleObjCContainer(const ObjCContainerDecl *D,
|
||||
SourceLocation Loc, CXCursor Cursor,
|
||||
bool isForwardRef,
|
||||
bool isRedeclaration,
|
||||
bool isImplementation,
|
||||
ObjCContainerDeclInfo &ContDInfo);
|
||||
|
||||
void addContainerInMap(const DeclContext *DC, CXIdxClientContainer container);
|
||||
|
@ -138,7 +138,7 @@ clang_hashCursor
|
||||
clang_index_getObjCCategoryDeclInfo
|
||||
clang_index_getObjCContainerDeclInfo
|
||||
clang_index_getObjCInterfaceDeclInfo
|
||||
clang_index_getObjCProtocolDeclInfo
|
||||
clang_index_getObjCProtocolRefListInfo
|
||||
clang_index_isEntityObjCContainerKind
|
||||
clang_indexLoc_getCXSourceLocation
|
||||
clang_indexLoc_getFileLocation
|
||||
|
Loading…
Reference in New Issue
Block a user