(_MonoGenericContainer): ... here. Add into union with klass field.
* class.c, icall.c, loader.c, metadata.c, reflection.c: Update to changes.
svn path=/trunk/mono/; revision=70918
+2007-01-12 Raja R Harinath <rharinath@novell.com>
+
+ * class-internals.h (_MonoGenericParam.method): Move ...
+ (_MonoGenericContainer): ... here. Add into union with klass field.
+ * class.c, icall.c, loader.c, metadata.c, reflection.c:
+ Update to changes.
Fri Jan 12 11:58:52 CET 2007 Paolo Molaro <lupus@ximian.com>
MonoGenericContainer *parent;
/* If we're a generic method definition, caches all their instantiations. */
GHashTable *method_hash;
- /* If we're a generic type definition, its `MonoClass'. */
- MonoClass *klass;
+ /* the generic type definition or the generic method definition corresponding to this container */
+ union {
+ MonoClass *klass;
+ MonoMethod *method;
+ } owner;
int type_argc : 6;
/* If true, we're a generic method, otherwise a generic type definition. */
/* Invariant: parent != NULL => is_method */
struct _MonoGenericParam {
MonoGenericContainer *owner; /* Type or method this parameter was defined in. */
MonoClass *pklass; /* The corresponding `MonoClass'. */
- MonoMethod *method; /* If we're a method type parameter, the method. */
const char *name;
guint16 flags;
guint16 num;
{
MonoGenericClass *gclass;
+ g_assert (!container->is_method);
+
if (is_dynamic) {
MonoDynamicGenericClass *dgclass = g_new0 (MonoDynamicGenericClass, 1);
gclass = &dgclass->generic_class;
}
gclass->cached_context = &container->context;
- gclass->container_class = container->klass;
+ gclass->container_class = container->owner.klass;
gclass->inst = mono_get_shared_generic_inst (container);
if (!is_dynamic) {
}
}
- gclass->cached_class = container->klass;
+ gclass->cached_class = container->owner.klass;
return gclass;
}
*/
class->generic_container = mono_metadata_load_generic_params (image, class->type_token, NULL);
if (class->generic_container) {
- class->generic_container->klass = class;
+ class->generic_container->owner.klass = class;
context = &class->generic_container->context;
context->class_inst = mono_get_shared_generic_inst (class->generic_container);
klass->name_space = "";
- if (image)
- klass->image = image;
- else if (is_mvar && param->method && param->method->klass)
- klass->image = param->method->klass->image;
- else if (param->owner && param->owner->klass)
- klass->image = param->owner->klass->image;
- else
- klass->image = mono_defaults.corlib;
+ if (!image && param->owner) {
+ if (is_mvar) {
+ MonoMethod *method = param->owner->owner.method;
+ image = method->klass ? method->klass->image : NULL;
+ } else {
+ MonoClass *klass = param->owner->owner.klass;
+ image = klass->image;
+ }
+ }
+
+ if (!image)
+ image = mono_defaults.corlib;
+
+ klass->image = image;
klass->inited = TRUE;
klass->cast_class = klass->element_class = klass;
if (type->type->byref)
return NULL;
if (type->type->type == MONO_TYPE_VAR)
- class = type->type->data.generic_param->owner->klass;
+ class = type->type->data.generic_param->owner->owner.klass;
else if (type->type->type == MONO_TYPE_MVAR)
- class = type->type->data.generic_param->method->klass;
+ class = type->type->data.generic_param->owner->owner.method->klass;
else
class = mono_class_from_mono_type (type->type)->nested_in;
if (type->type->byref || type->type->type != MONO_TYPE_MVAR)
return NULL;
- method = type->type->data.generic_param->method;
+ method = type->type->data.generic_param->owner->owner.method;
g_assert (method);
klass = mono_class_from_mono_type (type->type);
return mono_method_get_object (mono_object_domain (type), method, klass);
container = klass->generic_container;
generic_container = mono_metadata_load_generic_params (image, token, container);
if (generic_container) {
- MonoGenericContext *context = &generic_container->context;
+ MonoGenericContext *context;
+
+ generic_container->owner.method = result;
+ context = &generic_container->context;
if (container)
context->class_inst = container->context.class_inst;
context->gmethod = mono_get_shared_generic_method (generic_container);
- mono_metadata_load_generic_param_constraints (image, token, generic_container);
- for (i = 0; i < generic_container->type_argc; i++) {
- generic_container->type_params [i].method = result;
+ mono_metadata_load_generic_param_constraints (image, token, generic_container);
- mono_class_from_generic_parameter (
- &generic_container->type_params [i], image, TRUE);
- }
+ for (i = 0; i < generic_container->type_argc; i++)
+ mono_class_from_generic_parameter (&generic_container->type_params [i], image, TRUE);
container = generic_container;
}
GList *cons = NULL, *tmp;
MonoGenericContext *context = &container->context;
- /* FIXME: !container->klass => this is probably monodis */
- g_assert (!container->klass || context->class_inst || context->gmethod);
-
*constraints = NULL;
found = 0;
for (i = 0; i < tdef->rows; ++i) {
params = g_realloc (params, sizeof (MonoGenericParam) * n);
params [n - 1].owner = container;
params [n - 1].pklass = NULL;
- params [n - 1].method = NULL;
params [n - 1].flags = cols [MONO_GENERICPARAM_FLAGS];
params [n - 1].num = cols [MONO_GENERICPARAM_NUMBER];
params [n - 1].name = mono_metadata_string_heap (image, cols [MONO_GENERICPARAM_NAME]);
if (mono_metadata_token_table (token) == MONO_TABLE_METHOD)
container->is_method = 1;
+ g_assert (container->parent == NULL || container->is_method);
+
return container;
}
return;
tb->generic_container = g_new0 (MonoGenericContainer, 1);
- tb->generic_container->klass = klass;
+ tb->generic_container->owner.klass = klass;
}
/*
if (klass->generic_container || (count == 0))
return;
- g_assert (tb->generic_container && (tb->generic_container->klass == klass));
+ g_assert (tb->generic_container && (tb->generic_container->owner.klass == klass));
klass->generic_container = tb->generic_container;
m->generic_container = container = rmb->generic_container;
container->type_argc = count;
container->type_params = g_new0 (MonoGenericParam, count);
+ container->owner.method = m;
for (i = 0; i < count; i++) {
MonoReflectionGenericParam *gp =
mono_array_get (rmb->generic_params, MonoReflectionGenericParam*, i);
container->type_params [i] = *gp->type.type->data.generic_param;
- container->type_params [i].method = m;
}
if (klass->generic_container) {
param->owner = gparam->tbuilder->generic_container;
}
- param->method = NULL;
param->name = mono_string_to_utf8 (gparam->name);
param->num = gparam->index;