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

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

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

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

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

Warning: Undefined variable $m in /usr/local/www/websvn.planix.org/include/diff_util.php on line 251
WebSVN – tendra.SVN – Diff – /branches/tendra5/src/producers/common/output/init.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 66... Line 96...
66
#if TDF_OUTPUT
96
#if TDF_OUTPUT
67
 
97
 
68
 
98
 
69
/*
99
/*
70
    INITIALISER FLAGS
100
    INITIALISER FLAGS
71
 
101
 
72
    The flag in_static_init is set to true when encoding a static
102
    The flag in_static_init is set to true when encoding a static
73
    initialiser.  The flag in_dynamic_init is set to true when encoding
103
    initialiser.  The flag in_dynamic_init is set to true when encoding
74
    a dynamic initialiser.
104
    a dynamic initialiser.
75
*/
105
*/
76
 
106
 
77
int in_static_init = 0 ;
107
int in_static_init = 0;
78
int in_dynamic_init = 0 ;
108
int in_dynamic_init = 0;
79
 
109
 
80
 
110
 
81
/*
111
/*
82
    ENCODE AN AGGREGATE ARRAY INITIALISER
112
    ENCODE AN AGGREGATE ARRAY INITIALISER
83
 
113
 
84
    This routine adds the aggregate initialiser for an array of type t,
114
    This routine adds the aggregate initialiser for an array of type t,
85
    given by the aggregate expression e followed by n zeros, to the
115
    given by the aggregate expression e followed by n zeros, to the
86
    bitstream bs.  n may be null to indicate the absence of padding.
116
    bitstream bs.  n may be null to indicate the absence of padding.
87
*/
117
*/
88
 
118
 
89
BITSTREAM *enc_init_array
119
BITSTREAM *
90
    PROTO_N ( ( bs, e, n, t ) )
-
 
91
    PROTO_T ( BITSTREAM *bs X EXP e X NAT n X TYPE t )
120
enc_init_array(BITSTREAM *bs, EXP e, NAT n, TYPE t)
92
{
121
{
93
    LIST ( EXP ) p = DEREF_list ( exp_aggregate_args ( e ) ) ;
122
	LIST(EXP)p = DEREF_list(exp_aggregate_args(e));
94
    TYPE s = DEREF_type ( type_array_sub ( t ) ) ;
123
	TYPE s = DEREF_type(type_array_sub(t));
95
    unsigned tag = TAG_type ( s ) ;
124
	unsigned tag = TAG_type(s);
96
    if ( tag == type_integer_tag || tag == type_enumerate_tag ) {
125
	if (tag == type_integer_tag || tag == type_enumerate_tag) {
97
	unsigned mask = 0 ;
126
		unsigned mask = 0;
98
	unsigned long len = 0 ;
127
		unsigned long len = 0;
99
	LIST ( EXP ) q = p ;
128
		LIST(EXP)q = p;
100
	LIST ( unsigned ) vs = NULL_list ( unsigned ) ;
129
		LIST(unsigned)vs = NULL_list(unsigned);
101
	while ( !IS_NULL_list ( q ) ) {
130
		while (!IS_NULL_list(q)) {
102
	    /* Check for arrays of integers */
131
			/* Check for arrays of integers */
103
	    unsigned v = 0 ;
132
			unsigned v = 0;
104
	    EXP a = DEREF_exp ( HEAD_list ( q ) ) ;
133
			EXP a = DEREF_exp(HEAD_list(q));
105
	    if ( !IS_NULL_exp ( a ) ) {
134
			if (!IS_NULL_exp(a)) {
106
		NAT m ;
135
				NAT m;
107
		unsigned tm ;
136
				unsigned tm;
108
		if ( !IS_exp_int_lit ( a ) ) break ;
137
				if (!IS_exp_int_lit(a)) {
-
 
138
					break;
-
 
139
				}
109
		m = DEREF_nat ( exp_int_lit_nat ( a ) ) ;
140
				m = DEREF_nat(exp_int_lit_nat(a));
110
		tm = TAG_nat ( m ) ;
141
				tm = TAG_nat(m);
111
		if ( tm == nat_calc_tag ) {
142
				if (tm == nat_calc_tag) {
112
		    /* Allow for character literals */
143
					/* Allow for character literals */
113
		    a = eval_exp ( a, 1 ) ;
144
					a = eval_exp(a, 1);
114
		    if ( !IS_exp_int_lit ( a ) ) break ;
145
					if (!IS_exp_int_lit(a)) {
-
 
146
						break;
-
 
147
					}
115
		    m = DEREF_nat ( exp_int_lit_nat ( a ) ) ;
148
					m = DEREF_nat(exp_int_lit_nat(a));
116
		    tm = TAG_nat ( m ) ;
149
					tm = TAG_nat(m);
117
		}
150
				}
118
		if ( tm != nat_small_tag ) break ;
151
				if (tm != nat_small_tag) {
-
 
152
					break;
-
 
153
				}
119
		v = DEREF_unsigned ( nat_small_value ( m ) ) ;
154
				v = DEREF_unsigned(nat_small_value(m));
120
	    }
155
			}
121
	    CONS_unsigned ( v, vs, vs ) ;
156
			CONS_unsigned(v, vs, vs);
122
	    mask |= v ;
157
			mask |= v;
123
	    len++ ;
158
			len++;
124
	    q = TAIL_list ( q ) ;
159
			q = TAIL_list(q);
125
	}
160
		}
126
	if ( IS_NULL_list ( q ) ) {
161
		if (IS_NULL_list(q)) {
127
	    /* Array of small integers */
162
			/* Array of small integers */
128
	    if ( mask == 0 ) {
163
			if (mask == 0) {
129
		/* All zeros */
164
				/* All zeros */
130
		bs = enc_null_exp ( bs, t ) ;
165
				bs = enc_null_exp(bs, t);
131
	    } else {
166
			} else {
132
		/* Encode as a string */
167
				/* Encode as a string */
133
		LIST ( unsigned ) us ;
168
				LIST(unsigned)us;
134
		unsigned bits = no_bits ( mask ) ;
169
				unsigned bits = no_bits(mask);
135
		if ( !IS_NULL_nat ( n ) ) {
170
				if (!IS_NULL_nat(n)) {
136
		    /* Check for padding */
171
					/* Check for padding */
137
		    unsigned long pad = get_nat_value ( n ) ;
172
					unsigned long pad = get_nat_value(n);
138
		    if ( pad <= STRING_PADDING ) {
173
					if (pad <= STRING_PADDING) {
139
			len += pad ;
174
						len += pad;
140
			n = NULL_nat ;
175
						n = NULL_nat;
141
		    } else {
176
					} else {
142
			ENC_concat_nof ( bs ) ;
177
						ENC_concat_nof(bs);
143
		    }
178
					}
144
		}
179
				}
145
		ENC_make_nof_int ( bs ) ;
180
				ENC_make_nof_int(bs);
146
		bs = enc_variety ( bs, s ) ;
181
				bs = enc_variety(bs, s);
147
		ENC_make_string ( bs ) ;
182
				ENC_make_string(bs);
148
		ENC_INT ( bs, bits ) ;
183
				ENC_INT(bs, bits);
149
		ENC_INT ( bs, len ) ;
184
				ENC_INT(bs, len);
150
		vs = REVERSE_list ( vs ) ;
185
				vs = REVERSE_list(vs);
151
		us = vs ;
186
				us = vs;
152
		while ( !IS_NULL_list ( us ) ) {
187
				while (!IS_NULL_list(us)) {
153
		    /* Encode each element */
188
					/* Encode each element */
-
 
189
					unsigned v =
154
		    unsigned v = DEREF_unsigned ( HEAD_list ( us ) ) ;
190
					    DEREF_unsigned(HEAD_list(us));
155
		    ENC_BITS ( bs, bits, v ) ;
191
					ENC_BITS(bs, bits, v);
156
		    len-- ;
192
					len--;
157
		    us = TAIL_list ( us ) ;
193
					us = TAIL_list(us);
158
		}
194
				}
159
		while ( len ) {
195
				while (len) {
160
		    /* Encode explicit padding */
196
					/* Encode explicit padding */
161
		    ENC_BITS ( bs, bits, 0 ) ;
197
					ENC_BITS(bs, bits, 0);
162
		    len-- ;
198
					len--;
163
		}
199
				}
164
		if ( !IS_NULL_nat ( n ) ) {
200
				if (!IS_NULL_nat(n)) {
165
		    /* Encode remaining padding */
201
					/* Encode remaining padding */
166
		    ENC_n_copies ( bs ) ;
202
					ENC_n_copies(bs);
167
		    bs = enc_nat ( bs, n, 1 ) ;
203
					bs = enc_nat(bs, n, 1);
168
		    bs = enc_null_exp ( bs, s ) ;
204
					bs = enc_null_exp(bs, s);
169
		}
205
				}
170
	    }
206
			}
171
	    DESTROY_list ( vs, SIZE_unsigned ) ;
207
			DESTROY_list(vs, SIZE_unsigned);
172
	    return ( bs ) ;
208
			return (bs);
173
	}
209
		}
174
	DESTROY_list ( vs, SIZE_unsigned ) ;
210
		DESTROY_list(vs, SIZE_unsigned);
175
    }
211
	}
176
 
212
 
177
    /* Simple list */
213
	/* Simple list */
178
    if ( !IS_NULL_nat ( n ) ) {
214
	if (!IS_NULL_nat(n)) {
179
	ENC_concat_nof ( bs ) ;
215
		ENC_concat_nof(bs);
180
    }
216
	}
181
    ENC_make_nof ( bs ) ;
217
	ENC_make_nof(bs);
182
    bs = enc_exp_list ( bs, p ) ;
218
	bs = enc_exp_list(bs, p);
183
    if ( !IS_NULL_nat ( n ) ) {
219
	if (!IS_NULL_nat(n)) {
184
	ENC_n_copies ( bs ) ;
220
		ENC_n_copies(bs);
185
	bs = enc_nat ( bs, n, 1 ) ;
221
		bs = enc_nat(bs, n, 1);
186
	bs = enc_null_exp ( bs, s ) ;
222
		bs = enc_null_exp(bs, s);
187
    }
223
	}
188
    return ( bs ) ;
224
	return (bs);
189
}
225
}
190
 
226
 
191
 
227
 
192
/*
228
/*
193
    ENCODE AN AGGREGATE CLASS INITIALISER
229
    ENCODE AN AGGREGATE CLASS INITIALISER
194
 
230
 
195
    This routine adds the aggregate initialiser for an object of class
231
    This routine adds the aggregate initialiser for an object of class
196
    type t given by the aggregate expression p to the bitstream bs.  Note
232
    type t given by the aggregate expression p to the bitstream bs.  Note
197
    that t cannot have any base classes.
233
    that t cannot have any base classes.
198
*/
234
*/
199
 
235
 
200
BITSTREAM *enc_init_class
236
BITSTREAM *
201
    PROTO_N ( ( bs, e, ct ) )
-
 
202
    PROTO_T ( BITSTREAM *bs X EXP e X CLASS_TYPE ct )
237
enc_init_class(BITSTREAM *bs, EXP e, CLASS_TYPE ct)
203
{
238
{
204
    LIST ( EXP ) p = DEREF_list ( exp_aggregate_args ( e ) ) ;
239
	LIST(EXP)p = DEREF_list(exp_aggregate_args(e));
205
    LIST ( OFFSET ) q = DEREF_list ( exp_aggregate_offs ( e ) ) ;
240
	LIST(OFFSET)q = DEREF_list(exp_aggregate_offs(e));
206
    unsigned m = LENGTH_list ( p ) ;
241
	unsigned m = LENGTH_list(p);
207
    IGNORE compile_class ( ct ) ;
242
	IGNORE compile_class(ct);
208
    if ( m == 0 ) {
243
	if (m == 0) {
209
	/* Deal with empty classes */
244
		/* Deal with empty classes */
210
	ENC_make_value ( bs ) ;
245
		ENC_make_value(bs);
211
	bs = enc_ctype ( bs, ct ) ;
246
		bs = enc_ctype(bs, ct);
212
    } else {
247
	} else {
213
	ENC_make_compound ( bs ) ;
248
		ENC_make_compound(bs);
214
	ENC_shape_offset ( bs ) ;
249
		ENC_shape_offset(bs);
215
	bs = enc_ctype ( bs, ct ) ;
250
		bs = enc_ctype(bs, ct);
216
	ENC_LIST ( bs, m + m ) ;
251
		ENC_LIST(bs, m + m);
217
	while ( !IS_NULL_list ( p ) ) {
252
		while (!IS_NULL_list(p)) {
218
	    /* Scan aggregate initialiser */
253
			/* Scan aggregate initialiser */
219
	    EXP a = DEREF_exp ( HEAD_list ( p ) ) ;
254
			EXP a = DEREF_exp(HEAD_list(p));
220
	    OFFSET off = DEREF_off ( HEAD_list ( q ) ) ;
255
			OFFSET off = DEREF_off(HEAD_list(q));
221
	    bs = enc_offset ( bs, off ) ;
256
			bs = enc_offset(bs, off);
222
	    bs = enc_exp ( bs, a ) ;
257
			bs = enc_exp(bs, a);
223
	    q = TAIL_list ( q ) ;
258
			q = TAIL_list(q);
224
	    p = TAIL_list ( p ) ;
259
			p = TAIL_list(p);
225
	}
260
		}
226
    }
261
	}
227
    return ( bs ) ;
262
	return (bs);
228
}
263
}
229
 
