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

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

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

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

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

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

Subversion Repositories tendra.SVN

Rev

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

Rev 5 Rev 6
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2006 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
32
    		 Crown Copyright (c) 1997
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
Line 79... Line 109...
79
    The current linkage specifier is handled by means of this global
109
    The current linkage specifier is handled by means of this global
80
    variable.  The default, of no linkage being given, is interpreted
110
    variable.  The default, of no linkage being given, is interpreted
81
    according to the source language.
111
    according to the source language.
82
*/
112
*/
83
 
113
 
84
DECL_SPEC crt_linkage = dspec_none ;
114
DECL_SPEC crt_linkage = dspec_none;
85
DECL_SPEC new_linkage = dspec_none ;
115
DECL_SPEC new_linkage = dspec_none;
86
 
116
 
87
 
117
 
88
/*
118
/*
89
    FIND A LINKAGE SPECIFIER
119
    FIND A LINKAGE SPECIFIER
90
 
120
 
91
    This routine translates the string literal expression e into a linkage
121
    This routine translates the string literal expression e into a linkage
92
    specifier.  The only recognised strings are "C" and "C++".
122
    specifier.  The only recognised strings are "C" and "C++".
93
*/
123
*/
94
 
124
 
95
DECL_SPEC find_linkage
125
DECL_SPEC
96
    PROTO_N ( ( e ) )
-
 
97
    PROTO_T ( EXP e )
126
find_linkage(EXP e)
98
{
127
{
99
    STRING s = DEREF_str ( exp_string_lit_str ( e ) ) ;
128
	STRING s = DEREF_str(exp_string_lit_str(e));
100
    unsigned kind = DEREF_unsigned ( str_simple_kind ( s ) ) ;
129
	unsigned kind = DEREF_unsigned(str_simple_kind(s));
101
 
130
 
102
    /* Can only occur in namespace scope */
131
	/* Can only occur in namespace scope */
103
    if ( in_function_defn || in_class_defn ) {
132
	if (in_function_defn || in_class_defn) {
104
	report ( crt_loc, ERR_dcl_link_scope () ) ;
133
		report(crt_loc, ERR_dcl_link_scope());
105
    }
134
	}
106
 
135
 
107
    /* Check the linkage string */
136
	/* Check the linkage string */
108
    if ( kind == STRING_NONE ) {
137
	if (kind == STRING_NONE) {
109
	char *t = strlit ( DEREF_string ( str_simple_text ( s ) ) ) ;
138
		char *t = strlit(DEREF_string(str_simple_text(s)));
110
	unsigned long len = DEREF_ulong ( str_simple_len ( s ) ) ;
139
		unsigned long len = DEREF_ulong(str_simple_len(s));
111
	if ( len == 1 && streq ( t, "C" ) ) {
140
		if (len == 1 && streq(t, "C")) {
112
	    return ( dspec_c ) ;
141
			return (dspec_c);
113
	}
142
		}
114
	if ( len == 3 && streq ( t, "C++" ) ) {
143
		if (len == 3 && streq(t, "C++")) {
115
	    return ( dspec_cpp ) ;
144
			return (dspec_cpp);
116
	}
145
		}
117
    }
146
	}
118
 
147
 
119
    /* Report unknown strings */
148
	/* Report unknown strings */
120
    report ( crt_loc, ERR_dcl_link_unknown ( s ) ) ;
149
	report(crt_loc, ERR_dcl_link_unknown(s));
121
    return ( crt_linkage ) ;
150
	return (crt_linkage);
122
}
151
}
123
 
152
 
124
 
153
 
125
/*
154
/*
126
    FIND A LINKAGE STRING
155
    FIND A LINKAGE STRING
127
 
156
 
128
    This routine returns the string corresponding to the linkage specifiers
157
    This routine returns the string corresponding to the linkage specifiers
129
    given by ds and cv.
158
    given by ds and cv.
130
*/
159
*/
131
 
160
 
132
string linkage_string
161
string
133
    PROTO_N ( ( ds, cv ) )
-
 
134
    PROTO_T ( DECL_SPEC ds X CV_SPEC cv )
162
linkage_string(DECL_SPEC ds, CV_SPEC cv)
135
{
163
{
136
    CONST char *str ;
164
	CONST char *str;
137
    if ( ( ds & dspec_c ) || ( cv & cv_c ) ) {
165
	if ((ds & dspec_c) || (cv & cv_c)) {
138
	str = "C" ;
166
		str = "C";
139
    } else {
167
	} else {
140
	str = "C++" ;
168
		str = "C++";
141
    }
169
	}
142
    return ( ustrlit ( str ) ) ;
170
	return (ustrlit(str));
143
}
171
}
144
 
172
 
145
 
173
 
146
/*
174
/*
147
    ADJUST DECLARATION SPECIFIER FOR LANGUAGE
175
    ADJUST DECLARATION SPECIFIER FOR LANGUAGE
148
 
176
 
149
    This routine adds the current language specifier to the declaration
177
    This routine adds the current language specifier to the declaration
150
    specifier ds.  mem is true for a member declaration (which always
178
    specifier ds.  mem is true for a member declaration (which always
151
    has C++ linkage).  ds may contain a language specifier from a
179
    has C++ linkage).  ds may contain a language specifier from a
152
    previous declaration, otherwise it is deduced from crt_linkage.
180
    previous declaration, otherwise it is deduced from crt_linkage.
153
*/
181
*/
154
 
182
 
155
DECL_SPEC adjust_linkage
183
DECL_SPEC
156
    PROTO_N ( ( ds, mem ) )
-
 
157
    PROTO_T ( DECL_SPEC ds X int mem )
184
adjust_linkage(DECL_SPEC ds, int mem)
158
{
185
{
159
    DECL_SPEC rs = ( ds & ~dspec_language ) ;
186
	DECL_SPEC rs = (ds & ~dspec_language);
160
    if ( mem ) {
187
	if (mem) {
161
	/* Members have C++ linkage */
188
		/* Members have C++ linkage */
162
	rs |= dspec_cpp ;
189
		rs |= dspec_cpp;
163
    } else if ( rs & dspec_linkage ) {
190
	} else if (rs & dspec_linkage) {
164
	/* Only applies to objects with linkage */
191
		/* Only applies to objects with linkage */
165
	DECL_SPEC ln = ( ds | crt_linkage ) ;
192
		DECL_SPEC ln = (ds | crt_linkage);
166
	if ( ln & dspec_c ) {
193
		if (ln & dspec_c) {
167
	    rs |= dspec_c ;
194
			rs |= dspec_c;
168
	} else {
195
		} else {
169
	    rs |= dspec_cpp ;
196
			rs |= dspec_cpp;
-
 
197
		}
170
	}
198
	}
171
    }
-
 
172
    return ( rs ) ;
199
	return (rs);
173
}
200
}
174
 
201
 
175
 
202
 
176
/*
203
/*
177
    CHECK C LINKAGE DECLARATIONS
204
    CHECK C LINKAGE DECLARATIONS
178
 
205
 
179
    This routine checks the identifier id declared with C linkage.  Objects
206
    This routine checks the identifier id declared with C linkage.  Objects
180
    with C linkage in different namespaces are actually the same.
207
    with C linkage in different namespaces are actually the same.
181
*/
208
*/
182
 
209
 
183
void c_linkage
210
void
184
    PROTO_N ( ( id, def ) )
-
 
185
    PROTO_T ( IDENTIFIER id X int def )
211
c_linkage(IDENTIFIER id, int def)
186
{
212
{
187
    TYPE t = NULL_type ;
213
    TYPE t = NULL_type;
188
    unsigned tag = TAG_id ( id ) ;
214
    unsigned tag = TAG_id(id);
189
    if ( tag == id_function_tag ) {
215
    if (tag == id_function_tag) {
190
	/* Template functions can't have C linkage */
216
	/* Template functions can't have C linkage */
191
	t = DEREF_type ( id_function_type ( id ) ) ;
217
	t = DEREF_type(id_function_type(id));
192
	if ( IS_type_templ ( t ) ) {
218
	if (IS_type_templ(t)) {
193
	    report ( decl_loc, ERR_temp_decl_linkage () ) ;
219
	    report(decl_loc, ERR_temp_decl_linkage());
194
	}
220
	}
195
    } else if ( tag == id_variable_tag ) {
221
    } else if (tag == id_variable_tag) {
196
	t = DEREF_type ( id_variable_type ( id ) ) ;
222
	t = DEREF_type(id_variable_type(id));
197
    }
223
    }
198
    if ( !IS_NULL_type ( t ) ) {
224
    if (!IS_NULL_type(t)) {
199
	NAMESPACE ns = c_namespace ;
225
	NAMESPACE ns = c_namespace;
200
	if ( !IS_NULL_nspace ( ns ) ) {
226
	if (!IS_NULL_nspace(ns)) {
201
	    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
227
	    HASHID nm = DEREF_hashid(id_name(id));
202
	    MEMBER mem = search_member ( ns, nm, 1 ) ;
228
	    MEMBER mem = search_member(ns, nm, 1);
203
	    IDENTIFIER pid = DEREF_id ( member_id ( mem ) ) ;
229
	    IDENTIFIER pid = DEREF_id(member_id(mem));
204
	    if ( !IS_NULL_id ( pid ) && !EQ_id ( id, pid ) ) {
230
	    if (!IS_NULL_id(pid) && !EQ_id(id, pid)) {
205
		NAMESPACE cns = DEREF_nspace ( id_parent ( id ) ) ;
231
		NAMESPACE cns = DEREF_nspace(id_parent(id));
206
		NAMESPACE pns = DEREF_nspace ( id_parent ( pid ) ) ;
232
		NAMESPACE pns = DEREF_nspace(id_parent(pid));
207
		if ( !EQ_nspace ( cns, pns ) ) {
233
		if (!EQ_nspace(cns, pns)) {
208
		    DECL_SPEC cl = crt_linkage ;
234
		    DECL_SPEC cl = crt_linkage;
209
		    QUALIFIER cq = crt_id_qualifier ;
235
		    QUALIFIER cq = crt_id_qualifier;
210
		    DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
236
		    DECL_SPEC ds = DEREF_dspec(id_storage(id));
211
		    crt_linkage = ( ds & dspec_language ) ;
237
		    crt_linkage = (ds & dspec_language);
212
		    crt_id_qualifier = qual_none ;
238
		    crt_id_qualifier = qual_none;
213
		    pid = redecl_id ( ds, t, pid, 3, -1 ) ;
239
		    pid = redecl_id(ds, t, pid, 3, -1);
214
		    if ( !IS_NULL_id ( pid ) ) {
240
		    if (!IS_NULL_id(pid)) {
215
			/* Set up alias */
241
			/* Set up alias */
216
			if ( IS_id_function ( pid ) ) {
242
			if (IS_id_function(pid)) {
217
			    TYPE s = DEREF_type ( id_function_type ( pid ) ) ;
243
			    TYPE s = DEREF_type(id_function_type(pid));
218
			    s = redecl_func_type ( pid, s, t, def, 0 ) ;
244
			    s = redecl_func_type(pid, s, t, def, 0);
219
			    COPY_type ( id_function_type ( pid ), s ) ;
245
			    COPY_type(id_function_type(pid), s);
220
			}
246
			}
221
			ds |= dspec_alias ;
247
			ds |= dspec_alias;
222
			COPY_dspec ( id_storage ( id ), ds ) ;
248
			COPY_dspec(id_storage(id), ds);
223
			pid = DEREF_id ( id_alias ( pid ) ) ;
249
			pid = DEREF_id(id_alias(pid));
224
			COPY_id ( id_alias ( id ), pid ) ;
250
			COPY_id(id_alias(id), pid);
-
 
251
			if (do_dump) {
225
			if ( do_dump ) dump_alias ( id, pid, &decl_loc ) ;
252
				dump_alias(id, pid, &decl_loc);
-
 
253
			}
226
			id = pid ;
254
			id = pid;
227
		    }
255
		    }
228
		    crt_id_qualifier = cq ;
256
		    crt_id_qualifier = cq;
229
		    crt_linkage = cl ;
257
		    crt_linkage = cl;
230
		}
258
		}
231
	    }
259
	    }
232
	    COPY_id ( member_id ( mem ), id ) ;
260
	    COPY_id(member_id(mem), id);
233
	}
261
	}
234
    }
262
    }
235
    return ;
263
    return;
236
}
264
}
237
 
265
 
238
 
266
 
239
/*
267
/*
240
    FIND A PREVIOUS DECLARATION
268
    FIND A PREVIOUS DECLARATION
241
 
269
 
242
    If a declaration in block scope is declared extern then it has external
270
    If a declaration in block scope is declared extern then it has external
243
    linkage unless the declaration matches a visible declaration of namespace
271
    linkage unless the declaration matches a visible declaration of namespace
244
    scope.  This routine finds such a declaration for the identifier id
272
    scope.  This routine finds such a declaration for the identifier id
245
    of type t.
273
    of type t.
246
*/
274
*/
247
 
275
 
248
IDENTIFIER find_previous
276
IDENTIFIER
249
    PROTO_N ( ( t, id ) )
-
 
250
    PROTO_T ( TYPE t X IDENTIFIER id )
277
find_previous(TYPE t, IDENTIFIER id)
251
{
278
{
252
    if ( crt_id_qualifier == qual_none ) {
279
	if (crt_id_qualifier == qual_none) {
253
	NAMESPACE ns = nonblock_namespace ;
280
		NAMESPACE ns = nonblock_namespace;
254
	HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
281
		HASHID nm = DEREF_hashid(id_name(id));
255
	IDENTIFIER pid = find_extern_id ( nm, ns, 0 ) ;
282
		IDENTIFIER pid = find_extern_id(nm, ns, 0);
256
	if ( !IS_NULL_id ( pid ) ) {
283
		if (!IS_NULL_id(pid)) {
257
	    TYPE s ;
284
			TYPE s;
258
	    DECL_SPEC st ;
285
			DECL_SPEC st;
259
	    switch ( TAG_id ( pid ) ) {
286
			switch (TAG_id(pid)) {
260
		case id_variable_tag : {
287
			case id_variable_tag:
261
		    /* Variables may be redeclared */
288
				/* Variables may be redeclared */
262
		    s = DEREF_type ( id_variable_type ( pid ) ) ;
289
				s = DEREF_type(id_variable_type(pid));
263
		    break ;
290
				break;
264
		}
-
 
265
		case id_function_tag : {
291
			case id_function_tag: {
266
		    /* Functions may be redeclared */
292
				/* Functions may be redeclared */
267
#if LANGUAGE_CPP
293
#if LANGUAGE_CPP
268
		    int eq = 0 ;
294
				int eq = 0;
269
		    LIST ( IDENTIFIER ) pids = NULL_list ( IDENTIFIER ) ;
295
				LIST(IDENTIFIER) pids = NULL_list(IDENTIFIER);
270
		    pid = resolve_func ( pid, t, 0, 0, pids, &eq ) ;
296
				pid = resolve_func(pid, t, 0, 0, pids, &eq);
271
		    if ( IS_NULL_id ( pid ) ) return ( NULL_id ) ;
297
				if (IS_NULL_id(pid)) {
-
 
298
					return (NULL_id);
-
 
299
				}
272
		    if ( !IS_id_function ( pid ) ) return ( NULL_id ) ;
300
				if (!IS_id_function(pid)) {
-
 
301
					return (NULL_id);
-
 
302
				}
273
#endif
303
#endif
274
		    s = DEREF_type ( id_function_type ( pid ) ) ;
304
				s = DEREF_type(id_function_type(pid));
275
		    break ;
305
				break;
-
 
306
			}
-
 
307
			default:
-
 
308
				/* Nothing else can be redeclared */
-
 
309
				return (NULL_id);
-
 
310
			}
-
 
311
			st = DEREF_dspec(id_storage(pid));
-
 
312
			if (st & dspec_linkage) {
-
 
313
				/* Previous declaration must have linkage */
-
 
314
				s = type_composite(s, t, 0, 0, KILL_err, 0);
-
 
315
				if (!IS_NULL_type(s)) {
-
 
316
					return (pid);
-
 
317
				}
-
 
318
			}
276
		}
319
		}
277
		default : {
-
 
278
		    /* Nothing else can be redeclared */
-
 
279
		    return ( NULL_id ) ;
-
 
280
		}
-
 
281
	    }
-
 
282
	    st = DEREF_dspec ( id_storage ( pid ) ) ;
-
 
283
	    if ( st & dspec_linkage ) {
-
 
284
		/* Previous declaration must have linkage */
-
 
285
		s = type_composite ( s, t, 0, 0, KILL_err, 0 ) ;
-
 
286
		if ( !IS_NULL_type ( s ) ) return ( pid ) ;
-
 
287
	    }
-
 
288
	}
320
	}
289
    }
-
 
290
    return ( NULL_id ) ;
321
	return (NULL_id);
291
}
322
}
292
 
