for local -- there might be more entities than types for methods...
:wq
[r151]
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;
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 *
*/
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.
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);
}
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) {
assert(method && (method->type_op == type_method));
method->attr.ma.res_type[pos] = type;
}
+
/* typecheck */
bool is_method_type (type *method) {
assert(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;
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) {
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));
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 */
/* 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;
}
* 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
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? */
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 {
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:
/* 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();