diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-11-11 00:23:36 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-11-11 00:23:36 +0000 |
commit | 7519c5e44034ee85d531dd9d842d4233b91ac39a (patch) | |
tree | 072365c9e90e3b2b09f66ba368a18d5cd3e2a1f8 /clang/tools/libclang/Indexing.cpp | |
parent | 85b075b8451370f6f6fc1f3be737f49b52f63a07 (diff) | |
download | bcm5719-llvm-7519c5e44034ee85d531dd9d842d4233b91ac39a.tar.gz bcm5719-llvm-7519c5e44034ee85d531dd9d842d4233b91ac39a.zip |
[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.
llvm-svn: 144343
Diffstat (limited to 'clang/tools/libclang/Indexing.cpp')
-rw-r--r-- | clang/tools/libclang/Indexing.cpp | 54 |
1 files changed, 52 insertions, 2 deletions
diff --git a/clang/tools/libclang/Indexing.cpp b/clang/tools/libclang/Indexing.cpp index 7f296ae1d19..4bea88f8de6 100644 --- a/clang/tools/libclang/Indexing.cpp +++ b/clang/tools/libclang/Indexing.cpp @@ -40,10 +40,25 @@ namespace { class IndexPPCallbacks : public PPCallbacks { Preprocessor &PP; IndexingContext &IndexCtx; + bool IsMainFileEntered; public: IndexPPCallbacks(Preprocessor &PP, IndexingContext &indexCtx) - : PP(PP), IndexCtx(indexCtx) { } + : PP(PP), IndexCtx(indexCtx), IsMainFileEntered(false) { } + + virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason, + SrcMgr::CharacteristicKind FileType, FileID PrevFID) { + if (IsMainFileEntered) + return; + + SourceManager &SM = PP.getSourceManager(); + SourceLocation MainFileLoc = SM.getLocForStartOfFile(SM.getMainFileID()); + + if (Loc == MainFileLoc && Reason == PPCallbacks::EnterFile) { + IsMainFileEntered = true; + IndexCtx.enteredMainFile(SM.getFileEntryForID(SM.getMainFileID())); + } + } virtual void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, @@ -389,6 +404,41 @@ static void clang_indexTranslationUnit_Impl(void *UserData) { extern "C" { +int clang_index_isEntityTagKind(CXIdxEntityKind K) { + return CXIdxEntity_Enum <= K && K <= CXIdxEntity_CXXClass; +} + +CXIdxTagDeclInfo *clang_index_getTagDeclInfo(CXIdxDeclInfo *DInfo) { + if (clang_index_isEntityTagKind(DInfo->entityInfo->kind)) + return &static_cast<TagDeclInfo*>(DInfo)->CXTagDeclInfo; + + return 0; +} + +int clang_index_isEntityObjCContainerKind(CXIdxEntityKind K) { + return CXIdxEntity_ObjCClass <= K && K <= CXIdxEntity_ObjCCategory; +} + +CXIdxObjCContainerDeclInfo * +clang_index_getObjCContainerDeclInfo(CXIdxDeclInfo *DInfo) { + if (clang_index_isEntityObjCContainerKind(DInfo->entityInfo->kind)) + return &static_cast<ObjCContainerDeclInfo*>(DInfo)->CXObjCContDeclInfo; + + return 0; +} + +int clang_index_isEntityObjCCategoryKind(CXIdxEntityKind K) { + return K == CXIdxEntity_ObjCCategory; +} + +CXIdxObjCCategoryDeclInfo * +clang_index_getObjCCategoryDeclInfo(CXIdxDeclInfo *DInfo){ + if (clang_index_isEntityObjCCategoryKind(DInfo->entityInfo->kind)) + return &static_cast<ObjCCategoryDeclInfo*>(DInfo)->CXObjCCatDeclInfo; + + return 0; +} + int clang_indexTranslationUnit(CXIndex CIdx, CXClientData client_data, IndexerCallbacks *index_callbacks, @@ -445,7 +495,7 @@ int clang_indexTranslationUnit(CXIndex CIdx, } void clang_indexLoc_getFileLocation(CXIdxLoc location, - CXIdxFile *indexFile, + CXIdxClientFile *indexFile, CXFile *file, unsigned *line, unsigned *column, |