Skip to content

Commit

Permalink
2005-02-02 Zoltan Varga <vargaz@freemail.hu>
Browse files Browse the repository at this point in the history
	* loader.c (mono_method_get_index): New helper function.

	* loader.c reflection.c: Use mono_method_get_index ().

svn path=/trunk/mono/; revision=39975
  • Loading branch information
vargaz committed Feb 2, 2005
1 parent 3361135 commit 5a7ced8
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 88 deletions.
4 changes: 4 additions & 0 deletions mono/metadata/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
2005-02-02 Zoltan Varga <vargaz@freemail.hu>

* loader.c (mono_method_get_index): New helper function.

* loader.c reflection.c: Use mono_method_get_index ().

* class.c (mono_class_get_method_from_name_flags): New helper method.

* debug-helpers.h debug-helpers.c (mono_find_method_by_name): Remove
Expand Down
125 changes: 66 additions & 59 deletions mono/metadata/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,7 @@ mono_method_get_param_names (MonoMethod *method, const char **names)
MonoClass *klass = method->klass;
MonoTableInfo *methodt;
MonoTableInfo *paramt;
guint32 idx;

if (!mono_method_signature (method)->param_count)
return;
Expand All @@ -1024,32 +1025,30 @@ mono_method_get_param_names (MonoMethod *method, const char **names)

