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

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

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

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

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

Warning: Undefined variable $m in /usr/local/www/websvn.planix.org/include/diff_util.php on line 251
WebSVN – tendra.SVN – Diff – /trunk/src/producers/common/parse/preproc.c – Rev 2 and 7

Subversion Repositories tendra.SVN

Rev

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

Rev 2 Rev 7
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2005 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
32
    		 Crown Copyright (c) 1997
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
Line 75... Line 105...
75
 
105
 
76
    The following functions, which are concerned with processing assertions,
106
    The following functions, which are concerned with processing assertions,
77
    are used in read_if_exp before they are defined.
107
    are used in read_if_exp before they are defined.
78
*/
108
*/
79
 
109
 
80
static int eq_pptok PROTO_S ( ( PPTOKEN *, PPTOKEN * ) ) ;
110
static int eq_pptok(PPTOKEN *, PPTOKEN *);
81
static PPTOKEN *skip_predicate PROTO_S ( ( PPTOKEN **, int ) ) ;
111
static PPTOKEN *skip_predicate(PPTOKEN **, int);
82
static int check_assert PROTO_S ( ( HASHID, PPTOKEN *, int ) ) ;
112
static int check_assert(HASHID, PPTOKEN *, int);
83
 
113
 
84
 
114
 
85
/*
115
/*
86
    PREPROCESSING FLAGS
116
    PREPROCESSING FLAGS
87
 
117
 
88
    The flag in_preproc_dir is set to true in a preprocessing directive.
118
    The flag in_preproc_dir is set to true in a preprocessing directive.
89
    The flag preproc_only causes only the preprocessor to be run.  Finally
119
    The flag preproc_only causes only the preprocessor to be run.  Finally
90
    preproc_loc records the position of the start of each preprocessing
120
    preproc_loc records the position of the start of each preprocessing
91
    directive.
121
    directive.
92
*/
122
*/
93
 
123
 
94
int in_preproc_dir = 0 ;
124
int in_preproc_dir = 0;
95
int no_preproc_dir = 0 ;
125
int no_preproc_dir = 0;
96
int in_pragma_dir = 0 ;
126
int in_pragma_dir = 0;
97
int in_hash_if_exp = 0 ;
127
int in_hash_if_exp = 0;
98
int pragma_number = 0 ;
128
int pragma_number = 0;
99
int preproc_only = 0 ;
129
int preproc_only = 0;
100
int preproc_space = 0 ;
130
int preproc_space = 0;
101
LOCATION preproc_loc = NULL_loc ;
131
LOCATION preproc_loc = NULL_loc;
102
 
132
 
103
 
133
 
104
/*
134
/*
105
    NEGATE A CONDITIONAL
135
    NEGATE A CONDITIONAL
106
 
136
 
107
    This routine negates the conditional cond.  Note that skipped and
137
    This routine negates the conditional cond.  Note that skipped and
108
    unresolved conditions negate to themselves.
138
    unresolved conditions negate to themselves.
109
*/
139
*/
110
 
140
 
111
static unsigned negate_cond
141
static unsigned
112
    PROTO_N ( ( cond ) )
-
 
113
    PROTO_T ( unsigned cond )
142
negate_cond(unsigned cond)
114
{
143
{
115
    if ( cond == PP_TRUE ) return ( PP_FALSE ) ;
144
	if (cond == PP_TRUE) {
-
 
145
		return(PP_FALSE);
-
 
146
	}
116
    if ( cond == PP_FALSE ) return ( PP_TRUE ) ;
147
	if (cond == PP_FALSE) {
-
 
148
		return(PP_TRUE);
-
 
149
	}
117
    if ( cond == PP_PAST ) return ( PP_FALSE ) ;
150
	if (cond == PP_PAST) {
-
 
151
		return(PP_FALSE);
-
 
152
	}
118
    return ( cond ) ;
153
	return(cond);
119
}
154
}
120
 
155
 
121
 
156
 
122
/*
157
/*
123
    CONDITIONAL COMPILATION STACK
158
    CONDITIONAL COMPILATION STACK
124
 
159
 
125
    The stack preproc_stack gives all the active conditional compilation
160
    The stack preproc_stack gives all the active conditional compilation
126
    states.  In addition loc_stack records the corresponding file locations.
161
    states.  In addition loc_stack records the corresponding file locations.
127
    preproc_depth gives the depth of conditional compilation within the
162
    preproc_depth gives the depth of conditional compilation within the
128
    current file.
163
    current file.
129
*/
164
*/
130
 
165
 
131
static STACK ( unsigned ) preproc_stack = NULL_stack ( unsigned ) ;
166
static STACK(unsigned)preproc_stack = NULL_stack(unsigned);
132
static STACK ( LOCATION ) loc_stack = NULL_stack ( LOCATION ) ;
167
static STACK(LOCATION)loc_stack = NULL_stack(LOCATION);
133
static unsigned preproc_depth = 0 ;
168
static unsigned preproc_depth = 0;
134
 
169
 
135
 
170
 
136
/*
171
/*
137
    SET UP CONDITIONAL COMPILATION STACK
172
    SET UP CONDITIONAL COMPILATION STACK
138
 
173
 
139
    This routine sets up the conditional compilation stack at the start
174
    This routine sets up the conditional compilation stack at the start
140
    of a source file by pushing an end marker.
175
    of a source file by pushing an end marker.
141
*/
176
*/
142
 
177
 
-
 
178
void
143
void start_preproc_if
179
start_preproc_if(void)
144
    PROTO_Z ()
-
 
145
{
180
{
146
    PUSH_unsigned ( preproc_depth, preproc_stack ) ;
181
	PUSH_unsigned(preproc_depth, preproc_stack);
147
    PUSH_unsigned ( PP_END, preproc_stack ) ;
182
	PUSH_unsigned(PP_END, preproc_stack);
148
    PUSH_loc ( crt_loc, loc_stack ) ;
183
	PUSH_loc(crt_loc, loc_stack);
149
    preproc_depth = 0 ;
184
	preproc_depth = 0;
150
    return ;
185
	return;
151
}
186
}
152
 
187
 
153
 
188
 
154
/*
189
/*
155
    CLEAR CONDITIONAL COMPILATION STACK
190
    CLEAR CONDITIONAL COMPILATION STACK
156
 
191
 
157
    This routine is called at the end of each source file to check for
192
    This routine is called at the end of each source file to check for
158
    any unmatched '#if', '#elif' or '#else' directives.  It clears the
193
    any unmatched '#if', '#elif' or '#else' directives.  It clears the
159
    conditional compilation stack down as far as the end marker set up
194
    conditional compilation stack down as far as the end marker set up
160
    by the previous routine.  It is possible for the routine to be
195
    by the previous routine.  It is possible for the routine to be
161
    called more than once for the main source file, hence the necessity
196
    called more than once for the main source file, hence the necessity
162
    to check that the stack is not empty.  The routine returns true if
197
    to check that the stack is not empty.  The routine returns true if
163
    no unmatched directives are found.
198
    no unmatched directives are found.
164
*/
199
*/
165
 
200
 
-
 
201
int
166
int clear_preproc_if
202
clear_preproc_if(void)
167
    PROTO_Z ()
-
 
168
{
203
{
169
    int ok = 1 ;
204
	int ok = 1;
170
    while ( !IS_NULL_stack ( preproc_stack ) ) {
205
	while (!IS_NULL_stack(preproc_stack)) {
171
	int dir ;
206
		int dir;
172
	LOCATION loc ;
207
		LOCATION loc;
173
	unsigned cond ;
208
		unsigned cond;
174
	POP_unsigned ( cond, preproc_stack ) ;
209
		POP_unsigned(cond, preproc_stack);
175
	POP_loc ( loc, loc_stack ) ;
210
		POP_loc(loc, loc_stack);
176
	if ( cond == PP_END ) {
211
		if (cond == PP_END) {
177
	    /* Restore stored preprocessing depth */
212
			/* Restore stored preprocessing depth */
178
	    POP_unsigned ( preproc_depth, preproc_stack ) ;
213
			POP_unsigned(preproc_depth, preproc_stack);
179
	    break ;
214
			break;
180
	}
215
		}
181
	if ( cond & PP_HAVE_ELSE ) {
216
		if (cond & PP_HAVE_ELSE) {
182
	    dir = lex_else ;
217
			dir = lex_else;
183
	} else if ( cond & PP_HAVE_ELIF ) {
218
		} else if (cond & PP_HAVE_ELIF) {
184
	    dir = lex_elif ;
219
			dir = lex_elif;
185
	} else {
220
		} else {
186
	    dir = lex_if ;
221
			dir = lex_if;
-
 
222
		}
-
 
223
		report(loc, ERR_cpp_cond_if_match(dir, lex_endif));
-
 
224
		decr_value(OPT_VAL_hash_if_depth);
-
 
225
		preproc_depth--;
-
 
226
		ok = 0;
187
	}
227
	}
188
	report ( loc, ERR_cpp_cond_if_match ( dir, lex_endif ) ) ;
-
 
189
	decr_value ( OPT_VAL_hash_if_depth ) ;
-
 
190
	preproc_depth-- ;
-
 
191
	ok = 0 ;
-
 
192
    }
-
 
193
    return ( ok ) ;
228
	return(ok);
194
}
229
}
195
 
230
 
196
 
231
 
197
/*
232
/*
198
    MACRO-LIKE TOKEN IDENTIFIER
233
    MACRO-LIKE TOKEN IDENTIFIER
199
 
234
 
200
    If check_macro finds a macro-like token then the corresponding identifier
235
    If check_macro finds a macro-like token then the corresponding identifier
201
    is stored in this variable.
236
    is stored in this variable.
202
*/
237
*/
203
 
238
 
204
IDENTIFIER token_macro = NULL_id ;
239
IDENTIFIER token_macro = NULL_id;
205
 
240
 
206
 
241
 
207
/*
242
/*
208
    CHECK WHETHER A MACRO IS DEFINED
243
    CHECK WHETHER A MACRO IS DEFINED
209
 
244
 
Line 212... Line 247...
212
    PP_FALSE otherwise.  It also reports on ISO keywords and other invalid
247
    PP_FALSE otherwise.  It also reports on ISO keywords and other invalid
213
    macro identifiers.  If used is true then the macro is marked as having
248
    macro identifiers.  If used is true then the macro is marked as having
214
    been used.
249
    been used.
215
*/
250
*/
216
 
251
 
217
unsigned check_macro
252
unsigned
218
    PROTO_N ( ( macro, used ) )
-
 
219
    PROTO_T ( HASHID macro X int used )
253
check_macro(HASHID macro, int used)
220
{
254
{
221
    /* Check for simple macros */
255
	/* Check for simple macros */
222
    DECL_SPEC ds ;
256
	DECL_SPEC ds;
223
    IDENTIFIER id ;
257
	IDENTIFIER id;
224
    if ( IS_NULL_hashid ( macro ) ) {
258
	if (IS_NULL_hashid(macro)) {
225
	/* Special case for protection macros */
259
		/* Special case for protection macros */
226
	return ( PP_TRUE ) ;
260
		return(PP_TRUE);
227
    }
-
 
228
    id = DEREF_id ( hashid_id ( macro ) ) ;
-
 
229
    switch ( TAG_id ( id ) ) {
-
 
230
	case id_obj_macro_tag :
-
 
231
	case id_func_macro_tag : {
-
 
232
	    if ( used ) {
-
 
233
		ds = DEREF_dspec ( id_storage ( id ) ) ;
-
 
234
		ds |= dspec_used ;
-
 
235
		COPY_dspec ( id_storage ( id ), ds ) ;
-
 
236
		if ( do_macro && do_usage ) dump_use ( id, &preproc_loc, 1 ) ;
-
 
237
	    }
-
 
238
	    return ( PP_TRUE ) ;
-
 
239
	}
261
	}
-
 
262
	id = DEREF_id(hashid_id(macro));
-
 
263
	switch (TAG_id(id)) {
240
	case id_iso_keyword_tag : {
264
	case id_obj_macro_tag:
241
	    if ( used ) report ( preproc_loc, ERR_lex_key_iso ( macro ) ) ;
265
	case id_func_macro_tag:
242
	    break ;
266
		if (used) {
243
	}
-
 
244
    }
-
 
245
 
-
 
246
    /* Check for tokenised values */
267
			ds = DEREF_dspec(id_storage(id));
247
    if ( preproc_only ) {
268
			ds |= dspec_used;
248
	id = underlying_id ( id ) ;
269
			COPY_dspec(id_storage(id), ds);
249
	ds = DEREF_dspec ( id_storage ( id ) ) ;
270
			if (do_macro && do_usage) {
250
	if ( ds & dspec_token ) {
271
				dump_use(id, &preproc_loc, 1);
-
 
272
			}
-
 
273
		}
-
 
274
		return(PP_TRUE);
251
	    /* May be a token */
275
	case id_iso_keyword_tag:
252
	    token_macro = id ;
276
		if (used) {
253
	    return ( PP_TOKEN | PP_UNRESOLVED ) ;
277
			report(preproc_loc, ERR_lex_key_iso(macro));
-
 
278
		}
-
 
279
		break;
254
	}
280
	}
255
 
281
 
-
 
282
	/* Check for tokenised values */
-
 
283
	if (preproc_only) {
-
 
284
		id = underlying_id(id);
-
 
285
		ds = DEREF_dspec(id_storage(id));
-
 
286
		if (ds & dspec_token) {
-
 
287
			/* May be a token */
-
 
288
			token_macro = id;
-
 
289
			return(PP_TOKEN | PP_UNRESOLVED);
-
 
290
		}
-
 
291
 
256
    } else {
292
	} else {
257
	id = find_id ( macro ) ;
293
		id = find_id(macro);
258
	while ( !IS_NULL_id ( id ) ) {
294
		while (!IS_NULL_id(id)) {
259
	    IDENTIFIER tid = find_token ( id ) ;
295
			IDENTIFIER tid = find_token(id);
260
	    if ( IS_id_token ( tid ) ) {
296
			if (IS_id_token(tid)) {
261
		IDENTIFIER sid = DEREF_id ( id_token_alt ( tid ) ) ;
297
				IDENTIFIER sid = DEREF_id(id_token_alt(tid));
262
		ds = DEREF_dspec ( id_storage ( sid ) ) ;
298
				ds = DEREF_dspec(id_storage(sid));
-
 
299
				if ((ds & dspec_token) &&
263
		if ( ( ds & dspec_token ) && !( ds & dspec_template ) ) {
300
				    !(ds & dspec_template)) {
-
 
301
					TOKEN tok =
264
		    TOKEN tok = DEREF_tok ( id_token_sort ( tid ) ) ;
302
					    DEREF_tok(id_token_sort(tid));
265
		    switch ( TAG_tok ( tok ) ) {
303
					switch (TAG_tok(tok)) {
266
			case tok_exp_tag :
304
					case tok_exp_tag:
267
			case tok_stmt_tag :
305
					case tok_stmt_tag:
268
			case tok_nat_tag :
306
					case tok_nat_tag:
269
			case tok_snat_tag :
307
					case tok_snat_tag:
270
			case tok_func_tag :
308
					case tok_func_tag:
271
			case tok_proc_tag : {
309
					case tok_proc_tag:
272
			    /* These are in the macro namespace */
310
						/* These are in the macro
-
 
311
						 * namespace */
-
 
312
						if (used) {
273
			    if ( used ) use_id ( id, 0 ) ;
313
							use_id(id, 0);
-
 
314
						}
274
			    token_macro = id ;
315
						token_macro = id;
275
			    ds = DEREF_dspec ( id_storage ( tid ) ) ;
316
						ds = DEREF_dspec(id_storage(tid));
276
			    if ( ds & ( dspec_pure | dspec_defn ) ) {
317
						if (ds & (dspec_pure |
-
 
318
							  dspec_defn)) {
277
				return ( PP_TOKEN | PP_TRUE ) ;
319
							return(PP_TOKEN |
-
 
320
							       PP_TRUE);
278
			    }
321
						}
279
			    return ( PP_TOKEN | PP_FALSE ) ;
322
						return(PP_TOKEN | PP_FALSE);
-
 
323
					}
-
 
324
				}
-
 
325
			}
-
 
326
			if (!IS_id_function_etc(id)) {
-
 
327
				break;
280
			}
328
			}
281
		    }
329
			id = DEREF_id(id_function_etc_over(id));
282
		}
330
		}
283
	    }
-
 
284
	    if ( !IS_id_function_etc ( id ) ) break ;
-
 
285
	    id = DEREF_id ( id_function_etc_over ( id ) ) ;
-
 
286
	}
331
	}
287
    }
-
 
288
    return ( PP_FALSE ) ;
332
	return(PP_FALSE);
289
}
333
}
290
 
334
 
291
 
335
 
292
/*
336
/*
293
    TARGET DEPENDENT CONDITION
337
    TARGET DEPENDENT CONDITION
294
 
338
 
295
    Any target dependent conditional compilation expressions encountered
339
    Any target dependent conditional compilation expressions encountered
296
    are stored in this variable.
340
    are stored in this variable.
297
*/
341
*/
298
 
342
 
299
EXP crt_hash_if_exp = NULL_exp ;
343
EXP crt_hash_if_exp = NULL_exp;
300
 
344
 
301
 
345
 
302
/*
346
/*
303
    PATCH PREPROCESSING DIRECTIVE INTO PREPROCESSOR OUTPUT
347
    PATCH PREPROCESSING DIRECTIVE INTO PREPROCESSOR OUTPUT
304
 
348
 
305
    This routine is used to patch the preprocessing directive given by
349
    This routine is used to patch the preprocessing directive given by
306
    the preprocessing tokens p into the main preprocessor output.  It is
350
    the preprocessing tokens p into the main preprocessor output.  It is
307
    used to preserve target dependent conditionals and other directives
351
    used to preserve target dependent conditionals and other directives
308
    which need to be passed through to the output.
352
    which need to be passed through to the output.
309
*/
353
*/
310
 
354
 
311
void patch_preproc_dir
355
void
312
    PROTO_N ( ( p ) )
-
 
313
    PROTO_T ( PPTOKEN *p )
356
patch_preproc_dir(PPTOKEN *p)
314
{
357
{
315
    if ( p ) {
358
	if (p) {
316
	PPTOKEN *q = p ;
359
		PPTOKEN *q = p;
317
	while ( q->next && q->next->tok != lex_newline ) q = q->next ;
360
		while (q->next && q->next->tok != lex_newline) {
-
 
361
			q = q->next;
-
 
362
		}
318
	free_tok_list ( q->next ) ;
363
		free_tok_list(q->next);
319
	q->next = crt_token->next ;
364
		q->next = crt_token->next;
320
	crt_token->next = p ;
365
		crt_token->next = p;
321
	p->pp_space = WHITE_SPACE ;
366
		p->pp_space = WHITE_SPACE;
322
    }
367
	}
323
    return ;
368
	return;
324
}
369
}
325
 
370
 
326
 
371
 
327
/*
372
/*
328
    READ AN EXPRESSION COMPILATION CONDITION
373
    READ AN EXPRESSION COMPILATION CONDITION
Line 335... Line 380...
335
    defined operations suitably expanded.  This is then macro expanded
380
    defined operations suitably expanded.  This is then macro expanded
336
    and finally has any remaining identifiers replaced by 0.  All the
381
    and finally has any remaining identifiers replaced by 0.  All the
337
    parsing is done using this list of tokens - no other tokens are read
382
    parsing is done using this list of tokens - no other tokens are read
338
    from the input file (the newline appended by read_line ensures that
383
    from the input file (the newline appended by read_line ensures that
339
    the parser doesn't spill off the end).
384
    the parser doesn't spill off the end).
433
 
577
 
434
	/* Check for any remaining identifiers */
578
		/* Check the result expression */
435
	while ( q != NULL ) {
579
		if (!IS_NULL_exp(e)) {
436
	    if ( q->tok == lex_identifier ) {
580
			/* Evaluate the expression */
-
 
581
			ERROR err = NULL_err;
437
		HASHID nm = q->pp_data.id.hash ;
582
			IGNORE make_nat_exp(e, &err);
438
		IDENTIFIER id = DEREF_id ( hashid_id ( nm ) ) ;
583
			e = convert_boolean(e, exp_paren_tag, &err);
439
		unsigned tag = TAG_id ( id ) ;
584
			if (!IS_NULL_err(err)) {
440
		if ( tag == id_obj_macro_tag || tag == id_func_macro_tag ) {
585
				err = concat_error(err,
441
		    /* Allow for unexpanded macros */
586
						   ERR_cpp_cond_if_const(dir));
442
		    id = DEREF_id ( id_alias ( id ) ) ;
587
				report(preproc_loc, err);
443
		    tag = TAG_id ( id ) ;
588
				cond = PP_FALSE;
444
		}
589
			} else {
-
 
590
				unsigned b = eval_const_cond(e);
445
		if ( tag == id_keyword_tag ) {
591
				if (b == BOOL_TRUE) {
446
		    int u = ( int ) DEREF_ulong ( id_no ( id ) ) ;
592
					cond = PP_TRUE;
447
		    if ( u == lex_true || u == lex_false ) {
593
				} else if (b == BOOL_FALSE) {
448
			/* Preserve boolean literals */
594
					cond = PP_FALSE;
-
 
595
				} else {
449
			tag = id_iso_keyword_tag ;
596
					cond = PP_UNRESOLVED;
450
		    }
597
				}
-
 
598
			}
451
		}
599
		}
-
 
600
 
452
		if ( tag == id_iso_keyword_tag ) {
601
		/* Restore the parser */
453
		    /* Allow for ISO keywords */
602
		p = restore_parser();
454
		    int u = ( int ) DEREF_ulong ( id_no ( id ) ) ;
603
		if (cond == PP_UNRESOLVED) {
455
		    int v = primary_form ( u ) ;
604
			/* Save target dependent conditions */
456
		    if ( v != u ) {
605
			if (preproc_only) {
457
			ERROR err = ERR_lex_digraph_iso ( nm, v ) ;
606
				/* Patch crt_token with tokens comprising
-
 
607
				 * condition */
458
			report ( preproc_loc, err ) ;
608
				p = clean_tok_list(p);
459
		    }
609
				patch_preproc_dir(p);
460
		    q->tok = v ;
610
				p = NULL;
461
		} else {
611
			} else {
462
		    unsigned c = check_macro ( nm, 0 ) ;
-
 
463
		    if ( c & PP_TOKEN ) {
-
 
464
			/* Preserve token identifiers */
612
				/* Store condition in crt_hash_if_exp */
465
			c &= PP_COND_MASK ;
-
 
466
			if ( c == PP_UNRESOLVED ) {
613
				report(preproc_loc, ERR_cpp_cond_if_ti(dir));
467
			    cond = PP_UNRESOLVED ;
614
				crt_hash_if_exp = e;
468
			}
615
			}
469
		    } else {
-
 
470
			/* Replace other identifiers by 0 */
-
 
471
			ERROR err ;
-
 
472
			if ( EQ_hashid ( nm, def ) ) {
-
 
473
			    /* Shouldn't have defined */
-
 
474
			    err = ERR_cpp_cond_def_replace () ;
-
 
475
			    if ( !IS_NULL_err ( err ) ) {
-
 
476
				report ( preproc_loc, err ) ;
-
 
477
			    }
-
 
478
			}
-
 
479
			/* QUERY: what about true and false? */
-
 
480
			err = ERR_cpp_cond_zero ( nm ) ;
-
 
481
			if ( !IS_NULL_err ( err ) ) {
-
 
482
			    report ( preproc_loc, err ) ;
-
 
483
			}
-
 
484
			q->tok = lex_integer_Hlit ;
-
 
485
			q->pp_data.text = ustrlit ( "0" ) ;
-
 
486
		    }
-
 
487
		}
616
		}
488
	    }
-
 
489
	    q = q->next ;
-
 
490
	}
