Pristine Ack-5.5
[Ack-5.5.git] / lang / cem / cemcom / declarator.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: declarator.c,v 3.11 1994/06/24 12:03:05 ceriel Exp $ */
6 /*      D E C L A R A T O R   M A N I P U L A T I O N           */
7
8 #include        "botch_free.h"
9 #include        <alloc.h>
10 #include        "arith.h"
11 #include        "type.h"
12 #include        "Lpars.h"
13 #include        "declar.h"
14 #include        "idf.h"
15 #include        "label.h"
16 #include        "expr.h"
17 #include        "sizes.h"
18
19 struct declarator null_declarator;
20
21 struct type *
22 declare_type(tp, dc)
23         struct type *tp;
24         struct declarator *dc;
25 {
26         /*      Applies the decl_unary list starting at dc->dc_decl_unary
27                 to the type tp and returns the result.
28         */
29         register struct decl_unary *du = dc->dc_decl_unary;
30
31         while (du)      {
32                 tp = construct_type(du->du_fund, tp, du->du_count);
33                 du = du->next;
34         }
35         return tp;
36 }
37
38 add_decl_unary(dc, fund, count, fm)
39         register struct declarator *dc;
40         arith count;
41         struct formal *fm;
42 {
43         /*      A decl_unary describing a constructor with fundamental
44                 type fund and with size count is inserted in front of the
45                 declarator dc.
46         */
47         register struct decl_unary *new = new_decl_unary();
48
49         new->next = dc->dc_decl_unary;
50         new->du_fund = fund;
51         new->du_count = count;
52         if (fm) {
53                 if (dc->dc_decl_unary)  {
54                         /* paramlist only allowed at first decl_unary   */
55                         error("formal parameter list discarded");
56                 }
57                 else    {
58                         /* register the parameters      */
59                         dc->dc_formal = fm;
60                 }
61         }
62         dc->dc_decl_unary = new;
63 }
64
65 remove_declarator(dc)
66         struct declarator *dc;
67 {
68         /*      The decl_unary list starting at dc->dc_decl_unary is
69                 removed.
70         */
71         register struct decl_unary *du = dc->dc_decl_unary;
72
73         while (du)      {
74                 struct decl_unary *old_du = du;
75
76                 du = du->next;
77                 free_decl_unary(old_du);
78         }
79 }
80
81 reject_params(dc)
82         register struct declarator *dc;
83 {
84         /*      The declarator is checked to have no parameters, if it
85                 is a function.
86         */
87         if (dc->dc_formal)      {
88                 error("non_empty formal parameter pack");
89                 free_formals(dc->dc_formal);
90                 dc->dc_formal = 0;
91         }
92 }
93
94 check_array_subscript(expr)
95         register struct expr *expr;
96 {
97         arith size = expr->VL_VALUE;
98
99         if (size < 0)   {
100                 error("array size is negative");
101                 expr->VL_VALUE = (arith)1;
102         }
103         else
104         if (size == 0) {
105                 warning("array size is 0");
106         }
107         else
108         if (size & ~max_unsigned) {     /* absolutely ridiculous */
109                 expr_error(expr, "overflow in array size");
110                 expr->VL_VALUE = (arith)1;
111         }
112 }