* culture-info.h: Make defines more consistent, add calendar data
[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         MonoTypeEnum type;
17         gpointer value;
18 } MonoConstant;
19
20 /*
21  * MonoClassField is just a runtime representation of the metadata for
22  * field, it doesn't contain the data directly.  Static fields are
23  * stored in MonoVTable->data.  Instance fields are allocated in the
24  * objects after the object header.
25  */
26 typedef struct {
27         /* Type of the field */
28         MonoType        *type;
29
30         /* If this is an instantiated generic type, this is the
31          * "original" type, ie. the MONO_TYPE_VAR or MONO_TYPE_GENERICINST
32          * it was instantiated from.
33          */
34         MonoType        *generic_type;
35
36         /*
37          * Offset where this field is stored; if it is an instance
38          * field, it's the offset from the start of the object, if
39          * it's static, it's from the start of the memory chunk
40          * allocated for statics for the class.
41          */
42         int              offset;
43
44         const char      *name;
45
46         /*
47          * Pointer to the data (from the RVA address, valid only for
48          * fields with the has rva flag).
49          */
50         const char      *data;
51
52         /* Type where the field was defined */
53         MonoClass       *parent;
54
55         /*
56          * If the field is constant, pointer to the metadata where the
57          * constant value can be loaded. Initialized lazily during vtable creation.
58          */
59         MonoConstant    *def_value;
60 } MonoClassField;
61
62 /* a field is ignored if it's named "_Deleted" and it has the specialname and rtspecialname flags set */
63 #define mono_field_is_deleted(field) ((field)->name[0] == '_' && ((field)->type->attrs & 0x600) && (strcmp ((field)->name, "_Deleted") == 0))
64
65 typedef struct {
66         MonoClassField *field;
67         guint32 offset;
68         MonoMarshalSpec *mspec;
69 } MonoMarshalField;
70
71 typedef struct {
72         guint32 native_size;
73         guint32 num_fields;
74         MonoMarshalField fields [MONO_ZERO_LEN_ARRAY];
75 } MonoMarshalType;
76
77 typedef struct {
78         MonoClass *parent;
79         const char *name;
80         MonoMethod *get;
81         MonoMethod *set;
82         guint32 attrs;
83 } MonoProperty;
84
85 typedef struct {
86         MonoClass *parent;
87         const char *name;
88         MonoMethod *add;
89         MonoMethod *remove;
90         MonoMethod *raise;
91         MonoMethod **other;
92         guint32 attrs;
93 } MonoEvent;
94
95 struct _MonoClass {
96         MonoImage *image;
97
98         /* The underlying type of the enum */
99         MonoType *enum_basetype;
100         /* element class for arrays and enum */
101         MonoClass *element_class; 
102         /* used for subtype checks */
103         MonoClass *cast_class; 
104         /* array dimension */
105         guint32    rank;          
106
107         guint inited          : 1;
108         /* We use init_pending to detect cyclic calls to mono_class_init */
109         guint init_pending    : 1;
110
111         /* A class contains static and non static data. Static data can be
112          * of the same type as the class itselfs, but it does not influence
113          * the instance size of the class. To avoid cyclic calls to 
114          * mono_class_init (from mono_class_instance_size ()) we first 
115          * initialise all non static fields. After that we set size_inited 
116          * to 1, because we know the instance size now. After that we 
117          * initialise all static fields.
118          */
119         guint size_inited     : 1;
120         guint valuetype       : 1; /* derives from System.ValueType */
121         guint enumtype        : 1; /* derives from System.Enum */
122         guint blittable       : 1; /* class is blittable */
123         guint unicode         : 1; /* class uses unicode char when marshalled */
124         guint wastypebuilder  : 1; /* class was created at runtime from a TypeBuilder */
125         /* next byte */
126         guint min_align       : 4;
127         guint packing_size    : 4;
128         /* next byte */
129         guint ghcimpl         : 1; /* class has its own GetHashCode impl */ 
130         guint has_finalize    : 1; /* class has its own Finalize impl */ 
131         guint marshalbyref    : 1; /* class is a MarshalByRefObject */
132         guint contextbound    : 1; /* class is a ContextBoundObject */
133         guint delegate        : 1; /* class is a Delegate */
134         guint gc_descr_inited : 1; /* gc_descr is initialized */
135         guint dummy           : 1; /* temporary hack */
136
137         MonoClass  *parent;
138         MonoClass  *nested_in;
139         GList      *nested_classes;
140
141         guint32    type_token;
142         const char *name;
143         const char *name_space;
144         
145         guint       interface_count;
146         guint       interface_id;        /* unique inderface id (for interfaces) */
147         guint       max_interface_id;
148         gint       *interface_offsets;   
149         MonoClass **interfaces;
150
151         /* for fast subtype checks */
152         guint       idepth;
153         MonoClass **supertypes;
154
155         /*
156          * Computed object instance size, total.
157          */
158         int        instance_size;
159         int        class_size;
160         int        vtable_size; /* number of slots */
161
162         /*
163          * From the TypeDef table
164          */
165         guint32    flags;
166         struct {
167                 guint32 first, last;
168                 int count;
169         } field, method, property, event;
170
171         /* loaded on demand */
172         MonoMarshalType *marshal_info;
173
174         /*
175          * Field information: Type and location from object base
176          */
177         MonoClassField *fields;
178
179         MonoProperty *properties;
180         
181         MonoEvent *events;
182
183         MonoMethod **methods;
184
185         /* used as the type of the this argument and when passing the arg by value */
186         MonoType this_arg;
187         MonoType byval_arg;
188
189         MonoGenericInst *generic_inst;
190         MonoGenericParam *gen_params;
191         guint16 num_gen_params;
192
193         void *reflection_info;
194
195         void *gc_descr;
196         guint64 gc_bitmap;
197
198         MonoMethod *ptr_to_str;
199         MonoMethod *str_to_ptr;
200
201         MonoVTable *cached_vtable;
202         MonoMethod **vtable;    
203 };
204
205 struct MonoVTable {
206         MonoClass  *klass;
207     /*
208          * According to comments in gc_gcj.h, this should be the second word in
209          * the vtable.
210          */
211         void *gc_descr;         
212         MonoDomain *domain;  /* each object/vtable belongs to exactly one domain */
213         guint       max_interface_id;
214         gpointer   *interface_offsets;   
215         gpointer    data; /* to store static class data */
216         gpointer    type; /* System.Type type for klass */
217         guint remote          : 1; /* class is remotely activated */
218         guint initialized     : 1; /* cctor has been run */
219         /* do not add any fields after vtable, the structure is dynamically extended */
220         gpointer    vtable [MONO_ZERO_LEN_ARRAY];       
221 };
222
223 /*
224  * Generic instantiation data type encoding.
225  */
226 struct _MonoGenericInst {
227         MonoGenericContext *context;
228         MonoClass *klass;
229         MonoType *parent;
230         int count_ifaces;
231         MonoType **ifaces;
232         MonoType *generic_type;
233         MonoDynamicGenericInst *dynamic_info;
234         int type_argc;
235         MonoType **type_argv;
236         guint is_open       : 1;
237         guint initialized   : 1;
238         guint init_pending  : 1;
239         guint is_dynamic    : 1;
240 };
241
242 struct _MonoDynamicGenericInst {
243         int count_methods;
244         MonoMethod **methods;
245         int count_ctors;
246         MonoMethod **ctors;
247         int count_fields;
248         MonoClassField *fields;
249         int count_properties;
250         MonoProperty *properties;
251         int count_events;
252         MonoEvent *events;
253 };
254
255 struct _MonoGenericMethod {
256         gpointer reflection_info;
257         int mtype_argc;
258         MonoType **mtype_argv;
259         guint is_open       : 1;
260 };
261
262 struct _MonoGenericContext {
263         MonoGenericInst *ginst;
264         MonoGenericMethod *gmethod;
265 };
266
267 struct _MonoGenericParam {
268         MonoClass *pklass;
269         MonoMethod *method;
270         const char *name;
271         guint16 flags;
272         guint16 num;
273         MonoClass** constraints; /* NULL means end of list */
274 };
275
276 typedef struct {
277         MonoVTable *vtable;
278         MonoClass *proxy_class;
279         guint interface_count;
280         MonoClass **interfaces;
281         char* proxy_class_name;
282 } MonoRemoteClass;
283
284 #define mono_class_has_parent(klass,parent) (((klass)->idepth >= (parent)->idepth) && ((klass)->supertypes [(parent)->idepth - 1] == (parent)))
285
286 typedef struct {
287         gulong new_object_count;
288         gulong initialized_class_count;
289         gulong used_class_count;
290         gulong class_vtable_size;
291         gulong class_static_data_size;
292         gulong generic_instance_count;
293         gulong inflated_method_count;
294         gulong inflated_type_count;
295         gulong generics_metadata_size;
296 } MonoStats;
297
298 extern MonoStats mono_stats;
299
300 typedef gpointer (*MonoTrampoline)       (MonoMethod *method);
301
302 typedef gpointer (*MonoLookupDynamicToken) (MonoImage *image, guint32 token);
303
304 void
305 mono_classes_init (void);
306
307 MonoClass *
308 mono_class_get             (MonoImage *image, guint32 type_token);
309
310 MonoClass *
311 mono_class_get_full        (MonoImage *image, guint32 type_token, MonoGenericContext *context);
312
313 void
314 mono_class_init            (MonoClass *klass);
315
316 void
317 mono_class_layout_fields   (MonoClass *klass);
318
319 void
320 mono_class_setup_vtable    (MonoClass *klass, MonoMethod **overrides, int onum);
321
322 MonoVTable *
323 mono_class_vtable          (MonoDomain *domain, MonoClass *klass);
324
325 void
326 mono_class_setup_mono_type (MonoClass *klass);
327
328 void
329 mono_class_setup_parent    (MonoClass *klass, MonoClass *parent);
330
331 void
332 mono_class_setup_supertypes (MonoClass *klass);
333
334 MonoClass *
335 mono_class_from_name       (MonoImage *image, const char* name_space, const char *name);
336
337 MonoClass *
338 mono_class_from_name_case  (MonoImage *image, const char* name_space, const char *name);
339
340 MonoClass * 
341 mono_class_from_typeref    (MonoImage *image, guint32 type_token);
342
343 gboolean
344 mono_class_is_open_constructed_type (MonoType *t);
345
346 MonoClass *
347 mono_class_from_generic_parameter (MonoGenericParam *param, MonoImage *image, gboolean is_mvar);
348
349 MonoClass*
350 mono_class_create_generic  (MonoGenericInst *ginst);
351
352 MonoType*
353 mono_class_inflate_generic_type (MonoType *type, MonoGenericContext *context);
354
355 MonoMethod*
356 mono_class_inflate_generic_method (MonoMethod *method, MonoGenericContext *context, MonoClass *klass);
357
358 MonoClassField*
359 mono_field_from_token      (MonoImage *image, guint32 token, MonoClass **retklass, MonoGenericContext *context);
360
361 MonoMethod**
362 mono_class_get_overrides   (MonoImage *image, guint32 type_token, gint32 *num_overrides);
363
364 MonoClass *
365 mono_bounded_array_class_get (MonoClass *element_class, guint32 rank, gboolean bounded);
366
367 MonoClass *
368 mono_array_class_get       (MonoClass *element_class, guint32 rank);
369
370 MonoClass *
371 mono_ptr_class_get         (MonoType *type);
372
373 MonoClassField *
374 mono_class_get_field       (MonoClass *klass, guint32 field_token);
375
376 MonoClassField *
377 mono_class_get_field_from_name (MonoClass *klass, const char *name);
378
379 MonoProperty*
380 mono_class_get_property_from_name (MonoClass *klass, const char *name);
381
382 gint32
383 mono_array_element_size    (MonoClass *ac);
384
385 gint32
386 mono_class_instance_size   (MonoClass *klass);
387
388 gint32
389 mono_class_array_element_size (MonoClass *klass);
390
391 gint32
392 mono_class_data_size       (MonoClass *klass);
393
394 gint32
395 mono_class_value_size      (MonoClass *klass, guint32 *align);
396
397 gint32
398 mono_class_min_align       (MonoClass *klass);
399
400 MonoClass *
401 mono_class_from_mono_type  (MonoType *type);
402
403 gboolean
404 mono_class_is_subclass_of (MonoClass *klass, MonoClass *klassc, 
405                                                    gboolean check_interfaces);
406
407 gboolean
408 mono_class_is_assignable_from (MonoClass *klass, MonoClass *oklass);
409
410 gboolean
411 mono_class_needs_cctor_run (MonoClass *klass, MonoMethod *caller);
412
413 gpointer
414 mono_ldtoken               (MonoImage *image, guint32 token, MonoClass **retclass, MonoGenericContext *context);
415
416 char*         
417 mono_type_get_name         (MonoType *type);
418
419 void
420 mono_install_trampoline (MonoTrampoline func);
421
422 void
423 mono_install_remoting_trampoline (MonoTrampoline func);
424
425 gpointer
426 mono_lookup_dynamic_token (MonoImage *image, guint32 token);
427
428 void
429 mono_install_lookup_dynamic_token (MonoLookupDynamicToken func);
430
431 void    
432 mono_install_get_config_dir(void);
433
434 #endif /* _MONO_CLI_CLASS_H_ */