]> granicus.if.org Git - clang/commitdiff
[libclang 5/8] Add support for ObjC attributes without args
authorMichael Wu <mwu.code@gmail.com>
Fri, 3 Aug 2018 05:03:22 +0000 (05:03 +0000)
committerMichael Wu <mwu.code@gmail.com>
Fri, 3 Aug 2018 05:03:22 +0000 (05:03 +0000)
Summary:
This adds support to libclang for identifying ObjC related attributes that don't take arguments.

All attributes but NSObject and NSConsumed are tested.

Reviewers: yvvan, jbcoe

Reviewed By: yvvan

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D49127

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

include/clang-c/Index.h
test/Index/index-attrs.m
tools/libclang/CIndex.cpp
tools/libclang/CXCursor.cpp

index 712b1efda120036de298b4c1f3d7b144609320c6..a0ca0128c8a900dbd8a37320b171ca4548205da8 100644 (file)
@@ -2563,7 +2563,24 @@ enum CXCursorKind {
   CXCursor_VisibilityAttr                = 417,
   CXCursor_DLLExport                     = 418,
   CXCursor_DLLImport                     = 419,
-  CXCursor_LastAttr                      = CXCursor_DLLImport,
+  CXCursor_NSReturnsRetained             = 420,
+  CXCursor_NSReturnsNotRetained          = 421,
+  CXCursor_NSReturnsAutoreleased         = 422,
+  CXCursor_NSConsumesSelf                = 423,
+  CXCursor_NSConsumed                    = 424,
+  CXCursor_ObjCException                 = 425,
+  CXCursor_ObjCNSObject                  = 426,
+  CXCursor_ObjCIndependentClass          = 427,
+  CXCursor_ObjCPreciseLifetime           = 428,
+  CXCursor_ObjCReturnsInnerPointer       = 429,
+  CXCursor_ObjCRequiresSuper             = 430,
+  CXCursor_ObjCRootClass                 = 431,
+  CXCursor_ObjCSubclassingRestricted     = 432,
+  CXCursor_ObjCExplicitProtocolImpl      = 433,
+  CXCursor_ObjCDesignatedInitializer     = 434,
+  CXCursor_ObjCRuntimeVisible            = 435,
+  CXCursor_ObjCBoxable                   = 436,
+  CXCursor_LastAttr                      = CXCursor_ObjCBoxable,
 
   /* Preprocessing */
   CXCursor_PreprocessingDirective        = 500,
index 09c52ba3dcfece97ff8ae444718c588027b15750..574725562e40755add3744bd00a8991e8023133d 100644 (file)
@@ -9,9 +9,48 @@
 @property (assign) id prop __attribute__((annotate("anno")));
 @end
 
+__attribute__((objc_protocol_requires_explicit_implementation))
+@protocol P
+@end
+
+typedef id __attribute__((objc_independent_class)) T2;
+id __attribute__((objc_precise_lifetime)) x;
+struct __attribute__((objc_boxable)) S {
+  int x;
+};
+
+__attribute__((objc_exception))
+__attribute__((objc_root_class))
+__attribute__((objc_subclassing_restricted))
+__attribute__((objc_runtime_visible))
+@interface J
+-(id)a __attribute__((ns_returns_retained));
+-(id)b __attribute__((ns_returns_not_retained));
+-(id)c __attribute__((ns_returns_autoreleased));
+-(id)d __attribute__((ns_consumes_self));
+-(id)e __attribute__((objc_requires_super));
+-(int *)f __attribute__((objc_returns_inner_pointer));
+-(id)init __attribute__((objc_designated_initializer));
+@end
+
 // RUN: c-index-test -index-file %s | FileCheck %s
 // CHECK:      <attribute>: attribute(iboutletcollection)= [IBOutletCollection=ObjCInterface]
 
 // CHECK: <attribute>: attribute(annotate)=anno
 // CHECK: <getter>: kind: objc-instance-method | name: prop | {{.*}} <attribute>: attribute(annotate)=anno
 // CHECK: <setter>: kind: objc-instance-method | name: setProp: | {{.*}} <attribute>: attribute(annotate)=anno
+// CHECK: <attribute>: attribute(objc_protocol_requires_explicit_implementation)=
+// CHECK: <attribute>: attribute(objc_independent_class)=
+// CHECK: <attribute>: attribute(objc_precise_lifetime)=
+// CHECK: <attribute>: attribute(objc_boxable)=
+// CHECK: <attribute>: attribute(objc_exception)=
+// CHECK: <attribute>: attribute(objc_root_class)=
+// CHECK: <attribute>: attribute(objc_subclassing_restricted)=
+// CHECK: <attribute>: attribute(objc_runtime_visible)=
+// CHECK: <attribute>: attribute(ns_returns_retained)=
+// CHECK: <attribute>: attribute(ns_returns_not_retained)=
+// CHECK: <attribute>: attribute(ns_returns_autoreleased)=
+// CHECK: <attribute>: attribute(ns_consumes_self)=
+// CHECK: <attribute>: attribute(objc_requires_super)=
+// CHECK: <attribute>: attribute(objc_returns_inner_pointer)=
+// CHECK: <attribute>: attribute(objc_designated_initializer)=
index 499d9abf9a8ef024b8cc4b6733a84811ed74f701..2f96d3058ad3879090c1d769af49eda41ccaea4a 100644 (file)
@@ -5277,6 +5277,40 @@ CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) {
     return cxstring::createRef("attribute(dllexport)");
   case CXCursor_DLLImport:
     return cxstring::createRef("attribute(dllimport)");
+  case CXCursor_NSReturnsRetained:
+    return cxstring::createRef("attribute(ns_returns_retained)");
+  case CXCursor_NSReturnsNotRetained:
+    return cxstring::createRef("attribute(ns_returns_not_retained)");
+  case CXCursor_NSReturnsAutoreleased:
+    return cxstring::createRef("attribute(ns_returns_autoreleased)");
+  case CXCursor_NSConsumesSelf:
+    return cxstring::createRef("attribute(ns_consumes_self)");
+  case CXCursor_NSConsumed:
+    return cxstring::createRef("attribute(ns_consumed)");
+  case CXCursor_ObjCException:
+    return cxstring::createRef("attribute(objc_exception)");
+  case CXCursor_ObjCNSObject:
+    return cxstring::createRef("attribute(NSObject)");
+  case CXCursor_ObjCIndependentClass:
+    return cxstring::createRef("attribute(objc_independent_class)");
+  case CXCursor_ObjCPreciseLifetime:
+    return cxstring::createRef("attribute(objc_precise_lifetime)");
+  case CXCursor_ObjCReturnsInnerPointer:
+    return cxstring::createRef("attribute(objc_returns_inner_pointer)");
+  case CXCursor_ObjCRequiresSuper:
+    return cxstring::createRef("attribute(objc_requires_super)");
+  case CXCursor_ObjCRootClass:
+    return cxstring::createRef("attribute(objc_root_class)");
+  case CXCursor_ObjCSubclassingRestricted:
+    return cxstring::createRef("attribute(objc_subclassing_restricted)");
+  case CXCursor_ObjCExplicitProtocolImpl:
+    return cxstring::createRef("attribute(objc_protocol_requires_explicit_implementation)");
+  case CXCursor_ObjCDesignatedInitializer:
+    return cxstring::createRef("attribute(objc_designated_initializer)");
+  case CXCursor_ObjCRuntimeVisible:
+    return cxstring::createRef("attribute(objc_runtime_visible)");
+  case CXCursor_ObjCBoxable:
+    return cxstring::createRef("attribute(objc_boxable)");
   case CXCursor_PreprocessingDirective:
     return cxstring::createRef("preprocessing directive");
   case CXCursor_MacroDefinition:
index b4ad0595cc53db4ee685f713c872c3c541a95cdd..09321be0515e657609005835322233773e51187d 100644 (file)
@@ -61,6 +61,23 @@ static CXCursorKind GetCursorKind(const Attr *A) {
     case attr::Visibility: return CXCursor_VisibilityAttr;
     case attr::DLLExport: return CXCursor_DLLExport;
     case attr::DLLImport: return CXCursor_DLLImport;
+    case attr::NSReturnsRetained: return CXCursor_NSReturnsRetained;
+    case attr::NSReturnsNotRetained: return CXCursor_NSReturnsNotRetained;
+    case attr::NSReturnsAutoreleased: return CXCursor_NSReturnsAutoreleased;
+    case attr::NSConsumesSelf: return CXCursor_NSConsumesSelf;
+    case attr::NSConsumed: return CXCursor_NSConsumed;
+    case attr::ObjCException: return CXCursor_ObjCException;
+    case attr::ObjCNSObject: return CXCursor_ObjCNSObject;
+    case attr::ObjCIndependentClass: return CXCursor_ObjCIndependentClass;
+    case attr::ObjCPreciseLifetime: return CXCursor_ObjCPreciseLifetime;
+    case attr::ObjCReturnsInnerPointer: return CXCursor_ObjCReturnsInnerPointer;
+    case attr::ObjCRequiresSuper: return CXCursor_ObjCRequiresSuper;
+    case attr::ObjCRootClass: return CXCursor_ObjCRootClass;
+    case attr::ObjCSubclassingRestricted: return CXCursor_ObjCSubclassingRestricted;
+    case attr::ObjCExplicitProtocolImpl: return CXCursor_ObjCExplicitProtocolImpl;
+    case attr::ObjCDesignatedInitializer: return CXCursor_ObjCDesignatedInitializer;
+    case attr::ObjCRuntimeVisible: return CXCursor_ObjCRuntimeVisible;
+    case attr::ObjCBoxable: return CXCursor_ObjCBoxable;
   }
 
   return CXCursor_UnexposedAttr;