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

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

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

Subversion Repositories tendra.SVN

Rev

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

Rev 5 Rev 6
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2006 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
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 62... Line 92...
62
    variables which are pending at any moment during the TDF generation.
92
    variables which are pending at any moment during the TDF generation.
63
    This includes such pseudo-destructors as for jump locations in
93
    This includes such pseudo-destructors as for jump locations in
64
    try blocks.
94
    try blocks.
65
*/
95
*/
66
 
96
 
67
unsigned long no_destructors = 0 ;
97
unsigned long no_destructors = 0;
68
 
98
 
69
 
99
 
70
/*
100
/*
71
    TDF STATEMENT ENCODING ROUTINES
101
    TDF STATEMENT ENCODING ROUTINES
72
 
102
 
Line 83... Line 113...
83
    ignoring trivial statements and expanding compound statements
113
    ignoring trivial statements and expanding compound statements
84
    recursively.  The result equals the number of statements added to
114
    recursively.  The result equals the number of statements added to
85
    the bitstream by enc_compound_stmt.
115
    the bitstream by enc_compound_stmt.
86
*/
116
*/
87
 
117
 
88
unsigned stmt_length
118
unsigned
89
    PROTO_N ( ( e ) )
-
 
90
    PROTO_T ( EXP e )
119
stmt_length(EXP e)
91
{
120
{
92
    if ( !IS_NULL_exp ( e ) ) {
121
	if (!IS_NULL_exp(e)) {
93
	switch ( TAG_exp ( e ) ) {
122
		switch (TAG_exp(e)) {
94
	    case exp_sequence_tag : {
123
		case exp_sequence_tag: {
95
		/* Compound statements */
124
			/* Compound statements */
96
		unsigned n = 0 ;
125
			unsigned n = 0;
97
		LIST ( EXP ) p = DEREF_list ( exp_sequence_first ( e ) ) ;
126
			LIST(EXP)p = DEREF_list(exp_sequence_first(e));
98
		while ( !IS_NULL_list ( p ) ) {
127
			while (!IS_NULL_list(p)) {
99
		    EXP a = DEREF_exp ( HEAD_list ( p ) ) ;
128
				EXP a = DEREF_exp(HEAD_list(p));
100
		    if ( !IS_NULL_exp ( a ) ) {
129
				if (!IS_NULL_exp(a)) {
101
			n += stmt_length ( a ) ;
130
					n += stmt_length(a);
102
		    }
131
				}
103
		    p = TAIL_list ( p ) ;
132
				p = TAIL_list(p);
104
		}
133
			}
105
		return ( n ) ;
134
			return (n);
106
	    }
135
		}
107
	    case exp_location_tag : {
136
		case exp_location_tag: {
108
		/* Location statements */
137
			/* Location statements */
109
		EXP a = DEREF_exp ( exp_location_arg ( e ) ) ;
138
			EXP a = DEREF_exp(exp_location_arg(e));
110
		if ( !IS_NULL_exp ( a ) ) {
139
			if (!IS_NULL_exp(a)) {
111
		    if ( is_diag_stmt ( a ) ) return ( 1 ) ;
140
				if (is_diag_stmt(a)) {
-
 
141
					return (1);
-
 
142
				}
112
		    return ( stmt_length ( a ) ) ;
143
				return (stmt_length(a));
-
 
144
			}
-
 
145
			break;
-
 
146
		}
-
 
147
		case exp_reach_tag:
-
 
148
		case exp_unreach_tag: {
-
 
149
			/* Flow control statement */
-
 
150
			EXP a = DEREF_exp(exp_reach_etc_body(e));
-
 
151
			return (stmt_length(a));
-
 
152
		}
-
 
153
		case exp_set_tag:
-
 
154
		case exp_unused_tag: {
-
 
155
			/* Variable flow statements */
-
 
156
			break;
-
 
157
		}
-
 
158
		default : {
-
 
159
			/* Other statements */
-
 
160
			return (1);
-
 
161
		}
113
		}
162
		}
114
		break ;
-
 
115
	    }
-
 
116
	    case exp_reach_tag :
-
 
117
	    case exp_unreach_tag : {
-
 
118
		/* Flow control statement */
-
 
119
		EXP a = DEREF_exp ( exp_reach_etc_body ( e ) ) ;
-
 
120
		return ( stmt_length ( a ) ) ;
-
 
121
	    }
-
 
122
	    case exp_set_tag :
-
 
123
	    case exp_unused_tag : {
-
 
124
		/* Variable flow statements */
-
 
125
		break ;
-
 
126
	    }
-
 
127
	    default : {
-
 
128
		/* Other statements */
-
 
129
		return ( 1 ) ;
-
 
130
	    }
-
 
131
	}
163
	}
132
    }
-
 
133
    return ( 0 ) ;
164
	return (0);
134
}
165
}
135
 
166
 
136
 
167
 
137
/*
168
/*
138
    ENCODE A COMPOUND STATEMENT
169
    ENCODE A COMPOUND STATEMENT
139
 
170
 
140
    This routine adds the statement e to the bitstream bs, ignoring
171
    This routine adds the statement e to the bitstream bs, ignoring
141
    trivial statements and expanding compound statements recursively.
172
    trivial statements and expanding compound statements recursively.
142
*/
173
*/
143
 
174
 
144
BITSTREAM *enc_compound_stmt
175
BITSTREAM *
145
    PROTO_N ( ( bs, e ) )
-
 
146
    PROTO_T ( BITSTREAM *bs X EXP e )
176
enc_compound_stmt(BITSTREAM *bs, EXP e)
147
{
177
{
148
    if ( !IS_NULL_exp ( e ) ) {
178
	if (!IS_NULL_exp(e)) {
149
	switch ( TAG_exp ( e ) ) {
179
		switch (TAG_exp(e)) {
150
	    case exp_sequence_tag : {
180
		case exp_sequence_tag: {
151
		/* Compound statements */
181
			/* Compound statements */
152
		LIST ( EXP ) p = DEREF_list ( exp_sequence_first ( e ) ) ;
182
			LIST(EXP)p = DEREF_list(exp_sequence_first(e));
153
		while ( !IS_NULL_list ( p ) ) {
183
			while (!IS_NULL_list(p)) {
154
		    EXP a = DEREF_exp ( HEAD_list ( p ) ) ;
184
				EXP a = DEREF_exp(HEAD_list(p));
155
		    if ( !IS_NULL_exp ( a ) ) {
185
				if (!IS_NULL_exp(a)) {
156
			bs = enc_compound_stmt ( bs, a ) ;
186
					bs = enc_compound_stmt(bs, a);
157
		    }
187
				}
158
		    p = TAIL_list ( p ) ;
188
				p = TAIL_list(p);
159
		}
189
			}
160
		break ;
190
			break;
161
	    }
191
		}
162
	    case exp_location_tag : {
192
		case exp_location_tag: {
163
		/* Location statements */
193
			/* Location statements */
164
		EXP a = DEREF_exp ( exp_location_arg ( e ) ) ;
194
			EXP a = DEREF_exp(exp_location_arg(e));
165
		if ( !IS_NULL_exp ( a ) ) {
195
			if (!IS_NULL_exp(a)) {
166
		    if ( is_diag_stmt ( a ) ) {
196
				if (is_diag_stmt(a)) {
167
			BITSTREAM *ts = enc_diag_begin ( &bs ) ;
197
					BITSTREAM *ts = enc_diag_begin(&bs);
168
			ts = enc_stmt ( ts, a ) ;
198
					ts = enc_stmt(ts, a);
169
			bs = enc_diag_end ( bs, ts, a, 1 ) ;
199
					bs = enc_diag_end(bs, ts, a, 1);
170
		    } else {
200
				} else {
171
			bs = enc_compound_stmt ( bs, a ) ;
201
					bs = enc_compound_stmt(bs, a);
172
		    }
202
				}
173
		}
203
			}
174
		crt_enc_loc = exp_location_end ( e ) ;
204
			crt_enc_loc = exp_location_end(e);
175
		break ;
205
			break;
176
	    }
206
		}
177
	    case exp_reach_tag :
207
		case exp_reach_tag:
178
	    case exp_unreach_tag : {
208
		case exp_unreach_tag: {
179
		/* Flow control statement */
209
			/* Flow control statement */
180
		EXP a = DEREF_exp ( exp_reach_etc_body ( e ) ) ;
210
			EXP a = DEREF_exp(exp_reach_etc_body(e));
181
		bs = enc_compound_stmt ( bs, a ) ;
211
			bs = enc_compound_stmt(bs, a);
182
		break ;
212
			break;
183
	    }
213
		}
184
	    case exp_set_tag :
214
		case exp_set_tag:
185
	    case exp_unused_tag : {
215
		case exp_unused_tag: {
186
		/* Variable flow statements */
216
			/* Variable flow statements */
187
		break ;
217
			break;
188
	    }
218
		}
189
	    default : {
219
		default: {
190
		/* Other statements */
220
			/* Other statements */
191
		bs = enc_stmt ( bs, e ) ;
221
			bs = enc_stmt(bs, e);
192
		break ;
222
			break;
-
 
223
		}
193
	    }
224
		}
194
	}
225
	}
195
    }
-
 
196
    return ( bs ) ;
226
	return (bs);
197
}
227
}
198
 
228
 
199
 
229
 
200
/*
230
/*
201
    ENCODE A LIST OF DESTRUCTORS
231
    ENCODE A LIST OF DESTRUCTORS
202
 
232
 
203
    This routine adds all the destructors and pseudo-destructors called
233
    This routine adds all the destructors and pseudo-destructors called
204
    by a jump from e to d to the bitstream bs.
234
    by a jump from e to d to the bitstream bs.
205
*/
235
*/
206
 
236
 
207
static BITSTREAM *enc_destructors
237
static BITSTREAM *
208
    PROTO_N ( ( bs, e, d ) )
-
 
209
    PROTO_T ( BITSTREAM *bs X EXP e X EXP d )
