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

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

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

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

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

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

Subversion Repositories tendra.SVN

Rev

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

Rev 2 Rev 7
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2006 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997, 1998
32
    		 Crown Copyright (c) 1997, 1998
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
Line 84... Line 114...
84
    the top node of a graph, a virtual base class, or a non-virtual base
114
    the top node of a graph, a virtual base class, or a non-virtual base
85
    class.  These macros give mnemonic values for these uses.  Names are
115
    class.  These macros give mnemonic values for these uses.  Names are
86
    also given to the various class type token numbers.
116
    also given to the various class type token numbers.
87
*/
117
*/
88
 
118
 
89
#define ctype_shape( A )	ctype_tok1 ( ( A ) )
119
#define ctype_shape(A)		ctype_tok1((A))
90
#define ctype_null_exp( A )	ctype_tok2 ( ( A ) )
120
#define ctype_null_exp(A)	ctype_tok2((A))
91
#define graph_al_tag( A )	graph_tok1 ( ( A ) )
121
#define graph_al_tag(A)		graph_tok1((A))
92
#define graph_core_off( A )	graph_tok2 ( ( A ) )
122
#define graph_core_off(A)	graph_tok2((A))
93
#define graph_base_off( A )	graph_tok1 ( ( A ) )
123
#define graph_base_off(A)	graph_tok1((A))
94
#define graph_real_off( A )	graph_tok2 ( ( A ) )
124
#define graph_real_off(A)	graph_tok2((A))
95
 
125
 
96
 
126
 
97
/*
127
/*
98
    DUMMY CLASS TYPE
128
    DUMMY CLASS TYPE
99
 
129
 
100
    These types are dummies used in the class layout routines.
130
    These types are dummies used in the class layout routines.
101
*/
131
*/
102
 
132
 
103
TYPE dummy_class = NULL_type ;
133
TYPE dummy_class = NULL_type;
104
TYPE dummy_vtab = NULL_type ;
134
TYPE dummy_vtab = NULL_type;
105
TYPE dummy_count = NULL_type ;
135
TYPE dummy_count = NULL_type;
106
TYPE ptr_dummy_class = NULL_type ;
136
TYPE ptr_dummy_class = NULL_type;
107
TYPE ptr_dummy_vtab = NULL_type ;
137
TYPE ptr_dummy_vtab = NULL_type;
108
TYPE dummy_func = NULL_type ;
138
TYPE dummy_func = NULL_type;
109
ulong size_dummy_vtab = 0 ;
139
ulong size_dummy_vtab = 0;
110
OFFSET off_size_t = NULL_off ;
140
OFFSET off_size_t = NULL_off;
111
IDENTIFIER dummy_type_name = NULL_id ;
141
IDENTIFIER dummy_type_name = NULL_id;
112
 
142
 
113
 
143
 
114
/*
144
/*
115
    ENCODE AN EXPRESSION TOKEN APPLICATION
145
    ENCODE AN EXPRESSION TOKEN APPLICATION
116
 
146
 
117
    This routine adds an application of the simple expression token n to
147
    This routine adds an application of the simple expression token n to
118
    the bitstream bs.
148
    the bitstream bs.
119
*/
149
*/
120
 
150
 
121
static BITSTREAM *enc_exp_token
151
static BITSTREAM *
122
    PROTO_N ( ( bs, n ) )
-
 
123
    PROTO_T ( BITSTREAM *bs X ulong n )
152
enc_exp_token(BITSTREAM *bs, ulong n)
124
{
153
{
125
    ulong m = link_no ( bs, n, VAR_token ) ;
154
	ulong m = link_no(bs, n, VAR_token);
126
    ENC_exp_apply_token ( bs ) ;
155
	ENC_exp_apply_token(bs);
127
    ENC_make_tok ( bs, m ) ;
156
	ENC_make_tok(bs, m);
128
    ENC_LEN_SMALL ( bs, 0 ) ;
157
	ENC_LEN_SMALL(bs, 0);
129
    return ( bs ) ;
158
	return (bs);
130
}
159
}
131
 
160
 
132
 
161
 
133
/*
162
/*
134
    ENCODE A SHAPE TOKEN APPLICATION
163
    ENCODE A SHAPE TOKEN APPLICATION
135
 
164
 
136
    This routine adds an application of the simple shape token n to the
165
    This routine adds an application of the simple shape token n to the
137
    bitstream bs.
166
    bitstream bs.
138
*/
167
*/
139
 
168
 
140
static BITSTREAM *enc_shape_token
169
static BITSTREAM *
141
    PROTO_N ( ( bs, n ) )
-
 
142
    PROTO_T ( BITSTREAM *bs X ulong n )
170
enc_shape_token(BITSTREAM *bs, ulong n)
143
{
171
{
144
    ulong m = link_no ( bs, n, VAR_token ) ;
172
	ulong m = link_no(bs, n, VAR_token);
145
    ENC_shape_apply_token ( bs ) ;
173
	ENC_shape_apply_token(bs);
146
    ENC_make_tok ( bs, m ) ;
174
	ENC_make_tok(bs, m);
147
    ENC_LEN_SMALL ( bs, 0 ) ;
175
	ENC_LEN_SMALL(bs, 0);
148
    return ( bs ) ;
176
	return (bs);
149
}
177
}
150
 
178
 
151
 
179
 
152
/*
180
/*
153
    VIRTUAL FUNCTION TABLE ROUTINES
181
    VIRTUAL FUNCTION TABLE ROUTINES
Line 162... Line 190...
162
/*
190
/*
163
    ENCODE A BUFFER AS A STRING LITERAL
191
    ENCODE A BUFFER AS A STRING LITERAL
164
 
192
 
165
    This routine adds the contents of the buffer bf to the bitstream bs
193
    This routine adds the contents of the buffer bf to the bitstream bs
166
    as a string literal.
194
    as a string literal.
167
*/
195
*/
168
 
196
 
169
static BITSTREAM *enc_buffer
197
static BITSTREAM *
170
    PROTO_N ( ( bs, bf ) )
-
 
171
    PROTO_T ( BITSTREAM *bs X BUFFER *bf )
198
enc_buffer(BITSTREAM *bs, BUFFER *bf)
172
{
199
{
173
    string s = bf->start ;
200
	string s = bf->start;
174
    unsigned long n = ( unsigned long ) ( bf->posn - s ) ;
201
	unsigned long n = (unsigned long)(bf->posn - s);
175
 
202
 
176
    /* Declare the string literal */
203
	/* Declare the string literal */
177
    ulong m = capsule_no ( NULL_string, VAR_tag ) ;
204
	ulong m = capsule_no(NULL_string, VAR_tag);
178
    BITSTREAM *ts = enc_tagdec_start ( NULL_id, m, NULL_type, 1 ) ;
205
	BITSTREAM *ts = enc_tagdec_start(NULL_id, m, NULL_type, 1);
179
    ENC_nof ( ts ) ;
206
	ENC_nof(ts);
180
    ENC_make_nat ( ts ) ;
207
	ENC_make_nat(ts);
181
    ENC_INT ( ts, n ) ;
208
	ENC_INT(ts, n);
182
    ts = enc_shape ( ts, type_char ) ;
209
	ts = enc_shape(ts, type_char);
183
    enc_tagdec_end ( ts ) ;
210
	enc_tagdec_end(ts);
184
 
211
 
185
    /* Define the string literal */
212
	/* Define the string literal */
186
    ts = enc_tagdef_start ( NULL_id, m, NULL_type, 1 ) ;
213
	ts = enc_tagdef_start(NULL_id, m, NULL_type, 1);
187
    ENC_make_nof_int ( ts ) ;
214
	ENC_make_nof_int(ts);
188
    ts = enc_variety ( ts, type_char ) ;
215
	ts = enc_variety(ts, type_char);
189
    ENC_make_string ( ts ) ;
216
	ENC_make_string(ts);
190
    ts = enc_tdfstring ( ts, n, s ) ;
217
	ts = enc_tdfstring(ts, n, s);
191
    enc_tagdef_end ( ts ) ;
218
	enc_tagdef_end(ts);
192
 
219
 
193
    /* Encode the result */
220
	/* Encode the result */
194
    m = link_no ( bs, m, VAR_tag ) ;
221
	m = link_no(bs, m, VAR_tag);
195
    ENC_obtain_tag ( bs ) ;
222
	ENC_obtain_tag(bs);
196
    ENC_make_tag ( bs, m ) ;
223
	ENC_make_tag(bs, m);
197
    return ( bs ) ;
224
	return (bs);
198
}
225
}
199
 
226
 
200
 
227
 
201
/*
228
/*
202
    ENCODE RUN-TIME BASE CLASS INFORMATION
229
    ENCODE RUN-TIME BASE CLASS INFORMATION
203
 
230
 
204
    This routine defines the run-time base class information for the base
231
    This routine defines the run-time base class information for the base
205
    classes br or the sub-types pt and adds the address of the first base
232
    classes br or the sub-types pt and adds the address of the first base
206
    to bs.
233
    to bs.
207
*/
234
*/
208
 
235
 
209
static BITSTREAM *enc_rtti_bases
236
static BITSTREAM *
210
    PROTO_N ( ( bs, br, pt, sz ) )
-
 
211
    PROTO_T ( BITSTREAM *bs X LIST ( GRAPH ) br X LIST ( TYPE ) pt X NAT sz )
237
enc_rtti_bases(BITSTREAM *bs, LIST(GRAPH)br, LIST(TYPE)pt, NAT sz)
212
{
238
{
213
    TYPE t ;
239
	TYPE t;
214
    ulong n, m ;
240
	ulong n, m;
215
    BITSTREAM *ts, *us ;
241
	BITSTREAM *ts, *us;
216
    int a = INFO_public ;
242
	int a = INFO_public;
217
 
243
 
218
    if ( !IS_NULL_list ( br ) ) {
244
	if (!IS_NULL_list(br)) {
219
	/* Get base class information */
245
		/* Get base class information */
220
	VIRTUAL vt ;
246
		VIRTUAL vt;
221
	CLASS_TYPE ct ;
247
		CLASS_TYPE ct;
222
	GRAPH gr = DEREF_graph ( HEAD_list ( br ) ) ;
248
		GRAPH gr = DEREF_graph(HEAD_list(br));
223
	DECL_SPEC acc = DEREF_dspec ( graph_access ( gr ) ) ;
249
		DECL_SPEC acc = DEREF_dspec(graph_access(gr));
224
	br = TAIL_list ( br ) ;
250
		br = TAIL_list(br);
225
 
251
 
226
	/* Find base class information */
252
		/* Find base class information */
227
	ct = DEREF_ctype ( graph_head ( gr ) ) ;
253
		ct = DEREF_ctype(graph_head(gr));
228
	t = make_class_type ( ct ) ;
254
		t = make_class_type(ct);
229
	vt = DEREF_virt ( ctype_virt ( ct ) ) ;
255
		vt = DEREF_virt(ctype_virt(ct));
230
	if ( !IS_NULL_virt ( vt ) ) {
256
		if (!IS_NULL_virt(vt)) {
231
	    /* Make sure base class is declared */
257
			/* Make sure base class is declared */
232
	    int used = DEREF_int ( virt_table_rtti_used ( vt ) ) ;
258
			int used = DEREF_int(virt_table_rtti_used(vt));
233
	    if ( !used ) {
259
			if (!used) {
234
		IDENTIFIER cid = DEREF_id ( ctype_name ( ct ) ) ;
260
				IDENTIFIER cid = DEREF_id(ctype_name(ct));
235
		COPY_int ( virt_table_rtti_used ( vt ), 1 ) ;
261
				COPY_int(virt_table_rtti_used(vt), 1);
236
		compile_virtual ( ct, !has_linkage ( cid ) ) ;
262
				compile_virtual(ct, !has_linkage(cid));
237
	    }
263
			}
238
	}
264
		}
239
	if ( acc & dspec_virtual ) sz = small_nat [1] ;
265
		if (acc & dspec_virtual) {
-
 
266
			sz = small_nat[1];
-
 
267
		}
240
	acc &= dspec_access ;
268
		acc &= dspec_access;
241
	if ( acc == dspec_protected ) {
269
		if (acc == dspec_protected) {
242
	    a = INFO_protected ;
270
			a = INFO_protected;
243
	} else if ( acc == dspec_private ) {
271
		} else if (acc == dspec_private) {
244
	    a = INFO_private ;
272
			a = INFO_private;
245
	}
273
		}
246
	m = DEREF_ulong ( graph_base_off ( gr ) ) ;
274
		m = DEREF_ulong(graph_base_off(gr));
247
 
275
 
248
    } else if ( !IS_NULL_list ( pt ) ) {
276
	} else if (!IS_NULL_list(pt)) {
249
	/* Get sub-type information */
277
		/* Get sub-type information */
250
	t = DEREF_type ( HEAD_list ( pt ) ) ;
278
		t = DEREF_type(HEAD_list(pt));
251
	pt = TAIL_list ( pt ) ;
279
		pt = TAIL_list(pt);
252
	if ( !IS_NULL_type ( t ) ) {
280
		if (!IS_NULL_type(t)) {
253
	    CV_SPEC cv = DEREF_cv ( type_qual ( t ) ) ;
281
			CV_SPEC cv = DEREF_cv(type_qual(t));
254
	    if ( IS_type_func ( t ) ) {
282
			if (IS_type_func(t)) {
255
		/* Allow for function qualifiers */
283
				/* Allow for function qualifiers */
256
		cv = DEREF_cv ( type_func_mqual ( t ) ) ;
284
				cv = DEREF_cv(type_func_mqual(t));
257
	    }
285
			}
258
	    if ( cv ) {
286
			if (cv) {
259
		if ( cv & cv_const ) a |= INFO_const ;
287
				if (cv & cv_const) {
-
 
288
					a |= INFO_const;
-
 
289
				}
260
		if ( cv & cv_volatile ) a |= INFO_volatile ;
290
				if (cv & cv_volatile) {
-
 
291
					a |= INFO_volatile;
-
 
292
				}
261
		t = qualify_type ( t, cv_none, 0 ) ;
293
				t = qualify_type(t, cv_none, 0);
262
	    }
294
			}
263
	}
295
		}
264
	m = LINK_NONE ;
296
		m = LINK_NONE;
265
 
297
 
266
    } else {
298
	} else {
267
	/* Output end of list */
299
		/* Output end of list */
268
	ENC_make_null_ptr ( bs ) ;
300
		ENC_make_null_ptr(bs);
269
	ENC_alignment ( bs ) ;
301
		ENC_alignment(bs);
270
	bs = enc_special ( bs, TOK_baseid_type ) ;
302
		bs = enc_special(bs, TOK_baseid_type);
271
	return ( bs ) ;
303
		return (bs);
272
    }
-
 
273
 
304
	}
274
    /* Declare base structure */
-
 
275
    n = capsule_no ( NULL_string, VAR_tag ) ;
-
 
276
    ts = enc_tagdec_start ( NULL_id, n, NULL_type, 1 ) ;
-
 
277
    ts = enc_special ( ts, TOK_baseid_type ) ;
-
 
278
    enc_tagdec_end ( ts ) ;
-
 
279
 
305
 
-
 
306
	/* Declare base structure */
-
 
307
	n = capsule_no(NULL_string, VAR_tag);
-
 
308
	ts = enc_tagdec_start(NULL_id, n, NULL_type, 1);
-
 
309
	ts = enc_special(ts, TOK_baseid_type);
-
 
310
	enc_tagdec_end(ts);
-
 
311
 
280
    /* Define base structure */
312
	/* Define base structure */
281
    ts = enc_tagdef_start ( NULL_id, n, NULL_type, 1 ) ;
313
	ts = enc_tagdef_start(NULL_id, n, NULL_type, 1);
282
    ts = enc_special ( ts, TOK_baseid_make ) ;
314
	ts = enc_special(ts, TOK_baseid_make);
283
    us = start_bitstream ( NIL ( FILE ), ts->link ) ;
315
	us = start_bitstream(NIL(FILE), ts->link);
284
    us = enc_rtti_type ( us, t, lex_typeid ) ;
316
	us = enc_rtti_type(us, t, lex_typeid);
285
    if ( m == LINK_NONE ) {
317
	if (m == LINK_NONE) {
286
	ENC_offset_zero ( us ) ;
318
		ENC_offset_zero(us);
287
	us = enc_alignment ( us, type_sint ) ;
319
		us = enc_alignment(us, type_sint);
288
    } else {
320
	} else {
289
	us = enc_exp_token ( us, m ) ;
321
		us = enc_exp_token(us, m);
290
    }
322
	}
291
    us = enc_rtti_bases ( us, br, pt, NULL_nat ) ;
323
	us = enc_rtti_bases(us, br, pt, NULL_nat);
292
    us = enc_make_snat ( us, a ) ;
324
	us = enc_make_snat(us, a);
293
    us = enc_snat ( us, sz, 0, 0 ) ;
325
	us = enc_snat(us, sz, 0, 0);
294
    ts = enc_bitstream ( ts, us ) ;
326
	ts = enc_bitstream(ts, us);
295
    enc_tagdef_end ( ts ) ;
327
	enc_tagdef_end(ts);
296
 
328
 
297
    /* Encode the result */
329
	/* Encode the result */
298
    n = link_no ( bs, n, VAR_tag ) ;
330
	n = link_no(bs, n, VAR_tag);
299
    ENC_obtain_tag ( bs ) ;
331
	ENC_obtain_tag(bs);
300
    ENC_make_tag ( bs, n ) ;
332
	ENC_make_tag(bs, n);
301
    return ( bs ) ;
333
	return (bs);
302
}
334
}
303
 
335
 
304
 
336
 
305
/*
337
/*
306
    ENCODE A RUN-TIME TYPE INFORMATION STRUCTURE
338
    ENCODE A RUN-TIME TYPE INFORMATION STRUCTURE
Line 308... Line 340...
308
    This routine defines the tag n to be the run-time type information
340
    This routine defines the tag n to be the run-time type information
309
    structure for the type t.  If def is false then only the declaration
341
    structure for the type t.  If def is false then only the declaration
310
    is output.
342
    is output.
311
*/
343
*/
312
 
344
 
313
static void enc_rtti_struct
345
static void
314
    PROTO_N ( ( t, n, def ) )
-
 
315
    PROTO_T ( TYPE t X ulong n X int def )
