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

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

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

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

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

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

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

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

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

Subversion Repositories tendra.SVN

Rev

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

Rev 2 Rev 7
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2006 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
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
*/
29
 
59
 
30
 
60
 
31
#include "config.h"
61
#include "config.h"
32
#include "c_types.h"
62
#include "c_types.h"
33
#include "ctype_ops.h"
63
#include "ctype_ops.h"
34
#include "etype_ops.h"
64
#include "etype_ops.h"
35
#include "exp_ops.h"
65
#include "exp_ops.h"
Line 77... Line 107...
77
    first constructed.  Enumeration types and bitfield types are promoted
107
    first constructed.  Enumeration types and bitfield types are promoted
78
    according to their underlying types.  Other types (including floating
108
    according to their underlying types.  Other types (including floating
79
    point types) are their own promotions.
109
    point types) are their own promotions.
80
*/
110
*/
81
 
111
 
82
TYPE promote_type
112
TYPE
83
    PROTO_N ( ( t ) )
-
 
84
    PROTO_T ( TYPE t )
113
promote_type(TYPE t)
85
{
114
{
86
    switch ( TAG_type ( t ) ) {
115
	switch (TAG_type(t)) {
87
	case type_integer_tag : {
116
	case type_integer_tag: {
88
	    /* Retrieve the promotion of an integral type */
117
		/* Retrieve the promotion of an integral type */
89
	    INT_TYPE it = DEREF_itype ( type_integer_rep ( t ) ) ;
118
		INT_TYPE it = DEREF_itype(type_integer_rep(t));
90
	    t = DEREF_type ( itype_prom ( it ) ) ;
119
		t = DEREF_type(itype_prom(it));
91
	    break ;
120
		break;
92
	}
121
	}
93
	case type_enumerate_tag : {
122
	case type_enumerate_tag: {
94
	    /* Find the underlying type of an enumeration */
123
		/* Find the underlying type of an enumeration */
95
	    ENUM_TYPE et = DEREF_etype ( type_enumerate_defn ( t ) ) ;
124
		ENUM_TYPE et = DEREF_etype(type_enumerate_defn(t));
96
	    t = DEREF_type ( etype_rep ( et ) ) ;
125
		t = DEREF_type(etype_rep(et));
97
	    t = promote_type ( t ) ;
126
		t = promote_type(t);
98
	    break ;
127
		break;
99
	}
128
	}
100
	case type_bitfield_tag : {
129
	case type_bitfield_tag: {
101
	    /* Retrieve the promotion of a bitfield type */
130
		/* Retrieve the promotion of a bitfield type */
102
	    INT_TYPE it = DEREF_itype ( type_bitfield_defn ( t ) ) ;
131
		INT_TYPE it = DEREF_itype(type_bitfield_defn(t));
103
	    t = DEREF_type ( itype_prom ( it ) ) ;
132
		t = DEREF_type(itype_prom(it));
104
	    break ;
133
		break;
105
	}
134
	}
106
    }
135
	}
107
    return ( t ) ;
136
	return (t);
108
}
137
}
109
 
138
 
110
 
139
 
111
/*
140
/*
112
    FIND THE ARGUMENT PROMOTION OF A TYPE
141
    FIND THE ARGUMENT PROMOTION OF A TYPE
113
 
142
 
114
    This routine finds the argument promotion type for the type t.  This
143
    This routine finds the argument promotion type for the type t.  This
115
    is identical to the normal arithmetic promotion type for integral types,
144
    is identical to the normal arithmetic promotion type for integral types,
116
    but differs for floating point types (float promotes to double etc.).
145
    but differs for floating point types (float promotes to double etc.).
117
    Any errors are added to the end of err.
146
    Any errors are added to the end of err.
118
*/
147
*/
119
 
148
 
120
TYPE arg_promote_type
149
TYPE
121
    PROTO_N ( ( t, err ) )
-
 
122
    PROTO_T ( TYPE t X ERROR *err )
150
arg_promote_type(TYPE t, ERROR *err)
123
{
151
{
124
    switch ( TAG_type ( t ) ) {
152
	switch (TAG_type(t)) {
125
	case type_integer_tag :
153
	case type_integer_tag:
126
	case type_enumerate_tag :
154
	case type_enumerate_tag:
127
	case type_bitfield_tag : {
155
	case type_bitfield_tag: {
128
	    /* Promote integral types */
156
		/* Promote integral types */
129
	    t = promote_type ( t ) ;
157
		t = promote_type(t);
130
	    break ;
158
		break;
131
	}
159
	}
132
	case type_floating_tag : {
160
	case type_floating_tag: {
133
	    /* Retrieve the promotion of a floating point type */
161
		/* Retrieve the promotion of a floating point type */
134
	    FLOAT_TYPE ft = DEREF_ftype ( type_floating_rep ( t ) ) ;
162
		FLOAT_TYPE ft = DEREF_ftype(type_floating_rep(t));
135
	    t = DEREF_type ( ftype_arg_prom ( ft ) ) ;
163
		t = DEREF_type(ftype_arg_prom(ft));
136
	    break ;
164
		break;
137
	}
165
	}
138
	case type_top_tag :
166
	case type_top_tag:
139
	case type_bottom_tag : {
167
	case type_bottom_tag: {
140
	    /* Can't have 'void' arguments */
168
		/* Can't have 'void' arguments */
141
	    add_error ( err, ERR_basic_fund_void_exp ( t ) ) ;
169
		add_error(err, ERR_basic_fund_void_exp(t));
142
	    break ;
170
		break;
143
	}
171
	}
144
	case type_func_tag : {
172
	case type_func_tag: {
145
	    /* Apply function-to-pointer conversion */
173
		/* Apply function-to-pointer conversion */
146
	    MAKE_type_ptr ( cv_none, t, t ) ;
174
		MAKE_type_ptr(cv_none, t, t);
147
	    break ;
175
		break;
148
	}
176
	}
149
	case type_array_tag : {
177
	case type_array_tag: {
150
	    /* Apply array-to-pointer conversion */
178
		/* Apply array-to-pointer conversion */
151
	    TYPE s = DEREF_type ( type_array_sub ( t ) ) ;
179
		TYPE s = DEREF_type(type_array_sub(t));
152
	    MAKE_type_ptr ( cv_none, s, t ) ;
180
		MAKE_type_ptr(cv_none, s, t);
-
 
181
		break;
-
 
182
	}
-
 
183
	case type_compound_tag: {
-
 
184
		/* Types with constructors are suspicious */
-
 
185
		if (pass_complex_type(t)) {
-
 
186
			add_error(err, ERR_expr_call_struct(t));
-
 
187
		}
153
	    break ;
188
		break;
154
	}
189
	}
155
	case type_compound_tag : {
-
 
156
	    /* Types with constructors are suspicious */
-
 
157
	    if ( pass_complex_type ( t ) ) {
-
 
158
		add_error ( err, ERR_expr_call_struct ( t ) ) ;
-
 
159
	    }
-
 
160
	    break ;
-
 
161
	}
190
	}
162
    }
-
 
163
    return ( t ) ;
191
	return (t);
164
}
192
}
165
 
193
 
166
 
194
 
167
/*
195
/*
168
    IS A TYPE EQUAL TO ITS ARGUMENT PROMOTION TYPE?
196
    IS A TYPE EQUAL TO ITS ARGUMENT PROMOTION TYPE?
169
 
197
 
170
    This routine checks whether the integral or floating point type t is
198
    This routine checks whether the integral or floating point type t is
171
    equal to its argument promotion type.
199
    equal to its argument promotion type.
172
*/
200
*/
173
 
201
 
174
int is_arg_promote
202
int
175
    PROTO_N ( ( t ) )
-
 
176
    PROTO_T ( TYPE t )
203
is_arg_promote(TYPE t)
177
{
204
{
178
    int eq = 1 ;
205
	int eq = 1;
179
    if ( !IS_NULL_type ( t ) ) {
206
	if (!IS_NULL_type(t)) {
180
	t = expand_type ( t, 1 ) ;
207
		t = expand_type(t, 1);
181
	switch ( TAG_type ( t ) ) {
208
		switch (TAG_type(t)) {
182
	    case type_integer_tag :
209
		case type_integer_tag:
183
	    case type_floating_tag : {
210
		case type_floating_tag: {
184
		TYPE s = arg_promote_type ( t, KILL_err ) ;
211
			TYPE s = arg_promote_type(t, KILL_err);
185
		if ( !EQ_type ( s, t ) ) {
212
			if (!EQ_type(s, t)) {
186
		    int ft = force_tokdef ;
213
				int ft = force_tokdef;
187
		    force_tokdef = 0 ;
214
				force_tokdef = 0;
188
		    eq = eq_type_unqual ( s, t ) ;
215
				eq = eq_type_unqual(s, t);
189
		    force_tokdef = ft ;
216
				force_tokdef = ft;
-
 
217
			}
-
 
218
			break;
-
 
219
		}
190
		}
220
		}
191
		break ;
-
 
192
	    }
-
 
193
	}
221
	}
194
    }
-
 
195
    return ( eq ) ;
222
	return (eq);
196
}
223
}
197
 
224
 
198
 
225
 
199
/*
226
/*
200
    FIND THE TYPE WHICH PROMOTES TO A GIVEN TYPE
227
    FIND THE TYPE WHICH PROMOTES TO A GIVEN TYPE
201
 
228
 
202
    This routine is a partial inverse to arg_promote_type which finds a
229
    This routine is a partial inverse to arg_promote_type which finds a
203
    type whose promotion is t.
230
    type whose promotion is t.
204
*/
231
*/
205
 
232
 
206
TYPE unpromote_type
233
TYPE
207
    PROTO_N ( ( t ) )
-
 
208
    PROTO_T ( TYPE t )
234
unpromote_type(TYPE t)
209
{
235
{
210
    if ( !IS_NULL_type ( t ) ) {
236
	if (!IS_NULL_type(t)) {
211
	switch ( TAG_type ( t ) ) {
237
		switch (TAG_type(t)) {
212
	    case type_integer_tag : {
238
		case type_integer_tag: {
213
		INT_TYPE it = DEREF_itype ( type_integer_rep ( t ) ) ;
239
			INT_TYPE it = DEREF_itype(type_integer_rep(t));
214
		INT_TYPE is = DEREF_itype ( type_integer_sem ( t ) ) ;
240
			INT_TYPE is = DEREF_itype(type_integer_sem(t));
-
 
241
			if (!EQ_itype(is, it)) {
215
		if ( !EQ_itype ( is, it ) ) t = make_itype ( is, is ) ;
242
				t = make_itype(is, is);
-
 
243
			}
216
		break ;
244
			break;
217
	    }
245
		}
218
	    case type_floating_tag : {
246
		case type_floating_tag: {
219
		FLOAT_TYPE ft = DEREF_ftype ( type_floating_rep ( t ) ) ;
247
			FLOAT_TYPE ft = DEREF_ftype(type_floating_rep(t));
220
		FLOAT_TYPE fs = DEREF_ftype ( type_floating_sem ( t ) ) ;
248
			FLOAT_TYPE fs = DEREF_ftype(type_floating_sem(t));
-
 
249
			if (!EQ_ftype(fs, ft)) {
221
		if ( !EQ_ftype ( fs, ft ) ) t = make_ftype ( fs, fs ) ;
250
				t = make_ftype(fs, fs);
-
 
251
			}
222
		break ;
252
			break;
-
 
253
		}
223
	    }
254
		}
224
	}
255
	}
225
    }
-
 
226
    return ( t ) ;
256
	return (t);
227
}
257
}
228
 
258
 
229
 
259
 
230
/*
260
/*
231
    FIND THE TYPE FOR AN ARITHMETIC OPERATION
261
    FIND THE TYPE FOR AN ARITHMETIC OPERATION
232
 
262
 
233
    This routine performs finds the result type for an arithmetic operation
263
    This routine performs finds the result type for an arithmetic operation
234
    involving operands of types t and s.  These will always be arithmetic
264
    involving operands of types t and s.  These will always be arithmetic
235
    types.  The operands a and b are passed in order to help determine the
265
    types.  The operands a and b are passed in order to help determine the
236
    semantic type of the result.
266
    semantic type of the result.
237
*/
267
*/
238
 
268
 
239
TYPE arith_type
269
TYPE
240
    PROTO_N ( ( t, s, a, b ) )
-
 
241
    PROTO_T ( TYPE t X TYPE s X EXP a X EXP b )
270
arith_type(TYPE t, TYPE s, EXP a, EXP b)
242
{
271
{
243
    TYPE r ;
272
	TYPE r;
244
    if ( EQ_type ( t, s ) ) {
273
	if (EQ_type(t, s)) {
245
	/* Equal types, promote the result */
274
		/* Equal types, promote the result */
246
	r = promote_type ( t ) ;
275
		r = promote_type(t);
247
    } else {
-
 
248
	unsigned nt = TAG_type ( t ) ;
-
 
249
	unsigned ns = TAG_type ( s ) ;
-
 
250
	if ( nt == type_floating_tag ) {
-
 
251
	    if ( ns == type_floating_tag ) {
-
 
252
		/* Two floating point types */
-
 
253
		r = arith_ftype ( t, s ) ;
-
 
254
	    } else {
-
 
255
		/* If there is one floating type, this is the result */
-
 
256
		r = t ;
-
 
257
	    }
-
 
258
	} else {
276
	} else {
259
	    if ( ns == type_floating_tag ) {
277
		unsigned nt = TAG_type(t);
260
		/* If there is one floating type, this is the result */
278
		unsigned ns = TAG_type(s);
261
		r = s ;
279
		if (nt == type_floating_tag) {
262
	    } else {
280
			if (ns == type_floating_tag) {
263
		/* Two integer types, promote them both */
281
				/* Two floating point types */
264
		TYPE pt = promote_type ( t ) ;
282
				r = arith_ftype(t, s);
-
 
283
			} else {
265
		TYPE ps = promote_type ( s ) ;
284
				/* If there is one floating type, this is the
266
		if ( EQ_type ( pt, ps ) ) {
285
				 * result */
267
		    r = pt ;
286
				r = t;
-
 
287
			}
268
		} else {
288
		} else {
-
 
289
			if (ns == type_floating_tag) {
-
 
290
				/* If there is one floating type, this is the
-
 
291
				 * result */
-
 
292
				r = s;
-
 
293
			} else {
-
 
294
				/* Two integer types, promote them both */
-
 
295
				TYPE pt = promote_type(t);
-
 
296
				TYPE ps = promote_type(s);
-
 
297
				if (EQ_type(pt, ps)) {
-
 
298
					r = pt;
-
 
299
				} else {
269
		    r = arith_itype ( pt, ps, a, b ) ;
300
					r = arith_itype(pt, ps, a, b);
-
 
301
				}
-
 
302
			}
270
		}
303
		}
271
	    }
-
 
272
	}
304
	}
273
    }
-
 
274
    return ( r ) ;
305
	return (r);
275
}
306
}
276
 
307
 
277
 
308
 
278
/*
309
/*
279
    QUALIFIER DEPTH
310
    QUALIFIER DEPTH
Line 283... Line 314...
283
    are 0 (the types are identically qualified) and 1 (the conversion
314
    are 0 (the types are identically qualified) and 1 (the conversion
284
    is of the form 'cv1 T *' to 'cv2 T *').  The value qualifier_diff
315
    is of the form 'cv1 T *' to 'cv2 T *').  The value qualifier_diff
285
    gives the qualifiers added at this stage.
316
    gives the qualifiers added at this stage.
286
*/
317
*/
287
 
318
 
288
int qualifier_depth = 0 ;
319
int qualifier_depth = 0;
289
static CV_SPEC qualifier_diff = cv_none ;
320
static CV_SPEC qualifier_diff = cv_none;
290
 
321
 
291
 
322
 
292
/*
323
/*
293
    CHECK QUALIFICATION CONVERSIONS
324
    CHECK QUALIFICATION CONVERSIONS
294
 
325
 
295
    This routine checks for qualification conversions from the pointer or
326
    This routine checks for qualification conversions from the pointer or
Line 303... Line 334...
303
    rules are slightly different.  Only one level of pointers is
334
    rules are slightly different.  Only one level of pointers is
304
    considered and the types pointed to must be compatible.  Note that
335
    considered and the types pointed to must be compatible.  Note that
305
    for pointer to member types it is not checked that the underlying
336
    for pointer to member types it is not checked that the underlying
306
    classes are the same at the top level.  This is to allow base class
337
    classes are the same at the top level.  This is to allow base class
307
    pointer to member conversion to be checked elsewhere.
338
    pointer to member conversion to be checked elsewhere.
454
}
521
}
455
 
522
 
456
 
523
 
457
/*
524
/*
458
    FIND THE TYPE FOR A POINTER OPERATION
525
    FIND THE TYPE FOR A POINTER OPERATION
Line 465... Line 532...
465
    depth 1 qualification conversions are applied.  If t and s cannot be
532
    depth 1 qualification conversions are applied.  If t and s cannot be
466
    brought to a common type then the suspect flag is set to 2 and
533
    brought to a common type then the suspect flag is set to 2 and
467
    qualified 'void *' is returned.  suspect is set to 1 if precisely
534
    qualified 'void *' is returned.  suspect is set to 1 if precisely
468
    one of the types is 'void *'.  The routine also operates on reference
535
    one of the types is 'void *'.  The routine also operates on reference
469
    types except that it returns a null type in the 'void *' case.
536
    types except that it returns a null type in the 'void *' case.
470
*/
537
*/
471
 
538
 
472
TYPE ptr_common_type
539
TYPE
473
    PROTO_N ( ( t, s, base, suspect ) )
-
 
474
    PROTO_T ( TYPE t X TYPE s X int base X int *suspect )
