[libclang] Indexing API: Provide the protocols list for objc categories as well.

rdar://10573361

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146498 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h
index 8b0aed1..9da6b23 100644
--- a/include/clang-c/Index.h
+++ b/include/clang-c/Index.h
@@ -4239,13 +4239,6 @@
 } CXIdxObjCContainerDeclInfo;
 
 typedef struct {
-  const CXIdxObjCContainerDeclInfo *containerInfo;
-  const CXIdxEntityInfo *objcClass;
-  CXCursor classCursor;
-  CXIdxLoc classLoc;
-} CXIdxObjCCategoryDeclInfo;
-
-typedef struct {
   const CXIdxEntityInfo *base;
   CXCursor cursor;
   CXIdxLoc loc;
@@ -4269,6 +4262,14 @@
 } CXIdxObjCInterfaceDeclInfo;
 
 typedef struct {
+  const CXIdxObjCContainerDeclInfo *containerInfo;
+  const CXIdxEntityInfo *objcClass;
+  CXCursor classCursor;
+  CXIdxLoc classLoc;
+  const CXIdxObjCProtocolRefListInfo *protocols;
+} CXIdxObjCCategoryDeclInfo;
+
+typedef struct {
   const CXIdxDeclInfo *declInfo;
   const CXIdxBaseClassInfo *const *bases;
   unsigned numBases;
diff --git a/tools/libclang/Indexing.cpp b/tools/libclang/Indexing.cpp
index 50c37bc..630c55b 100644
--- a/tools/libclang/Indexing.cpp
+++ b/tools/libclang/Indexing.cpp
@@ -583,6 +583,9 @@
         ProtInfo = dyn_cast<ObjCProtocolDeclInfo>(DI))
     return &ProtInfo->ObjCProtoRefListInfo;
 
+  if (const ObjCCategoryDeclInfo *CatInfo = dyn_cast<ObjCCategoryDeclInfo>(DI))
+    return CatInfo->ObjCCatDeclInfo.protocols;
+
   return 0;
 }
 
diff --git a/tools/libclang/IndexingContext.cpp b/tools/libclang/IndexingContext.cpp
index 66e552c..8126693 100644
--- a/tools/libclang/IndexingContext.cpp
+++ b/tools/libclang/IndexingContext.cpp
@@ -383,6 +383,8 @@
   if (suppressRefs())
     markEntityOccurrenceInFile(IFaceD, ClassLoc);
 
+  ObjCProtocolListInfo ProtInfo(D->getReferencedProtocols(), *this, SA);
+  
   CatDInfo.ObjCCatDeclInfo.containerInfo = &CatDInfo.ObjCContDeclInfo;
   if (IFaceD) {
     CatDInfo.ObjCCatDeclInfo.objcClass = &ClassEntity;
@@ -393,6 +395,9 @@
     CatDInfo.ObjCCatDeclInfo.classCursor = clang_getNullCursor();
   }
   CatDInfo.ObjCCatDeclInfo.classLoc = getIndexLoc(ClassLoc);
+  CatDInfo.ObjCProtoListInfo = ProtInfo.getListInfo();
+  CatDInfo.ObjCCatDeclInfo.protocols = &CatDInfo.ObjCProtoListInfo;
+
   return handleObjCContainer(D, CategoryLoc, getCursor(D), CatDInfo);
 }
 
@@ -416,6 +421,8 @@
     CatDInfo.ObjCCatDeclInfo.classCursor = clang_getNullCursor();
   }
   CatDInfo.ObjCCatDeclInfo.classLoc = getIndexLoc(ClassLoc);
+  CatDInfo.ObjCCatDeclInfo.protocols = 0;
+
   return handleObjCContainer(D, CategoryLoc, getCursor(D), CatDInfo);
 }
 
diff --git a/tools/libclang/IndexingContext.h b/tools/libclang/IndexingContext.h
index 1ad1d80..b9234d8 100644
--- a/tools/libclang/IndexingContext.h
+++ b/tools/libclang/IndexingContext.h
@@ -149,6 +149,7 @@
 
 struct ObjCCategoryDeclInfo : public ObjCContainerDeclInfo {
   CXIdxObjCCategoryDeclInfo ObjCCatDeclInfo;
+  CXIdxObjCProtocolRefListInfo ObjCProtoListInfo;
 
   explicit ObjCCategoryDeclInfo(bool isImplementation)
     : ObjCContainerDeclInfo(Info_ObjCCategory,