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

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

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

Subversion Repositories tendra.SVN

Rev

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

Rev 2 Rev 7
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2006 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997, 1998
32
    		 Crown Copyright (c) 1997, 1998
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
Line 82... Line 112...
82
/*
112
/*
83
    SET A CLASS KEY
113
    SET A CLASS KEY
84
 
114
 
85
    This routine adjusts the class information ci to be that representing
115
    This routine adjusts the class information ci to be that representing
86
    the given class key.
116
    the given class key.
87
*/
117
*/
88
 
118
 
89
static CLASS_INFO set_class_key
119
static CLASS_INFO
90
    PROTO_N ( ( ci, key ) )
-
 
91
    PROTO_T ( CLASS_INFO ci X BASE_TYPE key )
120
set_class_key(CLASS_INFO ci, BASE_TYPE key)
92
{
121
{
93
    ci &= ~cinfo_key ;
122
	ci &= ~cinfo_key;
94
    if ( key == btype_union ) {
123
	if (key == btype_union) {
95
	ci |= cinfo_union ;
124
		ci |= cinfo_union;
96
    } else if ( key == btype_struct ) {
125
	} else if (key == btype_struct) {
97
	ci |= cinfo_struct ;
126
		ci |= cinfo_struct;
98
    }
127
	}
99
    return ( ci ) ;
128
	return (ci);
100
}
129
}
101
 
130
 
102
 
131
 
103
/*
132
/*
104
    IS A NAMESPACE CONTAINED IN A BLOCK?
133
    IS A NAMESPACE CONTAINED IN A BLOCK?
105
 
134
 
106
    This routine checks whether the namespace ns is enclosed within a
135
    This routine checks whether the namespace ns is enclosed within a
107
    block namespace.
136
    block namespace.
108
*/
137
*/
109
 
138
 
110
int is_local_nspace
139
int
111
    PROTO_N ( ( ns ) )
-
 
112
    PROTO_T ( NAMESPACE ns )
140
is_local_nspace(NAMESPACE ns)
113
{
141
{
114
    while ( !IS_NULL_nspace ( ns ) ) {
142
	while (!IS_NULL_nspace(ns)) {
115
	IDENTIFIER id ;
143
		IDENTIFIER id;
116
	switch ( TAG_nspace ( ns ) ) {
144
		switch (TAG_nspace(ns)) {
117
	    case nspace_block_tag :
145
		case nspace_block_tag:
118
	    case nspace_dummy_tag : {
146
		case nspace_dummy_tag: {
119
		return ( 1 ) ;
147
			return (1);
120
	    }
148
		}
121
	    case nspace_param_tag :
149
		case nspace_param_tag:
122
	    case nspace_templ_tag : {
150
		case nspace_templ_tag: {
123
		return ( 2 ) ;
151
			return (2);
-
 
152
		}
-
 
153
		}
-
 
154
		id = DEREF_id(nspace_name(ns));
-
 
155
		if (IS_NULL_id(id)) {
-
 
156
			break;
124
	    }
157
		}
-
 
158
		ns = DEREF_nspace(id_parent(id));
125
	}
159
	}
126
	id = DEREF_id ( nspace_name ( ns ) ) ;
-
 
127
	if ( IS_NULL_id ( id ) ) break ;
-
 
128
	ns = DEREF_nspace ( id_parent ( id ) ) ;
-
 
129
    }
-
 
130
    return ( 0 ) ;
160
	return (0);
131
}
161
}
132
 
162
 
133
 
163
 
134
/*
164
/*
135
    CREATE A CLASS OR ENUMERATION TYPE
165
    CREATE A CLASS OR ENUMERATION TYPE
136
 
166
 
137
    This routine creates a class or enumeration type (indicated by key)
167
    This routine creates a class or enumeration type (indicated by key)
138
    with type name nm and template qualifiers q in the namespace ns.
168
    with type name nm and template qualifiers q in the namespace ns.
139
*/
169
*/
140
 
170
 
141
IDENTIFIER make_class
171
IDENTIFIER
142
    PROTO_N ( ( ns, nm, key, bds, q, prev ) )
-
 
143
    PROTO_T ( NAMESPACE ns X HASHID nm X BASE_TYPE key X
172
make_class(NAMESPACE ns, HASHID nm, BASE_TYPE key, DECL_SPEC bds, TYPE q,
144
	      DECL_SPEC bds X TYPE q X TYPE prev )
173
	   TYPE prev)
145
{
174
{
146
    TYPE t ;
175
	TYPE t;
147
    IDENTIFIER id ;
176
	IDENTIFIER id;
148
    ENUM_TYPE et = NULL_etype ;
177
	ENUM_TYPE et = NULL_etype;
149
    CLASS_TYPE ct = NULL_ctype ;
178
	CLASS_TYPE ct = NULL_ctype;
150
    CLASS_INFO ci = cinfo_default ;
179
	CLASS_INFO ci = cinfo_default;
151
    DECL_SPEC ds = ( bds | dspec_lang ) ;
180
	DECL_SPEC ds = (bds | dspec_lang);
152
    if ( option ( OPT_complete_struct ) && crt_file_type == 0 ) {
181
	if (option(OPT_complete_struct) && crt_file_type == 0) {
153
	/* Allow incomplete types in start-up files */
182
		/* Allow incomplete types in start-up files */
154
	ci |= cinfo_incomplete ;
183
		ci |= cinfo_incomplete;
155
    }
-
 
156
 
-
 
157
    /* Check on class linkage and access */
-
 
158
    if ( !IS_NULL_nspace ( ns ) ) {
-
 
159
	if ( IS_nspace_ctype ( ns ) ) {
-
 
160
	    /* Only nested classes (not friend classes) have access */
-
 
161
	    if ( !( ds & dspec_access ) ) ds |= crt_access ;
-
 
162
	}
-
 
163
	if ( !really_in_function_defn || !is_local_nspace ( ns ) ) {
-
 
164
	    ds |= dspec_extern ;
-
 
165
	}
184
	}
166
    }
-
 
167
 
-
 
168
    if ( key == btype_enum ) {
-
 
169
	/* Create the enumeration type */
-
 
170
	MAKE_id_enum_name ( nm, ds, ns, decl_loc, NULL_type, id ) ;
-
 
171
	COPY_btype ( id_enum_name_rep ( id ), key ) ;
-
 
172
	MAKE_etype_basic ( id, ci, type_sint, et ) ;
-
 
173
	MAKE_type_enumerate ( cv_none, et, t ) ;
-
 
174
	if ( !IS_NULL_type ( q ) ) {
-
 
175
	    report ( decl_loc, ERR_temp_decl_bad () ) ;
-
 
176
	}
-
 
177
	COPY_type ( id_enum_name_defn ( id ), t ) ;
-
 
178
 
-
 
179
    } else {
-
 
180
	TYPE s ;
-
 
181
	GRAPH gr ;
-
 
182
	MEMBER mem ;
-
 
183
	NAMESPACE mns ;
-
 
184
	DECL_SPEC acc ;
-
 
185
	IDENTIFIER cid ;
-
 
186
 
-
 
187
	/* Allow for template classes */
-
 
188
	if ( !IS_NULL_type ( q ) ) {
-
 
189
	    ds |= dspec_template ;
-
 
190
	    ci |= cinfo_template ;
-
 
191
	}
-
 
192
 
-
 
193
	/* Create the class member namespace */
-
 
194
	MAKE_id_class_name ( nm, ds, ns, decl_loc, NULL_type, id ) ;
-
 
195
	COPY_btype ( id_class_name_rep ( id ), key ) ;
-
 
196
	mns = make_namespace ( id, nspace_ctype_tag, 20 ) ;
-
 
197
 
-
 
198
	/* Construct the base class graph */
-
 
199
	acc = ( dspec_public | dspec_defn | dspec_done ) ;
-
 
200
	MAKE_graph_basic ( NULL_ctype, acc, gr ) ;
-
 
201
	COPY_graph ( graph_top ( gr ), gr ) ;
-
 
202
 
-
 
203
	/* Construct the class */
-
 
204
	ci = set_class_key ( ci, key ) ;
-
 
205
	MAKE_ctype_basic ( id, ci, cusage_none, mns, gr, 1, prev, ct ) ;
-
 
206
	COPY_ctype ( graph_head ( gr ), ct ) ;
-
 
207
 
-
 
208
	/* Construct the class type */
-
 
209
	MAKE_type_compound ( cv_none, ct, t ) ;
-
 
210
	COPY_type ( id_class_name_defn ( id ), t ) ;
-
 
211
	s = t ;
-
 
212
	if ( !IS_NULL_type ( q ) ) {
-
 
213
	    /* Allow for template qualifiers */
-
 
214
	    t = inject_pre_type ( q, t, 0 ) ;
-
 
215
	    COPY_type ( id_class_name_defn ( id ), t ) ;
-
 
216
	    IGNORE check_templ_params ( t, id ) ;
-
 
217
	}
-
 
218
 
185
 
219
	/* Construct the constructor and destructor names */
186
	/* Check on class linkage and access */
-
 
187
	if (!IS_NULL_nspace(ns)) {
220
	IGNORE lookup_constr ( s, id ) ;
188
		if (IS_nspace_ctype(ns)) {
-
 
189
			/* Only nested classes (not friend classes) have
-
 
190
			 * access */
221
	IGNORE lookup_destr ( s, id ) ;
191
			if (!(ds & dspec_access)) {
-
 
192
				ds |= crt_access;
-
 
193
			}
-
 
194
		}
-
 
195
		if (!really_in_function_defn || !is_local_nspace(ns)) {
-
 
196
			ds |= dspec_extern;
-
 
197
		}
-
 
198
	}
222
 
199
 
-
 
200
	if (key == btype_enum) {
-
 
201
		/* Create the enumeration type */
-
 
202
		MAKE_id_enum_name(nm, ds, ns, decl_loc, NULL_type, id);
-
 
203
		COPY_btype(id_enum_name_rep(id), key);
-
 
204
		MAKE_etype_basic(id, ci, type_sint, et);
-
 
205
		MAKE_type_enumerate(cv_none, et, t);
-
 
206
		if (!IS_NULL_type(q)) {
-
 
207
			report(decl_loc, ERR_temp_decl_bad());
-
 
208
		}
-
 
209
		COPY_type(id_enum_name_defn(id), t);
-
 
210
	} else {
-
 
211
		TYPE s;
-
 
212
		GRAPH gr;
-
 
213
		MEMBER mem;
-
 
214
		NAMESPACE mns;
-
 
215
		DECL_SPEC acc;
-
 
216
		IDENTIFIER cid;
-
 
217
 
-
 
218
		/* Allow for template classes */
-
 
219
		if (!IS_NULL_type(q)) {
-
 
220
			ds |= dspec_template;
-
 
221
			ci |= cinfo_template;
-
 
222
		}
-
 
223
 
-
 
224
		/* Create the class member namespace */
-
 
225
		MAKE_id_class_name(nm, ds, ns, decl_loc, NULL_type, id);
-
 
226
		COPY_btype(id_class_name_rep(id), key);
-
 
227
		mns = make_namespace(id, nspace_ctype_tag, 20);
-
 
228
 
-
 
229
		/* Construct the base class graph */
-
 
230
		acc = (dspec_public | dspec_defn | dspec_done);
-
 
231
		MAKE_graph_basic(NULL_ctype, acc, gr);
-
 
232
		COPY_graph(graph_top(gr), gr);
-
 
233
 
-
 
234
		/* Construct the class */
-
 
235
		ci = set_class_key(ci, key);
-
 
236
		MAKE_ctype_basic(id, ci, cusage_none, mns, gr, 1, prev, ct);
-
 
237
		COPY_ctype(graph_head(gr), ct);
-
 
238
 
-
 
239
		/* Construct the class type */
-
 
240
		MAKE_type_compound(cv_none, ct, t);
-
 
241
		COPY_type(id_class_name_defn(id), t);
-
 
242
		s = t;
-
 
243
		if (!IS_NULL_type(q)) {
-
 
244
			/* Allow for template qualifiers */
-
 
245
			t = inject_pre_type(q, t, 0);
-
 
246
			COPY_type(id_class_name_defn(id), t);
-
 
247
			IGNORE check_templ_params(t, id);
-
 
248
		}
-
 
249
 
-
 
250
		/* Construct the constructor and destructor names */
-
 
251
		IGNORE lookup_constr(s, id);
-
 
252
		IGNORE lookup_destr(s, id);
-
 
253
 
223
	/* Inject the class name into the class */
254
		/* Inject the class name into the class */
224
	ds &= ~dspec_access ;
255
		ds &= ~dspec_access;
225
	ds |= ( dspec_alias | dspec_implicit | dspec_public ) ;
256
		ds |= (dspec_alias | dspec_implicit | dspec_public);
226
	if ( bds & dspec_instance ) ds |= dspec_template ;
257
		if (bds & dspec_instance) {
-
 
258
			ds |= dspec_template;
-
 
259
		}
227
	mem = search_member ( mns, nm, 1 ) ;
260
		mem = search_member(mns, nm, 1);
228
	MAKE_id_class_name ( nm, ds, mns, decl_loc, t, cid ) ;
261
		MAKE_id_class_name(nm, ds, mns, decl_loc, t, cid);
229
	COPY_btype ( id_class_name_rep ( cid ), key ) ;
262
		COPY_btype(id_class_name_rep(cid), key);
230
	COPY_id ( id_alias ( cid ), id ) ;
263
		COPY_id(id_alias(cid), id);
231
	COPY_id ( member_alt ( mem ), cid ) ;
264
		COPY_id(member_alt(mem), cid);
232
#if LANGUAGE_CPP
265
#if LANGUAGE_CPP
233
	COPY_id ( member_id ( mem ), cid ) ;
266
		COPY_id(member_id(mem), cid);
234
#endif
267
#endif
235
    }
-
 
236
 
-
 
237
    /* Deal with nested classes */
-
 
238
    if ( IS_nspace_ctype ( ns ) ) {
-
 
239
	CLASS_TYPE cr ;
-
 
240
	CLASS_INFO cj ;
-
 
241
	LIST ( IDENTIFIER ) fr ;
-
 
242
	IDENTIFIER rid = DEREF_id ( nspace_name ( ns ) ) ;
-
 
243
	TYPE r = DEREF_type ( id_class_name_defn ( rid ) ) ;
-
 
244
	while ( IS_type_templ ( r ) ) {
-
 
245
	    r = DEREF_type ( type_templ_defn ( r ) ) ;
-
 
246
	}
268
	}
-
 
269
 
-
 
270
	/* Deal with nested classes */
-
 
271
	if (IS_nspace_ctype(ns)) {
-
 
272
		CLASS_TYPE cr;
-
 
273
		CLASS_INFO cj;
-
 
274
		LIST(IDENTIFIER)fr;
-
 
275
		IDENTIFIER rid = DEREF_id(nspace_name(ns));
-
 
276
		TYPE r = DEREF_type(id_class_name_defn(rid));
-
 
277
		while (IS_type_templ(r)) {
-
 
278
			r = DEREF_type(type_templ_defn(r));
-
 
279
		}
247
	cr = DEREF_ctype ( type_compound_defn ( r ) ) ;
280
		cr = DEREF_ctype(type_compound_defn(r));
248
	cj = DEREF_cinfo ( ctype_info ( cr ) ) ;
281
		cj = DEREF_cinfo(ctype_info(cr));
249
	if ( cj & cinfo_template ) {
282
		if (cj & cinfo_template) {
250
	    /* Mark nested template classes */
283
			/* Mark nested template classes */
251
	    ci |= ( cinfo_template | cinfo_rescan ) ;
284
			ci |= (cinfo_template | cinfo_rescan);
-
 
285
		}
-
 
286
		ci |= cinfo_nested;
-
 
287
		if (!IS_NULL_ctype(ct)) {
-
 
288
			COPY_cinfo(ctype_info(ct), ci);
-
 
289
		}
-
 
290
		if (!IS_NULL_etype(et)) {
-
 
291
			COPY_cinfo(etype_info(et), ci);
-
 
292
		}
-
 
293
		fr = DEREF_list(ctype_nest(cr));
-
 
294
		CONS_id(id, fr, fr);
-
 
295
		COPY_list(ctype_nest(cr), fr);
252
	}
296
	}
253
	ci |= cinfo_nested ;
-
 
254
	if ( !IS_NULL_ctype ( ct ) ) COPY_cinfo ( ctype_info ( ct ), ci ) ;
-
 
255
	if ( !IS_NULL_etype ( et ) ) COPY_cinfo ( etype_info ( et ), ci ) ;
-
 
256
	fr = DEREF_list ( ctype_nest ( cr ) ) ;
-
 
257
	CONS_id ( id, fr, fr ) ;
-
 
258
	COPY_list ( ctype_nest ( cr ), fr ) ;
-
 
259
    }
-
 
260
    return ( id ) ;
297
	return (id);
261
}
298
}
262
 
299
 
263
 
300
 
264
/*
301
/*
265
    CHECK A CONSTRUCTOR NAME
302
    CHECK A CONSTRUCTOR NAME
Line 267... Line 304...
267
    This routine is called for a declarator id which represents a type
304
    This routine is called for a declarator id which represents a type
268
    name in the namespace ns.  It checks whether id is actually a
305
    name in the namespace ns.  It checks whether id is actually a
269
    constructor name, and if so returns the correct identifier.
306
    constructor name, and if so returns the correct identifier.
270
*/
307
*/
271
 
308
 
272
IDENTIFIER constr_name
309
IDENTIFIER
273
    PROTO_N ( ( ns, id ) )
-
 
274
    PROTO_T ( NAMESPACE ns X IDENTIFIER id )
310
constr_name(NAMESPACE ns, IDENTIFIER id)
275
{
311
{
276
    unsigned tag = TAG_id ( id ) ;
312
	unsigned tag = TAG_id(id);
277
    if ( tag == id_class_name_tag || tag == id_class_alias_tag ) {
313
	if (tag == id_class_name_tag || tag == id_class_alias_tag) {
278
	CLASS_TYPE ct ;
314
		CLASS_TYPE ct;
279
	NAMESPACE cns ;
315
		NAMESPACE cns;
280
	TYPE t = DEREF_type ( id_class_name_etc_defn ( id ) ) ;
316
		TYPE t = DEREF_type(id_class_name_etc_defn(id));
281
	while ( IS_type_templ ( t ) ) {
317
		while (IS_type_templ(t)) {
282
	    t = DEREF_type ( type_templ_defn ( t ) ) ;
318
			t = DEREF_type(type_templ_defn(t));
283
	}
319
		}
284
	ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
320
		ct = DEREF_ctype(type_compound_defn(t));
285
	cns = DEREF_nspace ( ctype_member ( ct ) ) ;
321
		cns = DEREF_nspace(ctype_member(ct));
286
	if ( IS_NULL_nspace ( ns ) ) ns = crt_namespace ;
322
		if (IS_NULL_nspace(ns)) {
-
 
323
			ns = crt_namespace;
-
 
324
		}
287
	if ( EQ_nspace ( ns, cns ) ) {
325
		if (EQ_nspace(ns, cns)) {
288
	    /* This is a constructor */
326
			/* This is a constructor */
289
	    IDENTIFIER cid = DEREF_id ( ctype_constr ( ct ) ) ;
327
			IDENTIFIER cid = DEREF_id(ctype_constr(ct));
290
	    if ( tag == id_class_alias_tag && is_constructor_next ) {
328
			if (tag == id_class_alias_tag && is_constructor_next) {
291
		/* Can't use type alias */
329
				/* Can't use type alias */
292
		HASHID cnm = DEREF_hashid ( id_name ( cid ) ) ;
330
				HASHID cnm = DEREF_hashid(id_name(cid));
-
 
331
				IDENTIFIER tid =
293
		IDENTIFIER tid = DEREF_id ( hashid_constr_tid ( cnm ) ) ;
332
				    DEREF_id(hashid_constr_tid(cnm));
294
		if ( !EQ_id ( tid, id ) ) {
333
				if (!EQ_id(tid, id)) {
295
		    report ( crt_loc, ERR_dcl_typedef_constr ( id, cnm ) ) ;
334
					report(crt_loc, ERR_dcl_typedef_constr(id, cnm));
-
 
335
				}
-
 
336
			}
-
 
337
			set_hashid_loc(cid, id);
-
 
338
			id = cid;
296
		}
339
		}
297
	    }
-
 
298
	    set_hashid_loc ( cid, id ) ;
-
 
299
	    id = cid ;
-
 
300
	}
340
	}
301
    }
-
 
302
    is_constructor_next = 0 ;
341
	is_constructor_next = 0;
303
    return ( id ) ;
342
	return (id);
304
}
343
}
305
 
344
 
306
 
345
 
307
/*
346
/*
308
    HAS A TYPE BEEN DEFINED?
347
    HAS A TYPE BEEN DEFINED?
309
 
348
 
310
    This routine checks whether the type associated with the identifier id
349
    This routine checks whether the type associated with the identifier id
311
    has been defined or just declared.  A value of 2 is returned for
350
    has been defined or just declared.  A value of 2 is returned for
312
    tokenised types.  The value associated with a defined type is returned
351
    tokenised types.  The value associated with a defined type is returned
313
    via pt.  If force is true then any template classes are completed.
352
    via pt.  If force is true then any template classes are completed.
314
*/
-
 
315
 
-
 
316
int is_defined
-
 
317
    PROTO_N ( ( id, pt, force ) )
-
 
318
    PROTO_T ( IDENTIFIER id X TYPE *pt X int force )
-
 
319
{
-
 
320
    if ( IS_id_class_name_etc ( id ) ) {
-
 
321
	CLASS_INFO ci ;
-
 
322
	TYPE t = DEREF_type ( id_class_name_etc_defn ( id ) ) ;
-
 
323
	unsigned tag = TAG_type ( t ) ;
-
 
324
	*pt = t ;
-
 
325
	while ( tag == type_templ_tag ) {
-
 
326
	    t = DEREF_type ( type_templ_defn ( t ) ) ;
-
 
327
	    tag = TAG_type ( t ) ;
-
 
328
	}
-
 
329
	if ( tag == type_compound_tag ) {
-
 
330
	    /* Class type */
-
 
331
	    CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
-
 
332
	    if ( force ) complete_class ( ct, 0 ) ;
-
 
333
	    ci = DEREF_cinfo ( ctype_info ( ct ) ) ;
-
 
334
	} else if ( tag == type_enumerate_tag ) {
-
 
335
	    /* Enumeration type */
-
 
336
	    ENUM_TYPE et = DEREF_etype ( type_enumerate_defn ( t ) ) ;
-
 
337
	    ci = DEREF_cinfo ( etype_info ( et ) ) ;
-
 
338
	} else {
-
 
339
	    return ( 1 ) ;
-
 
340
	}
-
 
341
	if ( ci & cinfo_token ) {
-
 
342
	    /* Tokenised types */
-
 
343
	    IDENTIFIER tid = find_token ( id ) ;
-
 
344
	    DECL_SPEC ds = DEREF_dspec ( id_storage ( tid ) ) ;
-
 
345
	    if ( ds & dspec_pure ) return ( 1 ) ;
-
 
346
	    return ( 2 ) ;
-
 
347
	}
-
 
348
	if ( ci & ( cinfo_complete | cinfo_defined ) ) {
-
 
349
	    /* Defined types */
-
 
350
	    return ( 1 ) ;
-
 
351
	}
-
 
352
    }
-
 
353
    return ( 0 ) ;
-
 
354
}
-
 
355
 
-
 
356
 
-
 
357
/*
-
 
358
    FIND THE KEY ASSOCIATED WITH A CLASS
-
 
359
 
-
 
360
    This routine returns the class key associated with the class type ct.
-
 
361
*/
353
*/
362
 
354
 
363
BASE_TYPE find_class_key
355
int
364
    PROTO_N ( ( ct ) )
-
 
365
    PROTO_T ( CLASS_TYPE ct )
356
is_defined(IDENTIFIER id, TYPE *pt, int force)
366
{
357
{
-
 
358
	if (IS_id_class_name_etc(id)) {
-
 
359
		CLASS_INFO ci;
-
 
360
		TYPE t = DEREF_type(id_class_name_etc_defn(id));
-
 
361
		unsigned tag = TAG_type(t);
-
 
362
		*pt = t;
-
 
363
		while (tag == type_templ_tag) {
-
 
364
			t = DEREF_type(type_templ_defn(t));
-
 
365
			tag = TAG_type(t);
-
 
366
		}
-
 
367
		if (tag == type_compound_tag) {
-
 
368
			/* Class type */
-
 
369
			CLASS_TYPE ct = DEREF_ctype(type_compound_defn(t));
-
 
370
			if (force) {
-
 
371
				complete_class(ct, 0);
-
 
372
			}
367
    CLASS_INFO ci = DEREF_cinfo ( ctype_info ( ct ) ) ;
373
			ci = DEREF_cinfo(ctype_info(ct));
-
 
374
		} else if (tag == type_enumerate_tag) {
-
 
375
			/* Enumeration type */
-
 
376
			ENUM_TYPE et = DEREF_etype(type_enumerate_defn(t));
368
    if ( ci & cinfo_union ) return ( btype_union ) ;
377
			ci = DEREF_cinfo(etype_info(et));
-
 
378
		} else {
-
 
379
			return (1);
-
 
380
		}
-
 
381
		if (ci & cinfo_token) {
-
 
382
			/* Tokenised types */
-
 
383
			IDENTIFIER tid = find_token(id);
-
 
384
			DECL_SPEC ds = DEREF_dspec(id_storage(tid));
-
 
385
			if (ds & dspec_pure) {
-
 
386
				return (1);
-
 
387
			}
-
 
388
			return (2);
-
 
389
		}
369
    if ( ci & cinfo_struct ) return ( btype_struct ) ;
390
		if (ci & (cinfo_complete | cinfo_defined)) {
370
    return ( btype_class ) ;
391
			/* Defined types */
-
 
392
			return (1);
-
 
393
		}
-
 
394
	}
-
 
395
	return (0);
371
}
396
}
372
 
397
 
373
 
398
 
374
/*
399
/*
375
    FIND THE KEY ASSOCIATED WITH A TYPE
400
    FIND THE KEY ASSOCIATED WITH A CLASS
376
 
401
 
377
    This routine returns the class key associated with the identifier id.
402
    This routine returns the class key associated with the class type ct.
378
    Note that typedef names are only expanded to their definitions if
-
 
379
    expand is true.  If id is a template type parameter which has not
-
 
380
    previously been qualified then its key is set to new_key.
-
 
381
*/
403
*/
382
 
404
 
383
static BASE_TYPE find_key
405
BASE_TYPE
384
    PROTO_N ( ( id, expand, new_key ) )
406
find_class_key(CLASS_TYPE ct)
385
    PROTO_T ( IDENTIFIER id X int expand X BASE_TYPE new_key )
-
 
