doxygen comment updated
[libfirm] / ir / tr / tr_inheritance.c
index 715771d..9abc5f9 100644 (file)
  *  @see  type.h entity.h
  */
 
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include "type.h"
 #include "entity.h"
 #include "typewalk.h"
 /* Resolve implicit inheritance.                                           */
 /* ----------------------------------------------------------------------- */
 
-ident *default_mangle_inherited_name(entity *super, type *clss) {
+ident *default_mangle_inherited_name(ir_entity *super, ir_type *clss) {
   return mangle_u(new_id_from_str("inh"), mangle_u(get_type_ident(clss), get_entity_ident(super)));
 }
 
 /** Replicates all entities in all super classes that are not overwritten
    by an entity of this class. */
-static void copy_entities_from_superclass(type *clss, void *env)
+static void copy_entities_from_superclass(ir_type *clss, void *env)
 {
   int i, j, k, l;
   int overwritten;
-  type *super, *inhenttype;
-  entity *inhent, *thisent;
+  ir_type *super, *inhenttype;
+  ir_entity *inhent, *thisent;
   mangle_inherited_name_func *mfunc = *(mangle_inherited_name_func **)env;
 
   for(i = 0; i < get_class_n_supertypes(clss); i++) {
@@ -172,7 +176,7 @@ static tr_inh_trans_tp* get_firm_kind_entry(firm_kind *k) {
   return found;
 }
 
-static pset *get_entity_map(entity *ent, dir d) {
+static pset *get_entity_map(ir_entity *ent, dir d) {
   tr_inh_trans_tp *found;
 
   assert(is_entity(ent));
@@ -180,7 +184,7 @@ static pset *get_entity_map(entity *ent, dir d) {
   return found->directions[d];
 }
 /*
-static void  add_entity_map(entity *ent, dir d, entity *new) {
+static void  add_entity_map(ir_entity *ent, dir d, ir_entity *new) {
   tr_inh_trans_tp *found;
 
   assert(is_entity(ent) && is_entity(new));
@@ -188,7 +192,7 @@ static void  add_entity_map(entity *ent, dir d, entity *new) {
   pset_insert_ptr(found->directions[d], new);
 }
 */
-static pset *get_type_map(type *tp, dir d) {
+static pset *get_type_map(ir_type *tp, dir d) {
   tr_inh_trans_tp *found;
 
   assert(is_type(tp));
@@ -196,7 +200,7 @@ static pset *get_type_map(type *tp, dir d) {
   return found->directions[d];
 }
 /*
-static void  add_type_map(type *tp, dir d, type *new) {
+static void  add_type_map(ir_type *tp, dir d, type *new) {
   tr_inh_trans_tp *found;
 
   assert(is_type(tp) && is_type(new));
@@ -222,7 +226,7 @@ static void  add_type_map(type *tp, dir d, type *new) {
  * If it is marked with master_flag_visited it is fully processed.
  *
  * Well, we still miss some candidates ... */
-static void compute_down_closure(type *tp) {
+static void compute_down_closure(ir_type *tp) {
   pset *myset, *subset;
   int i, n_subtypes, n_members, n_supertypes;
   unsigned long master_visited = get_master_type_visited();
@@ -234,7 +238,7 @@ static void compute_down_closure(type *tp) {
   /* Recursive descend. */
   n_subtypes = get_class_n_subtypes(tp);
   for (i = 0; i < n_subtypes; ++i) {
-    type *stp = get_class_subtype(tp, i);
+    ir_type *stp = get_class_subtype(tp, i);
     if (get_type_visited(stp) < master_visited-1) {
       compute_down_closure(stp);
     }
@@ -243,7 +247,7 @@ static void compute_down_closure(type *tp) {
   /* types */
   myset = get_type_map(tp, d_down);
   for (i = 0; i < n_subtypes; ++i) {
-    type *stp = get_class_subtype(tp, i);
+    ir_type *stp = get_class_subtype(tp, i);
     subset = get_type_map(stp, d_down);
     pset_insert_ptr(myset, stp);
     pset_insert_pset_ptr(myset, subset);
@@ -252,12 +256,12 @@ static void compute_down_closure(type *tp) {
   /* entities */
   n_members = get_class_n_members(tp);
   for (i = 0; i < n_members; ++i) {
-    entity *mem = get_class_member(tp, i);
+    ir_entity *mem = get_class_member(tp, i);
     int j, n_overwrittenby = get_entity_n_overwrittenby(mem);
 
     myset = get_entity_map(mem, d_down);
     for (j = 0; j < n_overwrittenby; ++j) {
-      entity *ov = get_entity_overwrittenby(mem, j);
+      ir_entity *ov = get_entity_overwrittenby(mem, j);
       subset = get_entity_map(ov, d_down);
       pset_insert_ptr(myset, ov);
       pset_insert_pset_ptr(myset, subset);
@@ -269,14 +273,14 @@ static void compute_down_closure(type *tp) {
   /* Walk up. */
   n_supertypes = get_class_n_supertypes(tp);
   for (i = 0; i < n_supertypes; ++i) {
-    type *stp = get_class_supertype(tp, i);
+    ir_type *stp = get_class_supertype(tp, i);
     if (get_type_visited(stp) < master_visited-1) {
       compute_down_closure(stp);
     }
   }
 }
 
-static void compute_up_closure(type *tp) {
+static void compute_up_closure(ir_type *tp) {
   pset *myset, *subset;
   int i, n_subtypes, n_members, n_supertypes;
   unsigned long master_visited = get_master_type_visited();
@@ -288,7 +292,7 @@ static void compute_up_closure(type *tp) {
   /* Recursive descend. */
   n_supertypes = get_class_n_supertypes(tp);
   for (i = 0; i < n_supertypes; ++i) {
-    type *stp = get_class_supertype(tp, i);
+    ir_type *stp = get_class_supertype(tp, i);
     if (get_type_visited(stp) < get_master_type_visited()-1) {
       compute_up_closure(stp);
     }
@@ -297,7 +301,7 @@ static void compute_up_closure(type *tp) {
   /* types */
   myset = get_type_map(tp, d_up);
   for (i = 0; i < n_supertypes; ++i) {
-    type *stp = get_class_supertype(tp, i);
+    ir_type *stp = get_class_supertype(tp, i);
     subset = get_type_map(stp, d_up);
     pset_insert_ptr(myset, stp);
     pset_insert_pset_ptr(myset, subset);
@@ -306,12 +310,12 @@ static void compute_up_closure(type *tp) {
   /* entities */
   n_members = get_class_n_members(tp);
   for (i = 0; i < n_members; ++i) {
-    entity *mem = get_class_member(tp, i);
+    ir_entity *mem = get_class_member(tp, i);
     int j, n_overwrites = get_entity_n_overwrites(mem);
 
     myset = get_entity_map(mem, d_up);
     for (j = 0; j < n_overwrites; ++j) {
-      entity *ov = get_entity_overwrites(mem, j);
+      ir_entity *ov = get_entity_overwrites(mem, j);
       subset = get_entity_map(ov, d_up);
       pset_insert_pset_ptr(myset, subset);
       pset_insert_ptr(myset, ov);
@@ -323,7 +327,7 @@ static void compute_up_closure(type *tp) {
   /* Walk down. */
   n_subtypes = get_class_n_subtypes(tp);
   for (i = 0; i < n_subtypes; ++i) {
-    type *stp = get_class_subtype(tp, i);
+    ir_type *stp = get_class_subtype(tp, i);
     if (get_type_visited(stp) < master_visited-1) {
       compute_up_closure(stp);
     }
@@ -343,14 +347,14 @@ void compute_inh_transitive_closure(void) {
   inc_master_type_visited();  /* Inc twice: one if on stack, second if values computed. */
   inc_master_type_visited();
   for (i = 0; i < n_types; ++i) {
-    type *tp = get_irp_type(i);
+    ir_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 = 0;
 
       assert(get_type_visited(tp) < get_master_type_visited()-1);
       for (j = 0; j < n_subtypes; ++j) {
-        type *stp = get_class_subtype(tp, j);
+        ir_type *stp = get_class_subtype(tp, j);
         if (type_not_visited(stp)) {
           has_unmarked_subtype = 1;
           break;
@@ -367,14 +371,14 @@ void compute_inh_transitive_closure(void) {
   inc_master_type_visited();
   inc_master_type_visited();
   for (i = 0; i < n_types; ++i) {
-    type *tp = get_irp_type(i);
+    ir_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 = 0;
 
       assert(get_type_visited(tp) < get_master_type_visited()-1);
       for (j = 0; j < n_supertypes; ++j) {
-             type *stp = get_class_supertype(tp, j);
+             ir_type *stp = get_class_supertype(tp, j);
         if (type_not_visited(stp)) {
           has_unmarked_supertype = 1;
           break;
@@ -406,41 +410,41 @@ void free_inh_transitive_closure(void) {
 
 /* - subtype ------------------------------------------------------------- */
 
-type *get_class_trans_subtype_first(type *tp) {
+ir_type *get_class_trans_subtype_first(ir_type *tp) {
   assert_valid_state();
   return pset_first(get_type_map(tp, d_down));
 }
 
-type *get_class_trans_subtype_next (type *tp) {
+ir_type *get_class_trans_subtype_next (ir_type *tp) {
   assert_valid_state();
   return pset_next(get_type_map(tp, d_down));
 }
 
-int is_class_trans_subtype (type *tp, type *subtp) {
+int is_class_trans_subtype (ir_type *tp, ir_type *subtp) {
   assert_valid_state();
   return (pset_find_ptr(get_type_map(tp, d_down), subtp) != NULL);
 }
 
 /* - supertype ----------------------------------------------------------- */
 
-type *get_class_trans_supertype_first(type *tp) {
+ir_type *get_class_trans_supertype_first(ir_type *tp) {
   assert_valid_state();
   return pset_first(get_type_map(tp, d_up));
 }
 
-type *get_class_trans_supertype_next (type *tp) {
+ir_type *get_class_trans_supertype_next (ir_type *tp) {
   assert_valid_state();
   return pset_next(get_type_map(tp, d_up));
 }
 
 /* - overwrittenby ------------------------------------------------------- */
 
-entity *get_entity_trans_overwrittenby_first(entity *ent) {
+ir_entity *get_entity_trans_overwrittenby_first(ir_entity *ent) {
   assert_valid_state();
   return pset_first(get_entity_map(ent, d_down));
 }
 
-entity *get_entity_trans_overwrittenby_next (entity *ent) {
+ir_entity *get_entity_trans_overwrittenby_next (ir_entity *ent) {
   assert_valid_state();
   return pset_next(get_entity_map(ent, d_down));
 }
@@ -449,12 +453,12 @@ entity *get_entity_trans_overwrittenby_next (entity *ent) {
 
 
 /** Iterate over all transitive overwritten entities. */
-entity *get_entity_trans_overwrites_first(entity *ent) {
+ir_entity *get_entity_trans_overwrites_first(ir_entity *ent) {
   assert_valid_state();
   return pset_first(get_entity_map(ent, d_up));
 }
 
-entity *get_entity_trans_overwrites_next (entity *ent) {
+ir_entity *get_entity_trans_overwrites_next (ir_entity *ent) {
   assert_valid_state();
   return pset_next(get_entity_map(ent, d_up));
 }
@@ -467,22 +471,14 @@ entity *get_entity_trans_overwrites_next (entity *ent) {
 /* Classify pairs of types/entities in the inheritance relations.          */
 /* ----------------------------------------------------------------------- */
 
-/* Returns true if low is subclass of high. */
-int is_SubClass_of(type *low, type *high) {
+/** Returns true if low is subclass of high. */
+static int check_is_SubClass_of(ir_type *low, ir_type *high) {
   int i, n_subtypes;
-  assert(is_Class_type(low) && is_Class_type(high));
-
-  if (low == high) return 1;
-
-  if (get_irp_inh_transitive_closure_state() == inh_transitive_closure_valid) {
-    pset *m = get_type_map(high, d_down);
-    return pset_find_ptr(m, low) ? 1 : 0;
-  }
 
   /* depth first search from high downwards. */
   n_subtypes = get_class_n_subtypes(high);
   for (i = 0; i < n_subtypes; i++) {
-    type *stp = get_class_subtype(high, i);
+    ir_type *stp = get_class_subtype(high, i);
     if (low == stp) return 1;
     if (is_SubClass_of(low, stp))
       return 1;
@@ -490,6 +486,19 @@ int is_SubClass_of(type *low, type *high) {
   return 0;
 }
 
+/* Returns true if low is subclass of high. */
+int is_SubClass_of(ir_type *low, ir_type *high) {
+  assert(is_Class_type(low) && is_Class_type(high));
+
+  if (low == high) return 1;
+
+  if (get_irp_inh_transitive_closure_state() == inh_transitive_closure_valid) {
+    pset *m = get_type_map(high, d_down);
+    return pset_find_ptr(m, low) ? 1 : 0;
+  }
+  return check_is_SubClass_of(low, high);
+}
+
 
 /* Subclass check for pointers to classes.
  *
@@ -497,7 +506,7 @@ int is_SubClass_of(type *low, type *high) {
  *  many as possible).  If the remaining types are both class types
  *  and subclasses, returns true, else false.  Can also be called with
  *  two class types.  */
-int is_SubClass_ptr_of(type *low, type *high) {
+int is_SubClass_ptr_of(ir_type *low, ir_type *high) {
   while (is_Pointer_type(low) && is_Pointer_type(high)) {
     low  = get_pointer_points_to_type(low);
     high = get_pointer_points_to_type(high);
@@ -508,7 +517,7 @@ int is_SubClass_ptr_of(type *low, type *high) {
   return 0;
 }
 
-int is_overwritten_by(entity *high, entity *low) {
+int is_overwritten_by(ir_entity *high, ir_entity *low) {
   int i, n_overwrittenby;
   assert(is_entity(low) && is_entity(high));
 
@@ -520,7 +529,7 @@ int is_overwritten_by(entity *high, entity *low) {
   /* depth first search from high downwards. */
   n_overwrittenby = get_entity_n_overwrittenby(high);
   for (i = 0; i < n_overwrittenby; i++) {
-    entity *ov = get_entity_overwrittenby(high, i);
+    ir_entity *ov = get_entity_overwrittenby(high, i);
     if (low == ov) return 1;
     if (is_overwritten_by(low, ov))
       return 1;
@@ -528,22 +537,26 @@ int is_overwritten_by(entity *high, entity *low) {
   return 0;
 }
 
-
-/** Need two routines because I want to assert the result. */
-static entity *resolve_ent_polymorphy2 (type *dynamic_class, entity *static_ent) {
+/** Resolve polymorphy in the inheritance relation.
+ *
+ * Returns the dynamically referenced entity if the static entity and the
+ * dynamic type are given.
+ * Search downwards in overwritten tree.
+ *
+ * Need two routines because I want to assert the result.
+ */
+static ir_entity *do_resolve_ent_polymorphy(ir_type *dynamic_class, ir_entity *static_ent) {
   int i, n_overwrittenby;
-  entity *res = NULL;
 
   if (get_entity_owner(static_ent) == dynamic_class) return static_ent;
 
   n_overwrittenby = get_entity_n_overwrittenby(static_ent);
   for (i = 0; i < n_overwrittenby; ++i) {
-    res = resolve_ent_polymorphy2(dynamic_class, get_entity_overwrittenby(static_ent, i));
-    if (res)
-      break;
+    ir_entity *ent = get_entity_overwrittenby(static_ent, i);
+    ent = do_resolve_ent_polymorphy(dynamic_class, ent);
+    if (ent) return ent;
   }
-
-  return res;
+  return NULL;
 }
 
 /* Resolve polymorphy in the inheritance relation.
@@ -551,11 +564,11 @@ static entity *resolve_ent_polymorphy2 (type *dynamic_class, entity *static_ent)
  * Returns the dynamically referenced entity if the static entity and the
  * dynamic type are given.
  * Search downwards in overwritten tree. */
-entity *resolve_ent_polymorphy(type *dynamic_class, entity *static_ent) {
-  entity *res;
+ir_entity *resolve_ent_polymorphy(ir_type *dynamic_class, ir_entity *static_ent) {
+  ir_entity *res;
   assert(static_ent && is_entity(static_ent));
 
-  res = resolve_ent_polymorphy2(dynamic_class, static_ent);
+  res = do_resolve_ent_polymorphy(dynamic_class, static_ent);
   assert(res);
 
   return res;
@@ -611,7 +624,7 @@ typedef struct ccs_env {
 void verify_irn_class_cast_state(ir_node *n, void *env) {
   ccs_env             *ccs = (ccs_env *)env;
   ir_class_cast_state this_state = ir_class_casts_any;
-  type                *fromtype, *totype;
+  ir_type             *fromtype, *totype;
   int                 ref_depth = 0;
 
   if (get_irn_op(n) != op_Cast) return;