346
enc_rtti_struct(TYPE t, ulong n, int def)
316
{
347
{
317
    unsigned acc = find_usage ( n, VAR_tag ) ;
348
	unsigned acc = find_usage(n, VAR_tag);
318
    if ( !( acc & USAGE_DECL ) ) {
349
	if (!(acc & USAGE_DECL)) {
319
	BITSTREAM *bs = enc_tagdec_start ( NULL_id, n, NULL_type, 1 ) ;
350
		BITSTREAM *bs = enc_tagdec_start(NULL_id, n, NULL_type, 1);
320
	bs = enc_special ( bs, TOK_typeid_type ) ;
351
		bs = enc_special(bs, TOK_typeid_type);
321
	enc_tagdec_end ( bs ) ;
352
		enc_tagdec_end(bs);
322
    }
353
	}
323
    if ( def && !( acc & USAGE_DEFN ) ) {
354
	if (def && !(acc & USAGE_DEFN)) {
324
	int c = RTTI_void ;
355
		int c = RTTI_void;
325
	NAT sz = NULL_nat ;
356
		NAT sz = NULL_nat;
326
	BITSTREAM *bs, *ts ;
357
		BITSTREAM *bs, *ts;
327
	LIST ( TYPE ) p = NULL_list ( TYPE ) ;
358
		LIST(TYPE)p = NULL_list(TYPE);
328
	LIST ( GRAPH ) br = NULL_list ( GRAPH ) ;
359
		LIST(GRAPH)br = NULL_list(GRAPH);
329
	BUFFER *bf = clear_buffer ( &print_buff, NIL ( FILE ) ) ;
360
		BUFFER *bf = clear_buffer(&print_buff, NIL(FILE));
330
	print_uniq_anon++ ;
361
		print_uniq_anon++;
331
	IGNORE print_type ( t, bf, 0 ) ;
362
		IGNORE print_type(t, bf, 0);
332
	print_uniq_anon-- ;
363
		print_uniq_anon--;
333
	bfputc ( bf, 0 ) ;
364
		bfputc(bf, 0);
334
	switch ( TAG_type ( t ) ) {
365
		switch (TAG_type(t)) {
335
	    case type_integer_tag : {
366
		case type_integer_tag: {
336
		/* Integral types */
367
			/* Integral types */
337
		c = RTTI_integer ;
368
			c = RTTI_integer;
338
		break ;
369
			break;
339
	    }
370
		}
340
	    case type_floating_tag : {
371
		case type_floating_tag: {
341
		/* Floating-point types */
372
			/* Floating-point types */
342
		c = RTTI_float ;
373
			c = RTTI_float;
343
		break ;
374
			break;
344
	    }
375
		}
345
	    case type_ptr_tag : {
376
		case type_ptr_tag: {
346
		/* Pointer types */
377
			/* Pointer types */
347
		TYPE s = DEREF_type ( type_ptr_sub ( t ) ) ;
378
			TYPE s = DEREF_type(type_ptr_sub(t));
348
		CONS_type ( s, p, p ) ;
379
			CONS_type(s, p, p);
349
		c = RTTI_ptr ;
380
			c = RTTI_ptr;
350
		break ;
381
			break;
351
	    }
382
		}
352
	    case type_ref_tag : {
383
		case type_ref_tag: {
353
		/* Reference types */
384
			/* Reference types */
354
		TYPE s = DEREF_type ( type_ref_sub ( t ) ) ;
385
			TYPE s = DEREF_type(type_ref_sub(t));
355
		CONS_type ( s, p, p ) ;
386
			CONS_type(s, p, p);
356
		c = RTTI_ref ;
387
			c = RTTI_ref;
357
		break ;
388
			break;
358
	    }
389
		}
359
	    case type_ptr_mem_tag : {
390
		case type_ptr_mem_tag: {
360
		/* Pointer to member types */
391
			/* Pointer to member types */
361
		TYPE s = DEREF_type ( type_ptr_mem_sub ( t ) ) ;
392
			TYPE s = DEREF_type(type_ptr_mem_sub(t));
362
		CLASS_TYPE cs = DEREF_ctype ( type_ptr_mem_of ( t ) ) ;
393
			CLASS_TYPE cs = DEREF_ctype(type_ptr_mem_of(t));
363
		CONS_type ( s, p, p ) ;
394
			CONS_type(s, p, p);
364
		s = make_class_type ( cs ) ;
395
			s = make_class_type(cs);
365
		CONS_type ( s, p, p ) ;
396
			CONS_type(s, p, p);
366
		c = RTTI_ptr_mem ;
397
			c = RTTI_ptr_mem;
367
		break ;
398
			break;
368
	    }
399
		}
369
	    case type_func_tag : {
400
		case type_func_tag: {
370
		/* Function types */
401
			/* Function types */
371
		TYPE s = DEREF_type ( type_func_ret ( t ) ) ;
402
			TYPE s = DEREF_type(type_func_ret(t));
372
		CV_SPEC mq = DEREF_cv ( type_func_mqual ( t ) ) ;
403
			CV_SPEC mq = DEREF_cv(type_func_mqual(t));
373
		int ell = DEREF_int ( type_func_ellipsis ( t ) ) ;
404
			int ell = DEREF_int(type_func_ellipsis(t));
374
		LIST ( TYPE ) q = DEREF_list ( type_func_ptypes ( t ) ) ;
405
			LIST(TYPE)q = DEREF_list(type_func_ptypes(t));
375
		CONS_type ( s, p, p ) ;
406
			CONS_type(s, p, p);
376
		while ( !IS_NULL_list ( q ) ) {
407
			while (!IS_NULL_list(q)) {
377
		    s = DEREF_type ( HEAD_list ( q ) ) ;
408
				s = DEREF_type(HEAD_list(q));
378
		    CONS_type ( s, p, p ) ;
409
				CONS_type(s, p, p);
379
		    q = TAIL_list ( q ) ;
410
				q = TAIL_list(q);
380
		}
411
			}
381
		if ( ell & FUNC_ELLIPSIS ) {
412
			if (ell & FUNC_ELLIPSIS) {
382
		    CONS_type ( type_any, p, p ) ;
413
				CONS_type(type_any, p, p);
-
 
414
			}
-
 
415
			p = REVERSE_list(p);
-
 
416
			if (mq & cv_c) {
-
 
417
				c = RTTI_c_func;
-
 
418
			} else {
-
 
419
				c = RTTI_func;
-
 
420
			}
-
 
421
			break;
-
 
422
		}
-
 
423
		case type_array_tag: {
-
 
424
			/* Array types */
-
 
425
			TYPE s = DEREF_type(type_array_sub(t));
-
 
426
			CONS_type(s, p, p);
-
 
427
			sz = DEREF_nat(type_array_size(t));
-
 
428
			c = RTTI_array;
-
 
429
			break;
-
 
430
		}
-
 
431
		case type_bitfield_tag: {
-
 
432
			/* Bitfield types */
-
 
433
			INT_TYPE it = DEREF_itype(type_bitfield_defn(t));
-
 
434
			TYPE s = DEREF_type(itype_bitfield_sub(it));
-
 
435
			CONS_type(s, p, p);
-
 
436
			sz = DEREF_nat(itype_bitfield_size(it));
-
 
437
			c = RTTI_bitfield;
-
 
438
			break;
-
 
439
		}
-
 
440
		case type_compound_tag: {
-
 
441
			/* Class types */
-
 
442
			CLASS_TYPE ct = DEREF_ctype(type_compound_defn(t));
-
 
443
			CLASS_INFO ci = DEREF_cinfo(ctype_info(ct));
-
 
444
			GRAPH gr = DEREF_graph(ctype_base(ct));
-
 
445
			br = DEREF_list(graph_tails(gr));
-
 
446
			if (ci & cinfo_union) {
-
 
447
				c = RTTI_union;
-
 
448
			} else {
-
 
449
				c = RTTI_class;
-
 
450
			}
-
 
451
			break;
383
		}
452
		}
384
		p = REVERSE_list ( p ) ;
453
		case type_enumerate_tag: {
385
		if ( mq & cv_c ) {
454
			/* Enumeration types */
386
		    c = RTTI_c_func ;
455
			c = RTTI_enum;
387
		} else {
456
			break;
388
		    c = RTTI_func ;
-
 
389
		}
457
		}
390
		break ;
-
 
391
	    }
-
 
392
	    case type_array_tag : {
-
 
393
		/* Array types */
-
 
394
		TYPE s = DEREF_type ( type_array_sub ( t ) ) ;
-
 
395
		CONS_type ( s, p, p ) ;
-
 
396
		sz = DEREF_nat ( type_array_size ( t ) ) ;
-
 
397
		c = RTTI_array ;
-
 
398
		break ;
-
 
399
	    }
-
 
400
	    case type_bitfield_tag : {
-
 
401
		/* Bitfield types */
-
 
402
		INT_TYPE it = DEREF_itype ( type_bitfield_defn ( t ) ) ;
-
 
403
		TYPE s = DEREF_type ( itype_bitfield_sub ( it ) ) ;
-
 
404
		CONS_type ( s, p, p ) ;
-
 
405
		sz = DEREF_nat ( itype_bitfield_size ( it ) ) ;
-
 
406
		c = RTTI_bitfield ;
-
 
407
		break ;
-
 
408
	    }
-
 
409
	    case type_compound_tag : {
-
 
410
		/* Class types */
-
 
411
		CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
-
 
412
		CLASS_INFO ci = DEREF_cinfo ( ctype_info ( ct ) ) ;
-
 
413
		GRAPH gr = DEREF_graph ( ctype_base ( ct ) ) ;
-
 
414
		br = DEREF_list ( graph_tails ( gr ) ) ;
-
 
415
		if ( ci & cinfo_union ) {
-
 
416
		    c = RTTI_union ;
-
 
417
		} else {
-
 
418
		    c = RTTI_class ;
-
 
419
		}
458
		}
-
 
459
		bs = enc_tagdef_start(NULL_id, n, NULL_type, 1);
-
 
460
		bs = enc_special(bs, TOK_typeid_make);
-
 
461
		ts = start_bitstream(NIL(FILE), bs->link);
420
		break ;
462
		ts = enc_make_snat(ts, c);
421
	    }
463
		ts = enc_buffer(ts, bf);
422
	    case type_enumerate_tag : {
464
		ts = enc_rtti_bases(ts, br, p, sz);
423
		/* Enumeration types */
465
		DESTROY_list(p, SIZE_type);
424
		c = RTTI_enum ;
466
		bs = enc_bitstream(bs, ts);
425
		break ;
467
		enc_tagdef_end(bs);
426
	    }
-
 
427
	}
468
	}
428
	bs = enc_tagdef_start ( NULL_id, n, NULL_type, 1 ) ;
-
 
429
	bs = enc_special ( bs, TOK_typeid_make ) ;
-
 
430
	ts = start_bitstream ( NIL ( FILE ), bs->link ) ;
-
 
431
	ts = enc_make_snat ( ts, c ) ;
-
 
432
	ts = enc_buffer ( ts, bf ) ;
-
 
433
	ts = enc_rtti_bases ( ts, br, p, sz ) ;
-
 
434
	DESTROY_list ( p, SIZE_type ) ;
-
 
435
	bs = enc_bitstream ( bs, ts ) ;
-
 
436
	enc_tagdef_end ( bs ) ;
-
 
437
    }
-
 
438
    return ;
469
	return;
439
}
470
}
440
 
471
 
441
 
472
 
442
/*
473
/*
443
    LIST OF RUN-TIME TYPE INFORMATION STRUCTURES
474
    LIST OF RUN-TIME TYPE INFORMATION STRUCTURES
444
 
475
 
445
    These lists gives the tag numbers for the various type information
476
    These lists gives the tag numbers for the various type information
446
    structures output.  Polymorphic classes, which form the most common
477
    structures output.  Polymorphic classes, which form the most common
447
    such types, are dealt with separately as part of the virtual function
478
    such types, are dealt with separately as part of the virtual function
448
    table.
479
    table.
449
*/
480
*/
450
 
481
 
451
static LIST ( TYPE ) rtti_types = NULL_list ( TYPE ) ;
482
static LIST(TYPE)rtti_types = NULL_list(TYPE);
452
static LIST ( ulong ) rtti_tags = NULL_list ( ulong ) ;
483
static LIST(ulong)rtti_tags = NULL_list(ulong);
453
 
484
 
454
 
485
 
455
/*
486
/*
456
    ENCODE THE RUN-TIME TYPE INFORMATION FOR A TYPE
487
    ENCODE THE RUN-TIME TYPE INFORMATION FOR A TYPE
457
 
488
 
458
    This routine adds a reference to the run-time type information
489
    This routine adds a reference to the run-time type information
459
    structure for the type t to the bitstream bs, defining this if
490
    structure for the type t to the bitstream bs, defining this if
460
    necessary.
491
    necessary.
461
*/
492
*/
462
 
493
 
463
BITSTREAM *enc_rtti_type
494
BITSTREAM *
464
    PROTO_N ( ( bs, t, op ) )
-
 
465
    PROTO_T ( BITSTREAM *bs X TYPE t X int op )
495
enc_rtti_type(BITSTREAM *bs, TYPE t, int op)
466
{
496
{
467
    ulong n = LINK_NONE ;
497
	ulong n = LINK_NONE;
468
    if ( IS_NULL_type ( t ) ) {
498
	if (IS_NULL_type(t)) {
469
	/* Map null type to null pointer */
499
		/* Map null type to null pointer */
470
	ENC_make_null_ptr ( bs ) ;
500
		ENC_make_null_ptr(bs);
471
	ENC_alignment ( bs ) ;
501
		ENC_alignment(bs);
472
	bs = enc_special ( bs, TOK_typeid_type ) ;
502
		bs = enc_special(bs, TOK_typeid_type);
473
	return ( bs ) ;
503
		return (bs);
474
    }
504
	}
475
    if ( op == lex_typeid && !output_rtti ) {
505
	if (op == lex_typeid && !output_rtti) {
476
	/* Use dummy type if RTTI suppressed */
506
		/* Use dummy type if RTTI suppressed */
477
	t = type_error ;
507
		t = type_error;
478
    }
508
	}
479
    switch ( TAG_type ( t ) ) {
509
	switch (TAG_type(t)) {
480
	case type_top_tag :
510
	case type_top_tag:
481
	case type_bottom_tag :
511
	case type_bottom_tag:
482
	case type_integer_tag :
512
	case type_integer_tag:
483
	case type_floating_tag :
513
	case type_floating_tag:
484
	case type_pre_tag :
514
	case type_pre_tag:
485
	case type_error_tag : {
515
	case type_error_tag: {
486
	    /* Built-in types */
516
		/* Built-in types */
487
	    BITSTREAM *ts ;
517
		BITSTREAM *ts;
488
	    bs = enc_special ( bs, TOK_typeid_basic ) ;
518
		bs = enc_special(bs, TOK_typeid_basic);
489
	    ts = start_bitstream ( NIL ( FILE ), bs->link ) ;
519
		ts = start_bitstream(NIL(FILE), bs->link);
490
	    ts = enc_arith ( ts, t, 1 ) ;
520
		ts = enc_arith(ts, t, 1);
491
	    bs = enc_bitstream ( bs, ts ) ;
521
		bs = enc_bitstream(bs, ts);
492
	    return ( bs ) ;
522
		return (bs);
493
	}
523
	}
494
	case type_compound_tag : {
524
	case type_compound_tag: {
495
	    /* Class types */
525
		/* Class types */
496
	    CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
526
		CLASS_TYPE ct = DEREF_ctype(type_compound_defn(t));
497
	    CLASS_INFO ci = DEREF_cinfo ( ctype_info ( ct ) ) ;
527
		CLASS_INFO ci = DEREF_cinfo(ctype_info(ct));
498
	    if ( ci & cinfo_polymorphic ) {
528
		if (ci & cinfo_polymorphic) {
499
		/* Polymorphic class types */
529
			/* Polymorphic class types */
500
		int used ;
530
			int used;
501
		VIRTUAL vt = DEREF_virt ( ctype_virt ( ct ) ) ;
531
			VIRTUAL vt = DEREF_virt(ctype_virt(ct));
502
		n = DEREF_ulong ( virt_table_rtti ( vt ) ) ;
532
			n = DEREF_ulong(virt_table_rtti(vt));
503
		if ( n == LINK_NONE ) {
533
			if (n == LINK_NONE) {
504
		    IGNORE compile_class ( ct ) ;
534
				IGNORE compile_class(ct);
505
		    n = DEREF_ulong ( virt_table_rtti ( vt ) ) ;
535
				n = DEREF_ulong(virt_table_rtti(vt));
506
		}
536
			}
507
		used = DEREF_int ( virt_table_rtti_used ( vt ) ) ;
537
			used = DEREF_int(virt_table_rtti_used(vt));
508
		if ( !used ) {
538
			if (!used) {
509
		    IDENTIFIER cid = DEREF_id ( ctype_name ( ct ) ) ;
539
				IDENTIFIER cid = DEREF_id(ctype_name(ct));
510
		    COPY_int ( virt_table_rtti_used ( vt ), 1 ) ;
540
				COPY_int(virt_table_rtti_used(vt), 1);
511
		    compile_virtual ( ct, !has_linkage ( cid ) ) ;
541
				compile_virtual(ct, !has_linkage(cid));
-
 
542
			}
-
 
543
			if (op == lex_vtable) {
-
 
544
				/* Deal with virtual function tables */
-
 
545
				/* NOT YET IMPLEMENTED */
-
 
546
				n = DEREF_ulong(virt_table_tbl(vt));
-
 
547
				n = link_no(bs, n, VAR_tag);
-
 
548
				ENC_obtain_tag(bs);
-
 
549
				ENC_make_tag(bs, n);
-
 
550
				return (bs);
-
 
551
			}
-
 
552
		} else {
-
 
553
			IGNORE compile_class(ct);
-
 
554
		}
-
 
555
		break;
-
 
556
	}
-
 
557
	}
-
 
558
	if (n == LINK_NONE) {
-
 
559
		/* Check for previous definition */
-
 
560
		LIST(TYPE)p = rtti_types;
-
 
561
		LIST(ulong)q = rtti_tags;
-
 
562
		while (!IS_NULL_list(p)) {
-
 
563
			TYPE s = DEREF_type(HEAD_list(p));
-
 
564
			if (eq_type(s, t)) {
-
 
565
				n = DEREF_ulong(HEAD_list(q));
-
 
566
				break;
-
 
567
			}
-
 
568
			q = TAIL_list(q);
-
 
569
			p = TAIL_list(p);
-
 
570
		}
-
 
571
		if (n == LINK_NONE) {
-
 
572
			/* Define a new structure */
-
 
573
			string s = NULL;
-
 
574
			if (output_all) {
-
 
575
				s = mangle_tname("__ti__", t);
-
 
576
			}
-
 
577
			n = capsule_no(s, VAR_tag);
-
 
578
			CONS_type(t, rtti_types, rtti_types);
-
 
579
			CONS_ulong(n, rtti_tags, rtti_tags);
-
 
580
			enc_rtti_struct(t, n, 1);
512
		}
581
		}
513
		if ( op == lex_vtable ) {
-
 
514
		    /* Deal with virtual function tables */
-
 
515
		    /* NOT YET IMPLEMENTED */
-
 
516
		    n = DEREF_ulong ( virt_table_tbl ( vt ) ) ;
-
 
517
		    n = link_no ( bs, n, VAR_tag ) ;
-
 
518
		    ENC_obtain_tag ( bs ) ;
-
 
519
		    ENC_make_tag ( bs, n ) ;
-
 
520
		    return ( bs ) ;
-
 
521
		}
-
 
522
	    } else {
-
 
523
		IGNORE compile_class ( ct ) ;
-
 
524
	    }
-
 
525
	    break ;
-
 
526
	}
-
 
527
    }
-
 
528
    if ( n == LINK_NONE ) {
-
 
529
	/* Check for previous definition */
-
 
530
	LIST ( TYPE ) p = rtti_types ;
-
 
531
	LIST ( ulong ) q = rtti_tags ;
-
 
532
	while ( !IS_NULL_list ( p ) ) {
-
 
533
	    TYPE s = DEREF_type ( HEAD_list ( p ) ) ;
-
 
534
	    if ( eq_type ( s, t ) ) {
-
 
535
		n = DEREF_ulong ( HEAD_list ( q ) ) ;
-
 
536
		break ;
-
 
537
	    }
-
 
538
	    q = TAIL_list ( q ) ;
-
 
539
	    p = TAIL_list ( p ) ;
-
 
540
	}
-
 
541
	if ( n == LINK_NONE ) {
-
 
542
	    /* Define a new structure */
-
 
543
	    string s = NULL ;
-
 
544
	    if ( output_all ) s = mangle_tname ( "__ti__", t ) ;
-
 
545
	    n = capsule_no ( s, VAR_tag ) ;
-
 
546
	    CONS_type ( t, rtti_types, rtti_types ) ;
-
 
547
	    CONS_ulong ( n, rtti_tags, rtti_tags ) ;
-
 
548
	    enc_rtti_struct ( t, n, 1 ) ;
-
 
549
	}
582
	}
550
    }
-
 
551
    n = link_no ( bs, n, VAR_tag ) ;
583
	n = link_no(bs, n, VAR_tag);
552
    ENC_obtain_tag ( bs ) ;
584
	ENC_obtain_tag(bs);
553
    ENC_make_tag ( bs, n ) ;
585
	ENC_make_tag(bs, n);
554
    return ( bs ) ;
586
	return (bs);
555
}
587
}
556
 
588
 
557
 
589
 
558
/*
590
/*
559
    ENCODE THE RUN-TIME TYPE INFORMATION FOR AN EXPRESSION
591
    ENCODE THE RUN-TIME TYPE INFORMATION FOR AN EXPRESSION
560
 
592
 
561
    This routine adds the run-time type information expression e to
593
    This routine adds the run-time type information expression e to
562
    the bitstream bs.
594
    the bitstream bs.
563
*/
595
*/
564
 
596
 
565
BITSTREAM *enc_rtti_exp
597
BITSTREAM *
566
    PROTO_N ( ( bs, e ) )
-
 
567
    PROTO_T ( BITSTREAM *bs X EXP e )
598
enc_rtti_exp(BITSTREAM *bs, EXP e)
568
{
599
{
569
    EXP a = DEREF_exp ( exp_rtti_arg ( e ) ) ;
600
	EXP a = DEREF_exp(exp_rtti_arg(e));
570
    EXP b = DEREF_exp ( exp_rtti_except ( e ) ) ;
601
	EXP b = DEREF_exp(exp_rtti_except(e));
571
    int op = DEREF_int ( exp_rtti_op ( e ) ) ;
602
	int op = DEREF_int(exp_rtti_op(e));
572
    TYPE t = DEREF_type ( exp_type ( a ) ) ;
603
	TYPE t = DEREF_type(exp_type(a));
573
    if ( IS_type_ptr_etc ( t ) ) {
604
	if (IS_type_ptr_etc(t)) {
574
	TYPE s = DEREF_type ( type_ptr_etc_sub ( t ) ) ;
605
		TYPE s = DEREF_type(type_ptr_etc_sub(t));
575
	if ( IS_type_compound ( s ) ) {
606
		if (IS_type_compound(s)) {
576
	    CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( s ) ) ;
607
			CLASS_TYPE ct = DEREF_ctype(type_compound_defn(s));
577
	    VIRTUAL vt = DEREF_virt ( ctype_virt ( ct ) ) ;
608
			VIRTUAL vt = DEREF_virt(ctype_virt(ct));
578
	    if ( !IS_NULL_virt ( vt ) ) {
609
			if (!IS_NULL_virt(vt)) {
579
		/* Pointer to polymorphic class */
610
				/* Pointer to polymorphic class */
580
		EXP a1 ;
611
				EXP a1;
581
		int used ;
612
				int used;
582
		OFFSET off ;
613
				OFFSET off;
583
		ulong n, m ;
614
				ulong n, m;
584
		BITSTREAM *ts ;
615
				BITSTREAM *ts;
585
		IGNORE compile_class ( ct ) ;
616
				IGNORE compile_class(ct);
586
		off = DEREF_off ( virt_table_off ( vt ) ) ;
617
				off = DEREF_off(virt_table_off(vt));
587
		n = DEREF_ulong ( virt_table_tok ( vt ) ) ;
618
				n = DEREF_ulong(virt_table_tok(vt));
588
 
619
 
589
		/* Introduce variable for pointer */
620
				/* Introduce variable for pointer */
590
		a1 = DEREF_exp ( exp_dummy_value ( a ) ) ;
621
				a1 = DEREF_exp(exp_dummy_value(a));
591
		m = unit_no ( bs, NULL_id, VAR_tag, 1 ) ;
622
				m = unit_no(bs, NULL_id, VAR_tag, 1);
592
		ENC_variable ( bs ) ;
623
				ENC_variable(bs);
593
		bs = enc_access ( bs, crt_func_access ) ;
624
				bs = enc_access(bs, crt_func_access);
594
		ENC_make_tag ( bs, m ) ;
625
				ENC_make_tag(bs, m);
595
		bs = enc_exp ( bs, a ) ;
626
				bs = enc_exp(bs, a);
596
		COPY_ulong ( exp_dummy_no ( a ), m ) ;
627
				COPY_ulong(exp_dummy_no(a), m);
597
		COPY_exp ( exp_dummy_value ( a ), NULL_exp ) ;
628
				COPY_exp(exp_dummy_value(a), NULL_exp);
598
 
629
 
599
		/* Check for null pointers */
630
				/* Check for null pointers */
600
		if ( !IS_NULL_exp ( b ) ) {
631
				if (!IS_NULL_exp(b)) {
601
		    ulong lab = unit_no ( bs, NULL_id, VAR_label, 1 ) ;
632
					ulong lab = unit_no(bs, NULL_id,
-
 
633
							    VAR_label, 1);
602
		    ENC_SEQ_SMALL ( bs, 1 ) ;
634
					ENC_SEQ_SMALL(bs, 1);
603
		    ENC_conditional ( bs ) ;
635
					ENC_conditional(bs);
604
		    ENC_make_label ( bs, lab ) ;
636
					ENC_make_label(bs, lab);
605
		    ENC_SEQ_SMALL ( bs, 1 ) ;
637
					ENC_SEQ_SMALL(bs, 1);
606
		    ENC_pointer_test ( bs ) ;
638
					ENC_pointer_test(bs);
607
		    ENC_OFF ( bs ) ;
639
					ENC_OFF(bs);
608
		    ENC_equal ( bs ) ;
640
					ENC_equal(bs);
609
		    ENC_make_label ( bs, lab ) ;
641
					ENC_make_label(bs, lab);
610
		    bs = enc_exp ( bs, a ) ;
642
					bs = enc_exp(bs, a);
611
		    bs = enc_null_exp ( bs, t ) ;
643
					bs = enc_null_exp(bs, t);
612
		    bs = enc_exp ( bs, b ) ;
644
					bs = enc_exp(bs, b);
613
		    ENC_make_top ( bs ) ;
645
					ENC_make_top(bs);
614
		}
646
				}
615
 
647
 
616
		/* Find the run-time type information */
648
				/* Find the run-time type information */
617
		ts = start_bitstream ( NIL ( FILE ), bs->link ) ;
649
				ts = start_bitstream(NIL(FILE), bs->link);
618
		if ( op == lex_typeid ) {
650
				if (op == lex_typeid) {
619
		    bs = enc_special ( bs, TOK_typeid_ref ) ;
651
					bs = enc_special(bs, TOK_typeid_ref);
620
		} else {
652
				} else {
621
		    bs = enc_special ( bs, TOK_vtab_func ) ;
653
					bs = enc_special(bs, TOK_vtab_func);
622
		}
654
				}
623
		ENC_add_to_ptr ( ts ) ;
655
				ENC_add_to_ptr(ts);
624
		ts = enc_add_ptr ( ts, a, LINK_NONE, off, 0 ) ;
656
				ts = enc_add_ptr(ts, a, LINK_NONE, off, 0);
625
		ts = enc_exp_token ( ts, n ) ;
657
				ts = enc_exp_token(ts, n);
626
		if ( op != lex_typeid ) {
658
				if (op != lex_typeid) {
627
		    ENC_make_signed_nat ( ts ) ;
659
					ENC_make_signed_nat(ts);
628
		    ENC_OFF ( ts ) ;
660
					ENC_OFF(ts);
629
		    ENC_INT_SMALL ( ts, 0 ) ;
661
					ENC_INT_SMALL(ts, 0);
630
		}
662
				}
631
		bs = enc_bitstream ( bs, ts ) ;
663
				bs = enc_bitstream(bs, ts);
632
		used = DEREF_int ( virt_table_rtti_used ( vt ) ) ;
664
				used = DEREF_int(virt_table_rtti_used(vt));
633
		if ( !used ) {
665
				if (!used) {
634
		    IDENTIFIER cid = DEREF_id ( ctype_name ( ct ) ) ;
666
					IDENTIFIER cid = DEREF_id(ctype_name(ct));
635
		    COPY_int ( virt_table_rtti_used ( vt ), 1 ) ;
667
					COPY_int(virt_table_rtti_used(vt), 1);
636
		    compile_virtual ( ct, !has_linkage ( cid ) ) ;
668
					compile_virtual(ct, !has_linkage(cid));
-
 
669
				}
-
 
670
				COPY_exp(exp_dummy_value(a), a1);
-
 
671
				return (bs);
-
 
672
			}
637
		}
673
		}
638
		COPY_exp ( exp_dummy_value ( a ), a1 ) ;
-
 
639
		return ( bs ) ;
-
 
640
	    }
-
 
641
	}
674
	}
642
    }
-
 
643
    bs = enc_rtti_type ( bs, t, op ) ;
675
	bs = enc_rtti_type(bs, t, op);
644
    return ( bs ) ;
676
	return (bs);
645
}
677
}
646
 
