Pristine Ack-5.5
[Ack-5.5.git] / lang / pc / comp / type.H
1 /* T Y P E   D E S C R I P T O R   S T R U C T U R E */
2
3 #include "dbsymtab.h"
4
5 struct paramlist {              /* structure for parameterlist of a PROCEDURE */
6         struct paramlist *next;
7         struct def *par_def;    /* "df" of parameter */
8 #define IsVarParam(xpar)        ((xpar)->par_def->df_flags & D_VARPAR)
9 #define TypeOfParam(xpar)       ((xpar)->par_def->df_type)
10 };
11
12 /* ALLOCDEF "paramlist" 50 */
13
14 struct enume    {
15         struct def *en_enums;
16         unsigned int en_ncst;   /* number of constants */
17         label en_rck;           /* label of range check descriptor */
18 #define enm_enums       tp_value.tp_enum.en_enums
19 #define enm_ncst        tp_value.tp_enum.en_ncst
20 #define enm_rck         tp_value.tp_enum.en_rck
21 };
22
23 struct subrange {
24         arith su_lb, su_ub;     /* lower bound and upper bound */
25         label su_rck;           /* label of range check descriptor */
26 #define sub_lb          tp_value.tp_subrange.su_lb
27 #define sub_ub          tp_value.tp_subrange.su_ub
28 #define sub_rck         tp_value.tp_subrange.su_rck
29 };
30
31 struct array    {
32         struct type *ar_elem;   /* type of elements */
33         union   {
34                 struct  {       /* normal array */
35                         arith ar_elsize;        /* size of elements */
36                         label ar_descr;         /* label of array descriptor */
37                 } norm_arr;
38                 struct  {       /* conformant array */
39                         int cf_sclevel;         /* scope level of declaration */
40                         arith cf_descr;         /* offset array descriptor */
41                 } conf_arr;
42         } ar_type;
43 #define arr_elem        tp_value.tp_arr.ar_elem
44 #define arr_elsize      tp_value.tp_arr.ar_type.norm_arr.ar_elsize
45 #define arr_ardescr     tp_value.tp_arr.ar_type.norm_arr.ar_descr
46 #define arr_cfdescr     tp_value.tp_arr.ar_type.conf_arr.cf_descr
47 #define arr_sclevel     tp_value.tp_arr.ar_type.conf_arr.cf_sclevel
48 };
49
50 struct selector {
51         struct type *sel_type;          /* type of the selector of a variant */
52         arith sel_ncst;                 /* number of values of selector type */
53         arith sel_lb;                   /* lower bound of selector type */
54         struct selector **sel_ptrs;     /* tagvalue table with pointers to
55                                            nested variant-selectors */
56 };
57
58 struct record   {
59         struct scope *rc_scope;         /* scope of this record */
60                                         /* members are in the symbol table */
61         struct selector *rc_selector;   /* selector of variant (if present) */
62 #define rec_scope       tp_value.tp_record.rc_scope
63 #define rec_sel         tp_value.tp_record.rc_selector
64 };
65
66 struct proc     {
67         struct paramlist *pr_params;
68         arith pr_nbpar;
69 #define prc_params      tp_value.tp_proc.pr_params
70 #define prc_nbpar       tp_value.tp_proc.pr_nbpar
71 };
72
73 struct type     {
74         struct type *next;      /* used with ARRAY, PROCEDURE, FILE, SET,
75                                    POINTER, SUBRANGE */
76         int tp_fund;            /* fundamental type  or constructor */
77 #define T_ENUMERATION   0x0001
78 #define T_INTEGER       0x0002
79 #define T_REAL          0x0004
80 #define T_CHAR          0x0008
81 #define T_PROCEDURE     0x0010
82 #define T_FUNCTION      0x0020
83 #define T_FILE          0x0040
84 #define T_STRINGCONST   0x0080
85 #define T_SUBRANGE      0x0100
86 #define T_SET           0x0200
87 #define T_ARRAY         0x0400
88 #define T_RECORD        0x0800
89 #define T_POINTER       0x1000
90 #define T_LONG          0x2000
91 #define T_STRING        0x4000
92 #define T_ERROR         0x8000  /* bad type */
93 #define T_NUMERIC       (T_INTEGER | T_REAL | T_LONG)
94 #define T_INDEX         (T_SUBRANGE | T_ENUMERATION | T_CHAR | T_INTEGER )
95 #define T_ORDINAL       (T_INDEX | T_LONG)
96 #define T_CONSTRUCTED   (T_ARRAY | T_SET | T_RECORD | T_FILE | T_STRINGCONST)
97 #define T_ROUTINE       (T_FUNCTION | T_PROCEDURE)
98         unsigned short tp_flags;
99 #define T_HASFILE       0x1     /* set if type has a filecomponent */
100 #define T_PACKED        0x2     /* set if type is packed */
101 #define T_CHECKED       0x4     /* set if array has been checked */
102 #ifdef DBSYMTAB
103         short tp_dbindex;       /* index in debugger symbol table */
104 #endif
105         int tp_align;           /* alignment requirement of this type */
106         int tp_palign;          /* in packed structures */
107         arith tp_size;          /* size of this type */
108         arith tp_psize;         /* in packed structures */
109         union {
110             struct enume tp_enum;
111             struct subrange tp_subrange;
112             struct array tp_arr;
113             struct record tp_record;
114             struct proc tp_proc;
115         } tp_value;
116 };
117
118 /* ALLOCDEF "type" 50 */
119
120 extern struct type
121         *bool_type,
122         *char_type,
123         *int_type,
124         *long_type,
125         *real_type,
126         *string_type,
127         *std_type,
128         *text_type,
129         *nil_type,
130         *emptyset_type,
131         *void_type,
132         *error_type;            /* All from type.c */
133
134 #include "nocross.h"
135 #ifdef NOCROSS
136 #include "target_sizes.h"
137 #define word_align      (AL_WORD)
138 #define int_align       (AL_INT)
139 #define long_align      (AL_LONG)
140 #define pointer_align   (AL_POINTER)
141 #define real_align      (AL_REAL)
142 #define struct_align    (AL_STRUCT)
143
144 #define word_size       (SZ_WORD)
145 #define int_size        (SZ_INT)
146 #define long_size       (SZ_LONG)
147 #define pointer_size    (SZ_POINTER)
148 #define real_size       (SZ_REAL)
149 #else /* NOCROSS */
150 extern int
151         word_align,
152         int_align,
153         long_align,
154         pointer_align,
155         real_align,
156         struct_align;           /* All from type.c */
157
158 extern arith
159         word_size,
160         int_size,
161         long_size,
162         pointer_size,
163         real_size;              /* All from type.c */
164 #endif /* NOCROSS */
165
166 extern arith
167         align();
168
169 struct type
170         *construct_type(),
171         *standard_type(),
172         *proc_type(),
173         *func_type(),
174         *set_type(),
175         *subr_type();           /* All from type.c */
176
177 #define NULLTYPE ((struct type *) 0)
178
179 #define bounded(tpx)            ((tpx)->tp_fund & T_INDEX)
180 #define WA(sz)                  (align(sz, (int) word_size))
181 #define ResultType(tpx)         (assert((tpx)->tp_fund & T_ROUTINE),(tpx)->next)
182 #define ElementType(tpx)        (assert((tpx)->tp_fund & T_SET), (tpx)->next)
183 #define BaseType(tpx)           ((tpx)->tp_fund & T_SUBRANGE ? (tpx)->next :\
184                                                                         (tpx))
185 #define IndexType(tpx)          (assert((tpx)->tp_fund == T_ARRAY), (tpx)->next)
186 #define IsConstructed(tpx)      ((tpx)->tp_fund & T_CONSTRUCTED)
187 #define IsConformantArray(tpx)  ((tpx)->tp_fund & T_ARRAY &&\
188                                                         (tpx)->tp_size == 0)
189 #define IsPacked(tpx)           ((tpx)->tp_flags & T_PACKED)
190 #define PointedtoType(tpx)      (assert((tpx)->tp_fund == T_POINTER ||\
191                                         (tpx)->tp_fund == T_FILE), (tpx)->next)
192 #define ParamList(tpx)          (assert((tpx)->tp_fund & T_ROUTINE),\
193                                         (tpx)->prc_params)
194
195 extern long full_mask[];
196
197 #define ufit(n, i)      (((n) & ~full_mask[(i)]) == 0)