Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – tendra.SVN – Blame – //branches/tendra4/src/producers/common/construct/initialise.c – Rev 2

Subversion Repositories tendra.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
2
    		 Crown Copyright (c) 1997, 1998
3
 
4
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
12
 
13
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
15
 
16
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
19
 
20
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
22
        these conditions;
23
 
24
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
27
        it may be put.
28
*/
29
 
30
 
31
#include "config.h"
32
#include "c_types.h"
33
#include "ctype_ops.h"
34
#include "etype_ops.h"
35
#include "exp_ops.h"
36
#include "ftype_ops.h"
37
#include "graph_ops.h"
38
#include "hashid_ops.h"
39
#include "id_ops.h"
40
#include "member_ops.h"
41
#include "nat_ops.h"
42
#include "nspace_ops.h"
43
#include "str_ops.h"
44
#include "type_ops.h"
45
#include "error.h"
46
#include "catalog.h"
47
#include "option.h"
48
#include "tdf.h"
49
#include "access.h"
50
#include "assign.h"
51
#include "basetype.h"
52
#include "buffer.h"
53
#include "cast.h"
54
#include "check.h"
55
#include "chktype.h"
56
#include "class.h"
57
#include "compile.h"
58
#include "constant.h"
59
#include "construct.h"
60
#include "convert.h"
61
#include "declare.h"
62
#include "derive.h"
63
#include "destroy.h"
64
#include "dump.h"
65
#include "exception.h"
66
#include "expression.h"
67
#include "file.h"
68
#include "function.h"
69
#include "hash.h"
70
#include "identifier.h"
71
#include "initialise.h"
72
#include "instance.h"
73
#include "inttype.h"
74
#include "literal.h"
75
#include "namespace.h"
76
#include "overload.h"
77
#include "parse.h"
78
#include "predict.h"
79
#include "print.h"
80
#include "statement.h"
81
#include "syntax.h"
82
#include "template.h"
83
#include "tok.h"
84
#include "tokdef.h"
85
#include "token.h"
86
#include "ustring.h"
87
 
88
 
89
/*
90
    INLINE MEMBER DEFINITIONS
91
 
92
    A static member can be defined inline in its class.  This is only a
93
    provisional definition for use in constant expressions etc.  The real
94
    definition (which cannot contain an initialiser) must be provided
95
    elsewhere.  This value is used to indicate such members.
96
*/
97
 
98
#define dspec_stat_inline	dspec_explicit
99
#define dspec_ignore_mem	( dspec_alias | dspec_inherit | dspec_token )
100
 
101
 
102
/*
103
    MEMBER NUMBER
104
 
105
    This variable is used to keep track of the number of data members
106
    within next_data_member.  Anonymous unions, rather than their members,
107
    are counted.
108
*/
109
 
110
unsigned long member_no = 0 ;
111
 
112
 
113
/*
114
    FIND NEXT DATA MEMBER
115
 
116
    This routine returns the first non-static, non-function member of a
117
    class following mem.  Anonymous unions are included if bit 1 of bf
118
    is false, but their members if it is true.  Anonymous bitfields are
119
    included if bit 0 of bf is true.  The null member is returned if there
120
    are no further members.
121
*/
122
 
123
MEMBER next_data_member
124
    PROTO_N ( ( mem, bf ) )
125
    PROTO_T ( MEMBER mem X int bf )
126
{
127
    while ( !IS_NULL_member ( mem ) ) {
128
	IDENTIFIER id = DEREF_id ( member_id ( mem ) ) ;
129
	if ( !IS_NULL_id ( id ) && IS_id_member ( id ) ) {
130
	    DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
131
	    if ( !( ds & dspec_ignore_mem ) ) {
132
		int ok = 1 ;
133
		HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
134
		if ( ds & dspec_reserve ) {
135
		    /* Anonymous union members */
136
		    if ( !( bf & 2 ) ) ok = 0 ;
137
		} else {
138
		    member_no++ ;
139
		}
140
		if ( IS_hashid_anon ( nm ) ) {
141
		    TYPE t = DEREF_type ( id_member_type ( id ) ) ;
142
		    unsigned tag = TAG_type ( t ) ;
143
		    if ( tag == type_bitfield_tag ) {
144
			/* Anonymous bitfield */
145
			if ( !( bf & 1 ) ) ok = 0 ;
146
		    } else if ( tag == type_compound_tag ) {
147
			/* Anonymous union */
148
			if ( bf & 2 ) ok = 0 ;
149
		    }
150
		}
151
		if ( ok ) return ( mem ) ;
152
	    }
153
	}
154
	mem = DEREF_member ( member_next ( mem ) ) ;
155
    }
156
    return ( NULL_member ) ;
157
}
158
 
159
 
160
/*
161
    CONSTRUCT A DYNAMIC INITIALISER
162
 
163
    This routine checks whether the expression e is a non-constant
164
    initialiser for id (or a component of id if off is not null).  If so
165
    it is embedded in a dynamic initialiser expression and an error is
166
    reported.
167
*/
168
 
169
EXP dynamic_init
170
    PROTO_N ( ( id, off, e ) )
171
    PROTO_T ( IDENTIFIER id X string off X EXP e )
172
{
173
    int fs = 0 ;
174
    int c = -1 ;
175
    if ( !IS_NULL_id ( id ) ) {
176
	switch ( TAG_id ( id ) ) {
177
	    case id_variable_tag : {
178
		DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
179
		if ( ds & dspec_auto ) {
180
		    if ( off == NULL ) return ( e ) ;
181
		} else {
182
		    if ( !( ds & dspec_linkage ) ) fs = 1 ;
183
		}
184
		break ;
185
	    }
186
	    case id_stat_member_tag : {
187
		/* Check static members */
188
		break ;
189
	    }
190
	    default : {
191
		/* Ignore other identifiers */
192
		return ( e ) ;
193
	    }
194
	}
195
    }
196
    if ( option ( OPT_init_dynamic ) ) {
197
	/* Dynamic initialisation not allowed */
198
	c = 1 ;
199
    }
200
    if ( !is_const_exp ( e, c ) ) {
201
	/* Non-constant initialiser */
202
	TYPE t = DEREF_type ( exp_type ( e ) ) ;
203
	if ( !is_templ_type ( t ) ) {
204
	    ERROR err ;
205
	    if ( off ) {
206
		err = ERR_dcl_init_aggr_dynamic () ;
207
	    } else {
208
		err = ERR_dcl_init_dynamic () ;
209
	    }
210
	    if ( !IS_NULL_err ( err ) ) {
211
		ERROR err2 = ERR_dcl_init_decl ( id, off ) ;
212
		err = concat_error ( err2, err ) ;
213
		report ( crt_loc, err ) ;
214
	    }
215
	    if ( fs ) {
216
		/* Check function statics */
217
		e = check_return_exp ( e, lex_static ) ;
218
	    }
219
	    MAKE_exp_dynamic ( t, e, e ) ;
220
	}
221
    }
222
    return ( e ) ;
223
}
224
 
225
 
226
/*
227
    CHECK A VARIABLE INITIALISER
228
 
229
    This routine is called to check the initialiser for a variable or static
230
    data member.  Its primary purpose is to mark those temporaries which
231
    are bound to variables.
232
*/
233
 
234
EXP check_init
235
    PROTO_N ( ( e ) )
236
    PROTO_T ( EXP e )
237
{
238
    if ( !IS_NULL_exp ( e ) ) {
239
	switch ( TAG_exp ( e ) ) {
240
	    case exp_identifier_tag : {
241
		IDENTIFIER id = DEREF_id ( exp_identifier_id ( e ) ) ;
242
		DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
243
		if ( ds & dspec_temp ) {
244
		    ds &= ~dspec_register ;
245
		    COPY_dspec ( id_storage ( id ), ds ) ;
246
		}
247
		break ;
248
	    }
249
	    case exp_init_tag : {
250
		IDENTIFIER id = DEREF_id ( exp_init_id ( e ) ) ;
251
		DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
252
		if ( ds & dspec_temp ) {
253
		    ds &= ~dspec_register ;
254
		    COPY_dspec ( id_storage ( id ), ds ) ;
255
		}
256
		break ;
257
	    }
258
	    case exp_indir_tag : {
259
		EXP a = DEREF_exp ( exp_indir_ptr ( e ) ) ;
260
		a = check_init ( a ) ;
261
		COPY_exp ( exp_indir_ptr ( e ), a ) ;
262
		break ;
263
	    }
264
	    case exp_address_tag : {
265
		EXP a = DEREF_exp ( exp_address_arg ( e ) ) ;
266
		a = check_init ( a ) ;
267
		COPY_exp ( exp_address_arg ( e ), a ) ;
268
		break ;
269
	    }
270
	    case exp_base_cast_tag : {
271
		EXP a = DEREF_exp ( exp_base_cast_arg ( e ) ) ;
272
		a = check_init ( a ) ;
273
		COPY_exp ( exp_base_cast_arg ( e ), a ) ;
274
		break ;
275
	    }
276
	    case exp_add_ptr_tag : {
277
		EXP a = DEREF_exp ( exp_add_ptr_ptr ( e ) ) ;
278
		a = check_init ( a ) ;
279
		COPY_exp ( exp_add_ptr_ptr ( e ), a ) ;
280
		break ;
281
	    }
282
	    case exp_dynamic_tag : {
283
		EXP a = DEREF_exp ( exp_dynamic_arg ( e ) ) ;
284
		a = check_init ( a ) ;
285
		COPY_exp ( exp_dynamic_arg ( e ), a ) ;
286
		break ;
287
	    }
288
	    case exp_aggregate_tag : {
289
		LIST ( EXP ) p = DEREF_list ( exp_aggregate_args ( e ) ) ;
290
		while ( !IS_NULL_list ( p ) ) {
291
		    EXP a = DEREF_exp ( HEAD_list ( p ) ) ;
292
		    a = check_init ( a ) ;
293
		    COPY_exp ( HEAD_list ( p ), a ) ;
294
		    p = TAIL_list ( p ) ;
295
		}
296
		break ;
297
	    }
298
	    case exp_nof_tag : {
299
		EXP a = DEREF_exp ( exp_nof_start ( e ) ) ;
300
		EXP b = DEREF_exp ( exp_nof_pad ( e ) ) ;
301
		EXP c = DEREF_exp ( exp_nof_end ( e ) ) ;
302
		a = check_init ( a ) ;
303
		b = check_init ( b ) ;
304
		c = check_init ( c ) ;
305
		COPY_exp ( exp_nof_start ( e ), a ) ;
306
		COPY_exp ( exp_nof_pad ( e ), b ) ;
307
		COPY_exp ( exp_nof_end ( e ), c ) ;
308
		break ;
309
	    }
310
	}
311
    }
312
    return ( e ) ;
313
}
314
 
315
 
316
/*
317
    TEMPORARY VARIABLE FLAG
318
 
319
    The variable made_temporary is set to the temporary variable whenever
320
    a temporary variable is created.  temp_storage is used to determine
321
    the storage class for a local variable.
322
*/
323
 
324
IDENTIFIER made_temporary = NULL_id ;
325
int keep_temporary = 0 ;
326
static DECL_SPEC temp_storage = dspec_auto ;
327
 
328
 
329
/*
330
    DECLARE A TEMPORARY VARIABLE
331
 
332
    This routine declares a temporary variable of type t, initial value
333
    e, and destructor d (the implicit destructor will be created if this
334
    is the null expression).  It returns an expression giving the value of
335
    this temporary.  Note the use of an assignment expression to ensure
336
    that the temporary gets initialised in the right place.
337
*/
338
 
339
EXP make_temporary
340
    PROTO_N ( ( t, e, d, ref, err ) )
341
    PROTO_T ( TYPE t X EXP e X EXP d X int ref X ERROR *err )
