[cfe-commits] r144343 - 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
Thu Nov 10 16:23:36 PST 2011
Author: akirtzidis
Date: Thu Nov 10 18:23:36 2011
New Revision: 144343
URL: http://llvm.org/viewvc/llvm-project?rev=144343&view=rev
Log:
[libclang] Simplify the indexing API.
Cut down the number of callbacks to more generic ones. Clients can check
an enum to find out what kind of declaration it is and they can call functions
to get more specific information than the generic provided info.
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=144343&r1=144342&r2=144343&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Thu Nov 10 18:23:36 2011
@@ -3938,7 +3938,7 @@
/**
* \brief The client's data object that is associated with a CXFile.
*/
-typedef void *CXIdxFile;
+typedef void *CXIdxClientFile;
/**
* \brief The client's data object that is associated with a unique entity in
@@ -3952,7 +3952,7 @@
*
* In the example above there is only one entity introduced, the class 'Foo'.
*/
-typedef void *CXIdxEntity;
+typedef void *CXIdxClientEntity;
/**
* \brief The client's data object that is associated with a semantic container
@@ -3983,23 +3983,22 @@
* 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 *CXIdxContainer;
+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 *CXIdxMacro;
+typedef void *CXIdxClientMacro;
/**
* \brief The client's data object that is associated with an AST file (PCH
* or module).
*/
-typedef void *CXIdxASTFile;
+typedef void *CXIdxClientASTFile;
/**
- * \brief The client's data object that is associated with an AST file (PCH
- * or module).
+ * \brief Source location passed to index callbacks.
*/
typedef struct {
void *ptr_data[2];
@@ -4021,7 +4020,7 @@
/**
* \brief The actual file that the #include/#import directive resolved to.
*/
- CXIdxFile file;
+ CXFile file;
int isImport;
int isAngled;
} CXIdxIncludedFileInfo;
@@ -4068,7 +4067,7 @@
typedef struct {
CXIdxLoc loc;
const char *name;
- CXIdxMacro macro;
+ CXIdxClientMacro macro;
} CXIdxMacroUndefinedInfo;
/**
@@ -4077,20 +4076,47 @@
typedef struct {
CXIdxLoc loc;
const char *name;
- CXIdxMacro macro;
+ CXIdxClientMacro macro;
} CXIdxMacroExpandedInfo;
+/**
+ * \brief Data for \see importedMacro callback.
+ */
+typedef struct {
+ CXIdxMacroInfo *macroInfo;
+ CXIdxClientASTFile ASTFile;
+} CXIdxImportedMacroInfo;
+
+typedef enum {
+ CXIdxEntity_Unexposed = 0,
+ CXIdxEntity_Typedef = 1,
+ CXIdxEntity_Function = 2,
+ CXIdxEntity_Variable = 3,
+ CXIdxEntity_Field = 4,
+ CXIdxEntity_EnumConstant = 5,
+
+ CXIdxEntity_ObjCClass = 6,
+ CXIdxEntity_ObjCProtocol = 7,
+ CXIdxEntity_ObjCCategory = 8,
+
+ CXIdxEntity_ObjCMethod = 9,
+ CXIdxEntity_ObjCProperty = 10,
+ CXIdxEntity_ObjCIvar = 11,
+
+ CXIdxEntity_Enum = 12,
+ CXIdxEntity_Struct = 13,
+ CXIdxEntity_Union = 14,
+ CXIdxEntity_CXXClass = 15
+
+} CXIdxEntityKind;
+
typedef struct {
+ CXIdxEntityKind kind;
const char *name;
const char *USR;
+ CXIdxClientEntity clientEntity;
} CXIdxEntityInfo;
-typedef struct {
- CXCursor cursor;
- CXIdxLoc loc;
- CXIdxContainer container;
-} CXIdxIndexedDeclInfo;
-
/**
* \brief Data for \see importedEntity callback.
*/
@@ -4098,177 +4124,51 @@
CXIdxEntityInfo *entityInfo;
CXCursor cursor;
CXIdxLoc loc;
- CXIdxASTFile ASTFile;
+ CXIdxClientASTFile ASTFile;
} CXIdxImportedEntityInfo;
-/**
- * \brief Data for \see importedMacro callback.
- */
-typedef struct {
- CXIdxMacroInfo *macroInfo;
- CXIdxASTFile ASTFile;
-} CXIdxImportedMacroInfo;
-
-typedef struct {
- CXIdxEntityInfo *entityInfo;
- CXIdxIndexedDeclInfo *declInfo;
-} CXIdxIndexedEntityInfo;
-
-typedef struct {
- CXIdxIndexedDeclInfo *declInfo;
- CXIdxEntity entity;
-} CXIdxIndexedRedeclInfo;
-
typedef struct {
+ CXIdxEntityInfo *entity;
CXCursor cursor;
CXIdxLoc loc;
- CXIdxEntity entity;
+ int isObjCImpl;
} CXIdxContainerInfo;
-/**
- * \brief Data for \see indexTypedef callback.
- */
-typedef struct {
- CXIdxIndexedEntityInfo *indexedEntityInfo;
-} CXIdxTypedefInfo;
-
-/**
- * \brief Data for \see indexFunction callback.
- */
-typedef struct {
- CXIdxIndexedEntityInfo *indexedEntityInfo;
- int isDefinition;
-} CXIdxFunctionInfo;
-
-/**
- * \brief Data for \see indexFunctionRedeclaration callback.
- */
-typedef struct {
- CXIdxIndexedRedeclInfo *indexedRedeclInfo;
- int isDefinition;
-} CXIdxFunctionRedeclInfo;
-
-/**
- * \brief Data for \see indexVariable callback.
- */
-typedef struct {
- CXIdxIndexedEntityInfo *indexedEntityInfo;
- int isDefinition;
-} CXIdxVariableInfo;
-
-/**
- * \brief Data for \see indexVariableRedeclaration callback.
- */
typedef struct {
- CXIdxIndexedRedeclInfo *indexedRedeclInfo;
+ CXIdxEntityInfo *entityInfo;
+ CXCursor cursor;
+ CXIdxLoc loc;
+ CXIdxClientContainer container;
+ int isRedeclaration;
int isDefinition;
-} CXIdxVariableRedeclInfo;
+} CXIdxDeclInfo;
-/**
- * \brief Data for \see indexTagType callback.
- */
typedef struct {
- CXIdxIndexedEntityInfo *indexedEntityInfo;
- int isDefinition;
+ CXIdxDeclInfo *declInfo;
int isAnonymous;
-} CXIdxTagTypeInfo;
-
-/**
- * \brief Data for \see indexTagTypeRedeclaration callback.
- */
-typedef struct {
- CXIdxIndexedRedeclInfo *indexedRedeclInfo;
- int isDefinition;
-} CXIdxTagTypeRedeclInfo;
-
-/**
- * \brief Data for \see startedTagTypeDefinition callback.
- */
-typedef struct {
- CXIdxContainerInfo *containerInfo;
-} CXIdxTagTypeDefinitionInfo;
-
-/**
- * \brief Data for \see indexField callback.
- */
-typedef struct {
- CXIdxIndexedEntityInfo *indexedEntityInfo;
-} CXIdxFieldInfo;
-
-/**
- * \brief Data for \see indexEnumerator callback.
- */
-typedef struct {
- CXIdxIndexedEntityInfo *indexedEntityInfo;
-} CXIdxEnumeratorInfo;
-
-/**
- * \brief Data for \see indexObjCClass callback.
- */
-typedef struct {
- CXIdxIndexedEntityInfo *indexedEntityInfo;
- int isForwardRef;
-} CXIdxObjCClassInfo;
-
-/**
- * \brief Data for \see indexObjCProtocol callback.
- */
-typedef struct {
- CXIdxIndexedEntityInfo *indexedEntityInfo;
- int isForwardRef;
-} CXIdxObjCProtocolInfo;
-
-/**
- * \brief Data for \see indexObjCCategory callback.
- */
-typedef struct {
- CXIdxIndexedEntityInfo *indexedEntityInfo;
- CXIdxEntity objcClass;
-} CXIdxObjCCategoryInfo;
-
-/**
- * \brief Data for \see indexObjCMethod callback.
- */
-typedef struct {
- CXIdxIndexedEntityInfo *indexedEntityInfo;
- int isDefinition;
-} CXIdxObjCMethodInfo;
+} CXIdxTagDeclInfo;
-/**
- * \brief Data for \see indexObjCProperty callback.
- */
-typedef struct {
- CXIdxIndexedEntityInfo *indexedEntityInfo;
-} CXIdxObjCPropertyInfo;
-
-/**
- * \brief Data for \see indexObjCMethodRedeclaration callback.
- */
-typedef struct {
- CXIdxIndexedRedeclInfo *indexedRedeclInfo;
- int isDefinition;
-} CXIdxObjCMethodRedeclInfo;
+typedef enum {
+ CXIdxObjCContainer_ForwardRef = 0,
+ CXIdxObjCContainer_Interface = 1,
+ CXIdxObjCContainer_Implementation = 2
+} CXIdxObjCContainerKind;
-/**
- * \brief Data for \see startedStatementBody callback.
- */
typedef struct {
- CXIdxContainerInfo *containerInfo;
- CXIdxLoc bodyBegin;
-} CXIdxStmtBodyInfo;
+ CXIdxDeclInfo *declInfo;
+ CXIdxObjCContainerKind kind;
+} CXIdxObjCContainerDeclInfo;
-/**
- * \brief Data for \see startedObjCContainer callback.
- */
typedef struct {
- CXIdxContainerInfo *containerInfo;
-} CXIdxObjCContainerInfo;
+ CXIdxObjCContainerDeclInfo *containerInfo;
+ CXIdxEntityInfo *objcClass;
+} CXIdxObjCCategoryDeclInfo;
/**
* \brief Data for \see defineObjCClass callback.
*/
typedef struct {
- CXIdxEntity objcClass;
+ CXIdxEntityInfo *objcClass;
CXIdxLoc loc;
} CXIdxObjCBaseClassInfo;
@@ -4276,7 +4176,7 @@
* \brief Data for \see defineObjCClass callback.
*/
typedef struct {
- CXIdxEntity protocol;
+ CXIdxEntityInfo *protocol;
CXIdxLoc loc;
} CXIdxObjCProtocolRefInfo;
@@ -4285,8 +4185,8 @@
*/
typedef struct {
CXCursor cursor;
- CXIdxEntity objcClass;
- CXIdxContainer container;
+ CXIdxEntityInfo *objcClass;
+ CXIdxClientContainer container;
CXIdxObjCBaseClassInfo *baseInfo;
CXIdxObjCProtocolRefInfo **protocols;
unsigned numProtocols;
@@ -4296,7 +4196,7 @@
* \brief Data for \see endedContainer callback.
*/
typedef struct {
- CXIdxContainer container;
+ CXIdxClientContainer container;
CXIdxLoc endLoc;
} CXIdxEndContainerInfo;
@@ -4326,7 +4226,7 @@
/**
* \brief The entity that gets referenced.
*/
- CXIdxEntity referencedEntity;
+ CXIdxEntityInfo *referencedEntity;
/**
* \brief Immediate "parent" of the reference. For example:
*
@@ -4337,11 +4237,11 @@
* The parent of reference of type 'Foo' is the variable 'var'.
* parentEntity will be null for references inside statement bodies.
*/
- CXIdxEntity parentEntity;
+ CXIdxEntityInfo *parentEntity;
/**
* \brief Container context of the reference.
*/
- CXIdxContainer container;
+ CXIdxClientContainer container;
CXIdxEntityRefKind kind;
} CXIdxEntityRefInfo;
@@ -4352,23 +4252,19 @@
void (*diagnostic)(CXClientData client_data,
CXDiagnostic, void *reserved);
- /**
- * \brief Called for the purpose of associating a client's CXIdxFile with
- * a CXFile.
- */
- CXIdxFile (*recordFile)(CXClientData client_data,
- CXFile file, void *reserved);
-
+ CXIdxClientFile (*enteredMainFile)(CXClientData client_data,
+ CXFile mainFile, void *reserved);
+
/**
* \brief Called when a file gets #included/#imported.
*/
- void (*ppIncludedFile)(CXClientData client_data,
- CXIdxIncludedFileInfo *);
+ CXIdxClientFile (*ppIncludedFile)(CXClientData client_data,
+ CXIdxIncludedFileInfo *);
/**
* \brief Called when a macro gets #defined.
*/
- CXIdxMacro (*ppMacroDefined)(CXClientData client_data,
+ CXIdxClientMacro (*ppMacroDefined)(CXClientData client_data,
CXIdxMacroDefinedInfo *);
/**
@@ -4393,138 +4289,37 @@
* the AST file can be later associated with CXIdxEntities returned by
* \see importedEntity callbacks.
*/
- CXIdxASTFile (*importedASTFile)(CXClientData client_data,
+ 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.
*/
- CXIdxEntity (*importedEntity)(CXClientData client_data,
- CXIdxImportedEntityInfo *);
+ 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.
*/
- CXIdxEntity (*importedMacro)(CXClientData client_data,
- CXIdxImportedMacroInfo *);
+ CXIdxClientMacro (*importedMacro)(CXClientData client_data,
+ CXIdxImportedMacroInfo *);
/**
* \brief Called at the beginning of indexing a translation unit.
*/
- CXIdxContainer (*startedTranslationUnit)(CXClientData client_data,
+ CXIdxClientContainer (*startedTranslationUnit)(CXClientData client_data,
void *reserved);
- /**
- * \brief Called to index a typedef entity.
- */
- CXIdxEntity (*indexTypedef)(CXClientData client_data,
- CXIdxTypedefInfo *);
-
- /**
- * \brief Called to index a function entity.
- */
- CXIdxEntity (*indexFunction)(CXClientData client_data,
- CXIdxFunctionInfo *);
-
- /**
- * \brief Called to index a function redeclaration.
- */
- void (*indexFunctionRedeclaration)(CXClientData client_data,
- CXIdxFunctionRedeclInfo *);
-
- /**
- * \brief Called to index a file-scope variable (not field or ivar).
- */
- CXIdxEntity (*indexVariable)(CXClientData client_data,
- CXIdxVariableInfo *);
-
- /**
- * \brief Called to index a variable redeclaration.
- */
- void (*indexVariableRedeclaration)(CXClientData client_data,
- CXIdxVariableRedeclInfo *);
-
- /**
- * \brief Called to index a tag entity (struct/union/enum/class).
- */
- CXIdxEntity (*indexTagType)(CXClientData client_data,
- CXIdxTagTypeInfo *);
-
- /**
- * \brief Called to index a tag redeclaration.
- */
- void (*indexTagTypeRedeclaration)(CXClientData client_data,
- CXIdxTagTypeRedeclInfo *);
-
- /**
- * \brief Called to index a tag type's field entity.
- */
- CXIdxEntity (*indexField)(CXClientData client_data,
- CXIdxFieldInfo *);
-
- /**
- * \brief Called to index an enumerator entity.
- */
- CXIdxEntity (*indexEnumerator)(CXClientData client_data,
- CXIdxEnumeratorInfo *);
-
- /**
- * \brief Called to initiate a tag type's container context.
- */
- CXIdxContainer (*startedTagTypeDefinition)(CXClientData client_data,
- CXIdxTagTypeDefinitionInfo *);
-
- /**
- * \brief Called to index an ObjC class entity.
- */
- CXIdxEntity (*indexObjCClass)(CXClientData client_data,
- CXIdxObjCClassInfo *);
-
- /**
- * \brief Called to index an ObjC protocol entity.
- */
- CXIdxEntity (*indexObjCProtocol)(CXClientData client_data,
- CXIdxObjCProtocolInfo *);
-
- /**
- * \brief Called to index an ObjC category entity.
- */
- CXIdxEntity (*indexObjCCategory)(CXClientData client_data,
- CXIdxObjCCategoryInfo *);
-
- /**
- * \brief Called to index an ObjC method entity.
- */
- CXIdxEntity (*indexObjCMethod)(CXClientData client_data,
- CXIdxObjCMethodInfo *);
-
- /**
- * \brief Called to index an ObjC property entity.
- */
- CXIdxEntity (*indexObjCProperty)(CXClientData client_data,
- CXIdxObjCPropertyInfo *);
-
- /**
- * \brief Called to index an ObjC method redeclaration.
- */
- void (*indexObjCMethodRedeclaration)(CXClientData client_data,
- CXIdxObjCMethodRedeclInfo *);
-
- /**
- * \brief Called to initiate a statement body container context for a
- * function/ObjC method/C++ member function/block.
- */
- CXIdxContainer (*startedStatementBody)(CXClientData client_data,
- CXIdxStmtBodyInfo *);
+ CXIdxClientEntity (*indexDeclaration)(CXClientData client_data,
+ CXIdxDeclInfo *);
/**
- * \brief Called to initiate an ObjC container context for
- * @interface/@implementation/@protocol.
+ * \brief Called to initiate a container context.
*/
- CXIdxContainer (*startedObjCContainer)(CXClientData client_data,
- CXIdxObjCContainerInfo *);
+ CXIdxClientContainer (*startedContainer)(CXClientData client_data,
+ CXIdxContainerInfo *);
/**
* \brief Called to define an ObjC class via its @interface.
@@ -4546,6 +4341,16 @@
} IndexerCallbacks;
+int clang_index_isEntityTagKind(CXIdxEntityKind);
+CXIdxTagDeclInfo *clang_index_getTagDeclInfo(CXIdxDeclInfo *);
+
+int clang_index_isEntityObjCContainerKind(CXIdxEntityKind);
+CXIdxObjCContainerDeclInfo *
+clang_index_getObjCContainerDeclInfo(CXIdxDeclInfo *);
+
+int clang_index_isEntityObjCCategoryKind(CXIdxEntityKind);
+CXIdxObjCCategoryDeclInfo *clang_index_getObjCCategoryDeclInfo(CXIdxDeclInfo *);
+
/**
* \brief Index the given source file and the translation unit corresponding
* to that file via callbacks implemented through \see IndexerCallbacks.
@@ -4591,7 +4396,7 @@
* retrieves the location of the argument.
*/
CINDEX_LINKAGE void clang_indexLoc_getFileLocation(CXIdxLoc loc,
- CXIdxFile *indexFile,
+ CXIdxClientFile *indexFile,
CXFile *file,
unsigned *line,
unsigned *column,
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=144343&r1=144342&r2=144343&view=diff
==============================================================================
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Thu Nov 10 18:23:36 2011
@@ -1547,7 +1547,7 @@
}
}
-static void printCXIndexFile(CXIdxFile file) {
+static void printCXIndexFile(CXIdxClientFile file) {
CXString filename = clang_getFileName((CXFile)file);
printf("%s", clang_getCString(filename));
clang_disposeString(filename);
@@ -1556,7 +1556,7 @@
static void printCXIndexLoc(CXIdxLoc loc) {
CXString filename;
const char *cname, *end;
- CXIdxFile file;
+ CXIdxClientFile file;
unsigned line, column;
int isHeader;
@@ -1577,88 +1577,63 @@
printf("%d:%d", line, column);
}
-static CXIdxEntity makeCXIndexEntity(CXIdxIndexedEntityInfo *info) {
+static CXIdxClientEntity makeClientEntity(CXIdxEntityInfo *info, CXIdxLoc loc) {
const char *name;
- CXIdxLoc loc;
char *newStr;
- CXIdxFile file;
+ CXIdxClientFile file;
unsigned line, column;
- name = info->entityInfo->name;
+ name = info->name;
if (!name)
name = "<anon-tag>";
- loc = info->declInfo->loc;
clang_indexLoc_getFileLocation(loc, &file, 0, &line, &column, 0);
/* FIXME: free these.*/
newStr = (char *)malloc(strlen(name) + 10);
sprintf(newStr, "%s:%d:%d", name, line, column);
- return (CXIdxEntity)newStr;
+ return (CXIdxClientEntity)newStr;
}
-static CXIdxContainer makeCXIndexContainer(CXIdxEntity entity) {
- return (CXIdxContainer)entity;
-}
-
-static void printCXIndexEntity(CXIdxEntity entity) {
- printf("{%s}", (const char *)entity);
-}
-
-static void printCXIndexContainer(CXIdxContainer container) {
+static void printCXIndexContainer(CXIdxClientContainer container) {
printf("[%s]", (const char *)container);
}
-static void printIndexedDeclInfo(CXIdxIndexedDeclInfo *info) {
- printf(" | cursor: ");
- PrintCursor(info->cursor);
- printf(" | loc: ");
- printCXIndexLoc(info->loc);
- printf(" | container: ");
- printCXIndexContainer(info->container);
+static const char *getEntityKindString(CXIdxEntityKind kind) {
+ switch (kind) {
+ case CXIdxEntity_Unexposed: return "<<UNEXPOSED>>";
+ case CXIdxEntity_Typedef: return "typedef";
+ case CXIdxEntity_Function: return "function";
+ case CXIdxEntity_Variable: return "variable";
+ case CXIdxEntity_Field: return "field";
+ case CXIdxEntity_EnumConstant: return "enumerator";
+ 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_ObjCProperty: return "objc-property";
+ case CXIdxEntity_ObjCIvar: return "objc-ivar";
+ case CXIdxEntity_Enum: return "enum";
+ case CXIdxEntity_Struct: return "struct";
+ case CXIdxEntity_Union: return "union";
+ case CXIdxEntity_CXXClass: return "c++-class";
+ }
}
-static void printIndexedEntityInfo(const char *cb,
- CXClientData client_data,
- CXIdxIndexedEntityInfo *info) {
+static void printEntityInfo(const char *cb,
+ CXClientData client_data,
+ CXIdxEntityInfo *info) {
const char *name;
IndexData *index_data;
index_data = (IndexData *)client_data;
printCheck(index_data);
- name = info->entityInfo->name;
+ name = info->name;
if (!name)
name = "<anon-tag>";
- printf("%s: %s", cb, info->entityInfo->name);
- printIndexedDeclInfo(info->declInfo);
- printf(" | USR: %s", info->entityInfo->USR);
-}
-
-static void printIndexedRedeclInfo(const char *cb,
- CXClientData client_data,
- CXIdxIndexedRedeclInfo *info) {
- IndexData *index_data;
- index_data = (IndexData *)client_data;
- printCheck(index_data);
-
- printf("%s redeclaration: ", cb);
- printCXIndexEntity(info->entity);
- printIndexedDeclInfo(info->declInfo);
-}
-
-static void printStartedContainerInfo(const char *cb,
- CXClientData client_data,
- CXIdxContainerInfo *info) {
- IndexData *index_data;
- index_data = (IndexData *)client_data;
- printCheck(index_data);
-
- printf("%s: ", cb);
- printCXIndexEntity(info->entity);
- printf(" | cursor: ");
- PrintCursor(info->cursor);
- printf(" | loc: ");
- printCXIndexLoc(info->loc);
+ printf("%s: kind: %s", cb, getEntityKindString(info->kind));
+ printf(" | name: %s", name);
+ printf(" | USR: %s", info->USR);
}
static void index_diagnostic(CXClientData client_data,
@@ -1680,26 +1655,36 @@
}
}
-static CXIdxFile index_recordFile(CXClientData client_data,
- CXFile file, void *reserved) {
- return (CXIdxFile)file;
+static CXIdxClientFile index_enteredMainFile(CXClientData client_data,
+ CXFile file, void *reserved) {
+ IndexData *index_data;
+ index_data = (IndexData *)client_data;
+ printCheck(index_data);
+
+ printf("[enteredMainFile]: ");
+ printCXIndexFile((CXIdxClientFile)file);
+ printf("\n");
+
+ return (CXIdxClientFile)file;
}
-static void index_ppIncludedFile(CXClientData client_data,
- CXIdxIncludedFileInfo *info) {
+static CXIdxClientFile index_ppIncludedFile(CXClientData client_data,
+ CXIdxIncludedFileInfo *info) {
IndexData *index_data;
index_data = (IndexData *)client_data;
printCheck(index_data);
printf("[ppIncludedFile]: ");
- printCXIndexFile(info->file);
+ printCXIndexFile((CXIdxClientFile)info->file);
printf(" | name: \"%s\"", info->filename);
printf(" | hash loc: ");
printCXIndexLoc(info->hashLoc);
printf(" | isImport: %d | isAngled: %d\n", info->isImport, info->isAngled);
+
+ return (CXIdxClientFile)info->file;
}
-static CXIdxMacro index_ppMacroDefined(CXClientData client_data,
+static CXIdxClientMacro index_ppMacroDefined(CXClientData client_data,
CXIdxMacroDefinedInfo *info) {
IndexData *index_data;
index_data = (IndexData *)client_data;
@@ -1712,7 +1697,7 @@
printCXIndexLoc(info->defBegin);
printf(" | length: %d\n", info->defLength);
- return (CXIdxMacro)info->macroInfo->name;
+ return (CXIdxClientMacro)info->macroInfo->name;
}
static void index_ppMacroUndefined(CXClientData client_data,
@@ -1739,217 +1724,105 @@
printf("\n");
}
-static CXIdxEntity index_importedEntity(CXClientData client_data,
+static CXIdxClientEntity index_importedEntity(CXClientData client_data,
CXIdxImportedEntityInfo *info) {
IndexData *index_data;
- CXIdxIndexedDeclInfo DeclInfo;
- CXIdxIndexedEntityInfo EntityInfo;
- const char *name;
- DeclInfo.cursor = info->cursor;
- DeclInfo.loc = info->loc;
- DeclInfo.container = 0;
- EntityInfo.entityInfo = info->entityInfo;
- EntityInfo.declInfo = &DeclInfo;
index_data = (IndexData *)client_data;
printCheck(index_data);
- name = info->entityInfo->name;
- if (!name)
- name = "<anon-tag>";
-
- printf("[importedEntity]: %s", name);
+ printEntityInfo("[importedEntity]", client_data, info->entityInfo);
printf(" | cursor: ");
PrintCursor(info->cursor);
printf(" | loc: ");
printCXIndexLoc(info->loc);
printf("\n");
- return makeCXIndexEntity(&EntityInfo);
+ return makeClientEntity(info->entityInfo, info->loc);
}
-static CXIdxContainer index_startedTranslationUnit(CXClientData client_data,
+static CXIdxClientContainer index_startedTranslationUnit(CXClientData client_data,
void *reserved) {
IndexData *index_data;
index_data = (IndexData *)client_data;
printCheck(index_data);
printf("[startedTranslationUnit]\n");
- return (CXIdxContainer)"TU";
-}
-
-static CXIdxEntity index_indexTypedef(CXClientData client_data,
- CXIdxTypedefInfo *info) {
- printIndexedEntityInfo("[indexTypedef]", client_data, info->indexedEntityInfo);
- printf("\n");
-
- return makeCXIndexEntity(info->indexedEntityInfo);
-}
-
-static CXIdxEntity index_indexFunction(CXClientData client_data,
- CXIdxFunctionInfo *info) {
- printIndexedEntityInfo("[indexFunction]", client_data, info->indexedEntityInfo);
- printf(" | isDefinition: %d\n", info->isDefinition);
-
- return makeCXIndexEntity(info->indexedEntityInfo);
-}
-
-static void index_indexFunctionRedeclaration(CXClientData client_data,
- CXIdxFunctionRedeclInfo *info) {
- printIndexedRedeclInfo("[indexFunctionRedeclaration]", client_data,
- info->indexedRedeclInfo);
- printf(" | isDefinition: %d\n", info->isDefinition);
-}
-
-static CXIdxEntity index_indexVariable(CXClientData client_data,
- CXIdxVariableInfo *info) {
- printIndexedEntityInfo("[indexVariable]", client_data, info->indexedEntityInfo);
- printf(" | isDefinition: %d\n", info->isDefinition);
-
- return makeCXIndexEntity(info->indexedEntityInfo);
-}
-
-static void index_indexVariableRedeclaration(CXClientData client_data,
- CXIdxVariableRedeclInfo *info) {
- printIndexedRedeclInfo("[indexVariableRedeclaration]", client_data,
- info->indexedRedeclInfo);
- printf(" | isDefinition: %d\n", info->isDefinition);
-}
-
-static CXIdxEntity index_indexTagType(CXClientData client_data,
- CXIdxTagTypeInfo *info) {
- printIndexedEntityInfo("[indexTagType]", client_data, info->indexedEntityInfo);
- printf(" | isDefinition: %d | anon: %d\n",
- info->isDefinition, info->isAnonymous);
-
- return makeCXIndexEntity(info->indexedEntityInfo);
-}
-
-static void index_indexTagTypeRedeclaration(CXClientData client_data,
- CXIdxTagTypeRedeclInfo *info) {
- printIndexedRedeclInfo("[indexTagTypeRedeclaration]", client_data,
- info->indexedRedeclInfo);
- printf(" | isDefinition: %d\n", info->isDefinition);
+ return (CXIdxClientContainer)"TU";
}
-static CXIdxEntity index_indexField(CXClientData client_data,
- CXIdxFieldInfo *info) {
- printIndexedEntityInfo("[indexField]", client_data, info->indexedEntityInfo);
- printf("\n");
-
- return makeCXIndexEntity(info->indexedEntityInfo);
-}
+static CXIdxClientEntity index_indexDeclaration(CXClientData client_data,
+ CXIdxDeclInfo *info) {
+ IndexData *index_data;
+ index_data = (IndexData *)client_data;
-static CXIdxEntity index_indexEnumerator(CXClientData client_data,
- CXIdxEnumeratorInfo *info) {
- printIndexedEntityInfo("[indexEnumerator]", client_data,
- info->indexedEntityInfo);
- printf("\n");
-
- return makeCXIndexEntity(info->indexedEntityInfo);
-}
+ printEntityInfo("[indexDeclaration]", client_data, info->entityInfo);
+ printf(" | cursor: ");
+ PrintCursor(info->cursor);
+ printf(" | loc: ");
+ printCXIndexLoc(info->loc);
+ printf(" | container: ");
+ printCXIndexContainer(info->container);
+ printf(" | isRedecl: %d", info->isRedeclaration);
+ printf(" | isDef: %d\n", info->isDefinition);
-static CXIdxContainer
-index_startedTagTypeDefinition(CXClientData client_data,
- CXIdxTagTypeDefinitionInfo *info) {
- printStartedContainerInfo("[startedTagTypeDefinition]", client_data,
- info->containerInfo);
- printf("\n");
- return makeCXIndexContainer(info->containerInfo->entity);
-}
-
-static CXIdxEntity index_indexObjCClass(CXClientData client_data,
- CXIdxObjCClassInfo *info) {
- printIndexedEntityInfo("[indexObjCClass]", client_data,
- info->indexedEntityInfo);
- printf(" | forward ref: %d\n", info->isForwardRef);
-
- return makeCXIndexEntity(info->indexedEntityInfo);
-}
-
-static CXIdxEntity index_indexObjCProtocol(CXClientData client_data,
- CXIdxObjCProtocolInfo *info) {
- printIndexedEntityInfo("[indexObjCProtocol]", client_data,
- info->indexedEntityInfo);
- printf(" | forward ref: %d\n", info->isForwardRef);
-
- return makeCXIndexEntity(info->indexedEntityInfo);
-}
-
-static CXIdxEntity index_indexObjCCategory(CXClientData client_data,
- CXIdxObjCCategoryInfo *info) {
- printIndexedEntityInfo("[indexObjCCategory]", client_data,
- info->indexedEntityInfo);
- printf(" | class: ");
- printCXIndexEntity(info->objcClass);
- printf("\n");
-
- return makeCXIndexEntity(info->indexedEntityInfo);
-}
-
-static CXIdxEntity index_indexObjCMethod(CXClientData client_data,
- CXIdxObjCMethodInfo *info) {
- printIndexedEntityInfo("[indexObjCMethod]", client_data,
- info->indexedEntityInfo);
- printf(" | isDefinition: %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;
+ switch (K) {
+ case CXIdxObjCContainer_ForwardRef:
+ kindName = "forward-ref"; break;
+ case CXIdxObjCContainer_Interface:
+ kindName = "interface"; break;
+ case CXIdxObjCContainer_Implementation:
+ kindName = "implementation"; break;
+ }
+ printCheck(index_data);
+ printf(" <ObjCContainerInfo>: kind: %s\n", kindName);
+ }
- return makeCXIndexEntity(info->indexedEntityInfo);
-}
+ if (clang_index_isEntityObjCCategoryKind(info->entityInfo->kind)) {
+ CXIdxObjCCategoryDeclInfo *
+ CatInfo = clang_index_getObjCCategoryDeclInfo(info);
+ printEntityInfo(" <ObjCCategoryInfo>: class", client_data,
+ CatInfo->objcClass);
+ printf("\n");
+ }
-static CXIdxEntity index_indexObjCProperty(CXClientData client_data,
- CXIdxObjCPropertyInfo *info) {
- printIndexedEntityInfo("[indexObjCProperty]", client_data,
- info->indexedEntityInfo);
- printf("\n");
+ if (!info->isRedeclaration)
+ return makeClientEntity(info->entityInfo, info->loc);
- return makeCXIndexEntity(info->indexedEntityInfo);
+ return 0;
}
-static void index_indexObjCMethodRedeclaration(CXClientData client_data,
- CXIdxObjCMethodRedeclInfo *info) {
- printIndexedRedeclInfo("[indexObjCMethodRedeclaration]", client_data,
- info->indexedRedeclInfo);
- printf(" | isDefinition: %d\n", info->isDefinition);
-}
-
-static CXIdxContainer
-index_startedStatementBody(CXClientData client_data,
- CXIdxStmtBodyInfo *info) {
- printStartedContainerInfo("[startedStatementBody]", client_data,
- info->containerInfo);
- printf(" | body: ");
- printCXIndexLoc(info->bodyBegin);
- printf("\n");
-
- return makeCXIndexContainer(info->containerInfo->entity);
-}
+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);
-static CXIdxContainer
-index_startedObjCContainer(CXClientData client_data,
- CXIdxObjCContainerInfo *info) {
- printStartedContainerInfo("[startedObjCContainer]", client_data,
- info->containerInfo);
- printf("\n");
-
- return makeCXIndexContainer(info->containerInfo->entity);
+ return (CXIdxClientContainer)info->entity->clientEntity;
}
static void index_defineObjCClass(CXClientData client_data,
CXIdxObjCClassDefineInfo *info) {
- IndexData *index_data;
- index_data = (IndexData *)client_data;
- printCheck(index_data);
-
- printf("[defineObjCClass]: ");
- printCXIndexEntity(info->objcClass);
+ printEntityInfo("[defineObjCClass]", client_data, info->objcClass);
printf(" | cursor: ");
PrintCursor(info->cursor);
printf(" | container: ");
printCXIndexContainer(info->container);
if (info->baseInfo) {
- printf(" | base: ");
- printCXIndexEntity(info->baseInfo->objcClass);
+ printEntityInfo(" | <base>", client_data, info->baseInfo->objcClass);
printf(" | base loc: ");
printCXIndexLoc(info->baseInfo->loc);
}
@@ -1972,18 +1845,12 @@
static void index_indexEntityReference(CXClientData client_data,
CXIdxEntityRefInfo *info) {
- IndexData *index_data;
- index_data = (IndexData *)client_data;
- printCheck(index_data);
-
- printf("[indexEntityReference]: ");
- printCXIndexEntity(info->referencedEntity);
+ printEntityInfo("[indexEntityReference]", client_data, info->referencedEntity);
printf(" | cursor: ");
PrintCursor(info->cursor);
printf(" | loc: ");
printCXIndexLoc(info->loc);
- printf(" | parent: ");
- printCXIndexEntity(info->parentEntity);
+ printEntityInfo(" | <parent>:", client_data, info->parentEntity);
printf(" | container: ");
printCXIndexContainer(info->container);
printf(" | kind: ");
@@ -1996,7 +1863,7 @@
static IndexerCallbacks IndexCB = {
index_diagnostic,
- index_recordFile,
+ index_enteredMainFile,
index_ppIncludedFile,
index_ppMacroDefined,
index_ppMacroUndefined,
@@ -2005,24 +1872,8 @@
index_importedEntity,
0,/*index_importedMacro,*/
index_startedTranslationUnit,
- index_indexTypedef,
- index_indexFunction,
- index_indexFunctionRedeclaration,
- index_indexVariable,
- index_indexVariableRedeclaration,
- index_indexTagType,
- index_indexTagTypeRedeclaration,
- index_indexField,
- index_indexEnumerator,
- index_startedTagTypeDefinition,
- index_indexObjCClass,
- index_indexObjCProtocol,
- index_indexObjCCategory,
- index_indexObjCMethod,
- index_indexObjCProperty,
- index_indexObjCMethodRedeclaration,
- index_startedStatementBody,
- index_startedObjCContainer,
+ 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=144343&r1=144342&r2=144343&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/IndexDecl.cpp (original)
+++ cfe/trunk/tools/libclang/IndexDecl.cpp Thu Nov 10 18:23:36 2011
@@ -29,9 +29,9 @@
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 @@
}
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 @@
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 @@
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;
Modified: cfe/trunk/tools/libclang/IndexTypeSourceInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/IndexTypeSourceInfo.cpp?rev=144343&r1=144342&r2=144343&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/IndexTypeSourceInfo.cpp (original)
+++ cfe/trunk/tools/libclang/IndexTypeSourceInfo.cpp Thu Nov 10 18:23:36 2011
@@ -87,8 +87,8 @@
void IndexingContext::indexTagDecl(const TagDecl *D) {
handleTagDecl(D);
if (D->isThisDeclarationADefinition()) {
- invokeStartedTagTypeDefinition(D);
+ startContainer(D);
indexDeclContext(D);
- invokeEndedContainer(D);
+ endContainer(D);
}
}
Modified: cfe/trunk/tools/libclang/Indexing.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/Indexing.cpp?rev=144343&r1=144342&r2=144343&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/Indexing.cpp (original)
+++ cfe/trunk/tools/libclang/Indexing.cpp Thu Nov 10 18:23:36 2011
@@ -40,10 +40,25 @@
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 @@
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 @@
}
void clang_indexLoc_getFileLocation(CXIdxLoc location,
- CXIdxFile *indexFile,
+ CXIdxClientFile *indexFile,
CXFile *file,
unsigned *line,
unsigned *column,
Modified: cfe/trunk/tools/libclang/IndexingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/IndexingContext.cpp?rev=144343&r1=144342&r2=144343&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/IndexingContext.cpp (original)
+++ cfe/trunk/tools/libclang/IndexingContext.cpp Thu Nov 10 18:23:36 2011
@@ -33,6 +33,13 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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);
- }
-
- addEntityInMap(D, idxEntity);
+void IndexingContext::handleDecl(const NamedDecl *D,
+ SourceLocation Loc, CXCursor Cursor,
+ bool isRedeclaration, bool isDefinition,
+ DeclInfo &DInfo) {
+ if (!CB.indexDeclaration)
+ return;
+
+ 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() };
+ handleDecl(D, Loc, Cursor,
+ isRedeclaration, /*isDefinition=*/!isForwardRef, ContDInfo);
+}
- CB.indexFunctionRedeclaration(ClientData, &Info);
- }
- }
+void IndexingContext::handleFunction(const FunctionDecl *D) {
+ DeclInfo DInfo;
+ handleDecl(D, D->getLocation(), getCursor(D),
+ !D->isFirstDeclaration(), D->isThisDeclarationADefinition(),
+ DInfo);
}
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);
-
- } else {
- if (CB.indexVariableRedeclaration) {
- CXIdxIndexedDeclInfo DeclInfo;
- CXIdxIndexedRedeclInfo RedeclInfo;
- getIndexedRedeclInfo(D, RedeclInfo, DeclInfo);
- CXIdxVariableRedeclInfo Info = { &RedeclInfo,
- D->isThisDeclarationADefinition() };
-
- CB.indexVariableRedeclaration(ClientData, &Info);
- }
- }
+ 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);
-
- CXIdxEntity idxEntity = 0;
- if (CB.indexObjCClass) {
- CXIdxEntityInfo EntityInfo;
- CXIdxIndexedDeclInfo DeclInfo;
- CXIdxIndexedEntityInfo IdxEntityInfo;
- getIndexedEntityInfo(D, IdxEntityInfo, EntityInfo, DeclInfo, SA);
- CXIdxObjCClassInfo Info = { &IdxEntityInfo,
- D->isForwardDecl() };
-
- idxEntity = CB.indexObjCClass(ClientData, &Info);
- }
+ ObjCContainerDeclInfo ContDInfo;
+ handleObjCContainer(D, D->getLocation(), getCursor(D),
+ /*isForwardRef=*/false,
+ /*isRedeclaration=*/D->isInitiallyForwardDecl(),
+ /*isImplementation=*/false, ContDInfo);
+}
+
+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);
+}
+
+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 @@
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 @@
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 @@
}
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
}
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 @@
*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::getContainerInfo(const NamedDecl *D,
- CXIdxContainerInfo &ContainerInfo) {
- ContainerInfo.cursor = getCursor(D);
- ContainerInfo.loc = getIndexLoc(D->getLocation());
- ContainerInfo.entity = getIndexEntity(D);
-}
-
void IndexingContext::getEntityInfo(const NamedDecl *D,
- CXIdxEntityInfo &EntityInfo,
- StrAdapter &SA) {
+ CXIdxEntityInfo &EntityInfo,
+ StrAdapter &SA) {
+ D = getEntityDecl(D);
+ EntityInfo.kind = CXIdxEntity_Unexposed;
+ EntityInfo.clientEntity = getClientEntity(D);
+
+ if (const TagDecl *TD = dyn_cast<TagDecl>(D)) {
+ switch (TD->getTagKind()) {
+ case TTK_Struct:
+ EntityInfo.kind = CXIdxEntity_Struct; break;
+ case TTK_Union:
+ EntityInfo.kind = CXIdxEntity_Union; break;
+ case TTK_Class:
+ EntityInfo.kind = CXIdxEntity_CXXClass; break;
+ case TTK_Enum:
+ EntityInfo.kind = CXIdxEntity_Enum; break;
+ }
+
+ } else {
+ switch (D->getKind()) {
+ case Decl::Typedef:
+ EntityInfo.kind = CXIdxEntity_Typedef; break;
+ case Decl::Function:
+ EntityInfo.kind = CXIdxEntity_Function; break;
+ case Decl::Var:
+ EntityInfo.kind = CXIdxEntity_Variable; break;
+ case Decl::Field:
+ EntityInfo.kind = CXIdxEntity_Field; break;
+ case Decl::EnumConstant:
+ EntityInfo.kind = CXIdxEntity_EnumConstant; break;
+ case Decl::ObjCInterface:
+ EntityInfo.kind = CXIdxEntity_ObjCClass; break;
+ case Decl::ObjCProtocol:
+ EntityInfo.kind = CXIdxEntity_ObjCProtocol; break;
+ case Decl::ObjCCategory:
+ EntityInfo.kind = CXIdxEntity_ObjCCategory; break;
+ case Decl::ObjCMethod:
+ EntityInfo.kind = CXIdxEntity_ObjCMethod; break;
+ case Decl::ObjCProperty:
+ EntityInfo.kind = CXIdxEntity_ObjCProperty; break;
+ case Decl::ObjCIvar:
+ EntityInfo.kind = CXIdxEntity_ObjCIvar; break;
+ default:
+ break;
+ }
+ }
+
if (IdentifierInfo *II = D->getIdentifier()) {
EntityInfo.name = SA.toCStr(II->getName());
} else if (isa<RecordDecl>(D) || isa<NamespaceDecl>(D)) {
- EntityInfo.name = 0;
+ EntityInfo.name = 0; // anonymous record/namespace.
} else {
unsigned Begin = SA.getCurSize();
@@ -677,12 +612,14 @@
EntityInfo.name = SA.getCStr(Begin);
}
- unsigned Begin = SA.getCurSize();
- bool Ignore = getDeclCursorUSR(D, SA.getBuffer());
- if (Ignore) {
- EntityInfo.USR = "";
- } else {
- EntityInfo.USR = SA.getCStr(Begin);
+ {
+ unsigned Begin = SA.getCurSize();
+ bool Ignore = getDeclCursorUSR(D, SA.getBuffer());
+ if (Ignore) {
+ EntityInfo.USR = "";
+ } else {
+ EntityInfo.USR = SA.getCStr(Begin);
+ }
}
}
Modified: cfe/trunk/tools/libclang/IndexingContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/IndexingContext.h?rev=144343&r1=144342&r2=144343&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/IndexingContext.h (original)
+++ cfe/trunk/tools/libclang/IndexingContext.h Thu Nov 10 18:23:36 2011
@@ -17,10 +17,27 @@
namespace clang {
class FileEntry;
class ObjCPropertyDecl;
+ class ObjCClassDecl;
namespace cxindex {
class IndexingContext;
+struct DeclInfo : public CXIdxDeclInfo {
+ CXIdxEntityInfo CXEntInfo;
+};
+
+struct TagDeclInfo : public DeclInfo {
+ CXIdxTagDeclInfo CXTagDeclInfo;
+};
+
+struct ObjCContainerDeclInfo : public DeclInfo {
+ CXIdxObjCContainerDeclInfo CXObjCContDeclInfo;
+};
+
+struct ObjCCategoryDeclInfo : public ObjCContainerDeclInfo {
+ CXIdxObjCCategoryDeclInfo CXObjCCatDeclInfo;
+};
+
class IndexingContext {
ASTContext *Ctx;
CXClientData ClientData;
@@ -28,10 +45,10 @@
unsigned IndexOptions;
CXTranslationUnit CXTU;
- typedef llvm::DenseMap<const FileEntry *, CXIdxFile> FileMapTy;
- typedef llvm::DenseMap<const NamedDecl *, CXIdxEntity> EntityMapTy;
- typedef llvm::DenseMap<const void *, CXIdxMacro> MacroMapTy;
- typedef llvm::DenseMap<const DeclContext *, CXIdxContainer> ContainerMapTy;
+ 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;
@@ -40,14 +57,23 @@
SmallVector<DeclGroupRef, 8> TUDeclsInObjCContainer;
llvm::SmallString<256> StrScratch;
+ unsigned StrAdapterCount;
class StrAdapter {
llvm::SmallString<256> &Scratch;
+ IndexingContext &IdxCtx;
public:
- StrAdapter(IndexingContext *indexCtx)
- : Scratch(indexCtx->StrScratch) {}
- ~StrAdapter() { Scratch.clear(); }
+ StrAdapter(IndexingContext &indexCtx)
+ : Scratch(indexCtx.StrScratch), IdxCtx(indexCtx) {
+ ++IdxCtx.StrAdapterCount;
+ }
+
+ ~StrAdapter() {
+ --IdxCtx.StrAdapterCount;
+ if (IdxCtx.StrAdapterCount == 0)
+ Scratch.clear();
+ }
const char *toCStr(StringRef Str);
@@ -65,12 +91,14 @@
IndexingContext(CXClientData clientData, IndexerCallbacks &indexCallbacks,
unsigned indexOptions, CXTranslationUnit cxTU)
: Ctx(0), ClientData(clientData), CB(indexCallbacks),
- IndexOptions(indexOptions), CXTU(cxTU) { }
+ IndexOptions(indexOptions), CXTU(cxTU), StrAdapterCount(0) { }
ASTContext &getASTContext() const { return *Ctx; }
void setASTContext(ASTContext &ctx);
+ void enteredMainFile(const FileEntry *File);
+
void ppIncludedFile(SourceLocation hashLoc,
StringRef filename, const FileEntry *File,
bool isImport, bool isAngled);
@@ -117,13 +145,20 @@
void handleTypedef(const TypedefDecl *D);
+ 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,
+ bool isRedeclaration);
+
void handleObjCProtocol(const ObjCProtocolDecl *D);
void handleObjCCategory(const ObjCCategoryDecl *D);
+ void handleObjCCategoryImpl(const ObjCCategoryImplDecl *D);
void handleObjCMethod(const ObjCMethodDecl *D);
@@ -135,13 +170,10 @@
const Expr *E = 0,
CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct);
- void invokeStartedTagTypeDefinition(const TagDecl *D);
-
- void invokeStartedStatementBody(const NamedDecl *D, const DeclContext *DC);
+ void startContainer(const NamedDecl *D, bool isStmtBody = false,
+ const DeclContext *DC = 0);
- void invokeStartedObjCContainer(const ObjCContainerDecl *D);
-
- void invokeEndedContainer(const DeclContext *DC);
+ void endContainer(const DeclContext *DC);
bool isNotFromSourceFile(SourceLocation Loc) const;
@@ -152,45 +184,41 @@
TUDeclsInObjCContainer.push_back(DG);
}
- void translateLoc(SourceLocation Loc, CXIdxFile *indexFile, CXFile *file,
+ void translateLoc(SourceLocation Loc, CXIdxClientFile *indexFile, CXFile *file,
unsigned *line, unsigned *column, unsigned *offset);
private:
- void addEntityInMap(const NamedDecl *D, CXIdxEntity entity);
+ void handleDecl(const NamedDecl *D,
+ SourceLocation Loc, CXCursor Cursor,
+ bool isRedeclaration, bool isDefinition,
+ DeclInfo &DInfo);
+
+ void handleObjCContainer(const ObjCContainerDecl *D,
+ SourceLocation Loc, CXCursor Cursor,
+ bool isForwardRef,
+ bool isRedeclaration,
+ bool isImplementation,
+ ObjCContainerDeclInfo &ContDInfo);
+
+ void addEntityInMap(const NamedDecl *D, CXIdxClientEntity entity);
- void addContainerInMap(const DeclContext *DC, CXIdxContainer container);
+ void addContainerInMap(const DeclContext *DC, CXIdxClientContainer container);
- CXIdxEntity getIndexEntity(const NamedDecl *D);
+ CXIdxClientEntity getClientEntity(const NamedDecl *D);
const NamedDecl *getEntityDecl(const NamedDecl *D) const;
- CXIdxContainer getIndexContainer(const NamedDecl *D) const {
+ CXIdxClientContainer getIndexContainer(const NamedDecl *D) const {
return getIndexContainerForDC(D->getDeclContext());
}
const DeclContext *getScopedContext(const DeclContext *DC) const;
- CXIdxContainer getIndexContainerForDC(const DeclContext *DC) const;
+ CXIdxClientContainer getIndexContainerForDC(const DeclContext *DC) const;
- CXIdxFile getIndexFile(const FileEntry *File);
+ CXIdxClientFile getIndexFile(const FileEntry *File);
CXIdxLoc getIndexLoc(SourceLocation Loc) const;
- void getIndexedEntityInfo(const NamedDecl *D,
- CXIdxIndexedEntityInfo &IdxEntityInfo,
- CXIdxEntityInfo &EntityInfo,
- CXIdxIndexedDeclInfo &IdxDeclInfo,
- StrAdapter &SA);
-
- void getIndexedDeclInfo(const NamedDecl *D,
- CXIdxIndexedDeclInfo &IdxDeclInfo);
-
- void getIndexedRedeclInfo(const NamedDecl *D,
- CXIdxIndexedRedeclInfo &RedeclInfo,
- CXIdxIndexedDeclInfo &IdxDeclInfo);
-
- void getContainerInfo(const NamedDecl *D,
- CXIdxContainerInfo &ContainerInfo);
-
void getEntityInfo(const NamedDecl *D,
CXIdxEntityInfo &EntityInfo,
StrAdapter &SA);
Modified: cfe/trunk/tools/libclang/libclang.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.exports?rev=144343&r1=144342&r2=144343&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/libclang.exports (original)
+++ cfe/trunk/tools/libclang/libclang.exports Thu Nov 10 18:23:36 2011
@@ -135,6 +135,12 @@
clang_getTypeDeclaration
clang_getTypeKindSpelling
clang_hashCursor
+clang_index_getObjCCategoryDeclInfo
+clang_index_getObjCContainerDeclInfo
+clang_index_getTagDeclInfo
+clang_index_isEntityObjCCategoryKind
+clang_index_isEntityObjCContainerKind
+clang_index_isEntityTagKind
clang_indexLoc_getCXSourceLocation
clang_indexLoc_getFileLocation
clang_indexTranslationUnit
More information about the cfe-commits
mailing list