Warning: Undefined variable $n in /usr/local/www/websvn.planix.org/include/diff_util.php on line 243

Warning: Undefined variable $n in /usr/local/www/websvn.planix.org/include/diff_util.php on line 247

Warning: Undefined variable $m in /usr/local/www/websvn.planix.org/include/diff_util.php on line 251

Warning: Undefined variable $n in /usr/local/www/websvn.planix.org/include/diff_util.php on line 243

Warning: Undefined variable $n in /usr/local/www/websvn.planix.org/include/diff_util.php on line 247

Warning: Undefined variable $m in /usr/local/www/websvn.planix.org/include/diff_util.php on line 251

Warning: Undefined variable $n in /usr/local/www/websvn.planix.org/include/diff_util.php on line 243

Warning: Undefined variable $n in /usr/local/www/websvn.planix.org/include/diff_util.php on line 247

Warning: Undefined variable $m in /usr/local/www/websvn.planix.org/include/diff_util.php on line 251

Warning: Undefined variable $n in /usr/local/www/websvn.planix.org/include/diff_util.php on line 243

Warning: Undefined variable $n in /usr/local/www/websvn.planix.org/include/diff_util.php on line 247

Warning: Undefined variable $m in /usr/local/www/websvn.planix.org/include/diff_util.php on line 251

Warning: Undefined variable $n in /usr/local/www/websvn.planix.org/include/diff_util.php on line 243

Warning: Undefined variable $n in /usr/local/www/websvn.planix.org/include/diff_util.php on line 247

Warning: Undefined variable $m in /usr/local/www/websvn.planix.org/include/diff_util.php on line 251
WebSVN – tendra.SVN – Diff – /trunk/src/producers/common/construct/expression.c – Rev 2 and 7

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 68... Line 98...
68
 
98
 
69
    This routine creates an error expression.  The result is an lvalue
99
    This routine creates an error expression.  The result is an lvalue
70
    if lv is true.
100
    if lv is true.
71
*/
101
*/
72
 
102
 
73
EXP make_error_exp
103
EXP
74
    PROTO_N ( ( lv ) )
-
 
75
    PROTO_T ( int lv )
104
make_error_exp(int lv)
76
{
105
{
77
    EXP a ;
106
	EXP a;
78
    TYPE t = type_error ;
107
	TYPE t = type_error;
-
 
108
	if (lv) {
79
    if ( lv ) t = lvalue_type ( t ) ;
109
		t = lvalue_type(t);
-
 
110
	}
80
    MAKE_exp_value ( t, a ) ;
111
	MAKE_exp_value(t, a);
81
    return ( a ) ;
112
	return (a);
82
}
113
}
83
 
114
 
84
 
115
 
85
/*
116
/*
86
    CONSTRUCT A NULL POINTER CONSTANT
117
    CONSTRUCT A NULL POINTER CONSTANT
Line 91... Line 122...
91
    anything other than a plain literal '0' for the null pointer (for
122
    anything other than a plain literal '0' for the null pointer (for
92
    example '1 - 1') is considered bad practice, so there is a test
123
    example '1 - 1') is considered bad practice, so there is a test
93
    for this.  The null expression is returns if a is non-zero.
124
    for this.  The null expression is returns if a is non-zero.
94
*/
125
*/
95
 
126
 
96
EXP make_null_ptr
127
EXP
97
    PROTO_N ( ( a, t ) )
-
 
98
    PROTO_T ( EXP a X TYPE t )
128
make_null_ptr(EXP a, TYPE t)
99
{
129
{
100
    EXP e = NULL_exp ;
130
	EXP e = NULL_exp;
101
    if ( IS_NULL_exp ( a ) ) {
131
	if (IS_NULL_exp(a)) {
102
	/* Allow null expressions */
132
		/* Allow null expressions */
103
	MAKE_exp_null ( t, e ) ;
133
		MAKE_exp_null(t, e);
104
    } else {
-
 
105
	if ( is_zero_exp ( a ) ) {
-
 
106
	    if ( !is_literal ( a ) ) {
-
 
107
		/* Report complex literals */
-
 
108
		report ( crt_loc, ERR_conv_ptr_null_complex () ) ;
-
 
109
	    }
-
 
110
	    MAKE_exp_null ( t, e ) ;
-
 
111
	} else {
134
	} else {
-
 
135
		if (is_zero_exp(a)) {
-
 
136
			if (!is_literal(a)) {
-
 
137
				/* Report complex literals */
-
 
138
				report(crt_loc, ERR_conv_ptr_null_complex());
-
 
139
			}
-
 
140
			MAKE_exp_null(t, e);
-
 
141
		} else {
112
	    if ( in_template_decl && IS_exp_int_lit ( a ) ) {
142
			if (in_template_decl && IS_exp_int_lit(a)) {
113
		if ( depends_on_exp ( a, any_templ_param, 0 ) ) {
143
				if (depends_on_exp(a, any_templ_param, 0)) {
114
		    /* Check for template parameters */
144
					/* Check for template parameters */
-
 
145
					report(crt_loc,
115
		    report ( crt_loc, ERR_conv_ptr_null_complex () ) ;
146
					       ERR_conv_ptr_null_complex());
116
		    MAKE_exp_op ( t, lex_pointer, a, NULL_exp, e ) ;
147
					MAKE_exp_op(t, lex_pointer, a,
-
 
148
						    NULL_exp, e);
-
 
149
				}
-
 
150
			}
117
		}
151
		}
118
	    }
-
 
119
	}
152
	}
120
    }
-
 
121
    return ( e ) ;
153
	return (e);
122
}
154
}
123
 
155
 
124
 
156
 
125
/*
157
/*
126
    CONSTRUCT A PARENTHESISED EXPRESSION
158
    CONSTRUCT A PARENTHESISED EXPRESSION
127
 
159
 
128
    This routine constructs the expression '( a )'.  Note that parentheses
160
    This routine constructs the expression '( a )'.  Note that parentheses
129
    are only needed in order to perform analysis for odd precedence in
161
    are only needed in order to perform analysis for odd precedence in
130
    expressions.  It is otherwise just an identity operation.
162
    expressions.  It is otherwise just an identity operation.
131
*/
163
*/
132
 
164
 
133
EXP make_paren_exp
165
EXP
134
    PROTO_N ( ( a ) )
-
 
135
    PROTO_T ( EXP a )
166
make_paren_exp(EXP a)
136
{
167
{
137
    EXP e ;
168
	EXP e;
138
    TYPE ta = DEREF_type ( exp_type ( a ) ) ;
169
	TYPE ta = DEREF_type(exp_type(a));
139
    if ( IS_exp_int_lit ( a ) ) {
170
	if (IS_exp_int_lit(a)) {
140
	/* Deal with integer constant expressions */
171
		/* Deal with integer constant expressions */
141
	unsigned etag = DEREF_unsigned ( exp_int_lit_etag ( a ) ) ;
172
		unsigned etag = DEREF_unsigned(exp_int_lit_etag(a));
142
	switch ( etag ) {
173
		switch (etag) {
143
	    case exp_int_lit_tag :
174
		case exp_int_lit_tag:
144
	    case exp_null_tag :
175
		case exp_null_tag:
145
	    case exp_identifier_tag : {
176
		case exp_identifier_tag: {
146
		/* Don't bother with literals and enumerators */
177
			/* Don't bother with literals and enumerators */
147
		e = a ;
178
			e = a;
148
		break ;
179
			break;
149
	    }
180
		}
150
	    default : {
181
		default: {
151
		/* Mark other values as parenthesised */
182
			/* Mark other values as parenthesised */
152
		NAT n = DEREF_nat ( exp_int_lit_nat ( a ) ) ;
183
			NAT n = DEREF_nat(exp_int_lit_nat(a));
153
		MAKE_exp_int_lit ( ta, n, exp_paren_tag, e ) ;
184
			MAKE_exp_int_lit(ta, n, exp_paren_tag, e);
154
		break ;
185
			break;
155
	    }
186
		}
156
	}
187
		}
157
    } else {
188
	} else {
158
	MAKE_exp_paren ( ta, a, e ) ;
189
		MAKE_exp_paren(ta, a, e);
159
    }
190
	}
160
    return ( e ) ;
191
	return (e);
161
}
192
}
162
 
193
 
163
 
194
 
164
/*
195
/*
165
    CONSTRUCT A TYPE OFFSET
196
    CONSTRUCT A TYPE OFFSET
166
 
197
 
167
    This routine constructs an offset of a times the offset of the type t.
198
    This routine constructs an offset of a times the offset of the type t.
168
    This is negated if neg is true.
199
    This is negated if neg is true.
169
*/
200
*/
170
 
201
 
171
OFFSET make_off_mult
202
OFFSET
172
    PROTO_N ( ( t, a, neg ) )
-
 
173
    PROTO_T ( TYPE t X EXP a X int neg )
203
make_off_mult(TYPE t, EXP a, int neg)
174
{
204
{
175
    OFFSET off ;
205
	OFFSET off;
176
    if ( IS_type_top_etc ( t ) ) {
206
	if (IS_type_top_etc(t)) {
177
	/* Map 'void *' to 'char *' */
207
		/* Map 'void *' to 'char *' */
178
	t = type_char ;
208
		t = type_char;
179
    }
209
	}
180
    if ( IS_exp_int_lit ( a ) ) {
210
	if (IS_exp_int_lit(a)) {
181
	/* Constant offsets */
211
		/* Constant offsets */
182
	int neg1 = neg ;
212
		int neg1 = neg;
183
	NAT n = DEREF_nat ( exp_int_lit_nat ( a ) ) ;
213
		NAT n = DEREF_nat(exp_int_lit_nat(a));
184
	if ( IS_nat_neg ( n ) ) {
214
		if (IS_nat_neg(n)) {
185
	    n = DEREF_nat ( nat_neg_arg ( n ) ) ;
215
			n = DEREF_nat(nat_neg_arg(n));
186
	    neg1 = !neg1 ;
216
			neg1 = !neg1;
187
	}
217
		}
188
	if ( IS_nat_small ( n ) ) {
218
		if (IS_nat_small(n)) {
189
	    unsigned v = DEREF_unsigned ( nat_small_value ( n ) ) ;
219
			unsigned v = DEREF_unsigned(nat_small_value(n));
190
	    if ( v < 100 ) {
220
			if (v < 100) {
191
		if ( v == 0 ) {
221
				if (v == 0) {
192
		    MAKE_off_zero ( t, off ) ;
222
					MAKE_off_zero(t, off);
193
		} else if ( v == 1 ) {
223
				} else if (v == 1) {
194
		    MAKE_off_type ( t, off ) ;
224
					MAKE_off_type(t, off);
195
		} else {
225
				} else {
196
		    MAKE_type_array ( cv_none, t, n, t ) ;
226
					MAKE_type_array(cv_none, t, n, t);
197
		    MAKE_off_type ( t, off ) ;
227
					MAKE_off_type(t, off);
198
		}
228
				}
-
 
229
				if (neg1) {
199
		if ( neg1 ) MAKE_off_negate ( off, off ) ;
230
					MAKE_off_negate(off, off);
-
 
231
				}
200
		return ( off ) ;
232
				return (off);
201
	    }
233
			}
-
 
234
		}
-
 
235
	}
-
 
236
	MAKE_off_type(t, off);
-
 
237
	MAKE_off_mult(off, a, off);
-
 
238
	if (neg) {
-
 
239
		MAKE_off_negate(off, off);
202
	}
240
	}
203
    }
-
 
204
    MAKE_off_type ( t, off ) ;
-
 
205
    MAKE_off_mult ( off, a, off ) ;
-
 
206
    if ( neg ) MAKE_off_negate ( off, off ) ;
-
 
207
    return ( off ) ;
241
	return (off);
208
}
242
}
209
 
243
 
210
 
244
 
211
/*
245
/*
212
    CREATE AN ADD-TO-POINTER EXPRESSION
246
    CREATE AN ADD-TO-POINTER EXPRESSION
213
 
247
 
214
    This routine creates a pointer of type t by adding the offset off to
248
    This routine creates a pointer of type t by adding the offset off to
215
    the pointer expression a.  For pointers of type 'void *' conversions
249
    the pointer expression a.  For pointers of type 'void *' conversions
216
    are performed to and from 'char *'.
250
    are performed to and from 'char *'.
217
*/
251
*/
218
 
252
 
219
EXP make_add_ptr
253
EXP
220
    PROTO_N ( ( t, a, off ) )
-
 
221
    PROTO_T ( TYPE t X EXP a X OFFSET off )
254
make_add_ptr(TYPE t, EXP a, OFFSET off)
222
{
255
{
223
    EXP e ;
256
	EXP e;
224
    if ( IS_type_ptr ( t ) ) {
257
	if (IS_type_ptr(t)) {
225
	TYPE s = DEREF_type ( type_ptr_sub ( t ) ) ;
258
		TYPE s = DEREF_type(type_ptr_sub(t));
226
	if ( IS_type_top_etc ( s ) ) {
259
		if (IS_type_top_etc(s)) {
227
	    TYPE p = type_char_star ;
260
			TYPE p = type_char_star;
228
	    MAKE_exp_cast ( p, ( CONV_PTR_VOID | CONV_REVERSE ), a, e ) ;
261
			MAKE_exp_cast(p,(CONV_PTR_VOID | CONV_REVERSE), a, e);
229
	    e = make_add_ptr ( p, e, off ) ;
262
			e = make_add_ptr(p, e, off);
230
	    MAKE_exp_cast ( t, CONV_PTR_VOID, e, e ) ;
263
			MAKE_exp_cast(t, CONV_PTR_VOID, e, e);
231
	    return ( e ) ;
264
			return (e);
-
 
265
		}
232
	}
266
	}
233
    }
-
 
234
    MAKE_exp_add_ptr ( t, a, off, 0, e ) ;
267
	MAKE_exp_add_ptr(t, a, off, 0, e);
235
    return ( e ) ;
268
	return (e);
236
}
269
}
237
 
270
 
238
 
271
 
239
/*
272
/*
240
    CONSTRUCT AN INDEX EXPRESSION
273
    CONSTRUCT AN INDEX EXPRESSION
Line 244... Line 277...
244
    an integer constant then bounds checks are applied to the operation.
277
    an integer constant then bounds checks are applied to the operation.
245
    However once an array has been converted into a pointer any associated
278
    However once an array has been converted into a pointer any associated
246
    bounds information is lost.
279
    bounds information is lost.
247
*/
280
*/
248
 
281
 
249
EXP make_index_exp
282
EXP
250
    PROTO_N ( ( a, b ) )
-
 
251
    PROTO_T ( EXP a X EXP b )
