summaryrefslogtreecommitdiffhomepage
path: root/ir/tr
diff options
context:
space:
mode:
authorMatthias Braun <matze@braunis.de>2016-01-30 23:04:07 +0100
committerMatthias Braun <matze@braunis.de>2016-01-30 23:16:16 +0100
commit2600cf449339b336bb932f263a0079f7c9f3e671 (patch)
treee6911131edd0696bdbd3c18f529325bd310f4b46 /ir/tr
parentce0541cfd279c9dd9b8e95f9be0b4b1c2f6abead (diff)
tr: Replace copy_entity_own()/copy_entity_name() with a new clone_entity()
Diffstat (limited to 'ir/tr')
-rw-r--r--ir/tr/entity.c59
-rw-r--r--ir/tr/type.c3
2 files changed, 18 insertions, 44 deletions
diff --git a/ir/tr/entity.c b/ir/tr/entity.c
index 42b5e9f..2814053 100644
--- a/ir/tr/entity.c
+++ b/ir/tr/entity.c
@@ -168,56 +168,29 @@ static void free_entity_attrs(ir_entity *ent)
}
}
-/**
- * Creates a deep copy of an entity.
- */
-static ir_entity *deep_entity_copy(ir_entity *old)
+ir_entity *clone_entity(ir_entity const *const old, ident *const name,
+ ir_type *const owner)
{
- ir_entity *newe = XMALLOC(ir_entity);
+ ir_entity *res = XMALLOC(ir_entity);
- *newe = *old;
+ *res = *old;
/* FIXME: the initializers are NOT copied */
if (is_method_entity(old)) {
/* do NOT copy them, reanalyze. This might be the best solution */
- newe->attr.mtd_attr.param_access = NULL;
- newe->attr.mtd_attr.param_weight = NULL;
+ res->attr.mtd_attr.param_access = NULL;
+ res->attr.mtd_attr.param_weight = NULL;
}
- newe->overwrites = NULL;
- newe->overwrittenby = NULL;
-
- newe->nr = get_irp_new_node_nr();
- hook_new_entity(newe);
- return newe;
-}
-
-ir_entity *copy_entity_own(ir_entity *old, ir_type *new_owner)
-{
- assert(old->kind == k_entity);
- assert(is_compound_type(new_owner));
- assert(get_type_state(new_owner) != layout_fixed);
- if (old->owner == new_owner)
- return old;
-
- /* create a deep copy so we are safe of aliasing and double-freeing. */
- ir_entity *newe = deep_entity_copy(old);
- newe->owner = new_owner;
- add_compound_member(new_owner, newe);
-
- return newe;
-}
-
-ir_entity *copy_entity_name(ir_entity *old, ident *new_name)
-{
- assert(old->kind == k_entity);
- if (old->name == new_name)
- return old;
-
- ir_entity *newe = deep_entity_copy(old);
- newe->name = new_name;
- newe->ld_name = NULL;
- add_compound_member(old->owner, newe);
+ res->overwrites = NULL;
+ res->overwrittenby = NULL;
- return newe;
+ res->nr = get_irp_new_node_nr();
+ res->name = name;
+ res->visit = 0;
+ res->usage = ir_usage_unknown;
+ res->owner = owner;
+ add_compound_member(owner, res);
+ hook_new_entity(res);
+ return res;
}
void free_entity(ir_entity *ent)
diff --git a/ir/tr/type.c b/ir/tr/type.c
index a0453e1..9d210ab 100644
--- a/ir/tr/type.c
+++ b/ir/tr/type.c
@@ -1037,7 +1037,8 @@ ir_type *clone_frame_type(ir_type *type)
ir_type *res = new_type_frame();
for (size_t i = 0, n = get_compound_n_members(type); i < n; ++i) {
ir_entity *ent = get_compound_member(type, i);
- ir_entity *nent = copy_entity_own(ent, res);
+ ident *name = get_entity_name(ent);
+ ir_entity *nent = clone_entity(ent, name, res);
set_entity_link(ent, nent);
set_entity_link(nent, ent);
}