Subversion Repositories tendra.SVN

Rev

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

Rev 2 Rev 7
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2006 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997, 1998
32
    		 Crown Copyright (c) 1997, 1998
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
Line 67... Line 97...
67
    being defined) and the stack of all enclosing namespaces.  Another stack
97
    being defined) and the stack of all enclosing namespaces.  Another stack
68
    of namespaces, which will be a superset of the first, gives the list
98
    of namespaces, which will be a superset of the first, gives the list
69
    of locations to be searched during name look-up.
99
    of locations to be searched during name look-up.
70
*/
100
*/
71
 
101
 
72
NAMESPACE crt_namespace = NULL_nspace ;
102
NAMESPACE crt_namespace = NULL_nspace;
73
NAMESPACE last_namespace = NULL_nspace ;
103
NAMESPACE last_namespace = NULL_nspace;
74
NAMESPACE qual_namespace = NULL_nspace ;
104
NAMESPACE qual_namespace = NULL_nspace;
75
STACK ( NAMESPACE ) namespace_stack = NULL_stack ( NAMESPACE ) ;
105
STACK(NAMESPACE) namespace_stack = NULL_stack(NAMESPACE);
76
STACK ( NAMESPACE ) crt_nspace_stack = NULL_stack ( NAMESPACE ) ;
106
STACK(NAMESPACE) crt_nspace_stack = NULL_stack(NAMESPACE);
77
STACK ( NAMESPACE ) local_nspace_stack = NULL_stack ( NAMESPACE ) ;
107
STACK(NAMESPACE) local_nspace_stack = NULL_stack(NAMESPACE);
78
 
108
 
79
 
109
 
80
/*
110
/*
81
    STANDARD NAMESPACES
111
    STANDARD NAMESPACES
82
 
112
 
Line 87... Line 117...
87
    proto_scope option is true, function prototype namespace) enclosing
117
    proto_scope option is true, function prototype namespace) enclosing
88
    the current namespace are maintained in nonblock_namespace and
118
    the current namespace are maintained in nonblock_namespace and
89
    nonclass_namespace respectively.
119
    nonclass_namespace respectively.
90
*/
120
*/
91
 
121
 
92
NAMESPACE global_namespace = NULL_nspace ;
122
NAMESPACE global_namespace = NULL_nspace;
93
NAMESPACE token_namespace = NULL_nspace ;
123
NAMESPACE token_namespace = NULL_nspace;
94
NAMESPACE c_namespace = NULL_nspace ;
124
NAMESPACE c_namespace = NULL_nspace;
95
NAMESPACE nonblock_namespace = NULL_nspace ;
125
NAMESPACE nonblock_namespace = NULL_nspace;
96
NAMESPACE nonclass_namespace = NULL_nspace ;
126
NAMESPACE nonclass_namespace = NULL_nspace;
97
static NAMESPACE scope_namespace = NULL_nspace ;
127
static NAMESPACE scope_namespace = NULL_nspace;
98
 
128
 
99
 
129
 
100
/*
130
/*
101
    STANDARD NAMESPACE IDENTIFIERS
131
    STANDARD NAMESPACE IDENTIFIERS
102
 
132
 
103
    The identifier local_namespace_id is used as the name for all unnamed
133
    The identifier local_namespace_id is used as the name for all unnamed
104
    namespaces defined within the current translation unit.
134
    namespaces defined within the current translation unit.
105
*/
135
*/
106
 
136
 
107
static IDENTIFIER local_namespace_id = NULL_id ;
137
static IDENTIFIER local_namespace_id = NULL_id;
108
 
138
 
109
 
139
 
110
/*
140
/*
111
    NAME LOOK-UP CACHE FLAG
141
    NAME LOOK-UP CACHE FLAG
112
 
142
 
113
    This flag is set to indicate that name look-up should be cached
143
    This flag is set to indicate that name look-up should be cached
114
    whenever possible.  It is switched off temporarily in field selectors
144
    whenever possible.  It is switched off temporarily in field selectors
115
    as an optimisation.
145
    as an optimisation.
116
*/
146
*/
117
 
147
 
118
int cache_lookup = 1 ;
148
int cache_lookup = 1;
119
int old_cache_lookup = 1 ;
149
int old_cache_lookup = 1;
120
 
150
 
121
 
151
 
122
/*
152
/*
123
    CREATE A STANDARD NAMESPACE
153
    CREATE A STANDARD NAMESPACE
124
 
154
 
125
    This routine creates a global namespace of size sz with a dummy name
155
    This routine creates a global namespace of size sz with a dummy name
126
    given by s.
156
    given by s.
127
*/
157
*/
128
 
158
 
129
NAMESPACE make_global_nspace
159
NAMESPACE
130
    PROTO_N ( ( s, sz ) )
-
 
131
    PROTO_T ( CONST char *s X int sz )
160
make_global_nspace(CONST char *s, int sz)
132
{
161
{
133
    IDENTIFIER id ;
162
	IDENTIFIER id;
134
    string u = ustrlit ( s ) ;
163
	string u = ustrlit(s);
135
    NAMESPACE ns = NULL_nspace ;
164
	NAMESPACE ns = NULL_nspace;
136
    DECL_SPEC ds = ( dspec_defn | dspec_extern ) ;
165
	DECL_SPEC ds = (dspec_defn | dspec_extern);
137
    HASHID nm = lookup_name ( u, hash ( u ), 1, lex_identifier ) ;
166
	HASHID nm = lookup_name(u, hash(u), 1, lex_identifier);
138
    MAKE_id_nspace_name ( nm, ds, NULL_nspace, crt_loc, ns, id ) ;
167
	MAKE_id_nspace_name(nm, ds, NULL_nspace, crt_loc, ns, id);
139
    ns = make_namespace ( id, nspace_global_tag, sz ) ;
168
	ns = make_namespace(id, nspace_global_tag, sz);
140
    COPY_nspace ( id_nspace_name_defn ( id ), ns ) ;
169
	COPY_nspace(id_nspace_name_defn(id), ns);
141
    return ( ns ) ;
170
	return (ns);
142
}
171
}
143
 
172
 
144
 
173
 
145
/*
174
/*
146
    INITIALISE STANDARD NAMESPACES
175
    INITIALISE STANDARD NAMESPACES
147
 
176
 
148
    This routine initialises the standard namespaces above.
177
    This routine initialises the standard namespaces above.
149
*/
178
*/
150
 
179
 
151
void init_namespace
180
void
152
    PROTO_Z ()
181
init_namespace(void)
153
{
182
{
154
    string s = ustrlit ( "<local>" ) ;
183
	string s = ustrlit("<local>");
155
    HASHID nm = lookup_name ( s, hash ( s ), 1, lex_identifier ) ;
184
	HASHID nm = lookup_name(s, hash(s), 1, lex_identifier);
156
    local_namespace_id = DEREF_id ( hashid_id ( nm ) ) ;
185
	local_namespace_id = DEREF_id(hashid_id(nm));
157
    global_namespace = make_global_nspace ( "<global>", 50 ) ;
186
	global_namespace = make_global_nspace("<global>", 50);
158
#if LANGUAGE_CPP
187
#if LANGUAGE_CPP
159
    c_namespace = make_global_nspace ( "<c>", 50 ) ;
188
	c_namespace = make_global_nspace("<c>", 50);
160
#endif
189
#endif
161
    token_namespace = make_global_nspace ( "<token>", 50 ) ;
190
	token_namespace = make_global_nspace("<token>", 50);
162
    scope_namespace = make_global_nspace ( "<scope>", 50 ) ;
191
	scope_namespace = make_global_nspace("<scope>", 50);
163
    last_namespace = global_namespace ;
192
	last_namespace = global_namespace;
164
    old_cache_lookup = cache_lookup ;
193
	old_cache_lookup = cache_lookup;
165
    return ;
194
	return;
166
}
195
}
167
 
196
 
168
 
197
 
169
/*
198
/*
170
    DOES ONE NAMESPACE CONTAIN ANOTHER?
199
    DOES ONE NAMESPACE CONTAIN ANOTHER?
171
 
200
 
172
    This routine checks whether the namespace ns contains the definition
201
    This routine checks whether the namespace ns contains the definition
173
    of the namespace pns.
202
    of the namespace pns.
174
*/
203
*/
175
 
204
 
176
int is_subnspace
205
int
177
    PROTO_N ( ( ns, pns ) )
-
 
178
    PROTO_T ( NAMESPACE ns X NAMESPACE pns )
206
is_subnspace(NAMESPACE ns, NAMESPACE pns)
179
{
207
{
180
    if ( EQ_nspace ( ns, pns ) ) return ( 1 ) ;
208
	if (EQ_nspace(ns, pns)) {
-
 
209
		return (1);
-
 
210
	}
181
    while ( !IS_NULL_nspace ( pns ) ) {
211
	while (!IS_NULL_nspace(pns)) {
182
	pns = DEREF_nspace ( nspace_parent ( pns ) ) ;
212
		pns = DEREF_nspace(nspace_parent(pns));
183
	if ( EQ_nspace ( ns, pns ) ) return ( 1 ) ;
213
		if (EQ_nspace(ns, pns)) {
-
 
214
			return (1);
184
    }
215
		}
-
 
216
	}
185
    return ( 0 ) ;
217
	return (0);
186
}
218
}
187
 
219
 
188
 
220
 
189
/*
221
/*
190
    FIND THE JOIN OF TWO NAMESPACES
222
    FIND THE JOIN OF TWO NAMESPACES
Line 192... Line 224...
192
    This routine finds the join of the namespaces ns and nt, that is to
224
    This routine finds the join of the namespaces ns and nt, that is to
193
    say the smallest namespace which contains both ns and nt.  A using
225
    say the smallest namespace which contains both ns and nt.  A using
194
    directive for nt in ns causes the members of nt to be treated as
226
    directive for nt in ns causes the members of nt to be treated as
195
    members of the join namespace for the purposes of unqualified name
227
    members of the join namespace for the purposes of unqualified name
196
    look-up.
228
    look-up.
197
*/
229
*/
198
 
230
 
199
static NAMESPACE join_namespace
231
static NAMESPACE
200
    PROTO_N ( ( ns, nt ) )
-
 
201
    PROTO_T ( NAMESPACE ns X NAMESPACE nt )
232
join_namespace(NAMESPACE ns, NAMESPACE nt)
202
{
233
{
203
    while ( !EQ_nspace ( ns, nt ) ) {
234
	while (!EQ_nspace(ns, nt)) {
204
	if ( IS_NULL_nspace ( ns ) ) return ( NULL_nspace ) ;
235
		if (IS_NULL_nspace(ns)) {
-
 
236
			return (NULL_nspace);
-
 
237
		}
205
	if ( IS_NULL_nspace ( nt ) ) return ( NULL_nspace ) ;
238
		if (IS_NULL_nspace(nt)) {
-
 
239
			return (NULL_nspace);
-
 
240
		}
206
	if ( is_subnspace ( ns, nt ) ) return ( ns ) ;
241
		if (is_subnspace(ns, nt)) {
-
 
242
			return (ns);
-
 
243
		}
207
	if ( is_subnspace ( nt, ns ) ) return ( nt ) ;
244
		if (is_subnspace(nt, ns)) {
-
 
245
			return (nt);
-
 
246
		}
208
	ns = DEREF_nspace ( nspace_parent ( ns ) ) ;
247
		ns = DEREF_nspace(nspace_parent(ns));
209
	nt = DEREF_nspace ( nspace_parent ( nt ) ) ;
248
		nt = DEREF_nspace(nspace_parent(nt));
210
    }
249
	}
211
    return ( ns ) ;
250
	return (ns);
212
}
251
}
213
 
252
 
214
 
253
 
215
/*
254
/*
216
    UNCACHE A NAMESPACE
255
    UNCACHE A NAMESPACE
217
 
256
 
218
    This routine clears the cached name look-ups for all the names
257
    This routine clears the cached name look-ups for all the names
219
    accessible from the namespace ns.
258
    accessible from the namespace ns.
220
*/
259
*/
221
 
260
 
222
void uncache_namespace
261
void
223
    PROTO_N ( ( ns, add ) )
-
 
224
    PROTO_T ( NAMESPACE ns X int add )
262
uncache_namespace(NAMESPACE ns, int add)
225
{
263
{
226
    if ( !IS_NULL_nspace ( ns ) && cache_lookup ) {
264
	if (!IS_NULL_nspace(ns) && cache_lookup) {
227
	MEMBER mem ;
265
		MEMBER mem;
228
	LIST ( NAMESPACE ) uns ;
266
		LIST(NAMESPACE) uns;
229
 
267
 
230
	/* Clear cache fields for all members */
268
		/* Clear cache fields for all members */
231
	if ( IS_nspace_named_etc ( ns ) ) {
269
		if (IS_nspace_named_etc(ns)) {
232
	    mem = DEREF_member ( nspace_named_etc_first ( ns ) ) ;
270
			mem = DEREF_member(nspace_named_etc_first(ns));
233
	} else {
271
		} else {
234
	    mem = DEREF_member ( nspace_last ( ns ) ) ;
272
			mem = DEREF_member(nspace_last(ns));
235
	}
273
		}
236
	while ( !IS_NULL_member ( mem ) ) {
274
		while (!IS_NULL_member(mem)) {
237
	    IDENTIFIER id = DEREF_id ( member_id ( mem ) ) ;
275
			IDENTIFIER id = DEREF_id(member_id(mem));
238
	    if ( !IS_NULL_id ( id ) ) {
276
			if (!IS_NULL_id(id)) {
239
		HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
277
				HASHID nm = DEREF_hashid(id_name(id));
-
 
278
				if (!add) {
240
		if ( !add ) id = NULL_id ;
279
					id = NULL_id;
-
 
280
				}
241
		COPY_id ( hashid_cache ( nm ), id ) ;
281
				COPY_id(hashid_cache(nm), id);
242
	    }
282
			}
243
	    mem = DEREF_member ( member_next ( mem ) ) ;
283
			mem = DEREF_member(member_next(mem));
244
	}
284
		}
245
 
285
 
246
	/* Recursively clear all used namespaces */
286
		/* Recursively clear all used namespaces */
247
	uns = DEREF_list ( nspace_use ( ns ) ) ;
287
		uns = DEREF_list(nspace_use(ns));
248
	if ( !IS_NULL_list ( uns ) ) {
288
		if (!IS_NULL_list(uns)) {
249
	    LIST ( NAMESPACE ) lns = uns ;
289
			LIST(NAMESPACE) lns = uns;
250
	    COPY_list ( nspace_use ( ns ), NULL_list ( NAMESPACE ) ) ;
290
			COPY_list(nspace_use(ns), NULL_list(NAMESPACE));
251
	    while ( !IS_NULL_list ( lns ) ) {
291
			while (!IS_NULL_list(lns)) {
252
		NAMESPACE pns = DEREF_nspace ( HEAD_list ( lns ) ) ;
292
				NAMESPACE pns = DEREF_nspace(HEAD_list(lns));
253
		uncache_namespace ( pns, 0 ) ;
293
				uncache_namespace(pns, 0);
254
		lns = TAIL_list ( lns ) ;
294
				lns = TAIL_list(lns);
255
	    }
295
			}
256
	    COPY_list ( nspace_use ( ns ), uns ) ;
296
			COPY_list(nspace_use(ns), uns);
257
	}
297
		}
258
    }
298
	}
259
    return ;
299
	return;
260
}
300
}
261
 
301
 
262
 
302
 
263
/*
303
/*
264
    ADD A NAMESPACE TO THE LOOK-UP LIST
304
    ADD A NAMESPACE TO THE LOOK-UP LIST
265
 
305
 
266
    This routine adds the namespace ns to the look-up namespace list.  Note
306
    This routine adds the namespace ns to the look-up namespace list.  Note
267
    that this is automatically called by push_namespace.
307
    that this is automatically called by push_namespace.
268
*/
308
*/
-
 
309
 
-
 
310
void
-
 
311
add_namespace(NAMESPACE ns)
-
 
312
{
-
 
313
	PUSH_nspace(ns, namespace_stack);
-
 
314
	uncache_namespace(ns, 1);
-
 
315
	return;
-
 
316
}
-
 
317
 
-
 
318
 
-
 
319
/*
-
 
320
    REMOVE A NAMESPACE FROM THE LOOK-UP LIST
269
 
321
 
270
void add_namespace
322
    This routine removes the top namespace from the look-up namespace list.
271
    PROTO_N ( ( ns ) )
323
    Note that this is automatically called by pop_namespace.
-
 
324
*/
-
 
325
 
-
 
326
void
272
    PROTO_T ( NAMESPACE ns )
327
remove_namespace(void)
273
{
328
{
-
 
329
	NAMESPACE ns;
274
    PUSH_nspace ( ns, namespace_stack ) ;
330
	POP_nspace(ns, namespace_stack);
275
    uncache_namespace ( ns, 1 ) ;
331
	uncache_namespace(ns, 0);
276
    return ;
332
	return;
277
}
333
}
278
 
334
 
279
 
335
 
280
/*
336
/*
281
    REMOVE A NAMESPACE FROM THE LOOK-UP LIST
337
    PUSH A NAMESPACE
282
 
-
 
283
    This routine removes the top namespace from the look-up namespace list.
-
 
284
    Note that this is automatically called by pop_namespace.
-
 
285
*/
-
 
286
 
338
 
287
void remove_namespace
339
    This routine pushes the namespace ns onto the namespace stack.
-
 
340
*/
-
 
341
 
-
 
342
void
288
    PROTO_Z ()
