Commit a264fae9 authored by Götz Lindenmaier's avatar Götz Lindenmaier
Browse files

Added memberlist to union. Method type will not need a member list

for local -- there might be more entities than types for methods...

:wq

[r151]
parent a78311ba
......@@ -51,12 +51,9 @@ new_entity (type *owner, ident *name, type *type)
add_struct_member (owner, res);
} break;
case tpo_union: {
/* not implemented */
add_union_member (owner, res);
} break;
case tpo_method: {
/* not implemented */
} break;
default: ;
default: assert(0);
}
return res;
......@@ -94,8 +91,7 @@ inline void /* should this go into type.c? */
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_array ||
get_type_tpop_code(owner) == tpo_method );
get_type_tpop_code(owner) == tpo_struct);
}
inline ident *
......
......@@ -65,10 +65,10 @@ tp_op * new_tpop (tp_opcode code, ident *name, size_t attr_size);
*/
void init_tpop (void);
/****f* tpop/get_topo_attr_size
/****f* tpop/get_tpop_attr_size
*
* NAME
* get_topo_attr_size - Returns the size of the attribute to this kind
* get_tpop_attr_size - Returns the size of the attribute to this kind
* of type.
* NOTE
* Internal feature.
......
......@@ -82,6 +82,9 @@ ir_mode* get_type_mode(type *tp) {
void set_type_mode(type *tp, ir_mode* m) {
assert(tp);
tp->mode = m;
/* For pointer and primitive size depends on the mode. */
if ((tp->type_op == type_pointer) || (tp->type_op == type_primitive))
tp->size == get_mode_size(m);
}
ident* get_type_nameid(type *tp) {
assert(tp);
......@@ -101,6 +104,8 @@ int get_type_size(type *tp) {
}
void set_type_size(type *tp, int size) {
assert(tp);
/* For pointer and primitive size depends on the mode. */
assert((tp->type_op != type_pointer) && (tp->type_op != type_primitive));
tp->size = size;
}
unsigned long get_type_visited(type *tp) {
......@@ -275,6 +280,7 @@ void set_method_res_type(type *method, int pos, type* type) {
assert(method && (method->type_op == type_method));
method->attr.ma.res_type[pos] = type;
}
/* typecheck */
bool is_method_type (type *method) {
assert(method);
......@@ -287,15 +293,16 @@ bool is_method_type (type *method) {
/*******************************************************************/
/* create a new type uni */
type *new_type_uni (ident *name, int n_types) {
type *new_type_uni (ident *name) {
type *res;
res = new_type(type_union, NULL, name);
res->attr.ua.n_types = n_types;
res->attr.ua.unioned_type = (type **) xmalloc (sizeof (type *) * n_types);
res->attr.ua.delim_names = (ident **) xmalloc (sizeof (ident *) * n_types);
/*res->attr.ua.unioned_type = (type **) xmalloc (sizeof (type *) * n_types);
res->attr.ua.delim_names = (ident **) xmalloc (sizeof (ident *) * n_types); */
res->attr.ua.members = NEW_ARR_F (entity *, 1);
return res;
}
/* manipulate private fields of struct */
#if 0
int get_union_n_types (type *uni) {
assert(uni && (uni->type_op == type_union));
return uni->attr.ua.n_types;
......@@ -320,6 +327,23 @@ void set_union_delim_nameid (type *uni, int pos, ident *id) {
assert(uni && (uni->type_op == type_union));
uni->attr.ua.delim_names[pos] = id;
}
#endif
int get_union_n_members (type *uni) {
assert(uni && (uni->type_op == type_union));
return (ARR_LEN (uni->attr.ua.members))-1;
}
void add_union_member (type *uni, entity *member) {
assert(uni && (uni->type_op == type_union));
ARR_APP1 (entity *, uni->attr.ua.members, member);
}
entity *get_union_member (type *uni, int pos) {
assert(uni && (uni->type_op == type_union));
return uni->attr.ua.members[pos+1];
}
void set_union_member (type *uni, int pos, entity *member) {
assert(uni && (uni->type_op == type_union));
uni->attr.ua.members[pos+1] = member;
}
/* typecheck */
bool is_union_type (type *uni) {
......@@ -341,6 +365,7 @@ type *new_type_array (ident *name, int n_dimensions) {
res->attr.aa.upper_bound = (int *) xmalloc (sizeof (int) * n_dimensions);
return res;
}
/* manipulate private fields of array type */
int get_array_n_dimensions (type *array) {
assert(array && (array->type_op == type_array));
......@@ -437,6 +462,7 @@ type *new_type_pointer (ident *name, type *points_to) {
type *res;
res = new_type(type_pointer, mode_p, name);
res->attr.pa.points_to = points_to;
res->size = get_mode_size(res->mode);
return res;
}
/* manipulate fields of type_pointer */
......@@ -463,7 +489,8 @@ bool is_pointer_type (type *pointer) {
/* create a new type primitive */
type *new_type_primitive (ident *name, ir_mode *mode) {
type *res;
res = new_type(type_primitive, mode_p, name);
res = new_type(type_primitive, mode, name);
res->size = get_mode_size(mode);
return res;
}
......
......@@ -267,28 +267,33 @@ bool is_method_type (type *method);
* The union type represents union types.
* ATTRIBUTES
* n_types Number of unioned types.
* unioned_type A list of unioned types.
* delim_names Idents for the names of the union delimiters.
* members Entities for unioned types. Fixed length array.
* SOURCE
*/
/* create a new type union
The arrays for the types and idents are not initialized by the
constructor. */
type *new_type_union (ident *name, int n_types);
The array with the entities is not initalized by the constructor. */
type *new_type_union (ident *name);
/* manipulate private fields of struct */
int get_union_n_types (type *uni);
int get_union_n_members (type *uni);
void add_union_member (type *uni, entity *member);
entity *get_union_member (type *uni, int pos);
void set_union_member (type *uni, int pos, entity *member);
/* typecheck */
bool is_union_type (type *uni);
/*****/
#if 0
/* We don't need these if the union has entities, which it now
does. The entities are necessary for the analysis algorithms. */
type *get_union_unioned_type (type *uni, int pos);
void set_union_unioned_type (type *uni, int pos, type *type);
ident *get_union_delim_nameid (type *uni, int pos);
const char *get_union_delim_name (type *uni, int pos);
void set_union_delim_nameid (type *uni, int pos, ident *id);
/* typecheck */
bool is_union_type (type *uni);
/*****/
#endif
/****** type/array
* NAME
......
......@@ -33,7 +33,7 @@ typedef struct {
typedef struct {
int n_params; /* number of parameters */
type **param_type; /* code generation needs this information.
Should it be generated by the frontend,
@@@ Should it be generated by the frontend,
or does this impose unnecessary work for
optimizations that change the parameters of
methods? */
......@@ -43,8 +43,11 @@ typedef struct {
typedef struct {
int n_types;
type **unioned_type;/* a list of unioned types. */
ident **delim_names; /* names of the union delimiters. */
/* type **unioned_type; * a list of unioned types. */
/* ident **delim_names; * names of the union delimiters. */
entity **members; /* fields of this union. No method entities
allowed. */
} uni_attr;
typedef struct {
......
......@@ -95,8 +95,8 @@ void type_walk_2(type_or_ent *tore,
break;
case tpo_union:
{
for (i = 0; i < get_union_n_types(tp); i++)
type_walk_2((type_or_ent *)get_union_unioned_type(tp, i), pre, post, env);
for (i = 0; i < get_union_n_members(tp); i++)
type_walk_2((type_or_ent *)get_union_member(tp, i), pre, post, env);
}
break;
case tpo_array:
......
......@@ -58,6 +58,9 @@ main(void)
/* make basic type information for primitive type int.*/
prim_t_int = new_type_primitive(id_from_str ("int", 3), mode_i);
printf(" Hier %s\n", get_mode_name(get_type_mode(prim_t_int)));
/* first build procedure main */
printf("\nCreating an IR graph: OO_PROGRAM_EXAMPLE...\n");
owner = get_glob_type();
......
Supports Markdown
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