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/tokdef.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 84... Line 114...
84
    is set.  This is only done if we are reasonably sure that the equality
114
    is set.  This is only done if we are reasonably sure that the equality
85
    should hold.  Similarly template specialisation is only considered
115
    should hold.  Similarly template specialisation is only considered
86
    if force_template is true.
116
    if force_template is true.
87
*/
117
*/
88
 
118
 
89
int force_tokdef = 0 ;
119
int force_tokdef = 0;
90
int force_template = 0 ;
120
int force_template = 0;
91
int expand_tokdef = 0 ;
121
int expand_tokdef = 0;
92
 
122
 
93
 
123
 
94
/*
124
/*
95
    IS A TOKEN BEING DEFINED?
125
    IS A TOKEN BEING DEFINED?
96
 
126
 
97
    This routine uses the values force_tokdef and force_template to
127
    This routine uses the values force_tokdef and force_template to
98
    determine whether the token id is available for token unification.
128
    determine whether the token id is available for token unification.
99
*/
129
*/
100
 
130
 
101
int defining_token
131
int
102
    PROTO_N ( ( id ) )
-
 
103
    PROTO_T ( IDENTIFIER id )
132
defining_token(IDENTIFIER id)
104
{
133
{
105
    if ( !IS_NULL_id ( id ) && IS_id_token ( id ) ) {
134
	if (!IS_NULL_id(id) && IS_id_token(id)) {
106
	DECL_SPEC ds ;
135
		DECL_SPEC ds;
107
	if ( force_tokdef ) return ( 1 ) ;
136
		if (force_tokdef) {
-
 
137
			return (1);
-
 
138
		}
108
	ds = DEREF_dspec ( id_storage ( id ) ) ;
139
		ds = DEREF_dspec(id_storage(id));
109
	if ( ds & dspec_template ) return ( force_template ) ;
140
		if (ds & dspec_template) {
-
 
141
			return (force_template);
110
    }
142
		}
-
 
143
	}
111
    return ( 0 ) ;
144
	return (0);
112
}
145
}
113
 
146
 
114
 
147
 
115
/*
148
/*
116
    FIND THE RESULT COMPONENT OF A TOKEN
149
    FIND THE RESULT COMPONENT OF A TOKEN
117
 
150
 
118
    This routine finds the result component of the token id.
151
    This routine finds the result component of the token id.
119
*/
152
*/
120
 
153
 
121
TOKEN find_tokdef
154
TOKEN
122
    PROTO_N ( ( id ) )
-
 
123
    PROTO_T ( IDENTIFIER id )
155
find_tokdef(IDENTIFIER id)
124
{
156
{
125
    TOKEN tok = NULL_tok ;
157
	TOKEN tok = NULL_tok;
126
    if ( !IS_NULL_id ( id ) && IS_id_token ( id ) ) {
158
	if (!IS_NULL_id(id) && IS_id_token(id)) {
127
	unsigned tag ;
159
		unsigned tag;
128
	tok = DEREF_tok ( id_token_sort ( id ) ) ;
160
		tok = DEREF_tok(id_token_sort(id));
129
	tag = TAG_tok ( tok ) ;
161
		tag = TAG_tok(tok);
130
	if ( tag == tok_func_tag ) {
162
		if (tag == tok_func_tag) {
131
	    TOKEN ptok = DEREF_tok ( tok_func_proc ( tok ) ) ;
163
			TOKEN ptok = DEREF_tok(tok_func_proc(tok));
132
	    if ( !IS_NULL_tok ( ptok ) ) {
164
			if (!IS_NULL_tok(ptok)) {
133
		tok = DEREF_tok ( tok_proc_res ( ptok ) ) ;
165
				tok = DEREF_tok(tok_proc_res(ptok));
134
	    }
166
			}
135
	} else if ( tag == tok_proc_tag ) {
167
		} else if (tag == tok_proc_tag) {
136
	    tok = DEREF_tok ( tok_proc_res ( tok ) ) ;
168
			tok = DEREF_tok(tok_proc_res(tok));
137
	}
169
		}
138
    }
170
	}
139
    return ( tok ) ;
171
	return (tok);
140
}
172
}
141
 
173
 
142
 
174
 
143
/*
175
/*
144
    DUMMY TOKEN PARAMETER VALUES
176
    DUMMY TOKEN PARAMETER VALUES
145
 
177
 
146
    These values are used to indicate that a token parameter has been
178
    These values are used to indicate that a token parameter has been
147
    redefined inconsistently.
179
    redefined inconsistently.
148
*/
180
*/
149
 
181
 
150
static NAT redef_nat = NULL_nat ;
182
static NAT redef_nat = NULL_nat;
151
static EXP redef_exp = NULL_exp ;
183
static EXP redef_exp = NULL_exp;
152
TYPE redef_type = NULL_type ;
184
TYPE redef_type = NULL_type;
153
static IDENTIFIER redef_id = NULL_id ;
185
static IDENTIFIER redef_id = NULL_id;
154
static OFFSET redef_off = NULL_off ;
186
static OFFSET redef_off = NULL_off;
155
 
187
 
156
 
188
 
157
/*
189
/*
158
    INITIALISE DUMMY TOKEN PARAMETER VALUES
190
    INITIALISE DUMMY TOKEN PARAMETER VALUES
159
 
191
 
160
    This routine initialises the dummy token parameter values above.
192
    This routine initialises the dummy token parameter values above.
161
    They are set to impossible values which could not arise naturally.
193
    They are set to impossible values which could not arise naturally.
162
*/
194
*/
163
 
195
 
164
void init_token_args
196
void
165
    PROTO_Z ()
197
init_token_args(void)
166
{
198
{
167
    HASHID nm = KEYWORD ( lex_error ) ;
199
	HASHID nm = KEYWORD(lex_error);
168
    redef_id = DEREF_id ( hashid_id ( nm ) ) ;
200
	redef_id = DEREF_id(hashid_id(nm));
169
    MAKE_type_ref ( cv_none, type_void, redef_type ) ;
201
	MAKE_type_ref(cv_none, type_void, redef_type);
170
    MAKE_exp_value ( redef_type, redef_exp ) ;
202
	MAKE_exp_value(redef_type, redef_exp);
171
    MAKE_nat_calc ( redef_exp, redef_nat ) ;
203
	MAKE_nat_calc(redef_exp, redef_nat);
172
    MAKE_off_zero ( redef_type, redef_off ) ;
204
	MAKE_off_zero(redef_type, redef_off);
173
    return ;
205
	return;
174
}
206
}
175
 
207
 
176
 
208
 
177
/*
209
/*
178
    DEFINE AN INTEGER CONSTANT TOKEN
210
    DEFINE AN INTEGER CONSTANT TOKEN
179
 
211
 
180
    This routine defines the integer constant token id to be e.  It
212
    This routine defines the integer constant token id to be e.  It
181
    returns true if the token is assigned a value.
213
    returns true if the token is assigned a value.
182
*/
214
*/
183
 
215
 
184
int define_nat_token
216
int
185
    PROTO_N ( ( id, n ) )
-
 
186
    PROTO_T ( IDENTIFIER id X NAT n )
217
define_nat_token(IDENTIFIER id, NAT n)
187
{
218
{
188
    if ( !IS_NULL_nat ( n ) ) {
219
	if (!IS_NULL_nat(n)) {
189
	DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
220
		DECL_SPEC ds = DEREF_dspec(id_storage(id));
190
	if ( !( ds & dspec_pure ) ) {
221
		if (!(ds & dspec_pure)) {
191
	    int ok = 1 ;
222
			int ok = 1;
192
	    TOKEN tok = find_tokdef ( id ) ;
223
			TOKEN tok = find_tokdef(id);
193
	    if ( IS_NULL_tok ( tok ) ) return ( 0 ) ;
224
			if (IS_NULL_tok(tok)) {
-
 
225
				return (0);
-
 
226
			}
194
	    switch ( TAG_tok ( tok ) ) {
227
			switch (TAG_tok(tok)) {
195
		case tok_nat_tag :
228
			case tok_nat_tag:
196
		case tok_snat_tag : {
229
			case tok_snat_tag: {
197
		    /* Integer constant tokens */
230
				/* Integer constant tokens */
198
		    NAT m = DEREF_nat ( tok_nat_etc_value ( tok ) ) ;
231
				NAT m = DEREF_nat(tok_nat_etc_value(tok));
199
		    if ( !IS_NULL_nat ( m ) && !eq_nat ( n, m ) ) {
232
				if (!IS_NULL_nat(m) && !eq_nat(n, m)) {
200
			if ( ds & dspec_auto ) {
233
					if (ds & dspec_auto) {
201
			    n = redef_nat ;
234
						n = redef_nat;
202
			} else {
235
					} else {
203
			    PTR ( LOCATION ) loc = id_loc ( id ) ;
236
						PTR(LOCATION) loc = id_loc(id);
204
			    report ( crt_loc, ERR_token_redef ( id, loc ) ) ;
237
						report(crt_loc, ERR_token_redef(id, loc));
-
 
238
					}
-
 
239
					ok = 0;
-
 
240
				}
-
 
241
				COPY_nat(tok_nat_etc_value(tok), n);
-
 
242
				break;
-
 
243
			}
-
 
244
			case tok_exp_tag:
-
 
245
			case tok_stmt_tag: {
-
 
246
				/* Expression tokens */
-
 
247
				EXP e = calc_nat_value(n, type_sint);
-
 
248
				return (define_exp_token(id, e, 1));
205
			}
249
			}
206
			ok = 0 ;
250
			default:
207
		    }
251
				/* Other tokens */
208
		    COPY_nat ( tok_nat_etc_value ( tok ), n ) ;
-
 
209
		    break ;
252
				return (0);
210
		}
253
			}
-
 
254
 
211
		case tok_exp_tag :
255
			if (!(ds & dspec_auto)) {
212
		case tok_stmt_tag : {
256
				no_token_defns++;
213
		    /* Expression tokens */
-
 
214
		    EXP e = calc_nat_value ( n, type_sint ) ;
-
 
215
		    return ( define_exp_token ( id, e, 1 ) ) ;
-
 
216
		}
257
			}
217
		default : {
258
			ds |= dspec_defn;
218
		    /* Other tokens */
259
			COPY_dspec(id_storage(id), ds);
-
 
260
			COPY_loc(id_loc(id), crt_loc);
219
		    return ( 0 ) ;
261
			return (ok);
220
		}
262
		}
221
	    }
-
 
222
	    if ( !( ds & dspec_auto ) ) no_token_defns++ ;
-
 
223
	    ds |= dspec_defn ;
-
 
224
	    COPY_dspec ( id_storage ( id ), ds ) ;
-
 
225
	    COPY_loc ( id_loc ( id ), crt_loc ) ;
-
 
226
	    return ( ok ) ;
-
 
227
	}
263
	}
228
    }
-
 
229
    return ( 0 ) ;
264
	return (0);
230
}
265
}
231
 
266
 
232
 
267
 
233
/*
268
/*
234
    DEFINE AN EXPRESSION TOKEN
269
    DEFINE AN EXPRESSION TOKEN
235
 
270
 
236
    This routine defines the expression, statement or integer constant
271
    This routine defines the expression, statement or integer constant
237
    token id to be e.  It returns true if the token is assigned a value.
272
    token id to be e.  It returns true if the token is assigned a value.
238
    expl is false for an enforcing external declaration, such as that
273
    expl is false for an enforcing external declaration, such as that
239
    arising from unify_id.
274
    arising from unify_id.
240
*/
275
*/
241
 
276
 
242
int define_exp_token
277
int
243
    PROTO_N ( ( id, e, expl ) )
-
 
244
    PROTO_T ( IDENTIFIER id X EXP e X int expl )
278
define_exp_token(IDENTIFIER id, EXP e, int expl)
245
{
279
{
246
    if ( !IS_NULL_exp ( e ) ) {
280
    if (!IS_NULL_exp(e)) {
247
	DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
281
	DECL_SPEC ds = DEREF_dspec(id_storage(id));
248
	if ( !( ds & dspec_pure ) ) {
282
	if (!(ds & dspec_pure)) {
249
	    int ok = 1 ;
283
	    int ok = 1;
250
	    unsigned tt ;
284
	    unsigned tt;
251
	    TOKEN tok = find_tokdef ( id ) ;
285
	    TOKEN tok = find_tokdef(id);
252
	    if ( IS_NULL_tok ( tok ) ) return ( 0 ) ;
286
	    if (IS_NULL_tok(tok)) {
-
 
287
		    return (0);
-
 
288
	    }
253
	    tt = TAG_tok ( tok ) ;
289
	    tt = TAG_tok(tok);
254
	    switch ( tt ) {
290
	    switch (tt) {
255
 
-
 
256
		case tok_exp_tag : {
291
		case tok_exp_tag: {
257
		    /* Expression tokens */
292
		    /* Expression tokens */
258
		    TYPE s ;
293
		    TYPE s;
259
		    ERROR err = NULL_err ;
294
		    ERROR err = NULL_err;
260
		    unsigned etag = TAG_exp ( e ) ;
295
		    unsigned etag = TAG_exp(e);
261
		    EXP d = DEREF_exp ( tok_exp_value ( tok ) ) ;
296
		    EXP d = DEREF_exp(tok_exp_value(tok));
262
		    int c = DEREF_int ( tok_exp_constant ( tok ) ) ;
297
		    int c = DEREF_int(tok_exp_constant(tok));
263
		    TYPE t = DEREF_type ( tok_exp_type ( tok ) ) ;
298
		    TYPE t = DEREF_type(tok_exp_type(tok));
264
		    CV_SPEC cv = DEREF_cv ( type_qual ( t ) ) ;
299
		    CV_SPEC cv = DEREF_cv(type_qual(t));
265
		    LIST ( IDENTIFIER ) pids = NULL_list ( IDENTIFIER ) ;
300
		    LIST(IDENTIFIER) pids = NULL_list(IDENTIFIER);
266
		    force_tokdef++ ;
301
		    force_tokdef++;
267
		    e = convert_reference ( e, REF_ASSIGN ) ;
302
		    e = convert_reference(e, REF_ASSIGN);
268
		    e = resolve_cast ( t, e, &err, 1, 0, pids ) ;
303
		    e = resolve_cast(t, e, &err, 1, 0, pids);
269
		    s = DEREF_type ( exp_type ( e ) ) ;
304
		    s = DEREF_type(exp_type(e));
270
		    if ( cv & cv_lvalue ) {
305
		    if (cv & cv_lvalue) {
271
			/* lvalue tokens */
306
			/* lvalue tokens */
272
			cv = DEREF_cv ( type_qual ( s ) ) ;
307
			cv = DEREF_cv(type_qual(s));
273
			if ( cv & cv_lvalue ) {
308
			if (cv & cv_lvalue) {
274
			    if ( eq_type ( s, t ) ) {
309
			    if (eq_type(s, t)) {
275
				if ( !IS_exp_address ( e ) ) {
310
				if (!IS_exp_address(e)) {
276
				    MAKE_exp_address ( t, e, e ) ;
311
				    MAKE_exp_address(t, e, e);
277
				}
312
				}
278
			    } else {
313
			    } else {
279
				EXP a = init_ref_lvalue ( t, e, &err ) ;
314
				EXP a = init_ref_lvalue(t, e, &err);
280
				if ( IS_NULL_exp ( a ) ) {
315
				if (IS_NULL_exp(a)) {
281
				    err = ERR_basic_link_incompat ( t, s ) ;
316
				    err = ERR_basic_link_incompat(t, s);
282
				} else {
317
				} else {
283
				    e = make_ref_init ( t, a ) ;
318
				    e = make_ref_init(t, a);
284
				}
319
				}
285
			    }
320
			    }
286
			} else {
321
			} else {
287
			    report ( crt_loc, ERR_token_arg_lvalue ( id ) ) ;
322
			    report(crt_loc, ERR_token_arg_lvalue(id));
288
			}
323
			}
289
		    } else {
324
		    } else {
290
			/* rvalue tokens */
325
			/* rvalue tokens */
291
			if ( IS_exp_aggregate ( e ) ) {
326
			if (IS_exp_aggregate(e)) {
292
			    /* Aggregate initialiser */
327
			    /* Aggregate initialiser */
293
			    e = init_aggregate ( t, e, id, &err ) ;
328
			    e = init_aggregate(t, e, id, &err);
294
			} else {
329
			} else {
295
			    switch ( TAG_type ( t ) ) {
330
			    switch (TAG_type(t)) {
296
				case type_top_tag :
331
				case type_top_tag:
297
				case type_bottom_tag : {
332
				case type_bottom_tag:
298
				    /* Void expressions */
333
				    /* Void expressions */
299
				    e = convert_lvalue ( e ) ;
334
				    e = convert_lvalue(e);
300
				    e = convert_none ( e ) ;
335
				    e = convert_none(e);
301
				    e = make_discard_exp ( e ) ;
336
				    e = make_discard_exp(e);
302
				    if ( !IS_type_top_etc ( s ) ) {
337
				    if (!IS_type_top_etc(s)) {
303
					EXP a = make_null_exp ( t ) ;
338
					EXP a = make_null_exp(t);
304
					e = join_exp ( e, a ) ;
339
					e = join_exp(e, a);
305
				    }
340
				    }
306
				    break ;
341
				    break;
307
				}
-
 
308
				case type_ref_tag : {
342
				case type_ref_tag:
309
				    /* Reference initialiser */
343
				    /* Reference initialiser */
310
				    e = init_assign ( t, cv_none, e, &err ) ;
344
				    e = init_assign(t, cv_none, e, &err);
311
				    break ;
345
				    break;
312
				}
-
 
313
				case type_array_tag : {
346
				case type_array_tag:
314
				    /* Array initialiser */
347
				    /* Array initialiser */
315
				    if ( etag == exp_paren_tag ) {
348
				    if (etag == exp_paren_tag) {
316
					e = make_paren_exp ( e ) ;
349
					e = make_paren_exp(e);
317
				    }
350
				    }
318
				    e = init_array ( t, cv_none, e, 1, &err ) ;
351
				    e = init_array(t, cv_none, e, 1, &err);
319
				    break ;
352
				    break;
320
				}
-
 
321
				case type_error_tag : {
353
				case type_error_tag:
322
				    e = convert_none ( e ) ;
354
				    e = convert_none(e);
323
				    break ;
355
				    break;
324
				}
-
 
325
				default : {
356
				default:
326
				    /* Simple initialiser */
357
				    /* Simple initialiser */
327
				    e = convert_lvalue ( e ) ;
358
				    e = convert_lvalue(e);
328
				    e = init_assign ( t, cv_none, e, &err ) ;
359
				    e = init_assign(t, cv_none, e, &err);
329
				    break ;
360
				    break;
330
				}
-
 
331
			    }
361
			    }
332
			}
362
			}
333
		    }
363
		    }
334
		    force_tokdef-- ;
364
		    force_tokdef--;
335
		    if ( !IS_NULL_err ( err ) ) {
365
		    if (!IS_NULL_err(err)) {
336
			/* Conversion error */
366
			/* Conversion error */
337
			err = init_error ( err, 0 ) ;
367
			err = init_error(err, 0);
338
			err = concat_error ( err, ERR_token_arg_exp ( id ) ) ;
368
			err = concat_error(err, ERR_token_arg_exp(id));
339
			report ( crt_loc, err ) ;
369
			report(crt_loc, err);
340
		    }
370
		    }
341
		    if ( c == 1 && !is_const_exp ( e, 1 ) ) {
371
		    if (c == 1 && !is_const_exp(e, 1)) {
342
			report ( crt_loc, ERR_token_arg_const ( id ) ) ;
372
			report(crt_loc, ERR_token_arg_const(id));
343
		    }
373
		    }
344
		    if ( !IS_NULL_exp ( d ) && !eq_exp ( e, d, 0 ) ) {
374
		    if (!IS_NULL_exp(d) && !eq_exp(e, d, 0)) {
345
			int redef = 0 ;
375
			int redef = 0;
346
			if ( ds & dspec_auto ) {
376
			if (ds & dspec_auto) {
347
			    e = redef_exp ;
377
			    e = redef_exp;
348
			} else {
378
			} else {
349
			    if ( expl ) {
379
			    if (expl) {
350
				if ( ds & dspec_main ) {
380
				if (ds & dspec_main) {
351
				    redef = 1 ;
381
				    redef = 1;
352
				} else {
382
				} else {
353
				    ds |= dspec_main ;
383
				    ds |= dspec_main;
354
				}
384
				}
355
			    } else {
385
			    } else {
356
				if ( ds & dspec_main ) {
386
				if (ds & dspec_main) {
357
				    e = d ;
387
				    e = d;
358
				} else {
388
				} else {
359
				    redef = 1 ;
389
				    redef = 1;
360
				}
390
				}
361
			    }
391
			    }
362
			}
392
			}
363
			if ( redef ) {
393
			if (redef) {
364
			    PTR ( LOCATION ) loc = id_loc ( id ) ;
394
			    PTR(LOCATION) loc = id_loc(id);
365
			    report ( crt_loc, ERR_token_redef ( id, loc ) ) ;
395
			    report(crt_loc, ERR_token_redef(id, loc));
366
			    ok = 0 ;
396
			    ok = 0;
367
			}
397
			}
368
		    } else {
398
		    } else {
369
			if ( expl && !( ds & dspec_auto ) ) {
399
			if (expl && !(ds & dspec_auto)) {
370
			    /* Mark explicit definitions */
400
			    /* Mark explicit definitions */
371
			    ds |= dspec_main ;
401
			    ds |= dspec_main;
372
			}
402
			}
373
		    }
403
		    }
374
		    COPY_exp ( tok_exp_value ( tok ), e ) ;
404
		    COPY_exp(tok_exp_value(tok), e);
375
		    break ;
405
		    break;
376
		}
406
		}
377
 
407
 
378
		case tok_nat_tag :
408
		case tok_nat_tag:
379
		case tok_snat_tag : {
409
		case tok_snat_tag: {
380
		    /* Constant tokens */
410
		    /* Constant tokens */
381
		    NAT n ;
411
		    NAT n;
382
		    ERROR err = NULL_err ;
412
		    ERROR err = NULL_err;
383
		    e = convert_reference ( e, REF_NORMAL ) ;
413
		    e = convert_reference(e, REF_NORMAL);
384
		    e = convert_lvalue ( e ) ;
414
		    e = convert_lvalue(e);
385
		    n = make_nat_exp ( e, &err ) ;
415
		    n = make_nat_exp(e, &err);
386
		    if ( !IS_NULL_err ( err ) ) {
416
		    if (!IS_NULL_err(err)) {
387
			/* Not a constant expression */
417
			/* Not a constant expression */
388
			err = concat_error ( err, ERR_token_arg_nat ( id ) ) ;
418
			err = concat_error(err, ERR_token_arg_nat(id));
389
			report ( crt_loc, err ) ;
419
			report(crt_loc, err);
390
		    } else {
420
		    } else {
391
			if ( tt == tok_nat_tag && is_negative_nat ( n ) ) {
421
			if (tt == tok_nat_tag && is_negative_nat(n)) {
392
			    /* Negative constant */
422
			    /* Negative constant */
393
			    report ( crt_loc, ERR_token_arg_nat ( id ) ) ;
423
			    report(crt_loc, ERR_token_arg_nat(id));
394
			    n = negate_nat ( n ) ;
424
			    n = negate_nat(n);
395
			}
425
			}
396
		    }
426
		    }
397
		    return ( define_nat_token ( id, n ) ) ;
427
		    return (define_nat_token(id, n));
398
		}
428
		}
399
 
429
 
400
		case tok_stmt_tag : {
430
		case tok_stmt_tag: {
401
		    /* Statement tokens */
431
		    /* Statement tokens */
402
		    EXP d = DEREF_exp ( tok_stmt_value ( tok ) ) ;
432
		    EXP d = DEREF_exp(tok_stmt_value(tok));
403
		    if ( !IS_NULL_exp ( d ) && !eq_exp ( e, d, 0 ) ) {
433
		    if (!IS_NULL_exp(d) && !eq_exp(e, d, 0)) {
404
			if ( ds & dspec_auto ) {
434
			if (ds & dspec_auto) {
405
			    e = redef_exp ;
435
			    e = redef_exp;
406
			} else {
436
			} else {
407
			    PTR ( LOCATION ) loc = id_loc ( id ) ;
437
			    PTR(LOCATION) loc = id_loc(id);
408
			    report ( crt_loc, ERR_token_redef ( id, loc ) ) ;
438
			    report(crt_loc, ERR_token_redef(id, loc));
409
			}
439
			}
410
			ok = 0 ;
440
			ok = 0;
411
		    }
441
		    }
412
		    COPY_exp ( tok_stmt_value ( tok ), e ) ;
442
		    COPY_exp(tok_stmt_value(tok), e);
413
		    break ;
443
		    break;
414
		}
444
		}
415
 
445
 
416
		default : {
446
		default:
417
		    /* Other tokens */
447
		    /* Other tokens */
418
		    return ( 0 ) ;
448
		    return (0);
419
		}
-
 
420
	    }
449
	    }
421
	    if ( !( ds & dspec_auto ) ) no_token_defns++ ;
450
	    if (!(ds & dspec_auto)) {
-
 
451
		    no_token_defns++;
-
 
452
	    }
422
	    ds |= dspec_defn ;
453
	    ds |= dspec_defn;
423
	    COPY_dspec ( id_storage ( id ), ds ) ;
454
	    COPY_dspec(id_storage(id), ds);
424
	    COPY_loc ( id_loc ( id ), crt_loc ) ;
455
	    COPY_loc(id_loc(id), crt_loc);
425
	    return ( ok ) ;
456
	    return (ok);
426
	}
457
	}
427
    }
458
    }
428
    return ( 0 ) ;
459
    return (0);
429
}
460
}
430
 