386
{
407
{
387
    switch ( TAG_id ( id ) ) {
-
 
388
	case id_class_name_tag :
-
 
389
	class_name_lab : {
-
 
390
	    /* Class names */
-
 
391
	    CLASS_TYPE ct ;
-
 
392
	    BASE_TYPE key ;
-
 
393
	    TYPE t = DEREF_type ( id_class_name_etc_defn ( id ) ) ;
-
 
394
	    while ( IS_type_templ ( t ) ) {
-
 
395
		t = DEREF_type ( type_templ_defn ( t ) ) ;
-
 
396
	    }
-
 
397
	    ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
408
	CLASS_INFO ci = DEREF_cinfo(ctype_info(ct));
398
	    key = find_class_key ( ct ) ;
409
	if (ci & cinfo_union) {
399
	    return ( key ) ;
410
		return (btype_union);
400
	}
411
	}
401
	case id_enum_name_tag : {
412
	if (ci & cinfo_struct) {
402
	    /* Enumeration names */
-
 
403
	    return ( btype_enum ) ;
413
		return (btype_struct);
404
	}
-
 
405
	case id_class_alias_tag : {
-
 
406
	    /* Class aliases */
-
 
407
	    if ( expand ) goto class_name_lab ;
-
 
408
	    return ( btype_alias ) ;
-
 
409
	}
414
	}
-
 
415
	return (btype_class);
-
 
416
}
-
 
417
 
-
 
418
 
-
 
419
/*
-
 
420
    FIND THE KEY ASSOCIATED WITH A TYPE
-
 
421
 
-
 
422
    This routine returns the class key associated with the identifier id.
-
 
423
    Note that typedef names are only expanded to their definitions if
-
 
424
    expand is true.  If id is a template type parameter which has not
-
 
425
    previously been qualified then its key is set to new_key.
-
 
426
*/
-
 
427
 
-
 
428
static BASE_TYPE
-
 
429
find_key(IDENTIFIER id, int expand, BASE_TYPE new_key)
-
 
430
{
-
 
431
	switch (TAG_id(id)) {
-
 
432
	case id_class_name_tag:
-
 
433
class_name_lab: {
-
 
434
			/* Class names */
-
 
435
			CLASS_TYPE ct;
-
 
436
			BASE_TYPE key;
-
 
437
			TYPE t = DEREF_type(id_class_name_etc_defn(id));
-
 
438
			while (IS_type_templ(t)) {
-
 
439
				t = DEREF_type(type_templ_defn(t));
-
 
440
			}
-
 
441
			ct = DEREF_ctype(type_compound_defn(t));
-
 
442
			key = find_class_key(ct);
-
 
443
			return (key);
-
 
444
		}
-
 
445
	case id_enum_name_tag: {
-
 
446
		/* Enumeration names */
-
 
447
		return (btype_enum);
-
 
448
	}
-
 
449
	case id_class_alias_tag: {
-
 
450
		/* Class aliases */
-
 
451
		if (expand) {
-
 
452
			goto class_name_lab;
-
 
453
		}
-
 
454
		return (btype_alias);
-
 
455
	}
410
	case id_enum_alias_tag : {
456
	case id_enum_alias_tag: {
411
	    /* Enumeration aliases */
457
		/* Enumeration aliases */
-
 
458
		if (expand) {
412
	    if ( expand ) return ( btype_enum ) ;
459
			return (btype_enum);
-
 
460
		}
413
	    return ( btype_alias ) ;
461
		return (btype_alias);
414
	}
462
	}
415
	case id_type_alias_tag : {
463
	case id_type_alias_tag: {
416
	    /* Type aliases */
464
		/* Type aliases */
417
	    DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
465
		DECL_SPEC ds = DEREF_dspec(id_storage(id));
418
	    if ( ds & dspec_token ) {
466
		if (ds & dspec_token) {
419
		/* Check tokenised types */
467
			/* Check tokenised types */
420
		TYPE t = DEREF_type ( id_type_alias_defn ( id ) ) ;
468
			TYPE t = DEREF_type(id_type_alias_defn(id));
421
		if ( IS_type_token ( t ) ) {
469
			if (IS_type_token(t)) {
422
		    id = DEREF_id ( type_token_tok ( t ) ) ;
470
				id = DEREF_id(type_token_tok(t));
423
		    return ( find_key ( id, expand, new_key ) ) ;
471
				return (find_key(id, expand, new_key));
424
		}
472
			}
425
	    }
473
		}
426
	    return ( btype_alias ) ;
474
		return (btype_alias);
427
	}
475
	}
428
	case id_token_tag : {
476
	case id_token_tag: {
429
	    /* Tokenised types */
477
		/* Tokenised types */
430
	    TOKEN tok = DEREF_tok ( id_token_sort ( id ) ) ;
478
		TOKEN tok = DEREF_tok(id_token_sort(id));
431
	    if ( IS_tok_type ( tok ) ) {
479
		if (IS_tok_type(tok)) {
432
		BASE_TYPE bt = DEREF_btype ( tok_type_kind ( tok ) ) ;
480
			BASE_TYPE bt = DEREF_btype(tok_type_kind(tok));
433
		if ( bt & btype_template ) {
481
			if (bt & btype_template) {
434
		    /* Template parameter */
482
				/* Template parameter */
435
		    BASE_TYPE key = ( bt & btype_named ) ;
483
				BASE_TYPE key = (bt & btype_named);
436
		    if ( key == btype_none ) {
484
				if (key == btype_none) {
437
			key = new_key ;
485
					key = new_key;
438
			bt |= key ;
486
					bt |= key;
439
			COPY_btype ( tok_type_kind ( tok ), bt ) ;
487
					COPY_btype(tok_type_kind(tok), bt);
440
		    }
488
				}
441
		    return ( key ) ;
489
				return (key);
-
 
490
			}
-
 
491
			return (btype_alias);
442
		}
492
		}
443
		return ( btype_alias ) ;
493
		break;
444
	    }
494
	}
445
	    break ;
-
 
446
	}
495
	}
447
    }
-
 
448
    return ( btype_none ) ;
496
	return (btype_none);
449
}
497
}
450
 
498
 
451
 
499
 
452
/*
500
/*
453
    CHECK THAT TWO CLASS KEYS ARE CONSISTENT
501
    CHECK THAT TWO CLASS KEYS ARE CONSISTENT
454
 
502
 
455
    This routine checks whether the class keys key1 and key2 are consistent.
503
    This routine checks whether the class keys key1 and key2 are consistent.
456
    Basically they are consistent if they are equal, but also 'class' is
504
    Basically they are consistent if they are equal, but also 'class' is
457
    consistent with 'struct'.
505
    consistent with 'struct'.
458
*/
506
*/
459
 
507
 
460
int equal_key
508
int
461
    PROTO_N ( ( key1, key2 ) )
-
 
462
    PROTO_T ( BASE_TYPE key1 X BASE_TYPE key2 )
509
equal_key(BASE_TYPE key1, BASE_TYPE key2)
463
{
510
{
464
    if ( key1 == key2 ) return ( 1 ) ;
511
	if (key1 == key2) {
-
 
512
		return (1);
-
 
513
	}
465
    if ( key1 == btype_class && key2 == btype_struct ) return ( 1 ) ;
514
	if (key1 == btype_class && key2 == btype_struct) {
-
 
515
		return (1);
-
 
516
	}
466
    if ( key1 == btype_struct && key2 == btype_class ) return ( 1 ) ;
517
	if (key1 == btype_struct && key2 == btype_class) {
-
 
518
		return (1);
-
 
519
	}
467
    if ( key1 == btype_any || key2 == btype_any ) return ( 1 ) ;
520
	if (key1 == btype_any || key2 == btype_any) {
-
 
521
		return (1);
-
 
522
	}
468
    return ( 0 ) ;
523
	return (0);
469
}
524
}
470
 
525
 
471
 
526
 
472
/*
527
/*
473
    CHECK A CLASS KEY
528
    CHECK A CLASS KEY
474
 
529
 
475
    This routine checks the given class key for the type id.  It returns
530
    This routine checks the given class key for the type id.  It returns
476
    true if either the new or the existing class key is 'enum'.
531
    true if either the new or the existing class key is 'enum'.
477
*/
532
*/
478
 
533
 
479
static int check_key
534
static int
480
    PROTO_N ( ( id, key ) )
-
 
481
    PROTO_T ( IDENTIFIER id X BASE_TYPE key )
535
check_key(IDENTIFIER id, BASE_TYPE key)
482
{
536
{
483
    int is_enum = 0 ;
537
	int is_enum = 0;
484
    BASE_TYPE prev = find_key ( id, 1, key ) ;
538
	BASE_TYPE prev = find_key(id, 1, key);
485
    if ( !equal_key ( prev, key ) ) {
539
	if (!equal_key(prev, key)) {
486
	PTR ( LOCATION ) loc = id_loc ( id ) ;
540
		PTR(LOCATION)loc = id_loc(id);
487
	ERROR err = ERR_dcl_type_elab_bad ( key, prev, id, loc ) ;
541
		ERROR err = ERR_dcl_type_elab_bad(key, prev, id, loc);
488
	report ( crt_loc, err ) ;
542
		report(crt_loc, err);
489
	if ( prev == btype_enum ) is_enum = 1 ;
543
		if (prev == btype_enum) {
-
 
544
			is_enum = 1;
-
 
545
		}
490
	if ( key == btype_enum ) is_enum = 1 ;
546
		if (key == btype_enum) {
-
 
547
			is_enum = 1;
491
    }
548
		}
-
 
549
	}
492
    return ( is_enum ) ;
550
	return (is_enum);
493
}
551
}
494
 
552
 
495
 
553
 
496
/*
554
/*
497
    CREATE A DUMMY CLASS TYPE
555
    CREATE A DUMMY CLASS TYPE
498
 
556
 
499
    This routine creates a dummy class or union type (as indicated by key)
557
    This routine creates a dummy class or union type (as indicated by key)
500
    representing the type 'id < args >' where id depends on a template
558
    representing the type 'id < args >' where id depends on a template
501
    parameter.
559
    parameter.
502
*/
560
*/
503
 
561
 
504
TYPE make_dummy_class
562
TYPE
505
    PROTO_N ( ( id, args, key ) )
-
 
506
    PROTO_T ( IDENTIFIER id X LIST ( TOKEN ) args X BASE_TYPE key )
563
make_dummy_class(IDENTIFIER id, LIST(TOKEN)args, BASE_TYPE key)
507
{
564
{
508
    TYPE t, s ;
565
	TYPE t, s;
509
    CLASS_TYPE ct ;
566
	CLASS_TYPE ct;
510
    CLASS_INFO ci ;
567
	CLASS_INFO ci;
511
    IDENTIFIER tid ;
568
	IDENTIFIER tid;
512
    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
569
	HASHID nm = DEREF_hashid(id_name(id));
513
    NAMESPACE ns = DEREF_nspace ( id_parent ( id ) ) ;
570
	NAMESPACE ns = DEREF_nspace(id_parent(id));
514
    decl_loc = crt_loc ;
571
	decl_loc = crt_loc;
515
    tid = make_class ( ns, nm, key, dspec_public, NULL_type, NULL_type ) ;
572
	tid = make_class(ns, nm, key, dspec_public, NULL_type, NULL_type);
516
    t = DEREF_type ( id_class_name_defn ( tid ) ) ;
573
	t = DEREF_type(id_class_name_defn(tid));
517
    ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
574
	ct = DEREF_ctype(type_compound_defn(t));
518
    ci = DEREF_cinfo ( ctype_info ( ct ) ) ;
575
	ci = DEREF_cinfo(ctype_info(ct));
519
    ci |= ( cinfo_defined | cinfo_complete ) ;
576
	ci |= (cinfo_defined | cinfo_complete);
520
    COPY_cinfo ( ctype_info ( ct ), ci ) ;
577
	COPY_cinfo(ctype_info(ct), ci);
521
    MAKE_type_token ( cv_none, id, args, s ) ;
578
	MAKE_type_token(cv_none, id, args, s);
522
    COPY_type ( ctype_form ( ct ), s ) ;
579
	COPY_type(ctype_form(ct), s);
523
    return ( t ) ;
580
	return (t);
524
}
581
}
525
 
582
 
526
 
583
 
527
/*
584
/*
528
    FIND THE CLASS ASSOCIATED WITH AN IDENTIFIER
585
    FIND THE CLASS ASSOCIATED WITH AN IDENTIFIER
529
 
586
 
530
    This routine returns the class type associated with the identifier id.
587
    This routine returns the class type associated with the identifier id.
531
    The null class type is returned if id is not a class name.
588
    The null class type is returned if id is not a class name.
532
*/
589
*/
533
 
590
 
534
CLASS_TYPE find_class
591
CLASS_TYPE
535
    PROTO_N ( ( id ) )
-
 
536
    PROTO_T ( IDENTIFIER id )
592
find_class(IDENTIFIER id)
537
{
593
{
538
    unsigned tag = TAG_id ( id ) ;
594
	unsigned tag = TAG_id(id);
539
    if ( tag == id_class_name_tag || tag == id_class_alias_tag ) {
595
	if (tag == id_class_name_tag || tag == id_class_alias_tag) {
540
	/* Simple class names */
596
		/* Simple class names */
541
	TYPE t = DEREF_type ( id_class_name_etc_defn ( id ) ) ;
597
		TYPE t = DEREF_type(id_class_name_etc_defn(id));
542
	if ( IS_type_compound ( t ) ) {
598
		if (IS_type_compound(t)) {
543
	    /* Simple classes */
599
			/* Simple classes */
544
	    CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
600
			CLASS_TYPE ct = DEREF_ctype(type_compound_defn(t));
545
	    return ( ct ) ;
601
			return (ct);
546
	} else {
602
		} else {
547
	    /* Template classes */
603
			/* Template classes */
548
	    while ( IS_type_templ ( t ) ) {
604
			while (IS_type_templ(t)) {
549
		t = DEREF_type ( type_templ_defn ( t ) ) ;
605
				t = DEREF_type(type_templ_defn(t));
550
	    }
606
			}
551
	    if ( IS_type_compound ( t ) ) {
607
			if (IS_type_compound(t)) {
552
		CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
608
				CLASS_TYPE ct = DEREF_ctype(type_compound_defn(t));
553
		if ( defining_class ( ct ) ) {
609
				if (defining_class(ct)) {
554
		    /* Only allow unqualified in definition */
610
					/* Only allow unqualified in definition */
555
		    return ( ct ) ;
611
					return (ct);
556
		}
612
				}
557
	    }
613
			}
558
	}
614
		}
559
 
615
 
560
    } else if ( tag == id_type_alias_tag ) {
616
	} else if (tag == id_type_alias_tag) {
561
	/* Check tokenised types */
617
		/* Check tokenised types */
562
	TYPE t = DEREF_type ( id_type_alias_defn ( id ) ) ;
618
		TYPE t = DEREF_type(id_type_alias_defn(id));
563
	while ( IS_type_templ ( t ) ) {
619
		while (IS_type_templ(t)) {
564
	    t = DEREF_type ( type_templ_defn ( t ) ) ;
620
			t = DEREF_type(type_templ_defn(t));
565
	}
621
		}
566
	if ( IS_type_token ( t ) ) {
622
		if (IS_type_token(t)) {
567
	    id = DEREF_id ( type_token_tok ( t ) ) ;
623
			id = DEREF_id(type_token_tok(t));
568
	    return ( find_class ( id ) ) ;
624
			return (find_class(id));
569
	}
625
		}
570
 
626
 
571
    } else if ( tag == id_token_tag && is_templ_param ( id ) ) {
627
	} else if (tag == id_token_tag && is_templ_param(id)) {
572
	/* Check for template parameters */
628
		/* Check for template parameters */
573
	int simple = 0 ;
629
		int simple = 0;
574
	BASE_TYPE key = btype_lang ;
630
		BASE_TYPE key = btype_lang;
575
	TOKEN sort = DEREF_tok ( id_token_sort ( id ) ) ;
631
		TOKEN sort = DEREF_tok(id_token_sort(id));
576
	if ( IS_tok_type ( sort ) ) {
632
		if (IS_tok_type(sort)) {
577
	    key = DEREF_btype ( tok_type_kind ( sort ) ) ;
633
			key = DEREF_btype(tok_type_kind(sort));
578
	    key &= btype_named ;
634
			key &= btype_named;
579
	    simple = 1 ;
635
			simple = 1;
580
	}
636
		}
581
	if ( key != btype_enum ) {
637
		if (key != btype_enum) {
582
	    TYPE t ;
638
			TYPE t;
583
	    if ( simple ) {
639
			if (simple) {
584
		t = DEREF_type ( tok_type_alt ( sort ) ) ;
640
				t = DEREF_type(tok_type_alt(sort));
585
	    } else {
641
			} else {
586
		t = DEREF_type ( tok_class_alt ( sort ) ) ;
642
				t = DEREF_type(tok_class_alt(sort));
587
	    }
643
			}
588
	    if ( IS_NULL_type ( t ) ) {
644
			if (IS_NULL_type(t)) {
589
		/* Create dummy class type */
645
				/* Create dummy class type */
590
		if ( key == btype_none ) key = btype_lang ;
646
				if (key == btype_none) {
-
 
647
					key = btype_lang;
-
 
648
				}
591
		t = make_dummy_class ( id, NULL_list ( TOKEN ), key ) ;
649
				t = make_dummy_class(id, NULL_list(TOKEN), key);
592
		if ( simple ) {
650
				if (simple) {
593
		    COPY_type ( tok_type_alt ( sort ), t ) ;
651
					COPY_type(tok_type_alt(sort), t);
594
		} else {
652
				} else {
595
		    COPY_type ( tok_class_alt ( sort ), t ) ;
653
					COPY_type(tok_class_alt(sort), t);
596
		}
654
				}
597
	    }
655
			}
598
	    if ( IS_type_compound ( t ) ) {
656
			if (IS_type_compound(t)) {
599
		/* Return previous dummy class type */
657
				/* Return previous dummy class type */
-
 
658
				CLASS_TYPE ct =
600
		CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
659
				    DEREF_ctype(type_compound_defn(t));
601
		return ( ct ) ;
660
				return (ct);
602
	    }
661
			}
603
	}
662
		}
604
    }
663
	}
605
    return ( NULL_ctype ) ;
664
	return (NULL_ctype);
606
}
665
}
607
 
666
 
608
 
667
 
609
/*
668
/*
610
    FIND A CLASS TYPE
669
    FIND A CLASS TYPE
611
 
670
 
612
    This routine returns the compound type associated with the class ct.
671
    This routine returns the compound type associated with the class ct.
613
*/
672
*/
614
 
673
 
615
TYPE make_class_type
674
TYPE
616
    PROTO_N ( ( ct ) )
-
 
617
    PROTO_T ( CLASS_TYPE ct )
675
make_class_type(CLASS_TYPE ct)
618
{
676
{
619
    IDENTIFIER cid = DEREF_id ( ctype_name ( ct ) ) ;
677
	IDENTIFIER cid = DEREF_id(ctype_name(ct));
620
    TYPE t = DEREF_type ( id_class_name_etc_defn ( cid ) ) ;
678
	TYPE t = DEREF_type(id_class_name_etc_defn(cid));
621
    while ( IS_type_templ ( t ) ) {
679
	while (IS_type_templ(t)) {
622
	t = DEREF_type ( type_templ_defn ( t ) ) ;
680
		t = DEREF_type(type_templ_defn(t));
623
    }
681
	}
624
    return ( t ) ;
682
	return (t);
625
}
683
}
626
 
684
 
627
 
685
 
628
/*
686
/*
629
    REDECLARE A TEMPLATE CLASS
687
    REDECLARE A TEMPLATE CLASS
630
 
688
 
631
    This routine redeclares the template class t using the template type
689
    This routine redeclares the template class t using the template type
632
    qualifiers q.
690
    qualifiers q.
633
*/
691
*/
634
 
692
 
635
static TYPE redecl_templ_class
693
static TYPE
636
    PROTO_N ( ( q, t, pid ) )
-
 
637
    PROTO_T ( TYPE q X TYPE t X IDENTIFIER *pid )
694
redecl_templ_class(TYPE q, TYPE t, IDENTIFIER *pid)
638
{
695
{
639
    TYPE s = t ;
696
	TYPE s = t;
640
    IDENTIFIER id ;
697
	IDENTIFIER id;
641
    while ( IS_type_templ ( s ) ) {
698
	while (IS_type_templ(s)) {
642
	s = DEREF_type ( type_templ_defn ( s ) ) ;
699
		s = DEREF_type(type_templ_defn(s));
643
    }
700
	}
644
    s = inject_pre_type ( q, s, 0 ) ;
701
	s = inject_pre_type(q, s, 0);
645
    s = bind_specialise ( pid, s, dspec_none, 1, 0, 0 ) ;
702
	s = bind_specialise(pid, s, dspec_none, 1, 0, 0);
646
    id = *pid ;
703
	id = *pid;
647
    if ( eq_type ( s, t ) == 1 ) {
704
	if (eq_type(s, t) == 1) {
648
	/* Consistent redeclaration */
705
		/* Consistent redeclaration */
649
	TYPE ps = s ;
706
		TYPE ps = s;
650
	TYPE pt = t ;
707
		TYPE pt = t;
651
	redecl_template ( &pt, &ps, id ) ;
708
		redecl_template(&pt, &ps, id);
652
    } else {
709
	} else {
653
	/* Inconsistent redeclaration */
710
		/* Inconsistent redeclaration */
654
	ERROR err = ERR_basic_link_incompat ( s, t ) ;
711
		ERROR err = ERR_basic_link_incompat(s, t);
655
	ERROR err2 = ERR_basic_link_decl_type ( id, id_loc ( id ) ) ;
712
		ERROR err2 = ERR_basic_link_decl_type(id, id_loc(id));
656
	err = concat_error ( err, err2 ) ;
713
		err = concat_error(err, err2);
657
	report ( crt_loc, err ) ;
714
		report(crt_loc, err);
658
    }
715
	}
659
    return ( s ) ;
716
	return (s);
660
}
717
}
661
 
718
 
662
 
719
 
663
/*
720
/*
664
    EXTRACT THE TEMPLATE QUALIFIERS OF A TYPE
721
    EXTRACT THE TEMPLATE QUALIFIERS OF A TYPE
665
 
722
 
666
    This routine does the opposite of inject_pre_type by extracting the
723
    This routine does the opposite of inject_pre_type by extracting the
667
    template qualifiers from the type t.
724
    template qualifiers from the type t.
668
*/
725
*/
669
 
726
 
670
static TYPE extract_templ_qual
727
static TYPE
671
    PROTO_N ( ( t ) )
-
 
672
    PROTO_T ( TYPE t )
728
extract_templ_qual(TYPE t)
673
{
729
{
674
    if ( !IS_NULL_type ( t ) && IS_type_templ ( t ) ) {
730
	if (!IS_NULL_type(t) && IS_type_templ(t)) {
675
	TYPE s = DEREF_type ( type_templ_defn ( t ) ) ;
731
		TYPE s = DEREF_type(type_templ_defn(t));
676
	s = extract_templ_qual ( s ) ;
732
		s = extract_templ_qual(s);
677
	COPY_type ( type_templ_defn ( t ), s ) ;
733
		COPY_type(type_templ_defn(t), s);
678
	return ( t ) ;
734
		return (t);
679
    }
735
	}
680
    return ( NULL_type ) ;
736
	return (NULL_type);
681
}
737
}
682
 
738
 
683
 
739
 
684
/*
740
/*
685
    DECLARE A CLASS OR ENUMERATION NAME
741
    DECLARE A CLASS OR ENUMERATION NAME
Line 691... Line 747...
691
    as a token.  Note that it is possible for a class or enumeration
747
    as a token.  Note that it is possible for a class or enumeration
692
    to have the same name as an object in the same scope.  In this case
748
    to have the same name as an object in the same scope.  In this case
693
    the type name is hidden by the object name.
749
    the type name is hidden by the object name.
694
*/
750
*/
695
 
751
 
696
static IDENTIFIER declare_type
752
static IDENTIFIER
697
    PROTO_N ( ( ns, nm, key, q, def, force ) )
-
 
698
    PROTO_T ( NAMESPACE ns X HASHID nm X BASE_TYPE key X TYPE q X
753
declare_type(NAMESPACE ns, HASHID nm, BASE_TYPE key, TYPE q, int def,
699
	      int def X int force )
754
	     int force)
700
{
755
{
701
    TYPE t = NULL_type ;
756
	TYPE t = NULL_type;
702
    MEMBER mem = search_member ( ns, nm, 1 ) ;
757
	MEMBER mem = search_member(ns, nm, 1);
703
    IDENTIFIER pid = DEREF_id ( member_id ( mem ) ) ;
758
	IDENTIFIER pid = DEREF_id(member_id(mem));
704
    IDENTIFIER id = type_member ( mem, 3 ) ;
759
	IDENTIFIER id = type_member(mem, 3);
705
    if ( !IS_NULL_id ( id ) ) {
760
	if (!IS_NULL_id(id)) {
706
	/* Check for reserved identifiers */
761
		/* Check for reserved identifiers */
707
	IDENTIFIER qid = id ;
762
		IDENTIFIER qid = id;
708
	DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
763
		DECL_SPEC ds = DEREF_dspec(id_storage(id));
709
	if ( ds & dspec_reserve ) {
764
		if (ds & dspec_reserve) {
710
	    PTR ( LOCATION ) loc = id_loc ( id ) ;
765
			PTR(LOCATION)loc = id_loc(id);
711
	    report ( crt_loc, ERR_basic_odr_def_type ( id, loc ) ) ;
766
			report(crt_loc, ERR_basic_odr_def_type(id, loc));
712
	    id = NULL_id ;
767
			id = NULL_id;
713
	} else {
768
		} else {
714
	    id = redecl_inherit ( id, crt_id_qualifier, in_class_defn, 0 ) ;
769
			id = redecl_inherit(id, crt_id_qualifier,
715
	}
-
 
716
 
-
 
717
	/* Check previous type declaration */
-
 
718
	if ( !IS_NULL_id ( id ) ) {
-
 
719
	    switch ( TAG_id ( id ) ) {
-
 
720
 
-
 
721
		case id_class_name_tag :
-
 
722
		case id_enum_name_tag : {
-
 
723
		    /* Previously declared as class name */
-
 
724
		    int hide_prev = check_key ( id, key ) ;
-
 
725
		    int prev_def = is_defined ( id, &t, 1 ) ;
-
 
726
		    if ( !IS_NULL_type ( q ) || IS_type_templ ( t ) ) {
-
 
727
			/* Redeclaration of template type */
-
 
728
			q = redecl_templ_class ( q, t, &id ) ;
-
 
729
		    }
-
 
730
		    if ( def && prev_def ) {
-
 
731
			/* Multiple definitions */
-
 
732
			if ( def == 2 ) {
-
 
733
			    /* This is a token */
-
 
734
			    /* EMPTY */
-
 
735
			} else if ( prev_def == 2 ) {
-
 
736
			    /* Previous was a token */
-
 
737
			    /* EMPTY */
-
 
738
			} else {
-
 
739
			    /* Neither is a token */
-
 
740
			    PTR ( LOCATION ) loc = id_loc ( id ) ;
-
 
741
			    ERROR err = ERR_basic_odr_def_type ( id, loc ) ;
-
 
742
			    report ( crt_loc, err ) ;
-
 
743
			    q = extract_templ_qual ( q ) ;
-
 
744
			    t = NULL_type ;
-
 
745
			}
-
 
746
			break ;
-
 
747
		    }
-
 
748
		    if ( hide_prev ) {
-
 
749
			/* Hide previous if only one is an enumeration */
-
 
750
			break ;
-
 
751
		    }
-
 
752
		    /* This is a genuine type redeclaration */
-
 
753
		    found_elaborate_type = 1 ;
-
 
754
		    if ( in_class_defn ) {
770
					    in_class_defn, 0);
755
			/* Adjust access specifiers */
-
 
756
			adjust_access ( id, crt_access, 0 ) ;
-
 
757
		    }
-
 
758
		    if ( def ) {
-
 
759
			/* Record location of definition */
-
 
760
			if ( !IS_NULL_type ( q ) ) {
-
 
761
			    /* Update template class */
-
 
762
			    COPY_type ( id_class_name_etc_defn ( id ), q ) ;
-
 
763
			    reset_primary_templ ( t, q ) ;
-
 
764
			}
-
 
765
			COPY_loc ( id_loc ( id ), decl_loc ) ;
-
 
766
		    }
-
 
767
		    return ( id ) ;
-
 
768
		}
771
		}
769
 
772
 
-
 
773
		/* Check previous type declaration */
-
 
774
		if (!IS_NULL_id(id)) {
-
 
775
			switch (TAG_id(id)) {
-
 
776
 
-
 
777
			case id_class_name_tag:
-
 
778
			case id_enum_name_tag: {
-
 
779
				/* Previously declared as class name */
-
 
780
				int hide_prev = check_key(id, key);
-
 
781
				int prev_def = is_defined(id, &t, 1);
-
 
782
				if (!IS_NULL_type(q) || IS_type_templ(t)) {
-
 
783
					/* Redeclaration of template type */
-
 
784
					q = redecl_templ_class(q, t, &id);
-
 
785
				}
-
 
786
				if (def && prev_def) {
-
 
787
					/* Multiple definitions */
-
 
788
					if (def == 2) {
-
 
789
						/* This is a token */
-
 
790
						/* EMPTY */
-
 
791
					} else if (prev_def == 2) {
-
 
792
						/* Previous was a token */
-
 
793
						/* EMPTY */
-
 
794
					} else {
-
 
795
						/* Neither is a token */
-
 
796
						PTR(LOCATION)loc = id_loc(id);
-
 
797
						ERROR err = ERR_basic_odr_def_type(id, loc);
-
 
798
						report(crt_loc, err);
-
 
799
						q = extract_templ_qual(q);
-
 
800
						t = NULL_type;
-
 
801
					}
-
 
802
					break;
-
 
803
				}
-
 
804
				if (hide_prev) {
-
 
805
					/* Hide previous if only one is an
-
 
806
					 * enumeration */
-
 
807
					break;
-
 
808
				}
-
 
809
				/* This is a genuine type redeclaration */
-
 
810
				found_elaborate_type = 1;
-
 
811
				if (in_class_defn) {
-
 
812
					/* Adjust access specifiers */
-
 
813
					adjust_access(id, crt_access, 0);
-
 
814
				}
-
 
815
				if (def) {
-
 
816
					/* Record location of definition */
-
 
817
					if (!IS_NULL_type(q)) {
-
 
818
						/* Update template class */
-
 
819
						COPY_type(id_class_name_etc_defn(id), q);
-
 
820
						reset_primary_templ(t, q);
-
 
821
					}
-
 
822
					COPY_loc(id_loc(id), decl_loc);
-
 
823
				}
-
 
824
				return (id);
-
 
825
			}
770
		case id_class_alias_tag :
826
			case id_class_alias_tag:
771
		case id_enum_alias_tag :
827
			case id_enum_alias_tag:
772
		case id_type_alias_tag : {
828
			case id_type_alias_tag: {
773
		    /* Previously declared as typedef name */
829
				/* Previously declared as typedef name */
774
		    PTR ( LOCATION ) loc = id_loc ( id ) ;
830
				PTR(LOCATION)loc = id_loc(id);
-
 
831
				report(crt_loc,
775
		    report ( crt_loc, ERR_basic_odr_def_type ( id, loc ) ) ;
832
				       ERR_basic_odr_def_type(id, loc));
776
		    break ;
833
				break;
777
		}
834
			}
778
 
-
 
779
		case id_nspace_name_tag :
835
			case id_nspace_name_tag:
780
		case id_nspace_alias_tag : {
836
			case id_nspace_alias_tag: {
781
		    /* Previously declared as namespace name */
837
				/* Previously declared as namespace name */
782
		    PTR ( LOCATION ) loc = id_loc ( id ) ;
838
				PTR(LOCATION)loc = id_loc(id);
783
		    report ( crt_loc, ERR_basic_odr_decl ( id, loc ) ) ;
839
				report(crt_loc, ERR_basic_odr_decl(id, loc));
784
		    break ;
840
				break;
-
 
841
			}
-
 
842
			}
-
 
843
			/* Clobber previous definition */
-
 
844
			if (EQ_id(pid, qid)) {
-
 
845
				COPY_id(member_id(mem), NULL_id);
-
 
846
				pid = NULL_id;
-
 
847
			}
-
 
848
			COPY_id(member_alt(mem), NULL_id);
-
 
849
		}
-
 
850
	}
-
 
851
 
-
 
852
	/* Check for template declarations */
-
 
853
	if (!IS_NULL_type(q)) {
-
 
854
		if (!IS_NULL_id(pid)) {
-
 
855
			/* Already declared as object */
-
 
856
			PTR(LOCATION)loc = id_loc(pid);
-
 
857
			report(crt_loc, ERR_basic_odr_diff(pid, loc));
-
 
858
		}
-
 
859
		if (crt_linkage == dspec_c) {
-
 
860
			report(crt_loc, ERR_temp_decl_linkage());
785
		}
861
		}
786
	    }
-
 
787
 
-
 
788
	    /* Clobber previous definition */
-
 
789
	    if ( EQ_id ( pid, qid ) ) {
-
 
790
		COPY_id ( member_id ( mem ), NULL_id ) ;
-
 
791
		pid = NULL_id ;
-
 
792
	    }
-
 
793
	    COPY_id ( member_alt ( mem ), NULL_id ) ;
-
 
794
	}
862
	}
795
    }
-
 
796
 
863
 
797
    /* Check for template declarations */
-
 
798
    if ( !IS_NULL_type ( q ) ) {
-
 
799
	if ( !IS_NULL_id ( pid ) ) {
-
 
800
	    /* Already declared as object */
-
 
801
	    PTR ( LOCATION ) loc = id_loc ( pid ) ;
-
 
802
	    report ( crt_loc, ERR_basic_odr_diff ( pid, loc ) ) ;
-
 
803
	}
-
 
804
	if ( crt_linkage == dspec_c ) {
-
 
805
	    report ( crt_loc, ERR_temp_decl_linkage () ) ;
-
 
806
	}
-
 
807
    }
-
 
808
 
-
 
809
    /* Construct the type declaration */
864
	/* Construct the type declaration */
810
    if ( force ) {
865
	if (force) {
811
	id = make_class ( ns, nm, key, dspec_none, q, t ) ;
866
		id = make_class(ns, nm, key, dspec_none, q, t);
812
	set_type_member ( mem, id ) ;
867
		set_type_member(mem, id);
813
	if ( IS_nspace_param ( ns ) ) {
868
		if (IS_nspace_param(ns)) {
814
	    /* Warn about function parameter scope */
869
			/* Warn about function parameter scope */
815
	    report ( crt_loc, ERR_basic_scope_pdecl_param ( id ) ) ;
870
			report(crt_loc, ERR_basic_scope_pdecl_param(id));
-
 
871
		}
816
	}
872
	}
817
    }
-
 
818
    found_elaborate_type = 0 ;
873
	found_elaborate_type = 0;
819
    return ( id ) ;
874
	return (id);
820
}
875
}
821
 
