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
32
    		 Crown Copyright (c) 1997
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
Line 54... Line 84...
54
 
84
 
55
    This flag is set to true to indicate that name merging is taking
85
    This flag is set to true to indicate that name merging is taking
56
    place.
86
    place.
57
*/
87
*/
58
 
88
 
59
int force_merge = 0 ;
89
int force_merge = 0;
60
 
90
 
61
 
91
 
62
/*
92
/*
63
    ARE TWO CLASSES LAYOUT COMPATIBLE?
93
    ARE TWO CLASSES LAYOUT COMPATIBLE?
64
 
94
 
65
    This routine checks whether the classes ct and cs are layout compatible,
95
    This routine checks whether the classes ct and cs are layout compatible,
66
    i.e. they have the same member types and accesses.
96
    i.e. they have the same member types and accesses.
67
*/
97
*/
68
 
98
 
69
int compatible_class
99
int
70
    PROTO_N ( ( ct, cs ) )
-
 
71
    PROTO_T ( CLASS_TYPE ct X CLASS_TYPE cs )
100
compatible_class(CLASS_TYPE ct, CLASS_TYPE cs)
72
{
101
{
73
    GRAPH gt, gs ;
102
	GRAPH gt, gs;
74
    MEMBER mt, ms ;
103
	MEMBER mt, ms;
75
    BASE_TYPE kt, ks ;
104
	BASE_TYPE kt, ks;
76
    NAMESPACE nt, ns ;
105
	NAMESPACE nt, ns;
77
    LIST ( GRAPH ) bt, bs ;
106
	LIST(GRAPH) bt, bs;
78
 
107
 
79
    /* Check for obvious equality */
108
	/* Check for obvious equality */
80
    if ( eq_ctype ( ct, cs ) ) return ( 1 ) ;
109
	if (eq_ctype(ct, cs)) {
-
 
110
		return (1);
-
 
111
	}
81
 
112
 
82
    /* Check class keys */
113
	/* Check class keys */
83
    kt = find_class_key ( ct ) ;
114
	kt = find_class_key(ct);
84
    ks = find_class_key ( cs ) ;
115
	ks = find_class_key(cs);
85
    if ( !equal_key ( kt, ks ) ) return ( 0 ) ;
116
	if (!equal_key(kt, ks)) {
-
 
117
		return (0);
-
 
118
	}
86
 
119
 
87
    /* Check base classes */
120
	/* Check base classes */
88
    gt = DEREF_graph ( ctype_base ( ct ) ) ;
121
	gt = DEREF_graph(ctype_base(ct));
89
    gs = DEREF_graph ( ctype_base ( cs ) ) ;
122
	gs = DEREF_graph(ctype_base(cs));
90
    bt = DEREF_list ( graph_tails ( gt ) ) ;
123
	bt = DEREF_list(graph_tails(gt));
91
    bs = DEREF_list ( graph_tails ( gs ) ) ;
124
	bs = DEREF_list(graph_tails(gs));
92
    while ( !IS_NULL_list ( bt ) && !IS_NULL_list ( bs ) ) {
125
	while (!IS_NULL_list(bt) && !IS_NULL_list(bs)) {
93
	GRAPH ht = DEREF_graph ( HEAD_list ( bt ) ) ;
126
		GRAPH ht = DEREF_graph(HEAD_list(bt));
94
	GRAPH hs = DEREF_graph ( HEAD_list ( bs ) ) ;
127
		GRAPH hs = DEREF_graph(HEAD_list(bs));
95
	CLASS_TYPE pt = DEREF_ctype ( graph_head ( ht ) ) ;
128
		CLASS_TYPE pt = DEREF_ctype(graph_head(ht));
96
	CLASS_TYPE ps = DEREF_ctype ( graph_head ( hs ) ) ;
129
		CLASS_TYPE ps = DEREF_ctype(graph_head(hs));
97
	DECL_SPEC at = DEREF_dspec ( graph_access ( ht ) ) ;
130
		DECL_SPEC at = DEREF_dspec(graph_access(ht));
98
	DECL_SPEC as = DEREF_dspec ( graph_access ( hs ) ) ;
131
		DECL_SPEC as = DEREF_dspec(graph_access(hs));
99
	at &= ( dspec_access | dspec_virtual ) ;
132
		at &= (dspec_access | dspec_virtual);
100
	as &= ( dspec_access | dspec_virtual ) ;
133
		as &= (dspec_access | dspec_virtual);
101
	if ( at != as ) return ( 0 ) ;
134
		if (at != as) {
-
 
135
			return (0);
-
 
136
		}
102
	if ( !compatible_class ( pt, ps ) ) return ( 0 ) ;
137
		if (!compatible_class(pt, ps)) {
-
 
138
			return (0);
-
 
139
		}
103
	bs = TAIL_list ( bs ) ;
140
		bs = TAIL_list(bs);
104
	bt = TAIL_list ( bt ) ;
141
		bt = TAIL_list(bt);
105
    }
142
	}
106
    if ( !EQ_list ( bt, bs ) ) return ( 0 ) ;
143
	if (!EQ_list(bt, bs)) {
-
 
144
		return (0);
-
 
145
	}
107
 
146
 
108
    /* Check class members */
147
	/* Check class members */
109
    nt = DEREF_nspace ( ctype_member ( ct ) ) ;
148
	nt = DEREF_nspace(ctype_member(ct));
110
    mt = DEREF_member ( nspace_ctype_first ( nt ) ) ;
149
	mt = DEREF_member(nspace_ctype_first(nt));
111
    mt = next_data_member ( mt, 1 ) ;
150
	mt = next_data_member(mt, 1);
112
    ns = DEREF_nspace ( ctype_member ( cs ) ) ;
151
	ns = DEREF_nspace(ctype_member(cs));
113
    ms = DEREF_member ( nspace_ctype_first ( ns ) ) ;
152
	ms = DEREF_member(nspace_ctype_first(ns));
114
    ms = next_data_member ( ms, 1 ) ;
153
	ms = next_data_member(ms, 1);
115
    while ( !IS_NULL_member ( mt ) && !IS_NULL_member ( ms ) ) {
154
	while (!IS_NULL_member(mt) && !IS_NULL_member(ms)) {
116
	IDENTIFIER it = DEREF_id ( member_id ( mt ) ) ;
155
		IDENTIFIER it = DEREF_id(member_id(mt));
117
	IDENTIFIER is = DEREF_id ( member_id ( ms ) ) ;
156
		IDENTIFIER is = DEREF_id(member_id(ms));
118
	TYPE t = DEREF_type ( id_member_type ( it ) ) ;
157
		TYPE t = DEREF_type(id_member_type(it));
119
	TYPE s = DEREF_type ( id_member_type ( is ) ) ;
158
		TYPE s = DEREF_type(id_member_type(is));
120
	DECL_SPEC at = DEREF_dspec ( id_storage ( it ) ) ;
159
		DECL_SPEC at = DEREF_dspec(id_storage(it));
121
	DECL_SPEC as = DEREF_dspec ( id_storage ( is ) ) ;
160
		DECL_SPEC as = DEREF_dspec(id_storage(is));
122
	at &= dspec_access ;
161
		at &= dspec_access;
123
	as &= dspec_access ;
162
		as &= dspec_access;
124
	if ( at != as ) return ( 0 ) ;
163
		if (at != as) {
-
 
164
			return (0);
-
 
165
		}
125
	if ( !eq_type ( t, s ) ) return ( 0 ) ;
166
		if (!eq_type(t, s)) {
-
 
167
			return (0);
-
 
168
		}
126
	ms = DEREF_member ( member_next ( ms ) ) ;
169
		ms = DEREF_member(member_next(ms));
127
	ms = next_data_member ( ms, 1 ) ;
170
		ms = next_data_member(ms, 1);
128
	mt = DEREF_member ( member_next ( mt ) ) ;
171
		mt = DEREF_member(member_next(mt));
129
	mt = next_data_member ( mt, 1 ) ;
172
		mt = next_data_member(mt, 1);
130
    }
173
	}
131
    if ( !EQ_member ( mt, ms ) ) return ( 0 ) ;
174
	if (!EQ_member(mt, ms)) {
-
 
175
		return (0);
-
 
176
	}
132
    return ( 1 ) ;
177
	return (1);
133
}
178
}
134
 