264
 
230
 
265
 
231
/*
266
/*
232
    ALLOCATION LOOP COUNTER
267
    ALLOCATION LOOP COUNTER
233
 
268
 
234
    This variable is used to hold the tag of the loop counter variable
269
    This variable is used to hold the tag of the loop counter variable
235
    which is used in new-initialiser expressions.
270
    which is used in new-initialiser expressions.
236
*/
271
*/
237
 
272
 
238
static ulong alloc_counter = LINK_NONE ;
273
static ulong alloc_counter = LINK_NONE;
239
 
274
 
240
 
275
 
241
/*
276
/*
242
    DECLARE A LOOP COUNTER
277
    DECLARE A LOOP COUNTER
243
 
278
 
244
    This routine declares the pointer to s variable n to be the pointer
279
    This routine declares the pointer to s variable n to be the pointer
245
    variable m plus the offset off and the offset of the type t.
280
    variable m plus the offset off and the offset of the type t.
246
*/
281
*/
247
 
282
 
248
static BITSTREAM *enc_loop_decl
283
static BITSTREAM *
249
    PROTO_N ( ( bs, n, m, s, cnt, off, t ) )
-
 
250
    PROTO_T ( BITSTREAM *bs X ulong n X ulong m X TYPE s X
284
enc_loop_decl(BITSTREAM *bs, ulong n, ulong m, TYPE s, int cnt, OFFSET off,
251
	      int cnt X OFFSET off X TYPE t )
285
	      TYPE t)
252
{
286
{
253
    DECL_SPEC ds = dspec_none ;
287
	DECL_SPEC ds = dspec_none;
254
    if ( n == alloc_counter ) ds = dspec_mutable ;
288
	if (n == alloc_counter) {
-
 
289
		ds = dspec_mutable;
-
 
290
	}
255
    if ( cnt ) cnt = 2 ;
291
	if (cnt) {
-
 
292
		cnt = 2;
-
 
293
	}
256
    ENC_variable ( bs ) ;
294
	ENC_variable(bs);
257
    bs = enc_access ( bs, ds ) ;
295
	bs = enc_access(bs, ds);
258
    ENC_make_tag ( bs, n ) ;
296
	ENC_make_tag(bs, n);
259
    if ( IS_NULL_type ( t ) ) {
297
	if (IS_NULL_type(t)) {
260
	bs = enc_dummy_exp ( bs, s, m, off, cnt, 0 ) ;
298
		bs = enc_dummy_exp(bs, s, m, off, cnt, 0);
261
    } else {
299
	} else {
262
	ENC_add_to_ptr ( bs ) ;
300
		ENC_add_to_ptr(bs);
263
	bs = enc_dummy_exp ( bs, s, m, off, cnt, 0 ) ;
301
		bs = enc_dummy_exp(bs, s, m, off, cnt, 0);
264
	bs = enc_shape_offset ( bs, t ) ;
302
		bs = enc_shape_offset(bs, t);
265
    }
303
	}
266
    return ( bs ) ;
304
	return (bs);
267
}
305
}
268
 
306
 
269
 
307
 
270
/*
308
/*
271
    TEST A LOOP COUNTER
309
    TEST A LOOP COUNTER
272
 
310
 
273
    This routine compares the pointer to t variables n and m using test
311
    This routine compares the pointer to t variables n and m using test
274
    tst, jumping to label lab if appropriate.
312
    tst, jumping to label lab if appropriate.
275
*/
313
*/
276
 
314
 
277
static BITSTREAM *enc_loop_test
315
static BITSTREAM *
278
    PROTO_N ( ( bs, n, m, t, lab, tst ) )
-
 
279
    PROTO_T ( BITSTREAM *bs X ulong n X ulong m X TYPE t X
316
enc_loop_test(BITSTREAM *bs, ulong n, ulong m, TYPE t, ulong lab, NTEST tst)
280
	      ulong lab X NTEST tst )
-
 
281
{
317
{
282
    ENC_pointer_test ( bs ) ;
318
	ENC_pointer_test(bs);
283
    ENC_OFF ( bs ) ;
319
	ENC_OFF(bs);
284
    bs = enc_ntest ( bs, tst ) ;
320
	bs = enc_ntest(bs, tst);
285
    ENC_make_label ( bs, lab ) ;
321
	ENC_make_label(bs, lab);
286
    ENC_contents ( bs ) ;
322
	ENC_contents(bs);
287
    ENC_pointer ( bs ) ;
323
	ENC_pointer(bs);
288
    bs = enc_alignment ( bs, t ) ;
324
	bs = enc_alignment(bs, t);
289
    ENC_obtain_tag ( bs ) ;
325
	ENC_obtain_tag(bs);
290
    ENC_make_tag ( bs, n ) ;
326
	ENC_make_tag(bs, n);
291
    if ( m == LINK_NONE ) {
327
	if (m == LINK_NONE) {
292
	ENC_make_null_ptr ( bs ) ;
328
		ENC_make_null_ptr(bs);
293
	bs = enc_alignment ( bs, t ) ;
329
		bs = enc_alignment(bs, t);
294
    } else {
330
	} else {
295
	ENC_contents ( bs ) ;
331
		ENC_contents(bs);
296
	ENC_pointer ( bs ) ;
332
		ENC_pointer(bs);
297
	bs = enc_alignment ( bs, t ) ;
333
		bs = enc_alignment(bs, t);
298
	ENC_obtain_tag ( bs ) ;
334
		ENC_obtain_tag(bs);
299
	ENC_make_tag ( bs, m ) ;
335
		ENC_make_tag(bs, m);
300
    }
336
	}
301
    return ( bs ) ;
337
	return (bs);
302
}
338
}
303
 
339
 
304
 
340
 
305
/*
341
/*
306
    TEST A BOOLEAN FLAG
342
    TEST A BOOLEAN FLAG
307
 
343
 
308
    This routine tests the flag given by the tag n, and-ed with a if this
344
    This routine tests the flag given by the tag n, and-ed with a if this
309
    is not zero, against zero.  A further s expressions to be evaluated
345
    is not zero, against zero.  A further s expressions to be evaluated
310
    if tst is true must be added together with the terminating expression
346
    if tst is true must be added together with the terminating expression
311
    of the conditional.
347
    of the conditional.
312
*/
348
*/
313
 
349
 
314
BITSTREAM *enc_flag_test
350
BITSTREAM *
315
    PROTO_N ( ( bs, n, s, a, tst ) )
-
 
316
    PROTO_T ( BITSTREAM *bs X ulong n X unsigned s X int a X NTEST tst )
351
enc_flag_test(BITSTREAM *bs, ulong n, unsigned s, int a, NTEST tst)
317
{
352
{
318
    ulong lab = unit_no ( bs, NULL_id, VAR_label, 1 ) ;
353
	ulong lab = unit_no(bs, NULL_id, VAR_label, 1);
319
    ENC_conditional ( bs ) ;
354
	ENC_conditional(bs);
320
    ENC_make_label ( bs, lab ) ;
355
	ENC_make_label(bs, lab);
-
 
356
	if (s) {
321
    if ( s ) ENC_SEQUENCE ( bs, s ) ;
357
		ENC_SEQUENCE(bs, s);
-
 
358
	}
322
    ENC_integer_test ( bs ) ;
359
	ENC_integer_test(bs);
323
    ENC_OFF ( bs ) ;
360
	ENC_OFF(bs);
324
    bs = enc_ntest ( bs, tst ) ;
361
	bs = enc_ntest(bs, tst);
325
    ENC_make_label ( bs, lab ) ;
362
	ENC_make_label(bs, lab);
-
 
363
	if (a) {
326
    if ( a ) ENC_and ( bs ) ;
364
		ENC_and(bs);
-
 
365
	}
327
    ENC_contents ( bs ) ;
366
	ENC_contents(bs);
328
    bs = enc_shape ( bs, type_sint ) ;
367
	bs = enc_shape(bs, type_sint);
329
    ENC_obtain_tag ( bs ) ;
368
	ENC_obtain_tag(bs);
330
    ENC_make_tag ( bs, n ) ;
369
	ENC_make_tag(bs, n);
-
 
370
	if (a) {
331
    if ( a ) bs = enc_make_int ( bs, type_sint, a ) ;
371
		bs = enc_make_int(bs, type_sint, a);
-
 
372
	}
332
    bs = enc_make_int ( bs, type_sint, 0 ) ;
373
	bs = enc_make_int(bs, type_sint, 0);
333
    return ( bs ) ;
374
	return (bs);
334
}
375
}
335
 
376
 
336
 
377
 
337
/*
378
/*
338
    INCREMENT A LOOP COUNTER
379
    INCREMENT A LOOP COUNTER
339
 
380
 
340
    This routine increments (or decrements if neg is true) the pointer
381
    This routine increments (or decrements if neg is true) the pointer
341
    variable n by the offset of the type t.
382
    variable n by the offset of the type t.
342
*/
383
*/
343
 
384
 
344
static BITSTREAM *enc_loop_incr
385
static BITSTREAM *
345
    PROTO_N ( ( bs, n, t, neg ) )
-
 
346
    PROTO_T ( BITSTREAM *bs X ulong n X TYPE t X int neg )
386
enc_loop_incr(BITSTREAM *bs, ulong n, TYPE t, int neg)
347
{
387
{
348
    ENC_assign ( bs ) ;
388
	ENC_assign(bs);
349
    ENC_obtain_tag ( bs ) ;
389
	ENC_obtain_tag(bs);
350
    ENC_make_tag ( bs, n ) ;
390
	ENC_make_tag(bs, n);
351
    ENC_add_to_ptr ( bs ) ;
391
	ENC_add_to_ptr(bs);
352
    ENC_contents ( bs ) ;
392
	ENC_contents(bs);
353
    ENC_pointer ( bs ) ;
393
	ENC_pointer(bs);
354
    bs = enc_alignment ( bs, t ) ;
394
	bs = enc_alignment(bs, t);
355
    ENC_obtain_tag ( bs ) ;
395
	ENC_obtain_tag(bs);
356
    ENC_make_tag ( bs, n ) ;
396
	ENC_make_tag(bs, n);
-
 
397
	if (neg) {
357
    if ( neg ) ENC_offset_negate ( bs ) ;
398
		ENC_offset_negate(bs);
-
 
399
	}
358
    bs = enc_shape_offset ( bs, t ) ;
400
	bs = enc_shape_offset(bs, t);
359
    return ( bs ) ;
401
	return (bs);
360
}
402
}
361
 
403
 
362
 
404
 
363
/*
405
/*
364
    FIND A TERMINATOR TYPE
406
    FIND A TERMINATOR TYPE
365
 
407
 
366
    This routine returns the type for a terminator for a value of type t.
408
    This routine returns the type for a terminator for a value of type t.
367
*/
409
*/
368
 
410
 
369
static TYPE find_count_type
411
static TYPE
370
    PROTO_N ( ( t ) )
-
 
371
    PROTO_T ( TYPE t )
412
find_count_type(TYPE t)
372
{
413
{
373
    if ( !IS_NULL_type ( t ) ) {
414
	if (!IS_NULL_type(t)) {
374
	if ( IS_type_array ( t ) ) {
415
		if (IS_type_array(t)) {
375
	    /* Handle arrays */
416
			/* Handle arrays */
376
	    NAT n = DEREF_nat ( type_array_size ( t ) ) ;
417
			NAT n = DEREF_nat(type_array_size(t));
377
	    TYPE s = DEREF_type ( type_array_sub ( t ) ) ;
418
			TYPE s = DEREF_type(type_array_sub(t));
378
	    s = find_count_type ( s ) ;
419
			s = find_count_type(s);
379
	    MAKE_type_array ( cv_none, s, n, t ) ;
420
			MAKE_type_array(cv_none, s, n, t);
380
	} else {
421
		} else {
381
	    t = dummy_count ;
422
			t = dummy_count;
382
	}
423
		}
383
    }
424
	}
384
    return ( t ) ;
425
	return (t);
385
}
426
}
386
 
427
 
387
 
428
 
388
/*
429
/*
389
    DECLARE A TERMINATOR COUNT VARIABLE
430
    DECLARE A TERMINATOR COUNT VARIABLE
390
 
431
 
391
    This routine introduces a local variable for the terminator count
432
    This routine introduces a local variable for the terminator count
392
    variable given by d.
433
    variable given by d.
393
*/
434
*/
394
 
435
 
395
static BITSTREAM *enc_count_decl
436
static BITSTREAM *
396
    PROTO_N ( ( bs, d, s, pm ) )
-
 
397
    PROTO_T ( BITSTREAM *bs X EXP d X TYPE s X ulong *pm )
