2005-04-06 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mono / metadata / reflection.h
1 #ifndef __METADATA_REFLECTION_H__
2 #define __METADATA_REFLECTION_H__
3
4 #include <mono/metadata/object.h>
5
6 typedef struct MonoTypeNameParse MonoTypeNameParse;
7
8 struct MonoTypeNameParse {
9         char *name_space;
10         char *name;
11         MonoAssemblyName assembly;
12         GList *modifiers; /* 0 -> byref, -1 -> pointer, > 0 -> array rank */
13         GList *nested;
14 };
15
16 typedef struct {
17         MonoMethod *ctor;
18         guint32     data_size;
19         const guchar* data;
20 } MonoCustomAttrEntry;
21
22 typedef struct {
23         int num_attrs;
24         int cached;
25         MonoImage *image;
26         MonoCustomAttrEntry attrs [MONO_ZERO_LEN_ARRAY];
27 } MonoCustomAttrInfo;
28
29 /* 
30  * Information which isn't in the MonoMethod structure is stored here for
31  * dynamic methods.
32  */
33 typedef struct {
34         char **param_names;
35         MonoMarshalSpec **param_marshall;
36         MonoCustomAttrInfo **param_cattr;
37         guint8** param_defaults;
38         char *dllentry, *dll;
39 } MonoReflectionMethodAux;
40
41 typedef enum {
42         ResolveTokenError_OutOfRange,
43         ResolveTokenError_BadTable,
44         ResolveTokenError_Other
45 } MonoResolveTokenError;
46
47 int           mono_reflection_parse_type (char *name, MonoTypeNameParse *info);
48 MonoType*     mono_reflection_get_type   (MonoImage* image, MonoTypeNameParse *info, gboolean ignorecase, gboolean *type_resolve);
49 MonoType*     mono_reflection_type_from_name (char *name, MonoImage *image);
50 guint32       mono_reflection_get_token (MonoObject *obj);
51
52 MonoReflectionAssembly* mono_assembly_get_object (MonoDomain *domain, MonoAssembly *assembly);
53 MonoReflectionModule*   mono_module_get_object   (MonoDomain *domain, MonoImage *image);
54 MonoReflectionModule*   mono_module_file_get_object (MonoDomain *domain, MonoImage *image, int table_index);
55 MonoReflectionType*     mono_type_get_object     (MonoDomain *domain, MonoType *type);
56 MonoReflectionMethod*   mono_method_get_object   (MonoDomain *domain, MonoMethod *method, MonoClass *refclass);
57 MonoReflectionField*    mono_field_get_object    (MonoDomain *domain, MonoClass *klass, MonoClassField *field);
58 MonoReflectionProperty* mono_property_get_object (MonoDomain *domain, MonoClass *klass, MonoProperty *property);
59 MonoReflectionEvent*    mono_event_get_object    (MonoDomain *domain, MonoClass *klass, MonoEvent *event);
60 /* note: this one is slightly different: we keep the whole array of params in the cache */
61 MonoArray* mono_param_get_objects  (MonoDomain *domain, MonoMethod *method);
62 MonoReflectionMethodBody* mono_method_body_get_object (MonoDomain *domain, MonoMethod *method);
63 MonoObject* mono_get_dbnull_object (MonoDomain *domain);
64
65 MonoArray*  mono_reflection_get_custom_attrs (MonoObject *obj);
66 MonoArray*  mono_reflection_get_custom_attrs_blob (MonoReflectionAssembly *assembly, MonoObject *ctor, MonoArray *ctorArgs, MonoArray *properties, MonoArray *porpValues, MonoArray *fields, MonoArray* fieldValues);
67
68 MonoCustomAttrInfo* mono_reflection_get_custom_attrs_info (MonoObject *obj);
69 MonoArray*  mono_custom_attrs_construct (MonoCustomAttrInfo *cinfo);
70 MonoCustomAttrInfo* mono_custom_attrs_from_index    (MonoImage *image, guint32 idx);
71 MonoCustomAttrInfo* mono_custom_attrs_from_method   (MonoMethod *method);
72 MonoCustomAttrInfo* mono_custom_attrs_from_class    (MonoClass *klass);
73 MonoCustomAttrInfo* mono_custom_attrs_from_assembly (MonoAssembly *assembly);
74 MonoCustomAttrInfo* mono_custom_attrs_from_property (MonoClass *klass, MonoProperty *property);
75 MonoCustomAttrInfo* mono_custom_attrs_from_event    (MonoClass *klass, MonoEvent *event);
76 MonoCustomAttrInfo* mono_custom_attrs_from_field    (MonoClass *klass, MonoClassField *field);
77 MonoCustomAttrInfo* mono_custom_attrs_from_param    (MonoMethod *method, guint32 param);
78 gboolean            mono_custom_attrs_has_attr      (MonoCustomAttrInfo *ainfo, MonoClass *attr_klass);
79 MonoObject*         mono_custom_attrs_get_attr      (MonoCustomAttrInfo *ainfo, MonoClass *attr_klass);
80 void                mono_custom_attrs_free          (MonoCustomAttrInfo *ainfo);
81
82
83 #define MONO_DECLSEC_ACTION_MIN         0x1
84 #define MONO_DECLSEC_ACTION_MAX         0x12
85
86 enum {
87         MONO_DECLSEC_FLAG_REQUEST                       = 0x00000001,
88         MONO_DECLSEC_FLAG_DEMAND                        = 0x00000002,
89         MONO_DECLSEC_FLAG_ASSERT                        = 0x00000004,
90         MONO_DECLSEC_FLAG_DENY                          = 0x00000008,
91         MONO_DECLSEC_FLAG_PERMITONLY                    = 0x00000010,
92         MONO_DECLSEC_FLAG_LINKDEMAND                    = 0x00000020,
93         MONO_DECLSEC_FLAG_INHERITANCEDEMAND             = 0x00000040,
94         MONO_DECLSEC_FLAG_REQUEST_MINIMUM               = 0x00000080,
95         MONO_DECLSEC_FLAG_REQUEST_OPTIONAL              = 0x00000100,
96         MONO_DECLSEC_FLAG_REQUEST_REFUSE                = 0x00000200,
97         MONO_DECLSEC_FLAG_PREJIT_GRANT                  = 0x00000400,
98         MONO_DECLSEC_FLAG_PREJIT_DENY                   = 0x00000800,
99         MONO_DECLSEC_FLAG_NONCAS_DEMAND                 = 0x00001000,
100         MONO_DECLSEC_FLAG_NONCAS_LINKDEMAND             = 0x00002000,
101         MONO_DECLSEC_FLAG_NONCAS_INHERITANCEDEMAND      = 0x00004000,
102         MONO_DECLSEC_FLAG_LINKDEMAND_CHOICE             = 0x00008000,
103         MONO_DECLSEC_FLAG_INHERITANCEDEMAND_CHOICE      = 0x00010000,
104         MONO_DECLSEC_FLAG_DEMAND_CHOICE                 = 0x00020000
105 };
106
107 guint32 mono_declsec_flags_from_method (MonoMethod *method);
108 guint32 mono_declsec_flags_from_class (MonoClass *klass);
109 guint32 mono_declsec_flags_from_assembly (MonoAssembly *assembly);
110
111 /* this structure MUST be kept in synch with RuntimeDeclSecurityEntry
112  * located in /mcs/class/corlib/System.Security/SecurityFrame.cs */
113 typedef struct {
114         char *blob;                             /* pointer to metadata blob */
115         guint32 size;                           /* size of the metadata blob */
116         guint32 index;
117 } MonoDeclSecurityEntry;
118
119 typedef struct {
120         MonoDeclSecurityEntry demand;
121         MonoDeclSecurityEntry noncasdemand;
122         MonoDeclSecurityEntry demandchoice;
123 } MonoDeclSecurityActions;
124
125 MonoBoolean mono_declsec_get_demands (MonoMethod *callee, MonoDeclSecurityActions* demands);
126 MonoBoolean mono_declsec_get_linkdemands (MonoMethod *callee, MonoDeclSecurityActions* klass, MonoDeclSecurityActions* cmethod);
127 MonoBoolean mono_declsec_get_inheritdemands_class (MonoClass *klass, MonoDeclSecurityActions* demands);
128 MonoBoolean mono_declsec_get_inheritdemands_method (MonoMethod *callee, MonoDeclSecurityActions* demands);
129
130 MonoBoolean mono_declsec_get_method_action (MonoMethod *method, guint32 action, MonoDeclSecurityEntry *entry);
131 MonoBoolean mono_declsec_get_class_action (MonoClass *klass, guint32 action, MonoDeclSecurityEntry *entry);
132 MonoBoolean mono_declsec_get_assembly_action (MonoAssembly *assembly, guint32 action, MonoDeclSecurityEntry *entry);
133
134 #endif /* __METADATA_REFLECTION_H__ */