461
 
431
 
462
 
432
/*
463
/*
433
    DEFINE THE FIELDS OF A TYPE TOKEN
464
    DEFINE THE FIELDS OF A TYPE TOKEN
434
 
465
 
435
    This routine is called when a tokenised structure or union id is defined
466
    This routine is called when a tokenised structure or union id is defined
436
    by the compound type t.  It checks for any tokenised members of id
467
    by the compound type t.  It checks for any tokenised members of id
437
    which may also be defined as a result of this identification.  This
468
    which may also be defined as a result of this identification.  This
438
    should really be done by the class merging routines.
469
    should really be done by the class merging routines.
439
*/
470
*/
440
 
471
 
441
static void define_field_tokens
472
static void
442
    PROTO_N ( ( id, t ) )
-
 
443
    PROTO_T ( IDENTIFIER id X TYPE t )
473
define_field_tokens(IDENTIFIER id, TYPE t)
444
{
474
{
445
    IDENTIFIER tid = DEREF_id ( id_token_alt ( id ) ) ;
475
    IDENTIFIER tid = DEREF_id(id_token_alt(id));
446
    unsigned tag = TAG_id ( tid ) ;
476
    unsigned tag = TAG_id(tid);
447
    if ( tag == id_class_name_tag || tag == id_class_alias_tag ) {
477
    if (tag == id_class_name_tag || tag == id_class_alias_tag) {
448
	TYPE s = DEREF_type ( id_class_name_etc_defn ( tid ) ) ;
478
	TYPE s = DEREF_type(id_class_name_etc_defn(tid));
449
	if ( IS_type_compound ( s ) && IS_type_compound ( t ) ) {
479
	if (IS_type_compound(s) && IS_type_compound(t)) {
450
	    MEMBER mem ;
480
	    MEMBER mem;
451
	    CLASS_TYPE cs = DEREF_ctype ( type_compound_defn ( s ) ) ;
481
	    CLASS_TYPE cs = DEREF_ctype(type_compound_defn(s));
452
	    CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
482
	    CLASS_TYPE ct = DEREF_ctype(type_compound_defn(t));
453
	    NAMESPACE ns = DEREF_nspace ( ctype_member ( cs ) ) ;
483
	    NAMESPACE ns = DEREF_nspace(ctype_member(cs));
454
	    NAMESPACE nt = DEREF_nspace ( ctype_member ( ct ) ) ;
484
	    NAMESPACE nt = DEREF_nspace(ctype_member(ct));
455
 
485
 
456
	    /* Check that keys match for type aliases */
486
	    /* Check that keys match for type aliases */
457
	    if ( tag == id_class_alias_tag ) {
487
	    if (tag == id_class_alias_tag) {
458
		BASE_TYPE bs = find_class_key ( cs ) ;
488
		BASE_TYPE bs = find_class_key(cs);
459
		BASE_TYPE bt = find_class_key ( ct ) ;
489
		BASE_TYPE bt = find_class_key(ct);
460
		if ( !equal_key ( bs, bt ) ) {
490
		if (!equal_key(bs, bt)) {
461
		    PTR ( LOCATION ) loc = id_loc ( id ) ;
491
		    PTR(LOCATION) loc = id_loc(id);
462
		    ERROR err = ERR_dcl_type_elab_bad ( bt, bs, id, loc ) ;
492
		    ERROR err = ERR_dcl_type_elab_bad(bt, bs, id, loc);
463
		    report ( crt_loc, err ) ;
493
		    report(crt_loc, err);
464
		}
494
		}
465
	    }
495
	    }
466
 
496
 
467
	    /* Scan through members of ns */
497
	    /* Scan through members of ns */
468
	    mem = DEREF_member ( nspace_ctype_first ( ns ) ) ;
498
	    mem = DEREF_member(nspace_ctype_first(ns));
469
	    while ( !IS_NULL_member ( mem ) ) {
499
	    while (!IS_NULL_member(mem)) {
470
		IDENTIFIER mid = DEREF_id ( member_id ( mem ) ) ;
500
		IDENTIFIER mid = DEREF_id(member_id(mem));
471
		if ( !IS_NULL_id ( mid ) && IS_id_member ( mid ) ) {
501
		if (!IS_NULL_id(mid) && IS_id_member(mid)) {
472
		    DECL_SPEC ds = DEREF_dspec ( id_storage ( mid ) ) ;
502
		    DECL_SPEC ds = DEREF_dspec(id_storage(mid));
473
		    if ( ds & dspec_token ) {
503
		    if (ds & dspec_token) {
474
			/* Tokenised member found */
504
			/* Tokenised member found */
475
			HASHID nm = DEREF_hashid ( id_name ( mid ) ) ;
505
			HASHID nm = DEREF_hashid(id_name(mid));
476
			IDENTIFIER nid = search_field ( nt, nm, 0, 0 ) ;
506
			IDENTIFIER nid = search_field(nt, nm, 0, 0);
477
			if ( !IS_NULL_id ( nid ) ) {
507
			if (!IS_NULL_id(nid)) {
478
			    /* Token definition found */
508
			    /* Token definition found */
479
			    IDENTIFIER tok = find_token ( mid ) ;
509
			    IDENTIFIER tok = find_token(mid);
480
			    ds = DEREF_dspec ( id_storage ( tok ) ) ;
510
			    ds = DEREF_dspec(id_storage(tok));
481
			    if ( ds & dspec_pure ) {
511
			    if (ds & dspec_pure) {
482
				LOCATION loc ;
512
				LOCATION loc;
483
				DEREF_loc ( id_loc ( nid ), loc ) ;
513
				DEREF_loc(id_loc(nid), loc);
484
				report ( loc, ERR_token_def_not ( nid ) ) ;
514
				report(loc, ERR_token_def_not(nid));
485
			    } else {
515
			    } else {
486
				OFFSET off ;
516
				OFFSET off;
487
				TYPE r = NULL_type ;
517
				TYPE r = NULL_type;
488
				off = offset_member ( t, nid, &r, nt, 0 ) ;
518
				off = offset_member(t, nid, &r, nt, 0);
489
				IGNORE define_mem_token ( tok, off, r, 1 ) ;
519
				IGNORE define_mem_token(tok, off, r, 1);
490
			    }
520
			    }
491
			} else {
521
			} else {
492
			    /* Copy tokenised member */
522
			    /* Copy tokenised member */
493
			    MEMBER mem2 = search_member ( nt, nm, 1 ) ;
523
			    MEMBER mem2 = search_member(nt, nm, 1);
494
			    mid = copy_id ( mid, 0 ) ;
524
			    mid = copy_id(mid, 0);
495
			    COPY_nspace ( id_parent ( mid ), nt ) ;
525
			    COPY_nspace(id_parent(mid), nt);
496
			    set_member ( mem2, mid ) ;
526
			    set_member(mem2, mid);
497
			}
527
			}
498
		    }
528
		    }
499
		}
529
		}
500
		mem = DEREF_member ( member_next ( mem ) ) ;
530
		mem = DEREF_member(member_next(mem));
501
	    }
531
	    }
502
 
532
 
503
	    /* Scan through members of nt */
533
	    /* Scan through members of nt */
504
	    mem = DEREF_member ( nspace_ctype_first ( nt ) ) ;
534
	    mem = DEREF_member(nspace_ctype_first(nt));
505
	    while ( !IS_NULL_member ( mem ) ) {
535
	    while (!IS_NULL_member(mem)) {
506
		MEMBER mem2 = NULL_member ;
536
		MEMBER mem2 = NULL_member;
507
		IDENTIFIER mid = DEREF_id ( member_id ( mem ) ) ;
537
		IDENTIFIER mid = DEREF_id(member_id(mem));
508
		IDENTIFIER nid = DEREF_id ( member_alt ( mem ) ) ;
538
		IDENTIFIER nid = DEREF_id(member_alt(mem));
509
		if ( !IS_NULL_id ( mid ) ) {
539
		if (!IS_NULL_id(mid)) {
510
		    IDENTIFIER pid ;
540
		    IDENTIFIER pid;
511
		    HASHID nm = DEREF_hashid ( id_name ( mid ) ) ;
541
		    HASHID nm = DEREF_hashid(id_name(mid));
512
		    mem2 = search_member ( ns, nm, 1 ) ;
542
		    mem2 = search_member(ns, nm, 1);
513
		    mid = copy_id ( mid, 0 ) ;
543
		    mid = copy_id(mid, 0);
514
		    COPY_nspace ( id_parent ( mid ), ns ) ;
544
		    COPY_nspace(id_parent(mid), ns);
515
		    pid = DEREF_id ( member_id ( mem2 ) ) ;
545
		    pid = DEREF_id(member_id(mem2));
516
		    if ( IS_NULL_id ( pid ) ) {
546
		    if (IS_NULL_id(pid)) {
517
			set_member ( mem2, mid ) ;
547
			set_member(mem2, mid);
518
		    }
548
		    }
519
		}
549
		}
520
		if ( !IS_NULL_id ( nid ) && !EQ_id ( mid, nid ) ) {
550
		if (!IS_NULL_id(nid) && !EQ_id(mid, nid)) {
521
		    if ( IS_NULL_member ( mem2 ) ) {
551
		    if (IS_NULL_member(mem2)) {
522
			HASHID nm = DEREF_hashid ( id_name ( nid ) ) ;
552
			HASHID nm = DEREF_hashid(id_name(nid));
523
			mem2 = search_member ( ns, nm, 1 ) ;
553
			mem2 = search_member(ns, nm, 1);
524
		    }
554
		    }
525
		    nid = copy_id ( nid, 0 ) ;
555
		    nid = copy_id(nid, 0);
526
		    COPY_nspace ( id_parent ( nid ), ns ) ;
556
		    COPY_nspace(id_parent(nid), ns);
527
		    if ( !IS_NULL_id ( nid ) ) {
557
		    if (!IS_NULL_id(nid)) {
528
			set_type_member ( mem2, mid ) ;
558
			set_type_member(mem2, mid);
529
		    }
559
		    }
530
		}
560
		}
531
		mem = DEREF_member ( member_next ( mem ) ) ;
561
		mem = DEREF_member(member_next(mem));
532
	    }
562
	    }
533
	}
563
	}
534
    }
564
    }
535
    return ;
565
    return;
536
}
566
}
537
 
567
 
538
 
568
 
539
/*
569
/*
540
    CHECK A TYPE CATEGORY
570
    CHECK A TYPE CATEGORY
541
 
571
 
542
    This routine checks whether the type t of category ca can be used to
572
    This routine checks whether the type t of category ca can be used to
543
    define a token of kind bt.
573
    define a token of kind bt.
544
*/
574
*/
545
 
575
 
546
static int match_type_token
576
static int
547
    PROTO_N ( ( bt, ca, t ) )
-
 
548
    PROTO_T ( BASE_TYPE bt X unsigned ca X TYPE t )
577
match_type_token(BASE_TYPE bt, unsigned ca, TYPE t)
549
{
578
{
550
    int ok = 1 ;
579
	int ok = 1;
551
    if ( bt & btype_star ) {
580
	if (bt & btype_star) {
552
	/* Scalar types */
581
		/* Scalar types */
553
	if ( !IS_TYPE_SCALAR ( ca ) ) ok = 0 ;
582
		if (!IS_TYPE_SCALAR(ca)) {
-
 
583
			ok = 0;
-
 
584
		}
554
    } else if ( bt & btype_float ) {
585
	} else if (bt & btype_float) {
555
	/* Arithmetic types */
586
		/* Arithmetic types */
556
	if ( bt & btype_int ) {
587
		if (bt & btype_int) {
557
	    if ( !IS_TYPE_ARITH ( ca ) ) ok = 0 ;
588
			if (!IS_TYPE_ARITH(ca)) {
-
 
589
				ok = 0;
-
 
590
			}
558
	} else {
591
		} else {
559
	    if ( !IS_TYPE_FLOAT ( ca ) ) ok = 0 ;
592
			if (!IS_TYPE_FLOAT(ca)) {
-
 
593
				ok = 0;
-
 
594
			}
-
 
595
		}
-
 
596
	} else if (bt & btype_int) {
-
 
597
		/* Integral types */
-
 
598
		if (IS_TYPE_INT(ca)) {
-
 
599
			if (bt & btype_signed) {
-
 
600
				if (check_int_type(t, btype_unsigned)) {
-
 
601
					ok = 0;
-
 
602
				}
-
 
603
			} else if (bt & btype_unsigned) {
-
 
604
				if (check_int_type(t, btype_signed)) {
-
 
605
					ok = 0;
-
 
606
				}
-
 
607
			}
-
 
608
		} else {
-
 
609
			ok = 0;
-
 
610
		}
560
	}
611
	}
561
    } else if ( bt & btype_int ) {
-
 
562
	/* Integral types */
-
 
563
	if ( IS_TYPE_INT ( ca ) ) {
-
 
564
	    if ( bt & btype_signed ) {
-
 
565
		if ( check_int_type ( t, btype_unsigned ) ) ok = 0 ;
-
 
566
	    } else if ( bt & btype_unsigned ) {
-
 
567
		if ( check_int_type ( t, btype_signed ) ) ok = 0 ;
-
 
568
	    }
-
 
569
	} else {
-
 
570
	    ok = 0 ;
-
 
571
	}
-
 
572
    }
-
 
573
    return ( ok ) ;
612
	return (ok);
574
}
613
}
575
 