437
enc_count_decl(BITSTREAM *bs, EXP d, TYPE s, ulong *pm)
398
{
438
{
399
    if ( IS_exp_destr ( d ) ) {
439
	if (IS_exp_destr(d)) {
400
	EXP c = DEREF_exp ( exp_destr_count ( d ) ) ;
440
		EXP c = DEREF_exp(exp_destr_count(d));
401
	if ( !IS_NULL_exp ( c ) ) {
441
		if (!IS_NULL_exp(c)) {
402
	    int cnt = DEREF_int ( exp_dummy_cont ( c ) ) ;
442
			int cnt = DEREF_int(exp_dummy_cont(c));
403
	    if ( cnt == 0 ) {
443
			if (cnt == 0) {
404
		/* Variable not yet introduced */
444
				/* Variable not yet introduced */
405
		TYPE t = dummy_count ;
445
				TYPE t = dummy_count;
406
		ulong n = unit_no ( bs, NULL_id, VAR_tag, 1 ) ;
446
				ulong n = unit_no(bs, NULL_id, VAR_tag, 1);
407
		ulong m = DEREF_ulong ( exp_dummy_no ( c ) ) ;
447
				ulong m = DEREF_ulong(exp_dummy_no(c));
408
		s = find_count_type ( s ) ;
448
				s = find_count_type(s);
409
		bs = enc_loop_decl ( bs, n, m, t, 0, NULL_off, s ) ;
449
				bs = enc_loop_decl(bs, n, m, t, 0, NULL_off, s);
410
		COPY_int ( exp_dummy_cont ( c ), 2 ) ;
450
				COPY_int(exp_dummy_cont(c), 2);
411
		COPY_ulong ( exp_dummy_no ( c ), n ) ;
451
				COPY_ulong(exp_dummy_no(c), n);
412
		*pm = m ;
452
				*pm = m;
413
	    }
453
			}
-
 
454
		}
414
	}
455
	}
415
    }
-
 
416
    return ( bs ) ;
456
	return (bs);
417
}
457
}
418
 
458
 
419
 
459
 
420
/*
460
/*
421
    END A TERMINATOR COUNT VARIABLE
461
    END A TERMINATOR COUNT VARIABLE
422
 
462
 
423
    This routine ends the terminator count given by d.
463
    This routine ends the terminator count given by d.
424
*/
464
*/
425
 
465
 
426
static void enc_count_end
466
static void
427
    PROTO_N ( ( d, m ) )
-
 
428
    PROTO_T ( EXP d X ulong m )
467
enc_count_end(EXP d, ulong m)
429
{
468
{
430
    if ( IS_exp_destr ( d ) ) {
469
	if (IS_exp_destr(d)) {
431
	EXP c = DEREF_exp ( exp_destr_count ( d ) ) ;
470
		EXP c = DEREF_exp(exp_destr_count(d));
432
	if ( !IS_NULL_exp ( c ) && m != LINK_NONE ) {
471
		if (!IS_NULL_exp(c) && m != LINK_NONE) {
433
	    COPY_int ( exp_dummy_cont ( c ), 0 ) ;
472
			COPY_int(exp_dummy_cont(c), 0);
434
	    COPY_ulong ( exp_dummy_no ( c ), m ) ;
473
			COPY_ulong(exp_dummy_no(c), m);
435
	}
474
		}
436
    }
475
	}
437
    return ;
476
	return;
438
}
477
}
439
 
478
 
440
 
479
 
441
/*
480
/*
442
    INCREMENT A TERMINATOR COUNT VARIABLE
481
    INCREMENT A TERMINATOR COUNT VARIABLE
443
 
482
 
444
    This routine increments the terminator count variable given by d.
483
    This routine increments the terminator count variable given by d.
445
    Note that this is only done at the innermost level, i.e. when the
484
    Note that this is only done at the innermost level, i.e. when the
446
    associated type t is not an array.
485
    associated type t is not an array.
447
*/
486
*/
448
 
487
 
449
static BITSTREAM *enc_count_incr
488
static BITSTREAM *
450
    PROTO_N ( ( bs, d, neg, t ) )
-
 
451
    PROTO_T ( BITSTREAM *bs X EXP d X int neg X TYPE t )
489
enc_count_incr(BITSTREAM *bs, EXP d, int neg, TYPE t)
452
{
490
{
453
    if ( IS_exp_destr ( d ) && !IS_type_array ( t ) ) {
491
	if (IS_exp_destr(d) && !IS_type_array(t)) {
454
	EXP c = DEREF_exp ( exp_destr_count ( d ) ) ;
492
		EXP c = DEREF_exp(exp_destr_count(d));
455
	if ( !IS_NULL_exp ( c ) ) {
493
		if (!IS_NULL_exp(c)) {
456
	    ulong n = DEREF_ulong ( exp_dummy_no ( c ) ) ;
494
			ulong n = DEREF_ulong(exp_dummy_no(c));
457
	    bs = enc_loop_incr ( bs, n, dummy_count, neg ) ;
495
			bs = enc_loop_incr(bs, n, dummy_count, neg);
458
	    return ( bs ) ;
496
			return (bs);
-
 
497
		}
459
	}
498
	}
460
    }
-
 
461
    ENC_make_top ( bs ) ;
499
	ENC_make_top(bs);
462
    return ( bs ) ;
500
	return (bs);
463
}
501
}
464
 
502
 
465
 
503
 
466
/*
504
/*
467
    ENCODE A TERMINATOR TYPE
505
    ENCODE A TERMINATOR TYPE
468
 
506
 
469
    This routine adds the type of the terminator object corresponding to
507
    This routine adds the type of the terminator object corresponding to
470
    type t to the bitstream bs.
508
    type t to the bitstream bs.
471
*/
509
*/
472
 
510
 
473
BITSTREAM *enc_term_type
511
BITSTREAM *
474
    PROTO_N ( ( bs, t ) )
-
 
475
    PROTO_T ( BITSTREAM *bs X TYPE t )
512
enc_term_type(BITSTREAM *bs, TYPE t)
476
{
513
{
477
    while ( IS_type_array ( t ) ) {
514
	while (IS_type_array(t)) {
478
	/* Allow for arrays */
515
		/* Allow for arrays */
479
	NAT n = DEREF_nat ( type_array_size ( t ) ) ;
516
		NAT n = DEREF_nat(type_array_size(t));
480
	ENC_nof ( bs ) ;
517
		ENC_nof(bs);
481
	bs = enc_nat ( bs, n, 1 ) ;
518
		bs = enc_nat(bs, n, 1);
482
	t = DEREF_type ( type_array_sub ( t ) ) ;
519
		t = DEREF_type(type_array_sub(t));
483
    }
520
	}
484
    bs = enc_special ( bs, TOK_destr_type ) ;
521
	bs = enc_special(bs, TOK_destr_type);
485
    return ( bs ) ;
522
	return (bs);
486
}
523
}
487
 
524
 
488
 
525
 
489
/*
526
/*
490
    DEFINE A GLOBAL TERMINATOR OBJECT
527
    DEFINE A GLOBAL TERMINATOR OBJECT
491
 
528
 
492
    This routine defines a global terminator object corresponding to an
529
    This routine defines a global terminator object corresponding to an
493
    object of type t and destructor pd.
530
    object of type t and destructor pd.
494
*/
531
*/
495
 
532
 
496
void make_term_global
533
void
497
    PROTO_N ( ( t, pd ) )
-
 
498
    PROTO_T ( TYPE t X EXP *pd )
534
make_term_global(TYPE t, EXP *pd)
499
{
535
{
500
    EXP d = *pd ;
536
	EXP d = *pd;
501
    if ( !IS_NULL_exp ( d ) ) {
537
	if (!IS_NULL_exp(d)) {
502
	EXP a ;
538
		EXP a;
503
	while ( IS_exp_nof ( d ) ) {
539
		while (IS_exp_nof(d)) {
504
	    d = DEREF_exp ( exp_nof_pad ( d ) ) ;
540
			d = DEREF_exp(exp_nof_pad(d));
505
	}
541
		}
506
	a = DEREF_exp ( exp_destr_count ( d ) ) ;
542
		a = DEREF_exp(exp_destr_count(d));
507
	if ( IS_NULL_exp ( a ) ) {
543
		if (IS_NULL_exp(a)) {
508
	    /* Not already defined */
544
			/* Not already defined */
509
	    TYPE s = dummy_count ;
545
			TYPE s = dummy_count;
510
	    ulong n = capsule_no ( NULL_string, VAR_tag ) ;
546
			ulong n = capsule_no(NULL_string, VAR_tag);
511
	    BITSTREAM *bs = enc_tagdec_start ( NULL_id, n, t, 1 ) ;
547
			BITSTREAM *bs = enc_tagdec_start(NULL_id, n, t, 1);
512
	    bs = enc_term_type ( bs, t ) ;
548
			bs = enc_term_type(bs, t);
513
	    enc_tagdec_end ( bs ) ;
549
			enc_tagdec_end(bs);
514
	    bs = enc_tagdef_start ( NULL_id, n, t, 1 ) ;
550
			bs = enc_tagdef_start(NULL_id, n, t, 1);
515
	    while ( IS_type_array ( t ) ) {
551
			while (IS_type_array(t)) {
516
		NAT m = DEREF_nat ( type_array_size ( t ) ) ;
552
				NAT m = DEREF_nat(type_array_size(t));
517
		ENC_n_copies ( bs ) ;
553
				ENC_n_copies(bs);
518
		bs = enc_nat ( bs, m, 1 ) ;
554
				bs = enc_nat(bs, m, 1);
519
		t = DEREF_type ( type_array_sub ( t ) ) ;
555
				t = DEREF_type(type_array_sub(t));
520
	    }
556
			}
521
	    bs = enc_special ( bs, TOK_destr_null ) ;
557
			bs = enc_special(bs, TOK_destr_null);
522
	    enc_tagdef_end ( bs ) ;
558
			enc_tagdef_end(bs);
523
	    MAKE_exp_dummy ( s, NULL_exp, n, NULL_off, 0, a ) ;
559
			MAKE_exp_dummy(s, NULL_exp, n, NULL_off, 0, a);
524
	    COPY_exp ( exp_destr_count ( d ), a ) ;
560
			COPY_exp(exp_destr_count(d), a);
-
 
561
		}
-
 
562
		*pd = d;
525
	}
563
	}
526
	*pd = d ;
-
 
527
    }
-
 
528
    return ;
564
	return;
529
}
565
}
530
 
566
 
531
 
567
 
532
/*
568
/*
533
    DEFINE A LOCAL TERMINATOR OBJECT
569
    DEFINE A LOCAL TERMINATOR OBJECT
534
 
570
 
535
    This routine defines a local terminator object corresponding to an
571
    This routine defines a local terminator object corresponding to an
536
    object of type t and destructor pd.
572
    object of type t and destructor pd.
537
*/
573
*/
538
 
574
 
539
BITSTREAM *make_term_local
575
BITSTREAM *
540
    PROTO_N ( ( bs, t, pd, var ) )
-
 
541
    PROTO_T ( BITSTREAM *bs X TYPE t X EXP *pd X int var )
576
make_term_local(BITSTREAM *bs, TYPE t, EXP *pd, int var)
542
{
577
{
543
    EXP d = *pd ;
578
	EXP d = *pd;
544
    if ( !IS_NULL_exp ( d ) ) {
579
	if (!IS_NULL_exp(d)) {
545
	EXP a ;
580
		EXP a;
546
	TYPE s = dummy_count ;
581
		TYPE s = dummy_count;
547
	ulong n = unit_no ( bs, NULL_id, VAR_tag, 1 ) ;
582
		ulong n = unit_no(bs, NULL_id, VAR_tag, 1);
548
	ENC_variable ( bs ) ;
583
		ENC_variable(bs);
549
	bs = enc_access ( bs, dspec_none ) ;
584
		bs = enc_access(bs, dspec_none);
550
	ENC_make_tag ( bs, n ) ;
585
		ENC_make_tag(bs, n);
551
	if ( var == 4 ) {
586
		if (var == 4) {
552
	    /* Initialise to zero for temporaries */
587
			/* Initialise to zero for temporaries */
553
	    while ( IS_type_array ( t ) ) {
588
			while (IS_type_array(t)) {
554
		NAT m = DEREF_nat ( type_array_size ( t ) ) ;
589
				NAT m = DEREF_nat(type_array_size(t));
555
		ENC_n_copies ( bs ) ;
590
				ENC_n_copies(bs);
556
		bs = enc_nat ( bs, m, 1 ) ;
591
				bs = enc_nat(bs, m, 1);
557
		t = DEREF_type ( type_array_sub ( t ) ) ;
592
				t = DEREF_type(type_array_sub(t));
558
	    }
593
			}
559
	    bs = enc_special ( bs, TOK_destr_null ) ;
594
			bs = enc_special(bs, TOK_destr_null);
560
	} else {
595
		} else {
561
	    ENC_make_value ( bs ) ;
596
			ENC_make_value(bs);
562
	    bs = enc_term_type ( bs, t ) ;
597
			bs = enc_term_type(bs, t);
-
 
598
		}
-
 
599
		while (IS_exp_nof(d)) {
-
 
600
			d = DEREF_exp(exp_nof_pad(d));
-
 
601
		}
-
 
602
		MAKE_exp_dummy(s, NULL_exp, n, NULL_off, 0, a);
-
 
603
		COPY_exp(exp_destr_count(d), a);
-
 
604
		*pd = d;
563
	}
605
	}
564
	while ( IS_exp_nof ( d ) ) {
-
 
565
	    d = DEREF_exp ( exp_nof_pad ( d ) ) ;
-
 
566
	}
-
 
567
	MAKE_exp_dummy ( s, NULL_exp, n, NULL_off, 0, a ) ;
-
 
568
	COPY_exp ( exp_destr_count ( d ), a ) ;
-
 
569
	*pd = d ;
-
 
570
    }
-
 
571
    return ( bs ) ;
606
	return (bs);
572
}
607
}
573
 
608
 
574
 
609
 
575
/*
610
/*
576
    DECREASE A PARTIAL DESTRUCTOR COUNT
611
    DECREASE A PARTIAL DESTRUCTOR COUNT
577
 
612
 
578
    This routine decreases the partial destructor count by the value given
613
    This routine decreases the partial destructor count by the value given
579
    in t and n.
614
    in t and n.
580
*/
615
*/
581
 
616
 
582
BITSTREAM *enc_destr_count
617
BITSTREAM *
583
    PROTO_N ( ( bs, t, n ) )
-
 
584
    PROTO_T ( BITSTREAM *bs X TYPE t X int n )
618
enc_destr_count(BITSTREAM *bs, TYPE t, int n)
585
{
619
{
586
    TYPE s = type_sint ;
620
	TYPE s = type_sint;
587
    ulong m = last_params [ DUMMY_count ] ;
621
	ulong m = last_params[DUMMY_count];
588
    ENC_assign ( bs ) ;
622
	ENC_assign(bs);
589
    ENC_obtain_tag ( bs ) ;
623
	ENC_obtain_tag(bs);
590
    ENC_make_tag ( bs, m ) ;
624
	ENC_make_tag(bs, m);
591
    ENC_minus ( bs ) ;
625
	ENC_minus(bs);
592
    bs = enc_error_treatment ( bs, s ) ;
626
	bs = enc_error_treatment(bs, s);
593
    ENC_contents ( bs ) ;
627
	ENC_contents(bs);
594
    bs = enc_shape ( bs, s ) ;
628
	bs = enc_shape(bs, s);
595
    ENC_obtain_tag ( bs ) ;
629
	ENC_obtain_tag(bs);
596
    ENC_make_tag ( bs, m ) ;
630
	ENC_make_tag(bs, m);
597
    if ( !IS_NULL_type ( t ) && IS_type_array ( t ) ) {
631
	if (!IS_NULL_type(t) && IS_type_array(t)) {
598
	EXP a = sizeof_array ( &t, s ) ;
632
		EXP a = sizeof_array(&t, s);
599
	bs = enc_exp ( bs, a ) ;
633
		bs = enc_exp(bs, a);
600
	free_exp ( a, 1 ) ;
634
		free_exp(a, 1);
601
    } else {
635
	} else {
602
	bs = enc_make_int ( bs, s, n ) ;
636
		bs = enc_make_int(bs, s, n);
603
    }
637
	}
604
    return ( bs ) ;
638
	return (bs);
605
}
639
}
606
 
640
 
607
 
641
 
608
/*
642
/*
609
    ENCODE THE TERMINATOR FOR A TAG
643
    ENCODE THE TERMINATOR FOR A TAG
610
 
644
 
611
    This routine adds a terminator expression for the destructor d to the
645
    This routine adds a terminator expression for the destructor d to the
612
    bitstream bs.  The other arguments are as in enc_init_tag.  The effect
646
    bitstream bs.  The other arguments are as in enc_init_tag.  The effect
613
    of the terminator expression is to add the destructor call to a list
647
    of the terminator expression is to add the destructor call to a list
614
    of destructors to be called at a later stage.
648
    of destructors to be called at a later stage.
615
*/
649
*/
616
 
650
 
617
static BITSTREAM *enc_term_start
651
static BITSTREAM *
618
    PROTO_N ( ( bs, n, off, cnt, t, d, context ) )
-
 
619
    PROTO_T ( BITSTREAM *bs X ulong n X OFFSET off X int cnt X
652
enc_term_start(BITSTREAM *bs, ulong n, OFFSET off, int cnt, TYPE t, EXP d,
620
	      TYPE t X EXP d X int context )
653
	       int context)
621
{
654
{
622
    int tok = TOK_destr_local ;
655
	int tok = TOK_destr_local;
623
    switch ( context ) {
656
	switch (context) {
624
	case 1 :
657
	case 1:
625
	destr_lab : {
658
destr_lab: {
626
	    /* Destroy local variable */
659
		   /* Destroy local variable */
627
	    BITSTREAM *ts, *us ;
660
		   BITSTREAM *ts, *us;
628
	    EXP c = DEREF_exp ( exp_destr_count ( d ) ) ;
661
		   EXP c = DEREF_exp(exp_destr_count(d));
629
	    ASSERT ( !IS_NULL_exp ( c ) ) ;
662
		   ASSERT(!IS_NULL_exp(c));
630
	    bs = enc_special ( bs, tok ) ;
663
		   bs = enc_special(bs, tok);
631
	    ts = start_bitstream ( NIL ( FILE ), bs->link ) ;
664
		   ts = start_bitstream(NIL(FILE), bs->link);
632
	    ts = enc_exp ( ts, c ) ;
665
		   ts = enc_exp(ts, c);
633
	    ts = enc_special ( ts, TOK_destr_cast ) ;
666
		   ts = enc_special(ts, TOK_destr_cast);
634
	    us = start_bitstream ( NIL ( FILE ), ts->link ) ;
667
		   us = start_bitstream(NIL(FILE), ts->link);
635
	    us = enc_alignment ( us, t ) ;
668
		   us = enc_alignment(us, t);
636
	    us = enc_dummy_exp ( us, t, n, off, 2 * cnt, 0 ) ;
669
		   us = enc_dummy_exp(us, t, n, off, 2 * cnt, 0);
637
	    ts = enc_bitstream ( ts, us ) ;
670
		   ts = enc_bitstream(ts, us);
638
	    ts = enc_destr_func ( ts, d ) ;
671
		   ts = enc_destr_func(ts, d);
639
	    bs = enc_bitstream ( bs, ts ) ;
672
		   bs = enc_bitstream(bs, ts);
640
	    break ;
673
		   break;
-
 
674
	   }
-
 
675
	case 2: {
-
 
676
		/* Destroy global variable */
-
 
677
		tok = TOK_destr_global;
-
 
678
		goto destr_lab;
641
	}
679
	}
642
	case 2 : {
680
	case 5: {
643
	    /* Destroy global variable */
681
		/* Partial constructor count */
644
	    tok = TOK_destr_global ;
682
		bs = enc_destr_count(bs, t, 1);
645
	    goto destr_lab ;
683
		break;
646
	}
684
	}
647
	case 5 : {
685
	default: {
648
	    /* Partial constructor count */
-
 
649
	    bs = enc_destr_count ( bs, t, 1 ) ;
686
		ENC_make_top(bs);
650
	    break ;
687
		break;
651
	}
688
	}
652
	default : {
-
 
653
	    ENC_make_top ( bs ) ;
-
 
654
	    break ;
-
 
655
	}
689
	}
656
    }
-
 
657
    return ( bs ) ;
690
	return (bs);
658
}
691
}
659
 
692
 
660
 
693
 
661
/*
694
/*
662
    ENCODE AN ASSIGNMENT TO A TAG
695
    ENCODE AN ASSIGNMENT TO A TAG
663
 
696
 
664
    This routine adds an assignment of the value e to the tag n plus offset
697
    This routine adds an assignment of the value e to the tag n plus offset
665
    off of type t (or the contents of tag n plus offset off if cnt is true)
698
    off of type t (or the contents of tag n plus offset off if cnt is true)
666
    to the bitstream bs.  context is 2 for the initialisation of a global
699
    to the bitstream bs.  context is 2 for the initialisation of a global
667
    variable, 1 for the initialisation of a local variable and 0 otherwise.
700
    variable, 1 for the initialisation of a local variable and 0 otherwise.
668
    If the destructor expression d is not null then the terminator
701
    If the destructor expression d is not null then the terminator
669
    expressions for tag n are also initialised.  In this the case the
702
    expressions for tag n are also initialised.  In this the case the
670
    output comprises two TDF expressions, otherwise it is a single
703
    output comprises two TDF expressions, otherwise it is a single
671
    expression.
704
    expression.
994
	}
1043
	}
995
    }
-
 
996
    return ( bs ) ;
1044
	return (bs);
997
}
1045
}
998
 
1046
 
999
 
1047
 
1000
/*
1048
/*
1001
    CREATE A DUMMY INITIALISER EXPRESSION
1049
    CREATE A DUMMY INITIALISER EXPRESSION
1002
 
1050
 
1003
    This routine creates a dummy initialiser expression of type t.
1051
    This routine creates a dummy initialiser expression of type t.
1004
*/
1052
*/
1005
 
1053
 
1006
EXP make_dummy_init
1054
EXP
1007
    PROTO_N ( ( t ) )
-
 
1008
    PROTO_T ( TYPE t )
1055
make_dummy_init(TYPE t)
1009
{
1056
{
1010
    EXP a ;
1057
	EXP a;
1011
    if ( IS_type_array ( t ) ) {
1058
	if (IS_type_array(t)) {
1012
	NAT n = DEREF_nat ( type_array_size ( t ) ) ;
1059
		NAT n = DEREF_nat(type_array_size(t));
1013
	TYPE s = DEREF_type ( type_array_sub ( t ) ) ;
1060
		TYPE s = DEREF_type(type_array_sub(t));
1014
	EXP b = make_dummy_init ( s ) ;
1061
		EXP b = make_dummy_init(s);
1015
	MAKE_exp_nof ( t, NULL_exp, n, b, NULL_exp, a ) ;
1062
		MAKE_exp_nof(t, NULL_exp, n, b, NULL_exp, a);
1016
	return ( a ) ;
1063
		return (a);
1017
    }
1064
	}
1018
    MAKE_exp_value ( t, a ) ;
1065
	MAKE_exp_value(t, a);
1019
    return ( a ) ;
1066
	return (a);
1020
}
1067
}
1021
 
1068
 
1022
 
1069
 
1023
/*
1070
/*
1024
    ENCODE A GLOBAL INITIALISER EXPRESSION
1071
    ENCODE A GLOBAL INITIALISER EXPRESSION
1025
 
1072
 
1026
    This routine adds the initialiser expression e for the global variable
1073
    This routine adds the initialiser expression e for the global variable
1027
    with capsule tag number n and type t to the bitstream bs.  If d is
1074
    with capsule tag number n and type t to the bitstream bs.  If d is
1028
    not the null expression then the terminator expressions for tag n
1075
    not the null expression then the terminator expressions for tag n
1029
    are also initialised.
1076
    are also initialised.
1030
*/
1077
*/
1031
 
1078
 
1032
BITSTREAM *enc_init_global
1079
BITSTREAM *
1033
    PROTO_N ( ( bs, e, d, n, t ) )
-
 
1034
    PROTO_T ( BITSTREAM *bs X EXP e X EXP d X ulong n X TYPE t )
1080
enc_init_global(BITSTREAM *bs, EXP e, EXP d, ulong n, TYPE t)
1035
{
1081
{
1036
    int i = in_static_init ;
1082
	int i = in_static_init;
1037
    int j = in_dynamic_init ;
1083
	int j = in_dynamic_init;
1038
    int uc = unreached_code ;
1084
	int uc = unreached_code;
1039
    unreached_code = 0 ;
1085
	unreached_code = 0;
1040
    in_static_init = 1 ;
1086
	in_static_init = 1;
1041
    if ( IS_exp_dynamic ( e ) && n != LINK_NONE ) {
1087
	if (IS_exp_dynamic(e) && n != LINK_NONE) {
1042
	/* Dynamic initialisers */
1088
		/* Dynamic initialisers */
1043
	BITSTREAM *ts ;
1089
		BITSTREAM *ts;
1044
	EXP a = DEREF_exp ( exp_dynamic_arg ( e ) ) ;
1090
		EXP a = DEREF_exp(exp_dynamic_arg(e));
1045
	bs = enc_null_exp ( bs, t ) ;
1091
		bs = enc_null_exp(bs, t);
1046
	in_static_init = 0 ;
1092
		in_static_init = 0;
1047
	in_dynamic_init = 1 ;
1093
		in_dynamic_init = 1;
1048
	ts = start_bitstream ( NIL ( FILE ), init_func->link ) ;
1094
		ts = start_bitstream(NIL(FILE), init_func->link);
1049
	n = link_no ( ts, n, VAR_tag ) ;
1095
		n = link_no(ts, n, VAR_tag);
1050
	ts = enc_init_tag ( ts, n, NULL_off, 0, t, a, d, 2 ) ;
1096
		ts = enc_init_tag(ts, n, NULL_off, 0, t, a, d, 2);
1051
	init_func = join_bitstreams ( init_func, ts ) ;
1097
		init_func = join_bitstreams(init_func, ts);
1052
	if ( !IS_NULL_exp ( d ) ) init_no++ ;
1098
		if (!IS_NULL_exp(d)) {
-
 
1099
			init_no++;
-
 
1100
		}
1053
	init_no++ ;
1101
		init_no++;
1054
    } else {
1102
	} else {
1055
	/* Static initialisers */
1103
		/* Static initialisers */
1056
	bs = enc_exp ( bs, e ) ;
1104
		bs = enc_exp(bs, e);
1057
	if ( !IS_NULL_exp ( d ) && n != LINK_NONE ) {
1105
		if (!IS_NULL_exp(d) && n != LINK_NONE) {
1058
	    /* Dynamic destructors */
1106
			/* Dynamic destructors */
1059
	    BITSTREAM *ts ;
1107
			BITSTREAM *ts;
1060
	    EXP a = make_dummy_init ( t ) ;
1108
			EXP a = make_dummy_init(t);
1061
	    in_static_init = 0 ;
1109
			in_static_init = 0;
1062
	    in_dynamic_init = 1 ;
1110
			in_dynamic_init = 1;
1063
	    ts = start_bitstream ( NIL ( FILE ), init_func->link ) ;
1111
			ts = start_bitstream(NIL(FILE), init_func->link);
1064
	    n = link_no ( ts, n, VAR_tag ) ;
1112
			n = link_no(ts, n, VAR_tag);
1065
	    ts = enc_init_tag ( ts, n, NULL_off, 0, t, a, d, 2 ) ;
1113
			ts = enc_init_tag(ts, n, NULL_off, 0, t, a, d, 2);
1066
	    init_func = join_bitstreams ( init_func, ts ) ;
1114
			init_func = join_bitstreams(init_func, ts);
1067
	    init_no += 2 ;
1115
			init_no += 2;
1068
	    free_exp ( a, 1 ) ;
1116
			free_exp(a, 1);
-
 
1117
		}
1069
	}
1118
	}
1070
    }
-
 
1071
    unreached_code = uc ;
1119
	unreached_code = uc;
1072
    in_dynamic_init = j ;
1120
	in_dynamic_init = j;
1073
    in_static_init = i ;
1121
	in_static_init = i;
1074
    return ( bs ) ;
1122
	return (bs);
1075
}
1123
}
1076
 
