]> gcc.gnu.org Git - gcc.git/blob - gcc/objc/objc.h
Initial check in. Preliminary development stage.
[gcc.git] / gcc / objc / objc.h
1 /* -*-c-*-
2 * This file contains declarations used by the run-time system.
3 *
4 * Most of these declarations are defined by virtue of data
5 * structures produced by the compiler.
6 *
7 $Header$
8 $Author$
9 $Date$
10 $Log$
11 */
12
13
14 #ifndef _objc_INCLUDE_GNU
15 #define _objc_INCLUDE_GNU
16
17 /* If someone is using a c++
18 compiler then adjust the
19 types in the file back
20 to C. */
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 #include <sys/types.h>
26 #include <hash.h>
27
28
29 #define nil ( id )0 /* id of Nil instance */
30 #define Nil ( Class_t )0 /* id of Nil class */
31 typedef char* STR; /* String alias */
32
33 /* Boolean typedefs */
34 typedef char BOOL;
35 #define YES (BOOL)1
36 #define NO (BOOL)0
37
38 /* Defination of a
39 selector. Selectors are
40 really of type char*. The
41 run-time uses strcmp() to
42 locate selectors. */
43 typedef STR SEL;
44
45 /* ObjC uses this typedef
46 for untyped instances. */
47 typedef struct objc_object {
48 struct objc_class* isa;
49 } *id;
50
51 /* Prototype for method
52 functions. */
53 typedef id ( *IMP )(
54 #ifdef __STDC__
55 id, SEL, ...
56 #endif
57 );
58
59 /* Filer types used to
60 describe Ivars and
61 Methods. */
62 #define _C_ID '@'
63 #define _C_CLASS '#'
64 #define _C_SEL ':'
65 #define _C_CHR 'c'
66 #define _C_UCHR 'C'
67 #define _C_SHT 's'
68 #define _C_USHT 'S'
69 #define _C_INT 'i'
70 #define _C_UINT 'I'
71 #define _C_LNG 'l'
72 #define _C_ULNG 'L'
73 #define _C_FLT 'f'
74 #define _C_DBL 'd'
75 #define _C_BFLD 'b'
76 #define _C_VOID 'v'
77 #define _C_UNDEF '?'
78 #define _C_PTR '^'
79 #define _C_CHARPTR '*'
80 #define _C_ARY_B '['
81 #define _C_ARY_E ']'
82 #define _C_UNION_B '('
83 #define _C_UNION_E ')'
84 #define _C_STRUCT_B '{'
85 #define _C_STRUCT_E '}'
86
87 /*
88 * These definitions are masks used with
89 * the "info" member variable in the class and
90 * meta class structures.
91 */
92 #define CLS_CLASS 0x1L /* The structure is of type
93 class (Class_t). */
94 #define CLS_META 0x2L /* The structure is of type
95 meta class (MetaClass_t). */
96 #define CLS_INITIALIZED 0x4L /* Class is initialized. A
97 +initialize method is the
98 first message sent to a
99 class. It isn't guaranteed
100 to be sent only once. */
101 #define CLS_POSING 0x8L /* Class is posing as another.
102 Used to fix broken
103 classes. */
104 #define CLS_MAPPED 0x10L /* Unknown. */
105
106
107 /* Set this variable to !0 to
108 have the messager print
109 messaging operations. */
110 extern BOOL objc_trace;
111
112
113 /*
114 * Whereas a Module (defined further down) is the
115 * root (typically) of a file, a Symtab is the root of the
116 * class and category definitions within the module.
117 *
118 * A Symtab contains a variable length array of pointers
119 * to classes and categories defined in the module.
120 */
121 typedef struct objc_symtab {
122 u_long sel_ref_cnt; /* Unknown. */
123 SEL *refs; /* Unknown. */
124 u_short cls_def_cnt; /* Number of classes compiled
125 (defined) in the module. */
126 u_short cat_def_cnt; /* Number of categories
127 compiled (defined) in the
128 module. */
129 void *defs[1]; /* Variable array of pointers.
130 cls_def_cnt of type Class_t
131 followed by cat_def_cnt of
132 type Category_t. */
133 } Symtab, *Symtab_t;
134
135
136 /*
137 * The compiler generates one of these structures for each
138 * module that composes the executable (eg main.m).
139 *
140 * This data structure is the root of the definition tree
141 * for the module.
142 *
143 * A collect program runs between ld stages and creates
144 * a ObjC ctor array. That array holds a pointer to each
145 * module structure of the executable.
146 */
147 typedef struct objc_module {
148 u_long version; /* Unknown. */
149 u_long size; /* Suspect this is
150 sizeof(Module). It is always
151 16. */
152 char* name; /* Name of the file where the
153 module was generated. The
154 name includes the path. */
155 Symtab_t symtab; /* Pointer to the Symtab of
156 the module. The Symtab
157 holds an array of pointers to
158 the classes and categories
159 defined in the module. */
160 } Module, *Module_t;
161
162
163 /*
164 * The compiler generates one of these structures for a
165 * class that has instance variables defined in its
166 * specification.
167 */
168 typedef struct objc_ivar* Ivar_t;
169 typedef struct objc_ivar_list {
170 int ivar_count; /* Number of structures (Ivar)
171 contained in the list. One
172 structure per instance
173 variable defined in the
174 class. */
175 struct objc_ivar {
176 char* ivar_name; /* Name of the instance
177 variable as entered in the
178 class definition. */
179 char* ivar_type; /* Description of the Ivar's
180 type. Useful for
181 debuggers. */
182 int ivar_offset; /* Byte offset from the base
183 address of the instance
184 structure to the variable. */
185
186 } ivar_list[1]; /* Variable length
187 structure. */
188 } IvarList, *IvarList_t;
189
190
191 /*
192 * The compiler generates one (or more) of these structures
193 * for a class that has methods defined in its specification.
194 *
195 * The implementation of a class can be broken into separate
196 * pieces in a file and categories can break them across modules.
197 * To handle this problem is a singly linked list of methods.
198 */
199 typedef struct objc_method Method;
200 typedef Method* Method_t;
201 typedef struct objc_method_list {
202 struct objc_method_list* method_next; /* This variable is used to link
203 a method list to another. It
204 is a singly linked list. */
205 int method_count; /* Number of methods defined in
206 this structure. */
207 struct objc_method {
208 SEL method_name; /* This variable is the method's
209 name. It is a char*.
210 The unique integer passed to
211 objc_msgSend() is a char* too.
212 It is compared against
213 method_name using strcmp(). */
214 char* method_types; /* Description of the method's
215 parameter list. Useful for
216 debuggers. */
217 IMP method_imp; /* Address of the method in the
218 executable. */
219 } method_list[1]; /* Variable length
220 structure. */
221 } MethodList, *MethodList_t;
222
223
224 /*
225 * The compiler generates one of these structures for
226 * each class.
227 *
228 * This structure is the definition for meta classes.
229 * By definition a meta class is the class's class. Its
230 * most relevant contribution is that its method list
231 * contain the class's factory methods.
232 *
233 * This structure is generated by the compiler in the
234 * executable and used by the run-time during normal
235 * messaging operations. Therefore some definitions
236 * don't make sense in some contexts.
237 */
238 typedef struct objc_metaClass {
239 char* isa; /* Always a pointer to the
240 string "Object". */
241 char* super_class; /* Name of the class's super
242 class. */
243 char* name; /* Name of the meta class. */
244 long version; /* Unknown. */
245 long info; /* Bit mask. See class masks
246 defined above. */
247 long instance_size; /* Always 0 except for Object.
248 Should be ignored. */
249 IvarList_t ivars; /* Always NULL except for
250 Object. Should be ignored. */
251 MethodList_t methods; /* Linked List of factory methods
252 for the class. */
253 Cache_t cache; /* Used to cache factory methods
254 defined for the class and its
255 super classes. Entries are
256 made to the cache as the
257 messager receives them. */
258 } MetaClass, *MetaClass_t;
259
260
261 /*
262 * The compiler generates one of these structures for
263 * each class.
264 *
265 * This structure is the definition for classes.
266 *
267 * This structure is generated by the compiler in the
268 * executable and used by the run-time during normal
269 * messaging operations. Therefore some definitions
270 * don't make sense in some contexts.
271 */
272 typedef struct objc_class {
273 MetaClass_t isa; /* Pointer to the class's
274 meta class. */
275 char* super_class; /* Name of the class's super
276 class. */
277 char* name; /* Name of the class. */
278 long version; /* Unknown. */
279 long info; /* Bit mask. See class masks
280 defined above. */
281 long instance_size; /* Size in bytes of the class.
282 The sum of the class definition
283 and all super class
284 definitions. */
285 IvarList_t ivars; /* Pointer to a structure that
286 describes the instance
287 variables in the class
288 definition. NULL indicates
289 no instance variables. Does
290 not include super class
291 variables. */
292 MethodList_t methods; /* Linked list of instance
293 methods defined for the
294 class. */
295 Cache_t cache; /* Used to cache instance methods
296 defined for the class and its
297 super classes. Entries are
298 made to the cache as the
299 messager receives them. */
300 } Class, *Class_t;
301
302
303 /*
304 * The compiler generates one of these structures
305 * for each category. A class may have many
306 * categories and contain both instance and
307 * factory methods.
308 */
309 typedef struct objc_category {
310 char* category_name; /* Name of the category. Name
311 contained in the () of the
312 category definition. */
313 char* class_name; /* Name of the class to which
314 the category belongs. */
315 MethodList_t instance_methods; /* Linked list of instance
316 methods defined in the
317 category. NULL indicates no
318 instance methods defined. */
319 MethodList_t class_methods; /* Linked list of factory
320 methods defined in the
321 category. NULL indicates no
322 class methods defined. */
323 } Category, *Category_t;
324
325
326 /*
327 * Structure used when a message is send to a class's
328 * super class. The compiler generates one of these
329 * structures and passes it to objc_msgSuper().
330 */
331 typedef struct objc_super {
332 id receiver; /* Id of the object sending
333 the message. */
334 char* class; /* Name of the object's super
335 class. Passed to remove a
336 level of indirection? */
337 } Super, *Super_t;
338
339
340 #ifdef __cplusplus
341 }
342 #endif
343
344 #endif
This page took 0.600807 seconds and 5 git commands to generate.