Pristine Ack-5.5
[Ack-5.5.git] / lang / m2 / comp / type.H
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  * Author: Ceriel J.H. Jacobs
6  */
7
8 /* T Y P E   D E S C R I P T O R   S T R U C T U R E */
9
10 /* $Id: type.H,v 1.57 1996/08/14 07:42:36 ceriel Exp $ */
11
12 #include "dbsymtab.h"
13
14 struct paramlist {              /* structure for parameterlist of a PROCEDURE */
15         struct paramlist *par_next;
16         struct def *par_def;    /* "df" of parameter */
17 #define IsVarParam(xpar)        ((int) ((xpar)->par_def->df_flags & D_VARPAR))
18 #define TypeOfParam(xpar)       ((xpar)->par_def->df_type)
19 };
20
21 typedef struct paramlist t_param;
22
23 /* ALLOCDEF "paramlist" 20 */
24
25 struct enume {
26         struct def *en_enums;   /* Definitions of enumeration literals */
27         arith en_ncst;          /* Number of constants */
28         label en_rck;           /* Label of range check descriptor */
29 #define enm_enums       tp_value.tp_enum->en_enums
30 #define enm_ncst        tp_value.tp_enum->en_ncst
31 #define enm_rck         tp_value.tp_enum->en_rck
32 };
33
34 /* ALLOCDEF "enume" 5 */
35
36 struct subrange {
37         arith su_lb, su_ub;     /* lower bound and upper bound */
38         label su_rck;           /* label of range check descriptor */
39 #define sub_lb  tp_value.tp_subrange->su_lb
40 #define sub_ub  tp_value.tp_subrange->su_ub
41 #define sub_rck tp_value.tp_subrange->su_rck
42 };
43
44 /* ALLOCDEF "subrange" 5 */
45
46 struct array {
47         struct type *ar_elem;   /* type of elements */
48         label ar_descr;         /* label of array descriptor */
49         arith ar_elsize;        /* size of elements */
50         arith ar_low;           /* lower bound of index */
51         arith ar_high;          /* upper bound of index */
52 #define arr_elem        tp_value.tp_arr->ar_elem
53 #define arr_descr       tp_value.tp_arr->ar_descr
54 #define arr_elsize      tp_value.tp_arr->ar_elsize
55 #define arr_low         tp_value.tp_arr->ar_low
56 #define arr_high        tp_value.tp_arr->ar_high
57 };
58
59 /* ALLOCDEF "array" 5 */
60
61 struct record {
62         struct scope *rc_scope; /* scope of this record */
63                                 /* members are in the symbol table */
64 #define rec_scope       tp_value.tp_record.rc_scope
65 };
66
67 struct proc {
68         struct paramlist *pr_params;
69         arith pr_nbpar;         /* number of bytes parameters accessed */
70 #define prc_params      tp_value.tp_proc.pr_params
71 #define prc_nbpar       tp_value.tp_proc.pr_nbpar
72 };
73
74 struct set {
75         arith st_low;           /* lowerbound of subrange type of set */
76         unsigned st_sz;         /* size of constant set in compiler */
77 #define set_low         tp_value.tp_set.st_low
78 #define set_sz          tp_value.tp_set.st_sz
79 };
80
81 struct type     {
82         struct type *tp_next;   /* used with ARRAY, PROCEDURE, POINTER, SET,
83                                    SUBRANGE, EQUAL
84                                 */
85         short tp_fund;          /* fundamental type  or constructor */
86 #define T_RECORD        0x0001
87 #define T_ENUMERATION   0x0002
88 #define T_INTEGER       0x0004
89 #define T_CARDINAL      0x0008
90 #define T_EQUAL         0x0010
91 #define T_REAL          0x0020
92 #define T_HIDDEN        0x0040
93 #define T_POINTER       0x0080
94 #define T_CHAR          0x0100
95 #define T_WORD          0x0200
96 #define T_SET           0x0400
97 #define T_SUBRANGE      0x0800
98 #define T_PROCEDURE     0x1000
99 #define T_ARRAY         0x2000
100 #define T_STRING        0x4000
101 #define T_INTORCARD     (T_INTEGER|T_CARDINAL)
102 #define T_NOSUB         (T_INTORCARD|T_ENUMERATION|T_CHAR)
103 #define T_NUMERIC       (T_INTORCARD|T_REAL)
104 #define T_INDEX         (T_ENUMERATION|T_CHAR|T_SUBRANGE)
105 #define T_DISCRETE      (T_INDEX|T_INTORCARD)
106 #define T_CONSTRUCTED   (T_ARRAY|T_SET|T_RECORD)
107 #ifdef DBSYMTAB
108         short tp_dbindex;       /* index in debugger symbol table */
109 #endif
110         int tp_align;           /* alignment requirement of this type */
111         arith tp_size;          /* size of this type */
112         union {
113             struct enume *tp_enum;
114             struct subrange *tp_subrange;
115             struct array *tp_arr;
116             struct record tp_record;
117             struct proc tp_proc;
118             struct set tp_set;
119         } tp_value;
120 };
121
122 typedef struct type t_type;
123
124 /* ALLOCDEF "type" 50 */
125
126 extern t_type
127         *bool_type,
128         *char_type,
129         *int_type,
130         *card_type,
131         *longint_type,
132         *longcard_type,
133         *real_type,
134         *longreal_type,
135         *word_type,
136         *byte_type,
137         *address_type,
138         *intorcard_type,
139         *longintorcard_type,
140         *bitset_type,
141         *void_type,
142         *std_type,
143         *error_type;            /* All from type.c */
144
145 #include "nocross.h"
146 #ifdef NOCROSS
147 #include "target_sizes.h"
148 #define word_align      (AL_WORD)
149 #define short_align     (AL_SHORT)
150 #define int_align       (AL_INT)
151 #define long_align      (AL_LONG)
152 #define float_align     (AL_FLOAT)
153 #define double_align    (AL_DOUBLE)
154 #define pointer_align   (AL_POINTER)
155 #define struct_align    (AL_STRUCT)
156
157 #define word_size       (SZ_WORD)
158 #define dword_size      (2 * SZ_WORD)
159 #define int_size        (SZ_INT)
160 #define short_size      (SZ_SHORT)
161 #define long_size       (SZ_LONG)
162 #define float_size      (SZ_FLOAT)
163 #define double_size     (SZ_DOUBLE)
164 #define pointer_size    (SZ_POINTER)
165
166 #define wrd_bits        (8*(int)word_size)
167 #else /* NOCROSS */
168
169 extern int
170         word_align,
171         short_align,
172         int_align,
173         long_align,
174         float_align,
175         double_align,
176         pointer_align,
177         struct_align;           /* All from type.c */
178
179 extern arith
180         word_size,
181         dword_size,
182         short_size,
183         int_size,
184         long_size,
185         float_size,
186         double_size,
187         pointer_size;           /* All from type.c */
188
189 extern unsigned int
190         wrd_bits;               /* from cstoper.c */
191 #endif /* NOCROSS */
192
193 extern arith
194         ret_area_size;
195
196 extern arith
197         align();                /* type.c */
198
199 extern t_type
200         *construct_type(),
201         *standard_type(),
202         *set_type(),
203         *subr_type(),
204         *proc_type(),
205         *enum_type(),
206         *qualified_type(),
207         *intorcard(),
208         *RemoveEqual(); /* All from type.c */
209
210 #define NULLTYPE ((t_type *) 0)
211
212 #define IsConformantArray(tpx)  ((tpx)->tp_fund==T_ARRAY && (tpx)->tp_size==0)
213 #define bounded(tpx)            ((tpx)->tp_fund & T_INDEX)
214 #define complex(tpx)            ((tpx)->tp_fund & (T_RECORD|T_ARRAY))
215 #define WA(sz)                  (align(sz, (int) word_size))
216 #ifdef DEBUG
217 #define ResultType(tpx)         (assert((tpx)->tp_fund == T_PROCEDURE),\
218                                         (tpx)->tp_next)
219 #define ParamList(tpx)          (assert((tpx)->tp_fund == T_PROCEDURE),\
220                                         (tpx)->prc_params)
221 #define IndexType(tpx)          (assert((tpx)->tp_fund == T_ARRAY),\
222                                         (tpx)->tp_next)
223 #define ElementType(tpx)        (assert((tpx)->tp_fund == T_SET),\
224                                         (tpx)->tp_next)
225 #define PointedtoType(tpx)      (assert((tpx)->tp_fund == T_POINTER),\
226                                         (tpx)->tp_next)
227 #define SubBaseType(tpx)        (assert((tpx)->tp_fund == T_SUBRANGE), \
228                                         (tpx)->tp_next)
229 #else /* DEBUG */
230 #define ResultType(tpx)         ((tpx)->tp_next)
231 #define ParamList(tpx)          ((tpx)->prc_params)
232 #define IndexType(tpx)          ((tpx)->tp_next)
233 #define ElementType(tpx)        ((tpx)->tp_next)
234 #define PointedtoType(tpx)      ((tpx)->tp_next)
235 #define SubBaseType(tpx)        ((tpx)->tp_next)
236 #endif /* DEBUG */
237 #define BaseType(tpx)           ((tpx)->tp_fund == T_SUBRANGE ? (tpx)->tp_next : \
238                                         (tpx))
239 #define IsConstructed(tpx)      ((tpx)->tp_fund & T_CONSTRUCTED)
240 #define TooBigForReturnArea(tpx) ((tpx)->tp_size > ret_area_size)
241
242 extern arith full_mask[];
243 extern arith max_int[];
244 extern arith min_int[];
245
246 #define ufit(n, i)      (((n) & ~full_mask[(i)]) == 0)