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

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

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

Subversion Repositories tendra.SVN

Rev

Rev 2 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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