179
 
135
 
180
 
136
/*
181
/*
137
    ARE TWO TYPES TO BE MERGED?
182
    ARE TWO TYPES TO BE MERGED?
138
 
183
 
139
    This routine checks whether the identifiers tid and sid are to be made
184
    This routine checks whether the identifiers tid and sid are to be made
140
    equal by merge_id.  This essentially means that they should be the
185
    equal by merge_id.  This essentially means that they should be the
141
    same.
186
    same.
142
*/
187
*/
143
 
188
 
144
int merge_type
189
int
145
    PROTO_N ( ( tid, sid ) )
-
 
146
    PROTO_T ( IDENTIFIER tid X IDENTIFIER sid )
190
merge_type(IDENTIFIER tid, IDENTIFIER sid)
147
{
191
{
148
    while ( !EQ_id ( tid, sid ) ) {
192
	while (!EQ_id(tid, sid)) {
149
	unsigned tt, ts ;
193
		unsigned tt, ts;
150
	HASHID tnm, snm ;
194
		HASHID tnm, snm;
151
	NAMESPACE nt, ns ;
195
		NAMESPACE nt, ns;
152
 
196
 
153
	/* Check identifiers */
197
		/* Check identifiers */
154
	if ( IS_NULL_id ( tid ) ) return ( 0 ) ;
198
		if (IS_NULL_id(tid)) {
-
 
199
			return (0);
-
 
200
		}
155
	if ( IS_NULL_id ( sid ) ) return ( 0 ) ;
201
		if (IS_NULL_id(sid)) {
-
 
202
			return (0);
-
 
203
		}
156
	tt = TAG_id ( tid ) ;
204
		tt = TAG_id(tid);
157
	ts = TAG_id ( sid ) ;
205
		ts = TAG_id(sid);
158
	if ( tt != ts ) return ( 0 ) ;
206
		if (tt != ts) {
-
 
207
			return (0);
-
 
208
		}
159
 
209
 
160
	/* Check identifier names */
210
		/* Check identifier names */
161
	tnm = DEREF_hashid ( id_name ( tid ) ) ;
211
		tnm = DEREF_hashid(id_name(tid));
162
	snm = DEREF_hashid ( id_name ( sid ) ) ;
212
		snm = DEREF_hashid(id_name(sid));
163
	if ( !EQ_hashid ( tnm, snm ) ) return ( 0 ) ;
213
		if (!EQ_hashid(tnm, snm)) {
-
 
214
			return (0);
-
 
215
		}
164
 
216
 
165
	/* Check identifier namespaces */
217
		/* Check identifier namespaces */
166
	nt = DEREF_nspace ( id_parent ( tid ) ) ;
218
		nt = DEREF_nspace(id_parent(tid));
167
	ns = DEREF_nspace ( id_parent ( sid ) ) ;
219
		ns = DEREF_nspace(id_parent(sid));
168
	if ( EQ_nspace ( nt, ns ) ) return ( 1 ) ;
220
		if (EQ_nspace(nt, ns)) {
-
 
221
			return (1);
-
 
222
		}
169
	if ( IS_NULL_nspace ( nt ) ) return ( 0 ) ;
223
		if (IS_NULL_nspace(nt)) {
-
 
224
			return (0);
-
 
225
		}
170
	if ( IS_NULL_nspace ( ns ) ) return ( 0 ) ;
226
		if (IS_NULL_nspace(ns)) {
-
 
227
			return (0);
-
 
228
		}
171
	tt = TAG_nspace ( nt ) ;
229
		tt = TAG_nspace(nt);
172
	ts = TAG_nspace ( ns ) ;
230
		ts = TAG_nspace(ns);
173
	if ( tt != ts ) return ( 0 ) ;
231
		if (tt != ts) {
-
 
232
			return (0);
-
 
233
		}
174
	switch ( tt ) {
234
		switch (tt) {
175
	    case nspace_global_tag : {
235
		case nspace_global_tag:
176
		return ( 1 ) ;
236
			return (1);
177
	    }
-
 
178
	    case nspace_ctype_tag :
237
		case nspace_ctype_tag:
179
	    case nspace_named_tag :
238
		case nspace_named_tag:
180
	    case nspace_unnamed_tag : {
239
		case nspace_unnamed_tag:
181
		break ;
240
			break;
182
	    }
-
 
183
	    default : {
241
		default:
184
		return ( 0 ) ;
242
			return (0);
185
	    }
-
 
186
	}
243
		}
187
	tid = DEREF_id ( nspace_name ( nt ) ) ;
244
		tid = DEREF_id(nspace_name(nt));
188
	sid = DEREF_id ( nspace_name ( ns ) ) ;
245
		sid = DEREF_id(nspace_name(ns));
189
    }
246
	}
190
    return ( 1 ) ;
247
	return (1);
191
}
248
}
192
 