238
enc_destructors(BITSTREAM *bs, EXP e, EXP d)
210
{
239
{
211
    unsigned long m = no_destructors ;
240
	unsigned long m = no_destructors;
212
    if ( m && !unreached_code ) {
241
	if (m && !unreached_code) {
213
	unsigned long n = 0 ;
242
		unsigned long n = 0;
214
	unsigned long extra = 0 ;
243
		unsigned long extra = 0;
215
#if LANGUAGE_CPP
244
#if LANGUAGE_CPP
216
	unsigned ptag = null_tag ;
245
		unsigned ptag = null_tag;
217
#endif
246
#endif
218
	BITSTREAM *ts = start_bitstream ( NIL ( FILE ), bs->link ) ;
247
		BITSTREAM *ts = start_bitstream(NIL(FILE), bs->link);
219
	while ( !EQ_exp ( e, d ) && !IS_NULL_exp ( e ) && n < m ) {
248
		while (!EQ_exp(e, d) && !IS_NULL_exp(e) && n < m) {
220
	    unsigned tag = TAG_exp ( e ) ;
249
			unsigned tag = TAG_exp(e);
221
	    if ( tag == exp_decl_stmt_tag ) {
250
			if (tag == exp_decl_stmt_tag) {
222
		/* Jump out of variable scope */
251
				/* Jump out of variable scope */
223
		IDENTIFIER id = DEREF_id ( exp_decl_stmt_id ( e ) ) ;
252
				IDENTIFIER id = DEREF_id(exp_decl_stmt_id(e));
224
		DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
253
				DECL_SPEC ds = DEREF_dspec(id_storage(id));
225
		if ( ds & dspec_auto ) {
254
				if (ds & dspec_auto) {
226
		    EXP a = DEREF_exp ( id_variable_term ( id ) ) ;
255
					EXP a = DEREF_exp(id_variable_term(id));
227
		    if ( !IS_NULL_exp ( a ) ) {
256
					if (!IS_NULL_exp(a)) {
228
			/* Destructor found */
257
						/* Destructor found */
229
			ulong v ;
258
						ulong v;
230
			int var = 1 ;
259
						int var = 1;
231
			TYPE t = DEREF_type ( id_variable_type ( id ) ) ;
260
						TYPE t = DEREF_type(id_variable_type(id));
232
			if ( ds & dspec_explicit ) {
261
						if (ds & dspec_explicit) {
233
			    if ( ds & dspec_temp ) var = 4 ;
262
							if (ds & dspec_temp) {
-
 
263
								var = 4;
-
 
264
							}
-
 
265
						}
-
 
266
						v = unit_no(ts, id, VAR_tag, 0);
-
 
267
						ts = enc_term_local(ts, v,
-
 
268
								    NULL_off,
-
 
269
								    0, t, a,
-
 
270
								    var);
-
 
271
						extra++;
-
 
272
						n++;
-
 
273
					}
-
 
274
				}
234
			}
275
			}
-
 
276
#if LANGUAGE_CPP
-
 
277
			/* ... continued */
-
 
278
			else if (tag == exp_try_block_tag) {
-
 
279
				/* Jump out of try block */
235
			v = unit_no ( ts, id, VAR_tag, 0 ) ;
280
				if (ptag != exp_handler_tag) {
-
 
281
					ulong ex =
-
 
282
					    DEREF_ulong(exp_try_block_no(e));
236
			ts = enc_term_local ( ts, v, NULL_off, 0, t, a, var ) ;
283
					ts = enc_try_end(ts, ex);
237
			extra++ ;
284
					n++;
-
 
285
				}
-
 
286
			} else if (tag == exp_handler_tag) {
-
 
287
				/* Jump out of exception handler */
-
 
288
				ts = enc_special(ts, TOK_except_end);
238
			n++ ;
289
				n++;
239
		    }
290
			}
-
 
291
			ptag = tag;
-
 
292
#endif
-
 
293
			e = get_parent_stmt(e);
240
		}
294
		}
241
	    }
295
 
-
 
296
		/* Check for exception specifications */
242
#if LANGUAGE_CPP
297
#if LANGUAGE_CPP
243
	    /* ... continued */ else if ( tag == exp_try_block_tag ) {
298
		if (IS_NULL_exp(e) && n < m && in_exception_spec) {
244
		/* Jump out of try block */
-
 
245
		if ( ptag != exp_handler_tag ) {
-
 
246
		    ulong ex = DEREF_ulong ( exp_try_block_no ( e ) ) ;
-
 
247
		    ts = enc_try_end ( ts, ex ) ;
299
			ts = enc_try_end(ts, last_params[DUMMY_catch]);
248
		    n++ ;
300
			n++;
249
		}
301
		}
250
	    } else if ( tag == exp_handler_tag ) {
-
 
251
		/* Jump out of exception handler */
-
 
252
		ts = enc_special ( ts, TOK_except_end ) ;
-
 
253
		n++ ;
-
 
254
	    }
-
 
255
	    ptag = tag ;
-
 
256
#endif
302
#endif
257
	    e = get_parent_stmt ( e ) ;
-
 
258
	}
-
 
259
 
303
 
260
	/* Check for exception specifications */
304
		/* Add destructors to main list */
261
#if LANGUAGE_CPP
305
		if (n) {
262
	if ( IS_NULL_exp ( e ) && n < m && in_exception_spec ) {
306
			ENC_SEQUENCE(bs, n + extra);
-
 
307
		}
263
	    ts = enc_try_end ( ts, last_params [ DUMMY_catch ] ) ;
308
		bs = join_bitstreams(bs, ts);
264
	    n++ ;
-
 
265
	}
309
	}
266
#endif
-
 
267
 
-
 
268
	/* Add destructors to main list */
-
 
269
	if ( n ) ENC_SEQUENCE ( bs, n + extra ) ;
-
 
270
	bs = join_bitstreams ( bs, ts ) ;
-
 
271
    }
-
 
272
    return ( bs ) ;
310
	return (bs);
273
}
311
}
274
 
312
 
275
 
313
 
276
/*
314
/*
277
    ENCODE THE DESTRUCTOR FOR A CONDITION DECLARATION
315
    ENCODE THE DESTRUCTOR FOR A CONDITION DECLARATION
Line 280... Line 318...
280
    then this destructor needs to be called at the completion of the
318
    then this destructor needs to be called at the completion of the
281
    loop (this is the normal end-of-scope destructor) and just before
319
    loop (this is the normal end-of-scope destructor) and just before
282
    the second and subsequent evaluations of the condition.  This
320
    the second and subsequent evaluations of the condition.  This
283
    routine adds the latter such destructors for the variable ids to
321
    routine adds the latter such destructors for the variable ids to
284
    the bitstream bs
322
    the bitstream bs
285
*/
323
*/
286
 
324
 
287
static BITSTREAM *enc_while_destr
325
static BITSTREAM *
288
    PROTO_N ( ( bs, ids ) )
-
 
289
    PROTO_T ( BITSTREAM *bs X LIST ( IDENTIFIER ) ids )
326
enc_while_destr(BITSTREAM *bs, LIST(IDENTIFIER)ids)
290
{
327
{
291
    while ( !IS_NULL_list ( ids ) ) {
328
	while (!IS_NULL_list(ids)) {
292
	IDENTIFIER id = DEREF_id ( HEAD_list ( ids ) ) ;
329
		IDENTIFIER id = DEREF_id(HEAD_list(ids));
293
	EXP d = DEREF_exp ( id_variable_term ( id ) ) ;
330
		EXP d = DEREF_exp(id_variable_term(id));
294
	if ( !IS_NULL_exp ( d ) ) {
331
		if (!IS_NULL_exp(d)) {
295
	    int var = 1 ;
332
			int var = 1;
296
	    DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
333
			DECL_SPEC ds = DEREF_dspec(id_storage(id));
297
	    TYPE t = DEREF_type ( id_variable_type ( id ) ) ;
334
			TYPE t = DEREF_type(id_variable_type(id));
298
	    ulong n = unit_no ( bs, id, VAR_tag, 0 ) ;
335
			ulong n = unit_no(bs, id, VAR_tag, 0);
299
	    ENC_SEQ_SMALL ( bs, 2 ) ;
336
			ENC_SEQ_SMALL(bs, 2);
300
	    if ( ( ds & dspec_explicit ) && ( ds & dspec_temp ) ) {
337
			if ((ds & dspec_explicit) && (ds & dspec_temp)) {
301
		var = 4 ;
338
				var = 4;
302
	    }
339
			}
303
	    bs = enc_term_local ( bs, n, NULL_off, 0, t, d, var ) ;
340
			bs = enc_term_local(bs, n, NULL_off, 0, t, d, var);
304
	}
341
		}
305
	ids = TAIL_list ( ids ) ;
342
		ids = TAIL_list(ids);
306
    }
343
	}
307
    return ( bs ) ;
344
	return (bs);
308
}
345
}
309
 
346
 
310
 
347
 
311
/*
348
/*
312
    ENCODE A LABELLED STATEMENT
349
    ENCODE A LABELLED STATEMENT
313
 
350
 
314
    This routine adds the labelled statement 'e' to the bitstream bs.
351
    This routine adds the labelled statement 'e' to the bitstream bs.
315
*/
352
*/
316
 
353
 
317
static BITSTREAM *enc_label_stmt
354
static BITSTREAM *
318
    PROTO_N ( ( bs, e ) )
-
 
319
    PROTO_T ( BITSTREAM *bs X EXP e )
355
enc_label_stmt(BITSTREAM *bs, EXP e)
320
{
356
{
321
    EXP a = DEREF_exp ( exp_label_stmt_body ( e ) ) ;
357
	EXP a = DEREF_exp(exp_label_stmt_body(e));
322
    IDENTIFIER lab = DEREF_id ( exp_label_stmt_label ( e ) ) ;
358
	IDENTIFIER lab = DEREF_id(exp_label_stmt_label(e));
323
    IDENTIFIER flab = DEREF_id ( id_alias ( lab ) ) ;
359
	IDENTIFIER flab = DEREF_id(id_alias(lab));
324
    if ( EQ_id ( lab, flab ) ) {
360
	if (EQ_id(lab, flab)) {
325
	/* Simple label */
361
		/* Simple label */
326
	ulong n = DEREF_ulong ( id_no ( flab ) ) ;
362
		ulong n = DEREF_ulong(id_no(flab));
327
	if ( n == LINK_NONE ) {
363
		if (n == LINK_NONE) {
328
	    /* Label not previously output */
364
			/* Label not previously output */
329
	    DECL_SPEC info = DEREF_dspec ( id_storage ( flab ) ) ;
365
			DECL_SPEC info = DEREF_dspec(id_storage(flab));
330
	    if ( info & dspec_used ) {
366
			if (info & dspec_used) {
331
		n = unit_no ( bs, flab, VAR_label, 1 ) ;
367
				n = unit_no(bs, flab, VAR_label, 1);
332
		ENC_repeat ( bs ) ;
368
				ENC_repeat(bs);
333
		ENC_make_label ( bs, n ) ;
369
				ENC_make_label(bs, n);
334
		ENC_make_top ( bs ) ;
370
				ENC_make_top(bs);
335
		unreached_code = 0 ;
371
				unreached_code = 0;
336
		bs = enc_stmt ( bs, a ) ;
372
				bs = enc_stmt(bs, a);
337
		clear_no ( flab ) ;
373
				clear_no(flab);
338
	    } else {
374
			} else {
339
		bs = enc_stmt ( bs, a ) ;
375
				bs = enc_stmt(bs, a);
340
	    }
376
			}
-
 
377
		} else {
-
 
378
			/* Label body output separately */
-
 
379
			ENC_goto(bs);
-
 
380
			ENC_make_label(bs, n);
-
 
381
			unreached_code = 1;
-
 
382
		}
341
	} else {
383
	} else {
342
	    /* Label body output separately */
-
 
343
	    ENC_goto ( bs ) ;
-
 
344
	    ENC_make_label ( bs, n ) ;
-
 
345
	    unreached_code = 1 ;
-
 
346
	}
-
 
347
    } else {
-
 
348
	/* Label alias */
384
		/* Label alias */
349
	bs = enc_stmt ( bs, a ) ;
385
		bs = enc_stmt(bs, a);
350
    }
386
	}
351
    return ( bs ) ;
387
	return (bs);
352
}
388
}
353
 
389
 
354
 
390
 
355
/*
391
/*
356
    ADD A LABEL TO A LIST
392
    ADD A LABEL TO A LIST
357
 
393
 
358
    This routine adds the label lab to the list q if it has not been
394
    This routine adds the label lab to the list q if it has not been
359
    output in bitstream bs and is not already a member of the list.
395
    output in bitstream bs and is not already a member of the list.
360
*/
396
*/
361
 
397
 
362
static LIST ( IDENTIFIER ) add_label
398
static LIST(IDENTIFIER)
363
    PROTO_N ( ( bs, lab, q ) )
-
 
364
    PROTO_T ( BITSTREAM *bs X IDENTIFIER lab X LIST ( IDENTIFIER ) q )
