]> git.saurik.com Git - apple/objc4.git/blob - runtime/objc-class.h
objc4-274.tar.gz
[apple/objc4.git] / runtime / objc-class.h
1 /*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * objc-class.h
27 * Copyright 1988-1996, NeXT Software, Inc.
28 */
29
30 #ifndef _OBJC_CLASS_H_
31 #define _OBJC_CLASS_H_
32
33 #import <objc/objc.h>
34 /*
35 * Class Template
36 */
37 struct objc_class {
38 struct objc_class *isa;
39 struct objc_class *super_class;
40 const char *name;
41 long version;
42 long info;
43 long instance_size;
44 struct objc_ivar_list *ivars;
45
46 struct objc_method_list **methodLists;
47
48 struct objc_cache *cache;
49 struct objc_protocol_list *protocols;
50 };
51 #define CLS_GETINFO(cls,infomask) ((cls)->info & (infomask))
52 #define CLS_SETINFO(cls,infomask) ((cls)->info |= (infomask))
53
54 #define CLS_CLASS 0x1L
55 #define CLS_META 0x2L
56 #define CLS_INITIALIZED 0x4L
57 #define CLS_POSING 0x8L
58 #define CLS_MAPPED 0x10L
59 #define CLS_FLUSH_CACHE 0x20L
60 #define CLS_GROW_CACHE 0x40L
61 #define CLS_NEED_BIND 0x80L
62 #define CLS_METHOD_ARRAY 0x100L
63 // the JavaBridge constructs classes with these markers
64 #define CLS_JAVA_HYBRID 0x200L
65 #define CLS_JAVA_CLASS 0x400L
66 // thread-safe +initialize
67 #define CLS_INITIALIZING 0x800
68 // bundle unloading
69 #define CLS_FROM_BUNDLE 0x1000L
70 // C++ ivar support
71 #define CLS_HAS_CXX_STRUCTORS 0x2000L
72 // Lazy method list arrays
73 #define CLS_NO_METHOD_ARRAY 0x4000L
74 // +load implementation
75 // #define CLS_HAS_LOAD_METHOD 0x8000L
76
77
78 /*
79 * Category Template
80 */
81 typedef struct objc_category *Category;
82
83 struct objc_category {
84 char *category_name;
85 char *class_name;
86 struct objc_method_list *instance_methods;
87 struct objc_method_list *class_methods;
88 struct objc_protocol_list *protocols;
89 };
90
91 /*
92 * Instance Variable Template
93 */
94 typedef struct objc_ivar *Ivar;
95
96 struct objc_ivar {
97 char *ivar_name;
98 char *ivar_type;
99 int ivar_offset;
100 #ifdef __alpha__
101 int space;
102 #endif
103 };
104
105 struct objc_ivar_list {
106 int ivar_count;
107 #ifdef __alpha__
108 int space;
109 #endif
110 struct objc_ivar ivar_list[1]; /* variable length structure */
111 };
112
113 OBJC_EXPORT Ivar object_setInstanceVariable(id, const char *name, void *);
114 OBJC_EXPORT Ivar object_getInstanceVariable(id, const char *name, void **);
115
116 /*
117 * Method Template
118 */
119 typedef struct objc_method *Method;
120
121 struct objc_method {
122 SEL method_name;
123 char *method_types;
124 IMP method_imp;
125 };
126
127 struct objc_method_list {
128 struct objc_method_list *obsolete;
129
130 int method_count;
131 #ifdef __alpha__
132 int space;
133 #endif
134 struct objc_method method_list[1]; /* variable length structure */
135 };
136
137 /* Protocol support */
138
139 #ifdef __OBJC__
140 @class Protocol;
141 #else
142 typedef struct objc_object Protocol;
143 #endif
144
145 struct objc_protocol_list {
146 struct objc_protocol_list *next;
147 int count;
148 Protocol *list[1];
149 };
150
151 /* Definitions of filer types */
152
153 #define _C_ID '@'
154 #define _C_CLASS '#'
155 #define _C_SEL ':'
156 #define _C_CHR 'c'
157 #define _C_UCHR 'C'
158 #define _C_SHT 's'
159 #define _C_USHT 'S'
160 #define _C_INT 'i'
161 #define _C_UINT 'I'
162 #define _C_LNG 'l'
163 #define _C_ULNG 'L'
164 #define _C_FLT 'f'
165 #define _C_DBL 'd'
166 #define _C_BFLD 'b'
167 #define _C_VOID 'v'
168 #define _C_UNDEF '?'
169 #define _C_PTR '^'
170 #define _C_CHARPTR '*'
171 #define _C_ARY_B '['
172 #define _C_ARY_E ']'
173 #define _C_UNION_B '('
174 #define _C_UNION_E ')'
175 #define _C_STRUCT_B '{'
176 #define _C_STRUCT_E '}'
177
178 /* Structure for method cache - allocated/sized at runtime */
179
180 typedef struct objc_cache * Cache;
181
182 #define CACHE_BUCKET_NAME(B) ((B)->method_name)
183 #define CACHE_BUCKET_IMP(B) ((B)->method_imp)
184 #define CACHE_BUCKET_VALID(B) (B)
185 #define CACHE_HASH(sel, mask) (((uarith_t)(sel)>>2) & (mask))
186 struct objc_cache {
187 unsigned int mask; /* total = mask + 1 */
188 unsigned int occupied;
189 Method buckets[1];
190 };
191
192 /* operations */
193 OBJC_EXPORT id class_createInstance(Class, unsigned idxIvars);
194 OBJC_EXPORT id class_createInstanceFromZone(Class, unsigned idxIvars, void *z);
195
196 OBJC_EXPORT void class_setVersion(Class, int);
197 OBJC_EXPORT int class_getVersion(Class);
198
199 OBJC_EXPORT Ivar class_getInstanceVariable(Class, const char *);
200 OBJC_EXPORT Method class_getInstanceMethod(Class, SEL);
201 OBJC_EXPORT Method class_getClassMethod(Class, SEL);
202
203 OBJC_EXPORT void class_addMethods(Class, struct objc_method_list *);
204 OBJC_EXPORT void class_removeMethods(Class, struct objc_method_list *);
205
206 OBJC_EXPORT Class class_poseAs(Class imposter, Class original);
207
208 OBJC_EXPORT unsigned method_getNumberOfArguments(Method);
209 OBJC_EXPORT unsigned method_getSizeOfArguments(Method);
210 OBJC_EXPORT unsigned method_getArgumentInfo(Method m, int arg, const char **type, int *offset);
211
212 // usage for nextMethodList
213 //
214 // void *iterator = 0;
215 // struct objc_method_list *mlist;
216 // while ( mlist = class_nextMethodList( cls, &iterator ) )
217 // ;
218 #define OBJC_NEXT_METHOD_LIST 1
219 OBJC_EXPORT struct objc_method_list *class_nextMethodList(Class, void **);
220
221 typedef void *marg_list;
222
223 #if defined(__ppc__) || defined(ppc)
224 #define marg_prearg_size 128
225 #else
226 #define marg_prearg_size 0
227 #endif
228
229 #define marg_malloc(margs, method) \
230 do { \
231 margs = (marg_list *)malloc (marg_prearg_size + ((7 + method_getSizeOfArguments(method)) & ~7)); \
232 } while (0)
233
234
235 #define marg_free(margs) \
236 do { \
237 free(margs); \
238 } while (0)
239
240 #define marg_adjustedOffset(method, offset) \
241 (marg_prearg_size + offset)
242
243
244
245
246 #define marg_getRef(margs, offset, type) \
247 ( (type *)((char *)margs + marg_adjustedOffset(method,offset) ) )
248
249 #define marg_getValue(margs, offset, type) \
250 ( *marg_getRef(margs, offset, type) )
251
252 #define marg_setValue(margs, offset, type, value) \
253 ( marg_getValue(margs, offset, type) = (value) )
254
255 /* Load categories and non-referenced classes from libraries. */
256
257 #endif /* _OBJC_CLASS_H_ */