1124
 
1077
 
1125
 
1078
/*
1126
/*
1079
    ENCODE A LOCAL ASSIGNMENT EXPRESSION
1127
    ENCODE A LOCAL ASSIGNMENT EXPRESSION
1080
 
1128
 
1081
    This routine is similar to enc_init_local, but handles assignment
1129
    This routine is similar to enc_init_local, but handles assignment
1082
    rather than initialisation.
1130
    rather than initialisation.
1083
*/
1131
*/
1084
 
1132
 
1085
BITSTREAM *enc_assign_local
1133
BITSTREAM *
1086
    PROTO_N ( ( bs, a, d, n, t, e ) )
-
 
1087
    PROTO_T ( BITSTREAM *bs X EXP a X EXP d X ulong n X TYPE t X EXP e )
1134
enc_assign_local(BITSTREAM *bs, EXP a, EXP d, ulong n, TYPE t, EXP e)
1088
{
1135
{
1089
    if ( !IS_NULL_exp ( e ) ) {
1136
	if (!IS_NULL_exp(e)) {
1090
	BITSTREAM *ts ;
1137
		BITSTREAM *ts;
1091
	ENC_SEQ_SMALL ( bs, 1 ) ;
1138
		ENC_SEQ_SMALL(bs, 1);
1092
	ts = enc_diag_begin ( &bs ) ;
1139
		ts = enc_diag_begin(&bs);
-
 
1140
		if (!IS_NULL_exp(d)) {
1093
	if ( !IS_NULL_exp ( d ) ) ENC_SEQ_SMALL ( ts, 1 ) ;
1141
			ENC_SEQ_SMALL(ts, 1);
-
 
1142
		}
1094
	ts = enc_init_tag ( ts, n, NULL_off, 0, t, a, d, 1 ) ;
1143
		ts = enc_init_tag(ts, n, NULL_off, 0, t, a, d, 1);
1095
	bs = enc_diag_end ( bs, ts, e, 1 ) ;
1144
		bs = enc_diag_end(bs, ts, e, 1);
1096
    } else {
1145
	} else {
1097
	unsigned seq = 1 ;
1146
		unsigned seq = 1;
1098
	if ( !IS_NULL_exp ( d ) ) seq++ ;
1147
		if (!IS_NULL_exp(d)) {
-
 
1148
			seq++;
-
 
1149
		}
1099
	ENC_SEQ_SMALL ( bs, seq ) ;
1150
		ENC_SEQ_SMALL(bs, seq);
1100
	bs = enc_init_tag ( bs, n, NULL_off, 0, t, a, d, 1 ) ;
1151
		bs = enc_init_tag(bs, n, NULL_off, 0, t, a, d, 1);
1101
    }
1152
	}
1102
    return ( bs ) ;
1153
	return (bs);
1103
}
1154
}
1104
 
1155
 
1105
 
1156
 
1106
/*
1157
/*
1107
    ENCODE A LOCAL INITIALISER EXPRESSION
1158
    ENCODE A LOCAL INITIALISER EXPRESSION
1108
 
1159
 
1109
    This routine adds the initialiser expression a for the local
1160
    This routine adds the initialiser expression a for the local
1110
    variable with tag number n (in the current unit) and type t to the
1161
    variable with tag number n (in the current unit) and type t to the
1111
    bitstream bs.  e gives the corresponding declaration statement for
1162
    bitstream bs.  e gives the corresponding declaration statement for
1112
    use with diagnostics.
1163
    use with diagnostics.
1113
*/
1164
*/
1114
 
1165
 
1115
BITSTREAM *enc_init_local
1166
BITSTREAM *
1116
    PROTO_N ( ( bs, a, d, n, t, e ) )
-
 
1117
    PROTO_T ( BITSTREAM *bs X EXP a X EXP d X ulong n X TYPE t X EXP e )
1167
enc_init_local(BITSTREAM *bs, EXP a, EXP d, ulong n, TYPE t, EXP e)
1118
{
1168
{
1119
    if ( n != LINK_NONE ) {
1169
	if (n != LINK_NONE) {
1120
	switch ( TAG_exp ( a ) ) {
1170
		switch (TAG_exp(a)) {
1121
	    case exp_constr_tag :
1171
		case exp_constr_tag:
1122
	    case exp_dynamic_tag :
1172
		case exp_dynamic_tag:
1123
	    dynamic_label : {
1173
dynamic_label: {
1124
		/* Explicit initialisation */
1174
		       /* Explicit initialisation */
1125
		ENC_make_value ( bs ) ;
1175
		       ENC_make_value(bs);
1126
		bs = enc_shape ( bs, t ) ;
1176
		       bs = enc_shape(bs, t);
1127
		bs = enc_assign_local ( bs, a, d, n, t, e ) ;
1177
		       bs = enc_assign_local(bs, a, d, n, t, e);
1128
		return ( bs ) ;
1178
		       return (bs);
1129
	    }
1179
	       }
1130
	    case exp_aggregate_tag :
1180
		case exp_aggregate_tag:
1131
	    case exp_nof_tag : {
1181
		case exp_nof_tag: {
1132
		/* Explicitly initialise in non-constant cases */
1182
			/* Explicitly initialise in non-constant cases */
1133
		if ( !is_const_exp ( a, -1 ) ) goto dynamic_label ;
1183
			if (!is_const_exp(a, -1)) {
-
 
1184
				goto dynamic_label;
-
 
1185
			}
1134
		break ;
1186
			break;
1135
	    }
1187
		}
1136
	    case exp_paren_tag :
1188
		case exp_paren_tag:
1137
	    case exp_copy_tag : {
1189
		case exp_copy_tag: {
1138
		/* Parenthesised expressions */
1190
			/* Parenthesised expressions */
1139
		a = DEREF_exp ( exp_paren_etc_arg ( a ) ) ;
1191
			a = DEREF_exp(exp_paren_etc_arg(a));
1140
		bs = enc_init_local ( bs, a, d, n, t, e ) ;
1192
			bs = enc_init_local(bs, a, d, n, t, e);
1141
		return ( bs ) ;
1193
			return (bs);
1142
	    }
1194
		}
1143
	    default : {
1195
		default : {
1144
		if ( !IS_NULL_exp ( d ) ) goto dynamic_label ;
1196
			if (!IS_NULL_exp(d)) {
-
 
1197
				goto dynamic_label;
-
 
1198
			}
1145
		break ;
1199
			break;
-
 
1200
		}
1146
	    }
1201
		}
-
 
1202
	}
-
 
1203
	if (!IS_NULL_exp(e)) {
-
 
1204
		BITSTREAM *ts = enc_diag_begin(&bs);
-
 
1205
		ts = enc_exp(ts, a);
-
 
1206
		bs = enc_diag_end(bs, ts, e, 1);
-
 
1207
	} else {
-
 
1208
		bs = enc_exp(bs, a);
1147
	}
1209
	}
1148
    }
-
 
1149
    if ( !IS_NULL_exp ( e ) ) {
-
 
1150
	BITSTREAM *ts = enc_diag_begin ( &bs ) ;
-
 
1151
	ts = enc_exp ( ts, a ) ;
-
 
1152
	bs = enc_diag_end ( bs, ts, e, 1 ) ;
-
 
1153
    } else {
-
 
1154
	bs = enc_exp ( bs, a ) ;
-
 
1155
    }
-
 
1156
    return ( bs ) ;
1210
	return (bs);
1157
}
1211
}
1158
 
1212
 
1159
 
1213
 
1160
/*
1214
/*
1161
    IS AN EXPRESSION A COMPLEX ASSIGNEE?
1215
    IS AN EXPRESSION A COMPLEX ASSIGNEE?
1162
 
1216
 
1163
    This routine checks whether the expression a, which forms the right hand
1217
    This routine checks whether the expression a, which forms the right hand
1164
    side of an assignment, requires the use of enc_init_tag rather than a
1218
    side of an assignment, requires the use of enc_init_tag rather than a
1165
    simple assignment operation.
1219
    simple assignment operation.
1166
*/
1220
*/
1167
 
1221
 
1168
int is_init_complex
1222
int
1169
    PROTO_N ( ( a ) )
-
 
1170
    PROTO_T ( EXP a )
1223
is_init_complex(EXP a)
1171
{
1224
{
1172
    switch ( TAG_exp ( a ) ) {
1225
	switch (TAG_exp(a)) {
1173
	case exp_constr_tag :
1226
	case exp_constr_tag:
1174
	case exp_dynamic_tag :
1227
	case exp_dynamic_tag:
1175
	case exp_aggregate_tag :
1228
	case exp_aggregate_tag:
1176
	case exp_string_lit_tag :
1229
	case exp_string_lit_tag:
1177
	case exp_nof_tag : {
1230
	case exp_nof_tag: {
1178
	    /* These are the complex cases */
1231
		/* These are the complex cases */
1179
	    return ( 1 ) ;
1232
		return (1);
1180
	}
1233
	}
1181
	case exp_paren_tag :
1234
	case exp_paren_tag:
1182
	case exp_copy_tag : {
1235
	case exp_copy_tag: {
1183
	    a = DEREF_exp ( exp_paren_etc_arg ( a ) ) ;
1236
		a = DEREF_exp(exp_paren_etc_arg(a));
1184
	    return ( is_init_complex ( a ) ) ;
1237
		return (is_init_complex(a));
1185
	}
1238
	}
1186
    }
1239
	}
1187
    return ( 0 ) ;
1240
	return (0);
1188
}
1241
}
1189
 
1242
 
1190
 
1243
 
1191
/*
1244
/*
1192
    ENCODE A GLOBAL TERMINATOR EXPRESSION
1245
    ENCODE A GLOBAL TERMINATOR EXPRESSION
Line 1195... Line 1248...
1195
    capsule tag number n and type t to the termination function ts.  If m
1248
    capsule tag number n and type t to the termination function ts.  If m
1196
    is not LINK_NONE then it is the capsule tag number of a flag which
1249
    is not LINK_NONE then it is the capsule tag number of a flag which
1197
    needs to be checked before the termination expression is called.
1250
    needs to be checked before the termination expression is called.
1198
    Note that the terminations are done in the reverse order to the
1251
    Note that the terminations are done in the reverse order to the
1199
    initialisations.
1252
    initialisations.
1200
*/
1253
*/
1201
 
1254
 
1202
BITSTREAM *enc_term_global
1255
BITSTREAM *
1203
    PROTO_N ( ( ts, n, t, e, m ) )
-
 
1204
    PROTO_T ( BITSTREAM *ts X ulong n X TYPE t X EXP e X ulong m )
1256
enc_term_global(BITSTREAM *ts, ulong n, TYPE t, EXP e, ulong m)
1205
{
1257
{
1206
    if ( !IS_NULL_exp ( e ) ) {
1258
	if (!IS_NULL_exp(e)) {
1207
	BITSTREAM *bs ;
1259
		BITSTREAM *bs;
1208
	int uc = unreached_code ;
1260
		int uc = unreached_code;
1209
	unreached_code = 0 ;
1261
		unreached_code = 0;
1210
	bs = start_bitstream ( NIL ( FILE ), ts->link ) ;
1262
		bs = start_bitstream(NIL(FILE), ts->link);
1211
	n = link_no ( bs, n, VAR_tag ) ;
1263
		n = link_no(bs, n, VAR_tag);
1212
	if ( m == LINK_NONE ) {
1264
		if (m == LINK_NONE) {
1213
	    /* Simple case */
1265
			/* Simple case */
1214
	    bs = enc_term_local ( bs, n, NULL_off, 0, t, e, 2 ) ;
1266
			bs = enc_term_local(bs, n, NULL_off, 0, t, e, 2);
1215
	} else {
1267
		} else {
1216
	    /* Check flag before call */
1268
			/* Check flag before call */
1217
	    m = link_no ( bs, m, VAR_tag ) ;
1269
			m = link_no(bs, m, VAR_tag);
1218
	    bs = enc_flag_test ( bs, m, ( unsigned ) 1, 0, ntest_not_eq ) ;
1270
			bs = enc_flag_test(bs, m,(unsigned)1, 0, ntest_not_eq);
1219
	    bs = enc_term_local ( bs, n, NULL_off, 0, t, e, 2 ) ;
1271
			bs = enc_term_local(bs, n, NULL_off, 0, t, e, 2);
1220
	    ENC_make_top ( bs ) ;
1272
			ENC_make_top(bs);
-
 
1273
		}
-
 
1274
		ts = join_bitstreams(bs, ts);
-
 
1275
		unreached_code = uc;
1221
	}
1276
	}
1222
	ts = join_bitstreams ( bs, ts ) ;
-
 
1223
	unreached_code = uc ;
-
 
1224
    }
-
 
1225
    return ( ts ) ;
1277
	return (ts);
1226
}
1278
}
1227
 
