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

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

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

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

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

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

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

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

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

Subversion Repositories tendra.SVN

Rev

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

Rev 2 Rev 7
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2006 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
32
    		 Crown Copyright (c) 1997
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
Line 75... Line 105...
75
#include "xalloc.h"
105
#include "xalloc.h"
76
 
106
 
77
 
107
 
78
/*
108
/*
79
    CANDIDATE LIST
109
    CANDIDATE LIST
80
 
110
 
81
    This variable gives the main candidate list used in overload resolution.
111
    This variable gives the main candidate list used in overload resolution.
82
*/
112
*/
83
 
113
 
84
CANDIDATE_LIST candidates = { NULL, 0, 0, NULL, 0 } ;
114
CANDIDATE_LIST candidates = { NULL, 0, 0, NULL, 0 };
85
 
115
 
86
 
116
 
87
/*
117
/*
88
    ADD A CANDIDATE TO A LIST
118
    ADD A CANDIDATE TO A LIST
89
 
119
 
90
    This routine adds the candidate given by id, bid and kind to the
120
    This routine adds the candidate given by id, bid and kind to the
91
    candidate list p.
121
    candidate list p.
92
*/
122
*/
93
 
123
 
94
static void add_candidate
124
static void
95
    PROTO_N ( ( p, id, bid, kind ) )
-
 
96
    PROTO_T ( CANDIDATE_LIST *p X IDENTIFIER id X IDENTIFIER bid X int kind )
125
add_candidate(CANDIDATE_LIST *p, IDENTIFIER id, IDENTIFIER bid, int kind)
97
{
126
{
98
    CANDIDATE *q = p->elem ;
127
	CANDIDATE *q = p->elem;
99
    unsigned n = p->size ;
128
	unsigned n = p->size;
100
    unsigned m = p->max_size ;
129
	unsigned m = p->max_size;
101
    if ( n >= m ) {
130
	if (n >= m) {
102
	/* Increase size if necessary */
131
		/* Increase size if necessary */
103
	m += 200 ;
132
		m += 200;
104
	q = xrealloc_nof ( q, CANDIDATE, m ) ;
133
		q = xrealloc_nof(q, CANDIDATE, m);
105
	p->elem = q ;
134
		p->elem = q;
106
	p->max_size = m ;
135
		p->max_size = m;
107
    }
136
	}
108
    q [n].func = id ;
137
	q[n].func = id;
109
    q [n].base = bid ;
138
	q[n].base = bid;
110
    q [n].kind = kind ;
139
	q[n].kind = kind;
111
    q [n].rank = RANK_NONE ;
140
	q[n].rank = RANK_NONE;
112
    q [n].convs = NULL ;
141
	q[n].convs = NULL;
113
    q [n].cond = NULL_exp ;
142
	q[n].cond = NULL_exp;
114
    p->size = n + 1 ;
143
	p->size = n + 1;
115
    return ;
144
	return;
116
}
145
}
117
 
146
 
118
 
147
 
119
/*
148
/*
120
    ADD AN IDENTIFIER TO A CANDIDATE LIST
149
    ADD AN IDENTIFIER TO A CANDIDATE LIST
121
 
150
 
122
    This routine adds the overloaded function identifier id to the candidate
151
    This routine adds the overloaded function identifier id to the candidate
123
    list given by p.  The kind argument is stored in the kind field of each
152
    list given by p.  The kind argument is stored in the kind field of each
124
    candidate.  The table of candidate functions may need extending.  Note
153
    candidate.  The table of candidate functions may need extending.  Note
125
    that the candidates are added in the reverse order in which they were
154
    that the candidates are added in the reverse order in which they were
126
    declared.
155
    declared.
127
*/
156
*/
128
 
157
 
129
void add_candidates
158
void
130
    PROTO_N ( ( p, id, over, kind ) )
-
 
131
    PROTO_T ( CANDIDATE_LIST *p X IDENTIFIER id X int over X int kind )
159
add_candidates(CANDIDATE_LIST *p, IDENTIFIER id, int over, int kind)
132
{
160
{
133
    unsigned tag = TAG_id ( id ) ;
161
	unsigned tag = TAG_id(id);
134
    switch ( tag ) {
162
	switch (tag) {
135
	case id_function_tag :
163
	case id_function_tag:
136
	case id_mem_func_tag :
164
	case id_mem_func_tag:
137
	case id_stat_mem_func_tag : {
165
	case id_stat_mem_func_tag:
138
	    /* Functions */
166
		/* Functions */
139
	    while ( !IS_NULL_id ( id ) ) {
167
		while (!IS_NULL_id(id)) {
140
		IDENTIFIER bid = DEREF_id ( id_alias ( id ) ) ;
168
			IDENTIFIER bid = DEREF_id(id_alias(id));
141
		add_candidate ( p, id, bid, kind ) ;
169
			add_candidate(p, id, bid, kind);
142
		if ( !over ) break ;
170
			if (!over) {
-
 
171
				break;
-
 
172
			}
143
		id = DEREF_id ( id_function_etc_over ( id ) ) ;
173
			id = DEREF_id(id_function_etc_over(id));
144
	    }
174
		}
145
	    break ;
175
		break;
146
	}
-
 
147
	case id_builtin_tag : {
176
	case id_builtin_tag:
148
	    /* Built-in operators */
177
		/* Built-in operators */
149
	    add_candidate ( p, id, id, kind ) ;
178
		add_candidate(p, id, id, kind);
150
	    break ;
179
		break;
151
	}
-
 
152
	case id_ambig_tag : {
180
	case id_ambig_tag: {
153
	    /* Ambiguous functions */
181
		/* Ambiguous functions */
154
	    LIST ( IDENTIFIER ) r = DEREF_list ( id_ambig_ids ( id ) ) ;
182
		LIST(IDENTIFIER) r = DEREF_list(id_ambig_ids(id));
-
 
183
		if (over) {
155
	    if ( over ) over = DEREF_int ( id_ambig_over ( id ) ) ;
184
			over = DEREF_int(id_ambig_over(id));
-
 
185
		}
156
	    while ( !IS_NULL_list ( r ) ) {
186
		while (!IS_NULL_list(r)) {
157
		IDENTIFIER rid = DEREF_id ( HEAD_list ( r ) ) ;
187
			IDENTIFIER rid = DEREF_id(HEAD_list(r));
158
		add_candidates ( p, rid, over, kind ) ;
188
			add_candidates(p, rid, over, kind);
159
		r = TAIL_list ( r ) ;
189
			r = TAIL_list(r);
160
	    }
190
		}
161
	    break ;
191
		break;
162
	}
192
	}
163
    }
193
	}
164
    return ;
194
	return;
165
}
195
}
166
 
196
 
167
 
197
 
168
/*
198
/*
169
    LOOK UP A FUNCTION IN AN ARGUMENT NAMESPACE
199
    LOOK UP A FUNCTION IN AN ARGUMENT NAMESPACE
170
 
200
 
171
    This routine looks up the function id in the namespace containing the
201
    This routine looks up the function id in the namespace containing the
172
    type name cid.  Any functions found are added to the candidate list p.
202
    type name cid.  Any functions found are added to the candidate list p.
173
*/
203
*/
174
 
204
 
-
 
205
static IDENTIFIER
-
 
206
koenig_id(CANDIDATE_LIST *p, IDENTIFIER id, IDENTIFIER cid, int kind)
-
 
207
{
-
 
208
	if (!IS_NULL_id(cid)) {
-
 
209
		NAMESPACE cns = DEREF_nspace(id_parent(cid));
-
 
210
		if (!IS_NULL_nspace(cns)) {
-
 
211
			switch (TAG_nspace(cns)) {
-
 
212
			case nspace_named_tag:
-
 
213
			case nspace_unnamed_tag:
-
 
214
			case nspace_global_tag: {
-
 
215
				/* Look up identifier in parent class */
-
 
216
				HASHID nm = DEREF_hashid(id_name(id));
-
 
217
				MEMBER mem = search_member(cns, nm, 0);
-
 
218
				if (!IS_NULL_member(mem)) {
-
 
219
					IDENTIFIER fid =
-
 
220
					    DEREF_id(member_id(mem));
-
 
221
					if (!IS_NULL_id(fid) &&
-
 
222
					    !EQ_id(fid, id)) {
-
 
223
						add_candidates(p, fid, 1, kind);
-
 
224
						id = fid;
-
 
225
					}
-
 
226
				}
-
 
227
				break;
-
 
228
			}
-
 
229
			case nspace_ctype_tag: {
-
 
230
				/* Allow for nested classes */
-
 
231
				IDENTIFIER pid = DEREF_id(nspace_name(cns));
-
 
232
				id = koenig_id(p, id, pid, kind);
-
 
233
				break;
-
 
234
			}
-
 
235
			}
-
 
236
		}
-
 
237
	}
-
 
238
	return (id);
-
 
239
}
-
 
240
 
-
 
241
 
-
 
242
/*
-
 
243
    PERFORM ARGUMENT DEPENDENT NAME LOOK-UP FOR A CLASS
-
 
244
 
-
 
245
    This routine performs argument dependent name look-up for the function
-
 
246
    id and the argument class type ct.
-
 
247
*/
-
 
248
 
175
static IDENTIFIER koenig_id
249
static IDENTIFIER
-
 
250
koenig_class(CANDIDATE_LIST *p, IDENTIFIER id, CLASS_TYPE ct, int kind)
-
 
251
{
-
 
252
	TYPE form = DEREF_type(ctype_form(ct));
-
 
253
	if (IS_NULL_type(form)) {
-
 
254
		IDENTIFIER cid = DEREF_id(ctype_name(ct));
-
 
255
		GRAPH gr = DEREF_graph(ctype_base(ct));
-
 
256
		LIST(GRAPH) br = DEREF_list(graph_tails(gr));
176
    PROTO_N ( ( p, id, cid, kind ) )
257
		id = koenig_id(p, id, cid, kind);
-
 
258
		while (!IS_NULL_list(br)) {
-
 
259
			GRAPH gs = DEREF_graph(HEAD_list(br));
-
 
260
			CLASS_TYPE cs = DEREF_ctype(graph_head(gs));
-
 
261
			id = koenig_class(p, id, cs, kind);
-
 
262
			br = TAIL_list(br);
-
 
263
		}
-
 
264
	} else {
-
 
265
		id = koenig_candidates(p, id, form, kind);
-
 
266
	}
-
 
267
	return (id);
-
 
268
}
-
 
269
 
-
 
270
 
-
 
271
/*
-
 
272
    PERFORM ARGUMENT DEPENDENT NAME LOOK-UP FOR A TOKEN ARGUMENT
-
 
273
 
-
 
274
    This routine performs argument dependent name look-up for the function
-
 
275
    id and the token argument tok.
-
 
276
*/
-
 
277
 
-
 
278
static IDENTIFIER
177
    PROTO_T ( CANDIDATE_LIST *p X IDENTIFIER id X IDENTIFIER cid X int kind )
279
koenig_token(CANDIDATE_LIST *p, IDENTIFIER id, TOKEN tok, int kind)
-
 
280
{
-
 
281
	if (!IS_NULL_tok(tok)) {
-
 
282
		ASSERT(ORDER_tok == 10);
-
 
283
		switch (TAG_tok(tok)) {
-
 
284
		case tok_type_tag: {
-
 
285
			TYPE t = DEREF_type(tok_type_value(tok));
-
 
286
			id = koenig_candidates(p, id, t, kind);
-
 
287
			break;
-
 
288
		}
-
 
289
		case tok_class_tag: {
-
 
290
			IDENTIFIER tid = DEREF_id(tok_class_value(tok));
-
 
291
			id = koenig_id(p, id, tid, kind);
-
 
292
			break;
-
 
293
		}
-
 
294
		}
-
 
295
	}
-
 
296
	return (id);
-
 
297
}
-
 
298
 
-
 
299
 
-
 
300
/*
-
 
301
    PERFORM ARGUMENT DEPENDENT NAME LOOK-UP
-
 
302
 
-
 
303
    This routine performs argument dependent name look-up for the function
-
 
304
    id and the argument type t, adding any candidates found to the list p.
-
 
305
*/
-
 
306
 
-
 
307
IDENTIFIER
-
 
308
koenig_candidates(CANDIDATE_LIST *p, IDENTIFIER id, TYPE t, int kind)
178
{
309
{
179
    if ( !IS_NULL_id ( cid ) ) {
310
	if (!IS_NULL_type(t)) {
-
 
311
		ASSERT(ORDER_type == 18);
-
 
312
		switch (TAG_type(t)) {
-
 
313
		case type_ptr_tag:
-
 
314
		case type_ref_tag: {
180
	NAMESPACE cns = DEREF_nspace ( id_parent ( cid ) ) ;
315
			TYPE s = DEREF_type(type_ptr_etc_sub(t));
-
 
316
			id = koenig_candidates(p, id, s, kind);
-
 
317
			break;
-
 
318
		}
-
 
319
		case type_ptr_mem_tag: {
-
 
320
			CLASS_TYPE cs = DEREF_ctype(type_ptr_mem_of(t));
-
 
321
			TYPE s = DEREF_type(type_ptr_mem_sub(t));
-
 
322
			id = koenig_class(p, id, cs, kind);
-
 
323
			id = koenig_candidates(p, id, s, kind);
-
 
324
			break;
-
 
325
		}
-
 
326
		case type_func_tag: {
-
 
327
			TYPE r = DEREF_type(type_func_ret(t));
-
 
328
			LIST(TYPE) q = DEREF_list(type_func_ptypes(t));
-
 
329
			id = koenig_candidates(p, id, r, kind);
181
	if ( !IS_NULL_nspace ( cns ) ) {
330
			while (!IS_NULL_list(q)) {
182
	    switch ( TAG_nspace ( cns ) ) {
331
				TYPE s = DEREF_type(HEAD_list(q));
-
 
332
				id = koenig_candidates(p, id, s, kind);
-
 
333
				q = TAIL_list(q);
-
 
334
			}
-
 
335
			break;
-
 
336
		}
183
		case nspace_named_tag :
337
		case type_array_tag: {
-
 
338
			TYPE s = DEREF_type(type_array_sub(t));
-
 
339
			id = koenig_candidates(p, id, s, kind);
-
 
340
			break;
-
 
341
		}
184
		case nspace_unnamed_tag :
342
		case type_compound_tag: {
-
 
343
			CLASS_TYPE ct = DEREF_ctype(type_compound_defn(t));
-
 
344
			id = koenig_class(p, id, ct, kind);
-
 
345
			break;
-
 
346
		}
185
		case nspace_global_tag : {
347
		case type_enumerate_tag: {
186
		    /* Look up identifier in parent class */
348
			ENUM_TYPE et = DEREF_etype(type_enumerate_defn(t));
187
		    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
349
			IDENTIFIER eid = DEREF_id(etype_name(et));
-
 
350
			id = koenig_id(p, id, eid, kind);
-
 
351
			break;
-
 
352
		}
-
 
353
		case type_token_tag: {
188
		    MEMBER mem = search_member ( cns, nm, 0 ) ;
354
			IDENTIFIER tid = DEREF_id(type_token_tok(t));
-
 
355
			LIST(TOKEN) args = DEREF_list(type_token_args(t));
189
		    if ( !IS_NULL_member ( mem ) ) {
356
			if (IS_id_token(tid)) {
190
			IDENTIFIER fid = DEREF_id ( member_id ( mem ) ) ;
357
				tid = DEREF_id(id_token_alt(tid));
-
 
358
			}
191
			if ( !IS_NULL_id ( fid ) && !EQ_id ( fid, id ) ) {
359
			id = koenig_id(p, id, tid, kind);
-
 
360
			while (!IS_NULL_list(args)) {
-
 
361
				TOKEN arg = DEREF_tok(HEAD_list(args));
192
			    add_candidates ( p, fid, 1, kind ) ;
362
				id = koenig_token(p, id, arg, kind);
193
			    id = fid ;
363
				args = TAIL_list(args);
194
			}
364
			}
-
 
365
			break;
195
		    }
366
		}
-
 
367
		case type_templ_tag: {
-
 
368
			TYPE s = DEREF_type(type_templ_defn(t));
-
 
369
			id = koenig_candidates(p, id, s, kind);
196
		    break ;
370
			break;
197
		}
371
		}
198
		case nspace_ctype_tag : {
-
 
199
		    /* Allow for nested classes */
-
 
200
		    IDENTIFIER pid = DEREF_id ( nspace_name ( cns ) ) ;
-
 
201
		    id = koenig_id ( p, id, pid, kind ) ;
-
 
202
		    break ;
-
 
203
		}
372
		}
204
	    }
-
 
205
	}
373
	}
206
    }
-
 
207
    return ( id ) ;
374
	return (id);
208
}
-
 
209
 
-
 
210
 
-
 
211
/*
-
 
212
    PERFORM ARGUMENT DEPENDENT NAME LOOK-UP FOR A CLASS
-
 
213
 
-
 
214
    This routine performs argument dependent name look-up for the function
-
 
215
    id and the argument class type ct.
-
 
216
*/
-
 
217
 
-
 
218
static IDENTIFIER koenig_class
-
 
219
    PROTO_N ( ( p, id, ct, kind ) )
-
 
220
    PROTO_T ( CANDIDATE_LIST *p X IDENTIFIER id X CLASS_TYPE ct X int kind )
-
 
221
{
-
 
222
    TYPE form = DEREF_type ( ctype_form ( ct ) ) ;
-
 
223
    if ( IS_NULL_type ( form ) ) {
-
 
224
	IDENTIFIER cid = DEREF_id ( ctype_name ( ct ) ) ;
-
 
225
	GRAPH gr = DEREF_graph ( ctype_base ( ct ) ) ;
-
 
226
	LIST ( GRAPH ) br = DEREF_list ( graph_tails ( gr ) ) ;
-
 
227
	id = koenig_id ( p, id, cid, kind ) ;
-
 
228
	while ( !IS_NULL_list ( br ) ) {
-
 
229
	    GRAPH gs = DEREF_graph ( HEAD_list ( br ) ) ;
-
 
230
	    CLASS_TYPE cs = DEREF_ctype ( graph_head ( gs ) ) ;
-
 
231
	    id = koenig_class ( p, id, cs, kind ) ;
-
 
232
	    br = TAIL_list ( br ) ;
-
 
233
	}
-
 
234
    } else {
-
 
235
	id = koenig_candidates ( p, id, form, kind ) ;
-
 
236
    }
-
 
237
    return ( id ) ;
-
 
238
}
375
}
239
 