283
make_index_exp(EXP a, EXP b)
252
{
284
{
253
    TYPE t ;
285
	TYPE t;
254
    EXP e, p ;
286
	EXP e, p;
255
    int z = 0 ;
287
	int z = 0;
256
    OFFSET off ;
288
	OFFSET off;
257
    TYPE ta, tb ;
289
	TYPE ta, tb;
258
    unsigned ca, cb ;
290
	unsigned ca, cb;
259
    ERROR err = NULL_err ;
291
	ERROR err = NULL_err;
260
    TYPE sa = DEREF_type ( exp_type ( a ) ) ;
292
	TYPE sa = DEREF_type(exp_type(a));
261
    TYPE sb = DEREF_type ( exp_type ( b ) ) ;
293
	TYPE sb = DEREF_type(exp_type(b));
262
 
294
 
263
    /* Do reference conversions */
295
	/* Do reference conversions */
264
    a = convert_reference ( a, REF_NORMAL ) ;
296
	a = convert_reference(a, REF_NORMAL);
265
    b = convert_reference ( b, REF_NORMAL ) ;
297
	b = convert_reference(b, REF_NORMAL);
266
 
298
 
267
    /* Find the operand types */
299
	/* Find the operand types */
268
    ta = DEREF_type ( exp_type ( a ) ) ;
300
	ta = DEREF_type(exp_type(a));
269
    ca = type_category ( &ta ) ;
301
	ca = type_category(&ta);
270
    tb = DEREF_type ( exp_type ( b ) ) ;
302
	tb = DEREF_type(exp_type(b));
271
    cb = type_category ( &tb ) ;
303
	cb = type_category(&tb);
272
 
304
 
273
    /* Check for overloading */
305
	/* Check for overloading */
274
#if LANGUAGE_CPP
306
#if LANGUAGE_CPP
275
    if ( IS_TYPE_OVERLOAD ( ca ) || IS_TYPE_OVERLOAD ( cb ) ) {
307
	if (IS_TYPE_OVERLOAD(ca) || IS_TYPE_OVERLOAD(cb)) {
276
	if ( overload_depth == 0 ) {
308
		if (overload_depth == 0) {
277
	    e = binary_overload ( lex_array_Hop, a, b ) ;
309
			e = binary_overload(lex_array_Hop, a, b);
278
	    return ( e ) ;
310
			return (e);
279
	}
-
 
280
    }
-
 
281
#endif
-
 
282
 
-
 
283
    /* Do lvalue conversions */
-
 
284
    if ( IS_TYPE_ADDRESS ( ca ) ) {
-
 
285
	a = convert_lvalue ( a ) ;
-
 
286
	ta = DEREF_type ( exp_type ( a ) ) ;
-
 
287
	ca = type_category ( &ta ) ;
-
 
288
    }
-
 
289
    if ( IS_TYPE_ADDRESS ( cb ) ) {
-
 
290
	b = convert_lvalue ( b ) ;
-
 
291
	tb = DEREF_type ( exp_type ( b ) ) ;
-
 
292
	cb = type_category ( &tb ) ;
-
 
293
    }
-
 
294
 
-
 
295
    /* Swap operands if the second is a pointer */
-
 
296
    if ( IS_TYPE_PTR ( cb ) ) {
-
 
297
	/* Alright because order of evaluation is undefined */
-
 
298
	EXP c = a ;
-
 
299
	TYPE tc = ta ;
-
 
300
	unsigned cc = ca ;
-
 
301
	a = b ;
-
 
302
	b = c ;
-
 
303
	ta = tb ;
-
 
304
	tb = tc ;
-
 
305
	ca = cb ;
-
 
306
	cb = cc ;
-
 
307
	sa = sb ;
-
 
308
    }
-
 
309
 
-
 
310
    /* The first operand should now be a pointer */
-
 
311
    if ( !IS_TYPE_PTR ( ca ) ) {
-
 
312
	if ( !IS_TYPE_ERROR ( ca ) && !IS_TYPE_ERROR ( cb ) ) {
-
 
313
	    report ( crt_loc, ERR_expr_sub_ptr_op ( ta, tb ) ) ;
-
 
314
	}
-
 
315
	return ( make_error_exp ( 0 ) ) ;
-
 
316
    }
-
 
317
 
-
 
318
    /* The second operand should be integral */
-
 
319
    if ( !IS_TYPE_INT ( cb ) ) {
-
 
320
	if ( !IS_TYPE_ERROR ( cb ) ) {
-
 
321
	    report ( crt_loc, ERR_expr_sub_int_op ( tb ) ) ;
-
 
322
	}
-
 
323
	/* Continue with zero index */
-
 
324
	z = 1 ;
-
 
325
    }
-
 
326
 
-
 
327
    /* Check index value */
-
 
328
    if ( IS_exp_int_lit ( b ) ) {
-
 
329
	if ( IS_type_array ( sa ) ) {
-
 
330
	    check_bounds ( lex_array_Hop, sa, b ) ;
-
 
331
	}
311
		}
332
	z = is_zero_exp ( b ) ;
-
 
333
    } else {
-
 
334
	if ( eq_type_unqual ( tb, type_char ) ) {
-
 
335
	    report ( crt_loc, ERR_expr_sub_char_op ( tb ) ) ;
-
 
336
	}
312
	}
337
    }
-
 
338
 
-
 
339
    /* The pointer must be to a complete object type */
-
 
340
    t = check_pointer ( ta, &err ) ;
-
 
341
    if ( !IS_NULL_err ( err ) ) {
-
 
342
	err = concat_error ( err, ERR_expr_sub_incompl () ) ;
-
 
343
	report ( crt_loc, err ) ;
-
 
344
    }
-
 
345
 
-
 
346
    /* Construct pointer to the result */
-
 
347
    if ( z ) {
-
 
348
	/* Zero offset */
-
 
349
	p = a ;
-
 
350
    } else {
-
 
351
	/* Non-zero offset */
-
 
352
	if ( IS_TYPE_BITF ( cb ) ) b = convert_bitfield ( b ) ;
-
 
353
	off = make_off_mult ( t, b, 0 ) ;
-
 
354
	p = make_add_ptr ( ta, a, off ) ;
-
 
355
    }
-
 
356
 
-
 
357
    /* The result is an lvalue */
-
 
358
    t = lvalue_type ( t ) ;
-
 
359
 
-
 
360
    /* Construct the result */
-
 
361
    MAKE_exp_indir ( t, p, e ) ;
-
 
362
    COPY_int ( exp_indir_index ( e ), 1 ) ;
-
 
363
    return ( e ) ;
-
 
364
}
-
 
365
 
-
 
366
 
-
 
367
/*
-
 
368
    CONSTRUCT A INDIRECTION EXPRESSION
-
 
369
 
-
 
370
    This routine constructs the indirection expression '*a'.  The result
-
 
371
    is an lvalue.
-
 
372
*/
-
 
373
 
-
 
374
EXP make_indir_exp
-
 
375
    PROTO_N ( ( a ) )
-
 
376
    PROTO_T ( EXP a )
-
 
377
{
-
 
378
    EXP e ;
-
 
379
    TYPE ta ;
-
 
380
    unsigned ca ;
-
 
381
 
-
 
382
    /* Do reference conversion */
-
 
383
    a = convert_reference ( a, REF_NORMAL ) ;
-
 
384
 
-
 
385
    /* Find operand type */
-
 
386
    ta = DEREF_type ( exp_type ( a ) ) ;
-
 
387
    ca = type_category ( &ta ) ;
-
 
388
 
-
 
389
    /* Check for overloading */
-
 
390
#if LANGUAGE_CPP
-
 
391
    if ( IS_TYPE_OVERLOAD ( ca ) ) {
-
 
392
	if ( overload_depth == 0 ) {
-
 
393
	    e = unary_overload ( lex_star, a ) ;
-
 
394
	    return ( e ) ;
-
 
395
	}
-
 
396
    }
-
 
397
#endif
313
#endif
398
 
314
 
399
    /* Do lvalue conversion */
315
	/* Do lvalue conversions */
400
    if ( IS_TYPE_ADDRESS ( ca ) ) {
316
	if (IS_TYPE_ADDRESS(ca)) {
401
	a = convert_lvalue ( a ) ;
317
		a = convert_lvalue(a);
402
	ta = DEREF_type ( exp_type ( a ) ) ;
318
		ta = DEREF_type(exp_type(a));
403
	ca = type_category ( &ta ) ;
319
		ca = type_category(&ta);
-
 
320
	}
-
 
321
	if (IS_TYPE_ADDRESS(cb)) {
-
 
322
		b = convert_lvalue(b);
-
 
323
		tb = DEREF_type(exp_type(b));
-
 
324
		cb = type_category(&tb);
-
 
325
	}
-
 
326
 
-
 
327
	/* Swap operands if the second is a pointer */
-
 
328
	if (IS_TYPE_PTR(cb)) {
-
 
329
		/* Alright because order of evaluation is undefined */
-
 
330
		EXP c = a;
-
 
331
		TYPE tc = ta;
-
 
332
		unsigned cc = ca;
-
 
333
		a = b;
-
 
334
		b = c;
-
 
335
		ta = tb;
-
 
336
		tb = tc;
-
 
337
		ca = cb;
-
 
338
		cb = cc;
-
 
339
		sa = sb;
-
 
340
	}
-
 
341
 
-
 
342
	/* The first operand should now be a pointer */
-
 
343
	if (!IS_TYPE_PTR(ca)) {
-
 
344
		if (!IS_TYPE_ERROR(ca) && !IS_TYPE_ERROR(cb)) {
-
 
345
			report(crt_loc, ERR_expr_sub_ptr_op(ta, tb));
-
 
346
		}
-
 
347
		return (make_error_exp(0));
-
 
348
	}
-
 
349
 
-
 
350
	/* The second operand should be integral */
-
 
351
	if (!IS_TYPE_INT(cb)) {
-
 
352
		if (!IS_TYPE_ERROR(cb)) {
-
 
353
			report(crt_loc, ERR_expr_sub_int_op(tb));
-
 
354
		}
-
 
355
		/* Continue with zero index */
-
 
356
		z = 1;
-
 
357
	}
-
 
358
 
-
 
359
	/* Check index value */
-
 
360
	if (IS_exp_int_lit(b)) {
-
 
361
		if (IS_type_array(sa)) {
-
 
362
			check_bounds(lex_array_Hop, sa, b);
-
 
363
		}
-
 
364
		z = is_zero_exp(b);
-
 
365
	} else {
-
 
366
		if (eq_type_unqual(tb, type_char)) {
-
 
367
			report(crt_loc, ERR_expr_sub_char_op(tb));
404
    }
368
		}
-
 
369
	}
405
 
370
 
406
    /* Operand can be pointer ... */
371
	/* The pointer must be to a complete object type */
407
    if ( IS_TYPE_PTR ( ca ) ) {
-
 
408
	TYPE t = check_pointer ( ta, KILL_err ) ;
372
	t = check_pointer(ta, &err);
409
	if ( IS_type_top_etc ( t ) ) {
-
 
410
	    /* The pointer cannot be 'void *' */
-
 
411
	    report ( crt_loc, ERR_expr_unary_op_indir_void ( ta ) ) ;
-
 
412
	}
-
 
413
	if ( IS_exp_null ( a ) ) {
373
	if (!IS_NULL_err(err)) {
414
	    /* Check for obvious null pointers */
-
 
415
	    report ( crt_loc, ERR_expr_unary_op_indir_null ( lex_star ) ) ;
-
 
416
	}
-
 
417
 
-
 
418
	/* The result is an lvalue */
-
 
419
	t = lvalue_type ( t ) ;
-
 
420
 
-
 
421
	/* Construct the result */
-
 
422
	MAKE_exp_indir ( t, a, e ) ;
-
 
423
	return ( e ) ;
-
 
424
    }
-
 
425
 
-
 
426
    /* ... and nothing else */
-
 
427
    if ( !IS_TYPE_ERROR ( ca ) ) {
-
 
428
	report ( crt_loc, ERR_expr_unary_op_indir_op ( ta ) ) ;
374
		err = concat_error(err, ERR_expr_sub_incompl());
429
    }
-
 
430
    return ( make_error_exp ( 1 ) ) ;
-
 
431
}
-
 
432
 
-
 
433
 
-
 
434
/*
-
 
435
    CONSTRUCT A REFERENCE TO AN OBJECT
-
 
436
 
-
 
437
    This routine constructs a pointer to the expression a which designates
-
 
438
    an object.  Any errors arising are added to err.
-
 
439
*/
-
 
440
 
-
 
441
EXP make_ref_object
-
 
442
    PROTO_N ( ( a, err ) )
-
 
443
    PROTO_T ( EXP a X ERROR *err )
-
 
444
{
-
 
445
    EXP e ;
-
 
446
    TYPE p ;
-
 
447
    TYPE ta = DEREF_type ( exp_type ( a ) ) ;
-
 
448
    unsigned ca = type_category ( &ta ) ;
-
 
449
    if ( IS_TYPE_ERROR ( ca ) ) {
-
 
450
	/* Error progagation */
-
 
451
	e = make_error_exp ( 0 ) ;
-
 
452
	return ( e ) ;
375
		report(crt_loc, err);
453
    }
-
 
454
    if ( !IS_TYPE_LVALUE ( ca ) ) {
-
 
455
	/* Operand should be an lvalue */
-
 
456
	add_error ( err, ERR_expr_unary_op_ref_lvalue () ) ;
-
 
457
    }
-
 
458
    if ( IS_TYPE_BITF ( ca ) ) {
-
 
459
	/* Can't apply to a bitfield */
-
 
460
	add_error ( err, ERR_expr_unary_op_ref_bitf () ) ;
-
 
461
	ta = find_bitfield_type ( ta ) ;
-
 
462
    }
-
 
463
    if ( option ( OPT_addr_register ) && used_register ) {
-
 
464
	/* Can't apply to a register variable in C */
-
 
465
	EXP b = NULL_exp ;
-
 
466
	DECL_SPEC ds = find_exp_linkage ( a, &b, 1 ) ;
-
 
467
	if ( ( ds & dspec_register ) && !( ds & dspec_temp ) ) {
-
 
468
	    if ( IS_exp_identifier ( b ) ) {
-
 
469
		IDENTIFIER id = DEREF_id ( exp_identifier_id ( b ) ) ;
-
 
470
		add_error ( err, ERR_expr_unary_op_ref_register ( id ) ) ;
-
 
471
	    }
-
 
472
	}
376
	}
473
    }
377
 
474
    if ( IS_type_top_etc ( ta ) ) {
378
	/* Construct pointer to the result */
-
 
379
	if (z) {
475
	/* Can't apply to void */
380
		/* Zero offset */
476
	add_error ( err, ERR_expr_unary_op_ref_void ( ta ) ) ;
381
		p = a;
477
    } else {
382
	} else {
478
	/* Check for incomplete types */
383
		/* Non-zero offset */
479
	ERROR err2 = check_incomplete ( ta ) ;
384
		if (IS_TYPE_BITF(cb)) {
480
	if ( !IS_NULL_err ( err2 ) ) {
385
			b = convert_bitfield(b);
-
 
386
		}
481
	    add_error ( err, err2 ) ;
387
		off = make_off_mult(t, b, 0);
482
	    add_error ( err, ERR_expr_unary_op_ref_incompl () ) ;
388
		p = make_add_ptr(ta, a, off);
483
	}
389
	}
484
    }
-
 
485
 
390
 
-
 
391
	/* The result is an lvalue */
-
 
392
	t = lvalue_type(t);
-
 
393
 
-
 
394
	/* Construct the result */
-
 
395
	MAKE_exp_indir(t, p, e);
-
 
396
	COPY_int(exp_indir_index(e), 1);
-
 
397
	return (e);
-
 
398
}
-
 
399
 
-
 
400
 
-
 
401
/*
-
 
402
    CONSTRUCT A INDIRECTION EXPRESSION
-
 
403
 
-
 
404
    This routine constructs the indirection expression '*a'.  The result
-
 
405
    is an lvalue.
-
 
406
*/
-
 
407
 
-
 
408
EXP
-
 
409
make_indir_exp(EXP a)
-
 
410
{
-
 
411
	EXP e;
-
 
412
	TYPE ta;
-
 
413
	unsigned ca;
-
 
414
 
-
 
415
	/* Do reference conversion */
-
 
416
	a = convert_reference(a, REF_NORMAL);
-
 
417
 
-
 
418
	/* Find operand type */
-
 
419
	ta = DEREF_type(exp_type(a));
-
 
420
	ca = type_category(&ta);
-
 
421
 
-
 
422
	/* Check for overloading */
-
 
423
#if LANGUAGE_CPP
-
 
424
	if (IS_TYPE_OVERLOAD(ca)) {
-
 
425
		if (overload_depth == 0) {
-
 
426
			e = unary_overload(lex_star, a);
-
 
427
			return (e);
-
 
428
		}
-
 
429
	}
-
 
430
#endif
-
 
431
 
-
 
432
	/* Do lvalue conversion */
-
 
433
	if (IS_TYPE_ADDRESS(ca)) {
-
 
434
		a = convert_lvalue(a);
-
 
435
		ta = DEREF_type(exp_type(a));
-
 
436
		ca = type_category(&ta);
-
 
437
	}
-
 
438
 
-
 
439
	/* Operand can be pointer ... */
-
 
440
	if (IS_TYPE_PTR(ca)) {
-
 
441
		TYPE t = check_pointer(ta, KILL_err);
-
 
442
		if (IS_type_top_etc(t)) {
-
 
443
			/* The pointer cannot be 'void *' */
-
 
444
			report(crt_loc, ERR_expr_unary_op_indir_void(ta));
-
 
445
		}
-
 
446
		if (IS_exp_null(a)) {
-
 
447
			/* Check for obvious null pointers */
-
 
448
			report(crt_loc, ERR_expr_unary_op_indir_null(lex_star));
-
 
449
		}
-
 
450
 
-
 
451
		/* The result is an lvalue */
-
 
452
		t = lvalue_type(t);
-
 
453
 
486
    /* Construct the result */
454
		/* Construct the result */
-
 
455
		MAKE_exp_indir(t, a, e);
-
 
456
		return (e);
-
 
457
	}
-
 
458
 
-
 
459
	/* ... and nothing else */
-
 
460
	if (!IS_TYPE_ERROR(ca)) {
-
 
461
		report(crt_loc, ERR_expr_unary_op_indir_op(ta));
-
 
462
	}
-
 
463
	return (make_error_exp(1));
-
 
464
}
-
 
465
 
-
 
466
 
-
 
467
/*
-
 
468
    CONSTRUCT A REFERENCE TO AN OBJECT
-
 
469
 
-
 
470
    This routine constructs a pointer to the expression a which designates
-
 
471
    an object.  Any errors arising are added to err.
-
 
472
*/
-
 
473
 
-
 
474
EXP
-
 
475
make_ref_object(EXP a, ERROR *err)
-
 
476
{
-
 
477
	EXP e;
-
 
478
	TYPE p;
-
 
479
	TYPE ta = DEREF_type(exp_type(a));
-
 
480
	unsigned ca = type_category(&ta);
-
 
481
	if (IS_TYPE_ERROR(ca)) {
-
 
482
		/* Error progagation */
-
 
483
		e = make_error_exp(0);
-
 
484
		return (e);
-
 
485
	}
-
 
486
	if (!IS_TYPE_LVALUE(ca)) {
-
 
487
		/* Operand should be an lvalue */
-
 
488
		add_error(err, ERR_expr_unary_op_ref_lvalue());
-
 
489
	}
-
 
490
	if (IS_TYPE_BITF(ca)) {
-
 
491
		/* Can't apply to a bitfield */
-
 
492
		add_error(err, ERR_expr_unary_op_ref_bitf());
-
 
493
		ta = find_bitfield_type(ta);
-
 
494
	}
-
 
495
	if (option(OPT_addr_register) && used_register) {
-
 
496
		/* Can't apply to a register variable in C */
-
 
497
		EXP b = NULL_exp;
-
 
498
		DECL_SPEC ds = find_exp_linkage(a, &b, 1);
-
 
499
		if ((ds & dspec_register) && !(ds & dspec_temp)) {
-
 
500
			if (IS_exp_identifier(b)) {
-
 
501
				IDENTIFIER id = DEREF_id(exp_identifier_id(b));
-
 
502
				add_error(err,
-
 
503
					  ERR_expr_unary_op_ref_register(id));
-
 
504
			}
-
 
505
		}
-
 
506
	}
-
 
507
	if (IS_type_top_etc(ta)) {
-
 
508
		/* Can't apply to void */
-
 
509
		add_error(err, ERR_expr_unary_op_ref_void(ta));
-
 
510
	} else {
-
 
511
		/* Check for incomplete types */
-
 
512
		ERROR err2 = check_incomplete(ta);
-
 
513
		if (!IS_NULL_err(err2)) {
-
 
514
			add_error(err, err2);
-
 
515
			add_error(err, ERR_expr_unary_op_ref_incompl());
-
 
516
		}
-
 
517
	}
-
 
518
 
-
 
519
	/* Construct the result */
487
    ta = rvalue_type ( ta ) ;
520
	ta = rvalue_type(ta);
488
    MAKE_type_ptr ( cv_none, ta, p ) ;
521
	MAKE_type_ptr(cv_none, ta, p);
489
    MAKE_exp_address ( p, a, e ) ;
522
	MAKE_exp_address(p, a, e);
490
    return ( e ) ;
523
	return (e);
491
}
524
}
492
 
