Subversion Repositories tendra.SVN

Rev

Rev 5 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
6 7u83 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
 */
31
/*
2 7u83 32
    		 Crown Copyright (c) 1997, 1998
6 7u83 33
 
2 7u83 34
    This TenDRA(r) Computer Program is subject to Copyright
35
    owned by the United Kingdom Secretary of State for Defence
36
    acting through the Defence Evaluation and Research Agency
37
    (DERA).  It is made available to Recipients with a
38
    royalty-free licence for its use, reproduction, transfer
39
    to other parties and amendment for any purpose not excluding
40
    product development provided that any such use et cetera
41
    shall be deemed to be acceptance of the following conditions:-
6 7u83 42
 
2 7u83 43
        (1) Its Recipients shall ensure that this Notice is
44
        reproduced upon any copies or amended versions of it;
6 7u83 45
 
2 7u83 46
        (2) Any amended version of it shall be clearly marked to
47
        show both the nature of and the organisation responsible
48
        for the relevant amendment or amendments;
6 7u83 49
 
2 7u83 50
        (3) Its onward transfer from a recipient to another
51
        party shall be deemed to be that party's acceptance of
52
        these conditions;
6 7u83 53
 
2 7u83 54
        (4) DERA gives no warranty or assurance as to its
55
        quality or suitability for any purpose and DERA accepts
56
        no liability whatsoever in relation to any use to which
57
        it may be put.
58
*/
59
 
60
 
61
#include "config.h"
62
#include "c_types.h"
63
#include "ctype_ops.h"
64
#include "exp_ops.h"
65
#include "id_ops.h"
66
#include "hashid_ops.h"
67
#include "member_ops.h"
68
#include "nspace_ops.h"
69
#include "tok_ops.h"
70
#include "type_ops.h"
71
#include "error.h"
72
#include "catalog.h"
73
#include "access.h"
74
#include "basetype.h"
75
#include "class.h"
76
#include "constant.h"
77
#include "construct.h"
78
#include "convert.h"
79
#include "declare.h"
80
#include "derive.h"
81
#include "dump.h"
82
#include "exception.h"
83
#include "expression.h"
84
#include "file.h"
85
#include "function.h"
86
#include "hash.h"
87
#include "identifier.h"
88
#include "initialise.h"
89
#include "instance.h"
90
#include "namespace.h"
91
#include "option.h"
92
#include "parse.h"
93
#include "predict.h"
94
#include "redeclare.h"
95
#include "syntax.h"
96
#include "template.h"
97
#include "tok.h"
98
#include "token.h"
99
 
100
 
101
/*
102
    USAGE SUPPRESSION FLAG
103
 
104
    This flag may be set to true to indicate that the parser is in a sizeof
105
    expression or similar so that any usages should not be included.
106
*/
107
 
6 7u83 108
int suppress_usage = 0;
2 7u83 109
 
110
 
111
/*
112
    MARK AN IDENTIFIER AS BEING USED
113
 
114
    This routine marks the identifier id as having been used and checks
115
    any access controls.
116
*/
117
 
6 7u83 118
void
119
use_id(IDENTIFIER id, int suppress)
2 7u83 120
{
6 7u83 121
	DECL_SPEC ds = DEREF_dspec(id_storage(id));
122
	DECL_SPEC acc = (ds & dspec_access);
123
	if (acc)check_access(id, acc);
2 7u83 124
 
6 7u83 125
	/* Check usage */
126
	if (ds & dspec_main) {
127
		HASHID nm = DEREF_hashid(id_name(id));
128
		switch (TAG_hashid(nm)) {
129
		case hashid_name_tag:
130
			/* Can't take the address of 'main' */
131
			report(crt_loc, ERR_basic_start_main_addr(id));
132
			break;
133
		case hashid_constr_tag:
134
			/* Can't take the address of a constructor */
135
			report(crt_loc, ERR_class_ctor_addr(id));
136
			break;
137
		case hashid_destr_tag:
138
			/* Can't take the address of a destructor */
139
			report(crt_loc, ERR_class_dtor_addr(id));
140
			break;
141
		}
2 7u83 142
	}
143
 
6 7u83 144
	/* Mark use */
145
	if (!(ds & dspec_used)) {
146
		if (!suppress) {
147
			ds |= dspec_used;
148
			COPY_dspec(id_storage(id), ds);
2 7u83 149
		}
6 7u83 150
		if (ds & (dspec_inherit | dspec_alias | dspec_extern)) {
151
			/* Check for inheritance */
152
			IDENTIFIER uid = DEREF_id(id_alias(id));
153
			if (!EQ_id(uid, id)) {
154
				ds = DEREF_dspec(id_storage(uid));
155
				if (ds & dspec_used) {
156
					if (do_usage) {
157
						dump_use(id, &crt_loc, 1);
158
					}
159
					return;
160
				}
161
				if (!suppress) {
162
					ds |= dspec_used;
163
					COPY_dspec(id_storage(uid), ds);
164
				}
165
			}
2 7u83 166
		}
6 7u83 167
		if (!(ds & dspec_defn) && (ds & dspec_instance)) {
168
			/* Define template instance */
169
			if (!suppress) {
170
				define_template(id, 0);
171
			}
172
		}
2 7u83 173
	}
6 7u83 174
	if (do_usage) {
175
		dump_use(id, &crt_loc, 1);
2 7u83 176
	}
6 7u83 177
	return;
2 7u83 178
}
179
 
180
 
181
/*
182
    MARK A FUNCTION IDENTIFIER AS BEING USED
183
 
184
    This routine marks the function identifier id as having been called
185
    and checks any access controls.  In addition certain checks are applied
186
    to the first call of an identifier.  expl is true for explicit calls.
187
*/
188
 
