r338813 - [libclang 5/8] Add support for ObjC attributes without args
Michael Wu via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 2 22:03:22 PDT 2018
Author: mwu
Date: Thu Aug 2 22:03:22 2018
New Revision: 338813
URL: http://llvm.org/viewvc/llvm-project?rev=338813&view=rev
Log:
[libclang 5/8] Add support for ObjC attributes without args
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
Modified:
cfe/trunk/include/clang-c/Index.h
cfe/trunk/test/Index/index-attrs.m
cfe/trunk/tools/libclang/CIndex.cpp
cfe/trunk/tools/libclang/CXCursor.cpp
Modified: cfe/trunk/include/clang-c/Index.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=338813&r1=338812&r2=338813&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Thu Aug 2 22:03:22 2018
@@ -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,
Modified: cfe/trunk/test/Index/index-attrs.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/index-attrs.m?rev=338813&r1=338812&r2=338813&view=diff
==============================================================================
--- cfe/trunk/test/Index/index-attrs.m (original)
+++ cfe/trunk/test/Index/index-attrs.m Thu Aug 2 22:03:22 2018
@@ -9,9 +9,48 @@
@property (assign) id prop __attribute__((annotate("anno")));
@end
+__attribute__((objc_protocol_requires_explicit_implementation))
+ at protocol P
+ at 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))
+ at 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));
+ at 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)=
Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=338813&r1=338812&r2=338813&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Thu Aug 2 22:03:22 2018
@@ -5277,6 +5277,40 @@ CXString clang_getCursorKindSpelling(enu
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:
Modified: cfe/trunk/tools/libclang/CXCursor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXCursor.cpp?rev=338813&r1=338812&r2=338813&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXCursor.cpp (original)
+++ cfe/trunk/tools/libclang/CXCursor.cpp Thu Aug 2 22:03:22 2018
@@ -61,6 +61,23 @@ static CXCursorKind GetCursorKind(const
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;
More information about the cfe-commits
mailing list