343
store_namespace(NAMESPACE ns)
289
{
344
{
290
    NAMESPACE ns ;
-
 
291
    POP_nspace ( ns, namespace_stack ) ;
-
 
292
    uncache_namespace ( ns, 0 ) ;
-
 
293
    return ;
-
 
294
}
-
 
295
 
-
 
296
 
-
 
297
/*
-
 
298
    PUSH A NAMESPACE
-
 
299
 
-
 
300
    This routine pushes the namespace ns onto the namespace stack.
-
 
301
*/
-
 
302
 
-
 
303
void store_namespace
-
 
304
    PROTO_N ( ( ns ) )
-
 
305
    PROTO_T ( NAMESPACE ns )
-
 
306
{
-
 
307
    NAMESPACE cns = crt_namespace ;
345
	NAMESPACE cns = crt_namespace;
308
    switch ( TAG_nspace ( ns ) ) {
346
	switch (TAG_nspace(ns)) {
309
	case nspace_named_tag :
347
	case nspace_named_tag:
310
	case nspace_unnamed_tag :
348
	case nspace_unnamed_tag:
311
	case nspace_global_tag : {
349
	case nspace_global_tag:
312
	    /* Record named namespaces */
350
		/* Record named namespaces */
313
	    nonblock_namespace = ns ;
351
		nonblock_namespace = ns;
314
	    nonclass_namespace = ns ;
352
		nonclass_namespace = ns;
315
	    break ;
353
		break;
316
	}
-
 
317
	case nspace_param_tag : {
354
	case nspace_param_tag:
318
	    /* Deal with function prototype scopes */
355
		/* Deal with function prototype scopes */
319
	    if ( option ( OPT_proto_scope ) ) {
356
		if (option(OPT_proto_scope)) {
320
		nonclass_namespace = ns ;
357
			nonclass_namespace = ns;
321
	    }
358
		}
322
	    break ;
359
		break;
323
	}
-
 
324
	case nspace_block_tag : {
360
	case nspace_block_tag:
325
	    /* A block is a non-class namespace */
361
		/* A block is a non-class namespace */
326
	    nonclass_namespace = ns ;
362
		nonclass_namespace = ns;
327
	    break ;
363
		break;
328
	}
364
	}
329
    }
-
 
330
    COPY_nspace ( nspace_parent ( ns ), cns ) ;
365
	COPY_nspace(nspace_parent(ns), cns);
331
    PUSH_nspace ( cns, crt_nspace_stack ) ;
366
	PUSH_nspace(cns, crt_nspace_stack);
332
    crt_namespace = ns ;
367
	crt_namespace = ns;
333
    return ;
368
	return;
334
}
369
}
335
 
370
 
336
 
371
 
337
/*
372
/*
338
    POP A NAMESPACE
373
    POP A NAMESPACE
339
 
374
 
340
    This routine removes a namespace from the namespace stack.
375
    This routine removes a namespace from the namespace stack.
341
*/
376
*/
342
 
377
 
343
NAMESPACE restore_namespace
378
NAMESPACE
344
    PROTO_Z ()
379
restore_namespace(void)
345
{
380
{
346
    NAMESPACE ns = crt_namespace ;
381
	NAMESPACE ns = crt_namespace;
347
    int fb = EQ_nspace ( ns, nonblock_namespace ) ;
382
	int fb = EQ_nspace(ns, nonblock_namespace);
348
    int fc = EQ_nspace ( ns, nonclass_namespace ) ;
383
	int fc = EQ_nspace(ns, nonclass_namespace);
349
    int fa = ( fb || fc ) ;
384
	int fa = (fb || fc);
350
    if ( fa ) {
385
	if (fa) {
351
	/* Check for enclosing namespaces */
386
		/* Check for enclosing namespaces */
352
	LIST ( NAMESPACE ) lns = LIST_stack ( crt_nspace_stack ) ;
387
		LIST(NAMESPACE) lns = LIST_stack(crt_nspace_stack);
353
	while ( fa && !IS_NULL_list ( lns ) ) {
388
		while (fa && !IS_NULL_list(lns)) {
354
	    NAMESPACE pns = DEREF_nspace ( HEAD_list ( lns ) ) ;
389
			NAMESPACE pns = DEREF_nspace(HEAD_list(lns));
355
	    switch ( TAG_nspace ( pns ) ) {
390
			switch (TAG_nspace(pns)) {
356
		case nspace_named_tag :
391
			case nspace_named_tag:
357
		case nspace_unnamed_tag :
392
			case nspace_unnamed_tag:
358
		case nspace_global_tag : {
393
			case nspace_global_tag:
359
		    if ( fb ) {
394
				if (fb) {
360
			/* Non-block namespace found */
395
					/* Non-block namespace found */
361
			nonblock_namespace = pns ;
396
					nonblock_namespace = pns;
362
			fa = fc ;
397
					fa = fc;
363
			fb = 0 ;
398
					fb = 0;
364
		    }
399
				}
365
		    goto nonclass_namespace_lab ;
400
				goto nonclass_namespace_lab;
366
		}
-
 
367
		case nspace_param_tag : {
401
			case nspace_param_tag:
368
		    /* Deal with function prototype scopes */
402
				/* Deal with function prototype scopes */
369
		    if ( !option ( OPT_proto_scope ) ) break ;
403
				if (!option(OPT_proto_scope)) {
370
		    goto nonclass_namespace_lab ;
404
					break;
371
		}
405
				}
-
 
406
				goto nonclass_namespace_lab;
372
		case nspace_block_tag :
407
			case nspace_block_tag:
373
		nonclass_namespace_lab : {
408
nonclass_namespace_lab:
374
		    if ( fc ) {
409
				if (fc) {
375
			/* Non-class namespace found */
410
					/* Non-class namespace found */
376
			nonclass_namespace = pns ;
411
					nonclass_namespace = pns;
377
			fa = fb ;
412
					fa = fb;
378
			fc = 0 ;
413
					fc = 0;
379
		    }
414
				}
380
		    break ;
415
				break;
-
 
416
			}
-
 
417
			lns = TAIL_list(lns);
381
		}
418
		}
382
	    }
-
 
383
	    lns = TAIL_list ( lns ) ;
-
 
384
	}
419
	}
385
    }
-
 
386
    POP_nspace ( crt_namespace, crt_nspace_stack ) ;
420
	POP_nspace(crt_namespace, crt_nspace_stack);
387
    return ( ns ) ;
421
	return (ns);
388
}
422
}
389
 
423
 
390
 
424
 
391
/*
425
/*
392
    SET CURRENT NAMESPACE
426
    SET CURRENT NAMESPACE
393
 
427
 
394
    This routine makes the namespace ns into the current namespace, pushing
428
    This routine makes the namespace ns into the current namespace, pushing
395
    the previous namespace onto the stack.
429
    the previous namespace onto the stack.
396
*/
430
*/
397
 
431
 
398
void push_namespace
432
void
399
    PROTO_N ( ( ns ) )
-
 
400
    PROTO_T ( NAMESPACE ns )
433
push_namespace(NAMESPACE ns)
401
{
434
{
402
    store_namespace ( ns ) ;
435
	store_namespace(ns);
403
    add_namespace ( ns ) ;
436
	add_namespace(ns);
404
    return ;
437
	return;
405
}
438
}
406
 
439
 
407
 
440
 
408
/*
441
/*
409
    RESTORE PREVIOUS NAMESPACE
442
    RESTORE PREVIOUS NAMESPACE
410
 
443
 
411
    This routine restores the current namespace to its previous value by
444
    This routine restores the current namespace to its previous value by
412
    popping it from the stack.  It returns the removed namespace.
445
    popping it from the stack.  It returns the removed namespace.
413
*/
446
*/
414
 
447
 
415
NAMESPACE pop_namespace
448
NAMESPACE
416
    PROTO_Z ()
449
pop_namespace(void)
417
{
450
{
418
    NAMESPACE ns = restore_namespace () ;
451
	NAMESPACE ns = restore_namespace();
419
    remove_namespace () ;
452
	remove_namespace();
420
    return ( ns ) ;
453
	return (ns);
421
}
454
}
422
 
455
 
423
 
456
 
424
/*
457
/*
425
    RECALCULATE NAMESPACES
458
    RECALCULATE NAMESPACES
Line 427... Line 460...
427
    This routine forces the recalculation of nonblock_namespace and
460
    This routine forces the recalculation of nonblock_namespace and
428
    nonclass_namespace by pushing and immediately popping the global
461
    nonclass_namespace by pushing and immediately popping the global
429
    namespace.
462
    namespace.
430
*/
463
*/
431
 
464
 
-
 
465
void
432
void update_namespace
466
update_namespace(void)
433
    PROTO_Z ()
-
 
434
{
467
{
435
    NAMESPACE ns = global_namespace ;
468
	NAMESPACE ns = global_namespace;
436
    if ( !IS_NULL_nspace ( ns ) ) {
469
	if (!IS_NULL_nspace(ns)) {
437
	store_namespace ( ns ) ;
470
		store_namespace(ns);
438
	IGNORE restore_namespace () ;
471
		IGNORE restore_namespace();
439
    }
472
	}
440
    return ;
473
	return;
441
}
474
}
442
 
475
 
443
 
476
 
444
/*
477
/*
445
    CREATE A NAMESPACE
478
    CREATE A NAMESPACE
446
 
479
 
447
    This routine creates a namespace named id of type tag.  If tag is
480
    This routine creates a namespace named id of type tag.  If tag is
448
    indicates a small namespace then sz will be zero.  Otherwise sz gives
481
    indicates a small namespace then sz will be zero.  Otherwise sz gives
449
    the size of hash table to be created.
482
    the size of hash table to be created.
450
*/
483
*/
451
 
484
 
452
NAMESPACE make_namespace
485
NAMESPACE
453
    PROTO_N ( ( id, tag, sz ) )
-
 
454
    PROTO_T ( IDENTIFIER id X unsigned tag X int sz )
486
make_namespace(IDENTIFIER id, unsigned tag, int sz)
455
{
487
{
456
    NAMESPACE ns ;
488
	NAMESPACE ns;
457
    NAMESPACE pns ;
489
	NAMESPACE pns;
458
    if ( !IS_NULL_id ( id ) ) {
490
	if (!IS_NULL_id(id)) {
459
	pns = DEREF_nspace ( id_parent ( id ) ) ;
491
		pns = DEREF_nspace(id_parent(id));
460
    } else {
492
	} else {
461
	pns = crt_namespace ;
493
		pns = crt_namespace;
462
    }
494
	}
463
    if ( sz == 0 ) {
495
	if (sz == 0) {
464
	/* Small namespace */
496
		/* Small namespace */
465
	MAKE_nspace_block_etc ( tag, id, pns, ns ) ;
497
		MAKE_nspace_block_etc(tag, id, pns, ns);
466
    } else {
498
	} else {
467
	/* Large namespace */
499
		/* Large namespace */
468
	PTR ( MEMBER ) ptr ;
500
		PTR(MEMBER) ptr;
469
	SIZE ( MEMBER ) psz ;
501
		SIZE(MEMBER) psz;
470
	unsigned long i, n = ( unsigned long ) sz ;
502
		unsigned long i, n = (unsigned long)sz;
471
 
503
 
472
	/* Allocate namespace hash table */
504
		/* Allocate namespace hash table */
473
	psz = SCALE ( SIZE_member, n ) ;
505
		psz = SCALE(SIZE_member, n);
474
	ptr = MAKE_ptr ( psz ) ;
506
		ptr = MAKE_ptr(psz);
475
	MAKE_nspace_named_etc ( tag, id, pns, n, ptr, ns ) ;
507
		MAKE_nspace_named_etc(tag, id, pns, n, ptr, ns);
476
 
508
 
477
	/* Initialise hash table entries */
509
		/* Initialise hash table entries */
478
	for ( i = 0 ; i < n ; i++ ) {
510
		for (i = 0; i < n; i++) {
479
	    COPY_member ( ptr, NULL_member ) ;
511
			COPY_member(ptr, NULL_member);
480
	    ptr = STEP_ptr ( ptr, SIZE_member ) ;
512
			ptr = STEP_ptr(ptr, SIZE_member);
-
 
513
		}
481
	}
514
	}
482
    }
-
 
483
    return ( ns ) ;
515
	return (ns);
484
}
516
}
485
 
517
 
486
 
518
 
487
/*
519
/*
488
    USE A NAMESPACE
520
    USE A NAMESPACE
489
 
521
 
490
    This routine creates a using directive for the namespace ns in
522
    This routine creates a using directive for the namespace ns in
491
    the namespace cns.  nt gives the join of cns and ns.  The routine
523
    the namespace cns.  nt gives the join of cns and ns.  The routine
492
    returns zero to indicate that ns has already been used from cns.
524
    returns zero to indicate that ns has already been used from cns.
493
*/
525
*/
494
 
526
 
495
int use_namespace
527
int
496
    PROTO_N ( ( ns, cns, nt ) )
-
 
497
    PROTO_T ( NAMESPACE ns X NAMESPACE cns X NAMESPACE nt )
528
use_namespace(NAMESPACE ns, NAMESPACE cns, NAMESPACE nt)
498
{
529
{
499
    if ( !EQ_nspace ( cns, ns ) ) {
530
	if (!EQ_nspace(cns, ns)) {
500
	LIST ( NAMESPACE ) p = DEREF_list ( nspace_use ( cns ) ) ;
531
		LIST(NAMESPACE) p = DEREF_list(nspace_use(cns));
501
	LIST ( NAMESPACE ) r = DEREF_list ( nspace_join ( cns ) ) ;
532
		LIST(NAMESPACE) r = DEREF_list(nspace_join(cns));
502
	LIST ( NAMESPACE ) q = p ;
533
		LIST(NAMESPACE) q = p;
503
	while ( !IS_NULL_list ( q ) ) {
534
		while (!IS_NULL_list(q)) {
504
	    NAMESPACE qns = DEREF_nspace ( HEAD_list ( q ) ) ;
535
			NAMESPACE qns = DEREF_nspace(HEAD_list(q));
505
	    if ( EQ_nspace ( qns, ns ) ) return ( 0 ) ;
536
			if (EQ_nspace(qns, ns)) {
-
 
537
				return (0);
-
 
538
			}
506
	    q = TAIL_list ( q ) ;
539
			q = TAIL_list(q);
507
	}
540
		}
508
	CONS_nspace ( nt, r, r ) ;
541
		CONS_nspace(nt, r, r);
509
	COPY_list ( nspace_join ( cns ), r ) ;
542
		COPY_list(nspace_join(cns), r);
510
	CONS_nspace ( ns, p, p ) ;
543
		CONS_nspace(ns, p, p);
511
	COPY_list ( nspace_use ( cns ), p ) ;
544
		COPY_list(nspace_use(cns), p);
512
	return ( 1 ) ;
545
		return (1);
513
    }
546
	}
514
    return ( 0 ) ;
547
	return (0);
515
}
548
}
516
 
549
 
517
 
550
 
518
/*
551
/*
519
    LIST OF JOIN NAMESPACES
552
    LIST OF JOIN NAMESPACES
520
 
553
 
521
    During unqualified name look-up any using-directives are treated as
554
    During unqualified name look-up any using-directives are treated as
Line 524... Line 557...
524
    dummy using-directive into the join namespace.  This list is used
557
    dummy using-directive into the join namespace.  This list is used
525
    to keep track of all the join namespaces which have using-directives
558
    to keep track of all the join namespaces which have using-directives
526
    injected in this way.
559
    injected in this way.
527
*/
560
*/
528
 
561
 
529
static LIST ( NAMESPACE ) join_nspaces = NULL_list ( NAMESPACE ) ;
562
static LIST(NAMESPACE) join_nspaces = NULL_list(NAMESPACE);
530
 
563
 
531
 
564
 
532
/*
565
/*
533
    CLEAR LIST OF JOIN NAMESPACES
566
    CLEAR LIST OF JOIN NAMESPACES
534
 
567
 
535
    This routine removes any dummy using-directives from the list of join
568
    This routine removes any dummy using-directives from the list of join
536
    namespaces above.
569
    namespaces above.
537
*/
570
*/
538
 
571
 
539
static void clear_join_nspaces
572
static void
540
    PROTO_Z ()
573
clear_join_nspaces(void)
541
{
574
{
542
    LIST ( NAMESPACE ) lns = join_nspaces ;
575
	LIST(NAMESPACE) lns = join_nspaces;
543
    while ( !IS_NULL_list ( lns ) ) {
576
	while (!IS_NULL_list(lns)) {
544
	NAMESPACE ns ;
577
		NAMESPACE ns;
545
	NAMESPACE dns ;
578
		NAMESPACE dns;
546
	LIST ( NAMESPACE ) p ;
579
		LIST(NAMESPACE) p;
547
	DESTROY_CONS_nspace ( destroy, ns, lns, lns ) ;
580
		DESTROY_CONS_nspace(destroy, ns, lns, lns);
548
	p = DEREF_list ( nspace_use ( ns ) ) ;
581
		p = DEREF_list(nspace_use(ns));
549
	if ( !IS_NULL_list ( p ) ) {
582
		if (!IS_NULL_list(p)) {
550
	    DESTROY_CONS_nspace ( destroy, dns, p, p ) ;
583
			DESTROY_CONS_nspace(destroy, dns, p, p);
551
	    UNUSED ( dns ) ;
584
			UNUSED(dns);
552
	    COPY_list ( nspace_use ( ns ), p ) ;
585
			COPY_list(nspace_use(ns), p);
-
 
586
		}
-
 
587
		p = DEREF_list(nspace_join(ns));
-
 
588
		if (!IS_NULL_list(p)) {
-
 
589
			DESTROY_CONS_nspace(destroy, dns, p, p);
-
 
590
			UNUSED(dns);
-
 
591
			COPY_list(nspace_join(ns), p);
-
 
592
		}
553
	}
593
	}
554
	p = DEREF_list ( nspace_join ( ns ) ) ;
-
 
555
	if ( !IS_NULL_list ( p ) ) {
-
 
556
	    DESTROY_CONS_nspace ( destroy, dns, p, p ) ;
-
 
557
	    UNUSED ( dns ) ;
-
 
558
	    COPY_list ( nspace_join ( ns ), p ) ;
-
 
559
	}
-
 
560
    }
-
 
561
    join_nspaces = NULL_list ( NAMESPACE ) ;
594
	join_nspaces = NULL_list(NAMESPACE);
562
    return ;
595
	return;
563
}
596
}
564
 
597
 
565
 
598
 
566
/*
599
/*
567
    BEGIN A NAMESPACE DEFINITION
600
    BEGIN A NAMESPACE DEFINITION
568
 
601
 
569
    This routine begins the definition of a namespace named id (or an
602
    This routine begins the definition of a namespace named id (or an
570
    anonymous namespace if anon is true).  Note that there may be multiple
603
    anonymous namespace if anon is true).  Note that there may be multiple
571
    definitions of a namespace, the effect of the later definitions being
604
    definitions of a namespace, the effect of the later definitions being
572
    to add elements to the existing namespace.  Only original namespace
605
    to add elements to the existing namespace.  Only original namespace
573
    names, and not namespace aliases, can be used in these namespace
606
    names, and not namespace aliases, can be used in these namespace
574
    extensions.
607
    extensions.
575
*/
608
*/
576
 
609
 
577
void begin_namespace
610
void
578
    PROTO_N ( ( id, anon ) )
-
 
579
    PROTO_T ( IDENTIFIER id X int anon )