614
 
576
 
615
 
577
/*
616
/*
578
    DEFINE A TYPE TOKEN
617
    DEFINE A TYPE TOKEN
579
 
618
 
580
    This routine defines the type token id to be t.  It returns true if
619
    This routine defines the type token id to be t.  It returns true if
581
    the token is assigned a value.  qual is as in check_compatible.
620
    the token is assigned a value.  qual is as in check_compatible.
582
*/
621
*/
583
 
622
 
584
int define_type_token
623
int
585
    PROTO_N ( ( id, t, qual ) )
-
 
586
    PROTO_T ( IDENTIFIER id X TYPE t X int qual )
624
define_type_token(IDENTIFIER id, TYPE t, int qual)
587
{
625
{
588
    if ( !IS_NULL_type ( t ) ) {
626
    if (!IS_NULL_type(t)) {
589
	DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
627
	DECL_SPEC ds = DEREF_dspec(id_storage(id));
590
	if ( !( ds & dspec_pure ) ) {
628
	if (!(ds & dspec_pure)) {
591
	    TYPE s ;
629
	    TYPE s;
592
	    int ok = 1 ;
630
	    int ok = 1;
593
	    int check_promote = 0 ;
631
	    int check_promote = 0;
594
	    TOKEN tok = find_tokdef ( id ) ;
632
	    TOKEN tok = find_tokdef(id);
595
	    if ( IS_NULL_tok ( tok ) || !IS_tok_type ( tok ) ) return ( 0 ) ;
633
	    if (IS_NULL_tok(tok) || !IS_tok_type(tok)) {
-
 
634
		    return (0);
-
 
635
	    }
596
	    s = DEREF_type ( tok_type_value ( tok ) ) ;
636
	    s = DEREF_type(tok_type_value(tok));
597
	    if ( !IS_NULL_type ( s ) ) {
637
	    if (!IS_NULL_type(s)) {
598
		ERROR err = NULL_err ;
638
		ERROR err = NULL_err;
599
		t = check_compatible ( s, t, qual, &err, 1 ) ;
639
		t = check_compatible(s, t, qual, &err, 1);
600
		if ( !IS_NULL_err ( err ) ) {
640
		if (!IS_NULL_err(err)) {
601
		    if ( ds & dspec_auto ) {
641
		    if (ds & dspec_auto) {
602
			destroy_error ( err, 1 ) ;
642
			destroy_error(err, 1);
603
			t = redef_type ;
643
			t = redef_type;
604
		    } else {
644
		    } else {
605
			ERROR err2 ;
645
			ERROR err2;
606
			err2 = ERR_token_redef ( id, id_loc ( id ) ) ;
646
			err2 = ERR_token_redef(id, id_loc(id));
607
			err = concat_error ( err, err2 ) ;
647
			err = concat_error(err, err2);
608
			report ( crt_loc, err ) ;
648
			report(crt_loc, err);
609
		    }
649
		    }
610
		    ok = 0 ;
650
		    ok = 0;
611
		}
651
		}
612
	    } else {
652
	    } else {
613
		unsigned ca = type_category ( &t ) ;
653
		unsigned ca = type_category(&t);
614
		BASE_TYPE bt = DEREF_btype ( tok_type_kind ( tok ) ) ;
654
		BASE_TYPE bt = DEREF_btype(tok_type_kind(tok));
615
		if ( !( bt & btype_template ) ) {
655
		if (!(bt & btype_template)) {
616
		    /* Tokens */
656
		    /* Tokens */
617
		    ERROR err = NULL_err ;
657
		    ERROR err = NULL_err;
618
		    switch ( TAG_type ( t ) ) {
658
		    switch (TAG_type(t)) {
619
			case type_ref_tag :
659
			case type_ref_tag:
620
			case type_func_tag :
660
			case type_func_tag:
621
			case type_bitfield_tag : {
661
			case type_bitfield_tag:
622
			    /* These types can't be tokenised */
662
			    /* These types can't be tokenised */
623
			    ok = 0 ;
663
			    ok = 0;
624
			    break ;
664
			    break;
625
			}
-
 
626
			case type_compound_tag : {
665
			case type_compound_tag:
627
			    /* Can only tokenise trivial classes */
666
			    /* Can only tokenise trivial classes */
628
			    if ( bt != btype_none || !( ds & dspec_auto ) ) {
667
			    if (bt != btype_none || !(ds & dspec_auto)) {
629
				CLASS_TYPE ct ;
668
				CLASS_TYPE ct;
630
				ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
669
				ct = DEREF_ctype(type_compound_defn(t));
631
				err = check_trivial_class ( ct ) ;
670
				err = check_trivial_class(ct);
632
				if ( !IS_NULL_err ( err ) ) ok = 0 ;
671
				if (!IS_NULL_err(err))ok = 0;
633
			    }
672
			    }
634
			    break ;
673
			    break;
635
			}
-
 
636
		    }
674
		    }
637
		    if ( bt ) {
675
		    if (bt) {
638
			if ( bt & btype_named ) {
676
			if (bt & btype_named) {
639
			    /* Structure and union types */
677
			    /* Structure and union types */
640
			    if ( IS_type_compound ( t ) ) {
678
			    if (IS_type_compound(t)) {
641
				if ( !( ds & dspec_auto ) ) {
679
				if (!(ds & dspec_auto)) {
642
				    /* Check structure fields */
680
				    /* Check structure fields */
643
				    define_field_tokens ( id, t ) ;
681
				    define_field_tokens(id, t);
644
				}
682
				}
645
			    } else {
683
			    } else {
646
				ok = 0 ;
684
				ok = 0;
647
			    }
685
			    }
648
			} else {
686
			} else {
649
			    /* Check scalar types */
687
			    /* Check scalar types */
650
			    if ( !match_type_token ( bt, ca, t ) ) ok = 0 ;
688
			    if (!match_type_token(bt, ca, t)) {
-
 
689
				    ok = 0;
-
 
690
			    }
-
 
691
			}
-
 
692
			if (bt & btype_int) {
-
 
693
				check_promote = ok;
651
			}
694
			}
652
			if ( bt & btype_int ) check_promote = ok ;
-
 
653
		    }
695
		    }
654
		    if ( !ok ) {
696
		    if (!ok) {
655
			/* Report any type mismatch errors */
697
			/* Report any type mismatch errors */
656
			if ( !IS_type_error ( t ) ) {
698
			if (!IS_type_error(t)) {
657
			    int lex = type_token_key ( bt ) ;
699
			    int lex = type_token_key(bt);
658
			    ERROR err2 = ERR_token_arg_type ( lex, id, t ) ;
700
			    ERROR err2 = ERR_token_arg_type(lex, id, t);
659
			    err = concat_error ( err, err2 ) ;
701
			    err = concat_error(err, err2);
660
			    report ( crt_loc, err ) ;
702
			    report(crt_loc, err);
661
			    t = type_error ;
703
			    t = type_error;
662
			}
704
			}
663
		    }
705
		    }
664
		}
706
		}
665
		if ( !IS_TYPE_INT ( ca ) ) check_promote = 0 ;
707
		if (!IS_TYPE_INT(ca)) {
-
 
708
			check_promote = 0;
-
 
709
		}
666
	    }
710
	    }
667
	    COPY_type ( tok_type_value ( tok ), t ) ;
711
	    COPY_type(tok_type_value(tok), t);
668
	    if ( ds & dspec_auto ) {
712
	    if (ds & dspec_auto) {
669
		check_promote = 0 ;
713
		check_promote = 0;
670
	    } else {
714
	    } else {
671
		no_token_defns++ ;
715
		no_token_defns++;
672
	    }
716
	    }
673
	    ds |= dspec_defn ;
717
	    ds |= dspec_defn;
674
	    COPY_dspec ( id_storage ( id ), ds ) ;
718
	    COPY_dspec(id_storage(id), ds);
675
	    COPY_loc ( id_loc ( id ), crt_loc ) ;
719
	    COPY_loc(id_loc(id), crt_loc);
676
	    if ( check_promote ) {
720
	    if (check_promote) {
677
		/* Check that promoted types are compatible */
721
		/* Check that promoted types are compatible */
678
		s = apply_itype_token ( id, NULL_list ( TOKEN ) ) ;
722
		s = apply_itype_token(id, NULL_list(TOKEN));
679
		t = promote_type ( t ) ;
723
		t = promote_type(t);
680
		set_promote_type ( s, t, ntype_none ) ;
724
		set_promote_type(s, t, ntype_none);
681
	    }
725
	    }
682
	    return ( ok ) ;
726
	    return (ok);
683
	}
727
	}
684
    }
728
    }
685
    return ( 0 ) ;
729
    return (0);
686
}
730
}
687
 
731
 
688
 
732
 
689
/*
733
/*
690
    DEFINE A TEMPLATE TEMPLATE PARAMETER
734
    DEFINE A TEMPLATE TEMPLATE PARAMETER
Line 692... Line 736...
692
    This routine defines the template template parameter id to be the
736
    This routine defines the template template parameter id to be the
693
    class given by tid.  It returns true if the parameter is assigned a
737
    class given by tid.  It returns true if the parameter is assigned a
694
    value.
738
    value.
695
*/
739
*/
696
 
740
 
697
int define_templ_token
741
int
698
    PROTO_N ( ( id, tid ) )
-
 
699
    PROTO_T ( IDENTIFIER id X IDENTIFIER tid )
742
define_templ_token(IDENTIFIER id, IDENTIFIER tid)
700
{
743
{
701
    if ( !IS_NULL_id ( tid ) ) {
744
    if (!IS_NULL_id(tid)) {
702
	DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
745
	DECL_SPEC ds = DEREF_dspec(id_storage(id));
703
	if ( !( ds & dspec_pure ) ) {
746
	if (!(ds & dspec_pure)) {
704
	    TOKEN tok = DEREF_tok ( id_token_sort ( id ) ) ;
747
	    TOKEN tok = DEREF_tok(id_token_sort(id));
705
	    if ( IS_tok_class ( tok ) ) {
748
	    if (IS_tok_class(tok)) {
706
		int ok = 0 ;
749
		int ok = 0;
707
		IDENTIFIER sid = DEREF_id ( tok_class_value ( tok ) ) ;
750
		IDENTIFIER sid = DEREF_id(tok_class_value(tok));
708
		if ( EQ_id ( sid, tid ) ) return ( 1 ) ;
751
		if (EQ_id(sid, tid)) {
-
 
752
			return (1);
-
 
753
		}
709
		if ( IS_id_class_name_etc ( tid ) ) {
754
		if (IS_id_class_name_etc(tid)) {
710
		    TYPE t = DEREF_type ( tok_class_type ( tok ) ) ;
755
		    TYPE t = DEREF_type(tok_class_type(tok));
711
		    TYPE s = DEREF_type ( id_class_name_etc_defn ( tid ) ) ;
756
		    TYPE s = DEREF_type(id_class_name_etc_defn(tid));
712
		    if ( IS_type_templ ( t ) && IS_type_templ ( s ) ) {
757
		    if (IS_type_templ(t) && IS_type_templ(s)) {
713
			/* Check for equality of template parameters */
758
			/* Check for equality of template parameters */
714
			LIST ( IDENTIFIER ) ps, pt ;
759
			LIST(IDENTIFIER) ps, pt;
715
			TOKEN as = DEREF_tok ( type_templ_sort ( s ) ) ;
760
			TOKEN as = DEREF_tok(type_templ_sort(s));
716
			TOKEN at = DEREF_tok ( type_templ_sort ( t ) ) ;
761
			TOKEN at = DEREF_tok(type_templ_sort(t));
717
			ps = DEREF_list ( tok_templ_pids ( as ) ) ;
762
			ps = DEREF_list(tok_templ_pids(as));
718
			pt = DEREF_list ( tok_templ_pids ( at ) ) ;
763
			pt = DEREF_list(tok_templ_pids(at));
719
			ok = eq_templ_params ( ps, pt ) ;
764
			ok = eq_templ_params(ps, pt);
720
			restore_templ_params ( ps ) ;
765
			restore_templ_params(ps);
721
		    }
766
		    }
722
		    if ( !ok ) {
767
		    if (!ok) {
723
			/* Report illegal definitions */
768
			/* Report illegal definitions */
724
			ERROR err = ERR_temp_arg_templ_bad ( id, s ) ;
769
			ERROR err = ERR_temp_arg_templ_bad(id, s);
725
			report ( crt_loc, err ) ;
770
			report(crt_loc, err);
726
		    }
771
		    }
727
		    if ( !IS_NULL_id ( sid ) ) {
772
		    if (!IS_NULL_id(sid)) {
728
			/* Check for redefinitions */
773
			/* Check for redefinitions */
729
			if ( ds & dspec_auto ) {
774
			if (ds & dspec_auto) {
730
			    tid = redef_id ;
775
			    tid = redef_id;
731
			} else {
776
			} else {
732
			    PTR ( LOCATION ) loc = id_loc ( id ) ;
777
			    PTR(LOCATION) loc = id_loc(id);
733
			    report ( crt_loc, ERR_token_redef ( id, loc ) ) ;
778
			    report(crt_loc, ERR_token_redef(id, loc));
734
			}
779
			}
735
			ok = 0 ;
780
			ok = 0;
736
		    }
781
		    }
737
		} else {
782
		} else {
738
		    ok = 0 ;
783
		    ok = 0;
-
 
784
		}
-
 
785
		COPY_id(tok_class_value(tok), tid);
-
 
786
		if (!(ds & dspec_auto)) {
-
 
787
			no_token_defns++;
739
		}
788
		}
740
		COPY_id ( tok_class_value ( tok ), tid ) ;
-
 
741
		if ( !( ds & dspec_auto ) ) no_token_defns++ ;
-
 
742
		ds |= dspec_defn ;
789
		ds |= dspec_defn;
743
		COPY_dspec ( id_storage ( id ), ds ) ;
790
		COPY_dspec(id_storage(id), ds);
744
		COPY_loc ( id_loc ( id ), crt_loc ) ;
791
		COPY_loc(id_loc(id), crt_loc);
745
		return ( ok ) ;
792
		return (ok);
746
	    }
793
	    }
747
	}
794
	}
748
    }
795
    }
749
    return ( 0 ) ;
796
    return (0);
750
}
797
}
751
 
798
 
752
 
799
 
753
/*
800
/*
754
    DEFINE A MEMBER TOKEN
801
    DEFINE A MEMBER TOKEN
Line 756... Line 803...
756
    This routine defines the member token id to be a member of offset off
803
    This routine defines the member token id to be a member of offset off
757
    and type t.  It returns true if the token is assigned a value.  ext is
804
    and type t.  It returns true if the token is assigned a value.  ext is
758
    true for an external token definition.
805
    true for an external token definition.
759
*/
806
*/
760
 
807
 
761
int define_mem_token
808
int
762
    PROTO_N ( ( id, off, t, ext ) )
-
 
763
    PROTO_T ( IDENTIFIER id X OFFSET off X TYPE t X int ext )
809
define_mem_token(IDENTIFIER id, OFFSET off, TYPE t, int ext)
764
{
810
{
765
    if ( !IS_NULL_off ( off ) ) {
811
    if (!IS_NULL_off(off)) {
766
	DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
812
	DECL_SPEC ds = DEREF_dspec(id_storage(id));
767
	if ( ( ds & dspec_auto ) && ext ) {
813
	if ((ds & dspec_auto) && ext) {
768
	    ERROR err = ERR_class_mem_redecl ( id, id_loc ( id ) ) ;
814
	    ERROR err = ERR_class_mem_redecl(id, id_loc(id));
769
	    report ( crt_loc, err ) ;
815
	    report(crt_loc, err);
770
	} else if ( !( ds & dspec_pure ) ) {
816
	} else if (!(ds & dspec_pure)) {
771
	    TOKEN tok = find_tokdef ( id ) ;
817
	    TOKEN tok = find_tokdef(id);
772
	    if ( !IS_NULL_tok ( tok ) && IS_tok_member ( tok ) ) {
818
	    if (!IS_NULL_tok(tok) && IS_tok_member(tok)) {
773
		TYPE u ;
819
		TYPE u;
774
		ERROR err = NULL_err ;
820
		ERROR err = NULL_err;
775
		TYPE s = DEREF_type ( tok_member_type ( tok ) ) ;
821
		TYPE s = DEREF_type(tok_member_type(tok));
776
		OFFSET d = DEREF_off ( tok_member_value ( tok ) ) ;
822
		OFFSET d = DEREF_off(tok_member_value(tok));
777
		if ( !IS_NULL_off ( d ) && !eq_offset ( off, d, 0 ) ) {
823
		if (!IS_NULL_off(d) && !eq_offset(off, d, 0)) {
778
		    if ( ds & dspec_auto ) {
824
		    if (ds & dspec_auto) {
779
			off = redef_off ;
825
			off = redef_off;
780
		    } else {
826
		    } else {
781
			PTR ( LOCATION ) loc = id_loc ( id ) ;
827
			PTR(LOCATION) loc = id_loc(id);
782
			report ( crt_loc, ERR_token_redef ( id, loc ) ) ;
828
			report(crt_loc, ERR_token_redef(id, loc));
783
		    }
829
		    }
784
		}
830
		}
785
		u = check_compatible ( s, t, 0, &err, 0 ) ;
831
		u = check_compatible(s, t, 0, &err, 0);
786
		if ( !IS_NULL_err ( err ) ) {
832
		if (!IS_NULL_err(err)) {
787
		    /* Member type is wrong */
833
		    /* Member type is wrong */
788
		    if ( eq_type_offset ( s, t ) ) {
834
		    if (eq_type_offset(s, t)) {
789
			/* Types have same representation */
835
			/* Types have same representation */
790
			err = set_severity ( err, OPT_member_incompat, -1 ) ;
836
			err = set_severity(err, OPT_member_incompat, -1);
791
		    }
837
		    }
792
		    err = concat_error ( err, ERR_token_arg_mem ( id ) ) ;
838
		    err = concat_error(err, ERR_token_arg_mem(id));
793
		    report ( crt_loc, err ) ;
839
		    report(crt_loc, err);
794
		}
840
		}
795
		COPY_off ( tok_member_value ( tok ), off ) ;
841
		COPY_off(tok_member_value(tok), off);
796
		if ( !( ds & dspec_auto ) ) {
842
		if (!(ds & dspec_auto)) {
797
		    if ( IS_type_error ( s ) ) {
843
		    if (IS_type_error(s)) {
798
			/* Fill in type if not known */
844
			/* Fill in type if not known */
799
			IDENTIFIER mid = DEREF_id ( id_token_alt ( id ) ) ;
845
			IDENTIFIER mid = DEREF_id(id_token_alt(id));
800
			COPY_type ( tok_member_type ( tok ), u ) ;
846
			COPY_type(tok_member_type(tok), u);
801
			u = lvalue_type ( u ) ;
847
			u = lvalue_type(u);
802
			COPY_type ( id_member_type ( mid ), u ) ;
848
			COPY_type(id_member_type(mid), u);
803
		    }
849
		    }
804
		    no_token_defns++ ;
850
		    no_token_defns++;
805
		}
851
		}
806
		ds |= dspec_defn ;
852
		ds |= dspec_defn;
807
		COPY_dspec ( id_storage ( id ), ds ) ;
853
		COPY_dspec(id_storage(id), ds);
808
		COPY_loc ( id_loc ( id ), crt_loc ) ;
854
		COPY_loc(id_loc(id), crt_loc);
809
		UNUSED ( ext ) ;
855
		UNUSED(ext);
810
		return ( 1 ) ;
856
		return (1);
811
	    }
857
	    }
812
	}
858
	}
813
    }
859
    }
814
    return ( 0 ) ;
860
    return (0);
815
}
861
}
816
 
