[cfe-commits] r144446 - in /cfe/trunk: include/clang-c/Index.h tools/c-index-test/c-index-test.c tools/libclang/IndexDecl.cpp tools/libclang/IndexTypeSourceInfo.cpp tools/libclang/Indexing.cpp tools/libclang/IndexingContext.cpp tools/libclang/IndexingContext.h tools/libclang/libclang.exports
Argyrios Kyrtzidis
akyrtzi at gmail.com
Fri Nov 11 18:16:30 PST 2011
Author: akirtzidis
Date: Fri Nov 11 20:16:30 2011
New Revision: 144446
URL: http://llvm.org/viewvc/llvm-project?rev=144446&view=rev
Log:
[libclang] Further simplify the indexing API.
That stuff can be added later on if we need them.
Also add some const goodness.
Modified:
cfe/trunk/include/clang-c/Index.h
cfe/trunk/tools/c-index-test/c-index-test.c
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
cfe/trunk/tools/libclang/libclang.exports
Modified: cfe/trunk/include/clang-c/Index.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=144446&r1=144445&r2=144446&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Fri Nov 11 20:16:30 2011
@@ -3941,57 +3941,12 @@
typedef void *CXIdxClientFile;
/**
- * \brief The client's data object that is associated with a unique entity in
- * the current translation unit that gets indexed. For example:
- *
- * \code
- * @class Foo;
- * @interface Foo
- * @end
- * \endcode
- *
- * In the example above there is only one entity introduced, the class 'Foo'.
- */
-typedef void *CXIdxClientEntity;
-
-/**
* \brief The client's data object that is associated with a semantic container
* of entities.
- *
- * \code
- * // #1 \see startedTranslationUnit
- *
- * void func() { } // #2 \see startedStatementBody
- *
- * @interface Foo // #3 \see startedObjCContainer
- * -(void)meth;
- * @end
- *
- * @implementation Foo // #4 \see startedObjCContainer
- * -(void)meth {} // #5 \see startedStatementBody
- * @end
- *
- * class C { // #6 \see startedTagTypeDefinition
- * void meth();
- * };
- * void C::meth() {} // #7 \see startedStatementBody
- * \endcode
- *
- * In the example above the markings are wherever there is a callback that
- * initiates a container context. The CXIdxContainer that the client returns
- * for the callbacks will be passed along the indexed entities in the
- * container. Note that C++ out-of-line member functions (#7) are considered
- * as part of the C++ class container, not of the translation unit.
*/
typedef void *CXIdxClientContainer;
/**
- * \brief The client's data object that is associated with a macro definition
- * in the current translation unit that gets indexed.
- */
-typedef void *CXIdxClientMacro;
-
-/**
* \brief The client's data object that is associated with an AST file (PCH
* or module).
*/
@@ -4041,52 +3996,6 @@
int isModule;
} CXIdxImportedASTFileInfo;
-typedef struct {
- /**
- * \brief Location of the macro definition.
- */
- CXIdxLoc loc;
- const char *name;
-} CXIdxMacroInfo;
-
-/**
- * \brief Data for \see ppMacroDefined callback.
- */
-typedef struct {
- CXIdxMacroInfo *macroInfo;
- CXIdxLoc defBegin;
- /**
- * \brief Length of macro definition in characters.
- */
- unsigned defLength;
-} CXIdxMacroDefinedInfo;
-
-/**
- * \brief Data for \see ppMacroUndefined callback.
- */
-typedef struct {
- CXIdxLoc loc;
- const char *name;
- CXIdxClientMacro macro;
-} CXIdxMacroUndefinedInfo;
-
-/**
- * \brief Data for \see ppMacroExpanded callback.
- */
-typedef struct {
- CXIdxLoc loc;
- const char *name;
- CXIdxClientMacro macro;
-} CXIdxMacroExpandedInfo;
-
-/**
- * \brief Data for \see importedMacro callback.
- */
-typedef struct {
- CXIdxMacroInfo *macroInfo;
- CXIdxClientASTFile ASTFile;
-} CXIdxImportedMacroInfo;
-
typedef enum {
CXIdxEntity_Unexposed = 0,
CXIdxEntity_Typedef = 1,
@@ -4114,28 +4023,10 @@
CXIdxEntityKind kind;
const char *name;
const char *USR;
- CXIdxClientEntity clientEntity;
} CXIdxEntityInfo;
-/**
- * \brief Data for \see importedEntity callback.
- */
-typedef struct {
- CXIdxEntityInfo *entityInfo;
- CXCursor cursor;
- CXIdxLoc loc;
- CXIdxClientASTFile ASTFile;
-} CXIdxImportedEntityInfo;
-
-typedef struct {
- CXIdxEntityInfo *entity;
- CXCursor cursor;
- CXIdxLoc loc;
- int isObjCImpl;
-} CXIdxContainerInfo;
-
typedef struct {
- CXIdxEntityInfo *entityInfo;
+ const CXIdxEntityInfo *entityInfo;
CXCursor cursor;
CXIdxLoc loc;
CXIdxClientContainer container;
@@ -4144,9 +4035,8 @@
} CXIdxDeclInfo;
typedef struct {
- CXIdxDeclInfo *declInfo;
- int isAnonymous;
-} CXIdxTagDeclInfo;
+ CXIdxClientContainer *outContainer;
+} CXIdxDeclOut;
typedef enum {
CXIdxObjCContainer_ForwardRef = 0,
@@ -4155,50 +4045,39 @@
} CXIdxObjCContainerKind;
typedef struct {
- CXIdxDeclInfo *declInfo;
+ const CXIdxDeclInfo *declInfo;
CXIdxObjCContainerKind kind;
} CXIdxObjCContainerDeclInfo;
typedef struct {
- CXIdxObjCContainerDeclInfo *containerInfo;
- CXIdxEntityInfo *objcClass;
+ const CXIdxObjCContainerDeclInfo *containerInfo;
+ const CXIdxEntityInfo *objcClass;
} CXIdxObjCCategoryDeclInfo;
-/**
- * \brief Data for \see defineObjCClass callback.
- */
typedef struct {
- CXIdxEntityInfo *objcClass;
+ const CXIdxEntityInfo *base;
+ CXCursor cursor;
CXIdxLoc loc;
-} CXIdxObjCBaseClassInfo;
+} CXIdxBaseClassInfo;
-/**
- * \brief Data for \see defineObjCClass callback.
- */
typedef struct {
- CXIdxEntityInfo *protocol;
+ const CXIdxEntityInfo *protocol;
+ CXCursor cursor;
CXIdxLoc loc;
} CXIdxObjCProtocolRefInfo;
-/**
- * \brief Data for \see defineObjCClass callback.
- */
typedef struct {
- CXCursor cursor;
- CXIdxEntityInfo *objcClass;
- CXIdxClientContainer container;
- CXIdxObjCBaseClassInfo *baseInfo;
- CXIdxObjCProtocolRefInfo **protocols;
+ const CXIdxDeclInfo *declInfo;
+ const CXIdxBaseClassInfo *superInfo;
+ const CXIdxObjCProtocolRefInfo *const *protocols;
unsigned numProtocols;
-} CXIdxObjCClassDefineInfo;
+} CXIdxObjCInterfaceDeclInfo;
-/**
- * \brief Data for \see endedContainer callback.
- */
typedef struct {
- CXIdxClientContainer container;
- CXIdxLoc endLoc;
-} CXIdxEndContainerInfo;
+ const CXIdxDeclInfo *declInfo;
+ const CXIdxObjCProtocolRefInfo *const *protocols;
+ unsigned numProtocols;
+} CXIdxObjCProtocolDeclInfo;
/**
* \brief Data for \see indexEntityReference callback.
@@ -4226,7 +4105,7 @@
/**
* \brief The entity that gets referenced.
*/
- CXIdxEntityInfo *referencedEntity;
+ const CXIdxEntityInfo *referencedEntity;
/**
* \brief Immediate "parent" of the reference. For example:
*
@@ -4237,7 +4116,7 @@
* The parent of reference of type 'Foo' is the variable 'var'.
* parentEntity will be null for references inside statement bodies.
*/
- CXIdxEntityInfo *parentEntity;
+ const CXIdxEntityInfo *parentEntity;
/**
* \brief Container context of the reference.
*/
@@ -4247,6 +4126,12 @@
typedef struct {
/**
+ * \brief Called periodically to check whether indexing should be aborted.
+ * Should return 0 to continue, and non-zero to abort.
+ */
+ int (*abortQuery)(CXClientData client_data, void *reserved);
+
+ /**
* \brief Called when a diagnostic is emitted.
*/
void (*diagnostic)(CXClientData client_data,
@@ -4259,25 +4144,7 @@
* \brief Called when a file gets #included/#imported.
*/
CXIdxClientFile (*ppIncludedFile)(CXClientData client_data,
- CXIdxIncludedFileInfo *);
-
- /**
- * \brief Called when a macro gets #defined.
- */
- CXIdxClientMacro (*ppMacroDefined)(CXClientData client_data,
- CXIdxMacroDefinedInfo *);
-
- /**
- * \brief Called when a macro gets undefined.
- */
- void (*ppMacroUndefined)(CXClientData client_data,
- CXIdxMacroUndefinedInfo *);
-
- /**
- * \brief Called when a macro gets expanded.
- */
- void (*ppMacroExpanded)(CXClientData client_data,
- CXIdxMacroExpandedInfo *);
+ const CXIdxIncludedFileInfo *);
/**
* \brief Called when a AST file (PCH or module) gets imported.
@@ -4285,72 +4152,41 @@
* AST files will not get indexed (there will not be callbacks to index all
* the entities in an AST file). The recommended action is that, if the AST
* file is not already indexed, to block further indexing and initiate a new
- * indexing job specific to the AST file, so that references of entities of
- * the AST file can be later associated with CXIdxEntities returned by
- * \see importedEntity callbacks.
+ * indexing job specific to the AST file.
*/
CXIdxClientASTFile (*importedASTFile)(CXClientData client_data,
- CXIdxImportedASTFileInfo *);
-
- /**
- * \brief Called when an entity gets imported from an AST file. This generally
- * happens when an entity from a PCH/module is referenced for the first time.
- */
- CXIdxClientEntity (*importedEntity)(CXClientData client_data,
- CXIdxImportedEntityInfo *);
-
- /**
- * \brief Called when a macro gets imported from an AST file. This generally
- * happens when a macro from a PCH/module is referenced for the first time.
- */
- CXIdxClientMacro (*importedMacro)(CXClientData client_data,
- CXIdxImportedMacroInfo *);
+ const CXIdxImportedASTFileInfo *);
/**
* \brief Called at the beginning of indexing a translation unit.
*/
CXIdxClientContainer (*startedTranslationUnit)(CXClientData client_data,
- void *reserved);
-
- CXIdxClientEntity (*indexDeclaration)(CXClientData client_data,
- CXIdxDeclInfo *);
+ void *reserved);
- /**
- * \brief Called to initiate a container context.
- */
- CXIdxClientContainer (*startedContainer)(CXClientData client_data,
- CXIdxContainerInfo *);
-
- /**
- * \brief Called to define an ObjC class via its @interface.
- */
- void (*defineObjCClass)(CXClientData client_data,
- CXIdxObjCClassDefineInfo *);
-
- /**
- * \brief Called when a container context is ended.
- */
- void (*endedContainer)(CXClientData client_data,
- CXIdxEndContainerInfo *);
+ void (*indexDeclaration)(CXClientData client_data,
+ const CXIdxDeclInfo *, const CXIdxDeclOut *);
/**
* \brief Called to index a reference of an entity.
*/
void (*indexEntityReference)(CXClientData client_data,
- CXIdxEntityRefInfo *);
+ const CXIdxEntityRefInfo *);
} IndexerCallbacks;
-CINDEX_LINKAGE int clang_index_isEntityTagKind(CXIdxEntityKind);
-CINDEX_LINKAGE CXIdxTagDeclInfo *clang_index_getTagDeclInfo(CXIdxDeclInfo *);
-
CINDEX_LINKAGE int clang_index_isEntityObjCContainerKind(CXIdxEntityKind);
-CINDEX_LINKAGE CXIdxObjCContainerDeclInfo *
-clang_index_getObjCContainerDeclInfo(CXIdxDeclInfo *);
+CINDEX_LINKAGE const CXIdxObjCContainerDeclInfo *
+clang_index_getObjCContainerDeclInfo(const CXIdxDeclInfo *);
+
+CINDEX_LINKAGE const CXIdxObjCInterfaceDeclInfo *
+clang_index_getObjCInterfaceDeclInfo(const CXIdxDeclInfo *);
-CINDEX_LINKAGE int clang_index_isEntityObjCCategoryKind(CXIdxEntityKind);
CINDEX_LINKAGE
-CXIdxObjCCategoryDeclInfo *clang_index_getObjCCategoryDeclInfo(CXIdxDeclInfo *);
+const CXIdxObjCCategoryDeclInfo *
+clang_index_getObjCCategoryDeclInfo(const CXIdxDeclInfo *);
+
+CINDEX_LINKAGE const CXIdxObjCProtocolDeclInfo *
+clang_index_getObjCProtocolDeclInfo(const CXIdxDeclInfo *);
/**
* \brief Index the given source file and the translation unit corresponding
Modified: cfe/trunk/tools/c-index-test/c-index-test.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=144446&r1=144445&r2=144446&view=diff
==============================================================================
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Fri Nov 11 20:16:30 2011
@@ -1577,7 +1577,8 @@
printf("%d:%d", line, column);
}
-static CXIdxClientEntity makeClientEntity(CXIdxEntityInfo *info, CXIdxLoc loc) {
+static CXIdxClientContainer makeClientContainer(const CXIdxEntityInfo *info,
+ CXIdxLoc loc) {
const char *name;
char *newStr;
CXIdxClientFile file;
@@ -1591,7 +1592,7 @@
/* FIXME: free these.*/
newStr = (char *)malloc(strlen(name) + 10);
sprintf(newStr, "%s:%d:%d", name, line, column);
- return (CXIdxClientEntity)newStr;
+ return (CXIdxClientContainer)newStr;
}
static void printCXIndexContainer(CXIdxClientContainer container) {
@@ -1617,12 +1618,13 @@
case CXIdxEntity_Union: return "union";
case CXIdxEntity_CXXClass: return "c++-class";
}
- return "<unknown>";
+ assert(0 && "Garbage entity kind");
+ return 0;
}
static void printEntityInfo(const char *cb,
CXClientData client_data,
- CXIdxEntityInfo *info) {
+ const CXIdxEntityInfo *info) {
const char *name;
IndexData *index_data;
index_data = (IndexData *)client_data;
@@ -1670,7 +1672,7 @@
}
static CXIdxClientFile index_ppIncludedFile(CXClientData client_data,
- CXIdxIncludedFileInfo *info) {
+ const CXIdxIncludedFileInfo *info) {
IndexData *index_data;
index_data = (IndexData *)client_data;
printCheck(index_data);
@@ -1685,62 +1687,6 @@
return (CXIdxClientFile)info->file;
}
-static CXIdxClientMacro index_ppMacroDefined(CXClientData client_data,
- CXIdxMacroDefinedInfo *info) {
- IndexData *index_data;
- index_data = (IndexData *)client_data;
- printCheck(index_data);
-
- printf("[ppMacroDefined]: %s", info->macroInfo->name);
- printf(" | loc: ");
- printCXIndexLoc(info->macroInfo->loc);
- printf(" | defBegin: ");
- printCXIndexLoc(info->defBegin);
- printf(" | length: %d\n", info->defLength);
-
- return (CXIdxClientMacro)info->macroInfo->name;
-}
-
-static void index_ppMacroUndefined(CXClientData client_data,
- CXIdxMacroUndefinedInfo *info) {
- IndexData *index_data;
- index_data = (IndexData *)client_data;
- printCheck(index_data);
-
- printf("[ppMacroUndefined]: %s", info->name);
- printf(" | loc: ");
- printCXIndexLoc(info->loc);
- printf("\n");
-}
-
-static void index_ppMacroExpanded(CXClientData client_data,
- CXIdxMacroExpandedInfo *info) {
- IndexData *index_data;
- index_data = (IndexData *)client_data;
- printCheck(index_data);
-
- printf("[ppMacroExpanded]: %s", info->name);
- printf(" | loc: ");
- printCXIndexLoc(info->loc);
- printf("\n");
-}
-
-static CXIdxClientEntity index_importedEntity(CXClientData client_data,
- CXIdxImportedEntityInfo *info) {
- IndexData *index_data;
- index_data = (IndexData *)client_data;
- printCheck(index_data);
-
- printEntityInfo("[importedEntity]", client_data, info->entityInfo);
- printf(" | cursor: ");
- PrintCursor(info->cursor);
- printf(" | loc: ");
- printCXIndexLoc(info->loc);
- printf("\n");
-
- return makeClientEntity(info->entityInfo, info->loc);
-}
-
static CXIdxClientContainer index_startedTranslationUnit(CXClientData client_data,
void *reserved) {
IndexData *index_data;
@@ -1751,9 +1697,14 @@
return (CXIdxClientContainer)"TU";
}
-static CXIdxClientEntity index_indexDeclaration(CXClientData client_data,
- CXIdxDeclInfo *info) {
- IndexData *index_data;
+static void index_indexDeclaration(CXClientData client_data,
+ const CXIdxDeclInfo *info,
+ const CXIdxDeclOut *outData) {
+ IndexData *index_data;
+ const CXIdxObjCCategoryDeclInfo *CatInfo;
+ const CXIdxObjCInterfaceDeclInfo *InterInfo;
+ const CXIdxObjCProtocolDeclInfo *ProtoInfo;
+ unsigned i;
index_data = (IndexData *)client_data;
printEntityInfo("[indexDeclaration]", client_data, info->entityInfo);
@@ -1766,13 +1717,6 @@
printf(" | isRedecl: %d", info->isRedeclaration);
printf(" | isDef: %d\n", info->isDefinition);
-
- if (clang_index_isEntityTagKind(info->entityInfo->kind)) {
- printCheck(index_data);
- printf(" <TagInfo>: isAnonymous: %d\n",
- clang_index_getTagDeclInfo(info)->isAnonymous);
- }
-
if (clang_index_isEntityObjCContainerKind(info->entityInfo->kind)) {
const char *kindName = 0;
CXIdxObjCContainerKind K = clang_index_getObjCContainerDeclInfo(info)->kind;
@@ -1788,64 +1732,51 @@
printf(" <ObjCContainerInfo>: kind: %s\n", kindName);
}
- if (clang_index_isEntityObjCCategoryKind(info->entityInfo->kind)) {
- CXIdxObjCCategoryDeclInfo *
- CatInfo = clang_index_getObjCCategoryDeclInfo(info);
+ if ((CatInfo = clang_index_getObjCCategoryDeclInfo(info))) {
printEntityInfo(" <ObjCCategoryInfo>: class", client_data,
CatInfo->objcClass);
printf("\n");
}
- if (!info->isRedeclaration)
- return makeClientEntity(info->entityInfo, info->loc);
-
- return 0;
-}
-
-static CXIdxClientContainer
-index_startedContainer(CXClientData client_data, CXIdxContainerInfo *info) {
- printEntityInfo("[startedContainer]", client_data, info->entity);
- printf(" | cursor: ");
- PrintCursor(info->cursor);
- printf(" | loc: ");
- printCXIndexLoc(info->loc);
- printf(" | isObjCImpl: %d\n", info->isObjCImpl);
-
- return (CXIdxClientContainer)info->entity->clientEntity;
-}
-
-static void index_defineObjCClass(CXClientData client_data,
- CXIdxObjCClassDefineInfo *info) {
- printEntityInfo("[defineObjCClass]", client_data, info->objcClass);
- printf(" | cursor: ");
- PrintCursor(info->cursor);
- printf(" | container: ");
- printCXIndexContainer(info->container);
-
- if (info->baseInfo) {
- printEntityInfo(" | <base>", client_data, info->baseInfo->objcClass);
- printf(" | base loc: ");
- printCXIndexLoc(info->baseInfo->loc);
+ if ((InterInfo = clang_index_getObjCInterfaceDeclInfo(info))) {
+ if (InterInfo->superInfo) {
+ printEntityInfo(" <ObjCInterfaceInfo>: base", client_data,
+ InterInfo->superInfo->base);
+ printf(" | cursor: ");
+ PrintCursor(InterInfo->superInfo->cursor);
+ printf(" | loc: ");
+ 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");
+ }
}
- printf("\n");
-}
-
-static void index_endedContainer(CXClientData client_data,
- CXIdxEndContainerInfo *info) {
- IndexData *index_data;
- index_data = (IndexData *)client_data;
- printCheck(index_data);
+ 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");
+ }
+ }
- printf("[endedContainer]: ");
- printCXIndexContainer(info->container);
- printf(" | end: ");
- printCXIndexLoc(info->endLoc);
- printf("\n");
+ if (outData->outContainer)
+ *outData->outContainer = makeClientContainer(info->entityInfo, info->loc);
}
static void index_indexEntityReference(CXClientData client_data,
- CXIdxEntityRefInfo *info) {
+ const CXIdxEntityRefInfo *info) {
printEntityInfo("[indexEntityReference]", client_data, info->referencedEntity);
printf(" | cursor: ");
PrintCursor(info->cursor);
@@ -1863,20 +1794,13 @@
}
static IndexerCallbacks IndexCB = {
+ 0, /*abortQuery*/
index_diagnostic,
index_enteredMainFile,
index_ppIncludedFile,
- index_ppMacroDefined,
- index_ppMacroUndefined,
- index_ppMacroExpanded,
0, /*importedASTFile*/
- index_importedEntity,
- 0,/*index_importedMacro,*/
index_startedTranslationUnit,
index_indexDeclaration,
- index_startedContainer,
- index_defineObjCClass,
- index_endedContainer,
index_indexEntityReference
};
Modified: cfe/trunk/tools/libclang/IndexDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/IndexDecl.cpp?rev=144446&r1=144445&r2=144446&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/IndexDecl.cpp (original)
+++ cfe/trunk/tools/libclang/IndexDecl.cpp Fri Nov 11 20:16:30 2011
@@ -29,9 +29,7 @@
if (D->isThisDeclarationADefinition()) {
const Stmt *Body = D->getBody();
if (Body) {
- IndexCtx.startContainer(D, /*isBody=*/true);
IndexCtx.indexBody(Body, D);
- IndexCtx.endContainer(D);
}
}
return true;
@@ -93,10 +91,7 @@
IndexCtx.handleObjCInterface(D);
IndexCtx.indexTUDeclsInObjCContainer();
- IndexCtx.startContainer(D);
- IndexCtx.defineObjCInterface(D);
IndexCtx.indexDeclContext(D);
- IndexCtx.endContainer(D);
return true;
}
@@ -108,9 +103,7 @@
IndexCtx.handleObjCProtocol(D);
IndexCtx.indexTUDeclsInObjCContainer();
- IndexCtx.startContainer(D);
IndexCtx.indexDeclContext(D);
- IndexCtx.endContainer(D);
return true;
}
@@ -118,9 +111,7 @@
IndexCtx.handleObjCImplementation(D);
IndexCtx.indexTUDeclsInObjCContainer();
- IndexCtx.startContainer(D);
IndexCtx.indexDeclContext(D);
- IndexCtx.endContainer(D);
return true;
}
@@ -128,9 +119,7 @@
IndexCtx.handleObjCCategory(D);
IndexCtx.indexTUDeclsInObjCContainer();
- IndexCtx.startContainer(D);
IndexCtx.indexDeclContext(D);
- IndexCtx.endContainer(D);
return true;
}
@@ -141,9 +130,7 @@
IndexCtx.handleObjCCategoryImpl(D);
IndexCtx.indexTUDeclsInObjCContainer();
- IndexCtx.startContainer(D);
IndexCtx.indexDeclContext(D);
- IndexCtx.endContainer(D);
return true;
}
@@ -157,9 +144,7 @@
if (D->isThisDeclarationADefinition()) {
const Stmt *Body = D->getBody();
if (Body) {
- IndexCtx.startContainer(D, /*isBody=*/true);
IndexCtx.indexBody(Body, D);
- IndexCtx.endContainer(D);
}
}
return true;
Modified: cfe/trunk/tools/libclang/IndexTypeSourceInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/IndexTypeSourceInfo.cpp?rev=144446&r1=144445&r2=144446&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/IndexTypeSourceInfo.cpp (original)
+++ cfe/trunk/tools/libclang/IndexTypeSourceInfo.cpp Fri Nov 11 20:16:30 2011
@@ -87,8 +87,6 @@
void IndexingContext::indexTagDecl(const TagDecl *D) {
handleTagDecl(D);
if (D->isThisDeclarationADefinition()) {
- startContainer(D);
indexDeclContext(D);
- endContainer(D);
}
}
Modified: cfe/trunk/tools/libclang/Indexing.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/Indexing.cpp?rev=144446&r1=144445&r2=144446&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/Indexing.cpp (original)
+++ cfe/trunk/tools/libclang/Indexing.cpp Fri Nov 11 20:16:30 2011
@@ -75,47 +75,16 @@
/// MacroDefined - This hook is called whenever a macro definition is seen.
virtual void MacroDefined(const Token &Id, const MacroInfo *MI) {
- if (MI->isBuiltinMacro())
- return;
- if (IndexCtx.isNotFromSourceFile(MI->getDefinitionLoc()))
- return;
-
- SourceLocation Loc = MI->getDefinitionLoc();
- SourceLocation DefBegin = MI->tokens_empty() ? Loc
- : MI->getReplacementToken(0).getLocation();
- IndexCtx.ppMacroDefined(Loc,
- Id.getIdentifierInfo()->getName(),
- DefBegin,
- MI->getDefinitionLength(PP.getSourceManager()),
- MI);
}
/// MacroUndefined - This hook is called whenever a macro #undef is seen.
/// MI is released immediately following this callback.
virtual void MacroUndefined(const Token &MacroNameTok, const MacroInfo *MI) {
- if (MI->isBuiltinMacro())
- return;
- if (IndexCtx.isNotFromSourceFile(MI->getDefinitionLoc()))
- return;
-
- SourceLocation Loc = MacroNameTok.getLocation();
- IndexCtx.ppMacroUndefined(Loc,
- MacroNameTok.getIdentifierInfo()->getName(),
- MI);
}
/// MacroExpands - This is called by when a macro invocation is found.
virtual void MacroExpands(const Token &MacroNameTok, const MacroInfo* MI,
SourceRange Range) {
- if (MI->isBuiltinMacro())
- return;
- if (IndexCtx.isNotFromSourceFile(MI->getDefinitionLoc()))
- return;
-
- SourceLocation Loc = MacroNameTok.getLocation();
- IndexCtx.ppMacroExpanded(Loc,
- MacroNameTok.getIdentifierInfo()->getName(),
- MI);
}
/// SourceRangeSkipped - This hook is called when a source range is skipped.
@@ -140,11 +109,10 @@
virtual void Initialize(ASTContext &Context) {
IndexCtx.setASTContext(Context);
- IndexCtx.invokeStartedTranslationUnit();
+ IndexCtx.startedTranslationUnit();
}
virtual void HandleTranslationUnit(ASTContext &Ctx) {
- IndexCtx.invokeFinishedTranslationUnit();
}
virtual void HandleTopLevelDecl(DeclGroupRef DG) {
@@ -404,41 +372,57 @@
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) {
+const CXIdxObjCContainerDeclInfo *
+clang_index_getObjCContainerDeclInfo(const CXIdxDeclInfo *DInfo) {
+ if (!DInfo)
+ return 0;
+
if (clang_index_isEntityObjCContainerKind(DInfo->entityInfo->kind))
- return &static_cast<ObjCContainerDeclInfo*>(DInfo)->CXObjCContDeclInfo;
+ return &static_cast<const ObjCContainerDeclInfo*>(DInfo)->ObjCContDeclInfo;
return 0;
}
-int clang_index_isEntityObjCCategoryKind(CXIdxEntityKind K) {
- return K == CXIdxEntity_ObjCCategory;
+const CXIdxObjCInterfaceDeclInfo *
+clang_index_getObjCInterfaceDeclInfo(const CXIdxDeclInfo *DInfo) {
+ if (!DInfo || DInfo->entityInfo->kind != CXIdxEntity_ObjCClass)
+ return 0;
+
+ if (const CXIdxObjCContainerDeclInfo *
+ ContInfo = clang_index_getObjCContainerDeclInfo(DInfo)) {
+ if (ContInfo->kind == CXIdxObjCContainer_Interface)
+ return &static_cast<const ObjCInterfaceDeclInfo*>(DInfo)->ObjCInterDeclInfo;
+ }
+
+ return 0;
}
-CXIdxObjCCategoryDeclInfo *
-clang_index_getObjCCategoryDeclInfo(CXIdxDeclInfo *DInfo){
- if (clang_index_isEntityObjCCategoryKind(DInfo->entityInfo->kind))
- return &static_cast<ObjCCategoryDeclInfo*>(DInfo)->CXObjCCatDeclInfo;
+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;
+ }
return 0;
}
+const CXIdxObjCCategoryDeclInfo *
+clang_index_getObjCCategoryDeclInfo(const CXIdxDeclInfo *DInfo){
+ if (!DInfo || DInfo->entityInfo->kind != CXIdxEntity_ObjCCategory)
+ return 0;
+
+ return &static_cast<const ObjCCategoryDeclInfo*>(DInfo)->ObjCCatDeclInfo;
+}
+
int clang_indexTranslationUnit(CXIndex CIdx,
CXClientData client_data,
IndexerCallbacks *index_callbacks,
Modified: cfe/trunk/tools/libclang/IndexingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/IndexingContext.cpp?rev=144446&r1=144445&r2=144446&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/IndexingContext.cpp (original)
+++ cfe/trunk/tools/libclang/IndexingContext.cpp Fri Nov 11 20:16:30 2011
@@ -18,6 +18,30 @@
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 @@
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::handleDecl(const NamedDecl *D,
SourceLocation Loc, CXCursor Cursor,
bool isRedeclaration, bool isDefinition,
+ bool isContainer,
DeclInfo &DInfo) {
if (!CB.indexDeclaration)
return;
@@ -127,11 +112,12 @@
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 @@
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::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::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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
StrAdapter &SA) {
D = getEntityDecl(D);
EntityInfo.kind = CXIdxEntity_Unexposed;
- EntityInfo.clientEntity = getClientEntity(D);
if (const TagDecl *TD = dyn_cast<TagDecl>(D)) {
switch (TD->getTagKind()) {
Modified: cfe/trunk/tools/libclang/IndexingContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/IndexingContext.h?rev=144446&r1=144445&r2=144446&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/IndexingContext.h (original)
+++ cfe/trunk/tools/libclang/IndexingContext.h Fri Nov 11 20:16:30 2011
@@ -10,7 +10,7 @@
#include "Index_Internal.h"
#include "CXCursor.h"
-#include "clang/AST/Decl.h"
+#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclGroup.h"
#include "llvm/ADT/DenseMap.h"
@@ -26,16 +26,20 @@
CXIdxEntityInfo CXEntInfo;
};
-struct TagDeclInfo : public DeclInfo {
- CXIdxTagDeclInfo CXTagDeclInfo;
-};
-
struct ObjCContainerDeclInfo : public DeclInfo {
- CXIdxObjCContainerDeclInfo CXObjCContDeclInfo;
+ CXIdxObjCContainerDeclInfo ObjCContDeclInfo;
};
struct ObjCCategoryDeclInfo : public ObjCContainerDeclInfo {
- CXIdxObjCCategoryDeclInfo CXObjCCatDeclInfo;
+ CXIdxObjCCategoryDeclInfo ObjCCatDeclInfo;
+};
+
+struct ObjCInterfaceDeclInfo : public ObjCCategoryDeclInfo {
+ CXIdxObjCInterfaceDeclInfo ObjCInterDeclInfo;
+};
+
+struct ObjCProtocolDeclInfo : public ObjCCategoryDeclInfo {
+ CXIdxObjCProtocolDeclInfo ObjCProtoDeclInfo;
};
class IndexingContext {
@@ -46,12 +50,8 @@
CXTranslationUnit CXTU;
typedef llvm::DenseMap<const FileEntry *, CXIdxClientFile> FileMapTy;
- typedef llvm::DenseMap<const NamedDecl *, CXIdxClientEntity> EntityMapTy;
- typedef llvm::DenseMap<const void *, CXIdxClientMacro> MacroMapTy;
typedef llvm::DenseMap<const DeclContext *, CXIdxClientContainer> ContainerMapTy;
FileMapTy FileMap;
- EntityMapTy EntityMap;
- MacroMapTy MacroMap;
ContainerMapTy ContainerMap;
SmallVector<DeclGroupRef, 8> TUDeclsInObjCContainer;
@@ -87,6 +87,19 @@
SmallVectorImpl<char> &getBuffer() { return Scratch; }
};
+ struct ObjCProtocolListInfo {
+ SmallVector<CXIdxObjCProtocolRefInfo, 4> ProtInfos;
+ SmallVector<CXIdxEntityInfo, 4> ProtEntities;
+ SmallVector<CXIdxObjCProtocolRefInfo *, 4> Prots;
+
+ CXIdxObjCProtocolRefInfo **getProtocolRefs() { return Prots.data(); }
+ unsigned getNumProtocols() { return (unsigned)Prots.size(); }
+
+ ObjCProtocolListInfo(const ObjCProtocolList &ProtList,
+ IndexingContext &IdxCtx,
+ IndexingContext::StrAdapter &SA);
+ };
+
public:
IndexingContext(CXClientData clientData, IndexerCallbacks &indexCallbacks,
unsigned indexOptions, CXTranslationUnit cxTU)
@@ -103,19 +116,7 @@
StringRef filename, const FileEntry *File,
bool isImport, bool isAngled);
- void ppMacroDefined(SourceLocation Loc, StringRef Name,
- SourceLocation DefBegin, unsigned Length,
- const void *OpaqueMacro);
-
- void ppMacroUndefined(SourceLocation Loc, StringRef Name,
- const void *OpaqueMacro);
-
- void ppMacroExpanded(SourceLocation Loc, StringRef Name,
- const void *OpaqueMacro);
-
- void invokeStartedTranslationUnit();
-
- void invokeFinishedTranslationUnit();
+ void startedTranslationUnit();
void indexDecl(const Decl *D);
@@ -148,8 +149,6 @@
void handleObjCClass(const ObjCClassDecl *D);
void handleObjCInterface(const ObjCInterfaceDecl *D);
void handleObjCImplementation(const ObjCImplementationDecl *D);
-
- void defineObjCInterface(const ObjCInterfaceDecl *D);
void handleObjCForwardProtocol(const ObjCProtocolDecl *D,
SourceLocation Loc,
@@ -169,11 +168,6 @@
const DeclContext *DC,
const Expr *E = 0,
CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct);
-
- void startContainer(const NamedDecl *D, bool isStmtBody = false,
- const DeclContext *DC = 0);
-
- void endContainer(const DeclContext *DC);
bool isNotFromSourceFile(SourceLocation Loc) const;
@@ -190,7 +184,7 @@
private:
void handleDecl(const NamedDecl *D,
SourceLocation Loc, CXCursor Cursor,
- bool isRedeclaration, bool isDefinition,
+ bool isRedeclaration, bool isDefinition, bool isContainer,
DeclInfo &DInfo);
void handleObjCContainer(const ObjCContainerDecl *D,
@@ -200,12 +194,8 @@
bool isImplementation,
ObjCContainerDeclInfo &ContDInfo);
- void addEntityInMap(const NamedDecl *D, CXIdxClientEntity entity);
-
void addContainerInMap(const DeclContext *DC, CXIdxClientContainer container);
- CXIdxClientEntity getClientEntity(const NamedDecl *D);
-
const NamedDecl *getEntityDecl(const NamedDecl *D) const;
CXIdxClientContainer getIndexContainer(const NamedDecl *D) const {
Modified: cfe/trunk/tools/libclang/libclang.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.exports?rev=144446&r1=144445&r2=144446&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/libclang.exports (original)
+++ cfe/trunk/tools/libclang/libclang.exports Fri Nov 11 20:16:30 2011
@@ -137,10 +137,9 @@
clang_hashCursor
clang_index_getObjCCategoryDeclInfo
clang_index_getObjCContainerDeclInfo
-clang_index_getTagDeclInfo
-clang_index_isEntityObjCCategoryKind
+clang_index_getObjCInterfaceDeclInfo
+clang_index_getObjCProtocolDeclInfo
clang_index_isEntityObjCContainerKind
-clang_index_isEntityTagKind
clang_indexLoc_getCXSourceLocation
clang_indexLoc_getFileLocation
clang_indexTranslationUnit
More information about the cfe-commits
mailing list