611
begin_namespace(IDENTIFIER id, int anon)
580
{
612
{
581
    HASHID nm ;
613
	HASHID nm;
582
    MEMBER mem ;
614
	MEMBER mem;
583
    IDENTIFIER old_id ;
615
	IDENTIFIER old_id;
584
    NAMESPACE ns = NULL_nspace ;
616
	NAMESPACE ns = NULL_nspace;
585
    NAMESPACE cns = crt_namespace ;
617
	NAMESPACE cns = crt_namespace;
586
    unsigned tag = nspace_named_tag ;
618
	unsigned tag = nspace_named_tag;
587
 
619
 
588
    /* Find name for anonymous namespaces */
620
	/* Find name for anonymous namespaces */
589
    if ( anon ) {
621
	if (anon) {
590
	id = local_namespace_id ;
622
		id = local_namespace_id;
591
	tag = nspace_unnamed_tag ;
623
		tag = nspace_unnamed_tag;
592
    }
624
	}
593
    nm = DEREF_hashid ( id_name ( id ) ) ;
625
	nm = DEREF_hashid(id_name(id));
594
 
626
 
595
    /* Can only occur in namespace scope */
627
	/* Can only occur in namespace scope */
596
    if ( in_function_defn || in_class_defn ) {
628
	if (in_function_defn || in_class_defn) {
597
	report ( crt_loc, ERR_dcl_nspace_scope () ) ;
629
		report(crt_loc, ERR_dcl_nspace_scope());
598
    }
630
	}
599
 
631
 
600
    /* Look up namespace name */
632
	/* Look up namespace name */
601
    mem = search_member ( cns, nm, 1 ) ;
633
	mem = search_member(cns, nm, 1);
602
    old_id = DEREF_id ( member_id ( mem ) ) ;
634
	old_id = DEREF_id(member_id(mem));
603
    if ( !IS_NULL_id ( old_id ) ) {
635
	if (!IS_NULL_id(old_id)) {
604
	/* Check for redeclarations */
636
		/* Check for redeclarations */
605
	old_id = redecl_inherit ( old_id, qual_none, in_class_defn, 2 ) ;
637
		old_id = redecl_inherit(old_id, qual_none, in_class_defn, 2);
606
	switch ( TAG_id ( old_id ) ) {
638
		switch (TAG_id(old_id)) {
607
	    case id_nspace_name_tag : {
639
		case id_nspace_name_tag:
608
		/* Previously defined namespace */
640
			/* Previously defined namespace */
609
		ns = DEREF_nspace ( id_nspace_name_defn ( old_id ) ) ;
641
			ns = DEREF_nspace(id_nspace_name_defn(old_id));
610
		break ;
642
			break;
611
	    }
-
 
612
	    case id_nspace_alias_tag : {
643
		case id_nspace_alias_tag: {
613
		/* Previously defined namespace alias */
644
			/* Previously defined namespace alias */
614
		IDENTIFIER ns_id ;
645
			IDENTIFIER ns_id;
615
		ns = DEREF_nspace ( id_nspace_alias_defn ( old_id ) ) ;
646
			ns = DEREF_nspace(id_nspace_alias_defn(old_id));
616
		ns_id = DEREF_id ( nspace_name ( ns ) ) ;
647
			ns_id = DEREF_id(nspace_name(ns));
617
		if ( !IS_id_nspace_name ( ns_id ) ) {
648
			if (!IS_id_nspace_name(ns_id)) {
618
		    /* Alias for class namespace */
649
				/* Alias for class namespace */
619
		    ns = NULL_nspace ;
650
				ns = NULL_nspace;
620
		    goto default_lab ;
651
				goto default_lab;
621
		}
652
			}
622
		report ( crt_loc, ERR_dcl_nspace_def_orig ( ns_id, old_id ) ) ;
653
			report(crt_loc, ERR_dcl_nspace_def_orig(ns_id, old_id));
623
		break ;
654
			break;
624
	    }
655
		}
625
	    default :
656
		default:
626
	    default_lab : {
657
default_lab: {
627
		/* Other previously defined identifier */
658
		     /* Other previously defined identifier */
628
		PTR ( LOCATION ) loc = id_loc ( old_id ) ;
659
		     PTR(LOCATION) loc = id_loc(old_id);
629
		report ( crt_loc, ERR_basic_odr_decl ( old_id, loc ) ) ;
660
		     report(crt_loc, ERR_basic_odr_decl(old_id, loc));
630
		break ;
661
		     break;
631
	    }
662
	     }
632
	}
663
		}
633
    }
664
	}
634
 
665
 
635
    /* Construct the namespace if necessary */
666
	/* Construct the namespace if necessary */
636
    if ( IS_NULL_nspace ( ns ) ) {
667
	if (IS_NULL_nspace(ns)) {
637
	DECL_SPEC ds = ( dspec_defn | dspec_extern ) ;
668
		DECL_SPEC ds = (dspec_defn | dspec_extern);
638
	MAKE_id_nspace_name ( nm, ds, cns, decl_loc, ns, id ) ;
669
		MAKE_id_nspace_name(nm, ds, cns, decl_loc, ns, id);
639
	ns = make_namespace ( id, tag, 50 ) ;
670
		ns = make_namespace(id, tag, 50);
640
	COPY_nspace ( id_nspace_name_defn ( id ), ns ) ;
671
		COPY_nspace(id_nspace_name_defn(id), ns);
641
	set_member ( mem, id ) ;
672
		set_member(mem, id);
642
	if ( anon ) {
673
		if (anon) {
643
	    /* Anonymous namespaces are implicitly used */
674
			/* Anonymous namespaces are implicitly used */
644
	    IGNORE use_namespace ( ns, cns, cns ) ;
675
			IGNORE use_namespace(ns, cns, cns);
-
 
676
			if (do_dump) {
645
	    if ( do_dump ) dump_using ( ns, cns, &decl_loc ) ;
677
				dump_using(ns, cns, &decl_loc);
-
 
678
			}
646
	}
679
		}
647
    }
680
	}
648
 
681
 
649
    /* Adjust the current namespace */
682
	/* Adjust the current namespace */
-
 
683
	if (do_dump) {
650
    if ( do_dump ) dump_declare ( id, &decl_loc, 1 ) ;
684
		dump_declare(id, &decl_loc, 1);
-
 
685
	}
651
    push_namespace ( ns ) ;
686
	push_namespace(ns);
652
    cns = DEREF_nspace ( id_parent ( id ) ) ;
687
	cns = DEREF_nspace(id_parent(id));
653
    COPY_nspace ( nspace_parent ( ns ), cns ) ;
688
	COPY_nspace(nspace_parent(ns), cns);
654
    return ;
689
	return;
655
}
690
}
656
 
691
 
657
 
692
 
658
/*
693
/*
659
    END A NAMESPACE DEFINITION
694
    END A NAMESPACE DEFINITION
660
 
695
 
661
    This routine ends the definition of the current namespace.
696
    This routine ends the definition of the current namespace.
662
*/
697
*/
663
 
698
 
664
void end_namespace
699
void
665
    PROTO_N ( ( anon ) )
-
 
666
    PROTO_T ( int anon )
700
end_namespace(int anon)
667
{
701
{
668
    NAMESPACE ns ;
702
	NAMESPACE ns;
669
    clear_decl_blocks () ;
703
	clear_decl_blocks();
670
    ns = pop_namespace () ;
704
	ns = pop_namespace();
671
    if ( do_dump ) {
705
	if (do_dump) {
672
	IDENTIFIER id = DEREF_id ( nspace_name ( ns ) ) ;
706
		IDENTIFIER id = DEREF_id(nspace_name(ns));
673
	dump_undefine ( id, &crt_loc, 0 ) ;
707
		dump_undefine(id, &crt_loc, 0);
674
    }
708
	}
675
    UNUSED ( anon ) ;
709
	UNUSED(anon);
676
    return ;
710
	return;
677
}
711
}
678
 
712
 
679
 
713
 
680
/*
714
/*
681
    PROCESS A TARGET DEPENDENT DECLARATION SEQUENCE
715
    PROCESS A TARGET DEPENDENT DECLARATION SEQUENCE
682
 
716
 
683
    This routine is called in the processing of target dependent
717
    This routine is called in the processing of target dependent
684
    preprocessing directives within declaration sequences.  The directive
718
    preprocessing directives within declaration sequences.  The directive
685
    involved is given by dir, while c gives the associated condition for
719
    involved is given by dir, while c gives the associated condition for
686
    '#if' and '#elif'.
720
    '#if' and '#elif'.
687
*/
721
*/
688
 
722
 
689
void target_decl
723
void
690
    PROTO_N ( ( dir, c ) )
-
 
691
    PROTO_T ( int dir X EXP c )
724
target_decl(int dir, EXP c)
692
{
725
{
693
    if ( !IS_NULL_exp ( c ) ) {
726
	if (!IS_NULL_exp(c)) {
694
	report ( crt_loc, ERR_cpp_cond_if_ti_decl ( dir ) ) ;
727
		report(crt_loc, ERR_cpp_cond_if_ti_decl(dir));
695
    }
728
	}
696
    return ;
729
	return;
697
}
730
}
698
 
731
 
699
 
732
 
700
/*
733
/*
701
    BEGIN A DECLARATION BLOCK
734
    BEGIN A DECLARATION BLOCK
702
 
735
 
703
    A declaration block is a technique for partitioning the external
736
    A declaration block is a technique for partitioning the external
704
    declarations into subsets.  These subsets have no significance within
737
    declarations into subsets.  These subsets have no significance within
705
    the language, but are useful for indicating, for example, those
738
    the language, but are useful for indicating, for example, those
706
    identifiers which form part of a certain API.  This routine starts
739
    identifiers which form part of a certain API.  This routine starts
707
    a declaration block named id.
740
    a declaration block named id.
708
*/
741
*/
709
 
742
 
710
void begin_decl_block
743
void
711
    PROTO_N ( ( id ) )
-
 
712
    PROTO_T ( IDENTIFIER id )
744
begin_decl_block(IDENTIFIER id)
713
{
745
{
714
    NAMESPACE cns = nonblock_namespace ;
746
	NAMESPACE cns = nonblock_namespace;
715
    NAMESPACE sns = scope_namespace ;
747
	NAMESPACE sns = scope_namespace;
716
    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
748
	HASHID nm = DEREF_hashid(id_name(id));
717
    MEMBER mem = search_member ( sns, nm, 1 ) ;
749
	MEMBER mem = search_member(sns, nm, 1);
718
    id = DEREF_id ( member_id ( mem ) ) ;
750
	id = DEREF_id(member_id(mem));
719
    if ( IS_NULL_id ( id ) ) {
751
	if (IS_NULL_id(id)) {
720
	/* Create dummy namespace identifier */
752
		/* Create dummy namespace identifier */
721
	NAMESPACE bns = NULL_nspace ;
753
		NAMESPACE bns = NULL_nspace;
722
	DECL_SPEC ds = ( dspec_defn | dspec_extern ) ;
754
		DECL_SPEC ds = (dspec_defn | dspec_extern);
723
	MAKE_id_nspace_name ( nm, ds, cns, crt_loc, bns, id ) ;
755
		MAKE_id_nspace_name(nm, ds, cns, crt_loc, bns, id);
724
	bns = make_namespace ( id, nspace_block_tag, 0 ) ;
756
		bns = make_namespace(id, nspace_block_tag, 0);
725
	COPY_nspace ( id_nspace_name_defn ( id ), bns ) ;
757
		COPY_nspace(id_nspace_name_defn(id), bns);
726
	COPY_id ( member_id ( mem ), id ) ;
758
		COPY_id(member_id(mem), id);
727
    }
759
	}
728
    if ( do_dump ) {
760
	if (do_dump) {
729
	/* Output scope to dump file */
761
		/* Output scope to dump file */
730
	NAMESPACE bns = DEREF_nspace ( id_nspace_name_defn ( id ) ) ;
762
		NAMESPACE bns = DEREF_nspace(id_nspace_name_defn(id));
731
	dump_begin_scope ( id, bns, cns, &crt_loc ) ;
763
		dump_begin_scope(id, bns, cns, &crt_loc);
732
    }
764
	}
733
    if ( !IS_NULL_nspace ( cns ) ) {
765
	if (!IS_NULL_nspace(cns)) {
734
	/* Add to current namespace */
766
		/* Add to current namespace */
735
	STACK ( IDENTIFIER ) pids = DEREF_stack ( nspace_set ( cns ) ) ;
767
		STACK(IDENTIFIER)pids = DEREF_stack(nspace_set(cns));
736
	PUSH_id ( id, pids ) ;
768
		PUSH_id(id, pids);
737
	COPY_stack ( nspace_set ( cns ), pids ) ;
769
		COPY_stack(nspace_set(cns), pids);
738
    }
770
	}
739
    return ;
771
	return;
740
}
772
}
741
 
773
 
742
 
774
 
743
/*
775
/*
744
    END A DECLARATION BLOCK
776
    END A DECLARATION BLOCK
745
 
777
 
746
    This routine ends a declaration block named id or the current
778
    This routine ends a declaration block named id or the current
747
    declaration block if id is the null identifier.  If there is no
779
    declaration block if id is the null identifier.  If there is no
748
    current declaration block and force is true then an error is
780
    current declaration block and force is true then an error is
749
    raised.  The routine returns true if a declaration block is ended.
781
    raised.  The routine returns true if a declaration block is ended.
750
*/
782
*/
751
 
783
 
752
int end_decl_block
784
int
753
    PROTO_N ( ( id, force ) )
-
 
754
    PROTO_T ( IDENTIFIER id X int force )
785
end_decl_block(IDENTIFIER id, int force)
755
{
786
{
756
    int res = 0 ;
787
	int res = 0;
757
    NAMESPACE cns = nonblock_namespace ;
788
	NAMESPACE cns = nonblock_namespace;
758
    if ( !IS_NULL_nspace ( cns ) ) {
789
	if (!IS_NULL_nspace(cns)) {
759
	/* Add to current namespace */
790
		/* Add to current namespace */
760
	STACK ( IDENTIFIER ) pids = DEREF_stack ( nspace_set ( cns ) ) ;
791
		STACK(IDENTIFIER) pids = DEREF_stack(nspace_set(cns));
761
	if ( IS_NULL_stack ( pids ) ) {
792
		if (IS_NULL_stack(pids)) {
762
	    if ( force ) {
793
			if (force) {
763
		/* Stack shouldn't be empty */
794
				/* Stack shouldn't be empty */
764
		report ( crt_loc, ERR_pragma_dblock_end () ) ;
795
				report(crt_loc, ERR_pragma_dblock_end());
765
	    }
796
			}
766
	} else {
797
		} else {
767
	    IDENTIFIER pid ;
798
			IDENTIFIER pid;
768
	    POP_id ( pid, pids ) ;
799
			POP_id(pid, pids);
769
	    COPY_stack ( nspace_set ( cns ), pids ) ;
800
			COPY_stack(nspace_set(cns), pids);
770
	    if ( !IS_NULL_id ( id ) ) {
801
			if (!IS_NULL_id(id)) {
771
		/* Check block name if given */
802
				/* Check block name if given */
772
		HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
803
				HASHID nm = DEREF_hashid(id_name(id));
773
		HASHID pnm = DEREF_hashid ( id_name ( pid ) ) ;
804
				HASHID pnm = DEREF_hashid(id_name(pid));
774
		if ( !EQ_hashid ( nm, pnm ) ) {
805
				if (!EQ_hashid(nm, pnm)) {
-
 
806
					report(crt_loc,
775
		    report ( crt_loc, ERR_pragma_dblock_name ( pnm ) ) ;
807
					       ERR_pragma_dblock_name(pnm));
776
		}
808
				}
777
	    }
809
			}
778
	    if ( do_dump ) {
810
			if (do_dump) {
779
		/* Output scope to dump file */
811
				/* Output scope to dump file */
-
 
812
				NAMESPACE bns =
780
		NAMESPACE bns = DEREF_nspace ( id_nspace_name_defn ( pid ) ) ;
813
				    DEREF_nspace(id_nspace_name_defn(pid));
781
		dump_end_scope ( pid, bns, &crt_loc ) ;
814
				dump_end_scope(pid, bns, &crt_loc);
782
	    }
815
			}
783
	    res = 1 ;
816
			res = 1;
784
	}
817
		}
785
    }
818
	}
786
    return ( res ) ;
819
	return (res);
787
}
820
}
788
 
821
 
789
 
822
 
790
/*
823
/*
791
    END ALL DECLARATION BLOCKS
824
    END ALL DECLARATION BLOCKS
792
 
825
 
793
    This routine ends all the declaration blocks associated with the
826
    This routine ends all the declaration blocks associated with the
794
    current namespace.  This is called at the end of a namespace definition
827
    current namespace.  This is called at the end of a namespace definition
795
    and at the end of the input file.
828
    and at the end of the input file.
796
*/
829
*/
797
 
830
 
-
 
831
void
798
void clear_decl_blocks
832
clear_decl_blocks(void)
799
    PROTO_Z ()
-
 
800
{
833
{
801
    while ( end_decl_block ( NULL_id, 0 ) ) ;
834
	while (end_decl_block(NULL_id, 0));
802
    return ;
835
	return;
803
}
836
}
804
 
837
 
805
 
838
 
806
/*
839
/*
807
    FIND A NAMESPACE
840
    FIND A NAMESPACE
808
 
841
 
809
    This routine finds the namespace corresponding to the identifier id,
842
    This routine finds the namespace corresponding to the identifier id,
810
    returning the null namespace if id does not represent a class or a
843
    returning the null namespace if id does not represent a class or a
811
    namespace.
844
    namespace.
812
*/
845
*/
813
 
846
 
814
NAMESPACE find_namespace
847
NAMESPACE
815
    PROTO_N ( ( id ) )
-
 
816
    PROTO_T ( IDENTIFIER id )
848
find_namespace(IDENTIFIER id)
817
{
849
{
818
    NAMESPACE ns = NULL_nspace ;
850
	NAMESPACE ns = NULL_nspace;
819
    if ( !IS_NULL_id ( id ) ) {
851
	if (!IS_NULL_id(id)) {
820
	switch ( TAG_id ( id ) ) {
852
		switch (TAG_id(id)) {
821
	    case id_nspace_name_tag :
853
		case id_nspace_name_tag:
822
	    case id_nspace_alias_tag : {
854
		case id_nspace_alias_tag:
823
		/* Explicitly named namespaces */
855
			/* Explicitly named namespaces */
824
		ns = DEREF_nspace ( id_nspace_name_etc_defn ( id ) ) ;
856
			ns = DEREF_nspace(id_nspace_name_etc_defn(id));
825
		break ;
857
			break;
826
	    }
-
 
827
	    case id_class_name_tag :
858
		case id_class_name_tag:
828
	    case id_class_alias_tag : {
859
		case id_class_alias_tag: {
829
		/* Class namespaces */
860
			/* Class namespaces */
830
		TYPE t = DEREF_type ( id_class_name_etc_defn ( id ) ) ;
861
			TYPE t = DEREF_type(id_class_name_etc_defn(id));
831
		if ( IS_type_compound ( t ) ) {
862
			if (IS_type_compound(t)) {
-
 
863
				CLASS_TYPE ct =
832
		    CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
864
				    DEREF_ctype(type_compound_defn(t));
833
		    complete_class ( ct, 1 ) ;
865
				complete_class(ct, 1);
834
		    ns = DEREF_nspace ( ctype_member ( ct ) ) ;
866
				ns = DEREF_nspace(ctype_member(ct));
835
		} else {
867
			} else {
836
		    CLASS_TYPE ct = find_class ( id ) ;
868
				CLASS_TYPE ct = find_class(id);
837
		    if ( !IS_NULL_ctype ( ct ) ) {
869
				if (!IS_NULL_ctype(ct)) {
838
			complete_class ( ct, 1 ) ;
870
					complete_class(ct, 1);
839
			ns = DEREF_nspace ( ctype_member ( ct ) ) ;
871
					ns = DEREF_nspace(ctype_member(ct));
840
		    }
872
				}
841
		}
873
			}
842
		break ;
874
			break;
843
	    }
875
		}
844
	}
876
		}
845
    }
877
	}
846
    return ( ns ) ;
878
	return (ns);
847
}
879
}
848
 