399
add_label(BITSTREAM *bs, IDENTIFIER lab, LIST(IDENTIFIER)q)
365
{
400
{
366
    if ( !IS_NULL_id ( lab ) ) {
401
	if (!IS_NULL_id(lab)) {
367
	IDENTIFIER flab = DEREF_id ( id_alias ( lab ) ) ;
402
		IDENTIFIER flab = DEREF_id(id_alias(lab));
368
	ulong n = DEREF_ulong ( id_no ( flab ) ) ;
403
		ulong n = DEREF_ulong(id_no(flab));
369
	if ( n == LINK_NONE ) {
404
		if (n == LINK_NONE) {
370
	    /* Not previously output */
405
			/* Not previously output */
371
	    IGNORE unit_no ( bs, flab, VAR_label, 1 ) ;
406
			IGNORE unit_no(bs, flab, VAR_label, 1);
372
	    CONS_id ( flab, q, q ) ;
407
			CONS_id(flab, q, q);
373
	}
408
		}
374
    }
409
	}
375
    return ( q ) ;
410
	return (q);
376
}
411
}
377
 
412
 
378
 
413
 
379
/*
414
/*
380
    ADD A NUMBER OF LABELS TO A LIST
415
    ADD A NUMBER OF LABELS TO A LIST
381
 
416
 
382
    This routine adds the those labels in the list p which have not been
417
    This routine adds the those labels in the list p which have not been
383
    output in bitstream bs to the list q.
418
    output in bitstream bs to the list q.
384
*/
419
*/
385
 
420
 
386
static LIST ( IDENTIFIER ) add_labels
421
static LIST(IDENTIFIER)
387
    PROTO_N ( ( bs, p, q ) )
-
 
388
    PROTO_T ( BITSTREAM *bs X LIST ( IDENTIFIER ) p X LIST ( IDENTIFIER ) q )
422
add_labels(BITSTREAM *bs, LIST(IDENTIFIER)p, LIST(IDENTIFIER)q)
389
{
423
{
390
    while ( !IS_NULL_list ( p ) ) {
424
	while (!IS_NULL_list(p)) {
391
	IDENTIFIER lab = DEREF_id ( HEAD_list ( p ) ) ;
425
		IDENTIFIER lab = DEREF_id(HEAD_list(p));
392
	q = add_label ( bs, lab, q ) ;
426
		q = add_label(bs, lab, q);
393
	p = TAIL_list ( p ) ;
427
		p = TAIL_list(p);
394
    }
428
	}
395
    return ( q ) ;
429
	return (q);
396
}
430
}
397
 
431
 
398
 
432
 
399
/*
433
/*
400
    ENCODE THE START OF A LABELLED STATEMENT
434
    ENCODE THE START OF A LABELLED STATEMENT
401
 
435
 
402
    This routine adds the start of a labelled statement for the labels
436
    This routine adds the start of a labelled statement for the labels
403
    lbs to the bitstream bs.  This comprises outputting the list of
437
    lbs to the bitstream bs.  This comprises outputting the list of
404
    labels.  vars gives a list of variable declarations which need to
438
    labels.  vars gives a list of variable declarations which need to
405
    be moved outside the labelled statement.
439
    be moved outside the labelled statement.
406
*/
440
*/
407
 
441
 
408
static BITSTREAM *enc_labelled_start
442
static BITSTREAM *
409
    PROTO_N ( ( bs, lbs, vars ) )
-
 
410
    PROTO_T ( BITSTREAM *bs X LIST ( IDENTIFIER ) lbs X
443
enc_labelled_start(BITSTREAM *bs, LIST(IDENTIFIER)lbs,
411
	      LIST ( IDENTIFIER ) vars )
444
		   LIST(IDENTIFIER)vars)
412
{
445
{
413
    unsigned nl = LENGTH_list ( lbs ) ;
446
	unsigned nl = LENGTH_list(lbs);
414
    while ( !IS_NULL_list ( vars ) ) {
447
	while (!IS_NULL_list(vars)) {
415
	/* Declare variables */
448
		/* Declare variables */
416
	IDENTIFIER id = DEREF_id ( HEAD_list ( vars ) ) ;
449
		IDENTIFIER id = DEREF_id(HEAD_list(vars));
417
	DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
450
		DECL_SPEC ds = DEREF_dspec(id_storage(id));
418
	if ( !( ds & dspec_reserve ) || !is_anon_member ( id ) ) {
451
		if (!(ds & dspec_reserve) || !is_anon_member(id)) {
419
	    int var = 2 ;
452
			int var = 2;
420
	    EXP d = NULL_exp ;
453
			EXP d = NULL_exp;
421
	    if ( ( ds & dspec_explicit ) && ( ds & dspec_temp ) ) {
454
			if ((ds & dspec_explicit) && (ds & dspec_temp)) {
422
		var = 4 ;
455
				var = 4;
423
	    }
456
			}
424
	    bs = enc_variable ( bs, id, var, &d, NULL_exp ) ;
457
			bs = enc_variable(bs, id, var, &d, NULL_exp);
425
	    if ( !IS_NULL_exp ( d ) ) no_destructors++ ;
458
			if (!IS_NULL_exp(d)) {
-
 
459
				no_destructors++;
-
 
460
			}
426
	}
461
		}
427
	vars = TAIL_list ( vars ) ;
462
		vars = TAIL_list(vars);
428
    }
463
	}
429
    if ( nl == 0 ) {
464
	if (nl == 0) {
430
	/* No labels */
465
		/* No labels */
431
	/* EMPTY */
466
		/* EMPTY */
432
    } else if ( nl == 1 ) {
467
	} else if (nl == 1) {
433
	/* Single label can be mapped to conditional */
468
		/* Single label can be mapped to conditional */
434
	IDENTIFIER lab = DEREF_id ( HEAD_list ( lbs ) ) ;
469
		IDENTIFIER lab = DEREF_id(HEAD_list(lbs));
435
	ulong n = unit_no ( bs, lab, VAR_label, 1 ) ;
470
		ulong n = unit_no(bs, lab, VAR_label, 1);
436
	ENC_conditional ( bs ) ;
471
		ENC_conditional(bs);
437
	ENC_make_label ( bs, n ) ;
472
		ENC_make_label(bs, n);
438
    } else {
473
	} else {
439
	/* Multiple labels require labelled */
474
		/* Multiple labels require labelled */
440
	ENC_labelled ( bs ) ;
475
		ENC_labelled(bs);
441
	ENC_LIST ( bs, nl ) ;
476
		ENC_LIST(bs, nl);
442
	while ( !IS_NULL_list ( lbs ) ) {
477
		while (!IS_NULL_list(lbs)) {
443
	    IDENTIFIER lab = DEREF_id ( HEAD_list ( lbs ) ) ;
478
			IDENTIFIER lab = DEREF_id(HEAD_list(lbs));
444
	    ulong n = unit_no ( bs, lab, VAR_label, 1 ) ;
479
			ulong n = unit_no(bs, lab, VAR_label, 1);
445
	    ENC_make_label ( bs, n ) ;
480
			ENC_make_label(bs, n);
446
	    lbs = TAIL_list ( lbs ) ;
481
			lbs = TAIL_list(lbs);
447
	}
482
		}
448
    }
483
	}
449
    return ( bs ) ;
484
	return (bs);
450
}
485
}
451
 
486
 
452
 
487
 
453
/*
488
/*
454
    ENCODE A BRANCH OF A LABELLED STATEMENT
489
    ENCODE A BRANCH OF A LABELLED STATEMENT
455
 
490
 
456
    This routine adds the branch of the labelled statement d corresponding
491
    This routine adds the branch of the labelled statement d corresponding
457
    to the label lab to the bitstream bs.  Note that each such branch is
492
    to the label lab to the bitstream bs.  Note that each such branch is
458
    terminated by a jump to an immediately following label, a jump to an
493
    terminated by a jump to an immediately following label, a jump to an
459
    enclosing break or continue label, or by falling through to the end
494
    enclosing break or continue label, or by falling through to the end
460
    of the labelled statement (see end_solve_branch).
495
    of the labelled statement (see end_solve_branch).
461
*/
496
*/
462
 
497
 
463
static BITSTREAM *enc_labelled_branch
498
static BITSTREAM *
464
    PROTO_N ( ( bs, lab, d ) )
-
 
465
    PROTO_T ( BITSTREAM *bs X IDENTIFIER lab X EXP d )
