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 – /branches/tendra5/src/producers/common/construct/cast.c – Rev 5 and 6

Subversion Repositories tendra.SVN

Rev

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

Rev 5 Rev 6
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
32
    		 Crown Copyright (c) 1997
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 66... Line 96...
66
#include "template.h"
96
#include "template.h"
67
#include "tok.h"
97
#include "tok.h"
68
#include "tokdef.h"
98
#include "tokdef.h"
69
#include "token.h"
99
#include "token.h"
70
#include "typeid.h"
100
#include "typeid.h"
71
 
101
 
72
 
102
 
73
/*
103
/*
74
    CREATE AN EXACT CAST EXPRESSION
104
    CREATE AN EXACT CAST EXPRESSION
75
 
105
 
76
    This routine introduces a dummy cast expression which converts the
106
    This routine introduces a dummy cast expression which converts the
77
    expression a to its own type t.  This is needed in a couple of places
107
    expression a to its own type t.  This is needed in a couple of places
78
    where it is necessary to recognise cast expressions.
108
    where it is necessary to recognise cast expressions.
79
*/
109
*/
80
 
110
 
81
static EXP cast_exact
111
static EXP
82
    PROTO_N ( ( t, a ) )
-
 
83
    PROTO_T ( TYPE t X EXP a )
112
cast_exact(TYPE t, EXP a)
84
{
113
{
85
    EXP e ;
114
	EXP e;
86
    if ( IS_exp_cast ( a ) ) {
115
	if (IS_exp_cast(a)) {
87
	/* Exact casts are idempotent */
116
		/* Exact casts are idempotent */
88
	unsigned conv = DEREF_unsigned ( exp_cast_conv ( a ) ) ;
117
		unsigned conv = DEREF_unsigned(exp_cast_conv(a));
89
	if ( conv == CONV_EXACT ) {
118
		if (conv == CONV_EXACT) {
90
	    a = DEREF_exp ( exp_cast_arg ( a ) ) ;
119
			a = DEREF_exp(exp_cast_arg(a));
-
 
120
		}
91
	}
121
	}
92
    }
-
 
93
    MAKE_exp_cast ( t, CONV_EXACT, a, e ) ;
122
	MAKE_exp_cast(t, CONV_EXACT, a, e);
94
    return ( e ) ;
123
	return (e);
95
}
124
}
96
 
125
 
97
 
126
 
98
/*
127
/*
99
    FIND THE RANK OF AN INTEGER-INTEGER CONVERSION
128
    FIND THE RANK OF AN INTEGER-INTEGER CONVERSION
Line 101... Line 130...
101
    This routine finds the rank of a conversion to the integral type t
130
    This routine finds the rank of a conversion to the integral type t
102
    from the integral type s.  For basic types this is given by the
131
    from the integral type s.  For basic types this is given by the
103
    table builtin_casts.
132
    table builtin_casts.
104
*/
133
*/
105
 
134
 
106
static int rank_int_int
135
static int
107
    PROTO_N ( ( t, s ) )
-
 
108
    PROTO_T ( TYPE t X TYPE s )
136
rank_int_int(TYPE t, TYPE s)
109
{
137
{
110
    int ct = 100, cr = 100 ;
138
	int ct = 100, cr = 100;
111
    INT_TYPE is = DEREF_itype ( type_integer_sem ( s ) ) ;
139
	INT_TYPE is = DEREF_itype(type_integer_sem(s));
112
    INT_TYPE it = DEREF_itype ( type_integer_sem ( t ) ) ;
140
	INT_TYPE it = DEREF_itype(type_integer_sem(t));
113
    INT_TYPE ir = DEREF_itype ( type_integer_rep ( t ) ) ;
141
	INT_TYPE ir = DEREF_itype(type_integer_rep(t));
114
 
142
 
115
    /* Find the semantic conversion */
143
	/* Find the semantic conversion */
116
    if ( !EQ_itype ( it, ir ) ) {
144
	if (!EQ_itype(it, ir)) {
117
	if ( eq_itype ( it, is ) ) return ( 0 ) ;
145
		if (eq_itype(it, is)) {
-
 
146
			return (0);
-
 
147
		}
118
	if ( IS_itype_basic ( ir ) && IS_itype_basic ( is ) ) {
148
		if (IS_itype_basic(ir) && IS_itype_basic(is)) {
119
	    BUILTIN_TYPE bt = DEREF_ntype ( itype_basic_no ( it ) ) ;
149
			BUILTIN_TYPE bt = DEREF_ntype(itype_basic_no(it));
120
	    BUILTIN_TYPE bs = DEREF_ntype ( itype_basic_no ( is ) ) ;
150
			BUILTIN_TYPE bs = DEREF_ntype(itype_basic_no(is));
121
	    ct = builtin_cast ( bs, bt ) ;
151
			ct = builtin_cast(bs, bt);
122
	}
152
		}
123
    }
153
	}
124
 
154
 
125
    /* Find the representational conversion */
155
	/* Find the representational conversion */
126
    while ( IS_itype_promote ( ir ) ) {
156
	while (IS_itype_promote(ir)) {
127
	/* Allow for integer promotion conversions */
157
		/* Allow for integer promotion conversions */
128
	ir = DEREF_itype ( itype_promote_arg ( ir ) ) ;
158
		ir = DEREF_itype(itype_promote_arg(ir));
129
    }
159
	}
130
    if ( eq_itype ( ir, is ) ) return ( 0 ) ;
160
	if (eq_itype(ir, is)) {
-
 
161
		return (0);
-
 
162
	}
131
    if ( IS_itype_basic ( ir ) && IS_itype_basic ( is ) ) {
163
	if (IS_itype_basic(ir) && IS_itype_basic(is)) {
132
	BUILTIN_TYPE br = DEREF_ntype ( itype_basic_no ( ir ) ) ;
164
		BUILTIN_TYPE br = DEREF_ntype(itype_basic_no(ir));
133
	BUILTIN_TYPE bs = DEREF_ntype ( itype_basic_no ( is ) ) ;
165
		BUILTIN_TYPE bs = DEREF_ntype(itype_basic_no(is));
134
	cr = builtin_cast ( bs, br ) ;
166
		cr = builtin_cast(bs, br);
135
    } else {
167
	} else {
136
	TYPE ps = promote_type ( s ) ;
168
		TYPE ps = promote_type(s);
137
	if ( eq_type ( ps, t ) ) return ( 0 ) ;
169
		if (eq_type(ps, t)) {
-
 
170
			return (0);
138
    }
171
		}
-
 
172
	}
139
 
173
 
140
    /* Return the better conversion */
174
	/* Return the better conversion */
141
    return ( cr < ct ? cr : ct ) ;
175
	return (cr < ct ? cr : ct);
142
}
176
}
143
 
177
 
144
 
178
 
145
/*
179
/*
146
    FIND THE RANK OF A FLOATING-FLOATING CONVERSION
180
    FIND THE RANK OF A FLOATING-FLOATING CONVERSION
147
 
181
 
148
    This routine finds the rank of a conversion to the floating-point
182
    This routine finds the rank of a conversion to the floating-point
149
    type t from the floating-point type s.
183
    type t from the floating-point type s.
150
*/
184
*/
151
 
185
 
152
static int rank_float_float
186
static int
153
    PROTO_N ( ( t, s ) )
-
 
154
    PROTO_T ( TYPE t X TYPE s )
187
rank_float_float(TYPE t, TYPE s)
155
{
188
{
156
    int ct = 0 ;
189
	int ct = 0;
157
    FLOAT_TYPE fs = DEREF_ftype ( type_floating_rep ( s ) ) ;
190
	FLOAT_TYPE fs = DEREF_ftype(type_floating_rep(s));
158
    FLOAT_TYPE ft = DEREF_ftype ( type_floating_rep ( t ) ) ;
191
	FLOAT_TYPE ft = DEREF_ftype(type_floating_rep(t));
159
    while ( IS_ftype_arg_promote ( ft ) ) {
192
	while (IS_ftype_arg_promote(ft)) {
160
	/* Allow for floating promotion conversions */
193
		/* Allow for floating promotion conversions */
161
	ft = DEREF_ftype ( ftype_arg_promote_arg ( ft ) ) ;
194
		ft = DEREF_ftype(ftype_arg_promote_arg(ft));
162
    }
195
	}
163
    if ( !eq_ftype ( ft, fs ) ) {
196
	if (!eq_ftype(ft, fs)) {
164
	if ( IS_ftype_basic ( ft ) && IS_ftype_basic ( fs ) ) {
197
		if (IS_ftype_basic(ft) && IS_ftype_basic(fs)) {
165
	    BUILTIN_TYPE nt = DEREF_ntype ( ftype_basic_no ( ft ) ) ;
198
			BUILTIN_TYPE nt = DEREF_ntype(ftype_basic_no(ft));
166
	    BUILTIN_TYPE ns = DEREF_ntype ( ftype_basic_no ( fs ) ) ;
199
			BUILTIN_TYPE ns = DEREF_ntype(ftype_basic_no(fs));
167
	    ct = builtin_cast ( ns, nt ) ;
200
			ct = builtin_cast(ns, nt);
168
	} else {
201
		} else {
169
	    TYPE ps = promote_type ( s ) ;
202
			TYPE ps = promote_type(s);
170
	    if ( eq_type ( ps, t ) ) return ( 0 ) ;
203
			if (eq_type(ps, t)) {
-
 
204
				return (0);
-
 
205
			}
171
	}
206
		}
172
    }
207
	}
173
    return ( ct ) ;
208
	return (ct);
174
}
209
}
175
 
210
 
176
 
211
 
177
/*
212
/*
178
    PERFORM AN INTEGER-INTEGER CONVERSION
213
    PERFORM AN INTEGER-INTEGER CONVERSION
179
 
214
 
180
    This, and the following routines, are used to perform the basic type
215
    This, and the following routines, are used to perform the basic type
181
    conversions allowed within the language.  Each takes a destination
216
    conversions allowed within the language.  Each takes a destination
Line 184... Line 219...
184
    where t is bool is dealt with separately by convert_boolean, however a
219
    where t is bool is dealt with separately by convert_boolean, however a
185
    may have type bool.  rank gives the rank of the conversion, or -1 if
220
    may have type bool.  rank gives the rank of the conversion, or -1 if
186
    the rank needs to be calculated using rank_int_int.
221
    the rank needs to be calculated using rank_int_int.
187
*/
222
*/
188
 
223
 
189
EXP cast_int_int
224
EXP
190
    PROTO_N ( ( t, a, err, cast, rank ) )
-
 
191
    PROTO_T ( TYPE t X EXP a X ERROR *err X unsigned cast X int rank )
225
cast_int_int(TYPE t, EXP a, ERROR *err, unsigned cast, int rank)
192
{
226
{
193
    EXP e ;
227
	EXP e;
194
    int opt ;
228
	int opt;
195
    TYPE s = DEREF_type ( exp_type ( a ) ) ;
229
	TYPE s = DEREF_type(exp_type(a));
196
    unsigned nt = TAG_type ( t ) ;
230
	unsigned nt = TAG_type(t);
197
    unsigned ns = TAG_type ( s ) ;
231
	unsigned ns = TAG_type(s);
198
 
232
 
199
    /* Don't force unnecessary token definitions */
233
	/* Don't force unnecessary token definitions */
200
    if ( force_tokdef ) {
234
	if (force_tokdef) {
201
	TYPE t0 = t ;
235
		TYPE t0 = t;
202
	TYPE s0 = s ;
236
		TYPE s0 = s;
203
	t = expand_type ( t0, 1 ) ;
237
		t = expand_type(t0, 1);
204
	if ( !EQ_type ( t, t0 ) ) {
238
		if (!EQ_type(t, t0)) {
205
	    nt = TAG_type ( t ) ;
239
			nt = TAG_type(t);
206
	    if ( nt == type_floating_tag || nt == type_ptr_tag ) {
240
			if (nt == type_floating_tag || nt == type_ptr_tag) {
207
		t = t0 ;
241
				t = t0;
208
		nt = TAG_type ( t ) ;
242
				nt = TAG_type(t);
209
	    }
243
			}
210
	}
244
		}
211
	s = expand_type ( s0, 1 ) ;
245
		s = expand_type(s0, 1);
212
	if ( !EQ_type ( s, s0 ) ) {
246
		if (!EQ_type(s, s0)) {
213
	    ns = TAG_type ( s ) ;
247
			ns = TAG_type(s);
214
	    if ( ns == type_floating_tag || ns == type_ptr_tag ) {
248
			if (ns == type_floating_tag || ns == type_ptr_tag) {
215
		s = s0 ;
249
				s = s0;
216
		ns = TAG_type ( s ) ;
250
				ns = TAG_type(s);
217
	    }
251
			}
218
	}
252
		}
219
    }
253
	}
220
 
254
 
221
    /* Deal with bitfields */
255
	/* Deal with bitfields */
222
    if ( ns == type_bitfield_tag ) {
256
	if (ns == type_bitfield_tag) {
223
	TYPE r = find_bitfield_type ( s ) ;
257
		TYPE r = find_bitfield_type(s);
224
	MAKE_exp_cast ( r, CONV_BITFIELD, a, a ) ;
258
		MAKE_exp_cast(r, CONV_BITFIELD, a, a);
225
	/* NOT YET IMPLEMENTED: find rank */
259
		/* NOT YET IMPLEMENTED: find rank */
226
	rank = 0 ;
260
		rank = 0;
227
	e = cast_int_int ( t, a, err, cast, rank ) ;
261
		e = cast_int_int(t, a, err, cast, rank);
228
	if ( EQ_exp ( e, a ) ) {
262
		if (EQ_exp(e, a)) {
229
	    MAKE_exp_cast ( t, CONV_INT_INT, e, e ) ;
263
			MAKE_exp_cast(t, CONV_INT_INT, e, e);
-
 
264
		}
-
 
265
		return (e);
-
 
266
	}
-
 
267
	if (nt == type_bitfield_tag) {
-
 
268
		TYPE r = find_bitfield_type(t);
-
 
269
		/* NOT YET IMPLEMENTED: find rank */
-
 
270
		rank = 0;
-
 
271
		e = cast_int_int(r, a, err, cast, rank);
-
 
272
		if (EQ_exp(e, a)) {
-
 
273
			MAKE_exp_cast(r, CONV_INT_INT, e, e);
-
 
274
		}
-
 
275
		MAKE_exp_cast(t,(CONV_BITFIELD | CONV_REVERSE), e, e);
-
 
276
		return (e);
-
 
277
	}
-
 
278
 
-
 
279
	/* Deal with identity casts */
-
 
280
	if (nt == ns) {
-
 
281
		if (EQ_type(t, s)) {
-
 
282
			if (IS_exp_int_lit(a) && cast != CAST_IMPLICIT) {
-
 
283
				NAT n = DEREF_nat(exp_int_lit_nat(a));
-
 
284
				MAKE_exp_int_lit(t, n, exp_cast_tag, a);
-
 
285
			}
-
 
286
			return (a);
-
 
287
		}
-
 
288
		if (eq_type(t, s)) {
-
 
289
			if (cast == CAST_IMPLICIT) {
-
 
290
				/* Preserve semantics for implicit casts */
-
 
291
				return (a);
-
 
292
			}
-
 
293
			if (cast != CAST_REINTERP) {
-
 
294
				/* Override semantics for other casts */
-
 
295
				if (IS_exp_int_lit(a)) {
-
 
296
					NAT n = DEREF_nat(exp_int_lit_nat(a));
-
 
297
					MAKE_exp_int_lit(t, n, exp_cast_tag, e);
-
 
298
				} else {
-
 
299
					MAKE_exp_cast(t, CONV_INT_INT, a, e);
-
 
300
				}
-
 
301
				return (e);
-
 
302
			}
-
 
303
		}
-
 
304
	}
-
 
305
 
-
 
306
	/* Find error severity level */
-
 
307
	if (cast == CAST_IMPLICIT) {
-
 
308
		opt = OPT_conv_int_int_impl;
-
 
309
	} else if (cast & CAST_STATIC) {
-
 
310
		opt = OPT_conv_int_int_expl;
-
 
311
	} else {
-
 
312
		opt = OPT_error;
230
	}
313
	}
-
 
314
 
-
 
315
	/* Can't cast implicitly to enumeration type */
-
 
316
	if (nt == type_enumerate_tag) {
-
 
317
		ERROR err2;
-
 
318
#if LANGUAGE_C
-
 
319
		if (IS_exp_int_lit(a)) {
-
 
320
			/* Allow for C enumerators */
-
 
321
			unsigned tag = DEREF_unsigned(exp_int_lit_etag(a));
-
 
322
			if (tag == exp_identifier_tag) {
-
 
323
				e = make_cast_nat(t, a, err, cast);
231
	return ( e ) ;
324
				return (e);
-
 
325
			}
-
 
326
		}
-
 
327
#endif
-
 
328
		if (cast == CAST_IMPLICIT) {
-
 
329
			if (option(OPT_conv_int_enum) > option(opt)) {
-
 
330
				opt = OPT_conv_int_enum;
232
    }
331
			}
-
 
332
		}
233
    if ( nt == type_bitfield_tag ) {
333
		if (ns == type_enumerate_tag) {
-
 
334
			err2 = ERR_expr_cast_stat_enum_enum(s, t);
-
 
335
		} else {
-
 
336
			err2 = ERR_expr_cast_stat_int_enum(s, t);
-
 
337
		}
234
	TYPE r = find_bitfield_type ( t ) ;
338
		err2 = set_severity(err2, opt, 0);
-
 
339
		if (!IS_NULL_err(err2)) {
235
	/* NOT YET IMPLEMENTED: find rank */
340
			e = cast_token(t, a, err, err2, cast);
-
 
341
			if (!IS_NULL_exp(e)) {
236
	rank = 0 ;
342
				return (e);
-
 
343
			}
-
 
344
		}
-
 
345
	} else if (opt == OPT_error) {
-
 
346
		ERROR err2 = ERR_conv_integral_cast(s, t);
-
 
347
		err2 = set_severity(err2, opt, 0);
-
 
348
		if (!IS_NULL_err(err2)) {
237
	e = cast_int_int ( r, a, err, cast, rank ) ;
349
			e = cast_token(t, a, err, err2, cast);
238
	if ( EQ_exp ( e, a ) ) {
350
			if (!IS_NULL_exp(e)) {
-
 
351
				return (e);
-
 
352
			}
-
 
353
		}
239
	    MAKE_exp_cast ( r, CONV_INT_INT, e, e ) ;
354
		opt = OPT_none;
240
	}
355
	}
241
	MAKE_exp_cast ( t, ( CONV_BITFIELD | CONV_REVERSE ), e, e ) ;
-
 
242
	return ( e ) ;
-
 
243
    }
-
 
244
 
356
 
245
    /* Deal with identity casts */
357
	/* Deal with integral constants */
246
    if ( nt == ns ) {
-
 
247
	if ( EQ_type ( t, s ) ) {
358
	if (IS_exp_int_lit(a)) {
248
	    if ( IS_exp_int_lit ( a ) && cast != CAST_IMPLICIT ) {
-
 
249
		NAT n = DEREF_nat ( exp_int_lit_nat ( a ) ) ;
-
 
250
		MAKE_exp_int_lit ( t, n, exp_cast_tag, a ) ;
359
		e = make_cast_nat(t, a, err, cast);
251
	    }
-
 
252
	    return ( a ) ;
360
		return (e);
253
	}
361
	}
-
 
362
 
254
	if ( eq_type ( t, s ) ) {
363
	/* Check integer to integer conversions */
255
	    if ( cast == CAST_IMPLICIT ) {
364
	if (rank != 0 && option(opt)) {
256
		/* Preserve semantics for implicit casts */
365
		if (nt == type_integer_tag && ns == type_integer_tag) {
257
		return ( a ) ;
366
			if (rank < 0) {
-
 
367
				rank = rank_int_int(t, s);
258
	    }
368
			}
259
	    if ( cast != CAST_REINTERP ) {
369
			if (rank >= max_builtin_cast) {
260
		/* Override semantics for other casts */
370
				ERROR err2 = ERR_conv_integral_cast(s, t);
261
		if ( IS_exp_int_lit ( a ) ) {
371
				err2 = set_severity(err2, opt, 0);
262
		    NAT n = DEREF_nat ( exp_int_lit_nat ( a ) ) ;
372
				if (!IS_NULL_err(err2)) {
263
		    MAKE_exp_int_lit ( t, n, exp_cast_tag, e ) ;
373
					e = cast_token(t, a, err, err2, cast);
264
		} else {
374
					if (!IS_NULL_exp(e)) {
265
		    MAKE_exp_cast ( t, CONV_INT_INT, a, e ) ;
375
						return (e);
-
 
376
					}
-
 
377
				}
-
 
378
			}
266
		}
379
		}
267
		return ( e ) ;
-
 
268
	    }
-
 
269
	}
-
 
270
    }
-
 
271
 
-
 
272
    /* Find error severity level */
-
 
273
    if ( cast == CAST_IMPLICIT ) {
-
 
274
	opt = OPT_conv_int_int_impl ;
-
 
275
    } else if ( cast & CAST_STATIC ) {
-
 
276
	opt = OPT_conv_int_int_expl ;
-
 
277
    } else {
-
 
278
	opt = OPT_error ;
-
 
279
    }
-
 
280
 
-
 
281
    /* Can't cast implicitly to enumeration type */
-
 
282
    if ( nt == type_enumerate_tag ) {
-
 
283
	ERROR err2 ;
-
 
284
#if LANGUAGE_C
-
 
285
	if ( IS_exp_int_lit ( a ) ) {
-
 
286
	    /* Allow for C enumerators */
-
 
287
	    unsigned tag = DEREF_unsigned ( exp_int_lit_etag ( a ) ) ;
-
 
288
	    if ( tag == exp_identifier_tag ) {
-
 
289
		e = make_cast_nat ( t, a, err, cast ) ;
-
 
290
		return ( e ) ;
-
 
291
	    }
-
 
292
	}
-
 
293
#endif
-
 
294
	if ( cast == CAST_IMPLICIT ) {
-
 
295
	    if ( option ( OPT_conv_int_enum ) > option ( opt ) ) {
-
 
296
		opt = OPT_conv_int_enum ;
-
 
297
	    }
-
 
298
	}
-
 
299
	if ( ns == type_enumerate_tag ) {
-
 
300
	    err2 = ERR_expr_cast_stat_enum_enum ( s, t ) ;
-
 
301
	} else {
-
 
302
	    err2 = ERR_expr_cast_stat_int_enum ( s, t ) ;
-
 
303
	}
380
	}
304
	err2 = set_severity ( err2, opt, 0 ) ;
-
 
305
	if ( !IS_NULL_err ( err2 ) ) {
-
 
306
	    e = cast_token ( t, a, err, err2, cast ) ;
-
 
307
	    if ( !IS_NULL_exp ( e ) ) return ( e ) ;
-
 
308
	}
-
 
309
    } else if ( opt == OPT_error ) {
-
 
310
	ERROR err2 = ERR_conv_integral_cast ( s, t ) ;
-
 
311
	err2 = set_severity ( err2, opt, 0 ) ;
-
 
312
	if ( !IS_NULL_err ( err2 ) ) {
-
 
313
	    e = cast_token ( t, a, err, err2, cast ) ;
-
 
314
	    if ( !IS_NULL_exp ( e ) ) return ( e ) ;
-
 
315
	}
-
 
316
	opt = OPT_none ;
-
 
317
    }
-
 
318
 
-
 
319
    /* Deal with integral constants */
-
 
320
    if ( IS_exp_int_lit ( a ) ) {
-
 
321
	e = make_cast_nat ( t, a, err, cast ) ;
-
 
322
	return ( e ) ;
-
 
323
    }
-
 
324
 
-
 
325
    /* Check integer to integer conversions */
-
 
326
    if ( rank != 0 && option ( opt ) ) {
-
 
327
	if ( nt == type_integer_tag && ns == type_integer_tag ) {
-
 
328
	    if ( rank < 0 ) rank = rank_int_int ( t, s ) ;
-
 
329
	    if ( rank >= max_builtin_cast ) {
-
 
330
		ERROR err2 = ERR_conv_integral_cast ( s, t ) ;
-
 
331
		err2 = set_severity ( err2, opt, 0 ) ;
-
 
332
		if ( !IS_NULL_err ( err2 ) ) {
-
 
333
		    e = cast_token ( t, a, err, err2, cast ) ;
-
 
334
		    if ( !IS_NULL_exp ( e ) ) return ( e ) ;
-
 
335
		}
-
 
336
	    }
-
 
337
	}
-
 
338
    }
-
 
339
 
381
 
340
    /* Construct the result */
382
	/* Construct the result */
341
    MAKE_exp_cast ( t, CONV_INT_INT, a, e ) ;
383
	MAKE_exp_cast(t, CONV_INT_INT, a, e);
342
    return ( e ) ;
384
	return (e);
343
}
385
}
344
 
