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