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 MonoArray *permissions;
208 } MonoReflectionCtorBuilder;
213 MonoReflectionType *rtype;
214 MonoArray *parameters;
220 MonoReflectionILGen *ilgen;
224 MonoReflectionMethod *override_method;
226 MonoString *dllentry;
230 MonoBoolean init_locals;
231 MonoArray *generic_params;
232 MonoArray *return_modreq;
233 MonoArray *return_modopt;
234 MonoArray *param_modreq;
235 MonoArray *param_modopt;
236 MonoArray *permissions;
237 } MonoReflectionMethodBuilder;
242 MonoReflectionType *parent;
243 MonoReflectionType *ret;
244 MonoArray *parameters;
248 } MonoReflectionArrayMethod;
251 * Information which isn't in the MonoMethod structure is stored here for
256 MonoMarshalSpec **param_marshall;
257 } MonoReflectionMethodAux;
267 MonoAssembly assembly;
271 guint32 strong_name_size;
272 } MonoDynamicAssembly;
278 guint32 metadata_rva;
280 guint32 cli_header_offset;
284 guint32 imp_names_offset;
290 } sections [MONO_SECTION_MAX];
292 GHashTable *handleref;
293 MonoGHashTable *tokens;
294 MonoGHashTable *blob_cache;
295 GList *array_methods;
296 MonoGHashTable *token_fixups;
297 MonoGHashTable *method_to_table_idx;
298 MonoGHashTable *field_to_table_idx;
299 MonoGHashTable *method_aux_hash;
303 guint32 strong_name_size;
305 guint32 win32_res_size;
306 MonoDynamicStream pefile;
307 MonoDynamicStream sheap;
308 MonoDynamicStream code; /* used to store method headers and bytecode */
309 MonoDynamicStream resources; /* managed embedded resources */
310 MonoDynamicStream us;
311 MonoDynamicStream blob;
312 MonoDynamicStream tstream;
313 MonoDynamicStream guid;
314 MonoDynamicTable tables [64];
320 MonoString *filename;
323 } MonoReflectionResource;
330 } MonoReflectionWin32Resource;
335 } MonoReflectionPermissionSet;
338 MonoReflectionAssembly assembly;
339 MonoDynamicAssembly *dynamic_assembly;
340 MonoReflectionMethod *entry_point;
345 MonoArray *resources;
346 MonoArray *public_key;
352 MonoBoolean delay_sign;
354 MonoArray *loaded_modules;
355 MonoArray *win32_resources;
356 } MonoReflectionAssemblyBuilder;
361 MonoReflectionType *type;
363 MonoObject *def_value;
366 MonoReflectionType *typeb;
369 MonoReflectionMarshal *marshal_info;
370 MonoClassField *handle;
373 } MonoReflectionFieldBuilder;
379 MonoReflectionType *type;
380 MonoArray *parameters;
382 MonoObject *def_value;
383 MonoReflectionMethodBuilder *set_method;
384 MonoReflectionMethodBuilder *get_method;
386 } MonoReflectionPropertyBuilder;
391 MonoReflectionAssembly *assembly;
394 MonoString *scopename;
395 MonoBoolean is_resource;
396 } MonoReflectionModule;
399 MonoReflectionModule module;
400 MonoDynamicImage *dynamic_image;
406 MonoReflectionAssemblyBuilder *assemblyb;
407 MonoArray *global_methods;
408 MonoArray *global_fields;
410 MonoArray *resources;
411 } MonoReflectionModuleBuilder;
414 MonoReflectionType type;
417 MonoReflectionType *parent;
418 MonoReflectionType *nesting_type;
419 MonoArray *interfaces;
423 MonoArray *properties;
431 MonoReflectionModuleBuilder *module;
434 MonoArray *generic_params;
435 MonoArray *permissions;
436 } MonoReflectionTypeBuilder;
439 MonoReflectionType type;
444 MonoArray *constraints;
446 } MonoReflectionGenericParam;
448 typedef struct _MonoReflectionGenericInst MonoReflectionGenericInst;
449 struct _MonoReflectionGenericInst {
450 MonoReflectionType type;
452 MonoReflectionGenericInst *parent;
453 MonoReflectionType *generic_type;
454 MonoArray *interfaces;
461 MonoReflectionMethod rmethod;
462 MonoReflectionMethod *declaring;
463 MonoReflectionGenericInst *declaring_type;
464 MonoReflectionGenericInst *reflected_type;
465 MonoGenericInst *ginst;
466 } MonoReflectionInflatedMethod;
469 MonoReflectionField rfield;
470 MonoClassField *declaring;
471 MonoReflectionGenericInst *declaring_type;
472 MonoReflectionGenericInst *reflected_type;
473 } MonoReflectionInflatedField;
478 MonoString *codebase;
479 gint32 major, minor, build, revision;
480 /* FIXME: add missing stuff */
481 /* CultureInfo cultureinfo;
482 AssemblyNameFlags flags;
483 AssemblyHashAlgorithm hashalg;
484 StrongNameKeyPair keypair;
485 AssemblyVersionCompatibility versioncompat;*/
486 MonoObject *cultureInfo;
490 MonoArray *publicKey;
492 MonoObject *versioncompat;
493 } MonoReflectionAssemblyName;
498 MonoReflectionType *type;
499 MonoReflectionTypeBuilder *typeb;
501 MonoReflectionMethodBuilder *add_method;
502 MonoReflectionMethodBuilder *remove_method;
503 MonoReflectionMethodBuilder *raise_method;
504 MonoArray *other_methods;
507 } MonoReflectionEventBuilder;
511 MonoReflectionMethod *ctor;
513 } MonoReflectionCustomAttr;
519 MonoReflectionType *rtype;
520 MonoArray *parameters;
523 MonoReflectionModule *module;
524 MonoBoolean skip_visibility;
525 MonoBoolean init_locals;
526 MonoReflectionILGen *ilgen;
529 } MonoReflectionDynamicMethod;
531 typedef struct MonoTypeNameParse MonoTypeNameParse;
533 struct MonoTypeNameParse {
536 MonoAssemblyName assembly;
537 GList *modifiers; /* 0 -> byref, -1 -> pointer, > 0 -> array rank */
543 MonoReflectionModuleBuilder *module;
544 MonoArray *arguments;
546 MonoReflectionType *return_type;
548 guint32 unmanaged_call_conv;
549 } MonoReflectionSigHelper;
555 } MonoCustomAttrEntry;
560 MonoCustomAttrEntry attrs [MONO_ZERO_LEN_ARRAY];
561 } MonoCustomAttrInfo;
564 RESOURCE_LOCATION_EMBEDDED = 1,
565 RESOURCE_LOCATION_ANOTHER_ASSEMBLY = 2,
566 RESOURCE_LOCATION_IN_MANIFEST = 4
571 MonoReflectionAssembly *assembly;
572 MonoString *filename;
574 } MonoManifestResourceInfo;
576 int mono_reflection_parse_type (char *name, MonoTypeNameParse *info);
577 MonoType* mono_reflection_get_type (MonoImage* image, MonoTypeNameParse *info, gboolean ignorecase);
578 MonoType* mono_reflection_type_from_name (char *name, MonoImage *image);
580 void mono_image_create_pefile (MonoReflectionModuleBuilder *module);
581 void mono_image_basic_init (MonoReflectionAssemblyBuilder *assembly);
582 MonoReflectionModule * mono_image_load_module (MonoReflectionAssemblyBuilder *assembly, MonoString *file_name);
583 guint32 mono_image_insert_string (MonoReflectionModuleBuilder *module, MonoString *str);
584 guint32 mono_image_create_token (MonoDynamicImage *assembly, MonoObject *obj);
585 void mono_image_module_basic_init (MonoReflectionModuleBuilder *module);
587 MonoReflectionAssembly* mono_assembly_get_object (MonoDomain *domain, MonoAssembly *assembly);
588 MonoReflectionModule* mono_module_get_object (MonoDomain *domain, MonoImage *image);
589 MonoReflectionModule* mono_module_file_get_object (MonoDomain *domain, MonoImage *image, int table_index);
590 MonoReflectionType* mono_type_get_object (MonoDomain *domain, MonoType *type);
591 MonoReflectionMethod* mono_method_get_object (MonoDomain *domain, MonoMethod *method, MonoClass *refclass);
592 MonoReflectionField* mono_field_get_object (MonoDomain *domain, MonoClass *klass, MonoClassField *field);
593 MonoReflectionProperty* mono_property_get_object (MonoDomain *domain, MonoClass *klass, MonoProperty *property);
594 MonoReflectionEvent* mono_event_get_object (MonoDomain *domain, MonoClass *klass, MonoEvent *event);
595 /* note: this one is slightly different: we keep the whole array of params in the cache */
596 MonoArray* mono_param_get_objects (MonoDomain *domain, MonoMethod *method);
598 MonoArray* mono_reflection_get_custom_attrs (MonoObject *obj);
599 MonoArray* mono_reflection_get_custom_attrs_blob (MonoObject *ctor, MonoArray *ctorArgs, MonoArray *properties, MonoArray *porpValues, MonoArray *fields, MonoArray* fieldValues);
601 MonoArray* mono_custom_attrs_construct (MonoCustomAttrInfo *cinfo);
602 MonoCustomAttrInfo* mono_custom_attrs_from_index (MonoImage *image, guint32 idx);
603 MonoCustomAttrInfo* mono_custom_attrs_from_method (MonoMethod *method);
604 MonoCustomAttrInfo* mono_custom_attrs_from_class (MonoClass *klass);
605 MonoCustomAttrInfo* mono_custom_attrs_from_assembly (MonoAssembly *assembly);
606 MonoCustomAttrInfo* mono_custom_attrs_from_property (MonoClass *klass, MonoProperty *property);
607 MonoCustomAttrInfo* mono_custom_attrs_from_event (MonoClass *klass, MonoEvent *event);
608 MonoCustomAttrInfo* mono_custom_attrs_from_field (MonoClass *klass, MonoClassField *field);
609 MonoCustomAttrInfo* mono_custom_attrs_from_param (MonoMethod *method, guint32 param);
610 void mono_custom_attrs_free (MonoCustomAttrInfo *ainfo);
612 void mono_reflection_setup_internal_class (MonoReflectionTypeBuilder *tb);
614 void mono_reflection_create_internal_class (MonoReflectionTypeBuilder *tb);
616 void mono_reflection_setup_generic_class (MonoReflectionTypeBuilder *tb);
618 MonoReflectionType* mono_reflection_create_runtime_class (MonoReflectionTypeBuilder *tb);
620 void mono_reflection_create_dynamic_method (MonoReflectionDynamicMethod *m);
622 MonoReflectionGenericParam *mono_reflection_define_generic_parameter (MonoReflectionTypeBuilder *tb, MonoReflectionMethodBuilder *mb, MonoString *name, guint32 index);
623 void mono_reflection_initialize_generic_parameter (MonoReflectionGenericParam *gparam);
625 MonoReflectionGenericInst*
626 mono_reflection_bind_generic_parameters (MonoReflectionType *type, MonoArray *types);
627 MonoReflectionInflatedMethod*
628 mono_reflection_bind_generic_method_parameters (MonoReflectionMethod *method, MonoArray *types);
629 MonoReflectionInflatedMethod*
630 mono_reflection_inflate_method_or_ctor (MonoReflectionGenericInst *declaring_type, MonoReflectionGenericInst *reflected_type, MonoObject *obj);
631 MonoReflectionInflatedField*
632 mono_reflection_inflate_field (MonoReflectionGenericInst *declaring_type, MonoReflectionGenericInst *reflected_type, MonoObject *obj);
634 MonoArray *mono_reflection_sighelper_get_signature_local (MonoReflectionSigHelper *sig);
636 MonoArray *mono_reflection_sighelper_get_signature_field (MonoReflectionSigHelper *sig);
639 mono_reflection_lookup_dynamic_token (MonoImage *image, guint32 token);
642 mono_image_build_metadata (MonoReflectionModuleBuilder *module);
644 #endif /* __METADATA_REFLECTION_H__ */