323
 
293
 
324
 
294
/*
325
/*
295
    UNIFY AN EXTERNAL IDENTIFIER
326
    UNIFY AN EXTERNAL IDENTIFIER
Line 298... Line 329...
298
    extern in a block, against conflicts with the namespace ns into
329
    extern in a block, against conflicts with the namespace ns into
299
    which it is injected.  p gives all the other extern block identifiers
330
    which it is injected.  p gives all the other extern block identifiers
300
    declared before id.  The routine returns any previous identifier.
331
    declared before id.  The routine returns any previous identifier.
301
*/
332
*/
302
 
333
 
303
IDENTIFIER unify_extern
334
IDENTIFIER
304
    PROTO_N ( ( id, t, ns, p ) )
-
 
305
    PROTO_T ( IDENTIFIER id X TYPE t X NAMESPACE ns X LIST ( IDENTIFIER ) p )
335
unify_extern(IDENTIFIER id, TYPE t, NAMESPACE ns, LIST(IDENTIFIER) p)
306
{
336
{
307
    IDENTIFIER pid = NULL_id ;
337
	IDENTIFIER pid = NULL_id;
308
    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
338
	HASHID nm = DEREF_hashid(id_name(id));
309
    LIST ( IDENTIFIER ) pids = NULL_list ( IDENTIFIER ) ;
339
	LIST(IDENTIFIER) pids = NULL_list(IDENTIFIER);
310
    while ( !IS_NULL_list ( p ) ) {
340
	while (!IS_NULL_list(p)) {
311
	/* Check other block externs */
341
		/* Check other block externs */
312
	IDENTIFIER bid = DEREF_id ( HEAD_list ( p ) ) ;
342
		IDENTIFIER bid = DEREF_id(HEAD_list(p));
313
	HASHID bnm = DEREF_hashid ( id_name ( bid ) ) ;
343
		HASHID bnm = DEREF_hashid(id_name(bid));
314
	if ( EQ_hashid ( bnm, nm ) ) {
344
		if (EQ_hashid(bnm, nm)) {
315
	    bid = DEREF_id ( id_alias ( bid ) ) ;
345
			bid = DEREF_id(id_alias(bid));
316
	    CONS_id ( bid, pids, pids ) ;
346
			CONS_id(bid, pids, pids);
317
	}
347
		}
318
	p = TAIL_list ( p ) ;
348
		p = TAIL_list(p);
319
    }
-
 
320
    if ( !IS_NULL_nspace ( ns ) ) {
-
 
321
	/* Check actual namespace */
-
 
322
	MEMBER mem = search_member ( ns, nm, 0 ) ;
-
 
323
	if ( !IS_NULL_member ( mem ) ) {
-
 
324
	    IDENTIFIER bid = DEREF_id ( member_id ( mem ) ) ;
-
 
325
	    if ( !IS_NULL_id ( bid ) ) {
-
 
326
		bid = DEREF_id ( id_alias ( bid ) ) ;
-
 
327
		CONS_id ( bid, pids, pids ) ;
-
 
328
	    }
-
 
329
	}
349
	}
330
    }
-
 
331
    if ( !IS_NULL_list ( pids ) ) {
350
	if (!IS_NULL_nspace(ns)) {
332
	/* Match found */
351
		/* Check actual namespace */
333
	if ( IS_NULL_type ( t ) ) {
352
		MEMBER mem = search_member(ns, nm, 0);
334
	    if ( IS_NULL_list ( TAIL_list ( pids ) ) ) {
353
		if (!IS_NULL_member(mem)) {
335
		pid = DEREF_id ( HEAD_list ( pids ) ) ;
354
			IDENTIFIER bid = DEREF_id(member_id(mem));
336
		DESTROY_list ( pids, SIZE_id ) ;
355
			if (!IS_NULL_id(bid)) {
337
	    } else {
-
 
338
		DECL_SPEC ds ;
-
 
339
		pids = REVERSE_list ( pids ) ;
356
				bid = DEREF_id(id_alias(bid));
340
		ds = find_ambig_dspec ( pids ) ;
357
				CONS_id(bid, pids, pids);
341
		MAKE_id_ambig ( nm, ds, ns, crt_loc, pids, 1, pid ) ;
-
 
342
	    }
358
			}
-
 
359
		}
343
	} else {
360
	}
344
	    LIST ( IDENTIFIER ) qids ;
361
	if (!IS_NULL_list(pids)) {
345
	    DECL_SPEC cl = crt_linkage ;
362
		/* Match found */
346
	    QUALIFIER cq = crt_id_qualifier ;
363
		if (IS_NULL_type(t)) {
347
	    DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
-
 
348
	    crt_linkage = ( ds & dspec_language ) ;
-
 
349
	    crt_id_qualifier = qual_none ;
364
			if (IS_NULL_list(TAIL_list(pids))) {
350
	    DEREF_loc ( id_loc ( id ), decl_loc ) ;
365
				pid = DEREF_id(HEAD_list(pids));
351
	    pids = REVERSE_list ( pids ) ;
366
				DESTROY_list(pids, SIZE_id);
352
	    qids = pids ;
367
			} else {
353
	    while ( !IS_NULL_list ( qids ) ) {
368
				DECL_SPEC ds;
354
		IDENTIFIER qid = DEREF_id ( HEAD_list ( qids ) ) ;
369
				pids = REVERSE_list(pids);
355
		qid = DEREF_id ( id_alias ( qid ) ) ;
370
				ds = find_ambig_dspec(pids);
356
		if ( IS_type_func ( t ) ) {
-
 
357
		    /* Check function redeclaration */
371
				MAKE_id_ambig(nm, ds, ns, crt_loc, pids, 1,
358
		    IDENTIFIER over = NULL_id ;
372
					      pid);
359
		    unsigned tag = TAG_id ( id ) ;
373
			}
360
		    qid = redecl_func ( ds, t, qid, tag, &over, -1 ) ;
-
 
361
		} else {
374
		} else {
-
 
375
			LIST(IDENTIFIER) qids;
-
 
376
			DECL_SPEC cl = crt_linkage;
-
 
377
			QUALIFIER cq = crt_id_qualifier;
-
 
378
			DECL_SPEC ds = DEREF_dspec(id_storage(id));
-
 
379
			crt_linkage = (ds & dspec_language);
-
 
380
			crt_id_qualifier = qual_none;
-
 
381
			DEREF_loc(id_loc(id), decl_loc);
-
 
382
			pids = REVERSE_list(pids);
-
 
383
			qids = pids;
-
 
384
			while (!IS_NULL_list(qids)) {
-
 
385
				IDENTIFIER qid = DEREF_id(HEAD_list(qids));
-
 
386
				qid = DEREF_id(id_alias(qid));
-
 
387
				if (IS_type_func(t)) {
-
 
388
					/* Check function redeclaration */
-
 
389
					IDENTIFIER over = NULL_id;
-
 
390
					unsigned tag = TAG_id(id);
-
 
391
					qid = redecl_func(ds, t, qid, tag,
-
 
392
							  &over, -1);
-
 
393
				} else {
362
		    /* Check variable redeclaration */
394
					/* Check variable redeclaration */
363
		    qid = redecl_id ( ds, t, qid, 0, -1 ) ;
395
					qid = redecl_id(ds, t, qid, 0, -1);
364
		}
396
				}
365
		if ( !IS_NULL_id ( qid ) ) pid = qid ;
397
				if (!IS_NULL_id(qid)) {
-
 
398
					pid = qid;
-
 
399
				}
366
		qids = TAIL_list ( qids ) ;
400
				qids = TAIL_list(qids);
367
	    }
401
			}
368
	    DESTROY_list ( pids, SIZE_id ) ;
402
			DESTROY_list(pids, SIZE_id);
369
	    crt_id_qualifier = cq ;
403
			crt_id_qualifier = cq;
370
	    crt_linkage = cl ;
404
			crt_linkage = cl;
-
 
405
		}
371
	}
406
	}
372
    }
-
 
373
    return ( pid ) ;
407
	return (pid);
374
}
408
}
375
 
409
 
376
 
410
 
377
/*
411
/*
378
    UNIFY A BLOCK DECLARATION WITH A PREVIOUS DECLARATION
412
    UNIFY A BLOCK DECLARATION WITH A PREVIOUS DECLARATION
Line 380... Line 414...
380
    This routine is used to unify the external block declaration id of
414
    This routine is used to unify the external block declaration id of
381
    type t with its previous declaration pid (as returned by find_previous).
415
    type t with its previous declaration pid (as returned by find_previous).
382
    def is true is id is a function definition.  The routine returns id.
416
    def is true is id is a function definition.  The routine returns id.
383
    If there is no previous declaration then one is created and added to
417
    If there is no previous declaration then one is created and added to
384
    the extra identifier list of the enclosing non-block namespace.
418
    the extra identifier list of the enclosing non-block namespace.
385
*/
419
*/
386
 
420
 
387
IDENTIFIER unify_previous
421
IDENTIFIER
388
    PROTO_N ( ( id, t, pid, def ) )
-
 
389
    PROTO_T ( IDENTIFIER id X TYPE t X IDENTIFIER pid X int def )
422
unify_previous(IDENTIFIER id, TYPE t, IDENTIFIER pid, int def)
390
{
423
{
391
    /* Unify external linkage */
424
	/* Unify external linkage */
392
    if ( IS_NULL_id ( pid ) ) {
425
	if (IS_NULL_id(pid)) {
393
	LIST ( IDENTIFIER ) p ;
426
		LIST(IDENTIFIER) p;
394
	NAMESPACE ns = nonblock_namespace ;
427
		NAMESPACE ns = nonblock_namespace;
395
	p = DEREF_list ( nspace_named_etc_extra ( ns ) ) ;
428
		p = DEREF_list(nspace_named_etc_extra(ns));
396
	pid = unify_extern ( id, t, ns, p ) ;
429
		pid = unify_extern(id, t, ns, p);
397
	if ( IS_NULL_id ( pid ) ) {
430
		if (IS_NULL_id(pid)) {
398
	    if ( !is_templ_depend ( t ) ) {
431
			if (!is_templ_depend(t)) {
399
		/* Declare new external object */
432
				/* Declare new external object */
400
		DECL_SPEC ds ;
433
				DECL_SPEC ds;
401
		pid = copy_id ( id, 0 ) ;
434
				pid = copy_id(id, 0);
402
		ds = DEREF_dspec ( id_storage ( pid ) ) ;
435
				ds = DEREF_dspec(id_storage(pid));
403
		if ( !( ds & dspec_linkage ) ) ds |= dspec_extern ;
436
				if (!(ds & dspec_linkage)) {
-
 
437
					ds |= dspec_extern;
-
 
438
				}
404
		ds &= ~dspec_alias ;
439
				ds &= ~dspec_alias;
405
		COPY_dspec ( id_storage ( pid ), ds ) ;
440
				COPY_dspec(id_storage(pid), ds);
406
		COPY_nspace ( id_parent ( pid ), ns ) ;
441
				COPY_nspace(id_parent(pid), ns);
407
		COPY_id ( id_alias ( pid ), pid ) ;
442
				COPY_id(id_alias(pid), pid);
408
		CONS_id ( pid, p, p ) ;
443
				CONS_id(pid, p, p);
409
		COPY_list ( nspace_named_etc_extra ( ns ), p ) ;
444
				COPY_list(nspace_named_etc_extra(ns), p);
410
	    }
445
			}
411
 
446
 
412
	    /* Check object type */
447
			/* Check object type */
413
	    if ( !is_global_type ( t ) ) {
448
			if (!is_global_type(t)) {
414
		report ( crt_loc, ERR_basic_link_none ( t, id ) ) ;
449
				report(crt_loc, ERR_basic_link_none(t, id));
415
	    }
450
			}
416
	}
451
		}
417
    }
452
	}
418
 
453
 
419
    /* Alias id to be pid */
454
	/* Alias id to be pid */
420
    if ( !IS_NULL_id ( pid ) ) {
455
	if (!IS_NULL_id(pid)) {
421
	if ( IS_id_function_etc ( pid ) ) {
456
		if (IS_id_function_etc(pid)) {
422
	    TYPE s = DEREF_type ( id_function_etc_type ( pid ) ) ;
457
			TYPE s = DEREF_type(id_function_etc_type(pid));
423
	    s = redecl_func_type ( pid, s, t, def, 0 ) ;
458
			s = redecl_func_type(pid, s, t, def, 0);
424
	    COPY_type ( id_function_etc_type ( pid ), s ) ;
459
			COPY_type(id_function_etc_type(pid), s);
-
 
460
		}
-
 
461
		pid = DEREF_id(id_alias(pid));
-
 
462
		COPY_id(id_alias(id), pid);
425
	}
463
	}
426
	pid = DEREF_id ( id_alias ( pid ) ) ;
-
 
427
	COPY_id ( id_alias ( id ), pid ) ;
-
 
428
    }
-
 
429
    return ( id ) ;
464
	return (id);
430
}
465
}
431
 
466
 
432
 
467
 
433
/*
468
/*
434
    UNIFY A DECLARATION WITH A PREVIOUS BLOCK DECLARATION
469
    UNIFY A DECLARATION WITH A PREVIOUS BLOCK DECLARATION
Line 436... Line 471...
436
    This routine is used to unify the external declaration id of type
471
    This routine is used to unify the external declaration id of type
437
    t with any previous external block declaration of the same object.
472
    t with any previous external block declaration of the same object.
438
    def is true if id is a function definition.  The routine returns id.
473
    def is true if id is a function definition.  The routine returns id.
439
*/
474
*/
440
 
475
 
441
IDENTIFIER unify_subsequent
476
IDENTIFIER
442
    PROTO_N ( ( id, t, def ) )
-
 
443
    PROTO_T ( IDENTIFIER id X TYPE t X int def )
477
unify_subsequent(IDENTIFIER id, TYPE t, int def)
444
{
478
{
445
    NAMESPACE ns = DEREF_nspace ( id_parent ( id ) ) ;
479
	NAMESPACE ns = DEREF_nspace(id_parent(id));
446
    if ( IS_nspace_named_etc ( ns ) ) {
480
	if (IS_nspace_named_etc(ns)) {
447
	LIST ( IDENTIFIER ) p ;
481
		LIST(IDENTIFIER) p;
448
	p = DEREF_list ( nspace_named_etc_extra ( ns ) ) ;
482
		p = DEREF_list(nspace_named_etc_extra(ns));
449
	if ( !IS_NULL_list ( p ) ) {
483
		if (!IS_NULL_list(p)) {
450
	    IDENTIFIER pid = unify_extern ( id, t, NULL_nspace, p ) ;
484
			IDENTIFIER pid = unify_extern(id, t, NULL_nspace, p);
451
	    if ( !IS_NULL_id ( pid ) ) {
485
			if (!IS_NULL_id(pid)) {
452
		/* Alias id to be pid */
486
				/* Alias id to be pid */
453
		if ( IS_id_function_etc ( pid ) ) {
487
				if (IS_id_function_etc(pid)) {
454
		    TYPE s = DEREF_type ( id_function_etc_type ( pid ) ) ;
488
					TYPE s = DEREF_type(id_function_etc_type(pid));
455
		    s = redecl_func_type ( pid, s, t, def, 0 ) ;
489
					s = redecl_func_type(pid, s, t, def, 0);
456
		    COPY_type ( id_function_etc_type ( pid ), s ) ;
490
					COPY_type(id_function_etc_type(pid), s);
-
 
491
				}
-
 
492
				pid = DEREF_id(id_alias(pid));
-
 
493
				COPY_id(id_alias(id), pid);
-
 
494
			}
457
		}
495
		}
458
		pid = DEREF_id ( id_alias ( pid ) ) ;
-
 
459
		COPY_id ( id_alias ( id ), pid ) ;
-
 
460
	    }
-
 
461
	}
496
	}
462
    }
-
 
463
    return ( id ) ;
497
	return (id);
464
}
498
}
465
 