6 7u83 189
void
190
use_func_id(IDENTIFIER id, int expl, int suppress)
2 7u83 191
{
6 7u83 192
	DECL_SPEC ds = DEREF_dspec(id_storage(id));
193
	DECL_SPEC acc = (ds & dspec_access);
194
	if (acc) {
195
		check_access(id, acc);
2 7u83 196
	}
6 7u83 197
	if (!(ds & dspec_called)) {
198
		/* Mark use */
199
		if (!suppress) {
200
			if (!(ds & dspec_virtual)) {
201
				ds |= dspec_used;
202
			}
203
			ds |= dspec_called;
204
			COPY_dspec(id_storage(id), ds);
205
		}
2 7u83 206
 
6 7u83 207
		/* Check for inheritance */
208
		if (ds & (dspec_inherit | dspec_alias | dspec_extern)) {
209
			IDENTIFIER uid = DEREF_id(id_alias(id));
210
			if (!EQ_id(uid, id)) {
211
				ds = DEREF_dspec(id_storage(uid));
212
				if (ds & dspec_called) {
213
					if (do_usage) {
214
						dump_call(id, &crt_loc, expl);
215
					}
216
					return;
217
				}
218
				if (!suppress) {
219
					if (!(ds & dspec_virtual)) {
220
						ds |= dspec_used;
221
					}
222
					ds |= dspec_called;
223
					COPY_dspec(id_storage(uid), ds);
224
				}
225
			}
2 7u83 226
		}
6 7u83 227
 
228
		/* Check usage */
229
		if (ds & dspec_main) {
230
			HASHID nm = DEREF_hashid(id_name(id));
231
			if (IS_hashid_name(nm)) {
232
				/* Can't call 'main' */
233
				report(crt_loc, ERR_basic_start_main_call(id));
234
			}
2 7u83 235
		}
6 7u83 236
		if (!(ds & dspec_defn) && !suppress) {
237
			if (ds & dspec_implicit) {
238
				/* Define implicitly declared function */
239
				implicit_defn(id, DEFAULT_USR);
240
				ds = DEREF_dspec(id_storage(id));
241
			} else if (ds & dspec_instance) {
242
				/* Define template function */
243
				if (!(ds & dspec_virtual)) {
244
					define_template(id, 0);
245
					ds = DEREF_dspec(id_storage(id));
246
				}
247
			}
248
			if ((ds & dspec_inline) && !(ds & dspec_defn)) {
249
				/* An inline function called before it is
250
				 * defined */
251
				report(crt_loc,
252
				       ERR_dcl_fct_spec_inline_call(id));
253
			}
254
		}
2 7u83 255
	}
6 7u83 256
	if (do_usage) {
257
		dump_call(id, &crt_loc, expl);
2 7u83 258
	}
6 7u83 259
	return;
2 7u83 260
}
261
 
262
 
263
/*
264
    MARK A VIRTUAL FUNCTION AS BEING USED
265
 
266
    Note that use_func_id does not mark virtual functions as having been
267
    used because the actual function called can only be determined at
268
    run-time.  If subsequently it is found that the function called can
269
    be determined statically then this routine is called to mark that
270
    function as having been used.  It is also used in certain similar
271
    situations.
272
*/
273
 
6 7u83 274
void
275
reuse_id(IDENTIFIER id, int suppress)
2 7u83 276
{
6 7u83 277
	DECL_SPEC ds = DEREF_dspec(id_storage(id));
278
	if (!(ds & dspec_used) && !suppress) {
279
		ds |= dspec_used;
280
		COPY_dspec(id_storage(id), ds);
281
		if (!(ds & dspec_defn)) {
282
			if (ds & dspec_implicit) {
283
				/* Define implicitly declared function */
284
				implicit_defn(id, DEFAULT_USR);
285
			} else if (ds & dspec_instance) {
286
				/* Instantiate template functions */
287
				define_template(id, 0);
288
			}
289
		}
2 7u83 290
	}
6 7u83 291
	return;
2 7u83 292
}
293
 
294
 
295
/*
296
    DEFINE AN IDENTIFIER ALIAS
297
 
298
    This routine is called if the function or variable id is defined
299
    (excluding tentative definitions).  It passes the definition on to
300
    any alias of id.
301
*/
302
 
6 7u83 303
void
304
define_id(IDENTIFIER id)
2 7u83 305
{
6 7u83 306
	IDENTIFIER lid = DEREF_id(id_alias(id));
307
	if (!EQ_id(lid, id)) {
308
		/* Check for previous definition */
309
		LOCATION loc;
310
		DECL_SPEC ds;
311
		DEREF_loc(id_loc(id), loc);
312
		ds = DEREF_dspec(id_storage(lid));
313
		if (ds & dspec_defn) {
314
			EXP e = DEREF_exp(id_variable_etc_init(lid));
315
			if (IS_NULL_exp(e) || !IS_exp_zero(e)) {
316
				/* Exclude previous tentative definitions */
317
				PTR(LOCATION)ploc = id_loc(lid);
318
				ERROR err = ERR_basic_odr_def(lid, ploc);
319
				if (ds & dspec_c) {
320
					/* Explain C linkage identifications */
321
					HASHID nm = DEREF_hashid(id_name(lid));
322
					ERROR err2 =
323
					    ERR_dcl_link_redecl(nm, ploc);
324
					err = concat_error(err, err2);
325
				}
326
				report(loc, err);
327
			}
2 7u83 328
		}
329
 
6 7u83 330
		/* Copy definition */
331
		if (IS_id_function_etc(id)) {
332
			EXP e = DEREF_exp(id_function_etc_defn(id));
333
			COPY_exp(id_function_etc_defn(lid), e);
334
		} else if (IS_id_variable_etc(id)) {
335
			TYPE t = DEREF_type(id_variable_etc_type(id));
336
			EXP e = DEREF_exp(id_variable_etc_init(id));
337
			EXP d = DEREF_exp(id_variable_etc_term(id));
338
			COPY_exp(id_variable_etc_init(lid), e);
339
			COPY_exp(id_variable_etc_term(lid), d);
340
			COPY_type(id_variable_etc_type(lid), t);
341
		}
342
 
343
		/* Record definition */
344
		ds |= dspec_defn;
345
		COPY_dspec(id_storage(lid), ds);
346
		DEREF_loc(id_loc(lid), loc);
2 7u83 347
	}
6 7u83 348
	return;
2 7u83 349
}
350
 
351
 
352
/*
353
    FIND THE END OF A LIST OF IDENTIFIER ALIASES
354
 
355
    In most cases the alias of an identifier is its underlying meaning,
356
    however for function parameters it is possible to have vast lists
357
    of identifiers arising from redeclarations all linked by their alias
358
    field.  This routine scans down such a list until it finds an identifier
359
    which is its own alias.
360
*/
361
 
