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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Subversion Repositories tendra.SVN

Rev

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

Rev 5 Rev 6
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2006 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997, 1998
32
    		 Crown Copyright (c) 1997, 1998
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
Line 80... Line 110...
80
    This is primarily so that the location of a declaration can be set to
110
    This is primarily so that the location of a declaration can be set to
81
    the location of the declarator rather than the end of the corresponding
111
    the location of the declarator rather than the end of the corresponding
82
    initialiser.
112
    initialiser.
83
*/
113
*/
84
 
114
 
85
LOCATION decl_loc = NULL_loc ;
115
LOCATION decl_loc = NULL_loc;
86
int is_redeclared = 0 ;
116
int is_redeclared = 0;
87
 
117
 
88
 
118
 
89
/*
119
/*
90
    DEFAULT LINKAGE FOR INLINE FUNCTIONS AND CONST OBJECTS
120
    DEFAULT LINKAGE FOR INLINE FUNCTIONS AND CONST OBJECTS
91
 
121
 
92
    These variables give the default linkages for inline functions and
122
    These variables give the default linkages for inline functions and
93
    const objects and the default cv-qualifiers for external objects.
123
    const objects and the default cv-qualifiers for external objects.
94
*/
124
*/
95
 
125
 
96
DECL_SPEC inline_linkage = dspec_static ;
126
DECL_SPEC inline_linkage = dspec_static;
97
DECL_SPEC const_linkage = dspec_static ;
127
DECL_SPEC const_linkage = dspec_static;
98
CV_SPEC cv_extern = cv_none ;
128
CV_SPEC cv_extern = cv_none;
99
 
129
 
100
 
130
 
101
/*
131
/*
102
    DUMMY EMPTY DECLARATION SPECIFIER
132
    DUMMY EMPTY DECLARATION SPECIFIER
103
 
133
 
104
    The value dspec_empty is used during the processing of declarations
134
    The value dspec_empty is used during the processing of declarations
105
    to mark any declaration specifier which does not contain an explicit
135
    to mark any declaration specifier which does not contain an explicit
106
    specifier.  The value dspec_nonempty gives those declaration
136
    specifier.  The value dspec_nonempty gives those declaration
107
    specifiers which constitute an explicit specifier.
137
    specifiers which constitute an explicit specifier.
108
*/
138
*/
109
 
139
 
110
#define dspec_empty		dspec_pure
140
#define dspec_empty		dspec_pure
111
#define dspec_nonempty		dspec_keyword
141
#define dspec_nonempty		dspec_keyword
112
 
142
 
113
 
143
 
114
/*
144
/*
115
    COMPLETE A DECLARATION SPECIFIER
145
    COMPLETE A DECLARATION SPECIFIER
116
 
146
 
117
    This routine completes the declaration specifier given by the
147
    This routine completes the declaration specifier given by the
118
    specifiers ds, the type t and the cv-qualifier cv.  If these are
148
    specifiers ds, the type t and the cv-qualifier cv.  If these are
119
    all empty then the result is marked using dspec_empty.  The special
149
    all empty then the result is marked using dspec_empty.  The special
120
    case 'extern "LANG" typedef' is checked.
150
    case 'extern "LANG" typedef' is checked.
121
*/
151
*/
122
 
152
 
123
DECL_SPEC complete_dspec
153
DECL_SPEC
124
    PROTO_N ( ( ds, bt, t, cv ) )
-
 
125
    PROTO_T ( DECL_SPEC ds X BASE_TYPE bt X TYPE t X CV_SPEC cv )
154
complete_dspec(DECL_SPEC ds, BASE_TYPE bt, TYPE t, CV_SPEC cv)
126
{
155
{
127
    DECL_SPEC key = ( ds & dspec_nonempty ) ;
156
	DECL_SPEC key = (ds & dspec_nonempty);
128
    if ( key || bt || !IS_NULL_type ( t ) || cv ) {
157
	if (key || bt || !IS_NULL_type(t) || cv) {
129
	/* Have a declaration specifier */
158
		/* Have a declaration specifier */
130
	if ( ds & dspec_c ) {
159
		if (ds & dspec_c) {
131
	    /* Have a linkage specification */
160
			/* Have a linkage specification */
132
	    if ( ds & dspec_typedef ) ds &= ~dspec_extern ;
161
			if (ds & dspec_typedef) {
-
 
162
				ds &= ~dspec_extern;
-
 
163
			}
133
	    ds &= ~dspec_c ;
164
			ds &= ~dspec_c;
-
 
165
		}
-
 
166
	} else {
-
 
167
		ds |= dspec_empty;
134
	}
168
	}
135
    } else {
-
 
136
	ds |= dspec_empty ;
-
 
137
    }
-
 
138
    return ( ds ) ;
169
	return (ds);
139
}
170
}
140
 
171
 
141
 
172
 
142
/*
173
/*
143
    CHECK INFERRED OBJECT TYPES
174
    CHECK INFERRED OBJECT TYPES
144
 
175
 
145
    This routine checks the declaration specifiers ds and the type *p for
176
    This routine checks the declaration specifiers ds and the type *p for
146
    inferred types and empty specifier lists.  It is used in object,
177
    inferred types and empty specifier lists.  It is used in object,
147
    parameter and class member declarations.
178
    parameter and class member declarations.
148
*/
179
*/
149
 
180
 
150
static DECL_SPEC check_inferred_type
181
static DECL_SPEC
151
    PROTO_N ( ( ds, p, mem ) )
-
 
152
    PROTO_T ( DECL_SPEC ds X TYPE *p X int mem )
182
check_inferred_type(DECL_SPEC ds, TYPE *p, int mem)
153
{
183
{
154
    int infer ;
184
	int infer;
155
    TYPE t = *p ;
185
	TYPE t = *p;
156
    int empty = 0 ;
186
	int empty = 0;
157
    ERROR err = NULL_err ;
187
	ERROR err = NULL_err;
158
 
188
 
159
    /* Report if there are no declaration specifiers */
189
	/* Report if there are no declaration specifiers */
160
    if ( ds & dspec_empty ) {
190
	if (ds & dspec_empty) {
161
	if ( mem ) {
191
		if (mem) {
162
	    err = ERR_class_mem_ds_empty () ;
192
			err = ERR_class_mem_ds_empty();
163
	} else {
193
		} else {
164
	    err = ERR_dcl_dcl_ds_empty () ;
194
			err = ERR_dcl_dcl_ds_empty();
165
	}
195
		}
166
	ds &= ~dspec_empty ;
196
		ds &= ~dspec_empty;
167
	empty = 1 ;
197
		empty = 1;
168
    }
198
	}
169
 
199
 
170
    /* Check on inferred types */
200
	/* Check on inferred types */
171
    infer = is_type_inferred ( t ) ;
201
	infer = is_type_inferred(t);
172
    if ( infer != INFERRED_NOT ) {
202
	if (infer != INFERRED_NOT) {
173
	ERROR err2 ;
203
		ERROR err2;
174
	t = clean_inferred_type ( t ) ;
204
		t = clean_inferred_type(t);
175
	if ( empty ) {
205
		if (empty) {
176
	    err2 = ERR_dcl_type_infer ( t ) ;
206
			err2 = ERR_dcl_type_infer(t);
177
	} else {
207
		} else {
178
	    err2 = report_inferred_type ( t, infer ) ;
208
			err2 = report_inferred_type(t, infer);
179
	}
209
		}
180
	err = concat_error ( err, err2 ) ;
210
		err = concat_error(err, err2);
181
	*p = t ;
211
		*p = t;
182
    }
212
	}
183
    if ( !IS_NULL_err ( err ) ) report ( crt_loc, err ) ;
213
	if (!IS_NULL_err(err)) {
-
 
214
		report(crt_loc, err);
-
 
215
	}
184
    return ( ds ) ;
216
	return (ds);
185
}
217
}
186
 
218
 
187
 
219
 
188
/*
220
/*
189
    CHECK INFERRED FUNCTION TYPES
221
    CHECK INFERRED FUNCTION TYPES
190
 
222
 
191
    This routine checks the declaration specifiers ds and the function
223
    This routine checks the declaration specifiers ds and the function
192
    type t for inferred types and empty specifier lists.  It is used in
224
    type t for inferred types and empty specifier lists.  It is used in
193
    function declarations and definitions (as indicated by def).
225
    function declarations and definitions (as indicated by def).
194
*/
226
*/
195
 
227
 
196
static DECL_SPEC check_func_type
228
static DECL_SPEC
197
    PROTO_N ( ( ds, t, def, chk, mem ) )
-
 
198
    PROTO_T ( DECL_SPEC ds X TYPE t X int def X int chk X int mem )
229
check_func_type(DECL_SPEC ds, TYPE t, int def, int chk, int mem)
199
{
230
{
200
    int empty = 0 ;
231
	int empty = 0;
201
    ERROR err = NULL_err ;
232
	ERROR err = NULL_err;
202
 
233
 
203
    /* Report if there are no declaration specifiers */
234
	/* Report if there are no declaration specifiers */
204
    if ( ds & dspec_empty ) {
235
	if (ds & dspec_empty) {
205
	if ( mem ) {
236
		if (mem) {
206
	    err = ERR_class_mem_ds_empty () ;
237
			err = ERR_class_mem_ds_empty();
207
	} else if ( def ) {
238
		} else if (def) {
208
	    err = ERR_dcl_dcl_ds_func () ;
239
			err = ERR_dcl_dcl_ds_func();
209
	} else {
240
		} else {
210
	    err = ERR_dcl_dcl_ds_empty () ;
241
			err = ERR_dcl_dcl_ds_empty();
211
	}
242
		}
212
	ds &= ~dspec_empty ;
243
		ds &= ~dspec_empty;
213
	empty = 1 ;
244
		empty = 1;
214
    }
245
	}
215
 
246
 
216
    /* Check for template types */
247
	/* Check for template types */
217
    while ( IS_type_templ ( t ) ) {
248
	while (IS_type_templ(t)) {
218
	ds |= dspec_template ;
249
		ds |= dspec_template;
219
	t = DEREF_type ( type_templ_defn ( t ) ) ;
250
		t = DEREF_type(type_templ_defn(t));
220
    }
251
	}
221
 
252
 
222
    /* Check the return type */
253
	/* Check the return type */
223
    if ( chk ) {
254
	if (chk) {
224
	TYPE r = DEREF_type ( type_func_ret ( t ) ) ;
255
		TYPE r = DEREF_type(type_func_ret(t));
225
	int infer = is_type_inferred ( r ) ;
256
		int infer = is_type_inferred(r);
226
	if ( infer != INFERRED_NOT ) {
257
		if (infer != INFERRED_NOT) {
227
	    ERROR err2 ;
258
			ERROR err2;
228
	    r = clean_inferred_type ( r ) ;
259
			r = clean_inferred_type(r);
229
	    if ( empty ) {
260
			if (empty) {
230
		err2 = ERR_dcl_type_infer ( r ) ;
261
				err2 = ERR_dcl_type_infer(r);
231
	    } else {
262
			} else {
232
		err2 = report_inferred_type ( r, infer ) ;
263
				err2 = report_inferred_type(r, infer);
233
	    }
264
			}
234
	    err = concat_error ( err, err2 ) ;
265
			err = concat_error(err, err2);
235
	    COPY_type ( type_func_ret ( t ), r ) ;
266
			COPY_type(type_func_ret(t), r);
-
 
267
		}
-
 
268
	}
-
 
269
	if (!IS_NULL_err(err)) {
-
 
270
		report(crt_loc, err);
236
	}
271
	}
237
    }
-
 
238
    if ( !IS_NULL_err ( err ) ) report ( crt_loc, err ) ;
-
 
239
    return ( ds ) ;
272
	return (ds);
240
}
273
}
241
 
274
 
242
 
275
 
243
/*
276
/*
244
    SHIFT A STORAGE CLASS
277
    SHIFT A STORAGE CLASS
245
 
278
 
246
    This macro is used to shift a storage class specifier into a more
279
    This macro is used to shift a storage class specifier into a more
247
    sensible range.
280
    sensible range.
248
*/
281
*/
249
 
282
 
250
#define DSPEC_STORAGE( A )	( ( A ) >> 6 )
283
#define DSPEC_STORAGE(A)	((A) >> 6)
251
 
284
 
252
 
285
 
253
/*
286
/*
254
    CHECK STORAGE CLASS SPECIFIERS
287
    CHECK STORAGE CLASS SPECIFIERS
255
 
288
 
256
    This routine extracts the storage class specifiers from the declaration
289
    This routine extracts the storage class specifiers from the declaration
257
    specifiers ds in the context given by loc.  It returns a valid storage
290
    specifiers ds in the context given by loc.  It returns a valid storage
258
    class specifier.
291
    class specifier.
259
*/
292
*/
260
 
293
 
261
static DECL_SPEC check_storage
294
static DECL_SPEC
262
    PROTO_N ( ( ds, loc, id ) )
-
 
263
    PROTO_T ( DECL_SPEC ds X int loc X IDENTIFIER id )