540
ptr_common_type(TYPE t, TYPE s, int base, int *suspect)
475
{
541
{
476
    CV_SPEC qt, qs ;
542
	CV_SPEC qt, qs;
477
    TYPE r = NULL_type ;
543
	TYPE r = NULL_type;
478
    unsigned tag = TAG_type ( t ) ;
544
	unsigned tag = TAG_type(t);
479
    TYPE pt = DEREF_type ( type_ptr_etc_sub ( t ) ) ;
545
	TYPE pt = DEREF_type(type_ptr_etc_sub(t));
480
    TYPE ps = DEREF_type ( type_ptr_etc_sub ( s ) ) ;
546
	TYPE ps = DEREF_type(type_ptr_etc_sub(s));
481
    unsigned nt = TAG_type ( pt ) ;
547
	unsigned nt = TAG_type(pt);
482
    unsigned ns = TAG_type ( ps ) ;
548
	unsigned ns = TAG_type(ps);
483
 
549
 
484
    /* Find the common type */
550
	/* Find the common type */
485
    if ( nt == ns ) {
551
	if (nt == ns) {
486
	if ( eq_type_unqual ( pt, ps ) ) {
552
		if (eq_type_unqual(pt, ps)) {
487
	    /* Pointers to the same type */
553
			/* Pointers to the same type */
488
	    r = pt ;
554
			r = pt;
489
	} else if ( nt == type_compound_tag && base ) {
555
		} else if (nt == type_compound_tag && base) {
490
	    /* Check for base class conversions */
556
			/* Check for base class conversions */
491
	    CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( pt ) ) ;
557
			CLASS_TYPE ct = DEREF_ctype(type_compound_defn(pt));
492
	    CLASS_TYPE cs = DEREF_ctype ( type_compound_defn ( ps ) ) ;
558
			CLASS_TYPE cs = DEREF_ctype(type_compound_defn(ps));
493
	    CLASS_TYPE cr = compare_base_class ( ct, cs, 1 ) ;
559
			CLASS_TYPE cr = compare_base_class(ct, cs, 1);
494
	    if ( EQ_ctype ( cr, ct ) ) {
560
			if (EQ_ctype(cr, ct)) {
495
		/* p is a base class of q */
561
				/* p is a base class of q */
496
		r = pt ;
562
				r = pt;
497
	    } else if ( EQ_ctype ( cr, cs ) ) {
563
			} else if (EQ_ctype(cr, cs)) {
498
		/* q is a base class of p */
564
				/* q is a base class of p */
499
		r = ps ;
565
				r = ps;
500
	    }
566
			}
501
	}
567
		}
502
    } else if ( nt == type_top_tag || nt == type_bottom_tag ) {
568
	} else if (nt == type_top_tag || nt == type_bottom_tag) {
503
	/* One pointer is 'void *' */
569
		/* One pointer is 'void *' */
504
	*suspect = 1 ;
570
		*suspect = 1;
505
	r = pt ;
571
		r = pt;
506
    } else if ( ns == type_top_tag || ns == type_bottom_tag ) {
572
	} else if (ns == type_top_tag || ns == type_bottom_tag) {
507
	/* One pointer is 'void *' */
573
		/* One pointer is 'void *' */
508
	*suspect = 1 ;
574
		*suspect = 1;
509
	r = ps ;
575
		r = ps;
510
    }
576
	}
511
#if LANGUAGE_C
577
#if LANGUAGE_C
512
    if ( IS_NULL_type ( r ) ) {
578
	if (IS_NULL_type(r)) {
513
	/* In C, compatible types are allowed */
579
		/* In C, compatible types are allowed */
514
	r = type_composite ( pt, ps, 1, 0, KILL_err, 1 ) ;
580
		r = type_composite(pt, ps, 1, 0, KILL_err, 1);
515
    }
581
	}
516
#endif
582
#endif
517
    if ( IS_NULL_type ( r ) ) {
583
	if (IS_NULL_type(r)) {
518
	/* Can't bring to common pointer type */
584
		/* Can't bring to common pointer type */
519
	if ( is_templ_type ( t ) || is_templ_type ( s ) ) {
585
		if (is_templ_type(t) || is_templ_type(s)) {
520
	    *suspect = -1 ;
586
			*suspect = -1;
521
	} else {
587
		} else {
522
	    *suspect = 2 ;
588
			*suspect = 2;
523
	}
589
		}
524
	if ( tag == type_ref_tag ) {
590
		if (tag == type_ref_tag) {
525
	    /* There are no generic references */
591
			/* There are no generic references */
526
	    return ( NULL_type ) ;
592
			return (NULL_type);
527
	}
593
		}
528
	r = type_void ;
594
		r = type_void;
529
    }
-
 
530
 
595
	}
531
    /* Qualify the common type appropriately */
-
 
532
    qt = find_cv_qual ( pt ) ;
-
 
533
    qs = find_cv_qual ( ps ) ;
-
 
534
    r = qualify_type ( r, ( qt | qs ), 0 ) ;
-
 
535
 
596
 
-
 
597
	/* Qualify the common type appropriately */
-
 
598
	qt = find_cv_qual(pt);
-
 
599
	qs = find_cv_qual(ps);
-
 
600
	r = qualify_type(r,(qt | qs), 0);
-
 
601
 
536
    /* Form the result type */
602
	/* Form the result type */
537
    if ( EQ_type ( r, pt ) ) return ( t ) ;
603
	if (EQ_type(r, pt)) {
-
 
604
		return (t);
-
 
605
	}
538
    if ( EQ_type ( r, ps ) ) return ( s ) ;
606
	if (EQ_type(r, ps)) {
-
 
607
		return (s);
-
 
608
	}
539
    MAKE_type_ptr_etc ( tag, cv_none, r, r ) ;
609
	MAKE_type_ptr_etc(tag, cv_none, r, r);
540
    return ( r ) ;
610
	return (r);
541
}
611
}
542
 
612
 
543
 
613
 
544
/*
614
/*
545
    FIND THE TYPE FOR A POINTER MEMBER OPERATION
615
    FIND THE TYPE FOR A POINTER MEMBER OPERATION
Line 550... Line 620...
550
    type then suspect is set to 2 and the error type is returned.  If
620
    type then suspect is set to 2 and the error type is returned.  If
551
    the cv-qualifier of the common type is not equal to the cv-qualifier
621
    the cv-qualifier of the common type is not equal to the cv-qualifier
552
    of either t or s then suspect is set to 1.
622
    of either t or s then suspect is set to 1.
553
*/
623
*/
554
 
624
 
555
TYPE ptr_mem_common_type
625
TYPE
556
    PROTO_N ( ( t, s, suspect ) )
-
 
557
    PROTO_T ( TYPE t X TYPE s X int *suspect )
626
ptr_mem_common_type(TYPE t, TYPE s, int *suspect)
558
{
627
{
559
    /* Check for base class conversions */
628
	/* Check for base class conversions */
560
    CLASS_TYPE ct = DEREF_ctype ( type_ptr_mem_of ( t ) ) ;
629
	CLASS_TYPE ct = DEREF_ctype(type_ptr_mem_of(t));
561
    CLASS_TYPE cs = DEREF_ctype ( type_ptr_mem_of ( s ) ) ;
630
	CLASS_TYPE cs = DEREF_ctype(type_ptr_mem_of(s));
562
    CLASS_TYPE cr = compare_base_class ( ct, cs, 1 ) ;
631
	CLASS_TYPE cr = compare_base_class(ct, cs, 1);
563
    if ( !IS_NULL_ctype ( cr ) ) {
632
	if (!IS_NULL_ctype(cr)) {
564
	TYPE pr ;
633
		TYPE pr;
565
	TYPE pt = DEREF_type ( type_ptr_mem_sub ( t ) ) ;
634
		TYPE pt = DEREF_type(type_ptr_mem_sub(t));
566
	TYPE ps = DEREF_type ( type_ptr_mem_sub ( s ) ) ;
635
		TYPE ps = DEREF_type(type_ptr_mem_sub(s));
567
	if ( EQ_ctype ( cr, ct ) ) {
636
		if (EQ_ctype(cr, ct)) {
568
	    cr = cs ;
637
			cr = cs;
569
	    pr = ps ;
638
			pr = ps;
570
	} else {
639
		} else {
571
	    cr = ct ;
640
			cr = ct;
572
	    pr = pt ;
641
			pr = pt;
-
 
642
		}
-
 
643
 
-
 
644
		/* Check that underlying types are the same */
-
 
645
		if (eq_type_unqual(pt, ps)) {
-
 
646
			/* Form the result type */
-
 
647
			CV_SPEC qt = find_cv_qual(pt);
-
 
648
			CV_SPEC qs = find_cv_qual(ps);
-
 
649
			CV_SPEC qr = (qt | qs);
-
 
650
			pr = qualify_type(pr, qr, 0);
-
 
651
			if (qt != qs && qr != qs) {
-
 
652
				*suspect = 1;
-
 
653
			}
-
 
654
			if (EQ_ctype(cr, ct) && EQ_type(pr, pt)) {
-
 
655
				return (t);
-
 
656
			}
-
 
657
			if (EQ_ctype(cr, cs) && EQ_type(pr, ps)) {
-
 
658
				return (s);
-
 
659
			}
-
 
660
			MAKE_type_ptr_mem(cv_none, cr, pr, pr);
-
 
661
			return (pr);
-
 
662
		}
573
	}
663
	}
574
 
664
 
575
	/* Check that underlying types are the same */
-
 
576
	if ( eq_type_unqual ( pt, ps ) ) {
-
 
577
	    /* Form the result type */
-
 
578
	    CV_SPEC qt = find_cv_qual ( pt ) ;
-
 
579
	    CV_SPEC qs = find_cv_qual ( ps ) ;
-
 
580
	    CV_SPEC qr = ( qt | qs ) ;
-
 
581
	    pr = qualify_type ( pr, qr, 0 ) ;
-
 
582
	    if ( qt != qs && qr != qs ) *suspect = 1 ;
-
 
583
	    if ( EQ_ctype ( cr, ct ) && EQ_type ( pr, pt ) ) return ( t ) ;
-
 
584
	    if ( EQ_ctype ( cr, cs ) && EQ_type ( pr, ps ) ) return ( s ) ;
-
 
585
	    MAKE_type_ptr_mem ( cv_none, cr, pr, pr ) ;
-
 
586
	    return ( pr ) ;
-
 
587
	}
-
 
588
    }
-
 
589
 
-
 
590
    /* Can't bring to common pointer member type */
665
	/* Can't bring to common pointer member type */
591
    if ( is_templ_type ( t ) || is_templ_type ( s ) ) {
666
	if (is_templ_type(t) || is_templ_type(s)) {
592
	*suspect = -1 ;
667
		*suspect = -1;
593
    } else {
668
	} else {
594
	*suspect = 2 ;
669
		*suspect = 2;
595
    }
670
	}
596
    return ( type_error ) ;
671
	return (type_error);
597
}
672
}
598
 
673
 
599
 
674
 
600
/*
675
/*
601
    FIND A COMMON TYPE
676
    FIND A COMMON TYPE
Line 607... Line 682...
607
    The null type is returned if the common type cannot be formed and
682
    The null type is returned if the common type cannot be formed and
608
    suspect is set accordingly.  The rules are essentially the same as
683
    suspect is set accordingly.  The rules are essentially the same as
609
    for the '?:' operation.
684
    for the '?:' operation.
610
*/
685
*/
611
 
686
 
612
TYPE common_type
687
TYPE
613
    PROTO_N ( ( t, s, suspect ) )
-
 
614
    PROTO_T ( TYPE t X TYPE s X int *suspect )
688
common_type(TYPE t, TYPE s, int *suspect)
615
{
689
{
616
    unsigned nt, ns ;
690
	unsigned nt, ns;
617
    TYPE r = NULL_type ;
691
	TYPE r = NULL_type;
618
    if ( IS_NULL_type ( t ) ) return ( s ) ;
692
	if (IS_NULL_type(t)) {
-
 
693
		return (s);
-
 
694
	}
619
    if ( IS_NULL_type ( s ) ) return ( t ) ;
695
	if (IS_NULL_type(s)) {
-
 
696
		return (t);
-
 
697
	}
620
    nt = TAG_type ( t ) ;
698
	nt = TAG_type(t);
621
    ns = TAG_type ( s ) ;
699
	ns = TAG_type(s);
622
    if ( nt == ns ) {
700
	if (nt == ns) {
623
	switch ( nt ) {
701
		switch (nt) {
624
	    case type_ptr_tag :
702
		case type_ptr_tag:
625
	    case type_ref_tag : {
703
		case type_ref_tag: {
626
		/* Common pointer or reference type */
704
			/* Common pointer or reference type */
627
		r = ptr_common_type ( t, s, 1, suspect ) ;
705
			r = ptr_common_type(t, s, 1, suspect);
628
		if ( *suspect != 2 ) return ( r ) ;
706
			if (*suspect != 2) {
-
 
707
				return (r);
-
 
708
			}
629
		r = NULL_type ;
709
			r = NULL_type;
630
		break ;
710
			break;
631
	    }
711
		}
632
	    case type_ptr_mem_tag : {
712
		case type_ptr_mem_tag: {
633
		/* Common pointer to member type */
713
			/* Common pointer to member type */
634
		r = ptr_mem_common_type ( t, s, suspect ) ;
714
			r = ptr_mem_common_type(t, s, suspect);
635
		if ( *suspect != 2 ) return ( r ) ;
715
			if (*suspect != 2) {
-
 
716
				return (r);
-
 
717
			}
636
		r = NULL_type ;
718
			r = NULL_type;
637
		break ;
719
			break;
638
	    }
720
		}
639
	    default : {
721
		default:
640
		/* Other types */
722
			/* Other types */
641
		if ( eq_type_unqual ( t, s ) ) {
723
			if (eq_type_unqual(t, s)) {
642
		    CV_SPEC qt = find_cv_qual ( t ) ;
724
				CV_SPEC qt = find_cv_qual(t);
643
		    CV_SPEC qs = find_cv_qual ( s ) ;
725
				CV_SPEC qs = find_cv_qual(s);
644
		    if ( qt != qs ) {
726
				if (qt != qs) {
645
			*suspect = 1 ;
727
					*suspect = 1;
646
			t = qualify_type ( t, ( qt | qs ), 0 ) ;
728
					t = qualify_type(t,(qt | qs), 0);
647
		    }
729
				}
648
		    return ( t ) ;
730
				return (t);
649
		}
731
			}
650
		break ;
732
			break;
651
	    }
733
		}
652
	}
734
	}
653
    }
-
 
654
    switch ( nt ) {
735
	switch (nt) {
655
	case type_integer_tag :
736
	case type_integer_tag:
656
	case type_enumerate_tag :
737
	case type_enumerate_tag:
657
	case type_bitfield_tag :
738
	case type_bitfield_tag:
658
	case type_floating_tag : {
739
	case type_floating_tag: {
659
	    switch ( ns ) {
740
		switch (ns) {
660
		case type_integer_tag :
741
		case type_integer_tag:
661
		case type_enumerate_tag :
742
		case type_enumerate_tag:
662
		case type_bitfield_tag :
743
		case type_bitfield_tag:
663
		case type_floating_tag : {
744
		case type_floating_tag: {
664
		    /* Common arithmetic type */
745
			/* Common arithmetic type */
665
		    r = arith_type ( t, s, NULL_exp, NULL_exp ) ;
746
			r = arith_type(t, s, NULL_exp, NULL_exp);
666
		    return ( r ) ;
747
			return (r);
667
		}
748
		}
668
	    }
749
		}
669
	}
750
	}
670
    }
751
	}
671
#if LANGUAGE_C
752
#if LANGUAGE_C
672
    if ( IS_NULL_type ( r ) ) {
753
	if (IS_NULL_type(r)) {
673
	r = type_composite ( t, s, 1, 0, KILL_err, 1 ) ;
754
		r = type_composite(t, s, 1, 0, KILL_err, 1);
674
	if ( !IS_NULL_type ( r ) ) return ( r ) ;
755
		if (!IS_NULL_type(r)) {
-
 
756
			return (r);
675
    }
757
		}
-
 
758
	}
676
#endif
759
#endif
677
    if ( nt == type_error_tag ) return ( s ) ;
760
	if (nt == type_error_tag) {
-
 
761
		return (s);
-
 
762
	}
678
    if ( ns == type_error_tag ) return ( t ) ;
763
	if (ns == type_error_tag) {
-
 
764
		return (t);
-
 
765
	}
679
    *suspect = 2 ;
766
	*suspect = 2;
680
    return ( r ) ;
767
	return (r);
681
}
768
}
682
 
769
 
683
 
770
 
684
/*
771
/*
685
    CONVERT AN EXPRESSION TO ITS PROMOTED TYPE
772
    CONVERT AN EXPRESSION TO ITS PROMOTED TYPE
686
 
773
 
687
    This routine converts the expression e to its promoted type, t
774
    This routine converts the expression e to its promoted type, t
688
    (previously calculated using promote_type).  Note that there is no
775
    (previously calculated using promote_type).  Note that there is no
689
    effect unless t is an integral type.
776
    effect unless t is an integral type.
690
*/
777
*/
691
 
778
 
692
EXP convert_promote
779
EXP
693
    PROTO_N ( ( t, e ) )
-
 
694
    PROTO_T ( TYPE t X EXP e )
780
convert_promote(TYPE t, EXP e)
695
{
781
{
696
    if ( IS_type_integer ( t ) ) {
782
	if (IS_type_integer(t)) {
697
	TYPE s = DEREF_type ( exp_type ( e ) ) ;
783
		TYPE s = DEREF_type(exp_type(e));
698
	if ( !EQ_type ( t, s ) ) {
784
		if (!EQ_type(t, s)) {
699
	    /* Perform non-trivial integral promotions */
785
			/* Perform non-trivial integral promotions */
700
	    e = cast_int_int ( t, e, KILL_err, CAST_IMPLICIT, 0 ) ;
786
			e = cast_int_int(t, e, KILL_err, CAST_IMPLICIT, 0);
-
 
787
		}
701
	}
788
	}
702
    }
-
 
703
    return ( e ) ;
789
	return (e);
704
}
790
}
705
 
791
 
706
 
792
 
707
/*
793
/*
708
    CONVERT AN EXPRESSION TO ITS ARITHMETIC TYPE
794
    CONVERT AN EXPRESSION TO ITS ARITHMETIC TYPE
709
 
795
 
710
    This routine converts the expression e to an arithmetic result type, t,
796
    This routine converts the expression e to an arithmetic result type, t,
711
    formed by arith_type using the type of e as its nth argument.  Note that
797
    formed by arith_type using the type of e as its nth argument.  Note that
712
    there are three cases: integer->integer, integer->float and float->float.
798
    there are three cases: integer->integer, integer->float and float->float.
713
*/
799
*/
714
 
800
 
715
EXP convert_arith
801
EXP
716
    PROTO_N ( ( t, e, op, n ) )
-
 
717
    PROTO_T ( TYPE t X EXP e X int op X int n )