6 7u83 362
IDENTIFIER
363
chase_alias(IDENTIFIER id)
2 7u83 364
{
6 7u83 365
	while (!IS_NULL_id(id)) {
366
		IDENTIFIER lid = DEREF_id(id_alias(id));
367
		if (EQ_id(lid, id)) {
368
			break;
369
		}
370
		id = lid;
371
	}
372
	return (id);
2 7u83 373
}
374
 
375
 
376
/*
377
    CURRENT IDENTIFIER QUALIFIER
378
 
379
    This variable is set to describe how the current identifier is
380
    qualified.
381
*/
382
 
6 7u83 383
QUALIFIER crt_id_qualifier = qual_none;
384
int crt_templ_qualifier = 0;
2 7u83 385
 
386
 
387
/*
388
    CHECK AN IDENTIFIER NAME
389
 
390
    This routine checks whether the identifier name id is suitable for use
391
    in the context given by loc.  The namespace qualifiers used in describing
392
    id will be given by crt_id_qualifier.  The routine returns true for
393
    legal identifiers.
394
*/
395
 
6 7u83 396
ERROR
397
check_id_name(IDENTIFIER id, int loc)
2 7u83 398
{
6 7u83 399
	/* Check on namespace component */
400
	ERROR err = NULL_err;
401
	QUALIFIER cq = crt_id_qualifier;
402
	switch (cq) {
403
	case qual_none: {
404
		/* No namespace specifier */
405
		if (in_template_decl && is_templ_alias(id)) {
406
			/* Check for hiding of template parameters */
407
			err = ERR_temp_local_hide(id);
408
			if (!IS_NULL_err(err)) {
409
				return (err);
410
			}
411
		}
412
		if (crt_templ_qualifier) {
413
			goto qualifier_lab;
414
		}
415
		break;
2 7u83 416
	}
6 7u83 417
	case qual_nested:
418
qualifier_lab:
419
		/* Nested namespace specifier */
420
		if (loc == CONTEXT_PARAMETER || loc == CONTEXT_TEMPL_PARAM) {
421
			err = ERR_dcl_meaning_id(cq, id);
422
			if (!IS_NULL_err(err)) {
423
				return (err);
424
			}
425
		}
426
		break;
427
	case qual_full:
428
	case qual_top:
429
		/* Namespace specifier beginning with '::' */
430
		err = ERR_dcl_meaning_full(cq, id);
431
		if (!IS_NULL_err(err)) {
432
			return (err);
433
		}
434
		goto qualifier_lab;
2 7u83 435
	}
436
 
6 7u83 437
	/* Check on name component */
438
	if (loc != CONTEXT_FUNCTION && loc != CONTEXT_FUNC_MEMBER) {
439
		HASHID nm = DEREF_hashid(id_name(id));
440
		switch (TAG_hashid(nm)) {
441
		case hashid_constr_tag:
442
			/* A constructor must be a member function */
443
			err = ERR_class_mem_ctor(id);
444
			break;
445
		case hashid_destr_tag:
446
			/* A destructor must be a member function */
447
			err = ERR_class_dtor_func(nm);
448
			break;
449
		case hashid_conv_tag:
450
		case hashid_op_tag:
451
			/* These must be functions */
452
			err = ERR_dcl_meaning_id(cq, id);
453
			break;
454
		}
2 7u83 455
	}
6 7u83 456
	return (err);
2 7u83 457
}
458
 
459
 
460
/*
461
    DECLARE AN IMPLICIT FUNCTION
462
 
463
    This routine declares a function named id in the current scope with
464
    declaration specifiers ds, return type ret (which may be the null type),
465
    parameter types p (terminated by the null type), and function kind ell.
466
    It is used to declare implicit functions.
467
*/
468
 
6 7u83 469
IDENTIFIER
470
declare_func(DECL_SPEC ds, IDENTIFIER id, TYPE ret, TYPE *p, int ell,
471
	     LIST(TYPE) ex)
2 7u83 472
{
6 7u83 473
	/* Save certain information */
474
	TYPE t;
475
	CV_SPEC cv;
476
	DECL_SPEC acc = crt_access;
477
	int td = have_type_declaration;
478
	QUALIFIER cq = crt_id_qualifier;
479
	int tq = crt_templ_qualifier;
480
	crt_access = dspec_public;
481
	crt_id_qualifier = qual_none;
482
	crt_templ_qualifier = 0;
483
	have_type_declaration = TYPE_DECL_NONE;
2 7u83 484
 
6 7u83 485
	/* Declare parameters */
486
	decl_loc = crt_loc;
487
	begin_param(id);
488
	while (!IS_NULL_type(*p)) {
489
		HASHID nm = lookup_anon();
490
		IDENTIFIER pid = DEREF_id(hashid_id(nm));
491
		pid = make_param_decl(dspec_none, *p, pid, CONTEXT_PARAMETER);
492
		init_param(pid, NULL_exp);
493
		p++;
494
	}
495
	if (IS_NULL_type(ret)) {
496
		ret = type_inferred;
497
	}
498
	cv = func_linkage(cv_none);
499
	t = make_func_type(ret, ell, cv, ex);
500
	end_param();
2 7u83 501
 
6 7u83 502
	/* Declare the function */
503
	if (in_class_defn) {
2 7u83 504
#if LANGUAGE_CPP
6 7u83 505
		if (ds & dspec_friend) {
506
			id = make_friend_decl(ds, t, id, 0, 1);
507
		} else {
508
			id = make_func_mem_decl(ds, t, id, 0);
509
		}
510
#else
511
		id = make_member_decl(ds, t, id, 0);
512
#endif
2 7u83 513
	} else {
6 7u83 514
		id = make_func_decl(ds, t, id, 0);
2 7u83 515
	}
6 7u83 516
	if (do_dump) {
517
		dump_implicit = 1;
518
		dump_declare(id, &decl_loc, 0);
519
	}
520
	have_type_declaration = td;
521
	crt_templ_qualifier = tq;
522
	crt_id_qualifier = cq;
523
	crt_access = acc;
524
	return (id);
2 7u83 525
}
526
 
527
 
528
/*
529
    IMPLICITLY DECLARE AN IDENTIFIER
530
 
531
    This routine implicitly declares an identifier id, either as a local
532
    variable, if fn is false, or as a function.  fn will be 2 in the cases
533
    where C allows an implicit function declaration.  The routine returns
534
    the corresponding identifier expression.
535
*/
536
 