386
 
345
 
387
 
346
/*
388
/*
347
    PERFORM A INTEGER-FLOAT CONVERSION
389
    PERFORM A INTEGER-FLOAT CONVERSION
348
 
390
 
349
    This routine converts the integral expression a to the floating point
391
    This routine converts the integral expression a to the floating point
350
    type t.
392
    type t.
351
*/
393
*/
352
 
394
 
353
EXP cast_int_float
395
EXP
354
    PROTO_N ( ( t, a, err, cast ) )
-
 
355
    PROTO_T ( TYPE t X EXP a X ERROR *err X unsigned cast )
396
cast_int_float(TYPE t, EXP a, ERROR *err, unsigned cast)
356
{
397
{
357
    EXP e ;
398
	EXP e;
358
    int opt ;
399
	int opt;
359
    TYPE s = DEREF_type ( exp_type ( a ) ) ;
400
	TYPE s = DEREF_type(exp_type(a));
360
 
401
 
361
    /* Find error severity level */
402
	/* Find error severity level */
362
    if ( cast == CAST_IMPLICIT ) {
403
	if (cast == CAST_IMPLICIT) {
363
	opt = OPT_conv_int_int_impl ;
404
		opt = OPT_conv_int_int_impl;
364
    } else if ( cast & CAST_STATIC ) {
405
	} else if (cast & CAST_STATIC) {
365
	opt = OPT_conv_int_int_expl ;
406
		opt = OPT_conv_int_int_expl;
366
    } else {
407
	} else {
367
	opt = OPT_error ;
408
		opt = OPT_error;
368
    }
409
	}
369
    if ( option ( opt ) ) {
410
	if (option(opt)) {
370
	ERROR err2 = ERR_conv_fpint_float ( s, t ) ;
411
		ERROR err2 = ERR_conv_fpint_float(s, t);
371
	err2 = set_severity ( err2, opt, 0 ) ;
412
		err2 = set_severity(err2, opt, 0);
372
	if ( !IS_NULL_err ( err2 ) ) {
413
		if (!IS_NULL_err(err2)) {
373
	    e = cast_token ( t, a, err, err2, cast ) ;
414
			e = cast_token(t, a, err, err2, cast);
374
	    if ( !IS_NULL_exp ( e ) ) return ( e ) ;
415
			if (!IS_NULL_exp(e)) {
-
 
416
				return (e);
-
 
417
			}
-
 
418
		}
375
	}
419
	}
376
    }
-
 
377
 
420
 
378
    /* Construct the result */
421
	/* Construct the result */
379
    MAKE_exp_cast ( t, CONV_INT_FLT, a, e ) ;
422
	MAKE_exp_cast(t, CONV_INT_FLT, a, e);
380
    return ( e ) ;
423
	return (e);
381
}
424
}
382
 
425
 
383
 
426
 
384
/*
427
/*
385
    PERFORM A FLOAT-INTEGER CONVERSION
428
    PERFORM A FLOAT-INTEGER CONVERSION
386
 
429
 
387
    This routine converts the floating point expression a to the integral
430
    This routine converts the floating point expression a to the integral
388
    type t (which will not be bool).  Note that a floating point literal
431
    type t (which will not be bool).  Note that a floating point literal
389
    cast to an integral type is an integral constant expression.
432
    cast to an integral type is an integral constant expression.
390
*/
433
*/
391
 
434
 
392
static EXP cast_float_int
435
static EXP
393
    PROTO_N ( ( t, a, err, cast ) )
-
 
394
    PROTO_T ( TYPE t X EXP a X ERROR *err X unsigned cast )
436
cast_float_int(TYPE t, EXP a, ERROR *err, unsigned cast)
395
{
437
{
396
    EXP e ;
438
	EXP e;
397
    int opt ;
439
	int opt;
398
    TYPE s = DEREF_type ( exp_type ( a ) ) ;
440
	TYPE s = DEREF_type(exp_type(a));
399
 
441
 
400
    /* Find error severity level */
442
	/* Find error severity level */
401
    if ( cast == CAST_IMPLICIT ) {
443
	if (cast == CAST_IMPLICIT) {
402
	opt = OPT_conv_int_int_impl ;
444
		opt = OPT_conv_int_int_impl;
403
	if ( IS_type_enumerate ( t ) ) {
445
		if (IS_type_enumerate(t)) {
404
	    /* Can't have enumeration type */
446
			/* Can't have enumeration type */
405
	    if ( option ( OPT_conv_int_enum ) > option ( opt ) ) {
447
			if (option(OPT_conv_int_enum) > option(opt)) {
406
		opt = OPT_conv_int_enum ;
448
				opt = OPT_conv_int_enum;
407
	    }
449
			}
408
	}
450
		}
409
    } else if ( cast & CAST_STATIC ) {
451
	} else if (cast & CAST_STATIC) {
410
	opt = OPT_conv_int_int_expl ;
452
		opt = OPT_conv_int_int_expl;
411
    } else {
453
	} else {
412
	opt = OPT_error ;
454
		opt = OPT_error;
413
    }
455
	}
414
    if ( option ( opt ) ) {
456
	if (option(opt)) {
415
	ERROR err2 = ERR_conv_fpint_trunc ( s, t ) ;
457
		ERROR err2 = ERR_conv_fpint_trunc(s, t);
416
	err2 = set_severity ( err2, opt, 0 ) ;
458
		err2 = set_severity(err2, opt, 0);
417
	if ( !IS_NULL_err ( err2 ) ) {
459
		if (!IS_NULL_err(err2)) {
418
	    e = cast_token ( t, a, err, err2, cast ) ;
460
			e = cast_token(t, a, err, err2, cast);
419
	    if ( !IS_NULL_exp ( e ) ) return ( e ) ;
461
			if (!IS_NULL_exp(e)) {
-
 
462
				return (e);
-
 
463
			}
420
	}
464
		}
421
    }
465
	}
422
 
466
 
423
    /* Construct the result */
467
	/* Construct the result */
424
    MAKE_exp_cast ( t, CONV_FLT_INT, a, e ) ;
468
	MAKE_exp_cast(t, CONV_FLT_INT, a, e);
425
 
469
 
426
    /* Deal with floating point literals */
470
	/* Deal with floating point literals */
427
    if ( IS_exp_float_lit ( a ) ) {
471
	if (IS_exp_float_lit(a)) {
428
	FLOAT f = DEREF_flt ( exp_float_lit_flt ( a ) ) ;
472
		FLOAT f = DEREF_flt(exp_float_lit_flt(a));
429
	NAT n = round_float_lit ( f, crt_round_mode ) ;
473
		NAT n = round_float_lit(f, crt_round_mode);
430
	if ( !IS_NULL_nat ( n ) ) {
474
		if (!IS_NULL_nat(n)) {
431
	    EXP c = make_int_exp ( t, exp_cast_tag, n ) ;
475
			EXP c = make_int_exp(t, exp_cast_tag, n);
432
	    if ( !IS_NULL_exp ( c ) ) return ( c ) ;
476
			if (!IS_NULL_exp(c)) {
-
 
477
				return (c);
-
 
478
			}
-
 
479
		}
-
 
480
		MAKE_nat_calc(e, n);
-
 
481
		MAKE_exp_int_lit(t, n, exp_cast_tag, e);
433
	}
482
	}
434
	MAKE_nat_calc ( e, n ) ;
-
 
435
	MAKE_exp_int_lit ( t, n, exp_cast_tag, e ) ;
-
 
436
    }
-
 
437
    return ( e ) ;
483
	return (e);
438
}
484
}
439
 
485
 
440
 
486
 
441
/*
487
/*
442
    PERFORM A FLOAT-FLOAT CONVERSION
488
    PERFORM A FLOAT-FLOAT CONVERSION
443
 
489
 
444
    This routine converts the floating point expression a to the floating
490
    This routine converts the floating point expression a to the floating
445
    point type t.
491
    point type t.
446
*/
492
*/
447
 
493
 
448
EXP cast_float_float
494
EXP
449
    PROTO_N ( ( t, a, err, cast ) )
-
 
450
    PROTO_T ( TYPE t X EXP a X ERROR *err X unsigned cast )
495
cast_float_float(TYPE t, EXP a, ERROR *err, unsigned cast)
451
{
496
{
452
    EXP e ;
497
	EXP e;
453
    int opt ;
498
	int opt;
454
    TYPE s = DEREF_type ( exp_type ( a ) ) ;
499
	TYPE s = DEREF_type(exp_type(a));
455
 
500
 
456
    /* Don't force unnecessary token definitions */
501
	/* Don't force unnecessary token definitions */
457
    if ( force_tokdef ) {
502
	if (force_tokdef) {
458
	TYPE t0 = t ;
503
		TYPE t0 = t;
459
	TYPE s0 = s ;
504
		TYPE s0 = s;
460
	t = expand_type ( t0, 1 ) ;
505
		t = expand_type(t0, 1);
461
	s = expand_type ( s0, 1 ) ;
506
		s = expand_type(s0, 1);
462
	if ( !IS_type_floating ( t ) ) t = t0 ;
507
		if (!IS_type_floating(t)) {
-
 
508
			t = t0;
-
 
509
		}
463
	if ( !IS_type_floating ( s ) ) s = s0 ;
510
		if (!IS_type_floating(s)) {
-
 
511
			s = s0;
464
    }
512
		}
-
 
513
	}
465
 
514
 
466
    /* Deal with identity casts */
515
	/* Deal with identity casts */
467
    if ( eq_type ( t, s ) ) {
516
	if (eq_type(t, s)) {
468
	if ( cast != CAST_REINTERP ) return ( a ) ;
517
		if (cast != CAST_REINTERP) {
-
 
518
			return (a);
469
    }
519
		}
-
 
520
	}
470
 
521
 
471
    /* Find error severity level */
522
	/* Find error severity level */
472
    if ( cast == CAST_IMPLICIT ) {
523
	if (cast == CAST_IMPLICIT) {
473
	opt = OPT_conv_int_int_impl ;
524
		opt = OPT_conv_int_int_impl;
474
    } else if ( cast & CAST_STATIC ) {
525
	} else if (cast & CAST_STATIC) {
475
	opt = OPT_conv_int_int_expl ;
526
		opt = OPT_conv_int_int_expl;
476
    } else {
527
	} else {
477
	opt = OPT_error ;
528
		opt = OPT_error;
478
    }
529
	}
479
    if ( option ( opt ) ) {
530
	if (option(opt)) {
480
	int c = rank_float_float ( t, s ) ;
531
		int c = rank_float_float(t, s);
481
	if ( c >= max_builtin_cast || opt == OPT_error ) {
532
		if (c >= max_builtin_cast || opt == OPT_error) {
482
	    ERROR err2 = ERR_conv_double_cast ( s, t ) ;
533
			ERROR err2 = ERR_conv_double_cast(s, t);
483
	    err2 = set_severity ( err2, opt, 0 ) ;
534
			err2 = set_severity(err2, opt, 0);
484
	    if ( !IS_NULL_err ( err2 ) ) {
535
			if (!IS_NULL_err(err2)) {
485
		e = cast_token ( t, a, err, err2, cast ) ;
536
				e = cast_token(t, a, err, err2, cast);
486
		if ( !IS_NULL_exp ( e ) ) return ( e ) ;
537
				if (!IS_NULL_exp(e)) {
-
 
538
					return (e);
487
	    }
539
				}
-
 
540
			}
488
	}
541
		}
489
    }
542
	}
490
 
543
 
491
    /* Construct the result */
544
	/* Construct the result */
492
    MAKE_exp_cast ( t, CONV_FLT_FLT, a, e ) ;
545
	MAKE_exp_cast(t, CONV_FLT_FLT, a, e);
493
    return ( e ) ;
546
	return (e);
494
}
547
}
495
 
548
 
496
 
549
 
