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: decspecs.c,v 1.11 1994/06/27 07:59:12 ceriel Exp $ */
6 /* D E C L A R A T I O N S P E C I F I E R C H E C K I N G */
16 extern char options[];
18 extern char *symbol2str();
19 extern struct type *qualifier_type();
21 struct decspecs null_decspecs;
24 register struct decspecs *ds;
26 /* The provisional decspecs ds as obtained from the program
27 is turned into a legal consistent decspecs.
29 register struct type *tp = ds->ds_type;
31 ASSERT(level != L_FORMAL1);
33 if ( level == L_GLOBAL &&
34 (ds->ds_sc == AUTO || ds->ds_sc == REGISTER)
36 error("no global %s variable allowed",
37 symbol2str(ds->ds_sc));
41 if (level == L_FORMAL2) {
42 if (ds->ds_sc_given &&
43 ds->ds_sc != REGISTER){
44 error("%s formal illegal", symbol2str(ds->ds_sc));
49 /* Since type qualifiers may be associated with types by means
50 of typedefs, we have to perform same basic tests down here.
52 if (tp != (struct type *)0) {
53 if ((ds->ds_typequal & TQ_VOLATILE) && (tp->tp_typequal & TQ_VOLATILE))
54 error("indirect repeated type qualifier");
55 if ((ds->ds_typequal & TQ_CONST) && (tp->tp_typequal & TQ_CONST))
56 error("indirect repeated type qualifier");
57 ds->ds_typequal |= tp->tp_typequal;
60 /* The tests concerning types require a full knowledge of the
61 type and will have to be postponed to declare_idf.
64 /* some adjustments as described in 3.5.2. */
66 ds->ds_notypegiven = 1;
70 register int ds_isshort = (ds->ds_size == SHORT);
72 if (ds->ds_typedef) goto SIZE_ERROR; /* yes */
74 if (ds_isshort) tp = short_type;
76 } else if (tp == double_type && !ds_isshort ) {
80 error("%s with illegal type",symbol2str(ds->ds_size));
82 ds->ds_notypegiven = 0;
84 if (ds->ds_unsigned) {
85 register int ds_isunsigned = (ds->ds_unsigned == UNSIGNED);
87 if (ds->ds_typedef) goto SIGN_ERROR; /* yes */
89 * All integral types are signed by default (char too),
90 * so the case that ds->ds_unsigned == SIGNED can be ignored.
92 if (tp == schar_type) {
93 if (ds_isunsigned) tp = uchar_type;
94 } else if (tp == short_type) {
95 if (ds_isunsigned) tp = ushort_type;
96 } else if (tp == int_type) {
97 if (ds_isunsigned) tp = uint_type;
98 } else if (tp == long_type) {
99 if (ds_isunsigned) tp = ulong_type;
102 error("%s with illegal type"
103 , symbol2str(ds->ds_unsigned));
105 ds->ds_notypegiven = 0;
107 ds->ds_type = qualifier_type(tp, ds->ds_typequal);
110 /* Make tp into a qualified type. This is not as trivial as it
111 may seem. If tp is a fundamental type the qualified type is
112 either existent or will be generated.
113 In case of a complex type the top of the type list will be
114 replaced by a qualified version.
117 qualifier_type(tp, typequal)
118 register struct type *tp;
121 register struct type *dtp = tp;
122 register int fund = tp->tp_fund;
124 while (dtp && dtp->tp_typequal != typequal)
128 dtp = create_type(fund);
129 dtp->tp_unsigned = tp->tp_unsigned;
130 dtp->tp_align = tp->tp_align;
131 dtp->tp_typequal = typequal;
132 dtp->tp_size = tp->tp_size;
134 /* The tp_function field does not exist now. See the comment in the
135 function_of() routine.
137 dtp->tp_function = tp->tp_function;
142 tp->tp_up = qualifier_type(tp->tp_up, typequal);
143 dtp->tp_typequal = typequal = 0;
147 dtp->tp_field = tp->tp_field;
150 case FUNCTION: /* dont't assign tp_proto */
152 dtp->tp_up = tp->tp_up;
157 dtp->tp_idf = tp->tp_idf;
158 dtp->tp_sdef = tp->tp_sdef;
163 dtp->next = tp->next; /* don't know head or tail */