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