295
check_storage(DECL_SPEC ds, int loc, IDENTIFIER id)
264
{
296
{
265
    DECL_SPEC st = ( ds & dspec_storage ) ;
297
	DECL_SPEC st = (ds & dspec_storage);
266
 
298
 
267
    /* Check on storage class */
299
	/* Check on storage class */
268
    switch_label : {
300
switch_label:
269
	switch ( DSPEC_STORAGE ( st ) ) {
301
	switch (DSPEC_STORAGE(st)) {
270
 
-
 
271
	    case DSPEC_STORAGE ( dspec_none ) : {
302
	case DSPEC_STORAGE(dspec_none): {
272
		/* No storage class given */
303
		/* No storage class given */
273
		break ;
304
		break;
274
	    }
-
 
275
 
305
	}
276
	    case DSPEC_STORAGE ( dspec_auto ) :
306
	case DSPEC_STORAGE(dspec_auto):
277
	    case DSPEC_STORAGE ( dspec_register ) : {
307
	case DSPEC_STORAGE(dspec_register): {
278
		/* Deal with auto and register */
308
		/* Deal with auto and register */
279
		switch ( loc ) {
309
		switch (loc) {
280
		    case CONTEXT_OBJECT : {
310
		case CONTEXT_OBJECT: {
281
			/* Objects declared in a block are alright */
311
			/* Objects declared in a block are alright */
282
			if ( !in_function_defn ) goto bad_auto_lab ;
312
			if (!in_function_defn) {
-
 
313
				goto bad_auto_lab;
-
 
314
			}
283
			break ;
315
			break;
284
		    }
316
		}
285
		    case CONTEXT_FUNCTION : {
317
		case CONTEXT_FUNCTION: {
286
			/* Functions can't be auto */
318
			/* Functions can't be auto */
287
			if ( !in_function_defn ) goto bad_auto_lab ;
319
			if (!in_function_defn) {
-
 
320
				goto bad_auto_lab;
-
 
321
			}
288
			report ( crt_loc, ERR_dcl_stc_auto_func ( st ) ) ;
322
			report(crt_loc, ERR_dcl_stc_auto_func(st));
289
			st = dspec_none ;
323
			st = dspec_none;
290
			break ;
324
			break;
291
		    }
325
		}
292
		    case CONTEXT_PARAMETER :
326
		case CONTEXT_PARAMETER:
293
		    case CONTEXT_WEAK_PARAM : {
327
		case CONTEXT_WEAK_PARAM: {
294
			/* Function parameters are alright */
328
			/* Function parameters are alright */
295
			if ( st == dspec_auto ) {
329
			if (st == dspec_auto) {
296
			    /* Can't have auto parameters in C */
330
				/* Can't have auto parameters in C */
297
			    report ( crt_loc, ERR_dcl_stc_auto_par () ) ;
331
				report(crt_loc, ERR_dcl_stc_auto_par());
298
			}
332
			}
299
			break ;
333
			break;
300
		    }
334
		}
301
		    case CONTEXT_TEMPL_PARAM : {
335
		case CONTEXT_TEMPL_PARAM: {
302
			/* Template parameters can't have storage class */
336
			/* Template parameters can't have storage class */
303
			report ( crt_loc, ERR_temp_param_dcl_stc ( st ) ) ;
337
			report(crt_loc, ERR_temp_param_dcl_stc(st));
304
			st = dspec_none ;
338
			st = dspec_none;
305
			break ;
339
			break;
306
		    }
-
 
307
		    default :
-
 
308
		    bad_auto_lab : {
-
 
309
			/* Anything outside a block can't be auto */
-
 
310
			report ( crt_loc, ERR_dcl_stc_auto_bad ( st ) ) ;
-
 
311
			st = dspec_none ;
-
 
312
			break ;
-
 
313
		    }
-
 
314
		}
340
		}
-
 
341
		default:
-
 
342
bad_auto_lab:
-
 
343
			/* Anything outside a block can't be auto */
-
 
344
			report(crt_loc, ERR_dcl_stc_auto_bad(st));
-
 
345
			st = dspec_none;
315
		break ;
346
			break;
316
	    }
347
		}
-
 
348
		break;
317
 
349
	}
318
	    case DSPEC_STORAGE ( dspec_static ) : {
350
	case DSPEC_STORAGE(dspec_static): {
319
		/* Deal with static */
351
		/* Deal with static */
320
		switch ( loc ) {
352
		switch (loc) {
321
		    case CONTEXT_PARAMETER :
353
		case CONTEXT_PARAMETER:
322
		    case CONTEXT_WEAK_PARAM : {
354
		case CONTEXT_WEAK_PARAM: {
323
			/* Function parameters can't be static */
355
			/* Function parameters can't be static */
324
			report ( crt_loc, ERR_dcl_stc_param ( st ) ) ;
356
			report(crt_loc, ERR_dcl_stc_param(st));
325
			st = dspec_none ;
357
			st = dspec_none;
326
			break ;
358
			break;
327
		    }
359
		}
328
		    case CONTEXT_TEMPL_PARAM : {
360
		case CONTEXT_TEMPL_PARAM: {
329
			/* Template parameters can't have storage class */
361
			/* Template parameters can't have storage class */
330
			report ( crt_loc, ERR_temp_param_dcl_stc ( st ) ) ;
362
			report(crt_loc, ERR_temp_param_dcl_stc(st));
331
			st = dspec_none ;
363
			st = dspec_none;
332
			break ;
364
			break;
333
		    }
365
		}
334
		}
366
		}
335
		break ;
367
		break;
336
	    }
-
 
337
 
368
	}
338
	    case DSPEC_STORAGE ( dspec_extern ) : {
369
	case DSPEC_STORAGE(dspec_extern): {
339
		/* Deal with extern */
370
		/* Deal with extern */
340
		switch ( loc ) {
371
		switch (loc) {
341
		    case CONTEXT_OBJECT :
372
		case CONTEXT_OBJECT:
342
		    case CONTEXT_FUNCTION : {
373
		case CONTEXT_FUNCTION: {
343
			/* Objects and functions can be extern */
374
			/* Objects and functions can be extern */
344
			if ( !IS_NULL_id ( id ) ) {
375
			if (!IS_NULL_id(id)) {
345
			    switch ( TAG_id ( id ) ) {
376
				switch (TAG_id(id)) {
346
				case id_member_tag :
377
				case id_member_tag:
347
				case id_mem_func_tag :
378
				case id_mem_func_tag:
348
				case id_stat_member_tag :
379
				case id_stat_member_tag:
349
				case id_stat_mem_func_tag : {
380
				case id_stat_mem_func_tag: {
350
				    /* But not class members */
381
					/* But not class members */
351
				    ERROR err = ERR_dcl_stc_ext_mem () ;
382
					ERROR err = ERR_dcl_stc_ext_mem();
352
				    report ( crt_loc, err ) ;
383
					report(crt_loc, err);
353
				    break ;
384
					break;
-
 
385
				}
354
				}
386
				}
355
			    }
-
 
356
			}
387
			}
357
			break ;
388
			break;
358
		    }
389
		}
359
		    case CONTEXT_PARAMETER :
390
		case CONTEXT_PARAMETER:
360
		    case CONTEXT_WEAK_PARAM : {
391
		case CONTEXT_WEAK_PARAM: {
361
			/* Function parameters can't be extern */
392
			/* Function parameters can't be extern */
362
			report ( crt_loc, ERR_dcl_stc_param ( st ) ) ;
393
			report(crt_loc, ERR_dcl_stc_param(st));
363
			st = dspec_none ;
394
			st = dspec_none;
364
			break ;
395
			break;
365
		    }
396
		}
366
		    case CONTEXT_TEMPL_PARAM : {
397
		case CONTEXT_TEMPL_PARAM: {
367
			/* Template parameters can't have storage class */
398
			/* Template parameters can't have storage class */
368
			report ( crt_loc, ERR_temp_param_dcl_stc ( st ) ) ;
399
			report(crt_loc, ERR_temp_param_dcl_stc(st));
369
			st = dspec_none ;
400
			st = dspec_none;
370
			break ;
401
			break;
371
		    }
402
		}
372
		    default : {
403
		default:
373
			/* Class members can't be extern */
404
			/* Class members can't be extern */
374
			report ( crt_loc, ERR_dcl_stc_ext_mem () ) ;
405
			report(crt_loc, ERR_dcl_stc_ext_mem());
375
			st = dspec_none ;
406
			st = dspec_none;
376
			break ;
407
			break;
377
		    }
-
 
378
		}
408
		}
379
		break ;
409
		break;
380
	    }
-
 
381
 
410
	}
382
	    case DSPEC_STORAGE ( dspec_mutable ) : {
411
	case DSPEC_STORAGE(dspec_mutable): {
383
		/* Deal with mutable */
412
		/* Deal with mutable */
384
		if ( loc != CONTEXT_MEMBER ) {
413
		if (loc != CONTEXT_MEMBER) {
385
		    /* Only data members can be mutable */
414
			/* Only data members can be mutable */
386
		    report ( crt_loc, ERR_dcl_stc_mut_bad () ) ;
415
			report(crt_loc, ERR_dcl_stc_mut_bad());
387
		    st = dspec_none ;
416
			st = dspec_none;
388
		}
417
		}
389
		break ;
418
		break;
390
	    }
-
 
391
 
419
	}
392
	    default : {
420
	default: {
393
		/* More than one storage class - select one */
421
		/* More than one storage class - select one */
394
		DECL_SPEC nst = dspec_static ;
422
		DECL_SPEC nst = dspec_static;
395
		while ( !( st & nst ) ) {
423
		while (!(st & nst)) {
396
		    ASSERT ( nst != dspec_none ) ;
424
			ASSERT(nst != dspec_none);
397
		    nst <<= 1 ;
425
			nst <<= 1;
398
		}
426
		}
399
		report ( crt_loc, ERR_dcl_stc_dup ( st, nst ) ) ;
427
		report(crt_loc, ERR_dcl_stc_dup(st, nst));
400
		st = nst ;
428
		st = nst;
401
		goto switch_label ;
429
		goto switch_label;
402
	    }
430
	}
403
	}
431
	}
404
    }
-
 
405
    return ( st ) ;
432
	return (st);
406
}
433
}
407
 
434
 
408
 
435
 
409
/*
436
/*
410
    CHECK STORAGE CLASS SPECIFIERS
437
    CHECK STORAGE CLASS SPECIFIERS
411
 
438
 
412
    This routine extracts the function specifiers (plus friend specifiers)
439
    This routine extracts the function specifiers (plus friend specifiers)
413
    from the declaration specifiers ds in the context given by loc (as
440
    from the declaration specifiers ds in the context given by loc (as
414
    above).  It returns a valid combination of function and friend
441
    above).  It returns a valid combination of function and friend
415
    specifiers.
442
    specifiers.
416
*/
443
*/
417
 
444
 
418
static DECL_SPEC check_func_spec
445
static DECL_SPEC
419
    PROTO_N ( ( ds, loc ) )
-
 
420
    PROTO_T ( DECL_SPEC ds X int loc )
446
check_func_spec(DECL_SPEC ds, int loc)
421
{
447
{
422
    DECL_SPEC fn = dspec_none ;
448
	DECL_SPEC fn = dspec_none;
423
 
449
 
424
    /* Only functions can be inline */
450
	/* Only functions can be inline */
425
    if ( ds & dspec_inline ) {
451
	if (ds & dspec_inline) {
426
	if ( loc == CONTEXT_FUNCTION || loc == CONTEXT_FUNC_MEMBER ) {
452
		if (loc == CONTEXT_FUNCTION || loc == CONTEXT_FUNC_MEMBER) {
427
	    fn |= dspec_inline ;
453
			fn |= dspec_inline;
428
	} else {
454
		} else {
429
	    report ( crt_loc, ERR_dcl_fct_spec_inline_bad () ) ;
455
			report(crt_loc, ERR_dcl_fct_spec_inline_bad());
430
	}
456
		}
431
    }
457
	}
432
 
458
 
433
    /* Only function members can be virtual */
459
	/* Only function members can be virtual */
434
    if ( ds & dspec_virtual ) {
460
	if (ds & dspec_virtual) {
435
	if ( loc == CONTEXT_FUNC_MEMBER ) {
461
		if (loc == CONTEXT_FUNC_MEMBER) {
436
	    fn |= dspec_virtual ;
462
			fn |= dspec_virtual;
437
	} else {
463
		} else {
438
	    report ( crt_loc, ERR_dcl_fct_spec_virtual () ) ;
464
			report(crt_loc, ERR_dcl_fct_spec_virtual());
439
	}
465
		}
440
    }
466
	}
441
 
467
 
442
    /* Only function members can be explicit */
468
	/* Only function members can be explicit */
443
    if ( ds & dspec_explicit ) {
469
	if (ds & dspec_explicit) {
444
	if ( loc == CONTEXT_FUNC_MEMBER ) {
470
		if (loc == CONTEXT_FUNC_MEMBER) {
445
	    fn |= dspec_explicit ;
471
			fn |= dspec_explicit;
446
	} else {
472
		} else {
447
	    report ( crt_loc, ERR_dcl_fct_spec_explicit () ) ;
473
			report(crt_loc, ERR_dcl_fct_spec_explicit());
448
	}
474
		}
449
    }
475
	}
450
 
476
 
451
    /* Only functions declared in a class can be friends */
477
	/* Only functions declared in a class can be friends */
452
    if ( ds & dspec_friend ) {
478
	if (ds & dspec_friend) {
453
	if ( loc == CONTEXT_FUNCTION && in_class_defn ) {
479
		if (loc == CONTEXT_FUNCTION && in_class_defn) {
454
	    /* Don't add to specifier list */
480
			/* Don't add to specifier list */
455
	    /* EMPTY */
481
			/* EMPTY */
456
	} else if ( in_class_defn ) {
482
		} else if (in_class_defn) {
457
	    report ( crt_loc, ERR_class_friend_decl () ) ;
483
			report(crt_loc, ERR_class_friend_decl());
458
	} else {
484
		} else {
459
	    report ( crt_loc, ERR_dcl_friend_class () ) ;
485
			report(crt_loc, ERR_dcl_friend_class());
460
	}
486
		}
461
    }
487
	}
462
 
488
 
463
    /* Allow for function discarding */
489
	/* Allow for function discarding */
464
    if ( loc == CONTEXT_FUNCTION || loc == CONTEXT_FUNC_MEMBER ) {
490
	if (loc == CONTEXT_FUNCTION || loc == CONTEXT_FUNC_MEMBER) {
465
	fn |= dspec_ignore ;
491
		fn |= dspec_ignore;
466
    }
492
	}
467
    return ( fn ) ;
493
	return (fn);
468
}
494
}
469
 
495
 
470
 
496
 
471
/*
497
/*
472
    CONSTRUCT A TYPE DECLARATION
498
    CONSTRUCT A TYPE DECLARATION
473
 
499
 
474
    This routine constructs the declaration of a type with declaration
500
    This routine constructs the declaration of a type with declaration
475
    specifiers ds (which will include typedef), type t and name id in the
501
    specifiers ds (which will include typedef), type t and name id in the
476
    namespace ns.  mem gives the member of ns corresponding to id or the
502
    namespace ns.  mem gives the member of ns corresponding to id or the
477
    null member for class member redeclarations.
503
    null member for class member redeclarations.
478
*/
504
*/
479
 
505
 
480
static IDENTIFIER make_type_decl
506
static IDENTIFIER
481
    PROTO_N ( ( ns, ds, t, mem, id ) )
-
 
482
    PROTO_T ( NAMESPACE ns X DECL_SPEC ds X TYPE t X
507
make_type_decl(NAMESPACE ns, DECL_SPEC ds, TYPE t, MEMBER mem, IDENTIFIER id)
483
	      MEMBER mem X IDENTIFIER id )
-
 
484
{
508
{
485
    int reported = 0 ;
509
	int reported = 0;
486
    IDENTIFIER old_id ;
510
	IDENTIFIER old_id;
487
    unsigned tag = TAG_type ( t ) ;
511
	unsigned tag = TAG_type(t);
488
    QUALIFIER cq = crt_id_qualifier ;
512
	QUALIFIER cq = crt_id_qualifier;
489
    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
513
	HASHID nm = DEREF_hashid(id_name(id));
490
 
514
 
491
    /* Can't have other declaration specifiers with typedef */
515
	/* Can't have other declaration specifiers with typedef */
492
    DECL_SPEC st = ( ds & dspec_keyword ) ;
516
	DECL_SPEC st = (ds & dspec_keyword);
493
    if ( st != dspec_typedef ) {
517
	if (st != dspec_typedef) {
494
	st &= ~dspec_typedef ;
518
		st &= ~dspec_typedef;
495
	report ( crt_loc, ERR_dcl_typedef_dspec ( st ) ) ;
519
		report(crt_loc, ERR_dcl_typedef_dspec(st));
496
    }
520
	}
497
 
521
 
498
    /* Check for function cv-qualifiers and exception specifiers */
522
	/* Check for function cv-qualifiers and exception specifiers */
499
    object_type ( t, id_type_alias_tag ) ;
523
	object_type(t, id_type_alias_tag);
500
 
524
 
501
    /* Check for previous declaration */
525
	/* Check for previous declaration */
502
    if ( IS_NULL_member ( mem ) ) {
526
	if (IS_NULL_member(mem)) {
503
	mem = search_member ( ns, nm, 1 ) ;
527
		mem = search_member(ns, nm, 1);
504
	old_id = DEREF_id ( member_id ( mem ) ) ;
528
		old_id = DEREF_id(member_id(mem));
505
	old_id = redecl_inherit ( old_id, cq, in_class_defn, 2 ) ;
529
		old_id = redecl_inherit(old_id, cq, in_class_defn, 2);
506
	if ( IS_NULL_id ( old_id ) ) {
530
		if (IS_NULL_id(old_id)) {
507
	    report ( crt_loc, ERR_lookup_qual_undef ( nm, ns ) ) ;
531
			report(crt_loc, ERR_lookup_qual_undef(nm, ns));
508
	}
532
		}
509
    } else {
533
	} else {
510
	old_id = DEREF_id ( member_id ( mem ) ) ;
534
		old_id = DEREF_id(member_id(mem));
511
	old_id = redecl_inherit ( old_id, cq, in_class_defn, 2 ) ;
535
		old_id = redecl_inherit(old_id, cq, in_class_defn, 2);
512
    }
536
	}
513
 
537
 
514
    /* Allow for type redeclarations */
538
	/* Allow for type redeclarations */
515
#if LANGUAGE_CPP
539
#if LANGUAGE_CPP
516
    id = type_member ( mem, 3 ) ;
540
	id = type_member(mem, 3);
517
    id = redecl_inherit ( id, cq, in_class_defn, 2 ) ;
541
	id = redecl_inherit(id, cq, in_class_defn, 2);
518
#else
542
#else
519
    id = old_id ;
543
	id = old_id;
520
#endif
544
#endif
521
    if ( !IS_NULL_id ( id ) && IS_id_class_name_etc ( id ) ) {
545
	if (!IS_NULL_id(id) && IS_id_class_name_etc(id)) {
522
	/* Already declared as a type name */
546
		/* Already declared as a type name */
523
	TYPE s ;
547
		TYPE s;
524
	ERROR err = NULL_err ;
548
		ERROR err = NULL_err;
525
	PTR ( LOCATION ) loc = id_loc ( id ) ;
549
		PTR(LOCATION)loc = id_loc(id);
526
	unsigned long tokdefs = no_token_defns ;
550
		unsigned long tokdefs = no_token_defns;
527
 
551
 
528
	/* Check for reserved identifiers */
552
		/* Check for reserved identifiers */
529
	DECL_SPEC ods = DEREF_dspec ( id_storage ( id ) ) ;
553
		DECL_SPEC ods = DEREF_dspec(id_storage(id));
530
	if ( ( ds | ods ) & dspec_reserve ) {
554
		if ((ds | ods) & dspec_reserve) {
531
	    report ( crt_loc, ERR_basic_odr_decl ( id, loc ) ) ;
555
			report(crt_loc, ERR_basic_odr_decl(id, loc));
532
	    return ( id ) ;
556
			return (id);
533
	}
557
		}
534
 
558
 
535
	/* Check type compatibility */
559
		/* Check type compatibility */
536
	s = DEREF_type ( id_class_name_etc_defn ( id ) ) ;
560
		s = DEREF_type(id_class_name_etc_defn(id));
537
	s = check_compatible ( s, t, 0, &err, 1 ) ;
561
		s = check_compatible(s, t, 0, &err, 1);
538
	/* QUERY: or is type equality required? */
562
		/* QUERY: or is type equality required? */
-
 
563
 
-
 
564
		/* Compatible redefinition */
-
 
565
		if (IS_NULL_err(err)) {
-
 
566
			NAMESPACE cns = crt_namespace;
-
 
567
			if (cq != qual_none) {
-
 
568
				/* Check qualified definitions */
-
 
569
				check_decl_nspace(id, ns, 1, cns);
-
 
570
			}
-
 
571
			if (in_class_defn && EQ_nspace(ns, cns)) {
-
 
572
				if (!is_tagged_type(id)) {
-
 
573
					/* Still not allowed in a class
-
 
574
					 * definition */
-
 
575
					report(crt_loc,
-
 
576
					       ERR_class_mem_redecl(id, loc));
-
 
577
				}
-
 
578
			} else if (tokdefs == no_token_defns &&
-
 
579
				   !in_pragma_dir) {
-
 
580
				/* Can't redeclare types in C */
-
 
581
				report(crt_loc, ERR_basic_odr_typedef(id, loc));
-
 
582
			}
-
 
583
			if (tag == type_func_tag) {
-
 
584
				/* Check function types */
-
 
585
				s = redecl_func_type(id, s, t, 0, 1);
-
 
586
			}
-
 
587
			COPY_type(id_class_name_etc_defn(id), s);
-
 
588
			adjust_access(id, crt_access, 0);
-
 
589
			return (id);
-
 
590
		}
-
 
591
 
-
 
592
		/* Incompatible redefinition */
-
 
593
		err = concat_error(err, ERR_basic_link_typedef(id, loc));
-
 
594
		report(crt_loc, err);
-
 
595
		reported = 1;
-
 
596
	}
539
 
597
 
540
	/* Compatible redefinition */
598
	/* Declare the type */
541
	if ( IS_NULL_err ( err ) ) {
-
 
542
	    NAMESPACE cns = crt_namespace ;
599
	id = make_typedef(ns, nm, t, dspec_none);
543
	    if ( cq != qual_none ) {
600
	if (is_tagged_type(id)) {
544
		/* Check qualified definitions */
601
		/* Class-like typedef-names */
545
		check_decl_nspace ( id, ns, 1, cns ) ;
602
		set_type_member(mem, id);
546
	    }
603
	} else {
547
	    if ( in_class_defn && EQ_nspace ( ns, cns ) ) {
604
		/* Object-like typedef-names */
548
		if ( !is_tagged_type ( id ) ) {
605
		if (!IS_NULL_id(old_id) && !reported) {
549
		    /* Still not allowed in a class definition */
606
			/* Already declared as an object */
-
 
607
			PTR(LOCATION)loc = id_loc(old_id);
550
		    report ( crt_loc, ERR_class_mem_redecl ( id, loc ) ) ;
608
			report(crt_loc, ERR_basic_odr_diff(old_id, loc));
551
		}
609
		}
552
	    } else if ( tokdefs == no_token_defns && !in_pragma_dir ) {
-
 
553
		/* Can't redeclare types in C */
-
 
554
		report ( crt_loc, ERR_basic_odr_typedef ( id, loc ) ) ;
-
 
555
	    }
-
 
556
	    if ( tag == type_func_tag ) {
-
 
557
		/* Check function types */
-
 
558
		s = redecl_func_type ( id, s, t, 0, 1 ) ;
-
 
559
	    }
-
 
560
	    COPY_type ( id_class_name_etc_defn ( id ), s ) ;
-
 
561
	    adjust_access ( id, crt_access, 0 ) ;
-
 
562
	    return ( id ) ;
610
		set_member(mem, id);
563
	}
611
	}
564
 
-
 
565
	/* Incompatible redefinition */
612
	if (tag == type_func_tag) {
566
	err = concat_error ( err, ERR_basic_link_typedef ( id, loc ) ) ;
-
 
567
	report ( crt_loc, err ) ;
-
 
568
	reported = 1 ;
-
 
569
    }
-
 
570
 
-
 
571
    /* Declare the type */
613
		/* Check function type */
572
    id = make_typedef ( ns, nm, t, dspec_none ) ;
614
		decl_func_type(id, t, 0);
573
    if ( is_tagged_type ( id ) ) {
615
	} else if (tag == type_templ_tag) {
574
	/* Class-like typedef-names */
-
 
575
	set_type_member ( mem, id ) ;
616
		IGNORE check_templ_params(t, id);
576
    } else {
-
 
577
	/* Object-like typedef-names */
-
 
578
	if ( !IS_NULL_id ( old_id ) && !reported ) {
-
 
579
	    /* Already declared as an object */
-
 
580
	    PTR ( LOCATION ) loc = id_loc ( old_id ) ;
-
 
581
	    report ( crt_loc, ERR_basic_odr_diff ( old_id, loc ) ) ;
617
		report(crt_loc, ERR_temp_decl_bad());
582
	}
618
	}
583
	set_member ( mem, id ) ;
-
 
584
    }
-
 
585
    if ( tag == type_func_tag ) {
-
 
586
	/* Check function type */
-
 
587
	decl_func_type ( id, t, 0 ) ;
-
 
588
    } else if ( tag == type_templ_tag ) {
-
 
589
	IGNORE check_templ_params ( t, id ) ;
-
 
590
	report ( crt_loc, ERR_temp_decl_bad () ) ;
-
 
591
    }
-
 
592
    return ( id ) ;
619
	return (id);
593
}
620
}
594
 