methodt = &klass->image->tables [MONO_TABLE_METHOD];
paramt = &klass->image->tables [MONO_TABLE_PARAM];
for (i = 0; i < klass->method.count; ++i) {
if (method == klass->methods [i]) {
guint32 idx = klass->method.first + i;
guint32 cols [MONO_PARAM_SIZE];
guint param_index = mono_metadata_decode_row_col (methodt, idx, MONO_METHOD_PARAMLIST);
idx = mono_method_get_index (method);
if (idx > 0) {
guint32 cols [MONO_PARAM_SIZE];
guint param_index = mono_metadata_decode_row_col (methodt, idx - 1, MONO_METHOD_PARAMLIST);

if (idx + 1 < methodt->rows)
lastp = mono_metadata_decode_row_col (methodt, idx + 1, MONO_METHOD_PARAMLIST);
else
lastp = paramt->rows + 1;
for (i = param_index; i < lastp; ++i) {
mono_metadata_decode_row (paramt, i -1, cols, MONO_PARAM_SIZE);
if (cols [MONO_PARAM_SEQUENCE]) /* skip return param spec */
names [cols [MONO_PARAM_SEQUENCE] - 1] = mono_metadata_string_heap (klass->image, cols [MONO_PARAM_NAME]);
}
return;
if (idx < methodt->rows)
lastp = mono_metadata_decode_row_col (methodt, idx, MONO_METHOD_PARAMLIST);
else
lastp = paramt->rows + 1;
for (i = param_index; i < lastp; ++i) {
mono_metadata_decode_row (paramt, i -1, cols, MONO_PARAM_SIZE);
if (cols [MONO_PARAM_SEQUENCE]) /* skip return param spec */
names [cols [MONO_PARAM_SEQUENCE] - 1] = mono_metadata_string_heap (klass->image, cols [MONO_PARAM_NAME]);
}
return;
}
}

guint32
mono_method_get_param_token (MonoMethod *method, int index)
{
int i;
MonoClass *klass = method->klass;
MonoTableInfo *methodt;
guint32 idx;

if (klass->generic_class)
g_assert_not_reached ();
Expand All @@ -1061,13 +1060,11 @@ mono_method_get_param_token (MonoMethod *method, int index)
}

methodt = &klass->image->tables [MONO_TABLE_METHOD];
for (i = 0; i < klass->method.count; ++i) {
if (method == klass->methods [i]) {
guint32 idx = klass->method.first + i;
guint param_index = mono_metadata_decode_row_col (methodt, idx, MONO_METHOD_PARAMLIST);
idx = mono_method_get_index (method);
if (idx > 0) {
guint param_index = mono_metadata_decode_row_col (methodt, idx - 1, MONO_METHOD_PARAMLIST);

return mono_metadata_make_token (MONO_TABLE_PARAM, param_index + index);
}
return mono_metadata_make_token (MONO_TABLE_PARAM, param_index + index);
}

return 0;
Expand All @@ -1080,6 +1077,7 @@ mono_method_get_marshal_info (MonoMethod *method, MonoMarshalSpec **mspecs)
MonoClass *klass = method->klass;
MonoTableInfo *methodt;
MonoTableInfo *paramt;
guint32 idx;

for (i = 0; i < mono_method_signature (method)->param_count + 1; ++i)
mspecs [i] = NULL;
Expand All @@ -1103,31 +1101,28 @@ mono_method_get_marshal_info (MonoMethod *method, MonoMarshalSpec **mspecs)

methodt = &klass->image->tables [MONO_TABLE_METHOD];
paramt = &klass->image->tables [MONO_TABLE_PARAM];
idx = mono_method_get_index (method);
if (idx > 0) {
guint32 cols [MONO_PARAM_SIZE];
guint param_index = mono_metadata_decode_row_col (methodt, idx - 1, MONO_METHOD_PARAMLIST);

for (i = 0; i < klass->method.count; ++i) {
if (method == klass->methods [i]) {
guint32 idx = klass->method.first + i;
guint32 cols [MONO_PARAM_SIZE];
guint param_index = mono_metadata_decode_row_col (methodt, idx, MONO_METHOD_PARAMLIST);

if (idx + 1 < methodt->rows)
lastp = mono_metadata_decode_row_col (methodt, idx + 1, MONO_METHOD_PARAMLIST);
else
lastp = paramt->rows + 1;
if (idx < methodt->rows)
lastp = mono_metadata_decode_row_col (methodt, idx, MONO_METHOD_PARAMLIST);
else
lastp = paramt->rows + 1;

for (i = param_index; i < lastp; ++i) {
mono_metadata_decode_row (paramt, i -1, cols, MONO_PARAM_SIZE);
for (i = param_index; i < lastp; ++i) {
mono_metadata_decode_row (paramt, i -1, cols, MONO_PARAM_SIZE);

if (cols [MONO_PARAM_FLAGS] & PARAM_ATTRIBUTE_HAS_FIELD_MARSHAL) {
const char *tp;
tp = mono_metadata_get_marshal_info (klass->image, i - 1, FALSE);
g_assert (tp);
mspecs [cols [MONO_PARAM_SEQUENCE]]= mono_metadata_parse_marshal_spec (klass->image, tp);
}
if (cols [MONO_PARAM_FLAGS] & PARAM_ATTRIBUTE_HAS_FIELD_MARSHAL) {
const char *tp;
tp = mono_metadata_get_marshal_info (klass->image, i - 1, FALSE);
g_assert (tp);
mspecs [cols [MONO_PARAM_SEQUENCE]]= mono_metadata_parse_marshal_spec (klass->image, tp);
}

return;
}

return;
}
}

Expand All @@ -1138,6 +1133,7 @@ mono_method_has_marshal_info (MonoMethod *method)
MonoClass *klass = method->klass;
MonoTableInfo *methodt;
MonoTableInfo *paramt;
guint32 idx;

if (method->klass->image->dynamic) {
MonoReflectionMethodAux *method_aux =
Expand All @@ -1156,26 +1152,23 @@ mono_method_has_marshal_info (MonoMethod *method)

methodt = &klass->image->tables [MONO_TABLE_METHOD];
paramt = &klass->image->tables [MONO_TABLE_PARAM];
idx = mono_method_get_index (method);
if (idx > 0) {
guint32 cols [MONO_PARAM_SIZE];
guint param_index = mono_metadata_decode_row_col (methodt, idx - 1, MONO_METHOD_PARAMLIST);

if (idx + 1 < methodt->rows)
lastp = mono_metadata_decode_row_col (methodt, idx, MONO_METHOD_PARAMLIST);
else
lastp = paramt->rows + 1;

for (i = 0; i < klass->method.count; ++i) {
if (method == klass->methods [i]) {
guint32 idx = klass->method.first + i;
guint32 cols [MONO_PARAM_SIZE];
guint param_index = mono_metadata_decode_row_col (methodt, idx, MONO_METHOD_PARAMLIST);

if (idx + 1 < methodt->rows)
lastp = mono_metadata_decode_row_col (methodt, idx + 1, MONO_METHOD_PARAMLIST);
else
lastp = paramt->rows + 1;

for (i = param_index; i < lastp; ++i) {
mono_metadata_decode_row (paramt, i -1, cols, MONO_PARAM_SIZE);
for (i = param_index; i < lastp; ++i) {
mono_metadata_decode_row (paramt, i -1, cols, MONO_PARAM_SIZE);

if (cols [MONO_PARAM_FLAGS] & PARAM_ATTRIBUTE_HAS_FIELD_MARSHAL)
return TRUE;
}
return FALSE;
if (cols [MONO_PARAM_FLAGS] & PARAM_ATTRIBUTE_HAS_FIELD_MARSHAL)
return TRUE;
}
return FALSE;
}
return FALSE;
}
Expand Down Expand Up @@ -1377,4 +1370,18 @@ mono_method_get_flags (MonoMethod *method, guint32 *iflags)
return method->flags;
}

/*
* Find the method index in the metadata methodDef table.
*/
guint32
mono_method_get_index (MonoMethod *method) {
MonoClass *klass = method->klass;
int i;

for (i = 0; i < klass->method.count; ++i) {
if (method == klass->methods [i])
return klass->method.first + 1 + i;
}
return 0;
}

3 changes: 3 additions & 0 deletions mono/metadata/loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ mono_method_get_token (MonoMethod *method);
guint32
mono_method_get_flags (MonoMethod *method, guint32 *iflags);

guint32
mono_method_get_index (MonoMethod *method);

MonoImage *
mono_load_image (const char *fname, MonoImageOpenStatus *status);

Expand Down
36 changes: 7 additions & 29 deletions mono/metadata/reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -5673,7 +5673,7 @@ get_default_param_value_blobs (MonoMethod *method, char **blobs)
{
guint32 param_index, i, lastp, crow = 0;
guint32 param_cols [MONO_PARAM_SIZE], const_cols [MONO_CONSTANT_SIZE];
gint32 idx = -1;
gint32 idx;

MonoClass *klass = method->klass;
MonoImage *image = klass->image;
Expand Down Expand Up @@ -5703,13 +5703,7 @@ get_default_param_value_blobs (MonoMethod *method, char **blobs)
paramt = &klass->image->tables [MONO_TABLE_PARAM];
constt = &image->tables [MONO_TABLE_CONSTANT];

for (i = 0; i < klass->method.count; ++i) {
if (method == klass->methods [i]) {
idx = klass->method.first + i;
break;
}
}

idx = mono_method_get_index (method) - 1;
g_assert (idx != -1);

param_index = mono_metadata_decode_row_col (methodt, idx, MONO_METHOD_PARAMLIST);
Expand Down Expand Up @@ -6472,22 +6466,6 @@ free_param_data (MonoMethodSignature *sig, void **params) {
}
}

/*
* Find the method index in the metadata methodDef table.
* Later put these three helper methods in metadata and export them.
*/
static guint32
find_method_index (MonoMethod *method) {
MonoClass *klass = method->klass;
int i;

for (i = 0; i < klass->method.count; ++i) {
if (method == klass->methods [i])
return klass->method.first + 1 + i;
}
return 0;
}

/*
* Find the field index in the metadata FieldDef table.
*/
Expand Down Expand Up @@ -6696,7 +6674,7 @@ mono_custom_attrs_from_method (MonoMethod *method)

if (dynamic_custom_attrs && (cinfo = g_hash_table_lookup (dynamic_custom_attrs, method)))
return cinfo;
idx = find_method_index (method);
idx = mono_method_get_index (method);
idx <<= MONO_CUSTOM_ATTR_BITS;
idx |= MONO_CUSTOM_ATTR_METHODDEF;
return mono_custom_attrs_from_index (method->klass->image, idx);
Expand Down Expand Up @@ -6803,7 +6781,7 @@ mono_custom_attrs_from_param (MonoMethod *method, guint32 param)
}

image = method->klass->image;
method_index = find_method_index (method);
method_index = mono_method_get_index (method);
ca = &image->tables [MONO_TABLE_METHOD];

if (method->klass->generic_class || mono_method_signature (method)->generic_param_count) {
Expand Down Expand Up @@ -9011,7 +8989,7 @@ mono_declsec_flags_from_method (MonoMethod *method)
{
if (method->flags & METHOD_ATTRIBUTE_HAS_SECURITY) {
/* FIXME: No cache (for the moment) */
guint32 idx = find_method_index (method);
guint32 idx = mono_method_get_index (method);
idx <<= MONO_HAS_DECL_SECURITY_BITS;
idx |= MONO_HAS_DECL_SECURITY_METHODDEF;
return mono_declsec_get_flags (method->klass->image, idx);
Expand Down Expand Up @@ -9145,7 +9123,7 @@ mono_declsec_get_demands (MonoMethod *method, MonoDeclSecurityActions* demands)
mono_class_init (method->klass);
memset (demands, 0, sizeof (MonoDeclSecurityActions));

guint32 idx = find_method_index (method);
guint32 idx = mono_method_get_index (method);
idx <<= MONO_HAS_DECL_SECURITY_BITS;
idx |= MONO_HAS_DECL_SECURITY_METHODDEF;
result = fill_actions_from_index (image, idx, demands);
Expand Down Expand Up @@ -9204,7 +9182,7 @@ MonoBoolean
mono_declsec_get_method_action (MonoMethod *method, guint32 action, MonoDeclSecurityEntry *entry)
{
if (method->flags & METHOD_ATTRIBUTE_HAS_SECURITY) {
guint32 idx = find_method_index (method);
guint32 idx = mono_method_get_index (method);
idx <<= MONO_HAS_DECL_SECURITY_BITS;
idx |= MONO_HAS_DECL_SECURITY_METHODDEF;
return get_declsec_action (method->klass->image, idx, action, entry);
Expand Down

0 comments on commit 5a7ced8

Please sign in to comment.