499
 
466
 
500
 
467
/*
501
/*
468
    CHECK FOR CLASS-LIKE TYPEDEF NAMES
502
    CHECK FOR CLASS-LIKE TYPEDEF NAMES
469
 
503
 
470
    This routine checks whether the typedef name id behaves like a class
504
    This routine checks whether the typedef name id behaves like a class
471
    or an object with respect to name hiding.  It is not entirely clear
505
    or an object with respect to name hiding.  It is not entirely clear
472
    whether it is just original class and enumeration names or all class
506
    whether it is just original class and enumeration names or all class
473
    and enumeration names (including those introduced using typedef)
507
    and enumeration names (including those introduced using typedef)
474
    which behave in this way.
508
    which behave in this way.
475
*/
509
*/
476
 
510
 
477
int is_tagged_type
511
int
478
    PROTO_N ( ( id ) )
-
 
479
    PROTO_T ( IDENTIFIER id )
512
is_tagged_type(IDENTIFIER id)
480
{
513
{
481
    switch ( TAG_id ( id ) ) {
514
	switch (TAG_id(id)) {
482
	case id_class_name_tag :
515
	case id_class_name_tag:
483
	case id_enum_name_tag : {
516
	case id_enum_name_tag:
484
	    /* Original class and enumeration names */
517
		/* Original class and enumeration names */
485
	    return ( 1 ) ;
518
		return (1);
-
 
519
	case id_class_alias_tag:
-
 
520
	case id_enum_alias_tag:
-
 
521
	case id_type_alias_tag:
-
 
522
		/* Type aliases */
-
 
523
		return (0);
486
	}
524
	}
487
	case id_class_alias_tag :
-
 
488
	case id_enum_alias_tag :
-
 
489
	case id_type_alias_tag : {
-
 
490
	    /* Type aliases */
-
 
491
	    return ( 0 ) ;
525
	return (0);
492
	}
-
 
493
    }
-
 
494
    return ( 0 ) ;
-
 
495
}
526
}
496
 
527
 
497
 
528
 
498
/*
529
/*
499
    REPORT AN OVERLOADIN ERROR
530
    REPORT AN OVERLOADIN ERROR
Line 501... Line 532...
501
    This routine reports the overloading error err for the function id
532
    This routine reports the overloading error err for the function id
502
    which cannot be overloaded for the reason corresponding to reason.
533
    which cannot be overloaded for the reason corresponding to reason.
503
    It returns the severity of the error.
534
    It returns the severity of the error.
504
*/
535
*/
505
 
536
 
506
static int overload_error
537
static int
507
    PROTO_N ( ( id, err, reason ) )
-
 
508
    PROTO_T ( IDENTIFIER id X ERROR err X int reason )
538
overload_error(IDENTIFIER id, ERROR err, int reason)
509
{
539
{
510
    int sev = ERROR_NONE ;
540
	int sev = ERROR_NONE;
511
    switch ( reason ) {
541
	switch (reason) {
512
	case 1 : {
542
	case 1:
513
	    /* Two functions with C linkage */
543
		/* Two functions with C linkage */
514
	    err = concat_error ( err, ERR_dcl_link_over () ) ;
544
		err = concat_error(err, ERR_dcl_link_over());
-
 
545
		break;
-
 
546
	case 2:
-
 
547
		/* Two functions with indistinguishable parameters */
-
 
548
		err = concat_error(err, ERR_over_load_pars());
-
 
549
		break;
-
 
550
	case 3: {
-
 
551
		/* Two objects with C linkage */
-
 
552
		PTR(LOCATION)loc = id_loc(id);
-
 
553
		HASHID nm = DEREF_hashid(id_name(id));
-
 
554
		err = concat_error(err, ERR_dcl_link_redecl(nm, loc));
515
	    break ;
555
		break;
516
	}
556
	}
517
	case 2 : {
-
 
518
	    /* Two functions with indistinguishable parameters */
-
 
519
	    err = concat_error ( err, ERR_over_load_pars () ) ;
-
 
520
	    break ;
-
 
521
	}
557
	}
522
	case 3 : {
558
 
523
	    /* Two objects with C linkage */
-
 
524
	    PTR ( LOCATION ) loc = id_loc ( id ) ;
559
	if (!IS_NULL_err(err)) {
525
	    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
560
		sev = DEREF_int(err_severity(err));
526
	    err = concat_error ( err, ERR_dcl_link_redecl ( nm, loc ) ) ;
-
 
527
	    break ;
561
		report(decl_loc, err);
528
	}
562
	}
529
    }
-
 
530
    if ( !IS_NULL_err ( err ) ) {
-
 
531
	sev = DEREF_int ( err_severity ( err ) ) ;
-
 
532
	report ( decl_loc, err ) ;
-
 
533
    }
-
 
534
    return ( sev ) ;
563
	return (sev);
535
}
564
}
536
 
565
 
537
 
566
 
538
/*
567
/*
539
    REDECLARE AN OBJECT IDENTIFIER
568
    REDECLARE AN OBJECT IDENTIFIER
Line 548... Line 577...
548
    redeclared identifier will be marked as defined according to whether
577
    redeclared identifier will be marked as defined according to whether
549
    the redeclaration is a definition.  Whether the initial declaration
578
    the redeclaration is a definition.  Whether the initial declaration
550
    was a definition may be determined from the initialiser expression.
579
    was a definition may be determined from the initialiser expression.
551
*/
580
*/
552
 
581
 
553
IDENTIFIER redecl_id
582
IDENTIFIER
554
    PROTO_N ( ( ds, t, id, reason, def ) )
-
 
555
    PROTO_T ( DECL_SPEC ds X TYPE t X IDENTIFIER id X int reason X int def )
583
redecl_id(DECL_SPEC ds, TYPE t, IDENTIFIER id, int reason, int def)
556
{
584
{
557
    TYPE s ;
585
	TYPE s;
558
    DECL_SPEC ln ;
586
	DECL_SPEC ln;
559
    PTR ( TYPE ) pt ;
587
	PTR(TYPE) pt;
560
    int changed = 0 ;
588
	int changed = 0;
561
    int is_member = 0 ;
589
	int is_member = 0;
562
    int is_function = 0 ;
590
	int is_function = 0;
563
    ERROR err = NULL_err ;
591
	ERROR err = NULL_err;
564
    DECL_SPEC ds_old, ln_old ;
592
	DECL_SPEC ds_old, ln_old;
565
 
593
 
663
	}
783
	}
664
    }
-
 
665
 
784
 
666
    /* Check previous type */
785
	/* Mark whether this declaration is a definition */
667
    s = DEREF_type ( pt ) ;
786
	if (def >= 0) {
668
    s = check_compatible ( s, t, 0, &err, 1 ) ;
-
 
669
    if ( !IS_NULL_err ( err ) ) {
787
		if (ds & dspec_defn) {
670
	/* Incompatible declaration */
788
			ds_old |= dspec_defn;
671
	PTR ( LOCATION ) loc = id_loc ( id ) ;
789
		} else {
672
	err = concat_error ( err, ERR_basic_link_decl_type ( id, loc ) ) ;
-
 
673
	if ( ( ds | ds_old ) & dspec_token ) {
790
			ds_old &= ~dspec_defn;
674
	    /* Allow for interface declarations */
-
 
675
	    err = set_severity ( err, OPT_interf_incompat, -1 ) ;
-
 
676
	}
791
		}
677
	if ( overload_error ( id, err, reason ) == ERROR_SERIOUS ) {
-
 
678
	    return ( NULL_id ) ;
-
 
679
	}
792
	}
680
    }
-
 
681
    if ( is_function ) {
-
 
682
	/* Sanity check for error types */
-
 
683
	if ( type_tag ( s ) != type_func_tag ) return ( NULL_id ) ;
-
 
684
    } else {
-
 
685
	if ( type_tag ( s ) == type_func_tag ) return ( NULL_id ) ;
-
 
686
    }
-
 
687
    if ( def >= 0 ) COPY_type ( pt, s ) ;
-
 
688
 
793
 
689
    /* Check for redeclaration of aliases */
794
	/* Compatible redeclaration */
690
    if ( ( ds | ds_old ) & dspec_alias ) {
-
 
691
	PTR ( LOCATION ) loc = id_loc ( id ) ;
-
 
692
	report ( decl_loc, ERR_dcl_nspace_udecl_redecl ( id, loc ) ) ;
-
 
693
    }
-
 
694
 
-
 
695
    /* Check for inconsistent linkage */
-
 
696
    if ( ln != ln_old ) {
-
 
697
	ERROR err1 ;
-
 
698
	DECL_SPEC ln_new ;
-
 
699
	PTR ( LOCATION ) loc = id_loc ( id ) ;
-
 
700
	if ( ln_old == dspec_static ) {
-
 
701
	    err1 = ERR_dcl_stc_internal ( id, loc ) ;
-
 
702
	} else {
-
 
703
	    err1 = ERR_dcl_stc_external ( id, loc ) ;
795
	COPY_dspec(id_storage(id), ds_old);
704
	    if ( is_member ) {
796
	if (changed) {
705
		/* Members have external linkage */
-
 
706
		ERROR err2 = ERR_basic_link_mem_extern ( id ) ;
-
 
707
		err1 = concat_error ( err2, err1 ) ;
797
		update_tag(id, 0);
708
	    }
-
 
709
	}
798
	}
710
	if ( reason == 3 ) {
-
 
711
	    /* Identification of objects with C linkage */
-
 
712
	    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
-
 
713
	    ERROR err2 = ERR_dcl_link_redecl ( nm, loc ) ;
-
 
714
	    err1 = concat_error ( err1, err2 ) ;
-
 
715
	}
-
 
716
	if ( def == -1 && option ( OPT_link_internal ) == OPTION_OFF ) {
-
 
717
	    ln_new = dspec_extern ;
-
 
718
	} else {
-
 
719
	    ln_new = dspec_static ;
-
 
720
	}
-
 
721
	ds_old = ( ln_new | ( ds_old & ~dspec_linkage ) ) ;
-
 
722
	report ( decl_loc, err1 ) ;
-
 
723
	changed = 1 ;
-
 
724
    }
-
 
725
 
-
 
726
    /* Check language specifier */
-
 
727
    ln = crt_linkage ;
-
 
728
    if ( ln != dspec_none ) {
-
 
729
	/* Check against the current language */
-
 
730
	ln_old = ( ds_old & dspec_language ) ;
-
 
731
	if ( ( ds_old & dspec_extern ) && ln != ln_old ) {
-
 
732
	    /* Report inconsistent linkage */
-
 
733
	    if ( !is_member ) {
-
 
734
		/* Should this only apply to functions? */
-
 
735
		PTR ( LOCATION ) loc = id_loc ( id ) ;
-
 
736
		string lang = linkage_string ( ln_old, cv_none ) ;
-
 
737
		report ( decl_loc, ERR_dcl_link_lang ( id, lang, loc ) ) ;
-
 
738
		ds_old = adjust_linkage ( ds_old, is_member ) ;
-
 
739
		changed = 1 ;
-
 
740
	    }
-
 
741
	}
-
 
742
    }
-
 
743
 
-
 
744
    /* Check for inline specifier */
-
 
745
    if ( ds & dspec_inline ) {
-
 
746
	ds_old |= dspec_inline ;
-
 
747
	changed = 1 ;
-
 
748
    }
-
 
749
 
-
 
750
    /* Mark whether this declaration is a definition */
-
 
751
    if ( def >= 0 ) {
-
 
752
	if ( ds & dspec_defn ) {
-
 
753
	    ds_old |= dspec_defn ;
-
 
754
	} else {
-
 
755
	    ds_old &= ~dspec_defn ;
-
 
756
	}
-
 
757
    }
-
 
758
 
-
 
759
    /* Compatible redeclaration */
-
 
760
    COPY_dspec ( id_storage ( id ), ds_old ) ;
-
 
761
    if ( changed ) update_tag ( id, 0 ) ;
-
 
762
    return ( id ) ;
799
	return (id);
763
}
800
}
764
 
801
 
765
 
802
 
766
/*
803
/*
767
    REDECLARE A FUNCTION IDENTIFIER
804
    REDECLARE A FUNCTION IDENTIFIER
Line 769... Line 806...
769
    This routine is similar to redecl_id except that it allows for function
806
    This routine is similar to redecl_id except that it allows for function
770
    overloading.  As before it returns id if this is a redeclaration of an
807
    overloading.  As before it returns id if this is a redeclaration of an
771
    existing function, and the null identifier otherwise.  However in the
808
    existing function, and the null identifier otherwise.  However in the
772
    latter case any functions overloaded by the declaration are returned
809
    latter case any functions overloaded by the declaration are returned
773
    via over.
810
    via over.
774
*/
811
*/
775
 
812
 
776
IDENTIFIER redecl_func
813
IDENTIFIER
777
    PROTO_N ( ( ds, t, id, tag, over, def ) )
-
 
778
    PROTO_T ( DECL_SPEC ds X TYPE t X IDENTIFIER id X unsigned tag X
814
redecl_func(DECL_SPEC ds, TYPE t, IDENTIFIER id, unsigned tag,
779
	      IDENTIFIER *over X int def )
815
	    IDENTIFIER *over, int def)