876
 
822
 
877
 
823
/*
878
/*
824
    FIND THE TYPE OF A CLASS MEMBER
879
    FIND THE TYPE OF A CLASS MEMBER
825
 
880
 
826
    This routine returns the class type corresponding to the member
881
    This routine returns the class type corresponding to the member
827
    identifier id.  The null type is returned for non-members.
882
    identifier id.  The null type is returned for non-members.
828
*/
883
*/
829
 
884
 
830
CLASS_TYPE parent_class
885
CLASS_TYPE
831
    PROTO_N ( ( id ) )
-
 
832
    PROTO_T ( IDENTIFIER id )
886
parent_class(IDENTIFIER id)
833
{
887
{
834
    if ( !IS_NULL_id ( id ) ) {
888
	if (!IS_NULL_id(id)) {
835
	NAMESPACE ns = DEREF_nspace ( id_parent ( id ) ) ;
889
		NAMESPACE ns = DEREF_nspace(id_parent(id));
836
	if ( !IS_NULL_nspace ( ns ) && IS_nspace_ctype ( ns ) ) {
890
		if (!IS_NULL_nspace(ns) && IS_nspace_ctype(ns)) {
837
	    IDENTIFIER cid = DEREF_id ( nspace_name ( ns ) ) ;
891
			IDENTIFIER cid = DEREF_id(nspace_name(ns));
838
	    TYPE t = DEREF_type ( id_class_name_etc_defn ( cid ) ) ;
892
			TYPE t = DEREF_type(id_class_name_etc_defn(cid));
839
	    while ( IS_type_templ ( t ) ) {
893
			while (IS_type_templ(t)) {
840
		t = DEREF_type ( type_templ_defn ( t ) ) ;
894
				t = DEREF_type(type_templ_defn(t));
841
	    }
895
			}
842
	    if ( IS_type_compound ( t ) ) {
896
			if (IS_type_compound(t)) {
-
 
897
				CLASS_TYPE ct =
843
		CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
898
				    DEREF_ctype(type_compound_defn(t));
844
		return ( ct ) ;
899
				return (ct);
845
	    }
900
			}
-
 
901
		}
846
	}
902
	}
847
    }
-
 
848
    return ( NULL_ctype ) ;
903
	return (NULL_ctype);
849
}
904
}
850
 
905
 
851
 
906
 
852
/*
907
/*
853
    FIND THE TYPE CORRESPONDING TO A NAMESPACE
908
    FIND THE TYPE CORRESPONDING TO A NAMESPACE
854
 
909
 
855
    This routine returns the class type corresponding to the namespace
910
    This routine returns the class type corresponding to the namespace
856
    ns.  The null type is returned if ns is not a class member namespace.
911
    ns.  The null type is returned if ns is not a class member namespace.
857
*/
912
*/
858
 
913
 
859
CLASS_TYPE namespace_class
914
CLASS_TYPE
860
    PROTO_N ( ( ns ) )
-
 
861
    PROTO_T ( NAMESPACE ns )
915
namespace_class(NAMESPACE ns)
862
{
916
{
863
    if ( IS_nspace_ctype ( ns ) ) {
917
	if (IS_nspace_ctype(ns)) {
864
	CLASS_TYPE ct ;
918
		CLASS_TYPE ct;
865
	IDENTIFIER cid = DEREF_id ( nspace_name ( ns ) ) ;
919
		IDENTIFIER cid = DEREF_id(nspace_name(ns));
866
	TYPE t = DEREF_type ( id_class_name_etc_defn ( cid ) ) ;
920
		TYPE t = DEREF_type(id_class_name_etc_defn(cid));
867
	while ( IS_type_templ ( t ) ) {
921
		while (IS_type_templ(t)) {
868
	    t = DEREF_type ( type_templ_defn ( t ) ) ;
922
			t = DEREF_type(type_templ_defn(t));
869
	}
923
		}
870
	ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
924
		ct = DEREF_ctype(type_compound_defn(t));
871
	return ( ct ) ;
925
		return (ct);
872
    }
926
	}
873
    return ( NULL_ctype ) ;
927
	return (NULL_ctype);
874
}
928
}
875
 
929
 
876
 
930
 
877
/*
931
/*
878
    CLASS STACK
932
    CLASS STACK
879
 
933
 
880
    The variable crt_class holds the class currently being defined.  The
934
    The variable crt_class holds the class currently being defined.  The
881
    stack class_stack allows for nested class definitions.
935
    stack class_stack allows for nested class definitions.
882
*/
936
*/
883
 
937
 
884
CLASS_TYPE crt_class = NULL_ctype ;
938
CLASS_TYPE crt_class = NULL_ctype;
885
static STACK ( CLASS_TYPE ) class_stack = NULL_stack ( CLASS_TYPE ) ;
939
static STACK(CLASS_TYPE) class_stack = NULL_stack(CLASS_TYPE);
886
 
940
 
887
 
941
 
888
/*
942
/*
889
    PUSH A CLASS ONTO THE CLASS STACK
943
    PUSH A CLASS ONTO THE CLASS STACK
890
 
944
 
891
    This routine sets the current class to ct pushing the previous class
945
    This routine sets the current class to ct pushing the previous class
892
    to the class stack.
946
    to the class stack.
893
*/
947
*/
894
 
948
 
895
void push_class
949
void
896
    PROTO_N ( ( ct ) )
-
 
897
    PROTO_T ( CLASS_TYPE ct )
950
push_class(CLASS_TYPE ct)
898
{
951
{
899
    PUSH_ctype ( crt_class, class_stack ) ;
952
	PUSH_ctype(crt_class, class_stack);
900
    crt_class = ct ;
953
	crt_class = ct;
901
    return ;
954
	return;
902
}
955
}
903
 
956
 
904
 
957
 
905
/*
958
/*
906
    POP A CLASS FROM THE CLASS STACK
959
    POP A CLASS FROM THE CLASS STACK
907
 
960
 
908
    This routine sets the current class from the top of the class stack.
961
    This routine sets the current class from the top of the class stack.
909
*/
962
*/
910
 
963
 
911
void pop_class
964
void
912
    PROTO_Z ()
965
pop_class(void)
913
{
966
{
914
    POP_ctype ( crt_class, class_stack ) ;
967
	POP_ctype(crt_class, class_stack);
915
    return ;
968
	return;
916
}
969
}
917
 
970
 
918
 
971
 
919
/*
972
/*
920
    IS A CLASS BEING DEFINED?
973
    IS A CLASS BEING DEFINED?
Line 922... Line 975...
922
    This routine checks whether the class ct is in the process of being
975
    This routine checks whether the class ct is in the process of being
923
    defined by checking it against the current class and the various
976
    defined by checking it against the current class and the various
924
    elements of the class stack.
977
    elements of the class stack.
925
*/
978
*/
926
 
979
 
927
int defining_class
980
int
928
    PROTO_N ( ( ct ) )
-
 
929
    PROTO_T ( CLASS_TYPE ct )
981
defining_class(CLASS_TYPE ct)
930
{
982
{
931
    NAMESPACE nt ;
983
	NAMESPACE nt;
932
    LIST ( NAMESPACE ) q ;
984
	LIST(NAMESPACE)q;
933
    LIST ( CLASS_TYPE ) p ;
985
	LIST(CLASS_TYPE)p;
934
    if ( EQ_ctype ( ct, crt_class ) ) return ( 1 ) ;
986
	if (EQ_ctype(ct, crt_class)) {
-
 
987
		return (1);
-
 
988
	}
935
    p = LIST_stack ( class_stack ) ;
989
	p = LIST_stack(class_stack);
936
    while ( !IS_NULL_list ( p ) ) {
990
	while (!IS_NULL_list(p)) {
937
	CLASS_TYPE cs = DEREF_ctype ( HEAD_list ( p ) ) ;
991
		CLASS_TYPE cs = DEREF_ctype(HEAD_list(p));
938
	if ( EQ_ctype ( cs, ct ) ) return ( 1 ) ;
992
		if (EQ_ctype(cs, ct)) {
-
 
993
			return (1);
-
 
994
		}
939
	p = TAIL_list ( p ) ;
995
		p = TAIL_list(p);
940
    }
996
	}
941
    nt = DEREF_nspace ( ctype_member ( ct ) ) ;
997
	nt = DEREF_nspace(ctype_member(ct));
942
    q = LIST_stack ( namespace_stack ) ;
998
	q = LIST_stack(namespace_stack);
943
    while ( !IS_NULL_list ( q ) ) {
999
	while (!IS_NULL_list(q)) {
944
	NAMESPACE ns = DEREF_nspace ( HEAD_list ( q ) ) ;
1000
		NAMESPACE ns = DEREF_nspace(HEAD_list(q));
945
	if ( EQ_nspace ( ns, nt ) ) return ( 1 ) ;
1001
		if (EQ_nspace(ns, nt)) {
-
 
1002
			return (1);
-
 
1003
		}
946
	q = TAIL_list ( q ) ;
1004
		q = TAIL_list(q);
947
    }
1005
	}
948
    return ( 0 ) ;
1006
	return (0);
949
}
1007
}
950
 
1008
 
951
 
1009
 
952
/*
1010
/*
953
    BEGIN A CLASS DEFINITION
1011
    BEGIN A CLASS DEFINITION
Line 957... Line 1015...
957
    of the values btype_class, btype_struct or btype_union indicating the
1015
    of the values btype_class, btype_struct or btype_union indicating the
958
    class key.  ci gives any initial class information and q gives any
1016
    class key.  ci gives any initial class information and q gives any
959
    template class qualifiers.
1017
    template class qualifiers.
960
*/
1018
*/
961
 
1019
 
962
IDENTIFIER begin_class_defn
1020
IDENTIFIER
963
    PROTO_N ( ( id, key, ci, q ) )
-
 
964
    PROTO_T ( IDENTIFIER id X BASE_TYPE key X CLASS_INFO ci X TYPE q )
1021
begin_class_defn(IDENTIFIER id, BASE_TYPE key, CLASS_INFO ci, TYPE q)
965
{
1022
{
966
    TYPE t ;
1023
	TYPE t;
967
    DECL_SPEC ds ;
1024
	DECL_SPEC ds;
968
    CLASS_TYPE ct ;
1025
	CLASS_TYPE ct;
969
    CLASS_INFO cj ;
1026
	CLASS_INFO cj;
970
    int nested = 0 ;
1027
	int nested = 0;
971
    IDENTIFIER cid = NULL_id ;
1028
	IDENTIFIER cid = NULL_id;
972
    QUALIFIER cq = crt_id_qualifier ;
1029
	QUALIFIER cq = crt_id_qualifier;
973
    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
1030
	HASHID nm = DEREF_hashid(id_name(id));
974
    NAMESPACE ns = crt_namespace ;
1031
	NAMESPACE ns = crt_namespace;
975
    begin_declarator ( id, cq, qual_namespace, 1 ) ;
1032
	begin_declarator(id, cq, qual_namespace, 1);
976
    IGNORE incr_value ( OPT_VAL_nested_class ) ;
1033
	IGNORE incr_value(OPT_VAL_nested_class);
977
 
1034
 
978
    /* Check for template specialisations */
1035
	/* Check for template specialisations */
979
    if ( is_templ_decl ( id, NULL_type ) || is_templ_spec ( q ) ) {
1036
	if (is_templ_decl(id, NULL_type) || is_templ_spec(q)) {
980
	q = bind_specialise ( &id, q, dspec_none, 1, 1, 1 ) ;
1037
		q = bind_specialise(&id, q, dspec_none, 1, 1, 1);
981
	if ( IS_NULL_id ( id ) || check_key ( id, key ) ) {
1038
		if (IS_NULL_id(id) || check_key(id, key)) {
982
	    nm = lookup_anon () ;
1039
			nm = lookup_anon();
983
	    id = DEREF_id ( hashid_id ( nm ) ) ;
1040
			id = DEREF_id(hashid_id(nm));
984
	    cq = qual_none ;
1041
			cq = qual_none;
985
	} else {
1042
		} else {
986
	    cid = id ;
1043
			cid = id;
987
	    ns = DEREF_nspace ( id_parent ( cid ) ) ;
1044
			ns = DEREF_nspace(id_parent(cid));
988
	    check_decl_nspace ( cid, ns, 1, crt_namespace ) ;
1045
			check_decl_nspace(cid, ns, 1, crt_namespace);
989
	    if ( is_defined ( cid, &t, 0 ) ) {
1046
			if (is_defined(cid, &t, 0)) {
990
		/* Redefinition of template class */
1047
				/* Redefinition of template class */
991
		PTR ( LOCATION ) loc = id_loc ( cid ) ;
1048
				PTR(LOCATION)loc = id_loc(cid);
992
		ERROR err = ERR_basic_odr_def_type ( cid, loc ) ;
1049
				ERROR err = ERR_basic_odr_def_type(cid, loc);
993
		report ( crt_loc, err ) ;
1050
				report(crt_loc, err);
994
	    }
-
 
995
	}
1051
			}
996
    }
-
 
997
 
-
 
998
    /* Check for qualified identifiers */
-
 
999
    if ( IS_NULL_id ( cid ) ) {
-
 
1000
	/* Check on class name */
-
 
1001
	int def = 1 ;
-
 
1002
	ERROR err = check_id_name ( id, CONTEXT_CLASS ) ;
-
 
1003
	if ( !IS_NULL_err ( err ) ) report ( crt_loc, err ) ;
-
 
1004
	if ( IS_nspace_ctype ( ns ) ) nested = 1 ;
-
 
1005
	if ( cq == qual_none ) {
-
 
1006
	    /* Simple class name */
-
 
1007
	    if ( option ( OPT_class_scope ) ) {
-
 
1008
		ns = crt_namespace ;
-
 
1009
		if ( IS_nspace_param ( ns ) ) {
-
 
1010
		    ns = nonclass_namespace ;
-
 
1011
		    if ( nested ) nested = 2 ;
-
 
1012
		}
1052
		}
1013
	    } else {
-
 
1014
		ns = nonclass_namespace ;
-
 
1015
		if ( nested ) nested = 2 ;
-
 
1016
	    }
-
 
1017
	} else {
-
 
1018
	    /* Definition of nested class */
-
 
1019
	    ns = DEREF_nspace ( id_parent ( id ) ) ;
-
 
1020
	    check_decl_nspace ( id, ns, 1, crt_namespace ) ;
-
 
1021
	    if ( IS_id_undef ( id ) ) nm = lookup_anon () ;
-
 
1022
	    if ( nested ) nested = 2 ;
-
 
1023
	}
1053
	}
1024
 
1054
 
-
 
1055
	/* Check for qualified identifiers */
-
 
1056
	if (IS_NULL_id(cid)) {
1025
	/* Declare the type */
1057
		/* Check on class name */
-
 
1058
		int def = 1;
-
 
1059
		ERROR err = check_id_name(id, CONTEXT_CLASS);
-
 
1060
		if (!IS_NULL_err(err)) {
-
 
1061
			report(crt_loc, err);
-
 
1062
		}
-
 
1063
		if (IS_nspace_ctype(ns)) {
-
 
1064
			nested = 1;
-
 
1065
		}
1026
	if ( ci & cinfo_token ) def = 2 ;
1066
		if (cq == qual_none) {
-
 
1067
			/* Simple class name */
-
 
1068
			if (option(OPT_class_scope)) {
-
 
1069
				ns = crt_namespace;
-
 
1070
				if (IS_nspace_param(ns)) {
-
 
1071
					ns = nonclass_namespace;
-
 
1072
					if (nested) {
-
 
1073
						nested = 2;
-
 
1074
					}
-
 
1075
				}
-
 
1076
			} else {
-
 
1077
				ns = nonclass_namespace;
-
 
1078
				if (nested) {
-
 
1079
					nested = 2;
-
 
1080
				}
-
 
1081
			}
-
 
1082
		} else {
-
 
1083
			/* Definition of nested class */
-
 
1084
			ns = DEREF_nspace(id_parent(id));
1027
	cid = declare_type ( ns, nm, key, q, def, 1 ) ;
1085
			check_decl_nspace(id, ns, 1, crt_namespace);
-
 
1086
			if (IS_id_undef(id)) {
-
 
1087
				nm = lookup_anon();
-
 
1088
			}
-
 
1089
			if (nested) {
-
 
1090
				nested = 2;
1028
    }
1091
			}
-
 
1092
		}
1029
 
1093
 
-
 
1094
		/* Declare the type */
-
 
1095
		if (ci & cinfo_token) {
-
 
1096
			def = 2;
-
 
1097
		}
-
 
1098
		cid = declare_type(ns, nm, key, q, def, 1);
-
 
1099
	}
-
 
1100
 
1030
    /* Find the class type */
1101
	/* Find the class type */
1031
    t = DEREF_type ( id_class_name_defn ( cid ) ) ;
1102
	t = DEREF_type(id_class_name_defn(cid));
1032
    while ( IS_type_templ ( t ) ) {
1103
	while (IS_type_templ(t)) {
1033
	t = DEREF_type ( type_templ_defn ( t ) ) ;
1104
		t = DEREF_type(type_templ_defn(t));
1034
    }
1105
	}
1035
    ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
1106
	ct = DEREF_ctype(type_compound_defn(t));
1036
    ns = DEREF_nspace ( ctype_member ( ct ) ) ;
1107
	ns = DEREF_nspace(ctype_member(ct));
1037
 
1108
 
1038
    /* Mark start of definition */
1109
	/* Mark start of definition */
1039
    cj = DEREF_cinfo ( ctype_info ( ct ) ) ;
1110
	cj = DEREF_cinfo(ctype_info(ct));
1040
    cj = set_class_key ( cj, key ) ;
1111
	cj = set_class_key(cj, key);
1041
    cj |= ( ci | cinfo_defined ) ;
1112
	cj |= (ci | cinfo_defined);
-
 
1113
	if (nested == 1) {
1042
    if ( nested == 1 ) cj |= cinfo_nested ;
1114
		cj |= cinfo_nested;
-
 
1115
	}
1043
    cj &= ~cinfo_complete ;
1116
	cj &= ~cinfo_complete;
1044
    COPY_cinfo ( ctype_info ( ct ), cj ) ;
1117
	COPY_cinfo(ctype_info(ct), cj);
1045
 
1118
 
1046
    /* Mark tokenised types */
1119
	/* Mark tokenised types */
1047
    ds = DEREF_dspec ( id_storage ( cid ) ) ;
1120
	ds = DEREF_dspec(id_storage(cid));
1048
    if ( cj & cinfo_token ) ds |= dspec_token ;
1121
	if (cj & cinfo_token) {
-
 
1122
		ds |= dspec_token;
-
 
1123
	}
1049
    COPY_dspec ( id_storage ( cid ), ( ds | dspec_defn ) ) ;
1124
	COPY_dspec(id_storage(cid), (ds | dspec_defn));
1050
 
1125
 
1051
#if LANGUAGE_CPP
1126
#if LANGUAGE_CPP
1052
    /* Make sure that nested classes are nested */
1127
	/* Make sure that nested classes are nested */
1053
    if ( nested == 2 ) {
1128
	if (nested == 2) {
1054
	NAMESPACE pns = crt_namespace ;
1129
		NAMESPACE pns = crt_namespace;
1055
	HASHID pnm = lookup_anon () ;
1130
		HASHID pnm = lookup_anon();
1056
	IDENTIFIER pid = declare_type ( pns, pnm, key, q, 1, 1 ) ;
1131
		IDENTIFIER pid = declare_type(pns, pnm, key, q, 1, 1);
1057
	ds = DEREF_dspec ( id_storage ( pid ) ) ;
1132
		ds = DEREF_dspec(id_storage(pid));
1058
	COPY_dspec ( id_storage ( pid ), ( ds | dspec_defn ) ) ;
1133
		COPY_dspec(id_storage(pid), (ds | dspec_defn));
1059
	t = DEREF_type ( id_class_name_defn ( cid ) ) ;
1134
		t = DEREF_type(id_class_name_defn(cid));
1060
	COPY_type ( id_class_name_defn ( pid ), t ) ;
1135
		COPY_type(id_class_name_defn(pid), t);
1061
    }
1136
	}
1062
#endif
1137
#endif
1063
 
1138
 
1064
    /* Force definition information */
1139
	/* Force definition information */
1065
    COPY_loc ( id_loc ( cid ), decl_loc ) ;
1140
	COPY_loc(id_loc(cid), decl_loc);
-
 
1141
	if (do_dump) {
1066
    if ( do_dump ) dump_declare ( cid, &decl_loc, 1 ) ;
1142
		dump_declare(cid, &decl_loc, 1);
-
 
1143
	}
1067
 
1144
 
1068
    /* Push current class and namespace */
1145
	/* Push current class and namespace */
1069
    push_namespace ( ns ) ;
1146
	push_namespace(ns);
1070
    push_class ( ct ) ;
1147
	push_class(ct);
1071
 
1148
 
1072
    /* Set up default access specifier */
1149
	/* Set up default access specifier */
1073
    ds = ( key == btype_class ? dspec_private : dspec_public ) ;
1150
	ds = (key == btype_class ? dspec_private : dspec_public);
1074
    crt_access = ds ;
1151
	crt_access = ds;
1075
    prev_access = ds ;
1152
	prev_access = ds;
1076
    return ( cid ) ;
1153
	return (cid);
1077
}
1154
}
1078
 
1155
 
1079
 
1156
 
1080
/*
1157
/*
1081
    END A CLASS DEFINITION
1158
    END A CLASS DEFINITION
1082
 
1159
 
1083
    This routine completes the definition of the class type id.
1160
    This routine completes the definition of the class type id.
1084
*/
1161
*/
1085
 
1162
 
1086
IDENTIFIER end_class_defn
1163
IDENTIFIER
1087
    PROTO_N ( ( id ) )
-
 
1088
    PROTO_T ( IDENTIFIER id )