342
{
343
    LOCATION loc ;
344
    DECL_SPEC ds ;
345
    EXP c = NULL_exp ;
346
    HASHID nm = lookup_anon () ;
347
    NAMESPACE ns = crt_namespace ;
348
    QUALIFIER cq = crt_id_qualifier ;
349
    int tq = crt_templ_qualifier ;
350
    int fn = in_function_defn ;
351
    IDENTIFIER id = DEREF_id ( hashid_id ( nm ) ) ;
352
    loc = decl_loc ;
353
    decl_loc = crt_loc ;
354
    crt_id_qualifier = qual_none ;
355
    crt_templ_qualifier = 0 ;
356
 
357
    /* Declare the temporary object */
358
    if ( IS_type_ref ( t ) ) t = DEREF_type ( type_ref_sub ( t ) ) ;
359
    if ( in_default_arg ) {
360
	/* NOT YET IMPLEMENTED */
361
	crt_namespace = global_namespace ;
362
	in_function_defn = 0 ;
363
    }
364
    t = qualify_type ( t, cv_none, 0 ) ;
365
    if ( IS_type_compound ( t ) ) {
366
	add_error ( err, ERR_dcl_init_ref_tmp ( t ) ) ;
367
    }
368
    id = make_object_decl ( dspec_temp, t, id, 0 ) ;
369
    ds = DEREF_dspec ( id_storage ( id ) ) ;
370
    if ( temp_storage != dspec_auto ) {
371
	/* Set storage class */
372
	ds &= ~dspec_storage ;
373
	ds |= temp_storage ;
374
    }
375
    if ( ds & dspec_auto ) ds |= dspec_register ;
376
    COPY_dspec ( id_storage ( id ), ds ) ;
377
    made_temporary = id ;
378
 
379
    /* Check initialiser */
380
    if ( !is_const_exp ( e, -1 ) ) {
381
	if ( ds & dspec_auto ) {
382
	    c = e ;
383
	    e = NULL_exp ;
384
	} else if ( ref ) {
385
	    TYPE s = DEREF_type ( exp_type ( e ) ) ;
386
	    MAKE_exp_dynamic ( s, e, e ) ;
387
	    add_error ( err, ERR_dcl_init_dynamic () ) ;
388
	} else {
389
	    TYPE s = DEREF_type ( exp_type ( e ) ) ;
390
	    c = e ;
391
	    e = make_null_exp ( s ) ;
392
	}
393
    }
394
    if ( IS_NULL_exp ( d ) ) {
395
	/* Create destructor */
396
	int du = do_usage ;
397
	do_usage = 0 ;
398
	d = init_default ( t, &d, DEFAULT_DESTR, EXTRA_DESTR, err ) ;
399
	do_usage = du ;
400
    }
401
    COPY_exp ( id_variable_init ( id ), e ) ;
402
    COPY_exp ( id_variable_term ( id ), d ) ;
403
    define_id ( id ) ;
404
 
405
    /* Construct the result expression */
406
    if ( !IS_NULL_exp ( c ) ) {
407
	/* Assign initial value */
408
	t = DEREF_type ( id_variable_type ( id ) ) ;
409
	MAKE_exp_init ( t, id, c, e ) ;
410
	ds = DEREF_dspec ( id_storage ( id ) ) ;
411
	ds |= dspec_explicit ;
412
	COPY_dspec ( id_storage ( id ), ds ) ;
413
    } else {
414
	e = make_id_exp ( id ) ;
415
    }
416
 
417
    /* Define variable */
418
    if ( !( ds & dspec_auto ) ) {
419
	if ( !really_in_function_defn && !in_template_decl ) {
420
	    /* Compile variable definition */
421
	    compile_variable ( id, 0 ) ;
422
	}
423
    }
424
    if ( do_dump ) {
425
	dump_implicit = 1 ;
426
	dump_declare ( id, &decl_loc, 1 ) ;
427
    }
428
    crt_templ_qualifier = tq ;
429
    crt_id_qualifier = cq ;
430
    in_function_defn = fn ;
431
    crt_namespace = ns ;
432
    decl_loc = loc ;
433
    return ( e ) ;
434
}
435
 
436
 
437
/*
438
    IS A VARIABLE ALIASED IN AN EXPRESSION
439
 
440
    This routine checks whether the variable expression d is aliased in
441
    the expression e.
442
*/
443
 
444
static int involves_alias
445
    PROTO_N ( ( e, d ) )
446
    PROTO_T ( EXP e X EXP d )
447
{
448
    if ( !IS_NULL_exp ( d ) ) {
449
	/* NOT YET IMPLEMENTED */
450
	UNUSED ( e ) ;
451
	return ( 1 ) ;
452
    }
453
    return ( 0 ) ;
454
}
455
 
456
 
457
/*
458
    ELIMINATE A TEMPORARY VARIABLE
459
 
460
    This routine is called to eliminate any temporary variables from the
461
    value e which is to be assigned to a variable given by d.  d is the
462
    null expression in a variable initialisation, otherwise care needs
463
    to be taken if d is aliased in e.  Note that creating a temporary and
464
    then removing it ensures that the accesses for the copy constructor
465
    and destructor are checked correctly.
466
*/
467
 
468
EXP remove_temporary
469
    PROTO_N ( ( e, d ) )
470
    PROTO_T ( EXP e X EXP d )
471
{
472
    if ( !IS_NULL_exp ( e ) ) {
473
	EXP a = NULL_exp ;
474
	unsigned tag = TAG_exp ( e ) ;
475
	if ( tag == exp_constr_tag ) {
476
	    LIST ( EXP ) p ;
477
	    int info = DEREF_int ( exp_constr_info ( e ) ) ;
478
	    if ( info != DEFAULT_COPY ) return ( e ) ;
479
	    a = DEREF_exp ( exp_constr_call ( e ) ) ;
480
	    p = DEREF_list ( exp_func_id_args ( a ) ) ;
481
	    if ( IS_NULL_list ( p ) ) return ( e ) ;
482
	    p = TAIL_list ( p ) ;
483
	    if ( IS_NULL_list ( p ) ) return ( e ) ;
484
	    a = DEREF_exp ( HEAD_list ( p ) ) ;
485
	    if ( !IS_exp_address ( a ) ) return ( e ) ;
486
	    a = DEREF_exp ( exp_address_arg ( a ) ) ;
487
	} else if ( tag == exp_contents_tag ) {
488
	    a = DEREF_exp ( exp_contents_ptr ( e ) ) ;
489
	}
490
	if ( !IS_NULL_exp ( a ) && IS_exp_init ( a ) ) {
491
	    /* Check for temporary variable */
492
	    IDENTIFIER id = DEREF_id ( exp_init_id ( a ) ) ;
493
	    if ( IS_id_variable ( id ) ) {
494
		DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
495
		if ( ( ds & dspec_temp ) && !keep_temporary ) {
496
		    /* Eliminate temporary variable */
497
		    EXP b = DEREF_exp ( exp_init_arg ( a ) ) ;
498
		    if ( IS_NULL_exp ( b ) ) {
499
			b = DEREF_exp ( id_variable_init ( id ) ) ;
500
		    }
501
		    if ( !involves_alias ( b, d ) ) {
502
			ds |= dspec_ignore ;
503
			COPY_dspec ( id_storage ( id ), ds ) ;
504
			return ( b ) ;
505
		    }
506
		}
507
	    }
508
	}
509
    }
510
    return ( e ) ;
511
}
512
 
513
 
514
/*
515
    FORCE A REFERENCE INITIALISATION
516
 
517
    This flag forces a reference to be initialised by a less cv-qualified
518
    version of the same type.  Values of greater than 1 can arise in
519
    copy constructors.
520
*/
521
 
522
int init_ref_force = 1 ;
523
 
524
 
525
/*
526
    INITIALISE A REFERENCE WITH AN LVALUE
527
 
528
    This routine checks whether e is a suitable lvalue initialiser for a
529
    reference to type t.  If so a suitably converted version of e is
530
    returned.  The null expression is returned otherwise.
531
*/
532
 
533
EXP init_ref_lvalue
534
    PROTO_N ( ( t, e, err ) )
535
    PROTO_T ( TYPE t X EXP e X ERROR *err )
536
{
537
    EXP a = NULL_exp ;
538
    if ( !IS_NULL_exp ( e ) ) {
539
	TYPE s = DEREF_type ( exp_type ( e ) ) ;
540
	CV_SPEC qual = DEREF_cv ( type_qual ( s ) ) ;
541
	if ( qual & cv_lvalue ) {
542
	    /* Check whether t is reference compatible with s */
543
	    unsigned nt = TAG_type ( t ) ;
544
	    unsigned ns = TAG_type ( s ) ;
545
	    CV_SPEC cv = cv_compare ( t, s ) ;
546
	    if ( nt == ns ) {
547
		if ( nt == type_compound_tag ) {
548
		    /* Check for base class conversions */
549
		    if ( cv == cv_none || init_ref_force ) {
550
			a = cast_class_class ( t, e, err, CAST_IMPLICIT, 1 ) ;
551
		    }
552
		} else if ( nt == type_func_tag ) {
553
		    /* Allow for overloading */
554
		    LIST ( IDENTIFIER ) pids = NULL_list ( IDENTIFIER ) ;
555
		    e = resolve_cast ( t, e, err, 1, 0, pids ) ;
556
		    if ( !IS_exp_member ( e ) ) {
557
			s = DEREF_type ( exp_type ( e ) ) ;
558
			if ( eq_type_unqual ( t, s ) ) {
559
			    if ( eq_except ( t, s ) != 2 ) {
560
				add_error ( err, ERR_except_spec_init () ) ;
561
			    }
562
			    a = e ;
563
			}
564
		    }
565
		} else {
566
		    /* Otherwise check for equal types */
567
		    if ( eq_type_unqual ( t, s ) ) {
568
			a = e ;
569
			if ( cv != cv_none ) {
570
			    add_error ( err, ERR_dcl_init_ref_qual ( cv ) ) ;
571
			}
572
		    }
573
		}
574
	    }
575
	}
576
	if ( is_templ_type ( s ) ) {
577
	    /* Allow for template parameters */
578
	    a = cast_templ_type ( t, e, CAST_IMPLICIT ) ;
579
	}
580
    }
581
    return ( a ) ;
582
}
583
 
584
 
585
/*
586
    INITIALISE A REFERENCE WITH AN RVALUE
587
 
588
    This routine checks whether e is a suitable rvalue initialiser for a
589
    reference to type t.  It is firstly checked that t is a const reference
590
    and not a reference to function.  If t is reference compatible with the
591
    type of s then a temporary is created to hold the value of e and the
592
    contents of this temporary are returned.  Otherwise the null expression
593
    is returned.
594
*/
595
 
596
static EXP init_ref_rvalue
597
    PROTO_N ( ( t, e, err ) )
598
    PROTO_T ( TYPE t X EXP e X ERROR *err )
599
{
600
    /* Check for reference to functions */
601
    CV_SPEC qual ;
602
    unsigned nt = TAG_type ( t ) ;
603
    if ( nt == type_func_tag ) {
604
	add_error ( err, ERR_dcl_init_ref_func () ) ;
605
	e = make_null_exp ( t ) ;
606
	return ( e ) ;
607
    }
608
 
609
    /* Check for const references */
610
    qual = find_cv_qual ( t ) ;
611
    qual &= cv_qual ;
612
    if ( qual != cv_const ) {
613
	int ok = 0 ;
614
	if ( !IS_NULL_exp ( e ) ) {
615
	    TYPE s = DEREF_type ( exp_type ( e ) ) ;
616
	    if ( IS_type_error ( s ) ) ok = 1 ;
617
	}
618
	if ( !ok ) add_error ( err, ERR_dcl_init_ref_const () ) ;
619
    }
620
 
621
    /* Check the initialiser */
622
    if ( !IS_NULL_exp ( e ) ) {
623
	/* Check whether t is reference compatible with s */
624
	int force = init_ref_force ;
625
	TYPE s = DEREF_type ( exp_type ( e ) ) ;
626
	unsigned ns = TAG_type ( s ) ;
627
	CV_SPEC cv = cv_compare ( t, s ) ;
628
	if ( nt == ns && ( cv == cv_none || force ) ) {
629
	    TYPE r = t ;
630
	    if ( nt == type_compound_tag ) {
631
		/* t must be a base class of s */
632
		CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
633
		CLASS_TYPE cs = DEREF_ctype ( type_compound_defn ( s ) ) ;
634
		GRAPH gr = find_base_class ( cs, ct, 1 ) ;
635
		if ( IS_NULL_graph ( gr ) ) return ( NULL_exp ) ;
636
		r = qualify_type ( s, qual, 0 ) ;
637
		/* NOT YET IMPLEMENTED: copy e */
638
	    } else {
639
		/* Otherwise check for equal types */
640
		if ( !eq_type_unqual ( t, s ) ) return ( NULL_exp ) ;
641
	    }
642
	    if ( cv != cv_none ) {
643
		/* Binding from more qualified type */
644
		add_error ( err, ERR_dcl_init_ref_qual ( cv ) ) ;
645
	    }
646
	    e = make_temporary ( r, e, NULL_exp, 1, err ) ;
647
	    if ( nt == type_compound_tag ) {
648
		/* Bind temporary to reference */
649
		e = cast_class_class ( t, e, err, CAST_IMPLICIT, 1 ) ;
650
	    }
651
	    return ( e ) ;
652
	}
653
    }
654
    return ( NULL_exp ) ;
655
}
656
 
657
 
658
/*
659
    CREATE A REFERENCE INITIALISER
660
 
661
    This routine creates a reference initialiser of type t out of the
662
    expression e.
663
*/
664
 
665
EXP make_ref_init
666
    PROTO_N ( ( t, e ) )
667
    PROTO_T ( TYPE t X EXP e )
668
{
669
    if ( !IS_NULL_exp ( e ) ) {
670
	if ( IS_exp_op ( e ) ) {
671
	    /* Allow for template parameters */
672
	    COPY_type ( exp_type ( e ), t ) ;
673
	} else {
674
	    TYPE s = t ;
675
	    unsigned tag = TAG_type ( s ) ;
676
	    if ( tag == type_ref_tag ) {
677
		s = DEREF_type ( type_ref_sub ( s ) ) ;
678
		tag = TAG_type ( s ) ;
679
	    }
680
	    if ( tag == type_token_tag && is_templ_type ( s ) ) {
681
		/* Check again later */
682
		/* EMPTY */
683
	    } else {
684
		MAKE_exp_address ( t, e, e ) ;
685
	    }
686
	}
687
    }
688
    return ( e ) ;
689
}
690
 
