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

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

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

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

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

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

Subversion Repositories tendra.SVN

Rev

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

Rev 5 Rev 6
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2006 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997, 1998
32
    		 Crown Copyright (c) 1997, 1998
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
Line 79... Line 109...
79
#include "token.h"
109
#include "token.h"
80
 
110
 
81
 
111
 
82
/*
112
/*
83
    SET AN INFERRED FUNCTION RETURN TYPE
113
    SET AN INFERRED FUNCTION RETURN TYPE
84
 
114
 
85
    If t is a function type with an inferred return type then the actual
115
    If t is a function type with an inferred return type then the actual
86
    return type is set according to id.  The routine returns the original
116
    return type is set according to id.  The routine returns the original
87
    inferred return type.
117
    inferred return type.
88
*/
118
*/
89
 
119
 
90
TYPE inferred_return
120
TYPE
91
    PROTO_N ( ( t, id ) )
-
 
92
    PROTO_T ( TYPE t X IDENTIFIER id )
121
inferred_return(TYPE t, IDENTIFIER id)
93
{
122
{
94
    if ( IS_type_func ( t ) ) {
123
	if (IS_type_func(t)) {
95
	TYPE r = DEREF_type ( type_func_ret ( t ) ) ;
124
		TYPE r = DEREF_type(type_func_ret(t));
96
	if ( is_type_inferred ( r ) == INFERRED_EMPTY ) {
125
		if (is_type_inferred(r) == INFERRED_EMPTY) {
97
	    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
126
			HASHID nm = DEREF_hashid(id_name(id));
98
	    switch ( TAG_hashid ( nm ) ) {
127
			switch (TAG_hashid(nm)) {
99
		case hashid_constr_tag :
128
			case hashid_constr_tag:
100
		case hashid_destr_tag : {
129
			case hashid_destr_tag: {
101
		    /* Constructors and destructors */
130
				/* Constructors and destructors */
102
		    COPY_type ( type_func_ret ( t ), type_void ) ;
131
				COPY_type(type_func_ret(t), type_void);
103
		    break ;
132
				break;
104
		}
133
			}
105
		case hashid_conv_tag : {
134
			case hashid_conv_tag: {
106
		    /* Conversion functions */
135
				/* Conversion functions */
107
		    TYPE s = DEREF_type ( hashid_conv_type ( nm ) ) ;
136
				TYPE s = DEREF_type(hashid_conv_type(nm));
108
		    COPY_type ( type_func_ret ( t ), s ) ;
137
				COPY_type(type_func_ret(t), s);
109
		    break ;
138
				break;
-
 
139
			}
-
 
140
			}
-
 
141
			return (r);
110
		}
142
		}
111
	    }
-
 
112
	    return ( r ) ;
-
 
113
	}
143
	}
114
    }
-
 
115
    return ( NULL_type ) ;
144
	return (NULL_type);
116
}
145
}
117
 
146
 
118
 
147
 
119
/*
148
/*
120
    CHECK A COPY CONSTRUCTOR OR ASSIGNMENT OPERATOR TYPE
149
    CHECK A COPY CONSTRUCTOR OR ASSIGNMENT OPERATOR TYPE
Line 124... Line 153...
124
    [volatile] ct' with any subsequent parameters being optional.  It
153
    [volatile] ct' with any subsequent parameters being optional.  It
125
    returns 1, 2 and 3 respectively in these cases, or 0 if fn does not
154
    returns 1, 2 and 3 respectively in these cases, or 0 if fn does not
126
    match this description.
155
    match this description.
127
*/
156
*/
128
 
157
 
129
static int check_copy_constr
158
static int
130
    PROTO_N ( ( fn, ct ) )
-
 
131
    PROTO_T ( TYPE fn X CLASS_TYPE ct )
159
check_copy_constr(TYPE fn, CLASS_TYPE ct)
132
{
160
{
133
    int c = 0 ;
161
	int c = 0;
134
    if ( IS_type_templ ( fn ) ) {
162
	if (IS_type_templ(fn)) {
135
	/* Allow for template constructors */
163
		/* Allow for template constructors */
136
	in_template_decl++ ;
164
		in_template_decl++;
137
	fn = DEREF_type ( type_templ_defn ( fn ) ) ;
165
		fn = DEREF_type(type_templ_defn(fn));
138
	c = check_copy_constr ( fn, ct ) ;
166
		c = check_copy_constr(fn, ct);
139
	in_template_decl-- ;
167
		in_template_decl--;
140
    } else {
168
	} else {
141
	LIST ( IDENTIFIER ) pids = DEREF_list ( type_func_pids ( fn ) ) ;
169
		LIST(IDENTIFIER)pids = DEREF_list(type_func_pids(fn));
142
	if ( !IS_NULL_list ( pids ) ) {
170
		if (!IS_NULL_list(pids)) {
143
	    /* Have at least one parameter */
171
			/* Have at least one parameter */
144
	    IDENTIFIER pid = DEREF_id ( HEAD_list ( pids ) ) ;
172
			IDENTIFIER pid = DEREF_id(HEAD_list(pids));
145
	    TYPE t = DEREF_type ( id_parameter_type ( pid ) ) ;
173
			TYPE t = DEREF_type(id_parameter_type(pid));
146
 
-
 
147
	    /* Check for second parameter */
-
 
148
	    pids = TAIL_list ( pids ) ;
-
 
149
	    if ( !IS_NULL_list ( pids ) ) {
-
 
150
		/* Second parameter must have a default argument */
-
 
151
		EXP e ;
-
 
152
		pid = DEREF_id ( HEAD_list ( pids ) ) ;
-
 
153
		e = DEREF_exp ( id_parameter_init ( pid ) ) ;
-
 
154
		if ( IS_NULL_exp ( e ) ) return ( 0 ) ;
-
 
155
	    }
-
 
156
 
174
 
-
 
175
			/* Check for second parameter */
-
 
176
			pids = TAIL_list(pids);
-
 
177
			if (!IS_NULL_list(pids)) {
-
 
178
				/* Second parameter must have a default
-
 
179
				 * argument */
-
 
180
				EXP e;
-
 
181
				pid = DEREF_id(HEAD_list(pids));
-
 
182
				e = DEREF_exp(id_parameter_init(pid));
-
 
183
				if (IS_NULL_exp(e)) {
-
 
184
					return (0);
-
 
185
				}
-
 
186
			}
-
 
187
 
157
	    /* Check parameter type */
188
			/* Check parameter type */
158
	    if ( IS_type_ref ( t ) ) {
189
			if (IS_type_ref(t)) {
159
		TYPE s = DEREF_type ( type_ref_sub ( t ) ) ;
190
				TYPE s = DEREF_type(type_ref_sub(t));
160
		if ( IS_type_compound ( s ) ) {
191
				if (IS_type_compound(s)) {
-
 
192
					CLASS_TYPE cs =
161
		    CLASS_TYPE cs = DEREF_ctype ( type_compound_defn ( s ) ) ;
193
					    DEREF_ctype(type_compound_defn(s));
162
		    if ( eq_ctype ( cs, ct ) ) {
194
					if (eq_ctype(cs, ct)) {
163
			/* Reference to same class */
195
						/* Reference to same class */
-
 
196
						CV_SPEC qual =
164
			CV_SPEC qual = DEREF_cv ( type_qual ( s ) ) ;
197
						    DEREF_cv(type_qual(s));
165
			c = ( ( qual & cv_const ) ? 2 : 1 ) ;
198
						c = ((qual & cv_const) ? 2 : 1);
166
		    }
199
					}
167
		} else if ( is_templ_type ( s ) ) {
200
				} else if (is_templ_type(s)) {
168
		    /* Reference to template parameter */
201
					/* Reference to template parameter */
169
		    CV_SPEC qual = DEREF_cv ( type_qual ( s ) ) ;
202
					CV_SPEC qual = DEREF_cv(type_qual(s));
170
		    c = ( ( qual & cv_const ) ? 2 : 1 ) ;
203
					c = ((qual & cv_const)? 2 : 1);
-
 
204
				}
-
 
205
			} else if (IS_type_compound(t)) {
-
 
206
				CLASS_TYPE cs =
-
 
207
				    DEREF_ctype(type_compound_defn(t));
-
 
208
				if (eq_ctype(cs, ct)) {
-
 
209
					c = 3;
-
 
210
				}
-
 
211
			} else if (is_templ_type(t)) {
-
 
212
				/* Template parameter */
-
 
213
				c = 1;
-
 
214
			}
171
		}
215
		}
172
	    } else if ( IS_type_compound ( t ) ) {
-
 
173
		CLASS_TYPE cs = DEREF_ctype ( type_compound_defn ( t ) ) ;
-
 
174
		if ( eq_ctype ( cs, ct ) ) c = 3 ;
-
 
175
	    } else if ( is_templ_type ( t ) ) {
-
 
176
		/* Template parameter */
-
 
177
		c = 1 ;
-
 
178
	    }
-
 
179
	}
216
	}
180
    }
-
 
181
    return ( c ) ;
217
	return (c);
182
}
218
}
183
 
219
 
184
 
220
 
185
/*
221
/*
186
    CHECK A CONSTRUCTOR FUNCTION TYPE
222
    CHECK A CONSTRUCTOR FUNCTION TYPE
Line 192... Line 228...
192
    illegal copy constructors such as 'X::X ( X )' into valid constructors
228
    illegal copy constructors such as 'X::X ( X )' into valid constructors
193
    such as 'X::X ( X & )'.  This is to avoid having to check for infinite
229
    such as 'X::X ( X & )'.  This is to avoid having to check for infinite
194
    loops later.
230
    loops later.
195
*/
231
*/
196
 
232
 
197
TYPE check_constr
233
TYPE
198
    PROTO_N ( ( t, id, ns ) )
-
 
199
    PROTO_T ( TYPE t X IDENTIFIER id X NAMESPACE ns )
234
check_constr(TYPE t, IDENTIFIER id, NAMESPACE ns)
200
{
235
{
201
    if ( IS_type_templ ( t ) ) {
236
	if (IS_type_templ(t)) {
202
	/* Allow for template types */
237
		/* Allow for template types */
203
	TYPE s = DEREF_type ( type_templ_defn ( t ) ) ;
238
		TYPE s = DEREF_type(type_templ_defn(t));
204
	s = check_constr ( s, id, ns ) ;
239
		s = check_constr(s, id, ns);
205
	COPY_type ( type_templ_defn ( t ), s ) ;
240
		COPY_type(type_templ_defn(t), s);
206
    } else {
241
	} else {
207
	/* Decompose function type */
242
		/* Decompose function type */
208
	TYPE r = DEREF_type ( type_func_ret ( t ) ) ;
243
		TYPE r = DEREF_type(type_func_ret(t));
209
	CV_SPEC cv = DEREF_cv ( type_func_mqual ( t ) ) ;
244
		CV_SPEC cv = DEREF_cv(type_func_mqual(t));
210
 
245
 
211
	/* Find underlying class */
246
		/* Find underlying class */
212
	CLASS_TYPE ct = namespace_class ( ns ) ;
247
		CLASS_TYPE ct = namespace_class(ns);
-
 
248
 
-
 
249
		/* No return type can be given for a constructor */
-
 
250
		if (is_type_inferred(r)!= INFERRED_EMPTY) {
-
 
251
			HASHID nm = DEREF_hashid(id_name(id));
-
 
252
			report(crt_loc, ERR_class_ctor_ret(nm));
-
 
253
		}
-
 
254
		COPY_type(type_func_ret(t), type_void);
213
 
255
 
214
	/* No return type can be given for a constructor */
256
		/* Check for invalid copy constructors */
215
	if ( is_type_inferred ( r ) != INFERRED_EMPTY ) {
257
		if (check_copy_constr(t, ct) == 3) {
216
	    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
258
			HASHID nm = DEREF_hashid(id_name(id));
217
	    report ( crt_loc, ERR_class_ctor_ret ( nm ) ) ;
259
			report(crt_loc, ERR_class_copy_bad(nm));
218
	}
260
		}
219
	COPY_type ( type_func_ret ( t ), type_void ) ;
-
 
220
 
261
 
221
	/* Check for invalid copy constructors */
-
 
222
	if ( check_copy_constr ( t, ct ) == 3 ) {
-
 
223
	    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
-
 
224
	    report ( crt_loc, ERR_class_copy_bad ( nm ) ) ;
-
 
225
	}
-
 
226
 
-
 
227
	/* A constructor cannot be cv-qualified */
262
		/* A constructor cannot be cv-qualified */
228
	if ( cv & cv_qual ) {
263
		if (cv & cv_qual) {
229
	    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
264
			HASHID nm = DEREF_hashid(id_name(id));
230
	    report ( crt_loc, ERR_class_ctor_qual ( nm, cv ) ) ;
265
			report(crt_loc, ERR_class_ctor_qual(nm, cv));
-
 
266
		}
231
	}
267
	}
232
    }
-
 
233
    return ( t ) ;
268
	return (t);
234
}
269
}
235
 
270
 
236
 
271
 
237
/*
272
/*
238
    CHECK A DESTRUCTOR FUNCTION TYPE
273
    CHECK A DESTRUCTOR FUNCTION TYPE
239
 
274
 
240
    This routine checks the function type t for the destructor id.  The
275
    This routine checks the function type t for the destructor id.  The
241
    check that the destructor is a non-static member function is carried
276
    check that the destructor is a non-static member function is carried
242
    out elsewhere.  Note that no return type can be given for id - it is
277
    out elsewhere.  Note that no return type can be given for id - it is
243
    implicitly void.
278
    implicitly void.
244
*/
279
*/
245
 
280
 
246
TYPE check_destr
281
TYPE
247
    PROTO_N ( ( t, id, ns ) )
-
 
248
    PROTO_T ( TYPE t X IDENTIFIER id X NAMESPACE ns )
282
check_destr(TYPE t, IDENTIFIER id, NAMESPACE ns)
249
{
283
{
250
    if ( IS_type_templ ( t ) ) {
284
	if (IS_type_templ(t)) {
251
	/* Allow for template types */
285
		/* Allow for template types */
252
	TYPE s = DEREF_type ( type_templ_defn ( t ) ) ;
286
		TYPE s = DEREF_type(type_templ_defn(t));
253
	s = check_destr ( s, id, ns ) ;
287
		s = check_destr(s, id, ns);
254
	COPY_type ( type_templ_defn ( t ), s ) ;
288
		COPY_type(type_templ_defn(t), s);
255
    } else {
289
	} else {
256
	/* Decompose function type */
290
		/* Decompose function type */
257
	TYPE r = DEREF_type ( type_func_ret ( t ) ) ;
291
		TYPE r = DEREF_type(type_func_ret(t));
258
	CV_SPEC cv = DEREF_cv ( type_func_mqual ( t ) ) ;
292
		CV_SPEC cv = DEREF_cv(type_func_mqual(t));
259
	int ell = DEREF_int ( type_func_ellipsis ( t ) ) ;
293
		int ell = DEREF_int(type_func_ellipsis(t));
260
	LIST ( TYPE ) p = DEREF_list ( type_func_ptypes ( t ) ) ;
294
		LIST(TYPE)p = DEREF_list(type_func_ptypes(t));
261
 
295
 
262
	/* Check namespace */
296
		/* Check namespace */
263
	HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
297
		HASHID nm = DEREF_hashid(id_name(id));
264
	TYPE dt = DEREF_type ( hashid_destr_type ( nm ) ) ;
298
		TYPE dt = DEREF_type(hashid_destr_type(nm));
265
	if ( IS_type_compound ( dt ) ) {
299
		if (IS_type_compound(dt)) {
266
	    /* Check inheritance */
300
			/* Check inheritance */
267
	    CLASS_TYPE dct = DEREF_ctype ( type_compound_defn ( dt ) ) ;
301
			CLASS_TYPE dct = DEREF_ctype(type_compound_defn(dt));
268
	    NAMESPACE dns = DEREF_nspace ( ctype_member ( dct ) ) ;
302
			NAMESPACE dns = DEREF_nspace(ctype_member(dct));
269
	    if ( !EQ_nspace ( dns, ns ) ) {
303
			if (!EQ_nspace(dns, ns)) {
270
		report ( crt_loc, ERR_class_dtor_inherit ( nm, ns ) ) ;
304
				report(crt_loc, ERR_class_dtor_inherit(nm, ns));
271
	    }
305
			}
272
	}
306
		}
273
 
307
 
274
	/* No return type can be given for a destructor */
308
		/* No return type can be given for a destructor */
275
	if ( is_type_inferred ( r ) != INFERRED_EMPTY ) {
309
		if (is_type_inferred(r)!= INFERRED_EMPTY) {
276
	    report ( crt_loc, ERR_class_dtor_ret ( nm ) ) ;
310
			report(crt_loc, ERR_class_dtor_ret(nm));
277
	}
311
		}
278
	COPY_type ( type_func_ret ( t ), type_void ) ;
312
		COPY_type(type_func_ret(t), type_void);
279
 
313
 
280
	/* No parameter types can be given for a destructor */
314
		/* No parameter types can be given for a destructor */
281
	if ( !IS_NULL_list ( p ) || ell ) {
315
		if (!IS_NULL_list(p) || ell) {
282
	    report ( crt_loc, ERR_class_dtor_pars ( nm ) ) ;
316
			report(crt_loc, ERR_class_dtor_pars(nm));
283
	}
317
		}
284
 
318
 
285
	/* A destructor cannot be cv-qualified */
319
		/* A destructor cannot be cv-qualified */
286
	if ( cv & cv_qual ) {
320
		if (cv & cv_qual) {
287
	    report ( crt_loc, ERR_class_dtor_qual ( nm, cv ) ) ;
321
			report(crt_loc, ERR_class_dtor_qual(nm, cv));
288
	}
322
		}
289
    }
323
	}
290
    return ( t ) ;
324
	return (t);
291
}
325
}
292
 
326
 
293
 
327
 
294
/*
328
/*
295
    CHECK A CONVERSION FUNCTION TYPE
329
    CHECK A CONVERSION FUNCTION TYPE
296
 
330
 
297
    This routine checks the function type t for the conversion function id.
331
    This routine checks the function type t for the conversion function id.
298
    The check that the converter is a non-static member function is carried
332
    The check that the converter is a non-static member function is carried
299
    out elsewhere.  Note that no return type can be given for id - it is
333
    out elsewhere.  Note that no return type can be given for id - it is
300
    inferred from the type used in id.  This may not be a legal return type,
334
    inferred from the type used in id.  This may not be a legal return type,
301
    so inject_pre_type is used to check it.
335
    so inject_pre_type is used to check it.
302
*/
336
*/
303
 
337
 
304
TYPE check_conv
338
TYPE
305
    PROTO_N ( ( t, id ) )
-
 
306
    PROTO_T ( TYPE t X IDENTIFIER id )
339
check_conv(TYPE t, IDENTIFIER id)
307
{
340
{
308
    if ( IS_type_templ ( t ) ) {
341
	if (IS_type_templ(t)) {
309
	/* Allow for template types */
342
		/* Allow for template types */
310
	TYPE s = DEREF_type ( type_templ_defn ( t ) ) ;
343
		TYPE s = DEREF_type(type_templ_defn(t));
311
	s = check_conv ( s, id ) ;
344
		s = check_conv(s, id);
312
	COPY_type ( type_templ_defn ( t ), s ) ;
345
		COPY_type(type_templ_defn(t), s);
313
    } else {
346
	} else {
314
	/* Find the conversion type */
347
		/* Find the conversion type */
315
	HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
348
		HASHID nm = DEREF_hashid(id_name(id));
316
	TYPE s = DEREF_type ( hashid_conv_type ( nm ) ) ;
349
		TYPE s = DEREF_type(hashid_conv_type(nm));
317
 
350
 
318
	/* Decompose function type */
351
		/* Decompose function type */
319
	TYPE r = DEREF_type ( type_func_ret ( t ) ) ;
352
		TYPE r = DEREF_type(type_func_ret(t));
320
	int ell = DEREF_int ( type_func_ellipsis ( t ) ) ;
353
		int ell = DEREF_int(type_func_ellipsis(t));
321
	LIST ( TYPE ) p = DEREF_list ( type_func_ptypes ( t ) ) ;
354
		LIST(TYPE)p = DEREF_list(type_func_ptypes(t));
322
 
355
 
323
	/* No return type can be given for a conversion function */
356
		/* No return type can be given for a conversion function */
324
	if ( is_type_inferred ( r ) != INFERRED_EMPTY ) {
357
		if (is_type_inferred(r)!= INFERRED_EMPTY) {
325
	    /* If a return type is given it might as well be right */
358
			/* If a return type is given it might as well be
-
 
359
			 * right */
326
	    if ( eq_type ( r, s ) ) {
360
			if (eq_type(r, s)) {
327
		report ( crt_loc, ERR_class_conv_fct_ret ( nm ) ) ;
361
				report(crt_loc, ERR_class_conv_fct_ret(nm));
328
	    } else {
362
			} else {
-
 
363
				report(crt_loc,
329
		report ( crt_loc, ERR_class_conv_fct_ret_bad ( nm, r ) ) ;
364
				       ERR_class_conv_fct_ret_bad(nm, r));
330
	    }
365
			}
331
	}
366
		}
332
	COPY_type ( type_func_ret ( t ), NULL_type ) ;
367
		COPY_type(type_func_ret(t), NULL_type);
333
	t = inject_pre_type ( t, s, 0 ) ;
368
		t = inject_pre_type(t, s, 0);
-
 
369
 
-
 
370
		/* No parameter types can be given for a conversion function */
-
 
371
		if (!IS_NULL_list(p) || ell) {
-
 
372
			report(crt_loc, ERR_class_conv_fct_pars(nm));
-
 
373
		}
334
 
374
 
335
	/* No parameter types can be given for a conversion function */
-
 
336
	if ( !IS_NULL_list ( p ) || ell ) {
-
 
337
	    report ( crt_loc, ERR_class_conv_fct_pars ( nm ) ) ;
-
 
338
	}
-
 
339
 
-
 
340
	/* Can't have conversion to cv-qualified void */
375
		/* Can't have conversion to cv-qualified void */
341
	if ( IS_type_top_etc ( s ) ) {
376
		if (IS_type_top_etc(s)) {
342
	    report ( crt_loc, ERR_class_conv_fct_void ( nm ) ) ;
377
			report(crt_loc, ERR_class_conv_fct_void(nm));
343
	}
378
		}
344
    }
379
	}
345
    return ( t ) ;
380
	return (t);
346
}
381
}
347
 
382
 
348
 
383
 
349
/*
384
/*
350
    LOOK UP AN OVERLOADED OPERATOR FUNCTION
385
    LOOK UP AN OVERLOADED OPERATOR FUNCTION
351
 
386
 
352
    This routine looks up the overloaded operator function 'operator op'
387
    This routine looks up the overloaded operator function 'operator op'
353
    in the class ct.
388
    in the class ct.
354
*/
389
*/
355
 
390
 
356
IDENTIFIER find_operator
391
IDENTIFIER
357
    PROTO_N ( ( ct, op ) )
-
 
358
    PROTO_T ( CLASS_TYPE ct X int op )
392
find_operator(CLASS_TYPE ct, int op)
359
{
393
{
360
    HASHID nm = lookup_op ( op ) ;
394
	HASHID nm = lookup_op(op);
361
    NAMESPACE cns = DEREF_nspace ( ctype_member ( ct ) ) ;
395
	NAMESPACE cns = DEREF_nspace(ctype_member(ct));
362
    IDENTIFIER id = search_field ( cns, nm, 0, 0 ) ;
396
	IDENTIFIER id = search_field(cns, nm, 0, 0);
363
    return ( id ) ;
397
	return (id);
364
}
398
}
365
 
399
 
366
 
400
 
367
/*
401
/*
368
    FIND A DEFAULT CONSTRUCTOR OR DESTRUCTOR
402
    FIND A DEFAULT CONSTRUCTOR OR DESTRUCTOR
Line 372... Line 406...
372
    depending on the value of n.  The null identifier is returned and
406
    depending on the value of n.  The null identifier is returned and
373
    an error is added to err if such a function does not exist (including
407
    an error is added to err if such a function does not exist (including
374
    for incomplete types).
408
    for incomplete types).
375
*/
409
*/
376
 
410
 
377
static IDENTIFIER find_constr
411
static IDENTIFIER
378
    PROTO_N ( ( ct, n, err ) )
-
 
379
    PROTO_T ( CLASS_TYPE ct X int n X ERROR *err )
