diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-11-16 02:35:05 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-11-16 02:35:05 +0000 |
commit | 3e340a67f4522a2f633a719cb7f3389fe2474374 (patch) | |
tree | c26a7d322faaf09bcf9928346a96546c1f2c38a6 | |
parent | d6c8209fd1567db9c2721f441b50cb23cdf8d835 (diff) |
[libclang] Indexing API: fill the objc category info for a category implementation and
do not crash if no client container is registered for a declaration context.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144765 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | tools/c-index-test/c-index-test.c | 5 | ||||
-rw-r--r-- | tools/libclang/IndexingContext.cpp | 19 |
2 files changed, 20 insertions, 4 deletions
diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c index 56b555213a..c479278457 100644 --- a/tools/c-index-test/c-index-test.c +++ b/tools/c-index-test/c-index-test.c @@ -1610,7 +1610,10 @@ static CXIdxClientContainer makeClientContainer(const CXIdxEntityInfo *info, } static void printCXIndexContainer(CXIdxClientContainer container) { - printf("[%s]", (const char *)container); + if (!container) + printf("[<<NULL>>]"); + else + printf("[%s]", (const char *)container); } static const char *getEntityKindString(CXIdxEntityKind kind) { diff --git a/tools/libclang/IndexingContext.cpp b/tools/libclang/IndexingContext.cpp index 3ecc560d35..890336e3ac 100644 --- a/tools/libclang/IndexingContext.cpp +++ b/tools/libclang/IndexingContext.cpp @@ -259,11 +259,22 @@ void IndexingContext::handleObjCCategoryImpl(const ObjCCategoryImplDecl *D) { ObjCCategoryDeclInfo CatDInfo(/*isImplementation=*/true); CXIdxEntityInfo ClassEntity; StrAdapter SA(*this); - getEntityInfo(CatD->getClassInterface(), ClassEntity, SA); + const ObjCInterfaceDecl *IFaceD = CatD->getClassInterface(); + SourceLocation ClassLoc = D->getLocation(); + SourceLocation CategoryLoc = ClassLoc; //FIXME: D->getCategoryNameLoc(); + getEntityInfo(IFaceD, ClassEntity, SA); CatDInfo.ObjCCatDeclInfo.containerInfo = &CatDInfo.ObjCContDeclInfo; - CatDInfo.ObjCCatDeclInfo.objcClass = &ClassEntity; - handleObjCContainer(D, D->getLocation(), getCursor(D), CatDInfo); + if (IFaceD) { + CatDInfo.ObjCCatDeclInfo.objcClass = &ClassEntity; + CatDInfo.ObjCCatDeclInfo.classCursor = + MakeCursorObjCClassRef(IFaceD, ClassLoc, CXTU); + } else { + CatDInfo.ObjCCatDeclInfo.objcClass = 0; + CatDInfo.ObjCCatDeclInfo.classCursor = clang_getNullCursor(); + } + CatDInfo.ObjCCatDeclInfo.classLoc = getIndexLoc(ClassLoc); + handleObjCContainer(D, CategoryLoc, getCursor(D), CatDInfo); } void IndexingContext::handleObjCMethod(const ObjCMethodDecl *D) { @@ -402,6 +413,8 @@ CXIdxClientContainer IndexingContext::getIndexContainerForDC(const DeclContext *DC) const { DC = getScopedContext(DC); ContainerMapTy::const_iterator I = ContainerMap.find(DC); + if (I == ContainerMap.end()) + return 0; // assert(I != ContainerMap.end() && // "Failed to include a scoped context in the container map"); return I->second; |