OSDN Git Service

Daily bump.
[pf3gnuchains/gcc-fork.git] / libobjc / objc / objc-api.h
1 /* GNU Objective-C Runtime API - Traditional API
2    Copyright (C) 1993, 1995, 1996, 1997, 2001, 2002, 2003, 2004, 2005,
3    2007, 2009, 2010 Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3, or (at your option) any
10 later version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
15 License for more details.
16
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
20
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
24 <http://www.gnu.org/licenses/>.  */
25
26 #ifndef __objc_api_INCLUDE_GNU
27 #define __objc_api_INCLUDE_GNU
28
29 /*
30   This file declares the "traditional" GNU Objective-C Runtime API.
31   It is the API supported by older versions of the GNU Objective-C
32   Runtime.  Include this file to use it.
33
34   This API is being replaced by the "modern" GNU Objective-C Runtime
35   API, which is declared in objc/runtime.h.  The "modern" API is very
36   similar to the API used by the modern Apple/NeXT runtime.
37
38   Because the two APIs have some conflicting definitions (in
39   particular, Method and Category are defined differently) you should
40   include either objc/objc-api.h (to use the traditional GNU
41   Objective-C Runtime API) or objc/runtime.h (to use the modern GNU
42   Objective-C Runtime API), but not both.
43 */
44 #ifdef __objc_runtime_INCLUDE_GNU
45 # error You can not include both objc/objc-api.h and objc/runtime.h.  Include objc/objc-api.h for the traditional GNU Objective-C Runtime API and objc/runtime.h for the modern one.
46 #endif
47
48 #include "objc.h"
49 #ifndef GNU_LIBOBJC_COMPILING_LIBOBJC_ITSELF
50 # include "deprecated/hash.h"
51 #endif
52 #include "thr.h"
53 #include "objc-decls.h"
54 #include <stdio.h>
55 #include <stdarg.h>
56
57 #ifdef __cplusplus
58 extern "C" {
59 #endif /* __cplusplus */
60
61 #include "deprecated/METHOD_NULL.h"
62
63 /* Method descriptor returned by introspective Object methods.
64    This is really just the first part of the more complete objc_method
65    structure defined below and used internally by the runtime.  */
66 struct objc_method_description
67 {
68     SEL name;                   /* this is a selector, not a string */
69     char *types;                /* type encoding */
70 };
71
72 /* The following are used in encode strings to describe the type of
73    Ivars and Methods.  */
74 #define _C_ID       '@'
75 #define _C_CLASS    '#'
76 #define _C_SEL      ':'
77 #define _C_CHR      'c'
78 #define _C_UCHR     'C'
79 #define _C_SHT      's'
80 #define _C_USHT     'S'
81 #define _C_INT      'i'
82 #define _C_UINT     'I'
83 #define _C_LNG      'l'
84 #define _C_ULNG     'L'
85 #define _C_LNG_LNG  'q'
86 #define _C_ULNG_LNG 'Q'
87 #define _C_FLT      'f'
88 #define _C_DBL      'd'
89 #define _C_LNG_DBL  'D'
90 #define _C_BFLD     'b'
91 #define _C_BOOL     'B'
92 #define _C_VOID     'v'
93 #define _C_UNDEF    '?'
94 #define _C_PTR      '^'
95 #define _C_CHARPTR  '*'
96 #define _C_ARY_B    '['
97 #define _C_ARY_E    ']'
98 #define _C_UNION_B  '('
99 #define _C_UNION_E  ')'
100 #define _C_STRUCT_B '{'
101 #define _C_STRUCT_E '}'
102 #define _C_VECTOR   '!'
103 #define _C_COMPLEX  'j'
104
105 /* _C_ATOM is never generated by the compiler.  You can treat it as
106    equivalent to "*".  */
107 #define _C_ATOM     '%'
108
109 #include "deprecated/objc_error.h"
110
111 #include "deprecated/struct_objc_static_instances.h"
112 #include "deprecated/struct_objc_symtab.h"
113 #include "deprecated/struct_objc_module.h"
114 #include "deprecated/struct_objc_ivar.h"
115 #include "deprecated/struct_objc_ivar_list.h"
116 #include "deprecated/struct_objc_method.h"
117 typedef struct objc_method Method, *Method_t;
118
119 #include "deprecated/struct_objc_method_list.h"
120 #include "deprecated/struct_objc_protocol_list.h"
121
122 /*
123 ** This is used to assure consistent access to the info field of 
124 ** classes
125 */
126 #ifndef HOST_BITS_PER_LONG
127 #define HOST_BITS_PER_LONG  (sizeof(long)*8)
128 #endif 
129
130 #define __CLS_INFO(cls) ((cls)->info)
131 #define __CLS_ISINFO(cls, mask) ((__CLS_INFO(cls)&mask)==mask)
132 #define __CLS_SETINFO(cls, mask) (__CLS_INFO(cls) |= mask)
133
134 /* The structure is of type MetaClass */
135 #define _CLS_META 0x2L
136 #define CLS_ISMETA(cls) ((cls)&&__CLS_ISINFO(cls, _CLS_META))
137
138
139 /* The structure is of type Class */
140 #define _CLS_CLASS 0x1L
141 #define CLS_ISCLASS(cls) ((cls)&&__CLS_ISINFO(cls, _CLS_CLASS))
142
143 /*
144 ** The class is initialized within the runtime.  This means that 
145 ** it has had correct super and sublinks assigned
146 */
147 #define _CLS_RESOLV 0x8L
148 #define CLS_ISRESOLV(cls) __CLS_ISINFO(cls, _CLS_RESOLV)
149 #define CLS_SETRESOLV(cls) __CLS_SETINFO(cls, _CLS_RESOLV)
150
151 /*
152 ** The class has been send a +initialize message or a such is not 
153 ** defined for this class
154 */
155 #define _CLS_INITIALIZED 0x04L
156 #define CLS_ISINITIALIZED(cls) __CLS_ISINFO(cls, _CLS_INITIALIZED)
157 #define CLS_SETINITIALIZED(cls) __CLS_SETINFO(cls, _CLS_INITIALIZED)
158
159 /*
160 ** The class number of this class.  This must be the same for both the 
161 ** class and its meta class object
162 */
163 #define CLS_GETNUMBER(cls) (__CLS_INFO(cls) >> (HOST_BITS_PER_LONG/2))
164 #define CLS_SETNUMBER(cls, num) \
165   ({ (cls)->info <<= (HOST_BITS_PER_LONG/2); \
166      (cls)->info >>= (HOST_BITS_PER_LONG/2); \
167      __CLS_SETINFO(cls, (((unsigned long)num) << (HOST_BITS_PER_LONG/2))); })
168
169 #include "deprecated/struct_objc_category.h"
170
171 typedef struct objc_category Category, *Category_t;
172
173 /* We include message.h for compatibility with the old objc-api.h
174    which included the declarations currently in message.h.  The
175    Apple/NeXT runtime does not do this and only includes message.h in
176    objc-runtime.h.  It does not matter that much since most of the
177    definitions in message.h are runtime-specific.  */
178 #include "message.h"
179
180 /*
181 ** This is a hook which is called by objc_lookup_class and
182 ** objc_get_class if the runtime is not able to find the class.
183 ** This may e.g. try to load in the class using dynamic loading.
184 ** The function is guaranteed to be passed a non-NULL name string.
185 */
186 objc_EXPORT Class (*_objc_lookup_class)(const char *name);
187
188 /*
189 ** This is a hook which is called by __objc_exec_class every time a class
190 ** or a category is loaded into the runtime.  This may e.g. help a
191 ** dynamic loader determine the classes that have been loaded when
192 ** an object file is dynamically linked in.
193 */
194 objc_EXPORT void (*_objc_load_callback)(Class _class, Category* category);
195
196 #include "deprecated/objc_object_alloc.h"
197
198 /*
199   Standard functions for memory allocation and disposal.  Users should
200   use these functions in their ObjC programs so that they work so that
201   they work properly with garbage collectors.
202 */
203 objc_EXPORT void *
204 objc_malloc(size_t size);
205
206 /* FIXME: Shouldn't the following be called objc_malloc_atomic ?  The
207    GC function is GC_malloc_atomic() which makes sense.
208  */
209 objc_EXPORT void *
210 objc_atomic_malloc(size_t size);
211
212 objc_EXPORT void *
213 objc_realloc(void *mem, size_t size);
214
215 objc_EXPORT void *
216 objc_calloc(size_t nelem, size_t size);
217
218 objc_EXPORT void
219 objc_free(void *mem);
220
221 #include "deprecated/objc_valloc.h"
222 #include "deprecated/objc_malloc.h"
223
224 #include "deprecated/objc_unexpected_exception.h"
225
226 objc_EXPORT Method_t class_get_class_method(MetaClass _class, SEL aSel);
227
228 objc_EXPORT Method_t class_get_instance_method(Class _class, SEL aSel);
229
230 objc_EXPORT Class class_pose_as(Class impostor, Class superclass);
231
232 objc_EXPORT Class objc_get_class(const char *name);
233
234 objc_EXPORT Class objc_lookup_class(const char *name);
235
236 objc_EXPORT Class objc_next_class(void **enum_state);
237
238 objc_EXPORT const char *sel_get_name(SEL selector);
239
240 objc_EXPORT const char *sel_get_type(SEL selector);
241
242 objc_EXPORT SEL sel_get_uid(const char *name);
243
244 objc_EXPORT SEL sel_get_any_uid(const char *name);
245
246 objc_EXPORT SEL sel_get_any_typed_uid(const char *name);
247
248 objc_EXPORT SEL sel_get_typed_uid(const char *name, const char*);
249
250 objc_EXPORT SEL sel_register_name(const char *name);
251
252 objc_EXPORT SEL sel_register_typed_name(const char *name, const char*type);
253
254
255 objc_EXPORT BOOL sel_is_mapped (SEL aSel);
256
257 extern id class_create_instance(Class _class);
258
259 static inline const char *
260 class_get_class_name(Class _class)
261 {
262   return CLS_ISCLASS(_class)?_class->name:((_class==Nil)?"Nil":0);
263 }
264
265 static inline long
266 class_get_instance_size(Class _class)
267 {
268   return CLS_ISCLASS(_class)?_class->instance_size:0;
269 }
270
271 static inline MetaClass
272 class_get_meta_class(Class _class)
273 {
274   return CLS_ISCLASS(_class)?_class->class_pointer:Nil;
275 }
276
277 static inline Class
278 class_get_super_class(Class _class)
279 {
280   return CLS_ISCLASS(_class)?_class->super_class:Nil;
281 }
282
283 static inline int
284 class_get_version(Class _class)
285 {
286   return CLS_ISCLASS(_class)?_class->version:-1;
287 }
288
289 static inline BOOL
290 class_is_class(Class _class)
291 {
292   return CLS_ISCLASS(_class);
293 }
294
295 static inline BOOL
296 class_is_meta_class(Class _class)
297 {
298   return CLS_ISMETA(_class);
299 }
300
301
302 static inline void
303 class_set_version(Class _class, long version)
304 {
305   if (CLS_ISCLASS(_class))
306     _class->version = version;
307 }
308
309 static inline void *
310 class_get_gc_object_type (Class _class)
311 {
312   return CLS_ISCLASS(_class) ? _class->gc_object_type : NULL;
313 }
314
315 /* Mark the instance variable as innaccessible to the garbage collector */
316 extern void class_ivar_set_gcinvisible (Class _class,
317                                         const char* ivarname,
318                                         BOOL gcInvisible);
319
320 objc_EXPORT IMP method_get_imp(Method_t method);
321
322 objc_EXPORT IMP get_imp (Class _class, SEL sel);
323
324 /* object_copy used to take a single argument in the traditional GNU
325    Objective-C Runtime API (the one declared here), but takes 2 in the
326    modern API (implemented in the actual runtime).  Define the old
327    object_copy in terms of the new one.  */
328 objc_EXPORT id object_copy (id object, size_t size);
329 #define object_copy(X) (object_copy ((X), 0))
330
331 objc_EXPORT id object_dispose(id object);
332
333 static inline Class
334 object_get_class(id object)
335 {
336   return ((object!=nil)
337           ? (CLS_ISCLASS(object->class_pointer)
338              ? object->class_pointer
339              : (CLS_ISMETA(object->class_pointer)
340                 ? (Class)object
341                 : Nil))
342           : Nil);
343 }
344
345 static inline const char *
346 object_get_class_name(id object)
347 {
348   return ((object!=nil)?(CLS_ISCLASS(object->class_pointer)
349                          ?object->class_pointer->name
350                          :((Class)object)->name)
351                        :"Nil");
352 }
353
354 static inline MetaClass
355 object_get_meta_class(id object)
356 {
357   return ((object!=nil)?(CLS_ISCLASS(object->class_pointer)
358                          ?object->class_pointer->class_pointer
359                          :(CLS_ISMETA(object->class_pointer)
360                            ?object->class_pointer
361                            :Nil))
362                        :Nil);
363 }
364
365 static inline Class
366 object_get_super_class
367 (id object)
368 {
369   return ((object!=nil)?(CLS_ISCLASS(object->class_pointer)
370                          ?object->class_pointer->super_class
371                          :(CLS_ISMETA(object->class_pointer)
372                            ?((Class)object)->super_class
373                            :Nil))
374                        :Nil);
375 }
376
377 static inline BOOL
378 object_is_class (id object)
379 {
380   return ((object != nil)  &&  CLS_ISMETA (object->class_pointer));
381 }
382  
383 static inline BOOL
384 object_is_instance (id object)
385 {
386   return ((object != nil)  &&  CLS_ISCLASS (object->class_pointer));
387 }
388
389 static inline BOOL
390 object_is_meta_class (id object)
391 {
392   return ((object != nil)
393           &&  !object_is_instance (object)  
394           &&  !object_is_class (object));
395 }
396
397 #include "deprecated/objc_get_uninstalled_dtable.h"
398
399 #ifdef __cplusplus
400 }
401 #endif /* __cplusplus */
402
403 #endif /* not __objc_api_INCLUDE_GNU */
404
405
406