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

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

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

Subversion Repositories tendra.SVN

Rev

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

Rev 5 Rev 6
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2006 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997, 1998
32
    		 Crown Copyright (c) 1997, 1998
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
Line 87... Line 117...
87
    CHECK A FUNCTION RETURN TYPE
117
    CHECK A FUNCTION RETURN TYPE
88
 
118
 
89
    This routine checks whether the type t is a suitable function return
119
    This routine checks whether the type t is a suitable function return
90
    type.  This can be void (unqualified) or a complete type.  def is
120
    type.  This can be void (unqualified) or a complete type.  def is
91
    true for a function definition or call, but false otherwise.
121
    true for a function definition or call, but false otherwise.
92
*/
122
*/
93
 
123
 
94
TYPE check_ret_type
124
TYPE
95
    PROTO_N ( ( t, err, def ) )
-
 
96
    PROTO_T ( TYPE t X ERROR *err X int def )
125
check_ret_type(TYPE t, ERROR *err, int def)
97
{
126
{
98
    CV_SPEC cv = DEREF_cv ( type_qual ( t ) ) ;
127
	CV_SPEC cv = DEREF_cv(type_qual(t));
99
    cv &= cv_qual ;
128
	cv &= cv_qual;
100
    if ( IS_type_top_etc ( t ) ) {
129
	if (IS_type_top_etc(t)) {
101
	if ( cv != cv_none && !def ) {
130
		if (cv != cv_none && !def) {
102
	    /* Can't return 'cv void' */
131
			/* Can't return 'cv void' */
103
	    add_error ( err, ERR_dcl_fct_ret_void ( t ) ) ;
132
			add_error(err, ERR_dcl_fct_ret_void(t));
104
	    if ( ( cv & cv_volatile ) && IS_type_top ( t ) ) {
133
			if ((cv & cv_volatile) && IS_type_top(t)) {
105
		/* Map 'volatile void' to 'bottom' */
134
				/* Map 'volatile void' to 'bottom' */
106
		t = type_bottom ;
135
				t = type_bottom;
107
		cv &= ~cv_volatile ;
136
				cv &= ~cv_volatile;
108
		t = qualify_type ( t, cv, 0 ) ;
137
				t = qualify_type(t, cv, 0);
109
	    }
138
			}
110
	}
139
		}
111
    } else {
140
	} else {
-
 
141
		if (def) {
112
	if ( def ) add_error ( err, check_incomplete ( t ) ) ;
142
			add_error(err, check_incomplete(t));
113
    }
143
		}
-
 
144
	}
114
    if ( cv != cv_none && !def ) {
145
	if (cv != cv_none && !def) {
115
	/* Check for cv-qualified return types */
146
		/* Check for cv-qualified return types */
116
	add_error ( err, ERR_dcl_fct_cv_ret ( cv ) ) ;
147
		add_error(err, ERR_dcl_fct_cv_ret(cv));
117
    }
148
	}
118
    return ( t ) ;
149
	return (t);
119
}
150
}
120
 
151
 
121
 
152
 
122
/*
153
/*
123
    APPLY REFERENCE CONVERSIONS TO A LIST OF EXPRESSIONS
154
    APPLY REFERENCE CONVERSIONS TO A LIST OF EXPRESSIONS
124
 
155
 
125
    This routine applies reference conversions to each element of the
156
    This routine applies reference conversions to each element of the
126
    argument list args.
157
    argument list args.
127
*/
158
*/
128
 
159
 
129
LIST ( EXP ) convert_args
160
LIST(EXP)
130
    PROTO_N ( ( args ) )
-
 
131
    PROTO_T ( LIST ( EXP ) args )
161
convert_args(LIST(EXP) args)
132
{
162
{
133
    LIST ( EXP ) p = args ;
163
	LIST(EXP)p = args;
134
    while ( !IS_NULL_list ( p ) ) {
164
	while (!IS_NULL_list(p)) {
135
	EXP e = DEREF_exp ( HEAD_list ( p ) ) ;
165
		EXP e = DEREF_exp(HEAD_list(p));
136
	if ( !IS_NULL_exp ( e ) ) {
166
		if (!IS_NULL_exp(e)) {
137
	    e = convert_reference ( e, REF_ASSIGN ) ;
167
			e = convert_reference(e, REF_ASSIGN);
138
	    COPY_exp ( HEAD_list ( p ), e ) ;
168
			COPY_exp(HEAD_list(p), e);
139
	}
169
		}
140
	p = TAIL_list ( p ) ;
170
		p = TAIL_list(p);
141
    }
171
	}
142
    return ( args ) ;
172
	return (args);
143
}
173
}
144
 
174
 
145
 
175
 
146
/*
176
/*
147
    FIND MINIMUM NUMBER OF ARGUMENTS FOR A FUNCTION
177
    FIND MINIMUM NUMBER OF ARGUMENTS FOR A FUNCTION
148
 
178
 
149
    This routine calculates the minimum number of arguments for the function
179
    This routine calculates the minimum number of arguments for the function
150
    type fn, taking default arguments and weak prototypes into account.
180
    type fn, taking default arguments and weak prototypes into account.
151
    The extra argument for member functions is included.
181
    The extra argument for member functions is included.
152
*/
182
*/
153
 
183
 
154
unsigned min_no_args
184
unsigned
155
    PROTO_N ( ( fn ) )
-
 
156
    PROTO_T ( TYPE fn )
185
min_no_args(TYPE fn)
157
{
186
{
158
    unsigned n = 0 ;
187
	unsigned n = 0;
159
    LIST ( TYPE ) ptypes ;
188
	LIST(TYPE)ptypes;
160
    LIST ( TYPE ) mtypes ;
189
	LIST(TYPE)mtypes;
161
    LIST ( IDENTIFIER ) p ;
190
	LIST(IDENTIFIER)p;
162
    while ( IS_type_templ ( fn ) ) {
191
	while (IS_type_templ(fn)) {
163
	fn = DEREF_type ( type_templ_defn ( fn ) ) ;
192
		fn = DEREF_type(type_templ_defn(fn));
164
    }
-
 
165
    p = DEREF_list ( type_func_pids ( fn ) ) ;
-
 
166
    ptypes = DEREF_list ( type_func_ptypes ( fn ) ) ;
-
 
167
    mtypes = DEREF_list ( type_func_mtypes ( fn ) ) ;
-
 
168
    if ( !EQ_list ( mtypes, ptypes ) ) {
-
 
169
	/* Add one for member functions */
-
 
170
	if ( !IS_NULL_list ( mtypes ) ) {
-
 
171
	    mtypes = TAIL_list ( mtypes ) ;
-
 
172
	    if ( EQ_list ( mtypes, ptypes ) ) n = 1 ;
-
 
173
	}
193
	}
-
 
194
	p = DEREF_list(type_func_pids(fn));
-
 
195
	ptypes = DEREF_list(type_func_ptypes(fn));
-
 
196
	mtypes = DEREF_list(type_func_mtypes(fn));
-
 
197
	if (!EQ_list(mtypes, ptypes)) {
-
 
198
		/* Add one for member functions */
-
 
199
		if (!IS_NULL_list(mtypes)) {
-
 
200
			mtypes = TAIL_list(mtypes);
-
 
201
			if (EQ_list(mtypes, ptypes)) {
-
 
202
				n = 1;
174
    }
203
			}
-
 
204
		}
-
 
205
	}
175
    while ( !IS_NULL_list ( p ) ) {
206
	while (!IS_NULL_list(p)) {
176
	/* Scan for default arguments */
207
		/* Scan for default arguments */
177
	IDENTIFIER id = DEREF_id ( HEAD_list ( p ) ) ;
208
		IDENTIFIER id = DEREF_id(HEAD_list(p));
178
	EXP e = DEREF_exp ( id_parameter_init ( id ) ) ;
209
		EXP e = DEREF_exp(id_parameter_init(id));
179
	if ( !IS_NULL_exp ( e ) ) break ;
210
		if (!IS_NULL_exp(e)) {
-
 
211
			break;
-
 
212
		}
180
	n++ ;
213
		n++;
181
	p = TAIL_list ( p ) ;
214
		p = TAIL_list(p);
182
    }
215
	}
183
    return ( n ) ;
216
	return (n);
184
}
217
}
185
 
218
 
186
 
219
 
187
/*
220
/*
188
    CHECK FUNCTION DEFAULT ARGUMENTS
221
    CHECK FUNCTION DEFAULT ARGUMENTS
Line 190... Line 223...
190
    This routine checks the default arguments for the function type fn,
223
    This routine checks the default arguments for the function type fn,
191
    returning true if there is a default argument.  Missing default
224
    returning true if there is a default argument.  Missing default
192
    arguments are checked if chk is true.
225
    arguments are checked if chk is true.
193
*/
226
*/
194
 
227
 
195
int check_func_dargs
228
int
196
    PROTO_N ( ( fn, chk, clr ) )
-
 
197
    PROTO_T ( TYPE fn X int chk X int clr )
229
check_func_dargs(TYPE fn, int chk, int clr)
198
{
230
{
199
    int started = 0 ;
231
	int started = 0;
200
    unsigned tag = TAG_type ( fn ) ;
232
	unsigned tag = TAG_type(fn);
201
    while ( tag == type_templ_tag ) {
233
	while (tag == type_templ_tag) {
202
	fn = DEREF_type ( type_templ_defn ( fn ) ) ;
234
		fn = DEREF_type(type_templ_defn(fn));
203
	tag = TAG_type ( fn ) ;
235
		tag = TAG_type(fn);
204
    }
236
	}
205
    if ( tag == type_func_tag ) {
237
	if (tag == type_func_tag) {
206
	LIST ( IDENTIFIER ) pids = DEREF_list ( type_func_pids ( fn ) ) ;
238
		LIST(IDENTIFIER)pids = DEREF_list(type_func_pids(fn));
207
	while ( !IS_NULL_list ( pids ) ) {
239
		while (!IS_NULL_list(pids)) {
208
	    IDENTIFIER pid = DEREF_id ( HEAD_list ( pids ) ) ;
240
			IDENTIFIER pid = DEREF_id(HEAD_list(pids));
209
	    EXP a = DEREF_exp ( id_parameter_init ( pid ) ) ;
241
			EXP a = DEREF_exp(id_parameter_init(pid));
210
	    if ( IS_NULL_exp ( a ) ) {
242
			if (IS_NULL_exp(a)) {
211
		if ( started && !clr ) {
243
				if (started && !clr) {
212
		    /* Missing default arguments */
244
					/* Missing default arguments */
213
		    TYPE s ;
245
					TYPE s;
214
		    LOCATION loc ;
246
					LOCATION loc;
215
		    DEREF_loc ( id_loc ( pid ), loc ) ;
247
					DEREF_loc(id_loc(pid), loc);
216
		    report ( loc, ERR_dcl_fct_default_missing ( pid ) ) ;
248
					report(loc, ERR_dcl_fct_default_missing(pid));
217
		    s = DEREF_type ( id_parameter_type ( pid ) ) ;
249
					s = DEREF_type(id_parameter_type(pid));
218
		    MAKE_exp_value ( s, a ) ;
250
					MAKE_exp_value(s, a);
219
		    COPY_exp ( id_parameter_init ( pid ), a ) ;
251
					COPY_exp(id_parameter_init(pid), a);
-
 
252
				}
-
 
253
			} else {
-
 
254
				started = 1;
-
 
255
				if (clr) {
-
 
256
					/* Clear default argument */
-
 
257
					COPY_exp(id_parameter_init(pid),
-
 
258
						 NULL_exp);
-
 
259
				} else {
-
 
260
					if (!chk) {
-
 
261
						break;
-
 
262
					}
-
 
263
				}
-
 
264
			}
-
 
265
			pids = TAIL_list(pids);
220
		}
266
		}
221
	    } else {
-
 
222
		started = 1 ;
-
 
223
		if ( clr ) {
-
 
224
		    /* Clear default argument */
-
 
225
		    COPY_exp ( id_parameter_init ( pid ), NULL_exp ) ;
-
 
226
		} else {
-
 
227
		    if ( !chk ) break ;
-
 
228
		}
-
 
229
	    }
-
 
230
	    pids = TAIL_list ( pids ) ;
-
 
231
	}
267
	}
232
    }
-
 
233
    return ( started ) ;
268
	return (started);
234
}
269
}
235
 
270
 
236
 
271
 
237
/*
272
/*
238
    CHECK A WEAK PROTOTYPE ARGUMENT
273
    CHECK A WEAK PROTOTYPE ARGUMENT
Line 240... Line 275...
240
    This routine checks the expression a passed as an argument to a weak
275
    This routine checks the expression a passed as an argument to a weak
241
    function parameter of type t.  It returns the composite of t and the
276
    function parameter of type t.  It returns the composite of t and the
242
    type of a, adding any errors to err.
277
    type of a, adding any errors to err.
243
*/
278
*/
244
 
279
 
245
static TYPE check_weak_arg
280
static TYPE
246
    PROTO_N ( ( t, a, err ) )
-
 
247
    PROTO_T ( TYPE t X EXP a X ERROR *err )
281
check_weak_arg(TYPE t, EXP a, ERROR *err)
248
{
282
{
249
    ERROR err2 = NULL_err ;
283
	ERROR err2 = NULL_err;
250
    TYPE s = DEREF_type ( exp_type ( a ) ) ;
284
	TYPE s = DEREF_type(exp_type(a));
251
    if ( IS_exp_int_lit ( a ) && eq_type_offset ( s, t ) ) {
285
	if (IS_exp_int_lit(a) && eq_type_offset(s, t)) {
252
	/* Allow for integer literals */
286
		/* Allow for integer literals */
253
	NAT n = DEREF_nat ( exp_int_lit_nat ( a ) ) ;
287
		NAT n = DEREF_nat(exp_int_lit_nat(a));
254
	if ( check_nat_range ( t, n ) == 0 ) return ( t ) ;
288
		if (check_nat_range(t, n) == 0) {
-
 
289
			return (t);
255
    }
290
		}
-
 
291
	}
256
    t = check_compatible ( t, s, 2, &err2, 1 ) ;
292
	t = check_compatible(t, s, 2, &err2, 1);
257
    if ( !IS_NULL_err ( err2 ) ) {
293
	if (!IS_NULL_err(err2)) {
258
	err2 = set_severity ( err2, OPT_whatever, 0 ) ;
294
		err2 = set_severity(err2, OPT_whatever, 0);
259
	add_error ( err, err2 ) ;
295
		add_error(err, err2);
260
    }
296
	}
261
    return ( t ) ;
297
	return (t);
262
}
298
}
263
 
299
 
264
 
300
 
265
/*
301
/*
266
    PERFORM WEAK PROTOTYPE ANALYSIS
302
    PERFORM WEAK PROTOTYPE ANALYSIS
267
 
303
 
268
    This routine performs weak prototype analysis for a call to the
304
    This routine performs weak prototype analysis for a call to the
269
    function id with the arguments args.  It is only called when the
305
    function id with the arguments args.  It is only called when the
270
    number of arguments matches the function type.
306
    number of arguments matches the function type.
271
*/
307
*/
272
 
308
 
273
static void check_weak_args
309
static void
274
    PROTO_N ( ( id, args, n ) )
-
 
275
    PROTO_T ( IDENTIFIER id X LIST ( EXP ) args X unsigned n )
310
check_weak_args(IDENTIFIER id, LIST(EXP) args, unsigned n)
276
{
311
{
277
    TYPE fn = DEREF_type ( id_function_etc_type ( id ) ) ;
312
	TYPE fn = DEREF_type(id_function_etc_type(id));
278
    if ( IS_type_func ( fn ) ) {
313
	if (IS_type_func(fn)) {
279
	int changed = 0 ;
314
		int changed = 0;
280
	int ell = DEREF_int ( type_func_ellipsis ( fn ) ) ;
315
		int ell = DEREF_int(type_func_ellipsis(fn));
281
	LIST ( TYPE ) p = DEREF_list ( type_func_ptypes ( fn ) ) ;
316
		LIST(TYPE) p = DEREF_list(type_func_ptypes(fn));
282
	LIST ( TYPE ) q = NULL_list ( TYPE ) ;
317
		LIST(TYPE) q = NULL_list(TYPE);
283
	LIST ( IDENTIFIER ) pids = NULL_list ( IDENTIFIER ) ;
318
		LIST(IDENTIFIER) pids = NULL_list(IDENTIFIER);
284
	if ( ell == FUNC_WEAK_ARGS ) changed = 1 ;
319
		if (ell == FUNC_WEAK_ARGS) {
-
 
320
			changed = 1;
-
 
321
		}
285
	while ( !IS_NULL_list ( p ) ) {
322
		while (!IS_NULL_list(p)) {
286
	    /* Check parameter types */
323
			/* Check parameter types */
287
	    TYPE s = DEREF_type ( HEAD_list ( p ) ) ;
324
			TYPE s = DEREF_type(HEAD_list(p));
288
	    if ( !IS_NULL_list ( args ) ) {
325
			if (!IS_NULL_list(args)) {
289
		ERROR err = NULL_err ;
326
				ERROR err = NULL_err;
290
		EXP a = DEREF_exp ( HEAD_list ( args ) ) ;
327
				EXP a = DEREF_exp(HEAD_list(args));
291
		TYPE t = check_weak_arg ( s, a, &err ) ;
328
				TYPE t = check_weak_arg(s, a, &err);
292
		if ( !IS_NULL_err ( err ) ) {
329
				if (!IS_NULL_err(err)) {
293
		    /* Report incompatible argument types */
330
					/* Report incompatible argument types */
294
		    PTR ( LOCATION ) loc = id_loc ( id ) ;
331
					PTR(LOCATION)loc = id_loc(id);
-
 
332
					ERROR err2 =
295
		    ERROR err2 = ERR_expr_call_weak_arg ( n, loc ) ;
333
					    ERR_expr_call_weak_arg(n, loc);
296
		    err = concat_error ( ERR_expr_call_func ( id ), err ) ;
334
					err = concat_error(ERR_expr_call_func(id), err);
297
		    err = concat_error ( err, err2 ) ;
335
					err = concat_error(err, err2);
298
		    report ( crt_loc, err ) ;
336
					report(crt_loc, err);
299
		}
337
				}
300
		if ( !EQ_type ( t, s ) ) {
338
				if (!EQ_type(t, s)) {
301
		    if ( changed ) changed = 1 ;
339
					if (changed) {
-
 
340
						changed = 1;
-
 
341
					}
302
		    s = t ;
342
					s = t;
-
 
343
				}
-
 
344
				args = TAIL_list(args);
-
 
345
				n++;
-
 
346
			}
-
 
347
			if (changed) {
-
 
348
				CONS_type(s, q, q);
-
 
349
			}
-
 
350
			p = TAIL_list(p);
-
 
351
		}
-
 
352
		if (ell == FUNC_NO_PARAMS) {
-
 
353
			/* Previous declaration was 'id()' */
-
 
354
			LOCATION loc;
-
 
355
			int par = CONTEXT_PARAMETER;
-
 
356
			NAMESPACE ns = DEREF_nspace(type_func_pars(fn));
-
 
357
			loc = decl_loc;
-
 
358
			decl_loc = crt_loc;
-
 
359
			push_namespace(ns);
-
 
360
			while (!IS_NULL_list(args)) {
-
 
361
				HASHID nm = lookup_anon();
-
 
362
				EXP a = DEREF_exp(HEAD_list(args));
-
 
363
				TYPE t = DEREF_type(exp_type(a));
-
 
364
				IDENTIFIER pid = DEREF_id(hashid_id(nm));
-
 
365
				pid = make_param_decl(dspec_none, t, pid, par);
-
 
366
				init_param(pid, NULL_exp);
-
 
367
				CONS_id(pid, pids, pids);
-
 
368
				CONS_type(t, q, q);
-
 
369
				args = TAIL_list(args);
-
 
370
			}
-
 
371
			IGNORE pop_namespace();
-
 
372
			ell = FUNC_WEAK_ARGS;
-
 
373
			decl_loc = loc;
-
 
374
			changed = 2;
-
 
375
		}
-
 
376
		if (changed == 2) {
-
 
377
			q = REVERSE_list(q);
-
 
378
			fn = copy_typedef(id, fn, cv_none);
-
 
379
			COPY_list(type_func_ptypes(fn), q);
-
 
380
			COPY_list(type_func_mtypes(fn), q);
-
 
381
			if (!IS_NULL_list(pids)) {
-
 
382
				pids = REVERSE_list(pids);
-
 
383
				COPY_list(type_func_pids(fn), pids);
-
 
384
			}
-
 
385
			COPY_int(type_func_ellipsis(fn), ell);
-
 
386
			COPY_type(id_function_etc_type(id), fn);
-
 
387
			COPY_loc(id_loc(id), crt_loc);
-
 
388
			decl_func_type(id, fn, 0);
-
 
389
		} else {
-
 
390
			DESTROY_list(q, SIZE_type);
303
		}
391
		}
304
		args = TAIL_list ( args ) ;
-
 
305
		n++ ;
-
 
306
	    }
-
 
307
	    if ( changed ) CONS_type ( s, q, q ) ;
-
 
308
	    p = TAIL_list ( p ) ;
-
 
309
	}
-
 
310
	if ( ell == FUNC_NO_PARAMS ) {
-
 
311
	    /* Previous declaration was 'id ()' */
-
 
312
	    LOCATION loc ;
-
 
313
	    int par = CONTEXT_PARAMETER ;
-
 
314
	    NAMESPACE ns = DEREF_nspace ( type_func_pars ( fn ) ) ;
-
 
315
	    loc = decl_loc ;
-
 
316
	    decl_loc = crt_loc ;
-
 
317
	    push_namespace ( ns ) ;
-
 
318
	    while ( !IS_NULL_list ( args ) ) {
-
 
319
		HASHID nm = lookup_anon () ;
-
 
320
		EXP a = DEREF_exp ( HEAD_list ( args ) ) ;
-
 
321
		TYPE t = DEREF_type ( exp_type ( a ) ) ;
-
 
322
		IDENTIFIER pid = DEREF_id ( hashid_id ( nm ) ) ;
-
 
323
		pid = make_param_decl ( dspec_none, t, pid, par ) ;
-
 
324
		init_param ( pid, NULL_exp ) ;
-
 
325
		CONS_id ( pid, pids, pids ) ;
-
 
326
		CONS_type ( t, q, q ) ;
-
 
327
		args = TAIL_list ( args ) ;
-
 
328
	    }
-
 
329
	    IGNORE pop_namespace () ;
-
 
330
	    ell = FUNC_WEAK_ARGS ;
-
 
331
	    decl_loc = loc ;
-
 
332
	    changed = 2 ;
-
 
333
	}
-
 
334
	if ( changed == 2 ) {
-
 
335
	    q = REVERSE_list ( q ) ;
-
 
336
	    fn = copy_typedef ( id, fn, cv_none ) ;
-
 
337
	    COPY_list ( type_func_ptypes ( fn ), q ) ;
-
 
338
	    COPY_list ( type_func_mtypes ( fn ), q ) ;
-
 
339
	    if ( !IS_NULL_list ( pids ) ) {
-
 
340
		pids = REVERSE_list ( pids ) ;
-
 
341
		COPY_list ( type_func_pids ( fn ), pids ) ;
-
 
342
	    }
-
 
343
	    COPY_int ( type_func_ellipsis ( fn ), ell ) ;
-
 
344
	    COPY_type ( id_function_etc_type ( id ), fn ) ;
-
 
345
	    COPY_loc ( id_loc ( id ), crt_loc ) ;
-
 
346
	    decl_func_type ( id, fn, 0 ) ;
-
 
347
	} else {
-
 
348
	    DESTROY_list ( q, SIZE_type ) ;
-
 
349
	}
392
	}
350
    }
-
 
351
    return ;
393
	return;
352
}
394
}
353
 
395
 
354
 
396
 
355
/*
397
/*
356
    CHECK PRINTF AND SCANF ARGUMENTS
398
    CHECK PRINTF AND SCANF ARGUMENTS
357
 
399
 
358
    This routine performs weak prototype analysis for a call to the
400
    This routine performs weak prototype analysis for a call to the
359
    printf-like or scanf-like function id with the arguments args.  p gives
401
    printf-like or scanf-like function id with the arguments args.  p gives
360
    the parameter types deduced from the format string.
402
    the parameter types deduced from the format string.
361
*/
403
*/
362
 
404
 
363
static void check_printf_args
405
static void
364
    PROTO_N ( ( id, p, args, n, pf ) )
-
 
365
    PROTO_T ( IDENTIFIER id X LIST ( TYPE ) p X LIST ( EXP ) args X
406
check_printf_args(IDENTIFIER id, LIST(TYPE) p, LIST(EXP) args, unsigned n,
366
	      unsigned n X int pf )
407
		  int pf)