1164
end_class_defn(IDENTIFIER id)
1089
{
1165
{
1090
    TYPE p ;
1166
	TYPE p;
1091
    CLASS_TYPE ct ;
1167
	CLASS_TYPE ct;
1092
    CLASS_INFO ci ;
1168
	CLASS_INFO ci;
1093
    LIST ( IDENTIFIER ) ft ;
1169
	LIST(IDENTIFIER)ft;
1094
    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
1170
	HASHID nm = DEREF_hashid(id_name(id));
1095
    TYPE t = DEREF_type ( id_class_name_defn ( id ) ) ;
1171
	TYPE t = DEREF_type(id_class_name_defn(id));
1096
    while ( IS_type_templ ( t ) ) {
1172
	while (IS_type_templ(t)) {
1097
	t = DEREF_type ( type_templ_defn ( t ) ) ;
1173
		t = DEREF_type(type_templ_defn(t));
1098
    }
1174
	}
1099
    ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
1175
	ct = DEREF_ctype(type_compound_defn(t));
1100
 
1176
 
1101
    /* Deal with implicitly declared constructors */
1177
	/* Deal with implicitly declared constructors */
1102
    ci = DEREF_cinfo ( ctype_info ( ct ) ) ;
1178
	ci = DEREF_cinfo(ctype_info(ct));
-
 
1179
	if (ci & cinfo_empty) {
1103
    if ( ci & cinfo_empty ) report ( crt_loc, ERR_class_none () ) ;
1180
		report(crt_loc, ERR_class_none());
-
 
1181
	}
1104
#if LANGUAGE_CPP
1182
#if LANGUAGE_CPP
1105
    ci = implicit_decl ( ct, ci, dspec_none ) ;
1183
	ci = implicit_decl(ct, ci, dspec_none);
1106
#endif
1184
#endif
1107
    if ( ci & cinfo_non_aggregate ) {
1185
	if (ci & cinfo_non_aggregate) {
1108
	/* POD classes must be aggregate classes */
1186
		/* POD classes must be aggregate classes */
1109
	ci &= ~cinfo_pod ;
1187
		ci &= ~cinfo_pod;
1110
    }
1188
	}
1111
    ci |= cinfo_complete ;
1189
	ci |= cinfo_complete;
1112
    COPY_cinfo ( ctype_info ( ct ), ci ) ;
1190
	COPY_cinfo(ctype_info(ct), ci);
1113
 
1191
 
1114
    /* Deal with any inheritance issues */
1192
	/* Deal with any inheritance issues */
1115
    inherit_class () ;
1193
	inherit_class();
1116
 
1194
 
1117
    /* Check for previous definitions */
1195
	/* Check for previous definitions */
1118
    p = DEREF_type ( ctype_prev ( ct ) ) ;
1196
	p = DEREF_type(ctype_prev(ct));
1119
    if ( !IS_NULL_type ( p ) ) {
1197
	if (!IS_NULL_type(p)) {
1120
	if ( ci & cinfo_token ) {
1198
		if (ci & cinfo_token) {
1121
	    /* Make p the tokenised type */
1199
			/* Make p the tokenised type */
1122
	    TYPE q = p ;
1200
			TYPE q = p;
1123
	    p = t ;
1201
			p = t;
1124
	    t = q ;
1202
			t = q;
1125
	}
1203
		}
1126
	force_tokdef++ ;
1204
		force_tokdef++;
1127
	IGNORE unify_type ( p, t, cv_none, 0 ) ;
1205
		IGNORE unify_type(p, t, cv_none, 0);
1128
	force_tokdef-- ;
1206
		force_tokdef--;
1129
    }
1207
	}
1130
 
1208
 
1131
    /* Compile any inline functions */
1209
	/* Compile any inline functions */
-
 
1210
	if (is_exported(id)) {
1132
    if ( is_exported ( id ) ) export_template ( id, 1 ) ;
1211
		export_template(id, 1);
-
 
1212
	}
1133
    ft = DEREF_list ( ctype_pals ( ct ) ) ;
1213
	ft = DEREF_list(ctype_pals(ct));
1134
    if ( !IS_NULL_list ( ft ) ) {
1214
	if (!IS_NULL_list(ft)) {
1135
	unsigned nf ;
1215
		unsigned nf;
1136
	ft = REVERSE_list ( ft ) ;
1216
		ft = REVERSE_list(ft);
1137
	COPY_list ( ctype_pals ( ct ), ft ) ;
1217
		COPY_list(ctype_pals(ct), ft);
1138
	nf = LENGTH_list ( ft ) ;
1218
		nf = LENGTH_list(ft);
1139
	IGNORE check_value ( OPT_VAL_friends, ( ulong ) nf ) ;
1219
		IGNORE check_value(OPT_VAL_friends,(ulong)nf);
1140
    }
1220
	}
1141
    ft = DEREF_list ( ctype_nest ( ct ) ) ;
1221
	ft = DEREF_list(ctype_nest(ct));
1142
    if ( !IS_NULL_list ( ft ) ) {
1222
	if (!IS_NULL_list(ft)) {
1143
	ft = REVERSE_list ( ft ) ;
1223
		ft = REVERSE_list(ft);
1144
	COPY_list ( ctype_nest ( ct ), ft ) ;
1224
		COPY_list(ctype_nest(ct), ft);
1145
	if ( !( ci & cinfo_nested ) || in_class_defn == 1 ) {
1225
		if (!(ci & cinfo_nested) || in_class_defn == 1) {
1146
	    rescan_functions () ;
1226
			rescan_functions();
1147
	}
1227
		}
1148
    }
-
 
1149
 
1228
	}
1150
    /* Pop current class and namespace */
-
 
1151
    if ( do_dump ) dump_undefine ( id, &crt_loc, 0 ) ;
-
 
1152
    IGNORE pop_namespace () ;
-
 
1153
    pop_class () ;
-
 
1154
    decr_value ( OPT_VAL_nested_class ) ;
-
 
1155
    end_declarator ( id, 1 ) ;
-
 
1156
 
1229
 
-
 
1230
	/* Pop current class and namespace */
-
 
1231
	if (do_dump) {
-
 
1232
		dump_undefine(id, &crt_loc, 0);
-
 
1233
	}
-
 
1234
	IGNORE pop_namespace();
-
 
1235
	pop_class();
-
 
1236
	decr_value(OPT_VAL_nested_class);
-
 
1237
	end_declarator(id, 1);
-
 
1238
 
1157
    /* Set type declaration flag */
1239
	/* Set type declaration flag */
1158
    if ( IS_hashid_anon ( nm ) ) {
1240
	if (IS_hashid_anon(nm)) {
1159
	have_type_declaration = TYPE_DECL_ANON ;
1241
		have_type_declaration = TYPE_DECL_ANON;
1160
    } else {
1242
	} else {
1161
	have_type_declaration = TYPE_DECL_NORMAL ;
1243
		have_type_declaration = TYPE_DECL_NORMAL;
1162
    }
1244
	}
1163
    return ( id ) ;
1245
	return (id);
1164
}
1246
}
1165
 
1247
 
1166
 
1248
 
1167
/*
1249
/*
1168
    CHECK CLASS INFORMATION
1250
    CHECK CLASS INFORMATION
Line 1172... Line 1254...
1172
    with class information ci.  In a class definition trivial_constr,
1254
    with class information ci.  In a class definition trivial_constr,
1173
    for example, is true if all the base classes and members have
1255
    for example, is true if all the base classes and members have
1174
    trivial constructors.  At the end of the definition, when the
1256
    trivial constructors.  At the end of the definition, when the
1175
    implicit constructors are declared, it is used to indicate that the
1257
    implicit constructors are declared, it is used to indicate that the
1176
    class itself has a trivial constructor.
1258
    class itself has a trivial constructor.
1177
*/
1259
*/
1178
 
1260
 
1179
CLASS_INFO check_class_info
1261
CLASS_INFO
1180
    PROTO_N ( ( ci, cj, base, acc ) )
-
 
1181
    PROTO_T ( CLASS_INFO ci X CLASS_INFO cj X int base X DECL_SPEC acc )
1262
check_class_info(CLASS_INFO ci, CLASS_INFO cj, int base, DECL_SPEC acc)
1182
{
1263
{
1183
    if ( !( cj & cinfo_pod ) ) ci &= ~cinfo_pod ;
1264
	if (!(cj & cinfo_pod)) {
-
 
1265
		ci &= ~cinfo_pod;
-
 
1266
	}
1184
    if ( !( cj & cinfo_trivial_constr ) ) ci &= ~cinfo_trivial_constr ;
1267
	if (!(cj & cinfo_trivial_constr)) {
-
 
1268
		ci &= ~cinfo_trivial_constr;
-
 
1269
	}
1185
    if ( !( cj & cinfo_trivial_copy ) ) ci &= ~cinfo_trivial_copy ;
1270
	if (!(cj & cinfo_trivial_copy)) {
-
 
1271
		ci &= ~cinfo_trivial_copy;
-
 
1272
	}
1186
    if ( !( cj & cinfo_trivial_assign ) ) ci &= ~cinfo_trivial_assign ;
1273
	if (!(cj & cinfo_trivial_assign)) {
-
 
1274
		ci &= ~cinfo_trivial_assign;
-
 
1275
	}
1187
    if ( !( cj & cinfo_trivial_destr ) ) ci &= ~cinfo_trivial_destr ;
1276
	if (!(cj & cinfo_trivial_destr)) {
-
 
1277
		ci &= ~cinfo_trivial_destr;
-
 
1278
	}
1188
    if ( !( cj & cinfo_const_copy ) ) ci &= ~cinfo_const_copy ;
1279
	if (!(cj & cinfo_const_copy)) {
-
 
1280
		ci &= ~cinfo_const_copy;
-
 
1281
	}
1189
    if ( !( cj & cinfo_const_assign ) ) ci &= ~cinfo_const_assign ;
1282
	if (!(cj & cinfo_const_assign)) {
-
 
1283
		ci &= ~cinfo_const_assign;
-
 
1284
	}
1190
    if ( cj & cinfo_recursive ) ci |= cinfo_recursive ;
1285
	if (cj & cinfo_recursive) {
-
 
1286
		ci |= cinfo_recursive;
-
 
1287
	}
1191
    if ( cj & cinfo_params ) ci |= cinfo_params ;
1288
	if (cj & cinfo_params) {
-
 
1289
		ci |= cinfo_params;
-
 
1290
	}
1192
    if ( cj & cinfo_const ) ci |= cinfo_const ;
1291
	if (cj & cinfo_const) {
-
 
1292
		ci |= cinfo_const;
-
 
1293
	}
1193
    if ( base ) {
1294
	if (base) {
1194
	/* Base class checks */
1295
		/* Base class checks */
1195
	if ( cj & cinfo_multiple_base ) ci |= cinfo_multiple_base ;
1296
		if (cj & cinfo_multiple_base) {
-
 
1297
			ci |= cinfo_multiple_base;
-
 
1298
		}
1196
	if ( cj & cinfo_templ_base ) ci |= cinfo_templ_base ;
1299
		if (cj & cinfo_templ_base) {
-
 
1300
			ci |= cinfo_templ_base;
-
 
1301
		}
1197
	if ( cj & cinfo_function ) ci |= cinfo_function ;
1302
		if (cj & cinfo_function) {
-
 
1303
			ci |= cinfo_function;
-
 
1304
		}
1198
	if ( cj & cinfo_static ) ci |= cinfo_static ;
1305
		if (cj & cinfo_static) {
-
 
1306
			ci |= cinfo_static;
-
 
1307
		}
1199
	ci &= ~cinfo_empty ;
1308
		ci &= ~cinfo_empty;
1200
	ci |= cinfo_base ;
1309
		ci |= cinfo_base;
1201
	UNUSED ( acc ) ;
1310
		UNUSED(acc);
1202
    }
1311
	}
1203
    return ( ci ) ;
1312
	return (ci);
1204
}
1313
}
1205
 
1314
 
1206
 
1315
 
1207
/*
1316
/*
1208
    CHECK FOR TRIVIAL CLASSES
1317
    CHECK FOR TRIVIAL CLASSES
1209
 
1318
 
1210
    This routine checks whether the class ct has trivial default
1319
    This routine checks whether the class ct has trivial default
1211
    constructors, destructors, copy constructors and copy assignment
1320
    constructors, destructors, copy constructors and copy assignment
1212
    operators.
1321
    operators.
1213
*/
1322
*/
1214
 
1323
 
1215
ERROR check_trivial_class
1324
ERROR
1216
    PROTO_N ( ( ct ) )
-
 
1217
    PROTO_T ( CLASS_TYPE ct )
1325
check_trivial_class(CLASS_TYPE ct)
1218
{
1326
{
1219
    ERROR err = NULL_err ;
1327
	ERROR err = NULL_err;
1220
    CLASS_INFO ci = DEREF_cinfo ( ctype_info ( ct ) ) ;
1328
	CLASS_INFO ci = DEREF_cinfo(ctype_info(ct));
1221
    CLASS_INFO cj = ( ci & cinfo_trivial ) ;
1329
	CLASS_INFO cj = (ci & cinfo_trivial);
1222
    if ( cj != cinfo_trivial ) {
1330
	if (cj != cinfo_trivial) {
1223
	if ( !( cj & cinfo_trivial_constr ) ) {
1331
		if (!(cj & cinfo_trivial_constr)) {
1224
	    err = ERR_class_ctor_nontriv ( ct ) ;
1332
			err = ERR_class_ctor_nontriv(ct);
1225
	} else if ( !( cj & cinfo_trivial_destr ) ) {
1333
		} else if (!(cj & cinfo_trivial_destr)) {
1226
	    err = ERR_class_dtor_nontriv ( ct ) ;
1334
			err = ERR_class_dtor_nontriv(ct);
1227
	} else if ( !( cj & cinfo_trivial_copy ) ) {
1335
		} else if (!(cj & cinfo_trivial_copy)) {
1228
	    err = ERR_class_copy_nontriv_constr ( ct ) ;
1336
			err = ERR_class_copy_nontriv_constr(ct);
1229
	} else if ( !( cj & cinfo_trivial_assign ) ) {
1337
		} else if (!(cj & cinfo_trivial_assign)) {
1230
	    err = ERR_class_copy_nontriv_assign ( ct ) ;
1338
			err = ERR_class_copy_nontriv_assign(ct);
-
 
1339
		}
1231
	}
1340
	}
1232
    }
-
 
1233
    return ( err ) ;
1341
	return (err);
1234
}
1342
}
1235
 
1343
 
1236
 
1344
 
1237
/*
1345
/*
1238
    CHECK A CLASS MEMBER TYPE
1346
    CHECK A CLASS MEMBER TYPE
Line 1241... Line 1349...
1241
    class ct.  This is recorded in the effect on the class information ci.
1349
    class ct.  This is recorded in the effect on the class information ci.
1242
    The criterion for spotting recursively defined classes is that it
1350
    The criterion for spotting recursively defined classes is that it
1243
    contains a pointer to an incomplete type (or a base class or member
1351
    contains a pointer to an incomplete type (or a base class or member
1244
    of such a type).  This certainly contains all recursive types, and
1352
    of such a type).  This certainly contains all recursive types, and
1245
    is about the best that can be done without any deep analysis.
1353
    is about the best that can be done without any deep analysis.
1246
*/
1354
*/
1247
 
1355
 
1248
CLASS_INFO check_member_type
1356
CLASS_INFO
1249
    PROTO_N ( ( ct, ci, t, ptr ) )
-
 
1250
    PROTO_T ( CLASS_TYPE ct X CLASS_INFO ci X TYPE t X int ptr )
1357
check_member_type(CLASS_TYPE ct, CLASS_INFO ci, TYPE t, int ptr)
1251
{
1358
{
1252
    if ( !ptr ) {
1359
	if (!ptr) {
1253
	/* Check for const members */
1360
		/* Check for const members */
1254
	CV_SPEC cv = DEREF_cv ( type_qual ( t ) ) ;
1361
		CV_SPEC cv = DEREF_cv(type_qual(t));
1255
	if ( cv & cv_const ) ci |= cinfo_const ;
1362
		if (cv & cv_const) {
-
 
1363
			ci |= cinfo_const;
1256
    }
1364
		}
-
 
1365
	}
1257
    switch ( TAG_type ( t ) ) {
1366
	switch (TAG_type(t)) {
1258
	case type_compound_tag : {
1367
	case type_compound_tag: {
1259
	    /* Compound types */
1368
		/* Compound types */
1260
	    CLASS_TYPE cs = DEREF_ctype ( type_compound_defn ( t ) ) ;
1369
		CLASS_TYPE cs = DEREF_ctype(type_compound_defn(t));
1261
	    CLASS_INFO cj = DEREF_cinfo ( ctype_info ( cs ) ) ;
1370
		CLASS_INFO cj = DEREF_cinfo(ctype_info(cs));
1262
	    if ( !( cj & cinfo_complete ) ) {
1371
		if (!(cj & cinfo_complete)) {
1263
		/* Could be a recursive type ... */
1372
			/* Could be a recursive type ... */
1264
		ci |= cinfo_recursive ;
1373
			ci |= cinfo_recursive;
1265
	    }
1374
		}
1266
	    if ( !ptr ) {
1375
		if (!ptr) {
1267
		if ( ci & cinfo_union ) {
1376
			if (ci & cinfo_union) {
1268
		    /* Union component must be trivial */
1377
				/* Union component must be trivial */
1269
		    ERROR err = check_trivial_class ( cs ) ;
1378
				ERROR err = check_trivial_class(cs);
1270
		    if ( !IS_NULL_err ( err ) ) {
1379
				if (!IS_NULL_err(err)) {
1271
			ERROR err2 = ERR_class_union_mem ( ct, t ) ;
1380
					ERROR err2 = ERR_class_union_mem(ct, t);
1272
			err = concat_error ( err, err2 ) ;
1381
					err = concat_error(err, err2);
1273
			report ( crt_loc, err ) ;
1382
					report(crt_loc, err);
1274
		    }
1383
				}
1275
		}
1384
			}
1276
		ci = check_class_info ( ci, cj, 0, dspec_none ) ;
1385
			ci = check_class_info(ci, cj, 0, dspec_none);
1277
	    }
1386
		}
1278
	    break ;
1387
		break;
1279
	}
1388
	}
1280
	case type_ptr_tag : {
1389
	case type_ptr_tag: {
1281
	    /* Pointer types */
1390
		/* Pointer types */
1282
	    if ( !ptr ) {
1391
		if (!ptr) {
1283
		TYPE s = DEREF_type ( type_ptr_sub ( t ) ) ;
1392
			TYPE s = DEREF_type(type_ptr_sub(t));
1284
		ci = check_member_type ( ct, ci, s, 1 ) ;
1393
			ci = check_member_type(ct, ci, s, 1);
1285
	    }
1394
		}
1286
	    break ;
1395
		break;
1287
	}
1396
	}
1288
	case type_ref_tag : {
1397
	case type_ref_tag: {
1289
	    /* Reference types */
1398
		/* Reference types */
1290
	    if ( !ptr ) {
1399
		if (!ptr) {
1291
		TYPE s = DEREF_type ( type_ref_sub ( t ) ) ;
1400
			TYPE s = DEREF_type(type_ref_sub(t));
1292
		if ( ci & cinfo_union ) {
1401
			if (ci & cinfo_union) {
1293
		    /* Unions can't have reference members */
1402
				/* Unions can't have reference members */
1294
		    report ( crt_loc, ERR_class_union_ref ( ct, t ) ) ;
1403
				report(crt_loc, ERR_class_union_ref(ct, t));
-
 
1404
			}
-
 
1405
			ci = check_member_type(ct, ci, s, 1);
-
 
1406
			ci &= ~cinfo_pod;
-
 
1407
		}
-
 
1408
		break;
-
 
1409
	}
-
 
1410
	case type_ptr_mem_tag: {
-
 
1411
		/* Pointer to member types */
-
 
1412
		if (!ptr) {
-
 
1413
			ci &= ~cinfo_pod;
1295
		}
1414
		}
-
 
1415
		break;
-
 
1416
	}
1296
		ci = check_member_type ( ct, ci, s, 1 ) ;
1417
	case type_array_tag: {
1297
		ci &= ~cinfo_pod ;
1418
		/* Array types */
-
 
1419
		TYPE s = DEREF_type(type_array_sub(t));
1298
	    }
1420
		ci = check_member_type(ct, ci, s, ptr);
1299
	    break ;
1421
		break;
1300
	}
1422
	}
1301
	case type_ptr_mem_tag : {
-
 
1302
	    /* Pointer to member types */
-
 
1303
	    if ( !ptr ) ci &= ~cinfo_pod ;
-
 
1304
	    break ;
-
 
1305
	}
1423
	}
1306
	case type_array_tag : {
1424
	if (is_templ_depend(t)) {
1307
	    /* Array types */
1425
		ci |= cinfo_params;
1308
	    TYPE s = DEREF_type ( type_array_sub ( t ) ) ;
-
 
1309
	    ci = check_member_type ( ct, ci, s, ptr ) ;
-
 
1310
	    break ;
-
 
1311
	}
1426
	}
1312
    }
-
 
1313
    if ( is_templ_depend ( t ) ) ci |= cinfo_params ;
-
 
1314
    return ( ci ) ;
1427
	return (ci);
1315
}
1428
}
1316
 
1429
 
1317
 
1430
 
1318
/*
1431
/*
1319
    REPORT INFORMATION ABOUT A CLASS
1432
    REPORT INFORMATION ABOUT A CLASS
1320
 
1433
 
1321
    This routine reports the information about the class ct indicated by
1434
    This routine reports the information about the class ct indicated by
1322
    the class information mask cm.  It returns an error message summarising
1435
    the class information mask cm.  It returns an error message summarising
1323
    those properties which hold for ct.  At most n properties are reported.
1436
    those properties which hold for ct.  At most n properties are reported.
1324
*/
1437
*/
1325
 
1438
 
1326
ERROR class_info
1439
ERROR
1327
    PROTO_N ( ( ct, cm, n ) )
-
 
1328
    PROTO_T ( CLASS_TYPE ct X CLASS_INFO cm X int n )
1440
class_info(CLASS_TYPE ct, CLASS_INFO cm, int n)
1329
{
1441
{
1330
    /* Find class information */
1442
	/* Find class information */
1331
    ERROR err = NULL_err ;
1443
	ERROR err = NULL_err;
1332
    CLASS_INFO ci = DEREF_cinfo ( ctype_info ( ct ) ) ;
1444
	CLASS_INFO ci = DEREF_cinfo(ctype_info(ct));
1333
    ci &= cm ;
1445
	ci &= cm;
1334
    if ( ci == cinfo_none ) return ( err ) ;
1446
	if (ci == cinfo_none) {
-
 
1447
		return (err);
-
 
1448
	}
1335
 
1449
 
1336
    /* Check for tokenised types */
1450
	/* Check for tokenised types */
1337
    if ( ci & cinfo_token ) {
1451
	if (ci & cinfo_token) {
1338
	IDENTIFIER id = DEREF_id ( ctype_name ( ct ) ) ;
1452
		IDENTIFIER id = DEREF_id(ctype_name(ct));
1339
	err = concat_error ( err, ERR_token_info ( id ) ) ;
1453
		err = concat_error(err, ERR_token_info(id));
1340
	if ( --n == 0 ) return ( err ) ;
1454
		if (--n == 0) {
-
 
1455
			return (err);
1341
    }
1456
		}
-
 
1457
	}
1342
 
1458
 
1343
    /* Check for user-defined constructors */
1459
	/* Check for user-defined constructors */
1344
    if ( ci & cinfo_usr_constr ) {
1460
	if (ci & cinfo_usr_constr) {
1345
	err = concat_error ( err, ERR_class_ctor_user ( ct ) ) ;
1461
		err = concat_error(err, ERR_class_ctor_user(ct));
1346
	if ( --n == 0 ) return ( err ) ;
1462
		if (--n == 0) {
-
 
1463
			return (err);
1347
    }
1464
		}
-
 
1465
	}
1348
 
1466
 
1349
    /* Check for ambiguous base classes */
1467
	/* Check for ambiguous base classes */
1350
    if ( ci & cinfo_ambiguous ) {
1468
	if (ci & cinfo_ambiguous) {
1351
	GRAPH gr = DEREF_graph ( ctype_base ( ct ) ) ;
1469
		GRAPH gr = DEREF_graph(ctype_base(ct));
1352
	gr = find_ambig_base ( gr ) ;
1470
		gr = find_ambig_base(gr);
1353
	if ( !IS_NULL_graph ( gr ) ) {
1471
		if (!IS_NULL_graph(gr)) {
1354
	    /* Ambiguous base class found */
1472
			/* Ambiguous base class found */
1355
	    CLASS_TYPE cs = DEREF_ctype ( graph_head ( gr ) ) ;
1473
			CLASS_TYPE cs = DEREF_ctype(graph_head(gr));
1356
	    ERROR err2 = ERR_class_member_lookup_ambig ( cs, ct ) ;
1474
			ERROR err2 = ERR_class_member_lookup_ambig(cs, ct);
1357
	    err = concat_error ( err, err2 ) ;
1475
			err = concat_error(err, err2);
1358
	    if ( --n == 0 ) return ( err ) ;
1476
			if (--n == 0) {
-
 
1477
				return (err);
-
 
1478
			}
1359
	}
1479
		}
1360
    }
1480
	}
1361
 
1481
 
1362
    /* Check for base classes */
1482
	/* Check for base classes */
1363
    if ( ci & cinfo_base ) {
1483
	if (ci & cinfo_base) {
1364
	CLASS_TYPE cs ;
1484
		CLASS_TYPE cs;
1365
	GRAPH gr = DEREF_graph ( ctype_base ( ct ) ) ;
1485
		GRAPH gr = DEREF_graph(ctype_base(ct));
1366
	LIST ( GRAPH ) tails = DEREF_list ( graph_tails ( gr ) ) ;
1486
		LIST(GRAPH)tails = DEREF_list(graph_tails(gr));
1367
	gr = DEREF_graph ( HEAD_list ( tails ) ) ;
1487
		gr = DEREF_graph(HEAD_list(tails));
1368
	cs = DEREF_ctype ( graph_head ( gr ) ) ;
1488
		cs = DEREF_ctype(graph_head(gr));
1369
	err = concat_error ( err, ERR_class_derived_base ( ct, cs ) ) ;
1489
		err = concat_error(err, ERR_class_derived_base(ct, cs));
1370
	if ( --n == 0 ) return ( err ) ;
1490
		if (--n == 0) {
-
 
1491
			return (err);
1371
    }
1492
		}
-
 
1493
	}
1372
 
1494
 
1373
    /* Check for private or protected members */
1495
	/* Check for private or protected members */
1374
    if ( ci & cinfo_private ) {
1496
	if (ci & cinfo_private) {
1375
	err = concat_error ( err, ERR_class_access_spec_priv ( ct ) ) ;
1497
		err = concat_error(err, ERR_class_access_spec_priv(ct));
1376
	if ( --n == 0 ) return ( err ) ;
1498
		if (--n == 0) {
-
 
1499
			return (err);
1377
    }
1500
		}
-
 
1501
	}
1378
 
1502
 
1379
    /* Check for abstract classes */
1503
	/* Check for abstract classes */
1380
    if ( ci & cinfo_abstract ) {
1504
	if (ci & cinfo_abstract) {
1381
	IDENTIFIER id = find_pure_function ( ct ) ;
1505
		IDENTIFIER id = find_pure_function(ct);
1382
	err = concat_error ( err, ERR_class_abstract_pure ( id ) ) ;
1506
		err = concat_error(err, ERR_class_abstract_pure(id));
1383
	err = concat_error ( err, ERR_class_abstract_class ( ct ) ) ;
1507
		err = concat_error(err, ERR_class_abstract_class(ct));
1384
	if ( --n == 0 ) return ( err ) ;
1508
		if (--n == 0) {
-
 
1509
			return (err);
1385
    }
1510
		}
-
 
1511
	}
1386
 
1512
 
1387
    /* Check for polymorphic classes */
1513
	/* Check for polymorphic classes */
1388
    if ( ci & cinfo_polymorphic ) {
1514
	if (ci & cinfo_polymorphic) {
1389
	err = concat_error ( err, ERR_class_virtual_poly ( ct ) ) ;
1515
		err = concat_error(err, ERR_class_virtual_poly(ct));
1390
	if ( --n == 0 ) return ( err ) ;
1516
		if (--n == 0) {
-
 
1517
			return (err);
1391
    }
1518
		}
-
 
1519
	}
1392
 
1520
 
1393
    /* Return the resultant error */
1521
	/* Return the resultant error */
1394
    UNUSED ( n ) ;
1522
	UNUSED(n);
1395
    return ( err ) ;
1523
	return (err);
1396
}
1524
}
1397
 
1525
 
1398
 
1526
 
1399
/*
1527
/*
1400
    DOES A CLASS TYPE HAVE A NON-TRIVIAL MEMBER?
1528
    DOES A CLASS TYPE HAVE A NON-TRIVIAL MEMBER?
1401
 
1529
 
1402
    This routine checks whether the class type ct has a non-trivial member,
1530
    This routine checks whether the class type ct has a non-trivial member,
1403
    that is to say not all its base classes and members are empty classes.
1531
    that is to say not all its base classes and members are empty classes.
1404
*/
1532
*/
1405
 
1533
 
1406
static int is_empty_ctype
1534
static int
1407
    PROTO_N ( ( ct ) )
-
 
1408
    PROTO_T ( CLASS_TYPE ct )
1535
is_empty_ctype(CLASS_TYPE ct)
1409
{
1536
{
1410
    GRAPH gr = DEREF_graph ( ctype_base ( ct ) ) ;
1537
	GRAPH gr = DEREF_graph(ctype_base(ct));
1411
    LIST ( GRAPH ) br = DEREF_list ( graph_tails ( gr ) ) ;
1538
	LIST(GRAPH)br = DEREF_list(graph_tails(gr));
1412
    NAMESPACE ns = DEREF_nspace ( ctype_member ( ct ) ) ;
1539
	NAMESPACE ns = DEREF_nspace(ctype_member(ct));
1413
    MEMBER mem = DEREF_member ( nspace_ctype_first ( ns ) ) ;
1540
	MEMBER mem = DEREF_member(nspace_ctype_first(ns));
1414
    mem = next_data_member ( mem, 2 ) ;
1541
	mem = next_data_member(mem, 2);
1415
    if ( !IS_NULL_member ( mem ) ) return ( 0 ) ;
1542
	if (!IS_NULL_member(mem)) {
-
 
1543
		return (0);
-
 
1544
	}
1416
    while ( !IS_NULL_list ( br ) ) {
1545
	while (!IS_NULL_list(br)) {
1417
	GRAPH gs = DEREF_graph ( HEAD_list ( br ) ) ;
1546
		GRAPH gs = DEREF_graph(HEAD_list(br));
1418
	CLASS_TYPE cs = DEREF_ctype ( graph_head ( gs ) ) ;
1547
		CLASS_TYPE cs = DEREF_ctype(graph_head(gs));
1419
	if ( !is_empty_ctype ( cs ) ) return ( 0 ) ;
1548
		if (!is_empty_ctype(cs)) {
-
 
1549
			return (0);
-
 
1550
		}
1420
	br = TAIL_list ( br ) ;
1551
		br = TAIL_list(br);
1421
    }
1552
	}
1422
    return ( 1 ) ;
1553
	return (1);
1423
}
1554
}
1424
 
1555
 
1425
 
1556
 
1426
/*
1557
/*
1427
    IS A TYPE A TRIVIAL CLASS TYPE?
1558
    IS A TYPE A TRIVIAL CLASS TYPE?
1428
 
1559
 
1429
    This routine checks whether the type t is an empty class type or an
1560
    This routine checks whether the type t is an empty class type or an
1430
    array of such.
1561
    array of such.
1431
*/
1562
*/
1432
 
1563
 
1433
int is_empty_class
1564
int
1434
    PROTO_N ( ( t ) )
-
 
1435
    PROTO_T ( TYPE t )