499
enc_labelled_branch(BITSTREAM *bs, IDENTIFIER lab, EXP d)
466
{
500
{
467
    ulong n ;
501
	ulong n;
468
    IDENTIFIER nlab ;
502
	IDENTIFIER nlab;
469
    EXP e = DEREF_exp ( id_label_stmt ( lab ) ) ;
503
	EXP e = DEREF_exp(id_label_stmt(lab));
470
    EXP f = e ;
504
	EXP f = e;
471
    EXP g = NULL_exp ;
505
	EXP g = NULL_exp;
472
 
-
 
473
    /* Examine label type */
-
 
474
    int op = DEREF_int ( id_label_op ( lab ) ) ;
-
 
475
    switch ( op ) {
-
 
476
 
-
 
477
	case lex_while :
-
 
478
	case lex_for : {
-
 
479
	    /* While or for label */
-
 
480
	    e = DEREF_exp ( exp_label_stmt_parent ( e ) ) ;
-
 
481
	    nlab = DEREF_id ( exp_while_stmt_cont_lab ( e ) ) ;
-
 
482
	    e = DEREF_exp ( exp_while_stmt_body ( e ) ) ;
-
 
483
	    if ( is_diag_stmt ( e ) ) g = e ;
-
 
484
	    break ;
-
 
485
	}
-
 
486
 
-
 
487
	case lex_do : {
-
 
488
	    /* Do label */
-
 
489
	    e = DEREF_exp ( exp_label_stmt_parent ( e ) ) ;
-
 
490
	    nlab = DEREF_id ( exp_do_stmt_cont_lab ( e ) ) ;
-
 
491
	    e = DEREF_exp ( exp_do_stmt_body ( e ) ) ;
-
 
492
	    if ( is_diag_stmt ( e ) ) g = e ;
-
 
493
	    break ;
-
 
494
	}
-
 
495
 
-
 
496
	case lex_if : {
-
 
497
	    /* Conditional label */
-
 
498
	    EXP c ;
-
 
499
	    int sw = 0 ;
-
 
500
	    nlab = DEREF_id ( exp_label_stmt_next ( e ) ) ;
-
 
501
	    e = DEREF_exp ( exp_label_stmt_parent ( e ) ) ;
-
 
502
	    c = DEREF_exp ( exp_if_stmt_cond ( e ) ) ;
-
 
503
	    IGNORE simplify_cond ( c, &sw ) ;
-
 
504
	    if ( sw ) {
-
 
505
		e = DEREF_exp ( exp_if_stmt_true_code ( e ) ) ;
-
 
506
	    } else {
-
 
507
		e = DEREF_exp ( exp_if_stmt_false_code ( e ) ) ;
-
 
508
	    }
-
 
509
	    if ( is_diag_stmt ( e ) ) g = e ;
-
 
510
	    break ;
-
 
511
	}
-
 
512
 
506
 
513
	case lex_continue : {
-
 
514
	    /* Continue label */
507
	/* Examine label type */
515
	    EXP c ;
-
 
516
	    unsigned m ;
-
 
517
	    IDENTIFIER rlab ;
-
 
518
	    LIST ( IDENTIFIER ) cids ;
-
 
519
	    EXP b = DEREF_exp ( exp_label_stmt_body ( e ) ) ;
-
 
520
	    e = DEREF_exp ( exp_label_stmt_parent ( e ) ) ;
508
	int op = DEREF_int(id_label_op(lab));
521
	    if ( IS_exp_while_stmt ( e ) ) {
-
 
522
		c = DEREF_exp ( exp_while_stmt_cond ( e ) ) ;
-
 
523
		rlab = DEREF_id ( exp_while_stmt_loop_lab ( e ) ) ;
-
 
524
		nlab = DEREF_id ( exp_while_stmt_break_lab ( e ) ) ;
-
 
525
		cids = DEREF_list ( exp_while_stmt_cond_id ( e ) ) ;
-
 
526
	    } else {
509
	switch (op) {
527
		c = DEREF_exp ( exp_do_stmt_cond ( e ) ) ;
-
 
528
		rlab = DEREF_id ( exp_do_stmt_loop_lab ( e ) ) ;
-
 
529
		nlab = DEREF_id ( exp_do_stmt_break_lab ( e ) ) ;
-
 
530
		cids = NULL_list ( IDENTIFIER ) ;
-
 
531
	    }
-
 
532
	    m = stmt_length ( b ) ;
-
 
533
	    ENC_SEQUENCE ( bs, m + 1 ) ;
-
 
534
	    if ( m ) bs = enc_compound_stmt ( bs, b ) ;
-
 
535
 
510
 
-
 
511
	case lex_while:
-
 
512
	case lex_for: {
-
 
513
		/* While or for label */
-
 
514
		e = DEREF_exp(exp_label_stmt_parent(e));
-
 
515
		nlab = DEREF_id(exp_while_stmt_cont_lab(e));
-
 
516
		e = DEREF_exp(exp_while_stmt_body(e));
-
 
517
		if (is_diag_stmt(e)) {
-
 
518
			g = e;
-
 
519
		}
-
 
520
		break;
-
 
521
	}
-
 
522
 
-
 
523
	case lex_do: {
-
 
524
		/* Do label */
-
 
525
		e = DEREF_exp(exp_label_stmt_parent(e));
-
 
526
		nlab = DEREF_id(exp_do_stmt_cont_lab(e));
-
 
527
		e = DEREF_exp(exp_do_stmt_body(e));
-
 
528
		if (is_diag_stmt(e)) {
-
 
529
			g = e;
-
 
530
		}
-
 
531
		break;
-
 
532
	}
-
 
533
 
-
 
534
	case lex_if: {
-
 
535
		/* Conditional label */
-
 
536
		EXP c;
-
 
537
		int sw = 0;
-
 
538
		nlab = DEREF_id(exp_label_stmt_next(e));
-
 
539
		e = DEREF_exp(exp_label_stmt_parent(e));
-
 
540
		c = DEREF_exp(exp_if_stmt_cond(e));
-
 
541
		IGNORE simplify_cond(c, &sw);
-
 
542
		if (sw) {
-
 
543
			e = DEREF_exp(exp_if_stmt_true_code(e));
-
 
544
		} else {
-
 
545
			e = DEREF_exp(exp_if_stmt_false_code(e));
-
 
546
		}
-
 
547
		if (is_diag_stmt(e)) {
-
 
548
			g = e;
-
 
549
		}
-
 
550
		break;
-
 
551
	}
-
 
552
 
-
 
553
	case lex_continue: {
-
 
554
		/* Continue label */
-
 
555
		EXP c;
-
 
556
		unsigned m;
-
 
557
		IDENTIFIER rlab;
-
 
558
		LIST(IDENTIFIER)cids;
-
 
559
		EXP b = DEREF_exp(exp_label_stmt_body(e));
-
 
560
		e = DEREF_exp(exp_label_stmt_parent(e));
-
 
561
		if (IS_exp_while_stmt(e)) {
-
 
562
			c = DEREF_exp(exp_while_stmt_cond(e));
-
 
563
			rlab = DEREF_id(exp_while_stmt_loop_lab(e));
-
 
564
			nlab = DEREF_id(exp_while_stmt_break_lab(e));
-
 
565
			cids = DEREF_list(exp_while_stmt_cond_id(e));
-
 
566
		} else {
-
 
567
			c = DEREF_exp(exp_do_stmt_cond(e));
-
 
568
			rlab = DEREF_id(exp_do_stmt_loop_lab(e));
-
 
569
			nlab = DEREF_id(exp_do_stmt_break_lab(e));
-
 
570
			cids = NULL_list(IDENTIFIER);
-
 
571
		}
-
 
572
		m = stmt_length(b);
-
 
573
		ENC_SEQUENCE(bs, m + 1);
-
 
574
		if (m) {
-
 
575
			bs = enc_compound_stmt(bs, b);
-
 
576
		}
-
 
577
 
536
	    /* Output conditional jump */
578
		/* Output conditional jump */
537
	    n = unit_no ( bs, rlab, VAR_label, 0 ) ;
579
		n = unit_no(bs, rlab, VAR_label, 0);
538
	    if ( !IS_NULL_list ( cids ) ) {
580
		if (!IS_NULL_list(cids)) {
539
		bs = enc_while_destr ( bs, cids ) ;
581
			bs = enc_while_destr(bs, cids);
540
	    }
582
		}
541
	    bs = enc_condition ( bs, c, LINK_NONE, n ) ;
583
		bs = enc_condition(bs, c, LINK_NONE, n);
542
	    n = unit_no ( bs, nlab, VAR_label, 0 ) ;
584
		n = unit_no(bs, nlab, VAR_label, 0);
543
	    ENC_goto ( bs ) ;
585
		ENC_goto(bs);
544
	    ENC_make_label ( bs, n ) ;
586
		ENC_make_label(bs, n);
545
	    unreached_code = 1 ;
587
		unreached_code = 1;
546
	    return ( bs ) ;
588
		return (bs);
547
	}
589
	}
548
 
590
 
549
	default : {
591
	default : {
550
	    /* Other labels */
592
		/* Other labels */
551
	    if ( !IS_NULL_exp ( e ) ) {
593
		if (!IS_NULL_exp(e)) {
552
		if ( is_diag_stmt ( e ) ) g = e ;
594
			if (is_diag_stmt(e)) {
-
 
595
				g = e;
-
 
596
			}
553
		nlab = DEREF_id ( exp_label_stmt_next ( e ) ) ;
597
			nlab = DEREF_id(exp_label_stmt_next(e));
554
		e = DEREF_exp ( exp_label_stmt_body ( e ) ) ;
598
			e = DEREF_exp(exp_label_stmt_body(e));
555
	    } else {
599
		} else {
556
		nlab = NULL_id ;
600
			nlab = NULL_id;
557
	    }
601
		}
558
	    break ;
602
		break;
559
	}
603
	}
560
    }
604
	}
561
 
605
 
562
    /* Output label body */
606
	/* Output label body */
563
    if ( IS_NULL_id ( nlab ) ) {
607
	if (IS_NULL_id(nlab)) {
564
	/* Fall through to end of labelled statement */
608
		/* Fall through to end of labelled statement */
565
	if ( no_destructors ) {
609
		if (no_destructors) {
566
	    if ( !IS_NULL_exp ( e ) ) {
610
			if (!IS_NULL_exp(e)) {
567
		ENC_SEQ_SMALL ( bs, 1 ) ;
611
				ENC_SEQ_SMALL(bs, 1);
568
		if ( !IS_NULL_exp ( g ) ) {
612
				if (!IS_NULL_exp(g)) {
569
		    BITSTREAM *ts = enc_diag_begin ( &bs ) ;
613
					BITSTREAM *ts = enc_diag_begin(&bs);
570
		    ts = enc_stmt ( ts, e ) ;
614
					ts = enc_stmt(ts, e);
571
		    bs = enc_diag_end ( bs, ts, g, 1 ) ;
615
					bs = enc_diag_end(bs, ts, g, 1);
-
 
616
				} else {
-
 
617
					bs = enc_stmt(bs, e);
-
 
618
				}
-
 
619
			}
-
 
620
			bs = enc_destructors(bs, f, d);
-
 
621
			ENC_make_top(bs);
572
		} else {
622
		} else {
-
 
623
			if (!IS_NULL_exp(g)) {
-
 
624
				BITSTREAM *ts = enc_diag_begin(&bs);
-
 
625
				ts = enc_stmt(ts, e);
-
 
626
				bs = enc_diag_end(bs, ts, g, 1);
-
 
627
			} else {
573
		    bs = enc_stmt ( bs, e ) ;
628
				bs = enc_stmt(bs, e);
574
		}
629
			}
575
	    }
630
		}
576
	    bs = enc_destructors ( bs, f, d ) ;
-
 
577
	    ENC_make_top ( bs ) ;
-
 
578
	} else {
631
	} else {
-
 
632
		/* Jump to following label */
-
 
633
		if (!IS_NULL_exp(e)) {
-
 
634
			ENC_SEQ_SMALL(bs, 1);
579
	    if ( !IS_NULL_exp ( g ) ) {
635
			if (!IS_NULL_exp(g)) {
580
		BITSTREAM *ts = enc_diag_begin ( &bs ) ;
636
				BITSTREAM *ts = enc_diag_begin(&bs);
581
		ts = enc_stmt ( ts, e ) ;
637
				ts = enc_stmt(ts, e);
582
		bs = enc_diag_end ( bs, ts, g, 1 ) ;
638
				bs = enc_diag_end(bs, ts, g, 1);
583
	    } else {
639
			} else {
584
		bs = enc_stmt ( bs, e ) ;
640
				bs = enc_stmt(bs, e);
585
	    }
641
			}
586
	}
642
		}
587
    } else {
-
 
588
	/* Jump to following label */
643
		op = DEREF_int(id_label_op(nlab));
589
	if ( !IS_NULL_exp ( e ) ) {
644
		if (op == lex_break || op == lex_continue) {
590
	    ENC_SEQ_SMALL ( bs, 1 ) ;
645
			/* Need to call destructors for jump */
591
	    if ( !IS_NULL_exp ( g ) ) {
646
			EXP b = DEREF_exp(id_label_stmt(nlab));
592
		BITSTREAM *ts = enc_diag_begin ( &bs ) ;
647
			b = DEREF_exp(exp_label_stmt_parent(b));
593
		ts = enc_stmt ( ts, e ) ;
648
			bs = enc_destructors(bs, f, b);
-
 
649
		}
594
		bs = enc_diag_end ( bs, ts, g, 1 ) ;
650
		n = unit_no(bs, nlab, VAR_label, 0);
595
	    } else {
651
		ENC_goto(bs);
596
		bs = enc_stmt ( bs, e ) ;
652
		ENC_make_label(bs, n);
597
	    }
653
		unreached_code = 1;
598
	}
654
	}
599
	op = DEREF_int ( id_label_op ( nlab ) ) ;
-
 
600
	if ( op == lex_break || op == lex_continue ) {
-
 
601
	    /* Need to call destructors for jump */
-
 
602
	    EXP b = DEREF_exp ( id_label_stmt ( nlab ) ) ;
-
 
603
	    b = DEREF_exp ( exp_label_stmt_parent ( b ) ) ;
-
 
604
	    bs = enc_destructors ( bs, f, b ) ;
-
 
605
	}
-
 
606
	n = unit_no ( bs, nlab, VAR_label, 0 ) ;
-
 
607
	ENC_goto ( bs ) ;
-
 
608
	ENC_make_label ( bs, n ) ;
-
 
609
	unreached_code = 1 ;
-
 
610
    }
-
 
611
    return ( bs ) ;
655
	return (bs);
612
}
656
}
613
 
657
 
614
 
658
 
615
/*
659
/*
616
    ENCODE THE END OF A LABELLED STATEMENT
660
    ENCODE THE END OF A LABELLED STATEMENT
617
 
661
 
618
    This routine adds the end of the labelled statement e to the bitstream
662
    This routine adds the end of the labelled statement e to the bitstream
619
    bs.  This comprises outputting the list of label bodies for the labels
663
    bs.  This comprises outputting the list of label bodies for the labels
620
    lbs and then taking the labels and the variables vars out of scope.
664
    lbs and then taking the labels and the variables vars out of scope.
621
*/
665
*/
622
 
666
 
623
static BITSTREAM *enc_labelled_end
667
static BITSTREAM *
624
    PROTO_N ( ( bs, lbs, vars, e ) )
-
 