497
/*
550
/*
498
    CONSTRUCT AN UNRESOLVED CAST EXPRESSION
551
    CONSTRUCT AN UNRESOLVED CAST EXPRESSION
499
 
552
 
500
    This routine creates an expression for casting the expression a to
553
    This routine creates an expression for casting the expression a to
501
    type t using cast where either t or the type of a depends on a
554
    type t using cast where either t or the type of a depends on a
502
    template parameter type.
555
    template parameter type.
503
*/
556
*/
504
 
557
 
505
EXP cast_templ_type
558
EXP
506
    PROTO_N ( ( t, a, cast ) )
-
 
507
    PROTO_T ( TYPE t X EXP a X unsigned cast )
559
cast_templ_type(TYPE t, EXP a, unsigned cast)
508
{
560
{
509
    EXP e ;
561
	EXP e;
510
    int op ;
562
	int op;
511
    switch ( cast ) {
563
	switch (cast) {
512
	case CAST_IMPLICIT : op = lex_implicit ; break ;
564
	case CAST_IMPLICIT:
-
 
565
		op = lex_implicit;
-
 
566
		break;
-
 
567
	case CAST_STATIC:
513
	case CAST_STATIC : op = lex_static_Hcast ; break ;
568
		op = lex_static_Hcast;
-
 
569
		break;
-
 
570
	case CAST_REINTERP:
514
	case CAST_REINTERP : op = lex_reinterpret_Hcast ; break ;
571
		op = lex_reinterpret_Hcast;
-
 
572
		break;
-
 
573
	case CAST_CONST:
515
	case CAST_CONST : op = lex_const_Hcast ; break ;
574
		op = lex_const_Hcast;
-
 
575
		break;
-
 
576
	default:
516
	default : op = lex_cast ; break ;
577
		op = lex_cast;
-
 
578
		break;
517
    }
579
	}
518
    t = rvalue_type ( t ) ;
580
	t = rvalue_type(t);
519
    MAKE_exp_op ( t, op, a, NULL_exp, e ) ;
581
	MAKE_exp_op(t, op, a, NULL_exp, e);
520
    return ( e ) ;
582
	return (e);
521
}
583
}
522
 
584
 
523
 
585
 
524
/*
586
/*
525
    REPORT CASTING AWAY CONST-NESS
587
    REPORT CASTING AWAY CONST-NESS
526
 
588
 
527
    This routine adds an error to the end of err if the value qual returned
589
    This routine adds an error to the end of err if the value qual returned
528
    by check_qualifier indicates that a particular conversion casts away
590
    by check_qualifier indicates that a particular conversion casts away
529
    const-ness (or volatile-ness).
591
    const-ness (or volatile-ness).
530
*/
592
*/
531
 
593
 
532
void cast_away_const
594
void
533
    PROTO_N ( ( qual, err, cast ) )
-
 
534
    PROTO_T ( unsigned qual X ERROR *err X unsigned cast )
595
cast_away_const(unsigned qual, ERROR *err, unsigned cast)
535
{
596
{
536
    if ( !( cast & CAST_CONST ) ) {
597
	if (!(cast & CAST_CONST)) {
537
	CV_SPEC cv = cv_none ;
598
		CV_SPEC cv = cv_none;
538
	if ( !( qual & QUAL_CONST ) ) cv |= cv_const ;
599
		if (!(qual & QUAL_CONST)) {
-
 
600
			cv |= cv_const;
-
 
601
		}
539
	if ( !( qual & QUAL_VOLATILE ) ) cv |= cv_volatile ;
602
		if (!(qual & QUAL_VOLATILE)) {
-
 
603
			cv |= cv_volatile;
-
 
604
		}
540
	if ( cv == cv_none ) {
605
		if (cv == cv_none) {
541
	    if ( !( qual & QUAL_ALL_CONST ) ) {
606
			if (!(qual & QUAL_ALL_CONST)) {
542
		add_error ( err, ERR_conv_qual_multi () ) ;
607
				add_error(err, ERR_conv_qual_multi());
543
	    }
608
			}
544
	} else {
609
		} else {
545
	    add_error ( err, ERR_conv_qual_cast ( cv ) ) ;
610
			add_error(err, ERR_conv_qual_cast(cv));
-
 
611
		}
546
	}
612
	}
547
    }
-
 
548
    return ;
613
	return;
549
}
614
}
550
 
615
 
551
 
616
 
552
/*
617
/*
553
    CREATE A BASE CAST EXPRESSION
618
    CREATE A BASE CAST EXPRESSION
Line 556... Line 621...
556
    expression a to type t using the offset off.  If off is a zero offset
621
    expression a to type t using the offset off.  If off is a zero offset
557
    (indicating single inheritance) or the type of a can be statically
622
    (indicating single inheritance) or the type of a can be statically
558
    determined then this is a simple add_ptr operation.  Otherwise a
623
    determined then this is a simple add_ptr operation.  Otherwise a
559
    base_cast expression is used.  Note that a dummy expression is
624
    base_cast expression is used.  Note that a dummy expression is
560
    introduced to represent the argument.
625
    introduced to represent the argument.
561
*/
626
*/
562
 
627
 
563
EXP make_base_cast
628
EXP
564
    PROTO_N ( ( t, a, off ) )
-
 
565
    PROTO_T ( TYPE t X EXP a X OFFSET off )
629
make_base_cast(TYPE t, EXP a, OFFSET off)
566
{
630
{
567
    EXP e ;
631
	EXP e;
568
    if ( is_zero_offset ( off ) || know_type ( a ) == 1 ) {
632
	if (is_zero_offset(off) || know_type(a) == 1) {
569
	MAKE_exp_add_ptr ( t, a, off, 0, e ) ;
633
		MAKE_exp_add_ptr(t, a, off, 0, e);
570
    } else {
634
	} else {
571
	TYPE s = DEREF_type ( exp_type ( a ) ) ;
635
		TYPE s = DEREF_type(exp_type(a));
572
	if ( !IS_type_ptr ( s ) ) s = t ;
636
		if (!IS_type_ptr(s)) {
-
 
637
			s = t;
-
 
638
		}
573
	MAKE_exp_dummy ( s, a, LINK_NONE, NULL_off, 1, a ) ;
639
		MAKE_exp_dummy(s, a, LINK_NONE, NULL_off, 1, a);
574
	MAKE_exp_base_cast ( t, CONV_PTR_BASE, a, off, e ) ;
640
		MAKE_exp_base_cast(t, CONV_PTR_BASE, a, off, e);
575
    }
641
	}
576
    return ( e ) ;
642
	return (e);
577
}
643
}
578
 
644
 
579
 
645
 
580
/*
646
/*
581
    PERFORM A POINTER-POINTER CONVERSION
647
    PERFORM A POINTER-POINTER CONVERSION
582
 
648
 
Line 588... Line 654...
588
    if force is true then an identity explicit cast is inserted after any
654
    if force is true then an identity explicit cast is inserted after any
589
    base pointer cast.  This is to allow for TDF operations such as
655
    base pointer cast.  This is to allow for TDF operations such as
590
    pointer_test which require exact equality of alignments.
656
    pointer_test which require exact equality of alignments.
591
*/
657
*/
592
 
658
 
593
EXP cast_ptr_ptr
659
EXP
594
    PROTO_N ( ( t, a, err, cast, safe, force ) )
-
 
595
    PROTO_T ( TYPE t X EXP a X ERROR *err X unsigned cast X
660
cast_ptr_ptr(TYPE t, EXP a, ERROR *err, unsigned cast, int safe, int force)
596
	      int safe X int force )
-
 
