Subversion Repositories tendra.SVN

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 7
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2006 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997, 1998
32
    		 Crown Copyright (c) 1997, 1998
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
Line 62... Line 92...
62
 
92
 
63
    These values give the fundamental information about the built-in
93
    These values give the fundamental information about the built-in
64
    types, the sizes of the various types, whether char is signed, and
94
    types, the sizes of the various types, whether char is signed, and
65
    whether the signed ranges are full (for example [-128,127]) or
95
    whether the signed ranges are full (for example [-128,127]) or
66
    symmetric (for example [-127,127]).
96
    symmetric (for example [-127,127]).
67
*/
97
*/
68
 
98
 
69
BASE_INFO basetype_info [ ORDER_ntype ] = {
99
BASE_INFO basetype_info[ORDER_ntype] = {
70
    { btype_sint, 16, UINT_MAX, btype_signed, 1, NULL_type },
100
	{ btype_sint, 16, UINT_MAX, btype_signed, 1, NULL_type },
71
    { btype_char, 8, UINT_MAX, btype_none, 1, NULL_type },
101
	{ btype_char, 8, UINT_MAX, btype_none, 1, NULL_type },
72
    { btype_schar, 8, UINT_MAX, btype_signed, 1, NULL_type },
102
	{ btype_schar, 8, UINT_MAX, btype_signed, 1, NULL_type },
73
    { btype_uchar, 8, UINT_MAX, btype_unsigned, 1, NULL_type },
103
	{ btype_uchar, 8, UINT_MAX, btype_unsigned, 1, NULL_type },
74
    { btype_sshort, 16, UINT_MAX, btype_signed, 1, NULL_type },
104
	{ btype_sshort, 16, UINT_MAX, btype_signed, 1, NULL_type },
75
    { btype_ushort, 16, UINT_MAX, btype_unsigned, 1, NULL_type },
105
	{ btype_ushort, 16, UINT_MAX, btype_unsigned, 1, NULL_type },
76
    { btype_sint, 16, UINT_MAX, btype_signed, 1, NULL_type },
106
	{ btype_sint, 16, UINT_MAX, btype_signed, 1, NULL_type },
77
    { btype_uint, 16, UINT_MAX, btype_unsigned, 1, NULL_type },
107
	{ btype_uint, 16, UINT_MAX, btype_unsigned, 1, NULL_type },
78
    { btype_slong, 32, UINT_MAX, btype_signed, 1, NULL_type },
108
	{ btype_slong, 32, UINT_MAX, btype_signed, 1, NULL_type },
79
    { btype_ulong, 32, UINT_MAX, btype_unsigned, 1, NULL_type },
109
	{ btype_ulong, 32, UINT_MAX, btype_unsigned, 1, NULL_type },
80
    { btype_sllong, 32, UINT_MAX, btype_signed, 0, NULL_type },
110
	{ btype_sllong, 32, UINT_MAX, btype_signed, 0, NULL_type },
81
    { btype_ullong, 32, UINT_MAX, btype_unsigned, 0, NULL_type },
111
	{ btype_ullong, 32, UINT_MAX, btype_unsigned, 0, NULL_type },
82
    { btype_float, 0, 0, btype_none, 1, NULL_type },
112
	{ btype_float, 0, 0, btype_none, 1, NULL_type },
83
    { btype_double, 0, 0, btype_none, 1, NULL_type },
113
	{ btype_double, 0, 0, btype_none, 1, NULL_type },
84
    { btype_ldouble, 0, 0, btype_none, 1, NULL_type },
114
	{ btype_ldouble, 0, 0, btype_none, 1, NULL_type },
85
    { btype_void, 0, 0, btype_none, 1, NULL_type },
115
	{ btype_void, 0, 0, btype_none, 1, NULL_type },
86
    { btype_bottom, 0, 0, btype_none, 1, NULL_type },
116
	{ btype_bottom, 0, 0, btype_none, 1, NULL_type },
87
    { btype_bool, 1, 1, btype_unsigned, LANGUAGE_CPP, NULL_type },
117
	{ btype_bool, 1, 1, btype_unsigned, LANGUAGE_CPP, NULL_type },
88
    { btype_ptrdiff_t, 16, UINT_MAX, btype_signed, 0, NULL_type },
118
	{ btype_ptrdiff_t, 16, UINT_MAX, btype_signed, 0, NULL_type },
89
    { btype_size_t, 16, UINT_MAX, btype_unsigned, 0, NULL_type },
119
	{ btype_size_t, 16, UINT_MAX, btype_unsigned, 0, NULL_type },
90
    { btype_wchar_t, 8, UINT_MAX, btype_none, LANGUAGE_CPP, NULL_type },
120
	{ btype_wchar_t, 8, UINT_MAX, btype_none, LANGUAGE_CPP, NULL_type },
91
    { btype_ellipsis, 0, UINT_MAX, btype_none, 0, NULL_type }
121
	{ btype_ellipsis, 0, UINT_MAX, btype_none, 0, NULL_type }
92
} ;
122
};
93
 
123
 
94
 
124
 
95
/*
125
/*
96
    STANDARD LISTS OF TYPES
126
    STANDARD LISTS OF TYPES
97
 
127
 
98
    These variables give various standard lists of types.
128
    These variables give various standard lists of types.
99
*/
129
*/
100
 
130
 
101
LIST ( TYPE ) all_int_types = NULL_list ( TYPE ) ;
131
LIST(TYPE) all_int_types = NULL_list(TYPE);
102
LIST ( TYPE ) all_prom_types = NULL_list ( TYPE ) ;
132
LIST(TYPE) all_prom_types = NULL_list(TYPE);
103
LIST ( TYPE ) all_llong_types = NULL_list ( TYPE ) ;
133
LIST(TYPE) all_llong_types = NULL_list(TYPE);
104
 
134
 
105
 
135
 
106
/*
136
/*
107
    TABLE OF BASIC TYPE CONVERSIONS
137
    TABLE OF BASIC TYPE CONVERSIONS
108
 
138
 
109
    This table gives the severity levels for conversions between the
139
    This table gives the severity levels for conversions between the
110
    various built-in types (the source types are listed along the right
140
    various built-in types (the source types are listed along the right
111
    hand side, and the destination types along the top).  The first row
141
    hand side, and the destination types along the top).  The first row
112
    and column are just copies of the second.  The values are as follows
142
    and column are just copies of the second.  The values are as follows
113
    (from safest to most unsafe):
143
    (from safest to most unsafe):
114
 
144
 
115
	0 = always safe					SAFE
145
	0 = always safe					SAFE
116
	1 = almost certainly safe			SAFE
146
	1 = almost certainly safe			SAFE
117
	2 = safe on real machines			SAFE
147
	2 = safe on real machines			SAFE
118
	3 = safe on 32-bit machines			DEPENDS
148
	3 = safe on 32-bit machines			DEPENDS
119
	4 = safe on 64-bit machines			DEPENDS
149
	4 = safe on 64-bit machines			DEPENDS
Line 127... Line 157...
127
    probably safe by the program.  safe_builtin_cast gives the maximum
157
    probably safe by the program.  safe_builtin_cast gives the maximum
128
    value which is considered possibly safe.  max_builtin_cast gives the
158
    value which is considered possibly safe.  max_builtin_cast gives the
129
    minimum threshold value for error reporting.
159
    minimum threshold value for error reporting.
130
*/
160
*/
131
 
161
 
132
unsigned char builtin_casts [ ORDER_ntype ] [ ORDER_ntype ] = {
162
unsigned char builtin_casts[ORDER_ntype][ORDER_ntype] = {
133
	 /* CH CH SC UC SS US SI UI SL UL SX UX FL DB LD VD BT BL PD SZ WC EL */
163
	 /* CH CH SC UC SS US SI UI SL UL SX UX FL DB LD VD BT BL PD SZ WC EL */
134
 /* CH */ { 0, 0, 5, 5, 1, 7, 1, 7, 1, 7, 1, 7, 8, 8, 8, 9, 9, 8, 1, 7, 0, 0 },
164
 /* CH */ { 0, 0, 5, 5, 1, 7, 1, 7, 1, 7, 1, 7, 8, 8, 8, 9, 9, 8, 1, 7, 0, 0 },
135
 /* CH */ { 0, 0, 5, 5, 1, 7, 1, 7, 1, 7, 1, 7, 8, 8, 8, 9, 9, 8, 1, 7, 0, 0 },
165
 /* CH */ { 0, 0, 5, 5, 1, 7, 1, 7, 1, 7, 1, 7, 8, 8, 8, 9, 9, 8, 1, 7, 0, 0 },
136
 /* SC */ { 5, 5, 0, 6, 0, 7, 0, 7, 0, 7, 0, 7, 8, 8, 8, 9, 9, 8, 1, 7, 8, 0 },
166
 /* SC */ { 5, 5, 0, 6, 0, 7, 0, 7, 0, 7, 0, 7, 8, 8, 8, 9, 9, 8, 1, 7, 8, 0 },
137
 /* UC */ { 5, 5, 6, 0, 2, 0, 2, 0, 2, 0, 2, 0, 8, 8, 8, 9, 9, 8, 2, 1, 8, 0 },
167
 /* UC */ { 5, 5, 6, 0, 2, 0, 2, 0, 2, 0, 2, 0, 8, 8, 8, 9, 9, 8, 2, 1, 8, 0 },
Line 151... Line 181...
151
 /* BL */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0 },
181
 /* BL */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0 },
152
 /* PD */ { 8, 8, 8, 8, 8, 8, 3, 7, 0, 7, 0, 7, 8, 8, 8, 9, 9, 8, 0, 8, 8, 0 },
182
 /* PD */ { 8, 8, 8, 8, 8, 8, 3, 7, 0, 7, 0, 7, 8, 8, 8, 9, 9, 8, 0, 8, 8, 0 },
153
 /* SZ */ { 8, 8, 8, 8, 8, 8, 8, 3, 7, 0, 7, 0, 8, 8, 8, 9, 9, 8, 8, 0, 8, 0 },
183
 /* SZ */ { 8, 8, 8, 8, 8, 8, 8, 3, 7, 0, 7, 0, 8, 8, 8, 9, 9, 8, 8, 0, 8, 0 },
154
 /* WC */ { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 8, 8, 8, 0, 0 },
184
 /* WC */ { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 8, 8, 8, 0, 0 },
155
 /* EL */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
185
 /* EL */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
156
} ;
186
};
157
 
187
 
158
int min_builtin_cast = 2 ;
188
int min_builtin_cast = 2;
159
int safe_builtin_cast = 4 ;
189
int safe_builtin_cast = 4;
160
int max_builtin_cast = 3 ;
190
int max_builtin_cast = 3;
161
 
191
 
162
 
192
 
163
/*
193
/*
164
    COPY BUILT-IN CASTS
194
    COPY BUILT-IN CASTS
165
 
195
 
166
    This routine copies the built-in cast values for type m into type n.
196
    This routine copies the built-in cast values for type m into type n.
167
*/
197
*/
168
 
198
 
169
static void copy_builtin_cast
199
static void
170
    PROTO_N ( ( n, m ) )
-
 
171
    PROTO_T ( BUILTIN_TYPE n X BUILTIN_TYPE m )
200
copy_builtin_cast(BUILTIN_TYPE n, BUILTIN_TYPE m)
172
{
201
{
173
    unsigned long i ;
202
	unsigned long i;
174
    for ( i = 1 ; i < ORDER_ntype ; i++ ) {
203
	for (i = 1; i < ORDER_ntype; i++) {
175
	builtin_casts [n] [i] = builtin_casts [m] [i] ;
204
		builtin_casts[n][i] = builtin_casts[m][i];
176
	builtin_casts [i] [n] = builtin_casts [i] [m] ;
205
		builtin_casts[i][n] = builtin_casts[i][m];
177
    }
206
	}
178
    builtin_casts [n] [n] = 0 ;
207
	builtin_casts[n][n] = 0;
179
    builtin_casts [n] [m] = 0 ;
208
	builtin_casts[n][m] = 0;
180
    builtin_casts [m] [n] = 0 ;
209
	builtin_casts[m][n] = 0;
181
    builtin_casts [m] [m] = 0 ;
210
	builtin_casts[m][m] = 0;
182
    return ;
211
	return;
183
}
212
}
184
 
213
 
185
 
214
 
186
/*
215
/*
187
    SET EXACT TYPE RANGES
216
    SET EXACT TYPE RANGES
Line 189... Line 218...
189
    This routine recalculates the table of built-in casts on the assumption
218
    This routine recalculates the table of built-in casts on the assumption
190
    that the type sizes given in basetype_info are exact.  The definition
219
    that the type sizes given in basetype_info are exact.  The definition
191
    of what constitutes a safe conversion is adjusted accordingly.  Note
220
    of what constitutes a safe conversion is adjusted accordingly.  Note
192
    that the conversions between char and signed/unsigned char are handled
221
    that the conversions between char and signed/unsigned char are handled
193
    separately by set_char_type.
222
    separately by set_char_type.
194
*/
223
*/
195
 
224
 
196
void set_exact_types
225
void
197
    PROTO_Z ()
226
set_exact_types(void)
198
{
227
{
199
    BUILTIN_TYPE n, m ;
228
	BUILTIN_TYPE n, m;
200
    BASE_INFO *p = basetype_info ;
229
	BASE_INFO *p = basetype_info;
201
    for ( n = ntype_char ; n < ntype_ellipsis ; n++ ) {
230
	for (n = ntype_char; n < ntype_ellipsis; n++) {
202
	for ( m = ntype_char ; m < ntype_ellipsis ; m++ ) {
231
		for (m = ntype_char; m < ntype_ellipsis; m++) {
203
	    unsigned char c = builtin_casts [n] [m] ;
232
			unsigned char c = builtin_casts[n][m];
204
	    if ( c >= 1 && c <= 4 ) {
233
			if (c >= 1 && c <= 4) {
205
		unsigned bn = p [n].min_bits ;
234
				unsigned bn = p[n].min_bits;
206
		unsigned bm = p [m].min_bits ;
235
				unsigned bm = p[m].min_bits;
207
		BASE_TYPE sn = p [n].sign ;
236
				BASE_TYPE sn = p[n].sign;
208
		BASE_TYPE sm = p [m].sign ;
237
				BASE_TYPE sm = p[m].sign;
209
		if ( sn == sm ) {
238
				if (sn == sm) {
210
		    /* Same sign */
239
					/* Same sign */
211
		    if ( bn <= bm ) c = 1 ;
240
					if (bn <= bm) {
-
 
241
						c = 1;
-
 
242
					}
212
		} else if ( sn & btype_unsigned ) {
243
				} else if (sn & btype_unsigned) {
213
		    /* n is unsigned */
244
					/* n is unsigned */
214
		    if ( bn < bm ) c = 1 ;
245
					if (bn < bm) {
-
 
246
						c = 1;
-
 
247
					}
215
		} else if ( sm & btype_signed ) {
248
				} else if (sm & btype_signed) {
216
		    /* m is signed */
249
					/* m is signed */
217
		    if ( bn < bm ) c = 1 ;
250
					if (bn < bm) {
-
 
251
						c = 1;
-
 
252
					}
218
		}
253
				}
219
		builtin_casts [n] [m] = c ;
254
				builtin_casts[n][m] = c;
220
	    }
255
			}
-
 
256
		}
221
	}
257
	}
222
    }
-
 
223
    min_builtin_cast = 1 ;
258
	min_builtin_cast = 1;
224
    safe_builtin_cast = 1 ;
259
	safe_builtin_cast = 1;
225
    max_builtin_cast = 2 ;
260
	max_builtin_cast = 2;
226
    return ;
261
	return;
227
}
262
}
228
 