-
 
491
 
-
 
492
	/* Parse the line for a constant expression */
-
 
493
	save_state ( &ps, 0 ) ;
-
 
494
	init_parser ( p ) ;
617
		free_tok_list(p);
495
	in_hash_if_exp++ ;
618
		in_hash_if_exp--;
496
	crt_loc = preproc_loc ;
-
 
497
	crt_line_changed = 1 ;
-
 
498
	ADVANCE_LEXER ;
-
 
499
	if ( cond == PP_UNRESOLVED ) {
-
 
500
	    /* Unresolved tokens when preprocessing */
-
 
501
	    ASSERT ( preproc_only ) ;
-
 
502
	    /* EMPTY */
-
 
503
	} else {
-
 
504
	    /* Parse condition */
-
 
505
	    cond = PP_FALSE ;
-
 
506
	    parse_nat ( &e ) ;
-
 
507
	    if ( crt_lex_token != lex_newline && !have_syntax_error ) {
-
 
508
		/* Should have reached the end of the line */
-
 
509
		ERROR err = ERR_lex_parse ( crt_token ) ;
-
 
510
		err = concat_error ( err, ERR_cpp_end ( dir ) ) ;
-
 
511
		report ( preproc_loc, err ) ;
-
 
512
	    }
-
 
513
	}
-
 
514
	restore_state ( &ps ) ;
-
 
515
 
-
 
516
	/* Check the result expression */
-
 
517
	if ( !IS_NULL_exp ( e ) ) {
-
 
518
	    /* Evaluate the expression */
-
 
519
	    ERROR err = NULL_err ;
-
 
520
	    IGNORE make_nat_exp ( e, &err ) ;
-
 
521
	    e = convert_boolean ( e, exp_paren_tag, &err ) ;
-
 
522
	    if ( !IS_NULL_err ( err ) ) {
-
 
523
		err = concat_error ( err, ERR_cpp_cond_if_const ( dir ) ) ;
-
 
524
		report ( preproc_loc, err ) ;
-
 
525
		cond = PP_FALSE ;
-
 
526
	    } else {
-
 
527
		unsigned b = eval_const_cond ( e ) ;
-
 
528
		if ( b == BOOL_TRUE ) {
-
 
529
		    cond = PP_TRUE ;
-
 
530
		} else if ( b == BOOL_FALSE ) {
-
 
531
		    cond = PP_FALSE ;
-
 
532
		} else {
-
 
533
		    cond = PP_UNRESOLVED ;
-
 
534
		}
-
 
535
	    }
-
 
536
	}
619
	}
537
 
-
 
538
	/* Restore the parser */
-
 
539
	p = restore_parser () ;
-
 
540
	if ( cond == PP_UNRESOLVED ) {
-
 
541
	    /* Save target dependent conditions */
-
 
542
	    if ( preproc_only ) {
-
 
543
		/* Patch crt_token with tokens comprising condition */
-
 
544
		p = clean_tok_list ( p ) ;
-
 
545
		patch_preproc_dir ( p ) ;
620
	if (in_preproc_dir) {
546
		p = NULL ;
-
 
547
	    } else {
-
 
548
		/* Store condition in crt_hash_if_exp */
-
 
549
		report ( preproc_loc, ERR_cpp_cond_if_ti ( dir ) ) ;
-
 
550
		crt_hash_if_exp = e ;
621
		IGNORE skip_to_end();
551
	    }
-
 
552
	}
622
	}
553
	free_tok_list ( p ) ;
-
 
554
	in_hash_if_exp-- ;
-
 
555
    }
-
 
556
    if ( in_preproc_dir ) IGNORE skip_to_end () ;
-
 
557
    return ( cond ) ;
623
	return(cond);
558
}
624
}
559
 
625
 
560
 
626
 
561
/*
627
/*
562
    READ A DEFINED COMPILATION CONDITION
628
    READ A DEFINED COMPILATION CONDITION
563
 
629
 
564
    This routine reads the macro identifier following a '#ifdef' or
630
    This routine reads the macro identifier following a '#ifdef' or
565
    '#ifndef' preprocessing directive.  It returns a value indicating
631
    '#ifndef' preprocessing directive.  It returns a value indicating
566
    whether the macro is defined or not.  The argument act is false to
632
    whether the macro is defined or not.  The argument act is false to
567
    indicate that the directive is being skipped, prev is as in
633
    indicate that the directive is being skipped, prev is as in
568
    read_preproc_dir.
634
    read_preproc_dir.
569
*/
635
*/
570
 
636
 
571
static unsigned read_if_def
637
static unsigned
572
    PROTO_N ( ( act, dir, prev ) )
-
 
573
    PROTO_T ( int act X int dir X int prev )
638
read_if_def(int act, int dir, int prev)
574
{
639
{
575
    unsigned cond ;
640
	unsigned cond;
576
    if ( act ) {
641
	if (act) {
577
	int t = read_token () ;
642
		int t = read_token();
578
	update_column () ;
643
		update_column();
-
 
644
		if (in_preproc_dir) {
579
	if ( in_preproc_dir ) preproc_loc = crt_loc ;
645
			preproc_loc = crt_loc;
-
 
646
		}
580
	if ( t == lex_identifier ) {
647
		if (t == lex_identifier) {
581
	    HASHID macro = token_hashid ;
648
			HASHID macro = token_hashid;
582
	    cond = check_macro ( macro, 1 ) ;
649
			cond = check_macro(macro, 1);
583
	    cond &= PP_COND_MASK ;
650
			cond &= PP_COND_MASK;
584
	    if ( prev == lex_included ) {
651
			if (prev == lex_included) {
585
		/* Protection macro begins '#ifndef macro' */
652
				/* Protection macro begins '#ifndef macro' */
586
		protection_macro ( macro, prev, dir ) ;
653
				protection_macro(macro, prev, dir);
587
	    }
654
			}
588
	    if ( in_preproc_dir && skip_to_end () ) {
655
			if (in_preproc_dir && skip_to_end()) {
589
		report ( preproc_loc, ERR_cpp_end ( dir ) ) ;
656
				report(preproc_loc, ERR_cpp_end(dir));
590
	    }
657
			}
-
 
658
		} else {
-
 
659
			report(preproc_loc, ERR_cpp_cond_ifdef_id(dir));
-
 
660
			cond = PP_FALSE;
-
 
661
		}
591
	} else {
662
	} else {
-
 
663
		cond = PP_SKIP;
-
 
664
	}
592
	    report ( preproc_loc, ERR_cpp_cond_ifdef_id ( dir ) ) ;
665
	if (in_preproc_dir) {
593
	    cond = PP_FALSE ;
666
		IGNORE skip_to_end();
594
	}
667
	}
595
    } else {
-
 
596
	cond = PP_SKIP ;
-
 
597
    }
-
 
598
    if ( in_preproc_dir ) IGNORE skip_to_end () ;
-
 
599
    return ( cond ) ;
668
	return(cond);
600
}
669
}
601
 
670
 
602
 
671
 
603
/*
672
/*
604
    DEAL WITH CONDITIONAL COMPILATIONS
673
    DEAL WITH CONDITIONAL COMPILATIONS
Line 610... Line 679...
610
    '#elif' directives, lex_end_condition for simple '#else' and '#endif'
679
    '#elif' directives, lex_end_condition for simple '#else' and '#endif'
611
    directives, and one of the values lex_hash_Hif, lex_hash_Helif,
680
    directives, and one of the values lex_hash_Hif, lex_hash_Helif,
612
    lex_hash_Helse and lex_hash_Hendif for target dependent conditions.
681
    lex_hash_Helse and lex_hash_Hendif for target dependent conditions.
613
*/
682
*/
614
 
683
 
615
static int read_if
684
static int
616
    PROTO_N ( ( dir, c, prev ) )
-
 
617
    PROTO_T ( int dir X unsigned c X int prev )
685
read_if(int dir, unsigned c, int prev)
618
{
686
{
619
    unsigned cond = c ;
687
	unsigned cond = c;
620
    int ret = lex_ignore_token ;
688
	int ret = lex_ignore_token;
621
 
689
 
622
    if ( dir == lex_if || dir == lex_ifdef || dir == lex_ifndef ) {
690
	if (dir == lex_if || dir == lex_ifdef || dir == lex_ifndef) {
623
	/* Deal with '#if', '#ifdef' and '#ifndef' */
691
		/* Deal with '#if', '#ifdef' and '#ifndef' */
624
	if ( cond == PP_UNRESOLVED ) ret = lex_hash_Hif ;
-
 
625
	if ( prev != lex_included && preproc_depth == 0 ) {
-
 
626
	    /* Can't have second '#if' in protection macro */
-
 
627
	    protection_macro ( NULL_hashid, lex_ignore_token, dir ) ;
-
 
628
	}
-
 
629
	PUSH_unsigned ( cond, preproc_stack ) ;
-
 
630
	PUSH_loc ( preproc_loc, loc_stack ) ;
-
 
631
	IGNORE incr_value ( OPT_VAL_hash_if_depth ) ;
-
 
632
	preproc_depth++ ;
-
 
633
 
-
 
634
    } else {
-
 
635
	/* Get current condition for other directives */
-
 
636
	LOCATION loc ;
-
 
637
	unsigned crt_cond ;
-
 
638
	POP_unsigned ( cond, preproc_stack ) ;
-
 
639
	decr_value ( OPT_VAL_hash_if_depth ) ;
-
 
640
	preproc_depth-- ;
-
 
641
	/* Don't pop location yet */
-
 
642
	if ( cond == PP_END ) {
-
 
643
	    /* No matching '#if' */
-
 
644
	    ERROR err = ERR_cpp_cond_if_match ( dir, lex_if ) ;
-
 
645
	    report ( preproc_loc, err ) ;
-
 
646
	    PUSH_unsigned ( cond, preproc_stack ) ;
-
 
647
	    PUSH_loc ( preproc_loc, loc_stack ) ;
-
 
648
	    IGNORE incr_value ( OPT_VAL_hash_if_depth ) ;
-
 
649
	    preproc_depth++ ;
-
 
650
	    cond = c ;
-
 
651
	}
-
 
652
	crt_cond = ( cond & PP_COND_MASK ) ;
-
 
653
	ret = lex_end_condition ;
-
 
654
 
-
 
655
	if ( dir == lex_endif ) {
-
 
656
	    /* Deal with '#endif' */
-
 
657
	    if ( crt_cond == PP_UNRESOLVED ) {
692
		if (cond == PP_UNRESOLVED) {
658
		ret = lex_hash_Hendif ;
693
			ret = lex_hash_Hif;
659
		cond = PP_TRUE ;
-
 
660
	    } else if ( crt_cond == PP_SKIP ) {
-
 
661
		cond = PP_SKIP ;
-
 
662
	    } else {
-
 
663
		cond = PP_TRUE ;
-
 
664
	    }
-
 
665
	    POP_loc ( loc, loc_stack ) ;
-
 
666
	    UNUSED ( loc ) ;
-
 
667
 
-
 
668
	} else if ( dir == lex_else ) {
-
 
669
	    /* Deal with '#else' */
-
 
670
	    PTR ( LOCATION ) ploc ;
-
 
671
	    ploc = HEAD_list ( LIST_stack ( loc_stack ) ) ;
-
 
672
	    if ( cond & PP_HAVE_ELSE ) {
-
 
673
		/* Duplicate '#else' directives */
-
 
674
		ERROR err = ERR_cpp_cond_else_dup ( dir, dir, ploc ) ;
-
 
675
		report ( preproc_loc, err ) ;
-
 
676
	    }
-
 
677
	    if ( crt_cond == PP_UNRESOLVED ) ret = lex_hash_Helse ;
-
 
678
	    cond = ( negate_cond ( crt_cond ) | PP_HAVE_ELSE ) ;
-
 
679
	    PUSH_unsigned ( cond, preproc_stack ) ;
-
 
680
	    COPY_loc ( ploc, preproc_loc ) ;
-
 
681
	    if ( preproc_depth == 0 ) {
-
 
682
		/* Can't have '#else' in protection macro */
-
 
683
		protection_macro ( NULL_hashid, lex_ignore_token, dir ) ;
-
 
684
	    }
-
 
685
	    IGNORE incr_value ( OPT_VAL_hash_if_depth ) ;
-
 
686
	    preproc_depth++ ;
-
 
687
 
-
 
688
	} else {
-
 
689
	    /* Deal with '#elif' (fairly tricky) */
-
 
690
	    unsigned new_cond ;
-
 
691
	    PTR ( LOCATION ) ploc ;
-
 
692
	    ploc = HEAD_list ( LIST_stack ( loc_stack ) ) ;
-
 
693
	    if ( cond & PP_HAVE_ELSE ) {
-
 
694
		/* '#elif' after '#else' */
-
 
695
		ERROR err = ERR_cpp_cond_else_dup ( dir, lex_else, ploc ) ;
-
 
696
		report ( preproc_loc, err ) ;
-
 
697
	    }
-
 
698
	    if ( crt_cond == PP_TRUE || crt_cond == PP_PAST ) {
-
 
699
		/* A previous '#if' or '#elif' was true */
-
 
700
		ret = lex_ignore_token ;
-
 
701
		IGNORE read_if_exp ( 0, dir ) ;
-
 
702
		c = PP_PAST ;
-
 
703
		new_cond = ( c | PP_HAVE_ELIF ) ;
-
 
704
	    } else if ( crt_cond == PP_FALSE ) {
-
 
705
		/* All previous '#if's and '#elif's were false */
-
 
706
		c = read_if_exp ( 1, dir ) ;
-
 
707
		if ( c == PP_UNRESOLVED ) ret = lex_hash_Hif ;
-
 
708
		new_cond = ( c | PP_HAVE_ELIF ) ;
-
 
709
	    } else if ( crt_cond == PP_UNRESOLVED ) {
-
 
710
		/* Unresolved existing condition */
-
 
711
		c = read_if_exp ( 1, dir ) ;
-
 
712
		if ( c == PP_FALSE ) {
-
 
713
		    /* Overall condition is still unresolved */
-
 
714
		    ret = lex_ignore_token ;
-
 
715
		    new_cond = ( crt_cond | PP_HAVE_ELIF ) ;
-
 
716
		} else if ( c == PP_TRUE ) {
-
 
717
		    /* This terminates the conditional */
-
 
718
		    ret = lex_hash_Hendif ;
-
 
719
		    new_cond = ( c | PP_HAVE_ELIF ) ;
-
 
720
		} else {
-
 
721
		    /* A second unresolved condition */
-
 
722
		    ret = lex_hash_Helif ;
-
 
723
		    new_cond = ( c | PP_HAVE_ELIF ) ;
-
 
724
		}
-
 
725
	    } else {
-
 
726
		/* Skip this directive */
-
 
727
		ret = lex_ignore_token ;
-
 
728
		c = read_if_exp ( 0, dir ) ;
-
 
729
		new_cond = ( c | PP_HAVE_ELIF ) ;
-
 
730
	    }
-
 
731
	    PUSH_unsigned ( new_cond, preproc_stack ) ;
-
 
732
	    COPY_loc ( ploc, preproc_loc ) ;
-
 
733
	    if ( preproc_depth == 0 ) {
-
 
734
		/* Can't have '#elif' in protection macro */
-
 
735
		protection_macro ( NULL_hashid, lex_ignore_token, dir ) ;
-
 
736
	    }
-
 
737
	    IGNORE incr_value ( OPT_VAL_hash_if_depth ) ;
-
 
738
	    preproc_depth++ ;
-
 
739
	    cond = c ;
-
 
740
	}
-
 
741
    }
-
 
742
    ASSERT ( !in_preproc_dir ) ;
-
 
743
 
-
 
744
    /* Step over any unused code */
-
 
745
    cond &= PP_COND_MASK ;
-
 
746
    if ( cond == PP_FALSE || cond == PP_PAST || cond == PP_SKIP ) {
-
 
747
	for ( ; ; ) {
-
 
748
	    int t ;
-
 
749
	    unsigned long sp = skip_white ( 1 ) ;
-
 
750
	    in_preproc_dir = 1 ;
-
 
751
	    t = read_token () ;
-
 
752
	    update_column () ;
-
 
753
	    if ( in_preproc_dir ) preproc_loc = crt_loc ;
-
 
754
	    if ( t == lex_hash_H2 ) t = get_digraph ( t ) ;
-
 
755
	    if ( t == lex_hash_H1 ) {
-
 
756
		/* Scan any nested preprocessing directives */
-
 
757
		int p ;
-
 
758
		unsigned long sp2 = skip_white ( 0 ) ;
-
 
759
		update_column () ;
-
 
760
		p = read_preproc_dir ( 0, lex_ignore_token ) ;
-
 
761
		switch ( p ) {
-
 
762
		    case lex_hash_Hif :
-
 
763
		    case lex_hash_Helif :
-
 
764
		    case lex_hash_Helse :
-
 
765
		    case lex_hash_Hendif :
-
 
766
		    case lex_end_condition : {
-
 
767
			/* These terminate the current condition */
-
 
768
			if ( sp & ( WHITE_SPACE | WHITE_ESC_NEWLINE ) ) {
-
 
769
			    report ( preproc_loc, ERR_cpp_indent () ) ;
-
 
770
			}
-
 
771
			if ( sp2 & ( WHITE_SPACE | WHITE_ESC_NEWLINE ) ) {
-
 
772
			    report ( preproc_loc, ERR_cpp_indent_dir () ) ;
-
 
773
			}
-
 
774
			in_preproc_dir = 0 ;
-
 
775
			return ( p ) ;
-
 
776
		    }
-
 
777
		}
694
		}
-
 
695
		if (prev != lex_included && preproc_depth == 0) {
-
 
696
			/* Can't have second '#if' in protection macro */
-
 
697
			protection_macro(NULL_hashid, lex_ignore_token, dir);
-
 
698
		}
-
 
699
		PUSH_unsigned(cond, preproc_stack);
-
 
700
		PUSH_loc(preproc_loc, loc_stack);
-
 
701
		IGNORE incr_value(OPT_VAL_hash_if_depth);
-
 
702
		preproc_depth++;
-
 
703
 
-
 
704
	} else {
-
 
705
		/* Get current condition for other directives */
-
 
706
		LOCATION loc;
-
 
707
		unsigned crt_cond;
-
 
708
		POP_unsigned(cond, preproc_stack);
-
 
709
		decr_value(OPT_VAL_hash_if_depth);
-
 
710
		preproc_depth--;
-
 
711
		/* Don't pop location yet */
-
 
712
		if (cond == PP_END) {
-
 
713
			/* No matching '#if' */
-
 
714
			ERROR err = ERR_cpp_cond_if_match(dir, lex_if);
-
 
715
			report(preproc_loc, err);
-
 
716
			PUSH_unsigned(cond, preproc_stack);
-
 
717
			PUSH_loc(preproc_loc, loc_stack);
-
 
718
			IGNORE incr_value(OPT_VAL_hash_if_depth);
-
 
719
			preproc_depth++;
-
 
720
			cond = c;
-
 
721
		}
-
 
722
		crt_cond = (cond & PP_COND_MASK);
-
 
723
		ret = lex_end_condition;
-
 
724
 
-
 
725
		if (dir == lex_endif) {
-
 
726
			/* Deal with '#endif' */
-
 
727
			if (crt_cond == PP_UNRESOLVED) {
-
 
728
				ret = lex_hash_Hendif;
-
 
729
				cond = PP_TRUE;
-
 
730
			} else if (crt_cond == PP_SKIP) {
-
 
731
				cond = PP_SKIP;
-
 
732
			} else {
-
 
733
				cond = PP_TRUE;
-
 
734
			}
-
 
735
			POP_loc(loc, loc_stack);
-
 
736
			UNUSED(loc);
-
 
737
 
-
 
738
		} else if (dir == lex_else) {
-
 
739
			/* Deal with '#else' */
-
 
740
			PTR(LOCATION)ploc;
-
 
741
			ploc = HEAD_list(LIST_stack(loc_stack));
-
 
742
			if (cond & PP_HAVE_ELSE) {
-
 
743
				/* Duplicate '#else' directives */
-
 
744
				ERROR err = ERR_cpp_cond_else_dup(dir, dir,
-
 
745
								  ploc);
-
 
746
				report(preproc_loc, err);
-
 
747
			}
-
 
748
			if (crt_cond == PP_UNRESOLVED)ret = lex_hash_Helse;
-
 
749
			cond = (negate_cond(crt_cond) | PP_HAVE_ELSE);
-
 
750
			PUSH_unsigned(cond, preproc_stack);
-
 
751
			COPY_loc(ploc, preproc_loc);
-
 
752
			if (preproc_depth == 0) {
-
 
753
				/* Can't have '#else' in protection macro */
-
 
754
				protection_macro(NULL_hashid, lex_ignore_token,
-
 
755
						 dir);
-
 
756
			}
-
 
757
			IGNORE incr_value(OPT_VAL_hash_if_depth);
-
 
758
			preproc_depth++;
-
 
759
 
-
 
760
		} else {
-
 
761
			/* Deal with '#elif' (fairly tricky) */
-
 
762
			unsigned new_cond;
-
 
763
			PTR(LOCATION)ploc;
-
 
764
			ploc = HEAD_list(LIST_stack(loc_stack));
-
 
765
			if (cond & PP_HAVE_ELSE) {
-
 
766
				/* '#elif' after '#else' */
-
 
767
				ERROR err = ERR_cpp_cond_else_dup(dir, lex_else,
-
 
768
								  ploc);
-
 
769
				report(preproc_loc, err);
-
 
770
			}
-
 
771
			if (crt_cond == PP_TRUE || crt_cond == PP_PAST) {
-
 
772
				/* A previous '#if' or '#elif' was true */
-
 
773
				ret = lex_ignore_token;
-
 
774
				IGNORE read_if_exp(0, dir);
-
 
775
				c = PP_PAST;
-
 
776
				new_cond = (c | PP_HAVE_ELIF);
-
 
777
			} else if (crt_cond == PP_FALSE) {
-
 
778
				/* All previous '#if's and '#elif's were
-
 
779
				 * false */
-
 
780
				c = read_if_exp(1, dir);
-
 
781
				if (c == PP_UNRESOLVED) {
-
 
782
					ret = lex_hash_Hif;
-
 
783
				}
-
 
784
				new_cond = (c | PP_HAVE_ELIF);
-
 
785
			} else if (crt_cond == PP_UNRESOLVED) {
-
 
786
				/* Unresolved existing condition */
-
 
787
				c = read_if_exp(1, dir);
-
 
788
				if (c == PP_FALSE) {
-
 
789
					/* Overall condition is still
-
 
790
					 * unresolved */
-
 
791
					ret = lex_ignore_token;
-
 
792
					new_cond = (crt_cond | PP_HAVE_ELIF);
-
 
793
				} else if (c == PP_TRUE) {
-
 
794
					/* This terminates the conditional */
-
 
795
					ret = lex_hash_Hendif;
-
 
796
					new_cond = (c | PP_HAVE_ELIF);
-
 
797
				} else {
-
 
798
					/* A second unresolved condition */
-
 
799
					ret = lex_hash_Helif;
-
 
800
					new_cond = (c | PP_HAVE_ELIF);
-
 
801
				}
-
 
802
			} else {
-
 
803
				/* Skip this directive */
-
 
804
				ret = lex_ignore_token;
-
 
805
				c = read_if_exp(0, dir);
-
 
806
				new_cond = (c | PP_HAVE_ELIF);
-
 
807
			}
-
 
808
			PUSH_unsigned(new_cond, preproc_stack);
-
 
809
			COPY_loc(ploc, preproc_loc);
-
 
810
			if (preproc_depth == 0) {
-
 
811
				/* Can't have '#elif' in protection macro */
-
 
812
				protection_macro(NULL_hashid, lex_ignore_token,
-
 
813
						 dir);
-
 
814
			}
-
 
815
			IGNORE incr_value(OPT_VAL_hash_if_depth);
-
 
816
			preproc_depth++;
-
 
817
			cond = c;
-
 
818
		}
-
 
819
	}
-
 
820
	ASSERT(!in_preproc_dir);
-
 
821
 
-
 
822
	/* Step over any unused code */
-
 
823
	cond &= PP_COND_MASK;
-
 
824
	if (cond == PP_FALSE || cond == PP_PAST || cond == PP_SKIP) {
-
 
825
		for (;;) {
-
 
826
			int t;
-
 
827
			unsigned long sp = skip_white(1);
-
 
828
			in_preproc_dir = 1;
-
 
829
			t = read_token();
-
 
830
			update_column();
-
 
831
			if (in_preproc_dir) {
-
 
832
				preproc_loc = crt_loc;
-
 
833
			}
-
 
834
			if (t == lex_hash_H2) {
-
 
835
				t = get_digraph(t);
-
 
836
			}
-
 
837
			if (t == lex_hash_H1) {
-
 
838
				/* Scan any nested preprocessing directives */
-
 
839
				int p;
-
 
840
				unsigned long sp2 = skip_white(0);
-
 
841
				update_column();
-
 
842
				p = read_preproc_dir(0, lex_ignore_token);
-
 
843
				switch (p) {
-
 
844
				case lex_hash_Hif:
-
 
845
				case lex_hash_Helif:
-
 
846
				case lex_hash_Helse:
-
 
847
				case lex_hash_Hendif:
-
 
848
				case lex_end_condition: {
-
 
849
					/* These terminate the current
-
 
850
					 * condition */
-
 
851
					if (sp & (WHITE_SPACE |
-
 
852
						  WHITE_ESC_NEWLINE)) {
-
 
853
						report(preproc_loc,
-
 
854
						       ERR_cpp_indent());
-
 
855
					}
-
 
856
					if (sp2 & (WHITE_SPACE |
-
 
857
						   WHITE_ESC_NEWLINE)) {
-
 
858
						report(preproc_loc,
-
 
859
						       ERR_cpp_indent_dir());
-
 
860
					}
-
 
861
					in_preproc_dir = 0;
-
 
862
					return(p);
-
 
863
				}
-
 
864
				}
778
	    } else if ( t == lex_eof ) {
865
			} else if (t == lex_eof) {
779
		if ( sp & ( WHITE_SPACE | WHITE_ESC_NEWLINE ) ) {
866
				if (sp & (WHITE_SPACE | WHITE_ESC_NEWLINE)) {
780
		    report ( crt_loc, ERR_lex_phases_eof () ) ;
867
					report(crt_loc, ERR_lex_phases_eof());
-
 
868
				}
-
 
869
				break;
-
 
870
			} else {
-
 
871
				if (in_preproc_dir)IGNORE skip_to_end();
-
 
872
			}
781
		}
873
		}
782
		break ;
-
 
783
	    } else {
-
 
784
		if ( in_preproc_dir ) IGNORE skip_to_end () ;
-
 
785
	    }
-
 
786
	}
874
	}
787
    }
-
 
788
    in_preproc_dir = 0 ;
875
	in_preproc_dir = 0;
789
    return ( ret ) ;
876
	return(ret);
790
}
877
}
791
 