691
 
692
/*
693
    CREATE A NULL EXPRESSION
694
 
695
    This routine creates a null expression (i.e. all zeros) for the type t.
696
    This is the default value for a non-explicitly initialised variable with
697
    internal or external linkage.
698
*/
699
 
700
EXP make_null_exp
701
    PROTO_N ( ( t ) )
702
    PROTO_T ( TYPE t )
703
{
704
    EXP e ;
705
    switch ( TAG_type ( t ) ) {
706
	case type_integer_tag :
707
	case type_enumerate_tag : {
708
	    NAT n = small_nat [0] ;
709
	    MAKE_exp_int_lit ( t, n, exp_int_lit_tag, e ) ;
710
	    break ;
711
	}
712
	case type_floating_tag : {
713
	    FLOAT f = get_float ( t, 0 ) ;
714
	    MAKE_exp_float_lit ( t, f, e ) ;
715
	    break ;
716
	}
717
	case type_bitfield_tag : {
718
	    TYPE s = find_bitfield_type ( t ) ;
719
	    e = make_null_exp ( s ) ;
720
	    MAKE_exp_cast ( t, ( CONV_BITFIELD | CONV_REVERSE ), e, e ) ;
721
	    break ;
722
	}
723
	default : {
724
	    MAKE_exp_null ( t, e ) ;
725
	    break ;
726
	}
727
    }
728
    return ( e ) ;
729
}
730
 
731
 
732
/*
733
    CREATE A UNIT EXPRESSION
734
 
735
    This routine creates a unit expression (i.e. one) for the type t.
736
*/
737
 
738
EXP make_unit_exp
739
    PROTO_N ( ( t ) )
740
    PROTO_T ( TYPE t )
741
{
742
    EXP e ;
743
    switch ( TAG_type ( t ) ) {
744
	case type_integer_tag :
745
	case type_enumerate_tag : {
746
	    NAT n = small_nat [1] ;
747
	    MAKE_exp_int_lit ( t, n, exp_int_lit_tag, e ) ;
748
	    break ;
749
	}
750
	case type_floating_tag : {
751
	    FLOAT f = get_float ( t, 1 ) ;
752
	    MAKE_exp_float_lit ( t, f, e ) ;
753
	    break ;
754
	}
755
	case type_bitfield_tag : {
756
	    TYPE s = find_bitfield_type ( t ) ;
757
	    e = make_unit_exp ( s ) ;
758
	    MAKE_exp_cast ( t, ( CONV_BITFIELD | CONV_REVERSE ), e, e ) ;
759
	    break ;
760
	}
761
	default : {
762
	    FAIL ( Invalid unit type ) ;
763
	    MAKE_exp_null ( t, e ) ;
764
	    break ;
765
	}
766
    }
767
    return ( e ) ;
768
}
769
 
770
 
771
/*
772
    IS AN EXPRESSION NULL?
773
 
774
    This routine checks whether the expression e is a null expression.
775
*/
776
 
777
int is_null_exp
778
    PROTO_N ( ( e ) )
779
    PROTO_T ( EXP e )
780
{
781
    if ( IS_NULL_exp ( e ) ) return ( 1 ) ;
782
    switch ( TAG_exp ( e ) ) {
783
	case exp_int_lit_tag : {
784
	    NAT n = DEREF_nat ( exp_int_lit_nat ( e ) ) ;
785
	    return ( is_zero_nat ( n ) ) ;
786
	}
787
	case exp_float_lit_tag : {
788
	    FLOAT f = DEREF_flt ( exp_float_lit_flt ( e ) ) ;
789
	    return ( is_zero_float ( f ) ) ;
790
	}
791
	case exp_null_tag :
792
	case exp_zero_tag : {
793
	    return ( 1 ) ;
794
	}
795
	case exp_aggregate_tag : {
796
	    LIST ( EXP ) p = DEREF_list ( exp_aggregate_args ( e ) ) ;
797
	    while ( !IS_NULL_list ( p ) ) {
798
		EXP a = DEREF_exp ( HEAD_list ( p ) ) ;
799
		if ( !is_null_exp ( a ) ) return ( 0 ) ;
800
		p = TAIL_list ( p ) ;
801
	    }
802
	    return ( 1 ) ;
803
	}
804
	case exp_nof_tag : {
805
	    EXP a = DEREF_exp ( exp_nof_start ( e ) ) ;
806
	    EXP b = DEREF_exp ( exp_nof_pad ( e ) ) ;
807
	    EXP c = DEREF_exp ( exp_nof_end ( e ) ) ;
808
	    if ( !is_null_exp ( a ) ) return ( 0 ) ;
809
	    if ( !is_null_exp ( b ) ) return ( 0 ) ;
810
	    return ( is_null_exp ( c ) ) ;
811
	}
812
    }
813
    return ( 0 ) ;
814
}
815
 
816
 
817
/*
818
    CREATE AN EMPTY INITIALISER
819
 
820
    This routine creates an empty initialiser for the type t.  Basically
821
    this is the same as make_null_exp except that it also checks for
822
    uninitialised references and const objects.  Also if force is false
823
    then a value is only created if absolutely necessary.
824
*/
825
 
826
EXP init_empty
827
    PROTO_N ( ( t, cv, force, err ) )
828
    PROTO_T ( TYPE t X CV_SPEC cv X int force X ERROR *err )
829
{
830
    EXP e = NULL_exp ;
831
    switch ( TAG_type ( t ) ) {
832
	case type_array_tag : {
833
	    NAT n = DEREF_nat ( type_array_size ( t ) ) ;
834
	    TYPE s = DEREF_type ( type_array_sub ( t ) ) ;
835
	    e = init_empty ( s, cv, force, err ) ;
836
	    if ( !IS_NULL_exp ( e ) ) {
837
		MAKE_exp_nof ( t, NULL_exp, n, e, NULL_exp, e ) ;
838
	    }
839
	    break ;
840
	}
841
	case type_ref_tag : {
842
	    /* References must be initialised */
843
	    TYPE s = DEREF_type ( type_ref_sub ( t ) ) ;
844
	    add_error ( err, ERR_dcl_init_ref_none () ) ;
845
	    if ( IS_type_func ( s ) ) {
846
		e = make_null_exp ( s ) ;
847
	    } else {
848
		e = init_empty ( s, cv_none, 1, err ) ;
849
		e = make_temporary ( s, e, NULL_exp, 1, err ) ;
850
		e = make_ref_init ( t, e ) ;
851
	    }
852
	    break ;
853
	}
854
	case type_compound_tag : {
855
	    /* Call default constructor for classes */
856
	    e = init_default ( t, &e, DEFAULT_CONSTR, EXTRA_CONSTR, err ) ;
857
	    if ( IS_NULL_exp ( e ) ) goto default_lab ;
858
	    break ;
859
	}
860
	case type_enumerate_tag : {
861
	    if ( force ) {
862
		/* Check for zero enumerator */
863
		ENUM_TYPE et = DEREF_etype ( type_enumerate_defn ( t ) ) ;
864
		CLASS_INFO ei = DEREF_cinfo ( etype_info ( et ) ) ;
865
		if ( !( ei & cinfo_usr_constr ) ) {
866
		    add_error ( err, ERR_dcl_enum_zero ( t ) ) ;
867
		}
868
	    }
869
	    goto default_lab ;
870
	}
871
	case type_token_tag : {
872
	    if ( is_templ_type ( t ) ) {
873
		/* Allow for template parameters */
874
		if ( force ) {
875
		    MAKE_exp_op ( t, lex_cast, NULL_exp, NULL_exp, e ) ;
876
		}
877
		break ;
878
	    }
879
	    goto default_lab ;
880
	}
881
	default :
882
	default_lab : {
883
	    CV_SPEC qual = find_cv_qual ( t ) ;
884
	    qual |= cv ;
885
	    if ( qual & cv_const ) {
886
		/* Const objects must be initialised */
887
		add_error ( err, ERR_dcl_init_const () ) ;
888
	    }
889
	    if ( force ) e = make_null_exp ( t ) ;
890
	    break ;
891
	}
892
    }
893
    return ( e ) ;
894
}
895
 
896
 
897
/*
898
    LAST ARRAY INITIALISER SIZE
899
 
900
    This variable is used to hold the number of elements in the last array
901
    initialiser processed.  It is subsequently used to calculate the bound
902
    for an unbounded, but initialised, array type.
903
*/
904
 
905
static NAT last_array_size = NULL_nat ;
906
 
907
 
908
/*
909
    IS A TYPE A CHARACTER ARRAY?
910
 
911
    This routine checks whether the type t is an array of 'char', 'signed
912
    char', 'unsigned char' 'wchar_t', and so may be initialised by a single
913
    literal.  It returns 1 for character arrays, 2 for wide character
914
    arrays, and 3 for types compatible with wide character arrays.
915
*/
916
 
917
static int is_char_array
918
    PROTO_N ( ( t ) )
919
    PROTO_T ( TYPE t )
920
{
921
    if ( IS_type_array ( t ) ) {
922
	TYPE s = DEREF_type ( type_array_sub ( t ) ) ;
923
	if ( check_int_type ( s, btype_char ) ) return ( 1 ) ;
924
	if ( check_int_type ( s, btype_wchar_t ) ) return ( 2 ) ;
925
	if ( !basetype_info [ ntype_wchar_t ].key ) {
926
	    s = type_composite ( s, type_wchar_t, 1, 0, KILL_err, 0 ) ;
927
	    if ( !IS_NULL_type ( s ) ) return ( 3 ) ;
928
	}
929
    }
930
    return ( 0 ) ;
931
 
932
}
933
 
934
 
935
/*
936
    PAD AN ARRAY INITIALISER
937
 
938
    This routine pads the array initialiser e, which contains m elements,
939
    with zeros until it matches the type t.  n gives the bound size of t.
940
*/
941
 
942
static EXP pad_array
943
    PROTO_N ( ( e, m, t, n, pad, err ) )
944
    PROTO_T ( EXP e X NAT m X TYPE t X NAT n X int pad X ERROR *err )
945
{
946
    EXP a ;
947
    int eq ;
948
    unsigned long c ;
949
    ERROR err2 = NULL_err ;
950
    TYPE s = DEREF_type ( type_array_sub ( t ) ) ;
951
 
952
    /* Check for equality */
953
    eq = compare_nat ( n, m ) ;
954
    if ( eq == 0 ) {
955
	return ( e ) ;
956
    } else if ( eq == 1 ) {
957
	if ( !pad ) return ( NULL_exp ) ;
958
    } else if ( eq == -1 ) {
959
	/* Too many initialisers */
960
	if ( !pad ) return ( NULL_exp ) ;
961
	add_error ( err, ERR_dcl_init_aggr_excess ( t ) ) ;
962
	return ( e ) ;
963
    } else {
964
	/* Allow for token definitions */
965
	force_tokdef++ ;
966
	eq = eq_nat ( n, m ) ;
967
	force_tokdef-- ;
968
	if ( eq ) return ( e ) ;
969
	if ( !pad ) return ( NULL_exp ) ;
970
    }
971
 
972
    /* Find number of uninitialised elements */
973
    c = get_nat_value ( m ) ;
974
    if ( c != 0 ) {
975
	EXP en = calc_nat_value ( n, type_size_t ) ;
976
	EXP em = calc_nat_value ( m, type_size_t ) ;
977
	en = make_minus_exp ( en, em ) ;
978
	if ( IS_exp_int_lit ( en ) ) {
979
	    n = DEREF_nat ( exp_int_lit_nat ( en ) ) ;
980
	    if ( pad && c > 1 && is_calc_nat ( n ) ) {
981
		/* Warn about potentially dubious initialisers */
982
		err2 = ERR_dcl_init_aggr_array_ti ( m, t ) ;
983
	    }
984
	    c = get_nat_value ( n ) ;
985
	    if ( c == 0 ) return ( e ) ;
986
	}
987
    }
988
 
989
    /* Form initialiser */
990
    if ( IS_NULL_err ( err2 ) ) err2 = ERR_dcl_init_aggr_pad ( n, t ) ;
991
    if ( !IS_NULL_err ( err2 ) ) add_error ( err, err2 ) ;
992
    a = init_empty ( s, cv_none, 1, err ) ;
993
    if ( !IS_NULL_exp ( e ) && IS_exp_aggregate ( e ) ) {
994
	if ( c <= ARRAY_PADDING ) {
995
	    /* Explicitly pad small arrays */
996
	    LIST ( EXP ) p = DEREF_list ( exp_aggregate_args ( e ) ) ;
997
	    LIST ( EXP ) q = NULL_list ( EXP ) ;
998
	    while ( c ) {
999
		CONS_exp ( a, q, q ) ;
1000
		c-- ;
1001
	    }
1002
	    p = APPEND_list ( p, q ) ;
1003
	    COPY_list ( exp_aggregate_args ( e ), p ) ;
1004
	    COPY_type ( exp_type ( e ), t ) ;
1005
	    return ( e ) ;
1006
	}
1007
    }
1008
    MAKE_exp_nof ( t, e, n, a, NULL_exp, e ) ;
1009
    return ( e ) ;
1010
}
1011
 
