]> gcc.gnu.org Git - gcc.git/blob - gcc/objc/objc-api.h
(_objc_load_callback): Add declaration.
[gcc.git] / gcc / objc / objc-api.h
1 /* GNU Objective-C Runtime API.
2 Copyright (C) 1993, 1995 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
6 GNU CC is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
9 later version.
10
11 GNU CC is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 /* As a special exception, if you link this library with files compiled
21 with GCC to produce an executable, this does not cause the resulting
22 executable to be covered by the GNU General Public License. This
23 exception does not however invalidate any other reasons why the
24 executable file might be covered by the GNU General Public License. */
25
26 #ifndef __objc_api_INCLUDE_GNU
27 #define __objc_api_INCLUDE_GNU
28
29 #include "objc/objc.h"
30 #include "objc/hash.h"
31 #include <stdio.h>
32
33 /* For functions which return Method_t */
34 #define METHOD_NULL (Method_t)0
35 /* Boolean typedefs */
36 /*
37 ** Method descriptor returned by introspective Object methods.
38 ** This is really just the first part of the more complete objc_method
39 ** structure defined below and used internally by the runtime.
40 */
41 struct objc_method_description
42 {
43 SEL name; /* this is a selector, not a string */
44 char *types; /* type encoding */
45 };
46
47 /* Filer types used to describe Ivars and Methods. */
48 #define _C_ID '@'
49 #define _C_CLASS '#'
50 #define _C_SEL ':'
51 #define _C_CHR 'c'
52 #define _C_UCHR 'C'
53 #define _C_SHT 's'
54 #define _C_USHT 'S'
55 #define _C_INT 'i'
56 #define _C_UINT 'I'
57 #define _C_LNG 'l'
58 #define _C_ULNG 'L'
59 #define _C_FLT 'f'
60 #define _C_DBL 'd'
61 #define _C_BFLD 'b'
62 #define _C_VOID 'v'
63 #define _C_UNDEF '?'
64 #define _C_PTR '^'
65 #define _C_CHARPTR '*'
66 #define _C_ATOM '%'
67 #define _C_ARY_B '['
68 #define _C_ARY_E ']'
69 #define _C_UNION_B '('
70 #define _C_UNION_E ')'
71 #define _C_STRUCT_B '{'
72 #define _C_STRUCT_E '}'
73
74
75
76 /*
77 ** Set this variable nonzero to print a line describing each
78 ** message that is sent. (this is currently disabled)
79 */
80 extern BOOL objc_trace;
81
82
83 /*
84 ** Whereas a Module (defined further down) is the root (typically) of a file,
85 ** a Symtab is the root of the class and category definitions within the
86 ** module.
87 **
88 ** A Symtab contains a variable length array of pointers to classes and
89 ** categories defined in the module.
90 */
91 typedef struct objc_symtab {
92 unsigned long sel_ref_cnt; /* Unknown. */
93 SEL refs; /* Unknown. */
94 unsigned short cls_def_cnt; /* Number of classes compiled
95 (defined) in the module. */
96 unsigned short cat_def_cnt; /* Number of categories
97 compiled (defined) in the
98 module. */
99 void *defs[1]; /* Variable array of pointers.
100 cls_def_cnt of type Class
101 followed by cat_def_cnt of
102 type Category_t. */
103 } Symtab, *Symtab_t;
104
105
106 /* For every class which happens to have statically allocated instances in
107 this module, one OBJC_STATIC_INSTANCES is allocated by the compiler.
108 INSTANCES is NULL terminated and points to all statically allocated
109 instances of this class. */
110 struct objc_static_instances
111 {
112 char *class_name;
113 id instances[0];
114 };
115
116 /*
117 ** The compiler generates one of these structures for each module that
118 ** composes the executable (eg main.m).
119 **
120 ** This data structure is the root of the definition tree for the module.
121 **
122 ** A collect program runs between ld stages and creates a ObjC ctor array.
123 ** That array holds a pointer to each module structure of the executable.
124 */
125 typedef struct objc_module {
126 unsigned long version; /* Compiler revision. */
127 unsigned long size; /* sizeof(Module). */
128 const char* name; /* Name of the file where the
129 module was generated. The
130 name includes the path. */
131
132 /* Pointer to a NULL terminated array of objc_static_instances. */
133 struct objc_static_instances **statics;
134
135 Symtab_t symtab; /* Pointer to the Symtab of
136 the module. The Symtab
137 holds an array of pointers to
138 the classes and categories
139 defined in the module. */
140 } Module, *Module_t;
141
142
143 /*
144 ** The compiler generates one of these structures for a class that has
145 ** instance variables defined in its specification.
146 */
147 typedef struct objc_ivar* Ivar_t;
148 typedef struct objc_ivar_list {
149 int ivar_count; /* Number of structures (Ivar)
150 contained in the list. One
151 structure per instance
152 variable defined in the
153 class. */
154 struct objc_ivar {
155 const char* ivar_name; /* Name of the instance
156 variable as entered in the
157 class definition. */
158 const char* ivar_type; /* Description of the Ivar's
159 type. Useful for
160 debuggers. */
161 int ivar_offset; /* Byte offset from the base
162 address of the instance
163 structure to the variable. */
164
165 } ivar_list[1]; /* Variable length
166 structure. */
167 } IvarList, *IvarList_t;
168
169
170 /*
171 ** The compiler generates one (or more) of these structures for a class that
172 ** has methods defined in its specification.
173 **
174 ** The implementation of a class can be broken into separate pieces in a file
175 ** and categories can break them across modules. To handle this problem is a
176 ** singly linked list of methods.
177 */
178 typedef struct objc_method Method;
179 typedef Method* Method_t;
180 typedef struct objc_method_list {
181 struct objc_method_list* method_next; /* This variable is used to link
182 a method list to another. It
183 is a singly linked list. */
184 int method_count; /* Number of methods defined in
185 this structure. */
186 struct objc_method {
187 SEL method_name; /* This variable is the method's
188 name. It is a char*.
189 The unique integer passed to
190 objc_msg_send is a char* too.
191 It is compared against
192 method_name using strcmp. */
193 const char* method_types; /* Description of the method's
194 parameter list. Useful for
195 debuggers. */
196 IMP method_imp; /* Address of the method in the
197 executable. */
198 } method_list[1]; /* Variable length
199 structure. */
200 } MethodList, *MethodList_t;
201
202 struct objc_protocol_list {
203 struct objc_protocol_list *next;
204 int count;
205 Protocol *list[1];
206 };
207
208 /*
209 ** This is used to assure consistent access to the info field of
210 ** classes
211 */
212 #ifndef HOST_BITS_PER_LONG
213 #define HOST_BITS_PER_LONG (sizeof(long)*8)
214 #endif
215
216 #define __CLS_INFO(cls) ((cls)->info)
217 #define __CLS_ISINFO(cls, mask) ((__CLS_INFO(cls)&mask)==mask)
218 #define __CLS_SETINFO(cls, mask) (__CLS_INFO(cls) |= mask)
219
220 /* The structure is of type MetaClass */
221 #define _CLS_META 0x2L
222 #define CLS_ISMETA(cls) ((cls)&&__CLS_ISINFO(cls, _CLS_META))
223
224
225 /* The structure is of type Class */
226 #define _CLS_CLASS 0x1L
227 #define CLS_ISCLASS(cls) ((cls)&&__CLS_ISINFO(cls, _CLS_CLASS))
228
229 /*
230 ** The class is initialized within the runtime. This means that
231 ** it has had correct super and sublinks assigned
232 */
233 #define _CLS_RESOLV 0x8L
234 #define CLS_ISRESOLV(cls) __CLS_ISINFO(cls, _CLS_RESOLV)
235 #define CLS_SETRESOLV(cls) __CLS_SETINFO(cls, _CLS_RESOLV)
236
237 /*
238 ** The class has been send a +initialize message or a such is not
239 ** defined for this class
240 */
241 #define _CLS_INITIALIZED 0x04L
242 #define CLS_ISINITIALIZED(cls) __CLS_ISINFO(cls, _CLS_INITIALIZED)
243 #define CLS_SETINITIALIZED(cls) __CLS_SETINFO(cls, _CLS_INITIALIZED)
244
245 /*
246 ** The class number of this class. This must be the same for both the
247 ** class and it's meta class object
248 */
249 #define CLS_GETNUMBER(cls) (__CLS_INFO(cls) >> (HOST_BITS_PER_LONG/2))
250 #define CLS_SETNUMBER(cls, num) \
251 ({ (cls)->info <<= (HOST_BITS_PER_LONG/2); \
252 (cls)->info >>= (HOST_BITS_PER_LONG/2); \
253 __CLS_SETINFO(cls, (((unsigned long)num) << (HOST_BITS_PER_LONG/2))); })
254
255 /*
256 ** The compiler generates one of these structures for each category. A class
257 ** may have many categories and contain both instance and factory methods.
258 */
259 typedef struct objc_category {
260 const char* category_name; /* Name of the category. Name
261 contained in the () of the
262 category definition. */
263 const char* class_name; /* Name of the class to which
264 the category belongs. */
265 MethodList_t instance_methods; /* Linked list of instance
266 methods defined in the
267 category. NULL indicates no
268 instance methods defined. */
269 MethodList_t class_methods; /* Linked list of factory
270 methods defined in the
271 category. NULL indicates no
272 class methods defined. */
273 struct objc_protocol_list *protocols; /* List of Protocols
274 conformed to */
275 } Category, *Category_t;
276
277 /*
278 ** Structure used when a message is send to a class's super class. The
279 ** compiler generates one of these structures and passes it to
280 ** objc_msg_super.
281 */
282 typedef struct objc_super {
283 id self; /* Id of the object sending
284 the message. */
285 Class class; /* Object's super class. */
286 } Super, *Super_t;
287
288 IMP objc_msg_lookup_super(Super_t super, SEL sel);
289
290 retval_t objc_msg_sendv(id, SEL, arglist_t);
291
292
293
294 /*
295 ** This is a hook which is called by objc_lookup_class and
296 ** objc_get_class if the runtime is not able to find the class.
297 ** This may e.g. try to load in the class using dynamic loading.
298 ** The function is guaranteed to be passed a non-NULL name string.
299 */
300 extern Class (*_objc_lookup_class)(const char *name);
301
302 /*
303 ** This is a hook which is called by __objc_exec_class every time a class
304 ** or a category is loaded into the runtime. This may e.g. help a
305 ** dynamic loader determine the classes that have been loaded when
306 ** an object file is dynamically linked in.
307 */
308 extern void (*_objc_load_callback)(Class class, Category* category);
309
310 extern id (*_objc_object_alloc)(Class class);
311
312 extern id (*_objc_object_copy)(id object);
313
314 extern id (*_objc_object_dispose)(id object);
315
316 Method_t class_get_class_method(MetaClass class, SEL aSel);
317
318 Method_t class_get_instance_method(Class class, SEL aSel);
319
320 Class class_pose_as(Class impostor, Class superclass);
321
322 Class objc_get_class(const char *name);
323
324 Class objc_lookup_class(const char *name);
325
326 Class objc_next_class(void **enum_state);
327
328 const char *sel_get_name(SEL selector);
329
330 const char *sel_get_type(SEL selector);
331
332 SEL sel_get_uid(const char *name);
333
334 SEL sel_get_any_uid(const char *name);
335
336 SEL sel_get_typed_uid(const char *name, const char*);
337
338 SEL sel_register_name(const char *name);
339
340 SEL sel_register_typed_name(const char *name, const char*type);
341
342
343 BOOL sel_is_mapped (SEL aSel);
344
345 extern id class_create_instance(Class class);
346
347 static inline const char *
348 class_get_class_name(Class class)
349 {
350 return CLS_ISCLASS(class)?class->name:((class==Nil)?"Nil":0);
351 }
352
353 static inline long
354 class_get_instance_size(Class class)
355 {
356 return CLS_ISCLASS(class)?class->instance_size:0;
357 }
358
359 static inline MetaClass
360 class_get_meta_class(Class class)
361 {
362 return CLS_ISCLASS(class)?class->class_pointer:Nil;
363 }
364
365 static inline Class
366 class_get_super_class(Class class)
367 {
368 return CLS_ISCLASS(class)?class->super_class:Nil;
369 }
370
371 static inline int
372 class_get_version(Class class)
373 {
374 return CLS_ISCLASS(class)?class->version:-1;
375 }
376
377 static inline BOOL
378 class_is_class(Class class)
379 {
380 return CLS_ISCLASS(class);
381 }
382
383 static inline BOOL
384 class_is_meta_class(Class class)
385 {
386 return CLS_ISMETA(class);
387 }
388
389
390 static inline void
391 class_set_version(Class class, long version)
392 {
393 if (CLS_ISCLASS(class))
394 class->version = version;
395 }
396
397 static inline IMP
398 method_get_imp(Method_t method)
399 {
400 return (method!=METHOD_NULL)?method->method_imp:(IMP)0;
401 }
402
403 IMP get_imp (Class class, SEL sel);
404
405 id object_copy(id object);
406
407 id object_dispose(id object);
408
409 static inline Class
410 object_get_class(id object)
411 {
412 return ((object!=nil)
413 ? (CLS_ISCLASS(object->class_pointer)
414 ? object->class_pointer
415 : (CLS_ISMETA(object->class_pointer)
416 ? (Class)object
417 : Nil))
418 : Nil);
419 }
420
421 static inline const char *
422 object_get_class_name(id object)
423 {
424 return ((object!=nil)?(CLS_ISCLASS(object->class_pointer)
425 ?object->class_pointer->name
426 :((Class)object)->name)
427 :"Nil");
428 }
429
430 static inline MetaClass
431 object_get_meta_class(id object)
432 {
433 return ((object!=nil)?(CLS_ISCLASS(object->class_pointer)
434 ?object->class_pointer->class_pointer
435 :(CLS_ISMETA(object->class_pointer)
436 ?object->class_pointer
437 :Nil))
438 :Nil);
439 }
440
441 static inline Class
442 object_get_super_class
443 (id object)
444 {
445 return ((object!=nil)?(CLS_ISCLASS(object->class_pointer)
446 ?object->class_pointer->super_class
447 :(CLS_ISMETA(object->class_pointer)
448 ?((Class)object)->super_class
449 :Nil))
450 :Nil);
451 }
452
453 static inline BOOL
454 object_is_class(id object)
455 {
456 return CLS_ISCLASS((Class)object);
457 }
458
459 static inline BOOL
460 object_is_instance(id object)
461 {
462 return (object!=nil)&&CLS_ISCLASS(object->class_pointer);
463 }
464
465 static inline BOOL
466 object_is_meta_class(id object)
467 {
468 return CLS_ISMETA((Class)object);
469 }
470
471 #endif /* not __objc_api_INCLUDE_GNU */
472
473
474
This page took 0.06036 seconds and 6 git commands to generate.