376
 
240
 
377
 
241
/*
378
/*
242
    PERFORM ARGUMENT DEPENDENT NAME LOOK-UP FOR A TOKEN ARGUMENT
-
 
243
 
-
 
244
    This routine performs argument dependent name look-up for the function
-
 
245
    id and the token argument tok.
-
 
246
*/
-
 
247
 
-
 
248
static IDENTIFIER koenig_token
-
 
249
    PROTO_N ( ( p, id, tok, kind ) )
-
 
250
    PROTO_T ( CANDIDATE_LIST *p X IDENTIFIER id X TOKEN tok X int kind )
-
 
251
{
-
 
252
    if ( !IS_NULL_tok ( tok ) ) {
-
 
253
	ASSERT ( ORDER_tok == 10 ) ;
-
 
254
	switch ( TAG_tok ( tok ) ) {
-
 
255
	    case tok_type_tag : {
-
 
256
		TYPE t = DEREF_type ( tok_type_value ( tok ) ) ;
-
 
257
		id = koenig_candidates ( p, id, t, kind ) ;
-
 
258
		break ;
-
 
259
	    }
-
 
260
	    case tok_class_tag : {
-
 
261
		IDENTIFIER tid = DEREF_id ( tok_class_value ( tok ) ) ;
-
 
262
		id = koenig_id ( p, id, tid, kind ) ;
-
 
263
		break ;
-
 
264
	    }
-
 
265
	}
-
 
266
    }
-
 
267
    return ( id ) ;
-
 
268
}
-
 
269
 
-
 
270
 
-
 
271
/*
-
 
272
    PERFORM ARGUMENT DEPENDENT NAME LOOK-UP
-
 
273
 
-
 
274
    This routine performs argument dependent name look-up for the function
-
 
275
    id and the argument type t, adding any candidates found to the list p.
-
 
276
*/
-
 
277
 
-
 
278
IDENTIFIER koenig_candidates
-
 
279
    PROTO_N ( ( p, id, t, kind ) )
-
 
280
    PROTO_T ( CANDIDATE_LIST *p X IDENTIFIER id X TYPE t X int kind )
-
 
281
{
-
 
282
    if ( !IS_NULL_type ( t ) ) {
-
 
283
	ASSERT ( ORDER_type == 18 ) ;
-
 
284
	switch ( TAG_type ( t ) ) {
-
 
285
	    case type_ptr_tag :
-
 
286
	    case type_ref_tag : {
-
 
287
		TYPE s = DEREF_type ( type_ptr_etc_sub ( t ) ) ;
-
 
288
		id = koenig_candidates ( p, id, s, kind ) ;
-
 
289
		break ;
-
 
290
	    }
-
 
291
	    case type_ptr_mem_tag : {
-
 
292
		CLASS_TYPE cs = DEREF_ctype ( type_ptr_mem_of ( t ) ) ;
-
 
293
		TYPE s = DEREF_type ( type_ptr_mem_sub ( t ) ) ;
-
 
294
		id = koenig_class ( p, id, cs, kind ) ;
-
 
295
		id = koenig_candidates ( p, id, s, kind ) ;
-
 
296
		break ;
-
 
297
	    }
-
 
298
	    case type_func_tag : {
-
 
299
		TYPE r = DEREF_type ( type_func_ret ( t ) ) ;
-
 
300
		LIST ( TYPE ) q = DEREF_list ( type_func_ptypes ( t ) ) ;
-
 
301
		id = koenig_candidates ( p, id, r, kind ) ;
-
 
302
		while ( !IS_NULL_list ( q ) ) {
-
 
303
		    TYPE s = DEREF_type ( HEAD_list ( q ) ) ;
-
 
304
		    id = koenig_candidates ( p, id, s, kind ) ;
-
 
305
		    q = TAIL_list ( q ) ;
-
 
306
		}
-
 
307
		break ;
-
 
308
	    }
-
 
309
	    case type_array_tag : {
-
 
310
		TYPE s = DEREF_type ( type_array_sub ( t ) ) ;
-
 
311
		id = koenig_candidates ( p, id, s, kind ) ;
-
 
312
		break ;
-
 
313
	    }
-
 
314
	    case type_compound_tag : {
-
 
315
		CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
-
 
316
		id = koenig_class ( p, id, ct, kind ) ;
-
 
317
		break ;
-
 
318
	    }
-
 
319
	    case type_enumerate_tag : {
-
 
320
		ENUM_TYPE et = DEREF_etype ( type_enumerate_defn ( t ) ) ;
-
 
321
		IDENTIFIER eid = DEREF_id ( etype_name ( et ) ) ;
-
 
322
		id = koenig_id ( p, id, eid, kind ) ;
-
 
323
		break ;
-
 
324
	    }
-
 
325
	    case type_token_tag : {
-
 
326
		IDENTIFIER tid = DEREF_id ( type_token_tok ( t ) ) ;
-
 
327
		LIST ( TOKEN ) args = DEREF_list ( type_token_args ( t ) ) ;
-
 
328
		if ( IS_id_token ( tid ) ) {
-
 
329
		    tid = DEREF_id ( id_token_alt ( tid ) ) ;
-
 
330
		}
-
 
331
		id = koenig_id ( p, id, tid, kind ) ;
-
 
332
		while ( !IS_NULL_list ( args ) ) {
-
 
333
		    TOKEN arg = DEREF_tok ( HEAD_list ( args ) ) ;
-
 
334
		    id = koenig_token ( p, id, arg, kind ) ;
-
 
335
		    args = TAIL_list ( args ) ;
-
 
336
		}
-
 
337
		break ;
-
 
338
	    }
-
 
339
	    case type_templ_tag : {
-
 
340
		TYPE s = DEREF_type ( type_templ_defn ( t ) ) ;
-
 
341
		id = koenig_candidates ( p, id, s, kind ) ;
-
 
342
		break ;
-
 
343
	    }
-
 
344
	}
-
 
345
    }
-
 
346
    return ( id ) ;
-
 
347
}
-
 
348
 
-
 
349
 
-
 
350
/*
-
 
351
    FREE A LIST OF CANDIDATES
379
    FREE A LIST OF CANDIDATES
352
 
380
 
353
    This routine frees the elements of the candidate list p.
381
    This routine frees the elements of the candidate list p.
354
*/
382
*/
355
 
383
 
356
void free_candidates
384
void
357
    PROTO_N ( ( p ) )
-
 
358
    PROTO_T ( CANDIDATE_LIST *p )
385
free_candidates(CANDIDATE_LIST *p)
359
{
386
{
360
    xfree_nof ( p->elem ) ;
387
	xfree_nof(p->elem);
361
    xfree_nof ( p->convs ) ;
388
	xfree_nof(p->convs);
362
    p->elem = NULL ;
389
	p->elem = NULL;
363
    p->size = 0 ;
390
	p->size = 0;
364
    p->max_size = 0 ;
391
	p->max_size = 0;
365
    p->convs = NULL ;
392
	p->convs = NULL;
366
    p->nconvs = 0 ;
393
	p->nconvs = 0;
367
    return ;
394
	return;
368
}
395
}
369
 
396
 
370
 
397
 
371
/*
398
/*
372
    SWAP PARAMETER TYPE FIELDS FOR A FUNCTION
399
    SWAP PARAMETER TYPE FIELDS FOR A FUNCTION
373
 
400
 
374
    Overload resolution is based on the mtypes field of the function type.
401
    Overload resolution is based on the mtypes field of the function type.
375
    This routine can be used to force resolution on the ptypes field by
402
    This routine can be used to force resolution on the ptypes field by
376
    swapping the two fields for the overloaded function identifier id.
403
    swapping the two fields for the overloaded function identifier id.
377
    Note that after overload resolution the fields should be swapped back.
404
    Note that after overload resolution the fields should be swapped back.
378
*/
405
*/
379
 
406
 
380
void swap_ptypes
407
void
381
    PROTO_N ( ( id ) )
-
 
382
    PROTO_T ( IDENTIFIER id )
408
swap_ptypes(IDENTIFIER id)
383
{
409
{
384
    LIST ( TYPE ) ptypes ;
410
	LIST(TYPE) ptypes;
385
    LIST ( TYPE ) mtypes ;
411
	LIST(TYPE) mtypes;
386
    TYPE fn = DEREF_type ( id_function_etc_type ( id ) ) ;
412
	TYPE fn = DEREF_type(id_function_etc_type(id));
387
    while ( IS_type_templ ( fn ) ) {
413
	while (IS_type_templ(fn)) {
388
	/* Allow for template functions */
414
		/* Allow for template functions */
389
	fn = DEREF_type ( type_templ_defn ( fn ) ) ;
415
		fn = DEREF_type(type_templ_defn(fn));
390
    }
416
	}
391
    ptypes = DEREF_list ( type_func_ptypes ( fn ) ) ;
417
	ptypes = DEREF_list(type_func_ptypes(fn));
392
    mtypes = DEREF_list ( type_func_mtypes ( fn ) ) ;
418
	mtypes = DEREF_list(type_func_mtypes(fn));
393
    if ( !EQ_list ( ptypes, mtypes ) ) {
419
	if (!EQ_list(ptypes, mtypes)) {
394
	COPY_list ( type_func_ptypes ( fn ), mtypes ) ;
420
		COPY_list(type_func_ptypes(fn), mtypes);
395
	COPY_list ( type_func_mtypes ( fn ), ptypes ) ;
421
		COPY_list(type_func_mtypes(fn), ptypes);
396
    }
422
	}
397
    return ;
423
	return;
398
}
424
}
399
 
425
 
400
 
426
 
401
/*
427
/*
402
    SWAP PARAMETER TYPE FIELDS FOR CANDIDATES FUNCTIONS
428
    SWAP PARAMETER TYPE FIELDS FOR CANDIDATES FUNCTIONS
403
 
429
 
404
    This routine swaps the parameter type fields for all the constructor
430
    This routine swaps the parameter type fields for all the constructor
405
    candidates in p, starting with the nth entry.
431
    candidates in p, starting with the nth entry.
406
*/
432
*/
407
 
433
 
408
void swap_candidates
434
void
409
    PROTO_N ( ( p, n ) )
-
 
410
    PROTO_T ( CANDIDATE_LIST *p X unsigned n )
435
swap_candidates(CANDIDATE_LIST *p, unsigned n)
411
{
436
{
412
    unsigned i, m = p->size ;
437
	unsigned i, m = p->size;
413
    for ( i = n ; i < m ; i++ ) {
438
	for (i = n; i < m; i++) {
414
	CANDIDATE *r = p->elem + i ;
439
		CANDIDATE *r = p->elem + i;
415
	if ( r->kind == KIND_CONSTR ) {
440
		if (r->kind == KIND_CONSTR) {
416
	    swap_ptypes ( r->base ) ;
441
			swap_ptypes(r->base);
417
	}
442
		}
418
    }
443
	}
419
    return ;
444
	return;
420
}
445
}
421
 
446
 
422
 
447
 
423
/*
448
/*
424
    LIST CANDIDATES FOR ERROR REPORTING
449
    LIST CANDIDATES FOR ERROR REPORTING
425
 
450
 
426
    This routine appends messages listing all the candidates from the list
451
    This routine appends messages listing all the candidates from the list
427
    p of rank at least rank to the end of the error message err.  No action
452
    p of rank at least rank to the end of the error message err.  No action
428
    is taken if err is the null error.
453
    is taken if err is the null error.
429
*/
454
*/
430
 
455
 
431
ERROR list_candidates
456
ERROR
432
    PROTO_N ( ( err, p, rank ) )
-
 
433
    PROTO_T ( ERROR err X CANDIDATE_LIST *p X unsigned rank )
457
list_candidates(ERROR err, CANDIDATE_LIST *p, unsigned rank)
434
{
458
{
435
    if ( !IS_NULL_err ( err ) ) {
459
	if (!IS_NULL_err(err)) {
436
	ERROR err2 = ERR_over_match_viable_list () ;
460
		ERROR err2 = ERR_over_match_viable_list();
437
	if ( !IS_NULL_err ( err2 ) ) {
461
		if (!IS_NULL_err(err2)) {
438
	    unsigned m = 0 ;
462
			unsigned m = 0;
439
	    CANDIDATE *q = p->elem ;
463
			CANDIDATE *q = p->elem;
440
	    unsigned n = p->size ;
464
			unsigned n = p->size;
441
	    err = concat_error ( err, err2 ) ;
465
			err = concat_error(err, err2);
442
	    while ( n ) {
466
			while (n) {
443
		CANDIDATE *r = q + ( --n ) ;
467
				CANDIDATE *r = q + (--n);
444
		if ( r->rank >= rank ) {
468
				if (r->rank >= rank) {
445
		    /* List viable candidates */
469
					/* List viable candidates */
446
		    IDENTIFIER bid = r->base ;
470
					IDENTIFIER bid = r->base;
-
 
471
					DECL_SPEC ds =
447
		    DECL_SPEC ds = DEREF_dspec ( id_storage ( bid ) ) ;
472
					    DEREF_dspec(id_storage(bid));
448
		    if ( !( ds & dspec_register ) ) {
473
					if (!(ds & dspec_register)) {
449
			IDENTIFIER id = r->func ;
474
						IDENTIFIER id = r->func;
450
			if ( IS_id_builtin ( id ) ) {
475
						if (IS_id_builtin(id)) {
451
			    /* Dump dummy built-in operators */
476
							/* Dump dummy built-in
-
 
477
							 * operators */
-
 
478
							if (do_dump) {
452
			    if ( do_dump ) dump_builtin ( id ) ;
479
								dump_builtin(id);
-
 
480
							}
-
 
481
						}
-
 
482
						m++;
-
 
483
						err2 = ERR_fail_list_item(m, id, id_loc(id));
-
 
484
						err = concat_error(err, err2);
-
 
485
						ds |= dspec_register;
-
 
486
						COPY_dspec(id_storage(bid), ds);
-
 
487
					}
-
 
488
				}
453
			}
489
			}
454
			m++ ;
-
 
455
			err2 = ERR_fail_list_item ( m, id, id_loc ( id ) ) ;
-
 
456
			err = concat_error ( err, err2 ) ;
-
 
457
			ds |= dspec_register ;
-
 
458
			COPY_dspec ( id_storage ( bid ), ds ) ;
-
 
459
		    }
-
 
460
		}
-
 
461
	    }
-
 
462
	    if ( m ) {
490
			if (m) {
463
		n = p->size ;
491
				n = p->size;
464
		while ( n ) {
492
				while (n) {
465
		    /* Clear marks */
493
					/* Clear marks */
466
		    CANDIDATE *r = q + ( --n ) ;
494
					CANDIDATE *r = q + (--n);
467
		    IDENTIFIER bid = r->base ;
495
					IDENTIFIER bid = r->base;
-
 
496
					DECL_SPEC ds =
468
		    DECL_SPEC ds = DEREF_dspec ( id_storage ( bid ) ) ;
497
					    DEREF_dspec(id_storage(bid));
469
		    if ( ds & dspec_register ) {
498
					if (ds & dspec_register) {
470
			ds &= ~dspec_register ;
499
						ds &= ~dspec_register;
471
			COPY_dspec ( id_storage ( bid ), ds ) ;
500
						COPY_dspec(id_storage(bid), ds);
472
		    }
501
					}
-
 
502
				}
-
 
503
			}
-
 
504
			err = concat_error(err, ERR_fail_list_end(m));
473
		}
505
		}
474
	    }
-
 
475
	    err = concat_error ( err, ERR_fail_list_end ( m ) ) ;
-
 
476
	}
506
	}
477
    }
-
 
478
    return ( err ) ;
507
	return (err);
479
}
508
}
480
 
509
 
481
 
510
 
482
/*
511
/*
483
    OVERLOAD MATCHING INFORMATION
512
    OVERLOAD MATCHING INFORMATION
Line 486... Line 515...
486
    resolution.  If match_no_args is nonzero it gives the number of
515
    resolution.  If match_no_args is nonzero it gives the number of
487
    candidates which take the right number of arguments, otherwise if it
516
    candidates which take the right number of arguments, otherwise if it
488
    is zero it indicates that either there are no such functions or there
517
    is zero it indicates that either there are no such functions or there
489
    is only one candidate.  Similarly match_no_viable gives the number of
518
    is only one candidate.  Similarly match_no_viable gives the number of
490
    viable candidates (counting viable templates twice).
519
    viable candidates (counting viable templates twice).
491
*/
520
*/
492
 
521
 
493
unsigned match_no_args = 0 ;
522
unsigned match_no_args = 0;
494
unsigned match_no_viable = 0 ;
523
unsigned match_no_viable = 0;
495
static unsigned viable_templates = 0 ;
524
static unsigned viable_templates = 0;
496
int resolved_kind = KIND_FUNC ;
525
int resolved_kind = KIND_FUNC;
497
 
526
 
498
 
527
 
499
/*
528
/*
500
    IS A CANDIDATE FUNCTION PLAUSIBLE?
529
    IS A CANDIDATE FUNCTION PLAUSIBLE?
501
 
530
 
502
    A candidate function is plausible for a list of arguments if it accepts
531
    A candidate function is plausible for a list of arguments if it accepts
503
    that number of arguments.  This routine tests whether the candidate r
532
    that number of arguments.  This routine tests whether the candidate r
504
    is plausible.  It returns the absolute difference between the number
533
    is plausible.  It returns the absolute difference between the number
505
    of arguments and the number of parameters (i.e. zero for a plausible
534
    of arguments and the number of parameters (i.e. zero for a plausible
506
    candidate).
535
    candidate).
507
*/
536
*/
508
 
537
 
509
static unsigned plausible_candidate
538
static unsigned
510
    PROTO_N ( ( r, nargs ) )
-
 
511
    PROTO_T ( CANDIDATE *r X unsigned nargs )
539
plausible_candidate(CANDIDATE *r, unsigned nargs)
512
{
540
{
513
    IDENTIFIER id = r->base ;
541
	IDENTIFIER id = r->base;
514
    if ( IS_id_builtin ( id ) ) {
542
	if (IS_id_builtin(id)) {
515
	/* Built-in candidates */
543
		/* Built-in candidates */
516
	LIST ( TYPE ) mtypes = DEREF_list ( id_builtin_ptypes ( id ) ) ;
544
		LIST(TYPE) mtypes = DEREF_list(id_builtin_ptypes(id));
517
	unsigned npars = LENGTH_list ( mtypes ) ;
545
		unsigned npars = LENGTH_list(mtypes);
518
	if ( nargs == npars ) {
546
		if (nargs == npars) {
519
	    /* Equal numbers of arguments and parameters */
547
			/* Equal numbers of arguments and parameters */
520
	    return ( 0 ) ;
548
			return (0);
521
	} else if ( nargs > npars ) {
549
		} else if (nargs > npars) {
522
	    /* More arguments than parameters */
550
			/* More arguments than parameters */
523
	    return ( nargs - npars ) ;
551
			return (nargs - npars);
524
	} else {
552
		} else {
525
	    /* Less arguments than parameters */
553
			/* Less arguments than parameters */
526
	    return ( npars - nargs ) ;
554
			return (npars - nargs);
527
	}
-
 
528
    } else {
-
 
529
	/* Function candidates */
-
 
530
	unsigned npars ;
-
 
531
	LIST ( TYPE ) mtypes ;
-
 
532
	TYPE fn = DEREF_type ( id_function_etc_type ( id ) ) ;
-
 
533
	while ( IS_type_templ ( fn ) ) {
-
 
534
	    /* Allow for template functions */
-
 
535
	    fn = DEREF_type ( type_templ_defn ( fn ) ) ;
-
 
536
	}
555
		}
537
	mtypes = DEREF_list ( type_func_mtypes ( fn ) ) ;
-
 
538
	npars = LENGTH_list ( mtypes ) ;
-
 
539
	if ( nargs == npars ) {
-
 
540
	    /* Equal numbers of arguments and parameters */
-
 
541
	    return ( 0 ) ;
-
 
542
	} else if ( nargs > npars ) {
-
 
543
	    /* More arguments than parameters */
-
 
544
	    int ell = DEREF_int ( type_func_ellipsis ( fn ) ) ;
-
 
545
	    if ( ell ) {
-
 
546
		/* Match with ellipsis */
-
 
547
		return ( 0 ) ;
-
 
548
	    }
-
 
549
	    return ( nargs - npars ) ;
-
 
550
	} else {
556
	} else {
-
 
557
		/* Function candidates */
-
 
558
		unsigned npars;
-
 
559
		LIST(TYPE) mtypes;
-
 
560
		TYPE fn = DEREF_type(id_function_etc_type(id));
-
 
561
		while (IS_type_templ(fn)) {
-
 
562
			/* Allow for template functions */
-
 
563
			fn = DEREF_type(type_templ_defn(fn));
-
 
564
		}
-
 
565
		mtypes = DEREF_list(type_func_mtypes(fn));
-
 
566
		npars = LENGTH_list(mtypes);
-
 
567
		if (nargs == npars) {
-
 
568
			/* Equal numbers of arguments and parameters */
-
 
569
			return (0);
-
 
570
		} else if (nargs > npars) {
-
 
571
			/* More arguments than parameters */
-
 
572
			int ell = DEREF_int(type_func_ellipsis(fn));
-
 
573
			if (ell) {
-
 
574
				/* Match with ellipsis */
-
 
575
				return (0);
-
 
576
			}
-
 
577
			return (nargs - npars);
-
 
578
		} else {
551
	    /* Less arguments than parameters */
579
			/* Less arguments than parameters */
552
	    unsigned margs = min_no_args ( fn ) ;
580
			unsigned margs = min_no_args(fn);
553
	    if ( nargs >= margs ) {
581
			if (nargs >= margs) {
554
		/* Match with default arguments */
582
				/* Match with default arguments */
555
		return ( 0 ) ;
583
				return (0);
556
	    }
584
			}
557
	    return ( margs - nargs ) ;
585
			return (margs - nargs);
-
 
586
		}
558
	}
587
	}
559
    }
-
 
560
    /* NOTREACHED */
588
	/* NOTREACHED */
561
}
589
}
562
 
590
 
563
 
591
 
564
/*
592
/*
565
    INHERITANCE MATCHING FLAG
593
    INHERITANCE MATCHING FLAG
566
 
594
 
567
    This flag may be set to true to make the match for the implicit
595
    This flag may be set to true to make the match for the implicit
568
    this parameter for an inherited function as good as a match for
596
    this parameter for an inherited function as good as a match for
569
    a non-inherited function from the point of view of function
597
    a non-inherited function from the point of view of function
570
    overloading.
598
    overloading.
571
*/
599
*/
572
 
600
 
573
int match_this = 0 ;
601
int match_this = 0;
574
 
602
 
575
 
603
 
576
/*
604
/*
577
    IS A PLAUSIBLE CANDIDATE FUNCTION VIABLE?
605
    IS A PLAUSIBLE CANDIDATE FUNCTION VIABLE?
578
 
606
 
579
    A plausible candidate function is viable for a list of arguments if
607
    A plausible candidate function is viable for a list of arguments if
580
    there is an implicit conversion sequence for each argument to the
608
    there is an implicit conversion sequence for each argument to the
581
    corresponding parameter type.  This routine tests whether the plausible
609
    corresponding parameter type.  This routine tests whether the plausible
582
    candidate r is viable, building up the corresponding list of conversions.
610
    candidate r is viable, building up the corresponding list of conversions.
583
    It returns the number of arguments for which a sequence exists, plus
611
    It returns the number of arguments for which a sequence exists, plus
584
    one.
612
    one.
730
 
770
 
731
 
771
 
732
/*
772
/*
733
    COMPARE TWO FUNCTIONS
773
    COMPARE TWO FUNCTIONS
734
 
774
 
735
    This routine compares the candidate functions rid and sid to determine
775
    This routine compares the candidate functions rid and sid to determine
736
    which is better under the template specialisation rules.  It returns
776
    which is better under the template specialisation rules.  It returns
737
    1 if rid is better than sid, 2 if sid is better than rid, and 0 otherwise.
777
    1 if rid is better than sid, 2 if sid is better than rid, and 0 otherwise.
738
*/
778
*/
739
 
779
 
740
static int compare_funcs
780
static int
741
    PROTO_N ( ( rid, sid ) )
-
 
742
    PROTO_T ( IDENTIFIER rid X IDENTIFIER sid )
781
compare_funcs(IDENTIFIER rid, IDENTIFIER sid)
743
{
782
{
744
    int res = 0 ;
783
	int res = 0;
745
    if ( EQ_id ( rid, sid ) ) {
784
	if (EQ_id(rid, sid)) {
746
	/* Select first if equal */
785
		/* Select first if equal */
747
	res = 1 ;
786
		res = 1;
748
    } else {
-
 
749
	if ( IS_NULL_id ( rid ) ) {
-
 
750
	    res = 2 ;
-
 
751
	} else if ( IS_NULL_id ( sid ) ) {
-
 
752
	    res = 1 ;
-
 
753
	} else {
787
	} else {
754
	    rid = find_template ( rid, 0 ) ;
-
 
755
	    sid = find_template ( sid, 0 ) ;
-
 
756
	    if ( !IS_NULL_id ( rid ) ) {
788
		if (IS_NULL_id(rid)) {
757
		if ( !IS_NULL_id ( sid ) ) {
789
			res = 2;
758
		    /* Both template functions */
790
		} else if (IS_NULL_id(sid)) {
759
		    res = compare_specs ( rid, sid ) ;
791
			res = 1;
760
		} else {
792
		} else {
-
 
793
			rid = find_template(rid, 0);
-
 
794
			sid = find_template(sid, 0);
-
 
795
			if (!IS_NULL_id(rid)) {
-
 
796
				if (!IS_NULL_id(sid)) {
-
 
797
					/* Both template functions */
-
 
798
					res = compare_specs(rid, sid);
-
 
799
				} else {
761
		    /* rid is a template function */
800
					/* rid is a template function */
762
		    res = 2 ;
801
					res = 2;
763
		}
802
				}
764
	    } else if ( !IS_NULL_id ( sid ) ) {
803
			} else if (!IS_NULL_id(sid)) {
765
		/* sid is a template function */
804
				/* sid is a template function */
766
		res = 1 ;
805
				res = 1;
767
	    }
806
			}
768
	}
807
		}
769
    }
808
	}
770
    return ( res ) ;
809
	return (res);
771
}
810
}
772
 
811
 
773
 
812
 
774
/*
813
/*
775
    COMPARE TWO CANDIDATE FUNCTIONS
814
    COMPARE TWO CANDIDATE FUNCTIONS
776
 
815
 
777
    This routine compares the candidate functions r and s for the argument
816
    This routine compares the candidate functions r and s for the argument
778
    list args and return type ret.  It returns 1 if r is better than s, 2 if
817
    list args and return type ret.  It returns 1 if r is better than s, 2 if
779
    s is better than r, and some other value otherwise.  Better in this
818
    s is better than r, and some other value otherwise.  Better in this
780
    sense means at least as good for all arguments, plus strictly better
819
    sense means at least as good for all arguments, plus strictly better
781
    in at least one argument or the return type.
820
    in at least one argument or the return type.
782
*/
821
*/
783
 
822
 
784
static int compare_candidates
823
static int
785
    PROTO_N ( ( r, s, args, ret ) )
-
 
786
    PROTO_T ( CANDIDATE *r X CANDIDATE *s X LIST ( EXP ) args X TYPE ret )
824
compare_candidates(CANDIDATE *r, CANDIDATE *s, LIST(EXP) args, TYPE ret)
787
{
825
{
788
    int res = 0 ;
826
	int res = 0;
789
    CONVERSION *cr = r->convs ;
827
	CONVERSION *cr = r->convs;
790
    CONVERSION *cs = s->convs ;
828
	CONVERSION *cs = s->convs;
791
 
829
 
792
    /* Compare each argument in turn */
830
	/* Compare each argument in turn */
793
    while ( !IS_NULL_list ( args ) ) {
831
	while (!IS_NULL_list(args)) {
794
	int cmp = compare_seq ( cr, cs ) ;
832
		int cmp = compare_seq(cr, cs);
795
	if ( cmp == 1 ) {
833
		if (cmp == 1) {
796
	    /* r better in this argument */
834
			/* r better in this argument */
797
	    if ( res == 2 ) return ( 0 ) ;
835
			if (res == 2) {
-
 
836
				return (0);
-
 
837
			}
798
	    res = 1 ;
838
			res = 1;
799
	} else if ( cmp == 2 ) {
839
		} else if (cmp == 2) {
800
	    /* s better in this argument */
840
			/* s better in this argument */
801
	    if ( res == 1 ) return ( 0 ) ;
841
			if (res == 1) {
-
 
842
				return (0);
-
 
843
			}
802
	    res = 2 ;
844
			res = 2;
803
	}
845
		}
804
	cr++ ;
846
		cr++;
805
	cs++ ;
847
		cs++;
806
	args = TAIL_list ( args ) ;
848
		args = TAIL_list(args);
807
    }
849
	}
808
 
850
 
809
    /* Tie breakers */
851
	/* Tie breakers */
810
    if ( res == 0 ) {
852
	if (res == 0) {
811
	res = compare_funcs ( r->base, s->base ) ;
853
		res = compare_funcs(r->base, s->base);
812
	if ( res == 0 && !IS_NULL_type ( ret ) ) {
854
		if (res == 0 && !IS_NULL_type(ret)) {
813
	    /* Resolve on return type */
855
			/* Resolve on return type */
814
	    res = compare_seq ( cr, cs ) ;
856
			res = compare_seq(cr, cs);
815
	}
857
		}
816
    }
858
	}
817
    return ( res ) ;
859
	return (res);
818
}
860
}
819
 
861
 
820
 
862
 
821
/*
863
/*
822
    OVERLOADED FUNCTION RESOLUTION
864
    OVERLOADED FUNCTION RESOLUTION
823
 
865
 
824
    This routine selects the best match from the list of overloaded function
866
    This routine selects the best match from the list of overloaded function
825
    given by p based on the argument list args and the return type ret (which
867
    given by p based on the argument list args and the return type ret (which
826
    may be the null type).  The list of candidate functions will not be empty.
868
    may be the null type).  The list of candidate functions will not be empty.
827
    If replay is true then the conversion sequences have already been
869
    If replay is true then the conversion sequences have already been
828
    calculated and only the final tournament to select the best viable
870
    calculated and only the final tournament to select the best viable
829
    candidate is necessary.
871
    candidate is necessary.
1004
		}
1059
		}
1005
	    }
-
 
1006
	}
1060
	}
1007
    } else {
-
 
1008
	/* No clear tournament winner */
-
 
1009
	if ( best->rank >= RANK_VIABLE ) best->rank = RANK_VIABLE ;
-
 
1010
    }
-
 
1011
    return ( best ) ;
1061
	return (best);
1012
}
1062
}
1013
 
1063
 
1014
 
1064
 
1015
/*
1065
/*
1016
    FIND A LIST OF POSSIBLE TYPE VALUES
1066
    FIND A LIST OF POSSIBLE TYPE VALUES
Line 1019... Line 1069...
1019
    target dependent type t or its promotion.  In the latter case prom
1069
    target dependent type t or its promotion.  In the latter case prom
1020
    is set to true.  If neither t or its promotion is target dependent
1070
    is set to true.  If neither t or its promotion is target dependent
1021
    then the empty list is returned.
1071
    then the empty list is returned.
1022
*/
1072
*/
1023
 
1073
 
1024
static LIST ( TYPE ) possible_types
1074
static LIST(TYPE)
1025
    PROTO_N ( ( t, prom ) )
-
 
1026
    PROTO_T ( TYPE t X int *prom )
1075
possible_types(TYPE t, int *prom)
1027
{
1076
{
1028
    LIST ( TYPE ) r = NULL_list ( TYPE ) ;
1077
	LIST(TYPE) r = NULL_list(TYPE);
1029
    switch ( TAG_type ( t ) ) {
1078
	switch (TAG_type(t)) {
1030
	case type_integer_tag : {
1079
	case type_integer_tag: {
1031
	    /* Integral type */
1080
		/* Integral type */
1032
	    INT_TYPE it = DEREF_itype ( type_integer_rep ( t ) ) ;
1081
		INT_TYPE it = DEREF_itype(type_integer_rep(t));
1033
	    r = DEREF_list ( itype_cases ( it ) ) ;
1082
		r = DEREF_list(itype_cases(it));
1034
	    if ( LENGTH_list ( r ) == 1 ) {
1083
		if (LENGTH_list(r) == 1) {
1035
		/* Type is not target dependent */
1084
			/* Type is not target dependent */
1036
		t = DEREF_type ( itype_prom ( it ) ) ;
1085
			t = DEREF_type(itype_prom(it));
1037
		it = DEREF_itype ( type_integer_rep ( t ) ) ;
1086
			it = DEREF_itype(type_integer_rep(t));
1038
		r = DEREF_list ( itype_cases ( it ) ) ;
1087
			r = DEREF_list(itype_cases(it));
1039
		if ( LENGTH_list ( r ) == 1 ) {
1088
			if (LENGTH_list(r) == 1) {
1040
		    /* Promoted type is not target dependent */
1089
				/* Promoted type is not target dependent */
1041
		    r = NULL_list ( TYPE ) ;
1090
				r = NULL_list(TYPE);
1042
		} else {
1091
			} else {
1043
		    *prom = 1 ;
1092
				*prom = 1;
-
 
1093
			}
1044
		}
1094
		}
-
 
1095
		break;
1045
	    }
1096
	}
-
 
1097
	case type_bitfield_tag:
-
 
1098
	case type_enumerate_tag:
-
 
1099
		/* Enumeration and bitfield types */
-
 
1100
		t = promote_type(t);
-
 
1101
		r = possible_types(t, prom);
-
 
1102
		*prom = 1;
1046
	    break ;
1103
		break;
1047
	}
1104
	}
1048
	case type_bitfield_tag :
-
 
1049
	case type_enumerate_tag : {
-
 
1050
	    /* Enumeration and bitfield types */
-
 
1051
	    t = promote_type ( t ) ;
-
 
1052
	    r = possible_types ( t, prom ) ;
-
 
1053
	    *prom = 1 ;
-
 
1054
	    break ;
-
 
1055
	}
-
 
1056
    }
-
 
1057
    return ( r ) ;
1105
	return (r);
1058
}
1106
}
1059
 
1107
 
1060
 
1108
 
1061
/*
1109
/*
1062
    CHECK FOR TARGET DEPENDENT OVERLOADED FUNCTION RESOLUTIONS
1110
    CHECK FOR TARGET DEPENDENT OVERLOADED FUNCTION RESOLUTIONS
Line 1064... Line 1112...
1064
    This routine is called when an ambiguous overload resolution is
1112
    This routine is called when an ambiguous overload resolution is
1065
    detected to determine which of the viable candidates to proceed with.
1113
    detected to determine which of the viable candidates to proceed with.
1066
    The parameters are as in resolve_overload.
1114
    The parameters are as in resolve_overload.
1067
*/
1115
*/
1068
 
1116
 
1069
CANDIDATE *resolve_ambiguous
1117
CANDIDATE *
1070
    PROTO_N ( ( p, args, ret, depth ) )
-
 
1071
    PROTO_T ( CANDIDATE_LIST *p X LIST ( EXP ) args X TYPE ret X int depth )
1118
resolve_ambiguous(CANDIDATE_LIST *p, LIST(EXP) args, TYPE ret, int depth)
1072
{
1119
{
1073
    CANDIDATE *q = p->elem ;
1120
    CANDIDATE *q = p->elem;
1074
    CANDIDATE *best = q ;
1121
    CANDIDATE *best = q;
1075
    unsigned i, n = p->size ;
1122
    unsigned i, n = p->size;
1076
    unsigned overall_rank = RANK_VIABLE ;
1123
    unsigned overall_rank = RANK_VIABLE;
1077
 
1124
 
1078
    /* Check for arguments of error type */
1125
    /* Check for arguments of error type */
1079
    if ( depth == 0 ) {
1126
    if (depth == 0) {
1080
	LIST ( EXP ) a = args ;
1127
	LIST(EXP) a = args;
1081
	while ( !IS_NULL_list ( a ) ) {
1128
	while (!IS_NULL_list(a)) {
1082
	    EXP e = DEREF_exp ( HEAD_list ( a ) ) ;
1129
	    EXP e = DEREF_exp(HEAD_list(a));
1083
	    if ( !IS_NULL_exp ( e ) ) {
1130
	    if (!IS_NULL_exp(e)) {
1084
		TYPE t = DEREF_type ( exp_type ( e ) ) ;
1131
		TYPE t = DEREF_type(exp_type(e));
1085
		if ( IS_type_error ( t ) ) {
1132
		if (IS_type_error(t)) {
1086
		    /* Error types are ignored */
1133
		    /* Error types are ignored */
1087
		    overall_rank = RANK_BEST ;
1134
		    overall_rank = RANK_BEST;
1088
		    break ;
1135
		    break;
1089
		}
1136
		}
1090
	    }
1137
	    }
1091
	    a = TAIL_list ( a ) ;
1138
	    a = TAIL_list(a);
1092
	}
1139
	}
1093
    }
1140
    }
1094
 
1141
 
1095
    /* Check for target dependent resolutions */
1142
    /* Check for target dependent resolutions */
1096
    if ( overall_rank != RANK_BEST ) {
1143
    if (overall_rank != RANK_BEST) {
1097
	unsigned na = 0 ;
1144
	unsigned na = 0;
1098
	LIST ( EXP ) a = args ;
1145
	LIST(EXP) a = args;
1099
	EXP saved [100] ;
1146
	EXP saved[100];
1100
	EXP *save = saved ;
1147
	EXP *save = saved;
-
 
1148
	if (n >= 100) {
1101
	if ( n >= 100 ) save = xmalloc_nof ( EXP, n ) ;
1149
		save = xmalloc_nof(EXP, n);
-
 
1150
	}
1102
	for ( i = 0 ; i < n ; i++ ) save [i] = NULL_exp ;
1151
	for (i = 0; i < n; i++)save[i] = NULL_exp;
1103
	while ( !IS_NULL_list ( a ) ) {
1152
	while (!IS_NULL_list(a)) {
1104
	    EXP e = DEREF_exp ( HEAD_list ( a ) ) ;
1153
	    EXP e = DEREF_exp(HEAD_list(a));
1105
	    if ( !IS_NULL_exp ( e ) ) {
1154
	    if (!IS_NULL_exp(e)) {
1106
		int prom = 0 ;
1155
		int prom = 0;
1107
		int have_match = 0 ;
1156
		int have_match = 0;
1108
		TYPE t = DEREF_type ( exp_type ( e ) ) ;
1157
		TYPE t = DEREF_type(exp_type(e));
1109
		LIST ( TYPE ) pt = possible_types ( t, &prom ) ;
1158
		LIST(TYPE) pt = possible_types(t, &prom);
1110
		if ( !IS_NULL_list ( pt ) ) {
1159
		if (!IS_NULL_list(pt)) {
1111
		    CANDIDATE *r ;
1160
		    CANDIDATE *r;
1112
		    LIST ( TYPE ) ps = pt ;
1161
		    LIST(TYPE) ps = pt;
1113
		    unsigned new_rank = RANK_TARGET ;
1162
		    unsigned new_rank = RANK_TARGET;
1114
		    if ( prom ) {
1163
		    if (prom) {
1115
			/* Only use promoted types if no exact match */
1164
			/* Only use promoted types if no exact match */
1116
			for ( i = 0 ; i < n ; i++ ) {
1165
			for (i = 0; i < n; i++) {
1117
			    r = q + i ;
1166
			    r = q + i;
1118
			    if ( r->rank >= RANK_VIABLE ) {
1167
			    if (r->rank >= RANK_VIABLE) {
1119
				if ( r->convs [ na ].rank == CONV_EXACT ) {
1168
				if (r->convs[na].rank == CONV_EXACT) {
1120
				    ps = NULL_list ( TYPE ) ;
1169
				    ps = NULL_list(TYPE);
1121
				    new_rank = overall_rank ;
1170
				    new_rank = overall_rank;
1122
				    break ;
1171
				    break;
1123
				}
1172
				}
1124
			    }
1173
			    }
1125
			}
1174
			}
1126
		    }
1175
		    }
1127
		    overall_rank = new_rank ;
1176
		    overall_rank = new_rank;
1128
		    while ( !IS_NULL_list ( ps ) ) {
1177
		    while (!IS_NULL_list(ps)) {
1129
			TYPE u = t ;
1178
			TYPE u = t;
1130
			TYPE s = DEREF_type ( HEAD_list ( ps ) ) ;
1179
			TYPE s = DEREF_type(HEAD_list(ps));
1131
			COPY_type ( exp_type ( e ), s ) ;
1180
			COPY_type(exp_type(e), s);
1132
			for ( i = 0 ; i < n ; i++ ) {
1181
			for (i = 0; i < n; i++) {
1133
			    r = q + i ;
1182
			    r = q + i;
1134
			    if ( r->rank >= RANK_VIABLE ) {
1183
			    if (r->rank >= RANK_VIABLE) {
1135
				/* Recalculate conversions */
1184
				/* Recalculate conversions */
1136
				r->convs [ na ].rank = CONV_NONE ;
1185
				r->convs[na].rank = CONV_NONE;
1137
				IGNORE viable_candidate ( r, args, ret ) ;
1186
				IGNORE viable_candidate(r, args, ret);
1138
				r->rank = RANK_VIABLE ;
1187
				r->rank = RANK_VIABLE;
1139
			    }
1188
			    }
1140
			}
1189
			}
1141
			r = resolve_overload ( p, args, ret, 1 ) ;
1190
			r = resolve_overload(p, args, ret, 1);
1142
			if ( r->rank == RANK_VIABLE ) {
1191
			if (r->rank == RANK_VIABLE) {
1143
			    /* Check further arguments */
1192
			    /* Check further arguments */
1144
			    for ( i = 0 ; i < n ; i++ ) {
1193
			    for (i = 0; i < n; i++) {
1145
				/* Save conditions */
1194
				/* Save conditions */
1146
				save [i] = q [i].cond ;
1195
				save[i] = q[i].cond;
1147
				q [i].cond = NULL_exp ;
1196
				q[i].cond = NULL_exp;
1148
			    }
1197
			    }
1149
			    r = resolve_ambiguous ( p, args, ret, 1 ) ;
1198
			    r = resolve_ambiguous(p, args, ret, 1);
1150
			    for ( i = 0 ; i < n ; i++ ) {
1199
			    for (i = 0; i < n; i++) {
1151
				/* Restore conditions */
1200
				/* Restore conditions */
1152
				EXP c = q [i].cond ;
1201
				EXP c = q[i].cond;
1153
				q [i].cond = save [i] ;
1202
				q[i].cond = save[i];
1154
				save [i] = c ;
1203
				save[i] = c;
1155
			    }
1204
			    }
1156
			}
1205
			}
1157
			COPY_type ( exp_type ( e ), t ) ;
1206
			COPY_type(exp_type(e), t);
1158
			if ( r->rank >= RANK_TARGET ) {
1207
			if (r->rank >= RANK_TARGET) {
1159
			    /* Create condition for resolution */
1208
			    /* Create condition for resolution */
-
 
1209
			    if (prom) {
1160
			    if ( prom ) u = promote_type ( u ) ;
1210
				    u = promote_type(u);
-
 
1211
			    }
1161
			    for ( i = 0 ; i < n ; i++ ) {
1212
			    for (i = 0; i < n; i++) {
1162
				r = q + i ;
1213
				r = q + i;
1163
				if ( r->rank >= RANK_TARGET ) {
1214
				if (r->rank >= RANK_TARGET) {
1164
				    EXP c1, c2 ;
1215
				    EXP c1, c2;
1165
				    TYPE ti = type_sint ;
1216
				    TYPE ti = type_sint;
1166
				    TYPE tb = type_bool ;
1217
				    TYPE tb = type_bool;
1167
				    NTEST nt = ntest_eq ;
1218
				    NTEST nt = ntest_eq;
1168
				    MAKE_exp_rtti_no ( ti, u, c1 ) ;
1219
				    MAKE_exp_rtti_no(ti, u, c1);
1169
				    MAKE_exp_rtti_no ( ti, s, c2 ) ;
1220
				    MAKE_exp_rtti_no(ti, s, c2);
1170
				    MAKE_exp_compare ( tb, nt, c1, c2, c1 ) ;
1221
				    MAKE_exp_compare(tb, nt, c1, c2, c1);
1171
				    c2 = save [i] ;
1222
				    c2 = save[i];
1172
				    if ( !IS_NULL_exp ( c2 ) ) {
1223
				    if (!IS_NULL_exp(c2)) {
1173
					MAKE_exp_log_and ( tb, c1, c2, c1 ) ;
1224
					MAKE_exp_log_and(tb, c1, c2, c1);
1174
				    }
-
 
1175
				    c2 = r->cond ;
-
 
1176
				    if ( !IS_NULL_exp ( c2 ) ) {
-
 
1177
					MAKE_exp_log_or ( tb, c1, c2, c1 ) ;
-
 
1178
				    }
1225
				    }
-
 
1226
				    c2 = r->cond;
-
 
1227
				    if (!IS_NULL_exp(c2)) {
-
 
1228
					MAKE_exp_log_or(tb, c1, c2, c1);
-
 
1229
				    }
1179
				    r->cond = c1 ;
1230
				    r->cond = c1;
1180
				    have_match = 1 ;
1231
				    have_match = 1;
1181
				}
1232
				}
1182
				save [i] = NULL_exp ;
1233
				save[i] = NULL_exp;
1183
			    }
1234
			    }
1184
			} else if ( option ( OPT_overload_strict ) ) {
1235
			} else if (option(OPT_overload_strict)) {
1185
			    /* Don't have match in all cases */
1236
			    /* Don't have match in all cases */
1186
			    have_match = 0 ;
1237
			    have_match = 0;
1187
			    break ;
1238
			    break;
1188
			}
1239
			}
1189
			ps = TAIL_list ( ps ) ;
1240
			ps = TAIL_list(ps);
1190
		    }
1241
		    }
1191
		    if ( !have_match ) {
1242
		    if (!have_match) {
1192
			overall_rank = RANK_VIABLE ;
1243
			overall_rank = RANK_VIABLE;
1193
			break ;
1244
			break;
1194
		    }
1245
		    }
1195
		}
1246
		}
1196
	    }
1247
	    }
1197
	    a = TAIL_list ( a ) ;
1248
	    a = TAIL_list(a);
1198
	    na++ ;
1249
	    na++;
-
 
1250
	}
-
 
1251
	if (save != saved) {
-
 
1252
		xfree_nof(save);
1199
	}
1253
	}
1200
	if ( save != saved ) xfree_nof ( save ) ;
-
 
1201
    }
1254
    }
1202
 
1255
 
1203
    /* Select last viable candidate */
1256
    /* Select last viable candidate */
1204
    for ( i = 0 ; i < n ; i++ ) {
1257
    for (i = 0; i < n; i++) {
1205
	CANDIDATE *r = q + i ;
1258
	CANDIDATE *r = q + i;
1206
	if ( r->rank >= RANK_VIABLE ) {
1259
	if (r->rank >= RANK_VIABLE) {
1207
	    if ( overall_rank == RANK_TARGET ) {
1260
	    if (overall_rank == RANK_TARGET) {
1208
		if ( IS_NULL_exp ( r->cond ) ) {
1261
		if (IS_NULL_exp(r->cond)) {
1209
		    if ( depth == 0 ) r->rank = RANK_ARGS ;
1262
		    if (depth == 0)r->rank = RANK_ARGS;
1210
		} else {
1263
		} else {
1211
		    r->rank = overall_rank ;
1264
		    r->rank = overall_rank;
1212
		    best = r ;
1265
		    best = r;
1213
		}
1266
		}
1214
	    } else {
1267
	    } else {
1215
		r->rank = overall_rank ;
1268
		r->rank = overall_rank;
1216
		best = r ;
1269
		best = r;
1217
	    }
1270
	    }
1218
	}
1271
	}
1219
    }
1272
    }
1220
    return ( best ) ;
1273
    return (best);
1221
}
1274
}
1222
 
1275
 
1223
 
1276
 
1224
/*
1277
/*
1225
    LIST OF ALL AMBIGUOUS OVERLOADED FUNCTIONS
1278
    LIST OF ALL AMBIGUOUS OVERLOADED FUNCTIONS
1226
 
1279
 
1227
    This list is used to hold all the dummy tokenised functions constructed
1280
    This list is used to hold all the dummy tokenised functions constructed
1228
    to represent target dependent overload resolutions.  The functions are
1281
    to represent target dependent overload resolutions.  The functions are
1229
    determined by the list of candidates, the list of argument types and
1282
    determined by the list of candidates, the list of argument types and
1230
    the qualifier used.
1283
    the qualifier used.
1231
*/
1284
*/
1232
 
1285
 
1233
typedef struct ambig_func_tag {
1286
typedef struct ambig_func_tag {
1234
    IDENTIFIER id ;
1287
	IDENTIFIER id;
1235
    LIST ( IDENTIFIER ) funcs ;
1288
	LIST(IDENTIFIER) funcs;
1236
    LIST ( TYPE ) types ;
1289
	LIST(TYPE) types;
1237
    QUALIFIER qual ;
1290
	QUALIFIER qual;
1238
    struct ambig_func_tag *next ;
1291
	struct ambig_func_tag *next;
1239
} AMBIG_FUNCTION ;
1292
} AMBIG_FUNCTION;
1240
 
1293
 
1241
static AMBIG_FUNCTION *all_ambig_funcs = NULL ;
1294
static AMBIG_FUNCTION *all_ambig_funcs = NULL;
1242
 
1295
 
1243
 
1296
 
1244
/*
1297
/*
1245
    FIND A PREVIOUS AMBIGUOUS OVERLOADED FUNCTION
1298
    FIND A PREVIOUS AMBIGUOUS OVERLOADED FUNCTION
1246
 
1299
 
1247
    This routine searches the list of all ambiguous overloaded functions
1300
    This routine searches the list of all ambiguous overloaded functions
1248
    for one which candidate functions p, argument types q and qualifier
1301
    for one which candidate functions p, argument types q and qualifier
1249
    qual.
1302
    qual.
1250
*/
1303
*/
1251
 
1304
 
1252
static IDENTIFIER previous_ambig_func
1305
static IDENTIFIER
1253
    PROTO_N ( ( p, q, qual ) )
-
 
1254
    PROTO_T ( LIST ( IDENTIFIER ) p X LIST ( TYPE ) q X QUALIFIER qual )
