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