678
 
647
 
679
 
648
/*
680
/*
649
    ENCODE A DYNAMIC CAST EXPRESSION
681
    ENCODE A DYNAMIC CAST EXPRESSION
650
 
682
 
651
    This routine adds the dynamic cast expression e to the bitstream bs.
683
    This routine adds the dynamic cast expression e to the bitstream bs.
652
*/
684
*/
653
 
685
 
654
BITSTREAM *enc_dyn_cast
686
BITSTREAM *
655
    PROTO_N ( ( bs, e ) )
-
 
656
    PROTO_T ( BITSTREAM *bs X EXP e )
687
enc_dyn_cast(BITSTREAM *bs, EXP e)
657
{
688
{
658
    ulong m ;
689
	ulong m;
659
    int used ;
690
	int used;
660
    OFFSET off ;
691
	OFFSET off;
661
    VIRTUAL vt ;
692
	VIRTUAL vt;
662
    CLASS_TYPE ct ;
693
	CLASS_TYPE ct;
663
    BITSTREAM *ts, *us ;
694
	BITSTREAM *ts, *us;
664
    ulong r = LINK_NONE ;
695
	ulong r = LINK_NONE;
665
    TYPE t = DEREF_type ( exp_type ( e ) ) ;
696
	TYPE t = DEREF_type(exp_type(e));
666
    EXP a = DEREF_exp ( exp_dyn_cast_arg ( e ) ) ;
697
	EXP a = DEREF_exp(exp_dyn_cast_arg(e));
667
    TYPE s = DEREF_type ( exp_type ( a ) ) ;
698
	TYPE s = DEREF_type(exp_type(a));
668
    EXP a1 = DEREF_exp ( exp_dummy_value ( a ) ) ;
699
	EXP a1 = DEREF_exp(exp_dummy_value(a));
669
    EXP b = DEREF_exp ( exp_dyn_cast_except ( e ) ) ;
700
	EXP b = DEREF_exp(exp_dyn_cast_except(e));
670
 
701
 
671
    /* Introduce identity for argument */
702
	/* Introduce identity for argument */
672
    ulong n = unit_no ( bs, NULL_id, VAR_tag, 1 ) ;
703
	ulong n = unit_no(bs, NULL_id, VAR_tag, 1);
673
    ENC_identify ( bs ) ;
704
	ENC_identify(bs);
674
    bs = enc_access ( bs, dspec_none ) ;
705
	bs = enc_access(bs, dspec_none);
675
    ENC_make_tag ( bs, n ) ;
706
	ENC_make_tag(bs, n);
676
    bs = enc_exp ( bs, a1 ) ;
707
	bs = enc_exp(bs, a1);
677
    COPY_exp ( exp_dummy_value ( a ), NULL_exp ) ;
708
	COPY_exp(exp_dummy_value(a), NULL_exp);
678
    COPY_ulong ( exp_dummy_no ( a ), n ) ;
709
	COPY_ulong(exp_dummy_no(a), n);
679
 
710
 
680
    /* Convert to result type */
711
	/* Convert to result type */
681
    bs = enc_special ( bs, TOK_from_ptr_void ) ;
712
	bs = enc_special(bs, TOK_from_ptr_void);
682
    ts = start_bitstream ( NIL ( FILE ), bs->link ) ;
713
	ts = start_bitstream(NIL(FILE), bs->link);
683
    t = DEREF_type ( type_ptr_etc_sub ( t ) ) ;
714
	t = DEREF_type(type_ptr_etc_sub(t));
684
    ts = enc_alignment ( ts, t ) ;
715
	ts = enc_alignment(ts, t);
685
 
716
 
686
    /* Introduce variable in exception case */
717
	/* Introduce variable in exception case */
687
    if ( !IS_NULL_exp ( b ) ) {
718
	if (!IS_NULL_exp(b)) {
688
	r = unit_no ( ts, NULL_id, VAR_tag, 1 ) ;
719
		r = unit_no(ts, NULL_id, VAR_tag, 1);
689
	ENC_variable ( ts ) ;
720
		ENC_variable(ts);
690
	ts = enc_access ( ts, crt_func_access ) ;
721
		ts = enc_access(ts, crt_func_access);
691
	ENC_make_tag ( ts, r ) ;
722
		ENC_make_tag(ts, r);
692
    }
723
	}
693
 
724
 
694
    /* Encode main token */
725
	/* Encode main token */
695
    ts = enc_special ( ts, TOK_dynam_cast ) ;
726
	ts = enc_special(ts, TOK_dynam_cast);
696
    us = start_bitstream ( NIL ( FILE ), ts->link ) ;
727
	us = start_bitstream(NIL(FILE), ts->link);
697
 
728
 
698
    /* Encode address of virtual function table */
729
	/* Encode address of virtual function table */
699
    s = DEREF_type ( type_ptr_etc_sub ( s ) ) ;
730
	s = DEREF_type(type_ptr_etc_sub(s));
700
    ct = DEREF_ctype ( type_compound_defn ( s ) ) ;
731
	ct = DEREF_ctype(type_compound_defn(s));
701
    IGNORE compile_class ( ct ) ;
732
	IGNORE compile_class(ct);
702
    vt = DEREF_virt ( ctype_virt ( ct ) ) ;
733
	vt = DEREF_virt(ctype_virt(ct));
703
    off = DEREF_off ( virt_table_off ( vt ) ) ;
734
	off = DEREF_off(virt_table_off(vt));
704
    m = DEREF_ulong ( virt_table_tok ( vt ) ) ;
735
	m = DEREF_ulong(virt_table_tok(vt));
705
    ENC_add_to_ptr ( us ) ;
736
	ENC_add_to_ptr(us);
706
    us = enc_add_ptr ( us, a, LINK_NONE, off, 0 ) ;
737
	us = enc_add_ptr(us, a, LINK_NONE, off, 0);
707
    us = enc_exp_token ( us, m ) ;
738
	us = enc_exp_token(us, m);
708
    used = DEREF_int ( virt_table_rtti_used ( vt ) ) ;
739
	used = DEREF_int(virt_table_rtti_used(vt));
709
    if ( !used ) {
740
	if (!used) {
710
	IDENTIFIER cid = DEREF_id ( ctype_name ( ct ) ) ;
741
		IDENTIFIER cid = DEREF_id(ctype_name(ct));
711
	COPY_int ( virt_table_rtti_used ( vt ), 1 ) ;
742
		COPY_int(virt_table_rtti_used(vt), 1);
712
	compile_virtual ( ct, !has_linkage ( cid ) ) ;
743
		compile_virtual(ct, !has_linkage(cid));
713
    }
744
	}
714
 
745
 
715
    /* Output run-time type information */
746
	/* Output run-time type information */
716
    us = enc_rtti_type ( us, t, lex_typeid ) ;
747
	us = enc_rtti_type(us, t, lex_typeid);
717
    ts = enc_bitstream ( ts, us ) ;
748
	ts = enc_bitstream(ts, us);
718
 
749
 
719
    /* Check for exceptions */
750
	/* Check for exceptions */
720
    if ( !IS_NULL_exp ( b ) ) {
751
	if (!IS_NULL_exp(b)) {
721
	ulong lab = unit_no ( ts, NULL_id, VAR_label, 1 ) ;
752
		ulong lab = unit_no(ts, NULL_id, VAR_label, 1);
722
	ENC_SEQ_SMALL ( ts, 1 ) ;
753
		ENC_SEQ_SMALL(ts, 1);
723
	ENC_conditional ( ts ) ;
754
		ENC_conditional(ts);
724
	ENC_make_label ( ts, lab ) ;
755
		ENC_make_label(ts, lab);
725
	ENC_SEQ_SMALL ( ts, 1 ) ;
756
		ENC_SEQ_SMALL(ts, 1);
726
	ts = enc_special ( ts, TOK_pv_test ) ;
757
		ts = enc_special(ts, TOK_pv_test);
727
	us = start_bitstream ( NIL ( FILE ), ts->link ) ;
758
		us = start_bitstream(NIL(FILE), ts->link);
728
	ENC_contents ( us ) ;
759
		ENC_contents(us);
729
	us = enc_special ( us, TOK_ptr_void ) ;
760
		us = enc_special(us, TOK_ptr_void);
730
	ENC_obtain_tag ( us ) ;
761
		ENC_obtain_tag(us);
731
	ENC_make_tag ( us, r ) ;
762
		ENC_make_tag(us, r);
732
	ENC_make_label ( us, lab ) ;
763
		ENC_make_label(us, lab);
733
	ENC_equal ( us ) ;
764
		ENC_equal(us);
734
	ts = enc_bitstream ( ts, us ) ;
765
		ts = enc_bitstream(ts, us);
735
	ts = enc_exp ( ts, b ) ;
766
		ts = enc_exp(ts, b);
736
	ENC_make_top ( ts ) ;
767
		ENC_make_top(ts);
737
	ENC_contents ( ts ) ;
768
		ENC_contents(ts);
738
	ts = enc_special ( ts, TOK_ptr_void ) ;
769
		ts = enc_special(ts, TOK_ptr_void);
739
	ENC_obtain_tag ( ts ) ;
770
		ENC_obtain_tag(ts);
740
	ENC_make_tag ( ts, r ) ;
771
		ENC_make_tag(ts, r);
741
    }
772
	}
742
 
773
 
743
    /* End conversion expression */
774
	/* End conversion expression */
744
    bs = enc_bitstream ( bs, ts ) ;
775
	bs = enc_bitstream(bs, ts);
745
    COPY_exp ( exp_dummy_value ( a ), a1 ) ;
776
	COPY_exp(exp_dummy_value(a), a1);
746
    return ( bs ) ;
777
	return (bs);
747
}
778
}
748
 
779
 
749
 
780
 
750
/*
781
/*
751
    LIST OF PREVIOUSLY DEFINED THUNKS
782
    LIST OF PREVIOUSLY DEFINED THUNKS
752
 
783
 
753
    A list of all previously defined thunks is maintained to avoid
784
    A list of all previously defined thunks is maintained to avoid
754
    unnecessary duplication.
785
    unnecessary duplication.
755
*/
786
*/
756
 
787
 
757
static VIRTUAL all_thunks = NULL_virt ;
788
static VIRTUAL all_thunks = NULL_virt;
758
 
789
 
759
 
790
 
760
/*
791
/*
761
    CREATE A THUNK FUNCTION
792
    CREATE A THUNK FUNCTION
762
 
793
 
763
    This routine creates a dummy function of type f which calls fid with
794
    This routine creates a dummy function of type f which calls fid with
764
    its given arguments and returns its result with the base class conversion
795
    its given arguments and returns its result with the base class conversion
765
    given by ret applied.  The tag number of the dummy function is returned.
796
    given by ret applied.  The tag number of the dummy function is returned.
766
    This is used for overriding virtual functions in which the return
797
    This is used for overriding virtual functions in which the return
767
    type differs.
798
    type differs.
896
 
926
 
897
 
927
 
898
/*
928
/*
899
    ENCODE THE SHAPE OF A VIRTUAL FUNCTION TABLE
929
    ENCODE THE SHAPE OF A VIRTUAL FUNCTION TABLE
900
 
930
 
901
    This routine adds the shape of a virtual function table containing
931
    This routine adds the shape of a virtual function table containing
902
    n functions to the bitstream bs.
932
    n functions to the bitstream bs.
903
*/
933
*/
904
 
934
 
905
BITSTREAM *enc_vtable_shape
935
BITSTREAM *
906
    PROTO_N ( ( bs, n ) )
-
 
907
    PROTO_T ( BITSTREAM *bs X ulong n )
936
enc_vtable_shape(BITSTREAM *bs, ulong n)
908
{
937
{
909
    BITSTREAM *ts ;
938
	BITSTREAM *ts;
910
    bs = enc_special ( bs, TOK_vtab_type ) ;
939
	bs = enc_special(bs, TOK_vtab_type);
911
    ts = start_bitstream ( NIL ( FILE ), bs->link ) ;
940
	ts = start_bitstream(NIL(FILE), bs->link);
912
    ENC_make_nat ( ts ) ;
941
	ENC_make_nat(ts);
913
    ENC_INT ( ts, n + VIRTUAL_EXTRA ) ;
942
	ENC_INT(ts, n + VIRTUAL_EXTRA);
914
    bs = enc_bitstream ( bs, ts ) ;
943
	bs = enc_bitstream(bs, ts);
915
    return ( bs ) ;
944
	return (bs);
916
}
945
}
917
 
946
 
918
 
947
 
919
/*
948
/*
920
    ENCODE THE DEFINITION OF A VIRTUAL FUNCTION TABLE
949
    ENCODE THE DEFINITION OF A VIRTUAL FUNCTION TABLE
921
 
950
 
922
    This routine encodes the definition of the virtual function table vt.
951
    This routine encodes the definition of the virtual function table vt.
923
    n gives the tag number for the table, gr is the table offset and the
952
    n gives the tag number for the table, gr is the table offset and the
924
    flag inherited is true for secondary tables.  rtti gives the tag
953
    flag inherited is true for secondary tables.  rtti gives the tag
925
    number for the run-time type information.
954
    number for the run-time type information.
926
*/
955
*/
927
 
956
 
928
static void enc_vtable_defn
957
static void
929
    PROTO_N ( ( vt, n, ct, gr, inherited, rtti ) )
-
 
930
    PROTO_T ( VIRTUAL vt X ulong n X CLASS_TYPE ct X GRAPH gr X
958
enc_vtable_defn(VIRTUAL vt, ulong n, CLASS_TYPE ct, GRAPH gr, int inherited,
931
	      int inherited X ulong rtti )
959
		ulong rtti)
932
{
960
{
933
    ulong r ;
961
	ulong r;
934
    BITSTREAM *bs, *ts, *us ;
962
	BITSTREAM *bs, *ts, *us;
935
    ulong m = DEREF_ulong ( virt_no ( vt ) ) ;
963
	ulong m = DEREF_ulong(virt_no(vt));
936
    ulong p = DEREF_ulong ( virt_table_tok ( vt ) ) ;
964
	ulong p = DEREF_ulong(virt_table_tok(vt));
937
    OFFSET off = DEREF_off ( virt_table_off ( vt ) ) ;
965
	OFFSET off = DEREF_off(virt_table_off(vt));
938
    LIST ( VIRTUAL ) pt = DEREF_list ( virt_table_entries ( vt ) ) ;
966
	LIST(VIRTUAL)pt = DEREF_list(virt_table_entries(vt));
939
 
967
 
940
    /* Output start of table */
968
	/* Output start of table */
941
    bs = enc_tagdef_start ( NULL_id, n, NULL_type, 1 ) ;
969
	bs = enc_tagdef_start(NULL_id, n, NULL_type, 1);
942
    bs = enc_special ( bs, TOK_vtab_make ) ;
970
	bs = enc_special(bs, TOK_vtab_make);
943
    ts = start_bitstream ( NIL ( FILE ), bs->link ) ;
971
	ts = start_bitstream(NIL(FILE), bs->link);
944
    ENC_obtain_tag ( ts ) ;
972
	ENC_obtain_tag(ts);
945
    r = link_no ( ts, rtti, VAR_tag ) ;
973
	r = link_no(ts, rtti, VAR_tag);
946
    ENC_make_tag ( ts, r ) ;
974
	ENC_make_tag(ts, r);
947
    if ( inherited ) {
975
	if (inherited) {
948
	/* Add base class offset */
976
		/* Add base class offset */
949
	OFFSET off2 = DEREF_off ( graph_off ( gr ) ) ;
977
		OFFSET off2 = DEREF_off(graph_off(gr));
950
	if ( !is_zero_offset ( off2 ) ) {
978
		if (!is_zero_offset(off2)) {
951
	    ENC_offset_add ( ts ) ;
979
			ENC_offset_add(ts);
952
	    ts = enc_offset ( ts, off2 ) ;
980
			ts = enc_offset(ts, off2);
953
	}
981
		}
954
    }
982
	}
955
    if ( !is_zero_offset ( off ) ) {
983
	if (!is_zero_offset(off)) {
956
	/* Add inherited table offset */
984
		/* Add inherited table offset */
957
	ENC_offset_add ( ts ) ;
985
		ENC_offset_add(ts);
958
	ts = enc_offset ( ts, off ) ;
986
		ts = enc_offset(ts, off);
959
    }
987
	}
960
    ts = enc_exp_token ( ts, p ) ;
988
	ts = enc_exp_token(ts, p);
961
    ENC_make_nat ( ts ) ;
989
	ENC_make_nat(ts);
962
    ENC_INT ( ts, m + VIRTUAL_EXTRA ) ;
990
	ENC_INT(ts, m + VIRTUAL_EXTRA);
963
 
991
 
964
    /* Output virtual functions */
992
	/* Output virtual functions */
965
    ENC_make_nof ( ts ) ;
993
	ENC_make_nof(ts);
966
    ENC_LIST ( ts, m ) ;
994
	ENC_LIST(ts, m);
967
    while ( !IS_NULL_list ( pt ) ) {
995
	while (!IS_NULL_list(pt)) {
968
	GRAPH gs ;
996
		GRAPH gs;
969
	DECL_SPEC ds ;
997
		DECL_SPEC ds;
970
	IDENTIFIER fid ;
998
		IDENTIFIER fid;
971
	GRAPH ret = NULL_graph ;
999
		GRAPH ret = NULL_graph;
972
	IDENTIFIER pid = NULL_id ;
1000
		IDENTIFIER pid = NULL_id;
973
	VIRTUAL at = DEREF_virt ( HEAD_list ( pt ) ) ;
1001
		VIRTUAL at = DEREF_virt(HEAD_list(pt));
974
	while ( IS_virt_link ( at ) ) {
1002
		while (IS_virt_link(at)) {
975
	    /* Allow for symbolic links */
1003
			/* Allow for symbolic links */
976
	    at = DEREF_virt ( DEREF_ptr ( virt_link_to ( at ) ) ) ;
1004
			at = DEREF_virt(DEREF_ptr(virt_link_to(at)));
977
	}
1005
		}
978
	if ( inherited ) {
1006
		if (inherited) {
979
	    /* Allow for inherited function tables */
1007
			/* Allow for inherited function tables */
980
	    VIRTUAL as ;
1008
			VIRTUAL as;
981
	    pid = DEREF_id ( virt_func ( at ) ) ;
1009
			pid = DEREF_id(virt_func(at));
982
	    as = find_overrider ( ct, pid, gr, &ret ) ;
1010
			as = find_overrider(ct, pid, gr, &ret);
983
	    if ( !IS_NULL_virt ( as ) ) at = as ;
1011
			if (!IS_NULL_virt(as)) {
-
 
1012
				at = as;
-
 
1013
			}
984
	}
1014
		}
985
	fid = DEREF_id ( virt_func ( at ) ) ;
1015
		fid = DEREF_id(virt_func(at));
986
	ds = DEREF_dspec ( id_storage ( fid ) ) ;
1016
		ds = DEREF_dspec(id_storage(fid));
987
	gs = DEREF_graph ( virt_base ( at ) ) ;
1017
		gs = DEREF_graph(virt_base(at));
988
 
1018
 
989
	/* Output pointer to member function */
1019
		/* Output pointer to member function */
990
	ts = enc_special ( ts, TOK_pmf_make ) ;
1020
		ts = enc_special(ts, TOK_pmf_make);
991
	us = start_bitstream ( NIL ( FILE ), ts->link ) ;
1021
		us = start_bitstream(NIL(FILE), ts->link);
992
	if ( ds & dspec_pure ) {
1022
		if (ds & dspec_pure) {
993
	    /* Pure virtual function */
1023
			/* Pure virtual function */
994
	    us = enc_special ( us, TOK_vtab_pure ) ;
1024
			us = enc_special(us, TOK_vtab_pure);
995
	} else {
1025
		} else {
996
	    if ( IS_NULL_graph ( ret ) ) {
1026
			if (IS_NULL_graph(ret)) {
997
		IGNORE capsule_id ( fid, VAR_tag ) ;
1027
				IGNORE capsule_id(fid, VAR_tag);
998
		r = unit_no ( us, fid, VAR_tag, 0 ) ;
1028
				r = unit_no(us, fid, VAR_tag, 0);
999
	    } else {
1029
			} else {
1000
		TYPE f = DEREF_type ( id_function_etc_type ( pid ) ) ;
1030
				TYPE f = DEREF_type(id_function_etc_type(pid));
1001
		r = make_thunk ( f, fid, ret ) ;
1031
				r = make_thunk(f, fid, ret);
1002
		r = link_no ( us, r, VAR_tag ) ;
1032
				r = link_no(us, r, VAR_tag);
1003
	    }
1033
			}
1004
	    ENC_obtain_tag ( us ) ;
1034
			ENC_obtain_tag(us);
1005
	    ENC_make_tag ( us, r ) ;
1035
			ENC_make_tag(us, r);
1006
	}
1036
		}
1007
	us = enc_base ( us, gs, 0 ) ;
1037
		us = enc_base(us, gs, 0);
1008
	us = enc_base ( us, gr, 0 ) ;
1038
		us = enc_base(us, gr, 0);
1009
	ts = enc_bitstream ( ts, us ) ;
1039
		ts = enc_bitstream(ts, us);
1010
	pt = TAIL_list ( pt ) ;
1040
		pt = TAIL_list(pt);
1011
    }
1041
	}
1012
    bs = enc_bitstream ( bs, ts ) ;
1042
	bs = enc_bitstream(bs, ts);
1013
    enc_tagdef_end ( bs ) ;
1043
	enc_tagdef_end(bs);
1014
    return ;
1044
	return;
1015
}
1045
}
1016
 
1046
 
1017
 
1047
 