1279
 
1228
 
1280
 
1229
/*
1281
/*
1230
    ENCODE A LOCAL TERMINATOR EXPRESSION
1282
    ENCODE A LOCAL TERMINATOR EXPRESSION
Line 1233... Line 1285...
1233
    tag number n and type t to the bitstream bs.  context is 2 for global
1285
    tag number n and type t to the bitstream bs.  context is 2 for global
1234
    variables, 1, 3 or 4 for local variables, and 0 in destructors and
1286
    variables, 1, 3 or 4 for local variables, and 0 in destructors and
1235
    deallocation expressions.  For local variables the result consists
1287
    deallocation expressions.  For local variables the result consists
1236
    of two TDF expressions (including terminator variable adjustment).
1288
    of two TDF expressions (including terminator variable adjustment).
1237
    Otherwise the result is a single expression.
1289
    Otherwise the result is a single expression.
1238
*/
1290
*/
1239
 
1291
 
1240
BITSTREAM *enc_term_local
1292
BITSTREAM *
1241
    PROTO_N ( ( bs, n, off, cnt, t, e, context ) )
-
 
1242
    PROTO_T ( BITSTREAM *bs X ulong n X OFFSET off X int cnt X
1293
enc_term_local(BITSTREAM *bs, ulong n, OFFSET off, int cnt, TYPE t, EXP e,
1243
	      TYPE t X EXP e X int context )
1294
	       int context)
1244
{
1295
{
1245
    /* Allow for parenthesised expressions */
1296
	/* Allow for parenthesised expressions */
1246
    EXP a = NULL_exp ;
1297
	EXP a = NULL_exp;
1247
    EXP c = NULL_exp ;
1298
	EXP c = NULL_exp;
1248
    unsigned tops = 0 ;
1299
	unsigned tops = 0;
1249
    while ( IS_exp_paren_etc ( e ) ) {
1300
	while (IS_exp_paren_etc(e)) {
1250
	e = DEREF_exp ( exp_paren_etc_arg ( e ) ) ;
1301
		e = DEREF_exp(exp_paren_etc_arg(e));
-
 
1302
	}
-
 
1303
 
-
 
1304
	/* Check for array destructors */
-
 
1305
	if (IS_type_array(t)) {
-
 
1306
		TYPE r = t;
-
 
1307
		EXP d = sizeof_array(&r, type_sint);
-
 
1308
		switch (context) {
-
 
1309
		case 1:
-
 
1310
		case 3:
-
 
1311
		case 4: {
-
 
1312
			/* Local variables */
-
 
1313
			tops = 1;
-
 
1314
			break;
-
 
1315
		}
-
 
1316
		}
-
 
1317
		if (IS_NULL_exp(d) || is_zero_exp(d)) {
-
 
1318
			/* Zero sized arrays */
-
 
1319
			tops++;
-
 
1320
		} else {
-
 
1321
			/* Non-trivial arrays */
-
 
1322
			int calc = 1;
-
 
1323
			ulong dn = LINK_NONE;
-
 
1324
			unsigned seq = tops + 2;
-
 
1325
			ulong ptr = unit_no(bs, NULL_id, VAR_tag, 1);
-
 
1326
			ulong end = unit_no(bs, NULL_id, VAR_tag, 1);
-
 
1327
			ulong lab = unit_no(bs, NULL_id, VAR_label, 1);
-
 
1328
			bs = enc_loop_decl(bs, ptr, n, r, cnt, off, t);
-
 
1329
			bs = enc_loop_decl(bs, end, n, r, cnt, off, NULL_type);
-
 
1330
			while (IS_exp_nof(e)) {
-
 
1331
				/* Step over array destructors */
-
 
1332
				e = DEREF_exp(exp_nof_pad(e));
-
 
1333
			}
-
 
1334
			if (context != 2) {
-
 
1335
				/* Declare counter */
-
 
1336
				bs = enc_count_decl(bs, e, t, &dn);
-
 
1337
				seq++;
-
 
1338
			}
-
 
1339
			if (IS_exp_int_lit(d)) {
-
 
1340
				/* Check whether dimensions are constant */
-
 
1341
				NAT m = DEREF_nat(exp_int_lit_nat(d));
-
 
1342
				if (!IS_nat_calc(m)) {
-
 
1343
					calc = 0;
1251
    }
1344
				}
-
 
1345
			}
-
 
1346
			if (calc) {
-
 
1347
				/* Check for calculated bounds */
-
 
1348
				ulong lab2 = unit_no(bs, NULL_id, VAR_label, 1);
-
 
1349
				ENC_conditional(bs);
-
 
1350
				ENC_make_label(bs, lab2);
-
 
1351
				ENC_SEQ_SMALL(bs, 1);
-
 
1352
				bs = enc_loop_test(bs, ptr, end, r, lab2,
-
 
1353
						   ntest_greater);
-
 
1354
				tops++;
-
 
1355
			}
-
 
1356
			ENC_repeat(bs);
-
 
1357
			ENC_make_label(bs, lab);
-
 
1358
			ENC_make_top(bs);
-
 
1359
			ENC_SEQ_SMALL(bs, seq);
-
 
1360
			bs = enc_loop_incr(bs, ptr, r, 1);
-
 
1361
			if (context != 2) {
-
 
1362
				/* Decrease counter */
-
 
1363
				bs = enc_count_incr(bs, e, 1, r);
-
 
1364
			}
-
 
1365
			bs = enc_term_local(bs, ptr, NULL_off, 1, r, e,
-
 
1366
					    context);
-
 
1367
			bs = enc_loop_test(bs, ptr, end, r, lab, ntest_eq);
-
 
1368
			enc_count_end(e, dn);
-
 
1369
		}
-
 
1370
		while (tops) {
-
 
1371
			ENC_make_top(bs);
-
 
1372
			tops--;
-
 
1373
		}
-
 
1374
		return (bs);
-
 
1375
	}
1252
 
1376
 
1253
    /* Check for array destructors */
-
 
1254
    if ( IS_type_array ( t ) ) {
-
 
1255
	TYPE r = t ;
-
 
1256
	EXP d = sizeof_array ( &r, type_sint ) ;
-
 
1257
	switch ( context ) {
-
 
1258
	    case 1 : case 3 : case 4 : {
-
 
1259
		/* Local variables */
-
 
1260
		tops = 1 ;
-
 
1261
		break ;
-
 
1262
	    }
-
 
1263
	}
-
 
1264
	if ( IS_NULL_exp ( d ) || is_zero_exp ( d ) ) {
-
 
1265
	    /* Zero sized arrays */
1377
	/* Simple destructor calls */
1266
	    tops++ ;
-
 
1267
	} else {
-
 
1268
	    /* Non-trivial arrays */
-
 
1269
	    int calc = 1 ;
-
 
1270
	    ulong dn = LINK_NONE ;
-
 
1271
	    unsigned seq = tops + 2 ;
-
 
1272
	    ulong ptr = unit_no ( bs, NULL_id, VAR_tag, 1 ) ;
-
 
1273
	    ulong end = unit_no ( bs, NULL_id, VAR_tag, 1 ) ;
-
 
1274
	    ulong lab = unit_no ( bs, NULL_id, VAR_label, 1 ) ;
-
 
1275
	    bs = enc_loop_decl ( bs, ptr, n, r, cnt, off, t ) ;
-
 
1276
	    bs = enc_loop_decl ( bs, end, n, r, cnt, off, NULL_type ) ;
-
 
1277
	    while ( IS_exp_nof ( e ) ) {
1378
	if (IS_exp_destr(e)) {
1278
		/* Step over array destructors */
-
 
1279
		e = DEREF_exp ( exp_nof_pad ( e ) ) ;
1379
		a = DEREF_exp(exp_destr_obj(e));
1280
	    }
-
 
1281
	    if ( context != 2 ) {
-
 
1282
		/* Declare counter */
-
 
1283
		bs = enc_count_decl ( bs, e, t, &dn ) ;
1380
		COPY_ulong(exp_dummy_no(a), n);
1284
		seq++ ;
-
 
1285
	    }
-
 
1286
	    if ( IS_exp_int_lit ( d ) ) {
1381
		COPY_off(exp_dummy_off(a), off);
1287
		/* Check whether dimensions are constant */
1382
		COPY_int(exp_dummy_cont(a), 2 * cnt);
1288
		NAT m = DEREF_nat ( exp_int_lit_nat ( d ) ) ;
1383
		c = DEREF_exp(exp_destr_count(e));
1289
		if ( !IS_nat_calc ( m ) ) calc = 0 ;
-
 
1290
	    }
-
 
1291
	    if ( calc ) {
-
 
1292
		/* Check for calculated bounds */
-
 
1293
		ulong lab2 = unit_no ( bs, NULL_id, VAR_label, 1 ) ;
-
 
1294
		ENC_conditional ( bs ) ;
-
 
1295
		ENC_make_label ( bs, lab2 ) ;
-
 
1296
		ENC_SEQ_SMALL ( bs, 1 ) ;
-
 
1297
		bs = enc_loop_test ( bs, ptr, end, r, lab2, ntest_greater ) ;
-
 
1298
		tops++ ;
-
 
1299
	    }
-
 
1300
	    ENC_repeat ( bs ) ;
-
 
1301
	    ENC_make_label ( bs, lab ) ;
1384
		e = DEREF_exp(exp_destr_call(e));
1302
	    ENC_make_top ( bs ) ;
-
 
1303
	    ENC_SEQ_SMALL ( bs, seq ) ;
-
 
1304
	    bs = enc_loop_incr ( bs, ptr, r, 1 ) ;
-
 
1305
	    if ( context != 2 ) {
-
 
1306
		/* Decrease counter */
-
 
1307
		bs = enc_count_incr ( bs, e, 1, r ) ;
-
 
1308
	    }
-
 
1309
	    bs = enc_term_local ( bs, ptr, NULL_off, 1, r, e, context ) ;
-
 
1310
	    bs = enc_loop_test ( bs, ptr, end, r, lab, ntest_eq ) ;
-
 
1311
	    enc_count_end ( e, dn ) ;
-
 
1312
	}
1385
	}
1313
	while ( tops ) {
1386
	switch (context) {
-
 
1387
	case 1:
-
 
1388
	case 3: {
-
 
1389
		/* Local variable */
-
 
1390
		if (!IS_NULL_exp(c)) {
-
 
1391
			BITSTREAM *ts;
-
 
1392
			bs = enc_special(bs, TOK_destr_end);
-
 
1393
			ts = start_bitstream(NIL(FILE), bs->link);
-
 
1394
			ts = enc_exp(ts, c);
-
 
1395
			bs = enc_bitstream(bs, ts);
-
 
1396
		} else {
-
 
1397
			tops = 1;
-
 
1398
		}
-
 
1399
		break;
-
 
1400
	}
-
 
1401
	case 4: {
-
 
1402
		/* Explicitly initialised local variable */
-
 
1403
		if (!IS_NULL_exp(c)) {
-
 
1404
			/* Check for initialisation */
-
 
1405
			BITSTREAM *ts;
-
 
1406
			ulong lab = unit_no(bs, NULL_id, VAR_label, 1);
-
 
1407
			ENC_conditional(bs);
1314
	    ENC_make_top ( bs ) ;
1408
			ENC_make_label(bs, lab);
-
 
1409
			ENC_SEQ_SMALL(bs, 2);
-
 
1410
			bs = enc_special(bs, TOK_destr_test);
-
 
1411
			ts = start_bitstream(NIL(FILE), bs->link);
-
 
1412
			ts = enc_exp(ts, c);
-
 
1413
			ENC_make_label(ts, lab);
-
 
1414
			bs = enc_bitstream(bs, ts);
-
 
1415
			bs = enc_special(bs, TOK_destr_end);
-
 
1416
			ts = start_bitstream(NIL(FILE), bs->link);
-
 
1417
			ts = enc_exp(ts, c);
-
 
1418
			bs = enc_bitstream(bs, ts);
-
 
1419
			tops = 2;
-
 
1420
		} else {
1315
	    tops-- ;
1421
			tops = 1;
-
 
1422
		}
-
 
1423
		break;
-
 
1424
	}
-
 
1425
	case 5: {
-
 
1426
		/* Partial destructor count */
-
 
1427
		ulong m = last_params[DUMMY_count];
-
 
1428
		bs = enc_flag_test(bs, m,(unsigned)1, 0, ntest_not_eq);
-
 
1429
		bs = enc_destr_count(bs, t, 1);
-
 
1430
		break;
1316
	}
1431
	}
1317
	return ( bs ) ;
-
 
1318
    }
-
 
1319
 
-
 
1320
    /* Simple destructor calls */
-
 
1321
    if ( IS_exp_destr ( e ) ) {
-
 
1322
	a = DEREF_exp ( exp_destr_obj ( e ) ) ;
-
 
1323
	COPY_ulong ( exp_dummy_no ( a ), n ) ;
-
 
1324
	COPY_off ( exp_dummy_off ( a ), off ) ;
-
 
1325
	COPY_int ( exp_dummy_cont ( a ), 2 * cnt ) ;
-
 
1326
	c = DEREF_exp ( exp_destr_count ( e ) ) ;
-
 
1327
	e = DEREF_exp ( exp_destr_call ( e ) ) ;
-
 
1328
    }
-
 
1329
    switch ( context ) {
-
 
1330
	case 1 :
-
 
1331
	case 3 : {
-
 
1332
	    /* Local variable */
-
 
1333
	    if ( !IS_NULL_exp ( c ) ) {
-
 
1334
		BITSTREAM *ts ;
-
 
1335
		bs = enc_special ( bs, TOK_destr_end ) ;
-
 
1336
		ts = start_bitstream ( NIL ( FILE ), bs->link ) ;
-
 
1337
		ts = enc_exp ( ts, c ) ;
-
 
1338
		bs = enc_bitstream ( bs, ts ) ;
-
 
1339
	    } else {
-
 
1340
		tops = 1 ;
-
 
1341
	    }
-
 
1342
	    break ;
-
 
1343
	}
1432
	}
1344
	case 4 : {
1433
	bs = enc_exp(bs, e);
1345
	    /* Explicitly initialised local variable */
-
 
1346
	    if ( !IS_NULL_exp ( c ) ) {
1434
	if (!IS_NULL_exp(a)) {
1347
		/* Check for initialisation */
1435
		/* Reset dummy expression */
1348
		BITSTREAM *ts ;
-
 
1349
		ulong lab = unit_no ( bs, NULL_id, VAR_label, 1 ) ;
-
 
1350
		ENC_conditional ( bs ) ;
-
 
1351
		ENC_make_label ( bs, lab ) ;
-
 
1352
		ENC_SEQ_SMALL ( bs, 2 ) ;
-
 
1353
		bs = enc_special ( bs, TOK_destr_test ) ;
-
 
1354
		ts = start_bitstream ( NIL ( FILE ), bs->link ) ;
-
 
1355
		ts = enc_exp ( ts, c ) ;
-
 
1356
		ENC_make_label ( ts, lab ) ;
1436
		COPY_off(exp_dummy_off(a), NULL_off);
1357
		bs = enc_bitstream ( bs, ts ) ;
-
 
1358
		bs = enc_special ( bs, TOK_destr_end ) ;
-
 
1359
		ts = start_bitstream ( NIL ( FILE ), bs->link ) ;
-
 
1360
		ts = enc_exp ( ts, c ) ;
-
 
1361
		bs = enc_bitstream ( bs, ts ) ;
-
 
1362
		tops = 2 ;
-
 
1363
	    } else {
-
 
1364
		tops = 1 ;
-
 
1365
	    }
-
 
1366
	    break ;
-
 
1367
	}
1437
	}
1368
	case 5 : {
1438
	while (tops) {
1369
	    /* Partial destructor count */
1439
		/* End any conditionals */
1370
	    ulong m = last_params [ DUMMY_count ] ;
-
 
1371
	    bs = enc_flag_test ( bs, m, ( unsigned ) 1, 0, ntest_not_eq ) ;
-
 
1372
	    bs = enc_destr_count ( bs, t, 1 ) ;
1440
		ENC_make_top(bs);
1373
	    break ;
1441
		tops--;
1374
	}
1442
	}
1375
    }
-
 
1376
    bs = enc_exp ( bs, e ) ;
-
 
1377
    if ( !IS_NULL_exp ( a ) ) {
-
 
1378
	/* Reset dummy expression */
-
 
1379
	COPY_off ( exp_dummy_off ( a ), NULL_off ) ;
-
 
1380
    }
-
 
1381
    while ( tops ) {
-
 
1382
	/* End any conditionals */
-
 
1383
	ENC_make_top ( bs ) ;
-
 
1384
	tops-- ;
-
 
1385
    }
-
 
1386
    return ( bs ) ;
1443
	return (bs);
1387
}
1444
}
1388
 