780
{
816
{
781
    int reason = 0 ;
817
	int reason = 0;
782
    IDENTIFIER fid = id ;
818
	IDENTIFIER fid = id;
783
#if LANGUAGE_CPP
819
#if LANGUAGE_CPP
784
    if ( IS_id_function_etc ( fid ) ) {
820
	if (IS_id_function_etc(fid)) {
785
	DECL_SPEC ds_old ;
821
		DECL_SPEC ds_old;
786
	*over = fid ;
822
		*over = fid;
787
 
823
 
788
	/* Scan through overloaded functions for a match */
824
		/* Scan through overloaded functions for a match */
789
	while ( !IS_NULL_id ( fid ) ) {
825
		while (!IS_NULL_id(fid)) {
790
	    int m ;
826
			int m;
791
	    TYPE s ;
827
			TYPE s;
792
	    int mq = 1 ;
828
			int mq = 1;
793
	    if ( ( ds & dspec_extern ) && crt_linkage == dspec_c ) {
829
			if ((ds & dspec_extern) && crt_linkage == dspec_c) {
794
		/* Two functions with C linkage are the same */
830
				/* Two functions with C linkage are the same */
795
		ds_old = DEREF_dspec ( id_storage ( fid ) ) ;
831
				ds_old = DEREF_dspec(id_storage(fid));
796
		if ( ( ds_old & dspec_c ) && IS_id_function ( fid ) ) {
832
				if ((ds_old & dspec_c) && IS_id_function(fid)) {
797
		    reason = 1 ;
833
					reason = 1;
798
		    break ;
834
					break;
799
		}
835
				}
800
	    }
836
			}
801
 
837
 
802
	    /* Two functions with the same parameters are the same */
838
			/* Two functions with the same parameters are the
-
 
839
			 * same */
803
	    s = DEREF_type ( id_function_etc_type ( fid ) ) ;
840
			s = DEREF_type(id_function_etc_type(fid));
804
	    if ( tag == id_stat_mem_func_tag ) mq = 0 ;
841
			if (tag == id_stat_mem_func_tag) {
-
 
842
				mq = 0;
-
 
843
			}
805
	    if ( IS_id_stat_mem_func ( fid ) ) mq = 0 ;
844
			if (IS_id_stat_mem_func(fid)) {
-
 
845
				mq = 0;
-
 
846
			}
806
	    m = eq_func_type ( t, s, mq, 0 ) ;
847
			m = eq_func_type(t, s, mq, 0);
807
	    if ( m ) {
848
			if (m) {
808
		/* Function types basically match */
849
				/* Function types basically match */
809
		if ( m == 1 ) {
850
				if (m == 1) {
810
		    /* Return types don't match */
851
					/* Return types don't match */
811
		    reason = 2 ;
852
					reason = 2;
812
		}
853
				}
813
		break ;
854
				break;
814
	    }
855
			}
815
	    fid = DEREF_id ( id_function_etc_over ( fid ) ) ;
856
			fid = DEREF_id(id_function_etc_over(fid));
816
	}
857
		}
817
 
858
 
818
	if ( IS_NULL_id ( fid ) ) {
859
		if (IS_NULL_id(fid)) {
819
	    /* No match found */
860
			/* No match found */
820
	    IDENTIFIER tid = find_template ( id, 0 ) ;
861
			IDENTIFIER tid = find_template(id, 0);
821
	    if ( !IS_NULL_id ( tid ) ) {
862
			if (!IS_NULL_id(tid)) {
822
		/* Must have match with template specialisation */
863
				/* Must have match with template
-
 
864
				 * specialisation */
823
		report ( decl_loc, ERR_temp_spec_type ( t, id ) ) ;
865
				report(decl_loc, ERR_temp_spec_type(t, id));
824
		return ( NULL_id ) ;
866
				return (NULL_id);
825
	    }
867
			}
826
	    if ( crt_id_qualifier != qual_none ) {
868
			if (crt_id_qualifier != qual_none) {
827
		/* Must have match with qualified identifier */
869
				/* Must have match with qualified identifier */
828
		if ( def == -2 && tag == id_function_tag ) {
870
				if (def == -2 && tag == id_function_tag) {
829
		    /* Allow for name injection */
871
					/* Allow for name injection */
830
		    /* EMPTY */
872
					/* EMPTY */
831
		} else {
873
				} else {
-
 
874
					report(decl_loc,
832
		    report ( decl_loc, ERR_basic_link_unmatch ( t, id ) ) ;
875
					       ERR_basic_link_unmatch(t, id));
833
		}
876
				}
834
		return ( NULL_id ) ;
877
				return (NULL_id);
835
	    }
878
			}
-
 
879
			if (reason == 0) {
836
	    if ( reason == 0 ) return ( NULL_id ) ;
880
				return (NULL_id);
-
 
881
			}
837
	    fid = id ;
882
			fid = id;
838
	}
883
		}
839
 
884
 
840
	/* Match found */
885
		/* Match found */
841
	ds_old = DEREF_dspec ( id_storage ( fid ) ) ;
886
		ds_old = DEREF_dspec(id_storage(fid));
842
	if ( ( ds_old & dspec_implicit ) && !( ds & dspec_implicit ) ) {
887
		if ((ds_old & dspec_implicit) && !(ds & dspec_implicit)) {
843
	    if ( IS_id_mem_func ( fid ) ) {
888
			if (IS_id_mem_func(fid)) {
844
		/* Matches implicitly declared member function */
889
				/* Matches implicitly declared member
-
 
890
				 * function */
845
		report ( decl_loc, ERR_class_special_decl ( fid ) ) ;
891
				report(decl_loc, ERR_class_special_decl(fid));
846
		return ( NULL_id ) ;
892
				return (NULL_id);
847
	    }
893
			}
848
	}
894
		}
849
	if ( ds_old & dspec_inherit ) {
895
		if (ds_old & dspec_inherit) {
850
	    /* Inherited functions (including aliases) are hidden */
896
			/* Inherited functions (including aliases) are hidden */
851
	    return ( NULL_id ) ;
897
			return (NULL_id);
-
 
898
		}
-
 
899
		/* *over = NULL_id ; */
852
	}
900
	}
853
	/* *over = NULL_id ; */
-
 
854
    }
-
 
855
#else
901
#else
856
    /* Don't check overloading in C */
902
	/* Don't check overloading in C */
857
    *over = NULL_id ;
903
	*over = NULL_id;
858
    UNUSED ( tag ) ;
904
	UNUSED(tag);
859
#endif
905
#endif
860
 
906
 
861
    /* Redeclare id */
907
	/* Redeclare id */
862
    fid = redecl_id ( ds, t, fid, reason, def ) ;
908
	fid = redecl_id(ds, t, fid, reason, def);
863
    if ( !IS_NULL_id ( fid ) ) {
909
	if (!IS_NULL_id(fid)) {
864
	TYPE form = DEREF_type ( id_function_etc_form ( id ) ) ;
910
		TYPE form = DEREF_type(id_function_etc_form(id));
865
	if ( def >= 0 ) {
911
		if (def >= 0) {
866
	    /* Allow for default arguments etc. */
912
			/* Allow for default arguments etc. */
867
	    TYPE s = DEREF_type ( id_function_etc_type ( fid ) ) ;
913
			TYPE s = DEREF_type(id_function_etc_type(fid));
868
	    s = redecl_func_type ( fid, s, t, def, 1 ) ;
914
			s = redecl_func_type(fid, s, t, def, 1);
869
	    COPY_type ( id_function_etc_type ( fid ), s ) ;
915
			COPY_type(id_function_etc_type(fid), s);
870
	}
916
		}
871
	if ( !IS_NULL_type ( form ) && IS_type_token ( form ) ) {
917
		if (!IS_NULL_type(form) && IS_type_token(form)) {
872
	    IDENTIFIER ext = DEREF_id ( type_token_tok ( form ) ) ;
918
			IDENTIFIER ext = DEREF_id(type_token_tok(form));
873
	    if ( !IS_NULL_id ( ext ) && IS_id_token ( ext ) ) {
919
			if (!IS_NULL_id(ext) && IS_id_token(ext)) {
874
		/* Check for tokenised functions */
920
				/* Check for tokenised functions */
875
		ds = DEREF_dspec ( id_storage ( ext ) ) ;
921
				ds = DEREF_dspec(id_storage(ext));
876
		ds |= dspec_explicit ;
922
				ds |= dspec_explicit;
877
		COPY_dspec ( id_storage ( ext ), ds ) ;
923
				COPY_dspec(id_storage(ext), ds);
878
		if ( def ) {
924
				if (def) {
879
		    /* Check for token definitions */
925
					/* Check for token definitions */
880
		    IGNORE define_func_token ( ext, fid ) ;
926
					IGNORE define_func_token(ext, fid);
881
		    if ( ds & dspec_pure ) {
927
					if (ds & dspec_pure) {
-
 
928
						report(decl_loc,
882
			report ( decl_loc, ERR_token_def_not ( ext ) ) ;
929
						       ERR_token_def_not(ext));
883
		    }
930
					}
884
		}
931
				}
885
	    }
932
			}
886
	}
933
		}
887
    }
934
	}
888
    return ( fid ) ;
935
	return (fid);
889
}
936
}
890
 
937
 
891
 
938
 
892
/*
939
/*
893
    REDECLARE AN INHERITED OR ALIASED MEMBER
940
    REDECLARE AN INHERITED OR ALIASED MEMBER
894
 
941
 
895
    This routine is used to allow for declarations of class members to
942
    This routine is used to allow for declarations of class members to
896
    override any inherited value of the member.  id gives the inherited
943
    override any inherited value of the member.  id gives the inherited
897
    value, mem is true for a member declaration, fn is true for a function
944
    value, mem is true for a member declaration, fn is true for a function
898
    declaration or a declaration which can't coexist with a function
945
    declaration or a declaration which can't coexist with a function
899
    declaration.  The null identifier is returned to indicate that id is
946
    declaration.  The null identifier is returned to indicate that id is
900
    to be overridden.
947
    to be overridden.
901
*/
948
*/
902
 
949
 
903
IDENTIFIER redecl_inherit
950
IDENTIFIER
904
    PROTO_N ( ( id, qual, mem, fn ) )
-
 
905
    PROTO_T ( IDENTIFIER id X QUALIFIER qual X int mem X int fn )
951
redecl_inherit(IDENTIFIER id, QUALIFIER qual, int mem, int fn)
906
{
952
{
907
    if ( !IS_NULL_id ( id ) ) {
953
	if (!IS_NULL_id(id)) {
908
	DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
954
		DECL_SPEC ds = DEREF_dspec(id_storage(id));
909
	if ( ds & dspec_alias ) {
955
		if (ds & dspec_alias) {
910
	    if ( fn && IS_id_function_etc ( id ) ) {
956
			if (fn && IS_id_function_etc(id)) {
911
		/* Everything is a function */
957
				/* Everything is a function */
912
		return ( id ) ;
958
				return (id);
913
	    }
959
			}
914
	    if ( mem && IS_id_class_name ( id ) ) {
960
			if (mem && IS_id_class_name(id)) {
915
		/* Allow for injected type names */
961
				/* Allow for injected type names */
916
		if ( ds & dspec_implicit ) return ( id ) ;
962
				if (ds & dspec_implicit) {
-
 
963
					return (id);
917
	    }
964
				}
-
 
965
			}
918
	    if ( qual == qual_none ) {
966
			if (qual == qual_none) {
919
		/* New declaration */
967
				/* New declaration */
920
		PTR ( LOCATION ) loc = id_loc ( id ) ;
968
				PTR(LOCATION) loc = id_loc(id);
-
 
969
				report(decl_loc,
921
		report ( decl_loc, ERR_dcl_nspace_udecl_multi ( id, loc ) ) ;
970
				       ERR_dcl_nspace_udecl_multi(id, loc));
922
		return ( NULL_id ) ;
971
				return (NULL_id);
923
	    }
972
			}
924
	}
973
		}
925
	if ( ds & dspec_inherit ) {
974
		if (ds & dspec_inherit) {
926
	    NAMESPACE ns ;
975
			NAMESPACE ns;
-
 
976
			if (mem) {
927
	    if ( mem ) return ( NULL_id ) ;
977
				return (NULL_id);
-
 
978
			}
928
	    ns = DEREF_nspace ( id_parent ( id ) ) ;
979
			ns = DEREF_nspace(id_parent(id));
929
	    id = DEREF_id ( id_alias ( id ) ) ;
980
			id = DEREF_id(id_alias(id));
930
	    report ( decl_loc, ERR_lookup_qual_decl ( id, ns ) ) ;
981
			report(decl_loc, ERR_lookup_qual_decl(id, ns));
931
	}
982
		}
932
    }
983
	}
933
    return ( id ) ;
984
	return (id);
934
}
985
}
935
 
986
 
936
 
987
 
937
/*
988
/*
938
    COPY AN IDENTIFIER
989
    COPY AN IDENTIFIER
939
 
990
 
940
    This routine creates a copy of the identifier id.  If type is 1
991
    This routine creates a copy of the identifier id.  If type is 1
941
    then any type components in id are copied using copy_typedef, if it
992
    then any type components in id are copied using copy_typedef, if it
942
    is 2 they are further expanded using expand_type.
993
    is 2 they are further expanded using expand_type.
943
*/
994
*/
944
 
995
 
945
IDENTIFIER copy_id
996
IDENTIFIER
946
    PROTO_N ( ( id, type ) )
-
 
947
    PROTO_T ( IDENTIFIER id X int type )
