]> granicus.if.org Git - clang/commitdiff
[libclang] Indexing API: fill the objc category info for a category implementation and
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 16 Nov 2011 02:35:05 +0000 (02:35 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 16 Nov 2011 02:35:05 +0000 (02:35 +0000)
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

tools/c-index-test/c-index-test.c
tools/libclang/IndexingContext.cpp

index 56b555213ac79264a68e67bc17c87f4357a8a792..c4792784577e39a608527af5b0714fe5c2cb1d3d 100644 (file)
@@ -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) {
index 3ecc560d35013fdbf552ef57ceb76276c61fc721..890336e3ac01d0d73a73b50abc4baf4c190918e5 100644 (file)
@@ -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;