621
 
595
 
622
 
596
/*
623
/*
597
    CREATE A SPECIAL TYPE DEFINITION
624
    CREATE A SPECIAL TYPE DEFINITION
598
 
625
 
599
    This routine creates a typedef of the identifier id to the special
626
    This routine creates a typedef of the identifier id to the special
600
    type t.
627
    type t.
601
*/
628
*/
602
 
629
 
603
void typedef_special
630
void
604
    PROTO_N ( ( id, t ) )
-
 
605
    PROTO_T ( IDENTIFIER id X TYPE t )
631
typedef_special(IDENTIFIER id, TYPE t)
606
{
632
{
607
    int pushed = 0 ;
633
	int pushed = 0;
608
    NAMESPACE ns = nonblock_namespace ;
634
	NAMESPACE ns = nonblock_namespace;
609
    if ( !EQ_nspace ( ns, crt_namespace ) ) {
635
	if (!EQ_nspace(ns, crt_namespace)) {
610
	push_namespace ( ns ) ;
636
		push_namespace(ns);
611
	pushed = 1 ;
637
		pushed = 1;
612
    }
638
	}
613
    decl_loc = preproc_loc ;
639
	decl_loc = preproc_loc;
614
    if ( in_class_defn ) {
640
	if (in_class_defn) {
615
	id = make_member_decl ( dspec_typedef, t, id, 0 ) ;
641
		id = make_member_decl(dspec_typedef, t, id, 0);
616
    } else {
642
	} else {
617
	id = make_object_decl ( dspec_typedef, t, id, 0 ) ;
643
		id = make_object_decl(dspec_typedef, t, id, 0);
618
    }
644
	}
-
 
645
	if (do_dump) {
619
    if ( do_dump ) dump_declare ( id, &decl_loc, 1 ) ;
646
		dump_declare(id, &decl_loc, 1);
-
 
647
	}
620
    if ( pushed ) {
648
	if (pushed) {
621
	IGNORE pop_namespace () ;
649
		IGNORE pop_namespace();
622
    }
650
	}
623
    return ;
651
	return;
624
}
652
}
625
 
653
 
626
 
654
 
627
/*
655
/*
628
    FIND THE LINKAGE OF AN IDENTIFIER
656
    FIND THE LINKAGE OF AN IDENTIFIER
Line 630... Line 658...
630
    This routine finds the linkage of the identifier id (including the
658
    This routine finds the linkage of the identifier id (including the
631
    language specifier), returning the default value st if id does not
659
    language specifier), returning the default value st if id does not
632
    represent an object or function.
660
    represent an object or function.
633
*/
661
*/
634
 
662
 
635
static DECL_SPEC find_storage
663
static DECL_SPEC
636
    PROTO_N ( ( id, st, t ) )
-
 
637
    PROTO_T ( IDENTIFIER id X DECL_SPEC st X TYPE t )
664
find_storage(IDENTIFIER id, DECL_SPEC st, TYPE t)
638
{
665
{
639
    if ( !IS_NULL_id ( id ) ) {
666
	if (!IS_NULL_id(id)) {
640
	switch ( TAG_id ( id ) ) {
667
		switch (TAG_id(id)) {
641
	    case id_variable_tag :
668
		case id_variable_tag:
642
	    case id_parameter_tag :
669
		case id_parameter_tag:
643
	    case id_stat_member_tag :
670
		case id_stat_member_tag:
644
	    case id_weak_param_tag : {
671
		case id_weak_param_tag: {
645
		/* Objects */
672
			/* Objects */
646
		DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
673
			DECL_SPEC ds = DEREF_dspec(id_storage(id));
647
		st = ( ds & ( dspec_storage | dspec_language ) ) ;
674
			st = (ds & (dspec_storage | dspec_language));
648
		break ;
675
			break;
649
	    }
676
		}
650
	    case id_function_tag :
677
		case id_function_tag:
651
	    case id_mem_func_tag :
678
		case id_mem_func_tag:
652
	    case id_stat_mem_func_tag : {
679
		case id_stat_mem_func_tag: {
653
		/* Functions */
680
			/* Functions */
654
		DECL_SPEC ds ;
681
			DECL_SPEC ds;
655
#if LANGUAGE_CPP
682
#if LANGUAGE_CPP
656
		LIST ( IDENTIFIER ) pids = NULL_list ( IDENTIFIER ) ;
683
			LIST(IDENTIFIER)pids = NULL_list(IDENTIFIER);
657
		if ( !IS_NULL_type ( t ) ) {
684
			if (!IS_NULL_type(t)) {
658
		    int eq = 0 ;
685
				int eq = 0;
659
		    id = resolve_func ( id, t, 0, 0, pids, &eq ) ;
686
				id = resolve_func(id, t, 0, 0, pids, &eq);
-
 
687
				if (IS_NULL_id(id) ||
660
		    if ( IS_NULL_id ( id ) || !IS_id_function_etc ( id ) ) {
688
				    !IS_id_function_etc(id)) {
661
			return ( st ) ;
689
					return (st);
662
		    }
690
				}
663
		}
691
			}
664
#else
692
#else
665
		UNUSED ( t ) ;
693
			UNUSED(t);
666
#endif
694
#endif
667
		ds = DEREF_dspec ( id_storage ( id ) ) ;
695
			ds = DEREF_dspec(id_storage(id));
668
		st = ( ds & ( dspec_storage | dspec_language ) ) ;
696
			st = (ds & (dspec_storage | dspec_language));
669
		break ;
697
			break;
670
	    }
698
		}
-
 
699
		}
671
	}
700
	}
672
    }
-
 
673
    return ( st ) ;
701
	return (st);
674
}
702
}
675
 
703
 
676
 
704
 
677
/*
705
/*
678
    CHECK THE LOCATION OF A DECLARATION
706
    CHECK THE LOCATION OF A DECLARATION
Line 680... Line 708...
680
    This routine checks whether the namespace cns is a suitable location
708
    This routine checks whether the namespace cns is a suitable location
681
    for redeclaring the object id, which is a member of the namespace ns.
709
    for redeclaring the object id, which is a member of the namespace ns.
682
    def is true for a definition.
710
    def is true for a definition.
683
*/
711
*/
684
 
712
 
685
void check_decl_nspace
713
void
686
    PROTO_N ( ( id, ns, def, cns ) )
-
 
687
    PROTO_T ( IDENTIFIER id X NAMESPACE ns X int def X NAMESPACE cns )
714
check_decl_nspace(IDENTIFIER id, NAMESPACE ns, int def, NAMESPACE cns)
688
{
715
{
689
    int func = 0 ;
716
	int func = 0;
690
    int local_def = really_in_function_defn ;
717
	int local_def = really_in_function_defn;
691
    switch ( TAG_id ( id ) ) {
718
	switch (TAG_id(id)) {
692
	case id_class_name_tag :
719
	case id_class_name_tag:
693
	case id_enum_name_tag :
720
	case id_enum_name_tag:
694
	case id_class_alias_tag :
721
	case id_class_alias_tag:
695
	case id_enum_alias_tag :
722
	case id_enum_alias_tag:
696
	case id_type_alias_tag : {
723
	case id_type_alias_tag: {
697
	    /* Can define local types */
724
		/* Can define local types */
698
	    local_def = 0 ;
725
		local_def = 0;
699
	    break ;
726
		break;
700
	}
727
	}
701
	case id_mem_func_tag :
728
	case id_mem_func_tag:
702
	case id_stat_mem_func_tag : {
729
	case id_stat_mem_func_tag: {
703
	    /* Member function */
730
		/* Member function */
704
	    DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
731
		DECL_SPEC ds = DEREF_dspec(id_storage(id));
705
	    if ( ds & dspec_implicit ) {
732
		if (ds & dspec_implicit) {
706
		/* Ignore implicit constructors etc */
733
			/* Ignore implicit constructors etc */
707
		return ;
734
			return;
708
	    }
735
		}
709
	    if ( !def && !is_templ_nspace ( ns ) ) {
736
		if (!def && !is_templ_nspace(ns)) {
710
		/* Can't even redeclare in this case */
737
			/* Can't even redeclare in this case */
711
		report ( crt_loc, ERR_class_mfct_redecl ( id ) ) ;
738
			report(crt_loc, ERR_class_mfct_redecl(id));
712
		return ;
739
			return;
713
	    }
740
		}
714
	    func = 1 ;
741
		func = 1;
715
	    break ;
742
		break;
-
 
743
	}
-
 
744
	case id_undef_tag: {
-
 
745
		/* Report undeclared members */
-
 
746
		HASHID nm = DEREF_hashid(id_name(id));
-
 
747
		report(crt_loc, ERR_lookup_qual_undef(nm, ns));
-
 
748
		return;
716
	}
749
	}
717
	case id_undef_tag : {
-
 
718
	    /* Report undeclared members */
-
 
719
	    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
-
 
720
	    report ( crt_loc, ERR_lookup_qual_undef ( nm, ns ) ) ;
-
 
721
	    return ;
-
 
722
	}
750
	}
723
    }
-
 
724
 
751
 
725
    if ( def ) {
752
	if (def) {
726
	/* Check for enclosing namespace scope */
753
		/* Check for enclosing namespace scope */
727
	if ( local_def || !is_subnspace ( cns, ns ) ) {
754
		if (local_def || !is_subnspace(cns, ns)) {
728
	    /* Report badly placed definition */
755
			/* Report badly placed definition */
729
	    ERROR err ;
756
			ERROR err;
730
	    if ( IS_nspace_ctype ( ns ) ) {
757
			if (IS_nspace_ctype(ns)) {
731
		if ( func ) {
758
				if (func) {
732
		    /* Member functions */
759
					/* Member functions */
733
		    err = ERR_class_mfct_scope ( id ) ;
760
					err = ERR_class_mfct_scope(id);
734
		} else {
761
				} else {
735
		    /* Other class members */
762
					/* Other class members */
736
		    err = ERR_class_static_data_scope ( id ) ;
763
					err = ERR_class_static_data_scope(id);
-
 
764
				}
-
 
765
			} else {
-
 
766
				/* Namespace members */
-
 
767
				err = ERR_dcl_nspace_memdef_scope(id);
-
 
768
			}
-
 
769
			report(crt_loc, err);
737
		}
770
		}
738
	    } else {
-
 
739
		/* Namespace members */
-
 
740
		err = ERR_dcl_nspace_memdef_scope ( id ) ;
-
 
741
	    }
-
 
742
	    report ( crt_loc, err ) ;
-
 
743
	}
771
	}
744
    }
-
 
745
    return ;
772
	return;
746
}
773
}
747
 
774
 
748
 
775
 
749
/*
776
/*
750
    CHECK AN OBJECT TYPE
777
    CHECK AN OBJECT TYPE
751
 
778
 
752
    This routine checks the type t for the object id with declaration
779
    This routine checks the type t for the object id with declaration
753
    specifiers ds.
780
    specifiers ds.
754
*/
781
*/
755
 
782
 
756
void check_obj_decl
783
void
757
    PROTO_N ( ( ds, t, id, tentative ) )
-
 
758
    PROTO_T ( DECL_SPEC ds X TYPE t X IDENTIFIER id X int tentative )
784
check_obj_decl(DECL_SPEC ds, TYPE t, IDENTIFIER id, int tentative)
759
{
785
{
760
    unsigned tag = TAG_type ( t ) ;
786
	unsigned tag = TAG_type(t);
761
    if ( tag == type_top_tag || tag == type_bottom_tag ) {
787
	if (tag == type_top_tag || tag == type_bottom_tag) {
762
	/* Always report void declarations */
788
		/* Always report void declarations */
763
	report ( crt_loc, ERR_basic_fund_void_decl ( id, t ) ) ;
789
		report(crt_loc, ERR_basic_fund_void_decl(id, t));
764
    } else if ( tag == type_templ_tag ) {
790
	} else if (tag == type_templ_tag) {
765
	/* Shouldn't have template type */
791
		/* Shouldn't have template type */
766
	report ( crt_loc, ERR_temp_decl_bad () ) ;
792
		report(crt_loc, ERR_temp_decl_bad());
767
    } else if ( ds & dspec_defn ) {
793
	} else if (ds & dspec_defn) {
768
	/* Only check otherwise if this is a definition */
794
		/* Only check otherwise if this is a definition */
769
	if ( tag == type_array_tag ) {
795
		if (tag == type_array_tag) {
770
	    /* Arrays may be completed by the initialiser */
796
			/* Arrays may be completed by the initialiser */
771
	    /* EMPTY */
797
			/* EMPTY */
772
	} else if ( tag == type_ref_tag ) {
798
		} else if (tag == type_ref_tag) {
773
	    /* References don't need checking */
799
			/* References don't need checking */
774
	    /* EMPTY */
800
			/* EMPTY */
775
	} else {
801
		} else {
776
	    ERROR err ;
802
			ERROR err;
777
	    if ( !tentative ) {
803
			if (!tentative) {
778
		err = check_complete ( t ) ;
804
				err = check_complete(t);
779
		if ( !IS_NULL_err ( err ) ) {
805
				if (!IS_NULL_err(err)) {
780
		    /* Other definitions should have complete type */
806
					/* Other definitions should have
-
 
807
					 * complete type */
-
 
808
					ERROR err2 =
781
		    ERROR err2 = ERR_basic_types_def_incompl ( id ) ;
809
					    ERR_basic_types_def_incompl(id);
782
		    err = concat_error ( err, err2 ) ;
810
					err = concat_error(err, err2);
783
		    report ( crt_loc, err ) ;
811
					report(crt_loc, err);
784
		}
812
				}
785
	    }
813
			}
786
	    err = check_abstract ( t ) ;
814
			err = check_abstract(t);
787
	    if ( !IS_NULL_err ( err ) ) {
815
			if (!IS_NULL_err(err)) {
788
		/* Objects can't have abstract type */
816
				/* Objects can't have abstract type */
789
		ERROR err2 = ERR_class_abstract_decl ( id ) ;
817
				ERROR err2 = ERR_class_abstract_decl(id);
790
		err = concat_error ( err, err2 ) ;
818
				err = concat_error(err, err2);
791
		report ( crt_loc, err ) ;
819
				report(crt_loc, err);
792
	    }
820
			}
793
	}
821
		}
794
    }
822
	}
795
    return ;
823
	return;
796
}
824
}
797
 