878
 
792
 
879
 
793
/*
880
/*
794
    PATCH TARGET DEPENDENT CONDITIONALS
881
    PATCH TARGET DEPENDENT CONDITIONALS
Line 797... Line 884...
797
    as if they comprised a compound statement.  In particular any variables
884
    as if they comprised a compound statement.  In particular any variables
798
    declared within the conditional are only in scope inside that condition.
885
    declared within the conditional are only in scope inside that condition.
799
    The neatest way to do this is for the preprocessor to patch the necessary
886
    The neatest way to do this is for the preprocessor to patch the necessary
800
    open and close braces into the parser input.  This is the purpose of
887
    open and close braces into the parser input.  This is the purpose of
801
    this routine.
888
    this routine.
802
*/
889
*/
803
 
890
 
804
int patch_cond
891
int
805
    PROTO_N ( ( t, dir ) )
-
 
806
    PROTO_T ( int t X int dir )
892
patch_cond(int t, int dir)
807
{
893
{
808
    HASHID nm ;
894
	HASHID nm;
809
    PPTOKEN *p ;
895
	PPTOKEN *p;
810
    IDENTIFIER id ;
896
	IDENTIFIER id;
811
 
897
 
812
    /* Compilation action */
898
	/* Compilation action */
813
    if ( !preproc_only ) {
899
	if (!preproc_only) {
814
	switch ( t ) {
900
		switch (t) {
815
	    case lex_hash_Hif : {
901
		case lex_hash_Hif:
816
		/* Create '#if {' */
902
			/* Create '#if {' */
817
		p = patch_tokens ( 1 ) ;
903
			p = patch_tokens(1);
818
		p->tok = lex_open_Hbrace_H1 ;
904
			p->tok = lex_open_Hbrace_H1;
819
		break ;
905
			break;
820
	    }
-
 
821
	    case lex_hash_Helif :
906
		case lex_hash_Helif:
822
	    case lex_hash_Helse : {
907
		case lex_hash_Helse:
823
		/* Create '} #elif {' and '} #else {' */
908
			/* Create '} #elif {' and '} #else {' */
824
		p = patch_tokens ( 2 ) ;
909
			p = patch_tokens(2);
825
		p->tok = t ;
910
			p->tok = t;
826
		token_parts ( t, p ) ;
911
			token_parts(t, p);
827
		p->next->tok = lex_open_Hbrace_H1 ;
912
			p->next->tok = lex_open_Hbrace_H1;
828
		t = lex_close_Hbrace_H1 ;
913
			t = lex_close_Hbrace_H1;
829
		break ;
914
			break;
830
	    }
-
 
831
	    case lex_hash_Hendif : {
915
		case lex_hash_Hendif:
832
		/* Create '} #endif' */
916
			/* Create '} #endif' */
833
		p = patch_tokens ( 1 ) ;
917
			p = patch_tokens(1);
834
		p->tok = t ;
918
			p->tok = t;
835
		t = lex_close_Hbrace_H1 ;
919
			t = lex_close_Hbrace_H1;
836
		break ;
920
			break;
837
	    }
921
		}
-
 
922
		return(t);
-
 
923
	}
-
 
924
 
-
 
925
	/* Preprocessing action */
-
 
926
	id = token_macro;
-
 
927
	if (IS_NULL_id(id)) {
-
 
928
		return(t);
838
	}
929
	}
839
	return ( t ) ;
-
 
840
    }
-
 
841
 
-
 
842
    /* Preprocessing action */
-
 
843
    id = token_macro ;
-
 
844
    if ( IS_NULL_id ( id ) ) return ( t ) ;
-
 
845
    nm = DEREF_hashid ( id_name ( id ) ) ;
930
	nm = DEREF_hashid(id_name(id));
846
    switch ( t ) {
931
	switch (t) {
847
 
932
 
848
	case lex_hash_Hif : {
933
	case lex_hash_Hif:
849
	    if ( dir == lex_ifdef ) {
934
		if (dir == lex_ifdef) {
850
		/* Create '#if defined x' */
935
			/* Create '#if defined x' */
851
		p = patch_tokens ( 2 ) ;
936
			p = patch_tokens(2);
852
		p->tok = lex_identifier ,
937
			p->tok = lex_identifier,
853
		p->pp_data.id.hash = KEYWORD ( lex_defined ) ;
938
			    p->pp_data.id.hash = KEYWORD(lex_defined);
854
		p->next->tok = lex_identifier ,
939
			p->next->tok = lex_identifier,
855
		p->next->pp_data.id.hash = nm ;
940
			    p->next->pp_data.id.hash = nm;
856
		p->next->pp_data.id.use = id ;
941
			p->next->pp_data.id.use = id;
857
	    } else if ( dir == lex_ifndef ) {
942
		} else if (dir == lex_ifndef) {
858
		/* Create '#if !defined x' */
943
			/* Create '#if !defined x' */
859
		p = patch_tokens ( 3 ) ;
944
			p = patch_tokens(3);
860
		p->tok = lex_not_H1 ;
945
			p->tok = lex_not_H1;
861
		p->next->tok = lex_identifier ,
946
			p->next->tok = lex_identifier,
862
		p->next->pp_data.id.hash = KEYWORD ( lex_defined ) ;
947
			    p->next->pp_data.id.hash = KEYWORD(lex_defined);
863
		p->next->pp_space = 0 ;
948
			p->next->pp_space = 0;
864
		p->next->next->tok = lex_identifier ,
949
			p->next->next->tok = lex_identifier,
865
		p->next->next->pp_data.id.hash = nm ;
950
			    p->next->next->pp_data.id.hash = nm;
866
		p->next->next->pp_data.id.use = id ;
951
			p->next->next->pp_data.id.use = id;
867
	    }
-
 
868
	    break ;
-
 
869
	}
-
 
870
 
-
 
871
	case lex_hash_Hop : {
-
 
872
	    /* Create '#define x ...' or '#undef x' */
-
 
873
	    if ( dir == lex_define ) {
-
 
874
		/* Patch in macro definition */
-
 
875
		PPTOKEN *q = NULL ;
-
 
876
		unsigned tag = TAG_id ( id ) ;
-
 
877
		if ( tag == id_obj_macro_tag ) {
-
 
878
		    q = DEREF_pptok ( id_obj_macro_defn ( id ) ) ;
-
 
879
		} else if ( tag == id_func_macro_tag ) {
-
 
880
		    q = DEREF_pptok ( id_func_macro_defn ( id ) ) ;
-
 
881
		}
952
		}
-
 
953
		break;
-
 
954
 
-
 
955
	case lex_hash_Hop:
-
 
956
		/* Create '#define x ...' or '#undef x' */
-
 
957
		if (dir == lex_define) {
-
 
958
			/* Patch in macro definition */
-
 
959
			PPTOKEN *q = NULL;
-
 
960
			unsigned tag = TAG_id(id);
-
 
961
			if (tag == id_obj_macro_tag) {
-
 
962
				q = DEREF_pptok(id_obj_macro_defn(id));
-
 
963
			} else if (tag == id_func_macro_tag) {
-
 
964
				q = DEREF_pptok(id_func_macro_defn(id));
-
 
965
			}
882
		q = expand_tok_list ( q ) ;
966
			q = expand_tok_list(q);
883
		q = clean_tok_list ( q ) ;
967
			q = clean_tok_list(q);
884
		patch_preproc_dir ( q ) ;
968
			patch_preproc_dir(q);
885
		if ( tag == id_func_macro_tag ) {
969
			if (tag == id_func_macro_tag) {
886
		    unsigned n ;
970
				unsigned n;
887
		    LIST ( HASHID ) pars ;
971
				LIST(HASHID)pars;
888
		    pars = DEREF_list ( id_func_macro_params ( id ) ) ;
972
				pars = DEREF_list(id_func_macro_params(id));
889
		    n = DEREF_unsigned ( id_func_macro_no_params ( id ) ) ;
973
				n = DEREF_unsigned(id_func_macro_no_params(id));
890
		    p = patch_tokens ( ( int ) ( 2 * n + 2 ) ) ;
974
				p = patch_tokens((int)(2 * n + 2));
891
		    p->tok = lex_open_Hround ;
975
				p->tok = lex_open_Hround;
892
		    p->pp_space = 0 ;
976
				p->pp_space = 0;
893
		    p->next->tok = lex_close_Hround ;
977
				p->next->tok = lex_close_Hround;
894
		    p->next->pp_space = 0 ;
978
				p->next->pp_space = 0;
895
		    while ( !IS_NULL_list ( pars ) ) {
979
				while (!IS_NULL_list(pars)) {
-
 
980
					HASHID par =
896
			HASHID par = DEREF_hashid ( HEAD_list ( pars ) ) ;
981
					    DEREF_hashid(HEAD_list(pars));
897
			pars = TAIL_list ( pars ) ;
982
					pars = TAIL_list(pars);
898
			p = p->next ;
983
					p = p->next;
899
			p->tok = lex_identifier ;
984
					p->tok = lex_identifier;
900
			p->pp_data.id.hash = par ;
985
					p->pp_data.id.hash = par;
901
			p->pp_space = WHITE_SPACE ;
986
					p->pp_space = WHITE_SPACE;
902
			p = p->next ;
987
					p = p->next;
903
			if ( IS_NULL_list ( pars ) ) {
988
					if (IS_NULL_list(pars)) {
904
			    p->tok = lex_close_Hround ;
989
						p->tok = lex_close_Hround;
905
			    p->pp_space = WHITE_SPACE ;
990
						p->pp_space = WHITE_SPACE;
906
			} else {
991
					} else {
907
			    p->tok = lex_comma ;
992
						p->tok = lex_comma;
908
			    p->pp_space = 0 ;
993
						p->pp_space = 0;
-
 
994
					}
-
 
995
				}
909
			}
996
			}
910
		    }
-
 
911
		}
997
		}
912
	    }
-
 
913
	    p = patch_tokens ( 2 ) ;
998
		p = patch_tokens(2);
914
	    p->tok = lex_identifier ;
999
		p->tok = lex_identifier;
915
	    p->pp_data.id.hash = KEYWORD ( dir ) ;
1000
		p->pp_data.id.hash = KEYWORD(dir);
916
	    p->pp_space = 0 ;
1001
		p->pp_space = 0;
917
	    p->next->tok = lex_identifier ,
1002
		p->next->tok = lex_identifier,
918
	    p->next->pp_data.id.hash = nm ;
1003
		    p->next->pp_data.id.hash = nm;
919
	    p->next->pp_data.id.use = id ;
1004
		p->next->pp_data.id.use = id;
920
	    break ;
1005
		break;
921
	}
1006
	}
922
    }
-
 
923
    return ( t ) ;
1007
	return(t);
924
}
1008
}
925
 
1009
 
926
 
1010
 
927
/*
1011
/*
928
    READ AN INCLUDE DIRECTIVE
1012
    READ AN INCLUDE DIRECTIVE
Line 933... Line 1017...
933
    The name of the preprocessing directive, dir, is passed in for the
1017
    The name of the preprocessing directive, dir, is passed in for the
934
    purposes of error reporting.  The routine returns lex_included to
1018
    purposes of error reporting.  The routine returns lex_included to
935
    indicate that control has passed to the new file.
1019
    indicate that control has passed to the new file.
936
*/
1020
*/
937
 
1021
 
938
int read_include
1022
int
939
    PROTO_N ( ( act, dir ) )
-
 
940
    PROTO_T ( int act X int dir )
1023
read_include(int act, int dir)
941
{
1024
{
942
    int ret = lex_ignore_token ;
1025
	int ret = lex_ignore_token;
943
    if ( act ) {
1026
	if (act) {
944
	string s ;
1027
		string s;
945
	character c ;
1028
		character c;
946
	int end = 0 ;
1029
		int end = 0;
947
	int next = 0 ;
1030
		int next = 0;
948
	int legal = 1 ;
1031
		int legal = 1;
949
	int import = 0 ;
1032
		int import = 0;
950
	character quote = 0 ;
1033
		character quote = 0;
951
 
1034
 
952
	/* Look ahead for start of header name */
1035
		/* Look ahead for start of header name */
953
	if ( dir == lex_import ) import = 1 ;
1036
		if (dir == lex_import) {
-
 
1037
			import = 1;
-
 
1038
		}
954
	if ( dir == lex_include_Hnext ) next = 1 ;
1039
		if (dir == lex_include_Hnext) {
-
 
1040
			next = 1;
-
 
1041
		}
955
	IGNORE skip_white ( 0 ) ;
1042
		IGNORE skip_white(0);
956
	if ( peek_char ( char_less, &legal ) ) {
1043
		if (peek_char(char_less, &legal)) {
957
	    quote = char_greater ;
1044
			quote = char_greater;
958
	} else if ( peek_char ( char_quote, &legal ) ) {
1045
		} else if (peek_char(char_quote, &legal)) {
959
	    quote = char_quote ;
1046
			quote = char_quote;
960
	} else if ( dir == lex_pragma ) {
1047
		} else if (dir == lex_pragma) {
961
	    if ( peek_char ( char_open_square, &legal ) ) {
1048
			if (peek_char(char_open_square, &legal)) {
962
		quote = char_close_square ;
1049
				quote = char_close_square;
963
		next = 1 ;
1050
				next = 1;
964
	    }
1051
			}
965
	}
1052
		}
966
	update_column () ;
1053
		update_column();
967
 
1054
 
968
	if ( quote ) {
1055
		if (quote) {
969
	    /* Read simple header name */
1056
			/* Read simple header name */
970
	    int e = read_string ( ( int ) quote, 0 ) ;
1057
			int e = read_string((int)quote, 0);
971
	    if ( e != lex_eof ) {
1058
			if (e != lex_eof) {
-
 
1059
				if (in_preproc_dir) {
972
		if ( in_preproc_dir ) end = skip_to_end () ;
1060
					end = skip_to_end();
973
	    }
1061
				}
-
 
1062
			}
974
	    s = token_buff.start ;
1063
			s = token_buff.start;
975
	} else {
1064
		} else {
976
	    /* Expand complex header name */
1065
			/* Expand complex header name */
977
	    PPTOKEN *p = read_line ( lex_ignore_token, lex_ignore_token ) ;
1066
			PPTOKEN *p = read_line(lex_ignore_token,
-
 
1067
					       lex_ignore_token);
978
	    PPTOKEN *q = expand_tok_list ( p ) ;
1068
			PPTOKEN *q = expand_tok_list(p);
979
	    IGNORE quote_tok_list ( q, 0, char_quote ) ;
1069
			IGNORE quote_tok_list(q, 0, char_quote);
980
	    s = token_buff.start ;
1070
			s = token_buff.start;
981
 
1071
 
982
	    /* Check first character */
1072
			/* Check first character */
983
	    c = s [0] ;
1073
			c = s[0];
984
	    if ( c == char_less ) {
1074
			if (c == char_less) {
985
		quote = char_greater ;
1075
				quote = char_greater;
986
	    } else if ( c == char_quote ) {
1076
			} else if (c == char_quote) {
987
		quote = char_quote ;
1077
				quote = char_quote;
988
	    } else if ( dir == lex_pragma && c == char_open_square ) {
1078
			} else if (dir == lex_pragma && c == char_open_square) {
989
		quote = char_close_square ;
1079
				quote = char_close_square;
990
		next = 1 ;
1080
				next = 1;
991
	    } else {
1081
			} else {
992
		report ( preproc_loc, ERR_cpp_include_bad () ) ;
1082
				report(preproc_loc, ERR_cpp_include_bad());
993
		act = 0 ;
1083
				act = 0;
994
	    }
1084
			}
995
 
1085
 
996
	    /* Scan header name */
1086
			/* Scan header name */
997
	    if ( quote ) {
1087
			if (quote) {
998
		string t = ++s ;
1088
				string t = ++s;
999
		for ( ; ; ) {
1089
				for (;;) {
1000
		    if ( *t == quote ) {
1090
					if (*t == quote) {
1001
			*t = 0 ;
1091
						*t = 0;
1002
			if ( t + 1 != token_buff.posn ) end = 1 ;
1092
						if (t + 1 != token_buff.posn) {
-
 
1093
							end = 1;
-
 
1094
						}
1003
			break ;
1095
						break;
1004
		    }
1096
					}
1005
		    if ( t == token_buff.posn ) {
1097
					if (t == token_buff.posn) {
1006
			/* End of buffer reached */
1098
						/* End of buffer reached */
-
 
1099
						report(preproc_loc,
1007
			report ( preproc_loc, ERR_cpp_include_incompl () ) ;
1100
						       ERR_cpp_include_incompl());
1008
			break ;
1101
						break;
1009
		    }
1102
					}
1010
		    t++ ;
1103
					t++;
1011
		}
1104
				}
1012
	    }
1105
			}
1013
	    free_tok_list ( p ) ;
1106
			free_tok_list(p);
1014
	    free_tok_list ( q ) ;
1107
			free_tok_list(q);
1015
	}
1108
		}
1016
	if ( end ) report ( preproc_loc, ERR_cpp_end ( dir ) ) ;
-
 
1017
	in_preproc_dir = 0 ;
-
 
1018
	if ( act ) {
1109
		if (end) {
1019
	    /* Check header name */
-
 
1020
	    string t = s ;
-
 
1021
	    while ( c = *( t++ ), c != 0 ) {
-
 
1022
		if ( c == char_quote ||
-
 
1023
		     c == char_single_quote || c == char_backslash ||
-
 
1024
		     ( c == char_slash && *t == char_asterix ) ||
-
 
1025
		     ( c == char_slash && *t == char_slash ) ) {
-
 
1026
		    report ( preproc_loc, ERR_cpp_include_undef ( s ) ) ;
1110
			report(preproc_loc, ERR_cpp_end(dir));
1027
		    break ;
-
 
1028
		}
1111
		}
-
 
1112
		in_preproc_dir = 0;
-
 
1113
		if (act) {
-
 
1114
			/* Check header name */
-
 
1115
			string t = s;
-
 
1116
			while (c = *(t++), c != 0) {
-
 
1117
				if (c == char_quote ||
-
 
1118
				    c == char_single_quote ||
-
 
1119
				    c == char_backslash ||
-
 
1120
				    (c == char_slash && *t == char_asterix) ||
-
 
1121
				    (c == char_slash && *t == char_slash)) {
-
 
1122
					report(preproc_loc,
-
 
1123
					       ERR_cpp_include_undef(s));
-
 
1124
					break;
1029
	    }
1125
				}
-
 
1126
			}
1030
	    if ( start_include ( s, ( int ) quote, import, next ) ) {
1127
			if (start_include(s, (int)quote, import, next)) {
1031
		/* Control passed to new file */
1128
				/* Control passed to new file */
1032
		ret = lex_included ;
1129
				ret = lex_included;
1033
	    }
1130
			}
-
 
1131
		}
-
 
1132
	} else {
-
 
1133
		/* Ignore rest of line */
-
 
1134
		if (in_preproc_dir)IGNORE skip_to_end();
1034
	}
1135
	}
1035
    } else {
-
 
1036
	/* Ignore rest of line */
-
 
1037
	if ( in_preproc_dir ) IGNORE skip_to_end () ;
-
 
1038
    }
-
 
1039
    return ( ret ) ;
1136
	return(ret);
1040
}
1137
}
1041
 
1138
 
1042
 
1139
 
