]>
Commit | Line | Data |
---|---|---|
8a7d0ecc | 1 | /* Basic data types for Objective C. |
344bfd09 | 2 | Copyright (C) 1993, 1995, 1996, 2004, 2009, |
71e45bc2 | 3 | 2010, 2011 Free Software Foundation, Inc. |
8a7d0ecc | 4 | |
893d9197 | 5 | This file is part of GCC. |
8a7d0ecc | 6 | |
893d9197 | 7 | GCC is free software; you can redistribute it and/or modify |
8a7d0ecc | 8 | it under the terms of the GNU General Public License as published by |
6bc9506f | 9 | the Free Software Foundation; either version 3, or (at your option) |
8a7d0ecc | 10 | any later version. |
11 | ||
893d9197 | 12 | GCC is distributed in the hope that it will be useful, |
8a7d0ecc | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
6bc9506f | 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. | |
20 | ||
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/>. */ | |
8a7d0ecc | 25 | |
8a7d0ecc | 26 | #ifndef __objc_INCLUDE_GNU |
27 | #define __objc_INCLUDE_GNU | |
28 | ||
e58aa1bc | 29 | /* This file contains the definition of the basic types used by the |
30 | Objective-C language. It needs to be included to do almost | |
69cfe70f | 31 | anything with Objective-C. */ |
e58aa1bc | 32 | |
8a7d0ecc | 33 | #ifdef __cplusplus |
34 | extern "C" { | |
35 | #endif | |
36 | ||
37 | #include <stddef.h> | |
38 | ||
e58aa1bc | 39 | /* The current version of the GNU Objective-C Runtime library in |
40 | compressed ISO date format. This should be updated any time a new | |
41 | version is released with changes to the public API (there is no | |
42 | need to update it if there were no API changes since the previous | |
43 | release). This macro is only defined starting with the GNU | |
44 | Objective-C Runtime shipped with GCC 4.6.0. If it is not defined, | |
69cfe70f | 45 | it is either an older version of the runtime, or another runtime. */ |
068d3ea7 | 46 | #define __GNU_LIBOBJC__ 20110608 |
e58aa1bc | 47 | |
69cfe70f | 48 | /* Definition of the boolean type. |
344bfd09 | 49 | |
69cfe70f | 50 | Compatibility note: the Apple/NeXT runtime defines a BOOL as a |
51 | 'signed char'. The GNU runtime uses an 'unsigned char'. | |
344bfd09 | 52 | |
69cfe70f | 53 | Important: this could change and we could switch to 'typedef bool |
54 | BOOL' in the future. Do not depend on the type of BOOL. */ | |
a5095f65 | 55 | #undef BOOL |
8a7d0ecc | 56 | typedef unsigned char BOOL; |
344bfd09 | 57 | |
8a7d0ecc | 58 | #define YES (BOOL)1 |
59 | #define NO (BOOL)0 | |
60 | ||
344bfd09 | 61 | /* The basic Objective-C types (SEL, Class, id) are defined as pointer |
62 | to opaque structures. The details of the structures are private to | |
63 | the runtime and may potentially change from one version to the | |
69cfe70f | 64 | other. */ |
8a7d0ecc | 65 | |
344bfd09 | 66 | /* A SEL (selector) represents an abstract method (in the |
67 | object-oriented sense) and includes all the details of how to | |
68 | invoke the method (which means its name, arguments and return | |
69 | types) but provides no implementation of its own. You can check | |
70 | whether a class implements a selector or not, and if you have a | |
71 | selector and know that the class implements it, you can use it to | |
69cfe70f | 72 | call the method for an object in the class. */ |
344bfd09 | 73 | typedef const struct objc_selector *SEL; |
344bfd09 | 74 | |
75 | /* A Class is a class (in the object-oriented sense). In Objective-C | |
76 | there is the complication that each Class is an object itself, and | |
77 | so belongs to a class too. This class that a class belongs to is | |
69cfe70f | 78 | called its 'meta class'. */ |
344bfd09 | 79 | typedef struct objc_class *Class; |
344bfd09 | 80 | |
3c744362 | 81 | /* An 'id' is an object of an unknown class. The way the object data |
82 | is stored inside the object is private and what you see here is | |
83 | only the beginning of the actual struct. The first field is always | |
69cfe70f | 84 | a pointer to the Class that the object belongs to. */ |
344bfd09 | 85 | typedef struct objc_object |
86 | { | |
87 | /* 'class_pointer' is the Class that the object belongs to. In case | |
3c744362 | 88 | of a Class object, this pointer points to the meta class. |
89 | ||
90 | Compatibility Note: The Apple/NeXT runtime calls this field | |
69cfe70f | 91 | 'isa'. To access this field, use object_getClass() from |
92 | runtime.h, which is an inline function so does not add any | |
93 | overhead and is also portable to other runtimes. */ | |
344bfd09 | 94 | Class class_pointer; |
8a7d0ecc | 95 | } *id; |
96 | ||
69cfe70f | 97 | /* 'IMP' is a C function that implements a method. When retrieving |
98 | the implementation of a method from the runtime, this is the type | |
99 | of the pointer returned. The idea of the definition of IMP is to | |
100 | represent a 'pointer to a general function taking an id, a SEL, | |
101 | followed by other unspecified arguments'. You must always cast an | |
102 | IMP to a pointer to a function taking the appropriate, specific | |
103 | types for that function, before calling it - to make sure the | |
104 | appropriate arguments are passed to it. The code generated by the | |
105 | compiler to perform method calls automatically does this cast | |
106 | inside method calls. */ | |
8a7d0ecc | 107 | typedef id (*IMP)(id, SEL, ...); |
108 | ||
344bfd09 | 109 | /* 'nil' is the null object. Messages to nil do nothing and always |
110 | return 0. */ | |
111 | #define nil (id)0 | |
8a7d0ecc | 112 | |
344bfd09 | 113 | /* 'Nil' is the null class. Since classes are objects too, this is |
114 | actually the same object as 'nil' (and behaves in the same way), | |
115 | but it has a type of Class, so it is good to use it instead of | |
116 | 'nil' if you are comparing a Class object to nil as it enables the | |
117 | compiler to do some type-checking. */ | |
118 | #define Nil (Class)0 | |
119 | ||
344bfd09 | 120 | /* TODO: Move the 'Protocol' declaration into objc/runtime.h. A |
121 | Protocol is simply an object, not a basic Objective-C type. The | |
122 | Apple runtime defines Protocol in objc/runtime.h too, so it's good | |
69cfe70f | 123 | to move it there for API compatibility. */ |
8a7d0ecc | 124 | |
344bfd09 | 125 | /* A 'Protocol' is a formally defined list of selectors (normally |
126 | created using the @protocol Objective-C syntax). It is mostly used | |
127 | at compile-time to check that classes implement all the methods | |
128 | that they are supposed to. Protocols are also available in the | |
69cfe70f | 129 | runtime system as Protocol objects. */ |
8a7d0ecc | 130 | #ifndef __OBJC__ |
344bfd09 | 131 | /* Once we stop including the deprecated struct_objc_protocol.h |
132 | there is no reason to even define a 'struct objc_protocol'. As | |
133 | all the structure details will be hidden, a Protocol basically is | |
69cfe70f | 134 | simply an object (as it should be). */ |
72c46466 | 135 | typedef struct objc_object Protocol; |
8a7d0ecc | 136 | #else /* __OBJC__ */ |
344bfd09 | 137 | @class Protocol; |
8a7d0ecc | 138 | #endif |
139 | ||
344bfd09 | 140 | /* Compatibility note: the Apple/NeXT runtime defines sel_getName(), |
141 | sel_registerName(), object_getClassName(), object_getIndexedIvars() | |
142 | in this file while the GNU runtime defines them in runtime.h. | |
8a7d0ecc | 143 | |
344bfd09 | 144 | The reason the GNU runtime does not define them here is that they |
145 | are not basic Objective-C types (defined in this file), but are | |
69cfe70f | 146 | part of the runtime API (defined in runtime.h). */ |
8a7d0ecc | 147 | |
148 | #ifdef __cplusplus | |
149 | } | |
150 | #endif | |
151 | ||
152 | #endif /* not __objc_INCLUDE_GNU */ |