597
{
661
{
598
    EXP e ;
662
	EXP e;
599
    int opt ;
663
	int opt;
600
    unsigned qual ;
664
	unsigned qual;
601
    OFFSET off = NULL_off ;
665
	OFFSET off = NULL_off;
602
    unsigned conv = CONV_NONE ;
666
	unsigned conv = CONV_NONE;
603
    TYPE s = DEREF_type ( exp_type ( a ) ) ;
667
	TYPE s = DEREF_type(exp_type(a));
604
    TYPE pt = DEREF_type ( type_ptr_sub ( t ) ) ;
668
	TYPE pt = DEREF_type(type_ptr_sub(t));
605
    TYPE ps = DEREF_type ( type_ptr_sub ( s ) ) ;
669
	TYPE ps = DEREF_type(type_ptr_sub(s));
606
    unsigned nt = TAG_type ( pt ) ;
670
	unsigned nt = TAG_type(pt);
607
    unsigned ns = TAG_type ( ps ) ;
671
	unsigned ns = TAG_type(ps);
608
 
-
 
609
    /* Allow for tokenised types */
-
 
610
    if ( nt == type_token_tag ) {
-
 
611
	t = expand_type ( t, 1 ) ;
-
 
612
	pt = DEREF_type ( type_ptr_sub ( t ) ) ;
-
 
613
	nt = TAG_type ( pt ) ;
-
 
614
    }
-
 
615
    if ( ns == type_token_tag ) {
-
 
616
	s = expand_type ( s, 1 ) ;
-
 
617
	ps = DEREF_type ( type_ptr_sub ( s ) ) ;
-
 
618
	ns = TAG_type ( ps ) ;
-
 
619
    }
-
 
620
 
-
 
621
    /* Check for qualifier conversions */
-
 
622
    qual = check_qualifier ( t, s, safe ) ;
-
 
623
    if ( qual == QUAL_EQUAL ) {
-
 
624
	/* Allow for type equality */
-
 
625
	if ( cast != CAST_IMPLICIT ) a = cast_exact ( t, a ) ;
-
 
626
	return ( a ) ;
-
 
627
    }
-
 
628
    if ( qual == QUAL_EQ_FUNC ) {
-
 
629
	/* Allow for equality of function types */
-
 
630
	if ( !( cast & CAST_REINTERP ) && !eq_except ( ps, pt ) ) {
-
 
631
	    add_error ( err, ERR_except_spec_assign () ) ;
-
 
632
	}
-
 
633
	e = cast_exact ( t, a ) ;
-
 
634
	return ( e ) ;
-
 
635
    }
-
 
636
    if ( qual & QUAL_TEMPL ) {
-
 
637
	/* Conversion depends on template parameter */
-
 
638
	e = cast_templ_type ( t, a, cast ) ;
-
 
639
	return ( e ) ;
-
 
640
    }
-
 
641
    if ( !( qual & QUAL_CONST ) ) {
-
 
642
	/* Check for string literal conversions */
-
 
643
	if ( IS_exp_address ( a ) && ns == type_integer_tag ) {
-
 
644
	    EXP b = DEREF_exp ( exp_address_arg ( a ) ) ;
-
 
645
	    if ( IS_exp_string_lit ( b ) ) {
-
 
646
		/* Remove const and try again */
-
 
647
		int str = 1 ;
-
 
648
		if ( !( cast & CAST_CONST ) ) str = 2 ;
-
 
649
		a = convert_array ( b, str, err ) ;
-
 
650
		e = cast_ptr_ptr ( t, a, err, cast, safe, force ) ;
-
 
651
		return ( e ) ;
-
 
652
	    }
-
 
653
	}
-
 
654
    }
-
 
655
    if ( !( qual & QUAL_VOLATILE ) && used_extern_volatile ) {
-
 
656
	/* Check for implicitly volatile external objects */
-
 
657
	EXP pa = NULL_exp ;
-
 
658
	DECL_SPEC ds = find_exp_linkage ( a, &pa, 1 ) ;
-
 
659
	if ( ds & dspec_implicit ) qual |= QUAL_VOLATILE ;
-
 
660
    }
-
 
661
 
672
 
-
 
673
	/* Allow for tokenised types */
-
 
674
	if (nt == type_token_tag) {
-
 
675
		t = expand_type(t, 1);
-
 
676
		pt = DEREF_type(type_ptr_sub(t));
-
 
677
		nt = TAG_type(pt);
-
 
678
	}
-
 
679
	if (ns == type_token_tag) {
-
 
680
		s = expand_type(s, 1);
-
 
681
		ps = DEREF_type(type_ptr_sub(s));
-
 
682
		ns = TAG_type(ps);
-
 
683
	}
-
 
684
 
-
 
685
	/* Check for qualifier conversions */
-
 
686
	qual = check_qualifier(t, s, safe);
-
 
687
	if (qual == QUAL_EQUAL) {
-
 
688
		/* Allow for type equality */
-
 
689
		if (cast != CAST_IMPLICIT) {
-
 
690
			a = cast_exact(t, a);
-
 
691
		}
-
 
692
		return (a);
-
 
693
	}
-
 
694
	if (qual == QUAL_EQ_FUNC) {
-
 
695
		/* Allow for equality of function types */
-
 
696
		if (!(cast & CAST_REINTERP) && !eq_except(ps, pt)) {
-
 
697
			add_error(err, ERR_except_spec_assign());
-
 
698
		}
-
 
699
		e = cast_exact(t, a);
-
 
700
		return (e);
-
 
701
	}
-
 
702
	if (qual & QUAL_TEMPL) {
-
 
703
		/* Conversion depends on template parameter */
-
 
704
		e = cast_templ_type(t, a, cast);
-
 
705
		return (e);
-
 
706
	}
-
 
707
	if (!(qual & QUAL_CONST)) {
-
 
708
		/* Check for string literal conversions */
-
 
709
		if (IS_exp_address(a) && ns == type_integer_tag) {
-
 
710
			EXP b = DEREF_exp(exp_address_arg(a));
-
 
711
			if (IS_exp_string_lit(b)) {
-
 
712
				/* Remove const and try again */
-
 
713
				int str = 1;
-
 
714
				if (!(cast & CAST_CONST)) {
-
 
715
					str = 2;
-
 
716
				}
-
 
717
				a = convert_array(b, str, err);
-
 
718
				e = cast_ptr_ptr(t, a, err, cast, safe, force);
-
 
719
				return (e);
-
 
720
			}
-
 
721
		}
-
 
722
	}
-
 
723
	if (!(qual & QUAL_VOLATILE) && used_extern_volatile) {
-
 
724
		/* Check for implicitly volatile external objects */
-
 
725
		EXP pa = NULL_exp;
-
 
726
		DECL_SPEC ds = find_exp_linkage(a, &pa, 1);
-
 
727
		if (ds & dspec_implicit) {
-
 
728
			qual |= QUAL_VOLATILE;
-
 
729
		}
-
 
730
	}
-
 
731
 
662
    /* Check conversion */
732
	/* Check conversion */
663
    if ( qual & QUAL_SIMILAR ) {
733
	if (qual & QUAL_SIMILAR) {
664
	/* Simple qualification conversions */
734
		/* Simple qualification conversions */
665
	opt = OPT_none ;
735
		opt = OPT_none;
666
	conv = CONV_QUAL ;
736
		conv = CONV_QUAL;
667
    } else {
737
	} else {
668
	/* Other pointer conversions */
738
		/* Other pointer conversions */
669
	ERROR ferr = NULL_err ;
739
		ERROR ferr = NULL_err;
670
	switch ( nt ) {
740
		switch (nt) {
671
	    case type_top_tag :
741
		case type_top_tag:
672
	    case type_bottom_tag :
742
		case type_bottom_tag:
673
	    generic_lab : {
743
generic_lab:
674
		if ( ns == type_func_tag ) {
744
			if (ns == type_func_tag) {
675
		    /* Conversion from 'function *' to 'void *' */
745
				/* Conversion from 'function *' to 'void *' */
676
		    ERROR err2 = ERR_expr_cast_reint_func_ptr ( s, t ) ;
746
				ERROR err2 = ERR_expr_cast_reint_func_ptr(s, t);
677
		    if ( !IS_NULL_err ( err2 ) ) {
747
				if (!IS_NULL_err(err2)) {
678
			e = cast_token ( t, a, err, err2, cast ) ;
748
					e = cast_token(t, a, err, err2, cast);
679
			if ( !IS_NULL_exp ( e ) ) return ( e ) ;
749
					if (!IS_NULL_exp(e)) {
-
 
750
						return (e);
680
		    }
751
					}
-
 
752
				}
681
		}
753
			}
682
		if ( ns == type_top_tag || ns == type_bottom_tag ) {
754
			if (ns == type_top_tag || ns == type_bottom_tag) {
683
		    /* Conversion from 'void *' to 'void *' */
755
				/* Conversion from 'void *' to 'void *' */
684
		    opt = OPT_none ;
756
				opt = OPT_none;
685
		    if ( nt == type_integer_tag ) {
757
				if (nt == type_integer_tag) {
686
			conv = ( CONV_PTR_VOID | CONV_REVERSE ) ;
758
					conv = (CONV_PTR_VOID | CONV_REVERSE);
687
		    } else {
759
				} else {
688
			conv = CONV_EXACT ;
760
					conv = CONV_EXACT;
689
		    }
761
				}
690
		} else {
762
			} else {
691
		    /* Conversion from 'object *' to 'void *' */
763
				/* Conversion from 'object *' to 'void *' */
692
		    TYPE r = NULL_type ;
764
				TYPE r = NULL_type;
693
		    if ( ns == type_integer_tag ) {
765
				if (ns == type_integer_tag) {
694
			/* Check for generic pointers */
766
					/* Check for generic pointers */
695
			r = type_void_star ;
767
					r = type_void_star;
696
			r = type_composite ( s, r, 1, 0, &ferr, 0 ) ;
768
					r = type_composite(s, r, 1, 0, &ferr,
-
 
769
							   0);
697
		    }
770
				}
698
		    if ( !IS_NULL_type ( r ) ) {
771
				if (!IS_NULL_type(r)) {
699
			opt = OPT_none ;
772
					opt = OPT_none;
700
		    } else if ( cast == CAST_IMPLICIT ) {
773
				} else if (cast == CAST_IMPLICIT) {
701
			opt = OPT_conv_ptr_ptr_void ;
774
					opt = OPT_conv_ptr_ptr_void;
702
		    } else if ( cast == CAST_CONST ) {
775
				} else if (cast == CAST_CONST) {
703
			opt = OPT_error ;
776
					opt = OPT_error;
704
		    } else {
777
				} else {
705
			opt = OPT_none ;
778
					opt = OPT_none;
706
		    }
779
				}
707
		    if ( nt != type_integer_tag ) conv = CONV_PTR_VOID ;
780
				if (nt != type_integer_tag)conv = CONV_PTR_VOID;
-
 
781
			}
-
 
782
			break;
-
 
783
		case type_compound_tag: {
-
 
784
			if (cast == CAST_CONST || cast == CAST_REINTERP) {
-
 
785
				goto default_lab;
-
 
786
			}
-
 
787
			if (ns == type_compound_tag) {
-
 
788
				/* Conversion from 'class *' to 'class *' */
-
 
789
				GRAPH gr;
-
 
790
				CLASS_TYPE ct, cs;
-
 
791
				ct = DEREF_ctype(type_compound_defn(pt));
-
 
792
				cs = DEREF_ctype(type_compound_defn(ps));
-
 
793
				gr = find_base_class(cs, ct, 1);
-
 
794
				if (!IS_NULL_graph(gr)) {
-
 
795
					/* Base class conversion */
-
 
796
					ERROR err2 = check_ambig_base(gr);
-
 
797
					if (!IS_NULL_err(err2)) {
-
 
798
						/* Can't be ambiguous */
-
 
799
						e = cast_token(t, a, err, err2,
-
 
800
							       cast);
-
 
801
						if (!IS_NULL_exp(e)) {
-
 
802
							return (e);
-
 
803
						}
-
 
804
						add_error(err, ERR_conv_ptr_ambiguous());
-
 
805
					}
-
 
806
					if (!(cast & CAST_BAD)) {
-
 
807
						/* Check base access */
-
 
808
						check_base_access(gr);
-
 
809
					}
-
 
810
					off = DEREF_off(graph_off(gr));
-
 
811
					conv = CONV_PTR_BASE;
-
 
812
					opt = OPT_none;
-
 
813
					break;
-
 
814
				}
-
 
815
				if (cast & CAST_STATIC) {
-
 
816
					gr = find_base_class(ct, cs, 1);
-
 
817
					if (!IS_NULL_graph(gr)) {
-
 
818
						/* Reverse base class
-
 
819
						 * conversion */
-
 
820
						ERROR err2 =
-
 
821
						    check_ambig_base(gr);
-
 
822
						if (!IS_NULL_err(err2)) {
-
 
823
							/* Can't be ambiguous */
-
 
824
							e = cast_token(t, a, err, err2, cast);
-
 
825
							if (!IS_NULL_exp(e)) {
-
 
826
								return (e);
-
 
827
							}
-
 
828
							add_error(err, ERR_conv_ptr_ambiguous());
-
 
829
						}
-
 
830
						err2 = check_virt_base(gr);
-
 
831
						if (!IS_NULL_err(err2)) {
-
 
832
							/* Can't be virtual */
-
 
833
							e = cast_token(t, a, err, err2, cast);
-
 
834
							if (!IS_NULL_exp(e)) {
-
 
835
								return (e);
-
 
836
							}
-
 
837
							add_error(err, ERR_expr_cast_stat_virt());
-
 
838
						}
-
 
839
						if (!(cast & CAST_BAD)) {
-
 
840
							/* Check base access */
-
 
841
							check_base_access(gr);
-
 
842
						}
-
 
843
						off = DEREF_off(graph_off(gr));
-
 
844
						conv = (CONV_PTR_BASE |
-
 
845
							CONV_REVERSE);
-
 
846
						opt = OPT_none;
-
 
847
						break;
-
 
848
					}
-
 
849
				}
-
 
850
			}
-
 
851
			goto default_lab;
708
		}
852
		}
709
		break ;
-
 
710
	    }
-
 
711
	    case type_compound_tag : {
853
		case type_func_tag: {
712
		if ( cast == CAST_CONST || cast == CAST_REINTERP ) {
-
 
713
		    goto default_lab ;
-
 
714
		}
-
 
715
		if ( ns == type_compound_tag ) {
854
			if (ns != type_func_tag) {
716
		    /* Conversion from 'class *' to 'class *' */
855
				/* Conversion from 'function *' to 'object *' */
717
		    GRAPH gr ;
-
 
718
		    CLASS_TYPE ct, cs ;
-
 
719
		    ct = DEREF_ctype ( type_compound_defn ( pt ) ) ;
-
 
720
		    cs = DEREF_ctype ( type_compound_defn ( ps ) ) ;
-
 
721
		    gr = find_base_class ( cs, ct, 1 ) ;
-
 
722
		    if ( !IS_NULL_graph ( gr ) ) {
-
 
723
			/* Base class conversion */
-
 
724
			ERROR err2 = check_ambig_base ( gr ) ;
856
				ERROR err2 = ERR_expr_cast_reint_func_ptr(s, t);
725
			if ( !IS_NULL_err ( err2 ) ) {
857
				if (!IS_NULL_err(err2)) {
726
			    /* Can't be ambiguous */
-
 
727
			    e = cast_token ( t, a, err, err2, cast ) ;
858
					e = cast_token(t, a, err, err2, cast);
728
			    if ( !IS_NULL_exp ( e ) ) return ( e ) ;
859
					if (!IS_NULL_exp(e)) {
729
			    add_error ( err, ERR_conv_ptr_ambiguous () ) ;
860
						return (e);
730
			}
861
					}
731
			if ( !( cast & CAST_BAD ) ) {
862
				}
732
			    /* Check base access */
863
				goto object_lab;
733
			    check_base_access ( gr ) ;
-
 
734
			}
864
			}
735
			off = DEREF_off ( graph_off ( gr ) ) ;
865
			/* Conversion from 'function *' to 'function *' */
736
			conv = CONV_PTR_BASE ;
-
 
737
			opt = OPT_none ;
-
 
738
			break ;
-
 
739
		    }
-
 
740
		    if ( cast & CAST_STATIC ) {
866
			if (cast & CAST_REINTERP) {
741
			gr = find_base_class ( ct, cs, 1 ) ;
-
 
742
			if ( !IS_NULL_graph ( gr ) ) {
-
 
743
			    /* Reverse base class conversion */
-
 
744
			    ERROR err2 = check_ambig_base ( gr ) ;
-
 
745
			    if ( !IS_NULL_err ( err2 ) ) {
-
 
746
				/* Can't be ambiguous */
-
 
747
				e = cast_token ( t, a, err, err2, cast ) ;
-
 
748
				if ( !IS_NULL_exp ( e ) ) return ( e ) ;
-
 
749
				add_error ( err, ERR_conv_ptr_ambiguous () ) ;
867
				opt = OPT_conv_ptr_ptr_expl;
750
			    }
-
 
751
			    err2 = check_virt_base ( gr ) ;
-
 
752
			    if ( !IS_NULL_err ( err2 ) ) {
-
 
753
				/* Can't be virtual */
-
 
754
				e = cast_token ( t, a, err, err2, cast ) ;
-
 
755
				if ( !IS_NULL_exp ( e ) ) return ( e ) ;
-
 
756
				add_error ( err, ERR_expr_cast_stat_virt () ) ;
-
 
757
			    }
-
 
758
			    if ( !( cast & CAST_BAD ) ) {
-
 
759
				/* Check base access */
-
 
760
				check_base_access ( gr ) ;
-
 
761
			    }
868
			} else {
762
			    off = DEREF_off ( graph_off ( gr ) ) ;
-
 
763
			    conv = ( CONV_PTR_BASE | CONV_REVERSE ) ;
-
 
764
			    opt = OPT_none ;
869
				opt = OPT_conv_ptr_ptr_impl;
765
			    break ;
-
 
766
			}
870
			}
-
 
871
			conv = CONV_FUNC;
767
		    }
872
			break;
768
		}
873
		}
-
 
874
		case type_integer_tag: {
-
 
875
			/* Check for generic pointers */
-
 
876
			TYPE r = type_void_star;
-
 
877
			r = type_composite(t, r, 1, 0, &ferr, 0);
-
 
878
			if (!IS_NULL_type(r)) {
-
 
879
				goto generic_lab;
-
 
880
			}
769
		goto default_lab ;
881
			goto default_lab;
770
	    }
882
		}
-
 
883
		default:
771
	    case type_func_tag : {
884
default_lab:
772
		if ( ns != type_func_tag ) {
885
			if (ns == type_func_tag) {
773
		    /* Conversion from 'function *' to 'object *' */
886
				/* Conversion from 'function *' to 'object *' */
774
		    ERROR err2 = ERR_expr_cast_reint_func_ptr ( s, t ) ;
887
				ERROR err2 = ERR_expr_cast_reint_func_ptr(s, t);
775
		    if ( !IS_NULL_err ( err2 ) ) {
888
				if (!IS_NULL_err(err2)) {
776
			e = cast_token ( t, a, err, err2, cast ) ;
889
					e = cast_token(t, a, err, err2, cast);
777
			if ( !IS_NULL_exp ( e ) ) return ( e ) ;
890
					if (!IS_NULL_exp(e)) {
-
 
891
						return (e);
778
		    }
892
					}
-
 
893
				}
-
 
894
			}
779
		    goto object_lab ;
895
			goto object_lab;
-
 
896
object_lab: {
-
 
897
			TYPE r = NULL_type;
-
 
898
			if (ns == type_integer_tag) {
-
 
899
				/* Check for generic pointers */
-
 
900
				r = type_void_star;
-
 
901
				r = type_composite(s, r, 1, 0, &ferr, 0);
780
		}
902
			}
-
 
903
			if (IS_NULL_type(r)) {
-
 
904
				if (ns != type_top_tag &&
-
 
905
				    ns != type_bottom_tag) {
781
		/* Conversion from 'function *' to 'function *' */
906
					/* Conversion from 'object *' to
-
 
907
					 * 'object *' */
782
		if ( cast & CAST_REINTERP ) {
908
					if (cast & CAST_REINTERP) {
783
		    opt = OPT_conv_ptr_ptr_expl ;
909
						opt = OPT_conv_ptr_ptr_expl;
784
		} else {
910
					} else {
785
		    opt = OPT_conv_ptr_ptr_impl ;
911
						opt = OPT_conv_ptr_ptr_impl;
786
		}
912
					}
787
		conv = CONV_FUNC ;
913
					break;
788
		break ;
914
				}
789
	    }
915
			}
790
	    case type_integer_tag : {
916
			/* Conversion from 'void *' to 'object *' */
791
		/* Check for generic pointers */
917
			if (cast == CAST_IMPLICIT) {
792
		TYPE r = type_void_star ;
918
				opt = OPT_conv_ptr_void_ptr;
793
		r = type_composite ( t, r, 1, 0, &ferr, 0 ) ;
919
			} else if (cast == CAST_CONST) {
794
		if ( !IS_NULL_type ( r ) ) goto generic_lab ;
-
 
795
		goto default_lab ;
920
				opt = OPT_error;
796
	    }
921
			} else {
797
	    default :
922
				opt = OPT_none;
798
	    default_lab : {
923
			}
799
		if ( ns == type_func_tag ) {
-
 
800
		    /* Conversion from 'function *' to 'object *' */
-
 
801
		    ERROR err2 = ERR_expr_cast_reint_func_ptr ( s, t ) ;
-
 
802
		    if ( !IS_NULL_err ( err2 ) ) {
924
			if (IS_NULL_type(r)) {
803
			e = cast_token ( t, a, err, err2, cast ) ;
-
 
804
			if ( !IS_NULL_exp ( e ) ) return ( e ) ;
925
				conv = (CONV_PTR_VOID | CONV_REVERSE);
805
		    }
-
 
806
		}
926
			}
807
		goto object_lab ;
927
			break;
808
	    }
928
	    }
-
 
929
		}
-
 
930
 
809
	    object_lab : {
931
		/* Add generic pointer errors */
810
		TYPE r = NULL_type ;
932
		if (!IS_NULL_err(ferr)) {
811
		if ( ns == type_integer_tag ) {
933
			if (opt == OPT_none) {
-
 
934
				destroy_error(ferr, 1);
-
 
935
			} else {
-
 
936
				add_error(err, ferr);
-
 
937
			}
-
 
938
		}
-
 
939
 
812
		    /* Check for generic pointers */
940
		/* Check for function linkage conversions */
-
 
941
		if ((qual & QUAL_FUNC) && opt == OPT_conv_ptr_ptr_impl) {
813
		    r = type_void_star ;
942
			opt = OPT_func_linkage;
-
 
943
		}
-
 
944
	}
-
 
945
 
-
 
946
	/* Report any conversion errors */
-
 
947
	if (option(opt)) {
-
 
948
		ERROR err2;
-
 
949
		switch (opt) {
-
 
950
		case OPT_func_linkage: {
-
 
951
			err2 = ERR_dcl_link_conv();
-
 
952
			break;
-
 
953
		}
-
 
954
		case OPT_conv_ptr_ptr_expl:
-
 
955
		case OPT_conv_ptr_ptr_impl: {
814
		    r = type_composite ( s, r, 1, 0, &ferr, 0 ) ;
956
			err2 = ERR_basic_link_incompat(ps, pt);
-
 
957
			err2 = concat_error(err2, ERR_conv_ptr_incompat());
-
 
958
			break;
-
 
959
		}
-
 
960
		default : {
-
 
961
			err2 = ERR_conv_ptr_cast(s, t);
-
 
962
			break;
-
 
963
		}
815
		}
964
		}
-
 
965
		err2 = set_severity(err2, opt, 0);
816
		if ( IS_NULL_type ( r ) ) {
966
		if (!IS_NULL_err(err2)) {
-
 
967
			e = cast_token(t, a, err, err2, cast);
-
 
968
			if (!IS_NULL_exp(e)) {
-
 
969
				return (e);
-
 
970
			}
-
 
971
		}
-
 
972
	}
-
 
973
	if (qual != QUAL_OK) {
-
 
974
		cast_away_const(qual, err, cast);
-
 
975
	}
-
 
976
 
-
 
977
	/* Construct the result */
-
 
978
	if (IS_exp_null(a)) {
-
 
979
		/* Deal with null pointers */
-
 
980
		e = make_null_exp(t);
-
 
981
	} else if (conv == CONV_PTR_BASE) {
-
 
982
		/* Deal with base class conversions */
-
 
983
		e = make_base_cast(t, a, off);
-
 
984
		if (force) {
-
 
985
			/* Force pointer cast */
-
 
986
			conv = (CONV_PTR_PTR | CONV_REVERSE);
-
 
987
			MAKE_exp_cast(t, conv, e, e);
-
 
988
		}
817
		    if ( ns != type_top_tag && ns != type_bottom_tag ) {
989
	} else if (conv == (CONV_PTR_BASE | CONV_REVERSE)) {
818
			/* Conversion from 'object *' to 'object *' */
990
		/* Deal with reverse base class conversions */
-
 
991
		MAKE_exp_cast(t, CONV_PTR_PTR, a, a);
-
 
992
		if (is_zero_offset(off)) {
-
 
993
			e = a;
-
 
994
		} else {
-
 
995
			MAKE_exp_dummy(t, a, LINK_NONE, NULL_off, 1, a);
-
 
996
			MAKE_exp_base_cast(t, conv, a, off, e);
-
 
997
			if (force) {
-
 
998
				/* Force pointer cast */
-
 
999
				conv = (CONV_PTR_PTR | CONV_REVERSE);
-
 
1000
				MAKE_exp_cast(t, conv, e, e);
-
 
1001
			}
-
 
1002
		}
-
 
1003
	} else {
819
			if ( cast & CAST_REINTERP ) {
1004
		if (conv == CONV_NONE) {
-
 
1005
			if (eq_type_offset(pt, ps)) {
820
			    opt = OPT_conv_ptr_ptr_expl ;
1006
				conv = CONV_PTR_PTR_ALIGN;
821
			} else {
1007
			} else {
822
			    opt = OPT_conv_ptr_ptr_impl ;
1008
				conv = CONV_PTR_PTR;
823
			}
1009
			}
824
			break ;
-
 
825
		    }
-
 
826
		}
-
 
827
		/* Conversion from 'void *' to 'object *' */
-
 
828
		if ( cast == CAST_IMPLICIT ) {
-
 
829
		    opt = OPT_conv_ptr_void_ptr ;
-
 
830
		} else if ( cast == CAST_CONST ) {
-
 
831
		    opt = OPT_error ;
-
 
832
		} else {
-
 
833
		    opt = OPT_none ;
-
 
834
		}
-
 
835
		if ( IS_NULL_type ( r ) ) {
-
 
836
		    conv = ( CONV_PTR_VOID | CONV_REVERSE ) ;
-
 
837
		}
1010
		}
838
		break ;
-
 
839
	    }
-
 
840
	}
-
 
841
 
-
 
842
	/* Add generic pointer errors */
-
 
843
	if ( !IS_NULL_err ( ferr ) ) {
-
 
844
	    if ( opt == OPT_none ) {
-
 
845
		destroy_error ( ferr, 1 ) ;
-
 
846
	    } else {
-
 
847
		add_error ( err, ferr ) ;
-
 
848
	    }
-
 
849
	}
-
 
850
 
-
 
851
	/* Check for function linkage conversions */
-
 
852
	if ( ( qual & QUAL_FUNC ) && opt == OPT_conv_ptr_ptr_impl ) {
-
 
853
	    opt = OPT_func_linkage ;
-
 
854
	}
-
 
855
    }
-
 
856
 
-
 
857
    /* Report any conversion errors */
-
 
858
    if ( option ( opt ) ) {
-
 
859
	ERROR err2 ;
-
 
860
	switch ( opt ) {
-
 
861
	    case OPT_func_linkage : {
-
 
862
		err2 = ERR_dcl_link_conv () ;
-
 
863
		break ;
-
 
864
	    }
-
 
865
	    case OPT_conv_ptr_ptr_expl :
-
 
866
	    case OPT_conv_ptr_ptr_impl : {
-
 
867
		err2 = ERR_basic_link_incompat ( ps, pt ) ;
-
 
868
		err2 = concat_error ( err2, ERR_conv_ptr_incompat () ) ;
-
 
869
		break ;
-
 
870
	    }
-
 
871
	    default : {
-
 
872
		err2 = ERR_conv_ptr_cast ( s, t ) ;
-
 
873
		break ;
-
 
874
	    }
-
 
875
	}
-
 
876
	err2 = set_severity ( err2, opt, 0 ) ;
-
 
877
	if ( !IS_NULL_err ( err2 ) ) {
-
 
878
	    e = cast_token ( t, a, err, err2, cast ) ;
-
 
879
	    if ( !IS_NULL_exp ( e ) ) return ( e ) ;
-
 
880
	}
-
 
881
    }
-
 
882
    if ( qual != QUAL_OK ) cast_away_const ( qual, err, cast ) ;
-
 
883
 
-
 
884
    /* Construct the result */
-
 
885
    if ( IS_exp_null ( a ) ) {
-
 
886
	/* Deal with null pointers */
-
 
887
	e = make_null_exp ( t ) ;
-
 
888
    } else if ( conv == CONV_PTR_BASE ) {
-
 
889
	/* Deal with base class conversions */
-
 
890
	e = make_base_cast ( t, a, off ) ;
-
 
891
	if ( force ) {
-
 
892
	    /* Force pointer cast */
-
 
893
	    conv = ( CONV_PTR_PTR | CONV_REVERSE ) ;
-
 
894
	    MAKE_exp_cast ( t, conv, e, e ) ;
-
 
895
	}
-
 
896
    } else if ( conv == ( CONV_PTR_BASE | CONV_REVERSE ) ) {
-
 
897
	/* Deal with reverse base class conversions */
-
 
898
	MAKE_exp_cast ( t, CONV_PTR_PTR, a, a ) ;
-
 
899
	if ( is_zero_offset ( off ) ) {
-
 
900
	    e = a ;
-
 
901
	} else {
-
 
902
	    MAKE_exp_dummy ( t, a, LINK_NONE, NULL_off, 1, a ) ;
-
 
903
	    MAKE_exp_base_cast ( t, conv, a, off, e ) ;
-
 
904
	    if ( force ) {
-
 
905
		/* Force pointer cast */
-
 
906
		conv = ( CONV_PTR_PTR | CONV_REVERSE ) ;
-
 
907
		MAKE_exp_cast ( t, conv, e, e ) ;
1011
		MAKE_exp_cast(t, conv, a, e);
908
	    }
-
 
909
	}
-
 
910
    } else {
-
 
911
	if ( conv == CONV_NONE ) {
-
 
912
	    if ( eq_type_offset ( pt, ps ) ) {
-
 
913
		conv = CONV_PTR_PTR_ALIGN ;
-
 
914
	    } else {
-
 
915
		conv = CONV_PTR_PTR ;
-
 
916
	    }
-
 
917
	}
1012
	}
918
	MAKE_exp_cast ( t, conv, a, e ) ;
-
 
919
    }
-
 
920
    return ( e ) ;
1013
	return (e);
921
}
1014
}
922
 