802
convert_arith(TYPE t, EXP e, int op, int n)
718
{
803
{
719
    TYPE s = DEREF_type ( exp_type ( e ) ) ;
804
	TYPE s = DEREF_type(exp_type(e));
720
    if ( !EQ_type ( t, s ) ) {
805
	if (!EQ_type(t, s)) {
721
	ERROR err = NULL_err ;
806
		ERROR err = NULL_err;
722
	if ( IS_type_floating ( t ) ) {
807
		if (IS_type_floating(t)) {
723
	    unsigned tag = TAG_type ( s ) ;
808
			unsigned tag = TAG_type(s);
724
	    if ( tag == type_floating_tag ) {
809
			if (tag == type_floating_tag) {
725
		e = cast_float_float ( t, e, &err, CAST_IMPLICIT ) ;
810
				e = cast_float_float(t, e, &err, CAST_IMPLICIT);
726
	    } else {
811
			} else {
727
		if ( tag == type_bitfield_tag ) {
812
				if (tag == type_bitfield_tag) {
728
		    s = find_bitfield_type ( s ) ;
813
					s = find_bitfield_type(s);
729
		    e = cast_int_int ( s, e, &err, CAST_IMPLICIT, -1 ) ;
814
					e = cast_int_int(s, e, &err,
-
 
815
							 CAST_IMPLICIT, -1);
730
		}
816
				}
731
		e = cast_int_float ( t, e, &err, CAST_IMPLICIT ) ;
817
				e = cast_int_float(t, e, &err, CAST_IMPLICIT);
732
	    }
818
			}
733
	} else {
819
		} else {
734
	    e = cast_int_int ( t, e, &err, CAST_IMPLICIT, -1 ) ;
820
			e = cast_int_int(t, e, &err, CAST_IMPLICIT, -1);
735
	}
821
		}
736
	if ( !IS_NULL_err ( err ) ) {
822
		if (!IS_NULL_err(err)) {
737
	    unsigned m = ( unsigned ) n ;
823
			unsigned m = (unsigned)n;
738
	    err = concat_error ( err, ERR_expr_convert_op ( m, op ) ) ;
824
			err = concat_error(err, ERR_expr_convert_op(m, op));
739
	    report ( crt_loc, err ) ;
825
			report(crt_loc, err);
740
	}
826
		}
741
    }
827
	}
742
    return ( e ) ;
828
	return (e);
743
}
829
}
744
 
830
 
745
 
831
 
746
/*
832
/*
747
    CONVERT A POINTER TO A COMMON POINTER TYPE
833
    CONVERT A POINTER TO A COMMON POINTER TYPE
748
 
834
 
749
    This routine converts the pointer expression e to a common pointer
835
    This routine converts the pointer expression e to a common pointer
750
    type, t, formed by ptr_common_type using the type of e as its nth
836
    type, t, formed by ptr_common_type using the type of e as its nth
751
    argument.
837
    argument.
752
*/
838
*/
753
 
839
 
754
EXP convert_ptr_common
840
EXP
755
    PROTO_N ( ( t, e, op, n ) )
-
 
756
    PROTO_T ( TYPE t X EXP e X int op X int n )
841
convert_ptr_common(TYPE t, EXP e, int op, int n)
757
{
842
{
758
    TYPE s = DEREF_type ( exp_type ( e ) ) ;
843
	TYPE s = DEREF_type(exp_type(e));
759
    if ( !EQ_type ( t, s ) ) {
844
	if (!EQ_type(t, s)) {
760
	ERROR err = NULL_err ;
845
		ERROR err = NULL_err;
761
	e = cast_ptr_ptr ( t, e, &err, CAST_IMPLICIT, 1, 1 ) ;
846
		e = cast_ptr_ptr(t, e, &err, CAST_IMPLICIT, 1, 1);
762
	if ( !IS_NULL_err ( err ) ) {
847
		if (!IS_NULL_err(err)) {
763
	    unsigned m = ( unsigned ) n ;
848
			unsigned m = (unsigned)n;
764
	    err = concat_error ( err, ERR_expr_convert_op ( m, op ) ) ;
849
			err = concat_error(err, ERR_expr_convert_op(m, op));
765
	    report ( crt_loc, err ) ;
850
			report(crt_loc, err);
766
	}
851
		}
767
    }
852
	}
768
    return ( e ) ;
853
	return (e);
769
}
854
}
770
 
855
 
771
 
856
 
772
/*
857
/*
773
    CONVERT A POINTER MEMBER TO A COMMON POINTER MEMBER TYPE
858
    CONVERT A POINTER MEMBER TO A COMMON POINTER MEMBER TYPE
774
 
859
 
775
    This routine converts the pointer member expression e to a common
860
    This routine converts the pointer member expression e to a common
776
    pointer to member type, t, formed by ptr_mem_common_type using the
861
    pointer to member type, t, formed by ptr_mem_common_type using the
777
    type of e as its nth argument.
862
    type of e as its nth argument.
778
*/
863
*/
779
 
864
 
780
EXP convert_ptr_mem_common
865
EXP
781
    PROTO_N ( ( t, e, op, n ) )
-
 
782
    PROTO_T ( TYPE t X EXP e X int op X int n )
866
convert_ptr_mem_common(TYPE t, EXP e, int op, int n)
783
{
867
{
784
    TYPE s = DEREF_type ( exp_type ( e ) ) ;
868
	TYPE s = DEREF_type(exp_type(e));
785
    if ( !EQ_type ( t, s ) ) {
869
	if (!EQ_type(t, s)) {
786
	ERROR err = NULL_err ;
870
		ERROR err = NULL_err;
787
	e = cast_ptr_mem_ptr_mem ( t, e, &err, CAST_IMPLICIT, 1, 1 ) ;
871
		e = cast_ptr_mem_ptr_mem(t, e, &err, CAST_IMPLICIT, 1, 1);
788
	if ( !IS_NULL_err ( err ) ) {
872
		if (!IS_NULL_err(err)) {
789
	    unsigned m = ( unsigned ) n ;
873
			unsigned m = (unsigned)n;
790
	    err = concat_error ( err, ERR_expr_convert_op ( m, op ) ) ;
874
			err = concat_error(err, ERR_expr_convert_op(m, op));
791
	    report ( crt_loc, err ) ;
875
			report(crt_loc, err);
792
	}
876
		}
793
    }
877
	}
794
    return ( e ) ;
878
	return (e);
795
}
879
}
796
 
880
 
797
 
881
 
798
/*
882
/*
799
    CHECK FOR ASSIGNMENT IN A BOOLEAN
883
    CHECK FOR ASSIGNMENT IN A BOOLEAN
800
 
884
 
801
    This routine checks whether the expression a, which is to be converted
885
    This routine checks whether the expression a, which is to be converted
802
    to a boolean, is an assignment.  A warning is issued for 'x = y' and
886
    to a boolean, is an assignment.  A warning is issued for 'x = y' and
803
    'x /= y' because of possible confusion with 'x == y' and 'x != y'
887
    'x /= y' because of possible confusion with 'x == y' and 'x != y'
804
    respectively.  If the original expression was enclosed in brackets
888
    respectively.  If the original expression was enclosed in brackets
805
    (as indicated by tag) then no warning is issued.
889
    (as indicated by tag) then no warning is issued.
806
*/
890
*/
807
 
891
 
808
static void boolean_assign
892
static void
809
    PROTO_N ( ( a, tag ) )
-
 
810
    PROTO_T ( EXP a X unsigned tag )
893
boolean_assign(EXP a, unsigned tag)
811
{
894
{
812
    if ( tag != exp_paren_tag && !suppress_quality ) {
895
	if (tag != exp_paren_tag && !suppress_quality) {
813
	if ( IS_exp_assign ( a ) ) {
896
		if (IS_exp_assign(a)) {
814
	    report ( crt_loc, ERR_conv_bool_assign () ) ;
897
			report(crt_loc, ERR_conv_bool_assign());
815
	} else if ( IS_exp_preinc ( a ) ) {
898
		} else if (IS_exp_preinc(a)) {
816
	    int op = DEREF_int ( exp_preinc_becomes ( a ) ) ;
899
			int op = DEREF_int(exp_preinc_becomes(a));
817
	    if ( op == lex_assign || op == lex_div_Heq ) {
900
			if (op == lex_assign || op == lex_div_Heq) {
818
		report ( crt_loc, ERR_conv_bool_assign () ) ;
901
				report(crt_loc, ERR_conv_bool_assign());
819
	    }
902
			}
-
 
903
		}
820
	}
904
	}
821
    }
-
 
822
    return ;
905
	return;
823
}
906
}
824
 
907
 
825
 
908
 
826
/*
909
/*
827
    CONVERT AN EXPRESSION TO A BOOLEAN
910
    CONVERT AN EXPRESSION TO A BOOLEAN
Line 830... Line 913...
830
    returning the corresponding boolean expression.  Any error arising are
913
    returning the corresponding boolean expression.  Any error arising are
831
    added to the position indicated by the err argument.  User-defined
914
    added to the position indicated by the err argument.  User-defined
832
    conversions are handled elsewhere.
915
    conversions are handled elsewhere.
833
*/
916
*/
834
 
917
 
835
EXP convert_boolean
918
EXP
836
    PROTO_N ( ( a, tag, err ) )
-
 
837
    PROTO_T ( EXP a X unsigned tag X ERROR *err )
919
convert_boolean(EXP a, unsigned tag, ERROR *err)
838
{
920
{
839
    EXP e ;
921
	EXP e;
840
    TYPE t = DEREF_type ( exp_type ( a ) ) ;
922
	TYPE t = DEREF_type(exp_type(a));
841
    switch ( TAG_exp ( a ) ) {
923
	switch (TAG_exp(a)) {
842
	case exp_int_lit_tag : {
924
	case exp_int_lit_tag: {
843
	    /* Check for integer literals */
925
		/* Check for integer literals */
844
	    e = make_test_nat ( a ) ;
926
		e = make_test_nat(a);
845
	    return ( e ) ;
927
		return (e);
846
	}
928
	}
847
	case exp_float_lit_tag : {
929
	case exp_float_lit_tag: {
848
	    /* Check for floating-point literals */
930
		/* Check for floating-point literals */
849
	    FLOAT f = DEREF_flt ( exp_float_lit_flt ( a ) ) ;
931
		FLOAT f = DEREF_flt(exp_float_lit_flt(a));
850
	    NAT n = round_float_lit ( f, crt_round_mode ) ;
932
		NAT n = round_float_lit(f, crt_round_mode);
851
	    if ( !IS_NULL_nat ( n ) && IS_nat_small ( n ) ) {
933
		if (!IS_NULL_nat(n) && IS_nat_small(n)) {
852
		unsigned v = DEREF_unsigned ( nat_small_value ( n ) ) ;
934
			unsigned v = DEREF_unsigned(nat_small_value(n));
853
		if ( v < 2 ) {
935
			if (v < 2) {
854
		    v = BOOL_VALUE ( v ) ;
936
				v = BOOL_VALUE(v);
855
		    e = make_bool_exp ( v, exp_float_lit_tag ) ;
937
				e = make_bool_exp(v, exp_float_lit_tag);
856
		    return ( e ) ;
938
				return (e);
857
		}
939
			}
858
	    }
940
		}
859
	    MAKE_exp_test ( type_bool, ntest_not_eq, a, e ) ;
941
		MAKE_exp_test(type_bool, ntest_not_eq, a, e);
860
	    MAKE_nat_calc ( e, n ) ;
942
		MAKE_nat_calc(e, n);
861
	    MAKE_exp_int_lit ( type_bool, n, exp_test_tag, e ) ;
943
		MAKE_exp_int_lit(type_bool, n, exp_test_tag, e);
862
	    return ( e ) ;
944
		return (e);
863
	}
945
	}
864
	case exp_contents_tag : {
946
	case exp_contents_tag: {
865
	    /* Check for assignment in boolean */
947
		/* Check for assignment in boolean */
866
	    EXP b = DEREF_exp ( exp_contents_ptr ( a ) ) ;
948
		EXP b = DEREF_exp(exp_contents_ptr(a));
867
	    switch ( TAG_exp ( b ) ) {
949
		switch (TAG_exp(b)) {
868
		case exp_assign_tag :
950
		case exp_assign_tag:
869
		case exp_preinc_tag :
951
		case exp_preinc_tag:
870
		case exp_postinc_tag : {
952
		case exp_postinc_tag: {
871
		    boolean_assign ( b, tag ) ;
953
			boolean_assign(b, tag);
872
		    break ;
954
			break;
873
		}
955
		}
874
	    }
956
		}
-
 
957
		break;
-
 
958
	}
-
 
959
	case exp_assign_tag:
-
 
960
	case exp_preinc_tag:
-
 
961
	case exp_postinc_tag: {
-
 
962
		/* Check for assignment in boolean */
-
 
963
		boolean_assign(a, tag);
875
	    break ;
964
		break;
876
	}
965
	}
877
	case exp_assign_tag :
-
 
878
	case exp_preinc_tag :
-
 
879
	case exp_postinc_tag : {
-
 
880
	    /* Check for assignment in boolean */
-
 
881
	    boolean_assign ( a, tag ) ;
-
 
882
	    break ;
-
 
883
	}
966
	}
884
    }
-
 
885
 
967
 
886
    /* Perform the conversion */
968
	/* Perform the conversion */
887
    switch ( TAG_type ( t ) ) {
969
	switch (TAG_type(t)) {
888
	case type_integer_tag : {
970
	case type_integer_tag: {
889
	    /* Integral types are allowed */
971
		/* Integral types are allowed */
890
	    if ( check_int_type ( t, btype_bool ) ) return ( a ) ;
972
		if (check_int_type(t, btype_bool)) {
-
 
973
			return (a);
-
 
974
		}
891
	    break ;
975
		break;
892
	}
976
	}
893
	case type_bitfield_tag : {
977
	case type_bitfield_tag: {
894
	    /* Convert bitfields to integers */
978
		/* Convert bitfields to integers */
895
	    a = convert_bitfield ( a ) ;
979
		a = convert_bitfield(a);
896
	    break ;
980
		break;
897
	}
981
	}
898
	case type_enumerate_tag :
982
	case type_enumerate_tag:
899
	case type_floating_tag :
983
	case type_floating_tag:
900
	case type_ptr_tag :
984
	case type_ptr_tag:
901
	case type_ptr_mem_tag : {
985
	case type_ptr_mem_tag: {
902
	    /* These types are allowed */
986
		/* These types are allowed */
903
	    break ;
987
		break;
904
	}
988
	}
905
	case type_error_tag : {
989
	case type_error_tag: {
906
	    /* Allow for error propagation */
990
		/* Allow for error propagation */
907
	    break ;
991
		break;
908
	}
992
	}
909
	default : {
993
	default:
910
	    /* These types are not allowed */
994
		/* These types are not allowed */
911
	    add_error ( err, ERR_conv_bool_cast ( t ) ) ;
995
		add_error(err, ERR_conv_bool_cast(t));
912
	    break ;
996
		break;
913
	}
997
	}
914
    }
-
 
915
    MAKE_exp_test ( type_bool, ntest_not_eq, a, e ) ;
998
	MAKE_exp_test(type_bool, ntest_not_eq, a, e);
916
    return ( e ) ;
999
	return (e);
917
}
1000
}
918
 
1001
 
919
 
1002
 
920
/*
1003
/*
921
    REPORT OVERLOADED FUNCTIONS
1004
    REPORT OVERLOADED FUNCTIONS
Line 924... Line 1007...
924
    overloaded function.  If it represents a non-overloaded function which
1007
    overloaded function.  If it represents a non-overloaded function which
925
    has not already resolved using resolve_cast then the function is
1008
    has not already resolved using resolve_cast then the function is
926
    marked as used.
1009
    marked as used.
927
*/
1010
*/
928
 
1011
 
929
static int is_overloaded
1012
static int
930
    PROTO_N ( ( e ) )
-
 
931
    PROTO_T ( EXP e )
1013
is_overloaded(EXP e)
932
{
1014
{
933
    if ( !IS_NULL_exp ( e ) && IS_exp_identifier_etc ( e ) ) {
1015
	if (!IS_NULL_exp(e) && IS_exp_identifier_etc(e)) {
934
	IDENTIFIER id = DEREF_id ( exp_identifier_etc_id ( e ) ) ;
1016
		IDENTIFIER id = DEREF_id(exp_identifier_etc_id(e));
935
	if ( IS_id_function_etc ( id ) ) {
1017
		if (IS_id_function_etc(id)) {
936
	    QUALIFIER q = DEREF_qual ( exp_identifier_etc_qual ( e ) ) ;
1018
			QUALIFIER q = DEREF_qual(exp_identifier_etc_qual(e));
937
	    if ( !( q & qual_mark ) ) {
1019
			if (!(q & qual_mark)) {
938
		/* Not already resolved */
1020
				/* Not already resolved */
939
		TYPE fn = DEREF_type ( id_function_etc_type ( id ) ) ;
1021
				TYPE fn = DEREF_type(id_function_etc_type(id));
-
 
1022
				IDENTIFIER over =
940
		IDENTIFIER over = DEREF_id ( id_function_etc_over ( id ) ) ;
1023
				    DEREF_id(id_function_etc_over(id));
941
		if ( !IS_NULL_id ( over ) || IS_type_templ ( fn ) ) {
1024
				if (!IS_NULL_id(over) || IS_type_templ(fn)) {
942
		    /* Overloaded function */
1025
					/* Overloaded function */
-
 
1026
					report(crt_loc,
943
		    report ( crt_loc, ERR_over_over_context ( id ) ) ;
1027
					       ERR_over_over_context(id));
944
		    return ( 1 ) ;
1028
					return (1);
-
 
1029
				}
-
 
1030
				use_id(id, suppress_usage);
-
 
1031
			}
945
		}
1032
		}
946
		use_id ( id, suppress_usage ) ;
-
 
947
	    }
-
 
948
	}
1033
	}
949
    }
-
 
950
    return ( 0 ) ;
1034
	return (0);
951
}
1035
}
952
 
1036
 
953
 
1037
 
954
/*
1038
/*
955
    PERFORM QUALIFICATION CONVERSIONS ON A TYPE
1039
    PERFORM QUALIFICATION CONVERSIONS ON A TYPE
Line 957... Line 1041...
957
    This routine removes any type qualifiers from a rvalue, non-class
1041
    This routine removes any type qualifiers from a rvalue, non-class
958
    type t.  Class types maintain their type qualifiers, lvalue types
1042
    type t.  Class types maintain their type qualifiers, lvalue types
959
    lose theirs in convert_lvalue.
1043
    lose theirs in convert_lvalue.
960
*/
1044
*/
961
 
1045
 
962
TYPE convert_qual_type
1046
TYPE
963
    PROTO_N ( ( t ) )
-
 
964
    PROTO_T ( TYPE t )
1047
convert_qual_type(TYPE t)
965
{
1048
{
966
    CV_SPEC qual = DEREF_cv ( type_qual ( t ) ) ;
1049
	CV_SPEC qual = DEREF_cv(type_qual(t));
967
    if ( qual && !( qual & cv_lvalue ) ) {
1050
	if (qual && !(qual & cv_lvalue)) {
968
#if LANGUAGE_CPP
1051
#if LANGUAGE_CPP
969
	if ( IS_type_compound ( t ) ) return ( t ) ;
1052
		if (IS_type_compound(t)) {
-
 
1053
			return (t);
-
 
1054
		}
970
#endif
1055
#endif
971
	t = qualify_type ( t, cv_none, 0 ) ;
1056
		t = qualify_type(t, cv_none, 0);
972
    }
1057
	}
973
    return ( t ) ;
1058
	return (t);
974
}
1059
}
975
 
1060
 
976
 
1061
 
