d7608ea067e1f096258469d5d2ef00f26eeae9a7
[mono.git] / mono / metadata / class.h
1 #ifndef _MONO_CLI_CLASS_H_
2 #define _MONO_CLI_CLASS_H_
3
4 #include <mono/metadata/metadata.h>
5 #include <mono/metadata/image.h>
6 #include <mono/metadata/loader.h>
7
8 #define MONO_CLASS_IS_ARRAY(c) ((c)->rank)
9
10 extern gboolean mono_print_vtable;
11
12 typedef struct {
13         MonoType *type;
14         int       offset;
15         const char     *name;
16         const char     *data;
17         /* add marshal data, too */
18 } MonoClassField;
19
20 typedef struct {
21         const char *name;
22         MonoMethod *get;
23         MonoMethod *set;
24         guint32 attrs;
25 } MonoProperty;
26
27 typedef struct {
28         const char *name;
29         MonoMethod *add;
30         MonoMethod *remove;
31         MonoMethod *raise;
32         MonoMethod **other;
33         guint32 attrs;
34 } MonoEvent;
35
36 struct _MonoClass {
37         MonoImage *image;
38         guint32    type_token;
39
40         guint dummy           : 1; /* temorary hack */
41         guint inited          : 1;
42         guint valuetype       : 1; /* derives from System.ValueType */
43         guint enumtype        : 1; /* derives from System.Enum */
44         guint ghcimpl         : 1; /* class has its own GetHashCode impl */ 
45         guint min_align       : 4;
46
47         MonoClass  *parent;
48         MonoClass  *nested_in;
49         GList      *nested_classes;
50         GList      *subclasses; /* list of all subclasses */
51
52         const char *name;
53         const char *name_space;
54         
55         guint       interface_count;
56         guint       interface_id;        /* unique inderface id (for interfaces) */
57         guint       max_interface_id;
58         gint       *interface_offsets;   
59         MonoClass **interfaces;
60
61         /*
62          * Computed object instance size, total.
63          */
64         int        instance_size;
65         int        class_size;
66         int        vtable_size; /* number of slots */
67
68         /*
69          * relative numbering for fast type checking
70          */
71         unsigned int baseval;
72         unsigned int diffval;
73
74         /*
75          * From the TypeDef table
76          */
77         guint32    flags;
78         struct {
79                 guint32 first, last;
80                 int count;
81         } field, method, property, event;
82
83         /*
84          * Field information: Type and location from object base
85          */
86         MonoClassField *fields;
87
88         MonoProperty *properties;
89         
90         MonoEvent *events;
91
92         MonoMethod **methods;
93
94         /* The underlying type of the enum */
95         MonoType *enum_basetype;
96         /* element class for arrays and enum */
97         MonoClass *element_class; 
98         /* array dimension */
99         guint32    rank;          
100
101         /* used as the type of the this argument and when passing the arg by value */
102         MonoType this_arg;
103         MonoType byval_arg;
104
105         void *reflection_info;
106
107         MonoMethod *vtable [0]; 
108 };
109
110 typedef struct {
111         MonoClass  *klass;
112         MonoDomain *domain;  /* each object/vtable belongs to exactly one domain */
113         gpointer   *interface_offsets;   
114         gpointer    data;
115         gpointer    vtable [0]; 
116 } MonoVTable;
117
118
119 typedef gpointer (*MonoTrampoline)       (MonoMethod *method);
120 typedef void     (*MonoRuntimeClassInit) (MonoClass *klass);
121
122 MonoClass *
123 mono_class_get             (MonoImage *image, guint32 type_token);
124
125 void
126 mono_class_init            (MonoClass *klass);
127
128 MonoVTable *
129 mono_class_vtable          (MonoDomain *domain, MonoClass *class);
130
131 void
132 mono_class_setup_mono_type (MonoClass *class);
133
134 void
135 mono_class_setup_parent    (MonoClass *class, MonoClass *parent);
136
137 MonoClass *
138 mono_class_from_name       (MonoImage *image, const char* name_space, const char *name);
139
140 MonoClassField*
141 mono_field_from_memberref  (MonoImage *image, guint32 token, MonoClass **retklass);
142
143 MonoClass *
144 mono_array_class_get       (MonoType *element_type, guint32 rank);
145
146 MonoClassField *
147 mono_class_get_field       (MonoClass *klass, guint32 field_token);
148
149 MonoClassField *
150 mono_class_get_field_from_name (MonoClass *klass, const char *name);
151
152 gint32
153 mono_array_element_size    (MonoClass *ac);
154
155 gint32
156 mono_class_instance_size   (MonoClass *klass);
157
158 gint32
159 mono_class_value_size      (MonoClass *klass, guint32 *align);
160
161 gint32
162 mono_class_data_size       (MonoClass *klass);
163
164 MonoClass *
165 mono_class_from_mono_type  (MonoType *type);
166
167 gpointer
168 mono_ldtoken               (MonoImage *image, guint32 token, MonoClass **retclass);
169
170 void
171 mono_install_trampoline (MonoTrampoline func);
172
173 void
174 mono_install_runtime_class_init (MonoRuntimeClassInit func);
175
176 #endif /* _MONO_CLI_CLASS_H_ */