625
    PROTO_T ( BITSTREAM *bs X LIST ( IDENTIFIER ) lbs X
668
enc_labelled_end(BITSTREAM *bs, LIST(IDENTIFIER)lbs, LIST(IDENTIFIER)vars,
626
	      LIST ( IDENTIFIER ) vars X EXP e )
669
		 EXP e)
627
{
670
{
628
    int uc = unreached_code ;
671
	int uc = unreached_code;
629
    unsigned nl = LENGTH_list ( lbs ) ;
672
	unsigned nl = LENGTH_list(lbs);
630
    if ( nl == 0 ) {
673
	if (nl == 0) {
631
	/* No labels */
674
		/* No labels */
632
	/* EMPTY */
675
		/* EMPTY */
633
    } else if ( nl == 1 ) {
676
	} else if (nl == 1) {
634
	/* Single label */
677
		/* Single label */
635
	IDENTIFIER lab = DEREF_id ( HEAD_list ( lbs ) ) ;
678
		IDENTIFIER lab = DEREF_id(HEAD_list(lbs));
636
	unreached_code = 0 ;
679
		unreached_code = 0;
637
	bs = enc_labelled_branch ( bs, lab, e ) ;
680
		bs = enc_labelled_branch(bs, lab, e);
638
	if ( !unreached_code ) uc = 0 ;
681
		if (!unreached_code) {
-
 
682
			uc = 0;
-
 
683
		}
639
	clear_no ( lab ) ;
684
		clear_no(lab);
640
    } else {
685
	} else {
641
	/* Multiple labels */
686
		/* Multiple labels */
642
	LIST ( IDENTIFIER ) p = lbs ;
687
		LIST(IDENTIFIER)p = lbs;
643
	ENC_LIST ( bs, nl ) ;
688
		ENC_LIST(bs, nl);
644
	while ( !IS_NULL_list ( p ) ) {
689
		while (!IS_NULL_list(p)) {
645
	    IDENTIFIER lab = DEREF_id ( HEAD_list ( p ) ) ;
690
			IDENTIFIER lab = DEREF_id(HEAD_list(p));
646
	    unreached_code = 0 ;
691
			unreached_code = 0;
647
	    bs = enc_labelled_branch ( bs, lab, e ) ;
692
			bs = enc_labelled_branch(bs, lab, e);
648
	    if ( !unreached_code ) uc = 0 ;
693
			if (!unreached_code) {
-
 
694
				uc = 0;
-
 
695
			}
649
	    p = TAIL_list ( p ) ;
696
			p = TAIL_list(p);
650
	}
697
		}
651
	p = lbs ;
698
		p = lbs;
652
	while ( !IS_NULL_list ( p ) ) {
699
		while (!IS_NULL_list(p)) {
653
	    IDENTIFIER lab = DEREF_id ( HEAD_list ( p ) ) ;
700
			IDENTIFIER lab = DEREF_id(HEAD_list(p));
654
	    clear_no ( lab ) ;
701
			clear_no(lab);
655
	    p = TAIL_list ( p ) ;
702
			p = TAIL_list(p);
656
	}
703
		}
657
    }
704
	}
658
    while ( !IS_NULL_list ( vars ) ) {
705
	while (!IS_NULL_list(vars)) {
659
	/* Take variables out of scope */
706
		/* Take variables out of scope */
660
	IDENTIFIER id = DEREF_id ( HEAD_list ( vars ) ) ;
707
		IDENTIFIER id = DEREF_id(HEAD_list(vars));
661
	DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
708
		DECL_SPEC ds = DEREF_dspec(id_storage(id));
662
	if ( ds & dspec_auto ) clear_no ( id ) ;
709
		if (ds & dspec_auto) {
-
 
710
			clear_no(id);
-
 
711
		}
663
	vars = TAIL_list ( vars ) ;
712
		vars = TAIL_list(vars);
664
    }
713
	}
665
    unreached_code = uc ;
714
	unreached_code = uc;
666
    return ( bs ) ;
715
	return (bs);
667
}
716
}
668
 
717
 
669
 
718
 
670
/*
719
/*
671
    CURRENT ENCODING LOCATION
720
    CURRENT ENCODING LOCATION
672
 
721
 
673
    This location is used to store the current location during the
722
    This location is used to store the current location during the
674
    encoding of statements.
723
    encoding of statements.
675
*/
724
*/
676
 
725
 
677
PTR ( LOCATION ) crt_enc_loc = NULL_ptr ( LOCATION ) ;
726
PTR(LOCATION)crt_enc_loc = NULL_ptr(LOCATION);
678
 
727
 
679
 
728
 
680
/*
729
/*
681
    ENCODE A DECLARATION STATEMENT
730
    ENCODE A DECLARATION STATEMENT
682
 
731
 
683
    This routine adds the declaration statement e to the bitstream bs.
732
    This routine adds the declaration statement e to the bitstream bs.
684
*/
733
*/
685
 
734
 
686
static BITSTREAM *enc_decl_stmt
735
static BITSTREAM *
687
    PROTO_N ( ( bs, e ) )
-
 
688
    PROTO_T ( BITSTREAM *bs X EXP e )
736
enc_decl_stmt(BITSTREAM *bs, EXP e)
689
{
737
{
690
    int var = 1 ;
738
	int var = 1;
691
    int scope = 0 ;
739
	int scope = 0;
692
    BITSTREAM *ts ;
740
	BITSTREAM *ts;
693
    ulong nlabs = 0 ;
741
	ulong nlabs = 0;
694
    EXP d = NULL_exp ;
742
	EXP d = NULL_exp;
695
    int diag = output_diag ;
743
	int diag = output_diag;
696
    EXP a = DEREF_exp ( exp_decl_stmt_body ( e ) ) ;
744
	EXP a = DEREF_exp(exp_decl_stmt_body(e));
697
    IDENTIFIER id = DEREF_id ( exp_decl_stmt_id ( e ) ) ;
745
	IDENTIFIER id = DEREF_id(exp_decl_stmt_id(e));
698
    TYPE t = DEREF_type ( id_variable_type ( id ) ) ;
746
	TYPE t = DEREF_type(id_variable_type(id));
699
    DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
747
	DECL_SPEC ds = DEREF_dspec(id_storage(id));
700
    if ( !( ds & dspec_reserve ) || !is_anon_member ( id ) ) {
748
	if (!(ds & dspec_reserve) || !is_anon_member(id)) {
701
	EXP b = DEREF_exp ( id_variable_init ( id ) ) ;
749
		EXP b = DEREF_exp(id_variable_init(id));
702
	if ( IS_NULL_exp ( b ) || !output_diag ) {
750
		if (IS_NULL_exp(b) || !output_diag) {
703
	    /* Don't output diagnostics */
751
			/* Don't output diagnostics */
704
	    e = NULL_exp ;
752
			e = NULL_exp;
705
	}
753
		}
706
	if ( ds & dspec_explicit ) {
754
		if (ds & dspec_explicit) {
707
	    /* Only declare explicitly initialised variables */
755
			/* Only declare explicitly initialised variables */
708
	    if ( ds & dspec_temp ) {
756
			if (ds & dspec_temp) {
709
		nlabs = no_labels ( bs ) ;
757
				nlabs = no_labels(bs);
710
		e = NULL_exp ;
758
				e = NULL_exp;
711
		var = 4 ;
759
				var = 4;
712
	    } else {
760
			} else {
713
		var = 3 ;
761
				var = 3;
714
	    }
762
			}
715
	}
763
		}
716
	if ( ds & dspec_done ) {
764
		if (ds & dspec_done) {
717
	    /* Variable previously declared */
765
			/* Variable previously declared */
718
	    int dummy = 0 ;
766
			int dummy = 0;
719
	    EXP d1 = DEREF_exp ( id_variable_term ( id ) ) ;
767
			EXP d1 = DEREF_exp(id_variable_term(id));
720
	    if ( !IS_NULL_exp ( d1 ) ) {
768
			if (!IS_NULL_exp(d1)) {
721
		/* Allow for terminator expressions */
769
				/* Allow for terminator expressions */
722
		if ( output_except ) {
770
				if (output_except) {
723
		    while ( IS_exp_nof ( d1 ) ) {
771
					while (IS_exp_nof(d1)) {
724
			d1 = DEREF_exp ( exp_nof_pad ( d1 ) ) ;
772
						d1 = DEREF_exp(exp_nof_pad(d1));
725
		    }
773
					}
726
		    if ( IS_NULL_exp ( b ) && var == 1 ) {
774
					if (IS_NULL_exp(b) && var == 1) {
727
			/* Force initialisation */
775
						/* Force initialisation */
728
			b = make_dummy_init ( t ) ;
776
						b = make_dummy_init(t);
729
			dummy = 1 ;
777
						dummy = 1;
730
		    }
778
					}
-
 
779
				} else {
-
 
780
					d1 = NULL_exp;
-
 
781
				}
-
 
782
			}
-
 
783
			if (!IS_NULL_exp(b)) {
-
 
784
				ulong n = unit_no(bs, id, VAR_tag, 0);
-
 
785
				bs = enc_assign_local(bs, b, d1, n, t, e);
-
 
786
				if (IS_exp_thrown(b) && output_new_diag) {
-
 
787
					diag = 0;
-
 
788
				}
-
 
789
				if (dummy)free_exp(b, 1);
-
 
790
			}
-
 
791
		} else {
-
 
792
			/* Variable not previously declared */
-
 
793
			bs = enc_variable(bs, id, var, &d, e);
-
 
794
			if (ds & dspec_auto) {
-
 
795
				scope = 1;
-
 
796
			}
-
 
797
		}
-
 
798
	}
-
 
799
	if (diag && !(ds & dspec_temp)) {
-
 
800
		HASHID nm = DEREF_hashid(id_name(id));
-
 
801
		if (!IS_hashid_anon(nm)) {
-
 
802
			ts = start_bitstream(NIL(FILE), bs->link);
-
 
803
		} else {
-
 
804
			ts = bs;
-
 
805
			diag = 0;
-
 
806
		}
-
 
807
	} else {
-
 
808
		ts = bs;
-
 
809
		diag = 0;
-
 
810
	}
-
 
811
	if (IS_NULL_exp(d)) {
-
 
812
		ts = enc_stmt(ts, a);
-
 
813
	} else {
-
 
814
		unsigned seq = stmt_length(a) + 1;
-
 
815
		no_destructors++;
-
 
816
		ENC_SEQUENCE(ts, seq);
-
 
817
		ts = enc_compound_stmt(ts, a);
-
 
818
		if (unreached_code) {
-
 
819
			ENC_make_top(ts);
-
 
820
			ENC_make_top(ts);
731
		} else {
821
		} else {
-
 
822
			ulong n = unit_no(ts, id, VAR_tag, 0);
-
 
823
			if (var == 4 && nlabs == no_labels(bs)) {
732
		    d1 = NULL_exp ;
824
				var = 3;
-
 
825
			}
-
 
826
			ts = enc_term_local(ts, n, NULL_off, 0, t, d, var);
733
		}
827
		}
734
	    }
-
 
735
	    if ( !IS_NULL_exp ( b ) ) {
-
 
736
		ulong n = unit_no ( bs, id, VAR_tag, 0 ) ;
-
 
737
		bs = enc_assign_local ( bs, b, d1, n, t, e ) ;
-
 
738
		if ( IS_exp_thrown ( b ) && output_new_diag ) diag = 0 ;
-
 
739
		if ( dummy ) free_exp ( b, 1 ) ;
-
 
740
	    }
-
 
741
	} else {
828
		no_destructors--;
742
	    /* Variable not previously declared */
-
 
743
	    bs = enc_variable ( bs, id, var, &d, e ) ;
-
 
744
	    if ( ds & dspec_auto ) scope = 1 ;
-
 
745
	}
829
	}
746
    }
830
	if (diag) {
747
    if ( diag && !( ds & dspec_temp ) ) {
-
 
748
	HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
-
 
749
	if ( !IS_hashid_anon ( nm ) ) {
831
		bs = enc_diag_local(bs, id, ts);
750
	    ts = start_bitstream ( NIL ( FILE ), bs->link ) ;
-
 
751
	} else {
832
	} else {
752
	    ts = bs ;
833
		bs = ts;
753
	    diag = 0 ;
-
 
754
	}
834
	}
755
    } else {
-
 
756
	ts = bs ;
-
 
757
	diag = 0 ;
-
 
758
    }
-
 
759
    if ( IS_NULL_exp ( d ) ) {
-
 
760
	ts = enc_stmt ( ts, a ) ;
-
 
761
    } else {
835
	if (scope) {
762
	unsigned seq = stmt_length ( a ) + 1 ;
836
		/* Take variable out of scope */
763
	no_destructors++ ;
837
		clear_no(id);
764
	ENC_SEQUENCE ( ts, seq ) ;
-
 
765
	ts = enc_compound_stmt ( ts, a ) ;
-
 
766
	if ( unreached_code ) {
-
 
767
	    ENC_make_top ( ts ) ;
-
 
768
	    ENC_make_top ( ts ) ;
-
 
769
	} else {
-
 
770
	    ulong n = unit_no ( ts, id, VAR_tag, 0 ) ;
-
 
771
	    if ( var == 4 && nlabs == no_labels ( bs ) ) var = 3 ;
-
 
772
	    ts = enc_term_local ( ts, n, NULL_off, 0, t, d, var ) ;
-
 
773
	}
838
	}
774
	no_destructors-- ;
-
 
775
    }
-
 
776
    if ( diag ) {
-
 
777
	bs = enc_diag_local ( bs, id, ts ) ;
-
 
778
    } else {
-
 
779
	bs = ts ;
-
 
780
    }
-
 
781
    if ( scope ) {
-
 
782
	/* Take variable out of scope */
-
 
783
	clear_no ( id ) ;
-
 
784
    }
-
 
785
    return ( bs ) ;
839
	return (bs);
786
}
840
}
787
 