1012
 
1013
/*
1014
    CHECK AN ASSIGNMENT STYLE ARRAY INITIALISER
1015
 
1016
    This routine checks the assignment style initialiser 't id = e ;' where
1017
    t is an array type.  If arr is true then e is allowed to be another
1018
    array expression of compatible type.  The routine returns the
1019
    initialising expression for id.
1020
*/
1021
 
1022
EXP init_array
1023
    PROTO_N ( ( t, cv, e, arr, err ) )
1024
    PROTO_T ( TYPE t X CV_SPEC cv X EXP e X int arr X ERROR *err )
1025
{
1026
    TYPE r = DEREF_type ( exp_type ( e ) ) ;
1027
    NAT n = DEREF_nat ( type_array_size ( t ) ) ;
1028
    TYPE s = DEREF_type ( type_array_sub ( t ) ) ;
1029
    if ( IS_type_array ( r ) ) {
1030
	unsigned tag = TAG_exp ( e ) ;
1031
	NAT m = DEREF_nat ( type_array_size ( r ) ) ;
1032
	TYPE u = DEREF_type ( type_array_sub ( r ) ) ;
1033
	if ( IS_NULL_nat ( n ) ) n = m ;
1034
	last_array_size = m ;
1035
 
1036
	/* Check for templates */
1037
	if ( in_template_decl ) {
1038
	    if ( is_templ_type ( s ) || is_templ_type ( u ) ) {
1039
		e = cast_templ_type ( t, e, CAST_IMPLICIT ) ;
1040
		return ( e ) ;
1041
	    }
1042
	}
1043
 
1044
	/* Initialisation by string literal */
1045
	if ( tag == exp_string_lit_tag ) {
1046
	    unsigned long na, ma ;
1047
	    int ca = is_char_array ( t ) ;
1048
	    STRING str = DEREF_str ( exp_string_lit_str ( e ) ) ;
1049
	    unsigned kind = DEREF_unsigned ( str_simple_kind ( str ) ) ;
1050
	    if ( kind & STRING_WIDE ) {
1051
		/* Wide string literals */
1052
		if ( ca == 2 ) {
1053
		    u = s ;
1054
		} else if ( ca == 3 ) {
1055
		    if ( IS_type_enumerate ( s ) ) {
1056
			/* It could happen ... */
1057
			EXP a ;
1058
			ENUM_TYPE es ;
1059
			MAKE_exp_value ( u, a ) ;
1060
			a = cast_int_int ( s, a, err, CAST_IMPLICIT, -1 ) ;
1061
			es = DEREF_etype ( type_enumerate_defn ( s ) ) ;
1062
			s = DEREF_type ( etype_rep ( es ) ) ;
1063
			free_exp ( a, 1 ) ;
1064
		    }
1065
		} else {
1066
		    add_error ( err, ERR_dcl_init_string_wchar () ) ;
1067
		}
1068
	    } else {
1069
		/* Normal string literals */
1070
		if ( ca == 1 ) {
1071
		    u = s ;
1072
		} else {
1073
		    add_error ( err, ERR_dcl_init_string_char () ) ;
1074
		}
1075
	    }
1076
	    if ( !EQ_type ( u, s ) ) {
1077
		/* Deal with invalid cases */
1078
		if ( IS_type_integer ( s ) ) {
1079
		    /* Cast string to appropriate type */
1080
		    MAKE_type_array ( cv_none, s, m, r ) ;
1081
		    MAKE_exp_string_lit ( r, str, e ) ;
1082
		} else {
1083
		    /* Don't take any initialisers from the string */
1084
		    e = NULL_exp ;
1085
		}
1086
	    }
1087
 
1088
	    /* Check array bound */
1089
	    na = get_nat_value ( n ) ;
1090
	    ma = get_nat_value ( m ) ;
1091
	    if ( na != EXTENDED_MAX ) {
1092
		/* Known array bounds */
1093
		if ( ma > na ) {
1094
		    /* Too many initialisers - trim string */
1095
		    if ( ma == na + 1 ) {
1096
			add_error ( err, ERR_dcl_init_string_zero ( t ) ) ;
1097
		    } else {
1098
			add_error ( err, ERR_dcl_init_string_excess ( t ) ) ;
1099
		    }
1100
		    MAKE_exp_string_lit ( t, str, e ) ;
1101
		} else if ( ma < na ) {
1102
		    /* Not enough initialisers */
1103
		    NAT d = make_nat_value ( na - ma ) ;
1104
		    add_error ( err, ERR_dcl_init_aggr_pad ( d, t ) ) ;
1105
		    MAKE_exp_string_lit ( t, str, e ) ;
1106
		}
1107
	    } else {
1108
		/* Unknown array bounds */
1109
		e = pad_array ( e, m, t, n, 1, err ) ;
1110
	    }
1111
	    return ( e ) ;
1112
	}
1113
 
1114
	/* Check array initialisers */
1115
	if ( tag == exp_token_tag ) {
1116
	    /* Allow rvalue array tokens */
1117
	    CV_SPEC qual = DEREF_cv ( type_qual ( r ) ) ;
1118
	    if ( !( qual & cv_lvalue ) ) arr = 2 ;
1119
	}
1120
	e = convert_reference ( e, REF_ASSIGN ) ;
1121
	if ( arr == 0 ) {
1122
	    /* Invalid array initialiser */
1123
	    report ( crt_loc, ERR_dcl_init_aggr_array_bad () ) ;
1124
	    if ( tag == exp_paren_tag ) {
1125
		/* Parenthesised initialiser */
1126
		e = init_array ( t, cv, e, arr, err ) ;
1127
		return ( e ) ;
1128
	    }
1129
	    arr = 1 ;
1130
	}
1131
	if ( eq_type_unqual ( s, u ) ) {
1132
	    if ( arr != 2 ) {
1133
		EXP d ;
1134
		d = init_default ( r, &e, DEFAULT_COPY, EXTRA_CONSTR, err ) ;
1135
		if ( IS_NULL_exp ( d ) ) {
1136
		    MAKE_exp_contents ( r, e, e ) ;
1137
		} else {
1138
		    MAKE_exp_preinc ( r, e, d, lex_array, e ) ;
1139
		}
1140
	    }
1141
	    e = pad_array ( e, m, t, n, arr - 1, err ) ;
1142
	    if ( !IS_NULL_exp ( e ) ) return ( e ) ;
1143
	}
1144
	add_error ( err, ERR_basic_link_incompat ( t, r ) ) ;
1145
    } else {
1146
	/* Other array initialisations are not allowed */
1147
	report ( crt_loc, ERR_dcl_init_aggr_array_bad () ) ;
1148
	last_array_size = NULL_nat ;
1149
    }
1150
    e = init_empty ( t, cv, 1, err ) ;
1151
    return ( e ) ;
1152
}
1153
 
1154
 
1155
/*
1156
    REPORT AN INITIALISATION ERROR
1157
 
1158
    In C there is no distinction between conversion by initialisation and
1159
    conversion by assignment.  This routine adds a suitable error message
1160
    to err which says that the conversion cannot be done by initialisation.
1161
*/
1162
 
1163
ERROR init_error
1164
    PROTO_N ( ( err, init ) )
1165
    PROTO_T ( ERROR err X int init )
1166
{
1167
    ERROR ferr ;
1168
#if LANGUAGE_CPP
1169
    ferr = ERR_dcl_init_conv () ;
1170
    UNUSED ( init ) ;
1171
#else
1172
    ferr = ERR_expr_ass_conv () ;
1173
    if ( init ) ferr = concat_error ( ferr, ERR_dcl_init_assign () ) ;
1174
#endif
1175
    err = concat_warning ( err, ferr ) ;
1176
    return ( err ) ;
1177
}
1178
 
1179
 
1180
/*
1181
    CHECK AN ASSIGNMENT STYLE INITIALISER
1182
 
1183
    This routine checks the assignment style initialiser 'cv t id = e ;'.
1184
    It returns a suitably converted version of e.
1185
*/
1186
 
1187
EXP init_assign
1188
    PROTO_N ( ( t, cv, e, err ) )
1189
    PROTO_T ( TYPE t X CV_SPEC cv X EXP e X ERROR *err )
1190
{
1191
    switch ( TAG_type ( t ) ) {
1192
	case type_array_tag : {
1193
	    /* Array initialisers */
1194
	    e = init_array ( t, cv, e, 0, err ) ;
1195
	    break ;
1196
	}
1197
	case type_ref_tag : {
1198
	    /* Reference initialisers */
1199
	    EXP a ;
1200
	    TYPE s = DEREF_type ( type_ref_sub ( t ) ) ;
1201
	    TYPE r = DEREF_type ( exp_type ( e ) ) ;
1202
	    if ( IS_type_compound ( r ) ) {
1203
		if ( IS_type_compound ( s ) ) {
1204
		    /* Check base class conversions first */
1205
		    a = init_ref_lvalue ( s, e, err ) ;
1206
		    if ( !IS_NULL_exp ( a ) ) {
1207
			e = make_ref_init ( t, a ) ;
1208
			break ;
1209
		    }
1210
		}
1211
		a = convert_conv_aux ( t, e, err, CAST_IMPLICIT ) ;
1212
		if ( !IS_NULL_exp ( a ) ) {
1213
		    e = a ;
1214
		    r = DEREF_type ( exp_type ( e ) ) ;
1215
		    if ( eq_type ( r, t ) ) break ;
1216
		    e = convert_reference ( e, REF_ASSIGN ) ;
1217
		}
1218
	    }
1219
	    a = init_ref_lvalue ( s, e, err ) ;
1220
	    if ( IS_NULL_exp ( a ) ) {
1221
		a = init_ref_rvalue ( s, e, err ) ;
1222
		if ( IS_NULL_exp ( a ) ) {
1223
		    e = init_assign ( s, cv_none, e, err ) ;
1224
		    if ( !IS_exp_null ( e ) ) {
1225
			e = make_temporary ( s, e, NULL_exp, 1, err ) ;
1226
		    }
1227
		} else {
1228
		    e = a ;
1229
		}
1230
	    } else {
1231
		e = a ;
1232
	    }
1233
	    e = make_ref_init ( t, e ) ;
1234
	    break ;
1235
	}
1236
	case type_compound_tag : {
1237
	    /* Class initialisers */
1238
	    TYPE s = DEREF_type ( exp_type ( e ) ) ;
1239
	    if ( IS_type_compound ( s ) ) {
1240
		/* Check for base class initialisers */
1241
		CLASS_TYPE cs = DEREF_ctype ( type_compound_defn ( s ) ) ;
1242
		CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
1243
		GRAPH gr = find_base_class ( cs, ct, 1 ) ;
1244
		if ( !IS_NULL_graph ( gr ) ) {
1245
		    e = init_direct ( t, e, err ) ;
1246
		    break ;
1247
		}
1248
	    }
1249
	    e = convert_conv ( t, e, err, CAST_IMPLICIT ) ;
1250
	    if ( !IS_exp_null ( e ) ) {
1251
		e = make_temporary ( t, e, NULL_exp, 0, err ) ;
1252
		e = init_direct ( t, e, err ) ;
1253
		e = remove_temporary ( e, NULL_exp ) ;
1254
	    }
1255
	    break ;
1256
	}
1257
	default : {
1258
	    /* Do conversion by initialisation */
1259
	    e = convert_assign ( t, e, err ) ;
1260
	    break ;
1261
	}
1262
    }
1263
    return ( e ) ;
1264
}
1265
 
1266
 
1267
/*
1268
    CHECK A CONSTRUCTOR STYLE INITIALISER
1269
 
1270
    This routine checks the constructor style initialiser 't id ( args ) ;'.
1271
    It returns an expression representing the result of converting args to
1272
    type t.
1273
*/
1274
 
1275
EXP init_constr
1276
    PROTO_N ( ( t, args, err ) )
1277
    PROTO_T ( TYPE t X LIST ( EXP ) args X ERROR *err )