367
{
408
{
368
    unsigned np = LENGTH_list ( p ) + ( n - 1 ) ;
409
	unsigned np = LENGTH_list(p) + (n - 1);
369
    unsigned na = LENGTH_list ( args ) + ( n - 1 ) ;
410
	unsigned na = LENGTH_list(args) + (n - 1);
370
    if ( np != na ) {
411
	if (np != na) {
371
	/* Check number of parameters */
412
		/* Check number of parameters */
372
	ERROR err = ERR_expr_call_args_exact ( na, na, np ) ;
413
		ERROR err = ERR_expr_call_args_exact(na, na, np);
373
	err = set_severity ( err, OPT_weak, -1 ) ;
414
		err = set_severity(err, OPT_weak, -1);
374
	if ( !IS_NULL_id ( id ) ) {
415
		if (!IS_NULL_id(id)) {
375
	    err = concat_error ( ERR_expr_call_func ( id ), err ) ;
416
			err = concat_error(ERR_expr_call_func(id), err);
-
 
417
		}
-
 
418
		report(crt_loc, err);
376
	}
419
	}
377
	report ( crt_loc, err ) ;
-
 
378
    }
-
 
379
    while ( !IS_NULL_list ( p ) && !IS_NULL_list ( args ) ) {
420
	while (!IS_NULL_list(p) && !IS_NULL_list(args)) {
380
	/* Check parameter types */
421
		/* Check parameter types */
381
	ERROR err = NULL_err ;
422
		ERROR err = NULL_err;
382
	TYPE s = DEREF_type ( HEAD_list ( p ) ) ;
423
		TYPE s = DEREF_type(HEAD_list(p));
383
	EXP a = DEREF_exp ( HEAD_list ( args ) ) ;
424
		EXP a = DEREF_exp(HEAD_list(args));
384
	TYPE t = check_weak_arg ( s, a, &err ) ;
425
		TYPE t = check_weak_arg(s, a, &err);
385
	if ( !IS_NULL_err ( err ) ) {
426
		if (!IS_NULL_err(err)) {
386
	    /* Report incompatible argument types */
427
			/* Report incompatible argument types */
387
	    PTR ( LOCATION ) loc = NULL_ptr ( LOCATION ) ;
428
			PTR(LOCATION)loc = NULL_ptr(LOCATION);
388
	    if ( !IS_NULL_id ( id ) ) loc = id_loc ( id ) ;
429
			if (!IS_NULL_id(id)) {
-
 
430
				loc = id_loc(id);
-
 
431
			}
389
	    err = concat_error ( err, ERR_expr_call_weak_arg ( n, loc ) ) ;
432
			err = concat_error(err, ERR_expr_call_weak_arg(n, loc));
390
	} else {
433
		} else {
391
	    /* Check that scanf arguments aren't const */
434
			/* Check that scanf arguments aren't const */
392
	    if ( !( pf & 1 ) && IS_type_ptr ( t ) ) {
435
			if (!(pf & 1) && IS_type_ptr(t)) {
393
		CV_SPEC cv ;
436
				CV_SPEC cv;
394
		t = DEREF_type ( type_ptr_sub ( t ) ) ;
437
				t = DEREF_type(type_ptr_sub(t));
395
		cv = DEREF_cv ( type_qual ( t ) ) ;
438
				cv = DEREF_cv(type_qual(t));
396
		if ( cv & cv_const ) {
439
				if (cv & cv_const) {
397
		    err = ERR_conv_qual_cast ( cv_const ) ;
440
					err = ERR_conv_qual_cast(cv_const);
398
		    err = set_severity ( err, OPT_weak, -1 ) ;
441
					err = set_severity(err, OPT_weak, -1);
399
		}
442
				}
400
	    }
443
			}
401
	}
444
		}
402
	if ( !IS_NULL_err ( err ) ) {
445
		if (!IS_NULL_err(err)) {
403
	    if ( !IS_NULL_id ( id ) ) {
446
			if (!IS_NULL_id(id)) {
404
		err = concat_error ( ERR_expr_call_func ( id ), err ) ;
447
				err = concat_error(ERR_expr_call_func(id), err);
405
	    }
448
			}
406
	    report ( crt_loc, err ) ;
449
			report(crt_loc, err);
-
 
450
		}
-
 
451
		args = TAIL_list(args);
-
 
452
		p = TAIL_list(p);
-
 
453
		n++;
407
	}
454
	}
408
	args = TAIL_list ( args ) ;
-
 
409
	p = TAIL_list ( p ) ;
-
 
410
	n++ ;
-
 
411
    }
-
 
412
    return ;
455
	return;
413
}
456
}
414
 
457
 
415
 
458
 
416
/*
459
/*
417
    APPLY ARGUMENT CONVERSIONS TO A LIST OF EXPRESSIONS
460
    APPLY ARGUMENT CONVERSIONS TO A LIST OF EXPRESSIONS
Line 421... Line 464...
421
    functions are inherited.  The function return type is returned via pr.
464
    functions are inherited.  The function return type is returned via pr.
422
    The identifier id is used in error reporting only, it is the function
465
    The identifier id is used in error reporting only, it is the function
423
    being called for named functions and the null identifier otherwise.
466
    being called for named functions and the null identifier otherwise.
424
*/
467
*/
425
 
468
 
426
static LIST ( EXP ) cast_args
469
static LIST(EXP)
427
    PROTO_N ( ( id, fn, gr, args, pr, mem ) )
-
 
428
    PROTO_T ( IDENTIFIER id X TYPE fn X GRAPH gr X LIST ( EXP ) args X
470
cast_args(IDENTIFIER id, TYPE fn, GRAPH gr, LIST(EXP) args, TYPE *pr, int mem)
429
	      TYPE *pr X int mem )
-
 
430
{
471
{
431
    int ell ;
472
    int ell;
432
    TYPE ret ;
473
    TYPE ret;
433
    int extra = 0 ;
474
    int extra = 0;
434
    unsigned n = 1 ;
475
    unsigned n = 1;
435
    LIST ( EXP ) q ;
476
    LIST(EXP)q;
436
    LIST ( TYPE ) p ;
477
    LIST(TYPE)p;
437
    LIST ( TYPE ) ptypes ;
478
    LIST(TYPE)ptypes;
438
    LIST ( TYPE ) mtypes ;
479
    LIST(TYPE)mtypes;
439
    ERROR err = NULL_err ;
480
    ERROR err = NULL_err;
440
    int printf_function = 0 ;
481
    int printf_function = 0;
441
    LIST ( IDENTIFIER ) pids ;
482
    LIST(IDENTIFIER)pids;
442
    OPTION weak = OPTION_OFF ;
483
    OPTION weak = OPTION_OFF;
443
    LIST ( TYPE ) ftypes = NULL_list ( TYPE ) ;
484
    LIST(TYPE)ftypes = NULL_list(TYPE);
444
 
485
 
445
    /* Allow for template types */
486
    /* Allow for template types */
446
    if ( IS_type_templ ( fn ) ) {
487
    if (IS_type_templ(fn)) {
447
	int d ;
488
	int d;
448
	TOKEN sort = DEREF_tok ( type_templ_sort ( fn ) ) ;
489
	TOKEN sort = DEREF_tok(type_templ_sort(fn));
449
	pids = DEREF_list ( tok_templ_pids ( sort ) ) ;
490
	pids = DEREF_list(tok_templ_pids(sort));
450
	force_template++ ;
491
	force_template++;
451
	d = save_token_args ( pids, NULL_list ( TOKEN ) ) ;
492
	d = save_token_args(pids, NULL_list(TOKEN));
452
	fn = DEREF_type ( type_templ_defn ( fn ) ) ;
493
	fn = DEREF_type(type_templ_defn(fn));
453
	args = cast_args ( id, fn, gr, args, &ret, mem ) ;
494
	args = cast_args(id, fn, gr, args, &ret, mem);
454
	*pr = expand_type ( ret, 2 ) ;
495
	*pr = expand_type(ret, 2);
455
	restore_token_args ( pids, d ) ;
496
	restore_token_args(pids, d);
456
	force_template-- ;
497
	force_template--;
457
	return ( args ) ;
498
	return (args);
458
    }
499
    }
459
 
500
 
460
    /* Check function return type */
501
    /* Check function return type */
461
    ret = DEREF_type ( type_func_ret ( fn ) ) ;
502
    ret = DEREF_type(type_func_ret(fn));
462
    ret = check_ret_type ( ret, &err, 1 ) ;
503
    ret = check_ret_type(ret, &err, 1);
463
    if ( !IS_NULL_err ( err ) ) {
504
    if (!IS_NULL_err(err)) {
464
	err = concat_error ( err, ERR_expr_call_ret () ) ;
505
	err = concat_error(err, ERR_expr_call_ret());
465
	if ( !IS_NULL_id ( id ) ) {
506
	if (!IS_NULL_id(id)) {
466
	    err = concat_error ( ERR_expr_call_func ( id ), err ) ;
507
	    err = concat_error(ERR_expr_call_func(id), err);
467
	}
508
	}
468
	report ( crt_loc, err ) ;
509
	report(crt_loc, err);
469
    }
510
    }
470
    ret = convert_qual_type ( ret ) ;
511
    ret = convert_qual_type(ret);
471
    *pr = ret ;
512
    *pr = ret;
472
 
513
 
473
    /* Check number of arguments */
514
    /* Check number of arguments */
474
    ell = DEREF_int ( type_func_ellipsis ( fn ) ) ;
515
    ell = DEREF_int(type_func_ellipsis(fn));
475
    ptypes = DEREF_list ( type_func_ptypes ( fn ) ) ;
516
    ptypes = DEREF_list(type_func_ptypes(fn));
476
    mtypes = DEREF_list ( type_func_mtypes ( fn ) ) ;
517
    mtypes = DEREF_list(type_func_mtypes(fn));
477
    if ( !EQ_list ( mtypes, ptypes ) ) {
518
    if (!EQ_list(mtypes, ptypes)) {
478
	if ( mem ) {
519
	if (mem) {
479
	    /* Member function */
520
	    /* Member function */
480
	    extra = 1 ;
521
	    extra = 1;
481
	} else {
522
	} else {
482
	    fn = copy_typedef ( NULL_id, fn, cv_none ) ;
523
	    fn = copy_typedef(NULL_id, fn, cv_none);
483
	    mtypes = ptypes ;
524
	    mtypes = ptypes;
484
	    COPY_list ( type_func_mtypes ( fn ), mtypes ) ;
525
	    COPY_list(type_func_mtypes(fn), mtypes);
485
	}
526
	}
486
    }
527
    }
487
    if ( match_no_args == 0 ) {
528
    if (match_no_args == 0) {
488
	/* Weren't checked in overload resolution */
529
	/* Weren't checked in overload resolution */
489
	unsigned na = LENGTH_list ( args ) ;
530
	unsigned na = LENGTH_list(args);
490
	unsigned npars = LENGTH_list ( mtypes ) ;
531
	unsigned npars = LENGTH_list(mtypes);
491
	if ( na != npars ) {
532
	if (na != npars) {
492
	    int more = 0 ;
533
	    int more = 0;
493
	    unsigned margs = min_no_args ( fn ) ;
534
	    unsigned margs = min_no_args(fn);
494
	    if ( ell & FUNC_VAR_PARAMS ) more = 1 ;
535
	    if (ell & FUNC_VAR_PARAMS) {
-
 
536
		    more = 1;
-
 
537
	    }
495
	    if ( na < margs || ( na > npars && !more ) ) {
538
	    if (na < margs || (na > npars && !more)) {
496
		/* Illegal number of arguments */
539
		/* Illegal number of arguments */
497
		if ( extra ) {
540
		if (extra) {
498
		    /* Report actual numbers of passed arguments */
541
		    /* Report actual numbers of passed arguments */
499
		    na-- ;
542
		    na--;
500
		    npars-- ;
543
		    npars--;
501
		    margs-- ;
544
		    margs--;
502
		}
545
		}
503
		if ( more ) {
546
		if (more) {
504
		    err = ERR_expr_call_args_min ( na, na, margs ) ;
547
		    err = ERR_expr_call_args_min(na, na, margs);
505
		} else if ( npars == margs ) {
548
		} else if (npars == margs) {
506
		    err = ERR_expr_call_args_exact ( na, na, npars ) ;
549
		    err = ERR_expr_call_args_exact(na, na, npars);
507
		} else {
550
		} else {
508
		    err = ERR_expr_call_args_range ( na, na, margs, npars ) ;
551
		    err = ERR_expr_call_args_range(na, na, margs, npars);
509
		}
552
		}
510
		if ( ell & FUNC_NON_PROTO ) {
553
		if (ell & FUNC_NON_PROTO) {
511
		    /* Allowed for non-prototype functions */
554
		    /* Allowed for non-prototype functions */
512
		    err = set_severity ( err, OPT_weak, -1 ) ;
555
		    err = set_severity(err, OPT_weak, -1);
513
		}
556
		}
514
		if ( !IS_NULL_err ( err ) ) {
557
		if (!IS_NULL_err(err)) {
515
		    if ( !IS_NULL_id ( id ) ) {
558
		    if (!IS_NULL_id(id)) {
516
			ERROR err2 = ERR_expr_call_func ( id ) ;
559
			ERROR err2 = ERR_expr_call_func(id);
517
			err = concat_error ( err2, err ) ;
560
			err = concat_error(err2, err);
518
		    }
561
		    }
519
		    report ( crt_loc, err ) ;
562
		    report(crt_loc, err);
520
		}
563
		}
521
	    }
564
	    }
522
	}
565
	}
523
    }
566
    }
524
 
567
 
525
    /* Check function argument types */
568
    /* Check function argument types */
526
    p = mtypes ;
569
    p = mtypes;
527
    q = args ;
570
    q = args;
528
    pids = DEREF_list ( type_func_pids ( fn ) ) ;
571
    pids = DEREF_list(type_func_pids(fn));
529
 
572
 
530
    /* Extra implicit argument */
573
    /* Extra implicit argument */
531
    if ( extra && !IS_NULL_list ( p ) && !IS_NULL_list ( q ) ) {
574
    if (extra && !IS_NULL_list(p) && !IS_NULL_list(q)) {
532
	EXP b = DEREF_exp ( HEAD_list ( q ) ) ;
575
	EXP b = DEREF_exp(HEAD_list(q));
533
	TYPE t = DEREF_type ( HEAD_list ( p ) ) ;
576
	TYPE t = DEREF_type(HEAD_list(p));
534
	if ( !IS_NULL_exp ( b ) && !IS_NULL_type ( t ) ) {
577
	if (!IS_NULL_exp(b) && !IS_NULL_type(t)) {
535
	    /* Non-static member function called with object */
578
	    /* Non-static member function called with object */
536
	    TYPE u = t ;
579
	    TYPE u = t;
537
	    int temp = 1 ;
580
	    int temp = 1;
538
	    CLASS_TYPE cs, ct ;
581
	    CLASS_TYPE cs, ct;
539
	    TYPE s = DEREF_type ( exp_type ( b ) ) ;
582
	    TYPE s = DEREF_type(exp_type(b));
540
	    CV_SPEC qs = DEREF_cv ( type_qual ( s ) ) ;
583
	    CV_SPEC qs = DEREF_cv(type_qual(s));
541
	    CV_SPEC qt = DEREF_cv ( type_func_mqual ( fn ) ) ;
584
	    CV_SPEC qt = DEREF_cv(type_func_mqual(fn));
542
 
585
 
543
	    /* Check for temporary object */
586
	    /* Check for temporary object */
544
	    while ( IS_type_array ( s ) ) {
587
	    while (IS_type_array(s)) {
545
		s = DEREF_type ( type_array_sub ( s ) ) ;
588
		s = DEREF_type(type_array_sub(s));
546
		temp = 0 ;
-
 
547
	    }
-
 
548
	    while ( IS_type_ptr_etc ( s ) ) {
-
 
549
		s = DEREF_type ( type_ptr_etc_sub ( s ) ) ;
-
 
550
		temp = 0 ;
589
		temp = 0;
551
	    }
-
 
552
	    if ( temp ) {
-
 
553
		TYPE ps ;
-
 
554
		if ( !( qs & cv_lvalue ) ) {
-
 
555
		    ERROR ferr = NULL_err ;
-
 
556
		    b = make_temporary ( s, b, NULL_exp, 0, &ferr ) ;
-
 
557
		    if ( !IS_NULL_err ( ferr ) ) report ( crt_loc, ferr ) ;
-
 
558
		}
-
 
559
		MAKE_type_ptr ( cv_none, s, ps ) ;
-
 
560
		MAKE_exp_address ( ps, b, b ) ;
-
 
561
	    }
-
 
562
 
-
 
563
	    /* Check types for base class conversion */
-
 
564
	    while ( IS_type_ptr_etc ( t ) ) {
-
 
565
		t = DEREF_type ( type_ptr_etc_sub ( t ) ) ;
-
 
566
	    }
590
	    }
-
 
591
	    while (IS_type_ptr_etc(s)) {
-
 
592
		s = DEREF_type(type_ptr_etc_sub(s));
-
 
593
		temp = 0;
-
 
594
	    }
-
 
595
	    if (temp) {
-
 
596
		TYPE ps;
-
 
597
		if (!(qs & cv_lvalue)) {
-
 
598
		    ERROR ferr = NULL_err;
-
 
599
		    b = make_temporary(s, b, NULL_exp, 0, &ferr);
-
 
600
		    if (!IS_NULL_err(ferr)) {
-
 
601
			    report(crt_loc, ferr);
-
 
602
		    }
-
 
603
		}
-
 
604
		MAKE_type_ptr(cv_none, s, ps);
-
 
605
		MAKE_exp_address(ps, b, b);
-
 
606
	    }
-
 
607
 
-
 
608
	    /* Check types for base class conversion */
-
 
609
	    while (IS_type_ptr_etc(t)) {
-
 
610
		t = DEREF_type(type_ptr_etc_sub(t));
-
 
611
	    }
567
	    cs = DEREF_ctype ( type_compound_defn ( s ) ) ;
612
	    cs = DEREF_ctype(type_compound_defn(s));
568
	    ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
613
	    ct = DEREF_ctype(type_compound_defn(t));
569
	    if ( !eq_ctype ( cs, ct ) ) {
614
	    if (!eq_ctype(cs, ct)) {
570
		GRAPH gs = find_base_class ( cs, ct, 1 ) ;
615
		GRAPH gs = find_base_class(cs, ct, 1);
571
		if ( IS_NULL_graph ( gs ) ) {
616
		if (IS_NULL_graph(gs)) {
572
		    err = ERR_expr_ref_func_type ( cs ) ;
617
		    err = ERR_expr_ref_func_type(cs);
573
		} else {
618
		} else {
574
		    OFFSET off ;
619
		    OFFSET off;
575
		    err = check_ambig_base ( gs ) ;
620
		    err = check_ambig_base(gs);
576
		    if ( !IS_NULL_graph ( gr ) ) {
621
		    if (!IS_NULL_graph(gr)) {
577
			CLASS_TYPE cr = DEREF_ctype ( graph_head ( gr ) ) ;
622
			CLASS_TYPE cr = DEREF_ctype(graph_head(gr));
578
			if ( !eq_ctype ( cs, cr ) && !eq_ctype ( cr, ct ) ) {
623
			if (!eq_ctype(cs, cr) && !eq_ctype(cr, ct)) {
579
			    /* Inherited via intermediate base */
624
			    /* Inherited via intermediate base */
580
			    GRAPH g1 = find_base_class ( cs, cr, 1 ) ;
625
			    GRAPH g1 = find_base_class(cs, cr, 1);
581
			    if ( !IS_NULL_graph ( g1 ) ) {
626
			    if (!IS_NULL_graph(g1)) {
582
				GRAPH g2 = find_base_class ( cr, ct, 1 ) ;
627
				GRAPH g2 = find_base_class(cr, ct, 1);
583
				if ( !IS_NULL_graph ( g2 ) ) {
628
				if (!IS_NULL_graph(g2)) {
584
				    if ( !IS_NULL_err ( err ) ) {
629
				    if (!IS_NULL_err(err)) {
585
					ERROR err2 ;
630
					ERROR err2;
586
					destroy_error ( err, 1 ) ;
631
					destroy_error(err, 1);
587
					err = check_ambig_base ( g1 ) ;
632
					err = check_ambig_base(g1);
588
					err2 = check_ambig_base ( g2 ) ;
633
					err2 = check_ambig_base(g2);
589
					err = concat_error ( err, err2 ) ;
634
					err = concat_error(err, err2);
590
				    }
635
				    }
591
				    gs = DEREF_graph ( graph_top ( g2 ) ) ;
636
				    gs = DEREF_graph(graph_top(g2));
592
				    gs = find_subgraph ( g1, gs, g2 ) ;
637
				    gs = find_subgraph(g1, gs, g2);
593
				}
638
				}
594
			    }
639
			    }
595
			}
640
			}
596
		    }
641
		    }
597
		    if ( !IS_NULL_err ( err ) ) {
642
		    if (!IS_NULL_err(err)) {
598
			/* Report ambiguous bases */
643
			/* Report ambiguous bases */
599
			ERROR err2 = ERR_class_member_lookup_func () ;
644
			ERROR err2 = ERR_class_member_lookup_func();
600
			err = concat_error ( err, err2 ) ;
645
			err = concat_error(err, err2);
601
		    }
646
		    }
602
		    off = DEREF_off ( graph_off ( gs ) ) ;
647
		    off = DEREF_off(graph_off(gs));
603
		    b = make_base_cast ( u, b, off ) ;
648
		    b = make_base_cast(u, b, off);
604
		    /* Access should have been checked */
649
		    /* Access should have been checked */
605
		}
650
		}
606
		if ( !IS_NULL_err ( err ) ) {
651
		if (!IS_NULL_err(err)) {
607
		    if ( !IS_NULL_id ( id ) ) {
652
		    if (!IS_NULL_id(id)) {
608
			ERROR err2 = ERR_expr_call_func ( id ) ;
653
			ERROR err2 = ERR_expr_call_func(id);
609
			err = concat_error ( err2, err ) ;
654
			err = concat_error(err2, err);
610
		    }
655
		    }
611
		    report ( crt_loc, err ) ;
656
		    report(crt_loc, err);
612
		}
657
		}
613
	    }
658
	    }
614
 
659
 
615
	    /* Check type qualifiers */
660
	    /* Check type qualifiers */
616
	    qs &= cv_qual ;
661
	    qs &= cv_qual;
617
	    qt &= cv_qual ;
662
	    qt &= cv_qual;
-
 
663
	    if (qs != qt) {
618
	    if ( qs != qt ) MAKE_exp_cast ( u, CONV_QUAL, b, b ) ;
664
		    MAKE_exp_cast(u, CONV_QUAL, b, b);
-
 
665
	    }
619
	    qs = ( qs & ~qt ) ;
666
	    qs = (qs & ~qt);
620
	    if ( qs != cv_none ) {
667
	    if (qs != cv_none) {
621
		if ( IS_NULL_id ( id ) ) {
668
		if (IS_NULL_id(id)) {
622
		    err = ERR_class_this_qual ( qs ) ;
669
		    err = ERR_class_this_qual(qs);
623
		    report ( crt_loc, err ) ;
670
		    report(crt_loc, err);
624
		} else {
671
		} else {
625
		    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
672
		    HASHID nm = DEREF_hashid(id_name(id));
626
		    if ( !IS_hashid_destr ( nm ) ) {
673
		    if (!IS_hashid_destr(nm)) {
627
			/* Allowed for destructors */
674
			/* Allowed for destructors */
628
			ERROR err2 ;
675
			ERROR err2;
629
			err = ERR_class_this_qual ( qs ) ;
676
			err = ERR_class_this_qual(qs);
630
			err2 = ERR_expr_call_func ( id ) ;
677
			err2 = ERR_expr_call_func(id);
631
			err = concat_error ( err2, err ) ;
678
			err = concat_error(err2, err);
632
			report ( crt_loc, err ) ;
679
			report(crt_loc, err);
633
		    }
680
		    }
634
		}
681
		}
635
	    }
682
	    }
636
	    COPY_exp ( HEAD_list ( q ), b ) ;
683
	    COPY_exp(HEAD_list(q), b);
637
	}
684
	}
638
	p = TAIL_list ( p ) ;
685
	p = TAIL_list(p);
639
	q = TAIL_list ( q ) ;
686
	q = TAIL_list(q);
640
    }
687
    }
641
 
688
 
642
    /* Normal arguments */
689
    /* Normal arguments */
643
    if ( ell & FUNC_NON_PROTO ) {
690
    if (ell & FUNC_NON_PROTO) {
644
	weak = option ( OPT_weak ) ;
691
	weak = option(OPT_weak);
645
	goto ellipsis_lab ;
692
	goto ellipsis_lab;
646
    }
693
    }
647
    while ( !IS_NULL_list ( p ) && !IS_NULL_list ( q ) ) {
694
    while (!IS_NULL_list(p) && !IS_NULL_list(q)) {
648
	EXP b = DEREF_exp ( HEAD_list ( q ) ) ;
695
	EXP b = DEREF_exp(HEAD_list(q));
649
	TYPE t = DEREF_type ( HEAD_list ( p ) ) ;
696
	TYPE t = DEREF_type(HEAD_list(p));
650
	OPTION opt = option ( OPT_conv_int_int_impl ) ;
697
	OPTION opt = option(OPT_conv_int_int_impl);
-
 
698
	if (IS_NULL_exp(b)) {
651
	if ( IS_NULL_exp ( b ) ) b = make_error_exp ( 0 ) ;
699
		b = make_error_exp(0);
-
 
700
	}
652
	if ( IS_exp_paren ( b ) ) {
701
	if (IS_exp_paren(b)) {
653
	    /* Parentheses suppress conversion warnings */
702
	    /* Parentheses suppress conversion warnings */
654
	    b = DEREF_exp ( exp_paren_arg ( b ) ) ;
703
	    b = DEREF_exp(exp_paren_arg(b));
655
	    option ( OPT_conv_int_int_impl ) = OPTION_ALLOW ;
704
	    option(OPT_conv_int_int_impl) = OPTION_ALLOW;
656
	}
705
	}
657
	if ( IS_exp_string_lit ( b ) ) {
706
	if (IS_exp_string_lit(b)) {
658
	    if ( option ( OPT_printf_string ) ) {
707
	    if (option(OPT_printf_string)) {
659
		/* Check for printf and scanf strings */
708
		/* Check for printf and scanf strings */
660
		int pf = is_printf_type ( t ) ;
709
		int pf = is_printf_type(t);
661
		if ( pf ) {
710
		if (pf) {
662
		    unsigned na = LENGTH_list ( q ) + 100 ;
711
		    unsigned na = LENGTH_list(q) + 100;
663
		    STRING fmt = DEREF_str ( exp_string_lit_str ( b ) ) ;
712
		    STRING fmt = DEREF_str(exp_string_lit_str(b));
664
		    ftypes = find_printf_args ( fmt, na, pf ) ;
713
		    ftypes = find_printf_args(fmt, na, pf);
665
		    printf_function = pf ;
714
		    printf_function = pf;
666
		}
715
		}
667
	    }
716
	    }
668
	}
717
	}
669
	err = NULL_err ;
718
	err = NULL_err;
670
	b = init_assign ( t, cv_none, b, &err ) ;
719
	b = init_assign(t, cv_none, b, &err);
671
	if ( pass_complex_type ( t ) ) {
720
	if (pass_complex_type(t)) {
672
	    /* Create temporary variable */
721
	    /* Create temporary variable */
673
	    b = remove_temporary ( b, NULL_exp ) ;
722
	    b = remove_temporary(b, NULL_exp);
674
	    b = make_temporary ( t, b, NULL_exp, 0, &err ) ;
723
	    b = make_temporary(t, b, NULL_exp, 0, &err);
675
	    MAKE_type_ptr ( cv_none, t, t ) ;
724
	    MAKE_type_ptr(cv_none, t, t);
676
	    MAKE_exp_address ( t, b, b ) ;
725
	    MAKE_exp_address(t, b, b);
677
	}
726
	}
678
	if ( !IS_NULL_err ( err ) ) {
727
	if (!IS_NULL_err(err)) {
679
	    err = init_error ( err, 0 ) ;
728
	    err = init_error(err, 0);
680
	    err = concat_error ( err, ERR_expr_call_arg ( n ) ) ;
729
	    err = concat_error(err, ERR_expr_call_arg(n));
681
	    if ( !IS_NULL_id ( id ) ) {
730
	    if (!IS_NULL_id(id)) {
682
		err = concat_error ( ERR_expr_call_func ( id ), err ) ;
731
		err = concat_error(ERR_expr_call_func(id), err);
683
	    }
732
	    }
684
	    report ( crt_loc, err ) ;
733
	    report(crt_loc, err);
685
	}
734
	}
686
	option ( OPT_conv_int_int_impl ) = opt ;
735
	option(OPT_conv_int_int_impl) = opt;
687
	n++ ;
736
	n++;
688
	COPY_exp ( HEAD_list ( q ), b ) ;
737
	COPY_exp(HEAD_list(q), b);
689
	pids = TAIL_list ( pids ) ;
738
	pids = TAIL_list(pids);
690
	p = TAIL_list ( p ) ;
739
	p = TAIL_list(p);
691
	q = TAIL_list ( q ) ;
740
	q = TAIL_list(q);
692
    }
741
    }
693
 
742
 
694
    /* Default arguments */
743
    /* Default arguments */
695
    if ( !IS_NULL_list ( p ) ) {
744
    if (!IS_NULL_list(p)) {
696
	LIST ( EXP ) dargs = NULL_list ( EXP ) ;
745
	LIST(EXP)dargs = NULL_list(EXP);
697
	while ( !IS_NULL_list ( pids ) ) {
746
	while (!IS_NULL_list(pids)) {
698
	    IDENTIFIER pid = DEREF_id ( HEAD_list ( pids ) ) ;
747
	    IDENTIFIER pid = DEREF_id(HEAD_list(pids));
699
	    EXP e = DEREF_exp ( id_parameter_init ( pid ) ) ;
748
	    EXP e = DEREF_exp(id_parameter_init(pid));
700
	    if ( !IS_NULL_exp ( e ) ) {
749
	    if (!IS_NULL_exp(e)) {
701
		TYPE t = DEREF_type ( exp_type ( e ) ) ;
750
		TYPE t = DEREF_type(exp_type(e));
702
		if ( pass_complex_type ( t ) ) {
751
		if (pass_complex_type(t)) {
703
		    /* Create temporary variable */
752
		    /* Create temporary variable */
704
		    EXP d = DEREF_exp ( id_parameter_term ( pid ) ) ;
753
		    EXP d = DEREF_exp(id_parameter_term(pid));
705
		    if ( !IS_NULL_exp ( d ) ) {
754
		    if (!IS_NULL_exp(d)) {
706
			d = copy_exp ( d, NULL_type, NULL_type ) ;
755
			d = copy_exp(d, NULL_type, NULL_type);
707
		    }
756
		    }
708
		    err = NULL_err ;
757
		    err = NULL_err;
709
		    e = remove_temporary ( e, NULL_exp ) ;
758
		    e = remove_temporary(e, NULL_exp);
710
		    MAKE_exp_copy ( t, e, e ) ;
759
		    MAKE_exp_copy(t, e, e);
711
		    e = make_temporary ( t, e, d, 0, &err ) ;
760
		    e = make_temporary(t, e, d, 0, &err);
712
		    if ( !IS_NULL_err ( err ) ) {
761
		    if (!IS_NULL_err(err)) {
713
			err = concat_error ( err, ERR_expr_call_arg ( n ) ) ;
762
			err = concat_error(err, ERR_expr_call_arg(n));
714
			if ( !IS_NULL_id ( id ) ) {
763
			if (!IS_NULL_id(id)) {
715
			    ERROR err2 = ERR_expr_call_func ( id ) ;
764
			    ERROR err2 = ERR_expr_call_func(id);
716
			    err = concat_error ( err2, err ) ;
765
			    err = concat_error(err2, err);
717
			}
766
			}
718
			report ( crt_loc, err ) ;
767
			report(crt_loc, err);
719
		    }
768
		    }
720
		    MAKE_type_ptr ( cv_none, t, t ) ;
769
		    MAKE_type_ptr(cv_none, t, t);
721
		    MAKE_exp_address ( t, e, e ) ;
770
		    MAKE_exp_address(t, e, e);
722
		} else {
771
		} else {
723
		    MAKE_exp_copy ( t, e, e ) ;
772
		    MAKE_exp_copy(t, e, e);
724
		}
773
		}
725
		CONS_exp ( e, dargs, dargs ) ;
774
		CONS_exp(e, dargs, dargs);
726
		n++ ;
775
		n++;
727
	    }
776
	    }
728
	    pids = TAIL_list ( pids ) ;
777
	    pids = TAIL_list(pids);
729
	}
778
	}
730
	if ( !IS_NULL_list ( dargs ) ) {
779
	if (!IS_NULL_list(dargs)) {
731
	    dargs = REVERSE_list ( dargs ) ;
780
	    dargs = REVERSE_list(dargs);
732
	    args = APPEND_list ( args, dargs ) ;
781
	    args = APPEND_list(args, dargs);
733
	}
782
	}
734
    }
783
    }
735
 
784
 
736
    /* Ellipsis arguments */
785
    /* Ellipsis arguments */
737
    ellipsis_lab : {
786
    ellipsis_lab: {
738
	unsigned wn = n ;
787
	unsigned wn = n;
739
	LIST ( EXP ) wq = q ;
788
	LIST(EXP)wq = q;
740
	while ( !IS_NULL_list ( q ) ) {
789
	while (!IS_NULL_list(q)) {
741
	    TYPE t, s ;
790
	    TYPE t, s;
742
	    EXP b = DEREF_exp ( HEAD_list ( q ) ) ;
791
	    EXP b = DEREF_exp(HEAD_list(q));
-
 
792
	    if (IS_NULL_exp(b)) {
743
	    if ( IS_NULL_exp ( b ) ) b = make_error_exp ( 0 ) ;
793
		    b = make_error_exp(0);
-
 
794
	    }
744
	    b = convert_lvalue ( b ) ;
795
	    b = convert_lvalue(b);
745
	    b = convert_none ( b ) ;
796
	    b = convert_none(b);
746
	    t = DEREF_type ( exp_type ( b ) ) ;
797
	    t = DEREF_type(exp_type(b));
747
	    err = NULL_err ;
798
	    err = NULL_err;
748
	    s = arg_promote_type ( t, &err ) ;
799
	    s = arg_promote_type(t, &err);
749
	    if ( !EQ_type ( s, t ) ) {
800
	    if (!EQ_type(s, t)) {
750
		b = init_assign ( s, cv_none, b, &err ) ;
801
		b = init_assign(s, cv_none, b, &err);
751
	    }
802
	    }
752
	    if ( !IS_NULL_err ( err ) ) {
803
	    if (!IS_NULL_err(err)) {
753
		err = init_error ( err, 0 ) ;
804
		err = init_error(err, 0);
754
		err = concat_error ( err, ERR_expr_call_ellipsis ( n ) ) ;
805
		err = concat_error(err, ERR_expr_call_ellipsis(n));
755
		if ( !IS_NULL_id ( id ) ) {
806
		if (!IS_NULL_id(id)) {
756
		    err = concat_error ( ERR_expr_call_func ( id ), err ) ;
807
		    err = concat_error(ERR_expr_call_func(id), err);
757
		}
808
		}
758
		report ( crt_loc, err ) ;
809
		report(crt_loc, err);
759
	    }
810
	    }
760
	    COPY_exp ( HEAD_list ( q ), b ) ;
811
	    COPY_exp(HEAD_list(q), b);
761
	    n++ ;
812
	    n++;
762
	    q = TAIL_list ( q ) ;
813
	    q = TAIL_list(q);
763
	}
814
	}
764
	if ( weak && !IS_NULL_id ( id ) ) {
815
	if (weak && !IS_NULL_id(id)) {
765
	    /* Perform weak prototype analysis */
816
	    /* Perform weak prototype analysis */
766
	    check_weak_args ( id, wq, wn ) ;
817
	    check_weak_args(id, wq, wn);
767
	}
818
	}
768
	if ( printf_function ) {
819
	if (printf_function) {
769
	    /* Check printf arguments */
820
	    /* Check printf arguments */
770
	    if ( option ( OPT_weak ) ) {
821
	    if (option(OPT_weak)) {
771
		check_printf_args ( id, ftypes, wq, wn, printf_function ) ;
822
		check_printf_args(id, ftypes, wq, wn, printf_function);
772
	    }
823
	    }
773
	    DESTROY_list ( ftypes, SIZE_type ) ;
824
	    DESTROY_list(ftypes, SIZE_type);
774
	}
825
	}
775
    }
826
    }
776
    IGNORE check_value ( OPT_VAL_func_args, ( unsigned long ) ( n - 1 ) ) ;
827
    IGNORE check_value(OPT_VAL_func_args,(unsigned long)(n - 1));
777
    return ( args ) ;
828
    return (args);
778
}
829
}
779
 