412
find_constr(CLASS_TYPE ct, int n, ERROR *err)
380
{
413
{
381
    CLASS_INFO ci ;
414
	CLASS_INFO ci;
382
    int match = 0 ;
415
	int match = 0;
383
    int nargs = 0 ;
416
	int nargs = 0;
384
    int kind = KIND_FUNC ;
417
	int kind = KIND_FUNC;
385
    IDENTIFIER id = NULL_id ;
418
	IDENTIFIER id = NULL_id;
386
    IDENTIFIER qid = NULL_id ;
419
	IDENTIFIER qid = NULL_id;
387
 
420
 
388
    /* Check for complete types */
421
	/* Check for complete types */
389
    complete_class ( ct, 1 ) ;
422
	complete_class(ct, 1);
390
    ci = DEREF_cinfo ( ctype_info ( ct ) ) ;
423
	ci = DEREF_cinfo(ctype_info(ct));
391
    if ( !( ci & cinfo_complete ) ) return ( NULL_id ) ;
424
	if (!(ci & cinfo_complete)) {
-
 
425
		return (NULL_id);
-
 
426
	}
392
 
427
 
393
    /* Find the basic identifier */
428
	/* Find the basic identifier */
394
    switch ( n ) {
429
	switch (n) {
395
	case DEFAULT_CONSTR :
430
	case DEFAULT_CONSTR:
396
	case DEFAULT_COPY :
431
	case DEFAULT_COPY:
397
	case DEFAULT_USR : {
432
	case DEFAULT_USR: {
398
	    /* Find constructors */
433
		/* Find constructors */
399
	    id = DEREF_id ( ctype_constr ( ct ) ) ;
434
		id = DEREF_id(ctype_constr(ct));
400
	    if ( n == DEFAULT_COPY ) nargs = 1 ;
435
		if (n == DEFAULT_COPY) {
-
 
436
			nargs = 1;
-
 
437
		}
401
	    kind = KIND_CONSTR ;
438
		kind = KIND_CONSTR;
402
	    break ;
439
		break;
403
	}
440
	}
404
	case DEFAULT_DESTR :
441
	case DEFAULT_DESTR:
405
	case DEFAULT_DELETE : {
442
	case DEFAULT_DELETE: {
406
	    /* Find destructors */
443
		/* Find destructors */
407
	    id = DEREF_id ( ctype_destr ( ct ) ) ;
444
		id = DEREF_id(ctype_destr(ct));
408
	    nargs = 1 ;
445
		nargs = 1;
-
 
446
		break;
-
 
447
	}
-
 
448
	case DEFAULT_ASSIGN: {
-
 
449
		/* Find 'operator =' */
-
 
450
		id = find_operator(ct, lex_assign);
-
 
451
		nargs = 2;
409
	    break ;
452
		break;
410
	}
453
	}
411
	case DEFAULT_ASSIGN : {
-
 
412
	    /* Find 'operator =' */
-
 
413
	    id = find_operator ( ct, lex_assign ) ;
-
 
414
	    nargs = 2 ;
-
 
415
	    break ;
-
 
416
	}
454
	}
417
    }
-
 
418
 
455
 
419
    /* Find appropriate function */
456
	/* Find appropriate function */
420
    if ( !IS_NULL_id ( id ) && IS_id_mem_func ( id ) ) {
457
	if (!IS_NULL_id(id) && IS_id_mem_func(id)) {
421
	DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
458
		DECL_SPEC ds = DEREF_dspec(id_storage(id));
422
	if ( ds & dspec_template ) {
459
		if (ds & dspec_template) {
423
	    /* Allow for template constructors */
460
			/* Allow for template constructors */
424
	    match = 2 ;
461
			match = 2;
425
	} else {
462
		} else {
426
	    switch ( n ) {
463
			switch (n) {
427
		case DEFAULT_CONSTR :
464
			case DEFAULT_CONSTR:
428
		case DEFAULT_DESTR :
465
			case DEFAULT_DESTR:
429
		case DEFAULT_DELETE :
466
			case DEFAULT_DELETE:
430
		case DEFAULT_USR : {
467
			case DEFAULT_USR: {
431
		    /* Should take no arguments */
468
				/* Should take no arguments */
432
		    IDENTIFIER pid = id ;
469
				IDENTIFIER pid = id;
433
		    while ( !IS_NULL_id ( pid ) ) {
470
				while (!IS_NULL_id(pid)) {
-
 
471
					TYPE t =
434
			TYPE t = DEREF_type ( id_mem_func_type ( pid ) ) ;
472
					    DEREF_type(id_mem_func_type(pid));
435
			if ( min_no_args ( t ) == 1 ) {
473
					if (min_no_args(t) == 1) {
436
			    qid = pid ;
474
						qid = pid;
-
 
475
						match++;
-
 
476
					}
-
 
477
					pid = DEREF_id(id_mem_func_over(pid));
-
 
478
				}
-
 
479
				break;
-
 
480
			}
-
 
481
			case DEFAULT_COPY:
-
 
482
			case DEFAULT_ASSIGN: {
-
 
483
				/* Should be a copy constructor */
-
 
484
				IDENTIFIER pid = id;
-
 
485
				while (!IS_NULL_id(pid)) {
-
 
486
					TYPE t =
-
 
487
					    DEREF_type(id_mem_func_type(pid));
-
 
488
					if (check_copy_constr(t, ct)) {
-
 
489
						qid = pid;
437
			    match++ ;
490
						match++;
-
 
491
					}
-
 
492
					pid = DEREF_id(id_mem_func_over(pid));
-
 
493
				}
-
 
494
				break;
-
 
495
			}
438
			}
496
			}
439
			pid = DEREF_id ( id_mem_func_over ( pid ) ) ;
-
 
440
		    }
-
 
441
		    break ;
-
 
442
		}
497
		}
443
		case DEFAULT_COPY :
-
 
444
		case DEFAULT_ASSIGN : {
-
 
445
		    /* Should be a copy constructor */
-
 
446
		    IDENTIFIER pid = id ;
-
 
447
		    while ( !IS_NULL_id ( pid ) ) {
-
 
448
			TYPE t = DEREF_type ( id_mem_func_type ( pid ) ) ;
-
 
449
			if ( check_copy_constr ( t, ct ) ) {
-
 
450
			    qid = pid ;
-
 
451
			    match++ ;
-
 
452
			}
-
 
453
			pid = DEREF_id ( id_mem_func_over ( pid ) ) ;
-
 
454
		    }
-
 
455
		    break ;
-
 
456
		}
-
 
457
	    }
-
 
458
	}
-
 
459
    } else {
498
	} else {
460
	/* This can only happen for dummy classes */
499
		/* This can only happen for dummy classes */
461
	return ( NULL_id ) ;
500
		return (NULL_id);
462
    }
501
	}
463
 
502
 
464
    /* Deal with ambiguous cases */
503
	/* Deal with ambiguous cases */
465
    if ( match > 1 ) {
504
	if (match > 1) {
466
	CANDIDATE_LIST *p = &candidates ;
505
		CANDIDATE_LIST *p = &candidates;
467
	p->size = 0 ;
506
		p->size = 0;
468
	add_candidates ( p, id, 1, KIND_CONSTR ) ;
507
		add_candidates(p, id, 1, KIND_CONSTR);
469
	if ( p->size ) {
508
		if (p->size) {
470
	    CANDIDATE *q ;
509
			CANDIDATE *q;
471
	    unsigned rank ;
510
			unsigned rank;
472
	    TYPE t = make_class_type ( ct ) ;
511
			TYPE t = make_class_type(ct);
473
	    LIST ( EXP ) args = NULL_list ( EXP ) ;
512
			LIST(EXP)args = NULL_list(EXP);
474
	    while ( nargs ) {
513
			while (nargs) {
475
		/* Create dummy arguments */
514
				/* Create dummy arguments */
476
		EXP a ;
515
				EXP a;
477
		MAKE_exp_value ( t, a ) ;
516
				MAKE_exp_value(t, a);
478
		CONS_exp ( a, args, args ) ;
517
				CONS_exp(a, args, args);
479
		nargs-- ;
518
				nargs--;
480
	    }
519
			}
481
	    if ( kind == KIND_CONSTR ) {
520
			if (kind == KIND_CONSTR) {
482
		swap_candidates ( p, ( unsigned ) 0 ) ;
521
				swap_candidates(p,(unsigned)0);
483
	    }
522
			}
484
	    q = resolve_overload ( p, args, t, 0 ) ;
523
			q = resolve_overload(p, args, t, 0);
485
	    if ( kind == KIND_CONSTR ) {
524
			if (kind == KIND_CONSTR) {
486
		swap_candidates ( p, ( unsigned ) 0 ) ;
525
				swap_candidates(p,(unsigned)0);
487
	    }
526
			}
488
	    rank = q->rank ;
527
			rank = q->rank;
489
	    if ( rank >= RANK_VIABLE ) {
528
			if (rank >= RANK_VIABLE) {
490
		qid = q->func ;
529
				qid = q->func;
491
		if ( rank == RANK_BEST ) {
530
				if (rank == RANK_BEST) {
492
		    /* Best match */
531
					/* Best match */
493
		    if ( match_no_viable > 1 ) {
532
					if (match_no_viable > 1) {
494
			ERROR err2 ;
533
						ERROR err2;
495
			if ( kind == KIND_CONSTR ) {
534
						if (kind == KIND_CONSTR) {
496
			    err2 = ERR_over_match_ctor_ok ( qid ) ;
535
							err2 = ERR_over_match_ctor_ok(qid);
-
 
536
						} else {
-
 
537
							err2 = ERR_over_match_call_ok(qid);
-
 
538
						}
-
 
539
						add_error(err, err2);
-
 
540
					}
-
 
541
					match = 1;
-
 
542
				} else {
-
 
543
					/* Ambiguous call */
-
 
544
					ERROR err2;
-
 
545
					if (kind == KIND_CONSTR) {
-
 
546
						err2 = ERR_over_match_ctor_ambig(qid);
-
 
547
					} else {
-
 
548
						err2 = ERR_over_match_call_ambig(qid);
-
 
549
					}
-
 
550
					err2 = list_candidates(err2, p, RANK_VIABLE);
-
 
551
					add_error(err, err2);
-
 
552
				}
497
			} else {
553
			} else {
-
 
554
				/* No viable call */
-
 
555
				qid = NULL_id;
-
 
556
				match = 0;
-
 
557
			}
498
			    err2 = ERR_over_match_call_ok ( qid ) ;
558
			if (!IS_NULL_list(args)) {
-
 
559
				free_exp_list(args, 1);
499
			}
560
			}
500
			add_error ( err, err2 ) ;
-
 
501
		    }
-
 
502
		    match = 1 ;
-
 
503
		} else {
561
		} else {
504
		    /* Ambiguous call */
-
 
505
		    ERROR err2 ;
-
 
506
		    if ( kind == KIND_CONSTR ) {
-
 
507
			err2 = ERR_over_match_ctor_ambig ( qid ) ;
-
 
508
		    } else {
-
 
509
			err2 = ERR_over_match_call_ambig ( qid ) ;
-
 
510
		    }
-
 
511
		    err2 = list_candidates ( err2, p, RANK_VIABLE ) ;
-
 
512
		    add_error ( err, err2 ) ;
-
 
513
		}
-
 
514
	    } else {
-
 
515
		/* No viable call */
562
			/* No viable call */
516
		qid = NULL_id ;
563
			qid = NULL_id;
517
		match = 0 ;
564
			match = 0;
518
	    }
565
		}
519
	    if ( !IS_NULL_list ( args ) ) free_exp_list ( args, 1 ) ;
-
 
520
	} else {
-
 
521
	    /* No viable call */
-
 
522
	    qid = NULL_id ;
-
 
523
	    match = 0 ;
-
 
524
	}
566
	}
525
    }
-
 
526
 
567
 
527
    /* Report error */
568
	/* Report error */
528
    if ( match == 0 ) {
569
	if (match == 0) {
529
	switch ( n ) {
570
		switch (n) {
530
	    case DEFAULT_CONSTR :
571
		case DEFAULT_CONSTR:
531
	    case DEFAULT_USR : {
572
		case DEFAULT_USR: {
532
		add_error ( err, ERR_class_ctor_default ( ct ) ) ;
573
			add_error(err, ERR_class_ctor_default(ct));
533
		break ;
574
			break;
534
	    }
575
		}
535
	    case DEFAULT_COPY : {
576
		case DEFAULT_COPY: {
536
		add_error ( err, ERR_class_copy_constr ( ct ) ) ;
577
			add_error(err, ERR_class_copy_constr(ct));
537
		break ;
578
			break;
538
	    }
579
		}
539
	    case DEFAULT_DESTR :
580
		case DEFAULT_DESTR:
540
	    case DEFAULT_DELETE : {
581
		case DEFAULT_DELETE: {
541
		add_error ( err, ERR_class_dtor_default ( ct ) ) ;
582
			add_error(err, ERR_class_dtor_default(ct));
542
		break ;
583
			break;
543
	    }
584
		}
544
	    case DEFAULT_ASSIGN : {
585
		case DEFAULT_ASSIGN: {
545
		add_error ( err, ERR_class_copy_assign ( ct ) ) ;
586
			add_error(err, ERR_class_copy_assign(ct));
546
		break ;
587
			break;
-
 
588
		}
547
	    }
589
		}
548
	}
590
	}
549
    }
-
 
550
    return ( qid ) ;
591
	return (qid);
551
}
592
}
552
 
593
 
553
 
594
 
554
/*
595
/*
555
    FIND NUMBER OF EXTRA CONSTRUCTOR ARGUMENTS
596
    FIND NUMBER OF EXTRA CONSTRUCTOR ARGUMENTS
Line 561... Line 602...
561
    initialised.  For non-trivial destructors bit 1 of the extra argument
602
    initialised.  For non-trivial destructors bit 1 of the extra argument
562
    is used to indicate that any virtual components should be destroyed,
603
    is used to indicate that any virtual components should be destroyed,
563
    while bit 0 is used to indicate that 'operator delete' should be
604
    while bit 0 is used to indicate that 'operator delete' should be
564
    called on the argument.  The macros EXTRA_* are used to represent
605
    called on the argument.  The macros EXTRA_* are used to represent
565
    these values.
606
    these values.
566
*/
607
*/
567
 
608
 
568
unsigned extra_constr_args
609
unsigned
569
    PROTO_N ( ( id, ct ) )
-
 
570
    PROTO_T ( IDENTIFIER id X CLASS_TYPE ct )
610
extra_constr_args(IDENTIFIER id, CLASS_TYPE ct)
571
{
611
{
572
    DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
612
	DECL_SPEC ds = DEREF_dspec(id_storage(id));
573
    if ( !( ds & dspec_trivial ) ) {
613
	if (!(ds & dspec_trivial)) {
574
	HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
614
		HASHID nm = DEREF_hashid(id_name(id));
575
	unsigned tag = TAG_hashid ( nm ) ;
615
		unsigned tag = TAG_hashid(nm);
576
	if ( tag == hashid_constr_tag ) {
616
		if (tag == hashid_constr_tag) {
577
	    /* Constructors */
617
			/* Constructors */
578
	    CLASS_INFO ci = DEREF_cinfo ( ctype_info ( ct ) ) ;
618
			CLASS_INFO ci = DEREF_cinfo(ctype_info(ct));
579
	    if ( ci & cinfo_virtual_base ) return ( 1 ) ;
619
			if (ci & cinfo_virtual_base) {
-
 
620
				return (1);
-
 
621
			}
580
	} else if ( tag == hashid_destr_tag ) {
622
		} else if (tag == hashid_destr_tag) {
581
	    /* Destructors */
623
			/* Destructors */
582
	    return ( 1 ) ;
624
			return (1);
583
	}
625
		}
584
    }
626
	}
585
    return ( 0 ) ;
627
	return (0);
586
}
628
}
587
 
629
 
588
 
630
 
589
/*
631
/*
590
    CONSTRUCTOR BASE CLASS INITIALISER FLAG
632
    CONSTRUCTOR BASE CLASS INITIALISER FLAG
591
 
633
 
592
    This flag is set to true in a constructor base class initialiser.
634
    This flag is set to true in a constructor base class initialiser.
593
    This overrides the value of any extra arguments passed to the
635
    This overrides the value of any extra arguments passed to the
594
    constructor.
636
    constructor.
595
*/
637
*/
596
 
638
 
597
static int in_ctor_base_init = 0 ;
639
static int in_ctor_base_init = 0;
598
 
640
 
599
 
641
 
600
/*
642
/*
601
    ADD EXTRA CONSTRUCTOR ARGUMENTS
643
    ADD EXTRA CONSTRUCTOR ARGUMENTS
602
 
644
 
603
    This routine adds any necessary extra constructor arguments to the
645
    This routine adds any necessary extra constructor arguments to the
604
    member function call expression e.  ct gives the associate class
646
    member function call expression e.  ct gives the associate class
605
    type and v is the value to be passed to such arguments.
647
    type and v is the value to be passed to such arguments.
606
*/
648
*/
607
 
649
 
608
EXP add_constr_args
650
EXP
609
    PROTO_N ( ( e, ct, v ) )
-
 
610
    PROTO_T ( EXP e X CLASS_TYPE ct X int v )
651
add_constr_args(EXP e, CLASS_TYPE ct, int v)
611
{
652
{
612
    if ( IS_exp_func_id ( e ) ) {
653
	if (IS_exp_func_id(e)) {
613
	IDENTIFIER id = DEREF_id ( exp_func_id_id ( e ) ) ;
654
		IDENTIFIER id = DEREF_id(exp_func_id_id(e));
614
	unsigned n = extra_constr_args ( id, ct ) ;
655
		unsigned n = extra_constr_args(id, ct);
615
	if ( n ) {
656
		if (n) {
616
	    LIST ( EXP ) args = DEREF_list ( exp_func_id_args ( e ) ) ;
657
			LIST(EXP)args = DEREF_list(exp_func_id_args(e));
617
	    LIST ( EXP ) extra = NULL_list ( EXP ) ;
658
			LIST(EXP)extra = NULL_list(EXP);
618
	    if ( in_ctor_base_init ) v = 0 ;
659
			if (in_ctor_base_init) {
-
 
660
				v = 0;
-
 
661
			}
619
	    while ( n ) {
662
			while (n) {
620
		EXP a ;
663
				EXP a;
621
		NAT c = small_nat [v] ;
664
				NAT c = small_nat[v];
622
		MAKE_exp_int_lit ( type_sint, c, exp_int_lit_tag, a ) ;
665
				MAKE_exp_int_lit(type_sint, c,
-
 
666
						 exp_int_lit_tag, a);
623
		CONS_exp ( a, extra, extra ) ;
667
				CONS_exp(a, extra, extra);
624
		n-- ;
668
				n--;
625
	    }
669
			}
626
	    args = APPEND_list ( args, extra ) ;
670
			args = APPEND_list(args, extra);
627
	    COPY_list ( exp_func_id_args ( e ), args ) ;
671
			COPY_list(exp_func_id_args(e), args);
-
 
672
		}
628
	}
673
	}
629
    }
-
 
630
    return ( e ) ;
674
	return (e);
631
}
675
}
632
 
676
 
633
 
677
 
634
/*
678
/*
635
    CALL A CONSTRUCTOR OR DESTRUCTOR
679
    CALL A CONSTRUCTOR OR DESTRUCTOR
Line 637... Line 681...
637
    This routine constructs a default call of the constructor or destructor
681
    This routine constructs a default call of the constructor or destructor
638
    id of type n.  ct gives the corresponding class type and pb gives the
682
    id of type n.  ct gives the corresponding class type and pb gives the
639
    second argument for copy constructors and assignment operators.
683
    second argument for copy constructors and assignment operators.
640
*/
684
*/
641
 
685
 
642
static EXP call_constr
686
static EXP
643
    PROTO_N ( ( id, pb, n, v, ct ) )
-
 
644
    PROTO_T ( IDENTIFIER id X EXP *pb X int n X int v X CLASS_TYPE ct )
687
call_constr(IDENTIFIER id, EXP *pb, int n, int v, CLASS_TYPE ct)
645
{
688
{
646
    /* Create argument list */
689
	/* Create argument list */
647
    TYPE t ;
690
	TYPE t;
648
    EXP e, a, b ;
691
	EXP e, a, b;
649
    LIST ( EXP ) args = NULL_list ( EXP ) ;
692
	LIST(EXP)args = NULL_list(EXP);
650
    IDENTIFIER cid = DEREF_id ( ctype_name ( ct ) ) ;
693
	IDENTIFIER cid = DEREF_id(ctype_name(ct));
651
    MAKE_type_compound ( cv_lvalue, ct, t ) ;
694
	MAKE_type_compound(cv_lvalue, ct, t);
652
    COPY_id ( type_name ( t ), cid ) ;
695
	COPY_id(type_name(t), cid);
653
    MAKE_exp_dummy ( t, NULL_exp, LINK_NONE, NULL_off, 0, a ) ;
696
	MAKE_exp_dummy(t, NULL_exp, LINK_NONE, NULL_off, 0, a);
654
    if ( n == DEFAULT_ASSIGN || n == DEFAULT_DELETE ) {
697
	if (n == DEFAULT_ASSIGN || n == DEFAULT_DELETE) {
655
	/* Don't know object type */
698
		/* Don't know object type */
656
	COPY_int ( exp_dummy_virt ( a ), 1 ) ;
699
		COPY_int(exp_dummy_virt(a), 1);
657
    }
-
 
658
    if ( n == DEFAULT_COPY || n == DEFAULT_ASSIGN ) {
-
 
659
	/* These have two arguments */
-
 
660
	TYPE s = t ;
-
 
661
	int virt = 1 ;
-
 
662
	b = *pb ;
-
 
663
	if ( !IS_NULL_exp ( b ) ) {
-
 
664
	    s = DEREF_type ( exp_type ( b ) ) ;
-
 
665
	    while ( IS_type_array ( s ) ) {
-
 
666
		s = DEREF_type ( type_array_sub ( s ) ) ;
-
 
667
	    }
-
 
668
	    s = lvalue_type ( s ) ;
-
 
669
	    if ( know_type ( b ) ) virt = 0 ;
-
 
670
	}
700
	}
-
 
701
	if (n == DEFAULT_COPY || n == DEFAULT_ASSIGN) {
-
 
702
		/* These have two arguments */
-
 
703
		TYPE s = t;
-
 
704
		int virt = 1;
-
 
705
		b = *pb;
-
 
706
		if (!IS_NULL_exp(b)) {
-
 
707
			s = DEREF_type(exp_type(b));
-
 
708
			while (IS_type_array(s)) {
-
 
709
				s = DEREF_type(type_array_sub(s));
-
 
710
			}
-
 
711
			s = lvalue_type(s);
-
 
712
			if (know_type(b)) {
-
 
713
				virt = 0;
-
 
714
			}
-
 
715
		}
671
	MAKE_exp_dummy ( s, b, LINK_NONE, NULL_off, DUMMY_copy, b ) ;
716
		MAKE_exp_dummy(s, b, LINK_NONE, NULL_off, DUMMY_copy, b);
672
	COPY_int ( exp_dummy_virt ( b ), virt ) ;
717
		COPY_int(exp_dummy_virt(b), virt);
673
	CONS_exp ( b, args, args ) ;
718
		CONS_exp(b, args, args);
674
	*pb = b ;
719
		*pb = b;
675
    } else {
720
	} else {
676
	/* These have one argument */
721
		/* These have one argument */
677
	b = a ;
722
		b = a;
678
    }
723
	}
679
    CONS_exp ( a, args, args ) ;
724
	CONS_exp(a, args, args);
680
 
725
 
681
    /* Call the function */
726
	/* Call the function */
682
    use_func_id ( id, 0, suppress_usage ) ;
727
	use_func_id(id, 0, suppress_usage);
683
    e = apply_func_id ( id, qual_none, NULL_graph, args ) ;
728
	e = apply_func_id(id, qual_none, NULL_graph, args);
684
    e = add_constr_args ( e, ct, v ) ;
729
	e = add_constr_args(e, ct, v);
685
    if ( n == DEFAULT_DESTR || n == DEFAULT_DELETE ) {
730
	if (n == DEFAULT_DESTR || n == DEFAULT_DELETE) {
686
	MAKE_exp_destr ( type_void, e, a, e ) ;
731
		MAKE_exp_destr(type_void, e, a, e);
687
    } else {
732
	} else {
688
	t = make_class_type ( ct ) ;
733
		t = make_class_type(ct);
689
	MAKE_exp_constr ( t, e, a, b, n, e ) ;
734
		MAKE_exp_constr(t, e, a, b, n, e);
690
    }
735
	}
691
    return ( e ) ;
736
	return (e);
692
}
737
}
693
 
738
 
694
 
739
 
695
/*
740
/*
696
    CREATE A DEFAULT INITIALISER
741
    CREATE A DEFAULT INITIALISER
697
 
742
 
698
    This routine creates a default initialiser for an object of type t
743
    This routine creates a default initialiser for an object of type t
699
    in a constructor, destructor or assignment operator (as indicated
744
    in a constructor, destructor or assignment operator (as indicated
700
    by n).  Any resultant errors are added to err.
745
    by n).  Any resultant errors are added to err.
701
*/
746
*/
702
 
747
 
703
EXP init_default
748
EXP
704
    PROTO_N ( ( t, pa, n, v, err ) )
-
 
705
    PROTO_T ( TYPE t X EXP *pa X int n X int v X ERROR *err )
749
init_default(TYPE t, EXP *pa, int n, int v, ERROR *err)
706
{
750
{
707
    CV_SPEC cv ;
751
	CV_SPEC cv;
708
    EXP e = NULL_exp ;
752
	EXP e = NULL_exp;
709
    unsigned tag = TAG_type ( t ) ;
753
	unsigned tag = TAG_type(t);
710
 
754
 
711
    /* Deal with classes */
755
	/* Deal with classes */
712
    if ( tag == type_compound_tag ) {
756
	if (tag == type_compound_tag) {
713
	CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
757
		CLASS_TYPE ct = DEREF_ctype(type_compound_defn(t));
714
	IDENTIFIER id = find_constr ( ct, n, err ) ;
758
		IDENTIFIER id = find_constr(ct, n, err);
715
	if ( !IS_NULL_id ( id ) ) {
759
		if (!IS_NULL_id(id)) {
716
	    DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
760
			DECL_SPEC ds = DEREF_dspec(id_storage(id));
717
	    if ( !( ds & dspec_trivial ) ) {
761
			if (!(ds & dspec_trivial)) {
718
		/* Non-trivial constructor */
762
				/* Non-trivial constructor */
719
		e = call_constr ( id, pa, n, v, ct ) ;
763
				e = call_constr(id, pa, n, v, ct);
720
	    } else if ( ds & dspec_implicit ) {
764
			} else if (ds & dspec_implicit) {
721
		if ( !( ds & dspec_defn ) ) {
765
				if (!(ds & dspec_defn)) {
722
		    /* Trivial constructor */
766
					/* Trivial constructor */
723
		    implicit_defn ( id, n ) ;
767
					implicit_defn(id, n);
724
		}
768
				}
725
	    }
769
			}
726
	}
770
		}
727
	return ( e ) ;
771
		return (e);
728
    }
772
	}
729
 
773
 
730
    /* Deal with arrays */
774
	/* Deal with arrays */
731
    if ( tag == type_array_tag ) {
775
	if (tag == type_array_tag) {
732
	NAT m = DEREF_nat ( type_array_size ( t ) ) ;
776
		NAT m = DEREF_nat(type_array_size(t));
733
	TYPE s = DEREF_type ( type_array_sub ( t ) ) ;
777
		TYPE s = DEREF_type(type_array_sub(t));
734
	e = init_default ( s, pa, n, v, err ) ;
778
		e = init_default(s, pa, n, v, err);
735
	if ( !IS_NULL_exp ( e ) ) {
779
		if (!IS_NULL_exp(e)) {
736
	    /* Apply to each array element */
780
			/* Apply to each array element */
737
	    MAKE_exp_nof ( t, NULL_exp, m, e, NULL_exp, e ) ;
781
			MAKE_exp_nof(t, NULL_exp, m, e, NULL_exp, e);
738
	}
782
		}
739
	return ( e ) ;
783
		return (e);
740
    }
784
	}
741
 
785
 
742
    /* Everything else is alright in these cases */
786
	/* Everything else is alright in these cases */
743
    if ( n == DEFAULT_COPY || n == DEFAULT_DESTR || n == DEFAULT_DELETE ) {
787
	if (n == DEFAULT_COPY || n == DEFAULT_DESTR || n == DEFAULT_DELETE) {
744
	return ( NULL_exp ) ;
788
		return (NULL_exp);
745
    }
789
	}
746
 
790
 
747
    /* Deal with references */
791
	/* Deal with references */
748
    if ( tag == type_ref_tag ) {
792
	if (tag == type_ref_tag) {
749
	add_error ( err, ERR_dcl_init_ref_none () ) ;
793
		add_error(err, ERR_dcl_init_ref_none());
750
	if ( n == DEFAULT_ASSIGN ) return ( NULL_exp ) ;
794
		if (n == DEFAULT_ASSIGN) {
-
 
795
			return (NULL_exp);
-
 
796
		}
751
	MAKE_exp_null ( t, e ) ;
797
		MAKE_exp_null(t, e);
752
	return ( e ) ;
798
		return (e);
753
    }
799
	}
754
 
800
 
755
    /* Deal with const objects */
801
	/* Deal with const objects */
756
    cv = DEREF_cv ( type_qual ( t ) ) ;
802
	cv = DEREF_cv(type_qual(t));
-
 
803
	if (cv & cv_const) {
757
    if ( cv & cv_const ) add_error ( err, ERR_dcl_init_const () ) ;
804
		add_error(err, ERR_dcl_init_const());
-
 
805
	}
758
    return ( NULL_exp ) ;
806
	return (NULL_exp);
759
}
807
}
760
 
808
 
761
 
809
 
762
/*
810
/*
763
    REPORT AN INITIALISATION ERROR
811
    REPORT AN INITIALISATION ERROR
764
 
812
 
765
    This routine reports the error err which occurred in the initialisation
813
    This routine reports the error err which occurred in the initialisation
766
    of id in constructor or destructor fn of type n.
814
    of id in constructor or destructor fn of type n.
767
*/
815
*/
768
 
816
 
769
static void constr_error
817
static void
770
    PROTO_N ( ( err, id, fn, n ) )
-
 
771
    PROTO_T ( ERROR err X IDENTIFIER id X IDENTIFIER fn X int n )
