In libobjc/: 2010-12-21 Nicola Pero <nicola.pero@meta-innovation.com>
[official-gcc.git] / libobjc / objc-private / module-abi-8.h
blob0c9574bb49911f59fd35f82ed780eed5305a8a0a
1 /* Definitions of Module Structures used by ABI version 8
2 Copyright (C) 1993, 1995, 1996, 1997, 2001, 2002, 2003, 2004, 2005,
3 2007, 2009, 2010 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under the
8 terms of the GNU General Public License as published by the Free Software
9 Foundation; either version 3, or (at your option) any later version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14 details.
16 Under Section 7 of GPL version 3, you are granted additional
17 permissions described in the GCC Runtime Library Exception, version
18 3.1, as published by the Free Software Foundation.
20 You should have received a copy of the GNU General Public License and
21 a copy of the GCC Runtime Library Exception along with this program;
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 <http://www.gnu.org/licenses/>. */
25 #ifndef __objc_private_module_abi_8_INCLUDE_GNU
26 #define __objc_private_module_abi_8_INCLUDE_GNU
28 /* For every class which happens to have statically allocated instances in
29 this module, one OBJC_STATIC_INSTANCES is allocated by the compiler.
30 INSTANCES is NULL terminated and points to all statically allocated
31 instances of this class. */
32 struct objc_static_instances
34 char *class_name;
35 #ifdef __cplusplus
36 id instances[1];
37 #else
38 id instances[0];
39 #endif
42 /* Whereas a Module (defined further down) is the root (typically) of a file,
43 a Symtab is the root of the class and category definitions within the
44 module.
46 A Symtab contains a variable length array of pointers to classes and
47 categories defined in the module. */
48 struct objc_symtab
50 unsigned long sel_ref_cnt; /* Unused (always set to 0). */
51 struct objc_selector *refs; /* The table of selectors referenced in
52 this module. This is terminated by a
53 selector with NULL sel_id and NULL
54 sel_types. Note that we use the type
55 'struct objc_selector *' and not
56 'SEL' (which is 'const struct
57 objc_selector *') because the sel_id
58 of these selectors is patched up by
59 the runtime when the module is
60 loaded. */
61 unsigned short cls_def_cnt; /* Number of classes compiled (defined)
62 in the module. */
63 unsigned short cat_def_cnt; /* Number of categories compiled
64 (defined) in the module. */
65 void *defs[1]; /* Variable array of pointers.
66 cls_def_cnt of type Class followed by
67 cat_def_cnt of type Category_t,
68 followed by a NULL terminated array
69 of objc_static_instances. */
72 /* The compiler generates one of these structures for each module that
73 composes the executable (eg main.m).
75 This data structure is the root of the definition tree for the
76 module.
78 A collect program runs between ld stages and creates a ObjC ctor
79 array. That array holds a pointer to each module structure of the
80 executable. */
81 struct objc_module
83 unsigned long version; /* Version of the Module data
84 structure. */
85 unsigned long size; /* sizeof(Module) according to the
86 compiler - only used to sanity check
87 that it matches sizeof(Module)
88 according to the runtime. */
89 const char* name; /* Name of the file used to compile the
90 module - not set by modern compilers
91 for security reasons. */
92 struct objc_symtab *symtab; /* Pointer to the Symtab of the module.
93 The Symtab holds an array of pointers
94 to the classes and categories defined
95 in the module. */
98 /* The compiler generates one of these structures for a class that has
99 instance variables defined in its specification. */
100 struct objc_ivar
102 const char* ivar_name; /* Name of the instance variable as entered
103 in the class definition. */
104 const char* ivar_type; /* Description of the Ivar's type. Useful
105 for debuggers. */
106 int ivar_offset; /* Byte offset from the base address of the
107 instance structure to the variable. */
110 struct objc_ivar_list
112 int ivar_count; /* Number of structures (Ivar)
113 contained in the list. One
114 structure per instance variable
115 defined in the class. */
116 struct objc_ivar ivar_list[1]; /* Variable length structure. */
119 /* The compiler generates one (or more) of these structures for a
120 class that has methods defined in its specification.
122 The implementation of a class can be broken into separate pieces in
123 a file and categories can break them across modules. To handle this
124 problem is a singly linked list of methods. */
125 struct objc_method
127 SEL method_name; /* This variable is the method's name.
128 The compiler puts a char* here, and
129 it's replaced by a real SEL at runtime
130 when the method is registered. */
131 const char* method_types; /* Description of the method's parameter
132 list. Used when registering the
133 selector with the runtime. When that
134 happens, method_name will contain the
135 method's parameter list. */
136 IMP method_imp; /* Address of the method in the
137 executable. */
140 struct objc_method_list
142 struct objc_method_list* method_next; /* This variable is used to
143 link a method list to
144 another. It is a singly
145 linked list. */
146 int method_count; /* Number of methods defined
147 in this structure. */
148 struct objc_method method_list[1]; /* Variable length
149 structure. */
152 /* Currently defined in Protocol.m (that definition should go away
153 once we include this file). Note that a 'struct
154 objc_method_description' as embedded inside a Protocol uses the
155 same trick as a 'struct objc_method': the method_name is a 'char *'
156 according to the compiler, who puts the method name as a string in
157 there. At runtime, the selectors need to be registered, and the
158 method_name then becomes a SEL. */
159 struct objc_method_description_list
161 int count;
162 struct objc_method_description list[1];
165 /* Currently defined by objc/objc.h. */
167 struct objc_protocol {
168 struct objc_class* class_pointer;
169 char *protocol_name;
170 struct objc_protocol_list *protocol_list;
171 struct objc_method_description_list *instance_methods, *class_methods;
175 struct objc_protocol_list
177 struct objc_protocol_list *next;
178 size_t count;
179 Protocol *list[1];
183 The compiler generates one of these structures for each class.
185 This structure is the definition for classes.
187 This structure is generated by the compiler in the executable and
188 used by the run-time during normal messaging operations. Therefore
189 some members change type. The compiler generates "char* const" and
190 places a string in the following member variables: super_class.
192 #ifndef __objc_STRUCT_OBJC_CLASS_defined
193 struct objc_class {
194 struct objc_class* class_pointer; /* Pointer to the class's meta
195 class. */
196 struct objc_class* super_class; /* Pointer to the super
197 class. NULL for class
198 Object. */
199 const char* name; /* Name of the class. */
200 long version; /* Unknown. */
201 unsigned long info; /* Bit mask. See class masks
202 defined below. */
203 long instance_size; /* Size in bytes of the class.
204 The sum of the class
205 definition and all super
206 class definitions. */
207 #ifdef _WIN64
208 /* We pad the structure manually to prevent warning when -Wpadded is
209 used. The compiler automatically pads the structures that it
210 generates, so this manually padded structure still matches the
211 one generated by the compiler, but if we don't pad manually,
212 -Wpadded detects that padding is being added and generates
213 annoying warnings. This hack is necessary as on LLP64 targets
214 sizeof (long) isn't equal to sizeof (void *). */
215 long pad;
216 #endif
217 struct objc_ivar_list* ivars; /* Pointer to a structure that
218 describes the instance
219 variables in the class
220 definition. NULL indicates
221 no instance variables.
222 Does not include super
223 class variables. */
224 struct objc_method_list* methods; /* Linked list of instance
225 methods defined for the
226 class. */
227 struct sarray * dtable; /* Pointer to instance method
228 dispatch table. */
229 struct objc_class* subclass_list; /* Subclasses */
230 struct objc_class* sibling_class;
232 struct objc_protocol_list *protocols; /* Protocols conformed to */
233 void* gc_object_type;
235 #endif /* __objc_STRUCT_OBJC_CLASS_defined */
237 /* This is used to assure consistent access to the info field of
238 classes. */
239 #ifndef HOST_BITS_PER_LONG
240 # define HOST_BITS_PER_LONG (sizeof(long)*8)
241 #endif
243 #define __CLS_INFO(cls) ((cls)->info)
244 #define __CLS_ISINFO(cls, mask) ((__CLS_INFO(cls)&mask)==mask)
245 #define __CLS_SETINFO(cls, mask) (__CLS_INFO(cls) |= mask)
246 #define __CLS_SETNOTINFO(cls, mask) (__CLS_INFO(cls) &= ~mask)
248 /* The structure is of type MetaClass */
249 #define _CLS_META 0x2L
250 #define CLS_ISMETA(cls) ((cls)&&__CLS_ISINFO(cls, _CLS_META))
252 /* The structure is of type Class */
253 #define _CLS_CLASS 0x1L
254 #define CLS_ISCLASS(cls) ((cls)&&__CLS_ISINFO(cls, _CLS_CLASS))
256 /* The class is initialized within the runtime. This means that it
257 has had correct super and sublinks assigned. */
258 #define _CLS_RESOLV 0x8L
259 #define CLS_ISRESOLV(cls) __CLS_ISINFO(cls, _CLS_RESOLV)
260 #define CLS_SETRESOLV(cls) __CLS_SETINFO(cls, _CLS_RESOLV)
262 /* The class has been send a +initialize message or a such is not
263 defined for this class. */
264 #define _CLS_INITIALIZED 0x04L
265 #define CLS_ISINITIALIZED(cls) __CLS_ISINFO(cls, _CLS_INITIALIZED)
266 #define CLS_SETINITIALIZED(cls) __CLS_SETINFO(cls, _CLS_INITIALIZED)
268 /* The class is being constructed; it has been allocated using
269 objc_allocateClassPair(), but has not been registered yet by using
270 objc_registerClassPair(). This means it is possible to freely add
271 instance variables to the class, but it can't be used for anything
272 yet. */
273 #define _CLS_IN_CONSTRUCTION 0x10L
274 #define CLS_IS_IN_CONSTRUCTION(cls) __CLS_ISINFO(cls, _CLS_IN_CONSTRUCTION)
275 #define CLS_SET_IN_CONSTRUCTION(cls) __CLS_SETINFO(cls, _CLS_IN_CONSTRUCTION)
276 #define CLS_SET_NOT_IN_CONSTRUCTION(cls) __CLS_SETNOTINFO(cls, _CLS_IN_CONSTRUCTION)
278 /* The class number of this class. This must be the same for both the
279 class and its meta class object. */
280 #define CLS_GETNUMBER(cls) (__CLS_INFO(cls) >> (HOST_BITS_PER_LONG/2))
281 #define CLS_SETNUMBER(cls, num) \
282 ({ (cls)->info <<= (HOST_BITS_PER_LONG/2); \
283 (cls)->info >>= (HOST_BITS_PER_LONG/2); \
284 __CLS_SETINFO(cls, (((unsigned long)num) << (HOST_BITS_PER_LONG/2))); })
287 /* The compiler generates one of these structures for each category.
288 A class may have many categories and contain both instance and
289 factory methods. */
290 struct objc_category
292 const char* category_name; /* Name of the category.
293 Name contained in the
294 () of the category
295 definition. */
296 const char* class_name; /* Name of the class to
297 which the category
298 belongs. */
299 struct objc_method_list *instance_methods; /* Linked list of
300 instance methods
301 defined in the
302 category. NULL
303 indicates no instance
304 methods defined. */
305 struct objc_method_list *class_methods; /* Linked list of
306 factory methods
307 defined in the
308 category. NULL
309 indicates no class
310 methods defined. */
311 struct objc_protocol_list *protocols; /* List of Protocols
312 conformed to. */
315 #endif /* __objc_private_module_abi_8_INCLUDE_GNU */