Change "associated type" logic to a single linked list to the "higher type"
[libfirm] / ir / tr / trverify.c
index 15b2e91..23c806a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
+ * Copyright (C) 1995-2011 University of Karlsruhe.  All right reserved.
  *
  * This file is part of libFirm.
  *
@@ -78,6 +78,7 @@ do { \
 
 static const char *firm_verify_failure_msg;
 
+#if 0
 /**
  * Show diagnostic if an entity overwrites another one not
  * in direct superclasses.
@@ -86,7 +87,7 @@ static void show_ent_not_supertp(ir_entity *ent, ir_entity *ovw)
 {
        ir_type *owner = get_entity_owner(ent);
        ir_type *ov_own = get_entity_owner(ovw);
-       int i;
+       size_t   i;
 
        fprintf(stderr, "Type verification error:\n");
        ir_fprintf(stderr, "Entity %+F::%+e owerwrites ", owner, ent);
@@ -98,6 +99,7 @@ static void show_ent_not_supertp(ir_entity *ent, ir_entity *ovw)
                ir_fprintf(stderr, " %+F:\n", super);
        }
 }
+#endif
 
 /**
  * Show diagnostic if an entity overwrites a wrong number of things.
@@ -105,25 +107,31 @@ static void show_ent_not_supertp(ir_entity *ent, ir_entity *ovw)
 static void show_ent_overwrite_cnt(ir_entity *ent)
 {
        ir_type *owner = get_entity_owner(ent);
-       int i, j, k, found, show_stp = 0;
+       size_t i;
+       size_t j;
+       size_t k;
+       bool   found;
+       bool   show_stp = false;
 
        fprintf(stderr, "Type verification error:\n");
        ir_fprintf(stderr, "Entity %t::%e owerwrites\n", owner, ent);
        for (i = 0; i < get_entity_n_overwrites(ent); ++i) {
                ir_entity *ovw = get_entity_overwrites(ent, i);
                ir_type *ov_own = get_entity_owner(ovw);
+               size_t n_supertypes = get_class_n_supertypes(owner);
 
                ir_fprintf(stderr, "  %t::%e\n", ov_own, ovw);
-               for (k = 0; k < i; ++k)
+               for (k = 0; k < i; ++k) {
                        if (ovw == get_entity_overwrites(ent, k)) {
                                ir_fprintf(stderr, "  ->%t::%e entered more than once\n", ov_own, ovw);
                                break;
                        }
+               }
 
-               found = 0;
-               for (j = get_class_n_supertypes(owner) - 1; j >= 0; --j) {
+               found = false;
+               for (j = 0; j < n_supertypes; ++j) {
                        if (ov_own == get_class_supertype(owner, j)) {
-                               show_stp = found = 1;
+                               show_stp = found = true;
                                break;
                        }
                }
@@ -147,10 +155,9 @@ static void show_ent_overwrite_cnt(ir_entity *ent)
  */
 static int check_class(ir_type *tp)
 {
-       int i, j, k;
-       int found;
+       size_t i, n;
 
-       for (i = get_class_n_members(tp) - 1; i >= 0; --i) {
+       for (i = 0, n = get_class_n_members(tp); i < n; ++i) {
                ir_entity *mem = get_class_member(tp, i);
 
                ASSERT_AND_RET_DBG(
@@ -163,7 +170,7 @@ static int check_class(ir_type *tp)
                        mem,
                        "NULL members not allowed",
                        error_null_mem,
-                       ir_fprintf(stderr, "Type verification error:\n%+F member %d is NULL\n", tp, i)
+                       ir_fprintf(stderr, "Type verification error:\n%+F member %zu is NULL\n", tp, i)
                );
 
                ASSERT_AND_RET_DBG(
@@ -173,25 +180,31 @@ static int check_class(ir_type *tp)
                        show_ent_overwrite_cnt(mem)
                );
 
-               for (j = get_entity_n_overwrites(mem) - 1; j >= 0; --j) {
-                       ir_entity *ovw = get_entity_overwrites(mem, j);
-                       /*printf(" overwrites: "); DDME(ovw);*/
-                       /* Check whether ovw is member of one of tp's supertypes. If so,
-                       the representation is correct. */
-                       found = 0;
-                       for (k = get_class_n_supertypes(tp) - 1; k >= 0; --k) {
-                               if (get_class_member_index(get_class_supertype(tp, k), ovw) >= 0) {
-                                       found = 1;
-                                       break;
+#if 0
+               {
+                       size_t j, m;
+                       /* check if the overwrite relation is flat, i.e. every overwrite
+                        * is visible in every direct superclass. */
+                       for (j = 0, m = get_entity_n_overwrites(mem); j < m; ++j) {
+                               ir_entity *ovw = get_entity_overwrites(mem, j);
+                               size_t    k, n_super;
+
+                               /* Check whether ovw is member of one of tp's supertypes. If so,
+                                  the representation is correct. */
+                               for (k = 0, n_super = get_class_n_supertypes(tp); k < n_super; ++k) {
+                                       if (get_class_member_index(get_class_supertype(tp, k), ovw) != INVALID_MEMBER_INDEX) {
+                                               ASSERT_AND_RET_DBG(
+                                                       0,
+                                                       "overwrites an entity not contained in direct supertype",
+                                                       error_ent_not_cont,
+                                                       show_ent_not_supertp(mem, ovw)
+                                               );
+                                               break;
+                                       }
                                }
                        }
-                       ASSERT_AND_RET_DBG(
-                               found,
-                               "overwrites an entity not contained in direct supertype",
-                               error_ent_not_cont,
-                               show_ent_not_supertp(mem, ovw)
-                       );
                }
+#endif
        }
        return 0;
 }
@@ -199,16 +212,16 @@ static int check_class(ir_type *tp)
 /**
  * Check an array.
  */
-static int check_array(ir_type *tp)
+static int check_array(const ir_type *tp)
 {
-       int i, n_dim = get_array_n_dimensions(tp);
+       size_t i, n_dim = get_array_n_dimensions(tp);
 
        for (i = 0; i < n_dim; ++i) {
                ASSERT_AND_RET_DBG(
                        has_array_lower_bound(tp, i) || has_array_upper_bound(tp, i),
                        "array bound missing",
                        1,
-                       ir_fprintf(stderr, "%+F in dimension %d\n", tp, i)
+                       ir_fprintf(stderr, "%+F in dimension %zu\n", tp, i)
                );
        }
        return 0;
@@ -267,21 +280,21 @@ static int check_visited_flag(ir_graph *irg, ir_node *n)
 /**
  * helper environment struct for constant_on_wrong_obstack()
  */
-struct myenv {
+typedef struct myenv {
        int res;
        ir_graph *irg;
-};
+} myenv;
 
 /**
  * called by the walker
  */
-static void on_irg_storage(ir_node *n, void *env)
+static void on_irg_storage(ir_node *n, void *data)
 {
-       struct myenv *myenv = env;
+       myenv *env = (myenv*)data;
 
        /* We also test whether the setting of the visited flag is legal. */
-       myenv->res = node_is_in_irgs_storage(myenv->irg, n) &&
-                    check_visited_flag(myenv->irg, n);
+       env->res = node_is_in_irgs_storage(env->irg, n) &&
+                  check_visited_flag(env->irg, n);
 }
 
 /**
@@ -290,7 +303,7 @@ static void on_irg_storage(ir_node *n, void *env)
  */
 static int constant_on_wrong_irg(ir_node *n)
 {
-       struct myenv env;
+       myenv env;
 
        env.res = 1;  /* on right obstack */
        env.irg = get_const_code_irg();
@@ -309,8 +322,7 @@ static int initializer_constant_on_wrong_irg(ir_initializer_t *initializer)
        case IR_INITIALIZER_CONST:
                return constant_on_wrong_irg(get_initializer_const_value(initializer));
        case IR_INITIALIZER_COMPOUND: {
-               int n = get_initializer_compound_n_entries(initializer);
-               int i;
+               size_t i, n = get_initializer_compound_n_entries(initializer);
                for (i = 0; i < n; ++i) {
                        ir_initializer_t *sub
                                = get_initializer_compound_value(initializer, i);
@@ -334,8 +346,8 @@ static int constants_on_wrong_irg(ir_entity *ent)
        if (ent->initializer != NULL) {
                return initializer_constant_on_wrong_irg(ent->initializer);
        } else if (entity_has_compound_ent_values(ent)) {
-               int i;
-               for (i = get_compound_ent_n_values(ent) - 1; i >= 0; --i) {
+               size_t i, n;
+               for (i = 0, n = get_compound_ent_n_values(ent); i < n; ++i) {
                        if (constant_on_wrong_irg(get_compound_ent_value(ent, i)))
                                return 1;
                }
@@ -408,7 +420,7 @@ int check_entity(ir_entity *ent)
  */
 static void check_tore(type_or_ent tore, void *env)
 {
-       int *res = env;
+       int *res = (int*)env;
        assert(tore.ent);
        if (is_type(tore.typ)) {
                *res = check_type(tore.typ);
@@ -423,20 +435,33 @@ static void check_tore(type_or_ent tore, void *env)
  */
 int tr_verify(void)
 {
-       int      res = no_error;
-       ir_type *constructors;
-       ir_type *destructors;
-       ir_type *thread_locals;
-       int      i;
        static ident *empty = NULL;
+       int           res = no_error;
+       ir_type      *constructors;
+       ir_type      *destructors;
+       ir_type      *thread_locals;
+       size_t        i, n;
+       ir_segment_t  s;
 
        if (empty == NULL)
                empty = new_id_from_chars("", 0);
 
        type_walk(check_tore, NULL, &res);
 
+       for (s = IR_SEGMENT_FIRST; s <= IR_SEGMENT_LAST; ++s) {
+               const ir_type *type = get_segment_type(s);
+               size_t         e;
+               for (e = 0; e < get_compound_n_members(type); ++e) {
+                       ir_entity *entity = get_compound_member(type, e);
+                       ASSERT_AND_RET(get_entity_ld_ident(entity) != NULL ||
+                                       get_entity_visibility(entity) == ir_visibility_private,
+                                       "segment members must have a name or visibility_private",
+                                       1);
+               }
+       }
+
        constructors = get_segment_type(IR_SEGMENT_CONSTRUCTORS);
-       for (i = get_compound_n_members(constructors)-1; i >= 0; --i) {
+       for (i = 0, n = get_compound_n_members(constructors); i < n; ++i) {
                const ir_entity *entity = get_compound_member(constructors, i);
                ASSERT_AND_RET(get_entity_linkage(entity) & IR_LINKAGE_HIDDEN_USER,
                               "entity without LINKAGE_HIDDEN_USER in constructors is pointless",
@@ -446,7 +471,7 @@ int tr_verify(void)
                               "entity in constructors should have ld_ident=''", 1);
        }
        destructors = get_segment_type(IR_SEGMENT_DESTRUCTORS);
-       for (i = get_compound_n_members(destructors)-1; i >= 0; --i) {
+       for (i = 0, n = get_compound_n_members(destructors); i < n; ++i) {
                const ir_entity *entity = get_compound_member(destructors, i);
                ASSERT_AND_RET(get_entity_linkage(entity) & IR_LINKAGE_HIDDEN_USER,
                               "entity without LINKAGE_HIDDEN_USER in destructors is pointless",
@@ -456,7 +481,7 @@ int tr_verify(void)
                               "entity in destructors should have ld_ident=''", 1);
        }
        thread_locals = get_segment_type(IR_SEGMENT_THREAD_LOCAL);
-       for (i = get_compound_n_members(thread_locals)-1; i >= 0; --i) {
+       for (i = 0, n = get_compound_n_members(thread_locals); i < n; ++i) {
                const ir_entity *entity = get_compound_member(thread_locals, i);
                /* this is odd and should not be allowed I think */
                ASSERT_AND_RET(!is_method_entity(entity),