880
 
849
 
881
 
850
/*
882
/*
851
    LOOK UP A NAMESPACE NAME
883
    LOOK UP A NAMESPACE NAME
852
 
884
 
853
    This routine looks up the identifier id as a namespace name in a
885
    This routine looks up the identifier id as a namespace name in a
854
    namespace alias or namespace directive.
886
    namespace alias or namespace directive.
855
*/
887
*/
856
 
888
 
857
NAMESPACE find_nspace_id
889
NAMESPACE
858
    PROTO_N ( ( id ) )
-
 
859
    PROTO_T ( IDENTIFIER id )
890
find_nspace_id(IDENTIFIER id)
860
{
891
{
861
    NAMESPACE ns ;
892
	NAMESPACE ns;
862
    if ( IS_id_nspace_name_etc ( id ) ) {
893
	if (IS_id_nspace_name_etc(id)) {
863
	ns = DEREF_nspace ( id_nspace_name_etc_defn ( id ) ) ;
894
		ns = DEREF_nspace(id_nspace_name_etc_defn(id));
864
    } else {
895
	} else {
865
	if ( crt_templ_qualifier == 0 ) {
896
		if (crt_templ_qualifier == 0) {
866
	    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
897
			HASHID nm = DEREF_hashid(id_name(id));
867
	    if ( crt_id_qualifier == qual_none ) {
898
			if (crt_id_qualifier == qual_none) {
868
		IDENTIFIER nid = find_type_id ( nm, 2 ) ;
899
				IDENTIFIER nid = find_type_id(nm, 2);
869
		if ( !IS_NULL_id ( nid ) ) id = nid ;
900
				if (!IS_NULL_id(nid)) {
-
 
901
					id = nid;
-
 
902
				}
870
	    } else {
903
			} else {
871
		NAMESPACE pns = DEREF_nspace ( id_parent ( id ) ) ;
904
				NAMESPACE pns = DEREF_nspace(id_parent(id));
872
		IDENTIFIER nid = find_qual_id ( pns, nm, 0, 2 ) ;
905
				IDENTIFIER nid = find_qual_id(pns, nm, 0, 2);
873
		if ( !IS_NULL_id ( nid ) ) id = nid ;
906
				if (!IS_NULL_id(nid)) {
-
 
907
					id = nid;
874
	    }
908
				}
-
 
909
			}
875
	}
910
		}
876
	ns = find_namespace ( id ) ;
911
		ns = find_namespace(id);
877
	if ( IS_NULL_nspace ( ns ) ) {
912
		if (IS_NULL_nspace(ns)) {
878
	    /* Invalid namespace identifier */
913
			/* Invalid namespace identifier */
879
	    report ( crt_loc, ERR_dcl_nspace_undef ( id ) ) ;
914
			report(crt_loc, ERR_dcl_nspace_undef(id));
880
	    return ( NULL_nspace ) ;
915
			return (NULL_nspace);
-
 
916
		}
881
	}
917
	}
882
    }
-
 
883
    use_id ( id, 0 ) ;
918
	use_id(id, 0);
884
    return ( ns ) ;
919
	return (ns);
885
}
920
}
886
 
921
 
887
 
922
 
888
/*
923
/*
889
    CONSTRUCT A NAMESPACE ALIAS
924
    CONSTRUCT A NAMESPACE ALIAS
890
 
925
 
891
    This routine sets up id as an alias for the namespace ns.  A namespace
926
    This routine sets up id as an alias for the namespace ns.  A namespace
892
    alias may be consistently redefined any number of times.
927
    alias may be consistently redefined any number of times.
893
*/
928
*/
894
 
929
 
895
void alias_namespace
930
void
896
    PROTO_N ( ( id, ns ) )
-
 
897
    PROTO_T ( IDENTIFIER id X NAMESPACE ns )
931
alias_namespace(IDENTIFIER id, NAMESPACE ns)
898
{
932
{
899
    MEMBER mem ;
933
	MEMBER mem;
900
    IDENTIFIER old_id ;
934
	IDENTIFIER old_id;
901
    NAMESPACE cns = crt_namespace ;
935
	NAMESPACE cns = crt_namespace;
902
    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
936
	HASHID nm = DEREF_hashid(id_name(id));
903
    DECL_SPEC ds = ( dspec_defn | dspec_extern ) ;
937
	DECL_SPEC ds = (dspec_defn | dspec_extern);
904
    if ( IS_NULL_nspace ( ns ) ) {
938
	if (IS_NULL_nspace(ns)) {
905
	/* Invalid namespace identifier */
939
		/* Invalid namespace identifier */
906
	begin_namespace ( id, 0 ) ;
940
		begin_namespace(id, 0);
907
	end_namespace ( 0 ) ;
941
		end_namespace(0);
908
	return ;
942
		return;
909
    }
943
	}
910
    if ( IS_nspace_ctype ( ns ) ) {
944
	if (IS_nspace_ctype(ns)) {
911
	/* Can't have a class namespace */
945
		/* Can't have a class namespace */
912
	report ( crt_loc, ERR_dcl_nspace_alias_class ( ns ) ) ;
946
		report(crt_loc, ERR_dcl_nspace_alias_class(ns));
913
    }
947
	}
914
 
948
 
915
    /* Look up namespace alias name */
949
	/* Look up namespace alias name */
916
    mem = search_member ( cns, nm, 1 ) ;
950
	mem = search_member(cns, nm, 1);
917
    old_id = DEREF_id ( member_id ( mem ) ) ;
951
	old_id = DEREF_id(member_id(mem));
918
 
952
 
919
    /* Check for redeclarations */
953
	/* Check for redeclarations */
920
    if ( !IS_NULL_id ( old_id ) ) {
954
	if (!IS_NULL_id(old_id)) {
921
	old_id = redecl_inherit ( old_id, qual_none, in_class_defn, 2 ) ;
955
		old_id = redecl_inherit(old_id, qual_none, in_class_defn, 2);
922
	switch ( TAG_id ( old_id ) ) {
956
		switch (TAG_id(old_id)) {
923
	    case id_nspace_name_tag : {
957
		case id_nspace_name_tag: {
924
		/* Previously defined namespace name */
958
			/* Previously defined namespace name */
925
		ERROR err ;
959
			ERROR err;
926
		NAMESPACE old_ns ;
960
			NAMESPACE old_ns;
927
		PTR ( LOCATION ) loc = id_loc ( old_id ) ;
961
			PTR(LOCATION) loc = id_loc(old_id);
928
		old_ns = DEREF_nspace ( id_nspace_name_defn ( old_id ) ) ;
962
			old_ns = DEREF_nspace(id_nspace_name_defn(old_id));
929
		report ( crt_loc, ERR_dcl_nspace_alias_bad ( old_id, loc ) ) ;
963
			report(crt_loc, ERR_dcl_nspace_alias_bad(old_id, loc));
930
		if ( EQ_nspace ( ns, old_ns ) ) {
964
			if (EQ_nspace(ns, old_ns)) {
931
		    /* No further action if consistent */
965
				/* No further action if consistent */
932
		    return ;
966
				return;
933
		}
967
			}
934
		/* Hide namespace name with namespace alias */
968
			/* Hide namespace name with namespace alias */
935
		err = ERR_dcl_nspace_alias_redef ( old_id, loc ) ;
969
			err = ERR_dcl_nspace_alias_redef(old_id, loc);
936
		report ( crt_loc, err ) ;
970
			report(crt_loc, err);
937
		break ;
971
			break;
938
	    }
972
		}
939
	    case id_nspace_alias_tag : {
973
		case id_nspace_alias_tag: {
940
		/* Previously defined namespace alias */
974
			/* Previously defined namespace alias */
941
		NAMESPACE old_ns ;
975
			NAMESPACE old_ns;
942
		old_ns = DEREF_nspace ( id_nspace_alias_defn ( old_id ) ) ;
976
			old_ns = DEREF_nspace(id_nspace_alias_defn(old_id));
943
		if ( !EQ_nspace ( ns, old_ns ) ) {
977
			if (!EQ_nspace(ns, old_ns)) {
944
		    /* Inconsistent alias redefinition */
978
				/* Inconsistent alias redefinition */
945
		    ERROR err ;
979
				ERROR err;
946
		    PTR ( LOCATION ) loc = id_loc ( old_id ) ;
980
				PTR(LOCATION) loc = id_loc(old_id);
947
		    err = ERR_dcl_nspace_alias_redef ( old_id, loc ) ;
981
				err = ERR_dcl_nspace_alias_redef(old_id, loc);
948
		    report ( crt_loc, err ) ;
982
				report(crt_loc, err);
949
		    COPY_nspace ( id_nspace_alias_defn ( old_id ), ns ) ;
983
				COPY_nspace(id_nspace_alias_defn(old_id), ns);
950
		}
984
			}
951
		return ;
985
			return;
952
	    }
986
		}
953
	    default : {
987
		default: {
954
		/* Other previously defined identifier */
988
			/* Other previously defined identifier */
955
		PTR ( LOCATION ) loc = id_loc ( old_id ) ;
989
			PTR(LOCATION) loc = id_loc(old_id);
956
		report ( crt_loc, ERR_basic_odr_decl ( old_id, loc ) ) ;
990
			report(crt_loc, ERR_basic_odr_decl(old_id, loc));
957
		break ;
991
			break;
958
	    }
992
		}
959
	}
993
		}
960
    }
994
	}
961
 
995
 
962
    /* Set up the namespace alias */
996
	/* Set up the namespace alias */
963
    MAKE_id_nspace_alias ( nm, ds, cns, decl_loc, ns, id ) ;
997
	MAKE_id_nspace_alias(nm, ds, cns, decl_loc, ns, id);
964
    set_member ( mem, id ) ;
998
	set_member(mem, id);
965
    return ;
999
	return;
966
}
1000
}
967
 
1001
 
968
 
1002
 
969
/*
1003
/*
970
    PROCESS A USING NAMESPACE DIRECTIVE
1004
    PROCESS A USING NAMESPACE DIRECTIVE
971
 
1005
 
972
    This routine processes a using namespace directive for the namespace ns.
1006
    This routine processes a using namespace directive for the namespace ns.
973
*/
1007
*/
974
 
1008
 
975
void using_namespace
1009
void
976
    PROTO_N ( ( ns ) )
-
 
977
    PROTO_T ( NAMESPACE ns )
1010
using_namespace(NAMESPACE ns)
978
{
1011
{
979
    if ( !IS_NULL_nspace ( ns ) ) {
1012
	if (!IS_NULL_nspace(ns)) {
980
	if ( IS_nspace_ctype ( ns ) ) {
1013
		if (IS_nspace_ctype(ns)) {
981
	    /* Namespace designates a class */
1014
			/* Namespace designates a class */
982
	    report ( crt_loc, ERR_dcl_nspace_udir_class ( ns ) ) ;
1015
			report(crt_loc, ERR_dcl_nspace_udir_class(ns));
983
	} else {
1016
		} else {
984
	    NAMESPACE cns = crt_namespace ;
1017
			NAMESPACE cns = crt_namespace;
985
	    NAMESPACE jns = join_namespace ( ns, cns ) ;
1018
			NAMESPACE jns = join_namespace(ns, cns);
986
	    if ( IS_NULL_nspace ( jns ) ) jns = global_namespace ;
1019
			if (IS_NULL_nspace(jns)) {
-
 
1020
				jns = global_namespace;
-
 
1021
			}
987
	    if ( !use_namespace ( ns, cns, jns ) ) {
1022
			if (!use_namespace(ns, cns, jns)) {
988
		/* Namespace already used */
1023
				/* Namespace already used */
989
		report ( crt_loc, ERR_dcl_nspace_udir_dup ( ns ) ) ;
1024
				report(crt_loc, ERR_dcl_nspace_udir_dup(ns));
990
	    }
1025
			}
991
	    uncache_namespace ( ns, 0 ) ;
1026
			uncache_namespace(ns, 0);
-
 
1027
			if (do_dump) {
992
	    if ( do_dump ) dump_using ( ns, cns, &crt_loc ) ;
1028
				dump_using(ns, cns, &crt_loc);
-
 
1029
			}
-
 
1030
		}
993
	}
1031
	}
994
    }
-
 
995
    return ;
1032
	return;
996
}
1033
}
997
 
1034
 
998
 
1035
 
999
/*
1036
/*
1000
    ADD A NESTED NAMESPACE
1037
    ADD A NESTED NAMESPACE
1001
 
1038
 
1002
    This routine adds the namespace ns to the look-up stack.  If ns is
1039
    This routine adds the namespace ns to the look-up stack.  If ns is
1003
    a nested namespace then the enclosing namespaces are also added.
1040
    a nested namespace then the enclosing namespaces are also added.
1004
    It returns true if the stack is changed.
1041
    It returns true if the stack is changed.
1005
*/
1042
*/
1006
 
1043
 
1007
int add_nested_nspace
1044
int
1008
    PROTO_N ( ( ns ) )
-
 
1009
    PROTO_T ( NAMESPACE ns )
1045
add_nested_nspace(NAMESPACE ns)
1010
{
1046
{
1011
    int res = 0 ;
1047
	int res = 0;
1012
    if ( !IS_NULL_nspace ( ns ) && !EQ_nspace ( ns, crt_namespace ) ) {
1048
	if (!IS_NULL_nspace(ns) && !EQ_nspace(ns, crt_namespace)) {
1013
	switch ( TAG_nspace ( ns ) ) {
1049
		switch (TAG_nspace(ns)) {
1014
	    case nspace_named_tag :
1050
		case nspace_named_tag:
1015
	    case nspace_unnamed_tag :
1051
		case nspace_unnamed_tag:
1016
	    case nspace_ctype_tag : {
1052
		case nspace_ctype_tag: {
1017
		IDENTIFIER id = DEREF_id ( nspace_name ( ns ) ) ;
1053
			IDENTIFIER id = DEREF_id(nspace_name(ns));
1018
		if ( !IS_NULL_id ( id ) ) {
1054
			if (!IS_NULL_id(id)) {
1019
		    NAMESPACE pns = DEREF_nspace ( id_parent ( id ) ) ;
1055
				NAMESPACE pns = DEREF_nspace(id_parent(id));
1020
		    IGNORE add_nested_nspace ( pns ) ;
1056
				IGNORE add_nested_nspace(pns);
-
 
1057
			}
-
 
1058
			add_namespace(ns);
-
 
1059
			res = 1;
-
 
1060
			break;
-
 
1061
		}
1021
		}
1062
		}
1022
		add_namespace ( ns ) ;
-
 
1023
		res = 1 ;
-
 
1024
		break ;
-
 
1025
	    }
-
 
1026
	}
1063
	}
1027
    }
-
 
1028
    return ( res ) ;
1064
	return (res);
1029
}
1065
}
1030
 
1066
 
1031
 
1067
 
1032
/*
1068
/*
1033
    REMOVE A NESTED NAMESPACE
1069
    REMOVE A NESTED NAMESPACE
Line 1035... Line 1071...
1035
    This routine removes the namespace ns from the look-up stack.  If
1071
    This routine removes the namespace ns from the look-up stack.  If
1036
    ns is a namespace class then the enclosing namespaces are also
1072
    ns is a namespace class then the enclosing namespaces are also
1037
    removed.  It returns true if the stack is changed.
1073
    removed.  It returns true if the stack is changed.
1038
*/
1074
*/
1039
 
1075
 
1040
int remove_nested_nspace
1076
int
1041
    PROTO_N ( ( ns ) )
-
 
1042
    PROTO_T ( NAMESPACE ns )
1077
remove_nested_nspace(NAMESPACE ns)
1043
{
1078
{
1044
    int res = 0 ;
1079
	int res = 0;
1045
    if ( !IS_NULL_nspace ( ns ) && !EQ_nspace ( ns, crt_namespace ) ) {
1080
	if (!IS_NULL_nspace(ns) && !EQ_nspace(ns, crt_namespace)) {
1046
	switch ( TAG_nspace ( ns ) ) {
1081
		switch (TAG_nspace(ns)) {
1047
	    case nspace_named_tag :
1082
		case nspace_named_tag:
1048
	    case nspace_unnamed_tag :
1083
		case nspace_unnamed_tag:
1049
	    case nspace_ctype_tag : {
1084
		case nspace_ctype_tag: {
1050
		IDENTIFIER id ;
1085
			IDENTIFIER id;
1051
		remove_namespace () ;
1086
			remove_namespace();
1052
		id = DEREF_id ( nspace_name ( ns ) ) ;
1087
			id = DEREF_id(nspace_name(ns));
1053
		if ( !IS_NULL_id ( id ) ) {
1088
			if (!IS_NULL_id(id)) {
1054
		    NAMESPACE pns = DEREF_nspace ( id_parent ( id ) ) ;
1089
				NAMESPACE pns = DEREF_nspace(id_parent(id));
1055
		    IGNORE remove_nested_nspace ( pns ) ;
1090
				IGNORE remove_nested_nspace(pns);
-
 
1091
			}
-
 
1092
			res = 1;
-
 
1093
			break;
-
 
1094
		}
1056
		}
1095
		}
1057
		res = 1 ;
-
 
1058
		break ;
-
 
1059
	    }
-
 
1060
	}
1096
	}
1061
    }
-
 
1062
    return ( res ) ;
1097
	return (res);
1063
}
1098
}
1064
 
1099
 
1065
 
1100
 
