Wed Apr 9 15:19:41 CEST 2003 Paolo Molaro <lupus@ximian.com>
[mono.git] / mono / metadata / class.h
1 #ifndef _MONO_CLI_CLASS_H_
2 #define _MONO_CLI_CLASS_H_
3
4 #include <mono/metadata/metadata.h>
5 #include <mono/metadata/image.h>
6 #include <mono/metadata/loader.h>
7
8 #define MONO_CLASS_IS_ARRAY(c) ((c)->rank)
9
10 #define MONO_DEFAULT_SUPERTABLE_SIZE 6
11
12 extern gboolean mono_print_vtable;
13 typedef struct MonoVTable MonoVTable;
14
15 typedef struct {
16         MonoType        *type;
17         int              offset;
18         const char      *name;
19         const char      *data;
20         MonoClass       *parent;
21 } MonoClassField;
22
23 typedef struct {
24         MonoClassField *field;
25         guint32 offset;
26         MonoMarshalSpec *mspec;
27 } MonoMarshalField;
28
29 typedef struct {
30         guint32 native_size;
31         guint32 num_fields;
32         MonoMarshalField fields [MONO_ZERO_LEN_ARRAY];
33 } MonoMarshalType;
34
35 typedef struct {
36         const char *name;
37         MonoMethod *get;
38         MonoMethod *set;
39         guint32 attrs;
40 } MonoProperty;
41
42 typedef struct {
43         const char *name;
44         MonoMethod *add;
45         MonoMethod *remove;
46         MonoMethod *raise;
47         MonoMethod **other;
48         guint32 attrs;
49 } MonoEvent;
50
51 struct _MonoClass {
52         MonoImage *image;
53
54         /*
55          * relative numbering for fast type checking
56          */
57         unsigned int baseval;
58         unsigned int diffval;
59
60         /* The underlying type of the enum */
61         MonoType *enum_basetype;
62         /* element class for arrays and enum */
63         MonoClass *element_class; 
64         /* used for subtype checks */
65         MonoClass *cast_class; 
66         /* array dimension */
67         guint32    rank;          
68
69         guint inited          : 1;
70         /* We use init_pending to detect cyclic calls to mono_class_init */
71         guint init_pending    : 1;
72
73         /* A class contains static and non static data. Static data can be
74          * of the same type as the class itselfs, but it does not influence
75          * the instance size of the class. To avoid cyclic calls to 
76          * mono_class_init (from mono_class_instance_size ()) we first 
77          * initialise all non static fields. After that we set size_inited 
78          * to 1, because we know the instance size now. After that we 
79          * initialise all static fields.
80          */
81         guint size_inited     : 1;
82         guint valuetype       : 1; /* derives from System.ValueType */
83         guint enumtype        : 1; /* derives from System.Enum */
84         guint blittable       : 1; /* class is blittable */
85         guint unicode         : 1; /* class uses unicode char when marshalled */
86         guint wastypebuilder  : 1; /* class was created at runtime from a TypeBuilder */
87         /* next byte */
88         guint min_align       : 4;
89         guint packing_size    : 4;
90         /* next byte */
91         guint ghcimpl         : 1; /* class has its own GetHashCode impl */ 
92         guint has_finalize    : 1; /* class has its own Finalize impl */ 
93         guint marshalbyref    : 1; /* class is a MarshalByRefObject */
94         guint contextbound    : 1; /* class is a ContextBoundObject */
95         guint delegate        : 1; /* class is a Delegate */
96         guint gc_descr_inited : 1; /* gc_descr is initialized */
97         guint dummy           : 1; /* temporary hack */
98
99         MonoClass  *parent;
100         MonoClass  *nested_in;
101         GList      *nested_classes;
102         GList      *subclasses; /* list of all subclasses */
103
104         guint32    type_token;
105         const char *name;
106         const char *name_space;
107         
108         guint       interface_count;
109         guint       interface_id;        /* unique inderface id (for interfaces) */
110         guint       max_interface_id;
111         gint       *interface_offsets;   
112         MonoClass **interfaces;
113
114         /* for fast subtype checks */
115         guint       idepth;
116         MonoClass **supertypes;
117
118         /*
119          * Computed object instance size, total.
120          */
121         int        instance_size;
122         int        class_size;
123         int        vtable_size; /* number of slots */
124
125         /*
126          * From the TypeDef table
127          */
128         guint32    flags;
129         struct {
130                 guint32 first, last;
131                 int count;
132         } field, method, property, event;
133
134         /* loaded on demand */
135         MonoMarshalType *marshal_info;
136
137         /*
138          * Field information: Type and location from object base
139          */
140         MonoClassField *fields;
141
142         MonoProperty *properties;
143         
144         MonoEvent *events;
145
146         MonoMethod **methods;
147
148         /* used as the type of the this argument and when passing the arg by value */
149         MonoType this_arg;
150         MonoType byval_arg;
151
152         void *reflection_info;
153
154         void *gc_descr;
155         guint64 gc_bitmap;
156
157         MonoMethod *ptr_to_str;
158         MonoMethod *str_to_ptr;
159
160         MonoVTable *cached_vtable;
161         MonoMethod **vtable;    
162 };
163
164 struct MonoVTable {
165         MonoClass  *klass;
166     /*
167          * According to comments in gc_gcj.h, this should be the second word in
168          * the vtable.
169          */
170         void *gc_descr;         
171         MonoDomain *domain;  /* each object/vtable belongs to exactly one domain */
172         guint       max_interface_id;
173         gpointer   *interface_offsets;   
174         gpointer    data; /* to store static class data */
175         guint remote          : 1; /* class is remotely activated */
176         /* do not add any fields after vtable, the structure is dynamically extended */
177         gpointer    vtable [MONO_ZERO_LEN_ARRAY];       
178 };
179
180 typedef struct {
181         gulong new_object_count;
182         gulong initialized_class_count;
183         gulong used_class_count;
184         gulong class_vtable_size;
185         gulong class_static_data_size;
186 } MonoStats;
187
188 extern MonoStats mono_stats;
189
190 typedef gpointer (*MonoTrampoline)       (MonoMethod *method);
191
192 typedef gpointer (*MonoLookupDynamicToken) (MonoImage *image, guint32 token);
193
194 MonoClass *
195 mono_class_get             (MonoImage *image, guint32 type_token);
196
197 void
198 mono_class_init            (MonoClass *klass);
199
200 void
201 mono_class_layout_fields   (MonoClass *klass);
202
203 void
204 mono_class_setup_vtable    (MonoClass *klass, MonoMethod **overrides, int onum);
205
206 MonoVTable *
207 mono_class_vtable          (MonoDomain *domain, MonoClass *klass);
208
209 MonoVTable *
210 mono_class_proxy_vtable    (MonoDomain *domain, MonoClass *klass);
211
212 void
213 mono_class_setup_mono_type (MonoClass *klass);
214
215 void
216 mono_class_setup_parent    (MonoClass *klass, MonoClass *parent);
217
218 void
219 mono_class_setup_supertypes (MonoClass *klass);
220
221 MonoClass *
222 mono_class_from_name       (MonoImage *image, const char* name_space, const char *name);
223
224 MonoClass *
225 mono_class_from_name_case  (MonoImage *image, const char* name_space, const char *name);
226
227 MonoClass * 
228 mono_class_from_typeref    (MonoImage *image, guint32 type_token);
229
230 MonoClassField*
231 mono_field_from_memberref  (MonoImage *image, guint32 token, MonoClass **retklass);
232
233 MonoClassField*
234 mono_field_from_token      (MonoImage *image, guint32 token, MonoClass **retklass);
235
236 MonoMethod**
237 mono_class_get_overrides   (MonoImage *image, guint32 type_token, gint32 *num_overrides);
238
239 MonoClass *
240 mono_array_class_get       (MonoType *element_type, guint32 rank);
241
242 MonoClass *
243 mono_ptr_class_get         (MonoType *type);
244
245 MonoClassField *
246 mono_class_get_field       (MonoClass *klass, guint32 field_token);
247
248 MonoClassField *
249 mono_class_get_field_from_name (MonoClass *klass, const char *name);
250
251 MonoProperty*
252 mono_class_get_property_from_name (MonoClass *klass, const char *name);
253
254 gint32
255 mono_array_element_size    (MonoClass *ac);
256
257 gint32
258 mono_class_instance_size   (MonoClass *klass);
259
260 gint32
261 mono_class_array_element_size (MonoClass *klass);
262
263 gint32
264 mono_class_data_size       (MonoClass *klass);
265
266 gint32
267 mono_class_value_size      (MonoClass *klass, guint32 *align);
268
269 gint32
270 mono_class_native_size     (MonoClass *klass, guint32 *align);
271
272 MonoMarshalType *
273 mono_marshal_load_type_info (MonoClass* klass);
274
275 gint32
276 mono_class_min_align       (MonoClass *klass);
277
278 MonoClass *
279 mono_class_from_mono_type  (MonoType *type);
280
281 gboolean
282 mono_class_is_subclass_of (MonoClass *klass, MonoClass *klassc, 
283                                                    gboolean check_interfaces);
284
285 gpointer
286 mono_ldtoken               (MonoImage *image, guint32 token, MonoClass **retclass);
287
288 void
289 mono_install_trampoline (MonoTrampoline func);
290
291 void
292 mono_install_remoting_trampoline (MonoTrampoline func);
293
294 gpointer
295 mono_lookup_dynamic_token (MonoImage *image, guint32 token);
296
297 void
298 mono_install_lookup_dynamic_token (MonoLookupDynamicToken func);
299
300 void    
301 mono_install_get_config_dir(void);
302
303 #endif /* _MONO_CLI_CLASS_H_ */