archive.c: Do not include objc/objc.h.
[official-gcc.git] / libobjc / objc / runtime.h
blob6efe78d6fce3db5b21b0d043df23b7c19109a4cb
1 /* GNU Objective-C Runtime API - Modern API
2 Copyright (C) 2010 Free Software Foundation, Inc.
3 Contributed by Nicola Pero <nicola.pero@meta-innovation.com>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3, or (at your option) any
10 later version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 License for more details.
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
26 #ifndef __objc_runtime_INCLUDE_GNU
27 #define __objc_runtime_INCLUDE_GNU
30 This file declares the "modern" GNU Objective-C Runtime API.
31 Include this file to use it.
33 This API is replacing the "traditional" GNU Objective-C Runtime API
34 (declared in objc/objc-api.h) which is the one supported by older
35 versions of the GNU Objective-C Runtime. The "modern" API is very
36 similar to the API used by the modern Apple/NeXT runtime.
38 Because the two APIs have some conflicting definitions (in
39 particular, Method and Category are defined differently) you should
40 include either objc/objc-api.h (to use the traditional GNU
41 Objective-C Runtime API) or objc/runtime.h (to use the modern GNU
42 Objective-C Runtime API), but not both.
44 #ifdef __objc_api_INCLUDE_GNU
45 # error You can not include both objc/objc-api.h and objc/runtime.h. Include objc/objc-api.h for the traditional GNU Objective-C Runtime API and objc/runtime.h for the modern one.
46 #endif
48 /* TODO: This file is incomplete. */
50 #include "objc.h"
51 #include "objc-decls.h"
53 /* An 'Ivar' represents an instance variable. It holds information
54 about the name, type and offset of the instance variable. */
55 typedef struct objc_ivar *Ivar;
57 /* A 'Property' represents a property. It holds information about the
58 name of the property, and its attributes.
60 Compatibility Note: the Apple/NeXT runtime defines this as
61 objc_property_t, so we define it that way as well, but obviously
62 Property is the right name. */
63 typedef struct objc_property *Property;
64 typedef struct objc_property *objc_property_t;
66 /* A 'Method' represents a method. It holds information about the
67 name, types and the IMP of the method. */
68 typedef struct objc_method *Method;
70 /* A 'Category' represents a category. It holds information about the
71 name of the category, the class it belongs to, and the methods,
72 protocols and such like provided by the category. */
73 typedef struct objc_category *Category;
75 /* 'Protocol' is defined in objc/objc.h (which is included by this
76 file). */
78 /* Method descriptor returned by introspective Object methods. At the
79 moment, this is really just the first part of the more complete
80 objc_method structure used internally by the runtime. (PS: In the
81 GNU Objective-C Runtime, selectors already include a type, so an
82 objc_method_description does not add much to a SEL. But in other
83 runtimes, that is not the case, which is why
84 objc_method_description exists). */
85 struct objc_method_description
87 SEL name; /* Selector (name and signature) */
88 char *types; /* Type encoding */
91 /* The following are used in encode strings to describe the type of
92 Ivars and Methods. */
93 #define _C_ID '@'
94 #define _C_CLASS '#'
95 #define _C_SEL ':'
96 #define _C_CHR 'c'
97 #define _C_UCHR 'C'
98 #define _C_SHT 's'
99 #define _C_USHT 'S'
100 #define _C_INT 'i'
101 #define _C_UINT 'I'
102 #define _C_LNG 'l'
103 #define _C_ULNG 'L'
104 #define _C_LNG_LNG 'q'
105 #define _C_ULNG_LNG 'Q'
106 #define _C_FLT 'f'
107 #define _C_DBL 'd'
108 #define _C_LNG_DBL 'D'
109 #define _C_BFLD 'b'
110 #define _C_BOOL 'B'
111 #define _C_VOID 'v'
112 #define _C_UNDEF '?'
113 #define _C_PTR '^'
114 #define _C_CHARPTR '*'
115 #define _C_ARY_B '['
116 #define _C_ARY_E ']'
117 #define _C_UNION_B '('
118 #define _C_UNION_E ')'
119 #define _C_STRUCT_B '{'
120 #define _C_STRUCT_E '}'
121 #define _C_VECTOR '!'
122 #define _C_COMPLEX 'j'
124 /* _C_ATOM is never generated by the compiler. You can treat it as
125 equivalent to "*". */
126 #define _C_ATOM '%'
128 /* The following are used in encode strings to describe some
129 qualifiers of method and ivar types. */
130 #define _C_CONST 'r'
131 #define _C_IN 'n'
132 #define _C_INOUT 'N'
133 #define _C_OUT 'o'
134 #define _C_BYCOPY 'O'
135 #define _C_BYREF 'R'
136 #define _C_ONEWAY 'V'
137 #define _C_GCINVISIBLE '|'
139 /* The same when used as flags. */
140 #define _F_CONST 0x01
141 #define _F_IN 0x01
142 #define _F_OUT 0x02
143 #define _F_INOUT 0x03
144 #define _F_BYCOPY 0x04
145 #define _F_BYREF 0x08
146 #define _F_ONEWAY 0x10
147 #define _F_GCINVISIBLE 0x20
150 /** Implementation: the following functions are defined inline. */
152 /* Return the class of 'object', or Nil if the object is nil. If
153 'object' is a class, the meta class is returned; if 'object' is a
154 meta class, the root meta class is returned (note that this is
155 different from the traditional GNU Objective-C Runtime API function
156 object_get_class(), which for a meta class would return the meta
157 class itself). This function is inline, so it is really fast and
158 should be used instead of accessing object->class_pointer
159 directly. */
160 static inline Class
161 object_getClass (id object)
163 if (object != nil)
164 return object->class_pointer;
165 else
166 return Nil;
170 /** Implementation: the following functions are in selector.c. */
172 /* Return the name of a given selector. If 'selector' is NULL, return
173 "<null selector>". */
174 objc_EXPORT const char *sel_getName (SEL selector);
176 /* Return the type of a given selector.
178 Compatibility Note: the Apple/NeXT runtime has untyped selectors,
179 so it does not have this function, which is specific to the GNU
180 Runtime. */
181 objc_EXPORT const char *sel_getType (SEL selector);
183 /* This is the same as sel_registerName (). Please use
184 sel_registerName () instead. */
185 objc_EXPORT SEL sel_getUid (const char *name);
187 /* Register a selector with a given name (but unspecified types). If
188 you know the types, it is better to call sel_registerTypedName().
189 If a selector with this name already exists, it is returned. */
190 objc_EXPORT SEL sel_registerName (const char *name);
192 /* Register a selector with a given name and types. If a selector
193 with this name and types already exists, it is returned.
195 Compatibility Note: the Apple/NeXT runtime has untyped selectors,
196 so it does not have this function, which is specific to the GNU
197 Runtime. */
198 objc_EXPORT SEL set_registerTypedName (const char *name, const char *type);
200 /* Return YES if first_selector is the same as second_selector, and NO
201 if not. */
202 objc_EXPORT BOOL sel_isEqual (SEL first_selector, SEL second_selector);
205 /** Implementation: the following functions are in objects.c. */
207 /* Create an instance of class 'class_', adding extraBytes to the size
208 of the returned object. This method allocates the appropriate
209 amount of memory for the instance, initializes it to zero, then
210 calls all the C++ constructors on appropriate C++ instance
211 variables of the instance (if any) (TODO: The C++ constructors bit
212 is not implemented yet). */
213 objc_EXPORT id class_createInstance (Class class_, size_t extraBytes);
215 /* Copy an object and return the copy. extraBytes should be identical
216 to the extraBytes parameter that was passed when creating the
217 original object. */
218 objc_EXPORT id object_copy (id object, size_t extraBytes);
220 /* Dispose of an object. This method calls the appropriate C++
221 destructors on appropriate C++ instance variables of the instance
222 (if any) (TODO: This is not implemented yet), then frees the memory
223 for the instance. */
224 objc_EXPORT id object_dispose (id object);
226 /* Return the name of the class of 'object'. If 'object' is 'nil',
227 returns "Nil". */
228 objc_EXPORT const char * object_getClassName (id object);
230 /* Change the class of object to be class_. Return the previous class
231 of object. This is currently not really thread-safe. */
232 objc_EXPORT Class object_setClass (id object, Class class_);
235 /** Implementation: the following functions are in ivars.c. */
237 /* Return an instance variable given the class and the instance
238 variable name. This is an expensive function to call, so try to
239 reuse the returned Ivar if you can. */
240 objc_EXPORT Ivar class_getInstanceVariable (Class class_, const char *name);
242 /* If the object was created in class_createInstance() with some
243 extraBytes, returns a pointer to them. If it was not, then the
244 returned pointer may make no sense. */
245 objc_EXPORT void * object_getIndexedIvars (id object);
247 /* Get the value of an instance variable of type 'id'. The function
248 returns the instance variable. To get the value of the instance
249 variable, you should pass as 'returnValue' a pointer to an 'id';
250 the value will be copied there. Note that 'returnValue' is really
251 a 'void *', not a 'void **'. This function really works only with
252 instance variables of type 'id'; for other types of instance
253 variables, access directly the data at (char *)object +
254 ivar_getOffset (ivar). */
255 objc_EXPORT Ivar object_getInstanceVariable (id object, const char *name, void **returnValue);
257 /* Set the value of an instance variable. The value to set is passed
258 in 'newValue' (which really is an 'id', not a 'void *'). The
259 function returns the instance variable. This function really works
260 only with instance variables of type 'id'; for other types of
261 instance variables, access directly the data at (char *)object +
262 ivar_getOffset (ivar). */
263 objc_EXPORT Ivar object_setInstanceVariable (id object, const char *name, void *newValue);
265 /* Get the value of an instance variable of type 'id' of the object
266 'object'. This is faster than object_getInstanceVariable if you
267 already have the instance variable because it avoids the expensive
268 call to class_getInstanceVariable that is done by
269 object_getInstanceVariable. */
270 objc_EXPORT id object_getIvar (id object, Ivar variable);
272 /* Set the value of an instance variable of type 'id' of the object
273 'object'. This is faster than object_setInstanceVariable if you
274 already have the instance variable because it avoids the expensive
275 call to class_getInstanceVariable that is done by
276 object_setInstanceVariable. */
277 objc_EXPORT void object_setIvar (id object, Ivar variable, id value);
279 /* Return the name of the instance variable. */
280 objc_EXPORT const char * ivar_getName (Ivar variable);
282 /* Return the offset of the instance variable from the start of the
283 object data. */
284 objc_EXPORT ptrdiff_t ivar_getOffset (Ivar variable);
286 /* Return the type encoding of the variable. */
287 objc_EXPORT const char * ivar_getTypeEncoding (Ivar variable);
290 /** Implementation: the following functions are in class.c. */
292 /* Compatibility Note: The Apple/NeXT runtime does not have
293 objc_get_unknown_class_handler and
294 objc_setGetUnknownClassHandler(). They provide functionality that
295 the traditional GNU Objective-C Runtime API used to provide via the
296 _objc_lookup_class hook. */
298 /* An 'objc_get_unknown_class_handler' function is used by
299 objc_getClass() to get a class that is currently unknown to the
300 compiler. You could use it for example to have the class loaded by
301 dynamically loading a library. 'class_name' is the name of the
302 class. The function should return the Class object if it manages to
303 load the class, and Nil if not. */
304 typedef Class (*objc_get_unknown_class_handler)(const char *class_name);
306 /* Sets a new handler function for getting unknown classes (to be used
307 by objc_getClass () and related), and returns the previous one.
308 This function is not safe to call in a multi-threaded environment
309 because other threads may be trying to use the get unknown class
310 handler while you change it! */
311 objc_get_unknown_class_handler
312 objc_setGetUnknownClassHandler (objc_get_unknown_class_handler new_handler);
315 /* Return the class with name 'name', if it is already registered with
316 the runtime. If it is not registered, and
317 objc_setGetUnknownClassHandler() has been called to set a handler
318 for unknown classes, the handler is called to give it a chance to
319 load the class in some other way. If the class is not known to the
320 runtime and the handler is not set or returns Nil, objc_getClass()
321 returns Nil. */
322 objc_EXPORT Class objc_getClass (const char *name);
324 /* Return the class with name 'name', if it is already registered with
325 the runtime. Return Nil if not. This function does not call the
326 objc_get_unknown_class_handler function if the class is not
327 found. */
328 objc_EXPORT Class objc_lookupClass (const char *name);
330 /* Return the meta class associated to the class with name 'name', if
331 it is already registered with the runtime. First, it finds the
332 class using objc_getClass(). Then, it returns the associated meta
333 class. If the class could not be found using objc_getClass(),
334 returns Nil. */
335 objc_EXPORT Class objc_getMetaClass (const char *name);
337 /* This is identical to objc_getClass(), but if the class is not found,
338 it aborts the process instead of returning Nil. */
339 objc_EXPORT Class objc_getRequiredClass (const char *name);
341 /* If 'returnValue' is NULL, 'objc_getClassList' returns the number of
342 classes currently registered with the runtime. If 'returnValue' is
343 not NULL, it should be a (Class *) pointer to an area of memory
344 which can contain up to 'maxNumberOfClassesToReturn' Class records.
345 'objc_getClassList' will fill the area pointed to by 'returnValue'
346 with all the Classes registered with the runtime (or up to
347 maxNumberOfClassesToReturn if there are more than
348 maxNumberOfClassesToReturn). The function return value is the
349 number of classes actually returned in 'returnValue'. */
350 objc_EXPORT int objc_getClassList (Class *returnValue, int maxNumberOfClassesToReturn);
352 /* Compatibility Note: The Apple/NeXT runtime also has
354 Class objc_getFutureClass (const char *name);
355 void objc_setFutureClass (Class class_, const char *name);
357 the documentation is unclear on what they are supposed to do, and
358 the GNU Objective-C Runtime currently does not provide them. */
360 /* Return the name of the class 'class_', or the string "nil" if the
361 class_ is Nil. */
362 objc_EXPORT const char * class_getName (Class class_);
365 /** Implementation: the following functions are in protocols.c. */
367 /* Return the protocol with name 'name', or nil if it the protocol is
368 not known to the runtime. */
369 objc_EXPORT Protocol *objc_getProtocol (const char *name);
371 /* Return all the protocols known to the runtime. The return value of
372 the function is a pointer to an area, allocated with malloc(), that
373 contains all the protocols known to the runtime; the list is
374 terminated by NULL. You should free this area using free() once
375 you no longer need it. Optionally, if you pass a non-NULL
376 'numberOfReturnedProtocols' pointer, the unsigned int that it
377 points to will be filled with the number of protocols returned. If
378 there are no protocols known to the runtime, NULL is returned. */
379 objc_EXPORT Protocol **objc_copyProtocolList (unsigned int *numberOfReturnedProtocols);
381 /* Add a protocol to a class, and return YES if it was done
382 succesfully, and NO if not. At the moment, NO should only happen
383 if class_ or protocol are nil, if the protocol is not a Protocol
384 object or if the class already conforms to the protocol. */
385 objc_EXPORT BOOL class_addProtocol (Class class_, Protocol *protocol);
387 /* Return YES if the class 'class_' conforms to Protocol 'protocol',
388 and NO if not. */
389 objc_EXPORT BOOL class_conformsToProtocol (Class class_, Protocol *protocol);
391 /* Return all the protocols that the class conforms to. The return
392 value of the function is a pointer to an area, allocated with
393 malloc(), that contains all the protocols formally adopted by the
394 class. It does not include protocols adopted by superclasses. The
395 list is terminated by NULL. Optionally, if you pass a non-NULL
396 'numberOfReturnedProtocols' pointer, the unsigned int that it
397 points to will be filled with the number of protocols returned. */
398 objc_EXPORT Protocol **class_copyProtocolList (Class class_, unsigned int *numberOfReturnedProtocols);
400 /* Return YES if protocol 'protocol' conforms to protocol
401 'anotherProtocol', and NO if not. Note that if one of the two
402 protocols is nil, it returns NO. */
403 objc_EXPORT BOOL protocol_conformsToProtocol (Protocol *protocol, Protocol *anotherProtocol);
405 /* Return YES if protocol 'protocol' is the same as protocol
406 'anotherProtocol', and 'NO' if not. Note that it returns YES if
407 the two protocols are both nil. */
408 objc_EXPORT BOOL protocol_isEqual (Protocol *protocol, Protocol *anotherProtocol);
410 /* Return the name of protocol 'protocol'. If 'protocol' is nil or is
411 not a Protocol, return NULL. */
412 objc_EXPORT const char *protocol_getName (Protocol *protocol);
414 /* Return the method description for the method with selector
415 'selector' in protocol 'protocol'; if 'requiredMethod' is YES, the
416 function searches the list of required methods; if NO, the list of
417 optional methods. If 'instanceMethod' is YES, the function search
418 for an instance method; if NO, for a class method. If there is no
419 matching method, an objc_method_description structure with both
420 name and types set to NULL is returned. This function will only
421 find methods that are directly declared in the protocol itself, not
422 in other protocols that this protocol adopts.
424 Note that the traditional ABI does not store the list of optional
425 methods of a protocol in a compiled module, so the traditional ABI
426 will always return (NULL, NULL) when requiredMethod == NO. */
427 objc_EXPORT struct objc_method_description protocol_getMethodDescription (Protocol *protocol,
428 SEL selector,
429 BOOL requiredMethod,
430 BOOL instanceMethod);
432 /* Return the method descriptions of all the methods of the protocol.
433 The return value of the function is a pointer to an area, allocated
434 with malloc(), that contains all the method descriptions of the
435 methods of the protocol. It does not recursively include methods
436 of the protocols adopted by this protocol. The list is terminated
437 by a NULL objc_method_description (one with both fields set to
438 NULL). Optionally, if you pass a non-NULL
439 'numberOfReturnedMethods' pointer, the unsigned int that it points
440 to will be filled with the number of properties returned.
442 Note that the traditional ABI does not store the list of optional
443 methods of a protocol in a compiled module, so the traditional ABI
444 will always return an empty list if requiredMethod is set to
445 NO. */
446 objc_EXPORT struct objc_method_description *protocol_copyMethodDescriptionList (Protocol *protocol,
447 BOOL requiredMethod,
448 BOOL instanceMethod,
449 unsigned int *numberOfReturnedMethods);
451 /* Return the property with name 'propertyName' of the protocol
452 'protocol'. If 'requiredProperty' is YES, the function searches
453 the list of required properties; if NO, the list of optional
454 properties. If 'instanceProperty' is YES, the function searches
455 the list of instance properties; if NO, the list of class
456 properties. At the moment, optional properties and class
457 properties are not part of the Objective-C language, so both
458 'requiredProperty' and 'instanceProperty' should be set to YES.
459 This function returns NULL if the required property can not be
460 found.
462 Note that the traditional ABI does not store the list of properties
463 of a protocol in a compiled module, so the traditional ABI will
464 always return NULL. */
465 objc_EXPORT Property protocol_getProperty (Protocol *protocol, const char *propertyName,
466 BOOL requiredProperty, BOOL instanceProperty);
468 /* Return all the properties of the protocol. The return value of the
469 function is a pointer to an area, allocated with malloc(), that
470 contains all the properties of the protocol. It does not
471 recursively include properties of the protocols adopted by this
472 protocol. The list is terminated by NULL. Optionally, if you pass
473 a non-NULL 'numberOfReturnedProperties' pointer, the unsigned int
474 that it points to will be filled with the number of properties
475 returned.
477 Note that the traditional ABI does not store the list of properties
478 of a protocol in a compiled module, so the traditional ABI will
479 always return NULL and store 0 in numberOfReturnedProperties. */
480 objc_EXPORT Property *protocol_copyPropertyList (Protocol *protocol, unsigned int *numberOfReturnedProperties);
482 /* Return all the protocols that the protocol conforms to. The return
483 value of the function is a pointer to an area, allocated with
484 malloc(), that contains all the protocols formally adopted by the
485 protocol. It does not recursively include protocols adopted by the
486 protocols adopted by this protocol. The list is terminated by
487 NULL. Optionally, if you pass a non-NULL
488 'numberOfReturnedProtocols' pointer, the unsigned int that it
489 points to will be filled with the number of protocols returned. */
490 objc_EXPORT Protocol **protocol_copyProtocolList (Protocol *protocol, unsigned int *numberOfReturnedProtocols);
493 /* TODO: Add all the other functions in the API. */
496 /** Implementation: the following functions are in objc-foreach.c. */
498 /* 'objc_enumerationMutation()' is called when a collection is
499 mutated while being "fast enumerated". That is a hard error, and
500 objc_enumerationMutation is called to deal with it. 'collection'
501 is the collection object that was mutated during an enumeration.
503 objc_enumerationMutation() will invoke the mutation handler if any
504 is set. Then, it will abort the program.
506 Compatibility note: the Apple runtime will not abort the program
507 after calling the mutation handler. */
508 objc_EXPORT void objc_enumerationMutation (id collection);
510 /* 'objc_set_enumeration_mutation_handler' can be used to set a
511 function that will be called (instead of aborting) when a fast
512 enumeration is mutated during enumeration. The handler will be
513 called with the 'collection' being mutated as the only argument and
514 it should not return; it should either exit the program, or could
515 throw an exception. The recommended implementation is to throw an
516 exception - the user can then use exception handlers to deal with
519 This function is not thread safe (other threads may be trying to
520 invoke the enumeration mutation handler while you are changing it!)
521 and should be called during during the program initialization
522 before threads are started. It is mostly reserved for "Foundation"
523 libraries; in the case of GNUstep, GNUstep Base may be using this
524 function to improve the standard enumeration mutation handling.
525 You probably shouldn't use this function unless you are writing
526 your own Foundation library. */
527 objc_EXPORT void objc_setEnumerationMutationHandler (void (*handler)(id));
529 /* This structure (used during fast enumeration) is automatically
530 defined by the compiler (it is as if this definition was always
531 included in all Objective-C files). Note that it is usually
532 defined again with the name of NSFastEnumeration by "Foundation"
533 libraries such as GNUstep Base. And if NSFastEnumeration is
534 defined, the compiler will use it instead of
535 __objcFastEnumerationState when doing fast enumeration. */
537 struct __objcFastEnumerationState
539 unsigned long state;
540 id *itemsPtr;
541 unsigned long *mutationsPtr;
542 unsigned long extra[5];
547 /** Implementation: the following functions are in memory.c. */
549 /* Traditional GNU Objective-C Runtime functions that are used for
550 memory allocation and disposal. These functions are used in the
551 same way as you use malloc, realloc, calloc and free and make sure
552 that memory allocation works properly with the garbage
553 collector.
555 Compatibility Note: these functions are not available with the
556 Apple/NeXT runtime. */
558 objc_EXPORT void *objc_malloc(size_t size);
560 /* FIXME: Shouldn't the following be called objc_malloc_atomic ? The
561 GC function is GC_malloc_atomic() which makes sense.
563 objc_EXPORT void *objc_atomic_malloc(size_t size);
565 objc_EXPORT void *objc_realloc(void *mem, size_t size);
567 objc_EXPORT void *objc_calloc(size_t nelem, size_t size);
569 objc_EXPORT void objc_free(void *mem);
572 /** Implementation: the following functions are in encoding.c. */
574 /* Traditional GNU Objective-C Runtime functions that are currently
575 used to implement method forwarding.
577 Compatibility Note: these functions are not available with the
578 Apple/NeXT runtime. */
580 /* Return the size of a variable which has the specified 'type'
581 encoding. */
582 int objc_sizeof_type (const char *type);
584 /* Return the align of a variable which has the specified 'type'
585 encoding. */
586 int objc_alignof_type (const char *type);
588 /* Return the aligned size of a variable which has the specified
589 'type' encoding. The aligned size is the size rounded up to the
590 nearest alignment. */
591 int objc_aligned_size (const char *type);
593 /* Return the promoted size of a variable which has the specified
594 'type' encoding. This is the size rounded up to the nearest
595 integral of the wordsize, taken to be the size of a void *. */
596 int objc_promoted_size (const char *type);
599 /* The following functions are used when parsing the type encoding of
600 methods, to skip over parts that are ignored. They take as
601 argument a pointer to a location inside the type encoding of a
602 method (which is a string) and return a new pointer, pointing to a
603 new location inside the string after having skipped the unwanted
604 information. */
606 /* Skip some type qualifiers (_C_CONST, _C_IN, etc). These may
607 eventually precede typespecs occurring in method prototype
608 encodings. */
609 const char *objc_skip_type_qualifiers (const char *type);
611 /* Skip one typespec element (_C_CLASS, _C_SEL, etc). If the typespec
612 is prepended by type qualifiers, these are skipped as well. */
613 const char *objc_skip_typespec (const char *type);
615 /* Skip an offset. */
616 const char *objc_skip_offset (const char *type);
618 /* Skip an argument specification (ie, skipping a typespec, which may
619 include qualifiers, and an offset too). */
620 const char *objc_skip_argspec (const char *type);
622 /* Read type qualifiers (_C_CONST, _C_IN, etc) from string 'type'
623 (stopping at the first non-type qualifier found) and return an
624 unsigned int which is the logical OR of all the corresponding flags
625 (_F_CONST, _F_IN etc). */
626 unsigned objc_get_type_qualifiers (const char *type);
629 /* Note that the following functions work for very simple structures,
630 but get easily confused by more complicated ones (for example,
631 containing vectors). A better solution is required.
634 /* The following three functions can be used to determine how a
635 structure is laid out by the compiler. For example:
637 struct objc_struct_layout layout;
638 int i;
640 objc_layout_structure (type, &layout);
641 while (objc_layout_structure_next_member (&layout))
643 int position, align;
644 const char *type;
646 objc_layout_structure_get_info (&layout, &position, &align, &type);
647 printf ("element %d has offset %d, alignment %d\n",
648 i++, position, align);
651 These functions are used by objc_sizeof_type and objc_alignof_type
652 functions to compute the size and alignment of structures. The
653 previous method of computing the size and alignment of a structure
654 was not working on some architectures, particulary on AIX, and in
655 the presence of bitfields inside the structure. */
656 struct objc_struct_layout
658 const char *original_type;
659 const char *type;
660 const char *prev_type;
661 unsigned int record_size;
662 unsigned int record_align;
665 void objc_layout_structure (const char *type,
666 struct objc_struct_layout *layout);
667 BOOL objc_layout_structure_next_member (struct objc_struct_layout *layout);
668 void objc_layout_finish_structure (struct objc_struct_layout *layout,
669 unsigned int *size,
670 unsigned int *align);
671 void objc_layout_structure_get_info (struct objc_struct_layout *layout,
672 unsigned int *offset,
673 unsigned int *align,
674 const char **type);
676 #endif