862
 
817
 
863
 
818
/*
864
/*
819
    DEFINE A FUNCTION TOKEN
865
    DEFINE A FUNCTION TOKEN
820
 
866
 
821
    This routine defines the function token id to be the function fid.
867
    This routine defines the function token id to be the function fid.
822
*/
868
*/
823
 
869
 
824
int define_func_token
870
int
825
    PROTO_N ( ( id, fid ) )
-
 
826
    PROTO_T ( IDENTIFIER id X IDENTIFIER fid )
871
define_func_token(IDENTIFIER id, IDENTIFIER fid)
827
{
872
{
828
    if ( !IS_NULL_id ( fid ) ) {
873
    if (!IS_NULL_id(fid)) {
829
	DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
874
	DECL_SPEC ds = DEREF_dspec(id_storage(id));
830
	if ( !( ds & dspec_pure ) ) {
875
	if (!(ds & dspec_pure)) {
831
	    TOKEN tok = DEREF_tok ( id_token_sort ( id ) ) ;
876
	    TOKEN tok = DEREF_tok(id_token_sort(id));
832
	    if ( IS_tok_func ( tok ) ) {
877
	    if (IS_tok_func(tok)) {
833
		int eq = 0 ;
878
		int eq = 0;
834
		int redef = 0 ;
879
		int redef = 0;
835
		LIST ( IDENTIFIER ) pids = NULL_list ( IDENTIFIER ) ;
880
		LIST(IDENTIFIER) pids = NULL_list(IDENTIFIER);
836
		TYPE t = DEREF_type ( tok_func_type ( tok ) ) ;
881
		TYPE t = DEREF_type(tok_func_type(tok));
837
		TOKEN res = DEREF_tok ( tok_func_proc ( tok ) ) ;
882
		TOKEN res = DEREF_tok(tok_func_proc(tok));
838
		IDENTIFIER pid = DEREF_id ( tok_func_defn ( tok ) ) ;
883
		IDENTIFIER pid = DEREF_id(tok_func_defn(tok));
839
		IDENTIFIER qid = resolve_func ( fid, t, 1, 0, pids, &eq ) ;
884
		IDENTIFIER qid = resolve_func(fid, t, 1, 0, pids, &eq);
840
		if ( !IS_NULL_id ( qid ) ) {
885
		if (!IS_NULL_id(qid)) {
841
		    switch ( TAG_id ( qid ) ) {
886
		    switch (TAG_id(qid)) {
842
			case id_function_tag :
887
			case id_function_tag:
843
			case id_stat_mem_func_tag : {
888
			case id_stat_mem_func_tag:
844
			    use_id ( qid, 0 ) ;
889
			    use_id(qid, 0);
845
			    break ;
890
			    break;
846
			}
-
 
847
			default : {
891
			default:
848
			    qid = NULL_id ;
892
			    qid = NULL_id;
849
			    break ;
893
			    break;
850
			}
-
 
851
		    }
894
		    }
852
		}
895
		}
853
		if ( IS_NULL_id ( qid ) ) {
896
		if (IS_NULL_id(qid)) {
854
		    report ( crt_loc, ERR_token_def_func ( fid, t ) ) ;
897
		    report(crt_loc, ERR_token_def_func(fid, t));
855
		    qid = fid ;
898
		    qid = fid;
856
		} else {
899
		} else {
857
		    TYPE s = DEREF_type ( id_function_etc_type ( qid ) ) ;
900
		    TYPE s = DEREF_type(id_function_etc_type(qid));
858
		    if ( eq == 2 ) {
901
		    if (eq == 2) {
859
			report ( crt_loc, ERR_dcl_link_conv () ) ;
902
			report(crt_loc, ERR_dcl_link_conv());
860
		    }
-
 
861
		    if ( eq_except ( s, t ) != 2 ) {
-
 
862
			report ( crt_loc, ERR_token_def_except () ) ;
-
 
863
		    }
903
		    }
-
 
904
		    if (eq_except(s, t)!= 2) {
-
 
905
			report(crt_loc, ERR_token_def_except());
-
 
906
		    }
864
		}
907
		}
865
		if ( !IS_NULL_tok ( res ) ) {
908
		if (!IS_NULL_tok(res)) {
866
		    /* Previously defined by macro */
909
		    /* Previously defined by macro */
867
		    redef = 1 ;
910
		    redef = 1;
868
		}
911
		}
869
		if ( !IS_NULL_id ( pid ) && !EQ_id ( pid, qid ) ) {
912
		if (!IS_NULL_id(pid) && !EQ_id(pid, qid)) {
870
		    /* Previously defined by different function */
913
		    /* Previously defined by different function */
871
		    redef = 1 ;
914
		    redef = 1;
-
 
915
		}
-
 
916
		if (redef) {
-
 
917
		    PTR(LOCATION) loc = id_loc(id);
-
 
918
		    report(crt_loc, ERR_token_redef(id, loc));
872
		}
919
		}
873
		if ( redef ) {
920
		COPY_id(tok_func_defn(tok), qid);
874
		    PTR ( LOCATION ) loc = id_loc ( id ) ;
921
		if (!(ds & dspec_auto)) {
875
		    report ( crt_loc, ERR_token_redef ( id, loc ) ) ;
922
			no_token_defns++;
876
		}
923
		}
877
		COPY_id ( tok_func_defn ( tok ), qid ) ;
-
 
878
		if ( !( ds & dspec_auto ) ) no_token_defns++ ;
-
 
879
		ds |= dspec_defn ;
924
		ds |= dspec_defn;
880
		COPY_dspec ( id_storage ( id ), ds ) ;
925
		COPY_dspec(id_storage(id), ds);
881
		COPY_loc ( id_loc ( id ), crt_loc ) ;
926
		COPY_loc(id_loc(id), crt_loc);
882
		return ( 1 ) ;
927
		return (1);
883
	    }
928
	    }
884
	}
929
	}
885
    }
930
    }
886
    return ( 0 ) ;
931
    return (0);
887
}
932
}
888
 
933
 
889
 
934
 
890
/*
935
/*
891
    PROCEDURE TOKEN FLAG
936
    PROCEDURE TOKEN FLAG
892
 
937
 
893
    This variable is used to keep track of the depth of procedure token
938
    This variable is used to keep track of the depth of procedure token
894
    arguments being read.
939
    arguments being read.
895
*/
940
*/
896
 
941
 
897
int in_proc_token = 0 ;
942
int in_proc_token = 0;
898
 
943
 
899
 
944
 
900
/*
945
/*
901
    FIND A TOKEN MEMBER TYPE
946
    FIND A TOKEN MEMBER TYPE
902
 
947
 
903
    If id represents a member token then this routine returns the type
948
    If id represents a member token then this routine returns the type
904
    of which id is a member, suitably expanded.  Otherwise the null type
949
    of which id is a member, suitably expanded.  Otherwise the null type
905
    is returned.  This represents the only barrier to doing argument
950
    is returned.  This represents the only barrier to doing argument
906
    deduction in procedure tokens independently for each argument - if
951
    deduction in procedure tokens independently for each argument - if
907
    a member parameter is a member of a previous structure parameter
952
    a member parameter is a member of a previous structure parameter
908
    (as in offsetof), we need to know the value of the structure
953
    (as in offsetof), we need to know the value of the structure
909
    argument before we can decode the member argument.
954
    argument before we can decode the member argument.
910
*/
955
*/
911
 
956
 
912
static TYPE expand_member_type
957
static TYPE
913
    PROTO_N ( ( id ) )
-
 
914
    PROTO_T ( IDENTIFIER id )
958
expand_member_type(IDENTIFIER id)
915
{
959
{
916
    TYPE t = NULL_type ;
960
	TYPE t = NULL_type;
917
    TOKEN tok = find_tokdef ( id ) ;
961
	TOKEN tok = find_tokdef(id);
918
    if ( !IS_NULL_tok ( tok ) && IS_tok_member ( tok ) ) {
962
	if (!IS_NULL_tok(tok) && IS_tok_member(tok)) {
919
	t = DEREF_type ( tok_member_of ( tok ) ) ;
963
		t = DEREF_type(tok_member_of(tok));
920
	t = expand_type ( t, 1 ) ;
964
		t = expand_type(t, 1);
921
    }
965
	}
922
    return ( t ) ;
966
	return (t);
923
}
967
}
924
 
968
 
925
 
969
 
926
/*
970
/*
927
    PARSE A TOKEN DEFINITION
971
    PARSE A TOKEN DEFINITION
928
 
972
 
929
    This routine reads the definition of the token id.  It returns true
973
    This routine reads the definition of the token id.  It returns true
930
    if a value is assigned to the token.  If mt is not null it is the
974
    if a value is assigned to the token.  If mt is not null it is the
931
    class type for a member token.  fn is true for procedure tokens and
975
    class type for a member token.  fn is true for procedure tokens and
932
    mac is true is true for macro token definitions.
976
    mac is true is true for macro token definitions.
1079
/*
1122
/*
1080
    SET A TOKEN VALUE
1123
    SET A TOKEN VALUE
1081
 
1124
 
1082
    This routine sets the value of the token id to be arg.
1125
    This routine sets the value of the token id to be arg.
1083
*/
1126
*/
1084
 
1127
 
1085
void assign_token
1128
void
1086
    PROTO_N ( ( id, arg ) )
-
 
1087
    PROTO_T ( IDENTIFIER id X TOKEN arg )
1129
assign_token(IDENTIFIER id, TOKEN arg)
1088
{
1130
{
1089
    if ( !IS_NULL_tok ( arg ) ) {
1131
	if (!IS_NULL_tok(arg)) {
1090
	TOKEN sort = DEREF_tok ( id_token_sort ( id ) ) ;
1132
		TOKEN sort = DEREF_tok(id_token_sort(id));
1091
	unsigned na = TAG_tok ( arg ) ;
1133
		unsigned na = TAG_tok(arg);
1092
	unsigned nb = TAG_tok ( sort ) ;
1134
		unsigned nb = TAG_tok(sort);
1093
	if ( nb == tok_proc_tag ) {
1135
		if (nb == tok_proc_tag) {
1094
	    sort = DEREF_tok ( tok_proc_res ( sort ) ) ;
1136
			sort = DEREF_tok(tok_proc_res(sort));
1095
	    nb = TAG_tok ( sort ) ;
1137
			nb = TAG_tok(sort);
1096
	}
1138
		}
1097
	if ( na == nb ) {
1139
		if (na == nb) {
1098
	    switch ( na ) {
1140
			switch (na) {
1099
		case tok_exp_tag : {
1141
			case tok_exp_tag: {
1100
		    EXP e = DEREF_exp ( tok_exp_value ( arg ) ) ;
1142
				EXP e = DEREF_exp(tok_exp_value(arg));
1101
		    COPY_exp ( tok_exp_value ( sort ), e ) ;
1143
				COPY_exp(tok_exp_value(sort), e);
1102
		    break ;
1144
				break;
1103
		}
1145
			}
1104
		case tok_nat_tag :
1146
			case tok_nat_tag:
1105
		case tok_snat_tag : {
1147
			case tok_snat_tag: {
1106
		    NAT n = DEREF_nat ( tok_nat_etc_value ( arg ) ) ;
1148
				NAT n = DEREF_nat(tok_nat_etc_value(arg));
1107
		    COPY_nat ( tok_nat_etc_value ( sort ), n ) ;
1149
				COPY_nat(tok_nat_etc_value(sort), n);
1108
		    break ;
1150
				break;
1109
		}
1151
			}
1110
		case tok_stmt_tag : {
1152
			case tok_stmt_tag: {
1111
		    EXP e = DEREF_exp ( tok_stmt_value ( arg ) ) ;
1153
				EXP e = DEREF_exp(tok_stmt_value(arg));
1112
		    COPY_exp ( tok_stmt_value ( sort ), e ) ;
1154
				COPY_exp(tok_stmt_value(sort), e);
1113
		    break ;
1155
				break;
1114
		}
1156
			}
1115
		case tok_member_tag : {
1157
			case tok_member_tag: {
1116
		    OFFSET off = DEREF_off ( tok_member_value ( arg ) ) ;
1158
				OFFSET off = DEREF_off(tok_member_value(arg));
1117
		    COPY_off ( tok_member_value ( sort ), off ) ;
1159
				COPY_off(tok_member_value(sort), off);
1118
		    break ;
1160
				break;
1119
		}
1161
			}
1120
		case tok_type_tag : {
1162
			case tok_type_tag: {
1121
		    TYPE t = DEREF_type ( tok_type_value ( arg ) ) ;
1163
				TYPE t = DEREF_type(tok_type_value(arg));
1122
		    COPY_type ( tok_type_value ( sort ), t ) ;
1164
				COPY_type(tok_type_value(sort), t);
1123
		    break ;
1165
				break;
1124
		}
1166
			}
1125
		case tok_class_tag : {
1167
			case tok_class_tag: {
1126
		    IDENTIFIER cid = DEREF_id ( tok_class_value ( arg ) ) ;
1168
				IDENTIFIER cid = DEREF_id(tok_class_value(arg));
1127
		    COPY_id ( tok_class_value ( sort ), cid ) ;
1169
				COPY_id(tok_class_value(sort), cid);
1128
		    break ;
1170
				break;
1129
		}
1171
			}
1130
	    }
1172
			}
1131
	}
1173
		}
1132
    }
1174
	}
1133
    return ;
1175
	return;
1134
}
1176
}
1135
 
1177
 
1136
 
1178
 
1137
/*
1179
/*
1138
    TOKEN ARGUMENT STACKS
1180
    TOKEN ARGUMENT STACKS
1139
 
1181
 
1140
    These stacks are used to store the values of the token arguments to
1182
    These stacks are used to store the values of the token arguments to
1141
    allow for recursive token applications.
1183
    allow for recursive token applications.
1142
*/
1184
*/
1143
 
1185
 
1144
static STACK ( EXP ) token_exp_stack = NULL_stack ( EXP ) ;
1186
static STACK(EXP) token_exp_stack = NULL_stack(EXP);
1145
static STACK ( NAT ) token_nat_stack = NULL_stack ( NAT ) ;
1187
static STACK(NAT) token_nat_stack = NULL_stack(NAT);
1146
static STACK ( EXP ) token_stmt_stack = NULL_stack ( EXP ) ;
1188
static STACK(EXP) token_stmt_stack = NULL_stack(EXP);
1147
static STACK ( OFFSET ) token_mem_stack = NULL_stack ( OFFSET ) ;
1189
static STACK(OFFSET) token_mem_stack = NULL_stack(OFFSET);
1148
static STACK ( TYPE ) token_type_stack = NULL_stack ( TYPE ) ;
1190
static STACK(TYPE) token_type_stack = NULL_stack(TYPE);
1149
static STACK ( IDENTIFIER ) token_class_stack = NULL_stack ( IDENTIFIER ) ;
1191
static STACK(IDENTIFIER) token_class_stack = NULL_stack(IDENTIFIER);
1150
 
1192
 
1151
 
1193
 
1152
/*
1194
/*
1153
    SAVE TOKEN ARGUMENT VALUES
1195
    SAVE TOKEN ARGUMENT VALUES
1154
 
1196
 
1155
    This routine saves the argument values for the token parameters pids
1197
    This routine saves the argument values for the token parameters pids
1156
    by pushing them onto the stacks above.  The argument values set to those
1198
    by pushing them onto the stacks above.  The argument values set to those
1157
    stored in args, or the null value when these are exhausted.  The routine
1199
    stored in args, or the null value when these are exhausted.  The routine
1158
    also clears the pure field of the token, returning 0 if they were
1200
    also clears the pure field of the token, returning 0 if they were
1159
    previously set.
1201
    previously set.
1160
*/
1202
*/
1161
 
1203
 
1162
int save_token_args
1204
int
1163
    PROTO_N ( ( pids, args ) )
-
 
1164
    PROTO_T ( LIST ( IDENTIFIER ) pids X LIST ( TOKEN ) args )