1278
{
1279
    EXP e ;
1280
    unsigned tag = TAG_type ( t ) ;
1281
    switch ( tag ) {
1282
	case type_ref_tag : {
1283
	    /* Reference initialisers */
1284
	    EXP a ;
1285
	    TYPE s = DEREF_type ( type_ref_sub ( t ) ) ;
1286
	    if ( LENGTH_list ( args ) == 1 ) {
1287
		a = DEREF_exp ( HEAD_list ( args ) ) ;
1288
		a = init_ref_lvalue ( s, a, err ) ;
1289
	    } else {
1290
		a = NULL_exp ;
1291
	    }
1292
	    if ( IS_NULL_exp ( a ) ) {
1293
		a = init_ref_rvalue ( s, a, err ) ;
1294
		if ( IS_NULL_exp ( a ) ) {
1295
		    e = init_constr ( s, args, err ) ;
1296
		    if ( !IS_exp_null ( e ) ) {
1297
			e = make_temporary ( s, e, NULL_exp, 1, err ) ;
1298
		    }
1299
		} else {
1300
		    e = a ;
1301
		}
1302
	    } else {
1303
		e = a ;
1304
	    }
1305
	    e = make_ref_init ( t, e ) ;
1306
	    break ;
1307
	}
1308
	case type_compound_tag : {
1309
	    /* Class constructor initialisers */
1310
	    e = convert_constr ( t, args, err, CAST_STATIC ) ;
1311
	    e = remove_temporary ( e, NULL_exp ) ;
1312
	    break ;
1313
	}
1314
	case type_token_tag : {
1315
	    /* Check for template parameters */
1316
	    if ( is_templ_type ( t ) ) {
1317
		LIST ( OFFSET ) offs = NULL_list ( OFFSET ) ;
1318
		MAKE_exp_initialiser ( t, args, offs, 0, 0, 0, e ) ;
1319
		e = cast_templ_type ( t, e, CAST_IMPLICIT ) ;
1320
		break ;
1321
	    }
1322
	    goto default_lab ;
1323
	}
1324
	default :
1325
	default_lab : {
1326
	    /* Should have at most one argument otherwise */
1327
	    unsigned nargs = LENGTH_list ( args ) ;
1328
	    if ( nargs == 0 ) {
1329
		e = init_empty ( t, cv_none, 1, err ) ;
1330
	    } else {
1331
		EXP a = DEREF_exp ( HEAD_list ( args ) ) ;
1332
		DESTROY_list ( args, SIZE_exp ) ;
1333
		if ( nargs > 1 ) {
1334
		    /* Can't have more than one initialiser */
1335
		    add_error ( err, ERR_dcl_init_ctor ( t ) ) ;
1336
		}
1337
		if ( tag == type_array_tag ) {
1338
		    e = init_array ( t, cv_none, a, 0, err ) ;
1339
		} else {
1340
		    TYPE s = DEREF_type ( exp_type ( a ) ) ;
1341
		    if ( IS_type_compound ( s ) ) {
1342
			e = convert_conv ( t, a, err, CAST_STATIC ) ;
1343
		    } else {
1344
			e = convert_assign ( t, a, err ) ;
1345
		    }
1346
		}
1347
	    }
1348
	    break ;
1349
	}
1350
    }
1351
    return ( e ) ;
1352
}
1353
 
1354
 
1355
/*
1356
    CHECK A DIRECT INITIALISER
1357
 
1358
    This routine checks the direct initialiser 't id ( a ) ;'.  It is
1359
    a special case of init_constr in which there is only one initialiser.
1360
*/
1361
 
1362
EXP init_direct
1363
    PROTO_N ( ( t, a, err ) )
1364
    PROTO_T ( TYPE t X EXP a X ERROR *err )
1365
{
1366
    LIST ( EXP ) args ;
1367
    CONS_exp ( a, NULL_list ( EXP ), args ) ;
1368
    a = init_constr ( t, args, err ) ;
1369
    return ( a ) ;
1370
}
1371
 
1372
 
1373
/*
1374
    FIELD NAME BUFFER
1375
 
1376
    This buffer is used to build up field names for use in error reporting.
1377
*/
1378
 
1379
BUFFER field_buff = NULL_buff ;
1380
 
1381
 
1382
/*
1383
    SET LOCATION FROM AN AGGREGATE INITIALISER
1384
 
1385
    Because aggregate initialisers may be spread over several lines each
1386
    component is embedded in a location expression.  This routine gets
1387
    the first element of the aggregate list p, setting the current location
1388
    as appropriate.  It returns the tag of e (ignoring parentheses) via
1389
    ptag.
1390
*/
1391
 
1392
static EXP get_aggr_elem
1393
    PROTO_N ( ( p, ptag ) )
1394
    PROTO_T ( LIST ( EXP ) p X unsigned *ptag )
1395
{
1396
    EXP a = DEREF_exp ( HEAD_list ( p ) ) ;
1397
    if ( !IS_NULL_exp ( a ) ) {
1398
	if ( IS_exp_location ( a ) ) {
1399
	    TYPE t ;
1400
	    DESTROY_exp_location ( destroy, t, crt_loc, a, a ) ;
1401
	    UNUSED ( t ) ;
1402
	    COPY_exp ( HEAD_list ( p ), a ) ;
1403
	}
1404
	if ( !IS_NULL_exp ( a ) ) {
1405
	    EXP b = a ;
1406
	    unsigned tag = TAG_exp ( b ) ;
1407
	    while ( tag == exp_paren_tag ) {
1408
		b = DEREF_exp ( exp_paren_arg ( b ) ) ;
1409
		tag = TAG_exp ( b ) ;
1410
	    }
1411
	    *ptag = tag ;
1412
	}
1413
    }
1414
    return ( a ) ;
1415
}
1416
 
1417
 
1418
/*
1419
    CHECK AN AGGREGATE INITIALISER
1420
 
1421
    This routine checks the aggregate initialiser expression list pointed
1422
    to by r against the type t.  The argument start is 1 to indicate the
1423
    presence of a open brace immediately preceding r and 2 to indicate
1424
    the top-level aggregate.  The result is a structured aggregate
1425
    initialiser expression for compound types t or a suitably converted
1426
    initialiser expression.
1427
*/
1428
 
1429
static EXP init_aggr_aux
1430
    PROTO_N ( ( t, cv, r, start, id, err ) )
1431
    PROTO_T ( TYPE t X CV_SPEC cv X LIST ( EXP ) *r X int start X
1432
	      IDENTIFIER id X ERROR *err )
