Skip to content

Commit

Permalink
In mono/dis:
Browse files Browse the repository at this point in the history
	* get.c (mono_generic_params_with_ambiguous_names): New.
	(generic_containers): New. Hashtable of all generic containers that have
	been checked for ambiguous params.
	(check_ambiguous_genparams): New. Walk a MonoGenericContainer
	and fill mono_generic_params_with_ambiguous_names table.
	(is_ambiguous_generic_param): New. Check whether a MonoGenericParam has
	ambiguous names.
	(dis_stringify_type): Use new is_ambiguous_generic_param to determine
	whether to print number or name for VAR/MVAR.

In mono/metadata:
	* metadata.c (mono_metadata_load_generic_params): Move the code
	checking for ambiguous generic params from here to mono/dis/get.c
	* metadata-internals.h (mono_generic_params_with_ambiguous_names): Remove.


svn path=/trunk/mono/; revision=57084


Commit migrated from mono/mono@144a3b8
  • Loading branch information
radical committed Feb 21, 2006
1 parent dbd807f commit 4ab0b6b
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 26 deletions.
65 changes: 63 additions & 2 deletions src/mono/mono/dis/get.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ get_memberref_context (MonoImage *m, guint32 mrp_token, MonoGenericContext *cont

static char *
get_memberref_parent (MonoImage *m, guint32 mrp_token, MonoGenericContext *context);

static gboolean
can_print_generic_param_name (MonoGenericParam *gparam);

GHashTable *key_table = NULL;
GHashTable *mono_generic_params_with_ambiguous_names = NULL;
GHashTable *generic_containers = NULL;
gboolean show_method_tokens = FALSE;
gboolean show_tokens = FALSE;

Expand Down Expand Up @@ -1157,13 +1162,13 @@ dis_stringify_type (MonoImage *m, MonoType *type, gboolean is_def)
bare = g_strdup ("void");
break;
case MONO_TYPE_MVAR:
if (is_def && (!mono_generic_params_with_ambiguous_names || !g_hash_table_lookup (mono_generic_params_with_ambiguous_names, type->data.generic_param)))
if (is_def && !can_print_generic_param_name (type->data.generic_param))
bare = g_strdup_printf ("!!%s", get_escaped_name (type->data.generic_param->name));
else
bare = g_strdup_printf ("!!%d", type->data.generic_param->num);
break;
case MONO_TYPE_VAR:
if (is_def && (!mono_generic_params_with_ambiguous_names || !g_hash_table_lookup (mono_generic_params_with_ambiguous_names, type->data.generic_param)))
if (is_def && !can_print_generic_param_name (type->data.generic_param))
bare = g_strdup_printf ("!%s", get_escaped_name (type->data.generic_param->name));
else
bare = g_strdup_printf ("!%d", type->data.generic_param->num);
Expand Down Expand Up @@ -3010,3 +3015,59 @@ get_method_override (MonoImage *m, guint32 token, MonoGenericContext *context)

return NULL;
}

static void
check_ambiguous_genparams (MonoGenericContainer *container)
{
GSList *dup_list = NULL, *l;
GHashTable *table = NULL;
gpointer *p;
int i;

if (!container)
return;

if (generic_containers && g_hash_table_lookup (generic_containers, container))
/* Already been checked for ambiguous gen params */
return;

table = g_hash_table_new (g_str_hash, g_str_equal);
for (i = 0; i < container->type_argc; i++) {
MonoGenericParam *param = &container->type_params [i];

if ((p = g_hash_table_lookup (table, param->name)))
dup_list = g_slist_prepend (g_slist_prepend (dup_list, GUINT_TO_POINTER (i + 1)), p);
else
g_hash_table_insert (table, (char*)param->name, GUINT_TO_POINTER (i + 1));
}

if (dup_list) {
if (!mono_generic_params_with_ambiguous_names)
mono_generic_params_with_ambiguous_names = g_hash_table_new (NULL, NULL);
for (l = dup_list; l; l = l->next) {
int param = GPOINTER_TO_UINT (l->data);
g_hash_table_insert (mono_generic_params_with_ambiguous_names,
&container->type_params [param-1],
&container->type_params [param-1]);
}
g_slist_free (dup_list);
}

if (!generic_containers)
generic_containers = g_hash_table_new (NULL, NULL);

g_hash_table_insert (generic_containers, container, container);
g_hash_table_destroy (table);
}

