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

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

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

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

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

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

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

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

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

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

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

Warning: Undefined variable $m in /usr/local/www/websvn.planix.org/include/diff_util.php on line 251
WebSVN – tendra.SVN – Diff – /branches/tendra5/src/producers/common/construct/operator.c – Rev 5 and 6

Subversion Repositories tendra.SVN

Rev

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

Rev 5 Rev 6
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2006 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
32
    		 Crown Copyright (c) 1997
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
Line 74... Line 104...
74
/*
104
/*
75
    FIND AN EXPRESSION RELATION
105
    FIND AN EXPRESSION RELATION
76
 
106
 
77
    This routine returns the lexical token number of associated with
107
    This routine returns the lexical token number of associated with
78
    the test ntst.  The default value returned is lex.
108
    the test ntst.  The default value returned is lex.
79
*/
109
*/
80
 
110
 
81
int ntest_token
111
int
82
    PROTO_N ( ( ntst, lex ) )
-
 
83
    PROTO_T ( NTEST ntst X int lex )
112
ntest_token(NTEST ntst, int lex)
84
{
113
{
85
    switch ( ntst ) {
114
	switch (ntst) {
-
 
115
	case ntest_eq:
-
 
116
		lex = lex_eq;
-
 
117
		break;
86
	case ntest_eq : lex = lex_eq ; break ;
118
	case ntest_not_eq:
87
	case ntest_not_eq : lex = lex_not_Heq_H1 ; break ;
119
		lex = lex_not_Heq_H1;
-
 
120
		break;
-
 
121
	case ntest_less:
-
 
122
		lex = lex_less;
-
 
123
		break;
88
	case ntest_less : lex = lex_less ; break ;
124
	case ntest_less_eq:
89
	case ntest_less_eq : lex = lex_less_Heq ; break ;
125
		lex = lex_less_Heq;
-
 
126
		break;
-
 
127
	case ntest_greater:
-
 
128
		lex = lex_greater;
-
 
129
		break;
90
	case ntest_greater : lex = lex_greater ; break ;
130
	case ntest_greater_eq:
91
	case ntest_greater_eq : lex = lex_greater_Heq ; break ;
131
		lex = lex_greater_Heq;
-
 
132
		break;
92
    }
133
	}
93
    return ( lex ) ;
134
	return (lex);
94
}
135
}
95
 
136
 
96
 
137
 
97
/*
138
/*
98
    FIND THE TOKEN NUMBER FOR AN OPERATION
139
    FIND THE TOKEN NUMBER FOR AN OPERATION
99
 
140
 
100
    This routine returns the lexical token number associated with the
141
    This routine returns the lexical token number associated with the
101
    expression e.  The default value returned is lex.
142
    expression e.  The default value returned is lex.
102
*/
143
*/
103
 
144
 
104
int op_token
145
int
105
    PROTO_N ( ( e, lex ) )
-
 
106
    PROTO_T ( EXP e X int lex )
146
op_token(EXP e, int lex)
107
{
147
{
108
    if ( !IS_NULL_exp ( e ) ) {
148
	if (!IS_NULL_exp(e)) {
109
	switch ( TAG_exp ( e ) ) {
149
		switch (TAG_exp(e)) {
110
	    case exp_negate_tag : lex = lex_minus ; break ;
150
		case exp_negate_tag:
-
 
151
			lex = lex_minus;
-
 
152
			break;
-
 
153
		case exp_compl_tag:
111
	    case exp_compl_tag : lex = lex_compl_H1 ; break ;
154
			lex = lex_compl_H1;
-
 
155
			break;
-
 
156
		case exp_not_tag:
112
	    case exp_not_tag : lex = lex_not_H1 ; break ;
157
			lex = lex_not_H1;
-
 
158
			break;
113
	    case exp_abs_tag : lex = lex_abs ; break ;
159
		case exp_abs_tag:
-
 
160
			lex = lex_abs;
-
 
161
			break;
114
	    case exp_plus_tag : lex = lex_plus ; break ;
162
		case exp_plus_tag:
-
 
163
			lex = lex_plus;
-
 
164
			break;
115
	    case exp_minus_tag : lex = lex_minus ; break ;
165
		case exp_minus_tag:
-
 
166
			lex = lex_minus;
-
 
167
			break;
116
	    case exp_mult_tag : lex = lex_star ; break ;
168
		case exp_mult_tag:
-
 
169
			lex = lex_star;
-
 
170
			break;
117
	    case exp_div_tag : lex = lex_div ; break ;
171
		case exp_div_tag:
-
 
172
			lex = lex_div;
-
 
173
			break;
118
	    case exp_rem_tag : lex = lex_rem ; break ;
174
		case exp_rem_tag:
-
 
175
			lex = lex_rem;
-
 
176
			break;
-
 
177
		case exp_and_tag:
119
	    case exp_and_tag : lex = lex_and_H1 ; break ;
178
			lex = lex_and_H1;
-
 
179
			break;
-
 
180
		case exp_or_tag:
120
	    case exp_or_tag : lex = lex_or_H1 ; break ;
181
			lex = lex_or_H1;
-
 
182
			break;
-
 
183
		case exp_xor_tag:
121
	    case exp_xor_tag : lex = lex_xor_H1 ; break ;
184
			lex = lex_xor_H1;
-
 
185
			break;
-
 
186
		case exp_log_and_tag:
122
	    case exp_log_and_tag : lex = lex_logical_Hand_H1 ; break ;
187
			lex = lex_logical_Hand_H1;
-
 
188
			break;
-
 
189
		case exp_log_or_tag:
123
	    case exp_log_or_tag : lex = lex_logical_Hor_H1 ; break ;
190
			lex = lex_logical_Hor_H1;
-
 
191
			break;
124
	    case exp_lshift_tag : lex = lex_lshift ; break ;
192
		case exp_lshift_tag:
-
 
193
			lex = lex_lshift;
-
 
194
			break;
125
	    case exp_rshift_tag : lex = lex_rshift ; break ;
195
		case exp_rshift_tag:
-
 
196
			lex = lex_rshift;
-
 
197
			break;
126
	    case exp_max_tag : lex = lex_max ; break ;
198
		case exp_max_tag:
-
 
199
			lex = lex_max;
-
 
200
			break;
127
	    case exp_min_tag : lex = lex_min ; break ;
201
		case exp_min_tag:
-
 
202
			lex = lex_min;
-
 
203
			break;
128
	    case exp_test_tag : {
204
		case exp_test_tag: {
129
		NTEST ntst = DEREF_ntest ( exp_test_tst ( e ) ) ;
205
			NTEST ntst = DEREF_ntest(exp_test_tst(e));
130
		lex = ntest_token ( ntst, lex ) ;
206
			lex = ntest_token(ntst, lex);
131
		break ;
207
			break;
132
	    }
208
		}
133
	    case exp_compare_tag : {
209
		case exp_compare_tag: {
134
		NTEST ntst = DEREF_ntest ( exp_compare_tst ( e ) ) ;
210
			NTEST ntst = DEREF_ntest(exp_compare_tst(e));
135
		lex = ntest_token ( ntst, lex ) ;
211
			lex = ntest_token(ntst, lex);
136
		break ;
212
			break;
137
	    }
213
		}
138
	    case exp_paren_tag : {
214
		case exp_paren_tag: {
139
		EXP a = DEREF_exp ( exp_paren_arg ( e ) ) ;
215
			EXP a = DEREF_exp(exp_paren_arg(e));
140
		lex = op_token ( a, lex ) ;
216
			lex = op_token(a, lex);
141
		break ;
217
			break;
142
	    }
218
		}
143
	    case exp_copy_tag : {
219
		case exp_copy_tag: {
144
		EXP a = DEREF_exp ( exp_copy_arg ( e ) ) ;
220
			EXP a = DEREF_exp(exp_copy_arg(e));
145
		lex = op_token ( a, lex ) ;
221
			lex = op_token(a, lex);
146
		break ;
222
			break;
147
	    }
223
		}
148
	}
224
		}
149
    }
225
	}
150
    return ( lex ) ;
226
	return (lex);
151
}
227
}
152
 
228
 
153
 
229
 
154
/*
230
/*
155
    APPLY A UNARY OPERATOR
231
    APPLY A UNARY OPERATOR
156
 
232
 
157
    This routine applies the unary operator op to the argument a.  The
233
    This routine applies the unary operator op to the argument a.  The
365
 
424
 
366
 
425
 
367
/*
426
/*
368
    APPLY A BINARY OPERATOR
427
    APPLY A BINARY OPERATOR
369
 
428
 
370
    This routine applies the binary operator op to the arguments a and b.
429
    This routine applies the binary operator op to the arguments a and b.
502
#if LANGUAGE_CPP
542
#if LANGUAGE_CPP
503
	case lex_arrow_Hstar :
543
	case lex_arrow_Hstar:
504
	case lex_dot_Hstar : {
544
	case lex_dot_Hstar:
505
	    /* Construct 'a->*b' and 'a.*b' */
545
		/* Construct 'a->*b' and 'a.*b' */
506
	    e = make_member_exp ( op, a, b ) ;
546
		e = make_member_exp(op, a, b);
507
	    break ;
547
		break;
508
	}
-
 
509
#endif
548
#endif
510
	default : {
549
	default:
511
	    /* Illegal operations */
550
		/* Illegal operations */
512
	    FAIL ( Unexpected binary operation ) ;
551
		FAIL(Unexpected binary operation);
513
	    e = make_error_exp ( 0 ) ;
552
		e = make_error_exp(0);
514
	    break ;
553
		break;
515
	}
554
	}
516
    }
-
 
517
    suppress_quality-- ;
555
	suppress_quality--;
518
    return ( e ) ;
556
	return (e);
519
}
557
}
520
 
558
 
521
 
559
 
522
/*
560
/*
523
    APPLY AN N-ARY OPERATOR
561
    APPLY AN N-ARY OPERATOR
524
 
562
 
525
    This routine applies the n-ary operator op to the arguments p.  The
563
    This routine applies the n-ary operator op to the arguments p.  The
526
    type t2 gives the destination for any cast operator.
564
    type t2 gives the destination for any cast operator.
527
*/
565
*/
528
 
566
 
529
EXP apply_nary
567
EXP
530
    PROTO_N ( ( op, p, t1, t2, cpy ) )
-
 
531
    PROTO_T ( int op X LIST ( EXP ) p X TYPE t1 X TYPE t2 X int cpy )
568
apply_nary(int op, LIST(EXP)p, TYPE t1, TYPE t2, int cpy)
532
{
569
{
533
    EXP e ;
570
	EXP e;
534
    suppress_quality++ ;
571
	suppress_quality++;
535
    switch ( op ) {
572
	switch (op) {
536
	case lex_comma : {
573
	case lex_comma: {
537
	    /* Construct 'p0, p1, ..., pn' */
574
		/* Construct 'p0, p1, ..., pn' */
-
 
575
		if (cpy) {
538
	    if ( cpy ) p = copy_exp_list ( p, t1, t2 ) ;
576
			p = copy_exp_list(p, t1, t2);
-
 
577
		}
539
	    e = make_comma_exp ( p ) ;
578
		e = make_comma_exp(p);
540
	    break ;
579
		break;
541
	}
580
	}
542
	case lex_cond_Hop : {
581
	case lex_cond_Hop: {
543
	    /* Construct 'p0 ? p1 : p2' */
582
		/* Construct 'p0 ? p1 : p2' */
544
	    EXP c, a, b ;
583
		EXP c, a, b;
545
	    c = DEREF_exp ( HEAD_list ( p ) ) ;
584
		c = DEREF_exp(HEAD_list(p));
546
	    p = TAIL_list ( p ) ;
585
		p = TAIL_list(p);
547
	    a = DEREF_exp ( HEAD_list ( p ) ) ;
586
		a = DEREF_exp(HEAD_list(p));
548
	    p = TAIL_list ( p ) ;
587
		p = TAIL_list(p);
549
	    b = DEREF_exp ( HEAD_list ( p ) ) ;
588
		b = DEREF_exp(HEAD_list(p));
550
	    if ( cpy ) {
589
		if (cpy) {
551
		c = copy_exp ( c, type_bool, type_bool ) ;
590
			c = copy_exp(c, type_bool, type_bool);
552
		a = copy_exp ( a, t1, t2 ) ;
591
			a = copy_exp(a, t1, t2);
553
		b = copy_exp ( b, t1, t2 ) ;
592
			b = copy_exp(b, t1, t2);
554
	    }
593
		}
555
	    e = make_cond_exp ( c, a, b ) ;
594
		e = make_cond_exp(c, a, b);
556
	    break ;
595
		break;
557
	}
596
	}
558
	case lex_func_Hop : {
597
	case lex_func_Hop: {
559
	    /* Construct 'p0 ( p1, ..., pn )' */
598
		/* Construct 'p0 ( p1, ..., pn )' */
560
	    EXP a = DEREF_exp ( HEAD_list ( p ) ) ;
599
		EXP a = DEREF_exp(HEAD_list(p));
561
	    p = TAIL_list ( p ) ;
600
		p = TAIL_list(p);
562
	    if ( cpy ) {
601
		if (cpy) {
563
		a = copy_func_exp ( a, t1, t2 ) ;
602
			a = copy_func_exp(a, t1, t2);
564
		p = copy_exp_list ( p, t1, t2 ) ;
603
			p = copy_exp_list(p, t1, t2);
565
	    }
-
 
566
	    e = make_func_exp ( a, p, 1 ) ;
-
 
567
	    break ;
-
 
568
	}
604
		}
569
	case lex_cast : {
-
 
570
	    /* Construct 't2 ( p0, ..., pn )' */
-
 
571
	    if ( cpy ) p = copy_exp_list ( p, t1, t2 ) ;
-
 
572
	    e = make_func_cast_exp ( t2, p ) ;
605
		e = make_func_exp(a, p, 1);
573
	    break ;
606
		break;
574
	}
607
	}
-
 
608
	case lex_cast:
-
 
609
		/* Construct 't2 ( p0, ..., pn )' */
-
 
610
		if (cpy) {
-
 
611
			p = copy_exp_list(p, t1, t2);
-
 
612
		}
-
 
613
		e = make_func_cast_exp(t2, p);
-
 
614
		break;
575
	case lex_static_Hcast : {
615
	case lex_static_Hcast: {
576
	    /* Construct 't2 ( p0, ..., pn )' */
616
		/* Construct 't2 ( p0, ..., pn )' */
577
	    ERROR err = NULL_err ;
617
		ERROR err = NULL_err;
-
 
618
		if (cpy) {
578
	    if ( cpy ) p = copy_exp_list ( p, t1, t2 ) ;
619
			p = copy_exp_list(p, t1, t2);
-
 
620
		}
579
	    p = convert_args ( p ) ;
621
		p = convert_args(p);
580
	    e = convert_constr ( t2, p, &err, CAST_STATIC ) ;
622
		e = convert_constr(t2, p, &err, CAST_STATIC);
581
	    if ( !IS_NULL_err ( err ) ) report ( crt_loc, err ) ;
623
		if (!IS_NULL_err(err)) {
-
 
624
			report(crt_loc, err);
-
 
625
		}
582
	    break ;
626
		break;
583
	}
627
	}
584
#if LANGUAGE_CPP
628
#if LANGUAGE_CPP
585
	case lex_new :
629
	case lex_new:
586
	case lex_new_Hfull : {
630
	case lex_new_Hfull: {
587
	    /* Construct 'new ( p3, ..., pn ) ( t0 [ p1 ] ) ( p2 )' */
631
		/* Construct 'new ( p3, ..., pn ) ( t0 [ p1 ] ) ( p2 )' */
588
	    EXP a ;
632
		EXP a;
589
	    TYPE s ;
633
		TYPE s;
590
	    int b = 0 ;
634
		int b = 0;
591
	    if ( op == lex_new_Hfull ) b = 1 ;
635
		if (op == lex_new_Hfull) {
-
 
636
			b = 1;
-
 
637
		}
-
 
638
		if (cpy) {
592
	    if ( cpy ) p = copy_exp_list ( p, t1, t2 ) ;
639
			p = copy_exp_list(p, t1, t2);
-
 
640
		}
593
	    a = DEREF_exp ( HEAD_list ( p ) ) ;
641
		a = DEREF_exp(HEAD_list(p));
594
	    p = TAIL_list ( p ) ;
642
		p = TAIL_list(p);
595
	    s = DEREF_type ( exp_type ( a ) ) ;
643
		s = DEREF_type(exp_type(a));
596
	    a = DEREF_exp ( HEAD_list ( p ) ) ;
644
		a = DEREF_exp(HEAD_list(p));
597
	    p = TAIL_list ( p ) ;
645
		p = TAIL_list(p);
598
	    if ( !IS_NULL_exp ( a ) ) {
646
		if (!IS_NULL_exp(a)) {
599
		/* Array dimension */
647
			/* Array dimension */
600
		NAT n ;
648
			NAT n;
601
		MAKE_nat_calc ( a, n ) ;
649
			MAKE_nat_calc(a, n);
602
		MAKE_type_array ( cv_none, s, n, s ) ;
650
			MAKE_type_array(cv_none, s, n, s);
603
	    }
651
		}
604
	    a = DEREF_exp ( HEAD_list ( p ) ) ;
652
		a = DEREF_exp(HEAD_list(p));
605
	    p = TAIL_list ( p ) ;
653
		p = TAIL_list(p);
606
	    e = make_new_exp ( s, 0, b, p, a ) ;
654
		e = make_new_exp(s, 0, b, p, a);
607
	    break ;
-
 
608
	}
-
 
609
	case lex_compute : {
-
 
610
	    /* Construct new-initialiser, '( p0, ..., pn )' */
-
 
611
	    if ( cpy ) p = copy_exp_list ( p, t1, t2 ) ;
-
 
612
	    e = make_new_init ( t2, p, 1 ) ;
-
 
613
	    break ;
655
		break;
614
	}
656
	}
-
 
657
	case lex_compute:
-
 
658
		/* Construct new-initialiser, '( p0, ..., pn )' */
-
 
659
		if (cpy) {
-
 
660
			p = copy_exp_list(p, t1, t2);
-
 
661
		}
-
 
662
		e = make_new_init(t2, p, 1);
-
 
663
		break;
615
#endif
664
#endif
616
	default : {
665
	default:
617
	    /* Illegal operations */
666
		/* Illegal operations */
618
	    FAIL ( Unexpected nary operation ) ;
667
		FAIL(Unexpected nary operation);
619
	    e = make_error_exp ( 0 ) ;
668
		e = make_error_exp(0);
620
	    break ;
669
		break;
621
	}
670
	}
622
    }
-
 
623
    suppress_quality-- ;
671
	suppress_quality--;
624
    return ( e ) ;
672
	return (e);
625
}
673
}
626
 