1018
/*
1048
/*
1019
    DEFINE VIRTUAL FUNCTION TABLES
1049
    DEFINE VIRTUAL FUNCTION TABLES
1020
 
1050
 
1021
    This routine defines or declares the virtual function tables for
1051
    This routine defines or declares the virtual function tables for
1022
    the class ct depending on the value of def.  The tables are given
1052
    the class ct depending on the value of def.  The tables are given
1023
    external names only if ext is true.
1053
    external names only if ext is true.
1024
*/
1054
*/
1025
 
1055
 
1026
void define_vtable
1056
void
1027
    PROTO_N ( ( ct, def, ext ) )
-
 
1028
    PROTO_T ( CLASS_TYPE ct X int def X int ext )
1057
define_vtable(CLASS_TYPE ct, int def, int ext)
1029
{
1058
{
1030
    ulong r ;
1059
	ulong r;
1031
    int used ;
1060
	int used;
1032
    int have_main_table = 0 ;
1061
	int have_main_table = 0;
1033
    VIRTUAL vt = DEREF_virt ( ctype_virt ( ct ) ) ;
1062
	VIRTUAL vt = DEREF_virt(ctype_virt(ct));
1034
    if ( IS_NULL_virt ( vt ) ) return ;
1063
	if (IS_NULL_virt(vt)) {
1035
    if ( output_all ) ext = 1 ;
-
 
1036
    if ( def == 2 ) {
-
 
1037
	/* Force definition in this case */
-
 
1038
	IGNORE compile_class ( ct ) ;
-
 
1039
    } else {
-
 
1040
	ulong n = DEREF_ulong ( ctype_shape ( ct ) ) ;
-
 
1041
	if ( n == LINK_NONE ) return ;
-
 
1042
    }
-
 
1043
 
-
 
1044
    /* Output run-time type information */
-
 
1045
    r = DEREF_ulong ( virt_table_rtti ( vt ) ) ;
-
 
1046
    used = DEREF_int ( virt_table_rtti_used ( vt ) ) ;
-
 
1047
    if ( used || def ) {
-
 
1048
	TYPE t = dummy_class ;
-
 
1049
	if ( ext ) {
1064
		return;
1050
	    /* Make up external name */
-
 
1051
	    string s = mangle_typeid ( "__ti__", ct ) ;
-
 
1052
	    r = capsule_name ( r, &s, VAR_tag ) ;
-
 
1053
	}
1065
	}
1054
	record_usage ( r, VAR_tag, USAGE_USE ) ;
-
 
1055
	COPY_int ( virt_table_rtti_used ( vt ), 1 ) ;
-
 
1056
	COPY_ctype ( type_compound_defn ( t ), ct ) ;
-
 
1057
	enc_rtti_struct ( t, r, def ) ;
-
 
1058
    }
-
 
1059
 
-
 
1060
    /* Output virtual function tables */
-
 
1061
    while ( !IS_NULL_virt ( vt ) ) {
-
 
1062
	ulong n ;
-
 
1063
	VIRTUAL vs ;
-
 
1064
	unsigned acc ;
-
 
1065
	CLASS_TYPE cs ;
-
 
1066
	int inherited = 1 ;
1066
	if (output_all) {
1067
	GRAPH gr = DEREF_graph ( virt_base ( vt ) ) ;
-
 
1068
	DECL_SPEC gacc = DEREF_dspec ( graph_access ( gr ) ) ;
-
 
1069
	if ( ( gacc & dspec_ignore ) && !have_main_table ) {
-
 
1070
	    /* Main virtual function table */
-
 
1071
	    gr = DEREF_graph ( graph_top ( gr ) ) ;
-
 
1072
	    have_main_table = 1 ;
-
 
1073
	    inherited = 0 ;
1067
		ext = 1;
1074
	}
1068
	}
1075
	cs = DEREF_ctype ( graph_head ( gr ) ) ;
-
 
1076
	vs = DEREF_virt ( ctype_virt ( cs ) ) ;
-
 
1077
	n = DEREF_ulong ( virt_table_tbl ( vt ) ) ;
-
 
1078
	record_usage ( n, VAR_tag, USAGE_USE ) ;
-
 
1079
	acc = find_usage ( n, VAR_tag ) ;
-
 
1080
	if ( ext ) {
1069
	if (def == 2) {
1081
	    /* Make up external name */
1070
		/* Force definition in this case */
1082
	    string s = mangle_vtable ( "__vt__", gr ) ;
-
 
1083
	    n = capsule_name ( n, &s, VAR_tag ) ;
1071
		IGNORE compile_class(ct);
1084
	}
1072
	} else {
1085
	if ( !( acc & USAGE_DECL ) ) {
-
 
1086
	    /* Output table declaration */
-
 
1087
	    ulong m = DEREF_ulong ( virt_no ( vs ) ) ;
1073
		ulong n = DEREF_ulong(ctype_shape(ct));
1088
	    BITSTREAM *ts = enc_tagdec_start ( NULL_id, n, NULL_type, 1 ) ;
-
 
1089
	    ts = enc_vtable_shape ( ts, m ) ;
1074
		if (n == LINK_NONE) {
1090
	    enc_tagdec_end ( ts ) ;
1075
			return;
1091
	}
1076
		}
1092
	if ( def && !( acc & USAGE_DEFN ) ) {
-
 
1093
	    /* Output table definition */
-
 
1094
	    enc_vtable_defn ( vs, n, ct, gr, inherited, r ) ;
-
 
1095
	}
1077
	}
1096
	vt = DEREF_virt ( virt_next ( vt ) ) ;
-
 
1097
    }
-
 
1098
    return ;
-
 
1099
}
-
 
1100
 
1078
 
-
 
1079
	/* Output run-time type information */
-
 
1080
	r = DEREF_ulong(virt_table_rtti(vt));
-
 
1081
	used = DEREF_int(virt_table_rtti_used(vt));
-
 
1082
	if (used || def) {
-
 
1083
		TYPE t = dummy_class;
-
 
1084
		if (ext) {
-
 
1085
			/* Make up external name */
-
 
1086
			string s = mangle_typeid("__ti__", ct);
-
 
1087
			r = capsule_name(r, &s, VAR_tag);
-
 
1088
		}
-
 
1089
		record_usage(r, VAR_tag, USAGE_USE);
-
 
1090
		COPY_int(virt_table_rtti_used(vt), 1);
-
 
1091
		COPY_ctype(type_compound_defn(t), ct);
-
 
1092
		enc_rtti_struct(t, r, def);
-
 
1093
	}
-
 
1094
 
-
 
1095
	/* Output virtual function tables */
-
 
1096
	while (!IS_NULL_virt(vt)) {
-
 
1097
		ulong n;
-
 
1098
		VIRTUAL vs;
-
 
1099
		unsigned acc;
-
 
1100
		CLASS_TYPE cs;
-
 
1101
		int inherited = 1;
-
 
1102
		GRAPH gr = DEREF_graph(virt_base(vt));
-
 
1103
		DECL_SPEC gacc = DEREF_dspec(graph_access(gr));
-
 
1104
		if ((gacc & dspec_ignore) && !have_main_table) {
-
 
1105
			/* Main virtual function table */
-
 
1106
			gr = DEREF_graph(graph_top(gr));
-
 
1107
			have_main_table = 1;
-
 
1108
			inherited = 0;
-
 
1109
		}
-
 
1110
		cs = DEREF_ctype(graph_head(gr));
-
 
1111
		vs = DEREF_virt(ctype_virt(cs));
-
 
1112
		n = DEREF_ulong(virt_table_tbl(vt));
-
 
1113
		record_usage(n, VAR_tag, USAGE_USE);
-
 
1114
		acc = find_usage(n, VAR_tag);
-
 
1115
		if (ext) {
-
 
1116
			/* Make up external name */
-
 
1117
			string s = mangle_vtable("__vt__", gr);
-
 
1118
			n = capsule_name(n, &s, VAR_tag);
-
 
1119
		}
-
 
1120
		if (!(acc & USAGE_DECL)) {
-
 
1121
			/* Output table declaration */
-
 
1122
			ulong m = DEREF_ulong(virt_no(vs));
-
 
1123
			BITSTREAM *ts = enc_tagdec_start(NULL_id, n, NULL_type,
-
 
1124
							 1);
-
 
1125
			ts = enc_vtable_shape(ts, m);
-
 
1126
			enc_tagdec_end(ts);
-
 
1127
		}
-
 
1128
		if (def && !(acc & USAGE_DEFN)) {
-
 
1129
			/* Output table definition */
-
 
1130
			enc_vtable_defn(vs, n, ct, gr, inherited, r);
-
 
1131
		}
-
 
1132
		vt = DEREF_virt(virt_next(vt));
-
 
1133
	}
-
 
1134
	return;
-
 
1135
}
-
 
1136
 
1101
 
1137
 
1102
/*
1138
/*
1103
    ALLOCATE TAG NUMBERS FOR VIRTUAL FUNCTION TABLES
1139
    ALLOCATE TAG NUMBERS FOR VIRTUAL FUNCTION TABLES
1104
 
1140
 
1105
    This routine allocates tag and token numbers for the virtual function
1141
    This routine allocates tag and token numbers for the virtual function
1106
    tables of the polymorphic class ct and its base classes.
1142
    tables of the polymorphic class ct and its base classes.
1107
*/
1143
*/
1108
 
1144
 
1109
static ulong declare_vtable
1145
static ulong
1110
    PROTO_N ( ( ct ) )
-
 
1111
    PROTO_T ( CLASS_TYPE ct )
1146
declare_vtable(CLASS_TYPE ct)
1112
{
1147
{
1113
    ulong n = LINK_NONE ;
1148
	ulong n = LINK_NONE;
1114
    ulong r = LINK_NONE ;
1149
	ulong r = LINK_NONE;
1115
    VIRTUAL vt = DEREF_virt ( ctype_virt ( ct ) ) ;
1150
	VIRTUAL vt = DEREF_virt(ctype_virt(ct));
1116
    while ( !IS_NULL_virt ( vt ) ) {
1151
	while (!IS_NULL_virt(vt)) {
1117
	ulong t ;
1152
		ulong t;
1118
	OFFSET off ;
1153
		OFFSET off;
1119
	ulong m = DEREF_ulong ( virt_table_tok ( vt ) ) ;
1154
		ulong m = DEREF_ulong(virt_table_tok(vt));
1120
	if ( m != LINK_NONE ) {
1155
		if (m != LINK_NONE) {
1121
	    /* Already declared */
1156
			/* Already declared */
1122
	    return ( m ) ;
1157
			return (m);
1123
	}
1158
		}
1124
	off = DEREF_off ( virt_table_off ( vt ) ) ;
1159
		off = DEREF_off(virt_table_off(vt));
1125
	if ( IS_NULL_off ( off ) ) {
1160
		if (IS_NULL_off(off)) {
1126
	    /* New virtual function table required */
1161
			/* New virtual function table required */
1127
	    m = capsule_no ( NULL_string, VAR_token ) ;
1162
			m = capsule_no(NULL_string, VAR_token);
1128
	} else if ( IS_off_base ( off ) ) {
1163
		} else if (IS_off_base(off)) {
1129
	    /* Use existing virtual function table */
1164
			/* Use existing virtual function table */
1130
	    GRAPH gs = DEREF_graph ( off_base_graph ( off ) ) ;
1165
			GRAPH gs = DEREF_graph(off_base_graph(off));
1131
	    CLASS_TYPE cs = DEREF_ctype ( graph_head ( gs ) ) ;
1166
			CLASS_TYPE cs = DEREF_ctype(graph_head(gs));
1132
	    m = declare_vtable ( cs ) ;
1167
			m = declare_vtable(cs);
1133
	} else {
1168
		} else {
1134
	    /* Use existing virtual function table */
1169
			/* Use existing virtual function table */
1135
	    GRAPH gs = DEREF_graph ( off_deriv_graph ( off ) ) ;
1170
			GRAPH gs = DEREF_graph(off_deriv_graph(off));
1136
	    CLASS_TYPE cs = DEREF_ctype ( graph_head ( gs ) ) ;
1171
			CLASS_TYPE cs = DEREF_ctype(graph_head(gs));
1137
	    m = declare_vtable ( cs ) ;
1172
			m = declare_vtable(cs);
1138
	}
1173
		}
1139
	if ( n == LINK_NONE ) n = m ;
1174
		if (n == LINK_NONE) {
-
 
1175
			n = m;
-
 
1176
		}
1140
 
1177
 
1141
	/* Allocate (but not define) virtual table tags */
1178
		/* Allocate (but not define) virtual table tags */
1142
	t = capsule_no ( NULL_string, VAR_tag ) ;
1179
		t = capsule_no(NULL_string, VAR_tag);
1143
	clear_usage ( t, VAR_tag ) ;
1180
		clear_usage(t, VAR_tag);
1144
	if ( r == LINK_NONE ) {
1181
		if (r == LINK_NONE) {
1145
	    r = capsule_no ( NULL_string, VAR_tag ) ;
1182
			r = capsule_no(NULL_string, VAR_tag);
1146
	    clear_usage ( r, VAR_tag ) ;
1183
			clear_usage(r, VAR_tag);
-
 
1184
		}
-
 
1185
		COPY_ulong(virt_table_tbl(vt), t);
-
 
1186
		COPY_ulong(virt_table_rtti(vt), r);
-
 
1187
		COPY_ulong(virt_table_tok(vt), m);
-
 
1188
		vt = DEREF_virt(virt_next(vt));
1147
	}
1189
	}
1148
	COPY_ulong ( virt_table_tbl ( vt ), t ) ;
-
 
1149
	COPY_ulong ( virt_table_rtti ( vt ), r ) ;
-
 
1150
	COPY_ulong ( virt_table_tok ( vt ), m ) ;
-
 
1151
	vt = DEREF_virt ( virt_next ( vt ) ) ;
-
 
1152
    }
-
 
1153
    return ( n ) ;
1190
	return (n);
1154
}
1191
}
1155
 
1192
 
1156
 
1193
 
1157
/*
1194
/*
1158
    END OF RUN-TIME TYPE INFORMATION ROUTINES
1195
    END OF RUN-TIME TYPE INFORMATION ROUTINES
1159
 
1196
 
1160
    The remaining routines are common to both the C and C++ producers.
1197
    The remaining routines are common to both the C and C++ producers.
1161
*/
1198
*/
1162
 
1199
 
1163
#endif /* LANGUAGE_CPP */
1200
#endif /* LANGUAGE_CPP */
1164
 
1201
 
1165
 
1202
 
1166
/*
1203
/*
1167
    FIND THE TABLE OFFSET OF A VIRTUAL FUNCTION
1204
    FIND THE TABLE OFFSET OF A VIRTUAL FUNCTION
1168
 
1205
 
1169
    This routine finds the position of the virtual function id in the
1206
    This routine finds the position of the virtual function id in the
1170
    virtual function table vt.
1207
    virtual function table vt.
1171
*/
1208
*/
1172
 
1209
 
1173
ulong virtual_no
1210
ulong
1174
    PROTO_N ( ( id, vt ) )
-
 
1175
    PROTO_T ( IDENTIFIER id X VIRTUAL vt )
1211
virtual_no(IDENTIFIER id, VIRTUAL vt)
1176
{
1212
{
1177
    LIST ( VIRTUAL ) pv = DEREF_list ( virt_table_entries ( vt ) ) ;
1213
	LIST(VIRTUAL)pv = DEREF_list(virt_table_entries(vt));
1178
    while ( !IS_NULL_list ( pv ) ) {
1214
	while (!IS_NULL_list(pv)) {
1179
	VIRTUAL vs = DEREF_virt ( HEAD_list ( pv ) ) ;
1215
		VIRTUAL vs = DEREF_virt(HEAD_list(pv));
1180
	IDENTIFIER vid = DEREF_id ( virt_func ( vs ) ) ;
1216
		IDENTIFIER vid = DEREF_id(virt_func(vs));
1181
	if ( EQ_id ( vid, id ) ) {
1217
		if (EQ_id(vid, id)) {
1182
	    ulong m = DEREF_ulong ( virt_no ( vs ) ) ;
1218
			ulong m = DEREF_ulong(virt_no(vs));
1183
	    return ( m + VIRTUAL_EXTRA ) ;
1219
			return (m + VIRTUAL_EXTRA);
-
 
1220
		}
-
 
1221
		pv = TAIL_list(pv);
1184
	}
1222
	}
1185
	pv = TAIL_list ( pv ) ;
-
 
1186
    }
-
 
1187
    return ( VIRTUAL_EXTRA ) ;
1223
	return (VIRTUAL_EXTRA);
1188
}
1224
}
1189
 
1225
 
1190
 
1226
 
1191
/*
1227
/*
1192
    IS A TYPE A ZERO SIZED BITFIELD?
1228
    IS A TYPE A ZERO SIZED BITFIELD?
Line 1194... Line 1230...
1194
    This routine checks whether the type t represents a zero sized
1230
    This routine checks whether the type t represents a zero sized
1195
    bitfield.  These force an alignment in a class rather than being
1231
    bitfield.  These force an alignment in a class rather than being
1196
    a proper class member.
1232
    a proper class member.
1197
*/
1233
*/
1198
 
1234
 
1199
static int is_zero_bitfield
1235
static int
1200
    PROTO_N ( ( t ) )
-
 
1201
    PROTO_T ( TYPE t )
1236
is_zero_bitfield(TYPE t)
1202
{
1237
{
1203
    if ( !IS_NULL_type ( t ) && IS_type_bitfield ( t ) ) {
1238
	if (!IS_NULL_type(t) && IS_type_bitfield(t)) {
1204
	INT_TYPE bf = DEREF_itype ( type_bitfield_defn ( t ) ) ;
1239
		INT_TYPE bf = DEREF_itype(type_bitfield_defn(t));
1205
	DECL_SPEC ds = DEREF_dspec ( itype_bitfield_info ( bf ) ) ;
1240
		DECL_SPEC ds = DEREF_dspec(itype_bitfield_info(bf));
1206
	if ( ds & dspec_pure ) return ( 1 ) ;
1241
		if (ds & dspec_pure) {
-
 
1242
			return (1);
1207
    }
1243
		}
-
 
1244
	}
1208
    return ( 0 ) ;
1245
	return (0);
1209
}
1246
}
1210
 
1247
 
1211
 
1248
 
1212
/*
1249
/*
1213
    ENCODE A SHAPE OFFSET EXPRESSION
1250
    ENCODE A SHAPE OFFSET EXPRESSION
1214
 
1251
 
1215
    This routine adds the offset of the type t to the bitstream bs,
1252
    This routine adds the offset of the type t to the bitstream bs,
1216
    unless t is dummy_class, when the offset of the type excluding the
1253
    unless t is dummy_class, when the offset of the type excluding the
1217
    virtual bases is added.
1254
    virtual bases is added.
1218
*/
1255
*/
1219
 
1256
 
1220
static BITSTREAM *enc_offset_add
1257
static BITSTREAM *
1221
    PROTO_N ( ( bs, t ) )
-
 
1222
    PROTO_T ( BITSTREAM *bs X TYPE t )
1258
enc_offset_add(BITSTREAM *bs, TYPE t)
1223
{
1259
{
1224
    if ( EQ_type ( t, dummy_class ) ) {
1260
	if (EQ_type(t, dummy_class)) {
1225
	/* Class offset */
1261
		/* Class offset */
1226
	CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
1262
		CLASS_TYPE ct = DEREF_ctype(type_compound_defn(t));
1227
	GRAPH gr = DEREF_graph ( ctype_base ( ct ) ) ;
1263
		GRAPH gr = DEREF_graph(ctype_base(ct));
1228
	ulong m = DEREF_ulong ( graph_core_off ( gr ) ) ;
1264
		ulong m = DEREF_ulong(graph_core_off(gr));
1229
	if ( m != LINK_NONE ) {
1265
		if (m != LINK_NONE) {
1230
	    bs = enc_exp_token ( bs, m ) ;
1266
			bs = enc_exp_token(bs, m);
1231
	    return ( bs ) ;
1267
			return (bs);
1232
	}
1268
		}
1233
    }
1269
	}
1234
    ENC_shape_offset ( bs ) ;
1270
	ENC_shape_offset(bs);
1235
    bs = enc_shape ( bs, t ) ;
1271
	bs = enc_shape(bs, t);
1236
    return ( bs ) ;
1272
	return (bs);
1237
}
1273
}
1238
 
1274
 
1239
 
1275
 
1240
/*
1276
/*
1241
    ENCODE AN OFFSET PAD EXPRESSION
1277
    ENCODE AN OFFSET PAD EXPRESSION
1242
 
1278
 
1243
    This routine adds the offset of a structure member of type s
1279
    This routine adds the offset of a structure member of type s
1244
    which follows a member of type t with offset given by the token n
1280
    which follows a member of type t with offset given by the token n
1245
    to the bitstream bs.  Note that bitfield types are awkward.
1281
    to the bitstream bs.  Note that bitfield types are awkward.
1246
*/
1282
*/
1247
 
1283
 
1248
static BITSTREAM *enc_offset_pad
1284
static BITSTREAM *
1249
    PROTO_N ( ( bs, n, t, s ) )
-
 
1250
    PROTO_T ( BITSTREAM *bs X ulong n X TYPE t X TYPE s )
1285
enc_offset_pad(BITSTREAM *bs, ulong n, TYPE t, TYPE s)
1251
{
1286
{
1252
    BITSTREAM *ts ;
1287
	BITSTREAM *ts;
1253
    unsigned tag = null_tag ;
1288
	unsigned tag = null_tag;
1254
    int z = is_zero_bitfield ( t ) ;
1289
	int z = is_zero_bitfield(t);
1255
    if ( !IS_NULL_type ( s ) ) {
1290
	if (!IS_NULL_type(s)) {
1256
	if ( is_zero_bitfield ( s ) ) {
1291
		if (is_zero_bitfield(s)) {
1257
	    /* Force an alignment */
1292
			/* Force an alignment */
1258
	    s = find_bitfield_type ( s ) ;
1293
			s = find_bitfield_type(s);
1259
	}
1294
		}
1260
	ENC_offset_pad ( bs ) ;
1295
		ENC_offset_pad(bs);
1261
	bs = enc_alignment ( bs, s ) ;
1296
		bs = enc_alignment(bs, s);
1262
	tag = TAG_type ( s ) ;
1297
		tag = TAG_type(s);
1263
    }
1298
	}
1264
    if ( tag == type_bitfield_tag ) {
1299
	if (tag == type_bitfield_tag) {
1265
	/* Use token for bitfields */
1300
		/* Use token for bitfields */
1266
	bs = enc_special ( bs, TOK_pad ) ;
1301
		bs = enc_special(bs, TOK_pad);
1267
	ts = start_bitstream ( NIL ( FILE ), bs->link ) ;
1302
		ts = start_bitstream(NIL(FILE), bs->link);
1268
    } else {
1303
	} else {
1269
	ts = bs ;
1304
		ts = bs;
1270
    }
1305
	}
1271
 
1306
 
1272
    /* Add offset (except for zero sized bitfields) */
1307
	/* Add offset (except for zero sized bitfields) */
-
 
1308
	if (!z) {
1273
    if ( !z ) ENC_offset_add ( ts ) ;
1309
		ENC_offset_add(ts);
-
 
1310
	}
1274
    ts = enc_exp_token ( ts, n ) ;
1311
	ts = enc_exp_token(ts, n);
-
 
1312
	if (!z) {
1275
    if ( !z ) ts = enc_offset_add ( ts, t ) ;
1313
		ts = enc_offset_add(ts, t);
-
 
1314
	}
1276
 
1315
 
1277
    /* Encode extra bitfield arguments */
1316
	/* Encode extra bitfield arguments */
1278
    if ( tag == type_bitfield_tag ) {
1317
	if (tag == type_bitfield_tag) {
1279
	TYPE r = find_bitfield_type ( s ) ;
1318
		TYPE r = find_bitfield_type(s);
1280
	ts = enc_shape ( ts, r ) ;
1319
		ts = enc_shape(ts, r);
1281
	ts = enc_shape ( ts, s ) ;
1320
		ts = enc_shape(ts, s);
1282
	bs = enc_bitstream ( bs, ts ) ;
1321
		bs = enc_bitstream(bs, ts);
1283
    } else {
1322
	} else {
1284
	bs = ts ;
1323
		bs = ts;
1285
    }
1324
	}
1286
    return ( bs ) ;
1325
	return (bs);
1287
}
1326
}
1288
 