1565
is_empty_class(TYPE t)
1436
{
1566
{
1437
    while ( !IS_NULL_type ( t ) ) {
1567
	while (!IS_NULL_type(t)) {
1438
	switch ( TAG_type ( t ) ) {
1568
		switch (TAG_type(t)) {
1439
	    case type_compound_tag : {
1569
		case type_compound_tag: {
1440
		CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
1570
			CLASS_TYPE ct = DEREF_ctype(type_compound_defn(t));
1441
		return ( is_empty_ctype ( ct ) ) ;
1571
			return (is_empty_ctype(ct));
1442
	    }
1572
		}
1443
	    case type_array_tag : {
1573
		case type_array_tag: {
1444
		t = DEREF_type ( type_array_sub ( t ) ) ;
1574
			t = DEREF_type(type_array_sub(t));
1445
		break ;
1575
			break;
1446
	    }
1576
		}
1447
	    case type_templ_tag : {
1577
		case type_templ_tag: {
1448
		t = DEREF_type ( type_templ_defn ( t ) ) ;
1578
			t = DEREF_type(type_templ_defn(t));
1449
		break ;
1579
			break;
1450
	    }
1580
		}
1451
	    default : {
1581
		default:
1452
		return ( 0 ) ;
1582
			return (0);
1453
	    }
1583
		}
1454
	}
1584
	}
1455
    }
-
 
1456
    return ( 0 ) ;
1585
	return (0);
1457
}
1586
}
1458
 
1587
 
1459
 
1588
 
1460
/*
1589
/*
1461
    BEGIN AN ENUMERATION DEFINITION
1590
    BEGIN AN ENUMERATION DEFINITION
Line 1463... Line 1592...
1463
    This routine begins the definition on an enumeration type.  The
1592
    This routine begins the definition on an enumeration type.  The
1464
    enumeration name is given by id and q gives any template type qualifiers.
1593
    enumeration name is given by id and q gives any template type qualifiers.
1465
    Note that an enumeration definition does not define a scope.
1594
    Note that an enumeration definition does not define a scope.
1466
*/
1595
*/
1467
 
1596
 
1468
IDENTIFIER begin_enum_defn
1597
IDENTIFIER
1469
    PROTO_N ( ( id, q ) )
-
 
1470
    PROTO_T ( IDENTIFIER id X TYPE q )
1598
begin_enum_defn(IDENTIFIER id, TYPE q)
1471
{
1599
{
1472
    TYPE t ;
1600
	TYPE t;
1473
    ERROR err ;
1601
	ERROR err;
1474
    DECL_SPEC ds ;
1602
	DECL_SPEC ds;
1475
    NAMESPACE ns ;
1603
	NAMESPACE ns;
1476
    ENUM_TYPE et ;
1604
	ENUM_TYPE et;
1477
    CLASS_INFO ei ;
1605
	CLASS_INFO ei;
1478
    IDENTIFIER eid = id ;
1606
	IDENTIFIER eid = id;
1479
    QUALIFIER cq = crt_id_qualifier ;
1607
	QUALIFIER cq = crt_id_qualifier;
1480
    HASHID nm = DEREF_hashid ( id_name ( eid ) ) ;
1608
	HASHID nm = DEREF_hashid(id_name(eid));
1481
    begin_declarator ( id, cq, qual_namespace, 1 ) ;
1609
	begin_declarator(id, cq, qual_namespace, 1);
1482
 
1610
 
1483
    /* Check on enumeration name */
1611
	/* Check on enumeration name */
1484
    if ( is_templ_decl ( id, NULL_type ) || is_templ_spec ( q ) ) {
1612
	if (is_templ_decl(id, NULL_type) || is_templ_spec(q)) {
1485
	/* Shouldn't have a template application */
1613
		/* Shouldn't have a template application */
1486
	q = bind_specialise ( &eid, q, dspec_none, 1, 1, 1 ) ;
1614
		q = bind_specialise(&eid, q, dspec_none, 1, 1, 1);
1487
	if ( IS_NULL_id ( eid ) || check_key ( eid, btype_enum ) ) {
1615
		if (IS_NULL_id(eid) || check_key(eid, btype_enum)) {
1488
	    nm = lookup_anon () ;
1616
			nm = lookup_anon();
1489
	    eid = DEREF_id ( hashid_id ( nm ) ) ;
1617
			eid = DEREF_id(hashid_id(nm));
1490
	    cq = qual_none ;
1618
			cq = qual_none;
1491
	}
1619
		}
1492
    }
1620
	}
1493
    err = check_id_name ( eid, CONTEXT_ENUM ) ;
1621
	err = check_id_name(eid, CONTEXT_ENUM);
1494
    if ( !IS_NULL_err ( err ) ) report ( crt_loc, err ) ;
1622
	if (!IS_NULL_err(err)) {
-
 
1623
		report(crt_loc, err);
-
 
1624
	}
1495
 
1625
 
1496
    /* Check for qualified identifiers */
1626
	/* Check for qualified identifiers */
1497
    if ( cq == qual_none ) {
1627
	if (cq == qual_none) {
1498
	/* Simple enumeration name */
1628
		/* Simple enumeration name */
1499
	if ( option ( OPT_class_scope ) ) {
1629
		if (option(OPT_class_scope)) {
1500
	    ns = crt_namespace ;
1630
			ns = crt_namespace;
1501
	    if ( IS_nspace_param ( ns ) ) ns = nonclass_namespace ;
1631
			if (IS_nspace_param(ns)) {
-
 
1632
				ns = nonclass_namespace;
-
 
1633
			}
1502
	} else {
1634
		} else {
1503
	    ns = nonclass_namespace ;
1635
			ns = nonclass_namespace;
1504
	}
1636
		}
1505
    } else {
1637
	} else {
1506
	/* Definition of nested enumeration */
1638
		/* Definition of nested enumeration */
1507
	ns = DEREF_nspace ( id_parent ( eid ) ) ;
1639
		ns = DEREF_nspace(id_parent(eid));
1508
	check_decl_nspace ( eid, ns, 1, crt_namespace ) ;
1640
		check_decl_nspace(eid, ns, 1, crt_namespace);
1509
	if ( IS_id_undef ( eid ) ) nm = lookup_anon () ;
1641
		if (IS_id_undef(eid)) {
-
 
1642
			nm = lookup_anon();
1510
    }
1643
		}
-
 
1644
	}
1511
 
1645
 
1512
    /* Declare the enumeration */
1646
	/* Declare the enumeration */
1513
    eid = declare_type ( ns, nm, btype_enum, q, 1, 1 ) ;
1647
	eid = declare_type(ns, nm, btype_enum, q, 1, 1);
1514
    ds = DEREF_dspec ( id_storage ( eid ) ) ;
1648
	ds = DEREF_dspec(id_storage(eid));
1515
    COPY_dspec ( id_storage ( eid ), ( ds | dspec_defn ) ) ;
1649
	COPY_dspec(id_storage(eid), (ds | dspec_defn));
1516
    t = DEREF_type ( id_enum_name_defn ( eid ) ) ;
1650
	t = DEREF_type(id_enum_name_defn(eid));
1517
    et = DEREF_etype ( type_enumerate_defn ( t ) ) ;
1651
	et = DEREF_etype(type_enumerate_defn(t));
1518
 
1652
 
1519
    /* Mark start of definition */
1653
	/* Mark start of definition */
1520
    ei = DEREF_cinfo ( etype_info ( et ) ) ;
1654
	ei = DEREF_cinfo(etype_info(et));
1521
    ei |= cinfo_defined ;
1655
	ei |= cinfo_defined;
1522
    ei &= ~cinfo_complete ;
1656
	ei &= ~cinfo_complete;
1523
    COPY_cinfo ( etype_info ( et ), ei ) ;
1657
	COPY_cinfo(etype_info(et), ei);
-
 
1658
	if (do_dump) {
1524
    if ( do_dump ) dump_declare ( eid, &decl_loc, 1 ) ;
1659
		dump_declare(eid, &decl_loc, 1);
-
 
1660
	}
1525
 
1661
 
1526
    /* Force definition information */
1662
	/* Force definition information */
1527
    COPY_loc ( id_loc ( eid ), decl_loc ) ;
1663
	COPY_loc(id_loc(eid), decl_loc);
1528
    return ( eid ) ;
1664
	return (eid);
1529
}
1665
}
1530
 
1666
 
1531
 
1667
 
1532
/*
1668
/*
1533
    END AN ENUMERATION DEFINITION
1669
    END AN ENUMERATION DEFINITION
1534
 
1670
 
1535
    This routine completes the definition of the enumeration type id.
1671
    This routine completes the definition of the enumeration type id.
1536
    Note that only at this stage do the enumerators acquire the type
1672
    Note that only at this stage do the enumerators acquire the type
1537
    of the enumeration in C++.
1673
    of the enumeration in C++.
1538
*/
1674
*/
1539
 
1675
 
1540
IDENTIFIER end_enum_defn
1676
IDENTIFIER
1541
    PROTO_N ( ( id ) )
-
 
1542
    PROTO_T ( IDENTIFIER id )
1677
end_enum_defn(IDENTIFIER id)
1543
{
1678
{
1544
    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
1679
	HASHID nm = DEREF_hashid(id_name(id));
1545
    TYPE t = DEREF_type ( id_enum_name_defn ( id ) ) ;
1680
	TYPE t = DEREF_type(id_enum_name_defn(id));
1546
    ENUM_TYPE et = DEREF_etype ( type_enumerate_defn ( t ) ) ;
1681
	ENUM_TYPE et = DEREF_etype(type_enumerate_defn(t));
1547
    CLASS_INFO ei = DEREF_cinfo ( etype_info ( et ) ) ;
1682
	CLASS_INFO ei = DEREF_cinfo(etype_info(et));
1548
 
1683
 
1549
    /* Sort enumerators */
1684
	/* Sort enumerators */
1550
    LIST ( IDENTIFIER ) ens = DEREF_list ( etype_values ( et ) ) ;
1685
	LIST(IDENTIFIER)ens = DEREF_list(etype_values(et));
1551
    unsigned nenums = LENGTH_list ( ens ) ;
1686
	unsigned nenums = LENGTH_list(ens);
-
 
1687
	if (nenums == 0) {
1552
    if ( nenums == 0 ) report ( crt_loc, ERR_dcl_enum_none () ) ;
1688
		report(crt_loc, ERR_dcl_enum_none());
-
 
1689
	}
1553
    IGNORE check_value ( OPT_VAL_enum_consts, ( ulong ) nenums ) ;
1690
	IGNORE check_value(OPT_VAL_enum_consts,(ulong)nenums);
1554
    ens = REVERSE_list ( ens ) ;
1691
	ens = REVERSE_list(ens);
1555
    COPY_list ( etype_values ( et ), ens ) ;
1692
	COPY_list(etype_values(et), ens);
1556
 
1693
 
1557
#if LANGUAGE_CPP
1694
#if LANGUAGE_CPP
1558
    /* Convert enumerators to enumeration type */
1695
	/* Convert enumerators to enumeration type */
1559
    while ( !IS_NULL_list ( ens ) ) {
1696
	while (!IS_NULL_list(ens)) {
1560
	IDENTIFIER eid = DEREF_id ( HEAD_list ( ens ) ) ;
1697
		IDENTIFIER eid = DEREF_id(HEAD_list(ens));
1561
	EXP e = DEREF_exp ( id_enumerator_value ( eid ) ) ;
1698
		EXP e = DEREF_exp(id_enumerator_value(eid));
1562
	e = eval_exp ( e, 0 ) ;
1699
		e = eval_exp(e, 0);
1563
	e = cast_exp ( t, e, KILL_err, CAST_STATIC ) ;
1700
		e = cast_exp(t, e, KILL_err, CAST_STATIC);
1564
	if ( IS_exp_int_lit ( e ) ) {
1701
		if (IS_exp_int_lit(e)) {
1565
	    COPY_unsigned ( exp_int_lit_etag ( e ), exp_identifier_tag ) ;
1702
			COPY_unsigned(exp_int_lit_etag(e), exp_identifier_tag);
-
 
1703
			if (is_zero_exp(e)) {
1566
	    if ( is_zero_exp ( e ) ) ei |= cinfo_usr_constr ;
1704
				ei |= cinfo_usr_constr;
-
 
1705
			}
1567
	    COPY_exp ( id_enumerator_value ( eid ), e ) ;
1706
			COPY_exp(id_enumerator_value(eid), e);
-
 
1707
		}
-
 
1708
		ens = TAIL_list(ens);
1568
	}
1709
	}
1569
	ens = TAIL_list ( ens ) ;
-
 
1570
    }
-
 
1571
#endif
1710
#endif
1572
 
1711
 
1573
    /* Mark end of definition */
1712
	/* Mark end of definition */
1574
    ei |= cinfo_complete ;
1713
	ei |= cinfo_complete;
1575
    COPY_cinfo ( etype_info ( et ), ei ) ;
1714
	COPY_cinfo(etype_info(et), ei);
1576
    COPY_exp ( etype_value ( et ), NULL_exp ) ;
1715
	COPY_exp(etype_value(et), NULL_exp);
1577
    COPY_ulong ( etype_plus ( et ), 0 ) ;
1716
	COPY_ulong(etype_plus(et), 0);
-
 
1717
	if (do_dump) {
1578
    if ( do_dump ) dump_undefine ( id, &crt_loc, 0 ) ;
1718
		dump_undefine(id, &crt_loc, 0);
-
 
1719
	}
1579
    end_declarator ( id, 1 ) ;
1720
	end_declarator(id, 1);
1580
 
1721
 
1581
    /* Set type declaration flag */
1722
	/* Set type declaration flag */
1582
    if ( IS_hashid_anon ( nm ) && nenums == 0 ) {
1723
	if (IS_hashid_anon(nm) && nenums == 0) {
1583
	have_type_declaration = TYPE_DECL_ANON ;
1724
		have_type_declaration = TYPE_DECL_ANON;
1584
    } else {
1725
	} else {
1585
	have_type_declaration = TYPE_DECL_NORMAL ;
1726
		have_type_declaration = TYPE_DECL_NORMAL;
1586
    }
1727
	}
1587
    return ( id ) ;
1728
	return (id);
1588
}
1729
}
1589
 
1730
 
1590
 
1731
 
1591
/*
1732
/*
1592
    LARGEST SIMPLE ENUMERATOR VALUE
1733
    LARGEST SIMPLE ENUMERATOR VALUE
1593
 
1734
 
1594
    The underlying type of an enumeration can be int, unsigned int, long
1735
    The underlying type of an enumeration can be int, unsigned int, long
1595
    or unsigned long, depending on the values of the enumerators.  This
1736
    or unsigned long, depending on the values of the enumerators.  This
1596
    macro gives the maximum value which is guaranteed to fit into all of
1737
    macro gives the maximum value which is guaranteed to fit into all of
1597
    these types.  Because unsigned types are involved, the minimum value
1738
    these types.  Because unsigned types are involved, the minimum value
1598
    is 0.
1739
    is 0.
1599
*/
1740
*/
1600
 
1741
 
1601
#define ENUM_MAX		( ( unsigned long ) 0x7fff )
1742
#define ENUM_MAX		((unsigned long)0x7fff)
1602
 
1743
 
1603
 
1744
 
1604
/*
1745
/*
1605
    DECLARE AN ENUMERATOR
1746
    DECLARE AN ENUMERATOR
1606
 
1747
 
1607
    This routine declares an enumerator named id belonging to the enumeration
1748
    This routine declares an enumerator named id belonging to the enumeration
1608
    type indicated by eid.  The value of the enumerator is given by the
1749
    type indicated by eid.  The value of the enumerator is given by the
1609
    integer constant expression val, if this is present, or one more than
1750
    integer constant expression val, if this is present, or one more than
1610
    the previous enumerator otherwise.  In C the value is converted to
1751
    the previous enumerator otherwise.  In C the value is converted to
1611
    'int'.  In C++ the value is converted to the enumeration type, but
1752
    'int'.  In C++ the value is converted to the enumeration type, but
1612
    this is only done at the end of the enumeration definition.
1753
    this is only done at the end of the enumeration definition.
1613
*/
1754
*/
1614
 
-
 
1615
IDENTIFIER make_enumerator
-
 
1616
    PROTO_N ( ( eid, id, val ) )
-
 
1617
    PROTO_T ( IDENTIFIER eid X IDENTIFIER id X EXP val )
-
 
1618
{
-
 
1619
    NAT n ;
-
 
1620
    EXP e ;
-
 
1621
    ERROR err ;
-
 
1622
    int record = 0 ;
-
 
1623
    unsigned long v ;
-
 
1624
    DECL_SPEC ds = ( crt_access | dspec_defn | dspec_lang ) ;
-
 
1625
 
1755
 
1626
    /* Find the current enumeration type */
-
 
1627
    TYPE t = DEREF_type ( id_enum_name_defn ( eid ) ) ;
-
 
1628
    ENUM_TYPE et = DEREF_etype ( type_enumerate_defn ( t ) ) ;
-
 
1629
    CLASS_INFO ei = DEREF_cinfo ( etype_info ( et ) ) ;
-
 
1630
    LIST ( IDENTIFIER ) ens = DEREF_list ( etype_values ( et ) ) ;
1756
IDENTIFIER
1631
    NAMESPACE ns = DEREF_nspace ( id_parent ( eid ) ) ;
1757
make_enumerator(IDENTIFIER eid, IDENTIFIER id, EXP val)
1632
 
1758
{
-
 
1759
	NAT n;
-
 
1760
	EXP e;
1633
    /* Look up the enumerator name */
1761
	ERROR err;
1634
    IDENTIFIER nid = id ;
1762
	int record = 0;
1635
    HASHID nm = DEREF_hashid ( id_name ( nid ) ) ;
1763
	unsigned long v;
1636
    MEMBER mem = search_member ( ns, nm, 1 ) ;
1764
	DECL_SPEC ds = (crt_access | dspec_defn | dspec_lang);
1637
 
1765
 
1638
    /* Check on enumeration name */
1766
	/* Find the current enumeration type */
1639
    err = check_id_name ( nid, CONTEXT_ENUMERATOR ) ;
1767
	TYPE t = DEREF_type(id_enum_name_defn(eid));
1640
    if ( !IS_NULL_err ( err ) ) {
1768
	ENUM_TYPE et = DEREF_etype(type_enumerate_defn(t));
1641
	report ( decl_loc, err ) ;
1769
	CLASS_INFO ei = DEREF_cinfo(etype_info(et));
-
 
1770
	LIST(IDENTIFIER)ens = DEREF_list(etype_values(et));
1642
	err = NULL_err ;
1771
	NAMESPACE ns = DEREF_nspace(id_parent(eid));
1643
    }
-
 
1644
 
1772
 
-
 
1773
	/* Look up the enumerator name */
-
 
1774
	IDENTIFIER nid = id;
-
 
1775
	HASHID nm = DEREF_hashid(id_name(nid));
-
 
1776
	MEMBER mem = search_member(ns, nm, 1);
-
 
1777
 
-
 
1778
	/* Check on enumeration name */
-
 
1779
	err = check_id_name(nid, CONTEXT_ENUMERATOR);
-
 
1780
	if (!IS_NULL_err(err)) {
-
 
1781
		report(decl_loc, err);
-
 
1782
		err = NULL_err;
-
 
1783
	}
-
 
1784
 
1645
    /* Check for redeclarations */
1785
	/* Check for redeclarations */
1646
    nid = DEREF_id ( member_id ( mem ) ) ;
1786
	nid = DEREF_id(member_id(mem));
1647
    if ( !IS_NULL_id ( nid ) ) {
1787
	if (!IS_NULL_id(nid)) {
1648
	nid = redecl_inherit ( nid, crt_id_qualifier, in_class_defn, 0 ) ;
1788
		nid = redecl_inherit(nid, crt_id_qualifier, in_class_defn, 0);
1649
	if ( !IS_NULL_id ( nid ) ) {
1789
		if (!IS_NULL_id(nid)) {
1650
	    IGNORE redecl_id ( dspec_reserve, t, nid, 0, 0 ) ;
1790
			IGNORE redecl_id(dspec_reserve, t, nid, 0, 0);
-
 
1791
		}
-
 
1792
	}
-
 
1793
 
-
 
1794
	/* Declare the enumerator */
-
 
1795
	MAKE_id_enumerator(nm, ds, ns, decl_loc, t, val, nid);
-
 
1796
	if (do_dump) {
-
 
1797
		dump_declare(nid, &decl_loc, 1);
1651
	}
1798
	}
1652
    }
-
 
1653
 
1799
 
1654
    /* Declare the enumerator */
-
 
1655
    MAKE_id_enumerator ( nm, ds, ns, decl_loc, t, val, nid ) ;
-
 
1656
    if ( do_dump ) dump_declare ( nid, &decl_loc, 1 ) ;
-
 
1657
 
-
 
1658
    /* Find the enumerator value */
1800
	/* Find the enumerator value */
1659
    t = DEREF_type ( etype_rep ( et ) ) ;
1801
	t = DEREF_type(etype_rep(et));
1660
    if ( !IS_NULL_exp ( val ) ) {
1802
	if (!IS_NULL_exp(val)) {
1661
	/* Check that any given val is a constant */
1803
		/* Check that any given val is a constant */
1662
	TYPE s = DEREF_type ( exp_type ( val ) ) ;
1804
		TYPE s = DEREF_type(exp_type(val));
1663
#if LANGUAGE_CPP
1805
#if LANGUAGE_CPP
1664
	s = promote_type ( s ) ;
1806
		s = promote_type(s);
1665
	val = convert_promote ( s, val ) ;
1807
		val = convert_promote(s, val);
1666
#else
1808
#else
1667
	switch ( TAG_type ( s ) ) {
1809
		switch (TAG_type(s)) {
1668
	    case type_integer_tag :
1810
		case type_integer_tag:
1669
	    case type_bitfield_tag :
1811
		case type_bitfield_tag:
1670
	    case type_enumerate_tag : {
1812
		case type_enumerate_tag: {
1671
		/* Convert integral values to 'int' */
1813
			/* Convert integral values to 'int' */
1672
		s = t ;
1814
			s = t;
1673
		val = cast_int_int ( s, val, &err, CAST_IMPLICIT, -1 ) ;
1815
			val = cast_int_int(s, val, &err, CAST_IMPLICIT, -1);
1674
		if ( !IS_NULL_err ( err ) ) {
1816
			if (!IS_NULL_err(err)) {
1675
		    report ( crt_loc, err ) ;
1817
				report(crt_loc, err);
1676
		    err = NULL_err ;
1818
				err = NULL_err;
1677
		}
1819
			}
1678
		break ;
1820
			break;
1679
	    }
1821
		}
1680
	}
1822
		}
1681
#endif
1823
#endif
1682
	n = make_nat_exp ( val, &err ) ;
1824
		n = make_nat_exp(val, &err);
1683
	if ( !IS_NULL_err ( err ) ) {
1825
		if (!IS_NULL_err(err)) {
1684
	    /* Value is not an integral constant */
1826
			/* Value is not an integral constant */
1685
	    err = concat_error ( err, ERR_dcl_enum_const ( nid ) ) ;
1827
			err = concat_error(err, ERR_dcl_enum_const(nid));
1686
	    report ( crt_loc, err ) ;
1828
			report(crt_loc, err);
1687
	    s = t ;
1829
			s = t;
1688
	}
1830
		}
1689
	v = get_nat_value ( n ) ;
1831
		v = get_nat_value(n);
1690
	if ( v <= ENUM_MAX ) {
1832
		if (v <= ENUM_MAX) {
1691
	    /* Small values */
1833
			/* Small values */
1692
	    if ( !EQ_type ( t, s ) ) {
1834
			if (!EQ_type(t, s)) {
1693
		/* Mark if enumerator has different type */
1835
				/* Mark if enumerator has different type */
1694
		ei |= cinfo_polymorphic ;
1836
				ei |= cinfo_polymorphic;
1695
		t = s ;
1837
				t = s;
1696
	    }
1838
			}
-
 
1839
			if (v == 0) {
1697
	    if ( v == 0 ) ei |= cinfo_usr_constr ;
1840
				ei |= cinfo_usr_constr;
-
 
1841
			}
1698
	    COPY_exp ( etype_value ( et ), NULL_exp ) ;
1842
			COPY_exp(etype_value(et), NULL_exp);
-
 
1843
		} else {
-
 
1844
			/* Large values */
-
 
1845
			EXP cond = crt_hash_cond;
-
 
1846
			if (!EQ_type(t, s)) {
-
 
1847
				/* Extend type range if necessary */
-
 
1848
				t = arith_type(t, s, NULL_exp, NULL_exp);
-
 
1849
				COPY_type(etype_rep(et), t);
-
 
1850
				ei |= cinfo_polymorphic;
-
 
1851
				t = s;
-
 
1852
			}
-
 
1853
			if (!IS_NULL_exp(cond) && is_calc_nat(n)) {
-
 
1854
				/* Propagate target dependent conditionals */
-
 
1855
				EXP alt = make_null_exp(t);
-
 
1856
				MAKE_exp_hash_if (t, cond, val, alt, val);
-
 
1857
				MAKE_nat_calc(val, n);
-
 
1858
			}
-
 
1859
			record = 1;
-
 
1860
			v = 0;
-
 
1861
		}
1699
	} else {
1862
	} else {
1700
	    /* Large values */
-
 
1701
	    EXP cond = crt_hash_cond ;
-
 
1702
	    if ( !EQ_type ( t, s ) ) {
-
 
1703
		/* Extend type range if necessary */
-
 
1704
		t = arith_type ( t, s, NULL_exp, NULL_exp ) ;
-
 
1705
		COPY_type ( etype_rep ( et ), t ) ;
-
 
1706
		ei |= cinfo_polymorphic ;
-
 
1707
		t = s ;
-
 
1708
	    }
-
 
1709
	    if ( !IS_NULL_exp ( cond ) && is_calc_nat ( n ) ) {
-
 
1710
		/* Propagate target dependent conditionals */
-
 
1711
		EXP alt = make_null_exp ( t ) ;
-
 
1712
		MAKE_exp_hash_if ( t, cond, val, alt, val ) ;
-
 
1713
		MAKE_nat_calc ( val, n ) ;
-
 
1714
	    }
-
 
1715
	    record = 1 ;
-
 
1716
	    v = 0 ;
-
 
1717
	}
-
 
1718
    } else {
-
 
1719
	/* Other enumerators are one more than the previous one */
1863
		/* Other enumerators are one more than the previous one */
1720
	v = DEREF_ulong ( etype_plus ( et ) ) ;
1864
		v = DEREF_ulong(etype_plus(et));
1721
	n = make_nat_value ( v ) ;
1865
		n = make_nat_value(v);
1722
	e = DEREF_exp ( etype_value ( et ) ) ;
1866
		e = DEREF_exp(etype_value(et));
1723
	if ( IS_NULL_exp ( e ) ) {
1867
		if (IS_NULL_exp(e)) {
1724
	    if ( ei & cinfo_polymorphic ) {
1868
			if (ei & cinfo_polymorphic) {
1725
		/* Use type of last enumerator, if different */
1869
				/* Use type of last enumerator, if different */
1726
		IDENTIFIER pid = DEREF_id ( HEAD_list ( ens ) ) ;
1870
				IDENTIFIER pid = DEREF_id(HEAD_list(ens));
1727
		e = DEREF_exp ( id_enumerator_value ( pid ) ) ;
1871
				e = DEREF_exp(id_enumerator_value(pid));
1728
		t = DEREF_type ( exp_type ( e ) ) ;
1872
				t = DEREF_type(exp_type(e));
1729
	    }
1873
			}
-
 
1874
			if (v == 0) {
1730
	    if ( v == 0 ) ei |= cinfo_usr_constr ;
1875
				ei |= cinfo_usr_constr;
-
 
1876
			}
1731
	} else {
1877
		} else {
1732
	    EXP c ;
1878
			EXP c;
1733
	    t = DEREF_type ( exp_type ( e ) ) ;
1879
			t = DEREF_type(exp_type(e));
1734
	    MAKE_exp_int_lit ( t, n, exp_int_lit_tag, c ) ;
1880
			MAKE_exp_int_lit(t, n, exp_int_lit_tag, c);
1735
	    MAKE_exp_plus ( t, e, c, e ) ;
1881
			MAKE_exp_plus(t, e, c, e);
1736
	    MAKE_nat_calc ( e, n ) ;
1882
			MAKE_nat_calc(e, n);
1737
	}
1883
		}
1738
    }
1884
	}
1739
    MAKE_exp_int_lit ( t, n, exp_identifier_tag, e ) ;
1885
	MAKE_exp_int_lit(t, n, exp_identifier_tag, e);
1740
    COPY_exp ( id_enumerator_value ( nid ), e ) ;
1886
	COPY_exp(id_enumerator_value(nid), e);
1741
 
1887
 
1742
    /* Increment enumerator counter */
1888
	/* Increment enumerator counter */
1743
    if ( v >= ENUM_MAX ) {
1889
	if (v >= ENUM_MAX) {
1744
	record = 1 ;
1890
		record = 1;
1745
	v = 0 ;
1891
		v = 0;
1746
    }
1892
	}
-
 
1893
	if (record) {
1747
    if ( record ) COPY_exp ( etype_value ( et ), e ) ;
1894
		COPY_exp(etype_value(et), e);
-
 
1895
	}
1748
    COPY_ulong ( etype_plus ( et ), v + 1 ) ;
1896
	COPY_ulong(etype_plus(et), v + 1);
1749
 
1897
 
1750
    /* Add enumerator to the enumerator list */
1898
	/* Add enumerator to the enumerator list */
1751
    set_member ( mem, nid ) ;
1899
	set_member(mem, nid);
1752
    CONS_id ( nid, ens, ens ) ;
1900
	CONS_id(nid, ens, ens);
1753
    COPY_list ( etype_values ( et ), ens ) ;
1901
	COPY_list(etype_values(et), ens);
1754
    COPY_cinfo ( etype_info ( et ), ei ) ;
1902
	COPY_cinfo(etype_info(et), ei);
1755
    return ( nid ) ;
1903
	return (nid);
1756
}
1904
}
1757
 