263
 
229
 
264
 
230
/*
265
/*
231
    SET THE SIGN OF CHAR
266
    SET THE SIGN OF CHAR
232
 
267
 
233
    This routine sets the type of char to be bt, which can be btype_signed,
268
    This routine sets the type of char to be bt, which can be btype_signed,
234
    btype_unsigned, or btype_none.
269
    btype_unsigned, or btype_none.
235
*/
270
*/
236
 
271
 
237
void set_char_sign
272
void
238
    PROTO_N ( ( bt ) )
-
 
239
    PROTO_T ( BASE_TYPE bt )
273
set_char_sign(BASE_TYPE bt)
240
{
274
{
241
    BASE_INFO *p = basetype_info ;
275
	BASE_INFO *p = basetype_info;
242
    BUILTIN_TYPE nt = ntype_none ;
276
	BUILTIN_TYPE nt = ntype_none;
243
    if ( bt & btype_signed ) {
277
	if (bt & btype_signed) {
244
	nt = ntype_schar ;
278
		nt = ntype_schar;
245
	bt = p [ nt ].sign ;
279
		bt = p[nt].sign;
246
    } else if ( bt & btype_unsigned ) {
280
	} else if (bt & btype_unsigned) {
247
	nt = ntype_uchar ;
281
		nt = ntype_uchar;
248
	bt = p [ nt ].sign ;
282
		bt = p[nt].sign;
249
    }
283
	}
250
    if ( p [ ntype_char ].sign != bt ) {
284
	if (p[ntype_char].sign != bt) {
251
	p [ ntype_char ].sign = bt ;
285
		p[ntype_char].sign = bt;
252
	builtin_casts [ ntype_char ] [ ntype_schar ] = 5 ;
286
		builtin_casts[ntype_char][ntype_schar] = 5;
253
	builtin_casts [ ntype_char ] [ ntype_uchar ] = 5 ;
287
		builtin_casts[ntype_char][ntype_uchar] = 5;
254
	builtin_casts [ ntype_schar ] [ ntype_char ] = 5 ;
288
		builtin_casts[ntype_schar][ntype_char] = 5;
255
	builtin_casts [ ntype_uchar ] [ ntype_char ] = 5 ;
289
		builtin_casts[ntype_uchar][ntype_char] = 5;
256
	builtin_casts [ ntype_schar ] [ ntype_wchar_t ] = 8 ;
290
		builtin_casts[ntype_schar][ntype_wchar_t] = 8;
257
	builtin_casts [ ntype_uchar ] [ ntype_wchar_t ] = 8 ;
291
		builtin_casts[ntype_uchar][ntype_wchar_t] = 8;
258
	copy_builtin_cast ( ntype_char, nt ) ;
292
		copy_builtin_cast(ntype_char, nt);
259
	builtin_casts [ ntype_char ] [ ntype_wchar_t ] = 0 ;
293
		builtin_casts[ntype_char][ntype_wchar_t] = 0;
260
	builtin_casts [ nt ] [ ntype_wchar_t ] = 0 ;
294
		builtin_casts[nt][ntype_wchar_t] = 0;
261
    }
295
	}
262
    return ;
296
	return;
263
}
297
}
264
 
298
 
265
 
299
 
266
/*
300
/*
267
    DEFINE A BUILT-IN TYPE
301
    DEFINE A BUILT-IN TYPE
268
 
302
 
269
    This routine defines the built-in type indicated by bt to be t.
303
    This routine defines the built-in type indicated by bt to be t.
270
*/
304
*/
271
 
305
 
272
void set_builtin_type
306
void
273
    PROTO_N ( ( bt, t ) )
-
 
274
    PROTO_T ( BASE_TYPE bt X TYPE t )
307
set_builtin_type(BASE_TYPE bt, TYPE t)
275
{
308
{
276
    /* Built-in integral types */
309
	/* Built-in integral types */
277
    INT_TYPE is, it ;
310
	INT_TYPE is, it;
278
    TYPE s = make_base_type ( bt ) ;
311
	TYPE s = make_base_type(bt);
279
    if ( !IS_type_integer ( t ) ) {
312
	if (!IS_type_integer(t)) {
280
	report ( crt_loc, ERR_pragma_builtin_type ( t ) ) ;
313
		report(crt_loc, ERR_pragma_builtin_type(t));
281
	return ;
314
		return;
282
    }
315
	}
283
    is = DEREF_itype ( type_integer_rep ( s ) ) ;
316
	is = DEREF_itype(type_integer_rep(s));
284
    it = DEREF_itype ( type_integer_rep ( t ) ) ;
317
	it = DEREF_itype(type_integer_rep(t));
285
    if ( !EQ_itype ( is, it ) ) {
318
	if (!EQ_itype(is, it)) {
286
	TYPE r ;
319
		TYPE r;
287
	int key ;
320
		int key;
288
	BUILTIN_TYPE ns = ntype_none ;
321
		BUILTIN_TYPE ns = ntype_none;
289
	if ( bt == btype_ptrdiff_t ) {
322
		if (bt == btype_ptrdiff_t) {
290
	    ns = ntype_ptrdiff_t ;
323
			ns = ntype_ptrdiff_t;
291
	} else if ( bt == btype_size_t ) {
324
		} else if (bt == btype_size_t) {
292
	    ns = ntype_size_t ;
325
			ns = ntype_size_t;
293
	} else if ( bt == btype_wchar_t ) {
326
		} else if (bt == btype_wchar_t) {
294
	    ns = ntype_wchar_t ;
327
			ns = ntype_wchar_t;
295
	}
328
		}
296
	key = basetype_info [ ns ].key ;
329
		key = basetype_info[ns].key;
297
	r = basetype_info [ ns ].set ;
330
		r = basetype_info[ns].set;
298
	basetype_info [ ns ].set = t ;
331
		basetype_info[ns].set = t;
299
	if ( !IS_NULL_type ( r ) ) {
332
		if (!IS_NULL_type(r)) {
300
	    /* Check compatibility */
333
			/* Check compatibility */
301
	    ERROR err = NULL_err ;
334
			ERROR err = NULL_err;
302
	    IGNORE check_compatible ( r, t, 0, &err, 0 ) ;
335
			IGNORE check_compatible(r, t, 0, &err, 0);
303
	    if ( !IS_NULL_err ( err ) ) report ( crt_loc, err ) ;
336
			if (!IS_NULL_err(err)) {
-
 
337
				report(crt_loc, err);
-
 
338
			}
304
	}
339
		}
305
	if ( !key ) {
340
		if (!key) {
306
	    /* Set integral type */
341
			/* Set integral type */
307
	    TYPE p = DEREF_type ( itype_prom ( it ) ) ;
342
			TYPE p = DEREF_type(itype_prom(it));
308
	    BUILTIN_TYPE nu = DEREF_ntype ( itype_unprom ( it ) ) ;
343
			BUILTIN_TYPE nu = DEREF_ntype(itype_unprom(it));
309
	    LIST ( TYPE ) cases = DEREF_list ( itype_cases ( it ) ) ;
344
			LIST(TYPE)cases = DEREF_list(itype_cases(it));
310
	    COPY_type ( itype_prom ( is ), p ) ;
345
			COPY_type(itype_prom(is), p);
311
	    COPY_ntype ( itype_unprom ( is ), nu ) ;
346
			COPY_ntype(itype_unprom(is), nu);
312
	    COPY_list ( itype_cases ( is ), cases ) ;
347
			COPY_list(itype_cases(is), cases);
313
	    if ( IS_itype_basic ( it ) ) {
348
			if (IS_itype_basic(it)) {
-
 
349
				BUILTIN_TYPE nt =
314
		BUILTIN_TYPE nt = DEREF_ntype ( itype_basic_no ( it ) ) ;
350
				    DEREF_ntype(itype_basic_no(it));
315
		copy_builtin_cast ( ns, nt ) ;
351
				copy_builtin_cast(ns, nt);
316
	    }
352
			}
-
 
353
		}
317
	}
354
	}
318
    }
-
 
319
    return ;
355
	return;
320
}
356
}
321
 
357
 
322
 
358
 
323
/*
359
/*
324
    SET THE IMPLEMENTATION OF LONG LONG
360
    SET THE IMPLEMENTATION OF LONG LONG
325
 
361
 
326
    This routine sets the implementation of 'long long' to be the
362
    This routine sets the implementation of 'long long' to be the
327
    real 'long long' type if big is true and 'long' otherwise.
363
    real 'long long' type if big is true and 'long' otherwise.
328
*/
364
*/
329
 
365
 
330
void set_long_long_type
366
void
331
    PROTO_N ( ( big ) )
-
 
332
    PROTO_T ( int big )
367
set_long_long_type(int big)
333
{
368
{
334
    if ( big ) {
369
	if (big) {
335
	base_token [ ntype_sllong ].tok = TOK_signed_llong ; ;
370
		base_token[ntype_sllong].tok = TOK_signed_llong;;
336
	base_token [ ntype_sllong ].no = ARITH_sllong ; ;
371
		base_token[ntype_sllong].no = ARITH_sllong;;
337
	base_token [ ntype_ullong ].tok = TOK_unsigned_llong ; ;
372
		base_token[ntype_ullong].tok = TOK_unsigned_llong;;
338
	base_token [ ntype_ullong ].no = ARITH_ullong ; ;
373
		base_token[ntype_ullong].no = ARITH_ullong;;
339
    } else {
374
	} else {
340
	base_token [ ntype_sllong ].tok = TOK_signed_long ; ;
375
		base_token[ntype_sllong].tok = TOK_signed_long;;
341
	base_token [ ntype_sllong ].no = ARITH_slong ; ;
376
		base_token[ntype_sllong].no = ARITH_slong;;
342
	base_token [ ntype_ullong ].tok = TOK_unsigned_long ; ;
377
		base_token[ntype_ullong].tok = TOK_unsigned_long;;
343
	base_token [ ntype_ullong ].no = ARITH_ulong ; ;
378
		base_token[ntype_ullong].no = ARITH_ulong;;
344
    }
379
	}
345
    return ;
380
	return;
346
}
381
}
347
 
382
 
348
 
383
 
349
/*
384
/*
350
    IS A TYPE A BUILT-IN TYPE?
385
    IS A TYPE A BUILT-IN TYPE?
351
 
386
 
352
    This routine checks whether the type t is a qualified version of a
387
    This routine checks whether the type t is a qualified version of a
353
    built-in type (including the semantic type if sem is true).  If so
388
    built-in type (including the semantic type if sem is true).  If so
354
    it returns the corresponding built-in type number.
389
    it returns the corresponding built-in type number.
355
*/
390
*/
356
 
391
 
357
BUILTIN_TYPE is_builtin_type
392
BUILTIN_TYPE
358
    PROTO_N ( ( t, sem ) )
-
 
359
    PROTO_T ( TYPE t X int sem )
393
is_builtin_type(TYPE t, int sem)
360
{
394
{
361
    BUILTIN_TYPE nt = ntype_none ;
395
	BUILTIN_TYPE nt = ntype_none;
362
    if ( !IS_NULL_type ( t ) ) {
396
	if (!IS_NULL_type(t)) {
363
	switch ( TAG_type ( t ) ) {
397
		switch (TAG_type(t)) {
364
	    case type_integer_tag : {
398
		case type_integer_tag: {
365
		INT_TYPE it = DEREF_itype ( type_integer_rep ( t ) ) ;
399
			INT_TYPE it = DEREF_itype(type_integer_rep(t));
366
		if ( IS_itype_basic ( it ) ) {
400
			if (IS_itype_basic(it)) {
367
		    nt = DEREF_ntype ( itype_basic_no ( it ) ) ;
401
				nt = DEREF_ntype(itype_basic_no(it));
368
		    if ( sem ) {
402
				if (sem) {
369
			/* Check semantic type */
403
					/* Check semantic type */
370
			INT_TYPE is ;
404
					INT_TYPE is;
371
			is = DEREF_itype ( type_integer_sem ( t ) ) ;
405
					is = DEREF_itype(type_integer_sem(t));
372
			if ( IS_itype_basic ( is ) ) {
406
					if (IS_itype_basic(is)) {
373
			    BUILTIN_TYPE ns ;
407
						BUILTIN_TYPE ns;
374
			    ns = DEREF_ntype ( itype_basic_no ( is ) ) ;
408
						ns = DEREF_ntype(itype_basic_no(is));
375
			    if ( ns != nt ) nt = ntype_none ;
409
						if (ns != nt)nt = ntype_none;
376
			} else {
410
					} else {
377
			    nt = ntype_none ;
411
						nt = ntype_none;
378
			}
412
					}
379
		    }
413
				}
380
		}
414
			}
381
		break ;
415
			break;
382
	    }
416
		}
383
	    case type_floating_tag : {
417
		case type_floating_tag: {
384
		FLOAT_TYPE ft = DEREF_ftype ( type_floating_rep ( t ) ) ;
418
			FLOAT_TYPE ft = DEREF_ftype(type_floating_rep(t));
385
		if ( IS_ftype_basic ( ft ) ) {
419
			if (IS_ftype_basic(ft)) {
386
		    nt = DEREF_ntype ( ftype_basic_no ( ft ) ) ;
420
				nt = DEREF_ntype(ftype_basic_no(ft));
387
		}
421
			}
388
		break ;
422
			break;
389
	    }
423
		}
390
	    case type_top_tag : {
424
		case type_top_tag:
391
		nt = ntype_void ;
425
			nt = ntype_void;
392
		break ;
426
			break;
393
	    }
-
 
394
	    case type_bottom_tag : {
427
		case type_bottom_tag:
395
		nt = ntype_bottom ;
428
			nt = ntype_bottom;
396
		break ;
429
			break;
397
	    }
-
 
398
	    case type_pre_tag : {
430
		case type_pre_tag: {
399
		BASE_TYPE bt = DEREF_btype ( type_pre_rep ( t ) ) ;
431
			BASE_TYPE bt = DEREF_btype(type_pre_rep(t));
400
		if ( bt == btype_ellipsis ) nt = ntype_ellipsis ;
432
			if (bt == btype_ellipsis) {
-
 
433
				nt = ntype_ellipsis;
-
 
434
			}
401
		break ;
435
			break;
402
	    }
436
		}
403
	}
437
		}
404
    }
438
	}
405
    return ( nt ) ;
439
	return (nt);
406
}
440
}
407
 