1445
 
1389
 
1446
 
1390
/*
1447
/*
1391
    ALLOCATION ROUTINES
1448
    ALLOCATION ROUTINES
Line 1396... Line 1453...
1396
#if LANGUAGE_CPP
1453
#if LANGUAGE_CPP
1397
 
1454
 
1398
 
1455
 
1399
/*
1456
/*
1400
    ENCODE A NEW-INITIALISER EXPRESSION
1457
    ENCODE A NEW-INITIALISER EXPRESSION
1401
 
1458
 
1402
    This routine adds the initialisation of the tag n, obtained from a
1459
    This routine adds the initialisation of the tag n, obtained from a
1403
    call to an allocation function, with the expression a to the bitstream
1460
    call to an allocation function, with the expression a to the bitstream
1404
    bs.  If d is not the null expression then any exceptions thrown by a
1461
    bs.  If d is not the null expression then any exceptions thrown by a
1405
    must be caught and the allocated memory freed using d.
1462
    must be caught and the allocated memory freed using d.
1406
*/
1463
*/
1407
 
1464
 
1408
static BITSTREAM *enc_init_new
1465
static BITSTREAM *
1409
    PROTO_N ( ( bs, n, a, d ) )
-
 
1410
    PROTO_T ( BITSTREAM *bs X ulong n X EXP a X EXP d )
1466
enc_init_new(BITSTREAM *bs, ulong n, EXP a, EXP d)
1411
{
1467
{
1412
    EXP a0 = new_try_body ( a ) ;
1468
	EXP a0 = new_try_body(a);
1413
    EXP a1 = DEREF_exp ( exp_assign_ref ( a0 ) ) ;
1469
	EXP a1 = DEREF_exp(exp_assign_ref(a0));
1414
    EXP a2 = DEREF_exp ( exp_assign_arg ( a0 ) ) ;
1470
	EXP a2 = DEREF_exp(exp_assign_arg(a0));
1415
    COPY_ulong ( exp_dummy_no ( a1 ), n ) ;
1471
	COPY_ulong(exp_dummy_no(a1), n);
1416
    if ( IS_NULL_exp ( d ) ) {
1472
	if (IS_NULL_exp(d)) {
1417
	/* Simple initialisation */
1473
		/* Simple initialisation */
1418
	a = DEREF_exp ( exp_try_block_body ( a ) ) ;
-
 
1419
	bs = enc_stmt ( bs, a ) ;
-
 
1420
    } else {
-
 
1421
	/* Initialisation with deletion */
-
 
1422
	int uc ;
-
 
1423
	ulong ex ;
-
 
1424
	TYPE s = NULL_type ;
-
 
1425
	ulong ptr = LINK_NONE ;
-
 
1426
	ulong prev = alloc_counter ;
-
 
1427
	TYPE t = DEREF_type ( exp_type ( a2 ) ) ;
-
 
1428
	EXP b = DEREF_exp ( exp_dealloc_term ( d ) ) ;
-
 
1429
	if ( IS_exp_nof ( a2 ) && !IS_NULL_exp ( b ) ) {
-
 
1430
	    /* Declare array initialisation counter */
-
 
1431
	    s = DEREF_type ( type_array_sub ( t ) ) ;
-
 
1432
	    ptr = unit_no ( bs, NULL_id, VAR_tag, 1 ) ;
-
 
1433
	    alloc_counter = ptr ;
-
 
1434
	    bs = enc_loop_decl ( bs, ptr, n, s, 1, NULL_off, NULL_type ) ;
-
 
1435
	} else {
-
 
1436
	    alloc_counter = LINK_NONE ;
-
 
1437
	}
-
 
1438
	bs = enc_try_start ( bs, &ex, ( unsigned ) 2 ) ;
-
 
1439
	COPY_ulong ( exp_try_block_no ( a ), ex ) ;
-
 
1440
	a = DEREF_exp ( exp_try_block_body ( a ) ) ;
1474
		a = DEREF_exp(exp_try_block_body(a));
1441
	bs = enc_stmt ( bs, a ) ;
1475
		bs = enc_stmt(bs, a);
1442
	bs = enc_try_end ( bs, ex ) ;
-
 
1443
	uc = unreached_code ;
-
 
1444
	if ( ptr == LINK_NONE ) {
-
 
1445
	    ENC_SEQ_SMALL ( bs, 1 ) ;
-
 
1446
	} else {
1476
	} else {
-
 
1477
		/* Initialisation with deletion */
-
 
1478
		int uc;
-
 
1479
		ulong ex;
-
 
1480
		TYPE s = NULL_type;
-
 
1481
		ulong ptr = LINK_NONE;
-
 
1482
		ulong prev = alloc_counter;
-
 
1483
		TYPE t = DEREF_type(exp_type(a2));
-
 
1484
		EXP b = DEREF_exp(exp_dealloc_term(d));
-
 
1485
		if (IS_exp_nof(a2) && !IS_NULL_exp(b)) {
-
 
1486
			/* Declare array initialisation counter */
-
 
1487
			s = DEREF_type(type_array_sub(t));
-
 
1488
			ptr = unit_no(bs, NULL_id, VAR_tag, 1);
-
 
1489
			alloc_counter = ptr;
-
 
1490
			bs = enc_loop_decl(bs, ptr, n, s, 1, NULL_off,
-
 
1491
					   NULL_type);
-
 
1492
		} else {
-
 
1493
			alloc_counter = LINK_NONE;
-
 
1494
		}
-
 
1495
		bs = enc_try_start(bs, &ex,(unsigned)2);
-
 
1496
		COPY_ulong(exp_try_block_no(a), ex);
-
 
1497
		a = DEREF_exp(exp_try_block_body(a));
-
 
1498
		bs = enc_stmt(bs, a);
-
 
1499
		bs = enc_try_end(bs, ex);
-
 
1500
		uc = unreached_code;
-
 
1501
		if (ptr == LINK_NONE) {
-
 
1502
			ENC_SEQ_SMALL(bs, 1);
-
 
1503
		} else {
1447
	    /* Destroy a partially constructed array */
1504
			/* Destroy a partially constructed array */
1448
	    EXP b1 = b ;
1505
			EXP b1 = b;
1449
	    ulong lab1 = unit_no ( bs, NULL_id, VAR_label, 1 ) ;
1506
			ulong lab1 = unit_no(bs, NULL_id, VAR_label, 1);
1450
	    ulong lab2 = unit_no ( bs, NULL_id, VAR_label, 1 ) ;
1507
			ulong lab2 = unit_no(bs, NULL_id, VAR_label, 1);
1451
	    ENC_SEQ_SMALL ( bs, 2 ) ;
1508
			ENC_SEQ_SMALL(bs, 2);
1452
	    ENC_conditional ( bs ) ;
1509
			ENC_conditional(bs);
1453
	    ENC_make_label ( bs, lab1 ) ;
1510
			ENC_make_label(bs, lab1);
1454
	    ENC_SEQ_SMALL ( bs, 1 ) ;
1511
			ENC_SEQ_SMALL(bs, 1);
1455
	    bs = enc_loop_test ( bs, ptr, n, s, lab1, ntest_not_eq ) ;
1512
			bs = enc_loop_test(bs, ptr, n, s, lab1, ntest_not_eq);
1456
	    ENC_repeat ( bs ) ;
1513
			ENC_repeat(bs);
1457
	    ENC_make_label ( bs, lab2 ) ;
1514
			ENC_make_label(bs, lab2);
1458
	    ENC_make_top ( bs ) ;
1515
			ENC_make_top(bs);
1459
	    ENC_SEQ_SMALL ( bs, 2 ) ;
1516
			ENC_SEQ_SMALL(bs, 2);
1460
	    bs = enc_loop_incr ( bs, ptr, s, 1 ) ;
1517
			bs = enc_loop_incr(bs, ptr, s, 1);
-
 
1518
			if (IS_exp_nof(b1)) {
1461
	    if ( IS_exp_nof ( b1 ) ) b1 = DEREF_exp ( exp_nof_pad ( b1 ) ) ;
1519
				b1 = DEREF_exp(exp_nof_pad(b1));
-
 
1520
			}
1462
	    bs = enc_term_local ( bs, ptr, NULL_off, 1, s, b1, 0 ) ;
1521
			bs = enc_term_local(bs, ptr, NULL_off, 1, s, b1, 0);
1463
	    bs = enc_loop_test ( bs, ptr, n, s, lab2, ntest_eq ) ;
1522
			bs = enc_loop_test(bs, ptr, n, s, lab2, ntest_eq);
1464
	    ENC_make_top ( bs ) ;
1523
			ENC_make_top(bs);
-
 
1524
		}
-
 
1525
		COPY_exp(exp_dealloc_term(d), NULL_exp);
-
 
1526
		bs = enc_dealloc(bs, d, n);
-
 
1527
		COPY_exp(exp_dealloc_term(d), b);
-
 
1528
		bs = enc_rethrow(bs);
-
 
1529
		alloc_counter = prev;
-
 
1530
		unreached_code = uc;
1465
	}
1531
	}
1466
	COPY_exp ( exp_dealloc_term ( d ), NULL_exp ) ;
-
 
1467
	bs = enc_dealloc ( bs, d, n ) ;
-
 
1468
	COPY_exp ( exp_dealloc_term ( d ), b ) ;
-
 
1469
	bs = enc_rethrow ( bs ) ;
-
 
1470
	alloc_counter = prev ;
-
 
1471
	unreached_code = uc ;
-
 
1472
    }
-
 
1473
    return ( bs ) ;
1532
	return (bs);
1474
}
1533
}
1475
 
1534
 
1476
 
1535
 
1477
/*
1536
/*
1478
    ENCODE AN ALLOCATION EXPRESSION
1537
    ENCODE AN ALLOCATION EXPRESSION
1479
 
1538
 
1480
    This routine adds the allocation expression e to the bitstream bs.
1539
    This routine adds the allocation expression e to the bitstream bs.
1612
 
1672
 
1613
 
1673
 
1614
/*
1674
/*
1615
    ENCODE A DEALLOCATION EXPRESSION
1675
    ENCODE A DEALLOCATION EXPRESSION
1616
 
1676
 
1617
    This routine adds the deallocation expression e to the bitstream bs.
1677
    This routine adds the deallocation expression e to the bitstream bs.
1618
    If the argument is already stored in a tag then this is given by n.
1678
    If the argument is already stored in a tag then this is given by n.
1619
*/
1679
*/
1620
 
