1 #ifndef _MONO_CLI_CLASS_H_
2 #define _MONO_CLI_CLASS_H_
4 #include <mono/metadata/metadata.h>
5 #include <mono/metadata/image.h>
6 #include <mono/metadata/loader.h>
8 #define MONO_CLASS_IS_ARRAY(c) ((c)->rank)
10 #define MONO_DEFAULT_SUPERTABLE_SIZE 6
12 extern gboolean mono_print_vtable;
13 typedef struct MonoVTable MonoVTable;
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.
27 /* Type of the field */
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.
34 MonoType *generic_type;
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.
47 * Pointer to the data (from the RVA address, valid only for
48 * fields with the has rva flag).
52 /* Type where the field was defined */
56 * If the field is constant, pointer to the metadata where the
57 * constant value can be loaded. Initialized lazily during vtable creation.
59 MonoConstant *def_value;
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))
66 MonoClassField *field;
68 MonoMarshalSpec *mspec;
74 MonoMarshalField fields [MONO_ZERO_LEN_ARRAY];
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 */
108 /* We use init_pending to detect cyclic calls to mono_class_init */
109 guint init_pending : 1;
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.
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 */
127 guint packing_size : 4;
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 */
138 MonoClass *nested_in;
139 GList *nested_classes;
143 const char *name_space;
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;
151 /* for fast subtype checks */
153 MonoClass **supertypes;
156 * Computed object instance size, total.
160 int vtable_size; /* number of slots */
163 * From the TypeDef table
169 } field, method, property, event;
171 /* loaded on demand */
172 MonoMarshalType *marshal_info;
175 * Field information: Type and location from object base
177 MonoClassField *fields;
179 MonoProperty *properties;
183 MonoMethod **methods;
185 /* used as the type of the this argument and when passing the arg by value */
189 MonoGenericInst *generic_inst;
190 MonoGenericParam *gen_params;
191 guint16 num_gen_params;
193 void *reflection_info;
198 MonoMethod *ptr_to_str;
199 MonoMethod *str_to_ptr;
201 MonoVTable *cached_vtable;
208 * According to comments in gc_gcj.h, this should be the second word in
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];
224 * Generic instantiation data type encoding.
226 struct _MonoGenericInst {
227 MonoGenericContext *context;
232 MonoType *generic_type;
233 MonoDynamicGenericInst *dynamic_info;
235 MonoType **type_argv;
237 guint initialized : 1;
238 guint init_pending : 1;
239 guint is_dynamic : 1;
242 struct _MonoDynamicGenericInst {
244 MonoMethod **methods;
248 MonoClassField *fields;
249 int count_properties;
250 MonoProperty *properties;
255 struct _MonoGenericMethod {
256 gpointer reflection_info;
258 MonoType **mtype_argv;
262 struct _MonoGenericContext {
263 MonoGenericInst *ginst;
264 MonoGenericMethod *gmethod;
267 struct _MonoGenericParam {
273 MonoClass** constraints; /* NULL means end of list */
278 MonoClass *proxy_class;
279 guint interface_count;
280 MonoClass **interfaces;
281 char* proxy_class_name;
284 #define mono_class_has_parent(klass,parent) (((klass)->idepth >= (parent)->idepth) && ((klass)->supertypes [(parent)->idepth - 1] == (parent)))
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;
298 extern MonoStats mono_stats;
300 typedef gpointer (*MonoTrampoline) (MonoMethod *method);
302 typedef gpointer (*MonoLookupDynamicToken) (MonoImage *image, guint32 token);
305 mono_classes_init (void);
308 mono_class_get (MonoImage *image, guint32 type_token);
311 mono_class_get_full (MonoImage *image, guint32 type_token, MonoGenericContext *context);
314 mono_class_init (MonoClass *klass);
317 mono_class_layout_fields (MonoClass *klass);
320 mono_class_setup_vtable (MonoClass *klass, MonoMethod **overrides, int onum);
323 mono_class_vtable (MonoDomain *domain, MonoClass *klass);
326 mono_class_setup_mono_type (MonoClass *klass);
329 mono_class_setup_parent (MonoClass *klass, MonoClass *parent);
332 mono_class_setup_supertypes (MonoClass *klass);
335 mono_class_from_name (MonoImage *image, const char* name_space, const char *name);
338 mono_class_from_name_case (MonoImage *image, const char* name_space, const char *name);
341 mono_class_from_typeref (MonoImage *image, guint32 type_token);
344 mono_class_is_open_constructed_type (MonoType *t);
347 mono_class_from_generic_parameter (MonoGenericParam *param, MonoImage *image, gboolean is_mvar);
350 mono_class_create_generic (MonoGenericInst *ginst);
353 mono_class_inflate_generic_type (MonoType *type, MonoGenericContext *context);
356 mono_class_inflate_generic_method (MonoMethod *method, MonoGenericContext *context, MonoClass *klass);
359 mono_field_from_token (MonoImage *image, guint32 token, MonoClass **retklass, MonoGenericContext *context);
362 mono_class_get_overrides (MonoImage *image, guint32 type_token, gint32 *num_overrides);
365 mono_bounded_array_class_get (MonoClass *element_class, guint32 rank, gboolean bounded);
368 mono_array_class_get (MonoClass *element_class, guint32 rank);
371 mono_ptr_class_get (MonoType *type);
374 mono_class_get_field (MonoClass *klass, guint32 field_token);
377 mono_class_get_field_from_name (MonoClass *klass, const char *name);
380 mono_class_get_property_from_name (MonoClass *klass, const char *name);
383 mono_array_element_size (MonoClass *ac);
386 mono_class_instance_size (MonoClass *klass);
389 mono_class_array_element_size (MonoClass *klass);
392 mono_class_data_size (MonoClass *klass);
395 mono_class_value_size (MonoClass *klass, guint32 *align);
398 mono_class_min_align (MonoClass *klass);
401 mono_class_from_mono_type (MonoType *type);
404 mono_class_is_subclass_of (MonoClass *klass, MonoClass *klassc,
405 gboolean check_interfaces);
408 mono_class_is_assignable_from (MonoClass *klass, MonoClass *oklass);
411 mono_class_needs_cctor_run (MonoClass *klass, MonoMethod *caller);
414 mono_ldtoken (MonoImage *image, guint32 token, MonoClass **retclass, MonoGenericContext *context);
417 mono_type_get_name (MonoType *type);
420 mono_install_trampoline (MonoTrampoline func);
423 mono_install_remoting_trampoline (MonoTrampoline func);
426 mono_lookup_dynamic_token (MonoImage *image, guint32 token);
429 mono_install_lookup_dynamic_token (MonoLookupDynamicToken func);
432 mono_install_get_config_dir(void);
434 #endif /* _MONO_CLI_CLASS_H_ */