1043
/*
1140
/*
1044
    CHECK THAT TWO PREPROCESSING TOKENS ARE EQUAL
1141
    CHECK THAT TWO PREPROCESSING TOKENS ARE EQUAL
1045
 
1142
 
1046
    This routine checks whether the lists of preprocessing tokens p and q
1143
    This routine checks whether the lists of preprocessing tokens p and q
1047
    are identical.  It returns 2 if they are equal including preceeding
1144
    are identical.  It returns 2 if they are equal including preceeding
1048
    white spaces, 1 if they are otherwise equal, and 0 otherwise.
1145
    white spaces, 1 if they are otherwise equal, and 0 otherwise.
1049
*/
1146
*/
1050
 
1147
 
1051
static int eq_pptok
1148
static int
1052
    PROTO_N ( ( p, q ) )
-
 
1053
    PROTO_T ( PPTOKEN *p X PPTOKEN *q )
1149
eq_pptok(PPTOKEN *p, PPTOKEN *q)
1054
{
1150
{
1055
    int eq = 2 ;
1151
	int eq = 2;
1056
    while ( p && q ) {
1152
	while (p && q) {
1057
	int t1 = p->tok ;
1153
		int t1 = p->tok;
1058
	int t2 = q->tok ;
1154
		int t2 = q->tok;
1059
	if ( t1 != t2 ) return ( 0 ) ;
1155
		if (t1 != t2) {
-
 
1156
			return(0);
-
 
1157
		}
1060
	if ( p->pp_space != q->pp_space ) eq = 1 ;
1158
		if (p->pp_space != q->pp_space) {
-
 
1159
			eq = 1;
-
 
1160
		}
1061
	switch ( t1 ) {
1161
		switch (t1) {
1062
	    case lex_identifier : {
1162
		case lex_identifier: {
1063
		/* Check identifiers */
1163
			/* Check identifiers */
1064
		HASHID n1 = p->pp_data.id.hash ;
1164
			HASHID n1 = p->pp_data.id.hash;
1065
		HASHID n2 = q->pp_data.id.hash ;
1165
			HASHID n2 = q->pp_data.id.hash;
1066
		if ( !EQ_hashid ( n1, n2 ) ) return ( 0 ) ;
1166
			if (!EQ_hashid(n1, n2)) {
-
 
1167
				return(0);
-
 
1168
			}
1067
		break ;
1169
			break;
1068
	    }
1170
		}
1069
	    case lex_integer_Hlit : {
1171
		case lex_integer_Hlit: {
1070
		/* Check integer and floating-point literals */
1172
			/* Check integer and floating-point literals */
1071
		string s1 = p->pp_data.text ;
1173
			string s1 = p->pp_data.text;
1072
		string s2 = q->pp_data.text ;
1174
			string s2 = q->pp_data.text;
1073
		if ( !ustreq ( s1, s2 ) ) return ( 0 ) ;
1175
			if (!ustreq(s1, s2)) {
-
 
1176
				return(0);
-
 
1177
			}
1074
		break ;
1178
			break;
1075
	    }
1179
		}
1076
	    case lex_char_Hlit :
1180
		case lex_char_Hlit:
1077
	    case lex_string_Hlit :
1181
		case lex_string_Hlit:
1078
	    case lex_wchar_Hlit :
1182
		case lex_wchar_Hlit:
1079
	    case lex_wstring_Hlit : {
1183
		case lex_wstring_Hlit: {
1080
		/* Check string and characters literals */
1184
			/* Check string and characters literals */
1081
		string s1 = p->pp_data.str.start ;
1185
			string s1 = p->pp_data.str.start;
1082
		string s2 = q->pp_data.str.start ;
1186
			string s2 = q->pp_data.str.start;
1083
		gen_size n1 = ( gen_size ) ( p->pp_data.str.end - s1 ) ;
1187
			gen_size n1 = (gen_size)(p->pp_data.str.end - s1);
1084
		gen_size n2 = ( gen_size ) ( q->pp_data.str.end - s2 ) ;
1188
			gen_size n2 = (gen_size)(q->pp_data.str.end - s2);
1085
		if ( n1 != n2 ) return ( 0 ) ;
1189
			if (n1 != n2) {
-
 
1190
				return(0);
-
 
1191
			}
1086
		if ( xumemcmp ( s1, s2, n1 ) != 0 ) return ( 0 ) ;
1192
			if (xumemcmp(s1, s2, n1)!= 0) {
-
 
1193
				return(0);
-
 
1194
			}
1087
		break ;
1195
			break;
1088
	    }
1196
		}
1089
	    case lex_unknown : {
1197
		case lex_unknown: {
1090
		/* Check unknown characters */
1198
			/* Check unknown characters */
1091
		string s1 = p->pp_data.buff ;
1199
			string s1 = p->pp_data.buff;
1092
		string s2 = q->pp_data.buff ;
1200
			string s2 = q->pp_data.buff;
1093
		gen_size n1 = MULTI_WIDTH ;
1201
			gen_size n1 = MULTI_WIDTH;
1094
		if ( xumemcmp ( s1, s2, n1 ) != 0 ) return ( 0 ) ;
1202
			if (xumemcmp(s1, s2, n1)!= 0) {
-
 
1203
				return(0);
-
 
1204
			}
1095
		break ;
1205
			break;
1096
	    }
1206
		}
1097
	    case lex_macro_Harg : {
1207
		case lex_macro_Harg: {
1098
		/* Check macro parameter applications */
1208
			/* Check macro parameter applications */
1099
		unsigned long m1 = p->pp_data.par.no ;
1209
			unsigned long m1 = p->pp_data.par.no;
1100
		unsigned long m2 = q->pp_data.par.no ;
1210
			unsigned long m2 = q->pp_data.par.no;
1101
		if ( m1 != m2 ) return ( 0 ) ;
1211
			if (m1 != m2) {
-
 
1212
				return(0);
-
 
1213
			}
1102
		break ;
1214
			break;
1103
	    }
1215
		}
1104
	}
1216
		}
1105
	p = p->next ;
1217
		p = p->next;
1106
	q = q->next ;
1218
		q = q->next;
1107
    }
1219
	}
1108
    if ( p || q ) return ( 0 ) ;
1220
	if (p || q) {
-
 
1221
		return(0);
-
 
1222
	}
1109
    return ( eq ) ;
1223
	return(eq);
1110
}
1224
}
1111
 
1225
 
1112
 
1226
 
1113
/*
1227
/*
1114
    CHECK CONSISTENCY OF TWO MACRO DEFINITIONS
1228
    CHECK CONSISTENCY OF TWO MACRO DEFINITIONS
1115
 
1229
 
1116
    This routine checks that a definition of the macro given by id_new is
1230
    This routine checks that a definition of the macro given by id_new is
1117
    consistent with the previous definition, id_old.  It returns an error
1231
    consistent with the previous definition, id_old.  It returns an error
1118
    message reporting on the level of consistency.
1232
    message reporting on the level of consistency.
1119
*/
1233
*/
1120
 
1234
 
1121
static ERROR check_macro_redef
1235
static ERROR
1122
    PROTO_N ( ( id_new, id_old ) )
-
 
1123
    PROTO_T ( IDENTIFIER id_new X IDENTIFIER id_old )
1236
check_macro_redef(IDENTIFIER id_new, IDENTIFIER id_old)
1124
{
1237
{
1125
    int defn_ok ;
1238
	int defn_ok;
1126
    int pars_ok = 1 ;
1239
	int pars_ok = 1;
1127
    ERROR err = NULL_err ;
1240
	ERROR err = NULL_err;
1128
    PTR ( LOCATION ) loc_old ;
1241
	PTR(LOCATION)loc_old;
1129
    PPTOKEN *defn_new, *defn_old ;
1242
	PPTOKEN *defn_new, *defn_old;
1130
    unsigned tag_new = TAG_id ( id_new ) ;
1243
	unsigned tag_new = TAG_id(id_new);
1131
    unsigned tag_old = TAG_id ( id_old ) ;
1244
	unsigned tag_old = TAG_id(id_old);
1132
    DECL_SPEC ds_old = DEREF_dspec ( id_storage ( id_old ) ) ;
1245
	DECL_SPEC ds_old = DEREF_dspec(id_storage(id_old));
1133
 
1246
 
1134
    /* Check on old macro definition */
1247
	/* Check on old macro definition */
1135
    loc_old = id_loc ( id_old ) ;
1248
	loc_old = id_loc(id_old);
1136
    if ( ( ds_old & dspec_builtin ) && crt_file_type == 0 ) {
1249
	if ((ds_old & dspec_builtin) && crt_file_type == 0) {
1137
	/* Built-in macro redefined */
1250
		/* Built-in macro redefined */
1138
	err = ERR_cpp_predef_redef ( id_old ) ;
1251
		err = ERR_cpp_predef_redef(id_old);
1139
    }
1252
	}
1140
 
1253
 
1141
    /* Macro types must agree */
1254
	/* Macro types must agree */
1142
    if ( tag_new != tag_old ) {
1255
	if (tag_new != tag_old) {
1143
	ERROR e = ERR_cpp_replace_redef_bad ( id_old, loc_old ) ;
1256
		ERROR e = ERR_cpp_replace_redef_bad(id_old, loc_old);
1144
	err = concat_error ( err, e ) ;
1257
		err = concat_error(err, e);
1145
	return ( err ) ;
1258
		return(err);
1146
    }
1259
	}
1147
 
1260
 
1148
    if ( tag_new == id_obj_macro_tag ) {
1261
	if (tag_new == id_obj_macro_tag) {
1149
	/* Find the definitions for object-like macros */
1262
		/* Find the definitions for object-like macros */
1150
	defn_new = DEREF_pptok ( id_obj_macro_defn ( id_new ) ) ;
1263
		defn_new = DEREF_pptok(id_obj_macro_defn(id_new));
1151
	defn_old = DEREF_pptok ( id_obj_macro_defn ( id_old ) ) ;
1264
		defn_old = DEREF_pptok(id_obj_macro_defn(id_old));
1152
 
1265
 
1153
    } else {
1266
	} else {
1154
	/* Check parameter lists for function-like macros */
1267
		/* Check parameter lists for function-like macros */
1155
	unsigned no_pars_new, no_pars_old ;
1268
		unsigned no_pars_new, no_pars_old;
1156
	LIST ( HASHID ) pars_new, pars_old ;
1269
		LIST(HASHID)pars_new, pars_old;
1157
	pars_new = DEREF_list ( id_func_macro_params ( id_new ) ) ;
1270
		pars_new = DEREF_list(id_func_macro_params(id_new));
1158
	pars_old = DEREF_list ( id_func_macro_params ( id_old ) ) ;
1271
		pars_old = DEREF_list(id_func_macro_params(id_old));
1159
	no_pars_new = DEREF_unsigned ( id_func_macro_no_params ( id_new ) ) ;
1272
		no_pars_new = DEREF_unsigned(id_func_macro_no_params(id_new));
1160
	no_pars_old = DEREF_unsigned ( id_func_macro_no_params ( id_old ) ) ;
1273
		no_pars_old = DEREF_unsigned(id_func_macro_no_params(id_old));
1161
 
1274
 
1162
	if ( no_pars_new != no_pars_old ) {
1275
		if (no_pars_new != no_pars_old) {
1163
	    /* Number of parameters must match */
1276
			/* Number of parameters must match */
1164
	    ERROR e = ERR_cpp_replace_redef_bad ( id_old, loc_old ) ;
1277
			ERROR e = ERR_cpp_replace_redef_bad(id_old, loc_old);
1165
	    err = concat_error ( err, e ) ;
1278
			err = concat_error(err, e);
1166
	    return ( err ) ;
1279
			return(err);
1167
	}
1280
		}
1168
 
1281
 
1169
	while ( !IS_NULL_list ( pars_new ) ) {
1282
		while (!IS_NULL_list(pars_new)) {
1170
	    /* Check that parameter names match */
1283
			/* Check that parameter names match */
1171
	    HASHID p_new = DEREF_hashid ( HEAD_list ( pars_new ) ) ;
1284
			HASHID p_new = DEREF_hashid(HEAD_list(pars_new));
1172
	    HASHID p_old = DEREF_hashid ( HEAD_list ( pars_old ) ) ;
1285
			HASHID p_old = DEREF_hashid(HEAD_list(pars_old));
1173
	    if ( !EQ_hashid ( p_new, p_old ) ) {
1286
			if (!EQ_hashid(p_new, p_old)) {
1174
		/* Just clear pars_ok if they don't */
1287
				/* Just clear pars_ok if they don't */
1175
		pars_ok = 0 ;
1288
				pars_ok = 0;
1176
		break ;
1289
				break;
1177
	    }
1290
			}
1178
	    pars_new = TAIL_list ( pars_new ) ;
1291
			pars_new = TAIL_list(pars_new);
1179
	    pars_old = TAIL_list ( pars_old ) ;
1292
			pars_old = TAIL_list(pars_old);
1180
	}
1293
		}
1181
 
1294
 
1182
	/* Find the definitions for function-like macros */
1295
		/* Find the definitions for function-like macros */
1183
	defn_new = DEREF_pptok ( id_func_macro_defn ( id_new ) ) ;
1296
		defn_new = DEREF_pptok(id_func_macro_defn(id_new));
1184
	defn_old = DEREF_pptok ( id_func_macro_defn ( id_old ) ) ;
1297
		defn_old = DEREF_pptok(id_func_macro_defn(id_old));
1185
    }
1298
	}
1186
 
1299
 
1187
    /* Check that the definitions match */
1300
	/* Check that the definitions match */
1188
    defn_ok = eq_pptok ( defn_new, defn_old ) ;
1301
	defn_ok = eq_pptok(defn_new, defn_old);
1189
    if ( defn_ok == 0 ) {
1302
	if (defn_ok == 0) {
1190
	/* Inconsistent redefinition */
1303
		/* Inconsistent redefinition */
1191
	ERROR e = ERR_cpp_replace_redef_bad ( id_old, loc_old ) ;
1304
		ERROR e = ERR_cpp_replace_redef_bad(id_old, loc_old);
1192
	err = concat_error ( err, e ) ;
1305
		err = concat_error(err, e);
1193
	return ( err ) ;
1306
		return(err);
1194
    } else if ( defn_ok == 1 ) {
1307
	} else if (defn_ok == 1) {
1195
	/* Consistent redefinition up to white space */
1308
		/* Consistent redefinition up to white space */
1196
	ERROR e = ERR_cpp_replace_redef_space ( id_old, loc_old ) ;
1309
		ERROR e = ERR_cpp_replace_redef_space(id_old, loc_old);
1197
	e = set_severity ( e, OPT_macro_redef, -1 ) ;
1310
		e = set_severity(e, OPT_macro_redef, -1);
1198
	err = concat_error ( err, e ) ;
1311
		err = concat_error(err, e);
1199
    }
1312
	}
1200
 
1313
 
1201
    /* Prepare final error */
1314
	/* Prepare final error */
1202
    if ( pars_ok ) {
1315
	if (pars_ok) {
1203
	/* Consistent macro redefinition */
1316
		/* Consistent macro redefinition */
1204
	if ( IS_NULL_err ( err ) ) {
1317
		if (IS_NULL_err(err)) {
1205
	    err = ERR_cpp_replace_redef_ok ( id_old, loc_old ) ;
1318
			err = ERR_cpp_replace_redef_ok(id_old, loc_old);
-
 
1319
		}
-
 
1320
	} else {
-
 
1321
		/* Consistent redefinition up to parameter names */
-
 
1322
		ERROR e = ERR_cpp_replace_redef_weak(id_old, loc_old);
-
 
1323
		e = set_severity(e, OPT_macro_redef, -1);
-
 
1324
		err = concat_error(err, e);
1206
	}
1325
	}
1207
    } else {
-
 
1208
	/* Consistent redefinition up to parameter names */
-
 
1209
	ERROR e = ERR_cpp_replace_redef_weak ( id_old, loc_old ) ;
-
 
1210
	e = set_severity ( e, OPT_macro_redef, -1 ) ;
-
 
1211
	err = concat_error ( err, e ) ;
-
 
1212
    }
-
 
1213
    return ( err ) ;
1326
	return(err);
1214
}
1327
}
1215
 
1328
 
1216
 
1329
 
1217
/*
1330
/*
1218
    FREE A MACRO DEFINITION
1331
    FREE A MACRO DEFINITION
1219
 
1332
 
1220
    This routine frees the macro definition given by the identifier id.
1333
    This routine frees the macro definition given by the identifier id.
1221
    It returns the previous definition of id.
1334
    It returns the previous definition of id.
1222
*/
1335
*/
1223
 
1336
 
1224
static IDENTIFIER free_macro_defn
1337
static IDENTIFIER
1225
    PROTO_N ( ( id ) )
-
 
1226
    PROTO_T ( IDENTIFIER id )
1338
free_macro_defn(IDENTIFIER id)
1227
{
1339
{
1228
    PPTOKEN *defn ;
1340
	PPTOKEN *defn;
1229
    IDENTIFIER prev = DEREF_id ( id_alias ( id ) ) ;
1341
	IDENTIFIER prev = DEREF_id(id_alias(id));
1230
    if ( IS_id_obj_macro ( id ) ) {
1342
	if (IS_id_obj_macro(id)) {
1231
	defn = DEREF_pptok ( id_obj_macro_defn ( id ) ) ;
1343
		defn = DEREF_pptok(id_obj_macro_defn(id));
1232
	COPY_pptok ( id_obj_macro_defn ( id ), NULL ) ;
1344
		COPY_pptok(id_obj_macro_defn(id), NULL);
1233
    } else {
1345
	} else {
1234
	defn = DEREF_pptok ( id_func_macro_defn ( id ) ) ;
1346
		defn = DEREF_pptok(id_func_macro_defn(id));
1235
	COPY_pptok ( id_func_macro_defn ( id ), NULL ) ;
1347
		COPY_pptok(id_func_macro_defn(id), NULL);
1236
    }
1348
	}
1237
    free_tok_list ( defn ) ;
1349
	free_tok_list(defn);
1238
    return ( prev ) ;
1350
	return(prev);
1239
}
1351
}
1240
 
1352
 
1241
 
1353
 
1242
/*
1354
/*
1243
    READ A DEFINE DIRECTIVE
1355
    READ A DEFINE DIRECTIVE
1244
 
1356
 
1245
    This routine processes a '#define' directive.  This consists of a macro
1357
    This routine processes a '#define' directive.  This consists of a macro
1246
    identifier, and optional list of macro parameters, and a list of token
1358
    identifier, and optional list of macro parameters, and a list of token
1247
    comprising the macro definition.  Note that the list of parameters is
1359
    comprising the macro definition.  Note that the list of parameters is
1248
    built up in the reverse order to that in which they appear in the file
1360
    built up in the reverse order to that in which they appear in the file
1249
    (also see read_macro_args).  The routine returns true if the directive
1361
    (also see read_macro_args).  The routine returns true if the directive
1250
    is a macro definition.
1362
    is a macro definition.
1251
*/
1363
*/
1252
 
1364
 
1253
static int read_define
1365
static int
1254
    PROTO_Z ()
-
 