1015
 
923
 
1016
 
924
/*
1017
/*
925
    PERFORM A INTEGER-POINTER CONVERSION
1018
    PERFORM A INTEGER-POINTER CONVERSION
926
 
1019
 
927
    This routine converts the integral expression a to the pointer type t.
1020
    This routine converts the integral expression a to the pointer type t.
928
    There are two cases, depending on whether a represents a null pointer.
1021
    There are two cases, depending on whether a represents a null pointer.
929
*/
1022
*/
930
 
1023
 
931
static EXP cast_int_ptr
1024
static EXP
932
    PROTO_N ( ( t, a, err, cast, nptr ) )
-
 
933
    PROTO_T ( TYPE t X EXP a X ERROR *err X unsigned cast X int nptr )
1025
cast_int_ptr(TYPE t, EXP a, ERROR *err, unsigned cast, int nptr)
934
{
1026
{
935
    EXP e ;
1027
	EXP e;
936
    int opt ;
1028
	int opt;
937
    if ( nptr && ( cast == CAST_IMPLICIT || ( cast & CAST_STATIC ) ) ) {
1029
	if (nptr && (cast == CAST_IMPLICIT || (cast & CAST_STATIC))) {
938
	/* Deal with null pointers */
1030
		/* Deal with null pointers */
939
	EXP b = make_null_ptr ( a, t ) ;
1031
		EXP b = make_null_ptr(a, t);
940
	if ( !IS_NULL_exp ( b ) ) return ( b ) ;
1032
		if (!IS_NULL_exp(b)) {
-
 
1033
			return (b);
941
    }
1034
		}
-
 
1035
	}
942
    if ( cast & CAST_REINTERP ) {
1036
	if (cast & CAST_REINTERP) {
943
	opt = OPT_conv_int_ptr_expl ;
1037
		opt = OPT_conv_int_ptr_expl;
944
    } else {
1038
	} else {
945
	opt = OPT_conv_int_ptr_impl ;
1039
		opt = OPT_conv_int_ptr_impl;
946
    }
1040
	}
947
    if ( option ( opt ) ) {
1041
	if (option(opt)) {
948
	TYPE s = DEREF_type ( exp_type ( a ) ) ;
1042
		TYPE s = DEREF_type(exp_type(a));
949
	ERROR err2 = ERR_conv_ptr_nonzero ( s, t ) ;
1043
		ERROR err2 = ERR_conv_ptr_nonzero(s, t);
950
	err2 = set_severity ( err2, opt, 0 ) ;
1044
		err2 = set_severity(err2, opt, 0);
951
	if ( !IS_NULL_err ( err2 ) ) {
1045
		if (!IS_NULL_err(err2)) {
952
	    e = cast_token ( t, a, err, err2, cast ) ;
1046
			e = cast_token(t, a, err, err2, cast);
953
	    if ( !IS_NULL_exp ( e ) ) return ( e ) ;
1047
			if (!IS_NULL_exp(e)) {
-
 
1048
				return (e);
-
 
1049
			}
954
	}
1050
		}
955
    }
1051
	}
956
    MAKE_exp_cast ( t, CONV_INT_PTR, a, e ) ;
1052
	MAKE_exp_cast(t, CONV_INT_PTR, a, e);
957
    return ( e ) ;
1053
	return (e);
958
}
1054
}
959
 
1055
 
960
 
1056
 
961
/*
1057
/*
962
    PERFORM A POINTER-INTEGER CONVERSION
1058
    PERFORM A POINTER-INTEGER CONVERSION
963
 
1059
 
964
    This routine converts the pointer expression a to the integral type t
1060
    This routine converts the pointer expression a to the integral type t
965
    (which will not be bool).
1061
    (which will not be bool).
966
*/
1062
*/
967
 
1063
 
968
static EXP cast_ptr_int
1064
static EXP
969
    PROTO_N ( ( t, a, err, cast ) )
-
 
970
    PROTO_T ( TYPE t X EXP a X ERROR *err X unsigned cast )
1065
cast_ptr_int(TYPE t, EXP a, ERROR *err, unsigned cast)
971
{
1066
{
972
    EXP e ;
1067
	EXP e;
973
    int opt ;
1068
	int opt;
974
    if ( IS_exp_null ( a ) ) {
1069
	if (IS_exp_null(a)) {
975
	if ( cast & CAST_STATIC ) {
1070
		if (cast & CAST_STATIC) {
976
	    MAKE_exp_cast ( t, CONV_NULL, a, e ) ;
1071
			MAKE_exp_cast(t, CONV_NULL, a, e);
977
	    return ( e ) ;
1072
			return (e);
978
	}
1073
		}
979
    }
1074
	}
980
    if ( cast & CAST_REINTERP ) {
1075
	if (cast & CAST_REINTERP) {
981
	opt = OPT_conv_int_ptr_expl ;
1076
		opt = OPT_conv_int_ptr_expl;
982
    } else {
1077
	} else {
983
	opt = OPT_conv_int_ptr_impl ;
1078
		opt = OPT_conv_int_ptr_impl;
984
    }
1079
	}
985
    if ( option ( opt ) ) {
1080
	if (option(opt)) {
986
	TYPE s = DEREF_type ( exp_type ( a ) ) ;
1081
		TYPE s = DEREF_type(exp_type(a));
987
	ERROR err2 = ERR_expr_cast_reint_ptr_int ( s, t ) ;
1082
		ERROR err2 = ERR_expr_cast_reint_ptr_int(s, t);
988
	if ( !IS_NULL_err ( err2 ) ) {
1083
		if (!IS_NULL_err(err2)) {
989
	    e = cast_token ( t, a, err, err2, cast ) ;
1084
			e = cast_token(t, a, err, err2, cast);
990
	    if ( !IS_NULL_exp ( e ) ) return ( e ) ;
1085
			if (!IS_NULL_exp(e)) {
-
 
1086
				return (e);
-
 
1087
			}
991
	}
1088
		}
992
    }
1089
	}
993
    MAKE_exp_cast ( t, CONV_PTR_INT, a, e ) ;
1090
	MAKE_exp_cast(t, CONV_PTR_INT, a, e);
994
    return ( e ) ;
1091
	return (e);
995
}
1092
}
996
 
1093
 
997
 
1094
 
998
/*
1095
/*
999
    PERFORM A POINTER MEMBER-POINTER MEMBER CONVERSION
1096
    PERFORM A POINTER MEMBER-POINTER MEMBER CONVERSION
1000
 
1097
 
1001
    This routine converts the pointer to member expression a to the pointer
1098
    This routine converts the pointer to member expression a to the pointer
1002
    to member type t.  force is as in cast_ptr_ptr.
1099
    to member type t.  force is as in cast_ptr_ptr.
1003
*/
1100
*/
1004
 
1101
 
1005
EXP cast_ptr_mem_ptr_mem
1102
EXP
1006
    PROTO_N ( ( t, a, err, cast, safe, force ) )
-
 
1007
    PROTO_T ( TYPE t X EXP a X ERROR *err X unsigned cast X
1103
cast_ptr_mem_ptr_mem(TYPE t, EXP a, ERROR *err, unsigned cast, int safe,
1008
	      int safe X int force )
1104
		     int force)
1009
{
1105
{
1010
    EXP e ;
1106
	EXP e;
1011
    int ok = 2 ;
1107
	int ok = 2;
1012
    unsigned conv = CONV_EXACT ;
1108
	unsigned conv = CONV_EXACT;
1013
    TYPE s = DEREF_type ( exp_type ( a ) ) ;
1109
	TYPE s = DEREF_type(exp_type(a));
1014
 
1110
 
1015
    if ( cast != CAST_REINTERP ) {
1111
	if (cast != CAST_REINTERP) {
1016
	/* Check for base class conversions */
1112
		/* Check for base class conversions */
1017
	OFFSET off = NULL_off ;
1113
		OFFSET off = NULL_off;
1018
	CLASS_TYPE ct = DEREF_ctype ( type_ptr_mem_of ( t ) ) ;
1114
		CLASS_TYPE ct = DEREF_ctype(type_ptr_mem_of(t));
1019
	CLASS_TYPE cs = DEREF_ctype ( type_ptr_mem_of ( s ) ) ;
1115
		CLASS_TYPE cs = DEREF_ctype(type_ptr_mem_of(s));
1020
	if ( !eq_ctype ( ct, cs ) ) {
1116
		if (!eq_ctype(ct, cs)) {
1021
	    GRAPH gr = find_base_class ( ct, cs, 1 ) ;
1117
			GRAPH gr = find_base_class(ct, cs, 1);
1022
	    if ( !IS_NULL_graph ( gr ) ) {
1118
			if (!IS_NULL_graph(gr)) {
1023
		/* cs is a base class of ct */
1119
				/* cs is a base class of ct */
1024
		ERROR err2 = check_ambig_base ( gr ) ;
1120
				ERROR err2 = check_ambig_base(gr);
1025
		if ( !IS_NULL_err ( err2 ) ) {
1121
				if (!IS_NULL_err(err2)) {
1026
		    /* Can't be ambiguous */
1122
					/* Can't be ambiguous */
1027
		    e = cast_token ( t, a, err, err2, cast ) ;
1123
					e = cast_token(t, a, err, err2, cast);
1028
		    if ( !IS_NULL_exp ( e ) ) return ( e ) ;
1124
					if (!IS_NULL_exp(e)) {
-
 
1125
						return (e);
-
 
1126
					}
1029
		    add_error ( err, ERR_conv_mem_ambiguous () ) ;
1127
					add_error(err, ERR_conv_mem_ambiguous());
1030
		}
1128
				}
1031
		err2 = check_virt_base ( gr ) ;
1129
				err2 = check_virt_base(gr);
1032
		if ( !IS_NULL_err ( err2 ) ) {
1130
				if (!IS_NULL_err(err2)) {
1033
		    /* Can't be virtual */
1131
					/* Can't be virtual */
1034
		    e = cast_token ( t, a, err, err2, cast ) ;
1132
					e = cast_token(t, a, err, err2, cast);
1035
		    if ( !IS_NULL_exp ( e ) ) return ( e ) ;
1133
					if (!IS_NULL_exp(e)) {
-
 
1134
						return (e);
-
 
1135
					}
1036
		    add_error ( err, ERR_conv_mem_virtual () ) ;
1136
					add_error(err, ERR_conv_mem_virtual());
-
 
1137
				}
-
 
1138
				if (!(cast & CAST_BAD)) {
-
 
1139
					/* Check base access */
-
 
1140
					check_base_access(gr);
-
 
1141
				}
-
 
1142
				off = DEREF_off(graph_off(gr));
-
 
1143
				conv = CONV_PTR_MEM_BASE;
-
 
1144
				ok = 1;
-
 
1145
			} else {
-
 
1146
				/* cs is not a base class of ct */
-
 
1147
				if (cast & CAST_STATIC) {
-
 
1148
					gr = find_base_class(cs, ct, 1);
-
 
1149
					if (!IS_NULL_graph(gr)) {
-
 
1150
						/* ct is a base class of cs */
-
 
1151
						ERROR err2 = check_ambig_base(gr);
-
 
1152
						if (!IS_NULL_err(err2)) {
-
 
1153
							/* Can't be ambiguous */
-
 
1154
							e = cast_token(t, a, err, err2, cast);
-
 
1155
							if (!IS_NULL_exp(e)) {
-
 
1156
								return (e);
-
 
1157
							}
-
 
1158
							add_error(err, ERR_conv_mem_ambiguous());
-
 
1159
						}
-
 
1160
						err2 = check_virt_base(gr);
-
 
1161
						if (!IS_NULL_err(err2)) {
-
 
1162
							/* Can't be virtual */
-
 
1163
							e = cast_token(t, a, err, err2, cast);
-
 
1164
							if (!IS_NULL_exp(e)) {
-
 
1165
								return (e);
-
 
1166
							}
-
 
1167
							add_error(err, ERR_conv_mem_virtual());
-
 
1168
						}
-
 
1169
						if (!(cast & CAST_BAD)) {
-
 
1170
							/* Check base access */
-
 
1171
							check_base_access(gr);
-
 
1172
						}
-
 
1173
						off = DEREF_off(graph_off(gr));
-
 
1174
						conv = (CONV_PTR_MEM_BASE | CONV_REVERSE);
-
 
1175
						ok = 1;
-
 
1176
					} else {
-
 
1177
						ok = 0;
-
 
1178
					}
-
 
1179
				} else {
-
 
1180
					ok = 0;
-
 
1181
				}
-
 
1182
			}
-
 
1183
 
-
 
1184
			if (ok == 0 && in_template_decl) {
-
 
1185
				/* Allow for template parameter types */
-
 
1186
				TYPE ft = DEREF_type(ctype_form(ct));
-
 
1187
				TYPE fs = DEREF_type(ctype_form(cs));
-
 
1188
				if (is_templ_depend(ft) ||
-
 
1189
				    is_templ_depend(fs)) {
-
 
1190
					/* Check further */
-
 
1191
					ok = -1;
-
 
1192
				}
-
 
1193
			}
-
 
1194
		}
-
 
1195
 
-
 
1196
		/* Check for qualification conversions */
-
 
1197
		if (ok) {
-
 
1198
			unsigned qual;
-
 
1199
			TYPE pt = DEREF_type(type_ptr_mem_sub(t));
-
 
1200
			TYPE ps = DEREF_type(type_ptr_mem_sub(s));
-
 
1201
			if (IS_type_token(pt)) {
-
 
1202
				t = expand_type(t, 1);
-
 
1203
			}
-
 
1204
			if (IS_type_token(ps)) {
-
 
1205
				s = expand_type(s, 1);
-
 
1206
			}
-
 
1207
			qual = check_qualifier(t, s, safe);
-
 
1208
			if (qual == QUAL_EQUAL) {
-
 
1209
				/* Type equality */
-
 
1210
				if (ok == 2) {
-
 
1211
					if (cast != CAST_IMPLICIT) {
-
 
1212
						a = cast_exact(t, a);
-
 
1213
					}
-
 
1214
					return (a);
-
 
1215
				}
-
 
1216
				qual = QUAL_OK;
-
 
1217
			} else if (qual == QUAL_EQ_FUNC) {
-
 
1218
				/* Function type equality */
-
 
1219
				if (!(cast & CAST_REINTERP) &&
-
 
1220
				    !eq_except(ps, pt)) {
-
 
1221
					/* Exception specifications don't
-
 
1222
					 * match */
-
 
1223
					add_error(err, ERR_except_spec_assign());
-
 
1224
				}
-
 
1225
				if (ok == 2) {
-
 
1226
					e = cast_exact(t, a);
-
 
1227
					return (e);
-
 
1228
				}
-
 
1229
				qual = QUAL_OK;
-
 
1230
			}
-
 
1231
			if ((qual & QUAL_TEMPL) || ok == -1) {
-
 
1232
				/* Conversion depends on template parameter */
-
 
1233
				e = cast_templ_type(t, a, cast);
-
 
1234
				return (e);
-
 
1235
			}
-
 
1236
			if (qual & QUAL_SIMILAR) {
-
 
1237
				/* Check for casting away const-ness */
-
 
1238
				if (qual != QUAL_OK) {
-
 
1239
					cast_away_const(qual, err, cast);
-
 
1240
				}
-
 
1241
				if (ok == 2) {
-
 
1242
					MAKE_exp_cast(t, CONV_QUAL, a, e);
-
 
1243
				} else {
-
 
1244
					MAKE_exp_dummy(s, a, LINK_NONE, NULL_off, 1, a);
-
 
1245
					MAKE_exp_base_cast(t, conv, a, off, e);
-
 
1246
					UNUSED(force);
-
 
1247
				}
-
 
1248
				return (e);
-
 
1249
			}
-
 
1250
			ok = 0;
-
 
1251
		}
-
 
1252
	}
-
 
1253
 
-
 
1254
	/* Check for reinterpret conversions */
-
 
1255
	conv = CONV_NONE;
-
 
1256
	if (cast & CAST_REINTERP) {
-
 
1257
		unsigned nt = TAG_type(t);
-
 
1258
		unsigned ns = TAG_type(s);
-
 
1259
		if (nt == type_func_tag) {
-
 
1260
			ok = (ns == type_func_tag ? 1 : 0);
-
 
1261
		} else {
-
 
1262
			ok = (ns == type_func_tag ? 0 : 1);
1037
		}
1263
		}
-
 
1264
		if (ok) {
1038
		if ( !( cast & CAST_BAD ) ) {
1265
			unsigned qual = check_qualifier(t, s, safe);
1039
		    /* Check base access */
1266
			if (qual != QUAL_OK) {
1040
		    check_base_access ( gr ) ;
1267
				cast_away_const(qual, err, cast);
1041
		}
1268
			}
1042
		off = DEREF_off ( graph_off ( gr ) ) ;
-
 
1043
		conv = CONV_PTR_MEM_BASE ;
1269
			conv = CONV_PTR_MEM_PTR_MEM;
1044
		ok = 1 ;
1270
		}
1045
	    } else {
1271
	}
-
 
1272
 
1046
		/* cs is not a base class of ct */
1273
	/* Invalid cast expression */
1047
		if ( cast & CAST_STATIC ) {
1274
	if (!ok) {
1048
		    gr = find_base_class ( cs, ct, 1 ) ;
-
 
1049
		    if ( !IS_NULL_graph ( gr ) ) {
-
 
1050
			/* ct is a base class of cs */
-
 
1051
			ERROR err2 = check_ambig_base ( gr ) ;
1275
		ERROR err2 = ERR_conv_mem_cast(s, t);
1052
			if ( !IS_NULL_err ( err2 ) ) {
1276
		if (!IS_NULL_err(err2)) {
1053
			    /* Can't be ambiguous */
-
 
1054
			    e = cast_token ( t, a, err, err2, cast ) ;
1277
			e = cast_token(t, a, err, err2, cast);
1055
			    if ( !IS_NULL_exp ( e ) ) return ( e ) ;
-
 
1056
			    add_error ( err, ERR_conv_mem_ambiguous () ) ;
-
 
1057
			}
-
 
1058
			err2 = check_virt_base ( gr ) ;
-
 
1059
			if ( !IS_NULL_err ( err2 ) ) {
1278
			if (!IS_NULL_exp(e)) {
1060
			    /* Can't be virtual */
1279
				return (e);
1061
			    e = cast_token ( t, a, err, err2, cast ) ;
-
 
1062
			    if ( !IS_NULL_exp ( e ) ) return ( e ) ;
-
 
1063
			    add_error ( err, ERR_conv_mem_virtual () ) ;
-
 
1064
			}
1280
			}
1065
			if ( !( cast & CAST_BAD ) ) {
-
 
1066
			    /* Check base access */
-
 
1067
			    check_base_access ( gr ) ;
-
 
1068
			}
-
 
1069
			off = DEREF_off ( graph_off ( gr ) ) ;
-
 
1070
			conv = ( CONV_PTR_MEM_BASE | CONV_REVERSE ) ;
-
 
1071
			ok = 1 ;
-
 
1072
		    } else {
-
 
1073
			ok = 0 ;
-
 
1074
		    }
-
 
1075
		} else {
-
 
1076
		    ok = 0 ;
-
 
1077
		}
1281
		}
1078
	    }
-
 
1079
 
-
 
1080
	    if ( ok == 0 && in_template_decl ) {
-
 
1081
		/* Allow for template parameter types */
-
 
1082
		TYPE ft = DEREF_type ( ctype_form ( ct ) ) ;
-
 
1083
		TYPE fs = DEREF_type ( ctype_form ( cs ) ) ;
-
 
1084
		if ( is_templ_depend ( ft ) || is_templ_depend ( fs ) ) {
-
 
1085
		    /* Check further */
-
 
1086
		    ok = -1 ;
-
 
1087
		}
-
 
1088
	    }
-
 
1089
	}
-
 
1090
 
-
 
1091
	/* Check for qualification conversions */
-
 
1092
	if ( ok ) {
-
 
1093
	    unsigned qual ;
-
 
1094
	    TYPE pt = DEREF_type ( type_ptr_mem_sub ( t ) ) ;
-
 
1095
	    TYPE ps = DEREF_type ( type_ptr_mem_sub ( s ) ) ;
-
 
1096
	    if ( IS_type_token ( pt ) ) {
-
 
1097
		t = expand_type ( t, 1 ) ;
-
 
1098
	    }
-
 
1099
	    if ( IS_type_token ( ps ) ) {
-
 
1100
		s = expand_type ( s, 1 ) ;
-
 
1101
	    }
-
 
1102
	    qual = check_qualifier ( t, s, safe ) ;
-
 
1103
	    if ( qual == QUAL_EQUAL ) {
-
 
1104
		/* Type equality */
-
 
1105
		if ( ok == 2 ) {
-
 
1106
		    if ( cast != CAST_IMPLICIT ) a = cast_exact ( t, a ) ;
-
 
1107
		    return ( a ) ;
-
 
1108
		}
-
 
1109
		qual = QUAL_OK ;
-
 
1110
	    } else if ( qual == QUAL_EQ_FUNC ) {
-
 
1111
		/* Function type equality */
-
 
1112
		if ( !( cast & CAST_REINTERP ) && !eq_except ( ps, pt ) ) {
-
 
1113
		    /* Exception specifications don't match */
-
 
1114
		    add_error ( err, ERR_except_spec_assign () ) ;
-
 
1115
		}
-
 
1116
		if ( ok == 2 ) {
-
 
1117
		    e = cast_exact ( t, a ) ;
-
 
1118
		    return ( e ) ;
-
 
1119
		}
-
 
1120
		qual = QUAL_OK ;
-
 
1121
	    }
-
 
1122
	    if ( ( qual & QUAL_TEMPL ) || ok == -1 ) {
-
 
1123
		/* Conversion depends on template parameter */
-
 
1124
		e = cast_templ_type ( t, a, cast ) ;
-
 
1125
		return ( e ) ;
-
 
1126
	    }
-
 
1127
	    if ( qual & QUAL_SIMILAR ) {
-
 
1128
		/* Check for casting away const-ness */
-
 
1129
		if ( qual != QUAL_OK ) {
-
 
1130
		    cast_away_const ( qual, err, cast ) ;
-
 
1131
		}
-
 
1132
		if ( ok == 2 ) {
-
 
1133
		    MAKE_exp_cast ( t, CONV_QUAL, a, e ) ;
-
 
1134
		} else {
-
 
1135
		    MAKE_exp_dummy ( s, a, LINK_NONE, NULL_off, 1, a ) ;
-
 
1136
		    MAKE_exp_base_cast ( t, conv, a, off, e ) ;
-
 
1137
		    UNUSED ( force ) ;
-
 
1138
		}
-
 
1139
		return ( e ) ;
-
 
1140
	    }
-
 
1141
	    ok = 0 ;
-
 
1142
	}
-
 
1143
    }
-
 
1144
 
-
 
1145
    /* Check for reinterpret conversions */
-
 
1146
    conv = CONV_NONE ;
-
 
1147
    if ( cast & CAST_REINTERP ) {
-
 
1148
	unsigned nt = TAG_type ( t ) ;
-
 
1149
	unsigned ns = TAG_type ( s ) ;
-
 
1150
	if ( nt == type_func_tag ) {
-
 
1151
	    ok = ( ns == type_func_tag ? 1 : 0 ) ;
-
 
1152
	} else {
-
 
1153
	    ok = ( ns == type_func_tag ? 0 : 1 ) ;
-
 
1154
	}
-
 
1155
	if ( ok ) {
-
 
1156
	    unsigned qual = check_qualifier ( t, s, safe ) ;
-
 
1157
	    if ( qual != QUAL_OK ) {
-
 
1158
		cast_away_const ( qual, err, cast ) ;
-
 
1159
	    }
-
 
1160
	    conv = CONV_PTR_MEM_PTR_MEM ;
-
 
1161
	}
-
 
1162
    }
-
 
1163
 
-
 
1164
    /* Invalid cast expression */
-
 
1165
    if ( !ok ) {
-
 
1166
	ERROR err2 = ERR_conv_mem_cast ( s, t ) ;
-
 
1167
	if ( !IS_NULL_err ( err2 ) ) {
-
 
1168
	    e = cast_token ( t, a, err, err2, cast ) ;
-
 
1169
	    if ( !IS_NULL_exp ( e ) ) return ( e ) ;
-
 
1170
	}
1282
	}
1171
    }
-
 
1172
    MAKE_exp_cast ( t, conv, a, e ) ;
1283
	MAKE_exp_cast(t, conv, a, e);
1173
    return ( e ) ;
1284
	return (e);
1174
}
1285
}
1175
 