441
 
408
 
442
 
409
/*
443
/*
410
    EXPAND A BUILT-IN INTEGRAL TYPE
444
    EXPAND A BUILT-IN INTEGRAL TYPE
411
 
445
 
412
    This routine expands the integral type it by replacing built-in types
446
    This routine expands the integral type it by replacing built-in types
413
    such as size_t by their definition.
447
    such as size_t by their definition.
414
*/
448
*/
415
 
449
 
416
INT_TYPE expand_itype
450
INT_TYPE
417
    PROTO_N ( ( it ) )
-
 
418
    PROTO_T ( INT_TYPE it )
451
expand_itype(INT_TYPE it)
419
{
452
{
420
    if ( !IS_NULL_itype ( it ) && IS_itype_basic ( it ) ) {
453
	if (!IS_NULL_itype(it) && IS_itype_basic(it)) {
421
	BUILTIN_TYPE nt = DEREF_ntype ( itype_basic_no ( it ) ) ;
454
		BUILTIN_TYPE nt = DEREF_ntype(itype_basic_no(it));
422
	TYPE t = basetype_info [ nt ].set ;
455
		TYPE t = basetype_info[nt].set;
423
	if ( !IS_NULL_type ( t ) && !basetype_info [ nt ].key ) {
456
		if (!IS_NULL_type(t) && !basetype_info[nt].key) {
424
	    it = DEREF_itype ( type_integer_rep ( t ) ) ;
457
			it = DEREF_itype(type_integer_rep(t));
-
 
458
		}
425
	}
459
	}
426
    }
-
 
427
    return ( it ) ;
460
	return (it);
428
}
461
}
429
 
462
 
430
 
463
 
431
/*
464
/*
432
    CHECK BUILT-IN TYPE DEFINITIONS
465
    CHECK BUILT-IN TYPE DEFINITIONS
433
 
466
 
434
    This routine defines any tokens for the built-in types from their
467
    This routine defines any tokens for the built-in types from their
435
    set values.
468
    set values.
436
*/
469
*/
437
 
470
 
438
void term_itypes
471
void
439
    PROTO_Z ()
472
term_itypes(void)
440
{
473
{
441
    IDENTIFIER id = get_special ( TOK_ptrdiff_t, 1 ) ;
474
	IDENTIFIER id = get_special(TOK_ptrdiff_t, 1);
442
    if ( !IS_NULL_id ( id ) ) {
475
	if (!IS_NULL_id(id)) {
443
	TYPE t = basetype_info [ ntype_ptrdiff_t ].set ;
476
		TYPE t = basetype_info[ntype_ptrdiff_t].set;
444
	if ( !IS_NULL_type ( t ) ) {
477
		if (!IS_NULL_type(t)) {
445
	    IGNORE define_type_token ( id, t, 0 ) ;
478
			IGNORE define_type_token(id, t, 0);
446
	}
479
		}
447
    }
480
	}
448
    id = get_special ( TOK_size_t, 1 ) ;
481
	id = get_special(TOK_size_t, 1);
449
    if ( !IS_NULL_id ( id ) ) {
482
	if (!IS_NULL_id(id)) {
450
	TYPE t = basetype_info [ ntype_size_t ].set ;
483
		TYPE t = basetype_info[ntype_size_t].set;
451
	if ( !IS_NULL_type ( t ) ) {
484
		if (!IS_NULL_type(t)) {
452
	    IGNORE define_type_token ( id, t, 0 ) ;
485
			IGNORE define_type_token(id, t, 0);
453
	} else {
486
		} else {
454
	    TOKEN tok = DEREF_tok ( id_token_sort ( id ) ) ;
487
			TOKEN tok = DEREF_tok(id_token_sort(id));
455
	    if ( IS_tok_type ( tok ) ) {
488
			if (IS_tok_type(tok)) {
456
		/* Allow deduction of __size_t from size_t */
489
				/* Allow deduction of __size_t from size_t */
457
		t = DEREF_type ( tok_type_value ( tok ) ) ;
490
				t = DEREF_type(tok_type_value(tok));
458
		basetype_info [ ntype_size_t ].set = t ;
491
				basetype_info[ntype_size_t].set = t;
459
	    }
492
			}
460
	}
493
		}
461
    }
494
	}
462
    id = get_special ( TOK_size_t_2, 1 ) ;
495
	id = get_special(TOK_size_t_2, 1);
463
    if ( !IS_NULL_id ( id ) ) {
496
	if (!IS_NULL_id(id)) {
464
	TYPE t = basetype_info [ ntype_size_t ].set ;
497
		TYPE t = basetype_info[ntype_size_t].set;
465
	if ( !IS_NULL_type ( t ) ) {
498
		if (!IS_NULL_type(t)) {
466
	    t = promote_type ( t ) ;
499
			t = promote_type(t);
467
	    IGNORE define_type_token ( id, t, 0 ) ;
500
			IGNORE define_type_token(id, t, 0);
468
	}
501
		}
469
    }
502
	}
470
    id = get_special ( TOK_wchar_t, 1 ) ;
503
	id = get_special(TOK_wchar_t, 1);
471
    if ( !IS_NULL_id ( id ) ) {
504
	if (!IS_NULL_id(id)) {
472
	TYPE t = basetype_info [ ntype_wchar_t ].set ;
505
		TYPE t = basetype_info[ntype_wchar_t].set;
473
	if ( !IS_NULL_type ( t ) ) {
506
		if (!IS_NULL_type(t)) {
474
	    IGNORE define_type_token ( id, t, 0 ) ;
507
			IGNORE define_type_token(id, t, 0);
-
 
508
		}
475
	}
509
	}
476
    }
-
 
477
    return ;
510
	return;
478
}
511
}
479
 
512
 
480
 
513
 
481
/*
514
/*
482
    SET A PROMOTED TYPE
515
    SET A PROMOTED TYPE
Line 484... Line 517...
484
    This routine sets the promotion of type t to be s.  Note that this
517
    This routine sets the promotion of type t to be s.  Note that this
485
    implies that s is its own promotion and that the conversion from t to
518
    implies that s is its own promotion and that the conversion from t to
486
    s is deemed to be safe.
519
    s is deemed to be safe.
487
*/
520
*/
488
 
521
 
489
void set_promote_type
522
void
490
    PROTO_N ( ( t, s, ns ) )
-
 
491
    PROTO_T ( TYPE t X TYPE s X BUILTIN_TYPE ns )
523
set_promote_type(TYPE t, TYPE s, BUILTIN_TYPE ns)
492
{
524
{
493
    INT_TYPE it, is ;
525
	INT_TYPE it, is;
494
    BUILTIN_TYPE nt ;
526
	BUILTIN_TYPE nt;
495
    if ( !IS_type_integer ( t ) ) {
527
	if (!IS_type_integer(t)) {
496
	ENUM_TYPE et ;
528
		ENUM_TYPE et;
497
	if ( !IS_type_enumerate ( t ) ) {
529
		if (!IS_type_enumerate(t)) {
498
	    report ( crt_loc, ERR_pragma_promote_type ( t ) ) ;
530
			report(crt_loc, ERR_pragma_promote_type(t));
499
	    return ;
531
			return;
500
	}
532
		}
501
	et = DEREF_etype ( type_enumerate_defn ( t ) ) ;
533
		et = DEREF_etype(type_enumerate_defn(t));
502
	t = DEREF_type ( etype_rep ( et ) ) ;
534
		t = DEREF_type(etype_rep(et));
503
    }
535
	}
504
    if ( !IS_type_integer ( s ) ) {
536
	if (!IS_type_integer(s)) {
505
	ENUM_TYPE es ;
537
		ENUM_TYPE es;
506
	if ( !IS_type_enumerate ( s ) ) {
538
		if (!IS_type_enumerate(s)) {
507
	    report ( crt_loc, ERR_pragma_promote_type ( s ) ) ;
539
			report(crt_loc, ERR_pragma_promote_type(s));
508
	    return ;
540
			return;
509
	}
541
		}
510
	es = DEREF_etype ( type_enumerate_defn ( s ) ) ;
542
		es = DEREF_etype(type_enumerate_defn(s));
511
	s = DEREF_type ( etype_rep ( es ) ) ;
543
		s = DEREF_type(etype_rep(es));
512
    }
544
	}
513
 
545
 
514
    /* Check previous definition */
546
	/* Check previous definition */
515
    is = DEREF_itype ( type_integer_rep ( s ) ) ;
547
	is = DEREF_itype(type_integer_rep(s));
516
    it = DEREF_itype ( type_integer_rep ( t ) ) ;
548
	it = DEREF_itype(type_integer_rep(t));
517
    nt = DEREF_ntype ( itype_unprom ( it ) ) ;
549
	nt = DEREF_ntype(itype_unprom(it));
518
    if ( nt != ntype_none ) {
550
	if (nt != ntype_none) {
519
	ERROR err = NULL_err ;
551
		ERROR err = NULL_err;
520
	TYPE p = DEREF_type ( itype_prom ( it ) ) ;
552
		TYPE p = DEREF_type(itype_prom(it));
521
	IGNORE check_compatible ( p, s, 0, &err, 0 ) ;
553
		IGNORE check_compatible(p, s, 0, &err, 0);
522
	if ( !IS_NULL_err ( err ) ) {
554
		if (!IS_NULL_err(err)) {
523
	    ERROR err2 = ERR_pragma_promote_compat ( t ) ;
555
			ERROR err2 = ERR_pragma_promote_compat(t);
524
	    err = concat_error ( err, err2 ) ;
556
			err = concat_error(err, err2);
525
	    report ( crt_loc, err ) ;
557
			report(crt_loc, err);
526
	}
558
		}
527
	if ( nt != ntype_ellipsis ) ns = ntype_none ;
559
		if (nt != ntype_ellipsis) {
-
 
560
			ns = ntype_none;
528
    }
561
		}
-
 
562
	}
529
 
563
 
530
    /* Set promoted type */
564
	/* Set promoted type */
531
    if ( ns != ntype_none ) {
565
	if (ns != ntype_none) {
532
	LIST ( TYPE ) ps ;
566
		LIST(TYPE) ps;
533
	TYPE p = make_itype ( is, it ) ;
567
		TYPE p = make_itype(is, it);
534
	COPY_type ( itype_prom ( it ), p ) ;
568
		COPY_type(itype_prom(it), p);
535
	if ( nt == ntype_none ) {
569
		if (nt == ntype_none) {
536
	    COPY_ntype ( itype_unprom ( it ), ns ) ;
570
			COPY_ntype(itype_unprom(it), ns);
537
	}
571
		}
538
	ps = DEREF_list ( itype_cases ( is ) ) ;
572
		ps = DEREF_list(itype_cases(is));
539
	if ( EQ_list ( ps, all_int_types ) ) {
573
		if (EQ_list(ps, all_int_types)) {
540
	    /* Restrict cases for is */
574
			/* Restrict cases for is */
541
	    COPY_list ( itype_cases ( is ), all_prom_types ) ;
575
			COPY_list(itype_cases(is), all_prom_types);
542
	}
576
		}
543
	if ( IS_itype_basic ( it ) ) {
577
		if (IS_itype_basic(it)) {
544
	    BUILTIN_TYPE n = DEREF_ntype ( itype_basic_no ( it ) ) ;
578
			BUILTIN_TYPE n = DEREF_ntype(itype_basic_no(it));
545
	    if ( IS_itype_basic ( is ) ) {
579
			if (IS_itype_basic(is)) {
546
		/* Set conversion rank */
580
				/* Set conversion rank */
-
 
581
				BUILTIN_TYPE m =
547
		BUILTIN_TYPE m = DEREF_ntype ( itype_basic_no ( is ) ) ;
582
				    DEREF_ntype(itype_basic_no(is));
548
		builtin_casts [n] [m] = 0 ;
583
				builtin_casts[n][m] = 0;
549
	    }
584
			}
550
	    ns = n ;
585
			ns = n;
-
 
586
		}
-
 
587
		if (do_dump) {
-
 
588
			dump_promote(it, is);
-
 
589
		}
551
	}
590
	}
552
	if ( do_dump ) dump_promote ( it, is ) ;
-
 
553
    }
-
 
554
 
591
 
555
    /* Set s to be its own promotion */
592
	/* Set s to be its own promotion */
-
 
593
	if (!eq_itype(it, is)) {
556
    if ( !eq_itype ( it, is ) ) set_promote_type ( s, s, ns ) ;
594
		set_promote_type(s, s, ns);
-
 
595
	}
557
    return ;
596
	return;
558
}
597
}
559
 
598
 
560
 
599
 
561
/*
600
/*
562
    SET THE PROMOTION COMPUTATION TOKEN
601
    SET THE PROMOTION COMPUTATION TOKEN
563
 
602
 
564
    This routine sets the token used to calculate promoted types to be id.
603
    This routine sets the token used to calculate promoted types to be id.
565
*/
604
*/
566
 
605
 
567
void compute_promote_type
606
void
568
    PROTO_N ( ( id ) )
-
 
569
    PROTO_T ( IDENTIFIER id )
607
compute_promote_type(IDENTIFIER id)
570
{
608
{
571
    IDENTIFIER tid = resolve_token ( id, "ZZ", 0 ) ;
609
	IDENTIFIER tid = resolve_token(id, "ZZ", 0);
-
 
610
	if (!IS_NULL_id(tid)) {
572
    if ( !IS_NULL_id ( tid ) ) set_special ( TOK_promote, tid ) ;
611
		set_special(TOK_promote, tid);
-
 
612
	}
573
    return ;
613
	return;
574
}
614
}
575
 
615
 
576
 
616
 
577
/*
617
/*
578
    ARRAY OF ALL INTEGRAL AND FLOATING POINT TYPES
618
    ARRAY OF ALL INTEGRAL AND FLOATING POINT TYPES
579
 
619
 
580
    This array is used to hold all the integral and floating point types,
620
    This array is used to hold all the integral and floating point types,
581
    with all the cases of representation and semantics.
621
    with all the cases of representation and semantics.
582
*/
622
*/
583
 
623
 
584
static TYPE all_itypes [ ORDER_ntype ] [ ORDER_ntype ] ;
624
static TYPE all_itypes[ORDER_ntype][ORDER_ntype];
585
 
625
 
586
 
626
 
587
/*
627
/*
588
    CONSTRUCT AN INTEGRAL TYPE
628
    CONSTRUCT AN INTEGRAL TYPE
589
 
629
 
590
    This routine constructs an integral type with representation it and
630
    This routine constructs an integral type with representation it and
591
    semantics is.  If the semantic type is the null type then the semantics
631
    semantics is.  If the semantic type is the null type then the semantics
592
    are the same as the representation.
632
    are the same as the representation.
593
*/
633
*/
594
 
634
 
595
TYPE make_itype
635
TYPE
596
    PROTO_N ( ( it, is ) )
-
 
597
    PROTO_T ( INT_TYPE it X INT_TYPE is )