6 7u83 537
EXP
538
implicit_id_exp(IDENTIFIER id, int fn)
2 7u83 539
{
6 7u83 540
	EXP e;
541
	ERROR err;
542
	LOCATION loc;
543
	DECL_SPEC ds;
544
	IDENTIFIER pid;
545
	DECL_SPEC cl = crt_linkage;
546
	QUALIFIER cq = crt_id_qualifier;
547
	int tq = crt_templ_qualifier;
548
	NAMESPACE cns = crt_namespace;
549
	HASHID nm = DEREF_hashid(id_name(id));
550
	NAMESPACE ns = DEREF_nspace(id_parent(id));
2 7u83 551
 
6 7u83 552
	/* Check for implicit function declarations */
553
	if (fn == 2 && option(OPT_func_impl) == OPTION_DISALLOW) {
554
		fn = 1;
555
	}
2 7u83 556
 
6 7u83 557
	/* Allow for template dependent declarations */
558
	if (in_template_decl && is_templ_nspace(cns)) {
559
		int opt = OPT_templ_undecl;
560
		OPTION sev = option(opt);
561
		if (sev != OPTION_ALLOW) {
562
			/* Implicit declarations for dependent identifiers */
563
			if (dependent_id(id)) {
564
				opt = OPT_none;
565
				sev = OPTION_ALLOW;
566
			}
567
		}
568
		if (sev != OPTION_DISALLOW) {
569
			if (sev != OPTION_ALLOW && fn != 2) {
570
				if (cq == qual_none) {
571
					err = ERR_lookup_unqual_undef(nm);
572
				} else {
573
					err = ERR_lookup_qual_undef(nm, ns);
574
				}
575
				err = set_severity(err, opt, 0);
576
				report(crt_loc, err);
577
			}
578
			MAKE_exp_undeclared(type_templ_param, id, cq, e);
579
			return (e);
580
		}
581
		if (cq == qual_none) {
582
			ns = NULL_nspace;
583
		}
2 7u83 584
	}
6 7u83 585
 
586
	/* Check for previous declaration */
587
	if (IS_NULL_nspace(ns)) {
588
		OPTION sev = option(OPT_decl_unify);
589
		if (sev != OPTION_OFF) {
590
			LIST(IDENTIFIER)p;
591
			NAMESPACE pns = nonblock_namespace;
592
			p = DEREF_list(nspace_named_etc_extra(pns));
593
			pid = unify_extern(id, NULL_type, pns, p);
594
			if (!IS_NULL_id(pid)) {
595
				if (sev != OPTION_ON) {
596
					err = ERR_lookup_unqual_vis(pid);
597
					err = set_severity(err, OPT_decl_unify,
598
							   0);
599
					report(crt_loc, err);
600
				}
601
				e = make_id_exp(pid);
602
				return (e);
603
			}
2 7u83 604
		}
6 7u83 605
		ns = cns;
2 7u83 606
	}
607
 
6 7u83 608
	/* Rescan identifier */
609
	pid = search_id(ns, nm, 0, 0);
610
	if (!IS_NULL_id(pid)) {
611
		switch (TAG_id(pid)) {
612
		case id_variable_tag:
613
		case id_function_tag: {
614
			e = make_id_exp(pid);
615
			return (e);
2 7u83 616
		}
6 7u83 617
		}
2 7u83 618
	}
619
 
6 7u83 620
	/* Find namespace for declaration */
621
	crt_linkage = dspec_c;
622
	crt_id_qualifier = qual_none;
623
	crt_templ_qualifier = 0;
624
	push_namespace(ns);
625
	bad_crt_loc++;
626
	loc = crt_loc;
627
	if (crt_state_depth == 0) {
628
		/* Find identifier location */
629
		IDENTIFIER uid = underlying_id(id);
630
		DEREF_loc(id_loc(uid), crt_loc);
2 7u83 631
	}
632
 
6 7u83 633
	if (fn) {
634
		/* Implicit functions declarations */
635
		int ell;
636
		TYPE ret = type_sint;
637
		TYPE pars = NULL_type;
2 7u83 638
#if LANGUAGE_CPP
6 7u83 639
		/* Type is 'int ( ... )' in C++ */
640
		ell = FUNC_ELLIPSIS;
641
		if (fn == 1) {
642
			ret = type_error;
643
		}
2 7u83 644
#else
6 7u83 645
		/* Type is 'int ()' in C */
646
		ell = FUNC_NO_PARAMS;
2 7u83 647
#endif
6 7u83 648
		ds = (dspec_extern | dspec_ignore);
649
		id = declare_func(ds, id, ret, &pars, ell, empty_type_set);
650
	} else {
651
		/* Other implicit declarations */
652
		decl_loc = crt_loc;
653
		id = make_object_decl(dspec_none, type_error, id, 0);
654
		IGNORE init_object(id, NULL_exp);
655
	}
2 7u83 656
 
6 7u83 657
	/* Report error */
658
	crt_linkage = cl;
659
	crt_templ_qualifier = tq;
660
	crt_id_qualifier = cq;
661
	if (fn == 2) {
662
		pid = DEREF_id(id_alias(id));
663
		ds = DEREF_dspec(id_storage(pid));
664
		if (ds & dspec_temp) {
665
			/* Implicit declaration already reported */
666
			err = NULL_err;
667
		} else {
668
			err = ERR_expr_call_undecl(id);
669
			if (!IS_NULL_err(err)) {
670
				ds |= dspec_temp;
671
				COPY_dspec(id_storage(pid), ds);
672
			}
673
		}
674
	} else if (cq == qual_none) {
675
		err = ERR_lookup_unqual_undef(nm);
2 7u83 676
	} else {
6 7u83 677
		err = ERR_lookup_qual_undef(nm, ns);
2 7u83 678
	}
6 7u83 679
	report(crt_loc, err);
2 7u83 680
 
6 7u83 681
	/* Construct the result */
682
	crt_loc = loc;
683
	bad_crt_loc--;
684
	IGNORE pop_namespace();
685
	e = make_id_exp(id);
686
	return (e);
2 7u83 687
}
688
 
689
 