1286
 
1176
 
1287
 
1177
/*
1288
/*
1178
    PERFORM A INTEGER-POINTER MEMBER CONVERSION
1289
    PERFORM A INTEGER-POINTER MEMBER CONVERSION
1179
 
1290
 
1180
    This routine converts the integral expression a to the pointer to
1291
    This routine converts the integral expression a to the pointer to
1181
    member type t.  The only valid case is when a is zero.
1292
    member type t.  The only valid case is when a is zero.
1182
*/
1293
*/
1183
 
1294
 
1184
static EXP cast_int_ptr_mem
1295
static EXP
1185
    PROTO_N ( ( t, a, err, cast, nptr ) )
-
 
1186
    PROTO_T ( TYPE t X EXP a X ERROR *err X unsigned cast X int nptr )
1296
cast_int_ptr_mem(TYPE t, EXP a, ERROR *err, unsigned cast, int nptr)
1187
{
1297
{
1188
    EXP e ;
1298
	EXP e;
1189
    TYPE s ;
1299
	TYPE s;
1190
    ERROR err2 ;
1300
	ERROR err2;
1191
    if ( nptr && ( cast == CAST_IMPLICIT || ( cast & CAST_STATIC ) ) ) {
1301
	if (nptr && (cast == CAST_IMPLICIT || (cast & CAST_STATIC))) {
1192
	/* Deal with null pointers */
1302
		/* Deal with null pointers */
1193
	EXP b = make_null_ptr ( a, t ) ;
1303
		EXP b = make_null_ptr(a, t);
1194
	if ( !IS_NULL_exp ( b ) ) return ( b ) ;
1304
		if (!IS_NULL_exp(b)) {
-
 
1305
			return (b);
1195
    }
1306
		}
-
 
1307
	}
1196
    s = DEREF_type ( exp_type ( a ) ) ;
1308
	s = DEREF_type(exp_type(a));
1197
    err2 = ERR_conv_mem_nonzero ( s, t ) ;
1309
	err2 = ERR_conv_mem_nonzero(s, t);
1198
    if ( !IS_NULL_err ( err2 ) ) {
1310
	if (!IS_NULL_err(err2)) {
1199
	e = cast_token ( t, a, err, err2, cast ) ;
1311
		e = cast_token(t, a, err, err2, cast);
1200
	if ( !IS_NULL_exp ( e ) ) return ( e ) ;
1312
		if (!IS_NULL_exp(e)) {
-
 
1313
			return (e);
1201
    }
1314
		}
-
 
1315
	}
1202
    MAKE_exp_cast ( t, CONV_NONE, a, e ) ;
1316
	MAKE_exp_cast(t, CONV_NONE, a, e);
1203
    return ( e ) ;
1317
	return (e);
1204
}
1318
}
1205
 
1319
 
1206
 
1320
 
1207
/*
1321
/*
1208
    PERFORM A POINTER MEMBER-INTEGER CONVERSION
1322
    PERFORM A POINTER MEMBER-INTEGER CONVERSION
1209
 
1323
 
1210
    This routine converts the pointer to member expression a to the
1324
    This routine converts the pointer to member expression a to the
1211
    integral type t.  The only valid case is when a is a null pointer.
1325
    integral type t.  The only valid case is when a is a null pointer.
1212
    In all other cases the null expression is returned.
1326
    In all other cases the null expression is returned.
1213
*/
1327
*/
1214
 
1328
 
1215
static EXP cast_ptr_mem_int
1329
static EXP
1216
    PROTO_N ( ( t, a, err, cast ) )
-
 
1217
    PROTO_T ( TYPE t X EXP a X ERROR *err X unsigned cast )
1330
cast_ptr_mem_int(TYPE t, EXP a, ERROR *err, unsigned cast)
1218
{
1331
{
1219
    if ( IS_exp_null ( a ) ) {
1332
	if (IS_exp_null(a)) {
1220
	if ( cast & CAST_STATIC ) {
1333
		if (cast & CAST_STATIC) {
1221
	    EXP e ;
1334
			EXP e;
1222
	    MAKE_exp_cast ( t, CONV_NULL, a, e ) ;
1335
			MAKE_exp_cast(t, CONV_NULL, a, e);
1223
	    return ( e ) ;
1336
			return (e);
1224
	}
1337
		}
1225
    }
1338
	}
1226
    UNUSED ( err ) ;
1339
	UNUSED(err);
1227
    return ( NULL_exp ) ;
1340
	return (NULL_exp);
1228
}
1341
}
1229
 
1342
 
1230
 
1343
 
1231
/*
1344
/*
1232
    PERFORM A POINTER MEMBER-POINTER CONVERSION
1345
    PERFORM A POINTER MEMBER-POINTER CONVERSION
1233
 
1346
 
1234
    This routine converts the pointer to member expression a to the
1347
    This routine converts the pointer to member expression a to the
1235
    pointer type t.  The only potentially valid case is casting a pointer
1348
    pointer type t.  The only potentially valid case is casting a pointer
1236
    to member function to a pointer to function.  In all other cases the
1349
    to member function to a pointer to function.  In all other cases the
1237
    null expression is returned.
1350
    null expression is returned.
1238
*/
1351
*/
1239
 
1352
 
1240
static EXP cast_ptr_mem_ptr
1353
static EXP
1241
    PROTO_N ( ( t, a, err, cast ) )
-
 
1242
    PROTO_T ( TYPE t X EXP a X ERROR *err X unsigned cast )
1354
cast_ptr_mem_ptr(TYPE t, EXP a, ERROR *err, unsigned cast)
1243
{
1355
{
1244
    TYPE s = DEREF_type ( exp_type ( a ) ) ;
1356
	TYPE s = DEREF_type(exp_type(a));
1245
    TYPE p = DEREF_type ( type_ptr_mem_sub ( s ) ) ;
1357
	TYPE p = DEREF_type(type_ptr_mem_sub(s));
1246
    TYPE q = DEREF_type ( type_ptr_sub ( t ) ) ;
1358
	TYPE q = DEREF_type(type_ptr_sub(t));
1247
    if ( IS_type_func ( p ) && IS_type_func ( q ) ) {
1359
	if (IS_type_func(p) && IS_type_func(q)) {
1248
	if ( cast & CAST_REINTERP ) {
1360
		if (cast & CAST_REINTERP) {
1249
	    EXP e ;
1361
			EXP e;
1250
	    ERROR err2 = ERR_expr_cast_reint_mem_func ( s, t ) ;
1362
			ERROR err2 = ERR_expr_cast_reint_mem_func(s, t);
1251
	    if ( !IS_NULL_err ( err2 ) ) {
1363
			if (!IS_NULL_err(err2)) {
1252
		e = cast_token ( t, a, err, err2, cast ) ;
1364
				e = cast_token(t, a, err, err2, cast);
1253
		if ( !IS_NULL_exp ( e ) ) return ( e ) ;
1365
				if (!IS_NULL_exp(e)) {
-
 
1366
					return (e);
1254
	    }
1367
				}
-
 
1368
			}
1255
	    MAKE_exp_cast ( t, CONV_PTR_MEM_FUNC, a, e ) ;
1369
			MAKE_exp_cast(t, CONV_PTR_MEM_FUNC, a, e);
1256
	    return ( e ) ;
1370
			return (e);
1257
	}
1371
		}
1258
    }
1372
	}
1259
    return ( NULL_exp ) ;
1373
	return (NULL_exp);
1260
}
1374
}
1261
 
1375
 
1262
 
1376
 
1263
/*
1377
/*
1264
    PERFORM A CLASS-CLASS CONVERSION
1378
    PERFORM A CLASS-CLASS CONVERSION
1265
 
1379
 
1266
    This routine performs any base class conversion of the class object
1380
    This routine performs any base class conversion of the class object
1267
    a to the class t.  ref is true if this is a reference binding.  The
1381
    a to the class t.  ref is true if this is a reference binding.  The
1268
    null expression is returned if no such conversion is possible.
1382
    null expression is returned if no such conversion is possible.
1269
*/
1383
*/
1270
 
1384
 
1271
EXP cast_class_class
1385
EXP
1272
    PROTO_N ( ( t, a, err, cast, ref ) )
-
 
1273
    PROTO_T ( TYPE t X EXP a X ERROR *err X unsigned cast X int ref )