1306
previous_ambig_func(LIST(IDENTIFIER) p, LIST(TYPE) q, QUALIFIER qual)
1255
{
1307
{
1256
    AMBIG_FUNCTION *f = all_ambig_funcs ;
1308
	AMBIG_FUNCTION *f = all_ambig_funcs;
1257
    if ( f ) {
1309
	if (f) {
1258
	unsigned np = LENGTH_list ( p ) ;
1310
		unsigned np = LENGTH_list(p);
1259
	unsigned nq = LENGTH_list ( q ) ;
1311
		unsigned nq = LENGTH_list(q);
1260
	while ( f != NULL ) {
1312
		while (f != NULL) {
1261
	    if ( f->qual == qual ) {
1313
			if (f->qual == qual) {
1262
		int ok = 1 ;
1314
				int ok = 1;
1263
		LIST ( IDENTIFIER ) pf = f->funcs ;
1315
				LIST(IDENTIFIER) pf = f->funcs;
1264
		LIST ( TYPE ) qf = f->types ;
1316
				LIST(TYPE) qf = f->types;
1265
		if ( LENGTH_list ( pf ) == np ) {
1317
				if (LENGTH_list(pf) == np) {
1266
		    LIST ( IDENTIFIER ) pg = p ;
1318
					LIST(IDENTIFIER) pg = p;
1267
		    while ( !IS_NULL_list ( pg ) ) {
1319
					while (!IS_NULL_list(pg)) {
-
 
1320
						IDENTIFIER nf =
1268
			IDENTIFIER nf = DEREF_id ( HEAD_list ( pf ) ) ;
1321
						    DEREF_id(HEAD_list(pf));
-
 
1322
						IDENTIFIER ng =
1269
			IDENTIFIER ng = DEREF_id ( HEAD_list ( pg ) ) ;
1323
						    DEREF_id(HEAD_list(pg));
1270
			if ( !EQ_id ( nf, ng ) ) {
1324
						if (!EQ_id(nf, ng)) {
1271
			    ok = 0 ;
1325
							ok = 0;
1272
			    break ;
1326
							break;
1273
			}
1327
						}
1274
			pf = TAIL_list ( pf ) ;
1328
						pf = TAIL_list(pf);
1275
			pg = TAIL_list ( pg ) ;
1329
						pg = TAIL_list(pg);
1276
		    }
1330
					}
1277
		}
1331
				}
1278
		if ( ok && LENGTH_list ( qf ) == nq ) {
1332
				if (ok && LENGTH_list(qf) == nq) {
1279
		    LIST ( TYPE ) qg = q ;
1333
					LIST(TYPE) qg = q;
1280
		    while ( !IS_NULL_list ( qg ) ) {
1334
					while (!IS_NULL_list(qg)) {
-
 
1335
						TYPE tf =
1281
			TYPE tf = DEREF_type ( HEAD_list ( qf ) ) ;
1336
						    DEREF_type(HEAD_list(qf));
-
 
1337
						TYPE tg =
1282
			TYPE tg = DEREF_type ( HEAD_list ( qg ) ) ;
1338
						    DEREF_type(HEAD_list(qg));
1283
			if ( !eq_type ( tf, tg ) ) {
1339
						if (!eq_type(tf, tg)) {
1284
			    ok = 0 ;
1340
							ok = 0;
1285
			    break ;
1341
							break;
-
 
1342
						}
-
 
1343
						qf = TAIL_list(qf);
-
 
1344
						qg = TAIL_list(qg);
-
 
1345
					}
-
 
1346
				}
-
 
1347
				if (ok) {
-
 
1348
					return (f->id);
-
 
1349
				}
1286
			}
1350
			}
1287
			qf = TAIL_list ( qf ) ;
1351
			f = f->next;
1288
			qg = TAIL_list ( qg ) ;
-
 
1289
		    }
-
 
1290
		}
1352
		}
1291
		if ( ok ) return ( f->id ) ;
-
 
1292
	    }
-
 
1293
	    f = f->next ;
-
 
1294
	}
1353
	}
1295
    }
-
 
1296
    return ( NULL_id ) ;
1354
	return (NULL_id);
1297
}
1355
}
1298
 
1356
 
1299
 
1357
 
1300
/*
1358
/*
1301
    CONSTRUCT AN AMBIGUOUS OVERLOADED FUNCTION
1359
    CONSTRUCT AN AMBIGUOUS OVERLOADED FUNCTION
1302
 
1360
 
1303
    This routine constructs a dummy tokenised function to represent the
1361
    This routine constructs a dummy tokenised function to represent the
1304
    target dependent overload resolution given by the candidates p for
1362
    target dependent overload resolution given by the candidates p for
1305
    the function call 'id ( args )' detected by the previous call to
1363
    the function call 'id ( args )' detected by the previous call to
1306
    resolve_ambiguous.  Any errors arising are added to err.
1364
    resolve_ambiguous.  Any errors arising are added to err.
1307
*/
1365
*/
1308
 
1366
 
1309
IDENTIFIER make_ambig_func
1367
IDENTIFIER
1310
    PROTO_N ( ( p, id, args, qual, err ) )
-
 
1311
    PROTO_T ( CANDIDATE_LIST *p X IDENTIFIER id X LIST ( EXP ) args X
1368
make_ambig_func(CANDIDATE_LIST *p, IDENTIFIER id, LIST(EXP) args,
1312
	      QUALIFIER qual X ERROR *err )
1369
		QUALIFIER qual, ERROR *err)
1313
{
1370
{
1314
    EXP res ;
1371
	EXP res;
1315
    TYPE fn ;
1372
	TYPE fn;
1316
    TOKEN tok ;
1373
	TOKEN tok;
1317
    TYPE form ;
1374
	TYPE form;
1318
    MEMBER mem ;
1375
	MEMBER mem;
1319
    DECL_SPEC ds ;
1376
	DECL_SPEC ds;
1320
    IDENTIFIER tid ;
1377
	IDENTIFIER tid;
1321
    LIST ( TYPE ) mt ;
1378
	LIST(TYPE) mt;
1322
    AMBIG_FUNCTION *all ;
1379
	AMBIG_FUNCTION *all;
1323
    TYPE ret = NULL_type ;
1380
	TYPE ret = NULL_type;
1324
    TYPE et = type_error ;
1381
	TYPE et = type_error;
1325
    CANDIDATE *q = p->elem ;
1382
	CANDIDATE *q = p->elem;
1326
    unsigned i, n = p->size ;
1383
	unsigned i, n = p->size;
1327
    NAMESPACE ns = crt_namespace ;
1384
	NAMESPACE ns = crt_namespace;
1328
    QUALIFIER cq = crt_id_qualifier ;
1385
	QUALIFIER cq = crt_id_qualifier;
1329
    int tq = crt_templ_qualifier ;
1386
	int tq = crt_templ_qualifier;
1330
    int td = have_type_declaration ;
1387
	int td = have_type_declaration;
1331
    unsigned tag = id_function_tag ;
1388
	unsigned tag = id_function_tag;
1332
    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
1389
	HASHID nm = DEREF_hashid(id_name(id));
-
 
1390
 
-
 
1391
	/* List of viable candidates */
-
 
1392
	LIST(EXP) conds = NULL_list(EXP);
-
 
1393
	LIST(TYPE) types = NULL_list(TYPE);
-
 
1394
	LIST(IDENTIFIER) funcs = NULL_list(IDENTIFIER);
-
 
1395
 
-
 
1396
	/* Check function return types */
-
 
1397
	for (i = 0; i < n; i++) {
-
 
1398
		CANDIDATE *r = q + i;
-
 
1399
		if (r->rank >= RANK_VIABLE) {
-
 
1400
			int suspect = 0;
-
 
1401
			TYPE ta = NULL_type;
-
 
1402
			IDENTIFIER fid = r->base;
-
 
1403
			switch (TAG_id(fid)) {
-
 
1404
			case id_builtin_tag: {
-
 
1405
				ta = DEREF_type(id_builtin_ret(fid));
-
 
1406
				break;
-
 
1407
			}
-
 
1408
			case id_function_tag: {
-
 
1409
				TYPE fa = DEREF_type(id_function_type(fid));
-
 
1410
				if (IS_type_func(fa)) {
-
 
1411
					ta = DEREF_type(type_func_ret(fa));
-
 
1412
				}
-
 
1413
				break;
-
 
1414
			}
-
 
1415
			case id_mem_func_tag: {
-
 
1416
				TYPE fa = DEREF_type(id_mem_func_type(fid));
-
 
1417
				if (IS_type_func(fa)) {
-
 
1418
					HASHID fnm = DEREF_hashid(id_name(fid));
-
 
1419
					mt = DEREF_list(type_func_mtypes(fa));
-
 
1420
					et = DEREF_type(HEAD_list(mt));
-
 
1421
					if (IS_hashid_constr(fnm)) {
-
 
1422
						ta = DEREF_type(hashid_constr_type(fnm));
-
 
1423
					} else {
-
 
1424
						ta = DEREF_type(type_func_ret(fa));
-
 
1425
						tag = id_mem_func_tag;
-
 
1426
					}
-
 
1427
				}
-
 
1428
				break;
-
 
1429
			}
-
 
1430
			case id_stat_mem_func_tag: {
-
 
1431
				TYPE fa =
-
 
1432
				    DEREF_type(id_stat_mem_func_type(fid));
-
 
1433
				if (IS_type_func(fa)) {
-
 
1434
					mt = DEREF_list(type_func_mtypes(fa));
-
 
1435
					et = DEREF_type(HEAD_list(mt));
-
 
1436
					ta = DEREF_type(type_func_ret(fa));
-
 
1437
					if (tag != id_mem_func_tag) {
-
 
1438
						tag = id_stat_mem_func_tag;
-
 
1439
					}
-
 
1440
				}
-
 
1441
				break;
-
 
1442
			}
-
 
1443
			}
-
 
1444
			ret = common_type(ret, ta, &suspect);
-
 
1445
			if (suspect) {
-
 
1446
				ret = NULL_type;
-
 
1447
			}
-
 
1448
			CONS_exp(r->cond, conds, conds);
-
 
1449
			CONS_id(fid, funcs, funcs);
-
 
1450
		}
-
 
1451
	}
-
 
1452
	if (IS_NULL_type(ret)) {
-
 
1453
		/* Couldn't bring return types to common type */
-
 
1454
		ERROR err2 = ERR_over_match_best_common();
-
 
1455
		add_error(err, err2);
-
 
1456
		ret = type_error;
-
 
1457
	}
-
 
1458
	if (err != KILL_err) {
-
 
1459
		*err = list_candidates(*err, p, RANK_VIABLE);
-
 
1460
	}
-
 
1461
 
-
 
1462
	/* Create list of argument types */
-
 
1463
	while (!IS_NULL_list(args)) {
-
 
1464
		TYPE t;
-
 
1465
		EXP e = DEREF_exp(HEAD_list(args));
-
 
1466
		if (IS_NULL_exp(e)) {
-
 
1467
			t = et;
-
 
1468
			et = type_error;
-
 
1469
		} else {
-
 
1470
			t = DEREF_type(exp_type(e));
-
 
1471
			if (IS_type_bitfield(t)) {
-
 
1472
				t = promote_type(t);
-
 
1473
			} else {
-
 
1474
				CV_SPEC cv = DEREF_cv(type_qual(t));
-
 
1475
				if (cv & cv_lvalue) {
-
 
1476
					MAKE_type_ref(cv_none, t, t);
-
 
1477
				}
-
 
1478
			}
-
 
1479
		}
-
 
1480
		CONS_type(t, types, types);
-
 
1481
		args = TAIL_list(args);
-
 
1482
	}
-
 
1483
	types = REVERSE_list(types);
-
 
1484
 
-
 
1485
	/* Check for previous instance */
-
 
1486
	tid = previous_ambig_func(funcs, types, qual);
-
 
1487
	if (!IS_NULL_id(tid)) {
-
 
1488
		DESTROY_list(funcs, SIZE_id);
-
 
1489
		DESTROY_list(types, SIZE_type);
-
 
1490
		free_exp_list(conds, 1);
-
 
1491
		return (tid);
-
 
1492
	}
-
 
1493
 
-
 
1494
	/* Create new instance */
-
 
1495
	all = xmalloc_one(AMBIG_FUNCTION);
-
 
1496
	all->id = NULL_id;
-
 
1497
	all->funcs = funcs;
-
 
1498
	all->types = types;
-
 
1499
	all->qual = qual;
-
 
1500
	all->next = all_ambig_funcs;
-
 
1501
	all_ambig_funcs = all;
-
 
1502
 
-
 
1503
	/* Scan through argument types */
-
 
1504
	crt_id_qualifier = qual_none;
-
 
1505
	crt_templ_qualifier = 0;
-
 
1506
	have_type_declaration = TYPE_DECL_NONE;
-
 
1507
	decl_loc = crt_loc;
-
 
1508
	begin_param(id);
-
 
1509
	mt = types;
-
 
1510
	while (!IS_NULL_list(mt)) {
-
 
1511
		HASHID pnm = lookup_anon();
-
 
1512
		IDENTIFIER pid = DEREF_id(hashid_id(pnm));
-
 
1513
		TYPE t = DEREF_type(HEAD_list(mt));
-
 
1514
		pid = make_param_decl(dspec_none, t, pid, CONTEXT_PARAMETER);
-
 
1515
		init_param(pid, NULL_exp);
-
 
1516
		mt = TAIL_list(mt);
-
 
1517
	}
-
 
1518
	fn = make_func_type(ret, FUNC_NONE, cv_none, empty_type_set);
-
 
1519
	if (tag != id_function_tag) {
-
 
1520
		mt = DEREF_list(type_func_ptypes(fn));
-
 
1521
		mt = TAIL_list(mt);
-
 
1522
		COPY_list(type_func_ptypes(fn), mt);
-
 
1523
	}
-
 
1524
	end_param();
-
 
1525
 
-
 
1526
	/* Create a function identifier */
-
 
1527
	ds = (dspec_static | dspec_token | dspec_reserve);
-
 
1528
	MAKE_id_function_etc(tag, nm, ds, ns, crt_loc, fn, NULL_id, id);
1333
 
1529
 
1334
    /* List of viable candidates */
1530
	/* Create token identifier */
-
 
1531
	ns = token_namespace;
-
 
1532
	nm = lookup_anon();
1335
    LIST ( EXP ) conds = NULL_list ( EXP ) ;
1533
	mem = search_member(ns, nm, 1);
-
 
1534
	MAKE_tok_func(fn, tok);
1336
    LIST ( TYPE ) types = NULL_list ( TYPE ) ;
1535
	MAKE_id_token(nm, ds, ns, crt_loc, tok, id, tid);
1337
    LIST ( IDENTIFIER ) funcs = NULL_list ( IDENTIFIER ) ;
1536
	MAKE_type_token(cv_none, tid, NULL_list(TOKEN), form);
-
 
1537
	COPY_type(id_function_etc_form(id), form);
-
 
1538
	set_member(mem, tid);
-
 
1539
	tok = func_proc_token(tok);
1338
 
1540
 
1339
    /* Check function return types */
1541
	/* Define token */
-
 
1542
	res = install_error(&crt_loc, ERR_over_match_best_install());
1340
    for ( i = 0 ; i < n ; i++ ) {
1543
	while (!IS_NULL_list(funcs)) {
-
 
1544
		EXP c, f;
1341
	CANDIDATE *r = q + i ;
1545
		LIST(EXP) fargs = NULL_list(EXP);
-
 
1546
		LIST(IDENTIFIER) pids = DEREF_list(tok_proc_bids(tok));
-
 
1547
		IDENTIFIER fid = DEREF_id(HEAD_list(funcs));
-
 
1548
		DESTROY_CONS_exp(destroy, c, conds, conds);
-
 
1549
		while (!IS_NULL_list(pids)) {
1342
	if ( r->rank >= RANK_VIABLE ) {
1550
			/* Build up argument list */
-
 
1551
			TYPE t;
1343
	    int suspect = 0 ;
1552
			int prom = 0;
1344
	    TYPE ta = NULL_type ;
1553
			LIST(TYPE) pt;
1345
	    IDENTIFIER fid = r->base ;
1554
			IDENTIFIER pid = DEREF_id(HEAD_list(pids));
-
 
1555
			EXP e = apply_exp_token(pid, NULL_list(TOKEN), 0);
-
 
1556
			e = convert_reference(e, REF_NORMAL);
1346
	    switch ( TAG_id ( fid ) ) {
1557
			t = DEREF_type(exp_type(e));
-
 
1558
			pt = possible_types(t, &prom);
1347
		case id_builtin_tag : {
1559
			if (!IS_NULL_list(pt)) {
1348
		    ta = DEREF_type ( id_builtin_ret ( fid ) ) ;
1560
				/* Mark target dependent arguments */
-
 
1561
				MAKE_exp_paren(t, e, e);
-
 
1562
			}
-
 
1563
			CONS_exp(e, fargs, fargs);
1349
		    break ;
1564
			pids = TAIL_list(pids);
1350
		}
1565
		}
1351
		case id_function_tag : {
1566
		fargs = REVERSE_list(fargs);
1352
		    TYPE fa = DEREF_type ( id_function_type ( fid ) ) ;
-
 
1353
		    if ( IS_type_func ( fa ) ) {
1567
		if (IS_id_builtin(fid)) {
1354
			ta = DEREF_type ( type_func_ret ( fa ) ) ;
1568
			f = apply_builtin(fid, fargs);
1355
		    }
1569
		} else {
1356
		    break ;
-
 
1357
		}
-
 
1358
		case id_mem_func_tag : {
-
 
1359
		    TYPE fa = DEREF_type ( id_mem_func_type ( fid ) ) ;
-
 
1360
		    if ( IS_type_func ( fa ) ) {
-
 
1361
			HASHID fnm = DEREF_hashid ( id_name ( fid ) ) ;
1570
			HASHID fnm = DEREF_hashid(id_name(fid));
1362
			mt = DEREF_list ( type_func_mtypes ( fa ) ) ;
1571
			use_func_id(fid, 1, 0);
1363
			et = DEREF_type ( HEAD_list ( mt ) ) ;
-
 
1364
			if ( IS_hashid_constr ( fnm ) ) {
1572
			if (IS_hashid_constr(fnm)) {
1365
			    ta = DEREF_type ( hashid_constr_type ( fnm ) ) ;
1573
				f = apply_constr(fid, fargs);
1366
			} else {
1574
			} else {
1367
			    ta = DEREF_type ( type_func_ret ( fa ) ) ;
1575
				f = apply_func_id(fid, qual, NULL_graph, fargs);
1368
			    tag = id_mem_func_tag ;
-
 
1369
			}
1576
			}
1370
		    }
-
 
1371
		    break ;
-
 
1372
		}
1577
		}
1373
		case id_stat_mem_func_tag : {
1578
		if (!IS_type_top_etc(ret)) {
1374
		    TYPE fa = DEREF_type ( id_stat_mem_func_type ( fid ) ) ;
-
 
1375
		    if ( IS_type_func ( fa ) ) {
1579
			/* Convert to common return type */
1376
			mt = DEREF_list ( type_func_mtypes ( fa ) ) ;
1580
			ERROR err2 = NULL_err;
1377
			et = DEREF_type ( HEAD_list ( mt ) ) ;
1581
			f = convert_reference(f, REF_ASSIGN);
1378
			ta = DEREF_type ( type_func_ret ( fa ) ) ;
1582
			f = cast_exp(ret, f, &err2, CAST_IMPLICIT);
1379
			if ( tag != id_mem_func_tag ) {
1583
			if (!IS_NULL_err(err2)) {
1380
			    tag = id_stat_mem_func_tag ;
1584
				report(crt_loc, err2);
1381
			}
1585
			}
1382
		    }
-
 
1383
		    break ;
-
 
1384
		}
1586
		}
1385
	    }
1587
		if (IS_NULL_exp(res)) {
1386
	    ret = common_type ( ret, ta, &suspect ) ;
1588
			free_exp(c, 1);
1387
	    if ( suspect ) ret = NULL_type ;
1589
			res = f;
-
 
1590
		} else {
1388
	    CONS_exp ( r->cond, conds, conds ) ;
1591
			MAKE_exp_hash_if (ret, c, f, res, res);
-
 
1592
		}
1389
	    CONS_id ( fid, funcs, funcs ) ;
1593
		funcs = TAIL_list(funcs);
1390
	}
1594
	}
1391
    }
-
 
1392
    if ( IS_NULL_type ( ret ) ) {
1595
	IGNORE define_exp_token(tid, res, 1);
1393
	/* Couldn't bring return types to common type */
-
 
1394
	ERROR err2 = ERR_over_match_best_common () ;
-
 
1395
	add_error ( err, err2 ) ;
-
 
1396
	ret = type_error ;
-
 
1397
    }
-
 
1398
    if ( err != KILL_err ) {
-
 
1399
	*err = list_candidates ( *err, p, RANK_VIABLE ) ;
-
 
1400
    }
-
 
1401
 
1596
 
1402
    /* Create list of argument types */
-
 
1403
    while ( !IS_NULL_list ( args ) ) {
-
 
1404
	TYPE t ;
-
 
1405
	EXP e = DEREF_exp ( HEAD_list ( args ) ) ;
-
 
1406
	if ( IS_NULL_exp ( e ) ) {
-
 
1407
	    t = et ;
-
 
1408
	    et = type_error ;
-
 
1409
	} else {
-
 
1410
	    t = DEREF_type ( exp_type ( e ) ) ;
-
 
1411
	    if ( IS_type_bitfield ( t ) ) {
-
 
1412
		t = promote_type ( t ) ;
-
 
1413
	    } else {
-
 
1414
		CV_SPEC cv = DEREF_cv ( type_qual ( t ) ) ;
-
 
1415
		if ( cv & cv_lvalue ) {
-
 
1416
		    MAKE_type_ref ( cv_none, t, t ) ;
-
 
1417
		}
-
 
1418
	    }
-
 
1419
	}
-
 
1420
	CONS_type ( t, types, types ) ;
-
 
1421
	args = TAIL_list ( args ) ;
-
 
1422
    }
-
 
1423
    types = REVERSE_list ( types ) ;
-
 
1424
 
-
 
1425
    /* Check for previous instance */
-
 
1426
    tid = previous_ambig_func ( funcs, types, qual ) ;
-
 
1427
    if ( !IS_NULL_id ( tid ) ) {
-
 
1428
	DESTROY_list ( funcs, SIZE_id ) ;
-
 
1429
	DESTROY_list ( types, SIZE_type ) ;
-
 
1430
	free_exp_list ( conds, 1 ) ;
-
 
1431
	return ( tid ) ;
-
 
1432
    }
-
 
1433
 
-
 
1434
    /* Create new instance */
-
 
1435
    all = xmalloc_one ( AMBIG_FUNCTION ) ;
-
 
1436
    all->id = NULL_id ;
-
 
1437
    all->funcs = funcs ;
-
 
1438
    all->types = types ;
-
 
1439
    all->qual = qual ;
-
 
1440
    all->next = all_ambig_funcs ;
-
 
1441
    all_ambig_funcs = all ;
-
 
1442
 
-
 
1443
    /* Scan through argument types */
-
 
1444
    crt_id_qualifier = qual_none ;
-
 
1445
    crt_templ_qualifier = 0 ;
-
 
1446
    have_type_declaration = TYPE_DECL_NONE ;
-
 
1447
    decl_loc = crt_loc ;
-
 
1448
    begin_param ( id ) ;
-
 
1449
    mt = types ;
-
 
1450
    while ( !IS_NULL_list ( mt ) ) {
-
 
1451
	HASHID pnm = lookup_anon () ;
-
 
1452
	IDENTIFIER pid = DEREF_id ( hashid_id ( pnm ) ) ;
-
 
1453
	TYPE t = DEREF_type ( HEAD_list ( mt ) ) ;
-
 
1454
	pid = make_param_decl ( dspec_none, t, pid, CONTEXT_PARAMETER ) ;
-
 
1455
	init_param ( pid, NULL_exp ) ;
-
 
1456
	mt = TAIL_list ( mt ) ;
-
 
1457
    }
-
 
1458
    fn = make_func_type ( ret, FUNC_NONE, cv_none, empty_type_set ) ;
-
 
1459
    if ( tag != id_function_tag ) {
-
 
1460
	mt = DEREF_list ( type_func_ptypes ( fn ) ) ;
-
 
1461
	mt = TAIL_list ( mt ) ;
-
 
1462
	COPY_list ( type_func_ptypes ( fn ), mt ) ;
-
 
1463
    }
-
 
1464
    end_param () ;
-
 
1465
 
-
 
1466
    /* Create a function identifier */
-
 
1467
    ds = ( dspec_static | dspec_token | dspec_reserve ) ;
-
 
1468
    MAKE_id_function_etc ( tag, nm, ds, ns, crt_loc, fn, NULL_id, id ) ;
-
 
1469
 
-
 
1470
    /* Create token identifier */
-
 
1471
    ns = token_namespace ;
-
 
1472
    nm = lookup_anon () ;
-
 
1473
    mem = search_member ( ns, nm, 1 ) ;
-
 
1474
    MAKE_tok_func ( fn, tok ) ;
-
 
1475
    MAKE_id_token ( nm, ds, ns, crt_loc, tok, id, tid ) ;
-
 
1476
    MAKE_type_token ( cv_none, tid, NULL_list ( TOKEN ), form ) ;
-
 
1477
    COPY_type ( id_function_etc_form ( id ), form ) ;
-
 
1478
    set_member ( mem, tid ) ;
-
 
1479
    tok = func_proc_token ( tok ) ;
-
 
1480
 
-
 
1481
    /* Define token */
-
 
1482
    res = install_error ( &crt_loc, ERR_over_match_best_install () ) ;
-
 
1483
    while ( !IS_NULL_list ( funcs ) ) {
-
 
1484
	EXP c, f ;
-
 
1485
	LIST ( EXP ) fargs = NULL_list ( EXP ) ;
-
 
1486
	LIST ( IDENTIFIER ) pids = DEREF_list ( tok_proc_bids ( tok ) ) ;
-
 
1487
	IDENTIFIER fid = DEREF_id ( HEAD_list ( funcs ) ) ;
-
 
1488
	DESTROY_CONS_exp ( destroy, c, conds, conds ) ;
-
 
1489
	while ( !IS_NULL_list ( pids ) ) {
-
 
1490
	    /* Build up argument list */
-
 
1491
	    TYPE t ;
-
 
1492
	    int prom = 0 ;
-
 
1493
	    LIST ( TYPE ) pt ;
-
 
1494
	    IDENTIFIER pid = DEREF_id ( HEAD_list ( pids ) ) ;
-
 
1495
	    EXP e = apply_exp_token ( pid, NULL_list ( TOKEN ), 0 ) ;
-
 
1496
	    e = convert_reference ( e, REF_NORMAL ) ;
-
 
1497
	    t = DEREF_type ( exp_type ( e ) ) ;
-
 
1498
	    pt = possible_types ( t, &prom ) ;
-
 
1499
	    if ( !IS_NULL_list ( pt ) ) {
-
 
1500
		/* Mark target dependent arguments */
-
 
1501
		MAKE_exp_paren ( t, e, e ) ;
-
 
1502
	    }
-
 
1503
	    CONS_exp ( e, fargs, fargs ) ;
-
 
1504
	    pids = TAIL_list ( pids ) ;
-
 
1505
	}
-
 
1506
	fargs = REVERSE_list ( fargs ) ;
-
 
1507
	if ( IS_id_builtin ( fid ) ) {
-
 
1508
	    f = apply_builtin ( fid, fargs ) ;
-
 
1509
	} else {
-
 
1510
	    HASHID fnm = DEREF_hashid ( id_name ( fid ) ) ;
-
 
1511
	    use_func_id ( fid, 1, 0 ) ;
-
 
1512
	    if ( IS_hashid_constr ( fnm ) ) {
-
 
1513
		f = apply_constr ( fid, fargs ) ;
-
 
1514
	    } else {
-
 
1515
		f = apply_func_id ( fid, qual, NULL_graph, fargs ) ;
-
 
1516
	    }
-
 
1517
	}
-
 
1518
	if ( !IS_type_top_etc ( ret ) ) {
-
 
1519
	    /* Convert to common return type */
-
 
1520
	    ERROR err2 = NULL_err ;
-
 
1521
	    f = convert_reference ( f, REF_ASSIGN ) ;
-
 
1522
	    f = cast_exp ( ret, f, &err2, CAST_IMPLICIT ) ;
-
 
1523
	    if ( !IS_NULL_err ( err2 ) ) report ( crt_loc, err2 ) ;
-
 
1524
	}
-
 
1525
	if ( IS_NULL_exp ( res ) ) {
-
 
1526
	    free_exp ( c, 1 ) ;
-
 
1527
	    res = f ;
-
 
1528
	} else {
-
 
1529
	    MAKE_exp_hash_if ( ret, c, f, res, res ) ;
-
 
1530
	}
-
 
1531
	funcs = TAIL_list ( funcs ) ;
-
 
1532
    }
-
 
1533
    IGNORE define_exp_token ( tid, res, 1 ) ;
-
 
1534
 
-
 
1535
    /* Restore previous state */
1597
	/* Restore previous state */
1536
    have_type_declaration = td ;
1598
	have_type_declaration = td;
1537
    crt_templ_qualifier = tq ;
1599
	crt_templ_qualifier = tq;
1538
    crt_id_qualifier = cq ;
1600
	crt_id_qualifier = cq;
1539
    all->id = id ;
1601
	all->id = id;
1540
    return ( id ) ;
1602
	return (id);
1541
}
1603
}
1542
 
