+ /* reserve space to store vector pointer in arrays */
+ if (!strcmp (nspace, "System") && !strcmp (name, "Array")) {
+ class->instance_size += 2 * sizeof (gpointer);
+ g_assert (class->field.count == 0);
+ }
+
+ class->interfaces = mono_metadata_interfaces_from_typedef (image, type_token);
+ return class;
+}
+
+MonoClass *
+mono_class_from_mono_type (MonoType *type)
+{
+ switch (type->type) {
+ case MONO_TYPE_OBJECT:
+ return mono_defaults.object_class;
+ case MONO_TYPE_VOID:
+ return mono_defaults.void_class;
+ case MONO_TYPE_BOOLEAN:
+ return mono_defaults.boolean_class;
+ case MONO_TYPE_CHAR:
+ return mono_defaults.char_class;
+ case MONO_TYPE_I1:
+ return mono_defaults.byte_class;
+ case MONO_TYPE_U1:
+ return mono_defaults.sbyte_class;
+ case MONO_TYPE_I2:
+ return mono_defaults.int16_class;
+ case MONO_TYPE_U2:
+ return mono_defaults.uint16_class;
+ case MONO_TYPE_I4:
+ return mono_defaults.int32_class;
+ case MONO_TYPE_U4:
+ return mono_defaults.uint32_class;
+ case MONO_TYPE_I:
+ return mono_defaults.int_class;
+ case MONO_TYPE_U:
+ return mono_defaults.uint_class;
+ case MONO_TYPE_I8:
+ return mono_defaults.int64_class;
+ case MONO_TYPE_U8:
+ return mono_defaults.uint64_class;
+ case MONO_TYPE_R4:
+ return mono_defaults.single_class;
+ case MONO_TYPE_R8:
+ return mono_defaults.double_class;
+ case MONO_TYPE_STRING:
+ return mono_defaults.string_class;
+ case MONO_TYPE_ARRAY:
+ return mono_defaults.array_class;
+ case MONO_TYPE_SZARRAY:
+ case MONO_TYPE_PTR:
+ /* Not really sure about these. */
+ return mono_class_from_mono_type (type->data.type);
+ case MONO_TYPE_CLASS:
+ case MONO_TYPE_VALUETYPE:
+ return type->data.klass;
+ default:
+ g_warning ("implement me %02x\n", type->type);
+ g_assert_not_reached ();
+ }
+
+ return NULL;
+}
+
+/**
+ * @image: context where the image is created
+ * @type_spec: typespec token
+ * @at: an optional pointer to return the array type
+ */
+static MonoClass *
+mono_class_create_from_typespec (MonoImage *image, guint32 type_spec)
+{
+ guint32 idx = mono_metadata_token_index (type_spec);
+ MonoTableInfo *t;
+ guint32 cols [MONO_TYPESPEC_SIZE];
+ const char *ptr;
+ guint32 len;
+ MonoType *type;
+ MonoClass *class, *eclass;
+
+ t = &image->tables [MONO_TABLE_TYPESPEC];
+
+ mono_metadata_decode_row (t, idx-1, cols, MONO_TYPESPEC_SIZE);
+ ptr = mono_metadata_blob_heap (image, cols [MONO_TYPESPEC_SIGNATURE]);
+ len = mono_metadata_decode_value (ptr, &ptr);
+ type = mono_metadata_parse_type (image, MONO_PARSE_TYPE, 0, ptr, &ptr);
+
+ switch (type->type) {
+ case MONO_TYPE_ARRAY:
+ eclass = mono_class_from_mono_type (type->data.array->type);
+ class = mono_array_class_get (eclass, type->data.array->rank);
+ break;
+ case MONO_TYPE_SZARRAY:
+ eclass = mono_class_from_mono_type (type->data.type);
+ class = mono_array_class_get (eclass, 1);
+ break;
+ default:
+ g_warning ("implement me: %08x", type->type);
+ g_assert_not_reached ();