636
make_itype(INT_TYPE it, INT_TYPE is)
598
{
637
{
599
    TYPE r ;
638
	TYPE r;
600
    if ( IS_NULL_itype ( is ) ) is = it ;
639
	if (IS_NULL_itype(is)) {
-
 
640
		is = it;
-
 
641
	}
601
    if ( IS_itype_basic ( it ) && IS_itype_basic ( is ) ) {
642
	if (IS_itype_basic(it) && IS_itype_basic(is)) {
602
	BUILTIN_TYPE n = DEREF_ntype ( itype_basic_no ( it ) ) ;
643
		BUILTIN_TYPE n = DEREF_ntype(itype_basic_no(it));
603
	BUILTIN_TYPE m = DEREF_ntype ( itype_basic_no ( is ) ) ;
644
		BUILTIN_TYPE m = DEREF_ntype(itype_basic_no(is));
604
	r = all_itypes [n] [m] ;
645
		r = all_itypes[n][m];
605
	if ( IS_NULL_type ( r ) ) {
646
		if (IS_NULL_type(r)) {
606
	    MAKE_type_integer ( cv_none, it, is, r ) ;
647
			MAKE_type_integer(cv_none, it, is, r);
607
	    all_itypes [n] [m] = r ;
648
			all_itypes[n][m] = r;
608
	}
649
		}
609
    } else {
650
	} else {
610
	MAKE_type_integer ( cv_none, it, is, r ) ;
651
		MAKE_type_integer(cv_none, it, is, r);
611
    }
652
	}
612
    return ( r ) ;
653
	return (r);
613
}
654
}
614
 
655
 
615
 
656
 
616
/*
657
/*
617
    CONSTRUCT A FLOATING POINT TYPE
658
    CONSTRUCT A FLOATING POINT TYPE
618
 
659
 
619
    This routine constructs a floating point type with representation ft
660
    This routine constructs a floating point type with representation ft
620
    and semantics fs.
661
    and semantics fs.
621
*/
662
*/
622
 
663
 
623
TYPE make_ftype
664
TYPE
624
    PROTO_N ( ( ft, fs ) )
-
 
625
    PROTO_T ( FLOAT_TYPE ft X FLOAT_TYPE fs )
665
make_ftype(FLOAT_TYPE ft, FLOAT_TYPE fs)
626
{
666
{
627
    TYPE r ;
667
	TYPE r;
628
    if ( IS_NULL_ftype ( fs ) ) fs = ft ;
-
 
629
    if ( IS_ftype_basic ( ft ) ) {
-
 
630
	BUILTIN_TYPE n = DEREF_ntype ( ftype_basic_no ( ft ) ) ;
-
 
631
	BUILTIN_TYPE m = DEREF_ntype ( ftype_basic_no ( fs ) ) ;
-
 
632
	r = all_itypes [n] [m] ;
-
 
633
	if ( IS_NULL_type ( r ) ) {
668
	if (IS_NULL_ftype(fs)) {
634
	    MAKE_type_floating ( cv_none, ft, fs, r ) ;
-
 
635
	    all_itypes [n] [m] = r ;
669
		fs = ft;
636
	}
670
	}
-
 
671
	if (IS_ftype_basic(ft)) {
-
 
672
		BUILTIN_TYPE n = DEREF_ntype(ftype_basic_no(ft));
-
 
673
		BUILTIN_TYPE m = DEREF_ntype(ftype_basic_no(fs));
-
 
674
		r = all_itypes[n][m];
-
 
675
		if (IS_NULL_type(r)) {
-
 
676
			MAKE_type_floating(cv_none, ft, fs, r);
-
 
677
			all_itypes[n][m] = r;
-
 
678
		}
637
    } else {
679
	} else {
638
	MAKE_type_floating ( cv_none, ft, fs, r ) ;
680
		MAKE_type_floating(cv_none, ft, fs, r);
639
    }
681
	}
640
    return ( r ) ;
682
	return (r);
641
}
683
}
642
 
684
 
643
 
685
 
644
/*
686
/*
645
    CREATE AN INTEGRAL PROMOTION TYPE
687
    CREATE AN INTEGRAL PROMOTION TYPE
646
 
688
 
647
    This routine sets the promotion type of the integral type it to be
689
    This routine sets the promotion type of the integral type it to be
648
    ip.  If ip is the null type then a promotion type is created.  An
690
    ip.  If ip is the null type then a promotion type is created.  An
649
    integral type corresponding to it is returned.
691
    integral type corresponding to it is returned.
650
*/
692
*/
651
 
693
 
652
TYPE promote_itype
694
TYPE
653
    PROTO_N ( ( it, ip ) )
-
 
654
    PROTO_T ( INT_TYPE it X INT_TYPE ip )
695
promote_itype(INT_TYPE it, INT_TYPE ip)
655
{
696
{
656
    TYPE p ;
697
	TYPE p;
657
    TYPE t = make_itype ( it, it ) ;
698
	TYPE t = make_itype(it, it);
658
    if ( IS_NULL_itype ( ip ) ) {
699
	if (IS_NULL_itype(ip)) {
659
	MAKE_itype_promote ( NULL_type, all_prom_types, it, ip ) ;
700
		MAKE_itype_promote(NULL_type, all_prom_types, it, ip);
660
    } else {
701
	} else {
661
	COPY_ntype ( itype_unprom ( ip ), ntype_ellipsis ) ;
702
		COPY_ntype(itype_unprom(ip), ntype_ellipsis);
662
	COPY_ntype ( itype_unprom ( it ), ntype_ellipsis ) ;
703
		COPY_ntype(itype_unprom(it), ntype_ellipsis);
663
    }
704
	}
664
    if ( EQ_itype ( it, ip ) ) {
705
	if (EQ_itype(it, ip)) {
665
	p = t ;
706
		p = t;
666
    } else {
707
	} else {
667
	p = make_itype ( ip, it ) ;
708
		p = make_itype(ip, it);
668
    }
709
	}
669
    COPY_type ( itype_prom ( ip ), p ) ;
710
	COPY_type(itype_prom(ip), p);
670
    COPY_type ( itype_prom ( it ), p ) ;
711
	COPY_type(itype_prom(it), p);
671
    return ( t ) ;
712
	return (t);
672
}
713
}
673
 
714
 
674
 
715
 
675
/*
716
/*
676
    ARITHMETIC TYPES
717
    ARITHMETIC TYPES
677
 
718
 
678
    The only difficult case in the basic arithmetic types is the combination
719
    The only difficult case in the basic arithmetic types is the combination
679
    of 'signed long' and 'unsigned int'.  The variable arith_slong_uint is
720
    of 'signed long' and 'unsigned int'.  The variable arith_slong_uint is
680
    used to hold this value.  If 'long long' is allowed then combining
721
    used to hold this value.  If 'long long' is allowed then combining
681
    'signed long long' with 'unsigned long' or 'unsigned int' is also
722
    'signed long long' with 'unsigned long' or 'unsigned int' is also
682
    target dependent.
723
    target dependent.
683
*/
724
*/
684
 
725
 
685
static INT_TYPE arith_slong_uint ;
726
static INT_TYPE arith_slong_uint;
686
static INT_TYPE arith_sllong_uint ;
727
static INT_TYPE arith_sllong_uint;
687
static INT_TYPE arith_sllong_ulong ;
728
static INT_TYPE arith_sllong_ulong;
688
 
729
 
689
 
730
 
690
/*
731
/*
691
    FIND AN ARITHMETIC INTEGRAL TYPE
732
    FIND AN ARITHMETIC INTEGRAL TYPE
692
 
733
 
693
    This routine finds the type to be used for arithmetic involving operands
734
    This routine finds the type to be used for arithmetic involving operands
694
    of promoted integral types t and s.  The operands a and b are passed
735
    of promoted integral types t and s.  The operands a and b are passed
695
    in to enable the semantic type to be determined.  Note that for base
736
    in to enable the semantic type to be determined.  Note that for base
696
    integral types, because:
737
    integral types, because:
697
 
738
 
Line 708... Line 749...
708
		    UL | UL  UL  UL  UL  ??  UX
749
		    UL | UL  UL  UL  UL  ??  UX
709
		    SX | SX  ??  SX  ??  SX  UX
750
		    SX | SX  ??  SX  ??  SX  UX
710
		    UX | UX  UX  UX  UX  UX  UX
751
		    UX | UX  UX  UX  UX  UX  UX
711
*/
752
*/
712
 
753
 
713
TYPE arith_itype
754
TYPE
714
    PROTO_N ( ( t, s, a, b ) )
-
 
715
    PROTO_T ( TYPE t X TYPE s X EXP a X EXP b )
755
arith_itype(TYPE t, TYPE s, EXP a, EXP b)
716
{
756
{
717
    TYPE r ;
757
	TYPE r;
718
    if ( IS_type_integer ( t ) && IS_type_integer ( s ) ) {
758
	if (IS_type_integer(t) && IS_type_integer(s)) {
719
	INT_TYPE ir ;
759
		INT_TYPE ir;
720
	INT_TYPE it = DEREF_itype ( type_integer_rep ( t ) ) ;
760
		INT_TYPE it = DEREF_itype(type_integer_rep(t));
721
	INT_TYPE is = DEREF_itype ( type_integer_rep ( s ) ) ;
761
		INT_TYPE is = DEREF_itype(type_integer_rep(s));
722
 
762
 
723
	/* Find semantic type of result */
763
		/* Find semantic type of result */
724
	INT_TYPE mr = NULL_itype ;
764
		INT_TYPE mr = NULL_itype;
725
	INT_TYPE mt = DEREF_itype ( type_integer_sem ( t ) ) ;
765
		INT_TYPE mt = DEREF_itype(type_integer_sem(t));
726
	INT_TYPE ms = DEREF_itype ( type_integer_sem ( s ) ) ;
766
		INT_TYPE ms = DEREF_itype(type_integer_sem(s));
727
	if ( EQ_itype ( mt, ms ) ) {
767
		if (EQ_itype(mt, ms)) {
728
	    /* Same semantic types */
768
			/* Same semantic types */
729
	    mr = mt ;
769
			mr = mt;
730
	} else {
-
 
731
	    /* Allow for variable semantics of constants */
-
 
732
	    if ( !IS_NULL_exp ( a ) && IS_exp_int_lit ( a ) ) {
-
 
733
		if ( !IS_NULL_exp ( b ) && IS_exp_int_lit ( b ) ) {
-
 
734
		    /* Leave to constant evaluation routines */
-
 
735
		    /* EMPTY */
-
 
736
		} else {
770
		} else {
-
 
771
			/* Allow for variable semantics of constants */
-
 
772
			if (!IS_NULL_exp(a) && IS_exp_int_lit(a)) {
-
 
773
				if (!IS_NULL_exp(b) && IS_exp_int_lit(b)) {
-
 
774
					/* Leave to constant evaluation
-
 
775
					 * routines */
-
 
776
					/* EMPTY */
-
 
777
				} else {
737
		    NAT n = DEREF_nat ( exp_int_lit_nat ( a ) ) ;
778
					NAT n = DEREF_nat(exp_int_lit_nat(a));
738
		    COPY_itype ( type_integer_rep ( s ), ms ) ;
779
					COPY_itype(type_integer_rep(s), ms);
739
		    if ( check_nat_range ( s, n ) == 0 ) mr = ms ;
780
					if (check_nat_range(s, n) == 0) {
-
 
781
						mr = ms;
-
 
782
					}
740
		    COPY_itype ( type_integer_rep ( s ), is ) ;
783
					COPY_itype(type_integer_rep(s), is);
741
		}
784
				}
742
	    } else if ( !IS_NULL_exp ( b ) && IS_exp_int_lit ( b ) ) {
785
			} else if (!IS_NULL_exp(b) && IS_exp_int_lit(b)) {
743
		NAT n = DEREF_nat ( exp_int_lit_nat ( b ) ) ;
786
				NAT n = DEREF_nat(exp_int_lit_nat(b));
744
		COPY_itype ( type_integer_rep ( t ), mt ) ;
787
				COPY_itype(type_integer_rep(t), mt);
745
		if ( check_nat_range ( t, n ) == 0 ) mr = mt ;
788
				if (check_nat_range(t, n) == 0) {
-
 
789
					mr = mt;
-
 
790
				}
746
		COPY_itype ( type_integer_rep ( t ), it ) ;
791
				COPY_itype(type_integer_rep(t), it);
747
	    }
792
			}
748
	}
793
		}
749
 
794
 
750
	/* Find representation type of result */
795
		/* Find representation type of result */
751
	if ( EQ_itype ( it, is ) ) {
796
		if (EQ_itype(it, is)) {
752
	    r = make_itype ( it, mr ) ;
797
			r = make_itype(it, mr);
753
	    return ( r ) ;
798
			return (r);
754
	}
799
		}
755
	if ( IS_itype_basic ( it ) ) {
800
		if (IS_itype_basic(it)) {
756
	    BUILTIN_TYPE nt = DEREF_ntype ( itype_basic_no ( it ) ) ;
801
			BUILTIN_TYPE nt = DEREF_ntype(itype_basic_no(it));
757
	    if ( IS_itype_basic ( is ) ) {
802
			if (IS_itype_basic(is)) {
758
		BUILTIN_TYPE bt = nt ;
803
				BUILTIN_TYPE bt = nt;
-
 
804
				BUILTIN_TYPE bs =
759
		BUILTIN_TYPE bs = DEREF_ntype ( itype_basic_no ( is ) ) ;
805
				    DEREF_ntype(itype_basic_no(is));
760
		if ( bs > bt ) {
806
				if (bs > bt) {
761
		    bt = bs ;
807
					bt = bs;
762
		    bs = nt ;
808
					bs = nt;
763
		    ir = is ;
809
					ir = is;
764
		} else {
810
				} else {
765
		    ir = it ;
811
					ir = it;
766
		}
812
				}
767
		if ( bt <= ntype_ullong ) {
813
				if (bt <= ntype_ullong) {
768
		    if ( bt == ntype_sllong ) {
814
					if (bt == ntype_sllong) {
-
 
815
						if (bs == ntype_ulong) {
769
			if ( bs == ntype_ulong ) ir = arith_sllong_ulong ;
816
							ir = arith_sllong_ulong;
-
 
817
						}
-
 
818
						if (bs == ntype_uint) {
770
			if ( bs == ntype_uint ) ir = arith_sllong_uint ;
819
							ir = arith_sllong_uint;
-
 
820
						}
771
		    } else if ( bt == ntype_slong ) {
821
					} else if (bt == ntype_slong) {
-
 
822
						if (bs == ntype_uint) {
772
			if ( bs == ntype_uint ) ir = arith_slong_uint ;
823
							ir = arith_slong_uint;
773
		    }
824
						}
-
 
825
					}
774
		    r = make_itype ( ir, mr ) ;
826
					r = make_itype(ir, mr);
775
		    return ( r ) ;
827
					return (r);
-
 
828
				}
-
 
829
			}
-
 
830
			if (nt == ntype_ullong) {
-
 
831
				r = make_itype(it, mr);
-
 
832
				return (r);
-
 
833
			}
-
 
834
			if (nt == ntype_ulong &&
-
 
835
			    !basetype_info[ntype_sllong].key) {
-
 
836
				r = make_itype(it, mr);
-
 
837
				return (r);
-
 
838
			}
-
 
839
			if (nt == ntype_sint) {
-
 
840
				r = make_itype(is, mr);
-
 
841
				return (r);
-
 
842
			}
-
 
843
		}
-
 
844
		if (IS_itype_basic(is)) {
-
 
845
			BUILTIN_TYPE ns = DEREF_ntype(itype_basic_no(is));
-
 
846
			if (ns == ntype_ullong) {
-
 
847
				r = make_itype(is, mr);
-
 
848
				return (r);
-
 
849
			}
-
 
850
			if (ns == ntype_ulong &&
-
 
851
			    !basetype_info[ntype_sllong].key) {
-
 
852
				r = make_itype(is, mr);
-
 
853
				return (r);
-
 
854
			}
-
 
855
			if (ns == ntype_sint) {
-
 
856
				r = make_itype(it, mr);
-
 
857
				return (r);
-
 
858
			}
776
		}
859
		}
777
	    }
-
 
778
	    if ( nt == ntype_ullong ) {
-
 
779
		r = make_itype ( it, mr ) ;
-
 
780
		return ( r ) ;
-
 
781
	    }
-
 
782
	    if ( nt == ntype_ulong && !basetype_info [ ntype_sllong ].key ) {
-
 
783
		r = make_itype ( it, mr ) ;
-
 
784
		return ( r ) ;
-
 
785
	    }
-
 
786
	    if ( nt == ntype_sint ) {
-
 
787
		r = make_itype ( is, mr ) ;
-
 
788
		return ( r ) ;
-
 
789
	    }
-
 
790
	}
-
 
791
	if ( IS_itype_basic ( is ) ) {
-
 
792
	    BUILTIN_TYPE ns = DEREF_ntype ( itype_basic_no ( is ) ) ;
-
 
793
	    if ( ns == ntype_ullong ) {
-
 
794
		r = make_itype ( is, mr ) ;
-
 
795
		return ( r ) ;
-
 
796
	    }
-
 
797
	    if ( ns == ntype_ulong && !basetype_info [ ntype_sllong ].key ) {
-
 
798
		r = make_itype ( is, mr ) ;
-
 
799
		return ( r ) ;
-
 
800
	    }
-
 
801
	    if ( ns == ntype_sint ) {
-
 
802
		r = make_itype ( it, mr ) ;
-
 
803
		return ( r ) ;
-
 
804
	    }
-
 
805
	}
-
 
806
 
860
 
807
	/* Construct an arithmetic type */
861
		/* Construct an arithmetic type */
808
	MAKE_itype_arith ( NULL_type, all_prom_types, it, is, ir ) ;
862
		MAKE_itype_arith(NULL_type, all_prom_types, it, is, ir);
809
	r = promote_itype ( ir, ir ) ;
863
		r = promote_itype(ir, ir);
810
	if ( !IS_NULL_itype ( mr ) ) r = make_itype ( ir, mr ) ;
864
		if (!IS_NULL_itype(mr)) {
-
 
865
			r = make_itype(ir, mr);
-
 
866
		}
811
    } else {
867
	} else {
812
	/* This shouldn't happen */
868
		/* This shouldn't happen */
813
	r = t ;
869
		r = t;
814
    }
870
	}
815
    return ( r ) ;
871
	return (r);
816
}
872
}
817
 