674
 
627
 
675
 
628
/*
676
/*
629
    CONVERT AN OPERAND TO A BUILT-IN OPERATOR
677
    CONVERT AN OPERAND TO A BUILT-IN OPERATOR
630
 
678
 
631
    This routine converts the nth operand a to the built-in operator op
679
    This routine converts the nth operand a to the built-in operator op
632
    to type t.
680
    to type t.
633
*/
681
*/
634
 
682
 
635
static EXP convert_builtin
683
static EXP
636
    PROTO_N ( ( t, a, op, n ) )
-
 
637
    PROTO_T ( TYPE t X EXP a X int op X unsigned n )
684
convert_builtin(TYPE t, EXP a, int op, unsigned n)
638
{
685
{
639
    ERROR err = NULL_err ;
686
	ERROR err = NULL_err;
640
    if ( IS_type_compound ( t ) ) {
687
	if (IS_type_compound(t)) {
641
	a = convert_class ( t, a, &err ) ;
688
		a = convert_class(t, a, &err);
642
    } else {
689
	} else {
643
	a = init_assign ( t, cv_none, a, &err ) ;
690
		a = init_assign(t, cv_none, a, &err);
644
    }
691
	}
645
    if ( !IS_NULL_err ( err ) ) {
692
	if (!IS_NULL_err(err)) {
646
	err = init_error ( err, 0 ) ;
693
		err = init_error(err, 0);
647
	err = concat_error ( err, ERR_expr_convert_op ( n, op ) ) ;
694
		err = concat_error(err, ERR_expr_convert_op(n, op));
648
	report ( crt_loc, err ) ;
695
		report(crt_loc, err);
649
    }
696
	}
650
    return ( a ) ;
697
	return (a);
651
}
698
}
652
 
699
 
653
 
700
 
654
/*
701
/*
655
    APPLY A BUILT-IN OPERATOR
702
    APPLY A BUILT-IN OPERATOR
656
 
703
 
657
    This routine applies the built-in operator id to the arguments args.
704
    This routine applies the built-in operator id to the arguments args.
658
*/
705
*/
659
 
706
 
660
EXP apply_builtin
707
EXP
661
    PROTO_N ( ( id, args ) )
-
 
662
    PROTO_T ( IDENTIFIER id X LIST ( EXP ) args )
708
apply_builtin(IDENTIFIER id, LIST(EXP) args)
663
{
709
{
664
    EXP e ;
710
	EXP e;
665
    TYPE t ;
711
	TYPE t;
666
    int op ;
712
	int op;
667
    EXP a, b ;
713
	EXP a, b;
668
    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
714
	HASHID nm = DEREF_hashid(id_name(id));
669
    LIST ( TYPE ) ts = DEREF_list ( id_builtin_ptypes ( id ) ) ;
715
	LIST(TYPE) ts = DEREF_list(id_builtin_ptypes(id));
-
 
716
 
-
 
717
	/* Find operator */
-
 
718
	if (IS_hashid_op(nm)) {
-
 
719
		op = DEREF_int(hashid_op_lex(nm));
-
 
720
	} else {
-
 
721
		op = lex_func_Hop;
-
 
722
	}
-
 
723
 
-
 
724
	/* Shouldn't have no arguments */
-
 
725
	if (IS_NULL_list(args)) {
-
 
726
		e = make_error_exp(0);
-
 
727
		return (e);
-
 
728
	}
670
 
729
 
671
    /* Find operator */
-
 
672
    if ( IS_hashid_op ( nm ) ) {
-
 
673
	op = DEREF_int ( hashid_op_lex ( nm ) ) ;
-
 
674
    } else {
-
 
675
	op = lex_func_Hop ;
-
 
676
    }
-
 
677
 
-
 
678
    /* Shouldn't have no arguments */
-
 
679
    if ( IS_NULL_list ( args ) ) {
-
 
680
	e = make_error_exp ( 0 ) ;
-
 
681
	return ( e ) ;
-
 
682
    }
-
 
683
 
-
 
684
    /* Convert first argument */
730
	/* Convert first argument */
685
    DESTROY_CONS_exp ( destroy, a, args, args ) ;
731
	DESTROY_CONS_exp(destroy, a, args, args);
686
    t = DEREF_type ( HEAD_list ( ts ) ) ;
732
	t = DEREF_type(HEAD_list(ts));
687
    a = convert_builtin ( t, a, op, ( unsigned ) 1 ) ;
733
	a = convert_builtin(t, a, op,(unsigned)1);
688
 
-
 
689
    /* Allow for 'operator ()' */
-
 
690
    if ( op == lex_func_Hop ) {
-
 
691
	overload_depth++ ;
-
 
692
	e = make_func_exp ( a, args, 0 ) ;
-
 
693
	overload_depth-- ;
-
 
694
	return ( e ) ;
-
 
695
    }
-
 
696
 
734
 
697
    /* Allow for unary operators */
735
	/* Allow for 'operator ()' */
698
    if ( IS_NULL_list ( args ) ) {
736
	if (op == lex_func_Hop) {
699
	overload_depth++ ;
737
		overload_depth++;
700
	e = apply_unary ( op, a, NULL_type, NULL_type, 0 ) ;
738
		e = make_func_exp(a, args, 0);
701
	overload_depth-- ;
739
		overload_depth--;
702
	return ( e ) ;
740
		return (e);
703
    }
741
	}
704
 
742
 
705
    /* Convert second argument */
743
	/* Allow for unary operators */
706
    DESTROY_CONS_exp ( destroy, b, args, args ) ;
744
	if (IS_NULL_list(args)) {
-
 
745
		overload_depth++;
707
    t = DEREF_type ( HEAD_list ( TAIL_list ( ts ) ) ) ;
746
		e = apply_unary(op, a, NULL_type, NULL_type, 0);
708
    b = convert_builtin ( t, b, op, ( unsigned ) 1 ) ;
747
		overload_depth--;
-
 
748
		return (e);
-
 
749
	}
709
 
750
 
-
 
751
	/* Convert second argument */
-
 
752
	DESTROY_CONS_exp(destroy, b, args, args);
-
 
753
	t = DEREF_type(HEAD_list(TAIL_list(ts)));
-
 
754
	b = convert_builtin(t, b, op,(unsigned)1);
-
 
755
 
710
    /* Allow for binary operators */
756
	/* Allow for binary operators */
711
    if ( IS_NULL_list ( args ) ) {
757
	if (IS_NULL_list(args)) {
712
	overload_depth++ ;
758
		overload_depth++;
713
	e = apply_binary ( op, a, b, NULL_type, NULL_type, 0 ) ;
759
		e = apply_binary(op, a, b, NULL_type, NULL_type, 0);
714
	overload_depth-- ;
760
		overload_depth--;
715
	return ( e ) ;
761
		return (e);
716
    }
762
	}
717
 
763
 
718
    /* Shouldn't have more than two arguments */
764
	/* Shouldn't have more than two arguments */
719
    DESTROY_list ( args, SIZE_exp ) ;
765
	DESTROY_list(args, SIZE_exp);
720
    e = make_error_exp ( 0 ) ;
766
	e = make_error_exp(0);
721
    return ( e ) ;
767
	return (e);
722
}
768
}
723
 
769
 
724
 
770
 
725
/*
771
/*
726
    OVERLOAD DEPTH FLAG
772
    OVERLOAD DEPTH FLAG
727
 
773
 
728
    This flag is used to keep track of the depth of overloaded operator
774
    This flag is used to keep track of the depth of overloaded operator
729
    resolutions.
775
    resolutions.
730
*/
776
*/
731
 
777
 
732
int overload_depth = 0 ;
778
int overload_depth = 0;
733
int overload_warn = 1 ;
779
int overload_warn = 1;
734
 
780
 
735
 
781
 
736
/*
782
/*
737
    OPERATOR OVERLOADING ROUTINES
783
    OPERATOR OVERLOADING ROUTINES
738
 
784
 
Line 753... Line 799...
753
    only covers genuine overloading operators such as 'operator +', the
799
    only covers genuine overloading operators such as 'operator +', the
754
    allocation operators such as 'operator new' are handled by the routine
800
    allocation operators such as 'operator new' are handled by the routine
755
    check_allocator and alloc is set accordingly.
801
    check_allocator and alloc is set accordingly.
756
*/
802
*/
757
 
803
 
758
TYPE check_operator
804
TYPE
759
    PROTO_N ( ( t, id, mem, alloc ) )
-
 
760
    PROTO_T ( TYPE t X IDENTIFIER id X int mem X int *alloc )