830
 
780
 
831
 
781
/*
832
/*
782
    APPLY A NAMED FUNCTION TO A LIST OF EXPRESSIONS
833
    APPLY A NAMED FUNCTION TO A LIST OF EXPRESSIONS
783
 
834
 
784
    This routine applies the function id to the list of arguments args.
835
    This routine applies the function id to the list of arguments args.
785
    Any qualifiers used to express id are passed in as qual, since these
836
    Any qualifiers used to express id are passed in as qual, since these
786
    may suppress the virtual call mechanism.  gr gives the base class
837
    may suppress the virtual call mechanism.  gr gives the base class
787
    from which a member function is inherited.
838
    from which a member function is inherited.
788
*/
839
*/
789
 
840
 
790
EXP apply_func_id
841
EXP
791
    PROTO_N ( ( id, qual, gr, args ) )
-
 
792
    PROTO_T ( IDENTIFIER id X QUALIFIER qual X GRAPH gr X LIST ( EXP ) args )
842
apply_func_id(IDENTIFIER id, QUALIFIER qual, GRAPH gr, LIST(EXP)args)
793
{
843
{
794
    EXP e ;
844
	EXP e;
795
    TYPE fn ;
845
	TYPE fn;
796
    TYPE ret ;
846
	TYPE ret;
797
    DECL_SPEC ds ;
847
	DECL_SPEC ds;
798
    int throws = 1 ;
848
	int throws = 1;
799
    EXP virt = NULL_exp ;
849
	EXP virt = NULL_exp;
800
    IDENTIFIER fid = id ;
850
	IDENTIFIER fid = id;
801
 
851
 
802
    /* Check for non-functions */
852
	/* Check for non-functions */
803
    if ( !IS_id_function_etc ( id ) ) {
853
	if (!IS_id_function_etc(id)) {
804
	e = make_error_exp ( 0 ) ;
854
		e = make_error_exp(0);
805
	return ( e ) ;
855
		return (e);
806
    }
856
	}
807
 
857
 
808
    /* Check for inherited functions */
858
	/* Check for inherited functions */
809
    ds = DEREF_dspec ( id_storage ( id ) ) ;
859
	ds = DEREF_dspec(id_storage(id));
810
    if ( ds & dspec_inherit ) {
860
	if (ds & dspec_inherit) {
811
	id = DEREF_id ( id_alias ( id ) ) ;
861
		id = DEREF_id(id_alias(id));
812
	ds = DEREF_dspec ( id_storage ( id ) ) ;
862
		ds = DEREF_dspec(id_storage(id));
813
    }
863
	}
814
 
864
 
815
    /* Check for trivial functions */
865
	/* Check for trivial functions */
816
    if ( ds & dspec_trivial ) {
866
	if (ds & dspec_trivial) {
817
	e = apply_trivial_func ( id, args ) ;
867
		e = apply_trivial_func(id, args);
818
	if ( !IS_NULL_exp ( e ) ) {
868
		if (!IS_NULL_exp(e)) {
819
	    DESTROY_list ( args, SIZE_exp ) ;
869
			DESTROY_list(args, SIZE_exp);
820
	    return ( e ) ;
870
			return (e);
821
	}
871
		}
822
    }
872
	}
823
 
873
 
824
    /* Convert the arguments */
874
	/* Convert the arguments */
825
    fn = DEREF_type ( id_function_etc_type ( id ) ) ;
875
	fn = DEREF_type(id_function_etc_type(id));
826
    args = cast_args ( id, fn, gr, args, &ret, 1 ) ;
876
	args = cast_args(id, fn, gr, args, &ret, 1);
827
 
877
 
828
    /* Check for virtual function calls */
878
	/* Check for virtual function calls */
829
    if ( ds & dspec_virtual ) {
879
	if (ds & dspec_virtual) {
830
	if ( !( qual & qual_explicit ) ) {
880
		if (!(qual & qual_explicit)) {
831
	    EXP a = DEREF_exp ( HEAD_list ( args ) ) ;
881
			EXP a = DEREF_exp(HEAD_list(args));
832
	    int know = know_type ( a ) ;
882
			int know = know_type(a);
833
	    if ( know == 0 ) {
883
			if (know == 0) {
834
		if ( !IS_NULL_exp ( a ) ) {
884
				if (!IS_NULL_exp(a)) {
835
		    TYPE ta = DEREF_type ( exp_type ( a ) ) ;
885
					TYPE ta = DEREF_type(exp_type(a));
836
		    MAKE_exp_dummy ( ta, a, LINK_NONE, NULL_off, 1, virt ) ;
886
					MAKE_exp_dummy(ta, a, LINK_NONE,
-
 
887
						       NULL_off, 1, virt);
837
		    COPY_exp ( HEAD_list ( args ), virt ) ;
888
					COPY_exp(HEAD_list(args), virt);
838
		}
889
				}
839
	    } else if ( know == 2 ) {
890
			} else if (know == 2) {
840
		/* Non-obvious case */
891
				/* Non-obvious case */
841
		report ( crt_loc, ERR_class_virtual_not ( id ) ) ;
892
				report(crt_loc, ERR_class_virtual_not(id));
842
	    }
893
			}
843
	}
894
		}
844
	if ( IS_NULL_exp ( virt ) ) {
895
		if (IS_NULL_exp(virt)) {
845
	    /* Explicit call of virtual function */
896
			/* Explicit call of virtual function */
846
	    if ( ds & dspec_pure ) {
897
			if (ds & dspec_pure) {
847
		/* Call of pure virtual function */
898
				/* Call of pure virtual function */
848
		HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
899
				HASHID nm = DEREF_hashid(id_name(id));
849
		if ( IS_hashid_destr ( nm ) ) {
900
				if (IS_hashid_destr(nm)) {
850
		    /* Calling pure destructor is alright */
901
					/* Calling pure destructor is alright */
851
		    /* EMPTY */
902
					/* EMPTY */
852
		} else {
903
				} else {
-
 
904
					report(crt_loc,
853
		    report ( crt_loc, ERR_class_abstract_call ( id ) ) ;
905
					       ERR_class_abstract_call(id));
-
 
906
				}
-
 
907
			}
-
 
908
			if (!(ds & dspec_used)) {
-
 
909
				/* Mark explicit use */
-
 
910
				reuse_id(id, suppress_usage);
-
 
911
				ds = DEREF_dspec(id_storage(id));
-
 
912
			}
854
		}
913
		}
855
	    }
-
 
856
	    if ( !( ds & dspec_used ) ) {
-
 
857
		/* Mark explicit use */
-
 
858
		reuse_id ( id, suppress_usage ) ;
-
 
859
		ds = DEREF_dspec ( id_storage ( id ) ) ;
-
 
860
	    }
-
 
861
	}
-
 
862
    }
-
 
863
    if ( ( ds & dspec_friend ) && IS_NULL_exp ( virt ) ) {
-
 
864
	/* Call can't throw an exception */
-
 
865
	throws = 0 ;
-
 
866
    }
-
 
867
 
-
 
868
    /* Check for token applications */
-
 
869
    if ( ds & dspec_token ) {
-
 
870
	if ( ( qual & qual_mark ) && !( ds & dspec_reserve ) ) {
-
 
871
	    /* Parenthesised - use function proper */
-
 
872
	    /* EMPTY */
-
 
873
	} else {
-
 
874
	    TYPE form = DEREF_type ( id_function_etc_form ( id ) ) ;
-
 
875
	    if ( !IS_NULL_type ( form ) && IS_type_token ( form ) ) {
-
 
876
		IDENTIFIER ext = DEREF_id ( type_token_tok ( form ) ) ;
-
 
877
		if ( !IS_NULL_id ( ext ) && IS_id_token ( ext ) ) {
-
 
878
		    id = ext ;
-
 
879
		}
-
 
880
	    }
-
 
881
	}
914
	}
882
    }
-
 
883
 
-
 
884
    /* A function call is a side effect */
-
 
885
    no_side_effects++ ;
-
 
886
 
-
 
887
    /* Form the result */
-
 
888
    MAKE_exp_func_id ( ret, id, args, virt, e ) ;
915
	if ((ds & dspec_friend) && IS_NULL_exp(virt)) {
889
    if ( pass_complex_type ( ret ) ) {
-
 
890
	/* Allow for complex return types */
916
		/* Call can't throw an exception */
891
	EXP a ;
917
		throws = 0;
892
	MAKE_exp_dummy ( ret, NULL_exp, LINK_NONE, NULL_off, 0, a ) ;
-
 
893
	if ( IS_id_stat_mem_func ( id ) ) {
-
 
894
	    /* Insert as second parameter for static member functions */
-
 
895
	    EXP b = DEREF_exp ( HEAD_list ( args ) ) ;
-
 
896
	    COPY_exp ( HEAD_list ( args ), a ) ;
-
 
897
	    CONS_exp ( b, args, args ) ;
-
 
898
	} else {
-
 
899
	    /* Insert as first parameter for other functions */
-
 
900
	    CONS_exp ( a, args, args ) ;
-
 
901
	}
918
	}
902
	COPY_list ( exp_func_id_args ( e ), args ) ;
-
 
903
	COPY_unsigned ( exp_func_id_extra ( e ), 1 ) ;
-
 
904
	COPY_type ( exp_type ( e ), type_void ) ;
-
 
905
	MAKE_exp_constr ( ret, e, a, a, DEFAULT_USR, e ) ;
-
 
906
    }
-
 
907
 
-
 
908
    /* Check for exception violations */
-
 
909
    if ( throws ) {
-
 
910
	IGNORE check_func_throw ( fn, fid ) ;
-
 
911
    }
-
 
912
    return ( e ) ;
-
 
913
}
-
 
914
 
-
 
915
 
-
 
916
/*
-
 
917
    APPLY A FUNCTION TO A LIST OF EXPRESSIONS
-
 
918
 
-
 
919
    This routine applies the function expression a to the list of arguments
-
 
920
    args.
-
 
921
*/
-
 
922
 
919
 
923
static EXP apply_func_exp
920
	/* Check for token applications */
924
    PROTO_N ( ( a, args ) )
921
	if (ds & dspec_token) {
925
    PROTO_T ( EXP a X LIST ( EXP ) args )
922
		if ((qual & qual_mark) && !(ds & dspec_reserve)) {
926
{
-
 
927
    /* Find function type */
923
			/* Parenthesised - use function proper */
928
    EXP e ;
924
			/* EMPTY */
929
    TYPE ret ;
925
		} else {
930
    int mem = 0 ;
-
 
931
    TYPE fn = DEREF_type ( exp_type ( a ) ) ;
926
			TYPE form = DEREF_type(id_function_etc_form(id));
932
    CV_SPEC cv = DEREF_cv ( type_qual ( fn ) ) ;
927
			if (!IS_NULL_type(form) && IS_type_token(form)) {
933
    if ( cv & cv_lvalue ) {
928
				IDENTIFIER ext = DEREF_id(type_token_tok(form));
934
	a = convert_lvalue ( a ) ;
929
				if (!IS_NULL_id(ext) && IS_id_token(ext)) {
935
	fn = DEREF_type ( exp_type ( a ) ) ;
930
					id = ext;
936
    }
931
				}
937
    switch ( TAG_type ( fn ) ) {
-
 
938
	case type_ptr_tag : {
-
 
939
	    fn = DEREF_type ( type_ptr_sub ( fn ) ) ;
-
 
940
	    break ;
932
			}
941
	}
933
		}
942
	case type_ptr_mem_tag : {
-
 
943
	    fn = DEREF_type ( type_ptr_mem_sub ( fn ) ) ;
-
 
944
	    break ;
-
 
945
	}
934
	}
946
    }
-
 
947
 
-
 
948
    /* Convert the arguments */
-
 
949
    match_no_args = 0 ;
-
 
950
    if ( IS_exp_call ( a ) ) mem = 1 ;
-
 
951
    args = cast_args ( NULL_id, fn, NULL_graph, args, &ret, mem ) ;
-
 
952
    if ( mem ) {
-
 
953
	/* Record pointer to function member argument */
-
 
954
	EXP c = DEREF_exp ( HEAD_list ( args ) ) ;
-
 
955
	TYPE t = DEREF_type ( exp_type ( c ) ) ;
-
 
956
	MAKE_exp_dummy ( t, c, LINK_NONE, NULL_off, 1, c ) ;
-
 
957
	COPY_exp ( exp_call_arg ( a ), c ) ;
-
 
958
	COPY_exp ( HEAD_list ( args ), c ) ;
-
 
959
    }
-
 
960
 
935
 
961
    /* A function call is a side effect */
936
	/* A function call is a side effect */
962
    no_side_effects++ ;
937
	no_side_effects++;
-
 
938
 
-
 
939
	/* Form the result */
-
 
940
	MAKE_exp_func_id(ret, id, args, virt, e);
-
 
941
	if (pass_complex_type(ret)) {
-
 
942
		/* Allow for complex return types */
-
 
943
		EXP a;
-
 
944
		MAKE_exp_dummy(ret, NULL_exp, LINK_NONE, NULL_off, 0, a);
-
 
945
		if (IS_id_stat_mem_func(id)) {
-
 
946
			/* Insert as second parameter for static member functions */
-
 
947
			EXP b = DEREF_exp(HEAD_list(args));
-
 
948
			COPY_exp(HEAD_list(args), a);
-
 
949
			CONS_exp(b, args, args);
-
 
950
		} else {
-
 
951
			/* Insert as first parameter for other functions */
-
 
952
			CONS_exp(a, args, args);
-
 
953
		}
-
 
954
		COPY_list(exp_func_id_args(e), args);
-
 
955
		COPY_unsigned(exp_func_id_extra(e), 1);
-
 
956
		COPY_type(exp_type(e), type_void);
-
 
957
		MAKE_exp_constr(ret, e, a, a, DEFAULT_USR, e);
-
 
958
	}
-
 
959
 
-
 
960
	/* Check for exception violations */
-
 
961
	if (throws) {
-
 
962
		IGNORE check_func_throw(fn, fid);
-
 
963
	}
-
 
964
	return (e);
-
 
965
}
-
 
966
 
-
 
967
 
-
 
968
/*
-
 
969
    APPLY A FUNCTION TO A LIST OF EXPRESSIONS
963
 
970
 
-
 
971
    This routine applies the function expression a to the list of arguments
-
 
972
    args.
-
 
973
*/
-
 
974
 
-
 
975
static EXP
-
 
976
apply_func_exp(EXP a, LIST(EXP)args)
-
 
977
{
-
 
978
	/* Find function type */
-
 
979
	EXP e;
-
 
980
	TYPE ret;
-
 
981
	int mem = 0;
-
 
982
	TYPE fn = DEREF_type(exp_type(a));
-
 
983
	CV_SPEC cv = DEREF_cv(type_qual(fn));
-
 
984
	if (cv & cv_lvalue) {
-
 
985
		a = convert_lvalue(a);
-
 
986
		fn = DEREF_type(exp_type(a));
-
 
987
	}
-
 
988
	switch (TAG_type(fn)) {
-
 
989
	case type_ptr_tag:
-
 
990
		fn = DEREF_type(type_ptr_sub(fn));
-
 
991
		break;
-
 
992
	case type_ptr_mem_tag:
-
 
993
		fn = DEREF_type(type_ptr_mem_sub(fn));
-
 
994
		break;
-
 
995
	}
-
 
996
 
-
 
997
	/* Convert the arguments */
-
 
998
	match_no_args = 0;
-
 
999
	if (IS_exp_call(a)) {
-
 
1000
		mem = 1;
-
 
1001
	}
-
 
1002
	args = cast_args(NULL_id, fn, NULL_graph, args, &ret, mem);
-
 
1003
	if (mem) {
-
 
1004
		/* Record pointer to function member argument */
-
 
1005
		EXP c = DEREF_exp(HEAD_list(args));
-
 
1006
		TYPE t = DEREF_type(exp_type(c));
-
 
1007
		MAKE_exp_dummy(t, c, LINK_NONE, NULL_off, 1, c);
-
 
1008
		COPY_exp(exp_call_arg(a), c);
-
 
1009
		COPY_exp(HEAD_list(args), c);
-
 
1010
	}
-
 
1011
 
-
 
1012
	/* A function call is a side effect */
-
 
1013
	no_side_effects++;
-
 
1014
 
964
    /* Form the result */
1015
	/* Form the result */
965
    MAKE_exp_func ( ret, a, args, e ) ;
1016
	MAKE_exp_func(ret, a, args, e);
966
    if ( pass_complex_type ( ret ) ) {
1017
	if (pass_complex_type(ret)) {
967
	/* Allow for complex return types */
1018
		/* Allow for complex return types */
968
	EXP b ;
1019
		EXP b;
969
	MAKE_exp_dummy ( ret, NULL_exp, LINK_NONE, NULL_off, 0, b ) ;
1020
		MAKE_exp_dummy(ret, NULL_exp, LINK_NONE, NULL_off, 0, b);
970
	CONS_exp ( b, args, args ) ;
1021
		CONS_exp(b, args, args);
971
	COPY_list ( exp_func_args ( e ), args ) ;
1022
		COPY_list(exp_func_args(e), args);
972
	COPY_unsigned ( exp_func_extra ( e ), 1 ) ;
1023
		COPY_unsigned(exp_func_extra(e), 1);
973
	COPY_type ( exp_type ( e ), type_void ) ;
1024
		COPY_type(exp_type(e), type_void);
974
	MAKE_exp_constr ( ret, e, b, b, DEFAULT_USR, e ) ;
1025
		MAKE_exp_constr(ret, e, b, b, DEFAULT_USR, e);
975
    }
1026
	}
976
 
1027
 
977
    /* Check for exception violations */
1028
	/* Check for exception violations */
978
    IGNORE check_func_throw ( fn, NULL_id ) ;
1029
	IGNORE check_func_throw(fn, NULL_id);
979
    return ( e ) ;
1030
	return (e);
980
}
1031
}
981
 