1905
 
1758
 
1906
 
1759
/*
1907
/*
1760
    DOES A VALUE APPEAR AS AN ENUMERATOR?
1908
    DOES A VALUE APPEAR AS AN ENUMERATOR?
1761
 
1909
 
1762
    This routine checks whether the integer constant n is a valid enumerator
1910
    This routine checks whether the integer constant n is a valid enumerator
1763
    for the enumeration et.  If so it returns the enumerator identifier.
1911
    for the enumeration et.  If so it returns the enumerator identifier.
1764
*/
1912
*/
1765
 
1913
 
1766
IDENTIFIER find_enumerator
1914
IDENTIFIER
1767
    PROTO_N ( ( et, n ) )
-
 
1768
    PROTO_T ( ENUM_TYPE et X NAT n )
1915
find_enumerator(ENUM_TYPE et, NAT n)
1769
{
1916
{
1770
    LIST ( IDENTIFIER ) p = DEREF_list ( etype_values ( et ) ) ;
1917
	LIST(IDENTIFIER)p = DEREF_list(etype_values(et));
1771
    while ( !IS_NULL_list ( p ) ) {
1918
	while (!IS_NULL_list(p)) {
1772
	IDENTIFIER eid = DEREF_id ( HEAD_list ( p ) ) ;
1919
		IDENTIFIER eid = DEREF_id(HEAD_list(p));
1773
	EXP e = DEREF_exp ( id_enumerator_value ( eid ) ) ;
1920
		EXP e = DEREF_exp(id_enumerator_value(eid));
1774
	NAT m = DEREF_nat ( exp_int_lit_nat ( e ) ) ;
1921
		NAT m = DEREF_nat(exp_int_lit_nat(e));
1775
	if ( EQ_nat ( n, m ) || eq_nat ( n, m ) ) return ( eid ) ;
1922
		if (EQ_nat(n, m) || eq_nat(n, m)) {
-
 
1923
			return (eid);
-
 
1924
		}
1776
	p = TAIL_list ( p ) ;
1925
		p = TAIL_list(p);
1777
    }
1926
	}
1778
    return ( NULL_id ) ;
1927
	return (NULL_id);
1779
}
1928
}
1780
 
1929
 
1781
 
1930
 
1782
/*
1931
/*
1783
    ELABORATE TYPE SPECIFIER FLAG
1932
    ELABORATE TYPE SPECIFIER FLAG
1784
 
1933
 
1785
    This flag is set by find_elaborate_type and declare_type to indicate
1934
    This flag is set by find_elaborate_type and declare_type to indicate
1786
    that the given type specifier referred to a pre-existing type.
1935
    that the given type specifier referred to a pre-existing type.
1787
*/
1936
*/
1788
 
1937
 
1789
int found_elaborate_type = 0 ;
1938
int found_elaborate_type = 0;
1790
 
1939
 
1791
 
1940
 
1792
/*
1941
/*
1793
    FIND AN ELABORATED TYPE SPECIFIER
1942
    FIND AN ELABORATED TYPE SPECIFIER
1794
 
1943
 
Line 1803... Line 1952...
1803
	dspec_alias	for qualified identifiers,
1952
	dspec_alias	for qualified identifiers,
1804
	dspec_auto	if type is to be declared in current namespace,
1953
	dspec_auto	if type is to be declared in current namespace,
1805
	dspec_used	if type is to be searched for.
1954
	dspec_used	if type is to be searched for.
1806
*/
1955
*/
1807
 
1956
 
1808
IDENTIFIER find_elaborate_type
1957
IDENTIFIER
1809
    PROTO_N ( ( id, key, q, mode ) )
-
 
1810
    PROTO_T ( IDENTIFIER id X BASE_TYPE key X TYPE q X DECL_SPEC mode )
1958
find_elaborate_type(IDENTIFIER id, BASE_TYPE key, TYPE q, DECL_SPEC mode)
1811
{
1959
{
1812
    ERROR err ;
1960
	ERROR err;
1813
    LOCATION loc ;
1961
	LOCATION loc;
1814
    NAMESPACE ns ;
1962
	NAMESPACE ns;
1815
    IDENTIFIER tid ;
1963
	IDENTIFIER tid;
1816
    int templ = is_templ_spec ( q ) ;
1964
	int templ = is_templ_spec(q);
1817
    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
1965
	HASHID nm = DEREF_hashid(id_name(id));
1818
 
1966
 
1819
    /* Check for template applications */
1967
	/* Check for template applications */
1820
    if ( templ || is_templ_decl ( id, NULL_type ) ) {
1968
	if (templ || is_templ_decl(id, NULL_type)) {
1821
	tid = id ;
1969
		tid = id;
1822
	if ( mode & dspec_defn ) {
1970
		if (mode & dspec_defn) {
1823
	    /* Bind template specialisations */
1971
			/* Bind template specialisations */
1824
	    DECL_SPEC ds = ( mode & dspec_friend ) ;
1972
			DECL_SPEC ds = (mode & dspec_friend);
1825
	    q = bind_specialise ( &tid, q, ds, 1, 1, 0 ) ;
1973
			q = bind_specialise(&tid, q, ds, 1, 1, 0);
1826
	}
1974
		}
1827
	if ( !IS_NULL_id ( tid ) && IS_id_class_name_etc ( tid ) ) {
1975
		if (!IS_NULL_id(tid) && IS_id_class_name_etc(tid)) {
1828
	    IGNORE check_key ( tid, key ) ;
1976
			IGNORE check_key(tid, key);
1829
	    if ( templ ) {
1977
			if (templ) {
1830
		/* Check namespace for explicit declaration */
1978
				/* Check namespace for explicit declaration */
1831
		ns = DEREF_nspace ( id_parent ( tid ) ) ;
1979
				ns = DEREF_nspace(id_parent(tid));
1832
		check_decl_nspace ( tid, ns, 0, crt_namespace ) ;
1980
				check_decl_nspace(tid, ns, 0, crt_namespace);
1833
	    }
1981
			}
1834
	    found_elaborate_type = 1 ;
1982
			found_elaborate_type = 1;
1835
	    return ( tid ) ;
1983
			return (tid);
-
 
1984
		}
-
 
1985
	} else {
-
 
1986
		if (mode & dspec_alias) {
-
 
1987
			/* Qualified identifier */
-
 
1988
			NAMESPACE tns = DEREF_nspace(id_parent(id));
-
 
1989
			tid = find_qual_id(tns, nm, 0, 1);
-
 
1990
			if (IS_NULL_id(tid) || !IS_id_class_name_etc(tid)) {
-
 
1991
				if (!IS_NULL_id(tid) && IS_id_ambig(tid)) {
-
 
1992
					tid = report_ambiguous(tid, 1, 1, 1);
-
 
1993
				} else {
-
 
1994
					report(crt_loc,
-
 
1995
					       ERR_dcl_type_simple_undef(id));
-
 
1996
					tid = NULL_id;
-
 
1997
					q = NULL_type;
-
 
1998
				}
-
 
1999
			}
-
 
2000
		} else if (mode & dspec_register) {
-
 
2001
			/* Search enclosing namespace */
-
 
2002
			tid = find_extern_id(nm, nonclass_namespace, 1);
-
 
2003
		} else if (mode & dspec_used) {
-
 
2004
			/* Search for enclosing declaration */
-
 
2005
			tid = find_type_id(nm, 1);
-
 
2006
		} else {
-
 
2007
			/* Force a new declaration */
-
 
2008
			tid = NULL_id;
-
 
2009
		}
1836
	}
2010
	}
-
 
2011
 
1837
    } else {
2012
	/* Check previous declaration */
-
 
2013
	while (!IS_NULL_id(tid)) {
-
 
2014
		if (IS_id_class_name_etc(tid)) {
-
 
2015
			/* Previous declaration was a type name */
-
 
2016
			BASE_TYPE prev = find_key(tid, 0, key);
1838
	if ( mode & dspec_alias ) {
2017
			if (prev == btype_alias) {
1839
	    /* Qualified identifier */
2018
				/* This was a typedef name */
1840
	    NAMESPACE tns = DEREF_nspace ( id_parent ( id ) ) ;
2019
				err = ERR_lookup_elab_alias(key, tid);
-
 
2020
				report(crt_loc, err);
1841
	    tid = find_qual_id ( tns, nm, 0, 1 ) ;
2021
			} else if (!equal_key(prev, key)) {
-
 
2022
				/* The class keys don't match */
-
 
2023
				PTR(LOCATION)ploc = id_loc(tid);
1842
	    if ( IS_NULL_id ( tid ) || !IS_id_class_name_etc ( tid ) ) {
2024
				err = ERR_dcl_type_elab_bad(key, prev, tid,
-
 
2025
							    ploc);
-
 
2026
				report(crt_loc, err);
-
 
2027
			}
-
 
2028
			found_elaborate_type = 1;
-
 
2029
			return (tid);
-
 
2030
		}
1843
		if ( !IS_NULL_id ( tid ) && IS_id_ambig ( tid ) ) {
2031
		if (IS_id_ambig(tid)) {
1844
		    tid = report_ambiguous ( tid, 1, 1, 1 ) ;
2032
			tid = report_ambiguous(tid, 1, 1, 1);
1845
		} else {
2033
		} else {
1846
		    report ( crt_loc, ERR_dcl_type_simple_undef ( id ) ) ;
2034
			report(crt_loc, ERR_lookup_elab_invalid(key, tid));
1847
		    tid = NULL_id ;
2035
			tid = NULL_id;
1848
		    q = NULL_type ;
-
 
1849
		}
2036
		}
1850
	    }
-
 
1851
	} else if ( mode & dspec_register ) {
-
 
1852
	    /* Search enclosing namespace */
-
 
1853
	    tid = find_extern_id ( nm, nonclass_namespace, 1 ) ;
-
 
1854
	} else if ( mode & dspec_used ) {
-
 
1855
	    /* Search for enclosing declaration */
-
 
1856
	    tid = find_type_id ( nm, 1 ) ;
-
 
1857
	} else {
-
 
1858
	    /* Force a new declaration */
-
 
1859
	    tid = NULL_id ;
-
 
1860
	}
2037
	}
1861
    }
-
 
1862
 
2038
 
1863
    /* Check previous declaration */
2039
	/* Find namespace for declared type */
1864
    while ( !IS_NULL_id ( tid ) ) {
-
 
1865
	if ( IS_id_class_name_etc ( tid ) ) {
2040
	if (mode & dspec_alias) {
1866
	    /* Previous declaration was a type name */
2041
		/* Declare in parent namespace */
1867
	    BASE_TYPE prev = find_key ( tid, 0, key ) ;
2042
		ns = DEREF_nspace(id_parent(id));
1868
	    if ( prev == btype_alias ) {
2043
	} else if ((mode & dspec_auto) && option(OPT_class_scope)) {
1869
		/* This was a typedef name */
2044
		/* Declare in the current namespace */
1870
		err = ERR_lookup_elab_alias ( key, tid ) ;
-
 
1871
		report ( crt_loc, err ) ;
2045
		ns = crt_namespace;
1872
	    } else if ( !equal_key ( prev, key ) ) {
2046
	} else if (mode & dspec_template) {
1873
		/* The class keys don't match */
2047
		/* Declare in template namespace */
1874
		PTR ( LOCATION ) ploc = id_loc ( tid ) ;
-
 
1875
		err = ERR_dcl_type_elab_bad ( key, prev, tid, ploc ) ;
-
 
1876
		report ( crt_loc, err ) ;
2048
		ns = templ_namespace;
1877
	    }
-
 
1878
	    found_elaborate_type = 1 ;
-
 
1879
	    return ( tid ) ;
-
 
1880
	}
-
 
1881
	if ( IS_id_ambig ( tid ) ) {
-
 
1882
	    tid = report_ambiguous ( tid, 1, 1, 1 ) ;
-
 
1883
	} else {
2049
	} else {
1884
	    report ( crt_loc, ERR_lookup_elab_invalid ( key, tid ) ) ;
-
 
1885
	    tid = NULL_id ;
-
 
1886
	}
-
 
1887
    }
-
 
1888
 
-
 
1889
    /* Find namespace for declared type */
-
 
1890
    if ( mode & dspec_alias ) {
-
 
1891
	/* Declare in parent namespace */
-
 
1892
	ns = DEREF_nspace ( id_parent ( id ) ) ;
-
 
1893
    } else if ( ( mode & dspec_auto ) && option ( OPT_class_scope ) ) {
-
 
1894
	/* Declare in the current namespace */
-
 
1895
	ns = crt_namespace ;
-
 
1896
    } else if ( mode & dspec_template ) {
-
 
1897
	/* Declare in template namespace */
-
 
1898
	ns = templ_namespace ;
-
 
1899
    } else {
-
 
1900
	/* Declare in enclosing namespace */
2050
		/* Declare in enclosing namespace */
1901
	ns = nonclass_namespace ;
2051
		ns = nonclass_namespace;
1902
    }
2052
	}
1903
 
2053
 
1904
    /* Declare new type */
2054
	/* Declare new type */
1905
    loc = decl_loc ;
2055
	loc = decl_loc;
1906
    err = check_id_name ( id, CONTEXT_CLASS ) ;
2056
	err = check_id_name(id, CONTEXT_CLASS);
1907
    id = underlying_id ( id ) ;
2057
	id = underlying_id(id);
1908
    DEREF_loc ( id_loc ( id ), decl_loc ) ;
2058
	DEREF_loc(id_loc(id), decl_loc);
1909
    if ( !IS_NULL_err ( err ) ) report ( decl_loc, err ) ;
2059
	if (!IS_NULL_err(err)) {
-
 
2060
		report(decl_loc, err);
-
 
2061
	}
1910
    tid = declare_type ( ns, nm, key, q, 0, 1 ) ;
2062
	tid = declare_type(ns, nm, key, q, 0, 1);
-
 
2063
	if (do_dump) {
1911
    if ( do_dump ) dump_declare ( tid, &decl_loc, 0 ) ;
2064
		dump_declare(tid, &decl_loc, 0);
-
 
2065
	}
1912
    if ( key == btype_enum ) {
2066
	if (key == btype_enum) {
1913
	/* Can't declare enumerations (but have done) */
2067
		/* Can't declare enumerations (but have done) */
1914
	report ( decl_loc, ERR_lookup_elab_enum ( tid ) ) ;
2068
		report(decl_loc, ERR_lookup_elab_enum(tid));
1915
    }
2069
	}
1916
    if ( mode & dspec_friend ) {
2070
	if (mode & dspec_friend) {
1917
	/* Warn about potential friend problems */
2071
		/* Warn about potential friend problems */
1918
	report ( decl_loc, ERR_class_friend_pre ( tid ) ) ;
2072
		report(decl_loc, ERR_class_friend_pre(tid));
1919
    }
2073
	}
1920
    decl_loc = loc ;
2074
	decl_loc = loc;
1921
    return ( tid ) ;
2075
	return (tid);
1922
}
2076
}
1923
 
2077
 
1924
 
2078
 
1925
/*
2079
/*
1926
    CREATE A TYPE ALIAS
2080
    CREATE A TYPE ALIAS
1927
 
2081
 
Line 1929... Line 2083...
1929
    in the namespace ns (but doesn't bring it into scope).  Note that
2083
    in the namespace ns (but doesn't bring it into scope).  Note that
1930
    typedefs are split into class aliases, enumeration aliases and other
2084
    typedefs are split into class aliases, enumeration aliases and other
1931
    type aliases.  In the former two cases the class identifier is
2085
    type aliases.  In the former two cases the class identifier is
1932
    associated with t as the type name, and the member namespace name for
2086
    associated with t as the type name, and the member namespace name for
1933
    classes, if this has not yet been defined.
2087
    classes, if this has not yet been defined.
1934
*/
2088
*/
1935
 
2089
 
1936
IDENTIFIER make_typedef
2090
IDENTIFIER
1937
    PROTO_N ( ( ns, nm, t, ds ) )
-
 
1938
    PROTO_T ( NAMESPACE ns X HASHID nm X TYPE t X DECL_SPEC ds )
2091
make_typedef(NAMESPACE ns, HASHID nm, TYPE t, DECL_SPEC ds)
1939
{
2092
{
1940
    TYPE s ;
2093
	TYPE s;
1941
    unsigned tag ;
2094
	unsigned tag;
1942
    IDENTIFIER id ;
2095
	IDENTIFIER id;
1943
 
2096
 
1944
    /* Force copy of type */
2097
	/* Force copy of type */
1945
    CV_SPEC cv = DEREF_cv ( type_qual ( t ) ) ;
2098
	CV_SPEC cv = DEREF_cv(type_qual(t));
1946
    t = qualify_type ( t, cv, 1 ) ;
2099
	t = qualify_type(t, cv, 1);
1947
    s = t ;
2100
	s = t;
1948
    tag = TAG_type ( s ) ;
2101
	tag = TAG_type(s);
1949
 
2102
 
1950
    /* Check for template types */
2103
	/* Check for template types */
-
 
2104
	if (ds == dspec_none) {
1951
    if ( ds == dspec_none ) ds = ( crt_access | dspec_defn ) ;
2105
		ds = (crt_access | dspec_defn);
-
 
2106
	}
1952
    while ( tag == type_templ_tag ) {
2107
	while (tag == type_templ_tag) {
1953
	s = DEREF_type ( type_templ_defn ( s ) ) ;
2108
		s = DEREF_type(type_templ_defn(s));
1954
	tag = TAG_type ( s ) ;
2109
		tag = TAG_type(s);
1955
	ds |= dspec_template ;
2110
		ds |= dspec_template;
1956
    }
2111
	}
1957
 
2112
 
1958
    /* Check for class aliases */
2113
	/* Check for class aliases */
1959
    if ( tag == type_compound_tag ) {
2114
	if (tag == type_compound_tag) {
1960
	CV_SPEC qual = DEREF_cv ( type_qual ( s ) ) ;
2115
		CV_SPEC qual = DEREF_cv(type_qual(s));
1961
	if ( qual == cv_none ) {
2116
		if (qual == cv_none) {
1962
	    /* Find the class name */
2117
			/* Find the class name */
1963
	    CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( s ) ) ;
2118
			CLASS_TYPE ct = DEREF_ctype(type_compound_defn(s));
1964
	    IDENTIFIER cid = DEREF_id ( ctype_name ( ct ) ) ;
2119
			IDENTIFIER cid = DEREF_id(ctype_name(ct));
1965
	    HASHID cnm = DEREF_hashid ( id_name ( cid ) ) ;
2120
			HASHID cnm = DEREF_hashid(id_name(cid));
1966
 
2121
 
1967
	    /* Set up the class alias */
2122
			/* Set up the class alias */
1968
	    MAKE_id_class_alias ( nm, ds, ns, decl_loc, t, id ) ;
2123
			MAKE_id_class_alias(nm, ds, ns, decl_loc, t, id);
1969
 
2124
 
1970
	    if ( IS_hashid_anon ( cnm ) ) {
2125
			if (IS_hashid_anon(cnm)) {
1971
		/* Set the class name if necessary */
2126
				/* Set the class name if necessary */
1972
		NAMESPACE mns ;
2127
				NAMESPACE mns;
1973
		if ( do_dump ) {
2128
				if (do_dump) {
1974
		    dump_declare ( id, &decl_loc, 1 ) ;
2129
					dump_declare(id, &decl_loc, 1);
1975
		    dump_anon_class = 1 ;
2130
					dump_anon_class = 1;
1976
		}
2131
				}
1977
		COPY_dspec ( id_storage ( id ), ( ds | dspec_lang ) ) ;
2132
				COPY_dspec(id_storage(id), (ds | dspec_lang));
1978
		mns = DEREF_nspace ( ctype_member ( ct ) ) ;
2133
				mns = DEREF_nspace(ctype_member(ct));
1979
		COPY_id ( nspace_name ( mns ), id ) ;
2134
				COPY_id(nspace_name(mns), id);
1980
		COPY_id ( ctype_name ( ct ), id ) ;
2135
				COPY_id(ctype_name(ct), id);
1981
 
2136
 
1982
		/* Also set constructor and destructor names */
2137
				/* Also set constructor and destructor names */
1983
		cid = DEREF_id ( ctype_constr ( ct ) ) ;
2138
				cid = DEREF_id(ctype_constr(ct));
1984
		cnm = DEREF_hashid ( id_name ( cid ) ) ;
2139
				cnm = DEREF_hashid(id_name(cid));
1985
		COPY_id ( hashid_constr_tid ( cnm ), id ) ;
2140
				COPY_id(hashid_constr_tid(cnm), id);
1986
		cid = DEREF_id ( ctype_destr ( ct ) ) ;
2141
				cid = DEREF_id(ctype_destr(ct));
1987
		cnm = DEREF_hashid ( id_name ( cid ) ) ;
2142
				cnm = DEREF_hashid(id_name(cid));
1988
		COPY_id ( hashid_destr_tid ( cnm ), id ) ;
2143
				COPY_id(hashid_destr_tid(cnm), id);
1989
	    }
2144
			}
1990
	    return ( id ) ;
2145
			return (id);
1991
	}
2146
		}
1992
    }
2147
	}
1993
 
2148
 
1994
    /* Check for enumeration aliases */
2149
	/* Check for enumeration aliases */
1995
    if ( tag == type_enumerate_tag ) {
2150
	if (tag == type_enumerate_tag) {
1996
	CV_SPEC qual = DEREF_cv ( type_qual ( s ) ) ;
2151
		CV_SPEC qual = DEREF_cv(type_qual(s));
1997
	if ( qual == cv_none ) {
2152
		if (qual == cv_none) {
1998
	    /* Find the enumeration name */
2153
			/* Find the enumeration name */
1999
	    ENUM_TYPE et = DEREF_etype ( type_enumerate_defn ( s ) ) ;
2154
			ENUM_TYPE et = DEREF_etype(type_enumerate_defn(s));
2000
	    IDENTIFIER eid = DEREF_id ( etype_name ( et ) ) ;
2155
			IDENTIFIER eid = DEREF_id(etype_name(et));
2001
	    HASHID enm = DEREF_hashid ( id_name ( eid ) ) ;
2156
			HASHID enm = DEREF_hashid(id_name(eid));
2002
 
2157
 
2003
	    /* Set up the enumeration alias */
2158
			/* Set up the enumeration alias */
2004
	    MAKE_id_enum_alias ( nm, ds, ns, decl_loc, t, id ) ;
2159
			MAKE_id_enum_alias(nm, ds, ns, decl_loc, t, id);
2005
 
2160
 
2006
	    /* Set the enumeration name if necessary */
2161
			/* Set the enumeration name if necessary */
2007
	    if ( IS_hashid_anon ( enm ) ) {
2162
			if (IS_hashid_anon(enm)) {
2008
		if ( do_dump ) {
2163
				if (do_dump) {
2009
		    dump_declare ( id, &decl_loc, 1 ) ;
2164
					dump_declare(id, &decl_loc, 1);
2010
		    dump_anon_class = 1 ;
2165
					dump_anon_class = 1;
-
 
2166
				}
-
 
2167
				COPY_dspec(id_storage(id), (ds | dspec_lang));
-
 
2168
				COPY_id(etype_name(et), id);
-
 
2169
			}
-
 
2170
			return (id);
2011
		}
2171
		}
2012
		COPY_dspec ( id_storage ( id ), ( ds | dspec_lang ) ) ;
-
 
2013
		COPY_id ( etype_name ( et ), id ) ;
-
 
2014
	    }
-
 
2015
	    return ( id ) ;
-
 
2016
	}
2172
	}
2017
    }
-
 
2018
 
2173
 
2019
    /* Other type aliases */
2174
	/* Other type aliases */
2020
    MAKE_id_type_alias ( nm, ds, ns, decl_loc, t, id ) ;
2175
	MAKE_id_type_alias(nm, ds, ns, decl_loc, t, id);
2021
    return ( id ) ;
2176
	return (id);
2022
}
2177
}
2023
 
2178
 
2024
 
2179
 
2025
/*
2180
/*
2026
    FIND THE COPIED VERSION OF A CLASS MEMBER
2181
    FIND THE COPIED VERSION OF A CLASS MEMBER
Line 2029... Line 2184...
2029
    class member id.  cid will be a copy of the class containing id.
2184
    class member id.  cid will be a copy of the class containing id.
2030
    Note that if res is false a set of overloaded functions is mapped to
2185
    Note that if res is false a set of overloaded functions is mapped to
2031
    a set of overloaded functions, further resolutions based on type may be
2186
    a set of overloaded functions, further resolutions based on type may be
2032
    performed later.  If res is true overload resolution is performed
2187
    performed later.  If res is true overload resolution is performed
2033
    based on whether the result is an instantiation of id.
2188
    based on whether the result is an instantiation of id.
2034
*/
2189
*/
2035
 
2190
 
2036
IDENTIFIER find_copied
2191
IDENTIFIER
2037
    PROTO_N ( ( cid, id, res ) )
-
 
2038
    PROTO_T ( IDENTIFIER cid X IDENTIFIER id X int res )