818
constr_error(ERROR err, IDENTIFIER id, IDENTIFIER fn, int n)
772
{
819
{
773
    ERROR err1 ;
820
	ERROR err1;
774
    ERROR err2 = ERR_dcl_init_decl ( id, NULL_string ) ;
821
	ERROR err2 = ERR_dcl_init_decl(id, NULL_string);
775
    if ( n == DEFAULT_USR ) {
822
	if (n == DEFAULT_USR) {
776
	err1 = ERR_class_base_init_err ( fn ) ;
823
		err1 = ERR_class_base_init_err(fn);
777
    } else {
824
	} else {
778
	err1 = ERR_class_base_init_impl ( fn ) ;
825
		err1 = ERR_class_base_init_impl(fn);
779
    }
826
	}
780
    err = concat_error ( err2, err ) ;
827
	err = concat_error(err2, err);
781
    err = concat_error ( err1, err ) ;
828
	err = concat_error(err1, err);
782
    report ( crt_loc, err ) ;
829
	report(crt_loc, err);
783
    return ;
830
	return;
784
}
831
}
785
 
832
 
786
 
833
 
787
/*
834
/*
788
    CREATE A BASE CLASS INITIALISER
835
    CREATE A BASE CLASS INITIALISER
Line 792... Line 839...
792
    and assignment operators a dummy expression is used to indicate that
839
    and assignment operators a dummy expression is used to indicate that
793
    the base should be initialised from the corresponding base of the
840
    the base should be initialised from the corresponding base of the
794
    second argument (see enc_ctor_exp).
841
    second argument (see enc_ctor_exp).
795
*/
842
*/
796
 
843
 
797
static EXP init_empty_base
844
static EXP
798
    PROTO_N ( ( gr, fn, n, m ) )
-
 
799
    PROTO_T ( GRAPH gr X IDENTIFIER fn X int n X int m )
845
init_empty_base(GRAPH gr, IDENTIFIER fn, int n, int m)
800
{
846
{
801
    EXP e = NULL_exp ;
847
	EXP e = NULL_exp;
802
    ERROR err = NULL_err ;
848
	ERROR err = NULL_err;
803
    CLASS_TYPE ct = DEREF_ctype ( graph_head ( gr ) ) ;
849
	CLASS_TYPE ct = DEREF_ctype(graph_head(gr));
804
    TYPE t = make_class_type ( ct ) ;
850
	TYPE t = make_class_type(ct);
805
    e = init_default ( t, &e, m, EXTRA_NONE, &err ) ;
851
	e = init_default(t, &e, m, EXTRA_NONE, &err);
806
    if ( IS_NULL_exp ( e ) ) {
852
	if (IS_NULL_exp(e)) {
807
	if ( n == DEFAULT_USR && m != DEFAULT_DESTR ) {
853
		if (n == DEFAULT_USR && m != DEFAULT_DESTR) {
808
	    /* Warn about uninitialised bases */
854
			/* Warn about uninitialised bases */
809
	    if ( !is_empty_class ( t ) ) {
855
			if (!is_empty_class(t)) {
810
		IDENTIFIER id = DEREF_id ( ctype_name ( ct ) ) ;
856
				IDENTIFIER id = DEREF_id(ctype_name(ct));
811
		err = concat_error ( err, ERR_class_base_init_none ( id ) ) ;
857
				err = concat_error(err, ERR_class_base_init_none(id));
812
	    }
858
			}
813
	}
859
		}
814
	if ( m == DEFAULT_COPY || m == DEFAULT_ASSIGN ) {
860
		if (m == DEFAULT_COPY || m == DEFAULT_ASSIGN) {
815
	    /* Dummy value for copy constructor */
861
			/* Dummy value for copy constructor */
816
	    MAKE_exp_value ( t, e ) ;
862
			MAKE_exp_value(t, e);
-
 
863
		}
817
	}
864
	}
818
    }
-
 
819
    if ( !IS_NULL_err ( err ) ) {
865
	if (!IS_NULL_err(err)) {
820
	IDENTIFIER id = DEREF_id ( ctype_name ( ct ) ) ;
866
		IDENTIFIER id = DEREF_id(ctype_name(ct));
821
	constr_error ( err, id, fn, n ) ;
867
		constr_error(err, id, fn, n);
822
    }
868
	}
823
    return ( e ) ;
869
	return (e);
824
}
870
}
825
 
871
 
826
 
872
 
827
/*
873
/*
828
    CREATE A CLASS MEMBER INITIALISER
874
    CREATE A CLASS MEMBER INITIALISER
829
 
875
 
830
    This routine creates a default initialiser for a class member id
876
    This routine creates a default initialiser for a class member id
831
    for the constructor or destructor fn of type n.  Again a dummy value
877
    for the constructor or destructor fn of type n.  Again a dummy value
832
    is used in copy constructors and assignment operators.
878
    is used in copy constructors and assignment operators.
833
*/
879
*/
834
 
880
 
835
static EXP init_empty_mem
881
static EXP
836
    PROTO_N ( ( id, fn, n, m ) )
-
 
837
    PROTO_T ( IDENTIFIER id X IDENTIFIER fn X int n X int m )
882
init_empty_mem(IDENTIFIER id, IDENTIFIER fn, int n, int m)
838
{
883
{
839
    EXP e = NULL_exp ;
884
	EXP e = NULL_exp;
840
    ERROR err = NULL_err ;
885
	ERROR err = NULL_err;
841
    TYPE t = DEREF_type ( id_member_type ( id ) ) ;
886
	TYPE t = DEREF_type(id_member_type(id));
842
    int v = ( m == DEFAULT_DESTR ? EXTRA_DESTR : EXTRA_CONSTR ) ;
887
	int v = (m == DEFAULT_DESTR ? EXTRA_DESTR : EXTRA_CONSTR);
843
    e = init_default ( t, &e, m, v, &err ) ;
888
	e = init_default(t, &e, m, v, &err);
844
    if ( IS_NULL_exp ( e ) ) {
889
	if (IS_NULL_exp(e)) {
845
	if ( m == DEFAULT_COPY || m == DEFAULT_ASSIGN ) {
890
		if (m == DEFAULT_COPY || m == DEFAULT_ASSIGN) {
846
	    /* Dummy value for copy constructor */
891
			/* Dummy value for copy constructor */
847
	    if ( IS_type_ptr ( t ) ) {
892
			if (IS_type_ptr(t)) {
848
		DECL_SPEC ds = DEREF_dspec ( id_storage ( fn ) ) ;
893
				DECL_SPEC ds = DEREF_dspec(id_storage(fn));
849
		if ( !( ds & dspec_trivial ) ) {
894
				if (!(ds & dspec_trivial)) {
850
		    /* Warn about shallow copies */
895
					/* Warn about shallow copies */
851
		    err = concat_error ( err, ERR_class_copy_ptr () ) ;
896
					err = concat_error(err, ERR_class_copy_ptr());
-
 
897
				}
-
 
898
			}
-
 
899
			MAKE_exp_value(t, e);
852
		}
900
		}
853
	    }
-
 
854
	    MAKE_exp_value ( t, e ) ;
-
 
855
	}
901
	}
856
    }
-
 
857
    if ( !IS_NULL_err ( err ) ) {
902
	if (!IS_NULL_err(err)) {
858
	constr_error ( err, id, fn, n ) ;
903
		constr_error(err, id, fn, n);
859
    }
904
	}
860
    return ( e ) ;
905
	return (e);
861
}
906
}
862
 
907
 
863
 
908
 
864
/*
909
/*
865
    LISTS OF CONSTRUCTOR INITIALISERS
910
    LISTS OF CONSTRUCTOR INITIALISERS
866
 
911
 
867
    These lists are built up by the constructor initialisers.
912
    These lists are built up by the constructor initialisers.
868
*/
913
*/
869
 
914
 
870
static LIST ( GRAPH ) init_bases = NULL_list ( GRAPH ) ;
915
static LIST(GRAPH) init_bases = NULL_list(GRAPH);
871
static LIST ( EXP ) val_bases = NULL_list ( EXP ) ;
916
static LIST(EXP) val_bases = NULL_list(EXP);
872
static LIST ( IDENTIFIER ) init_mems = NULL_list ( IDENTIFIER ) ;
917
static LIST(IDENTIFIER) init_mems = NULL_list(IDENTIFIER);
873
static LIST ( EXP ) val_mems = NULL_list ( EXP ) ;
918
static LIST(EXP) val_mems = NULL_list(EXP);
874
static unsigned long no_ctor_init = 0 ;
919
static unsigned long no_ctor_init = 0;
875
static int init_base_last = 1 ;
920
static int init_base_last = 1;
876
 
921
 
877
 
922
 
878
/*
923
/*
879
    CLEAR THE LISTS OF CONSTRUCTOR INITIALISERS
924
    CLEAR THE LISTS OF CONSTRUCTOR INITIALISERS
880
 
925
 
881
    This routine clears the lists of constructor initialisers above.
926
    This routine clears the lists of constructor initialisers above.
882
*/
927
*/
883
 
928
 
884
static void destroy_ctor_lists
929
static void
885
    PROTO_Z ()
930
destroy_ctor_lists(void)
886
{
931
{
887
    IGNORE check_value ( OPT_VAL_ctor_initializers, no_ctor_init ) ;
932
	IGNORE check_value(OPT_VAL_ctor_initializers, no_ctor_init);
888
    DESTROY_list ( init_bases, SIZE_graph ) ;
933
	DESTROY_list(init_bases, SIZE_graph);
889
    DESTROY_list ( val_bases, SIZE_exp ) ;
934
	DESTROY_list(val_bases, SIZE_exp);
890
    DESTROY_list ( init_mems, SIZE_id ) ;
935
	DESTROY_list(init_mems, SIZE_id);
891
    DESTROY_list ( val_mems, SIZE_exp ) ;
936
	DESTROY_list(val_mems, SIZE_exp);
892
    init_bases = NULL_list ( GRAPH ) ;
937
	init_bases = NULL_list(GRAPH);
893
    val_bases = NULL_list ( EXP ) ;
938
	val_bases = NULL_list(EXP);
894
    init_mems = NULL_list ( IDENTIFIER ) ;
939
	init_mems = NULL_list(IDENTIFIER);
895
    val_mems = NULL_list ( EXP ) ;
940
	val_mems = NULL_list(EXP);
896
    init_base_last = 1 ;
941
	init_base_last = 1;
897
    no_ctor_init = 0 ;
942
	no_ctor_init = 0;
898
    return ;
943
	return;
899
}
944
}
900
 
945
 
901
 
946
 
902
/*
947
/*
903
    FIND A BASE CLASS INITIALISER
948
    FIND A BASE CLASS INITIALISER
904
 
949
 
905
    This routine finds the base class initialiser for gr in the lists
950
    This routine finds the base class initialiser for gr in the lists
906
    given above.  If gr is a member of init_bases then the corresponding
951
    given above.  If gr is a member of init_bases then the corresponding
907
    element of val_bases is returned, otherwise the null expression is
952
    element of val_bases is returned, otherwise the null expression is
908
    returned.
953
    returned.
909
*/
954
*/
910
 
955
 
911
static EXP find_base_init
956
static EXP
912
    PROTO_N ( ( gr ) )
-
 
913
    PROTO_T ( GRAPH gr )
957
find_base_init(GRAPH gr)
914
{
958
{
915
    LIST ( GRAPH ) p = init_bases ;
959
	LIST(GRAPH)p = init_bases;
916
    LIST ( EXP ) q = val_bases ;
960
	LIST(EXP)q = val_bases;
917
    while ( !IS_NULL_list ( p ) ) {
961
	while (!IS_NULL_list(p)) {
918
	GRAPH gs = DEREF_graph ( HEAD_list ( p ) ) ;
962
		GRAPH gs = DEREF_graph(HEAD_list(p));
919
	if ( eq_graph ( gs, gr ) ) {
963
		if (eq_graph(gs, gr)) {
920
	    /* Found graph - return corresponding expression */
964
			/* Found graph - return corresponding expression */
921
	    EXP e = DEREF_exp ( HEAD_list ( q ) ) ;
965
			EXP e = DEREF_exp(HEAD_list(q));
922
	    return ( e ) ;
966
			return (e);
923
	}
967
		}
924
	q = TAIL_list ( q ) ;
968
		q = TAIL_list(q);
925
	p = TAIL_list ( p ) ;
969
		p = TAIL_list(p);
926
    }
970
	}
927
    return ( NULL_exp ) ;
971
	return (NULL_exp);
928
}
972
}
929
 
973
 
930
 
974
 
931
/*
975
/*
932
    FIND A CLASS MEMBER INITIALISER
976
    FIND A CLASS MEMBER INITIALISER
933
 
977
 
934
    This routine finds the class member initialiser for id in the lists
978
    This routine finds the class member initialiser for id in the lists
935
    given above.  If id is a member of init_mems then the corresponding
979
    given above.  If id is a member of init_mems then the corresponding
936
    element of val_mems is returned, otherwise the null expression is
980
    element of val_mems is returned, otherwise the null expression is
937
    returned.
981
    returned.
938
*/
982
*/
939
 
983
 
940
static EXP find_mem_init
984
static EXP
941
    PROTO_N ( ( id ) )
-
 
942
    PROTO_T ( IDENTIFIER id )
985
find_mem_init(IDENTIFIER id)
943
{
986
{
944
    LIST ( IDENTIFIER ) p = init_mems ;
987
	LIST(IDENTIFIER)p = init_mems;
945
    LIST ( EXP ) q = val_mems ;
988
	LIST(EXP)q = val_mems;
946
    while ( !IS_NULL_list ( p ) ) {
989
	while (!IS_NULL_list(p)) {
947
	IDENTIFIER mid = DEREF_id ( HEAD_list ( p ) ) ;
990
		IDENTIFIER mid = DEREF_id(HEAD_list(p));
948
	if ( EQ_id ( mid, id ) ) {
991
		if (EQ_id(mid, id)) {
949
	    /* Found identifier - return corresponding expression */
992
			/* Found identifier - return corresponding expression */
950
	    EXP e = DEREF_exp ( HEAD_list ( q ) ) ;
993
			EXP e = DEREF_exp(HEAD_list(q));
951
	    return ( e ) ;
994
			return (e);
-
 
995
		}
-
 
996
		q = TAIL_list(q);
-
 
997
		p = TAIL_list(p);
952
	}
998
	}
953
	q = TAIL_list ( q ) ;
-
 
954
	p = TAIL_list ( p ) ;
-
 
955
    }
-
 
956
    return ( NULL_exp ) ;
999
	return (NULL_exp);
957
}
1000
}
958
 
1001
 
959
 
1002
 
960
/*
1003
/*
961
    MARK A DESTRUCTOR
1004
    MARK A DESTRUCTOR
962
 
1005
 
963
    This routine marks the initialiser expression e for an object of type t
1006
    This routine marks the initialiser expression e for an object of type t
964
    if t has a non-trivial destructor by enclosing it in parentheses.
1007
    if t has a non-trivial destructor by enclosing it in parentheses.
965
*/
1008
*/
966
 
1009
 
967
static EXP destr_init
1010
static EXP
968
    PROTO_N ( ( t, e ) )
-
 
969
    PROTO_T ( TYPE t X EXP e )
1011
destr_init(TYPE t, EXP e)
970
{
1012
{
971
    TYPE s = t ;
1013
	TYPE s = t;
972
    while ( IS_type_array ( s ) ) {
1014
	while (IS_type_array(s)) {
973
	s = DEREF_type ( type_array_sub ( s ) ) ;
1015
		s = DEREF_type(type_array_sub(s));
974
    }
1016
	}
975
    if ( IS_type_compound ( s ) ) {
1017
	if (IS_type_compound(s)) {
976
	CLASS_TYPE cs = DEREF_ctype ( type_compound_defn ( s ) ) ;
1018
		CLASS_TYPE cs = DEREF_ctype(type_compound_defn(s));
977
	IDENTIFIER id = DEREF_id ( ctype_destr ( cs ) ) ;
1019
		IDENTIFIER id = DEREF_id(ctype_destr(cs));
978
	if ( IS_id_mem_func ( id ) ) {
1020
		if (IS_id_mem_func(id)) {
979
	    DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
1021
			DECL_SPEC ds = DEREF_dspec(id_storage(id));
980
	    if ( !( ds & dspec_trivial ) ) {
1022
			if (!(ds & dspec_trivial)) {
981
		if ( ds & dspec_implicit ) {
1023
				if (ds & dspec_implicit) {
982
		    if ( !( ds & dspec_defn ) ) {
1024
					if (!(ds & dspec_defn)) {
983
			/* Trivial constructor */
1025
						/* Trivial constructor */
984
			implicit_defn ( id, DEFAULT_DESTR ) ;
1026
						implicit_defn(id, DEFAULT_DESTR);
985
		    }
1027
					}
-
 
1028
				}
-
 
1029
				MAKE_exp_paren(t, e, e);
-
 
1030
			}
986
		}
1031
		}
987
		MAKE_exp_paren ( t, e, e ) ;
-
 
988
	    }
-
 
989
	}
1032
	}
990
    }
-
 
991
    return ( e ) ;
1033
	return (e);
992
}
1034
}
993
 
1035
 
994
 
1036
 
995
/*
1037
/*
996
    CREATE A CONSTRUCTOR OR DESTRUCTOR
1038
    CREATE A CONSTRUCTOR OR DESTRUCTOR
997
 
1039
 
998
    This routine creates a constructor or destructor initialiser list.
1040
    This routine creates a constructor or destructor initialiser list.
999
    cns gives the corresponding class namespace and fn is the function
1041
    cns gives the corresponding class namespace and fn is the function
1000
    name.  n and m indicate the constructor or destructor type.  This can
1042
    name.  n and m indicate the constructor or destructor type.  This can
1001
    be an implicitly declared constructor, destructor or assignment
1043
    be an implicitly declared constructor, destructor or assignment
1002
    function, or an explicitly declared constructor.  In the latter
1044
    function, or an explicitly declared constructor.  In the latter
1003
    case the ctor-initialiser lists above are used to indicate the
1045
    case the ctor-initialiser lists above are used to indicate the
1004
    initialiser values.
1046
    initialiser values.
1005
*/
1047
*/
1006
 
1048
 
1007
static EXP make_constr
1049
static EXP
1008
    PROTO_N ( ( cns, fn, n, m ) )
-
 
1009
    PROTO_T ( NAMESPACE cns X IDENTIFIER fn X int n X int m )
1050
make_constr(NAMESPACE cns, IDENTIFIER fn, int n, int m)
1010
{
1051
{
1011
    EXP r ;
1052
	EXP r;
1012
    int usr = 0 ;
1053
	int usr = 0;
1013
    int str = 1 ;
1054
	int str = 1;
1014
    unsigned nv = 0 ;
1055
	unsigned nv = 0;
1015
    unsigned nb = 0 ;
1056
	unsigned nb = 0;
1016
    unsigned long no = 0 ;
1057
	unsigned long no = 0;
1017
    int templ = in_template_decl ;
1058
	int templ = in_template_decl;
1018
    LIST ( EXP ) p = NULL_list ( EXP ) ;
1059
	LIST(EXP)p = NULL_list(EXP);
1019
    LIST ( OFFSET ) q = NULL_list ( OFFSET ) ;
1060
	LIST(OFFSET)q = NULL_list(OFFSET);
1020
 
1061
 
1021
    /* Deconstruct class type */
1062
	/* Deconstruct class type */
1022
    CLASS_TYPE ct = namespace_class ( cns ) ;
1063
	CLASS_TYPE ct = namespace_class(cns);
1023
    CLASS_INFO ci = DEREF_cinfo ( ctype_info ( ct ) ) ;
1064
	CLASS_INFO ci = DEREF_cinfo(ctype_info(ct));
1024
    GRAPH gr = DEREF_graph ( ctype_base ( ct ) ) ;
1065
	GRAPH gr = DEREF_graph(ctype_base(ct));
1025
    LIST ( GRAPH ) br = DEREF_list ( graph_tails ( gr ) ) ;
1066
	LIST(GRAPH)br = DEREF_list(graph_tails(gr));
1026
    LIST ( GRAPH ) bv = DEREF_list ( ctype_vbase ( ct ) ) ;
1067
	LIST(GRAPH)bv = DEREF_list(ctype_vbase(ct));
1027
    MEMBER mem = DEREF_member ( nspace_ctype_first ( cns ) ) ;
1068
	MEMBER mem = DEREF_member(nspace_ctype_first(cns));
1028
 
1069
 
1029
    /* Mark 'this' parameter as used */
1070
	/* Mark 'this' parameter as used */
1030
    crt_access_list.inherit++ ;
1071
	crt_access_list.inherit++;
1031
    IGNORE this_param ( fn, 1 ) ;
1072
	IGNORE this_param(fn, 1);
1032
 
1073
 
1033
    /* Check for user-defined constructors */
1074
	/* Check for user-defined constructors */
1034
    if ( n == DEFAULT_USR && m == DEFAULT_CONSTR ) usr = 1 ;
1075
	if (n == DEFAULT_USR && m == DEFAULT_CONSTR) {
-
 
1076
		usr = 1;
-
 
1077
	}
1035
 
1078
 
1036
    /* Initialise virtual bases */
1079
	/* Initialise virtual bases */
1037
    if ( m != DEFAULT_ASSIGN ) {
1080
	if (m != DEFAULT_ASSIGN) {
1038
	while ( !IS_NULL_list ( bv ) ) {
1081
		while (!IS_NULL_list(bv)) {
1039
	    EXP e = NULL_exp ;
1082
			EXP e = NULL_exp;
1040
	    GRAPH gs = DEREF_graph ( HEAD_list ( bv ) ) ;
1083
			GRAPH gs = DEREF_graph(HEAD_list(bv));
1041
	    DECL_SPEC acc = DEREF_dspec ( graph_access ( gs ) ) ;
1084
			DECL_SPEC acc = DEREF_dspec(graph_access(gs));
-
 
1085
			if (usr) {
1042
	    if ( usr ) e = find_base_init ( gs ) ;
1086
				e = find_base_init(gs);
-
 
1087
			}
1043
	    if ( IS_NULL_exp ( e ) && !( acc & dspec_template ) ) {
1088
			if (IS_NULL_exp(e) && !(acc & dspec_template)) {
1044
		e = init_empty_base ( gs, fn, n, m ) ;
1089
				e = init_empty_base(gs, fn, n, m);
1045
		if ( templ ) {
1090
				if (templ) {
1046
		    /* Only testing for template classes */
1091
					/* Only testing for template classes */
1047
		    free_exp ( e, 1 ) ;
1092
					free_exp(e, 1);
1048
		    e = NULL_exp ;
1093
					e = NULL_exp;
-
 
1094
				}
-
 
1095
			}
-
 
1096
			if (m == DEFAULT_CONSTR && !templ) {
-
 
1097
				CLASS_TYPE cs = DEREF_ctype(graph_head(gs));
-
 
1098
				TYPE s = make_class_type(cs);
-
 
1099
				e = destr_init(s, e);
-
 
1100
			}
-
 
1101
			if (!IS_NULL_exp(e)) {
-
 
1102
				OFFSET off = DEREF_off(graph_off(gs));
-
 
1103
				CONS_off(off, q, q);
-
 
1104
				CONS_exp(e, p, p);
-
 
1105
				nv++;
-
 
1106
			}
-
 
1107
			bv = TAIL_list(bv);
1049
		}
1108
		}
-
 
1109
	}
-
 
1110
 
-
 
1111
	/* Initialise direct bases */
-
 
1112
	while (!IS_NULL_list(br)) {
-
 
1113
		EXP e = NULL_exp;
-
 
1114
		GRAPH gs = DEREF_graph(HEAD_list(br));
-
 
1115
		DECL_SPEC acc = DEREF_dspec(graph_access(gs));
-
 
1116
		if (!(acc & dspec_virtual) || m == DEFAULT_ASSIGN) {
-
 
1117
			if (usr) {
-
 
1118
				e = find_base_init(gs);
-
 
1119
			}
-
 
1120
			if (IS_NULL_exp(e) && !(acc & dspec_template)) {
-
 
1121
				e = init_empty_base(gs, fn, n, m);
-
 
1122
				if (templ) {
-
 
1123
					/* Only testing for template classes */
-
 
1124
					free_exp(e, 1);
-
 
1125
					e = NULL_exp;
1050
	    }
1126
				}
-
 
1127
			}
1051
	    if ( m == DEFAULT_CONSTR && !templ ) {
1128
			if (m == DEFAULT_CONSTR && !templ) {
1052
		CLASS_TYPE cs = DEREF_ctype ( graph_head ( gs ) ) ;
1129
				CLASS_TYPE cs = DEREF_ctype(graph_head(gs));
1053
		TYPE s = make_class_type ( cs ) ;
1130
				TYPE s = make_class_type(cs);
1054
		e = destr_init ( s, e ) ;
1131
				e = destr_init(s, e);
1055
	    }
1132
			}
1056
	    if ( !IS_NULL_exp ( e ) ) {
1133
			if (!IS_NULL_exp(e)) {
1057
		OFFSET off = DEREF_off ( graph_off ( gs ) ) ;
1134
				OFFSET off = DEREF_off(graph_off(gs));
1058
		CONS_off ( off, q, q ) ;
1135
				CONS_off(off, q, q);
1059
		CONS_exp ( e, p, p ) ;
1136
				CONS_exp(e, p, p);
1060
		nv++ ;
1137
				nb++;
1061
	    }
1138
			}
-
 
1139
		}
1062
	    bv = TAIL_list ( bv ) ;
1140
		br = TAIL_list(br);
-
 
1141
	}
-
 
1142
 
-
 
1143
	/* Initialise data members */
-
 
1144
	member_no = no;
-
 
1145
	mem = next_data_member(mem, 2);
-
 
1146
	if (usr && (ci & cinfo_union)) {
-
 
1147
		/* Check union initialisers */
-
 
1148
		unsigned ni = LENGTH_list(init_mems);
-
 
1149
		if (ni) {
-
 
1150
			if (ni > 1) {
-
 
1151
				/* More than one initialiser for union */
-
 
1152
				report(crt_loc, ERR_class_base_init_union(ct));
-
 
1153
			}
-
 
1154
			str = 0;
-
 
1155
		}
1063
	}
1156
	}
-
 
1157
	while (!IS_NULL_member(mem)) {
-
 
1158
		EXP e = NULL_exp;
-
 
1159
		IDENTIFIER id = DEREF_id(member_id(mem));
-
 
1160
		if (usr) {
-
 
1161
			e = find_mem_init(id);
-
 
1162
			if (!IS_NULL_exp(e)) {
-
 
1163
				if (no == member_no) {
-
 
1164
					/* More than one initialiser for
-
 
1165
					 * anonymous union */
-
 
1166
					report(crt_loc,
-
 
1167
					       ERR_class_base_init_anon(id));
1064
    }
1168
				}
-
 
1169
				no = member_no;
-
 
1170
			}
-
 
1171
		}
-
 
1172
		if (IS_NULL_exp(e) && str) {
-
 
1173
			e = init_empty_mem(id, fn, n, m);
-
 
1174
			if (templ) {
-
 
1175
				/* Only testing for template classes */
-
 
1176
				free_exp(e, 1);
-
 
1177
				e = NULL_exp;
-
 
1178
			}
-
 
1179
		}
-
 
1180
		if (m == DEFAULT_CONSTR && !templ) {
-
 
1181
			TYPE s = DEREF_type(id_member_type(id));
-
 
1182
			e = destr_init(s, e);
-
 
1183
		}
-
 
1184
		if (!IS_NULL_exp(e)) {
-
 
1185
			OFFSET off = DEREF_off(id_member_off(id));
-
 
1186
			e = check_init(e);
-
 
1187
			CONS_off(off, q, q);
-
 
1188
			CONS_exp(e, p, p);
-
 
1189
		}
-
 
1190
		if (ci & cinfo_union) {
-
 
1191
			if (!usr) {
-
 
1192
				break;
-
 
1193
			}
-
 
1194
			str = 0;
-
 
1195
		}
-
 
1196
		mem = DEREF_member(member_next(mem));
-
 
1197
		mem = next_data_member(mem, 2);
-
 
1198
	}
1065
 
1199
 
1066
    /* Initialise direct bases */
1200
	/* Construct the result */
1067
    while ( !IS_NULL_list ( br ) ) {
1201
	crt_access_list.inherit--;
1068
	EXP e = NULL_exp ;
1202
	if (IS_NULL_list(p)) {
1069
	GRAPH gs = DEREF_graph ( HEAD_list ( br ) ) ;
1203
		DECL_SPEC ds = DEREF_dspec(id_storage(fn));
1070
	DECL_SPEC acc = DEREF_dspec ( graph_access ( gs ) ) ;
1204
		if (ds & dspec_trivial) {
1071
	if ( !( acc & dspec_virtual ) || m == DEFAULT_ASSIGN ) {
1205
			return (NULL_exp);
-
 
1206
		}
1072
	    if ( usr ) e = find_base_init ( gs ) ;
1207
		if (m != DEFAULT_DESTR && !templ) {
1073
	    if ( IS_NULL_exp ( e ) && !( acc & dspec_template ) ) {
1208
			if (ci & (cinfo_virtual_base | cinfo_polymorphic)) {
1074
		e = init_empty_base ( gs, fn, n, m ) ;
1209
				/* These require an initialiser */
1075
		if ( templ ) {
1210
				/* EMPTY */
1076
		    /* Only testing for template classes */
-
 
1077
		    free_exp ( e, 1 ) ;
1211
			} else {
1078
		    e = NULL_exp ;
1212
				return (NULL_exp);
-
 
1213
			}
1079
		}
1214
		}
1080
	    }
-
 
1081
	    if ( m == DEFAULT_CONSTR && !templ ) {
-
 
1082
		CLASS_TYPE cs = DEREF_ctype ( graph_head ( gs ) ) ;
-
 
1083
		TYPE s = make_class_type ( cs ) ;
-
 
1084
		e = destr_init ( s, e ) ;
-
 
1085
	    }
-
 
1086
	    if ( !IS_NULL_exp ( e ) ) {
-
 
1087
		OFFSET off = DEREF_off ( graph_off ( gs ) ) ;
-
 
1088
		CONS_off ( off, q, q ) ;
-
 
1089
		CONS_exp ( e, p, p ) ;
-
 
1090
		nb++ ;
-
 
1091
	    }
-
 
1092
	}
-
 
1093
	br = TAIL_list ( br ) ;
-
 
1094
    }
-
 
1095
 
-
 
1096
    /* Initialise data members */
-
 
1097
    member_no = no ;
-
 
1098
    mem = next_data_member ( mem, 2 ) ;
-
 
1099
    if ( usr && ( ci & cinfo_union ) ) {
-
 
1100
	/* Check union initialisers */
-
 
1101
	unsigned ni = LENGTH_list ( init_mems ) ;
-
 
1102
	if ( ni ) {
-
 
1103
	    if ( ni > 1 ) {
-
 
1104
		/* More than one initialiser for union */
-
 
1105
		report ( crt_loc, ERR_class_base_init_union ( ct ) ) ;
-
 
1106
	    }
-
 
1107
	    str = 0 ;
-
 
1108
	}
-
 
1109
    }
-
 
1110
    while ( !IS_NULL_member ( mem ) ) {
-
 
1111
	EXP e = NULL_exp ;
-
 
1112
	IDENTIFIER id = DEREF_id ( member_id ( mem ) ) ;
-
 
1113
	if ( usr ) {
-
 
1114
	    e = find_mem_init ( id ) ;
-
 
1115
	    if ( !IS_NULL_exp ( e ) ) {
-
 
1116
		if ( no == member_no ) {
-
 
1117
		    /* More than one initialiser for anonymous union */
-
 
1118
		    report ( crt_loc, ERR_class_base_init_anon ( id ) ) ;
-
 
1119
		}
-
 
1120
		no = member_no ;
-
 
1121
	    }
-
 
1122
	}
-
 
1123
	if ( IS_NULL_exp ( e ) && str ) {
-
 
1124
	    e = init_empty_mem ( id, fn, n, m ) ;
-
 
1125
	    if ( templ ) {
-
 
1126
		/* Only testing for template classes */
-
 
1127
		free_exp ( e, 1 ) ;
-
 
1128
		e = NULL_exp ;
-
 
1129
	    }
-
 
1130
	}
-
 
1131
	if ( m == DEFAULT_CONSTR && !templ ) {
-
 
1132
	    TYPE s = DEREF_type ( id_member_type ( id ) ) ;
-
 
1133
	    e = destr_init ( s, e ) ;
-
 
1134
	}
-
 
1135
	if ( !IS_NULL_exp ( e ) ) {
-
 
1136
	    OFFSET off = DEREF_off ( id_member_off ( id ) ) ;
-
 
1137
	    e = check_init ( e ) ;
-
 
1138
	    CONS_off ( off, q, q ) ;
-
 
1139
	    CONS_exp ( e, p, p ) ;
-
 
1140
	}
1215
	}
1141
	if ( ci & cinfo_union ) {
-
 
1142
	    if ( !usr ) break ;
-
 
1143
	    str = 0 ;
-
 
1144
	}
-
 
1145
	mem = DEREF_member ( member_next ( mem ) ) ;
-
 
1146
	mem = next_data_member ( mem, 2 ) ;
-
 
1147
    }
-
 
1148
 
-
 
1149
    /* Construct the result */
-
 
1150
    crt_access_list.inherit-- ;
-
 
1151
    if ( IS_NULL_list ( p ) ) {
-
 
1152
	DECL_SPEC ds = DEREF_dspec ( id_storage ( fn ) ) ;
-
 
1153
	if ( ds & dspec_trivial ) return ( NULL_exp ) ;
-
 
1154
	if ( m != DEFAULT_DESTR && !templ ) {
1216
	if (m != DEFAULT_DESTR) {
1155
	    if ( ci & ( cinfo_virtual_base | cinfo_polymorphic ) ) {
-
 
1156
		/* These require an initialiser */
1217
		/* Initialisers are built in reverse order */
1157
		/* EMPTY */
-
 
1158
	    } else {
1218
		p = REVERSE_list(p);
1159
		return ( NULL_exp ) ;
1219
		q = REVERSE_list(q);
1160
	    }
-
 
1161
	}
1220
	}
1162
    }
-
 
1163
    if ( m != DEFAULT_DESTR ) {
-
 
1164
	/* Initialisers are built in reverse order */
-
 
1165
	p = REVERSE_list ( p ) ;
-
 
1166
	q = REVERSE_list ( q ) ;
-
 
1167
    }
-
 
1168
    MAKE_exp_initialiser ( type_void, p, q, m, nv, nb, r ) ;
1221
	MAKE_exp_initialiser(type_void, p, q, m, nv, nb, r);
1169
    return ( r ) ;
1222
	return (r);
1170
}
1223
}
1171
 