249
 
193
 
250
 
194
/*
251
/*
195
    CHECK FOR CONSISTENT REDEFINITION
252
    CHECK FOR CONSISTENT REDEFINITION
196
 
253
 
197
    This routine checks whether the definitions of the objects pid and
254
    This routine checks whether the definitions of the objects pid and
198
    qid and consistent.
255
    qid and consistent.
199
*/
256
*/
200
 
257
 
201
static int consistent_redef
258
static int
202
    PROTO_N ( ( pid, qid ) )
-
 
203
    PROTO_T ( IDENTIFIER pid X IDENTIFIER qid )
259
consistent_redef(IDENTIFIER pid, IDENTIFIER qid)
204
{
260
{
205
    int ok = 1 ;
261
	int ok = 1;
206
    switch ( TAG_id ( pid ) ) {
262
	switch (TAG_id(pid)) {
207
	case id_nspace_name_tag : {
263
	case id_nspace_name_tag: {
208
	    /* Merge namespace definitions */
264
		/* Merge namespace definitions */
209
	    NAMESPACE pns = DEREF_nspace ( id_nspace_name_defn ( pid ) ) ;
265
		NAMESPACE pns = DEREF_nspace(id_nspace_name_defn(pid));
210
	    NAMESPACE qns = DEREF_nspace ( id_nspace_name_defn ( qid ) ) ;
266
		NAMESPACE qns = DEREF_nspace(id_nspace_name_defn(qid));
211
	    if ( IS_nspace_named ( pns ) ) {
267
		if (IS_nspace_named(pns)) {
212
		COPY_nspace ( id_nspace_name_defn ( pid ), qns ) ;
268
			COPY_nspace(id_nspace_name_defn(pid), qns);
213
		merge_namespaces ( qns, pns ) ;
269
			merge_namespaces(qns, pns);
214
	    } else {
270
		} else {
215
		merge_namespaces ( NULL_nspace, pns ) ;
271
			merge_namespaces(NULL_nspace, pns);
216
	    }
272
		}
217
	    break ;
273
		break;
218
	}
274
	}
219
	case id_class_name_tag : {
275
	case id_class_name_tag: {
220
	    BASE_TYPE bt, bs ;
276
		BASE_TYPE bt, bs;
221
	    CLASS_TYPE ct, cs ;
277
		CLASS_TYPE ct, cs;
222
	    NAMESPACE pns, qns ;
278
		NAMESPACE pns, qns;
223
	    TYPE t = DEREF_type ( id_class_name_defn ( pid ) ) ;
279
		TYPE t = DEREF_type(id_class_name_defn(pid));
224
	    TYPE s = DEREF_type ( id_class_name_defn ( qid ) ) ;
280
		TYPE s = DEREF_type(id_class_name_defn(qid));
225
	    while ( IS_type_templ ( t ) ) {
281
		while (IS_type_templ(t)) {
226
		t = DEREF_type ( type_templ_defn ( t ) ) ;
282
			t = DEREF_type(type_templ_defn(t));
227
	    }
283
		}
228
	    ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
284
		ct = DEREF_ctype(type_compound_defn(t));
229
	    bt = find_class_key ( ct ) ;
285
		bt = find_class_key(ct);
230
	    pns = DEREF_nspace ( ctype_member ( ct ) ) ;
286
		pns = DEREF_nspace(ctype_member(ct));
231
	    while ( IS_type_templ ( s ) ) {
287
		while (IS_type_templ(s)) {
232
		s = DEREF_type ( type_templ_defn ( s ) ) ;
288
			s = DEREF_type(type_templ_defn(s));
233
	    }
289
		}
234
	    cs = DEREF_ctype ( type_compound_defn ( s ) ) ;
290
		cs = DEREF_ctype(type_compound_defn(s));
235
	    bs = find_class_key ( cs ) ;
291
		bs = find_class_key(cs);
236
	    qns = DEREF_nspace ( ctype_member ( cs ) ) ;
292
		qns = DEREF_nspace(ctype_member(cs));
237
	    COPY_nspace ( ctype_member ( ct ), qns ) ;
293
		COPY_nspace(ctype_member(ct), qns);
238
	    if ( !equal_key ( bt, bs ) ) {
294
		if (!equal_key(bt, bs)) {
239
		/* Inconsistent key */
295
			/* Inconsistent key */
240
		PTR ( LOCATION ) loc = id_loc ( qid ) ;
296
			PTR(LOCATION) loc = id_loc(qid);
241
		ERROR err = ERR_dcl_type_elab_bad ( bt, bs, qid, loc ) ;
297
			ERROR err = ERR_dcl_type_elab_bad(bt, bs, qid, loc);
242
		report ( crt_loc, err ) ;
298
			report(crt_loc, err);
243
	    }
299
		}
244
	    merge_namespaces ( qns, pns ) ;
300
		merge_namespaces(qns, pns);
245
	    break ;
301
		break;
246
	}
302
	}
247
	case id_variable_tag :
303
	case id_variable_tag:
248
	case id_stat_member_tag : {
304
	case id_stat_member_tag:
249
	    ok = 0 ;
305
		ok = 0;
250
	    break ;
306
		break;
251
	}
307
	}
252
    }
-
 
253
    return ( ok ) ;
308
	return (ok);
254
}
309
}
255
 