1066
/*
1101
/*
1067
    BEGIN THE LOOK-UP SCOPE FOR A DECLARATOR
1102
    BEGIN THE LOOK-UP SCOPE FOR A DECLARATOR
1068
 
1103
 
1069
    This routine is called immediately after the declarator id given with
1104
    This routine is called immediately after the declarator id given with
1070
    identifier qualifiers idtype and qns to set the name look-up
1105
    identifier qualifiers idtype and qns to set the name look-up
1071
    appropriately.  Thus for example, in 'int C::a = b ;', b is looked up
1106
    appropriately.  Thus for example, in 'int C::a = b ;', b is looked up
1072
    in the scope of C.
1107
    in the scope of C.
1073
*/
1108
*/
1074
 
1109
 
1075
void begin_declarator
1110
void
1076
    PROTO_N ( ( id, idtype, qns, scan ) )
-
 
1077
    PROTO_T ( IDENTIFIER id X QUALIFIER idtype X NAMESPACE qns X int scan )
1111
begin_declarator(IDENTIFIER id, QUALIFIER idtype, NAMESPACE qns, int scan)
1078
{
1112
{
1079
    NAMESPACE ns = NULL_nspace ;
1113
	NAMESPACE ns = NULL_nspace;
1080
    if ( idtype != qual_none ) {
1114
	if (idtype != qual_none) {
1081
	ns = DEREF_nspace ( id_parent ( id ) ) ;
1115
		ns = DEREF_nspace(id_parent(id));
1082
	if ( !IS_NULL_nspace ( ns ) && !IS_nspace_ctype ( ns ) ) {
1116
		if (!IS_NULL_nspace(ns) && !IS_nspace_ctype(ns)) {
1083
	    if ( !IS_NULL_nspace ( qns ) && !EQ_nspace ( qns, ns ) ) {
1117
			if (!IS_NULL_nspace(qns) && !EQ_nspace(qns, ns)) {
1084
		/* Should have an immediate member */
1118
				/* Should have an immediate member */
1085
		report ( crt_loc, ERR_lookup_qual_decl ( id, qns ) ) ;
1119
				report(crt_loc, ERR_lookup_qual_decl(id, qns));
1086
		ns = qns ;
1120
				ns = qns;
1087
	    }
1121
			}
1088
	}
1122
		}
1089
	if ( add_nested_nspace ( ns ) && scan ) {
1123
		if (add_nested_nspace(ns) && scan) {
1090
	    /* Rescan identifier if stack has changed */
1124
			/* Rescan identifier if stack has changed */
1091
	    RESCAN_LEXER ;
1125
			RESCAN_LEXER;
-
 
1126
		}
-
 
1127
	}
-
 
1128
	PUSH_nspace(ns, local_nspace_stack);
-
 
1129
	if (crt_state_depth == 0) {
-
 
1130
		id = underlying_id(id);
-
 
1131
		DEREF_loc(id_loc(id), decl_loc);
-
 
1132
	} else {
-
 
1133
		decl_loc = crt_loc;
1092
	}
1134
	}
1093
    }
-
 
1094
    PUSH_nspace ( ns, local_nspace_stack ) ;
-
 
1095
    if ( crt_state_depth == 0 ) {
-
 
1096
	id = underlying_id ( id ) ;
-
 
1097
	DEREF_loc ( id_loc ( id ), decl_loc ) ;
-
 
1098
    } else {
-
 
1099
	decl_loc = crt_loc ;
-
 
1100
    }
-
 
1101
    return ;
1135
	return;
1102
}
1136
}
1103
 
1137
 
1104
 
1138
 
1105
/*
1139
/*
1106
    END THE LOOK-UP SCOPE FOR A DECLARATOR
1140
    END THE LOOK-UP SCOPE FOR A DECLARATOR
1107
 
1141
 
1108
    This routine is called at the end of the initialiser or definition
1142
    This routine is called at the end of the initialiser or definition
1109
    of the declarator id to reset the name look-up.
1143
    of the declarator id to reset the name look-up.
1110
*/
1144
*/
1111
 
1145
 
1112
void end_declarator
1146
void
1113
    PROTO_N ( ( id, scan ) )
-
 
1114
    PROTO_T ( IDENTIFIER id X int scan )
1147
end_declarator(IDENTIFIER id, int scan)
1115
{
1148
{
1116
    NAMESPACE ns ;
1149
	NAMESPACE ns;
1117
    POP_nspace ( ns, local_nspace_stack ) ;
1150
	POP_nspace(ns, local_nspace_stack);
1118
    if ( IS_NULL_nspace ( ns ) ) {
1151
	if (IS_NULL_nspace(ns)) {
1119
	if ( !IS_NULL_id ( id ) ) {
1152
		if (!IS_NULL_id(id)) {
1120
	    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
1153
			HASHID nm = DEREF_hashid(id_name(id));
1121
	    IDENTIFIER cid = DEREF_id ( hashid_cache ( nm ) ) ;
1154
			IDENTIFIER cid = DEREF_id(hashid_cache(nm));
1122
	    if ( !EQ_id ( id, cid ) ) {
1155
			if (!EQ_id(id, cid)) {
1123
		/* Look-up may have changed */
1156
				/* Look-up may have changed */
1124
		COPY_id ( hashid_cache ( nm ), NULL_id ) ;
1157
				COPY_id(hashid_cache(nm), NULL_id);
1125
		if ( scan ) {
1158
				if (scan) {
1126
		    /* Rescan identifier if look-up has changed */
1159
					/* Rescan identifier if look-up has
-
 
1160
					 * changed */
1127
		    RESCAN_LEXER ;
1161
					RESCAN_LEXER;
-
 
1162
				}
-
 
1163
			}
1128
		}
1164
		}
1129
	    }
-
 
1130
	}
-
 
1131
    } else {
1165
	} else {
1132
	if ( remove_nested_nspace ( ns ) && scan ) {
1166
		if (remove_nested_nspace(ns) && scan) {
1133
	    /* Rescan identifier if stack has changed */
1167
			/* Rescan identifier if stack has changed */
1134
	    RESCAN_LEXER ;
1168
			RESCAN_LEXER;
1135
	}
1169
		}
1136
    }
1170
	}
1137
    return ;
1171
	return;
1138
}
1172
}
1139
 
1173
 
1140
 
1174
 
1141
/*
1175
/*
1142
    SET A NAMESPACE MEMBER
1176
    SET A NAMESPACE MEMBER
1143
 
1177
 
1144
    This routine sets the identifier id to be a namespace member as
1178
    This routine sets the identifier id to be a namespace member as
1145
    indicated by mem.  It also sets the look-up cache to id if appropriate.
1179
    indicated by mem.  It also sets the look-up cache to id if appropriate.
1146
*/
1180
*/
1147
 
1181
 
1148
void set_member
1182
void
1149
    PROTO_N ( ( mem, id ) )
-
 
1150
    PROTO_T ( MEMBER mem X IDENTIFIER id )
1183
set_member(MEMBER mem, IDENTIFIER id)
1151
{
1184
{
1152
    if ( !IS_NULL_member ( mem ) ) {
1185
	if (!IS_NULL_member(mem)) {
1153
	HASHID nm ;
1186
		HASHID nm;
1154
	IDENTIFIER cid ;
1187
		IDENTIFIER cid;
1155
	LIST ( NAMESPACE ) lns ;
1188
		LIST(NAMESPACE) lns;
1156
 
1189
 
1157
	/* Check any previous definition */
1190
		/* Check any previous definition */
1158
	IDENTIFIER pid = DEREF_id ( member_id ( mem ) ) ;
1191
		IDENTIFIER pid = DEREF_id(member_id(mem));
1159
	if ( !IS_NULL_id ( pid ) ) {
1192
		if (!IS_NULL_id(pid)) {
1160
	    if ( IS_id_token ( pid ) ) {
1193
			if (IS_id_token(pid)) {
1161
		IGNORE unify_id ( pid, id, 1 ) ;
1194
				IGNORE unify_id(pid, id, 1);
1162
	    } else if ( IS_id_token ( id ) ) {
1195
			} else if (IS_id_token(id)) {
1163
		if ( unify_id ( id, pid, 0 ) ) return ;
1196
				if (unify_id(id, pid, 0)) {
-
 
1197
					return;
1164
	    }
1198
				}
-
 
1199
			}
1165
	}
1200
		}
1166
 
1201
 
1167
	/* Check look-up cache */
1202
		/* Check look-up cache */
1168
	cid = NULL_id ;
1203
		cid = NULL_id;
1169
	nm = DEREF_hashid ( id_name ( id ) ) ;
1204
		nm = DEREF_hashid(id_name(id));
1170
	lns = LIST_stack ( namespace_stack ) ;
1205
		lns = LIST_stack(namespace_stack);
1171
	if ( !IS_NULL_list ( lns ) ) {
1206
		if (!IS_NULL_list(lns)) {
1172
	    /* Check for current namespace */
1207
			/* Check for current namespace */
1173
	    NAMESPACE ns = DEREF_nspace ( id_parent ( id ) ) ;
1208
			NAMESPACE ns = DEREF_nspace(id_parent(id));
1174
	    NAMESPACE pns = DEREF_nspace ( HEAD_list ( lns ) ) ;
1209
			NAMESPACE pns = DEREF_nspace(HEAD_list(lns));
1175
	    if ( EQ_nspace ( ns, pns ) ) {
1210
			if (EQ_nspace(ns, pns)) {
1176
		/* Check for unambiguous look-up */
1211
				/* Check for unambiguous look-up */
1177
		lns = DEREF_list ( nspace_use ( ns ) ) ;
1212
				lns = DEREF_list(nspace_use(ns));
1178
		if ( IS_NULL_list ( lns ) ) cid = id ;
1213
				if (IS_NULL_list(lns)) {
-
 
1214
					cid = id;
1179
	    }
1215
				}
-
 
1216
			}
1180
	}
1217
		}
1181
	COPY_id ( hashid_cache ( nm ), cid ) ;
1218
		COPY_id(hashid_cache(nm), cid);
1182
 
1219
 
1183
	/* Set member identifier */
1220
		/* Set member identifier */
1184
	COPY_id ( member_id ( mem ), id ) ;
1221
		COPY_id(member_id(mem), id);
1185
    }
1222
	}
1186
    return ;
1223
	return;
1187
}
1224
}
1188
 
1225
 
1189
 
1226
 
1190
/*
1227
/*
1191
    SET A NAMESPACE TYPE MEMBER
1228
    SET A NAMESPACE TYPE MEMBER
1192
 
1229
 
1193
    This routine sets the type identifier id to be a namespace member
1230
    This routine sets the type identifier id to be a namespace member
1194
    as indicated by mem.  Note that in C this just sets the alt field
1231
    as indicated by mem.  Note that in C this just sets the alt field
1195
    of mem, whereas in C++ it may also set the id field.
1232
    of mem, whereas in C++ it may also set the id field.
1196
*/
1233
*/
1197
 
1234
 
1198
void set_type_member
1235
void
1199
    PROTO_N ( ( mem, id ) )
-
 
1200
    PROTO_T ( MEMBER mem X IDENTIFIER id )
1236
set_type_member(MEMBER mem, IDENTIFIER id)
1201
{
1237
{
1202
    if ( !IS_NULL_member ( mem ) ) {
1238
	if (!IS_NULL_member(mem)) {
1203
#if LANGUAGE_CPP
1239
#if LANGUAGE_CPP
1204
	IDENTIFIER mid = DEREF_id ( member_id ( mem ) ) ;
1240
		IDENTIFIER mid = DEREF_id(member_id(mem));
1205
	if ( IS_NULL_id ( mid ) ) {
1241
		if (IS_NULL_id(mid)) {
1206
	    /* No object of the same name */
1242
			/* No object of the same name */
1207
	    set_member ( mem, id ) ;
1243
			set_member(mem, id);
1208
	} else {
1244
		} else {
1209
	    /* Hidden by object of the same name */
1245
			/* Hidden by object of the same name */
1210
	    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
1246
			HASHID nm = DEREF_hashid(id_name(id));
1211
	    DECL_SPEC ds = DEREF_dspec ( id_storage ( mid ) ) ;
1247
			DECL_SPEC ds = DEREF_dspec(id_storage(mid));
1212
	    if ( ( ds & dspec_inherit ) && !( ds & dspec_alias ) ) {
1248
			if ((ds & dspec_inherit) && !(ds & dspec_alias)) {
1213
		ds = DEREF_dspec ( id_storage ( id ) ) ;
1249
				ds = DEREF_dspec(id_storage(id));
1214
		if ( !( ds & dspec_inherit ) ) {
1250
				if (!(ds & dspec_inherit)) {
1215
		    /* An uninherited type overrrides an inherited object */
1251
					/* An uninherited type overrrides an
-
 
1252
					 * inherited object */
1216
		    COPY_id ( member_id ( mem ), id ) ;
1253
					COPY_id(member_id(mem), id);
-
 
1254
				}
-
 
1255
			}
-
 
1256
			COPY_id(hashid_cache(nm), NULL_id);
1217
		}
1257
		}
1218
	    }
-
 
1219
	    COPY_id ( hashid_cache ( nm ), NULL_id ) ;
-
 
1220
	}
-
 
1221
#endif
1258
#endif
1222
	COPY_id ( member_alt ( mem ), id ) ;
1259
		COPY_id(member_alt(mem), id);
1223
    }
1260
	}
1224
    return ;
1261
	return;
1225
}
1262
}
1226
 
1263
 
1227
 
1264
 
1228
/*
1265
/*
1229
    CLEAR A NAMESPACE MEMBER
1266
    CLEAR A NAMESPACE MEMBER
1230
 
1267
 
1231
    This routine clears all meanings of the member nm of the namespace ns.
1268
    This routine clears all meanings of the member nm of the namespace ns.
1232
*/
1269
*/
1233
 
1270
 
1234
void clear_member
1271
void
1235
    PROTO_N ( ( ns, nm ) )
-
 
1236
    PROTO_T ( NAMESPACE ns X HASHID nm )
1272
clear_member(NAMESPACE ns, HASHID nm)
1237
{
1273
{
1238
    MEMBER mem = search_member ( ns, nm, 0 ) ;
1274
	MEMBER mem = search_member(ns, nm, 0);
1239
    if ( !IS_NULL_member ( mem ) ) {
1275
	if (!IS_NULL_member(mem)) {
1240
	COPY_id ( member_id ( mem ), NULL_id ) ;
1276
		COPY_id(member_id(mem), NULL_id);
1241
	COPY_id ( member_alt ( mem ), NULL_id ) ;
1277
		COPY_id(member_alt(mem), NULL_id);
1242
    }
1278
	}
1243
    COPY_id ( hashid_cache ( nm ), NULL_id ) ;
1279
	COPY_id(hashid_cache(nm), NULL_id);
1244
    return ;
1280
	return;
1245
}
1281
}
1246
 
1282
 
1247
 
1283
 
1248
/*
1284
/*
1249
    FIND A MEMBER OF A NAMESPACE
1285
    FIND A MEMBER OF A NAMESPACE
1250
 
1286
 
1251
    This routine searches the namespace ns for a member named nm.  This
1287
    This routine searches the namespace ns for a member named nm.  This
1252
    is returned if found.  Otherwise if create is true then an empty
1288
    is returned if found.  Otherwise if create is true then an empty
1253
    member is created and returned.  Otherwise the null member is returned.
1289
    member is created and returned.  Otherwise the null member is returned.
1254
*/
1290
*/
1255
 
1291
 
1256
MEMBER search_member
1292
MEMBER
1257
    PROTO_N ( ( ns, nm, create ) )
-
 
1258
    PROTO_T ( NAMESPACE ns X HASHID nm X int create )
