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