525
 
493
 
526
 
494
/*
527
/*
495
    CONSTRUCT A REFERENCE TO A MEMBER
528
    CONSTRUCT A REFERENCE TO A MEMBER
Line 497... Line 530...
497
    This routine constructs a pointer to the expression a which designates
530
    This routine constructs a pointer to the expression a which designates
498
    a class member.  Note that a can represent an overloaded member function
531
    a class member.  Note that a can represent an overloaded member function
499
    in which case the actual result type can only be determined after
532
    in which case the actual result type can only be determined after
500
    overload resolution.  Also the type of an inherited member is that
533
    overload resolution.  Also the type of an inherited member is that
501
    of its base class rather than its derived class.
534
    of its base class rather than its derived class.
502
*/
535
*/
503
 
536
 
504
#if LANGUAGE_CPP
537
#if LANGUAGE_CPP
505
 
538
 
506
static EXP make_ref_member
539
static EXP
507
    PROTO_N ( ( a, paren, res ) )
-
 
508
    PROTO_T ( EXP a X int paren X int res )
540
make_ref_member(EXP a, int paren, int res)
509
{
541
{
510
    EXP e ;
542
	EXP e;
511
    TYPE p ;
543
	TYPE p;
512
    DECL_SPEC ds ;
544
	DECL_SPEC ds;
513
 
545
 
514
    /* Find the base class */
546
	/* Find the base class */
515
    IDENTIFIER id = DEREF_id ( exp_member_id ( a ) ) ;
547
	IDENTIFIER id = DEREF_id(exp_member_id(a));
516
    IDENTIFIER uid = DEREF_id ( id_alias ( id ) ) ;
548
	IDENTIFIER uid = DEREF_id(id_alias(id));
517
    CLASS_TYPE tc = parent_class ( uid ) ;
549
	CLASS_TYPE tc = parent_class(uid);
518
 
550
 
519
    /* Find the result type */
551
	/* Find the result type */
520
    TYPE ta = DEREF_type ( exp_type ( a ) ) ;
552
	TYPE ta = DEREF_type(exp_type(a));
521
    ta = rvalue_type ( ta ) ;
553
	ta = rvalue_type(ta);
522
    if ( IS_type_bitfield ( ta ) ) {
554
	if (IS_type_bitfield(ta)) {
523
	/* Can't apply to a bitfield */
555
		/* Can't apply to a bitfield */
524
	report ( crt_loc, ERR_expr_unary_op_ref_bitf () ) ;
556
		report(crt_loc, ERR_expr_unary_op_ref_bitf());
525
	ta = find_bitfield_type ( ta ) ;
557
		ta = find_bitfield_type(ta);
526
    }
558
	}
527
    MAKE_type_ptr_mem ( cv_none, tc, ta, p ) ;
559
	MAKE_type_ptr_mem(cv_none, tc, ta, p);
528
 
560
 
529
    /* Construct the result */
561
	/* Construct the result */
530
    if ( !EQ_id ( id, uid ) ) {
562
	if (!EQ_id(id, uid)) {
531
	QUALIFIER qual = DEREF_qual ( exp_member_qual ( a ) ) ;
563
		QUALIFIER qual = DEREF_qual(exp_member_qual(a));
532
	MAKE_exp_member ( ta, uid, qual, a ) ;
564
		MAKE_exp_member(ta, uid, qual, a);
533
    }
565
	}
534
    MAKE_exp_address_mem ( p, a, paren, e ) ;
566
	MAKE_exp_address_mem(p, a, paren, e);
535
    if ( res ) {
567
	if (res) {
536
	/* Mark identifier as used */
568
		/* Mark identifier as used */
537
	if ( res == 2 ) {
569
		if (res == 2) {
538
	    use_id ( id, suppress_usage ) ;
570
			use_id(id, suppress_usage);
539
	} else {
571
		} else {
540
	    reuse_id ( id, suppress_usage ) ;
572
			reuse_id(id, suppress_usage);
541
	}
573
		}
542
	ds = DEREF_dspec ( id_storage ( id ) ) ;
574
		ds = DEREF_dspec(id_storage(id));
543
	if ( ds & dspec_trivial ) {
575
		if (ds & dspec_trivial) {
544
	    /* Can take the address of a trivial function */
576
			/* Can take the address of a trivial function */
545
	    CONS_id ( id, pending_funcs, pending_funcs ) ;
577
			CONS_id(id, pending_funcs, pending_funcs);
546
	}
578
		}
547
    }
579
	}
548
    return ( e ) ;
580
	return (e);
549
}
581
}
550
 
582
 
551
#endif
583
#endif
552
 
584
 
553
 
585
 
554
/*
586
/*
555
    CONSTRUCT A REFERENCE EXPRESSION
587
    CONSTRUCT A REFERENCE EXPRESSION
556
 
588
 
557
    This routine constructs the expression '&a' for constructing a pointer
589
    This routine constructs the expression '&a' for constructing a pointer
558
    to a or a pointer member to a.  The res argument is true to indicate
590
    to a or a pointer member to a.  The res argument is true to indicate
559
    that any overloaded functions in a have been resolved.
591
    that any overloaded functions in a have been resolved.
560
*/
592
*/
561
 
593
 
562
EXP make_ref_exp
594
EXP
563
    PROTO_N ( ( a, res ) )
-
 
564
    PROTO_T ( EXP a X int res )
595
make_ref_exp(EXP a, int res)
565
{
596
{
566
    EXP e ;
597
	EXP e;
567
    ERROR err = NULL_err ;
598
	ERROR err = NULL_err;
568
 
599
 
569
#if LANGUAGE_CPP
600
#if LANGUAGE_CPP
570
    TYPE ta ;
601
	TYPE ta;
571
    unsigned ca ;
602
	unsigned ca;
572
    int paren = IS_exp_paren ( a ) ;
603
	int paren = IS_exp_paren(a);
573
 
604
 
574
    /* Perform reference conversions */
605
	/* Perform reference conversions */
575
    a = convert_reference ( a, REF_ADDRESS ) ;
606
	a = convert_reference(a, REF_ADDRESS);
576
 
607
 
577
    /* Check for members */
608
	/* Check for members */
578
    if ( IS_exp_member ( a ) ) {
609
	if (IS_exp_member(a)) {
579
	int is_mem = 1 ;
610
		int is_mem = 1;
580
	IDENTIFIER id = DEREF_id ( exp_member_id ( a ) ) ;
611
		IDENTIFIER id = DEREF_id(exp_member_id(a));
581
	QUALIFIER idtype = DEREF_qual ( exp_member_qual ( a ) ) ;
612
		QUALIFIER idtype = DEREF_qual(exp_member_qual(a));
582
	idtype &= ~qual_mark ;
613
		idtype &= ~qual_mark;
583
	if ( !( idtype & qual_explicit ) ) {
614
		if (!(idtype & qual_explicit)) {
584
	    EXP b = make_this_field ( id ) ;
615
			EXP b = make_this_field(id);
585
	    if ( !IS_NULL_exp ( b ) ) {
616
			if (!IS_NULL_exp(b)) {
586
		a = convert_reference ( b, REF_ADDRESS ) ;
617
				a = convert_reference(b, REF_ADDRESS);
587
		is_mem = 0 ;
618
				is_mem = 0;
588
	    }
619
			}
589
	}
620
		}
590
	if ( is_mem ) {
621
		if (is_mem) {
591
	    if ( IS_id_member ( id ) ) res = 2 ;
622
			if (IS_id_member(id))res = 2;
592
	    if ( res ) {
623
			if (res) {
593
		if ( idtype == qual_none ) {
624
				if (idtype == qual_none) {
594
		    /* Identifiers must be qualified */
625
					/* Identifiers must be qualified */
-
 
626
					report(crt_loc,
595
		    report ( crt_loc, ERR_expr_unary_op_ref_unqual () ) ;
627
					       ERR_expr_unary_op_ref_unqual());
596
		} else {
628
				} else {
597
		    if ( idtype != qual_nested ) {
629
					if (idtype != qual_nested) {
-
 
630
						/* Shouldn't have fully
598
			/* Shouldn't have fully qualified identifier */
631
						 * qualified identifier */
599
			report ( crt_loc, ERR_expr_unary_op_ref_full () ) ;
632
						report(crt_loc, ERR_expr_unary_op_ref_full());
600
		    }
633
					}
601
		    if ( paren ) {
634
					if (paren) {
602
			/* Identifier can't be parenthesised */
635
						/* Identifier can't be
-
 
636
						 * parenthesised */
603
			report ( crt_loc, ERR_expr_unary_op_ref_paren () ) ;
637
						report(crt_loc, ERR_expr_unary_op_ref_paren());
604
			paren = 0 ;
638
						paren = 0;
605
		    }
639
					}
-
 
640
				}
-
 
641
			}
-
 
642
			e = make_ref_member(a, paren, res);
-
 
643
			return (e);
-
 
644
		}
-
 
645
	}
-
 
646
 
-
 
647
	/* Get operand type */
-
 
648
	ta = DEREF_type(exp_type(a));
-
 
649
	ca = type_category(&ta);
-
 
650
	if (IS_TYPE_OVERLOAD(ca)) {
-
 
651
		/* Check for overloading */
-
 
652
		if (overload_depth == 0) {
-
 
653
			e = unary_overload(lex_and_H1, a);
-
 
654
			return (e);
-
 
655
		}
-
 
656
		if (IS_type_compound(ta)) {
-
 
657
			/* Mark class types */
-
 
658
			CLASS_TYPE ct = DEREF_ctype(type_compound_defn(ta));
-
 
659
			CLASS_USAGE cu = DEREF_cusage(ctype_usage(ct));
-
 
660
			cu |= cusage_address;
-
 
661
			COPY_cusage(ctype_usage(ct), cu);
606
		}
662
		}
607
	    }
-
 
608
	    e = make_ref_member ( a, paren, res ) ;
-
 
609
	    return ( e ) ;
-
 
610
	}
663
	}
611
    }
-
 
612
 
-
 
613
    /* Get operand type */
-
 
614
    ta = DEREF_type ( exp_type ( a ) ) ;
-
 
615
    ca = type_category ( &ta ) ;
-
 
616
    if ( IS_TYPE_OVERLOAD ( ca ) ) {
-
 
617
	/* Check for overloading */
-
 
618
	if ( overload_depth == 0 ) {
-
 
619
	    e = unary_overload ( lex_and_H1, a ) ;
-
 
620
	    return ( e ) ;
-
 
621
	}
-
 
622
	if ( IS_type_compound ( ta ) ) {
-
 
623
	    /* Mark class types */
-
 
624
	    CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( ta ) ) ;
-
 
625
	    CLASS_USAGE cu = DEREF_cusage ( ctype_usage ( ct ) ) ;
-
 
626
	    cu |= cusage_address ;
-
 
627
	    COPY_cusage ( ctype_usage ( ct ), cu ) ;
-
 
628
	}
-
 
629
    }
-
 
630
 
664
 
631
#else
665
#else
632
 
666
 
633
    /* Perform reference conversions */
667
	/* Perform reference conversions */
634
    a = convert_reference ( a, REF_ADDRESS ) ;
668
	a = convert_reference(a, REF_ADDRESS);
635
    UNUSED ( res ) ;
669
	UNUSED(res);
636
 
670
 
637
#endif
671
#endif
638
 
672
 
639
    /* Construct the result */
673
	/* Construct the result */
640
    e = make_ref_object ( a, &err ) ;
674
	e = make_ref_object(a, &err);
641
    if ( !IS_NULL_err ( err ) ) report ( crt_loc, err ) ;
675
	if (!IS_NULL_err(err)) {
-
 
676
		report(crt_loc, err);
-
 
677
	}
642
    return ( e ) ;
678
	return (e);
643
}
679
}
644
 
680
 
645
 
681
 
646
/*
682
/*
647
    CONSTRUCT A UNARY ARITHMETIC EXPRESSION
683
    CONSTRUCT A UNARY ARITHMETIC EXPRESSION
Line 650... Line 686...
650
    '+a' the expression constructed is '( a )' rather than 'a'.  This is
686
    '+a' the expression constructed is '( a )' rather than 'a'.  This is
651
    to prevent expressions like 'a << +( b + c )' confusing the dubious
687
    to prevent expressions like 'a << +( b + c )' confusing the dubious
652
    parenthesis checks.
688
    parenthesis checks.
653
*/
689
*/
654
 
690
 
655
EXP make_uminus_exp
691
EXP
656
    PROTO_N ( ( op, a ) )
-
 
657
    PROTO_T ( int op X EXP a )