1386
cast_class_class(TYPE t, EXP a, ERROR *err, unsigned cast, int ref)
1274
{
1387
{
1275
    EXP e = NULL_exp ;
1388
	EXP e = NULL_exp;
1276
    TYPE s = DEREF_type ( exp_type ( a ) ) ;
1389
	TYPE s = DEREF_type(exp_type(a));
1277
    CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
1390
	CLASS_TYPE ct = DEREF_ctype(type_compound_defn(t));
1278
    CLASS_TYPE cs = DEREF_ctype ( type_compound_defn ( s ) ) ;
1391
	CLASS_TYPE cs = DEREF_ctype(type_compound_defn(s));
1279
    if ( eq_ctype ( cs, ct ) ) {
1392
	if (eq_ctype(cs, ct)) {
1280
	e = a ;
1393
		e = a;
1281
    } else {
1394
	} else {
1282
	GRAPH gr = find_base_class ( cs, ct, 1 ) ;
1395
		GRAPH gr = find_base_class(cs, ct, 1);
1283
	if ( !IS_NULL_graph ( gr ) ) {
1396
		if (!IS_NULL_graph(gr)) {
1284
	    /* Allow for base class conversions */
1397
			/* Allow for base class conversions */
1285
	    TYPE p ;
1398
			TYPE p;
1286
	    CV_SPEC cv = DEREF_cv ( type_qual ( s ) ) ;
1399
			CV_SPEC cv = DEREF_cv(type_qual(s));
1287
	    OFFSET off = DEREF_off ( graph_off ( gr ) ) ;
1400
			OFFSET off = DEREF_off(graph_off(gr));
1288
	    ERROR err2 = check_ambig_base ( gr ) ;
1401
			ERROR err2 = check_ambig_base(gr);
1289
	    if ( !IS_NULL_err ( err2 ) ) {
1402
			if (!IS_NULL_err(err2)) {
1290
		e = cast_token ( t, a, err, err2, cast ) ;
1403
				e = cast_token(t, a, err, err2, cast);
1291
		if ( !IS_NULL_exp ( e ) ) return ( e ) ;
1404
				if (!IS_NULL_exp(e)) {
-
 
1405
					return (e);
-
 
1406
				}
1292
		add_error ( err, ERR_dcl_init_ref_ambig () ) ;
1407
				add_error(err, ERR_dcl_init_ref_ambig());
1293
	    }
1408
			}
1294
	    check_base_access ( gr ) ;
1409
			check_base_access(gr);
1295
	    p = rvalue_type ( t ) ;
1410
			p = rvalue_type(t);
1296
	    MAKE_type_ptr ( cv_none, p, p ) ;
1411
			MAKE_type_ptr(cv_none, p, p);
1297
	    if ( !( cv & cv_lvalue ) ) {
1412
			if (!(cv & cv_lvalue)) {
1298
		/* Introduce temporary if necessary */
1413
				/* Introduce temporary if necessary */
1299
		a = make_temporary ( s, a, NULL_exp, 0, err ) ;
1414
				a = make_temporary(s, a, NULL_exp, 0, err);
1300
	    }
1415
			}
1301
	    MAKE_exp_address ( p, a, e ) ;
1416
			MAKE_exp_address(p, a, e);
1302
	    e = make_base_cast ( p, e, off ) ;
1417
			e = make_base_cast(p, e, off);
1303
	    t = lvalue_type ( t ) ;
1418
			t = lvalue_type(t);
1304
	    MAKE_exp_indir ( t, e, e ) ;
1419
			MAKE_exp_indir(t, e, e);
1305
	}
1420
		}
1306
    }
1421
	}
1307
    if ( !IS_NULL_exp ( e ) ) {
1422
	if (!IS_NULL_exp(e)) {
1308
	if ( ref ) {
1423
		if (ref) {
1309
	    /* Check cv-qualifiers */
1424
			/* Check cv-qualifiers */
1310
	    CV_SPEC cv = cv_compare ( t, s ) ;
1425
			CV_SPEC cv = cv_compare(t, s);
-
 
1426
			if (cv) {
1311
	    if ( cv ) add_error ( err, ERR_dcl_init_ref_qual ( cv ) ) ;
1427
				add_error(err, ERR_dcl_init_ref_qual(cv));
-
 
1428
			}
1312
	} else {
1429
		} else {
1313
	    e = convert_lvalue ( e ) ;
1430
			e = convert_lvalue(e);
1314
	}
1431
		}
1315
	if ( cast != CAST_IMPLICIT && err != KILL_err ) {
1432
		if (cast != CAST_IMPLICIT && err != KILL_err) {
1316
	    /* Can't have explicit cast in C */
1433
			/* Can't have explicit cast in C */
1317
	    *err = concat_error ( ERR_expr_cast_expl_scalar ( t ), *err ) ;
1434
			*err = concat_error(ERR_expr_cast_expl_scalar(t), *err);
-
 
1435
		}
1318
	}
1436
	}
1319
    }
-
 
1320
    return ( e ) ;
1437
	return (e);
1321
}
1438
}
1322
 
1439
 
1323
 
1440
 
1324
/*
1441
/*
1325
    CONSTRUCT A CAST EXPRESSION
1442
    CONSTRUCT A CAST EXPRESSION
1326
 
1443
 
1327
    This routine constructs a cast expression for converting the expression
1444
    This routine constructs a cast expression for converting the expression
1328
    a to the type t.  Any errors are added to the end of the position given
1445
    a to the type t.  Any errors are added to the end of the position given
1329
    by err.
1446
    by err.
1575
		}
1726
		}
1576
	    }
-
 
1577
	    break ;
1727
		break;
1578
	}
1728
	}
-
 
1729
	}
-
 
1730
 
1579
	case type_ptr_mem_tag : {
1731
	if (IS_NULL_exp(e)) {
1580
	    /* Conversion from pointer to member */
1732
		if (cast != CAST_IMPLICIT) {
1581
	    switch ( nt ) {
1733
			switch (nt) {
-
 
1734
			case type_func_tag:
-
 
1735
			case type_array_tag:
1582
		case type_integer_tag :
1736
			case type_token_tag:
1583
		case type_enumerate_tag : {
1737
			case type_compound_tag: {
1584
		    e = cast_ptr_mem_int ( t, a, err, cast ) ;
1738
				/* Cast to non-scalar type */
-
 
1739
				add_error(err, ERR_expr_cast_expl_scalar(t));
1585
		    break ;
1740
				break;
-
 
1741
			}
-
 
1742
			}
1586
		}
1743
		}
1587
		case type_bitfield_tag : {
1744
		if (ns == type_token_tag || nt == type_token_tag) {
1588
		    TYPE r = find_bitfield_type ( t ) ;
1745
			/* Allow for tokenised types */
-
 
1746
			int ft = force_tokdef;
-
 
1747
			int fs = force_template;
1589
		    e = cast_ptr_mem_int ( r, a, err, cast ) ;
1748
			if (cast != CAST_IMPLICIT) {
-
 
1749
				force_tokdef = 0;
-
 
1750
				force_template = 0;
-
 
1751
			}
1590
		    a = cast_int_int ( t, a, err, cast, -1 ) ;
1752
			if (eq_type_unqual(s, t)) {
1591
		    break ;
1753
				e = a;
-
 
1754
			}
-
 
1755
			force_template = fs;
-
 
1756
			force_tokdef = ft;
1592
		}
1757
		}
-
 
1758
		if (IS_NULL_exp(e)) {
-
 
1759
			/* No other conversions are allowed */
-
 
1760
			if (ns == type_error_tag || nt == type_error_tag) {
1593
		case type_ptr_tag : {
1761
				e = cast_exact(t, a);
-
 
1762
			} else {
-
 
1763
				ERROR err2 = check_incomplete(t);
-
 
1764
				err2 = concat_error(err2, ERR_expr_cast_invalid(s, t));
-
 
1765
				if (!IS_NULL_err(err2)) {
1594
		    e = cast_ptr_mem_ptr ( t, a, err, cast ) ;
1766
					e = cast_token(t, a, err, err2, cast);
-
 
1767
					if (!IS_NULL_exp(e)) {
1595
		    break ;
1768
						return (e);
-
 
1769
					}
-
 
1770
				}
-
 
1771
				MAKE_exp_cast(t, CONV_NONE, a, e);
-
 
1772
			}
1596
		}
1773
		}
1597
		case type_ptr_mem_tag : {
-
 
1598
		    e = cast_ptr_mem_ptr_mem ( t, a, err, cast, 0, 0 ) ;
-
 
1599
		    break ;
-
 
1600
		}
-
 
1601
	    }
-
 
1602
	    break ;
-
 
1603
	}
-
 
1604
	case type_compound_tag : {
-
 
1605
	    if ( nt == type_compound_tag && !usr ) {
-
 
1606
		e = cast_class_class ( t, a, err, cast, 0 ) ;
-
 
1607
	    }
-
 
1608
	    break ;
-
 
1609
	}
-
 
1610
    }
-
 
1611
 
-
 
1612
    if ( IS_NULL_exp ( e ) ) {
-
 
1613
	if ( cast != CAST_IMPLICIT ) {
-
 
1614
	    switch ( nt ) {
-
 
1615
		case type_func_tag :
-
 
1616
		case type_array_tag :
-
 
1617
		case type_token_tag :
-
 
1618
		case type_compound_tag : {
-
 
1619
		    /* Cast to non-scalar type */
-
 
1620
		    add_error ( err, ERR_expr_cast_expl_scalar ( t ) ) ;
-
 
1621
		    break ;
-
 
1622
		}
-
 
1623
	    }
-
 
1624
	}
-
 
1625
	if ( ns == type_token_tag || nt == type_token_tag ) {
-
 
1626
	    /* Allow for tokenised types */
-
 
1627
	    int ft = force_tokdef ;
-
 
1628
	    int fs = force_template ;
-
 
1629
	    if ( cast != CAST_IMPLICIT ) {
-
 
1630
		force_tokdef = 0 ;
-
 
1631
		force_template = 0 ;
-
 
1632
	    }
-
 
1633
	    if ( eq_type_unqual ( s, t ) ) e = a ;
-
 
1634
	    force_template = fs ;
-
 
1635
	    force_tokdef = ft ;
-
 
1636
	}
-
 
1637
	if ( IS_NULL_exp ( e ) ) {
-
 
1638
	    /* No other conversions are allowed */
-
 
1639
	    if ( ns == type_error_tag || nt == type_error_tag ) {
-
 
1640
		e = cast_exact ( t, a ) ;
-
 
1641
	    } else {
-
 
1642
		ERROR err2 = check_incomplete ( t ) ;
-
 
1643
		err2 = concat_error ( err2, ERR_expr_cast_invalid ( s, t ) ) ;
-
 
1644
		if ( !IS_NULL_err ( err2 ) ) {
-
 
1645
		    e = cast_token ( t, a, err, err2, cast ) ;
-
 
1646
		    if ( !IS_NULL_exp ( e ) ) return ( e ) ;
-
 
1647
		}
-
 
1648
		MAKE_exp_cast ( t, CONV_NONE, a, e ) ;
-
 
1649
	    }
-
 
1650
	}
1774
	}
1651
    }
-
 
1652
    return ( e ) ;
1775
	return (e);
1653
}
1776
}
1654
 
1777
 
1655
 
1778
 
1656
/*
1779
/*
1657
    CONSTRUCT A SIMPLE CAST EXPRESSION
1780
    CONSTRUCT A SIMPLE CAST EXPRESSION
1658
 
1781
 
1659
    This routine constructs the simple cast expression '( t ) a'.  n gives
1782
    This routine constructs the simple cast expression '( t ) a'.  n gives
1660
    the number of types defined in t.
1783
    the number of types defined in t.
1661
*/
1784
*/
1662
 
1785
 
1663
EXP make_cast_exp
1786
EXP
1664
    PROTO_N ( ( t, a, n ) )
-
 
1665
    PROTO_T ( TYPE t X EXP a X int n )
1787
make_cast_exp(TYPE t, EXP a, int n)
1666
{
1788
{
1667
    EXP e ;
1789
	EXP e;
1668
    ERROR err = NULL_err ;
1790
	ERROR err = NULL_err;
1669
    unsigned conv = ( unsigned ) option_value ( OPT_VAL_cast_explicit ) ;
1791
	unsigned conv = (unsigned)option_value(OPT_VAL_cast_explicit);
1670
    report ( crt_loc, ERR_expr_cast_expl_used () ) ;
1792
	report(crt_loc, ERR_expr_cast_expl_used());
-
 
1793
	if (n) {
1671
    if ( n ) report ( crt_loc, ERR_expr_cast_expl_typedef () ) ;
1794
		report(crt_loc, ERR_expr_cast_expl_typedef());
-
 
1795
	}
1672
    a = convert_reference ( a, REF_ASSIGN ) ;
1796
	a = convert_reference(a, REF_ASSIGN);
1673
    e = cast_exp ( t, a, &err, conv ) ;
1797
	e = cast_exp(t, a, &err, conv);
1674
    if ( !IS_NULL_err ( err ) ) {
1798
	if (!IS_NULL_err(err)) {
1675
	err = concat_warning ( err, ERR_expr_cast_expl_bad () ) ;
1799
		err = concat_warning(err, ERR_expr_cast_expl_bad());
1676
	report ( crt_loc, err ) ;
1800
		report(crt_loc, err);
1677
    }
1801
	}
1678
    return ( e ) ;
1802
	return (e);
1679
}
1803
}
1680
 
1804
 
1681
 
1805
 
1682
/*
1806
/*
1683
    CONSTRUCT A STATIC CAST EXPRESSION
1807
    CONSTRUCT A STATIC CAST EXPRESSION
1684
 
1808
 
1685
    This routine constructs the static cast expression 'static_cast < t >
1809
    This routine constructs the static cast expression 'static_cast < t >
1686
    ( a )'.  n gives the number of types defined in t.
1810
    ( a )'.  n gives the number of types defined in t.
1687
*/
1811
*/
1688
 
1812
 
1689
EXP make_static_cast_exp
1813
EXP
1690
    PROTO_N ( ( t, a, n ) )
-
 
1691
    PROTO_T ( TYPE t X EXP a X int n )
1814
make_static_cast_exp(TYPE t, EXP a, int n)
1692
{
1815
{
1693
    EXP e ;
1816
	EXP e;
1694
    ERROR err = NULL_err ;
1817
	ERROR err = NULL_err;
-
 
1818
	if (n) {
1695
    if ( n ) report ( crt_loc, ERR_expr_cast_stat_typedef () ) ;
1819
		report(crt_loc, ERR_expr_cast_stat_typedef());
-
 
1820
	}
1696
    a = convert_reference ( a, REF_ASSIGN ) ;
1821
	a = convert_reference(a, REF_ASSIGN);
1697
    e = cast_exp ( t, a, &err, CAST_STATIC ) ;
1822
	e = cast_exp(t, a, &err, CAST_STATIC);
1698
    if ( !IS_NULL_err ( err ) ) {
1823
	if (!IS_NULL_err(err)) {
1699
	err = concat_warning ( err, ERR_expr_cast_stat_bad () ) ;
1824
		err = concat_warning(err, ERR_expr_cast_stat_bad());
1700
	report ( crt_loc, err ) ;
1825
		report(crt_loc, err);
1701
    }
1826
	}
1702
    return ( e ) ;
1827
	return (e);
1703
}
1828
}
1704
 
1829
 
1705
 
1830
 
1706
/*
1831
/*
1707
    CONSTRUCT A REINTERPRET CAST EXPRESSION
1832
    CONSTRUCT A REINTERPRET CAST EXPRESSION
1708
 
1833
 
1709
    This routine constructs the reinterpret cast expression 'reinterpret_cast
1834
    This routine constructs the reinterpret cast expression 'reinterpret_cast
1710
    < t > ( a )'.  n gives the number of types defined in t.
1835
    < t > ( a )'.  n gives the number of types defined in t.
1711
*/
1836
*/
1712
 
1837
 
1713
EXP make_reinterp_cast_exp
1838
EXP
1714
    PROTO_N ( ( t, a, n ) )
-
 
1715
    PROTO_T ( TYPE t X EXP a X int n )
1839
make_reinterp_cast_exp(TYPE t, EXP a, int n)
1716
{
1840
{
1717
    EXP e ;
1841
	EXP e;
1718
    ERROR err = NULL_err ;
1842
	ERROR err = NULL_err;
-
 
1843
	if (n) {
1719
    if ( n ) report ( crt_loc, ERR_expr_cast_reint_typedef () ) ;
1844
		report(crt_loc, ERR_expr_cast_reint_typedef());
-
 
1845
	}
1720
    a = convert_reference ( a, REF_ASSIGN ) ;
1846
	a = convert_reference(a, REF_ASSIGN);
1721
    e = cast_exp ( t, a, &err, CAST_REINTERP ) ;
1847
	e = cast_exp(t, a, &err, CAST_REINTERP);
1722
    if ( !IS_NULL_err ( err ) ) {
1848
	if (!IS_NULL_err(err)) {
1723
	err = concat_warning ( err, ERR_expr_cast_reint_bad () ) ;
1849
		err = concat_warning(err, ERR_expr_cast_reint_bad());
1724
	report ( crt_loc, err ) ;
1850
		report(crt_loc, err);
1725
    }
1851
	}
1726
    return ( e ) ;
1852
	return (e);
1727
}
1853
}
1728
 
1854
 
1729
 
1855
 
1730
/*
1856
/*
1731
    CONSTRUCT A CONST CAST EXPRESSION
1857
    CONSTRUCT A CONST CAST EXPRESSION
1732
 
1858
 
1733
    This routine constructs the const cast expression 'const_cast < t >
1859
    This routine constructs the const cast expression 'const_cast < t >
1734
    ( a )'.  n gives the number of types defined in t.
1860
    ( a )'.  n gives the number of types defined in t.
1735
*/
1861
*/
1736
 
1862
 
1737
EXP make_const_cast_exp
1863
EXP
1738
    PROTO_N ( ( t, a, n ) )
-
 
1739
    PROTO_T ( TYPE t X EXP a X int n )
1864
make_const_cast_exp(TYPE t, EXP a, int n)
1740
{
1865
{
1741
    EXP e ;
1866
	EXP e;
1742
    ERROR err = NULL_err ;
1867
	ERROR err = NULL_err;
-
 
1868
	if (n) {
1743
    if ( n ) report ( crt_loc, ERR_expr_cast_const_typedef () ) ;
1869
		report(crt_loc, ERR_expr_cast_const_typedef());
-
 
1870
	}
1744
    a = convert_reference ( a, REF_ASSIGN ) ;
1871
	a = convert_reference(a, REF_ASSIGN);
1745
    e = cast_exp ( t, a, &err, CAST_CONST ) ;
1872
	e = cast_exp(t, a, &err, CAST_CONST);
1746
    if ( !IS_NULL_err ( err ) ) {
1873
	if (!IS_NULL_err(err)) {
1747
	err = concat_warning ( err, ERR_expr_cast_const_bad () ) ;
1874
		err = concat_warning(err, ERR_expr_cast_const_bad());
1748
	report ( crt_loc, err ) ;
1875
		report(crt_loc, err);
1749
    }
1876
	}
1750
    return ( e ) ;
1877
	return (e);
1751
}
1878
}
1752
 
1879
 
1753
 
1880
 
1754
/*
1881
/*
1755
    CONSTRUCT A NEW-STYLE CAST EXPRESSION
1882
    CONSTRUCT A NEW-STYLE CAST EXPRESSION
1756
 
1883
 
1757
    This routine constructs the new-style cast expression 'op < t > ( a )'.
1884
    This routine constructs the new-style cast expression 'op < t > ( a )'.
1758
    n gives the number of types defined in t.
1885
    n gives the number of types defined in t.
1759
*/
1886
*/
1760
 
1887
 
1761
#if LANGUAGE_CPP
1888
#if LANGUAGE_CPP
1762
 
1889
 
1763
EXP make_new_cast_exp
1890
EXP
1764
    PROTO_N ( ( op, t, a, n ) )
-
 