1224
 
1172
 
1225
 
1173
/*
1226
/*
1174
    CREATE A DESTRUCTOR PRELUDE EXPRESSION
1227
    CREATE A DESTRUCTOR PRELUDE EXPRESSION
Line 1177... Line 1230...
1177
    place at the end of the destructor, and it is this which is handled
1230
    place at the end of the destructor, and it is this which is handled
1178
    by make_constr.  However for polymorphic classes some action is
1231
    by make_constr.  However for polymorphic classes some action is
1179
    also required at the start of the destructor, namely the resetting
1232
    also required at the start of the destructor, namely the resetting
1180
    of the virtual function tables.  This routine creates a dummy
1233
    of the virtual function tables.  This routine creates a dummy
1181
    initialiser expression which performs this action.
1234
    initialiser expression which performs this action.
1182
*/
1235
*/
1183
 
1236
 
1184
static EXP make_destr_prelude
1237
static EXP
1185
    PROTO_N ( ( cns ) )
-
 
1186
    PROTO_T ( NAMESPACE cns )
1238
make_destr_prelude(NAMESPACE cns)
1187
{
1239
{
1188
    EXP r = NULL_exp ;
1240
	EXP r = NULL_exp;
1189
    CLASS_TYPE ct = namespace_class ( cns ) ;
1241
	CLASS_TYPE ct = namespace_class(cns);
1190
    CLASS_INFO ci = DEREF_cinfo ( ctype_info ( ct ) ) ;
1242
	CLASS_INFO ci = DEREF_cinfo(ctype_info(ct));
1191
    if ( ci & cinfo_polymorphic ) {
1243
	if (ci & cinfo_polymorphic) {
1192
	/* Create dummy initialiser */
1244
		/* Create dummy initialiser */
1193
	MAKE_exp_initialiser ( type_void, NULL_list ( EXP ),
1245
		MAKE_exp_initialiser(type_void, NULL_list(EXP),
1194
		NULL_list ( OFFSET ), DEFAULT_PRELUDE, 0, 0, r ) ;
1246
				     NULL_list(OFFSET), DEFAULT_PRELUDE, 0, 0,
-
 
1247
				     r);
1195
    }
1248
	}
1196
    return ( r ) ;
1249
	return (r);
1197
}
1250
}
1198
 
1251
 
1199
 
1252
 
1200
/*
1253
/*
1201
    COPY A CONSTRUCTOR INITIALISER LIST
1254
    COPY A CONSTRUCTOR INITIALISER LIST
1202
 
1255
 
1203
    This routine copies the constructor initialiser list of type m.
1256
    This routine copies the constructor initialiser list of type m.
1204
*/
1257
*/
1205
 
1258
 
1206
EXP copy_ctor
1259
EXP
1207
    PROTO_N ( ( e, m ) )
-
 
1208
    PROTO_T ( EXP e X int m )
1260
copy_ctor(EXP e, int m)
1209
{
1261
{
1210
    IDENTIFIER fn = crt_func_id ;
1262
	IDENTIFIER fn = crt_func_id;
1211
    NAMESPACE cns = DEREF_nspace ( id_parent ( fn ) ) ;
1263
	NAMESPACE cns = DEREF_nspace(id_parent(fn));
1212
    LIST ( EXP ) p = DEREF_list ( exp_initialiser_args ( e ) ) ;
1264
	LIST(EXP)p = DEREF_list(exp_initialiser_args(e));
1213
    LIST ( OFFSET ) q = DEREF_list ( exp_initialiser_offs ( e ) ) ;
1265
	LIST(OFFSET)q = DEREF_list(exp_initialiser_offs(e));
1214
    if ( !IS_NULL_list ( p ) ) {
1266
	if (!IS_NULL_list(p)) {
1215
	/* Copy initialisers */
1267
		/* Copy initialisers */
1216
	while ( !IS_NULL_list ( p ) && !IS_NULL_list ( q ) ) {
1268
		while (!IS_NULL_list(p) && !IS_NULL_list(q)) {
1217
	    int redo = 0 ;
1269
			int redo = 0;
1218
	    IDENTIFIER id = NULL_id ;
1270
			IDENTIFIER id = NULL_id;
1219
	    EXP a = DEREF_exp ( HEAD_list ( p ) ) ;
1271
			EXP a = DEREF_exp(HEAD_list(p));
1220
	    OFFSET off = DEREF_off ( HEAD_list ( q ) ) ;
1272
			OFFSET off = DEREF_off(HEAD_list(q));
1221
	    EXP b = implicit_cast_exp ( a ) ;
1273
			EXP b = implicit_cast_exp(a);
1222
	    if ( !IS_NULL_exp ( b ) && !EQ_exp ( b, a ) ) {
1274
			if (!IS_NULL_exp(b) && !EQ_exp(b, a)) {
1223
		redo = 1 ;
1275
				redo = 1;
1224
		a = b ;
1276
				a = b;
1225
	    }
1277
			}
1226
	    a = copy_exp ( a, NULL_type, NULL_type ) ;
1278
			a = copy_exp(a, NULL_type, NULL_type);
1227
	    if ( redo && !IS_exp_initialiser ( a ) ) {
1279
			if (redo && !IS_exp_initialiser(a)) {
1228
		/* Turn expression into ctor-initialiser list */
1280
				/* Turn expression into ctor-initialiser list */
1229
		LIST ( EXP ) r = NULL_list ( EXP ) ;
1281
				LIST(EXP)r = NULL_list(EXP);
1230
		LIST ( OFFSET ) s = NULL_list ( OFFSET ) ;
1282
				LIST(OFFSET)s = NULL_list(OFFSET);
1231
		CONS_exp ( a, r, r ) ;
1283
				CONS_exp(a, r, r);
1232
		MAKE_exp_initialiser ( type_void, r, s, 0, 0, 0, a ) ;
1284
				MAKE_exp_initialiser(type_void, r, s, 0, 0, 0,
-
 
1285
						     a);
1233
	    }
1286
			}
1234
	    off = copy_offset ( off, lex_plus ) ;
1287
			off = copy_offset(off, lex_plus);
1235
	    switch ( TAG_off ( off ) ) {
1288
			switch (TAG_off(off)) {
1236
		case off_member_tag : {
1289
			case off_member_tag: {
1237
		    /* Member initialiser */
1290
				/* Member initialiser */
1238
		    id = DEREF_id ( off_member_id ( off ) ) ;
1291
				id = DEREF_id(off_member_id(off));
1239
		    break ;
1292
				break;
1240
		}
1293
			}
1241
		case off_base_tag : {
1294
			case off_base_tag: {
1242
		    /* Direct base class initialiser */
1295
				/* Direct base class initialiser */
1243
		    GRAPH gr = DEREF_graph ( off_base_graph ( off ) ) ;
1296
				GRAPH gr = DEREF_graph(off_base_graph(off));
1244
		    CLASS_TYPE ct = DEREF_ctype ( graph_head ( gr ) ) ;
1297
				CLASS_TYPE ct = DEREF_ctype(graph_head(gr));
1245
		    id = DEREF_id ( ctype_name ( ct ) ) ;
1298
				id = DEREF_id(ctype_name(ct));
1246
		    break ;
1299
				break;
1247
		}
1300
			}
1248
		case off_deriv_tag : {
1301
			case off_deriv_tag: {
1249
		    /* Indirect base class initialiser */
1302
				/* Indirect base class initialiser */
1250
		    GRAPH gr = DEREF_graph ( off_deriv_graph ( off ) ) ;
1303
				GRAPH gr = DEREF_graph(off_deriv_graph(off));
1251
		    CLASS_TYPE ct = DEREF_ctype ( graph_head ( gr ) ) ;
1304
				CLASS_TYPE ct = DEREF_ctype(graph_head(gr));
1252
		    id = DEREF_id ( ctype_name ( ct ) ) ;
1305
				id = DEREF_id(ctype_name(ct));
1253
		    break ;
1306
				break;
-
 
1307
			}
-
 
1308
			}
-
 
1309
			if (!IS_NULL_id(id)) {
-
 
1310
				/* Add initialiser to list */
-
 
1311
				ctor_initialise(cns, id, a);
-
 
1312
			}
-
 
1313
			q = TAIL_list(q);
-
 
1314
			p = TAIL_list(p);
1254
		}
1315
		}
1255
	    }
-
 
1256
	    if ( !IS_NULL_id ( id ) ) {
-
 
1257
		/* Add initialiser to list */
-
 
1258
		ctor_initialise ( cns, id, a ) ;
-
 
1259
	    }
-
 
1260
	    q = TAIL_list ( q ) ;
-
 
1261
	    p = TAIL_list ( p ) ;
-
 
1262
	}
1316
	}
1263
    }
-
 
1264
    e = make_constr ( cns, fn, DEFAULT_USR, m ) ;
1317
	e = make_constr(cns, fn, DEFAULT_USR, m);
1265
    destroy_ctor_lists () ;
1318
	destroy_ctor_lists();
1266
    return ( e ) ;
1319
	return (e);
1267
}
1320
}
1268
 
1321
 
1269
 
1322
 
1270
/*
1323
/*
1271
    BEGIN A CONSTRUCTOR INITIALISER LIST
1324
    BEGIN A CONSTRUCTOR INITIALISER LIST
1272
 
1325
 
1273
    This routine is called at the start of a ctor-initialiser list to
1326
    This routine is called at the start of a ctor-initialiser list to
1274
    check that the current function is a constructor.  If so it returns
1327
    check that the current function is a constructor.  If so it returns
1275
    the corresponding class namespace.  Otherwise the null namespace
1328
    the corresponding class namespace.  Otherwise the null namespace
1276
    is returned.
1329
    is returned.
1277
*/
1330
*/
1278
 
1331
 
1279
NAMESPACE ctor_begin
1332
NAMESPACE
1280
    PROTO_Z ()
1333
ctor_begin(void)
1281
{
1334
{
1282
    IDENTIFIER id = crt_func_id ;
1335
	IDENTIFIER id = crt_func_id;
1283
    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
1336
	HASHID nm = DEREF_hashid(id_name(id));
1284
    if ( IS_hashid_constr ( nm ) ) {
1337
	if (IS_hashid_constr(nm)) {
1285
	TYPE t = DEREF_type ( hashid_constr_type ( nm ) ) ;
1338
		TYPE t = DEREF_type(hashid_constr_type(nm));
1286
	if ( IS_type_compound ( t ) ) {
1339
		if (IS_type_compound(t)) {
1287
	    CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
1340
			CLASS_TYPE ct = DEREF_ctype(type_compound_defn(t));
1288
	    NAMESPACE cns = DEREF_nspace ( ctype_member ( ct ) ) ;
1341
			NAMESPACE cns = DEREF_nspace(ctype_member(ct));
1289
	    return ( cns ) ;
1342
			return (cns);
1290
	}
1343
		}
1291
    }
1344
	}
1292
    report ( crt_loc, ERR_class_base_init_bad ( id ) ) ;
1345
	report(crt_loc, ERR_class_base_init_bad(id));
1293
    return ( NULL_nspace ) ;
1346
	return (NULL_nspace);
1294
}
1347
}
1295
 
1348
 
1296
 
1349
 
1297
/*
1350
/*
1298
    END A CONSTRUCTOR INITIALISER LIST
1351
    END A CONSTRUCTOR INITIALISER LIST
1299
 
1352
 
1300
    This routine is called at the end of a ctor-initialiser list.  cns
1353
    This routine is called at the end of a ctor-initialiser list.  cns
1301
    gives the class namespace, e is the compound statement to which
1354
    gives the class namespace, e is the compound statement to which
1302
    the initialisers are to be added and elem is true if the list was
1355
    the initialisers are to be added and elem is true if the list was
1303
    not empty.  The routine returns the resultant compound statement.
1356
    not empty.  The routine returns the resultant compound statement.
1304
*/
1357
*/
1305
 
1358
 
1306
EXP ctor_end
1359
EXP
1307
    PROTO_N ( ( cns, e, elem ) )
-
 
1308
    PROTO_T ( NAMESPACE cns X EXP e X int elem )
1360
ctor_end(NAMESPACE cns, EXP e, int elem)
1309
{
1361
{
1310
    if ( !IS_NULL_nspace ( cns ) ) {
1362
	if (!IS_NULL_nspace(cns)) {
1311
	/* Construct the constructor */
1363
		/* Construct the constructor */
1312
	IDENTIFIER id = crt_func_id ;
1364
		IDENTIFIER id = crt_func_id;
-
 
1365
		if (!elem) {
1313
	if ( !elem ) report ( crt_loc, ERR_class_base_init_empty ( id ) ) ;
1366
			report(crt_loc, ERR_class_base_init_empty(id));
-
 
1367
		}
1314
	if ( IS_id_mem_func ( id ) ) {
1368
		if (IS_id_mem_func(id)) {
1315
	    EXP c = make_constr ( cns, id, DEFAULT_USR, DEFAULT_CONSTR ) ;
1369
			EXP c = make_constr(cns, id, DEFAULT_USR,
-
 
1370
					    DEFAULT_CONSTR);
1316
	    if ( !IS_NULL_exp ( c ) ) {
1371
			if (!IS_NULL_exp(c)) {
1317
		e = add_compound_stmt ( e, c ) ;
1372
				e = add_compound_stmt(e, c);
1318
	    }
1373
			}
1319
	}
1374
		}
1320
	destroy_ctor_lists () ;
1375
		destroy_ctor_lists();
1321
    }
1376
	}
1322
    return ( e ) ;
1377
	return (e);
1323
}
1378
}
1324
 
1379
 
1325
 
1380
 
1326
/*
1381
/*
1327
    HANDLE AN ABSENT CONSTRUCTOR INITIALISER LIST
1382
    HANDLE AN ABSENT CONSTRUCTOR INITIALISER LIST
1328
 
1383
 
1329
    This routine is called for a function definition which contains no
1384
    This routine is called for a function definition which contains no
1330
    ctor-initialiser.  e gives the compound statement giving the function
1385
    ctor-initialiser.  e gives the compound statement giving the function
1331
    body.  The routine returns the value of e after any initialisers
1386
    body.  The routine returns the value of e after any initialisers
1332
    required for constructors have been added.  Any destructors which need
1387
    required for constructors have been added.  Any destructors which need
1333
    to be called at the end of the function are returned via p.
1388
    to be called at the end of the function are returned via p.
1334
*/
1389
*/
1335
 
1390
 
1336
EXP ctor_none
1391
EXP
1337
    PROTO_N ( ( e, p ) )
-
 
1338
    PROTO_T ( EXP e X EXP *p )
1392
ctor_none(EXP e, EXP *p)
1339
{
1393
{
1340
    IDENTIFIER id = crt_func_id ;
1394
	IDENTIFIER id = crt_func_id;
1341
    if ( IS_id_mem_func ( id ) ) {
1395
	if (IS_id_mem_func(id)) {
1342
	HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
1396
		HASHID nm = DEREF_hashid(id_name(id));
1343
	switch ( TAG_hashid ( nm ) ) {
1397
		switch (TAG_hashid(nm)) {
1344
	    case hashid_constr_tag : {
1398
		case hashid_constr_tag: {
1345
		/* Constructor declarations */
1399
			/* Constructor declarations */
1346
		NAMESPACE cns = DEREF_nspace ( id_parent ( id ) ) ;
1400
			NAMESPACE cns = DEREF_nspace(id_parent(id));
1347
		EXP c = make_constr ( cns, id, DEFAULT_USR, DEFAULT_CONSTR ) ;
1401
			EXP c = make_constr(cns, id, DEFAULT_USR,
-
 
1402
					    DEFAULT_CONSTR);
1348
		if ( !IS_NULL_exp ( c ) ) {
1403
			if (!IS_NULL_exp(c)) {
1349
		    /* Add initialiser to function body */
1404
				/* Add initialiser to function body */
1350
		    e = add_compound_stmt ( e, c ) ;
1405
				e = add_compound_stmt(e, c);
1351
		}
1406
			}
1352
		break ;
1407
			break;
1353
	    }
1408
		}
1354
	    case hashid_destr_tag : {
1409
		case hashid_destr_tag: {
1355
		/* Destructor declarations */
1410
			/* Destructor declarations */
1356
		NAMESPACE cns = DEREF_nspace ( id_parent ( id ) ) ;
1411
			NAMESPACE cns = DEREF_nspace(id_parent(id));
1357
		EXP c = make_destr_prelude ( cns ) ;
1412
			EXP c = make_destr_prelude(cns);
1358
		EXP d = make_constr ( cns, id, DEFAULT_USR, DEFAULT_DESTR ) ;
1413
			EXP d = make_constr(cns, id, DEFAULT_USR,
-
 
1414
					    DEFAULT_DESTR);
1359
		if ( !IS_NULL_exp ( c ) ) {
1415
			if (!IS_NULL_exp(c)) {
1360
		    /* Add destructor prelude to function body */
1416
				/* Add destructor prelude to function body */
1361
		    e = add_compound_stmt ( e, c ) ;
1417
				e = add_compound_stmt(e, c);
1362
		}
1418
			}
1363
		if ( !IS_NULL_exp ( d ) ) {
1419
			if (!IS_NULL_exp(d)) {
1364
		    /* Set up destructor postlude */
1420
				/* Set up destructor postlude */
1365
		    IDENTIFIER lab = postlude_label () ;
1421
				IDENTIFIER lab = postlude_label();
1366
		    EXP a = begin_label_stmt ( lab, lex_return ) ;
1422
				EXP a = begin_label_stmt(lab, lex_return);
1367
		    *p = end_label_stmt ( a, d ) ;
1423
				*p = end_label_stmt(a, d);
1368
		}
1424
			}
1369
		break ;
1425
			break;
-
 
1426
		}
1370
	    }
1427
		}
1371
	}
1428
	}
1372
    }
-
 
1373
    return ( e ) ;
1429
	return (e);
1374
}
1430
}
1375
 
1431
 
1376
 
1432
 
1377
/*
1433
/*
1378
    ADD A POSTLUDE TO A FUNCTION BODY
1434
    ADD A POSTLUDE TO A FUNCTION BODY
Line 1380... Line 1436...
1380
    This routine adds the postlude expression d to the end of the
1436
    This routine adds the postlude expression d to the end of the
1381
    function body e.  This is used in user declared destructors where the
1437
    function body e.  This is used in user declared destructors where the
1382
    default destructors need to be called after the main function body.
1438
    default destructors need to be called after the main function body.
1383
    For convenience the code for falling out of a normal function body
1439
    For convenience the code for falling out of a normal function body
1384
    is also handled by this routine.
1440
    is also handled by this routine.
1385
*/
1441
*/
1386
 
1442
 
1387
EXP ctor_postlude
1443
EXP
1388
    PROTO_N ( ( e, d ) )
-
 
1389
    PROTO_T ( EXP e X EXP d )
1444
ctor_postlude(EXP e, EXP d)
1390
{
1445
{
1391
    if ( !IS_NULL_exp ( d ) ) {
1446
	if (!IS_NULL_exp(d)) {
1392
	/* Add postlude expression */
1447
		/* Add postlude expression */
1393
	EXP r ;
1448
		EXP r;
1394
	unreached_code = 0 ;
1449
		unreached_code = 0;
1395
	e = add_compound_stmt ( e, d ) ;
1450
		e = add_compound_stmt(e, d);
1396
	unreached_code = 0 ;
1451
		unreached_code = 0;
1397
	MAKE_exp_return_stmt ( type_bottom, NULL_exp, r ) ;
1452
		MAKE_exp_return_stmt(type_bottom, NULL_exp, r);
1398
	e = add_compound_stmt ( e, r ) ;
1453
		e = add_compound_stmt(e, r);
1399
	unreached_code = 1 ;
1454
		unreached_code = 1;
1400
	unreached_last = 0 ;
1455
		unreached_last = 0;
1401
    } else {
1456
	} else {
1402
	/* Fall out of function */
1457
		/* Fall out of function */
1403
	if ( !unreached_code ) {
1458
		if (!unreached_code) {
1404
	    EXP r = fall_return_stmt () ;
1459
			EXP r = fall_return_stmt();
1405
	    e = add_compound_stmt ( e, r ) ;
1460
			e = add_compound_stmt(e, r);
-
 
1461
		}
1406
	}
1462
	}
1407
    }
-
 
1408
    return ( e ) ;
1463
	return (e);
1409
}
1464
}
1410
 