692
make_uminus_exp(int op, EXP a)
658
{
693
{
659
    TYPE ta ;
694
	TYPE ta;
660
    unsigned ca ;
695
	unsigned ca;
661
 
696
 
662
    /* Find operation information */
697
	/* Find operation information */
663
    unsigned cb = CTYPE_ARITH ;
698
	unsigned cb = CTYPE_ARITH;
664
    unsigned tag = exp_negate_tag ;
699
	unsigned tag = exp_negate_tag;
665
    switch ( op ) {
700
	switch (op) {
666
	case lex_plus : {
701
	case lex_plus: {
667
	    tag = exp_paren_tag ;
702
		tag = exp_paren_tag;
668
#if LANGUAGE_CPP
703
#if LANGUAGE_CPP
669
	    cb = CTYPE_SCALAR ;
704
		cb = CTYPE_SCALAR;
670
#endif
705
#endif
671
	    break ;
706
		break;
672
	}
707
	}
673
	case lex_compl_H1 : {
708
	case lex_compl_H1: {
674
	    tag = exp_compl_tag ;
709
		tag = exp_compl_tag;
675
	    cb = CTYPE_INT ;
710
		cb = CTYPE_INT;
676
	    break ;
711
		break;
677
	}
712
	}
678
	case lex_abs : {
713
	case lex_abs: {
679
	    tag = exp_abs_tag ;
714
		tag = exp_abs_tag;
680
	    break ;
715
		break;
-
 
716
	}
-
 
717
	}
-
 
718
 
-
 
719
	/* Do reference conversion */
-
 
720
	a = convert_reference(a, REF_NORMAL);
-
 
721
 
-
 
722
	/* Find the operand type */
-
 
723
	ta = DEREF_type(exp_type(a));
-
 
724
	ca = type_category(&ta);
-
 
725
 
-
 
726
	/* Check for overloading */
-
 
727
#if LANGUAGE_CPP
-
 
728
	if (IS_TYPE_OVERLOAD(ca)) {
-
 
729
		if (overload_depth == 0) {
-
 
730
			EXP e = unary_overload(op, a);
-
 
731
			return (e);
-
 
732
		}
-
 
733
	}
-
 
734
#endif
-
 
735
 
-
 
736
	/* Do lvalue conversion */
-
 
737
	if (IS_TYPE_ADDRESS(ca)) {
-
 
738
		a = convert_lvalue(a);
-
 
739
		ta = DEREF_type(exp_type(a));
-
 
740
		ca = type_category(&ta);
681
	}
741
	}
682
    }
-
 
683
 
-
 
684
    /* Do reference conversion */
-
 
685
    a = convert_reference ( a, REF_NORMAL ) ;
-
 
686
 
742
 
687
    /* Find the operand type */
743
	/* Check operand type ... */
-
 
744
	if (ca & cb) {
-
 
745
		EXP e;
688
    ta = DEREF_type ( exp_type ( a ) ) ;
746
		TYPE pta = promote_type(ta);
-
 
747
		a = convert_promote(pta, a);
-
 
748
		if (tag == exp_paren_tag) {
689
    ca = type_category ( &ta ) ;
749
			e = make_paren_exp(a);
-
 
750
		} else {
-
 
751
			if (IS_exp_int_lit(a)) {
-
 
752
				e = make_unary_nat(tag, a);
-
 
753
			} else {
-
 
754
				MAKE_exp_negate_etc(tag, pta, a, e);
-
 
755
			}
-
 
756
		}
-
 
757
		return (e);
-
 
758
	}
690
 
759
 
691
    /* Check for overloading */
-
 
692
#if LANGUAGE_CPP
-
 
693
    if ( IS_TYPE_OVERLOAD ( ca ) ) {
-
 
694
	if ( overload_depth == 0 ) {
-
 
695
	    EXP e = unary_overload ( op, a ) ;
-
 
696
	    return ( e ) ;
-
 
697
	}
-
 
698
    }
-
 
699
#endif
-
 
700
 
-
 
701
    /* Do lvalue conversion */
-
 
702
    if ( IS_TYPE_ADDRESS ( ca ) ) {
-
 
703
	a = convert_lvalue ( a ) ;
-
 
704
	ta = DEREF_type ( exp_type ( a ) ) ;
-
 
705
	ca = type_category ( &ta ) ;
-
 
706
    }
-
 
707
 
-
 
708
    /* Check operand type ... */
-
 
709
    if ( ca & cb ) {
-
 
710
	EXP e ;
-
 
711
	TYPE pta = promote_type ( ta ) ;
-
 
712
	a = convert_promote ( pta, a ) ;
-
 
713
	if ( tag == exp_paren_tag ) {
-
 
714
	    e = make_paren_exp ( a ) ;
-
 
715
	} else {
-
 
716
	    if ( IS_exp_int_lit ( a ) ) {
-
 
717
		e = make_unary_nat ( tag, a ) ;
-
 
718
	    } else {
-
 
719
		MAKE_exp_negate_etc ( tag, pta, a, e ) ;
-
 
720
	    }
-
 
721
	}
-
 
722
	return ( e ) ;
-
 
723
    }
-
 
724
 
-
 
725
    /* ... and report error otherwise */
760
	/* ... and report error otherwise */
726
    if ( !IS_TYPE_ERROR ( ca ) ) {
761
	if (!IS_TYPE_ERROR(ca)) {
727
	ERROR err ;
762
		ERROR err;
728
	if ( cb == CTYPE_SCALAR ) {
763
		if (cb == CTYPE_SCALAR) {
729
	    err = ERR_expr_unary_op_uplus_op ( op, ta ) ;
764
			err = ERR_expr_unary_op_uplus_op(op, ta);
730
	} else if ( cb == CTYPE_ARITH ) {
765
		} else if (cb == CTYPE_ARITH) {
731
	    err = ERR_expr_unary_op_uminus_op ( op, ta ) ;
766
			err = ERR_expr_unary_op_uminus_op(op, ta);
732
	} else {
767
		} else {
733
	    err = ERR_expr_unary_op_compl_op ( op, ta ) ;
768
			err = ERR_expr_unary_op_compl_op(op, ta);
734
	}
769
		}
735
	report ( crt_loc, err ) ;
770
		report(crt_loc, err);
736
    }
771
	}
737
    return ( make_error_exp ( 0 ) ) ;
772
	return (make_error_exp(0));
738
}
773
}
739
 
774
 
740
 
775
 
741
/*
776
/*
742
    CONSTRUCT A LOGICAL NEGATION EXPRESSION
777
    CONSTRUCT A LOGICAL NEGATION EXPRESSION
743
 
778
 
744
    This routine constructs the expression '!a'.
779
    This routine constructs the expression '!a'.
745
*/
780
*/
746
 
781
 
747
EXP make_not_exp
782
EXP
748
    PROTO_N ( ( a ) )
-
 
749
    PROTO_T ( EXP a )
783
make_not_exp(EXP a)
750
{
784
{
751
    TYPE ta ;
785
	TYPE ta;
752
    EXP e, b ;
786
	EXP e, b;
753
    unsigned ca ;
787
	unsigned ca;
754
    ERROR err = NULL_err ;
788
	ERROR err = NULL_err;
755
    unsigned tag = TAG_exp ( a ) ;
789
	unsigned tag = TAG_exp(a);
756
 
790
 
757
    /* Do reference conversion */
791
	/* Do reference conversion */
758
    a = convert_reference ( a, REF_NORMAL ) ;
792
	a = convert_reference(a, REF_NORMAL);
759
 
793
 
760
    /* Find the operand type */
794
	/* Find the operand type */
761
    ta = DEREF_type ( exp_type ( a ) ) ;
795
	ta = DEREF_type(exp_type(a));
762
    ca = type_category ( &ta ) ;
796
	ca = type_category(&ta);
763
 
797
 
764
    /* Check for overloading */
798
	/* Check for overloading */
765
#if LANGUAGE_CPP
799
#if LANGUAGE_CPP
766
    if ( IS_TYPE_OVERLOAD ( ca ) ) {
800
	if (IS_TYPE_OVERLOAD(ca)) {
767
	if ( overload_depth == 0 ) {
801
		if (overload_depth == 0) {
768
	    e = unary_overload ( lex_not_H1, a ) ;
802
			e = unary_overload(lex_not_H1, a);
769
	    return ( e ) ;
803
			return (e);
770
	}
804
		}
771
    }
805
	}
772
#endif
806
#endif
773
 
807
 
774
    /* Do lvalue conversion */
808
	/* Do lvalue conversion */
775
    if ( IS_TYPE_ADDRESS ( ca ) ) {
809
	if (IS_TYPE_ADDRESS(ca)) {
776
	a = convert_lvalue ( a ) ;
810
		a = convert_lvalue(a);
777
    }
811
	}
778
 
812
 
779
    /* Convert the operand to a boolean */
813
	/* Convert the operand to a boolean */
780
    b = convert_boolean ( a, tag, &err ) ;
814
	b = convert_boolean(a, tag, &err);
781
    if ( !IS_NULL_err ( err ) ) {
815
	if (!IS_NULL_err(err)) {
782
	err = concat_error ( err, ERR_expr_unary_op_not_op () ) ;
816
		err = concat_error(err, ERR_expr_unary_op_not_op());
783
	report ( crt_loc, err ) ;
817
		report(crt_loc, err);
784
    }
818
	}
785
 
819
 
786
    /* Construct the result */
820
	/* Construct the result */
787
    if ( IS_exp_int_lit ( b ) ) {
821
	if (IS_exp_int_lit(b)) {
788
	e = make_unary_nat ( exp_not_tag, b ) ;
822
		e = make_unary_nat(exp_not_tag, b);
789
    } else {
823
	} else {
790
	MAKE_exp_not ( type_bool, b, e ) ;
824
		MAKE_exp_not(type_bool, b, e);
791
    }
825
	}
792
    return ( e ) ;
826
	return (e);
793
}
827
}
794
 
828
 
795
 
829
 
796
/*
830
/*
797
    DIVISION MODE
831
    DIVISION MODE
Line 800... Line 834...
800
    operations.  The values 0, 1 and 2 correspond to the TDF operations
834
    operations.  The values 0, 1 and 2 correspond to the TDF operations
801
    div0, div1 and div2 and rem0, rem1 and rem2 respectively.  The value 3
835
    div0, div1 and div2 and rem0, rem1 and rem2 respectively.  The value 3
802
    indicates that the decision should be postponed to the installers.
836
    indicates that the decision should be postponed to the installers.
803
*/
837
*/
804
 
838
 
805
int division_mode = 3 ;
839
int division_mode = 3;
806
 
840
 
807
 
841
 
808
/*
842
/*
809
    CHECK FOR DUBIOUS DIVISION EXPRESSIONS
843
    CHECK FOR DUBIOUS DIVISION EXPRESSIONS
810
 
844
 
Line 812... Line 846...
812
    dubious constant operands.  All the necessary operand and arithmetic
846
    dubious constant operands.  All the necessary operand and arithmetic
813
    type conversions have already been performed on a and b.  The routine
847
    type conversions have already been performed on a and b.  The routine
814
    returns 1 if both operands are integer constants and b is not zero.
848
    returns 1 if both operands are integer constants and b is not zero.
815
*/
849
*/
816
 
850
 
817
int check_div_exp
851
int
818
    PROTO_N ( ( op, a, b ) )
-
 
819
    PROTO_T ( int op X EXP a X EXP b )
852
check_div_exp(int op, EXP a, EXP b)
820
{
853
{
821
    int eval = 1 ;
854
	int eval = 1;
822
    int div_mode = division_mode ;
855
	int div_mode = division_mode;
823
    if ( IS_exp_int_lit ( b ) ) {
856
	if (IS_exp_int_lit(b)) {
824
	/* Check the second operand */
857
		/* Check the second operand */
825
	NAT n = DEREF_nat ( exp_int_lit_nat ( b ) ) ;
858
		NAT n = DEREF_nat(exp_int_lit_nat(b));
826
	if ( is_zero_nat ( n ) ) {
859
		if (is_zero_nat(n)) {
827
	    /* Report division by zero */
860
			/* Report division by zero */
828
	    report ( crt_loc, ERR_expr_mul_div_zero ( op ) ) ;
861
			report(crt_loc, ERR_expr_mul_div_zero(op));
829
	    return ( 0 ) ;
862
			return (0);
-
 
863
		}
-
 
864
		if (div_mode != 1 && div_mode != 2) {
-
 
865
			if (is_negative_nat(n) && !divides_nat(a, b)) {
-
 
866
				/* Division by negative is undefined */
-
 
867
				report(crt_loc, ERR_expr_mul_div_neg(op, n));
-
 
868
			}
-
 
869
		}
-
 
870
	} else {
-
 
871
		eval = 0;
830
	}
872
	}
831
	if ( div_mode != 1 && div_mode != 2 ) {
-
 
832
	    if ( is_negative_nat ( n ) && !divides_nat ( a, b ) ) {
-
 
833
		/* Division by negative is undefined */
-
 
834
		report ( crt_loc, ERR_expr_mul_div_neg ( op, n ) ) ;
-
 
835
	    }
-
 
836
	}
-
 
837
    } else {
-
 
838
	eval = 0 ;
-
 
839
    }
-
 
840
    if ( IS_exp_int_lit ( a ) ) {
873
	if (IS_exp_int_lit(a)) {
841
	/* Check the first operand */
874
		/* Check the first operand */
842
	if ( div_mode != 1 && div_mode != 2 ) {
875
		if (div_mode != 1 && div_mode != 2) {
843
	    NAT n = DEREF_nat ( exp_int_lit_nat ( a ) ) ;
876
			NAT n = DEREF_nat(exp_int_lit_nat(a));
844
	    if ( is_negative_nat ( n ) && !divides_nat ( a, b ) ) {
877
			if (is_negative_nat(n) && !divides_nat(a, b)) {
845
		/* Division of negative is undefined */
878
				/* Division of negative is undefined */
846
		report ( crt_loc, ERR_expr_mul_div_neg ( op, n ) ) ;
879
				report(crt_loc, ERR_expr_mul_div_neg(op, n));
847
	    }
880
			}
-
 
881
		}
-
 
882
	} else {
-
 
883
		eval = 0;
848
	}
884
	}
849
    } else {
-
 
850
	eval = 0 ;
-
 
851
    }
-
 
852
    return ( eval ) ;
885
	return (eval);
853
}
886
}
854
 
887
 
855
 
888
 
856
/*
889
/*
857
    CONSTRUCT A MULTIPLICATION OR DIVISION EXPRESSION
890
    CONSTRUCT A MULTIPLICATION OR DIVISION EXPRESSION
858
 
891
 
859
    This routine constructs the expressions 'a * b' and 'a / b'.
892
    This routine constructs the expressions 'a * b' and 'a / b'.
860
*/
893
*/
861
 
894
 
862
EXP make_mult_exp
895
EXP
863
    PROTO_N ( ( op, a, b ) )
-
 
864
    PROTO_T ( int op X EXP a X EXP b )