1205
save_token_args(LIST(IDENTIFIER) pids, LIST(TOKEN) args)
1165
{
1206
{
1166
    int depth = 1 ;
1207
	int depth = 1;
1167
    LIST ( IDENTIFIER ) bids = pids ;
1208
	LIST(IDENTIFIER) bids = pids;
1168
    while ( !IS_NULL_list ( bids ) ) {
1209
	while (!IS_NULL_list(bids)) {
1169
	IDENTIFIER bid = DEREF_id ( HEAD_list ( bids ) ) ;
1210
		IDENTIFIER bid = DEREF_id(HEAD_list(bids));
1170
 
1211
 
1171
	/* Get argument token value */
1212
		/* Get argument token value */
1172
	TOKEN atok = NULL_tok ;
1213
		TOKEN atok = NULL_tok;
1173
	unsigned at = null_tag ;
1214
		unsigned at = null_tag;
1174
	if ( !IS_NULL_list ( args ) ) {
1215
		if (!IS_NULL_list(args)) {
1175
	    atok = DEREF_tok ( HEAD_list ( args ) ) ;
1216
			atok = DEREF_tok(HEAD_list(args));
1176
	    if ( !IS_NULL_tok ( atok ) ) at = TAG_tok ( atok ) ;
1217
			if (!IS_NULL_tok(atok)) {
-
 
1218
				at = TAG_tok(atok);
-
 
1219
			}
1177
	    args = TAIL_list ( args ) ;
1220
			args = TAIL_list(args);
1178
	}
1221
		}
1179
 
1222
 
1180
	/* Save previous token value */
1223
		/* Save previous token value */
1181
	if ( !IS_NULL_id ( bid ) && IS_id_token ( bid ) ) {
1224
		if (!IS_NULL_id(bid) && IS_id_token(bid)) {
1182
	    DECL_SPEC ds ;
1225
			DECL_SPEC ds;
1183
	    TOKEN btok = DEREF_tok ( id_token_sort ( bid ) ) ;
1226
			TOKEN btok = DEREF_tok(id_token_sort(bid));
1184
	    unsigned bt = TAG_tok ( btok ) ;
1227
			unsigned bt = TAG_tok(btok);
1185
	    switch ( bt ) {
1228
			switch (bt) {
1186
		case tok_exp_tag : {
1229
			case tok_exp_tag: {
1187
		    EXP e = DEREF_exp ( tok_exp_value ( btok ) ) ;
1230
				EXP e = DEREF_exp(tok_exp_value(btok));
1188
		    PUSH_exp ( e, token_exp_stack ) ;
1231
				PUSH_exp(e, token_exp_stack);
1189
		    if ( at == bt ) {
1232
				if (at == bt) {
1190
			e = DEREF_exp ( tok_exp_value ( atok ) ) ;
1233
					e = DEREF_exp(tok_exp_value(atok));
1191
		    } else {
1234
				} else {
1192
			e = NULL_exp ;
1235
					e = NULL_exp;
1193
		    }
1236
				}
1194
		    COPY_exp ( tok_exp_value ( btok ), e ) ;
1237
				COPY_exp(tok_exp_value(btok), e);
1195
		    break ;
1238
				break;
1196
		}
1239
			}
1197
		case tok_nat_tag :
1240
			case tok_nat_tag:
1198
		case tok_snat_tag : {
1241
			case tok_snat_tag: {
1199
		    NAT n = DEREF_nat ( tok_nat_etc_value ( btok ) ) ;
1242
				NAT n = DEREF_nat(tok_nat_etc_value(btok));
1200
		    PUSH_nat ( n, token_nat_stack ) ;
1243
				PUSH_nat(n, token_nat_stack);
1201
		    if ( at == bt ) {
1244
				if (at == bt) {
1202
			n = DEREF_nat ( tok_nat_etc_value ( atok ) ) ;
1245
					n = DEREF_nat(tok_nat_etc_value(atok));
1203
		    } else {
1246
				} else {
1204
			n = NULL_nat ;
1247
					n = NULL_nat;
1205
		    }
1248
				}
1206
		    COPY_nat ( tok_nat_etc_value ( btok ), n ) ;
1249
				COPY_nat(tok_nat_etc_value(btok), n);
1207
		    break ;
1250
				break;
1208
		}
1251
			}
1209
		case tok_stmt_tag : {
1252
			case tok_stmt_tag: {
1210
		    EXP e = DEREF_exp ( tok_stmt_value ( btok ) ) ;
1253
				EXP e = DEREF_exp(tok_stmt_value(btok));
1211
		    PUSH_exp ( e, token_stmt_stack ) ;
1254
				PUSH_exp(e, token_stmt_stack);
1212
		    if ( at == bt ) {
1255
				if (at == bt) {
1213
			e = DEREF_exp ( tok_stmt_value ( atok ) ) ;
1256
					e = DEREF_exp(tok_stmt_value(atok));
1214
		    } else {
1257
				} else {
1215
			e = NULL_exp ;
1258
					e = NULL_exp;
1216
		    }
1259
				}
1217
		    COPY_exp ( tok_stmt_value ( btok ), e ) ;
1260
				COPY_exp(tok_stmt_value(btok), e);
1218
		    break ;
1261
				break;
1219
		}
1262
			}
1220
		case tok_member_tag : {
1263
			case tok_member_tag: {
1221
		    OFFSET off = DEREF_off ( tok_member_value ( btok ) ) ;
1264
				OFFSET off = DEREF_off(tok_member_value(btok));
1222
		    PUSH_off ( off, token_mem_stack ) ;
1265
				PUSH_off(off, token_mem_stack);
1223
		    if ( at == bt ) {
1266
				if (at == bt) {
1224
			off = DEREF_off ( tok_member_value ( atok ) ) ;
1267
					off = DEREF_off(tok_member_value(atok));
1225
		    } else {
1268
				} else {
1226
			off = NULL_off ;
1269
					off = NULL_off;
1227
		    }
1270
				}
1228
		    COPY_off ( tok_member_value ( btok ), off ) ;
1271
				COPY_off(tok_member_value(btok), off);
1229
		    break ;
1272
				break;
1230
		}
1273
			}
1231
		case tok_type_tag : {
1274
			case tok_type_tag: {
1232
		    TYPE t = DEREF_type ( tok_type_value ( btok ) ) ;
1275
				TYPE t = DEREF_type(tok_type_value(btok));
1233
		    PUSH_type ( t, token_type_stack ) ;
1276
				PUSH_type(t, token_type_stack);
1234
		    if ( at == bt ) {
1277
				if (at == bt) {
1235
			t = DEREF_type ( tok_type_value ( atok ) ) ;
1278
					t = DEREF_type(tok_type_value(atok));
1236
		    } else {
1279
				} else {
1237
			t = NULL_type ;
1280
					t = NULL_type;
1238
		    }
1281
				}
1239
		    COPY_type ( tok_type_value ( btok ), t ) ;
1282
				COPY_type(tok_type_value(btok), t);
1240
		    break ;
1283
				break;
1241
		}
1284
			}
1242
		case tok_class_tag : {
1285
			case tok_class_tag: {
1243
		    IDENTIFIER cid = DEREF_id ( tok_class_value ( btok ) ) ;
1286
				IDENTIFIER cid = DEREF_id(tok_class_value(btok));
1244
		    PUSH_id ( cid, token_class_stack ) ;
1287
				PUSH_id(cid, token_class_stack);
1245
		    if ( at == bt ) {
1288
				if (at == bt) {
1246
			cid = DEREF_id ( tok_class_value ( atok ) ) ;
1289
					cid = DEREF_id(tok_class_value(atok));
1247
		    } else {
1290
				} else {
1248
			cid = NULL_id ;
1291
					cid = NULL_id;
1249
		    }
1292
				}
1250
		    COPY_id ( tok_class_value ( btok ), cid ) ;
1293
				COPY_id(tok_class_value(btok), cid);
1251
		    break ;
1294
				break;
1252
		}
1295
			}
1253
		default : {
1296
			default:
1254
		    /* Procedure arguments not allowed */
1297
				/* Procedure arguments not allowed */
1255
		    break ;
1298
				break;
1256
		}
1299
			}
1257
	    }
-
 
1258
 
1300
 
1259
	    /* Allow definition of parameter */
1301
			/* Allow definition of parameter */
1260
	    ds = DEREF_dspec ( id_storage ( bid ) ) ;
1302
			ds = DEREF_dspec(id_storage(bid));
1261
	    if ( ds & dspec_pure ) {
1303
			if (ds & dspec_pure) {
1262
		ds &= ~dspec_pure ;
1304
				ds &= ~dspec_pure;
1263
		COPY_dspec ( id_storage ( bid ), ds ) ;
1305
				COPY_dspec(id_storage(bid), ds);
1264
		depth = 0 ;
1306
				depth = 0;
1265
	    }
1307
			}
-
 
1308
		}
-
 
1309
		bids = TAIL_list(bids);
1266
	}
1310
	}
1267
	bids = TAIL_list ( bids ) ;
-
 
1268
    }
-
 
1269
    in_proc_token++ ;
1311
	in_proc_token++;
1270
    return ( depth ) ;
1312
	return (depth);
1271
}
1313
}
1272
 
1314
 
1273
 
1315
 
1274
/*
1316
/*
1275
    RESTORE TOKEN ARGUMENT VALUES
1317
    RESTORE TOKEN ARGUMENT VALUES
1276
 
1318
 
1277
    This routine restores the argument values for the token parameters
1319
    This routine restores the argument values for the token parameters
1278
    pids by popping them from the stacks above.  The pure field of the
1320
    pids by popping them from the stacks above.  The pure field of the
1279
    tokens is set if depth is 0.
1321
    tokens is set if depth is 0.
1280
*/
1322
*/
1281
 
1323
 
1282
void restore_token_args
1324
void
1283
    PROTO_N ( ( pids, depth ) )
-
 
1284
    PROTO_T ( LIST ( IDENTIFIER ) pids X int depth )
1325
restore_token_args(LIST(IDENTIFIER) pids, int depth)
1285
{
1326
{
1286
    LIST ( IDENTIFIER ) bids = pids ;
1327
	LIST(IDENTIFIER) bids = pids;
1287
    if ( !IS_NULL_list ( bids ) ) {
1328
	if (!IS_NULL_list(bids)) {
1288
	IDENTIFIER bid = DEREF_id ( HEAD_list ( bids ) ) ;
1329
		IDENTIFIER bid = DEREF_id(HEAD_list(bids));
1289
	bids = TAIL_list ( bids ) ;
1330
		bids = TAIL_list(bids);
1290
	if ( !IS_NULL_list ( bids ) ) {
1331
		if (!IS_NULL_list(bids)) {
1291
	    restore_token_args ( bids, depth ) ;
1332
			restore_token_args(bids, depth);
1292
	    in_proc_token++ ;
1333
			in_proc_token++;
1293
	}
1334
		}
1294
	if ( !IS_NULL_id ( bid ) && IS_id_token ( bid ) ) {
1335
		if (!IS_NULL_id(bid) && IS_id_token(bid)) {
1295
	    TOKEN btok = DEREF_tok ( id_token_sort ( bid ) ) ;
1336
			TOKEN btok = DEREF_tok(id_token_sort(bid));
1296
	    unsigned bt = TAG_tok ( btok ) ;
1337
			unsigned bt = TAG_tok(btok);
1297
	    switch ( bt ) {
1338
			switch (bt) {
1298
		case tok_exp_tag : {
1339
			case tok_exp_tag: {
1299
		    EXP e ;
1340
				EXP e;
1300
		    POP_exp ( e, token_exp_stack ) ;
1341
				POP_exp(e, token_exp_stack);
1301
		    COPY_exp ( tok_exp_value ( btok ), e ) ;
1342
				COPY_exp(tok_exp_value(btok), e);
1302
		    break ;
1343
				break;
1303
		}
1344
			}
1304
		case tok_nat_tag :
1345
			case tok_nat_tag:
1305
		case tok_snat_tag : {
1346
			case tok_snat_tag: {
1306
		    NAT n ;
1347
				NAT n;
1307
		    POP_nat ( n, token_nat_stack ) ;
1348
				POP_nat(n, token_nat_stack);
1308
		    COPY_nat ( tok_nat_etc_value ( btok ), n ) ;
1349
				COPY_nat(tok_nat_etc_value(btok), n);
1309
		    break ;
1350
				break;
1310
		}
1351
			}
1311
		case tok_stmt_tag : {
1352
			case tok_stmt_tag: {
1312
		    EXP e ;
1353
				EXP e;
1313
		    POP_exp ( e, token_stmt_stack ) ;
1354
				POP_exp(e, token_stmt_stack);
1314
		    COPY_exp ( tok_stmt_value ( btok ), e ) ;
1355
				COPY_exp(tok_stmt_value(btok), e);
1315
		    break ;
1356
				break;
1316
		}
1357
			}
1317
		case tok_member_tag : {
1358
			case tok_member_tag: {
1318
		    OFFSET off ;
1359
				OFFSET off;
1319
		    POP_off ( off, token_mem_stack ) ;
1360
				POP_off(off, token_mem_stack);
1320
		    COPY_off ( tok_member_value ( btok ), off ) ;
1361
				COPY_off(tok_member_value(btok), off);
1321
		    break ;
1362
				break;
1322
		}
1363
			}
1323
		case tok_type_tag : {
1364
			case tok_type_tag: {
1324
		    TYPE t ;
1365
				TYPE t;
1325
		    POP_type ( t, token_type_stack ) ;
1366
				POP_type(t, token_type_stack);
1326
		    COPY_type ( tok_type_value ( btok ), t ) ;
1367
				COPY_type(tok_type_value(btok), t);
1327
		    break ;
1368
				break;
1328
		}
1369
			}
1329
		case tok_class_tag : {
1370
			case tok_class_tag: {
1330
		    IDENTIFIER cid ;
1371
				IDENTIFIER cid;
1331
		    POP_id ( cid, token_class_stack ) ;
1372
				POP_id(cid, token_class_stack);
1332
		    COPY_id ( tok_class_value ( btok ), cid ) ;
1373
				COPY_id(tok_class_value(btok), cid);
1333
		    break ;
1374
				break;
1334
		}
1375
			}
1335
		default : {
1376
			default:
1336
		    /* Procedure arguments not allowed */
1377
				/* Procedure arguments not allowed */
1337
		    break ;
1378
				break;
1338
		}
1379
			}
1339
	    }
-
 
1340
	    if ( depth == 0 ) {
1380
			if (depth == 0) {
1341
		/* Can't define parameter at outer level */
1381
				/* Can't define parameter at outer level */
1342
		DECL_SPEC ds = DEREF_dspec ( id_storage ( bid ) ) ;
1382
				DECL_SPEC ds = DEREF_dspec(id_storage(bid));
1343
		ds |= dspec_pure ;
1383
				ds |= dspec_pure;
1344
		COPY_dspec ( id_storage ( bid ), ds ) ;
1384
				COPY_dspec(id_storage(bid), ds);
1345
	    }
1385
			}
-
 
1386
		}
1346
	}
1387
	}
1347
    }
-
 
1348
    in_proc_token-- ;
1388
	in_proc_token--;
1349
    return ;
1389
	return;
1350
}
1390
}
1351
 
1391
 
1352
 
1392
 
1353
/*
1393
/*
1354
    MERGE TOKEN ARGUMENT VALUES
1394
    MERGE TOKEN ARGUMENT VALUES
1355
 
1395
 
1356
    This routine merges the argument values for the token parameters
1396
    This routine merges the argument values for the token parameters
1357
    pids with the values popped off the stacks above.  It returns true
1397
    pids with the values popped off the stacks above.  It returns true
1358
    if the merge was successful.  The pure field of the tokens is set
1398
    if the merge was successful.  The pure field of the tokens is set
1359
    if depth is 0.
1399
    if depth is 0.
1360
*/
1400
*/
1361
 
1401
 
1362
int merge_token_args
1402
int
1363
    PROTO_N ( ( pids, depth, qual ) )
-
 
1364
    PROTO_T ( LIST ( IDENTIFIER ) pids X int depth X int qual )
1403
merge_token_args(LIST(IDENTIFIER) pids, int depth, int qual)
1365
{
1404
{
1366
    int ok = 1 ;
1405
	int ok = 1;
1367
    LIST ( IDENTIFIER ) bids = pids ;
1406
	LIST(IDENTIFIER) bids = pids;
1368
    if ( !IS_NULL_list ( bids ) ) {
1407
	if (!IS_NULL_list(bids)) {
1369
	IDENTIFIER bid = DEREF_id ( HEAD_list ( bids ) ) ;
1408
		IDENTIFIER bid = DEREF_id(HEAD_list(bids));
1370
	bids = TAIL_list ( bids ) ;
1409
		bids = TAIL_list(bids);
1371
	if ( !IS_NULL_list ( bids ) ) {
1410
		if (!IS_NULL_list(bids)) {
1372
	    ok = merge_token_args ( bids, depth, qual ) ;
1411
			ok = merge_token_args(bids, depth, qual);
1373
	    in_proc_token++ ;
1412
			in_proc_token++;
1374
	}
1413
		}
1375
	if ( !IS_NULL_id ( bid ) && IS_id_token ( bid ) ) {
1414
		if (!IS_NULL_id(bid) && IS_id_token(bid)) {
1376
	    TOKEN btok = DEREF_tok ( id_token_sort ( bid ) ) ;
1415
			TOKEN btok = DEREF_tok(id_token_sort(bid));
1377
	    unsigned bt = TAG_tok ( btok ) ;
1416
			unsigned bt = TAG_tok(btok);
1378
	    switch ( bt ) {
1417
			switch (bt) {
1379
		case tok_exp_tag : {
1418
			case tok_exp_tag: {
1380
		    EXP e ;
1419
				EXP e;
1381
		    POP_exp ( e, token_exp_stack ) ;
1420
				POP_exp(e, token_exp_stack);
1382
		    if ( !IS_NULL_exp ( e ) ) {
1421
				if (!IS_NULL_exp(e)) {
1383
			if ( !define_exp_token ( bid, e, 1 ) ) ok = 0 ;
1422
					if (!define_exp_token(bid, e, 1)) {
-
 
1423
						ok = 0;
1384
		    }
1424
					}
-
 
1425
				}
1385
		    break ;
1426
				break;
1386
		}
1427
			}
1387
		case tok_nat_tag :
1428
			case tok_nat_tag:
1388
		case tok_snat_tag : {
1429
			case tok_snat_tag: {
1389
		    NAT n ;
1430
				NAT n;
1390
		    POP_nat ( n, token_nat_stack ) ;
1431
				POP_nat(n, token_nat_stack);
1391
		    if ( !IS_NULL_nat ( n ) ) {
1432
				if (!IS_NULL_nat(n)) {
1392
			if ( !define_nat_token ( bid, n ) ) ok = 0 ;
1433
					if (!define_nat_token(bid, n)) {
-
 
1434
						ok = 0;
1393
		    }
1435
					}
-
 
1436
				}
1394
		    break ;
1437
				break;
1395
		}
1438
			}
1396
		case tok_stmt_tag : {
1439
			case tok_stmt_tag: {
1397
		    EXP e ;
1440
				EXP e;
1398
		    POP_exp ( e, token_stmt_stack ) ;
1441
				POP_exp(e, token_stmt_stack);
1399
		    if ( !IS_NULL_exp ( e ) ) {
1442
				if (!IS_NULL_exp(e)) {
1400
			if ( !define_exp_token ( bid, e, 1 ) ) ok = 0 ;
1443
					if (!define_exp_token(bid, e, 1)) {
-
 
1444
						ok = 0;
1401
		    }
1445
					}
-
 
1446
				}
1402
		    break ;
1447
				break;
1403
		}
1448
			}
1404
		case tok_member_tag : {
1449
			case tok_member_tag: {
1405
		    OFFSET off ;
1450
				OFFSET off;
1406
		    POP_off ( off, token_mem_stack ) ;
1451
				POP_off(off, token_mem_stack);
1407
		    if ( !IS_NULL_off ( off ) ) {
1452
				if (!IS_NULL_off(off)) {
-
 
1453
					TYPE t =
1408
			TYPE t = DEREF_type ( tok_member_type ( btok ) ) ;
1454
					    DEREF_type(tok_member_type(btok));
1409
			if ( !define_mem_token ( bid, off, t, 0 ) ) ok = 0 ;
1455
					if (!define_mem_token(bid, off, t, 0)) {
-
 
1456
						ok = 0;
1410
		    }
1457
					}
-
 
1458
				}
1411
		    break ;
1459
				break;
1412
		}
1460
			}
1413
		case tok_type_tag : {
1461
			case tok_type_tag: {
1414
		    TYPE t ;
1462
				TYPE t;
1415
		    POP_type ( t, token_type_stack ) ;
1463
				POP_type(t, token_type_stack);
1416
		    if ( !IS_NULL_type ( t ) ) {
1464
				if (!IS_NULL_type(t)) {
1417
			if ( !define_type_token ( bid, t, qual ) ) ok = 0 ;
1465
					if (!define_type_token(bid, t, qual)) {
-
 
1466
						ok = 0;
1418
		    }
1467
					}
-
 
1468
				}
1419
		    break ;
1469
				break;
1420
		}
1470
			}
1421
		case tok_class_tag : {
1471
			case tok_class_tag: {
1422
		    IDENTIFIER cid ;
1472
				IDENTIFIER cid;
1423
		    POP_id ( cid, token_class_stack ) ;
1473
				POP_id(cid, token_class_stack);
1424
		    if ( !IS_NULL_id ( cid ) ) {
1474
				if (!IS_NULL_id(cid)) {
1425
			if ( !define_templ_token ( bid, cid ) ) ok = 0 ;
1475
					if (!define_templ_token(bid, cid)) {
-
 
1476
						ok = 0;
1426
		    }
1477
					}
-
 
1478
				}
1427
		    break ;
1479
				break;
1428
		}
1480
			}
1429
		default : {
1481
			default:
1430
		    /* Procedure arguments not allowed */
1482
				/* Procedure arguments not allowed */
1431
		    break ;
1483
				break;
-
 
1484
			}
-
 
1485
			if (depth == 0) {
-
 
1486
				/* Can't define parameter at outer level */
-
 
1487
				DECL_SPEC ds = DEREF_dspec(id_storage(bid));
-
 
1488
				ds |= dspec_pure;
-
 
1489
				COPY_dspec(id_storage(bid), ds);
-
 
1490
			}
1432
		}
1491
		}
1433
	    }
-
 
1434
	    if ( depth == 0 ) {
-
 
1435
		/* Can't define parameter at outer level */
-
 
1436
		DECL_SPEC ds = DEREF_dspec ( id_storage ( bid ) ) ;
-
 
1437
		ds |= dspec_pure ;
-
 
1438
		COPY_dspec ( id_storage ( bid ), ds ) ;
-
 
1439
	    }
-
 
1440
	}
1492
	}
1441
    }
-
 
1442
    in_proc_token-- ;
1493
	in_proc_token--;
1443
    return ( ok ) ;
1494
	return (ok);
1444
}
1495
}
1445
 