1465
 
1411
 
1466
 
1412
/*
1467
/*
1413
    CREATE AN EXCEPTION POSTLUDE EXPRESSION
1468
    CREATE AN EXCEPTION POSTLUDE EXPRESSION
1414
 
1469
 
1415
    This routine creates an expression which will be called in the exception
1470
    This routine creates an expression which will be called in the exception
1416
    specifier for the function id.  This is used in constructors to destroy
1471
    specifier for the function id.  This is used in constructors to destroy
1417
    the partially complete object.
1472
    the partially complete object.
1418
*/
1473
*/
1419
 
1474
 
1420
EXP except_postlude
1475
EXP
1421
    PROTO_N ( ( id ) )
-
 
1422
    PROTO_T ( IDENTIFIER id )
1476
except_postlude(IDENTIFIER id)
1423
{
1477
{
1424
    EXP e = NULL_exp ;
1478
	EXP e = NULL_exp;
1425
    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
1479
	HASHID nm = DEREF_hashid(id_name(id));
1426
    if ( IS_hashid_constr ( nm ) ) {
1480
	if (IS_hashid_constr(nm)) {
1427
	/* Have a constructor */
1481
		/* Have a constructor */
1428
	TYPE t = DEREF_type ( hashid_constr_type ( nm ) ) ;
1482
		TYPE t = DEREF_type(hashid_constr_type(nm));
1429
	if ( IS_type_compound ( t ) ) {
1483
		if (IS_type_compound(t)) {
1430
	    CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
1484
			CLASS_TYPE ct = DEREF_ctype(type_compound_defn(t));
1431
	    NAMESPACE cns = DEREF_nspace ( ctype_member ( ct ) ) ;
1485
			NAMESPACE cns = DEREF_nspace(ctype_member(ct));
1432
	    DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
1486
			DECL_SPEC ds = DEREF_dspec(id_storage(id));
1433
	    if ( !( ds & ( dspec_friend | dspec_trivial ) ) ) {
1487
			if (!(ds & (dspec_friend | dspec_trivial))) {
1434
		/* Constructor may throw an exception */
1488
				/* Constructor may throw an exception */
1435
		int ac = do_access_checks ;
1489
				int ac = do_access_checks;
1436
		EXP a = DEREF_exp ( id_function_etc_defn ( id ) ) ;
1490
				EXP a = DEREF_exp(id_function_etc_defn(id));
1437
		if ( !IS_NULL_exp ( a ) && IS_exp_initialiser ( a ) ) {
1491
				if (!IS_NULL_exp(a) && IS_exp_initialiser(a)) {
1438
		    LIST ( EXP ) p ;
1492
					LIST(EXP)p;
1439
		    p = DEREF_list ( exp_initialiser_args ( a ) ) ;
1493
					p = DEREF_list(exp_initialiser_args(a));
1440
		    if ( LENGTH_list ( p ) == 1 ) {
1494
					if (LENGTH_list(p) == 1) {
1441
			/* Single initialiser in constructor */
1495
						/* Single initialiser in constructor */
1442
			a = DEREF_exp ( HEAD_list ( p ) ) ;
1496
						a = DEREF_exp(HEAD_list(p));
1443
			if ( !IS_NULL_exp ( a ) ) {
1497
						if (!IS_NULL_exp(a)) {
1444
			    TYPE s = DEREF_type ( exp_type ( a ) ) ;
1498
							TYPE s = DEREF_type(exp_type(a));
1445
			    if ( !IS_type_array ( s ) ) return ( e ) ;
1499
							if (!IS_type_array(s)) {
-
 
1500
								return (e);
-
 
1501
							}
1446
			}
1502
						}
1447
		    }
1503
					}
1448
		}
1504
				}
1449
		do_access_checks = 0 ;
1505
				do_access_checks = 0;
1450
		COPY_dspec ( id_storage ( id ), ( ds | dspec_trivial ) ) ;
1506
				COPY_dspec(id_storage(id), (ds | dspec_trivial));
1451
		start_try_check ( univ_type_set ) ;
1507
				start_try_check(univ_type_set);
1452
		e = make_constr ( cns, id, DEFAULT_DESTR, DEFAULT_DESTR ) ;
1508
				e = make_constr(cns, id, DEFAULT_DESTR, DEFAULT_DESTR);
1453
		if ( !IS_NULL_exp ( e ) ) {
1509
				if (!IS_NULL_exp(e)) {
1454
		    /* Add destructor prelude */
1510
					/* Add destructor prelude */
1455
		    EXP d = make_destr_prelude ( cns ) ;
1511
					EXP d = make_destr_prelude(cns);
1456
		    e = join_exp ( d, e ) ;
1512
					e = join_exp(d, e);
-
 
1513
				}
-
 
1514
				e = end_try_check(id, e);
-
 
1515
				COPY_dspec(id_storage(id), ds);
-
 
1516
				do_access_checks = ac;
-
 
1517
			}
1457
		}
1518
		}
1458
		e = end_try_check ( id, e ) ;
-
 
1459
		COPY_dspec ( id_storage ( id ), ds ) ;
-
 
1460
		do_access_checks = ac ;
-
 
1461
	    }
-
 
1462
	}
1519
	}
1463
    }
-
 
1464
    return ( e ) ;
1520
	return (e);
1465
}
1521
}
1466
 
1522
 
1467
 
1523
 
1468
/*
1524
/*
1469
    FIND INITIALISATION ORDER OF TWO BASE GRAPHS
1525
    FIND INITIALISATION ORDER OF TWO BASE GRAPHS
1470
 
1526
 
1471
    This routine compares the order of initialisation of the base graphs
1527
    This routine compares the order of initialisation of the base graphs
1472
    gr and gs.  It returns 1 if gr is initialised before gs, -1 if gr is
1528
    gr and gs.  It returns 1 if gr is initialised before gs, -1 if gr is
1473
    initialised before gr and 0 if they are equal.  Note that virtual
1529
    initialised before gr and 0 if they are equal.  Note that virtual
1474
    bases are initialised before direct bases.
1530
    bases are initialised before direct bases.
1475
*/
1531
*/
1476
 
1532
 
1477
static int compare_base
1533
static int
1478
    PROTO_N ( ( gr, gs ) )
-
 
1479
    PROTO_T ( GRAPH gr X GRAPH gs )
1534
compare_base(GRAPH gr, GRAPH gs)
1480
{
1535
{
1481
    DECL_SPEC ar, as ;
1536
	DECL_SPEC ar, as;
1482
    LIST ( GRAPH ) br ;
1537
	LIST(GRAPH)br;
1483
    if ( eq_graph ( gr, gs ) ) return ( 0 ) ;
1538
	if (eq_graph(gr, gs)) {
-
 
1539
		return (0);
-
 
1540
	}
1484
    ar = DEREF_dspec ( graph_access ( gr ) ) ;
1541
	ar = DEREF_dspec(graph_access(gr));
1485
    as = DEREF_dspec ( graph_access ( gs ) ) ;
1542
	as = DEREF_dspec(graph_access(gs));
1486
    if ( ar & dspec_virtual ) {
1543
	if (ar & dspec_virtual) {
1487
	if ( as & dspec_virtual ) {
1544
		if (as & dspec_virtual) {
1488
	    GRAPH gt = DEREF_graph ( graph_top ( gr ) ) ;
1545
			GRAPH gt = DEREF_graph(graph_top(gr));
1489
	    CLASS_TYPE ct = DEREF_ctype ( graph_head ( gt ) ) ;
1546
			CLASS_TYPE ct = DEREF_ctype(graph_head(gt));
1490
	    br = DEREF_list ( ctype_vbase ( ct ) ) ;
1547
			br = DEREF_list(ctype_vbase(ct));
-
 
1548
		} else {
-
 
1549
			return (1);
-
 
1550
		}
1491
	} else {
1551
	} else {
-
 
1552
		if (as & dspec_virtual) {
1492
	    return ( 1 ) ;
1553
			return (-1);
-
 
1554
		} else {
-
 
1555
			GRAPH gt = DEREF_graph(graph_top(gr));
-
 
1556
			br = DEREF_list(graph_tails(gt));
-
 
1557
		}
1493
	}
1558
	}
1494
    } else {
1559
	while (!IS_NULL_list(br)) {
-
 
1560
		GRAPH gt = DEREF_graph(HEAD_list(br));
1495
	if ( as & dspec_virtual ) {
1561
		if (eq_graph(gt, gr)) {
1496
	    return ( -1 ) ;
1562
			return (1);
1497
	} else {
1563
		}
1498
	    GRAPH gt = DEREF_graph ( graph_top ( gr ) ) ;
1564
		if (eq_graph(gt, gs)) {
-
 
1565
			return (-1);
-
 
1566
		}
1499
	    br = DEREF_list ( graph_tails ( gt ) ) ;
1567
		br = TAIL_list(br);
1500
	}
1568
	}
1501
    }
-
 
1502
    while ( !IS_NULL_list ( br ) ) {
-
 
1503
	GRAPH gt = DEREF_graph ( HEAD_list ( br ) ) ;
-
 
1504
	if ( eq_graph ( gt, gr ) ) return ( 1 ) ;
-
 
1505
	if ( eq_graph ( gt, gs ) ) return ( -1 ) ;
-
 
1506
	br = TAIL_list ( br ) ;
-
 
1507
    }
-
 
1508
    return ( 0 ) ;
1569
	return (0);
1509
}
1570
}
1510
 
1571
 
1511
 
1572
 
1512
/*
1573
/*
1513
    FIND INITIALISATION ORDER OF TWO MEMBERS
1574
    FIND INITIALISATION ORDER OF TWO MEMBERS
1514
 
1575
 
1515
    This routine compares the order of initialisation of the members pid
1576
    This routine compares the order of initialisation of the members pid
1516
    and mid of the class namespace ns.  It returns 1 if mid is initialised
1577
    and mid of the class namespace ns.  It returns 1 if mid is initialised
1517
    before pid, -1 if pid is initialised before mid and 0 if they are equal.
1578
    before pid, -1 if pid is initialised before mid and 0 if they are equal.
1518
*/
1579
*/
1519
 
1580
 
1520
static int compare_mem
1581
static int
1521
    PROTO_N ( ( ns, mid, pid ) )
-
 
1522
    PROTO_T ( NAMESPACE ns X IDENTIFIER mid X IDENTIFIER pid )
1582
compare_mem(NAMESPACE ns, IDENTIFIER mid, IDENTIFIER pid)
1523
{
1583
{
1524
    MEMBER mem ;
1584
	MEMBER mem;
1525
    if ( EQ_id ( mid, pid ) ) return ( 0 ) ;
1585
	if (EQ_id(mid, pid)) {
-
 
1586
		return (0);
-
 
1587
	}
1526
    mem = DEREF_member ( nspace_ctype_first ( ns ) ) ;
1588
	mem = DEREF_member(nspace_ctype_first(ns));
1527
    while ( !IS_NULL_member ( mem ) ) {
1589
	while (!IS_NULL_member(mem)) {
1528
	IDENTIFIER id = DEREF_id ( member_id ( mem ) ) ;
1590
		IDENTIFIER id = DEREF_id(member_id(mem));
1529
	if ( EQ_id ( id, mid ) ) return ( 1 ) ;
1591
		if (EQ_id(id, mid)) {
-
 
1592
			return (1);
-
 
1593
		}
1530
	if ( EQ_id ( id, pid ) ) return ( -1 ) ;
1594
		if (EQ_id(id, pid)) {
-
 
1595
			return (-1);
-
 
1596
		}
1531
	mem = DEREF_member ( member_next ( mem ) ) ;
1597
		mem = DEREF_member(member_next(mem));
1532
    }
1598
	}
1533
    return ( 0 ) ;
1599
	return (0);
1534
}
1600
}
1535
 
1601
 
1536
 
1602
 
1537
/*
1603
/*
1538
    NAME LOOK-UP FOR CONSTRUCTOR INITIALISER
1604
    NAME LOOK-UP FOR CONSTRUCTOR INITIALISER
Line 1543... Line 1609...
1543
    anachronistic way of initialising the unique direct base class of
1609
    anachronistic way of initialising the unique direct base class of
1544
    cns, if this exists.  The null identifier is returned for illegal
1610
    cns, if this exists.  The null identifier is returned for illegal
1545
    initialisers.
1611
    initialisers.
1546
*/
1612
*/
1547
 
1613
 
1548
static IDENTIFIER ctor_field
1614
static IDENTIFIER
1549
    PROTO_N ( ( cns, id, pgr ) )
-
 
1550
    PROTO_T ( NAMESPACE cns X IDENTIFIER id X GRAPH *pgr )
1615
ctor_field(NAMESPACE cns, IDENTIFIER id, GRAPH *pgr)
1551
{
1616
{
1552
    if ( !IS_NULL_nspace ( cns ) ) {
1617
	if (!IS_NULL_nspace(cns)) {
1553
	if ( IS_NULL_id ( id ) ) {
1618
		if (IS_NULL_id(id)) {
1554
	    /* Search for unique base class */
1619
			/* Search for unique base class */
1555
	    ERROR err = ERR_class_base_init_old ( crt_func_id ) ;
1620
			ERROR err = ERR_class_base_init_old(crt_func_id);
1556
	    CLASS_TYPE ct = namespace_class ( cns ) ;
1621
			CLASS_TYPE ct = namespace_class(cns);
1557
	    GRAPH gr = uniq_base_class ( ct, &err ) ;
1622
			GRAPH gr = uniq_base_class(ct, &err);
1558
	    if ( !IS_NULL_graph ( gr ) ) {
1623
			if (!IS_NULL_graph(gr)) {
1559
		ct = DEREF_ctype ( graph_head ( gr ) ) ;
1624
				ct = DEREF_ctype(graph_head(gr));
1560
		id = DEREF_id ( ctype_name ( ct ) ) ;
1625
				id = DEREF_id(ctype_name(ct));
1561
		*pgr = gr ;
1626
				*pgr = gr;
1562
	    } else {
-
 
1563
		id = NULL_id ;
-
 
1564
	    }
-
 
1565
	    report ( crt_loc, err ) ;
-
 
1566
 
-
 
1567
	} else {
-
 
1568
	    /* Look up name as class member */
-
 
1569
	    GRAPH gr ;
-
 
1570
	    int check_base = 1 ;
-
 
1571
	    IDENTIFIER fid = id ;
-
 
1572
	    NAMESPACE fns = DEREF_nspace ( id_parent ( fid ) ) ;
-
 
1573
	    if ( EQ_nspace ( fns, crt_namespace ) ) {
-
 
1574
		/* Rescan constructor parameters in enclosing scope */
-
 
1575
		HASHID nm = DEREF_hashid ( id_name ( fid ) ) ;
-
 
1576
		int c = cache_lookup ;
-
 
1577
		cache_lookup = 0 ;
-
 
1578
		remove_namespace () ;
-
 
1579
		fid = find_id ( nm ) ;
-
 
1580
		add_namespace ( fns ) ;
-
 
1581
		cache_lookup = c ;
-
 
1582
		id = fid ;
-
 
1583
	    }
-
 
1584
 
-
 
1585
	    /* Check for class members */
-
 
1586
	    gr = is_subfield ( cns, fid ) ;
-
 
1587
	    if ( !IS_NULL_graph ( gr ) ) {
-
 
1588
		check_base = 0 ;
-
 
1589
		fid = search_subfield ( cns, gr, fid ) ;
-
 
1590
		switch ( TAG_id ( fid ) ) {
-
 
1591
		    case id_member_tag : {
-
 
1592
			/* Non-static data members */
-
 
1593
			DECL_SPEC ds = DEREF_dspec ( id_storage ( fid ) ) ;
-
 
1594
			if ( ds & dspec_inherit ) {
-
 
1595
			    /* Can't denote an inherited member */
-
 
1596
			    ERROR err ;
-
 
1597
			    err = ERR_class_base_init_inherit ( fid ) ;
-
 
1598
			    report ( crt_loc, err ) ;
-
 
1599
			    id = NULL_id ;
-
 
1600
			} else {
1627
			} else {
1601
			    id = fid ;
1628
				id = NULL_id;
1602
			}
1629
			}
1603
			break ;
-
 
1604
		    }
-
 
1605
		    case id_class_name_tag :
-
 
1606
		    case id_class_alias_tag : {
-
 
1607
			/* Check for base classes */
-
 
1608
			check_base = 1 ;
-
 
1609
			break ;
-
 
1610
		    }
-
 
1611
		    case id_undef_tag : {
-
 
1612
			/* Undeclared members */
-
 
1613
			HASHID nm = DEREF_hashid ( id_name ( fid ) ) ;
-
 
1614
			ERROR err = ERR_lookup_qual_undef ( nm, fns ) ;
-
 
1615
			report ( crt_loc, err ) ;
1630
			report(crt_loc, err);
1616
			id = NULL_id ;
-
 
1617
			break ;
-
 
1618
		    }
-
 
1619
		    case id_ambig_tag : {
-
 
1620
			/* Ambiguous members */
-
 
1621
			id = report_ambiguous ( fid, 0, 1, 1 ) ;
-
 
1622
			break ;
-
 
1623
		    }
-
 
1624
		    default : {
-
 
1625
			/* Other members */
-
 
1626
			ERROR err = ERR_class_base_init_static ( fid ) ;
-
 
1627
			report ( crt_loc, err ) ;
-
 
1628
			id = NULL_id ;
-
 
1629
			break ;
-
 
1630
		    }
-
 
1631
		}
-
 
1632
	    }
-
 
1633
 
1631
 
1634
	    /* Check for base classes */
-
 
1635
	    if ( check_base ) {
-
 
1636
		CLASS_TYPE cs = find_class ( fid ) ;
-
 
1637
		if ( IS_NULL_ctype ( cs ) && IS_id_undef ( fid ) ) {
-
 
1638
		    TYPE s = check_typename ( fns, fid, btype_class ) ;
-
 
1639
		    if ( !IS_NULL_type ( s ) && IS_type_compound ( s ) ) {
-
 
1640
			cs = DEREF_ctype ( type_compound_defn ( s ) ) ;
-
 
1641
		    }
-
 
1642
		}
-
 
1643
		if ( !IS_NULL_ctype ( cs ) ) {
-
 
1644
		    /* Class name found */
-
 
1645
		    ERROR err = NULL_err ;
-
 
1646
		    CLASS_TYPE ct = namespace_class ( cns ) ;
-
 
1647
		    gr = direct_base_class ( ct, cs, &err ) ;
-
 
1648
		    if ( !IS_NULL_err ( err ) ) {
-
 
1649
			/* Report invalid bases */
-
 
1650
			report ( crt_loc, err ) ;
-
 
1651
		    }
-
 
1652
		    if ( !IS_NULL_graph ( gr ) ) {
-
 
1653
			id = DEREF_id ( ctype_name ( cs ) ) ;
-
 
1654
			*pgr = gr ;
-
 
1655
		    } else {
-
 
1656
			id = NULL_id ;
-
 
1657
		    }
-
 
1658
		} else {
1632
		} else {
-
 
1633
			/* Look up name as class member */
-
 
1634
			GRAPH gr;
-
 
1635
			int check_base = 1;
-
 
1636
			IDENTIFIER fid = id;
-
 
1637
			NAMESPACE fns = DEREF_nspace(id_parent(fid));
-
 
1638
			if (EQ_nspace(fns, crt_namespace)) {
-
 
1639
				/* Rescan constructor parameters in enclosing
-
 
1640
				 * scope */
-
 
1641
				HASHID nm = DEREF_hashid(id_name(fid));
-
 
1642
				int c = cache_lookup;
-
 
1643
				cache_lookup = 0;
-
 
1644
				remove_namespace();
-
 
1645
				fid = find_id(nm);
-
 
1646
				add_namespace(fns);
-
 
1647
				cache_lookup = c;
-
 
1648
				id = fid;
-
 
1649
			}
-
 
1650
 
-
 
1651
			/* Check for class members */
-
 
1652
			gr = is_subfield(cns, fid);
-
 
1653
			if (!IS_NULL_graph(gr)) {
-
 
1654
				check_base = 0;
-
 
1655
				fid = search_subfield(cns, gr, fid);
-
 
1656
				switch (TAG_id(fid)) {
-
 
1657
				case id_member_tag: {
-
 
1658
					/* Non-static data members */
-
 
1659
					DECL_SPEC ds =
-
 
1660
					    DEREF_dspec(id_storage(fid));
-
 
1661
					if (ds & dspec_inherit) {
-
 
1662
						/* Can't denote an inherited
-
 
1663
						 * member */
-
 
1664
						ERROR err;
-
 
1665
						err = ERR_class_base_init_inherit(fid);
-
 
1666
						report(crt_loc, err);
-
 
1667
						id = NULL_id;
-
 
1668
					} else {
-
 
1669
						id = fid;
-
 
1670
					}
-
 
1671
					break;
-
 
1672
				}
-
 
1673
				case id_class_name_tag:
-
 
1674
				case id_class_alias_tag: {
-
 
1675
					/* Check for base classes */
-
 
1676
					check_base = 1;
-
 
1677
					break;
-
 
1678
				}
-
 
1679
				case id_undef_tag: {
-
 
1680
					/* Undeclared members */
-
 
1681
					HASHID nm = DEREF_hashid(id_name(fid));
-
 
1682
					ERROR err =
-
 
1683
					    ERR_lookup_qual_undef(nm, fns);
-
 
1684
					report(crt_loc, err);
-
 
1685
					id = NULL_id;
-
 
1686
					break;
-
 
1687
				}
-
 
1688
				case id_ambig_tag: {
-
 
1689
					/* Ambiguous members */
-
 
1690
					id = report_ambiguous(fid, 0, 1, 1);
-
 
1691
					break;
-
 
1692
				}
-
 
1693
				default : {
-
 
1694
					/* Other members */
-
 
1695
					ERROR err =
-
 
1696
					    ERR_class_base_init_static(fid);
-
 
1697
					report(crt_loc, err);
-
 
1698
					id = NULL_id;
-
 
1699
					break;
-
 
1700
				}
-
 
1701
				}
-
 
1702
			}
-
 
1703
 
-
 
1704
			/* Check for base classes */
-
 
1705
			if (check_base) {
-
 
1706
				CLASS_TYPE cs = find_class(fid);
-
 
1707
				if (IS_NULL_ctype(cs) && IS_id_undef(fid)) {
-
 
1708
					TYPE s = check_typename(fns, fid,
-
 
1709
								btype_class);
-
 
1710
					if (!IS_NULL_type(s) &&
-
 
1711
					    IS_type_compound(s)) {
-
 
1712
						cs = DEREF_ctype(type_compound_defn(s));
-
 
1713
					}
-
 
1714
				}
-
 
1715
				if (!IS_NULL_ctype(cs)) {
-
 
1716
					/* Class name found */
-
 
1717
					ERROR err = NULL_err;
-
 
1718
					CLASS_TYPE ct = namespace_class(cns);
-
 
1719
					gr = direct_base_class(ct, cs, &err);
-
 
1720
					if (!IS_NULL_err(err)) {
-
 
1721
						/* Report invalid bases */
-
 
1722
						report(crt_loc, err);
-
 
1723
					}
-
 
1724
					if (!IS_NULL_graph(gr)) {
-
 
1725
						id = DEREF_id(ctype_name(cs));
-
 
1726
						*pgr = gr;
-
 
1727
					} else {
-
 
1728
						id = NULL_id;
-
 
1729
					}
-
 
1730
				} else {
1659
		    /* Invalid ctor-initialiser */
1731
					/* Invalid ctor-initialiser */
1660
		    ERROR err = ERR_lookup_qual_bad ( id, cns ) ;
1732
					ERROR err = ERR_lookup_qual_bad(id, cns);
1661
		    report ( crt_loc, err ) ;
1733
					report(crt_loc, err);
1662
		    id = NULL_id ;
1734
					id = NULL_id;
1663
		}
1735
				}
1664
	    }
1736
			}
1665
	}
1737
		}
1666
    } else {
1738
	} else {
1667
	/* Invalid class namespace */
1739
		/* Invalid class namespace */
1668
	id = NULL_id ;
1740
		id = NULL_id;
1669
    }
1741
	}
1670
    return ( id ) ;
1742
	return (id);
1671
}
1743
}
1672
 
1744
 
1673
 
1745
 
1674
/*
1746
/*
1675
    PROCESS A CONSTRUCTOR INITIALISER
1747
    PROCESS A CONSTRUCTOR INITIALISER
1676
 
1748
 
1677
    This routine processes a ctor-initialiser which sets the id component
1749
    This routine processes a ctor-initialiser which sets the id component
1678
    of the current constructor function to the initialiser expression init.
1750
    of the current constructor function to the initialiser expression init.
1679
    cns gives the value returned by ctor_check.  id may be the null
1751
    cns gives the value returned by ctor_check.  id may be the null
1680
    identifier indicating the anachronistic single inheritance base class
1752
    identifier indicating the anachronistic single inheritance base class
1681
    initialisation.
1753
    initialisation.
1682
*/
1754
*/
1683
 
1755
 
1684
void ctor_initialise
1756
void
1685
    PROTO_N ( ( cns, id, init ) )
-
 
1686
    PROTO_T ( NAMESPACE cns X IDENTIFIER id X EXP init )
