Commit a96ece7b authored by Matthias Braun's avatar Matthias Braun
Browse files

typerep: freeing a type frees contained entities

Types "own" entities, so they should also free them when they get freed.
parent 62a070ee
......@@ -1070,20 +1070,11 @@ FIRM_API int check_type(ir_type *tp);
*/
FIRM_API int tr_verify(void);
/** Frees all entities associated with a type.
* Does not free the array entity.
* Warning: ensure these entities are not referenced anywhere else.
*/
FIRM_API void free_type_entities(ir_type *tp);
/** Frees the memory used by the type.
/**
* Frees the memory used by the type.
*
* Removes the type from the type list. Does not free the entities
* belonging to the type, except for the array element entity. Does
* not free if tp is "none" or "unknown". Frees entities in value
* param subtypes of method types!!! Make sure these are not
* referenced any more. Further make sure there is no pointer type
* that refers to this type.
* Removes the type from the type list and frees all entities
* belonging to the type.
*/
FIRM_API void free_type(ir_type *tp);
......
......@@ -131,8 +131,8 @@ void free_ir_prog(void)
for (i = get_irp_n_irgs(); i > 0;)
free_ir_graph(get_irp_irg(--i));
free_type_entities(get_glob_type());
/* must iterate backwards here */
/* free entities first to avoid entity types being destroyed before
* the entities using them */
for (i = get_irp_n_types(); i > 0;)
free_type_entities(get_irp_type(--i));
......
......@@ -145,10 +145,26 @@ ir_type *new_type(const tp_op *type_op, ir_mode *mode, type_dbg_info *db)
return res;
}
void free_type_entities(ir_type *tp)
{
const tp_op *op = get_type_tpop(tp);
if (op->ops.free_entities != NULL)
op->ops.free_entities(tp);
}
static void free_type_attrs(ir_type *tp)
{
const tp_op *tpop = get_type_tpop(tp);
if (tpop->ops.free_attrs)
tpop->ops.free_attrs(tp);
}
void free_type(ir_type *tp)
{
const tp_op *op = get_type_tpop(tp);
free_type_entities(tp);
/* Remove from list of all types */
remove_irp_type(tp);
/* Free the attributes of the type. */
......@@ -163,22 +179,6 @@ void free_type(ir_type *tp)
free(tp);
}
void free_type_entities(ir_type *tp)
{
const tp_op *tpop = get_type_tpop(tp);
if (tpop->ops.free_entities)
tpop->ops.free_entities(tp);
}
void free_type_attrs(ir_type *tp)
{
const tp_op *tpop = get_type_tpop(tp);
if (tpop->ops.free_attrs)
tpop->ops.free_attrs(tp);
}
void *(get_type_link)(const ir_type *tp)
{
return _get_type_link(tp);
......
......@@ -196,7 +196,8 @@ struct ir_type {
* initialized. The type is in state layout_undefined.
*/
ir_type *new_type(const tp_op *type_op, ir_mode *mode, type_dbg_info *db);
void free_type_attrs(ir_type *tp);
void free_type_entities(ir_type *tp);
void free_class_entities (ir_type *clss);
void free_struct_entities (ir_type *strct);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment