renamed reducible -> is_reducible
[libfirm] / ir / tr / tr_inheritance.c
index 926bd2f..2982d2e 100644 (file)
@@ -1,9 +1,9 @@
 /**
  *
- * @file tp_inheritance.c
+ * @file tr_inheritance.c
  *
  * Project:     libFIRM                                                   <br>
- * File name:   ir/tr/tp_inheritance.c                                    <br>
+ * File name:   ir/tr/tr_inheritance.c                                    <br>
  * Purpose:     Utility routines for inheritance representation           <br>
  * Author:      Goetz Lindenmaier                                         <br>
  * Modified by:                                                           <br>
@@ -46,7 +46,7 @@ static void copy_entities_from_superclass(type *clss, void *env)
   int overwritten;
   type *super, *inhenttype;
   entity *inhent, *thisent;
-  mangle_inherited_name_func *mfunc = (mangle_inherited_name_func *)env;
+  mangle_inherited_name_func *mfunc = *(mangle_inherited_name_func **)env;
 
   for(i = 0; i < get_class_n_supertypes(clss); i++) {
     super = get_class_supertype(clss, i);
@@ -57,27 +57,28 @@ static void copy_entities_from_superclass(type *clss, void *env)
       /* check whether inhent is already overwritten */
       overwritten = 0;
       for (k = 0; (k < get_class_n_members(clss)) && (overwritten == 0); k++) {
-             thisent = get_class_member(clss, k);
-             for(l = 0; l < get_entity_n_overwrites(thisent); l++) {
-               if(inhent == get_entity_overwrites(thisent, l)) {
-                 /* overwritten - do not copy */
-                 overwritten = 1;
-                 break;
-               }
-             }
+       thisent = get_class_member(clss, k);
+       for(l = 0; l < get_entity_n_overwrites(thisent); l++) {
+         if(inhent == get_entity_overwrites(thisent, l)) {
+           /* overwritten - do not copy */
+           overwritten = 1;
+           break;
+         }
+       }
       }
       /* Inherit entity */
       if (!overwritten) {
-             thisent = copy_entity_own(inhent, clss);
-             add_entity_overwrites(thisent, inhent);
-             set_entity_peculiarity(thisent, peculiarity_inherited);
-             set_entity_ld_ident(thisent, mfunc(inhent, clss));
-             if (get_entity_variability(inhent) == variability_constant) {
-               assert(is_atomic_entity(inhent) &&  /* @@@ */
-                      "Inheritance of constant, compound entities not implemented");
-               set_entity_variability(thisent, variability_constant);
-               set_atomic_ent_value(thisent, get_atomic_ent_value(inhent));
-             }
+       thisent = copy_entity_own(inhent, clss);
+       add_entity_overwrites(thisent, inhent);
+       if (get_entity_peculiarity(inhent) == peculiarity_existent)
+         set_entity_peculiarity(thisent, peculiarity_inherited);
+       set_entity_ld_ident(thisent, mfunc(inhent, clss));
+       if (get_entity_variability(inhent) == variability_constant) {
+         assert(is_atomic_entity(inhent) &&  /* @@@ */
+                "Inheritance of constant, compound entities not implemented");
+         set_entity_variability(thisent, variability_constant);
+         set_atomic_ent_value(thisent, get_atomic_ent_value(inhent));
+       }
       }
     }
   }
@@ -90,7 +91,7 @@ static void copy_entities_from_superclass(type *clss, void *env)
 void resolve_inheritance(mangle_inherited_name_func *mfunc) {
   if (!mfunc)
     mfunc = default_mangle_inherited_name;
-  class_walk_super2sub(copy_entities_from_superclass, NULL, (void *)mfunc);
+  class_walk_super2sub(copy_entities_from_superclass, NULL, (void *)&mfunc);
 }
 
 