1757
ctor_initialise(NAMESPACE cns, IDENTIFIER id, EXP init)
1687
{
1758
{
1688
    TYPE t ;
1759
	TYPE t;
1689
    int n = 0 ;
1760
	int n = 0;
1690
    int ok = 1 ;
1761
	int ok = 1;
1691
    GRAPH gr = NULL_graph ;
1762
	GRAPH gr = NULL_graph;
1692
 
1763
 
1693
    /* Check member identifier */
1764
	/* Check member identifier */
1694
    IDENTIFIER mid = ctor_field ( cns, id, &gr ) ;
1765
	IDENTIFIER mid = ctor_field(cns, id, &gr);
1695
    if ( !IS_NULL_id ( mid ) ) {
1766
	if (!IS_NULL_id(mid)) {
1696
	EXP e ;
1767
		EXP e;
1697
	if ( IS_id_member ( mid ) ) {
1768
		if (IS_id_member(mid)) {
1698
	    /* Member initialiser */
1769
			/* Member initialiser */
1699
	    e = find_mem_init ( mid ) ;
1770
			e = find_mem_init(mid);
1700
	    t = DEREF_type ( id_member_type ( mid ) ) ;
1771
			t = DEREF_type(id_member_type(mid));
1701
	    n = 1 ;
1772
			n = 1;
-
 
1773
		} else {
-
 
1774
			/* Base class initialiser */
-
 
1775
			e = find_base_init(gr);
-
 
1776
			t = DEREF_type(id_class_name_etc_defn(mid));
-
 
1777
			if (in_template_decl) {
-
 
1778
				/* Allow for template parameters */
-
 
1779
				DECL_SPEC acc = DEREF_dspec(graph_access(gr));
-
 
1780
				if (acc & dspec_template) {
-
 
1781
					CLASS_TYPE ct =
-
 
1782
					    DEREF_ctype(graph_head(gr));
-
 
1783
					t = DEREF_type(ctype_form(ct));
-
 
1784
				}
-
 
1785
			}
-
 
1786
			n = 2;
-
 
1787
		}
-
 
1788
		if (!IS_NULL_exp(e)) {
-
 
1789
			/* Initialiser already given */
-
 
1790
			report(crt_loc, ERR_class_base_init_dup(mid));
-
 
1791
		}
-
 
1792
	} else {
-
 
1793
		/* Invalid initialiser */
-
 
1794
		HASHID nm = KEYWORD(lex_zzzz);
-
 
1795
		mid = DEREF_id(hashid_id(nm));
-
 
1796
		t = type_error;
-
 
1797
	}
-
 
1798
 
-
 
1799
	/* Check for order of initialisers */
-
 
1800
	if (init_base_last) {
-
 
1801
		/* Previous initialiser was a base */
-
 
1802
		if (n == 2) {
-
 
1803
			if (!IS_NULL_list(init_bases)) {
-
 
1804
				GRAPH gp = DEREF_graph(HEAD_list(init_bases));
-
 
1805
				int cmp = compare_base(gr, gp);
-
 
1806
				if (cmp > 0) {
-
 
1807
					ok = 0;
-
 
1808
				}
-
 
1809
			}
-
 
1810
		}
1702
	} else {
1811
	} else {
1703
	    /* Base class initialiser */
1812
		/* Previous initialiser was a member */
-
 
1813
		if (n == 1) {
1704
	    e = find_base_init ( gr ) ;
1814
			if (!IS_NULL_list(init_mems)) {
-
 
1815
				IDENTIFIER pid = DEREF_id(HEAD_list(init_mems));
1705
	    t = DEREF_type ( id_class_name_etc_defn ( mid ) ) ;
1816
				int cmp = compare_mem(cns, mid, pid);
1706
	    if ( in_template_decl ) {
1817
				if (cmp > 0) {
-
 
1818
					ok = 0;
-
 
1819
				}
-
 
1820
			}
-
 
1821
		} else if (n == 2) {
-
 
1822
			ok = 0;
-
 
1823
		}
-
 
1824
	}
-
 
1825
	if (!ok) {
1707
		/* Allow for template parameters */
1826
		/* Initialisers out of sequence */
1708
		DECL_SPEC acc = DEREF_dspec ( graph_access ( gr ) ) ;
1827
		report(crt_loc, ERR_class_base_init_order(mid));
-
 
1828
	}
-
 
1829
 
-
 
1830
	/* Perform initialisation */
1709
		if ( acc & dspec_template ) {
1831
	if (IS_exp_initialiser(init)) {
1710
		    CLASS_TYPE ct = DEREF_ctype ( graph_head ( gr ) ) ;
1832
		crt_access_list.inherit++;
-
 
1833
		decl_loc = crt_loc;
-
 
1834
		if (n == 2) {
1711
		    t = DEREF_type ( ctype_form ( ct ) ) ;
1835
			in_ctor_base_init = 1;
1712
		}
1836
		}
1713
	    }
-
 
1714
	    n = 2 ;
-
 
1715
	}
-
 
1716
	if ( !IS_NULL_exp ( e ) ) {
1837
		init = init_general(t, init, mid, 0);
1717
	    /* Initialiser already given */
1838
		in_ctor_base_init = 0;
1718
	    report ( crt_loc, ERR_class_base_init_dup ( mid ) ) ;
1839
		crt_access_list.inherit--;
1719
	}
1840
	}
1720
    } else {
1841
	if (n == 1) {
1721
	/* Invalid initialiser */
1842
		CONS_id(mid, init_mems, init_mems);
1722
	HASHID nm = KEYWORD ( lex_zzzz ) ;
-
 
1723
	mid = DEREF_id ( hashid_id ( nm ) ) ;
1843
		CONS_exp(init, val_mems, val_mems);
1724
	t = type_error ;
-
 
1725
    }
-
 
1726
 
-
 
1727
    /* Check for order of initialisers */
-
 
1728
    if ( init_base_last ) {
1844
		init_base_last = 0;
1729
	/* Previous initialiser was a base */
-
 
1730
	if ( n == 2 ) {
1845
	} else if (n == 2) {
1731
	    if ( !IS_NULL_list ( init_bases ) ) {
-
 
1732
		GRAPH gp = DEREF_graph ( HEAD_list ( init_bases ) ) ;
1846
		CONS_graph(gr, init_bases, init_bases);
1733
		int cmp = compare_base ( gr, gp ) ;
1847
		CONS_exp(init, val_bases, val_bases);
1734
		if ( cmp > 0 ) ok = 0 ;
1848
		init_base_last = 1;
1735
	    }
-
 
1736
	}
1849
	}
1737
    } else {
-
 
1738
	/* Previous initialiser was a member */
-
 
1739
	if ( n == 1 ) {
-
 
1740
	    if ( !IS_NULL_list ( init_mems ) ) {
-
 
1741
		IDENTIFIER pid = DEREF_id ( HEAD_list ( init_mems ) ) ;
-
 
1742
		int cmp = compare_mem ( cns, mid, pid ) ;
-
 
1743
		if ( cmp > 0 ) ok = 0 ;
-
 
1744
	    }
-
 
1745
	} else if ( n == 2 ) {
-
 
1746
	    ok = 0 ;
-
 
1747
	}
-
 
1748
    }
-
 
1749
    if ( !ok ) {
-
 
1750
	/* Initialisers out of sequence */
-
 
1751
	report ( crt_loc, ERR_class_base_init_order ( mid ) ) ;
-
 
1752
    }
-
 
1753
 
-
 
1754
    /* Perform initialisation */
-
 
1755
    if ( IS_exp_initialiser ( init ) ) {
-
 
1756
	crt_access_list.inherit++ ;
-
 
1757
	decl_loc = crt_loc ;
-
 
1758
	if ( n == 2 ) in_ctor_base_init = 1 ;
-
 
1759
	init = init_general ( t, init, mid, 0 ) ;
-
 
1760
	in_ctor_base_init = 0 ;
-
 
1761
	crt_access_list.inherit-- ;
-
 
1762
    }
-
 
1763
    if ( n == 1 ) {
-
 
1764
	CONS_id ( mid, init_mems, init_mems ) ;
-
 
1765
	CONS_exp ( init, val_mems, val_mems ) ;
-
 
1766
	init_base_last = 0 ;
-
 
1767
    } else if ( n == 2 ) {
-
 
1768
	CONS_graph ( gr, init_bases, init_bases ) ;
-
 
1769
	CONS_exp ( init, val_bases, val_bases ) ;
-
 
1770
	init_base_last = 1 ;
-
 
1771
    }
-
 
1772
    no_ctor_init++ ;
1850
	no_ctor_init++;
1773
    return ;
1851
	return;
1774
}
1852
}
1775
 
1853
 
1776
 
1854
 
1777
/*
1855
/*
1778
    CONSTRUCT A PSEUDO-DESTRUCTOR
1856
    CONSTRUCT A PSEUDO-DESTRUCTOR
1779
 
1857
 
1780
    This routine creates a pseudo-destructor with class name given by
1858
    This routine creates a pseudo-destructor with class name given by
1781
    id1 and b1 and destructor name given by id2 and b2.
1859
    id1 and b1 and destructor name given by id2 and b2.
1782
*/
1860
*/
1783
 
1861
 
1784
IDENTIFIER make_pseudo_destr
1862
IDENTIFIER
1785
    PROTO_N ( ( id1, b1, id2, b2 ) )
-
 
1786
    PROTO_T ( IDENTIFIER id1 X BASE_TYPE b1 X IDENTIFIER id2 X BASE_TYPE b2 )
1863
make_pseudo_destr(IDENTIFIER id1, BASE_TYPE b1, IDENTIFIER id2, BASE_TYPE b2)
1787
{
1864
{
1788
    HASHID nm ;
1865
	HASHID nm;
1789
    int create = 0 ;
1866
	int create = 0;
1790
    int rescan = 0 ;
1867
	int rescan = 0;
1791
    TYPE t1 = NULL_type ;
1868
	TYPE t1 = NULL_type;
1792
    TYPE t2 = NULL_type ;
1869
	TYPE t2 = NULL_type;
1793
    NAMESPACE ns = NULL_nspace ;
1870
	NAMESPACE ns = NULL_nspace;
1794
 
1871
 
1795
    /* Check class name */
1872
	/* Check class name */
1796
    if ( b1 == btype_none ) {
1873
	if (b1 == btype_none) {
1797
	if ( !IS_NULL_id ( id1 ) ) {
1874
		if (!IS_NULL_id(id1)) {
1798
	    ns = find_namespace ( id1 ) ;
1875
			ns = find_namespace(id1);
1799
	    if ( IS_id_class_name_etc ( id1 ) ) {
1876
			if (IS_id_class_name_etc(id1)) {
1800
		t1 = DEREF_type ( id_class_name_etc_defn ( id1 ) ) ;
1877
				t1 = DEREF_type(id_class_name_etc_defn(id1));
1801
		t1 = copy_typedef ( id1, t1, cv_none ) ;
1878
				t1 = copy_typedef(id1, t1, cv_none);
1802
		COPY_id ( type_name ( t1 ), id1 ) ;
1879
				COPY_id(type_name(t1), id1);
1803
		if ( IS_NULL_nspace ( ns ) ) {
1880
				if (IS_NULL_nspace(ns)) {
1804
		    ns = DEREF_nspace ( id_parent ( id1 ) ) ;
1881
					ns = DEREF_nspace(id_parent(id1));
1805
		} else {
1882
				} else {
1806
		    /* Have class name */
1883
					/* Have class name */
1807
		    rescan = 1 ;
1884
					rescan = 1;
1808
		}
1885
				}
1809
		use_id ( id1, 0 ) ;
1886
				use_id(id1, 0);
1810
	    } else {
1887
			} else {
1811
		if ( !IS_NULL_nspace ( ns ) && !IS_NULL_id ( id2 ) ) {
1888
				if (!IS_NULL_nspace(ns) && !IS_NULL_id(id2)) {
1812
		    /* Namespace qualifier allowed */
1889
					/* Namespace qualifier allowed */
1813
		    create = 1 ;
1890
					create = 1;
-
 
1891
				} else {
-
 
1892
					report(crt_loc, ERR_dcl_type_simple_undef(id1));
-
 
1893
				}
-
 
1894
			}
-
 
1895
		}
-
 
1896
	} else {
-
 
1897
		t1 = make_base_type(b1);
-
 
1898
	}
-
 
1899
 
-
 
1900
	/* Check destructor name */
-
 
1901
	if (b2 == btype_none) {
-
 
1902
		if (!EQ_id(id2, id1)) {
-
 
1903
			nm = DEREF_hashid(id_name(id2));
-
 
1904
			if (!IS_NULL_nspace(ns)) {
-
 
1905
				/* Rescan id2 in the context of id1 */
-
 
1906
				IDENTIFIER id3 =
-
 
1907
				    find_qual_id(ns, nm, create, 1);
-
 
1908
				if (!IS_NULL_id(id3)) {
-
 
1909
					id2 = id3;
-
 
1910
				}
-
 
1911
			}
-
 
1912
			if (IS_id_class_name_etc(id2)) {
-
 
1913
				t2 = DEREF_type(id_class_name_etc_defn(id2));
-
 
1914
				t2 = copy_typedef(id2, t2, cv_none);
-
 
1915
				COPY_id(type_name(t2), id2);
-
 
1916
				use_id(id2, 0);
1814
		} else {
1917
			} else {
1815
		    report ( crt_loc, ERR_dcl_type_simple_undef ( id1 ) ) ;
1918
				report(crt_loc, ERR_dcl_type_simple_undef(id2));
-
 
1919
			}
-
 
1920
		}
-
 
1921
	} else {
-
 
1922
		if (b2 != b1) {
-
 
1923
			t2 = make_base_type(b2);
1816
		}
1924
		}
1817
	    }
-
 
1818
	}
1925
	}
1819
    } else {
-
 
1820
	t1 = make_base_type ( b1 ) ;
-
 
1821
    }
-
 
1822
 
1926
 
1823
    /* Check destructor name */
1927
	/* Form pseudo-destructor name */
1824
    if ( b2 == btype_none ) {
-
 
1825
	if ( !EQ_id ( id2, id1 ) ) {
-
 
1826
	    nm = DEREF_hashid ( id_name ( id2 ) ) ;
-
 
1827
	    if ( !IS_NULL_nspace ( ns ) ) {
1928
	if (IS_NULL_type(t2)) {
1828
		/* Rescan id2 in the context of id1 */
-
 
1829
		IDENTIFIER id3 = find_qual_id ( ns, nm, create, 1 ) ;
-
 
1830
		if ( !IS_NULL_id ( id3 ) ) id2 = id3 ;
-
 
1831
	    }
1929
		t2 = t1;
1832
	    if ( IS_id_class_name_etc ( id2 ) ) {
1930
		if (IS_NULL_type(t2)) {
1833
		t2 = DEREF_type ( id_class_name_etc_defn ( id2 ) ) ;
-
 
1834
		t2 = copy_typedef ( id2, t2, cv_none ) ;
-
 
1835
		COPY_id ( type_name ( t2 ), id2 ) ;
-
 
1836
		use_id ( id2, 0 ) ;
1931
			t2 = type_error;
1837
	    } else {
-
 
1838
		report ( crt_loc, ERR_dcl_type_simple_undef ( id2 ) ) ;
-
 
1839
	    }
-
 
1840
	}
1932
		}
1841
    } else {
-
 
1842
	if ( b2 != b1 ) t2 = make_base_type ( b2 ) ;
-
 
1843
    }
-
 
1844
 
-
 
1845
    /* Form pseudo-destructor name */
-
 
1846
    if ( IS_NULL_type ( t2 ) ) {
-
 
1847
	t2 = t1 ;
-
 
1848
	if ( IS_NULL_type ( t2 ) ) t2 = type_error ;
-
 
1849
    } else {
-
 
1850
	if ( rescan ) {
-
 
1851
	    /* Error will be caught in search_field */
-
 
1852
	    /* EMPTY */
-
 
1853
	} else {
1933
	} else {
-
 
1934
		if (rescan) {
-
 
1935
			/* Error will be caught in search_field */
-
 
1936
			/* EMPTY */
-
 
1937
		} else {
1854
	    if ( !IS_NULL_type ( t1 ) && !eq_type ( t1, t2 ) ) {
1938
			if (!IS_NULL_type(t1) && !eq_type(t1, t2)) {
1855
		/* If both specified, types should match */
1939
				/* If both specified, types should match */
1856
		report ( crt_loc, ERR_expr_pseudo_type ( t1, t2 ) ) ;
1940
				report(crt_loc, ERR_expr_pseudo_type(t1, t2));
1857
	    }
1941
			}
1858
	}
1942
		}
1859
    }
1943
	}
1860
    nm = lookup_destr ( t2, id2 ) ;
1944
	nm = lookup_destr(t2, id2);
1861
    id2 = DEREF_id ( hashid_id ( nm ) ) ;
1945
	id2 = DEREF_id(hashid_id(nm));
1862
    return ( id2 ) ;
1946
	return (id2);
1863
}
1947
}
1864
 
1948
 
1865
 
1949
 
1866
/*
1950
/*
1867
    DECLARATION SPECIFIERS FOR IMPLICIT CONSTRUCTORS
1951
    DECLARATION SPECIFIERS FOR IMPLICIT CONSTRUCTORS
1868
 
1952
 
1869
    This value gives the declaration specifiers used for implicitly declared
1953
    This value gives the declaration specifiers used for implicitly declared
1870
    constructors and destructors.
1954
    constructors and destructors.
1871
*/
1955
*/
1872
 
1956
 
1873
#define dspec_constr	( dspec_implicit | dspec_ignore | dspec_inline )
1957
#define dspec_constr	(dspec_implicit | dspec_ignore | dspec_inline)
1874
 
1958
 
1875
 
1959
 
1876
/*
1960
/*
1877
    ADD THE EXCEPTIONS THROWN BY A CONSTRUCTOR TO A LIST
1961
    ADD THE EXCEPTIONS THROWN BY A CONSTRUCTOR TO A LIST
1878
 
1962
 
1879
    This routine adds the list of exceptions thrown by the implicit
1963
    This routine adds the list of exceptions thrown by the implicit
1880
    constructor or destructor (given by n) of the class ct to the list p.
1964
    constructor or destructor (given by n) of the class ct to the list p.
1881
*/
1965
*/
1882
 
1966
 
1883
static LIST ( TYPE ) add_constr_except
1967
static LIST(TYPE)
1884
    PROTO_N ( ( p, ct, n ) )
-
 
1885
    PROTO_T ( LIST ( TYPE ) p X CLASS_TYPE ct X int n )
1968
add_constr_except(LIST(TYPE)p, CLASS_TYPE ct, int n)
1886
{
1969
{
1887
    IDENTIFIER id = find_constr ( ct, n, KILL_err ) ;
1970
	IDENTIFIER id = find_constr(ct, n, KILL_err);
1888
    if ( !IS_NULL_id ( id ) && IS_id_mem_func ( id ) ) {
1971
	if (!IS_NULL_id(id) && IS_id_mem_func(id)) {
1889
	TYPE fn = DEREF_type ( id_mem_func_type ( id ) ) ;
1972
		TYPE fn = DEREF_type(id_mem_func_type(id));
1890
	if ( IS_type_func ( fn ) ) {
1973
		if (IS_type_func(fn)) {
1891
	    LIST ( TYPE ) q = DEREF_list ( type_func_except ( fn ) ) ;
1974
			LIST(TYPE)q = DEREF_list(type_func_except(fn));
1892
	    p = union_type_set ( p, q ) ;
1975
			p = union_type_set(p, q);
-
 
1976
		}
1893
	}
1977
	}
1894
    }
-
 
1895
    return ( p ) ;
1978
	return (p);
1896
}
1979
}
1897
 
1980
 
1898
 
1981
 
1899
/*
1982
/*
1900
    FIND EXCEPTIONS THROWN BY AN IMPLICIT CONSTRUCTOR
1983
    FIND EXCEPTIONS THROWN BY AN IMPLICIT CONSTRUCTOR
1901
 
1984
 
1902
    This routine finds the list of exceptions thrown by the implicit
1985
    This routine finds the list of exceptions thrown by the implicit
1903
    constructor or destructor (given by n) of the class ct.
1986
    constructor or destructor (given by n) of the class ct.
1904
*/
1987
*/
1905
 
1988
 
1906
static LIST ( TYPE ) constr_except
1989
static LIST(TYPE)
1907
    PROTO_N ( ( ct, n ) )
-
 
1908
    PROTO_T ( CLASS_TYPE ct X int n )
1990
constr_except(CLASS_TYPE ct, int n)
1909
{
1991
{
1910
    LIST ( TYPE ) res = NULL_list ( TYPE ) ;
1992
	LIST(TYPE)res = NULL_list(TYPE);
1911
    GRAPH gr = DEREF_graph ( ctype_base ( ct ) ) ;
1993
	GRAPH gr = DEREF_graph(ctype_base(ct));
1912
    LIST ( GRAPH ) br = DEREF_list ( graph_tails ( gr ) ) ;
1994
	LIST(GRAPH)br = DEREF_list(graph_tails(gr));
1913
    NAMESPACE cns = DEREF_nspace ( ctype_member ( ct ) ) ;
1995
	NAMESPACE cns = DEREF_nspace(ctype_member(ct));
1914
    MEMBER mem = DEREF_member ( nspace_ctype_first ( cns ) ) ;
1996
	MEMBER mem = DEREF_member(nspace_ctype_first(cns));
1915
 
1997
 
1916
    /* Scan through virtual bases */
1998
	/* Scan through virtual bases */
1917
    if ( n != DEFAULT_ASSIGN ) {
1999
	if (n != DEFAULT_ASSIGN) {
1918
	LIST ( GRAPH ) bv = DEREF_list ( ctype_vbase ( ct ) ) ;
2000
		LIST(GRAPH)bv = DEREF_list(ctype_vbase(ct));
1919
	while ( !IS_NULL_list ( bv ) ) {
2001
		while (!IS_NULL_list(bv)) {
1920
	    GRAPH gs = DEREF_graph ( HEAD_list ( bv ) ) ;
2002
			GRAPH gs = DEREF_graph(HEAD_list(bv));
1921
	    CLASS_TYPE cs = DEREF_ctype ( graph_head ( gs ) ) ;
2003
			CLASS_TYPE cs = DEREF_ctype(graph_head(gs));
1922
	    res = add_constr_except ( res, cs, n ) ;
2004
			res = add_constr_except(res, cs, n);
1923
	    if ( EQ_list ( res, univ_type_set ) ) return ( res ) ;
2005
			if (EQ_list(res, univ_type_set)) {
1924
	    bv = TAIL_list ( bv ) ;
2006
				return (res);
1925
	}
2007
			}
1926
    }
-
 
1927
 
-
 
1928
    /* Scan through direct bases */
-
 
1929
    while ( !IS_NULL_list ( br ) ) {
2008
			bv = TAIL_list(bv);
1930
	GRAPH gs = DEREF_graph ( HEAD_list ( br ) ) ;
-
 
1931
	DECL_SPEC acc = DEREF_dspec ( graph_access ( gs ) ) ;
-
 
1932
	if ( !( acc & dspec_virtual ) || n == DEFAULT_ASSIGN ) {
-
 
1933
	    CLASS_TYPE cs = DEREF_ctype ( graph_head ( gs ) ) ;
-
 
1934
	    res = add_constr_except ( res, cs, n ) ;
-
 
1935
	    if ( EQ_list ( res, univ_type_set ) ) return ( res ) ;
-
 
1936
	}
2009
		}
1937
	br = TAIL_list ( br ) ;
-
 
1938
    }
2010
	}
1939
 
2011
 
1940
    /* Scan through data members */
2012
	/* Scan through direct bases */
1941
    mem = next_data_member ( mem, 2 ) ;
2013
	while (!IS_NULL_list(br)) {
1942
    while ( !IS_NULL_member ( mem ) ) {
2014
		GRAPH gs = DEREF_graph(HEAD_list(br));
1943
	IDENTIFIER id = DEREF_id ( member_id ( mem ) ) ;
2015
		DECL_SPEC acc = DEREF_dspec(graph_access(gs));
-
 
2016
		if (!(acc & dspec_virtual) || n == DEFAULT_ASSIGN) {
1944
	TYPE s = DEREF_type ( id_member_type ( id ) ) ;
2017
			CLASS_TYPE cs = DEREF_ctype(graph_head(gs));
1945
	while ( IS_type_array ( s ) ) {
2018
			res = add_constr_except(res, cs, n);
1946
	    s = DEREF_type ( type_array_sub ( s ) ) ;
2019
			if (EQ_list(res, univ_type_set)) {
-
 
2020
				return (res);
-
 
2021
			}
-
 
2022
		}
-
 
2023
		br = TAIL_list(br);
1947
	}
2024
	}
-
 
2025
 
-
 
2026
	/* Scan through data members */
-
 
2027
	mem = next_data_member(mem, 2);
-
 
2028
	while (!IS_NULL_member(mem)) {
-
 
2029
		IDENTIFIER id = DEREF_id(member_id(mem));
-
 
2030
		TYPE s = DEREF_type(id_member_type(id));
-
 
2031
		while (IS_type_array(s)) {
-
 
2032
			s = DEREF_type(type_array_sub(s));
-
 
2033
		}
1948
	if ( IS_type_compound ( s ) ) {
2034
		if (IS_type_compound(s)) {
1949
	    CLASS_TYPE cs = DEREF_ctype ( type_compound_defn ( s ) ) ;
2035
			CLASS_TYPE cs = DEREF_ctype(type_compound_defn(s));
1950
	    res = add_constr_except ( res, cs, n ) ;
2036
			res = add_constr_except(res, cs, n);
1951
	    if ( EQ_list ( res, univ_type_set ) ) return ( res ) ;
2037
			if (EQ_list(res, univ_type_set)) {
-
 
2038
				return (res);
-
 
2039
			}
-
 
2040
		}
-
 
2041
		mem = DEREF_member(member_next(mem));
-
 
2042
		mem = next_data_member(mem, 2);
1952
	}
2043
	}
1953
	mem = DEREF_member ( member_next ( mem ) ) ;
-
 
1954
	mem = next_data_member ( mem, 2 ) ;
-
 
1955
    }
-
 
1956
    return ( res ) ;
2044
	return (res);
1957
}
2045
}
1958
 
2046
 
1959
 
2047
 
1960
/*
2048
/*
1961
    DECLARE IMPLICIT CONSTRUCTORS AND DESTRUCTORS
2049
    DECLARE IMPLICIT CONSTRUCTORS AND DESTRUCTORS
Line 1963... Line 2051...
1963
    This routine is called at the end of a class definition to implicitly
2051
    This routine is called at the end of a class definition to implicitly
1964
    declare any necessary default constructors, copy constructors, assignment
2052
    declare any necessary default constructors, copy constructors, assignment
1965
    operators or destructors.  Note that these are only actually defined
2053
    operators or destructors.  Note that these are only actually defined
1966
    if they are used, and errors are only detected at this definition stage.
2054
    if they are used, and errors are only detected at this definition stage.
1967
    The routine returns information on the class being defined.
2055
    The routine returns information on the class being defined.
2155
	}
2242
	}
-
 
2243
	if (IS_NULL_list(pals)) {
-
 
2244
		if (!access_constr) {
-
 
2245
			report(crt_loc, ERR_class_ctor_private(ct));
-
 
2246
		}
2156
	if ( !access_destr ) {
2247
		if (!access_destr) {
2157
	    report ( crt_loc, ERR_class_dtor_private ( ct ) ) ;
2248
			report(crt_loc, ERR_class_dtor_private(ct));
-
 
2249
		}
2158
	}
2250
	}
2159
    }
-
 
2160
    return ( ci ) ;
2251
	return (ci);
2161
}
2252
}
2162
 
2253
 
2163
 
2254
 
2164
/*
2255
/*
2165
    FIND A CONSTRUCTOR KIND
2256
    FIND A CONSTRUCTOR KIND
2166
 
2257
 
2167
    This routine finds the kind of constructor for the function id of
2258
    This routine finds the kind of constructor for the function id of
2168
    type t.
2259
    type t.
2169
*/
2260
*/
2170
 
2261
 
2171
int constr_kind
2262
int
2172
    PROTO_N ( ( id, t ) )
-
 
2173
    PROTO_T ( IDENTIFIER id X TYPE t )
2263
constr_kind(IDENTIFIER id, TYPE t)
2174
{
2264
{
2175
    int n = DEFAULT_USR ;
2265
	int n = DEFAULT_USR;
2176
    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
2266
	HASHID nm = DEREF_hashid(id_name(id));
2177
    switch ( TAG_hashid ( nm ) ) {
2267
	switch (TAG_hashid(nm)) {
2178
	case hashid_constr_tag : {
2268
	case hashid_constr_tag: {
2179
	    if ( min_no_args ( t ) == 1 ) {
2269
		if (min_no_args(t) == 1) {
2180
		n = DEFAULT_CONSTR ;
2270
			n = DEFAULT_CONSTR;
2181
	    } else {
2271
		} else {
2182
		n = DEFAULT_COPY ;
2272
			n = DEFAULT_COPY;
2183
	    }
2273
		}
-
 
2274
		break;
-
 
2275
	}
-
 
2276
	case hashid_destr_tag: {
-
 
2277
		/* Implicit default destructor */
-
 
2278
		n = DEFAULT_DESTR;
2184
	    break ;
2279
		break;
2185
	}
2280
	}
2186
	case hashid_destr_tag : {
2281
	case hashid_op_tag: {
2187
	    /* Implicit default destructor */
2282
		/* Implicit assignment operator */
2188
	    n = DEFAULT_DESTR ;
2283
		n = DEFAULT_ASSIGN;
2189
	    break ;
2284
		break;
2190
	}
2285
	}
2191
	case hashid_op_tag : {
-
 
2192
	    /* Implicit assignment operator */
-
 
2193
	    n = DEFAULT_ASSIGN ;
-
 
2194
	    break ;
-
 
2195
	}
2286
	}
2196
    }
-
 
2197
    return ( n ) ;
2287
	return (n);
2198
}
2288
}
2199
 