805
check_operator(TYPE t, IDENTIFIER id, int mem, int *alloc)
761
{
806
{
762
    int op ;
807
	int op;
763
    int ell ;
808
	int ell;
764
    HASHID nm ;
809
	HASHID nm;
765
    int dargs = 0 ;
810
	int dargs = 0;
766
    unsigned n, m ;
811
	unsigned n, m;
767
    unsigned npars ;
812
	unsigned npars;
768
    LIST ( TYPE ) ptypes ;
813
	LIST(TYPE) ptypes;
769
 
814
 
770
    /* Allow for template types */
815
	/* Allow for template types */
771
    if ( IS_type_templ ( t ) ) {
816
	if (IS_type_templ(t)) {
772
	TYPE s = DEREF_type ( type_templ_defn ( t ) ) ;
817
		TYPE s = DEREF_type(type_templ_defn(t));
773
	s = check_operator ( s, id, mem, alloc ) ;
818
		s = check_operator(s, id, mem, alloc);
774
	COPY_type ( type_templ_defn ( t ), s ) ;
819
		COPY_type(type_templ_defn(t), s);
775
	return ( t ) ;
820
		return (t);
776
    }
821
	}
777
 
822
 
778
    /* Find the operator */
823
	/* Find the operator */
779
    nm = DEREF_hashid ( id_name ( id ) ) ;
824
	nm = DEREF_hashid(id_name(id));
780
    op = DEREF_int ( hashid_op_lex ( nm ) ) ;
825
	op = DEREF_int(hashid_op_lex(nm));
781
    switch ( op ) {
826
	switch (op) {
782
	case lex_new :
827
	case lex_new:
783
	case lex_new_Harray : {
828
	case lex_new_Harray:
784
	    /* Check for allocation operators */
829
		/* Check for allocation operators */
785
	    *alloc = 1 ;
830
		*alloc = 1;
786
	    t = check_allocator ( t, id, mem, 0 ) ;
831
		t = check_allocator(t, id, mem, 0);
787
	    return ( t ) ;
832
		return (t);
788
	}
-
 
789
	case lex_delete :
833
	case lex_delete:
790
	case lex_delete_Harray : {
834
	case lex_delete_Harray:
791
	    /* Check for deallocation operators */
835
		/* Check for deallocation operators */
792
	    *alloc = 2 ;
836
		*alloc = 2;
793
	    t = check_allocator ( t, id, mem, 0 ) ;
837
		t = check_allocator(t, id, mem, 0);
794
	    return ( t ) ;
838
		return (t);
795
	}
-
 
796
	default : {
839
	default:
797
	    *alloc = 0 ;
840
		*alloc = 0;
798
	    break ;
841
		break;
799
	}
842
	}
800
    }
-
 
801
 
843
 
802
    /* Decompose function type */
844
	/* Decompose function type */
803
    ptypes = DEREF_list ( type_func_ptypes ( t ) ) ;
845
	ptypes = DEREF_list(type_func_ptypes(t));
804
    npars = LENGTH_list ( ptypes ) ;
846
	npars = LENGTH_list(ptypes);
805
    ell = DEREF_int ( type_func_ellipsis ( t ) ) ;
847
	ell = DEREF_int(type_func_ellipsis(t));
806
    if ( ell ) {
848
	if (ell) {
807
	/* Set number of parameters to dummy large value */
849
		/* Set number of parameters to dummy large value */
808
	npars = 10000 ;
850
		npars = 10000;
809
    }
851
	}
810
 
852
 
811
    /* Check function arguments */
853
	/* Check function arguments */
812
    if ( mem ) {
854
	if (mem) {
813
	/* Member functions have implicit extra parameter */
855
		/* Member functions have implicit extra parameter */
814
	npars++ ;
856
		npars++;
815
	n = 0 ;
857
		n = 0;
816
	m = 1 ;
858
		m = 1;
817
    } else {
859
	} else {
818
	/* Should have an overloadable parameter */
860
		/* Should have an overloadable parameter */
819
	LIST ( TYPE ) p = ptypes ;
861
		LIST(TYPE) p = ptypes;
820
	while ( !IS_NULL_list ( p ) ) {
862
		while (!IS_NULL_list(p)) {
821
	    TYPE a = DEREF_type ( HEAD_list ( p ) ) ;
863
			TYPE a = DEREF_type(HEAD_list(p));
822
	    unsigned ca = type_category ( &a ) ;
864
			unsigned ca = type_category(&a);
823
	    if ( IS_TYPE_OVERLOAD ( ca ) ) break ;
865
			if (IS_TYPE_OVERLOAD(ca)) {
-
 
866
				break;
-
 
867
			}
824
	    p = TAIL_list ( p ) ;
868
			p = TAIL_list(p);
825
	}
869
		}
826
	if ( IS_NULL_list ( p ) ) {
870
		if (IS_NULL_list(p)) {
827
	    report ( crt_loc, ERR_over_oper_type ( nm ) ) ;
871
			report(crt_loc, ERR_over_oper_type(nm));
828
	}
872
		}
829
	n = 1 ;
873
		n = 1;
830
	m = 2 ;
874
		m = 2;
831
    }
875
	}
832
 
876
 
833
    /* Check number of arguments */
877
	/* Check number of arguments */
834
    switch ( op ) {
878
	switch (op) {
835
	case lex_compl_H1 :
879
	case lex_compl_H1:
836
	case lex_not_H1 :
880
	case lex_not_H1:
837
	case lex_abs :
881
	case lex_abs:
838
	case lex_alignof :
882
	case lex_alignof:
839
	case lex_sizeof :
883
	case lex_sizeof:
840
	case lex_typeid :
884
	case lex_typeid:
841
	case lex_vtable : {
885
	case lex_vtable:
842
	    /* Unary operators */
886
		/* Unary operators */
843
	    if ( npars != 1 ) {
887
		if (npars != 1) {
844
		ERROR err = ERR_over_unary_pars ( nm, n, n ) ;
888
			ERROR err = ERR_over_unary_pars(nm, n, n);
845
		report ( crt_loc, err ) ;
889
			report(crt_loc, err);
846
	    }
890
		}
847
	    break ;
891
		break;
848
	}
-
 
849
	case lex_plus :
892
	case lex_plus:
850
	case lex_minus :
893
	case lex_minus:
851
	case lex_star :
894
	case lex_star:
852
	case lex_and_H1 : {
895
	case lex_and_H1:
853
	    /* Either unary or binary operators */
896
		/* Either unary or binary operators */
854
	    if ( npars != 1 && npars != 2 ) {
897
		if (npars != 1 && npars != 2) {
855
		ERROR err = ERR_over_binary_pars_p1 ( nm, n, m, m ) ;
898
			ERROR err = ERR_over_binary_pars_p1(nm, n, m, m);
856
		report ( crt_loc, err ) ;
899
			report(crt_loc, err);
857
	    }
900
		}
858
	    break ;
901
		break;
859
	}
-
 
860
	default : {
902
	default:
861
	    /* Binary operators */
903
		/* Binary operators */
862
	    if ( npars != 2 ) {
904
		if (npars != 2) {
863
		ERROR err = ERR_over_binary_pars_p2 ( nm, m, m ) ;
905
			ERROR err = ERR_over_binary_pars_p2(nm, m, m);
864
		report ( crt_loc, err ) ;
906
			report(crt_loc, err);
865
	    }
907
		}
866
	    break ;
908
		break;
867
	}
-
 
868
	case lex_assign : {
909
	case lex_assign:
869
	    /* Assignment */
910
		/* Assignment */
870
	    if ( !mem ) report ( crt_loc, ERR_over_ass_mem ( nm ) ) ;
-
 
871
	    if ( npars != 2 ) {
-
 
872
		ERROR err = ERR_over_ass_pars ( nm, m, m ) ;
-
 
873
		report ( crt_loc, err ) ;
-
 
874
	    }
-
 
875
	    break ;
-
 
876
	}
-
 
877
	case lex_func_Hop : {
-
 
878
	    /* Function call (can have default arguments) */
-
 
879
	    if ( !mem ) report ( crt_loc, ERR_over_call_mem ( nm ) ) ;
-
 
880
	    dargs = 1 ;
-
 
881
	    break ;
-
 
882
	}
-
 
883
	case lex_array_Hop : {
-
 
884
	    /* Subscripting */
-
 
885
	    if ( !mem ) report ( crt_loc, ERR_over_sub_mem ( nm ) ) ;
-
 
886
	    if ( npars != 2 ) {
-
 
887
		ERROR err = ERR_over_sub_pars ( nm, m, m ) ;
-
 
888
		report ( crt_loc, err ) ;
-
 
889
	    }
-
 
890
	    break ;
-
 
891
	}
-
 
892
	case lex_arrow : {
-
 
893
	    /* Class member access */
-
 
894
	    if ( !mem ) report ( crt_loc, ERR_over_ref_mem ( nm ) ) ;
-
 
895
	    if ( npars != 1 ) {
-
 
896
		ERROR err = ERR_over_ref_pars ( nm, n, n ) ;
-
 
897
		report ( crt_loc, err ) ;
-
 
898
	    }
-
 
899
	    break ;
911
		if (!mem) {
900
	}
-
 
901
	case lex_plus_Hplus :
-
 
902
	case lex_minus_Hminus : {
-
 
903
	    /* Increment and decrement */
-
 
904
	    if ( npars == 1 ) {
-
 
905
		/* One argument form is fine */
-
 
906
		/* EMPTY */
-
 
907
	    } else if ( npars == 2 ) {
-
 
908
		/* Two argument form needs checking */
-
 
909
		TYPE a ;
-
 
910
		TYPE b = type_sint ;
-
 
911
		LIST ( TYPE ) p = ptypes ;
-
 
912
		if ( !mem ) p = TAIL_list ( p ) ;
-
 
913
		a = DEREF_type ( HEAD_list ( p ) ) ;
-
 
914
		if ( !eq_type_unqual ( a, b ) && !is_templ_type ( a ) ) {
-
 
915
		    /* Second argument should be 'int' */
-
 
916
		    report ( crt_loc, ERR_over_inc_pars_p2 ( nm, b ) ) ;
912
			report(crt_loc, ERR_over_ass_mem(nm));
917
		}
913
		}
-
 
914
		if (npars != 2) {
-
 
915
			ERROR err = ERR_over_ass_pars(nm, m, m);
-
 
916
			report(crt_loc, err);
-
 
917
		}
-
 
918
		break;
-
 
919
	case lex_func_Hop:
-
 
920
		/* Function call (can have default arguments) */
918
	    } else {
921
		if (!mem) {
-
 
922
			report(crt_loc, ERR_over_call_mem(nm));
-
 
923
		}
-
 
924
		dargs = 1;
-
 
925
		break;
-
 
926
	case lex_array_Hop:
-
 
927
		/* Subscripting */
-
 
928
		if (!mem) {
-
 
929
			report(crt_loc, ERR_over_sub_mem(nm));
-
 
930
		}
-
 
931
		if (npars != 2) {
-
 
932
			ERROR err = ERR_over_sub_pars(nm, m, m);
-
 
933
			report(crt_loc, err);
-
 
934
		}
-
 
935
		break;
-
 
936
	case lex_arrow:
919
		/* Anything else is illegal */
937
		/* Class member access */
-
 
938
		if (!mem) {
-
 
939
			report(crt_loc, ERR_over_ref_mem(nm));
-
 
940
		}
-
 
941
		if (npars != 1) {
920
		ERROR err = ERR_over_inc_pars ( nm, n, m, m ) ;
942
			ERROR err = ERR_over_ref_pars(nm, n, n);
921
		report ( crt_loc, err ) ;
943
			report(crt_loc, err);
922
	    }
944
		}
923
	    break ;
945
		break;
-
 
946
	case lex_plus_Hplus:
-
 
947
	case lex_minus_Hminus:
-
 
948
		/* Increment and decrement */
-
 
949
		if (npars == 1) {
-
 
950
			/* One argument form is fine */
-
 
951
			/* EMPTY */
-
 
952
		} else if (npars == 2) {
-
 
953
			/* Two argument form needs checking */
-
 
954
			TYPE a;
-
 
955
			TYPE b = type_sint;
-
 
956
			LIST(TYPE) p = ptypes;
-
 
957
			if (!mem) {
-
 
958
				p = TAIL_list(p);
-
 
959
			}
-
 
960
			a = DEREF_type(HEAD_list(p));
-
 
961
			if (!eq_type_unqual(a, b) && !is_templ_type(a)) {
-
 
962
				/* Second argument should be 'int' */
-
 
963
				report(crt_loc, ERR_over_inc_pars_p2(nm, b));
-
 
964
			}
-
 
965
		} else {
-
 
966
			/* Anything else is illegal */
-
 
967
			ERROR err = ERR_over_inc_pars(nm, n, m, m);
-
 
968
			report(crt_loc, err);
924
	}
969
		}
-
 
970
		break;
925
	case lex_cond_Hop : {
971
	case lex_cond_Hop:
926
	    /* Tertiary operators */
972
		/* Tertiary operators */
927
	    if ( npars != 3 ) {
973
		if (npars != 3) {
928
		unsigned p = n + 2 ;
974
			unsigned p = n + 2;
929
		ERROR err = ERR_over_binary_pars_p2 ( nm, p, p ) ;
975
			ERROR err = ERR_over_binary_pars_p2(nm, p, p);
930
		report ( crt_loc, err ) ;
976
			report(crt_loc, err);
931
	    }
977
		}
932
	    break ;
978
		break;
933
	}
979
	}
934
    }
-
 
935
 
980
 
936
    /* Check for default arguments */
981
	/* Check for default arguments */
937
    if ( !dargs && check_func_dargs ( t, 0, 0 ) ) {
982
	if (!dargs && check_func_dargs(t, 0, 0)) {
938
	report ( crt_loc, ERR_over_oper_default ( nm ) ) ;
983
		report(crt_loc, ERR_over_oper_default(nm));
939
    }
984
	}
940
    return ( t ) ;
985
	return (t);
941
}
986
}
942
 
987
 
943
 
988
 
944
/*
989
/*
945
    LISTS OF BUILT-IN OPERATORS
990
    LISTS OF BUILT-IN OPERATORS
946
 
991
 
947
    These values are used in the allocation and deallocation of built-in
992
    These values are used in the allocation and deallocation of built-in
948
    operators.
993
    operators.
949
*/
994
*/
950
 
995
 
951
static IDENTIFIER unary_free = NULL_id ;
996
static IDENTIFIER unary_free = NULL_id;
952
static IDENTIFIER unary_all = NULL_id ;
997
static IDENTIFIER unary_all = NULL_id;
953
static IDENTIFIER binary_free = NULL_id ;
998
static IDENTIFIER binary_free = NULL_id;
954
static IDENTIFIER binary_all = NULL_id ;
999
static IDENTIFIER binary_all = NULL_id;
955
static IDENTIFIER nary_free = NULL_id ;
1000
static IDENTIFIER nary_free = NULL_id;
956
static IDENTIFIER nary_all = NULL_id ;
1001
static IDENTIFIER nary_all = NULL_id;
957
 
1002
 
958
 
1003
 
959
/*
1004
/*
960
    CONSTRUCT A BUILT-IN UNARY OPERATOR
1005
    CONSTRUCT A BUILT-IN UNARY OPERATOR
961
 
1006
 
962
    This routine constructs the built-in unary operator 'r nm ( a )'.
1007
    This routine constructs the built-in unary operator 'r nm ( a )'.
963
*/
1008
*/
964
 
1009
 
965
static IDENTIFIER unary_builtin
1010
static IDENTIFIER
966
    PROTO_N ( ( nm, a, r ) )
-
 
967
    PROTO_T ( HASHID nm X TYPE a X TYPE r )
1011
unary_builtin(HASHID nm, TYPE a, TYPE r)
968
{
1012
{
969
    LIST ( TYPE ) p ;
1013
	LIST(TYPE) p;
970
    IDENTIFIER id = unary_free ;
1014
	IDENTIFIER id = unary_free;
971
    if ( IS_NULL_id ( id ) ) {
1015
	if (IS_NULL_id(id)) {
972
	/* Allocate new identifier */
1016
		/* Allocate new identifier */
973
	NAMESPACE ns = NULL_nspace ;
1017
		NAMESPACE ns = NULL_nspace;
974
	CONS_type ( a, NULL_list ( TYPE ), p ) ;
1018
		CONS_type(a, NULL_list(TYPE), p);
975
	MAKE_id_builtin ( nm, dspec_none, ns, builtin_loc, r, p, id ) ;
1019
		MAKE_id_builtin(nm, dspec_none, ns, builtin_loc, r, p, id);
976
	COPY_id ( id_alias ( id ), unary_all ) ;
1020
		COPY_id(id_alias(id), unary_all);
977
	unary_all = id ;
1021
		unary_all = id;
978
    } else {
1022
	} else {
979
	/* Use existing identifier */
1023
		/* Use existing identifier */
980
	COPY_hashid ( id_name ( id ), nm ) ;
1024
		COPY_hashid(id_name(id), nm);
981
	COPY_ulong ( id_dump ( id ), LINK_NONE ) ;
1025
		COPY_ulong(id_dump(id), LINK_NONE);
982
	COPY_type ( id_builtin_ret ( id ), r ) ;
1026
		COPY_type(id_builtin_ret(id), r);
983
	p = DEREF_list ( id_builtin_ptypes ( id ) ) ;
1027
		p = DEREF_list(id_builtin_ptypes(id));
984
	COPY_type ( HEAD_list ( p ), a ) ;
1028
		COPY_type(HEAD_list(p), a);
985
	unary_free = DEREF_id ( id_alias ( id ) ) ;
1029
		unary_free = DEREF_id(id_alias(id));
986
    }
1030
	}
987
    return ( id ) ;
1031
	return (id);
988
}
1032
}
989
 
1033
 
990
 
1034
 
991
/*
1035
/*
992
    CONSTRUCT A BUILT-IN BINARY OPERATOR
1036
    CONSTRUCT A BUILT-IN BINARY OPERATOR
993
 
1037
 
994
    This routine constructs the built-in binary operator 'r nm ( a, b )'.
1038
    This routine constructs the built-in binary operator 'r nm ( a, b )'.
995
*/
1039
*/
996
 
1040
 
997
static IDENTIFIER binary_builtin
1041
static IDENTIFIER
998
    PROTO_N ( ( nm, a, b, r ) )
-
 
999
    PROTO_T ( HASHID nm X TYPE a X TYPE b X TYPE r )
