]> git.saurik.com Git - apple/objc4.git/blob - runtime/objc-class.h
83e7b64ffe2ddff49488268167d32500d1a826f3
[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
75
76 /*
77 * Category Template
78 */
79 typedef struct objc_category *Category;
80
81 struct objc_category {
82 char *category_name;
83 char *class_name;
84 struct objc_method_list *instance_methods;
85 struct objc_method_list *class_methods;
86 struct objc_protocol_list *protocols;
87 };
88
89 /*
90 * Instance Variable Template
91 */
92 typedef struct objc_ivar *Ivar;
93
94 struct objc_ivar {
95 char *ivar_name;
96 char *ivar_type;
97 int ivar_offset;
98 #ifdef __alpha__
99 int space;
100 #endif
101 };
102
103 struct objc_ivar_list {
104 int ivar_count;
105 #ifdef __alpha__
106 int space;
107 #endif
108 struct objc_ivar ivar_list[1]; /* variable length structure */
109 };
110
111 OBJC_EXPORT Ivar object_setInstanceVariable(id, const char *name, void *);
112 OBJC_EXPORT Ivar object_getInstanceVariable(id, const char *name, void **);
113
114 /*
115 * Method Template
116 */
117 typedef struct objc_method *Method;
118
119 struct objc_method {
120 SEL method_name;
121 char *method_types;
122 IMP method_imp;
123 };
124
125 struct objc_method_list {
126 struct objc_method_list *obsolete;
127
128 int method_count;
129 #ifdef __alpha__
130 int space;
131 #endif
132 struct objc_method method_list[1]; /* variable length structure */
133 };
134
135 /* Protocol support */
136
137 #ifdef __OBJC__
138 @class Protocol;
139 #else
140 typedef struct objc_object Protocol;
141 #endif
142
143 struct objc_protocol_list {
144 struct objc_protocol_list *next;
145 int count;
146 Protocol *list[1];
147 };
148
149 /* Definitions of filer types */
150
151 #define _C_ID '@'
152 #define _C_CLASS '#'
153 #define _C_SEL ':'
154 #define _C_CHR 'c'
155 #define _C_UCHR 'C'
156 #define _C_SHT 's'
157 #define _C_USHT 'S'
158 #define _C_INT 'i'
159 #define _C_UINT 'I'
160 #define _C_LNG 'l'
161 #define _C_ULNG 'L'
162 #define _C_FLT 'f'
163 #define _C_DBL 'd'
164 #define _C_BFLD 'b'
165 #define _C_VOID 'v'
166 #define _C_UNDEF '?'
167 #define _C_PTR '^'
168 #define _C_CHARPTR '*'
169 #define _C_ARY_B '['
170 #define _C_ARY_E ']'
171 #define _C_UNION_B '('
172 #define _C_UNION_E ')'
173 #define _C_STRUCT_B '{'
174 #define _C_STRUCT_E '}'
175
176 /* Structure for method cache - allocated/sized at runtime */
177
178 typedef struct objc_cache * Cache;
179
180 #define CACHE_BUCKET_NAME(B) ((B)->method_name)
181 #define CACHE_BUCKET_IMP(B) ((B)->method_imp)
182 #define CACHE_BUCKET_VALID(B) (B)
183 #define CACHE_HASH(sel, mask) (((uarith_t)(sel)>>2) & (mask))
184 struct objc_cache {
185 unsigned int mask; /* total = mask + 1 */
186 unsigned int occupied;
187 Method buckets[1];
188 };
189
190 /* operations */
191 OBJC_EXPORT id class_createInstance(Class, unsigned idxIvars);
192 OBJC_EXPORT id class_createInstanceFromZone(Class, unsigned idxIvars, void *z);
193
194 OBJC_EXPORT void class_setVersion(Class, int);
195 OBJC_EXPORT int class_getVersion(Class);
196
197 OBJC_EXPORT Ivar class_getInstanceVariable(Class, const char *);
198 OBJC_EXPORT Method class_getInstanceMethod(Class, SEL);
199 OBJC_EXPORT Method class_getClassMethod(Class, SEL);
200
201 OBJC_EXPORT void class_addMethods(Class, struct objc_method_list *);
202 OBJC_EXPORT void class_removeMethods(Class, struct objc_method_list *);
203
204 OBJC_EXPORT Class class_poseAs(Class imposter, Class original);
205
206 OBJC_EXPORT unsigned method_getNumberOfArguments(Method);
207 OBJC_EXPORT unsigned method_getSizeOfArguments(Method);
208 OBJC_EXPORT unsigned method_getArgumentInfo(Method m, int arg, const char **type, int *offset);
209
210 // usage for nextMethodList
211 //
212 // void *iterator = 0;
213 // struct objc_method_list *mlist;
214 // while ( mlist = class_nextMethodList( cls, &iterator ) )
215 // ;
216 #define OBJC_NEXT_METHOD_LIST 1
217 OBJC_EXPORT struct objc_method_list *class_nextMethodList(Class, void **);
218
219 typedef void *marg_list;
220
221 #if defined(__ppc__) || defined(ppc)
222 #define marg_prearg_size 128
223 #else
224 #define marg_prearg_size 0
225 #endif
226
227 #define marg_malloc(margs, method) \
228 do { \
229 margs = (marg_list *)malloc (marg_prearg_size + ((7 + method_getSizeOfArguments(method)) & ~7)); \
230 } while (0)
231
232
233 #define marg_free(margs) \
234 do { \
235 free(margs); \
236 } while (0)
237
238 #define marg_adjustedOffset(method, offset) \
239 (marg_prearg_size + offset)
240
241
242
243
244 #define marg_getRef(margs, offset, type) \
245 ( (type *)((char *)margs + marg_adjustedOffset(method,offset) ) )
246
247 #define marg_getValue(margs, offset, type) \
248 ( *marg_getRef(margs, offset, type) )
249
250 #define marg_setValue(margs, offset, type, value) \
251 ( marg_getValue(margs, offset, type) = (value) )
252
253 /* Load categories and non-referenced classes from libraries. */
254
255 #endif /* _OBJC_CLASS_H_ */