2289
 
2200
 
2290
 
2201
/*
2291
/*
2202
    DEFINE AN IMPLICIT CONSTRUCTOR OR DESTRUCTOR
2292
    DEFINE AN IMPLICIT CONSTRUCTOR OR DESTRUCTOR
2203
 
2293
 
2204
    This routine defines the function id, which will be one of the
2294
    This routine defines the function id, which will be one of the
2205
    implicitly declared constructors or destructors declared in
2295
    implicitly declared constructors or destructors declared in
2206
    implicit_decl.  n gives the constructor type or DEFAULT_USR if this
2296
    implicit_decl.  n gives the constructor type or DEFAULT_USR if this
2207
    is not known.
2297
    is not known.
2208
*/
2298
*/
2209
 
-
 
2210
void implicit_defn
-
 
2211
    PROTO_N ( ( id, n ) )
-
 
2212
    PROTO_T ( IDENTIFIER id X int n )
-
 
2213
{
-
 
2214
    TYPE t ;
-
 
2215
    EXP e, r ;
-
 
2216
    DECL_SPEC ds ;
-
 
2217
    IDENTIFIER fn ;
-
 
2218
    NAMESPACE cns ;
-
 
2219
    int in_func, in_decl ;
-
 
2220
 
2299
 
2221
    /* Check for previous definition */
-
 
2222
    if ( !IS_id_mem_func ( id ) ) return ;
-
 
2223
    ds = DEREF_dspec ( id_storage ( id ) ) ;
-
 
2224
    if ( ds & dspec_inherit ) {
-
 
2225
	/* Inherited functions */
-
 
2226
	id = DEREF_id ( id_alias ( id ) ) ;
-
 
2227
	ds = DEREF_dspec ( id_storage ( id ) ) ;
-
 
2228
    }
2300
void
2229
    if ( !( ds & dspec_implicit ) ) return ;
-
 
2230
    if ( ds & dspec_defn ) return ;
-
 
2231
    ds |= dspec_defn ;
-
 
2232
    COPY_dspec ( id_storage ( id ), ds ) ;
2301
implicit_defn(IDENTIFIER id, int n)
2233
 
-
 
2234
    /* Find constructor type */
-
 
2235
    t = DEREF_type ( id_mem_func_type ( id ) ) ;
-
 
2236
    if ( !IS_type_func ( t ) ) return ;
-
 
2237
    if ( n == DEFAULT_USR ) n = constr_kind ( id, t ) ;
-
 
2238
 
2302
{
2239
    /* Force immediate access checks */
-
 
2240
    in_func = in_function_defn ;
-
 
2241
    in_decl = in_declaration ;
-
 
2242
    fn = crt_func_id ;
2303
	TYPE t;
2243
    in_function_defn = 1 ;
-
 
2244
    in_declaration = 0 ;
2304
	EXP e, r;
2245
    crt_func_id = id ;
2305
	DECL_SPEC ds;
2246
 
-
 
2247
    /* Make initialiser list */
-
 
2248
    start_try_check ( univ_type_set ) ;
-
 
2249
    cns = DEREF_nspace ( type_func_pars ( t ) ) ;
-
 
2250
    push_namespace ( cns ) ;
-
 
2251
    r = make_this_decl ( id ) ;
-
 
2252
    cns = DEREF_nspace ( id_parent ( id ) ) ;
-
 
2253
    e = make_constr ( cns, id, n, n ) ;
-
 
2254
    if ( n == DEFAULT_DESTR ) {
-
 
2255
	/* Allow for destructor prelude */
-
 
2256
	if ( !( ds & dspec_trivial ) ) {
-
 
2257
	    EXP d = make_destr_prelude ( cns ) ;
-
 
2258
	    e = join_exp ( d, e ) ;
-
 
2259
	}
-
 
2260
    } else if ( n == DEFAULT_ASSIGN ) {
-
 
2261
	/* Allow for return value */
-
 
2262
	r = make_indir_exp ( r ) ;
-
 
2263
	MAKE_exp_return_stmt ( type_bottom, r, r ) ;
-
 
2264
	e = join_exp ( e, r ) ;
2306
	IDENTIFIER fn;
2265
    }
-
 
2266
    IGNORE pop_namespace () ;
2307
	NAMESPACE cns;
2267
    e = end_try_check ( id, e ) ;
-
 
2268
    COPY_exp ( id_mem_func_defn ( id ), e ) ;
-
 
2269
    define_id ( id ) ;
2308
	int in_func, in_decl;
2270
 
2309
 
-
 
2310
	/* Check for previous definition */
-
 
2311
	if (!IS_id_mem_func(id)) {
-
 
2312
		return;
-
 
2313
	}
-
 
2314
	ds = DEREF_dspec(id_storage(id));
-
 
2315
	if (ds & dspec_inherit) {
-
 
2316
		/* Inherited functions */
-
 
2317
		id = DEREF_id(id_alias(id));
-
 
2318
		ds = DEREF_dspec(id_storage(id));
-
 
2319
	}
-
 
2320
	if (!(ds & dspec_implicit)) {
-
 
2321
		return;
-
 
2322
	}
-
 
2323
	if (ds & dspec_defn) {
-
 
2324
		return;
-
 
2325
	}
-
 
2326
	ds |= dspec_defn;
-
 
2327
	COPY_dspec(id_storage(id), ds);
-
 
2328
 
-
 
2329
	/* Find constructor type */
-
 
2330
	t = DEREF_type(id_mem_func_type(id));
-
 
2331
	if (!IS_type_func(t)) {
-
 
2332
		return;
-
 
2333
	}
-
 
2334
	if (n == DEFAULT_USR) {
-
 
2335
		n = constr_kind(id, t);
-
 
2336
	}
-
 
2337
 
-
 
2338
	/* Force immediate access checks */
-
 
2339
	in_func = in_function_defn;
-
 
2340
	in_decl = in_declaration;
-
 
2341
	fn = crt_func_id;
-
 
2342
	in_function_defn = 1;
-
 
2343
	in_declaration = 0;
-
 
2344
	crt_func_id = id;
-
 
2345
 
-
 
2346
	/* Make initialiser list */
-
 
2347
	start_try_check(univ_type_set);
-
 
2348
	cns = DEREF_nspace(type_func_pars(t));
-
 
2349
	push_namespace(cns);
-
 
2350
	r = make_this_decl(id);
-
 
2351
	cns = DEREF_nspace(id_parent(id));
-
 
2352
	e = make_constr(cns, id, n, n);
-
 
2353
	if (n == DEFAULT_DESTR) {
-
 
2354
		/* Allow for destructor prelude */
-
 
2355
		if (!(ds & dspec_trivial)) {
-
 
2356
			EXP d = make_destr_prelude(cns);
-
 
2357
			e = join_exp(d, e);
-
 
2358
		}
-
 
2359
	} else if (n == DEFAULT_ASSIGN) {
-
 
2360
		/* Allow for return value */
-
 
2361
		r = make_indir_exp(r);
-
 
2362
		MAKE_exp_return_stmt(type_bottom, r, r);
-
 
2363
		e = join_exp(e, r);
-
 
2364
	}
-
 
2365
	IGNORE pop_namespace();
-
 
2366
	e = end_try_check(id, e);
-
 
2367
	COPY_exp(id_mem_func_defn(id), e);
-
 
2368
	define_id(id);
-
 
2369
 
2271
    /* Compile the function definition */
2370
	/* Compile the function definition */
2272
    if ( !( ds & dspec_trivial ) ) {
2371
	if (!(ds & dspec_trivial)) {
2273
	if ( do_dump ) {
2372
		if (do_dump) {
2274
	    dump_implicit = 1 ;
2373
			dump_implicit = 1;
2275
	    dump_declare ( id, &crt_loc, 1 ) ;
2374
			dump_declare(id, &crt_loc, 1);
-
 
2375
		}
-
 
2376
		compile_function(id, 0);
2276
	}
2377
	}
2277
	compile_function ( id, 0 ) ;
-
 
2278
    }
-
 
2279
 
2378
 
2280
    /* Restore old values */
2379
	/* Restore old values */
2281
    in_function_defn = in_func ;
2380
	in_function_defn = in_func;
2282
    in_declaration = in_decl ;
2381
	in_declaration = in_decl;
2283
    crt_func_id = fn ;
2382
	crt_func_id = fn;
2284
    return ;
2383
	return;
2285
}
2384
}
2286
 
2385
 
2287
 
2386
 
2288
/*
2387
/*
2289
    EXPLICIT CONSTRUCTOR FLAGS
2388
    EXPLICIT CONSTRUCTOR FLAGS
2290
 
2389
 
2291
    These flags are used to indicate that an explicit constructor or
2390
    These flags are used to indicate that an explicit constructor or
2292
    conversion function has been declared.
2391
    conversion function has been declared.
2293
*/
2392
*/
2294
 
2393
 
2295
int have_conv_expl = 0 ;
2394
int have_conv_expl = 0;
2296
int have_constr_expl = 0 ;
2395
int have_constr_expl = 0;
2297
 
2396
 
2298
 
2397
 
2299
/*
2398
/*
2300
    REMOVE EXPLICIT CONSTRUCTORS
2399
    REMOVE EXPLICIT CONSTRUCTORS
2301
 
2400
 
2302
    This routine removes all explicit constructors from the candidate list
2401
    This routine removes all explicit constructors from the candidate list
2303
    p beginning with the mth element.
2402
    p beginning with the mth element.
2304
*/
2403
*/
2305
 
2404
 
2306
static void remove_explicit
2405
static void
2307
    PROTO_N ( ( p, m ) )
-
 
2308
    PROTO_T ( CANDIDATE_LIST *p X unsigned m )
2406
remove_explicit(CANDIDATE_LIST *p, unsigned m)
2309
{
2407
{
2310
    unsigned i, n = p->size ;
2408
	unsigned i, n = p->size;
2311
    CANDIDATE *q = p->elem + m ;
2409
	CANDIDATE *q = p->elem + m;
2312
    for ( i = m ; i < n ; i++ ) {
2410
	for (i = m; i < n; i++) {
2313
	DECL_SPEC ds = DEREF_dspec ( id_storage ( q->base ) ) ;
2411
		DECL_SPEC ds = DEREF_dspec(id_storage(q->base));
2314
	if ( ds & dspec_explicit ) q->rank = RANK_IGNORE ;
2412
		if (ds & dspec_explicit) {
-
 
2413
			q->rank = RANK_IGNORE;
-
 
2414
		}
2315
	q++ ;
2415
		q++;
2316
    }
2416
	}
2317
    return ;
2417
	return;
2318
}
2418
}
2319
 
2419
 
2320
 
2420
 
2321
/*
2421
/*
2322
    CONSTRUCT CONSTRUCTOR CANDIDATES LIST
2422
    CONSTRUCT CONSTRUCTOR CANDIDATES LIST
2323
 
2423
 
2324
    This routine constructs the candidate list consisting of the constructors
2424
    This routine constructs the candidate list consisting of the constructors
2325
    for the class type t (including the explicit constructors only if cast
2425
    for the class type t (including the explicit constructors only if cast
2326
    indicates an explicit conversion).  The candidates are added to the
2426
    indicates an explicit conversion).  The candidates are added to the
2327
    list p.  The routine returns the first constructor for t.
2427
    list p.  The routine returns the first constructor for t.
2328
*/
2428
*/
2329
 
2429
 
2330
static IDENTIFIER constr_candidates
2430
static IDENTIFIER
2331
    PROTO_N ( ( p, t, cast ) )
-
 
2332
    PROTO_T ( CANDIDATE_LIST *p X TYPE t X unsigned cast )
2431
constr_candidates(CANDIDATE_LIST *p, TYPE t, unsigned cast)
2333
{
2432
{
2334
    /* Search for constructor candidates */
2433
	/* Search for constructor candidates */
2335
    IDENTIFIER cid ;
2434
	IDENTIFIER cid;
2336
    CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
2435
	CLASS_TYPE ct = DEREF_ctype(type_compound_defn(t));
2337
    complete_class ( ct, 1 ) ;
2436
	complete_class(ct, 1);
2338
    cid = DEREF_id ( ctype_constr ( ct ) ) ;
2437
	cid = DEREF_id(ctype_constr(ct));
2339
    if ( IS_id_mem_func ( cid ) ) {
2438
	if (IS_id_mem_func(cid)) {
2340
	unsigned i = p->size ;
2439
		unsigned i = p->size;
2341
	add_candidates ( p, cid, 1, KIND_CONSTR ) ;
2440
		add_candidates(p, cid, 1, KIND_CONSTR);
2342
	swap_candidates ( p, i ) ;
2441
		swap_candidates(p, i);
2343
	if ( cast == CAST_IMPLICIT && have_constr_expl ) {
2442
		if (cast == CAST_IMPLICIT && have_constr_expl) {
2344
	    remove_explicit ( p, i ) ;
2443
			remove_explicit(p, i);
2345
	}
2444
		}
2346
    } else {
2445
	} else {
2347
	/* Can happen for incomplete types and in C */
2446
		/* Can happen for incomplete types and in C */
2348
	cid = NULL_id ;
2447
		cid = NULL_id;
2349
    }
2448
	}
2350
    return ( cid ) ;
2449
	return (cid);
2351
}
2450
}
2352
 
2451
 
2353
 
2452
 
2354
/*
2453
/*
2355
    CONSTRUCT CONVERSION CANDIDATES LIST
2454
    CONSTRUCT CONVERSION CANDIDATES LIST
2356
 
2455
 
2357
    This routine constructs the candidate list for the conversion functions
2456
    This routine constructs the candidate list for the conversion functions
2358
    for the type s which can be implicitly converted to type t, plus the
2457
    for the type s which can be implicitly converted to type t, plus the
2359
    constructors of t if t is a class type.  The candidates are added to
2458
    constructors of t if t is a class type.  The candidates are added to
2360
    the end of p.  The routine returns the first constructor for t if t is
2459
    the end of p.  The routine returns the first constructor for t if t is
2361
    a class type, and the null identifier otherwise.
2460
    a class type, and the null identifier otherwise.
2362
*/
2461
*/
2363
 
2462
 
2364
IDENTIFIER conv_candidates
2463
IDENTIFIER
2365
    PROTO_N ( ( p, t, s, cast ) )
-
 
2366
    PROTO_T ( CANDIDATE_LIST *p X TYPE t X TYPE s X unsigned cast )
2464
conv_candidates(CANDIDATE_LIST *p, TYPE t, TYPE s, unsigned cast)
2367
{
2465
{
2368
    /* Add constructors */
2466
	/* Add constructors */
2369
    IDENTIFIER cid = NULL_id ;
2467
	IDENTIFIER cid = NULL_id;
2370
    if ( IS_type_compound ( t ) ) {
2468
	if (IS_type_compound(t)) {
2371
	cid = constr_candidates ( p, t, cast ) ;
2469
		cid = constr_candidates(p, t, cast);
2372
    }
2470
	}
2373
 
2471
 
2374
    /* Add conversion functions */
2472
	/* Add conversion functions */
2375
    if ( IS_type_compound ( s ) ) {
2473
	if (IS_type_compound(s)) {
2376
	LIST ( IDENTIFIER ) conv ;
2474
		LIST(IDENTIFIER)conv;
2377
	CLASS_TYPE cs = DEREF_ctype ( type_compound_defn ( s ) ) ;
2475
		CLASS_TYPE cs = DEREF_ctype(type_compound_defn(s));
2378
	complete_class ( cs, 1 ) ;
2476
		complete_class(cs, 1);
2379
	conv = DEREF_list ( ctype_conv ( cs ) ) ;
2477
		conv = DEREF_list(ctype_conv(cs));
2380
	while ( !IS_NULL_list ( conv ) ) {
2478
		while (!IS_NULL_list(conv)) {
2381
	    IDENTIFIER id = DEREF_id ( HEAD_list ( conv ) ) ;
2479
			IDENTIFIER id = DEREF_id(HEAD_list(conv));
2382
	    TYPE fn = DEREF_type ( id_function_etc_type ( id ) ) ;
2480
			TYPE fn = DEREF_type(id_function_etc_type(id));
2383
	    if ( IS_type_templ ( fn ) ) {
2481
			if (IS_type_templ(fn)) {
2384
		/* Allow for template functions */
2482
				/* Allow for template functions */
2385
		fn = deduce_conv ( fn, t ) ;
2483
				fn = deduce_conv(fn, t);
2386
		if ( !IS_NULL_type ( fn ) ) {
2484
				if (!IS_NULL_type(fn)) {
2387
		    int eq = 0 ;
2485
					int eq = 0;
2388
		    id = deduce_func ( id, fn, &eq ) ;
2486
					id = deduce_func(id, fn, &eq);
2389
		} else {
2487
				} else {
2390
		    id = NULL_id ;
2488
					id = NULL_id;
2391
		}
2489
				}
2392
	    }
2490
			}
2393
	    if ( !IS_NULL_id ( id ) ) {
2491
			if (!IS_NULL_id(id)) {
2394
		unsigned r ;
2492
				unsigned r;
2395
		CONVERSION c ;
2493
				CONVERSION c;
2396
		HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
2494
				HASHID nm = DEREF_hashid(id_name(id));
2397
		c.from = DEREF_type ( hashid_conv_type ( nm ) ) ;
2495
				c.from = DEREF_type(hashid_conv_type(nm));
2398
		c.to = t ;
2496
				c.to = t;
2399
		r = std_convert_seq ( &c, NULL_exp, 0, 0 ) ;
2497
				r = std_convert_seq(&c, NULL_exp, 0, 0);
2400
		if ( r != CONV_NONE ) {
2498
				if (r != CONV_NONE) {
2401
		    unsigned i = p->size ;
2499
					unsigned i = p->size;
2402
		    add_candidates ( p, id, 1, KIND_CONV ) ;
2500
					add_candidates(p, id, 1, KIND_CONV);
2403
		    if ( cast == CAST_IMPLICIT && have_conv_expl ) {
2501
					if (cast == CAST_IMPLICIT &&
-
 
2502
					    have_conv_expl) {
2404
			remove_explicit ( p, i ) ;
2503
						remove_explicit(p, i);
2405
		    }
2504
					}
-
 
2505
				}
-
 
2506
			}
-
 
2507
			conv = TAIL_list(conv);
2406
		}
2508
		}
2407
	    }
-
 
2408
	    conv = TAIL_list ( conv ) ;
-
 
2409
	}
2509
	}
2410
    }
-
 
2411
    return ( cid ) ;
2510
	return (cid);
2412
}
2511
}
2413
 
2512
 
2414
 
2513
 
2415
/*
2514
/*
2416
    CONSTRUCT GENERIC CONVERSION CANDIDATES LIST
2515
    CONSTRUCT GENERIC CONVERSION CANDIDATES LIST
Line 2420... Line 2519...
2420
    Note that template conversion functions are excluded - they cannot
2519
    Note that template conversion functions are excluded - they cannot
2421
    give a non-ambiguous resolution and are beaten by any non-template
2520
    give a non-ambiguous resolution and are beaten by any non-template
2422
    conversion function.
2521
    conversion function.
2423
*/
2522
*/
2424
 
2523
 
2425
static void gen_candidates
2524
static void
2426
    PROTO_N ( ( p, t, kind ) )
-
 
2427
    PROTO_T ( CANDIDATE_LIST *p X TYPE t X unsigned kind )
2525
gen_candidates(CANDIDATE_LIST *p, TYPE t, unsigned kind)
2428
{
2526
{
2429
    if ( IS_type_compound ( t ) ) {
2527
	if (IS_type_compound(t)) {
2430
	LIST ( IDENTIFIER ) conv ;
2528
		LIST(IDENTIFIER)conv;
2431
	CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
2529
		CLASS_TYPE ct = DEREF_ctype(type_compound_defn(t));
2432
	complete_class ( ct, 1 ) ;
2530
		complete_class(ct, 1);
2433
	conv = DEREF_list ( ctype_conv ( ct ) ) ;
2531
		conv = DEREF_list(ctype_conv(ct));
2434
	while ( !IS_NULL_list ( conv ) ) {
2532
		while (!IS_NULL_list(conv)) {
2435
	    IDENTIFIER id = DEREF_id ( HEAD_list ( conv ) ) ;
2533
			IDENTIFIER id = DEREF_id(HEAD_list(conv));
2436
	    TYPE fn = DEREF_type ( id_function_etc_type ( id ) ) ;
2534
			TYPE fn = DEREF_type(id_function_etc_type(id));
2437
	    if ( IS_type_func ( fn ) ) {
2535
			if (IS_type_func(fn)) {
2438
		TYPE r = DEREF_type ( type_func_ret ( fn ) ) ;
2536
				TYPE r = DEREF_type(type_func_ret(fn));
2439
		unsigned c = type_category ( &r ) ;
2537
				unsigned c = type_category(&r);
2440
		if ( c & kind ) {
2538
				if (c & kind) {
2441
		    unsigned i = p->size ;
2539
					unsigned i = p->size;
2442
		    add_candidates ( p, id, 1, KIND_CONV ) ;
2540
					add_candidates(p, id, 1, KIND_CONV);
-
 
2541
					if (have_conv_expl) {
2443
		    if ( have_conv_expl ) remove_explicit ( p, i ) ;
2542
						remove_explicit(p, i);
-
 
2543
					}
-
 
2544
				}
-
 
2545
			}
-
 
2546
			conv = TAIL_list(conv);
2444
		}
2547
		}
2445
	    }
-
 
2446
	    conv = TAIL_list ( conv ) ;
-
 
2447
	}
2548
	}
2448
    }
-
 
2449
    return ;
2549
	return;
2450
}
2550
}
2451
 
2551
 
2452
 
2552
 
2453
/*
2553
/*
2454
    APPLY A TRIVIAL DESTRUCTOR
2554
    APPLY A TRIVIAL DESTRUCTOR
2455
 
2555
 
2456
    This routine applies a trivial destructor to the expression a.  It
2556
    This routine applies a trivial destructor to the expression a.  It
2457
    is used in explicit destructor and pseudo-destructor calls.
2557
    is used in explicit destructor and pseudo-destructor calls.
2458
*/
2558
*/
2459
 
2559
 
2460
EXP trivial_destr
2560
EXP
2461
    PROTO_N ( ( a ) )
-
 
2462
    PROTO_T ( EXP a )
2561
trivial_destr(EXP a)
2463
{
2562
{
2464
    EXP e = make_discard_exp ( a ) ;
2563
	EXP e = make_discard_exp(a);
2465
    MAKE_exp_cast ( type_void, CONV_ELLIPSIS, e, e ) ;
2564
	MAKE_exp_cast(type_void, CONV_ELLIPSIS, e, e);
2466
    return ( e ) ;
2565
	return (e);
2467
}
2566
}
2468
 
2567
 
2469
 
2568
 
2470
/*
2569
/*
2471
    APPLY A TRIVIAL FUNCTION
2570
    APPLY A TRIVIAL FUNCTION
2472
 
2571
 
2473
    This routine applies the trivial constructor or destructor id to
2572
    This routine applies the trivial constructor or destructor id to
2474
    the arguments args.  The null expression is returned for invalid
2573
    the arguments args.  The null expression is returned for invalid
2475
    arguments.
2574
    arguments.
2476
*/
2575
*/
2477
 
2576
 
2478
EXP apply_trivial_func
2577
EXP
2479
    PROTO_N ( ( id, args ) )
-
 
2480
    PROTO_T ( IDENTIFIER id X LIST ( EXP ) args )
2578
apply_trivial_func(IDENTIFIER id, LIST(EXP)args)
2481
{
2579
{
2482
    EXP e = NULL_exp ;
2580
	EXP e = NULL_exp;
2483
    TYPE t = DEREF_type ( id_function_etc_type ( id ) ) ;
2581
	TYPE t = DEREF_type(id_function_etc_type(id));
2484
    int n = constr_kind ( id, t ) ;
2582
	int n = constr_kind(id, t);
2485
    switch ( n ) {
2583
	switch (n) {
2486
	case DEFAULT_CONSTR : {
2584
	case DEFAULT_CONSTR: {
2487
	    if ( LENGTH_list ( args ) == 1 ) {
2585
		if (LENGTH_list(args) == 1) {
2488
		/* Trivial constructor */
2586
			/* Trivial constructor */
2489
		CLASS_TYPE ct = parent_class ( id ) ;
2587
			CLASS_TYPE ct = parent_class(id);
2490
		t = make_class_type ( ct ) ;
2588
			t = make_class_type(ct);
2491
		e = make_null_exp ( t ) ;
2589
			e = make_null_exp(t);
2492
	    }
2590
		}
2493
	    break ;
2591
		break;
2494
	}
2592
	}
2495
	case DEFAULT_COPY : {
2593
	case DEFAULT_COPY: {
2496
	    if ( LENGTH_list ( args ) == 2 ) {
2594
		if (LENGTH_list(args) == 2) {
2497
		/* Trivial copy constructor */
2595
			/* Trivial copy constructor */
2498
		ERROR err = NULL_err ;
2596
			ERROR err = NULL_err;
2499
		LIST ( TYPE ) p = DEREF_list ( type_func_mtypes ( t ) ) ;
2597
			LIST(TYPE)p = DEREF_list(type_func_mtypes(t));
2500
		TYPE ta = DEREF_type ( HEAD_list ( p ) ) ;
2598
			TYPE ta = DEREF_type(HEAD_list(p));
2501
		ta = DEREF_type ( type_ref_sub ( ta ) ) ;
2599
			ta = DEREF_type(type_ref_sub(ta));
2502
		e = DEREF_exp ( HEAD_list ( TAIL_list ( args ) ) ) ;
2600
			e = DEREF_exp(HEAD_list(TAIL_list(args)));
2503
		e = convert_reference ( e, REF_NORMAL ) ;
2601
			e = convert_reference(e, REF_NORMAL);
2504
		e = convert_class ( ta, e, &err ) ;
2602
			e = convert_class(ta, e, &err);
2505
		if ( !IS_NULL_err ( err ) ) {
2603
			if (!IS_NULL_err(err)) {
2506
		    err = concat_warning ( err, ERR_expr_ass_conv () ) ;
2604
				err = concat_warning(err, ERR_expr_ass_conv());
2507
		    report ( crt_loc, err ) ;
2605
				report(crt_loc, err);
-
 
2606
			}
2508
		}
2607
		}
-
 
2608
		break;
-
 
2609
	}
-
 
2610
	case DEFAULT_DESTR: {
-
 
2611
		if (LENGTH_list(args) == 1) {
-
 
2612
			/* Trivial destructor */
-
 
2613
			EXP a = DEREF_exp(HEAD_list(args));
-
 
2614
			e = trivial_destr(a);
2509
	    }
2615
		}
2510
	    break ;
2616
		break;
2511
	}
2617
	}
2512
	case DEFAULT_DESTR : {
2618
	case DEFAULT_ASSIGN: {
2513
	    if ( LENGTH_list ( args ) == 1 ) {
2619
		if (LENGTH_list(args) == 2) {
2514
		/* Trivial destructor */
2620
			/* Trivial assignment */
2515
		EXP a = DEREF_exp ( HEAD_list ( args ) ) ;
2621
			EXP a = DEREF_exp(HEAD_list(args));
-
 
2622
			EXP b = DEREF_exp(HEAD_list(TAIL_list(args)));
2516
		e = trivial_destr ( a ) ;
2623
			e = make_assign_exp(a, b, 1);
2517
	    }
2624
		}
2518
	    break ;
2625
		break;
2519
	}
2626
	}
2520
	case DEFAULT_ASSIGN : {
-
 
2521
	    if ( LENGTH_list ( args ) == 2 ) {
-
 
2522
		/* Trivial assignment */
-
 
2523
		EXP a = DEREF_exp ( HEAD_list ( args ) ) ;
-
 
2524
		EXP b = DEREF_exp ( HEAD_list ( TAIL_list ( args ) ) ) ;
-
 
2525
		e = make_assign_exp ( a, b, 1 ) ;
-
 
2526
	    }
-
 
2527
	    break ;
-
 
2528
	}
2627
	}
2529
    }
-
 
2530
    return ( e ) ;
2628
	return (e);
2531
}
2629
}
2532
 