310
 
256
 
311
 
257
/*
312
/*
258
    EXPAND AN IDENTIFIER
313
    EXPAND AN IDENTIFIER
259
 
314
 
260
    This routine expands the identifier id read from a spec input file.
315
    This routine expands the identifier id read from a spec input file.
261
    This is necessary because id may still contain pending identifiers.
316
    This is necessary because id may still contain pending identifiers.
262
*/
317
*/
263
 
318
 
264
static void expand_id
319
static void
265
    PROTO_N ( ( id ) )
-
 
266
    PROTO_T ( IDENTIFIER id )
320
expand_id(IDENTIFIER id)
267
{
321
{
268
    DEREF_loc ( id_loc ( id ), crt_loc ) ;
322
	DEREF_loc(id_loc(id), crt_loc);
269
    decl_loc = crt_loc ;
323
	decl_loc = crt_loc;
270
    return ;
324
	return;
271
}
325
}
272
 
326
 
273
 
327
 
274
/*
328
/*
275
    DECLARATION SPECIFIER MASK
329
    DECLARATION SPECIFIER MASK
Line 277... Line 331...
277
    The macro dspec_mask is a mask which gives those declaration specifiers
331
    The macro dspec_mask is a mask which gives those declaration specifiers
278
    which should be the same for all declarations.
332
    which should be the same for all declarations.
279
*/
333
*/
280
 