825
 
798
 
826
 
799
/*
827
/*
800
    DECLARE AN OBJECT
828
    DECLARE AN OBJECT
801
 
829
 
802
    This routine constructs the declaration of an object with declaration
830
    This routine constructs the declaration of an object with declaration
803
    specifiers ds, type t and name id.
831
    specifiers ds, type t and name id.
804
*/
832
*/
805
 
833
 
806
IDENTIFIER make_object_decl
834
IDENTIFIER
807
    PROTO_N ( ( ds, t, id, def ) )
-
 
808
    PROTO_T ( DECL_SPEC ds X TYPE t X IDENTIFIER id X int def )
835
make_object_decl(DECL_SPEC ds, TYPE t, IDENTIFIER id, int def)
809
{
836
{
810
    ERROR err ;
837
	ERROR err;
811
    MEMBER mem ;
838
	MEMBER mem;
812
    NAMESPACE ns ;
839
	NAMESPACE ns;
813
    int redef = 0 ;
840
	int redef = 0;
814
    int simple_id = 1 ;
841
	int simple_id = 1;
815
    int tentative = 0 ;
842
	int tentative = 0;
816
    IDENTIFIER old_id ;
843
	IDENTIFIER old_id;
817
    IDENTIFIER alt_id ;
844
	IDENTIFIER alt_id;
818
    DECL_SPEC st, df, rs ;
845
	DECL_SPEC st, df, rs;
819
    IDENTIFIER prev_id = NULL_id ;
846
	IDENTIFIER prev_id = NULL_id;
820
    unsigned tag = TAG_type ( t ) ;
847
	unsigned tag = TAG_type(t);
821
    unsigned itag = id_variable_tag ;
848
	unsigned itag = id_variable_tag;
822
    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
849
	HASHID nm = DEREF_hashid(id_name(id));
823
 
850
 
824
    /* Check for template specialisations */
851
	/* Check for template specialisations */
825
    bound_specialise = 0 ;
852
	bound_specialise = 0;
826
    if ( is_templ_decl ( id, NULL_type ) || is_templ_spec ( t ) ) {
853
	if (is_templ_decl(id, NULL_type) || is_templ_spec(t)) {
827
	t = bind_specialise ( &id, t, ds, 0, 1, def ) ;
854
		t = bind_specialise(&id, t, ds, 0, 1, def);
828
	if ( IS_NULL_id ( id ) ) {
855
		if (IS_NULL_id(id)) {
829
	    /* Invalid specialisation */
856
			/* Invalid specialisation */
830
	    crt_id_qualifier = qual_none ;
857
			crt_id_qualifier = qual_none;
831
	    crt_templ_qualifier = 0 ;
858
			crt_templ_qualifier = 0;
832
	    id = DEREF_id ( hashid_id ( nm ) ) ;
859
			id = DEREF_id(hashid_id(nm));
833
	    while ( IS_type_templ ( t ) ) {
860
			while (IS_type_templ(t)) {
834
		t = DEREF_type ( type_templ_defn ( t ) ) ;
861
				t = DEREF_type(type_templ_defn(t));
835
	    }
862
			}
836
	    id = make_object_decl ( ds, t, id, def ) ;
863
			id = make_object_decl(ds, t, id, def);
837
	    return ( id ) ;
864
			return (id);
838
	}
865
		}
839
	ns = DEREF_nspace ( id_parent ( id ) ) ;
866
		ns = DEREF_nspace(id_parent(id));
840
	check_decl_nspace ( id, ns, 0, crt_namespace ) ;
867
		check_decl_nspace(id, ns, 0, crt_namespace);
841
	old_id = id ;
868
		old_id = id;
842
	mem = NULL_member ;
869
		mem = NULL_member;
843
	simple_id = 0 ;
870
		simple_id = 0;
-
 
871
	} else {
-
 
872
		/* Check on identifier name */
-
 
873
		QUALIFIER cq = crt_id_qualifier;
-
 
874
		err = check_id_name(id, CONTEXT_OBJECT);
-
 
875
		if (!IS_NULL_err(err)) {
-
 
876
			report(crt_loc, err);
-
 
877
		}
844
 
878
 
-
 
879
		/* Check for qualified identifiers */
-
 
880
		if (cq == qual_none) {
-
 
881
			/* Declaration of simple identifier */
-
 
882
			ns = crt_namespace;
-
 
883
			mem = search_member(ns, nm, 1);
-
 
884
			old_id = DEREF_id(member_id(mem));
-
 
885
			alt_id = DEREF_id(member_alt(mem));
-
 
886
			if (!IS_NULL_id(old_id)) {
-
 
887
				if (in_function_defn && (ds & dspec_extern)) {
-
 
888
					/* Redeclaration of block external */
-
 
889
					prev_id = find_previous(t, id);
-
 
890
					if (EQ_id(prev_id, old_id)) {
-
 
891
						old_id = NULL_id;
-
 
892
					}
845
    } else {
893
				} else {
-
 
894
					old_id = redecl_inherit(old_id, cq, 0,
-
 
895
								2);
-
 
896
				}
-
 
897
				redef = 1;
-
 
898
			} else if (!IS_NULL_id(alt_id)) {
-
 
899
				redef = 1;
-
 
900
			}
-
 
901
		} else {
-
 
902
			/* Redeclaration of class or namespace member */
-
 
903
			ns = DEREF_nspace(id_parent(id));
-
 
904
			check_decl_nspace(id, ns, 0, crt_namespace);
-
 
905
			if (IS_id_undef(id)) {
-
 
906
				if (IS_nspace_ctype(ns)) {
-
 
907
					itag = id_stat_member_tag;
-
 
908
				}
-
 
909
				mem = search_member(ns, nm, 1);
-
 
910
				old_id = NULL_id;
-
 
911
			} else {
-
 
912
				mem = NULL_member;
-
 
913
				old_id = redecl_inherit(id, cq, 0, 2);
-
 
914
				t = bind_specialise(&old_id, t, ds, 0, 0, def);
-
 
915
				if (!IS_NULL_id(old_id)) {
-
 
916
					id = old_id;
-
 
917
					itag = TAG_id(id);
-
 
918
					ns = DEREF_nspace(id_parent(id));
-
 
919
				}
-
 
920
			}
-
 
921
			simple_id = 0;
-
 
922
		}
-
 
923
	}
-
 
924
 
846
	/* Check on identifier name */
925
	/* Deal with inferred types */
-
 
926
	ds = check_inferred_type(ds, &t, 0);
-
 
927
 
-
 
928
	/* Check on storage class specifiers */
-
 
929
	st = check_storage(ds, CONTEXT_OBJECT, old_id);
-
 
930
 
-
 
931
	/* Deal with type definitions */
-
 
932
	if (ds & dspec_typedef) {
-
 
933
		id = make_type_decl(ns, ds, t, mem, id);
-
 
934
		return (id);
-
 
935
	}
-
 
936
 
847
	QUALIFIER cq = crt_id_qualifier ;
937
	/* Check on function specifiers */
848
	err = check_id_name ( id, CONTEXT_OBJECT ) ;
938
	IGNORE check_func_spec(ds, CONTEXT_OBJECT);
-
 
939
 
-
 
940
	/* Find the object linkage and whether it is a definition */
-
 
941
	if (st == dspec_extern) {
-
 
942
		/* Explicit extern indicates a declaration (probably) */
-
 
943
		df = dspec_none;
-
 
944
		if (in_function_defn && simple_id) {
-
 
945
			if (IS_NULL_id(prev_id)) {
-
 
946
				prev_id = find_previous(t, id);
-
 
947
			}
-
 
948
			st = find_storage(prev_id, st, NULL_type);
-
 
949
		} else {
-
 
950
			prev_id = old_id;
-
 
951
			st = find_storage(old_id, st, t);
-
 
952
		}
-
 
953
	} else {
849
	if ( !IS_NULL_err ( err ) ) report ( crt_loc, err ) ;
954
		if (tag == type_templ_tag && bound_specialise) {
-
 
955
			/* A template specialisation is a declaration
-
 
956
			 * (probably) */
-
 
957
			df = dspec_none;
-
 
958
		} else {
-
 
959
			/* Everything else is a definition */
-
 
960
			df = dspec_defn;
-
 
961
		}
-
 
962
		if (in_function_defn) {
-
 
963
			/* Objects declared in a block have no linkage */
-
 
964
			if (IS_NULL_member(mem)) {
-
 
965
				/* Use old linkage if explicitly qualified */
-
 
966
				st = find_storage(old_id, dspec_none, t);
-
 
967
			} else if (st == dspec_static) {
-
 
968
				st = dspec_none;
-
 
969
			} else if (st == dspec_register) {
-
 
970
				st = (dspec_auto | dspec_register);
-
 
971
				used_register = 1;
-
 
972
			} else {
-
 
973
				st = dspec_auto;
-
 
974
			}
-
 
975
		} else if (st == dspec_static) {
-
 
976
			/* Check static declarations */
-
 
977
			if (!def) {
-
 
978
				tentative = LANGUAGE_C;
-
 
979
			}
-
 
980
		} else if (st == dspec_none) {
-
 
981
			/* Objects declared const have internal linkage */
-
 
982
			CV_SPEC qual = find_cv_qual(t);
-
 
983
			if (qual & cv_const) {
-
 
984
				st = const_linkage;
-
 
985
				if (st & dspec_static) {
-
 
986
					st = find_storage(old_id, st, t);
-
 
987
				}
-
 
988
			} else {
-
 
989
				st = dspec_extern;
-
 
990
			}
-
 
991
			/* find_storage is not applied for objects */
-
 
992
			if (!def) {
-
 
993
				tentative = LANGUAGE_C;
-
 
994
			}
-
 
995
		}
-
 
996
	}
850
 
997
 
851
	/* Check for qualified identifiers */
998
	/* Create the declaration */
-
 
999
	t = lvalue_type(t);
-
 
1000
	rs = (ds & dspec_other);
-
 
1001
	ds = (st | df | rs);
852
	if ( cq == qual_none ) {
1002
	if (!IS_NULL_id(old_id)) {
-
 
1003
		/* Check redeclarations */
-
 
1004
		old_id = redecl_id(ds, t, old_id, 0, 0);
-
 
1005
		if (IS_NULL_id(old_id) && IS_NULL_member(mem)) {
853
	    /* Declaration of simple identifier */
1006
			/* Bad redeclaration of class or namespace member */
854
	    ns = crt_namespace ;
1007
			nm = lookup_anon();
855
	    mem = search_member ( ns, nm, 1 ) ;
1008
			mem = search_member(ns, nm, 1);
856
	    old_id = DEREF_id ( member_id ( mem ) ) ;
1009
			itag = id_stat_member_tag;
-
 
1010
		}
-
 
1011
	}
857
	    alt_id = DEREF_id ( member_alt ( mem ) ) ;
1012
	object_type(t, itag);
858
	    if ( !IS_NULL_id ( old_id ) ) {
1013
	if (IS_NULL_id(old_id)) {
-
 
1014
		/* Construct the declaration */
-
 
1015
		ds = adjust_linkage(ds, 0);
-
 
1016
		MAKE_id_variable_etc(itag, nm, ds, ns, decl_loc, t, id);
859
		if ( in_function_defn && ( ds & dspec_extern ) ) {
1017
		if (in_function_defn) {
-
 
1018
			if (ds & dspec_linkage) {
860
		    /* Redeclaration of block external */
1019
				/* Block function declarations */
861
		    prev_id = find_previous ( t, id ) ;
1020
				id = unify_previous(id, t, prev_id, 0);
862
		    if ( EQ_id ( prev_id, old_id ) ) old_id = NULL_id ;
1021
			} else if (redef && (ds & dspec_auto)) {
-
 
1022
				/* Redeclarations of local variables */
-
 
1023
				mem = update_member(ns, mem);
-
 
1024
			}
863
		} else {
1025
		} else {
864
		    old_id = redecl_inherit ( old_id, cq, 0, 2 ) ;
-
 
865
		}
-
 
866
		redef = 1 ;
-
 
867
	    } else if ( !IS_NULL_id ( alt_id ) ) {
-
 
868
		redef = 1 ;
-
 
869
	    }
-
 
870
	} else {
-
 
871
	    /* Redeclaration of class or namespace member */
-
 
872
	    ns = DEREF_nspace ( id_parent ( id ) ) ;
-
 
873
	    check_decl_nspace ( id, ns, 0, crt_namespace ) ;
-
 
874
	    if ( IS_id_undef ( id ) ) {
-
 
875
		if ( IS_nspace_ctype ( ns ) ) itag = id_stat_member_tag ;
-
 
876
		mem = search_member ( ns, nm, 1 ) ;
-
 
877
		old_id = NULL_id ;
-
 
878
	    } else {
-
 
879
		mem = NULL_member ;
-
 
880
		old_id = redecl_inherit ( id, cq, 0, 2 ) ;
1026
			id = unify_subsequent(id, t, 0);
881
		t = bind_specialise ( &old_id, t, ds, 0, 0, def ) ;
-
 
882
		if ( !IS_NULL_id ( old_id ) ) {
-
 
883
		    id = old_id ;
-
 
884
		    itag = TAG_id ( id ) ;
-
 
885
		    ns = DEREF_nspace ( id_parent ( id ) ) ;
-
 
886
		}
1027
		}
887
	    }
-
 
888
	    simple_id = 0 ;
-
 
889
	}
-
 
890
    }
-
 
891
 
-
 
892
    /* Deal with inferred types */
-
 
893
    ds = check_inferred_type ( ds, &t, 0 ) ;
-
 
894
 
-
 
895
    /* Check on storage class specifiers */
-
 
896
    st = check_storage ( ds, CONTEXT_OBJECT, old_id ) ;
-
 
897
 
-
 
898
    /* Deal with type definitions */
-
 
899
    if ( ds & dspec_typedef ) {
-
 
900
	id = make_type_decl ( ns, ds, t, mem, id ) ;
-
 
901
	return ( id ) ;
1028
		set_member(mem, id);
902
    }
-
 
903
 
-
 
904
    /* Check on function specifiers */
-
 
905
    IGNORE check_func_spec ( ds, CONTEXT_OBJECT ) ;
-
 
906
 
-
 
907
    /* Find the object linkage and whether it is a definition */
-
 
908
    if ( st == dspec_extern ) {
-
 
909
	/* Explicit extern indicates a declaration (probably) */
-
 
910
	df = dspec_none ;
-
 
911
	if ( in_function_defn && simple_id ) {
1029
		if (itag == id_variable_tag && option(OPT_decl_hide)) {
912
	    if ( IS_NULL_id ( prev_id ) ) {
-
 
913
		prev_id = find_previous ( t, id ) ;
-
 
914
	    }
-
 
915
	    st = find_storage ( prev_id, st, NULL_type ) ;
-
 
916
	} else {
-
 
917
	    prev_id = old_id ;
1030
			check_hiding(id);
918
	    st = find_storage ( old_id, st, t ) ;
-
 
919
	}
1031
		}
920
    } else {
-
 
921
	if ( tag == type_templ_tag && bound_specialise ) {
-
 
922
	    /* A template specialisation is a declaration (probably) */
-
 
923
	    df = dspec_none ;
1032
		is_redeclared = 0;
924
	} else {
1033
	} else {
925
	    /* Everything else is a definition */
1034
		/* Redeclare an existing object */
926
	    df = dspec_defn ;
1035
		id = old_id;
927
	}
-
 
928
	if ( in_function_defn ) {
-
 
929
	    /* Objects declared in a block have no linkage */
-
 
930
	    if ( IS_NULL_member ( mem ) ) {
1036
		if (IS_id_member(id)) {
931
		/* Use old linkage if explicitly qualified */
-
 
932
		st = find_storage ( old_id, dspec_none, t ) ;
1037
			t = DEREF_type(id_member_type(id));
933
	    } else if ( st == dspec_static ) {
-
 
934
		st = dspec_none ;
-
 
935
	    } else if ( st == dspec_register ) {
-
 
936
		st = ( dspec_auto | dspec_register ) ;
-
 
937
		used_register = 1 ;
-
 
938
	    } else {
1038
		} else {
939
		st = dspec_auto ;
-
 
940
	    }
-
 
941
	} else if ( st == dspec_static ) {
-
 
942
	    /* Check static declarations */
-
 
943
	    if ( !def ) tentative = LANGUAGE_C ;
-
 
944
	} else if ( st == dspec_none ) {
-
 
945
	    /* Objects declared const have internal linkage */
-
 
946
	    CV_SPEC qual = find_cv_qual ( t ) ;
-
 
947
	    if ( qual & cv_const ) {
-
 
948
		st = const_linkage ;
-
 
949
		if ( st & dspec_static ) {
-
 
950
		    st = find_storage ( old_id, st, t ) ;
1039
			t = DEREF_type(id_variable_etc_type(id));
951
		}
1040
		}
952
	    } else {
-
 
953
		st = dspec_extern ;
-
 
954
	    }
-
 
955
	    /* find_storage is not applied for objects */
-
 
956
	    if ( !def ) tentative = LANGUAGE_C ;
-
 
957
	}
-
 
958
    }
-
 
959
 
-
 
960
    /* Create the declaration */
-
 
961
    t = lvalue_type ( t ) ;
-
 
962
    rs = ( ds & dspec_other ) ;
1041
		ds = DEREF_dspec(id_storage(id));
963
    ds = ( st | df | rs ) ;
-
 
964
    if ( !IS_NULL_id ( old_id ) ) {
-
 
965
	/* Check redeclarations */
1042
		is_redeclared = 1;
966
	old_id = redecl_id ( ds, t, old_id, 0, 0 ) ;
-
 
967
	if ( IS_NULL_id ( old_id ) && IS_NULL_member ( mem ) ) {
-
 
968
	    /* Bad redeclaration of class or namespace member */
-
 
969
	    nm = lookup_anon () ;
-
 
970
	    mem = search_member ( ns, nm, 1 ) ;
-
 
971
	    itag = id_stat_member_tag ;
-
 
972
	}
-
 
973
    }
-
 
974
    object_type ( t, itag ) ;
-
 
975
    if ( IS_NULL_id ( old_id ) ) {
-
 
976
	/* Construct the declaration */
-
 
977
	ds = adjust_linkage ( ds, 0 ) ;
-
 
978
	MAKE_id_variable_etc ( itag, nm, ds, ns, decl_loc, t, id ) ;
-
 
979
	if ( in_function_defn ) {
-
 
980
	    if ( ds & dspec_linkage ) {
-
 
981
		/* Block function declarations */
-
 
982
		id = unify_previous ( id, t, prev_id, 0 ) ;
-
 
983
	    } else if ( redef && ( ds & dspec_auto ) ) {
-
 
984
		/* Redeclarations of local variables */
-
 
985
		mem = update_member ( ns, mem ) ;
-
 
986
	    }
-
 
987
	} else {
-
 
988
	    id = unify_subsequent ( id, t, 0 ) ;
-
 
989
	}
1043
	}
990
	set_member ( mem, id ) ;
1044
#if LANGUAGE_CPP
991
	if ( itag == id_variable_tag && option ( OPT_decl_hide ) ) {
1045
	if (ds & dspec_c) {
992
	    check_hiding ( id ) ;
1046
		c_linkage(id, 0);
993
	}
1047
	}
994
	is_redeclared = 0 ;
-
 
995
    } else {
-
 
996
	/* Redeclare an existing object */
-
 
997
	id = old_id ;
-
 
998
	if ( IS_id_member ( id ) ) {
-
 
999
	    t = DEREF_type ( id_member_type ( id ) ) ;
-
 
1000
	} else {
-
 
1001
	    t = DEREF_type ( id_variable_etc_type ( id ) ) ;
-
 
1002
	}
-
 
1003
	ds = DEREF_dspec ( id_storage ( id ) ) ;
-
 
1004
	is_redeclared = 1 ;
-
 
1005
    }
-
 
1006
#if LANGUAGE_CPP
-
 
1007
    if ( ds & dspec_c ) c_linkage ( id, 0 ) ;
-
 
1008
#endif
1048
#endif
1009
    check_obj_decl ( ds, t, id, tentative ) ;
1049
	check_obj_decl(ds, t, id, tentative);
1010
    return ( id ) ;
1050
	return (id);
1011
}
1051
}
1012
 
