]> granicus.if.org Git - clang/commitdiff
[libclang] When indexing an objc property, also provide information about
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 28 Feb 2012 17:50:33 +0000 (17:50 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 28 Feb 2012 17:50:33 +0000 (17:50 +0000)
the getter/setter objc method entities that the property is associated with.

rdar://10244558

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@151634 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang-c/Index.h
tools/c-index-test/c-index-test.c
tools/libclang/Indexing.cpp
tools/libclang/IndexingContext.cpp
tools/libclang/IndexingContext.h
tools/libclang/libclang.exports

index 67a26d9f4e70b82f284765b9791c732c17248034..21e87b0b42ffc735768eb947f17d383692bc48af 100644 (file)
@@ -4270,6 +4270,12 @@ typedef struct {
   const CXIdxObjCProtocolRefListInfo *protocols;
 } CXIdxObjCCategoryDeclInfo;
 
+typedef struct {
+  const CXIdxDeclInfo *declInfo;
+  const CXIdxEntityInfo *getter;
+  const CXIdxEntityInfo *setter;
+} CXIdxObjCPropertyDeclInfo;
+
 typedef struct {
   const CXIdxDeclInfo *declInfo;
   const CXIdxBaseClassInfo *const *bases;
@@ -4387,6 +4393,9 @@ clang_index_getObjCCategoryDeclInfo(const CXIdxDeclInfo *);
 CINDEX_LINKAGE const CXIdxObjCProtocolRefListInfo *
 clang_index_getObjCProtocolRefListInfo(const CXIdxDeclInfo *);
 
+CINDEX_LINKAGE const CXIdxObjCPropertyDeclInfo *
+clang_index_getObjCPropertyDeclInfo(const CXIdxDeclInfo *);
+
 CINDEX_LINKAGE const CXIdxIBOutletCollectionAttrInfo *
 clang_index_getIBOutletCollectionAttrInfo(const CXIdxAttrInfo *);
 
index eee7f46ee41a1dddc1bdf1f36e1783ed1c305cbf..925f56a601a4d45fb93aa134f4ef0d4e1f4bfa11 100644 (file)
@@ -1809,6 +1809,7 @@ static void index_indexDeclaration(CXClientData client_data,
   const CXIdxObjCCategoryDeclInfo *CatInfo;
   const CXIdxObjCInterfaceDeclInfo *InterInfo;
   const CXIdxObjCProtocolRefListInfo *ProtoInfo;
+  const CXIdxObjCPropertyDeclInfo *PropInfo;
   const CXIdxCXXClassDeclInfo *CXXClassInfo;
   unsigned i;
   index_data = (IndexData *)client_data;
@@ -1870,6 +1871,17 @@ static void index_indexDeclaration(CXClientData client_data,
     printProtocolList(ProtoInfo, client_data);
   }
 
+  if ((PropInfo = clang_index_getObjCPropertyDeclInfo(info))) {
+    if (PropInfo->getter) {
+      printEntityInfo("     <getter>", client_data, PropInfo->getter);
+      printf("\n");
+    }
+    if (PropInfo->setter) {
+      printEntityInfo("     <setter>", client_data, PropInfo->setter);
+      printf("\n");
+    }
+  }
+
   if ((CXXClassInfo = clang_index_getCXXClassDeclInfo(info))) {
     for (i = 0; i != CXXClassInfo->numBases; ++i) {
       printBaseClassInfo(client_data, CXXClassInfo->bases[i]);
index 1aed5313b795f9909e1ced58d27bc08f8253dff0..1475859e3355eb371c60757f836a22d628e3d9b3 100644 (file)
@@ -608,6 +608,18 @@ clang_index_getObjCProtocolRefListInfo(const CXIdxDeclInfo *DInfo) {
   return 0;
 }
 
+const CXIdxObjCPropertyDeclInfo *
+clang_index_getObjCPropertyDeclInfo(const CXIdxDeclInfo *DInfo) {
+  if (!DInfo)
+    return 0;
+
+  const DeclInfo *DI = static_cast<const DeclInfo *>(DInfo);
+  if (const ObjCPropertyDeclInfo *PropInfo = dyn_cast<ObjCPropertyDeclInfo>(DI))
+    return &PropInfo->ObjCPropDeclInfo;
+
+  return 0;
+}
+
 const CXIdxIBOutletCollectionAttrInfo *
 clang_index_getIBOutletCollectionAttrInfo(const CXIdxAttrInfo *AInfo) {
   if (!AInfo)
index 2963f3b9453863b5a445b1e237705c71cf139a32..6797cc244aaef4c6a12299ec7e971c5f5697d3e0 100644 (file)
@@ -517,8 +517,26 @@ bool IndexingContext::handleSynthesizedObjCMethod(const ObjCMethodDecl *D,
 }
 
 bool IndexingContext::handleObjCProperty(const ObjCPropertyDecl *D) {
-  DeclInfo DInfo(/*isRedeclaration=*/false, /*isDefinition=*/false,
-                 /*isContainer=*/false);
+  ObjCPropertyDeclInfo DInfo;
+  EntityInfo GetterEntity;
+  EntityInfo SetterEntity;
+  ScratchAlloc SA(*this);
+
+  DInfo.ObjCPropDeclInfo.declInfo = &DInfo;
+
+  if (ObjCMethodDecl *Getter = D->getGetterMethodDecl()) {
+    getEntityInfo(Getter, GetterEntity, SA);
+    DInfo.ObjCPropDeclInfo.getter = &GetterEntity;
+  } else {
+    DInfo.ObjCPropDeclInfo.getter = 0;
+  }
+  if (ObjCMethodDecl *Setter = D->getSetterMethodDecl()) {
+    getEntityInfo(Setter, SetterEntity, SA);
+    DInfo.ObjCPropDeclInfo.setter = &SetterEntity;
+  } else {
+    DInfo.ObjCPropDeclInfo.setter = 0;
+  }
+
   return handleDecl(D, D->getLocation(), getCursor(D), DInfo);
 }
 
index ea457052b426fab54da8b0a185e4adf3c401eaf0..8463e3fedf9eeed05e9c014c83e84d5d2211fb60 100644 (file)
@@ -53,6 +53,8 @@ struct DeclInfo : public CXIdxDeclInfo {
       Info_ObjCProtocol,
       Info_ObjCCategory,
 
+    Info_ObjCProperty,
+
     Info_CXXClass
   };
   
@@ -168,6 +170,20 @@ struct ObjCCategoryDeclInfo : public ObjCContainerDeclInfo {
   static bool classof(const ObjCCategoryDeclInfo *D) { return true; }
 };
 
+struct ObjCPropertyDeclInfo : public DeclInfo {
+  CXIdxObjCPropertyDeclInfo ObjCPropDeclInfo;
+
+  ObjCPropertyDeclInfo()
+    : DeclInfo(Info_ObjCProperty,
+               /*isRedeclaration=*/false, /*isDefinition=*/false,
+               /*isContainer=*/false) { }
+
+  static bool classof(const DeclInfo *D) {
+    return D->Kind == Info_ObjCProperty;
+  }
+  static bool classof(const ObjCPropertyDeclInfo *D) { return true; }
+};
+
 struct CXXClassDeclInfo : public DeclInfo {
   CXIdxCXXClassDeclInfo CXXClassInfo;
 
index b028bb460289a6b3fab215f9f199361e09ea8f72..8645b15f7b2f1ab1298e0bc2211114aef23cf1a6 100644 (file)
@@ -158,6 +158,7 @@ clang_index_getIBOutletCollectionAttrInfo
 clang_index_getObjCCategoryDeclInfo
 clang_index_getObjCContainerDeclInfo
 clang_index_getObjCInterfaceDeclInfo
+clang_index_getObjCPropertyDeclInfo
 clang_index_getObjCProtocolRefListInfo
 clang_index_isEntityObjCContainerKind
 clang_index_setClientContainer