1042
binary_builtin(HASHID nm, TYPE a, TYPE b, TYPE r)
1000
{
1043
{
1001
    LIST ( TYPE ) p ;
1044
	LIST(TYPE) p;
1002
    IDENTIFIER id = binary_free ;
1045
	IDENTIFIER id = binary_free;
1003
    if ( IS_NULL_id ( id ) ) {
1046
	if (IS_NULL_id(id)) {
1004
	/* Allocate new identifier */
1047
		/* Allocate new identifier */
1005
	NAMESPACE ns = NULL_nspace ;
1048
		NAMESPACE ns = NULL_nspace;
1006
	CONS_type ( b, NULL_list ( TYPE ), p ) ;
1049
		CONS_type(b, NULL_list(TYPE), p);
1007
	CONS_type ( a, p, p ) ;
1050
		CONS_type(a, p, p);
1008
	MAKE_id_builtin ( nm, dspec_none, ns, builtin_loc, r, p, id ) ;
1051
		MAKE_id_builtin(nm, dspec_none, ns, builtin_loc, r, p, id);
1009
	COPY_id ( id_alias ( id ), binary_all ) ;
1052
		COPY_id(id_alias(id), binary_all);
1010
	binary_all = id ;
1053
		binary_all = id;
1011
    } else {
1054
	} else {
1012
	/* Use existing identifier */
1055
		/* Use existing identifier */
1013
	COPY_hashid ( id_name ( id ), nm ) ;
1056
		COPY_hashid(id_name(id), nm);
1014
	COPY_ulong ( id_dump ( id ), LINK_NONE ) ;
1057
		COPY_ulong(id_dump(id), LINK_NONE);
1015
	COPY_type ( id_builtin_ret ( id ), r ) ;
1058
		COPY_type(id_builtin_ret(id), r);
1016
	p = DEREF_list ( id_builtin_ptypes ( id ) ) ;
1059
		p = DEREF_list(id_builtin_ptypes(id));
1017
	COPY_type ( HEAD_list ( p ), a ) ;
1060
		COPY_type(HEAD_list(p), a);
1018
	p = TAIL_list ( p ) ;
1061
		p = TAIL_list(p);
1019
	COPY_type ( HEAD_list ( p ), b ) ;
1062
		COPY_type(HEAD_list(p), b);
1020
	binary_free = DEREF_id ( id_alias ( id ) ) ;
1063
		binary_free = DEREF_id(id_alias(id));
1021
    }
1064
	}
1022
    return ( id ) ;
1065
	return (id);
1023
}
1066
}
1024
 
1067
 
1025
 
1068
 
1026
/*
1069
/*
1027
    CONSTRUCT A BUILT-IN N-ARY OPERATOR
1070
    CONSTRUCT A BUILT-IN N-ARY OPERATOR
1028
 
1071
 
1029
    This routine constructs the built-in n-ary operator 'r nm ( a, p )'.
1072
    This routine constructs the built-in n-ary operator 'r nm ( a, p )'.
1030
*/
1073
*/
1031
 
1074
 
1032
static IDENTIFIER nary_builtin
1075
static IDENTIFIER
1033
    PROTO_N ( ( nm, a, p, r ) )
-
 
1034
    PROTO_T ( HASHID nm X TYPE a X LIST ( TYPE ) p X TYPE r )
1076
nary_builtin(HASHID nm, TYPE a, LIST(TYPE) p, TYPE r)
1035
{
1077
{
1036
    IDENTIFIER id = nary_free ;
1078
	IDENTIFIER id = nary_free;
1037
    if ( IS_NULL_id ( id ) ) {
1079
	if (IS_NULL_id(id)) {
1038
	/* Allocate new identifier */
1080
		/* Allocate new identifier */
1039
	NAMESPACE ns = NULL_nspace ;
1081
		NAMESPACE ns = NULL_nspace;
1040
	CONS_type ( a, p, p ) ;
1082
		CONS_type(a, p, p);
1041
	MAKE_id_builtin ( nm, dspec_none, ns, builtin_loc, r, p, id ) ;
1083
		MAKE_id_builtin(nm, dspec_none, ns, builtin_loc, r, p, id);
1042
	COPY_id ( id_alias ( id ), nary_all ) ;
1084
		COPY_id(id_alias(id), nary_all);
1043
	nary_all = id ;
1085
		nary_all = id;
1044
    } else {
1086
	} else {
1045
	/* Use existing identifier */
1087
		/* Use existing identifier */
1046
	LIST ( TYPE ) q ;
1088
		LIST(TYPE) q;
1047
	COPY_hashid ( id_name ( id ), nm ) ;
1089
		COPY_hashid(id_name(id), nm);
1048
	COPY_ulong ( id_dump ( id ), LINK_NONE ) ;
1090
		COPY_ulong(id_dump(id), LINK_NONE);
1049
	COPY_type ( id_builtin_ret ( id ), r ) ;
1091
		COPY_type(id_builtin_ret(id), r);
1050
	q = DEREF_list ( id_builtin_ptypes ( id ) ) ;
1092
		q = DEREF_list(id_builtin_ptypes(id));
1051
	COPY_type ( HEAD_list ( q ), a ) ;
1093
		COPY_type(HEAD_list(q), a);
1052
	COPY_list ( PTR_TAIL_list ( q ), p ) ;
1094
		COPY_list(PTR_TAIL_list(q), p);
1053
	nary_free = DEREF_id ( id_alias ( id ) ) ;
1095
		nary_free = DEREF_id(id_alias(id));
1054
    }
1096
	}
1055
    return ( id ) ;
1097
	return (id);
1056
}
1098
}
1057
 
1099
 
1058
 
1100
 
1059
/*
1101
/*
1060
    CONSTRUCT OVERLOADED OPERATION CANDIDATE LIST
1102
    CONSTRUCT OVERLOADED OPERATION CANDIDATE LIST
Line 1062... Line 1104...
1062
    This routine constructs the candidate list for the overloaded n-ary
1104
    This routine constructs the candidate list for the overloaded n-ary
1063
    operation op, adding the result to p.  The candidates come from the
1105
    operation op, adding the result to p.  The candidates come from the
1064
    current namespace and the type t, if this is a class.  The routine
1106
    current namespace and the type t, if this is a class.  The routine
1065
    returns the hash table entry for 'operator op'.
1107
    returns the hash table entry for 'operator op'.
1066
*/
1108
*/
1067
 
1109
 
1068
static HASHID overload_candidates
1110
static HASHID
1069
    PROTO_N ( ( p, op, t, s ) )
-
 
1070
    PROTO_T ( CANDIDATE_LIST *p X int op X TYPE t X TYPE s )
1111
overload_candidates(CANDIDATE_LIST *p, int op, TYPE t, TYPE s)
1071
{
-
 
1072
    /* Look up 'operator op' (non-standard) */
-
 
1073
    HASHID nm = lookup_op ( op ) ;
-
 
1074
    switch ( op ) {
-
 
1075
	case lex_assign :
-
 
1076
	case lex_func_Hop :
-
 
1077
	case lex_array_Hop :
-
 
1078
	case lex_arrow : {
-
 
1079
	    /* These can only be member functions */
-
 
1080
	    break ;
-
 
1081
	}
-
 
1082
	default : {
-
 
1083
	    /* These can be non-member functions */
-
 
1084
	    IDENTIFIER id = find_op_id ( nm ) ;
-
 
1085
	    if ( !IS_NULL_type ( s ) ) {
-
 
1086
		IGNORE koenig_candidates ( p, id, s, KIND_OP ) ;
-
 
1087
	    }
-
 
1088
	    IGNORE koenig_candidates ( p, id, t, KIND_OP ) ;
-
 
1089
	    if ( !IS_id_dummy ( id ) ) {
-
 
1090
		/* Function declared */
-
 
1091
		add_candidates ( p, id, 1, KIND_OP ) ;
-
 
1092
	    }
-
 
1093
	    break ;
-
 
1094
	}
-
 
1095
    }
-
 
1096
 
-
 
1097
    /* Look up 't::operator op' */
-
 
1098
    if ( IS_type_compound ( t ) ) {
-
 
1099
	CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
-
 
1100
	NAMESPACE ns = DEREF_nspace ( ctype_member ( ct ) ) ;
-
 
1101
	IDENTIFIER id = search_field ( ns, nm, 0, 0 ) ;
-
 
1102
	if ( !IS_NULL_id ( id ) ) {
-
 
1103
	    if ( IS_id_ambig ( id ) ) {
-
 
1104
		/* Ambiguous look-up */
-
 
1105
		IGNORE report_ambiguous ( id, 0, 1, 0 ) ;
-
 
1106
	    }
-
 
1107
	    add_candidates ( p, id, 1, KIND_MEM_OP ) ;
-
 
1108
	}
-
 
1109
    }
-
 
1110
    return ( nm ) ;
-
 
1111
}
-
 
1112
 
-
 
1113
 
-
 
1114
/*
-
 
1115
    CONSTRUCT LIST OF INTEGRAL TYPES
-
 
1116
 
-
 
1117
    This routine adds all the promoted integral types to the list res.
-
 
1118
*/
-
 
1119
 
-
 
1120
static LIST ( TYPE ) add_int_types
-
 
1121
    PROTO_N ( ( res ) )
-
 
1122
    PROTO_T ( LIST ( TYPE ) res )
-
 
1123
{
1112
{
1124
    if ( basetype_info [ ntype_sllong ].key ) {
1113
	/* Look up 'operator op' (non-standard) */
-
 
1114
	HASHID nm = lookup_op(op);
-
 
1115
	switch (op) {
-
 
1116
	case lex_assign:
-
 
1117
	case lex_func_Hop:
-
 
1118
	case lex_array_Hop:
-
 
1119
	case lex_arrow:
1125
	res = cons_type_set ( res, type_ullong ) ;
1120
		/* These can only be member functions */
-
 
1121
		break;
-
 
1122
	default: {
1126
	res = cons_type_set ( res, type_sllong ) ;
1123
		/* These can be non-member functions */
-
 
1124
		IDENTIFIER id = find_op_id(nm);
-
 
1125
		if (!IS_NULL_type(s)) {
-
 
1126
			IGNORE koenig_candidates(p, id, s, KIND_OP);
1127
    }
1127
		}
1128
    res = cons_type_set ( res, type_ulong ) ;
1128
		IGNORE koenig_candidates(p, id, t, KIND_OP);
-
 
1129
		if (!IS_id_dummy(id)) {
-
 
1130
			/* Function declared */
-
 
1131
			add_candidates(p, id, 1, KIND_OP);
-
 
1132
		}
-
 
1133
		break;
-
 
1134
	}
-
 
1135
	}
-
 
1136
 
-
 
1137
	/* Look up 't::operator op' */
-
 
1138
	if (IS_type_compound(t)) {
1129
    res = cons_type_set ( res, type_slong ) ;
1139
		CLASS_TYPE ct = DEREF_ctype(type_compound_defn(t));
1130
    res = cons_type_set ( res, type_uint ) ;
1140
		NAMESPACE ns = DEREF_nspace(ctype_member(ct));
-
 
1141
		IDENTIFIER id = search_field(ns, nm, 0, 0);
-
 
1142
		if (!IS_NULL_id(id)) {
-
 
1143
			if (IS_id_ambig(id)) {
-
 
1144
				/* Ambiguous look-up */
-
 
1145
				IGNORE report_ambiguous(id, 0, 1, 0);
-
 
1146
			}
1131
    res = cons_type_set ( res, type_sint ) ;
1147
			add_candidates(p, id, 1, KIND_MEM_OP);
-
 
1148
		}
-
 
1149
	}
1132
    return ( res ) ;
1150
	return (nm);
1133
}
1151
}
1134
 
1152
 
1135
 
1153
 
1136
/*
1154
/*
-
 
1155
    CONSTRUCT LIST OF INTEGRAL TYPES
-
 
1156
 
-
 
1157
    This routine adds all the promoted integral types to the list res.
-
 
1158
*/
-
 
1159
 
-
 
1160
static LIST(TYPE)
-
 
1161
add_int_types(LIST(TYPE) res)
-
 
1162
{
-
 
1163
	if (basetype_info[ntype_sllong].key) {
-
 
1164
		res = cons_type_set(res, type_ullong);
-
 
1165
		res = cons_type_set(res, type_sllong);
-
 
1166
	}
-
 
1167
	res = cons_type_set(res, type_ulong);
-
 
1168
	res = cons_type_set(res, type_slong);
-
 
1169
	res = cons_type_set(res, type_uint);
-
 
1170
	res = cons_type_set(res, type_sint);
-
 
1171
	return (res);
-
 
1172
}
-
 
1173
 
-
 
1174
 
-
 
1175
/*
1137
    CONSTRUCT LIST OF FLOATING POINT TYPES
1176
    CONSTRUCT LIST OF FLOATING POINT TYPES
1138
 
1177
 
1139
    This routine adds all the floating point types to the list res.
1178
    This routine adds all the floating point types to the list res.
1140
*/
1179
*/
1141
 
1180
 
1142
static LIST ( TYPE ) add_float_types
1181
static LIST(TYPE)
1143
    PROTO_N ( ( res ) )
-
 
1144
    PROTO_T ( LIST ( TYPE ) res )
1182
add_float_types(LIST(TYPE) res)
1145
{
1183
{
1146
    res = cons_type_set ( res, type_ldouble ) ;
1184
	res = cons_type_set(res, type_ldouble);
1147
    res = cons_type_set ( res, type_double ) ;
1185
	res = cons_type_set(res, type_double);
1148
    res = cons_type_set ( res, type_float ) ;
1186
	res = cons_type_set(res, type_float);
1149
    return ( res ) ;
1187
	return (res);
1150
}
1188
}
1151
 
1189
 
1152
 
1190
 
1153
/*
1191
/*
1154
    CONSTRUCT A LIST OF CONVERSION TYPES
1192
    CONSTRUCT A LIST OF CONVERSION TYPES
1155
 
1193
 
1156
    This routine constructs a list of types consisting of all the types
1194
    This routine constructs a list of types consisting of all the types
1157
    of a certain kind to which the type t can be converted.  Conversions
1195
    of a certain kind to which the type t can be converted.  Conversions
Line 1159... Line 1197...
1159
    is indicated by the CTYPE macros defined in chktype.h, except that
1197
    is indicated by the CTYPE macros defined in chktype.h, except that
1160
    CTYPE_INTEGER refers to promoted integer types unless qualified using
1198
    CTYPE_INTEGER refers to promoted integer types unless qualified using
1161
    CTYPE_LVALUE.
1199
    CTYPE_LVALUE.
1162
*/
1200
*/
1163
 
1201
 
1164
static LIST ( TYPE ) find_type_convs
1202
static LIST(TYPE)
1165
    PROTO_N ( ( t, a, kind ) )
-
 
1166
    PROTO_T ( TYPE t X EXP a X unsigned kind )