1032
 
982
 
1033
 
983
/*
1034
/*
984
    APPLY A TEMPLATE DEPENDENT FUNCTION
1035
    APPLY A TEMPLATE DEPENDENT FUNCTION
985
 
1036
 
986
    This routine constructs the template dependent function call
1037
    This routine constructs the template dependent function call
987
    'a ( args )', or '( a ) ( args )' if is_paren is true.
1038
    'a ( args )', or '( a ) ( args )' if is_paren is true.
988
*/
1039
*/
989
 
-
 
990
static EXP call_func_templ
-
 
991
    PROTO_N ( ( a, args, is_paren ) )
-
 
992
    PROTO_T ( EXP a X LIST ( EXP ) args X int is_paren )
-
 
993
{
-
 
994
    EXP e ;
-
 
995
    TYPE ret = type_templ_param ;
-
 
996
    if ( is_paren ) a = make_paren_exp ( a ) ;
-
 
997
    CONS_exp ( a, args, args ) ;
-
 
998
    MAKE_exp_opn ( ret, lex_func_Hop, args, e ) ;
-
 
999
    return ( e ) ;
-
 
1000
}
-
 
1001
 
-
 
1002
 
1040
 
1003
/*
-
 
1004
    CONSTRUCT A FUNCTION CALL EXPRESSION
-
 
1005
 
-
 
1006
    This routine constructs the function call expression 'a ( args )'.
-
 
1007
*/
-
 
1008
 
-
 
1009
EXP make_func_exp
1041
static EXP
1010
    PROTO_N ( ( a, args, rescan ) )
-
 
1011
    PROTO_T ( EXP a X LIST ( EXP ) args X int rescan )
1042
call_func_templ(EXP a, LIST(EXP) args, int is_paren)
1012
{
1043
{
1013
    EXP e ;
1044
	EXP e;
1014
    TYPE fn ;
1045
	TYPE ret = type_templ_param;
1015
    unsigned tag ;
1046
	if (is_paren) {
1016
    unsigned ftag ;
1047
		a = make_paren_exp(a);
-
 
1048
	}
1017
    int is_ptr = 0 ;
1049
	CONS_exp(a, args, args);
1018
    int is_ptr_mem = 0 ;
1050
	MAKE_exp_opn(ret, lex_func_Hop, args, e);
1019
    int is_paren = IS_exp_paren ( a ) ;
1051
	return (e);
-
 
1052
}
-
 
1053
 
1020
 
1054
 
1021
    /* Do reference conversions */
-
 
-
 
1055
/*
1022
    a = convert_reference ( a, REF_FUNCTION ) ;
1056
    CONSTRUCT A FUNCTION CALL EXPRESSION
1023
    args = convert_args ( args ) ;
-
 
1024
 
1057
 
-
 
1058
    This routine constructs the function call expression 'a ( args )'.
-
 
1059
*/
-
 
1060
 
-
 
1061
EXP
-
 
1062
make_func_exp(EXP a, LIST(EXP)args, int rescan)
-
 
1063
{
-
 
1064
	EXP e;
-
 
1065
	TYPE fn;
-
 
1066
	unsigned tag;
-
 
1067
	unsigned ftag;
-
 
1068
	int is_ptr = 0;
-
 
1069
	int is_ptr_mem = 0;
-
 
1070
	int is_paren = IS_exp_paren(a);
-
 
1071
 
-
 
1072
	/* Do reference conversions */
-
 
1073
	a = convert_reference(a, REF_FUNCTION);
-
 
1074
	args = convert_args(args);
-
 
1075
 
1025
    /* Map '&f' to 'f' */
1076
	/* Map '&f' to 'f' */
1026
    tag = TAG_exp ( a ) ;
1077
	tag = TAG_exp(a);
1027
    if ( tag == exp_address_tag ) {
1078
	if (tag == exp_address_tag) {
1028
	/* Non-member function */
1079
		/* Non-member function */
1029
	EXP b = DEREF_exp ( exp_address_arg ( a ) ) ;
1080
		EXP b = DEREF_exp(exp_address_arg(a));
1030
	if ( IS_exp_identifier_etc ( b ) ) {
1081
		if (IS_exp_identifier_etc(b)) {
1031
	    a = b ;
1082
			a = b;
1032
	    tag = TAG_exp ( a ) ;
1083
			tag = TAG_exp(a);
1033
	    is_paren = 1 ;
1084
			is_paren = 1;
1034
	}
1085
		}
1035
    } else if ( tag == exp_address_mem_tag ) {
1086
	} else if (tag == exp_address_mem_tag) {
1036
	/* Member function (which better eventually be static) */
1087
		/* Member function (which better eventually be static) */
1037
	EXP b = DEREF_exp ( exp_address_mem_arg ( a ) ) ;
1088
		EXP b = DEREF_exp(exp_address_mem_arg(a));
1038
	IDENTIFIER id = DEREF_id ( exp_member_id ( b ) ) ;
1089
		IDENTIFIER id = DEREF_id(exp_member_id(b));
1039
	if ( IS_id_function_etc ( id ) ) {
1090
		if (IS_id_function_etc(id)) {
1040
	    while ( !IS_NULL_id ( id ) ) {
1091
			while (!IS_NULL_id(id)) {
1041
		if ( IS_id_mem_func ( id ) ) {
1092
				if (IS_id_mem_func(id)) {
-
 
1093
					report(crt_loc,
1042
		    report ( crt_loc, ERR_over_match_call_mem ( id ) ) ;
1094
					       ERR_over_match_call_mem(id));
1043
		    break ;
1095
					break;
1044
		}
1096
				}
1045
		id = DEREF_id ( id_function_etc_over ( id ) ) ;
1097
				id = DEREF_id(id_function_etc_over(id));
1046
	    }
1098
			}
1047
	    a = b ;
1099
			a = b;
1048
	    tag = TAG_exp ( a ) ;
1100
			tag = TAG_exp(a);
1049
	    is_paren = 1 ;
1101
			is_paren = 1;
1050
	    is_ptr_mem = 1 ;
1102
			is_ptr_mem = 1;
1051
	}
1103
		}
1052
    }
1104
	}
1053
 
1105
 
1054
    /* Check function type */
1106
	/* Check function type */
1055
    fn = DEREF_type ( exp_type ( a ) ) ;
1107
	fn = DEREF_type(exp_type(a));
1056
    ftag = TAG_type ( fn ) ;
1108
	ftag = TAG_type(fn);
1057
#if LANGUAGE_CPP
1109
#if LANGUAGE_CPP
1058
    if ( ftag == type_compound_tag ) {
1110
	if (ftag == type_compound_tag) {
1059
	/* Allow for overloading using 'operator ()' */
1111
		/* Allow for overloading using 'operator ()' */
1060
	if ( overload_depth == 0 ) {
1112
		if (overload_depth == 0) {
1061
	    e = function_overload ( a, args ) ;
1113
			e = function_overload(a, args);
1062
	    return ( e ) ;
1114
			return (e);
-
 
1115
		}
1063
	}
1116
	}
1064
    }
-
 
1065
#endif
1117
#endif
1066
    if ( ftag == type_ptr_tag ) {
1118
	if (ftag == type_ptr_tag) {
1067
	/* Allow for pointers to functions */
1119
		/* Allow for pointers to functions */
1068
	fn = DEREF_type ( type_ptr_sub ( fn ) ) ;
1120
		fn = DEREF_type(type_ptr_sub(fn));
1069
	ftag = TAG_type ( fn ) ;
1121
		ftag = TAG_type(fn);
1070
	is_ptr = 1 ;
1122
		is_ptr = 1;
1071
    }
1123
	}
1072
    while ( ftag == type_templ_tag ) {
1124
	while (ftag == type_templ_tag) {
1073
	fn = DEREF_type ( type_templ_defn ( fn ) ) ;
1125
		fn = DEREF_type(type_templ_defn(fn));
1074
	ftag = TAG_type ( fn ) ;
1126
		ftag = TAG_type(fn);
1075
    }
1127
	}
1076
    if ( ftag != type_func_tag ) {
1128
	if (ftag != type_func_tag) {
1077
	if ( ftag == type_token_tag && is_templ_type ( fn ) ) {
1129
		if (ftag == type_token_tag && is_templ_type(fn)) {
1078
	    /* Allow for template types */
1130
			/* Allow for template types */
1079
	    e = call_func_templ ( a, args, is_paren ) ;
1131
			e = call_func_templ(a, args, is_paren);
1080
	    return ( e ) ;
-
 
1081
	}
-
 
1082
	if ( ftag != type_error_tag ) {
-
 
1083
	    /* Type should now be a function type */
-
 
1084
	    ERROR err ;
-
 
1085
	    if ( IS_exp_member ( a ) ) {
-
 
1086
		IDENTIFIER id = DEREF_id ( exp_member_id ( a ) ) ;
-
 
1087
		err = ERR_expr_prim_mem ( id ) ;
-
 
1088
	    } else {
-
 
1089
		err = ERR_expr_call_op ( fn ) ;
-
 
1090
	    }
-
 
1091
	    if ( ftag == type_ptr_mem_tag && in_ptr_mem_selector ) {
-
 
1092
		err = concat_error ( err, ERR_expr_mptr_oper_paren () ) ;
-
 
1093
	    }
-
 
1094
	    report ( crt_loc, err ) ;
-
 
1095
	}
-
 
1096
	e = make_error_exp ( 0 ) ;
-
 
1097
	return ( e ) ;
1132
			return (e);
1098
    }
-
 
1099
 
-
 
1100
    /* Deal with named functions */
-
 
1101
    if ( !is_ptr ) {
-
 
1102
	switch ( tag ) {
-
 
1103
 
-
 
1104
	    case exp_identifier_tag :
-
 
1105
	    case exp_member_tag :
-
 
1106
	    case exp_ambiguous_tag :
-
 
1107
	    case exp_undeclared_tag : {
-
 
1108
		/* Normal functions, 'f' */
-
 
1109
		int dep = 1 ;
-
 
1110
		DECL_SPEC ds ;
-
 
1111
		IDENTIFIER id ;
-
 
1112
		QUALIFIER qual ;
-
 
1113
		EXP extra = NULL_exp ;
-
 
1114
		NAMESPACE ns = NULL_nspace ;
-
 
1115
		int acc = crt_access_list.inherit ;
-
 
1116
		id = DEREF_id ( exp_identifier_etc_id ( a ) ) ;
-
 
1117
		qual = DEREF_qual ( exp_identifier_etc_qual ( a ) ) ;
-
 
1118
		if ( rescan ) id = rescan_func_id ( id, qual ) ;
-
 
1119
		if ( dependent_call ( id, args ) ) {
-
 
1120
		    /* Call depends on template argument */
-
 
1121
		    e = call_func_templ ( a, args, is_paren ) ;
-
 
1122
		    return ( e ) ;
-
 
1123
		}
-
 
1124
		ds = DEREF_dspec ( id_storage ( id ) ) ;
-
 
1125
		if ( ds & dspec_instance ) dep = 0 ;
-
 
1126
		if ( qual & qual_explicit ) dep = 0 ;
-
 
1127
		if ( is_paren ) qual |= qual_mark ;
-
 
1128
		switch ( TAG_id ( id ) ) {
-
 
1129
		    case id_mem_func_tag :
-
 
1130
		    case id_stat_mem_func_tag :
-
 
1131
		    mem_func_label : {
-
 
1132
			/* Add argument for member functions */
-
 
1133
			extra = make_this_ref ( &ns ) ;
-
 
1134
			CONS_exp ( extra, args, args ) ;
-
 
1135
			dep = 0 ;
-
 
1136
			break ;
-
 
1137
		    }
-
 
1138
		    case id_ambig_tag : {
-
 
1139
			/* Check for ambiguous member functions */
-
 
1140
			CLASS_TYPE ct = parent_class ( id ) ;
-
 
1141
			if ( !IS_NULL_ctype ( ct ) ) goto mem_func_label ;
-
 
1142
			break ;
-
 
1143
		    }
-
 
1144
		}
1133
		}
1145
		id = resolve_call ( id, args, qual, dep ) ;
-
 
1146
		switch ( TAG_id ( id ) ) {
-
 
1147
		    case id_function_tag : {
1134
		if (ftag != type_error_tag) {
1148
			/* Normal function call */
1135
			/* Type should now be a function type */
1149
			break ;
1136
			ERROR err;
1150
		    }
-
 
1151
		    case id_mem_func_tag : {
-
 
1152
			/* Member function call */
-
 
1153
			if ( is_ptr_mem ) {
1137
			if (IS_exp_member(a)) {
1154
			    fn = DEREF_type ( id_mem_func_type ( id ) ) ;
-
 
1155
			    COPY_type ( exp_type ( a ), fn ) ;
-
 
1156
			    a = make_ref_exp ( a, 1 ) ;
-
 
1157
			    fn = DEREF_type ( exp_type ( a ) ) ;
1138
				IDENTIFIER id = DEREF_id(exp_member_id(a));
1158
			    report ( crt_loc, ERR_expr_call_op ( fn ) ) ;
-
 
1159
			}
-
 
1160
			if ( IS_NULL_exp ( extra ) ) {
-
 
1161
			    /* No associated object */
-
 
1162
			    report ( crt_loc, ERR_expr_call_mem ( id ) ) ;
1139
				err = ERR_expr_prim_mem(id);
1163
			} else {
1140
			} else {
-
 
1141
				err = ERR_expr_call_op(fn);
-
 
1142
			}
-
 
1143
			if (ftag == type_ptr_mem_tag && in_ptr_mem_selector) {
-
 
1144
				err = concat_error(err,
-
 
1145
						   ERR_expr_mptr_oper_paren());
-
 
1146
			}
-
 
1147
			report(crt_loc, err);
-
 
1148
		}
-
 
1149
		e = make_error_exp(0);
-
 
1150
		return (e);
-
 
1151
	}
-
 
1152
 
1164
			    /* Indicate inherited member function */
1153
	/* Deal with named functions */
-
 
1154
	if (!is_ptr) {
-
 
1155
		switch (tag) {
-
 
1156
		case exp_identifier_tag:
-
 
1157
		case exp_member_tag:
-
 
1158
		case exp_ambiguous_tag:
-
 
1159
		case exp_undeclared_tag: {
-
 
1160
			/* Normal functions, 'f' */
-
 
1161
			int dep = 1;
-
 
1162
			DECL_SPEC ds;
-
 
1163
			IDENTIFIER id;
-
 
1164
			QUALIFIER qual;
-
 
1165
			EXP extra = NULL_exp;
-
 
1166
			NAMESPACE ns = NULL_nspace;
1165
			    crt_access_list.inherit++ ;
1167
			int acc = crt_access_list.inherit;
-
 
1168
			id = DEREF_id(exp_identifier_etc_id(a));
-
 
1169
			qual = DEREF_qual(exp_identifier_etc_qual(a));
-
 
1170
			if (rescan) {
-
 
1171
				id = rescan_func_id(id, qual);
-
 
1172
			}
-
 
1173
			if (dependent_call(id, args)) {
-
 
1174
				/* Call depends on template argument */
-
 
1175
				e = call_func_templ(a, args, is_paren);
-
 
1176
				return (e);
-
 
1177
			}
-
 
1178
			ds = DEREF_dspec(id_storage(id));
-
 
1179
			if (ds & dspec_instance) {
-
 
1180
				dep = 0;
1166
			}
1181
			}
-
 
1182
			if (qual & qual_explicit) {
1167
			break ;
1183
				dep = 0;
-
 
1184
			}
-
 
1185
			if (is_paren) {
-
 
1186
				qual |= qual_mark;
1168
		    }
1187
			}
-
 
1188
			switch (TAG_id(id)) {
-
 
1189
			case id_mem_func_tag:
1169
		    case id_stat_mem_func_tag : {
1190
			case id_stat_mem_func_tag:
-
 
1191
mem_func_label:
1170
			/* Static member function call */
1192
				/* Add argument for member functions */
-
 
1193
				extra = make_this_ref(&ns);
-
 
1194
				CONS_exp(extra, args, args);
-
 
1195
				dep = 0;
-
 
1196
				break;
-
 
1197
			case id_ambig_tag: {
-
 
1198
				/* Check for ambiguous member functions */
-
 
1199
				CLASS_TYPE ct = parent_class(id);
1171
			if ( !IS_NULL_exp ( extra ) ) {
1200
				if (!IS_NULL_ctype(ct)) {
1172
			    COPY_exp ( HEAD_list ( args ), NULL_exp ) ;
1201
					goto mem_func_label;
-
 
1202
				}
-
 
1203
				break;
-
 
1204
			}
1173
			}
1205
			}
-
 
1206
 
-
 
1207
			id = resolve_call(id, args, qual, dep);
-
 
1208
			switch (TAG_id(id)) {
-
 
1209
			case id_function_tag:
-
 
1210
				/* Normal function call */
1174
			break ;
1211
				break;
-
 
1212
			case id_mem_func_tag:
-
 
1213
				/* Member function call */
-
 
1214
				if (is_ptr_mem) {
-
 
1215
					fn = DEREF_type(id_mem_func_type(id));
-
 
1216
					COPY_type(exp_type(a), fn);
-
 
1217
					a = make_ref_exp(a, 1);
-
 
1218
					fn = DEREF_type(exp_type(a));
-
 
1219
					report(crt_loc, ERR_expr_call_op(fn));
-
 
1220
				}
-
 
1221
				if (IS_NULL_exp(extra)) {
-
 
1222
					/* No associated object */
-
 
1223
					report(crt_loc, ERR_expr_call_mem(id));
-
 
1224
				} else {
-
 
1225
					/* Indicate inherited member function */
-
 
1226
					crt_access_list.inherit++;
-
 
1227
				}
-
 
1228
				break;
-
 
1229
			case id_stat_mem_func_tag:
-
 
1230
				/* Static member function call */
-
 
1231
				if (!IS_NULL_exp(extra)) {
-
 
1232
					COPY_exp(HEAD_list(args), NULL_exp);
1175
		    }
1233
				}
-
 
1234
				break;
1176
		    default : {
1235
			default:
1177
			/* Non-function called */
1236
				/* Non-function called */
1178
			if ( in_template_decl ) {
1237
				if (in_template_decl) {
1179
			    e = call_func_templ ( a, args, is_paren ) ;
1238
					e = call_func_templ(a, args, is_paren);
-
 
1239
				} else {
-
 
1240
					e = make_id_exp(id);
-
 
1241
					if (eq_exp(e, a, 0)) {
-
 
1242
						e = make_error_exp(0);
-
 
1243
					} else {
-
 
1244
						e = make_func_exp(e, args, 0);
-
 
1245
					}
-
 
1246
				}
-
 
1247
				return (e);
-
 
1248
			}
-
 
1249
			use_func_id(id, 1, suppress_usage);
-
 
1250
			crt_access_list.inherit = acc;
-
 
1251
			if (resolved_kind == KIND_CONSTR) {
-
 
1252
				e = apply_constr(id, args);
1180
			} else {
1253
			} else {
1181
			    e = make_id_exp ( id ) ;
-
 
1182
			    if ( eq_exp ( e, a, 0 ) ) {
-
 
1183
				e = make_error_exp ( 0 ) ;
-
 
1184
			    } else {
-
 
1185
				e = make_func_exp ( e, args, 0 ) ;
1254
				e = apply_func_id(id, qual, NULL_graph, args);
1186
			    }
-
 
1187
			}
1255
			}
1188
			return ( e ) ;
1256
			return (e);
1189
		    }
-
 
1190
		}
-
 
1191
		use_func_id ( id, 1, suppress_usage ) ;
-
 
1192
		crt_access_list.inherit = acc ;
-
 
1193
		if ( resolved_kind == KIND_CONSTR ) {
-
 
1194
		    e = apply_constr ( id, args ) ;
-
 
1195
		} else {
-
 
1196
		    e = apply_func_id ( id, qual, NULL_graph, args ) ;
-
 
1197
		}
1257
		}
1198
		return ( e ) ;
-
 
1199
	    }
-
 
1200
 
1258
 
1201
	    case exp_call_tag : {
1259
		case exp_call_tag: {
1202
		/* Member function selectors */
1260
			/* Member function selectors */
1203
		EXP b = DEREF_exp ( exp_call_ptr ( a ) ) ;
1261
			EXP b = DEREF_exp(exp_call_ptr(a));
1204
		EXP c = DEREF_exp ( exp_call_arg ( a ) ) ;
1262
			EXP c = DEREF_exp(exp_call_arg(a));
1205
		tag = TAG_exp ( b ) ;
1263
			tag = TAG_exp(b);
1206
		if ( tag == exp_identifier_tag || tag == exp_member_tag ) {
1264
			if (tag == exp_identifier_tag ||
-
 
1265
			    tag == exp_member_tag) {
1207
		    /* Named function selector, 'c->f' */
1266
				/* Named function selector, 'c->f' */
1208
		    IDENTIFIER id ;
1267
				IDENTIFIER id;
1209
		    QUALIFIER qual ;
1268
				QUALIFIER qual;
1210
		    id = DEREF_id ( exp_identifier_etc_id ( b ) ) ;
1269
				id = DEREF_id(exp_identifier_etc_id(b));
1211
		    qual = DEREF_qual ( exp_identifier_etc_qual ( b ) ) ;
1270
				qual = DEREF_qual(exp_identifier_etc_qual(b));
1212
		    if ( rescan ) id = rescan_func_id ( id, qual_nested ) ;
1271
				if (rescan)id = rescan_func_id(id, qual_nested);
1213
		    if ( dependent_call ( id, args ) ) {
1272
				if (dependent_call(id, args)) {
1214
			e = call_func_templ ( a, args, is_paren ) ;
1273
					e = call_func_templ(a, args, is_paren);
1215
		    } else {
1274
				} else {
1216
			GRAPH gr = DEREF_graph ( exp_call_base ( a ) ) ;
1275
					GRAPH gr = DEREF_graph(exp_call_base(a));
-
 
1276
					if (is_paren) {
1217
			if ( is_paren ) qual |= qual_mark ;
1277
						qual |= qual_mark;
-
 
1278
					}
1218
			CONS_exp ( c, args, args ) ;
1279
					CONS_exp(c, args, args);
1219
			id = resolve_call ( id, args, qual, 0 ) ;
1280
					id = resolve_call(id, args, qual, 0);
1220
			use_func_id ( id, 1, suppress_usage ) ;
1281
					use_func_id(id, 1, suppress_usage);
1221
			if ( resolved_kind == KIND_CONSTR ) {
1282
					if (resolved_kind == KIND_CONSTR) {
1222
			    e = apply_constr ( id, args ) ;
1283
						e = apply_constr(id, args);
1223
			} else {
1284
					} else {
-
 
1285
						HASHID nm =
1224
			    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
1286
						    DEREF_hashid(id_name(id));
1225
			    e = apply_func_id ( id, qual, gr, args ) ;
1287
						e = apply_func_id(id, qual, gr,
-
 
1288
								  args);
1226
			    if ( !IS_hashid_name_etc ( nm ) ) {
1289
						if (!IS_hashid_name_etc(nm)) {
1227
				/* Check for extra arguments */
1290
							/* Check for extra
-
 
1291
							 * arguments */
1228
				int v = EXTRA_CONSTR ;
1292
							int v = EXTRA_CONSTR;
-
 
1293
							CLASS_TYPE ct =
1229
				CLASS_TYPE ct = parent_class ( id ) ;
1294
							    parent_class(id);
1230
				if ( IS_hashid_destr ( nm ) ) {
1295
							if (IS_hashid_destr(nm)) {
1231
				    v = EXTRA_DESTR ;
1296
								v = EXTRA_DESTR;
-
 
1297
							}
-
 
1298
							e = add_constr_args(e, ct, v);
-
 
1299
						}
-
 
1300
					}
1232
				}
1301
				}
1233
				e = add_constr_args ( e, ct, v ) ;
-
 
1234
			    }
1302
				return (e);
1235
			}
1303
			}
1236
		    }
-
 
1237
		    return ( e ) ;
-
 
1238
		}
-
 
1239
		if ( tag == exp_undeclared_tag ) {
1304
			if (tag == exp_undeclared_tag) {
1240
		    /* Pseudo-destructor call, 'c->C::~C' */
1305
				/* Pseudo-destructor call, 'c->C::~C' */
1241
		    IDENTIFIER id = DEREF_id ( exp_undeclared_id ( b ) ) ;
1306
				IDENTIFIER id = DEREF_id(exp_undeclared_id(b));
1242
		    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
1307
				HASHID nm = DEREF_hashid(id_name(id));
1243
		    if ( !IS_NULL_list ( args ) ) {
1308
				if (!IS_NULL_list(args)) {
1244
			report ( crt_loc, ERR_expr_pseudo_args ( nm ) ) ;
1309
					report(crt_loc, ERR_expr_pseudo_args(nm));
1245
		    }
1310
				}
1246
		    e = trivial_destr ( c ) ;
1311
				e = trivial_destr(c);
1247
		    return ( e ) ;
1312
				return (e);
1248
		}
1313
			}
1249
		/* Pointer to member function selector, 'a.*f' */
1314
			/* Pointer to member function selector, 'a.*f' */
1250
		CONS_exp ( c, args, args ) ;
1315
			CONS_exp(c, args, args);
1251
		break ;
1316
			break;
-
 
1317
		}
1252
	    }
1318
		}
1253
	}
1319
	}
1254
    }
-
 
1255
 
1320
 
1256
    /* Form the result for function expressions */
1321
	/* Form the result for function expressions */
1257
    e = apply_func_exp ( a, args ) ;
1322
	e = apply_func_exp(a, args);
1258
    return ( e ) ;
1323
	return (e);
1259
}
1324
}
1260
 
1325
 
1261
 
1326
 
