* appdomain.h: Added in MonoDomain a couple of MonoMethod* variables
[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         gpointer    vtable [MONO_ZERO_LEN_ARRAY];       
167         guint remote          : 1; /* class is remotely activated */
168 };
169
170 typedef struct {
171         gulong new_object_count;
172         gulong initialized_class_count;
173         gulong used_class_count;
174         gulong class_vtable_size;
175         gulong class_static_data_size;
176 } MonoStats;
177
178 extern MonoStats mono_stats;
179
180 typedef gpointer (*MonoTrampoline)       (MonoMethod *method);
181
182 typedef gpointer (*MonoLookupDynamicToken) (MonoImage *image, guint32 token);
183
184 MonoClass *
185 mono_class_get             (MonoImage *image, guint32 type_token);
186
187 void
188 mono_class_init            (MonoClass *klass);
189
190 void
191 mono_class_layout_fields   (MonoClass *klass);
192
193 void
194 mono_class_setup_vtable    (MonoClass *klass, MonoMethod **overrides, int onum);
195
196 MonoVTable *
197 mono_class_vtable          (MonoDomain *domain, MonoClass *klass);
198
199 MonoVTable *
200 mono_class_proxy_vtable    (MonoDomain *domain, MonoClass *klass);
201
202 void
203 mono_class_setup_mono_type (MonoClass *klass);
204
205 void
206 mono_class_setup_parent    (MonoClass *klass, MonoClass *parent);
207
208 MonoClass *
209 mono_class_from_name       (MonoImage *image, const char* name_space, const char *name);
210
211 MonoClass *
212 mono_class_from_name_case  (MonoImage *image, const char* name_space, const char *name);
213
214 MonoClass * 
215 mono_class_from_typeref    (MonoImage *image, guint32 type_token);
216
217 MonoClassField*
218 mono_field_from_memberref  (MonoImage *image, guint32 token, MonoClass **retklass);
219
220 MonoClassField*
221 mono_field_from_token      (MonoImage *image, guint32 token, MonoClass **retklass);
222
223 MonoMethod**
224 mono_class_get_overrides   (MonoImage *image, guint32 type_token, gint32 *num_overrides);
225
226 MonoClass *
227 mono_array_class_get       (MonoType *element_type, guint32 rank);
228
229 MonoClass *
230 mono_ptr_class_get         (MonoType *type);
231
232 MonoClassField *
233 mono_class_get_field       (MonoClass *klass, guint32 field_token);
234
235 MonoClassField *
236 mono_class_get_field_from_name (MonoClass *klass, const char *name);
237
238 MonoProperty*
239 mono_class_get_property_from_name (MonoClass *klass, const char *name);
240
241 gint32
242 mono_array_element_size    (MonoClass *ac);
243
244 gint32
245 mono_class_instance_size   (MonoClass *klass);
246
247 gint32
248 mono_class_array_element_size (MonoClass *klass);
249
250 gint32
251 mono_class_data_size       (MonoClass *klass);
252
253 gint32
254 mono_class_value_size      (MonoClass *klass, guint32 *align);
255
256 gint32
257 mono_class_native_size     (MonoClass *klass, guint32 *align);
258
259 MonoMarshalType *
260 mono_marshal_load_type_info (MonoClass* klass);
261
262 gint32
263 mono_class_min_align       (MonoClass *klass);
264
265 MonoClass *
266 mono_class_from_mono_type  (MonoType *type);
267
268 gpointer
269 mono_ldtoken               (MonoImage *image, guint32 token, MonoClass **retclass);
270
271 void
272 mono_install_trampoline (MonoTrampoline func);
273
274 void
275 mono_install_remoting_trampoline (MonoTrampoline func);
276
277 gpointer
278 mono_lookup_dynamic_token (MonoImage *image, guint32 token);
279
280 void
281 mono_install_lookup_dynamic_token (MonoLookupDynamicToken func);
282
283 void    
284 mono_install_get_config_dir(void);
285
286 #endif /* _MONO_CLI_CLASS_H_ */