690
/*
691
    LIST OF MEANINGS
692
 
693
    This list is built up by list_ambiguous to give all the meanings of
694
    its ambiguous identifier which match its type argument.
695
*/
696
 
6 7u83 697
static LIST(IDENTIFIER) ambig_meanings = NULL_list(IDENTIFIER);
2 7u83 698
 
699
 
700
/*
701
    LIST MEANINGS OF AN AMBIGUOUS IDENTIFIER
702
 
703
    This routine adds all meanings of the ambiguous identifier id to the
704
    error list err.
705
*/
706
 
6 7u83 707
static unsigned
708
list_ambiguous(IDENTIFIER id, unsigned n, ERROR *err, int type, int rec)
2 7u83 709
{
6 7u83 710
	if (!IS_NULL_id(id)) {
711
		switch (TAG_id(id)) {
712
		case id_ambig_tag: {
713
			/* Ambiguous identifiers */
714
			LIST(IDENTIFIER) p = DEREF_list(id_ambig_ids(id));
715
			rec = DEREF_int(id_ambig_over(id));
716
			while (!IS_NULL_list(p)) {
717
				id = DEREF_id(HEAD_list(p));
718
				n = list_ambiguous(id, n, err, type, rec);
719
				p = TAIL_list(p);
720
			}
721
			break;
2 7u83 722
		}
6 7u83 723
		case id_function_tag:
724
		case id_mem_func_tag:
725
		case id_stat_mem_func_tag: {
726
			/* Functions */
727
			if (rec) {
728
				IDENTIFIER over;
729
				over = DEREF_id(id_function_etc_over(id));
730
				n = list_ambiguous(over, n, err, type, rec);
731
			}
732
			goto default_lab;
2 7u83 733
		}
6 7u83 734
		case id_class_name_tag:
735
		case id_class_alias_tag:
736
		case id_enum_name_tag:
737
		case id_enum_alias_tag:
738
		case id_type_alias_tag: {
739
			/* Types */
740
			type = 0;
741
			goto default_lab;
742
		}
743
		default:
744
default_lab: {
745
		     /* Other identifiers */
746
		     PTR(LOCATION) loc = id_loc(id);
747
		     n++;
748
		     add_error(err, ERR_fail_list_item(n, id, loc));
749
		     break;
750
	     }
751
		}
752
		if (type == 0) {
753
			/* Add to list of meanings */
754
			CONS_id(id, ambig_meanings, ambig_meanings);
755
		}
2 7u83 756
	}
6 7u83 757
	return (n);
2 7u83 758
}
759
 
760
 
761
/*
762
    REPORT AN AMBIGUOUS IDENTIFIER
763
 
764
    This routine reports the identifier id as being ambiguous.  Overloaded
765
    functions count as a single identifier unless rec is true.  It returns
766
    one of the possible meanings.  Only types are considered if type is
767
    true.  If there is exactly one possible meaning or force is true the
768
    first meaning is returned.  Otherwise the null identifier is returned.
769
*/
770
 
6 7u83 771
IDENTIFIER
772
report_ambiguous(IDENTIFIER id, int type, int rec, int force)
2 7u83 773
{
6 7u83 774
	ERROR err, err2;
775
	LIST(IDENTIFIER) p;
776
	NAMESPACE ns = DEREF_nspace(id_parent(id));
2 7u83 777
 
6 7u83 778
	/* List all meanings */
779
	if (!IS_NULL_nspace(ns) && IS_nspace_ctype(ns)) {
780
		err = ERR_lookup_ambig_mem(id);
781
	} else {
782
		err = ERR_lookup_ambig_id(id);
783
	}
784
	err2 = ERR_lookup_ambig_list();
785
	if (!IS_NULL_err(err2)) {
786
		unsigned n = 0;
787
		err = concat_error(err, err2);
788
		n = list_ambiguous(id, n, &err, type, rec);
789
		err = concat_error(err, ERR_fail_list_end(n));
790
	}
791
	report(crt_loc, err);
2 7u83 792
 
6 7u83 793
	/* Check for resolved meaning */
794
	id = NULL_id;
795
	p = ambig_meanings;
796
	if (!IS_NULL_list(p)) {
797
		if (IS_NULL_list(TAIL_list(p)) || force) {
798
			id = DEREF_id(HEAD_list(p));
799
		}
800
		DESTROY_list(p, SIZE_id);
801
		ambig_meanings = NULL_list(IDENTIFIER);
2 7u83 802
	}
6 7u83 803
	return (id);
2 7u83 804
}
805
 
806
 
807
/*
808
    FIND THE DECLARATION SPECIFIER FOR AN AMBIGUOUS IDENTIFIER
809
 
810
    This routine finds the declaration specifier for an ambiguous identifier
811
    given by the list of cases pids.  This consists of various properties
812
    which all the cases share.
813
*/
814
 
6 7u83 815
DECL_SPEC
816
find_ambig_dspec(LIST(IDENTIFIER) pids)
2 7u83 817
{
6 7u83 818
	DECL_SPEC ds = (dspec_implicit | dspec_template);
819
	while (!IS_NULL_list(pids)) {
820
		IDENTIFIER pid = DEREF_id(HEAD_list(pids));
821
		if (!IS_NULL_id(pid)) {
822
			DECL_SPEC pds = DEREF_dspec(id_storage(pid));
823
			ds &= pds;
824
		}
825
		pids = TAIL_list(pids);
2 7u83 826
	}
6 7u83 827
	return (ds);
2 7u83 828
}
829
 
830
 
831
/*
832
    CREATE AN IDENTIFIER EXPRESSION
833
 
834
    This routine creates an expression corresponding to the identifier id.
835
    Note that static member functions are identifier expressions if they
836
    are not overloaded, but member expression otherwise.  They are sorted
837
    out properly during overload resolution (see resolve_cast).
838
*/
839
 
