rename type entity into ir_entity
[libfirm] / ir / tr / trvrfy.c
index 42c6e28..80e1752 100644 (file)
@@ -64,6 +64,68 @@ do { \
 
 #endif /* NDEBUG */
 
+/**
+ * Show diagnostic if an entity overwrites another one not
+ * in direct superclasses.
+ */
+static void show_ent_not_supertp(entity *ent, entity *ovw)
+{
+  ir_type *owner = get_entity_owner(ent);
+  ir_type *ov_own = get_entity_owner(ovw);
+  int i;
+
+  fprintf(stderr, "Type verification error:\n");
+  ir_fprintf(stderr, "Entity %+F::%+e owerwrites ", owner, ent);
+  ir_fprintf(stderr, "Entity %+F::%+e\n", ov_own, ovw);
+
+  ir_fprintf(stderr, "Supertypes of %+F:\n", owner);
+  for (i = 0; i < get_class_n_supertypes(owner); ++i) {
+    ir_type *super = get_class_supertype(owner, i);
+    ir_fprintf(stderr, " %+F:\n", super);
+  }
+}
+
+/**
+ * Show diagnostic if an entity overwrites a wrong number of things.
+ */
+static void show_ent_overwrite_cnt(entity *ent)
+{
+  ir_type *owner = get_entity_owner(ent);
+  int i, j, k, found, show_stp = 0;
+
+  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) {
+    entity *ovw = get_entity_overwrites(ent, i);
+    ir_type *ov_own = get_entity_owner(ovw);
+
+    ir_fprintf(stderr, "  %t::%e\n", ov_own, ovw);
+    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) {
+      if (ov_own == get_class_supertype(owner, j)) {
+        show_stp = found = 1;
+        break;
+      }
+    }
+    if (! found)
+      ir_fprintf(stderr, "  ->%t not in super types of %t\n", ov_own, owner);
+  }
+
+  if (show_stp) {
+    ir_fprintf(stderr, "Supertypes of %t:\n", owner);
+    for (i = 0; i < get_class_n_supertypes(owner); ++i) {
+      ir_type *super = get_class_supertype(owner, i);
+      ir_fprintf(stderr, " %t:\n", super);
+    }
+  }
+}
+
 /**
  * Check a class
  */