1262
/*
1327
/*
1263
    SHOULD A FUNCTION RETURN VALUE BE IGNORED?
1328
    SHOULD A FUNCTION RETURN VALUE BE IGNORED?
1264
 
1329
 
1265
    This routine checks whether a function consisting of 'return e ;'
1330
    This routine checks whether a function consisting of 'return e ;'
1266
    should be inlined.
1331
    should be inlined.
1267
*/
1332
*/
1268
 
1333
 
1269
static EXP check_inline_return
1334
static EXP
1270
    PROTO_N ( ( e, ret ) )
-
 
1271
    PROTO_T ( EXP e X TYPE ret )
1335
check_inline_return(EXP e, TYPE ret)
1272
{
1336
{
1273
    if ( IS_NULL_exp ( e ) ) {
1337
	if (IS_NULL_exp(e)) {
1274
	/* No value returned */
1338
		/* No value returned */
1275
	MAKE_exp_value ( ret, e ) ;
1339
		MAKE_exp_value(ret, e);
1276
	return ( e ) ;
1340
		return (e);
1277
    }
1341
	}
1278
    if ( is_const_exp ( e, -1 ) ) {
1342
	if (is_const_exp(e, -1)) {
1279
	/* Constant expression returned */
1343
		/* Constant expression returned */
1280
	MAKE_exp_copy ( ret, e, e ) ;
1344
		MAKE_exp_copy(ret, e, e);
1281
	return ( e ) ;
1345
		return (e);
1282
    }
1346
	}
1283
    return ( NULL_exp ) ;
1347
	return (NULL_exp);
1284
}
1348
}
1285
 
1349
 
1286
 
1350
 
1287
/*
1351
/*
1288
    SHOULD A FUNCTION CALL BE INLINED?
1352
    SHOULD A FUNCTION CALL BE INLINED?
Line 1293... Line 1357...
1293
    should be inlined by the producer.  This is generally done on the
1357
    should be inlined by the producer.  This is generally done on the
1294
    basis of code size rather than efficiency.  If so it returns the result
1358
    basis of code size rather than efficiency.  If so it returns the result
1295
    expression.  Otherwise the null expression is returned.
1359
    expression.  Otherwise the null expression is returned.
1296
*/
1360
*/
1297
 
1361
 
1298
EXP check_inline
1362
EXP
1299
    PROTO_N ( ( id, args, ret ) )
-
 
1300
    PROTO_T ( IDENTIFIER id X LIST ( EXP ) args X TYPE ret )
1363
check_inline(IDENTIFIER id, LIST(EXP)args, TYPE ret)
1301
{
1364
{
1302
    while ( !IS_NULL_list ( args ) ) {
1365
	while (!IS_NULL_list(args)) {
1303
	/* Check argument list */
1366
		/* Check argument list */
1304
	EXP a = DEREF_exp ( HEAD_list ( args ) ) ;
1367
		EXP a = DEREF_exp(HEAD_list(args));
1305
	if ( !IS_NULL_exp ( a ) ) return ( NULL_exp ) ;
-
 
1306
	args = TAIL_list ( args ) ;
-
 
1307
    }
-
 
1308
    if ( IS_id_function_etc ( id ) ) {
-
 
1309
	/* Check function definition */
-
 
1310
	EXP e = DEREF_exp ( id_function_etc_defn ( id ) ) ;
-
 
1311
	if ( !IS_NULL_exp ( e ) && IS_exp_sequence ( e ) ) {
-
 
1312
	    LIST ( EXP ) p = DEREF_list ( exp_sequence_first ( e ) ) ;
-
 
1313
	    p = TAIL_list ( p ) ;
-
 
1314
	    if ( IS_NULL_list ( p ) ) {
1368
		if (!IS_NULL_exp(a)) {
1315
		/* Empty function definition */
-
 
1316
		e = check_inline_return ( NULL_exp, ret ) ;
-
 
1317
		return ( e ) ;
1369
			return (NULL_exp);
1318
	    }
-
 
1319
	    e = DEREF_exp ( HEAD_list ( p ) ) ;
-
 
1320
	    p = TAIL_list ( p ) ;
-
 
1321
	    if ( IS_NULL_list ( p ) ) {
-
 
1322
		if ( !IS_NULL_exp ( e ) && IS_exp_location ( e ) ) {
-
 
1323
		    /* Step over location marker */
-
 
1324
		    e = DEREF_exp ( exp_location_arg ( e ) ) ;
-
 
1325
		}
-
 
1326
		if ( !IS_NULL_exp ( e ) && IS_exp_return_stmt ( e ) ) {
-
 
1327
		    /* Single return statement */
-
 
1328
		    e = DEREF_exp ( exp_return_stmt_value ( e ) ) ;
-
 
1329
		    e = check_inline_return ( e, ret ) ;
-
 
1330
		    return ( e ) ;
-
 
1331
		}
1370
		}
1332
	    }
1371
		args = TAIL_list(args);
1333
	}
1372
	}
-
 
1373
	if (IS_id_function_etc(id)) {
-
 
1374
		/* Check function definition */
-
 
1375
		EXP e = DEREF_exp(id_function_etc_defn(id));
-
 
1376
		if (!IS_NULL_exp(e) && IS_exp_sequence(e)) {
-
 
1377
			LIST(EXP)p = DEREF_list(exp_sequence_first(e));
-
 
1378
			p = TAIL_list(p);
-
 
1379
			if (IS_NULL_list(p)) {
-
 
1380
				/* Empty function definition */
-
 
1381
				e = check_inline_return(NULL_exp, ret);
-
 
1382
				return (e);
-
 
1383
			}
-
 
1384
			e = DEREF_exp(HEAD_list(p));
-
 
1385
			p = TAIL_list(p);
-
 
1386
			if (IS_NULL_list(p)) {
-
 
1387
				if (!IS_NULL_exp(e) && IS_exp_location(e)) {
-
 
1388
					/* Step over location marker */
-
 
1389
					e = DEREF_exp(exp_location_arg(e));
1334
    }
1390
				}
-
 
1391
				if (!IS_NULL_exp(e) && IS_exp_return_stmt(e)) {
-
 
1392
					/* Single return statement */
-
 
1393
					e = DEREF_exp(exp_return_stmt_value(e));
-
 
1394
					e = check_inline_return(e, ret);
-
 
1395
					return (e);
-
 
1396
				}
-
 
1397
			}
-
 
1398
		}
-
 
1399
	}
1335
    return ( NULL_exp ) ;
1400
	return (NULL_exp);
1336
}
1401
}
1337
 
1402
 
1338
 
1403
 
1339
/*
1404
/*
1340
    CHECK FOR COMPLEX FUNCTION RETURN OR ARGUMENT TYPE
1405
    CHECK FOR COMPLEX FUNCTION RETURN OR ARGUMENT TYPE
Line 1345... Line 1410...
1345
    is that such values are returned by means of a reference which is
1410
    is that such values are returned by means of a reference which is
1346
    passed to the function as the first argument, and that such values
1411
    passed to the function as the first argument, and that such values
1347
    are passed as arguments as a reference to a copy.
1412
    are passed as arguments as a reference to a copy.
1348
*/
1413
*/
1349
 
1414
 
1350
int pass_complex_type
1415
int
1351
    PROTO_N ( ( t ) )
-
 
1352
    PROTO_T ( TYPE t )
1416
pass_complex_type(TYPE t)
1353
{
1417
{
1354
    if ( !IS_NULL_type ( t ) && IS_type_compound ( t ) ) {
1418
	if (!IS_NULL_type(t) && IS_type_compound(t)) {
1355
	CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
1419
		CLASS_TYPE ct = DEREF_ctype(type_compound_defn(t));
1356
	CLASS_INFO ci = DEREF_cinfo ( ctype_info ( ct ) ) ;
1420
		CLASS_INFO ci = DEREF_cinfo(ctype_info(ct));
1357
	CLASS_INFO cj = ( ci & cinfo_trivial ) ;
1421
		CLASS_INFO cj = (ci & cinfo_trivial);
1358
	if ( cj != cinfo_trivial ) return ( 1 ) ;
1422
		if (cj != cinfo_trivial) {
-
 
1423
			return (1);
1359
    }
1424
		}
-
 
1425
	}
1360
    return ( 0 ) ;
1426
	return (0);
1361
}
1427
}
1362
 
1428
 
1363
 
1429
 
1364
/*
1430
/*
1365
    CHECK A FUNCTION RETURN OR PARAMETER TYPE
1431
    CHECK A FUNCTION RETURN OR PARAMETER TYPE
1366
 
1432
 
1367
    This routine checks whether the type just constructed by the parser
1433
    This routine checks whether the type just constructed by the parser
1368
    contains type definitions and so is not suitable for use as a function
1434
    contains type definitions and so is not suitable for use as a function
1369
    return or parameter type (as indicated by par).  The necessary
1435
    return or parameter type (as indicated by par).  The necessary
1370
    information is stored in the global variable have_type_declaration.
1436
    information is stored in the global variable have_type_declaration.
1371
*/
1437
*/
1372
 
1438
 
1373
void func_type_defn
1439
void
1374
    PROTO_N ( ( par ) )
-
 
1375
    PROTO_T ( int par )
1440
func_type_defn(int par)
1376
{
1441
{
1377
    int td = have_type_declaration ;
1442
	int td = have_type_declaration;
1378
    if ( td == TYPE_DECL_NORMAL || td == TYPE_DECL_ANON ) {
1443
	if (td == TYPE_DECL_NORMAL || td == TYPE_DECL_ANON) {
1379
	if ( par ) {
1444
		if (par) {
1380
	    report ( crt_loc, ERR_dcl_fct_typedef_par () ) ;
1445
			report(crt_loc, ERR_dcl_fct_typedef_par());
1381
	} else {
1446
		} else {
1382
	    report ( crt_loc, ERR_dcl_fct_typedef_ret () ) ;
1447
			report(crt_loc, ERR_dcl_fct_typedef_ret());
1383
	}
1448
		}
1384
    }
1449
	}
1385
    return ;
1450
	return;
1386
}
1451
}
1387
 
1452
 
1388
 
1453
 
1389
/*
1454
/*
1390
    CREATE A PARAMETER TYPE
1455
    CREATE A PARAMETER TYPE
1391
 
1456
 
1392
    This routine creates the parameter type for a function or template
1457
    This routine creates the parameter type for a function or template
1393
    parameter (as indicated by loc) declared with type t.  Thus functions
1458
    parameter (as indicated by loc) declared with type t.  Thus functions
1394
    and, for function parameters, arrays are converted to pointers.
1459
    and, for function parameters, arrays are converted to pointers.
1395
*/
1460
*/
1396
 
1461
 
1397
TYPE make_param_type
1462
TYPE
1398
    PROTO_N ( ( t, loc ) )
-
 
1399
    PROTO_T ( TYPE t X int loc )
1463
make_param_type(TYPE t, int loc)
1400
{
1464
{
1401
    switch ( TAG_type ( t ) ) {
1465
	switch (TAG_type(t)) {
1402
	case type_func_tag : {
1466
	case type_func_tag: {
1403
	    /* Function parameters are adjusted to pointers */
1467
		/* Function parameters are adjusted to pointers */
1404
	    member_func_type ( NULL_ctype, id_parameter_tag, t ) ;
1468
		member_func_type(NULL_ctype, id_parameter_tag, t);
1405
	    check_weak_func ( t, 0 ) ;
1469
		check_weak_func(t, 0);
1406
	    MAKE_type_ptr ( cv_none, t, t ) ;
1470
		MAKE_type_ptr(cv_none, t, t);
1407
	    break ;
1471
		break;
1408
	}
1472
	}
1409
	case type_array_tag : {
1473
	case type_array_tag: {
1410
	    /* Array parameters are adjusted to pointers */
1474
		/* Array parameters are adjusted to pointers */
1411
	    if ( loc == CONTEXT_PARAMETER || loc == CONTEXT_WEAK_PARAM ) {
1475
		if (loc == CONTEXT_PARAMETER || loc == CONTEXT_WEAK_PARAM) {
1412
		t = DEREF_type ( type_array_sub ( t ) ) ;
1476
			t = DEREF_type(type_array_sub(t));
1413
		MAKE_type_ptr ( cv_none, t, t ) ;
1477
			MAKE_type_ptr(cv_none, t, t);
1414
	    }
1478
		}
1415
	    break ;
1479
		break;
-
 
1480
	}
1416
	}
1481
	}
1417
    }
-
 
1418
    return ( t ) ;
1482
	return (t);
1419
}
1483
}
1420
 
1484
 
1421
 
1485
 
1422
/*
1486
/*
1423
    CHECK A PARAMETER TYPE
1487
    CHECK A PARAMETER TYPE
Line 1425... Line 1489...
1425
    A parameter cannot include a type of the form pointer to unbound array
1489
    A parameter cannot include a type of the form pointer to unbound array
1426
    or reference to unbound array.  This routine returns an error if the type
1490
    or reference to unbound array.  This routine returns an error if the type
1427
    t includes a type of this form.  Strictly the parameters of any function
1491
    t includes a type of this form.  Strictly the parameters of any function
1428
    components should also be checked, but these will have already been
1492
    components should also be checked, but these will have already been
1429
    handled by a previous check.
1493
    handled by a previous check.
1430
*/
1494
*/
1431
 
1495
 
1432
ERROR check_param_type
1496
ERROR
1433
    PROTO_N ( ( id, t ) )
-
 
1434
    PROTO_T ( IDENTIFIER id X TYPE t )
1497
check_param_type(IDENTIFIER id, TYPE t)
1435
{
1498
{
1436
    TYPE s = t ;
1499
	TYPE s = t;
1437
    int state = 0 ;
1500
	int state = 0;
1438
    while ( !IS_NULL_type ( s ) ) {
1501
	while (!IS_NULL_type(s)) {
1439
	switch ( TAG_type ( s ) ) {
1502
		switch (TAG_type(s)) {
1440
	    case type_top_tag :
1503
		case type_top_tag:
1441
	    case type_bottom_tag : {
1504
		case type_bottom_tag: {
1442
		/* Void types */
1505
			/* Void types */
-
 
1506
			if (state) {
1443
		if ( state ) return ( NULL_err ) ;
1507
				return (NULL_err);
-
 
1508
			}
1444
		return ( ERR_dcl_fct_par_void ( id, t ) ) ;
1509
			return (ERR_dcl_fct_par_void(id, t));
1445
	    }
1510
		}
1446
	    case type_ptr_tag :
1511
		case type_ptr_tag:
1447
	    case type_ref_tag : {
1512
		case type_ref_tag: {
1448
		/* Pointer and reference types */
1513
			/* Pointer and reference types */
1449
		s = DEREF_type ( type_ptr_etc_sub ( s ) ) ;
1514
			s = DEREF_type(type_ptr_etc_sub(s));
1450
		state = 1 ;
1515
			state = 1;
1451
		break ;
1516
			break;
1452
	    }
1517
		}
1453
	    case type_array_tag : {
1518
		case type_array_tag: {
1454
		/* Array types */
1519
			/* Array types */
1455
		if ( state ) {
1520
			if (state) {
1456
		    NAT n = DEREF_nat ( type_array_size ( s ) ) ;
1521
				NAT n = DEREF_nat(type_array_size(s));
1457
		    if ( IS_NULL_nat ( n ) ) {
1522
				if (IS_NULL_nat(n)) {
1458
			return ( ERR_dcl_fct_par_array ( id, t ) ) ;
1523
					return (ERR_dcl_fct_par_array(id, t));
1459
		    }
1524
				}
-
 
1525
			}
-
 
1526
			s = DEREF_type(type_array_sub(s));
-
 
1527
			state = 0;
-
 
1528
			break;
-
 
1529
		}
-
 
1530
		default:
-
 
1531
			/* Other types */
-
 
1532
			return (NULL_err);
1460
		}
1533
		}
1461
		s = DEREF_type ( type_array_sub ( s ) ) ;
-
 
1462
		state = 0 ;
-
 
1463
		break ;
-
 
1464
	    }
-
 
1465
	    default : {
-
 
1466
		/* Other types */
-
 
1467
		return ( NULL_err ) ;
-
 
1468
	    }
-
 
1469
	}
1534
	}
1470
    }
-
 
1471
    return ( NULL_err ) ;
1535
	return (NULL_err);
1472
}
1536
}
1473
 
1537
 
1474
 
1538
 
1475
/*
1539
/*
1476
    ADJUST A FUNCTION LINKAGE
1540
    ADJUST A FUNCTION LINKAGE
1477
 
1541
 
1478
    This routine adjusts the function linkage specifier cv to include
1542
    This routine adjusts the function linkage specifier cv to include
1479
    the current linkage specifier.
1543
    the current linkage specifier.
1480
*/
1544
*/
1481
 
1545
 
1482
CV_SPEC func_linkage
1546
CV_SPEC
1483
    PROTO_N ( ( cv ) )
-
 
1484
    PROTO_T ( CV_SPEC cv )
1547
func_linkage(CV_SPEC cv)
1485
{
1548
{
1486
    DECL_SPEC ln = crt_linkage ;
1549
	DECL_SPEC ln = crt_linkage;
1487
    if ( ln ) {
1550
	if (ln) {
1488
	if ( ln & dspec_c ) cv |= cv_c ;
1551
		if (ln & dspec_c) {
-
 
1552
			cv |= cv_c;
-
 
1553
		}
1489
	if ( ln & dspec_cpp ) cv |= cv_cpp ;
1554
		if (ln & dspec_cpp) {
-
 
1555
			cv |= cv_cpp;
1490
    }
1556
		}
-
 
1557
	}
1491
    return ( cv ) ;
1558
	return (cv);
1492
}
1559
}
1493
 
1560
 
1494
 
1561
 
1495
/*
1562
/*
1496
    CREATE A LIST OF FUNCTION PARAMETER TYPES
1563
    CREATE A LIST OF FUNCTION PARAMETER TYPES
1497
 
1564
 
1498
    This routine constructs the function type with parameter declarations
1565
    This routine constructs the function type with parameter declarations
1499
    given by the current namespace and const-volatile qualifiers cv.  The
1566
    given by the current namespace and const-volatile qualifiers cv.  The
1500
    kind of function is given by ell, which is a combination of the
1567
    kind of function is given by ell, which is a combination of the
1501
    FUNC_* values defined in function.h.  The function return type is
1568
    FUNC_* values defined in function.h.  The function return type is
1502
    usually filled in later (by inject_pre_type) but may be specified
1569
    usually filled in later (by inject_pre_type) but may be specified
1503
    by r.  Note that function and array parameters have already been
1570
    by r.  Note that function and array parameters have already been
1504
    adjusted to pointers by make_param_decl.
1571
    adjusted to pointers by make_param_decl.
1505
*/
1572
*/
1506
 
1573
 
1507
TYPE make_func_type
1574
TYPE
1508
    PROTO_N ( ( r, ell, cv, ex ) )
-
 
1509
    PROTO_T ( TYPE r X int ell X CV_SPEC cv X LIST ( TYPE ) ex )
1575
make_func_type(TYPE r, int ell, CV_SPEC cv, LIST(TYPE) ex)
1510
{
1576
{
1511
    int no_param = 0 ;
1577
	int no_param = 0;
1512
    TYPE t = NULL_type ;
1578
	TYPE t = NULL_type;
1513
    LIST ( IDENTIFIER ) p1 ;
1579
	LIST(IDENTIFIER) p1;
1514
    IDENTIFIER id = NULL_id ;
1580
	IDENTIFIER id = NULL_id;
1515
    LIST ( TYPE ) q = NULL_list ( TYPE ) ;
1581
	LIST(TYPE) q = NULL_list(TYPE);
1516
    LIST ( IDENTIFIER ) p = NULL_list ( IDENTIFIER ) ;
1582
	LIST(IDENTIFIER) p = NULL_list(IDENTIFIER);
-
 
1583
 
-
 
1584
	/* Get parameter declarations */
-
 
1585
	NAMESPACE ns = crt_namespace;
-
 
1586
	MEMBER mem = DEREF_member(nspace_last(ns));
-
 
1587
 
-
 
1588
	/* Build up parameter type list (deleting cv-qualifiers) */
-
 
1589
	while (!IS_NULL_member(mem)) {
-
 
1590
		id = DEREF_id(member_id(mem));
-
 
1591
		if (!IS_NULL_id(id) && IS_id_parameter(id)) {
-
 
1592
			t = DEREF_type(id_parameter_type(id));
-
 
1593
			if ((ell & FUNC_WEAK) && !is_arg_promote(t)) {
-
 
1594
				DECL_SPEC ds;
-
 
1595
				t = arg_promote_type(t, KILL_err);
-
 
1596
				ds = DEREF_dspec(id_storage(id));
-
 
1597
				ds |= dspec_virtual;
-
 
1598
				COPY_dspec(id_storage(id), ds);
-
 
1599
			}
-
 
1600
			t = qualify_type(t, cv_none, 0);
-
 
1601
			CONS_type(t, q, q);
-
 
1602
			CONS_id(id, p, p);
-
 
1603
			no_param++;
-
 
1604
		}
-
 
1605
		mem = DEREF_member(member_next(mem));
-
 
1606
	}
1517
 
1607
 
1518
    /* Get parameter declarations */
1608
	/* Check for non-prototype functions */
-
 
1609
	if (IS_NULL_type(r)) {
-
 
1610
		if (ell & FUNC_NON_PROTO) {
-
 
1611
			report(crt_loc, ERR_dcl_fct_nonproto());
-
 
1612
			if (ell == FUNC_WEAK && no_param == 0) {
1519
    NAMESPACE ns = crt_namespace ;
1613
				/* Can't have 't weak ()' */
-
 
1614
				report(crt_loc, ERR_dcl_fct_par_weak());
-
 
1615
			}
-
 
1616
#if LANGUAGE_CPP
-
 
1617
			ell &= FUNC_ELLIPSIS;
-
 
1618
#endif
-
 
1619
		} else {
-
 
1620
			report(crt_loc, ERR_dcl_fct_proto());
-
 
1621
		}
-
 
1622
	}
-
 
1623
 
-
 
1624
	/* Check for '( ... )' */
1520
    MEMBER mem = DEREF_member ( nspace_last ( ns ) ) ;
1625
	if (no_param == 0 && (ell & FUNC_ELLIPSIS)) {
-
 
1626
		report(crt_loc, ERR_dcl_fct_par_ellipsis());
-
 
1627
	}
1521
 
1628
 
1522
    /* Build up parameter type list (deleting cv-qualifiers) */
-
 
1523
    while ( !IS_NULL_member ( mem ) ) {
-
 
1524
	id = DEREF_id ( member_id ( mem ) ) ;
1629
	/* Check for '( void )' */
1525
	if ( !IS_NULL_id ( id ) && IS_id_parameter ( id ) ) {
1630
	if (no_param == 1 && !(ell & FUNC_ELLIPSIS)) {
1526
	    t = DEREF_type ( id_parameter_type ( id ) ) ;
1631
		/* Precisely one parameter (in t and id) */
1527
	    if ( ( ell & FUNC_WEAK ) && !is_arg_promote ( t ) ) {
-
 
1528
		DECL_SPEC ds ;
-
 
1529
		t = arg_promote_type ( t, KILL_err ) ;
1632
		if (IS_type_top(t)) {
1530
		ds = DEREF_dspec ( id_storage ( id ) ) ;
1633
			HASHID nm = DEREF_hashid(id_name(id));
1531
		ds |= dspec_virtual ;
1634
			if (!IS_hashid_anon(nm)) {
1532
		COPY_dspec ( id_storage ( id ), ds ) ;
1635
				report(crt_loc, ERR_dcl_fct_par_empty());
1533
	    }
1636
			}
1534
	    t = qualify_type ( t, cv_none, 0 ) ;
1637
			DESTROY_list(q, SIZE_type);
1535
	    CONS_type ( t, q, q ) ;
1638
			DESTROY_list(p, SIZE_id);
1536
	    CONS_id ( id, p, p ) ;
1639
			q = NULL_list(TYPE);
1537
	    no_param++ ;
1640
			p = NULL_list(IDENTIFIER);
-
 
1641
		}
1538
	}
1642
	}
1539
	mem = DEREF_member ( member_next ( mem ) ) ;
-
 
1540
    }
-
 
1541
 
1643
 
1542
    /* Check for non-prototype functions */
1644
	/* Check for other void parameters */
1543
    if ( IS_NULL_type ( r ) ) {
-
 
1544
	if ( ell & FUNC_NON_PROTO ) {
-
 
1545
	    report ( crt_loc, ERR_dcl_fct_nonproto () ) ;
-
 
1546
	    if ( ell == FUNC_WEAK && no_param == 0 ) {
-
 
1547
		/* Can't have 't weak ()' */
-
 
1548
		report ( crt_loc, ERR_dcl_fct_par_weak () ) ;
-
 
1549
	    }
1645
	p1 = p;
1550
#if LANGUAGE_CPP
-
 
1551
	    ell &= FUNC_ELLIPSIS ;
1646
	while (!IS_NULL_list(p1)) {
1552
#endif
-
 
1553
	} else {
1647
		ERROR err;
1554
	    report ( crt_loc, ERR_dcl_fct_proto () ) ;
1648
		id = DEREF_id(HEAD_list(p1));
1555
	}
-
 
1556
    }
-
 
1557
 
-
 
1558
    /* Check for '( ... )' */
-
 
1559
    if ( no_param == 0 && ( ell & FUNC_ELLIPSIS ) ) {
-
 
1560
	report ( crt_loc, ERR_dcl_fct_par_ellipsis () ) ;
1649
		t = DEREF_type(id_parameter_type(id));
1561
    }
-
 
1562
 
-
 
1563
    /* Check for '( void )' */
1650
		err = check_param_type(id, t);
1564
    if ( no_param == 1 && !( ell & FUNC_ELLIPSIS ) ) {
-
 
1565
	/* Precisely one parameter (in t and id) */
-
 
1566
	if ( IS_type_top ( t ) ) {
1651
		if (!IS_NULL_err(err)) {
1567
	    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
-
 
1568
	    if ( !IS_hashid_anon ( nm ) ) {
1652
			/* Void or other illegal parameter type */
1569
		report ( crt_loc, ERR_dcl_fct_par_empty () ) ;
1653
			report(crt_loc, err);
1570
	    }
1654
		}
1571
	    DESTROY_list ( q, SIZE_type ) ;
-
 
1572
	    DESTROY_list ( p, SIZE_id ) ;
-
 
1573
	    q = NULL_list ( TYPE ) ;
1655
		p1 = TAIL_list(p1);
1574
	    p = NULL_list ( IDENTIFIER ) ;
-
 
1575
	}
1656
	}
1576
    }
-
 
1577
 
1657
 
1578
    /* Check for other void parameters */
-
 
1579
    p1 = p ;
-
 
1580
    while ( !IS_NULL_list ( p1 ) ) {
-
 
1581
	ERROR err ;
-
 
1582
	id = DEREF_id ( HEAD_list ( p1 ) ) ;
-
 
1583
	t = DEREF_type ( id_parameter_type ( id ) ) ;
-
 
1584
	err = check_param_type ( id, t ) ;
-
 
1585
	if ( !IS_NULL_err ( err ) ) {
-
 
1586
	    /* Void or other illegal parameter type */
-
 
1587
	    report ( crt_loc, err ) ;
-
 
1588
	}
-
 
1589
	p1 = TAIL_list ( p1 ) ;
-
 
1590
    }
-
 
1591
 
-
 
1592
    /* Construct the function type */
1658
	/* Construct the function type */
1593
    MAKE_type_func ( cv_none, r, q, ell, cv, q, ns, p, ex, t ) ;
1659
	MAKE_type_func(cv_none, r, q, ell, cv, q, ns, p, ex, t);
1594
    return ( t ) ;
1660
	return (t);
1595
}
1661
}
1596
 