6 7u83 840
EXP
841
make_id_exp(IDENTIFIER id)
2 7u83 842
{
6 7u83 843
	EXP e;
844
	unsigned tag = TAG_id(id);
845
	QUALIFIER cq = crt_id_qualifier;
846
	switch (tag) {
847
	case id_variable_tag:
848
	case id_parameter_tag: {
849
		/* Variables and parameters */
850
		TYPE t;
851
		DECL_SPEC ds;
852
		use_id(id, 0);
853
		ds = DEREF_dspec(id_storage(id));
854
		if (ds & dspec_auto) {
855
			/* Check use of automatic variable */
856
			NAMESPACE ns = crt_namespace;
857
			switch (TAG_nspace(ns)) {
858
			case nspace_block_tag:
859
			case nspace_dummy_tag: {
860
				if (really_in_function_defn > 1) {
861
					/* Used in nested function */
862
					IDENTIFIER fid;
863
					ns = DEREF_nspace(id_parent(id));
864
					fid = DEREF_id(nspace_name(ns));
865
					if (!EQ_id(fid, crt_func_id)) {
866
						ERROR err =
867
						    ERR_class_local_auto(id);
868
						report(crt_loc, err);
869
					}
870
				}
871
				break;
2 7u83 872
			}
6 7u83 873
			case nspace_param_tag:
874
			case nspace_templ_tag: {
875
				/* Used in default argument */
876
				if (in_default_arg) {
877
					ERROR err =
878
					    ERR_dcl_fct_default_param(id);
879
					report(crt_loc, err);
880
				}
881
				break;
2 7u83 882
			}
6 7u83 883
			default: {
884
				/* Used in local class */
885
				ERROR err = ERR_class_local_auto(id);
886
				report(crt_loc, err);
887
				break;
888
			}
889
			}
2 7u83 890
		}
6 7u83 891
		t = DEREF_type(id_variable_etc_type(id));
892
		if ((ds & dspec_extern) && cv_extern) {
893
			CV_SPEC cv = DEREF_cv(type_qual(t));
894
			t = qualify_type(t,(cv | cv_extern), 0);
895
			used_extern_volatile = 1;
896
		}
897
		MAKE_exp_identifier(t, id, cq, e);
898
		break;
2 7u83 899
	}
6 7u83 900
	case id_stat_member_tag: {
901
		/* Static data members */
902
		TYPE t;
903
		DECL_SPEC ds;
904
		use_id(id, suppress_usage);
905
		ds = DEREF_dspec(id_storage(id));
906
		if (ds & dspec_inherit) {
907
			id = DEREF_id(id_alias(id));
908
		}
909
		t = DEREF_type(id_stat_member_type(id));
910
		if ((ds & dspec_extern) && cv_extern) {
911
			CV_SPEC cv = DEREF_cv(type_qual(t));
912
			t = qualify_type(t,(cv | cv_extern), 0);
913
			used_extern_volatile = 1;
914
		}
915
		MAKE_exp_identifier(t, id, cq, e);
916
		break;
2 7u83 917
	}
6 7u83 918
	case id_function_tag: {
919
		/* Normal functions */
920
		TYPE t = DEREF_type(id_function_type(id));
921
		MAKE_exp_identifier(t, id, cq, e);
922
		break;
2 7u83 923
	}
6 7u83 924
	case id_stat_mem_func_tag: {
925
		/* Static member functions */
926
		TYPE t = DEREF_type(id_stat_mem_func_type(id));
927
		IDENTIFIER over = DEREF_id(id_stat_mem_func_over(id));
928
		if (IS_NULL_id(over)) {
929
			MAKE_exp_identifier(t, id, cq, e);
930
		} else {
931
			MAKE_exp_member(t, id, cq, e);
932
		}
933
		break;
2 7u83 934
	}
6 7u83 935
	case id_mem_func_tag: {
936
		/* Non-static member functions */
937
		TYPE t = DEREF_type(id_mem_func_type(id));
938
		MAKE_exp_member(t, id, cq, e);
939
		break;
2 7u83 940
	}
6 7u83 941
	case id_member_tag: {
942
		/* Non-static members */
943
		TYPE t = DEREF_type(id_member_type(id));
944
		MAKE_exp_member(t, id, cq, e);
945
		break;
2 7u83 946
	}
6 7u83 947
	case id_enumerator_tag: {
948
		/* Enumerators */
949
		NAT n;
950
		TYPE t;
951
		use_id(id, 0);
952
		e = DEREF_exp(id_enumerator_value(id));
953
		DECONS_exp_int_lit(t, n, tag, e);
954
		MAKE_exp_int_lit(t, n, tag, e);
955
		break;
2 7u83 956
	}
6 7u83 957
	case id_token_tag: {
958
		/* Tokens */
959
		TOKEN tok = DEREF_tok(id_token_sort(id));
960
		switch (TAG_tok(tok)) {
961
		case tok_exp_tag:
962
		case tok_nat_tag:
963
		case tok_snat_tag:
964
		case tok_stmt_tag:
965
			/* Expression tokens */
966
			use_id(id, 0);
967
			id = DEREF_id(id_token_alt(id));
968
			e = apply_exp_token(id, NULL_list(TOKEN), 0);
969
			break;
970
		default:
971
			/* Other tokens */
972
			goto default_lab;
2 7u83 973
		}
6 7u83 974
		break;
2 7u83 975
	}
6 7u83 976
	case id_class_name_tag:
977
	case id_enum_name_tag:
978
	case id_class_alias_tag:
979
	case id_enum_alias_tag:
980
	case id_type_alias_tag: {
981
		/* Type names */
982
		TYPE t = DEREF_type(id_class_name_etc_defn(id));
983
		report(crt_loc, ERR_expr_prim_type(id));
984
		MAKE_exp_value(t, e);
985
		break;
2 7u83 986
	}
6 7u83 987
	case id_ambig_tag: {
988
		/* Ambiguous identifiers */
989
		MAKE_exp_ambiguous(type_error, id, cq, e);
990
		break;
2 7u83 991
	}
6 7u83 992
	default:
993
default_lab:
994
		/* Undefined identifiers */
995
		if (cq == qual_none && in_template_decl) {
996
			/* Create a dummy identifier */
997
			HASHID nm = DEREF_hashid(id_name(id));
998
			NAMESPACE ns = nonblock_namespace;
999
			MAKE_id_undef(nm, dspec_none, ns, crt_loc, id);
1000
		}
1001
		MAKE_exp_undeclared(type_error, id, cq, e);
1002
		break;
2 7u83 1003
	}
6 7u83 1004
	return (e);
2 7u83 1005
}
1006
 
1007
 
1008
/*
1009
    FIND THE THIS PARAMETER OF A FUNCTION
1010
 
1011
    This routine returns the 'this' parameter of the member function fn.
1012
    If use is true then the parameter is marked as used.
1013
*/
1014
 