1604
 
1543
 
1605
 
1544
/*
1606
/*
1545
    IS AN IDENTIFIER A FUNCTION TEMPLATE?
1607
    IS AN IDENTIFIER A FUNCTION TEMPLATE?
1546
 
1608
 
1547
    This routine returns true if id is a function template.  In this case
1609
    This routine returns true if id is a function template.  In this case
1548
    overload resolution is always done even if id is not overloaded.
1610
    overload resolution is always done even if id is not overloaded.
1549
*/
1611
*/
1550
 
1612
 
1551
static int is_template_func
1613
static int
1552
    PROTO_N ( ( id ) )
-
 
1553
    PROTO_T ( IDENTIFIER id )
1614
is_template_func(IDENTIFIER id)
1554
{
1615
{
1555
    if ( IS_id_function_etc ( id ) ) {
1616
	if (IS_id_function_etc(id)) {
1556
	TYPE fn = DEREF_type ( id_function_etc_type ( id ) ) ;
1617
		TYPE fn = DEREF_type(id_function_etc_type(id));
1557
	if ( IS_type_templ ( fn ) ) return ( 1 ) ;
1618
		if (IS_type_templ(fn)) {
-
 
1619
			return (1);
1558
    }
1620
		}
-
 
1621
	}
1559
    return ( 0 ) ;
1622
	return (0);
1560
}
1623
}
1561
 
1624
 
1562
 
1625
 
1563
/*
1626
/*
1564
    RESOLVE AN OVERLOADED FUNCTION CALL
1627
    RESOLVE AN OVERLOADED FUNCTION CALL
1565
 
1628
 
1566
    This routine resolves the overloaded function call 'id ( args )' where
1629
    This routine resolves the overloaded function call 'id ( args )' where
1567
    id is an identifier expression.  dep is true when id is a simple
1630
    id is an identifier expression.  dep is true when id is a simple
Line 1570... Line 1633...
1570
    identifier returned is the first of the viable functions to be declared
1633
    identifier returned is the first of the viable functions to be declared
1571
    (this is a side effect of the algorithm in resolve_overload and the
1634
    (this is a side effect of the algorithm in resolve_overload and the
1572
    way in which overloaded functions are represented).
1635
    way in which overloaded functions are represented).
1573
*/
1636
*/
1574
 
1637
 
1575
IDENTIFIER resolve_call
1638
IDENTIFIER
1576
    PROTO_N ( ( id, args, qual, dep ) )
-
 
1577
    PROTO_T ( IDENTIFIER id X LIST ( EXP ) args X QUALIFIER qual X int dep )