1496
 
1446
 
1497
 
1447
/*
1498
/*
1448
    HAS A TOKEN BEEN BOUND?
1499
    HAS A TOKEN BEEN BOUND?
1449
 
1500
 
1450
    This routine checks whether a value has been bound to the token tok.
1501
    This routine checks whether a value has been bound to the token tok.
1451
    If def is true then a dummy value is constructed for unbound values.
1502
    If def is true then a dummy value is constructed for unbound values.
1452
*/
1503
*/
1453
 
1504
 
1454
int is_bound_tok
1505
int
1455
    PROTO_N ( ( tok, def ) )
-
 
1456
    PROTO_T ( TOKEN tok X int def )
1506
is_bound_tok(TOKEN tok, int def)
1457
{
1507
{
1458
    int bound = 1 ;
1508
	int bound = 1;
1459
    if ( !IS_NULL_tok ( tok ) ) {
1509
	if (!IS_NULL_tok(tok)) {
1460
	switch ( TAG_tok ( tok ) ) {
1510
		switch (TAG_tok(tok)) {
1461
	    case tok_exp_tag : {
1511
		case tok_exp_tag: {
1462
		/* Expression tokens */
1512
			/* Expression tokens */
1463
		EXP e = DEREF_exp ( tok_exp_value ( tok ) ) ;
1513
			EXP e = DEREF_exp(tok_exp_value(tok));
1464
		if ( IS_NULL_exp ( e ) || EQ_exp ( e, redef_exp ) ) {
1514
			if (IS_NULL_exp(e) || EQ_exp(e, redef_exp)) {
1465
		    if ( def ) {
1515
				if (def) {
1466
			TYPE t = DEREF_type ( tok_exp_type ( tok ) ) ;
1516
					TYPE t = DEREF_type(tok_exp_type(tok));
1467
			MAKE_exp_value ( t, e ) ;
1517
					MAKE_exp_value(t, e);
1468
			COPY_exp ( tok_exp_value ( tok ), e ) ;
1518
					COPY_exp(tok_exp_value(tok), e);
1469
		    }
1519
				}
1470
		    bound = 0 ;
1520
				bound = 0;
1471
		}
1521
			}
1472
		break ;
1522
			break;
1473
	    }
1523
		}
1474
	    case tok_nat_tag :
1524
		case tok_nat_tag:
1475
	    case tok_snat_tag : {
1525
		case tok_snat_tag: {
1476
		/* Integer constant tokens */
1526
			/* Integer constant tokens */
1477
		NAT n = DEREF_nat ( tok_nat_etc_value ( tok ) ) ;
1527
			NAT n = DEREF_nat(tok_nat_etc_value(tok));
1478
		if ( IS_NULL_nat ( n ) || EQ_nat ( n, redef_nat ) ) {
1528
			if (IS_NULL_nat(n) || EQ_nat(n, redef_nat)) {
1479
		    if ( def ) {
1529
				if (def) {
1480
			n = small_nat [1] ;
1530
					n = small_nat[1];
1481
			COPY_nat ( tok_nat_etc_value ( tok ), n ) ;
1531
					COPY_nat(tok_nat_etc_value(tok), n);
1482
		    }
1532
				}
1483
		    bound = 0 ;
1533
				bound = 0;
1484
		}
1534
			}
1485
		break ;
1535
			break;
1486
	    }
1536
		}
1487
	    case tok_stmt_tag : {
1537
		case tok_stmt_tag: {
1488
		/* Statement tokens */
1538
			/* Statement tokens */
1489
		EXP e = DEREF_exp ( tok_stmt_value ( tok ) ) ;
1539
			EXP e = DEREF_exp(tok_stmt_value(tok));
1490
		if ( IS_NULL_exp ( e ) || EQ_exp ( e, redef_exp ) ) {
1540
			if (IS_NULL_exp(e) || EQ_exp(e, redef_exp)) {
1491
		    if ( def ) {
1541
				if (def) {
1492
			MAKE_exp_value ( type_void, e ) ;
1542
					MAKE_exp_value(type_void, e);
1493
			COPY_exp ( tok_stmt_value ( tok ), e ) ;
1543
					COPY_exp(tok_stmt_value(tok), e);
1494
		    }
1544
				}
1495
		    bound = 0 ;
1545
				bound = 0;
1496
		}
1546
			}
1497
		break ;
1547
			break;
1498
	    }
1548
		}
1499
	    case tok_member_tag : {
1549
		case tok_member_tag: {
1500
		/* Member tokens */
1550
			/* Member tokens */
1501
		OFFSET off = DEREF_off ( tok_member_value ( tok ) ) ;
1551
			OFFSET off = DEREF_off(tok_member_value(tok));
1502
		if ( IS_NULL_off ( off ) || EQ_off ( off, redef_off ) ) {
1552
			if (IS_NULL_off(off) || EQ_off(off, redef_off)) {
1503
		    if ( def ) {
1553
				if (def) {
-
 
1554
					TYPE t =
1504
			TYPE t = DEREF_type ( tok_member_type ( tok ) ) ;
1555
					    DEREF_type(tok_member_type(tok));
1505
			MAKE_off_zero ( t, off ) ;
1556
					MAKE_off_zero(t, off);
1506
			COPY_off ( tok_member_value ( tok ), off ) ;
1557
					COPY_off(tok_member_value(tok), off);
-
 
1558
				}
-
 
1559
				bound = 0;
-
 
1560
			}
-
 
1561
			break;
-
 
1562
		}
-
 
1563
		case tok_type_tag: {
-
 
1564
			/* Type tokens */
-
 
1565
			TYPE t = DEREF_type(tok_type_value(tok));
-
 
1566
			if (IS_NULL_type(t) || EQ_type(t, redef_type)) {
-
 
1567
				if (def) {
-
 
1568
					t = type_error;
-
 
1569
					COPY_type(tok_type_value(tok), t);
-
 
1570
				}
-
 
1571
				bound = 0;
-
 
1572
			}
-
 
1573
			break;
-
 
1574
		}
-
 
1575
		case tok_class_tag: {
-
 
1576
			/* Template class tokens */
-
 
1577
			IDENTIFIER cid = DEREF_id(tok_class_value(tok));
-
 
1578
			if (IS_NULL_id(cid) || EQ_id(cid, redef_id)) {
-
 
1579
				if (def) {
-
 
1580
					HASHID nm = KEYWORD(lex_zzzz);
-
 
1581
					cid = DEREF_id(hashid_id(nm));
-
 
1582
					COPY_id(tok_class_value(tok), cid);
1507
		    }
1583
				}
1508
		    bound = 0 ;
1584
				bound = 0;
-
 
1585
			}
-
 
1586
			break;
1509
		}
1587
		}
1510
		break ;
-
 
1511
	    }
-
 
1512
	    case tok_type_tag : {
-
 
1513
		/* Type tokens */
-
 
1514
		TYPE t = DEREF_type ( tok_type_value ( tok ) ) ;
-
 
1515
		if ( IS_NULL_type ( t ) || EQ_type ( t, redef_type ) ) {
-
 
1516
		    if ( def ) {
-
 
1517
			t = type_error ;
-
 
1518
			COPY_type ( tok_type_value ( tok ), t ) ;
-
 
1519
		    }
-
 
1520
		    bound = 0 ;
-
 
1521
		}
1588
		}
1522
		break ;
-
 
1523
	    }
-
 
1524
	    case tok_class_tag : {
-
 
1525
		/* Template class tokens */
-
 
1526
		IDENTIFIER cid = DEREF_id ( tok_class_value ( tok ) ) ;
-
 
1527
		if ( IS_NULL_id ( cid ) || EQ_id ( cid, redef_id ) ) {
-
 
1528
		    if ( def ) {
-
 
1529
			HASHID nm = KEYWORD ( lex_zzzz ) ;
-
 
1530
			cid = DEREF_id ( hashid_id ( nm ) ) ;
-
 
1531
			COPY_id ( tok_class_value ( tok ), cid ) ;
-
 
1532
		    }
-
 
1533
		    bound = 0 ;
-
 
1534
		}
-
 
1535
		break ;
-
 
1536
	    }
-
 
1537
	}
1589
	}
1538
    }
-
 
1539
    return ( bound ) ;
1590
	return (bound);
1540
}
1591
}
1541
 
1592
 
1542
 
1593
 
1543
/*
1594
/*
1544
    CONSTRUCT A LIST OF TOKEN ARGUMENTS
1595
    CONSTRUCT A LIST OF TOKEN ARGUMENTS
1545
 
1596
 
1546
    This routine constructs a list of token arguments for the token id
1597
    This routine constructs a list of token arguments for the token id
1547
    from the token parameters pids.  Any errors arising from undefined
1598
    from the token parameters pids.  Any errors arising from undefined
1548
    parameters are added to err.
1599
    parameters are added to err.
1549
*/
1600
*/
1550
 
1601
 
1551
LIST ( TOKEN ) make_token_args
1602
LIST(TOKEN)
1552
    PROTO_N ( ( id, pids, err ) )
-
 
1553
    PROTO_T ( IDENTIFIER id X LIST ( IDENTIFIER ) pids X ERROR *err )
1603
make_token_args(IDENTIFIER id, LIST(IDENTIFIER) pids, ERROR *err)
1554
{
1604
{
1555
    LIST ( TOKEN ) args = NULL_list ( TOKEN ) ;
1605
	LIST(TOKEN) args = NULL_list(TOKEN);
1556
    while ( !IS_NULL_list ( pids ) ) {
1606
	while (!IS_NULL_list(pids)) {
1557
	IDENTIFIER pid = DEREF_id ( HEAD_list ( pids ) ) ;
1607
		IDENTIFIER pid = DEREF_id(HEAD_list(pids));
1558
	if ( !IS_NULL_id ( pid ) && IS_id_token ( pid ) ) {
1608
		if (!IS_NULL_id(pid) && IS_id_token(pid)) {
1559
	    TOKEN tok = DEREF_tok ( id_token_sort ( pid ) ) ;
1609
			TOKEN tok = DEREF_tok(id_token_sort(pid));
1560
	    if ( !is_bound_tok ( tok, 1 ) ) {
1610
			if (!is_bound_tok(tok, 1)) {
1561
		/* Token parameter not defined */
1611
				/* Token parameter not defined */
1562
		if ( IS_id_token ( id ) ) {
1612
				if (IS_id_token(id)) {
1563
		    add_error ( err, ERR_token_arg_undef ( pid, id ) ) ;
1613
					add_error(err, ERR_token_arg_undef(pid, id));
1564
		} else {
1614
				} else {
1565
		    add_error ( err, ERR_temp_deduct_undef ( pid, id ) ) ;
1615
					add_error(err, ERR_temp_deduct_undef(pid, id));
-
 
1616
				}
-
 
1617
			}
-
 
1618
			tok = expand_sort(tok, 2, 1);
-
 
1619
			CONS_tok(tok, args, args);
1566
		}
1620
		}
1567
	    }
-
 
1568
	    tok = expand_sort ( tok, 2, 1 ) ;
1621
		pids = TAIL_list(pids);
1569
	    CONS_tok ( tok, args, args ) ;
-
 
1570
	}
1622
	}
1571
	pids = TAIL_list ( pids ) ;
-
 
1572
    }
-
 
1573
    args = REVERSE_list ( args ) ;
1623
	args = REVERSE_list(args);
1574
    return ( args ) ;
1624
	return (args);
1575
}
1625
}
1576
 
1626
 
1577
 
1627
 
1578
/*
1628
/*
1579
    SKIP TOKEN ARGUMENTS
1629
    SKIP TOKEN ARGUMENTS
Line 1581... Line 1631...
1581
    This routine skips a set of token arguments for the token id.  It is
1631
    This routine skips a set of token arguments for the token id.  It is
1582
    entered with the current token pointing to the token name preceding
1632
    entered with the current token pointing to the token name preceding
1583
    the initial open bracket.
1633
    the initial open bracket.
1584
*/
1634
*/
1585
 
1635
 
1586
PPTOKEN *skip_token_args
1636
PPTOKEN *
1587
    PROTO_N ( ( id ) )
-
 
1588
    PROTO_T ( IDENTIFIER id )
1637
skip_token_args(IDENTIFIER id)
1589
{
1638
{
1590
    PPTOKEN *q ;
1639
	PPTOKEN *q;
1591
    LOCATION loc ;
1640
	LOCATION loc;
1592
    int brackets = 0 ;
1641
	int brackets = 0;
1593
    PPTOKEN *p = crt_token ;
1642
	PPTOKEN *p = crt_token;
1594
    loc = crt_loc ;
1643
	loc = crt_loc;
1595
    for ( ; ; ) {
1644
	for (;;) {
1596
	int t = expand_preproc ( EXPAND_AHEAD ) ;
1645
		int t = expand_preproc(EXPAND_AHEAD);
1597
	if ( t == lex_open_Hround ) {
1646
		if (t == lex_open_Hround) {
1598
	    brackets++ ;
1647
			brackets++;
1599
	} else if ( t == lex_close_Hround ) {
1648
		} else if (t == lex_close_Hround) {
1600
	    if ( --brackets == 0 ) break ;
1649
			if (--brackets == 0) {
-
 
1650
				break;
-
 
1651
			}
1601
	} else if ( t == lex_eof ) {
1652
		} else if (t == lex_eof) {
1602
	    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
1653
			HASHID nm = DEREF_hashid(id_name(id));
1603
	    report ( loc, ERR_cpp_replace_arg_eof ( nm ) ) ;
1654
			report(loc, ERR_cpp_replace_arg_eof(nm));
1604
	    break ;
1655
			break;
-
 
1656
		}
1605
	}
1657
	}
1606
    }
-
 
1607
    q = p->next ;
1658
	q = p->next;
1608
    snip_tokens ( q, crt_token ) ;
1659
	snip_tokens(q, crt_token);
1609
    crt_token = p ;
1660
	crt_token = p;
1610
    return ( q ) ;
1661
	return (q);
1611
}
1662
}
1612
 
1663
 
1613
 
1664
 
1614
/*
1665
/*
1615
    PARSE A SET OF TOKEN ARGUMENTS
1666
    PARSE A SET OF TOKEN ARGUMENTS
1616
 
1667
 
1617
    This routine parses the preprocessing tokens p as a list of arguments
1668
    This routine parses the preprocessing tokens p as a list of arguments
1618
    for the procedure token id.
1669
    for the procedure token id.
1619
*/
1670
*/
1620
 
1671
 
1621
static LIST ( TOKEN ) parse_token_args
1672
static LIST(TOKEN)
1622
    PROTO_N ( ( id, p ) )
-
 
1623
    PROTO_T ( IDENTIFIER id X PPTOKEN *p )
