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