2630
 
2533
 
2631
 
2534
/*
2632
/*
2535
    APPLY A CONSTRUCTOR
2633
    APPLY A CONSTRUCTOR
2536
 
2634
 
2537
    This routine applies the constructor id to the arguments args, using a
2635
    This routine applies the constructor id to the arguments args, using a
2538
    dummy expression for the object the constructor is applied to.  The
2636
    dummy expression for the object the constructor is applied to.  The
2539
    definition of this object, whether an existing object or a temporary,
2637
    definition of this object, whether an existing object or a temporary,
2540
    is filled in later.
2638
    is filled in later.
2541
*/
2639
*/
2542
 
2640
 
2543
EXP apply_constr
2641
EXP
2544
    PROTO_N ( ( id, args ) )
-
 
2545
    PROTO_T ( IDENTIFIER id X LIST ( EXP ) args )
2642
apply_constr(IDENTIFIER id, LIST(EXP)args)
2546
{
2643
{
2547
    TYPE t ;
2644
	TYPE t;
2548
    EXP e, a ;
2645
	EXP e, a;
2549
    DECL_SPEC ds ;
2646
	DECL_SPEC ds;
2550
    CLASS_TYPE ct ;
2647
	CLASS_TYPE ct;
2551
    IDENTIFIER cid ;
2648
	IDENTIFIER cid;
2552
    CONS_exp ( NULL_exp, args, args ) ;
2649
	CONS_exp(NULL_exp, args, args);
2553
 
2650
 
2554
    /* Check for trivial constructors */
2651
	/* Check for trivial constructors */
2555
    ds = DEREF_dspec ( id_storage ( id ) ) ;
2652
	ds = DEREF_dspec(id_storage(id));
2556
    if ( ds & dspec_trivial ) {
2653
	if (ds & dspec_trivial) {
2557
	e = apply_trivial_func ( id, args ) ;
2654
		e = apply_trivial_func(id, args);
2558
	if ( !IS_NULL_exp ( e ) ) {
2655
		if (!IS_NULL_exp(e)) {
2559
	    DESTROY_list ( args, SIZE_exp ) ;
2656
			DESTROY_list(args, SIZE_exp);
2560
	    return ( e ) ;
2657
			return (e);
-
 
2658
		}
2561
	}
2659
	}
2562
    }
-
 
2563
 
-
 
2564
    /* Create dummy argument */
-
 
2565
    ct = parent_class ( id ) ;
-
 
2566
    cid = DEREF_id ( ctype_name ( ct ) ) ;
-
 
2567
    MAKE_type_compound ( cv_lvalue, ct, t ) ;
-
 
2568
    COPY_id ( type_name ( t ), cid ) ;
-
 
2569
    MAKE_exp_dummy ( t, NULL_exp, LINK_NONE, NULL_off, 0, a ) ;
-
 
2570
    COPY_exp ( HEAD_list ( args ), a ) ;
-
 
2571
 
2660
 
-
 
2661
	/* Create dummy argument */
-
 
2662
	ct = parent_class(id);
-
 
2663
	cid = DEREF_id(ctype_name(ct));
-
 
2664
	MAKE_type_compound(cv_lvalue, ct, t);
-
 
2665
	COPY_id(type_name(t), cid);
-
 
2666
	MAKE_exp_dummy(t, NULL_exp, LINK_NONE, NULL_off, 0, a);
-
 
2667
	COPY_exp(HEAD_list(args), a);
-
 
2668
 
2572
    /* Apply the constructor */
2669
	/* Apply the constructor */
2573
    e = apply_func_id ( id, qual_none, NULL_graph, args ) ;
2670
	e = apply_func_id(id, qual_none, NULL_graph, args);
2574
    if ( IS_exp_func_id ( e ) ) {
2671
	if (IS_exp_func_id(e)) {
2575
	int n = DEFAULT_USR ;
2672
		int n = DEFAULT_USR;
2576
	TYPE fn = DEREF_type ( id_function_etc_type ( id ) ) ;
2673
		TYPE fn = DEREF_type(id_function_etc_type(id));
2577
	if ( check_copy_constr ( fn, ct ) ) {
2674
		if (check_copy_constr(fn, ct)) {
2578
	    /* Mark copy constructor calls */
2675
			/* Mark copy constructor calls */
2579
	    n = DEFAULT_COPY ;
2676
			n = DEFAULT_COPY;
-
 
2677
		}
-
 
2678
		e = add_constr_args(e, ct, EXTRA_CONSTR);
-
 
2679
		t = make_class_type(ct);
-
 
2680
		MAKE_exp_constr(t, e, a, a, n, e);
2580
	}
2681
	}
2581
	e = add_constr_args ( e, ct, EXTRA_CONSTR ) ;
-
 
2582
	t = make_class_type ( ct ) ;
-
 
2583
	MAKE_exp_constr ( t, e, a, a, n, e ) ;
-
 
2584
    }
-
 
2585
    return ( e ) ;
2682
	return (e);
2586
}
2683
}
2587
 
2684
 
2588
 
2685
 
2589
/*
2686
/*
2590
    INITIALISATION BY CONSTRUCTOR
2687
    INITIALISATION BY CONSTRUCTOR
2591
 
2688
 
2592
    This routine converts the argument list args to the class type t by
2689
    This routine converts the argument list args to the class type t by
2593
    constructor.  The cast parameter indicates if this is an explicit
2690
    constructor.  The cast parameter indicates if this is an explicit
2594
    conversion.  The routine is used, for example, in initialisations of
2691
    conversion.  The routine is used, for example, in initialisations of
2595
    the form 't id ( args )'.
2692
    the form 't id ( args )'.
2596
*/
2693
*/
2597
 
2694
 
2598
EXP convert_constr
2695
EXP
2599
    PROTO_N ( ( t, args, err, cast ) )
-
 
2600
    PROTO_T ( TYPE t X LIST ( EXP ) args X ERROR *err X unsigned cast )
2696
convert_constr(TYPE t, LIST(EXP)args, ERROR *err, unsigned cast)
2601
{
2697
{
2602
    EXP e ;
2698
	EXP e;
2603
    IDENTIFIER cid ;
2699
	IDENTIFIER cid;
2604
    CANDIDATE_LIST *p ;
2700
	CANDIDATE_LIST *p;
2605
 
2701
 
2606
    /* Check for template parameters */
2702
	/* Check for template parameters */
2607
    if ( dependent_conv ( t, args ) ) {
2703
	if (dependent_conv(t, args)) {
2608
	MAKE_exp_opn ( t, lex_static_Hcast, args, e ) ;
2704
		MAKE_exp_opn(t, lex_static_Hcast, args, e);
2609
	return ( e ) ;
2705
		return (e);
2610
    }
-
 
2611
 
-
 
2612
    /* Construct list of candidates */
-
 
2613
    p = &candidates ;
-
 
2614
    p->size = 0 ;
-
 
2615
    cid = constr_candidates ( p, t, cast ) ;
-
 
2616
 
-
 
2617
    /* Perform overload resolution */
-
 
2618
    if ( p->size ) {
-
 
2619
	CANDIDATE *q = resolve_overload ( p, args, NULL_type, 0 ) ;
-
 
2620
	IDENTIFIER qid = q->func ;
-
 
2621
	unsigned rank = q->rank ;
-
 
2622
	int kind = q->kind ;
-
 
2623
	if ( rank == RANK_BEST ) {
-
 
2624
	    /* Unambiguous resolution */
-
 
2625
	    if ( !IS_NULL_id ( cid ) ) {
-
 
2626
		swap_candidates ( p, ( unsigned ) 0 ) ;
-
 
2627
	    }
-
 
2628
	    if ( match_no_viable > 1 && overload_warn ) {
-
 
2629
		add_error ( err, ERR_over_match_ctor_ok ( qid ) ) ;
-
 
2630
	    }
-
 
2631
	} else if ( rank == RANK_VIABLE ) {
-
 
2632
	    /* Ambiguous resolution */
-
 
2633
	    q = resolve_ambiguous ( p, args, NULL_type, 0 ) ;
-
 
2634
	    qid = q->func ;
-
 
2635
	    rank = q->rank ;
-
 
2636
	    if ( !IS_NULL_id ( cid ) ) {
-
 
2637
		swap_candidates ( p, ( unsigned ) 0 ) ;
-
 
2638
	    }
-
 
2639
	    if ( rank == RANK_TARGET ) {
-
 
2640
		ERROR err2 = ERR_over_match_ctor_target ( qid ) ;
-
 
2641
		qid = make_ambig_func ( p, qid, args, qual_none, &err2 ) ;
-
 
2642
		kind = KIND_FUNC ;
-
 
2643
		add_error ( err, err2 ) ;
-
 
2644
	    } else if ( rank == RANK_VIABLE ) {
-
 
2645
		ERROR err2 = ERR_over_match_ctor_ambig ( qid ) ;
-
 
2646
		err2 = list_candidates ( err2, p, RANK_VIABLE ) ;
-
 
2647
		add_error ( err, err2 ) ;
-
 
2648
	    }
-
 
2649
	} else {
-
 
2650
	    /* No resolution */
-
 
2651
	    if ( !IS_NULL_id ( cid ) ) {
-
 
2652
		swap_candidates ( p, ( unsigned ) 0 ) ;
-
 
2653
	    }
-
 
2654
	    goto error_lab ;
-
 
2655
	}
-
 
2656
	use_func_id ( qid, 0, suppress_usage ) ;
-
 
2657
	if ( kind == KIND_CONSTR ) {
-
 
2658
	    e = apply_constr ( qid, args ) ;
-
 
2659
	} else {
-
 
2660
	    /* Can only happen for target dependent resolutions */
-
 
2661
	    e = apply_func_id ( qid, qual_none, NULL_graph, args ) ;
-
 
2662
	    if ( IS_exp_constr ( e ) ) {
-
 
2663
		/* Introduce temporary variable if necessary */
-
 
2664
		TYPE s = DEREF_type ( exp_type ( e ) ) ;
-
 
2665
		e = make_temporary ( s, e, NULL_exp, 0, err ) ;
-
 
2666
		e = convert_lvalue ( e ) ;
-
 
2667
	    }
-
 
2668
	}
-
 
2669
	return ( e ) ;
-
 
2670
    }
-
 
2671
 
-
 
2672
    /* Deal with incomplete structures */
-
 
2673
    if ( IS_NULL_id ( cid ) ) {
-
 
2674
	ERROR err2 = check_incomplete ( t ) ;
-
 
2675
	if ( !IS_NULL_err ( err2 ) ) {
-
 
2676
	    add_error ( err, err2 ) ;
-
 
2677
	    add_error ( err, ERR_expr_type_conv_incompl () ) ;
-
 
2678
	    e = make_null_exp ( t ) ;
-
 
2679
	    return ( e ) ;
-
 
2680
	}
-
 
2681
#if LANGUAGE_C
-
 
2682
	if ( IS_NULL_list ( args ) ) {
-
 
2683
	    /* C default initialisation */
-
 
2684
	    e = make_null_exp ( t ) ;
-
 
2685
	    return ( e ) ;
-
 
2686
	}
2706
	}
-
 
2707
 
-
 
2708
	/* Construct list of candidates */
-
 
2709
	p = &candidates;
-
 
2710
	p->size = 0;
-
 
2711
	cid = constr_candidates(p, t, cast);
-
 
2712
 
-
 
2713
	/* Perform overload resolution */
-
 
2714
	if (p->size) {
-
 
2715
		CANDIDATE *q = resolve_overload(p, args, NULL_type, 0);
-
 
2716
		IDENTIFIER qid = q->func;
-
 
2717
		unsigned rank = q->rank;
-
 
2718
		int kind = q->kind;
-
 
2719
		if (rank == RANK_BEST) {
-
 
2720
			/* Unambiguous resolution */
2687
	if ( IS_NULL_list ( TAIL_list ( args ) ) ) {
2721
			if (!IS_NULL_id(cid)) {
-
 
2722
				swap_candidates(p,(unsigned)0);
-
 
2723
			}
-
 
2724
			if (match_no_viable > 1 && overload_warn) {
-
 
2725
				add_error(err, ERR_over_match_ctor_ok(qid));
-
 
2726
			}
-
 
2727
		} else if (rank == RANK_VIABLE) {
2688
	    /* C copy initialisation */
2728
			/* Ambiguous resolution */
-
 
2729
			q = resolve_ambiguous(p, args, NULL_type, 0);
-
 
2730
			qid = q->func;
-
 
2731
			rank = q->rank;
-
 
2732
			if (!IS_NULL_id(cid)) {
-
 
2733
				swap_candidates(p,(unsigned)0);
-
 
2734
			}
-
 
2735
			if (rank == RANK_TARGET) {
2689
	    EXP a = DEREF_exp ( HEAD_list ( args ) ) ;
2736
				ERROR err2 = ERR_over_match_ctor_target(qid);
-
 
2737
				qid = make_ambig_func(p, qid, args, qual_none,
-
 
2738
						      &err2);
-
 
2739
				kind = KIND_FUNC;
-
 
2740
				add_error(err, err2);
-
 
2741
			} else if (rank == RANK_VIABLE) {
-
 
2742
				ERROR err2 = ERR_over_match_ctor_ambig(qid);
-
 
2743
				err2 = list_candidates(err2, p, RANK_VIABLE);
2690
	    a = convert_none ( a ) ;
2744
				add_error(err, err2);
-
 
2745
			}
-
 
2746
		} else {
-
 
2747
			/* No resolution */
-
 
2748
			if (!IS_NULL_id(cid)) {
-
 
2749
				swap_candidates(p,(unsigned)0);
-
 
2750
			}
-
 
2751
			goto error_lab;
-
 
2752
		}
-
 
2753
		use_func_id(qid, 0, suppress_usage);
-
 
2754
		if (kind == KIND_CONSTR) {
2691
	    a = convert_class ( t, a, err ) ;
2755
			e = apply_constr(qid, args);
-
 
2756
		} else {
-
 
2757
			/* Can only happen for target dependent resolutions */
-
 
2758
			e = apply_func_id(qid, qual_none, NULL_graph, args);
-
 
2759
			if (IS_exp_constr(e)) {
-
 
2760
				/* Introduce temporary variable if necessary */
-
 
2761
				TYPE s = DEREF_type(exp_type(e));
2692
	    a = remove_temporary ( a, NULL_exp ) ;
2762
				e = make_temporary(s, e, NULL_exp, 0, err);
-
 
2763
				e = convert_lvalue(e);
-
 
2764
			}
-
 
2765
		}
2693
	    return ( a ) ;
2766
		return (e);
2694
	}
2767
	}
2695
#endif
-
 
2696
    }
-
 
2697
 
2768
 
-
 
2769
	/* Deal with incomplete structures */
-
 
2770
	if (IS_NULL_id(cid)) {
-
 
2771
		ERROR err2 = check_incomplete(t);
-
 
2772
		if (!IS_NULL_err(err2)) {
-
 
2773
			add_error(err, err2);
-
 
2774
			add_error(err, ERR_expr_type_conv_incompl());
-
 
2775
			e = make_null_exp(t);
-
 
2776
			return (e);
-
 
2777
		}
-
 
2778
#if LANGUAGE_C
-
 
2779
		if (IS_NULL_list(args)) {
-
 
2780
			/* C default initialisation */
-
 
2781
			e = make_null_exp(t);
-
 
2782
			return (e);
-
 
2783
		}
-
 
2784
		if (IS_NULL_list(TAIL_list(args))) {
-
 
2785
			/* C copy initialisation */
-
 
2786
			EXP a = DEREF_exp(HEAD_list(args));
-
 
2787
			a = convert_none(a);
-
 
2788
			a = convert_class(t, a, err);
-
 
2789
			a = remove_temporary(a, NULL_exp);
-
 
2790
			return (a);
-
 
2791
		}
-
 
2792
#endif
-
 
2793
	}
-
 
2794
 
2698
    /* No candidates */
2795
	/* No candidates */
2699
    error_lab : {
2796
error_lab: {
2700
	CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
2797
		   CLASS_TYPE ct = DEREF_ctype(type_compound_defn(t));
2701
	cid = DEREF_id ( ctype_constr ( ct ) ) ;
2798
		   cid = DEREF_id(ctype_constr(ct));
2702
	add_error ( err, ERR_over_match_ctor_none ( cid ) ) ;
2799
		   add_error(err, ERR_over_match_ctor_none(cid));
2703
	e = make_null_exp ( t ) ;
2800
		   e = make_null_exp(t);
2704
    }
2801
	   }
2705
    return ( e ) ;
2802
	   return (e);
2706
}
2803
}
2707
 
2804
 
2708
 
2805
 
2709
/*
2806
/*
2710
    CHECK FOR INITIALISATION BY USER-DEFINED CONVERSION
2807
    CHECK FOR INITIALISATION BY USER-DEFINED CONVERSION
2711
 
2808
 
2712
    This routine checks for user-defined conversions of a to type t.
2809
    This routine checks for user-defined conversions of a to type t.
2713
    It is identical to convert_conv except that it returns the null
2810
    It is identical to convert_conv except that it returns the null
2714
    expression is there are no viable conversion functions.
2811
    expression is there are no viable conversion functions.
2845
 
2944
 
2846
/*
2945
/*
2847
    INITIALISATION BY USER-DEFINED CONVERSION
2946
    INITIALISATION BY USER-DEFINED CONVERSION
2848
 
2947
 
2849
    This routine converts the expression a to the type t by user-defined
2948
    This routine converts the expression a to the type t by user-defined
2850
    conversions.  It is used, for example, in initialisations of the form
2949
    conversions.  It is used, for example, in initialisations of the form
2851
    't id = a'.
2950
    't id = a'.
2852
*/
2951
*/
2853
 
2952
 
2854
EXP convert_conv
2953
EXP
2855
    PROTO_N ( ( t, a, err, cast ) )
-
 
2856
    PROTO_T ( TYPE t X EXP a X ERROR *err X unsigned cast )
2954
convert_conv(TYPE t, EXP a, ERROR *err, unsigned cast)
2857
{
2955
{
2858
    EXP e = convert_conv_aux ( t, a, err, cast ) ;
2956
	EXP e = convert_conv_aux(t, a, err, cast);
2859
    if ( IS_NULL_exp ( e ) ) {
2957
	if (IS_NULL_exp(e)) {
2860
	/* No viable conversion functions */
2958
		/* No viable conversion functions */
2861
	TYPE s ;
2959
		TYPE s;
2862
	a = convert_lvalue ( a ) ;
2960
		a = convert_lvalue(a);
2863
	s = DEREF_type ( exp_type ( a ) ) ;
2961
		s = DEREF_type(exp_type(a));
2864
	if ( !IS_type_error ( s ) && !IS_type_error ( t ) ) {
2962
		if (!IS_type_error(s) && !IS_type_error(t)) {
2865
	    add_error ( err, check_incomplete ( t ) ) ;
2963
			add_error(err, check_incomplete(t));
2866
	    if ( check_int_type ( t, btype_bool ) ) {
2964
			if (check_int_type(t, btype_bool)) {
2867
		e = convert_boolean ( a, exp_paren_tag, err ) ;
2965
				e = convert_boolean(a, exp_paren_tag, err);
2868
		return ( e ) ;
2966
				return (e);
2869
	    }
2967
			}
2870
	    add_error ( err, ERR_expr_cast_invalid ( s, t ) ) ;
2968
			add_error(err, ERR_expr_cast_invalid(s, t));
2871
	}
2969
		}
2872
	e = make_null_exp ( t ) ;
2970
		e = make_null_exp(t);
2873
    } else {
2971
	} else {
2874
	/* Deal with further implicit conversions */
2972
		/* Deal with further implicit conversions */
2875
	TYPE s = DEREF_type ( exp_type ( e ) ) ;
2973
		TYPE s = DEREF_type(exp_type(e));
2876
	if ( IS_type_ref ( s ) ) {
2974
		if (IS_type_ref(s)) {
2877
	    /* Reference conversion */
2975
			/* Reference conversion */
2878
	    s = DEREF_type ( type_ref_sub ( s ) ) ;
2976
			s = DEREF_type(type_ref_sub(s));
2879
	    MAKE_exp_indir ( s, e, e ) ;
2977
			MAKE_exp_indir(s, e, e);
2880
	}
2978
		}
2881
	if ( !IS_type_ref ( t ) ) {
2979
		if (!IS_type_ref(t)) {
2882
	    CV_SPEC cv = DEREF_cv ( type_qual ( s ) ) ;
2980
			CV_SPEC cv = DEREF_cv(type_qual(s));
2883
	    if ( cv & cv_lvalue ) {
2981
			if (cv & cv_lvalue) {
2884
		/* lvalue conversion */
2982
				/* lvalue conversion */
2885
		s = rvalue_type ( s ) ;
2983
				s = rvalue_type(s);
2886
		MAKE_exp_contents ( s, e, e ) ;
2984
				MAKE_exp_contents(s, e, e);
2887
	    }
2985
			}
2888
	}
2986
		}
2889
	if ( !eq_type ( t, s ) ) {
2987
		if (!eq_type(t, s)) {
2890
	    cast = ( CAST_STANDARD | CAST_IMPLICIT ) ;
2988
			cast = (CAST_STANDARD | CAST_IMPLICIT);
2891
	    e = cast_exp ( t, e, err, cast ) ;
2989
			e = cast_exp(t, e, err, cast);
-
 
2990
		}
2892
	}
2991
	}
2893
    }
-
 
2894
    return ( e ) ;
2992
	return (e);
2895
}
2993
}
2896
 
2994
 
2897
 
2995
 
2898
/*
2996
/*
2899
    GENERIC INITIALISATION BY USER-DEFINED CONVERSION
2997
    GENERIC INITIALISATION BY USER-DEFINED CONVERSION
Line 2901... Line 2999...
2901
    This routine selects a user-defined conversion from the expression a
2999
    This routine selects a user-defined conversion from the expression a
2902
    to a type with category matching kind.  It returns the null expression
3000
    to a type with category matching kind.  It returns the null expression
2903
    if no such conversion exists.
3001
    if no such conversion exists.
2904
*/
3002
*/
2905
 
3003
 
2906
EXP convert_gen
3004
EXP
2907
    PROTO_N ( ( kind, a, err ) )
-
 
2908
    PROTO_T ( unsigned kind X EXP a X ERROR *err )
3005
convert_gen(unsigned kind, EXP a, ERROR *err)
2909
{
3006
{
2910
    EXP e = NULL_exp ;
3007
	EXP e = NULL_exp;
2911
    TYPE t = DEREF_type ( exp_type ( a ) ) ;
3008
	TYPE t = DEREF_type(exp_type(a));
2912
 
3009
 
2913
    /* Construct list of candidates */
3010
	/* Construct list of candidates */
2914
    CANDIDATE_LIST *p = &candidates ;
3011
	CANDIDATE_LIST *p = &candidates;
2915
    p->size = 0 ;
3012
	p->size = 0;
2916
    gen_candidates ( p, t, kind ) ;
3013
	gen_candidates(p, t, kind);
2917
 
3014
 
2918
    /* Perform overload resolution */
3015
	/* Perform overload resolution */
2919
    if ( p->size ) {
3016
	if (p->size) {
2920
	CANDIDATE *q ;
3017
		CANDIDATE *q;
2921
	unsigned rank ;
3018
		unsigned rank;
2922
	IDENTIFIER qid ;
3019
		IDENTIFIER qid;
2923
	LIST ( EXP ) args ;
3020
		LIST(EXP)args;
2924
	CONS_exp ( a, NULL_list ( EXP ), args ) ;
3021
		CONS_exp(a, NULL_list(EXP), args);
2925
	match_this++ ;
3022
		match_this++;
2926
	q = resolve_overload ( p, args, NULL_type, 0 ) ;
3023
		q = resolve_overload(p, args, NULL_type, 0);
2927
	match_this-- ;
3024
		match_this--;
2928
	qid = q->func ;
3025
		qid = q->func;
2929
	rank = q->rank ;
3026
		rank = q->rank;
2930
	if ( rank == RANK_BEST ) {
3027
		if (rank == RANK_BEST) {
2931
	    /* Unambiguous resolution */
3028
			/* Unambiguous resolution */
2932
	    if ( match_no_viable > 1 && overload_warn ) {
3029
			if (match_no_viable > 1 && overload_warn) {
2933
		add_error ( err, ERR_over_match_conv_ok ( qid ) ) ;
3030
				add_error(err, ERR_over_match_conv_ok(qid));
2934
	    }
3031
			}
2935
	} else if ( rank == RANK_VIABLE ) {
3032
		} else if (rank == RANK_VIABLE) {
2936
	    /* Ambiguous resolution */
3033
			/* Ambiguous resolution */
2937
	    q = resolve_ambiguous ( p, args, NULL_type, 0 ) ;
3034
			q = resolve_ambiguous(p, args, NULL_type, 0);
2938
	    qid = q->func ;
3035
			qid = q->func;
2939
	    rank = q->rank ;
3036
			rank = q->rank;
2940
	    if ( rank != RANK_BEST ) {
3037
			if (rank != RANK_BEST) {
2941
		/* Can't be target dependent */
3038
				/* Can't be target dependent */
2942
		ERROR err2 = ERR_over_match_conv_dup ( t ) ;
3039
				ERROR err2 = ERR_over_match_conv_dup(t);
2943
		err2 = list_candidates ( err2, p, RANK_VIABLE ) ;
3040
				err2 = list_candidates(err2, p, RANK_VIABLE);
2944
		add_error ( err, err2 ) ;
3041
				add_error(err, err2);
2945
	    }
3042
			}
2946
	} else {
3043
		} else {
2947
	    /* No viable candidates */
3044
			/* No viable candidates */
2948
	    return ( e ) ;
3045
			return (e);
-
 
3046
		}
-
 
3047
		use_func_id(qid, 0, suppress_usage);
-
 
3048
		e = apply_func_id(qid, qual_none, NULL_graph, args);
-
 
3049
		e = convert_reference(e, REF_NORMAL);
-
 
3050
		e = convert_lvalue(e);
2949
	}
3051
	}
2950
	use_func_id ( qid, 0, suppress_usage ) ;
-
 
2951
	e = apply_func_id ( qid, qual_none, NULL_graph, args ) ;
-
 
2952
	e = convert_reference ( e, REF_NORMAL ) ;
-
 
2953
	e = convert_lvalue ( e ) ;
-
 
2954
    }
-
 
2955
 
3052
 
2956
    /* No candidates */
3053
	/* No candidates */
2957
    return ( e ) ;
3054
	return (e);
2958
}
3055
}