1293
search_member(NAMESPACE ns, HASHID nm, int create)
1259
{
1294
{
1260
    MEMBER mem ;
1295
	MEMBER mem;
1261
 
1296
 
1262
    if ( IS_NULL_nspace ( ns ) ) {
1297
	if (IS_NULL_nspace(ns)) {
1263
	/* Null namespace */
1298
		/* Null namespace */
1264
	if ( create ) {
1299
		if (create) {
1265
	    MAKE_member_small ( NULL_member, mem ) ;
1300
			MAKE_member_small(NULL_member, mem);
1266
	} else {
1301
		} else {
1267
	    mem = NULL_member ;
1302
			mem = NULL_member;
1268
	}
1303
		}
1269
 
1304
 
1270
    } else if ( IS_nspace_block_etc ( ns ) ) {
1305
	} else if (IS_nspace_block_etc(ns)) {
1271
	/* Small namespaces */
1306
		/* Small namespaces */
1272
	MEMBER last = DEREF_member ( nspace_last ( ns ) ) ;
1307
		MEMBER last = DEREF_member(nspace_last(ns));
1273
 
1308
 
1274
	/* Search through members */
1309
		/* Search through members */
1275
	mem = last ;
1310
		mem = last;
1276
	while ( !IS_NULL_member ( mem ) ) {
1311
		while (!IS_NULL_member(mem)) {
1277
	    IDENTIFIER mid = DEREF_id ( member_id ( mem ) ) ;
1312
			IDENTIFIER mid = DEREF_id(member_id(mem));
1278
	    if ( !IS_NULL_id ( mid ) ) {
1313
			if (!IS_NULL_id(mid)) {
1279
		HASHID mnm = DEREF_hashid ( id_name ( mid ) ) ;
1314
				HASHID mnm = DEREF_hashid(id_name(mid));
1280
		if ( EQ_hashid ( nm, mnm ) ) return ( mem ) ;
1315
				if (EQ_hashid(nm, mnm)) {
-
 
1316
					return (mem);
1281
	    }
1317
				}
1282
#if LANGUAGE_C
1318
#if LANGUAGE_C
-
 
1319
			} else {
1283
	    /* ... continues */ else {
1320
			/* ... continues */
1284
		/* Need to also check tag namespace in C */
1321
				/* Need to also check tag namespace in C */
1285
		mid = DEREF_id ( member_alt ( mem ) ) ;
1322
				mid = DEREF_id(member_alt(mem));
1286
		if ( !IS_NULL_id ( mid ) ) {
1323
				if (!IS_NULL_id(mid)) {
1287
		    HASHID mnm = DEREF_hashid ( id_name ( mid ) ) ;
1324
					HASHID mnm = DEREF_hashid(id_name(mid));
1288
		    if ( EQ_hashid ( nm, mnm ) ) return ( mem ) ;
1325
					if (EQ_hashid(nm, mnm)) {
-
 
1326
						return (mem);
1289
		}
1327
					}
1290
	    }
1328
				}
1291
#endif
1329
#endif
-
 
1330
			}
1292
	    mem = DEREF_member ( member_next ( mem ) ) ;
1331
			mem = DEREF_member(member_next(mem));
1293
	}
1332
		}
1294
 
1333
 
1295
	/* Create new member if necessary */
1334
		/* Create new member if necessary */
1296
	if ( create ) {
1335
		if (create) {
1297
	    MAKE_member_small ( last, mem ) ;
1336
			MAKE_member_small(last, mem);
1298
	    COPY_member ( nspace_last ( ns ), mem ) ;
1337
			COPY_member(nspace_last(ns), mem);
1299
	}
1338
		}
1300
 
-
 
1301
    } else {
1339
	} else {
1302
	/* Large namespaces */
1340
		/* Large namespaces */
1303
	PTR ( MEMBER ) ptr = DEREF_ptr ( nspace_named_etc_table ( ns ) ) ;
1341
		PTR(MEMBER) ptr = DEREF_ptr(nspace_named_etc_table(ns));
1304
	unsigned long sz = DEREF_ulong ( nspace_named_etc_size ( ns ) ) ;
1342
		unsigned long sz = DEREF_ulong(nspace_named_etc_size(ns));
1305
	unsigned long h = DEREF_ulong ( hashid_hash ( nm ) ) ;
1343
		unsigned long h = DEREF_ulong(hashid_hash(nm));
1306
	SIZE ( MEMBER ) psz = SCALE ( SIZE_member, ( h % sz ) ) ;
1344
		SIZE(MEMBER) psz = SCALE(SIZE_member,(h % sz));
1307
 
1345
 
1308
	/* Search through members */
1346
		/* Search through members */
1309
	ptr = STEP_ptr ( ptr, psz ) ;
1347
		ptr = STEP_ptr(ptr, psz);
1310
	mem = DEREF_member ( ptr ) ;
1348
		mem = DEREF_member(ptr);
1311
	while ( !IS_NULL_member ( mem ) ) {
1349
		while (!IS_NULL_member(mem)) {
1312
	    IDENTIFIER mid = DEREF_id ( member_id ( mem ) ) ;
1350
			IDENTIFIER mid = DEREF_id(member_id(mem));
1313
	    if ( !IS_NULL_id ( mid ) ) {
1351
			if (!IS_NULL_id(mid)) {
1314
		HASHID mnm = DEREF_hashid ( id_name ( mid ) ) ;
1352
				HASHID mnm = DEREF_hashid(id_name(mid));
1315
		if ( EQ_hashid ( nm, mnm ) ) return ( mem ) ;
1353
				if (EQ_hashid(nm, mnm)) {
-
 
1354
					return (mem);
1316
	    }
1355
				}
1317
#if LANGUAGE_C
1356
#if LANGUAGE_C
-
 
1357
			} else {
1318
	    /* ... continues */ else {
1358
			/* ... continues */
1319
		/* Need to also check tag namespace in C */
1359
				/* Need to also check tag namespace in C */
1320
		mid = DEREF_id ( member_alt ( mem ) ) ;
1360
				mid = DEREF_id(member_alt(mem));
1321
		if ( !IS_NULL_id ( mid ) ) {
1361
				if (!IS_NULL_id(mid)) {
1322
		    HASHID mnm = DEREF_hashid ( id_name ( mid ) ) ;
1362
					HASHID mnm = DEREF_hashid(id_name(mid));
1323
		    if ( EQ_hashid ( nm, mnm ) ) return ( mem ) ;
1363
					if (EQ_hashid(nm, mnm)) {
-
 
1364
						return (mem);
1324
		}
1365
					}
1325
	    }
1366
				}
1326
#endif
1367
#endif
-
 
1368
			}
1327
	    mem = DEREF_member ( member_large_tnext ( mem ) ) ;
1369
			mem = DEREF_member(member_large_tnext(mem));
1328
	}
1370
		}
1329
 
1371
 
1330
	/* Create new member if necessary */
1372
		/* Create new member if necessary */
1331
	if ( create ) {
1373
		if (create) {
1332
	    MEMBER last ;
1374
			MEMBER last;
1333
	    mem = DEREF_member ( ptr ) ;
1375
			mem = DEREF_member(ptr);
1334
	    MAKE_member_large ( NULL_member, mem, mem ) ;
1376
			MAKE_member_large(NULL_member, mem, mem);
1335
	    COPY_member ( ptr, mem ) ;
1377
			COPY_member(ptr, mem);
1336
	    last = DEREF_member ( nspace_last ( ns ) ) ;
1378
			last = DEREF_member(nspace_last(ns));
1337
	    if ( IS_NULL_member ( last ) ) {
1379
			if (IS_NULL_member(last)) {
1338
		COPY_member ( nspace_named_etc_first ( ns ), mem ) ;
1380
				COPY_member(nspace_named_etc_first(ns), mem);
1339
	    } else {
1381
			} else {
1340
		COPY_member ( member_next ( last ), mem ) ;
1382
				COPY_member(member_next(last), mem);
1341
	    }
1383
			}
1342
	    COPY_member ( nspace_last ( ns ), mem ) ;
1384
			COPY_member(nspace_last(ns), mem);
1343
	}
1385
		}
1344
    }
1386
	}
1345
    return ( mem ) ;
1387
	return (mem);
1346
}
1388
}
1347
 
1389
 
1348
 
1390
 
1349
/*
1391
/*
1350
    UPDATE A NAMESPACE MEMBER
1392
    UPDATE A NAMESPACE MEMBER
1351
 
1393
 
1352
    This routine copies the member mem of the namespace ns to the end of
1394
    This routine copies the member mem of the namespace ns to the end of
1353
    the list of all members.  In block namespaces this is to force the
1395
    the list of all members.  In block namespaces this is to force the
1354
    member to be re-examined in make_decl_stmt.  In class namespaces this
1396
    member to be re-examined in make_decl_stmt.  In class namespaces this
1355
    is to preserve the order of the data members.
1397
    is to preserve the order of the data members.
1356
*/
1398
*/
1357
 
1399
 
1358
MEMBER update_member
1400
MEMBER
1359
    PROTO_N ( ( ns, mem ) )
-
 
1360
    PROTO_T ( NAMESPACE ns X MEMBER mem )
1401
update_member(NAMESPACE ns, MEMBER mem)
1361
{
1402
{
1362
    IDENTIFIER id = DEREF_id ( member_id ( mem ) ) ;
1403
	IDENTIFIER id = DEREF_id(member_id(mem));
1363
    IDENTIFIER alt = DEREF_id ( member_alt ( mem ) ) ;
1404
	IDENTIFIER alt = DEREF_id(member_alt(mem));
1364
    COPY_id ( member_id ( mem ), NULL_id ) ;
1405
	COPY_id(member_id(mem), NULL_id);
1365
    COPY_id ( member_alt ( mem ), NULL_id ) ;
1406
	COPY_id(member_alt(mem), NULL_id);
1366
    if ( IS_member_small ( mem ) ) {
1407
	if (IS_member_small(mem)) {
1367
	/* Create new small member */
1408
		/* Create new small member */
1368
	MEMBER last = DEREF_member ( nspace_last ( ns ) ) ;
1409
		MEMBER last = DEREF_member(nspace_last(ns));
1369
	MAKE_member_small ( last, mem ) ;
1410
		MAKE_member_small(last, mem);
1370
	COPY_member ( nspace_last ( ns ), mem ) ;
1411
		COPY_member(nspace_last(ns), mem);
1371
    } else {
1412
	} else {
1372
	/* Create new large member */
1413
		/* Create new large member */
1373
	if ( !IS_NULL_id ( id ) ) {
1414
		if (!IS_NULL_id(id)) {
1374
	    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
1415
			HASHID nm = DEREF_hashid(id_name(id));
1375
	    mem = search_member ( ns, nm, 1 ) ;
1416
			mem = search_member(ns, nm, 1);
1376
	} else if ( !IS_NULL_id ( alt ) ) {
1417
		} else if (!IS_NULL_id(alt)) {
1377
	    HASHID nm = DEREF_hashid ( id_name ( alt ) ) ;
1418
			HASHID nm = DEREF_hashid(id_name(alt));
1378
	    mem = search_member ( ns, nm, 1 ) ;
1419
			mem = search_member(ns, nm, 1);
1379
	}
1420
		}
1380
    }
1421
	}
1381
    COPY_id ( member_id ( mem ), id ) ;
1422
	COPY_id(member_id(mem), id);
1382
    COPY_id ( member_alt ( mem ), alt ) ;
1423
	COPY_id(member_alt(mem), alt);
1383
    return ( mem ) ;
1424
	return (mem);
1384
}
1425
}
1385
 
1426
 
1386
 
1427
 
1387
/*
1428
/*
1388
    FIND A TYPE IDENTIFIER
1429
    FIND A TYPE IDENTIFIER
1389
 
1430
 
1390
    This routine checks whether the identifier id is a type name (if bit 0
1431
    This routine checks whether the identifier id is a type name (if bit 0
1391
    of type is true) or a namespace name (if bit 1 of type is true).  In
1432
    of type is true) or a namespace name (if bit 1 of type is true).  In
1392
    C only struct, union and enum tags are allowed.
1433
    C only struct, union and enum tags are allowed.
1393
*/
1434
*/
1394
 
1435
 
1395
static IDENTIFIER select_type_id
1436
static IDENTIFIER
1396
    PROTO_N ( ( id, type ) )
-
 
1397
    PROTO_T ( IDENTIFIER id X int type )
1437
select_type_id(IDENTIFIER id, int type)
1398
{
1438
{
1399
    if ( !IS_NULL_id ( id ) ) {
1439
	if (!IS_NULL_id(id)) {
1400
	switch ( TAG_id ( id ) ) {
1440
		switch (TAG_id(id)) {
1401
	    case id_class_name_tag :
1441
		case id_class_name_tag:
1402
	    case id_enum_name_tag : {
1442
		case id_enum_name_tag:
1403
		if ( type & 1 ) return ( id ) ;
1443
			if (type & 1) {
1404
		break ;
1444
				return (id);
1405
	    }
1445
			}
-
 
1446
			break;
1406
#if LANGUAGE_CPP
1447
#if LANGUAGE_CPP
1407
	    case id_class_alias_tag :
1448
		case id_class_alias_tag:
1408
	    case id_enum_alias_tag :
1449
		case id_enum_alias_tag:
1409
	    case id_type_alias_tag : {
1450
		case id_type_alias_tag:
1410
		if ( type & 1 ) return ( id ) ;
1451
			if (type & 1) {
1411
		break ;
1452
				return (id);
1412
	    }
1453
			}
-
 
1454
			break;
1413
	    case id_nspace_name_tag :
1455
		case id_nspace_name_tag:
1414
	    case id_nspace_alias_tag : {
1456
		case id_nspace_alias_tag:
1415
		if ( type & 2 ) return ( id ) ;
1457
			if (type & 2) {
1416
		break ;
1458
				return (id);
1417
	    }
1459
			}
-
 
1460
			break;
1418
#endif
1461
#endif
-
 
1462
		}
1419
	}
1463
	}
1420
    }
-
 
1421
    return ( NULL_id ) ;
1464
	return (NULL_id);
1422
}
1465
}
1423
 
1466
 
1424
 
1467
 
1425
/*
1468
/*
1426
    FIND A TYPE MEMBER
1469
    FIND A TYPE MEMBER
1427
 
1470
 
1428
    This routine returns the type or namespace name associated with the
1471
    This routine returns the type or namespace name associated with the
1429
    member mem, or the null identifier if this does not exist.  The
1472
    member mem, or the null identifier if this does not exist.  The
1430
    type argument is as above.  In C++ it is necessary to check both
1473
    type argument is as above.  In C++ it is necessary to check both
1431
    the id and the alt fields of mem, whereas in C only the alt field
1474
    the id and the alt fields of mem, whereas in C only the alt field
1432
    needs to be examined.
1475
    needs to be examined.
1433
*/
1476
*/
1434
 
1477
 
1435
IDENTIFIER type_member
1478
IDENTIFIER
1436
    PROTO_N ( ( mem, type ) )
-
 
1437
    PROTO_T ( MEMBER mem X int type )
1479
type_member(MEMBER mem, int type)
1438
{
1480
{
1439
    IDENTIFIER id = NULL_id ;
1481
	IDENTIFIER id = NULL_id;
1440
    if ( !IS_NULL_member ( mem ) ) {
1482
	if (!IS_NULL_member(mem)) {
1441
#if LANGUAGE_CPP
1483
#if LANGUAGE_CPP
1442
	id = DEREF_id ( member_id ( mem ) ) ;
1484
		id = DEREF_id(member_id(mem));
1443
	id = select_type_id ( id, type ) ;
1485
		id = select_type_id(id, type);
1444
	if ( IS_NULL_id ( id ) ) {
1486
		if (IS_NULL_id(id)) {
1445
	    id = DEREF_id ( member_alt ( mem ) ) ;
1487
			id = DEREF_id(member_alt(mem));
1446
	    id = select_type_id ( id, type ) ;
1488
			id = select_type_id(id, type);
1447
	}
1489
		}
1448
#else
1490
#else
1449
	id = DEREF_id ( member_alt ( mem ) ) ;
1491
		id = DEREF_id(member_alt(mem));
1450
	id = select_type_id ( id, type ) ;
1492
		id = select_type_id(id, type);
1451
#endif
1493
#endif
1452
    }
1494
	}
1453
    return ( id ) ;
1495
	return (id);
1454
}
1496
}
1455
 
1497
 
1456
 
1498
 
1457
/*
1499
/*
1458
    IS AN IDENTIFIER IN A LIST?
1500
    IS AN IDENTIFIER IN A LIST?
Line 1460... Line 1502...
1460
    This routine checks whether the identifier id is in the list of
1502
    This routine checks whether the identifier id is in the list of
1461
    ambiguous meanings given by pid and pids.  Functions are excluded
1503
    ambiguous meanings given by pid and pids.  Functions are excluded
1462
    because of the complications introduced by using-declarations and
1504
    because of the complications introduced by using-declarations and
1463
    overloading.  Overload resolution will eliminate duplicate entries
1505
    overloading.  Overload resolution will eliminate duplicate entries
1464
    in this case.
1506
    in this case.
1465
*/
1507
*/
1466
 
1508
 
1467
static int already_found_id
1509
static int
1468
    PROTO_N ( ( id, pid, pids ) )
-
 
1469
    PROTO_T ( IDENTIFIER id X IDENTIFIER pid X LIST ( IDENTIFIER ) pids )
1510
already_found_id(IDENTIFIER id, IDENTIFIER pid, LIST(IDENTIFIER) pids)
1470
{
-
 
1471
    if ( IS_id_function_etc ( id ) ) {
-
 
1472
	/* Exclude functions */
-
 
1473
	return ( 0 ) ;
-
 
1474
    }
-
 
1475
    if ( !IS_NULL_id ( pid ) ) {
-
 
1476
	if ( IS_id_ambig ( pid ) ) {
-
 
1477
	    /* Check ambiguous identifiers */
-
 
1478
	    LIST ( IDENTIFIER ) qids = DEREF_list ( id_ambig_ids ( pid ) ) ;
-
 
1479
	    if ( already_found_id ( id, NULL_id, qids ) ) return ( 1 ) ;
-
 
1480
	} else {
-
 
1481
	    /* Check simple identifiers */
-
 
1482
	    if ( !IS_id_function_etc ( pid ) ) {
-
 
1483
		id = DEREF_id ( id_alias ( id ) ) ;
-
 
1484
		pid = DEREF_id ( id_alias ( pid ) ) ;
-
 
1485
		if ( EQ_id ( id, pid ) ) return ( 1 ) ;
-
 
1486
	    }
-
 
1487
	}
-
 
1488
    }
-
 
1489
    if ( !IS_NULL_list ( pids ) ) {
-
 
1490
	/* Check identifier lists */
-
 
1491
	IDENTIFIER qid = DEREF_id ( HEAD_list ( pids ) ) ;
-
 
1492
	pids = TAIL_list ( pids ) ;
-
 
1493
	return ( already_found_id ( id, qid, pids ) ) ;
-
 
1494
    }
-
 
1495
    return ( 0 ) ;
-
 
1496
}
-
 
1497
 
-
 
1498
 
-
 
1499
/*
-
 
1500
    LOOK UP AN IDENTIFIER IN A NAMESPACE
-
 
1501
 
-
 
1502
    This routine looks up the identifier nm in the namespace ns.
-
 
1503
*/
-
 
1504
 
-
 
1505
IDENTIFIER search_id
-
 
1506
    PROTO_N ( ( ns, nm, create, type ) )
-
 
1507
    PROTO_T ( NAMESPACE ns X HASHID nm X int create X int type )
-
 
1508
{
1511
{
1509
    IDENTIFIER id ;
-
 
1510
    MEMBER mem = search_member ( ns, nm, create ) ;
-
 
1511
    if ( !IS_NULL_member ( mem ) ) {
1512
	if (IS_id_function_etc(id)) {
1512
	if ( type ) {
1513
		/* Exclude functions */
1513
	    id = type_member ( mem, type ) ;
-
 
1514
	} else {
1514
		return (0);
1515
	    id = DEREF_id ( member_id ( mem ) ) ;
-
 
1516
	}
1515
	}
-
 
1516
	if (!IS_NULL_id(pid)) {
-
 
1517
		if (IS_id_ambig(pid)) {
-
 
1518
			/* Check ambiguous identifiers */
-
 
1519
			LIST(IDENTIFIER) qids = DEREF_list(id_ambig_ids(pid));
-
 
1520
			if (already_found_id(id, NULL_id, qids)) {
-
 
1521
				return (1);
-
 
1522
			}
1517
    } else {
1523
		} else {
-
 
1524
			/* Check simple identifiers */
-
 
1525
			if (!IS_id_function_etc(pid)) {
-
 
1526
				id = DEREF_id(id_alias(id));
-
 
1527
				pid = DEREF_id(id_alias(pid));
-
 
1528
				if (EQ_id(id, pid)) {
-
 
1529
					return (1);
-
 
1530
				}
-
 
1531
			}
-
 
1532
		}
-
 
1533
	}
-
 
1534
	if (!IS_NULL_list(pids)) {
-
 
1535
		/* Check identifier lists */
-
 
1536
		IDENTIFIER qid = DEREF_id(HEAD_list(pids));
1518
	id = NULL_id ;
1537
		pids = TAIL_list(pids);
-
 
1538
		return (already_found_id(id, qid, pids));
1519
    }
1539
	}
1520
    return ( id ) ;
1540
	return (0);
1521
}
1541
}
1522
 
1542
 
1523
 
1543
 
-
 
1544
/*
-
 
1545
    LOOK UP AN IDENTIFIER IN A NAMESPACE
-
 
1546
 
-
 
1547
    This routine looks up the identifier nm in the namespace ns.
-
 
1548
*/
-
 
1549
 
-
 
1550
IDENTIFIER
-
 
1551
search_id(NAMESPACE ns, HASHID nm, int create, int type)
-
 
