Rimproved interface to type array.
[libfirm] / ir / tr / entity.c
index 12466f4..f54ee06 100644 (file)
@@ -5,7 +5,13 @@
 **
 */
 
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
 # include <stdlib.h>
+# include <stddef.h>
+# include "entity_t.h"
 # include "entity.h"
 # include "mangle.h"
 
@@ -23,7 +29,6 @@ init_entity (void)
 /*******************************************************************/
 
 entity *
-// new_entity (type_class *owner, ident *name, type *type)
 new_entity (type *owner, ident *name, type *type)
 {
   entity *res;
@@ -38,45 +43,60 @@ new_entity (type *owner, ident *name, type *type)
 
   res->visit = 0;
 
-  /* add entity to the list of entities of the owner. */
-  // res->owner->member[res->owner->n_members] = res;
-  // res->owner->n_members ++;
+  switch (get_type_tpop_code(owner)) {
+  case tpo_class: {
+    add_class_member (owner, res);
+  } break;
+  case tpo_struct: {
+    add_struct_member (owner, res);
+  } break;
+  case tpo_union: {
+    add_union_member (owner, res);
+  } break;
+  case tpo_array: {
+    set_array_element_entity(owner, res);
+  } break;
+  default: assert(0);
+  }
 
   return res;
 }
 
-/*
-  char  *get_entity_name     (entity *);  */
+inline const char *
+get_entity_name (entity *ent) {
+  assert (ent);
+  return id_to_str(get_entity_ident(ent));
+}
 
 ident *
 get_entity_ident    (entity *ent) {
   assert(ent);
   return ent->name;
 }
+
 /*
 void   set_entity_ld_name  (entity *, char *ld_name);
 void   set_entity_ld_ident (entity *, ident *ld_ident);
 */
 
-//inline type_class *
 inline type *
-get_entity_owner (entity *entity) {
-  return entity->owner;
+get_entity_owner (entity *ent) {
+  return ent->owner;
 }
 
 inline void
-// set_entity_owner (entity *entity, type_class *owner) {
-set_entity_owner (entity *entity, type *owner) {
+set_entity_owner (entity *ent, type *owner) {
   assert_legal_owner_of_ent(owner);
-  entity->owner = owner;
+  ent->owner = owner;
 }
 
 inline void   /* should this go into type.c? */
-assert_legal_owner_of_ent(type *type) {
-  assert (type->clss.kind   == k_type_class ||
-          type->uni.kind    == k_type_union ||
-          type->array.kind  == k_type_array ||
-          type->method.kind == k_type_method );
+assert_legal_owner_of_ent(type *owner) {
+  assert (get_type_tpop_code(owner) == tpo_class ||
+          get_type_tpop_code(owner) == tpo_union ||
+          get_type_tpop_code(owner) == tpo_struct ||
+         get_type_tpop_code(owner) == tpo_array);   /* Yes, array has an entity
+                                                       -- to select fields! */
 }
 
 inline ident *
@@ -93,11 +113,36 @@ void   set_entity_ld_ident (entity *, ident *ld_ident);
 */
 
 inline type *
-get_entity_type (entity *entity) {
-  return entity->type;
+get_entity_type (entity *ent) {
+  return ent->type;
+}
+
+inline void
+set_entity_type (entity *ent, type *type) {
+  ent->type = type;
+}
+
+inline int
+get_entity_offset (entity *ent) {
+  return ent->offset;
+}
+
+inline void
+set_entity_offset (entity *ent, int offset) {
+  ent->offset = offset;
+}
+
+inline ir_graph *
+get_entity_irg(entity *ent) {
+  assert (ent);
+  assert (is_method_type(ent->type));
+  return ent->irg;
 }
 
 inline void
-set_entity_type (entity *entity, type *type) {
-  entity->type = type;
+set_entity_irg(entity *ent, ir_graph *irg) {
+  assert (ent && ent->type);
+  assert (irg);
+  assert (is_method_type(ent->type));
+  ent->irg = irg;
 }