1662
 
1597
 
1663
 
1598
/*
1664
/*
1599
    ADJUST MEMBER FUNCTION TYPES
1665
    ADJUST MEMBER FUNCTION TYPES
1600
 
1666
 
1601
    Each function type has two lists of parameter types, ptypes, which
1667
    Each function type has two lists of parameter types, ptypes, which
1602
    gives the actual declared parameters, and mtypes, which has an extra
1668
    gives the actual declared parameters, and mtypes, which has an extra
1603
    reference to class parameter for non-static member functions, or an
1669
    reference to class parameter for non-static member functions, or an
1604
    extra null parameter for static member functions.  This routine sets
1670
    extra null parameter for static member functions.  This routine sets
1605
    the mtypes field of t from the ptypes field according to whether or not
1671
    the mtypes field of t from the ptypes field according to whether or not
1606
    ct is the null class and the tag of an associated declaration, itag.
1672
    ct is the null class and the tag of an associated declaration, itag.
1607
    Note that member function types always have C++ linkage.
1673
    Note that member function types always have C++ linkage.
1608
*/
1674
*/
1609
 
1675
 
1610
void member_func_type
1676
void
1611
    PROTO_N ( ( ct, itag, t ) )
-
 
1612
    PROTO_T ( CLASS_TYPE ct X unsigned itag X TYPE t )
1677
member_func_type(CLASS_TYPE ct, unsigned itag, TYPE t)
1613
{
1678
{
1614
    unsigned tag = TAG_type ( t ) ;
1679
	unsigned tag = TAG_type(t);
1615
    while ( tag == type_templ_tag ) {
1680
	while (tag == type_templ_tag) {
1616
	t = DEREF_type ( type_templ_defn ( t ) ) ;
1681
		t = DEREF_type(type_templ_defn(t));
1617
	tag = TAG_type ( t ) ;
1682
		tag = TAG_type(t);
1618
    }
1683
	}
1619
    if ( tag == type_func_tag ) {
1684
	if (tag == type_func_tag) {
1620
	CV_SPEC cv = DEREF_cv ( type_func_mqual ( t ) ) ;
1685
		CV_SPEC cv = DEREF_cv(type_func_mqual(t));
1621
	CV_SPEC qual = ( cv & cv_qual ) ;
1686
		CV_SPEC qual = (cv & cv_qual);
1622
	LIST ( TYPE ) ptypes = DEREF_list ( type_func_ptypes ( t ) ) ;
1687
		LIST(TYPE) ptypes = DEREF_list(type_func_ptypes(t));
1623
	LIST ( TYPE ) mtypes = DEREF_list ( type_func_mtypes ( t ) ) ;
1688
		LIST(TYPE) mtypes = DEREF_list(type_func_mtypes(t));
1624
	if ( IS_NULL_ctype ( ct ) ) {
1689
		if (IS_NULL_ctype(ct)) {
1625
	    /* Non-member functions */
1690
			/* Non-member functions */
1626
	    if ( qual && itag != id_type_alias_tag ) {
1691
			if (qual && itag != id_type_alias_tag) {
1627
		/* Can't have cv-qualifiers */
1692
				/* Can't have cv-qualifiers */
1628
		report ( crt_loc, ERR_dcl_fct_cv ( qual ) ) ;
1693
				report(crt_loc, ERR_dcl_fct_cv(qual));
1629
		cv &= ~cv_qual ;
1694
				cv &= ~cv_qual;
1630
		COPY_cv ( type_func_mqual ( t ), cv ) ;
1695
				COPY_cv(type_func_mqual(t), cv);
1631
	    }
1696
			}
1632
	    if ( !EQ_list ( ptypes, mtypes ) ) {
1697
			if (!EQ_list(ptypes, mtypes)) {
1633
		/* Set mtypes equal to ptypes */
1698
				/* Set mtypes equal to ptypes */
1634
		COPY_list ( type_func_mtypes ( t ), ptypes ) ;
1699
				COPY_list(type_func_mtypes(t), ptypes);
1635
	    }
1700
			}
1636
	} else {
1701
		} else {
1637
	    /* Member functions */
1702
			/* Member functions */
1638
	    if ( EQ_list ( ptypes, mtypes ) ) {
1703
			if (EQ_list(ptypes, mtypes)) {
1639
		/* Add extra argument to mtypes */
1704
				/* Add extra argument to mtypes */
1640
		TYPE r ;
1705
				TYPE r;
1641
		if ( itag == id_mem_func_tag ) {
1706
				if (itag == id_mem_func_tag) {
-
 
1707
					IDENTIFIER cid =
1642
		    IDENTIFIER cid = DEREF_id ( ctype_name ( ct ) ) ;
1708
					    DEREF_id(ctype_name(ct));
1643
		    cv = ( qual | cv_cpp ) ;
1709
					cv = (qual | cv_cpp);
1644
		    qual |= cv_lvalue ;
1710
					qual |= cv_lvalue;
1645
		    MAKE_type_compound ( qual, ct, r ) ;
1711
					MAKE_type_compound(qual, ct, r);
1646
		    COPY_id ( type_name ( r ), cid ) ;
1712
					COPY_id(type_name(r), cid);
1647
		    MAKE_type_ref ( cv_none, r, r ) ;
1713
					MAKE_type_ref(cv_none, r, r);
1648
		} else {
1714
				} else {
1649
		    if ( qual ) {
1715
					if (qual) {
1650
			/* Can't have cv-qualifiers */
1716
						/* Can't have cv-qualifiers */
-
 
1717
						report(crt_loc,
1651
			report ( crt_loc, ERR_dcl_fct_cv ( qual ) ) ;
1718
						       ERR_dcl_fct_cv(qual));
1652
		    }
1719
					}
1653
		    r = NULL_type ;
1720
					r = NULL_type;
1654
		    cv = cv_cpp ;
1721
					cv = cv_cpp;
1655
		}
1722
				}
1656
		CONS_type ( r, ptypes, mtypes ) ;
1723
				CONS_type(r, ptypes, mtypes);
1657
		COPY_list ( type_func_mtypes ( t ), mtypes ) ;
1724
				COPY_list(type_func_mtypes(t), mtypes);
1658
		COPY_cv ( type_func_mqual ( t ), cv ) ;
1725
				COPY_cv(type_func_mqual(t), cv);
1659
	    } else {
1726
			} else {
1660
		/* Don't check existing extra argument */
1727
				/* Don't check existing extra argument */
1661
		/* EMPTY */
1728
				/* EMPTY */
1662
	    }
1729
			}
1663
	}
1730
		}
1664
    }
1731
	}
1665
    return ;
1732
	return;
1666
}
1733
}
1667
 
1734
 
1668
 
1735
 
1669
/*
1736
/*
1670
    CHECK A NON-PROTOTYPE FUNCTION TYPE
1737
    CHECK A NON-PROTOTYPE FUNCTION TYPE
1671
 
1738
 
1672
    A parameter list can only be used in a function definition.  This
1739
    A parameter list can only be used in a function definition.  This
1673
    routine checks the function type t with def being true for a function
1740
    routine checks the function type t with def being true for a function
1674
    definition.
1741
    definition.
1675
*/
1742
*/
1676
 
1743
 
1677
void check_weak_func
1744
void
1678
    PROTO_N ( ( t, def ) )
-
 
1679
    PROTO_T ( TYPE t X int def )
1745
check_weak_func(TYPE t, int def)
1680
{
1746
{
1681
    int ell = DEREF_int ( type_func_ellipsis ( t ) ) ;
1747
	int ell = DEREF_int(type_func_ellipsis(t));
1682
    if ( ell == FUNC_PARAMS ) {
1748
	if (ell == FUNC_PARAMS) {
1683
	/* Have parameter list '( a1, a2, ..., an )' */
1749
		/* Have parameter list '( a1, a2, ..., an )' */
1684
	if ( def ) {
1750
		if (def) {
1685
	    LOCATION loc ;
1751
			LOCATION loc;
1686
	    LIST ( TYPE ) q = NULL_list ( TYPE ) ;
1752
			LIST(TYPE) q = NULL_list(TYPE);
1687
	    LIST ( IDENTIFIER ) p = DEREF_list ( type_func_pids ( t ) ) ;
1753
			LIST(IDENTIFIER) p = DEREF_list(type_func_pids(t));
1688
	    NAMESPACE ns = DEREF_nspace ( type_func_pars ( t ) ) ;
1754
			NAMESPACE ns = DEREF_nspace(type_func_pars(t));
1689
	    MEMBER mem = DEREF_member ( nspace_last ( ns ) ) ;
1755
			MEMBER mem = DEREF_member(nspace_last(ns));
1690
	    loc = decl_loc ;
1756
			loc = decl_loc;
1691
	    bad_crt_loc++ ;
1757
			bad_crt_loc++;
1692
	    while ( !IS_NULL_member ( mem ) ) {
1758
			while (!IS_NULL_member(mem)) {
1693
		IDENTIFIER id = DEREF_id ( member_id ( mem ) ) ;
1759
				IDENTIFIER id = DEREF_id(member_id(mem));
1694
		if ( !IS_NULL_id ( id ) ) {
1760
				if (!IS_NULL_id(id)) {
1695
		    if ( IS_id_weak_param ( id ) ) {
1761
					if (IS_id_weak_param(id)) {
1696
			/* Implicitly declare parameter */
1762
						/* Implicitly declare
-
 
1763
						 * parameter */
1697
			ERROR err ;
1764
						ERROR err;
1698
			TYPE s = type_sint ;
1765
						TYPE s = type_sint;
1699
			int par = CONTEXT_WEAK_PARAM ;
1766
						int par = CONTEXT_WEAK_PARAM;
1700
			DEREF_loc ( id_loc ( id ), decl_loc ) ;
1767
						DEREF_loc(id_loc(id), decl_loc);
1701
			id = make_param_decl ( dspec_none, s, id, par ) ;
1768
						id = make_param_decl(dspec_none, s, id, par);
1702
			init_param ( id, NULL_exp ) ;
1769
						init_param(id, NULL_exp);
1703
			err = ERR_dcl_fct_par_impl ( id ) ;
1770
						err = ERR_dcl_fct_par_impl(id);
1704
			if ( !IS_NULL_err ( err ) ) {
1771
						if (!IS_NULL_err(err)) {
1705
			    ERROR err2 = ERR_dcl_type_infer ( s ) ;
1772
							ERROR err2 = ERR_dcl_type_infer(s);
1706
			    err = concat_error ( err, err2 ) ;
1773
							err = concat_error(err, err2);
1707
			    report ( decl_loc, err ) ;
1774
							report(decl_loc, err);
1708
			}
1775
						}
1709
			CONS_id ( id, p, p ) ;
1776
						CONS_id(id, p, p);
1710
			CONS_type ( s, q, q ) ;
1777
						CONS_type(s, q, q);
1711
		    } else if ( IS_id_parameter ( id ) ) {
1778
					} else if (IS_id_parameter(id)) {
1712
			/* Add parameter to list */
1779
						/* Add parameter to list */
1713
			TYPE s = DEREF_type ( id_parameter_type ( id ) ) ;
1780
						TYPE s = DEREF_type(id_parameter_type(id));
1714
			if ( !is_arg_promote ( s ) ) {
1781
						if (!is_arg_promote(s)) {
1715
			    DECL_SPEC ds ;
1782
							DECL_SPEC ds;
1716
			    s = arg_promote_type ( s, KILL_err ) ;
1783
							s = arg_promote_type(s, KILL_err);
1717
			    ds = DEREF_dspec ( id_storage ( id ) ) ;
1784
							ds = DEREF_dspec(id_storage(id));
1718
			    ds |= dspec_virtual ;
1785
							ds |= dspec_virtual;
1719
			    COPY_dspec ( id_storage ( id ), ds ) ;
1786
							COPY_dspec(id_storage(id), ds);
1720
			}
1787
						}
1721
			s = qualify_type ( s, cv_none, 0 ) ;
1788
						s = qualify_type(s, cv_none, 0);
1722
			CONS_id ( id, p, p ) ;
1789
						CONS_id(id, p, p);
1723
			CONS_type ( s, q, q ) ;
1790
						CONS_type(s, q, q);
1724
		    }
1791
					}
-
 
1792
				}
-
 
1793
				mem = DEREF_member(member_next(mem));
-
 
1794
			}
-
 
1795
			COPY_list(type_func_ptypes(t), q);
-
 
1796
			COPY_list(type_func_mtypes(t), q);
-
 
1797
			COPY_list(type_func_pids(t), p);
-
 
1798
			bad_crt_loc--;
-
 
1799
			decl_loc = loc;
-
 
1800
			ell = FUNC_WEAK_PARAMS;
-
 
1801
		} else {
-
 
1802
			report(crt_loc, ERR_dcl_fct_weak());
-
 
1803
			ell = FUNC_NO_PARAMS;
-
 
1804
		}
-
 
1805
	} else if (ell == FUNC_NO_PARAMS) {
-
 
1806
		/* Have empty parameter list '()' */
-
 
1807
		if (def) {
-
 
1808
			ell = FUNC_WEAK_PARAMS;
1725
		}
1809
		}
1726
		mem = DEREF_member ( member_next ( mem ) ) ;
-
 
1727
	    }
-
 
1728
	    COPY_list ( type_func_ptypes ( t ), q ) ;
-
 
1729
	    COPY_list ( type_func_mtypes ( t ), q ) ;
-
 
1730
	    COPY_list ( type_func_pids ( t ), p ) ;
-
 
1731
	    bad_crt_loc-- ;
-
 
1732
	    decl_loc = loc ;
-
 
1733
	    ell = FUNC_WEAK_PARAMS ;
-
 
1734
	} else {
-
 
1735
	    report ( crt_loc, ERR_dcl_fct_weak () ) ;
-
 
1736
	    ell = FUNC_NO_PARAMS ;
-
 
1737
	}
1810
	}
1738
    } else if ( ell == FUNC_NO_PARAMS ) {
-
 
1739
	/* Have empty parameter list '()' */
-
 
1740
	if ( def ) ell = FUNC_WEAK_PARAMS ;
-
 
1741
    }
-
 
1742
    COPY_int ( type_func_ellipsis ( t ), ell ) ;
1811
	COPY_int(type_func_ellipsis(t), ell);
1743
    return ;
1812
	return;
1744
}
1813
}
1745
 
1814
 
1746
 
1815
 
1747
/*
1816
/*
1748
    CHECK THE FUNCTION COMPONENTS OF AN OBJECT TYPE
1817
    CHECK THE FUNCTION COMPONENTS OF AN OBJECT TYPE
1749
 
1818
 
1750
    This routine checks the function components of an object with the
1819
    This routine checks the function components of an object with the
1751
    given identifier tag and type t.
1820
    given identifier tag and type t.
1752
*/
1821
*/
1753
 
1822
 
1754
void object_type
1823
void
1755
    PROTO_N ( ( t, tag ) )
-
 
1756
    PROTO_T ( TYPE t X unsigned tag )
1824
object_type(TYPE t, unsigned tag)
1757
{
1825
{
1758
    int depth = 0 ;
1826
	int depth = 0;
1759
    if ( tag == id_type_alias_tag || tag == null_tag ) {
1827
	if (tag == id_type_alias_tag || tag == null_tag) {
1760
	/* Force errors in these cases */
1828
		/* Force errors in these cases */
1761
	depth = 2 ;
1829
		depth = 2;
1762
    }
1830
	}
1763
    while ( !IS_NULL_type ( t ) ) {
1831
	while (!IS_NULL_type(t)) {
1764
	ASSERT ( ORDER_type == 18 ) ;
1832
		ASSERT(ORDER_type == 18);
1765
	switch ( TAG_type ( t ) ) {
1833
		switch (TAG_type(t)) {
1766
	    case type_func_tag : {
1834
		case type_func_tag: {
1767
		/* Function types */
1835
			/* Function types */
1768
		LIST ( TYPE ) ex ;
1836
			LIST(TYPE) ex;
1769
		CV_SPEC cv = DEREF_cv ( type_func_mqual ( t ) ) ;
1837
			CV_SPEC cv = DEREF_cv(type_func_mqual(t));
1770
 
1838
 
1771
		/* Check function qualifiers */
1839
			/* Check function qualifiers */
1772
		CV_SPEC mq = ( cv & cv_qual ) ;
1840
			CV_SPEC mq = (cv & cv_qual);
1773
		CV_SPEC lq = ( cv & cv_language ) ;
1841
			CV_SPEC lq = (cv & cv_language);
1774
		if ( depth == 0 ) {
1842
			if (depth == 0) {
1775
		    if ( tag == id_mem_func_tag ) {
1843
				if (tag == id_mem_func_tag) {
1776
			/* Member functions have C++ linkage */
1844
					/* Member functions have C++ linkage */
1777
			lq = cv_cpp ;
1845
					lq = cv_cpp;
1778
		    } else {
1846
				} else {
1779
			if ( mq ) {
1847
					if (mq) {
1780
			    /* Can't have cv-qualifiers */
1848
						/* Can't have cv-qualifiers */
-
 
1849
						report(crt_loc,
1781
			    report ( crt_loc, ERR_dcl_fct_cv_decl ( mq ) ) ;
1850
						       ERR_dcl_fct_cv_decl(mq));
1782
			    mq = cv_none ;
1851
						mq = cv_none;
1783
			}
1852
					}
1784
			if ( tag == id_stat_mem_func_tag ) {
1853
					if (tag == id_stat_mem_func_tag) {
1785
			    /* Member functions have C++ linkage */
1854
						/* Member functions have C++
-
 
1855
						 * linkage */
1786
			    lq = cv_cpp ;
1856
						lq = cv_cpp;
-
 
1857
					}
-
 
1858
				}
-
 
1859
			}
-
 
1860
			if (lq == cv_none) {
-
 
1861
				lq = cv_lang;
-
 
1862
			}
-
 
1863
			COPY_cv(type_func_mqual(t), (mq | lq));
-
 
1864
 
-
 
1865
			/* Check default arguments */
-
 
1866
			if (depth && check_func_dargs(t, 0, 0)) {
-
 
1867
				report(crt_loc, ERR_dcl_fct_default_bad());
-
 
1868
			}
-
 
1869
 
-
 
1870
			/* Check exception specifiers */
-
 
1871
			ex = DEREF_list(type_func_except(t));
-
 
1872
			if (!EQ_list(ex, empty_type_set)) {
-
 
1873
				if (!EQ_list(ex, univ_type_set)) {
-
 
1874
					ulong n = (ulong)LENGTH_list(ex);
-
 
1875
					IGNORE check_value(OPT_VAL_exception_specs, n);
-
 
1876
				}
-
 
1877
				if (depth > 1) {
-
 
1878
					report(crt_loc, ERR_except_spec_bad());
-
 
1879
				}
1787
			}
1880
			}
1788
		    }
-
 
1789
		}
-
 
1790
		if ( lq == cv_none ) lq = cv_lang ;
-
 
1791
		COPY_cv ( type_func_mqual ( t ), ( mq | lq ) ) ;
-
 
1792
 
-
 
1793
		/* Check default arguments */
-
 
1794
		if ( depth && check_func_dargs ( t, 0, 0 ) ) {
-
 
1795
		    report ( crt_loc, ERR_dcl_fct_default_bad () ) ;
-
 
1796
		}
-
 
1797
 
-
 
1798
		/* Check exception specifiers */
-
 
1799
		ex = DEREF_list ( type_func_except ( t ) ) ;
-
 
1800
		if ( !EQ_list ( ex, empty_type_set ) ) {
-
 
1801
		    if ( !EQ_list ( ex, univ_type_set ) ) {
-
 
1802
			ulong n = ( ulong ) LENGTH_list ( ex ) ;
-
 
1803
			IGNORE check_value ( OPT_VAL_exception_specs, n ) ;
-
 
1804
		    }
-
 
1805
		    if ( depth > 1 ) {
-
 
1806
			report ( crt_loc, ERR_except_spec_bad () ) ;
-
 
1807
		    }
-
 
1808
		}
-
 
1809
 
1881
 
1810
		/* Recheck parameter types */
1882
			/* Recheck parameter types */
1811
		if ( depth > 1 ) {
1883
			if (depth > 1) {
1812
		    LIST ( TYPE ) p ;
1884
				LIST(TYPE)p;
1813
		    p = DEREF_list ( type_func_ptypes ( t ) ) ;
1885
				p = DEREF_list(type_func_ptypes(t));
1814
		    while ( !IS_NULL_list ( p ) ) {
1886
				while (!IS_NULL_list(p)) {
1815
			TYPE s = DEREF_type ( HEAD_list ( p ) ) ;
1887
					TYPE s = DEREF_type(HEAD_list(p));
1816
			s = find_func_type ( s ) ;
1888
					s = find_func_type(s);
1817
			if ( !IS_NULL_type ( s ) ) {
1889
					if (!IS_NULL_type(s)) {
1818
			    ex = DEREF_list ( type_func_except ( s ) ) ;
1890
						ex = DEREF_list(type_func_except(s));
1819
			    if ( !EQ_list ( ex, empty_type_set ) ) {
1891
						if (!EQ_list(ex, empty_type_set)) {
1820
				report ( crt_loc, ERR_except_spec_bad () ) ;
1892
							report(crt_loc, ERR_except_spec_bad());
1821
			    }
1893
						}
-
 
1894
					}
-
 
1895
					p = TAIL_list(p);
-
 
1896
				}
1822
			}
1897
			}
-
 
1898
			return;
-
 
1899
		}
1823
			p = TAIL_list ( p ) ;
1900
		case type_ptr_tag: {
-
 
1901
			t = DEREF_type(type_ptr_sub(t));
-
 
1902
			depth++;
-
 
1903
			break;
-
 
1904
		}
-
 
1905
		case type_ref_tag: {
-
 
1906
			t = DEREF_type(type_ref_sub(t));
-
 
1907
			break;
-
 
1908
		}
-
 
1909
		case type_ptr_mem_tag: {
-
 
1910
			t = DEREF_type(type_ptr_mem_sub(t));
-
 
1911
			depth++;
-
 
1912
			break;
-
 
1913
		}
-
 
1914
		case type_array_tag: {
-
 
1915
			t = DEREF_type(type_array_sub(t));
-
 
1916
			depth++;
-
 
1917
			break;
-
 
1918
		}
-
 
1919
		case type_templ_tag: {
-
 
1920
			t = DEREF_type(type_templ_defn(t));
-
 
1921
			break;
1824
		    }
1922
		}
-
 
1923
		default:
-
 
1924
			/* Other types */
-
 
1925
			return;
1825
		}
1926
		}
1826
		return ;
-
 
1827
	    }
-
 
1828
	    case type_ptr_tag : {
-
 
1829
		t = DEREF_type ( type_ptr_sub ( t ) ) ;
-
 
1830
		depth++ ;
-
 
1831
		break ;
-
 
1832
	    }
-
 
1833
	    case type_ref_tag : {
-
 
1834
		t = DEREF_type ( type_ref_sub ( t ) ) ;
-
 
1835
		break ;
-
 
1836
	    }
-
 
1837
	    case type_ptr_mem_tag : {
-
 
1838
		t = DEREF_type ( type_ptr_mem_sub ( t ) ) ;
-
 
1839
		depth++ ;
-
 
1840
		break ;
-
 
1841
	    }
-
 
1842
	    case type_array_tag : {
-
 
1843
		t = DEREF_type ( type_array_sub ( t ) ) ;
-
 
1844
		depth++ ;
-
 
1845
		break ;
-
 
1846
	    }
-
 
1847
	    case type_templ_tag : {
-
 
1848
		t = DEREF_type ( type_templ_defn ( t ) ) ;
-
 
1849
		break ;
-
 
1850
	    }
-
 
1851
	    default : {
-
 
1852
		/* Other types */
-
 
1853
		return ;
-
 
1854
	    }
-
 
1855
	}
1927
	}
1856
    }
-
 
1857
    return ;
1928
	return;
1858
}
1929
}
1859
 
1930
 
1860
 
1931
 
1861
/*
1932
/*
1862
    DECLARE A FUNCTION TYPE
1933
    DECLARE A FUNCTION TYPE
Line 1864... Line 1935...
1864
    This routine checks the function or function typedef id of type t,
1935
    This routine checks the function or function typedef id of type t,
1865
    including checking that if a default argument is given for a
1936
    including checking that if a default argument is given for a
1866
    particular parameter one is also given for all subsequent parameters.
1937
    particular parameter one is also given for all subsequent parameters.
1867
    The redeclaration case, where default arguments can be inherited
1938
    The redeclaration case, where default arguments can be inherited
1868
    from the previous declaration is dealt with by redecl_func_type.
1939
    from the previous declaration is dealt with by redecl_func_type.
1869
*/
1940
*/
1870
 
1941
 
1871
void decl_func_type
1942
void
1872
    PROTO_N ( ( id, t, def ) )
-
 
1873
    PROTO_T ( IDENTIFIER id X TYPE t X int def )