334
 
281
#define dspec_mem_func\
335
#define dspec_mem_func\
282
    ( dspec_virtual | dspec_pure | dspec_explicit | dspec_implicit )
336
   (dspec_virtual | dspec_pure | dspec_explicit | dspec_implicit)
283
 
337
 
284
#define dspec_mask\
338
#define dspec_mask\
285
    ( dspec_storage | dspec_access | dspec_language | dspec_mem_func )
339
   (dspec_storage | dspec_access | dspec_language | dspec_mem_func)
286
 
340
 
287
 
341
 
288
/*
342
/*
289
    MERGE AN IDENTIFIER INTO A NAMESPACE
343
    MERGE AN IDENTIFIER INTO A NAMESPACE
290
 
344
 
291
    This routine merges the identifier id read from a spec input file
345
    This routine merges the identifier id read from a spec input file
292
    into the namespace ns.
346
    into the namespace ns.
293
*/
347
*/
294
 
348
 
295
static void merge_id
349
static void
296
    PROTO_N ( ( ns, id ) )
-
 
297
    PROTO_T ( NAMESPACE ns X IDENTIFIER id )
350
merge_id(NAMESPACE ns, IDENTIFIER id)
298
{
351
{
299
    int type ;
352
	int type;
300
    HASHID nm ;
353
	HASHID nm;
301
    MEMBER mem ;
354
	MEMBER mem;
302
    IDENTIFIER pid ;
355
	IDENTIFIER pid;
-
 
356
 
-
 
357
	/* Allow for overloaded functions */
-
 
358
	if (IS_id_function_etc(id)) {
-
 
359
		IDENTIFIER over = DEREF_id(id_function_etc_over(id));
-
 
360
		if (!IS_NULL_id(over)) {
-
 
361
			merge_id(ns, over);
-
 
362
		}
-
 
363
	}
303
 
364
 
304
    /* Allow for overloaded functions */
-
 
305
    if ( IS_id_function_etc ( id ) ) {
-
 
306
	IDENTIFIER over = DEREF_id ( id_function_etc_over ( id ) ) ;
-
 
307
	if ( !IS_NULL_id ( over ) ) merge_id ( ns, over ) ;
-
 
308
    }
-
 
309
 
-
 
310
    /* Find previous declaration */
365
	/* Find previous declaration */
311
    expand_id ( id ) ;
366
	expand_id(id);
312
    if ( IS_NULL_nspace ( ns ) ) return ;
367
	if (IS_NULL_nspace(ns)) {
-
 
368
		return;
-
 
369
	}
313
    nm = DEREF_hashid ( id_name ( id ) ) ;
370
	nm = DEREF_hashid(id_name(id));
314
    mem = search_member ( ns, nm, 1 ) ;
371
	mem = search_member(ns, nm, 1);
315
    if ( is_tagged_type ( id ) ) {
372
	if (is_tagged_type(id)) {
316
	pid = type_member ( mem, 3 ) ;
373
		pid = type_member(mem, 3);
317
	type = 1 ;
374
		type = 1;
318
    } else {
375
	} else {
319
	pid = DEREF_id ( member_id ( mem ) ) ;
376
		pid = DEREF_id(member_id(mem));
320
	type = 0 ;
377
		type = 0;
321
    }
378
	}
322
 
379
 
323
    /* Check previous declaration */
380
	/* Check previous declaration */
324
    if ( !IS_NULL_id ( pid ) ) {
381
	if (!IS_NULL_id(pid)) {
325
	unsigned tag = TAG_id ( id ) ;
382
		unsigned tag = TAG_id(id);
326
	unsigned ptag = TAG_id ( pid ) ;
383
		unsigned ptag = TAG_id(pid);
327
	if ( tag == id_stat_mem_func_tag ) tag = id_mem_func_tag ;
-
 
328
	if ( ptag == id_stat_mem_func_tag ) ptag = id_mem_func_tag ;
-
 
329
	if ( tag == ptag ) {
-
 
330
	    int ok = 1 ;
-
 
331
	    DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
-
 
332
	    DECL_SPEC pds = DEREF_dspec ( id_storage ( pid ) ) ;
-
 
333
	    PTR ( TYPE ) pt = NULL_ptr ( TYPE ) ;
-
 
334
	    PTR ( TYPE ) ps = NULL_ptr ( TYPE ) ;
-
 
335
	    switch ( tag ) {
-
 
336
		case id_class_name_tag :
-
 
337
		case id_enum_name_tag :
-
 
338
		case id_class_alias_tag :
-
 
339
		case id_enum_alias_tag :
-
 
340
		case id_type_alias_tag : {
-
 
341
		    pt = id_class_name_etc_defn ( id ) ;
-
 
342
		    ps = id_class_name_etc_defn ( pid ) ;
-
 
343
		    break ;
-
 
344
		}
-
 
345
		case id_variable_tag :
-
 
346
		case id_parameter_tag :
-
 
347
		case id_stat_member_tag : {
384
		if (tag == id_stat_mem_func_tag) {
348
		    pt = id_variable_etc_type ( id ) ;
-
 
349
		    ps = id_variable_etc_type ( pid ) ;
-
 
350
		    break ;
-
 
351
		}
-
 
352
#if 0
-
 
353
		case id_function_tag :
-
 
354
		case id_mem_func_tag :
385
			tag = id_mem_func_tag;
355
		case id_stat_mem_func_tag : {
-
 
356
		    /* NOT YET IMPLEMENTED - function overloading */
-
 
357
		    pt = id_function_etc_type ( id ) ;
-
 
358
		    ps = id_function_etc_type ( pid ) ;
-
 
359
		    break ;
-
 
360
		}
-
 
361
#endif
-
 
362
		case id_member_tag : {
-
 
363
		    pt = id_member_type ( id ) ;
-
 
364
		    ps = id_member_type ( pid ) ;
-
 
365
		    break ;
-
 
366
		}
-
 
367
		case id_enumerator_tag : {
-
 
368
		    pt = id_enumerator_etype ( id ) ;
-
 
369
		    ps = id_enumerator_etype ( pid ) ;
-
 
370
		    break ;
-
 
371
		}
-
 
372
	    }
-
 
373
 
-
 
374
	    /* Check type compatibility */
-
 
375
	    if ( !IS_NULL_ptr ( pt ) && !IS_NULL_ptr ( ps ) ) {
-
 
376
		ERROR err = NULL_err ;
-
 
377
		TYPE t = DEREF_type ( pt ) ;
-
 
378
		TYPE s = DEREF_type ( ps ) ;
-
 
379
		t = expand_type ( t, 1 ) ;
-
 
380
		s = expand_type ( s, 1 ) ;
-
 
381
		s = check_compatible ( s, t, 0, &err, 1 ) ;
-
 
382
		if ( !IS_NULL_err ( err ) ) {
-
 
383
		    /* Incompatible declaration */
-
 
384
		    PTR ( LOCATION ) ploc = id_loc ( pid ) ;
-
 
385
		    ERROR err2 = ERR_basic_link_decl_type ( pid, ploc ) ;
-
 
386
		    err = concat_error ( err, err2 ) ;
-
 
387
		    report ( crt_loc, err ) ;
-
 
388
		    ok = 0 ;
-
 
389
		} else {
-
 
390
		    COPY_type ( pt, t ) ;
-
 
391
		    COPY_type ( ps, s ) ;
-
 
392
		}
386
		}
393
	    }
-
 
394
 
-
 
395
	    /* Check declaration specifiers */
-
 
396
	    if ( ok && ( ds & dspec_mask ) != ( pds & dspec_mask ) ) {
-
 
397
		PTR ( LOCATION ) ploc = id_loc ( pid ) ;
-
 
398
		DECL_SPEC st = ( ds & dspec_storage ) ;
-
 
399
		DECL_SPEC pst = ( pds & dspec_storage ) ;
-
 
400
		if ( st != pst ) {
-
 
401
		    /* Inconsistent linkage */
-
 
402
		    ERROR err ;
-
 
403
		    if ( pst & dspec_static ) {
387
		if (ptag == id_stat_mem_func_tag) {
404
			err = ERR_dcl_stc_internal ( pid, ploc ) ;
-
 
405
		    } else {
-
 
406
			err = ERR_dcl_stc_external ( pid, ploc ) ;
-
 
407
		    }
-
 
408
		    report ( crt_loc, err ) ;
388
			ptag = id_mem_func_tag;
409
		}
389
		}
-
 
390
		if (tag == ptag) {
-
 
391
			int ok = 1;
-
 
392
			DECL_SPEC ds = DEREF_dspec(id_storage(id));
-
 
393
			DECL_SPEC pds = DEREF_dspec(id_storage(pid));
-
 
394
			PTR(TYPE) pt = NULL_ptr(TYPE);
-
 
395
			PTR(TYPE) ps = NULL_ptr(TYPE);
-
 
396
			switch (tag) {
-
 
397
			case id_class_name_tag:
-
 
398
			case id_enum_name_tag:
-
 
399
			case id_class_alias_tag:
-
 
400
			case id_enum_alias_tag:
-
 
401
			case id_type_alias_tag:
-
 
402
				pt = id_class_name_etc_defn(id);
-
 
403
				ps = id_class_name_etc_defn(pid);
-
 
404
				break;
-
 
405
			case id_variable_tag:
-
 
406
			case id_parameter_tag:
-
 
407
			case id_stat_member_tag:
-
 
408
				pt = id_variable_etc_type(id);
-
 
409
				ps = id_variable_etc_type(pid);
-
 
410
				break;
-
 
411
#if 0
-
 
412
			case id_function_tag:
-
 
413
			case id_mem_func_tag:
-
 
414
			case id_stat_mem_func_tag: {
-
 
415
				/* NOT YET IMPLEMENTED - function overloading */
-
 
416
				pt = id_function_etc_type(id);
-
 
417
				ps = id_function_etc_type(pid);
-
 
418
				break;
-
 
419
			}
-
 
420
#endif
-
 
421
			case id_member_tag:
-
 
422
				pt = id_member_type(id);
-
 
423
				ps = id_member_type(pid);
-
 
424
				break;
-
 
425
			case id_enumerator_tag:
-
 
426
				pt = id_enumerator_etype(id);
-
 
427
				ps = id_enumerator_etype(pid);
-
 
428
				break;
-
 
429
			}
-
 
430
 
-
 
431
			/* Check type compatibility */
-
 
432
			if (!IS_NULL_ptr(pt) && !IS_NULL_ptr(ps)) {
-
 
433
				ERROR err = NULL_err;
-
 
434
				TYPE t = DEREF_type(pt);
-
 
435
				TYPE s = DEREF_type(ps);
-
 
436
				t = expand_type(t, 1);
-
 
437
				s = expand_type(s, 1);
-
 
438
				s = check_compatible(s, t, 0, &err, 1);
-
 
439
				if (!IS_NULL_err(err)) {
-
 
440
					/* Incompatible declaration */
-
 
441
					PTR(LOCATION) ploc = id_loc(pid);
-
 
442
					ERROR err2 =
-
 
443
					    ERR_basic_link_decl_type(pid, ploc);
-
 
444
					err = concat_error(err, err2);
-
 
445
					report(crt_loc, err);
-
 
446
					ok = 0;
-
 
447
				} else {
-
 
448
					COPY_type(pt, t);
-
 
449
					COPY_type(ps, s);
-
 
450
				}
-
 
451
			}
-
 
452
 
-
 
453
			/* Check declaration specifiers */
-
 
454
			if (ok && (ds & dspec_mask)!= (pds & dspec_mask)) {
-
 
455
				PTR(LOCATION) ploc = id_loc(pid);
-
 
456
				DECL_SPEC st = (ds & dspec_storage);
-
 
457
				DECL_SPEC pst = (pds & dspec_storage);
-
 
458
				if (st != pst) {
-
 
459
					/* Inconsistent linkage */
-
 
460
					ERROR err;
-
 
461
					if (pst & dspec_static) {
-
 
462
						err = ERR_dcl_stc_internal(pid, ploc);
-
 
463
					} else {
-
 
464
						err = ERR_dcl_stc_external(pid, ploc);
-
 
465
					}
-
 
466
					report(crt_loc, err);
-
 
467
				}
410
		st = ( ds & dspec_access ) ;
468
				st = (ds & dspec_access);
411
		pst = ( pds & dspec_access ) ;
469
				pst = (pds & dspec_access);
412
		if ( st != pst ) {
470
				if (st != pst) {
413
		    /* Adjust access */
471
					/* Adjust access */
414
		    adjust_access ( pid, st, 0 ) ;
472
					adjust_access(pid, st, 0);
415
		}
473
				}
416
		st = ( ds & dspec_language ) ;
474
				st = (ds & dspec_language);
417
		pst = ( pds & dspec_language ) ;
475
				pst = (pds & dspec_language);
418
		if ( st != pst ) {
476
				if (st != pst) {
419
		    /* Inconsistent language */
477
					/* Inconsistent language */
-
 
478
					string lang =
420
		    string lang = linkage_string ( pst, cv_none ) ;
479
					    linkage_string(pst, cv_none);
-
 
480
					ERROR err =
421
		    ERROR err = ERR_dcl_link_lang ( pid, lang, ploc ) ;
481
					    ERR_dcl_link_lang(pid, lang, ploc);
422
		    report ( crt_loc, err ) ;
482
					report(crt_loc, err);
423
		}
483
				}
424
		st = ( ds & dspec_mem_func ) ;
484
				st = (ds & dspec_mem_func);
425
		pst = ( pds & dspec_mem_func ) ;
485
				pst = (pds & dspec_mem_func);
426
		if ( st != pst ) {
486
				if (st != pst) {
427
		    /* NOT YET IMPLEMENTED */
487
					/* NOT YET IMPLEMENTED */
428
		    /* EMPTY */
488
					/* EMPTY */
429
		}
489
				}
430
	    }
490
			}
431
 
491
 
432
	    /* Check for multiple definitions */
492
			/* Check for multiple definitions */
433
	    if ( pds & dspec_defn ) {
493
			if (pds & dspec_defn) {
434
		if ( ds & dspec_defn ) {
494
				if (ds & dspec_defn) {
435
		    if ( !consistent_redef ( id, pid ) && ok ) {
495
					if (!consistent_redef(id, pid) && ok) {
436
			PTR ( LOCATION ) ploc = id_loc ( pid ) ;
496
						PTR(LOCATION) ploc =
-
 
497
						    id_loc(pid);
437
			report ( crt_loc, ERR_basic_odr_def ( pid, ploc ) ) ;
498
						report(crt_loc, ERR_basic_odr_def(pid, ploc));
438
		    }
499
					}
-
 
500
				} else {
-
 
501
					id = pid;
-
 
502
				}
-
 
503
			}
-
 
504
 
439
		} else {
505
		} else {
-
 
506
			/* Redeclared as different type of object */
440
		    id = pid ;
507
			PTR(LOCATION) ploc = id_loc(pid);
-
 
508
			report(crt_loc, ERR_basic_odr_diff(pid, ploc));
441
		}
509
		}
442
	    }
510
	}
443
 
511
 
-
 
512
	/* Set member */
-
 
513
	COPY_nspace(id_parent(id), ns);
-
 
514
	if (type) {
-
 
515
		set_type_member(mem, id);
444
	} else {
516
	} else {
445
	    /* Redeclared as different type of object */
-
 
446
	    PTR ( LOCATION ) ploc = id_loc ( pid ) ;
517
		set_member(mem, id);
447
	    report ( crt_loc, ERR_basic_odr_diff ( pid, ploc ) ) ;
-
 
448
	}
518
	}
449
    }
-
 
450
 
-
 
451
    /* Set member */
-
 
452
    COPY_nspace ( id_parent ( id ), ns ) ;
-
 
453
    if ( type ) {
-
 
454
	set_type_member ( mem, id ) ;
-
 
455
    } else {
-
 
456
	set_member ( mem, id ) ;
-
 
457
    }
-
 
458
    return ;
519
	return;
459
}
520
}
460
 
