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