997
copy_id(IDENTIFIER id, int type)
948
{
998
{
949
    TYPE t ;
999
	TYPE t;
950
    ulong no ;
1000
	ulong no;
951
    ulong dno ;
1001
	ulong dno;
952
    HASHID nm ;
1002
	HASHID nm;
953
    unsigned tag ;
1003
	unsigned tag;
954
    LOCATION loc ;
1004
	LOCATION loc;
955
    NAMESPACE ns ;
1005
	NAMESPACE ns;
956
    DECL_SPEC ds ;
1006
	DECL_SPEC ds;
957
    IDENTIFIER lid ;
1007
	IDENTIFIER lid;
958
    IDENTIFIER cid = id ;
1008
	IDENTIFIER cid = id;
959
 
1009
 
960
    /* Examine various cases */
1010
	/* Examine various cases */
961
    if ( IS_NULL_id ( cid ) ) return ( NULL_id ) ;
1011
	if (IS_NULL_id(cid)) {
-
 
1012
		return (NULL_id);
-
 
1013
	}
962
    tag = TAG_id ( cid ) ;
1014
	tag = TAG_id(cid);
963
    switch ( tag ) {
1015
	switch (tag) {
964
 
-
 
965
	case id_class_name_tag :
1016
	case id_class_name_tag:
966
	case id_class_alias_tag :
1017
	case id_class_alias_tag:
967
	case id_enum_name_tag :
1018
	case id_enum_name_tag:
968
	case id_enum_alias_tag :
1019
	case id_enum_alias_tag:
969
	case id_type_alias_tag : {
1020
	case id_type_alias_tag: {
970
	    /* Types */
1021
		/* Types */
971
	    BASE_TYPE bt ;
1022
		BASE_TYPE bt;
972
	    DECONS_id_class_name_etc ( nm, ds, ns, loc, lid, no,
1023
		DECONS_id_class_name_etc(nm, ds, ns, loc, lid, no, dno, t, bt,
973
				       dno, t, bt, cid ) ;
1024
					 cid);
974
	    if ( type ) {
1025
		if (type) {
975
		t = copy_typedef ( cid, t, cv_none ) ;
1026
			t = copy_typedef(cid, t, cv_none);
976
		if ( type == 2 ) {
1027
			if (type == 2) {
977
		    t = expand_type ( t, 1 ) ;
1028
				t = expand_type(t, 1);
978
		    if ( tag == id_class_name_tag ) {
1029
				if (tag == id_class_name_tag) {
979
			/* Name already copied by copy_class */
1030
					/* Name already copied by copy_class */
980
			CLASS_TYPE ct ;
1031
					CLASS_TYPE ct;
981
			while ( IS_type_templ ( t ) ) {
1032
					while (IS_type_templ(t)) {
982
			    t = DEREF_type ( type_templ_defn ( t ) ) ;
1033
						t = DEREF_type(type_templ_defn(t));
983
			}
1034
					}
984
			ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
1035
					ct = DEREF_ctype(type_compound_defn(t));
985
			cid = DEREF_id ( ctype_name ( ct ) ) ;
1036
					cid = DEREF_id(ctype_name(ct));
986
			if ( !EQ_id ( cid, id ) ) {
1037
					if (!EQ_id(cid, id)) {
987
			    COPY_hashid ( id_name ( cid ), nm ) ;
1038
						COPY_hashid(id_name(cid), nm);
988
			    COPY_dspec ( id_storage ( cid ), ds ) ;
1039
						COPY_dspec(id_storage(cid), ds);
989
			    COPY_nspace ( id_parent ( cid ), ns ) ;
1040
						COPY_nspace(id_parent(cid), ns);
990
			    COPY_loc ( id_loc ( cid ), loc ) ;
1041
						COPY_loc(id_loc(cid), loc);
991
			    break ;
1042
						break;
-
 
1043
					}
-
 
1044
				}
-
 
1045
				if (tag != id_enum_name_tag) {
-
 
1046
					/* Find type alias tag */
-
 
1047
					unsigned ta = type_tag(t);
-
 
1048
					if (ta == type_compound_tag) {
-
 
1049
						tag = id_class_alias_tag;
-
 
1050
					} else if (ta == type_enumerate_tag) {
-
 
1051
						tag = id_enum_alias_tag;
-
 
1052
					} else {
-
 
1053
						tag = id_type_alias_tag;
-
 
1054
					}
-
 
1055
				}
-
 
1056
			}
-
 
1057
		}
-
 
1058
		MAKE_id_class_name_etc(tag, nm, ds, ns, loc, t, cid);
-
 
1059
		COPY_btype(id_class_name_etc_rep(cid), bt);
-
 
1060
		break;
-
 
1061
	}
-
 
1062
	case id_variable_tag:
-
 
1063
	case id_parameter_tag:
-
 
1064
	case id_stat_member_tag: {
-
 
1065
		/* Objects */
-
 
1066
		EXP a, b;
-
 
1067
		DECONS_id_variable_etc(nm, ds, ns, loc, lid, no, dno, t,
-
 
1068
				       a, b, cid);
-
 
1069
		if (type) {
-
 
1070
			t = copy_typedef(cid, t, cv_none);
-
 
1071
			if (type == 2) {
-
 
1072
				t = expand_type(t, 1);
-
 
1073
			}
-
 
1074
		}
-
 
1075
		MAKE_id_variable_etc(tag, nm, ds, ns, loc, t, cid);
-
 
1076
		COPY_exp(id_variable_etc_init(cid), a);
-
 
1077
		COPY_exp(id_variable_etc_term(cid), b);
-
 
1078
		break;
-
 
1079
	}
-
 
1080
	case id_function_tag:
-
 
1081
	case id_mem_func_tag:
-
 
1082
	case id_stat_mem_func_tag: {
-
 
1083
		/* Functions */
-
 
1084
		EXP a;
-
 
1085
		TYPE form;
-
 
1086
		IDENTIFIER over;
-
 
1087
		LIST(CLASS_TYPE)fr;
-
 
1088
		DECONS_id_function_etc(nm, ds, ns, loc, lid, no, dno, t,
-
 
1089
				       over, form, fr, a, cid);
-
 
1090
		if (type) {
-
 
1091
			t = copy_typedef(cid, t, cv_none);
-
 
1092
			if (type == 2) {
-
 
1093
				t = expand_type(t, 1);
992
			}
1094
			}
993
		    }
1095
		}
-
 
1096
		MAKE_id_function_etc(tag, nm, ds, ns, loc, t, over, cid);
-
 
1097
		COPY_type(id_function_etc_form(cid), form);
994
		    if ( tag != id_enum_name_tag ) {
1098
		COPY_exp(id_function_etc_defn(cid), a);
-
 
1099
		if (type == 2) {
995
			/* Find type alias tag */
1100
			/* Copy friend classes */
996
			unsigned ta = type_tag ( t ) ;
1101
			while (!IS_NULL_list(fr)) {
-
 
1102
				TYPE r = NULL_type;
997
			if ( ta == type_compound_tag ) {
1103
				CLASS_TYPE cr = DEREF_ctype(HEAD_list(fr));
998
			    tag = id_class_alias_tag ;
1104
				cr = expand_ctype(cr, 2, &r);
999
			} else if ( ta == type_enumerate_tag ) {
1105
				friend_function(cr, cid, 0);
1000
			    tag = id_enum_alias_tag ;
1106
				fr = TAIL_list(fr);
-
 
1107
			}
1001
			} else {
1108
		} else {
-
 
1109
			COPY_list(id_function_etc_chums(cid), fr);
-
 
1110
		}
-
 
1111
		break;
-
 
1112
	}
-
 
1113
	case id_member_tag: {
-
 
1114
		/* Members */
-
 
1115
		GRAPH gr;
-
 
1116
		OFFSET off;
-
 
1117
		DECONS_id_member(nm, ds, ns, loc, lid, no, dno, t, off, gr,
-
 
1118
				 cid);
-
 
1119
		if (type) {
-
 
1120
			t = copy_typedef(cid, t, cv_none);
-
 
1121
			if (type == 2) {
-
 
1122
				if (IS_hashid_anon(nm)) {
-
 
1123
					/* Allow for anonymous bitfields */
-
 
1124
					expand_anon_bitfield = 1;
-
 
1125
				}
1002
			    tag = id_type_alias_tag ;
1126
				t = expand_type(t, 1);
-
 
1127
				expand_anon_bitfield = 0;
1003
			}
1128
			}
1004
		    }
-
 
1005
		}
-
 
1006
	    }
-
 
1007
	    MAKE_id_class_name_etc ( tag, nm, ds, ns, loc, t, cid ) ;
-
 
1008
	    COPY_btype ( id_class_name_etc_rep ( cid ), bt ) ;
-
 
1009
	    break ;
-
 
1010
	}
-
 
1011
 
-
 
1012
	case id_variable_tag :
-
 
1013
	case id_parameter_tag :
-
 
1014
	case id_stat_member_tag : {
-
 
1015
	    /* Objects */
-
 
1016
	    EXP a, b ;
-
 
1017
	    DECONS_id_variable_etc ( nm, ds, ns, loc, lid, no, dno, t,
-
 
1018
				     a, b, cid ) ;
-
 
1019
	    if ( type ) {
-
 
1020
		t = copy_typedef ( cid, t, cv_none ) ;
-
 
1021
		if ( type == 2 ) t = expand_type ( t, 1 ) ;
-
 
1022
	    }
-
 
1023
	    MAKE_id_variable_etc ( tag, nm, ds, ns, loc, t, cid ) ;
-
 
1024
	    COPY_exp ( id_variable_etc_init ( cid ), a ) ;
-
 
1025
	    COPY_exp ( id_variable_etc_term ( cid ), b ) ;
-
 
1026
	    break ;
-
 
1027
	}
-
 
1028
 
-
 
1029
	case id_function_tag :
-
 
1030
	case id_mem_func_tag :
-
 
1031
	case id_stat_mem_func_tag : {
-
 
1032
	    /* Functions */
-
 
1033
	    EXP a ;
-
 
1034
	    TYPE form ;
-
 
1035
	    IDENTIFIER over ;
-
 
1036
	    LIST ( CLASS_TYPE ) fr ;
-
 
1037
	    DECONS_id_function_etc ( nm, ds, ns, loc, lid, no, dno, t,
-
 
1038
				     over, form, fr, a, cid ) ;
-
 
1039
	    if ( type ) {
-
 
1040
		t = copy_typedef ( cid, t, cv_none ) ;
-
 
1041
		if ( type == 2 ) t = expand_type ( t, 1 ) ;
-
 
1042
	    }
-
 
1043
	    MAKE_id_function_etc ( tag, nm, ds, ns, loc, t, over, cid ) ;
-
 
1044
	    COPY_type ( id_function_etc_form ( cid ), form ) ;
-
 
1045
	    COPY_exp ( id_function_etc_defn ( cid ), a ) ;
-
 
1046
	    if ( type == 2 ) {
-
 
1047
		/* Copy friend classes */
-
 
1048
		while ( !IS_NULL_list ( fr ) ) {
-
 
1049
		    TYPE r = NULL_type ;
-
 
1050
		    CLASS_TYPE cr = DEREF_ctype ( HEAD_list ( fr ) ) ;
-
 
1051
		    cr = expand_ctype ( cr, 2, &r ) ;
-
 
1052
		    friend_function ( cr, cid, 0 ) ;
-
 
1053
		    fr = TAIL_list ( fr ) ;
-
 
1054
		}
1129
		}
1055
	    } else {
1130
		MAKE_id_member(nm, ds, ns, loc, t, cid);
1056
		COPY_list ( id_function_etc_chums ( cid ), fr ) ;
1131
		COPY_graph(id_member_base(cid), gr);
1057
	    }
1132
		COPY_off(id_member_off(cid), off);
1058
	    break ;
1133
		break;
1059
	}
1134
	}
1060
 
-
 
1061
	case id_member_tag : {
1135
	case id_enumerator_tag: {
1062
	    /* Members */
1136
		/* Enumerators */
1063
	    GRAPH gr ;
1137
		EXP a;
1064
	    OFFSET off ;
1138
		ERROR err = NULL_err;
1065
	    DECONS_id_member ( nm, ds, ns, loc, lid, no, dno, t, off,
1139
		DECONS_id_enumerator(nm, ds, ns, loc, lid, no, dno, t, a, cid);
1066
			       gr, cid ) ;
-
 
1067
	    if ( type ) {
1140
		if (type == 2) {
1068
		t = copy_typedef ( cid, t, cv_none ) ;
1141
			/* Copy enumerator value */
1069
		if ( type == 2 ) {
1142
			TYPE s = expand_type(t, 1);
1070
		    if ( IS_hashid_anon ( nm ) ) {
1143
			a = copy_exp(a, t, s);
1071
			/* Allow for anonymous bitfields */
1144
			IGNORE make_nat_exp(a, &err);
1072
			expand_anon_bitfield = 1 ;
1145
			t = s;
1073
		    }
1146
		}
-
 
1147
		MAKE_id_enumerator(nm, ds, ns, loc, t, a, cid);
1074
		    t = expand_type ( t, 1 ) ;
1148
		if (!IS_NULL_err(err)) {
-
 
1149
			err = concat_error(err, ERR_dcl_enum_const(cid));
1075
		    expand_anon_bitfield = 0 ;
1150
			report(crt_loc, err);
1076
		}
1151
		}
1077
	    }
-
 
1078
	    MAKE_id_member ( nm, ds, ns, loc, t, cid ) ;
-
 
1079
	    COPY_graph ( id_member_base ( cid ), gr ) ;
-
 
1080
	    COPY_off ( id_member_off ( cid ), off ) ;
-
 
1081
	    break ;
1152
		break;
1082
	}
1153
	}
1083
 
-
 
1084
	case id_enumerator_tag : {
1154
	case id_token_tag: {
1085
	    /* Enumerators */
1155
		/* Tokens */
1086
	    EXP a ;
1156
		TOKEN sort;
1087
	    ERROR err = NULL_err ;
1157
		IDENTIFIER alt;
1088
	    DECONS_id_enumerator ( nm, ds, ns, loc, lid, no, dno,
1158
		DECONS_id_token(nm, ds, ns, loc, lid, no, dno, sort, alt, cid);
1089
				   t, a, cid ) ;
-
 
1090
	    if ( type == 2 ) {
1159
		if (type == 2) {
1091
		/* Copy enumerator value */
1160
			/* Expand token sort */
1092
		TYPE s = expand_type ( t, 1 ) ;
1161
			sort = expand_sort(sort, 1, 1);
1093
		a = copy_exp ( a, t, s ) ;
-
 
1094
		IGNORE make_nat_exp ( a, &err ) ;
-
 
1095
		t = s ;
-
 
1096
	    }
1162
		}
1097
	    MAKE_id_enumerator ( nm, ds, ns, loc, t, a, cid ) ;
1163
		MAKE_id_token(nm, ds, ns, loc, sort, alt, cid);
1098
	    if ( !IS_NULL_err ( err ) ) {
-
 
1099
		err = concat_error ( err, ERR_dcl_enum_const ( cid ) ) ;
-
 
1100
		report ( crt_loc, err ) ;
-
 
1101
	    }
-
 
1102
	    break ;
1164
		break;
1103
	}
1165
	}
1104
 
-
 
1105
	case id_token_tag : {
-
 
1106
	    /* Tokens */
-
 
1107
	    TOKEN sort ;
1166
	default:
1108
	    IDENTIFIER alt ;
-
 
1109
	    DECONS_id_token ( nm, ds, ns, loc, lid, no, dno,
-
 
1110
			      sort, alt, cid ) ;
-
 
1111
	    if ( type == 2 ) {
-
 
1112
		/* Expand token sort */
1167
		/* Don't copy other identifiers */
1113
		sort = expand_sort ( sort, 1, 1 ) ;
-
 
1114
	    }
-
 
1115
	    MAKE_id_token ( nm, ds, ns, loc, sort, alt, cid ) ;
-
 
1116
	    break ;
1168
		return (cid);
1117
	}
1169
	}
1118
 
1170
 
1119
	default : {
1171
	if (type != 2) {
1120
	    /* Don't copy other identifiers */
1172
		COPY_id(id_alias(cid), lid);
1121
	    return ( cid ) ;
1173
		COPY_ulong(id_no(cid), no);
-
 
1174
		COPY_ulong(id_dump(cid), dno);
1122
	}
1175
	}
1123
    }
-
 
1124
    if ( type != 2 ) {
-
 
1125
	COPY_id ( id_alias ( cid ), lid ) ;
-
 
1126
	COPY_ulong ( id_no ( cid ), no ) ;
-
 
1127
	COPY_ulong ( id_dump ( cid ), dno ) ;
-
 
1128
    }
-
 
1129
    return ( cid ) ;
1176
	return (cid);
1130
}
1177
}
1131
 
1178
 
1132
 
1179
 
1133
/*
1180
/*
1134
    CREATE AN IDENTIFIER ALIAS
1181
    CREATE AN IDENTIFIER ALIAS
1135
 
1182
 
1136
    This routine creates an alias for the identifier id in the namespace
1183
    This routine creates an alias for the identifier id in the namespace
1137
    ns.  fn gives a list of function which the alias will overload if
1184
    ns.  fn gives a list of function which the alias will overload if
1138
    it is a function.
1185
    it is a function.
1139
*/
1186
*/
1140
 
1187
 
1141
IDENTIFIER alias_id
1188
IDENTIFIER
1142
    PROTO_N ( ( id, ns, fn, rec ) )
-
 
1143
    PROTO_T ( IDENTIFIER id X NAMESPACE ns X IDENTIFIER fn X int rec )
1189
alias_id(IDENTIFIER id, NAMESPACE ns, IDENTIFIER fn, int rec)
1144
{
1190
{
1145
    IDENTIFIER cid = copy_id ( id, 1 ) ;
1191
	IDENTIFIER cid = copy_id(id, 1);
1146
    if ( !EQ_id ( cid, id ) ) {
1192
	if (!EQ_id(cid, id)) {
1147
	DECL_SPEC ds = DEREF_dspec ( id_storage ( cid ) ) ;
1193
		DECL_SPEC ds = DEREF_dspec(id_storage(cid));
1148
	DECL_SPEC acc = ( ds & dspec_access ) ;
1194
		DECL_SPEC acc = (ds & dspec_access);
1149
	if ( acc ) {
1195
		if (acc) {
1150
	    IDENTIFIER sid = DEREF_id ( nspace_name ( ns ) ) ;
1196
			IDENTIFIER sid = DEREF_id(nspace_name(ns));
1151
	    immediate_access ( sid, cid ) ;
1197
			immediate_access(sid, cid);
1152
	}
1198
		}
1153
	ds = ( ( ds & ~dspec_access ) | dspec_alias | crt_access ) ;
1199
		ds = ((ds & ~dspec_access) | dspec_alias | crt_access);
1154
	COPY_dspec ( id_storage ( cid ), ds ) ;
1200
		COPY_dspec(id_storage(cid), ds);
1155
	COPY_nspace ( id_parent ( cid ), ns ) ;
1201
		COPY_nspace(id_parent(cid), ns);
-
 
1202
		if (do_dump) {
1156
	if ( do_dump ) dump_alias ( cid, id, &crt_loc ) ;
1203
			dump_alias(cid, id, &crt_loc);
-
 
1204
		}
1157
	if ( IS_id_function_etc ( cid ) ) {
1205
		if (IS_id_function_etc(cid)) {
1158
	    /* Deal with overloaded functions */
1206
			/* Deal with overloaded functions */
1159
	    IDENTIFIER over ;
1207
			IDENTIFIER over;
1160
	    if ( rec ) {
1208
			if (rec) {
1161
		over = DEREF_id ( id_function_etc_over ( cid ) ) ;
1209
				over = DEREF_id(id_function_etc_over(cid));
1162
		if ( IS_NULL_id ( over ) ) {
1210
				if (IS_NULL_id(over)) {
1163
		    over = fn ;
1211
					over = fn;
1164
		} else {
1212
				} else {
1165
		    over = alias_id ( over, ns, fn, rec ) ;
1213
					over = alias_id(over, ns, fn, rec);
1166
		}
1214
				}
1167
	    } else {
1215
			} else {
1168
		over = fn ;
1216
				over = fn;
1169
	    }
1217
			}
1170
	    COPY_id ( id_function_etc_over ( cid ), over ) ;
1218
			COPY_id(id_function_etc_over(cid), over);
1171
	}
1219
		}
1172
    }
1220
	}
1173
    return ( cid ) ;
1221
	return (cid);
1174
}
1222
}
1175
 
1223
 
1176
 
1224
 