@@ -73,41 +135,47 @@ static int check_class(ir_type *tp) {
 
   /*printf("\n"); DDMT(tp);*/
 
-  for (i = 0; i < get_class_n_members(tp); i++) {
-
+  for (i = get_class_n_members(tp) - 1; i >= 0; --i) {
     entity *mem = get_class_member(tp, i);
-    assert(mem && "NULL members not allowed");
-    /*printf(" %d, %d", get_entity_n_overwrites(mem), get_class_n_supertypes(tp)); DDME(mem);*/
-    if (!mem) return error_null_mem;
 
-    if (get_entity_n_overwrites(mem) > get_class_n_supertypes(tp)) {
-      ASSERT_AND_RET_DBG(
-        get_entity_n_overwrites(mem) <= get_class_n_supertypes(tp),
-        "wrong number of entity overwrites",
-        error_wrong_ent_overwrites,
-        ir_fprintf(stderr, "%+F %+F\n", tp, mem)
-      );
-    }
-    for (j = 0; j < get_entity_n_overwrites(mem); j++) {
+    ASSERT_AND_RET_DBG(
+      tp == get_entity_owner(mem),
+      "class member with wrong owner",
+      error_ent_wrong_owner,
+      ir_fprintf(stderr, "Type verification error:\n%+F %+e(owner %+F)\n",tp, mem, get_entity_owner(mem))
+    );
+    ASSERT_AND_RET_DBG(
+      mem,
+      "NULL members not allowed",
+      error_null_mem,
+      ir_fprintf(stderr, "Type verification error:\n%+F member %d is NULL\n", tp, i)
+    );
+
+    ASSERT_AND_RET_DBG(
+      get_entity_n_overwrites(mem) <= get_class_n_supertypes(tp),
+      "wrong number of entity overwrites",
+      error_wrong_ent_overwrites,
+      show_ent_overwrite_cnt(mem)
+    );
+
+    for (j = get_entity_n_overwrites(mem) - 1; j >= 0; --j) {
       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 = 0; k < get_class_n_supertypes(tp); k++) {
+      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 (!found) {
-        ASSERT_AND_RET_DBG(
-          found,
-          "overwrites an entity not contained in direct supertype",
-          error_ent_not_cont,
-          ir_fprintf(stderr, "%+F %+F\n", tp, mem)
-        );
-      }
+      ASSERT_AND_RET_DBG(
+        found,
+        "overwrites an entity not contained in direct supertype",
+        error_ent_not_cont,
+        show_ent_not_supertp(mem, ovw)
+      );
     }
   }
   return 0;
@@ -209,8 +277,11 @@ static int constant_on_wrong_irg(ir_node *n) {
   return ! env.res;
 }
 
-/*
+/**
  * Check if constants node are NOT on the constant IR graph.
+ *
+ * @return NON-zero if an entity initializer constant is NOT on
+ * the current_ir_graph's obstack.
  */
 static int constants_on_wrong_irg(entity *ent) {
   if (get_entity_variability(ent) == variability_uninitialized) return 0;
@@ -231,13 +302,23 @@ static int constants_on_wrong_irg(entity *ent) {
         get_class_peculiarity(get_entity_owner(ent)) == peculiarity_description,
         "Value in constant atomic entity not set.",
         0,
-        ir_fprintf(stderr, "%+F, owner %+F\n", ent, get_entity_owner(ent))
+        ir_fprintf(stderr, "%+e, owner %+F\n", ent, get_entity_owner(ent))
       );
     }
   }
   return 0;
 }
 
+/**
+ * Shows a wrong entity allocation
+ */
+static void show_ent_alloc_error(entity *ent)
+{
+  ir_fprintf(stderr, "%+e owner %t has allocation %s\n",
+    ent, get_entity_type(ent),
+    get_allocation_name(get_entity_allocation(ent)));
+}
+
 /*
  * Check an entity. Currently, we check only if initialized constants
  * are build on the const irg graph.
@@ -252,7 +333,11 @@ int check_entity(entity *ent) {
   ir_type *owner = get_entity_owner(ent);
 
   current_ir_graph =  get_const_code_irg();
-  ASSERT_AND_RET(constants_on_wrong_irg(ent) == 0, "Contants placed on wrong IRG", error_const_on_wrong_irg);
+  ASSERT_AND_RET_DBG(
+    constants_on_wrong_irg(ent) == 0,
+    "Contants placed on wrong IRG",
+    error_const_on_wrong_irg,
+    ir_fprintf(stderr, "%+e not on %+F\n", ent, current_ir_graph));
 
   rem_vpi = get_visit_pseudo_irgs();
   set_visit_pseudo_irgs(1);
@@ -264,7 +349,7 @@ int check_entity(entity *ent) {
       0,
       "Method ents with pec_exist must have an irg",
       error_existent_entity_without_irg,
-      ir_fprintf(stderr, "%+F\n", ent)
+      ir_fprintf(stderr, "%+e\n", ent)
     );
   }
   set_visit_pseudo_irgs(rem_vpi);
@@ -279,7 +364,7 @@ int check_entity(entity *ent) {
         get_entity_peculiarity(impl) == peculiarity_existent,
             "inherited method entities must have constant pointing to existent entity.",
        error_inherited_ent_without_const,
-       ir_fprintf(stderr, "%+F points to %+F\n", ent, impl)
+       ir_fprintf(stderr, "%+e points to %+e\n", ent, impl)
       );
     }
   }
@@ -291,7 +376,7 @@ int check_entity(entity *ent) {
            get_entity_allocation(ent) != allocation_automatic,
       "Entities in global type are not allowed to by dynamic or automatic allocated",
       error_glob_ent_allocation,
-      ir_fprintf(stderr, "%+F\n", ent)
+      show_ent_alloc_error(ent)
     );
   }
 
@@ -303,7 +388,7 @@ int check_entity(entity *ent) {
           get_irn_mode(val) == get_type_mode(tp),
                "Mode of constant in entity must match type.",
           error_ent_const_mode,
-          ir_fprintf(stderr, "%+F const %+F, type %+F(%+F)\n",
+          ir_fprintf(stderr, "%+e const %+F, type %+F(%+F)\n",
             ent, val, tp, get_type_mode(tp))
         );
     }