2192
find_copied(IDENTIFIER cid, IDENTIFIER id, int res)
2039
{
2193
{
2040
    HASHID nm ;
2194
	HASHID nm;
2041
    MEMBER mem ;
2195
	MEMBER mem;
2042
    NAMESPACE ns ;
2196
	NAMESPACE ns;
2043
    CLASS_TYPE ct ;
2197
	CLASS_TYPE ct;
2044
    IDENTIFIER mid ;
2198
	IDENTIFIER mid;
2045
 
2199
 
2046
    /* Find class namespace */
2200
	/* Find class namespace */
2047
    TYPE t = DEREF_type ( id_class_name_etc_defn ( cid ) ) ;
2201
	TYPE t = DEREF_type(id_class_name_etc_defn(cid));
2048
    while ( IS_type_templ ( t ) ) {
2202
	while (IS_type_templ(t)) {
2049
	t = DEREF_type ( type_templ_defn ( t ) ) ;
2203
		t = DEREF_type(type_templ_defn(t));
2050
    }
-
 
2051
    ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
-
 
2052
    complete_class ( ct, 1 ) ;
-
 
2053
    ns = DEREF_nspace ( ctype_member ( ct ) ) ;
-
 
2054
 
-
 
2055
    /* Look up name in namespace */
-
 
2056
    nm = DEREF_hashid ( id_name ( id ) ) ;
-
 
2057
    nm = expand_name ( nm, ct ) ;
-
 
2058
    do {
-
 
2059
	mem = search_member ( ns, nm, 0 ) ;
-
 
2060
	if ( !IS_NULL_member ( mem ) ) break ;
-
 
2061
	nm = next_expand_name ( nm ) ;
-
 
2062
    } while ( !IS_NULL_hashid ( nm ) ) ;
-
 
2063
 
-
 
2064
    /* Check for corresponding identifier */
-
 
2065
    if ( !IS_NULL_member ( mem ) ) {
-
 
2066
	mid = DEREF_id ( member_id ( mem ) ) ;
-
 
2067
	if ( !IS_NULL_id ( mid ) ) {
-
 
2068
	    /* Identifier matches member */
-
 
2069
	    if ( IS_id_function_etc ( mid ) && IS_id_function_etc ( id ) ) {
-
 
2070
		/* Matching functions */
-
 
2071
		if ( res ) {
-
 
2072
		    IDENTIFIER fid = NULL_id ;
-
 
2073
		    TYPE f = DEREF_type ( id_function_etc_form ( id ) ) ;
-
 
2074
		    if ( !IS_NULL_type ( f ) && IS_type_instance ( f ) ) {
-
 
2075
			fid = DEREF_id ( type_instance_id ( f ) ) ;
-
 
2076
		    }
-
 
2077
		    while ( !IS_NULL_id ( mid ) ) {
-
 
2078
			/* Perform overload resolution */
-
 
2079
			if ( EQ_id ( mid, id ) ) return ( mid ) ;
-
 
2080
			if ( EQ_id ( mid, fid ) ) return ( mid ) ;
-
 
2081
			f = DEREF_type ( id_function_etc_form ( mid ) ) ;
-
 
2082
			if ( !IS_NULL_type ( f ) && IS_type_instance ( f ) ) {
-
 
2083
			    IDENTIFIER nid ;
-
 
2084
			    nid = DEREF_id ( type_instance_id ( f ) ) ;
-
 
2085
			    if ( EQ_id ( nid, id ) ) return ( mid ) ;
-
 
2086
			    if ( EQ_id ( nid, fid ) ) return ( mid ) ;
-
 
2087
			}
-
 
2088
			mid = DEREF_id ( id_function_etc_over ( mid ) ) ;
-
 
2089
		    }
-
 
2090
		    mid = id ;
-
 
2091
		}
-
 
2092
		return ( mid ) ;
-
 
2093
	    }
-
 
2094
	    if ( TAG_id ( mid ) == TAG_id ( id ) ) return ( mid ) ;
-
 
2095
	}
-
 
2096
	mid = DEREF_id ( member_alt ( mem ) ) ;
-
 
2097
	if ( !IS_NULL_id ( mid ) && TAG_id ( mid ) == TAG_id ( id ) ) {
-
 
2098
	    /* Identifier matches type member */
-
 
2099
	    return ( mid ) ;
-
 
2100
	}
2204
	}
-
 
2205
	ct = DEREF_ctype(type_compound_defn(t));
-
 
2206
	complete_class(ct, 1);
-
 
2207
	ns = DEREF_nspace(ctype_member(ct));
-
 
2208
 
-
 
2209
	/* Look up name in namespace */
-
 
2210
	nm = DEREF_hashid(id_name(id));
-
 
2211
	nm = expand_name(nm, ct);
-
 
2212
	do {
-
 
2213
		mem = search_member(ns, nm, 0);
-
 
2214
		if (!IS_NULL_member(mem)) {
-
 
2215
			break;
-
 
2216
		}
-
 
2217
		nm = next_expand_name(nm);
-
 
2218
	} while (!IS_NULL_hashid(nm));
-
 
2219
 
-
 
2220
	/* Check for corresponding identifier */
-
 
2221
	if (!IS_NULL_member(mem)) {
-
 
2222
		mid = DEREF_id(member_id(mem));
-
 
2223
		if (!IS_NULL_id(mid)) {
-
 
2224
			/* Identifier matches member */
-
 
2225
			if (IS_id_function_etc(mid) && IS_id_function_etc(id)) {
-
 
2226
				/* Matching functions */
-
 
2227
				if (res) {
-
 
2228
					IDENTIFIER fid = NULL_id;
-
 
2229
					TYPE f = DEREF_type(id_function_etc_form(id));
-
 
2230
					if (!IS_NULL_type(f) && IS_type_instance(f)) {
-
 
2231
						fid = DEREF_id(type_instance_id(f));
-
 
2232
					}
-
 
2233
					while (!IS_NULL_id(mid)) {
-
 
2234
						/* Perform overload resolution */
-
 
2235
						if (EQ_id(mid, id)) {
-
 
2236
							return (mid);
-
 
2237
						}
-
 
2238
						if (EQ_id(mid, fid)) {
-
 
2239
							return (mid);
-
 
2240
						}
-
 
2241
						f = DEREF_type(id_function_etc_form(mid));
-
 
2242
						if (!IS_NULL_type(f) && IS_type_instance(f)) {
-
 
2243
							IDENTIFIER nid;
-
 
2244
							nid = DEREF_id(type_instance_id(f));
-
 
2245
							if (EQ_id(nid, id)) {
-
 
2246
								return (mid);
-
 
2247
							}
-
 
2248
							if (EQ_id(nid, fid)) {
-
 
2249
								return (mid);
-
 
2250
							}
-
 
2251
						}
-
 
2252
						mid = DEREF_id(id_function_etc_over(mid));
-
 
2253
					}
-
 
2254
					mid = id;
2101
    }
2255
				}
-
 
2256
				return (mid);
-
 
2257
			}
-
 
2258
			if (TAG_id(mid) == TAG_id(id)) {
2102
    return ( id ) ;
2259
				return (mid);
-
 
2260
			}
-
 
2261
		}
-
 
2262
		mid = DEREF_id(member_alt(mem));
-
 
2263
		if (!IS_NULL_id(mid) && TAG_id(mid) == TAG_id(id)) {
-
 
2264
			/* Identifier matches type member */
-
 
2265
			return (mid);
-
 
2266
		}
-
 
2267
	}
-
 
2268
	return (id);
2103
}
2269
}
2104
 
2270
 
2105
 
2271
 
2106
/*
2272
/*
2107
    COPY A CLASS TYPE
2273
    COPY A CLASS TYPE
2108
 
2274
 
2109
    This routine creates a new class which is a copy of t.  This is used
2275
    This routine creates a new class which is a copy of t.  This is used
2110
    in the instantiation of template classes.  Note that the members of
2276
    in the instantiation of template classes.  Note that the members of
2111
    the class are copied later by copy_members.
2277
    the class are copied later by copy_members.
2112
*/
2278
*/
2113
 
2279
 
2114
TYPE copy_class
2280
TYPE
2115
    PROTO_N ( ( t, ds ) )
-
 
2116
    PROTO_T ( TYPE t X DECL_SPEC ds )
2281
copy_class(TYPE t, DECL_SPEC ds)
2117
{
2282
{
2118
    LOCATION loc ;
2283
	LOCATION loc;
2119
    IDENTIFIER tid ;
2284
	IDENTIFIER tid;
2120
    int r = really_in_class_defn ;
2285
	int r = really_in_class_defn;
2121
    int f = really_in_function_defn ;
2286
	int f = really_in_function_defn;
2122
    CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
2287
	CLASS_TYPE ct = DEREF_ctype(type_compound_defn(t));
2123
    BASE_TYPE key = find_class_key ( ct ) ;
2288
	BASE_TYPE key = find_class_key(ct);
2124
    IDENTIFIER id = DEREF_id ( ctype_name ( ct ) ) ;
2289
	IDENTIFIER id = DEREF_id(ctype_name(ct));
2125
    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
2290
	HASHID nm = DEREF_hashid(id_name(id));
2126
    NAMESPACE ns = DEREF_nspace ( id_parent ( id ) ) ;
2291
	NAMESPACE ns = DEREF_nspace(id_parent(id));
2127
    DECL_SPEC acc = DEREF_dspec ( id_storage ( id ) ) ;
2292
	DECL_SPEC acc = DEREF_dspec(id_storage(id));
2128
    ds |= ( acc & dspec_access ) ;
2293
	ds |= (acc & dspec_access);
2129
    loc = crt_loc ;
2294
	loc = crt_loc;
2130
    bad_crt_loc++ ;
2295
	bad_crt_loc++;
2131
    really_in_class_defn = 0 ;
2296
	really_in_class_defn = 0;
2132
    really_in_function_defn = 0 ;
2297
	really_in_function_defn = 0;
2133
    DEREF_loc ( id_loc ( id ), crt_loc ) ;
2298
	DEREF_loc(id_loc(id), crt_loc);
2134
    decl_loc = crt_loc ;
2299
	decl_loc = crt_loc;
2135
    tid = make_class ( ns, nm, key, ds, NULL_type, NULL_type ) ;
2300
	tid = make_class(ns, nm, key, ds, NULL_type, NULL_type);
2136
    t = DEREF_type ( id_class_name_defn ( tid ) ) ;
2301
	t = DEREF_type(id_class_name_defn(tid));
2137
    really_in_function_defn = f ;
2302
	really_in_function_defn = f;
2138
    really_in_class_defn = r ;
2303
	really_in_class_defn = r;
2139
    bad_crt_loc-- ;
2304
	bad_crt_loc--;
2140
    decl_loc = loc ;
2305
	decl_loc = loc;
2141
    crt_loc = loc ;
2306
	crt_loc = loc;
2142
    return ( t ) ;
2307
	return (t);
2143
}
2308
}
2144
 
2309
 
2145
 
2310
 
2146
/*
2311
/*
2147
    COPY A LIST OF TEMPLATE SPECIALISATIONS
2312
    COPY A LIST OF TEMPLATE SPECIALISATIONS
Line 2149... Line 2314...
2149
    This routine copies any partial or explicit specialisations of the
2314
    This routine copies any partial or explicit specialisations of the
2150
    template member tid of a template class to the corresponding member
2315
    template member tid of a template class to the corresponding member
2151
    sid of an instance of that template class.
2316
    sid of an instance of that template class.
2152
*/
2317
*/
2153
 
2318
 
2154
static void copy_specs
2319
static void
2155
    PROTO_N ( ( sid, tid, type ) )
-
 
2156
    PROTO_T ( IDENTIFIER sid X IDENTIFIER tid X int type )
2320
copy_specs(IDENTIFIER sid, IDENTIFIER tid, int type)
2157
{
2321
{
2158
    TYPE s, t ;
2322
	TYPE s, t;
2159
    if ( type ) {
2323
	if (type) {
2160
	/* Template classes */
2324
		/* Template classes */
2161
	s = DEREF_type ( id_class_name_etc_defn ( sid ) ) ;
2325
		s = DEREF_type(id_class_name_etc_defn(sid));
2162
	t = DEREF_type ( id_class_name_etc_defn ( tid ) ) ;
2326
		t = DEREF_type(id_class_name_etc_defn(tid));
2163
    } else {
2327
	} else {
2164
	/* Template functions */
2328
		/* Template functions */
2165
	s = DEREF_type ( id_function_etc_type ( sid ) ) ;
2329
		s = DEREF_type(id_function_etc_type(sid));
2166
	t = DEREF_type ( id_function_etc_type ( tid ) ) ;
2330
		t = DEREF_type(id_function_etc_type(tid));
2167
    }
2331
	}
2168
    if ( IS_type_templ ( s ) && IS_type_templ ( t ) ) {
2332
	if (IS_type_templ(s) && IS_type_templ(t)) {
2169
	TOKEN ps = DEREF_tok ( type_templ_sort ( s ) ) ;
2333
		TOKEN ps = DEREF_tok(type_templ_sort(s));
2170
	TOKEN pt = DEREF_tok ( type_templ_sort ( t ) ) ;
2334
		TOKEN pt = DEREF_tok(type_templ_sort(t));
2171
	INSTANCE as = DEREF_inst ( tok_templ_apps ( ps ) ) ;
2335
		INSTANCE as = DEREF_inst(tok_templ_apps(ps));
2172
	INSTANCE at = DEREF_inst ( tok_templ_apps ( pt ) ) ;
2336
		INSTANCE at = DEREF_inst(tok_templ_apps(pt));
2173
	while ( !IS_NULL_inst ( at ) ) {
2337
		while (!IS_NULL_inst(at)) {
2174
	    DECL_SPEC acc = DEREF_dspec ( inst_templ_access ( at ) ) ;
2338
			DECL_SPEC acc = DEREF_dspec(inst_templ_access(at));
2175
	    if ( !( acc & ( dspec_alias | dspec_main ) ) ) {
2339
			if (!(acc & (dspec_alias | dspec_main))) {
2176
		/* NOT YET IMPLEMENTED */
2340
				/* NOT YET IMPLEMENTED */
2177
	    }
2341
			}
2178
	    at = DEREF_inst ( inst_next ( at ) ) ;
2342
			at = DEREF_inst(inst_next(at));
-
 
2343
		}
-
 
2344
		COPY_inst(tok_templ_apps(ps), as);
2179
	}
2345
	}
2180
	COPY_inst ( tok_templ_apps ( ps ), as ) ;
-
 
2181
    }
-
 
2182
    return ;
2346
	return;
2183
}
2347
}
2184
 
2348
 
2185
 
2349
 
2186
/*
2350
/*
2187
    COPY A NESTED CLASS
2351
    COPY A NESTED CLASS
2188
 
2352
 
2189
    This routine copies the nested class or enumeration type tid of a
2353
    This routine copies the nested class or enumeration type tid of a
2190
    template class.
2354
    template class.
2191
*/
2355
*/
2192
 
2356
 
2193
static IDENTIFIER copy_nested
2357
static IDENTIFIER
2194
    PROTO_N ( ( tid, t, q, ploc ) )
-
 
2195
    PROTO_T ( IDENTIFIER tid X TYPE t X TYPE q X LOCATION *ploc )
2358
copy_nested(IDENTIFIER tid, TYPE t, TYPE q, LOCATION *ploc)
2196
{
2359
{
2197
    IDENTIFIER id = tid ;
2360
	IDENTIFIER id = tid;
2198
    switch ( TAG_type ( t ) ) {
2361
	switch (TAG_type(t)) {
2199
 
-
 
2200
	case type_compound_tag : {
2362
	case type_compound_tag: {
2201
	    /* Non-template classes */
2363
		/* Non-template classes */
2202
	    TYPE s ;
2364
		TYPE s;
2203
	    TYPE form ;
2365
		TYPE form;
2204
	    int def = 0 ;
2366
		int def = 0;
2205
	    DECL_SPEC ds ;
2367
		DECL_SPEC ds;
2206
	    CLASS_TYPE cs ;
2368
		CLASS_TYPE cs;
2207
	    CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
2369
		CLASS_TYPE ct = DEREF_ctype(type_compound_defn(t));
2208
	    CLASS_INFO ci = DEREF_cinfo ( ctype_info ( ct ) ) ;
2370
		CLASS_INFO ci = DEREF_cinfo(ctype_info(ct));
2209
	    BASE_TYPE key = find_class_key ( ct ) ;
2371
		BASE_TYPE key = find_class_key(ct);
2210
	    IDENTIFIER cid = DEREF_id ( ctype_name ( ct ) ) ;
2372
		IDENTIFIER cid = DEREF_id(ctype_name(ct));
2211
	    HASHID nm = DEREF_hashid ( id_name ( cid ) ) ;
2373
		HASHID nm = DEREF_hashid(id_name(cid));
2212
	    NAMESPACE ns = crt_namespace ;
2374
		NAMESPACE ns = crt_namespace;
2213
 
2375
 
2214
	    /* Declare class */
2376
		/* Declare class */
2215
	    if ( !IS_id_class_name ( tid ) ) break ;
2377
		if (!IS_id_class_name(tid)) {
-
 
2378
			break;
-
 
2379
		}
2216
	    if ( ci & cinfo_complete ) def = 1 ;
2380
		if (ci & cinfo_complete) {
-
 
2381
			def = 1;
-
 
2382
		}
2217
	    id = declare_type ( ns, nm, key, q, def, 1 ) ;
2383
		id = declare_type(ns, nm, key, q, def, 1);
2218
	    s = DEREF_type ( id_class_name_defn ( id ) ) ;
2384
		s = DEREF_type(id_class_name_defn(id));
2219
	    while ( IS_type_templ ( s ) ) {
2385
		while (IS_type_templ(s)) {
2220
		s = DEREF_type ( type_templ_defn ( s ) ) ;
2386
			s = DEREF_type(type_templ_defn(s));
2221
	    }
2387
		}
2222
	    cs = DEREF_ctype ( type_compound_defn ( s ) ) ;
2388
		cs = DEREF_ctype(type_compound_defn(s));
2223
	    ds = DEREF_dspec ( id_storage ( id ) ) ;
2389
		ds = DEREF_dspec(id_storage(id));
2224
	    ds |= dspec_instance ;
2390
		ds |= dspec_instance;
2225
	    COPY_dspec ( id_storage ( id ), ds ) ;
2391
		COPY_dspec(id_storage(id), ds);
2226
 
2392
 
2227
	    /* Set up instance type */
2393
		/* Set up instance type */
2228
	    MAKE_type_instance ( cv_none, tid, dspec_none, form ) ;
2394
		MAKE_type_instance(cv_none, tid, dspec_none, form);
2229
	    COPY_id ( type_name ( form ), id ) ;
2395
		COPY_id(type_name(form), id);
2230
	    COPY_type ( ctype_form ( cs ), form ) ;
2396
		COPY_type(ctype_form(cs), form);
-
 
2397
		if (do_dump) {
2231
	    if ( do_dump ) dump_declare ( id, ploc, 0 ) ;
2398
			dump_declare(id, ploc, 0);
-
 
2399
		}
2232
	    /* complete_class ( cs, 1 ) ; */
2400
		/* complete_class ( cs, 1 ) ; */
2233
	    break ;
2401
		break;
2234
	}
2402
	}
2235
 
-
 
2236
	case type_enumerate_tag : {
2403
	case type_enumerate_tag: {
2237
	    /* Enumeration type */
2404
		/* Enumeration type */
2238
	    TYPE form ;
2405
		TYPE form;
2239
	    DECL_SPEC ds ;
2406
		DECL_SPEC ds;
2240
	    ENUM_TYPE et = DEREF_etype ( type_enumerate_defn ( t ) ) ;
2407
		ENUM_TYPE et = DEREF_etype(type_enumerate_defn(t));
2241
	    CLASS_INFO ei = DEREF_cinfo ( etype_info ( et ) ) ;
2408
		CLASS_INFO ei = DEREF_cinfo(etype_info(et));
2242
	    TYPE s = DEREF_type ( etype_rep ( et ) ) ;
2409
		TYPE s = DEREF_type(etype_rep(et));
2243
	    IDENTIFIER eid = DEREF_id ( etype_name ( et ) ) ;
2410
		IDENTIFIER eid = DEREF_id(etype_name(et));
2244
	    HASHID nm = DEREF_hashid ( id_name ( eid ) ) ;
2411
		HASHID nm = DEREF_hashid(id_name(eid));
2245
	    NAMESPACE ns = crt_namespace ;
2412
		NAMESPACE ns = crt_namespace;
2246
 
2413
 
2247
	    /* Declare enumeration */
2414
		/* Declare enumeration */
2248
	    if ( !IS_id_enum_name ( tid ) ) break ;
2415
		if (!IS_id_enum_name(tid)) {
-
 
2416
			break;
-
 
2417
		}
2249
	    id = declare_type ( ns, nm, btype_enum, NULL_type, 1, 1 ) ;
2418
		id = declare_type(ns, nm, btype_enum, NULL_type, 1, 1);
2250
	    ds = DEREF_dspec ( id_storage ( id ) ) ;
2419
		ds = DEREF_dspec(id_storage(id));
2251
	    ds |= dspec_instance ;
2420
		ds |= dspec_instance;
2252
	    COPY_dspec ( id_storage ( id ), ds ) ;
2421
		COPY_dspec(id_storage(id), ds);
2253
	    t = DEREF_type ( id_enum_name_defn ( id ) ) ;
2422
		t = DEREF_type(id_enum_name_defn(id));
2254
	    et = DEREF_etype ( type_enumerate_defn ( t ) ) ;
2423
		et = DEREF_etype(type_enumerate_defn(t));
2255
	    COPY_cinfo ( etype_info ( et ), ei ) ;
2424
		COPY_cinfo(etype_info(et), ei);
2256
	    s = expand_type ( s, 1 ) ;
2425
		s = expand_type(s, 1);
2257
	    COPY_type ( etype_rep ( et ), s ) ;
2426
		COPY_type(etype_rep(et), s);
2258
 
2427
 
2259
	    /* Set up instance type */
2428
		/* Set up instance type */
2260
	    MAKE_type_instance ( cv_none, tid, dspec_none, form ) ;
2429
		MAKE_type_instance(cv_none, tid, dspec_none, form);
2261
	    COPY_id ( type_name ( form ), id ) ;
2430
		COPY_id(type_name(form), id);
2262
	    COPY_type ( etype_form ( et ), form ) ;
2431
		COPY_type(etype_form(et), form);
-
 
2432
		if (do_dump) {
2263
	    if ( do_dump ) dump_declare ( id, ploc, 0 ) ;
2433
			dump_declare(id, ploc, 0);
-
 
2434
		}
2264
	    break ;
2435
		break;
2265
	}
2436
	}
2266
 
-
 
2267
	case type_templ_tag : {
2437
	case type_templ_tag: {
2268
	    /* Template classes */
2438
		/* Template classes */
2269
	    TYPE s ;
2439
		TYPE s;
2270
	    TOKEN sort = DEREF_tok ( type_templ_sort ( t ) ) ;
2440
		TOKEN sort = DEREF_tok(type_templ_sort(t));
2271
	    sort = expand_templ_sort ( sort, 1 ) ;
2441
		sort = expand_templ_sort(sort, 1);
2272
	    MAKE_type_templ ( cv_none, sort, NULL_type, 0, s ) ;
2442
		MAKE_type_templ(cv_none, sort, NULL_type, 0, s);
2273
	    q = inject_pre_type ( q, s, 0 ) ;
2443
		q = inject_pre_type(q, s, 0);
2274
	    t = DEREF_type ( type_templ_defn ( t ) ) ;
2444
		t = DEREF_type(type_templ_defn(t));
2275
	    id = copy_nested ( tid, t, q, ploc ) ;
2445
		id = copy_nested(tid, t, q, ploc);
2276
	    reset_templ_sort ( sort ) ;
2446
		reset_templ_sort(sort);
2277
	    copy_specs ( id, tid, 1 ) ;
2447
		copy_specs(id, tid, 1);
2278
	    break ;
2448
		break;
2279
	}
2449
	}
2280
    }
2450
	}
2281
    return ( id ) ;
2451
	return (id);
2282
}
2452
}
2283
 
2453
 
2284
 
2454
 
2285
/*
2455
/*
2286
    COPY A MEMBER OF A CLASS
2456
    COPY A MEMBER OF A CLASS
2287
 
2457
 
2288
    This routine copies the class member id to the namespace ns, renaming
2458
    This routine copies the class member id to the namespace ns, renaming
2289
    it to nm.
2459
    it to nm.
2473
	}
2660
	}
2474
    }
-
 
2475
    return ( tid ) ;
2661
	return (tid);
2476
}
2662
}
2477
 
2663
 
2478
 
2664
 
2479
/*
2665
/*
2480
    COPY A FRIEND CLASS
2666
    COPY A FRIEND CLASS
2481
 
2667
 
2482
    This routine copies the friend class id of a template class.  This may
2668
    This routine copies the friend class id of a template class.  This may
2483
    involve name injection.
2669
    involve name injection.
2484
*/
2670
*/
2485
 
2671
 
2486
static IDENTIFIER copy_friend_class
2672
static IDENTIFIER
2487
    PROTO_N ( ( id ) )
-
 
2488
    PROTO_T ( IDENTIFIER id )
2673
copy_friend_class(IDENTIFIER id)
2489
{
2674
{
2490
    TYPE t = DEREF_type ( id_class_name_etc_defn ( id ) ) ;
2675
	TYPE t = DEREF_type(id_class_name_etc_defn(id));
2491
    TYPE s = expand_type ( t, 1 ) ;
2676
	TYPE s = expand_type(t, 1);
2492
    t = s ;
2677
	t = s;
2493
    while ( IS_type_templ ( s ) ) {
2678
	while (IS_type_templ(s)) {
2494
	s = DEREF_type ( type_templ_defn ( s ) ) ;
2679
		s = DEREF_type(type_templ_defn(s));
2495
    }
2680
	}
2496
    if ( IS_type_compound ( s ) ) {
2681
	if (IS_type_compound(s)) {
2497
	CLASS_TYPE cs = DEREF_ctype ( type_compound_defn ( s ) ) ;
2682
		CLASS_TYPE cs = DEREF_ctype(type_compound_defn(s));
2498
	TYPE form = DEREF_type ( ctype_form ( cs ) ) ;
2683
		TYPE form = DEREF_type(ctype_form(cs));
2499
	id = DEREF_id ( ctype_name ( cs ) ) ;
2684
		id = DEREF_id(ctype_name(cs));
2500
	if ( IS_NULL_type ( form ) ) {
2685
		if (IS_NULL_type(form)) {
2501
	    /* Allow for name injection */
2686
			/* Allow for name injection */
2502
	    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
2687
			HASHID nm = DEREF_hashid(id_name(id));
2503
	    NAMESPACE ns = DEREF_nspace ( id_parent ( id ) ) ;
2688
			NAMESPACE ns = DEREF_nspace(id_parent(id));
2504
	    MEMBER mem = search_member ( ns, nm, 1 ) ;
2689
			MEMBER mem = search_member(ns, nm, 1);
2505
	    TYPE q = extract_templ_qual ( t ) ;
2690
			TYPE q = extract_templ_qual(t);
2506
	    BASE_TYPE key = find_key ( id, 1, btype_none ) ;
2691
			BASE_TYPE key = find_key(id, 1, btype_none);
2507
	    IDENTIFIER tid = declare_type ( ns, nm, key, q, 0, 0 ) ;
2692
			IDENTIFIER tid = declare_type(ns, nm, key, q, 0, 0);
2508
	    IGNORE inject_pre_type ( q, t, 0 ) ;
2693
			IGNORE inject_pre_type(q, t, 0);
2509
	    if ( !IS_NULL_id ( tid ) && IS_id_class_name ( tid ) ) {
2694
			if (!IS_NULL_id(tid) && IS_id_class_name(tid)) {
2510
		/* Allow for redeclarations */
2695
				/* Allow for redeclarations */
2511
		if ( !EQ_id ( tid, id ) ) {
2696
				if (!EQ_id(tid, id)) {
-
 
2697
					IDENTIFIER pid =
2512
		    IDENTIFIER pid = DEREF_id ( id_alias ( tid ) ) ;
2698
					    DEREF_id(id_alias(tid));
-
 
2699
					DECL_SPEC ds =
2513
		    DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
2700
					    DEREF_dspec(id_storage(id));
2514
		    ds |= dspec_alias ;
2701
					ds |= dspec_alias;
2515
		    COPY_dspec ( id_storage ( id ), ds ) ;
2702
					COPY_dspec(id_storage(id), ds);
2516
		    COPY_id ( id_alias ( id ), pid ) ;
2703
					COPY_id(id_alias(id), pid);
2517
		    t = DEREF_type ( id_class_name_defn ( tid ) ) ;
2704
					t = DEREF_type(id_class_name_defn(tid));
2518
		    COPY_type ( ctype_form ( cs ), t ) ;
2705
					COPY_type(ctype_form(cs), t);
2519
		    id = tid ;
2706
					id = tid;
-
 
2707
				}
-
 
2708
			}
-
 
2709
			if (!in_template_decl) {
-
 
2710
				set_type_member(mem, id);
-
 
2711
			}
2520
		}
2712
		}
2521
	    }
-
 
2522
	    if ( !in_template_decl ) set_type_member ( mem, id ) ;
-
 
2523
	}
2713
	}
2524
    }
-
 
2525
    return ( id ) ;
2714
	return (id);
2526
}
2715
}
2527
 
2716
 
2528
 
2717
 
2529
/*
2718
/*
2530
    COPY A FRIEND FUNCTION
2719
    COPY A FRIEND FUNCTION
2531
 
2720
 
2532
    This routine copies the friend function id of a template class.  This
2721
    This routine copies the friend function id of a template class.  This
2533
    may involve name injection.
2722
    may involve name injection.
2534
*/
2723
*/
2535
 
2724
 
2536
static IDENTIFIER copy_friend_func
2725
static IDENTIFIER
2537
    PROTO_N ( ( id ) )
-
 
2538
    PROTO_T ( IDENTIFIER id )
