OSDN Git Service

17ae49b17472711176c46b26b9a349d215db0236
[pf3gnuchains/gcc-fork.git] / libobjc / objc / objc.h
1 /* Basic data types for Objective C.
2    Copyright (C) 1993, 1995, 1996, 2004, 2009, 
3    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
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.
11
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.
16
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/>.  */
25
26 #ifndef __objc_INCLUDE_GNU
27 #define __objc_INCLUDE_GNU
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 #include <stddef.h>
34
35 /*
36   Definition of the boolean type.
37
38   Compatibility note: the Apple/NeXT runtime defines a BOOL as a
39   'signed char'.  The GNU runtime uses an 'unsigned char'.
40
41   Important: this could change and we could switch to 'typedef bool
42   BOOL' in the future.  Do not depend on the type of BOOL.
43 */
44 #undef BOOL
45 typedef unsigned char  BOOL;
46
47 #define YES   (BOOL)1
48 #define NO    (BOOL)0
49
50 /* The basic Objective-C types (SEL, Class, id) are defined as pointer
51    to opaque structures.  The details of the structures are private to
52    the runtime and may potentially change from one version to the
53    other.
54 */
55
56 /* A SEL (selector) represents an abstract method (in the
57    object-oriented sense) and includes all the details of how to
58    invoke the method (which means its name, arguments and return
59    types) but provides no implementation of its own.  You can check
60    whether a class implements a selector or not, and if you have a
61    selector and know that the class implements it, you can use it to
62    call the method for an object in the class.
63  */
64 typedef const struct objc_selector *SEL;
65 #include "deprecated/struct_objc_selector.h"
66
67 /* A Class is a class (in the object-oriented sense).  In Objective-C
68    there is the complication that each Class is an object itself, and
69    so belongs to a class too.  This class that a class belongs to is
70    called its 'meta class'.
71 */
72 typedef struct objc_class *Class;
73 #include "deprecated/MetaClass.h"
74 #include "deprecated/struct_objc_class.h"
75
76 /* An 'id' is an object of an unknown class.  The struct objc_object
77    is private and what you see here is only the beginning of the
78    struct.  In theory, the fact that 'class_pointer' is public means
79    that if you have any object 'object', you can immediately get its
80    class by using '((id)object)->class_pointer', but this is not
81    recommended; you should use object_get_class(object) instead.
82 */
83 typedef struct objc_object
84 {
85   /* 'class_pointer' is the Class that the object belongs to.  In case
86      of a Class object, this pointer points to the meta class.  */
87   /* Note that the Apple/NeXT runtime calls this variable 'isa'.
88      TODO: Decide if we want to call it 'isa' too.  TODO: Why not
89      simply hide this pointer and force users to use the proper API to
90      get it ?
91   */
92   Class class_pointer;
93 } *id;
94
95 /*
96   'IMP' is a C function that implements a method.  When retrieving the
97   implementation of a method from the runtime, this is the type of the
98   pointer returned.  The idea of the definition of IMP is to represent
99   a 'pointer to a general function taking an id, a SEL, followed by
100   other unspecified arguments'.  You must always cast an IMP to a
101   pointer to a function taking the appropriate, specific types for
102   that function, before calling it - to make sure the appropriate
103   arguments are passed to it.  The code generated by the compiler to
104   perform method calls automatically does this cast inside method
105   calls.
106 */
107 typedef id (*IMP)(id, SEL, ...); 
108
109 /* 'nil' is the null object.  Messages to nil do nothing and always
110    return 0.  */
111 #define nil (id)0
112
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
120 #include "deprecated/STR.h"
121
122 /* TODO: Move the 'Protocol' declaration into objc/runtime.h.  A
123    Protocol is simply an object, not a basic Objective-C type.  The
124    Apple runtime defines Protocol in objc/runtime.h too, so it's good
125    to move it there for API compatibility.
126 */
127
128 /* A 'Protocol' is a formally defined list of selectors (normally
129    created using the @protocol Objective-C syntax).  It is mostly used
130    at compile-time to check that classes implement all the methods
131    that they are supposed to.  Protocols are also available in the
132    runtime system as Protocol objects.
133  */
134 #ifndef __OBJC__
135   /* Once we stop including the deprecated struct_objc_protocol.h
136      there is no reason to even define a 'struct objc_protocol'.  As
137      all the structure details will be hidden, a Protocol basically is
138      simply an object (as it should be).
139    */
140   /* typedef struct objc_object Protocol; */
141   #include "deprecated/struct_objc_protocol.h"
142 #else /* __OBJC__ */
143   @class Protocol;
144 #endif 
145
146 /* Deprecated include - here temporarily, for backwards-compatibility
147    as reval_t, apply_t, arglist_t and objc_msg_lookup() used to be
148    defined here.  */
149 #include "message.h"
150
151 /* Compatibility note: the Apple/NeXT runtime defines sel_getName(),
152    sel_registerName(), object_getClassName(), object_getIndexedIvars()
153    in this file while the GNU runtime defines them in runtime.h.
154
155    The reason the GNU runtime does not define them here is that they
156    are not basic Objective-C types (defined in this file), but are
157    part of the runtime API (defined in runtime.h).
158 */
159
160 #ifdef __cplusplus
161 }
162 #endif
163
164 #endif /* not __objc_INCLUDE_GNU */