1177
/*
1225
/*
1178
    DUMMY DECLARATION SPECIFIER
1226
    DUMMY DECLARATION SPECIFIER
1179
 
1227
 
1180
    This value is used as a dummy declaration specifier in the adjusting
1228
    This value is used as a dummy declaration specifier in the adjusting
1181
    of overloaded functions.
1229
    of overloaded functions.
1182
*/
1230
*/
1183
 
1231
 
1184
#define dspec_mark	( ( DECL_SPEC ) 0x7fffffff )
1232
#define dspec_mark	((DECL_SPEC)0x7fffffff)
1185
 
1233
 
1186
 
1234
 
1187
/*
1235
/*
1188
    REMOVE HIDDEN FUNCTIONS
1236
    REMOVE HIDDEN FUNCTIONS
1189
 
1237
 
1190
    This routine adjusts the set of overloaded functions id by removing
1238
    This routine adjusts the set of overloaded functions id by removing
1191
    any with storage field equal to dspec_mark.
1239
    any with storage field equal to dspec_mark.
1192
*/
1240
*/
1193
 
1241
 
1194
static IDENTIFIER remove_functions
1242
static IDENTIFIER
1195
    PROTO_N ( ( id ) )
-
 
1196
    PROTO_T ( IDENTIFIER id )
1243
remove_functions(IDENTIFIER id)
1197
{
1244
{
1198
    if ( !IS_NULL_id ( id ) ) {
1245
	if (!IS_NULL_id(id)) {
1199
	DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
1246
		DECL_SPEC ds = DEREF_dspec(id_storage(id));
1200
	IDENTIFIER over = DEREF_id ( id_function_etc_over ( id ) ) ;
1247
		IDENTIFIER over = DEREF_id(id_function_etc_over(id));
1201
	over = remove_functions ( over ) ;
1248
		over = remove_functions(over);
1202
	if ( ds == dspec_mark ) {
1249
		if (ds == dspec_mark) {
1203
	    id = over ;
1250
			id = over;
1204
	} else {
1251
		} else {
1205
	    COPY_id ( id_function_etc_over ( id ), over ) ;
1252
			COPY_id(id_function_etc_over(id), over);
-
 
1253
		}
1206
	}
1254
	}
1207
    }
-
 
1208
    return ( id ) ;
1255
	return (id);
1209
}
1256
}
1210
 
1257
 
1211
 
1258
 
1212
/*
1259
/*
1213
    COMPARE HIDING FUNCTIONS
1260
    COMPARE HIDING FUNCTIONS
1214
 
1261
 
1215
    This routine compares two functions id and over, one declared in the
1262
    This routine compares two functions id and over, one declared in the
1216
    normal fashion and the other by a using-declaration.  It returns
1263
    normal fashion and the other by a using-declaration.  It returns
1217
    true if the former overrides the latter.
1264
    true if the former overrides the latter.
1218
*/
1265
*/
1219
 
1266
 
1220
static int compare_functions
1267
static int
1221
    PROTO_N ( ( id, over, mem ) )
-
 
1222
    PROTO_T ( IDENTIFIER id X IDENTIFIER over X int mem )
1268
compare_functions(IDENTIFIER id, IDENTIFIER over, int mem)
1223
{
1269
{
1224
    TYPE t = DEREF_type ( id_function_etc_type ( id ) ) ;
1270
	TYPE t = DEREF_type(id_function_etc_type(id));
1225
    TYPE s = DEREF_type ( id_function_etc_type ( over ) ) ;
1271
	TYPE s = DEREF_type(id_function_etc_type(over));
1226
    int eq = eq_func_type ( t, s, 1, 0 ) ;
1272
	int eq = eq_func_type(t, s, 1, 0);
1227
    if ( eq ) {
1273
	if (eq) {
1228
	/* Equal parameter types */
1274
		/* Equal parameter types */
-
 
1275
		if (mem) {
1229
	if ( mem ) return ( 1 ) ;
1276
			return (1);
1230
    }
1277
		}
-
 
1278
	}
1231
    if ( eq >= 2 ) {
1279
	if (eq >= 2) {
1232
	/* Equal types */
1280
		/* Equal types */
1233
	PTR ( LOCATION ) loc = id_loc ( over ) ;
1281
		PTR(LOCATION)loc = id_loc(over);
1234
	report ( crt_loc, ERR_dcl_nspace_udecl_multi ( over, loc ) ) ;
1282
		report(crt_loc, ERR_dcl_nspace_udecl_multi(over, loc));
1235
	return ( 1 ) ;
1283
		return (1);
1236
    }
1284
	}
1237
    return ( 0 ) ;
1285
	return (0);
1238
}
1286
}
1239
 
1287
 
1240
 
1288
 
1241
/*
1289
/*
1242
    MARK HIDDEN FUNCTIONS
1290
    MARK HIDDEN FUNCTIONS
1243
 
1291
 
1244
    This routine marks any functions which hide, or are hidden by, id in
1292
    This routine marks any functions which hide, or are hidden by, id in
1245
    its set of overloaded functions.  mem is true for member functions.
1293
    its set of overloaded functions.  mem is true for member functions.
1246
    Any hidden function is marked by setting its storage field to the
1294
    Any hidden function is marked by setting its storage field to the
1247
    value dspec_mark.
1295
    value dspec_mark.
1248
*/
1296
*/
1249
 
1297
 
1250
static int mark_functions
1298
static int
1251
    PROTO_N ( ( id, mem ) )
-
 
1252
    PROTO_T ( IDENTIFIER id X int mem )
1299
mark_functions(IDENTIFIER id, int mem)
1253
{
1300
{
1254
    int ret = 0 ;
1301
    int ret = 0;
1255
    DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
1302
    DECL_SPEC ds = DEREF_dspec(id_storage(id));
1256
    if ( ds != dspec_mark ) {
1303
    if (ds != dspec_mark) {
1257
	IDENTIFIER over = DEREF_id ( id_function_etc_over ( id ) ) ;
1304
	IDENTIFIER over = DEREF_id(id_function_etc_over(id));
1258
	while ( !IS_NULL_id ( over ) ) {
1305
	while (!IS_NULL_id(over)) {
1259
	    DECL_SPEC pds = DEREF_dspec ( id_storage ( over ) ) ;
1306
	    DECL_SPEC pds = DEREF_dspec(id_storage(over));
1260
	    if ( pds != dspec_mark ) {
1307
	    if (pds != dspec_mark) {
1261
		if ( ds & dspec_alias ) {
1308
		if (ds & dspec_alias) {
1262
		    if ( pds & dspec_alias ) {
1309
		    if (pds & dspec_alias) {
1263
			/* Both are using declarations */
1310
			/* Both are using declarations */
1264
			IDENTIFIER a = DEREF_id ( id_alias ( id ) ) ;
1311
			IDENTIFIER a = DEREF_id(id_alias(id));
1265
			IDENTIFIER b = DEREF_id ( id_alias ( over ) ) ;
1312
			IDENTIFIER b = DEREF_id(id_alias(over));
1266
			if ( EQ_id ( a, b ) ) {
1313
			if (EQ_id(a, b)) {
1267
			    /* Duplicate declarations */
1314
			    /* Duplicate declarations */
1268
			    if ( mem ) {
1315
			    if (mem) {
1269
				ERROR err ;
1316
				ERROR err;
1270
				PTR ( LOCATION ) loc = id_loc ( over ) ;
1317
				PTR(LOCATION) loc = id_loc(over);
1271
				err = ERR_class_mem_redecl ( over, loc ) ;
1318
				err = ERR_class_mem_redecl(over, loc);
1272
				report ( crt_loc, err ) ;
1319
				report(crt_loc, err);
1273
			    }
1320
			    }
1274
			    COPY_dspec ( id_storage ( over ), dspec_mark ) ;
1321
			    COPY_dspec(id_storage(over), dspec_mark);
1275
			    ret++ ;
1322
			    ret++;
1276
			}
1323
			}
1277
		    } else {
1324
		    } else {
1278
			/* The first is a using declaration */
1325
			/* The first is a using declaration */
1279
			if ( compare_functions ( id, over, mem ) ) {
1326
			if (compare_functions(id, over, mem)) {
1280
			    COPY_dspec ( id_storage ( id ), dspec_mark ) ;
1327
			    COPY_dspec(id_storage(id), dspec_mark);
1281
			    ret++ ;
1328
			    ret++;
1282
			}
1329
			}
1283
		    }
1330
		    }
1284
		} else if ( pds & dspec_alias ) {
1331
		} else if (pds & dspec_alias) {
1285
		    /* The second is a using declaration */
1332
		    /* The second is a using declaration */
1286
		    if ( compare_functions ( id, over, mem ) ) {
1333
		    if (compare_functions(id, over, mem)) {
1287
			COPY_dspec ( id_storage ( over ), dspec_mark ) ;
1334
			COPY_dspec(id_storage(over), dspec_mark);
1288
			ret++ ;
1335
			ret++;
1289
			break ;
1336
			break;
1290
		    }
1337
		    }
1291
		}
1338
		}
1292
	    }
1339
	    }
1293
	    over = DEREF_id ( id_function_etc_over ( over ) ) ;
1340
	    over = DEREF_id(id_function_etc_over(over));
1294
	}
1341
	}
1295
    }
1342
    }
1296
    return ( ret ) ;
1343
    return (ret);
1297
}
1344
}
1298
 
1345
 
1299
 
1346
 
1300
/*
1347
/*
1301
    HANDLE HIDDEN FUNCTIONS WITH USING DECLARATIONS
1348
    HANDLE HIDDEN FUNCTIONS WITH USING DECLARATIONS
Line 1304... Line 1351...
1304
    of member functions is somewhat complex.  It is implemented by this
1351
    of member functions is somewhat complex.  It is implemented by this
1305
    routine which adjusts the declarations of the overloaded functions id
1352
    routine which adjusts the declarations of the overloaded functions id
1306
    up to the existing declarations over.  mem is true for member functions.
1353
    up to the existing declarations over.  mem is true for member functions.
1307
*/
1354
*/
1308
 
1355
 
1309
IDENTIFIER hide_functions
1356
IDENTIFIER
1310
    PROTO_N ( ( id, over, mem ) )
-
 
1311
    PROTO_T ( IDENTIFIER id X IDENTIFIER over X int mem )
1357
hide_functions(IDENTIFIER id, IDENTIFIER over, int mem)
1312
{
1358
{
1313
    if ( !IS_NULL_id ( over ) ) {
1359
	if (!IS_NULL_id(over)) {
1314
	int marked = 0 ;
1360
		int marked = 0;
1315
	IDENTIFIER pid = id ;
1361
		IDENTIFIER pid = id;
1316
	while ( !EQ_id ( pid, over ) ) {
1362
		while (!EQ_id(pid, over)) {
1317
	    marked += mark_functions ( pid, mem ) ;
1363
			marked += mark_functions(pid, mem);
-
 
1364
			pid = DEREF_id(id_function_etc_over(pid));
-
 
1365
		}
-
 
1366
		if (marked) {
-
 
1367
			id = remove_functions(id);
-
 
1368
		}
-
 
1369
		pid = id;
-
 
1370
		while (!IS_NULL_id(pid)) {
-
 
1371
			/* Mark template functions */
-
 
1372
			DECL_SPEC ds = DEREF_dspec(id_storage(pid));
-
 
1373
			if (ds & dspec_template) {
-
 
1374
				templ_func_decl(id);
-
 
1375
				break;
-
 
1376
			}
1318
	    pid = DEREF_id ( id_function_etc_over ( pid ) ) ;
1377
			pid = DEREF_id(id_function_etc_over(pid));
-
 
1378
		}
1319
	}
1379
	}
1320
	if ( marked ) id = remove_functions ( id ) ;
-
 
1321
	pid = id ;
-
 
1322
	while ( !IS_NULL_id ( pid ) ) {
-
 
1323
	    /* Mark template functions */
-
 
1324
	    DECL_SPEC ds = DEREF_dspec ( id_storage ( pid ) ) ;
-
 
1325
	    if ( ds & dspec_template ) {
-
 
1326
		templ_func_decl ( id ) ;
-
 
1327
		break ;
-
 
1328
	    }
-
 
1329
	    pid = DEREF_id ( id_function_etc_over ( pid ) ) ;
-
 
1330
	}
-
 
1331
    }
-
 
1332
    return ( id ) ;
1380
	return (id);
1333
}
1381
}
1334
 
1382
 
1335
 
1383
 
1336
/*
1384
/*
1337
    CHECK THE VISIBILITY OF AN IDENTIFIER
1385
    CHECK THE VISIBILITY OF AN IDENTIFIER
1338
 
1386
 
1339
    A member name in a using declaration should be visible from a direct
1387
    A member name in a using declaration should be visible from a direct
1340
    base class.  This routine checks whether the member id meets this
1388
    base class.  This routine checks whether the member id meets this
1341
    criterion by comparing it with its look-up in the direct base
1389
    criterion by comparing it with its look-up in the direct base
1342
    classes, pid.
1390
    classes, pid.
1343
*/
1391
*/
1344
 
1392
 
1345
static int using_visible
1393
static int
1346
    PROTO_N ( ( id, pid ) )
-
 
1347
    PROTO_T ( IDENTIFIER id X IDENTIFIER pid )
1394
using_visible(IDENTIFIER id, IDENTIFIER pid)
1348
{
1395
{
1349
    while ( !IS_NULL_id ( pid ) ) {
1396
	while (!IS_NULL_id(pid)) {
1350
	IDENTIFIER qid = DEREF_id ( id_alias ( pid ) ) ;
1397
		IDENTIFIER qid = DEREF_id(id_alias(pid));
1351
	if ( EQ_id ( qid, id ) ) return ( 1 ) ;
1398
		if (EQ_id(qid, id)) {
-
 
1399
			return (1);
-
 
1400
		}
1352
	switch ( TAG_id ( pid ) ) {
1401
		switch (TAG_id(pid)) {
1353
	    case id_function_tag :
1402
		case id_function_tag:
1354
	    case id_mem_func_tag :
1403
		case id_mem_func_tag:
1355
	    case id_stat_mem_func_tag : {
1404
		case id_stat_mem_func_tag:
1356
		/* Check overloaded functions */
1405
			/* Check overloaded functions */
1357
		pid = DEREF_id ( id_function_etc_over ( pid ) ) ;
1406
			pid = DEREF_id(id_function_etc_over(pid));
1358
		break ;
1407
			break;
1359
	    }
-
 
1360
	    case id_ambig_tag : {
1408
		case id_ambig_tag: {
1361
		/* Check ambiguous identifiers */
1409
			/* Check ambiguous identifiers */
1362
		LIST ( IDENTIFIER ) pids ;
1410
			LIST(IDENTIFIER)pids;
1363
		pids = DEREF_list ( id_ambig_ids ( pid ) ) ;
1411
			pids = DEREF_list(id_ambig_ids(pid));
1364
		while ( !IS_NULL_list ( pids ) ) {
1412
			while (!IS_NULL_list(pids)) {
1365
		    pid = DEREF_id ( HEAD_list ( pids ) ) ;
1413
				pid = DEREF_id(HEAD_list(pids));
1366
		    if ( using_visible ( id, pid ) ) return ( 1 ) ;
1414
				if (using_visible(id, pid)) {
-
 
1415
					return (1);
-
 
1416
				}
1367
		    pids = TAIL_list ( pids ) ;
1417
				pids = TAIL_list(pids);
1368
		}
1418
			}
1369
		return ( 0 ) ;
1419
			return (0);
1370
	    }
1420
		}
1371
	    default : {
1421
		default:
1372
		/* Other identifiers */
1422
			/* Other identifiers */
1373
		return ( 0 ) ;
1423
			return (0);
1374
	    }
1424
		}
1375
	}
1425
	}
1376
    }
-
 
1377
    return ( 0 ) ;
1426
	return (0);
1378
}
1427
}
1379
 
1428
 
1380
 
1429
 