1639
resolve_call(IDENTIFIER id, LIST(EXP) args, QUALIFIER qual, int dep)
1578
{
1640
{
1579
    /* Build up candidate list */
1641
	/* Build up candidate list */
1580
    unsigned sz ;
1642
	unsigned sz;
1581
    IDENTIFIER fid = id ;
1643
	IDENTIFIER fid = id;
1582
    CANDIDATE_LIST *p = &candidates ;
1644
	CANDIDATE_LIST *p = &candidates;
1583
    p->size = 0 ;
1645
	p->size = 0;
1584
    if ( dep ) {
1646
	if (dep) {
1585
	/* Allow for argument dependent look-up */
1647
		/* Allow for argument dependent look-up */
1586
	LIST ( EXP ) q = args ;
1648
		LIST(EXP) q = args;
1587
	while ( !IS_NULL_list ( q ) ) {
1649
		while (!IS_NULL_list(q)) {
1588
	    EXP a = DEREF_exp ( HEAD_list ( q ) ) ;
1650
			EXP a = DEREF_exp(HEAD_list(q));
1589
	    if ( !IS_NULL_exp ( a ) ) {
1651
			if (!IS_NULL_exp(a)) {
1590
		TYPE t = DEREF_type ( exp_type ( a ) ) ;
1652
				TYPE t = DEREF_type(exp_type(a));
1591
		IGNORE koenig_candidates ( p, fid, t, KIND_FUNC ) ;
1653
				IGNORE koenig_candidates(p, fid, t, KIND_FUNC);
1592
	    }
1654
			}
1593
	    q = TAIL_list ( q ) ;
1655
			q = TAIL_list(q);
1594
	}
1656
		}
1595
    }
1657
	}
1596
    add_candidates ( p, fid, 1, KIND_FUNC ) ;
1658
	add_candidates(p, fid, 1, KIND_FUNC);
1597
    sz = p->size ;
1659
	sz = p->size;
1598
    if ( sz == 0 ) {
1660
	if (sz == 0) {
1599
	/* No candidates */
1661
		/* No candidates */
1600
	EXP a ;
1662
		EXP a;
1601
	int fn = 2 ;
1663
		int fn = 2;
1602
	QUALIFIER cq = crt_id_qualifier ;
1664
		QUALIFIER cq = crt_id_qualifier;
1603
	crt_id_qualifier = ( qual & qual_explicit ) ;
1665
		crt_id_qualifier = (qual & qual_explicit);
1604
	if ( qual & qual_mark ) fn = 1 ;
1666
		if (qual & qual_mark) {
-
 
1667
			fn = 1;
-
 
1668
		}
1605
	a = implicit_id_exp ( fid, fn ) ;
1669
		a = implicit_id_exp(fid, fn);
1606
	if ( IS_exp_identifier_etc ( a ) ) {
1670
		if (IS_exp_identifier_etc(a)) {
1607
	    fid = DEREF_id ( exp_identifier_etc_id ( a ) ) ;
1671
			fid = DEREF_id(exp_identifier_etc_id(a));
1608
	    add_candidates ( p, fid, 1, KIND_FUNC ) ;
1672
			add_candidates(p, fid, 1, KIND_FUNC);
1609
	    sz = p->size ;
1673
			sz = p->size;
1610
	    if ( sz != 0 ) fid = p->elem [0].func ;
-
 
1611
	}
-
 
1612
	crt_id_qualifier = cq ;
-
 
1613
    } else {
1674
			if (sz != 0) {
1614
	fid = p->elem [0].func ;
1675
				fid = p->elem[0].func;
1615
    }
-
 
1616
 
-
 
1617
    /* Resolve overloaded functions */
-
 
1618
    if ( sz > 1 ) {
-
 
1619
	CANDIDATE *q = resolve_overload ( p, args, NULL_type, 0 ) ;
-
 
1620
	IDENTIFIER qid = q->func ;
-
 
1621
	unsigned rank = q->rank ;
-
 
1622
	int kind = q->kind ;
-
 
1623
	if ( rank == RANK_BEST ) {
-
 
1624
	    /* Unambiguous resolution */
-
 
1625
	    if ( match_no_viable > 1 ) {
-
 
1626
		ERROR err = ERR_over_match_call_ok ( qid ) ;
-
 
1627
		if ( !IS_NULL_err ( err ) ) report ( crt_loc, err ) ;
-
 
1628
	    }
-
 
1629
	} else if ( rank == RANK_VIABLE ) {
-
 
1630
	    /* Ambiguous resolution */
-
 
1631
	    q = resolve_ambiguous ( p, args, NULL_type, 0 ) ;
-
 
1632
	    qid = q->func ;
-
 
1633
	    rank = q->rank ;
-
 
1634
	    if ( rank == RANK_TARGET ) {
-
 
1635
		ERROR err = ERR_over_match_call_target ( id ) ;
-
 
1636
		qid = make_ambig_func ( p, qid, args, qual, &err ) ;
-
 
1637
		kind = KIND_FUNC ;
-
 
1638
		report ( crt_loc, err ) ;
-
 
1639
	    } else if ( rank == RANK_VIABLE ) {
-
 
1640
		ERROR err = ERR_over_match_call_ambig ( id ) ;
-
 
1641
		err = list_candidates ( err, p, RANK_VIABLE ) ;
-
 
1642
		report ( crt_loc, err ) ;
-
 
1643
	    }
-
 
1644
	} else {
-
 
1645
	    /* Unviable resolution */
-
 
1646
	    report ( crt_loc, ERR_over_match_viable_none ( id ) ) ;
-
 
1647
	}
1676
			}
1648
	resolved_kind = kind ;
-
 
1649
	return ( qid ) ;
-
 
1650
    }
-
 
1651
 
-
 
1652
    /* Check template functions */
-
 
1653
    if ( is_template_func ( fid ) ) {
-
 
1654
	ERROR err = NULL_err ;
-
 
1655
	IDENTIFIER qid = deduce_args ( fid, args, 2, 0, 1, &err ) ;
-
 
1656
	if ( IS_NULL_id ( qid ) ) {
-
 
1657
	    /* No viable resolution */
-
 
1658
	    err = concat_error ( err, ERR_over_match_viable_none ( id ) ) ;
-
 
1659
	    qid = fid ;
-
 
1660
	}
1677
		}
1661
	if ( !IS_NULL_err ( err ) ) {
-
 
1662
	    /* Report any argument deduction errors */
-
 
1663
	    err = concat_error ( err, ERR_temp_deduct_fail ( id ) ) ;
-
 
1664
	    report ( crt_loc, err ) ;
1678
		crt_id_qualifier = cq;
1665
	} else {
1679
	} else {
1666
	    /* Successful argument deduction */
1680
		fid = p->elem[0].func;
1667
	    report ( crt_loc, ERR_over_match_call_ok ( qid ) ) ;
-
 
1668
	}
1681
	}
-
 
1682
 
-
 
1683
	/* Resolve overloaded functions */
-
 
1684
	if (sz > 1) {
-
 
1685
		CANDIDATE *q = resolve_overload(p, args, NULL_type, 0);
-
 
1686
		IDENTIFIER qid = q->func;
-
 
1687
		unsigned rank = q->rank;
-
 
1688
		int kind = q->kind;
-
 
1689
		if (rank == RANK_BEST) {
-
 
1690
			/* Unambiguous resolution */
-
 
1691
			if (match_no_viable > 1) {
-
 
1692
				ERROR err = ERR_over_match_call_ok(qid);
-
 
1693
				if (!IS_NULL_err(err)) {
-
 
1694
					report(crt_loc, err);
-
 
1695
				}
-
 
1696
			}
-
 
1697
		} else if (rank == RANK_VIABLE) {
-
 
1698
			/* Ambiguous resolution */
-
 
1699
			q = resolve_ambiguous(p, args, NULL_type, 0);
-
 
1700
			qid = q->func;
-
 
1701
			rank = q->rank;
-
 
1702
			if (rank == RANK_TARGET) {
-
 
1703
				ERROR err = ERR_over_match_call_target(id);
-
 
1704
				qid = make_ambig_func(p, qid, args, qual, &err);
-
 
1705
				kind = KIND_FUNC;
-
 
1706
				report(crt_loc, err);
-
 
1707
			} else if (rank == RANK_VIABLE) {
-
 
1708
				ERROR err = ERR_over_match_call_ambig(id);
-
 
1709
				err = list_candidates(err, p, RANK_VIABLE);
-
 
1710
				report(crt_loc, err);
-
 
1711
			}
-
 
1712
		} else {
-
 
1713
			/* Unviable resolution */
-
 
1714
			report(crt_loc, ERR_over_match_viable_none(id));
-
 
1715
		}
-
 
1716
		resolved_kind = kind;
-
 
1717
		return (qid);
-
 
1718
	}
-
 
1719
 
-
 
1720
	/* Check template functions */
-
 
1721
	if (is_template_func(fid)) {
-
 
1722
		ERROR err = NULL_err;
-
 
1723
		IDENTIFIER qid = deduce_args(fid, args, 2, 0, 1, &err);
-
 
1724
		if (IS_NULL_id(qid)) {
-
 
1725
			/* No viable resolution */
-
 
1726
			err = concat_error(err, ERR_over_match_viable_none(id));
-
 
1727
			qid = fid;
-
 
1728
		}
-
 
1729
		if (!IS_NULL_err(err)) {
-
 
1730
			/* Report any argument deduction errors */
-
 
1731
			err = concat_error(err, ERR_temp_deduct_fail(id));
-
 
1732
			report(crt_loc, err);
-
 
1733
		} else {
-
 
1734
			/* Successful argument deduction */
-
 
1735
			report(crt_loc, ERR_over_match_call_ok(qid));
-
 
1736
		}
1669
	fid = qid ;
1737
		fid = qid;
1670
    }
1738
	}
1671
 
1739
 
1672
    /* Don't check non-overloaded functions */
1740
	/* Don't check non-overloaded functions */
1673
    match_no_args = 0 ;
1741
	match_no_args = 0;
1674
    match_no_viable = 0 ;
1742
	match_no_viable = 0;
1675
    resolved_kind = KIND_FUNC ;
1743
	resolved_kind = KIND_FUNC;
1676
    return ( fid ) ;
1744
	return (fid);
1677
}
1745
}
1678
 
1746
 
1679
 
1747
 
1680
/*
1748
/*
1681
    RESOLVE AN AMBIGUOUS FUNCTION ADDRESS
1749
    RESOLVE AN AMBIGUOUS FUNCTION ADDRESS
1682
 
1750
 
1683
    This routine resolves the list of functions ids to see which is the
1751
    This routine resolves the list of functions ids to see which is the
1684
    best under the template specialisation rules.  If no one best candidate
1752
    best under the template specialisation rules.  If no one best candidate
1685
    is found the null identifier is returned.  This rule is not actually
1753
    is found the null identifier is returned.  This rule is not actually
1686
    in ISO C++, but it could have been.
1754
    in ISO C++, but it could have been.
1687
*/
1755
*/
1688
 
1756
 
1689
static IDENTIFIER resolve_ambig_func
1757
static IDENTIFIER
1690
    PROTO_N ( ( ids, depth ) )
-
 
1691
    PROTO_T ( LIST ( IDENTIFIER ) ids X int depth )
1758
resolve_ambig_func(LIST(IDENTIFIER) ids, int depth)
1692
{
1759
{
1693
    if ( !IS_NULL_list ( ids ) ) {
1760
	if (!IS_NULL_list(ids)) {
1694
	int cmp ;
1761
		int cmp;
1695
	IDENTIFIER rid, sid ;
1762
		IDENTIFIER rid, sid;
1696
	LIST ( IDENTIFIER ) pids = ids ;
1763
		LIST(IDENTIFIER) pids = ids;
1697
 
1764
 
1698
	/* Find the first two functions */
1765
		/* Find the first two functions */
1699
	rid = DEREF_id ( HEAD_list ( pids ) ) ;
1766
		rid = DEREF_id(HEAD_list(pids));
1700
	pids = TAIL_list ( pids ) ;
1767
		pids = TAIL_list(pids);
1701
	if ( IS_NULL_list ( pids ) ) return ( rid ) ;
1768
		if (IS_NULL_list(pids)) {
-
 
1769
			return (rid);
-
 
1770
		}
1702
	sid = DEREF_id ( HEAD_list ( pids ) ) ;
1771
		sid = DEREF_id(HEAD_list(pids));
1703
	pids = TAIL_list ( pids ) ;
1772
		pids = TAIL_list(pids);
1704
 
1773
 
1705
	/* Compare them */
1774
		/* Compare them */
1706
	cmp = compare_funcs ( rid, sid ) ;
1775
		cmp = compare_funcs(rid, sid);
1707
	if ( cmp == 2 ) {
1776
		if (cmp == 2) {
1708
	    rid = sid ;
1777
			rid = sid;
1709
	} else if ( cmp != 1 ) {
1778
		} else if (cmp != 1) {
1710
	    rid = NULL_id ;
1779
			rid = NULL_id;
1711
	}
1780
		}
1712
 
1781
 
1713
	/* Compare the winner against the best of the rest */
1782
		/* Compare the winner against the best of the rest */
1714
	sid = resolve_ambig_func ( pids, depth + 1 ) ;
1783
		sid = resolve_ambig_func(pids, depth + 1);
1715
	cmp = compare_funcs ( rid, sid ) ;
1784
		cmp = compare_funcs(rid, sid);
1716
	if ( cmp == 2 ) {
1785
		if (cmp == 2) {
1717
	    rid = sid ;
1786
			rid = sid;
1718
	} else if ( cmp != 1 ) {
1787
		} else if (cmp != 1) {
1719
	    rid = NULL_id ;
1788
			rid = NULL_id;
1720
	}
1789
		}
1721
 
1790
 
1722
	/* Check overall winner */
1791
		/* Check overall winner */
1723
	if ( depth == 0 && !IS_NULL_id ( rid ) ) {
1792
		if (depth == 0 && !IS_NULL_id(rid)) {
1724
	    pids = ids ;
1793
			pids = ids;
1725
	    while ( !IS_NULL_list ( pids ) ) {
1794
			while (!IS_NULL_list(pids)) {
1726
		sid = DEREF_id ( HEAD_list ( pids ) ) ;
1795
				sid = DEREF_id(HEAD_list(pids));
1727
		if ( !EQ_id ( rid, sid ) ) {
1796
				if (!EQ_id(rid, sid)) {
1728
		    cmp = compare_funcs ( rid, sid ) ;
1797
					cmp = compare_funcs(rid, sid);
-
 
1798
					if (cmp != 1) {
1729
		    if ( cmp != 1 ) return ( NULL_id ) ;
1799
						return (NULL_id);
-
 
1800
					}
1730
		}
1801
				}
1731
		pids = TAIL_list ( pids ) ;
1802
				pids = TAIL_list(pids);
1732
	    }
1803
			}
-
 
1804
		}
-
 
1805
		return (rid);
1733
	}
1806
	}
1734
	return ( rid ) ;
-
 
1735
    }
-
 
1736
    return ( NULL_id ) ;
1807
	return (NULL_id);
1737
}
1808
}
1738
 
1809
 
1739
 
1810
 
1740
/*
1811
/*
1741
    FIND AN OVERLOADED FUNCTION OF A GIVEN TYPE
1812
    FIND AN OVERLOADED FUNCTION OF A GIVEN TYPE
Line 1748... Line 1819...
1748
    occurs if res is true).  If there is a match ignoring linkage
1819
    occurs if res is true).  If there is a match ignoring linkage
1749
    specifiers then this is returned, the value of eq_func_type for the
1820
    specifiers then this is returned, the value of eq_func_type for the
1750
    result is assigned to peq.
1821
    result is assigned to peq.
1751
*/
1822
*/
1752
 
1823
 
1753
IDENTIFIER resolve_func
1824
IDENTIFIER
1754
    PROTO_N ( ( id, t, templ, res, pids, peq ) )
-
 
1755
    PROTO_T ( IDENTIFIER id X TYPE t X int templ X int res X
1825
resolve_func(IDENTIFIER id, TYPE t, int templ, int res, LIST(IDENTIFIER) pids,
1756
	      LIST ( IDENTIFIER ) pids X int *peq )
1826
	     int *peq)