896
make_mult_exp(int op, EXP a, EXP b)
865
{
897
{
866
    TYPE ta, tb ;
898
	TYPE ta, tb;
867
    unsigned ca, cb ;
899
	unsigned ca, cb;
868
 
900
 
869
    /* Do reference conversions */
901
	/* Do reference conversions */
870
    a = convert_reference ( a, REF_NORMAL ) ;
902
	a = convert_reference(a, REF_NORMAL);
871
    b = convert_reference ( b, REF_NORMAL ) ;
903
	b = convert_reference(b, REF_NORMAL);
872
 
904
 
873
    /* Find operand types */
905
	/* Find operand types */
874
    ta = DEREF_type ( exp_type ( a ) ) ;
906
	ta = DEREF_type(exp_type(a));
875
    tb = DEREF_type ( exp_type ( b ) ) ;
907
	tb = DEREF_type(exp_type(b));
876
    ca = type_category ( &ta ) ;
908
	ca = type_category(&ta);
877
    cb = type_category ( &tb ) ;
909
	cb = type_category(&tb);
878
 
910
 
879
    /* Check for overloading */
911
	/* Check for overloading */
880
#if LANGUAGE_CPP
912
#if LANGUAGE_CPP
881
    if ( IS_TYPE_OVERLOAD ( ca ) || IS_TYPE_OVERLOAD ( cb ) ) {
913
	if (IS_TYPE_OVERLOAD(ca) || IS_TYPE_OVERLOAD(cb)) {
882
	if ( overload_depth == 0 ) {
914
		if (overload_depth == 0) {
883
	    EXP e = binary_overload ( op, a, b ) ;
915
			EXP e = binary_overload(op, a, b);
884
	    return ( e ) ;
916
			return (e);
885
	}
917
		}
886
    }
918
	}
887
#endif
919
#endif
888
 
920
 
889
    /* Do lvalue conversions */
921
	/* Do lvalue conversions */
890
    if ( IS_TYPE_ADDRESS ( ca ) ) {
922
	if (IS_TYPE_ADDRESS(ca)) {
891
	a = convert_lvalue ( a ) ;
923
		a = convert_lvalue(a);
892
	ta = DEREF_type ( exp_type ( a ) ) ;
924
		ta = DEREF_type(exp_type(a));
893
	ca = type_category ( &ta ) ;
925
		ca = type_category(&ta);
894
    }
926
	}
895
    if ( IS_TYPE_ADDRESS ( cb ) ) {
927
	if (IS_TYPE_ADDRESS(cb)) {
896
	b = convert_lvalue ( b ) ;
928
		b = convert_lvalue(b);
897
	tb = DEREF_type ( exp_type ( b ) ) ;
929
		tb = DEREF_type(exp_type(b));
898
	cb = type_category ( &tb ) ;
930
		cb = type_category(&tb);
899
    }
931
	}
900
 
932
 
901
    /* Operands can be arithmetic ... */
933
	/* Operands can be arithmetic ... */
902
    if ( IS_TYPE_ARITH ( ca ) && IS_TYPE_ARITH ( cb ) ) {
934
	if (IS_TYPE_ARITH(ca) && IS_TYPE_ARITH(cb)) {
903
	EXP e ;
935
		EXP e;
904
	unsigned tag ;
936
		unsigned tag;
905
	TYPE t = arith_type ( ta, tb, a, b ) ;
937
		TYPE t = arith_type(ta, tb, a, b);
906
	a = convert_arith ( t, a, op, 1 ) ;
938
		a = convert_arith(t, a, op, 1);
907
	b = convert_arith ( t, b, op, 2 ) ;
939
		b = convert_arith(t, b, op, 2);
908
 
940
 
909
	/* Check for constant operands */
941
		/* Check for constant operands */
910
	if ( op == lex_div ) {
942
		if (op == lex_div) {
911
	    tag = exp_div_tag ;
943
			tag = exp_div_tag;
912
	    if ( check_div_exp ( op, a, b ) ) {
944
			if (check_div_exp(op, a, b)) {
913
		e = make_binary_nat ( tag, a, b ) ;
945
				e = make_binary_nat(tag, a, b);
914
		return ( e ) ;
946
				return (e);
915
	    }
947
			}
916
	} else {
948
		} else {
917
	    if ( op == lex_star ) {
949
			if (op == lex_star) {
918
		tag = exp_mult_tag ;
950
				tag = exp_mult_tag;
919
	    } else if ( op == lex_max ) {
951
			} else if (op == lex_max) {
920
		tag = exp_max_tag ;
952
				tag = exp_max_tag;
921
	    } else {
953
			} else {
922
		tag = exp_min_tag ;
954
				tag = exp_min_tag;
923
	    }
955
			}
924
	    if ( IS_exp_int_lit ( a ) && IS_exp_int_lit ( b ) ) {
956
			if (IS_exp_int_lit(a) && IS_exp_int_lit(b)) {
925
		e = make_binary_nat ( tag, a, b ) ;
957
				e = make_binary_nat(tag, a, b);
926
		return ( e ) ;
958
				return (e);
927
	    }
959
			}
928
	}
960
		}
929
 
-
 
930
	/* Construct the result */
-
 
931
	MAKE_exp_plus_etc ( tag, t, a, b, e ) ;
-
 
932
	return ( e ) ;
-
 
933
    }
-
 
934
 
961
 
-
 
962
		/* Construct the result */
-
 
963
		MAKE_exp_plus_etc(tag, t, a, b, e);
-
 
964
		return (e);
-
 
965
	}
-
 
966
 
935
    /* ... and nothing else */
967
	/* ... and nothing else */
936
    if ( !IS_TYPE_ERROR ( ca ) && !IS_TYPE_ERROR ( cb ) ) {
968
	if (!IS_TYPE_ERROR(ca) && !IS_TYPE_ERROR(cb)) {
937
	report ( crt_loc, ERR_expr_mul_mul_op ( op, ta, tb ) ) ;
969
		report(crt_loc, ERR_expr_mul_mul_op(op, ta, tb));
938
    }
970
	}
939
    return ( make_error_exp ( 0 ) ) ;
971
	return (make_error_exp(0));
940
}
972
}
941
 
973
 
942
 
974
 
943
/*
975
/*
944
    CONSTRUCT A REMAINDER EXPRESSION
976
    CONSTRUCT A REMAINDER EXPRESSION
945
 
977
 
946
    This routine constructs the expression 'a % b'.
978
    This routine constructs the expression 'a % b'.
947
*/
979
*/
948
 
980
 
949
EXP make_rem_exp
981
EXP
950
    PROTO_N ( ( a, b ) )
-
 
951
    PROTO_T ( EXP a X EXP b )
982
make_rem_exp(EXP a, EXP b)
952
{
983
{
953
    TYPE ta, tb ;
984
	TYPE ta, tb;
954
    unsigned ca, cb ;
985
	unsigned ca, cb;
955
 
986
 
956
    /* Do reference conversions */
987
	/* Do reference conversions */
957
    a = convert_reference ( a, REF_NORMAL ) ;
988
	a = convert_reference(a, REF_NORMAL);
958
    b = convert_reference ( b, REF_NORMAL ) ;
989
	b = convert_reference(b, REF_NORMAL);
959
 
990
 
960
    /* Find operand types */
991
	/* Find operand types */
961
    ta = DEREF_type ( exp_type ( a ) ) ;
992
	ta = DEREF_type(exp_type(a));
962
    tb = DEREF_type ( exp_type ( b ) ) ;
993
	tb = DEREF_type(exp_type(b));
963
    ca = type_category ( &ta ) ;
994
	ca = type_category(&ta);
964
    cb = type_category ( &tb ) ;
995
	cb = type_category(&tb);
965
 
996
 
966
    /* Check for overloading */
997
	/* Check for overloading */
967
#if LANGUAGE_CPP
998
#if LANGUAGE_CPP
968
    if ( IS_TYPE_OVERLOAD ( ca ) || IS_TYPE_OVERLOAD ( cb ) ) {
999
	if (IS_TYPE_OVERLOAD(ca) || IS_TYPE_OVERLOAD(cb)) {
969
	if ( overload_depth == 0 ) {
1000
		if (overload_depth == 0) {
970
	    EXP e = binary_overload ( lex_rem, a, b ) ;
1001
			EXP e = binary_overload(lex_rem, a, b);
971
	    return ( e ) ;
1002
			return (e);
972
	}
1003
		}
973
    }
1004
	}
974
#endif
1005
#endif
975
 
1006
 
976
    /* Do lvalue conversions */
1007
	/* Do lvalue conversions */
977
    if ( IS_TYPE_ADDRESS ( ca ) ) {
1008
	if (IS_TYPE_ADDRESS(ca)) {
978
	a = convert_lvalue ( a ) ;
1009
		a = convert_lvalue(a);
979
	ta = DEREF_type ( exp_type ( a ) ) ;
1010
		ta = DEREF_type(exp_type(a));
980
	ca = type_category ( &ta ) ;
1011
		ca = type_category(&ta);
981
    }
1012
	}
982
    if ( IS_TYPE_ADDRESS ( cb ) ) {
1013
	if (IS_TYPE_ADDRESS(cb)) {
983
	b = convert_lvalue ( b ) ;
1014
		b = convert_lvalue(b);
984
	tb = DEREF_type ( exp_type ( b ) ) ;
1015
		tb = DEREF_type(exp_type(b));
985
	cb = type_category ( &tb ) ;
1016
		cb = type_category(&tb);
986
    }
1017
	}
987
 
1018
 
988
    /* Operands can be integral ... */
1019
	/* Operands can be integral ... */
989
    if ( IS_TYPE_INT ( ca ) && IS_TYPE_INT ( cb ) ) {
1020
	if (IS_TYPE_INT(ca) && IS_TYPE_INT(cb)) {
990
	EXP e ;
1021
		EXP e;
991
	TYPE t = arith_type ( ta, tb, a, b ) ;
1022
		TYPE t = arith_type(ta, tb, a, b);
992
	a = convert_arith ( t, a, lex_rem, 1 ) ;
1023
		a = convert_arith(t, a, lex_rem, 1);
993
	b = convert_arith ( t, b, lex_rem, 2 ) ;
1024
		b = convert_arith(t, b, lex_rem, 2);
-
 
1025
 
-
 
1026
		/* Check for constant operands */
-
 
1027
		if (check_div_exp(lex_rem, a, b)) {
-
 
1028
			e = make_binary_nat(exp_rem_tag, a, b);
-
 
1029
			return (e);
-
 
1030
		}
-
 
1031
 
-
 
1032
		/* Construct the result */
-
 
1033
		MAKE_exp_rem(t, a, b, e);
-
 
1034
		return (e);
-
 
1035
	}
994
 
1036
 
995
	/* Check for constant operands */
1037
	/* ... and nothing else */
996
	if ( check_div_exp ( lex_rem, a, b ) ) {
1038
	if (!IS_TYPE_ERROR(ca) && !IS_TYPE_ERROR(cb)) {
997
	    e = make_binary_nat ( exp_rem_tag, a, b ) ;
1039
		report(crt_loc, ERR_expr_mul_rem_op(lex_rem, ta, tb));
998
	    return ( e ) ;
-
 
999
	}
1040
	}
1000
 
-
 
1001
	/* Construct the result */
-
 
1002
	MAKE_exp_rem ( t, a, b, e ) ;
-
 
1003
	return ( e ) ;
-
 
1004
    }
-
 
1005
 
-
 
1006
    /* ... and nothing else */
-
 
1007
    if ( !IS_TYPE_ERROR ( ca ) && !IS_TYPE_ERROR ( cb ) ) {
-
 
1008
	report ( crt_loc, ERR_expr_mul_rem_op ( lex_rem, ta, tb ) ) ;
-
 
1009
    }
-
 
1010
    return ( make_error_exp ( 0 ) ) ;
1041
	return (make_error_exp(0));
1011
}
1042
}
1012
 
1043
 
1013
 
1044
 
1014
/*
1045
/*
1015
    CONSTRUCT AN ADDITION EXPRESSION
1046
    CONSTRUCT AN ADDITION EXPRESSION
1016
 
1047
 
1017
    This routine constructs the expression 'a + b'.
1048
    This routine constructs the expression 'a + b'.
1197
	/* Do bounds checks */
1140
	/* Do bounds checks */
1198
	if ( IS_exp_int_lit ( b ) && IS_type_array ( sa ) ) {
1141
	if (IS_exp_int_lit(b) && IS_type_array(sa)) {
1199
	    check_bounds ( op, sa, b ) ;
1142
		check_bounds(op, sa, b);
1200
	}
1143
	}
1201
 
1144
 
1202
	/* The pointer must be to a complete object type */
1145
	/* The pointer must be to a complete object type */
1203
	t = check_pointer ( ta, &err ) ;
1146
	t = check_pointer(ta, &err);
1204
	if ( !IS_NULL_err ( err ) ) {
1147
	if (!IS_NULL_err(err)) {
1205
	    err = concat_error ( err, ERR_expr_add_incompl ( op ) ) ;
1148
		err = concat_error(err, ERR_expr_add_incompl(op));
1206
	    report ( crt_loc, err ) ;
1149
		report(crt_loc, err);
1207
	}
1150
	}
1208
 
1151
 
1209
	/* Construct the result */
1152
	/* Construct the result */
1287
/*
1322
/*
1288
    CHECK FOR DUBIOUS SHIFT EXPRESSIONS
1323
    CHECK FOR DUBIOUS SHIFT EXPRESSIONS
1289
 
1324
 
1290
    This routine checks the shift operation 'a << b' or 'a >> b' for
1325
    This routine checks the shift operation 'a << b' or 'a >> b' for
1291
    dubious constant operands.  All the necessary operand and arithmetic
1326
    dubious constant operands.  All the necessary operand and arithmetic
1292
    type conversions have already been performed on a and b, and the type
1327
    type conversions have already been performed on a and b, and the type
1293
    of a is passed in as t.  The routine returns 1 if both operands are
1328
    of a is passed in as t.  The routine returns 1 if both operands are
1294
    integer constants.
1329
    integer constants.
1295
*/
1330
*/
1296
 
1331
 
1297
int check_shift_exp
1332
int
1298
    PROTO_N ( ( op, t, a, b ) )
-
 
1299
    PROTO_T ( int op X TYPE t X EXP a X EXP b )
1333
check_shift_exp(int op, TYPE t, EXP a, EXP b)
1300
{
1334
{
1301
    int ret = 1 ;
1335
	int ret = 1;
1302
    ERROR err = NULL_err ;
1336
	ERROR err = NULL_err;
1303
 
1337
 
1304
    /* Check first operand */
1338
	/* Check first operand */
1305
    if ( IS_exp_int_lit ( a ) ) {
1339
	if (IS_exp_int_lit(a)) {
1306
	NAT n = DEREF_nat ( exp_int_lit_nat ( a ) ) ;
1340
		NAT n = DEREF_nat(exp_int_lit_nat(a));
1307
	if ( is_negative_nat ( n ) ) {
1341
		if (is_negative_nat(n)) {
1308
	    err = ERR_expr_shift_op1_neg ( op, n ) ;
1342
			err = ERR_expr_shift_op1_neg(op, n);
1309
	}
1343
		}
1310
    } else {
1344
	} else {
1311
	if ( check_int_type ( t, btype_signed ) ) {
1345
		if (check_int_type(t, btype_signed)) {
1312
	    err = ERR_expr_shift_op1_sign ( op ) ;
1346
			err = ERR_expr_shift_op1_sign(op);
-
 
1347
		}
-
 
1348
		ret = 0;
1313
	}
1349
	}
-
 
1350
 
-
 
1351
	/* Check second operand */
-
 
1352
	if (IS_exp_int_lit(b)) {
-
 
1353
		NAT n = DEREF_nat(exp_int_lit_nat(b));
-
 
1354
		if (is_negative_nat(n)) {
-
 
1355
			err = concat_error(err, ERR_expr_shift_op2_neg(op, n));
-
 
1356
		} else if (check_type_size(t, n) >= 0) {
-
 
1357
			err = concat_error(err,
-
 
1358
					   ERR_expr_shift_op2_big(op, n, t));
-
 
1359
		}
-
 
1360
	} else {
1314
	ret = 0 ;
1361
		ret = 0;
1315
    }
1362
	}
1316
 
1363
 
1317
    /* Check second operand */
1364
	/* Report any accumulated errors */
1318
    if ( IS_exp_int_lit ( b ) ) {
1365
	if (!IS_NULL_err(err)) {
1319
	NAT n = DEREF_nat ( exp_int_lit_nat ( b ) ) ;
-
 
1320
	if ( is_negative_nat ( n ) ) {
1366
		report(crt_loc, err);
1321
	    err = concat_error ( err, ERR_expr_shift_op2_neg ( op, n ) ) ;
-
 
1322
	} else if ( check_type_size ( t, n ) >= 0 ) {
-
 
1323
	    err = concat_error ( err, ERR_expr_shift_op2_big ( op, n, t ) ) ;
-
 
1324
	}
1367
	}
1325
    } else {
-
 
1326
	ret = 0 ;
-
 
1327
    }
-
 
1328
 
-
 
1329
    /* Report any accumulated errors */
-
 
1330
    if ( !IS_NULL_err ( err ) ) report ( crt_loc, err ) ;
-
 
1331
    return ( ret ) ;
1368
	return (ret);
1332
}
1369
}
1333
 
1370
 
1334
 
1371
 
1335
/*
1372
/*
1336
    CONSTRUCT A SHIFT EXPRESSION
1373
    CONSTRUCT A SHIFT EXPRESSION
1337
 
1374
 
1338
    This routine constructs the expressions 'a << b' and 'a >> b'.  Note
1375
    This routine constructs the expressions 'a << b' and 'a >> b'.  Note
1339
    that this has a lower priority than plus and minus.
1376
    that this has a lower priority than plus and minus.
1340
*/
1377
*/
1341
 
1378
 
1342
EXP make_shift_exp
1379
EXP
1343
    PROTO_N ( ( op, a, b ) )
-
 
1344
    PROTO_T ( int op X EXP a X EXP b )