873
 
818
 
874
 
819
/*
875
/*
820
    CREATE A FLOATING POINT PROMOTION TYPE
876
    CREATE A FLOATING POINT PROMOTION TYPE
Line 823... Line 879...
823
    type ft to be fp.  If fp is the null type then an argument promotion
879
    type ft to be fp.  If fp is the null type then an argument promotion
824
    type is created.  A floating point type corresponding to ft is
880
    type is created.  A floating point type corresponding to ft is
825
    returned.
881
    returned.
826
*/
882
*/
827
 
883
 
828
TYPE promote_ftype
884
TYPE
829
    PROTO_N ( ( ft, fp ) )
-
 
830
    PROTO_T ( FLOAT_TYPE ft X FLOAT_TYPE fp )
885
promote_ftype(FLOAT_TYPE ft, FLOAT_TYPE fp)
831
{
886
{
832
    TYPE t, p ;
887
	TYPE t, p;
833
    init_float ( ft ) ;
888
	init_float(ft);
834
    t = make_ftype ( ft, ft ) ;
889
	t = make_ftype(ft, ft);
835
    if ( IS_NULL_ftype ( fp ) ) {
890
	if (IS_NULL_ftype(fp)) {
836
	MAKE_ftype_arg_promote ( NULL_type, ft, fp ) ;
891
		MAKE_ftype_arg_promote(NULL_type, ft, fp);
837
	init_float ( fp ) ;
892
		init_float(fp);
838
    }
893
	}
839
    if ( EQ_ftype ( ft, fp ) ) {
894
	if (EQ_ftype(ft, fp)) {
840
	p = t ;
895
		p = t;
841
    } else {
896
	} else {
842
	p = make_ftype ( fp, ft ) ;
897
		p = make_ftype(fp, ft);
843
    }
898
	}
844
    COPY_type ( ftype_arg_prom ( ft ), p ) ;
899
	COPY_type(ftype_arg_prom(ft), p);
845
    COPY_type ( ftype_arg_prom ( fp ), p ) ;
900
	COPY_type(ftype_arg_prom(fp), p);
846
    return ( t ) ;
901
	return (t);
847
}
902
}
848
 
903
 
849
 
904
 
850
/*
905
/*
851
    FIND AN ARITHMETIC FLOATING POINT TYPE
906
    FIND AN ARITHMETIC FLOATING POINT TYPE
852
 
907
 
853
    This routine finds the type to be used for arithmetic involving operands
908
    This routine finds the type to be used for arithmetic involving operands
854
    of floating point types t and s.
909
    of floating point types t and s.
855
*/
910
*/
856
 
911
 
857
TYPE arith_ftype
912
TYPE
858
    PROTO_N ( ( t, s ) )
-
 
859
    PROTO_T ( TYPE t X TYPE s )
913
arith_ftype(TYPE t, TYPE s)
860
{
914
{
861
    TYPE r ;
915
	TYPE r;
862
    if ( IS_type_floating ( t ) && IS_type_floating ( s ) ) {
916
	if (IS_type_floating(t) && IS_type_floating(s)) {
863
	FLOAT_TYPE fr ;
917
		FLOAT_TYPE fr;
864
	FLOAT_TYPE ft = DEREF_ftype ( type_floating_rep ( t ) ) ;
918
		FLOAT_TYPE ft = DEREF_ftype(type_floating_rep(t));
865
	FLOAT_TYPE fs = DEREF_ftype ( type_floating_rep ( s ) ) ;
919
		FLOAT_TYPE fs = DEREF_ftype(type_floating_rep(s));
866
 
920
 
867
	/* Find the arithmetic type */
921
		/* Find the arithmetic type */
868
	if ( EQ_ftype ( ft, fs ) ) {
922
		if (EQ_ftype(ft, fs)) {
869
	    return ( t ) ;
923
			return (t);
870
	} else if ( IS_ftype_basic ( ft ) ) {
924
		} else if (IS_ftype_basic(ft)) {
871
	    BUILTIN_TYPE nt = DEREF_ntype ( ftype_basic_no ( ft ) ) ;
925
			BUILTIN_TYPE nt = DEREF_ntype(ftype_basic_no(ft));
872
	    if ( IS_ftype_basic ( fs ) ) {
926
			if (IS_ftype_basic(fs)) {
-
 
927
				BUILTIN_TYPE ns =
873
		BUILTIN_TYPE ns = DEREF_ntype ( ftype_basic_no ( fs ) ) ;
928
				    DEREF_ntype(ftype_basic_no(fs));
874
		if ( nt == ntype_ldouble ) return ( t ) ;
929
				if (nt == ntype_ldouble) {
-
 
930
					return (t);
-
 
931
				}
875
		if ( ns == ntype_ldouble ) return ( s ) ;
932
				if (ns == ntype_ldouble) {
-
 
933
					return (s);
-
 
934
				}
876
		if ( nt == ntype_double ) return ( t ) ;
935
				if (nt == ntype_double) {
-
 
936
					return (t);
-
 
937
				}
877
		if ( ns == ntype_double ) return ( s ) ;
938
				if (ns == ntype_double) {
-
 
939
					return (s);
-
 
940
				}
878
		return ( t ) ;
941
				return (t);
879
	    }
942
			}
880
	    if ( nt == ntype_ldouble ) return ( t ) ;
943
			if (nt == ntype_ldouble) {
-
 
944
				return (t);
-
 
945
			}
881
	    if ( nt == ntype_float ) return ( s ) ;
946
			if (nt == ntype_float) {
-
 
947
				return (s);
-
 
948
			}
882
	} else if ( IS_ftype_basic ( fs ) ) {
949
		} else if (IS_ftype_basic(fs)) {
883
	    BUILTIN_TYPE ns = DEREF_ntype ( ftype_basic_no ( fs ) ) ;
950
			BUILTIN_TYPE ns = DEREF_ntype(ftype_basic_no(fs));
884
	    if ( ns == ntype_ldouble ) return ( s ) ;
951
			if (ns == ntype_ldouble) {
-
 
952
				return (s);
-
 
953
			}
885
	    if ( ns == ntype_float ) return ( t ) ;
954
			if (ns == ntype_float) {
-
 
955
				return (t);
-
 
956
			}
886
	}
957
		}
887
 
958
 
888
	/* Construct an arithmetic type */
959
		/* Construct an arithmetic type */
889
	MAKE_ftype_arith ( NULL_type, ft, fs, fr ) ;
960
		MAKE_ftype_arith(NULL_type, ft, fs, fr);
890
	r = promote_ftype ( fr, NULL_ftype ) ;
961
		r = promote_ftype(fr, NULL_ftype);
891
    } else {
962
	} else {
892
	/* This shouldn't happen */
963
		/* This shouldn't happen */
893
	r = t ;
964
		r = t;
894
    }
965
	}
895
    return ( r ) ;
966
	return (r);
896
}
967
}
897
 
968
 
898
 
969
 
899
/*
970
/*
900
    FIND A KEYWORD TYPE
971
    FIND A KEYWORD TYPE
901
 
972
 
902
    This routine finds the type corresponding to the keyword with lexical
973
    This routine finds the type corresponding to the keyword with lexical
903
    token number tok.
974
    token number tok.
904
*/
975
*/
905
 
976
 
906
BASE_TYPE key_type
977
BASE_TYPE
907
    PROTO_N ( ( tok ) )
-
 
908
    PROTO_T ( int tok )
978
key_type(int tok)
909
{
979
{
910
    BASE_TYPE bs = btype_none ;
980
	BASE_TYPE bs = btype_none;
911
    switch ( tok ) {
981
	switch (tok) {
-
 
982
	case lex_bool:
912
	case lex_bool : bs = btype_bool ; break ;
983
		bs = btype_bool;
-
 
984
		break;
-
 
985
	case lex_ptrdiff_Ht:
913
	case lex_ptrdiff_Ht : bs = btype_ptrdiff_t ; break ;
986
		bs = btype_ptrdiff_t;
-
 
987
		break;
-
 
988
	case lex_size_Ht:
914
	case lex_size_Ht : bs = btype_size_t ; break ;
989
		bs = btype_size_t;
-
 
990
		break;
-
 
991
	case lex_wchar_Ht:
915
	case lex_wchar_Ht : bs = btype_wchar_t ; break ;
992
		bs = btype_wchar_t;
-
 
993
		break;
916
    }
994
	}
917
    return ( bs ) ;
995
	return (bs);
918
}
996
}
919
 
997
 
920
 
998
 
921
/*
999
/*
922
    CREATE A TOKENISED INTEGRAL TYPE
1000
    CREATE A TOKENISED INTEGRAL TYPE
923
 
1001
 
924
    This routine creates a tokenised integral type from the token id
1002
    This routine creates a tokenised integral type from the token id
925
    and the token arguments args.
1003
    and the token arguments args.
926
*/
1004
*/
927
 
1005
 
928
TYPE apply_itype_token
1006
TYPE
929
    PROTO_N ( ( id, args ) )
-
 
930
    PROTO_T ( IDENTIFIER id X LIST ( TOKEN ) args )
1007
apply_itype_token(IDENTIFIER id, LIST(TOKEN) args)
931
{
1008
{
932
    TYPE t ;
1009
	TYPE t;
933
    INT_TYPE it ;
1010
	INT_TYPE it;
934
 
1011
 
935
    /* Check for previous instance */
1012
	/* Check for previous instance */
936
    if ( IS_NULL_list ( args ) ) {
1013
	if (IS_NULL_list(args)) {
937
	if ( IS_id_token ( id ) ) {
1014
		if (IS_id_token(id)) {
938
	    IDENTIFIER tid = DEREF_id ( id_token_alt ( id ) ) ;
1015
			IDENTIFIER tid = DEREF_id(id_token_alt(id));
939
	    if ( IS_id_type_alias ( tid ) ) {
1016
			if (IS_id_type_alias(tid)) {
940
		t = DEREF_type ( id_type_alias_defn ( tid ) ) ;
1017
				t = DEREF_type(id_type_alias_defn(tid));
941
		t = copy_typedef ( tid, t, cv_none ) ;
1018
				t = copy_typedef(tid, t, cv_none);
942
		COPY_id ( type_name ( t ), tid ) ;
1019
				COPY_id(type_name(t), tid);
943
		return ( t ) ;
1020
				return (t);
944
	    }
1021
			}
945
	}
1022
		}
946
    }
1023
	}
947
 
1024
 
948
    /* Create new instance */
1025
	/* Create new instance */
949
    MAKE_itype_token ( NULL_type, all_int_types, id, args, it ) ;
1026
	MAKE_itype_token(NULL_type, all_int_types, id, args, it);
950
    t = promote_itype ( it, NULL_itype ) ;
1027
	t = promote_itype(it, NULL_itype);
951
 
1028
 
952
    /* Allow for special tokens */
1029
	/* Allow for special tokens */
953
    if ( IS_id_token ( id ) ) {
1030
	if (IS_id_token(id)) {
954
	int tok = builtin_token ( id ) ;
1031
		int tok = builtin_token(id);
955
	switch ( tok ) {
1032
		switch (tok) {
-
 
1033
		case TOK_ptrdiff_t:
956
	    case TOK_ptrdiff_t : t = type_ptrdiff_t ; break ;
1034
			t = type_ptrdiff_t;
-
 
1035
			break;
-
 
1036
		case TOK_size_t:
-
 
1037
			t = type_size_t;
-
 
1038
			break;
957
	    case TOK_size_t : t = type_size_t ; break ;
1039
		case TOK_size_t_2:
958
	    case TOK_size_t_2 : t = promote_type ( type_size_t ) ; break ;
1040
			t = promote_type(type_size_t);
-
 
1041
			break;
-
 
1042
		case TOK_wchar_t:
959
	    case TOK_wchar_t : t = type_wchar_t ; break ;
1043
			t = type_wchar_t;
-
 
1044
			break;
960
	}
1045
		}
961
    }
1046
	}
962
    return ( t ) ;
1047
	return (t);
963
}
1048
}
964
 