1552
{
-
 
1553
	IDENTIFIER id;
-
 
1554
	MEMBER mem = search_member(ns, nm, create);
-
 
1555
	if (!IS_NULL_member(mem)) {
-
 
1556
		if (type) {
-
 
1557
			id = type_member(mem, type);
-
 
1558
		} else {
-
 
1559
			id = DEREF_id(member_id(mem));
-
 
1560
		}
-
 
1561
	} else {
-
 
1562
		id = NULL_id;
-
 
1563
	}
-
 
1564
	return (id);
-
 
1565
}
-
 
1566
 
-
 
1567
 
1524
/*
1568
/*
1525
    SEARCH A NAMESPACE FOR AN IDENTIFIER
1569
    SEARCH A NAMESPACE FOR AN IDENTIFIER
1526
 
1570
 
1527
    This routine searches the namespace ns and used namespaces for an
1571
    This routine searches the namespace ns and used namespaces for an
1528
    identifier named nm, which is returned if found.  Otherwise if create
1572
    identifier named nm, which is returned if found.  Otherwise if create
1529
    is true then a dummy identifier is created and returned.  Otherwise
1573
    is true then a dummy identifier is created and returned.  Otherwise
1530
    the null identifier is returned.  qual is true for qualified look-ups.
1574
    the null identifier is returned.  qual is true for qualified look-ups.
1531
    If type is nonzero then only type and namespace names are considered.
1575
    If type is nonzero then only type and namespace names are considered.
1532
    rns gives the original value of ns for use when recursively searching
1576
    rns gives the original value of ns for use when recursively searching
1533
    used namespaces.
1577
    used namespaces.
1534
*/
1578
*/
1535
 
1579
 
1536
static IDENTIFIER search_nspace
1580
static IDENTIFIER
1537
    PROTO_N ( ( ns, nm, rns, qual, create, type ) )
-
 
1538
    PROTO_T ( NAMESPACE ns X HASHID nm X NAMESPACE rns X int qual X
1581
search_nspace(NAMESPACE ns, HASHID nm, NAMESPACE rns, int qual, int create,
1539
	      int create X int type )
1582
	      int type)
1540
{
1583
{
1541
    IDENTIFIER id ;
1584
	IDENTIFIER id;
1542
    LIST ( NAMESPACE ) uns ;
1585
	LIST(NAMESPACE) uns;
1543
 
1586
 
1544
    /* Allow for class namespaces */
1587
	/* Allow for class namespaces */
1545
    if ( IS_nspace_ctype ( ns ) ) {
1588
	if (IS_nspace_ctype(ns)) {
1546
	id = search_field ( ns, nm, create, type ) ;
1589
		id = search_field(ns, nm, create, type);
1547
	return ( id ) ;
1590
		return (id);
1548
    }
1591
	}
1549
 
1592
 
1550
    /* Search main namespace */
1593
	/* Search main namespace */
1551
    id = search_id ( ns, nm, create, type ) ;
1594
	id = search_id(ns, nm, create, type);
1552
    if ( !IS_NULL_id ( id ) && qual ) {
1595
	if (!IS_NULL_id(id) && qual) {
1553
	/* Return found identifier */
1596
		/* Return found identifier */
1554
	return ( id ) ;
1597
		return (id);
1555
    }
1598
	}
1556
 
1599
 
1557
    /* Search used namespaces */
1600
	/* Search used namespaces */
1558
    uns = DEREF_list ( nspace_use ( ns ) ) ;
1601
	uns = DEREF_list(nspace_use(ns));
1559
    if ( !IS_NULL_list ( uns ) ) {
1602
	if (!IS_NULL_list(uns)) {
1560
	LIST ( NAMESPACE ) vns = DEREF_list ( nspace_join ( ns ) ) ;
1603
		LIST(NAMESPACE) vns = DEREF_list(nspace_join(ns));
1561
	LIST ( NAMESPACE ) uns_orig = uns ;
1604
		LIST(NAMESPACE) uns_orig = uns;
1562
	LIST ( NAMESPACE ) vns_orig = vns ;
1605
		LIST(NAMESPACE) vns_orig = vns;
1563
	LIST ( IDENTIFIER ) ambig = NULL_list ( IDENTIFIER ) ;
1606
		LIST(IDENTIFIER) ambig = NULL_list(IDENTIFIER);
1564
	COPY_list ( nspace_use ( ns ), NULL_list ( NAMESPACE ) ) ;
1607
		COPY_list(nspace_use(ns), NULL_list(NAMESPACE));
1565
	COPY_list ( nspace_join ( ns ), NULL_list ( NAMESPACE ) ) ;
1608
		COPY_list(nspace_join(ns), NULL_list(NAMESPACE));
1566
	while ( !IS_NULL_list ( uns ) ) {
1609
		while (!IS_NULL_list(uns)) {
1567
	    NAMESPACE pns = DEREF_nspace ( HEAD_list ( uns ) ) ;
1610
			NAMESPACE pns = DEREF_nspace(HEAD_list(uns));
1568
	    NAMESPACE jns = DEREF_nspace ( HEAD_list ( vns ) ) ;
1611
			NAMESPACE jns = DEREF_nspace(HEAD_list(vns));
1569
	    if ( qual || is_subnspace ( rns, jns ) ) {
1612
			if (qual || is_subnspace(rns, jns)) {
1570
		/* Look-up identifier in used namespace */
1613
				/* Look-up identifier in used namespace */
1571
		IDENTIFIER pid ;
1614
				IDENTIFIER pid;
1572
		pid = search_nspace ( pns, nm, rns, qual, 0, type ) ;
1615
				pid = search_nspace(pns, nm, rns, qual, 0,
-
 
1616
						    type);
1573
		if ( !IS_NULL_id ( pid ) ) {
1617
				if (!IS_NULL_id(pid)) {
1574
		    /* Add found identifier to list */
1618
					/* Add found identifier to list */
1575
		    if ( IS_NULL_id ( id ) ) {
1619
					if (IS_NULL_id(id)) {
1576
			id = pid ;
1620
						id = pid;
1577
		    } else if ( !already_found_id ( pid, id, ambig ) ) {
1621
					} else if (!already_found_id(pid, id,
-
 
1622
								     ambig)) {
1578
			CONS_id ( pid, ambig, ambig ) ;
1623
						CONS_id(pid, ambig, ambig);
1579
		    }
1624
					}
1580
		}
1625
				}
1581
	    } else {
1626
			} else {
1582
		/* Postpone look-up until join namespace */
1627
				/* Postpone look-up until join namespace */
1583
		if ( use_namespace ( pns, jns, jns ) ) {
1628
				if (use_namespace(pns, jns, jns)) {
1584
		    CONS_nspace ( jns, join_nspaces, join_nspaces ) ;
1629
					CONS_nspace(jns, join_nspaces,
-
 
1630
						    join_nspaces);
1585
		}
1631
				}
1586
	    }
1632
			}
1587
	    vns = TAIL_list ( vns ) ;
1633
			vns = TAIL_list(vns);
1588
	    uns = TAIL_list ( uns ) ;
1634
			uns = TAIL_list(uns);
1589
	}
1635
		}
1590
	if ( !IS_NULL_list ( ambig ) ) {
1636
		if (!IS_NULL_list(ambig)) {
1591
	    /* Ambiguous resolution */
1637
			/* Ambiguous resolution */
1592
	    DECL_SPEC ds ;
1638
			DECL_SPEC ds;
1593
	    CONS_id ( id, ambig, ambig ) ;
1639
			CONS_id(id, ambig, ambig);
1594
	    ds = find_ambig_dspec ( ambig ) ;
1640
			ds = find_ambig_dspec(ambig);
1595
	    MAKE_id_ambig ( nm, ds, rns, crt_loc, ambig, 1, id ) ;
1641
			MAKE_id_ambig(nm, ds, rns, crt_loc, ambig, 1, id);
1596
	}
1642
		}
1597
	COPY_list ( nspace_use ( ns ), uns_orig ) ;
1643
		COPY_list(nspace_use(ns), uns_orig);
1598
	COPY_list ( nspace_join ( ns ), vns_orig ) ;
1644
		COPY_list(nspace_join(ns), vns_orig);
1599
    }
1645
	}
1600
 
1646
 
1601
    /* Create dummy identifier if necessary */
1647
	/* Create dummy identifier if necessary */
1602
    if ( IS_NULL_id ( id ) && create ) {
1648
	if (IS_NULL_id(id) && create) {
1603
	MAKE_id_undef ( nm, dspec_none, ns, crt_loc, id ) ;
1649
		MAKE_id_undef(nm, dspec_none, ns, crt_loc, id);
1604
    }
1650
	}
1605
    return ( id ) ;
1651
	return (id);
1606
}
1652
}
1607
 
1653
 
1608
 
1654
 
1609
/*
1655
/*
1610
    EXTERNAL NAME LOOK-UP
1656
    EXTERNAL NAME LOOK-UP
1611
 
1657
 
1612
    This routine searches all the namespaces in the current namespace stack
1658
    This routine searches all the namespaces in the current namespace stack
1613
    which are contained within pns for the identifier pns.  If type is
1659
    which are contained within pns for the identifier pns.  If type is
1614
    nonzero then only type and namespace names are considered.
1660
    nonzero then only type and namespace names are considered.
1615
*/
1661
*/
1616
 
1662
 
1617
IDENTIFIER find_extern_id
1663
IDENTIFIER
1618
    PROTO_N ( ( nm, pns, type ) )
-
 
1619
    PROTO_T ( HASHID nm X NAMESPACE pns X int type )
1664
find_extern_id(HASHID nm, NAMESPACE pns, int type)
1620
{
1665
{
1621
    IDENTIFIER id = NULL_id ;
1666
	IDENTIFIER id = NULL_id;
1622
    LIST ( NAMESPACE ) lns = LIST_stack ( namespace_stack ) ;
1667
	LIST(NAMESPACE) lns = LIST_stack(namespace_stack);
1623
    while ( !IS_NULL_list ( lns ) ) {
1668
	while (!IS_NULL_list(lns)) {
1624
	NAMESPACE ns = DEREF_nspace ( HEAD_list ( lns ) ) ;
1669
		NAMESPACE ns = DEREF_nspace(HEAD_list(lns));
1625
	if ( !IS_NULL_nspace ( ns ) ) {
1670
		if (!IS_NULL_nspace(ns)) {
1626
	    id = search_nspace ( ns, nm, ns, 0, 0, type ) ;
1671
			id = search_nspace(ns, nm, ns, 0, 0, type);
1627
	    if ( !IS_NULL_id ( id ) ) break ;
1672
			if (!IS_NULL_id(id)) {
-
 
1673
				break;
-
 
1674
			}
1628
	    if ( EQ_nspace ( ns, pns ) ) break ;
1675
			if (EQ_nspace(ns, pns)) {
-
 
1676
				break;
-
 
1677
			}
1629
	}
1678
		}
1630
	lns = TAIL_list ( lns ) ;
1679
		lns = TAIL_list(lns);
1631
    }
1680
	}
1632
    if ( !IS_NULL_list ( join_nspaces ) ) clear_join_nspaces () ;
1681
	if (!IS_NULL_list(join_nspaces)) {
-
 
1682
		clear_join_nspaces();
-
 
1683
	}
1633
    return ( id ) ;
1684
	return (id);
1634
}
1685
}
1635
 
1686
 
1636
 
1687
 
1637
/*
1688
/*
1638
    UNQUALIFIED NAME LOOK-UP
1689
    UNQUALIFIED NAME LOOK-UP
1639
 
1690
 
1640
    This routine (aka who the feck is fred?) looks up the name nm in the
1691
    This routine (aka who the feck is fred?) looks up the name nm in the
1641
    current scope, returning the corresponding identifier.  Note that
1692
    current scope, returning the corresponding identifier.  Note that
1642
    there is always a meaning for nm even if it is the underlying dummy
1693
    there is always a meaning for nm even if it is the underlying dummy
1643
    identifier.
1694
    identifier.
1644
*/
1695
*/
1645
 
1696
 
1646
IDENTIFIER find_id
1697
IDENTIFIER
1647
    PROTO_N ( ( nm ) )
-
 
1648
    PROTO_T ( HASHID nm )
1698
find_id(HASHID nm)
1649
{
1699
{
1650
    IDENTIFIER id ;
1700
	IDENTIFIER id;
1651
    if ( cache_lookup ) {
1701
	if (cache_lookup) {
1652
	id = DEREF_id ( hashid_cache ( nm ) ) ;
1702
		id = DEREF_id(hashid_cache(nm));
1653
	if ( IS_NULL_id ( id ) ) {
1703
		if (IS_NULL_id(id)) {
1654
	    id = find_extern_id ( nm, NULL_nspace, 0 ) ;
1704
			id = find_extern_id(nm, NULL_nspace, 0);
1655
	    if ( IS_NULL_id ( id ) ) {
1705
			if (IS_NULL_id(id)) {
1656
		/* Use underlying meaning if not found */
1706
				/* Use underlying meaning if not found */
1657
		id = DEREF_id ( hashid_id ( nm ) ) ;
1707
				id = DEREF_id(hashid_id(nm));
1658
	    }
1708
			}
1659
	    COPY_id ( hashid_cache ( nm ), id ) ;
1709
			COPY_id(hashid_cache(nm), id);
1660
	}
1710
		}
1661
    } else {
1711
	} else {
1662
	id = find_extern_id ( nm, NULL_nspace, 0 ) ;
1712
		id = find_extern_id(nm, NULL_nspace, 0);
1663
	if ( IS_NULL_id ( id ) ) {
1713
		if (IS_NULL_id(id)) {
1664
	    /* Use underlying meaning if not found */
1714
			/* Use underlying meaning if not found */
1665
	    id = DEREF_id ( hashid_id ( nm ) ) ;
1715
			id = DEREF_id(hashid_id(nm));
-
 
1716
		}
1666
	}
1717
	}
1667
    }
-
 
1668
    return ( id ) ;
1718
	return (id);
1669
}
1719
}
1670
 
1720
 
1671
 
1721
 
1672
/*
1722
/*
1673
    QUALIFIED NAME LOOK-UP
1723
    QUALIFIED NAME LOOK-UP
1674
 
1724
 
1675
    This routine (aka who the feck is fred::bloggs?) looks up the name nm
1725
    This routine (aka who the feck is fred::bloggs?) looks up the name nm
1676
    in the namespace ns.  Only type names are considered when type is
1726
    in the namespace ns.  Only type names are considered when type is
1677
    nonzero.  When ns is the null namespace this reduces to an unqualified
1727
    nonzero.  When ns is the null namespace this reduces to an unqualified
1678
    name look-up.
1728
    name look-up.
1679
*/
1729
*/
1680
 
1730
 
1681
IDENTIFIER find_qual_id
1731
IDENTIFIER
1682
    PROTO_N ( ( ns, nm, create, type ) )
-
 
1683
    PROTO_T ( NAMESPACE ns X HASHID nm X int create X int type )
1732
find_qual_id(NAMESPACE ns, HASHID nm, int create, int type)
1684
{
1733
{
1685
    IDENTIFIER id ;
1734
	IDENTIFIER id;
1686
    if ( IS_NULL_nspace ( ns ) ) {
1735
	if (IS_NULL_nspace(ns)) {
1687
	/* Unqualified name look-up */
1736
		/* Unqualified name look-up */
1688
	if ( type == 0 ) {
1737
		if (type == 0) {
1689
	    id = find_id ( nm ) ;
1738
			id = find_id(nm);
-
 
1739
		} else {
-
 
1740
			id = find_type_id(nm, type);
-
 
1741
		}
1690
	} else {
1742
	} else {
-
 
1743
		/* Qualified name look-up */
1691
	    id = find_type_id ( nm, type ) ;
1744
		id = search_nspace(ns, nm, ns, 1, create, type);
1692
	}
1745
	}
1693
    } else {
-
 
1694
	/* Qualified name look-up */
-
 
1695
	id = search_nspace ( ns, nm, ns, 1, create, type ) ;
-
 
1696
    }
-
 
1697
    return ( id ) ;
1746
	return (id);
1698
}
1747
}
1699
 
1748
 
1700
 
1749
 
1701
/*
1750
/*
1702
    SIMPLE TYPE NAME LOOK-UP
1751
    SIMPLE TYPE NAME LOOK-UP
1703
 
1752
 
1704
    This routine looks up the name nm as a type in the current scope,
1753
    This routine looks up the name nm as a type in the current scope,
1705
    returning the corresponding identifier.  If there is no type named
1754
    returning the corresponding identifier.  If there is no type named
1706
    nm then the null identifier is returned.
1755
    nm then the null identifier is returned.
1707
*/
1756
*/
1708
 
1757
 
1709
IDENTIFIER find_type_id
1758
IDENTIFIER
1710
    PROTO_N ( ( nm, type ) )
-
 
1711
    PROTO_T ( HASHID nm X int type )
1759
find_type_id(HASHID nm, int type)
1712
{
1760
{
1713
    IDENTIFIER id ;
1761
	IDENTIFIER id;
1714
    if ( cache_lookup ) {
1762
	if (cache_lookup) {
1715
	/* Check whether cached value is a type */
1763
		/* Check whether cached value is a type */
1716
	id = DEREF_id ( hashid_cache ( nm ) ) ;
1764
		id = DEREF_id(hashid_cache(nm));
1717
	id = select_type_id ( id, type ) ;
1765
		id = select_type_id(id, type);
1718
	if ( !IS_NULL_id ( id ) ) return ( id ) ;
1766
		if (!IS_NULL_id(id)) {
-
 
1767
			return (id);
1719
    }
1768
		}
-
 
1769
	}
1720
    id = find_extern_id ( nm, NULL_nspace, type ) ;
1770
	id = find_extern_id(nm, NULL_nspace, type);
1721
    return ( id ) ;
1771
	return (id);
1722
}
1772
}
1723
 
1773
 
1724
 
1774
 
1725
/*
1775
/*
1726
    OPERATOR FUNCTION NAME LOOK-UP
1776
    OPERATOR FUNCTION NAME LOOK-UP
1727
 
1777
 
1728
    This routine is identical to find_id except that it ignores all class
1778
    This routine is identical to find_id except that it ignores all class
1729
    namespaces.  This is used when looking up operator functions in C++
1779
    namespaces.  This is used when looking up operator functions in C++
1730
    and is the default look-up rule in C.
1780
    and is the default look-up rule in C.
1731
*/
1781
*/
1732
 
1782
 
1733
IDENTIFIER find_op_id
1783
IDENTIFIER
1734
    PROTO_N ( ( nm ) )
-
 
1735
    PROTO_T ( HASHID nm )
