From: Michael Wu Date: Fri, 3 Aug 2018 05:03:22 +0000 (+0000) Subject: [libclang 5/8] Add support for ObjC attributes without args X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4042ae53b138dddb400aa62c3668c29075ca9e92;p=clang [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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@338813 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h index 712b1efda1..a0ca0128c8 100644 --- a/include/clang-c/Index.h +++ b/include/clang-c/Index.h @@ -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, diff --git a/test/Index/index-attrs.m b/test/Index/index-attrs.m index 09c52ba3dc..574725562e 100644 --- a/test/Index/index-attrs.m +++ b/test/Index/index-attrs.m @@ -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(iboutletcollection)= [IBOutletCollection=ObjCInterface] // CHECK: : attribute(annotate)=anno // CHECK: : kind: objc-instance-method | name: prop | {{.*}} : attribute(annotate)=anno // CHECK: : kind: objc-instance-method | name: setProp: | {{.*}} : attribute(annotate)=anno +// CHECK: : attribute(objc_protocol_requires_explicit_implementation)= +// CHECK: : attribute(objc_independent_class)= +// CHECK: : attribute(objc_precise_lifetime)= +// CHECK: : attribute(objc_boxable)= +// CHECK: : attribute(objc_exception)= +// CHECK: : attribute(objc_root_class)= +// CHECK: : attribute(objc_subclassing_restricted)= +// CHECK: : attribute(objc_runtime_visible)= +// CHECK: : attribute(ns_returns_retained)= +// CHECK: : attribute(ns_returns_not_retained)= +// CHECK: : attribute(ns_returns_autoreleased)= +// CHECK: : attribute(ns_consumes_self)= +// CHECK: : attribute(objc_requires_super)= +// CHECK: : attribute(objc_returns_inner_pointer)= +// CHECK: : attribute(objc_designated_initializer)= diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 499d9abf9a..2f96d3058a 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -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: diff --git a/tools/libclang/CXCursor.cpp b/tools/libclang/CXCursor.cpp index b4ad0595cc..09321be051 100644 --- a/tools/libclang/CXCursor.cpp +++ b/tools/libclang/CXCursor.cpp @@ -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;