841
 
788
 
842
 
789
/*
843
/*
790
    ENCODE A TDF BODY STATEMENT
844
    ENCODE A TDF BODY STATEMENT
791
 
845
 
792
    This routine is identical to enc_stmt except that it makes explicit
846
    This routine is identical to enc_stmt except that it makes explicit
793
    provision for diagnostic information.
847
    provision for diagnostic information.
794
*/
848
*/
795
 
849
 
796
static BITSTREAM *enc_body_stmt
850
static BITSTREAM *
797
    PROTO_N ( ( bs, e ) )
-
 
798
    PROTO_T ( BITSTREAM *bs X EXP e )
851
enc_body_stmt(BITSTREAM *bs, EXP e)
799
{
852
{
800
    if ( output_diag && is_diag_stmt ( e ) ) {
853
	if (output_diag && is_diag_stmt(e)) {
801
	BITSTREAM *ts = enc_diag_begin ( &bs ) ;
854
		BITSTREAM *ts = enc_diag_begin(&bs);
802
	ts = enc_stmt ( ts, e ) ;
855
		ts = enc_stmt(ts, e);
803
	bs = enc_diag_end ( bs, ts, e, 1 ) ;
856
		bs = enc_diag_end(bs, ts, e, 1);
804
    } else {
857
	} else {
805
	bs = enc_stmt ( bs, e ) ;
858
		bs = enc_stmt(bs, e);
806
    }
859
	}
807
    return ( bs ) ;
860
	return (bs);
808
}
861
}
809
 
862
 
810
 
863
 
811
/*
864
/*
812
    ENCODE A TDF STATEMENT
865
    ENCODE A TDF STATEMENT
813
 
866
 
814
    This routine adds the statement e to the bitstream bs as a TDF EXP.
867
    This routine adds the statement e to the bitstream bs as a TDF EXP.
815
*/
868
*/
816
 
869
 
817
BITSTREAM *enc_stmt
870
BITSTREAM *
818
    PROTO_N ( ( bs, e ) )
-
 
819
    PROTO_T ( BITSTREAM *bs X EXP e )
871
enc_stmt(BITSTREAM *bs, EXP e)
820
{
872
{
1060
 
1092
 
1061
	    /* Default or break jump */
1093
		/* Encode case jump */
-
 
1094
		ENC_SEQ_SMALL(bs, 1);
-
 
1095
		a = DEREF_exp(exp_switch_stmt_control(e));
1062
	    if ( IS_NULL_id ( dl ) ) dl = bl ;
1096
		if (IS_NULL_list(cls)) {
-
 
1097
			/* No cases */
1063
	    n = unit_no ( bs, dl, VAR_label, 0 ) ;
1098
			bs = enc_exp(bs, a);
-
 
1099
		} else {
-
 
1100
			ENC_case(bs);
1064
	    ENC_goto ( bs ) ;
1101
			ENC_false(bs);
-
 
1102
			bs = enc_exp(bs, a);
-
 
1103
			ENC_LIST(bs, nc);
-
 
1104
			while (!IS_NULL_list(cls)) {
-
 
1105
				/* Encode case limbs */
-
 
1106
				NAT cn = DEREF_nat(HEAD_list(cns));
-
 
1107
				IDENTIFIER cl = DEREF_id(HEAD_list(cls));
-
 
1108
				n = unit_no(bs, cl, VAR_label, 0);
1065
	    ENC_make_label ( bs, n ) ;
1109
				ENC_make_label(bs, n);
-
 
1110
				bs = enc_snat(bs, cn, 0, 1);
1066
	    unreached_code = 1 ;
1111
				bs = enc_snat(bs, cn, 0, 1);
-
 
1112
				cns = TAIL_list(cns);
-
 
1113
				cls = TAIL_list(cls);
-
 
1114
			}
-
 
1115
		}
1067
 
1116
 
1068
	    /* End labelled statement */
1117
		/* Default or break jump */
-
 
1118
		if (IS_NULL_id(dl)) {
-
 
1119
			dl = bl;
-
 
1120
		}
1069
	    bs = enc_labelled_end ( bs, lbs, vars, e ) ;
1121
		n = unit_no(bs, dl, VAR_label, 0);
1070
	    DESTROY_list ( lbs, SIZE_id ) ;
1122
		ENC_goto(bs);
1071
	    no_destructors = nd ;
1123
		ENC_make_label(bs, n);
1072
	    break ;
1124
		unreached_code = 1;
1073
	}
-
 
1074
 
1125
 
-
 
1126
		/* End labelled statement */
-
 
1127
		bs = enc_labelled_end(bs, lbs, vars, e);
-
 
1128
		DESTROY_list(lbs, SIZE_id);
-
 
1129
		no_destructors = nd;
-
 
1130
		break;
-
 
1131
	}
-
 
1132
 
1075
	case exp_return_stmt_tag : {
1133
	case exp_return_stmt_tag: {
1076
	    /* Return expressions */
1134
		/* Return expressions */
1077
	    ulong r = last_params [ DUMMY_return ] ;
1135
		ulong r = last_params[DUMMY_return];
1078
	    EXP a = DEREF_exp ( exp_return_stmt_value ( e ) ) ;
1136
		EXP a = DEREF_exp(exp_return_stmt_value(e));
1079
	    if ( IS_NULL_exp ( a ) ) {
1137
		if (IS_NULL_exp(a)) {
1080
		/* Plain return */
1138
			/* Plain return */
1081
		bs = enc_destructors ( bs, e, NULL_exp ) ;
1139
			bs = enc_destructors(bs, e, NULL_exp);
1082
		ENC_return ( bs ) ;
1140
			ENC_return(bs);
1083
		ENC_make_top ( bs ) ;
1141
			ENC_make_top(bs);
1084
	    } else if ( r != LINK_NONE ) {
1142
		} else if (r != LINK_NONE) {
1085
		/* Reference return */
1143
			/* Reference return */
1086
		ENC_SEQ_SMALL ( bs, 1 ) ;
1144
			ENC_SEQ_SMALL(bs, 1);
1087
		if ( r == LINK_ZERO ) {
1145
			if (r == LINK_ZERO) {
1088
		    bs = enc_exp ( bs, a ) ;
1146
				bs = enc_exp(bs, a);
-
 
1147
			} else {
-
 
1148
				OFFSET off = NULL_off;
-
 
1149
				TYPE t = DEREF_type(exp_type(a));
-
 
1150
				bs = enc_init_tag(bs, r, off, 1, t, a,
-
 
1151
						  NULL_exp, 0);
-
 
1152
			}
-
 
1153
			bs = enc_destructors(bs, e, NULL_exp);
-
 
1154
			ENC_return(bs);
-
 
1155
			ENC_make_top(bs);
1089
		} else {
1156
		} else {
1090
		    OFFSET off = NULL_off ;
-
 
1091
		    TYPE t = DEREF_type ( exp_type ( a ) ) ;
-
 
1092
		    bs = enc_init_tag ( bs, r, off, 1, t, a, NULL_exp, 0 ) ;
-
 
1093
		}
-
 
1094
		bs = enc_destructors ( bs, e, NULL_exp ) ;
-
 
1095
		ENC_return ( bs ) ;
-
 
1096
		ENC_make_top ( bs ) ;
-
 
1097
	    } else {
-
 
1098
		if ( no_destructors ) {
1157
			if (no_destructors) {
1099
		    /* Return with destructors */
1158
				/* Return with destructors */
1100
		    if ( is_const_exp ( a, -1 ) ) {
1159
				if (is_const_exp(a, -1)) {
1101
			bs = enc_destructors ( bs, e, NULL_exp ) ;
1160
					bs = enc_destructors(bs, e, NULL_exp);
1102
			ENC_return ( bs ) ;
1161
					ENC_return(bs);
1103
			bs = enc_exp ( bs, a ) ;
1162
					bs = enc_exp(bs, a);
1104
		    } else {
1163
				} else {
1105
			ulong n = unit_no ( bs, NULL_id, VAR_tag, 1 ) ;
1164
					ulong n = unit_no(bs, NULL_id, VAR_tag, 1);
1106
			ENC_identify ( bs ) ;
1165
					ENC_identify(bs);
1107
			bs = enc_access ( bs, dspec_none ) ;
1166
					bs = enc_access(bs, dspec_none);
1108
			ENC_make_tag ( bs, n ) ;
1167
					ENC_make_tag(bs, n);
1109
			bs = enc_exp ( bs, a ) ;
1168
					bs = enc_exp(bs, a);
1110
			bs = enc_destructors ( bs, e, NULL_exp ) ;
1169
					bs = enc_destructors(bs, e, NULL_exp);
1111
			ENC_return ( bs ) ;
1170
					ENC_return(bs);
1112
			ENC_obtain_tag ( bs ) ;
1171
					ENC_obtain_tag(bs);
1113
			ENC_make_tag ( bs, n ) ;
1172
					ENC_make_tag(bs, n);
1114
		    }
1173
				}
1115
		} else {
1174
			} else {
1116
		    /* Simple return */
1175
				/* Simple return */
1117
		    ENC_return ( bs ) ;
1176
				ENC_return(bs);
1118
		    bs = enc_exp ( bs, a ) ;
1177
				bs = enc_exp(bs, a);
-
 
1178
			}
1119
		}
1179
		}
1120
	    }
-
 
1121
	    unreached_code = 1 ;
1180
		unreached_code = 1;
1122
	    break ;
1181
		break;
1123
	}
1182
	}
1124
 
1183
 