1784
find_op_id(HASHID nm)
1736
{
1785
{
1737
    IDENTIFIER id ;
1786
	IDENTIFIER id;
1738
    LIST ( NAMESPACE ) lns ;
1787
	LIST(NAMESPACE) lns;
1739
    int cache = cache_lookup ;
1788
	int cache = cache_lookup;
1740
    if ( cache ) {
1789
	if (cache) {
1741
	/* Check cached look-up */
1790
		/* Check cached look-up */
1742
	id = DEREF_id ( hashid_cache ( nm ) ) ;
1791
		id = DEREF_id(hashid_cache(nm));
1743
	if ( !IS_NULL_id ( id ) ) {
1792
		if (!IS_NULL_id(id)) {
1744
	    NAMESPACE ns = DEREF_nspace ( id_parent ( id ) ) ;
1793
			NAMESPACE ns = DEREF_nspace(id_parent(id));
1745
	    if ( IS_NULL_nspace ( ns ) || !IS_nspace_ctype ( ns ) ) {
1794
			if (IS_NULL_nspace(ns) || !IS_nspace_ctype(ns)) {
1746
		return ( id ) ;
1795
				return (id);
1747
	    }
1796
			}
1748
	    cache = 0 ;
1797
			cache = 0;
1749
	}
1798
		}
1750
    }
1799
	}
1751
 
1800
 
1752
    /* Scan through namespace stack */
1801
	/* Scan through namespace stack */
1753
    lns = LIST_stack ( namespace_stack ) ;
1802
	lns = LIST_stack(namespace_stack);
1754
    while ( !IS_NULL_list ( lns ) ) {
1803
	while (!IS_NULL_list(lns)) {
1755
	NAMESPACE ns = DEREF_nspace ( HEAD_list ( lns ) ) ;
1804
		NAMESPACE ns = DEREF_nspace(HEAD_list(lns));
1756
	if ( !IS_NULL_nspace ( ns ) && !IS_nspace_ctype ( ns ) ) {
1805
		if (!IS_NULL_nspace(ns) && !IS_nspace_ctype(ns)) {
1757
	    id = search_nspace ( ns, nm, ns, 0, 0, 0 ) ;
1806
			id = search_nspace(ns, nm, ns, 0, 0, 0);
1758
	    if ( !IS_NULL_id ( id ) ) {
1807
			if (!IS_NULL_id(id)) {
1759
		if ( !IS_NULL_list ( join_nspaces ) ) clear_join_nspaces () ;
1808
				if (!IS_NULL_list(join_nspaces)) {
-
 
1809
					clear_join_nspaces();
-
 
1810
				}
-
 
1811
				if (cache) {
1760
		if ( cache ) COPY_id ( hashid_cache ( nm ), id ) ;
1812
					COPY_id(hashid_cache(nm), id);
-
 
1813
				}
1761
		return ( id ) ;
1814
				return (id);
1762
	    }
1815
			}
1763
	} else {
1816
		} else {
1764
	    cache = 0 ;
1817
			cache = 0;
-
 
1818
		}
-
 
1819
		lns = TAIL_list(lns);
-
 
1820
	}
-
 
1821
	if (!IS_NULL_list(join_nspaces)) {
-
 
1822
		clear_join_nspaces();
-
 
1823
	}
-
 
1824
	id = DEREF_id(hashid_id(nm));
-
 
1825
	if (cache) {
-
 
1826
		COPY_id(hashid_cache(nm), id);
1765
	}
1827
	}
1766
	lns = TAIL_list ( lns ) ;
-
 
1767
    }
-
 
1768
    if ( !IS_NULL_list ( join_nspaces ) ) clear_join_nspaces () ;
-
 
1769
    id = DEREF_id ( hashid_id ( nm ) ) ;
-
 
1770
    if ( cache ) COPY_id ( hashid_cache ( nm ), id ) ;
-
 
1771
    return ( id ) ;
1828
	return (id);
1772
}
1829
}
1773
 
1830
 
1774
 
1831
 
1775
/*
1832
/*
1776
    FINAL NAME LOOK-UP CHECK
1833
    FINAL NAME LOOK-UP CHECK
Line 1779... Line 1836...
1779
    id will already be a valid identifier for the namespace ns - the couple
1836
    id will already be a valid identifier for the namespace ns - the couple
1780
    of exceptions - undeclared members and non-simple identifier names
1837
    of exceptions - undeclared members and non-simple identifier names
1781
    are handled by this routine.
1838
    are handled by this routine.
1782
*/
1839
*/
1783
 
1840
 
1784
IDENTIFIER check_id
1841
IDENTIFIER
1785
    PROTO_N ( ( ns, id, templ ) )
-
 
1786
    PROTO_T ( NAMESPACE ns X IDENTIFIER id X int templ )
1842
check_id(NAMESPACE ns, IDENTIFIER id, int templ)
1787
{
1843
{
1788
    if ( !IS_NULL_id ( id ) ) {
1844
	if (!IS_NULL_id(id)) {
1789
	unsigned tag = TAG_id ( id ) ;
1845
		unsigned tag = TAG_id(id);
1790
	if ( tag == id_dummy_tag ) {
1846
		if (tag == id_dummy_tag) {
1791
	    /* Re-scan dummy identifiers */
1847
			/* Re-scan dummy identifiers */
1792
	    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
1848
			HASHID nm = DEREF_hashid(id_name(id));
1793
	    id = find_qual_id ( ns, nm, 1, 0 ) ;
1849
			id = find_qual_id(ns, nm, 1, 0);
1794
	    tag = TAG_id ( id ) ;
1850
			tag = TAG_id(id);
-
 
1851
		}
-
 
1852
		if (tag == id_token_tag && crt_id_qualifier != qual_none) {
-
 
1853
			/* Can't qualify token names */
-
 
1854
			report(crt_loc, ERR_token_qual(id));
-
 
1855
		}
-
 
1856
		UNUSED(templ);
1795
	}
1857
	}
1796
	if ( tag == id_token_tag && crt_id_qualifier != qual_none ) {
-
 
1797
	    /* Can't qualify token names */
-
 
1798
	    report ( crt_loc, ERR_token_qual ( id ) ) ;
-
 
1799
	}
-
 
1800
	UNUSED ( templ ) ;
-
 
1801
    }
-
 
1802
    return ( id ) ;
1858
	return (id);
1803
}
1859
}
1804
 
1860
 
1805
 
1861
 
1806
/*
1862
/*
1807
    REMOVE AN ELEMENT OF A SET OF OVERLOADED FUNCTIONS
1863
    REMOVE AN ELEMENT OF A SET OF OVERLOADED FUNCTIONS
1808
 
1864
 
1809
    This routine removes the function id from the set of overloaded
1865
    This routine removes the function id from the set of overloaded
1810
    functions fid.
1866
    functions fid.
1811
*/
1867
*/
1812
 
1868
 
1813
static IDENTIFIER remove_func
1869
static IDENTIFIER
1814
    PROTO_N ( ( fid, id ) )
-
 
1815
    PROTO_T ( IDENTIFIER fid X IDENTIFIER id )
1870
remove_func(IDENTIFIER fid, IDENTIFIER id)
1816
{
1871
{
1817
    if ( !IS_NULL_id ( fid ) ) {
1872
	if (!IS_NULL_id(fid)) {
1818
	IDENTIFIER pid = DEREF_id ( id_function_etc_over ( fid ) ) ;
1873
		IDENTIFIER pid = DEREF_id(id_function_etc_over(fid));
1819
	if ( EQ_id ( fid, id ) ) {
1874
		if (EQ_id(fid, id)) {
1820
	    fid = pid ;
1875
			fid = pid;
1821
	    COPY_id ( id_function_etc_over ( id ), NULL_id ) ;
1876
			COPY_id(id_function_etc_over(id), NULL_id);
1822
	} else {
1877
		} else {
1823
	    pid = remove_func ( pid, id ) ;
1878
			pid = remove_func(pid, id);
1824
	    COPY_id ( id_function_etc_over ( fid ), pid ) ;
1879
			COPY_id(id_function_etc_over(fid), pid);
-
 
1880
		}
1825
	}
1881
	}
1826
    }
-
 
1827
    return ( fid ) ;
1882
	return (fid);
1828
}
1883
}
1829
 
1884
 
1830
 
1885
 
1831
/*
1886
/*
1832
    REMOVE AN IDENTIFIER FROM A NAMESPACE
1887
    REMOVE AN IDENTIFIER FROM A NAMESPACE
1833
 
1888
 
1834
    This routine removes the identifier id its parent namespace.
1889
    This routine removes the identifier id its parent namespace.
1835
*/
1890
*/
1836
 
1891
 
1837
void remove_id
1892
void
1838
    PROTO_N ( ( id ) )
-
 
1839
    PROTO_T ( IDENTIFIER id )
1893
remove_id(IDENTIFIER id)
1840
{
1894
{
1841
    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
1895
	HASHID nm = DEREF_hashid(id_name(id));
1842
    NAMESPACE ns = DEREF_nspace ( id_parent ( id ) ) ;
1896
	NAMESPACE ns = DEREF_nspace(id_parent(id));
1843
    MEMBER mem = search_member ( ns, nm, 0 ) ;
1897
	MEMBER mem = search_member(ns, nm, 0);
1844
    if ( !IS_NULL_member ( mem ) ) {
1898
	if (!IS_NULL_member(mem)) {
1845
	IDENTIFIER mid = DEREF_id ( member_id ( mem ) ) ;
1899
		IDENTIFIER mid = DEREF_id(member_id(mem));
1846
	IDENTIFIER tid = DEREF_id ( member_alt ( mem ) ) ;
1900
		IDENTIFIER tid = DEREF_id(member_alt(mem));
1847
	if ( IS_id_function_etc ( id ) ) {
1901
		if (IS_id_function_etc(id)) {
1848
	    mid = remove_func ( mid, id ) ;
1902
			mid = remove_func(mid, id);
1849
	} else {
1903
		} else {
1850
	    if ( EQ_id ( id, mid ) ) mid = NULL_id ;
1904
			if (EQ_id(id, mid)) {
-
 
1905
				mid = NULL_id;
-
 
1906
			}
1851
	    if ( EQ_id ( id, tid ) ) tid = NULL_id ;
1907
			if (EQ_id(id, tid)) {
-
 
1908
				tid = NULL_id;
-
 
1909
			}
-
 
1910
		}
-
 
1911
		if (IS_NULL_id(mid)) {
-
 
1912
			mid = tid;
-
 
1913
		}
-
 
1914
		COPY_id(member_id(mem), mid);
-
 
1915
		COPY_id(member_alt(mem), tid);
-
 
1916
		COPY_id(hashid_cache(nm), NULL_id);
-
 
1917
		IGNORE check_identifier(id, ns, NULL_exp, ANON_NONE, 1);
1852
	}
1918
	}
1853
	if ( IS_NULL_id ( mid ) ) mid = tid ;
-
 
1854
	COPY_id ( member_id ( mem ), mid ) ;
-
 
1855
	COPY_id ( member_alt ( mem ), tid ) ;
-
 
1856
	COPY_id ( hashid_cache ( nm ), NULL_id ) ;
-
 
1857
	IGNORE check_identifier ( id, ns, NULL_exp, ANON_NONE, 1 ) ;
-
 
1858
    }
-
 
1859
    return ;
1919
	return;
1860
}
1920
}
1861
 
1921
 
1862
 
1922
 
1863
/*
1923
/*
1864
    DOES AN IDENTIFIER HAVE AN EXTERNAL LINKAGE NAME?
1924
    DOES AN IDENTIFIER HAVE AN EXTERNAL LINKAGE NAME?
Line 1866... Line 1926...
1866
    This routine checks whether the identifier id has an external linkage
1926
    This routine checks whether the identifier id has an external linkage
1867
    name.  It cannot be a member of a block, an unnamed class or an
1927
    name.  It cannot be a member of a block, an unnamed class or an
1868
    anonymous namespace.
1928
    anonymous namespace.
1869
*/
1929
*/
1870
 
1930
 
1871
int has_linkage
1931
int
1872
    PROTO_N ( ( id ) )
-
 
1873
    PROTO_T ( IDENTIFIER id )
1932
has_linkage(IDENTIFIER id)
1874
{
1933
{
1875
    while ( !IS_NULL_id ( id ) ) {
1934
	while (!IS_NULL_id(id)) {
1876
	HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
1935
		HASHID nm = DEREF_hashid(id_name(id));
1877
	NAMESPACE ns = DEREF_nspace ( id_parent ( id ) ) ;
1936
		NAMESPACE ns = DEREF_nspace(id_parent(id));
1878
	DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
1937
		DECL_SPEC ds = DEREF_dspec(id_storage(id));
1879
	if ( IS_hashid_anon ( nm ) ) return ( 0 ) ;
1938
		if (IS_hashid_anon(nm)) {
-
 
1939
			return (0);
-
 
1940
		}
1880
	if ( !( ds & dspec_extern ) ) return ( 0 ) ;
1941
		if (!(ds & dspec_extern)) {
-
 
1942
			return (0);
-
 
1943
		}
1881
	if ( ( ds & dspec_c ) && !anon_c_linkage ) return ( 1 ) ;
1944
		if ((ds & dspec_c) && !anon_c_linkage) {
-
 
1945
			return (1);
-
 
1946
		}
1882
	if ( IS_NULL_nspace ( ns ) ) return ( 0 ) ;
1947
		if (IS_NULL_nspace(ns)) {
-
 
1948
			return (0);
-
 
1949
		}
1883
	switch ( TAG_nspace ( ns ) ) {
1950
		switch (TAG_nspace(ns)) {
1884
	    case nspace_named_tag : break ;
1951
		case nspace_named_tag:
-
 
1952
			break;
1885
	    case nspace_ctype_tag : break ;
1953
		case nspace_ctype_tag:
-
 
1954
			break;
1886
	    case nspace_global_tag : return ( 1 ) ;
1955
		case nspace_global_tag:
-
 
1956
			return (1);
-
 
1957
		default:
1887
	    default : return ( 0 ) ;
1958
			return (0);
-
 
1959
		}
-
 
1960
		id = DEREF_id(nspace_name(ns));
1888
	}
1961
	}
1889
	id = DEREF_id ( nspace_name ( ns ) ) ;
-
 
1890
    }
-
 
1891
    return ( 0 ) ;
1962
	return (0);
1892
}
1963
}
1893
 
1964
 
1894
 
1965
 
1895
/*
1966
/*
1896
    CHECK HIDING OF LOCAL VARIABLES
1967
    CHECK HIDING OF LOCAL VARIABLES
Line 1899... Line 1970...
1899
    hidden by id.  Note that only the first instance is reported, and that
1970
    hidden by id.  Note that only the first instance is reported, and that
1900
    the hiding of one declaration by a subsequent incompatible redeclaration
1971
    the hiding of one declaration by a subsequent incompatible redeclaration
1901
    is excluded.
1972
    is excluded.
1902
*/
1973
*/
1903
 
1974
 
1904
void check_hiding
1975
void
1905
    PROTO_N ( ( id ) )
-
 
1906
    PROTO_T ( IDENTIFIER id )
1976
check_hiding(IDENTIFIER id)
1907
{
1977
{
1908
    if ( crt_id_qualifier == qual_none ) {
1978
    if (crt_id_qualifier == qual_none) {
1909
	/* Check through all look-up namespaces */
1979
	/* Check through all look-up namespaces */
1910
	HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
1980
	HASHID nm = DEREF_hashid(id_name(id));
1911
	LIST ( NAMESPACE ) lns = LIST_stack ( namespace_stack ) ;
1981
	LIST(NAMESPACE) lns = LIST_stack(namespace_stack);
1912
	while ( !IS_NULL_list ( lns ) ) {
1982
	while (!IS_NULL_list(lns)) {
1913
	    NAMESPACE ns = DEREF_nspace ( HEAD_list ( lns ) ) ;
1983
	    NAMESPACE ns = DEREF_nspace(HEAD_list(lns));
1914
	    if ( !IS_NULL_nspace ( ns ) ) {
1984
	    if (!IS_NULL_nspace(ns)) {
1915
		IDENTIFIER mid = search_nspace ( ns, nm, ns, 0, 0, 0 ) ;
1985
		IDENTIFIER mid = search_nspace(ns, nm, ns, 0, 0, 0);
1916
		if ( !IS_NULL_id ( mid ) && !EQ_id ( mid, id ) ) {
1986
		if (!IS_NULL_id(mid) && !EQ_id(mid, id)) {
1917
		    ERROR err = NULL_err ;
1987
		    ERROR err = NULL_err;
1918
		    switch ( TAG_id ( mid ) ) {
1988
		    switch (TAG_id(mid)) {
1919
			case id_variable_tag :
1989
			case id_variable_tag:
1920
			case id_parameter_tag :
1990
			case id_parameter_tag:
1921
			case id_function_tag : {
1991
			case id_function_tag: {
1922
			    /* Report hiding of these objects */
1992
			    /* Report hiding of these objects */
1923
			    PTR ( LOCATION ) mloc = id_loc ( mid ) ;
1993
			    PTR(LOCATION) mloc = id_loc(mid);
1924
			    err = ERR_basic_scope_hide ( nm, mloc ) ;
1994
			    err = ERR_basic_scope_hide(nm, mloc);
1925
			    break ;
1995
			    break;
1926
			}
1996
			}
1927
			case id_stat_member_tag :
1997
			case id_stat_member_tag:
1928
			case id_mem_func_tag :
1998
			case id_mem_func_tag:
1929
			case id_stat_mem_func_tag :
1999
			case id_stat_mem_func_tag:
1930
			case id_member_tag : {
2000
			case id_member_tag:
1931
			    /* Report hiding of members */
2001
			    /* Report hiding of members */
1932
			    err = ERR_basic_scope_hide_mem ( nm, mid ) ;
2002
			    err = ERR_basic_scope_hide_mem(nm, mid);
1933
			    break ;
2003
			    break;
1934
			}
-
 
1935
		    }
2004
		    }
1936
		    if ( !IS_NULL_err ( err ) ) {
2005
		    if (!IS_NULL_err(err)) {
1937
			/* Print error */
2006
			/* Print error */
1938
			LOCATION loc ;
2007
			LOCATION loc;
1939
			DEREF_loc ( id_loc ( id ), loc ) ;
2008
			DEREF_loc(id_loc(id), loc);
1940
			report ( crt_loc, err ) ;
2009
			report(crt_loc, err);
1941
		    }
2010
		    }
1942
		    break ;
2011
		    break;
1943
		}
2012
		}
1944
	    }
2013
	    }
1945
	    lns = TAIL_list ( lns ) ;
2014
	    lns = TAIL_list(lns);
-
 
2015
	}
-
 
2016
	if (!IS_NULL_list(join_nspaces)) {
-
 
2017
		clear_join_nspaces();
1946
	}
2018
	}
1947
	if ( !IS_NULL_list ( join_nspaces ) ) clear_join_nspaces () ;
-
 
1948
    }
2019
    }
1949
    return ;
2020
    return;
1950
}
2021
}