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

Get rid of last tp_op_op and the callback structure

parent 6f319bb1
...@@ -23,14 +23,12 @@ const tp_op *type_primitive; const tp_op *get_tpop_primitive(void) { return type ...@@ -23,14 +23,12 @@ const tp_op *type_primitive; const tp_op *get_tpop_primitive(void) { return type
const tp_op *tpop_code; const tp_op *get_tpop_code_type(void) { return tpop_code; } const tp_op *tpop_code; const tp_op *get_tpop_code_type(void) { return tpop_code; }
const tp_op *tpop_unknown; const tp_op *get_tpop_unknown (void) { return tpop_unknown; } const tp_op *tpop_unknown; const tp_op *get_tpop_unknown (void) { return tpop_unknown; }
const tp_op *new_tpop(tp_opcode code, ident *name, size_t attr_size, const tp_op *new_tpop(tp_opcode code, ident *name, size_t attr_size)
const tp_op_ops *ops)
{ {
tp_op *res = XMALLOC(tp_op); tp_op *res = XMALLOC(tp_op);
res->code = code; res->code = code;
res->name = name; res->name = name;
res->attr_size = attr_size; res->attr_size = attr_size;
res->ops = *ops;
return res; return res;
} }
...@@ -39,39 +37,17 @@ void free_tpop(const tp_op *tpop) ...@@ -39,39 +37,17 @@ void free_tpop(const tp_op *tpop)
free((void*)tpop); free((void*)tpop);
} }
static const tp_op_ops
/** tpop operations for class types */
class_ops = {
.free_attrs = free_class_attrs,
},
/** tpop operations for struct types */
struct_ops = {
.free_attrs = free_compound_attrs,
},
/** tpop operations for method types */
method_ops = {
.free_attrs = free_method_attrs,
},
/** tpop operations for union types */
union_ops = {
.free_attrs = free_compound_attrs,
},
null_ops = {
.free_attrs = NULL,
}
;
void init_tpop(void) void init_tpop(void)
{ {
type_class = new_tpop(tpo_class, NEW_IDENT("class"), sizeof(cls_attr), &class_ops); type_class = new_tpop(tpo_class, NEW_IDENT("class"), sizeof(cls_attr) );
type_struct = new_tpop(tpo_struct, NEW_IDENT("struct"), sizeof(compound_attr), &struct_ops); type_struct = new_tpop(tpo_struct, NEW_IDENT("struct"), sizeof(compound_attr));
type_method = new_tpop(tpo_method, NEW_IDENT("method"), sizeof(mtd_attr), &method_ops); type_method = new_tpop(tpo_method, NEW_IDENT("method"), sizeof(mtd_attr) );
type_union = new_tpop(tpo_union, NEW_IDENT("union"), sizeof(compound_attr), &union_ops); type_union = new_tpop(tpo_union, NEW_IDENT("union"), sizeof(compound_attr));
type_array = new_tpop(tpo_array, NEW_IDENT("array"), sizeof(arr_attr), &null_ops); type_array = new_tpop(tpo_array, NEW_IDENT("array"), sizeof(arr_attr) );
type_pointer = new_tpop(tpo_pointer, NEW_IDENT("pointer"), sizeof(ptr_attr), &null_ops); type_pointer = new_tpop(tpo_pointer, NEW_IDENT("pointer"), sizeof(ptr_attr) );
type_primitive = new_tpop(tpo_primitive, NEW_IDENT("primitive"), 0, &null_ops); type_primitive = new_tpop(tpo_primitive, NEW_IDENT("primitive"), 0 );
tpop_code = new_tpop(tpo_code, NEW_IDENT("code"), 0, &null_ops); tpop_code = new_tpop(tpo_code, NEW_IDENT("code"), 0 );
tpop_unknown = new_tpop(tpo_unknown, NEW_IDENT("Unknown"), 0, &null_ops); tpop_unknown = new_tpop(tpo_unknown, NEW_IDENT("Unknown"), 0 );
} }
void finish_tpop(void) void finish_tpop(void)
......
...@@ -19,20 +19,11 @@ ...@@ -19,20 +19,11 @@
#define get_tpop_code(op) _get_tpop_code(op) #define get_tpop_code(op) _get_tpop_code(op)
#define get_tpop_ident(op) _get_tpop_ident(op) #define get_tpop_ident(op) _get_tpop_ident(op)
/**
* tp_op operations.
*/
typedef struct tp_op_ops {
/** Called to free the attributes of a type. */
void (*free_attrs)(ir_type *type);
} tp_op_ops;
/** The type opcode. */ /** The type opcode. */
struct tp_op { struct tp_op {
tp_opcode code; /**< The tpop code. */ tp_opcode code; /**< The tpop code. */
ident *name; /**< The name of the type opcode. */ ident *name; /**< The name of the type opcode. */
size_t attr_size; /**< The attribute size for a type of this opcode. */ size_t attr_size; /**< The attribute size for a type of this opcode. */
tp_op_ops ops; /**< tp_op operations. */
}; };
/** /**
...@@ -46,11 +37,9 @@ struct tp_op { ...@@ -46,11 +37,9 @@ struct tp_op {
* @param name an ident for the name of the type opcode. * @param name an ident for the name of the type opcode.
* @param attr_size the size of the attributes necessary for a type with * @param attr_size the size of the attributes necessary for a type with
* this opcode * this opcode
* @param ops the tp_op operations for this type
* @return A new type opcode. * @return A new type opcode.
*/ */
tp_op const *new_tpop(tp_opcode code, ident *name, size_t attr_size, tp_op const *new_tpop(tp_opcode code, ident *name, size_t attr_size);
tp_op_ops const *ops);
/** /**
* Free a tpop data structure. * Free a tpop data structure.
......
...@@ -135,11 +135,28 @@ void free_type_entities(ir_type *const type) ...@@ -135,11 +135,28 @@ void free_type_entities(ir_type *const type)
free_compound_entities(type); free_compound_entities(type);
} }
static void free_type_attrs(ir_type *tp) static void free_type_attrs(ir_type *const type)
{ {
const tp_op *tpop = get_type_tpop(tp); switch (type->type_op->code) {
if (tpop->ops.free_attrs) case tpo_class:
tpop->ops.free_attrs(tp); free_class_attrs(type);
return;
case tpo_union:
case tpo_struct:
free_compound_attrs(type);
return;
case tpo_method:
free_method_attrs(type);
return;
case tpo_code:
case tpo_primitive:
case tpo_pointer:
case tpo_array:
case tpo_unknown:
case tpo_uninitialized:
return;
}
panic("Invalid type");
} }
void free_type(ir_type *tp) void free_type(ir_type *tp)
......
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