1203
find_type_convs(TYPE t, EXP a, unsigned kind)
1167
{
1204
{
1168
    LIST ( TYPE ) res = NULL_list ( TYPE ) ;
1205
	LIST(TYPE) res = NULL_list(TYPE);
1169
    unsigned nt = TAG_type ( t ) ;
1206
	unsigned nt = TAG_type(t);
1170
    switch ( nt ) {
1207
	switch (nt) {
1171
	case type_compound_tag : {
1208
	case type_compound_tag: {
1172
	    /* Class types */
1209
		/* Class types */
1173
	    LIST ( IDENTIFIER ) conv ;
1210
		LIST(IDENTIFIER) conv;
1174
	    CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
1211
		CLASS_TYPE ct = DEREF_ctype(type_compound_defn(t));
1175
	    complete_class ( ct, 1 ) ;
1212
		complete_class(ct, 1);
1176
	    conv = DEREF_list ( ctype_conv ( ct ) ) ;
1213
		conv = DEREF_list(ctype_conv(ct));
1177
	    for ( ; !IS_NULL_list ( conv ) ; conv = TAIL_list ( conv ) ) {
1214
		for (; !IS_NULL_list(conv); conv = TAIL_list(conv)) {
1178
		/* Scan through conversion operations */
1215
			/* Scan through conversion operations */
1179
		TYPE r ;
1216
			TYPE r;
1180
		HASHID nm ;
1217
			HASHID nm;
1181
		unsigned nr ;
1218
			unsigned nr;
1182
		IDENTIFIER id = DEREF_id ( HEAD_list ( conv ) ) ;
1219
			IDENTIFIER id = DEREF_id(HEAD_list(conv));
1183
		DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
1220
			DECL_SPEC ds = DEREF_dspec(id_storage(id));
1184
		if ( ds & dspec_explicit ) continue ;
1221
			if (ds & dspec_explicit) {
-
 
1222
				continue;
-
 
1223
			}
-
 
1224
 
-
 
1225
			/* Check for reference types */
-
 
1226
			nm = DEREF_hashid(id_name(id));
-
 
1227
			r = DEREF_type(hashid_conv_type(nm));
-
 
1228
			if (kind == CTYPE_NONE) {
-
 
1229
				/* Include all types in this case */
-
 
1230
				res = cons_type_set(res, r);
-
 
1231
				continue;
-
 
1232
			}
-
 
1233
			nr = TAG_type(r);
-
 
1234
			if (nr == type_ref_tag) {
-
 
1235
				/* Allow for reference bindings */
-
 
1236
				if (IS_TYPE_LVALUE(kind)) {
-
 
1237
					TYPE s = DEREF_type(type_ref_sub(r));
-
 
1238
					CV_SPEC cv = find_cv_qual(s);
-
 
1239
					if (!(cv & cv_const)) {
-
 
1240
						/* Don't include const
-
 
1241
						 * references */
-
 
1242
						unsigned ns = TAG_type(s);
-
 
1243
						switch (ns) {
-
 
1244
						case type_integer_tag:
-
 
1245
						case type_bitfield_tag:
-
 
1246
						case type_enumerate_tag:
-
 
1247
							if (IS_TYPE_INTEGER(kind)) {
-
 
1248
								res = cons_type_set(res, r);
-
 
1249
							}
-
 
1250
							break;
-
 
1251
						case type_floating_tag:
-
 
1252
							if (IS_TYPE_FLOAT(kind)) {
-
 
1253
								res = cons_type_set(res, r);
-
 
1254
							}
-
 
1255
							break;
-
 
1256
						case type_ptr_tag:
-
 
1257
							if (IS_TYPE_PTR(kind)) {
-
 
1258
								res = cons_type_set(res, r);
-
 
1259
							}
-
 
1260
							break;
-
 
1261
						case type_ptr_mem_tag:
-
 
1262
							if (IS_TYPE_PTR_MEM(kind)) {
-
 
1263
								res = cons_type_set(res, r);
-
 
1264
							}
-
 
1265
							break;
-
 
1266
						}
-
 
1267
					}
-
 
1268
				} else {
-
 
1269
					/* Allow for reference conversions */
-
 
1270
					r = DEREF_type(type_ref_sub(r));
-
 
1271
					nr = TAG_type(r);
-
 
1272
				}
-
 
1273
			}
1185
 
1274
 
1186
		/* Check for reference types */
1275
			/* Check return type */
1187
		nm = DEREF_hashid ( id_name ( id ) ) ;
-
 
1188
		r = DEREF_type ( hashid_conv_type ( nm ) ) ;
-
 
1189
		if ( kind == CTYPE_NONE ) {
-
 
1190
		    /* Include all types in this case */
-
 
1191
		    res = cons_type_set ( res, r ) ;
-
 
1192
		    continue ;
-
 
1193
		}
-
 
1194
		nr = TAG_type ( r ) ;
-
 
1195
		if ( nr == type_ref_tag ) {
-
 
1196
		    /* Allow for reference bindings */
-
 
1197
		    if ( IS_TYPE_LVALUE ( kind ) ) {
-
 
1198
			TYPE s = DEREF_type ( type_ref_sub ( r ) ) ;
-
 
1199
			CV_SPEC cv = find_cv_qual ( s ) ;
-
 
1200
			if ( !( cv & cv_const ) ) {
-
 
1201
			    /* Don't include const references */
-
 
1202
			    unsigned ns = TAG_type ( s ) ;
-
 
1203
			    switch ( ns ) {
1276
			switch (nr) {
1204
				case type_integer_tag :
1277
			case type_integer_tag:
1205
				case type_bitfield_tag :
1278
			case type_bitfield_tag:
1206
				case type_enumerate_tag : {
1279
			case type_enumerate_tag:
1207
				    if ( IS_TYPE_INTEGER ( kind ) ) {
-
 
1208
					res = cons_type_set ( res, r ) ;
-
 
1209
				    }
-
 
1210
				    break ;
1280
				/* Integral types */
1211
				}
-
 
1212
				case type_floating_tag : {
-
 
1213
				    if ( IS_TYPE_FLOAT ( kind ) ) {
1281
				if (IS_TYPE_INTEGER(kind)) {
1214
					res = cons_type_set ( res, r ) ;
1282
					/* Means promoted integer type */
1215
				    }
-
 
1216
				    break ;
1283
					TYPE s = promote_type(r);
1217
				}
-
 
1218
				case type_ptr_tag : {
1284
					res = cons_type_set(res, s);
1219
				    if ( IS_TYPE_PTR ( kind ) ) {
1285
				} else if (IS_TYPE_FLOAT(kind)) {
1220
					res = cons_type_set ( res, r ) ;
1286
					/* Can convert to any floating type */
1221
				    }
-
 
1222
				    break ;
1287
					res = add_float_types(res);
1223
				}
1288
				}
-
 
1289
				break;
-
 
1290
			case type_floating_tag:
-
 
1291
				/* Floating point types */
-
 
1292
				if (IS_TYPE_FLOAT(kind)) {
-
 
1293
					res = cons_type_set(res, r);
-
 
1294
				} else if (IS_TYPE_INTEGER(kind)) {
-
 
1295
					/* Can convert to any promoted integer
-
 
1296
					 * type */
-
 
1297
					res = add_int_types(res);
-
 
1298
				}
-
 
1299
				break;
1224
				case type_ptr_mem_tag : {
1300
			case type_ptr_tag:
-
 
1301
				/* Pointer types */
1225
				    if ( IS_TYPE_PTR_MEM ( kind ) ) {
1302
				if (IS_TYPE_PTR(kind)) {
1226
					res = cons_type_set ( res, r ) ;
1303
					res = cons_type_set(res, r);
1227
				    }
1304
				}
1228
				    break ;
1305
				break;
-
 
1306
			case type_ptr_mem_tag:
-
 
1307
				/* Pointer to member types */
-
 
1308
				if (IS_TYPE_PTR_MEM(kind)) {
-
 
1309
					res = cons_type_set(res, r);
1229
				}
1310
				}
1230
			    }
1311
				break;
1231
			}
1312
			}
1232
		    } else {
-
 
1233
			/* Allow for reference conversions */
-
 
1234
			r = DEREF_type ( type_ref_sub ( r ) ) ;
-
 
1235
			nr = TAG_type ( r ) ;
-
 
1236
		    }
-
 
1237
		}
1313
		}
1238
 
-
 
1239
		/* Check return type */
1314
		res = REVERSE_list(res);
1240
		switch ( nr ) {
1315
		break;
-
 
1316
	}
1241
		    case type_integer_tag :
1317
	case type_integer_tag:
1242
		    case type_bitfield_tag :
1318
	case type_bitfield_tag:
1243
		    case type_enumerate_tag : {
1319
	case type_enumerate_tag:
1244
			/* Integral types */
1320
		/* Integral types */
1245
			if ( IS_TYPE_INTEGER ( kind ) ) {
1321
		if (IS_TYPE_LVALUE(kind)) {
1246
			    /* Means promoted integer type */
1322
			/* Lvalue of integral type */
1247
			    TYPE s = promote_type ( r ) ;
1323
			if (IS_TYPE_INTEGER(kind)) {
1248
			    res = cons_type_set ( res, s ) ;
1324
				if (nt == type_integer_tag) {
1249
			} else if ( IS_TYPE_FLOAT ( kind ) ) {
1325
					t = lvalue_type(t);
1250
			    /* Can convert to any floating type */
1326
					MAKE_type_ref(cv_none, t, t);
1251
			    res = add_float_types ( res ) ;
1327
					CONS_type(t, res, res);
1252
			}
1328
				}
1253
			break ;
-
 
1254
		    }
1329
			}
1255
		    case type_floating_tag : {
1330
		} else if (IS_TYPE_INTEGER(kind)) {
1256
			/* Floating point types */
1331
			/* Means promoted integer type */
1257
			if ( IS_TYPE_FLOAT ( kind ) ) {
1332
			TYPE s = promote_type(t);
1258
			    res = cons_type_set ( res, r ) ;
1333
			CONS_type(s, res, res);
1259
			} else if ( IS_TYPE_INTEGER ( kind ) ) {
1334
		} else if (IS_TYPE_FLOAT(kind)) {
1260
			    /* Can convert to any promoted integer type */
1335
			/* Can convert to any floating type */
1261
			    res = add_int_types ( res ) ;
1336
			res = add_float_types(res);
1262
			}
1337
		}
1263
			break ;
1338
		break;
1264
		    }
-
 
1265
		    case type_ptr_tag : {
1339
	case type_floating_tag:
1266
			/* Pointer types */
1340
		/* Floating point types */
-
 
1341
		if (IS_TYPE_LVALUE(kind)) {
-
 
1342
			/* Lvalue of floating point type */
1267
			if ( IS_TYPE_PTR ( kind ) ) {
1343
			if (IS_TYPE_FLOAT(kind)) {
-
 
1344
				t = lvalue_type(t);
-
 
1345
				MAKE_type_ref(cv_none, t, t);
1268
			    res = cons_type_set ( res, r ) ;
1346
				CONS_type(t, res, res);
1269
			}
1347
			}
-
 
1348
		} else if (IS_TYPE_FLOAT(kind)) {
1270
			break ;
1349
			/* Floating point type */
1271
		    }
1350
			CONS_type(t, res, res);
1272
		    case type_ptr_mem_tag : {
1351
		} else if (IS_TYPE_INTEGER(kind)) {
1273
			/* Pointer to member types */
1352
			/* Can convert to any promoted integer type */
1274
			if ( IS_TYPE_PTR_MEM ( kind ) ) {
1353
			if (basetype_info[ntype_sllong].key) {
-
 
1354
				CONS_type(type_ullong, res, res);
1275
			    res = cons_type_set ( res, r ) ;
1355
				CONS_type(type_sllong, res, res);
1276
			}
1356
			}
-
 
1357
			CONS_type(type_ulong, res, res);
-
 
1358
			CONS_type(type_slong, res, res);
-
 
1359
			CONS_type(type_uint, res, res);
-
 
1360
			CONS_type(type_sint, res, res);
-
 
1361
		}
1277
			break ;
1362
		break;
-
 
1363
	case type_ptr_tag:
-
 
1364
		/* Pointer types */
-
 
1365
		if (IS_TYPE_PTR(kind)) {
-
 
1366
			if (IS_TYPE_LVALUE(kind)) {
-
 
1367
				t = lvalue_type(t);
-
 
1368
				MAKE_type_ref(cv_none, t, t);
-
 
1369
			}
-
 
1370
			CONS_type(t, res, res);
-
 
1371
		}
-
 
1372
		break;
-
 
1373
	case type_ptr_mem_tag:
-
 
1374
		/* Pointer to member types */
-
 
1375
		if (IS_TYPE_PTR_MEM(kind)) {
-
 
1376
			if (IS_TYPE_LVALUE(kind)) {
-
 
1377
				t = lvalue_type(t);
-
 
1378
				MAKE_type_ref(cv_none, t, t);
1278
		    }
1379
			}
-
 
1380
			CONS_type(t, res, res);
-
 
1381
		}
-
 
1382
		break;
-
 
1383
	case type_array_tag:
-
 
1384
		/* Allow for array-to-pointer conversion */
-
 
1385
		if (IS_TYPE_PTR(kind) && !IS_TYPE_LVALUE(kind)) {
-
 
1386
			TYPE s = DEREF_type(type_array_sub(t));
-
 
1387
			MAKE_type_ptr(cv_none, s, s);
-
 
1388
			CONS_type(s, res, res);
-
 
1389
		}
-
 
1390
		if (kind == CTYPE_NONE) {
-
 
1391
			TYPE s = DEREF_type(type_array_sub(t));
-
 
1392
			MAKE_type_ptr(cv_none, s, t);
-
 
1393
		}
-
 
1394
		break;
-
 
1395
	case type_func_tag:
-
 
1396
		/* Allow for function-to-pointer conversion */
-
 
1397
		if (IS_TYPE_PTR(kind) && !IS_TYPE_LVALUE(kind)) {
-
 
1398
			TYPE s;
-
 
1399
			MAKE_type_ptr(cv_none, t, s);
-
 
1400
			CONS_type(s, res, res);
-
 
1401
		}
-
 
1402
		if (kind == CTYPE_NONE) {
-
 
1403
			MAKE_type_ptr(cv_none, t, t);
1279
		}
1404
		}
1280
	    }
-
 
1281
	    res = REVERSE_list ( res ) ;
-
 
1282
	    break ;
1405
		break;
1283
	}
1406
	}
1284
	case type_integer_tag :
-
 
1285
	case type_bitfield_tag :
-
 
1286
	case type_enumerate_tag : {
-
 
1287
	    /* Integral types */
-
 
1288
	    if ( IS_TYPE_LVALUE ( kind ) ) {
-
 
1289
		/* Lvalue of integral type */
-
 
1290
		if ( IS_TYPE_INTEGER ( kind ) ) {
-
 
1291
		    if ( nt == type_integer_tag ) {
1407
	if (kind == CTYPE_NONE) {
1292
			t = lvalue_type ( t ) ;
-
 
1293
			MAKE_type_ref ( cv_none, t, t ) ;
-
 
1294
			CONS_type ( t, res, res ) ;
-
 
1295
		    }
-
 
1296
		}
-
 
1297
	    } else if ( IS_TYPE_INTEGER ( kind ) ) {
-
 
1298
		/* Means promoted integer type */
-
 
1299
		TYPE s = promote_type ( t ) ;
-
 
1300
		CONS_type ( s, res, res ) ;
-
 
1301
	    } else if ( IS_TYPE_FLOAT ( kind ) ) {
-
 
1302
		/* Can convert to any floating type */
-
 
1303
		res = add_float_types ( res ) ;
-
 
1304
	    }
-
 
1305
	    break ;
-
 
1306
	}
-
 
1307
	case type_floating_tag : {
-
 
1308
	    /* Floating point types */
-
 
1309
	    if ( IS_TYPE_LVALUE ( kind ) ) {
-
 
1310
		/* Lvalue of floating point type */
1408
		/* Include all types in this case */
1311
		if ( IS_TYPE_FLOAT ( kind ) ) {
-
 
1312
		    t = lvalue_type ( t ) ;
-
 
1313
		    MAKE_type_ref ( cv_none, t, t ) ;
-
 
1314
		    CONS_type ( t, res, res ) ;
-
 
1315
		}
-
 
1316
	    } else if ( IS_TYPE_FLOAT ( kind ) ) {
-
 
1317
		/* Floating point type */
-
 
1318
		CONS_type ( t, res, res ) ;
-
 
1319
	    } else if ( IS_TYPE_INTEGER ( kind ) ) {
-
 
1320
		/* Can convert to any promoted integer type */
-
 
1321
		if ( basetype_info [ ntype_sllong ].key ) {
-
 
1322
		    CONS_type ( type_ullong, res, res ) ;
-
 
1323
		    CONS_type ( type_sllong, res, res ) ;
-
 
1324
		}
-
 
1325
		CONS_type ( type_ulong, res, res ) ;
-
 
1326
		CONS_type ( type_slong, res, res ) ;
-
 
1327
		CONS_type ( type_uint, res, res ) ;
-
 
1328
		CONS_type ( type_sint, res, res ) ;
1409
		CV_SPEC cv = DEREF_cv(type_qual(t));
1329
	    }
-
 
1330
	    break ;
-
 
1331
	}
-
 
1332
	case type_ptr_tag : {
-
 
1333
	    /* Pointer types */
-
 
1334
	    if ( IS_TYPE_PTR ( kind ) ) {
-
 
1335
		if ( IS_TYPE_LVALUE ( kind ) ) {
-
 
1336
		    t = lvalue_type ( t ) ;
1410
		if (cv & cv_lvalue) {
1337
		    MAKE_type_ref ( cv_none, t, t ) ;
-
 
1338
		}
-
 
1339
		CONS_type ( t, res, res ) ;
-
 
1340
	    }
-
 
1341
	    break ;
-
 
1342
	}
-
 
1343
	case type_ptr_mem_tag : {
-
 
1344
	    /* Pointer to member types */
1411
			/* Turn lvalues into references */
1345
	    if ( IS_TYPE_PTR_MEM ( kind ) ) {
-
 
1346
		if ( IS_TYPE_LVALUE ( kind ) ) {
-
 
1347
		    t = lvalue_type ( t ) ;
-
 
1348
		    MAKE_type_ref ( cv_none, t, t ) ;
1412
			MAKE_type_ref(cv_none, t, t);
1349
		}
1413
		}
1350
		CONS_type ( t, res, res ) ;
1414
		res = cons_type_set(res, t);
1351
	    }
-
 
1352
	    break ;
-
 
1353
	}
-
 
1354
	case type_array_tag : {
-
 
1355
	    /* Allow for array-to-pointer conversion */
-
 
1356
	    if ( IS_TYPE_PTR ( kind ) && !IS_TYPE_LVALUE ( kind ) ) {
-
 
1357
		TYPE s = DEREF_type ( type_array_sub ( t ) ) ;
-
 
1358
		MAKE_type_ptr ( cv_none, s, s ) ;
-
 
1359
		CONS_type ( s, res, res ) ;
-
 
1360
	    }
-
 
1361
	    if ( kind == CTYPE_NONE ) {
-
 
1362
		TYPE s = DEREF_type ( type_array_sub ( t ) ) ;
-
 
1363
		MAKE_type_ptr ( cv_none, s, t ) ;
-
 
1364
	    }
-
 
1365
	    break ;
-
 
1366
	}
-
 
1367
	case type_func_tag : {
-
 
1368
	    /* Allow for function-to-pointer conversion */
-
 
1369
	    if ( IS_TYPE_PTR ( kind ) && !IS_TYPE_LVALUE ( kind ) ) {
-
 
1370
		TYPE s ;
-
 
1371
		MAKE_type_ptr ( cv_none, t, s ) ;
-
 
1372
		CONS_type ( s, res, res ) ;
-
 
1373
	    }
-
 
1374
	    if ( kind == CTYPE_NONE ) {
-
 
1375
		MAKE_type_ptr ( cv_none, t, t ) ;
-
 
1376
	    }
-
 
1377
	    break ;
-
 
1378
	}
-
 
1379
    }
-
 
1380
    if ( kind == CTYPE_NONE ) {
-
 
1381
	/* Include all types in this case */
-
 
1382
	CV_SPEC cv = DEREF_cv ( type_qual ( t ) ) ;
-
 
1383
	if ( cv & cv_lvalue ) {
-
 
1384
	    /* Turn lvalues into references */
-
 
1385
	    MAKE_type_ref ( cv_none, t, t ) ;
-
 
1386
	}
1415
	}
1387
	res = cons_type_set ( res, t ) ;
-
 
1388
    }
-
 
1389
    UNUSED ( a ) ;
1416
	UNUSED(a);
1390
    return ( res ) ;
1417
	return (res);
1391
}
1418
}
1392
 
