Pristine Ack-5.5
[Ack-5.5.git] / util / grind / type.hh
1 /* $Id: type.hh,v 1.10 1994/06/24 11:01:43 ceriel Exp $ */
2
3 /* internal type representation */
4
5 /* structure for struct/union elements */
6 struct fields {
7   long fld_pos;                 /* position of field */
8   long fld_bitsize;             /* size in bits */
9   struct type *fld_type;        /* type of field */
10   char *fld_name;               /* name of field */
11 };
12
13 /* structure for enumeration literals */
14 struct literal {
15   long lit_val;                 /* value of literal */
16   char *lit_name;               /* name of literal */
17 };
18
19 /* structure for parameters */
20 struct param {
21   struct type *par_type;        /* type of parameter */
22   long par_off;                 /* offset of parameter */
23   char par_kind;                /* kind of parameter ('p', 'i', or 'v') */
24 };
25
26 typedef struct type {
27   short         ty_class;
28 #define T_SUBRANGE       1
29 #define T_ARRAY          2
30 #define T_STRUCT         3
31 #define T_UNION          4
32 #define T_ENUM           5
33 #define T_POINTER        6
34 #define T_FILE           7
35 #define T_PROCEDURE      8
36 #define T_SET            9
37 #define T_REAL          10
38 #define T_INTEGER       11
39 #define T_VOID          12
40 #define T_UNSIGNED      13
41 #define T_STRING        14      /* only for string constants ... */
42 #define T_CROSS         15      /* cross reference to type */
43 #define T_INCOMPLETE   100
44   long          ty_size;
45   struct symbol *ty_sym;
46   union {
47      /* cross references */
48      struct type    *typ_cross;
49 #define ty_cross        ty_v.typ_cross
50      /* procedures/functions: */
51      struct {
52         int         typ_nparams;
53         struct type *typ_retval;
54         struct param *typ_params;
55         long        typ_nbparams;
56      } ty_proc;
57 #define ty_nparams      ty_v.ty_proc.typ_nparams
58 #define ty_retval       ty_v.ty_proc.typ_retval
59 #define ty_params       ty_v.ty_proc.typ_params
60 #define ty_nbparams     ty_v.ty_proc.typ_nbparams
61      /* pointers, files: */
62      struct type *typ_ptrto;
63 #define ty_ptrto        ty_v.typ_ptrto
64 #define ty_fileof       ty_v.typ_ptrto
65      /* arrays: */
66      struct {
67         long typ_lb, typ_hb;
68         struct type *typ_index;
69         struct type *typ_elements;
70      } ty_array;
71 #define ty_lb           ty_v.ty_array.typ_lb
72 #define ty_hb           ty_v.ty_array.typ_hb
73 #define ty_index        ty_v.ty_array.typ_index
74 #define ty_elements     ty_v.ty_array.typ_elements
75      /* subranges: */
76      struct {
77         long typ_low, typ_up;
78         int typ_A;
79         struct type *typ_base;
80      } ty_subrange;
81 #define ty_A            ty_v.ty_subrange.typ_A
82 #define ty_low          ty_v.ty_subrange.typ_low
83 #define ty_up           ty_v.ty_subrange.typ_up
84 #define ty_base         ty_v.ty_subrange.typ_base
85      /* structures/unions: */
86      struct {
87         unsigned typ_nfields;           /* number of field structures */
88         struct fields *typ_fields;
89      } ty_struct;
90 #define ty_nfields      ty_v.ty_struct.typ_nfields
91 #define ty_fields       ty_v.ty_struct.typ_fields
92      /* enumerations: */
93      struct {
94         unsigned typ_nenums;            /* number of enumeration literals */
95         struct literal *typ_literals;
96      } ty_enum;
97 #define ty_nenums       ty_v.ty_enum.typ_nenums
98 #define ty_literals     ty_v.ty_enum.typ_literals
99      /* bit sets: */
100      struct {
101         struct type *typ_setbase;       /* base type of set elements */
102         long typ_setlow;                /* low bound */
103      } ty_set;
104 #define ty_setbase      ty_v.ty_set.typ_setbase
105 #define ty_setlow       ty_v.ty_set.typ_setlow
106   } ty_v;
107 } t_type, *p_type;
108
109 /* ALLOCDEF "type" 50 */
110
111 extern p_type
112         subrange_type(),
113         array_type(),
114         *tp_lookup();
115 extern long
116         param_size(),
117         compute_size();
118
119 extern p_type   char_type, uchar_type, bool_type, int_type,
120                 long_type, double_type, string_type, address_type;
121 extern p_type   void_type;
122 extern long     int_size, short_size, pointer_size, long_size,
123                 float_size, double_size;
124