1943
decl_func_type(IDENTIFIER id, TYPE t, int def)
1874
{
1944
{
1875
    NAMESPACE pns ;
1945
	NAMESPACE pns;
1876
    int is_templ = 0 ;
1946
	int is_templ = 0;
1877
    unsigned tag = TAG_id ( id ) ;
1947
	unsigned tag = TAG_id(id);
1878
 
1948
 
1879
    /* Step over template components */
1949
	/* Step over template components */
1880
    if ( IS_type_templ ( t ) ) {
1950
	if (IS_type_templ(t)) {
1881
	t = check_templ_params ( t, id ) ;
1951
		t = check_templ_params(t, id);
1882
	is_templ = 1 ;
1952
		is_templ = 1;
1883
    }
1953
	}
1884
    pns = DEREF_nspace ( type_func_pars ( t ) ) ;
1954
	pns = DEREF_nspace(type_func_pars(t));
1885
    COPY_id ( nspace_name ( pns ), id ) ;
1955
	COPY_id(nspace_name(pns), id);
1886
 
1956
 
1887
    /* Check default arguments */
1957
	/* Check default arguments */
1888
    IGNORE check_func_dargs ( t, 1, 0 ) ;
1958
	IGNORE check_func_dargs(t, 1, 0);
1889
 
1959
 
1890
    /* Check cv-qualifiers */
1960
	/* Check cv-qualifiers */
1891
    switch ( tag ) {
1961
	switch (tag) {
1892
	case id_function_tag :
1962
	case id_function_tag:
1893
	case id_mem_func_tag :
1963
	case id_mem_func_tag:
1894
	case id_stat_mem_func_tag : {
1964
	case id_stat_mem_func_tag: {
1895
	    /* Allow for member functions */
1965
		/* Allow for member functions */
1896
	    CLASS_TYPE ct = parent_class ( id ) ;
1966
		CLASS_TYPE ct = parent_class(id);
1897
	    member_func_type ( ct, tag, t ) ;
1967
		member_func_type(ct, tag, t);
1898
 
1968
 
1899
	    /* Allow for overloading of template functions */
1969
		/* Allow for overloading of template functions */
1900
	    if ( is_templ ) {
1970
		if (is_templ) {
1901
		templ_func_decl ( id ) ;
1971
			templ_func_decl(id);
1902
	    } else {
1972
		} else {
1903
		IDENTIFIER over = DEREF_id ( id_function_etc_over ( id ) ) ;
1973
			IDENTIFIER over = DEREF_id(id_function_etc_over(id));
1904
		if ( !IS_NULL_id ( over ) ) {
1974
			if (!IS_NULL_id(over)) {
1905
		    /* Overloads a template function */
1975
				/* Overloads a template function */
1906
		    DECL_SPEC ds = DEREF_dspec ( id_storage ( over ) ) ;
1976
				DECL_SPEC ds = DEREF_dspec(id_storage(over));
1907
		    if ( ds & dspec_template ) templ_func_decl ( id ) ;
1977
				if (ds & dspec_template) {
-
 
1978
					templ_func_decl(id);
-
 
1979
				}
-
 
1980
			}
1908
		}
1981
		}
-
 
1982
		break;
1909
	    }
1983
	}
-
 
1984
	default:
-
 
1985
		/* Allow for function typedefs */
-
 
1986
		member_func_type(NULL_ctype, tag, t);
1910
	    break ;
1987
		break;
1911
	}
1988
	}
1912
	default : {
-
 
1913
	    /* Allow for function typedefs */
-
 
1914
	    member_func_type ( NULL_ctype, tag, t ) ;
-
 
1915
	    break ;
-
 
1916
	}
-
 
1917
    }
-
 
1918
    UNUSED ( def ) ;
1989
	UNUSED(def);
1919
    return ;
1990
	return;
1920
}
1991
}
1921
 
1992
 
1922
 
1993
 
1923
/*
1994
/*
1924
    REDECLARE DEFAULT ARGUMENTS
1995
    REDECLARE DEFAULT ARGUMENTS
Line 1926... Line 1997...
1926
    This routine checks and unifies the default arguments for the equal
1997
    This routine checks and unifies the default arguments for the equal
1927
    function types s and t.  It returns the number of default arguments
1998
    function types s and t.  It returns the number of default arguments
1928
    added by this unification.
1999
    added by this unification.
1929
*/
2000
*/
1930
 
2001
 
1931
static unsigned redecl_func_dargs
2002
static unsigned
1932
    PROTO_N ( ( s, t ) )
-
 
1933
    PROTO_T ( TYPE s X TYPE t )
2003
redecl_func_dargs(TYPE s, TYPE t)
1934
{
2004
{
1935
    unsigned nargs = 0 ;
2005
    unsigned nargs = 0;
1936
    if ( IS_type_func ( s ) && IS_type_func ( t ) ) {
2006
    if (IS_type_func(s) && IS_type_func(t)) {
1937
	int started = 0 ;
2007
	int started = 0;
1938
	LIST ( IDENTIFIER ) ps = DEREF_list ( type_func_pids ( s ) ) ;
2008
	LIST(IDENTIFIER) ps = DEREF_list(type_func_pids(s));
1939
	LIST ( IDENTIFIER ) pt = DEREF_list ( type_func_pids ( t ) ) ;
2009
	LIST(IDENTIFIER) pt = DEREF_list(type_func_pids(t));
1940
	while ( !IS_NULL_list ( ps ) && !IS_NULL_list ( pt ) ) {
2010
	while (!IS_NULL_list(ps) && !IS_NULL_list(pt)) {
1941
	    ERROR err = NULL_err ;
2011
	    ERROR err = NULL_err;
1942
	    IDENTIFIER as = DEREF_id ( HEAD_list ( ps ) ) ;
2012
	    IDENTIFIER as = DEREF_id(HEAD_list(ps));
1943
	    IDENTIFIER at = DEREF_id ( HEAD_list ( pt ) ) ;
2013
	    IDENTIFIER at = DEREF_id(HEAD_list(pt));
1944
	    EXP ds = DEREF_exp ( id_parameter_init ( as ) ) ;
2014
	    EXP ds = DEREF_exp(id_parameter_init(as));
1945
	    EXP dt = DEREF_exp ( id_parameter_init ( at ) ) ;
2015
	    EXP dt = DEREF_exp(id_parameter_init(at));
1946
	    if ( IS_NULL_exp ( ds ) ) {
2016
	    if (IS_NULL_exp(ds)) {
1947
		/* No existing default argument */
2017
		/* No existing default argument */
1948
		if ( IS_NULL_exp ( dt ) ) {
2018
		if (IS_NULL_exp(dt)) {
1949
		    if ( started ) {
2019
		    if (started) {
1950
			/* Missing default arguments */
2020
			/* Missing default arguments */
1951
			TYPE r = DEREF_type ( id_parameter_type ( at ) ) ;
2021
			TYPE r = DEREF_type(id_parameter_type(at));
1952
			err = ERR_dcl_fct_default_missing ( at ) ;
2022
			err = ERR_dcl_fct_default_missing(at);
1953
			MAKE_exp_value ( r, dt ) ;
2023
			MAKE_exp_value(r, dt);
1954
			COPY_exp ( id_parameter_init ( at ), dt ) ;
2024
			COPY_exp(id_parameter_init(at), dt);
1955
			COPY_exp ( id_parameter_init ( as ), dt ) ;
2025
			COPY_exp(id_parameter_init(as), dt);
1956
		    }
2026
		    }
1957
		} else {
2027
		} else {
1958
		    /* New default argument */
2028
		    /* New default argument */
1959
		    COPY_exp ( id_parameter_init ( as ), dt ) ;
2029
		    COPY_exp(id_parameter_init(as), dt);
1960
		    dt = DEREF_exp ( id_parameter_term ( at ) ) ;
2030
		    dt = DEREF_exp(id_parameter_term(at));
1961
		    COPY_exp ( id_parameter_term ( as ), dt ) ;
2031
		    COPY_exp(id_parameter_term(as), dt);
1962
		    nargs++ ;
2032
		    nargs++;
1963
		    started = 1 ;
2033
		    started = 1;
1964
		}
2034
		}
1965
	    } else {
2035
	    } else {
1966
		/* Existing default argument */
2036
		/* Existing default argument */
1967
		if ( IS_NULL_exp ( dt ) ) {
2037
		if (IS_NULL_exp(dt)) {
1968
		    /* Inherited default argument */
2038
		    /* Inherited default argument */
1969
		    COPY_exp ( id_parameter_init ( at ), ds ) ;
2039
		    COPY_exp(id_parameter_init(at), ds);
1970
		    ds = DEREF_exp ( id_parameter_term ( as ) ) ;
2040
		    ds = DEREF_exp(id_parameter_term(as));
1971
		    COPY_exp ( id_parameter_term ( at ), ds ) ;
2041
		    COPY_exp(id_parameter_term(at), ds);
1972
		} else {
2042
		} else {
1973
		    /* Redefined default argument */
2043
		    /* Redefined default argument */
1974
		    PTR ( LOCATION ) sloc = id_loc ( as ) ;
2044
		    PTR(LOCATION)sloc = id_loc(as);
1975
		    if ( eq_exp ( ds, dt, 0 ) ) {
2045
		    if (eq_exp(ds, dt, 0)) {
1976
			err = ERR_dcl_fct_default_dup ( at, sloc ) ;
2046
			err = ERR_dcl_fct_default_dup(at, sloc);
1977
		    } else {
2047
		    } else {
1978
			/* NOT YET IMPLEMENTED: dt uncompiled */
2048
			/* NOT YET IMPLEMENTED: dt uncompiled */
1979
			err = ERR_dcl_fct_default_redef ( at, sloc ) ;
2049
			err = ERR_dcl_fct_default_redef(at, sloc);
1980
		    }
2050
		    }
1981
		    COPY_exp ( id_parameter_init ( as ), dt ) ;
2051
		    COPY_exp(id_parameter_init(as), dt);
1982
		    dt = DEREF_exp ( id_parameter_term ( at ) ) ;
2052
		    dt = DEREF_exp(id_parameter_term(at));
1983
		    COPY_exp ( id_parameter_term ( as ), dt ) ;
2053
		    COPY_exp(id_parameter_term(as), dt);
1984
		}
2054
		}
1985
		started = 1 ;
2055
		started = 1;
1986
	    }
2056
	    }
1987
	    if ( !IS_NULL_err ( err ) ) {
2057
	    if (!IS_NULL_err(err)) {
1988
		/* Report any errors */
2058
		/* Report any errors */
1989
		LOCATION loc ;
2059
		LOCATION loc;
1990
		DEREF_loc ( id_loc ( at ), loc ) ;
2060
		DEREF_loc(id_loc(at), loc);
1991
		report ( loc, err ) ;
2061
		report(loc, err);
1992
	    }
2062
	    }
1993
	    ps = TAIL_list ( ps ) ;
2063
	    ps = TAIL_list(ps);
1994
	    pt = TAIL_list ( pt ) ;
2064
	    pt = TAIL_list(pt);
1995
	}
2065
	}
1996
    }
2066
    }
1997
    return ( nargs ) ;
2067
    return (nargs);
1998
}
2068
}
1999
 
2069
 
2000
 
2070
 
2001
/*
2071
/*
2002
    REDECLARE A FUNCTION TYPE
2072
    REDECLARE A FUNCTION TYPE
2003
 
2073
 
2004
    This routine deals with the compatible redeclaration of the function
2074
    This routine deals with the compatible redeclaration of the function
2005
    id of type s to have type t.  It unifies the parameter types, checking
2075
    id of type s to have type t.  It unifies the parameter types, checking
2006
    default arguments etc.  It also checks any exception specifications
2076
    default arguments etc.  It also checks any exception specifications
2007
    for the two declarations.  The parameter names in the returned type
2077
    for the two declarations.  The parameter names in the returned type
2008
    are those from t if def is true, and those from s otherwise.
2078
    are those from t if def is true, and those from s otherwise.
2009
*/
2079
*/
2010
 
2080
 
2011
TYPE redecl_func_type
2081
TYPE
2012
    PROTO_N ( ( id, s, t, def, dargs ) )
-
 
2013
    PROTO_T ( IDENTIFIER id X TYPE s X TYPE t X int def X int dargs )
2082
redecl_func_type(IDENTIFIER id, TYPE s, TYPE t, int def, int dargs)
2014
{
2083
{
2015
    TYPE fs = s ;
2084
	TYPE fs = s;
2016
    TYPE ft = t ;
2085
	TYPE ft = t;
2017
    CV_SPEC qs, qt ;
2086
	CV_SPEC qs, qt;
2018
    NAMESPACE ns, nt ;
2087
	NAMESPACE ns, nt;
2019
    unsigned tag = TAG_id ( id ) ;
2088
	unsigned tag = TAG_id(id);
2020
 
2089
 
2021
    /* Check template components */
2090
	/* Check template components */
2022
    redecl_template ( &fs, &ft, id ) ;
2091
	redecl_template(&fs, &ft, id);
2023
    ns = DEREF_nspace ( type_func_pars ( fs ) ) ;
2092
	ns = DEREF_nspace(type_func_pars(fs));
2024
    nt = DEREF_nspace ( type_func_pars ( ft ) ) ;
2093
	nt = DEREF_nspace(type_func_pars(ft));
2025
    COPY_id ( nspace_name ( ns ), id ) ;
2094
	COPY_id(nspace_name(ns), id);
2026
    COPY_id ( nspace_name ( nt ), id ) ;
2095
	COPY_id(nspace_name(nt), id);
2027
 
2096
 
2028
#if LANGUAGE_C
2097
#if LANGUAGE_C
2029
    /* Copy composite type information */
2098
	/* Copy composite type information */
2030
    if ( def ) {
2099
	if (def) {
2031
	TYPE ret = DEREF_type ( type_func_ret ( fs ) ) ;
2100
		TYPE ret = DEREF_type(type_func_ret(fs));
2032
	int ell = DEREF_int ( type_func_ellipsis ( fs ) ) ;
2101
		int ell = DEREF_int(type_func_ellipsis(fs));
2033
	LIST ( TYPE ) ptypes = DEREF_list ( type_func_ptypes ( fs ) ) ;
2102
		LIST(TYPE)ptypes = DEREF_list(type_func_ptypes(fs));
2034
	COPY_list ( type_func_ptypes ( ft ), ptypes ) ;
2103
		COPY_list(type_func_ptypes(ft), ptypes);
2035
	COPY_int ( type_func_ellipsis ( ft ), ell ) ;
2104
		COPY_int(type_func_ellipsis(ft), ell);
2036
	COPY_type ( type_func_ret ( ft ), ret ) ;
2105
		COPY_type(type_func_ret(ft), ret);
2037
    }
2106
	}
2038
#endif
2107
#endif
2039
 
2108
 
2040
    /* Check default arguments */
2109
	/* Check default arguments */
2041
    if ( dargs && redecl_func_dargs ( fs, ft ) ) {
2110
	if (dargs && redecl_func_dargs(fs, ft)) {
2042
	if ( IS_type_templ ( t ) ) {
2111
		if (IS_type_templ(t)) {
2043
	    report ( decl_loc, ERR_dcl_fct_default_templ () ) ;
2112
			report(decl_loc, ERR_dcl_fct_default_templ());
2044
	}
2113
		}
2045
    }
2114
	}
2046
 
2115
 
2047
    /* Check exception specifications */
2116
	/* Check exception specifications */
2048
    if ( eq_except ( s, t ) != 2 ) {
2117
	if (eq_except(s, t) != 2) {
2049
	PTR ( LOCATION ) loc = id_loc ( id ) ;
2118
		PTR(LOCATION)loc = id_loc(id);
2050
	report ( decl_loc, ERR_except_spec_wrong ( id, loc ) ) ;
2119
		report(decl_loc, ERR_except_spec_wrong(id, loc));
2051
    }
2120
	}
2052
 
2121
 
2053
    /* Check cv-qualifiers */
2122
	/* Check cv-qualifiers */
2054
    switch ( tag ) {
2123
	switch (tag) {
2055
	case id_mem_func_tag :
2124
	case id_mem_func_tag:
2056
	case id_stat_mem_func_tag : {
2125
	case id_stat_mem_func_tag: {
2057
	    /* Allow for member functions */
2126
		/* Allow for member functions */
2058
	    CLASS_TYPE ct = parent_class ( id ) ;
2127
		CLASS_TYPE ct = parent_class(id);
2059
	    member_func_type ( ct, tag, ft ) ;
2128
		member_func_type(ct, tag, ft);
2060
	    break ;
2129
		break;
2061
	}
2130
	}
2062
	default : {
2131
	default:
2063
	    /* Allow for function typedefs */
2132
		/* Allow for function typedefs */
2064
	    member_func_type ( NULL_ctype, tag, ft ) ;
2133
		member_func_type(NULL_ctype, tag, ft);
2065
	    break ;
2134
		break;
2066
	}
2135
	}
2067
    }
-
 
2068
 
2136
 
2069
    /* Check function qualifiers */
2137
	/* Check function qualifiers */
2070
    qs = DEREF_cv ( type_func_mqual ( fs ) ) ;
2138
	qs = DEREF_cv(type_func_mqual(fs));
2071
    qt = DEREF_cv ( type_func_mqual ( ft ) ) ;
2139
	qt = DEREF_cv(type_func_mqual(ft));
2072
    if ( qs != qt ) {
2140
	if (qs != qt) {
2073
	qs &= cv_language ;
2141
		qs &= cv_language;
2074
	qt &= cv_language ;
2142
		qt &= cv_language;
2075
	if ( qs != qt ) {
2143
		if (qs != qt) {
2076
	    /* Language specifiers don't match */
2144
			/* Language specifiers don't match */
2077
	    string ln = linkage_string ( dspec_none, qs ) ;
2145
			string ln = linkage_string(dspec_none, qs);
2078
	    report ( decl_loc, ERR_dcl_link_func ( ln ) ) ;
2146
			report(decl_loc, ERR_dcl_link_func(ln));
2079
	}
2147
		}
2080
    }
-
 
2081
 
-
 
2082
    /* Select type to continue with */
-
 
2083
    if ( def ) {
-
 
2084
	LIST ( IDENTIFIER ) sids = DEREF_list ( type_func_pids ( fs ) ) ;
-
 
2085
	LIST ( IDENTIFIER ) tids = DEREF_list ( type_func_pids ( ft ) ) ;
-
 
2086
	if ( !EQ_list ( sids, tids ) ) {
-
 
2087
	    while ( !IS_NULL_list ( sids ) && !IS_NULL_list ( tids ) ) {
-
 
2088
		/* Identify parameters */
-
 
2089
		IDENTIFIER sid = DEREF_id ( HEAD_list ( sids ) ) ;
-
 
2090
		IDENTIFIER tid = DEREF_id ( HEAD_list ( tids ) ) ;
-
 
2091
		tid = chase_alias ( tid ) ;
-
 
2092
		sid = chase_alias ( sid ) ;
-
 
2093
		COPY_id ( id_alias ( sid ), tid ) ;
-
 
2094
		tids = TAIL_list ( tids ) ;
-
 
2095
		sids = TAIL_list ( sids ) ;
-
 
2096
	    }
-
 
2097
	}
2148
	}
-
 
2149
 
-
 
2150
	/* Select type to continue with */
-
 
2151
	if (def) {
-
 
2152
		LIST(IDENTIFIER) sids = DEREF_list(type_func_pids(fs));
-
 
2153
		LIST(IDENTIFIER) tids = DEREF_list(type_func_pids(ft));
-
 
2154
		if (!EQ_list(sids, tids)) {
-
 
2155
			while (!IS_NULL_list(sids) && !IS_NULL_list(tids)) {
-
 
2156
				/* Identify parameters */
-
 
2157
				IDENTIFIER sid = DEREF_id(HEAD_list(sids));
-
 
2158
				IDENTIFIER tid = DEREF_id(HEAD_list(tids));
-
 
2159
				tid = chase_alias(tid);
-
 
2160
				sid = chase_alias(sid);
-
 
2161
				COPY_id(id_alias(sid), tid);
-
 
2162
				tids = TAIL_list(tids);
-
 
2163
				sids = TAIL_list(sids);
-
 
2164
			}
-
 
2165
		}
2098
	if ( IS_type_templ ( t ) ) {
2166
		if (IS_type_templ(t)) {
2099
	    /* Reset primary function template */
2167
			/* Reset primary function template */
2100
	    reset_primary_templ ( s, t ) ;
2168
			reset_primary_templ(s, t);
-
 
2169
		}
-
 
2170
		s = t;
2101
	}
2171
	}
2102
	s = t ;
-
 
2103
    }
-
 
2104
    return ( s ) ;
2172
	return (s);
2105
}
2173
}
2106
 
2174
 
2107
 
2175
 
2108
/*
2176
/*
2109
    FIND THE FUNCTION COMPONENT OF A TYPE
2177
    FIND THE FUNCTION COMPONENT OF A TYPE
2110
 
2178
 
2111
    This routine returns the function component of a function, pointer to
2179
    This routine returns the function component of a function, pointer to
2112
    function, or pointer to member function type.
2180
    function, or pointer to member function type.
2113
*/
2181
*/
2114
 
2182
 
2115
TYPE find_func_type
2183
TYPE
2116
    PROTO_N ( ( t ) )
-
 
2117
    PROTO_T ( TYPE t )
2184
find_func_type(TYPE t)
2118
{
2185
{
2119
    if ( !IS_NULL_type ( t ) ) {
2186
	if (!IS_NULL_type(t)) {
2120
	unsigned tag = TAG_type ( t ) ;
2187
		unsigned tag = TAG_type(t);
2121
	if ( tag == type_ref_tag ) {
2188
		if (tag == type_ref_tag) {
2122
	    t = DEREF_type ( type_ref_sub ( t ) ) ;
2189
			t = DEREF_type(type_ref_sub(t));
-
 
2190
			tag = TAG_type(t);
-
 
2191
		}
-
 
2192
		if (tag == type_ptr_tag) {
-
 
2193
			t = DEREF_type(type_ptr_sub(t));
-
 
2194
			tag = TAG_type(t);
-
 
2195
		} else if (tag == type_ptr_mem_tag) {
-
 
2196
			t = DEREF_type(type_ptr_mem_sub(t));
2123
	    tag = TAG_type ( t ) ;
2197
			tag = TAG_type(t);
-
 
2198
		}
-
 
2199
		if (tag == type_func_tag) {
-
 
2200
			return (t);
-
 
2201
		}
2124
	}
2202
	}
2125
	if ( tag == type_ptr_tag ) {
-
 
2126
	    t = DEREF_type ( type_ptr_sub ( t ) ) ;
-
 
2127
	    tag = TAG_type ( t ) ;
-
 
2128
	} else if ( tag == type_ptr_mem_tag ) {
-
 
2129
	    t = DEREF_type ( type_ptr_mem_sub ( t ) ) ;
-
 
2130
	    tag = TAG_type ( t ) ;
-
 
2131
	}
-
 
2132
	if ( tag == type_func_tag ) return ( t ) ;
-
 
2133
    }
-
 
2134
    return ( NULL_type ) ;
2203
	return (NULL_type);
2135
}
2204
}
2136
 
2205
 
2137
 
2206
 
2138
/*
2207
/*
2139
    STACK OF DECLARATOR LOCATIONS
2208
    STACK OF DECLARATOR LOCATIONS
2140
 
2209
 
2141
    The location decl_loc refers to the current declarator.  This value
2210
    The location decl_loc refers to the current declarator.  This value
2142
    needs to be stored during parameter declarations and this stack is
2211
    needs to be stored during parameter declarations and this stack is
2143
    used for this purpose.
2212
    used for this purpose.
2144
*/
2213
*/
2145
 
2214
 
2146
static STACK ( LOCATION ) decl_locs = NULL_stack ( LOCATION ) ;
2215
static STACK(LOCATION) decl_locs = NULL_stack(LOCATION);
2147
 
2216
 
2148
 
2217
 
2149
/*
2218
/*
2150
    BEGIN FUNCTION PARAMETER NAMESPACE
2219
    BEGIN FUNCTION PARAMETER NAMESPACE
2151
 
2220
 
2152
    This routine is called at the start of a list of function parameters to
2221
    This routine is called at the start of a list of function parameters to
2153
    initialise the parameter namespace.  id gives the associated function
2222
    initialise the parameter namespace.  id gives the associated function
2154
    name (or the null identifier).
2223
    name (or the null identifier).
2155
*/
2224
*/
2156
 
2225
 
2157
void begin_param
2226
void
2158
    PROTO_N ( ( id ) )
-
 
2159
    PROTO_T ( IDENTIFIER id )
2227
begin_param(IDENTIFIER id)
2160
{
-
 
2161
    NAMESPACE ns = make_namespace ( id, nspace_param_tag, 0 ) ;
-
 
2162
    push_namespace ( ns ) ;
-
 
2163
    PUSH_loc ( decl_loc, decl_locs ) ;
-
 
2164
    return ;
-
 
2165
}
-
 
2166
 
-
 
2167
 
-
 
2168
/*
-
 
2169
    END FUNCTION PARAMETER NAMESPACE
-
 
2170
 
-
 
2171
    This routine is called at the end of a list of function parameters.
-
 
2172
*/
-
 
2173
 
-
 
2174
void end_param
-
 
2175
    PROTO_Z ()
-
 
2176
{
2228
{
-
 
2229
	NAMESPACE ns = make_namespace(id, nspace_param_tag, 0);
2177
    IGNORE pop_namespace () ;
2230
	push_namespace(ns);
2178
    POP_loc ( decl_loc, decl_locs ) ;
2231
	PUSH_loc(decl_loc, decl_locs);
2179
    return ;
2232
	return;
2180
}
2233
}
2181
 
2234
 
2182
 
2235
 
2183
/*
2236
/*
2184
    ADJUST A FUNCTION PARAMETER NAMESPACE
2237
    END FUNCTION PARAMETER NAMESPACE
2185
 
2238
 
2186
    This routine adjusts the parameter namespace of the dfunction type
2239
    This routine is called at the end of a list of function parameters.
2187
    t used in a function definition.
-
 
2188
*/
2240
*/
2189
 
2241
 
2190
void adjust_param
2242
void
2191
    PROTO_N ( ( t ) )
2243
end_param(void)
2192
    PROTO_T ( TYPE t )
-
 
