[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

llvm-svn: 338813
This commit is contained in:
Michael Wu
2018-08-03 05:03:22 +00:00
parent a80352c04e
commit d092d0b179
4 changed files with 108 additions and 1 deletions

View 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,

View 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)=

View 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:

View 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;