6 7u83 1015
IDENTIFIER
1016
this_param(IDENTIFIER fn, int use)
2 7u83 1017
{
6 7u83 1018
	NAMESPACE ns;
1019
	IDENTIFIER pid;
1020
	HASHID nm = KEYWORD(lex_this_Hname);
1021
	TYPE t = DEREF_type(id_mem_func_type(fn));
1022
	while (IS_type_templ(t)) {
1023
		t = DEREF_type(type_templ_defn(t));
1024
	}
1025
	ns = DEREF_nspace(type_func_pars(t));
1026
	pid = search_id(ns, nm, 0, 0);
1027
	if (!IS_NULL_id(pid) && use) {
1028
		/* Mark parameter as used */
1029
		DECL_SPEC ds = DEREF_dspec(id_storage(pid));
1030
		ds |= dspec_used;
1031
		COPY_dspec(id_storage(pid), ds);
1032
	}
1033
	return (pid);
2 7u83 1034
}
1035
 
1036
 
1037
/*
1038
    CREATE A THIS EXPRESSION
1039
 
1040
    This routine deals with the 'this' expression.  This is only in scope
1041
    in the definition of a non-static member function.   Note that the
1042
    current value of 'this' is given by the address of the dummy parameter
1043
    with name given by lex_this_Hname.
1044
*/
1045
 
6 7u83 1046
EXP
1047
make_this_exp(void)
2 7u83 1048
{
6 7u83 1049
	EXP e;
1050
	TYPE t;
1051
	IDENTIFIER fn = crt_func_id;
1052
	if (in_function_defn && IS_id_mem_func(fn)) {
1053
		/* The current value of 'this' is returned */
1054
		IDENTIFIER pid = this_param(fn, 1);
1055
		if (in_default_arg) {
1056
			/* Can't use 'this' in default argument */
1057
			ERROR err = ERR_dcl_fct_default_param(pid);
1058
			report(crt_loc, err);
1059
		}
1060
		e = DEREF_exp(id_parameter_init(pid));
1061
		t = DEREF_type(exp_type(e));
1062
		MAKE_exp_copy(t, e, e);
1063
	} else {
1064
		/* Must be inside a non-static member function */
1065
		report(crt_loc, ERR_expr_prim_this());
1066
		e = make_error_exp(0);
2 7u83 1067
	}
6 7u83 1068
	return (e);
2 7u83 1069
}
1070
 
1071
 
1072
/*
1073
    CREATE A THIS EXPRESSION
1074
 
1075
    This routine creates an expression corresponding to the 'this' parameter
1076
    of a member function.  The parent class namespace is assigned to pns.
1077
    The null expression is returned if we are outside of a member function.
1078
*/
1079
 
6 7u83 1080
EXP
1081
make_this_ref(NAMESPACE *pns)
2 7u83 1082
{
6 7u83 1083
	IDENTIFIER fn = crt_func_id;
1084
	if (in_function_defn && IS_id_mem_func(fn)) {
1085
		EXP e;
1086
		IDENTIFIER pid = this_param(fn, 1);
1087
		TYPE t = DEREF_type(id_parameter_type(pid));
1088
		MAKE_exp_identifier(t, pid, qual_none, e);
1089
		*pns = DEREF_nspace(id_parent(fn));
1090
		return (e);
1091
	}
1092
	return (NULL_exp);
2 7u83 1093
}
1094
 
1095
 
1096
/*
1097
    DECLARE A THIS PARAMETER
1098
 
1099
    This routine declares the dummy extra parameter for the non-static
1100
    member function given by the identifier fn.  The type of this parameter
1101
    is the first element of the corresponding mtypes list (see
1102
    member_func_type).  An expression giving the address of the parameter
1103
    is stored in its default argument position.  This gives the value of
1104
    the 'this' expression.
1105
*/
1106
 
6 7u83 1107
EXP
1108
make_this_decl(IDENTIFIER fn)
2 7u83 1109
{
6 7u83 1110
	/* Look up identifier */
1111
	EXP e;
1112
	TYPE t;
1113
	IDENTIFIER pid;
1114
	LIST(TYPE) mtypes;
1115
	NAMESPACE ns = crt_namespace;
1116
	HASHID nm = KEYWORD(lex_this_Hname);
1117
	MEMBER mem = search_member(ns, nm, 1);
1118
	IDENTIFIER qid = DEREF_id(member_id(mem));
1119
	DECL_SPEC ds = (dspec_auto | dspec_defn | dspec_implicit);
2 7u83 1120
 
6 7u83 1121
	/* Construct the type of the parameter */
1122
	TYPE f = DEREF_type(id_mem_func_type(fn));
1123
	while (IS_type_templ(f)) {
1124
		f = DEREF_type(type_templ_defn(f));
1125
	}
1126
	mtypes = DEREF_list(type_func_mtypes(f));
1127
	t = DEREF_type(HEAD_list(mtypes));
2 7u83 1128
 
6 7u83 1129
	/* Declare parameter */
1130
	MAKE_id_parameter(nm, ds, ns, crt_loc, t, pid);
1131
	if (!IS_NULL_id(qid)) {
1132
		qid = DEREF_id(id_alias(qid));
1133
		COPY_id(id_alias(pid), qid);
1134
	}
1135
	COPY_id(hashid_cache(nm), pid);
1136
	COPY_id(member_id(mem), pid);
2 7u83 1137
 
6 7u83 1138
	/* Construct the 'this' expression */
1139
	t = DEREF_type(type_ref_sub(t));
1140
	t = rvalue_type(t);
1141
	if (option(OPT_this_lvalue) == OPTION_ALLOW) {
1142
		MAKE_type_ptr(cv_lvalue, t, t);
1143
		MAKE_exp_identifier(t, pid, qual_none, e);
1144
	} else {
1145
		MAKE_type_ptr(cv_none, t, t);
1146
		MAKE_exp_identifier(t, pid, qual_none, e);
1147
		MAKE_exp_contents(t, e, e);
1148
	}
1149
	COPY_exp(id_parameter_init(pid), e);
1150
	return (e);
2 7u83 1151
}
1152
 
1153
 
1154
/*
1155
    CHECK FOR THIS EXPRESSIONS
1156
 
1157
    This routine checks whether the expression e is a 'this' expression.
1158
*/
1159
 