1255
{
-
 
1256
    HASHID macro ;
-
 
1257
    PPTOKEN *defn ;
-
 
1258
    int legal = 1 ;
-
 
1259
    IDENTIFIER id ;
-
 
1260
    IDENTIFIER tok ;
-
 
1261
    IDENTIFIER prev ;
-
 
1262
    unsigned prev_def ;
-
 
1263
    unsigned npars = 0 ;
-
 
1264
    int object_like = 0 ;
-
 
1265
    int ret = lex_ignore_token ;
-
 
1266
    int first_tok = lex_ignore_token ;
-
 
1267
    LIST ( HASHID ) pars = NULL_list ( HASHID ) ;
-
 
1268
    OPTION preproc_strings = option ( OPT_preproc_old ) ;
-
 
1269
 
-
 
1270
    /* Read the macro identifier */
-
 
1271
    int t = read_token () ;
-
 
1272
    update_column () ;
-
 
1273
    if ( in_preproc_dir ) preproc_loc = crt_loc ;
-
 
1274
    if ( t != lex_identifier ) {
-
 
1275
	report ( preproc_loc, ERR_cpp_replace_id ( lex_define ) ) ;
-
 
1276
	return ( ret ) ;
-
 
1277
    }
-
 
1278
    macro = token_hashid ;
-
 
1279
    if ( EQ_KEYWORD ( macro, lex_defined ) ) {
-
 
1280
	/* Cannot define defined as a macro */
-
 
1281
	report ( preproc_loc, ERR_cpp_predef_bad ( macro, lex_define ) ) ;
-
 
1282
    } else {
-
 
1283
	id = DEREF_id ( hashid_id ( macro ) ) ;
-
 
1284
	if ( IS_id_keyword ( id ) && !preproc_only ) {
-
 
1285
	    /* Warn about redefining keywords */
-
 
1286
	    report ( preproc_loc, ERR_cpp_predef_keyword ( macro ) ) ;
-
 
1287
	}
-
 
1288
    }
-
 
1289
    prev_def = check_macro ( macro, 0 ) ;
-
 
1290
    tok = token_macro ;
-
 
1291
 
-
 
1292
    /* Check for macro parameters */
-
 
1293
    if ( peek_char ( char_open_round, &legal ) ) {
-
 
1294
	PPTOKEN *p ;
-
 
1295
	int err = 0 ;
-
 
1296
	int par_next = 2 ;
-
 
1297
	LIST ( HASHID ) lp ;
-
 
1298
	unsigned long par_no = 1 ;
-
 
1299
 
-
 
1300
	/* Scan through definition looking for parameters */
-
 
1301
	update_column () ;
-
 
1302
	if ( in_preproc_dir ) preproc_loc = crt_loc ;
-
 
1303
	while ( t = read_token (), t != lex_close_Hround ) {
-
 
1304
	    update_column () ;
-
 
1305
	    if ( in_preproc_dir ) preproc_loc = crt_loc ;
-
 
1306
	    if ( t == lex_identifier ) {
-
 
1307
		/* Identifiers are parameter names */
-
 
1308
		unsigned long mark ;
-
 
1309
		HASHID par = token_hashid ;
-
 
1310
		IGNORE check_macro ( par, 0 ) ;
-
 
1311
		CONS_hashid ( par, pars, pars ) ;
-
 
1312
 
-
 
1313
		/* Mark name with parameter number */
-
 
1314
		mark = DEREF_ulong ( hashid_hash ( par ) ) ;
-
 
1315
		if ( mark >= HASH_SIZE ) {
-
 
1316
		    /* Parameter already marked */
-
 
1317
		    ERROR e = ERR_cpp_replace_par_dup ( par, macro ) ;
-
 
1318
		    report ( preproc_loc, e ) ;
-
 
1319
		    mark %= HASH_SIZE ;
-
 
1320
		}
-
 
1321
		mark += HASH_SIZE * par_no ;
-
 
1322
		COPY_ulong ( hashid_hash ( par ), mark ) ;
-
 
1323
		if ( !par_next ) err = 1 ;
-
 
1324
		par_next = 0 ;
-
 
1325
		par_no++ ;
-
 
1326
	    } else if ( t == lex_comma ) {
-
 
1327
		/* Commas separate parameters */
-
 
1328
		if ( par_next ) err = 1 ;
-
 
1329
		par_next = 1 ;
-
 
1330
	    } else {
-
 
1331
		/* Anything else is an error */
-
 
1332
		first_tok = t ;
-
 
1333
		err = 1 ;
-
 
1334
		break ;
-
 
1335
	    }
-
 
1336
	}
-
 
1337
	update_column () ;
-
 
1338
	if ( in_preproc_dir ) preproc_loc = crt_loc ;
-
 
1339
	if ( err || par_next == 1 ) {
-
 
1340
	    /* Report any errors */
-
 
1341
	    report ( preproc_loc, ERR_cpp_replace_par_bad ( macro ) ) ;
-
 
1342
	}
-
 
1343
 
-
 
1344
	/* Allow for parameter expansion in strings */
-
 
1345
	if ( preproc_strings ) {
-
 
1346
	    /* This causes strings not to be recognised */
-
 
1347
	    set_char_lookup ( char_quote, char_illegal ) ;
-
 
1348
	    set_char_lookup ( char_single_quote, char_illegal ) ;
-
 
1349
	}
-
 
1350
 
-
 
1351
	/* Read the macro definition for function-like macros */
-
 
1352
	defn = read_line ( first_tok, lex_ignore_token ) ;
-
 
1353
	if ( defn ) defn->pp_space = WHITE_SPACE ;
-
 
1354
 
-
 
1355
	/* Restore string terminators */
-
 
1356
	if ( preproc_strings ) {
-
 
1357
	    set_char_lookup ( char_quote, char_quote ) ;
-
 
1358
	    set_char_lookup ( char_single_quote, char_single_quote ) ;
-
 
1359
	}
-
 
1360
 
-
 
1361
	/* Mark the macro parameters in the definition */
-
 
1362
	for ( p = defn ; p != NULL ; p = p->next ) {
-
 
1363
	    int tk = p->tok ;
-
 
1364
	    if ( tk == lex_identifier ) {
-
 
1365
		HASHID par = p->pp_data.id.hash ;
-
 
1366
		unsigned long mark = DEREF_ulong ( hashid_hash ( par ) ) ;
-
 
1367
		if ( mark >= HASH_SIZE ) {
-
 
1368
		    /* Parameters are identified by the parameter number */
-
 
1369
		    p->tok = lex_macro_Harg ;
-
 
1370
		    p->pp_data.par.hash = par ;
-
 
1371
		    p->pp_data.par.no = ( mark / HASH_SIZE ) ;
-
 
1372
		}
-
 
1373
	    }
-
 
1374
	}
-
 
1375
 
-
 
1376
	/* Check for quoted parameters */
-
 
1377
	if ( preproc_strings ) {
-
 
1378
	    defn = recognise_strings ( defn, macro, 0 ) ;
-
 
1379
	}
-
 
1380
 
-
 
1381
	/* Check for '#' operators */
-
 
1382
	for ( p = defn ; p != NULL ; p = p->next ) {
-
 
1383
	    int tk = p->tok ;
-
 
1384
	    if ( tk == lex_hash_H2 ) tk = get_digraph ( tk ) ;
-
 
1385
	    if ( tk == lex_hash_H1 ) {
-
 
1386
		/* '#' should be followed by a parameter */
-
 
1387
		if ( p->next == NULL || p->next->tok != lex_macro_Harg ) {
-
 
1388
		    report ( preproc_loc, ERR_cpp_stringize_par ( macro ) ) ;
-
 
1389
		} else {
-
 
1390
		    p->tok = lex_hash_Hop ;
-
 
1391
		}
-
 
1392
	    }
-
 
1393
	}
-
 
1394
 
-
 
1395
	/* Clear the parameter marks */
-
 
1396
	for ( lp = pars ; !IS_NULL_list ( lp ) ; lp = TAIL_list ( lp ) ) {
-
 
1397
	    HASHID par = DEREF_hashid ( HEAD_list ( lp ) ) ;
-
 
1398
	    unsigned long mark = DEREF_ulong ( hashid_hash ( par ) ) ;
-
 
1399
	    mark %= HASH_SIZE ;
-
 
1400
	    COPY_ulong ( hashid_hash ( par ), mark ) ;
-
 
1401
	    npars++ ;
-
 
1402
	}
-
 
1403
	pars = REVERSE_list ( pars ) ;
-
 
1404
 
-
 
1405
    } else {
-
 
1406
	/* Read the macro definition for object-like macros */
-
 
1407
	if ( !legal ) report ( preproc_loc, ERR_cpp_space_replace () ) ;
-
 
1408
	defn = read_line ( first_tok, lex_ignore_token ) ;
-
 
1409
	object_like = 1 ;
-
 
1410
    }
-
 
1411
 
-
 
1412
    /* Check for '##' operators */
-
 
1413
    if ( defn ) {
-
 
1414
	PPTOKEN *p ;
-
 
1415
	int tk = defn->tok ;
-
 
1416
	if ( tk == lex_hash_Hhash_H2 ) tk = get_digraph ( tk ) ;
-
 
1417
	if ( tk == lex_hash_Hhash_H1 ) {
-
 
1418
	    /* Definition can't start with '##' */
-
 
1419
	    report ( preproc_loc, ERR_cpp_concat_place ( macro ) ) ;
-
 
1420
	}
-
 
1421
	for ( p = defn->next ; p != NULL ; p = p->next ) {
-
 
1422
	    tk = p->tok ;
-
 
1423
	    if ( tk == lex_hash_Hhash_H2 ) tk = get_digraph ( tk ) ;
-
 
1424
	    if ( tk == lex_hash_Hhash_H1 ) {
-
 
1425
		if ( p->next == NULL ) {
-
 
1426
		    /* Definition can't end with '##' */
-
 
1427
		    report ( preproc_loc, ERR_cpp_concat_place ( macro ) ) ;
-
 
1428
		} else {
-
 
1429
		    p->tok = lex_hash_Hhash_Hop ;
-
 
1430
		}
-
 
1431
	    }
-
 
1432
	}
-
 
1433
    }
-
 
1434
 
-
 
1435
    /* Define the macro */
-
 
1436
    if ( !IS_NULL_exp ( crt_hash_cond ) ) {
-
 
1437
	report ( preproc_loc, ERR_cpp_cond_if_macro ( macro ) ) ;
-
 
1438
    }
-
 
1439
    prev = DEREF_id ( hashid_id ( macro ) ) ;
-
 
1440
    if ( object_like ) {
-
 
1441
	MAKE_id_obj_macro ( macro, dspec_defn, NULL_nspace, preproc_loc,
-
 
1442
			    defn, id ) ;
1366
read_define(void)
1443
    } else {
-
 
1444
	IGNORE check_value ( OPT_VAL_macro_pars, ( ulong ) npars ) ;
-
 
1445
	MAKE_id_func_macro ( macro, dspec_defn, NULL_nspace, preproc_loc,
-
 
1446
			     defn, pars, npars, id ) ;
-
 
1447
    }
-
 
1448
    COPY_id ( id_alias ( id ), prev ) ;
-
 
1449
    if ( prev_def & PP_TOKEN ) {
-
 
1450
	/* Allow for token definitions */
-
 
1451
	prev_def &= PP_COND_MASK ;
-
 
1452
	if ( prev_def == PP_UNRESOLVED ) {
-
 
1453
	    /* Can only happen when preprocessing */
-
 
1454
	    token_macro = id ;
-
 
1455
	    ret = lex_hash_Hop ;
-
 
1456
	} else {
-
 
1457
	    int tokdef ;
-
 
1458
	    DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
-
 
1459
	    COPY_dspec ( id_storage ( id ), ( ds | dspec_temp ) ) ;
-
 
1460
	    tokdef = define_token_macro ( tok, id ) ;
-
 
1461
	    COPY_dspec ( id_storage ( id ), ds ) ;
-
 
1462
	    if ( tokdef ) {
-
 
1463
		IGNORE free_macro_defn ( id ) ;
-
 
1464
		no_declarations++ ;
-
 
1465
		return ( ret ) ;
-
 
1466
	    }
-
 
1467
	    prev_def = PP_FALSE ;
-
 
1468
	}
-
 
1469
    }
-
 
1470
    COPY_id ( hashid_id ( macro ), id ) ;
-
 
1471
    if ( do_macro ) {
-
 
1472
	/* Dump macro definition using current namespace */
-
 
1473
	COPY_nspace ( id_parent ( id ), crt_namespace ) ;
-
 
1474
	dump_declare ( id, &preproc_loc, 1 ) ;
-
 
1475
	COPY_nspace ( id_parent ( id ), NULL_nspace ) ;
-
 
1476
    }
-
 
1477
 
-
 
1478
    /* Check consistency of previous definition */
-
 
1479
    if ( prev_def == PP_TRUE ) {
-
 
1480
	ERROR err ;
-
 
1481
	if ( option ( OPT_macro_nest ) == OPTION_DISALLOW ) {
-
 
1482
	    err = check_macro_redef ( id, prev ) ;
-
 
1483
	    prev = free_macro_defn ( prev ) ;
-
 
1484
	} else {
-
 
1485
	    PTR ( LOCATION ) loc = id_loc ( prev ) ;
-
 
1486
	    err = ERR_cpp_replace_redef_nest ( prev, loc ) ;
-
 
1487
	}
-
 
1488
	if ( !IS_NULL_err ( err ) ) report ( preproc_loc, err ) ;
-
 
1489
	COPY_id ( id_alias ( id ), prev ) ;
-
 
1490
    } else {
-
 
1491
	IGNORE incr_value ( OPT_VAL_macro_ids ) ;
-
 
1492
    }
-
 
1493
    return ( ret ) ;
-
 
1494
}
-
 
1495
 
-
 
1496
 
-
 
1497
/*
-
 
1498
    READ AN UNDEFINE DIRECTIVE
-
 
1499
 
-
 
1500
    This routine processes a '#undef' directive.  This just consists of a
-
 
1501
    macro identifier.  The routine returns true if the macro represents
-
 
1502
    a token.
-
 
1503
*/
-
 
1504
 
-
 
1505
static int read_undef
-
 
1506
    PROTO_Z ()
-
 
1507
{
1367
{
1508
    /* Read the macro identifier */
1368
	HASHID macro;
1509
    unsigned def ;
1369
	PPTOKEN *defn;
1510
    HASHID macro ;
1370
	int legal = 1;
1511
    int ret = lex_ignore_token ;
1371
	IDENTIFIER id;
1512
    int t = read_token () ;
1372
	IDENTIFIER tok;
1513
    update_column () ;
1373
	IDENTIFIER prev;
1514
    if ( in_preproc_dir ) preproc_loc = crt_loc ;
-
 
1515
    if ( t != lex_identifier ) {
1374
	unsigned prev_def;
1516
	report ( preproc_loc, ERR_cpp_scope_id ( lex_undef ) ) ;
-
 
1517
	return ( ret ) ;
1375
	unsigned npars = 0;
1518
    }
1376
	int object_like = 0;
1519
    macro = token_hashid ;
1377
	int ret = lex_ignore_token;
1520
    if ( EQ_KEYWORD ( macro, lex_defined ) ) {
1378
	int first_tok = lex_ignore_token;
1521
	/* Cannot undefine defined */
1379
	LIST(HASHID)pars = NULL_list(HASHID);
1522
	report ( preproc_loc, ERR_cpp_predef_bad ( macro, lex_undef ) ) ;
1380
	OPTION preproc_strings = option(OPT_preproc_old);
1523
    }
-
 
1524
 
1381
 
1525
    /* Undefine the macro if necessary */
1382
	/* Read the macro identifier */
1526
    def = check_macro ( macro, 0 ) ;
1383
	int t = read_token();
1527
    if ( def == PP_TRUE ) {
1384
	update_column();
1528
	/* Previously defined as macro */
1385
	if (in_preproc_dir) {
1529
	IDENTIFIER prev = DEREF_id ( hashid_id ( macro ) ) ;
-
 
1530
	DECL_SPEC ds = DEREF_dspec ( id_storage ( prev ) ) ;
-
 
1531
	if ( ( ds & dspec_builtin ) && crt_file_type == 0 ) {
-
 
1532
	    report ( preproc_loc, ERR_cpp_predef_undef ( prev ) ) ;
1386
		preproc_loc = crt_loc;
1533
	}
1387
	}
-
 
1388
	if (t != lex_identifier) {
-
 
1389
		report(preproc_loc, ERR_cpp_replace_id(lex_define));
-
 
1390
		return(ret);
-
 
1391
	}
-
 
1392
	macro = token_hashid;
-
 
1393
	if (EQ_KEYWORD(macro, lex_defined)) {
-
 
1394
		/* Cannot define defined as a macro */
-
 
1395
		report(preproc_loc, ERR_cpp_predef_bad(macro, lex_define));
-
 
1396
	} else {
-
 
1397
		id = DEREF_id(hashid_id(macro));
-
 
1398
		if (IS_id_keyword(id) && !preproc_only) {
-
 
1399
			/* Warn about redefining keywords */
-
 
1400
			report(preproc_loc, ERR_cpp_predef_keyword(macro));
-
 
1401
		}
-
 
1402
	}
-
 
1403
	prev_def = check_macro(macro, 0);
-
 
1404
	tok = token_macro;
-
 
1405
 
-
 
1406
	/* Check for macro parameters */
-
 
1407
	if (peek_char(char_open_round, &legal)) {
-
 
1408
		PPTOKEN *p;
-
 
1409
		int err = 0;
-
 
1410
		int par_next = 2;
-
 
1411
		LIST(HASHID)lp;
-
 
1412
		unsigned long par_no = 1;
-
 
1413
 
-
 
1414
		/* Scan through definition looking for parameters */
-
 
1415
		update_column();
-
 
1416
		if (in_preproc_dir) {
-
 
1417
			preproc_loc = crt_loc;
-
 
1418
		}
-
 
1419
		while (t = read_token(), t != lex_close_Hround) {
-
 
1420
			update_column();
-
 
1421
			if (in_preproc_dir) {
-
 
1422
				preproc_loc = crt_loc;
-
 
1423
			}
-
 
1424
			if (t == lex_identifier) {
-
 
1425
				/* Identifiers are parameter names */
-
 
1426
				unsigned long mark;
-
 
1427
				HASHID par = token_hashid;
-
 
1428
				IGNORE check_macro(par, 0);
-
 
1429
				CONS_hashid(par, pars, pars);
-
 
1430
 
-
 
1431
				/* Mark name with parameter number */
-
 
1432
				mark = DEREF_ulong(hashid_hash(par));
-
 
1433
				if (mark >= HASH_SIZE) {
-
 
1434
					/* Parameter already marked */
-
 
1435
					ERROR e =
-
 
1436
					    ERR_cpp_replace_par_dup(par, macro);
-
 
1437
					report(preproc_loc, e);
-
 
1438
					mark %= HASH_SIZE;
-
 
1439
				}
-
 
1440
				mark += HASH_SIZE * par_no;
-
 
1441
				COPY_ulong(hashid_hash(par), mark);
-
 
1442
				if (!par_next) {
-
 
1443
					err = 1;
-
 
1444
				}
-
 
1445
				par_next = 0;
-
 
1446
				par_no++;
-
 
1447
			} else if (t == lex_comma) {
-
 
1448
				/* Commas separate parameters */
-
 
1449
				if (par_next) {
-
 
1450
					err = 1;
-
 
1451
				}
-
 
1452
				par_next = 1;
-
 
1453
			} else {
-
 
1454
				/* Anything else is an error */
-
 
1455
				first_tok = t;
-
 
1456
				err = 1;
-
 
1457
				break;
-
 
1458
			}
-
 
1459
		}
-
 
1460
		update_column();
-
 
1461
		if (in_preproc_dir) {
-
 
1462
			preproc_loc = crt_loc;
-
 
1463
		}
-
 
1464
		if (err || par_next == 1) {
-
 
1465
			/* Report any errors */
-
 
1466
			report(preproc_loc, ERR_cpp_replace_par_bad(macro));
-
 
1467
		}
-
 
1468
 
-
 
1469
		/* Allow for parameter expansion in strings */
-
 
1470
		if (preproc_strings) {
-
 
1471
			/* This causes strings not to be recognised */
-
 
1472
			set_char_lookup(char_quote, char_illegal);
-
 
1473
			set_char_lookup(char_single_quote, char_illegal);
-
 
1474
		}
-
 
1475
 
-
 
1476
		/* Read the macro definition for function-like macros */
-
 
1477
		defn = read_line(first_tok, lex_ignore_token);
-
 
1478
		if (defn)defn->pp_space = WHITE_SPACE;
-
 
1479
 
-
 
1480
		/* Restore string terminators */
-
 
1481
		if (preproc_strings) {
-
 
1482
			set_char_lookup(char_quote, char_quote);
-
 
1483
			set_char_lookup(char_single_quote, char_single_quote);
-
 
1484
		}
-
 
1485
 
-
 
1486
		/* Mark the macro parameters in the definition */
-
 
1487
		for (p = defn; p != NULL; p = p->next) {
-
 
1488
			int tk = p->tok;
-
 
1489
			if (tk == lex_identifier) {
-
 
1490
				HASHID par = p->pp_data.id.hash;
-
 
1491
				unsigned long mark =
-
 
1492
				    DEREF_ulong(hashid_hash(par));
-
 
1493
				if (mark >= HASH_SIZE) {
-
 
1494
					/* Parameters are identified by the
-
 
1495
					 * parameter number */
-
 
1496
					p->tok = lex_macro_Harg;
-
 
1497
					p->pp_data.par.hash = par;
-
 
1498
					p->pp_data.par.no = (mark / HASH_SIZE);
-
 
1499
				}
-
 
1500
			}
-
 
1501
		}
-
 
1502
 
-
 
1503
		/* Check for quoted parameters */
-
 
1504
		if (preproc_strings) {
-
 
1505
			defn = recognise_strings(defn, macro, 0);
-
 
1506
		}
-
 
1507
 
-
 
1508
		/* Check for '#' operators */
-
 
1509
		for (p = defn; p != NULL; p = p->next) {
-
 
1510
			int tk = p->tok;
-
 
1511
			if (tk == lex_hash_H2) {
-
 
1512
				tk = get_digraph(tk);
-
 
1513
			}
-
 
1514
			if (tk == lex_hash_H1) {
-
 
1515
				/* '#' should be followed by a parameter */
-
 
1516
				if (p->next == NULL ||
-
 
1517
				    p->next->tok != lex_macro_Harg) {
-
 
1518
					report(preproc_loc,
-
 
1519
					       ERR_cpp_stringize_par(macro));
-
 
1520
				} else {
-
 
1521
					p->tok = lex_hash_Hop;
-
 
1522
				}
-
 
1523
			}
-
 
1524
		}
-
 
1525
 
-
 
1526
		/* Clear the parameter marks */
-
 
1527
		for (lp = pars; !IS_NULL_list(lp); lp = TAIL_list(lp)) {
-
 
1528
			HASHID par = DEREF_hashid(HEAD_list(lp));
-
 
1529
			unsigned long mark = DEREF_ulong(hashid_hash(par));
-
 
1530
			mark %= HASH_SIZE;
-
 
1531
			COPY_ulong(hashid_hash(par), mark);
-
 
1532
			npars++;
-
 
1533
		}
-
 
1534
		pars = REVERSE_list(pars);
-
 
1535
 
-
 
1536
	} else {
-
 
1537
		/* Read the macro definition for object-like macros */
-
 
1538
		if (!legal) {
-
 
1539
			report(preproc_loc, ERR_cpp_space_replace());
-
 
1540
		}
-
 
1541
		defn = read_line(first_tok, lex_ignore_token);
-
 
1542
		object_like = 1;
-
 
1543
	}
-
 
1544
 
-
 
1545
	/* Check for '##' operators */
-
 
1546
	if (defn) {
-
 
1547
		PPTOKEN *p;
-
 
1548
		int tk = defn->tok;
-
 
1549
		if (tk == lex_hash_Hhash_H2) {
-
 
1550
			tk = get_digraph(tk);
-
 
1551
		}
-
 
1552
		if (tk == lex_hash_Hhash_H1) {
-
 
1553
			/* Definition can't start with '##' */
-
 
1554
			report(preproc_loc, ERR_cpp_concat_place(macro));
-
 
1555
		}
-
 
1556
		for (p = defn->next; p != NULL; p = p->next) {
-
 
1557
			tk = p->tok;
-
 
1558
			if (tk == lex_hash_Hhash_H2) {
-
 
1559
				tk = get_digraph(tk);
-
 
1560
			}
-
 
1561
			if (tk == lex_hash_Hhash_H1) {
-
 
1562
				if (p->next == NULL) {
-
 
1563
					/* Definition can't end with '##' */
-
 
1564
					report(preproc_loc,
-
 
1565
					       ERR_cpp_concat_place(macro));
-
 
1566
				} else {
-
 
1567
					p->tok = lex_hash_Hhash_Hop;
-
 
1568
				}
-
 
1569
			}
-
 
1570
		}
-
 
1571
	}
-
 
1572
 
-
 
1573
	/* Define the macro */
-
 
1574
	if (!IS_NULL_exp(crt_hash_cond)) {
-
 
1575
		report(preproc_loc, ERR_cpp_cond_if_macro(macro));
-
 
1576
	}
-
 
1577
	prev = DEREF_id(hashid_id(macro));
-
 
1578
	if (object_like) {
-
 
1579
		MAKE_id_obj_macro(macro, dspec_defn, NULL_nspace, preproc_loc,
-
 
1580
				  defn, id);
-
 
1581
	} else {
-
 
1582
		IGNORE check_value(OPT_VAL_macro_pars, (ulong)npars);
-
 
1583
		MAKE_id_func_macro(macro, dspec_defn, NULL_nspace, preproc_loc,
-
 
1584
				   defn, pars, npars, id);
-
 
1585
	}
-
 
1586
	COPY_id(id_alias(id), prev);
-
 
1587
	if (prev_def & PP_TOKEN) {
-
 
1588
		/* Allow for token definitions */
-
 
1589
		prev_def &= PP_COND_MASK;
-
 
1590
		if (prev_def == PP_UNRESOLVED) {
-
 
1591
			/* Can only happen when preprocessing */
-
 
1592
			token_macro = id;
-
 
1593
			ret = lex_hash_Hop;
-
 
1594
		} else {
-
 
1595
			int tokdef;
-
 
1596
			DECL_SPEC ds = DEREF_dspec(id_storage(id));
-
 
1597
			COPY_dspec(id_storage(id), (ds | dspec_temp));
-
 
1598
			tokdef = define_token_macro(tok, id);
-
 
1599
			COPY_dspec(id_storage(id), ds);
-
 
1600
			if (tokdef) {
-
 
1601
				IGNORE free_macro_defn(id);
-
 
1602
				no_declarations++;
-
 
1603
				return(ret);
-
 
1604
			}
-
 
1605
			prev_def = PP_FALSE;
-
 
1606
		}
-
 
1607
	}
-
 
1608
	COPY_id(hashid_id(macro), id);
-
 
1609
	if (do_macro) {
-
 
1610
		/* Dump macro definition using current namespace */
-
 
1611
		COPY_nspace(id_parent(id), crt_namespace);
1534
	if ( do_macro ) dump_undefine ( prev, &preproc_loc, 1 ) ;
1612
		dump_declare(id, &preproc_loc, 1);
-
 
1613
		COPY_nspace(id_parent(id), NULL_nspace);
-
 
1614
	}
-
 
1615
 
-
 
1616
	/* Check consistency of previous definition */
-
 
1617
	if (prev_def == PP_TRUE) {
-
 
1618
		ERROR err;
-
 
1619
		if (option(OPT_macro_nest) == OPTION_DISALLOW) {
-
 
1620
			err = check_macro_redef(id, prev);
1535
	prev = free_macro_defn ( prev ) ;
1621
			prev = free_macro_defn(prev);
-
 
1622
		} else {
-
 
1623
			PTR(LOCATION)loc = id_loc(prev);
-
 
1624
			err = ERR_cpp_replace_redef_nest(prev, loc);
-
 
1625
		}
-
 
1626
		if (!IS_NULL_err(err)) {
-
 
1627
			report(preproc_loc, err);
-
 
1628
		}
1536
	COPY_id ( hashid_id ( macro ), prev ) ;
1629
		COPY_id(id_alias(id), prev);
-
 
1630
	} else {
1537
	decr_value ( OPT_VAL_macro_ids ) ;
1631
		IGNORE incr_value(OPT_VAL_macro_ids);
-
 
1632
	}
-
 
1633
	return(ret);
-
 
1634
}
-
 
1635
 
-
 
1636
 
-
 
1637
/*
-
 
1638
    READ AN UNDEFINE DIRECTIVE
1538
 
1639
 
-
 
1640
    This routine processes a '#undef' directive.  This just consists of a
-
 
1641
    macro identifier.  The routine returns true if the macro represents
-
 
1642
    a token.
-
 
1643
*/
-
 
1644
 
-
 
1645
static int
-
 
1646
read_undef(void)
-
 
1647
{
-
 
1648
	/* Read the macro identifier */
-
 
1649
	unsigned def;
-
 
1650
	HASHID macro;
-
 
1651
	int ret = lex_ignore_token;
-
 
1652
	int t = read_token();
-
 
1653
	update_column();
-
 
1654
	if (in_preproc_dir) {
-
 
1655
		preproc_loc = crt_loc;
-
 
1656
	}
-
 
1657
	if (t != lex_identifier) {
-
 
1658
		report(preproc_loc, ERR_cpp_scope_id(lex_undef));
-
 
1659
		return(ret);
-
 
1660
	}
-
 
1661
	macro = token_hashid;
-
 
1662
	if (EQ_KEYWORD(macro, lex_defined)) {
-
 
1663
		/* Cannot undefine defined */
-
 
1664
		report(preproc_loc, ERR_cpp_predef_bad(macro, lex_undef));
-
 
1665
	}
-
 
1666
 
-
 
1667
	/* Undefine the macro if necessary */
-
 
1668
	def = check_macro(macro, 0);
-
 
1669
	if (def == PP_TRUE) {
-
 
1670
		/* Previously defined as macro */
-
 
1671
		IDENTIFIER prev = DEREF_id(hashid_id(macro));
-
 
1672
		DECL_SPEC ds = DEREF_dspec(id_storage(prev));
-
 
1673
		if ((ds & dspec_builtin) && crt_file_type == 0) {
-
 
1674
			report(preproc_loc, ERR_cpp_predef_undef(prev));
-
 
1675
		}
-
 
1676
		if (do_macro) {
-
 
1677
			dump_undefine(prev, &preproc_loc, 1);
-
 
1678
		}
-
 
1679
		prev = free_macro_defn(prev);
-
 
1680
		COPY_id(hashid_id(macro), prev);
-
 
1681
		decr_value(OPT_VAL_macro_ids);
-
 
1682
 
1539
    } else if ( def & PP_TOKEN ) {
1683
	} else if (def & PP_TOKEN) {
1540
	/* Previously defined as token */
1684
		/* Previously defined as token */
1541
	IDENTIFIER prev = token_macro ;
1685
		IDENTIFIER prev = token_macro;
1542
	def &= PP_COND_MASK ;
1686
		def &= PP_COND_MASK;
1543
	if ( def == PP_UNRESOLVED ) {
1687
		if (def == PP_UNRESOLVED) {
1544
	    /* Can only happen when preprocessing */
1688
			/* Can only happen when preprocessing */
1545
	    ret = lex_hash_Hop ;
1689
			ret = lex_hash_Hop;
1546
	} else {
1690
		} else {
1547
	    if ( IS_id_function_etc ( prev ) ) {
1691
			if (IS_id_function_etc(prev)) {
1548
		do {
1692
				do {
-
 
1693
					DECL_SPEC ds =
1549
		    DECL_SPEC ds = DEREF_dspec ( id_storage ( prev ) ) ;
1694
					    DEREF_dspec(id_storage(prev));
1550
		    TYPE f = DEREF_type ( id_function_etc_form ( prev ) ) ;
1695
					TYPE f = DEREF_type(id_function_etc_form(prev));
-
 
1696
					if (!IS_NULL_type(f) &&
1551
		    if ( !IS_NULL_type ( f ) && IS_type_token ( f ) ) {
1697
					    IS_type_token(f)) {
-
 
1698
						IDENTIFIER ext =
1552
			IDENTIFIER ext = DEREF_id ( type_token_tok ( f ) ) ;
1699
						    DEREF_id(type_token_tok(f));
-
 
1700
						if (!IS_NULL_id(ext) &&
1553
			if ( !IS_NULL_id ( ext ) && IS_id_token ( ext ) ) {
1701
						    IS_id_token(ext)) {
1554
			    if ( do_dump ) {
1702
							if (do_dump) {
1555
				dump_undefine ( prev, &preproc_loc, 1 ) ;
1703
								dump_undefine(prev, &preproc_loc, 1);
1556
			    }
1704
							}
1557
			    f = NULL_type ;
1705
							f = NULL_type;
1558
			    COPY_type ( id_function_etc_form ( prev ), f ) ;
1706
							COPY_type(id_function_etc_form(prev), f);
-
 
1707
						}
-
 
1708
					}
-
 
1709
					ds &= ~dspec_token;
-
 
1710
					COPY_dspec(id_storage(prev), ds);
-
 
1711
					prev = DEREF_id(id_function_etc_over(prev));
-
 
1712
				} while (!IS_NULL_id(prev));
-
 
1713
			} else {
-
 
1714
				if (do_dump) {
-
 
1715
					dump_undefine(prev, &preproc_loc, 1);
-
 
1716
				}
-
 
1717
				remove_id(prev);
1559
			}
1718
			}
1560
		    }
1719
		}
1561
		    ds &= ~dspec_token ;
-
 
1562
		    COPY_dspec ( id_storage ( prev ), ds ) ;
-
 
1563
		    prev = DEREF_id ( id_function_etc_over ( prev ) ) ;
-
 
1564
		} while ( !IS_NULL_id ( prev ) ) ;
-
 
1565
	    } else {
1720
	} else {
1566
		if ( do_dump ) dump_undefine ( prev, &preproc_loc, 1 ) ;
1721
		/* Not previously declared */
1567
		remove_id ( prev ) ;
1722
		report(preproc_loc, ERR_cpp_scope_undef(macro));
1568
	    }
-
 
1569
	}
1723
	}
1570
 
1724
 
1571
    } else {
-
 
1572
	/* Not previously declared */
-
 
1573
	report ( preproc_loc, ERR_cpp_scope_undef ( macro ) ) ;
-
 
1574
    }
-
 
1575
 
-
 
1576
    /* Check the rest of the directive */
1725
	/* Check the rest of the directive */
1577
    if ( in_preproc_dir && skip_to_end () ) {
1726
	if (in_preproc_dir && skip_to_end()) {
1578
	report ( preproc_loc, ERR_cpp_end ( lex_undef ) ) ;
1727
		report(preproc_loc, ERR_cpp_end(lex_undef));
1579
    }
1728
	}
1580
    return ( ret ) ;
1729
	return(ret);
1581
}
1730
}
1582
 
