1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
4 ** Authors: Martin Trapp, Christian Schaefer &
7 ** type.c: datastructures to hold type information.
12 unsigned long type_visited = 0;
19 /*******************************************************************/
21 /*******************************************************************/
24 new_type_class (ident *name)//, int members)
28 res = (type_class *) xmalloc (sizeof (type_class));
29 res->kind = k_type_class;
32 // res->n_members = 0;
33 // res->max_members = members;
34 // res->member = (entity **) xmalloc (sizeof (entity*) * members);
41 /* manipulate fields of type_class */
44 get_class_name (type_class *class) {
46 return ID_TO_STR(class->name);
51 get_class_ident (type_class *class) {
57 void set_class_name (type_class *class, char *name);
58 void set_class_ident (type_class *class, ident* ident);
62 /*******************************************************************/
64 /*******************************************************************/
67 new_type_strct (ident *name)//, int members)
71 res = (type_strct *) xmalloc (sizeof (type_strct));
72 res->kind = k_type_strct;
75 // res->n_members = 0;
76 // res->max_members = members;
77 // res->member = (entity **) xmalloc (sizeof (entity*) * members);
84 /* manipulate fields of type_strct */
87 get_strct_name (type_strct *strct) {
89 return ID_TO_STR(strct->name);
94 get_strct_ident (type_strct *strct) {
100 void set_strct_name (type_strct *strct, char *name);
101 void set_strct_ident (type_strct *strct, ident* ident);
105 /*******************************************************************/
107 /*******************************************************************/
109 /* create a new type_method */
111 new_type_method (ident *name, int arity, int n_res)
115 res = (type_method *) xmalloc (sizeof (type_method));
116 res->kind = k_type_method;
117 res->name = name; // do I need the name, or is the name in entity sufficient?
119 res->param_type = (type **) xmalloc (sizeof (type *) * arity);
121 res->res_type = (type **) xmalloc (sizeof (type *) * n_res);
128 /* manipulate fields of type_method */
131 get_method_name (type_method *method) {
133 return ID_TO_STR(method->name);
138 get_method_ident (type_method *method) {
144 void set_method_name (type_method *method, char *name);
145 void set_method_ident (type_method *method, ident* ident);
149 get_method_arity (type_method *method) {
150 return method->arity;
155 set_method_arity (type_method *method, int arity) {
156 method->arity = arity;
157 / change array size, somehow copy. *
162 get_method_param_type(type_method *method, int pos) {
163 return method->param_type[pos];
167 set_method_param_type(type_method *method, int pos, type* type) {
168 method->param_type[pos] = type;
173 get_method_n_res (type_method *method) {
174 return method->n_res;
179 set_method_n_res (type_method *method, int n_res) {
180 method->n_res = n_res;
185 get_method_res_type(type_method *method, int pos) {
186 return method->res_type[pos];
190 set_method_res_type(type_method *method, int pos, type* type) {
191 method->res_type[pos] = type;
195 /*******************************************************************/
197 /*******************************************************************/
199 /* create a new type_union -- set unioned types by hand. */
201 new_type_union (ident *name, int n_types)
205 res = (type_union *) xmalloc (sizeof (type_union));
206 res->kind = k_type_union;
207 res->name = name; // do I need a name?
208 res->n_types = n_types;
210 res->unioned_type = (int *) xmalloc (sizeof (int) * n_types);
218 /* manipulate fields of type_union */
221 get_union_name (type_union *uni) {
223 return ID_TO_STR(uni->name);
228 get_union_ident (type_union *uni) {
234 void set_union_name (type_union *union, char *name);
235 void set_union_ident (type_union *union, ident* ident);
238 int get_union_n_types (type_union *union);
239 void set_union_n_types (type_union *union, int n);
240 type *get_union_unioned_type (type_union *union, int pos);
241 void set_union_unioned_type (type_union *union, int pos, type *type);
244 /*******************************************************************/
246 /*******************************************************************/
248 /* create a new type_array */
250 new_type_array (ident *name, int n_dimensions)
254 res = (type_array *) xmalloc (sizeof (type_array));
255 res->kind = k_type_array;
257 res->n_dimensions = n_dimensions;
258 res->lower_bound = (int *) xmalloc (sizeof (int) * n_dimensions);
259 res->upper_bound = (int *) xmalloc (sizeof (int) * n_dimensions);
266 /* manipulate fields of type_array */
269 get_array_name (type_array *array) {
271 return ID_TO_STR(array->name);
276 get_array_ident (type_array *array) {
282 void set_array_name (type_array *array, char *name);
283 void set_array_ident (type_array *array, ident* ident);
287 set_array_dimensions (type_array* array, int n) {
288 array->n_dimensions = n;
292 get_array_dimensions (type_array* array) {
293 return array->n_dimensions;
297 set_array_bounds (type_array* array, int dimension, int lower_bound,
299 array->lower_bound[dimension-1] = lower_bound;
300 array->upper_bound[dimension-1] = upper_bound;
304 set_array_lower_bound (type_array* array, int dimension, int lower_bound) {
305 array->lower_bound[dimension-1] = lower_bound;
309 set_array_upper_bound (type_array* array, int dimension, int upper_bound) {
310 array->upper_bound[dimension-1] = upper_bound;
314 get_array_lower_bound (type_array* array, int dimension) {
315 return array->lower_bound[dimension-1];
319 get_array_upper_bound (type_array* array, int dimension) {
320 return array->upper_bound[dimension-1];
323 inline void set_array_element_type (type_array *array, type *type) {
324 array->element_type = type;
328 get_array_element_type (type_array *array) {
329 return array->element_type;
333 /*******************************************************************/
334 /** TYPE_ENUMERATION **/
335 /*******************************************************************/
337 /* create a new type enumeration -- set the enumerators independently */
339 new_type_enumeration (ident *name /* , int n_enums */)
341 type_enumeration *res;
343 res = (type_enumeration *) xmalloc (sizeof (type_enumeration));
344 res->kind = k_type_enumeration;
347 res->n_enums = n_enums;
348 res->enum = (int *) xmalloc (sizeof (int) * n_enums);
356 /* manipulate fields of type_enumeration */
359 get_enumeration_name (type_enumeration *enumeration) {
361 return ID_TO_STR(enumeration->name);
366 get_enumeration_ident (type_enumeration *enumeration) {
368 return enumeration->name;
372 void set_enumeration_name (type_enumeration *enumeration, char *name);
373 void set_enumeration_ident (type_enumeration *enumeration, ident* ident);
376 void set_enumeration_n_enums (type_enumeration *enumeration, int n);
377 int *get_enumeration_n_enums (type_enumeration *enumeration);
378 void set_enumeration_enum (type_enumeration *enumeration, int pos,
380 ir_node *get_enumeration_enum (type_enumeration *enumeration, int pos);
384 /*******************************************************************/
386 /*******************************************************************/
388 /* create a new type pointer */
390 new_type_pointer (ident *name, type *points_to)
394 res = (type_pointer *) xmalloc (sizeof (type_pointer));
395 res->kind = k_type_pointer;
397 res->points_to = points_to;
404 /* manipulate fields of type_pointer */
407 get_pointer_name (type_pointer *pointer) {
409 return ID_TO_STR(pointer->name);
414 get_pointer_ident (type_pointer *pointer) {
416 return pointer->name;
420 void set_pointer_name (type_pointer *pointer, char *name);
421 void set_pointer_ident (type_pointer *pointer, ident* ident);
425 set_pointer_points_to_type (type_pointer *pointer, type* type) {
426 pointer->points_to = type;
430 get_pointer_points_to_type (type_pointer *pointer) {
431 return pointer->points_to;
435 /*******************************************************************/
436 /** TYPE_PRIMITIVE **/
437 /*******************************************************************/
439 /* create a new type_primitive */
440 inline type_primitive *
441 new_type_primitive (ident *name, ir_mode *mode)
445 res = (type_primitive *) xmalloc (sizeof (type_primitive));
446 res->kind = k_type_primitive;
455 /* manipulate fields of type_primitive */
459 get_primitive_name (type_primitive *primitive) {
461 return ID_TO_STR(primitive->name);
466 get_primitive_ident (type_primitive *primitive) {
468 return primitive->name;
471 void set_primitive_name (type_primitive *primitive, char *name);
472 void set_primitive_ident (type_primitive *primitive, ident* ident);
476 get_primitive_mode (type_primitive *primitive) {
477 return primitive->mode;
481 set_primitive_mode (type_primitive *primitive, ir_mode *mode) {
482 primitive->mode = mode;
488 /*******************************************************************/
489 /** To manage all different types the same **/
490 /*******************************************************************/
494 is_type(void *thing) {
497 kind = get_kind(thing);
498 if ( (kind == k_type_class)
499 || (kind == k_type_strct)
500 || (kind == k_type_method)
501 || (kind == k_type_union)
502 || (kind == k_type_array)
503 || (kind == k_type_enumeration)
504 || (kind == k_type_pointer)
505 || (kind == k_type_primitive))