977
/*
1062
/*
978
    EVALUATE A CONST VARIABLE
1063
    EVALUATE A CONST VARIABLE
979
 
1064
 
980
    This routine evaluates the 'const' variable expression a, so that
1065
    This routine evaluates the 'const' variable expression a, so that
981
    for example, if 'const int c = 5 ;' then 'c' is evaluated to '5'.
1066
    for example, if 'const int c = 5 ;' then 'c' is evaluated to '5'.
982
*/
1067
*/
983
 
1068
 
984
EXP convert_const
1069
EXP
985
    PROTO_N ( ( a ) )
-
 
986
    PROTO_T ( EXP a )
1070
convert_const(EXP a)
987
{
1071
{
988
#if LANGUAGE_CPP
1072
#if LANGUAGE_CPP
989
    IDENTIFIER id = DEREF_id ( exp_identifier_id ( a ) ) ;
1073
	IDENTIFIER id = DEREF_id(exp_identifier_id(a));
990
    EXP e = DEREF_exp ( id_variable_etc_init ( id ) ) ;
1074
	EXP e = DEREF_exp(id_variable_etc_init(id));
991
    if ( !IS_NULL_exp ( e ) ) {
1075
	if (!IS_NULL_exp(e)) {
992
	switch ( TAG_exp ( e ) ) {
1076
		switch (TAG_exp(e)) {
993
	    case exp_int_lit_tag : {
1077
		case exp_int_lit_tag: {
994
		/* Propagate simple constants */
1078
			/* Propagate simple constants */
995
		NAT n ;
1079
			NAT n;
996
		TYPE t ;
1080
			TYPE t;
997
		unsigned tag ;
1081
			unsigned tag;
998
		DECONS_exp_int_lit ( t, n, tag, e ) ;
1082
			DECONS_exp_int_lit(t, n, tag, e);
999
		MAKE_exp_int_lit ( t, n, tag, e ) ;
1083
			MAKE_exp_int_lit(t, n, tag, e);
1000
		return ( e ) ;
1084
			return (e);
1001
	    }
1085
		}
1002
	    case exp_null_tag : {
1086
		case exp_null_tag: {
1003
		/* Propagate null constants */
1087
			/* Propagate null constants */
1004
		TYPE t ;
1088
			TYPE t;
1005
		DECONS_exp_null ( t, e ) ;
1089
			DECONS_exp_null(t, e);
1006
		MAKE_exp_null ( t, e ) ;
1090
			MAKE_exp_null(t, e);
1007
		return ( e ) ;
1091
			return (e);
1008
	    }
1092
		}
1009
	}
1093
		}
1010
    }
1094
	}
1011
#endif
1095
#endif
1012
    return ( a ) ;
1096
	return (a);
1013
}
1097
}
1014
 
1098
 
1015
 
1099
 
1016
/*
1100
/*
1017
    PERFORM ARRAY TO POINTER CONVERSION
1101
    PERFORM ARRAY TO POINTER CONVERSION
1018
 
1102
 
1019
    This routine performs array to pointer conversion on the array
1103
    This routine performs array to pointer conversion on the array
1020
    expression a.  If a is a string literal and str is true then the
1104
    expression a.  If a is a string literal and str is true then the
1021
    const qualifiers are removed from the string.  A warning is also
1105
    const qualifiers are removed from the string.  A warning is also
1022
    added to err if str is 2.
1106
    added to err if str is 2.
1023
*/
1107
*/
1024
 
1108
 
1025
EXP convert_array
1109
EXP
1026
    PROTO_N ( ( a, str, err ) )
-
 
1027
    PROTO_T ( EXP a X int str X ERROR *err )
1110
convert_array(EXP a, int str, ERROR *err)
1028
{
1111
{
1029
    TYPE t = DEREF_type ( exp_type ( a ) ) ;
1112
	TYPE t = DEREF_type(exp_type(a));
1030
    TYPE s = DEREF_type ( type_array_sub ( t ) ) ;
1113
	TYPE s = DEREF_type(type_array_sub(t));
1031
    if ( str && IS_exp_string_lit ( a ) ) {
1114
	if (str && IS_exp_string_lit(a)) {
1032
	/* Remove const from string literals */
1115
		/* Remove const from string literals */
1033
	CV_SPEC cv = DEREF_cv ( type_qual ( s ) ) ;
1116
		CV_SPEC cv = DEREF_cv(type_qual(s));
1034
	if ( cv & cv_const ) {
1117
		if (cv & cv_const) {
1035
	    cv &= ~cv_const ;
1118
			cv &= ~cv_const;
1036
	    s = qualify_type ( s, cv, 0 ) ;
1119
			s = qualify_type(s, cv, 0);
-
 
1120
			if (str == 2) {
1037
	    if ( str == 2 ) add_error ( err, ERR_conv_array_string () ) ;
1121
				add_error(err, ERR_conv_array_string());
-
 
1122
			}
1038
	}
1123
		}
1039
    } else if ( option ( OPT_addr_register ) && used_register ) {
1124
	} else if (option(OPT_addr_register) && used_register) {
1040
	/* Can't apply to a register variable in C */
1125
		/* Can't apply to a register variable in C */
1041
	EXP b = NULL_exp ;
1126
		EXP b = NULL_exp;
1042
	DECL_SPEC ds = find_exp_linkage ( a, &b, 1 ) ;
1127
		DECL_SPEC ds = find_exp_linkage(a, &b, 1);
1043
	if ( ( ds & dspec_register ) && !( ds & dspec_temp ) ) {
1128
		if ((ds & dspec_register) && !(ds & dspec_temp)) {
1044
	    if ( IS_exp_identifier ( b ) ) {
1129
			if (IS_exp_identifier(b)) {
1045
		IDENTIFIER id = DEREF_id ( exp_identifier_id ( b ) ) ;
1130
				IDENTIFIER id = DEREF_id(exp_identifier_id(b));
-
 
1131
				add_error(err,
1046
		add_error ( err, ERR_expr_unary_op_ref_register ( id ) ) ;
1132
					  ERR_expr_unary_op_ref_register(id));
1047
	    }
1133
			}
-
 
1134
		}
1048
	}
1135
	}
1049
    }
-
 
1050
    MAKE_type_ptr ( cv_none, s, t ) ;
1136
	MAKE_type_ptr(cv_none, s, t);
1051
    MAKE_exp_address ( t, a, a ) ;
1137
	MAKE_exp_address(t, a, a);
1052
    return ( a ) ;
1138
	return (a);
1053
}
1139
}
1054
 
1140
 
1055
 
1141
 
1056
/*
1142
/*
1057
    PERFORM LVALUE CONVERSIONS
1143
    PERFORM LVALUE CONVERSIONS
Line 1061... Line 1147...
1061
    function-to-pointer conversions are applied to transform it into an
1147
    function-to-pointer conversions are applied to transform it into an
1062
    rvalue.  Checks for overloaded functions are also applied at this
1148
    rvalue.  Checks for overloaded functions are also applied at this
1063
    stage to both lvalues and rvalues.
1149
    stage to both lvalues and rvalues.
1064
*/
1150
*/
1065
 
1151
 
1066
EXP convert_lvalue
1152
EXP
1067
    PROTO_N ( ( a ) )
-
 
1068
    PROTO_T ( EXP a )
1153
convert_lvalue(EXP a)
1069
{
1154
{
1070
    EXP e = a ;
1155
	EXP e = a;
1071
    TYPE t = DEREF_type ( exp_type ( a ) ) ;
1156
	TYPE t = DEREF_type(exp_type(a));
1072
    CV_SPEC qual = DEREF_cv ( type_qual ( t ) ) ;
1157
	CV_SPEC qual = DEREF_cv(type_qual(t));
1073
    if ( qual & cv_lvalue ) {
1158
	if (qual & cv_lvalue) {
1074
	CV_SPEC cv = cv_none ;
1159
		CV_SPEC cv = cv_none;
1075
	switch ( TAG_type ( t ) ) {
1160
		switch (TAG_type(t)) {
1076
	    case type_array_tag : {
1161
		case type_array_tag: {
1077
		/* Array-to-pointer conversion */
1162
			/* Array-to-pointer conversion */
1078
		ERROR err = NULL_err ;
1163
			ERROR err = NULL_err;
1079
		e = convert_array ( a, 0, &err ) ;
1164
			e = convert_array(a, 0, &err);
1080
		if ( !IS_NULL_err ( err ) ) report ( crt_loc, err ) ;
1165
			if (!IS_NULL_err(err)) {
-
 
1166
				report(crt_loc, err);
-
 
1167
			}
1081
		break ;
1168
			break;
1082
	    }
1169
		}
1083
	    case type_func_tag : {
1170
		case type_func_tag: {
1084
		/* Function-to-pointer conversion */
1171
			/* Function-to-pointer conversion */
1085
		if ( is_overloaded ( a ) ) {
1172
			if (is_overloaded(a)) {
1086
		    e = make_error_exp ( 0 ) ;
1173
				e = make_error_exp(0);
1087
		    break ;
1174
				break;
-
 
1175
			}
-
 
1176
			if (IS_exp_member(a)) {
-
 
1177
				goto default_lab;
-
 
1178
			}
-
 
1179
			MAKE_type_ptr(cv_none, t, t);
-
 
1180
			MAKE_exp_address(t, a, e);
-
 
1181
			break;
1088
		}
1182
		}
1089
		if ( IS_exp_member ( a ) ) goto default_lab ;
-
 
1090
		MAKE_type_ptr ( cv_none, t, t ) ;
-
 
1091
		MAKE_exp_address ( t, a, e ) ;
-
 
1092
		break ;
-
 
1093
	    }
-
 
1094
#if LANGUAGE_CPP
1183
#if LANGUAGE_CPP
1095
	    case type_compound_tag : {
1184
		case type_compound_tag: {
1096
		/* Classes preserve qualifiers in lvalue conversion */
1185
			/* Classes preserve qualifiers in lvalue conversion */
1097
		cv = ( qual & cv_qual ) ;
1186
			cv = (qual & cv_qual);
1098
		goto default_lab ;
1187
			goto default_lab;
1099
	    }
1188
		}
1100
#endif
1189
#endif
1101
	    case type_templ_tag : {
1190
		case type_templ_tag: {
1102
		/* Can't have template expressions */
1191
			/* Can't have template expressions */
1103
		if ( !is_overloaded ( a ) ) {
1192
			if (!is_overloaded(a)) {
1104
		    report ( crt_loc, ERR_temp_local_not ( t ) ) ;
1193
				report(crt_loc, ERR_temp_local_not(t));
-
 
1194
			}
-
 
1195
			e = make_error_exp(0);
-
 
1196
			break;
-
 
1197
		}
-
 
1198
		default :
-
 
1199
default_lab: {
-
 
1200
		     /* Lvalue-to-rvalue conversion */
-
 
1201
		     ERROR err;
-
 
1202
		     if (qual == (cv_const | cv_lvalue)) {
-
 
1203
			     /* Check for constants at this stage */
-
 
1204
			     if (IS_exp_identifier(a)) {
-
 
1205
				     e = convert_const(a);
-
 
1206
				     if (!EQ_exp(e, a)) {
-
 
1207
					     return (e);
-
 
1208
				     }
-
 
1209
			     }
-
 
1210
		     }
-
 
1211
		     t = qualify_type(t, cv, 0);
-
 
1212
		     err = check_incomplete(t);
-
 
1213
		     if (!IS_NULL_err(err)) {
-
 
1214
			     err = concat_error(err, ERR_conv_lval_incompl());
-
 
1215
			     report(crt_loc, err);
-
 
1216
		     }
-
 
1217
		     MAKE_exp_contents(t, a, e);
-
 
1218
		     break;
-
 
1219
	     }
1105
		}
1220
		}
1106
		e = make_error_exp ( 0 ) ;
-
 
1107
		break ;
-
 
1108
	    }
-
 
1109
	    default :
-
 
1110
	    default_lab : {
-
 
1111
		/* Lvalue-to-rvalue conversion */
-
 
1112
		ERROR err ;
-
 
1113
		if ( qual == ( cv_const | cv_lvalue ) ) {
-
 
1114
		    /* Check for constants at this stage */
-
 
1115
		    if ( IS_exp_identifier ( a ) ) {
-
 
1116
			e = convert_const ( a ) ;
-
 
1117
			if ( !EQ_exp ( e, a ) ) return ( e ) ;
-
 
1118
		    }
-
 
1119
		}
-
 
1120
		t = qualify_type ( t, cv, 0 ) ;
-
 
1121
		err = check_incomplete ( t ) ;
-
 
1122
		if ( !IS_NULL_err ( err ) ) {
-
 
1123
		    err = concat_error ( err, ERR_conv_lval_incompl () ) ;
-
 
1124
		    report ( crt_loc, err ) ;
-
 
1125
		}
-
 
1126
		MAKE_exp_contents ( t, a, e ) ;
-
 
1127
		break ;
-
 
1128
	    }
-
 
1129
	}
-
 
1130
 
1221
 
1131
    } else {
1222
	} else {
1132
	/* Check rvalues for overloaded functions */
1223
		/* Check rvalues for overloaded functions */
1133
	switch ( TAG_exp ( e ) ) {
1224
		switch (TAG_exp(e)) {
1134
	    case exp_address_tag : {
1225
		case exp_address_tag: {
1135
		/* Address of object or function */
1226
			/* Address of object or function */
1136
		EXP b = DEREF_exp ( exp_address_arg ( a ) ) ;
1227
			EXP b = DEREF_exp(exp_address_arg(a));
-
 
1228
			if (is_overloaded(b)) {
1137
		if ( is_overloaded ( b ) ) e = make_error_exp ( 0 ) ;
1229
				e = make_error_exp(0);
-
 
1230
			}
1138
		break ;
1231
			break;
1139
	    }
1232
		}
1140
	    case exp_address_mem_tag : {
1233
		case exp_address_mem_tag: {
1141
		/* Address of member or member function */
1234
			/* Address of member or member function */
1142
		EXP b = DEREF_exp ( exp_address_mem_arg ( a ) ) ;
1235
			EXP b = DEREF_exp(exp_address_mem_arg(a));
-
 
1236
			if (is_overloaded(b)) {
1143
		if ( is_overloaded ( b ) ) e = make_error_exp ( 0 ) ;
1237
				e = make_error_exp(0);
-
 
1238
			}
1144
		break ;
1239
			break;
1145
	    }
1240
		}
1146
	    case exp_token_tag : {
1241
		case exp_token_tag: {
1147
		/* Check for tokenised arrays */
1242
			/* Check for tokenised arrays */
1148
		if ( IS_type_array ( t ) ) {
1243
			if (IS_type_array(t)) {
1149
		    ERROR err = NULL_err ;
1244
				ERROR err = NULL_err;
1150
		    e = convert_array ( a, 0, &err ) ;
1245
				e = convert_array(a, 0, &err);
1151
		    if ( !IS_NULL_err ( err ) ) report ( crt_loc, err ) ;
1246
				if (!IS_NULL_err(err)) {
-
 
1247
					report(crt_loc, err);
-
 
1248
				}
-
 
1249
			}
-
 
1250
			break;
-
 
1251
		}
1152
		}
1252
		}
1153
		break ;
-
 
1154
	    }
-
 
1155
	}
1253
	}
1156
    }
-
 
1157
    return ( e ) ;
1254
	return (e);
1158
}
1255
}
1159
 
1256
 
1160
 
1257
 
1161
/*
1258
/*
1162
    CHECK AMBIGUOUS IDENTIFIERS
1259
    CHECK AMBIGUOUS IDENTIFIERS
1163
 
1260
 
1164
    This routine checks whether the identifier id represents a non-member
1261
    This routine checks whether the identifier id represents a non-member
1165
    function or an ambiguous set of such functions.  It is required because
1262
    function or an ambiguous set of such functions.  It is required because
1166
    overload resolution is used to distinguish between the ambiguous cases
1263
    overload resolution is used to distinguish between the ambiguous cases
1167
    for non-member functions, whereas it is an error otherwise.
1264
    for non-member functions, whereas it is an error otherwise.
1168
*/
1265
*/
1169
 
1266
 
1170
int is_ambiguous_func
1267
int
1171
    PROTO_N ( ( id ) )
-
 
1172
    PROTO_T ( IDENTIFIER id )
1268
is_ambiguous_func(IDENTIFIER id)
1173
{
1269
{
1174
    switch ( TAG_id ( id ) ) {
1270
	switch (TAG_id(id)) {
1175
	case id_ambig_tag : {
1271
	case id_ambig_tag: {
1176
	    /* Deal with ambiguous identifiers */
1272
		/* Deal with ambiguous identifiers */
1177
	    LIST ( IDENTIFIER ) p = DEREF_list ( id_ambig_ids ( id ) ) ;
1273
		LIST(IDENTIFIER)p = DEREF_list(id_ambig_ids(id));
1178
	    while ( !IS_NULL_list ( p ) ) {
1274
		while (!IS_NULL_list(p)) {
1179
		id = DEREF_id ( HEAD_list ( p ) ) ;
1275
			id = DEREF_id(HEAD_list(p));
1180
		if ( !is_ambiguous_func ( id ) ) return ( 0 ) ;
1276
			if (!is_ambiguous_func(id)) {
-
 
1277
				return (0);
-
 
1278
			}
1181
		p = TAIL_list ( p ) ;
1279
			p = TAIL_list(p);
1182
	    }
1280
		}
-
 
1281
		return (1);
-
 
1282
	}
-
 
1283
	case id_function_tag: {
-
 
1284
		/* These are functions */
1183
	    return ( 1 ) ;
1285
		return (1);
1184
	}
1286
	}
1185
	case id_function_tag : {
-
 
1186
	    /* These are functions */
-
 
1187
	    return ( 1 ) ;
-
 
1188
	}
1287
	}
1189
    }
-
 
1190
    return ( 0 ) ;
1288
	return (0);
1191
}
1289
}
1192
 
1290
 
1193
 
1291
 
1194
/*
1292
/*
1195
    PERFORM REFERENCE CONVERSIONS
1293
    PERFORM REFERENCE CONVERSIONS
Line 1200... Line 1298...
1200
    parentheses are removed, undeclared variables are reported, and
1298
    parentheses are removed, undeclared variables are reported, and
1201
    constants are evaluated.  The precise checks applied depend on context
1299
    constants are evaluated.  The precise checks applied depend on context
1202
    which can take one of the values from convert.h.
1300
    which can take one of the values from convert.h.
1203
*/
1301
*/
1204
 
1302
 
1205
EXP convert_reference
1303
EXP
1206
    PROTO_N ( ( a, context ) )
-
 
1207
    PROTO_T ( EXP a X int context )