1381
/*
1430
/*
1382
    PROCESS A CLASS USING DECLARATION
1431
    PROCESS A CLASS USING DECLARATION
1383
 
1432
 
1384
    This routine processes a using-declaration of the identifier id in
1433
    This routine processes a using-declaration of the identifier id in
1385
    the case when this declaration is a member-declaration.
1434
    the case when this declaration is a member-declaration.
1477
	}
1582
	}
1478
    }
-
 
1479
 
1583
 
1480
    /* Find inherited member */
1584
	/* Check declarations */
-
 
1585
	nm = DEREF_hashid(id_name(id));
1481
    id = search_subfield ( cns, gr, id ) ;
1586
	mem = search_member(cns, nm, 1);
-
 
1587
	type = is_tagged_type(id);
-
 
1588
	if (type) {
-
 
1589
		DECL_SPEC ds = DEREF_dspec(id_storage(id));
-
 
1590
		if (ds & dspec_template) {
-
 
1591
			pid = DEREF_id(member_id(mem));
-
 
1592
		} else {
-
 
1593
			pid = type_member(mem, 3);
-
 
1594
		}
-
 
1595
	} else {
-
 
1596
		pid = DEREF_id(member_id(mem));
-
 
1597
		if (!IS_id_nspace_name_etc(id)) {
-
 
1598
			if (!IS_NULL_id(pid) && is_tagged_type(pid)) {
-
 
1599
				/* Allow hiding of non-template classes */
-
 
1600
				DECL_SPEC ds = DEREF_dspec(id_storage(pid));
-
 
1601
				if (!(ds & dspec_template)) {
-
 
1602
					pid = NULL_id;
-
 
1603
				}
-
 
1604
			}
-
 
1605
		}
-
 
1606
	}
-
 
1607
	if (!IS_NULL_id(pid)) {
-
 
1608
		IDENTIFIER qid = DEREF_id(id_alias(pid));
-
 
1609
		if (EQ_id(id, qid)) {
-
 
1610
			/* Redeclaration of existing meaning */
-
 
1611
			if (EQ_id(id, pid)) {
-
 
1612
				report(crt_loc, ERR_dcl_nspace_udecl_mem(id));
-
 
1613
			}
-
 
1614
			return (pid);
-
 
1615
		}
-
 
1616
		if (IS_id_function_etc(id) && IS_id_function_etc(pid)) {
-
 
1617
			/* Both new and old meanings are functions */
-
 
1618
			/* EMPTY */
-
 
1619
		} else {
-
 
1620
			/* Invalid redeclaration */
-
 
1621
			PTR(LOCATION) loc = id_loc(pid);
-
 
1622
			ERROR err = ERR_dcl_nspace_udecl_multi(pid, loc);
-
 
1623
			report(crt_loc, err);
-
 
1624
			pid = NULL_id;
-
 
1625
		}
-
 
1626
	}
-
 
1627
 
-
 
1628
	/* Create the alias */
1482
    aid = alias_id ( id, cns, pid, 1 ) ;
1629
	id = alias_id(id, cns, pid, 1);
1483
    if ( !IS_NULL_id ( pid ) ) {
1630
	if (!IS_NULL_id(pid)) {
1484
	/* Deal with function hiding */
1631
		/* Deal with function hiding */
1485
	aid = hide_functions ( aid, pid, 1 ) ;
1632
		id = hide_functions(id, pid, 0);
1486
    }
1633
	}
1487
    adjust_access ( id, crt_access, 1 ) ;
-
 
1488
    if ( type ) {
1634
	if (type) {
1489
	set_type_member ( mem, aid ) ;
1635
		set_type_member(mem, id);
1490
    } else {
1636
	} else {
1491
	set_member ( mem, aid ) ;
1637
		set_member(mem, id);
1492
    }
1638
	}
1493
    return ( aid ) ;
1639
	return (id);
1494
}
1640
}
1495
 
1641
 
1496
 
1642
 
1497
/*
1643
/*
1498
    PROCESS A NAMESPACE USING DECLARATION
1644
    PROCESS A USING DECLARATION
1499
 
1645
 
1500
    This routine processes a using-declaration of the identifier id in
1646
    This routine processes a using-declaration of the identifier id.  Note
1501
    the case when this declaration is not a member-declaration.
1647
    that this includes the access declarations used to modify access to
-
 
1648
    class members.
1502
*/
1649
*/
1503
 
1650
 
1504
static IDENTIFIER using_name
1651
IDENTIFIER
1505
    PROTO_N ( ( id ) )
-
 
1506
    PROTO_T ( IDENTIFIER id )
1652
using_identifier(IDENTIFIER id)
1507
{
1653
{
-
 
1654
	/* Identifier must be qualified */
1508
    int type ;
1655
	MEMBER mem;
1509
    HASHID nm ;
1656
	HASHID unm;
1510
    MEMBER mem ;
1657
	IDENTIFIER cid;
1511
    IDENTIFIER pid ;
1658
	IDENTIFIER uid = id;
1512
 
-
 
1513
    /* Check the identifier */
-
 
1514
    NAMESPACE cns = crt_namespace ;
-
 
1515
    NAMESPACE ns = DEREF_nspace ( id_parent ( id ) ) ;
1659
	NAMESPACE uns = DEREF_nspace(id_parent(uid));
1516
    if ( IS_nspace_ctype ( ns ) ) {
-
 
1517
	/* id denotes a class member */
-
 
1518
	report ( crt_loc, ERR_dcl_nspace_udecl_id ( id ) ) ;
-
 
1519
	switch ( TAG_id ( id ) ) {
-
 
1520
	    case id_member_tag :
-
 
1521
	    case id_stat_member_tag :
-
 
1522
	    case id_mem_func_tag :
1660
	uid = constr_name(uns, uid);
1523
	    case id_stat_mem_func_tag : {
-
 
1524
		/* Don't even try in these cases */
-
 
1525
		return ( NULL_id ) ;
-
 
1526
	    }
-
 
1527
	}
-
 
1528
    }
-
 
1529
 
-
 
1530
    /* Check declarations */
-
 
1531
    nm = DEREF_hashid ( id_name ( id ) ) ;
1661
	unm = DEREF_hashid(id_name(uid));
1532
    mem = search_member ( cns, nm, 1 ) ;
-
 
1533
    type = is_tagged_type ( id ) ;
-
 
1534
    if ( type ) {
-
 
1535
	DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
-
 
1536
	if ( ds & dspec_template ) {
1662
	if (crt_id_qualifier == qual_none) {
1537
	    pid = DEREF_id ( member_id ( mem ) ) ;
1663
		report(crt_loc, ERR_dcl_nspace_udecl_unqual());
1538
	} else {
1664
		return (uid);
1539
	    pid = type_member ( mem, 3 ) ;
-
 
1540
	}
-
 
1541
    } else {
-
 
1542
	pid = DEREF_id ( member_id ( mem ) ) ;
-
 
1543
	if ( !IS_id_nspace_name_etc ( id ) ) {
-
 
1544
	    if ( !IS_NULL_id ( pid ) && is_tagged_type ( pid ) ) {
-
 
1545
		/* Allow hiding of non-template classes */
-
 
1546
		DECL_SPEC ds = DEREF_dspec ( id_storage ( pid ) ) ;
-
 
1547
		if ( !( ds & dspec_template ) ) pid = NULL_id ;
-
 
1548
	    }
-
 
1549
	}
1665
	}
1550
    }
1666
 
-
 
1667
	/* Report undefined and ambiguous identifiers */
1551
    if ( !IS_NULL_id ( pid ) ) {
1668
	switch (TAG_id(uid)) {
-
 
1669
	case id_ambig_tag: {
-
 
1670
		/* Introduce all the ambiguous meanings */
1552
	IDENTIFIER qid = DEREF_id ( id_alias ( pid ) ) ;
1671
		LIST(IDENTIFIER) pids = DEREF_list(id_ambig_ids(uid));
1553
	if ( EQ_id ( id, qid ) ) {
1672
		while (!IS_NULL_list(pids)) {
-
 
1673
			IDENTIFIER pid = DEREF_id(HEAD_list(pids));
1554
	    /* Redeclaration of existing meaning */
1674
			IGNORE using_identifier(pid);
1555
	    if ( EQ_id ( id, pid ) ) {
1675
			pids = TAIL_list(pids);
-
 
1676
		}
1556
		report ( crt_loc, ERR_dcl_nspace_udecl_mem ( id ) ) ;
1677
		uid = find_qual_id(crt_namespace, unm, 0, 0);
-
 
1678
		return (uid);
1557
	    }
1679
	}
-
 
1680
	case id_undef_tag:
-
 
1681
		/* Report undeclared identifiers */
-
 
1682
		report(crt_loc, ERR_lookup_qual_undef(unm, uns));
1558
	    return ( pid ) ;
1683
		return (uid);
1559
	}
1684
	}
1560
	if ( IS_id_function_etc ( id ) && IS_id_function_etc ( pid ) ) {
-
 
-
 
1685
 
1561
	    /* Both new and old meanings are functions */
1686
	/* Can have constructors or destructors */
1562
	    /* EMPTY */
1687
	switch (TAG_hashid(unm)) {
1563
	} else {
1688
	case hashid_constr_tag:
1564
	    /* Invalid redeclaration */
1689
	case hashid_destr_tag:
1565
	    PTR ( LOCATION ) loc = id_loc ( pid ) ;
-
 
1566
	    ERROR err = ERR_dcl_nspace_udecl_multi ( pid, loc ) ;
1690
		report(crt_loc, ERR_dcl_nspace_udecl_constr(uid));
1567
	    report ( crt_loc, err ) ;
-
 
1568
	    pid = NULL_id ;
1691
		return (uid);
1569
	}
1692
	}
1570
    }
-
 
1571
 
1693
 
1572
    /* Create the alias */
-
 
1573
    id = alias_id ( id, cns, pid, 1 ) ;
-
 
1574
    if ( !IS_NULL_id ( pid ) ) {
-
 
1575
	/* Deal with function hiding */
1694
	/* Check for hidden type names */
1576
	id = hide_functions ( id, pid, 0 ) ;
1695
	mem = search_member(uns, unm, 0);
1577
    }
-
 
1578
    if ( type ) {
-
 
1579
	set_type_member ( mem, id ) ;
1696
	cid = type_member(mem, 1);
1580
    } else {
-
 
1581
	set_member ( mem, id ) ;
-
 
1582
    }
-
 
1583
    return ( id ) ;
-
 
1584
}
-
 
1585
 
-
 
1586
 
-
 
1587
/*
-
 
1588
    PROCESS A USING DECLARATION
-
 
1589
 
-
 
1590
    This routine processes a using-declaration of the identifier id.  Note
-
 
1591
    that this includes the access declarations used to modify access to
-
 
1592
    class members.
-
 
1593
*/
-
 
1594
 
-
 
1595
IDENTIFIER using_identifier
-
 
1596
    PROTO_N ( ( id ) )
-
 
1597
    PROTO_T ( IDENTIFIER id )
-
 
1598
{
-
 
1599
    /* Identifier must be qualified */
-
 
1600
    MEMBER mem ;
-
 
1601
    HASHID unm ;
-
 
1602
    IDENTIFIER cid ;
-
 
1603
    IDENTIFIER uid = id ;
-
 
1604
    NAMESPACE uns = DEREF_nspace ( id_parent ( uid ) ) ;
-
 
1605
    uid = constr_name ( uns, uid ) ;
-
 
1606
    unm = DEREF_hashid ( id_name ( uid ) ) ;
-
 
1607
    if ( crt_id_qualifier == qual_none ) {
-
 
1608
	report ( crt_loc, ERR_dcl_nspace_udecl_unqual () ) ;
-
 
1609
	return ( uid ) ;
-
 
1610
    }
-
 
1611
 
-
 
1612
    /* Report undefined and ambiguous identifiers */
-
 
1613
    switch ( TAG_id ( uid ) ) {
1697
	if (EQ_id(cid, uid)) {
1614
	case id_ambig_tag : {
-
 
1615
	    /* Introduce all the ambiguous meanings */
-
 
1616
	    LIST ( IDENTIFIER ) pids = DEREF_list ( id_ambig_ids ( uid ) ) ;
-
 
1617
	    while ( !IS_NULL_list ( pids ) ) {
-
 
1618
		IDENTIFIER pid = DEREF_id ( HEAD_list ( pids ) ) ;
-
 
1619
		IGNORE using_identifier ( pid ) ;
-
 
1620
		pids = TAIL_list ( pids ) ;
1698
		cid = NULL_id;
1621
	    }
-
 
1622
	    uid = find_qual_id ( crt_namespace, unm, 0, 0 ) ;
-
 
1623
	    return ( uid ) ;
-
 
1624
	}
-
 
1625
	case id_undef_tag : {
-
 
1626
	    /* Report undeclared identifiers */
-
 
1627
	    report ( crt_loc, ERR_lookup_qual_undef ( unm, uns ) ) ;
-
 
1628
	    return ( uid ) ;
-
 
1629
	}
-
 
1630
    }
-
 
1631
 
-
 
1632
    /* Can have constructors or destructors */
-
 
1633
    switch ( TAG_hashid ( unm ) ) {
-
 
1634
	case hashid_constr_tag :
-
 
1635
	case hashid_destr_tag : {
-
 
1636
	    report ( crt_loc, ERR_dcl_nspace_udecl_constr ( uid ) ) ;
-
 
1637
	    return ( uid ) ;
-
 
1638
	}
1699
	}
1639
    }
-
 
1640
 
-
 
1641
    /* Check for hidden type names */
-
 
1642
    mem = search_member ( uns, unm, 0 ) ;
-
 
1643
    cid = type_member ( mem, 1 ) ;
-
 
1644
    if ( EQ_id ( cid, uid ) ) cid = NULL_id ;
-
 
1645
 
1700
 
1646
    /* Process the declaration */
1701
	/* Process the declaration */
1647
    if ( in_class_defn ) {
1702
	if (in_class_defn) {
1648
	if ( !IS_NULL_id ( cid ) ) {
1703
		if (!IS_NULL_id(cid)) {
1649
	    IGNORE using_member ( cid, 1 ) ;
1704
			IGNORE using_member(cid, 1);
1650
	}
1705
		}
1651
	uid = using_member ( uid, 0 ) ;
1706
		uid = using_member(uid, 0);
1652
    } else {
1707
	} else {
1653
	if ( !IS_NULL_id ( cid ) ) {
1708
		if (!IS_NULL_id(cid)) {
1654
	    cid = DEREF_id ( id_alias ( cid ) ) ;
1709
			cid = DEREF_id(id_alias(cid));
1655
	    IGNORE using_name ( cid ) ;
1710
			IGNORE using_name(cid);
1656
	}
1711
		}
1657
	uid = DEREF_id ( id_alias ( uid ) ) ;
1712
		uid = DEREF_id(id_alias(uid));
1658
	uid = using_name ( uid ) ;
1713
		uid = using_name(uid);
1659
    }
1714
	}
1660
    if ( IS_NULL_id ( uid ) ) {
1715
	if (IS_NULL_id(uid)) {
1661
	uid = id ;
1716
		uid = id;
1662
    } else {
1717
	} else {
1663
	/* Check for hiding */
1718
		/* Check for hiding */
1664
	if ( option ( OPT_decl_hide ) ) {
1719
		if (option(OPT_decl_hide)) {
1665
	    switch ( TAG_id ( id ) ) {
1720
			switch (TAG_id(id)) {
1666
		case id_variable_tag :
1721
			case id_variable_tag:
1667
		case id_function_tag : {
1722
			case id_function_tag:
1668
		    check_hiding ( uid ) ;
1723
				check_hiding(uid);
1669
		    break ;
1724
				break;
1670
		}
1725
			}
1671
	    }
1726
		}
1672
	}
1727
	}
1673
    }
-
 
1674
    return ( uid ) ;
1728
	return (uid);
1675
}
1729
}
1676
 
1730
 
1677
 
1731
 
1678
/*
1732
/*
1679
    PROCESS A USING TYPENAME DECLARATION
1733
    PROCESS A USING TYPENAME DECLARATION
1680
 
1734
 
1681
    This routine processes a using-declaration involving the type t
1735
    This routine processes a using-declaration involving the type t
1682
    declared using typename.
1736
    declared using typename.
1683
*/
1737
*/
1684
 