1380
make_shift_exp(int op, EXP a, EXP b)
1345
{
1381
{
1346
    EXP e ;
1382
	EXP e;
1347
    TYPE ta, tb ;
1383
	TYPE ta, tb;
1348
    unsigned ca, cb ;
1384
	unsigned ca, cb;
1349
 
1385
 
1350
    /* Check for non-obvious resolutions */
1386
	/* Check for non-obvious resolutions */
-
 
1387
	if (option(OPT_paren)) {
1351
    if ( option ( OPT_paren ) ) check_paren ( PAREN_PLUS, op, a, b ) ;
1388
		check_paren(PAREN_PLUS, op, a, b);
-
 
1389
	}
1352
 
1390
 
1353
    /* Do reference conversions */
1391
	/* Do reference conversions */
1354
    a = convert_reference ( a, REF_NORMAL ) ;
1392
	a = convert_reference(a, REF_NORMAL);
1355
    b = convert_reference ( b, REF_NORMAL ) ;
1393
	b = convert_reference(b, REF_NORMAL);
1356
 
1394
 
1357
    /* Find operand types */
1395
	/* Find operand types */
1358
    ta = DEREF_type ( exp_type ( a ) ) ;
1396
	ta = DEREF_type(exp_type(a));
1359
    tb = DEREF_type ( exp_type ( b ) ) ;
1397
	tb = DEREF_type(exp_type(b));
1360
    ca = type_category ( &ta ) ;
1398
	ca = type_category(&ta);
1361
    cb = type_category ( &tb ) ;
1399
	cb = type_category(&tb);
1362
 
1400
 
1363
    /* Check for overloading */
1401
	/* Check for overloading */
1364
#if LANGUAGE_CPP
1402
#if LANGUAGE_CPP
1365
    if ( IS_TYPE_OVERLOAD ( ca ) || IS_TYPE_OVERLOAD ( cb ) ) {
1403
	if (IS_TYPE_OVERLOAD(ca) || IS_TYPE_OVERLOAD(cb)) {
1366
	if ( overload_depth == 0 ) {
1404
		if (overload_depth == 0) {
1367
	    e = binary_overload ( op, a, b ) ;
1405
			e = binary_overload(op, a, b);
1368
	    return ( e ) ;
1406
			return (e);
-
 
1407
		}
1369
	}
1408
	}
1370
    }
-
 
1371
#endif
1409
#endif
1372
 
1410
 
1373
    /* Do lvalue conversions */
1411
	/* Do lvalue conversions */
1374
    if ( IS_TYPE_ADDRESS ( ca ) ) {
1412
	if (IS_TYPE_ADDRESS(ca)) {
1375
	a = convert_lvalue ( a ) ;
1413
		a = convert_lvalue(a);
1376
	ta = DEREF_type ( exp_type ( a ) ) ;
1414
		ta = DEREF_type(exp_type(a));
1377
	ca = type_category ( &ta ) ;
1415
		ca = type_category(&ta);
1378
    }
1416
	}
1379
    if ( IS_TYPE_ADDRESS ( cb ) ) {
1417
	if (IS_TYPE_ADDRESS(cb)) {
1380
	b = convert_lvalue ( b ) ;
1418
		b = convert_lvalue(b);
1381
	tb = DEREF_type ( exp_type ( b ) ) ;
1419
		tb = DEREF_type(exp_type(b));
1382
	cb = type_category ( &tb ) ;
1420
		cb = type_category(&tb);
1383
    }
1421
	}
1384
 
1422
 
1385
    /* Operands can be integral ... */
1423
	/* Operands can be integral ... */
1386
    if ( IS_TYPE_INT ( ca ) && IS_TYPE_INT ( cb ) ) {
1424
	if (IS_TYPE_INT(ca) && IS_TYPE_INT(cb)) {
1387
	unsigned tag ;
1425
		unsigned tag;
1388
	ERROR err = NULL_err ;
1426
		ERROR err = NULL_err;
1389
	TYPE pta = promote_type ( ta ) ;
1427
		TYPE pta = promote_type(ta);
1390
	TYPE ptb = promote_type ( tb ) ;
1428
		TYPE ptb = promote_type(tb);
1391
	a = convert_promote ( pta, a ) ;
1429
		a = convert_promote(pta, a);
1392
	b = convert_promote ( ptb, b ) ;
1430
		b = convert_promote(ptb, b);
1393
	tag = ( op == lex_lshift ? exp_lshift_tag : exp_rshift_tag ) ;
1431
		tag = (op == lex_lshift ? exp_lshift_tag : exp_rshift_tag);
1394
 
1432
 
1395
	/* Check for dubious shifts */
1433
		/* Check for dubious shifts */
1396
	if ( check_shift_exp ( op, pta, a, b ) ) {
1434
		if (check_shift_exp(op, pta, a, b)) {
1397
	    /* Allow for constant evaluation */
1435
			/* Allow for constant evaluation */
1398
	    if ( !IS_NULL_err ( err ) ) report ( crt_loc, err ) ;
1436
			if (!IS_NULL_err(err)) {
-
 
1437
				report(crt_loc, err);
-
 
1438
			}
1399
	    e = make_binary_nat ( tag, a, b ) ;
1439
			e = make_binary_nat(tag, a, b);
1400
	    return ( e ) ;
1440
			return (e);
1401
	}
1441
		}
1402
 
1442
 
1403
	/* Construct the result */
1443
		/* Construct the result */
1404
	MAKE_exp_plus_etc ( tag, pta, a, b, e ) ;
1444
		MAKE_exp_plus_etc(tag, pta, a, b, e);
1405
	return ( e ) ;
1445
		return (e);
1406
    }
1446
	}
1407
 
1447
 
1408
    /* ... and nothing else */
1448
	/* ... and nothing else */
1409
    if ( !IS_TYPE_ERROR ( ca ) && !IS_TYPE_ERROR ( cb ) ) {
1449
	if (!IS_TYPE_ERROR(ca) && !IS_TYPE_ERROR(cb)) {
1410
	report ( crt_loc, ERR_expr_shift_op ( op, ta, tb ) ) ;
1450
		report(crt_loc, ERR_expr_shift_op(op, ta, tb));
1411
    }
1451
	}
1412
    return ( make_error_exp ( 0 ) ) ;
1452
	return (make_error_exp(0));
1413
}
1453
}
1414
 
1454
 
1415
 
1455
 
1416
/*
1456
/*
1417
    CONSTRUCT A RELATIONAL OPERATOR
1457
    CONSTRUCT A RELATIONAL OPERATOR
1418
 
1458
 
1419
    This routine converts the lexical token op to a relational operator.
1459
    This routine converts the lexical token op to a relational operator.
1420
*/
1460
*/
1421
 
1461
 
1422
static NTEST make_ntest
1462
static NTEST
1423
    PROTO_N ( ( op ) )
-
 
1424
    PROTO_T ( int op )
1463
make_ntest(int op)
1425
{
1464
{
1426
    switch ( op ) {
1465
	switch (op) {
-
 
1466
	case lex_eq:
1427
	case lex_eq : return ( ntest_eq ) ;
1467
		return (ntest_eq);
-
 
1468
	case lex_not_Heq_H1:
1428
	case lex_not_Heq_H1 : return ( ntest_not_eq ) ;
1469
		return (ntest_not_eq);
-
 
1470
	case lex_less:
1429
	case lex_less : return ( ntest_less ) ;
1471
		return (ntest_less);
-
 
1472
	case lex_less_Heq:
1430
	case lex_less_Heq : return ( ntest_less_eq ) ;
1473
		return (ntest_less_eq);
-
 
1474
	case lex_greater:
1431
	case lex_greater : return ( ntest_greater ) ;
1475
		return (ntest_greater);
-
 
1476
	case lex_greater_Heq:
1432
	case lex_greater_Heq : return ( ntest_greater_eq ) ;
1477
		return (ntest_greater_eq);
1433
    }
1478
	}
1434
    return ( ntest_none ) ;
1479
	return (ntest_none);
1435
}
1480
}
1436
 
1481
 
1437
 
1482
 
1438
/*
1483
/*
1439
    CONSTRUCT A RELATIONAL EXPRESSION
1484
    CONSTRUCT A RELATIONAL EXPRESSION
1440
 
1485
 
1441
    This routine constructs the expressions 'a < b', 'a > b', 'a <= b' and
1486
    This routine constructs the expressions 'a < b', 'a > b', 'a <= b' and
1442
    'a >= b'.
1487
    'a >= b'.
1594
 
1645
 
1595
/*
1646
/*
1596
    CONSTRUCT AN EQUALITY EXPRESSION
1647
    CONSTRUCT AN EQUALITY EXPRESSION
1597
 
1648
 
1598
    This routine constructs the expressions 'a == b' and 'a != b'.
1649
    This routine constructs the expressions 'a == b' and 'a != b'.
1744
	}
1767
	}
-
 
1768
 
-
 
1769
#if LANGUAGE_CPP
-
 
1770
	/* ... or both pointers to members ... */
-
 
1771
	if (IS_TYPE_PTR_MEM(ca)) {
-
 
1772
		if (IS_TYPE_PTR_MEM(cb)) {
-
 
1773
			int suspect = 0;
-
 
1774
			TYPE t = ptr_mem_common_type(ta, tb, &suspect);
-
 
1775
			if (suspect == -1) {
-
 
1776
				/* Allow for template types */
-
 
1777
				MAKE_exp_op(type_bool, op, a, b, e);
-
 
1778
				return (e);
-
 
1779
			}
-
 
1780
			if (suspect == 2) {
-
 
1781
				ERROR err = ERR_basic_link_incompat(ta, tb);
-
 
1782
				err = concat_error(err, ERR_conv_mem_common());
-
 
1783
				err = concat_error(err, ERR_expr_eq_mptr(op));
-
 
1784
				report(crt_loc, err);
-
 
1785
			} else {
-
 
1786
				a = convert_ptr_mem_common(t, a, op, 1);
-
 
1787
				b = convert_ptr_mem_common(t, b, op, 2);
-
 
1788
			}
-
 
1789
			if (IS_exp_null(a)) {
-
 
1790
				/* Make null pointer the second argument */
-
 
1791
				EXP c = a;
-
 
1792
				a = b;
-
 
1793
				b = c;
-
 
1794
			}
-
 
1795
			tst = make_ntest(op);
-
 
1796
			MAKE_exp_compare(type_bool, tst, a, b, e);
-
 
1797
			return (e);
-
 
1798
		}
1745
	if ( IS_TYPE_INT ( cb ) ) {
1799
		if (IS_TYPE_INT(cb)) {
1746
	    /* Allow zero integer as a null pointer member */
1800
			/* Allow zero integer as a null pointer member */
1747
	    b = make_null_ptr ( b, ta ) ;
1801
			b = make_null_ptr(b, ta);
1748
	    if ( IS_NULL_exp ( b ) ) {
1802
			if (IS_NULL_exp(b)) {
-
 
1803
				report(crt_loc,
1749
		report ( crt_loc, ERR_expr_eq_nonzero ( op, ta, tb ) ) ;
1804
				       ERR_expr_eq_nonzero(op, ta, tb));
1750
		b = make_null_ptr ( NULL_exp, ta ) ;
1805
				b = make_null_ptr(NULL_exp, ta);
1751
	    }
1806
			}
1752
	    tst = make_ntest ( op ) ;
1807
			tst = make_ntest(op);
1753
	    MAKE_exp_compare ( type_bool, tst, a, b, e ) ;
1808
			MAKE_exp_compare(type_bool, tst, a, b, e);
-
 
1809
			return (e);
-
 
1810
		}
-
 
1811
	} else if (IS_TYPE_PTR_MEM(cb)) {
-
 
1812
		if (IS_TYPE_INT(ca)) {
-
 
1813
			/* Allow zero integer as a null pointer member */
-
 
1814
			a = make_null_ptr(a, tb);
-
 
1815
			if (IS_NULL_exp(a)) {
-
 
1816
				report(crt_loc,
-
 
1817
				       ERR_expr_eq_nonzero(op, tb, ta));
-
 
1818
				a = make_null_ptr(NULL_exp, tb);
-
 
1819
			}
-
 
1820
			tst = make_ntest(op);
-
 
1821
			MAKE_exp_compare(type_bool, tst, b, a, e);
1754
	    return ( e ) ;
1822
			return (e);
-
 
1823
		}
1755
	}
1824
	}
1756
    } else if ( IS_TYPE_PTR_MEM ( cb ) ) {
-
 
1757
	if ( IS_TYPE_INT ( ca ) ) {
-
 
1758
	    /* Allow zero integer as a null pointer member */
-
 
1759
	    a = make_null_ptr ( a, tb ) ;
-
 
1760
	    if ( IS_NULL_exp ( a ) ) {
-
 
1761
		report ( crt_loc, ERR_expr_eq_nonzero ( op, tb, ta ) ) ;
-
 
1762
		a = make_null_ptr ( NULL_exp, tb ) ;
-
 
1763
	    }
-
 
1764
	    tst = make_ntest ( op ) ;
-
 
1765
	    MAKE_exp_compare ( type_bool, tst, b, a, e ) ;
-
 
1766
	    return ( e ) ;
-
 
1767
	}
-
 
1768
    }
-
 
1769
#endif
1825
#endif
1770
 
1826
 
1771
    /* ... and nothing else */
1827
	/* ... and nothing else */
1772
    if ( !IS_TYPE_ERROR ( ca ) && !IS_TYPE_ERROR ( cb ) ) {
1828
	if (!IS_TYPE_ERROR(ca) && !IS_TYPE_ERROR(cb)) {
1773
	report ( crt_loc, ERR_expr_eq_op ( op, ta, tb ) ) ;
1829
		report(crt_loc, ERR_expr_eq_op(op, ta, tb));
1774
    }
1830
	}
1775
    tst = make_ntest ( op ) ;
1831
	tst = make_ntest(op);
1776
    MAKE_exp_compare ( type_bool, tst, a, b, e ) ;
1832
	MAKE_exp_compare(type_bool, tst, a, b, e);
1777
    return ( e ) ;
1833
	return (e);
1778
}
1834
}
1779
 
1835
 
1780
 
1836
 
1781
/*
1837
/*
1782
    CONSTRUCT A BIT EXPRESSION
1838
    CONSTRUCT A BIT EXPRESSION
1783
 
1839
 
1784
    This routine constructs the expressions 'a & b', 'a ^ b' and 'a | b'.
1840
    This routine constructs the expressions 'a & b', 'a ^ b' and 'a | b'.
1785
*/
1841
*/
1786
 
1842
 
1787
static EXP make_bit_exp
1843
static EXP
1788
    PROTO_N ( ( op, tag, a, b ) )
-
 
1789
    PROTO_T ( int op X unsigned tag X EXP a X EXP b )