1304
convert_reference(EXP a, int context)
1208
{
1305
{
1346
 
1442
 
1347
    /* Check for reference conversions */
1443
	/* Check for reference conversions */
1348
    if ( IS_type_ref ( t ) ) {
1444
	if (IS_type_ref(t)) {
1349
	/* Reference to t becomes lvalue t */
1445
		/* Reference to t becomes lvalue t */
1350
	if ( etag == exp_indir_tag ) {
1446
		if (etag == exp_indir_tag) {
1351
	    /* Can't have two indirections in a row */
1447
			/* Can't have two indirections in a row */
1352
	    MAKE_exp_contents ( t, a, a ) ;
1448
			MAKE_exp_contents(t, a, a);
-
 
1449
		}
-
 
1450
		t = DEREF_type(type_ref_sub(t));
-
 
1451
		/* Note that t is already an lvalue */
-
 
1452
		MAKE_exp_indir(t, a, a);
1353
	}
1453
	}
1354
	t = DEREF_type ( type_ref_sub ( t ) ) ;
-
 
1355
	/* Note that t is already an lvalue */
-
 
1356
	MAKE_exp_indir ( t, a, a ) ;
-
 
1357
    }
-
 
1358
    return ( a ) ;
1454
	return (a);
1359
}
1455
}
1360
 
1456
 
1361
 
1457
 
1362
/*
1458
/*
1363
    PROMOTE BITFIELD EXPRESSIONS
1459
    PROMOTE BITFIELD EXPRESSIONS
1364
 
1460
 
1365
    In certain expressions, even though an integral operand is not subject
1461
    In certain expressions, even though an integral operand is not subject
1366
    to integer promotion, bitfield expressions need to be converted to
1462
    to integer promotion, bitfield expressions need to be converted to
1367
    integral expressions by promotion.  This routine performs this conversion
1463
    integral expressions by promotion.  This routine performs this conversion
1368
    for the expression a.
1464
    for the expression a.
1369
*/
1465
*/
1370
 
1466
 
1371
EXP convert_bitfield
1467
EXP
1372
    PROTO_N ( ( a ) )
-
 
1373
    PROTO_T ( EXP a )
1468
convert_bitfield(EXP a)
1374
{
1469
{
1375
    TYPE t = DEREF_type ( exp_type ( a ) ) ;
1470
	TYPE t = DEREF_type(exp_type(a));
1376
    if ( IS_type_bitfield ( t ) ) {
1471
	if (IS_type_bitfield(t)) {
1377
	t = promote_type ( t ) ;
1472
		t = promote_type(t);
1378
	a = convert_promote ( t, a ) ;
1473
		a = convert_promote(t, a);
1379
    }
1474
	}
1380
    return ( a ) ;
1475
	return (a);
1381
}
1476
}
1382
 
1477
 
1383
 
1478
 
1384
/*
1479
/*
1385
    CONVERT OPERAND WHERE NO CONTEXT IS GIVEN
1480
    CONVERT OPERAND WHERE NO CONTEXT IS GIVEN
1386
 
1481
 
1387
    This routine performs conversions on the operand a in contexts where
1482
    This routine performs conversions on the operand a in contexts where
1388
    there is no information to resolve overloaded functions etc.  It also
1483
    there is no information to resolve overloaded functions etc.  It also
1389
    introduces temporary variables for constructor call expressions.
1484
    introduces temporary variables for constructor call expressions.
1390
*/
1485
*/
1391
 
1486
 
1392
EXP convert_none
1487
EXP
1393
    PROTO_N ( ( a ) )
-
 
1394
    PROTO_T ( EXP a )
1488
convert_none(EXP a)
1395
{
1489
{
1396
    if ( !IS_NULL_exp ( a ) ) {
1490
	if (!IS_NULL_exp(a)) {
1397
	ERROR err = NULL_err ;
1491
		ERROR err = NULL_err;
1398
	if ( IS_exp_constr ( a ) ) {
1492
		if (IS_exp_constr(a)) {
1399
	    TYPE t = DEREF_type ( exp_type ( a ) ) ;
1493
			TYPE t = DEREF_type(exp_type(a));
1400
	    a = make_temporary ( t, a, NULL_exp, 0, &err ) ;
1494
			a = make_temporary(t, a, NULL_exp, 0, &err);
1401
	    a = convert_lvalue ( a ) ;
1495
			a = convert_lvalue(a);
1402
	} else {
1496
		} else {
1403
	    LIST ( IDENTIFIER ) pids = NULL_list ( IDENTIFIER ) ;
1497
			LIST(IDENTIFIER)pids = NULL_list(IDENTIFIER);
1404
	    a = resolve_cast ( type_void, a, &err, 1, 0, pids ) ;
1498
			a = resolve_cast(type_void, a, &err, 1, 0, pids);
-
 
1499
		}
-
 
1500
		if (!IS_NULL_err(err)) {
-
 
1501
			report(crt_loc, err);
-
 
1502
		}
1405
	}
1503
	}
1406
	if ( !IS_NULL_err ( err ) ) report ( crt_loc, err ) ;
-
 
1407
    }
-
 
1408
    return ( a ) ;
1504
	return (a);
1409
}
1505
}
1410
 
1506
 
1411
 
1507
 
1412
/*
1508
/*
1413
    QUALIFICATION CONVERSIONS
1509
    QUALIFICATION CONVERSIONS
Line 1417... Line 1513...
1417
    cv_strlit is used to represent the removal of const from a string
1513
    cv_strlit is used to represent the removal of const from a string
1418
    literal.  cv_multi is used to represent qualifications which add
1514
    literal.  cv_multi is used to represent qualifications which add
1419
    qualifiers at more than one level.
1515
    qualifiers at more than one level.
1420
*/
1516
*/
1421
 
1517
 
1422
#define cv_strlit	( ( CV_SPEC ) 0x10 )
1518
#define cv_strlit	((CV_SPEC)0x10)
1423
#define cv_multi	( ( CV_SPEC ) 0x20 )
1519
#define cv_multi	((CV_SPEC)0x20)
1424
 
1520
 
1425
 
1521
 
1426
/*
1522
/*
1427
    CHECK FOR OVERLOADED FUNCTION CONVERSION SEQUENCES
1523
    CHECK FOR OVERLOADED FUNCTION CONVERSION SEQUENCES
1428
 
1524
 
1429
    This routine checks for conversion sequences between the overloaded
1525
    This routine checks for conversion sequences between the overloaded
1430
    function id and the pointer or pointer to member (of the correct class)
1526
    function id and the pointer or pointer to member (of the correct class)
1431
    type t.
1527
    type t.
1432
*/
1528
*/
1433
 
1529
 
1434
static unsigned overload_convert_seq
1530
static unsigned
1435
    PROTO_N ( ( t, id, p ) )
-
 
1436
    PROTO_T ( TYPE t X IDENTIFIER id X CONVERSION *p )
1531
overload_convert_seq(TYPE t, IDENTIFIER id, CONVERSION *p)
1437
{
1532
{
1438
    /* Check arguments */
1533
	/* Check arguments */
1439
    TYPE fn ;
1534
	TYPE fn;
1440
    int eq = 0 ;
1535
	int eq = 0;
1441
    CV_SPEC cv ;
1536
	CV_SPEC cv;
1442
    unsigned conv = CONV_EXACT ;
1537
	unsigned conv = CONV_EXACT;
1443
    unsigned tag = TAG_type ( t ) ;
1538
	unsigned tag = TAG_type(t);
1444
    if ( tag == type_ptr_tag ) {
1539
	if (tag == type_ptr_tag) {
1445
	fn = DEREF_type ( type_ptr_sub ( t ) ) ;
1540
		fn = DEREF_type(type_ptr_sub(t));
1446
    } else {
1541
	} else {
1447
	fn = DEREF_type ( type_ptr_mem_sub ( t ) ) ;
1542
		fn = DEREF_type(type_ptr_mem_sub(t));
1448
    }
1543
	}
1449
    if ( !IS_type_func ( fn ) ) return ( CONV_NONE ) ;
1544
	if (!IS_type_func(fn)) {
-
 
1545
		return (CONV_NONE);
-
 
1546
	}
1450
    cv = DEREF_cv ( type_qual ( fn ) ) ;
1547
	cv = DEREF_cv(type_qual(fn));
1451
    cv &= cv_qual ;
1548
	cv &= cv_qual;
1452
    if ( cv != cv_none ) conv = CONV_QUAL ;
1549
	if (cv != cv_none) {
-
 
1550
		conv = CONV_QUAL;
-
 
1551
	}
1453
    p->qual = cv ;
1552
	p->qual = cv;
1454
 
1553
 
1455
    /* Check for matching overload function */
1554
	/* Check for matching overload function */
1456
    id = resolve_func ( id, fn, 1, 0, NULL_list ( IDENTIFIER ), &eq ) ;
1555
	id = resolve_func(id, fn, 1, 0, NULL_list(IDENTIFIER), &eq);
1457
    if ( !IS_NULL_id ( id ) && eq == 3 ) {
1556
	if (!IS_NULL_id(id) && eq == 3) {
1458
	switch ( TAG_id ( id ) ) {
1557
		switch (TAG_id(id)) {
1459
	    case id_mem_func_tag : {
1558
		case id_mem_func_tag: {
1460
		/* A member function gives a pointer to member */
1559
			/* A member function gives a pointer to member */
1461
		if ( tag == type_ptr_mem_tag ) return ( conv ) ;
1560
			if (tag == type_ptr_mem_tag) {
-
 
1561
				return (conv);
-
 
1562
			}
1462
		break ;
1563
			break;
1463
	    }
1564
		}
1464
	    case id_function_tag :
1565
		case id_function_tag:
1465
	    case id_stat_mem_func_tag : {
1566
		case id_stat_mem_func_tag: {
1466
		/* Other functions give pointers */
1567
			/* Other functions give pointers */
1467
		if ( tag == type_ptr_tag ) return ( conv ) ;
1568
			if (tag == type_ptr_tag) {
-
 
1569
				return (conv);
-
 
1570
			}
1468
		break ;
1571
			break;
-
 
1572
		}
1469
	    }
1573
		}
1470
	}
1574
	}
1471
    }
-
 
1472
    return ( CONV_NONE ) ;
1575
	return (CONV_NONE);
1473
}
1576
}
1474
 
1577
 
1475
 
1578
 
1476
/*
1579
/*
1477
    CHECK FOR REFERENCE CONVERSION SEQUENCES
1580
    CHECK FOR REFERENCE CONVERSION SEQUENCES
Line 1484... Line 1587...
1484
    rvalue reference bindings.  Values of 2 and 3 allow rvalues of
1587
    rvalue reference bindings.  Values of 2 and 3 allow rvalues of
1485
    related types to be bound to any reference (not just const references),
1588
    related types to be bound to any reference (not just const references),
1486
    with 2 further regarding any base class conversions as exact matches.
1589
    with 2 further regarding any base class conversions as exact matches.
1487
*/
1590
*/
1488
 
1591
 
1489
static unsigned ref_convert_seq
1592
static unsigned
1490
    PROTO_N ( ( p, e, bind, std ) )
-
 
1491
    PROTO_T ( CONVERSION *p X EXP e X int bind X int std )
1593
ref_convert_seq(CONVERSION *p, EXP e, int bind, int std)
1492
{
1594
{
1493
    unsigned conv ;
1595
	unsigned conv;
1494
    TYPE t = DEREF_type ( type_ref_sub ( p->to ) ) ;
1596
	TYPE t = DEREF_type(type_ref_sub(p->to));
1495
    TYPE s = p->from ;
1597
	TYPE s = p->from;
1496
    unsigned nt = TAG_type ( t ) ;
1598
	unsigned nt = TAG_type(t);
1497
    unsigned ns = TAG_type ( s ) ;
1599
	unsigned ns = TAG_type(s);
1498
    CV_SPEC qs = DEREF_cv ( type_qual ( s ) ) ;
1600
	CV_SPEC qs = DEREF_cv(type_qual(s));
1499
    if ( qs & cv_lvalue ) {
1601
	if (qs & cv_lvalue) {
1500
	CV_SPEC cv = cv_compare ( t, s ) ;
1602
		CV_SPEC cv = cv_compare(t, s);
1501
	if ( cv == cv_none ) {
1603
		if (cv == cv_none) {
1502
	    /* Qualifiers are alright */
1604
			/* Qualifiers are alright */
1503
	    cv = cv_compare ( s, t ) ;
1605
			cv = cv_compare(s, t);
1504
	    p->qual = cv ;
1606
			p->qual = cv;
1505
	    if ( eq_type_unqual ( s, t ) ) {
1607
			if (eq_type_unqual(s, t)) {
1506
		if ( cv == cv_none ) {
1608
				if (cv == cv_none) {
1507
		    conv = CONV_EXACT ;
1609
					conv = CONV_EXACT;
1508
		} else {
1610
				} else {
1509
		    conv = CONV_QUAL ;
1611
					conv = CONV_QUAL;
1510
		}
1612
				}
1511
		return ( conv ) ;
1613
				return (conv);
1512
	    }
1614
			}
-
 
1615
			if (ns == type_compound_tag &&
1513
	    if ( ns == type_compound_tag && nt == type_compound_tag ) {
1616
			    nt == type_compound_tag) {
-
 
1617
				CLASS_TYPE ct =
1514
		CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
1618
				    DEREF_ctype(type_compound_defn(t));
-
 
1619
				CLASS_TYPE cs =
1515
		CLASS_TYPE cs = DEREF_ctype ( type_compound_defn ( s ) ) ;
1620
				    DEREF_ctype(type_compound_defn(s));
1516
		if ( eq_ctype ( ct, cs ) ) {
1621
				if (eq_ctype(ct, cs)) {
1517
		    /* Classes match */
1622
					/* Classes match */
1518
		    if ( cv == cv_none ) {
1623
					if (cv == cv_none) {
1519
			conv = CONV_EXACT ;
1624
						conv = CONV_EXACT;
1520
		    } else {
1625
					} else {
1521
			conv = CONV_QUAL ;
1626
						conv = CONV_QUAL;
1522
		    }
1627
					}
1523
		    return ( conv ) ;
1628
					return (conv);
1524
		} else {
1629
				} else {
1525
		    /* Check for base classes */
1630
					/* Check for base classes */
1526
		    GRAPH gr = find_base_class ( cs, ct, 0 ) ;
1631
					GRAPH gr = find_base_class(cs, ct, 0);
1527
		    if ( !IS_NULL_graph ( gr ) ) {
1632
					if (!IS_NULL_graph(gr)) {
1528
			/* Base class conversion */
1633
						/* Base class conversion */
1529
			p->base = gr ;
1634
						p->base = gr;
1530
			if ( bind == 2 ) {
1635
						if (bind == 2) {
-
 
1636
							/* Base class
1531
			    /* Base class conversions match exactly */
1637
							 * conversions match
-
 
1638
							 * exactly */
1532
			    if ( cv == cv_none ) {
1639
							if (cv == cv_none) {
-
 
1640
								conv =
1533
				conv = CONV_EXACT ;
1641
								    CONV_EXACT;
1534
			    } else {
1642
							} else {
-
 
1643
								conv =
1535
				conv = CONV_QUAL ;
1644
								    CONV_QUAL;
1536
			    }
1645
							}
-
 
1646
						} else {
-
 
1647
							conv = CONV_BASE;
-
 
1648
						}
-
 
1649
						return (conv);
-
 
1650
					}
-
 
1651
				}
-
 
1652
			}
-
 
1653
		}
-
 
1654
	}
-
 
1655
	if (bind == 0) {
-
 
1656
		/* Default - only const references allowed */
-
 
1657
		CV_SPEC qt = find_cv_qual(t);
-
 
1658
		if (qt != (cv_lvalue | cv_const)) {
-
 
1659
			return (CONV_NONE);
-
 
1660
		}
-
 
1661
		qs = find_cv_qual(s);
-
 
1662
		if (qs & cv_volatile) {
-
 
1663
			return (CONV_NONE);
-
 
1664
		}
-
 
1665
	} else if (bind == 1) {
-
 
1666
		/* No references allowed */
-
 
1667
		return (CONV_NONE);
-
 
1668
	} else {
-
 
1669
		/* All references allowed */
-
 
1670
		std = 1;
-
 
1671
	}
-
 
1672
	p->to = t;
-
 
1673
	p->from = s;
-
 
1674
	if (std) {
-
 
1675
		conv = std_convert_seq(p, e, bind, 1);
-
 
1676
	} else {
-
 
1677
		conv = convert_seq(p, e, bind, 1);
-
 
1678
	}
-
 
1679
	if (bind == 2) {
-
 
1680
		/* Base class conversions match exactly */
-
 
1681
		if (conv == CONV_BASE) {
-
 
1682
			if (p->qual == cv_none) {
-
 
1683
				conv = CONV_EXACT;
1537
			} else {
1684
			} else {
1538
			    conv = CONV_BASE ;
1685
				conv = CONV_QUAL;
1539
			}
1686
			}
1540
			return ( conv ) ;
-
 
1541
		    }
-
 
1542
		}
1687
		}
1543
	    }
-
 
1544
	}
1688
	}
1545
    }
-
 
1546
    if ( bind == 0 ) {
-
 
1547
	/* Default - only const references allowed */
-
 
1548
	CV_SPEC qt = find_cv_qual ( t ) ;
-
 
1549
	if ( qt != ( cv_lvalue | cv_const ) ) return ( CONV_NONE ) ;
-
 
1550
	qs = find_cv_qual ( s ) ;
-
 
1551
	if ( qs & cv_volatile ) return ( CONV_NONE ) ;
-
 
1552
    } else if ( bind == 1 ) {
-
 
1553
	/* No references allowed */
-
 
1554
	return ( CONV_NONE ) ;
-
 
1555
    } else {
-
 
1556
	/* All references allowed */
-
 
1557
	std = 1 ;
-
 
1558
    }
-
 
1559
    p->to = t ;
-
 
1560
    p->from = s ;
-
 
1561
    if ( std ) {
-
 
1562
	conv = std_convert_seq ( p, e, bind, 1 ) ;
-
 
1563
    } else {
-
 
1564
	conv = convert_seq ( p, e, bind, 1 ) ;
-
 
1565
    }
-
 
1566
    if ( bind == 2 ) {
-
 
1567
	/* Base class conversions match exactly */
-
 
1568
	if ( conv == CONV_BASE ) {
-
 
1569
	    if ( p->qual == cv_none ) {
-
 
1570
		conv = CONV_EXACT ;
-
 
1571
	    } else {
-
 
1572
		conv = CONV_QUAL ;
-
 
1573
	    }
-
 
1574
	}
-
 
1575
    }
-
 
1576
    return ( conv ) ;
1689
	return (conv);
1577
}
1690
}
1578
 
1691
 
1579
 
1692
 
