2011-02-22 Tobias Burnus <burnus@net-b.de>
[official-gcc.git] / libobjc / objc / objc.h
blobece0f88410500f66128140dd8efce1631df7daa8
1 /* Basic data types for Objective C.
2 Copyright (C) 1993, 1995, 1996, 2004, 2009,
3 2010 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 GCC is distributed in the hope that it will be useful,
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.
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_INCLUDE_GNU
27 #define __objc_INCLUDE_GNU
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
31 anything with Objective-C. */
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
37 #include <stddef.h>
39 /* objc-decls.h is included because deprecated/objc_msg_sendv.h needs
40 it. When that goes away, the include of objc-decls.h should be
41 removed. */
42 #include "objc-decls.h"
44 /* The current version of the GNU Objective-C Runtime library in
45 compressed ISO date format. This should be updated any time a new
46 version is released with changes to the public API (there is no
47 need to update it if there were no API changes since the previous
48 release). This macro is only defined starting with the GNU
49 Objective-C Runtime shipped with GCC 4.6.0. If it is not defined,
50 it is either an older version of the runtime, or another runtime. */
51 #define __GNU_LIBOBJC__ 20100911
53 /* Definition of the boolean type.
55 Compatibility note: the Apple/NeXT runtime defines a BOOL as a
56 'signed char'. The GNU runtime uses an 'unsigned char'.
58 Important: this could change and we could switch to 'typedef bool
59 BOOL' in the future. Do not depend on the type of BOOL. */
60 #undef BOOL
61 typedef unsigned char BOOL;
63 #define YES (BOOL)1
64 #define NO (BOOL)0
66 /* The basic Objective-C types (SEL, Class, id) are defined as pointer
67 to opaque structures. The details of the structures are private to
68 the runtime and may potentially change from one version to the
69 other. */
71 /* A SEL (selector) represents an abstract method (in the
72 object-oriented sense) and includes all the details of how to
73 invoke the method (which means its name, arguments and return
74 types) but provides no implementation of its own. You can check
75 whether a class implements a selector or not, and if you have a
76 selector and know that the class implements it, you can use it to
77 call the method for an object in the class. */
78 typedef const struct objc_selector *SEL;
79 #include "deprecated/struct_objc_selector.h"
81 /* A Class is a class (in the object-oriented sense). In Objective-C
82 there is the complication that each Class is an object itself, and
83 so belongs to a class too. This class that a class belongs to is
84 called its 'meta class'. */
85 typedef struct objc_class *Class;
86 #include "deprecated/MetaClass.h"
87 #include "deprecated/struct_objc_class.h"
89 /* An 'id' is an object of an unknown class. The way the object data
90 is stored inside the object is private and what you see here is
91 only the beginning of the actual struct. The first field is always
92 a pointer to the Class that the object belongs to. */
93 typedef struct objc_object
95 /* 'class_pointer' is the Class that the object belongs to. In case
96 of a Class object, this pointer points to the meta class.
98 Compatibility Note: The Apple/NeXT runtime calls this field
99 'isa'. To access this field, use object_getClass() from
100 runtime.h, which is an inline function so does not add any
101 overhead and is also portable to other runtimes. */
102 Class class_pointer;
103 } *id;
105 /* 'IMP' is a C function that implements a method. When retrieving
106 the implementation of a method from the runtime, this is the type
107 of the pointer returned. The idea of the definition of IMP is to
108 represent a 'pointer to a general function taking an id, a SEL,
109 followed by other unspecified arguments'. You must always cast an
110 IMP to a pointer to a function taking the appropriate, specific
111 types for that function, before calling it - to make sure the
112 appropriate arguments are passed to it. The code generated by the
113 compiler to perform method calls automatically does this cast
114 inside method calls. */
115 typedef id (*IMP)(id, SEL, ...);
117 /* 'nil' is the null object. Messages to nil do nothing and always
118 return 0. */
119 #define nil (id)0
121 /* 'Nil' is the null class. Since classes are objects too, this is
122 actually the same object as 'nil' (and behaves in the same way),
123 but it has a type of Class, so it is good to use it instead of
124 'nil' if you are comparing a Class object to nil as it enables the
125 compiler to do some type-checking. */
126 #define Nil (Class)0
128 #include "deprecated/STR.h"
130 /* TODO: Move the 'Protocol' declaration into objc/runtime.h. A
131 Protocol is simply an object, not a basic Objective-C type. The
132 Apple runtime defines Protocol in objc/runtime.h too, so it's good
133 to move it there for API compatibility. */
135 /* A 'Protocol' is a formally defined list of selectors (normally
136 created using the @protocol Objective-C syntax). It is mostly used
137 at compile-time to check that classes implement all the methods
138 that they are supposed to. Protocols are also available in the
139 runtime system as Protocol objects. */
140 #ifndef __OBJC__
141 /* Once we stop including the deprecated struct_objc_protocol.h
142 there is no reason to even define a 'struct objc_protocol'. As
143 all the structure details will be hidden, a Protocol basically is
144 simply an object (as it should be). */
145 /* typedef struct objc_object Protocol; */
146 #include "deprecated/struct_objc_protocol.h"
147 #else /* __OBJC__ */
148 @class Protocol;
149 #endif
151 /* Deprecated include - here temporarily, for backwards-compatibility
152 as reval_t, apply_t, arglist_t and objc_msg_lookup() used to be
153 defined here. objc_msg_lookup() is now defined in message.h,
154 included by objc-api.h or runtime.h. */
155 #include "deprecated/objc_msg_sendv.h"
157 /* Compatibility note: the Apple/NeXT runtime defines sel_getName(),
158 sel_registerName(), object_getClassName(), object_getIndexedIvars()
159 in this file while the GNU runtime defines them in runtime.h.
161 The reason the GNU runtime does not define them here is that they
162 are not basic Objective-C types (defined in this file), but are
163 part of the runtime API (defined in runtime.h). */
165 #ifdef __cplusplus
167 #endif
169 #endif /* not __objc_INCLUDE_GNU */