1049
 
965
 
1050
 
966
/*
1051
/*
967
    CREATE A TOKENISED FLOATING POINT TYPE
1052
    CREATE A TOKENISED FLOATING POINT TYPE
968
 
1053
 
969
    This routine creates a tokenised floating point type from the token
1054
    This routine creates a tokenised floating point type from the token
970
    id and the token arguments args.
1055
    id and the token arguments args.
971
*/
1056
*/
972
 
1057
 
973
TYPE apply_ftype_token
1058
TYPE
974
    PROTO_N ( ( id, args ) )
-
 
975
    PROTO_T ( IDENTIFIER id X LIST ( TOKEN ) args )
1059
apply_ftype_token(IDENTIFIER id, LIST(TOKEN) args)
976
{
1060
{
977
    TYPE t ;
1061
	TYPE t;
978
    FLOAT_TYPE ft ;
1062
	FLOAT_TYPE ft;
979
 
1063
 
980
    /* Check for previous instance */
1064
	/* Check for previous instance */
981
    if ( IS_NULL_list ( args ) ) {
1065
	if (IS_NULL_list(args)) {
982
	if ( IS_id_token ( id ) ) {
1066
		if (IS_id_token(id)) {
983
	    IDENTIFIER tid = DEREF_id ( id_token_alt ( id ) ) ;
1067
			IDENTIFIER tid = DEREF_id(id_token_alt(id));
984
	    if ( IS_id_type_alias ( tid ) ) {
1068
			if (IS_id_type_alias(tid)) {
985
		t = DEREF_type ( id_type_alias_defn ( tid ) ) ;
1069
				t = DEREF_type(id_type_alias_defn(tid));
986
		t = copy_typedef ( tid, t, cv_none ) ;
1070
				t = copy_typedef(tid, t, cv_none);
987
		COPY_id ( type_name ( t ), tid ) ;
1071
				COPY_id(type_name(t), tid);
988
		return ( t ) ;
1072
				return (t);
989
	    }
1073
			}
990
	}
1074
		}
991
    }
1075
	}
992
 
1076
 
993
    /* Create new instance */
1077
	/* Create new instance */
994
    MAKE_ftype_token ( NULL_type, id, args, ft ) ;
1078
	MAKE_ftype_token(NULL_type, id, args, ft);
995
    t = promote_ftype ( ft, NULL_ftype ) ;
1079
	t = promote_ftype(ft, NULL_ftype);
996
    return ( t ) ;
1080
	return (t);
997
}
1081
}
998
 
1082
 
999
 
1083
 
1000
/*
1084
/*
1001
    FIND THE SIGN OF A TYPE
1085
    FIND THE SIGN OF A TYPE
1002
 
1086
 
1003
    This routine returns the sign of the type specified by bt.
1087
    This routine returns the sign of the type specified by bt.
1004
*/
1088
*/
1005
 
1089
 
1006
static BASE_TYPE find_itype_sign
1090
static BASE_TYPE
1007
    PROTO_N ( ( bt ) )
-
 
1008
    PROTO_T ( BASE_TYPE bt )
1091
find_itype_sign(BASE_TYPE bt)
1009
{
1092
{
1010
    BASE_TYPE sign ;
1093
	BASE_TYPE sign;
1011
    if ( bt & btype_unsigned ) {
1094
	if (bt & btype_unsigned) {
1012
	sign = btype_unsigned ;
1095
		sign = btype_unsigned;
1013
    } else if ( bt & btype_signed ) {
1096
	} else if (bt & btype_signed) {
1014
	sign = basetype_info [ ntype_sint ].sign ;
1097
		sign = basetype_info[ntype_sint].sign;
1015
    } else {
1098
	} else {
1016
	sign = btype_none ;
1099
		sign = btype_none;
1017
    }
1100
	}
1018
    return ( sign ) ;
1101
	return (sign);
1019
}
1102
}
1020
 
1103
 
1021
 
1104
 
1022
/*
1105
/*
1023
    FIND THE SIZE OF AN INTEGRAL TYPE
1106
    FIND THE SIZE OF AN INTEGRAL TYPE
1024
 
1107
 
1025
    This routine determines the minimum number of bits in the integral
1108
    This routine determines the minimum number of bits in the integral
1026
    type it.  It also returns information on the the maximum number of
1109
    type it.  It also returns information on the the maximum number of
1027
    bits and the sign of the type in the given pointer arguments.
1110
    bits and the sign of the type in the given pointer arguments.
1028
*/
1111
*/
1029
 
1112
 
1030
static unsigned find_itype_size
1113
static unsigned
1031
    PROTO_N ( ( it, mbits, sign ) )
-
 
1032
    PROTO_T ( INT_TYPE it X unsigned *mbits X BASE_TYPE *sign )
1114
find_itype_size(INT_TYPE it, unsigned *mbits, BASE_TYPE *sign)
1033
{
1115
{
1034
    unsigned sz ;
1116
	unsigned sz;
1035
    it = expand_itype ( it ) ;
1117
	it = expand_itype(it);
1036
    switch ( TAG_itype ( it ) ) {
1118
	switch (TAG_itype(it)) {
1037
	case itype_basic_tag : {
1119
	case itype_basic_tag: {
1038
	    /* Built-in types */
1120
		/* Built-in types */
1039
	    BUILTIN_TYPE n = DEREF_ntype ( itype_basic_no ( it ) ) ;
1121
		BUILTIN_TYPE n = DEREF_ntype(itype_basic_no(it));
1040
	    sz = basetype_info [n].min_bits ;
1122
		sz = basetype_info[n].min_bits;
1041
	    *mbits = basetype_info [n].max_bits ;
1123
		*mbits = basetype_info[n].max_bits;
1042
	    *sign = basetype_info [n].sign ;
1124
		*sign = basetype_info[n].sign;
1043
	    break ;
1125
		break;
1044
	}
1126
	}
1045
	case itype_bitfield_tag : {
1127
	case itype_bitfield_tag: {
1046
	    /* Bitfield types */
1128
		/* Bitfield types */
1047
	    NAT n = DEREF_nat ( itype_bitfield_size ( it ) ) ;
1129
		NAT n = DEREF_nat(itype_bitfield_size(it));
1048
	    BASE_TYPE rep = DEREF_btype ( itype_bitfield_rep ( it ) ) ;
1130
		BASE_TYPE rep = DEREF_btype(itype_bitfield_rep(it));
1049
	    sz = ( unsigned ) get_nat_value ( n ) ;
1131
		sz = (unsigned)get_nat_value(n);
1050
	    *mbits = sz ;
1132
		*mbits = sz;
1051
	    *sign = find_itype_sign ( rep ) ;
1133
		*sign = find_itype_sign(rep);
1052
	    break ;
1134
		break;
1053
	}
1135
	}
1054
	case itype_promote_tag : {
1136
	case itype_promote_tag: {
1055
	    /* Promotion types */
1137
		/* Promotion types */
1056
	    unsigned si ;
1138
		unsigned si;
1057
	    it = DEREF_itype ( itype_promote_arg ( it ) ) ;
1139
		it = DEREF_itype(itype_promote_arg(it));
1058
	    sz = find_itype_size ( it, mbits, sign ) ;
1140
		sz = find_itype_size(it, mbits, sign);
1059
	    si = basetype_info [ ntype_sint ].min_bits ;
1141
		si = basetype_info[ntype_sint].min_bits;
1060
	    if ( sz < si ) {
1142
		if (sz < si) {
1061
		sz = si ;
1143
			sz = si;
1062
		*mbits = basetype_info [ ntype_ellipsis ].max_bits ;
1144
			*mbits = basetype_info[ntype_ellipsis].max_bits;
1063
		*sign = btype_none ;
1145
			*sign = btype_none;
1064
	    }
1146
		}
1065
	    break ;
1147
		break;
1066
	}
1148
	}
1067
	case itype_arith_tag : {
1149
	case itype_arith_tag: {
1068
	    /* Arithmetic types */
1150
		/* Arithmetic types */
1069
	    INT_TYPE is = DEREF_itype ( itype_arith_arg1 ( it ) ) ;
1151
		INT_TYPE is = DEREF_itype(itype_arith_arg1(it));
1070
	    unsigned ssz = find_itype_size ( is, mbits, sign ) ;
1152
		unsigned ssz = find_itype_size(is, mbits, sign);
1071
	    is = DEREF_itype ( itype_arith_arg2 ( it ) ) ;
1153
		is = DEREF_itype(itype_arith_arg2(it));
1072
	    sz = find_itype_size ( is, mbits, sign ) ;
1154
		sz = find_itype_size(is, mbits, sign);
1073
	    if ( sz < ssz ) sz = ssz ;
1155
		if (sz < ssz) {
-
 
1156
			sz = ssz;
-
 
1157
		}
1074
	    *mbits = basetype_info [ ntype_ellipsis ].max_bits ;
1158
		*mbits = basetype_info[ntype_ellipsis].max_bits;
1075
	    *sign = btype_none ;
1159
		*sign = btype_none;
1076
	    break ;
1160
		break;
1077
	}
1161
	}
1078
	case itype_literal_tag : {
1162
	case itype_literal_tag: {
1079
	    /* Literal types */
1163
		/* Literal types */
1080
	    sz = basetype_info [ ntype_sint ].min_bits ;
1164
		sz = basetype_info[ntype_sint].min_bits;
1081
	    *mbits = basetype_info [ ntype_ellipsis ].max_bits ;
1165
		*mbits = basetype_info[ntype_ellipsis].max_bits;
1082
	    *sign = btype_none ;
1166
		*sign = btype_none;
1083
	    break ;
1167
		break;
1084
	}
1168
	}
1085
	case itype_token_tag : {
1169
	case itype_token_tag: {
1086
	    /* Tokenised types */
1170
		/* Tokenised types */
1087
	    BASE_TYPE bt = btype_none ;
1171
		BASE_TYPE bt = btype_none;
1088
	    IDENTIFIER tid = DEREF_id ( itype_token_tok ( it ) ) ;
1172
		IDENTIFIER tid = DEREF_id(itype_token_tok(it));
1089
	    TOKEN tok = DEREF_tok ( id_token_sort ( tid ) ) ;
1173
		TOKEN tok = DEREF_tok(id_token_sort(tid));
1090
	    if ( IS_tok_proc ( tok ) ) {
1174
		if (IS_tok_proc(tok)) {
1091
		tok = DEREF_tok ( tok_proc_res ( tok ) ) ;
1175
			tok = DEREF_tok(tok_proc_res(tok));
1092
	    }
1176
		}
1093
	    if ( IS_tok_type ( tok ) ) {
1177
		if (IS_tok_type(tok)) {
1094
		bt = DEREF_btype ( tok_type_kind ( tok ) ) ;
1178
			bt = DEREF_btype(tok_type_kind(tok));
1095
		bt = find_itype_sign ( bt ) ;
1179
			bt = find_itype_sign(bt);
1096
	    }
-
 
1097
	    sz = basetype_info [ ntype_ellipsis ].min_bits ;
-
 
1098
	    *mbits = basetype_info [ ntype_ellipsis ].max_bits ;
-
 
1099
	    *sign = bt ;
-
 
1100
	    break ;
-
 
1101
	}
1180
		}
1102
	default : {
-
 
1103
	    /* Other types */
-
 
1104
	    sz = basetype_info [ ntype_ellipsis ].min_bits ;
1181
		sz = basetype_info[ntype_ellipsis].min_bits;
1105
	    *mbits = basetype_info [ ntype_ellipsis ].max_bits ;
1182
		*mbits = basetype_info[ntype_ellipsis].max_bits;
1106
	    *sign = btype_none ;
1183
		*sign = bt;
1107
	    break ;
1184
		break;
1108
	}
1185
	}
-
 
1186
	default:
-
 
1187
		/* Other types */
-
 
1188
		sz = basetype_info[ntype_ellipsis].min_bits;
-
 
1189
		*mbits = basetype_info[ntype_ellipsis].max_bits;
-
 
1190
		*sign = btype_none;
-
 
1191
		break;
1109
    }
1192
	}
1110
    return ( sz ) ;
1193
	return (sz);
1111
}
1194
}
1112
 
1195
 
1113
 
1196
 
1114
/*
1197
/*
1115
    FIND THE SIZE OF A TYPE
1198
    FIND THE SIZE OF A TYPE
1116
 
1199
 
1117
    This routine is identical to find_itype_size except that it works for
1200
    This routine is identical to find_itype_size except that it works for
1118
    all integer, enumeration and bitfield types.
1201
    all integer, enumeration and bitfield types.
1119
*/
1202
*/
1120
 
1203
 
1121
unsigned find_type_size
1204
unsigned
1122
    PROTO_N ( ( t, mbits, sign ) )
-
 
1123
    PROTO_T ( TYPE t X unsigned *mbits X BASE_TYPE *sign )
1205
find_type_size(TYPE t, unsigned *mbits, BASE_TYPE *sign)
1124
{
1206
{
1125
    switch ( TAG_type ( t ) ) {
1207
	switch (TAG_type(t)) {
1126
	case type_integer_tag : {
1208
	case type_integer_tag: {
1127
	    /* Integral types */
1209
		/* Integral types */
1128
	    INT_TYPE it = DEREF_itype ( type_integer_rep ( t ) ) ;
1210
		INT_TYPE it = DEREF_itype(type_integer_rep(t));
1129
	    return ( find_itype_size ( it, mbits, sign ) ) ;
1211
		return (find_itype_size(it, mbits, sign));
1130
	}
1212
	}
1131
	case type_enumerate_tag : {
1213
	case type_enumerate_tag: {
1132
	    /* Enumeration types */
1214
		/* Enumeration types */
1133
	    ENUM_TYPE et = DEREF_etype ( type_enumerate_defn ( t ) ) ;
1215
		ENUM_TYPE et = DEREF_etype(type_enumerate_defn(t));
1134
	    t = DEREF_type ( etype_rep ( et ) ) ;
1216
		t = DEREF_type(etype_rep(et));
1135
	    return ( find_type_size ( t, mbits, sign ) ) ;
1217
		return (find_type_size(t, mbits, sign));
1136
	}
1218
	}
1137
	case type_bitfield_tag : {
1219
	case type_bitfield_tag: {
1138
	    /* Bitfield types */
1220
		/* Bitfield types */
1139
	    INT_TYPE it = DEREF_itype ( type_bitfield_defn ( t ) ) ;
1221
		INT_TYPE it = DEREF_itype(type_bitfield_defn(t));
1140
	    return ( find_itype_size ( it, mbits, sign ) ) ;
1222
		return (find_itype_size(it, mbits, sign));
1141
	}
1223
	}
1142
    }
1224
	}
1143
    *mbits = basetype_info [ ntype_ellipsis ].max_bits ;
1225
	*mbits = basetype_info[ntype_ellipsis].max_bits;
1144
    *sign = btype_none ;
1226
	*sign = btype_none;
1145
    return ( 0 ) ;
1227
	return (0);
1146
}
1228
}
1147
 