1419
 
1393
 
1420
 
1394
/*
1421
/*
1395
    FILTER A LIST OF POINTER TYPES
1422
    FILTER A LIST OF POINTER TYPES
Line 1398... Line 1425...
1398
    types pa replacing any types which are not pointers to complete object
1425
    types pa replacing any types which are not pointers to complete object
1399
    types by the null type.  If fn is true pointer to function types are
1426
    types by the null type.  If fn is true pointer to function types are
1400
    also allowed.
1427
    also allowed.
1401
*/
1428
*/
1402
 
1429
 
1403
static void filter_ptr
1430
static void
1404
    PROTO_N ( ( pa, fn ) )
-
 
1405
    PROTO_T ( LIST ( TYPE ) pa X int fn )
1431
filter_ptr(LIST(TYPE) pa, int fn)
1406
{
1432
{
1407
    while ( !IS_NULL_list ( pa ) ) {
1433
	while (!IS_NULL_list(pa)) {
1408
	TYPE ta = DEREF_type ( HEAD_list ( pa ) ) ;
1434
		TYPE ta = DEREF_type(HEAD_list(pa));
1409
	TYPE sa = ta ;
1435
		TYPE sa = ta;
1410
	if ( IS_type_ref ( sa ) ) {
1436
		if (IS_type_ref(sa)) {
1411
	    sa = DEREF_type ( type_ref_sub ( sa ) ) ;
1437
			sa = DEREF_type(type_ref_sub(sa));
1412
	}
1438
		}
1413
	if ( IS_type_ptr ( sa ) ) {
1439
		if (IS_type_ptr(sa)) {
1414
	    sa = DEREF_type ( type_ptr_sub ( sa ) ) ;
1440
			sa = DEREF_type(type_ptr_sub(sa));
1415
	} else {
1441
		} else {
1416
	    sa = DEREF_type ( type_ptr_mem_sub ( sa ) ) ;
1442
			sa = DEREF_type(type_ptr_mem_sub(sa));
1417
	}
1443
		}
1418
	switch ( TAG_type ( sa ) ) {
1444
		switch (TAG_type(sa)) {
1419
	    case type_array_tag : {
1445
		case type_array_tag: {
1420
		/* Check for incomplete arrays */
1446
			/* Check for incomplete arrays */
1421
		NAT n = DEREF_nat ( type_array_size ( sa ) ) ;
1447
			NAT n = DEREF_nat(type_array_size(sa));
1422
		if ( IS_NULL_nat ( n ) ) ta = NULL_type ;
1448
			if (IS_NULL_nat(n)) {
-
 
1449
				ta = NULL_type;
-
 
1450
			}
1423
		break ;
1451
			break;
1424
	    }
1452
		}
1425
	    case type_compound_tag : {
1453
		case type_compound_tag: {
1426
		/* Check for incomplete classes */
1454
			/* Check for incomplete classes */
1427
		CLASS_TYPE cs = DEREF_ctype ( type_compound_defn ( sa ) ) ;
1455
			CLASS_TYPE cs = DEREF_ctype(type_compound_defn(sa));
1428
		CLASS_INFO ci = DEREF_cinfo ( ctype_info ( cs ) ) ;
1456
			CLASS_INFO ci = DEREF_cinfo(ctype_info(cs));
1429
		if ( !( ci & cinfo_complete ) ) ta = NULL_type ;
1457
			if (!(ci & cinfo_complete)) {
-
 
1458
				ta = NULL_type;
-
 
1459
			}
1430
		break ;
1460
			break;
1431
	    }
1461
		}
1432
	    case type_enumerate_tag : {
1462
		case type_enumerate_tag: {
1433
		/* Check for incomplete enumerations */
1463
			/* Check for incomplete enumerations */
1434
		ENUM_TYPE es = DEREF_etype ( type_enumerate_defn ( sa ) ) ;
1464
			ENUM_TYPE es = DEREF_etype(type_enumerate_defn(sa));
1435
		CLASS_INFO ei = DEREF_cinfo ( etype_info ( es ) ) ;
1465
			CLASS_INFO ei = DEREF_cinfo(etype_info(es));
1436
		if ( !( ei & cinfo_complete ) ) ta = NULL_type ;
1466
			if (!(ei & cinfo_complete)) {
-
 
1467
				ta = NULL_type;
-
 
1468
			}
1437
		break ;
1469
			break;
1438
	    }
1470
		}
1439
	    case type_top_tag :
1471
		case type_top_tag:
1440
	    case type_bottom_tag : {
1472
		case type_bottom_tag:
1441
		/* These are always incomplete */
1473
			/* These are always incomplete */
1442
		ta = NULL_type ;
1474
			ta = NULL_type;
1443
		break ;
1475
			break;
1444
	    }
-
 
1445
	    case type_func_tag : {
1476
		case type_func_tag:
1446
		/* Deal with function types */
1477
			/* Deal with function types */
-
 
1478
			if (!fn) {
1447
		if ( !fn ) ta = NULL_type ;
1479
				ta = NULL_type;
-
 
1480
			}
1448
		break ;
1481
			break;
1449
	    }
1482
		}
-
 
1483
		COPY_type(HEAD_list(pa), ta);
-
 
1484
		pa = TAIL_list(pa);
1450
	}
1485
	}
1451
	COPY_type ( HEAD_list ( pa ), ta ) ;
-
 
1452
	pa = TAIL_list ( pa ) ;
-
 
1453
    }
-
 
1454
    return ;
1486
	return;
1455
}
1487
}
1456
 
1488
 
1457
 
1489
 
1458
/*
1490
/*
1459
    BUILT-IN OPERATOR TYPES
1491
    BUILT-IN OPERATOR TYPES
1460
 
1492
 
1461
    The following macros are used to describe the return types and the
1493
    The following macros are used to describe the return types and the
1462
    constraints on the operand types of the built-in operators.
1494
    constraints on the operand types of the built-in operators.
Line 1485... Line 1517...
1485
 
1517
 
1486
    This routine finds the return type for a built-in operator with
1518
    This routine finds the return type for a built-in operator with
1487
    operand types ta and tb and return descriptor rtype.  tc gives the
1519
    operand types ta and tb and return descriptor rtype.  tc gives the
1488
    default return type.  The return type is not used in overload
1520
    default return type.  The return type is not used in overload
1489
    resolution but is included for error reporting purposes.
1521
    resolution but is included for error reporting purposes.
1490
*/
1522
*/
1491
 
1523
 
1492
static TYPE find_builtin_ret
1524
static TYPE
1493
    PROTO_N ( ( ta, tb, rtype, tc ) )
-
 
1494
    PROTO_T ( TYPE ta X TYPE tb X int rtype X TYPE tc )
1525
find_builtin_ret(TYPE ta, TYPE tb, int rtype, TYPE tc)
1495
{
1526
{
1496
    switch ( rtype ) {
1527
	switch (rtype) {
1497
	case RTYPE_ARG_1 : {
1528
	case RTYPE_ARG_1:
1498
	    tc = ta ;
1529
		tc = ta;
1499
	    break ;
1530
		break;
1500
	}
-
 
1501
	case RTYPE_ARG_2 : {
1531
	case RTYPE_ARG_2:
1502
	    tc = tb ;
1532
		tc = tb;
1503
	    break ;
1533
		break;
1504
	}
-
 
1505
	case RTYPE_CONT_1 : {
1534
	case RTYPE_CONT_1:
1506
	    if ( IS_type_ptr_etc ( ta ) ) {
1535
		if (IS_type_ptr_etc(ta)) {
1507
		tc = DEREF_type ( type_ptr_etc_sub ( ta ) ) ;
1536
			tc = DEREF_type(type_ptr_etc_sub(ta));
1508
	    }
1537
		}
1509
	    break ;
1538
		break;
1510
	}
-
 
1511
	case RTYPE_CONT_2 : {
1539
	case RTYPE_CONT_2:
1512
	    if ( IS_type_ptr_etc ( tb ) ) {
1540
		if (IS_type_ptr_etc(tb)) {
1513
		tc = DEREF_type ( type_ptr_etc_sub ( tb ) ) ;
1541
			tc = DEREF_type(type_ptr_etc_sub(tb));
1514
	    }
1542
		}
1515
	    break ;
1543
		break;
1516
	}
-
 
1517
	case RTYPE_ARITH : {
1544
	case RTYPE_ARITH:
1518
	    tc = arith_type ( ta, tb, NULL_exp, NULL_exp ) ;
1545
		tc = arith_type(ta, tb, NULL_exp, NULL_exp);
1519
	    break ;
1546
		break;
1520
	}
-
 
1521
	case RTYPE_BOOL : {
1547
	case RTYPE_BOOL:
1522
	    tc = type_bool ;
1548
		tc = type_bool;
1523
	    break ;
1549
		break;
1524
	}
-
 
1525
	case RTYPE_PTRDIFF : {
1550
	case RTYPE_PTRDIFF:
1526
	    tc = type_ptrdiff_t ;
1551
		tc = type_ptrdiff_t;
1527
	    break ;
1552
		break;
1528
	}
1553
	}
1529
    }
-
 
1530
    return ( tc ) ;
1554
	return (tc);
1531
}
1555
}
1532
 
1556
 
1533
 
1557
 
1534
/*
1558
/*
1535
    CHECK BUILT-IN OPERAND TYPES
1559
    CHECK BUILT-IN OPERAND TYPES
1536
 
1560
 
1537
    This routine checks whether the operand types ta and tb are valid for
1561
    This routine checks whether the operand types ta and tb are valid for
1538
    a built-in operator with operand constraints otype.  In some cases
1562
    a built-in operator with operand constraints otype.  In some cases
1539
    the return type is returned via pt.
1563
    the return type is returned via pt.
1540
*/
1564
*/
1541
 
1565
 
1542
static int check_builtin_args
1566
static int
1543
    PROTO_N ( ( ta, tb, otype, pt ) )
-
 
1544
    PROTO_T ( TYPE ta X TYPE tb X int otype X TYPE *pt )
