renamed get_type_nameid to get_type_ident
[libfirm] / ir / tr / type.c
index 98b8c48..5588894 100644 (file)
@@ -59,10 +59,38 @@ new_type(tp_op *type_op, ir_mode *mode, ident* name) {
   res->state = layout_undefined;
   res->size = -1;
   res->visit = 0;
+  res -> link = NULL;
 
   return res;
 }
 
+void free_type_attrs(type *tp) {
+  switch(get_type_tpop_code(tp)) {
+  case tpo_class:       { free_class_attrs(tp);       } break;
+  case tpo_struct:      { free_struct_attrs(tp);      } break;
+  case tpo_method:      { free_method_attrs(tp);      } break;
+  case tpo_union:       { free_union_attrs(tp);       } break;
+  case tpo_array:       { free_array_attrs(tp);       } break;
+  case tpo_enumeration: { free_enumeration_attrs(tp); } break;
+  case tpo_pointer:     { free_pointer_attrs(tp);     } break;
+  case tpo_primitive:   { free_primitive_attrs(tp);   } break;
+  default: break;
+  }
+}
+
+/* set/get the link field */
+void *get_type_link(type *tp)
+{
+  assert(tp);
+  return(tp -> link);
+}
+
+void set_type_link(type *tp, void *l)
+{
+  assert(tp);
+  tp -> link = l;
+}
+
 tp_op*      get_type_tpop(type *tp) {
   assert(tp);
   return tp->type_op;
@@ -72,18 +100,22 @@ ident*      get_type_tpop_nameid(type *tp) {
   assert(tp);
   return tp->type_op->name;
 }
+
 const char* get_type_tpop_name(type *tp) {
   assert(tp);
   return id_to_str(tp->type_op->name);
 }
+
 tp_opcode    get_type_tpop_code(type *tp) {
   assert(tp);
   return tp->type_op->code;
 }
+
 ir_mode*    get_type_mode(type *tp) {
   assert(tp);
   return tp->mode;
 }
+
 void        set_type_mode(type *tp, ir_mode* m) {
   assert(tp);
   tp->mode = m;
@@ -91,18 +123,22 @@ void        set_type_mode(type *tp, ir_mode* m) {
   if ((tp->type_op == type_pointer) || (tp->type_op == type_primitive))
     tp->size == get_mode_size(m);
 }
-ident*      get_type_nameid(type *tp) {
+
+ident*      get_type_ident(type *tp) {
   assert(tp);
   return tp->name;
 }
-void        set_type_nameid(type *tp, ident* id) {
+
+void        set_type_ident(type *tp, ident* id) {
   assert(tp);
   tp->name = id;
 }
+
 const char* get_type_name(type *tp) {
   assert(tp);
   return id_to_str(tp->name);
 }
+
 int         get_type_size(type *tp) {
   assert(tp);
   return tp->size;
@@ -170,6 +206,12 @@ type   *new_type_class (ident *name) {
 
   return res;
 }
+inline void free_class_attrs(type *clss) {
+  assert(clss && (clss->type_op == type_class));
+  DEL_ARR_F(clss->attr.ca.members);
+  DEL_ARR_F(clss->attr.ca.subtypes);
+  DEL_ARR_F(clss->attr.ca.supertypes);
+}
 /* manipulate private fields of class type  */
 void    add_class_member   (type *clss, entity *member) {
   assert(clss && (clss->type_op == type_class));
@@ -200,8 +242,13 @@ void    remove_class_member(type *clss, entity *member) {
 }
 
 void    add_class_subtype   (type *clss, type *subtype) {
+  int i;
   assert(clss && (clss->type_op == type_class));
   ARR_APP1 (type *, clss->attr.ca.subtypes, subtype);
+  for (i = 0; i < get_class_n_supertype(subtype); i++)
+    if (get_class_supertype(subtype, i) == clss)
+      /* Class already registered */
+      return;
   ARR_APP1 (type *, subtype->attr.ca.supertypes, clss);
 }
 int     get_class_n_subtype (type *clss) {
@@ -229,8 +276,14 @@ void    remove_class_subtype(type *clss, type *subtype) {
 }
 
 void    add_class_supertype   (type *clss, type *supertype) {
+  int i;
   assert(clss && (clss->type_op == type_class));
+  assert(supertype && (supertype -> type_op == type_class));
   ARR_APP1 (type *, clss->attr.ca.supertypes, supertype);
+  for (i = 0; i < get_class_n_subtype(supertype); i++)
+    if (get_class_subtype(supertype, i) == clss)
+      /* Class already registered */
+      return;
   ARR_APP1 (type *, supertype->attr.ca.subtypes, clss);
 }
 int     get_class_n_supertype (type *clss) {
@@ -273,6 +326,10 @@ type   *new_type_struct (ident *name) {
   res->attr.sa.members = NEW_ARR_F (entity *, 1);
   return res;
 }
+inline void free_struct_attrs (type *strct) {
+  assert(strct && (strct->type_op == type_struct));
+  DEL_ARR_F(strct->attr.sa.members);
+}
 /* manipulate private fields of struct */
 void    add_struct_member   (type *strct, entity *member) {
   assert(strct && (strct->type_op == type_struct));
@@ -322,7 +379,11 @@ type *new_type_method (ident *name, int n_param, int n_res) {
   res->attr.ma.res_type   = (type **) xmalloc (sizeof (type *) * n_res);
   return res;
 }
-
+inline void free_method_attrs(type *method) {
+  assert(method && (method->type_op == type_method));
+  free(method->attr.ma.param_type);
+  free(method->attr.ma.res_type);
+}
 /* manipulate private fields of method. */
 int   get_method_n_params  (type *method) {
   assert(method && (method->type_op == type_method));
@@ -370,6 +431,10 @@ type  *new_type_uni (ident *name) {
   res->attr.ua.members = NEW_ARR_F (entity *, 1);
   return res;
 }
+inline void free_union_attrs (type *uni) {
+  assert(uni && (uni->type_op == type_union));
+  DEL_ARR_F(uni->attr.ua.members);
+}
 /* manipulate private fields of struct */
 #if 0
 int    get_union_n_types      (type *uni) {
@@ -448,6 +513,11 @@ type *new_type_array         (ident *name, int n_dimensions,
   new_entity(res, name, element_type);
   return res;
 }
+inline void free_array_attrs (type *array) {
+  assert(array && (array->type_op == type_array));
+  free(array->attr.aa.lower_bound);
+  free(array->attr.aa.upper_bound);
+}
 
 /* manipulate private fields of array type */
 int   get_array_n_dimensions (type *array) {
@@ -512,6 +582,11 @@ type   *new_type_enumeration    (ident *name, int n_enums) {
   res->attr.ea.enum_nameid = (ident  **) xmalloc (sizeof (ident  *) * n_enums);
   return res;
 }
+inline void free_enumeration_attrs(type *enumeration) {
+  assert(enumeration && (enumeration->type_op == type_enumeration));
+  free(enumeration->attr.ea.enumer);
+  free(enumeration->attr.ea.enum_nameid);
+}
 
 /* manipulate fields of enumeration type. */
 int     get_enumeration_n_enums (type *enumeration) {
@@ -558,6 +633,9 @@ type *new_type_pointer           (ident *name, type *points_to) {
   res->state = layout_fixed;
   return res;
 }
+inline void free_pointer_attrs (type *pointer) {
+  assert(pointer && (pointer->type_op == type_pointer));
+}
 /* manipulate fields of type_pointer */
 void  set_pointer_points_to_type (type *pointer, type *type) {
   assert(pointer && (pointer->type_op == type_pointer));
@@ -587,6 +665,9 @@ type *new_type_primitive (ident *name, ir_mode *mode) {
   res->state = layout_fixed;
   return res;
 }
+inline void free_primitive_attrs (type *primitive) {
+  assert(primitive && (primitive->type_op == type_primitive));
+}
 
 /* typecheck */
 bool  is_primitive_type  (type *primitive) {