1844
make_bit_exp(int op, unsigned tag, EXP a, EXP b)
1790
{
1845
{
1791
    EXP e ;
1846
	EXP e;
1792
    TYPE ta, tb ;
1847
	TYPE ta, tb;
1793
    unsigned ca, cb ;
1848
	unsigned ca, cb;
1794
 
-
 
1795
    /* Do reference conversions */
-
 
1796
    a = convert_reference ( a, REF_NORMAL ) ;
-
 
1797
    b = convert_reference ( b, REF_NORMAL ) ;
-
 
1798
 
1849
 
1799
    /* Find operand types */
1850
	/* Do reference conversions */
1800
    ta = DEREF_type ( exp_type ( a ) ) ;
1851
	a = convert_reference(a, REF_NORMAL);
1801
    tb = DEREF_type ( exp_type ( b ) ) ;
1852
	b = convert_reference(b, REF_NORMAL);
1802
    ca = type_category ( &ta ) ;
-
 
1803
    cb = type_category ( &tb ) ;
-
 
1804
 
1853
 
-
 
1854
	/* Find operand types */
-
 
1855
	ta = DEREF_type(exp_type(a));
-
 
1856
	tb = DEREF_type(exp_type(b));
-
 
1857
	ca = type_category(&ta);
-
 
1858
	cb = type_category(&tb);
-
 
1859
 
1805
    /* Check for overloading */
1860
	/* Check for overloading */
1806
#if LANGUAGE_CPP
1861
#if LANGUAGE_CPP
1807
    if ( IS_TYPE_OVERLOAD ( ca ) || IS_TYPE_OVERLOAD ( cb ) ) {
1862
	if (IS_TYPE_OVERLOAD(ca) || IS_TYPE_OVERLOAD(cb)) {
1808
	if ( overload_depth == 0 ) {
1863
		if (overload_depth == 0) {
1809
	    e = binary_overload ( op, a, b ) ;
1864
			e = binary_overload(op, a, b);
1810
	    return ( e ) ;
1865
			return (e);
-
 
1866
		}
1811
	}
1867
	}
1812
    }
-
 
1813
#endif
1868
#endif
1814
 
1869
 
1815
    /* Do lvalue conversions */
1870
	/* Do lvalue conversions */
1816
    if ( IS_TYPE_ADDRESS ( ca ) ) {
1871
	if (IS_TYPE_ADDRESS(ca)) {
1817
	a = convert_lvalue ( a ) ;
1872
		a = convert_lvalue(a);
1818
	ta = DEREF_type ( exp_type ( a ) ) ;
1873
		ta = DEREF_type(exp_type(a));
1819
	ca = type_category ( &ta ) ;
1874
		ca = type_category(&ta);
1820
    }
1875
	}
1821
    if ( IS_TYPE_ADDRESS ( cb ) ) {
1876
	if (IS_TYPE_ADDRESS(cb)) {
1822
	b = convert_lvalue ( b ) ;
1877
		b = convert_lvalue(b);
1823
	tb = DEREF_type ( exp_type ( b ) ) ;
1878
		tb = DEREF_type(exp_type(b));
1824
	cb = type_category ( &tb ) ;
1879
		cb = type_category(&tb);
1825
    }
1880
	}
1826
 
1881
 
1827
    /* Operands can both be integral ... */
1882
	/* Operands can both be integral ... */
1828
    if ( IS_TYPE_INT ( ca ) && IS_TYPE_INT ( cb ) ) {
1883
	if (IS_TYPE_INT(ca) && IS_TYPE_INT(cb)) {
1829
	TYPE t = arith_type ( ta, tb, a, b ) ;
1884
		TYPE t = arith_type(ta, tb, a, b);
1830
	a = convert_arith ( t, a, op, 1 ) ;
1885
		a = convert_arith(t, a, op, 1);
1831
	b = convert_arith ( t, b, op, 2 ) ;
1886
		b = convert_arith(t, b, op, 2);
1832
	if ( IS_exp_int_lit ( a ) && IS_exp_int_lit ( b ) ) {
1887
		if (IS_exp_int_lit(a) && IS_exp_int_lit(b)) {
1833
	    e = make_binary_nat ( tag, a, b ) ;
1888
			e = make_binary_nat(tag, a, b);
1834
	} else {
1889
		} else {
1835
	    MAKE_exp_plus_etc ( tag, t, a, b, e ) ;
1890
			MAKE_exp_plus_etc(tag, t, a, b, e);
1836
	}
1891
		}
1837
	return ( e ) ;
1892
		return (e);
1838
    }
-
 
1839
 
-
 
1840
    /* ... and nothing else */
-
 
1841
    if ( !IS_TYPE_ERROR ( ca ) && !IS_TYPE_ERROR ( cb ) ) {
-
 
1842
	switch ( tag ) {
-
 
1843
	    case exp_and_tag : {
-
 
1844
		report ( crt_loc, ERR_expr_bit_and_op ( op, ta, tb ) ) ;
-
 
1845
		break ;
-
 
1846
	    }
-
 
1847
	    case exp_or_tag : {
-
 
1848
		report ( crt_loc, ERR_expr_or_op ( op, ta, tb ) ) ;
-
 
1849
		break ;
-
 
1850
	    }
-
 
1851
	    case exp_xor_tag : {
-
 
1852
		report ( crt_loc, ERR_expr_xor_op ( op, ta, tb ) ) ;
-
 
1853
		break ;
-
 
1854
	    }
-
 
1855
	}
1893
	}
-
 
1894
 
-
 
1895
	/* ... and nothing else */
-
 
1896
	if (!IS_TYPE_ERROR(ca) && !IS_TYPE_ERROR(cb)) {
-
 
1897
		switch (tag) {
-
 
1898
		case exp_and_tag: {
-
 
1899
			report(crt_loc, ERR_expr_bit_and_op(op, ta, tb));
-
 
1900
			break;
1856
    }
1901
		}
-
 
1902
		case exp_or_tag: {
-
 
1903
			report(crt_loc, ERR_expr_or_op(op, ta, tb));
-
 
1904
			break;
-
 
1905
		}
-
 
1906
		case exp_xor_tag: {
-
 
1907
			report(crt_loc, ERR_expr_xor_op(op, ta, tb));
-
 
1908
			break;
-
 
1909
		}
-
 
1910
		}
-
 
1911
	}
1857
    return ( make_error_exp ( 0 ) ) ;
1912
	return (make_error_exp(0));
1858
}
1913
}
1859
 
1914
 
1860
 
1915
 
1861
/*
1916
/*
1862
    CONSTRUCT A BITWISE AND EXPRESSION
1917
    CONSTRUCT A BITWISE AND EXPRESSION
1863
 
1918
 
1864
    This routine constructs the expression 'a & b'.  Note that this
1919
    This routine constructs the expression 'a & b'.  Note that this
1865
    has lower priority than plus or minus and the equality operators.
1920
    has lower priority than plus or minus and the equality operators.
1866
*/
1921
*/
1867
 
1922
 
1868
EXP make_and_exp
1923
EXP
1869
    PROTO_N ( ( a, b ) )
-
 
1870
    PROTO_T ( EXP a X EXP b )
1924
make_and_exp(EXP a, EXP b)
1871
{
1925
{
1872
    EXP e ;
1926
	EXP e;
1873
    int op = lex_and_H1 ;
1927
	int op = lex_and_H1;
-
 
1928
	if (option(OPT_paren)) {
1874
    if ( option ( OPT_paren ) ) check_paren ( PAREN_EQUALITY, op, a, b ) ;
1929
		check_paren(PAREN_EQUALITY, op, a, b);
-
 
1930
	}
1875
    e = make_bit_exp ( op, exp_and_tag, a, b ) ;
1931
	e = make_bit_exp(op, exp_and_tag, a, b);
1876
    return ( e ) ;
1932
	return (e);
1877
}
1933
}
1878
 
1934
 
1879
 
1935
 
1880
/*
1936
/*
1881
    CONSTRUCT A BITWISE XOR EXPRESSION
1937
    CONSTRUCT A BITWISE XOR EXPRESSION
1882
 
1938
 
1883
    This routine constructs the expression 'a ^ b'.  Note that this has
1939
    This routine constructs the expression 'a ^ b'.  Note that this has
1884
    a lower priority than bitwise and, plus and minus.
1940
    a lower priority than bitwise and, plus and minus.
1885
*/
1941
*/
1886
 
1942
 
1887
EXP make_xor_exp
1943
EXP
1888
    PROTO_N ( ( a, b ) )
-
 
1889
    PROTO_T ( EXP a X EXP b )
1944
make_xor_exp(EXP a, EXP b)
1890
{
1945
{
1891
    EXP e ;
1946
	EXP e;
1892
    int op = lex_xor_H1 ;
1947
	int op = lex_xor_H1;
-
 
1948
	if (option(OPT_paren)) {
1893
    if ( option ( OPT_paren ) ) check_paren ( PAREN_AND, op, a, b ) ;
1949
		check_paren(PAREN_AND, op, a, b);
-
 
1950
	}
1894
    e = make_bit_exp ( op, exp_xor_tag, a, b ) ;
1951
	e = make_bit_exp(op, exp_xor_tag, a, b);
1895
    return ( e ) ;
1952
	return (e);
1896
}
1953
}
1897
 
1954
 
1898
 
1955
 
1899
/*
1956
/*
1900
    CONSTRUCT A BITWISE OR EXPRESSION
1957
    CONSTRUCT A BITWISE OR EXPRESSION
1901
 
1958
 
1902
    This routine constructs the expression 'a | b'.  Note that this has
1959
    This routine constructs the expression 'a | b'.  Note that this has
1903
    a lower priority than bitwise and, bitwise xor, plus and minus.
1960
    a lower priority than bitwise and, bitwise xor, plus and minus.
1904
*/
1961
*/
1905
 
-
 
1906
EXP make_or_exp
-
 
1907
    PROTO_N ( ( a, b ) )
-
 
1908
    PROTO_T ( EXP a X EXP b )
-
 
1909
{
-
 
1910
    EXP e ;
-
 
1911
    int op = lex_or_H1 ;
-
 
1912
    if ( option ( OPT_paren ) ) check_paren ( PAREN_XOR, op, a, b ) ;
-
 
1913
    e = make_bit_exp ( op, exp_or_tag, a, b ) ;
-
 
1914
    return ( e ) ;
-
 
1915
}
-
 
1916
 
1962
 
1917
 
-
 
1918
/*
-
 
1919
    CONSTRUCT A LOGICAL EXPRESSION
-
 
1920
 
-
 
1921
    This routine constructs the expressions 'a && b' and 'a || b'.
-
 
1922
*/
1963
EXP
1923
 
-
 
1924
static EXP make_logic_exp
-
 
1925
    PROTO_N ( ( op, tag, a, b ) )
1964
make_or_exp(EXP a, EXP b)
1926
    PROTO_T ( int op X unsigned tag X EXP a X EXP b )
-
 
1927
{
1965
{
1928
    EXP e ;
1966
	EXP e;
1929
    TYPE ta, tb ;
1967
	int op = lex_or_H1;
1930
    unsigned ca, cb ;
1968
	if (option(OPT_paren)) {
1931
    ERROR err = NULL_err ;
1969
		check_paren(PAREN_XOR, op, a, b);
-
 
1970
	}
1932
    unsigned taga = TAG_exp ( a ) ;
1971
	e = make_bit_exp(op, exp_or_tag, a, b);
1933
    unsigned tagb = TAG_exp ( b ) ;
1972
	return (e);
-
 
1973
}
-
 
1974
 
1934
 
1975
 
1935
    /* Do reference conversions */
-
 
1936
    a = convert_reference ( a, REF_NORMAL ) ;
-
 
1937
    b = convert_reference ( b, REF_NORMAL ) ;
-
 
1938
 
1976
/*
1939
    /* Find operand types */
-
 
1940
    ta = DEREF_type ( exp_type ( a ) ) ;
-
 
1941
    tb = DEREF_type ( exp_type ( b ) ) ;
-
 
1942
    ca = type_category ( &ta ) ;
-
 
1943
    cb = type_category ( &tb ) ;
1977
    CONSTRUCT A LOGICAL EXPRESSION
1944
 
1978
 
-
 
1979
    This routine constructs the expressions 'a && b' and 'a || b'.
-
 
1980
*/
-
 
1981
 
-
 
1982
static EXP
-
 
1983
make_logic_exp(int op, unsigned tag, EXP a, EXP b)
-
 
1984
{
-
 
1985
	EXP e;
-
 
1986
	TYPE ta, tb;
-
 
1987
	unsigned ca, cb;
-
 
1988
	ERROR err = NULL_err;
-
 
1989
	unsigned taga = TAG_exp(a);
-
 
1990
	unsigned tagb = TAG_exp(b);
-
 
1991
 
-
 
1992
	/* Do reference conversions */
-
 
1993
	a = convert_reference(a, REF_NORMAL);
-
 
1994
	b = convert_reference(b, REF_NORMAL);
-
 
1995
 
-
 
1996
	/* Find operand types */
-
 
1997
	ta = DEREF_type(exp_type(a));
-
 
1998
	tb = DEREF_type(exp_type(b));
-
 
1999
	ca = type_category(&ta);
-
 
2000
	cb = type_category(&tb);
-
 
2001
 
1945
    /* Check for overloading */
2002
	/* Check for overloading */
1946
#if LANGUAGE_CPP
2003
#if LANGUAGE_CPP
1947
    if ( IS_TYPE_OVERLOAD ( ca ) || IS_TYPE_OVERLOAD ( cb ) ) {
2004
	if (IS_TYPE_OVERLOAD(ca) || IS_TYPE_OVERLOAD(cb)) {
1948
	if ( overload_depth == 0 ) {
2005
		if (overload_depth == 0) {
1949
	    e = binary_overload ( op, a, b ) ;
2006
			e = binary_overload(op, a, b);
1950
	    return ( e ) ;
2007
			return (e);
-
 
2008
		}
1951
	}
2009
	}
1952
    }
-
 
1953
#endif
2010
#endif
1954
 
2011
 
1955
    /* Do lvalue conversions */
2012
	/* Do lvalue conversions */
1956
    if ( IS_TYPE_ADDRESS ( ca ) ) a = convert_lvalue ( a ) ;
2013
	if (IS_TYPE_ADDRESS(ca)) {
-
 
2014
		a = convert_lvalue(a);
-
 
2015
	}
1957
    if ( IS_TYPE_ADDRESS ( cb ) ) b = convert_lvalue ( b ) ;
2016
	if (IS_TYPE_ADDRESS(cb)) {
-
 
2017
		b = convert_lvalue(b);
-
 
2018
	}
1958
 
2019
 
1959
    /* Convert first operand to a boolean */
2020
	/* Convert first operand to a boolean */
1960
    a = convert_boolean ( a, taga, &err ) ;
2021
	a = convert_boolean(a, taga, &err);
-
 
2022
	if (!IS_NULL_err(err)) {
-
 
2023
		ERROR err2;
-
 
2024
		if (tag == exp_log_and_tag) {
-
 
2025
			err2 = ERR_expr_log_and_op(op);
-
 
2026
		} else {
-
 
2027
			err2 = ERR_expr_log_or_op(op);
-
 
2028
		}
-
 
2029
		err = concat_error(err, err2);
-
 
2030
		report(crt_loc, err);
-
 
2031
		err = NULL_err;
-
 
2032
	}
-
 
2033
 
-
 
2034
	/* Convert second operand to a boolean */
-
 
2035
	b = convert_boolean(b, tagb, &err);
1961
    if ( !IS_NULL_err ( err ) ) {
2036
	if (!IS_NULL_err(err)) {
1962
	ERROR err2 ;
2037
		ERROR err2;
1963
	if ( tag == exp_log_and_tag ) {
2038
		if (tag == exp_log_and_tag) {
1964
	    err2 = ERR_expr_log_and_op ( op ) ;
2039
			err2 = ERR_expr_log_and_op(op);
1965
	} else {
2040
		} else {
1966
	    err2 = ERR_expr_log_or_op ( op ) ;
2041
			err2 = ERR_expr_log_or_op(op);
-
 
2042
		}
-
 
2043
		err = concat_error(err, err2);
-
 
2044
		report(crt_loc, err);
1967
	}
2045
	}
1968
	err = concat_error ( err, err2 ) ;
-
 
1969
	report ( crt_loc, err ) ;
-
 
1970
	err = NULL_err ;
-
 
1971
    }
-
 
1972
 
2046
 
1973
    /* Convert second operand to a boolean */
2047
	/* Construct the result */
1974
    b = convert_boolean ( b, tagb, &err ) ;
-
 
1975
    if ( !IS_NULL_err ( err ) ) {
-
 
1976
	ERROR err2 ;
-
 
1977
	if ( tag == exp_log_and_tag ) {
2048
	if (IS_exp_int_lit(a) && IS_exp_int_lit(b)) {
1978
	    err2 = ERR_expr_log_and_op ( op ) ;
2049
		e = make_binary_nat(tag, a, b);
1979
	} else {
2050
	} else {
1980
	    err2 = ERR_expr_log_or_op ( op ) ;
2051
		MAKE_exp_plus_etc(tag, type_bool, a, b, e);
1981
	}
2052
	}
1982
	err = concat_error ( err, err2 ) ;
-
 
1983
	report ( crt_loc, err ) ;
-
 
1984
    }
-
 
1985
 
-
 
1986
    /* Construct the result */
-
 
1987
    if ( IS_exp_int_lit ( a ) && IS_exp_int_lit ( b ) ) {
-
 
1988
	e = make_binary_nat ( tag, a, b ) ;
-
 
1989
    } else {
-
 
1990
	MAKE_exp_plus_etc ( tag, type_bool, a, b, e ) ;
-
 
1991
    }
-
 
1992
    return ( e ) ;
2053
	return (e);
1993
}
2054
}
1994
 
2055
 
1995
 
2056
 
1996
/*
2057
/*
1997
    CONSTRUCT A LOGICAL AND EXPRESSION
2058
    CONSTRUCT A LOGICAL AND EXPRESSION
1998
 
2059
 
1999
    This routine constructs the expression 'a && b'.
2060
    This routine constructs the expression 'a && b'.
2000
*/
2061
*/
2001
 
2062
 
2002
EXP make_log_and_exp
2063
EXP
2003
    PROTO_N ( ( a, b ) )
-
 
2004
    PROTO_T ( EXP a X EXP b )
2064
make_log_and_exp(EXP a, EXP b)
2005
{
2065
{
2006
    EXP e ;
2066
	EXP e;
2007
    e = make_logic_exp ( lex_logical_Hand_H1, exp_log_and_tag, a, b ) ;
2067
	e = make_logic_exp(lex_logical_Hand_H1, exp_log_and_tag, a, b);
2008
    return ( e ) ;
2068
	return (e);
2009
}
2069
}
2010
 
2070
 
2011
 