1052
 
1013
 
1053
 
1014
/*
1054
/*
1015
    DECLARE A FUNCTION
1055
    DECLARE A FUNCTION
1016
 
1056
 
1017
    This routine constructs a function declaration for a function with
1057
    This routine constructs a function declaration for a function with
1018
    declaration specifiers ds, type t and name id.  The argument def is
1058
    declaration specifiers ds, type t and name id.  The argument def is
1019
    true to distinguish function definitions from function declarations.
1059
    true to distinguish function definitions from function declarations.
1266
	}
1336
	}
1267
	set_member ( mem, id ) ;
1337
#endif
1268
	decl_func_type ( id, t, def ) ;
-
 
1269
 
1338
 
1270
	/* Check for conversion functions */
1339
	/* Allow for discarded functions */
1271
	if ( it == hashid_conv_tag && itag != id_mem_func_tag ) {
1340
	if (!(rs & dspec_ignore) && option(OPT_discard_func)) {
1272
	    report ( crt_loc, ERR_class_conv_fct_mem () ) ;
1341
		ds &= ~dspec_ignore;
1273
	}
-
 
1274
	if ( itag == id_function_tag && option ( OPT_decl_hide ) ) {
-
 
1275
	    check_hiding ( id ) ;
1342
		COPY_dspec(id_storage(id), ds);
1276
	}
1343
	}
1277
	is_redeclared = 0 ;
-
 
1278
    } else {
-
 
1279
	/* Redeclare the function */
-
 
1280
	id = old_id ;
-
 
1281
	is_redeclared = 1 ;
-
 
1282
    }
-
 
1283
    ds = DEREF_dspec ( id_storage ( id ) ) ;
-
 
1284
#if LANGUAGE_CPP
1344
#if LANGUAGE_CPP
-
 
1345
	if (allocator) {
1285
    if ( ds & dspec_c ) c_linkage ( id, def ) ;
1346
		recheck_allocator(id, allocator);
-
 
1347
	}
1286
#endif
1348
#endif
1287
 
-
 
1288
    /* Allow for discarded functions */
-
 
1289
    if ( !( rs & dspec_ignore ) && option ( OPT_discard_func ) ) {
-
 
1290
	ds &= ~dspec_ignore ;
-
 
1291
	COPY_dspec ( id_storage ( id ), ds ) ;
-
 
1292
    }
-
 
1293
#if LANGUAGE_CPP
-
 
1294
    if ( allocator ) recheck_allocator ( id, allocator ) ;
-
 
1295
#endif
-
 
1296
    if ( main_func ) recheck_main ( id ) ;
-
 
1297
    return ( id ) ;
1349
	if (main_func) {
1298
}
-
 
1299
 
-
 
1300
 
-
 
1301
/*
-
 
1302
    CHECK A PARAMETER DECLARATION
-
 
1303
 
-
 
1304
    This routine checks the type of the parameter id declared with type t.
-
 
1305
*/
-
 
1306
 
-
 
1307
void check_par_decl
1350
		recheck_main(id);
1308
    PROTO_N ( ( t, id, loc ) )
-
 
1309
    PROTO_T ( TYPE t X IDENTIFIER id X int loc )
-
 
1310
{
-
 
1311
    unsigned tag = TAG_type ( t ) ;
-
 
1312
    if ( tag == type_compound_tag ) {
-
 
1313
	/* Parameters can't have abstract type */
-
 
1314
	ERROR err = check_abstract ( t ) ;
-
 
1315
	if ( !IS_NULL_err ( err ) ) {
-
 
1316
	    err = concat_error ( err, ERR_class_abstract_par () ) ;
-
 
1317
	    report ( crt_loc, err ) ;
-
 
1318
	}
1351
	}
1319
    } else if ( tag == type_templ_tag ) {
-
 
1320
	/* Shouldn't have template type */
-
 
1321
	report ( crt_loc, ERR_temp_decl_bad () ) ;
-
 
1322
    }
-
 
1323
    if ( loc == CONTEXT_WEAK_PARAM ) {
-
 
1324
	/* Check for 'void' and other types */
-
 
1325
	ERROR err = check_param_type ( id, t ) ;
-
 
1326
	if ( !IS_NULL_err ( err ) ) report ( crt_loc, err ) ;
-
 
1327
    }
-
 
1328
    return ;
1352
	return (id);
1329
}
1353
}
1330
 
1354
 
1331
 
1355
 
1332
/*
1356
/*
-
 
1357
    CHECK A PARAMETER DECLARATION
-
 
1358
 
-
 
1359
    This routine checks the type of the parameter id declared with type t.
-
 
1360
*/
-
 
1361
 
-
 
1362
void
-
 
1363
check_par_decl(TYPE t, IDENTIFIER id, int loc)
-
 
1364
{
-
 
1365
	unsigned tag = TAG_type(t);
-
 
1366
	if (tag == type_compound_tag) {
-
 
1367
		/* Parameters can't have abstract type */
-
 
1368
		ERROR err = check_abstract(t);
-
 
1369
		if (!IS_NULL_err(err)) {
-
 
1370
			err = concat_error(err, ERR_class_abstract_par());
-
 
1371
			report(crt_loc, err);
-
 
1372
		}
-
 
1373
	} else if (tag == type_templ_tag) {
-
 
1374
		/* Shouldn't have template type */
-
 
1375
		report(crt_loc, ERR_temp_decl_bad());
-
 
1376
	}
-
 
1377
	if (loc == CONTEXT_WEAK_PARAM) {
-
 
1378
		/* Check for 'void' and other types */
-
 
1379
		ERROR err = check_param_type(id, t);
-
 
1380
		if (!IS_NULL_err(err)) {
-
 
1381
			report(crt_loc, err);
-
 
1382
		}
-
 
1383
	}
-
 
1384
	return;
-
 
1385
}
-
 
1386
 
-
 
1387
 
-
 
1388
/*
1333
    DECLARE A FUNCTION PARAMETER
1389
    DECLARE A FUNCTION PARAMETER
1334
 
1390
 
1335
    This routine constructs the declaration of a function parameter or
1391
    This routine constructs the declaration of a function parameter or
1336
    non-type template parameter (as indicated by loc) with declaration
1392
    non-type template parameter (as indicated by loc) with declaration
1337
    specifiers ds, type t and name id.  Note that t is not checked - this
1393
    specifiers ds, type t and name id.  Note that t is not checked - this
1338
    is only a declaration, and t may still legitimately be void, however
1394
    is only a declaration, and t may still legitimately be void, however
1339
    function and array parameters are adjusted to pointer parameters at
1395
    function and array parameters are adjusted to pointer parameters at
1340
    this stage.
1396
    this stage.
1341
*/
1397
*/
1342
 
1398
 
1343
IDENTIFIER make_param_decl
1399
IDENTIFIER
1344
    PROTO_N ( ( ds, t, id, loc ) )
-
 
1345
    PROTO_T ( DECL_SPEC ds X TYPE t X IDENTIFIER id X int loc )
1400
make_param_decl(DECL_SPEC ds, TYPE t, IDENTIFIER id, int loc)
1346
{
1401
{
1347
    ERROR err ;
1402
	ERROR err;
1348
    DECL_SPEC st, rs ;
1403
	DECL_SPEC st, rs;
1349
    NAMESPACE ns = crt_namespace ;
1404
	NAMESPACE ns = crt_namespace;
1350
    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
1405
	HASHID nm = DEREF_hashid(id_name(id));
1351
    MEMBER mem = search_member ( ns, nm, 1 ) ;
1406
	MEMBER mem = search_member(ns, nm, 1);
1352
    IDENTIFIER old_id = DEREF_id ( member_id ( mem ) ) ;
1407
	IDENTIFIER old_id = DEREF_id(member_id(mem));
1353
 
1408
 
1354
    /* Check on identifier name */
1409
	/* Check on identifier name */
1355
    err = check_id_name ( id, loc ) ;
1410
	err = check_id_name(id, loc);
1356
    if ( !IS_NULL_err ( err ) ) report ( decl_loc, err ) ;
1411
	if (!IS_NULL_err(err)) {
-
 
1412
		report(decl_loc, err);
-
 
1413
	}
1357
 
1414
 
1358
    /* Deal with inferred types */
1415
	/* Deal with inferred types */
1359
    ds = check_inferred_type ( ds, &t, 0 ) ;
1416
	ds = check_inferred_type(ds, &t, 0);
1360
    func_type_defn ( 1 ) ;
1417
	func_type_defn(1);
-
 
1418
 
-
 
1419
	/* Check on storage class specifiers */
-
 
1420
	st = check_storage(ds, loc, old_id);
-
 
1421
	if (st == dspec_register) {
-
 
1422
		st = (dspec_auto | dspec_register);
-
 
1423
		used_register = 1;
-
 
1424
	} else {
-
 
1425
		st = dspec_auto;
-
 
1426
	}
1361
 
1427
 
1362
    /* Check on storage class specifiers */
1428
	/* Deal with type definitions */
1363
    st = check_storage ( ds, loc, old_id ) ;
-
 
1364
    if ( st == dspec_register ) {
1429
	if (ds & dspec_typedef) {
1365
	st = ( dspec_auto | dspec_register ) ;
1430
		/* Can't have typedef in function parameters */
1366
	used_register = 1 ;
-
 
1367
    } else {
-
 
1368
	st = dspec_auto ;
1431
		report(decl_loc, ERR_dcl_typedef_par());
1369
    }
1432
	}
1370
 
1433
 
1371
    /* Deal with type definitions */
-
 
1372
    if ( ds & dspec_typedef ) {
-
 
1373
	/* Can't have typedef in function parameters */
1434
	/* Check on function specifiers */
1374
	report ( decl_loc, ERR_dcl_typedef_par () ) ;
1435
	IGNORE check_func_spec(ds, loc);
1375
    }
-
 
1376
 
1436
 
1377
    /* Check on function specifiers */
-
 
1378
    IGNORE check_func_spec ( ds, loc ) ;
-
 
1379
 
-
 
1380
    /* Create the parameter declaration */
1437
	/* Create the parameter declaration */
1381
    t = make_param_type ( t, loc ) ;
1438
	t = make_param_type(t, loc);
1382
    rs = ( ds & dspec_other ) ;
1439
	rs = (ds & dspec_other);
1383
    ds = ( st | rs | dspec_defn ) ;
1440
	ds = (st | rs | dspec_defn);
1384
    if ( !IS_NULL_id ( old_id ) ) {
1441
	if (!IS_NULL_id(old_id)) {
1385
	/* Check for redeclarations */
1442
		/* Check for redeclarations */
1386
	if ( loc == CONTEXT_TEMPL_PARAM ) {
1443
		if (loc == CONTEXT_TEMPL_PARAM) {
1387
	    report ( decl_loc, ERR_temp_param_dup ( nm ) ) ;
1444
			report(decl_loc, ERR_temp_param_dup(nm));
1388
	    nm = lookup_anon () ;
1445
			nm = lookup_anon();
1389
	    mem = search_member ( ns, nm, 1 ) ;
1446
			mem = search_member(ns, nm, 1);
1390
	    id = DEREF_id ( hashid_id ( nm ) ) ;
1447
			id = DEREF_id(hashid_id(nm));
1391
	} else {
1448
		} else {
1392
	    if ( loc == CONTEXT_WEAK_PARAM ) {
1449
			if (loc == CONTEXT_WEAK_PARAM) {
1393
		if ( IS_id_weak_param ( old_id ) ) {
1450
				if (IS_id_weak_param(old_id)) {
1394
		    /* Check for order of declaration */
1451
					/* Check for order of declaration */
-
 
1452
					MEMBER mem1 =
1395
		    MEMBER mem1 = DEREF_member ( nspace_last ( ns ) ) ;
1453
					    DEREF_member(nspace_last(ns));
1396
		    while ( !EQ_member ( mem1, mem ) ) {
1454
					while (!EQ_member(mem1, mem)) {
-
 
1455
						IDENTIFIER mid =
1397
			IDENTIFIER mid = DEREF_id ( member_id ( mem1 ) ) ;
1456
						    DEREF_id(member_id(mem1));
-
 
1457
						if (!IS_NULL_id(mid) &&
1398
			if ( !IS_NULL_id ( mid ) && IS_id_parameter ( mid ) ) {
1458
						    IS_id_parameter(mid)) {
1399
			    report ( decl_loc, ERR_dcl_fct_par_order () ) ;
1459
							report(decl_loc, ERR_dcl_fct_par_order());
1400
			    break ;
1460
							break;
-
 
1461
						}
-
 
1462
						mem1 = DEREF_member(member_next(mem1));
-
 
1463
					}
-
 
1464
					old_id = NULL_id;
-
 
1465
				} else if (!IS_id_parameter(old_id)) {
-
 
1466
					report(decl_loc, ERR_dcl_fct_par_undecl(nm));
-
 
1467
				}
-
 
1468
			}
-
 
1469
			if (!IS_NULL_id(old_id)) {
-
 
1470
				if (IS_id_parameter(old_id)) {
-
 
1471
					/* Make up new name for parameter */
-
 
1472
					nm = lookup_anon();
-
 
1473
					mem = search_member(ns, nm, 1);
-
 
1474
				}
-
 
1475
				IGNORE redecl_id(ds, t, old_id, 0, 0);
1401
			}
1476
			}
1402
			mem1 = DEREF_member ( member_next ( mem1 ) ) ;
-
 
1403
		    }
-
 
1404
		    old_id = NULL_id ;
-
 
1405
		} else if ( !IS_id_parameter ( old_id ) ) {
-
 
1406
		    report ( decl_loc, ERR_dcl_fct_par_undecl ( nm ) ) ;
-
 
1407
		}
-
 
1408
	    }
-
 
1409
	    if ( !IS_NULL_id ( old_id ) ) {
-
 
1410
		if ( IS_id_parameter ( old_id ) ) {
-
 
1411
		    /* Make up new name for parameter */
-
 
1412
		    nm = lookup_anon () ;
-
 
1413
		    mem = search_member ( ns, nm, 1 ) ;
-
 
1414
		}
1477
		}
1415
		IGNORE redecl_id ( ds, t, old_id, 0, 0 ) ;
-
 
1416
	    }
-
 
1417
	}
-
 
1418
    } else {
1478
	} else {
1419
	if ( loc == CONTEXT_WEAK_PARAM ) {
1479
		if (loc == CONTEXT_WEAK_PARAM) {
1420
	    report ( decl_loc, ERR_dcl_fct_par_undecl ( nm ) ) ;
1480
			report(decl_loc, ERR_dcl_fct_par_undecl(nm));
-
 
1481
		}
1421
	}
1482
	}
1422
    }
-
 
1423
    ds = adjust_linkage ( ds, 0 ) ;
1483
	ds = adjust_linkage(ds, 0);
1424
    if ( loc == CONTEXT_TEMPL_PARAM ) {
1484
	if (loc == CONTEXT_TEMPL_PARAM) {
1425
	IDENTIFIER pid ;
1485
		IDENTIFIER pid;
1426
	object_type ( t, id_token_tag ) ;
1486
		object_type(t, id_token_tag);
1427
	id = make_exp_param ( t, id ) ;
1487
		id = make_exp_param(t, id);
1428
	pid = DEREF_id ( id_token_alt ( id ) ) ;
1488
		pid = DEREF_id(id_token_alt(id));
1429
	set_member ( mem, pid ) ;
1489
		set_member(mem, pid);
1430
    } else {
1490
	} else {
1431
	t = lvalue_type ( t ) ;
1491
		t = lvalue_type(t);
1432
	object_type ( t, id_parameter_tag ) ;
1492
		object_type(t, id_parameter_tag);
1433
	MAKE_id_parameter ( nm, ds, ns, decl_loc, t, id ) ;
1493
		MAKE_id_parameter(nm, ds, ns, decl_loc, t, id);
1434
	set_member ( mem, id ) ;
1494
		set_member(mem, id);
1435
    }
1495
	}
1436
    check_par_decl ( t, id, loc ) ;
1496
	check_par_decl(t, id, loc);
1437
    is_redeclared = 0 ;
1497
	is_redeclared = 0;
1438
    return ( id ) ;
1498
	return (id);
1439
}
1499
}
1440
 