1229
 
1148
 
1230
 
1149
/*
1231
/*
1150
    CREATE AN ARITHMETIC INTEGRAL TYPE
1232
    CREATE AN ARITHMETIC INTEGRAL TYPE
Line 1153... Line 1235...
1153
    nu gives the first type (for example, 'unsigned int'), ns gives the
1235
    nu gives the first type (for example, 'unsigned int'), ns gives the
1154
    second type (for example, 'signed long'), and nt gives the default
1236
    second type (for example, 'signed long'), and nt gives the default
1155
    arithmetic type (for example, 'unsigned long').
1237
    arithmetic type (for example, 'unsigned long').
1156
*/
1238
*/
1157
 
1239
 
1158
static INT_TYPE make_arith
1240
static INT_TYPE
1159
    PROTO_N ( ( nu, ns, nt ) )
-
 
1160
    PROTO_T ( BUILTIN_TYPE nu X BUILTIN_TYPE ns X BUILTIN_TYPE nt )
1241
make_arith(BUILTIN_TYPE nu, BUILTIN_TYPE ns, BUILTIN_TYPE nt)
1161
{
1242
{
1162
    INT_TYPE it ;
1243
	INT_TYPE it;
1163
    int c = builtin_cast ( nu, ns ) ;
1244
	int c = builtin_cast(nu, ns);
1164
    if ( c <= min_builtin_cast ) {
1245
	if (c <= min_builtin_cast) {
1165
	/* u definitely fits inside s */
1246
		/* u definitely fits inside s */
1166
	TYPE s = type_builtin [ ns ] ;
1247
		TYPE s = type_builtin[ns];
1167
	it = DEREF_itype ( type_integer_rep ( s ) ) ;
1248
		it = DEREF_itype(type_integer_rep(s));
1168
    } else if ( c <= safe_builtin_cast ) {
1249
	} else if (c <= safe_builtin_cast) {
1169
	/* u possibly fits inside s */
1250
		/* u possibly fits inside s */
1170
	TYPE u = type_builtin [ nu ] ;
1251
		TYPE u = type_builtin[nu];
1171
	TYPE s = type_builtin [ ns ] ;
1252
		TYPE s = type_builtin[ns];
1172
	TYPE t = type_builtin [ nt ] ;
1253
		TYPE t = type_builtin[nt];
1173
	LIST ( TYPE ) pt = NULL_list ( TYPE ) ;
1254
		LIST(TYPE)pt = NULL_list(TYPE);
1174
	INT_TYPE ir = DEREF_itype ( type_integer_rep ( u ) ) ;
1255
		INT_TYPE ir = DEREF_itype(type_integer_rep(u));
1175
	INT_TYPE is = DEREF_itype ( type_integer_rep ( s ) ) ;
1256
		INT_TYPE is = DEREF_itype(type_integer_rep(s));
1176
	CONS_type ( t, pt, pt ) ;
1257
		CONS_type(t, pt, pt);
1177
	CONS_type ( s, pt, pt ) ;
1258
		CONS_type(s, pt, pt);
1178
	pt = uniq_type_set ( pt ) ;
1259
		pt = uniq_type_set(pt);
1179
	MAKE_itype_arith ( NULL_type, pt, ir, is, it ) ;
1260
		MAKE_itype_arith(NULL_type, pt, ir, is, it);
1180
	IGNORE promote_itype ( it, it ) ;
1261
		IGNORE promote_itype(it, it);
1181
    } else {
1262
	} else {
1182
	/* u definitely does not fit inside s */
1263
		/* u definitely does not fit inside s */
1183
	TYPE t = type_builtin [ nt ] ;
1264
		TYPE t = type_builtin[nt];
1184
	it = DEREF_itype ( type_integer_rep ( t ) ) ;
1265
		it = DEREF_itype(type_integer_rep(t));
1185
    }
1266
	}
1186
    return ( it ) ;
1267
	return (it);
1187
}
1268
}
1188
 
1269
 
1189
 
1270
 
1190
/*
1271
/*
1191
    INITIALISE INTEGRAL TYPES
1272
    INITIALISE INTEGRAL TYPES
1192
 
1273
 
1193
    This routine initialises the integral and floating-point types.
1274
    This routine initialises the integral and floating-point types.
1194
*/
1275
*/
1195
 
1276
 
1196
void init_itypes
1277
void
1197
    PROTO_N ( ( init ) )
-
 
1198
    PROTO_T ( int init )