1327
 
1289
 
1328
 
1290
/*
1329
/*
1291
    DEFINE AN ALIGNMENT TAG
1330
    DEFINE AN ALIGNMENT TAG
1292
 
1331
 
1293
    This routine defines the alignment tag m to be the token n.  The value
1332
    This routine defines the alignment tag m to be the token n.  The value
1294
    LINK_NONE for n is used to indicate an incomplete structure.
1333
    LINK_NONE for n is used to indicate an incomplete structure.
1295
*/
1334
*/
1296
 
1335
 
1297
static void enc_al_tagdef
1336
static void
1298
    PROTO_N ( ( m, n ) )
-
 
1299
    PROTO_T ( ulong m X ulong n )
1337
enc_al_tagdef(ulong m, ulong n)
1300
{
1338
{
1301
    unsigned acc = find_usage ( m, VAR_alignment ) ;
1339
	unsigned acc = find_usage(m, VAR_alignment);
1302
    if ( !( acc & USAGE_DEFN ) ) {
1340
	if (!(acc & USAGE_DEFN)) {
1303
	BITSTREAM *bs = aldef_unit ;
1341
		BITSTREAM *bs = aldef_unit;
1304
	ulong r = link_no ( bs, m, VAR_alignment ) ;
1342
		ulong r = link_no(bs, m, VAR_alignment);
1305
	ENC_make_al_tagdef ( bs ) ;
1343
		ENC_make_al_tagdef(bs);
1306
	ENC_INT ( bs, r ) ;
1344
		ENC_INT(bs, r);
1307
	if ( n == LINK_NONE ) {
1345
		if (n == LINK_NONE) {
1308
	    bs = enc_special ( bs, TOK_empty_align ) ;
1346
			bs = enc_special(bs, TOK_empty_align);
1309
	} else {
1347
		} else {
1310
	    ENC_alignment ( bs ) ;
1348
			ENC_alignment(bs);
1311
	    bs = enc_shape_token ( bs, n ) ;
1349
			bs = enc_shape_token(bs, n);
-
 
1350
		}
-
 
1351
		record_usage(m, VAR_alignment, USAGE_DEFN);
-
 
1352
		count_item(bs);
-
 
1353
		aldef_unit = bs;
1312
	}
1354
	}
1313
	record_usage ( m, VAR_alignment, USAGE_DEFN ) ;
-
 
1314
	count_item ( bs ) ;
-
 
1315
	aldef_unit = bs ;
-
 
1316
    }
-
 
1317
    return ;
1355
	return;
1318
}
1356
}
1319
 
1357
 
1320
 
1358
 
1321
/*
1359
/*
1322
    ENCODE A TDF COMPOUND SHAPE
1360
    ENCODE A TDF COMPOUND SHAPE
1323
 
1361
 
1324
    This routine defines all the shape and offset tokens associated with
1362
    This routine defines all the shape and offset tokens associated with
1325
    the compound type ct.  It returns the external (capsule) number of
1363
    the compound type ct.  It returns the external (capsule) number of
1326
    a token giving the overall shape of the result.
1364
    a token giving the overall shape of the result.
1616
 
1677
 
-
 
1678
		} else {
1617
	    /* Record offset of non-virtual components */
1679
			/* Empty structure definition */
-
 
1680
			clear_usage(n, VAR_token);
-
 
1681
			n = special_no(TOK_empty_shape);
1618
	    if ( vo == LINK_NONE ) vo = m ;
1682
			COPY_ulong(ctype_shape(ct), n);
-
 
1683
			vo = special_no(TOK_empty_offset);
1619
	    COPY_ulong ( graph_core_off ( gr ), vo ) ;
1684
			COPY_ulong(graph_core_off(gr), vo);
-
 
1685
			ci |= cinfo_empty;
-
 
1686
		}
-
 
1687
		COPY_cinfo(ctype_info(ct), ci);
1620
 
1688
 
1621
	    /* Non-empty structure shape definition */
1689
		/* Define associated alignment tag */
1622
	    if ( ext ) {
-
 
1623
		string s = mangle_typeid ( "~cpp.sh.", ct ) ;
-
 
1624
		n = capsule_name ( n, &s, VAR_token ) ;
1690
		m = DEREF_ulong(graph_al_tag(gr));
1625
	    }
-
 
1626
	    bs = enc_tokdef_start ( n, "S", NIL ( ulong ), 1 ) ;
-
 
1627
	    ENC_compound ( bs ) ;
1691
		if (m != LINK_NONE) {
1628
	    bs = enc_exp_token ( bs, m ) ;
-
 
1629
	    enc_tokdef_end ( n, bs ) ;
1692
			enc_al_tagdef(m, n);
1630
	    ci &= ~cinfo_empty ;
-
 
1631
 
1693
		}
1632
	} else {
-
 
1633
	    /* Empty structure definition */
-
 
1634
	    clear_usage ( n, VAR_token ) ;
-
 
1635
	    n = special_no ( TOK_empty_shape ) ;
-
 
1636
	    COPY_ulong ( ctype_shape ( ct ), n ) ;
1694
		COPY_ctype(type_compound_defn(dummy_class), cd);
1637
	    vo = special_no ( TOK_empty_offset ) ;
-
 
1638
	    COPY_ulong ( graph_core_off ( gr ), vo ) ;
-
 
1639
	    ci |= cinfo_empty ;
-
 
1640
	}
1695
	}
1641
	COPY_cinfo ( ctype_info ( ct ), ci ) ;
-
 
1642
 
-
 
1643
	/* Define associated alignment tag */
-
 
1644
	m = DEREF_ulong ( graph_al_tag ( gr ) ) ;
-
 
1645
	if ( m != LINK_NONE ) enc_al_tagdef ( m, n ) ;
-
 
1646
	COPY_ctype ( type_compound_defn ( dummy_class ), cd ) ;
-
 
1647
    }
-
 
1648
    return ( n ) ;
1696
	return (n);
1649
}
1697
}
1650
 
1698
 
1651
 
1699
 
1652
/*
1700
/*
1653
    ENCODE THE SHAPE OF A CLASS TYPE
1701
    ENCODE THE SHAPE OF A CLASS TYPE
1654
 
1702
 
1655
    This routine adds the class type ct to the bitstream bs as a TDF SHAPE.
1703
    This routine adds the class type ct to the bitstream bs as a TDF SHAPE.
1656
*/
1704
*/
1657
 
1705
 
1658
BITSTREAM *enc_ctype
1706
BITSTREAM *
1659
    PROTO_N ( ( bs, ct ) )
-
 
1660
    PROTO_T ( BITSTREAM *bs X CLASS_TYPE ct )
1707
enc_ctype(BITSTREAM *bs, CLASS_TYPE ct)
1661
{
1708
{
1662
    ulong n = compile_class ( ct ) ;
1709
	ulong n = compile_class(ct);
1663
    bs = enc_shape_token ( bs, n ) ;
1710
	bs = enc_shape_token(bs, n);
1664
    return ( bs ) ;
1711
	return (bs);
1665
}
1712
}
1666
 
1713
 
1667
 
1714
 
1668
/*
1715
/*
1669
    LIST OF INCOMPLETE CLASSES
1716
    LIST OF INCOMPLETE CLASSES
Line 1671... Line 1718...
1671
    This list is used to hold all the classes which are used while they
1718
    This list is used to hold all the classes which are used while they
1672
    are incomplete.  An alignment tag is introduced for each such class
1719
    are incomplete.  An alignment tag is introduced for each such class
1673
    which may be defined later if the class is completed.
1720
    which may be defined later if the class is completed.
1674
*/
1721
*/
1675
 
1722
 
1676
static LIST ( CLASS_TYPE ) incompl_classes = NULL_list ( CLASS_TYPE ) ;
1723
static LIST(CLASS_TYPE)incompl_classes = NULL_list(CLASS_TYPE);
1677
 
1724
 
1678
 
1725
 
1679
/*
1726
/*
1680
    DEFINE INCOMPLETE CLASSES
1727
    DEFINE INCOMPLETE CLASSES
1681
 
1728
 
1682
    This routine defines the alignment tags for the incomplete classes
1729
    This routine defines the alignment tags for the incomplete classes
1683
    in this list above.  Note that the class is not compiled if it has
1730
    in this list above.  Note that the class is not compiled if it has
1684
    not already been so.
1731
    not already been so.
1685
*/
1732
*/
1686
 
1733
 
-
 
1734
void
1687
void compile_incompl
1735
compile_incompl(void)
1688
    PROTO_Z ()
-
 
1689
{
1736
{
1690
    LIST ( CLASS_TYPE ) p = incompl_classes ;
1737
	LIST(CLASS_TYPE)p = incompl_classes;
1691
    while ( !IS_NULL_list ( p ) ) {
1738
	while (!IS_NULL_list(p)) {
1692
	CLASS_TYPE ct = DEREF_ctype ( HEAD_list ( p ) ) ;
1739
		CLASS_TYPE ct = DEREF_ctype(HEAD_list(p));
1693
	ulong n = DEREF_ulong ( ctype_shape ( ct ) ) ;
1740
		ulong n = DEREF_ulong(ctype_shape(ct));
1694
	if ( n == LINK_NONE ) {
1741
		if (n == LINK_NONE) {
1695
	    /* Uncompiled or incomplete class */
1742
			/* Uncompiled or incomplete class */
1696
	    GRAPH gr = DEREF_graph ( ctype_base ( ct ) ) ;
1743
			GRAPH gr = DEREF_graph(ctype_base(ct));
1697
	    ulong m = DEREF_ulong ( graph_al_tag ( gr ) ) ;
1744
			ulong m = DEREF_ulong(graph_al_tag(gr));
1698
	    enc_al_tagdef ( m, n ) ;
1745
			enc_al_tagdef(m, n);
-
 
1746
		}
-
 
1747
		p = TAIL_list(p);
1699
	}
1748
	}
1700
	p = TAIL_list ( p ) ;
-
 
1701
    }
-
 
1702
    DESTROY_list ( incompl_classes, SIZE_ctype ) ;
1749
	DESTROY_list(incompl_classes, SIZE_ctype);
1703
    incompl_classes = NULL_list ( CLASS_TYPE ) ;
1750
	incompl_classes = NULL_list(CLASS_TYPE);
1704
    return ;
1751
	return;
1705
}
1752
}
1706
 
1753
 
1707
 
1754
 
1708
/*
1755
/*
1709
    ENCODE THE ALIGNMENT OF A CLASS TYPE
1756
    ENCODE THE ALIGNMENT OF A CLASS TYPE
1710
 
1757
 
1711
    This routine adds the alignment of the class type ct to the bitstream
1758
    This routine adds the alignment of the class type ct to the bitstream
1712
    bs.  Note that ct is not compiled by this routine.
1759
    bs.  Note that ct is not compiled by this routine.
1713
*/
1760
*/
1714
 
1761
 
1715
BITSTREAM *enc_al_ctype
1762
BITSTREAM *
1716
    PROTO_N ( ( bs, ct ) )
-
 
1717
    PROTO_T ( BITSTREAM *bs X CLASS_TYPE ct )
1763
enc_al_ctype(BITSTREAM *bs, CLASS_TYPE ct)
1718
{
1764
{
1719
    GRAPH gr = DEREF_graph ( ctype_base ( ct ) ) ;
1765
	GRAPH gr = DEREF_graph(ctype_base(ct));
1720
    ulong m = DEREF_ulong ( graph_al_tag ( gr ) ) ;
1766
	ulong m = DEREF_ulong(graph_al_tag(gr));
1721
    if ( m == LINK_NONE ) {
1767
	if (m == LINK_NONE) {
1722
	string s = NULL ;
1768
		string s = NULL;
1723
	ulong n = DEREF_ulong ( ctype_shape ( ct ) ) ;
1769
		ulong n = DEREF_ulong(ctype_shape(ct));
1724
	if ( n != LINK_NONE ) {
1770
		if (n != LINK_NONE) {
1725
	    /* Class already compiled */
1771
			/* Class already compiled */
1726
	    ENC_alignment ( bs ) ;
1772
			ENC_alignment(bs);
1727
	    bs = enc_shape_token ( bs, n ) ;
1773
			bs = enc_shape_token(bs, n);
1728
	    return ( bs ) ;
1774
			return (bs);
-
 
1775
		}
-
 
1776
		if (output_all) {
-
 
1777
			s = mangle_typeid("~cpp.al.", ct);
-
 
1778
		}
-
 
1779
		m = capsule_no(s, VAR_alignment);
-
 
1780
		COPY_ulong(graph_al_tag(gr), m);
-
 
1781
		CONS_ctype(ct, incompl_classes, incompl_classes);
1729
	}
1782
	}
1730
	if ( output_all ) s = mangle_typeid ( "~cpp.al.", ct ) ;
-
 
1731
	m = capsule_no ( s, VAR_alignment ) ;
-
 
1732
	COPY_ulong ( graph_al_tag ( gr ), m ) ;
-
 
1733
	CONS_ctype ( ct, incompl_classes, incompl_classes ) ;
-
 
1734
    }
-
 
1735
    m = link_no ( bs, m, VAR_alignment ) ;
1783
	m = link_no(bs, m, VAR_alignment);
1736
    ENC_obtain_al_tag ( bs ) ;
1784
	ENC_obtain_al_tag(bs);
1737
    ENC_make_al_tag ( bs, m ) ;
1785
	ENC_make_al_tag(bs, m);
1738
    return ( bs ) ;
1786
	return (bs);
1739
}
1787
}
1740
 
1788
 
1741
 
1789
 
1742
/*
1790
/*
1743
    COMPILE A BASE CLASS
1791
    COMPILE A BASE CLASS
Line 1746... Line 1794...
1746
    number representing the base class offset.  If gr is a virtual base
1794
    number representing the base class offset.  If gr is a virtual base
1747
    and ptr is true then this is the offset of the pointer to the base,
1795
    and ptr is true then this is the offset of the pointer to the base,
1748
    otherwise it is the actual base.
1796
    otherwise it is the actual base.
1749
*/
1797
*/
1750
 
1798
 
1751
static ulong compile_base
1799
static ulong
1752
    PROTO_N ( ( gr, ptr ) )
-
 
1753
    PROTO_T ( GRAPH gr X int ptr )
1800
compile_base(GRAPH gr, int ptr)
1754
{
1801
{
1755
    ulong n, m ;
1802
	ulong n, m;
1756
    GRAPH g1, g2 ;
1803
	GRAPH g1, g2;
1757
    BITSTREAM *bs ;
1804
	BITSTREAM *bs;
1758
    string s = NULL ;
1805
	string s = NULL;
1759
    OFFSET off = DEREF_off ( graph_off ( gr ) ) ;
1806
	OFFSET off = DEREF_off(graph_off(gr));
1760
    DECL_SPEC acc = DEREF_dspec ( graph_access ( gr ) ) ;
1807
	DECL_SPEC acc = DEREF_dspec(graph_access(gr));
1761
    if ( ( acc & dspec_virtual ) && !ptr ) {
1808
	if ((acc & dspec_virtual) && !ptr) {
1762
	/* Virtual base class */
1809
		/* Virtual base class */
1763
	n = DEREF_ulong ( graph_real_off ( gr ) ) ;
1810
		n = DEREF_ulong(graph_real_off(gr));
1764
	return ( n ) ;
1811
		return (n);
1765
    }
1812
	}
1766
    if ( IS_off_base ( off ) ) {
1813
	if (IS_off_base(off)) {
1767
	/* Direct base class */
1814
		/* Direct base class */
1768
	n = DEREF_ulong ( graph_base_off ( gr ) ) ;
1815
		n = DEREF_ulong(graph_base_off(gr));
1769
	return ( n ) ;
1816
		return (n);
1770
    }
-
 
1771
 
1817
	}
1772
    /* Check for recorded values */
-
 
1773
    if ( ptr ) {
-
 
1774
	n = DEREF_ulong ( graph_base_off ( gr ) ) ;
-
 
1775
    } else {
-
 
1776
	n = DEREF_ulong ( graph_real_off ( gr ) ) ;
-
 
1777
    }
-
 
1778
    if ( n != LINK_NONE ) return ( n ) ;
-
 
1779
    if ( output_all ) {
-
 
1780
	CONST char *pre = "~cpp.base." ;
-
 
1781
	if ( ( acc & dspec_mutable ) && !ptr ) pre = "~cpp.virt." ;
-
 
1782
	s = mangle_vtable ( pre, gr ) ;
-
 
1783
    }
-
 
1784
    n = capsule_no ( s, VAR_token ) ;
-
 
1785
 
1818
 
1786
    /* Decompose base offset */
1819
	/* Check for recorded values */
1787
    if ( acc & dspec_mutable ) {
1820
	if (ptr) {
1788
	/* Base of virtual base */
1821
		n = DEREF_ulong(graph_base_off(gr));
1789
	CLASS_TYPE cs ;
1822
	} else {
1790
	g1 = DEREF_graph ( graph_up ( gr ) ) ;
1823
		n = DEREF_ulong(graph_real_off(gr));
-
 
1824
	}
1791
	cs = DEREF_ctype ( graph_head ( g1 ) ) ;
1825
	if (n != LINK_NONE) {
-
 
1826
		return (n);
-
 
1827
	}
1792
	g2 = DEREF_graph ( ctype_base ( cs ) ) ;
1828
	if (output_all) {
1793
	g2 = find_subgraph ( g2, g1, gr ) ;
1829
		CONST char *pre = "~cpp.base.";
1794
	if ( ptr ) {
1830
		if ((acc & dspec_mutable) && !ptr) {
1795
	    COPY_ulong ( graph_base_off ( gr ), n ) ;
1831
			pre = "~cpp.virt.";
1796
	} else {
1832
		}
1797
	    COPY_ulong ( graph_real_off ( gr ), n ) ;
1833
		s = mangle_vtable(pre, gr);
1798
	}
1834
	}
-
 
1835
	n = capsule_no(s, VAR_token);
-
 
1836
 
-
 
1837
	/* Decompose base offset */
1799
    } else {
1838
	if (acc & dspec_mutable) {
1800
	/* Indirect base */
1839
		/* Base of virtual base */
-
 
1840
		CLASS_TYPE cs;
1801
	OFFSET off1 = DEREF_off ( off_deriv_direct ( off ) ) ;
1841
		g1 = DEREF_graph(graph_up(gr));
1802
	OFFSET off2 = DEREF_off ( off_deriv_indirect ( off ) ) ;
1842
		cs = DEREF_ctype(graph_head(g1));
1803
	g1 = DEREF_graph ( off_base_graph ( off1 ) ) ;
1843
		g2 = DEREF_graph(ctype_base(cs));
1804
	if ( IS_off_base ( off2 ) ) {
1844
		g2 = find_subgraph(g2, g1, gr);
-
 
1845
		if (ptr) {
1805
	    g2 = DEREF_graph ( off_base_graph ( off2 ) ) ;
1846
			COPY_ulong(graph_base_off(gr), n);
-
 
1847
		} else {
-
 
1848
			COPY_ulong(graph_real_off(gr), n);
-
 
1849
		}
1806
	} else {
1850
	} else {
-
 
1851
		/* Indirect base */
-
 
1852
		OFFSET off1 = DEREF_off(off_deriv_direct(off));
-
 
1853
		OFFSET off2 = DEREF_off(off_deriv_indirect(off));
-
 
1854
		g1 = DEREF_graph(off_base_graph(off1));
-
 
1855
		if (IS_off_base(off2)) {
-
 
1856
			g2 = DEREF_graph(off_base_graph(off2));
-
 
1857
		} else {
1807
	    g2 = DEREF_graph ( off_deriv_graph ( off2 ) ) ;
1858
			g2 = DEREF_graph(off_deriv_graph(off2));
-
 
1859
		}
-
 
1860
		COPY_ulong(graph_base_off(gr), n);
-
 
1861
		COPY_ulong(graph_real_off(gr), n);
1808
	}
1862
	}
1809
	COPY_ulong ( graph_base_off ( gr ), n ) ;
-
 
1810
	COPY_ulong ( graph_real_off ( gr ), n ) ;
-
 
1811
    }
-
 
1812
 
1863
 
1813
    /* Define the token */
1864
	/* Define the token */
1814
    bs = enc_tokdef_start ( n, "E", NIL ( ulong ), 1 ) ;
1865
	bs = enc_tokdef_start(n, "E", NIL(ulong), 1);
1815
    ENC_offset_add ( bs ) ;
1866
	ENC_offset_add(bs);
1816
    m = compile_base ( g1, 0 ) ;
1867
	m = compile_base(g1, 0);
1817
    bs = enc_exp_token ( bs, m ) ;
1868
	bs = enc_exp_token(bs, m);
1818
    m = compile_base ( g2, ptr ) ;
1869
	m = compile_base(g2, ptr);
1819
    bs = enc_exp_token ( bs, m ) ;
1870
	bs = enc_exp_token(bs, m);
1820
    enc_tokdef_end ( n, bs ) ;
1871
	enc_tokdef_end(n, bs);
1821
    return ( n ) ;
1872
	return (n);
1822
}
1873
}
1823
 
1874
 
1824
 
1875
 
1825
/*
1876
/*
1826
    ENCODE A BASE CLASS OFFSET
1877
    ENCODE A BASE CLASS OFFSET
1827
 
1878
 
1828
    This routine adds an offset representing the base class graph gr
1879
    This routine adds an offset representing the base class graph gr
1829
    to the bitstream bs.  For virtual bases this is the offset of the
1880
    to the bitstream bs.  For virtual bases this is the offset of the
1830
    pointer to the base if ptr is true and the offset of the actual base
1881
    pointer to the base if ptr is true and the offset of the actual base
1831
    otherwise.
1882
    otherwise.
1832
*/
1883
*/
1833
 
1884
 
1834
BITSTREAM *enc_base
1885
BITSTREAM *
1835
    PROTO_N ( ( bs, gr, ptr ) )
-
 
1836
    PROTO_T ( BITSTREAM *bs X GRAPH gr X int ptr )