1731
 
1583
 
1732
 
1584
/*
1733
/*
1585
    READ A LINE DIRECTIVE
1734
    READ A LINE DIRECTIVE
1586
 
1735
 
1587
    This routine processes a '#line' or '#file' directive (as indicated
1736
    This routine processes a '#line' or '#file' directive (as indicated
1588
    by dir).
1737
    by dir).
1589
*/
1738
*/
1590
 
1739
 
1591
static void read_location
1740
static void
1592
    PROTO_N ( ( dir ) )
-
 
1593
    PROTO_T ( int dir )
1741
read_location(int dir)
1594
{
1742
{
1595
    /* Read the line */
1743
	/* Read the line */
1596
    PPTOKEN *p = read_line ( lex_ignore_token, lex_ignore_token ) ;
1744
	PPTOKEN *p = read_line(lex_ignore_token, lex_ignore_token);
1597
    unsigned long ln = crt_loc.line ;
1745
	unsigned long ln = crt_loc.line;
1598
    string fn = DEREF_string ( posn_file ( crt_loc.posn ) ) ;
1746
	string fn = DEREF_string(posn_file(crt_loc.posn));
1599
    unsigned long ln_old = ln ;
1747
	unsigned long ln_old = ln;
1600
    string fn_old = fn ;
1748
	string fn_old = fn;
1601
 
1749
 
1602
    /* Macro expand the line */
1750
	/* Macro expand the line */
1603
    PPTOKEN *q = expand_tok_list ( p ) ;
1751
	PPTOKEN *q = expand_tok_list(p);
1604
    q = clean_tok_list ( q ) ;
1752
	q = clean_tok_list(q);
1605
    if ( q && q->tok == lex_integer_Hlit && dir == lex_line ) {
1753
	if (q && q->tok == lex_integer_Hlit && dir == lex_line) {
1606
	/* Process '#line number string-opt' */
1754
		/* Process '#line number string-opt' */
1607
	unsigned err = 0 ;
1755
		unsigned err = 0;
1608
	PPTOKEN *r = q->next ;
1756
		PPTOKEN *r = q->next;
1609
	ln = eval_line_digits ( q->pp_data.text, &err ) ;
1757
		ln = eval_line_digits(q->pp_data.text, &err);
-
 
1758
		if (ln != ln_old) {
1610
	if ( ln != ln_old ) crt_line_changed = 1 ;
1759
			crt_line_changed = 1;
-
 
1760
		}
1611
	if ( err & 2 ) {
1761
		if (err & 2) {
1612
	    report ( preproc_loc, ERR_cpp_line_float ( dir ) ) ;
1762
			report(preproc_loc, ERR_cpp_line_float(dir));
1613
	}
1763
		}
1614
	if ( ( err & 1 ) || ( ln == 0 ) ) {
1764
		if ((err & 1) || (ln == 0)) {
1615
	    report ( preproc_loc, ERR_cpp_line_range ( dir ) ) ;
1765
			report(preproc_loc, ERR_cpp_line_range(dir));
1616
	}
1766
		}
1617
	if ( r && r->tok == lex_string_Hlit ) {
1767
		if (r && r->tok == lex_string_Hlit) {
1618
	    fn = r->pp_data.str.start ;
1768
			fn = r->pp_data.str.start;
1619
	    if ( !ustreq ( fn, fn_old ) ) {
1769
			if (!ustreq(fn, fn_old)) {
1620
		crt_file_changed = 1 ;
1770
				crt_file_changed = 1;
1621
		crt_line_changed = 1 ;
1771
				crt_line_changed = 1;
1622
	    }
1772
			}
1623
	    r = r->next ;
1773
			r = r->next;
1624
	}
1774
		}
-
 
1775
		if (r) {
1625
	if ( r ) report ( preproc_loc, ERR_cpp_end ( dir ) ) ;
1776
			report(preproc_loc, ERR_cpp_end(dir));
-
 
1777
		}
1626
    } else if ( q && q->tok == lex_string_Hlit && dir == lex_file ) {
1778
	} else if (q && q->tok == lex_string_Hlit && dir == lex_file) {
1627
	/* Process '#file string' */
1779
		/* Process '#file string' */
1628
	PPTOKEN *r = q->next ;
1780
		PPTOKEN *r = q->next;
1629
	fn = q->pp_data.str.start ;
1781
		fn = q->pp_data.str.start;
1630
	if ( !ustreq ( fn, fn_old ) ) {
1782
		if (!ustreq(fn, fn_old)) {
1631
	    crt_file_changed = 1 ;
1783
			crt_file_changed = 1;
1632
	    crt_line_changed = 1 ;
1784
			crt_line_changed = 1;
1633
	}
1785
		}
-
 
1786
		if (r) {
1634
	if ( r ) report ( preproc_loc, ERR_cpp_end ( dir ) ) ;
1787
			report(preproc_loc, ERR_cpp_end(dir));
-
 
1788
		}
1635
    } else {
1789
	} else {
1636
	report ( preproc_loc, ERR_cpp_line_bad ( dir ) ) ;
1790
		report(preproc_loc, ERR_cpp_line_bad(dir));
1637
    }
1791
	}
1638
    free_tok_list ( p ) ;
1792
	free_tok_list(p);
1639
    free_tok_list ( q ) ;
1793
	free_tok_list(q);
1640
    if ( crt_line_changed ) {
1794
	if (crt_line_changed) {
1641
	PTR ( POSITION ) posn = crt_loc.posn ;
1795
		PTR(POSITION)posn = crt_loc.posn;
1642
	string d = DEREF_string ( posn_dir ( posn ) ) ;
1796
		string d = DEREF_string(posn_dir(posn));
1643
	string input = DEREF_string ( posn_input ( posn ) ) ;
1797
		string input = DEREF_string(posn_input(posn));
1644
	unsigned long off = DEREF_ulong ( posn_offset ( posn ) ) ;
1798
		unsigned long off = DEREF_ulong(posn_offset(posn));
1645
	unsigned long date = DEREF_ulong ( posn_datestamp ( posn ) ) ;
1799
		unsigned long date = DEREF_ulong(posn_datestamp(posn));
1646
	PTR ( LOCATION ) from = DEREF_ptr ( posn_from ( posn ) ) ;
1800
		PTR(LOCATION)from = DEREF_ptr(posn_from(posn));
1647
	off += ( ln - ln_old ) ;
1801
		off += (ln - ln_old);
1648
	posn = MAKE_ptr ( SIZE_posn ) ;
1802
		posn = MAKE_ptr(SIZE_posn);
1649
	MAKE_posn ( fn, input, fn, d, off, from, date, posn ) ;
1803
		MAKE_posn(fn, input, fn, d, off, from, date, posn);
1650
	crt_loc.posn = posn ;
1804
		crt_loc.posn = posn;
1651
    }
1805
	}
1652
    crt_loc.line = ln ;
1806
	crt_loc.line = ln;
1653
    crt_loc.column = 0 ;
1807
	crt_loc.column = 0;
1654
    return ;
1808
	return;
1655
}
1809
}
1656
 
1810
 
1657
 
1811
 
1658
/*
1812
/*
1659
    READ AN ERROR DIRECTIVE
1813
    READ AN ERROR DIRECTIVE
1660
 
1814
 
1661
    This routine processes a '#error' or '#warning' directive (as indicated
1815
    This routine processes a '#error' or '#warning' directive (as indicated
1662
    by the error severity level sev).
1816
    by the error severity level sev).
1663
*/
1817
*/
1664
 
1818
 
1665
static void read_error
1819
static void
1666
    PROTO_N ( ( opt ) )
-
 
1667
    PROTO_T ( int opt )
1820
read_error(int opt)
1668
{
-
 
1669
    ERROR err ;
-
 
1670
    PPTOKEN *p = read_line ( lex_ignore_token, lex_ignore_token ) ;
-
 
1671
    IGNORE quote_tok_list ( p, 0, char_quote ) ;
-
 
1672
    err = ERR_cpp_error_msg ( token_buff.start ) ;
-
 
1673
    if ( !IS_NULL_err ( err ) ) {
-
 
1674
	err = set_severity ( err, opt, 0 ) ;
-
 
1675
	report ( preproc_loc, err ) ;
-
 
1676
    }
-
 
1677
    free_tok_list ( p ) ;
-
 
1678
    return ;
-
 
1679
}
-
 
1680
 
-
 
1681
 
-
 
1682
/*
-
 
1683
    READ AN IDENT DIRECTIVE
-
 
1684
 
-
 
1685
    This routine processes a '#ident' directive.
-
 
1686
*/
-
 
1687
 
-
 
1688
void read_ident
-
 
1689
    PROTO_N ( ( dir ) )
-
 
1690
    PROTO_T ( int dir )
-
 
1691
{
1821
{
1692
    int t = read_token () ;
-
 
1693
    update_column () ;
1822
	ERROR err;
1694
    if ( in_preproc_dir ) preproc_loc = crt_loc ;
1823
	PPTOKEN *p = read_line(lex_ignore_token, lex_ignore_token);
1695
    if ( t == lex_string_Hlit ) {
1824
	IGNORE quote_tok_list(p, 0, char_quote);
1696
	string s = token_buff.start ;
1825
	err = ERR_cpp_error_msg(token_buff.start);
1697
	unsigned long n = ( unsigned long ) ( token_buff.posn - s ) ;
-
 
1698
	compile_comment ( s, n ) ;
1826
	if (!IS_NULL_err(err)) {
1699
	if ( in_preproc_dir && skip_to_end () ) {
1827
		err = set_severity(err, opt, 0);
1700
	    report ( preproc_loc, ERR_cpp_end ( dir ) ) ;
1828
		report(preproc_loc, err);
1701
	}
1829
	}
-
 
1830
	free_tok_list(p);
-
 
1831
	return;
-
 
1832
}
-
 
1833
 
-
 
1834
 
-
 
1835
/*
-
 
1836
    READ AN IDENT DIRECTIVE
-
 
1837
 
-
 
1838
    This routine processes a '#ident' directive.
-
 
1839
*/
-
 
1840
 
-
 
1841
void
-
 
1842
read_ident(int dir)
-
 
1843
{
-
 
1844
	int t = read_token();
-
 
1845
	update_column();
-
 
1846
	if (in_preproc_dir) {
-
 
1847
		preproc_loc = crt_loc;
-
 
1848
	}
-
 
1849
	if (t == lex_string_Hlit) {
-
 
1850
		string s = token_buff.start;
-
 
1851
		unsigned long n = (unsigned long)(token_buff.posn - s);
-
 
1852
		compile_comment(s, n);
-
 
1853
		if (in_preproc_dir && skip_to_end()) {
-
 
1854
			report(preproc_loc, ERR_cpp_end(dir));
-
 
1855
		}
1702
    } else {
1856
	} else {
1703
	report ( preproc_loc, ERR_pragma_cpp_ident ( dir ) ) ;
1857
		report(preproc_loc, ERR_pragma_cpp_ident(dir));
1704
    }
1858
	}
1705
    return ;
1859
	return;
1706
}
1860
}
1707
 
1861
 
1708
 
1862
 
1709
/*
1863
/*
1710
    CREATE AN ASSERTION
1864
    CREATE AN ASSERTION
1711
 
1865
 
1712
    This routine looks up the assertion named pred, creating it if it does
1866
    This routine looks up the assertion named pred, creating it if it does
1713
    not already exist.
1867
    not already exist.
1714
*/
1868
*/
1715
 
1869
 
1716
IDENTIFIER make_assert
1870
IDENTIFIER
1717
    PROTO_N ( ( pred, key ) )
-
 
1718
    PROTO_T ( HASHID pred X int key )
1871
make_assert(HASHID pred, int key)
1719
{
1872
{
1720
    NAMESPACE ns = assert_namespace ;
1873
	NAMESPACE ns = assert_namespace;
1721
    MEMBER mem = search_member ( ns, pred, 1 ) ;
1874
	MEMBER mem = search_member(ns, pred, 1);
1722
    IDENTIFIER id = DEREF_id ( member_id ( mem ) ) ;
1875
	IDENTIFIER id = DEREF_id(member_id(mem));
1723
    if ( IS_NULL_id ( id ) ) {
1876
	if (IS_NULL_id(id)) {
1724
	/* Define assertion if not already defined */
1877
		/* Define assertion if not already defined */
1725
	MAKE_id_predicate ( pred, dspec_none, ns, preproc_loc, id ) ;
1878
		MAKE_id_predicate(pred, dspec_none, ns, preproc_loc, id);
1726
	COPY_ulong ( id_no ( id ), ( unsigned long ) key ) ;
1879
		COPY_ulong(id_no(id), (unsigned long)key);
1727
	COPY_id ( member_id ( mem ), id ) ;
1880
		COPY_id(member_id(mem), id);
1728
    }
1881
	}
1729
    return ( id ) ;
1882
	return(id);
1730
}
1883
}
1731
 
1884
 
1732
 
1885
 
1733
/*
1886
/*
1734
    SKIP A PREDICATE
1887
    SKIP A PREDICATE
1735
 
1888
 
1736
    This routine skips a predicate given by the list of preprocessing
1889
    This routine skips a predicate given by the list of preprocessing
1737
    tokens p.  It is entered after the initial open bracket and returns
1890
    tokens p.  It is entered after the initial open bracket and returns
1738
    the token after the matching close bracket.
1891
    the token after the matching close bracket.
1739
*/
1892
*/
1740
 
1893
 
1741
static PPTOKEN *skip_predicate
1894
static PPTOKEN *
1742
    PROTO_N ( ( p, dir ) )
-
 
1743
    PROTO_T ( PPTOKEN **p X int dir )
1895
skip_predicate(PPTOKEN **p, int dir)
1744
{
1896
{
1745
    PPTOKEN *q = *p ;
1897
	PPTOKEN *q = *p;
1746
    PPTOKEN *r = NULL ;
1898
	PPTOKEN *r = NULL;
1747
    int bracket = 1 ;
1899
	int bracket = 1;
-
 
1900
	if (q) {
1748
    if ( q ) q->pp_space = 0 ;
1901
		q->pp_space = 0;
-
 
1902
	}
1749
    while ( q ) {
1903
	while (q) {
1750
	int t = q->tok ;
1904
		int t = q->tok;
1751
	if ( t == lex_open_Hround ) {
1905
		if (t == lex_open_Hround) {
1752
	    /* Increase bracket count */
1906
			/* Increase bracket count */
1753
	    bracket++ ;
1907
			bracket++;
1754
	} else if ( t == lex_close_Hround ) {
1908
		} else if (t == lex_close_Hround) {
1755
	    /* Decrease bracket count */
1909
			/* Decrease bracket count */
1756
	    if ( --bracket == 0 ) {
1910
			if (--bracket == 0) {
1757
		if ( r ) {
1911
				if (r) {
1758
		    r->next = NULL ;
1912
					r->next = NULL;
1759
		} else if ( dir == lex_define || dir == lex_undef ) {
1913
				} else if (dir == lex_define ||
-
 
1914
					   dir == lex_undef) {
1760
		    *p = NULL ;
1915
					*p = NULL;
1761
		} else {
1916
				} else {
-
 
1917
					report(preproc_loc,
-
 
1918
					       ERR_pragma_assert_empty(dir));
-
 
1919
					*p = NULL;
-
 
1920
				}
-
 
1921
				r = q->next;
-
 
1922
				q->next = free_tokens;
-
 
1923
				free_tokens = q;
-
 
1924
				return(r);
-
 
1925
			}
-
 
1926
		} else if (t == lex_newline) {
-
 
1927
			/* Terminate if a newline is reached */
1762
		    report ( preproc_loc, ERR_pragma_assert_empty ( dir ) ) ;
1928
			report(preproc_loc, ERR_pragma_assert_paren(dir));
-
 
1929
			if (r) {
-
 
1930
				r->next = NULL;
-
 
1931
			} else {
-
 
1932
				report(preproc_loc,
-
 
1933
				       ERR_pragma_assert_empty(dir));
1763
		    *p = NULL ;
1934
				*p = NULL;
-
 
1935
			}
-
 
1936
			return(q);
1764
		}
1937
		}
1765
		r = q->next ;
1938
		r = q;
1766
		q->next = free_tokens ;
-
 
1767
		free_tokens = q ;
-
 
1768
		return ( r ) ;
-
 
1769
	    }
-
 
1770
	} else if ( t == lex_newline ) {
-
 
1771
	    /* Terminate if a newline is reached */
-
 
1772
	    report ( preproc_loc, ERR_pragma_assert_paren ( dir ) ) ;
-
 
1773
	    if ( r ) {
-
 
1774
		r->next = NULL ;
-
 
1775
	    } else {
-
 
1776
		report ( preproc_loc, ERR_pragma_assert_empty ( dir ) ) ;
-
 
1777
		*p = NULL ;
1939
		q = q->next;
1778
	    }
-
 
1779
	    return ( q ) ;
-
 
1780
	}
1940
	}
1781
	r = q ;
-
 
1782
	q = q->next ;
-
 
1783
    }
-
 
1784
    report ( preproc_loc, ERR_pragma_assert_paren ( dir ) ) ;
1941
	report(preproc_loc, ERR_pragma_assert_paren(dir));
1785
    return ( NULL ) ;
1942
	return(NULL);
1786
}
1943
}
1787
 