6 7u83 1160
int
1161
is_this_exp(EXP e)
2 7u83 1162
{
6 7u83 1163
	if (!IS_NULL_exp(e)) {
1164
		unsigned tag = TAG_exp(e);
1165
		if (tag == exp_indir_tag) {
1166
			e = DEREF_exp(exp_indir_ptr(e));
1167
			tag = TAG_exp(e);
1168
		}
1169
		if (tag == exp_copy_tag) {
1170
			e = DEREF_exp(exp_copy_arg(e));
1171
			tag = TAG_exp(e);
1172
		}
1173
		if (tag == exp_contents_tag) {
1174
			e = DEREF_exp(exp_contents_ptr(e));
1175
			tag = TAG_exp(e);
1176
		}
1177
		if (tag == exp_copy_tag) {
1178
			e = DEREF_exp(exp_copy_arg(e));
1179
			tag = TAG_exp(e);
1180
		}
1181
		if (tag == exp_identifier_tag) {
1182
			IDENTIFIER id = DEREF_id(exp_identifier_id(e));
1183
			HASHID nm = DEREF_hashid(id_name(id));
1184
			if (EQ_KEYWORD(nm, lex_this_Hname)) {
1185
				return (1);
1186
			}
1187
		}
2 7u83 1188
	}
6 7u83 1189
	return (0);
2 7u83 1190
}
1191
 
1192
 
1193
/*
1194
    FIND THE ELLIPSIS PARAMETER OF A FUNCTION
1195
 
1196
    This routine returns the ellipsis parameter of the function fn.
1197
*/
1198
 
6 7u83 1199
IDENTIFIER
1200
ellipsis_param(IDENTIFIER fn)
2 7u83 1201
{
6 7u83 1202
	int ell;
1203
	TYPE t = DEREF_type(id_function_etc_type(fn));
1204
	while (IS_type_templ(t)) {
1205
		t = DEREF_type(type_templ_defn(t));
1206
	}
1207
	ell = DEREF_int(type_func_ellipsis(t));
1208
	if (ell & FUNC_ELLIPSIS) {
1209
		HASHID nm = KEYWORD(lex_ellipsis_Hexp);
1210
		NAMESPACE ns = DEREF_nspace(type_func_pars(t));
1211
		IDENTIFIER pid = search_id(ns, nm, 0, 0);
1212
		return (pid);
1213
	}
1214
	return (NULL_id);
2 7u83 1215
}
1216
 
1217
 
1218
/*
1219
    FIND ELLIPSIS TYPE
1220
 
1221
    This routine returns the type of the dummy ellipsis parameter.  If
1222
    force is true then an error is reported if this type has not been
1223
    declared.
1224
*/
1225
 
6 7u83 1226
static TYPE
1227
find_ellipsis_type(int force)
2 7u83 1228
{
6 7u83 1229
	TYPE t = type_ellipsis;
1230
	if (IS_NULL_type(t)) {
1231
		/* Look up token if not already defined */
1232
		IDENTIFIER tid = get_special(TOK_va_t, 1);
1233
		if (!IS_NULL_id(tid) && IS_id_token(tid)) {
1234
			tid = DEREF_id(id_token_alt(tid));
1235
			if (IS_id_class_name_etc(tid)) {
1236
				t = DEREF_type(id_class_name_etc_defn(tid));
1237
				type_ellipsis = t;
1238
			}
1239
		}
1240
		if (IS_NULL_type(t)) {
1241
			if (force) {
1242
				/* Report if ellipsis type is undefined */
1243
				HASHID nm = KEYWORD(lex_ellipsis_Hexp);
1244
				report(crt_loc,
1245
				       ERR_lib_builtin(NULL_string, nm));
1246
			}
1247
			t = type_error;
1248
		}
2 7u83 1249
	}
6 7u83 1250
	return (t);
2 7u83 1251
}
1252
 
1253
 
1254
/*
1255
    DECLARE AN ELLIPSIS PARAMETER
1256
 
1257
    This routine declares the dummy extra parameter representing the
1258
    ellipsis component of the function id.
1259
*/
1260
 
6 7u83 1261
void
1262
make_ellipsis_decl(void)
2 7u83 1263
{
6 7u83 1264
	IDENTIFIER pid;
1265
	NAMESPACE ns = crt_namespace;
1266
	TYPE t = find_ellipsis_type(0);
1267
	HASHID nm = KEYWORD(lex_ellipsis_Hexp);
1268
	MEMBER mem = search_member(ns, nm, 1);
1269
	IDENTIFIER qid = DEREF_id(member_id(mem));
1270
	DECL_SPEC ds = (dspec_auto | dspec_defn | dspec_implicit);
1271
	MAKE_id_parameter(nm, ds, ns, crt_loc, t, pid);
1272
	if (!IS_NULL_id(qid)) {
1273
		qid = DEREF_id(id_alias(qid));
1274
		COPY_id(id_alias(pid), qid);
1275
	}
1276
	COPY_id(hashid_cache(nm), pid);
1277
	COPY_id(member_id(mem), pid);
1278
	return;
2 7u83 1279
}
1280
 
1281
 
1282
/*
1283
    CREATE AN ELLIPSIS EXPRESSION
1284
 
1285
    This routine creates an expression corresponding to the ellipsis
1286
    expression '...'.  This can only be used in a function definition
1287
    which has an ellipsis type, in which case it is an rvalue of type
1288
    type_ellipsis.
1289
*/
1290
 
6 7u83 1291
EXP
1292
make_ellipsis_exp(void)
2 7u83 1293
{
6 7u83 1294
	EXP e;
1295
	if (in_function_defn) {
1296
		IDENTIFIER pid = ellipsis_param(crt_func_id);
1297
		if (!IS_NULL_id(pid)) {
1298
			/* Form result */
1299
			TYPE t = find_ellipsis_type(1);
1300
			report(crt_loc, ERR_expr_call_ell_exp());
1301
			MAKE_exp_identifier(t, pid, qual_none, e);
1302
			return (e);
1303
		}
2 7u83 1304
	}
6 7u83 1305
	report(crt_loc, ERR_expr_call_ell_func());
1306
	e = make_error_exp(0);
1307
	return (e);
2 7u83 1308
}