1886
enc_base(BITSTREAM *bs, GRAPH gr, int ptr)
1837
{
1887
{
1838
    GRAPH gt = DEREF_graph ( graph_top ( gr ) ) ;
1888
	GRAPH gt = DEREF_graph(graph_top(gr));
1839
    CLASS_TYPE ct = DEREF_ctype ( graph_head ( gt ) ) ;
1889
	CLASS_TYPE ct = DEREF_ctype(graph_head(gt));
1840
    if ( EQ_graph ( gr, gt ) ) {
1890
	if (EQ_graph(gr, gt)) {
1841
	ENC_offset_zero ( bs ) ;
1891
		ENC_offset_zero(bs);
1842
	bs = enc_al_ctype ( bs, ct ) ;
1892
		bs = enc_al_ctype(bs, ct);
1843
    } else {
1893
	} else {
1844
	ulong n ;
1894
		ulong n;
1845
	IGNORE compile_class ( ct ) ;
1895
		IGNORE compile_class(ct);
1846
	n = compile_base ( gr, ptr ) ;
1896
		n = compile_base(gr, ptr);
1847
	bs = enc_exp_token ( bs, n ) ;
1897
		bs = enc_exp_token(bs, n);
1848
    }
1898
	}
1849
    return ( bs ) ;
1899
	return (bs);
1850
}
1900
}
1851
 
1901
 
1852
 
1902
 
1853
/*
1903
/*
1854
    ENCODE THE START OF A VIRTUAL BASE CLASS POINTER EXPRESSION
1904
    ENCODE THE START OF A VIRTUAL BASE CLASS POINTER EXPRESSION
1855
 
1905
 
1856
    This routine adds the start of a virtual base class pointer expression
1906
    This routine adds the start of a virtual base class pointer expression
1857
    to the bitstream bs.  off1 gives the direct component of the offset
1907
    to the bitstream bs.  off1 gives the direct component of the offset
1858
    and off2 gives the indirect component.
1908
    and off2 gives the indirect component.
1859
*/
1909
*/
1860
 
1910
 
1861
BITSTREAM *enc_add_base
1911
BITSTREAM *
1862
    PROTO_N ( ( bs, off1, off2 ) )
-
 
1863
    PROTO_T ( BITSTREAM *bs X OFFSET off1 X OFFSET off2 )
1912
enc_add_base(BITSTREAM *bs, OFFSET off1, OFFSET off2)
1864
{
1913
{
1865
    GRAPH gr = DEREF_graph ( off_base_graph ( off1 ) ) ;
1914
	GRAPH gr = DEREF_graph(off_base_graph(off1));
1866
    DECL_SPEC acc = DEREF_dspec ( graph_access ( gr ) ) ;
1915
	DECL_SPEC acc = DEREF_dspec(graph_access(gr));
1867
    if ( !IS_NULL_off ( off2 ) ) {
1916
	if (!IS_NULL_off(off2)) {
1868
	if ( IS_off_deriv ( off2 ) ) {
1917
		if (IS_off_deriv(off2)) {
1869
	    OFFSET off3 = DEREF_off ( off_deriv_direct ( off2 ) ) ;
1918
			OFFSET off3 = DEREF_off(off_deriv_direct(off2));
1870
	    OFFSET off4 = DEREF_off ( off_deriv_indirect ( off2 ) ) ;
1919
			OFFSET off4 = DEREF_off(off_deriv_indirect(off2));
1871
	    bs = enc_add_base ( bs, off3, off4 ) ;
1920
			bs = enc_add_base(bs, off3, off4);
1872
	} else {
1921
		} else {
1873
	    bs = enc_add_base ( bs, off2, NULL_off ) ;
1922
			bs = enc_add_base(bs, off2, NULL_off);
-
 
1923
		}
-
 
1924
	}
-
 
1925
	if (acc & dspec_virtual) {
-
 
1926
		/* Indirection for virtual bases */
-
 
1927
		CLASS_TYPE ct = DEREF_ctype(graph_head(gr));
-
 
1928
		ENC_contents(bs);
-
 
1929
		ENC_pointer(bs);
-
 
1930
		bs = enc_al_ctype(bs, ct);
-
 
1931
	}
-
 
1932
	if (!(acc & dspec_ignore)) {
-
 
1933
		/* Add base class offset */
-
 
1934
		ENC_add_to_ptr(bs);
1874
	}
1935
	}
1875
    }
-
 
1876
    if ( acc & dspec_virtual ) {
-
 
1877
	/* Indirection for virtual bases */
-
 
1878
	CLASS_TYPE ct = DEREF_ctype ( graph_head ( gr ) ) ;
-
 
1879
	ENC_contents ( bs ) ;
-
 
1880
	ENC_pointer ( bs ) ;
-
 
1881
	bs = enc_al_ctype ( bs, ct ) ;
-
 
1882
    }
-
 
1883
    if ( !( acc & dspec_ignore ) ) {
-
 
1884
	/* Add base class offset */
-
 
1885
	ENC_add_to_ptr ( bs ) ;
-
 
1886
    }
-
 
1887
    return ( bs ) ;
1936
	return (bs);
1888
}
1937
}
1889
 
1938
 
1890
 
1939
 
1891
/*
1940
/*
1892
    ENCODE THE END OF A VIRTUAL BASE CLASS POINTER EXPRESSION
1941
    ENCODE THE END OF A VIRTUAL BASE CLASS POINTER EXPRESSION
1893
 
1942
 
1894
    This routine adds the end of a virtual base class pointer expression
1943
    This routine adds the end of a virtual base class pointer expression
1895
    to the bitstream bs.  off1 gives the direct component of the offset
1944
    to the bitstream bs.  off1 gives the direct component of the offset
1896
    and off2 gives the indirect component.
1945
    and off2 gives the indirect component.
1897
*/
1946
*/
1898
 
1947
 
1899
BITSTREAM *enc_end_base
1948
BITSTREAM *
1900
    PROTO_N ( ( bs, off1, off2 ) )
-
 
1901
    PROTO_T ( BITSTREAM *bs X OFFSET off1 X OFFSET off2 )
1949
enc_end_base(BITSTREAM *bs, OFFSET off1, OFFSET off2)
1902
{
1950
{
1903
    GRAPH gr = DEREF_graph ( off_base_graph ( off1 ) ) ;
1951
	GRAPH gr = DEREF_graph(off_base_graph(off1));
1904
    DECL_SPEC acc = DEREF_dspec ( graph_access ( gr ) ) ;
1952
	DECL_SPEC acc = DEREF_dspec(graph_access(gr));
1905
    if ( !( acc & dspec_ignore ) ) {
1953
	if (!(acc & dspec_ignore)) {
1906
	/* Output base class offset */
1954
		/* Output base class offset */
1907
	ulong n = DEREF_ulong ( graph_base_off ( gr ) ) ;
1955
		ulong n = DEREF_ulong(graph_base_off(gr));
1908
	if ( n == LINK_NONE ) {
1956
		if (n == LINK_NONE) {
1909
	    /* Compile class if necessary */
1957
			/* Compile class if necessary */
1910
	    GRAPH gt = DEREF_graph ( graph_top ( gr ) ) ;
1958
			GRAPH gt = DEREF_graph(graph_top(gr));
1911
	    CLASS_TYPE ct = DEREF_ctype ( graph_head ( gt ) ) ;
1959
			CLASS_TYPE ct = DEREF_ctype(graph_head(gt));
1912
	    IGNORE compile_class ( ct ) ;
1960
			IGNORE compile_class(ct);
1913
	    n = DEREF_ulong ( graph_base_off ( gr ) ) ;
1961
			n = DEREF_ulong(graph_base_off(gr));
1914
	}
1962
		}
1915
	bs = enc_exp_token ( bs, n ) ;
1963
		bs = enc_exp_token(bs, n);
1916
    }
1964
	}
1917
    if ( !IS_NULL_off ( off2 ) ) {
1965
	if (!IS_NULL_off(off2)) {
1918
	if ( IS_off_deriv ( off2 ) ) {
1966
		if (IS_off_deriv(off2)) {
1919
	    OFFSET off3 = DEREF_off ( off_deriv_direct ( off2 ) ) ;
1967
			OFFSET off3 = DEREF_off(off_deriv_direct(off2));
1920
	    OFFSET off4 = DEREF_off ( off_deriv_indirect ( off2 ) ) ;
1968
			OFFSET off4 = DEREF_off(off_deriv_indirect(off2));
1921
	    bs = enc_end_base ( bs, off3, off4 ) ;
1969
			bs = enc_end_base(bs, off3, off4);
1922
	} else {
1970
		} else {
1923
	    bs = enc_end_base ( bs, off2, NULL_off ) ;
1971
			bs = enc_end_base(bs, off2, NULL_off);
1924
	}
1972
		}
1925
    }
1973
	}
1926
    return ( bs ) ;
1974
	return (bs);
1927
}
1975
}
1928
 
1976
 
1929
 
1977
 
1930
/*
1978
/*
1931
    ENCODE A MEMBER OFFSET
1979
    ENCODE A MEMBER OFFSET
1932
 
1980
 
1933
    This routine adds the offset of the member id to the bitstream bs.
1981
    This routine adds the offset of the member id to the bitstream bs.
1934
    If id is a data member this is the offset of the member from the start
1982
    If id is a data member this is the offset of the member from the start
1935
    of the structure.
1983
    of the structure.
1936
*/
1984
*/
1937
 
1985
 
1938
BITSTREAM *enc_member
1986
BITSTREAM *
1939
    PROTO_N ( ( bs, id ) )
-
 
1940
    PROTO_T ( BITSTREAM *bs X IDENTIFIER id )
1987
enc_member(BITSTREAM *bs, IDENTIFIER id)
1941
{
1988
{
1942
    ulong tok ;
1989
	ulong tok;
1943
    unsigned tag = TAG_id ( id ) ;
1990
	unsigned tag = TAG_id(id);
1944
    if ( tag == id_member_tag ) {
1991
	if (tag == id_member_tag) {
1945
	/* Simple data member */
1992
		/* Simple data member */
1946
	OFFSET off = DEREF_off ( id_member_off ( id ) ) ;
1993
		OFFSET off = DEREF_off(id_member_off(id));
1947
	if ( IS_off_member ( off ) ) {
1994
		if (IS_off_member(off)) {
1948
	    tok = DEREF_ulong ( id_no ( id ) ) ;
1995
			tok = DEREF_ulong(id_no(id));
1949
	    if ( tok == LINK_NONE ) {
1996
			if (tok == LINK_NONE) {
1950
		CLASS_TYPE ct = parent_class ( id ) ;
1997
				CLASS_TYPE ct = parent_class(id);
1951
		IGNORE compile_class ( ct ) ;
1998
				IGNORE compile_class(ct);
1952
		tok = DEREF_ulong ( id_no ( id ) ) ;
1999
				tok = DEREF_ulong(id_no(id));
1953
	    }
2000
			}
1954
	    if ( tok == LINK_ZERO ) {
2001
			if (tok == LINK_ZERO) {
1955
		/* Union member */
2002
				/* Union member */
1956
		TYPE t = DEREF_type ( id_member_type ( id ) ) ;
2003
				TYPE t = DEREF_type(id_member_type(id));
1957
		ENC_offset_zero ( bs ) ;
2004
				ENC_offset_zero(bs);
1958
		bs = enc_alignment ( bs, t ) ;
2005
				bs = enc_alignment(bs, t);
1959
	    } else {
2006
			} else {
1960
		/* Structure member */
2007
				/* Structure member */
1961
		bs = enc_exp_token ( bs, tok ) ;
2008
				bs = enc_exp_token(bs, tok);
1962
	    }
2009
			}
1963
	} else {
2010
		} else {
1964
	    bs = enc_offset ( bs, off ) ;
2011
			bs = enc_offset(bs, off);
1965
	}
2012
		}
1966
    } else {
2013
	} else {
1967
	/* Static data members and member functions */
2014
		/* Static data members and member functions */
1968
	IGNORE capsule_id ( id, VAR_tag ) ;
2015
		IGNORE capsule_id(id, VAR_tag);
1969
	tok = unit_no ( bs, id, VAR_tag, 0 ) ;
2016
		tok = unit_no(bs, id, VAR_tag, 0);
1970
	ENC_obtain_tag ( bs ) ;
2017
		ENC_obtain_tag(bs);
1971
	ENC_make_tag ( bs, tok ) ;
2018
		ENC_make_tag(bs, tok);
1972
    }
2019
	}
1973
    return ( bs ) ;
2020
	return (bs);
1974
}
2021
}
1975
 
2022
 
1976
 
2023
 
1977
/*
2024
/*
1978
    ENCODE A NULL CLASS OBJECT DEFINITION
2025
    ENCODE A NULL CLASS OBJECT DEFINITION
1979
 
2026
 
1980
    This routine adds an expression representing a null value of type
2027
    This routine adds an expression representing a null value of type
1981
    ct to the bitstream bs.  The virtual base components are only
2028
    ct to the bitstream bs.  The virtual base components are only
1982
    included if virt is true.  Note that the order of the components
2029
    included if virt is true.  Note that the order of the components
1983
    is not necessarily the same as that in compile_class, but the
2030
    is not necessarily the same as that in compile_class, but the
1984
    installers always sort make_compound expressions into the correct
2031
    installers always sort make_compound expressions into the correct
1985
    order.
2032
    order.
1986
*/
2033
*/
1987
 
2034
 
1988
static BITSTREAM *enc_null_class_aux
2035
static BITSTREAM *
1989
    PROTO_N ( ( bs, ct, virt ) )
-
 
1990
    PROTO_T ( BITSTREAM *bs X CLASS_TYPE ct X int virt )
2036
enc_null_class_aux(BITSTREAM *bs, CLASS_TYPE ct, int virt)
1991
{
2037
{
1992
    CLASS_INFO ci = DEREF_cinfo ( ctype_info ( ct ) ) ;
2038
	CLASS_INFO ci = DEREF_cinfo(ctype_info(ct));
1993
    if ( ci & ( cinfo_empty | cinfo_token ) ) {
2039
	if (ci & (cinfo_empty | cinfo_token)) {
1994
	/* Tokenised and empty classes */
2040
		/* Tokenised and empty classes */
1995
	ENC_make_value ( bs ) ;
2041
		ENC_make_value(bs);
1996
	bs = enc_ctype ( bs, ct ) ;
2042
		bs = enc_ctype(bs, ct);
1997
    } else {
-
 
1998
	/* Non-empty classes */
-
 
1999
	MEMBER mem ;
-
 
2000
	unsigned no_mems = 0 ;
-
 
2001
	GRAPH gr = DEREF_graph ( ctype_base ( ct ) ) ;
-
 
2002
	LIST ( GRAPH ) br = DEREF_list ( graph_tails ( gr ) ) ;
-
 
2003
	LIST ( GRAPH ) bv = DEREF_list ( ctype_vbase ( ct ) ) ;
-
 
2004
	NAMESPACE ns = DEREF_nspace ( ctype_member ( ct ) ) ;
-
 
2005
	BITSTREAM *ts = start_bitstream ( NIL ( FILE ), bs->link ) ;
-
 
2006
 
-
 
2007
	/* Scan through direct base classes */
-
 
2008
	while ( !IS_NULL_list ( br ) ) {
-
 
2009
	    GRAPH gs = DEREF_graph ( HEAD_list ( br ) ) ;
-
 
2010
	    DECL_SPEC acc = DEREF_dspec ( graph_access ( gs ) ) ;
-
 
2011
	    CLASS_TYPE cs = DEREF_ctype ( graph_head ( gs ) ) ;
-
 
2012
	    ulong m = DEREF_ulong ( graph_base_off ( gs ) ) ;
-
 
2013
	    if ( acc & dspec_virtual ) {
-
 
2014
		ts = enc_exp_token ( ts, m ) ;
-
 
2015
		ENC_make_null_ptr ( ts ) ;
-
 
2016
		ts = enc_al_ctype ( ts, cs ) ;
-
 
2017
		no_mems++ ;
-
 
2018
	    } else {
-
 
2019
		CLASS_INFO cj = DEREF_cinfo ( ctype_info ( cs ) ) ;
-
 
2020
		if ( !( cj & cinfo_empty ) ) {
-
 
2021
		    ts = enc_exp_token ( ts, m ) ;
-
 
2022
		    ts = enc_null_class_aux ( ts, cs, 0 ) ;
-
 
2023
		    no_mems++ ;
-
 
2024
		}
-
 
2025
	    }
-
 
2026
	    br = TAIL_list ( br ) ;
-
 
2027
	}
-
 
2028
 
-
 
2029
	/* Scan through data members */
-
 
2030
	mem = DEREF_member ( nspace_ctype_first ( ns ) ) ;
-
 
2031
	mem = next_data_member ( mem, 0 ) ;
-
 
2032
	while ( !IS_NULL_member ( mem ) ) {
-
 
2033
	    IDENTIFIER mid = DEREF_id ( member_id ( mem ) ) ;
-
 
2034
	    TYPE s = DEREF_type ( id_member_type ( mid ) ) ;
-
 
2035
	    ts = enc_member ( ts, mid ) ;
-
 
2036
	    ts = enc_null_exp ( ts, s ) ;
-
 
2037
	    no_mems++ ;
-
 
2038
	    if ( ci & cinfo_union ) break ;
-
 
2039
	    mem = DEREF_member ( member_next ( mem ) ) ;
-
 
2040
	    mem = next_data_member ( mem, 0 ) ;
-
 
2041
	}
-
 
2042
 
-
 
2043
	/* Scan through virtual function tables */
-
 
2044
#if LANGUAGE_CPP
-
 
2045
	if ( ci & cinfo_polymorphic ) {
-
 
2046
	    VIRTUAL vt = DEREF_virt ( ctype_virt ( ct ) ) ;
-
 
2047
	    while ( !IS_NULL_virt ( vt ) ) {
-
 
2048
		OFFSET off = DEREF_off ( virt_table_off ( vt ) ) ;
-
 
2049
		if ( IS_NULL_off ( off ) ) {
-
 
2050
		    ulong m = DEREF_ulong ( virt_table_tok ( vt ) ) ;
-
 
2051
		    ts = enc_exp_token ( ts, m ) ;
-
 
2052
		    size_dummy_vtab = DEREF_ulong ( virt_no ( vt ) ) ;
-
 
2053
		    ts = enc_null_exp ( ts, ptr_dummy_vtab ) ;
-
 
2054
		    no_mems++ ;
-
 
2055
		}
-
 
2056
		vt = DEREF_virt ( virt_next ( vt ) ) ;
-
 
2057
	    }
-
 
2058
	}
-
 
2059
#endif
-
 
2060
 
-
 
2061
	/* Scan through virtual bases */
-
 
2062
	if ( virt ) {
-
 
2063
	    while ( !IS_NULL_list ( bv ) ) {
-
 
2064
		GRAPH gs = DEREF_graph ( HEAD_list ( bv ) ) ;
-
 
2065
		CLASS_TYPE cs = DEREF_ctype ( graph_head ( gs ) ) ;
-
 
2066
		CLASS_INFO cj = DEREF_cinfo ( ctype_info ( cs ) ) ;
-
 
2067
		if ( !( cj & cinfo_empty ) ) {
-
 
2068
		    ulong m = DEREF_ulong ( graph_real_off ( gs ) ) ;
-
 
2069
		    ts = enc_exp_token ( ts, m ) ;
-
 
2070
		    ts = enc_null_class_aux ( ts, cs, 0 ) ;
-
 
2071
		    no_mems++ ;
-
 
2072
		}
-
 
2073
		bv = TAIL_list ( bv ) ;
-
 
2074
	    }
-
 
2075
	} else {
2043
	} else {
-
 
2044
		/* Non-empty classes */
-
 
2045
		MEMBER mem;
-
 
2046
		unsigned no_mems = 0;
-
 
2047
		GRAPH gr = DEREF_graph(ctype_base(ct));
-
 
2048
		LIST(GRAPH)br = DEREF_list(graph_tails(gr));
-
 
2049
		LIST(GRAPH)bv = DEREF_list(ctype_vbase(ct));
-
 
2050
		NAMESPACE ns = DEREF_nspace(ctype_member(ct));
-
 
2051
		BITSTREAM *ts = start_bitstream(NIL(FILE), bs->link);
-
 
2052
 
-
 
2053
		/* Scan through direct base classes */
2076
	    if ( IS_NULL_list ( bv ) ) virt = 1 ;
2054
		while (!IS_NULL_list(br)) {
-
 
2055
			GRAPH gs = DEREF_graph(HEAD_list(br));
-
 
2056
			DECL_SPEC acc = DEREF_dspec(graph_access(gs));
-
 
2057
			CLASS_TYPE cs = DEREF_ctype(graph_head(gs));
-
 
2058
			ulong m = DEREF_ulong(graph_base_off(gs));
-
 
2059
			if (acc & dspec_virtual) {
-
 
2060
				ts = enc_exp_token(ts, m);
-
 
2061
				ENC_make_null_ptr(ts);
-
 
2062
				ts = enc_al_ctype(ts, cs);
-
 
2063
				no_mems++;
-
 
2064
			} else {
-
 
2065
				CLASS_INFO cj = DEREF_cinfo(ctype_info(cs));
-
 
2066
				if (!(cj & cinfo_empty)) {
-
 
2067
					ts = enc_exp_token(ts, m);
-
 
2068
					ts = enc_null_class_aux(ts, cs, 0);
-
 
2069
					no_mems++;
-
 
2070
				}
-
 
2071
			}
-
 
2072
			br = TAIL_list(br);
2077
	}
2073
		}
2078
 
2074
 
2079
	/* Encode complete construct */
2075
		/* Scan through data members */
-
 
2076
		mem = DEREF_member(nspace_ctype_first(ns));
-
 
2077
		mem = next_data_member(mem, 0);
-
 
2078
		while (!IS_NULL_member(mem)) {
-
 
2079
			IDENTIFIER mid = DEREF_id(member_id(mem));
-
 
2080
			TYPE s = DEREF_type(id_member_type(mid));
-
 
2081
			ts = enc_member(ts, mid);
-
 
2082
			ts = enc_null_exp(ts, s);
2080
	if ( no_mems ) {
2083
			no_mems++;
-
 
2084
			if (ci & cinfo_union) {
-
 
2085
				break;
-
 
2086
			}
-
 
2087
			mem = DEREF_member(member_next(mem));
-
 
2088
			mem = next_data_member(mem, 0);
-
 
2089
		}
-
 
2090
 
-
 
2091
		/* Scan through virtual function tables */
-
 
2092
#if LANGUAGE_CPP
2081
	    ENC_make_compound ( bs ) ;
2093
		if (ci & cinfo_polymorphic) {
-
 
2094
			VIRTUAL vt = DEREF_virt(ctype_virt(ct));
2082
	    if ( virt ) {
2095
			while (!IS_NULL_virt(vt)) {
-
 
2096
				OFFSET off = DEREF_off(virt_table_off(vt));
2083
		ENC_shape_offset ( bs ) ;
2097
				if (IS_NULL_off(off)) {
-
 
2098
					ulong m =
-
 
2099
					    DEREF_ulong(virt_table_tok(vt));
2084
		bs = enc_ctype ( bs, ct ) ;
2100
					ts = enc_exp_token(ts, m);
-
 
2101
					size_dummy_vtab =
-
 
2102
					    DEREF_ulong(virt_no(vt));
-
 
2103
					ts = enc_null_exp(ts, ptr_dummy_vtab);
-
 
2104
					no_mems++;
-
 
2105
				}
-
 
2106
				vt = DEREF_virt(virt_next(vt));
-
 
2107
			}
-
 
2108
		}
-
 
2109
#endif
-
 
2110
 
-
 
2111
		/* Scan through virtual bases */
2085
	    } else {
2112
		if (virt) {
-
 
2113
			while (!IS_NULL_list(bv)) {
2086
		ulong m = DEREF_ulong ( graph_core_off ( gr ) ) ;
2114
				GRAPH gs = DEREF_graph(HEAD_list(bv));
-
 
2115
				CLASS_TYPE cs = DEREF_ctype(graph_head(gs));
-
 
2116
				CLASS_INFO cj = DEREF_cinfo(ctype_info(cs));
2087
		if ( m == LINK_NONE ) {
2117
				if (!(cj & cinfo_empty)) {
-
 
2118
					ulong m =
2088
		    ENC_shape_offset ( bs ) ;
2119
					    DEREF_ulong(graph_real_off(gs));
2089
		    bs = enc_ctype ( bs, ct ) ;
2120
					ts = enc_exp_token(ts, m);
-
 
2121
					ts = enc_null_class_aux(ts, cs, 0);
-
 
2122
					no_mems++;
-
 
2123
				}
-
 
2124
				bv = TAIL_list(bv);
-
 
2125
			}
2090
		} else {
2126
		} else {
2091
		    bs = enc_exp_token ( bs, m ) ;
2127
			if (IS_NULL_list(bv)) {
-
 
2128
				virt = 1;
-
 
2129
			}
2092
		}
2130
		}
-
 
2131
 
-
 
2132
		/* Encode complete construct */
-
 
2133
		if (no_mems) {
-
 
2134
			ENC_make_compound(bs);
-
 
2135
			if (virt) {
-
 
2136
				ENC_shape_offset(bs);
-
 
2137
				bs = enc_ctype(bs, ct);
-
 
2138
			} else {
-
 
2139
				ulong m = DEREF_ulong(graph_core_off(gr));
-
 
2140
				if (m == LINK_NONE) {
-
 
2141
					ENC_shape_offset(bs);
-
 
2142
					bs = enc_ctype(bs, ct);
-
 
2143
				} else {
-
 
2144
					bs = enc_exp_token(bs, m);
2093
	    }
2145
				}
-
 
2146
			}
2094
	    ENC_LIST ( bs, no_mems + no_mems ) ;
2147
			ENC_LIST(bs, no_mems + no_mems);
2095
	    bs = join_bitstreams ( bs, ts ) ;
2148
			bs = join_bitstreams(bs, ts);
2096
	} else {
2149
		} else {
2097
	    ENC_make_value ( bs ) ;
2150
			ENC_make_value(bs);
2098
	    bs = enc_ctype ( bs, ct ) ;
2151
			bs = enc_ctype(bs, ct);
2099
	    end_bitstream ( ts, 0 ) ;
2152
			end_bitstream(ts, 0);
2100
	}
2153
		}
2101
    }
2154
	}
2102
    return ( bs ) ;
2155
	return (bs);
2103
}
2156
}
2104
 