2193
{
2244
{
-
 
2245
	IGNORE pop_namespace();
-
 
2246
	POP_loc(decl_loc, decl_locs);
-
 
2247
	return;
-
 
2248
}
-
 
2249
 
-
 
2250
 
-
 
2251
/*
-
 
2252
    ADJUST A FUNCTION PARAMETER NAMESPACE
-
 
2253
 
-
 
2254
    This routine adjusts the parameter namespace of the dfunction type
-
 
2255
    t used in a function definition.
-
 
2256
*/
-
 
2257
 
-
 
2258
void
-
 
2259
adjust_param(TYPE t)
-
 
2260
{
2194
    NAMESPACE ns ;
2261
	NAMESPACE ns;
2195
    while ( IS_type_templ ( t ) ) {
2262
	while (IS_type_templ(t)) {
2196
	t = DEREF_type ( type_templ_defn ( t ) ) ;
2263
		t = DEREF_type(type_templ_defn(t));
2197
    }
2264
	}
2198
    ns = DEREF_nspace ( type_func_pars ( t ) ) ;
2265
	ns = DEREF_nspace(type_func_pars(t));
2199
    MODIFY_nspace_block_etc ( nspace_block_tag, ns ) ;
2266
	MODIFY_nspace_block_etc(nspace_block_tag, ns);
2200
    report ( crt_loc, ERR_dcl_fct_typedef () ) ;
2267
	report(crt_loc, ERR_dcl_fct_typedef());
2201
    return ;
2268
	return;
2202
}
2269
}
2203
 
2270
 
2204
 
2271
 
2205
/*
2272
/*
2206
    READ A LIST OF NON-PROTOTYPE FUNCTION PARAMETERS
2273
    READ A LIST OF NON-PROTOTYPE FUNCTION PARAMETERS
2207
 
2274
 
2208
    This routine reads a list of function parameters, returning true for
2275
    This routine reads a list of function parameters, returning true for
2209
    a function definition.
2276
    a function definition.
2210
*/
2277
*/
2211
 
2278
 
2212
int function_params
2279
int
2213
    PROTO_N ( ( t ) )
-
 
2214
    PROTO_T ( TYPE t )
2280
function_params(TYPE t)
2215
{
2281
{
2216
    int def = 0 ;
2282
	int def = 0;
2217
    if ( IS_type_func ( t ) ) {
2283
	if (IS_type_func(t)) {
2218
	int func = have_func_declarator ;
2284
		int func = have_func_declarator;
2219
	int ell = DEREF_int ( type_func_ellipsis ( t ) ) ;
2285
		int ell = DEREF_int(type_func_ellipsis(t));
2220
	NAMESPACE ns = DEREF_nspace ( type_func_pars ( t ) ) ;
2286
		NAMESPACE ns = DEREF_nspace(type_func_pars(t));
2221
	in_weak_param++ ;
2287
		in_weak_param++;
2222
	push_namespace ( ns ) ;
2288
		push_namespace(ns);
2223
	while ( predict_dspec ( 0 ) ) {
2289
		while (predict_dspec(0)) {
2224
	    if ( !func ) {
2290
			if (!func) {
2225
		adjust_param ( t ) ;
2291
				adjust_param(t);
2226
		func = 1 ;
2292
				func = 1;
2227
	    }
2293
			}
2228
	    if ( ell != FUNC_NO_PARAMS && ell != FUNC_PARAMS ) {
2294
			if (ell != FUNC_NO_PARAMS && ell != FUNC_PARAMS) {
2229
		/* Can't have parameters with prototype */
2295
				/* Can't have parameters with prototype */
2230
		report ( crt_loc, ERR_dcl_fct_par_proto () ) ;
2296
				report(crt_loc, ERR_dcl_fct_par_proto());
2231
		ell = FUNC_PARAMS ;
2297
				ell = FUNC_PARAMS;
2232
	    }
2298
			}
2233
	    parse_decl ( NULL_type, dspec_none ) ;
2299
			parse_decl(NULL_type, dspec_none);
2234
	    def = 1 ;
2300
			def = 1;
2235
	}
2301
		}
2236
	if ( predict_func_defn () ) {
2302
		if (predict_func_defn()) {
2237
	    if ( !func ) adjust_param ( t ) ;
2303
			if (!func)adjust_param(t);
2238
	    def = 1 ;
2304
			def = 1;
-
 
2305
		}
-
 
2306
		check_weak_func(t, def);
-
 
2307
		IGNORE pop_namespace();
-
 
2308
		in_weak_param--;
2239
	}
2309
	}
2240
	check_weak_func ( t, def ) ;
-
 
2241
	IGNORE pop_namespace () ;
-
 
2242
	in_weak_param-- ;
-
 
2243
    }
-
 
2244
    return ( def ) ;
2310
	return (def);
2245
}
2311
}
2246
 
2312
 
2247
 
2313
 
2248
/*
2314
/*
2249
    MAIN FUNCTION
2315
    MAIN FUNCTION
2250
 
2316
 
2251
    This variable is used to hold the main function.
2317
    This variable is used to hold the main function.
2252
*/
2318
*/
2253
 
2319
 
2254
IDENTIFIER main_function = NULL_id ;
2320
IDENTIFIER main_function = NULL_id;
2255
 
2321
 
2256
 
2322
 
2257
/*
2323
/*
2258
    CHECK THE TYPE OF THE MAIN FUNCTION
2324
    CHECK THE TYPE OF THE MAIN FUNCTION
2259
 
2325
 
Line 2265... Line 2331...
2265
	    int main ( int, char **, [extra parameters] ) ;
2331
	    int main ( int, char **, [extra parameters] ) ;
2266
 
2332
 
2267
    is deemed to be unorthodox.
2333
    is deemed to be unorthodox.
2268
*/
2334
*/
2269
 
2335
 
2270
TYPE check_main
2336
TYPE
2271
    PROTO_N ( ( t, nm ) )
-
 
2272
    PROTO_T ( TYPE t X HASHID nm )
2337
check_main(TYPE t, HASHID nm)
2273
{
2338
{
2274
    int ok = 0 ;
2339
    int ok = 0;
2275
    if ( IS_type_func ( t ) ) {
2340
    if (IS_type_func(t)) {
2276
	TYPE r = DEREF_type ( type_func_ret ( t ) ) ;
2341
	TYPE r = DEREF_type(type_func_ret(t));
2277
	LIST ( TYPE ) p = DEREF_list ( type_func_ptypes ( t ) ) ;
2342
	LIST(TYPE) p = DEREF_list(type_func_ptypes(t));
2278
	int ell = DEREF_int ( type_func_ellipsis ( t ) ) ;
2343
	int ell = DEREF_int(type_func_ellipsis(t));
2279
	if ( !eq_type_unqual ( r, type_sint ) ) {
2344
	if (!eq_type_unqual(r, type_sint)) {
2280
	    /* Return type is wrong */
2345
	    /* Return type is wrong */
2281
	    ERROR err = ERR_basic_start_main_ret ( r, nm ) ;
2346
	    ERROR err = ERR_basic_start_main_ret(r, nm);
2282
	    report ( crt_loc, err ) ;
2347
	    report(crt_loc, err);
2283
	}
2348
	}
2284
	if ( IS_NULL_list ( p ) ) {
2349
	if (IS_NULL_list(p)) {
2285
	    /* Check for no parameter case */
2350
	    /* Check for no parameter case */
2286
	    if ( !( ell & FUNC_ELLIPSIS ) ) ok = 2 ;
2351
	    if (!(ell & FUNC_ELLIPSIS)) {
-
 
2352
		    ok = 2;
-
 
2353
	    }
2287
	} else {
2354
	} else {
2288
	    /* Check for two parameter case */
2355
	    /* Check for two parameter case */
2289
	    TYPE s = DEREF_type ( HEAD_list ( p ) ) ;
2356
	    TYPE s = DEREF_type(HEAD_list(p));
2290
	    if ( eq_type_unqual ( s, type_sint ) ) {
2357
	    if (eq_type_unqual(s, type_sint)) {
2291
		p = TAIL_list ( p ) ;
2358
		p = TAIL_list(p);
2292
		if ( !IS_NULL_list ( p ) ) {
2359
		if (!IS_NULL_list(p)) {
2293
		    s = DEREF_type ( HEAD_list ( p ) ) ;
2360
		    s = DEREF_type(HEAD_list(p));
2294
		    if ( IS_type_ptr ( s ) ) {
2361
		    if (IS_type_ptr(s)) {
2295
			s = DEREF_type ( type_ptr_sub ( s ) ) ;
2362
			s = DEREF_type(type_ptr_sub(s));
2296
			if ( IS_type_ptr ( s ) ) {
2363
			if (IS_type_ptr(s)) {
2297
			    s = DEREF_type ( type_ptr_sub ( s ) ) ;
2364
			    s = DEREF_type(type_ptr_sub(s));
2298
			    if ( eq_type_unqual ( s, type_char ) ) {
2365
			    if (eq_type_unqual(s, type_char)) {
2299
				p = TAIL_list ( p ) ;
2366
				p = TAIL_list(p);
2300
				if ( IS_NULL_list ( p ) ) {
2367
				if (IS_NULL_list(p)) {
2301
				    if ( !( ell & FUNC_ELLIPSIS ) ) {
2368
				    if (!(ell & FUNC_ELLIPSIS)) {
2302
					ok = 2 ;
2369
					ok = 2;
2303
				    } else {
2370
				    } else {
2304
					ok = 1 ;
2371
					ok = 1;
2305
				    }
2372
				    }
2306
				} else {
2373
				} else {
2307
				    ok = 1 ;
2374
				    ok = 1;
2308
				}
2375
				}
2309
			    }
2376
			    }
2310
			}
2377
			}
2311
		    }
2378
		    }
2312
		}
2379
		}
2313
	    }
2380
	    }
2314
	}
2381
	}
2315
    }
2382
    }
2316
    if ( !ok ) {
2383
    if (!ok) {
2317
	/* Warn about unorthodox parameter types */
2384
	/* Warn about unorthodox parameter types */
2318
	ERROR err = ERR_basic_start_main_proto ( t, nm ) ;
2385
	ERROR err = ERR_basic_start_main_proto(t, nm);
2319
	report ( crt_loc, err ) ;
2386
	report(crt_loc, err);
2320
    }
2387
    }
2321
    return ( t ) ;
2388
    return (t);
2322
}
2389
}
2323
 
2390
 
2324
 
2391
 
2325
/*
2392
/*
2326
    RECHECK THE MAIN FUNCTION
2393
    RECHECK THE MAIN FUNCTION
2327
 
2394
 
2328
    This routine rechecks the main function id.  In particular 'main' can't
2395
    This routine rechecks the main function id.  In particular 'main' can't
2329
    be overloaded.
2396
    be overloaded.
2330
*/
2397
*/
2331
 
2398
 
2332
void recheck_main
2399
void
2333
    PROTO_N ( ( id ) )
-
 
2334
    PROTO_T ( IDENTIFIER id )
2400
recheck_main(IDENTIFIER id)
2335
{
2401
{
2336
    TYPE fn = DEREF_type ( id_function_etc_type ( id ) ) ;
2402
	TYPE fn = DEREF_type(id_function_etc_type(id));
2337
    IDENTIFIER over = DEREF_id ( id_function_etc_over ( id ) ) ;
2403
	IDENTIFIER over = DEREF_id(id_function_etc_over(id));
2338
    if ( !IS_NULL_id ( over ) || IS_type_templ ( fn ) ) {
2404
	if (!IS_NULL_id(over) || IS_type_templ(fn)) {
2339
	/* Can't overload 'main' */
2405
		/* Can't overload 'main' */
2340
	report ( decl_loc, ERR_basic_start_main_over ( id ) ) ;
2406
		report(decl_loc, ERR_basic_start_main_over(id));
2341
    }
2407
	}
2342
    main_function = id ;
2408
	main_function = id;
2343
    return ;
2409
	return;
2344
}
2410
}
2345
 
2411
 
2346
 
2412
 
2347
/*
2413
/*
2348
    CURRENT FUNCTION INFORMATION
2414
    CURRENT FUNCTION INFORMATION
2349
 
2415
 
2350
    These variables are used to hold information concerning the current
2416
    These variables are used to hold information concerning the current
2351
    function, including its name, return type and exception specification.
2417
    function, including its name, return type and exception specification.
2352
*/
2418
*/
2353
 
2419
 
2354
IDENTIFIER crt_func_id = NULL_id ;
2420
IDENTIFIER crt_func_id = NULL_id;
2355
TYPE crt_func_return = NULL_type ;
2421
TYPE crt_func_return = NULL_type;
2356
int crt_func_complex = 0 ;
2422
int crt_func_complex = 0;
2357
 
2423
 
2358
 
2424
 
2359
/*
2425
/*
2360
    NESTED FUNCTION STACK
2426
    NESTED FUNCTION STACK
2361
 
2427
 
Line 2364... Line 2430...
2364
    a member function definition).  These stacks are used to preserve
2430
    a member function definition).  These stacks are used to preserve
2365
    information across nested functions.
2431
    information across nested functions.
2366
*/
2432
*/
2367
 
2433
 
2368
static struct {
2434
static struct {
2369
    STACK ( IDENTIFIER ) id ;
2435
	STACK(IDENTIFIER)id;
2370
    STACK ( TYPE ) ret ;
2436
	STACK(TYPE)ret;
2371
    STACK ( int ) unreached ;
2437
	STACK(int)unreached;
2372
    STACK ( int ) declaration ;
2438
	STACK(int)declaration;
2373
    STACK ( int ) destructor ;
2439
	STACK(int)destructor;
2374
    STACK ( int ) handler ;
2440
	STACK(int)handler;
2375
    STACK ( STACK ( EXP ) ) loops ;
2441
	STACK(STACK(EXP))loops;
2376
    STACK ( NAMESPACE ) labels ;
2442
	STACK(NAMESPACE)labels;
2377
    STACK ( LIST ( EXP ) ) solves ;
2443
	STACK(LIST(EXP))solves;
2378
    STACK ( LIST ( EXP ) ) tries ;
2444
	STACK(LIST(EXP))tries;
2379
    STACK ( unsigned long ) opts ;
2445
	STACK(unsigned long)opts;
2380
} func_stack = {
2446
} func_stack = {
2381
    NULL_stack ( IDENTIFIER ),
2447
	NULL_stack(IDENTIFIER),
2382
    NULL_stack ( TYPE ),
2448
	NULL_stack(TYPE),
2383
    NULL_stack ( int ),
2449
	NULL_stack(int),
2384
    NULL_stack ( int ),
2450
	NULL_stack(int),
2385
    NULL_stack ( int ),
2451
	NULL_stack(int),
2386
    NULL_stack ( int ),
2452
	NULL_stack(int),
2387
    NULL_stack ( STACK ( EXP ) ),
2453
	NULL_stack(STACK(EXP)),
2388
    NULL_stack ( NAMESPACE ),
2454
	NULL_stack(NAMESPACE),
2389
    NULL_stack ( LIST ( EXP ) ),
2455
	NULL_stack(LIST(EXP)),
2390
    NULL_stack ( LIST ( EXP ) ),
2456
	NULL_stack(LIST(EXP)),
2391
    NULL_stack ( unsigned long )
2457
	NULL_stack(unsigned long)
2392
} ;
2458
};
2393
 
2459
 
2394
 
2460
 
2395
/*
2461
/*
2396
    BEGIN A FUNCTION DEFINITION
2462
    BEGIN A FUNCTION DEFINITION
2397
 
2463
 
2398
    This routine is called at the start of a function definition.  t gives
2464
    This routine is called at the start of a function definition.  t gives
2399
    the function type.
2465
    the function type.
2400
*/
2466
*/
2401
 
2467
 
2402
void begin_function
2468
void
2403
    PROTO_N ( ( id ) )
-
 
2404
    PROTO_T ( IDENTIFIER id )
2469
begin_function(IDENTIFIER id)
2405
{
2470
{
2406
    TYPE t ;
2471
	TYPE t;
2407
    int ell ;
2472
	int ell;
2408
    TYPE ret ;
2473
	TYPE ret;
2409
    NAMESPACE ns ;
2474
	NAMESPACE ns;
2410
    NAMESPACE bns ;
2475
	NAMESPACE bns;
2411
    unsigned long n ;
2476
	unsigned long n;
2412
    LIST ( TYPE ) ex ;
2477
	LIST(TYPE) ex;
2413
    ERROR err = NULL_err ;
2478
	ERROR err = NULL_err;
2414
    LIST ( IDENTIFIER ) p ;
2479
	LIST(IDENTIFIER) p;
2415
    unsigned long npars = 0 ;
2480
	unsigned long npars = 0;
2416
 
2481
 
2417
    /* Check for previous definition */
2482
	/* Check for previous definition */
2418
    if ( IS_id_function_etc ( id ) ) {
2483
	if (IS_id_function_etc(id)) {
2419
	EXP e = DEREF_exp ( id_function_etc_defn ( id ) ) ;
2484
		EXP e = DEREF_exp(id_function_etc_defn(id));
2420
	DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
2485
		DECL_SPEC ds = DEREF_dspec(id_storage(id));
2421
	t = DEREF_type ( id_function_etc_type ( id ) ) ;
2486
		t = DEREF_type(id_function_etc_type(id));
2422
	if ( IS_NULL_exp ( e ) ) {
2487
		if (IS_NULL_exp(e)) {
2423
	    /* Mark with dummy definition */
2488
			/* Mark with dummy definition */
2424
	    MAKE_exp_value ( t, e ) ;
2489
			MAKE_exp_value(t, e);
2425
	    COPY_exp ( id_function_etc_defn ( id ), e ) ;
2490
			COPY_exp(id_function_etc_defn(id), e);
-
 
2491
		} else {
-
 
2492
			/* Already defined */
-
 
2493
			PTR(LOCATION) loc = id_loc(id);
-
 
2494
			report(decl_loc, ERR_basic_odr_def_func(id, loc));
-
 
2495
		}
-
 
2496
		if ((ds & dspec_inline) && (ds & dspec_called)) {
-
 
2497
			report(decl_loc, ERR_dcl_fct_spec_inline_call(id));
-
 
2498
		}
2426
	} else {
2499
	} else {
2567
 
2637
 
2568
    /* Deal with the ellipsis parameter */
2638
	/* Deal with the ellipsis parameter */
2569
    if ( ell & FUNC_ELLIPSIS ) make_ellipsis_decl () ;
2639
	if (ell & FUNC_ELLIPSIS) {
-
 
2640
		make_ellipsis_decl();
-
 
2641
	}
2570
 
2642
 
2571
    /* Create dummy try block */
2643
	/* Create dummy try block */
2572
    start_try_check ( ex ) ;
2644
	start_try_check(ex);
2573
    return ;
2645
	return;
2574
}
2646
}
2575
 
2647
 
2576
 
2648
 
2577
/*
2649
/*
2578
    END A FUNCTION DEFINITION
2650
    END A FUNCTION DEFINITION
Line 2581... Line 2653...
2581
    expression body gives the compound statement comprising the definition.
2653
    expression body gives the compound statement comprising the definition.
2582
    Note that the parameters are in the outermost scope of body and so
2654
    Note that the parameters are in the outermost scope of body and so
2583
    have already been taken out of scope.
2655
    have already been taken out of scope.
2584
*/
2656
*/
2585
 
2657
 
2586
EXP end_function
2658
EXP
2587
    PROTO_N ( ( id, body ) )
-
 
2588
    PROTO_T ( IDENTIFIER id X EXP body )
2659
end_function(IDENTIFIER id, EXP body)
2589
{
2660
{
2590
    /* Check for errors in function */
2661
	/* Check for errors in function */
2591
    TYPE ret ;
2662
	TYPE ret;
2592
    int flow = 0 ;
2663
	int flow = 0;
2593
    unsigned long n ;
2664
	unsigned long n;
2594
    POP_ulong ( n, func_stack.opts ) ;
2665
	POP_ulong(n, func_stack.opts);
2595
    if ( option ( OPT_variable ) ) {
2666
	if (option(OPT_variable)) {
2596
	if ( n == number_errors ) flow = 1 ;
2667
		if (n == number_errors) {
-
 
2668
			flow = 1;
-
 
2669
		}
2597
	record_location-- ;
2670
		record_location--;
2598
    }
2671
	}
2599
 
2672
 
2600
    /* Check function body */
2673
	/* Check function body */
2601
    if ( !IS_NULL_exp ( body ) ) {
2674
	if (!IS_NULL_exp(body)) {
2602
	if ( !unreached_code ) {
2675
		if (!unreached_code) {
2603
	    /* Check for falling out of function */
2676
			/* Check for falling out of function */
2604
	    EXP e = fall_return_stmt () ;
2677
			EXP e = fall_return_stmt();
2605
	    body = add_compound_stmt ( body, e ) ;
2678
			body = add_compound_stmt(body, e);
2606
	}
2679
		}
2607
	unreached_code = 0 ;
2680
		unreached_code = 0;
2608
	set_parent_stmt ( body, NULL_exp ) ;
2681
		set_parent_stmt(body, NULL_exp);
2609
	if ( IS_exp_solve_stmt ( body ) ) {
2682
		if (IS_exp_solve_stmt(body)) {
2610
	    /* Analyse enclosing solve statement */
2683
			/* Analyse enclosing solve statement */
2611
	    body = solve_labels ( body ) ;
2684
			body = solve_labels(body);
2612
	} else if ( check_labels () ) {
2685
		} else if (check_labels()) {
2613
	    /* Construct enclosing solve statement */
2686
			/* Construct enclosing solve statement */
2614
	    EXP a ;
2687
			EXP a;
2615
	    MAKE_exp_solve_stmt ( type_void, body, a ) ;
2688
			MAKE_exp_solve_stmt(type_void, body, a);
2616
	    CONS_exp ( a, all_solve_stmts, all_solve_stmts ) ;
2689
			CONS_exp(a, all_solve_stmts, all_solve_stmts);
2617
	    set_parent_stmt ( body, a ) ;
2690
			set_parent_stmt(body, a);
2618
	    body = solve_labels ( a ) ;
2691
			body = solve_labels(a);
2619
	}
2692
		}
2620
	end_solve_stmts () ;
2693
		end_solve_stmts();
2621
#if LANGUAGE_CPP
2694
#if LANGUAGE_CPP
2622
	if ( !IS_NULL_list ( all_try_blocks ) ) {
2695
		if (!IS_NULL_list(all_try_blocks)) {
2623
	    /* Check all try blocks */
2696
			/* Check all try blocks */
2624
	    end_try_blocks ( id ) ;
2697
			end_try_blocks(id);
2625
	}
2698
		}
2626
#endif
2699
#endif
2627
	body = end_try_check ( id, body ) ;
2700
		body = end_try_check(id, body);
2628
	if ( flow || ( have_destructor && do_usage ) ) {
2701
		if (flow || (have_destructor && do_usage)) {
2629
	    /* Variable flow analysis */
2702
			/* Variable flow analysis */
2630
	    check_flow ( id, body, flow ) ;
2703
			check_flow(id, body, flow);
-
 
2704
		}
2631
	}
2705
	}
2632
    }
-
 
2633
 
2706
 
2634
    /* Define the function */
2707
	/* Define the function */
2635
    if ( IS_id_function_etc ( id ) ) {
2708
	if (IS_id_function_etc(id)) {
2636
	COPY_exp ( id_function_etc_defn ( id ), body ) ;
2709
		COPY_exp(id_function_etc_defn(id), body);
2637
	define_id ( id ) ;
2710
		define_id(id);
2638
	if ( !in_template_decl ) {
2711
		if (!in_template_decl) {
2639
	    compile_function ( id, 0 ) ;
2712
			compile_function(id, 0);
2640
	    free_nspace ( label_namespace ) ;
2713
			free_nspace(label_namespace);
-
 
2714
		}
-
 
2715
		if (do_dump) {
-
 
2716
			dump_undefine(id, &crt_loc, 0);
-
 
2717
		}
2641
	}
2718
	}
2642
	if ( do_dump ) dump_undefine ( id, &crt_loc, 0 ) ;
-
 
2643
    }
-
 
2644
 
2719
 
2645
    /* Restore old function data */
2720
	/* Restore old function data */
2646
    POP_id ( crt_func_id, func_stack.id ) ;
2721
	POP_id(crt_func_id, func_stack.id);
2647
    POP_type ( ret, func_stack.ret ) ;
2722
	POP_type(ret, func_stack.ret);
2648
    POP_int ( unreached_code, func_stack.unreached ) ;
2723
	POP_int(unreached_code, func_stack.unreached);
2649
    POP_int ( in_declaration, func_stack.declaration ) ;
2724
	POP_int(in_declaration, func_stack.declaration);
2650
    POP_int ( have_destructor, func_stack.destructor ) ;
2725
	POP_int(have_destructor, func_stack.destructor);
2651
    POP_int ( in_func_handler, func_stack.handler ) ;
2726
	POP_int(in_func_handler, func_stack.handler);
2652
    POP_stack ( crt_loop_stack, func_stack.loops ) ;
2727
	POP_stack(crt_loop_stack, func_stack.loops);
2653
    POP_nspace ( label_namespace, func_stack.labels ) ;
2728
	POP_nspace(label_namespace, func_stack.labels);
2654
    POP_list ( all_solve_stmts, func_stack.solves ) ;
2729
	POP_list(all_solve_stmts, func_stack.solves);
2655
    POP_list ( all_try_blocks, func_stack.tries ) ;
2730
	POP_list(all_try_blocks, func_stack.tries);
2656
    POP_ulong ( n, func_stack.opts ) ;
2731
	POP_ulong(n, func_stack.opts);
2657
    crt_option_value ( OPT_VAL_nested_class ) = n ;
2732
	crt_option_value(OPT_VAL_nested_class) = n;
2658
    POP_ulong ( n, func_stack.opts ) ;
2733
	POP_ulong(n, func_stack.opts);
2659
    crt_option_value ( OPT_VAL_statement_depth ) = n ;
2734
	crt_option_value(OPT_VAL_statement_depth) = n;
2660
    crt_func_complex = pass_complex_type ( ret ) ;
2735
	crt_func_complex = pass_complex_type(ret);
2661
    crt_func_return = ret ;
2736
	crt_func_return = ret;
2662
    block_namespace = NULL_nspace ;
2737
	block_namespace = NULL_nspace;
2663
    suppress_variable = 0 ;
2738
	suppress_variable = 0;
2664
    unreached_last = 0 ;
2739
	unreached_last = 0;
2665
    return ( body ) ;
2740
	return (body);
2666
}
2741
}