1680
 
1621
BITSTREAM *enc_dealloc
1681
BITSTREAM *
1622
    PROTO_N ( ( bs, e, n ) )
-
 
1623
    PROTO_T ( BITSTREAM *bs X EXP e X ulong n )
1682
enc_dealloc(BITSTREAM *bs, EXP e, ulong n)
1624
{
1683
{
1625
    EXP a = DEREF_exp ( exp_dealloc_call ( e ) ) ;
1684
	EXP a = DEREF_exp(exp_dealloc_call(e));
1626
    EXP b = DEREF_exp ( exp_dealloc_term ( e ) ) ;
1685
	EXP b = DEREF_exp(exp_dealloc_term(e));
1627
    EXP c = DEREF_exp ( exp_dealloc_size ( e ) ) ;
1686
	EXP c = DEREF_exp(exp_dealloc_size(e));
1628
    EXP d = DEREF_exp ( exp_dealloc_arg ( e ) ) ;
1687
	EXP d = DEREF_exp(exp_dealloc_arg(e));
1629
    EXP d1 = DEREF_exp ( exp_dummy_value ( d ) ) ;
1688
	EXP d1 = DEREF_exp(exp_dummy_value(d));
1630
 
1689
 
1631
    /* Use given tag if necessary */
1690
	/* Use given tag if necessary */
1632
    int var = 1 ;
1691
	int var = 1;
1633
    if ( n != LINK_NONE ) {
1692
	if (n != LINK_NONE) {
1634
	COPY_exp ( exp_dummy_value ( d ), NULL_exp ) ;
1693
		COPY_exp(exp_dummy_value(d), NULL_exp);
1635
	COPY_ulong ( exp_dummy_no ( d ), n ) ;
1694
		COPY_ulong(exp_dummy_no(d), n);
1636
	var = 0 ;
1695
		var = 0;
1637
    }
-
 
1638
 
-
 
1639
    if ( IS_NULL_exp ( b ) && IS_NULL_exp ( c ) ) {
-
 
1640
	/* Simple case */
-
 
1641
	bs = enc_exp ( bs, a ) ;
-
 
1642
 
-
 
1643
    } else {
-
 
1644
	/* Complex case */
-
 
1645
	NAT i ;
-
 
1646
	TYPE t = DEREF_type ( exp_type ( d ) ) ;
-
 
1647
	TYPE s = DEREF_type ( type_ptr_sub ( t ) ) ;
-
 
1648
 
-
 
1649
	/* Check for virtual deallocators (see make_delete_exp) */
-
 
1650
	if ( !IS_NULL_exp ( a ) && IS_exp_paren ( a ) ) {
-
 
1651
	    if ( !IS_NULL_exp ( b ) ) a = NULL_exp ;
-
 
1652
	}
-
 
1653
 
-
 
1654
	/* Introduce variable for deallocation argument */
-
 
1655
	if ( var ) {
-
 
1656
	    unsigned seq = 2 ;
-
 
1657
	    ulong lab = unit_no ( bs, NULL_id, VAR_label, 1 ) ;
-
 
1658
	    n = unit_no ( bs, NULL_id, VAR_tag, 1 ) ;
-
 
1659
	    COPY_exp ( exp_dummy_value ( d ), NULL_exp ) ;
-
 
1660
	    COPY_ulong ( exp_dummy_no ( d ), n ) ;
-
 
1661
	    ENC_variable ( bs ) ;
-
 
1662
	    bs = enc_access ( bs, dspec_none ) ;
-
 
1663
	    ENC_make_tag ( bs, n ) ;
-
 
1664
	    bs = enc_exp ( bs, d1 ) ;
-
 
1665
 
-
 
1666
	    /* Check for null pointers */
-
 
1667
	    if ( !IS_NULL_exp ( c ) ) seq = 1 ;
-
 
1668
	    ENC_conditional ( bs ) ;
-
 
1669
	    ENC_make_label ( bs, lab ) ;
-
 
1670
	    ENC_SEQ_SMALL ( bs, seq ) ;
-
 
1671
	    bs = enc_loop_test ( bs, n, LINK_NONE, s, lab, ntest_not_eq ) ;
-
 
1672
	} else {
-
 
1673
	    if ( IS_NULL_exp ( c ) ) ENC_SEQ_SMALL ( bs, 1 ) ;
-
 
1674
	}
1696
	}
1675
 
1697
 
-
 
1698
	if (IS_NULL_exp(b) && IS_NULL_exp(c)) {
-
 
1699
		/* Simple case */
-
 
1700
		bs = enc_exp(bs, a);
-
 
1701
 
-
 
1702
	} else {
-
 
1703
		/* Complex case */
-
 
1704
		NAT i;
-
 
1705
		TYPE t = DEREF_type(exp_type(d));
-
 
1706
		TYPE s = DEREF_type(type_ptr_sub(t));
-
 
1707
 
-
 
1708
		/* Check for virtual deallocators (see make_delete_exp) */
-
 
1709
		if (!IS_NULL_exp(a) && IS_exp_paren(a)) {
-
 
1710
			if (!IS_NULL_exp(b)) {
-
 
1711
				a = NULL_exp;
-
 
1712
			}
-
 
1713
		}
-
 
1714
 
-
 
1715
		/* Introduce variable for deallocation argument */
-
 
1716
		if (var) {
-
 
1717
			unsigned seq = 2;
-
 
1718
			ulong lab = unit_no(bs, NULL_id, VAR_label, 1);
-
 
1719
			n = unit_no(bs, NULL_id, VAR_tag, 1);
-
 
1720
			COPY_exp(exp_dummy_value(d), NULL_exp);
-
 
1721
			COPY_ulong(exp_dummy_no(d), n);
-
 
1722
			ENC_variable(bs);
-
 
1723
			bs = enc_access(bs, dspec_none);
-
 
1724
			ENC_make_tag(bs, n);
-
 
1725
			bs = enc_exp(bs, d1);
-
 
1726
 
-
 
1727
			/* Check for null pointers */
-
 
1728
			if (!IS_NULL_exp(c)) {
-
 
1729
				seq = 1;
-
 
1730
			}
-
 
1731
			ENC_conditional(bs);
-
 
1732
			ENC_make_label(bs, lab);
-
 
1733
			ENC_SEQ_SMALL(bs, seq);
-
 
1734
			bs = enc_loop_test(bs, n, LINK_NONE, s, lab,
-
 
1735
					   ntest_not_eq);
-
 
1736
		} else {
-
 
1737
			if (IS_NULL_exp(c))ENC_SEQ_SMALL(bs, 1);
-
 
1738
		}
-
 
1739
 
1676
	/* Introduce identity for array size */
1740
		/* Introduce identity for array size */
1677
	if ( !IS_NULL_exp ( c ) ) {
1741
		if (!IS_NULL_exp(c)) {
1678
	    if ( IS_exp_dummy ( c ) ) {
1742
			if (IS_exp_dummy(c)) {
1679
		int bf = 0 ;
1743
				int bf = 0;
1680
		BITSTREAM *ts ;
1744
				BITSTREAM *ts;
1681
		TYPE tz = type_size_t ;
1745
				TYPE tz = type_size_t;
1682
		ulong m = unit_no ( bs, NULL_id, VAR_tag, 1 ) ;
1746
				ulong m = unit_no(bs, NULL_id, VAR_tag, 1);
1683
		COPY_ulong ( exp_dummy_no ( c ), m ) ;
1747
				COPY_ulong(exp_dummy_no(c), m);
1684
 
1748
 
1685
		/* Find array size */
1749
				/* Find array size */
1686
		ENC_identify ( bs ) ;
1750
				ENC_identify(bs);
1687
		bs = enc_access ( bs, dspec_none ) ;
1751
				bs = enc_access(bs, dspec_none);
1688
		ENC_make_tag ( bs, m ) ;
1752
				ENC_make_tag(bs, m);
1689
		ENC_contents ( bs ) ;
1753
				ENC_contents(bs);
1690
		bs = enc_shape ( bs, tz ) ;
1754
				bs = enc_shape(bs, tz);
1691
		bs = enc_special ( bs, TOK_ptr_to_ptr ) ;
1755
				bs = enc_special(bs, TOK_ptr_to_ptr);
1692
		ts = start_bitstream ( NIL ( FILE ), bs->link ) ;
1756
				ts = start_bitstream(NIL(FILE), bs->link);
1693
		ts = enc_alignment ( ts, s ) ;
1757
				ts = enc_alignment(ts, s);
1694
		ts = enc_alignment ( ts, tz ) ;
1758
				ts = enc_alignment(ts, tz);
1695
		ENC_add_to_ptr ( ts ) ;
1759
				ENC_add_to_ptr(ts);
1696
		ts = enc_cont_op ( ts, t, &bf ) ;
1760
				ts = enc_cont_op(ts, t, &bf);
1697
		ts = enc_shape ( ts, t ) ;
1761
				ts = enc_shape(ts, t);
1698
		ENC_obtain_tag ( ts ) ;
1762
				ENC_obtain_tag(ts);
1699
		ENC_make_tag ( ts, n ) ;
1763
				ENC_make_tag(ts, n);
1700
		ts = enc_extra_offset ( ts, s, off_size_t, -1 ) ;
1764
				ts = enc_extra_offset(ts, s, off_size_t, -1);
1701
		bs = enc_bitstream ( bs, ts ) ;
1765
				bs = enc_bitstream(bs, ts);
1702
		ASSERT ( bf == 0 ) ;
1766
				ASSERT(bf == 0);
-
 
1767
			}
-
 
1768
 
-
 
1769
			/* Construct dummy array type */
-
 
1770
			if (!IS_NULL_exp(b)) {
-
 
1771
				MAKE_nat_calc(c, i);
-
 
1772
				MAKE_type_array(cv_none, s, i, s);
-
 
1773
				ENC_SEQ_SMALL(bs, 1);
-
 
1774
			}
-
 
1775
		}
-
 
1776
 
-
 
1777
		/* Encode destructors */
-
 
1778
		if (!IS_NULL_exp(b)) {
-
 
1779
			bs = enc_term_local(bs, n, NULL_off, 1, s, b, 0);
-
 
1780
			if (!IS_NULL_exp(c)) {
-
 
1781
				/* Destroy dummy array type */
-
 
1782
				ulong tok;
-
 
1783
				CV_SPEC cv;
-
 
1784
				IDENTIFIER tid;
-
 
1785
				DESTROY_type_array(destroy, cv, tid, s, i, s);
-
 
1786
				DESTROY_nat_calc(destroy, c, tok, i);
-
 
1787
				UNUSED(tok);
-
 
1788
				UNUSED(tid);
-
 
1789
				UNUSED(cv);
-
 
1790
				UNUSED(c);
-
 
1791
				UNUSED(s);
1703
	    }
1792
			}
-
 
1793
		}
1704
 
1794
 
1705
	    /* Construct dummy array type */
-
 
1706
	    if ( !IS_NULL_exp ( b ) ) {
-
 
1707
		MAKE_nat_calc ( c, i ) ;
-
 
1708
		MAKE_type_array ( cv_none, s, i, s ) ;
-
 
1709
		ENC_SEQ_SMALL ( bs, 1 ) ;
-
 
1710
	    }
-
 
1711
	}
-
 
1712
 
-
 
1713
	/* Encode destructors */
-
 
1714
	if ( !IS_NULL_exp ( b ) ) {
-
 
1715
	    bs = enc_term_local ( bs, n, NULL_off, 1, s, b, 0 ) ;
-
 
1716
	    if ( !IS_NULL_exp ( c ) ) {
-
 
1717
		/* Destroy dummy array type */
-
 
1718
		ulong tok ;
-
 
1719
		CV_SPEC cv ;
-
 
1720
		IDENTIFIER tid ;
-
 
1721
		DESTROY_type_array ( destroy, cv, tid, s, i, s ) ;
-
 
1722
		DESTROY_nat_calc ( destroy, c, tok, i ) ;
-
 
1723
		UNUSED ( tok ) ;
-
 
1724
		UNUSED ( tid ) ;
-
 
1725
		UNUSED ( cv ) ;
-
 
1726
		UNUSED ( c ) ;
-
 
1727
		UNUSED ( s ) ;
-
 
1728
	    }
-
 
1729
	}
-
 
1730
 
-
 
1731
	/* Encode deallocation function call */
1795
		/* Encode deallocation function call */
1732
	bs = enc_exp ( bs, a ) ;
1796
		bs = enc_exp(bs, a);
1733
	if ( var ) {
1797
		if (var) {
1734
	    /* End conditional */
1798
			/* End conditional */
1735
	    ENC_make_top ( bs ) ;
1799
			ENC_make_top(bs);
-
 
1800
		}
1736
	}
1801
	}
1737
    }
-
 
1738
    COPY_exp ( exp_dummy_value ( d ), d1 ) ;
1802
	COPY_exp(exp_dummy_value(d), d1);
1739
    return ( bs ) ;
1803
	return (bs);
1740
}
1804
}
1741
 
1805
 
1742
 
1806
 
1743
#endif /* LANGUAGE_CPP */
1807
#endif /* LANGUAGE_CPP */
1744
#endif /* TDF_OUTPUT */
1808
#endif /* TDF_OUTPUT */