1125
	case exp_goto_stmt_tag : {
1184
	case exp_goto_stmt_tag: {
1126
	    /* Goto expressions */
1185
		/* Goto expressions */
1127
	    EXP a = DEREF_exp ( exp_goto_stmt_join ( e ) ) ;
1186
		EXP a = DEREF_exp(exp_goto_stmt_join(e));
1128
	    IDENTIFIER lab = DEREF_id ( exp_goto_stmt_label ( e ) ) ;
1187
		IDENTIFIER lab = DEREF_id(exp_goto_stmt_label(e));
1129
	    ulong n = unit_no ( bs, lab, VAR_label, 0 ) ;
1188
		ulong n = unit_no(bs, lab, VAR_label, 0);
1130
	    bs = enc_destructors ( bs, e, a ) ;
1189
		bs = enc_destructors(bs, e, a);
1131
	    ENC_goto ( bs ) ;
1190
		ENC_goto(bs);
1132
	    ENC_make_label ( bs, n ) ;
1191
		ENC_make_label(bs, n);
1133
	    unreached_code = 1 ;
1192
		unreached_code = 1;
1134
	    break ;
1193
		break;
1135
	}
1194
	}
1136
 
1195
 
1137
	case exp_label_stmt_tag : {
1196
	case exp_label_stmt_tag: {
1138
	    /* Labelled expressions */
1197
		/* Labelled expressions */
1139
	    if ( is_diag_stmt ( e ) ) {
1198
		if (is_diag_stmt(e)) {
1140
		IDENTIFIER lab = DEREF_id ( exp_label_stmt_label ( e ) ) ;
1199
			IDENTIFIER lab = DEREF_id(exp_label_stmt_label(e));
1141
		ulong n = DEREF_ulong ( id_no ( lab ) ) ;
1200
			ulong n = DEREF_ulong(id_no(lab));
1142
		if ( n == LINK_NONE ) {
1201
			if (n == LINK_NONE) {
1143
		    BITSTREAM *ts = enc_diag_begin ( &bs ) ;
1202
				BITSTREAM *ts = enc_diag_begin(&bs);
1144
		    ts = enc_label_stmt ( ts, e ) ;
1203
				ts = enc_label_stmt(ts, e);
1145
		    bs = enc_diag_end ( bs, ts, e, 1 ) ;
1204
				bs = enc_diag_end(bs, ts, e, 1);
-
 
1205
			} else {
-
 
1206
				bs = enc_label_stmt(bs, e);
-
 
1207
			}
1146
		} else {
1208
		} else {
1147
		    bs = enc_label_stmt ( bs, e ) ;
1209
			bs = enc_label_stmt(bs, e);
1148
		}
1210
		}
1149
	    } else {
-
 
1150
		bs = enc_label_stmt ( bs, e ) ;
-
 
1151
	    }
-
 
1152
	    break ;
1211
		break;
1153
	}
1212
	}
1154
 
1213
 
1155
#if LANGUAGE_CPP
1214
#if LANGUAGE_CPP
1156
	case exp_try_block_tag : {
1215
	case exp_try_block_tag: {
1157
	    /* Try block */
1216
		/* Try block */
1158
	    bs = enc_try ( bs, e ) ;
1217
		bs = enc_try(bs, e);
1159
	    break ;
-
 
1160
	}
-
 
1161
 
-
 
1162
	case exp_handler_tag : {
-
 
1163
	    /* Exception handler */
-
 
1164
	    BITSTREAM *ts ;
-
 
1165
	    EXP a = DEREF_exp ( exp_handler_body ( e ) ) ;
-
 
1166
	    IDENTIFIER id = DEREF_id ( exp_handler_except ( e ) ) ;
-
 
1167
	    if ( !IS_NULL_id ( id ) ) {
-
 
1168
		/* Declare exception variable */
-
 
1169
		EXP d = NULL_exp ;
-
 
1170
		bs = enc_variable ( bs, id, 2, &d, NULL_exp ) ;
-
 
1171
		if ( !IS_NULL_exp ( d ) ) no_destructors++ ;
-
 
1172
	    }
-
 
1173
	    ts = enc_diag_begin ( &bs ) ;
-
 
1174
	    ts = enc_stmt ( ts, a ) ;
-
 
1175
	    bs = enc_diag_end ( bs, ts, e, 1 ) ;
-
 
1176
	    clear_no ( id ) ;
-
 
1177
	    break ;
-
 
1178
	}
-
 
1179
#endif
-
 
1180
 
-
 
1181
	case exp_location_tag : {
-
 
1182
	    /* Location statement */
-
 
1183
	    EXP a = DEREF_exp ( exp_location_arg ( e ) ) ;
-
 
1184
	    bs = enc_body_stmt ( bs, a ) ;
-
 
1185
	    crt_enc_loc = exp_location_end ( e ) ;
-
 
1186
	    break ;
-
 
1187
	}
-
 
1188
 
-
 
1189
	case exp_reach_tag :
-
 
1190
	case exp_unreach_tag : {
-
 
1191
	    /* Flow control statement */
-
 
1192
	    EXP a = DEREF_exp ( exp_reach_etc_body ( e ) ) ;
-
 
1193
	    bs = enc_stmt ( bs, a ) ;
-
 
1194
	    break ;
-
 
1195
	}
-
 
1196
 
-
 
1197
	case exp_if_stmt_tag :
-
 
1198
	case exp_hash_if_tag :
-
 
1199
	default : {
-
 
1200
	    /* Expression statements */
-
 
1201
	    bs = enc_stmt_exp ( bs, e, type_void, 0 ) ;
-
 
1202
	    break ;
1218
		break;
1203
	}
1219
	}
-
 
1220
 
-
 
1221
	case exp_handler_tag: {
-
 
1222
		/* Exception handler */
-
 
1223
		BITSTREAM *ts;
-
 
1224
		EXP a = DEREF_exp(exp_handler_body(e));
-
 
1225
		IDENTIFIER id = DEREF_id(exp_handler_except(e));
-
 
1226
		if (!IS_NULL_id(id)) {
-
 
1227
			/* Declare exception variable */
-
 
1228
			EXP d = NULL_exp;
-
 
1229
			bs = enc_variable(bs, id, 2, &d, NULL_exp);
-
 
1230
			if (!IS_NULL_exp(d)) {
-
 
1231
				no_destructors++;
1204
    }
1232
			}
-
 
1233
		}
-
 
1234
		ts = enc_diag_begin(&bs);
-
 
1235
		ts = enc_stmt(ts, a);
-
 
1236
		bs = enc_diag_end(bs, ts, e, 1);
-
 
1237
		clear_no(id);
-
 
1238
		break;
-
 
1239
	}
-
 
1240
#endif
-
 
1241
 
-
 
1242
	case exp_location_tag: {
-
 
1243
		/* Location statement */
-
 
1244
		EXP a = DEREF_exp(exp_location_arg(e));
-
 
1245
		bs = enc_body_stmt(bs, a);
-
 
1246
		crt_enc_loc = exp_location_end(e);
-
 
1247
		break;
-
 
1248
	}
-
 
1249
 
-
 
1250
	case exp_reach_tag:
-
 
1251
	case exp_unreach_tag: {
-
 
1252
		/* Flow control statement */
-
 
1253
		EXP a = DEREF_exp(exp_reach_etc_body(e));
-
 
1254
		bs = enc_stmt(bs, a);
-
 
1255
		break;
-
 
1256
	}
-
 
1257
 
-
 
1258
	case exp_if_stmt_tag:
-
 
1259
	case exp_hash_if_tag:
-
 
1260
	default: {
-
 
1261
		/* Expression statements */
-
 
1262
		bs = enc_stmt_exp(bs, e, type_void, 0);
-
 
1263
		break;
-
 
1264
	}
-
 
1265
	}
1205
    return ( bs ) ;
1266
	return (bs);
1206
}
1267
}
1207
 
1268
 
1208
 
1269
 
1209
/*
1270
/*
1210
    ENCODE A TDF EXPRESSION STATEMENT
1271
    ENCODE A TDF EXPRESSION STATEMENT
1211
 
1272
 
1212
    This routine adds the expression statement e to the bitstream bs as
1273
    This routine adds the expression statement e to the bitstream bs as
1213
    a TDF EXP.  use indicates how the value of the expression is used.
1274
    a TDF EXP.  use indicates how the value of the expression is used.
1214
*/
1275
*/
1215
 
1276
 
1216
BITSTREAM *enc_stmt_exp
1277
BITSTREAM *
1217
    PROTO_N ( ( bs, e, t, use ) )
-
 
1218
    PROTO_T ( BITSTREAM *bs X EXP e X TYPE t X int use )
