xref: /llvm-project/clang/test/ARCMT/Common.h (revision 6ba7afb8e15fc40ec9cddefa98cab51e88bfa9ab)
1d70fb981SJohn McCall #if __has_feature(objc_arr)
2d70fb981SJohn McCall #define NS_AUTOMATED_REFCOUNT_UNAVAILABLE __attribute__((unavailable("not available in automatic reference counting mode")))
3d70fb981SJohn McCall #else
4d70fb981SJohn McCall #define NS_AUTOMATED_REFCOUNT_UNAVAILABLE
5d70fb981SJohn McCall #endif
6d70fb981SJohn McCall 
7d208ef95SArgyrios Kyrtzidis #define NS_RETURNS_RETAINED __attribute__((ns_returns_retained))
841899f3bSArgyrios Kyrtzidis #define CF_CONSUMED __attribute__((cf_consumed))
9273c7c40SArgyrios Kyrtzidis #define CF_RETURNS_RETAINED __attribute__((cf_returns_retained))
1041899f3bSArgyrios Kyrtzidis 
11d208ef95SArgyrios Kyrtzidis #define NS_INLINE static __inline__ __attribute__((always_inline))
1293907473SArgyrios Kyrtzidis #define nil ((void*) 0)
13*6ba7afb8SArgyrios Kyrtzidis #define NULL ((void*)0)
1493907473SArgyrios Kyrtzidis 
15d70fb981SJohn McCall typedef int BOOL;
16d70fb981SJohn McCall typedef unsigned NSUInteger;
17d70fb981SJohn McCall typedef int int32_t;
18d70fb981SJohn McCall typedef unsigned char uint8_t;
19d70fb981SJohn McCall typedef int32_t UChar32;
20d70fb981SJohn McCall typedef unsigned char UChar;
21d70fb981SJohn McCall 
2293907473SArgyrios Kyrtzidis typedef struct _NSZone NSZone;
2393907473SArgyrios Kyrtzidis 
2493907473SArgyrios Kyrtzidis typedef const void * CFTypeRef;
2593907473SArgyrios Kyrtzidis CFTypeRef CFRetain(CFTypeRef cf);
26273c7c40SArgyrios Kyrtzidis CFTypeRef CFMakeCollectable(CFTypeRef cf) NS_AUTOMATED_REFCOUNT_UNAVAILABLE;
27d208ef95SArgyrios Kyrtzidis 
28d208ef95SArgyrios Kyrtzidis NS_INLINE NS_RETURNS_RETAINED id NSMakeCollectable(CFTypeRef CF_CONSUMED cf) NS_AUTOMATED_REFCOUNT_UNAVAILABLE;
2993907473SArgyrios Kyrtzidis 
30d70fb981SJohn McCall @protocol NSObject
31d70fb981SJohn McCall - (BOOL)isEqual:(id)object;
3293907473SArgyrios Kyrtzidis - (NSZone *)zone NS_AUTOMATED_REFCOUNT_UNAVAILABLE;
33d70fb981SJohn McCall - (id)retain NS_AUTOMATED_REFCOUNT_UNAVAILABLE;
34d70fb981SJohn McCall - (NSUInteger)retainCount NS_AUTOMATED_REFCOUNT_UNAVAILABLE;
35d70fb981SJohn McCall - (oneway void)release NS_AUTOMATED_REFCOUNT_UNAVAILABLE;
36d70fb981SJohn McCall - (id)autorelease NS_AUTOMATED_REFCOUNT_UNAVAILABLE;
37d70fb981SJohn McCall @end
38d70fb981SJohn McCall 
39d70fb981SJohn McCall @interface NSObject <NSObject> {}
40d70fb981SJohn McCall - (id)init;
41d70fb981SJohn McCall 
42d70fb981SJohn McCall + (id)new;
43d70fb981SJohn McCall + (id)alloc;
44d70fb981SJohn McCall - (void)dealloc;
45d70fb981SJohn McCall 
46d70fb981SJohn McCall - (void)finalize;
47d70fb981SJohn McCall 
48d70fb981SJohn McCall - (id)copy;
49d70fb981SJohn McCall - (id)mutableCopy;
50d70fb981SJohn McCall @end
51d70fb981SJohn McCall 
52d70fb981SJohn McCall NS_AUTOMATED_REFCOUNT_UNAVAILABLE
53d70fb981SJohn McCall @interface NSAutoreleasePool : NSObject {
54d70fb981SJohn McCall @private
55d70fb981SJohn McCall     void    *_token;
56d70fb981SJohn McCall     void    *_reserved3;
57d70fb981SJohn McCall     void    *_reserved2;
58d70fb981SJohn McCall     void    *_reserved;
59d70fb981SJohn McCall }
60d70fb981SJohn McCall 
61d70fb981SJohn McCall + (void)addObject:(id)anObject;
62d70fb981SJohn McCall 
63d70fb981SJohn McCall - (void)addObject:(id)anObject;
64d70fb981SJohn McCall 
65d70fb981SJohn McCall - (void)drain;
66d70fb981SJohn McCall 
67d70fb981SJohn McCall @end
68d70fb981SJohn McCall 
69d70fb981SJohn McCall typedef const void* objc_objectptr_t;
70d70fb981SJohn McCall extern __attribute__((ns_returns_retained)) id objc_retainedObject(objc_objectptr_t __attribute__((cf_consumed)) pointer);
71d70fb981SJohn McCall extern __attribute__((ns_returns_not_retained)) id objc_unretainedObject(objc_objectptr_t pointer);
72d70fb981SJohn McCall extern objc_objectptr_t objc_unretainedPointer(id object);
730b21d824SArgyrios Kyrtzidis 
740b21d824SArgyrios Kyrtzidis #define dispatch_retain(object) ({ dispatch_object_t _o = (object); _dispatch_object_validate(_o); (void)[_o retain]; })
750b21d824SArgyrios Kyrtzidis #define dispatch_release(object) ({ dispatch_object_t _o = (object); _dispatch_object_validate(_o); [_o release]; })
760b21d824SArgyrios Kyrtzidis #define xpc_retain(object) ({ xpc_object_t _o = (object); _xpc_object_validate(_o); [_o retain]; })
770b21d824SArgyrios Kyrtzidis #define xpc_release(object) ({ xpc_object_t _o = (object); _xpc_object_validate(_o); [_o release]; })
780b21d824SArgyrios Kyrtzidis 
790b21d824SArgyrios Kyrtzidis typedef id dispatch_object_t;
800b21d824SArgyrios Kyrtzidis typedef id xpc_object_t;
810b21d824SArgyrios Kyrtzidis 
820b21d824SArgyrios Kyrtzidis void _dispatch_object_validate(dispatch_object_t object);
830b21d824SArgyrios Kyrtzidis void _xpc_object_validate(xpc_object_t object);
84273c7c40SArgyrios Kyrtzidis 
85273c7c40SArgyrios Kyrtzidis #if __has_feature(objc_arc)
86273c7c40SArgyrios Kyrtzidis 
CFBridgingRetain(id X)87273c7c40SArgyrios Kyrtzidis NS_INLINE CF_RETURNS_RETAINED CFTypeRef CFBridgingRetain(id X) {
88273c7c40SArgyrios Kyrtzidis     return (__bridge_retained CFTypeRef)X;
89273c7c40SArgyrios Kyrtzidis }
90273c7c40SArgyrios Kyrtzidis 
CFBridgingRelease(CFTypeRef CF_CONSUMED X)91273c7c40SArgyrios Kyrtzidis NS_INLINE id CFBridgingRelease(CFTypeRef CF_CONSUMED X) {
92273c7c40SArgyrios Kyrtzidis     return (__bridge_transfer id)X;
93273c7c40SArgyrios Kyrtzidis }
94273c7c40SArgyrios Kyrtzidis 
95273c7c40SArgyrios Kyrtzidis #else
96273c7c40SArgyrios Kyrtzidis 
CFBridgingRetain(id X)97273c7c40SArgyrios Kyrtzidis NS_INLINE CF_RETURNS_RETAINED CFTypeRef CFBridgingRetain(id X) {
98273c7c40SArgyrios Kyrtzidis     return X ? CFRetain((CFTypeRef)X) : NULL;
99273c7c40SArgyrios Kyrtzidis }
100273c7c40SArgyrios Kyrtzidis 
CFBridgingRelease(CFTypeRef CF_CONSUMED X)101273c7c40SArgyrios Kyrtzidis NS_INLINE id CFBridgingRelease(CFTypeRef CF_CONSUMED X) {
102273c7c40SArgyrios Kyrtzidis     return [(id)CFMakeCollectable(X) autorelease];
103273c7c40SArgyrios Kyrtzidis }
104273c7c40SArgyrios Kyrtzidis 
105273c7c40SArgyrios Kyrtzidis #endif
106*6ba7afb8SArgyrios Kyrtzidis 
107*6ba7afb8SArgyrios Kyrtzidis void *_Block_copy(const void *aBlock);
108*6ba7afb8SArgyrios Kyrtzidis void _Block_release(const void *aBlock);
109*6ba7afb8SArgyrios Kyrtzidis #define Block_copy(...) ((__typeof(__VA_ARGS__))_Block_copy((const void *)(__VA_ARGS__)))
110*6ba7afb8SArgyrios Kyrtzidis #define Block_release(...) _Block_release((const void *)(__VA_ARGS__))
111