2005-02-02 Zoltan Varga <vargaz@freemail.hu>
authorZoltan Varga <vargaz@gmail.com>
Wed, 2 Feb 2005 10:49:49 +0000 (10:49 -0000)
committerZoltan Varga <vargaz@gmail.com>
Wed, 2 Feb 2005 10:49:49 +0000 (10:49 -0000)
* loader.c (mono_method_get_index): New helper function.

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

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

mono/metadata/ChangeLog
mono/metadata/loader.c
mono/metadata/loader.h
mono/metadata/reflection.c

index 4eba7b936f232970e49997bd824747646eec4d5d..0d8b405be623223a8c475ee1edc7bc570ba35b02 100644 (file)
@@ -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
index f533d4e42247e51f69448be3c6ae924eae0f01b3..4e5d2c47a98010d262f3e3f19ab62aae422d72c2 100644 (file)
@@ -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;
@@ -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 ();
@@ -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;
@@ -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;
@@ -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;
        }
 }
 
@@ -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 = 
@@ -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;
 }
@@ -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;
+}
 
index 6a2fc69c914b96988b57e0b5215493a41ce2d27d..c79e75577ae268feaad599660b88dfef1002fd95 100644 (file)
@@ -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);
 
index 6e3750ae3bbbba27c24cc76ac041faa7199424e5..607924dd205718bc0a3b499b02cb34629f10a4dc 100644 (file)
@@ -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;
@@ -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);
@@ -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.
  */
@@ -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);
@@ -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) {
@@ -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);
@@ -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);
@@ -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);