1567
check_builtin_args(TYPE ta, TYPE tb, int otype, TYPE *pt)
1545
{
1568
{
1546
    int ok = 1 ;
1569
	int ok = 1;
1547
    switch ( otype ) {
1570
	switch (otype) {
1548
	case OTYPE_PTR : {
1571
	case OTYPE_PTR: {
1549
	    /* Allow equal pointer types */
1572
		/* Allow equal pointer types */
1550
	    TYPE sa = DEREF_type ( type_ptr_sub ( ta ) ) ;
1573
		TYPE sa = DEREF_type(type_ptr_sub(ta));
1551
	    TYPE sb = DEREF_type ( type_ptr_sub ( tb ) ) ;
1574
		TYPE sb = DEREF_type(type_ptr_sub(tb));
1552
	    ok = eq_type_unqual ( sa, sb ) ;
1575
		ok = eq_type_unqual(sa, sb);
1553
	    break ;
1576
		break;
1554
	}
1577
	}
1555
	case OTYPE_PTR_MEM : {
1578
	case OTYPE_PTR_MEM: {
1556
	    /* Allow equal pointer member types */
1579
		/* Allow equal pointer member types */
1557
	    CLASS_TYPE ca = DEREF_ctype ( type_ptr_mem_of ( ta ) ) ;
1580
		CLASS_TYPE ca = DEREF_ctype(type_ptr_mem_of(ta));
1558
	    CLASS_TYPE cb = DEREF_ctype ( type_ptr_mem_of ( tb ) ) ;
1581
		CLASS_TYPE cb = DEREF_ctype(type_ptr_mem_of(tb));
1559
	    if ( eq_ctype ( ca, cb ) ) {
1582
		if (eq_ctype(ca, cb)) {
1560
		TYPE sa = DEREF_type ( type_ptr_mem_sub ( ta ) ) ;
1583
			TYPE sa = DEREF_type(type_ptr_mem_sub(ta));
1561
		TYPE sb = DEREF_type ( type_ptr_mem_sub ( tb ) ) ;
1584
			TYPE sb = DEREF_type(type_ptr_mem_sub(tb));
1562
		ok = eq_type_unqual ( sa, sb ) ;
1585
			ok = eq_type_unqual(sa, sb);
1563
	    } else {
1586
		} else {
1564
		ok = 0 ;
1587
			ok = 0;
1565
	    }
1588
		}
1566
	    break ;
1589
		break;
1567
	}
1590
	}
1568
	case OTYPE_REF_PTR : {
1591
	case OTYPE_REF_PTR:
1569
	    /* Allow equal pointer types */
1592
		/* Allow equal pointer types */
1570
	    if ( IS_type_ref ( ta ) ) {
-
 
1571
		ta = DEREF_type ( type_ref_sub ( ta ) ) ;
-
 
1572
	    }
-
 
1573
	    return ( check_builtin_args ( ta, tb, OTYPE_PTR, pt ) ) ;
-
 
1574
	}
-
 
1575
	case OTYPE_REF_MEM : {
-
 
1576
	    /* Allow equal pointer member types */
-
 
1577
	    if ( IS_type_ref ( ta ) ) {
-
 
1578
		ta = DEREF_type ( type_ref_sub ( ta ) ) ;
-
 
1579
	    }
-
 
1580
	    return ( check_builtin_args ( ta, tb, OTYPE_PTR_MEM, pt ) ) ;
-
 
1581
	}
-
 
1582
	case OTYPE_SELECT : {
-
 
1583
	    /* Allow pointer member selection */
-
 
1584
	    TYPE sa = DEREF_type ( type_ptr_sub ( ta ) ) ;
-
 
1585
	    if ( IS_type_compound ( sa ) ) {
-
 
1586
		CLASS_TYPE ca = DEREF_ctype ( type_compound_defn ( sa ) ) ;
-
 
1587
		CLASS_TYPE cb = DEREF_ctype ( type_ptr_mem_of ( tb ) ) ;
-
 
1588
		GRAPH gr = find_base_class ( ca, cb, 0 ) ;
-
 
1589
		if ( IS_NULL_graph ( gr ) ) ok = 0 ;
-
 
1590
		*pt = DEREF_type ( type_ptr_mem_sub ( tb ) ) ;
-
 
1591
	    } else {
-
 
1592
		ok = 0 ;
-
 
1593
	    }
-
 
1594
	    break ;
-
 
1595
	}
-
 
1596
	case OTYPE_COND : {
-
 
1597
	    /* Allow for conditional expressions */
-
 
1598
	    int suspect = 0 ;
-
 
1599
	    TYPE r = common_type ( ta, tb, &suspect ) ;
-
 
1600
	    if ( IS_NULL_type ( r ) ) {
-
 
1601
		ok = 0 ;
-
 
1602
		if ( IS_type_ref ( ta ) ) {
1593
		if (IS_type_ref(ta)) {
1603
		    ta = DEREF_type ( type_ref_sub ( ta ) ) ;
1594
			ta = DEREF_type(type_ref_sub(ta));
1604
		    ok = 1 ;
-
 
1605
		}
-
 
1606
		if ( IS_type_ref ( tb ) ) {
-
 
1607
		    tb = DEREF_type ( type_ref_sub ( tb ) ) ;
-
 
1608
		    ok = 1 ;
-
 
1609
		}
1595
		}
1610
		if ( ok ) {
1596
		return (check_builtin_args(ta, tb, OTYPE_PTR, pt));
1611
		    suspect = 0 ;
1597
	case OTYPE_REF_MEM:
1612
		    r = common_type ( ta, tb, &suspect ) ;
1598
		/* Allow equal pointer member types */
1613
		    if ( IS_NULL_type ( r ) ) {
1599
		if (IS_type_ref(ta)) {
1614
			ok = 0 ;
-
 
1615
		    } else {
1600
			ta = DEREF_type(type_ref_sub(ta));
1616
			*pt = r ;
-
 
1617
		    }
-
 
1618
		}
1601
		}
-
 
1602
		return (check_builtin_args(ta, tb, OTYPE_PTR_MEM, pt));
-
 
1603
	case OTYPE_SELECT: {
-
 
1604
		/* Allow pointer member selection */
-
 
1605
		TYPE sa = DEREF_type(type_ptr_sub(ta));
-
 
1606
		if (IS_type_compound(sa)) {
-
 
1607
			CLASS_TYPE ca = DEREF_ctype(type_compound_defn(sa));
-
 
1608
			CLASS_TYPE cb = DEREF_ctype(type_ptr_mem_of(tb));
-
 
1609
			GRAPH gr = find_base_class(ca, cb, 0);
-
 
1610
			if (IS_NULL_graph(gr))ok = 0;
-
 
1611
			*pt = DEREF_type(type_ptr_mem_sub(tb));
-
 
1612
		} else {
-
 
1613
			ok = 0;
-
 
1614
		}
-
 
1615
		break;
-
 
1616
	}
-
 
1617
	case OTYPE_COND: {
-
 
1618
		/* Allow for conditional expressions */
-
 
1619
		int suspect = 0;
-
 
1620
		TYPE r = common_type(ta, tb, &suspect);
-
 
1621
		if (IS_NULL_type(r)) {
-
 
1622
			ok = 0;
-
 
1623
			if (IS_type_ref(ta)) {
-
 
1624
				ta = DEREF_type(type_ref_sub(ta));
-
 
1625
				ok = 1;
-
 
1626
			}
-
 
1627
			if (IS_type_ref(tb)) {
-
 
1628
				tb = DEREF_type(type_ref_sub(tb));
-
 
1629
				ok = 1;
-
 
1630
			}
-
 
1631
			if (ok) {
-
 
1632
				suspect = 0;
-
 
1633
				r = common_type(ta, tb, &suspect);
-
 
1634
				if (IS_NULL_type(r)) {
-
 
1635
					ok = 0;
1619
	    } else {
1636
				} else {
-
 
1637
					*pt = r;
-
 
1638
				}
-
 
1639
			}
-
 
1640
		} else {
1620
		*pt = r ;
1641
			*pt = r;
1621
	    }
1642
		}
1622
	    break ;
1643
		break;
-
 
1644
	}
1623
	}
1645
	}
1624
    }
-
 
1625
    return ( ok ) ;
1646
	return (ok);
1626
}
1647
}
1627
 
1648
 
1628
 
1649
 
1629
/*
1650
/*
1630
    ADD A LIST OF BUILT-IN UNARY CANDIDATES
1651
    ADD A LIST OF BUILT-IN UNARY CANDIDATES
1631
 
1652
 
1632
    This routine adds a series of built-in unary candidates for the
1653
    This routine adds a series of built-in unary candidates for the
1633
    operator nm to the list p.  The possible operand types are given by pa.
1654
    operator nm to the list p.  The possible operand types are given by pa.
1634
    rtype describes how to form the return type from the operand type.
1655
    rtype describes how to form the return type from the operand type.
1635
*/
1656
*/
1636
 
1657
 
1637
static void add_unary_builtin
1658
static void
1638
    PROTO_N ( ( p, nm, pa, rtype ) )
-
 
1639
    PROTO_T ( CANDIDATE_LIST *p X HASHID nm X LIST ( TYPE ) pa X int rtype )
1659
add_unary_builtin(CANDIDATE_LIST *p, HASHID nm, LIST(TYPE) pa, int rtype)
1640
{
1660
{
1641
    while ( !IS_NULL_list ( pa ) ) {
1661
	while (!IS_NULL_list(pa)) {
1642
	TYPE ta = DEREF_type ( HEAD_list ( pa ) ) ;
1662
		TYPE ta = DEREF_type(HEAD_list(pa));
1643
	if ( !IS_NULL_type ( ta ) ) {
1663
		if (!IS_NULL_type(ta)) {
1644
	    TYPE tb = find_builtin_ret ( ta, ta, rtype, type_error ) ;
1664
			TYPE tb = find_builtin_ret(ta, ta, rtype, type_error);
1645
	    IDENTIFIER id = unary_builtin ( nm, ta, tb ) ;
1665
			IDENTIFIER id = unary_builtin(nm, ta, tb);
1646
	    add_candidates ( p, id, 1, KIND_BUILTIN ) ;
1666
			add_candidates(p, id, 1, KIND_BUILTIN);
-
 
1667
		}
-
 
1668
		pa = TAIL_list(pa);
1647
	}
1669
	}
1648
	pa = TAIL_list ( pa ) ;
-
 
1649
    }
-
 
1650
    DESTROY_list ( pa, SIZE_type ) ;
1670
	DESTROY_list(pa, SIZE_type);
1651
    return ;
1671
	return;
1652
}
1672
}
1653
 
1673
 
1654
 
1674
 
1655
/*
1675
/*
1656
    ADD A LIST OF BUILT-IN BINARY CANDIDATES
1676
    ADD A LIST OF BUILT-IN BINARY CANDIDATES
Line 1660... Line 1680...
1660
    are given by pa and pb.  rtype describes how to form the return type
1680
    are given by pa and pb.  rtype describes how to form the return type
1661
    from the operand types, otype describes any restrictions on the operand
1681
    from the operand types, otype describes any restrictions on the operand
1662
    types.
1682
    types.
1663
*/
1683
*/
1664
 
1684
 
1665
static void add_binary_builtin
1685
static void
1666
    PROTO_N ( ( p, nm, pa, pb, rtype, otype ) )
-
 
1667
    PROTO_T ( CANDIDATE_LIST *p X HASHID nm X LIST ( TYPE ) pa X
1686
add_binary_builtin(CANDIDATE_LIST *p, HASHID nm, LIST(TYPE) pa, LIST(TYPE) pb,
1668
	      LIST ( TYPE ) pb X int rtype X int otype )
1687
		   int rtype, int otype)
1669
{
1688
{
1670
    while ( !IS_NULL_list ( pa ) ) {
1689
    while (!IS_NULL_list(pa)) {
1671
	TYPE ta = DEREF_type ( HEAD_list ( pa ) ) ;
1690
	TYPE ta = DEREF_type(HEAD_list(pa));
1672
	if ( !IS_NULL_type ( ta ) ) {
1691
	if (!IS_NULL_type(ta)) {
1673
	    LIST ( TYPE ) pc = pb ;
1692
	    LIST(TYPE) pc = pb;
1674
	    while ( !IS_NULL_list ( pc ) ) {
1693
	    while (!IS_NULL_list(pc)) {
1675
		TYPE tb = DEREF_type ( HEAD_list ( pc ) ) ;
1694
		TYPE tb = DEREF_type(HEAD_list(pc));
1676
		if ( !IS_NULL_type ( tb ) ) {
1695
		if (!IS_NULL_type(tb)) {
1677
		    /* Check operand types */
1696
		    /* Check operand types */
1678
		    TYPE tc = type_error ;
1697
		    TYPE tc = type_error;
1679
		    if ( check_builtin_args ( ta, tb, otype, &tc ) ) {
1698
		    if (check_builtin_args(ta, tb, otype, &tc)) {
1680
			IDENTIFIER id ;
1699
			IDENTIFIER id;
1681
			tc = find_builtin_ret ( ta, tb, rtype, tc ) ;
1700
			tc = find_builtin_ret(ta, tb, rtype, tc);
1682
			if ( otype == OTYPE_COND ) {
1701
			if (otype == OTYPE_COND) {
1683
			    ta = tc ;
1702
			    ta = tc;
1684
			    tb = tc ;
1703
			    tb = tc;
1685
			}
1704
			}
1686
			id = binary_builtin ( nm, ta, tb, tc ) ;
1705
			id = binary_builtin(nm, ta, tb, tc);
1687
			add_candidates ( p, id, 1, KIND_BUILTIN ) ;
1706
			add_candidates(p, id, 1, KIND_BUILTIN);
1688
		    }
1707
		    }
1689
		}
1708
		}
1690
		pc = TAIL_list ( pc ) ;
1709
		pc = TAIL_list(pc);
1691
	    }
1710
	    }
1692
	}
1711
	}
1693
	pa = TAIL_list ( pa ) ;
1712
	pa = TAIL_list(pa);
1694
    }
1713
    }
-
 
1714
    if (!EQ_list(pa, pb)) {
1695
    if ( !EQ_list ( pa, pb ) ) DESTROY_list ( pa, SIZE_type ) ;
1715
	    DESTROY_list(pa, SIZE_type);
-
 
1716
    }
1696
    DESTROY_list ( pb, SIZE_type ) ;
1717
    DESTROY_list(pb, SIZE_type);
1697
    return ;
1718
    return;
1698
}
1719
}
1699
 
1720
 
1700
 
1721
 
1701
/*
1722
/*
1702
    OVERLOAD A UNARY OPERATOR
1723
    OVERLOAD A UNARY OPERATOR
Line 1705... Line 1726...
1705
    be 'a.operator op ()', 'operator op ( a )' or 'op t ( a )' for some
1726
    be 'a.operator op ()', 'operator op ( a )' or 'op t ( a )' for some
1706
    type t.  Note that '->' is a special case for op, with 'a->b' being
1727
    type t.  Note that '->' is a special case for op, with 'a->b' being
1707
    expanded as '( a.operator -> () )->b'.  This expansion is done in
1728
    expanded as '( a.operator -> () )->b'.  This expansion is done in
1708
    begin_field_exp, this routine returning the null expression to indicate
1729
    begin_field_exp, this routine returning the null expression to indicate
1709
    that '->' is not overloaded.
1730
    that '->' is not overloaded.
1859
    OVERLOAD A BINARY OPERATOR
1883
    OVERLOAD A BINARY OPERATOR
1860
 
1884
 
1861
    This routine calculates the binary overload operator 'a op b'.  This can
1885
    This routine calculates the binary overload operator 'a op b'.  This can
1862
    be 'a.operator op ( b )', 'operator op ( a, b )' or 't ( a ) op s ( b )'
1886
    be 'a.operator op ( b )', 'operator op ( a, b )' or 't ( a ) op s ( b )'
1863
    for some types t and s.  Note that postfix '++' and '--' are special
1887
    for some types t and s.  Note that postfix '++' and '--' are special
1864
    cases for op in which b is a dummy zero operand.
1888
    cases for op in which b is a dummy zero operand.
2079
	}
2176
	}
2080
    }
-
 
2081
 
-
 
2082
    /* Search for overload operator */
