1 #ifndef __OBJECTIVEC2_RUNTIME_H_INCLUDED__
2 #define __OBJECTIVEC2_RUNTIME_H_INCLUDED__
3 
4 #ifdef HAVE_STDINT_H
5 #include <stdint.h>
6 #else
7 #include <inttypes.h>
8 #endif
9 
10 #include <stddef.h>
11 #include <sys/types.h>
12 
13 #include "ObjectiveC2/objc/Availability.h"
14 
15 #if   defined(ERROR_UNSUPPORTED_RUNTIME_FUNCTIONS)
16 #  define OBJC_GNU_RUNTIME_UNSUPPORTED(x) \
17 __attribute__((error(x " not supported by the GNU runtime")))
18 #else
19 #  define OBJC_GNU_RUNTIME_UNSUPPORTED(x)
20 #endif
21 
22 #if !defined(OBJC_DEPRECATED)
23 #  if !defined(__DEPRECATE_DIRECT_ACCESS) || defined(__OBJC_LEGACY_GNU_MODE__) || defined(__OBJC_RUNTIME_INTERNAL__)
24 #    define OBJC_DEPRECATED
25 #  else
26 #    if ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR >= 1))
27 #      define OBJC_DEPRECATED __attribute__((deprecated))
28 #    else
29 #      define OBJC_DEPRECATED
30 #    endif
31 #  endif
32 #endif
33 
34 // Undo GNUstep substitutions
35 #ifdef class_setVersion
36 #undef class_setVersion
37 #endif
38 #ifdef class_getClassMethod
39 #undef class_getClassMethod
40 #endif
41 #ifdef objc_getClass
42 #undef objc_getClass
43 #endif
44 #ifdef objc_lookUpClass
45 #undef objc_lookUpClass
46 #endif
47 
48 typedef struct objc_ivar* Ivar;
49 
50 #ifndef __objc_INCLUDE_GNU
51 typedef const struct objc_selector *SEL;
52 
53 typedef struct objc_class *Class;
54 
55 typedef struct objc_object
56 {
57   Class isa;
58 } *id;
59 
60 struct objc_super {
61   id receiver;
62 #  if !defined(__cplusplus)  &&  !__OBJC2__
63   Class class;
64 #  else
65   Class super_class;
66 #  endif
67 };
68 
69 typedef id (*IMP)(id, SEL, ...);
70 typedef struct objc_method *Method;
71 
72 #  ifdef STRICT_APPLE_COMPATIBILITY
73 typedef signed char BOOL;
74 #  else
75 #    ifdef __vxwords
76 typedef  int BOOL
77 #    else
78 typedef unsigned char BOOL;
79 #    endif
80 #  endif
81 
82 #else
83 // Method in the GNU runtime is a struct, Method_t is the pointer
84 #	define Method Method_t
85 #endif // __objc_INCLUDE_GNU
86 
87 
88 
89 typedef void *objc_property_t;
90 #ifdef __OBJC__
91 @class Protocol;
92 #else
93 typedef struct objc_protocol Protocol;
94 #endif
95 
96 #ifndef YES
97 #define YES ((BOOL)1)
98 #endif
99 #ifndef NO
100 #define NO ((BOOL)0)
101 #endif
102 
103 #ifdef __GNUC
104 #define _OBJC_NULL_PTR __null
105 #elif defined(__cplusplus)
106 #define _OBJC_NULL_PTR 0
107 #else
108 #define _OBJC_NULL_PTR ((void*)0)
109 #endif
110 
111 #ifndef nil
112 #define nil ((id)_OBJC_NULL_PTR)
113 #endif
114 
115 #ifndef Nil
116 #define Nil ((Class)_OBJC_NULL_PTR)
117 #endif
118 
119 BOOL class_addIvar(Class cls,
120                    const char *name,
121                    size_t size,
122                    uint8_t alignment,
123                    const char *types);
124 
125 BOOL class_addMethod(Class cls, SEL name, IMP imp, const char *types);
126 
127 BOOL class_addProtocol(Class cls, Protocol *protocol);
128 
129 BOOL class_conformsToProtocol(Class cls, Protocol *protocol);
130 
131 Ivar * class_copyIvarList(Class cls, unsigned int *outCount);
132 
133 Method * class_copyMethodList(Class cls, unsigned int *outCount);
134 
135 OBJC_GNU_RUNTIME_UNSUPPORTED("Property introspection")
136 objc_property_t * class_copyPropertyList(Class cls, unsigned int *outCount);
137 
138 Protocol ** class_copyProtocolList(Class cls, unsigned int *outCount);
139 
140 id class_createInstance(Class cls, size_t extraBytes);
141 
142 Method class_getClassMethod(Class aClass, SEL aSelector);
143 
144 Ivar class_getClassVariable(Class cls, const char* name);
145 
146 Method class_getInstanceMethod(Class aClass, SEL aSelector);
147 
148 size_t class_getInstanceSize(Class cls);
149 
150 Ivar class_getInstanceVariable(Class cls, const char* name);
151 
152 const char *class_getIvarLayout(Class cls);
153 
154 IMP class_getMethodImplementation(Class cls, SEL name);
155 
156 IMP class_getMethodImplementation_stret(Class cls, SEL name);
157 
158 const char * class_getName(Class cls);
159 
160 OBJC_GNU_RUNTIME_UNSUPPORTED("Property introspection")
161 objc_property_t class_getProperty(Class cls, const char *name);
162 
163 Class class_getSuperclass(Class cls);
164 
165 int class_getVersion(Class theClass);
166 
167 OBJC_GNU_RUNTIME_UNSUPPORTED("Weak instance variables")
168 const char *class_getWeakIvarLayout(Class cls);
169 
170 BOOL class_isMetaClass(Class cls);
171 
172 IMP class_replaceMethod(Class cls, SEL name, IMP imp, const char *types);
173 
174 BOOL class_respondsToSelector(Class cls, SEL sel);
175 
176 void class_setIvarLayout(Class cls, const char *layout);
177 
178 OBJC_DEPRECATED
179 Class class_setSuperclass(Class cls, Class newSuper);
180 
181 void class_setVersion(Class theClass, int version);
182 
183 OBJC_GNU_RUNTIME_UNSUPPORTED("Weak instance variables")
184 void class_setWeakIvarLayout(Class cls, const char *layout);
185 
186 const char * ivar_getName(Ivar ivar);
187 
188 ptrdiff_t ivar_getOffset(Ivar ivar);
189 
190 const char * ivar_getTypeEncoding(Ivar ivar);
191 
192 char * method_copyArgumentType(Method method, unsigned int index);
193 
194 char * method_copyReturnType(Method method);
195 
196 void method_exchangeImplementations(Method m1, Method m2);
197 
198 void method_getArgumentType(Method method, unsigned int index, char *dst, size_t dst_len);
199 
200 IMP method_getImplementation(Method method);
201 
202 SEL method_getName(Method method);
203 
204 unsigned method_getNumberOfArguments(Method method);
205 
206 void method_getReturnType(Method method, char *dst, size_t dst_len);
207 
208 const char * method_getTypeEncoding(Method method);
209 
210 IMP method_setImplementation(Method method, IMP imp);
211 
212 Class
213 objc_allocateClassPair(Class superclass, const char *name, size_t extraBytes);
214 
215 OBJC_NONPORTABLE
216 Class objc_allocateMetaClass(Class superclass, size_t extraBytes);
217 
218 void objc_disposeClassPair(Class cls);
219 
220 id objc_getClass(const char *name);
221 
222 int objc_getClassList(Class *buffer, int bufferLen);
223 
224 id objc_getMetaClass(const char *name);
225 
226 id objc_getRequiredClass(const char *name);
227 
228 id objc_lookUpClass(const char *name);
229 
230 Class objc_allocateClassPair(Class superclass, const char *name, size_t extraBytes);
231 
232 Protocol *objc_getProtocol(const char *name);
233 
234 void objc_registerClassPair(Class cls);
235 
236 void *object_getIndexedIvars(id obj);
237 
238 // FIXME: The GNU runtime has a version of this which omits the size parameter
239 //id object_copy(id obj, size_t size);
240 
241 id object_dispose(id obj);
242 
243 Class object_getClass(id obj);
244 Class object_setClass(id obj, Class cls);
245 
246 const char *object_getClassName(id obj);
247 
248 IMP objc_msg_lookup(id, SEL);
249 IMP objc_msg_lookup_super(struct objc_super*, SEL);
250 
251 OBJC_GNU_RUNTIME_UNSUPPORTED("Protocol introspection")
252 Protocol **objc_copyProtocolList(unsigned int *count);
253 
254 BOOL protocol_conformsToProtocol(Protocol *p, Protocol *other);
255 
256 struct objc_method_description *protocol_copyMethodDescriptionList(Protocol *p,
257   BOOL isRequiredMethod, BOOL isInstanceMethod, unsigned int *count);
258 
259 OBJC_GNU_RUNTIME_UNSUPPORTED("Protocol introspection")
260 objc_property_t *protocol_copyPropertyList(Protocol *p, unsigned int *count);
261 
262 Protocol **protocol_copyProtocolList(Protocol *p, unsigned int *count);
263 
264 struct objc_method_description protocol_getMethodDescription(Protocol *p,
265   SEL aSel, BOOL isRequiredMethod, BOOL isInstanceMethod);
266 
267 const char *protocol_getName(Protocol *p);
268 
269 OBJC_GNU_RUNTIME_UNSUPPORTED("Protocol introspection")
270 objc_property_t protocol_getProperty(Protocol *p, const char *name,
271   BOOL isRequiredProperty, BOOL isInstanceProperty);
272 
273 BOOL protocol_isEqual(Protocol *p, Protocol *other);
274 
275 // Only enable support for object planes when
276 // -fobjc-sender-dependent-dispatch is specified
277 #ifdef __OBJC_SENDER_AWARE_DISPATCH__
278 
279 // Global self so that self is a valid symbol everywhere.  Will be replaced by
280 // a real self in an inner scope if there is one.
281 static const id self = nil;
282 #define objc_msgSend(theReceiver, theSelector, ...) objc_msg_lookup_sender(theReceiver, theSelector, self)(theReceiver, theSelector, ## __VA_ARGS__)
283 
284 #endif
285 
286 #if (GCC_VERSION >= 3000)
287 
288 #define objc_msgSend(theReceiver, theSelector, ...) objc_msg_lookup(theReceiver, theSelector)(theReceiver, theSelector, ## __VA_ARGS__)
289 #define objc_msgSendSuper(super, op, ...) objc_msg_lookup_super(super, op)(super->receiver, op, ## __VA_ARGS__)
290 
291 #else /* GCC_VERSION >= 3000 */
292 
293 #define objc_msgSend(theReceiver, theSelector, args...) objc_msg_lookup(theReceiver, theSelector)(theReceiver, theSelector, args)
294 #define objc_msgSendSuper(super, op, args...) objc_msg_lookup_super(super, op)(super->receiver, op, args)
295 
296 #endif /* GCC_VERSION >= 3000 */
297 
298 
299 const char *sel_getName(SEL sel);
300 
301 SEL sel_getUid(const char *selName);
302 
303 BOOL sel_isEqual(SEL sel1, SEL sel2);
304 
305 SEL sel_registerName(const char *selName);
306 
307 #endif // __OBJECTIVEC2_RUNTIME_H_INCLUDED
308