1944
 
1788
 
1945
 
1789
/*
1946
/*
1790
    CHECK A PREDICATE VALUE
1947
    CHECK A PREDICATE VALUE
1791
 
1948
 
1792
    This routine checks whether the value p, or any value if def is true,
1949
    This routine checks whether the value p, or any value if def is true,
1793
    has been defined in the predicate pred.
1950
    has been defined in the predicate pred.
1794
*/
1951
*/
1795
 
1952
 
1796
static int check_assert
1953
static int
1797
    PROTO_N ( ( pred, p, def ) )
-
 
1798
    PROTO_T ( HASHID pred X PPTOKEN *p X int def )
1954
check_assert(HASHID pred, PPTOKEN *p, int def)
1799
{
1955
{
1800
    IDENTIFIER id = make_assert ( pred, lex_unknown ) ;
1956
	IDENTIFIER id = make_assert(pred, lex_unknown);
1801
    int key = ( int ) DEREF_ulong ( id_no ( id ) ) ;
1957
	int key = (int)DEREF_ulong(id_no(id));
1802
    LIST ( PPTOKEN_P ) s = DEREF_list ( id_predicate_values ( id ) ) ;
1958
	LIST(PPTOKEN_P)s = DEREF_list(id_predicate_values(id));
1803
    report ( preproc_loc, ERR_pragma_assert_pred ( pred ) ) ;
1959
	report(preproc_loc, ERR_pragma_assert_pred(pred));
1804
    if ( def ) {
1960
	if (def) {
1805
	/* Check for any predicate */
1961
		/* Check for any predicate */
1806
	if ( !IS_NULL_list ( s ) ) return ( 1 ) ;
1962
		if (!IS_NULL_list(s)) {
-
 
1963
			return(1);
-
 
1964
		}
1807
    } else {
1965
	} else {
1808
	while ( !IS_NULL_list ( s ) ) {
1966
		while (!IS_NULL_list(s)) {
1809
	    PPTOKEN *q = DEREF_pptok ( HEAD_list ( s ) ) ;
1967
			PPTOKEN *q = DEREF_pptok(HEAD_list(s));
1810
	    if ( eq_pptok ( p, q ) == 2 ) return ( 1 ) ;
1968
			if (eq_pptok(p, q) == 2) {
-
 
1969
				return(1);
-
 
1970
			}
1811
	    s = TAIL_list ( s ) ;
1971
			s = TAIL_list(s);
1812
	}
1972
		}
1813
    }
1973
	}
1814
    if ( key == lex_include ) {
1974
	if (key == lex_include) {
1815
	/* '#include' checks for included files */
1975
		/* '#include' checks for included files */
-
 
1976
		if (def) {
1816
	if ( def ) return ( 1 ) ;
1977
			return(1);
-
 
1978
		}
1817
	IGNORE quote_tok_list ( p, 0, char_quote ) ;
1979
		IGNORE quote_tok_list(p, 0, char_quote);
1818
	return ( start_include ( token_buff.start, char_quote, 4, 0 ) ) ;
1980
		return(start_include(token_buff.start, char_quote, 4, 0));
1819
    }
1981
	}
1820
    if ( key == lex_keyword ) {
1982
	if (key == lex_keyword) {
1821
	/* '#keyword' checks for keywords */
1983
		/* '#keyword' checks for keywords */
-
 
1984
		if (def) {
1822
	if ( def ) return ( 1 ) ;
1985
			return(1);
-
 
1986
		}
1823
	if ( p && p->next == NULL ) {
1987
		if (p && p->next == NULL) {
1824
	    if ( p->tok == lex_identifier ) {
1988
			if (p->tok == lex_identifier) {
1825
		IDENTIFIER pid = p->pp_data.id.use ;
1989
				IDENTIFIER pid = p->pp_data.id.use;
1826
		if ( IS_id_keyword ( pid ) ) return ( 1 ) ;
1990
				if (IS_id_keyword(pid)) {
-
 
1991
					return(1);
-
 
1992
				}
1827
		if ( IS_id_iso_keyword ( pid ) ) return ( 1 ) ;
1993
				if (IS_id_iso_keyword(pid)) {
-
 
1994
					return(1);
1828
	    }
1995
				}
-
 
1996
			}
1829
	}
1997
		}
1830
    }
1998
	}
1831
    if ( key == lex_option ) {
1999
	if (key == lex_option) {
1832
	/* '#option' checks for options */
2000
		/* '#option' checks for options */
1833
	int n ;
2001
		int n;
1834
	ulong sn ;
2002
		ulong sn;
1835
	string sb ;
2003
		string sb;
1836
	static STRING str = NULL_str ;
2004
		static STRING str = NULL_str;
-
 
2005
		if (def) {
1837
	if ( def ) return ( 1 ) ;
2006
			return(1);
-
 
2007
		}
1838
	IGNORE quote_tok_list ( p, 0, char_quote ) ;
2008
		IGNORE quote_tok_list(p, 0, char_quote);
1839
	sb = token_buff.start ;
2009
		sb = token_buff.start;
1840
	sn = ( ulong ) ( token_buff.posn - sb ) ;
2010
		sn = (ulong)(token_buff.posn - sb);
1841
	if ( IS_NULL_str ( str ) ) {
2011
		if (IS_NULL_str(str)) {
1842
	    MAKE_str_simple ( sn, sb, STRING_NONE, str ) ;
2012
			MAKE_str_simple(sn, sb, STRING_NONE, str);
1843
	} else {
2013
		} else {
1844
	    COPY_string ( str_simple_text ( str ), sb ) ;
2014
			COPY_string(str_simple_text(str), sb);
1845
	    COPY_ulong ( str_simple_len ( str ), sn ) ;
2015
			COPY_ulong(str_simple_len(str), sn);
1846
	}
2016
		}
1847
	n = find_option_no ( str, 0 ) ;
2017
		n = find_option_no(str, 0);
1848
	if ( n != -1 && option ( n ) ) return ( 1 ) ;
2018
		if (n != -1 && option(n)) {
-
 
2019
			return(1);
1849
    }
2020
		}
-
 
2021
	}
1850
    return ( 0 ) ;
2022
	return(0);
1851
}
2023
}
1852
 
2024
 
1853
 
2025
 
1854
/*
2026
/*
1855
    SET A PREDICATE VALUE
2027
    SET A PREDICATE VALUE
1856
 
2028
 
1857
    This routine sets the assertion value of the preprocessing tokens p
2029
    This routine sets the assertion value of the preprocessing tokens p
1858
    in the predicate id to be def.
2030
    in the predicate id to be def.
1859
*/
2031
*/
1860
 
2032
 
1861
static void set_assert
2033
static void
1862
    PROTO_N ( ( id, p, def ) )
-
 
1863
    PROTO_T ( IDENTIFIER id X PPTOKEN *p X int def )
2034
set_assert(IDENTIFIER id, PPTOKEN *p, int def)
1864
{
2035
{
1865
    LIST ( PPTOKEN_P ) s ;
2036
	LIST(PPTOKEN_P)s;
1866
    PTR ( LIST ( PPTOKEN_P ) ) ps = id_predicate_values ( id ) ;
2037
	PTR(LIST(PPTOKEN_P))ps = id_predicate_values(id);
1867
    LIST ( PPTOKEN_P ) r = DEREF_list ( ps ) ;
2038
	LIST(PPTOKEN_P)r = DEREF_list(ps);
1868
    while ( s = DEREF_list ( ps ), !IS_NULL_list ( s ) ) {
2039
	while (s = DEREF_list(ps), !IS_NULL_list(s)) {
1869
	PPTOKEN *q = DEREF_pptok ( HEAD_list ( s ) ) ;
2040
		PPTOKEN *q = DEREF_pptok(HEAD_list(s));
1870
	if ( eq_pptok ( p, q ) == 2 ) {
2041
		if (eq_pptok(p, q) == 2) {
1871
	    /* Already asserted */
2042
			/* Already asserted */
1872
	    if ( !def ) {
2043
			if (!def) {
1873
		DESTROY_CONS_pptok ( destroy, q, s, s ) ;
2044
				DESTROY_CONS_pptok(destroy, q, s, s);
1874
		COPY_list ( ps, s ) ;
2045
				COPY_list(ps, s);
1875
		free_tok_list ( q ) ;
2046
				free_tok_list(q);
1876
	    }
2047
			}
1877
	    free_tok_list ( p ) ;
2048
			free_tok_list(p);
1878
	    return ;
2049
			return;
1879
	}
2050
		}
1880
	ps = PTR_TAIL_list ( s ) ;
2051
		ps = PTR_TAIL_list(s);
1881
    }
2052
	}
1882
    if ( def ) {
2053
	if (def) {
1883
	/* Create assertion */
2054
		/* Create assertion */
1884
	CONS_pptok ( p, r, r ) ;
2055
		CONS_pptok(p, r, r);
1885
	COPY_list ( id_predicate_values ( id ), r ) ;
2056
		COPY_list(id_predicate_values(id), r);
1886
    } else {
2057
	} else {
1887
	free_tok_list ( p ) ;
2058
		free_tok_list(p);
1888
    }
2059
	}
1889
    return ;
2060
	return;
1890
}
2061
}
1891
 
2062
 
1892
 
2063
 
1893
/*
2064
/*
1894
    READ AN ASSERT DIRECTIVE
2065
    READ AN ASSERT DIRECTIVE
1895
 
2066
 
1896
    This routine processes a '#assert' directive.
2067
    This routine processes a '#assert' directive.
1897
*/
2068
*/
1898
 
-
 
1899
static void read_assert
-
 
1900
    PROTO_N ( ( dir ) )
-
 
1901
    PROTO_T ( int dir )
-
 
1902
{
-
 
1903
    /* Read the predicate name */
-
 
1904
    int def = 1 ;
-
 
1905
    IDENTIFIER id ;
-
 
1906
    PPTOKEN *p, *q ;
-
 
1907
    int t = read_token () ;
-
 
1908
    update_column () ;
-
 
1909
    if ( in_preproc_dir ) preproc_loc = crt_loc ;
-
 
1910
    if ( t != lex_identifier ) {
-
 
1911
	report ( preproc_loc, ERR_pragma_assert_id ( dir ) ) ;
-
 
1912
	return ;
-
 
1913
    }
-
 
1914
    id = make_assert ( token_hashid, lex_unknown ) ;
-
 
1915
 
2069
 
-
 
2070
static void
-
 
2071
read_assert(int dir)
-
 
2072
{
-
 
2073
	/* Read the predicate name */
-
 
2074
	int def = 1;
-
 
2075
	IDENTIFIER id;
-
 
2076
	PPTOKEN *p, *q;
-
 
2077
	int t = read_token();
-
 
2078
	update_column();
-
 
2079
	if (in_preproc_dir) {
-
 
2080
		preproc_loc = crt_loc;
-
 
2081
	}
-
 
2082
	if (t != lex_identifier) {
-
 
2083
		report(preproc_loc, ERR_pragma_assert_id(dir));
-
 
2084
		return;
-
 
2085
	}
-
 
2086
	id = make_assert(token_hashid, lex_unknown);
-
 
2087
 
1916
    /* Read the predicate token sequence */
2088
	/* Read the predicate token sequence */
1917
    t = read_token () ;
2089
	t = read_token();
1918
    update_column () ;
2090
	update_column();
-
 
2091
	if (in_preproc_dir) {
1919
    if ( in_preproc_dir ) preproc_loc = crt_loc ;
2092
		preproc_loc = crt_loc;
-
 
2093
	}
1920
    if ( t != lex_open_Hround ) {
2094
	if (t != lex_open_Hround) {
1921
	report ( preproc_loc, ERR_pragma_assert_open ( dir ) ) ;
2095
		report(preproc_loc, ERR_pragma_assert_open(dir));
1922
	return ;
2096
		return;
1923
    }
2097
	}
1924
    p = read_line ( lex_ignore_token, lex_ignore_token ) ;
2098
	p = read_line(lex_ignore_token, lex_ignore_token);
1925
    q = skip_predicate ( &p, dir ) ;
2099
	q = skip_predicate(&p, dir);
1926
    if ( q ) {
2100
	if (q) {
1927
	report ( preproc_loc, ERR_cpp_end ( dir ) ) ;
2101
		report(preproc_loc, ERR_cpp_end(dir));
1928
	free_tok_list ( q ) ;
2102
		free_tok_list(q);
1929
    }
2103
	}
1930
 
2104
 
1931
    /* Create the assertion */
2105
	/* Create the assertion */
-
 
2106
	if (p) {
1932
    if ( p ) set_assert ( id, p, def ) ;
2107
		set_assert(id, p, def);
-
 
2108
	}
1933
    return ;
2109
	return;
1934
}
2110
}
1935
 
2111
 
1936
 
2112
 
1937
/*
2113
/*
1938
    READ AN UNASSERT DIRECTIVE
2114
    READ AN UNASSERT DIRECTIVE
1939
 
2115
 
1940
    This routine processes a '#unassert' directive.
2116
    This routine processes a '#unassert' directive.
1941
*/
2117
*/
1942
 
2118
 
1943
static void read_unassert
2119
static void
1944
    PROTO_N ( ( dir ) )
-
 
1945
    PROTO_T ( int dir )
2120
read_unassert(int dir)
1946
{
2121
{
1947
    /* Read the predicate name */
2122
	/* Read the predicate name */
1948
    IDENTIFIER id ;
2123
	IDENTIFIER id;
1949
    PPTOKEN *p, *q ;
2124
	PPTOKEN *p, *q;
1950
    int t = read_token () ;
2125
	int t = read_token();
1951
    update_column () ;
2126
	update_column();
-
 
2127
	if (in_preproc_dir) {
1952
    if ( in_preproc_dir ) preproc_loc = crt_loc ;
2128
		preproc_loc = crt_loc;
-
 
2129
	}
1953
    if ( t != lex_identifier ) {
2130
	if (t != lex_identifier) {
1954
	report ( preproc_loc, ERR_pragma_assert_id ( dir ) ) ;
2131
		report(preproc_loc, ERR_pragma_assert_id(dir));
1955
	return ;
2132
		return;
1956
    }
2133
	}
1957
    id = make_assert ( token_hashid, lex_unknown ) ;
2134
	id = make_assert(token_hashid, lex_unknown);
1958
 
2135
 
1959
    /* Check for simple identifier */
2136
	/* Check for simple identifier */
1960
    t = read_token () ;
2137
	t = read_token();
1961
    update_column () ;
2138
	update_column();
-
 
2139
	if (in_preproc_dir) {
1962
    if ( in_preproc_dir ) preproc_loc = crt_loc ;
2140
		preproc_loc = crt_loc;
-
 
2141
	}
1963
    if ( t == lex_newline ) {
2142
	if (t == lex_newline) {
1964
	p = NULL ;
2143
		p = NULL;
1965
    } else {
2144
	} else {
1966
	/* Read the predicate token sequence */
2145
		/* Read the predicate token sequence */
1967
	if ( t != lex_open_Hround ) {
2146
		if (t != lex_open_Hround) {
1968
	    report ( preproc_loc, ERR_pragma_assert_open ( dir ) ) ;
2147
			report(preproc_loc, ERR_pragma_assert_open(dir));
1969
	    return ;
2148
			return;
1970
	}
2149
		}
1971
	p = read_line ( lex_ignore_token, lex_ignore_token ) ;
2150
		p = read_line(lex_ignore_token, lex_ignore_token);
1972
	q = skip_predicate ( &p, dir ) ;
2151
		q = skip_predicate(&p, dir);
1973
	if ( q ) {
2152
		if (q) {
1974
	    report ( preproc_loc, ERR_cpp_end ( dir ) ) ;
2153
			report(preproc_loc, ERR_cpp_end(dir));
1975
	    free_tok_list ( q ) ;
2154
			free_tok_list(q);
1976
	}
2155
		}
1977
    }
2156
	}
1978
 
2157
 
1979
    if ( p == NULL ) {
2158
	if (p == NULL) {
1980
	/* Unassert all values */
2159
		/* Unassert all values */
1981
	LIST ( PPTOKEN_P ) r ;
2160
		LIST(PPTOKEN_P)r;
1982
	r = DEREF_list ( id_predicate_values ( id ) ) ;
2161
		r = DEREF_list(id_predicate_values(id));
1983
	while ( !IS_NULL_list ( r ) ) {
2162
		while (!IS_NULL_list(r)) {
1984
	    DESTROY_CONS_pptok ( destroy, q, r, r ) ;
2163
			DESTROY_CONS_pptok(destroy, q, r, r);
1985
	    free_tok_list ( q ) ;
2164
			free_tok_list(q);
-
 
2165
		}
-
 
2166
		COPY_list(id_predicate_values(id), r);
-
 
2167
		COPY_ulong(id_no(id), lex_unknown);
-
 
2168
	} else {
-
 
2169
		/* Destroy the assertion */
-
 
2170
		set_assert(id, p, 0);
1986
	}
2171
	}
1987
	COPY_list ( id_predicate_values ( id ), r ) ;
-
 
1988
	COPY_ulong ( id_no ( id ), lex_unknown ) ;
-
 
1989
    } else {
-
 
1990
	/* Destroy the assertion */
-
 
1991
	set_assert ( id, p, 0 ) ;
-
 
1992
    }
-
 
1993
    return ;
2172
	return;
1994
}
2173
}
1995
 
2174
 
1996
 
2175
 
1997
/*
2176
/*
1998
    LOOK UP AN IDENTIFIER IN A PRAGMA WEAK DIRECTIVE
2177
    LOOK UP AN IDENTIFIER IN A PRAGMA WEAK DIRECTIVE
1999
 
2178
 
2000
    This routine looks up the identifier named nm used in a '#pragma
2179
    This routine looks up the identifier named nm used in a '#pragma
2001
    weak' directive.  The result should be an external variable or
2180
    weak' directive.  The result should be an external variable or
2002
    function.  The null identifier is returned to indicate an error.
2181
    function.  The null identifier is returned to indicate an error.
2003
*/
2182
*/
2004
 
2183
 
2005
static IDENTIFIER find_weak_id
2184
static IDENTIFIER
2006
    PROTO_N ( ( nm ) )
-
 
2007
    PROTO_T ( HASHID nm )
2185
find_weak_id(HASHID nm)
2008
{
2186
{
2009
    if ( !IS_NULL_hashid ( nm ) ) {
2187
	if (!IS_NULL_hashid(nm)) {
2010
	ERROR err ;
2188
		ERROR err;
2011
	IDENTIFIER id = find_id ( nm ) ;
2189
		IDENTIFIER id = find_id(nm);
2012
	switch ( TAG_id ( id ) ) {
2190
		switch (TAG_id(id)) {
2013
	    case id_variable_tag : {
2191
		case id_variable_tag: {
2014
		DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
2192
			DECL_SPEC ds = DEREF_dspec(id_storage(id));
2015
		if ( !( ds & dspec_auto ) ) {
2193
			if (!(ds & dspec_auto)) {
2016
		    ds |= dspec_used ;
2194
				ds |= dspec_used;
2017
		    COPY_dspec ( id_storage ( id ), ds ) ;
2195
				COPY_dspec(id_storage(id), ds);
2018
		    return ( id ) ;
2196
				return(id);
2019
		}
2197
			}
2020
		break ;
2198
			break;
2021
	    }
2199
		}
2022
	    case id_function_tag : {
2200
		case id_function_tag: {
2023
		TYPE t = DEREF_type ( id_function_type ( id ) ) ;
2201
			TYPE t = DEREF_type(id_function_type(id));
2024
		IDENTIFIER over = DEREF_id ( id_function_over ( id ) ) ;
2202
			IDENTIFIER over = DEREF_id(id_function_over(id));
2025
		if ( IS_NULL_id ( over ) && IS_type_func ( t ) ) {
2203
			if (IS_NULL_id(over) && IS_type_func(t)) {
2026
		    DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
2204
				DECL_SPEC ds = DEREF_dspec(id_storage(id));
2027
		    ds |= dspec_used ;
2205
				ds |= dspec_used;
2028
		    COPY_dspec ( id_storage ( id ), ds ) ;
2206
				COPY_dspec(id_storage(id), ds);
2029
		    return ( id ) ;
2207
				return(id);
2030
		}
2208
			}
2031
		break ;
2209
			break;
2032
	    }
2210
		}
2033
	}
2211
		}
2034
	err = ERR_pragma_preserve_undecl ( lex_weak, id ) ;
2212
		err = ERR_pragma_preserve_undecl(lex_weak, id);
2035
	report ( preproc_loc, err ) ;
2213
		report(preproc_loc, err);
2036
    }
2214
	}
2037
    return ( NULL_id ) ;
2215
	return(NULL_id);
2038
}
2216
}
2039
 
2217
 
2040
 
2218
 
2041
/*
2219
/*
2042
    READ A PRAGMA WEAK DIRECTIVE
2220
    READ A PRAGMA WEAK DIRECTIVE
2043
 
2221
 
2044
    This routine processes a '#pragma weak' directive.
2222
    This routine processes a '#pragma weak' directive.
2045
*/
2223
*/
2046
 
2224
 
2047
void read_weak
2225
void
2048
    PROTO_N ( ( dir ) )
-
 
2049
    PROTO_T ( int dir )