1580
/*
1693
/*
1581
    CHECK FOR STANDARD CONVERSION SEQUENCES
1694
    CHECK FOR STANDARD CONVERSION SEQUENCES
1582
 
1695
 
1583
    This routine checks whether there is a standard conversion sequence
1696
    This routine checks whether there is a standard conversion sequence
1584
    between the types given by p.  e gives the argument being converted
1697
    between the types given by p.  e gives the argument being converted
Line 1588... Line 1701...
1588
    the canonical sequence, lvalue transformations, promotions, conversions
1701
    the canonical sequence, lvalue transformations, promotions, conversions
1589
    and qualification adjustments.  The routine returns the value indicating
1702
    and qualification adjustments.  The routine returns the value indicating
1590
    the rank of this conversion.
1703
    the rank of this conversion.
1591
*/
1704
*/
1592
 
1705
 
1593
unsigned std_convert_seq
1706
unsigned
1594
    PROTO_N ( ( p, e, bind, ref ) )
-
 
1595
    PROTO_T ( CONVERSION *p X EXP e X int bind X int ref )
1707
std_convert_seq(CONVERSION *p, EXP e, int bind, int ref)
1596
{
1708
{
1597
    CV_SPEC qs ;
1709
	CV_SPEC qs;
1598
    int str = 0 ;
1710
	int str = 0;
1599
    unsigned etag ;
1711
	unsigned etag;
1600
    TYPE t = p->to ;
1712
	TYPE t = p->to;
1601
    TYPE s = p->from ;
1713
	TYPE s = p->from;
1602
    unsigned nt, ns ;
1714
	unsigned nt, ns;
1603
    unsigned conv = CONV_NONE ;
1715
	unsigned conv = CONV_NONE;
1604
 
-
 
1605
    /* Conversion to the null type counts as exact */
-
 
1606
    if ( IS_NULL_type ( t ) ) return ( CONV_EXACT ) ;
-
 
1607
 
-
 
1608
    /* Conversion from the error type counts as ellipsis */
-
 
1609
    ns = TAG_type ( s ) ;
-
 
1610
    if ( ns == type_error_tag ) return ( CONV_ELLIPSIS ) ;
-
 
1611
    qs = DEREF_cv ( type_qual ( s ) ) ;
-
 
1612
 
-
 
1613
    /* Reference conversion */
-
 
1614
    if ( ns == type_ref_tag ) {
-
 
1615
	s = DEREF_type ( type_ref_sub ( s ) ) ;
-
 
1616
	p->from = s ;
-
 
1617
	ns = TAG_type ( s ) ;
-
 
1618
	if ( ns == type_error_tag ) return ( CONV_ELLIPSIS ) ;
-
 
1619
	qs = DEREF_cv ( type_qual ( s ) ) ;
-
 
1620
    }
-
 
1621
 
-
 
1622
    /* Deal with conversions to reference types */
-
 
1623
    nt = TAG_type ( t ) ;
-
 
1624
    if ( nt == type_ref_tag ) {
-
 
1625
	conv = ref_convert_seq ( p, e, bind, 1 ) ;
-
 
1626
	return ( conv ) ;
-
 
1627
    }
-
 
1628
 
-
 
1629
    /* Examine expression */
-
 
1630
    etag = ( IS_NULL_exp ( e ) ? null_tag : TAG_exp ( e ) ) ;
-
 
1631
 
-
 
1632
    /* Lvalue transformations */
-
 
1633
    if ( qs & cv_lvalue ) {
-
 
1634
	if ( ns == type_func_tag ) {
-
 
1635
	    /* Function to pointer conversion */
-
 
1636
	    if ( etag != exp_member_tag ) {
-
 
1637
		TYPE ps = s ;
-
 
1638
		s = type_temp_star ;
-
 
1639
		COPY_type ( type_ptr_sub ( s ), ps ) ;
-
 
1640
		ns = type_ptr_tag ;
-
 
1641
	    }
-
 
1642
	} else if ( ns == type_array_tag ) {
-
 
1643
	    /* Array to pointer conversion */
-
 
1644
	    TYPE ps = DEREF_type ( type_array_sub ( s ) ) ;
-
 
1645
	    s = type_temp_star ;
-
 
1646
	    COPY_type ( type_ptr_sub ( s ), ps ) ;
-
 
1647
	    ns = type_ptr_tag ;
-
 
1648
	} else {
-
 
1649
	    /* lvalue to rvalue conversion */
-
 
1650
	    if ( etag == exp_identifier_tag ) {
-
 
1651
		if ( qs == ( cv_lvalue | cv_const ) ) {
-
 
1652
		    IDENTIFIER id = DEREF_id ( exp_identifier_id ( e ) ) ;
-
 
1653
		    EXP d = DEREF_exp ( id_variable_etc_init ( id ) ) ;
-
 
1654
		    if ( is_zero_exp ( d ) ) {
-
 
1655
			/* Propagate zero constants */
-
 
1656
			e = d ;
-
 
1657
		    }
-
 
1658
		}
-
 
1659
	    }
-
 
1660
	}
-
 
1661
    }
-
 
1662
 
-
 
1663
    /* Promotions and conversions */
-
 
1664
    switch ( ns ) {
-
 
1665
 
-
 
1666
	case type_integer_tag :
-
 
1667
	case type_enumerate_tag :
-
 
1668
	integral_lab : {
-
 
1669
	    /* Integral and similar arguments */
-
 
1670
	    if ( nt == ns && eq_type_unqual ( t, s ) ) {
-
 
1671
		/* Exact match */
-
 
1672
		conv = CONV_EXACT ;
-
 
1673
	    } else {
-
 
1674
		TYPE ps = promote_type ( s ) ;
-
 
1675
		if ( !EQ_type ( ps, s ) && eq_type_unqual ( t, ps ) ) {
-
 
1676
		    /* Integral promotion */
-
 
1677
		    conv = CONV_INT_PROM ;
-
 
1678
		} else if ( nt == type_integer_tag ) {
-
 
1679
		    /* Integral conversions (subsumes booleans) */
-
 
1680
		    conv = CONV_INT_INT ;
-
 
1681
		} else if ( nt == type_floating_tag ) {
-
 
1682
		    /* Floating-integer conversions */
-
 
1683
		    conv = CONV_INT_FLT ;
-
 
1684
		} else if ( is_zero_exp ( e ) ) {
-
 
1685
		    if ( nt == type_ptr_tag ) {
-
 
1686
			/* Null pointers */
-
 
1687
			conv = CONV_PTR_NULL ;
-
 
1688
		    } else if ( nt == type_ptr_mem_tag ) {
-
 
1689
			/* Null pointer members */
-
 
1690
			conv = CONV_PTR_MEM_NULL ;
-
 
1691
		    }
-
 
1692
		}
-
 
1693
	    }
-
 
1694
	    break ;
-
 
1695
	}
-
 
1696
 
-
 
1697
	case type_bitfield_tag : {
-
 
1698
	    /* Ignore any bitfield qualifiers */
-
 
1699
	    s = find_bitfield_type ( s ) ;
-
 
1700
	    ns = TAG_type ( s ) ;
-
 
1701
	    goto integral_lab ;
-
 
1702
	}
-
 
1703
 
1716
 
-
 
1717
	/* Conversion to the null type counts as exact */
-
 
1718
	if (IS_NULL_type(t)) {
-
 
1719
		return (CONV_EXACT);
-
 
1720
	}
-
 
1721
 
-
 
1722
	/* Conversion from the error type counts as ellipsis */
-
 
1723
	ns = TAG_type(s);
1704
	case type_floating_tag : {
1724
	if (ns == type_error_tag) {
-
 
1725
		return (CONV_ELLIPSIS);
-
 
1726
	}
-
 
1727
	qs = DEREF_cv(type_qual(s));
-
 
1728
 
1705
	    /* Floating point arguments */
1729
	/* Reference conversion */
-
 
1730
	if (ns == type_ref_tag) {
-
 
1731
		s = DEREF_type(type_ref_sub(s));
-
 
1732
		p->from = s;
-
 
1733
		ns = TAG_type(s);
-
 
1734
		if (ns == type_error_tag) {
-
 
1735
			return (CONV_ELLIPSIS);
-
 
1736
		}
-
 
1737
		qs = DEREF_cv(type_qual(s));
-
 
1738
	}
-
 
1739
 
-
 
1740
	/* Deal with conversions to reference types */
-
 
1741
	nt = TAG_type(t);
1706
	    if ( nt == type_floating_tag ) {
1742
	if (nt == type_ref_tag) {
-
 
1743
		conv = ref_convert_seq(p, e, bind, 1);
-
 
1744
		return (conv);
-
 
1745
	}
-
 
1746
 
-
 
1747
	/* Examine expression */
-
 
1748
	etag = (IS_NULL_exp(e)? null_tag : TAG_exp(e));
-
 
1749
 
-
 
1750
	/* Lvalue transformations */
-
 
1751
	if (qs & cv_lvalue) {
1707
		if ( eq_type_unqual ( t, s ) ) {
1752
		if (ns == type_func_tag) {
-
 
1753
			/* Function to pointer conversion */
-
 
1754
			if (etag != exp_member_tag) {
-
 
1755
				TYPE ps = s;
1708
		    /* Exact match */
1756
				s = type_temp_star;
-
 
1757
				COPY_type(type_ptr_sub(s), ps);
1709
		    conv = CONV_EXACT ;
1758
				ns = type_ptr_tag;
-
 
1759
			}
-
 
1760
		} else if (ns == type_array_tag) {
-
 
1761
			/* Array to pointer conversion */
-
 
1762
			TYPE ps = DEREF_type(type_array_sub(s));
-
 
1763
			s = type_temp_star;
-
 
1764
			COPY_type(type_ptr_sub(s), ps);
-
 
1765
			ns = type_ptr_tag;
1710
		} else {
1766
		} else {
1711
		    TYPE ps = arg_promote_type ( s, KILL_err ) ;
1767
			/* lvalue to rvalue conversion */
1712
		    if ( !EQ_type ( ps, s ) && eq_type_unqual ( t, ps ) ) {
1768
			if (etag == exp_identifier_tag) {
1713
			/* Floating point promotion */
1769
				if (qs == (cv_lvalue | cv_const)) {
1714
			conv = CONV_FLT_PROM ;
1770
					IDENTIFIER id =
-
 
1771
					    DEREF_id(exp_identifier_id(e));
1715
		    } else {
1772
					EXP d =
-
 
1773
					    DEREF_exp(id_variable_etc_init(id));
-
 
1774
					if (is_zero_exp(d)) {
1716
			/* Floating point conversions */
1775
						/* Propagate zero constants */
1717
			conv = CONV_FLT_FLT ;
1776
						e = d;
1718
		    }
1777
					}
-
 
1778
				}
-
 
1779
			}
1719
		}
1780
		}
1720
	    } else if ( nt == type_integer_tag ) {
-
 
1721
		/* Floating-integer conversions (subsumes booleans) */
-
 
1722
		conv = CONV_FLT_INT ;
-
 
1723
	    }
-
 
1724
	    break ;
-
 
1725
	}
1781
	}
1726
 
1782
 
1727
	case type_ptr_tag :
1783
	/* Promotions and conversions */
1728
	pointer_lab : {
1784
	switch (ns) {
1729
	    /* Pointer arguments */
1785
	case type_integer_tag:
1730
	    if ( nt == type_ptr_tag ) {
1786
	case type_enumerate_tag:
1731
		/* Check for qualifier conversions */
1787
integral_lab:
1732
		unsigned qual = check_qualifier ( t, s, 0 ) ;
1788
		/* Integral and similar arguments */
1733
		if ( qualifier_depth <= 1 ) {
1789
		if (nt == ns && eq_type_unqual(t, s)) {
1734
		    CV_SPEC cv = qualifier_diff ;
1790
			/* Exact match */
1735
		    if ( str ) cv |= cv_strlit ;
-
 
1736
		    p->qual = cv ;
1791
			conv = CONV_EXACT;
1737
		} else {
1792
		} else {
1738
		    p->qual = cv_multi ;
1793
			TYPE ps = promote_type(s);
1739
		}
-
 
1740
		if ( qual == QUAL_EQUAL || qual == QUAL_EQ_FUNC ) {
1794
			if (!EQ_type(ps, s) && eq_type_unqual(t, ps)) {
1741
		    /* Exact match */
1795
				/* Integral promotion */
1742
		    conv = CONV_EXACT ;
1796
				conv = CONV_INT_PROM;
1743
		    if ( str ) conv = CONV_STRING ;
-
 
1744
		} else if ( qual == QUAL_OK ) {
1797
			} else if (nt == type_integer_tag) {
1745
		    /* Qualification conversion */
1798
				/* Integral conversions (subsumes booleans) */
1746
		    conv = CONV_QUAL ;
1799
				conv = CONV_INT_INT;
1747
		    if ( str ) conv = CONV_STRING ;
-
 
1748
		} else if ( qual == QUAL_CV ) {
1800
			} else if (nt == type_floating_tag) {
1749
		    /* Conversion preserves cv-qualifiers */
-
 
1750
		    TYPE pt = DEREF_type ( type_ptr_sub ( t ) ) ;
-
 
1751
		    TYPE ps = DEREF_type ( type_ptr_sub ( s ) ) ;
-
 
1752
		    nt = TAG_type ( pt ) ;
-
 
1753
		    ns = TAG_type ( ps ) ;
-
 
1754
		    if ( nt == type_compound_tag && ns == nt ) {
-
 
1755
			/* Pointer base class conversions */
1801
				/* Floating-integer conversions */
1756
			GRAPH gr ;
-
 
1757
			CLASS_TYPE ct, cs ;
-
 
1758
			ct = DEREF_ctype ( type_compound_defn ( pt ) ) ;
-
 
1759
			cs = DEREF_ctype ( type_compound_defn ( ps ) ) ;
-
 
1760
			gr = find_base_class ( cs, ct, 0 ) ;
-
 
1761
			if ( !IS_NULL_graph ( gr ) ) {
-
 
1762
			    /* Don't worry about ambiguity */
-
 
1763
			    p->base = gr ;
-
 
1764
			    conv = CONV_PTR_BASE ;
1802
				conv = CONV_INT_FLT;
1765
			}
-
 
1766
		    } else if ( nt == type_top_tag ) {
1803
			} else if (is_zero_exp(e)) {
1767
			if ( ns != type_func_tag ) {
1804
				if (nt == type_ptr_tag) {
1768
			    /* Pointer to 'void *' conversions */
1805
					/* Null pointers */
1769
			    conv = CONV_PTR_VOID ;
1806
					conv = CONV_PTR_NULL;
1770
			}
-
 
1771
		    } else if ( nt == type_bottom_tag ) {
1807
				} else if (nt == type_ptr_mem_tag) {
1772
			if ( ns != type_func_tag ) {
-
 
1773
			    /* Pointer to 'void *' conversions */
1808
					/* Null pointer members */
1774
			    conv = CONV_PTR_BOTTOM ;
1809
					conv = CONV_PTR_MEM_NULL;
1775
			}
1810
				}
1776
		    }
1811
			}
1777
		}
1812
		}
1778
		if ( conv == CONV_NONE ) {
1813
		break;
1779
		    /* Check for string literals */
1814
	case type_bitfield_tag: {
1780
		    if ( etag == exp_string_lit_tag && !str ) {
-
 
1781
			if ( !( qual & QUAL_CONST ) ) {
-
 
1782
			    TYPE ps = DEREF_type ( type_ptr_sub ( s ) ) ;
-
 
1783
			    ps = qualify_type ( ps, cv_none, 0 ) ;
1815
		/* Ignore any bitfield qualifiers */
1784
			    s = type_temp_star ;
1816
		s = find_bitfield_type(s);
1785
			    COPY_type ( type_ptr_sub ( s ), ps ) ;
-
 
1786
			    str = 1 ;
1817
		ns = TAG_type(s);
1787
			    goto pointer_lab ;
1818
		goto integral_lab;
1788
			}
1819
	}
1789
		    }
1820
	case type_floating_tag: {
1790
 
-
 
1791
		    /* Check for overloaded functions */
1821
		/* Floating point arguments */
1792
		    if ( etag == exp_address_tag ) {
1822
		if (nt == type_floating_tag) {
1793
			e = DEREF_exp ( exp_address_arg ( e ) ) ;
1823
			if (eq_type_unqual(t, s)) {
-
 
1824
				/* Exact match */
1794
			etag = TAG_exp ( e ) ;
1825
				conv = CONV_EXACT;
1795
		    }
1826
			} else {
1796
		    if ( etag == exp_identifier_tag ) {
1827
				TYPE ps = arg_promote_type(s, KILL_err);
1797
			IDENTIFIER id = DEREF_id ( exp_identifier_id ( e ) ) ;
1828
				if (!EQ_type(ps, s) && eq_type_unqual(t, ps)) {
1798
			conv = overload_convert_seq ( t, id, p ) ;
1829
					/* Floating point promotion */
1799
		    } else if ( etag == exp_ambiguous_tag ) {
1830
					conv = CONV_FLT_PROM;
-
 
1831
				} else {
1800
			IDENTIFIER id = DEREF_id ( exp_ambiguous_id ( e ) ) ;
1832
					/* Floating point conversions */
1801
			conv = overload_convert_seq ( t, id, p ) ;
1833
					conv = CONV_FLT_FLT;
1802
		    }
1834
				}
1803
		}
1835
			}
1804
	    } else if ( nt == type_integer_tag ) {
1836
		} else if (nt == type_integer_tag) {
1805
		if ( check_int_type ( t, btype_bool ) ) {
1837
			/* Floating-integer conversions (subsumes booleans) */
1806
		    /* Boolean conversions */
-
 
1807
		    conv = CONV_BOOL ;
1838
			conv = CONV_FLT_INT;
1808
		}
1839
		}
1809
	    }
-
 
1810
	    break ;
1840
		break;
1811
	}
1841
	}
-
 
1842
	case type_ptr_tag:
-
 
1843
pointer_lab:
-
 
1844
		/* Pointer arguments */
-
 
1845
		if (nt == type_ptr_tag) {
-
 
1846
			/* Check for qualifier conversions */
-
 
1847
			unsigned qual = check_qualifier(t, s, 0);
-
 
1848
			if (qualifier_depth <= 1) {
-
 
1849
				CV_SPEC cv = qualifier_diff;
-
 
1850
				if (str) {
-
 
1851
					cv |= cv_strlit;
-
 
1852
				}
-
 
1853
				p->qual = cv;
-
 
1854
			} else {
-
 
1855
				p->qual = cv_multi;
-
 
1856
			}
-
 
1857
			if (qual == QUAL_EQUAL || qual == QUAL_EQ_FUNC) {
-
 
1858
				/* Exact match */
-
 
1859
				conv = CONV_EXACT;
-
 
1860
				if (str) {
-
 
1861
					conv = CONV_STRING;
-
 
1862
				}
-
 
1863
			} else if (qual == QUAL_OK) {
-
 
1864
				/* Qualification conversion */
-
 
1865
				conv = CONV_QUAL;
-
 
1866
				if (str) {
-
 
1867
					conv = CONV_STRING;
-
 
1868
				}
-
 
1869
			} else if (qual == QUAL_CV) {
-
 
1870
				/* Conversion preserves cv-qualifiers */
-
 
1871
				TYPE pt = DEREF_type(type_ptr_sub(t));
-
 
1872
				TYPE ps = DEREF_type(type_ptr_sub(s));
-
 
1873
				nt = TAG_type(pt);
-
 
1874
				ns = TAG_type(ps);
-
 
1875
				if (nt == type_compound_tag && ns == nt) {
-
 
1876
					/* Pointer base class conversions */
-
 
1877
					GRAPH gr;
-
 
1878
					CLASS_TYPE ct, cs;
-
 
1879
					ct =
-
 
1880
					    DEREF_ctype(type_compound_defn(pt));
-
 
1881
					cs =
-
 
1882
					    DEREF_ctype(type_compound_defn(ps));
-
 
1883
					gr = find_base_class(cs, ct, 0);
-
 
1884
					if (!IS_NULL_graph(gr)) {
-
 
1885
						/* Don't worry about
-
 
1886
						 * ambiguity */
-
 
1887
						p->base = gr;
-
 
1888
						conv = CONV_PTR_BASE;
-
 
1889
					}
-
 
1890
				} else if (nt == type_top_tag) {
-
 
1891
					if (ns != type_func_tag) {
-
 
1892
						/* Pointer to 'void *'
-
 
1893
						 * conversions */
-
 
1894
						conv = CONV_PTR_VOID;
-
 
1895
					}
-
 
1896
				} else if (nt == type_bottom_tag) {
-
 
1897
					if (ns != type_func_tag) {
-
 
1898
						/* Pointer to 'void *'
-
 
1899
						 * conversions */
-
 
1900
						conv = CONV_PTR_BOTTOM;
-
 
1901
					}
-
 
1902
				}
-
 
1903
			}
-
 
1904
			if (conv == CONV_NONE) {
-
 
1905
				/* Check for string literals */
-
 
1906
				if (etag == exp_string_lit_tag && !str) {
-
 
1907
					if (!(qual & QUAL_CONST)) {
-
 
1908
						TYPE ps =
-
 
1909
						    DEREF_type(type_ptr_sub(s));
-
 
1910
						ps = qualify_type(ps, cv_none,
-
 
1911
								  0);
-
 
1912
						s = type_temp_star;
-
 
1913
						COPY_type(type_ptr_sub(s), ps);
-
 
1914
						str = 1;
-
 
1915
						goto pointer_lab;
-
 
1916
					}
-
 
1917
				}
1812
 
1918
 
1813
#if LANGUAGE_CPP
1919
				/* Check for overloaded functions */
1814
	case type_ptr_mem_tag : {
1920
				if (etag == exp_address_tag) {
1815
	    /* Pointer to member arguments */
1921
					e = DEREF_exp(exp_address_arg(e));
-
 
1922
					etag = TAG_exp(e);
-
 
1923
				}
1816
	    if ( nt == type_ptr_mem_tag ) {
1924
				if (etag == exp_identifier_tag) {
1817
		unsigned qual ;
1925
					IDENTIFIER id =
1818
		int ctype_match = 0 ;
1926
					    DEREF_id(exp_identifier_id(e));
1819
		CLASS_TYPE ct = DEREF_ctype ( type_ptr_mem_of ( t ) ) ;
1927
					conv = overload_convert_seq(t, id, p);
1820
		CLASS_TYPE cs = DEREF_ctype ( type_ptr_mem_of ( s ) ) ;
1928
				} else if (etag == exp_ambiguous_tag) {
-
 
1929
					IDENTIFIER id =
1821
		if ( eq_ctype ( ct, cs ) ) {
1930
					    DEREF_id(exp_ambiguous_id(e));
1822
		    ctype_match = 2 ;
1931
					conv = overload_convert_seq(t, id, p);
1823
		} else {
1932
				}
-
 
1933
			}
1824
		    GRAPH gr = find_base_class ( ct, cs, 0 ) ;
1934
		} else if (nt == type_integer_tag) {
1825
		    if ( !IS_NULL_graph ( gr ) ) {
1935
			if (check_int_type(t, btype_bool)) {
1826
			ctype_match = 1 ;
1936
				/* Boolean conversions */
1827
			p->base = gr ;
1937
				conv = CONV_BOOL;
1828
		    }
1938
			}
1829
		}
1939
		}
-
 
1940
		break;
-
 
1941
#if LANGUAGE_CPP
-
 
1942
	case type_ptr_mem_tag: {
-
 
1943
		/* Pointer to member arguments */
-
 
1944
		if (nt == type_ptr_mem_tag) {
-
 
1945
			unsigned qual;
-
 
1946
			int ctype_match = 0;
-
 
1947
			CLASS_TYPE ct = DEREF_ctype(type_ptr_mem_of(t));
-
 
1948
			CLASS_TYPE cs = DEREF_ctype(type_ptr_mem_of(s));
-
 
1949
			if (eq_ctype(ct, cs)) {
-
 
1950
				ctype_match = 2;
-
 
1951
			} else {
-
 
1952
				GRAPH gr = find_base_class(ct, cs, 0);
-
 
1953
				if (!IS_NULL_graph(gr)) {
-
 
1954
					ctype_match = 1;
-
 
1955
					p->base = gr;
-
 
1956
				}
-
 
1957
			}
1830
		if ( ctype_match ) {
1958
			if (ctype_match) {
1831
		    if ( etag == exp_address_mem_tag ) {
1959
				if (etag == exp_address_mem_tag) {
1832
			/* Check overloaded functions */
1960
					/* Check overloaded functions */
1833
			IDENTIFIER id ;
1961
					IDENTIFIER id;
1834
			e = DEREF_exp ( exp_address_mem_arg ( e ) ) ;
1962
					e = DEREF_exp(exp_address_mem_arg(e));
1835
			id = DEREF_id ( exp_member_id ( e ) ) ;
1963
					id = DEREF_id(exp_member_id(e));
1836
			if ( IS_id_function_etc ( id ) ) {
1964
					if (IS_id_function_etc(id)) {
1837
			    conv = overload_convert_seq ( t, id, p ) ;
1965
						conv = overload_convert_seq(t, id, p);
1838
			    if ( conv != CONV_NONE && ctype_match == 1 ) {
1966
						if (conv != CONV_NONE &&
-
 
1967
						    ctype_match == 1) {
1839
				conv = CONV_PTR_MEM_BASE ;
1968
							conv = CONV_PTR_MEM_BASE;
1840
			    }
1969
						}
1841
			    break ;
1970
						break;
-
 
1971
					}
-
 
1972
				}
-
 
1973
				/* Check other cases */
-
 
1974
				qual = check_qualifier(t, s, 0);
-
 
1975
				if (qualifier_depth <= 1) {
-
 
1976
					p->qual = qualifier_diff;
-
 
1977
				} else {
-
 
1978
					p->qual = cv_multi;
-
 
1979
				}
-
 
1980
				if (qual == QUAL_EQUAL ||
-
 
1981
				    qual == QUAL_EQ_FUNC) {
-
 
1982
					/* Exact match */
-
 
1983
					if (ctype_match == 2) {
-
 
1984
						conv = CONV_EXACT;
-
 
1985
					} else {
-
 
1986
						conv = CONV_PTR_MEM_BASE;
-
 
1987
					}
-
 
1988
				} else if (qual == QUAL_OK) {
-
 
1989
					/* Qualification conversion */
-
 
1990
					if (ctype_match == 2) {
-
 
1991
						conv = CONV_QUAL;
-
 
1992
					} else {
-
 
1993
						conv = CONV_PTR_MEM_BASE;
-
 
1994
					}
-
 
1995
				}
-
 
1996
			}
-
 
1997
		} else if (nt == type_integer_tag) {
-
 
1998
			if (check_int_type(t, btype_bool)) {
-
 
1999
				/* Boolean conversions */
-
 
2000
				conv = CONV_BOOL;
1842
			}
2001
			}
1843
		    }
-
 
1844
		    /* Check other cases */
-
 
1845
		    qual = check_qualifier ( t, s, 0 ) ;
-
 
1846
		    if ( qualifier_depth <= 1 ) {
2002
		} else if (nt == type_ptr_tag) {
1847
			p->qual = qualifier_diff ;
2003
			if (etag == exp_address_mem_tag) {
1848
		    } else {
-
 
1849
			p->qual = cv_multi ;
-
 
1850
		    }
-
 
1851
		    if ( qual == QUAL_EQUAL || qual == QUAL_EQ_FUNC ) {
-
 
1852
			/* Exact match */
2004
				/* Check overloaded functions */
1853
			if ( ctype_match == 2 ) {
-
 
1854
			    conv = CONV_EXACT ;
-
 
1855
			} else {
2005
				IDENTIFIER id;
1856
			    conv = CONV_PTR_MEM_BASE ;
-
 
1857
			}
-
 
1858
		    } else if ( qual == QUAL_OK ) {
2006
				e = DEREF_exp(exp_address_mem_arg(e));
1859
			/* Qualification conversion */
-
 
1860
			if ( ctype_match == 2 ) {
2007
				id = DEREF_id(exp_member_id(e));
1861
			    conv = CONV_QUAL ;
-
 
1862
			} else {
-
 
1863
			    conv = CONV_PTR_MEM_BASE ;
2008
				conv = overload_convert_seq(t, id, p);
1864
			}
2009
			}
1865
		    }
-
 
1866
		}
2010
		}
1867
	    } else if ( nt == type_integer_tag ) {
-
 
1868
		if ( check_int_type ( t, btype_bool ) ) {
-
 
1869
		    /* Boolean conversions */
-
 
1870
		    conv = CONV_BOOL ;
-
 
1871
		}
-
 
1872
	    } else if ( nt == type_ptr_tag ) {
-
 
1873
		if ( etag == exp_address_mem_tag ) {
-
 
1874
		    /* Check overloaded functions */
-
 
1875
		    IDENTIFIER id ;
-
 
1876
		    e = DEREF_exp ( exp_address_mem_arg ( e ) ) ;
-
 
1877
		    id = DEREF_id ( exp_member_id ( e ) ) ;
-
 
1878
		    conv = overload_convert_seq ( t, id, p ) ;
-
 
1879
		}
-
 
1880
	    }
-
 
1881
	    break ;
2011
		break;
1882
	}
2012
	}
1883
#endif
2013
#endif
1884
 
-
 
1885
	case type_compound_tag : {
2014
	case type_compound_tag: {
1886
	    /* Class arguments */
2015
		/* Class arguments */
1887
	    if ( nt == type_compound_tag ) {
2016
		if (nt == type_compound_tag) {
1888
		CV_SPEC cv = cv_compare ( t, s ) ;
2017
			CV_SPEC cv = cv_compare(t, s);
1889
		if ( cv == cv_none || !ref ) {
2018
			if (cv == cv_none || !ref) {
1890
		    CLASS_TYPE ct, cs ;
2019
				CLASS_TYPE ct, cs;
1891
		    cv = cv_compare ( s, t ) ;
2020
				cv = cv_compare(s, t);
1892
		    p->qual = cv ;
2021
				p->qual = cv;
1893
		    ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
2022
				ct = DEREF_ctype(type_compound_defn(t));
1894
		    cs = DEREF_ctype ( type_compound_defn ( s ) ) ;
2023
				cs = DEREF_ctype(type_compound_defn(s));
1895
		    if ( eq_ctype ( ct, cs ) ) {
2024
				if (eq_ctype(ct, cs)) {
1896
			/* Class types match */
2025
					/* Class types match */
1897
			if ( cv == cv_none ) {
2026
					if (cv == cv_none) {
1898
			    conv = CONV_EXACT ;
2027
						conv = CONV_EXACT;
1899
			} else {
2028
					} else {
1900
			    conv = CONV_QUAL ;
2029
						conv = CONV_QUAL;
-
 
2030
					}
-
 
2031
				} else {
-
 
2032
					/* Examine base classes */
-
 
2033
					GRAPH gr = find_base_class(cs, ct, 0);
-
 
2034
					if (!IS_NULL_graph(gr)) {
-
 
2035
						/* Base class conversion */
-
 
2036
						p->base = gr;
-
 
2037
						conv = CONV_BASE;
-
 
2038
					}
-
 
2039
				}
1901
			}
2040
			}
1902
		    } else {
-
 
1903
			/* Examine base classes */
-
 
1904
			GRAPH gr = find_base_class ( cs, ct, 0 ) ;
-
 
1905
			if ( !IS_NULL_graph ( gr ) ) {
-
 
1906
			    /* Base class conversion */
-
 
1907
			    p->base = gr ;
-
 
1908
			    conv = CONV_BASE ;
-
 
1909
			}
-
 
1910
		    }
-
 
1911
		}
2041
		}
-
 
2042
		break;
-
 
2043
	}
-
 
2044
	case type_func_tag: {
-
 
2045
		/* Address of overloaded static member function */
-
 
2046
		if (nt == type_ptr_tag && etag == exp_member_tag) {
-
 
2047
			IDENTIFIER id = DEREF_id(exp_member_id(e));
-
 
2048
			conv = overload_convert_seq(t, id, p);
1912
	    }
2049
		}
-
 
2050
		break;
-
 
2051
	}
-
 
2052
	case type_token_tag: {
-
 
2053
		/* Exact conversion on tokenised type */
-
 
2054
		if (nt == ns && eq_type_unqual(t, s)) {
-
 
2055
			conv = CONV_EXACT;
-
 
2056
		}
1913
	    break ;
2057
		break;
1914
	}
2058
	}
1915
 
-
 
1916
	case type_func_tag : {
-
 
1917
	    /* Address of overloaded static member function */
-
 
1918
	    if ( nt == type_ptr_tag && etag == exp_member_tag ) {
-
 
1919
		IDENTIFIER id = DEREF_id ( exp_member_id ( e ) ) ;
-
 
1920
		conv = overload_convert_seq ( t, id, p ) ;
-
 
1921
	    }
-
 
1922
	    break ;
-
 
1923
	}
-
 
1924
 
-
 
1925
	case type_token_tag : {
-
 
1926
	    /* Exact conversion on tokenised type */
-
 
1927
	    if ( nt == ns && eq_type_unqual ( t, s ) ) {
-
 
1928
		conv = CONV_EXACT ;
-
 
1929
	    }
-
 
1930
	    break ;
-
 
1931
	}
2059
	}
1932
    }
-
 
1933
    return ( conv ) ;
2060
	return (conv);
1934
}
2061
}
1935
 