@@ -350,17 +351,20 @@ void compute_inh_transitive_closure(void) {
     type *tp = get_irp_type(i);
     if (is_Class_type(tp) && type_not_visited(tp)) { /* For others there is nothing to accumulate. */
       int j, n_subtypes = get_class_n_subtypes(tp);
-      int has_unmarked_subtype = false;
+      int has_unmarked_subtype = 0;
 
       assert(get_type_visited(tp) < get_master_type_visited()-1);
-      for (j = 0; j < n_subtypes && !has_unmarked_subtype; ++j) {
-       type *stp = get_class_subtype(tp, j);
-       if (type_not_visited(stp)) has_unmarked_subtype = true;
+      for (j = 0; j < n_subtypes; ++j) {
+        type *stp = get_class_subtype(tp, j);
+        if (type_not_visited(stp)) {
+          has_unmarked_subtype = 1;
+          break;
+        }
       }
 
       /* This is a good starting point. */
       if (!has_unmarked_subtype)
-       compute_down_closure(tp);
+        compute_down_closure(tp);
     }
   }
 
@@ -371,17 +375,20 @@ void compute_inh_transitive_closure(void) {
     type *tp = get_irp_type(i);
     if (is_Class_type(tp) && type_not_visited(tp)) { /* For others there is nothing to accumulate. */
       int j, n_supertypes = get_class_n_supertypes(tp);
-      int has_unmarked_supertype = false;
+      int has_unmarked_supertype = 0;
 
       assert(get_type_visited(tp) < get_master_type_visited()-1);
-      for (j = 0; j < n_supertypes && !has_unmarked_supertype; ++j) {
+      for (j = 0; j < n_supertypes; ++j) {
              type *stp = get_class_supertype(tp, j);
-             if (type_not_visited(stp)) has_unmarked_supertype = true;
+        if (type_not_visited(stp)) {
+          has_unmarked_supertype = 1;
+          break;
+        }
       }
 
       /* This is a good starting point. */
       if (!has_unmarked_supertype)
-       compute_up_closure(tp);
+        compute_up_closure(tp);
     }
   }
 
@@ -615,14 +622,15 @@ typedef struct ccs_env {
 } ccs_env;
 
 void verify_irn_class_cast_state(ir_node *n, void *env) {
-  ccs_env *ccs = (ccs_env *)env;
+  ccs_env             *ccs = (ccs_env *)env;
   ir_class_cast_state this_state = ir_class_casts_any;
+  type                *fromtype, *totype;
+  int                 ref_depth = 0;
 
   if (get_irn_op(n) != op_Cast) return;
 
-  type *fromtype = get_irn_typeinfo_type(get_Cast_op(n));
-  type *totype   = get_Cast_type(n);
-  int ref_depth = 0;
+  fromtype = get_irn_typeinfo_type(get_Cast_op(n));
+  totype   = get_Cast_type(n);
 
   while (is_Pointer_type(totype) && is_Pointer_type(fromtype)) {
     totype   = get_pointer_points_to_type(totype);
@@ -635,21 +643,33 @@ void verify_irn_class_cast_state(ir_node *n, void *env) {
   if (is_subclass_of(totype, fromtype) ||
       is_subclass_of(fromtype, totype)   ) {
     this_state = ir_class_casts_transitive;
-    if ((get_class_supertype_index(totype, fromtype) == -1) &&
-       (get_class_supertype_index(fromtype, totype) == -1) ) {
+    if ((get_class_supertype_index(totype, fromtype) != -1) ||
+       (get_class_supertype_index(fromtype, totype) != -1) ||
+       fromtype == totype) {
+      /*   Das ist doch alt?  Aus dem cvs aufgetaucht ...
+          if ((get_class_supertype_index(totype, fromtype) == -1) &&
+          (get_class_supertype_index(fromtype, totype) == -1) ) {  */
       this_state = ir_class_casts_normalized;
     }
   }
 
-  assert(this_state >= ccs->expected_state &&
-        "invalid state class cast state setting in graph");
+  if (!(this_state >= ccs->expected_state)) {
+    printf("  Node is "); DDMN(n);
+    printf("    totype   "); DDMT(totype);
+    printf("    fromtype "); DDMT(fromtype);
+    printf("    this_state: %s, exp. state: %s\n",
+          get_class_cast_state_string(this_state),
+          get_class_cast_state_string(ccs->expected_state));
+    assert(this_state >= ccs->expected_state &&
+          "invalid state class cast state setting in graph");
+  }
 
   if (this_state < ccs->worst_situation)
     ccs->worst_situation = this_state;
 }
 
 
-/** Verify that the graph meets reqirements of state set. */
+/** Verify that the graph meets requirements of state set. */
 void verify_irg_class_cast_state(ir_graph *irg) {
   ccs_env env;