/** ENTITY **/
/*******************************************************************/
+inline void insert_entity_in_owner (entity *ent) {
+ type *owner = ent->owner;
+ switch (get_type_tpop_code(owner)) {
+ case tpo_class: {
+ add_class_member (owner, ent);
+ } break;
+ case tpo_struct: {
+ add_struct_member (owner, ent);
+ } break;
+ case tpo_union: {
+ add_union_member (owner, ent);
+ } break;
+ case tpo_array: {
+ set_array_element_entity(owner, ent);
+ } break;
+ default: assert(0);
+ }
+}
+
entity *
new_entity (type *owner, ident *name, type *type)
{
res->visit = 0;
- 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);
- }
-
+ /* Remember entity in it's owner. */
+ insert_entity_in_owner (res);
return res;
}
+entity *
+copy_entity_own (entity *old, type *new_owner) {
+ entity *new;
+
+ assert_legal_owner_of_ent(new_owner);
+ if (old->owner == new_owner) return old;
+ new = (entity *) malloc (sizeof (entity));
+ memcpy (new, old, sizeof (entity));
+ new->owner = new_owner;
+
+ insert_entity_in_owner (new);
+
+ return new;
+}
+
+entity *
+copy_entity_name (entity *old, ident *new_name) {
+ entity *new;
+
+ if (old->name == new_name) return old;
+ new = (entity *) malloc (sizeof (entity));
+ memcpy (new, old, sizeof (entity));
+ new->name = new_name;
+ new->ld_name = NULL;
+
+ insert_entity_in_owner (new);
+
+ return new;
+}
+
inline const char *
get_entity_name (entity *ent) {
assert (ent);
return ent->ld_name;
}
-void set_entity_ld_ident (entity *, ident *ld_ident) {
+void set_entity_ld_ident (entity *ent, ident *ld_ident) {
ent->ld_name = ld_ident;
}
/* Creates a new entity.
Automatically inserts the entity as a member of owner. */
entity *new_entity (type *owner, ident *name, type *type);
-
+/* Copies the entity if the new_owner is different from the
+ owner of the old entity. Else returns the old entity.
+ Automatically inserts the new entity as a member of owner. */
+entity *copy_entity_own (entity *old, type *new_owner);
+/* Copies the entity if the new_name is different from the
+ name of the old entity. Else returns the old entity.
+ Automatically inserts the new entity as a member of owner.
+ The mangled name ld_name is set to NULL. */
+entity *copy_entity_name (entity *old, ident *new_name);
/* manipulate fields of entity */
const char *get_entity_name (entity *ent);
ident *get_entity_ident (entity *ent);