1278
init_itypes(int init)
1199
{
1279
{
1200
    int c ;
1280
	int c;
1201
    INT_TYPE it ;
1281
	INT_TYPE it;
1202
    BUILTIN_TYPE n ;
1282
	BUILTIN_TYPE n;
1203
    LIST ( TYPE ) qt ;
1283
	LIST(TYPE) qt;
1204
    unsigned long i, j ;
1284
	unsigned long i, j;
1205
    BUILTIN_TYPE ntype_max = ntype_ulong ;
1285
	BUILTIN_TYPE ntype_max = ntype_ulong;
1206
 
1286
 
1207
    /* Initialise type tables */
1287
	/* Initialise type tables */
1208
    if ( init ) {
1288
	if (init) {
1209
	for ( i = 0 ; i < ORDER_ntype ; i++ ) {
1289
		for (i = 0; i < ORDER_ntype; i++) {
1210
	    for ( j = 0 ; j < ORDER_ntype ; j++ ) {
1290
			for (j = 0; j < ORDER_ntype; j++) {
1211
		all_itypes [i] [j] = NULL_type ;
1291
				all_itypes[i][j] = NULL_type;
1212
	    }
1292
			}
-
 
1293
		}
1213
	}
1294
	}
1214
    }
-
 
1215
 
1295
 
1216
    /* Initialise all the types */
1296
	/* Initialise all the types */
1217
    for ( n = ntype_none ; n <= ntype_ellipsis ; n++ ) {
1297
	for (n = ntype_none; n <= ntype_ellipsis; n++) {
1218
	TYPE t = NULL_type ;
1298
		TYPE t = NULL_type;
1219
	BUILTIN_TYPE m = n ;
1299
		BUILTIN_TYPE m = n;
1220
	BASE_TYPE rep = basetype_info [n].rep ;
1300
		BASE_TYPE rep = basetype_info[n].rep;
1221
	switch ( n ) {
1301
		switch (n) {
1222
	    case ntype_none : {
1302
		case ntype_none: {
1223
		/* Allow for inferred types */
1303
			/* Allow for inferred types */
1224
		m = ntype_sint ;
1304
			m = ntype_sint;
1225
		goto default_lab ;
1305
			goto default_lab;
1226
	    }
-
 
1227
	    default :
-
 
1228
	    default_lab : {
-
 
1229
		/* Create an integral type */
-
 
1230
		LIST ( TYPE ) pt = NULL_list ( TYPE ) ;
-
 
1231
		MAKE_itype_basic ( t, pt, rep, m, it ) ;
-
 
1232
		if ( init ) {
-
 
1233
		    MAKE_type_integer ( cv_none, it, it, t ) ;
-
 
1234
		    CONS_type ( t, pt, pt ) ;
-
 
1235
		    COPY_list ( itype_cases ( it ), pt ) ;
-
 
1236
		    all_itypes [n] [n] = t ;
-
 
1237
		    type_builtin [n] = t ;
-
 
1238
		} else {
-
 
1239
		    t = type_builtin [n] ;
-
 
1240
		    COPY_itype ( type_integer_rep ( t ), it ) ;
-
 
1241
		    COPY_itype ( type_integer_sem ( t ), it ) ;
-
 
1242
		}
-
 
1243
		break ;
-
 
1244
	    }
-
 
1245
	    case ntype_float :
-
 
1246
	    case ntype_double :
-
 
1247
	    case ntype_ldouble : {
-
 
1248
		/* Create a floating type */
-
 
1249
		FLOAT_TYPE ft ;
-
 
1250
		MAKE_ftype_basic ( NULL_type, rep, n, ft ) ;
-
 
1251
		init_float ( ft ) ;
-
 
1252
		if ( init ) {
-
 
1253
		    MAKE_type_floating ( cv_none, ft, ft, t ) ;
-
 
1254
		    all_itypes [n] [n] = t ;
-
 
1255
		    type_builtin [n] = t ;
-
 
1256
		} else {
-
 
1257
		    t = type_builtin [n] ;
-
 
1258
		    COPY_ftype ( type_floating_rep ( t ), ft ) ;
-
 
1259
		    COPY_ftype ( type_floating_sem ( t ), ft ) ;
-
 
1260
		}
1306
		}
-
 
1307
		default:
-
 
1308
default_lab: {
-
 
1309
		     /* Create an integral type */
-
 
1310
		     LIST(TYPE) pt = NULL_list(TYPE);
-
 
1311
		     MAKE_itype_basic(t, pt, rep, m, it);
-
 
1312
		     if (init) {
-
 
1313
			     MAKE_type_integer(cv_none, it, it, t);
-
 
1314
			     CONS_type(t, pt, pt);
-
 
1315
			     COPY_list(itype_cases(it), pt);
-
 
1316
			     all_itypes[n][n] = t;
-
 
1317
			     type_builtin[n] = t;
-
 
1318
		     } else {
-
 
1319
			     t = type_builtin[n];
-
 
1320
			     COPY_itype(type_integer_rep(t), it);
-
 
1321
			     COPY_itype(type_integer_sem(t), it);
-
 
1322
		     }
1261
		break ;
1323
		     break;
1262
	    }
1324
	     }
-
 
1325
		case ntype_float:
-
 
1326
		case ntype_double:
1263
	    case ntype_void : {
1327
		case ntype_ldouble: {
-
 
1328
			/* Create a floating type */
-
 
1329
			FLOAT_TYPE ft;
-
 
1330
			MAKE_ftype_basic(NULL_type, rep, n, ft);
-
 
1331
			init_float(ft);
1264
		if ( init ) {
1332
			if (init) {
1265
		    MAKE_type_top ( cv_none, t ) ;
1333
				MAKE_type_floating(cv_none, ft, ft, t);
-
 
1334
				all_itypes[n][n] = t;
1266
		    type_builtin [n] = t ;
1335
				type_builtin[n] = t;
-
 
1336
			} else {
-
 
1337
				t = type_builtin[n];
-
 
1338
				COPY_ftype(type_floating_rep(t), ft);
-
 
1339
				COPY_ftype(type_floating_sem(t), ft);
-
 
1340
			}
-
 
1341
			break;
1267
		}
1342
		}
-
 
1343
		case ntype_void:
-
 
1344
			if (init) {
-
 
1345
				MAKE_type_top(cv_none, t);
-
 
1346
				type_builtin[n] = t;
-
 
1347
			}
1268
		break ;
1348
			break;
-
 
1349
		case ntype_bottom:
-
 
1350
			if (init) {
-
 
1351
				MAKE_type_bottom(cv_none, t);
-
 
1352
				type_builtin[n] = t;
1269
	    }
1353
			}
-
 
1354
			break;
1270
	    case ntype_bottom : {
1355
		case ntype_ellipsis:
1271
		if ( init ) {
1356
			if (init) {
1272
		    MAKE_type_bottom ( cv_none, t ) ;
1357
				MAKE_type_pre(cv_none, rep, qual_none, t);
1273
		    type_builtin [n] = t ;
1358
				type_builtin[n] = t;
-
 
1359
			}
-
 
1360
			break;
1274
		}
1361
		}
1275
		break ;
-
 
1276
	    }
-
 
1277
	    case ntype_ellipsis : {
-
 
1278
		if ( init ) {
-
 
1279
		    MAKE_type_pre ( cv_none, rep, qual_none, t ) ;
-
 
1280
		    type_builtin [n] = t ;
-
 
1281
		}
-
 
1282
		break ;
-
 
1283
	    }
-
 
1284
	}
1362
	}
1285
    }
-
 
1286
 
1363
 
1287
    /* Set up list of all integral types */
1364
	/* Set up list of all integral types */
1288
    qt = NULL_list ( TYPE ) ;
1365
	qt = NULL_list(TYPE);
1289
    for ( n = ntype_max ; n >= ntype_char ; n-- ) {
1366
	for (n = ntype_max; n >= ntype_char; n--) {
1290
	CONS_type ( type_builtin [n], qt, qt ) ;
1367
		CONS_type(type_builtin[n], qt, qt);
1291
    }
1368
	}
1292
    all_int_types = uniq_type_set ( qt ) ;
1369
	all_int_types = uniq_type_set(qt);
1293
 
1370
 
1294
    /* Set up list of all promoted types */
1371
	/* Set up list of all promoted types */
1295
    qt = NULL_list ( TYPE ) ;
1372
	qt = NULL_list(TYPE);
1296
    for ( n = ntype_max ; n >= ntype_sint ; n-- ) {
1373
	for (n = ntype_max; n >= ntype_sint; n--) {
1297
	CONS_type ( type_builtin [n], qt, qt ) ;
1374
		CONS_type(type_builtin[n], qt, qt);
1298
    }
1375
	}
1299
    all_prom_types = uniq_type_set ( qt ) ;
1376
	all_prom_types = uniq_type_set(qt);
1300
 
-
 
1301
    /* Set up list of all promoted types (including long long) */
-
 
1302
    qt = NULL_list ( TYPE ) ;
-
 
1303
    for ( n = ntype_ullong ; n >= ntype_sint ; n-- ) {
-
 
1304
	CONS_type ( type_builtin [n], qt, qt ) ;
-
 
1305
    }
-
 
1306
    all_llong_types = uniq_type_set ( qt ) ;
-
 
1307
 
-
 
1308
    /* Set up non-built-in types (also see init_tok) */
-
 
1309
    if ( basetype_info [ ntype_bool ].key ) {
-
 
1310
	base_token [ ntype_bool ].alt = ARITH_bool ;
-
 
1311
    } else {
-
 
1312
	/* 'bool' is equal to 'int' for most purposes */
-
 
1313
	CONST char **nms = ntype_name ; /* SCO cc gets const wrong */
-
 
1314
	it = DEREF_itype ( type_integer_rep ( type_bool ) ) ;
-
 
1315
	qt = NULL_list ( TYPE ) ;
-
 
1316
	CONS_type ( type_sint, qt, qt ) ;
-
 
1317
	COPY_list ( itype_cases ( it ), qt ) ;
-
 
1318
	base_token [ ntype_bool ].alt = ARITH_none ;
-
 
1319
	nms [ ntype_bool ] = nms [ ntype_sint ] ;
-
 
1320
	mangle_ntype [ ntype_bool ] [0] = MANGLE_int ;
-
 
1321
    }
-
 
1322
    if ( basetype_info [ ntype_ptrdiff_t ].key ) {
-
 
1323
	base_token [ ntype_ptrdiff_t ].alt = ARITH_ptrdiff_t ;
-
 
1324
    } else {
-
 
1325
	/* ptrdiff_t will be either 'int' or 'long' */
-
 
1326
	it = DEREF_itype ( type_integer_rep ( type_ptrdiff_t ) ) ;
-
 
1327
	qt = NULL_list ( TYPE ) ;
-
 
1328
	CONS_type ( type_slong, qt, qt ) ;
-
 
1329
	CONS_type ( type_sint, qt, qt ) ;
-
 
1330
	COPY_list ( itype_cases ( it ), qt ) ;
-
 
1331
	base_token [ ntype_ptrdiff_t ].alt = ARITH_none ;
-
 
1332
    }
-
 
1333
    if ( basetype_info [ ntype_size_t ].key ) {
-
 
1334
	base_token [ ntype_size_t ].alt = ARITH_size_t ;
-
 
1335
    } else {
-
 
1336
	/* size_t will be either 'unsigned' or 'unsigned long' */
-
 
1337
	it = DEREF_itype ( type_integer_rep ( type_size_t ) ) ;
-
 
1338
	qt = NULL_list ( TYPE ) ;
-
 
1339
	CONS_type ( type_ulong, qt, qt ) ;
-
 
1340
	CONS_type ( type_uint, qt, qt ) ;
-
 
1341
	COPY_list ( itype_cases ( it ), qt ) ;
-
 
1342
	base_token [ ntype_size_t ].alt = ARITH_none ;
-
 
1343
    }
-
 
1344
    if ( basetype_info [ ntype_wchar_t ].key ) {
-
 
1345
	base_token [ ntype_wchar_t ].alt = ARITH_wchar_t ;
-
 
1346
    } else {
-
 
1347
	/* wchar_t can be any type */
-
 
1348
	it = DEREF_itype ( type_integer_rep ( type_wchar_t ) ) ;
-
 
1349
	qt = all_int_types ;
-
 
1350
	COPY_list ( itype_cases ( it ), qt ) ;
-
 
1351
	base_token [ ntype_wchar_t ].alt = ARITH_none ;
-
 
1352
    }
-
 
1353
 
1377
 
1354
    /* Calculate all promotion types */
1378
	/* Set up list of all promoted types (including long long) */
1355
    for ( i = 0 ; i < ORDER_ntype ; i++ ) {
1379
	qt = NULL_list(TYPE);
1356
	TYPE t = type_builtin [i] ;
1380
	for (n = ntype_ullong; n >= ntype_sint; n--) {
1357
	if ( !IS_NULL_type ( t ) ) {
1381
		CONS_type(type_builtin[n], qt, qt);
-
 
1382
	}
1358
	    switch ( TAG_type ( t ) ) {
1383
	all_llong_types = uniq_type_set(qt);
1359
 
1384
 
-
 
1385
	/* Set up non-built-in types (also see init_tok) */
1360
		case type_integer_tag : {
1386
	if (basetype_info[ntype_bool].key) {
-
 
1387
		base_token[ntype_bool].alt = ARITH_bool;
-
 
1388
	} else {
1361
		    /* Calculate promotion for integral type */
1389
		/* 'bool' is equal to 'int' for most purposes */
-
 
1390
		CONST char **nms = ntype_name ; /* SCO cc gets const wrong */
-
 
1391
		it = DEREF_itype(type_integer_rep(type_bool));
1362
		    INT_TYPE ip ;
1392
		qt = NULL_list(TYPE);
-
 
1393
		CONS_type(type_sint, qt, qt);
-
 
1394
		COPY_list(itype_cases(it), qt);
-
 
1395
		base_token[ntype_bool].alt = ARITH_none;
-
 
1396
		nms[ntype_bool] = nms[ntype_sint];
-
 
1397
		mangle_ntype[ntype_bool][0] = MANGLE_int;
-
 
1398
	}
-
 
1399
	if (basetype_info[ntype_ptrdiff_t].key) {
-
 
1400
		base_token[ntype_ptrdiff_t].alt = ARITH_ptrdiff_t;
-
 
1401
	} else {
-
 
1402
		/* ptrdiff_t will be either 'int' or 'long' */
-
 
1403
		it = DEREF_itype(type_integer_rep(type_ptrdiff_t));
1363
		    BUILTIN_TYPE m ;
1404
		qt = NULL_list(TYPE);
-
 
1405
		CONS_type(type_slong, qt, qt);
1364
		    TYPE p = NULL_type ;
1406
		CONS_type(type_sint, qt, qt);
-
 
1407
		COPY_list(itype_cases(it), qt);
-
 
1408
		base_token[ntype_ptrdiff_t].alt = ARITH_none;
-
 
1409
	}
-
 
1410
	if (basetype_info[ntype_size_t].key) {
-
 
1411
		base_token[ntype_size_t].alt = ARITH_size_t;
-
 
1412
	} else {
-
 
1413
		/* size_t will be either 'unsigned' or 'unsigned long' */
-
 
1414
		it = DEREF_itype(type_integer_rep(type_size_t));
1365
		    LIST ( TYPE ) pt = NULL_list ( TYPE ) ;
1415
		qt = NULL_list(TYPE);
-
 
1416
		CONS_type(type_ulong, qt, qt);
-
 
1417
		CONS_type(type_uint, qt, qt);
-
 
1418
		COPY_list(itype_cases(it), qt);
-
 
1419
		base_token[ntype_size_t].alt = ARITH_none;
-
 
1420
	}
-
 
1421
	if (basetype_info[ntype_wchar_t].key) {
-
 
1422
		base_token[ntype_wchar_t].alt = ARITH_wchar_t;
-
 
1423
	} else {
-
 
1424
		/* wchar_t can be any type */
1366
		    it = DEREF_itype ( type_integer_rep ( t ) ) ;
1425
		it = DEREF_itype(type_integer_rep(type_wchar_t));
-
 
1426
		qt = all_int_types;
1367
		    n = DEREF_ntype ( itype_basic_no ( it ) ) ;
1427
		COPY_list(itype_cases(it), qt);
-
 
1428
		base_token[ntype_wchar_t].alt = ARITH_none;
-
 
1429
	}
1368
 
1430
 
1369
		    /* int, unsigned etc. promote to themselves */
1431
	/* Calculate all promotion types */
1370
		    if ( n >= ntype_sint && n <= ntype_ullong ) {
1432
	for (i = 0; i < ORDER_ntype; i++) {
-
 
1433
		TYPE t = type_builtin[i];
1371
			if ( do_dump && i ) dump_promote ( it, it ) ;
1434
		if (!IS_NULL_type(t)) {
1372
			COPY_type ( itype_prom ( it ), t ) ;
1435
			switch (TAG_type(t)) {
1373
			COPY_ntype ( itype_unprom ( it ), n ) ;
1436
			case type_integer_tag: {
-
 
1437
				/* Calculate promotion for integral type */
1374
			break ;
1438
				INT_TYPE ip;
-
 
1439
				BUILTIN_TYPE m;
1375
		    }
1440
				TYPE p = NULL_type;
-
 
1441
				LIST(TYPE)pt = NULL_list(TYPE);
-
 
1442
				it = DEREF_itype(type_integer_rep(t));
-
 
1443
				n = DEREF_ntype(itype_basic_no(it));
1376
 
1444
 
1377
		    /* ptrdiff_t and size_t promote to themselves */
1445
				/* int, unsigned etc. promote to themselves */
1378
		    if ( n == ntype_ptrdiff_t || n == ntype_size_t ) {
1446
				if (n >= ntype_sint && n <= ntype_ullong) {
-
 
1447
					if (do_dump && i) {
1379
			if ( do_dump ) dump_promote ( it, it ) ;
1448
						dump_promote(it, it);
-
 
1449
					}
1380
			COPY_type ( itype_prom ( it ), t ) ;
1450
					COPY_type(itype_prom(it), t);
-
 
1451
					COPY_ntype(itype_unprom(it), n);
1381
			break ;
1452
					break;
1382
		    }
1453
				}
1383
 
1454
 
1384
		    /* Construct promotion type for wchar_t */
1455
				/* ptrdiff_t and size_t promote to themselves */
1385
		    if ( n == ntype_wchar_t ) {
1456
				if (n == ntype_ptrdiff_t || n == ntype_size_t) {
-
 
1457
					if (do_dump) {
1386
			IGNORE promote_itype ( it, NULL_itype ) ;
1458
						dump_promote(it, it);
-
 
1459
					}
-
 
1460
					COPY_type(itype_prom(it), t);
1387
			break ;
1461
					break;
1388
		    }
1462
				}
1389
 
1463
 
1390
		    /* Find promotion type */
-
 
1391
		    for ( m = ntype_sint ; m <= ntype_ulong ; m++ ) {
-
 
1392
			c = builtin_cast ( n, m ) ;
-
 
1393
			if ( c <= safe_builtin_cast ) {
-
 
1394
			    /* Possibly fits */
-
 
1395
			    p = type_builtin [m] ;
-
 
1396
			    CONS_type ( p, pt, pt ) ;
-
 
1397
			}
-
 
1398
			if ( c <= min_builtin_cast ) {
-
 
1399
			    /* Definitely fits */
-
 
1400
			    break ;
-
 
1401
			}
-
 
1402
		    }
-
 
1403
		    if ( LENGTH_list ( pt ) == 1 ) {
-
 
1404
			/* Unique promotion type */
-
 
1405
			p = DEREF_type ( HEAD_list ( pt ) ) ;
-
 
1406
			ip = DEREF_itype ( type_integer_rep ( p ) ) ;
-
 
1407
			p = make_itype ( ip, it ) ;
-
 
1408
			DESTROY_list ( pt, SIZE_type ) ;
-
 
1409
			if ( do_dump ) dump_promote ( it, ip ) ;
-
 
1410
		    } else {
-
 
1411
			/* Construct promotion type */
1464
				/* Construct promotion type for wchar_t */
1412
			pt = REVERSE_list ( pt ) ;
-
 
1413
			pt = uniq_type_set ( pt ) ;
1465
				if (n == ntype_wchar_t) {
1414
			MAKE_itype_promote ( p, pt, it, ip ) ;
1466
					IGNORE promote_itype(it, NULL_itype);
1415
			p = make_itype ( ip, it ) ;
-
 
1416
			COPY_type ( itype_prom ( ip ), p ) ;
-
 
1417
		    }
-
 
1418
		    COPY_type ( itype_prom ( it ), p ) ;
-
 
1419
		    break ;
1467
					break;
1420
		}
1468
				}
1421
 
1469
 
-
 
1470
				/* Find promotion type */
-
 
1471
				for (m = ntype_sint; m <= ntype_ulong; m++) {
-
 
1472
					c = builtin_cast(n, m);
-
 
1473
					if (c <= safe_builtin_cast) {
-
 
1474
						/* Possibly fits */
-
 
1475
						p = type_builtin[m];
-
 
1476
						CONS_type(p, pt, pt);
-
 
1477
					}
-
 
1478
					if (c <= min_builtin_cast) {
-
 
1479
						/* Definitely fits */
-
 
1480
						break;
-
 
1481
					}
-
 
1482
				}
-
 
1483
				if (LENGTH_list(pt) == 1) {
-
 
1484
					/* Unique promotion type */
-
 
1485
					p = DEREF_type(HEAD_list(pt));
-
 
1486
					ip = DEREF_itype(type_integer_rep(p));
-
 
1487
					p = make_itype(ip, it);
-
 
1488
					DESTROY_list(pt, SIZE_type);
-
 
1489
					if (do_dump) {
-
 
1490
						dump_promote(it, ip);
-
 
1491
					}
-
 
1492
				} else {
-
 
1493
					/* Construct promotion type */
-
 
1494
					pt = REVERSE_list(pt);
-
 
1495
					pt = uniq_type_set(pt);
-
 
1496
					MAKE_itype_promote(p, pt, it, ip);
-
 
1497
					p = make_itype(ip, it);
-
 
1498
					COPY_type(itype_prom(ip), p);
-
 
1499
				}
-
 
1500
				COPY_type(itype_prom(it), p);
-
 
1501
				break;
-
 
1502
			}
-
 
1503
 
1422
		case type_floating_tag : {
1504
			case type_floating_tag: {
1423
		    /* Calculate promotion for floating-point type */
1505
				/* Calculate promotion for floating-point
-
 
1506
				 * type */
1424
		    FLOAT_TYPE ft ;
1507
				FLOAT_TYPE ft;
1425
		    ft = DEREF_ftype ( type_floating_rep ( t ) ) ;
1508
				ft = DEREF_ftype(type_floating_rep(t));
1426
		    n = DEREF_ntype ( ftype_basic_no ( ft ) ) ;
1509
				n = DEREF_ntype(ftype_basic_no(ft));
1427
		    if ( n == ntype_float ) {
1510
				if (n == ntype_float) {
1428
			FLOAT_TYPE fp ;
1511
					FLOAT_TYPE fp;
1429
			TYPE p = type_double ;
1512
					TYPE p = type_double;
1430
			fp = DEREF_ftype ( type_floating_rep ( p ) ) ;
1513
					fp = DEREF_ftype(type_floating_rep(p));
1431
			p = make_ftype ( fp, ft ) ;
1514
					p = make_ftype(fp, ft);
1432
			COPY_type ( ftype_arg_prom ( ft ), p ) ;
1515
					COPY_type(ftype_arg_prom(ft), p);
1433
		    } else {
1516
				} else {
1434
			COPY_type ( ftype_arg_prom ( ft ), t ) ;
1517
					COPY_type(ftype_arg_prom(ft), t);
1435
		    }
1518
				}
1436
		    break ;
1519
				break;
-
 
1520
			}
-
 
1521
			}
1437
		}
1522
		}
1438
	    }
-
 
1439
	}
1523
	}
1440
    }
-
 
1441
 
1524
 
1442
    /* Calculate the arithmetic types */
1525
	/* Calculate the arithmetic types */
1443
    it = make_arith ( ntype_uint, ntype_slong, ntype_ulong ) ;
1526
	it = make_arith(ntype_uint, ntype_slong, ntype_ulong);
1444
    arith_slong_uint = it ;
1527
	arith_slong_uint = it;
1445
    it = make_arith ( ntype_uint, ntype_sllong, ntype_ullong ) ;
1528
	it = make_arith(ntype_uint, ntype_sllong, ntype_ullong);
1446
    arith_sllong_uint = it ;
1529
	arith_sllong_uint = it;
1447
    it = make_arith ( ntype_ulong, ntype_sllong, ntype_ullong ) ;
1530
	it = make_arith(ntype_ulong, ntype_sllong, ntype_ullong);
1448
    arith_sllong_ulong = it ;
1531
	arith_sllong_ulong = it;
1449
    return ;
1532
	return;
1450
}
1533
}