1765
    PROTO_T ( int op X TYPE t X EXP a X int n )
1891
make_new_cast_exp(int op, TYPE t, EXP a, int n)
1766
{
1892
{
1767
    EXP e ;
1893
	EXP e;
1768
    switch ( op ) {
1894
	switch (op) {
1769
	case lex_static_Hcast : {
1895
	case lex_static_Hcast: {
1770
	    e = make_static_cast_exp ( t, a, n ) ;
1896
		e = make_static_cast_exp(t, a, n);
1771
	    break ;
1897
		break;
1772
	}
1898
	}
1773
	case lex_reinterpret_Hcast : {
1899
	case lex_reinterpret_Hcast: {
1774
	    e = make_reinterp_cast_exp ( t, a, n ) ;
1900
		e = make_reinterp_cast_exp(t, a, n);
1775
	    break ;
1901
		break;
1776
	}
1902
	}
1777
	case lex_const_Hcast : {
1903
	case lex_const_Hcast: {
1778
	    e = make_const_cast_exp ( t, a, n ) ;
1904
		e = make_const_cast_exp(t, a, n);
1779
	    break ;
1905
		break;
1780
	}
1906
	}
1781
	case lex_dynamic_Hcast : {
1907
	case lex_dynamic_Hcast: {
1782
	    e = make_dynamic_cast_exp ( t, a, n ) ;
1908
		e = make_dynamic_cast_exp(t, a, n);
1783
	    break ;
1909
		break;
1784
	}
1910
	}
1785
	default : {
1911
	default: {
1786
	    e = make_cast_exp ( t, a, n ) ;
1912
		e = make_cast_exp(t, a, n);
1787
	    break ;
1913
		break;
1788
	}
1914
	}
1789
    }
1915
	}
1790
    return ( e ) ;
1916
	return (e);
1791
}
1917
}
1792
 
1918
 
1793
#endif
1919
#endif
1794
 
1920
 
1795
 
1921
 
1796
/*
1922
/*
1797
    CONSTRUCT A FUNCTION-STYLE CAST EXPRESSION
1923
    CONSTRUCT A FUNCTION-STYLE CAST EXPRESSION
1798
 
1924
 
1799
    This routine constructs the function-style cast expression 't ( args )'.
1925
    This routine constructs the function-style cast expression 't ( args )'.
1800
    If args is a single argument, a, then this is identical to '( t ) a'.
1926
    If args is a single argument, a, then this is identical to '( t ) a'.
1801
    The expression 't ()' can be formed for any type, otherwise t must be
1927
    The expression 't ()' can be formed for any type, otherwise t must be
1802
    a class type with a suitable constructor.
1928
    a class type with a suitable constructor.
1803
*/
1929
*/
1804
 
1930
 
1805
EXP make_func_cast_exp
1931
EXP
1806
    PROTO_N ( ( t, args ) )
-
 
1807
    PROTO_T ( TYPE t X LIST ( EXP ) args )
1932
make_func_cast_exp(TYPE t, LIST(EXP)args)
1808
{
1933
{
1809
    EXP e ;
1934
	EXP e;
1810
    ERROR err = NULL_err ;
1935
	ERROR err = NULL_err;
1811
    unsigned tag = TAG_type ( t ) ;
1936
	unsigned tag = TAG_type(t);
1812
    unsigned len = LENGTH_list ( args ) ;
1937
	unsigned len = LENGTH_list(args);
1813
 
1938
 
1814
    /* Do reference conversions on arguments */
1939
	/* Do reference conversions on arguments */
1815
    args = convert_args ( args ) ;
1940
	args = convert_args(args);
1816
 
1941
 
1817
    /* Check for template types */
1942
	/* Check for template types */
1818
    if ( tag == type_token_tag && is_templ_type ( t ) ) {
1943
	if (tag == type_token_tag && is_templ_type(t)) {
1819
	MAKE_exp_opn ( t, lex_cast, args, e ) ;
1944
		MAKE_exp_opn(t, lex_cast, args, e);
1820
	return ( e ) ;
1945
		return (e);
1821
    }
1946
	}
1822
 
1947
 
1823
    /* Check for class type with more than one argument */
1948
	/* Check for class type with more than one argument */
1824
    if ( len > 1 && tag != type_compound_tag ) {
1949
	if (len > 1 && tag != type_compound_tag) {
1825
	report ( crt_loc, ERR_expr_type_conv_many ( t ) ) ;
1950
		report(crt_loc, ERR_expr_type_conv_many(t));
1826
	len = 1 ;
1951
		len = 1;
1827
    }
1952
	}
1828
 
1953
 
1829
    if ( len == 1 ) {
1954
	if (len == 1) {
1830
	/* A single argument is the same as a normal cast */
1955
		/* A single argument is the same as a normal cast */
1831
	unsigned conv = ( unsigned ) option_value ( OPT_VAL_cast_explicit ) ;
1956
		unsigned conv = (unsigned)option_value(OPT_VAL_cast_explicit);
1832
	EXP a = DEREF_exp ( HEAD_list ( args ) ) ;
1957
		EXP a = DEREF_exp(HEAD_list(args));
1833
	DESTROY_list ( args, SIZE_exp ) ;
1958
		DESTROY_list(args, SIZE_exp);
1834
	if ( tag != type_compound_tag ) {
1959
		if (tag != type_compound_tag) {
1835
	    report ( crt_loc, ERR_expr_cast_expl_used () ) ;
1960
			report(crt_loc, ERR_expr_cast_expl_used());
1836
	}
1961
		}
1837
	e = cast_exp ( t, a, &err, conv ) ;
1962
		e = cast_exp(t, a, &err, conv);
1838
	if ( !IS_NULL_err ( err ) ) {
1963
		if (!IS_NULL_err(err)) {
1839
	    err = concat_warning ( err, ERR_expr_type_conv_bad () ) ;
1964
			err = concat_warning(err, ERR_expr_type_conv_bad());
1840
	    report ( crt_loc, err ) ;
1965
			report(crt_loc, err);
1841
	}
1966
		}
1842
	return ( e ) ;
1967
		return (e);
1843
    }
1968
	}
1844
 
1969
 
1845
    if ( len == 0 ) {
1970
	if (len == 0) {
1846
	/* No arguments give a zero value */
1971
		/* No arguments give a zero value */
1847
	if ( IS_type_top_etc ( t ) ) {
1972
		if (IS_type_top_etc(t)) {
1848
	    MAKE_exp_value ( t, e ) ;
1973
			MAKE_exp_value(t, e);
1849
	} else {
1974
		} else {
1850
	    err = check_complete ( t ) ;
1975
			err = check_complete(t);
1851
	    if ( !IS_NULL_err ( err ) ) {
1976
			if (!IS_NULL_err(err)) {
1852
		/* Can't cast to an incomplete type */
1977
				/* Can't cast to an incomplete type */
1853
		err = concat_error ( err, ERR_expr_type_conv_incompl () ) ;
1978
				err = concat_error(err, ERR_expr_type_conv_incompl());
1854
		report ( crt_loc, err ) ;
1979
				report(crt_loc, err);
1855
	    }
1980
			}
1856
	    if ( IS_type_array ( t ) ) {
1981
			if (IS_type_array(t)) {
1857
		/* Can't use an array type */
1982
				/* Can't use an array type */
1858
		report ( crt_loc, ERR_expr_type_conv_array ( t ) ) ;
1983
				report(crt_loc, ERR_expr_type_conv_array(t));
1859
	    }
1984
			}
1860
	    err = check_abstract ( t ) ;
1985
			err = check_abstract(t);
1861
	    if ( !IS_NULL_err ( err ) ) {
1986
			if (!IS_NULL_err(err)) {
1862
		/* Can't cast to an abstract type */
1987
				/* Can't cast to an abstract type */
1863
		err = concat_error ( err, ERR_class_abstract_cast () ) ;
1988
				err = concat_error(err, ERR_class_abstract_cast());
1864
		report ( crt_loc, err ) ;
1989
				report(crt_loc, err);
1865
		err = NULL_err ;
1990
				err = NULL_err;
1866
	    }
1991
			}
1867
	    e = init_empty ( t, cv_none, 1, &err ) ;
1992
			e = init_empty(t, cv_none, 1, &err);
1868
	    if ( !IS_NULL_err ( err ) ) report ( crt_loc, err ) ;
1993
			if (!IS_NULL_err(err)) {
-
 
1994
				report(crt_loc, err);
-
 
1995
			}
1869
	}
1996
		}
1870
	return ( e ) ;
1997
		return (e);
1871
    }
1998
	}
1872
 
1999
 
1873
    /* Now check constructor conversions */
2000
	/* Now check constructor conversions */
1874
    e = convert_constr ( t, args, &err, CAST_STATIC ) ;
2001
	e = convert_constr(t, args, &err, CAST_STATIC);
1875
    if ( !IS_NULL_err ( err ) ) report ( crt_loc, err ) ;
2002
	if (!IS_NULL_err(err)) {
-
 
2003
		report(crt_loc, err);
-
 
2004
	}
1876
    return ( e ) ;
2005
	return (e);
1877
}
2006
}
1878
 
2007
 
1879
 
2008
 
1880
/*
2009
/*
1881
    LIST OF ALL CONVERSION TOKENS
2010
    LIST OF ALL CONVERSION TOKENS
1882
 
2011
 
1883
    Whenever a type conversion would raise an error this list of tokens
2012
    Whenever a type conversion would raise an error this list of tokens
1884
    is consulted to see if one of them could perform the conversion.
2013
    is consulted to see if one of them could perform the conversion.
1885
*/
2014
*/
1886
 
2015
 
1887
static LIST ( IDENTIFIER ) conv_tokens = NULL_list ( IDENTIFIER ) ;
2016
static LIST(IDENTIFIER) conv_tokens = NULL_list(IDENTIFIER);
1888
 
2017
 
1889
 
2018
 
1890
/*
2019
/*
1891
    ALLOW A TOKEN AS A CONVERSION
2020
    ALLOW A TOKEN AS A CONVERSION
1892
 
2021
 
1893
    This routine enables the token id as a conversion token.
2022
    This routine enables the token id as a conversion token.
1894
*/
2023
*/
1895
 
2024
 
1896
void allow_conversion
2025
void
1897
    PROTO_N ( ( id ) )
-
 
1898
    PROTO_T ( IDENTIFIER id )
2026
allow_conversion(IDENTIFIER id)
1899
{
2027
{
1900
    IDENTIFIER tid = resolve_token ( id, "EE", 1 ) ;
2028
	IDENTIFIER tid = resolve_token(id, "EE", 1);
1901
    if ( !IS_NULL_id ( tid ) ) {
2029
	if (!IS_NULL_id(tid)) {
1902
	CONS_id ( tid, conv_tokens, conv_tokens ) ;
2030
		CONS_id(tid, conv_tokens, conv_tokens);
1903
    }
2031
	}
1904
    return ;
2032
	return;
1905
}
2033
}
1906
 
2034
 
1907
 
2035
 
1908
/*
2036
/*
1909
    CHECK FOR TOKENISED CONVERSIONS
2037
    CHECK FOR TOKENISED CONVERSIONS
Line 1911... Line 2039...
1911
    This routine checks whether the expression a can be converted to the
2039
    This routine checks whether the expression a can be converted to the
1912
    type t using a conversion token.  If so it returns the appropriate
2040
    type t using a conversion token.  If so it returns the appropriate
1913
    token application.  Otherwise it returns the null expression.
2041
    token application.  Otherwise it returns the null expression.
1914
*/
2042
*/
1915
 
2043
 
1916
EXP cast_token
2044
EXP
1917
    PROTO_N ( ( t, a, err, err2, cast ) )
-
 
1918
    PROTO_T ( TYPE t X EXP a X ERROR *err X ERROR err2 X unsigned cast )
2045
cast_token(TYPE t, EXP a, ERROR *err, ERROR err2, unsigned cast)
1919
{
2046
{
1920
    EXP e = NULL_exp ;
2047
	EXP e = NULL_exp;
1921
    int sev = ERROR_NONE ;
2048
	int sev = ERROR_NONE;
1922
    if ( !IS_NULL_err ( err2 ) ) {
2049
	if (!IS_NULL_err(err2)) {
1923
	sev = DEREF_int ( err_severity ( err2 ) ) ;
2050
		sev = DEREF_int(err_severity(err2));
1924
    }
2051
	}
1925
    if ( sev == ERROR_SERIOUS ) {
2052
	if (sev == ERROR_SERIOUS) {
1926
	/* Only check illegal conversions */
2053
		/* Only check illegal conversions */
1927
	force_tokdef++ ;
2054
		force_tokdef++;
1928
	if ( cast == CAST_IMPLICIT || ( cast & CAST_STATIC ) ) {
2055
		if (cast == CAST_IMPLICIT || (cast & CAST_STATIC)) {
1929
	    /* Scan through conversion tokens */
2056
			/* Scan through conversion tokens */
1930
	    TYPE s = DEREF_type ( exp_type ( a ) ) ;
2057
			TYPE s = DEREF_type(exp_type(a));
1931
	    LIST ( IDENTIFIER ) convs = conv_tokens ;
2058
			LIST(IDENTIFIER)convs = conv_tokens;
1932
	    while ( !IS_NULL_list ( convs ) ) {
2059
			while (!IS_NULL_list(convs)) {
1933
		IDENTIFIER id = DEREF_id ( HEAD_list ( convs ) ) ;
2060
				IDENTIFIER id = DEREF_id(HEAD_list(convs));
1934
		TOKEN tok = DEREF_tok ( id_token_sort ( id ) ) ;
2061
				TOKEN tok = DEREF_tok(id_token_sort(id));
1935
		if ( IS_tok_func ( tok ) ) {
2062
				if (IS_tok_func(tok)) {
1936
		    /* Function tokens */
2063
					/* Function tokens */
1937
		    tok = func_proc_token ( tok ) ;
2064
					tok = func_proc_token(tok);
1938
		}
2065
				}
1939
		if ( IS_tok_proc ( tok ) ) {
2066
				if (IS_tok_proc(tok)) {
1940
		    /* Procedure tokens */
2067
					/* Procedure tokens */
1941
		    int d ;
2068
					int d;
1942
		    TYPE p ;
2069
					TYPE p;
1943
		    TOKEN par ;
2070
					TOKEN par;
1944
		    IDENTIFIER pid ;
2071
					IDENTIFIER pid;
1945
		    LIST ( IDENTIFIER ) bids ;
2072
					LIST(IDENTIFIER)bids;
1946
		    LIST ( IDENTIFIER ) pids ;
2073
					LIST(IDENTIFIER)pids;
1947
 
2074
 
1948
		    /* Find result type */
2075
					/* Find result type */
1949
		    TOKEN res = DEREF_tok ( tok_proc_res ( tok ) ) ;
2076
					TOKEN res = DEREF_tok(tok_proc_res(tok));
1950
		    TYPE r = DEREF_type ( tok_exp_type ( res ) ) ;
2077
					TYPE r = DEREF_type(tok_exp_type(res));
1951
 
2078
 
1952
		    /* Find parameter type */
2079
					/* Find parameter type */
1953
		    pids = DEREF_list ( tok_proc_pids ( tok ) ) ;
2080
					pids = DEREF_list(tok_proc_pids(tok));
1954
		    pid = DEREF_id ( HEAD_list ( pids ) ) ;
2081
					pid = DEREF_id(HEAD_list(pids));
1955
		    par = DEREF_tok ( id_token_sort ( pid ) ) ;
2082
					par = DEREF_tok(id_token_sort(pid));
1956
		    p = DEREF_type ( tok_exp_type ( par ) ) ;
2083
					p = DEREF_type(tok_exp_type(par));
1957
 
2084
 
1958
		    /* Check conversion */
2085
					/* Check conversion */
1959
		    bids = DEREF_list ( tok_proc_bids ( tok ) ) ;
2086
					bids = DEREF_list(tok_proc_bids(tok));
1960
		    d = save_token_args ( bids, NULL_list ( TOKEN ) ) ;
2087
					d = save_token_args(bids, NULL_list(TOKEN));
1961
		    if ( eq_type ( s, p ) && eq_type ( t, r ) ) {
2088
					if (eq_type(s, p) && eq_type(t, r)) {
1962
			LIST ( TOKEN ) args ;
2089
						LIST(TOKEN)args;
1963
			ERROR err1 = ERR_token_conv ( id, s, t ) ;
2090
						ERROR err1 = ERR_token_conv(id, s, t);
1964
			IGNORE define_exp_token ( pid, a, 1 ) ;
2091
						IGNORE define_exp_token(pid, a, 1);
1965
			args = make_token_args ( id, bids, &err1 ) ;
2092
						args = make_token_args(id, bids, &err1);
1966
			e = apply_exp_token ( id, args, 0 ) ;
2093
						e = apply_exp_token(id, args, 0);
1967
			if ( !IS_NULL_exp ( e ) ) {
2094
						if (!IS_NULL_exp(e)) {
1968
			    IDENTIFIER fid ;
2095
							IDENTIFIER fid;
1969
			    fid = DEREF_id ( id_token_alt ( id ) ) ;
2096
							fid = DEREF_id(id_token_alt(id));
1970
			    use_func_id ( fid, 0, 0 ) ;
2097
							use_func_id(fid, 0, 0);
1971
			    restore_token_args ( bids, d ) ;
2098
							restore_token_args(bids, d);
1972
			    destroy_error ( err2, 1 ) ;
2099
							destroy_error(err2, 1);
1973
			    err2 = err1 ;
2100
							err2 = err1;
1974
			    break ;
2101
							break;
-
 
2102
						}
-
 
2103
						destroy_error(err1, 1);
-
 
2104
					}
-
 
2105
					restore_token_args(bids, d);
-
 
2106
				}
-
 
2107
				convs = TAIL_list(convs);
1975
			}
2108
			}
1976
			destroy_error ( err1, 1 ) ;
-
 
1977
		    }
-
 
1978
		    restore_token_args ( bids, d ) ;
-
 
1979
		}
2109
		}
1980
		convs = TAIL_list ( convs ) ;
2110
		force_tokdef--;
1981
	    }
-
 
1982
	}
2111
	}
1983
	force_tokdef-- ;
-
 
1984
    }
-
 
1985
    add_error ( err, err2 ) ;
2112
	add_error(err, err2);
1986
    return ( e ) ;
2113
	return (e);
1987
}
2114
}