1278
enc_stmt_exp(BITSTREAM *bs, EXP e, TYPE t, int use)
1219
{
1279
{
1220
    if ( IS_NULL_exp ( e ) ) {
1280
	if (IS_NULL_exp(e)) {
1221
	/* Deal with null expressions */
1281
		/* Deal with null expressions */
1222
	ENC_make_top ( bs ) ;
1282
		ENC_make_top(bs);
1223
	return ( bs ) ;
1283
		return (bs);
1224
    }
1284
	}
1225
 
1285
 
1226
    /* Examine expression cases */
1286
	/* Examine expression cases */
1227
    switch ( TAG_exp ( e ) ) {
1287
	switch (TAG_exp(e)) {
1228
 
1288
 
1229
	case exp_solve_stmt_tag :
1289
	case exp_solve_stmt_tag:
1230
	case exp_decl_stmt_tag :
1290
	case exp_decl_stmt_tag:
1231
	case exp_while_stmt_tag :
1291
	case exp_while_stmt_tag:
1232
	case exp_do_stmt_tag :
1292
	case exp_do_stmt_tag:
1233
	case exp_switch_stmt_tag :
1293
	case exp_switch_stmt_tag:
1234
	case exp_return_stmt_tag :
1294
	case exp_return_stmt_tag:
1235
	case exp_goto_stmt_tag :
1295
	case exp_goto_stmt_tag:
1236
	case exp_label_stmt_tag :
1296
	case exp_label_stmt_tag:
1237
	case exp_try_block_tag :
1297
	case exp_try_block_tag:
1238
	case exp_handler_tag : {
1298
	case exp_handler_tag: {
1239
	    /* Simple statements */
1299
		/* Simple statements */
1240
	    bs = enc_stmt ( bs, e ) ;
1300
		bs = enc_stmt(bs, e);
1241
	    break ;
1301
		break;
1242
	}
1302
	}
1243
 
1303
 
1244
	case exp_sequence_tag : {
1304
	case exp_sequence_tag: {
1245
	    /* Lexical blocks */
1305
		/* Lexical blocks */
1246
	    bs = enc_body_stmt ( bs, e ) ;
1306
		bs = enc_body_stmt(bs, e);
1247
	    break ;
1307
		break;
1248
	}
1308
	}
1249
 
1309
 
1250
	case exp_if_stmt_tag : {
1310
	case exp_if_stmt_tag: {
1251
	    /* Conditional statements */
1311
		/* Conditional statements */
1252
	    ulong n ;
1312
		ulong n;
1253
	    int ua, ub ;
1313
		int ua, ub;
1254
	    int sw = 0 ;
1314
		int sw = 0;
1255
	    int whole = 1 ;
1315
		int whole = 1;
1256
	    ulong m = LINK_NONE ;
1316
		ulong m = LINK_NONE;
1257
	    EXP c = DEREF_exp ( exp_if_stmt_cond ( e ) ) ;
1317
		EXP c = DEREF_exp(exp_if_stmt_cond(e));
1258
	    EXP a = DEREF_exp ( exp_if_stmt_true_code ( e ) ) ;
1318
		EXP a = DEREF_exp(exp_if_stmt_true_code(e));
1259
	    EXP b = DEREF_exp ( exp_if_stmt_false_code ( e ) ) ;
1319
		EXP b = DEREF_exp(exp_if_stmt_false_code(e));
1260
 
1320
 
1261
	    /* Check for labelled statements */
1321
		/* Check for labelled statements */
1262
	    IDENTIFIER lab = DEREF_id ( exp_if_stmt_label ( e ) ) ;
1322
		IDENTIFIER lab = DEREF_id(exp_if_stmt_label(e));
1263
	    if ( !IS_NULL_id ( lab ) ) {
1323
		if (!IS_NULL_id(lab)) {
1264
		n = DEREF_ulong ( id_no ( lab ) ) ;
1324
			n = DEREF_ulong(id_no(lab));
1265
		if ( n != LINK_NONE ) whole = 0 ;
1325
			if (n != LINK_NONE) {
-
 
1326
				whole = 0;
1266
	    }
1327
			}
-
 
1328
		}
1267
	    n = unit_no ( bs, lab, VAR_label, whole ) ;
1329
		n = unit_no(bs, lab, VAR_label, whole);
1268
	    if ( whole ) {
1330
		if (whole) {
1269
		/* Introduce conditional label */
1331
			/* Introduce conditional label */
1270
		ENC_conditional ( bs ) ;
1332
			ENC_conditional(bs);
1271
		ENC_make_label ( bs, n ) ;
1333
			ENC_make_label(bs, n);
1272
	    }
1334
		}
1273
	    c = simplify_cond ( c, &sw ) ;
1335
		c = simplify_cond(c, &sw);
1274
	    if ( sw ) {
1336
		if (sw) {
1275
		/* Switch conditions */
1337
			/* Switch conditions */
1276
		EXP d = a ;
1338
			EXP d = a;
1277
		a = b ;
1339
			a = b;
1278
		b = d ;
1340
			b = d;
1279
		m = n ;
1341
			m = n;
1280
		n = LINK_NONE ;
1342
			n = LINK_NONE;
1281
	    }
1343
		}
1282
	    if ( !IS_NULL_exp ( a ) ) {
1344
		if (!IS_NULL_exp(a)) {
1283
		ENC_SEQ_SMALL ( bs, 1 ) ;
1345
			ENC_SEQ_SMALL(bs, 1);
1284
	    }
1346
		}
1285
	    bs = enc_condition ( bs, c, n, m ) ;
1347
		bs = enc_condition(bs, c, n, m);
1286
	    ub = unreached_code ;
1348
		ub = unreached_code;
1287
	    if ( !IS_NULL_exp ( a ) ) {
1349
		if (!IS_NULL_exp(a)) {
1288
		bs = enc_stmt_exp ( bs, a, t, use ) ;
1350
			bs = enc_stmt_exp(bs, a, t, use);
1289
	    }
1351
		}
1290
	    ua = unreached_code ;
1352
		ua = unreached_code;
1291
	    if ( whole ) {
1353
		if (whole) {
1292
		/* Conditional label body */
1354
			/* Conditional label body */
1293
		unreached_code = ub ;
1355
			unreached_code = ub;
1294
		bs = enc_stmt_exp ( bs, b, t, use ) ;
1356
			bs = enc_stmt_exp(bs, b, t, use);
1295
		ub = unreached_code ;
1357
			ub = unreached_code;
1296
		clear_no ( lab ) ;
1358
			clear_no(lab);
1297
	    }
1359
		}
-
 
1360
		unreached_code = (ua && ub);
-
 
1361
		break;
-
 
1362
	}
-
 
1363
 
-
 
1364
	case exp_hash_if_tag: {
-
 
1365
		/* Conditional compilations */
-
 
1366
		int ua, ub;
-
 
1367
		BITSTREAM *ts;
-
 
1368
		EXP c = DEREF_exp(exp_hash_if_cond(e));
-
 
1369
		EXP a = DEREF_exp(exp_hash_if_true_code(e));
-
 
1370
		EXP b = DEREF_exp(exp_hash_if_false_code(e));
-
 
1371
		ENC_exp_cond(bs);
-
 
1372
		bs = enc_exp(bs, c);
-
 
1373
		ts = start_bitstream(NIL(FILE), bs->link);
-
 
1374
		ub = unreached_code;
-
 
1375
		ts = enc_stmt_exp(ts, a, t, use);
-
 
1376
		ua = unreached_code;
-
 
1377
		bs = enc_bitstream(bs, ts);
-
 
1378
		ts = start_bitstream(NIL(FILE), bs->link);
-
 
1379
		unreached_code = ub;
-
 
1380
		ts = enc_stmt_exp(ts, b, t, use);
-
 
1381
		ub = unreached_code;
-
 
1382
		bs = enc_bitstream(bs, ts);
1298
	    unreached_code = ( ua && ub ) ;
1383
		unreached_code = (ua && ub);
-
 
1384
		break;
-
 
1385
	}
-
 
1386
 
-
 
1387
	case exp_location_tag: {
-
 
1388
		/* Location statements */
-
 
1389
		EXP a = DEREF_exp(exp_location_arg(e));
-
 
1390
		BITSTREAM *ts = enc_diag_begin(&bs);
-
 
1391
		ts = enc_stmt_exp(ts, a, t, use);
-
 
1392
		crt_enc_loc = exp_location_end(e);
-
 
1393
		bs = enc_diag_end(bs, ts, a, 0);
1299
	    break ;
1394
		break;
1300
	}
1395
	}
1301
 
1396
 
1302
	case exp_hash_if_tag : {
1397
	case exp_comma_tag: {
1303
	    /* Conditional compilations */
1398
		/* Comma expressions */
1304
	    int ua, ub ;
1399
		EXP a;
1305
	    BITSTREAM *ts ;
-
 
1306
	    EXP c = DEREF_exp ( exp_hash_if_cond ( e ) ) ;
1400
		LIST(EXP)p = DEREF_list(exp_comma_args(e));
1307
	    EXP a = DEREF_exp ( exp_hash_if_true_code ( e ) ) ;
1401
		unsigned m = LENGTH_list(p);
1308
	    EXP b = DEREF_exp ( exp_hash_if_false_code ( e ) ) ;
-
 
1309
	    ENC_exp_cond ( bs ) ;
1402
		if (m > 1) {
1310
	    bs = enc_exp ( bs, c ) ;
1403
			ENC_SEQUENCE(bs, m - 1);
1311
	    ts = start_bitstream ( NIL ( FILE ), bs->link ) ;
-
 
-
 
1404
		}
1312
	    ub = unreached_code ;
1405
		for (;;) {
1313
	    ts = enc_stmt_exp ( ts, a, t, use ) ;
1406
			a = DEREF_exp(HEAD_list(p));
1314
	    ua = unreached_code ;
1407
			p = TAIL_list(p);
1315
	    bs = enc_bitstream ( bs, ts ) ;
1408
			if (IS_NULL_list(p)) {
1316
	    ts = start_bitstream ( NIL ( FILE ), bs->link ) ;
-
 
1317
	    unreached_code = ub ;
1409
				break;
-
 
1410
			}
1318
	    ts = enc_stmt_exp ( ts, b, t, use ) ;
1411
			bs = enc_stmt_exp(bs, a, type_void, 0);
-
 
1412
		}
1319
	    ub = unreached_code ;
1413
		if (use != -1) {
1320
	    bs = enc_bitstream ( bs, ts ) ;
1414
			bs = enc_stmt_exp(bs, a, t, use);
1321
	    unreached_code = ( ua && ub ) ;
-
 
-
 
1415
		}
1322
	    break ;
1416
		break;
1323
	}
1417
	}
1324
 
1418
 
1325
	case exp_location_tag : {
1419
	case exp_paren_tag:
1326
	    /* Location statements */
1420
	case exp_copy_tag: {
1327
	    EXP a = DEREF_exp ( exp_location_arg ( e ) ) ;
1421
		/* Parenthesised expressions */
1328
	    BITSTREAM *ts = enc_diag_begin ( &bs ) ;
1422
		EXP a = DEREF_exp(exp_paren_etc_arg(e));
1329
	    ts = enc_stmt_exp ( ts, a, t, use ) ;
1423
		bs = enc_stmt_exp(bs, a, t, use);
1330
	    crt_enc_loc = exp_location_end ( e ) ;
-
 
1331
	    bs = enc_diag_end ( bs, ts, a, 0 ) ;
-
 
1332
	    break ;
1424
		break;
1333
	}
1425
	}
1334
 
1426
 
1335
	case exp_comma_tag : {
-
 
1336
	    /* Comma expressions */
-
 
1337
	    EXP a ;
-
 
1338
	    LIST ( EXP ) p = DEREF_list ( exp_comma_args ( e ) ) ;
-
 
1339
	    unsigned m = LENGTH_list ( p ) ;
-
 
1340
	    if ( m > 1 ) ENC_SEQUENCE ( bs, m - 1 ) ;
-
 
1341
	    for ( ; ; ) {
-
 
1342
		a = DEREF_exp ( HEAD_list ( p ) ) ;
-
 
1343
		p = TAIL_list ( p ) ;
-
 
1344
		if ( IS_NULL_list ( p ) ) break ;
-
 
1345
		bs = enc_stmt_exp ( bs, a, type_void, 0 ) ;
-
 
1346
	    }
-
 
1347
	    if ( use != -1 ) {
-
 
1348
		bs = enc_stmt_exp ( bs, a, t, use ) ;
-
 
1349
	    }
-
 
1350
	    break ;
-
 
1351
	}
-
 
1352
 
-
 
1353
	case exp_paren_tag :
-
 
1354
	case exp_copy_tag : {
-
 
1355
	    /* Parenthesised expressions */
-
 
1356
	    EXP a = DEREF_exp ( exp_paren_etc_arg ( e ) ) ;
-
 
1357
	    bs = enc_stmt_exp ( bs, a, t, use ) ;
-
 
1358
	    break ;
-
 
1359
	}
-
 
1360
 
-
 
1361
	case exp_contents_tag : {
1427
	case exp_contents_tag: {
1362
	    /* Contents expressions */
1428
		/* Contents expressions */
1363
	    if ( use == 0 ) {
1429
		if (use == 0) {
1364
		EXP a = DEREF_exp ( exp_contents_ptr ( e ) ) ;
1430
			EXP a = DEREF_exp(exp_contents_ptr(e));
1365
		bs = enc_exp ( bs, a ) ;
1431
			bs = enc_exp(bs, a);
1366
		break ;
1432
			break;
1367
	    }
1433
		}
1368
	    goto default_lab ;
1434
		goto default_lab;
1369
	}
1435
	}
1370
 
1436
 
1371
	default :
1437
	default:
1372
	default_lab : {
1438
default_lab: {
1373
	    /* Simple expressions */
1439
		      /* Simple expressions */
1374
	    switch ( use ) {
1440
		      switch (use) {
1375
		case 2 : {
1441
		      case 2: {
1376
		    bs = enc_addr_exp ( bs, t, e ) ;
1442
			      bs = enc_addr_exp(bs, t, e);
1377
		    break ;
1443
			      break;
1378
		}
1444
		      }
1379
		case 3 : {
1445
		      case 3: {
1380
		    bs = enc_cont_exp ( bs, t, e ) ;
1446
			      bs = enc_cont_exp(bs, t, e);
1381
		    break ;
1447
			      break;
1382
		}
1448
		      }
1383
		default : {
1449
		      default : {
1384
		    bs = enc_exp ( bs, e ) ;
1450
			      bs = enc_exp(bs, e);
1385
		    break ;
1451
			      break;
1386
		}
1452
		      }
1387
	    }
1453
		      }
1388
	    break ;
1454
		      break;
-
 
1455
	      }
1389
	}
1456
	}
1390
    }
-
 
1391
    return ( bs ) ;
1457
	return (bs);
1392
}
1458
}
1393
 
1459
 
1394
 
1460
 
1395
#endif /* TDF_OUTPUT */
1461
#endif /* TDF_OUTPUT */