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