2002-02-05 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->type_token == 0)
9
10 #define MONO_CLASS_STATIC_FIELDS_BASE(c) (c->data)
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 struct _MonoClass {
28         MonoImage *image;
29         guint32    type_token;
30
31         guint dummy           : 1; /* temorary hack */
32         guint inited          : 1;
33         guint valuetype       : 1; /* derives from System.ValueType */
34         guint enumtype        : 1; /* derives from System.Enum */
35         guint min_align       : 4;
36
37         MonoClass  *parent;
38         MonoClass  *nested_in;
39         GList      *nested_classes;
40         GList      *subclasses; /* list of all subclasses */
41
42         const char *name;
43         const char *name_space;
44         
45         guint       interface_id; /* unique inderface id (for interfaces) */
46         guint       max_interface_id;
47         gpointer   *interface_offsets;
48         guint       interface_count;
49         MonoClass **interfaces;
50
51         /*
52          * Computed object instance size, total.
53          */
54         int        instance_size;
55         int        class_size;
56         int        vtable_size; /* number of slots */
57
58         /*
59          * relative numbering for fast type checking
60          */
61         unsigned int baseval;
62         unsigned int diffval;
63
64         /*
65          * From the TypeDef table
66          */
67         guint32    flags;
68         struct {
69                 guint32 first, last;
70                 int count;
71         } field, method, property;
72
73         /*
74          * Field information: Type and location from object base
75          */
76         MonoClassField *fields;
77
78         MonoProperty *properties;
79
80         MonoMethod **methods;
81
82         /* The underlying type of the enum */
83         MonoType *enum_basetype;
84         /* element class for arrays and enum */
85         MonoClass *element_class; 
86         /* array dimension */
87         guint32    rank;          
88
89         /* used as the type of the this argument and when passing the arg by value */
90         MonoType this_arg;
91         MonoType byval_arg;
92         
93         gpointer data;
94
95         gpointer vtable [0];
96 };
97
98 typedef gpointer (*MonoTrampoline)       (MonoMethod *method);
99 typedef void     (*MonoRuntimeClassInit) (MonoClass *klass);
100
101 MonoClass *
102 mono_class_get             (MonoImage *image, guint32 type_token);
103
104 void
105 mono_class_init            (MonoClass *klass);
106
107 MonoClass *
108 mono_class_from_name       (MonoImage *image, const char* name_space, const char *name);
109
110 MonoClassField*
111 mono_field_from_memberref  (MonoImage *image, guint32 token, MonoClass **retklass);
112
113 MonoClass *
114 mono_array_class_get       (MonoClass *eclass, guint32 rank);
115
116 MonoClassField *
117 mono_class_get_field       (MonoClass *klass, guint32 field_token);
118
119 MonoClassField *
120 mono_class_get_field_from_name (MonoClass *klass, const char *name);
121
122 gint32
123 mono_array_element_size    (MonoClass *ac);
124
125 gint32
126 mono_class_instance_size   (MonoClass *klass);
127
128 gint32
129 mono_class_value_size      (MonoClass *klass, guint32 *align);
130
131 gint32
132 mono_class_data_size       (MonoClass *klass);
133
134 MonoClass *
135 mono_class_from_mono_type  (MonoType *type);
136
137 gpointer
138 mono_ldtoken               (MonoImage *image, guint32 token, MonoClass **retclass);
139
140 void
141 mono_install_trampoline (MonoTrampoline func);
142
143 void
144 mono_install_runtime_class_init (MonoRuntimeClassInit func);
145
146 #endif /* _MONO_CLI_CLASS_H_ */