1757
{
1827
{
1758
    int best = 2 ;
1828
	int best = 2;
1759
    IDENTIFIER rid = NULL_id ;
1829
	IDENTIFIER rid = NULL_id;
1760
    switch ( TAG_id ( id ) ) {
1830
	switch (TAG_id(id)) {
1761
 
-
 
1762
	case id_function_tag :
1831
	case id_function_tag:
1763
	case id_mem_func_tag :
1832
	case id_mem_func_tag:
1764
	case id_stat_mem_func_tag : {
1833
	case id_stat_mem_func_tag: {
1765
	    /* Check overloaded functions */
1834
		/* Check overloaded functions */
1766
	    IDENTIFIER fid = id ;
1835
		IDENTIFIER fid = id;
1767
	    int have_templates = 0 ;
1836
		int have_templates = 0;
1768
	    LIST ( IDENTIFIER ) rids = NULL_list ( IDENTIFIER ) ;
1837
		LIST(IDENTIFIER) rids = NULL_list(IDENTIFIER);
1769
	    while ( !IS_NULL_id ( fid ) ) {
1838
		while (!IS_NULL_id(fid)) {
1770
		TYPE s ;
1839
			TYPE s;
1771
		int d = 0 ;
1840
			int d = 0;
1772
		int eq = 0 ;
1841
			int eq = 0;
1773
		IDENTIFIER tid = fid ;
1842
			IDENTIFIER tid = fid;
1774
		if ( !IS_NULL_list ( pids ) ) {
1843
			if (!IS_NULL_list(pids)) {
1775
		    /* Save template parameter values */
1844
				/* Save template parameter values */
1776
		    d = save_token_args ( pids, NULL_list ( TOKEN ) ) ;
1845
				d = save_token_args(pids, NULL_list(TOKEN));
1777
		}
1846
			}
1778
		s = DEREF_type ( id_function_etc_type ( fid ) ) ;
1847
			s = DEREF_type(id_function_etc_type(fid));
1779
		if ( IS_type_templ ( s ) && templ ) {
1848
			if (IS_type_templ(s) && templ) {
1780
		    /* Template functions */
1849
				/* Template functions */
1781
		    tid = deduce_func ( tid, t, &eq ) ;
1850
				tid = deduce_func(tid, t, &eq);
1782
		    if ( !IS_NULL_id ( tid ) ) have_templates = 1 ;
1851
				if (!IS_NULL_id(tid)) {
-
 
1852
					have_templates = 1;
-
 
1853
				}
1783
		} else {
1854
			} else {
1784
		    /* Simple functions */
1855
				/* Simple functions */
1785
#if LANGUAGE_CPP
1856
#if LANGUAGE_CPP
1786
		    eq = eq_func_type ( s, t, 1, 0 ) ;
1857
				eq = eq_func_type(s, t, 1, 0);
1787
#else
1858
#else
1788
		    TYPE r = type_composite ( s, t, 1, 0, KILL_err, 0 ) ;
1859
				TYPE r = type_composite(s, t, 1, 0, KILL_err,
-
 
1860
							0);
1789
		    if ( !IS_NULL_type ( r ) ) eq = 3 ;
1861
				if (!IS_NULL_type(r)) {
-
 
1862
					eq = 3;
-
 
1863
				}
1790
#endif
1864
#endif
1898
 
1974
 
1899
 
1975
 
1900
/*
1976
/*
1901
    CREATE A RESOLVED OVERLOADED FUNCTION EXPRESSION
1977
    CREATE A RESOLVED OVERLOADED FUNCTION EXPRESSION
1902
 
1978
 
1903
    This routine creates a resolved overloaded function expression for
1979
    This routine creates a resolved overloaded function expression for
1904
    the function id.
1980
    the function id.
1905
*/
1981
*/
1906
 
1982
 
1907
static EXP make_resolved_exp
1983
static EXP
1908
    PROTO_N ( ( id, q, b, addr, paren ) )
-
 
1909
    PROTO_T ( IDENTIFIER id X QUALIFIER q X EXP b X int addr X int paren )
1984
make_resolved_exp(IDENTIFIER id, QUALIFIER q, EXP b, int addr, int paren)
1910
{
1985
{
1911
    EXP e ;
1986
	EXP e;
1912
    TYPE fn = DEREF_type ( id_function_etc_type ( id ) ) ;
1987
	TYPE fn = DEREF_type(id_function_etc_type(id));
1913
    if ( IS_id_mem_func ( id ) ) {
1988
	if (IS_id_mem_func(id)) {
1914
	if ( !IS_NULL_exp ( b ) ) {
1989
		if (!IS_NULL_exp(b)) {
1915
	    report ( crt_loc, ERR_expr_ref_call () ) ;
1990
			report(crt_loc, ERR_expr_ref_call());
1916
	    q = qual_nested ;
1991
			q = qual_nested;
-
 
1992
		}
-
 
1993
		MAKE_exp_member(fn, id, q, e);
-
 
1994
	} else {
-
 
1995
		MAKE_exp_identifier(fn, id, q, e);
-
 
1996
		if (!IS_NULL_exp(b)) {
-
 
1997
			e = join_exp(b, e);
-
 
1998
		}
1917
	}
1999
	}
1918
	MAKE_exp_member ( fn, id, q, e ) ;
-
 
1919
    } else {
2000
	if (addr) {
1920
	MAKE_exp_identifier ( fn, id, q, e ) ;
-
 
1921
	if ( !IS_NULL_exp ( b ) ) e = join_exp ( b, e ) ;
-
 
1922
    }
-
 
1923
    if ( addr ) {
2001
		if (paren) {
1924
	if ( paren ) e = make_paren_exp ( e ) ;
2002
			e = make_paren_exp(e);
-
 
2003
		}
1925
	e = make_ref_exp ( e, 1 ) ;
2004
		e = make_ref_exp(e, 1);
1926
    }
2005
	}
1927
    return ( e ) ;
2006
	return (e);
1928
}
2007
}
1929
 
2008
 
1930
 
2009
 
1931
/*
2010
/*
1932
    RESOLVE THE ADDRESS OF AN OVERLOADED FUNCTION
2011
    RESOLVE THE ADDRESS OF AN OVERLOADED FUNCTION
Line 1940... Line 2019...
1940
    The result is the appropriate version of e.  Note that member
2019
    The result is the appropriate version of e.  Note that member
1941
    expressions which resolve to static function members are replaced
2020
    expressions which resolve to static function members are replaced
1942
    by identifier expressions at this stage (see make_id_exp).
2021
    by identifier expressions at this stage (see make_id_exp).
1943
*/
2022
*/
1944
 
2023
 
1945
EXP resolve_cast
2024
EXP
1946
    PROTO_N ( ( t, e, err, use, rescan, pids ) )
-
 
1947
    PROTO_T ( TYPE t X EXP e X ERROR *err X int use X int rescan X
2025
resolve_cast(TYPE t, EXP e, ERROR *err, int use, int rescan,
1948
	      LIST ( IDENTIFIER ) pids )
2026
	     LIST(IDENTIFIER) pids)
1949
{
2027
{
1950
    /* Check for identifier expressions */
2028
	/* Check for identifier expressions */
1951
    EXP a = e ;
2029
	EXP a = e;
1952
    QUALIFIER q ;
2030
	QUALIFIER q;
1953
    int addr = 0 ;
2031
	int addr = 0;
1954
    int paren = 0 ;
2032
	int paren = 0;
1955
    IDENTIFIER id ;
2033
	IDENTIFIER id;
1956
    EXP b = NULL_exp ;
2034
	EXP b = NULL_exp;
1957
    unsigned tag = TAG_exp ( a ) ;
2035
	unsigned tag = TAG_exp(a);
1958
    while ( tag == exp_paren_tag ) {
2036
	while (tag == exp_paren_tag) {
1959
	a = DEREF_exp ( exp_paren_arg ( a ) ) ;
2037
		a = DEREF_exp(exp_paren_arg(a));
1960
	tag = TAG_exp ( a ) ;
2038
		tag = TAG_exp(a);
1961
    }
2039
	}
1962
    if ( tag == exp_address_tag ) {
2040
	if (tag == exp_address_tag) {
1963
	/* Address expression */
2041
		/* Address expression */
1964
	a = DEREF_exp ( exp_address_arg ( a ) ) ;
2042
		a = DEREF_exp(exp_address_arg(a));
1965
	tag = TAG_exp ( a ) ;
2043
		tag = TAG_exp(a);
1966
	addr = 1 ;
2044
		addr = 1;
1967
    } else if ( tag == exp_address_mem_tag ) {
2045
	} else if (tag == exp_address_mem_tag) {
1968
	/* Address of member expression */
2046
		/* Address of member expression */
1969
	paren = DEREF_int ( exp_address_mem_paren ( a ) ) ;
2047
		paren = DEREF_int(exp_address_mem_paren(a));
1970
	a = DEREF_exp ( exp_address_mem_arg ( a ) ) ;
2048
		a = DEREF_exp(exp_address_mem_arg(a));
1971
	tag = TAG_exp ( a ) ;
2049
		tag = TAG_exp(a);
1972
	addr = 1 ;
2050
		addr = 1;
1973
    } else if ( tag == exp_op_tag ) {
2051
	} else if (tag == exp_op_tag) {
1974
	/* Check for undetermined address expressions */
2052
		/* Check for undetermined address expressions */
1975
	int op = DEREF_int ( exp_op_lex ( a ) ) ;
2053
		int op = DEREF_int(exp_op_lex(a));
1976
	EXP c = DEREF_exp ( exp_op_arg2 ( a ) ) ;
2054
		EXP c = DEREF_exp(exp_op_arg2(a));
1977
	if ( op == lex_and_H1 && IS_NULL_exp ( c ) ) {
2055
		if (op == lex_and_H1 && IS_NULL_exp(c)) {
1978
	    a = DEREF_exp ( exp_op_arg1 ( a ) ) ;
2056
			a = DEREF_exp(exp_op_arg1(a));
1979
	    tag = TAG_exp ( a ) ;
2057
			tag = TAG_exp(a);
1980
	    addr = 1 ;
2058
			addr = 1;
1981
	}
2059
		}
1982
    }
2060
	}
1983
    while ( tag == exp_paren_tag ) {
2061
	while (tag == exp_paren_tag) {
1984
	a = DEREF_exp ( exp_paren_arg ( a ) ) ;
2062
		a = DEREF_exp(exp_paren_arg(a));
1985
	paren = 1 ;
2063
		paren = 1;
1986
	tag = TAG_exp ( a ) ;
2064
		tag = TAG_exp(a);
1987
    }
2065
	}
1988
    if ( tag == exp_call_tag ) {
2066
	if (tag == exp_call_tag) {
1989
	/* Member reference expression */
2067
		/* Member reference expression */
1990
	b = DEREF_exp ( exp_call_arg ( a ) ) ;
2068
		b = DEREF_exp(exp_call_arg(a));
1991
	a = DEREF_exp ( exp_call_ptr ( a ) ) ;
2069
		a = DEREF_exp(exp_call_ptr(a));
1992
    }
2070
	}
1993
    if ( !IS_exp_identifier_etc ( a ) ) {
2071
	if (!IS_exp_identifier_etc(a)) {
1994
	/* Not an identifier expression */
2072
		/* Not an identifier expression */
1995
	return ( e ) ;
2073
		return (e);
1996
    }
-
 
1997
 
-
 
1998
    /* Mark identifiers as resolved */
-
 
1999
    id = DEREF_id ( exp_identifier_etc_id ( a ) ) ;
-
 
2000
    q = DEREF_qual ( exp_identifier_etc_qual ( a ) ) ;
-
 
2001
    if ( q & qual_mark ) return ( e ) ;
-
 
2002
    if ( rescan ) {
-
 
2003
	/* Rescan function name if necessary */
-
 
2004
	id = rescan_func_id ( id, q ) ;
-
 
2005
    }
-
 
2006
    q |= qual_mark ;
-
 
2007
 
2074
	}
2008
    /* Check for overloaded functions */
-
 
2009
    tag = TAG_id ( id ) ;
-
 
2010
    switch ( tag ) {
-
 
2011
 
2075
 
2012
	case id_function_tag :
-
 
2013
	case id_mem_func_tag :
-
 
2014
	case id_stat_mem_func_tag :
-
 
2015
	function_lab : {
-
 
2016
	    /* Check functions for overloading */
2076
	/* Mark identifiers as resolved */
2017
	    TYPE s ;
-
 
2018
	    IDENTIFIER over ;
-
 
2019
	    if ( rescan ) goto overload_lab ;
-
 
2020
	    if ( dependent_cast ( id, t ) ) {
-
 
2021
		/* Allow for template parameters */
-
 
2022
		if ( !IS_type_func ( t ) ) t = rvalue_type ( t ) ;
-
 
2023
		MAKE_exp_op ( t, lex_function, e, NULL_exp, e ) ;
-
 
2024
		return ( e ) ;
-
 
2025
	    }
-
 
2026
	    over = DEREF_id ( id_function_etc_over ( id ) ) ;
-
 
2027
	    if ( !IS_NULL_id ( over ) ) goto overload_lab ;
-
 
2028
	    s = DEREF_type ( id_function_etc_type ( id ) ) ;
2077
	id = DEREF_id(exp_identifier_etc_id(a));
2029
	    if ( IS_type_templ ( s ) ) goto overload_lab ;
-
 
2030
	    if ( tag == id_mem_func_tag ) {
-
 
2031
		if ( !IS_NULL_exp ( b ) || addr ) {
-
 
2032
		    /* Force error in this case */
-
 
2033
		    e = make_resolved_exp ( id, q, b, addr, paren ) ;
-
 
2034
		}
-
 
2035
	    }
-
 
2036
	    if ( use ) {
-
 
2037
		COPY_qual ( exp_identifier_etc_qual ( a ), q ) ;
2078
	q = DEREF_qual(exp_identifier_etc_qual(a));
2038
		use_id ( id, suppress_usage ) ;
-
 
2039
	    }
-
 
2040
	    break ;
-
 
2041
	}
-
 
2042
 
-
 
2043
	case id_ambig_tag :
-
 
2044
	case id_undef_tag :
-
 
2045
	overload_lab : {
2079
	if (q & qual_mark) {
2046
	    /* Overloaded and ambiguous functions */
-
 
2047
	    TYPE fn = find_func_type ( t ) ;
-
 
2048
	    if ( !IS_NULL_type ( fn ) ) {
-
 
2049
		/* Overload resolution */
-
 
2050
		int eq = 0 ;
-
 
2051
		IDENTIFIER rid ;
-
 
2052
		if ( dependent_cast ( id, t ) ) {
-
 
2053
		    /* Allow for template parameters */
-
 
2054
		    if ( !IS_type_func ( t ) ) t = rvalue_type ( t ) ;
-
 
2055
		    MAKE_exp_op ( t, lex_function, e, NULL_exp, e ) ;
-
 
2056
		    return ( e ) ;
2080
		return (e);
2057
		}
2081
	}
2058
		if ( tag == id_undef_tag ) goto default_lab ;
-
 
2059
		rid = resolve_func ( id, fn, 1, 0, pids, &eq ) ;
-
 
2060
		if ( !IS_NULL_id ( rid ) ) {
-
 
2061
		    if ( IS_id_ambig ( rid ) ) {
-
 
2062
			/* Ambiguous resolution */
-
 
2063
			if ( use ) {
2082
	if (rescan) {
2064
			    /* Select one function */
2083
		/* Rescan function name if necessary */
2065
			    LIST ( IDENTIFIER ) ids ;
-
 
2066
			    IGNORE report_ambiguous ( rid, 0, 0, 0 ) ;
-
 
2067
			    ids = DEREF_list ( id_ambig_ids ( rid ) ) ;
-
 
2068
			    rid = resolve_ambig_func ( ids, 0 ) ;
2084
		id = rescan_func_id(id, q);
2069
			    if ( IS_NULL_id ( rid ) ) {
-
 
2070
				rid = DEREF_id ( HEAD_list ( ids ) ) ;
-
 
2071
			    }
-
 
2072
			} else {
-
 
2073
			    e = NULL_exp ;
-
 
2074
			    rid = NULL_id ;
-
 
2075
			}
-
 
2076
		    }
-
 
2077
		    if ( !IS_NULL_id ( rid ) ) {
-
 
2078
			/* Unique resolution */
-
 
2079
			report ( crt_loc, ERR_over_over_ok ( rid ) ) ;
-
 
2080
			e = make_resolved_exp ( rid, q, b, addr, paren ) ;
-
 
2081
			if ( use ) use_id ( rid, suppress_usage ) ;
-
 
2082
		    }
-
 
2083
		} else {
-
 
2084
		    /* Unsuccessful resolution */
-
 
2085
		    if ( use ) {
-
 
2086
			add_error ( err, ERR_over_over_none ( id, fn ) ) ;
-
 
2087
			e = make_error_exp ( 0 ) ;
-
 
2088
		    } else {
-
 
2089
			e = NULL_exp ;
-
 
2090
		    }
-
 
2091
		}
-
 
2092
	    } else {
-
 
2093
		/* No context for resolution */
-
 
2094
		if ( tag == id_undef_tag ) goto default_lab ;
-
 
2095
		if ( use ) {
-
 
2096
		    add_error ( err, ERR_over_over_context ( id ) ) ;
-
 
2097
		    e = make_error_exp ( 0 ) ;
-
 
2098
		} else {
-
 
2099
		    e = NULL_exp ;
-
 
2100
		}
-
 
2101
	    }
-
 
2102
	    break ;
-
 
2103
	}
2085
	}
-
 
2086
	q |= qual_mark;
2104
 
2087
 
-
 
2088
	/* Check for overloaded functions */
-
 
2089
	tag = TAG_id(id);
-
 
2090
	switch (tag) {
-
 
2091
	case id_function_tag:
-
 
2092
	case id_mem_func_tag:
-
 
2093
	case id_stat_mem_func_tag:
-
 
2094
function_lab: {
-
 
2095
		       /* Check functions for overloading */
-
 
2096
		       TYPE s;
-
 
2097
		       IDENTIFIER over;
-
 
2098
		       if (rescan) {
-
 
2099
			       goto overload_lab;
-
 
2100
		       }
-
 
2101
		       if (dependent_cast(id, t)) {
-
 
2102
			       /* Allow for template parameters */
-
 
2103
			       if (!IS_type_func(t)) {
-
 
2104
				       t = rvalue_type(t);
-
 
2105
			       }
-
 
2106
			       MAKE_exp_op(t, lex_function, e, NULL_exp, e);
-
 
2107
			       return (e);
-
 
2108
		       }
-
 
2109
		       over = DEREF_id(id_function_etc_over(id));
-
 
2110
		       if (!IS_NULL_id(over)) {
-
 
2111
			       goto overload_lab;
-
 
2112
		       }
-
 
2113
		       s = DEREF_type(id_function_etc_type(id));
-
 
2114
		       if (IS_type_templ(s)) {
-
 
2115
			       goto overload_lab;
-
 
2116
		       }
-
 
2117
		       if (tag == id_mem_func_tag) {
-
 
2118
			       if (!IS_NULL_exp(b) || addr) {
-
 
2119
				       /* Force error in this case */
-
 
2120
				       e = make_resolved_exp(id, q, b, addr,
-
 
2121
							     paren);
-
 
2122
			       }
-
 
2123
		       }
-
 
2124
		       if (use) {
-
 
2125
			       COPY_qual(exp_identifier_etc_qual(a), q);
-
 
2126
			       use_id(id, suppress_usage);
-
 
2127
		       }
-
 
2128
		       break;
-
 
2129
	       }
-
 
2130
 
-
 
2131
	case id_ambig_tag:
-
 
2132
	case id_undef_tag:
-
 
2133
overload_lab: {
-
 
2134
		      /* Overloaded and ambiguous functions */
-
 
2135
		      TYPE fn = find_func_type(t);
-
 
2136
		      if (!IS_NULL_type(fn)) {
-
 
2137
			      /* Overload resolution */
-
 
2138
			      int eq = 0;
-
 
2139
			      IDENTIFIER rid;
-
 
2140
			      if (dependent_cast(id, t)) {
-
 
2141
				      /* Allow for template parameters */
-
 
2142
				      if (!IS_type_func(t)) {
-
 
2143
					      t = rvalue_type(t);
-
 
2144
				      }
-
 
2145
				      MAKE_exp_op(t, lex_function, e, NULL_exp,
-
 
2146
						  e);
-
 
2147
				      return (e);
-
 
2148
			      }
-
 
2149
			      if (tag == id_undef_tag) {
-
 
2150
				      goto default_lab;
-
 
2151
			      }
-
 
2152
			      rid = resolve_func(id, fn, 1, 0, pids, &eq);
-
 
2153
			      if (!IS_NULL_id(rid)) {
-
 
2154
				      if (IS_id_ambig(rid)) {
-
 
2155
					      /* Ambiguous resolution */
-
 
2156
					      if (use) {
-
 
2157
						      /* Select one function */
-
 
2158
						      LIST(IDENTIFIER) ids;
-
 
2159
						      IGNORE report_ambiguous(rid, 0, 0, 0);
-
 
2160
						      ids = DEREF_list(id_ambig_ids(rid));
-
 
2161
						      rid = resolve_ambig_func(ids, 0);
-
 
2162
						      if (IS_NULL_id(rid)) {
-
 
2163
							      rid = DEREF_id(HEAD_list(ids));
-
 
2164
						      }
-
 
2165
					      } else {
-
 
2166
						      e = NULL_exp;
-
 
2167
						      rid = NULL_id;
-
 
2168
					      }
-
 
2169
				      }
-
 
2170
				      if (!IS_NULL_id(rid)) {
-
 
2171
					      /* Unique resolution */
-
 
2172
					      report(crt_loc, ERR_over_over_ok(rid));
-
 
2173
					      e = make_resolved_exp(rid, q, b, addr, paren);
-
 
2174
					      if (use) {
-
 
2175
						      use_id(rid, suppress_usage);
-
 
2176
					      }
-
 
2177
				      }
-
 
2178
			      } else {
-
 
2179
				      /* Unsuccessful resolution */
-
 
2180
				      if (use) {
-
 
2181
					      add_error(err, ERR_over_over_none(id, fn));
-
 
2182
					      e = make_error_exp(0);
-
 
2183
				      } else {
-
 
2184
					      e = NULL_exp;
-
 
2185
				      }
-
 
2186
			      }
-
 
2187
		      } else {
-
 
2188
			      /* No context for resolution */
-
 
2189
			      if (tag == id_undef_tag) {
-
 
2190
				      goto default_lab;
-
 
2191
			      }
-
 
2192
			      if (use) {
-
 
2193
				      add_error(err, ERR_over_over_context(id));
-
 
2194
				      e = make_error_exp(0);
-
 
2195
			      } else {
-
 
2196
				      e = NULL_exp;
-
 
2197
			      }
-
 
2198
		      }
-
 
2199
		      break;
-
 
2200
	      }
-
 
2201
 
2105
	default :
2202
	default:
2106
	default_lab : {
2203
default_lab:
2107
	    /* Other identifiers */
2204
	      /* Other identifiers */
2108
	    if ( rescan ) {
2205
	      if (rescan) {
2109
		if ( use ) {
2206
		      if (use) {
2110
		    EXP c = implicit_id_exp ( id, 1 ) ;
2207
			      EXP c = implicit_id_exp(id, 1);
2111
		    if ( IS_exp_identifier_etc ( c ) ) {
2208
			      if (IS_exp_identifier_etc(c)) {
2112
			id = DEREF_id ( exp_identifier_etc_id ( a ) ) ;
2209
				      id = DEREF_id(exp_identifier_etc_id(a));
2113
			if ( IS_id_function_etc ( id ) ) {
2210
				      if (IS_id_function_etc(id)) {
2114
			    goto function_lab ;
2211
					      goto function_lab;
2115
			}
2212
				      }
2116
		    }
2213
			      }
2117
		} else {
2214
		      } else {
2118
		    e = NULL_exp ;
2215
			      e = NULL_exp;
2119
		}
2216
		      }
2120
	    }
2217
	      }
2121
	    break ;
2218
	      break;
2122
	}
2219
	}
2123
    }
-
 
2124
    return ( e ) ;
2220
	return (e);
2125
}
2221
}