Permalink
Browse files

Tue Jan 22 22:43:47 CET 2002 Paolo Molaro <lupus@ximian.com>

	* class.c: load also nested classes on class init.
	System.ValueType instance methods gets passed boxed
	values, unless methods in derived classed that get a pointer to the
	data.
	* icall.c: use better name parsing code in GetType().
	* image.c, image.h: add mono_image_loaded ().
	* metadata.c, metadata.h: add mono_metadata_nesting_typedef ().
	* reflection.c, reflection.h: added mono_reflection_parse_type().

svn path=/trunk/mono/; revision=2094
  • Loading branch information...
1 parent 4b5634d commit 8cad5e83aeb716cd986dae2af47d9526c8b1609a @illupus illupus committed Jan 22, 2002
@@ -1,3 +1,15 @@
+
+Tue Jan 22 22:43:47 CET 2002 Paolo Molaro <lupus@ximian.com>
+
+ * class.c: load also nested classes on class init.
+ System.ValueType instance methods gets passed boxed
+ values, unless methods in derived classed that get a pointer to the
+ data.
+ * icall.c: use better name parsing code in GetType().
+ * image.c, image.h: add mono_image_loaded ().
+ * metadata.c, metadata.h: add mono_metadata_nesting_typedef ().
+ * reflection.c, reflection.h: added mono_reflection_parse_type().
+
2002-01-22 Veronica De Santis <veron78@interfree.it>
* icall.c : Added mapping of internal calls for Manual and Auto reset events
View
@@ -29,6 +29,8 @@
#define CSIZE(x) (sizeof (x) / 4)
+static MonoClass * mono_class_create_from_typedef (MonoImage *image, guint32 type_token);
+
static gpointer
default_trampoline (MonoMethod *method)
{
@@ -136,8 +138,10 @@ class_compute_field_layout (MonoClass *class)
if (class->enumtype && !(cols [MONO_FIELD_FLAGS] & FIELD_ATTRIBUTE_STATIC))
class->enum_basetype = class->fields [i].type;
}
- if (class->enumtype && !class->enum_basetype)
- G_BREAKPOINT ();
+ if (class->enumtype && !class->enum_basetype) {
+ if (!((strcmp (class->name, "Enum") == 0) && (strcmp (class->name_space, "System") == 0)))
+ G_BREAKPOINT ();
+ }
/*
* Compute field layout and total size.
*/
@@ -267,7 +271,7 @@ mono_class_init (MonoClass *class)
if (class->class_size)
class->data = g_malloc0 (class->class_size);
- /* initialize mothod pointers */
+ /* initialize method pointers */
class->methods = g_new (MonoMethod*, class->method.count);
for (i = 0; i < class->method.count; ++i)
class->methods [i] = mono_get_method (class->image,
@@ -479,6 +483,18 @@ mono_class_init (MonoClass *class)
init_properties (class);
+ i = mono_metadata_nesting_typedef (class->image, class->type_token);
+ while (i) {
+ MonoClass* nclass;
+ guint32 cols [MONO_NESTED_CLASS_SIZE];
+ mono_metadata_decode_row (&class->image->tables [MONO_TABLE_NESTEDCLASS], i - 1, cols, MONO_NESTED_CLASS_SIZE);
+ if (cols [MONO_NESTED_CLASS_ENCLOSING] != mono_metadata_token_index (class->type_token))
+ break;
+ nclass = mono_class_create_from_typedef (class->image, MONO_TOKEN_TYPE_DEF | cols [MONO_NESTED_CLASS_NESTED]);
+ class->nested_classes = g_list_prepend (class->nested_classes, nclass);
+ ++i;
+ }
+
mono_runtime_class_init (class);
/*
@@ -595,15 +611,21 @@ mono_class_create_from_typedef (MonoImage *image, guint32 type_token)
} else if (!(cols [0] & TYPE_ATTRIBUTE_INTERFACE)) {
int rnum = 0;
class->parent = mono_class_get (image, mono_metadata_token_from_dor (cols [3]));
- class->valuetype = class->parent->valuetype;
+ if ((strcmp (class->parent->name, "ValueType") == 0) && (strcmp (class->parent->name_space, "System") == 0))
+ class->valuetype = 1;
+ else
+ class->valuetype = class->parent->valuetype;
class->enumtype = class->parent->enumtype;
class->parent->subclasses = g_list_prepend (class->parent->subclasses, class);
mono_compute_relative_numbering (mono_defaults.object_class, &rnum);
}
if (!strcmp (nspace, "System")) {
if (!strcmp (name, "ValueType")) {
- class->valuetype = 1;
+ /*
+ * do not set the valuetype bit for System.ValueType.
+ * class->valuetype = 1;i
+ */
} else if (!strcmp (name, "Enum")) {
class->valuetype = 1;
class->enumtype = 1;
@@ -36,6 +36,7 @@ struct _MonoClass {
MonoClass *parent;
MonoClass *nested_in;
+ GList *nested_classes;
GList *subclasses; /* list of all subclasses */
const char *name;
View
@@ -190,6 +190,7 @@ static void
mono_type_type_from_obj (MonoReflectionType *mtype, MonoObject *obj)
{
mtype->type = &obj->klass->byval_arg;
+ g_assert (mtype->type->type);
}
static gint32
@@ -219,45 +220,51 @@ static MonoReflectionType*
ves_icall_type_from_name (MonoString *name)
{
MonoClass *klass;
- gchar *n, *namespace, *str;
- char* byref, *isarray;
- guint rank;
+ MonoImage *image;
+ MonoTypeNameParse info;
+ gchar *str;
- str = namespace = mono_string_to_utf8 (name);
+ str = mono_string_to_utf8 (name);
/*g_print ("requested type %s\n", str);*/
+ if (!mono_reflection_parse_type (str, &info)) {
+ g_free (str);
+ return NULL;
+ }
- n = strrchr (str, '.');
- byref = strrchr (str, '&');
- if (byref)
- *byref = 0;
- isarray = strrchr (str, '[');
- if (isarray) {
- rank = 1;
- *isarray = 0;
- while (*isarray) {
- if (*isarray == ',')
- rank++;
- if (*isarray == ']')
- break;
- ++isarray;
+ if (info.assembly) {
+ image = mono_image_loaded (info.assembly);
+ /* do we need to load if it's not already loaded? */
+ if (!image) {
+ g_free (str);
+ return NULL;
+ }
+ } else
+ image = mono_defaults.corlib;
+ if (info.nest_name) {
+ klass = mono_class_from_name (image, info.nest_name_space, info.nest_name);
+ if (klass) {
+ GList *nested;
+ mono_class_init (klass);
+ nested = klass->nested_classes;
+ while (nested) {
+ klass = nested->data;
+ if (strcmp (klass->name, info.nest_name) == 0 &&
+ strcmp (klass->name_space, info.nest_name_space) == 0)
+ break;
+ klass = NULL;
+ }
}
- }
- if (n) {
- *n = 0;
- ++n;
} else {
- namespace = "";
- n = str;
+ klass = mono_class_from_name (image, info.name_space, info.name);
}
- klass = mono_class_from_name (mono_defaults.corlib, namespace, n);
g_free (str);
if (!klass)
return NULL;
mono_class_init (klass);
- if (isarray)
- klass = mono_array_class_get (klass, rank);
+ if (info.rank)
+ klass = mono_array_class_get (klass, info.rank);
- if (byref)
+ if (info.isbyref || info.ispointer) /* hack */
return mono_type_get_object (&klass->this_arg);
else
return mono_type_get_object (&klass->byval_arg);
@@ -278,9 +285,10 @@ ves_icall_type_is_subtype_of (MonoReflectionType *type, MonoReflectionType *c)
g_assert (type != NULL);
+
if (!c) /* FIXME: dont know what do do here */
return 0;
-
+
while (!type->type) { /* FIXME: hack for TypeBuilder */
MonoReflectionTypeBuilder *tb = (MonoReflectionTypeBuilder *)type;
type = tb->parent;
@@ -680,7 +688,7 @@ ves_icall_System_Reflection_Assembly_GetType (MonoReflectionAssembly *assembly,
{
/* FIXME : use throwOnError and ignoreCase */
gchar *name, *namespace, *str;
- char *byref, *isarray;
+ char *byref, *isarray, *ispointer;
guint rank;
MonoClass *klass;
@@ -689,8 +697,11 @@ ves_icall_System_Reflection_Assembly_GetType (MonoReflectionAssembly *assembly,
name = strrchr (str, '.');
byref = strrchr (str, '&');
+ ispointer = strrchr (str, '*');
if (byref)
*byref = 0;
+ if (ispointer)
+ *ispointer = 0;
isarray = strrchr (str, '[');
if (isarray) {
rank = 1;
@@ -725,7 +736,7 @@ ves_icall_System_Reflection_Assembly_GetType (MonoReflectionAssembly *assembly,
/*g_print ("got array class %s [%d] (0x%x)\n", klass->element_class->name, klass->rank, klass->this_arg.type);*/
}
- if (byref)
+ if (byref || ispointer)
return mono_type_get_object (&klass->this_arg);
else
return mono_type_get_object (&klass->byval_arg);
@@ -872,7 +883,7 @@ static gpointer icall_map [] = {
"System.Type::get_constructor", ves_icall_get_constructor,
"System.Type::get_property", ves_icall_get_property,
"System.Type::get_method", ves_icall_get_method,
- "System.Type::get_attributes", ves_icall_get_attributes,
+ "System.MonoType::get_attributes", ves_icall_get_attributes,
"System.Type::type_is_subtype_of", ves_icall_type_is_subtype_of,
"System.Type::FindMembers", ves_icall_type_find_members,
@@ -528,6 +528,13 @@ do_mono_image_open (const char *fname, enum MonoImageOpenStatus *status)
return NULL;
}
+MonoImage *
+mono_image_loaded (const char *name) {
+ if (loaded_images_hash)
+ return g_hash_table_lookup (loaded_images_hash, name);
+ return NULL;
+}
+
/**
* mono_image_open:
* @fname: filename that points to the module we want to open
@@ -558,6 +565,7 @@ mono_image_open (const char *fname, enum MonoImageOpenStatus *status)
if (!loaded_images_hash)
loaded_images_hash = g_hash_table_new (g_str_hash, g_str_equal);
g_hash_table_insert (loaded_images_hash, image->name, image);
+ g_hash_table_insert (loaded_images_hash, image->assembly_name, image);
return image;
}
@@ -98,10 +98,10 @@ enum MonoImageOpenStatus {
MonoImage *mono_image_open (const char *fname,
enum MonoImageOpenStatus *status);
+MonoImage *mono_image_loaded (const char *name);
void mono_image_close (MonoImage *image);
const char *mono_image_strerror (enum MonoImageOpenStatus status);
-
int mono_image_ensure_section (MonoImage *image,
const char *section);
int mono_image_ensure_section_idx (MonoImage *image,
@@ -1750,6 +1750,36 @@ mono_metadata_nested_in_typedef (MonoMetadata *meta, guint32 index)
return mono_metadata_decode_row_col (tdef, loc.result, MONO_NESTED_CLASS_ENCLOSING) | MONO_TOKEN_TYPE_DEF;
}
+guint32
+mono_metadata_nesting_typedef (MonoMetadata *meta, guint32 index)
+{
+ MonoTableInfo *tdef = &meta->tables [MONO_TABLE_NESTEDCLASS];
+ locator_t loc;
+ guint32 start;
+
+ if (!tdef->base)
+ return 0;
+
+ loc.idx = mono_metadata_token_index (index);
+ loc.col_idx = MONO_NESTED_CLASS_ENCLOSING;
+ loc.t = tdef;
+
+ if (!bsearch (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator))
+ return 0;
+
+ start = loc.result;
+
+ while (start > 0) {
+ if (loc.idx == mono_metadata_decode_row_col (tdef, start - 1, MONO_NESTED_CLASS_ENCLOSING))
+ start--;
+ else
+ break;
+ }
+
+ /* loc_result is 0..1, needs to be mapped to table index (that is +1) */
+ return start + 1;
+}
+
#ifndef __GNUC__
#define __alignof__(a) sizeof(a)
#endif
@@ -112,6 +112,7 @@ const char *mono_metadata_user_string (MonoMetadata *meta, guint32 index);
guint32 mono_metadata_typedef_from_field (MonoMetadata *meta, guint32 index);
guint32 mono_metadata_typedef_from_method (MonoMetadata *meta, guint32 index);
guint32 mono_metadata_nested_in_typedef (MonoMetadata *meta, guint32 index);
+guint32 mono_metadata_nesting_typedef (MonoMetadata *meta, guint32 index);
MonoClass** mono_metadata_interfaces_from_typedef (MonoMetadata *meta, guint32 index, guint *count);
Oops, something went wrong.

0 comments on commit 8cad5e8

Please sign in to comment.