2157
 
2105
 
2158
 
2106
/*
2159
/*
2107
    ENCODE A NULL CLASS OBJECT
2160
    ENCODE A NULL CLASS OBJECT
2108
 
2161
 
2109
    This routine adds the default null value for the class type ct to the
2162
    This routine adds the default null value for the class type ct to the
2110
    bitstream bs.  This is represented by a token which is defined the
2163
    bitstream bs.  This is represented by a token which is defined the
2111
    first time the routine is called.
2164
    first time the routine is called.
2112
*/
2165
*/
2113
 
2166
 
2114
BITSTREAM *enc_null_class
2167
BITSTREAM *
2115
    PROTO_N ( ( bs, ct ) )
-
 
2116
    PROTO_T ( BITSTREAM *bs X CLASS_TYPE ct )
2168
enc_null_class(BITSTREAM *bs, CLASS_TYPE ct)
2117
{
2169
{
2118
    ulong n = DEREF_ulong ( ctype_null_exp ( ct ) ) ;
2170
	ulong n = DEREF_ulong(ctype_null_exp(ct));
2119
    if ( n == LINK_NONE ) {
2171
	if (n == LINK_NONE) {
2120
	/* Define token for null value */
2172
		/* Define token for null value */
2121
	BITSTREAM *ts ;
2173
		BITSTREAM *ts;
2122
	string s = NULL ;
2174
		string s = NULL;
2123
	IGNORE compile_class ( ct ) ;
2175
		IGNORE compile_class(ct);
-
 
2176
		if (output_all) {
2124
	if ( output_all ) s = mangle_typeid ( "~cpp.null.", ct ) ;
2177
			s = mangle_typeid("~cpp.null.", ct);
-
 
2178
		}
2125
	n = capsule_no ( s, VAR_token ) ;
2179
		n = capsule_no(s, VAR_token);
2126
	COPY_ulong ( ctype_null_exp ( ct ), n ) ;
2180
		COPY_ulong(ctype_null_exp(ct), n);
2127
	ts = enc_tokdef_start ( n, "E", NIL ( ulong ), 1 ) ;
2181
		ts = enc_tokdef_start(n, "E", NIL(ulong), 1);
2128
	ts = enc_null_class_aux ( ts, ct, 1 ) ;
2182
		ts = enc_null_class_aux(ts, ct, 1);
2129
	enc_tokdef_end ( n, ts ) ;
2183
		enc_tokdef_end(n, ts);
2130
    }
2184
	}
2131
    bs = enc_exp_token ( bs, n ) ;
2185
	bs = enc_exp_token(bs, n);
2132
    return ( bs ) ;
2186
	return (bs);
2133
}
2187
}
2134
 
2188
 
2135
 
2189
 
2136
/*
2190
/*
2137
    CONSTRUCTOR INITIALISER ROUTINES
2191
    CONSTRUCTOR INITIALISER ROUTINES
2138
 
2192
 
2139
    The constructor initialiser routines are only included in the C++
2193
    The constructor initialiser routines are only included in the C++
2140
    producer.
2194
    producer.
2141
*/
2195
*/
2142
 
2196
 
2143
#if LANGUAGE_CPP
2197
#if LANGUAGE_CPP
2144
 
2198
 
2145
 
2199
 
2146
/*
2200
/*
2147
    ENCODE A CONSTRUCTOR INITIALISER
2201
    ENCODE A CONSTRUCTOR INITIALISER
2148
 
2202
 
2149
    This routine performs a construct initialisation using a at offset
2203
    This routine performs a construct initialisation using a at offset
2150
    off from the tag m.  virt controls how m is accessed.  Note that a
2204
    off from the tag m.  virt controls how m is accessed.  Note that a
2151
    may be a dummy expression to indicate that m is initialised from
2205
    may be a dummy expression to indicate that m is initialised from
2152
    the corresponding offset from the second argument in a copy
2206
    the corresponding offset from the second argument in a copy
2153
    constructor or assignment operator (see init_empty_base).
2207
    constructor or assignment operator (see init_empty_base).
2154
*/
2208
*/
2155
 
2209
 
2156
static BITSTREAM *enc_ctor_exp
2210
static BITSTREAM *
2157
    PROTO_N ( ( bs, a, off, m, virt, seq ) )
-
 
2158
    PROTO_T ( BITSTREAM *bs X EXP a X OFFSET off X ulong m X
2211
enc_ctor_exp(BITSTREAM *bs, EXP a, OFFSET off, ulong m, int virt, unsigned seq)
2159
	      int virt X unsigned seq )
-
 
2160
{
2212
{
2161
    if ( !IS_NULL_exp ( a ) ) {
2213
	if (!IS_NULL_exp(a)) {
2162
	int context = 0 ;
2214
		int context = 0;
2163
	EXP d = NULL_exp ;
2215
		EXP d = NULL_exp;
2164
	TYPE s = DEREF_type ( exp_type ( a ) ) ;
2216
		TYPE s = DEREF_type(exp_type(a));
2165
	if ( IS_exp_paren ( a ) ) {
2217
		if (IS_exp_paren(a)) {
2166
	    /* Used to mark destructors - see destr_init */
2218
			/* Used to mark destructors - see destr_init */
2167
	    if ( seq > 1 ) {
2219
			if (seq > 1) {
2168
		context = 5 ;
2220
				context = 5;
2169
		d = a ;
2221
				d = a;
2170
	    }
2222
			}
2171
	    a = DEREF_exp ( exp_paren_arg ( a ) ) ;
2223
			a = DEREF_exp(exp_paren_arg(a));
2172
	}
2224
		}
2173
	if ( IS_NULL_exp ( a ) ) {
2225
		if (IS_NULL_exp(a)) {
2174
	    /* EMPTY */
2226
			/* EMPTY */
2175
	} else if ( IS_exp_value ( a ) ) {
2227
		} else if (IS_exp_value(a)) {
2176
	    /* Copy assignment */
2228
			/* Copy assignment */
2177
	    int bf = 0 ;
2229
			int bf = 0;
2178
	    TYPE t = DEREF_type ( exp_type ( a ) ) ;
2230
			TYPE t = DEREF_type(exp_type(a));
2179
	    bs = enc_assign_op ( bs, t, &bf ) ;
2231
			bs = enc_assign_op(bs, t, &bf);
2180
	    if ( bf ) {
2232
			if (bf) {
2181
		/* Bitfield assignment */
2233
				/* Bitfield assignment */
2182
		OFFSET off1 = off ;
2234
				OFFSET off1 = off;
2183
		OFFSET off2 = decons_bitf_off ( &off1 ) ;
2235
				OFFSET off2 = decons_bitf_off(&off1);
2184
		bs = enc_dummy_exp ( bs, t, m, off1, 0, virt ) ;
2236
				bs = enc_dummy_exp(bs, t, m, off1, 0, virt);
2185
		bs = enc_offset ( bs, off2 ) ;
2237
				bs = enc_offset(bs, off2);
2186
	    } else {
2238
			} else {
2187
		/* Non-bitfield assignment */
2239
				/* Non-bitfield assignment */
2188
		bs = enc_dummy_exp ( bs, t, m, off, 0, virt ) ;
2240
				bs = enc_dummy_exp(bs, t, m, off, 0, virt);
2189
	    }
2241
			}
2190
	    last_conts [ DUMMY_copy ] = 1 ;
2242
			last_conts[DUMMY_copy] = 1;
2191
	    bs = enc_dummy_exp ( bs, t, LINK_NONE, off, DUMMY_copy, 1 ) ;
2243
			bs = enc_dummy_exp(bs, t, LINK_NONE, off, DUMMY_copy, 1);
2192
	    last_conts [ DUMMY_copy ] = 0 ;
2244
			last_conts[DUMMY_copy] = 0;
2193
	    seq-- ;
2245
			seq--;
2194
	} else {
2246
		} else {
2195
	    /* Constructor initialiser */
2247
			/* Constructor initialiser */
2196
	    bs = enc_init_tag ( bs, m, off, 0, s, a, d, context ) ;
2248
			bs = enc_init_tag(bs, m, off, 0, s, a, d, context);
2197
	    if ( !IS_NULL_exp ( d ) ) {
2249
			if (!IS_NULL_exp(d)) {
2198
		d = NULL_exp ;
2250
				d = NULL_exp;
2199
		seq-- ;
2251
				seq--;
2200
	    }
2252
			}
2201
	    seq-- ;
2253
			seq--;
2202
	}
2254
		}
2203
	if ( !IS_NULL_exp ( d ) ) {
2255
		if (!IS_NULL_exp(d)) {
2204
	    /* Increase constructor count */
2256
			/* Increase constructor count */
2205
	    bs = enc_destr_count ( bs, s, 1 ) ;
2257
			bs = enc_destr_count(bs, s, 1);
2206
	    seq-- ;
2258
			seq--;
-
 
2259
		}
2207
	}
2260
	}
2208
    }
-
 
2209
    while ( seq ) {
2261
	while (seq) {
2210
	ENC_make_top ( bs ) ;
2262
		ENC_make_top(bs);
2211
	seq-- ;
2263
		seq--;
2212
    }
2264
	}
2213
    return ( bs ) ;
2265
	return (bs);
2214
}
2266
}
2215
 
2267
 
2216
 
2268
 
2217
/*
2269
/*
2218
    INITIALISE VIRTUAL BASE POINTERS
2270
    INITIALISE VIRTUAL BASE POINTERS
2219
 
2271
 
2220
    This routine adds a list of virtual base pointer initialisations
2272
    This routine adds a list of virtual base pointer initialisations
2221
    for an object with tag number m and class ct to the bitstream bs.
2273
    for an object with tag number m and class ct to the bitstream bs.
2222
*/
2274
*/
2223
 
2275
 
2224
static BITSTREAM *enc_virt_init
2276
static BITSTREAM *
2225
    PROTO_N ( ( bs, ct, m ) )
-
 
2226
    PROTO_T ( BITSTREAM *bs X CLASS_TYPE ct X ulong m )
2277
enc_virt_init(BITSTREAM *bs, CLASS_TYPE ct, ulong m)
2227
{
2278
{
2228
    LIST ( GRAPH ) bv = DEREF_list ( ctype_vbase ( ct ) ) ;
2279
	LIST(GRAPH)bv = DEREF_list(ctype_vbase(ct));
2229
    while ( !IS_NULL_list ( bv ) ) {
2280
	while (!IS_NULL_list(bv)) {
2230
	GRAPH gr = DEREF_graph ( HEAD_list ( bv ) ) ;
2281
		GRAPH gr = DEREF_graph(HEAD_list(bv));
2231
	ulong tv = DEREF_ulong ( graph_real_off ( gr ) ) ;
2282
		ulong tv = DEREF_ulong(graph_real_off(gr));
2232
	while ( !IS_NULL_graph ( gr ) ) {
2283
		while (!IS_NULL_graph(gr)) {
2233
	    ulong tp = compile_base ( gr, 1 ) ;
2284
			ulong tp = compile_base(gr, 1);
2234
	    ENC_assign ( bs ) ;
2285
			ENC_assign(bs);
2235
	    ENC_add_to_ptr ( bs ) ;
2286
			ENC_add_to_ptr(bs);
2236
	    ENC_obtain_tag ( bs ) ;
2287
			ENC_obtain_tag(bs);
2237
	    ENC_make_tag ( bs, m ) ;
2288
			ENC_make_tag(bs, m);
2238
	    bs = enc_exp_token ( bs, tp ) ;
2289
			bs = enc_exp_token(bs, tp);
2239
	    ENC_add_to_ptr ( bs ) ;
2290
			ENC_add_to_ptr(bs);
2240
	    ENC_obtain_tag ( bs ) ;
2291
			ENC_obtain_tag(bs);
2241
	    ENC_make_tag ( bs, m ) ;
2292
			ENC_make_tag(bs, m);
2242
	    bs = enc_exp_token ( bs, tv ) ;
2293
			bs = enc_exp_token(bs, tv);
2243
	    gr = DEREF_graph ( graph_equal ( gr ) ) ;
2294
			gr = DEREF_graph(graph_equal(gr));
-
 
2295
		}
-
 
2296
		bv = TAIL_list(bv);
2244
	}
2297
	}
2245
	bv = TAIL_list ( bv ) ;
-
 
2246
    }
-
 
2247
    return ( bs ) ;
2298
	return (bs);
2248
}
2299
}
2249
 
2300
 
2250
 
2301
 
2251
/*
2302
/*
2252
    INITIALISE VIRTUAL FUNCTION TABLES
2303
    INITIALISE VIRTUAL FUNCTION TABLES
2253
 
2304
 
2254
    This routine adds a list of virtual function table initialisations
2305
    This routine adds a list of virtual function table initialisations
2255
    for an object with tag number m and class ct to the bitstream bs.
2306
    for an object with tag number m and class ct to the bitstream bs.
2256
*/
2307
*/
2257
 
2308
 
2258
static BITSTREAM *enc_vtab_init
2309
static BITSTREAM *
2259
    PROTO_N ( ( bs, ct, m, virt ) )
-
 
2260
    PROTO_T ( BITSTREAM *bs X CLASS_TYPE ct X ulong m X int virt )
2310
enc_vtab_init(BITSTREAM *bs, CLASS_TYPE ct, ulong m, int virt)
2261
{
2311
{
2262
    VIRTUAL vt = DEREF_virt ( ctype_virt ( ct ) ) ;
2312
	VIRTUAL vt = DEREF_virt(ctype_virt(ct));
2263
    while ( !IS_NULL_virt ( vt ) ) {
2313
	while (!IS_NULL_virt(vt)) {
2264
	OFFSET off = DEREF_off ( virt_table_off ( vt ) ) ;
2314
		OFFSET off = DEREF_off(virt_table_off(vt));
2265
	ulong tv = DEREF_ulong ( virt_table_tok ( vt ) ) ;
2315
		ulong tv = DEREF_ulong(virt_table_tok(vt));
2266
	ulong tt = DEREF_ulong ( virt_table_tbl ( vt ) ) ;
2316
		ulong tt = DEREF_ulong(virt_table_tbl(vt));
2267
	record_usage ( tt, VAR_tag, USAGE_USE ) ;
2317
		record_usage(tt, VAR_tag, USAGE_USE);
2268
	ENC_assign ( bs ) ;
2318
		ENC_assign(bs);
2269
	ENC_add_to_ptr ( bs ) ;
2319
		ENC_add_to_ptr(bs);
2270
	if ( is_zero_offset ( off ) ) {
2320
		if (is_zero_offset(off)) {
2271
	    ENC_obtain_tag ( bs ) ;
2321
			ENC_obtain_tag(bs);
2272
	    ENC_make_tag ( bs, m ) ;
2322
			ENC_make_tag(bs, m);
2273
	} else {
2323
		} else {
2274
	    TYPE t = ptr_dummy_class ;
2324
			TYPE t = ptr_dummy_class;
2275
	    bs = enc_dummy_exp ( bs, t, m, off, 0, virt ) ;
2325
			bs = enc_dummy_exp(bs, t, m, off, 0, virt);
-
 
2326
		}
-
 
2327
		bs = enc_exp_token(bs, tv);
-
 
2328
		tt = link_no(bs, tt, VAR_tag);
-
 
2329
		ENC_obtain_tag(bs);
-
 
2330
		ENC_make_tag(bs, tt);
-
 
2331
		vt = DEREF_virt(virt_next(vt));
2276
	}
2332
	}
2277
	bs = enc_exp_token ( bs, tv ) ;
-
 
2278
	tt = link_no ( bs, tt, VAR_tag ) ;
-
 
2279
	ENC_obtain_tag ( bs ) ;
-
 
2280
	ENC_make_tag ( bs, tt ) ;
-
 
2281
	vt = DEREF_virt ( virt_next ( vt ) ) ;
-
 
2282
    }
-
 
2283
    return ( bs ) ;
2333
	return (bs);
2284
}
2334
}
2285
 
2335
 
2286
 
2336
 
2287
/*
2337
/*
2288
    DELETE AN OBJECT
2338
    DELETE AN OBJECT
2289
 
2339
 
2290
    This routine adds the conditional deletion for an object with tag
2340
    This routine adds the conditional deletion for an object with tag
2291
    number m and class ct to the bitstream bs.
2341
    number m and class ct to the bitstream bs.
2292
*/
2342
*/
2293
 
2343
 
2294
static BITSTREAM *enc_delete_obj
2344
static BITSTREAM *
2295
    PROTO_N ( ( bs, ct, m ) )
-
 
2296
    PROTO_T ( BITSTREAM *bs X CLASS_TYPE ct X ulong m )
2345
enc_delete_obj(BITSTREAM *bs, CLASS_TYPE ct, ulong m)
2297
{
2346
{
2298
    IDENTIFIER cid = DEREF_id ( ctype_name ( ct ) ) ;
2347
	IDENTIFIER cid = DEREF_id(ctype_name(ct));
2299
    TYPE t = DEREF_type ( id_class_name_etc_defn ( cid ) ) ;
2348
	TYPE t = DEREF_type(id_class_name_etc_defn(cid));
2300
    IDENTIFIER fid = find_allocator ( t, lex_delete, 0, NULL_id ) ;
2349
	IDENTIFIER fid = find_allocator(t, lex_delete, 0, NULL_id);
2301
    if ( IS_NULL_id ( fid ) ) {
2350
	if (IS_NULL_id(fid)) {
2302
	/* This shouldn't happen */
2351
		/* This shouldn't happen */
2303
	ENC_make_top ( bs ) ;
2352
		ENC_make_top(bs);
2304
    } else {
2353
	} else {
2305
	ulong d ;
2354
		ulong d;
2306
	BITSTREAM *ts ;
2355
		BITSTREAM *ts;
2307
	TYPE fn = DEREF_type ( id_function_etc_type ( fid ) ) ;
2356
		TYPE fn = DEREF_type(id_function_etc_type(fid));
2308
	LIST ( TYPE ) ptypes = DEREF_list ( type_func_ptypes ( fn ) ) ;
2357
		LIST(TYPE)ptypes = DEREF_list(type_func_ptypes(fn));
2309
	unsigned npids = LENGTH_list ( ptypes ) ;
2358
		unsigned npids = LENGTH_list(ptypes);
2310
 
2359
 
2311
	/* Mark the function as to be compiled */
2360
		/* Mark the function as to be compiled */
2312
	IGNORE capsule_id ( fid, VAR_tag ) ;
2361
		IGNORE capsule_id(fid, VAR_tag);
2313
	CONS_id ( fid, pending_funcs, pending_funcs ) ;
2362
		CONS_id(fid, pending_funcs, pending_funcs);
2314
 
2363
 
2315
	/* Encode the function call */
2364
		/* Encode the function call */
2316
	ENC_apply_proc ( bs ) ;
2365
		ENC_apply_proc(bs);
2317
	ENC_top ( bs ) ;
2366
		ENC_top(bs);
2318
	ENC_obtain_tag ( bs ) ;
2367
		ENC_obtain_tag(bs);
2319
	d = unit_no ( bs, fid, VAR_tag, 0 ) ;
2368
		d = unit_no(bs, fid, VAR_tag, 0);
2320
	ENC_make_tag ( bs, d ) ;
2369
		ENC_make_tag(bs, d);
2321
	if ( npids > 2 ) npids = 2 ;
2370
		if (npids > 2) {
-
 
2371
			npids = 2;
-
 
2372
		}
2322
	ENC_LIST_SMALL ( bs, npids ) ;
2373
		ENC_LIST_SMALL(bs, npids);
2323
	bs = enc_special ( bs, TOK_to_ptr_void ) ;
2374
		bs = enc_special(bs, TOK_to_ptr_void);
2324
	ts = start_bitstream ( NIL ( FILE ), bs->link ) ;
2375
		ts = start_bitstream(NIL(FILE), bs->link);
2325
	ts = enc_al_ctype ( ts, ct ) ;
2376
		ts = enc_al_ctype(ts, ct);
2326
	ENC_obtain_tag ( ts ) ;
2377
		ENC_obtain_tag(ts);
2327
	ENC_make_tag ( ts, m ) ;
2378
		ENC_make_tag(ts, m);
2328
	bs = enc_bitstream ( bs, ts ) ;
2379
		bs = enc_bitstream(bs, ts);
2329
	if ( npids == 2 ) {
2380
		if (npids == 2) {
2330
	    /* Allow for second argument */
2381
			/* Allow for second argument */
2331
	    TYPE s ;
2382
			TYPE s;
2332
	    TYPE c = type_char ;
2383
			TYPE c = type_char;
2333
	    ptypes = TAIL_list ( ptypes ) ;
2384
			ptypes = TAIL_list(ptypes);
2334
	    s = DEREF_type ( HEAD_list ( ptypes ) ) ;
2385
			s = DEREF_type(HEAD_list(ptypes));
2335
	    if ( !IS_type_integer ( s ) ) s = type_size_t ;
2386
			if (!IS_type_integer(s)) {
-
 
2387
				s = type_size_t;
-
 
2388
			}
2336
	    ENC_offset_div ( bs ) ;
2389
			ENC_offset_div(bs);
2337
	    bs = enc_variety ( bs, s ) ;
2390
			bs = enc_variety(bs, s);
2338
	    bs = enc_shape_offset ( bs, t ) ;
2391
			bs = enc_shape_offset(bs, t);
2339
	    bs = enc_shape_offset ( bs, c ) ;
2392
			bs = enc_shape_offset(bs, c);
-
 
2393
		}
-
 
2394
		ENC_OFF(bs);
2340
	}
2395
	}
2341
	ENC_OFF ( bs ) ;
-
 
2342
    }
-
 
2343
    return ( bs ) ;
2396
	return (bs);
2344
}
2397
}
2345
 