static gboolean
can_print_generic_param_name (MonoGenericParam *gparam)
{
g_assert (gparam);

check_ambiguous_genparams (gparam->owner);
return (!gparam->owner || (mono_generic_params_with_ambiguous_names &&
g_hash_table_lookup (mono_generic_params_with_ambiguous_names, gparam)));
}


2 changes: 0 additions & 2 deletions src/mono/mono/metadata/metadata-internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,6 @@ typedef struct _MonoAssemblyBindingInfo {
/* for use with allocated memory blocks (assumes alignment is to 8 bytes) */
guint mono_aligned_addr_hash (gconstpointer ptr);

extern GHashTable *mono_generic_params_with_ambiguous_names;

const char * mono_meta_table_name (int table);
void mono_metadata_compute_table_bases (MonoImage *meta);

Expand Down
22 changes: 0 additions & 22 deletions src/mono/mono/metadata/metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ static gboolean mono_metadata_class_equal (MonoClass *c1, MonoClass *c2, gboolea
static gboolean _mono_metadata_generic_class_equal (const MonoGenericClass *g1, const MonoGenericClass *g2,
gboolean signature_only);

GHashTable *mono_generic_params_with_ambiguous_names;

/*
* This enumeration is used to describe the data types in the metadata
* tables
Expand Down Expand Up @@ -4221,16 +4219,12 @@ mono_metadata_load_generic_params (MonoImage *image, guint32 token, MonoGenericC
guint32 i, owner = 0, n;
MonoGenericContainer *container;
MonoGenericParam *params;
gpointer *p;
GSList *dup_list = NULL, *l;
GHashTable *table = NULL;

if (!(i = mono_metadata_get_generic_param_row (image, token, &owner)))
return NULL;
mono_metadata_decode_row (tdef, i - 1, cols, MONO_GENERICPARAM_SIZE);
params = NULL;
n = 0;
table = g_hash_table_new (g_str_hash, g_str_equal);
container = g_new0 (MonoGenericContainer, 1);
do {
n++;
Expand All @@ -4241,28 +4235,12 @@ mono_metadata_load_generic_params (MonoImage *image, guint32 token, MonoGenericC
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 ((p = g_hash_table_lookup (table, params [n - 1].name)))
dup_list = g_slist_prepend (g_slist_prepend (dup_list, GUINT_TO_POINTER (n)), p);
else
g_hash_table_insert (table, (char*)params [n - 1].name, GUINT_TO_POINTER (n));
params [n - 1].constraints = NULL;
if (++i > tdef->rows)
break;
mono_metadata_decode_row (tdef, i - 1, cols, MONO_GENERICPARAM_SIZE);
} while (cols [MONO_GENERICPARAM_OWNER] == owner);

if (dup_list) {
if (!mono_generic_params_with_ambiguous_names)
mono_generic_params_with_ambiguous_names = g_hash_table_new (NULL, NULL);
for (l = dup_list; l; l = l->next) {
int param = GPOINTER_TO_UINT (l->data);
g_hash_table_insert (mono_generic_params_with_ambiguous_names, &params [param-1], &params [param-1]);
}
g_slist_free (dup_list);
}
g_hash_table_destroy (table);
table = NULL;

container->type_argc = n;
container->type_params = params;
container->parent = parent_container;
Expand Down

0 comments on commit 4ab0b6b

Please sign in to comment.