1 #ifndef __METADATA_REFLECTION_H__
2 #define __METADATA_REFLECTION_H__
4 #include <mono/metadata/image.h>
5 #include <mono/metadata/metadata.h>
6 #include <mono/metadata/class.h>
7 #include <mono/metadata/object.h>
8 #include <mono/utils/mono-hash.h>
13 guint32 alloc_size; /* malloced bytes */
15 guint32 offset; /* from start of metadata */
21 guint32 row_size; /* calculated later with column_sizes */
23 guint32 column_sizes [9];
24 guint32 *values; /* rows * columns */
29 * The followinbg structure must match the C# implementation in our corlib.
32 struct _MonoReflectionMethod {
36 MonoReflectionType *reftype;
39 struct _MonoDelegate {
41 MonoObject *target_type;
43 MonoString *method_name;
45 gpointer delegate_trampoline;
46 MonoReflectionMethod *method_info;
49 typedef struct _MonoMulticastDelegate MonoMulticastDelegate;
50 struct _MonoMulticastDelegate {
51 MonoDelegate delegate;
52 MonoMulticastDelegate *prev;
58 MonoClassField *field;
60 MonoReflectionType *type;
62 } MonoReflectionField;
67 MonoProperty *property;
68 } MonoReflectionProperty;
74 } MonoReflectionEvent;
78 MonoReflectionType *ClassImpl;
79 MonoObject *DefaultValueImpl;
80 MonoObject *MemberImpl;
84 } MonoReflectionParameter;
88 MonoAssembly *assembly;
89 } MonoReflectionAssembly;
92 MonoReflectionType *utype;
98 MonoReflectionType *parent;
99 MonoReflectionType *ret;
106 MonoReflectionType *parent;
108 MonoReflectionMethod *get;
109 MonoReflectionMethod *set;
114 MonoReflectionType *parent;
116 MonoReflectionMethod *add_method;
117 MonoReflectionMethod *remove_method;
118 MonoReflectionMethod *raise_method;
124 MonoString *name_space;
125 MonoReflectionType *etype;
126 MonoReflectionType *nested_in;
127 MonoReflectionAssembly *assembly;
129 MonoBoolean isprimitive;
135 } MonoReflectionILTokenInfo;
144 MonoArray *ex_handlers;
145 gint32 num_token_fixups;
146 MonoArray *token_fixups;
147 } MonoReflectionILGen;
154 } MonoILExceptionInfo;
157 MonoReflectionType *extype;
161 gint32 filter_offset;
162 } MonoILExceptionBlock;
166 MonoReflectionType *type;
168 } MonoReflectionLocalBuilder;
177 MonoString *marshaltype;
178 MonoReflectionType *marshaltyperef;
179 } MonoReflectionMarshal;
186 MonoReflectionMarshal *marshal_info;
190 } MonoReflectionParamBuilder;
195 MonoReflectionILGen *ilgen;
196 MonoArray *parameters;
204 MonoBoolean init_locals;
205 MonoArray *param_modreq;
206 MonoArray *param_modopt;
207 } MonoReflectionCtorBuilder;
212 MonoReflectionType *rtype;
213 MonoArray *parameters;
219 MonoReflectionILGen *ilgen;
223 MonoReflectionMethod *override_method;
225 MonoString *dllentry;
229 MonoBoolean init_locals;
230 MonoArray *generic_params;
231 MonoArray *return_modreq;
232 MonoArray *return_modopt;
233 MonoArray *param_modreq;
234 MonoArray *param_modopt;
235 } MonoReflectionMethodBuilder;
240 MonoReflectionType *parent;
241 MonoReflectionType *ret;
242 MonoArray *parameters;
246 } MonoReflectionArrayMethod;
249 * Information which isn't in the MonoMethod structure is stored here for
254 MonoMarshalSpec **param_marshall;
255 } MonoReflectionMethodAux;
265 MonoAssembly assembly;
269 guint32 strong_name_size;
270 } MonoDynamicAssembly;
276 guint32 metadata_rva;
278 guint32 cli_header_offset;
282 guint32 imp_names_offset;
288 } sections [MONO_SECTION_MAX];
290 GHashTable *handleref;
291 MonoGHashTable *tokens;
292 MonoGHashTable *blob_cache;
293 GList *array_methods;
294 MonoGHashTable *token_fixups;
295 MonoGHashTable *method_to_table_idx;
296 MonoGHashTable *field_to_table_idx;
297 MonoGHashTable *method_aux_hash;
301 guint32 strong_name_size;
302 MonoDynamicStream pefile;
303 MonoDynamicStream sheap;
304 MonoDynamicStream code; /* used to store method headers and bytecode */
305 MonoDynamicStream resources; /* managed embedded resources */
306 MonoDynamicStream us;
307 MonoDynamicStream blob;
308 MonoDynamicStream tstream;
309 MonoDynamicStream guid;
310 MonoDynamicTable tables [64];
316 MonoString *filename;
318 } MonoReflectionResource;
321 MonoReflectionAssembly assembly;
322 MonoDynamicAssembly *dynamic_assembly;
323 MonoReflectionMethodBuilder *entry_point;
328 MonoArray *resources;
329 MonoArray *public_key;
335 MonoBoolean delay_sign;
337 gpointer main_module;
338 } MonoReflectionAssemblyBuilder;
343 MonoReflectionType *type;
345 MonoObject *def_value;
348 MonoReflectionType *typeb;
351 MonoReflectionMarshal *marshal_info;
352 MonoClassField *handle;
355 } MonoReflectionFieldBuilder;
361 MonoReflectionType *type;
362 MonoArray *parameters;
364 MonoObject *def_value;
365 MonoReflectionMethodBuilder *set_method;
366 MonoReflectionMethodBuilder *get_method;
368 } MonoReflectionPropertyBuilder;
373 MonoReflectionAssembly *assembly;
376 MonoString *scopename;
377 MonoBoolean is_resource;
378 } MonoReflectionModule;
381 MonoReflectionModule module;
382 MonoDynamicImage *dynamic_image;
388 MonoReflectionAssemblyBuilder *assemblyb;
389 MonoArray *global_methods;
390 MonoArray *global_fields;
392 } MonoReflectionModuleBuilder;
395 MonoReflectionType type;
398 MonoReflectionType *parent;
399 MonoReflectionType *nesting_type;
400 MonoArray *interfaces;
404 MonoArray *properties;
412 MonoReflectionModuleBuilder *module;
415 MonoArray *generic_params;
416 } MonoReflectionTypeBuilder;
419 MonoReflectionType type;
424 MonoArray *constraints;
426 } MonoReflectionGenericParam;
428 typedef struct _MonoReflectionGenericInst MonoReflectionGenericInst;
429 struct _MonoReflectionGenericInst {
430 MonoReflectionType type;
432 MonoReflectionGenericInst *parent;
433 MonoReflectionType *generic_type;
434 MonoArray *interfaces;
441 MonoReflectionMethod rmethod;
442 MonoReflectionMethod *declaring;
443 MonoReflectionGenericInst *declaring_type;
444 MonoReflectionGenericInst *reflected_type;
445 MonoGenericInst *ginst;
446 } MonoReflectionInflatedMethod;
449 MonoReflectionField rfield;
450 MonoClassField *declaring;
451 MonoReflectionGenericInst *declaring_type;
452 MonoReflectionGenericInst *reflected_type;
453 } MonoReflectionInflatedField;
458 MonoString *codebase;
459 gint32 major, minor, build, revision;
460 /* FIXME: add missing stuff */
461 /* CultureInfo cultureinfo;
462 AssemblyNameFlags flags;
463 AssemblyHashAlgorithm hashalg;
464 StrongNameKeyPair keypair;
465 AssemblyVersionCompatibility versioncompat;*/
466 MonoObject *cultureInfo;
470 MonoArray *publicKey;
472 MonoObject *versioncompat;
473 } MonoReflectionAssemblyName;
478 MonoReflectionType *type;
479 MonoReflectionTypeBuilder *typeb;
481 MonoReflectionMethodBuilder *add_method;
482 MonoReflectionMethodBuilder *remove_method;
483 MonoReflectionMethodBuilder *raise_method;
484 MonoArray *other_methods;
487 } MonoReflectionEventBuilder;
491 MonoReflectionMethod *ctor;
493 } MonoReflectionCustomAttr;
499 MonoReflectionType *rtype;
500 MonoArray *parameters;
503 MonoReflectionModule *module;
504 MonoBoolean skip_visibility;
505 MonoBoolean init_locals;
506 MonoReflectionILGen *ilgen;
509 } MonoReflectionDynamicMethod;
511 typedef struct MonoTypeNameParse MonoTypeNameParse;
513 struct MonoTypeNameParse {
516 MonoAssemblyName assembly;
517 GList *modifiers; /* 0 -> byref, -1 -> pointer, > 0 -> array rank */
523 MonoReflectionModuleBuilder *module;
524 MonoArray *arguments;
526 MonoReflectionType *return_type;
528 guint32 unmanaged_call_conv;
529 } MonoReflectionSigHelper;
535 } MonoCustomAttrEntry;
540 MonoCustomAttrEntry attrs [MONO_ZERO_LEN_ARRAY];
541 } MonoCustomAttrInfo;
544 RESOURCE_LOCATION_EMBEDDED = 1,
545 RESOURCE_LOCATION_ANOTHER_ASSEMBLY = 2,
546 RESOURCE_LOCATION_IN_MANIFEST = 4
551 MonoReflectionAssembly *assembly;
552 MonoString *filename;
554 } MonoManifestResourceInfo;
556 int mono_reflection_parse_type (char *name, MonoTypeNameParse *info);
557 MonoType* mono_reflection_get_type (MonoImage* image, MonoTypeNameParse *info, gboolean ignorecase);
558 MonoType* mono_reflection_type_from_name (char *name, MonoImage *image);
560 void mono_image_create_pefile (MonoReflectionModuleBuilder *module);
561 void mono_image_basic_init (MonoReflectionAssemblyBuilder *assembly);
562 guint32 mono_image_insert_string (MonoReflectionModuleBuilder *module, MonoString *str);
563 guint32 mono_image_create_token (MonoDynamicImage *assembly, MonoObject *obj);
564 void mono_image_module_basic_init (MonoReflectionModuleBuilder *module);
566 MonoReflectionAssembly* mono_assembly_get_object (MonoDomain *domain, MonoAssembly *assembly);
567 MonoReflectionModule* mono_module_get_object (MonoDomain *domain, MonoImage *image);
568 MonoReflectionModule* mono_module_file_get_object (MonoDomain *domain, MonoImage *image, int table_index);
569 MonoReflectionType* mono_type_get_object (MonoDomain *domain, MonoType *type);
570 MonoReflectionMethod* mono_method_get_object (MonoDomain *domain, MonoMethod *method, MonoClass *refclass);
571 MonoReflectionField* mono_field_get_object (MonoDomain *domain, MonoClass *klass, MonoClassField *field);
572 MonoReflectionProperty* mono_property_get_object (MonoDomain *domain, MonoClass *klass, MonoProperty *property);
573 MonoReflectionEvent* mono_event_get_object (MonoDomain *domain, MonoClass *klass, MonoEvent *event);
574 /* note: this one is slightly different: we keep the whole array of params in the cache */
575 MonoArray* mono_param_get_objects (MonoDomain *domain, MonoMethod *method);
577 MonoArray* mono_reflection_get_custom_attrs (MonoObject *obj);
578 MonoArray* mono_reflection_get_custom_attrs_blob (MonoObject *ctor, MonoArray *ctorArgs, MonoArray *properties, MonoArray *porpValues, MonoArray *fields, MonoArray* fieldValues);
580 MonoArray* mono_custom_attrs_construct (MonoCustomAttrInfo *cinfo);
581 MonoCustomAttrInfo* mono_custom_attrs_from_index (MonoImage *image, guint32 idx);
582 MonoCustomAttrInfo* mono_custom_attrs_from_method (MonoMethod *method);
583 MonoCustomAttrInfo* mono_custom_attrs_from_class (MonoClass *klass);
584 MonoCustomAttrInfo* mono_custom_attrs_from_assembly (MonoAssembly *assembly);
585 MonoCustomAttrInfo* mono_custom_attrs_from_property (MonoClass *klass, MonoProperty *property);
586 MonoCustomAttrInfo* mono_custom_attrs_from_event (MonoClass *klass, MonoEvent *event);
587 MonoCustomAttrInfo* mono_custom_attrs_from_field (MonoClass *klass, MonoClassField *field);
588 MonoCustomAttrInfo* mono_custom_attrs_from_param (MonoMethod *method, guint32 param);
589 void mono_custom_attrs_free (MonoCustomAttrInfo *ainfo);
591 void mono_reflection_setup_internal_class (MonoReflectionTypeBuilder *tb);
593 void mono_reflection_create_internal_class (MonoReflectionTypeBuilder *tb);
595 void mono_reflection_setup_generic_class (MonoReflectionTypeBuilder *tb);
597 MonoReflectionType* mono_reflection_create_runtime_class (MonoReflectionTypeBuilder *tb);
599 void mono_reflection_create_dynamic_method (MonoReflectionDynamicMethod *m);
601 MonoReflectionGenericParam *mono_reflection_define_generic_parameter (MonoReflectionTypeBuilder *tb, MonoReflectionMethodBuilder *mb, MonoString *name, guint32 index);
602 void mono_reflection_initialize_generic_parameter (MonoReflectionGenericParam *gparam);
604 MonoReflectionGenericInst*
605 mono_reflection_bind_generic_parameters (MonoReflectionType *type, MonoArray *types);
606 MonoReflectionInflatedMethod*
607 mono_reflection_bind_generic_method_parameters (MonoReflectionMethod *method, MonoArray *types);
608 MonoReflectionInflatedMethod*
609 mono_reflection_inflate_method_or_ctor (MonoReflectionGenericInst *declaring_type, MonoReflectionGenericInst *reflected_type, MonoObject *obj);
610 MonoReflectionInflatedField*
611 mono_reflection_inflate_field (MonoReflectionGenericInst *declaring_type, MonoReflectionGenericInst *reflected_type, MonoObject *obj);
613 MonoArray *mono_reflection_sighelper_get_signature_local (MonoReflectionSigHelper *sig);
615 MonoArray *mono_reflection_sighelper_get_signature_field (MonoReflectionSigHelper *sig);
618 mono_reflection_lookup_dynamic_token (MonoImage *image, guint32 token);
621 mono_image_build_metadata (MonoReflectionModuleBuilder *module);
623 #endif /* __METADATA_REFLECTION_H__ */