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 */
31 * Offset where this field is stored; if it is an instance
32 * field, it's the offset from the start of the object, if
33 * it's static, it's from the start of the memory chunk
34 * allocated for statics for the class.
41 * Pointer to the data (from the RVA address, valid only for
42 * fields with the has rva flag).
46 /* Type where the field was defined */
50 * If the field is constant, pointer to the metadata where the
51 * constant value can be loaded.
53 MonoConstant *def_value;
57 MonoClassField *field;
59 MonoMarshalSpec *mspec;
65 MonoMarshalField fields [MONO_ZERO_LEN_ARRAY];
87 /* The underlying type of the enum */
88 MonoType *enum_basetype;
89 /* element class for arrays and enum */
90 MonoClass *element_class;
91 /* used for subtype checks */
92 MonoClass *cast_class;
97 /* We use init_pending to detect cyclic calls to mono_class_init */
98 guint init_pending : 1;
100 /* A class contains static and non static data. Static data can be
101 * of the same type as the class itselfs, but it does not influence
102 * the instance size of the class. To avoid cyclic calls to
103 * mono_class_init (from mono_class_instance_size ()) we first
104 * initialise all non static fields. After that we set size_inited
105 * to 1, because we know the instance size now. After that we
106 * initialise all static fields.
108 guint size_inited : 1;
109 guint valuetype : 1; /* derives from System.ValueType */
110 guint enumtype : 1; /* derives from System.Enum */
111 guint blittable : 1; /* class is blittable */
112 guint unicode : 1; /* class uses unicode char when marshalled */
113 guint wastypebuilder : 1; /* class was created at runtime from a TypeBuilder */
116 guint packing_size : 4;
118 guint ghcimpl : 1; /* class has its own GetHashCode impl */
119 guint has_finalize : 1; /* class has its own Finalize impl */
120 guint marshalbyref : 1; /* class is a MarshalByRefObject */
121 guint contextbound : 1; /* class is a ContextBoundObject */
122 guint delegate : 1; /* class is a Delegate */
123 guint gc_descr_inited : 1; /* gc_descr is initialized */
124 guint dummy : 1; /* temporary hack */
127 MonoClass *nested_in;
128 GList *nested_classes;
132 const char *name_space;
134 guint interface_count;
135 guint interface_id; /* unique inderface id (for interfaces) */
136 guint max_interface_id;
137 gint *interface_offsets;
138 MonoClass **interfaces;
140 /* for fast subtype checks */
142 MonoClass **supertypes;
145 * Computed object instance size, total.
149 int vtable_size; /* number of slots */
152 * From the TypeDef table
158 } field, method, property, event;
160 /* loaded on demand */
161 MonoMarshalType *marshal_info;
164 * Field information: Type and location from object base
166 MonoClassField *fields;
168 MonoProperty *properties;
172 MonoMethod **methods;
174 /* used as the type of the this argument and when passing the arg by value */
178 MonoType *generic_inst;
179 MonoGenericParam *gen_params;
180 guint16 num_gen_params;
182 void *reflection_info;
187 MonoMethod *ptr_to_str;
188 MonoMethod *str_to_ptr;
190 MonoVTable *cached_vtable;
197 * According to comments in gc_gcj.h, this should be the second word in
201 MonoDomain *domain; /* each object/vtable belongs to exactly one domain */
202 guint max_interface_id;
203 gpointer *interface_offsets;
204 gpointer data; /* to store static class data */
205 guint remote : 1; /* class is remotely activated */
206 guint initialized : 1; /* cctor has been run */
207 guint initializing : 1; /* cctor is running */
208 /* do not add any fields after vtable, the structure is dynamically extended */
209 gpointer vtable [MONO_ZERO_LEN_ARRAY];
213 * Generic instantiation data type encoding.
215 struct _MonoGenericInst {
217 MonoType *generic_type;
218 MonoMethod *generic_method;
220 MonoType **type_argv;
224 struct _MonoGenericParam {
230 MonoClass** constraints; /* NULL means end of list */
233 #define mono_class_has_parent(klass,parent) ((klass)->idepth >= (parent)->idepth) && ((klass)->supertypes [(parent)->idepth - 1] == (parent))
236 gulong new_object_count;
237 gulong initialized_class_count;
238 gulong used_class_count;
239 gulong class_vtable_size;
240 gulong class_static_data_size;
243 extern MonoStats mono_stats;
245 typedef gpointer (*MonoTrampoline) (MonoMethod *method);
247 typedef gpointer (*MonoLookupDynamicToken) (MonoImage *image, guint32 token);
250 mono_classes_init (void);
253 mono_class_get (MonoImage *image, guint32 type_token);
256 mono_class_init (MonoClass *klass);
259 mono_class_layout_fields (MonoClass *klass);
262 mono_class_setup_vtable (MonoClass *klass, MonoMethod **overrides, int onum);
265 mono_class_vtable (MonoDomain *domain, MonoClass *klass);
268 mono_class_proxy_vtable (MonoDomain *domain, MonoClass *klass);
271 mono_class_setup_mono_type (MonoClass *klass);
274 mono_class_setup_parent (MonoClass *klass, MonoClass *parent);
277 mono_class_setup_supertypes (MonoClass *klass);
280 mono_class_from_name (MonoImage *image, const char* name_space, const char *name);
283 mono_class_from_name_case (MonoImage *image, const char* name_space, const char *name);
286 mono_class_from_typeref (MonoImage *image, guint32 type_token);
289 mono_class_is_open_constructed_type (MonoType *t);
292 mono_class_from_generic_parameter (MonoGenericParam *param, MonoImage *image, gboolean is_mvar);
295 mono_class_from_generic (MonoType *gtype, gboolean inflate_methods);
298 mono_class_inflate_generic_type (MonoType *type, MonoGenericInst *ginst);
301 mono_class_inflate_generic_signature (MonoImage *image, MonoMethodSignature *sig, MonoGenericInst *ginst);
304 mono_class_inflate_generic_method (MonoMethod *method, MonoGenericInst *ginst);
307 mono_class_create_from_generic (MonoImage *image, MonoType *gtype);
310 mono_class_initialize_generic (MonoClass *class, gboolean inflate_methods);
313 mono_field_from_memberref (MonoImage *image, guint32 token, MonoClass **retklass);
316 mono_field_from_token (MonoImage *image, guint32 token, MonoClass **retklass);
319 mono_class_get_overrides (MonoImage *image, guint32 type_token, gint32 *num_overrides);
322 mono_array_class_get (MonoClass *element_class, guint32 rank);
325 mono_ptr_class_get (MonoType *type);
328 mono_class_get_field (MonoClass *klass, guint32 field_token);
331 mono_class_get_field_from_name (MonoClass *klass, const char *name);
334 mono_class_get_property_from_name (MonoClass *klass, const char *name);
337 mono_array_element_size (MonoClass *ac);
340 mono_class_instance_size (MonoClass *klass);
343 mono_class_array_element_size (MonoClass *klass);
346 mono_class_data_size (MonoClass *klass);
349 mono_class_value_size (MonoClass *klass, guint32 *align);
352 mono_class_min_align (MonoClass *klass);
355 mono_class_from_mono_type (MonoType *type);
358 mono_class_is_subclass_of (MonoClass *klass, MonoClass *klassc,
359 gboolean check_interfaces);
362 mono_class_is_assignable_from (MonoClass *klass, MonoClass *oklass);
365 mono_class_needs_cctor_run (MonoClass *klass, MonoMethod *caller);
368 mono_ldtoken (MonoImage *image, guint32 token, MonoClass **retclass);
371 mono_type_get_name (MonoType *type);
374 mono_install_trampoline (MonoTrampoline func);
377 mono_install_remoting_trampoline (MonoTrampoline func);
380 mono_lookup_dynamic_token (MonoImage *image, guint32 token);
383 mono_install_lookup_dynamic_token (MonoLookupDynamicToken func);
386 mono_install_get_config_dir(void);
388 #endif /* _MONO_CLI_CLASS_H_ */