1673
parse_token_args(IDENTIFIER id, PPTOKEN *p)
1624
{
1674
{
1625
    int t ;
1675
	int t;
1626
    int d = 0 ;
1676
	int d = 0;
1627
    int ok = 1 ;
1677
	int ok = 1;
1628
    PARSE_STATE st ;
1678
	PARSE_STATE st;
1629
    unsigned m = 0 ;
1679
	unsigned m = 0;
1630
    int started = 0 ;
1680
	int started = 0;
1631
    LIST ( TOKEN ) args ;
1681
	LIST(TOKEN) args;
1632
    ERROR err = NULL_err ;
1682
	ERROR err = NULL_err;
1633
    TOKEN tok = DEREF_tok ( id_token_sort ( id ) ) ;
1683
	TOKEN tok = DEREF_tok(id_token_sort(id));
1634
    LIST ( IDENTIFIER ) pids = DEREF_list ( tok_proc_pids ( tok ) ) ;
1684
	LIST(IDENTIFIER) pids = DEREF_list(tok_proc_pids(tok));
1635
    LIST ( IDENTIFIER ) bids = DEREF_list ( tok_proc_bids ( tok ) ) ;
1685
	LIST(IDENTIFIER) bids = DEREF_list(tok_proc_bids(tok));
1636
    unsigned n = LENGTH_list ( pids ) ;
1686
	unsigned n = LENGTH_list(pids);
1637
 
1687
 
1638
    /* Initialise parser */
1688
	/* Initialise parser */
1639
    save_state ( &st, 1 ) ;
1689
	save_state(&st, 1);
1640
    init_parser ( p ) ;
1690
	init_parser(p);
1641
    ADVANCE_LEXER ;
1691
	ADVANCE_LEXER;
1642
    t = crt_lex_token ;
1692
	t = crt_lex_token;
1643
    if ( t == lex_open_Hround || t == lex_open_Htemplate ) {
1693
	if (t == lex_open_Hround || t == lex_open_Htemplate) {
1644
	ADVANCE_LEXER ;
1694
		ADVANCE_LEXER;
1645
    }
1695
	}
1646
    if ( IS_NULL_list ( pids ) ) {
1696
	if (IS_NULL_list(pids)) {
1647
	/* Empty parameter list */
1697
		/* Empty parameter list */
1648
	t = crt_lex_token ;
1698
		t = crt_lex_token;
1649
	if ( t == lex_close_Hround || t == lex_close_Htemplate ) {
1699
		if (t == lex_close_Hround || t == lex_close_Htemplate) {
1650
	    ADVANCE_LEXER ;
1700
			ADVANCE_LEXER;
1651
	}
1701
		}
1652
    } else {
1702
	} else {
1653
	/* Non-empty parameter list */
1703
		/* Non-empty parameter list */
1654
	while ( !IS_NULL_list ( pids ) ) {
1704
		while (!IS_NULL_list(pids)) {
1655
	    IDENTIFIER pid = DEREF_id ( HEAD_list ( pids ) ) ;
1705
			IDENTIFIER pid = DEREF_id(HEAD_list(pids));
1656
	    if ( !IS_NULL_id ( pid ) ) {
1706
			if (!IS_NULL_id(pid)) {
1657
		TYPE mt = NULL_type ;
1707
				TYPE mt = NULL_type;
1658
		t = crt_lex_token ;
1708
				t = crt_lex_token;
-
 
1709
				if (t == lex_close_Hround ||
1659
		if ( t == lex_close_Hround || t == lex_close_Htemplate ) {
1710
				    t == lex_close_Htemplate) {
1660
		    ADVANCE_LEXER ;
1711
					ADVANCE_LEXER;
1661
		    break ;
1712
					break;
1662
		}
1713
				}
1663
		if ( started ) {
1714
				if (started) {
1664
		    /* Each argument deduction is (nearly) independent */
1715
					/* Each argument deduction is (nearly)
-
 
1716
					 * independent */
1665
		    mt = expand_member_type ( pid ) ;
1717
					mt = expand_member_type(pid);
1666
		    d = save_token_args ( bids, NULL_list ( TOKEN ) ) ;
1718
					d = save_token_args(bids,
-
 
1719
							    NULL_list(TOKEN));
1667
		}
1720
				}
1668
		if ( !parse_token ( pid, mt, 1, 0, bids ) ) ok = 0 ;
1721
				if (!parse_token(pid, mt, 1, 0, bids)) {
-
 
1722
					ok = 0;
-
 
1723
				}
1669
		if ( started ) {
1724
				if (started) {
1670
		    /* Combine argument deductions */
1725
					/* Combine argument deductions */
1671
		    IGNORE merge_token_args ( bids, d, 2 ) ;
1726
					IGNORE merge_token_args(bids, d, 2);
-
 
1727
				}
-
 
1728
				started = 1;
-
 
1729
				if (have_syntax_error) {
-
 
1730
					ok = 0;
-
 
1731
					break;
-
 
1732
				}
-
 
1733
			} else {
-
 
1734
				ok = 0;
-
 
1735
				break;
-
 
1736
			}
-
 
1737
			m++;
-
 
1738
			t = crt_lex_token;
-
 
1739
			if (t == lex_close_Hround ||
-
 
1740
			    t == lex_close_Htemplate) {
-
 
1741
				ADVANCE_LEXER;
-
 
1742
				break;
-
 
1743
			}
-
 
1744
			pids = TAIL_list(pids);
-
 
1745
			if (!IS_NULL_list(pids)) {
-
 
1746
				if (t == lex_comma) {
-
 
1747
					ADVANCE_LEXER;
-
 
1748
				} else {
-
 
1749
					report(crt_loc,
-
 
1750
					       ERR_lex_expect(lex_comma));
-
 
1751
				}
-
 
1752
			}
1672
		}
1753
		}
-
 
1754
	}
-
 
1755
 
-
 
1756
	/* Check for end of arguments */
-
 
1757
	if (ok) {
1673
		started = 1 ;
1758
		t = crt_lex_token;
1674
		if ( have_syntax_error ) {
1759
		if (t == lex_comma) {
1675
		    ok = 0 ;
1760
			m = n + 1;
-
 
1761
		} else if (t != lex_eof) {
-
 
1762
			ERROR err2 = ERR_lex_parse(crt_token);
-
 
1763
			report(crt_loc, err2);
1676
		    break ;
1764
			ok = 0;
1677
		}
1765
		}
1678
	    } else {
1766
		if (ok && m != n) {
-
 
1767
			HASHID nm = DEREF_hashid(id_name(id));
-
 
1768
			ERROR err2 = ERR_cpp_replace_arg_number(nm, m, m, n);
1679
		ok = 0 ;
1769
			report(crt_loc, err2);
1680
		break ;
1770
		}
-
 
1771
		IGNORE check_value(OPT_VAL_macro_args,(ulong)m);
1681
	    }
1772
	}
-
 
1773
 
1682
	    m++ ;
1774
	/* Restore state */
1683
	    t = crt_lex_token ;
1775
	restore_state(&st);
1684
	    if ( t == lex_close_Hround || t == lex_close_Htemplate ) {
1776
	p = restore_parser();
1685
		ADVANCE_LEXER ;
1777
	free_tok_list(p);
1686
		break ;
1778
 
1687
	    }
1779
	/* Construct token arguments */
1688
	    pids = TAIL_list ( pids ) ;
1780
	args = make_token_args(id, bids, &err);
1689
	    if ( !IS_NULL_list ( pids ) ) {
1781
	if (!IS_NULL_err(err)) {
1690
		if ( t == lex_comma ) {
1782
		if (ok) {
1691
		    ADVANCE_LEXER ;
1783
			report(crt_loc, err);
1692
		} else {
1784
		} else {
1693
		    report ( crt_loc, ERR_lex_expect ( lex_comma ) ) ;
1785
			destroy_error(err, 1);
1694
		}
1786
		}
1695
	    }
-
 
1696
	}
-
 
1697
    }
-
 
1698
 
-
 
1699
    /* Check for end of arguments */
-
 
1700
    if ( ok ) {
-
 
1701
	t = crt_lex_token ;
-
 
1702
	if ( t == lex_comma ) {
-
 
1703
	    m = n + 1 ;
-
 
1704
	} else if ( t != lex_eof ) {
-
 
1705
	    ERROR err2 = ERR_lex_parse ( crt_token ) ;
-
 
1706
	    report ( crt_loc, err2 ) ;
-
 
1707
	    ok = 0 ;
-
 
1708
	}
-
 
1709
	if ( ok && m != n ) {
-
 
1710
	    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
-
 
1711
	    ERROR err2 = ERR_cpp_replace_arg_number ( nm, m, m, n ) ;
-
 
1712
	    report ( crt_loc, err2 ) ;
-
 
1713
	}
1787
	}
1714
	IGNORE check_value ( OPT_VAL_macro_args, ( ulong ) m ) ;
-
 
1715
    }
-
 
1716
 
-
 
1717
    /* Restore state */
-
 
1718
    restore_state ( &st ) ;
-
 
1719
    p = restore_parser () ;
-
 
1720
    free_tok_list ( p ) ;
-
 
1721
 
-
 
1722
    /* Construct token arguments */
-
 
1723
    args = make_token_args ( id, bids, &err ) ;
-
 
1724
    if ( !IS_NULL_err ( err ) ) {
-
 
1725
	if ( ok ) {
-
 
1726
	    report ( crt_loc, err ) ;
-
 
1727
	} else {
-
 
1728
	    destroy_error ( err, 1 ) ;
-
 
1729
	}
-
 
1730
    }
-
 
1731
    return ( args ) ;
1788
	return (args);
1732
}
1789
}
1733
 
1790
 
1734
 
1791
 
1735
/*
1792
/*
1736
    PARSE AN EXPRESSION TOKEN
1793
    PARSE AN EXPRESSION TOKEN
1737
 
1794
 
1738
    This routine applies the expression procedure token id to the
1795
    This routine applies the expression procedure token id to the
1739
    arguments given by the preprocessing tokens p.
1796
    arguments given by the preprocessing tokens p.
1740
*/
1797
*/
1741
 
1798
 
1742
EXP parse_exp_token
1799
EXP
1743
    PROTO_N ( ( id, p ) )
-
 
1744
    PROTO_T ( IDENTIFIER id X PPTOKEN *p )
1800
parse_exp_token(IDENTIFIER id, PPTOKEN *p)
1745
{
1801
{
1746
    EXP e ;
1802
	EXP e;
1747
    LIST ( TOKEN ) args ;
1803
	LIST(TOKEN) args;
1748
    TOKEN tok = DEREF_tok ( id_token_sort ( id ) ) ;
1804
	TOKEN tok = DEREF_tok(id_token_sort(id));
1749
    LIST ( IDENTIFIER ) bids = DEREF_list ( tok_proc_bids ( tok ) ) ;
1805
	LIST(IDENTIFIER) bids = DEREF_list(tok_proc_bids(tok));
1750
    int d = save_token_args ( bids, NULL_list ( TOKEN ) ) ;
1806
	int d = save_token_args(bids, NULL_list(TOKEN));
1751
    args = parse_token_args ( id, p ) ;
1807
	args = parse_token_args(id, p);
1752
    e = apply_exp_token ( id, args, 2 ) ;
1808
	e = apply_exp_token(id, args, 2);
1753
    restore_token_args ( bids, d ) ;
1809
	restore_token_args(bids, d);
1754
    return ( e ) ;
1810
	return (e);
1755
}
1811
}
1756
 
1812
 
1757
 
1813
 
1758
/*
1814
/*
1759
    PARSE A TYPE TOKEN
1815
    PARSE A TYPE TOKEN
1760
 
1816
 
1761
    This routine applies the type procedure token id to the arguments
1817
    This routine applies the type procedure token id to the arguments
1762
    given by the preprocessing tokens p.
1818
    given by the preprocessing tokens p.
1763
*/
1819
*/
1764
 
1820
 
1765
TYPE parse_type_token
1821
TYPE
1766
    PROTO_N ( ( id, p ) )
-
 
1767
    PROTO_T ( IDENTIFIER id X PPTOKEN *p )
1822
parse_type_token(IDENTIFIER id, PPTOKEN *p)
1768
{
1823
{
1769
    TYPE t ;
1824
	TYPE t;
1770
    if ( IS_id_token ( id ) ) {
1825
	if (IS_id_token(id)) {
1771
	/* Type token */
1826
		/* Type token */
1772
	LIST ( TOKEN ) args ;
1827
		LIST(TOKEN) args;
1773
	TOKEN tok = DEREF_tok ( id_token_sort ( id ) ) ;
1828
		TOKEN tok = DEREF_tok(id_token_sort(id));
1774
	LIST ( IDENTIFIER ) bids = DEREF_list ( tok_proc_bids ( tok ) ) ;
1829
		LIST(IDENTIFIER) bids = DEREF_list(tok_proc_bids(tok));
1775
	int d = save_token_args ( bids, NULL_list ( TOKEN ) ) ;
1830
		int d = save_token_args(bids, NULL_list(TOKEN));
1776
	args = parse_token_args ( id, p ) ;
1831
		args = parse_token_args(id, p);
1777
	t = apply_type_token ( id, args, NULL_id ) ;
1832
		t = apply_type_token(id, args, NULL_id);
1778
	restore_token_args ( bids, d ) ;
1833
		restore_token_args(bids, d);
1779
    } else {
1834
	} else {
1780
	/* Typedef template */
1835
		/* Typedef template */
1781
	t = parse_typedef_templ ( id, p ) ;
1836
		t = parse_typedef_templ(id, p);
1782
    }
1837
	}
1783
    return ( t ) ;
1838
	return (t);
1784
}
1839
}
1785
 
1840
 
1786
 
1841
 
1787
/*
1842
/*
1788
    PARSE A MEMBER TOKEN
1843
    PARSE A MEMBER TOKEN
1789
 
1844
 
1790
    This routine applies the member procedure token id to the arguments
1845
    This routine applies the member procedure token id to the arguments
1791
    given by the preprocessing tokens p.
1846
    given by the preprocessing tokens p.
1792
*/
1847
*/
1793
 
1848
 
1794
OFFSET parse_mem_token
1849
OFFSET
1795
    PROTO_N ( ( id, p ) )
-
 
1796
    PROTO_T ( IDENTIFIER id X PPTOKEN *p )
1850
parse_mem_token(IDENTIFIER id, PPTOKEN *p)
1797
{
1851
{
1798
    OFFSET off ;
1852
	OFFSET off;
1799
    LIST ( TOKEN ) args ;
1853
	LIST(TOKEN) args;
1800
    TOKEN tok = DEREF_tok ( id_token_sort ( id ) ) ;
1854
	TOKEN tok = DEREF_tok(id_token_sort(id));
1801
    LIST ( IDENTIFIER ) bids = DEREF_list ( tok_proc_bids ( tok ) ) ;
1855
	LIST(IDENTIFIER) bids = DEREF_list(tok_proc_bids(tok));
1802
    int d = save_token_args ( bids, NULL_list ( TOKEN ) ) ;
1856
	int d = save_token_args(bids, NULL_list(TOKEN));
1803
    args = parse_token_args ( id, p ) ;
1857
	args = parse_token_args(id, p);
1804
    off = apply_mem_token ( id, args ) ;
1858
	off = apply_mem_token(id, args);
1805
    restore_token_args ( bids, d ) ;
1859
	restore_token_args(bids, d);
1806
    return ( off ) ;
1860
	return (off);
1807
}
1861
}
1808
 
1862
 
1809
 
1863
 
1810
/*
1864
/*
1811
    DEFINE A TOKEN USING A MACRO
1865
    DEFINE A TOKEN USING A MACRO
1812
 
1866
 
1813
    This routine defines the tokenised object id by means of the macro
1867
    This routine defines the tokenised object id by means of the macro
1814
    mid.  It returns true if this is possible.
1868
    mid.  It returns true if this is possible.
1815
*/
1869
*/
1816
 
1870
 
1817
int define_token_macro
1871
int
1818
    PROTO_N ( ( id, mid ) )
-
 
1819
    PROTO_T ( IDENTIFIER id X IDENTIFIER mid )
1872
define_token_macro(IDENTIFIER id, IDENTIFIER mid)
1820
{
1873
{
1821
    DECL_SPEC fds = DEREF_dspec ( id_storage ( id ) ) ;
1874
    DECL_SPEC fds = DEREF_dspec(id_storage(id));
1822
    IDENTIFIER tid = find_token ( id ) ;
1875
    IDENTIFIER tid = find_token(id);
1823
    if ( IS_id_token ( tid ) ) {
1876
    if (IS_id_token(tid)) {
1824
	int fn = 1 ;
1877
	int fn = 1;
1825
	PPTOKEN *p ;
1878
	PPTOKEN *p;
1826
	PPTOKEN *r ;
1879
	PPTOKEN *r;
1827
	LOCATION loc ;
1880
	LOCATION loc;
1828
	PARSE_STATE st ;
1881
	PARSE_STATE st;
1829
	STACK ( EXP ) tries ;
1882
	STACK(EXP) tries;
1830
	LIST ( IDENTIFIER ) pids ;
1883
	LIST(IDENTIFIER) pids;
1831
	LIST ( TYPE ) ex = univ_type_set ;
1884
	LIST(TYPE) ex = univ_type_set;
1832
	TOKEN tok = DEREF_tok ( id_token_sort ( tid ) ) ;
1885
	TOKEN tok = DEREF_tok(id_token_sort(tid));
1833
	DECL_SPEC ds = DEREF_dspec ( id_storage ( tid ) ) ;
1886
	DECL_SPEC ds = DEREF_dspec(id_storage(tid));
1834
 
1887
 
1835
	/* Find token definition */
1888
	/* Find token definition */
1836
	if ( IS_id_obj_macro ( mid ) ) {
1889
	if (IS_id_obj_macro(mid)) {
1837
	    switch ( TAG_tok ( tok ) ) {
1890
	    switch (TAG_tok(tok)) {
1838
		case tok_func_tag : {
1891
		case tok_func_tag:
1839
		    /* Function tokens read as identifiers */
1892
		    /* Function tokens read as identifiers */
1840
		    IGNORE find_func_token ( id, ( unsigned ) UINT_MAX ) ;
1893
		    IGNORE find_func_token(id,(unsigned)UINT_MAX);
1841
		    COPY_dspec ( id_storage ( id ), ( fds & ~dspec_token ) ) ;
1894
		    COPY_dspec(id_storage(id), (fds & ~dspec_token));
1842
		    fn = 0 ;
1895
		    fn = 0;
1843
		    break ;
1896
		    break;
1844
		}
-
 
1845
		case tok_templ_tag :
1897
		case tok_templ_tag:
1846
		case tok_proc_tag : {
1898
		case tok_proc_tag:
1847
		    /* Can't have procedure tokens */
1899
		    /* Can't have procedure tokens */
1848
		    report ( preproc_loc, ERR_token_def_args ( id ) ) ;
1900
		    report(preproc_loc, ERR_token_def_args(id));
1849
		    return ( 1 ) ;
1901
		    return (1);
1850
		}
-
 
1851
	    }
1902
	    }
1852
	    p = DEREF_pptok ( id_obj_macro_defn ( mid ) ) ;
1903
	    p = DEREF_pptok(id_obj_macro_defn(mid));
1853
	} else {
1904
	} else {
1854
	    unsigned n = DEREF_unsigned ( id_func_macro_no_params ( mid ) ) ;
1905
	    unsigned n = DEREF_unsigned(id_func_macro_no_params(mid));
1855
	    switch ( TAG_tok ( tok ) ) {
1906
	    switch (TAG_tok(tok)) {
1856
		case tok_func_tag : {
1907
		case tok_func_tag: {
1857
		    /* Find function token with n parameters */
1908
		    /* Find function token with n parameters */
1858
		    TYPE t = DEREF_type ( tok_func_type ( tok ) ) ;
1909
		    TYPE t = DEREF_type(tok_func_type(tok));
1859
		    tid = find_func_token ( id, n ) ;
1910
		    tid = find_func_token(id, n);
1860
		    if ( IS_NULL_id ( tid ) ) {
1911
		    if (IS_NULL_id(tid)) {
1861
			report ( preproc_loc, ERR_token_def_args ( id ) ) ;
1912
			report(preproc_loc, ERR_token_def_args(id));
1862
			return ( 1 ) ;
1913
			return (1);
1863
		    }
1914
		    }
1864
		    tok = DEREF_tok ( id_token_sort ( tid ) ) ;
1915
		    tok = DEREF_tok(id_token_sort(tid));
1865
		    tok = func_proc_token ( tok ) ;
1916
		    tok = func_proc_token(tok);
1866
		    id = DEREF_id ( id_token_alt ( tid ) ) ;
1917
		    id = DEREF_id(id_token_alt(tid));
1867
		    fds = DEREF_dspec ( id_storage ( id ) ) ;
1918
		    fds = DEREF_dspec(id_storage(id));
1868
		    COPY_dspec ( id_storage ( id ), ( fds & ~dspec_token ) ) ;
1919
		    COPY_dspec(id_storage(id), (fds & ~dspec_token));
1869
		    ex = DEREF_list ( type_func_except ( t ) ) ;
1920
		    ex = DEREF_list(type_func_except(t));
1870
		    break ;
-
 
1871
		}
-
 
1872
		case tok_proc_tag : {
-
 
1873
		    /* Procedure tokens */
-
 
1874
		    pids = DEREF_list ( tok_proc_pids ( tok ) ) ;
-
 
1875
		    if ( LENGTH_list ( pids ) != n ) {
-
 
1876
			report ( preproc_loc, ERR_token_def_args ( id ) ) ;
-
 
1877
			return ( 1 ) ;
-
 
1878
		    }
-
 
1879
		    break ;
1921
		    break;
1880
		}
1922
		}
1881
		default : {
1923
		case tok_proc_tag:
1882
		    /* Can't have simple tokens */
1924
		    /* Procedure tokens */
-
 
1925
		    pids = DEREF_list(tok_proc_pids(tok));
-
 
1926
		    if (LENGTH_list(pids)!= n) {
1883
		    report ( preproc_loc, ERR_token_def_args ( id ) ) ;
1927
			report(preproc_loc, ERR_token_def_args(id));
1884
		    return ( 1 ) ;
1928
			return (1);
1885
		}
1929
		    }
1886
	    }
1930
		    break;
1887
	    p = DEREF_pptok ( id_func_macro_defn ( mid ) ) ;
-
 
1888
	}
1931
		default:
1889
 
-
 
1890
	/* Expand token definition */
1932
		    /* Can't have simple tokens */
1891
	p = expand_tok_list ( p ) ;
1933
		    report(preproc_loc, ERR_token_def_args(id));
1892
	r = new_pptok () ;
-
 
1893
	r->tok = lex_newline ;
-
 
1894
	r->next = NULL ;
-
 
1895
	if ( p == NULL ) {
-
 
1896
	    p = r ;
1934
		    return (1);
1897
	} else {
1935
	    }
1898
	    PPTOKEN *q = p ;
-
 
1899
	    while ( q->next ) q = q->next ;
1936
	    p = DEREF_pptok(id_func_macro_defn(mid));
1900
	    q->next = r ;
-
 
1901
	}
1937
	}
1902
 
1938
 
-
 
1939
	/* Expand token definition */
-
 
1940
	p = expand_tok_list(p);
-
 
1941
	r = new_pptok();
-
 
1942
	r->tok = lex_newline;
-
 
1943
	r->next = NULL;
-
 
1944
	if (p == NULL) {
-
 
1945
	    p = r;
-
 
1946
	} else {
-
 
1947
	    PPTOKEN *q = p;
-
 
1948
	    while (q->next)q = q->next;
-
 
1949
	    q->next = r;
-
 
1950
	}
-
 
1951
 
1903
	/* Allow for procedure tokens */
1952
	/* Allow for procedure tokens */
1904
	if ( IS_tok_proc ( tok ) ) {
1953
	if (IS_tok_proc(tok)) {
1905
	    NAMESPACE ns ;
1954
	    NAMESPACE ns;
1906
	    PPTOKEN *q = p ;
1955
	    PPTOKEN *q = p;
1907
	    pids = DEREF_list ( tok_proc_pids ( tok ) ) ;
1956
	    pids = DEREF_list(tok_proc_pids(tok));
1908
	    while ( q != NULL ) {
1957
	    while (q != NULL) {
1909
		if ( q->tok == lex_macro_Harg ) {
1958
		if (q->tok == lex_macro_Harg) {
1910
		    unsigned long pn = q->pp_data.par.no - 1 ;
1959
		    unsigned long pn = q->pp_data.par.no - 1;
1911
		    LIST ( IDENTIFIER ) qids = pids ;
1960
		    LIST(IDENTIFIER)qids = pids;
1912
		    while ( pn && !IS_NULL_list ( qids ) ) {
1961
		    while (pn && !IS_NULL_list(qids)) {
1913
			qids = TAIL_list ( qids ) ;
1962
			qids = TAIL_list(qids);
1914
			pn-- ;
1963
			pn--;
1915
		    }
1964
		    }
1916
		    if ( !IS_NULL_list ( qids ) ) {
1965
		    if (!IS_NULL_list(qids)) {
1917
			IDENTIFIER qid = DEREF_id ( HEAD_list ( qids ) ) ;
1966
			IDENTIFIER qid = DEREF_id(HEAD_list(qids));
1918
			if ( !IS_NULL_id ( qid ) ) {
1967
			if (!IS_NULL_id(qid)) {
1919
			    HASHID qnm = DEREF_hashid ( id_name ( qid ) ) ;
1968
			    HASHID qnm = DEREF_hashid(id_name(qid));
1920
			    q->tok = lex_identifier ;
1969
			    q->tok = lex_identifier;
1921
			    q->pp_data.id.hash = qnm ;
1970
			    q->pp_data.id.hash = qnm;
1922
			    q->pp_data.id.use = qid ;
1971
			    q->pp_data.id.use = qid;
1923
			}
1972
			}
1924
		    }
1973
		    }
1925
		}
1974
		}
1926
		q = q->next ;
1975
		q = q->next;
1927
	    }
1976
	    }
1928
	    pids = DEREF_list ( tok_proc_bids ( tok ) ) ;
1977
	    pids = DEREF_list(tok_proc_bids(tok));
1929
	    while ( !IS_NULL_list ( pids ) ) {
1978
	    while (!IS_NULL_list(pids)) {
1930
		IDENTIFIER pid = DEREF_id ( HEAD_list ( pids ) ) ;
1979
		IDENTIFIER pid = DEREF_id(HEAD_list(pids));
1931
		if ( !IS_NULL_id ( pid ) ) {
1980
		if (!IS_NULL_id(pid)) {
1932
		    DECL_SPEC pds = DEREF_dspec ( id_storage ( pid ) ) ;
1981
		    DECL_SPEC pds = DEREF_dspec(id_storage(pid));
1933
		    pds |= dspec_pure ;
1982
		    pds |= dspec_pure;
1934
		    COPY_dspec ( id_storage ( pid ), pds ) ;
1983
		    COPY_dspec(id_storage(pid), pds);
1935
		}
1984
		}
1936
		pids = TAIL_list ( pids ) ;
1985
		pids = TAIL_list(pids);
1937
	    }
1986
	    }
1938
	    ns = DEREF_nspace ( tok_proc_pars ( tok ) ) ;
1987
	    ns = DEREF_nspace(tok_proc_pars(tok));
1939
	    add_namespace ( ns ) ;
1988
	    add_namespace(ns);
1940
	}
1989
	}
1941
 
1990
 
1942
	/* Parse token */
1991
	/* Parse token */
1943
	loc = crt_loc ;
1992
	loc = crt_loc;
1944
	bad_crt_loc++ ;
1993
	bad_crt_loc++;
1945
	crt_loc = preproc_loc ;
1994
	crt_loc = preproc_loc;
1946
	tries = crt_try_blocks ;
1995
	tries = crt_try_blocks;
1947
	start_try_check ( ex ) ;
1996
	start_try_check(ex);
1948
	save_state ( &st, 0 ) ;
1997
	save_state(&st, 0);
1949
	init_parser ( p ) ;
1998
	init_parser(p);
1950
	ADVANCE_LEXER ;
1999
	ADVANCE_LEXER;
1951
	pids = NULL_list ( IDENTIFIER ) ;
2000
	pids = NULL_list(IDENTIFIER);
1952
	IGNORE parse_token ( tid, NULL_type, fn, 1, pids ) ;
2001
	IGNORE parse_token(tid, NULL_type, fn, 1, pids);
1953
	if ( !have_syntax_error && crt_lex_token != lex_newline ) {
2002
	if (!have_syntax_error && crt_lex_token != lex_newline) {
1954
	    ERROR err = ERR_lex_parse ( crt_token ) ;
2003
	    ERROR err = ERR_lex_parse(crt_token);
1955
	    report ( crt_loc, err ) ;
2004
	    report(crt_loc, err);
1956
	}
2005
	}
1957
	if ( ds & dspec_pure ) {
2006
	if (ds & dspec_pure) {
1958
	    report ( preproc_loc, ERR_token_def_not ( id ) ) ;
2007
	    report(preproc_loc, ERR_token_def_not(id));
1959
	} else {
2008
	} else {
-
 
2009
	    if (do_dump) {
1960
	    if ( do_dump ) dump_declare ( id, &crt_loc, 1 ) ;
2010
		    dump_declare(id, &crt_loc, 1);
-
 
2011
	    }
1961
	}
2012
	}
1962
	restore_state ( &st ) ;
2013
	restore_state(&st);
1963
	p = restore_parser () ;
2014
	p = restore_parser();
1964
	free_tok_list ( p ) ;
2015
	free_tok_list(p);
1965
	IGNORE end_try_check ( id, NULL_exp ) ;
2016
	IGNORE end_try_check(id, NULL_exp);
1966
	crt_try_blocks = tries ;
2017
	crt_try_blocks = tries;
1967
	crt_loc = loc ;
2018
	crt_loc = loc;
1968
	bad_crt_loc-- ;
2019
	bad_crt_loc--;
1969
 
2020
 
1970
	/* Allow for procedure tokens */
2021
	/* Allow for procedure tokens */
1971
	if ( IS_tok_proc ( tok ) ) {
2022
	if (IS_tok_proc(tok)) {
1972
	    remove_namespace () ;
2023
	    remove_namespace();
1973
	    pids = DEREF_list ( tok_proc_bids ( tok ) ) ;
2024
	    pids = DEREF_list(tok_proc_bids(tok));
1974
	    while ( !IS_NULL_list ( pids ) ) {
2025
	    while (!IS_NULL_list(pids)) {
1975
		IDENTIFIER pid = DEREF_id ( HEAD_list ( pids ) ) ;
2026
		IDENTIFIER pid = DEREF_id(HEAD_list(pids));
1976
		if ( !IS_NULL_id ( pid ) ) {
2027
		if (!IS_NULL_id(pid)) {
1977
		    DECL_SPEC pds = DEREF_dspec ( id_storage ( pid ) ) ;
2028
		    DECL_SPEC pds = DEREF_dspec(id_storage(pid));
1978
		    pds &= ~dspec_pure ;
2029
		    pds &= ~dspec_pure;
1979
		    COPY_dspec ( id_storage ( pid ), pds ) ;
2030
		    COPY_dspec(id_storage(pid), pds);
1980
		}
2031
		}
1981
		pids = TAIL_list ( pids ) ;
2032
		pids = TAIL_list(pids);
1982
	    }
2033
	    }
1983
	}
2034
	}
1984
	COPY_dspec ( id_storage ( id ), fds ) ;
2035
	COPY_dspec(id_storage(id), fds);
1985
	return ( 1 ) ;
2036
	return (1);
1986
    }
2037
    }
1987
    return ( 0 ) ;
2038
    return (0);
1988
}
2039
}
1989
 