2071
 
2012
/*
2072
/*
2013
    CONSTRUCT A LOGICAL OR EXPRESSION
2073
    CONSTRUCT A LOGICAL OR EXPRESSION
2014
 
2074
 
2015
    This routine constructs the expression 'a || b'.  Note that this
2075
    This routine constructs the expression 'a || b'.  Note that this
2016
    has a lower priority than logical and.
2076
    has a lower priority than logical and.
2017
*/
2077
*/
2018
 
2078
 
2019
EXP make_log_or_exp
2079
EXP
2020
    PROTO_N ( ( a, b ) )
-
 
2021
    PROTO_T ( EXP a X EXP b )
2080
make_log_or_exp(EXP a, EXP b)
2022
{
2081
{
2023
    EXP e ;
2082
	EXP e;
2024
    if ( option ( OPT_paren ) ) check_logic ( a, b ) ;
2083
	if (option(OPT_paren)) {
-
 
2084
		check_logic(a, b);
-
 
2085
	}
2025
    e = make_logic_exp ( lex_logical_Hor_H1, exp_log_or_tag, a, b ) ;
2086
	e = make_logic_exp(lex_logical_Hor_H1, exp_log_or_tag, a, b);
2026
    return ( e ) ;
2087
	return (e);
2027
}
2088
}
2028
 
2089
 
2029
 
2090
 
2030
/*
2091
/*
2031
    CONSTRUCT A TEMPLATE DEPENDENT CONDITIONAL EXPRESSION
2092
    CONSTRUCT A TEMPLATE DEPENDENT CONDITIONAL EXPRESSION
2032
 
2093
 
2033
    This routine constructs the expression 'a ? b : c' where one of b
2094
    This routine constructs the expression 'a ? b : c' where one of b
2034
    and c depends on a template parameter.
2095
    and c depends on a template parameter.
2035
*/
2096
*/
2036
 
2097
 
2037
#if LANGUAGE_CPP
2098
#if LANGUAGE_CPP
2038
 
2099
 
2039
static EXP make_templ_cond
2100
static EXP
2040
    PROTO_N ( ( a, b, c ) )
-
 
2041
    PROTO_T ( EXP a X EXP b X EXP c )
2101
make_templ_cond(EXP a, EXP b, EXP c)
2042
{
2102
{
2043
    EXP e ;
2103
	EXP e;
2044
    TYPE t = type_templ_param ;
2104
	TYPE t = type_templ_param;
2045
    LIST ( EXP ) p = NULL_list ( EXP ) ;
2105
	LIST(EXP)p = NULL_list(EXP);
2046
    CONS_exp ( c, p, p ) ;
2106
	CONS_exp(c, p, p);
2047
    CONS_exp ( b, p, p ) ;
2107
	CONS_exp(b, p, p);
2048
    CONS_exp ( a, p, p ) ;
2108
	CONS_exp(a, p, p);
2049
    MAKE_exp_opn ( t, lex_cond_Hop, p, e ) ;
2109
	MAKE_exp_opn(t, lex_cond_Hop, p, e);
2050
    return ( e ) ;
2110
	return (e);
2051
}
2111
}
2052
 
2112
 
2053
#endif
2113
#endif
2054
 
2114
 
2055
 
2115
 
Line 2058... Line 2118...
2058
 
2118
 
2059
    This routine is used to turn the throw expression a into an expression
2119
    This routine is used to turn the throw expression a into an expression
2060
    of type t.  This is required so that a conditional involving a throw
2120
    of type t.  This is required so that a conditional involving a throw
2061
    expression satisfies the shape requirements of a TDF conditional
2121
    expression satisfies the shape requirements of a TDF conditional
2062
    construct.
2122
    construct.
2063
*/
2123
*/
2064
 
2124
 
2065
static EXP make_except_value
2125
static EXP
2066
    PROTO_N ( ( t, a ) )
-
 
2067
    PROTO_T ( TYPE t X EXP a )
2126
make_except_value(TYPE t, EXP a)
2068
{
2127
{
2069
    if ( !IS_type_top_etc ( t ) ) {
2128
	if (!IS_type_top_etc(t)) {
2070
	EXP b ;
2129
		EXP b;
2071
	MAKE_exp_value ( t, b ) ;
2130
		MAKE_exp_value(t, b);
2072
	a = join_exp ( a, b ) ;
2131
		a = join_exp(a, b);
2073
    }
2132
	}
2074
    return ( a ) ;
2133
	return (a);
2075
}
2134
}
2076
 
2135
 
2077
 
2136
 
2078
/*
2137
/*
2079
    CONSTRUCT A CONDITIONAL EXPRESSION
2138
    CONSTRUCT A CONDITIONAL EXPRESSION
2080
 
2139
 
2081
    This routine constructs the expression 'a ? b : c'.  Although '?:'
2140
    This routine constructs the expression 'a ? b : c'.  Although '?:'
2082
    cannot be overloaded, user-defined conversions which bring the second
2141
    cannot be overloaded, user-defined conversions which bring the second
2083
    and third operands to a common type are considered.  This is done
2142
    and third operands to a common type are considered.  This is done
2084
    using a dummy binary operation 'b : c' given by 'NULL_exp ? b : c'.
2143
    using a dummy binary operation 'b : c' given by 'NULL_exp ? b : c'.
2351
 
2412
 
2352
 
2413
 
2353
/*
2414
/*
2354
    JOIN TWO EXPRESSIONS
2415
    JOIN TWO EXPRESSIONS
2355
 
2416
 
2356
    This routine joins the expressions a and b by forming a comma
2417
    This routine joins the expressions a and b by forming a comma
2357
    expression, 'a, b'.
2418
    expression, 'a, b'.
2358
*/
2419
*/
2359
 
2420
 
2360
EXP join_exp
2421
EXP
2361
    PROTO_N ( ( a, b ) )
-
 
2362
    PROTO_T ( EXP a X EXP b )
2422
join_exp(EXP a, EXP b)
2363
{
2423
{
2364
    EXP e ;
2424
	EXP e;
2365
    TYPE t ;
2425
	TYPE t;
2366
    LIST ( EXP ) p ;
2426
	LIST(EXP)p;
2367
    if ( IS_NULL_exp ( a ) ) return ( b ) ;
2427
	if (IS_NULL_exp(a)) {
-
 
2428
		return (b);
-
 
2429
	}
2368
    if ( IS_NULL_exp ( b ) ) return ( a ) ;
2430
	if (IS_NULL_exp(b)) {
-
 
2431
		return (a);
-
 
2432
	}
2369
    CONS_exp ( b, NULL_list ( EXP ), p ) ;
2433
	CONS_exp(b, NULL_list(EXP), p);
2370
    CONS_exp ( a, p, p ) ;
2434
	CONS_exp(a, p, p);
2371
    t = DEREF_type ( exp_type ( b ) ) ;
2435
	t = DEREF_type(exp_type(b));
2372
    MAKE_exp_comma ( t, p, e ) ;
2436
	MAKE_exp_comma(t, p, e);
2373
    return ( e ) ;
2437
	return (e);
2374
}
2438
}
2375
 
2439
 
2376
 
2440
 
2377
/*
2441
/*
2378
    CONSTRUCT A SIMPLE COMMA EXPRESSION
2442
    CONSTRUCT A SIMPLE COMMA EXPRESSION
2379
 
2443
 
2380
    This routine constructs the simple comma expression 'a, b'.  If started
2444
    This routine constructs the simple comma expression 'a, b'.  If started
2381
    is true and a is itself a comma expression then b is added to the end
2445
    is true and a is itself a comma expression then b is added to the end
2382
    of a.  Otherwise a new comma expression is created.  Note that discard
2446
    of a.  Otherwise a new comma expression is created.  Note that discard
2383
    analysis is applied to a, and unreached code analysis to b.
2447
    analysis is applied to a, and unreached code analysis to b.
2384
*/
2448
*/
2385
 
2449
 
2386
static EXP make_comma_simple
2450
static EXP
2387
    PROTO_N ( ( a, b, started ) )
-
 
2388
    PROTO_T ( EXP a X EXP b X int started )
2451
make_comma_simple(EXP a, EXP b, int started)
2389
{
2452
{
2390
    EXP e ;
2453
	EXP e;
2391
    int uc ;
2454
	int uc;
2392
    TYPE ta, tb ;
2455
	TYPE ta, tb;
2393
#if LANGUAGE_CPP
2456
#if LANGUAGE_CPP
2394
    unsigned ca, cb ;
2457
	unsigned ca, cb;
2395
#endif
2458
#endif
2396
 
2459
 
2397
    /* Do reference conversions */
2460
	/* Do reference conversions */
2398
    a = convert_reference ( a, REF_NORMAL ) ;
2461
	a = convert_reference(a, REF_NORMAL);
2399
    b = convert_reference ( b, REF_NORMAL ) ;
2462
	b = convert_reference(b, REF_NORMAL);
2400
 
2463
 
2401
    /* Find operand types */
2464
	/* Find operand types */
2402
#if LANGUAGE_CPP
2465
#if LANGUAGE_CPP
2403
    ta = DEREF_type ( exp_type ( a ) ) ;
2466
	ta = DEREF_type(exp_type(a));
2404
    tb = DEREF_type ( exp_type ( b ) ) ;
2467
	tb = DEREF_type(exp_type(b));
2405
    ca = type_category ( &ta ) ;
2468
	ca = type_category(&ta);
2406
    cb = type_category ( &tb ) ;
2469
	cb = type_category(&tb);
2407
 
-
 
2408
    /* Check for overloading */
-
 
2409
    if ( IS_TYPE_OVERLOAD ( ca ) || IS_TYPE_OVERLOAD ( cb ) ) {
-
 
2410
	if ( overload_depth == 0 ) {
-
 
2411
	    e = binary_overload ( lex_comma, a, b ) ;
-
 
2412
	    if ( !IS_NULL_exp ( e ) ) return ( e ) ;
-
 
2413
	}
-
 
2414
	/* Continue if not overloaded */
-
 
2415
    }
-
 
2416
#endif
-
 
2417
 
-
 
2418
    /* Do discard analysis on first operand */
-
 
2419
    uc = unreached_code ;
-
 
2420
    a = make_exp_stmt ( a ) ;
-
 
2421
    ta = DEREF_type ( exp_type ( a ) ) ;
-
 
2422
    if ( IS_type_bottom ( ta ) ) {
-
 
2423
	if ( !unreached_last ) {
-
 
2424
	    /* Report unreached code */
-
 
2425
            report ( crt_loc, ERR_stmt_stmt_unreach () ) ;
-
 
2426
            unreached_last = 1 ;
-
 
2427
        }
-
 
2428
    }
-
 
2429
    unreached_code = uc ;
-
 
2430
 
2470
 
-
 
2471
	/* Check for overloading */
-
 
2472
	if (IS_TYPE_OVERLOAD(ca) || IS_TYPE_OVERLOAD(cb)) {
-
 
2473
		if (overload_depth == 0) {
-
 
2474
			e = binary_overload(lex_comma, a, b);
-
 
2475
			if (!IS_NULL_exp(e)) {
-
 
2476
				return (e);
-
 
2477
			}
-
 
2478
		}
-
 
2479
		/* Continue if not overloaded */
-
 
2480
	}
-
 
2481
#endif
-
 
2482
 
-
 
2483
	/* Do discard analysis on first operand */
-
 
2484
	uc = unreached_code;
-
 
2485
	a = make_exp_stmt(a);
-
 
2486
	ta = DEREF_type(exp_type(a));
-
 
2487
	if (IS_type_bottom(ta)) {
-
 
2488
		if (!unreached_last) {
-
 
2489
			/* Report unreached code */
-
 
2490
			report(crt_loc, ERR_stmt_stmt_unreach());
-
 
2491
			unreached_last = 1;
-
 
2492
		}
-
 
2493
	}
-
 
2494
	unreached_code = uc;
-
 
2495
 
2431
    /* Check second operand */
2496
	/* Check second operand */
2432
#if LANGUAGE_C
2497
#if LANGUAGE_C
2433
    b = convert_lvalue ( b ) ;
2498
	b = convert_lvalue(b);
2434
#endif
2499
#endif
2435
    b = convert_none ( b ) ;
2500
	b = convert_none(b);
2436
    tb = DEREF_type ( exp_type ( b ) ) ;
2501
	tb = DEREF_type(exp_type(b));
2437
 
2502
 
2438
    /* Construct the result */
2503
	/* Construct the result */
2439
    if ( started && IS_exp_comma ( a ) ) {
2504
	if (started && IS_exp_comma(a)) {
2440
	LIST ( EXP ) q ;
2505
		LIST(EXP)q;
2441
	LIST ( EXP ) p = DEREF_list ( exp_comma_args ( a ) ) ;
2506
		LIST(EXP)p = DEREF_list(exp_comma_args(a));
2442
	CONS_exp ( b, NULL_list ( EXP ), q ) ;
2507
		CONS_exp(b, NULL_list(EXP), q);
2443
	p = APPEND_list ( p, q ) ;
2508
		p = APPEND_list(p, q);
2444
	COPY_list ( exp_comma_args ( a ), p ) ;
2509
		COPY_list(exp_comma_args(a), p);
2445
	COPY_type ( exp_type ( a ), tb ) ;
2510
		COPY_type(exp_type(a), tb);
2446
	e = a ;
2511
		e = a;
2447
    } else {
2512
	} else {
2448
	LIST ( EXP ) p ;
2513
		LIST(EXP)p;
2449
	CONS_exp ( b, NULL_list ( EXP ), p ) ;
2514
		CONS_exp(b, NULL_list(EXP), p);
2450
	CONS_exp ( a, p, p ) ;
2515
		CONS_exp(a, p, p);
2451
	MAKE_exp_comma ( tb, p, e ) ;
2516
		MAKE_exp_comma(tb, p, e);
2452
    }
2517
	}
2453
    return ( e ) ;
2518
	return (e);
2454
}
2519
}
2455
 
2520
 
2456
 
2521
 
2457
/*
2522
/*
2458
    CONSTRUCT A COMMA EXPRESSION
2523
    CONSTRUCT A COMMA EXPRESSION
Line 2460... Line 2525...
2460
    This routine constructs the n-ary comma expression 'p1, p2, ..., pn' for
2525
    This routine constructs the n-ary comma expression 'p1, p2, ..., pn' for
2461
    the expression list p = ( p1, p2, ..., pn ).  Note that this groups from
2526
    the expression list p = ( p1, p2, ..., pn ).  Note that this groups from
2462
    left to right as '( ( ... ( p1, p2 ), ... ), pn )'.
2527
    left to right as '( ( ... ( p1, p2 ), ... ), pn )'.
2463
*/
2528
*/
2464
 
2529
 
2465
EXP make_comma_exp
2530
EXP
2466
    PROTO_N ( ( p ) )
-
 
2467
    PROTO_T ( LIST ( EXP ) p )
2531
make_comma_exp(LIST(EXP)p)
2468
{
2532
{
2469
    EXP e ;
2533
	EXP e;
2470
    if ( IS_NULL_list ( p ) ) {
2534
	if (IS_NULL_list(p)) {
2471
	/* This shouldn't happen */
2535
		/* This shouldn't happen */
2472
	e = make_error_exp ( LANGUAGE_CPP ) ;
2536
		e = make_error_exp(LANGUAGE_CPP);
2473
    } else {
2537
	} else {
2474
	int started = 0 ;
2538
		int started = 0;
2475
	DESTROY_CONS_exp ( destroy, e, p, p ) ;
2539
		DESTROY_CONS_exp(destroy, e, p, p);
2476
	while ( !IS_NULL_list ( p ) ) {
2540
		while (!IS_NULL_list(p)) {
2477
	    EXP a ;
2541
			EXP a;
2478
	    DESTROY_CONS_exp ( destroy, a, p, p ) ;
2542
			DESTROY_CONS_exp(destroy, a, p, p);
2479
	    e = make_comma_simple ( e, a, started ) ;
2543
			e = make_comma_simple(e, a, started);
2480
	    started = 1 ;
2544
			started = 1;
2481
	}
2545
		}
2482
	if ( !started ) {
2546
		if (!started) {
2483
	    /* This shouldn't happen */
2547
			/* This shouldn't happen */
2484
	    e = convert_reference ( e, REF_NORMAL ) ;
2548
			e = convert_reference(e, REF_NORMAL);
-
 
2549
		}
2485
	}
2550
	}
2486
    }
-
 
2487
    return ( e ) ;
2551
	return (e);
2488
}
2552
}