2 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3 * See the copyright notice in the ACK home directory, in the file "Copyright".
5 /* $Id: type.c,v 3.12 1994/06/24 12:06:40 ceriel Exp $ */
6 /* T Y P E D E F I N I T I O N M E C H A N I S M */
9 #include "nobitfield.h"
10 #include "botch_free.h"
20 struct type *function_of(), *array_of();
22 struct type *field_of();
23 #endif /* NOBITFIELD */
25 /* To be created dynamically in main() from defaults or from command
29 *char_type, *uchar_type,
30 *short_type, *ushort_type,
31 *word_type, *uword_type,
32 *int_type, *uint_type,
33 *long_type, *ulong_type,
35 *float_type, *double_type,
37 *void_type, *label_type,
38 *string_type, *funint_type, *error_type;
40 struct type *pa_type; /* Pointer-Arithmetic type */
46 /* A brand new struct type is created, and its tp_fund set
49 register struct type *ntp = new_type();
52 ntp->tp_size = (arith)-1;
58 construct_type(fund, tp, count)
59 register struct type *tp;
60 arith count; /* for fund == ARRAY only */
62 /* fund must be a type constructor: FIELD, FUNCTION, POINTER or
63 ARRAY. The pointer to the constructed type is returned.
65 register struct type *dtp;
72 #endif /* NOBITFIELD */
75 if (tp->tp_fund == FUNCTION) {
76 error("function cannot yield function");
79 if (tp->tp_fund == ARRAY) {
80 error("function cannot yield array");
84 dtp = function_of(tp);
90 if (count >= 0 && tp->tp_size < 0) {
91 error("cannot construct array of unknown type");
94 else if (tp->tp_size == 0) /* CJ */
95 warning("array elements have size 0");
96 if (count >= (arith)0)
98 dtp = array_of(tp, count);
101 crash("bad constructor in construct_type");
109 register struct type *tp;
111 register struct type *dtp = tp->tp_function;
114 tp->tp_function = dtp = create_type(FUNCTION);
116 dtp->tp_size = pointer_size;
117 dtp->tp_align = pointer_align;
124 register struct type *tp;
126 register struct type *dtp = tp->tp_pointer;
129 tp->tp_pointer = dtp = create_type(POINTER);
130 dtp->tp_unsigned = 1;
132 dtp->tp_size = pointer_size;
133 dtp->tp_align = pointer_align;
140 register struct type *tp;
143 register struct type *dtp = tp->tp_array;
145 /* look for a type with the right size */
146 while (dtp && dtp->tp_size != count)
150 dtp = create_type(ARRAY);
152 dtp->tp_size = count;
153 dtp->tp_align = tp->tp_align;
154 dtp->next = tp->tp_array;
163 register struct type *tp;
165 register struct type *dtp = create_type(FIELD);
168 dtp->tp_align = tp->tp_align;
169 dtp->tp_size = tp->tp_size;
172 #endif /* NOBITFIELD */
179 arith sz = tp->tp_size;
182 error("size of %s unknown", nm);
192 /* Decoding a typedef-ed identifier: if the size is yet
193 unknown we have to make copy of the type descriptor to
194 prevent garbage at the initialisation of arrays with
197 register struct type *tp = idf->id_def->df_type;
199 if ( tp->tp_size < (arith)0 && tp->tp_fund == ARRAY) {
202 /* this is really a structure assignment, AAGH!!! */
214 return ((pos + al - 1) / al) * al;
218 standard_type(fund, sgn, algn, sz)
221 register struct type *tp = create_type(fund);
223 tp->tp_unsigned = sgn;