2040
 
1990
 
2041
 
1991
/*
2042
/*
1992
    DEFINE A MEMBER TOKEN
2043
    DEFINE A MEMBER TOKEN
1993
 
2044
 
1994
    This routine is used to define the tokenised member id of t by the
2045
    This routine is used to define the tokenised member id of t by the
1995
    list of immediately following preprocessing tokens.  This is used
2046
    list of immediately following preprocessing tokens.  This is used
1996
    to implement the '#pragma TenDRA member definition' command.
2047
    to implement the '#pragma TenDRA member definition' command.
1997
*/
2048
*/
1998
 
2049
 
1999
int define_mem_macro
2050
int
2000
    PROTO_N ( ( id, t ) )
-
 
2001
    PROTO_T ( IDENTIFIER id X TYPE t )
2051
define_mem_macro(IDENTIFIER id, TYPE t)
2002
{
2052
{
2003
    IDENTIFIER tid = tok_member ( id, t, 0 ) ;
2053
	IDENTIFIER tid = tok_member(id, t, 0);
2004
    if ( !IS_NULL_id ( tid ) ) {
2054
	if (!IS_NULL_id(tid)) {
2005
	id = tid ;
2055
		id = tid;
2006
	tid = find_token ( tid ) ;
2056
		tid = find_token(tid);
2007
	if ( !IS_NULL_id ( tid ) && IS_id_token ( tid ) ) {
2057
		if (!IS_NULL_id(tid) && IS_id_token(tid)) {
2008
	    TOKEN tok = DEREF_tok ( id_token_sort ( tid ) ) ;
2058
			TOKEN tok = DEREF_tok(id_token_sort(tid));
2009
	    if ( IS_tok_member ( tok ) ) {
2059
			if (IS_tok_member(tok)) {
2010
		int def ;
2060
				int def;
2011
		LOCATION loc ;
2061
				LOCATION loc;
2012
		DECL_SPEC ds = DEREF_dspec ( id_storage ( tid ) ) ;
2062
				DECL_SPEC ds = DEREF_dspec(id_storage(tid));
2013
		LIST ( IDENTIFIER ) pids = NULL_list ( IDENTIFIER ) ;
2063
				LIST(IDENTIFIER) pids = NULL_list(IDENTIFIER);
2014
		bad_crt_loc++ ;
2064
				bad_crt_loc++;
2015
		loc = crt_loc ;
2065
				loc = crt_loc;
2016
		crt_loc = preproc_loc ;
2066
				crt_loc = preproc_loc;
2017
		def = parse_token ( tid, NULL_type, 1, 1, pids ) ;
2067
				def = parse_token(tid, NULL_type, 1, 1, pids);
2018
		if ( ds & dspec_pure ) {
2068
				if (ds & dspec_pure) {
-
 
2069
					report(preproc_loc,
2019
		    report ( preproc_loc, ERR_token_def_not ( id ) ) ;
2070
					       ERR_token_def_not(id));
2020
		} else {
2071
				} else {
-
 
2072
					if (do_dump) {
2021
		    if ( do_dump ) dump_declare ( id, &crt_loc, 1 ) ;
2073
						dump_declare(id, &crt_loc, 1);
-
 
2074
					}
2022
		}
2075
				}
2023
		crt_loc = loc ;
2076
				crt_loc = loc;
2024
		bad_crt_loc-- ;
2077
				bad_crt_loc--;
2025
		return ( def ) ;
2078
				return (def);
2026
	    }
2079
			}
-
 
2080
		}
-
 
2081
		report(preproc_loc, ERR_token_undecl(id));
-
 
2082
	}
-
 
2083
	if (in_preproc_dir) {
-
 
2084
		IGNORE skip_to_end();
2027
	}
2085
	}
2028
	report ( preproc_loc, ERR_token_undecl ( id ) ) ;
-
 
2029
    }
-
 
2030
    if ( in_preproc_dir ) IGNORE skip_to_end () ;
-
 
2031
    return ( 0 ) ;
2086
	return (0);
2032
}
2087
}
2033
 
2088
 
2034
 
2089
 
2035
/*
2090
/*
2036
    PENDING TOKEN FOR IDENTIFIER UNIFICATION
2091
    PENDING TOKEN FOR IDENTIFIER UNIFICATION
2037
 
2092
 
2038
    The normal unification routine is called immediately after the
2093
    The normal unification routine is called immediately after the
2039
    declaration of an object.  However for 'const' objects it is more
2094
    declaration of an object.  However for 'const' objects it is more
2040
    useful to postpone the unification until after the initialisation.
2095
    useful to postpone the unification until after the initialisation.
2041
*/
2096
*/
2042
 
2097
 
2043
IDENTIFIER unify_id_pending = NULL_id ;
2098
IDENTIFIER unify_id_pending = NULL_id;
2044
 
2099
 
2045
 
2100
 
2046
/*
2101
/*
2047
    UNIFY TWO IDENTIFIERS
2102
    UNIFY TWO IDENTIFIERS
2048
 
2103
 
Line 2052... Line 2107...
2052
    pid is a token identifier it may be a token definition.  The routine
2107
    pid is a token identifier it may be a token definition.  The routine
2053
    returns true if this is the case.
2108
    returns true if this is the case.
2054
*/
2109
*/
2055
 
2110
 
2056
int unify_id
2111
int unify_id
2057
    PROTO_N ( ( pid, id, def ) )
-
 
2058
    PROTO_T ( IDENTIFIER pid X IDENTIFIER id X int def )
2112
(IDENTIFIER pid, IDENTIFIER id, int def)
2059
{
2113
{
2060
    int ok = 0 ;
2114
    int ok = 0;
2061
    IDENTIFIER tid = DEREF_id ( id_token_alt ( pid ) ) ;
2115
    IDENTIFIER tid = DEREF_id(id_token_alt(pid));
2062
    if ( IS_id_token ( tid ) ) {
2116
    if (IS_id_token(tid)) {
2063
	/* Previous definition was a token */
2117
	/* Previous definition was a token */
2064
	TOKEN tok = DEREF_tok ( id_token_sort ( tid ) ) ;
2118
	TOKEN tok = DEREF_tok(id_token_sort(tid));
2065
	switch ( TAG_tok ( tok ) ) {
2119
	switch (TAG_tok(tok)) {
2066
	    case tok_exp_tag :
2120
	    case tok_exp_tag:
2067
	    case tok_nat_tag :
2121
	    case tok_nat_tag:
2068
	    case tok_snat_tag : {
2122
	    case tok_snat_tag: {
2069
		/* Expression tokens */
2123
		/* Expression tokens */
2070
		EXP e ;
2124
		EXP e;
2071
		int expl = 0 ;
2125
		int expl = 0;
2072
		switch ( TAG_id ( id ) ) {
2126
		switch (TAG_id(id)) {
2073
		    case id_variable_tag : {
2127
		    case id_variable_tag: {
2074
#if LANGUAGE_CPP
2128
#if LANGUAGE_CPP
2075
			TYPE t = DEREF_type ( id_variable_type ( id ) ) ;
2129
			TYPE t = DEREF_type(id_variable_type(id));
2076
			CV_SPEC cv = DEREF_cv ( type_qual ( t ) ) ;
2130
			CV_SPEC cv = DEREF_cv(type_qual(t));
2077
			if ( cv == ( cv_lvalue | cv_const ) ) {
2131
			if (cv == (cv_lvalue | cv_const)) {
2078
			    /* Allow for const objects */
2132
			    /* Allow for const objects */
2079
			    e = DEREF_exp ( id_variable_init ( id ) ) ;
2133
			    e = DEREF_exp(id_variable_init(id));
2080
			    if ( IS_NULL_exp ( e ) ) {
2134
			    if (IS_NULL_exp(e)) {
2081
				if ( IS_NULL_id ( unify_id_pending ) ) {
2135
				if (IS_NULL_id(unify_id_pending)) {
2082
				    unify_id_pending = pid ;
2136
				    unify_id_pending = pid;
2083
				    return ( 1 ) ;
2137
				    return (1);
2084
				}
2138
				}
2085
			    }
2139
			    }
2086
			}
2140
			}
2087
#endif
2141
#endif
2088
			unify_id_pending = NULL_id ;
2142
			unify_id_pending = NULL_id;
2089
			goto variable_label ;
2143
			goto variable_label;
2090
		    }
2144
		    }
2091
		    case id_enumerator_tag : {
2145
		    case id_enumerator_tag:
2092
			expl = 1 ;
2146
			expl = 1;
2093
			goto variable_label ;
2147
			goto variable_label;
2094
		    }
-
 
2095
		    variable_label :
2148
variable_label:
2096
		    case id_parameter_tag :
2149
		    case id_parameter_tag:
2097
		    case id_stat_member_tag : {
2150
		    case id_stat_member_tag: {
2098
			e = make_id_exp ( id ) ;
2151
			e = make_id_exp(id);
2099
			if ( define_exp_token ( tid, e, expl ) ) {
2152
			if (define_exp_token(tid, e, expl)) {
2100
			    LOCATION loc ;
2153
			    LOCATION loc;
2101
			    DEREF_loc ( id_loc ( id ), loc ) ;
2154
			    DEREF_loc(id_loc(id), loc);
2102
			    COPY_loc ( id_loc ( tid ), loc ) ;
2155
			    COPY_loc(id_loc(tid), loc);
2103
			}
2156
			}
2104
			ok = 1 ;
2157
			ok = 1;
2105
			break ;
2158
			break;
2106
		    }
2159
		    }
2107
		}
2160
		}
2108
		break ;
2161
		break;
2109
	    }
2162
	    }
2110
	}
2163
	}
2111
	if ( ok ) {
2164
	if (ok) {
2112
	    /* Set alternate look-up for token */
2165
	    /* Set alternate look-up for token */
2113
	    HASHID nm = DEREF_hashid ( id_name ( tid ) ) ;
2166
	    HASHID nm = DEREF_hashid(id_name(tid));
2114
	    MEMBER mem = search_member ( token_namespace, nm, 0 ) ;
2167
	    MEMBER mem = search_member(token_namespace, nm, 0);
2115
	    if ( !IS_NULL_member ( mem ) ) {
2168
	    if (!IS_NULL_member(mem)) {
2116
		COPY_id ( member_alt ( mem ), id ) ;
2169
		COPY_id(member_alt(mem), id);
2117
	    }
2170
	    }
2118
	}
2171
	}
2119
    }
2172
    }
2120
    if ( ok ) {
2173
    if (ok) {
2121
	/* Token definition */
2174
	/* Token definition */
2122
	DECL_SPEC ds = DEREF_dspec ( id_storage ( tid ) ) ;
2175
	DECL_SPEC ds = DEREF_dspec(id_storage(tid));
2123
	if ( ds & dspec_pure ) {
2176
	if (ds & dspec_pure) {
2124
	    report ( crt_loc, ERR_token_def_not ( pid ) ) ;
2177
	    report(crt_loc, ERR_token_def_not(pid));
2125
	} else {
2178
	} else {
-
 
2179
	    if (do_dump) {
2126
	    if ( do_dump ) dump_declare ( pid, &crt_loc, 1 ) ;
2180
		    dump_declare(pid, &crt_loc, 1);
-
 
2181
	    }
2127
	}
2182
	}
2128
    } else {
2183
    } else {
2129
	/* Illegal redeclaration */
2184
	/* Illegal redeclaration */
-
 
2185
	if (def) {
2130
	if ( def ) id = pid ;
2186
		id = pid;
-
 
2187
	}
2131
	report ( crt_loc, ERR_basic_odr_diff ( id, id_loc ( id ) ) ) ;
2188
	report(crt_loc, ERR_basic_odr_diff(id, id_loc(id)));
2132
    }
2189
    }
2133
    return ( ok ) ;
2190
    return (ok);
2134
}
2191
}