-
 
2083
    if ( p->size ) {
-
 
2084
	CANDIDATE *q ;
-
 
2085
	unsigned rank ;
-
 
2086
	LIST ( EXP ) args ;
-
 
2087
	CONS_exp ( b, NULL_list ( EXP ), args ) ;
-
 
2088
	CONS_exp ( a, args, args ) ;
-
 
2089
	q = resolve_overload ( p, args, NULL_type, 0 ) ;
-
 
2090
	binary_free = binary_all ;
-
 
2091
	rank = q->rank ;
-
 
2092
	if ( rank >= RANK_VIABLE ) {
-
 
2093
	    /* Only allow viable resolutions */
-
 
2094
	    int kind = q->kind ;
-
 
2095
	    IDENTIFIER qid = q->func ;
-
 
2096
	    int ow = overload_warn ;
-
 
2097
	    if ( rank == RANK_BEST ) {
-
 
2098
		/* Unambiguous resolution */
-
 
2099
		if ( match_no_viable > 1 && ow ) {
-
 
2100
		    if ( do_dump ) dump_builtin ( qid ) ;
-
 
2101
		    report ( crt_loc, ERR_over_match_oper_ok ( qid ) ) ;
-
 
2102
		}
-
 
2103
	    } else {
-
 
2104
		/* Ambiguous resolution */
-
 
2105
		q = resolve_ambiguous ( p, args, NULL_type, 0 ) ;
-
 
2106
		qid = q->func ;
-
 
2107
		rank = q->rank ;
-
 
2108
		if ( rank == RANK_TARGET ) {
-
 
2109
		    ERROR err2 = ERR_over_match_oper_target ( op ) ;
-
 
2110
		    qid = make_ambig_func ( p, qid, args, qual_none, &err2 ) ;
-
 
2111
		    kind = KIND_OP ;
-
 
2112
		    if ( do_dump ) dump_builtin ( qid ) ;
-
 
2113
		    report ( crt_loc, err2 ) ;
-
 
2114
		} else if ( rank == RANK_VIABLE ) {
-
 
2115
		    ERROR err2 = ERR_over_match_oper_ambig ( op ) ;
-
 
2116
		    err2 = list_candidates ( err2, p, RANK_VIABLE ) ;
-
 
2117
		    report ( crt_loc, err2 ) ;
-
 
2118
		}
-
 
2119
		overload_warn = 0 ;
-
 
2120
	    }
-
 
2121
	    if ( kind == KIND_BUILTIN ) {
-
 
2122
		/* Built-in resolution */
-
 
2123
		if ( op == lex_comma ) {
-
 
2124
		    /* Return null expression for 'a, b' */
-
 
2125
		    DESTROY_list ( args, SIZE_exp ) ;
-
 
2126
		    e = NULL_exp ;
-
 
2127
		} else {
-
 
2128
		    e = apply_builtin ( qid, args ) ;
-
 
2129
		}
-
 
2130
	    } else {
-
 
2131
		/* Function resolution */
-
 
2132
		use_func_id ( qid, 0, suppress_usage ) ;
-
 
2133
		e = apply_func_id ( qid, qual_none, NULL_graph, args ) ;
-
 
2134
	    }
-
 
2135
	    overload_warn = ow ;
-
 
2136
	    return ( e ) ;
2177
	return (e);
2137
	}
-
 
2138
	DESTROY_list ( args, SIZE_exp ) ;
-
 
2139
    }
-
 
2140
 
-
 
2141
    /* Try operation again */
-
 
2142
    if ( op == lex_comma ) {
-
 
2143
	/* Return null expression for 'a, b' */
-
 
2144
	e = NULL_exp ;
-
 
2145
    } else {
-
 
2146
	overload_depth++ ;
-
 
2147
	e = apply_binary ( op, a, b, NULL_type, NULL_type, 0 ) ;
-
 
2148
	overload_depth-- ;
-
 
2149
    }
-
 
2150
    return ( e ) ;
-
 
2151
}
2178
}
2152
 
2179
 
2153
 
2180
 
2154
/*
2181
/*
2155
    OVERLOAD A FUNCTION OPERATOR
2182
    OVERLOAD A FUNCTION OPERATOR
2156
 
2183
 
2157
    This routine calculates the function overload operator 'a ( args )'.
2184
    This routine calculates the function overload operator 'a ( args )'.
2158
    This is expanded as 'a.operator () ( args )'.
2185
    This is expanded as 'a.operator () ( args )'.
2159
*/
2186
*/
2160
 
2187
 
2161
EXP function_overload
2188
EXP
2162
    PROTO_N ( ( a, args ) )
-
 
2163
    PROTO_T ( EXP a X LIST ( EXP ) args )
2189
function_overload(EXP a, LIST(EXP)args)
2164
{
2190
{
2165
    EXP e ;
2191
	EXP e;
2166
    int op = lex_func_Hop ;
2192
	int op = lex_func_Hop;
2167
 
2193
 
2168
    /* Construct candidate list */
2194
	/* Construct candidate list */
2169
    TYPE t = DEREF_type ( exp_type ( a ) ) ;
2195
	TYPE t = DEREF_type(exp_type(a));
2170
    CANDIDATE_LIST *p = &candidates ;
2196
	CANDIDATE_LIST *p = &candidates;
2171
    p->size = 0 ;
2197
	p->size = 0;
2172
    IGNORE overload_candidates ( p, op, t, NULL_type ) ;
2198
	IGNORE overload_candidates(p, op, t, NULL_type);
2173
 
2199
 
2174
    if ( IS_type_compound ( t ) ) {
2200
	if (IS_type_compound(t)) {
2175
	LIST ( IDENTIFIER ) conv ;
2201
		LIST(IDENTIFIER) conv;
2176
	HASHID nm = KEYWORD ( lex_zzzz ) ;
2202
		HASHID nm = KEYWORD(lex_zzzz);
2177
	CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
2203
		CLASS_TYPE ct = DEREF_ctype(type_compound_defn(t));
2178
	complete_class ( ct, 1 ) ;
2204
		complete_class(ct, 1);
2179
	conv = DEREF_list ( ctype_conv ( ct ) ) ;
2205
		conv = DEREF_list(ctype_conv(ct));
2180
	while ( !IS_NULL_list ( conv ) ) {
2206
		while (!IS_NULL_list(conv)) {
2181
	    /* Scan through conversion operations */
2207
			/* Scan through conversion operations */
2182
	    IDENTIFIER cid = DEREF_id ( HEAD_list ( conv ) ) ;
2208
			IDENTIFIER cid = DEREF_id(HEAD_list(conv));
2183
	    DECL_SPEC ds = DEREF_dspec ( id_storage ( cid ) ) ;
2209
			DECL_SPEC ds = DEREF_dspec(id_storage(cid));
2184
	    if ( !( ds & dspec_explicit ) ) {
2210
			if (!(ds & dspec_explicit)) {
2185
		HASHID cnm = DEREF_hashid ( id_name ( cid ) ) ;
2211
				HASHID cnm = DEREF_hashid(id_name(cid));
2186
		TYPE r = DEREF_type ( hashid_conv_type ( cnm ) ) ;
2212
				TYPE r = DEREF_type(hashid_conv_type(cnm));
2187
		unsigned nr = TAG_type ( r ) ;
2213
				unsigned nr = TAG_type(r);
2188
 
-
 
2189
		/* Search for pointer or reference to functions */
-
 
2190
		if ( nr == type_ptr_tag || nr == type_ref_tag ) {
-
 
2191
		    TYPE s = DEREF_type ( type_ptr_etc_sub ( r ) ) ;
-
 
2192
		    if ( IS_type_func ( s ) ) {
-
 
2193
			LOCATION loc ;
-
 
2194
			LIST ( TYPE ) ptypes ;
-
 
2195
			TYPE ret = DEREF_type ( type_func_ret ( s ) ) ;
-
 
2196
			ptypes = DEREF_list ( type_func_ptypes ( s ) ) ;
-
 
2197
			DEREF_loc ( id_loc ( cid ), loc ) ;
-
 
2198
			cid = nary_builtin ( nm, r, ptypes, ret ) ;
-
 
2199
			COPY_loc ( id_loc ( cid ), loc ) ;
-
 
2200
			add_candidates ( p, cid, 1, KIND_BUILTIN ) ;
-
 
2201
		    }
-
 
2202
		}
-
 
2203
	    }
-
 
2204
	    conv = TAIL_list ( conv ) ;
-
 
2205
	}
-
 
2206
    }
-
 
2207
 
2214
 
2208
    /* Search for overload operator */
2215
				/* Search for pointer or reference to
2209
    if ( p->size ) {
2216
				 * functions */
2210
	CANDIDATE *q ;
2217
				if (nr == type_ptr_tag || nr == type_ref_tag) {
2211
	unsigned rank ;
2218
					TYPE s =
2212
	CONS_exp ( a, args, args ) ;
2219
					    DEREF_type(type_ptr_etc_sub(r));
2213
	q = resolve_overload ( p, args, NULL_type, 0 ) ;
2220
					if (IS_type_func(s)) {
2214
	nary_free = nary_all ;
2221
						LOCATION loc;
2215
	rank = q->rank ;
2222
						LIST(TYPE) ptypes;
2216
	if ( rank >= RANK_VIABLE ) {
2223
						TYPE ret = DEREF_type(type_func_ret(s));
2217
	    /* Only allow viable resolutions */
2224
						ptypes = DEREF_list(type_func_ptypes(s));
2218
	    int kind = q->kind ;
2225
						DEREF_loc(id_loc(cid), loc);
2219
	    IDENTIFIER qid = q->func ;
2226
						cid = nary_builtin(nm, r,
2220
	    int ow = overload_warn ;
2227
								   ptypes,
2221
	    if ( rank == RANK_BEST ) {
2228
								   ret);
2222
		/* Unambiguous resolution */
2229
						COPY_loc(id_loc(cid), loc);
2223
		if ( match_no_viable > 1 && ow ) {
2230
						add_candidates(p, cid, 1,
2224
		    if ( do_dump ) dump_builtin ( qid ) ;
2231
							       KIND_BUILTIN);
-
 
2232
					}
-
 
2233
				}
-
 
2234
			}
2225
		    report ( crt_loc, ERR_over_match_oper_ok ( qid ) ) ;
2235
			conv = TAIL_list(conv);
2226
		}
2236
		}
-
 
2237
	}
-
 
2238
 
-
 
2239
	/* Search for overload operator */
-
 
2240
	if (p->size) {
-
 
2241
		CANDIDATE *q;
-
 
2242
		unsigned rank;
-
 
2243
		CONS_exp(a, args, args);
-
 
2244
		q = resolve_overload(p, args, NULL_type, 0);
-
 
2245
		nary_free = nary_all;
-
 
2246
		rank = q->rank;
-
 
2247
		if (rank >= RANK_VIABLE) {
-
 
2248
			/* Only allow viable resolutions */
-
 
2249
			int kind = q->kind;
-
 
2250
			IDENTIFIER qid = q->func;
-
 
2251
			int ow = overload_warn;
-
 
2252
			if (rank == RANK_BEST) {
-
 
2253
				/* Unambiguous resolution */
-
 
2254
				if (match_no_viable > 1 && ow) {
-
 
2255
					if (do_dump) {
-
 
2256
						dump_builtin(qid);
-
 
2257
					}
-
 
2258
					report(crt_loc,
-
 
2259
					       ERR_over_match_oper_ok(qid));
-
 
2260
				}
2227
	    } else {
2261
			} else {
2228
		/* Ambiguous resolution */
2262
				/* Ambiguous resolution */
2229
		q = resolve_ambiguous ( p, args, NULL_type, 0 ) ;
2263
				q = resolve_ambiguous(p, args, NULL_type, 0);
2230
		qid = q->func ;
2264
				qid = q->func;
2231
		rank = q->rank ;
2265
				rank = q->rank;
2232
		if ( rank == RANK_TARGET ) {
2266
				if (rank == RANK_TARGET) {
-
 
2267
					ERROR err =
2233
		    ERROR err = ERR_over_match_oper_target ( op ) ;
2268
					    ERR_over_match_oper_target(op);
2234
		    qid = make_ambig_func ( p, qid, args, qual_none, &err ) ;
2269
					qid = make_ambig_func(p, qid, args,
-
 
2270
							      qual_none, &err);
2235
		    kind = KIND_OP ;
2271
					kind = KIND_OP;
-
 
2272
					if (do_dump) {
2236
		    if ( do_dump ) dump_builtin ( qid ) ;
2273
						dump_builtin(qid);
-
 
2274
					}
2237
		    report ( crt_loc, err ) ;
2275
					report(crt_loc, err);
2238
		} else if ( rank == RANK_VIABLE ) {
2276
				} else if (rank == RANK_VIABLE) {
-
 
2277
					ERROR err =
2239
		    ERROR err = ERR_over_match_oper_ambig ( op ) ;
2278
					    ERR_over_match_oper_ambig(op);
2240
		    err = list_candidates ( err, p, RANK_VIABLE ) ;
2279
					err = list_candidates(err, p,
-
 
2280
							      RANK_VIABLE);
2241
		    report ( crt_loc, err ) ;
2281
					report(crt_loc, err);
-
 
2282
				}
-
 
2283
				overload_warn = 0;
-
 
2284
			}
-
 
2285
			if (kind == KIND_BUILTIN) {
-
 
2286
				/* Built-in resolution */
-
 
2287
				e = apply_builtin(qid, args);
-
 
2288
			} else {
-
 
2289
				/* Function resolution */
-
 
2290
				use_func_id(qid, 0, suppress_usage);
-
 
2291
				e = apply_func_id(qid, qual_none, NULL_graph,
-
 
2292
						  args);
-
 
2293
			}
-
 
2294
			overload_warn = ow;
-
 
2295
			return (e);
2242
		}
2296
		}
2243
		overload_warn = 0 ;
-
 
2244
	    }
-
 
2245
	    if ( kind == KIND_BUILTIN ) {
-
 
2246
		/* Built-in resolution */
-
 
2247
		e = apply_builtin ( qid, args ) ;
2297
		DESTROY_CONS_exp(destroy, a, args, args);
2248
	    } else {
-
 
2249
		/* Function resolution */
-
 
2250
		use_func_id ( qid, 0, suppress_usage ) ;
-
 
2251
		e = apply_func_id ( qid, qual_none, NULL_graph, args ) ;
-
 
2252
	    }
-
 
2253
	    overload_warn = ow ;
-
 
2254
	    return ( e ) ;
-
 
2255
	}
2298
	}
2256
	DESTROY_CONS_exp ( destroy, a, args, args ) ;
-
 
2257
    }
-
 
2258
 
2299
 
2259
    /* Try operation again with increased overload depth */
2300
	/* Try operation again with increased overload depth */
2260
    overload_depth++ ;
2301
	overload_depth++;
2261
    e = make_func_exp ( a, args, 0 ) ;
2302
	e = make_func_exp(a, args, 0);
2262
    overload_depth-- ;
2303
	overload_depth--;
2263
    return ( e ) ;
2304
	return (e);
2264
}
2305
}
2265
 
2306
 
2266
 
2307
 
2267
#endif /* LANGUAGE_CPP */
2308
#endif /* LANGUAGE_CPP */