2226
read_weak(int dir)
2050
{
2227
{
2051
    IDENTIFIER id = NULL_id ;
2228
	IDENTIFIER id = NULL_id;
2052
    IDENTIFIER aid = NULL_id ;
2229
	IDENTIFIER aid = NULL_id;
2053
    int t = read_token () ;
2230
	int t = read_token();
2054
    update_column () ;
2231
	update_column();
-
 
2232
	if (in_preproc_dir) {
2055
    if ( in_preproc_dir ) preproc_loc = crt_loc ;
2233
		preproc_loc = crt_loc;
-
 
2234
	}
2056
    if ( t == lex_identifier ) {
2235
	if (t == lex_identifier) {
2057
	id = find_weak_id ( token_hashid ) ;
2236
		id = find_weak_id(token_hashid);
2058
	t = read_token () ;
2237
		t = read_token();
2059
	update_column () ;
2238
		update_column();
-
 
2239
		if (in_preproc_dir) {
2060
	if ( in_preproc_dir ) preproc_loc = crt_loc ;
2240
			preproc_loc = crt_loc;
-
 
2241
		}
2061
	if ( t == lex_assign ) {
2242
		if (t == lex_assign) {
2062
	    t = read_token () ;
2243
			t = read_token();
2063
	    update_column () ;
2244
			update_column();
-
 
2245
			if (in_preproc_dir) {
2064
	    if ( in_preproc_dir ) preproc_loc = crt_loc ;
2246
				preproc_loc = crt_loc;
-
 
2247
			}
2065
	    if ( t == lex_identifier ) {
2248
			if (t == lex_identifier) {
2066
		aid = find_weak_id ( token_hashid ) ;
2249
				aid = find_weak_id(token_hashid);
2067
		t = read_token () ;
2250
				t = read_token();
2068
		update_column () ;
2251
				update_column();
2069
		if ( in_preproc_dir ) preproc_loc = crt_loc ;
2252
				if (in_preproc_dir)preproc_loc = crt_loc;
-
 
2253
			}
-
 
2254
		}
-
 
2255
	} else {
-
 
2256
		t = lex_unknown;
-
 
2257
	}
-
 
2258
	if (!IS_NULL_id(aid)) {
-
 
2259
		static LIST(IDENTIFIER)weak_ids = NULL_list(IDENTIFIER);
-
 
2260
		LIST(IDENTIFIER)p = weak_ids;
-
 
2261
		while (!IS_NULL_list(p)) {
-
 
2262
			IDENTIFIER pid = DEREF_id(HEAD_list(p));
-
 
2263
			if (EQ_id(id, pid)) {
-
 
2264
				report(preproc_loc, ERR_pragma_weak_redef(id));
-
 
2265
				id = NULL_id;
-
 
2266
				break;
2070
	    }
2267
			}
-
 
2268
			p = TAIL_list(p);
-
 
2269
		}
-
 
2270
		if (!IS_NULL_id(id)) {
-
 
2271
			CONS_id(id, weak_ids, weak_ids);
-
 
2272
		}
2071
	}
2273
	}
2072
    } else {
-
 
2073
	t = lex_unknown ;
2274
	compile_weak(id, aid);
2074
    }
-
 
2075
    if ( !IS_NULL_id ( aid ) ) {
2275
	if (t != lex_newline) {
2076
	static LIST ( IDENTIFIER ) weak_ids = NULL_list ( IDENTIFIER ) ;
-
 
2077
	LIST ( IDENTIFIER ) p = weak_ids ;
-
 
2078
	while ( !IS_NULL_list ( p ) ) {
-
 
2079
	    IDENTIFIER pid = DEREF_id ( HEAD_list ( p ) ) ;
-
 
2080
	    if ( EQ_id ( id, pid ) ) {
-
 
2081
		report ( preproc_loc, ERR_pragma_weak_redef ( id ) ) ;
2276
		report(preproc_loc, ERR_cpp_end(dir));
2082
		id = NULL_id ;
-
 
2083
		break ;
-
 
2084
	    }
-
 
2085
	    p = TAIL_list ( p ) ;
-
 
2086
	}
2277
	}
2087
	if ( !IS_NULL_id ( id ) ) {
2278
	if (in_preproc_dir) {
2088
	    CONS_id ( id, weak_ids, weak_ids ) ;
2279
		IGNORE skip_to_end();
2089
	}
2280
	}
2090
    }
-
 
2091
    compile_weak ( id, aid ) ;
-
 
2092
    if ( t != lex_newline ) {
-
 
2093
	report ( preproc_loc, ERR_cpp_end ( dir ) ) ;
-
 
2094
    }
-
 
2095
    if ( in_preproc_dir ) IGNORE skip_to_end () ;
-
 
2096
    return ;
2281
	return;
2097
}
2282
}
2098
 
2283
 
2099
 
2284
 
2100
/*
2285
/*
2101
    READ A PREPROCESSING DIRECTIVE
2286
    READ A PREPROCESSING DIRECTIVE
Line 2111... Line 2296...
2111
    that these are all less than zero).  Other directives (for example,
2296
    that these are all less than zero).  Other directives (for example,
2112
    target dependent conditionals) do communicate with the main
2297
    target dependent conditionals) do communicate with the main
2113
    processor by returning a valid lexical token value.
2298
    processor by returning a valid lexical token value.
2114
*/
2299
*/
2115
 
2300
 
2116
int read_preproc_dir
2301
int
2117
    PROTO_N ( ( act, prev ) )
-
 
2118
    PROTO_T ( int act X int prev )
2302
read_preproc_dir(int act, int prev)
2119
{
2303
{
2120
    int t ;
2304
	int t;
2121
    ERROR err ;
2305
	ERROR err;
2122
    HASHID dir ;
2306
	HASHID dir;
2123
    int pp = lex_ignore_token ;
2307
	int pp = lex_ignore_token;
2124
    in_preproc_dir = 1 ;
2308
	in_preproc_dir = 1;
2125
    preproc_loc = crt_loc ;
2309
	preproc_loc = crt_loc;
2126
 
2310
 
2245
	}
2518
	}
2246
 
2519
 
2247
	case lex_assert : {
2520
	case lex_warning: {
2248
	    /* Deal with '#assert' (extension) */
2521
		/* Deal with '#warning' (extension) */
2249
	    OPTION opt = option ( OPT_ppdir_assert ) ;
2522
		OPTION opt = option(OPT_ppdir_warning);
2250
	    if ( opt != OPTION_DISALLOW ) {
2523
		if (opt != OPTION_DISALLOW) {
2251
		if ( opt != OPTION_ALLOW ) {
2524
			if (opt != OPTION_ALLOW) {
2252
		    err = ERR_pragma_cpp_known ( t ) ;
2525
				err = ERR_pragma_cpp_known(t);
2253
		    err = set_severity ( err, OPT_ppdir_assert, 0 ) ;
2526
				err = set_severity(err, OPT_ppdir_warning, 0);
2254
		    report ( preproc_loc, err ) ;
2527
				report(preproc_loc, err);
2255
		}
2528
			}
2256
		if ( act && !option ( OPT_ppdir_assert_ignore ) ) {
2529
			if (act && !option(OPT_ppdir_warning_ignore)) {
2257
		    read_assert ( t ) ;
2530
				read_error(OPT_warning);
-
 
2531
			}
-
 
2532
			goto end_label;
2258
		}
2533
		}
2259
		goto end_label ;
-
 
2260
	    }
-
 
2261
	    break ;
2534
		break;
2262
	}
2535
	}
2263
 
2536
 
2264
	case lex_file : {
2537
	case lex_weak: {
2265
	    /* Deal with '#file' (extension) */
2538
		/* Deal with '#weak' (extension) */
2266
	    OPTION opt = option ( OPT_ppdir_file ) ;
2539
		OPTION opt = option(OPT_ppdir_weak);
2267
	    if ( opt != OPTION_DISALLOW ) {
2540
		if (opt != OPTION_DISALLOW) {
2268
		if ( opt != OPTION_ALLOW ) {
2541
			if (opt != OPTION_ALLOW) {
2269
		    err = ERR_pragma_cpp_known ( t ) ;
2542
				err = ERR_pragma_cpp_known(t);
2270
		    err = set_severity ( err, OPT_ppdir_file, 0 ) ;
2543
				err = set_severity(err, OPT_ppdir_weak, 0);
2271
		    report ( preproc_loc, err ) ;
2544
				report(preproc_loc, err);
-
 
2545
			}
-
 
2546
			if (act && !option(OPT_ppdir_weak_ignore)) {
-
 
2547
				read_weak(t);
-
 
2548
			}
-
 
2549
			goto end_label;
2272
		}
2550
		}
2273
		if ( act && !option ( OPT_ppdir_file_ignore ) ) {
-
 
2274
		    read_location ( t ) ;
-
 
2275
		}
-
 
2276
		goto end_label ;
-
 
2277
	    }
-
 
2278
	    break ;
2551
		break;
2279
	}
2552
	}
2280
 
-
 
2281
	case lex_ident : {
-
 
2282
	    /* Deal with '#ident' (extension) */
-
 
2283
	    OPTION opt = option ( OPT_ppdir_ident ) ;
-
 
2284
	    if ( opt != OPTION_DISALLOW ) {
-
 
2285
		if ( opt != OPTION_ALLOW ) {
-
 
2286
		    err = ERR_pragma_cpp_known ( t ) ;
-
 
2287
		    err = set_severity ( err, OPT_ppdir_ident, 0 ) ;
-
 
2288
		    report ( preproc_loc, err ) ;
-
 
2289
		}
-
 
2290
		if ( act && !option ( OPT_ppdir_ident_ignore ) ) {
-
 
2291
		    read_ident ( t ) ;
-
 
2292
		}
-
 
2293
		goto end_label ;
-
 
2294
	    }
-
 
2295
	    break ;
-
 
2296
	}
2553
	}
2297
 
2554
 
2298
	case lex_import :
-
 
2299
	case lex_include_Hnext : {
-
 
2300
	    /* Deal with '#import' and '#include_next' (extension) */
-
 
2301
	    OPTION opt = option ( OPT_ppdir_import ) ;
-
 
2302
	    if ( opt != OPTION_DISALLOW ) {
-
 
2303
		if ( opt != OPTION_ALLOW ) {
-
 
2304
		    err = ERR_pragma_cpp_known ( t ) ;
-
 
2305
		    err = set_severity ( err, OPT_ppdir_import, 0 ) ;
-
 
2306
		    report ( preproc_loc, err ) ;
2555
	/* Unknown directives */
2307
		}
-
 
2308
		if ( !option ( OPT_ppdir_import_ignore ) ) {
-
 
2309
		    pp = read_include ( act, t ) ;
-
 
2310
		    return ( pp ) ;
-
 
2311
		}
-
 
2312
		goto end_label ;
-
 
2313
	    }
-
 
2314
	    break ;
-
 
2315
	}
-
 
2316
 
-
 
2317
	case lex_unassert : {
-
 
2318
	    /* Deal with '#unassert' (extension) */
-
 
2319
	    OPTION opt = option ( OPT_ppdir_unassert ) ;
-
 
2320
	    if ( opt != OPTION_DISALLOW ) {
-
 
2321
		if ( opt != OPTION_ALLOW ) {
-
 
2322
		    err = ERR_pragma_cpp_known ( t ) ;
-
 
2323
		    err = set_severity ( err, OPT_ppdir_unassert, 0 ) ;
-
 
2324
		    report ( preproc_loc, err ) ;
2556
	report(preproc_loc, ERR_cpp_unknown(dir));
2325
		}
-
 
2326
		if ( act && !option ( OPT_ppdir_unassert_ignore ) ) {
-
 
2327
		    read_unassert ( t ) ;
-
 
2328
		}
-
 
2329
		goto end_label ;
2557
end_label:
2330
	    }
-
 
2331
	    break ;
-
 
2332
	}
-
 
2333
 
-
 
2334
	case lex_warning : {
-
 
2335
	    /* Deal with '#warning' (extension) */
-
 
2336
	    OPTION opt = option ( OPT_ppdir_warning ) ;
-
 
2337
	    if ( opt != OPTION_DISALLOW ) {
-
 
2338
		if ( opt != OPTION_ALLOW ) {
-
 
2339
		    err = ERR_pragma_cpp_known ( t ) ;
-
 
2340
		    err = set_severity ( err, OPT_ppdir_warning, 0 ) ;
-
 
2341
		    report ( preproc_loc, err ) ;
2558
	if (in_preproc_dir) {
2342
		}
-
 
2343
		if ( act && !option ( OPT_ppdir_warning_ignore ) ) {
-
 
2344
		    read_error ( OPT_warning ) ;
-
 
2345
		}
-
 
2346
		goto end_label ;
2559
		IGNORE skip_to_end();
2347
	    }
-
 
2348
	    break ;
-
 
2349
	}
2560
	}
2350
 
-
 
2351
	case lex_weak : {
-
 
2352
	    /* Deal with '#weak' (extension) */
-
 
2353
	    OPTION opt = option ( OPT_ppdir_weak ) ;
-
 
2354
	    if ( opt != OPTION_DISALLOW ) {
-
 
2355
		if ( opt != OPTION_ALLOW ) {
-
 
2356
		    err = ERR_pragma_cpp_known ( t ) ;
-
 
2357
		    err = set_severity ( err, OPT_ppdir_weak, 0 ) ;
-
 
2358
		    report ( preproc_loc, err ) ;
-
 
2359
		}
-
 
2360
		if ( act && !option ( OPT_ppdir_weak_ignore ) ) {
-
 
2361
		    read_weak ( t ) ;
-
 
2362
		}
-
 
2363
		goto end_label ;
-
 
2364
	    }
-
 
2365
	    break ;
-
 
2366
	}
-
 
2367
    }
-
 
2368
 
-
 
2369
    /* Unknown directives */
-
 
2370
    report ( preproc_loc, ERR_cpp_unknown ( dir ) ) ;
-
 
2371
    end_label : {
-
 
2372
	if ( in_preproc_dir ) IGNORE skip_to_end () ;
-
 
2373
	return ( pp ) ;
2561
	return(pp);
2374
    }
-
 
2375
}
2562
}
2376
 
2563
 
2377
 
2564
 
2378
/*
2565
/*
2379
    PREPROCESS A FILE
2566
    PREPROCESS A FILE
Line 2381... Line 2568...
2381
    This routine gives the preprocessor entry point for the compiler.  Each
2568
    This routine gives the preprocessor entry point for the compiler.  Each
2382
    token is read, preprocessed, and printed.  The white space in the output
2569
    token is read, preprocessed, and printed.  The white space in the output
2383
    does not necessarily bear any resemblance to that in the input.
2570
    does not necessarily bear any resemblance to that in the input.
2384
*/
2571
*/
2385
 
2572
 
2386
void preprocess_file
2573
void
2387
    PROTO_Z ()
2574
preprocess_file(void)
2388
{
2575
{
2389
    int t ;
2576
	int t;
2390
    FILE *f ;
2577
	FILE *f;
2391
    string fn ;
2578
	string fn;
2392
    BUFFER *bf ;
2579
	BUFFER *bf;
2393
    unsigned long ws = 0 ;
2580
	unsigned long ws = 0;
2394
    unsigned long ln = 0 ;
2581
	unsigned long ln = 0;
2395
    int force_space = preproc_space ;
2582
	int force_space = preproc_space;
2396
    static BUFFER preproc_buff = { NULL, NULL, NULL, NULL } ;
2583
	static BUFFER preproc_buff = { NULL, NULL, NULL, NULL };
2397
 
-
 
2398
    /* Initialise input file */
-
 
2399
    init_lex () ;
-
 
2400
    fn = DEREF_string ( posn_file ( preproc_loc.posn ) ) ;
-
 
2401
 
-
 
2402
    /* Open output file */
-
 
2403
    if ( !open_output ( OUTPUT_PREPROC, text_mode ) ) {
-
 
2404
	string nm = output_name [ OUTPUT_PREPROC ] ;
-
 
2405
	fail ( ERR_fail_output ( nm ) ) ;
-
 
2406
	term_error ( 0 ) ;
-
 
2407
	return ;
-
 
2408
    }
-
 
2409
    f = output_file [ OUTPUT_PREPROC ] ;
-
 
2410
    bf = clear_buffer ( &preproc_buff, f ) ;
-
 
2411
    fprintf_v ( f, "#line 1 \"%s\"", strlit ( fn ) ) ;
-
 
2412
    crt_file_changed = 1 ;
-
 
2413
 
-
 
2414
    /* Scan through preprocessing tokens */
-
 
2415
    while ( t = expand_preproc ( EXPAND_NORMAL ), t != lex_eof ) {
-
 
2416
	/* Allow for skipped files */
-
 
2417
	if ( crt_file_type ) continue ;
-
 
2418
 
-
 
2419
	/* Replace keywords by underlying identifier */
-
 
2420
	if ( t >= FIRST_KEYWORD && t <= LAST_KEYWORD ) {
-
 
2421
	    crt_token->tok = lex_identifier ;
-
 
2422
	}
-
 
2423
	if ( t == lex_builtin_Hfile ) {
-
 
2424
	    fputc_v ( '\n', f ) ;
-
 
2425
	    ln++ ;
-
 
2426
	    crt_line_changed = 1 ;
-
 
2427
	    crt_spaces = 0 ;
-
 
2428
	    continue ;
-
 
2429
	}
-
 
2430
 
2584
 
2431
	/* Print any required '#line' directives */
2585
	/* Initialise input file */
2432
	if ( crt_line_changed ) {
2586
	init_lex();
-
 
2587
	fn = DEREF_string(posn_file(preproc_loc.posn));
-
 
2588
 
2433
	    int ch = crt_file_changed ;
2589
	/* Open output file */
-
 
2590
	if (!open_output(OUTPUT_PREPROC, text_mode)) {
2434
	    unsigned long n = crt_loc.line ;
2591
		string nm = output_name[OUTPUT_PREPROC];
2435
	    unsigned long sp = crt_spaces ;
2592
		fail(ERR_fail_output(nm));
-
 
2593
		term_error(0);
-
 
2594
		return;
-
 
2595
	}
2436
	    unsigned long tab = tab_width ;
2596
	f = output_file[OUTPUT_PREPROC];
2437
	    output_buffer ( bf, 0 ) ;
2597
	bf = clear_buffer(&preproc_buff, f);
-
 
2598
	fprintf_v(f, "#line 1 \"%s\"", strlit(fn));
2438
	    if ( ch ) {
2599
	crt_file_changed = 1;
-
 
2600
 
-
 
2601
	/* Scan through preprocessing tokens */
2439
		string fm = DEREF_string ( posn_file ( crt_loc.posn ) ) ;
2602
	while (t = expand_preproc(EXPAND_NORMAL), t != lex_eof) {
2440
		if ( ch > 1 || !ustreq ( fn, fm ) ) {
2603
		/* Allow for skipped files */
2441
		    char *s = strlit ( fm ) ;
2604
		if (crt_file_type) {
-
 
2605
			continue;
-
 
2606
		}
-
 
2607
 
2442
		    fprintf_v ( f, "\n\n#line %lu \"%s\"\n", n, s ) ;
2608
		/* Replace keywords by underlying identifier */
-
 
2609
		if (t >= FIRST_KEYWORD && t <= LAST_KEYWORD) {
-
 
2610
			crt_token->tok = lex_identifier;
-
 
2611
		}
-
 
2612
		if (t == lex_builtin_Hfile) {
-
 
2613
			fputc_v('\n', f);
-
 
2614
			ln++;
-
 
2615
			crt_line_changed = 1;
2443
		    fn = fm ;
2616
			crt_spaces = 0;
2444
		    ln = n ;
2617
			continue;
2445
		}
2618
		}
-
 
2619
 
-
 
2620
		/* Print any required '#line' directives */
-
 
2621
		if (crt_line_changed) {
-
 
2622
			int ch = crt_file_changed;
-
 
2623
			unsigned long n = crt_loc.line;
-
 
2624
			unsigned long sp = crt_spaces;
-
 
2625
			unsigned long tab = tab_width;
-
 
2626
			output_buffer(bf, 0);
-
 
2627
			if (ch) {
-
 
2628
				string fm =
-
 
2629
				    DEREF_string(posn_file(crt_loc.posn));
-
 
2630
				if (ch > 1 || !ustreq(fn, fm)) {
-
 
2631
					char *s = strlit(fm);
-
 
2632
					fprintf_v(f, "\n\n#line %lu \"%s\"\n",
-
 
2633
						  n, s);
-
 
2634
					fn = fm;
-
 
2635
					ln = n;
-
 
2636
				}
2446
		crt_file_changed = 0 ;
2637
				crt_file_changed = 0;
2447
	    }
2638
			}
2448
	    if ( n != ln ) {
2639
			if (n != ln) {
2449
		if ( n > ln && n <= ln + 10 ) {
2640
				if (n > ln && n <= ln + 10) {
2450
		    for ( ; ln < n ; ln++ ) fputc_v ( '\n', f ) ;
2641
					for (; ln < n; ln++) {
-
 
2642
						fputc_v('\n', f);
-
 
2643
					}
-
 
2644
				} else {
-
 
2645
					/* Force '#line' for more than 10 blank
-
 
2646
					 * lines */
-
 
2647
					fprintf_v(f, "\n\n#line %lu\n", n);
-
 
2648
				}
-
 
2649
				ln = n;
-
 
2650
			}
-
 
2651
			crt_line_changed = 0;
-
 
2652
 
-
 
2653
			/* Print indentation */
-
 
2654
			ws = sp;
-
 
2655
			for (; sp >= tab; sp -= tab) {
-
 
2656
				bfputc(bf, '\t');
-
 
2657
			}
-
 
2658
			for (; sp; sp--) {
-
 
2659
				bfputc(bf, ' ');
-
 
2660
			}
-
 
2661
 
-
 
2662
			/* Allow for hash symbols */
-
 
2663
			if (t == lex_hash_H1) {
-
 
2664
				crt_token->tok = lex_hash_Hhash_H1;
-
 
2665
			}
-
 
2666
			if (t == lex_hash_H2) {
-
 
2667
				crt_token->tok = lex_hash_Hhash_H2;
-
 
2668
			}
-
 
2669
 
2451
		} else {
2670
		} else {
2452
		    /* Force '#line' for more than 10 blank lines */
2671
			unsigned long sp = crt_spaces;
2453
		    fprintf_v ( f, "\n\n#line %lu\n", n ) ;
2672
			if (sp != ws || force_space) {
-
 
2673
				/* Print space */
-
 
2674
				ws = sp;
-
 
2675
				bfputc(bf, ' ');
-
 
2676
			}
2454
		}
2677
		}
2455
		ln = n ;
-
 
2456
	    }
-
 
2457
	    crt_line_changed = 0 ;
-
 
2458
 
2678
 
2459
	    /* Print indentation */
2679
		/* Print the token name */
2460
	    ws = sp ;
-
 
2461
	    for ( ; sp >= tab ; sp -= tab ) bfputc ( bf, '\t' ) ;
-
 
2462
	    for ( ; sp ; sp-- ) bfputc ( bf, ' ' ) ;
2680
		IGNORE print_pptok(crt_token, bf, 0);
2463
 
-
 
2464
	    /* Allow for hash symbols */
-
 
2465
	    if ( t == lex_hash_H1 ) crt_token->tok = lex_hash_Hhash_H1 ;
-
 
2466
	    if ( t == lex_hash_H2 ) crt_token->tok = lex_hash_Hhash_H2 ;
-
 
2467
 
-
 
2468
	} else {
-
 
2469
	    unsigned long sp = crt_spaces ;
-
 
2470
	    if ( sp != ws || force_space ) {
-
 
2471
		/* Print space */
-
 
2472
		ws = sp ;
-
 
2473
		bfputc ( bf, ' ' ) ;
-
 
2474
	    }
-
 
2475
	}
2681
	}
2476
 
-
 
2477
	/* Print the token name */
-
 
2478
	IGNORE print_pptok ( crt_token, bf, 0 ) ;
-
 
2479
    }
-
 
2480
    bfputc ( bf, '\n' ) ;
2682
	bfputc(bf, '\n');
2481
    output_buffer ( bf, 0 ) ;
2683
	output_buffer(bf, 0);
2482
    close_output ( OUTPUT_PREPROC ) ;
2684
	close_output(OUTPUT_PREPROC);
2483
    return ;
2685
	return;
2484
}
2686
}