2062
 
1936
 
2063
 
1937
/*
2064
/*
1938
    CHECK FOR CONVERSION SEQUENCES
2065
    CHECK FOR CONVERSION SEQUENCES
Line 1941... Line 2068...
1941
    corresponding to p.  e gives the argument being converted.  It returns
2068
    corresponding to p.  e gives the argument being converted.  It returns
1942
    the value indicating the rank of this conversion.  This is used in
2069
    the value indicating the rank of this conversion.  This is used in
1943
    overload resolution to determine the best viable function.
2070
    overload resolution to determine the best viable function.
1944
*/
2071
*/
1945
 
2072
 
1946
unsigned convert_seq
2073
unsigned
1947
    PROTO_N ( ( p, e, bind, ref ) )
-
 
1948
    PROTO_T ( CONVERSION *p X EXP e X int bind X int ref )
2074
convert_seq(CONVERSION *p, EXP e, int bind, int ref)
1949
{
2075
{
2098
 
2237
 
2099
 
2238
 
2100
/*
2239
/*
2101
    COMPARE TWO BASE CLASS CONVERSIONS
2240
    COMPARE TWO BASE CLASS CONVERSIONS
2102
 
2241
 
2103
    This routine compares the base classes given by p and q.  It returns 1
2242
    This routine compares the base classes given by p and q.  It returns 1
2104
    if p is a proper subgraph of q, 2 if q is a proper subgraph of p and
2243
    if p is a proper subgraph of q, 2 if q is a proper subgraph of p and
2105
    0 otherwise.
2244
    0 otherwise.
2106
*/
2245
*/
2107
 
2246
 
2108
static int base_compare_seq
2247
static int
2109
    PROTO_N ( ( p, q ) )
-
 
2110
    PROTO_T ( GRAPH p X GRAPH q )
2248
base_compare_seq(GRAPH p, GRAPH q)
2111
{
2249
{
2112
    CLASS_TYPE ct ;
2250
	CLASS_TYPE ct;
2113
    CLASS_TYPE pa, pb ;
2251
	CLASS_TYPE pa, pb;
2114
    CLASS_TYPE qa, qb ;
2252
	CLASS_TYPE qa, qb;
2115
 
2253
 
2116
    /* Decompose p into pa > pb */
2254
	/* Decompose p into pa > pb */
2117
    pb = DEREF_ctype ( graph_head ( p ) ) ;
2255
	pb = DEREF_ctype(graph_head(p));
2118
    p = DEREF_graph ( graph_top ( p ) ) ;
2256
	p = DEREF_graph(graph_top(p));
2119
    pa = DEREF_ctype ( graph_head ( p ) ) ;
2257
	pa = DEREF_ctype(graph_head(p));
2120
 
2258
 
2121
    /* Decompose q into qa > qb */
2259
	/* Decompose q into qa > qb */
2122
    qb = DEREF_ctype ( graph_head ( q ) ) ;
2260
	qb = DEREF_ctype(graph_head(q));
2123
    q = DEREF_graph ( graph_top ( q ) ) ;
2261
	q = DEREF_graph(graph_top(q));
2124
    qa = DEREF_ctype ( graph_head ( q ) ) ;
2262
	qa = DEREF_ctype(graph_head(q));
2125
 
2263
 
2126
    if ( eq_ctype ( pa, qa ) ) {
2264
	if (eq_ctype(pa, qa)) {
2127
	/* Graph tops are equal, pa = qa */
2265
		/* Graph tops are equal, pa = qa */
2128
	if ( eq_ctype ( pb, qb ) ) {
2266
		if (eq_ctype(pb, qb)) {
2129
	    /* Graphs are equal */
2267
			/* Graphs are equal */
2130
	    return ( 0 ) ;
2268
			return (0);
2131
	}
2269
		}
2132
	ct = compare_base_class ( pb, qb, 0 ) ;
2270
		ct = compare_base_class(pb, qb, 0);
2133
	if ( EQ_ctype ( ct, pb ) ) {
2271
		if (EQ_ctype(ct, pb)) {
2134
	    /* pa = qa > qb > pb */
2272
			/* pa = qa > qb > pb */
2135
	    return ( 2 ) ;
2273
			return (2);
2136
	}
2274
		}
2137
	if ( EQ_ctype ( ct, qb ) ) {
2275
		if (EQ_ctype(ct, qb)) {
2138
	    /* pa = qa > pb > qb */
2276
			/* pa = qa > pb > qb */
2139
	    return ( 1 ) ;
2277
			return (1);
2140
	}
2278
		}
2141
    } else if ( eq_ctype ( pb, qb ) ) {
2279
	} else if (eq_ctype(pb, qb)) {
2142
	/* Graph bottoms are equal, pb = qb */
2280
		/* Graph bottoms are equal, pb = qb */
2143
	ct = compare_base_class ( pa, qa, 0 ) ;
2281
		ct = compare_base_class(pa, qa, 0);
2144
	if ( EQ_ctype ( ct, pa ) ) {
2282
		if (EQ_ctype(ct, pa)) {
2145
	    /* qa > pa > pb = qb */
2283
			/* qa > pa > pb = qb */
2146
	    return ( 1 ) ;
2284
			return (1);
2147
	}
2285
		}
2148
	if ( EQ_ctype ( ct, qa ) ) {
2286
		if (EQ_ctype(ct, qa)) {
2149
	    /* pa > qa > pb = qb */
2287
			/* pa > qa > pb = qb */
2150
	    return ( 2 ) ;
2288
			return (2);
2151
	}
2289
		}
2152
    }
2290
	}
2153
    return ( 0 ) ;
2291
	return (0);
2154
}
2292
}
2155
 
2293
 
2156
 
2294
 
2157
/*
2295
/*
2158
    COMPARE TWO QUALIFICATION CONVERSIONS
2296
    COMPARE TWO QUALIFICATION CONVERSIONS
2159
 
2297
 
2160
    This routine compares the qualification conversions given by p and q.
2298
    This routine compares the qualification conversions given by p and q.
2161
    It returns 3 if they are identical, 1 if p is better (in that every
2299
    It returns 3 if they are identical, 1 if p is better (in that every
2162
    qualifier added by p is also added by q), 2 if q is better, and 0
2300
    qualifier added by p is also added by q), 2 if q is better, and 0
2163
    otherwise.  When qualifiers are added at only one level it is just
2301
    otherwise.  When qualifiers are added at only one level it is just
2164
    a matter of comparing the added qualifiers.  If qualifiers are added
2302
    a matter of comparing the added qualifiers.  If qualifiers are added
2165
    at more than one level a trial conversion is carried out.
2303
    at more than one level a trial conversion is carried out.
2166
*/
2304
*/
2167
 
2305
 
2168
static int qual_compare_seq
2306
static int
2169
    PROTO_N ( ( p, q ) )
-
 
2170
    PROTO_T ( CONVERSION *p X CONVERSION *q )
2307
qual_compare_seq(CONVERSION *p, CONVERSION *q)
2171
{
2308
{
2172
    CV_SPEC cp = p->qual ;
2309
	CV_SPEC cp = p->qual;
2173
    CV_SPEC cq = q->qual ;
2310
	CV_SPEC cq = q->qual;
2174
    if ( cp == cv_multi || cq == cv_multi ) {
2311
	if (cp == cv_multi || cq == cv_multi) {
2175
	/* Qualifiers at more than one level */
2312
		/* Qualifiers at more than one level */
2176
	TYPE t ;
2313
		TYPE t;
2177
	unsigned cmp ;
2314
		unsigned cmp;
2178
	CONVERSION r ;
2315
		CONVERSION r;
2179
	if ( EQ_type ( p->from, q->from ) ) {
2316
		if (EQ_type(p->from, q->from)) {
2180
	    /* Compare to-types */
2317
			/* Compare to-types */
2181
	    r.from = p->to ;
2318
			r.from = p->to;
2182
	    r.to = q->to ;
2319
			r.to = q->to;
2183
	} else if ( EQ_type ( p->to, q->to ) ) {
2320
		} else if (EQ_type(p->to, q->to)) {
2184
	    /* Compare from-types */
2321
			/* Compare from-types */
2185
	    r.from = q->from ;
2322
			r.from = q->from;
2186
	    r.to = p->from ;
2323
			r.to = p->from;
-
 
2324
		} else {
-
 
2325
			/* This shouldn't happen */
-
 
2326
			return (0);
-
 
2327
		}
-
 
2328
		cmp = std_convert_seq(&r, NULL_exp, 0, 0);
-
 
2329
		if (cmp == CONV_EXACT) {
-
 
2330
			return (3);
-
 
2331
		}
-
 
2332
		if (cmp != CONV_NONE) {
-
 
2333
			return (1);
-
 
2334
		}
-
 
2335
		t = r.from;
-
 
2336
		r.from = r.to;
-
 
2337
		r.to = t;
-
 
2338
		cmp = std_convert_seq(&r, NULL_exp, 0, 0);
-
 
2339
		if (cmp != CONV_NONE) {
-
 
2340
			return (2);
-
 
2341
		}
2187
	} else {
2342
	} else {
2188
	    /* This shouldn't happen */
2343
		/* Qualifiers at only one level */
-
 
2344
		CV_SPEC cr;
-
 
2345
		if (cp == cq) {
-
 
2346
			return (3);
-
 
2347
		}
-
 
2348
		cr = (cp | cq);
-
 
2349
		if (cr == cq) {
-
 
2350
			return (1);
-
 
2351
		}
-
 
2352
		if (cr == cp) {
2189
	    return ( 0 ) ;
2353
			return (2);
-
 
2354
		}
2190
	}
2355
	}
2191
	cmp = std_convert_seq ( &r, NULL_exp, 0, 0 ) ;
-
 
2192
	if ( cmp == CONV_EXACT ) return ( 3 ) ;
-
 
2193
	if ( cmp != CONV_NONE ) return ( 1 ) ;
-
 
2194
	t = r.from ;
-
 
2195
	r.from = r.to ;
-
 
2196
	r.to = t ;
-
 
2197
	cmp = std_convert_seq ( &r, NULL_exp, 0, 0 ) ;
-
 
2198
	if ( cmp != CONV_NONE ) return ( 2 ) ;
-
 
2199
    } else {
-
 
2200
	/* Qualifiers at only one level */
-
 
2201
	CV_SPEC cr ;
-
 
2202
	if ( cp == cq ) return ( 3 ) ;
-
 
2203
	cr = ( cp | cq ) ;
-
 
2204
	if ( cr == cq ) return ( 1 ) ;
-
 
2205
	if ( cr == cp ) return ( 2 ) ;
-
 
2206
    }
-
 
2207
    return ( 0 ) ;
2356
	return (0);
2208
}
2357
}
2209
 
2358
 
2210
 
2359
 
2211
/*
2360
/*
2212
    COMPARE TWO CONVERSION SEQUENCES
2361
    COMPARE TWO CONVERSION SEQUENCES
Line 2217... Line 2366...
2217
    the best viable function in overload resolution, it returns 1 if the
2366
    the best viable function in overload resolution, it returns 1 if the
2218
    first conversion is better, 2 if second is better, and some other
2367
    first conversion is better, 2 if second is better, and some other
2219
    value otherwise.
2368
    value otherwise.
2220
*/
2369
*/
2221
 
2370
 
2222
int compare_seq
2371
int
2223
    PROTO_N ( ( p1, p2 ) )
-
 
2224
    PROTO_T ( CONVERSION *p1 X CONVERSION *p2 )
2372
compare_seq(CONVERSION *p1, CONVERSION *p2)
2225
{
2373
{
2226
    /* Compare the ranks of the conversions */
2374
	/* Compare the ranks of the conversions */
2227
    int cmp = 0 ;
2375
	int cmp = 0;
2228
    unsigned a1 = p1->rank ;
2376
	unsigned a1 = p1->rank;
2229
    unsigned a2 = p2->rank ;
2377
	unsigned a2 = p2->rank;
2230
    unsigned b1 = CONV_RANK ( a1 ) ;
2378
	unsigned b1 = CONV_RANK(a1);
2231
    unsigned b2 = CONV_RANK ( a2 ) ;
2379
	unsigned b2 = CONV_RANK(a2);
2232
    if ( b1 > b2 ) return ( 1 ) ;
2380
	if (b1 > b2) {
-
 
2381
		return (1);
-
 
2382
	}
2233
    if ( b1 < b2 ) return ( 2 ) ;
2383
	if (b1 < b2) {
-
 
2384
		return (2);
-
 
2385
	}
2234
 
2386
 
2235
    /* Check user-defined conversions */
2387
	/* Check user-defined conversions */
2236
    if ( a1 == CONV_USER && a2 == CONV_USER ) {
2388
	if (a1 == CONV_USER && a2 == CONV_USER) {
2237
	if ( !EQ_id ( p1->usr, p2->usr ) ) return ( 0 ) ;
2389
		if (!EQ_id(p1->usr, p2->usr)) {
-
 
2390
			return (0);
-
 
2391
		}
2238
	a1 = p1->std ;
2392
		a1 = p1->std;
2239
	a2 = p2->std ;
2393
		a2 = p2->std;
2240
	b1 = CONV_RANK ( a1 ) ;
2394
		b1 = CONV_RANK(a1);
2241
	b2 = CONV_RANK ( a2 ) ;
2395
		b2 = CONV_RANK(a2);
2242
	if ( b1 > b2 ) return ( 1 ) ;
2396
		if (b1 > b2) {
-
 
2397
			return (1);
-
 
2398
		}
2243
	if ( b1 < b2 ) return ( 2 ) ;
2399
		if (b1 < b2) {
-
 
2400
			return (2);
2244
    }
2401
		}
-
 
2402
	}
2245
 
2403
 
2246
    /* Compare standard conversions */
2404
	/* Compare standard conversions */
2247
    switch ( a1 ) {
2405
	switch (a1) {
2248
	case CONV_PTR_BASE : {
2406
	case CONV_PTR_BASE: {
2249
	    /* Pointer conversions */
2407
		/* Pointer conversions */
2250
	    if ( a2 == a1 ) {
2408
		if (a2 == a1) {
2251
		/* Compare base pointer conversions */
2409
			/* Compare base pointer conversions */
2252
		GRAPH g1 = p1->base ;
2410
			GRAPH g1 = p1->base;
2253
		GRAPH g2 = p2->base ;
2411
			GRAPH g2 = p2->base;
2254
		if ( eq_graph ( g1, g2 ) ) {
2412
			if (eq_graph(g1, g2)) {
2255
		    cmp = qual_compare_seq ( p1, p2 ) ;
2413
				cmp = qual_compare_seq(p1, p2);
2256
		} else {
2414
			} else {
2257
		    cmp = base_compare_seq ( g1, g2 ) ;
2415
				cmp = base_compare_seq(g1, g2);
2258
		}
2416
			}
2259
	    } else if ( a2 == CONV_PTR_VOID || a2 == CONV_PTR_BOTTOM ) {
2417
		} else if (a2 == CONV_PTR_VOID || a2 == CONV_PTR_BOTTOM) {
2260
		/* Base pointer conversion is better than 'void *' */
2418
			/* Base pointer conversion is better than 'void *' */
2261
		cmp = 1 ;
2419
			cmp = 1;
2262
	    } else if ( a2 == CONV_BOOL ) {
2420
		} else if (a2 == CONV_BOOL) {
2263
		/* Base pointer conversion is better than 'bool' */
2421
			/* Base pointer conversion is better than 'bool' */
2264
		cmp = 1 ;
2422
			cmp = 1;
2265
	    }
2423
		}
2266
	    break ;
2424
		break;
2267
	}
2425
	}
2268
	case CONV_PTR_VOID :
2426
	case CONV_PTR_VOID:
2269
	case CONV_PTR_BOTTOM : {
2427
	case CONV_PTR_BOTTOM: {
2270
	    /* Pointer to 'void *' conversions */
2428
		/* Pointer to 'void *' conversions */
2271
	    if ( a2 == CONV_PTR_VOID || a2 == CONV_PTR_BOTTOM ) {
2429
		if (a2 == CONV_PTR_VOID || a2 == CONV_PTR_BOTTOM) {
2272
		/* Compare pointer conversions */
2430
			/* Compare pointer conversions */
2273
		cmp = qual_compare_seq ( p1, p2 ) ;
2431
			cmp = qual_compare_seq(p1, p2);
2274
	    } else if ( a2 == CONV_PTR_BASE ) {
2432
		} else if (a2 == CONV_PTR_BASE) {
2275
		/* Base pointer conversion is better than 'void *' */
2433
			/* Base pointer conversion is better than 'void *' */
2276
		cmp = 2 ;
2434
			cmp = 2;
2277
	    } else if ( a2 == CONV_BOOL ) {
2435
		} else if (a2 == CONV_BOOL) {
2278
		/* Pointer conversion is better than 'bool' */
2436
			/* Pointer conversion is better than 'bool' */
2279
		cmp = 1 ;
2437
			cmp = 1;
2280
	    }
2438
		}
2281
	    break ;
2439
		break;
2282
	}
2440
	}
2283
	case CONV_PTR_MEM_BASE : {
2441
	case CONV_PTR_MEM_BASE: {
2284
	    /* Pointer member conversions */
2442
		/* Pointer member conversions */
2285
	    if ( a2 == a1 ) {
2443
		if (a2 == a1) {
2286
		/* Compare base pointer member conversions */
2444
			/* Compare base pointer member conversions */
2287
		GRAPH g1 = p1->base ;
2445
			GRAPH g1 = p1->base;
2288
		GRAPH g2 = p2->base ;
2446
			GRAPH g2 = p2->base;
2289
		if ( eq_graph ( g1, g2 ) ) {
2447
			if (eq_graph(g1, g2)) {
2290
		    cmp = qual_compare_seq ( p1, p2 ) ;
2448
				cmp = qual_compare_seq(p1, p2);
2291
		} else {
2449
			} else {
2292
		    int bmp = base_compare_seq ( g1, g2 ) ;
2450
				int bmp = base_compare_seq(g1, g2);
2293
		    if ( bmp ) {
2451
				if (bmp) {
2294
			cmp = qual_compare_seq ( p1, p2 ) ;
2452
					cmp = qual_compare_seq(p1, p2);
2295
			switch ( cmp ) {
2453
					switch (cmp) {
2296
			    case 1 : {
2454
					case 1: {
2297
				if ( bmp != 2 ) cmp = 0 ;
2455
						if (bmp != 2) {
-
 
2456
							cmp = 0;
-
 
2457
						}
2298
				break ;
2458
						break;
2299
			    }
2459
					}
2300
			    case 2 : {
2460
					case 2: {
2301
				if ( bmp != 1 ) cmp = 0 ;
2461
						if (bmp != 1) {
-
 
2462
							cmp = 0;
-
 
2463
						}
2302
				break ;
2464
						break;
2303
			    }
2465
					}
2304
			    case 3 : {
2466
					case 3: {
2305
				cmp = bmp ;
2467
						cmp = bmp;
2306
				break ;
2468
						break;
-
 
2469
					}
2307
			    }
2470
					}
-
 
2471
				}
-
 
2472
			}
-
 
2473
		} else if (a2 == CONV_BOOL) {
-
 
2474
			/* Pointer conversion is better than 'bool' */
-
 
2475
			cmp = 1;
-
 
2476
		}
-
 
2477
		break;
-
 
2478
	}
-
 
2479
	case CONV_BASE: {
-
 
2480
		/* Base class conversions */
-
 
2481
		if (a2 == a1) {
-
 
2482
			/* Compare base class conversions */
-
 
2483
			GRAPH g1 = p1->base;
-
 
2484
			GRAPH g2 = p2->base;
-
 
2485
			if (eq_graph(g1, g2)) {
-
 
2486
				cmp = qual_compare_seq(p1, p2);
-
 
2487
			} else {
-
 
2488
				cmp = base_compare_seq(g1, g2);
2308
			}
2489
			}
2309
		    }
-
 
2310
		}
2490
		}
2311
	    } else if ( a2 == CONV_BOOL ) {
-
 
2312
		/* Pointer conversion is better than 'bool' */
-
 
2313
		cmp = 1 ;
-
 
2314
	    }
-
 
2315
	    break ;
2491
		break;
2316
	}
2492
	}
2317
	case CONV_BASE : {
2493
	case CONV_BOOL: {
2318
	    /* Base class conversions */
2494
		/* Boolean conversions */
2319
	    if ( a2 == a1 ) {
-
 
2320
		/* Compare base class conversions */
2495
		if (a2 == CONV_PTR_BASE || a2 == CONV_PTR_MEM_BASE ||
2321
		GRAPH g1 = p1->base ;
-
 
2322
		GRAPH g2 = p2->base ;
-
 
2323
		if ( eq_graph ( g1, g2 ) ) {
2496
		    a2 == CONV_PTR_VOID || a2 == CONV_PTR_BOTTOM) {
2324
		    cmp = qual_compare_seq ( p1, p2 ) ;
2497
			/* Pointer conversion is better than 'bool' */
2325
		} else {
2498
			cmp = 2;
2326
		    cmp = base_compare_seq ( g1, g2 ) ;
-
 
2327
		}
2499
		}
2328
	    }
-
 
2329
	    break ;
2500
		break;
2330
	}
2501
	}
2331
	case CONV_BOOL : {
2502
	case CONV_STRING: {
2332
	    /* Boolean conversions */
2503
		/* String literal conversions */
-
 
2504
		if (a2 == a1) {
2333
	    if ( a2 == CONV_PTR_BASE || a2 == CONV_PTR_MEM_BASE ||
2505
			cmp = qual_compare_seq(p1, p2);
2334
		 a2 == CONV_PTR_VOID || a2 == CONV_PTR_BOTTOM ) {
2506
		} else if (a2 == CONV_QUAL) {
2335
		/* Pointer conversion is better than 'bool' */
2507
			/* Qualification conversion is better than string */
2336
		cmp = 2 ;
2508
			cmp = 2;
2337
	    }
2509
		}
2338
	    break ;
2510
		break;
2339
	}
2511
	}
2340
	case CONV_STRING : {
2512
	case CONV_QUAL: {
2341
	    /* String literal conversions */
2513
		/* Qualification conversions */
2342
	    if ( a2 == a1 ) {
2514
		if (a2 == a1) {
2343
		cmp = qual_compare_seq ( p1, p2 ) ;
2515
			cmp = qual_compare_seq(p1, p2);
2344
	    } else if ( a2 == CONV_QUAL ) {
2516
		} else if (a2 == CONV_STRING) {
2345
		/* Qualification conversion is better than string */
2517
			/* Qualification conversion is better than string */
2346
		cmp = 2 ;
2518
			cmp = 1;
2347
	    }
2519
		}
2348
	    break ;
2520
		break;
2349
	}
2521
	}
2350
	case CONV_QUAL : {
-
 
2351
	    /* Qualification conversions */
-
 
2352
	    if ( a2 == a1 ) {
-
 
2353
		cmp = qual_compare_seq ( p1, p2 ) ;
-
 
2354
	    } else if ( a2 == CONV_STRING ) {
-
 
2355
		/* Qualification conversion is better than string */
-
 
2356
		cmp = 1 ;
-
 
2357
	    }
-
 
2358
	    break ;
-
 
2359
	}
2522
	}
2360
    }
-
 
2361
    return ( cmp ) ;
2523
	return (cmp);
2362
}
2524
}