OSDN Git Service

revert unintended change to gcc-def.exp.
[pf3gnuchains/gcc-fork.git] / libobjc / objc-private / module-abi-8.h
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.
4
5 This file is part of GCC.
6
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.
10
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.
15
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.
19
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/>.  */
24
25 #ifndef __objc_private_module_abi_8_INCLUDE_GNU
26 #define __objc_private_module_abi_8_INCLUDE_GNU
27
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
33 {
34   char *class_name;
35 #ifdef __cplusplus
36   id instances[1];
37 #else
38   id instances[0];
39 #endif
40 };
41
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.  
45    
46    A Symtab contains a variable length array of pointers to classes and
47    categories  defined in the module.   */
48 struct objc_symtab
49 {
50   unsigned long sel_ref_cnt;  /* Unknown. */
51   SEL        refs;            /* Unknown. */
52   unsigned short cls_def_cnt; /* Number of classes compiled (defined)
53                                  in the module. */
54   unsigned short cat_def_cnt; /* Number of categories compiled
55                                  (defined) in the module. */
56   void      *defs[1];         /* Variable array of pointers.
57                                  cls_def_cnt of type Class followed by
58                                  cat_def_cnt of type Category_t,
59                                  followed by a NULL terminated array
60                                  of objc_static_instances. */
61 };
62
63 /* The compiler generates one of these structures for each module that
64    composes the executable (eg main.m).
65  
66    This data structure is the root of the definition tree for the
67    module.
68  
69    A collect program runs between ld stages and creates a ObjC ctor
70    array.  That array holds a pointer to each module structure of the
71    executable.  */
72 struct objc_module
73 {
74   unsigned long version;      /* Version of the Module data
75                                  structure.  */
76   unsigned long size;         /* sizeof(Module) according to the
77                                  compiler - only used to sanity check
78                                  that it matches sizeof(Module)
79                                  according to the runtime.  */
80   const char* name;           /* Name of the file used to compile the
81                                  module - not set by modern compilers
82                                  for security reasons.  */
83   struct objc_symtab *symtab; /* Pointer to the Symtab of the module.
84                                  The Symtab holds an array of pointers
85                                  to the classes and categories defined
86                                  in the module. */
87 };
88
89 /* The compiler generates one of these structures for a class that has
90    instance variables defined in its specification.  */
91 struct objc_ivar
92 {
93   const char* ivar_name;  /* Name of the instance variable as entered
94                              in the class definition. */
95   const char* ivar_type;  /* Description of the Ivar's type.  Useful
96                              for debuggers. */
97   int        ivar_offset; /* Byte offset from the base address of the
98                              instance structure to the variable. */
99 };
100
101 struct objc_ivar_list
102 {
103   int   ivar_count;              /* Number of structures (Ivar)
104                                     contained in the list.  One
105                                     structure per instance variable
106                                     defined in the class. */
107   struct objc_ivar ivar_list[1]; /* Variable length structure. */
108 };
109
110 /* The compiler generates one (or more) of these structures for a
111    class that has methods defined in its specification.
112  
113    The implementation of a class can be broken into separate pieces in
114    a file and categories can break them across modules. To handle this
115    problem is a singly linked list of methods.  */
116 struct objc_method
117 {
118   SEL         method_name;  /* This variable is the method's name.
119                                The compiler puts a char* here, and
120                                it's replaced by a real SEL at runtime
121                                when the method is registered.  */
122   const char* method_types; /* Description of the method's parameter
123                                list.  Used when registering the
124                                selector with the runtime.  When that
125                                happens, method_name will contain the
126                                method's parameter list.  */
127   IMP         method_imp;   /* Address of the method in the
128                                executable. */
129 };
130
131 struct objc_method_list
132 {
133   struct objc_method_list*  method_next; /* This variable is used to
134                                             link a method list to
135                                             another.  It is a singly
136                                             linked list. */
137   int            method_count;            /* Number of methods defined
138                                              in this structure. */
139   struct objc_method method_list[1];      /* Variable length
140                                              structure. */
141 };
142
143 /* Currently defined in Protocol.m (that definition should go away
144    once we include this file).  Note that a 'struct
145    objc_method_description' as embedded inside a Protocol uses the
146    same trick as a 'struct objc_method': the method_name is a 'char *'
147    according to the compiler, who puts the method name as a string in
148    there.  At runtime, the selectors need to be registered, and the
149    method_name then becomes a SEL.  */
150 struct objc_method_description_list
151 {
152   int count;
153   struct objc_method_description list[1];
154 };
155
156 /* Currently defined by objc/objc.h.  */
157 /*
158 struct objc_protocol {
159   struct objc_class* class_pointer;
160   char *protocol_name;
161   struct objc_protocol_list *protocol_list;
162   struct objc_method_description_list *instance_methods, *class_methods; 
163 };
164 */
165
166 struct objc_protocol_list
167 {
168   struct objc_protocol_list *next;
169   size_t count;
170   Protocol *list[1];
171 };
172
173 /*
174   The compiler generates one of these structures for each class.  
175
176   This structure is the definition for classes.
177
178   This structure is generated by the compiler in the executable and
179   used by the run-time during normal messaging operations.  Therefore
180   some members change type. The compiler generates "char* const" and
181   places a string in the following member variables: super_class.
182 */
183 #ifndef __objc_STRUCT_OBJC_CLASS_defined
184 struct objc_class {
185   struct objc_class*  class_pointer;    /* Pointer to the class's meta
186                                            class. */
187   struct objc_class*  super_class;      /* Pointer to the super
188                                            class. NULL for class
189                                            Object. */
190   const char*         name;             /* Name of the class. */
191   long                version;          /* Unknown. */
192   unsigned long       info;             /* Bit mask.  See class masks
193                                            defined below. */
194   long                instance_size;    /* Size in bytes of the class.
195                                            The sum of the class
196                                            definition and all super
197                                            class definitions. */
198 #ifdef _WIN64
199   /* We pad the structure manually to prevent warning when -Wpadded is
200      used.  The compiler automatically pads the structures that it
201      generates, so this manually padded structure still matches the
202      one generated by the compiler, but if we don't pad manually,
203      -Wpadded detects that padding is being added and generates
204      annoying warnings.  This hack is necessary as on LLP64 targets
205      sizeof (long) isn't equal to sizeof (void *).  */
206   long pad;
207 #endif
208   struct objc_ivar_list* ivars;         /* Pointer to a structure that
209                                            describes the instance
210                                            variables in the class
211                                            definition.  NULL indicates
212                                            no instance variables.
213                                            Does not include super
214                                            class variables. */
215   struct objc_method_list*  methods;    /* Linked list of instance
216                                            methods defined for the
217                                            class. */
218   struct sarray *    dtable;            /* Pointer to instance method
219                                            dispatch table. */  
220   struct objc_class* subclass_list;     /* Subclasses */
221   struct objc_class* sibling_class;
222
223   struct objc_protocol_list *protocols; /* Protocols conformed to */
224   void* gc_object_type;
225 };
226 #endif /* __objc_STRUCT_OBJC_CLASS_defined */
227
228 /* This is used to assure consistent access to the info field of 
229    classes.  */
230 #ifndef HOST_BITS_PER_LONG
231 # define HOST_BITS_PER_LONG  (sizeof(long)*8)
232 #endif 
233
234 #define __CLS_INFO(cls) ((cls)->info)
235 #define __CLS_ISINFO(cls, mask) ((__CLS_INFO(cls)&mask)==mask)
236 #define __CLS_SETINFO(cls, mask) (__CLS_INFO(cls) |= mask)
237 #define __CLS_SETNOTINFO(cls, mask) (__CLS_INFO(cls) &= ~mask)
238
239 /* The structure is of type MetaClass */
240 #define _CLS_META 0x2L
241 #define CLS_ISMETA(cls) ((cls)&&__CLS_ISINFO(cls, _CLS_META))
242
243 /* The structure is of type Class */
244 #define _CLS_CLASS 0x1L
245 #define CLS_ISCLASS(cls) ((cls)&&__CLS_ISINFO(cls, _CLS_CLASS))
246
247 /* The class is initialized within the runtime.  This means that it
248    has had correct super and sublinks assigned.  */
249 #define _CLS_RESOLV 0x8L
250 #define CLS_ISRESOLV(cls) __CLS_ISINFO(cls, _CLS_RESOLV)
251 #define CLS_SETRESOLV(cls) __CLS_SETINFO(cls, _CLS_RESOLV)
252
253 /* The class has been send a +initialize message or a such is not 
254    defined for this class.  */
255 #define _CLS_INITIALIZED 0x04L
256 #define CLS_ISINITIALIZED(cls) __CLS_ISINFO(cls, _CLS_INITIALIZED)
257 #define CLS_SETINITIALIZED(cls) __CLS_SETINFO(cls, _CLS_INITIALIZED)
258
259 /* The class is being constructed; it has been allocated using
260    objc_allocateClassPair(), but has not been registered yet by using
261    objc_registerClassPair().  This means it is possible to freely add
262    instance variables to the class, but it can't be used for anything
263    yet.  */
264 #define _CLS_IN_CONSTRUCTION 0x10L
265 #define CLS_IS_IN_CONSTRUCTION(cls) __CLS_ISINFO(cls, _CLS_IN_CONSTRUCTION)
266 #define CLS_SET_IN_CONSTRUCTION(cls) __CLS_SETINFO(cls, _CLS_IN_CONSTRUCTION)
267 #define CLS_SET_NOT_IN_CONSTRUCTION(cls) __CLS_SETNOTINFO(cls, _CLS_IN_CONSTRUCTION)
268
269 /* The class number of this class.  This must be the same for both the
270    class and its meta class object.  */
271 #define CLS_GETNUMBER(cls) (__CLS_INFO(cls) >> (HOST_BITS_PER_LONG/2))
272 #define CLS_SETNUMBER(cls, num) \
273   ({ (cls)->info <<= (HOST_BITS_PER_LONG/2); \
274      (cls)->info >>= (HOST_BITS_PER_LONG/2); \
275      __CLS_SETINFO(cls, (((unsigned long)num) << (HOST_BITS_PER_LONG/2))); })
276
277
278 /* The compiler generates one of these structures for each category.
279    A class may have many categories and contain both instance and
280    factory methods.  */
281 struct objc_category
282 {
283   const char*   category_name;                /* Name of the category.
284                                                  Name contained in the
285                                                  () of the category
286                                                  definition.  */
287   const char*   class_name;                   /* Name of the class to
288                                                  which the category
289                                                  belongs.  */
290   struct objc_method_list  *instance_methods; /* Linked list of
291                                                  instance methods
292                                                  defined in the
293                                                  category. NULL
294                                                  indicates no instance
295                                                  methods defined.  */
296   struct objc_method_list *class_methods;     /* Linked list of
297                                                  factory methods
298                                                  defined in the
299                                                  category.  NULL
300                                                  indicates no class
301                                                  methods defined.  */
302   struct objc_protocol_list *protocols;       /* List of Protocols
303                                                  conformed to.  */
304 };
305
306 #endif /* __objc_private_module_abi_8_INCLUDE_GNU */