1738
 
1685
void using_typename
1739
void
1686
    PROTO_N ( ( t ) )
-
 
1687
    PROTO_T ( TYPE t )
1740
using_typename(TYPE t)
1688
{
1741
{
1689
    UNUSED ( t ) ;
1742
	UNUSED(t);
1690
    return ;
1743
	return;
1691
}
1744
}
1692
 
1745
 
1693
 
1746
 
1694
/*
1747
/*
1695
    REDECLARE AN IDENTIFIER
1748
    REDECLARE AN IDENTIFIER
1696
 
1749
 
1697
    This routine redeclares the identifier id in the namespace ns.
1750
    This routine redeclares the identifier id in the namespace ns.
1698
*/
1751
*/
1699
 
1752
 
1700
IDENTIFIER redeclare_id
1753
IDENTIFIER
1701
    PROTO_N ( ( ns, id ) )
-
 
1702
    PROTO_T ( NAMESPACE ns X IDENTIFIER id )
1754
redeclare_id(NAMESPACE ns, IDENTIFIER id)
1703
{
1755
{
1704
    IDENTIFIER old_id ;
1756
	IDENTIFIER old_id;
1705
    int cl = is_tagged_type ( id ) ;
1757
	int cl = is_tagged_type(id);
1706
    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
1758
	HASHID nm = DEREF_hashid(id_name(id));
1707
    MEMBER mem = search_member ( ns, nm, 1 ) ;
1759
	MEMBER mem = search_member(ns, nm, 1);
1708
    DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
1760
	DECL_SPEC ds = DEREF_dspec(id_storage(id));
1709
    if ( cl ) {
1761
	if (cl) {
1710
	old_id = type_member ( mem, 3 ) ;
1762
		old_id = type_member(mem, 3);
1711
    } else {
1763
	} else {
1712
	old_id = DEREF_id ( member_id ( mem ) ) ;
1764
		old_id = DEREF_id(member_id(mem));
1713
    }
1765
	}
1714
    if ( !IS_NULL_id ( old_id ) ) {
1766
	if (!IS_NULL_id(old_id)) {
1715
	PTR ( LOCATION ) loc = id_loc ( old_id ) ;
1767
		PTR(LOCATION) loc = id_loc(old_id);
1716
	report ( crt_loc, ERR_basic_odr_decl ( old_id, loc ) ) ;
1768
		report(crt_loc, ERR_basic_odr_decl(old_id, loc));
1717
    }
1769
	}
1718
    if ( cl ) {
1770
	if (cl) {
1719
	set_type_member ( mem, id ) ;
1771
		set_type_member(mem, id);
1720
    } else {
1772
	} else {
1721
	set_member ( mem, id ) ;
1773
		set_member(mem, id);
1722
    }
1774
	}
1723
    ds |= dspec_reserve ;
1775
	ds |= dspec_reserve;
1724
    COPY_dspec ( id_storage ( id ), ds ) ;
1776
	COPY_dspec(id_storage(id), ds);
1725
    COPY_nspace ( id_parent ( id ), ns ) ;
1777
	COPY_nspace(id_parent(id), ns);
1726
    return ( id ) ;
1778
	return (id);
1727
}
1779
}
1728
 
1780
 
1729
 
1781
 
1730
/*
1782
/*
1731
    CHECK ANONYMOUS UNION MEMBER
1783
    CHECK ANONYMOUS UNION MEMBER
1732
 
1784
 
1733
    This routine checks whether the identifier id is member of an
1785
    This routine checks whether the identifier id is member of an
1734
    anonymous union.
1786
    anonymous union.
1735
*/
1787
*/
1736
 
1788
 
1737
int is_anon_member
1789
int
1738
    PROTO_N ( ( id ) )
-
 
1739
    PROTO_T ( IDENTIFIER id )
1790
is_anon_member(IDENTIFIER id)
1740
{
1791
{
1741
    DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
1792
	DECL_SPEC ds = DEREF_dspec(id_storage(id));
1742
    if ( ds & dspec_reserve ) {
1793
	if (ds & dspec_reserve) {
1743
	IDENTIFIER pid = DEREF_id ( id_alias ( id ) ) ;
1794
		IDENTIFIER pid = DEREF_id(id_alias(id));
1744
	if ( !EQ_id ( pid, id ) ) {
1795
		if (!EQ_id(pid, id)) {
1745
	    TYPE s = DEREF_type ( id_variable_etc_type ( pid ) ) ;
1796
			TYPE s = DEREF_type(id_variable_etc_type(pid));
1746
	    if ( IS_type_compound ( s ) ) {
1797
			if (IS_type_compound(s)) {
1747
		TYPE t = DEREF_type ( id_variable_etc_type ( id ) ) ;
1798
				TYPE t = DEREF_type(id_variable_etc_type(id));
1748
		if ( !eq_type ( s, t ) ) return ( 1 ) ;
1799
				if (!eq_type(s, t)) {
-
 
1800
					return (1);
1749
	    }
1801
				}
-
 
1802
			}
1750
	}
1803
		}
1751
    }
1804
	}
1752
    return ( 0 ) ;
1805
	return (0);
1753
}
1806
}
1754
 
1807
 
1755
 
1808
 
1756
/*
1809
/*
1757
    REDECLARE A MEMBER OF AN ANONYMOUS UNION
1810
    REDECLARE A MEMBER OF AN ANONYMOUS UNION
1758
 
1811
 
1759
    This routine redeclares the member id of an anonymous union.  The
1812
    This routine redeclares the member id of an anonymous union.  The
1760
    remaining arguments are as in redecl_anon_union.
1813
    remaining arguments are as in redecl_anon_union.
1761
*/
1814
*/
1762
 
1815
 
1763
static IDENTIFIER redecl_anon_member
1816
static IDENTIFIER
1764
    PROTO_N ( ( id, ct, ds, obj ) )
-
 
1765
    PROTO_T ( IDENTIFIER id X CLASS_TYPE ct X DECL_SPEC ds X IDENTIFIER obj )
1817
redecl_anon_member(IDENTIFIER id, CLASS_TYPE ct, DECL_SPEC ds, IDENTIFIER obj)
1766
{
1818
{
1767
    IDENTIFIER pid = NULL_id ;
1819
	IDENTIFIER pid = NULL_id;
1768
    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
1820
	HASHID nm = DEREF_hashid(id_name(id));
1769
    if ( !IS_hashid_anon ( nm ) ) {
1821
	if (!IS_hashid_anon(nm)) {
1770
	switch ( TAG_id ( id ) ) {
1822
		switch (TAG_id(id)) {
1771
	    case id_member_tag : {
1823
		case id_member_tag: {
1772
		/* Redeclare a type member */
1824
			/* Redeclare a type member */
1773
		TYPE t = DEREF_type ( id_member_type ( id ) ) ;
1825
			TYPE t = DEREF_type(id_member_type(id));
1774
		DEREF_loc ( id_loc ( id ), crt_loc ) ;
1826
			DEREF_loc(id_loc(id), crt_loc);
1775
		if ( IS_id_member ( obj ) ) {
1827
			if (IS_id_member(obj)) {
1776
		    NAMESPACE cns = crt_namespace ;
1828
				NAMESPACE cns = crt_namespace;
1777
		    OFFSET off1 = DEREF_off ( id_member_off ( id ) ) ;
1829
				OFFSET off1 = DEREF_off(id_member_off(id));
1778
		    OFFSET off2 = DEREF_off ( id_member_off ( obj ) ) ;
1830
				OFFSET off2 = DEREF_off(id_member_off(obj));
1779
		    id = find_id ( nm ) ;
1831
				id = find_id(nm);
1780
		    id = constr_name ( cns, id ) ;
1832
				id = constr_name(cns, id);
1781
		    id = make_member_decl ( ds, t, id, 0 ) ;
1833
				id = make_member_decl(ds, t, id, 0);
1782
		    MAKE_off_plus ( off2, off1, off1 ) ;
1834
				MAKE_off_plus(off2, off1, off1);
1783
		    COPY_off ( id_member_off ( id ), off1 ) ;
1835
				COPY_off(id_member_off(id), off1);
1784
		} else {
1836
			} else {
1785
		    id = make_object_decl ( ds, t, id, 0 ) ;
1837
				id = make_object_decl(ds, t, id, 0);
1786
		    obj = DEREF_id ( id_alias ( obj ) ) ;
1838
				obj = DEREF_id(id_alias(obj));
1787
		    COPY_id ( id_alias ( id ), obj ) ;
1839
				COPY_id(id_alias(id), obj);
-
 
1840
			}
-
 
1841
			pid = id;
-
 
1842
			break;
1788
		}
1843
		}
1789
		pid = id ;
-
 
1790
		break ;
-
 
1791
	    }
-
 
1792
	    case id_class_name_tag : {
1844
		case id_class_name_tag: {
1793
		/* Redeclare a class name */
1845
			/* Redeclare a class name */
1794
		int templ = 0 ;
1846
			int templ = 0;
1795
		CLASS_TYPE cs ;
1847
			CLASS_TYPE cs;
1796
		TYPE t = DEREF_type ( id_class_name_defn ( id ) ) ;
1848
			TYPE t = DEREF_type(id_class_name_defn(id));
1797
		while ( IS_type_templ ( t ) ) {
1849
			while (IS_type_templ(t)) {
1798
		    templ = 1 ;
1850
				templ = 1;
1799
		    t = DEREF_type ( type_templ_defn ( t ) ) ;
1851
				t = DEREF_type(type_templ_defn(t));
-
 
1852
			}
-
 
1853
			cs = DEREF_ctype(type_compound_defn(t));
-
 
1854
			if (!eq_ctype(ct, cs)) {
-
 
1855
				NAMESPACE cns = crt_namespace;
-
 
1856
				if (templ) {
-
 
1857
					/* Shouldn't be a template class */
-
 
1858
					LOCATION loc;
-
 
1859
					DEREF_loc(id_loc(id), loc);
-
 
1860
					report(loc, ERR_temp_decl_bad());
-
 
1861
				}
-
 
1862
				pid = redeclare_id(cns, id);
-
 
1863
			}
-
 
1864
			break;
-
 
1865
		}
-
 
1866
		case id_enum_name_tag:
-
 
1867
		case id_class_alias_tag:
-
 
1868
		case id_enum_alias_tag:
-
 
1869
		case id_type_alias_tag:
-
 
1870
		case id_enumerator_tag: {
-
 
1871
			/* Redeclare other identifiers */
-
 
1872
			NAMESPACE cns = crt_namespace;
-
 
1873
			pid = redeclare_id(cns, id);
-
 
1874
			break;
1800
		}
1875
		}
1801
		cs = DEREF_ctype ( type_compound_defn ( t ) ) ;
-
 
1802
		if ( !eq_ctype ( ct, cs ) ) {
-
 
1803
		    NAMESPACE cns = crt_namespace ;
-
 
1804
		    if ( templ ) {
-
 
1805
			/* Shouldn't be a template class */
-
 
1806
			LOCATION loc ;
-
 
1807
			DEREF_loc ( id_loc ( id ), loc ) ;
-
 
1808
			report ( loc, ERR_temp_decl_bad () ) ;
-
 
1809
		    }
-
 
1810
		    pid = redeclare_id ( cns, id ) ;
-
 
1811
		}
1876
		}
1812
		break ;
-
 
1813
	    }
-
 
1814
	    case id_enum_name_tag :
-
 
1815
	    case id_class_alias_tag :
-
 
1816
	    case id_enum_alias_tag :
-
 
1817
	    case id_type_alias_tag :
-
 
1818
	    case id_enumerator_tag : {
-
 
1819
		/* Redeclare other identifiers */
-
 
1820
		NAMESPACE cns = crt_namespace ;
-
 
1821
		pid = redeclare_id ( cns, id ) ;
-
 
1822
		break ;
-
 
1823
	    }
-
 
1824
	}
1877
	}
1825
    }
-
 
1826
    return ( pid ) ;
1878
	return (pid);
1827
}
1879
}
1828
 
1880
 
1829
 
1881
 
1830
/*
1882
/*
1831
    REDECLARE AN ANONYMOUS UNION
1883
    REDECLARE AN ANONYMOUS UNION
Line 1835... Line 1887...
1835
    The routine returns false if there are no members to redeclare.  The
1887
    The routine returns false if there are no members to redeclare.  The
1836
    redeclared members are added to the extra field of the namespace given
1888
    redeclared members are added to the extra field of the namespace given
1837
    by ct.
1889
    by ct.
1838
*/
1890
*/
1839
 
1891
 
1840
int redecl_anon_union
1892
int
1841
    PROTO_N ( ( ct, ds, obj ) )
-
 
1842
    PROTO_T ( CLASS_TYPE ct X DECL_SPEC ds X IDENTIFIER obj )
1893
redecl_anon_union(CLASS_TYPE ct, DECL_SPEC ds, IDENTIFIER obj)
1843
{
1894
{
1844
    int ok = 0 ;
1895
	int ok = 0;
1845
    MEMBER mem ;
1896
	MEMBER mem;
1846
    NAMESPACE ns ;
1897
	NAMESPACE ns;
1847
    LOCATION old_loc ;
1898
	LOCATION old_loc;
1848
    bad_crt_loc++ ;
1899
	bad_crt_loc++;
1849
    old_loc = crt_loc ;
1900
	old_loc = crt_loc;
1850
    ds |= dspec_reserve ;
1901
	ds |= dspec_reserve;
1851
    crt_id_qualifier = qual_none ;
1902
	crt_id_qualifier = qual_none;
1852
    crt_templ_qualifier = 0 ;
1903
	crt_templ_qualifier = 0;
1853
    ns = DEREF_nspace ( ctype_member ( ct ) ) ;
1904
	ns = DEREF_nspace(ctype_member(ct));
1854
    mem = DEREF_member ( nspace_ctype_first ( ns ) ) ;
1905
	mem = DEREF_member(nspace_ctype_first(ns));
1855
    while ( !IS_NULL_member ( mem ) ) {
1906
	while (!IS_NULL_member(mem)) {
1856
	IDENTIFIER id = DEREF_id ( member_id ( mem ) ) ;
1907
		IDENTIFIER id = DEREF_id(member_id(mem));
1857
	IDENTIFIER aid = DEREF_id ( member_alt ( mem ) ) ;
1908
		IDENTIFIER aid = DEREF_id(member_alt(mem));
1858
	if ( !IS_NULL_id ( aid ) && !EQ_id ( aid, id ) ) {
1909
		if (!IS_NULL_id(aid) && !EQ_id(aid, id)) {
1859
	    aid = redecl_anon_member ( aid, ct, ds, obj ) ;
1910
			aid = redecl_anon_member(aid, ct, ds, obj);
1860
	    if ( !IS_NULL_id ( aid ) ) ok = 1 ;
1911
			if (!IS_NULL_id(aid)) {
-
 
1912
				ok = 1;
-
 
1913
			}
-
 
1914
		}
-
 
1915
		if (!IS_NULL_id(id)) {
-
 
1916
			id = redecl_anon_member(id, ct, ds, obj);
-
 
1917
			if (!IS_NULL_id(id)) {
-
 
1918
				ok = 1;
-
 
1919
			}
-
 
1920
		}
-
 
1921
		mem = DEREF_member(member_next(mem));
1861
	}
1922
	}
1862
	if ( !IS_NULL_id ( id ) ) {
-
 
1863
	    id = redecl_anon_member ( id, ct, ds, obj ) ;
-
 
1864
	    if ( !IS_NULL_id ( id ) ) ok = 1 ;
-
 
1865
	}
-
 
1866
	mem = DEREF_member ( member_next ( mem ) ) ;
-
 
1867
    }
-
 
1868
    crt_loc = old_loc ;
1923
	crt_loc = old_loc;
1869
    bad_crt_loc-- ;
1924
	bad_crt_loc--;
1870
    return ( ok ) ;
1925
	return (ok);
1871
}
1926
}