* test-9.il: New test, test instaniating a class
[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 dummy           : 1; /* temorary hack */
97
98         MonoClass  *parent;
99         MonoClass  *nested_in;
100         GList      *nested_classes;
101         GList      *subclasses; /* list of all subclasses */
102
103         guint32    type_token;
104         const char *name;
105         const char *name_space;
106         
107         guint       interface_count;
108         guint       interface_id;        /* unique inderface id (for interfaces) */
109         guint       max_interface_id;
110         gint       *interface_offsets;   
111         MonoClass **interfaces;
112
113         /* for fast subtype checks */
114         guint       idepth;
115         MonoClass **supertypes;
116
117         /*
118          * Computed object instance size, total.
119          */
120         int        instance_size;
121         int        class_size;
122         int        vtable_size; /* number of slots */
123
124         /*
125          * From the TypeDef table
126          */
127         guint32    flags;
128         struct {
129                 guint32 first, last;
130                 int count;
131         } field, method, property, event;
132
133         /* loaded on demand */
134         MonoMarshalType *marshal_info;
135
136         /*
137          * Field information: Type and location from object base
138          */
139         MonoClassField *fields;
140
141         MonoProperty *properties;
142         
143         MonoEvent *events;
144
145         MonoMethod **methods;
146
147         /* used as the type of the this argument and when passing the arg by value */
148         MonoType this_arg;
149         MonoType byval_arg;
150
151         void *reflection_info;
152
153         MonoMethod *ptr_to_str;
154         MonoMethod *str_to_ptr;
155
156         MonoVTable *cached_vtable;
157         MonoMethod **vtable;    
158 };
159
160 struct MonoVTable {
161         MonoClass  *klass;
162         MonoDomain *domain;  /* each object/vtable belongs to exactly one domain */
163         guint       max_interface_id;
164         gpointer   *interface_offsets;   
165         gpointer    data; /* to store static class data */
166         guint remote          : 1; /* class is remotely activated */
167         /* do not add any fields after vtable, the structure is dynamically extended */
168         gpointer    vtable [MONO_ZERO_LEN_ARRAY];       
169 };
170
171 typedef struct {
172         gulong new_object_count;
173         gulong initialized_class_count;
174         gulong used_class_count;
175         gulong class_vtable_size;
176         gulong class_static_data_size;
177 } MonoStats;
178
179 extern MonoStats mono_stats;
180
181 typedef gpointer (*MonoTrampoline)       (MonoMethod *method);
182
183 typedef gpointer (*MonoLookupDynamicToken) (MonoImage *image, guint32 token);
184
185 MonoClass *
186 mono_class_get             (MonoImage *image, guint32 type_token);
187
188 void
189 mono_class_init            (MonoClass *klass);
190
191 void
192 mono_class_layout_fields   (MonoClass *klass);
193
194 void
195 mono_class_setup_vtable    (MonoClass *klass, MonoMethod **overrides, int onum);
196
197 MonoVTable *
198 mono_class_vtable          (MonoDomain *domain, MonoClass *klass);
199
200 MonoVTable *
201 mono_class_proxy_vtable    (MonoDomain *domain, MonoClass *klass);
202
203 void
204 mono_class_setup_mono_type (MonoClass *klass);
205
206 void
207 mono_class_setup_parent    (MonoClass *klass, MonoClass *parent);
208
209 MonoClass *
210 mono_class_from_name       (MonoImage *image, const char* name_space, const char *name);
211
212 MonoClass *
213 mono_class_from_name_case  (MonoImage *image, const char* name_space, const char *name);
214
215 MonoClass * 
216 mono_class_from_typeref    (MonoImage *image, guint32 type_token);
217
218 MonoClassField*
219 mono_field_from_memberref  (MonoImage *image, guint32 token, MonoClass **retklass);
220
221 MonoClassField*
222 mono_field_from_token      (MonoImage *image, guint32 token, MonoClass **retklass);
223
224 MonoMethod**
225 mono_class_get_overrides   (MonoImage *image, guint32 type_token, gint32 *num_overrides);
226
227 MonoClass *
228 mono_array_class_get       (MonoType *element_type, guint32 rank);
229
230 MonoClass *
231 mono_ptr_class_get         (MonoType *type);
232
233 MonoClassField *
234 mono_class_get_field       (MonoClass *klass, guint32 field_token);
235
236 MonoClassField *
237 mono_class_get_field_from_name (MonoClass *klass, const char *name);
238
239 MonoProperty*
240 mono_class_get_property_from_name (MonoClass *klass, const char *name);
241
242 gint32
243 mono_array_element_size    (MonoClass *ac);
244
245 gint32
246 mono_class_instance_size   (MonoClass *klass);
247
248 gint32
249 mono_class_array_element_size (MonoClass *klass);
250
251 gint32
252 mono_class_data_size       (MonoClass *klass);
253
254 gint32
255 mono_class_value_size      (MonoClass *klass, guint32 *align);
256
257 gint32
258 mono_class_native_size     (MonoClass *klass, guint32 *align);
259
260 MonoMarshalType *
261 mono_marshal_load_type_info (MonoClass* klass);
262
263 gint32
264 mono_class_min_align       (MonoClass *klass);
265
266 MonoClass *
267 mono_class_from_mono_type  (MonoType *type);
268
269 gpointer
270 mono_ldtoken               (MonoImage *image, guint32 token, MonoClass **retclass);
271
272 void
273 mono_install_trampoline (MonoTrampoline func);
274
275 void
276 mono_install_remoting_trampoline (MonoTrampoline func);
277
278 gpointer
279 mono_lookup_dynamic_token (MonoImage *image, guint32 token);
280
281 void
282 mono_install_lookup_dynamic_token (MonoLookupDynamicToken func);
283
284 void    
285 mono_install_get_config_dir(void);
286
287 #endif /* _MONO_CLI_CLASS_H_ */