2726
copy_friend_func(IDENTIFIER id)
2539
{
2727
{
2540
    TYPE form ;
2728
	TYPE form;
2541
    MEMBER mem ;
2729
	MEMBER mem;
2542
    DECL_SPEC ds ;
2730
	DECL_SPEC ds;
2543
    IDENTIFIER fid ;
2731
	IDENTIFIER fid;
2544
    int changed = 0 ;
2732
	int changed = 0;
2545
    IDENTIFIER over = NULL_id ;
2733
	IDENTIFIER over = NULL_id;
2546
    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
2734
	HASHID nm = DEREF_hashid(id_name(id));
2547
    NAMESPACE ns = DEREF_nspace ( id_parent ( id ) ) ;
2735
	NAMESPACE ns = DEREF_nspace(id_parent(id));
2548
    HASHID nm1 = expand_name ( nm, NULL_ctype ) ;
2736
	HASHID nm1 = expand_name(nm, NULL_ctype);
2549
    NAMESPACE ns1 = rescan_nspace ( ns ) ;
2737
	NAMESPACE ns1 = rescan_nspace(ns);
2550
    TYPE t = DEREF_type ( id_function_etc_type ( id ) ) ;
2738
	TYPE t = DEREF_type(id_function_etc_type(id));
2551
    if ( !IS_type_templ ( t ) ) {
2739
	if (!IS_type_templ(t)) {
2552
	TYPE t1 = expand_type ( t, 1 ) ;
2740
		TYPE t1 = expand_type(t, 1);
2553
	if ( !EQ_type ( t1, t ) ) {
2741
		if (!EQ_type(t1, t)) {
2554
	    changed = 1 ;
2742
			changed = 1;
2555
	    t = t1 ;
2743
			t = t1;
2556
	}
2744
		}
2557
    }
2745
	}
2558
    if ( !EQ_hashid ( nm1, nm ) ) {
2746
	if (!EQ_hashid(nm1, nm)) {
2559
	changed = 1 ;
2747
		changed = 1;
2560
	nm = nm1 ;
2748
		nm = nm1;
2561
    }
2749
	}
2562
    if ( !EQ_nspace ( ns1, ns ) ) {
2750
	if (!EQ_nspace(ns1, ns)) {
2563
	changed = 1 ;
2751
		changed = 1;
2564
	ns = ns1 ;
2752
		ns = ns1;
2565
    }
2753
	}
2566
    if ( changed ) {
2754
	if (changed) {
2567
	/* Copy identifier if necessary */
2755
		/* Copy identifier if necessary */
2568
	id = copy_id ( id, 2 ) ;
2756
		id = copy_id(id, 2);
2569
	COPY_nspace ( id_parent ( id ), ns ) ;
2757
		COPY_nspace(id_parent(id), ns);
2570
	COPY_hashid ( id_name ( id ), nm ) ;
2758
		COPY_hashid(id_name(id), nm);
2571
    }
2759
	}
2572
 
2760
 
2573
    /* Check for template functions */
2761
	/* Check for template functions */
2574
    form = DEREF_type ( id_function_etc_form ( id ) ) ;
2762
	form = DEREF_type(id_function_etc_form(id));
2575
    if ( !IS_NULL_type ( form ) && IS_type_token ( form ) ) {
2763
	if (!IS_NULL_type(form) && IS_type_token(form)) {
2576
	IDENTIFIER tid = DEREF_id ( type_token_tok ( form ) ) ;
2764
		IDENTIFIER tid = DEREF_id(type_token_tok(form));
2577
	if ( IS_id_function_etc ( tid ) ) {
2765
		if (IS_id_function_etc(tid)) {
2578
	    /* Template function instance */
2766
			/* Template function instance */
2579
	    TYPE t1 = DEREF_type ( id_function_etc_type ( tid ) ) ;
2767
			TYPE t1 = DEREF_type(id_function_etc_type(tid));
2580
	    t = injected_type ( t, 1 ) ;
2768
			t = injected_type(t, 1);
2581
	    if ( eq_type ( t1, t ) == 1 ) {
2769
			if (eq_type(t1, t) == 1) {
2582
		/* Allow for redeclarations */
2770
				/* Allow for redeclarations */
2583
		id = tid ;
2771
				id = tid;
2584
	    } else {
2772
			} else {
2585
		LIST ( TOKEN ) args ;
2773
				LIST(TOKEN)args;
2586
		args = DEREF_list ( type_token_args ( form ) ) ;
2774
				args = DEREF_list(type_token_args(form));
2587
		tid = copy_friend_func ( tid ) ;
2775
				tid = copy_friend_func(tid);
-
 
2776
				if (do_dump) {
2588
		if ( do_dump ) dump_declare ( tid, &crt_loc, 0 ) ;
2777
					dump_declare(tid, &crt_loc, 0);
-
 
2778
				}
2589
		args = expand_args ( args, 1, 1 ) ;
2779
				args = expand_args(args, 1, 1);
2590
		id = instance_func ( tid, args, 0, 0 ) ;
2780
				id = instance_func(tid, args, 0, 0);
2591
		return ( id ) ;
2781
				return (id);
2592
	    }
2782
			}
2593
	}
2783
		}
2594
    }
2784
	}
2595
 
2785
 
2596
    /* Look up matching declaration */
2786
	/* Look up matching declaration */
2597
    ds = DEREF_dspec ( id_storage ( id ) ) ;
2787
	ds = DEREF_dspec(id_storage(id));
2598
    mem = search_member ( ns, nm, 1 ) ;
2788
	mem = search_member(ns, nm, 1);
2599
    fid = DEREF_id ( member_id ( mem ) ) ;
2789
	fid = DEREF_id(member_id(mem));
2600
    if ( !IS_NULL_id ( fid ) ) {
2790
	if (!IS_NULL_id(fid)) {
2601
	unsigned tag = TAG_id ( id ) ;
2791
		unsigned tag = TAG_id(id);
2602
	DECL_SPEC cl = crt_linkage ;
2792
		DECL_SPEC cl = crt_linkage;
2603
	QUALIFIER cq = crt_id_qualifier ;
2793
		QUALIFIER cq = crt_id_qualifier;
2604
	crt_id_qualifier = qual_nested ;
2794
		crt_id_qualifier = qual_nested;
2605
	crt_linkage = ( ds & dspec_language ) ;
2795
		crt_linkage = (ds & dspec_language);
2606
	ds &= ~dspec_alias ;
2796
		ds &= ~dspec_alias;
2607
	fid = redecl_func ( ds, t, fid, tag, &over, -2 ) ;
2797
		fid = redecl_func(ds, t, fid, tag, &over, -2);
2608
	crt_id_qualifier = cq ;
2798
		crt_id_qualifier = cq;
2609
	crt_linkage = cl ;
2799
		crt_linkage = cl;
2610
    }
2800
	}
2611
    if ( IS_NULL_id ( fid ) ) {
2801
	if (IS_NULL_id(fid)) {
2612
	/* Allow for name injection */
2802
		/* Allow for name injection */
2613
	if ( IS_nspace_ctype ( ns ) ) {
2803
		if (IS_nspace_ctype(ns)) {
2614
	    report ( crt_loc, ERR_basic_link_unmatch ( t, id ) ) ;
2804
			report(crt_loc, ERR_basic_link_unmatch(t, id));
-
 
2805
		} else {
-
 
2806
			COPY_id(id_function_etc_over(id), over);
-
 
2807
			COPY_exp(id_function_etc_defn(id), NULL_exp);
-
 
2808
			if (!in_template_decl) {
-
 
2809
				set_member(mem, id);
-
 
2810
			}
-
 
2811
		}
2615
	} else {
2812
	} else {
-
 
2813
		/* Set up function alias */
-
 
2814
		if (!EQ_id(fid, id)) {
2616
	    COPY_id ( id_function_etc_over ( id ), over ) ;
2815
			IDENTIFIER pid = DEREF_id(id_alias(fid));
-
 
2816
			ds |= dspec_alias;
2617
	    COPY_exp ( id_function_etc_defn ( id ), NULL_exp ) ;
2817
			COPY_dspec(id_storage(id), ds);
2618
	    if ( !in_template_decl ) set_member ( mem, id ) ;
2818
			COPY_id(id_alias(id), pid);
-
 
2819
			id = fid;
-
 
2820
		}
2619
	}
2821
	}
2620
    } else {
-
 
2621
	/* Set up function alias */
-
 
2622
	if ( !EQ_id ( fid, id ) ) {
-
 
2623
	    IDENTIFIER pid = DEREF_id ( id_alias ( fid ) ) ;
-
 
2624
	    ds |= dspec_alias ;
-
 
2625
	    COPY_dspec ( id_storage ( id ), ds ) ;
-
 
2626
	    COPY_id ( id_alias ( id ), pid ) ;
-
 
2627
	    id = fid ;
-
 
2628
	}
-
 
2629
    }
-
 
2630
    return ( id ) ;
2822
	return (id);
2631
}
2823
}
2632
 
2824
 
2633
 
2825
 
2634
/*
2826
/*
2635
    COPY THE MEMBERS OF A CLASS
2827
    COPY THE MEMBERS OF A CLASS
2636
 
2828
 
2637
    This routine copies the members of the class cs to the class ct.
2829
    This routine copies the members of the class cs to the class ct.
2638
    Note that this is done only if cs has been completely defined,
2830
    Note that this is done only if cs has been completely defined,
2639
    partially defined classes are not copied.
2831
    partially defined classes are not copied.
2640
*/
2832
*/
2641
 
2833
 
2642
void copy_members
2834
void
2643
    PROTO_N ( ( ct, cs, ci, def ) )
-
 
2644
    PROTO_T ( CLASS_TYPE ct X CLASS_TYPE cs X CLASS_INFO ci X int def )
2835
copy_members(CLASS_TYPE ct, CLASS_TYPE cs, CLASS_INFO ci, int def)
2645
{
2836
{
2646
    CLASS_INFO ck = DEREF_cinfo ( ctype_info ( cs ) ) ;
2837
	CLASS_INFO ck = DEREF_cinfo(ctype_info(cs));
2647
    CLASS_INFO cj = DEREF_cinfo ( ctype_info ( ct ) ) ;
2838
	CLASS_INFO cj = DEREF_cinfo(ctype_info(ct));
2648
    if ( !( ck & cinfo_complete ) ) def = 0 ;
2839
	if (!(ck & cinfo_complete)) {
2649
    if ( ck & cinfo_recursive ) cj |= cinfo_recursive ;
-
 
2650
    cj |= ci ;
-
 
2651
    COPY_cinfo ( ctype_info ( ct ), cj ) ;
-
 
2652
    if ( def && !( cj & cinfo_defined ) ) {
-
 
2653
	int ic ;
-
 
2654
	GRAPH gr ;
-
 
2655
	MEMBER mem ;
-
 
2656
	DECL_SPEC ds ;
-
 
2657
	LOCATION loc ;
-
 
2658
	IDENTIFIER cid ;
-
 
2659
	DECL_SPEC pacc ;
-
 
2660
	ACCESS_LIST accs ;
-
 
2661
	LIST ( GRAPH ) br ;
-
 
2662
	LIST ( IDENTIFIER ) fr ;
-
 
2663
	LIST ( CLASS_TYPE ) fc ;
-
 
2664
	int lex = crt_lex_token ;
-
 
2665
	int fn = in_function_defn ;
-
 
2666
	int rfn = really_in_function_defn ;
-
 
2667
	NAMESPACE nt = DEREF_nspace ( ctype_member ( ct ) ) ;
-
 
2668
	NAMESPACE ns = DEREF_nspace ( ctype_member ( cs ) ) ;
-
 
2669
 
-
 
2670
	/* Save class information */
-
 
2671
	loc = crt_loc ;
-
 
2672
	bad_crt_loc++ ;
-
 
2673
	ic = in_class_defn ;
-
 
2674
	push_class ( ct ) ;
-
 
2675
	push_namespace ( nt ) ;
-
 
2676
	in_class_defn = 1 ;
-
 
2677
	in_function_defn = 0 ;
-
 
2678
	really_in_class_defn++ ;
-
 
2679
	really_in_function_defn = 0 ;
-
 
2680
	crt_lex_token = lex_ignore_token ;
-
 
2681
	save_access ( &accs ) ;
-
 
2682
	cid = DEREF_id ( ctype_name ( ct ) ) ;
-
 
2683
	DEREF_loc ( id_loc ( cid ), crt_loc ) ;
-
 
2684
	ds = DEREF_dspec ( id_storage ( cid ) ) ;
-
 
2685
	ds |= dspec_defn ;
-
 
2686
	COPY_dspec ( id_storage ( cid ), ds ) ;
-
 
2687
	cj |= ( cinfo_complete | cinfo_defined ) ;
-
 
2688
	COPY_cinfo ( ctype_info ( ct ), cj ) ;
-
 
2689
	if ( do_dump ) dump_declare ( cid, &loc, 1 ) ;
-
 
2690
 
-
 
2691
	/* Copy base classes */
-
 
2692
	pacc = prev_access ;
-
 
2693
	gr = DEREF_graph ( ctype_base ( cs ) ) ;
-
 
2694
	br = DEREF_list ( graph_tails ( gr ) ) ;
-
 
2695
	while ( !IS_NULL_list ( br ) ) {
-
 
2696
	    int virt = 0 ;
-
 
2697
	    GRAPH gu = DEREF_graph ( HEAD_list ( br ) ) ;
-
 
2698
	    CLASS_TYPE cu = DEREF_ctype ( graph_head ( gu ) ) ;
-
 
2699
	    DECL_SPEC acc = DEREF_dspec ( graph_access ( gu ) ) ;
-
 
2700
	    cid = DEREF_id ( ctype_name ( cu ) ) ;
-
 
2701
	    if ( acc & dspec_virtual ) virt = 1 ;
-
 
2702
	    acc &= dspec_access ;
-
 
2703
	    add_base_class ( cid, acc, virt ) ;
-
 
2704
	    br = TAIL_list ( br ) ;
-
 
2705
	}
-
 
2706
	end_base_class ( ct, 1 ) ;
-
 
2707
	prev_access = pacc ;
-
 
2708
 
-
 
2709
	/* Copy nested classes */
-
 
2710
	fr = DEREF_list ( ctype_nest ( cs ) ) ;
-
 
2711
	while ( !IS_NULL_list ( fr ) ) {
-
 
2712
	    IDENTIFIER fid = DEREF_id ( HEAD_list ( fr ) ) ;
-
 
2713
	    if ( IS_id_class_name_etc ( fid ) ) {
-
 
2714
		DECL_SPEC fds = DEREF_dspec ( id_storage ( fid ) ) ;
-
 
2715
		if ( !( fds & dspec_instance ) ) {
-
 
2716
		    TYPE f ;
-
 
2717
		    DEREF_loc ( id_loc ( fid ), crt_loc ) ;
-
 
2718
		    pacc = crt_access ;
-
 
2719
		    crt_access = ( fds & dspec_access ) ;
-
 
2720
		    f = DEREF_type ( id_class_name_etc_defn ( fid ) ) ;
-
 
2721
		    IGNORE copy_nested ( fid, f, NULL_type, &loc ) ;
-
 
2722
		    crt_access = pacc ;
-
 
2723
		}
-
 
2724
	    }
-
 
2725
	    fr = TAIL_list ( fr ) ;
-
 
2726
	}
-
 
2727
 
-
 
2728
	/* Copy class members */
-
 
2729
	mem = DEREF_member ( nspace_ctype_first ( ns ) ) ;
-
 
2730
	while ( !IS_NULL_member ( mem ) ) {
-
 
2731
	    HASHID tnm = NULL_hashid ;
-
 
2732
	    MEMBER tmem = NULL_member ;
-
 
2733
	    IDENTIFIER id = DEREF_id ( member_id ( mem ) ) ;
-
 
2734
	    IDENTIFIER alt = DEREF_id ( member_alt ( mem ) ) ;
-
 
2735
	    if ( !IS_NULL_id ( id ) ) {
-
 
2736
		IDENTIFIER tid ;
-
 
2737
		HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
-
 
2738
		DEREF_loc ( id_loc ( id ), crt_loc ) ;
-
 
2739
		tnm = expand_name ( nm, ct ) ;
-
 
2740
		tmem = search_member ( nt, tnm, 1 ) ;
-
 
2741
		tid = copy_member ( id, tnm, nt, ct, &loc ) ;
-
 
2742
		if ( !IS_NULL_id ( tid ) ) {
-
 
2743
		    set_member ( tmem, tid ) ;
-
 
2744
		}
-
 
2745
	    }
-
 
2746
	    if ( !IS_NULL_id ( alt ) && !EQ_id ( id, alt ) ) {
-
 
2747
		IDENTIFIER talt ;
-
 
2748
		DEREF_loc ( id_loc ( alt ), crt_loc ) ;
-
 
2749
		if ( IS_NULL_member ( tmem ) ) {
-
 
2750
		    HASHID nm = DEREF_hashid ( id_name ( alt ) ) ;
-
 
2751
		    tnm = expand_name ( nm, ct ) ;
-
 
2752
		    tmem = search_member ( nt, tnm, 1 ) ;
-
 
2753
		}
-
 
2754
		talt = copy_member ( alt, tnm, nt, ct, &loc ) ;
-
 
2755
		if ( !IS_NULL_id ( talt ) ) {
-
 
2756
		    set_type_member ( tmem, talt ) ;
-
 
2757
		}
-
 
2758
	    }
-
 
2759
	    mem = DEREF_member ( member_next ( mem ) ) ;
-
 
2760
	}
-
 
2761
 
-
 
2762
	/* Copy chums */
-
 
2763
	fc = DEREF_list ( ctype_chums ( cs ) ) ;
-
 
2764
	while ( !IS_NULL_list ( fc ) ) {
-
 
2765
	    TYPE r = NULL_type ;
-
 
2766
	    CLASS_TYPE cr = DEREF_ctype ( HEAD_list ( fc ) ) ;
-
 
2767
	    cr = expand_ctype ( cr, 2, &r ) ;
-
 
2768
	    friend_class ( cr, cid, 0 ) ;
-
 
2769
	    fc = TAIL_list ( fc ) ;
-
 
2770
	}
-
 
2771
 
-
 
2772
	/* Copy pals */
-
 
2773
	fr = DEREF_list ( ctype_pals ( cs ) ) ;
-
 
2774
	if ( !IS_NULL_list ( fr ) ) {
-
 
2775
	    while ( !IS_NULL_list ( fr ) ) {
-
 
2776
		IDENTIFIER fid = DEREF_id ( HEAD_list ( fr ) ) ;
-
 
2777
		DEREF_loc ( id_loc ( fid ), decl_loc ) ;
-
 
2778
		DEREF_loc ( id_loc ( fid ), crt_loc ) ;
-
 
2779
		if ( IS_id_class_name ( fid ) ) {
-
 
2780
		    fid = copy_friend_class ( fid ) ;
-
 
2781
		    friend_class ( ct, fid, 0 ) ;
-
 
2782
		} else {
-
 
2783
		    EXP e = DEREF_exp ( id_function_etc_defn ( fid ) ) ;
-
 
2784
		    fid = copy_friend_func ( fid ) ;
-
 
2785
		    friend_function ( ct, fid, 0 ) ;
-
 
2786
		    if ( !IS_NULL_exp ( e ) && !IS_exp_value ( e ) ) {
-
 
2787
			copy_object ( fid, e ) ;
-
 
2788
		    }
2840
		def = 0;
2789
		}
-
 
2790
		if ( do_dump ) dump_declare ( fid, &crt_loc, 0 ) ;
-
 
2791
		fr = TAIL_list ( fr ) ;
-
 
2792
	    }
-
 
2793
	    fr = DEREF_list ( ctype_pals ( ct ) ) ;
-
 
2794
	    fr = REVERSE_list ( fr ) ;
-
 
2795
	    COPY_list ( ctype_pals ( ct ), fr ) ;
-
 
2796
	}
2841
	}
-
 
2842
	if (ck & cinfo_recursive) {
-
 
2843
		cj |= cinfo_recursive;
-
 
2844
	}
-
 
2845
	cj |= ci;
-
 
2846
	COPY_cinfo(ctype_info(ct), cj);
-
 
2847
	if (def && !(cj & cinfo_defined)) {
-
 
2848
		int ic;
-
 
2849
		GRAPH gr;
-
 
2850
		MEMBER mem;
-
 
2851
		DECL_SPEC ds;
-
 
2852
		LOCATION loc;
-
 
2853
		IDENTIFIER cid;
-
 
2854
		DECL_SPEC pacc;
-
 
2855
		ACCESS_LIST accs;
-
 
2856
		LIST(GRAPH)br;
-
 
2857
		LIST(IDENTIFIER)fr;
-
 
2858
		LIST(CLASS_TYPE)fc;
-
 
2859
		int lex = crt_lex_token;
-
 
2860
		int fn = in_function_defn;
-
 
2861
		int rfn = really_in_function_defn;
-
 
2862
		NAMESPACE nt = DEREF_nspace(ctype_member(ct));
-
 
2863
		NAMESPACE ns = DEREF_nspace(ctype_member(cs));
2797
 
2864
 
-
 
2865
		/* Save class information */
-
 
2866
		loc = crt_loc;
-
 
2867
		bad_crt_loc++;
-
 
2868
		ic = in_class_defn;
-
 
2869
		push_class(ct);
-
 
2870
		push_namespace(nt);
-
 
2871
		in_class_defn = 1;
-
 
2872
		in_function_defn = 0;
-
 
2873
		really_in_class_defn++;
-
 
2874
		really_in_function_defn = 0;
-
 
2875
		crt_lex_token = lex_ignore_token;
-
 
2876
		save_access(&accs);
-
 
2877
		cid = DEREF_id(ctype_name(ct));
-
 
2878
		DEREF_loc(id_loc(cid), crt_loc);
-
 
2879
		ds = DEREF_dspec(id_storage(cid));
-
 
2880
		ds |= dspec_defn;
-
 
2881
		COPY_dspec(id_storage(cid), ds);
-
 
2882
		cj |= (cinfo_complete | cinfo_defined);
-
 
2883
		COPY_cinfo(ctype_info(ct), cj);
-
 
2884
		if (do_dump) {
-
 
2885
			dump_declare(cid, &loc, 1);
-
 
2886
		}
-
 
2887
 
-
 
2888
		/* Copy base classes */
-
 
2889
		pacc = prev_access;
-
 
2890
		gr = DEREF_graph(ctype_base(cs));
-
 
2891
		br = DEREF_list(graph_tails(gr));
-
 
2892
		while (!IS_NULL_list(br)) {
-
 
2893
			int virt = 0;
-
 
2894
			GRAPH gu = DEREF_graph(HEAD_list(br));
-
 
2895
			CLASS_TYPE cu = DEREF_ctype(graph_head(gu));
-
 
2896
			DECL_SPEC acc = DEREF_dspec(graph_access(gu));
-
 
2897
			cid = DEREF_id(ctype_name(cu));
-
 
2898
			if (acc & dspec_virtual) {
-
 
2899
				virt = 1;
-
 
2900
			}
-
 
2901
			acc &= dspec_access;
-
 
2902
			add_base_class(cid, acc, virt);
-
 
2903
			br = TAIL_list(br);
-
 
2904
		}
-
 
2905
		end_base_class(ct, 1);
-
 
2906
		prev_access = pacc;
-
 
2907
 
-
 
2908
		/* Copy nested classes */
-
 
2909
		fr = DEREF_list(ctype_nest(cs));
-
 
2910
		while (!IS_NULL_list(fr)) {
-
 
2911
			IDENTIFIER fid = DEREF_id(HEAD_list(fr));
-
 
2912
			if (IS_id_class_name_etc(fid)) {
-
 
2913
				DECL_SPEC fds = DEREF_dspec(id_storage(fid));
-
 
2914
				if (!(fds & dspec_instance)) {
-
 
2915
					TYPE f;
-
 
2916
					DEREF_loc(id_loc(fid), crt_loc);
-
 
2917
					pacc = crt_access;
-
 
2918
					crt_access = (fds & dspec_access);
-
 
2919
					f = DEREF_type(id_class_name_etc_defn(fid));
-
 
2920
					IGNORE copy_nested(fid, f, NULL_type, &loc);
-
 
2921
					crt_access = pacc;
-
 
2922
				}
-
 
2923
			}
-
 
2924
			fr = TAIL_list(fr);
-
 
2925
		}
-
 
2926
 
-
 
2927
		/* Copy class members */
-
 
2928
		mem = DEREF_member(nspace_ctype_first(ns));
-
 
2929
		while (!IS_NULL_member(mem)) {
-
 
2930
			HASHID tnm = NULL_hashid;
-
 
2931
			MEMBER tmem = NULL_member;
-
 
2932
			IDENTIFIER id = DEREF_id(member_id(mem));
-
 
2933
			IDENTIFIER alt = DEREF_id(member_alt(mem));
-
 
2934
			if (!IS_NULL_id(id)) {
-
 
2935
				IDENTIFIER tid;
-
 
2936
				HASHID nm = DEREF_hashid(id_name(id));
-
 
2937
				DEREF_loc(id_loc(id), crt_loc);
-
 
2938
				tnm = expand_name(nm, ct);
-
 
2939
				tmem = search_member(nt, tnm, 1);
-
 
2940
				tid = copy_member(id, tnm, nt, ct, &loc);
-
 
2941
				if (!IS_NULL_id(tid)) {
-
 
2942
					set_member(tmem, tid);
-
 
2943
				}
-
 
2944
			}
-
 
2945
			if (!IS_NULL_id(alt) && !EQ_id(id, alt)) {
-
 
2946
				IDENTIFIER talt;
-
 
2947
				DEREF_loc(id_loc(alt), crt_loc);
-
 
2948
				if (IS_NULL_member(tmem)) {
-
 
2949
					HASHID nm = DEREF_hashid(id_name(alt));
-
 
2950
					tnm = expand_name(nm, ct);
-
 
2951
					tmem = search_member(nt, tnm, 1);
-
 
2952
				}
-
 
2953
				talt = copy_member(alt, tnm, nt, ct, &loc);
-
 
2954
				if (!IS_NULL_id(talt)) {
-
 
2955
					set_type_member(tmem, talt);
-
 
2956
				}
-
 
2957
			}
-
 
2958
			mem = DEREF_member(member_next(mem));
-
 
2959
		}
-
 
2960
 
-
 
2961
		/* Copy chums */
-
 
2962
		fc = DEREF_list(ctype_chums(cs));
-
 
2963
		while (!IS_NULL_list(fc)) {
-
 
2964
			TYPE r = NULL_type;
-
 
2965
			CLASS_TYPE cr = DEREF_ctype(HEAD_list(fc));
-
 
2966
			cr = expand_ctype(cr, 2, &r);
-
 
2967
			friend_class(cr, cid, 0);
-
 
2968
			fc = TAIL_list(fc);
-
 
2969
		}
-
 
2970
 
-
 
2971
		/* Copy pals */
-
 
2972
		fr = DEREF_list(ctype_pals(cs));
-
 
2973
		if (!IS_NULL_list(fr)) {
-
 
2974
			while (!IS_NULL_list(fr)) {
-
 
2975
				IDENTIFIER fid = DEREF_id(HEAD_list(fr));
-
 
2976
				DEREF_loc(id_loc(fid), decl_loc);
-
 
2977
				DEREF_loc(id_loc(fid), crt_loc);
-
 
2978
				if (IS_id_class_name(fid)) {
-
 
2979
					fid = copy_friend_class(fid);
-
 
2980
					friend_class(ct, fid, 0);
-
 
2981
				} else {
-
 
2982
					EXP e = DEREF_exp(id_function_etc_defn(fid));
-
 
2983
					fid = copy_friend_func(fid);
-
 
2984
					friend_function(ct, fid, 0);
-
 
2985
					if (!IS_NULL_exp(e) &&
-
 
2986
					    !IS_exp_value(e)) {
-
 
2987
						copy_object(fid, e);
-
 
2988
					}
-
 
2989
				}
-
 
2990
				if (do_dump) {
-
 
2991
					dump_declare(fid, &crt_loc, 0);
-
 
2992
				}
-
 
2993
				fr = TAIL_list(fr);
-
 
2994
			}
-
 
2995
			fr = DEREF_list(ctype_pals(ct));
-
 
2996
			fr = REVERSE_list(fr);
-
 
2997
			COPY_list(ctype_pals(ct), fr);
-
 
2998
		}
-
 
2999
 
2798
	/* Update class information */
3000
		/* Update class information */
2799
	cj = DEREF_cinfo ( ctype_info ( ct ) ) ;
3001
		cj = DEREF_cinfo(ctype_info(ct));
2800
#if LANGUAGE_CPP
3002
#if LANGUAGE_CPP
2801
	cj = implicit_decl ( ct, cj, dspec_instance ) ;
3003
		cj = implicit_decl(ct, cj, dspec_instance);
2802
#endif
3004
#endif
2803
	if ( cj & cinfo_non_aggregate ) {
3005
		if (cj & cinfo_non_aggregate) {
2804
	    /* POD classes must be aggregate classes */
3006
			/* POD classes must be aggregate classes */
2805
	    cj &= ~cinfo_pod ;
3007
			cj &= ~cinfo_pod;
-
 
3008
		}
-
 
3009
		cj |= cinfo_complete;
-
 
3010
		COPY_cinfo(ctype_info(ct), cj);
-
 
3011
		inherit_class();
-
 
3012
		IGNORE restore_access(cid, &accs);
-
 
3013
		in_class_defn = ic;
-
 
3014
		really_in_class_defn--;
-
 
3015
		really_in_function_defn = rfn;
-
 
3016
		in_function_defn = fn;
-
 
3017
		crt_lex_token = lex;
-
 
3018
		IGNORE pop_namespace();
-
 
3019
		pop_class();
-
 
3020
		decl_loc = loc;
-
 
3021
		crt_loc = loc;
-
 
3022
		bad_crt_loc--;
2806
	}
3023
	}
2807
	cj |= cinfo_complete ;
-
 
2808
	COPY_cinfo ( ctype_info ( ct ), cj ) ;
-
 
2809
	inherit_class () ;
-
 
2810
	IGNORE restore_access ( cid, &accs ) ;
-
 
2811
	in_class_defn = ic ;
-
 
2812
	really_in_class_defn-- ;
-
 
2813
	really_in_function_defn = rfn ;
-
 
2814
	in_function_defn = fn ;
-
 
2815
	crt_lex_token = lex ;
-
 
2816
	IGNORE pop_namespace () ;
-
 
2817
	pop_class () ;
-
 
2818
	decl_loc = loc ;
-
 
2819
	crt_loc = loc ;
-
 
2820
	bad_crt_loc-- ;
-
 
2821
    }
-
 
2822
    return ;
3024
	return;
2823
}
3025
}