1500
 
1441
 
1501
 
1442
/*
1502
/*
1443
    DECLARE A NON-PROTOTYPE FUNCTION PARAMETER
1503
    DECLARE A NON-PROTOTYPE FUNCTION PARAMETER
1444
 
1504
 
1445
    This routine is used to declare a non-prototype function parameter.
1505
    This routine is used to declare a non-prototype function parameter.
1446
*/
1506
*/
1447
 
1507
 
1448
IDENTIFIER weak_param_decl
1508
IDENTIFIER
1449
    PROTO_N ( ( id ) )
-
 
1450
    PROTO_T ( IDENTIFIER id )
1509
weak_param_decl(IDENTIFIER id)
1451
{
1510
{
1452
    NAMESPACE ns = crt_namespace ;
1511
	NAMESPACE ns = crt_namespace;
1453
    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
1512
	HASHID nm = DEREF_hashid(id_name(id));
1454
    MEMBER mem = search_member ( ns, nm, 1 ) ;
1513
	MEMBER mem = search_member(ns, nm, 1);
1455
    IDENTIFIER old_id = DEREF_id ( member_id ( mem ) ) ;
1514
	IDENTIFIER old_id = DEREF_id(member_id(mem));
1456
    if ( !IS_NULL_id ( old_id ) ) {
1515
	if (!IS_NULL_id(old_id)) {
1457
	nm = lookup_anon () ;
1516
		nm = lookup_anon();
1458
	mem = search_member ( ns, nm, 1 ) ;
1517
		mem = search_member(ns, nm, 1);
1459
	IGNORE redecl_id ( dspec_none, NULL_type, old_id, 0, 0 ) ;
1518
		IGNORE redecl_id(dspec_none, NULL_type, old_id, 0, 0);
1460
    }
1519
	}
1461
    MAKE_id_weak_param ( nm, dspec_none, ns, decl_loc, id ) ;
1520
	MAKE_id_weak_param(nm, dspec_none, ns, decl_loc, id);
1462
    set_member ( mem, id ) ;
1521
	set_member(mem, id);
1463
    is_redeclared = 0 ;
1522
	is_redeclared = 0;
1464
    return ( id ) ;
1523
	return (id);
1465
}
1524
}
1466
 
1525
 
1467
 
1526
 
1468
/*
1527
/*
1469
    CHECK A MEMBER DECLARATION
1528
    CHECK A MEMBER DECLARATION
1470
 
1529
 
1471
    This routine checks the declaration of the class member id with type
1530
    This routine checks the declaration of the class member id with type
1472
    t and declaration specifiers ds.
1531
    t and declaration specifiers ds.
1473
*/
1532
*/
1474
 
1533
 
1475
void check_mem_decl
1534
void
1476
    PROTO_N ( ( ds, t, id ) )
-
 
1477
    PROTO_T ( DECL_SPEC ds X TYPE t X IDENTIFIER id )
1535
check_mem_decl(DECL_SPEC ds, TYPE t, IDENTIFIER id)
1478
{
1536
{
1479
    unsigned tag = TAG_type ( t ) ;
1537
	unsigned tag = TAG_type(t);
1480
    if ( ds & dspec_mutable ) {
1538
	if (ds & dspec_mutable) {
1481
	/* Can't apply mutable to a const member */
1539
		/* Can't apply mutable to a const member */
1482
	CV_SPEC qual = find_cv_qual ( t ) ;
1540
		CV_SPEC qual = find_cv_qual(t);
1483
	if ( qual & cv_const ) {
1541
		if (qual & cv_const) {
1484
	    report ( crt_loc, ERR_dcl_stc_mut_const ( id ) ) ;
1542
			report(crt_loc, ERR_dcl_stc_mut_const(id));
1485
	    if ( IS_id_member ( id ) ) {
1543
			if (IS_id_member(id)) {
1486
		qual &= ~cv_const ;
1544
				qual &= ~cv_const;
1487
		t = qualify_type ( t, qual, 0 ) ;
1545
				t = qualify_type(t, qual, 0);
1488
		COPY_type ( id_member_type ( id ), t ) ;
1546
				COPY_type(id_member_type(id), t);
1489
	    }
1547
			}
1490
	}
1548
		}
1491
    }
1549
	}
1492
    if ( tag == type_top_tag || tag == type_bottom_tag ) {
1550
	if (tag == type_top_tag || tag == type_bottom_tag) {
1493
	/* Always report void members */
1551
		/* Always report void members */
1494
	report ( crt_loc, ERR_basic_fund_void_mem ( id, t ) ) ;
1552
		report(crt_loc, ERR_basic_fund_void_mem(id, t));
1495
    } else if ( tag == type_templ_tag ) {
1553
	} else if (tag == type_templ_tag) {
1496
	/* Shouldn't have template type */
1554
		/* Shouldn't have template type */
1497
	report ( crt_loc, ERR_temp_decl_bad () ) ;
1555
		report(crt_loc, ERR_temp_decl_bad());
1498
    } else if ( ds & dspec_defn ) {
1556
	} else if (ds & dspec_defn) {
1499
	/* Only check otherwise for defined (non-static) members */
1557
		/* Only check otherwise for defined (non-static) members */
1500
	if ( tag == type_ref_tag ) {
1558
		if (tag == type_ref_tag) {
1501
	    /* References don't need checking */
1559
			/* References don't need checking */
1502
	    /* EMPTY */
1560
			/* EMPTY */
1503
	} else {
1561
		} else {
1504
	    /* Other members should have complete type */
1562
			/* Other members should have complete type */
1505
	    ERROR err = check_complete ( t ) ;
1563
			ERROR err = check_complete(t);
1506
	    if ( !IS_NULL_err ( err ) ) {
1564
			if (!IS_NULL_err(err)) {
1507
		ERROR err2 = ERR_class_mem_incompl_mem ( id ) ;
1565
				ERROR err2 = ERR_class_mem_incompl_mem(id);
1508
		err = concat_error ( err, err2 ) ;
1566
				err = concat_error(err, err2);
1509
		report ( crt_loc, err ) ;
1567
				report(crt_loc, err);
1510
	    } else {
1568
			} else {
1511
		/* Members can't have abstract type */
1569
				/* Members can't have abstract type */
1512
		err = check_abstract ( t ) ;
1570
				err = check_abstract(t);
1513
		if ( !IS_NULL_err ( err ) ) {
1571
				if (!IS_NULL_err(err)) {
1514
		    ERROR err2 = ERR_class_abstract_mem ( id ) ;
1572
					ERROR err2 = ERR_class_abstract_mem(id);
1515
		    err = concat_error ( err, err2 ) ;
1573
					err = concat_error(err, err2);
1516
		    report ( crt_loc, err ) ;
1574
					report(crt_loc, err);
1517
		}
1575
				}
1518
	    }
1576
			}
1519
	}
1577
		}
1520
    }
1578
	}
1521
    return ;
1579
	return;
1522
}
1580
}
1523
 
1581
 
1524
 
1582
 
1525
/*
1583
/*
1526
    DECLARE A CLASS MEMBER
1584
    DECLARE A CLASS MEMBER
1527
 
1585
 
1528
    This routine constructs the declaration of a class member with
1586
    This routine constructs the declaration of a class member with
1529
    declaration specifiers ds, type t and name id.  Note that the access
1587
    declaration specifiers ds, type t and name id.  Note that the access
1530
    declarations (i.e. just a qualified-id and a semicolon) can only be
1588
    declarations (i.e. just a qualified-id and a semicolon) can only be
1531
    spotted at this stage.  The argument sm is true if this is the first
1589
    spotted at this stage.  The argument sm is true if this is the first
1532
    declarator in a list and the next token is a semicolon.
1590
    declarator in a list and the next token is a semicolon.
1715
	}
1789
	}
1716
	MAKE_member_large ( NULL_member, NULL_member, mem ) ;
-
 
1717
	COPY_id ( member_id ( mem ), id ) ;
-
 
1718
	COPY_member ( nspace_last ( ns ), mem ) ;
-
 
1719
	COPY_member ( member_next ( mem_old ), mem ) ;
-
 
1720
    }
-
 
1721
    set_member ( mem, id ) ;
1790
	set_member(mem, id);
1722
    check_mem_decl ( ds, t, id ) ;
1791
	check_mem_decl(ds, t, id);
1723
    is_redeclared = 0 ;
1792
	is_redeclared = 0;
1724
 
1793
 
1725
    /* Adjust class information */
1794
	/* Adjust class information */
1726
    if ( st == dspec_static ) {
1795
	if (st == dspec_static) {
1727
	if ( really_in_function_defn ) {
1796
		if (really_in_function_defn) {
1728
	    /* Can't have static members in local classes */
1797
			/* Can't have static members in local classes */
1729
	    report ( crt_loc, ERR_class_local_static ( id ) ) ;
1798
			report(crt_loc, ERR_class_local_static(id));
-
 
1799
		}
-
 
1800
		ci |= cinfo_static;
-
 
1801
	} else {
-
 
1802
		/* Check member types */
-
 
1803
		if (crt_access != dspec_public) {
-
 
1804
			ci |= cinfo_private;
-
 
1805
		}
-
 
1806
		ci = check_member_type(ct, ci, t, 0);
-
 
1807
		ci &= ~cinfo_empty;
1730
	}
1808
	}
1731
	ci |= cinfo_static ;
-
 
1732
    } else {
-
 
1733
	/* Check member types */
-
 
1734
	if ( crt_access != dspec_public ) ci |= cinfo_private ;
-
 
1735
	ci = check_member_type ( ct, ci, t, 0 ) ;
-
 
1736
	ci &= ~cinfo_empty ;
-
 
1737
    }
-
 
1738
    COPY_cinfo ( ctype_info ( ct ), ci ) ;
1809
	COPY_cinfo(ctype_info(ct), ci);
1739
    return ( id ) ;
1810
	return (id);
1740
}
1811
}
1741
 
1812
 
1742
 
1813
 
1743
/*
1814
/*
1744
    MAINTAIN SPECIAL MEMBER FUNCTIONS FOR A CLASS
1815
    MAINTAIN SPECIAL MEMBER FUNCTIONS FOR A CLASS
1745
 
1816
 
1746
    This routine updates the special member function information for
1817
    This routine updates the special member function information for
1747
    the class ct using the function id.  tag gives the identifier name tag.
1818
    the class ct using the function id.  tag gives the identifier name tag.
1748
*/
1819
*/
1749
 
1820
 
1750
void special_func_mem
1821
void
1751
    PROTO_N ( ( ct, id, tag, prev ) )
-
 
1752
    PROTO_T ( CLASS_TYPE ct X IDENTIFIER id X unsigned tag X IDENTIFIER prev )
1822
special_func_mem(CLASS_TYPE ct, IDENTIFIER id, unsigned tag, IDENTIFIER prev)
1753
{
1823
{
1754
    switch ( tag ) {
1824
	switch (tag) {
1755
	case hashid_constr_tag : {
1825
	case hashid_constr_tag: {
1756
	    /* Set constructor */
1826
		/* Set constructor */
1757
	    COPY_id ( ctype_constr ( ct ), id ) ;
1827
		COPY_id(ctype_constr(ct), id);
1758
	    break ;
1828
		break;
1759
	}
1829
	}
1760
	case hashid_destr_tag : {
1830
	case hashid_destr_tag: {
1761
	    /* Set destructor */
1831
		/* Set destructor */
1762
	    COPY_id ( ctype_destr ( ct ), id ) ;
1832
		COPY_id(ctype_destr(ct), id);
1763
	    break ;
1833
		break;
1764
	}
1834
	}
1765
	case hashid_conv_tag : {
1835
	case hashid_conv_tag: {
1766
	    /* Maintain list of conversion functions */
1836
		/* Maintain list of conversion functions */
1767
	    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
1837
		HASHID nm = DEREF_hashid(id_name(id));
1768
	    LIST ( IDENTIFIER ) conv = DEREF_list ( ctype_conv ( ct ) ) ;
1838
		LIST(IDENTIFIER)conv = DEREF_list(ctype_conv(ct));
1769
	    LIST ( IDENTIFIER ) p = conv ;
1839
		LIST(IDENTIFIER)p = conv;
1770
	    while ( !IS_NULL_list ( p ) ) {
1840
		while (!IS_NULL_list(p)) {
1771
		IDENTIFIER pid = DEREF_id ( HEAD_list ( p ) ) ;
1841
			IDENTIFIER pid = DEREF_id(HEAD_list(p));
1772
		HASHID pnm = DEREF_hashid ( id_name ( pid ) ) ;
1842
			HASHID pnm = DEREF_hashid(id_name(pid));
1773
		if ( EQ_hashid ( nm, pnm ) ) {
1843
			if (EQ_hashid(nm, pnm)) {
1774
		    /* Already member of list */
1844
				/* Already member of list */
1775
		    IDENTIFIER over ;
1845
				IDENTIFIER over;
1776
		    over = DEREF_id ( id_function_etc_over ( id ) ) ;
1846
				over = DEREF_id(id_function_etc_over(id));
1777
		    if ( !EQ_id ( pid, over ) && !EQ_id ( pid, prev ) ) {
1847
				if (!EQ_id(pid, over) && !EQ_id(pid, prev)) {
1778
			/* Template function has produced duplicate */
1848
					/* Template function has produced
-
 
1849
					 * duplicate */
1779
			PTR ( LOCATION ) ploc = id_loc ( pid ) ;
1850
					PTR(LOCATION)ploc = id_loc(pid);
-
 
1851
					report(crt_loc,
1780
			report ( crt_loc, ERR_class_mem_redecl ( id, ploc ) ) ;
1852
					       ERR_class_mem_redecl(id, ploc));
1781
		    }
1853
				}
1782
		    COPY_id ( HEAD_list ( p ), id ) ;
1854
				COPY_id(HEAD_list(p), id);
1783
		    return ;
1855
				return;
-
 
1856
			}
-
 
1857
			p = TAIL_list(p);
1784
		}
1858
		}
1785
		p = TAIL_list ( p ) ;
-
 
1786
	    }
-
 
1787
	    CONS_id ( id, conv, conv ) ;
1859
		CONS_id(id, conv, conv);
1788
	    COPY_list ( ctype_conv ( ct ), conv ) ;
1860
		COPY_list(ctype_conv(ct), conv);
1789
	    break ;
1861
		break;
-
 
1862
	}
1790
	}
1863
	}
1791
    }
-
 
1792
    return ;
1864
	return;
1793
}
1865
}
1794
 
1866
 
1795
 
1867
 
1796
/*
1868
/*
1797
    DECLARE A CLASS FUNCTION MEMBER
1869
    DECLARE A CLASS FUNCTION MEMBER
Line 1802... Line 1874...
1802
    declarations.
1874
    declarations.
1803
*/
1875
*/
1804
 
1876
 
1805
#if LANGUAGE_CPP
1877
#if LANGUAGE_CPP
1806
 
1878
 
1807
IDENTIFIER make_func_mem_decl
1879
IDENTIFIER
1808
    PROTO_N ( ( ds, t, id, def ) )
-
 
1809
    PROTO_T ( DECL_SPEC ds X TYPE t X IDENTIFIER id X int def )