2398
 
2346
 
2399
 
2347
/*
2400
/*
2348
    ENCODE A LIST OF CONSTRUCTOR INITIALISERS
2401
    ENCODE A LIST OF CONSTRUCTOR INITIALISERS
2349
 
2402
 
2350
    This routine adds the list of constructor initialisers given by e
2403
    This routine adds the list of constructor initialisers given by e
2351
    to the bitstream bs.
2404
    to the bitstream bs.
2352
*/
2405
*/
2353
 
2406
 
2354
BITSTREAM *enc_ctor_init
2407
BITSTREAM *
2355
    PROTO_N ( ( bs, e ) )
-
 
2356
    PROTO_T ( BITSTREAM *bs X EXP e )
2408
enc_ctor_init(BITSTREAM *bs, EXP e)
2357
{
2409
{
2358
    ulong n, m ;
2410
	ulong n, m;
2359
    CLASS_TYPE ct = last_class ;
2411
	CLASS_TYPE ct = last_class;
2360
    int kind = DEREF_int ( exp_initialiser_kind ( e ) ) ;
2412
	int kind = DEREF_int(exp_initialiser_kind(e));
2361
    LIST ( EXP ) p = DEREF_list ( exp_initialiser_args ( e ) ) ;
2413
	LIST(EXP)p = DEREF_list(exp_initialiser_args(e));
2362
    LIST ( OFFSET ) q = DEREF_list ( exp_initialiser_offs ( e ) ) ;
2414
	LIST(OFFSET)q = DEREF_list(exp_initialiser_offs(e));
2363
 
-
 
2364
    /* Find number of items */
-
 
2365
    unsigned np = LENGTH_list ( p ) ;
-
 
2366
    unsigned nv = DEREF_unsigned ( exp_initialiser_virt ( e ) ) ;
-
 
2367
    unsigned nb = DEREF_unsigned ( exp_initialiser_base ( e ) ) ;
-
 
2368
    unsigned no = np - nv ;
-
 
2369
 
2415
 
-
 
2416
	/* Find number of items */
-
 
2417
	unsigned np = LENGTH_list(p);
-
 
2418
	unsigned nv = DEREF_unsigned(exp_initialiser_virt(e));
-
 
2419
	unsigned nb = DEREF_unsigned(exp_initialiser_base(e));
-
 
2420
	unsigned no = np - nv;
-
 
2421
 
2370
    /* Compile the class */
2422
	/* Compile the class */
2371
    IGNORE compile_class ( ct ) ;
2423
	IGNORE compile_class(ct);
-
 
2424
 
-
 
2425
	/* Find the 'this' pointer */
-
 
2426
	n = last_params[DUMMY_this];
-
 
2427
	m = unit_no(bs, NULL_id, VAR_tag, 1);
-
 
2428
	ENC_identify(bs);
-
 
2429
	bs = enc_access(bs, crt_func_access);
-
 
2430
	ENC_make_tag(bs, m);
-
 
2431
	ENC_contents(bs);
-
 
2432
	ENC_pointer(bs);
-
 
2433
	bs = enc_al_ctype(bs, ct);
-
 
2434
	ENC_obtain_tag(bs);
-
 
2435
	ENC_make_tag(bs, n);
-
 
2436
 
-
 
2437
	if (kind == DEFAULT_DESTR) {
-
 
2438
		/* Deal with destructors */
-
 
2439
		int context = 0;
-
 
2440
		unsigned ns = no + 1;
-
 
2441
		ulong m2 = last_params[DUMMY_extra];
-
 
2442
		if (last_params[DUMMY_count] != LINK_NONE) {
-
 
2443
			context = 5;
-
 
2444
			ns--;
-
 
2445
		}
-
 
2446
		if (nv) {
-
 
2447
			ns++;
-
 
2448
		}
-
 
2449
		if (ns > 1) {
-
 
2450
			ENC_SEQUENCE(bs, ns - 1);
-
 
2451
		} else {
-
 
2452
			if (ns == 0) {
-
 
2453
				ENC_make_top(bs);
-
 
2454
			}
-
 
2455
		}
-
 
2456
 
-
 
2457
		/* Destroy members and direct bases */
-
 
2458
		while (no) {
-
 
2459
			EXP a = DEREF_exp(HEAD_list(p));
-
 
2460
			if (IS_NULL_exp(a)) {
-
 
2461
				ENC_make_top(bs);
-
 
2462
			} else {
-
 
2463
				TYPE s = DEREF_type(exp_type(a));
-
 
2464
				OFFSET off = DEREF_off(HEAD_list(q));
-
 
2465
				bs = enc_term_local(bs, m, off, 0, s, a,
-
 
2466
						    context);
-
 
2467
			}
-
 
2468
			q = TAIL_list(q);
-
 
2469
			p = TAIL_list(p);
-
 
2470
			no--;
-
 
2471
		}
-
 
2472
 
-
 
2473
		/* Conditionally destroy virtual bases */
-
 
2474
		if (nv) {
-
 
2475
			int mask = 0;
-
 
2476
			if (context == 0) {
-
 
2477
				mask = EXTRA_DESTR;
-
 
2478
			}
-
 
2479
			bs = enc_flag_test(bs, m2, nv, mask, ntest_not_eq);
-
 
2480
			while (!IS_NULL_list(p)) {
-
 
2481
				EXP a = DEREF_exp(HEAD_list(p));
-
 
2482
				if (IS_NULL_exp(a)) {
-
 
2483
					ENC_make_top(bs);
-
 
2484
				} else {
-
 
2485
					TYPE s = DEREF_type(exp_type(a));
-
 
2486
					OFFSET off = DEREF_off(HEAD_list(q));
-
 
2487
					bs = enc_term_local(bs, m, off, 0, s,
-
 
2488
							    a, context);
-
 
2489
				}
-
 
2490
				q = TAIL_list(q);
-
 
2491
				p = TAIL_list(p);
-
 
2492
			}
-
 
2493
			ENC_make_top(bs);
-
 
2494
		}
-
 
2495
 
-
 
2496
		/* Conditionally call 'operator delete' */
-
 
2497
		if (context == 0) {
-
 
2498
			ns = 1;
-
 
2499
			bs = enc_flag_test(bs, m2, ns, EXTRA_DELETE,
-
 
2500
					   ntest_not_eq);
-
 
2501
			bs = enc_delete_obj(bs, ct, m);
-
 
2502
			ENC_make_top(bs);
-
 
2503
		}
2372
 
2504
 
2373
    /* Find the 'this' pointer */
-
 
2374
    n = last_params [ DUMMY_this ] ;
-
 
2375
    m = unit_no ( bs, NULL_id, VAR_tag, 1 ) ;
-
 
2376
    ENC_identify ( bs ) ;
-
 
2377
    bs = enc_access ( bs, crt_func_access ) ;
-
 
2378
    ENC_make_tag ( bs, m ) ;
-
 
2379
    ENC_contents ( bs ) ;
-
 
2380
    ENC_pointer ( bs ) ;
-
 
2381
    bs = enc_al_ctype ( bs, ct ) ;
-
 
2382
    ENC_obtain_tag ( bs ) ;
-
 
2383
    ENC_make_tag ( bs, n ) ;
-
 
2384
 
-
 
2385
    if ( kind == DEFAULT_DESTR ) {
-
 
2386
	/* Deal with destructors */
-
 
2387
	int context = 0 ;
-
 
2388
	unsigned ns = no + 1 ;
-
 
2389
	ulong m2 = last_params [ DUMMY_extra ] ;
-
 
2390
	if ( last_params [ DUMMY_count ] != LINK_NONE ) {
-
 
2391
	    context = 5 ;
-
 
2392
	    ns-- ;
-
 
2393
	}
-
 
2394
	if ( nv ) ns++ ;
-
 
2395
	if ( ns > 1 ) {
-
 
2396
	    ENC_SEQUENCE ( bs, ns - 1 ) ;
-
 
2397
	} else {
2505
	} else {
2398
	    if ( ns == 0 ) ENC_make_top ( bs ) ;
2506
		/* Deal with constructors */
2399
	}
2507
		int virt = 1;
-
 
2508
		unsigned ns, nu;
-
 
2509
		unsigned ni = 0;
-
 
2510
		unsigned nt = 0;
-
 
2511
		unsigned ne = 1;
2400
 
2512
 
2401
	/* Destroy members and direct bases */
2513
		/* Allow for copy constructors */
2402
	while ( no ) {
2514
		if (kind == DEFAULT_COPY || kind == DEFAULT_ASSIGN) {
2403
	    EXP a = DEREF_exp ( HEAD_list ( p ) ) ;
2515
			ulong n1 = last_params[DUMMY_second];
2404
	    if ( IS_NULL_exp ( a ) ) {
2516
			ulong m1 = unit_no(bs, NULL_id, VAR_tag, 1);
2405
		ENC_make_top ( bs ) ;
2517
			ENC_identify(bs);
-
 
2518
			bs = enc_access(bs, crt_func_access);
2406
	    } else {
2519
			ENC_make_tag(bs, m1);
2407
		TYPE s = DEREF_type ( exp_type ( a ) ) ;
2520
			ENC_contents(bs);
2408
		OFFSET off = DEREF_off ( HEAD_list ( q ) ) ;
2521
			ENC_pointer(bs);
2409
		bs = enc_term_local ( bs, m, off, 0, s, a, context ) ;
2522
			bs = enc_al_ctype(bs, ct);
2410
	    }
-
 
2411
	    q = TAIL_list ( q ) ;
2523
			ENC_obtain_tag(bs);
2412
	    p = TAIL_list ( p ) ;
2524
			ENC_make_tag(bs, n1);
2413
	    no-- ;
2525
			last_params[DUMMY_copy] = m1;
2414
	}
2526
		}
2415
 
2527
 
2416
	/* Conditionally destroy virtual bases */
2528
		/* Count number of items */
2417
	if ( nv ) {
2529
		if (kind != DEFAULT_ASSIGN) {
2418
	    int mask = 0 ;
2530
			VIRTUAL vt = DEREF_virt(ctype_virt(ct));
2419
	    if ( context == 0 ) mask = EXTRA_DESTR ;
2531
			if (kind != DEFAULT_PRELUDE) {
2420
	    bs = enc_flag_test ( bs, m2, nv, mask, ntest_not_eq ) ;
2532
				LIST(GRAPH)bv = DEREF_list(ctype_vbase(ct));
2421
	    while ( !IS_NULL_list ( p ) ) {
2533
				while (!IS_NULL_list(bv)) {
-
 
2534
					/* Virtual base pointers */
2422
		EXP a = DEREF_exp ( HEAD_list ( p ) ) ;
2535
					GRAPH gr = DEREF_graph(HEAD_list(bv));
-
 
2536
					while (!IS_NULL_graph(gr)) {
-
 
2537
						ni++;
-
 
2538
						gr = DEREF_graph(graph_equal(gr));
-
 
2539
					}
-
 
2540
					bv = TAIL_list(bv);
-
 
2541
				}
-
 
2542
			}
2423
		if ( IS_NULL_exp ( a ) ) {
2543
			if (!IS_NULL_virt(vt)) {
-
 
2544
				/* Virtual function tables */
-
 
2545
				IDENTIFIER cid = DEREF_id(ctype_name(ct));
-
 
2546
				compile_virtual(ct, !has_linkage(cid));
-
 
2547
				while (!IS_NULL_virt(vt)) {
-
 
2548
					nt++;
-
 
2549
					vt = DEREF_virt(virt_next(vt));
-
 
2550
				}
-
 
2551
			}
-
 
2552
			virt = 0;
-
 
2553
		}
-
 
2554
		if (last_params[DUMMY_count] != LINK_NONE) {
-
 
2555
			ne = 2;
-
 
2556
		}
-
 
2557
		ns = ne * no + nt;
-
 
2558
		nu = ne * nv + ni;
-
 
2559
		if (nu) {
-
 
2560
			ns++;
-
 
2561
		}
-
 
2562
		if (ns > 1) {
2424
		    ENC_make_top ( bs ) ;
2563
			ENC_SEQUENCE(bs, ns - 1);
2425
		} else {
2564
		} else {
2426
		    TYPE s = DEREF_type ( exp_type ( a ) ) ;
-
 
2427
		    OFFSET off = DEREF_off ( HEAD_list ( q ) ) ;
-
 
2428
		    bs = enc_term_local ( bs, m, off, 0, s, a, context ) ;
-
 
2429
		}
-
 
2430
		q = TAIL_list ( q ) ;
2565
			if (ns == 0) {
2431
		p = TAIL_list ( p ) ;
-
 
2432
	    }
-
 
2433
	    ENC_make_top ( bs ) ;
2566
				ENC_make_top(bs);
2434
	}
2567
			}
2435
 
-
 
2436
	/* Conditionally call 'operator delete' */
-
 
2437
	if ( context == 0 ) {
-
 
2438
	    ns = 1 ;
-
 
2439
	    bs = enc_flag_test ( bs, m2, ns, EXTRA_DELETE, ntest_not_eq ) ;
-
 
2440
	    bs = enc_delete_obj ( bs, ct, m ) ;
-
 
2441
	    ENC_make_top ( bs ) ;
-
 
2442
	}
2568
		}
2443
 
2569
 
-
 
2570
		/* Conditionally initialise virtual bases */
-
 
2571
		if (nu) {
-
 
2572
			int dv = 0;
-
 
2573
			ulong m2 = last_params[DUMMY_extra];
-
 
2574
			bs = enc_flag_test(bs, m2, nu, 0, ntest_not_eq);
2444
    } else {
2575
			if (ni) {
2445
	/* Deal with constructors */
2576
				/* Initialise virtual base pointers */
-
 
2577
				bs = enc_virt_init(bs, ct, m);
-
 
2578
			}
2446
	int virt = 1 ;
2579
			while (nv) {
-
 
2580
				/* Virtual base initialisers */
-
 
2581
				EXP a = DEREF_exp(HEAD_list(p));
-
 
2582
				OFFSET off = DEREF_off(HEAD_list(q));
-
 
2583
				bs = enc_ctor_exp(bs, a, off, m, virt, ne);
-
 
2584
				if (!IS_NULL_exp(a) && IS_exp_paren(a)) {
-
 
2585
					dv++;
-
 
2586
				}
2447
	unsigned ns, nu ;
2587
				q = TAIL_list(q);
2448
	unsigned ni = 0 ;
2588
				p = TAIL_list(p);
-
 
2589
				nv--;
-
 
2590
			}
2449
	unsigned nt = 0 ;
2591
			if (ne == 1 || dv == 0) {
2450
	unsigned ne = 1 ;
2592
				ENC_make_top(bs);
-
 
2593
			} else {
-
 
2594
				bs = enc_destr_count(bs, NULL_type, dv);
-
 
2595
			}
-
 
2596
		}
2451
 
2597
 
2452
	/* Allow for copy constructors */
2598
		/* Initialise direct bases */
2453
	if ( kind == DEFAULT_COPY || kind == DEFAULT_ASSIGN ) {
-
 
2454
	    ulong n1 = last_params [ DUMMY_second ] ;
-
 
2455
	    ulong m1 = unit_no ( bs, NULL_id, VAR_tag, 1 ) ;
-
 
2456
	    ENC_identify ( bs ) ;
2599
		while (nb) {
2457
	    bs = enc_access ( bs, crt_func_access ) ;
2600
			EXP a = DEREF_exp(HEAD_list(p));
2458
	    ENC_make_tag ( bs, m1 ) ;
2601
			OFFSET off = DEREF_off(HEAD_list(q));
2459
	    ENC_contents ( bs ) ;
2602
			bs = enc_ctor_exp(bs, a, off, m, virt, ne);
2460
	    ENC_pointer ( bs ) ;
2603
			q = TAIL_list(q);
2461
	    bs = enc_al_ctype ( bs, ct ) ;
2604
			p = TAIL_list(p);
2462
	    ENC_obtain_tag ( bs ) ;
2605
			nb--;
2463
	    ENC_make_tag ( bs, n1 ) ;
-
 
2464
	    last_params [ DUMMY_copy ] = m1 ;
-
 
2465
	}
2606
		}
2466
 
2607
 
2467
	/* Count number of items */
-
 
2468
	if ( kind != DEFAULT_ASSIGN ) {
-
 
2469
	    VIRTUAL vt = DEREF_virt ( ctype_virt ( ct ) ) ;
-
 
2470
	    if ( kind != DEFAULT_PRELUDE ) {
-
 
2471
		LIST ( GRAPH ) bv = DEREF_list ( ctype_vbase ( ct ) ) ;
-
 
2472
		while ( !IS_NULL_list ( bv ) ) {
-
 
2473
		    /* Virtual base pointers */
2608
		/* Initialise virtual function tables */
2474
		    GRAPH gr = DEREF_graph ( HEAD_list ( bv ) ) ;
-
 
2475
		    while ( !IS_NULL_graph ( gr ) ) {
-
 
2476
			ni++ ;
-
 
2477
			gr = DEREF_graph ( graph_equal ( gr ) ) ;
-
 
2478
		    }
2609
		if (nt) {
2479
		    bv = TAIL_list ( bv ) ;
2610
			bs = enc_vtab_init(bs, ct, m, 1);
2480
		}
2611
		}
2481
	    }
2612
 
2482
	    if ( !IS_NULL_virt ( vt ) ) {
2613
		/* Initialise members */
2483
		/* Virtual function tables */
2614
		while (!IS_NULL_list(p)) {
2484
		IDENTIFIER cid = DEREF_id ( ctype_name ( ct ) ) ;
2615
			EXP a = DEREF_exp(HEAD_list(p));
2485
		compile_virtual ( ct, !has_linkage ( cid ) ) ;
2616
			OFFSET off = DEREF_off(HEAD_list(q));
2486
		while ( !IS_NULL_virt ( vt ) ) {
2617
			bs = enc_ctor_exp(bs, a, off, m, virt, ne);
2487
		    nt++ ;
2618
			q = TAIL_list(q);
2488
		    vt = DEREF_virt ( virt_next ( vt ) ) ;
2619
			p = TAIL_list(p);
2489
		}
2620
		}
2490
	    }
-
 
2491
	    virt = 0 ;
-
 
2492
	}
-
 
2493
	if ( last_params [ DUMMY_count ] != LINK_NONE ) ne = 2 ;
2621
		last_params[DUMMY_copy] = LINK_NONE;
2494
	ns = ne * no + nt ;
-
 
2495
	nu = ne * nv + ni ;
-
 
2496
	if ( nu ) ns++ ;
-
 
2497
	if ( ns > 1 ) {
-
 
2498
	    ENC_SEQUENCE ( bs, ns - 1 ) ;
-
 
2499
	} else {
-
 
2500
	    if ( ns == 0 ) ENC_make_top ( bs ) ;
-
 
2501
	}
-
 
2502
 
-
 
2503
	/* Conditionally initialise virtual bases */
-
 
2504
	if ( nu ) {
-
 
2505
	    int dv = 0 ;
-
 
2506
	    ulong m2 = last_params [ DUMMY_extra ] ;
-
 
2507
	    bs = enc_flag_test ( bs, m2, nu, 0, ntest_not_eq ) ;
-
 
2508
	    if ( ni ) {
-
 
2509
		/* Initialise virtual base pointers */
-
 
2510
		bs = enc_virt_init ( bs, ct, m ) ;
-
 
2511
	    }
-
 
2512
	    while ( nv ) {
-
 
2513
		/* Virtual base initialisers */
-
 
2514
		EXP a = DEREF_exp ( HEAD_list ( p ) ) ;
-
 
2515
		OFFSET off = DEREF_off ( HEAD_list ( q ) ) ;
-
 
2516
		bs = enc_ctor_exp ( bs, a, off, m, virt, ne ) ;
-
 
2517
		if ( !IS_NULL_exp ( a ) && IS_exp_paren ( a ) ) dv++ ;
-
 
2518
		q = TAIL_list ( q ) ;
-
 
2519
		p = TAIL_list ( p ) ;
-
 
2520
		nv-- ;
-
 
2521
	    }
-
 
2522
	    if ( ne == 1 || dv == 0 ) {
-
 
2523
		ENC_make_top ( bs ) ;
-
 
2524
	    } else {
-
 
2525
		bs = enc_destr_count ( bs, NULL_type, dv ) ;
-
 
2526
	    }
-
 
2527
	}
-
 
2528
 
-
 
2529
	/* Initialise direct bases */
-
 
2530
	while ( nb ) {
-
 
2531
	    EXP a = DEREF_exp ( HEAD_list ( p ) ) ;
-
 
2532
	    OFFSET off = DEREF_off ( HEAD_list ( q ) ) ;
-
 
2533
	    bs = enc_ctor_exp ( bs, a, off, m, virt, ne ) ;
-
 
2534
	    q = TAIL_list ( q ) ;
-
 
2535
	    p = TAIL_list ( p ) ;
-
 
2536
	    nb-- ;
-
 
2537
	}
-
 
2538
 
-
 
2539
	/* Initialise virtual function tables */
-
 
2540
	if ( nt ) bs = enc_vtab_init ( bs, ct, m, 1 ) ;
-
 
2541
 
-
 
2542
	/* Initialise members */
-
 
2543
	while ( !IS_NULL_list ( p ) ) {
-
 
2544
	    EXP a = DEREF_exp ( HEAD_list ( p ) ) ;
-
 
2545
	    OFFSET off = DEREF_off ( HEAD_list ( q ) ) ;
-
 
2546
	    bs = enc_ctor_exp ( bs, a, off, m, virt, ne ) ;
-
 
2547
	    q = TAIL_list ( q ) ;
-
 
2548
	    p = TAIL_list ( p ) ;
-
 
2549
	}
2622
	}
2550
	last_params [ DUMMY_copy ] = LINK_NONE ;
-
 
2551
    }
-
 
2552
    return ( bs ) ;
2623
	return (bs);
2553
}
2624
}
2554
 
2625
 
2555
 
2626
 
2556
#endif /* LANGUAGE_CPP */
2627
#endif /* LANGUAGE_CPP */
2557
#endif /* TDF_OUTPUT */
2628
#endif /* TDF_OUTPUT */