* class.h (MonoGenericMethod): New type.
(MonoGenericInst): Remove `mtype_argc', `mtype_argv' and
`generic_method'.
* metadata.h (MonoMethodHeader): Replaced the `geninst' field with
a `MonoGenericMethod *gen_method' one.
* class.c (mono_class_inflate_generic_type): Take an additional
`MonoGenericMethod * argument. This is only non-NULL if we're
inflating types for a generic method.
(mono_class_inflate_generic_signature): Renamed to
inflate_generic_signature() and made static; take a
`MonoGenericMethod *' argument instead of a `MonoGenericInst *'.
(inflate_generic_header): Take a `MonoGenericMethod *' argument
instead of a `MonoGenericInst *' one.
(mono_class_inflate_generic_method): Likewise.
* reflection.c (encode_generic_method_sig): Take a
`MonoGenericMethod *' argument instead of a `MonoGenericInst *'.
(method_encode_methodspec): Likewise.
(inflated_method_get_object): Likewise.
* reflection.h (MonoReflectionGenericInst): Replaced the `ginst'
field with a `MonoGenericMethod *gmethod' one.
svn path=/trunk/mono/; revision=22919
+2004-02-09 Martin Baulig <martin@ximian.com>
+
+ * class.h (MonoGenericMethod): New type.
+ (MonoGenericInst): Remove `mtype_argc', `mtype_argv' and
+ `generic_method'.
+
+ * metadata.h (MonoMethodHeader): Replaced the `geninst' field with
+ a `MonoGenericMethod *gen_method' one.
+
+ * class.c (mono_class_inflate_generic_type): Take an additional
+ `MonoGenericMethod * argument. This is only non-NULL if we're
+ inflating types for a generic method.
+ (mono_class_inflate_generic_signature): Renamed to
+ inflate_generic_signature() and made static; take a
+ `MonoGenericMethod *' argument instead of a `MonoGenericInst *'.
+ (inflate_generic_header): Take a `MonoGenericMethod *' argument
+ instead of a `MonoGenericInst *' one.
+ (mono_class_inflate_generic_method): Likewise.
+
+ * reflection.c (encode_generic_method_sig): Take a
+ `MonoGenericMethod *' argument instead of a `MonoGenericInst *'.
+ (method_encode_methodspec): Likewise.
+ (inflated_method_get_object): Likewise.
+
+ * reflection.h (MonoReflectionGenericInst): Replaced the `ginst'
+ field with a `MonoGenericMethod *gmethod' one.
+
2004-02-08 Bernie Solomon <bernard@ugsolutions.com>
* class.h (mono_class_has_parent): add parens to expansion
}
MonoType*
-mono_class_inflate_generic_type (MonoType *type, MonoGenericInst *ginst)
+mono_class_inflate_generic_type (MonoType *type, MonoGenericInst *ginst,
+ MonoGenericMethod *gmethod)
{
switch (type->type) {
case MONO_TYPE_MVAR:
- if (ginst && ginst->mtype_argv)
- return dup_type (ginst->mtype_argv [type->data.generic_param->num]);
+ if (gmethod && gmethod->mtype_argv)
+ return dup_type (gmethod->mtype_argv [type->data.generic_param->num]);
else
return type;
- case MONO_TYPE_VAR: {
- MonoType *t = ginst->type_argv [type->data.generic_param->num];
-
- if ((t->type == MONO_TYPE_VAR) || (t->type == MONO_TYPE_MVAR))
+ case MONO_TYPE_VAR:
+ if (ginst) {
+ MonoType *t = ginst->type_argv [type->data.generic_param->num];
+
+ if ((t->type == MONO_TYPE_VAR) || (t->type == MONO_TYPE_MVAR))
+ return type;
+ else
+ return dup_type (t);
+ } else
return type;
- else
- return dup_type (t);
- }
case MONO_TYPE_SZARRAY: {
MonoClass *eclass = type->data.klass;
MonoClass *nclass;
MonoType *nt;
- if (eclass->byval_arg.type == MONO_TYPE_MVAR) {
- nclass = mono_class_from_mono_type (ginst->type_argv [eclass->byval_arg.data.generic_param->num]);
- } else if (eclass->byval_arg.type == MONO_TYPE_VAR) {
+ if ((eclass->byval_arg.type == MONO_TYPE_MVAR) && gmethod) {
+ nclass = mono_class_from_mono_type (gmethod->mtype_argv [eclass->byval_arg.data.generic_param->num]);
+ } else if ((eclass->byval_arg.type == MONO_TYPE_VAR) && ginst) {
nclass = mono_class_from_mono_type (ginst->type_argv [eclass->byval_arg.data.generic_param->num]);
} else {
return type;
for (i = 0; i < oginst->type_argc; i++) {
MonoType *t = oginst->type_argv [i];
- nginst->type_argv [i] = mono_class_inflate_generic_type (t, ginst);
+ nginst->type_argv [i] = mono_class_inflate_generic_type (t, ginst, gmethod);
};
nt = dup_type (type);
return type;
}
-MonoMethodSignature*
-mono_class_inflate_generic_signature (MonoImage *image, MonoMethodSignature *sig, MonoGenericInst *ginst)
+static MonoMethodSignature*
+inflate_generic_signature (MonoImage *image, MonoMethodSignature *sig,
+ MonoGenericMethod *gmethod)
{
MonoMethodSignature *res;
int i;
res = mono_metadata_signature_alloc (image, sig->param_count);
- res->ret = mono_class_inflate_generic_type (sig->ret, ginst);
- for (i = 0; i < sig->param_count; ++i) {
- res->params [i] = mono_class_inflate_generic_type (sig->params [i], ginst);
- }
+ res->ret = mono_class_inflate_generic_type (sig->ret, gmethod->generic_inst, gmethod);
+ for (i = 0; i < sig->param_count; ++i)
+ res->params [i] = mono_class_inflate_generic_type (sig->params [i],
+ gmethod->generic_inst,
+ gmethod);
res->hasthis = sig->hasthis;
res->explicit_this = sig->explicit_this;
res->call_convention = sig->call_convention;
}
static MonoMethodHeader*
-inflate_generic_header (MonoMethodHeader *header, MonoGenericInst *ginst)
+inflate_generic_header (MonoMethodHeader *header, MonoGenericMethod *gmethod)
{
MonoMethodHeader *res;
int i;
res->num_locals = header->num_locals;
res->clauses = header->clauses;
res->gen_params = header->gen_params;
- res->geninst = ginst;
- for (i = 0; i < header->num_locals; ++i) {
- res->locals [i] = mono_class_inflate_generic_type (header->locals [i], ginst);
- }
+ res->gen_method = gmethod;
+ for (i = 0; i < header->num_locals; ++i)
+ res->locals [i] = mono_class_inflate_generic_type (header->locals [i],
+ gmethod->generic_inst,
+ gmethod);
return res;
}
MonoMethod*
-mono_class_inflate_generic_method (MonoMethod *method, MonoGenericInst *ginst)
+mono_class_inflate_generic_method (MonoMethod *method, MonoGenericMethod *gmethod)
{
MonoMethod *result;
if ((method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) || (method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL)) {
*nmethod = *(MonoMethodNormal*)method;
result = (MonoMethod*)nmethod;
if (nmethod->header)
- nmethod->header = inflate_generic_header (nmethod->header, ginst);
+ nmethod->header = inflate_generic_header (nmethod->header, gmethod);
}
- if (ginst->klass)
- result->klass = ginst->klass;
- result->signature = mono_class_inflate_generic_signature (method->klass->image, result->signature, ginst);
+ result->klass = gmethod->klass;
+ result->signature = inflate_generic_signature (
+ method->klass->image, result->signature, gmethod);
return result;
}
if (mono_field_is_deleted (field))
continue;
if (class->generic_inst) {
- field->type = mono_class_inflate_generic_type (field->type, class->generic_inst);
+ field->type = mono_class_inflate_generic_type (field->type, class->generic_inst, NULL);
field->type->attrs = cols [MONO_FIELD_FLAGS];
}
klass->field = gklass->field;
klass->method = gklass->method;
klass->methods = g_new0 (MonoMethod *, klass->method.count);
- for (i = 0; i < klass->method.count; i++)
- klass->methods [i] = mono_class_inflate_generic_method (gklass->methods [i], ginst);
+
+ for (i = 0; i < klass->method.count; i++) {
+ MonoGenericMethod *gmethod = g_new0 (MonoGenericMethod, 1);
+
+ gmethod->klass = klass;
+ gmethod->generic_method = gklass->methods [i];
+ gmethod->generic_inst = ginst;
+
+ klass->methods [i] = mono_class_inflate_generic_method (
+ gklass->methods [i], gmethod);
+ }
}
ginst->initialized = TRUE;
MonoType *parent;
MonoType **ifaces;
MonoType *generic_type;
- MonoMethod *generic_method;
int type_argc;
MonoType **type_argv;
- int mtype_argc;
- MonoType **mtype_argv;
guint is_open : 1;
guint initialized : 1;
guint init_pending : 1;
};
+struct _MonoGenericMethod {
+ MonoGenericInst *generic_inst;
+ MonoClass *klass;
+ MonoMethod *generic_method;
+ int mtype_argc;
+ MonoType **mtype_argv;
+ guint is_open : 1;
+};
+
struct _MonoGenericParam {
MonoClass *pklass;
MonoMethod *method;
mono_class_from_generic (MonoGenericInst *ginst);
MonoType*
-mono_class_inflate_generic_type (MonoType *type, MonoGenericInst *ginst);
-
-MonoMethodSignature*
-mono_class_inflate_generic_signature (MonoImage *image, MonoMethodSignature *sig, MonoGenericInst *ginst);
+mono_class_inflate_generic_type (MonoType *type, MonoGenericInst *ginst, MonoGenericMethod *gmethod);
MonoMethod*
-mono_class_inflate_generic_method (MonoMethod *method, MonoGenericInst *ginst);
+mono_class_inflate_generic_method (MonoMethod *method, MonoGenericMethod *gmethod);
MonoClassField*
mono_field_from_memberref (MonoImage *image, guint32 token, MonoClass **retklass);
!(method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL) &&
method->signature);
mn = (MonoMethodNormal *) method;
- g_assert (mn->header->geninst);
+ g_assert (mn->header->gen_method);
return method->signature;
}
method = find_method (klass, mname, sig);
if (!method)
g_warning ("Missing method %s in assembly %s typeref index %d", mname, image->name, nindex);
- else if (klass->generic_inst)
- method = mono_class_inflate_generic_method (method, klass->generic_inst);
+ else if (klass->generic_inst) {
+ MonoGenericMethod *gmethod = g_new0 (MonoGenericMethod, 1);
+
+ gmethod->klass = klass;
+ gmethod->generic_method = method;
+ gmethod->generic_inst = klass->generic_inst;
+
+ method = mono_class_inflate_generic_method (method, gmethod);
+ }
mono_metadata_free_method_signature (sig);
return method;
}
{
MonoMethod *method;
MonoTableInfo *tables = image->tables;
- MonoGenericInst *ginst;
+ MonoGenericMethod *gmethod;
const char *ptr;
guint32 cols [MONO_METHODSPEC_SIZE];
guint32 token, param_count, i;
ptr++;
param_count = mono_metadata_decode_value (ptr, &ptr);
- ginst = g_new0 (MonoGenericInst, 1);
- ginst->generic_method = method;
- ginst->mtype_argc = param_count;
- ginst->mtype_argv = g_new0 (MonoType *, param_count);
+ gmethod = g_new0 (MonoGenericMethod, 1);
+ gmethod->klass = method->klass;
+ gmethod->generic_method = method;
+ gmethod->mtype_argc = param_count;
+ gmethod->mtype_argv = g_new0 (MonoType *, param_count);
for (i = 0; i < param_count; i++) {
- ginst->mtype_argv [i] = mono_metadata_parse_type (image, MONO_PARSE_TYPE, 0, ptr, &ptr);
+ gmethod->mtype_argv [i] = mono_metadata_parse_type (image, MONO_PARSE_TYPE, 0, ptr, &ptr);
- if (!ginst->is_open)
- ginst->is_open = mono_class_is_open_constructed_type (ginst->mtype_argv [i]);
+ if (!gmethod->is_open)
+ gmethod->is_open = mono_class_is_open_constructed_type (gmethod->mtype_argv [i]);
}
- return mono_class_inflate_generic_method (method, ginst);
+ return mono_class_inflate_generic_method (method, gmethod);
}
typedef struct MonoDllMap MonoDllMap;
typedef struct _MonoType MonoType;
typedef struct _MonoGenericInst MonoGenericInst;
+typedef struct _MonoGenericMethod MonoGenericMethod;
typedef struct _MonoGenericParam MonoGenericParam;
typedef struct _MonoArrayType MonoArrayType;
typedef struct _MonoMethodSignature MonoMethodSignature;
guint16 num_locals;
MonoExceptionClause *clauses;
MonoGenericParam *gen_params;
- MonoGenericInst *geninst;
+ MonoGenericMethod *gen_method;
MonoType *locals [MONO_ZERO_LEN_ARRAY];
} MonoMethodHeader;
}
static guint32
-encode_generic_method_sig (MonoDynamicImage *assembly, MonoGenericInst *ginst)
+encode_generic_method_sig (MonoDynamicImage *assembly, MonoGenericMethod *gmethod)
{
char *buf;
char *p;
int i;
- guint32 nparams = ginst->mtype_argc;
+ guint32 nparams = gmethod->mtype_argc;
guint32 size = 10 + nparams * 10;
guint32 idx;
char blob_size [6];
mono_metadata_encode_value (nparams, p, &p);
for (i = 0; i < nparams; i++)
- encode_type (assembly, ginst->mtype_argv [i], p, &p);
+ encode_type (assembly, gmethod->mtype_argv [i], p, &p);
/* store length */
g_assert (p - buf < size);
}
static guint32
-method_encode_methodspec (MonoDynamicImage *assembly, MonoMethod *method, MonoGenericInst *ginst)
+method_encode_methodspec (MonoDynamicImage *assembly, MonoMethod *method,
+ MonoGenericMethod *gmethod)
{
MonoDynamicTable *table;
guint32 *values;
table = &assembly->tables [MONO_TABLE_METHODSPEC];
- g_assert (ginst);
- k = ginst->klass ? ginst->klass : method->klass;
+ g_assert (gmethod);
+ k = gmethod->klass ? gmethod->klass : method->klass;
sig = method_encode_signature (assembly, method->signature);
mtoken = mono_image_get_memberref_token (assembly, &k->byval_arg, method->name, sig);
g_assert_not_reached ();
}
- sig = encode_generic_method_sig (assembly, ginst);
+ sig = encode_generic_method_sig (assembly, gmethod);
if (assembly->save) {
alloc_table (table, table->rows + 1);
if (token)
return token;
if (m->declaring->method->signature->generic_param_count)
- token = method_encode_methodspec (assembly, m->declaring->method, m->ginst);
+ token = method_encode_methodspec (assembly, m->declaring->method, m->gmethod);
else {
MonoClass *k;
guint32 sig;
- g_assert (m->ginst);
- k = m->ginst->klass ? m->ginst->klass : m->ginst->generic_method->klass;
+ g_assert (m->gmethod);
+ k = m->gmethod->klass ? m->gmethod->klass : m->gmethod->generic_method->klass;
sig = method_encode_signature (assembly, m->declaring->method->signature);
token = mono_image_get_memberref_token (
- assembly, &k->byval_arg, m->ginst->generic_method->name, sig);
+ assembly, &k->byval_arg, m->gmethod->generic_method->name, sig);
}
g_hash_table_insert (assembly->handleref, m->rmethod.method, GUINT_TO_POINTER(token));
static MonoReflectionInflatedMethod*
inflated_method_get_object (MonoDomain *domain, MonoMethod *method, MonoClass *refclass,
- MonoReflectionMethod *declaring, MonoGenericInst *ginst)
+ MonoReflectionMethod *declaring, MonoGenericMethod *gmethod)
{
const char *cname;
MonoClass *klass;
ret->rmethod.name = mono_string_new (domain, method->name);
ret->rmethod.reftype = mono_type_get_object (domain, &refclass->byval_arg);
ret->declaring = declaring;
- ret->ginst = ginst;
+ ret->gmethod = gmethod;
CACHE_OBJECT (method, ret, refclass);
return ret;
}
MonoMethod *method, *inflated;
MonoReflectionMethodBuilder *mb = NULL;
MonoReflectionMethod *declaring;
- MonoGenericInst *ginst;
+ MonoGenericMethod *gmethod;
int count, i;
MONO_ARCH_SAVE_REGS;
if (count != mono_array_length (types))
return NULL;
- ginst = g_new0 (MonoGenericInst, 1);
- ginst->generic_method = method;
- ginst->mtype_argc = count;
- ginst->mtype_argv = g_new0 (MonoType *, count);
+ gmethod = g_new0 (MonoGenericMethod, 1);
+ gmethod->generic_method = method;
+ gmethod->mtype_argc = count;
+ gmethod->mtype_argv = g_new0 (MonoType *, count);
for (i = 0; i < count; i++) {
MonoReflectionType *garg = mono_array_get (types, gpointer, i);
- ginst->mtype_argv [i] = garg->type;
+ gmethod->mtype_argv [i] = garg->type;
}
- if (method->klass->generic_inst) {
- MonoGenericInst *kginst = method->klass->generic_inst;
-
- ginst->type_argc = kginst->type_argc;
- ginst->type_argv = kginst->type_argv;
- }
+ gmethod->generic_inst = method->klass->generic_inst;
+ gmethod->klass = method->klass;
- inflated = mono_class_inflate_generic_method (method, ginst);
+ inflated = mono_class_inflate_generic_method (method, gmethod);
return inflated_method_get_object (
- mono_object_domain (rmethod), inflated, NULL, declaring, ginst);
+ mono_object_domain (rmethod), inflated, NULL, declaring, gmethod);
}
MonoReflectionInflatedMethod*
MonoReflectionGenericInst *reflected_type,
MonoObject *obj)
{
- MonoGenericInst *ginst, *type_ginst;
MonoMethod *method = NULL, *inflated;
MonoReflectionInflatedMethod *res;
MonoReflectionMethod *declaring;
MonoClass *klass, *refclass;
+ MonoGenericMethod *gmethod;
+ MonoGenericInst *ginst;
MONO_ARCH_SAVE_REGS;
klass = mono_class_from_mono_type (declaring_type->type.type);
refclass = mono_class_from_mono_type (reflected_type->type.type);
- type_ginst = declaring_type->type.type->data.generic_inst;
+ ginst = declaring_type->type.type->data.generic_inst;
if (!strcmp (obj->vtable->klass->name, "MethodBuilder")) {
method = methodbuilder_to_mono_method (klass, (MonoReflectionMethodBuilder *) obj);
} else
g_assert_not_reached ();
- ginst = g_new0 (MonoGenericInst, 1);
- ginst->generic_method = method;
- ginst->generic_type = declaring_type->type.type;
- ginst->type_argc = type_ginst->type_argc;
- ginst->type_argv = type_ginst->type_argv;
- ginst->is_open = type_ginst->is_open;
-
- ginst->klass = type_ginst->klass;
+ gmethod = g_new0 (MonoGenericMethod, 1);
+ gmethod->generic_method = method;
+ gmethod->generic_inst = ginst;
+ gmethod->klass = ginst->klass;
- inflated = mono_class_inflate_generic_method (method, ginst);
+ inflated = mono_class_inflate_generic_method (method, gmethod);
res = inflated_method_get_object (
- mono_object_domain (declaring_type), inflated, refclass, declaring, ginst);
+ mono_object_domain (declaring_type), inflated, refclass, declaring, gmethod);
return res;
}
inflated = g_new0 (MonoClassField, 1);
*inflated = *field;
- inflated->type = mono_class_inflate_generic_type (field->type, ginst);
+ inflated->type = mono_class_inflate_generic_type (field->type, ginst, NULL);
domain = mono_object_domain (obj);
typedef struct {
MonoReflectionMethod rmethod;
MonoReflectionMethod *declaring;
- MonoGenericInst *ginst;
+ MonoGenericMethod *gmethod;
} MonoReflectionInflatedMethod;
typedef struct {
#define TYPE_PARAM_TO_TYPE(num) (method->klass->generic_inst->type_argv [(num)])
#define TYPE_PARAM_TO_CLASS(num) (mono_class_from_mono_type (TYPE_PARAM_TO_TYPE ((num))))
-#define MTYPE_PARAM_TO_TYPE(num) (((MonoMethodNormal *) method)->header->geninst->mtype_argv [(num)])
+#define MTYPE_PARAM_TO_TYPE(num) (((MonoMethodNormal *) method)->header->gen_method->mtype_argv [(num)])
#define MTYPE_PARAM_TO_CLASS(num) (mono_class_from_mono_type (MTYPE_PARAM_TO_TYPE ((num))))
res = g_new0 (MonoClassField, 1);
*res = *field;
ginst = klass->generic_inst;
- res->type = mono_class_inflate_generic_type (field->type, ginst);
+ res->type = mono_class_inflate_generic_type (field->type, ginst, NULL);
return res;
}