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