1433
{
1434
    EXP e ;
1435
    LIST ( EXP ) p = *r ;
1436
    ERROR cerr = NULL_err ;
1437
    CLASS_INFO ci = cinfo_none ;
1438
    unsigned tag = TAG_type ( t ) ;
1439
    switch ( tag ) {
1440
 
1441
	case type_array_tag : {
1442
	    /* Array types */
1443
	    NAT nc ;
1444
	    LIST ( EXP ) a = NULL_list ( EXP ) ;
1445
	    TYPE s = DEREF_type ( type_array_sub ( t ) ) ;
1446
	    int str = is_char_array ( s ) ;
1447
	    BUFFER *bf = &field_buff ;
1448
	    unsigned boff = ( unsigned ) ( bf->posn - bf->start ) ;
1449
 
1450
	    /* Find the array size */
1451
	    NAT n = DEREF_nat ( type_array_size ( t ) ) ;
1452
	    unsigned long m = get_nat_value ( n ) ;
1453
	    unsigned long c = 0 ;
1454
 
1455
	    /* Report partially bracketed initialisers */
1456
	    if ( !start ) add_error ( err, ERR_dcl_init_aggr_partial () ) ;
1457
 
1458
	    /* Check for string literals in braces */
1459
	    if ( start && !IS_NULL_list ( p ) ) {
1460
		unsigned et = null_tag ;
1461
		e = get_aggr_elem ( p, &et ) ;
1462
		if ( et == exp_string_lit_tag && is_char_array ( t ) ) {
1463
		    e = init_array ( t, cv, e, 0, err ) ;
1464
		    p = TAIL_list ( p ) ;
1465
		    break ;
1466
		}
1467
	    }
1468
 
1469
	    /* Loop through at most m initialisers */
1470
	    while ( !IS_NULL_list ( p ) && c != m ) {
1471
		LIST ( EXP ) p0 = p ;
1472
		ERROR serr = NULL_err ;
1473
		unsigned et = null_tag ;
1474
 
1475
		/* Build up the field name */
1476
		bfprintf ( bf, " [%lu]", c ) ;
1477
 
1478
		/* Check first element of aggregate */
1479
		e = get_aggr_elem ( p, &et ) ;
1480
		if ( IS_NULL_exp ( e ) ) {
1481
		    /* Can occur in template initialisers */
1482
		    e = init_empty ( s, cv_none, 1, &serr ) ;
1483
		    COPY_exp ( HEAD_list ( p ), e ) ;
1484
		}
1485
		if ( et == exp_string_lit_tag && str ) {
1486
		    /* Check for string literals */
1487
		    e = init_array ( s, cv, e, 0, &serr ) ;
1488
		    p = TAIL_list ( p ) ;
1489
		} else if ( et == exp_aggregate_tag && start ) {
1490
		    /* Check for sub-aggregates */
1491
		    LIST ( EXP ) q ;
1492
		    q = DEREF_list ( exp_aggregate_args ( e ) ) ;
1493
		    e = init_aggr_aux ( s, cv, &q, 1, id, &serr ) ;
1494
		    p = TAIL_list ( p ) ;
1495
		} else {
1496
		    /* Otherwise read constituents from p */
1497
		    e = init_aggr_aux ( s, cv, &p, 0, id, &serr ) ;
1498
		}
1499
 
1500
		/* Report any errors for this member */
1501
		if ( !IS_NULL_err ( serr ) ) {
1502
		    ERROR ferr = ERR_dcl_init_decl ( id, bf->start ) ;
1503
		    serr = concat_error ( ferr, serr ) ;
1504
		    report ( crt_loc, serr ) ;
1505
		}
1506
 
1507
		/* Check for dynamic initialisers */
1508
		e = dynamic_init ( id, bf->start, e ) ;
1509
 
1510
		/* Restore the field name */
1511
		bf->posn = bf->start + boff ;
1512
		bf->posn [0] = 0 ;
1513
 
1514
		/* Check that some initialisers were used up */
1515
		if ( EQ_list ( p, p0 ) ) break ;
1516
 
1517
		/* Build up the result (in reverse order) */
1518
		CONS_exp ( e, a, a ) ;
1519
		c++ ;
1520
	    }
1521
 
1522
	    /* Construct the result */
1523
	    a = REVERSE_list ( a ) ;
1524
	    nc = make_nat_value ( c ) ;
1525
	    MAKE_type_array ( cv_none, s, nc, s ) ;
1526
	    MAKE_exp_aggregate ( s, a, NULL_list ( OFFSET ), e ) ;
1527
 
1528
	    /* Check array size */
1529
	    if ( !IS_NULL_nat ( n ) ) {
1530
		e = pad_array ( e, nc, t, n, 1, err ) ;
1531
	    }
1532
	    last_array_size = nc ;
1533
	    break ;
1534
	}
1535
 
1536
	case type_ref_tag : {
1537
	    /* Reference types */
1538
	    TYPE s = DEREF_type ( type_ref_sub ( t ) ) ;
1539
	    e = init_ref_rvalue ( s, NULL_exp, err ) ;
1540
	    if ( IS_NULL_exp ( e ) ) {
1541
		e = init_aggr_aux ( s, cv, r, start, id, err ) ;
1542
		e = make_temporary ( s, e, NULL_exp, 1, err ) ;
1543
		e = make_ref_init ( t, e ) ;
1544
	    }
1545
	    return ( e ) ;
1546
	}
1547
 
1548
	case type_compound_tag : {
1549
	    /* Compound types */
1550
	    MEMBER mem ;
1551
	    NAMESPACE ns ;
1552
	    unsigned long pads = 0 ;
1553
	    LIST ( EXP ) a = NULL_list ( EXP ) ;
1554
	    LIST ( OFFSET ) b = NULL_list ( OFFSET ) ;
1555
	    CV_SPEC cv1 = ( DEREF_cv ( type_qual ( t ) ) | cv ) ;
1556
	    CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
1557
	    GRAPH gr = DEREF_graph ( ctype_base ( ct ) ) ;
1558
	    LIST ( GRAPH ) br = DEREF_list ( graph_tails ( gr ) ) ;
1559
	    BUFFER *bf = &field_buff ;
1560
	    unsigned boff = ( unsigned ) ( bf->posn - bf->start ) ;
1561
 
1562
	    /* Check for non-aggregate classes */
1563
	    ci = DEREF_cinfo ( ctype_info ( ct ) ) ;
1564
	    if ( !( ci & cinfo_defined ) ) {
1565
		/* Instantiate template types if necessary */
1566
		complete_class ( ct, 1 ) ;
1567
		ci = DEREF_cinfo ( ctype_info ( ct ) ) ;
1568
	    }
1569
	    if ( !( ci & cinfo_complete ) ) {
1570
		/* Incomplete types can't be initialised */
1571
		goto incomplete_lab ;
1572
	    }
1573
	    if ( ci & cinfo_non_aggregate ) {
1574
		/* Types with these properties can't be initialised */
1575
		cerr = class_info ( ct, cinfo_non_aggregate, 1 ) ;
1576
		if ( ci & cinfo_token ) goto token_lab ;
1577
		if ( ci & cinfo_usr_constr ) goto non_aggregate_lab ;
1578
		add_error ( err, cerr ) ;
1579
		add_error ( err, ERR_dcl_init_aggr_type ( t ) ) ;
1580
		cerr = NULL_err ;
1581
	    }
1582
 
1583
	    /* Check for non-aggregate initialisations */
1584
	    if ( !IS_NULL_list ( p ) ) {
1585
		unsigned rank ;
1586
		CONVERSION conv ;
1587
		unsigned et = null_tag ;
1588
		e = get_aggr_elem ( p, &et ) ;
1589
		conv.from = DEREF_type ( exp_type ( e ) ) ;
1590
		conv.to = t ;
1591
		rank = std_convert_seq ( &conv, e, 0, 0 ) ;
1592
		if ( rank != CONV_NONE ) goto non_aggregate_lab ;
1593
	    }
1594
 
1595
	    /* Report partially bracketed initialisers */
1596
	    if ( !start ) add_error ( err, ERR_dcl_init_aggr_partial () ) ;
1597
 
1598
	    /* Loop through base classes */
1599
	    while ( !IS_NULL_list ( br ) ) {
1600
		ERROR serr = NULL_err ;
1601
		GRAPH gs = DEREF_graph ( HEAD_list ( br ) ) ;
1602
		OFFSET off = DEREF_off ( graph_off ( gs ) ) ;
1603
		CLASS_TYPE cs = DEREF_ctype ( graph_head ( gs ) ) ;
1604
		TYPE s = make_class_type ( cs ) ;
1605
 
1606
		/* Build up field name */
1607
		IDENTIFIER sid = DEREF_id ( ctype_name ( cs ) ) ;
1608
		HASHID snm = DEREF_hashid ( id_name ( sid ) ) ;
1609
		if ( !IS_hashid_anon ( snm ) ) {
1610
		    bfputc ( bf, '.' ) ;
1611
		    IGNORE print_hashid ( snm, 1, 0, bf, 0 ) ;
1612
		}
1613
 
1614
		/* Check next initialiser */
1615
		if ( !IS_NULL_list ( p ) ) {
1616
		    unsigned et = null_tag ;
1617
		    e = get_aggr_elem ( p, &et ) ;
1618
		    if ( et == exp_aggregate_tag && start ) {
1619
			/* Check for sub-aggregates */
1620
			LIST ( EXP ) q ;
1621
			q = DEREF_list ( exp_aggregate_args ( e ) ) ;
1622
			e = init_aggr_aux ( s, cv1, &q, 1, id, &serr ) ;
1623
			p = TAIL_list ( p ) ;
1624
		    } else {
1625
			/* Otherwise read constituents from p */
1626
			e = init_aggr_aux ( s, cv1, &p, 0, id, &serr ) ;
1627
		    }
1628
		} else {
1629
		    e = init_empty ( s, cv1, 1, &serr ) ;
1630
		    pads++ ;
1631
		}
1632
 
1633
		/* Report any errors for this field */
1634
		if ( !IS_NULL_err ( serr ) ) {
1635
		    ERROR ferr = ERR_dcl_init_decl ( id, bf->start ) ;
1636
		    serr = concat_error ( ferr, serr ) ;
1637
		    report ( crt_loc, serr ) ;
1638
		}
1639
 
1640
		/* Check for dynamic initialisers */
1641
		e = dynamic_init ( id, bf->start, e ) ;
1642
 
1643
		/* Restore field name */
1644
		bf->posn = bf->start + boff ;
1645
		bf->posn [0] = 0 ;
1646
 
1647
		/* Build up the result (in reverse order) */
1648
		CONS_exp ( e, a, a ) ;
1649
		CONS_off ( off, b, b ) ;
1650
		br = TAIL_list ( br ) ;
1651
	    }
1652
 
1653
	    /* Find list of class members */
1654
	    ns = DEREF_nspace ( ctype_member ( ct ) ) ;
1655
	    mem = DEREF_member ( nspace_ctype_first ( ns ) ) ;
1656
	    mem = next_data_member ( mem, 0 ) ;
1657
 
1658
	    /* Loop through structure members */
1659
	    while ( !IS_NULL_member ( mem ) ) {
1660
		ERROR serr = NULL_err ;
1661
		CV_SPEC cv2 = cv1 ;
1662
		IDENTIFIER sid = DEREF_id ( member_id ( mem ) ) ;
1663
		TYPE s = DEREF_type ( id_member_type ( sid ) ) ;
1664
		DECL_SPEC ds = DEREF_dspec ( id_storage ( sid ) ) ;
1665
		OFFSET off = DEREF_off ( id_member_off ( sid ) ) ;
1666
 
1667
		/* Build up field name */
1668
		HASHID snm = DEREF_hashid ( id_name ( sid ) ) ;
1669
		if ( !IS_hashid_anon ( snm ) ) {
1670
		    bfputc ( bf, '.' ) ;
1671
		    IGNORE print_hashid ( snm, 1, 0, bf, 0 ) ;
1672
		}
1673
 
1674
		/* Adjust cv-qualifiers */
1675
		if ( ds & dspec_mutable ) cv2 = cv_none ;
1676
 
1677
		/* Check next initialiser */
1678
		if ( !IS_NULL_list ( p ) ) {
1679
		    unsigned et = null_tag ;
1680
		    e = get_aggr_elem ( p, &et ) ;
1681
		    if ( et == exp_string_lit_tag && is_char_array ( s ) ) {
1682
			/* Check for string literals */
1683
			e = init_array ( s, cv2, e, 0, &serr ) ;
1684
			p = TAIL_list ( p ) ;
1685
		    } else if ( et == exp_aggregate_tag && start ) {
1686
			/* Check for sub-aggregates */
1687
			LIST ( EXP ) q ;
1688
			q = DEREF_list ( exp_aggregate_args ( e ) ) ;
1689
			e = init_aggr_aux ( s, cv2, &q, 1, id, &serr ) ;
1690
			p = TAIL_list ( p ) ;
1691
		    } else {
1692
			/* Otherwise read constituents from p */
1693
			e = init_aggr_aux ( s, cv2, &p, 0, id, &serr ) ;
1694
		    }
1695
		} else {
1696
		    /* Pad rest of structure */
1697
		    e = init_empty ( s, cv2, 1, &serr ) ;
1698
		    pads++ ;
1699
		}
1700
 
1701
		/* Report any errors for this field */
1702
		if ( !IS_NULL_err ( serr ) ) {
1703
		    ERROR ferr = ERR_dcl_init_decl ( id, bf->start ) ;
1704
		    serr = concat_error ( ferr, serr ) ;
1705
		    report ( crt_loc, serr ) ;
1706
		}
1707
 
1708
		/* Check for dynamic initialisers */
1709
		e = dynamic_init ( id, bf->start, e ) ;
1710
 
1711
		/* Restore field name */
1712
		bf->posn = bf->start + boff ;
1713
		bf->posn [0] = 0 ;
1714
 
1715
		/* Build up the result (in reverse order) */
1716
		CONS_exp ( e, a, a ) ;
1717
		CONS_off ( off, b, b ) ;
1718
 
1719
		/* Examine next member */
1720
		if ( ci & cinfo_union ) break ;
1721
		mem = DEREF_member ( member_next ( mem ) ) ;
1722
		mem = next_data_member ( mem, 0 ) ;
1723
	    }
1724
 
1725
	    /* Report padded structures */
1726
	    if ( pads ) {
1727
		NAT n = make_nat_value ( pads ) ;
1728
		add_error ( err, ERR_dcl_init_aggr_pad ( n, t ) ) ;
1729
	    }
1730
 
1731
	    /* Construct the result */
1732
	    a = REVERSE_list ( a ) ;
1733
	    b = REVERSE_list ( b ) ;
1734
	    MAKE_exp_aggregate ( t, a, b, e ) ;
1735
	    break ;
1736
	}
1737
 
1738
	case type_integer_tag :
1739
	case type_floating_tag :
1740
	case type_enumerate_tag :
1741
	case type_ptr_tag :
1742
	case type_ptr_mem_tag : {
1743
	    /* Scalar types */
1744
	    if ( IS_NULL_list ( p ) ) {
1745
		/* Can't have empty initialiser */
1746
		add_error ( err, ERR_dcl_init_aggr_no_scalar () ) ;
1747
		e = init_empty ( t, cv, 1, err ) ;
1748
	    } else {
1749
		/* The first element must be a scalar */
1750
		unsigned et = null_tag ;
1751
		e = get_aggr_elem ( p, &et ) ;
1752
		if ( et == exp_aggregate_tag ) {
1753
		    LIST ( EXP ) q ;
1754
		    q = DEREF_list ( exp_aggregate_args ( e ) ) ;
1755
		    e = init_aggr_aux ( t, cv, &q, 1, id, err ) ;
1756
		} else {
1757
		    ERROR ferr = NULL_err ;
1758
		    if ( start == 1 ) {
1759
			/* Can only have aggregate at top level */
1760
			ferr = ERR_dcl_init_aggr_nest () ;
1761
		    }
1762
		    e = convert_reference ( e, REF_ASSIGN ) ;
1763
		    e = init_assign ( t, cv, e, &ferr ) ;
1764
		    if ( !IS_NULL_err ( ferr ) ) {
1765
			ferr = init_error ( ferr, 1 ) ;
1766
			add_error ( err, ferr ) ;
1767
		    }
1768
		}
1769
		p = TAIL_list ( p ) ;
1770
	    }
1771
	    break ;
1772
	}
1773
 
1774
	case type_token_tag :
1775
	token_lab : {
1776
	    /* Tokenised types */
1777
	    TYPE s = expand_type ( t, 0 ) ;
1778
	    if ( EQ_type ( s, t ) ) goto non_aggregate_lab ;
1779
	    e = init_aggr_aux ( s, cv, r, start, id, err ) ;
1780
	    return ( e ) ;
1781
	}
1782
 
1783
	case type_top_tag :
1784
	case type_bottom_tag :
1785
	incomplete_lab : {
1786
	    /* Incomplete types */
1787
	    add_error ( err, ERR_basic_types_incompl ( t ) ) ;
1788
	    add_error ( err, ERR_dcl_init_incompl () ) ;
1789
	    e = init_empty ( t, cv, 1, err ) ;
1790
	    break ;
1791
	}
1792
 
1793
	default :
1794
	non_aggregate_lab : {
1795
	    /* Other types */
1796
	    if ( start ) {
1797
		/* Can't have aggregate initialisers */
1798
		ERROR ferr = ERR_dcl_init_decl ( id, NULL_string ) ;
1799
		ferr = concat_error ( ferr, cerr ) ;
1800
		ferr = concat_error ( ferr, ERR_dcl_init_aggr_type ( t ) ) ;
1801
		report ( crt_loc, ferr ) ;
1802
		if ( ci & cinfo_usr_constr ) {
1803
		    /* Map to constructor call */
1804
		    LIST ( EXP ) q = p ;
1805
		    while ( !IS_NULL_list ( q ) ) {
1806
			unsigned et = null_tag ;
1807
			IGNORE get_aggr_elem ( q, &et ) ;
1808
			q = TAIL_list ( q ) ;
1809
		    }
1810
		    e = init_constr ( t, p, err ) ;
1811
		    return ( e ) ;
1812
		}
1813
	    } else {
1814
		if ( !IS_NULL_err ( cerr ) ) destroy_error ( cerr, 1 ) ;
1815
	    }
1816
	    if ( IS_NULL_list ( p ) ) {
1817
		/* Empty initialiser list */
1818
		e = init_empty ( t, cv, 1, err ) ;
1819
	    } else {
1820
		/* Get next initialiser from list */
1821
		unsigned et = null_tag ;
1822
		e = get_aggr_elem ( p, &et ) ;
1823
		if ( et == exp_aggregate_tag ) {
1824
		    LIST ( EXP ) q ;
1825
		    q = DEREF_list ( exp_aggregate_args ( e ) ) ;
1826
		    e = init_aggr_aux ( t, cv, &q, 1, id, err ) ;
1827
		} else {
1828
		    e = convert_reference ( e, REF_ASSIGN ) ;
1829
		    if ( tag == type_token_tag && is_zero_exp ( e ) ) {
1830
			/* Special concession to tokenised types */
1831
			e = init_empty ( t, cv, 1, err ) ;
1832
		    } else {
1833
			ERROR ferr = NULL_err ;
1834
			e = init_assign ( t, cv, e, &ferr ) ;
1835
			if ( !IS_NULL_err ( ferr ) ) {
1836
			    ferr = init_error ( ferr, 1 ) ;
1837
			    add_error ( err, ferr ) ;
1838
			}
1839
		    }
1840
		}
1841
		p = TAIL_list ( p ) ;
1842
	    }
1843
	    break ;
1844
	}
1845
    }
1846
 
1847
    /* Check for end of initialiser list */
1848
    if ( start && !IS_NULL_list ( p ) ) {
1849
	ERROR ferr = ERR_dcl_init_decl ( id, NULL_string ) ;
1850
	ferr = concat_error ( ferr, ERR_dcl_init_aggr_excess ( t ) ) ;
1851
	report ( crt_loc, ferr ) ;
1852
	p = NULL_list ( EXP ) ;
1853
    }
1854
    *r = p ;
1855
    return ( e ) ;
1856
}
1857
 
