Pristine Ack-5.5
[Ack-5.5.git] / lang / cem / cemcom / decspecs.c
1 /*
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".
4  */
5 /* $Id: decspecs.c,v 3.13 1994/06/24 12:03:08 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     */
7
8 #include        "nofloat.h"
9 #include        "assert.h"
10 #include        "Lpars.h"
11 #include        "decspecs.h"
12 #include        "arith.h"
13 #include        "type.h"
14 #include        "level.h"
15 #include        "def.h"
16 #include        "noRoption.h"
17
18 extern char options[];
19 extern int level;
20 extern char *symbol2str();
21
22 struct decspecs null_decspecs;
23
24 do_decspecs(ds)
25         register struct decspecs *ds;
26 {
27         /*      The provisional decspecs ds as obtained from the program
28                 is turned into a legal consistent decspecs.
29         */
30         register struct type *tp = ds->ds_type;
31         
32         ASSERT(level != L_FORMAL1);
33         
34         if (    level == L_GLOBAL &&
35                 (ds->ds_sc == AUTO || ds->ds_sc == REGISTER)
36         )       {
37                 warning("no global %s variable allowed",
38                         symbol2str(ds->ds_sc));
39                 ds->ds_sc = GLOBAL;
40         }
41
42         if (level == L_FORMAL2) {
43                 if (ds->ds_sc_given &&
44                     ds->ds_sc != REGISTER){
45                         error("%s formal illegal", symbol2str(ds->ds_sc));
46                         ds->ds_sc = FORMAL;
47                 }
48         }
49         /*      The tests concerning types require a full knowledge of the
50                 type and will have to be postponed to declare_idf.
51         */
52
53         /* some adjustments as described in RM 8.2 */
54         if (tp == 0 && ds->ds_size == 0 && ds->ds_unsigned == 0) {
55                 ds->ds_notypegiven = 1;
56         }
57         if (tp == 0) {
58                 tp = int_type;
59         }
60         switch (ds->ds_size)    {
61         case SHORT:
62                 if (tp == int_type)
63                         tp = short_type;
64                 else
65                         error("short with illegal type");
66                 break;
67         case LONG:
68                 if (tp == int_type)
69                         tp = long_type;
70                 else
71 #ifndef NOFLOAT
72                 if (tp == float_type)
73                         tp = double_type;
74                 else
75 #endif /* NOFLOAT */
76                         error("long with illegal type");
77                 break;
78         }
79         if (ds->ds_unsigned)    {
80                 switch (tp->tp_fund)    {
81                 case CHAR:
82 #ifndef NOROPTION
83                         if (options['R'])
84                                 warning("unsigned char not allowed");
85 #endif
86                         tp = uchar_type;
87                         break;
88                 case SHORT:
89 #ifndef NOROPTION
90                         if (options['R'])
91                                 warning("unsigned short not allowed");
92 #endif
93                         tp = ushort_type;
94                         break;
95                 case INT:
96                         tp = uint_type;
97                         break;
98                 case LONG:
99 #ifndef NOROPTION
100                         if (options['R'])
101                                 warning("unsigned long not allowed");
102 #endif
103                         tp = ulong_type;
104                         break;
105                 default:
106                         error("unsigned with illegal type");
107                         break;
108                 }
109         }
110         ds->ds_type = tp;
111 }