2002-03-12 Dietmar Maurer <dietmar@ximian.com>
[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 init_pending    : 1;
43         guint size_inited     : 1;
44         guint valuetype       : 1; /* derives from System.ValueType */
45         guint enumtype        : 1; /* derives from System.Enum */
46         guint ghcimpl         : 1; /* class has its own GetHashCode impl */ 
47         guint min_align       : 4;
48
49         MonoClass  *parent;
50         MonoClass  *nested_in;
51         GList      *nested_classes;
52         GList      *subclasses; /* list of all subclasses */
53
54         const char *name;
55         const char *name_space;
56         
57         guint       interface_count;
58         guint       interface_id;        /* unique inderface id (for interfaces) */
59         guint       max_interface_id;
60         gint       *interface_offsets;   
61         MonoClass **interfaces;
62
63         /*
64          * Computed object instance size, total.
65          */
66         int        instance_size;
67         int        class_size;
68         int        vtable_size; /* number of slots */
69
70         /*
71          * relative numbering for fast type checking
72          */
73         unsigned int baseval;
74         unsigned int diffval;
75
76         /*
77          * From the TypeDef table
78          */
79         guint32    flags;
80         struct {
81                 guint32 first, last;
82                 int count;
83         } field, method, property, event;
84
85         /*
86          * Field information: Type and location from object base
87          */
88         MonoClassField *fields;
89
90         MonoProperty *properties;
91         
92         MonoEvent *events;
93
94         MonoMethod **methods;
95
96         /* The underlying type of the enum */
97         MonoType *enum_basetype;
98         /* element class for arrays and enum */
99         MonoClass *element_class; 
100         /* array dimension */
101         guint32    rank;          
102
103         /* used as the type of the this argument and when passing the arg by value */
104         MonoType this_arg;
105         MonoType byval_arg;
106
107         void *reflection_info;
108
109         MonoMethod *vtable [0]; 
110 };
111
112 typedef struct {
113         MonoClass  *klass;
114         MonoDomain *domain;  /* each object/vtable belongs to exactly one domain */
115         gpointer   *interface_offsets;   
116         gpointer    data;
117         gpointer    vtable [0]; 
118 } MonoVTable;
119
120
121 typedef gpointer (*MonoTrampoline)       (MonoMethod *method);
122 typedef void     (*MonoRuntimeClassInit) (MonoClass *klass);
123
124 MonoClass *
125 mono_class_get             (MonoImage *image, guint32 type_token);
126
127 void
128 mono_class_init            (MonoClass *klass);
129
130 MonoVTable *
131 mono_class_vtable          (MonoDomain *domain, MonoClass *class);
132
133 void
134 mono_class_setup_mono_type (MonoClass *class);
135
136 void
137 mono_class_setup_parent    (MonoClass *class, MonoClass *parent);
138
139 MonoClass *
140 mono_class_from_name       (MonoImage *image, const char* name_space, const char *name);
141
142 MonoClassField*
143 mono_field_from_memberref  (MonoImage *image, guint32 token, MonoClass **retklass);
144
145 MonoClass *
146 mono_array_class_get       (MonoType *element_type, guint32 rank);
147
148 MonoClassField *
149 mono_class_get_field       (MonoClass *klass, guint32 field_token);
150
151 MonoClassField *
152 mono_class_get_field_from_name (MonoClass *klass, const char *name);
153
154 gint32
155 mono_array_element_size    (MonoClass *ac);
156
157 gint32
158 mono_class_instance_size   (MonoClass *klass);
159
160 gint32
161 mono_class_value_size      (MonoClass *klass, guint32 *align);
162
163 gint32
164 mono_class_data_size       (MonoClass *klass);
165
166 MonoClass *
167 mono_class_from_mono_type  (MonoType *type);
168
169 gpointer
170 mono_ldtoken               (MonoImage *image, guint32 token, MonoClass **retclass);
171
172 void
173 mono_install_trampoline (MonoTrampoline func);
174
175 void
176 mono_install_runtime_class_init (MonoRuntimeClassInit func);
177
178 #endif /* _MONO_CLI_CLASS_H_ */