521
 
461
 
522
 
462
/*
523
/*
463
    MERGE TWO NAMESPACES
524
    MERGE TWO NAMESPACES
464
 
525
 
465
    This routine merges the namespace ns with the additional members
526
    This routine merges the namespace ns with the additional members
466
    read from a spec input file given by pns.
527
    read from a spec input file given by pns.
467
*/
528
*/
468
 
529
 
469
void merge_namespaces
530
void
470
    PROTO_N ( ( ns, pns ) )
-
 
471
    PROTO_T ( NAMESPACE ns X NAMESPACE pns )
531
merge_namespaces(NAMESPACE ns, NAMESPACE pns)
472
{
532
{
473
    MEMBER mem = DEREF_member ( nspace_named_etc_first ( pns ) ) ;
533
	MEMBER mem = DEREF_member(nspace_named_etc_first(pns));
474
    LIST ( IDENTIFIER ) ids = DEREF_list ( nspace_named_etc_extra ( pns ) ) ;
534
	LIST(IDENTIFIER) ids = DEREF_list(nspace_named_etc_extra(pns));
475
    force_merge++ ;
535
	force_merge++;
476
    while ( !IS_NULL_member ( mem ) ) {
536
	while (!IS_NULL_member(mem)) {
477
	IDENTIFIER id = DEREF_id ( member_id ( mem ) ) ;
537
		IDENTIFIER id = DEREF_id(member_id(mem));
478
	IDENTIFIER alt = DEREF_id ( member_alt ( mem ) ) ;
538
		IDENTIFIER alt = DEREF_id(member_alt(mem));
479
	if ( !IS_NULL_id ( id ) ) {
539
		if (!IS_NULL_id(id)) {
480
	    merge_id ( ns, id ) ;
540
			merge_id(ns, id);
-
 
541
		}
-
 
542
		if (!IS_NULL_id(alt) && !EQ_id(id, alt)) {
-
 
543
			merge_id(ns, alt);
-
 
544
		}
-
 
545
		mem = DEREF_member(member_next(mem));
481
	}
546
	}
482
	if ( !IS_NULL_id ( alt ) && !EQ_id ( id, alt ) ) {
547
	while (!IS_NULL_list(ids)) {
-
 
548
		IDENTIFIER id = DEREF_id(HEAD_list(ids));
-
 
549
		expand_id(id);
483
	    merge_id ( ns, alt ) ;
550
		ids = TAIL_list(ids);
484
	}
551
	}
485
	mem = DEREF_member ( member_next ( mem ) ) ;
-
 
486
    }
-
 
487
    while ( !IS_NULL_list ( ids ) ) {
-
 
488
	IDENTIFIER id = DEREF_id ( HEAD_list ( ids ) ) ;
-
 
489
	expand_id ( id ) ;
-
 
490
	ids = TAIL_list ( ids ) ;
-
 
491
    }
-
 
492
    force_merge-- ;
552
	force_merge--;
493
    return ;
553
	return;
494
}
554
}