1858
 
1859
/*
1860
    CHECK AN AGGREGATE INITIALISER
1861
 
1862
    This is the top-level routine for analysing the aggregate initialiser
1863
    e for the object id of type t.  Any errors are added to err.
1864
*/
1865
 
1866
EXP init_aggregate
1867
    PROTO_N ( ( t, e, id, err ) )
1868
    PROTO_T ( TYPE t X EXP e X IDENTIFIER id X ERROR *err )
1869
{
1870
    LOCATION loc ;
1871
    LIST ( EXP ) args = DEREF_list ( exp_aggregate_args ( e ) ) ;
1872
    if ( IS_NULL_list ( args ) ) {
1873
	/* Report empty aggregate initialisers */
1874
	add_error ( err, ERR_dcl_init_aggr_empty () ) ;
1875
    }
1876
    bad_crt_loc++ ;
1877
    loc = crt_loc ;
1878
    IGNORE clear_buffer ( &field_buff, NIL ( FILE ) ) ;
1879
    e = init_aggr_aux ( t, cv_none, &args, 2, id, err ) ;
1880
    crt_loc = loc ;
1881
    bad_crt_loc-- ;
1882
    return ( e ) ;
1883
}
1884
 
1885
 
1886
/*
1887
    CHECK ANY INITIALISER
1888
 
1889
    This routine calls init_assign, init_constr or init_aggregate depending
1890
    on the value of e.  If tentative is true then an absent initialiser
1891
    (i.e. when e is null) is treated as a tentative definition.
1892
*/
1893
 
1894
EXP init_general
1895
    PROTO_N ( ( t, e, id, tentative ) )
1896
    PROTO_T ( TYPE t X EXP e X IDENTIFIER id X int tentative )
1897
{
1898
    /* Check the initialiser */
1899
    ERROR err = NULL_err ;
1900
    if ( IS_NULL_exp ( e ) ) {
1901
	/* Empty initialisers */
1902
	DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
1903
	if ( ds & dspec_auto ) {
1904
	    e = init_empty ( t, cv_none, 0, &err ) ;
1905
	} else if ( tentative ) {
1906
	    MAKE_exp_zero ( t, e ) ;
1907
	} else {
1908
	    e = init_empty ( t, cv_none, 1, &err ) ;
1909
	}
1910
    } else {
1911
	switch ( TAG_exp ( e ) ) {
1912
	    case exp_aggregate_tag : {
1913
		/* Aggregate initialisers */
1914
		if ( is_templ_type ( t ) ) {
1915
		    e = cast_templ_type ( t, e, CAST_IMPLICIT ) ;
1916
		} else {
1917
		    e = init_aggregate ( t, e, id, &err ) ;
1918
		}
1919
		break ;
1920
	    }
1921
	    case exp_nof_tag : {
1922
		/* Padded aggregate initialisers */
1923
		e = DEREF_exp ( exp_nof_start ( e ) ) ;
1924
		e = init_general ( t, e, id, 0 ) ;
1925
		return ( e ) ;
1926
	    }
1927
	    case exp_initialiser_tag : {
1928
		/* Function style initialisers */
1929
		LIST ( EXP ) args ;
1930
		args = DEREF_list ( exp_initialiser_args ( e ) ) ;
1931
		args = convert_args ( args ) ;
1932
		e = init_constr ( t, args, &err ) ;
1933
		if ( !IS_NULL_err ( err ) ) err = init_error ( err, 1 ) ;
1934
		break ;
1935
	    }
1936
	    default : {
1937
		/* Simple initialisers */
1938
		unsigned etag = TAG_exp ( e ) ;
1939
		e = convert_reference ( e, REF_ASSIGN ) ;
1940
		if ( etag == exp_paren_tag && IS_type_array ( t ) ) {
1941
		    e = make_paren_exp ( e ) ;
1942
		}
1943
		e = init_assign ( t, cv_none, e, &err ) ;
1944
		if ( !IS_NULL_err ( err ) ) err = init_error ( err, 1 ) ;
1945
		break ;
1946
	    }
1947
	}
1948
    }
1949
 
1950
    /* Report any errors */
1951
    if ( !IS_NULL_err ( err ) ) {
1952
	ERROR ferr = ERR_dcl_init_decl ( id, NULL_string ) ;
1953
	err = concat_error ( ferr, err ) ;
1954
	report ( crt_loc, err ) ;
1955
    }
1956
 
1957
    /* Check for dynamic initialisers */
1958
    if ( !IS_NULL_exp ( e ) ) {
1959
	e = dynamic_init ( id, NULL_string, e ) ;
1960
    }
1961
    return ( e ) ;
1962
}
1963
 
1964
 
1965
/*
1966
    DESTROY AN OBJECT
1967
 
1968
    This routine creates a destructor for the object id of type t,
1969
    reporting any errors.
1970
*/
1971
 
1972
EXP destroy_general
1973
    PROTO_N ( ( t, id ) )
1974
    PROTO_T ( TYPE t X IDENTIFIER id )
1975
{
1976
    EXP d = NULL_exp ;
1977
    int du = do_usage ;
1978
    ERROR err = NULL_err ;
1979
    do_usage = 0 ;
1980
    d = init_default ( t, &d, DEFAULT_DESTR, EXTRA_DESTR, &err ) ;
1981
    if ( !IS_NULL_err ( err ) ) {
1982
	/* Report any destructor errors */
1983
	ERROR ferr = ERR_dcl_init_decl ( id, NULL_string ) ;
1984
	err = concat_error ( ferr, err ) ;
1985
	report ( decl_loc, err ) ;
1986
    }
1987
    do_usage = du ;
1988
    return ( d ) ;
1989
}
1990
 
1991
 
1992
/*
1993
    INITIALISE AN OBJECT
1994
 
1995
    This routine initialises the object given by id to the value e.  Note
1996
    that e can be the null expression, indicating that no initialiser is
1997
    given.  The routine 1 if the object is defined, 2 if it is tentatively
1998
    defined, and 0 if it is just declared (see dump_declare).
1999
*/
2000
 
2001
int init_object
2002
    PROTO_N ( ( id, e ) )
2003
    PROTO_T ( IDENTIFIER id X EXP e )
2004
{
2005
    EXP d ;
2006
    TYPE t ;
2007
    int def = 0 ;
2008
    unsigned tag ;
2009
    DECL_SPEC ds ;
2010
    unsigned itag ;
2011
    int ignore = 0 ;
2012
 
2013
    /* Check for non-object declarations */
2014
    if ( IS_NULL_id ( id ) ) return ( 0 ) ;
2015
    itag = TAG_id ( id ) ;
2016
    switch ( itag ) {
2017
 
2018
	case id_variable_tag :
2019
	case id_stat_member_tag : {
2020
	    /* Variables and static data members */
2021
	    break ;
2022
	}
2023
 
2024
	case id_parameter_tag : {
2025
	    /* Function parameters */
2026
	    if ( !in_default_arg ) {
2027
		if ( !IS_NULL_exp ( e ) ) {
2028
		    report ( crt_loc, ERR_dcl_fct_default_weak ( id ) ) ;
2029
		}
2030
		return ( 0 ) ;
2031
	    }
2032
	    break ;
2033
	}
2034
 
2035
	case id_function_tag :
2036
	case id_mem_func_tag :
2037
	case id_stat_mem_func_tag : {
2038
	    /* Check for function declarations */
2039
	    if ( !IS_NULL_exp ( e ) ) {
2040
		/* Can't initialise functions */
2041
		report ( crt_loc, ERR_dcl_init_func ( id ) ) ;
2042
	    }
2043
 
2044
	    /* Check previous definition */
2045
	    d = DEREF_exp ( id_function_etc_defn ( id ) ) ;
2046
	    if ( !IS_NULL_exp ( d ) ) {
2047
		ds = DEREF_dspec ( id_storage ( id ) ) ;
2048
		ds |= dspec_defn ;
2049
		COPY_dspec ( id_storage ( id ), ds ) ;
2050
	    }
2051
	    return ( 0 ) ;
2052
	}
2053
 
2054
	case id_member_tag : {
2055
	    /* Check for non-static members (shouldn't be reached) */
2056
	    report ( crt_loc, ERR_class_mem_init_mem ( id ) ) ;
2057
	    return ( 0 ) ;
2058
	}
2059
 
2060
	default : {
2061
	    /* The declaration could have been a typedef */
2062
	    if ( !IS_NULL_exp ( e ) ) {
2063
		/* Can't initialise a typedef */
2064
		report ( crt_loc, ERR_dcl_init_typedef ( id ) ) ;
2065
	    }
2066
	    return ( 1 ) ;
2067
	}
2068
    }
2069
 
2070
    /* Get declaration data */
2071
    t = DEREF_type ( id_variable_etc_type ( id ) ) ;
2072
    tag = TAG_type ( t ) ;
2073
    ds = DEREF_dspec ( id_storage ( id ) ) ;
2074
    temp_storage = ( ds & dspec_storage ) ;
2075
 
2076
    /* Check array initialisers */
2077
    if ( tag == type_array_tag ) {
2078
	int chk = 0 ;
2079
	if ( !IS_NULL_exp ( e ) ) {
2080
	    /* Initialisation of array types */
2081
	    NAT n = DEREF_nat ( type_array_size ( t ) ) ;
2082
	    if ( ( ds & dspec_auto ) && itag == id_variable_tag ) {
2083
		/* Local aggregate initialiser */
2084
		report ( crt_loc, ERR_dcl_init_aggr_auto ( id ) ) ;
2085
	    }
2086
	    last_array_size = NULL_nat ;
2087
	    e = init_general ( t, e, id, 0 ) ;
2088
	    if ( IS_NULL_nat ( n ) ) {
2089
		/* Complete unbounded arrays */
2090
		n = last_array_size ;
2091
		if ( !IS_NULL_nat ( n ) ) {
2092
		    CV_SPEC qual = DEREF_cv ( type_qual ( t ) ) ;
2093
		    TYPE s = DEREF_type ( type_array_sub ( t ) ) ;
2094
		    n = check_array_dim ( n ) ;
2095
		    MAKE_type_array ( qual, s, n, t ) ;
2096
		    COPY_type ( id_variable_etc_type ( id ), t ) ;
2097
		}
2098
	    }
2099
	    ds |= dspec_defn ;
2100
	    chk = 1 ;
2101
	} else {
2102
	    /* Allow for tentative definitions */
2103
	    if ( ds & dspec_defn ) chk = LANGUAGE_CPP ;
2104
	}
2105
 
2106
	/* Can only spot incomplete arrays at this stage */
2107
	if ( chk ) {
2108
	    ERROR err = check_complete ( t ) ;
2109
	    if ( !IS_NULL_err ( err ) ) {
2110
		ERROR err2 = ERR_basic_types_def_incompl ( id ) ;
2111
		err = concat_error ( err, err2 ) ;
2112
		report ( decl_loc, err ) ;
2113
	    }
2114
	}
2115
 
2116
    } else {
2117
	/* Other initialisers */
2118
	if ( !IS_NULL_exp ( e ) ) {
2119
	    if ( tag == type_compound_tag ) {
2120
		if ( ( ds & dspec_auto ) && itag == id_variable_tag ) {
2121
		    /* Local aggregate initialiser */
2122
		    report ( crt_loc, ERR_dcl_init_aggr_auto ( id ) ) ;
2123
		}
2124
	    }
2125
	    if ( ds & dspec_defn ) {
2126
		/* Type already check for completeness */
2127
		/* EMPTY */
2128
	    } else if ( tag == type_ref_tag ) {
2129
		/* Reference types don't need checking */
2130
		/* EMPTY */
2131
	    } else {
2132
		/* Type not yet checked for completeness */
2133
		ERROR err = check_complete ( t ) ;
2134
		if ( !IS_NULL_err ( err ) ) {
2135
		    ERROR err2 = ERR_basic_types_def_incompl ( id ) ;
2136
		    err = concat_error ( err, err2 ) ;
2137
		    report ( decl_loc, err ) ;
2138
		}
2139
		ds |= dspec_defn ;
2140
	    }
2141
 
2142
	    /* Examine initialiser */
2143
	    e = init_general ( t, e, id, 0 ) ;
2144
	}
2145
    }
2146
 
2147
    /* Check on definition */
2148
    if ( ds & dspec_stat_inline ) {
2149
	/* Check for definitions of inline static members */
2150
	if ( ds & dspec_defn ) {
2151
	    if ( !IS_NULL_exp ( e ) ) {
2152
		/* Can't give a value in the definition */
2153
		PTR ( LOCATION ) loc = id_loc ( id ) ;
2154
		report ( decl_loc, ERR_class_static_data_def ( id, loc ) ) ;
2155
	    } else {
2156
		/* Force definition to existing value */
2157
		e = DEREF_exp ( id_variable_etc_init ( id ) ) ;
2158
	    }
2159
	    /* Mark as defined and no longer inline */
2160
	    ds &= ~dspec_stat_inline ;
2161
	}
2162
 
2163
    } else {
2164
	/* Provide default definition if necessary */
2165
	if ( ds & dspec_defn ) {
2166
	    def = 1 ;
2167
	    if ( IS_NULL_exp ( e ) ) {
2168
		e = init_general ( t, e, id, LANGUAGE_C ) ;
2169
		if ( !IS_NULL_exp ( e ) && IS_exp_zero ( e ) ) def = 2 ;
2170
	    }
2171
	}
2172
 
2173
	/* Check previous definition */
2174
	d = DEREF_exp ( id_variable_etc_init ( id ) ) ;
2175
	if ( !IS_NULL_exp ( d ) ) {
2176
	    if ( !IS_NULL_exp ( e ) ) {
2177
		/* Defined twice */
2178
		ERROR err ;
2179
		PTR ( LOCATION ) loc = id_loc ( id ) ;
2180
		if ( def == 2 ) {
2181
		    /* This definition is tentative */
2182
		    err = ERR_basic_odr_tentative ( id, loc ) ;
2183
		    ignore = 1 ;
2184
		} else if ( IS_exp_zero ( d ) ) {
2185
		    /* Previous definition was tentative */
2186
		    err = ERR_basic_odr_tentative ( id, loc ) ;
2187
		} else {
2188
		    /* Neither definition is tentative */
2189
		    err = ERR_basic_odr_def ( id, loc ) ;
2190
		}
2191
		report ( decl_loc, err ) ;
2192
	    }
2193
	    ds |= dspec_defn ;
2194
	}
2195
    }
2196
 
2197
    /* Update declaration data */
2198
    COPY_type ( id_variable_etc_type ( id ), t ) ;
2199
    COPY_dspec ( id_storage ( id ), ds ) ;
2200
    if ( !IS_NULL_exp ( e ) ) {
2201
	/* Define object */
2202
	if ( !ignore ) {
2203
	    if ( ( ds & dspec_auto ) && ( ds & dspec_used ) ) {
2204
		/* Local variable initialised in terms of itself */
2205
		TYPE s = DEREF_type ( exp_type ( e ) ) ;
2206
		MAKE_exp_dynamic ( s, e, e ) ;
2207
	    }
2208
	    if ( itag != id_parameter_tag ) e = check_init ( e ) ;
2209
	    COPY_exp ( id_variable_etc_init ( id ), e ) ;
2210
	    COPY_loc ( id_loc ( id ), decl_loc ) ;
2211
	    define_id ( id ) ;
2212
	}
2213
	if ( ds & dspec_linkage ) {
2214
	    /* Check enclosing namespace */
2215
	    NAMESPACE ns = DEREF_nspace ( id_parent ( id ) ) ;
2216
	    check_decl_nspace ( id, ns, 1, crt_namespace ) ;
2217
	}
2218
	if ( def == 0 ) def = 1 ;
2219
    }
2220
    if ( def ) {
2221
	/* Create destructor */
2222
	EXP d1 = DEREF_exp ( id_variable_etc_term ( id ) ) ;
2223
	d = destroy_general ( t, id ) ;
2224
	if ( !IS_NULL_exp ( d1 ) && IS_exp_paren ( d1 ) ) {
2225
	    /* Preserve parenthesised type information */
2226
	    TYPE t1 = DEREF_type ( exp_type ( d1 ) ) ;
2227
	    MAKE_exp_paren ( t1, d, d ) ;
2228
	}
2229
	COPY_exp ( id_variable_etc_term ( id ), d ) ;
2230
    }
2231
    if ( !IS_NULL_id ( unify_id_pending ) ) {
2232
	/* Deal with any pending identifiers */
2233
	IGNORE unify_id ( unify_id_pending, id, 1 ) ;
2234
    }
2235
    temp_storage = dspec_auto ;
2236
    if ( def && !( ds & dspec_auto ) ) {
2237
	if ( !really_in_function_defn && !in_template_decl ) {
2238
	    /* Compile variable definition */
2239
	    compile_variable ( id, 0 ) ;
2240
	}
2241
    }
2242
    return ( def ) ;
2243
}
2244
 