1880
make_func_mem_decl(DECL_SPEC ds, TYPE t, IDENTIFIER id, int def)
1810
{
1881
{
1811
    ERROR err ;
1882
	ERROR err;
1812
    MEMBER mem ;
1883
	MEMBER mem;
1813
    int ok = 1 ;
1884
	int ok = 1;
1814
    int chk = 1 ;
1885
	int chk = 1;
1815
    unsigned it ;
1886
	unsigned it;
1816
    unsigned itag ;
1887
	unsigned itag;
1817
    int allocator = 0 ;
1888
	int allocator = 0;
1818
    IDENTIFIER old_id ;
1889
	IDENTIFIER old_id;
1819
    LIST ( VIRTUAL ) vt ;
1890
	LIST(VIRTUAL)vt;
1820
    DECL_SPEC st, df, fn, rs ;
1891
	DECL_SPEC st, df, fn, rs;
1821
    IDENTIFIER over_id = NULL_id ;
1892
	IDENTIFIER over_id = NULL_id;
1822
    IDENTIFIER hide_id = NULL_id ;
1893
	IDENTIFIER hide_id = NULL_id;
1823
    NAMESPACE ns = crt_namespace ;
1894
	NAMESPACE ns = crt_namespace;
1824
    QUALIFIER cq = crt_id_qualifier ;
1895
	QUALIFIER cq = crt_id_qualifier;
1825
    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
1896
	HASHID nm = DEREF_hashid(id_name(id));
1826
    CLASS_TYPE ct = crt_class ;
1897
	CLASS_TYPE ct = crt_class;
1827
    CLASS_INFO ci = DEREF_cinfo ( ctype_info ( ct ) ) ;
1898
	CLASS_INFO ci = DEREF_cinfo(ctype_info(ct));
1828
 
-
 
1829
    /* Check for template specialisations */
-
 
1830
    if ( is_templ_decl ( id, t ) || is_templ_spec ( t ) ) {
-
 
1831
	st = ( dspec_extern | ( ds & dspec_inline ) ) ;
-
 
1832
	IGNORE bind_specialise ( &id, t, st, 0, 1, def ) ;
-
 
1833
	if ( !IS_NULL_id ( id ) ) {
-
 
1834
	    report ( crt_loc, ERR_temp_spec_member ( id ) ) ;
-
 
1835
	}
-
 
1836
	return ( id ) ;
-
 
1837
    }
-
 
1838
 
-
 
1839
    /* Find previous declaration */
-
 
1840
    mem = search_member ( ns, nm, 1 ) ;
-
 
1841
    old_id = DEREF_id ( member_id ( mem ) ) ;
-
 
1842
    if ( !IS_NULL_id ( old_id ) ) {
-
 
1843
	old_id = redecl_inherit ( old_id, cq, 1, 1 ) ;
-
 
1844
    }
-
 
1845
 
1899
 
-
 
1900
	/* Check for template specialisations */
-
 
1901
	if (is_templ_decl(id, t) || is_templ_spec(t)) {
-
 
1902
		st = (dspec_extern | (ds & dspec_inline));
-
 
1903
		IGNORE bind_specialise(&id, t, st, 0, 1, def);
-
 
1904
		if (!IS_NULL_id(id)) {
-
 
1905
			report(crt_loc, ERR_temp_spec_member(id));
-
 
1906
		}
-
 
1907
		return (id);
-
 
1908
	}
-
 
1909
 
-
 
1910
	/* Find previous declaration */
-
 
1911
	mem = search_member(ns, nm, 1);
-
 
1912
	old_id = DEREF_id(member_id(mem));
-
 
1913
	if (!IS_NULL_id(old_id)) {
-
 
1914
		old_id = redecl_inherit(old_id, cq, 1, 1);
-
 
1915
	}
-
 
1916
 
1846
    /* Check on member qualifications */
1917
	/* Check on member qualifications */
1847
    if ( cq != qual_none ) {
1918
	if (cq != qual_none) {
1848
	ns = DEREF_nspace ( id_parent ( id ) ) ;
1919
		ns = DEREF_nspace(id_parent(id));
1849
	if ( EQ_nspace ( ns, crt_namespace ) ) {
1920
		if (EQ_nspace(ns, crt_namespace)) {
1850
	    /* Qualifier indicates the current class */
1921
			/* Qualifier indicates the current class */
1851
	    report ( crt_loc, ERR_dcl_meaning_mem ( cq, id ) ) ;
1922
			report(crt_loc, ERR_dcl_meaning_mem(cq, id));
1852
	    crt_id_qualifier = qual_none ;
1923
			crt_id_qualifier = qual_none;
1853
	} else {
1924
		} else {
1854
	    /* Qualifier indicates some other namespace */
1925
			/* Qualifier indicates some other namespace */
1855
	    id = make_func_decl ( ds, t, id, def ) ;
1926
			id = make_func_decl(ds, t, id, def);
1856
	    return ( id ) ;
1927
			return (id);
-
 
1928
		}
-
 
1929
	}
-
 
1930
 
-
 
1931
	/* Check on identifier name */
-
 
1932
	err = check_id_name(id, CONTEXT_FUNC_MEMBER);
-
 
1933
	if (!IS_NULL_err(err)) {
-
 
1934
		report(crt_loc, err);
-
 
1935
		ok = 0;
-
 
1936
	}
-
 
1937
 
-
 
1938
	/* Allow for special functions */
-
 
1939
	it = TAG_hashid(nm);
-
 
1940
	switch (it) {
-
 
1941
	case hashid_constr_tag: {
-
 
1942
		t = check_constr(t, id, ns);
-
 
1943
		ds &= ~dspec_empty;
-
 
1944
		ds |= dspec_main;
-
 
1945
		break;
-
 
1946
	}
-
 
1947
	case hashid_destr_tag: {
-
 
1948
		t = check_destr(t, id, ns);
-
 
1949
		ds &= ~dspec_empty;
-
 
1950
		ds |= dspec_main;
-
 
1951
		break;
1857
	}
1952
	}
-
 
1953
	case hashid_op_tag: {
-
 
1954
		t = check_operator(t, id, 1, &allocator);
-
 
1955
		if (!allocator) {
-
 
1956
			ds |= dspec_ignore;
1858
    }
1957
		}
-
 
1958
		break;
-
 
1959
	}
-
 
1960
	case hashid_conv_tag: {
-
 
1961
		t = check_conv(t, id);
-
 
1962
		ds &= ~dspec_empty;
-
 
1963
		chk = 0;
-
 
1964
		break;
-
 
1965
	}
-
 
1966
	}
-
 
1967
 
-
 
1968
	/* Deal with inferred types */
-
 
1969
	ds = check_func_type(ds, t, def, chk, 1);
1859
 
1970
 
1860
    /* Check on identifier name */
1971
	/* Handle function definitions */
1861
    err = check_id_name ( id, CONTEXT_FUNC_MEMBER ) ;
-
 
1862
    if ( !IS_NULL_err ( err ) ) {
-
 
1863
	report ( crt_loc, err ) ;
-
 
1864
	ok = 0 ;
1972
	if (def) {
1865
    }
-
 
1866
 
-
 
1867
    /* Allow for special functions */
1973
		/* Functions defined in a class are inline */
1868
    it = TAG_hashid ( nm ) ;
-
 
1869
    switch ( it ) {
-
 
1870
	case hashid_constr_tag : {
-
 
1871
	    t = check_constr ( t, id, ns ) ;
-
 
1872
	    ds &= ~dspec_empty ;
1974
		df = dspec_defn;
1873
	    ds |= dspec_main ;
1975
		ds |= dspec_inline;
1874
	    break ;
1976
	} else {
1875
	}
-
 
1876
	case hashid_destr_tag : {
-
 
1877
	    t = check_destr ( t, id, ns ) ;
-
 
1878
	    ds &= ~dspec_empty ;
-
 
1879
	    ds |= dspec_main ;
1977
		df = dspec_none;
1880
	    break ;
-
 
1881
	}
1978
	}
1882
	case hashid_op_tag : {
-
 
1883
	    t = check_operator ( t, id, 1, &allocator ) ;
-
 
1884
	    if ( !allocator ) ds |= dspec_ignore ;
-
 
1885
	    break ;
-
 
1886
	}
-
 
1887
	case hashid_conv_tag : {
-
 
1888
	    t = check_conv ( t, id ) ;
-
 
1889
	    ds &= ~dspec_empty ;
-
 
1890
	    chk = 0 ;
-
 
1891
	    break ;
-
 
1892
	}
-
 
1893
    }
-
 
1894
 
-
 
1895
    /* Deal with inferred types */
-
 
1896
    ds = check_func_type ( ds, t, def, chk, 1 ) ;
-
 
1897
 
1979
 
1898
    /* Handle function definitions */
1980
	/* Check on storage class specifiers */
1899
    if ( def ) {
-
 
1900
	/* Functions defined in a class are inline */
1981
	st = check_storage(ds, CONTEXT_FUNC_MEMBER, old_id);
1901
	df = dspec_defn ;
-
 
1902
	ds |= dspec_inline ;
-
 
1903
    } else {
-
 
1904
	df = dspec_none ;
-
 
1905
    }
-
 
1906
 
1982
 
-
 
1983
	/* Deal with type definitions */
-
 
1984
	if (ds & dspec_typedef) {
-
 
1985
		/* Can only apply typedef to declarations, not definitions */
-
 
1986
		if (!def) {
-
 
1987
			if (ok) {
1907
    /* Check on storage class specifiers */
1988
				/* Recheck identifier name */
1908
    st = check_storage ( ds, CONTEXT_FUNC_MEMBER, old_id ) ;
1989
				err = check_id_name(id, CONTEXT_MEMBER);
-
 
1990
				if (!IS_NULL_err(err)) {
-
 
1991
					report(crt_loc, err);
-
 
1992
				}
-
 
1993
			}
-
 
1994
			id = make_type_decl(ns, ds, t, mem, id);
-
 
1995
			return (id);
-
 
1996
		}
-
 
1997
		report(crt_loc, ERR_dcl_typedef_func());
-
 
1998
	}
1909
 
1999
 
1910
    /* Deal with type definitions */
-
 
1911
    if ( ds & dspec_typedef ) {
-
 
1912
	/* Can only apply typedef to declarations, not definitions */
-
 
1913
	if ( !def ) {
-
 
1914
	    if ( ok ) {
-
 
1915
		/* Recheck identifier name */
-
 
1916
		err = check_id_name ( id, CONTEXT_MEMBER ) ;
-
 
1917
		if ( !IS_NULL_err ( err ) ) report ( crt_loc, err ) ;
-
 
1918
	    }
-
 
1919
	    id = make_type_decl ( ns, ds, t, mem, id ) ;
-
 
1920
	    return ( id ) ;
-
 
1921
	}
-
 
1922
	report ( crt_loc, ERR_dcl_typedef_func () ) ;
-
 
1923
    }
-
 
1924
 
-
 
1925
    /* Check special functions */
2000
	/* Check special functions */
1926
    if ( allocator ) {
2001
	if (allocator) {
1927
	/* Allocator functions are implicitly static */
-
 
1928
	if ( st != dspec_static ) {
-
 
1929
	    st = dspec_static ;
-
 
1930
	    allocator |= 0x4 ;
-
 
1931
	}
-
 
1932
    } else if ( st == dspec_static ) {
-
 
1933
	switch ( it ) {
-
 
1934
	    case hashid_constr_tag : {
-
 
1935
		/* Constructors can't be static */
-
 
1936
		report ( crt_loc, ERR_class_ctor_static () ) ;
-
 
1937
		st = dspec_none ;
-
 
1938
		break ;
-
 
1939
	    }
-
 
1940
	    case hashid_destr_tag : {
-
 
1941
		/* Destructors can't be static */
-
 
1942
		report ( crt_loc, ERR_class_dtor_static () ) ;
-
 
1943
		st = dspec_none ;
-
 
1944
		break ;
-
 
1945
	    }
-
 
1946
	    case hashid_op_tag : {
-
 
1947
		/* Overloaded operators can't be static */
-
 
1948
		report ( crt_loc, ERR_over_oper_static () ) ;
-
 
1949
		st = dspec_none ;
-
 
1950
		break ;
-
 
1951
	    }
-
 
1952
	    case hashid_conv_tag : {
-
 
1953
		/* Conversion functions can't be static */
-
 
1954
		report ( crt_loc, ERR_class_conv_fct_mem () ) ;
-
 
1955
		st = dspec_none ;
-
 
1956
		break ;
-
 
1957
	    }
-
 
1958
	}
-
 
1959
    }
-
 
1960
 
-
 
1961
    /* Check on function specifiers */
-
 
1962
    fn = check_func_spec ( ds, CONTEXT_FUNC_MEMBER ) ;
-
 
1963
    vt = overrides_virtual ( ct, nm, t, &hide_id ) ;
-
 
1964
    if ( !IS_NULL_list ( vt ) ) {
-
 
1965
	/* Check for overriding of virtual functions */
-
 
1966
	if ( !( fn & dspec_virtual ) ) {
-
 
1967
	    if ( !( ds & dspec_implicit ) ) {
-
 
1968
		err = ERR_class_virtual_override ( nm ) ;
-
 
1969
		if ( !IS_NULL_err ( err ) ) report ( crt_loc, err ) ;
-
 
1970
	    }
-
 
1971
	    fn |= dspec_virtual ;
-
 
1972
	}
-
 
1973
    } else if ( !IS_NULL_id ( hide_id ) ) {
-
 
1974
	err = ERR_class_virtual_hide ( nm, hide_id ) ;
-
 
1975
	if ( !IS_NULL_err ( err ) ) report ( crt_loc, err ) ;
-
 
1976
    }
-
 
1977
    if ( fn & dspec_virtual ) {
-
 
1978
	if ( st == dspec_static ) {
-
 
1979
	    /* Static members can't be virtual */
-
 
1980
	    err = ERR_class_static_mfct_virt () ;
-
 
1981
	    if ( allocator & 0x4 ) {
-
 
1982
		/* Allocator functions are implicitly static */
2002
		/* Allocator functions are implicitly static */
2084
/*
2166
/*
2085
    DECLARE A FRIEND FUNCTION
2167
    DECLARE A FRIEND FUNCTION
2086
 
2168
 
2087
    This routine is used to handle the declaration of a friend function
2169
    This routine is used to handle the declaration of a friend function
2088
    within a class.  The parameters are identical to those in the previous
2170
    within a class.  The parameters are identical to those in the previous
2089
    routine.
2171
    routine.
2090
*/
2172
*/
2091
 
2173
 
2092
#if LANGUAGE_CPP
2174
#if LANGUAGE_CPP
2093
 
-
 
2094
IDENTIFIER make_friend_decl
-
 
2095
    PROTO_N ( ( ds, t, id, def, chum ) )
-
 
2096
    PROTO_T ( DECL_SPEC ds X TYPE t X IDENTIFIER id X int def X int chum )
-
 
2097
{
-
 
2098
    ERROR err ;
-
 
2099
    MEMBER mem ;
-
 
2100
    int chk = 1 ;
-
 
2101
    unsigned it ;
-
 
2102
    int allocator = 0 ;
-
 
2103
    int main_func = 0 ;
-
 
2104
    IDENTIFIER old_id ;
-
 
2105
    NAMESPACE ns, ens ;
-
 
2106
    DECL_SPEC st, df, fn, rs ;
-
 
2107
    IDENTIFIER over_id = NULL_id ;
-
 
2108
    unsigned itag = id_function_tag ;
-
 
2109
    QUALIFIER cq = crt_id_qualifier ;
-
 
2110
    int td = crt_templ_qualifier ;
-
 
2111
    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
-
 
2112
 
-
 
2113
    /* Check for template specialisations */
-
 
2114
    if ( in_template_decl && cq == qual_none && td == 0 && chum ) {
-
 
2115
	TYPE s = injected_type ( t, 1 ) ;
-
 
2116
	if ( !EQ_type ( s, t ) ) {
-
 
2117
	    /* Friend declaration is implicitly a template */
-
 
2118
	    int eq = 0 ;
-
 
2119
	    IDENTIFIER tid = make_friend_decl ( ds, s, id, 0, 0 ) ;
-
 
2120
	    if ( do_dump ) dump_declare ( tid, &decl_loc, 0 ) ;
-
 
2121
	    id = deduce_func ( tid, t, &eq ) ;
-
 
2122
	    if ( IS_NULL_id ( id ) ) return ( tid ) ;
-
 
2123
	    crt_templ_qualifier = 1 ;
-
 
2124
	}
-
 
2125
    }
-
 
2126
    if ( is_templ_decl ( id, t ) || is_templ_spec ( t ) ) {
-
 
2127
	t = bind_specialise ( &id, t, ds, 0, 1, def ) ;
-
 
2128
	if ( IS_NULL_id ( id ) ) {
-
 
2129
	    /* Invalid specialisation */
-
 
2130
	    crt_id_qualifier = qual_none ;
-
 
2131
	    crt_templ_qualifier = 0 ;
-
 
2132
	    id = DEREF_id ( hashid_id ( nm ) ) ;
-
 
2133
	    while ( IS_type_templ ( t ) ) {
-
 
2134
		t = DEREF_type ( type_templ_defn ( t ) ) ;
-
 
2135
	    }
-
 
2136
	    id = make_friend_decl ( ds, t, id, def, chum ) ;
-
 
2137
	    return ( id ) ;
-
 
2138
	}
-
 
2139
	ns = DEREF_nspace ( id_parent ( id ) ) ;
-
 
2140
	ens = ns ;
-
 
2141
	mem = NULL_member ;
-
 
2142
	old_id = id ;
-
 
2143
	if ( def ) {
-
 
2144
	    /* Check enclosing namespace scope */
-
 
2145
	    check_decl_nspace ( id, ns, def, nonclass_namespace ) ;
-
 
2146
	}
-
 
2147
 
-
 
2148
    } else {
-
 
2149
	/* Deal with typedef immediately */
-
 
2150
	if ( ( ds & dspec_typedef ) && !def ) {
-
 
2151
	    id = make_func_mem_decl ( ds, t, id, def ) ;
-
 
2152
	    return ( id ) ;
-
 
2153
	}
-
 
2154
 
2175
 
-
 
2176
IDENTIFIER
-
 
2177
make_friend_decl(DECL_SPEC ds, TYPE t, IDENTIFIER id, int def, int chum)
-
 
2178
{
-
 
2179
	ERROR err;
-
 
2180
	MEMBER mem;
-
 
2181
	int chk = 1;
-
 
2182
	unsigned it;
-
 
2183
	int allocator = 0;
-
 
2184
	int main_func = 0;
-
 
2185
	IDENTIFIER old_id;
-
 
2186
	NAMESPACE ns, ens;
-
 
2187
	DECL_SPEC st, df, fn, rs;
2155
	/* Check on identifier name */
2188
	IDENTIFIER over_id = NULL_id;
2156
	err = check_id_name ( id, CONTEXT_FUNCTION ) ;
2189
	unsigned itag = id_function_tag;
2157
	if ( !IS_NULL_err ( err ) ) report ( crt_loc, err ) ;
2190
	QUALIFIER cq = crt_id_qualifier;
-
 
2191
	int td = crt_templ_qualifier;
-
 
2192
	HASHID nm = DEREF_hashid(id_name(id));
2158
 
2193
 
2159
	/* Check on member qualification */
2194
	/* Check for template specialisations */
2160
	if ( cq == qual_none ) {
-
 
2161
	    /* Declaration of simple identifier */
-
 
2162
	    ns = nonclass_namespace ;
-
 
2163
	    ens = nonblock_namespace ;
-
 
2164
	    mem = search_member ( ns, nm, 1 ) ;
-
 
2165
	    old_id = DEREF_id ( member_id ( mem ) ) ;
-
 
2166
	    if ( !IS_NULL_id ( old_id ) ) {
-
 
2167
		old_id = redecl_inherit ( old_id, cq, 0, 1 ) ;
-
 
2168
	    }
-
 
2169
	    if ( in_template_decl && is_templ_nspace ( crt_namespace ) ) {
2195
	if (in_template_decl && cq == qual_none && td == 0 && chum) {
2170
		/* Friend of template class */
-
 
2171
		NAMESPACE tns = templ_namespace ;
2196
		TYPE s = injected_type(t, 1);
2172
		mem = search_member ( tns, nm, 1 ) ;
2197
		if (!EQ_type(s, t)) {
2173
	    }
-
 
2174
	} else {
-
 
2175
	    /* Redeclaration of class or namespace member */
2198
			/* Friend declaration is implicitly a template */
2176
	    ns = DEREF_nspace ( id_parent ( id ) ) ;
-
 
2177
	    ens = ns ;
2199
			int eq = 0;
2178
	    /* QUERY: Any other restrictions? */
2200
			IDENTIFIER tid = make_friend_decl(ds, s, id, 0, 0);
2179
	    if ( IS_id_undef ( id ) ) {
2201
			if (do_dump) {
2180
		report ( crt_loc, ERR_lookup_qual_undef ( nm, ns ) ) ;
-
 
2181
		if ( IS_nspace_ctype ( ns ) ) itag = id_mem_func_tag ;
-
 
2182
		mem = search_member ( ns, nm, 1 ) ;
2202
				dump_declare(tid, &decl_loc, 0);
2183
		old_id = NULL_id ;
-
 
2184
	    } else {
2203
			}
2185
		mem = NULL_member ;
-
 
2186
		old_id = redecl_inherit ( id, cq, 0, 1 ) ;
2204
			id = deduce_func(tid, t, &eq);
2187
		t = bind_specialise ( &old_id, t, ds, 0, 0, def ) ;
-
 
2188
		if ( !IS_NULL_id ( old_id ) ) {
2205
			if (IS_NULL_id(id)) {
2189
		    id = old_id ;
2206
				return (tid);
2190
		    itag = TAG_id ( id ) ;
-
 
2191
		    ns = DEREF_nspace ( id_parent ( id ) ) ;
-
 
2192
		    ens = ns ;
2207
			}
2193
		    if ( def ) {
2208
			crt_templ_qualifier = 1;
2194
			/* Check enclosing namespace scope */
-
 
2195
			check_decl_nspace ( id, ns, def, nonclass_namespace ) ;
-
 
2196
		    }
-
 
2197
		}
2209
		}
2198
	    }
-
 
2199
	}
2210
	}
2336
/*
2441
/*
2337
    CHECK ON AN ANONYMOUS UNION
2442
    CHECK ON AN ANONYMOUS UNION
2338
 
2443
 
2339
    An anonymous union cannot have private or protected members or member
2444
    An anonymous union cannot have private or protected members or member
2340
    functions (in addition, no union can have static data members).  This
2445
    functions (in addition, no union can have static data members).  This
Line 2344... Line 2449...
2344
    ct is anonymous.
2449
    ct is anonymous.
2345
*/
2450
*/
2346
 
2451
 
2347
#if LANGUAGE_CPP
2452
#if LANGUAGE_CPP
2348
 
2453
 
2349
static void check_anon_union
2454
static void
2350
    PROTO_N ( ( ct ) )
-
 
2351
    PROTO_T ( CLASS_TYPE ct )
2455
check_anon_union(CLASS_TYPE ct)
2352
{
2456
{
2353
    CLASS_INFO ci = DEREF_cinfo ( ctype_info ( ct ) ) ;
2457
	CLASS_INFO ci = DEREF_cinfo(ctype_info(ct));
2354
    if ( ci & cinfo_private ) {
2458
	if (ci & cinfo_private) {
2355
	report ( crt_loc, ERR_class_union_anon_private () ) ;
2459
		report(crt_loc, ERR_class_union_anon_private());
2356
    }
2460
	}
2357
    if ( ci & cinfo_function ) {
2461
	if (ci & cinfo_function) {
2358
	report ( crt_loc, ERR_class_union_anon_func () ) ;
2462
		report(crt_loc, ERR_class_union_anon_func());
2359
    }
2463
	}
2360
    return ;
2464
	return;
2361
}
2465
}
2362
 
2466
 
2363
#endif
2467
#endif
2364
 
2468
 
2365
 
2469
 
Line 2371... Line 2475...
2371
    specifiers t (which may be an elaborate pre-type).  Whether this is
2475
    specifiers t (which may be an elaborate pre-type).  Whether this is
2372
    legal depends on the value of the flag have_type_specifier described
2476
    legal depends on the value of the flag have_type_specifier described
2373
    in predict.c, which indicates whether t contained a type declaration
2477
    in predict.c, which indicates whether t contained a type declaration
2374
    or definition.  Note that anonymous unions come under this heading
2478
    or definition.  Note that anonymous unions come under this heading
2375
    (I hate anonymous unions).
2479
    (I hate anonymous unions).
2482
	}
2599
	}
2483
	case TYPE_DECL_ANON : {
-
 
2484
	    report ( crt_loc, ERR_dcl_dcl_anon () ) ;
-
 
2485
	    break ;
-
 
2486
	}
2600
	}
2487
	case TYPE_DECL_OVER_ELAB : {
-
 
2488
	    report ( crt_loc, ERR_dcl_type_elab_qual ( key ) ) ;
-
 
2489
	    break ;
-
 
2490
	}
-
 
2491
    }
-
 
2492
    return ( tid ) ;
2601
	return (tid);
2493
}
2602
}
2494
 
2603
 
2495
 
2604
 
2496
/*
2605
/*
2497
    CHECK AN EMPTY MEMBER DECLARATION
2606
    CHECK AN EMPTY MEMBER DECLARATION
2498
 
2607
 
2499
    This routine handles a class member declaration with no declarators,
2608
    This routine handles a class member declaration with no declarators,
2500
    comprising the declaration specifiers ds, the template type qualifiers
2609
    comprising the declaration specifiers ds, the template type qualifiers
2501
    q and the type specifiers t.  This is similar to empty_object_decl,
2610
    q and the type specifiers t.  This is similar to empty_object_decl,
2502
    except that provision needs to be made for friend declarations of the
2611
    except that provision needs to be made for friend declarations of the
2503
    form 'friend class C'.
2612
    form 'friend class C'.
2683
/*
2796
/*
2684
    CHECK AN EMPTY DECLARATION
2797
    CHECK AN EMPTY DECLARATION
2685
 
2798
 
2686
    This routine checks the empty declaration declared with the declaration
2799
    This routine checks the empty declaration declared with the declaration
2687
    specifiers ds, the template type qualifiers q, the pre-type bt and t
2800
    specifiers ds, the template type qualifiers q, the pre-type bt and t
2688
    and the cv-qualifiers cv (not all of which will be empty).  The tok
2801
    and the cv-qualifiers cv (not all of which will be empty).  The tok
2689
    parameter is used to pass in the number of the last lexical token read,
2802
    parameter is used to pass in the number of the last lexical token read,
2690
    this is used for a backwards compatibility hack involving types such
2803
    this is used for a backwards compatibility hack involving types such
2691
    as wchar_t which used to be defined by typedefs, but are now keywords.
2804
    as wchar_t which used to be defined by typedefs, but are now keywords.
2692
    mem is true for member declarations.
2805
    mem is true for member declarations.
2693
*/
2806
*/
2694
 
2807
 
2695
IDENTIFIER empty_decl
2808
IDENTIFIER
2696
    PROTO_N ( ( ds, q, bt, t, cv, tok, mem ) )
-
 
2697
    PROTO_T ( DECL_SPEC ds X TYPE q X BASE_TYPE bt X TYPE t X
2809
empty_decl(DECL_SPEC ds, TYPE q, BASE_TYPE bt, TYPE t, CV_SPEC cv, int tok,
2698
	      CV_SPEC cv X int tok X int mem )
2810
	   int mem)
2699
{
2811
{
2700
    /* Check for empty declarations */
2812
	/* Check for empty declarations */
2701
    IDENTIFIER id ;
2813
	IDENTIFIER id;
2702
    int have_specifier = 1 ;
2814
	int have_specifier = 1;
2703
    decl_loc = crt_loc ;
2815
	decl_loc = crt_loc;
2704
    if ( ds == dspec_none && bt == btype_none && cv == cv_none ) {
2816
	if (ds == dspec_none && bt == btype_none && cv == cv_none) {
2705
	if ( IS_NULL_type ( q ) ) {
2817
		if (IS_NULL_type(q)) {
2706
	    if ( IS_NULL_type ( t ) ) {
2818
			if (IS_NULL_type(t)) {
2707
		/* Only semicolon in declaration */
2819
				/* Only semicolon in declaration */
2708
		if ( mem ) {
2820
				if (mem) {
2709
		    if ( tok != lex_func_Hop ) {
2821
					if (tok != lex_func_Hop) {
2710
			/* Allowed after function definition */
2822
						/* Allowed after function
-
 
2823
						 * definition */
2711
			report ( crt_loc, ERR_class_mem_semicolon () ) ;
2824
						report(crt_loc, ERR_class_mem_semicolon());
2712
		    }
2825
					}
2713
		} else {
2826
				} else {
-
 
2827
					report(crt_loc,
2714
		    report ( crt_loc, ERR_dcl_dcl_semicolon () ) ;
2828
					       ERR_dcl_dcl_semicolon());
2715
		}
2829
				}
2716
		return ( NULL_id ) ;
2830
				return (NULL_id);
2717
	    }
2831
			}
2718
	    if ( have_type_declaration == TYPE_DECL_NONE ) {
2832
			if (have_type_declaration == TYPE_DECL_NONE) {
2719
		/* No type specifier in declaration */
2833
				/* No type specifier in declaration */
2720
		have_specifier = 0 ;
2834
				have_specifier = 0;
2721
	    }
2835
			}
2722
	}
2836
		}
2723
    }
2837
	}
2724
 
2838
 
2725
    /* Check for definitions of built-in types */
2839
	/* Check for definitions of built-in types */
2726
    if ( ( ds & dspec_typedef ) && !mem ) {
2840
	if ((ds & dspec_typedef) && !mem) {
2727
	BASE_TYPE bs = key_type ( tok ) ;
2841
		BASE_TYPE bs = key_type(tok);
2728
	if ( bs ) {
2842
		if (bs) {
2729
	    /* Type is now a keyword */
2843
			/* Type is now a keyword */
2730
	    HASHID nm = KEYWORD ( tok ) ;
2844
			HASHID nm = KEYWORD(tok);
2731
	    id = DEREF_id ( hashid_id ( nm ) ) ;
2845
			id = DEREF_id(hashid_id(nm));
2732
	    bt &= ~bs ;
2846
			bt &= ~bs;
2733
	    t = complete_pre_type ( bt, t, cv, 0 ) ;
2847
			t = complete_pre_type(bt, t, cv, 0);
2734
	    report ( crt_loc, ERR_lex_key_word ( tok ) ) ;
2848
			report(crt_loc, ERR_lex_key_word(tok));
2735
	    crt_id_qualifier = qual_none ;
2849
			crt_id_qualifier = qual_none;
2736
	    crt_templ_qualifier = 0 ;
2850
			crt_templ_qualifier = 0;
2737
	    id = make_object_decl ( ds, t, id, 0 ) ;
2851
			id = make_object_decl(ds, t, id, 0);
2738
	    return ( id ) ;
2852
			return (id);
2739
	}
2853
		}
2740
    }
2854
	}
2741
 
2855
 
2742
    /* Check for type access declarations */
2856
	/* Check for type access declarations */
2743
    if ( !have_specifier && mem ) {
2857
	if (!have_specifier && mem) {
2744
	if ( !IS_NULL_type ( t ) && IS_type_pre ( t ) ) {
2858
		if (!IS_NULL_type(t) && IS_type_pre(t)) {
2745
	    BASE_TYPE key = DEREF_btype ( type_pre_rep ( t ) ) ;
2859
			BASE_TYPE key = DEREF_btype(type_pre_rep(t));
2746
	    if ( key == btype_alias ) {
2860
			if (key == btype_alias) {
2747
		IDENTIFIER tid = DEREF_id ( type_name ( t ) ) ;
2861
				IDENTIFIER tid = DEREF_id(type_name(t));
2748
		QUALIFIER qual = DEREF_qual ( type_pre_nqual ( t ) ) ;
2862
				QUALIFIER qual = DEREF_qual(type_pre_nqual(t));
2749
		if ( qual && !IS_NULL_id ( tid ) ) {
2863
				if (qual && !IS_NULL_id(tid)) {
2750
		    id = access_decl ( tid ) ;
2864
					id = access_decl(tid);
2751
		    return ( id ) ;
2865
					return (id);
2752
		}
2866
				}
2753
	    }
2867
			}
2754
	}
2868
		}
2755
    }
2869
	}
2756
 
2870
 
2757
    /* Perform the declaration */
2871
	/* Perform the declaration */
2758
    t = empty_complete_pre_type ( bt, t, cv, 0 ) ;
2872
	t = empty_complete_pre_type(bt, t, cv, 0);
2759
    if ( mem ) {
2873
	if (mem) {
2760
	report ( crt_loc, ERR_class_mem_declarator () ) ;
2874
		report(crt_loc, ERR_class_mem_declarator());
2761
	id = empty_member_decl ( ds, q, t ) ;
2875
		id = empty_member_decl(ds, q, t);
2762
    } else {
2876
	} else {
2763
	id = empty_object_decl ( ds, q, t ) ;
2877
		id = empty_object_decl(ds, q, t);
2764
    }
2878
	}
2765
    if ( in_weak_param ) {
2879
	if (in_weak_param) {
2766
	/* Shouldn't happen in parameter declaration lists */
2880
		/* Shouldn't happen in parameter declaration lists */
2767
	report ( crt_loc, ERR_dcl_fct_par_none () ) ;
2881
		report(crt_loc, ERR_dcl_fct_par_none());
2768
    }
2882
	}
2769
    return ( id ) ;
2883
	return (id);
2770
}
2884
}
2771
 
2885
 
2772
 
2886
 
2773
/*
2887
/*
2774
    UPDATE EXTERNAL DECLARATION INFORMATION
2888
    UPDATE EXTERNAL DECLARATION INFORMATION
2775
 
2889
 
2776
    This routine is called after each external declaration.  d gives
2890
    This routine is called after each external declaration.  d gives
2777
    the number of objects declared and e gives the associated expression
2891
    the number of objects declared and e gives the associated expression
2778
    for an asm definition.  Note that this is the point of instantiation
2892
    for an asm definition.  Note that this is the point of instantiation
2779
    for any pending templates.
2893
    for any pending templates.
2780
*/
2894
*/
2781
 
2895
 
2782
void external_declaration
2896
void
2783
    PROTO_N ( ( e, d ) )
-
 
2784
    PROTO_T ( EXP e X int d )
2897
external_declaration(EXP e, int d)
2785
{
2898
{
2786
    if ( crt_file_type == 0 ) {
2899
	if (crt_file_type == 0) {
2787
	no_declarations += ( unsigned long ) d ;
2900
		no_declarations += (unsigned long)d;
2788
    }
-
 
2789
    if ( !IS_NULL_exp ( e ) ) {
-
 
2790
	/* Compile any asm definitions */
-
 
2791
	compile_asm ( e ) ;
-
 
2792
    }
-
 
2793
    if ( !in_preproc_dir ) {
-
 
2794
	if ( crt_access_list.pending ) {
-
 
2795
	    /* Clear any outstanding access checks */
-
 
2796
	    IGNORE report_access ( NULL_id ) ;
-
 
2797
	}
2901
	}
-
 
2902
	if (!IS_NULL_exp(e)) {
-
 
2903
		/* Compile any asm definitions */
-
 
2904
		compile_asm(e);
-
 
2905
	}
-
 
2906
	if (!in_preproc_dir) {
-
 
2907
		if (crt_access_list.pending) {
-
 
2908
			/* Clear any outstanding access checks */
-
 
2909
			IGNORE report_access(NULL_id);
-
 
2910
		}
2798
	if ( !IS_NULL_list ( pending_templates ) ) {
2911
		if (!IS_NULL_list(pending_templates)) {
2799
	    /* Instantiate any pending templates */
2912
			/* Instantiate any pending templates */
2800
	    clear_templates ( 0 ) ;
2913
			clear_templates(0);
-
 
2914
		}
2801
	}
2915
	}
2802
    }
-
 
2803
    return ;
2916
	return;
2804
}
2917
}