2010-03-02 Rodrigo Kumpera <rkumpera@novell.com>
[mono.git] / mono / metadata / monodiet.c
index 906510d4bd4cd662b703fcb44139ce31f3e286b1..1ad1f538819b48207c633503e97fda3414b17d49 100644 (file)
@@ -86,13 +86,16 @@ static void
 add_types_from_method (MonoMethod *method) {
        const MonoOpcode *opcode;
        MonoMethodHeader *header;
-       const unsigned char *ip;
+       const unsigned char *ip, *il_code_end;
        gpointer val = NULL, oldkey = NULL;
        int i, n;
        guint32 token;
        MonoClass *klass;
        MonoClassField *field;
        MonoCustomAttrInfo* cattrs;
+       MonoType** locals;
+       gpointer exc_iter;
+       MonoExceptionClause clause;
 
        if (g_hash_table_lookup_extended (method_table, method, &oldkey, &val))
                return;
@@ -123,19 +126,20 @@ add_types_from_method (MonoMethod *method) {
 
        header = mono_method_get_header (method);
 
-       for (i = 0; i < header->num_locals; ++i) {
-               klass = mono_class_from_mono_type (header->locals [i]);
+       locals = mono_method_header_get_locals (header, &n, NULL);
+       for (i = 0; i < n; ++i) {
+               klass = mono_class_from_mono_type (locals [i]);
                add_type (klass);
        }
-       for (i = 0; i < header->num_clauses; ++i) {
-               MonoExceptionClause *clause = &header->clauses [i];
-               if (clause->flags == MONO_EXCEPTION_CLAUSE_NONE)
-                       add_type (clause->data.catch_class);
+       for (exc_iter = NULL; mono_method_header_get_clauses (header, method, &exc_iter, &clause);) {
+               if (clause.flags == MONO_EXCEPTION_CLAUSE_NONE)
+                       add_type (clause.data.catch_class);
        }
 
-       ip = header->code;
+       ip = mono_method_header_get_code (header, &n, NULL);
+       il_code_end = ip + n;
 
-       while (ip < (header->code + header->code_size)) {
+       while (ip < il_code_end) {
                if (verbose > 2)
                        g_print ("#%s", mono_disasm_code_one (NULL, method, ip, NULL));
                if (*ip == 0xfe) {
@@ -214,6 +218,7 @@ handle_cattrs (MonoCustomAttrInfo* cattrs)
        for (i = 0; i < cattrs->num_attrs; ++i) {
                add_types_from_method (cattrs->attrs [i].ctor);
        }
+       mono_custom_attrs_free (cattrs);
 }
 
 static void
@@ -223,6 +228,11 @@ handle_type (MonoClass *klass, guint32 flags)
        guint32 missing;
        MonoCustomAttrInfo* cattrs;
        gpointer val = NULL, oldkey = NULL;
+       MonoProperty* prop;
+       MonoEvent* event;
+       MonoMethod* method;
+       MonoClassField* field;
+       gpointer iter;
        
        if (g_hash_table_lookup_extended (type_table, klass, &oldkey, &val)) {
                missing = flags & ~(GPOINTER_TO_UINT (val));
@@ -239,27 +249,27 @@ handle_type (MonoClass *klass, guint32 flags)
                add_type (klass->parent);
        if (klass->nested_in)
                add_type (klass->nested_in);
-       mono_class_setup_methods (klass);
-       for (i = 0; i < klass->method.count; ++i) {
-               if ((missing & TYPE_METHODS) || strcmp (klass->methods [i]->name, ".cctor") == 0)
-                       add_types_from_method (klass->methods [i]);
+       iter = NULL;
+       while ((method = mono_class_get_methods (klass, &iter))) {
+               if ((missing & TYPE_METHODS) || strcmp (method->name, ".cctor") == 0)
+                       add_types_from_method (method);
        }
        if (klass->enumtype) {
                add_field (mono_class_get_field_from_name (klass, "value__"));
        }
        if (force_enums || (missing & TYPE_FIELDS)) {
-               for (i = 0; i < klass->field.count; ++i) {
-                       add_field (&klass->fields [i]);
-               }
+               iter = NULL;
+               while ((field = mono_class_get_fields (klass, &iter)))
+                       add_field (field);
        }
-       mono_class_setup_properties (klass);
-       for (i = 0; i < klass->property.count; ++i) {
-               cattrs = mono_custom_attrs_from_property (klass, &klass->properties [i]);
+       iter = NULL;
+       while ((prop = mono_class_get_properties (klass, &iter))) {
+               cattrs = mono_custom_attrs_from_property (klass, prop);
                handle_cattrs (cattrs);
        }
-       mono_class_setup_events (klass);
-       for (i = 0; i < klass->event.count; ++i) {
-               cattrs = mono_custom_attrs_from_event (klass, &klass->events [i]);
+       iter = NULL;
+       while ((event = mono_class_get_events (klass, &iter))) {
+               cattrs = mono_custom_attrs_from_event (klass, event);
                handle_cattrs (cattrs);
        }
        for (i = 0; i < klass->interface_count; ++i)
@@ -327,9 +337,8 @@ check_vmethods (MonoClass *klass, MonoMethod *method)
        if (!vtable)
                return;
        if (method->klass->flags & TYPE_ATTRIBUTE_INTERFACE) {
-               if (method->klass->interface_id <= klass->max_interface_id &&
-                               (klass->interface_offsets [method->klass->interface_id] >= 0)) {
-                       int iface_offset = klass->interface_offsets [method->klass->interface_id];
+               if (MONO_CLASS_IMPLEMENTS_INTERFACE (klass, method->klass->interface_id)) {
+                       int iface_offset = mono_class_interface_offset (klass, method->klass);
                        g_assert (method->slot != -1);
                        if (vtable [iface_offset + method->slot])
                                add_types_from_method (vtable [iface_offset + method->slot]);