2245
 
2246
/*
2247
    INITIALISE A FUNCTION PARAMETER
2248
 
2249
    This routine initialises the function parameter id with the expression
2250
    e (i.e. sets up a default argument value).  Note that the class
2251
    definition case, where e is initially just skipped over, is dealt
2252
    with here.
2253
*/
2254
 
2255
void init_param
2256
    PROTO_N ( ( id, e ) )
2257
    PROTO_T ( IDENTIFIER id X EXP e )
2258
{
2259
    if ( !IS_NULL_exp ( e ) ) {
2260
	if ( !IS_NULL_id ( id ) ) {
2261
	    if ( IS_id_token ( id ) ) {
2262
		/* Template parameter */
2263
		init_exp_param ( id, e ) ;
2264
	    } else {
2265
		/* Function parameter */
2266
		if ( IS_exp_uncompiled ( e ) ) {
2267
		    if ( in_class_defn ) {
2268
			LIST ( IDENTIFIER ) ft ;
2269
			CLASS_TYPE ct = crt_class ;
2270
			ft = DEREF_list ( ctype_nest ( ct ) ) ;
2271
			CONS_id ( id, ft, ft ) ;
2272
			COPY_list ( ctype_nest ( ct ), ft ) ;
2273
		    }
2274
		    COPY_exp ( id_parameter_init ( id ), e ) ;
2275
		} else {
2276
		    in_default_arg++ ;
2277
		    IGNORE init_object ( id, e ) ;
2278
		    in_default_arg-- ;
2279
		}
2280
	    }
2281
	}
2282
    }
2283
    return ;
2284
}
2285
 
2286
 
2287
/*
2288
    INITIALISE A CLASS MEMBER
2289
 
2290
    This routine initialises the class member id with the expression e
2291
    (which since it is a constant-expression has already undergone the
2292
    appropriate operand conversions).  Note that the pure specifier is
2293
    indistinguishible syntactically from a member initialiser, and so is
2294
    only spotted at this stage.  See above for inline definitions of static
2295
    data members.  The routine returns 1 for a definition and 0 for a
2296
    declaration (see dump_declare).
2297
*/
2298
 
2299
int init_member
2300
    PROTO_N ( ( id, e ) )
2301
    PROTO_T ( IDENTIFIER id X EXP e )
2302
{
2303
    int def ;
2304
    unsigned tag ;
2305
 
2306
    /* Check for definitions */
2307
    if ( IS_NULL_id ( id ) ) return ( 0 ) ;
2308
    tag = TAG_id ( id ) ;
2309
    if ( have_access_decl ) {
2310
	def = 2 ;
2311
	have_access_decl = 0 ;
2312
    } else {
2313
	switch ( tag ) {
2314
	    case id_stat_member_tag :
2315
	    case id_mem_func_tag :
2316
	    case id_stat_mem_func_tag : {
2317
		def = 0 ;
2318
		break ;
2319
	    }
2320
	    default : {
2321
		def = 1 ;
2322
		break ;
2323
	    }
2324
	}
2325
    }
2326
 
2327
    /* Check for function declarations */
2328
    if ( IS_NULL_exp ( e ) ) {
2329
	if ( tag == id_mem_func_tag || tag == id_stat_mem_func_tag ) {
2330
	    if ( really_in_function_defn ) {
2331
		NAMESPACE ns = DEREF_nspace ( id_parent ( id ) ) ;
2332
		if ( EQ_nspace ( ns, crt_namespace ) ) {
2333
		    DECL_SPEC ds, mds ;
2334
		    ds = DEREF_dspec ( id_storage ( id ) ) ;
2335
		    mds = ( dspec_inherit | dspec_implicit | dspec_defn ) ;
2336
		    if ( !( ds & mds ) ) {
2337
			/* Local functions should be defined */
2338
			report ( decl_loc, ERR_class_local_func ( id ) ) ;
2339
		    }
2340
		}
2341
	    }
2342
	}
2343
	return ( def ) ;
2344
    }
2345
 
2346
    /* Check the various types of member */
2347
    switch ( tag ) {
2348
 
2349
	case id_stat_member_tag : {
2350
	    /* Static data members may be initialised */
2351
	    DECL_SPEC ds ;
2352
	    TYPE t = DEREF_type ( id_stat_member_type ( id ) ) ;
2353
	    CV_SPEC cv = find_cv_qual ( t ) ;
2354
	    switch ( TAG_type ( t ) ) {
2355
		case type_integer_tag :
2356
		case type_enumerate_tag : {
2357
		    ERROR err = NULL_err ;
2358
		    IGNORE make_nat_exp ( e, &err ) ;
2359
		    if ( !IS_NULL_err ( err ) ) {
2360
			/* Initialiser should be a constant expression */
2361
			ERROR err2 = ERR_class_mem_init_const () ;
2362
			err = concat_error ( err, err2 ) ;
2363
			report ( crt_loc, err ) ;
2364
		    }
2365
		    break ;
2366
		}
2367
		case type_token_tag : {
2368
		    if ( !is_templ_type ( t ) ) goto default_lab ;
2369
		    break ;
2370
		}
2371
		default :
2372
		default_lab : {
2373
		    /* Only integral types allowed */
2374
		    report ( crt_loc, ERR_class_static_data_init ( id, t ) ) ;
2375
		    break ;
2376
		}
2377
	    }
2378
	    if ( cv != ( cv_const | cv_lvalue ) ) {
2379
		/* Only const types allowed */
2380
		report ( crt_loc, ERR_class_static_data_const ( id, t ) ) ;
2381
	    }
2382
	    e = init_general ( t, e, id, 0 ) ;
2383
	    e = dynamic_init ( id, NULL_string, e ) ;
2384
	    e = check_init ( e ) ;
2385
	    COPY_exp ( id_stat_member_init ( id ), e ) ;
2386
 
2387
	    /* Mark inline member definition */
2388
	    ds = DEREF_dspec ( id_storage ( id ) ) ;
2389
	    ds |= dspec_stat_inline ;
2390
	    COPY_dspec ( id_storage ( id ), ds ) ;
2391
	    break ;
2392
	}
2393
 
2394
	case id_mem_func_tag :
2395
	case id_stat_mem_func_tag : {
2396
	    /* Check for pure specifiers */
2397
	    if ( is_zero_exp ( e ) ) {
2398
		DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
2399
		if ( ds & dspec_virtual ) {
2400
		    CLASS_TYPE ct = crt_class ;
2401
		    CLASS_INFO ci = DEREF_cinfo ( ctype_info ( ct ) ) ;
2402
 
2403
		    /* Pure specifier should be precisely '0' */
2404
		    int tok = last_lex_token ;
2405
		    if ( tok != lex_integer_Hexp || is_literal ( e ) != 2 ) {
2406
			report ( crt_loc, ERR_class_abstract_zero () ) ;
2407
		    }
2408
 
2409
		    /* Mark class as abstract */
2410
		    ci |= cinfo_abstract ;
2411
		    COPY_cinfo ( ctype_info ( ct ), ci ) ;
2412
 
2413
		    /* Mark function as pure */
2414
		    ds |= dspec_pure ;
2415
		    COPY_dspec ( id_storage ( id ), ds ) ;
2416
		} else {
2417
		    /* Only virtual functions can be pure */
2418
		    report ( crt_loc, ERR_class_abstract_virt () ) ;
2419
		}
2420
	    } else {
2421
		/* Can't initialise functions otherwise */
2422
		report ( crt_loc, ERR_dcl_init_func ( id ) ) ;
2423
	    }
2424
	    break ;
2425
	}
2426
 
2427
	case id_member_tag : {
2428
	    /* Can't initialise non-static members */
2429
	    report ( crt_loc, ERR_class_mem_init_mem ( id ) ) ;
2430
	    break ;
2431
	}
2432
 
2433
	default : {
2434
	    /* Can't initialise a typedef */
2435
	    report ( crt_loc, ERR_dcl_init_typedef ( id ) ) ;
2436
	    break ;
2437
	}
2438
    }
2439
    return ( def ) ;
2440
}
2441
 
2442
 
2443
/*
2444
    ALLOW A TOKEN AS AN INITIALISER
2445
 
2446
    This routine enables the token id as an initialiser.
2447
*/
2448
 
2449
void allow_initialiser
2450
    PROTO_N ( ( id ) )
2451
    PROTO_T ( IDENTIFIER id )
2452
{
2453
    id = find_token ( id ) ;
2454
    if ( IS_id_token ( id ) ) {
2455
	/* NOT YET IMPLEMENTED */
2456
	/* EMPTY */
2457
    } else {
2458
	report ( crt_loc, ERR_token_undecl ( id ) ) ;
2459
    }
2460
    return ;
2461
}
2462
 
2463
 
2464
/*
2465
    INITIALISE THE FIELD BUFFER
2466
 
2467
    This routine initialises the field buffer.
2468
*/
2469
 
2470
void init_initialise
2471
    PROTO_Z ()
2472
{
2473
    field_buff.posn = extend_buffer ( &field_buff, field_buff.posn ) ;
2474
    return ;
2475
}