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/compile.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
*/
29
 
59
 
30
 
60
 
31
#include "config.h"
61
#include "config.h"
32
#include "version.h"
62
#include "version.h"
33
#include "c_types.h"
63
#include "c_types.h"
Line 82... Line 112...
82
 
112
 
83
    This list contains all the inline and implicit functions and
113
    This list contains all the inline and implicit functions and
84
    literal constants defined in the program.
114
    literal constants defined in the program.
85
*/
115
*/
86
 
116
 
87
LIST ( IDENTIFIER ) pending_funcs = NULL_list ( IDENTIFIER ) ;
117
LIST(IDENTIFIER)pending_funcs = NULL_list(IDENTIFIER);
88
 
118
 
89
 
119
 
90
/*
120
/*
91
    CHECK A MANGLED IDENTIFIER NAME
121
    CHECK A MANGLED IDENTIFIER NAME
92
 
122
 
93
    This routine checks whether the identifier id is used but not defined
123
    This routine checks whether the identifier id is used but not defined
94
    because, although it has external linkage, its mangled name is empty.
124
    because, although it has external linkage, its mangled name is empty.
95
*/
125
*/
96
 
126
 
97
static void check_mangled
127
static void
98
    PROTO_N ( ( id ) )
-
 
99
    PROTO_T ( IDENTIFIER id )
128
check_mangled(IDENTIFIER id)
100
{
129
{
101
    IDENTIFIER lid = DEREF_id ( id_alias ( id ) ) ;
130
	IDENTIFIER lid = DEREF_id(id_alias(id));
102
    DECL_SPEC ds = DEREF_dspec ( id_storage ( lid ) ) ;
131
	DECL_SPEC ds = DEREF_dspec(id_storage(lid));
103
    if ( !( ds & dspec_done ) ) {
132
	if (!(ds & dspec_done)) {
104
	if ( ( ds & dspec_extern ) && !( ds & dspec_defn ) ) {
133
		if ((ds & dspec_extern) && !(ds & dspec_defn)) {
105
	    if ( ds & ( dspec_used | dspec_called ) ) {
134
			if (ds & (dspec_used | dspec_called)) {
106
		/* Should have an external name */
135
				/* Should have an external name */
107
		string s = mangle_name ( lid, VAR_tag, 0 ) ;
136
				string s = mangle_name(lid, VAR_tag, 0);
108
		if ( s == NULL && has_linkage ( lid ) ) {
137
				if (s == NULL && has_linkage(lid)) {
109
		    LOCATION loc ;
138
					LOCATION loc;
110
		    DEREF_loc ( id_loc ( lid ), loc ) ;
139
					DEREF_loc(id_loc(lid), loc);
111
		    report ( loc, ERR_basic_odr_undef ( lid ) ) ;
140
					report(loc, ERR_basic_odr_undef(lid));
-
 
141
				}
-
 
142
			}
112
		}
143
		}
113
	    }
-
 
114
	}
-
 
115
	ds |= dspec_done ;
144
		ds |= dspec_done;
116
	COPY_dspec ( id_storage ( lid ), ds ) ;
145
		COPY_dspec(id_storage(lid), ds);
117
    }
146
	}
118
    return ;
147
	return;
119
}
148
}
120
 
149
 
121
 
150
 
122
/*
151
/*
123
    START OF TDF OUTPUT ROUTINES
152
    START OF TDF OUTPUT ROUTINES
124
 
153
 
125
    The compiler can optionally be compiled with the TDF output routines
154
    The compiler can optionally be compiled with the TDF output routines
126
    disabled by defining the TDF_OUTPUT macro to be zero on the
155
    disabled by defining the TDF_OUTPUT macro to be zero on the
127
    command-line.  The following routines are concerned with TDF output.
156
    command-line.  The following routines are concerned with TDF output.
128
*/
157
*/
129
 
158
 
130
#if TDF_OUTPUT
159
#if TDF_OUTPUT
131
 
160
 
132
 
161
 
133
/*
162
/*
134
    CURRENT FUNCTION ACCESS
163
    CURRENT FUNCTION ACCESS
135
 
164
 
136
    This variable is used to hold the declaration specifiers for the
165
    This variable is used to hold the declaration specifiers for the
137
    current function.
166
    current function.
138
*/
167
*/
139
 
168
 
140
DECL_SPEC crt_func_access = dspec_none ;
169
DECL_SPEC crt_func_access = dspec_none;
141
 
170
 
142
 
171
 
143
/*
172
/*
144
    ENCODE AN IDENTIFIER ACCESS
173
    ENCODE AN IDENTIFIER ACCESS
145
 
174
 
146
    This routine adds an optional TDF ACCESS corresponding to the
175
    This routine adds an optional TDF ACCESS corresponding to the
147
    declaration specifiers ds.
176
    declaration specifiers ds.
148
*/
177
*/
149
 
178
 
150
BITSTREAM *enc_access
179
BITSTREAM *
151
    PROTO_N ( ( bs, ds ) )
-
 
152
    PROTO_T ( BITSTREAM *bs X DECL_SPEC ds )
180
enc_access(BITSTREAM *bs, DECL_SPEC ds)
153
{
181
{
154
    if ( ds & dspec_mutable ) {
182
	if (ds & dspec_mutable) {
155
	ENC_ON ( bs ) ;
183
		ENC_ON(bs);
156
	if ( output_bugs ) {
184
		if (output_bugs) {
157
	    /* Needed for old installer bug */
185
			/* Needed for old installer bug */
158
	    ENC_add_accesses ( bs ) ;
186
			ENC_add_accesses(bs);
159
	    ENC_visible ( bs ) ;
187
			ENC_visible(bs);
-
 
188
		}
-
 
189
		ENC_long_jump_access(bs);
-
 
190
	} else {
-
 
191
		ENC_OFF(bs);
160
	}
192
	}
161
	ENC_long_jump_access ( bs ) ;
-
 
162
    } else {
-
 
163
	ENC_OFF ( bs ) ;
-
 
164
    }
-
 
165
    return ( bs ) ;
193
	return (bs);
166
}
194
}
167
 
195
 
168
 
196
 
169
/*
197
/*
170
    ENCODE AN IDENTIFIER SIGNATURE
198
    ENCODE AN IDENTIFIER SIGNATURE
Line 172... Line 200...
172
    This routine adds an optional identifier signature corresponding to id
200
    This routine adds an optional identifier signature corresponding to id
173
    to the bitstream bs.  Note that these signatures were only introduced
201
    to the bitstream bs.  Note that these signatures were only introduced
174
    in TDF version 4.0.
202
    in TDF version 4.0.
175
*/
203
*/
176
 
204
 
177
static BITSTREAM *enc_signature
205
static BITSTREAM *
178
    PROTO_N ( ( bs, id ) )
-
 
179
    PROTO_T ( BITSTREAM *bs X IDENTIFIER id )
206
enc_signature(BITSTREAM *bs, IDENTIFIER id)
180
{
207
{
181
#if ( TDF_major >= 4 )
208
#if (TDF_major >= 4)
182
    ENC_OFF ( bs ) ;
209
	ENC_OFF(bs);
183
#endif
210
#endif
184
    UNUSED ( id ) ;
211
	UNUSED(id);
185
    return ( bs ) ;
212
	return (bs);
186
}
213
}
187
 
214
 
188
 
215
 
189
/*
216
/*
190
    SHOULD A VARIABLE BE COMMON?
217
    SHOULD A VARIABLE BE COMMON?
191
 
218
 
192
    This routine checks whether the local static variable id should be
219
    This routine checks whether the local static variable id should be
193
    made a common tag.  It returns 2 if it should and 1 otherwise (see
220
    made a common tag.  It returns 2 if it should and 1 otherwise (see
194
    enc_tagdec).  The prefix to be used for mangling the name is returned
221
    enc_tagdec).  The prefix to be used for mangling the name is returned
195
    via ps.
222
    via ps.
196
*/
223
*/
197
 
224
 
198
static int is_common_tag
225
static int
199
    PROTO_N ( ( id, ps ) )
-
 
200
    PROTO_T ( IDENTIFIER id X string *ps )
226
is_common_tag(IDENTIFIER id, string *ps)
201
{
227
{
202
    NAMESPACE ns = DEREF_nspace ( id_parent ( id ) ) ;
228
	NAMESPACE ns = DEREF_nspace(id_parent(id));
203
    IDENTIFIER pid = DEREF_id ( nspace_name ( ns ) ) ;
229
	IDENTIFIER pid = DEREF_id(nspace_name(ns));
204
    if ( !IS_NULL_id ( pid ) && IS_id_function_etc ( pid ) ) {
230
	if (!IS_NULL_id(pid) && IS_id_function_etc(pid)) {
205
	DECL_SPEC ds = DEREF_dspec ( id_storage ( pid ) ) ;
231
		DECL_SPEC ds = DEREF_dspec(id_storage(pid));
206
	if ( ( ds & dspec_inline ) && ( ds & dspec_extern ) ) {
232
		if ((ds & dspec_inline) && (ds & dspec_extern)) {
207
	    string s = mangle_name ( pid, VAR_tag, 1 ) ;
233
			string s = mangle_name(pid, VAR_tag, 1);
208
	    if ( s ) {
234
			if (s) {
209
		*ps = s ;
235
				*ps = s;
210
		return ( 2 ) ;
236
				return (2);
211
	    }
237
			}
212
	}
238
		}
213
    }
239
	}
214
    return ( 1 ) ;
240
	return (1);
215
}
241
}
216
 
242
 
217
 
243
 
218
/*
244
/*
219
    CREATE A STATIC TAG DEFINITION
245
    CREATE A STATIC TAG DEFINITION
220
 
246
 
221
    This routine adds the tag declaration for the static variable id to
247
    This routine adds the tag declaration for the static variable id to
222
    the bitstream bs.  If id has a constant initialiser and no destructor
248
    the bitstream bs.  If id has a constant initialiser and no destructor
223
    then this is mapped to a simple tag definition, otherwise the
249
    then this is mapped to a simple tag definition, otherwise the
224
    initialisation and termination need to be done dynamically.
250
    initialisation and termination need to be done dynamically.
338
    CREATE A LOCAL TAG DEFINITION
371
    CREATE A LOCAL TAG DEFINITION
339
 
372
 
340
    This routine adds the start of a local tag declaration for the variable
373
    This routine adds the start of a local tag declaration for the variable
341
    id to the bitstream bs.  The definition body has to be added later.
374
    id to the bitstream bs.  The definition body has to be added later.
342
    Any destructor for id is returned via d.  var is 1 to indicate that
375
    Any destructor for id is returned via d.  var is 1 to indicate that
343
    id is a variable as opposed to an identity.  A value of 2 or more for
376
    id is a variable as opposed to an identity.  A value of 2 or more for
344
    var indicates that the variable should be just declared rather than
377
    var indicates that the variable should be just declared rather than
345
    defined.  This is only used for automatic variables.  e gives the
378
    defined.  This is only used for automatic variables.  e gives the
346
    corresponding declaration statement for use with diagnostics.
379
    corresponding declaration statement for use with diagnostics.
347
*/
380
*/
348
 
381
 
349
BITSTREAM *enc_variable
382
BITSTREAM *
350
    PROTO_N ( ( bs, id, var, d, e ) )
-
 
351
    PROTO_T ( BITSTREAM *bs X IDENTIFIER id X int var X EXP *d X EXP e )
383
enc_variable(BITSTREAM *bs, IDENTIFIER id, int var, EXP *d, EXP e)
352
{
384
{
353
    /* Check for previous definition */
385
	/* Check for previous definition */
354
    IDENTIFIER lid = DEREF_id ( id_alias ( id ) ) ;
386
	IDENTIFIER lid = DEREF_id(id_alias(id));
355
    DECL_SPEC ds = DEREF_dspec ( id_storage ( lid ) ) ;
387
	DECL_SPEC ds = DEREF_dspec(id_storage(lid));
356
    if ( ds & dspec_done ) return ( bs ) ;
388
	if (ds & dspec_done) {
-
 
389
		return (bs);
-
 
390
	}
357
    ds |= dspec_done ;
391
	ds |= dspec_done;
358
 
392
 
359
    if ( ds & dspec_auto ) {
393
	if (ds & dspec_auto) {
360
	/* Local variable definition */
394
		/* Local variable definition */
361
	int dummy = 0 ;
395
		int dummy = 0;
362
	ulong n = unit_no ( bs, id, VAR_tag, 1 ) ;
396
		ulong n = unit_no(bs, id, VAR_tag, 1);
363
	EXP a = DEREF_exp ( id_variable_init ( id ) ) ;
397
		EXP a = DEREF_exp(id_variable_init(id));
364
	EXP b = DEREF_exp ( id_variable_term ( id ) ) ;
398
		EXP b = DEREF_exp(id_variable_term(id));
365
	EXP b1 = NULL_exp ;
399
		EXP b1 = NULL_exp;
366
	TYPE t = DEREF_type ( id_variable_type ( id ) ) ;
400
		TYPE t = DEREF_type(id_variable_type(id));
367
	COPY_dspec ( id_storage ( lid ), ds ) ;
401
		COPY_dspec(id_storage(lid), ds);
368
	if ( var ) {
402
		if (var) {
369
	    if ( !IS_NULL_exp ( b ) ) {
403
			if (!IS_NULL_exp(b)) {
370
		if ( output_except || var == 4 ) {
404
				if (output_except || var == 4) {
371
		    /* Set up terminator variable */
405
					/* Set up terminator variable */
372
		    bs = make_term_local ( bs, t, &b, var ) ;
406
					bs = make_term_local(bs, t, &b, var);
373
		    b1 = b ;
407
					b1 = b;
374
		    if ( IS_NULL_exp ( a ) && var == 1 ) {
408
					if (IS_NULL_exp(a) && var == 1) {
375
			a = make_dummy_init ( t ) ;
409
						a = make_dummy_init(t);
376
			dummy = 1 ;
410
						dummy = 1;
377
		    }
411
					}
378
		}
412
				}
379
	    }
413
			}
380
	    ENC_variable ( bs ) ;
414
			ENC_variable(bs);
381
	} else {
415
		} else {
382
	    ENC_identify ( bs ) ;
416
			ENC_identify(bs);
383
	}
417
		}
384
	bs = enc_access ( bs, ds ) ;
418
		bs = enc_access(bs, ds);
385
	ENC_make_tag ( bs, n ) ;
419
		ENC_make_tag(bs, n);
386
	if ( IS_NULL_exp ( a ) || var >= 2 ) {
420
		if (IS_NULL_exp(a) || var >= 2) {
387
	    ENC_make_value ( bs ) ;
421
			ENC_make_value(bs);
388
	    bs = enc_shape ( bs, t ) ;
422
			bs = enc_shape(bs, t);
389
	} else if ( var ) {
423
		} else if (var) {
390
	    bs = enc_init_local ( bs, a, b1, n, t, e ) ;
424
			bs = enc_init_local(bs, a, b1, n, t, e);
391
	} else {
425
		} else {
392
	    if ( !IS_NULL_exp ( e ) ) {
426
			if (!IS_NULL_exp(e)) {
393
		BITSTREAM *ts = enc_diag_begin ( &bs ) ;
427
				BITSTREAM *ts = enc_diag_begin(&bs);
394
		ts = enc_addr_exp ( ts, t, a ) ;
428
				ts = enc_addr_exp(ts, t, a);
395
		bs = enc_diag_end ( bs, ts, e, 1 ) ;
429
				bs = enc_diag_end(bs, ts, e, 1);
396
	    } else {
430
			} else {
397
		bs = enc_addr_exp ( bs, t, a ) ;
431
				bs = enc_addr_exp(bs, t, a);
398
	    }
432
			}
399
	}
433
		}
-
 
434
		if (dummy) {
400
	if ( dummy ) free_exp ( a, 1 ) ;
435
			free_exp(a, 1);
-
 
436
		}
401
	if ( d ) *d = b ;
437
		if (d)*d = b;
402
    } else if ( !( ds & dspec_linkage ) ) {
438
	} else if (!(ds & dspec_linkage)) {
403
	/* Static variable definition */
439
		/* Static variable definition */
404
	if ( IS_id_variable ( id ) ) {
440
		if (IS_id_variable(id)) {
405
	    COPY_dspec ( id_storage ( lid ), ds ) ;
441
			COPY_dspec(id_storage(lid), ds);
406
	    bs = enc_static_var ( bs, id ) ;
442
			bs = enc_static_var(bs, id);
407
	}
443
		}
408
    }
444
	}
409
    return ( bs ) ;
445
	return (bs);
410
}
446
}
411
 
447
 
412
 
448
 
413
/*
449
/*
414
    ENCODE A FUNCTION DEFINITION
450
    ENCODE A FUNCTION DEFINITION
415
 
451
 
416
    This routine encodes the definition of the function id with body e
452
    This routine encodes the definition of the function id with body e
417
    to the bitstream bs.
453
    to the bitstream bs.
418
*/
454
*/
419
 
455
 
420
static BITSTREAM *enc_func_defn
456
static BITSTREAM *
421
    PROTO_N ( ( bs, id, e ) )
-
 
422
    PROTO_T ( BITSTREAM *bs X IDENTIFIER id X EXP e )
457
enc_func_defn(BITSTREAM *bs, IDENTIFIER id, EXP e)
423
{
458
{
424
    unsigned n ;
459
	unsigned n;
425
    unsigned npids ;
460
	unsigned npids;
426
    int is_main = 0 ;
461
	int is_main = 0;
427
    EXP r = NULL_exp ;
462
	EXP r = NULL_exp;
428
    unsigned seq = 0 ;
463
	unsigned seq = 0;
429
    unsigned rpids = 0 ;
464
	unsigned rpids = 0;
430
    unsigned epids = 0 ;
465
	unsigned epids = 0;
431
    BITSTREAM *ts = NULL ;
466
	BITSTREAM *ts = NULL;
432
    int diag = output_diag ;
467
	int diag = output_diag;
433
    LIST ( IDENTIFIER ) qids ;
468
	LIST(IDENTIFIER)qids;
434
    IDENTIFIER eid = NULL_id ;
469
	IDENTIFIER eid = NULL_id;
435
    DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
470
	DECL_SPEC ds = DEREF_dspec(id_storage(id));
436
    TYPE fn = DEREF_type ( id_function_etc_type ( id ) ) ;
471
	TYPE fn = DEREF_type(id_function_etc_type(id));
437
    TYPE ret = DEREF_type ( type_func_ret ( fn ) ) ;
472
	TYPE ret = DEREF_type(type_func_ret(fn));
438
    int ell = DEREF_int ( type_func_ellipsis ( fn ) ) ;
473
	int ell = DEREF_int(type_func_ellipsis(fn));
439
    LIST ( IDENTIFIER ) pids = DEREF_list ( type_func_pids ( fn ) ) ;
474
	LIST(IDENTIFIER)pids = DEREF_list(type_func_pids(fn));
440
#if LANGUAGE_CPP
475
#if LANGUAGE_CPP
441
    EXP post = NULL_exp ;
476
	EXP post = NULL_exp;
442
    int throws = output_except ;
477
	int throws = output_except;
443
    LIST ( TYPE ) except = DEREF_list ( type_func_except ( fn ) ) ;
478
	LIST(TYPE)except = DEREF_list(type_func_except(fn));
444
#endif
479
#endif
445
 
480
 
446
    /* Check for main routine */
481
	/* Check for main routine */
447
    if ( ds & dspec_main ) {
482
	if (ds & dspec_main) {
448
	HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
483
		HASHID nm = DEREF_hashid(id_name(id));
449
	if ( IS_hashid_name ( nm ) ) {
484
		if (IS_hashid_name(nm)) {
450
	    ds &= ~dspec_friend ;
485
			ds &= ~dspec_friend;
451
	    is_main = 1 ;
486
			is_main = 1;
452
	    seq++ ;
487
			seq++;
-
 
488
		}
-
 
489
	}
-
 
490
 
-
 
491
	/* Check exception specifier */
-
 
492
#if LANGUAGE_CPP
-
 
493
	if (throws) {
-
 
494
		if (output_partial) {
-
 
495
			post = except_postlude(id);
-
 
496
		}
-
 
497
		if (IS_NULL_exp(post)) {
-
 
498
			if (EQ_list(except, univ_type_set)) {
-
 
499
				throws = 0;
-
 
500
			} else if (ds & (dspec_friend | dspec_implicit)) {
-
 
501
				/* No exception specification required */
-
 
502
				throws = 0;
-
 
503
			}
-
 
504
		} else {
-
 
505
			ds |= dspec_mutable;
-
 
506
		}
-
 
507
	}
-
 
508
#endif
-
 
509
 
-
 
510
	/* Encode start of function */
-
 
511
	common_no = 0;
-
 
512
	crt_func_access = ds;
-
 
513
	clear_params();
-
 
514
	ENC_make_proc(bs);
-
 
515
	if (pass_complex_type(ret)) {
-
 
516
		ENC_top(bs);
-
 
517
		rpids = 1;
-
 
518
	} else {
-
 
519
		if (IS_type_top_etc(ret)) {
-
 
520
			last_params[DUMMY_return] = LINK_ZERO;
-
 
521
		} else if (is_main) {
-
 
522
			MAKE_exp_null(ret, r);
-
 
523
		} else {
-
 
524
			MAKE_exp_value(ret, r);
-
 
525
		}
-
 
526
		bs = enc_shape(bs, ret);
-
 
527
	}
-
 
528
	MAKE_exp_return_stmt(type_bottom, r, r);
-
 
529
 
-
 
530
	/* Encode 'this' parameter */
-
 
531
	if (IS_id_mem_func(id)) {
-
 
532
		CLASS_TYPE ct = parent_class(id);
-
 
533
		IDENTIFIER pid = this_param(id, 0);
-
 
534
		ASSERT(!IS_NULL_id(pid));
-
 
535
		CONS_id(pid, pids, pids);
-
 
536
		epids = extra_constr_args(id, ct);
-
 
537
		last_class = ct;
453
	}
538
	}
-
 
539
 
-
 
540
	/* Encode number of parameters */
-
 
541
	npids = LENGTH_list(pids);
-
 
542
	ENC_LIST(bs, rpids + npids + epids);
-
 
543
	qids = pids;
-
 
544
 
-
 
545
	/* Encode function return parameter */
-
 
546
	if (rpids) {
-
 
547
		ulong pn = unit_no(bs, NULL_id, VAR_tag, 1);
-
 
548
		ENC_pointer(bs);
-
 
549
		bs = enc_alignment(bs, ret);
-
 
550
		bs = enc_access(bs, ds);
-
 
551
		ENC_make_tag(bs, pn);
-
 
552
		last_params[DUMMY_return] = pn;
-
 
553
	}
-
 
554
 
-
 
555
	/* Encode normal function parameters */
-
 
556
	n = 0;
-
 
557
	while (!IS_NULL_list(pids)) {
-
 
558
		IDENTIFIER pid = DEREF_id(HEAD_list(pids));
-
 
559
		DECL_SPEC pds = DEREF_dspec(id_storage(pid));
-
 
560
		TYPE pt = DEREF_type(id_parameter_type(pid));
-
 
561
		ulong pn = unit_no(bs, pid, VAR_tag, 1);
-
 
562
		if (n < DUMMY_params) {
-
 
563
			last_params[n] = pn;
-
 
564
			n++;
-
 
565
		}
-
 
566
		if (pass_complex_type(pt)) {
-
 
567
			/* Introduce identity for complex parameters */
-
 
568
			ulong pm = unit_no(bs, NULL_id, VAR_tag, 1);
-
 
569
			ENC_pointer(bs);
-
 
570
			bs = enc_alignment(bs, pt);
-
 
571
			if (ts == NULL) {
-
 
572
				ts = start_bitstream(NIL(FILE), bs->link);
-
 
573
			}
-
 
574
			ENC_identify(ts);
-
 
575
			ts = enc_access(ts, ds);
-
 
576
			ENC_make_tag(ts, pn);
-
 
577
			ENC_contents(ts);
-
 
578
			ENC_pointer(ts);
-
 
579
			ts = enc_alignment(ts, pt);
-
 
580
			ENC_obtain_tag(ts);
-
 
581
			ENC_make_tag(ts, pm);
-
 
582
			pn = pm;
-
 
583
		} else if (pds & dspec_virtual) {
-
 
584
			/* Introduce variable for weak parameter types */
-
 
585
			ulong pm = unit_no(bs, NULL_id, VAR_tag, 1);
-
 
586
			TYPE pu = arg_promote_type(pt, KILL_err);
-
 
587
			bs = enc_shape(bs, pu);
-
 
588
			if (ts == NULL) {
-
 
589
				ts = start_bitstream(NIL(FILE), bs->link);
-
 
590
			}
-
 
591
			ENC_variable(ts);
-
 
592
			ts = enc_access(ts, ds);
-
 
593
			ENC_make_tag(ts, pn);
-
 
594
			if (IS_type_integer(pt)) {
-
 
595
				ENC_change_variety(ts);
-
 
596
				ts = enc_error_treatment(ts, pt);
-
 
597
				ts = enc_variety(ts, pt);
-
 
598
			} else {
-
 
599
				ENC_change_floating_variety(ts);
-
 
600
				ENC_impossible(ts);
-
 
601
				ts = enc_flvar(ts, pt);
454
    }
602
			}
-
 
603
			ENC_contents(ts);
-
 
604
			ts = enc_shape(ts, pu);
-
 
605
			ENC_obtain_tag(ts);
-
 
606
			ENC_make_tag(ts, pm);
-
 
607
			pn = pm;
-
 
608
		} else {
-
 
609
			/* Simple parameter */
-
 
610
			bs = enc_shape(bs, pt);
-
 
611
		}
-
 
612
		bs = enc_access(bs, ds);
-
 
613
		ENC_make_tag(bs, pn);
-
 
614
		pids = TAIL_list(pids);
-
 
615
	}
-
 
616
 
-
 
617
	/* Encode extra function parameters */
-
 
618
	while (epids) {
-
 
619
		ulong pn = unit_no(bs, NULL_id, VAR_tag, 1);
-
 
620
		bs = enc_shape(bs, type_sint);
-
 
621
		bs = enc_access(bs, ds);
-
 
622
		ENC_make_tag(bs, pn);
-
 
623
		last_params[DUMMY_extra] = pn;
-
 
624
		epids--;
-
 
625
	}
-
 
626
 
-
 
627
	/* Encode ellipsis parameter */
-
 
628
	if (ell & FUNC_ELLIPSIS) {
-
 
629
		ulong pn;
-
 
630
		eid = ellipsis_param(id);
-
 
631
		ASSERT(!IS_NULL_id(eid));
-
 
632
		pn = unit_no(bs, eid, VAR_tag, 1);
-
 
633
		ENC_ON(bs);
-
 
634
		ENC_make_tag(bs, pn);
-
 
635
		bs = enc_access(bs, ds);
-
 
636
		last_params[DUMMY_ellipsis] = pn;
-
 
637
	} else {
-
 
638
		ENC_OFF(bs);
-
 
639
	}
-
 
640
 
-
 
641
	/* Allow for reference parameters */
-
 
642
	if (ts) {
-
 
643
		bs = join_bitstreams(bs, ts);
-
 
644
	}
-
 
645
	ts = bs;
455
 
646
 
456
    /* Check exception specifier */
647
	/* Encode function body */
-
 
648
	seq += stmt_length(e);
-
 
649
	if (diag) {
-
 
650
		bs = start_bitstream(NIL(FILE), bs->link);
-
 
651
	}
457
#if LANGUAGE_CPP
652
#if LANGUAGE_CPP
458
    if ( throws ) {
653
	if (throws) {
459
	if ( output_partial ) post = except_postlude ( id ) ;
-
 
460
	if ( IS_NULL_exp ( post ) ) {
654
		bs = enc_try_func(bs, post);
461
	    if ( EQ_list ( except, univ_type_set ) ) {
-
 
462
		throws = 0 ;
-
 
463
	    } else if ( ds & ( dspec_friend | dspec_implicit ) ) {
-
 
464
		/* No exception specification required */
-
 
465
		throws = 0 ;
-
 
466
	    }
-
 
467
	} else {
-
 
468
	    ds |= dspec_mutable ;
-
 
469
	}
655
	}
470
    }
-
 
471
#endif
656
#endif
472
 
-
 
473
    /* Encode start of function */
-
 
474
    common_no = 0 ;
-
 
475
    crt_func_access = ds ;
-
 
476
    clear_params () ;
-
 
477
    ENC_make_proc ( bs ) ;
-
 
478
    if ( pass_complex_type ( ret ) ) {
-
 
479
	ENC_top ( bs ) ;
657
	ENC_SEQUENCE(bs, seq);
480
	rpids = 1 ;
-
 
481
    } else {
-
 
482
	if ( IS_type_top_etc ( ret ) ) {
-
 
483
	    last_params [ DUMMY_return ] = LINK_ZERO ;
-
 
484
	} else if ( is_main ) {
658
	if (is_main) {
485
	    MAKE_exp_null ( ret, r ) ;
-
 
486
	} else {
-
 
487
	    MAKE_exp_value ( ret, r ) ;
-
 
488
	}
-
 
489
	bs = enc_shape ( bs, ret ) ;
659
		bs = enc_special(bs, TOK_start);
490
    }
-
 
491
    MAKE_exp_return_stmt ( type_bottom, r, r ) ;
-
 
492
 
-
 
493
    /* Encode 'this' parameter */
-
 
494
    if ( IS_id_mem_func ( id ) ) {
-
 
495
	CLASS_TYPE ct = parent_class ( id ) ;
-
 
496
	IDENTIFIER pid = this_param ( id, 0 ) ;
-
 
497
	ASSERT ( !IS_NULL_id ( pid ) ) ;
-
 
498
	CONS_id ( pid, pids, pids ) ;
-
 
499
	epids = extra_constr_args ( id, ct ) ;
-
 
500
	last_class = ct ;
-
 
501
    }
-
 
502
 
-
 
503
    /* Encode number of parameters */
-
 
504
    npids = LENGTH_list ( pids ) ;
-
 
505
    ENC_LIST ( bs, rpids + npids + epids ) ;
-
 
506
    qids = pids ;
-
 
507
 
-
 
508
    /* Encode function return parameter */
-
 
509
    if ( rpids ) {
-
 
510
	ulong pn = unit_no ( bs, NULL_id, VAR_tag, 1 ) ;
-
 
511
	ENC_pointer ( bs ) ;
-
 
512
	bs = enc_alignment ( bs, ret ) ;
-
 
513
	bs = enc_access ( bs, ds ) ;
-
 
514
	ENC_make_tag ( bs, pn ) ;
-
 
515
	last_params [ DUMMY_return ] = pn ;
-
 
516
    }
-
 
517
 
-
 
518
    /* Encode normal function parameters */
-
 
519
    n = 0 ;
-
 
520
    while ( !IS_NULL_list ( pids ) ) {
-
 
521
	IDENTIFIER pid = DEREF_id ( HEAD_list ( pids ) ) ;
-
 
522
	DECL_SPEC pds = DEREF_dspec ( id_storage ( pid ) ) ;
-
 
523
	TYPE pt = DEREF_type ( id_parameter_type ( pid ) ) ;
-
 
524
	ulong pn = unit_no ( bs, pid, VAR_tag, 1 ) ;
-
 
525
	if ( n < DUMMY_params ) {
-
 
526
	    last_params [n] = pn ;
-
 
527
	    n++ ;
-
 
528
	}
-
 
529
	if ( pass_complex_type ( pt ) ) {
-
 
530
	    /* Introduce identity for complex parameters */
-
 
531
	    ulong pm = unit_no ( bs, NULL_id, VAR_tag, 1 ) ;
-
 
532
	    ENC_pointer ( bs ) ;
-
 
533
	    bs = enc_alignment ( bs, pt ) ;
-
 
534
	    if ( ts == NULL ) {
-
 
535
		ts = start_bitstream ( NIL ( FILE ), bs->link ) ;
-
 
536
	    }
-
 
537
	    ENC_identify ( ts ) ;
-
 
538
	    ts = enc_access ( ts, ds ) ;
-
 
539
	    ENC_make_tag ( ts, pn ) ;
-
 
540
	    ENC_contents ( ts ) ;
-
 
541
	    ENC_pointer ( ts ) ;
-
 
542
	    ts = enc_alignment ( ts, pt ) ;
-
 
543
	    ENC_obtain_tag ( ts ) ;
-
 
544
	    ENC_make_tag ( ts, pm ) ;
-
 
545
	    pn = pm ;
-
 
546
	} else if ( pds & dspec_virtual ) {
-
 
547
	    /* Introduce variable for weak parameter types */
-
 
548
	    ulong pm = unit_no ( bs, NULL_id, VAR_tag, 1 ) ;
-
 
549
	    TYPE pu = arg_promote_type ( pt, KILL_err ) ;
-
 
550
	    bs = enc_shape ( bs, pu ) ;
-
 
551
	    if ( ts == NULL ) {
-
 
552
		ts = start_bitstream ( NIL ( FILE ), bs->link ) ;
-
 
553
	    }
-
 
554
	    ENC_variable ( ts ) ;
-
 
555
	    ts = enc_access ( ts, ds ) ;
-
 
556
	    ENC_make_tag ( ts, pn ) ;
-
 
557
	    if ( IS_type_integer ( pt ) ) {
-
 
558
		ENC_change_variety ( ts ) ;
-
 
559
		ts = enc_error_treatment ( ts, pt ) ;
-
 
560
		ts = enc_variety ( ts, pt ) ;
-
 
561
	    } else {
-
 
562
		ENC_change_floating_variety ( ts ) ;
-
 
563
		ENC_impossible ( ts ) ;
-
 
564
		ts = enc_flvar ( ts, pt ) ;
-
 
565
	    }
-
 
566
	    ENC_contents ( ts ) ;
-
 
567
	    ts = enc_shape ( ts, pu ) ;
-
 
568
	    ENC_obtain_tag ( ts ) ;
-
 
569
	    ENC_make_tag ( ts, pm ) ;
-
 
570
	    pn = pm ;
-
 
571
	} else {
-
 
572
	    /* Simple parameter */
-
 
573
	    bs = enc_shape ( bs, pt ) ;
-
 
574
	}
660
	}
575
	bs = enc_access ( bs, ds ) ;
-
 
576
	ENC_make_tag ( bs, pn ) ;
-
 
577
	pids = TAIL_list ( pids ) ;
-
 
578
    }
-
 
579
 
-
 
580
    /* Encode extra function parameters */
-
 
581
    while ( epids ) {
-
 
582
	ulong pn = unit_no ( bs, NULL_id, VAR_tag, 1 ) ;
-
 
583
	bs = enc_shape ( bs, type_sint ) ;
-
 
584
	bs = enc_access ( bs, ds ) ;
661
	bs = enc_compound_stmt(bs, e);
585
	ENC_make_tag ( bs, pn ) ;
-
 
586
	last_params [ DUMMY_extra ] = pn ;
-
 
587
	epids-- ;
-
 
588
    }
-
 
589
 
-
 
590
    /* Encode ellipsis parameter */
-
 
591
    if ( ell & FUNC_ELLIPSIS ) {
-
 
592
	ulong pn ;
-
 
593
	eid = ellipsis_param ( id ) ;
-
 
594
	ASSERT ( !IS_NULL_id ( eid ) ) ;
-
 
595
	pn = unit_no ( bs, eid, VAR_tag, 1 ) ;
-
 
596
	ENC_ON ( bs ) ;
-
 
597
	ENC_make_tag ( bs, pn ) ;
-
 
598
	bs = enc_access ( bs, ds ) ;
-
 
599
	last_params [ DUMMY_ellipsis ] = pn ;
-
 
600
    } else {
-
 
601
	ENC_OFF ( bs ) ;
-
 
602
    }
-
 
603
 
-
 
604
    /* Allow for reference parameters */
-
 
605
    if ( ts ) bs = join_bitstreams ( bs, ts ) ;
-
 
606
    ts = bs ;
-
 
607
 
-
 
608
    /* Encode function body */
-
 
609
    seq += stmt_length ( e ) ;
-
 
610
    if ( diag ) bs = start_bitstream ( NIL ( FILE ), bs->link ) ;
-
 
611
#if LANGUAGE_CPP
662
#if LANGUAGE_CPP
-
 
663
	if (throws) {
612
    if ( throws ) bs = enc_try_func ( bs, post ) ;
664
		bs = enc_catch_func(bs, except, post);
-
 
665
	}
613
#endif
666
#endif
614
    ENC_SEQUENCE ( bs, seq ) ;
-
 
615
    if ( is_main ) bs = enc_special ( bs, TOK_start ) ;
-
 
616
    bs = enc_compound_stmt ( bs, e ) ;
-
 
617
#if LANGUAGE_CPP
-
 
618
    if ( throws ) bs = enc_catch_func ( bs, except, post ) ;
-
 
619
#endif
-
 
620
    if ( diag ) {
667
	if (diag) {
621
	BITSTREAM *us = enc_diag_begin ( &bs ) ;
668
		BITSTREAM *us = enc_diag_begin(&bs);
622
	us = enc_stmt ( us, r ) ;
669
		us = enc_stmt(us, r);
623
	bs = enc_diag_end ( bs, us, r, 1 ) ;
670
		bs = enc_diag_end(bs, us, r, 1);
624
	bs = enc_diag_params ( ts, qids, bs, e ) ;
671
		bs = enc_diag_params(ts, qids, bs, e);
625
    } else {
672
	} else {
626
	bs = enc_stmt ( bs, r ) ;
673
		bs = enc_stmt(bs, r);
627
    }
674
	}
628
    free_exp ( r, 1 ) ;
675
	free_exp(r, 1);
629
 
676
 
630
    /* Clear parameter tag numbers */
677
	/* Clear parameter tag numbers */
631
    pids = qids ;
678
	pids = qids;
632
    while ( !IS_NULL_list ( pids ) ) {
679
	while (!IS_NULL_list(pids)) {
633
	IDENTIFIER pid = DEREF_id ( HEAD_list ( pids ) ) ;
680
		IDENTIFIER pid = DEREF_id(HEAD_list(pids));
634
	clear_no ( pid ) ;
681
		clear_no(pid);
635
	pids = TAIL_list ( pids ) ;
682
		pids = TAIL_list(pids);
636
    }
683
	}
637
    if ( !IS_NULL_id ( eid ) ) clear_no ( eid ) ;
684
	if (!IS_NULL_id(eid)) {
-
 
685
		clear_no(eid);
-
 
686
	}
638
    crt_func_access = dspec_none ;
687
	crt_func_access = dspec_none;
639
    clear_params () ;
688
	clear_params();
640
    return ( bs ) ;
689
	return (bs);
641
}
690
}
642
 
691
 
643
 
692
 
644
/*
693
/*
645
    ENCODE THE START OF A TAG DECLARATION
694
    ENCODE THE START OF A TAG DECLARATION
646
 
695
 
647
    This routine adds the start of a declaration of the tag with identifier
696
    This routine adds the start of a declaration of the tag with identifier
648
    id, capsule number n and type t in the tag declaration unit.  var
697
    id, capsule number n and type t in the tag declaration unit.  var
649
    is 0 if the tag is an identity, 1 for a variable and 2 for a common tag.
698
    is 0 if the tag is an identity, 1 for a variable and 2 for a common tag.
650
    The actual tag type has to be added (t is only used for access checks).
699
    The actual tag type has to be added (t is only used for access checks).
651
*/
700
*/
652
 
701
 
653
BITSTREAM *enc_tagdec_start
702
BITSTREAM *
654
    PROTO_N ( ( id, n, t, var ) )
-
 
655
    PROTO_T ( IDENTIFIER id X ulong n X TYPE t X int var )
703
enc_tagdec_start(IDENTIFIER id, ulong n, TYPE t, int var)
656
{
704
{
657
    unsigned use = USAGE_DECL ;
705
	unsigned use = USAGE_DECL;
658
    BITSTREAM *bs = start_bitstream ( NIL ( FILE ), tagdec_unit->link ) ;
706
	BITSTREAM *bs = start_bitstream(NIL(FILE), tagdec_unit->link);
659
    ulong m = link_no ( bs, n, VAR_tag ) ;
707
	ulong m = link_no(bs, n, VAR_tag);
660
    if ( var == 0 ) {
708
	if (var == 0) {
661
	ENC_make_id_tagdec ( bs ) ;
709
		ENC_make_id_tagdec(bs);
662
    } else if ( var == 1 ) {
710
	} else if (var == 1) {
663
	ENC_make_var_tagdec ( bs ) ;
711
		ENC_make_var_tagdec(bs);
664
    } else {
712
	} else {
665
	ENC_common_tagdec ( bs ) ;
713
		ENC_common_tagdec(bs);
666
	use |= USAGE_COMMON ;
714
		use |= USAGE_COMMON;
667
    }
715
	}
668
    ENC_INT ( bs, m ) ;
716
	ENC_INT(bs, m);
669
    bs = enc_access ( bs, dspec_none ) ;
717
	bs = enc_access(bs, dspec_none);
670
    bs = enc_signature ( bs, id ) ;
718
	bs = enc_signature(bs, id);
671
    record_usage ( n, VAR_tag, use ) ;
719
	record_usage(n, VAR_tag, use);
672
    UNUSED ( t ) ;
720
	UNUSED(t);
673
    return ( bs ) ;
721
	return (bs);
674
}
722
}
675
 
723
 
676
 
724
 
677
/*
725
/*
678
    ENCODE THE END OF A TAG DECLARATION
726
    ENCODE THE END OF A TAG DECLARATION
679
 
727
 
680
    This routine ends the tag declaration started by enc_tagdec_start.
728
    This routine ends the tag declaration started by enc_tagdec_start.
681
*/
729
*/
682
 
730
 
683
void enc_tagdec_end
731
void
684
    PROTO_N ( ( bs ) )
-
 
685
    PROTO_T ( BITSTREAM *bs )
732
enc_tagdec_end(BITSTREAM *bs)
686
{
733
{
687
    count_item ( bs ) ;
734
	count_item(bs);
688
    tagdec_unit = join_bitstreams ( tagdec_unit, bs ) ;
735
	tagdec_unit = join_bitstreams(tagdec_unit, bs);
689
    return ;
736
	return;
690
}
737
}
691
 
738
 
692
 
739
 
693
/*
740
/*
694
    ENCODE A TAG DECLARATION
741
    ENCODE A TAG DECLARATION
695
 
742
 
696
    This routine adds a complete tag declaration to the tag declaration
743
    This routine adds a complete tag declaration to the tag declaration
697
    unit if it has not already been declared.
744
    unit if it has not already been declared.
698
*/
745
*/
699
 
746
 
700
void enc_tagdec
747
void
701
    PROTO_N ( ( id, n, t, var ) )
-
 
702
    PROTO_T ( IDENTIFIER id X ulong n X TYPE t X int var )
748
enc_tagdec(IDENTIFIER id, ulong n, TYPE t, int var)
703
{
749
{
704
    unsigned u = find_usage ( n, VAR_tag ) ;
750
	unsigned u = find_usage(n, VAR_tag);
705
    if ( !( u & USAGE_DECL ) ) {
751
	if (!(u & USAGE_DECL)) {
706
	BITSTREAM *bs = enc_tagdec_start ( id, n, t, var ) ;
752
		BITSTREAM *bs = enc_tagdec_start(id, n, t, var);
707
	bs = enc_shape ( bs, t ) ;
753
		bs = enc_shape(bs, t);
708
	enc_tagdec_end ( bs ) ;
754
		enc_tagdec_end(bs);
709
    }
755
	}
710
    return ;
756
	return;
711
}
757
}
712
 
758
 
713
 
759
 
714
/*
760
/*
715
    ENCODE THE START OF A TAG DEFINITION
761
    ENCODE THE START OF A TAG DEFINITION
716
 
762
 
717
    This routine adds a definition of the tag with identifier id, capsule
763
    This routine adds a definition of the tag with identifier id, capsule
718
    number n and type t to the tag definition unit.  var is as in
764
    number n and type t to the tag definition unit.  var is as in
719
    enc_tagdec_start.  The routine returns a bitstream to allow the actual
765
    enc_tagdec_start.  The routine returns a bitstream to allow the actual
720
    definition to be added.
766
    definition to be added.
721
*/
767
*/
722
 
768
 
723
BITSTREAM *enc_tagdef_start
769
BITSTREAM *
724
    PROTO_N ( ( id, n, t, var ) )
-
 
725
    PROTO_T ( IDENTIFIER id X ulong n X TYPE t X int var )
770
enc_tagdef_start(IDENTIFIER id, ulong n, TYPE t, int var)
726
{
771
{
727
    unsigned use = USAGE_DEFN ;
772
	unsigned use = USAGE_DEFN;
728
    BITSTREAM *bs = start_bitstream ( NIL ( FILE ), tagdef_unit->link ) ;
773
	BITSTREAM *bs = start_bitstream(NIL(FILE), tagdef_unit->link);
729
    ulong m = link_no ( bs, n, VAR_tag ) ;
774
	ulong m = link_no(bs, n, VAR_tag);
730
    if ( var == 0 ) {
775
	if (var == 0) {
731
	ENC_make_id_tagdef ( bs ) ;
776
		ENC_make_id_tagdef(bs);
732
    } else if ( var == 1 ) {
777
	} else if (var == 1) {
733
	ENC_make_var_tagdef ( bs ) ;
778
		ENC_make_var_tagdef(bs);
734
    } else {
779
	} else {
735
	ENC_common_tagdef ( bs ) ;
780
		ENC_common_tagdef(bs);
736
	use |= USAGE_COMMON ;
781
		use |= USAGE_COMMON;
737
    }
782
	}
738
    ENC_INT ( bs, m ) ;
783
	ENC_INT(bs, m);
-
 
784
	if (var) {
739
    if ( var ) bs = enc_access ( bs, dspec_none ) ;
785
		bs = enc_access(bs, dspec_none);
-
 
786
	}
740
    bs = enc_signature ( bs, id ) ;
787
	bs = enc_signature(bs, id);
741
    record_usage ( n, VAR_tag, use ) ;
788
	record_usage(n, VAR_tag, use);
742
    UNUSED ( t ) ;
789
	UNUSED(t);
743
    return ( bs ) ;
790
	return (bs);
744
}
791
}
745
 
792
 
746
 
793
 
747
/*
794
/*
748
    ENCODE THE END OF A TAG DEFINITION
795
    ENCODE THE END OF A TAG DEFINITION
749
 
796
 
750
    This routine ends the tag definition started by enc_tagdef_start.
797
    This routine ends the tag definition started by enc_tagdef_start.
751
*/
798
*/
752
 
799
 
753
void enc_tagdef_end
800
void
754
    PROTO_N ( ( bs ) )
-
 
755
    PROTO_T ( BITSTREAM *bs )
801
enc_tagdef_end(BITSTREAM *bs)
756
{
802
{
757
    count_item ( bs ) ;
803
	count_item(bs);
758
    tagdef_unit = join_bitstreams ( tagdef_unit, bs ) ;
804
	tagdef_unit = join_bitstreams(tagdef_unit, bs);
759
    return ;
805
	return;
760
}
806
}
761
 
807
 
762
 
808
 
763
/*
809
/*
764
    CREATE A TAG DEFINITION
810
    CREATE A TAG DEFINITION
765
 
811
 
Line 769... Line 815...
769
    null identifier, indicating a local tag, and e can be the null
815
    null identifier, indicating a local tag, and e can be the null
770
    expression, indicating that the tag is only declared.  The routine
816
    expression, indicating that the tag is only declared.  The routine
771
    returns the external (capsule) tag number.
817
    returns the external (capsule) tag number.
772
*/
818
*/
773
 
819
 
774
ulong make_tagdef
820
ulong
775
    PROTO_N ( ( id, t, e, d, var ) )
-
 
776
    PROTO_T ( IDENTIFIER id X TYPE t X EXP e X EXP d X int var )
821
make_tagdef(IDENTIFIER id, TYPE t, EXP e, EXP d, int var)
777
{
822
{
778
    ulong n ;
823
	ulong n;
779
    int fn = 0 ;
824
	int fn = 0;
780
    int def = 1 ;
825
	int def = 1;
781
    LOCATION loc ;
826
	LOCATION loc;
782
 
827
 
783
    /* Find the tag number */
828
	/* Find the tag number */
784
    bad_crt_loc++ ;
829
	bad_crt_loc++;
785
    loc = crt_loc ;
830
	loc = crt_loc;
786
    if ( IS_NULL_id ( id ) ) {
831
	if (IS_NULL_id(id)) {
787
	n = capsule_no ( NULL_string, VAR_tag ) ;
832
		n = capsule_no(NULL_string, VAR_tag);
788
    } else {
833
	} else {
789
	PTR ( LOCATION ) ploc = id_loc ( id ) ;
834
		PTR(LOCATION)ploc = id_loc(id);
790
	DEREF_loc ( ploc, crt_loc ) ;
835
		DEREF_loc(ploc, crt_loc);
791
	crt_enc_loc = ploc ;
836
		crt_enc_loc = ploc;
792
	IGNORE capsule_id ( id, VAR_tag ) ;
837
		IGNORE capsule_id(id, VAR_tag);
793
	n = DEREF_ulong ( id_no ( id ) ) ;
838
		n = DEREF_ulong(id_no(id));
794
	if ( IS_id_function_etc ( id ) ) {
839
		if (IS_id_function_etc(id)) {
795
	    var = 0 ;
840
			var = 0;
796
	    fn = 1 ;
841
			fn = 1;
-
 
842
		}
797
	}
843
	}
798
    }
-
 
799
 
-
 
800
    /* Encode the declaration */
-
 
801
    enc_tagdec ( id, n, t, var ) ;
-
 
802
 
844
 
-
 
845
	/* Encode the declaration */
-
 
846
	enc_tagdec(id, n, t, var);
-
 
847
 
803
    /* Check for definition */
848
	/* Check for definition */
804
    if ( !IS_NULL_exp ( e ) ) {
849
	if (!IS_NULL_exp(e)) {
805
	BITSTREAM *bs ;
850
		BITSTREAM *bs;
806
	EXP d1 = NULL_exp ;
851
		EXP d1 = NULL_exp;
807
	int uc = unreached_code ;
852
		int uc = unreached_code;
808
	if ( !IS_NULL_exp ( d ) ) {
853
		if (!IS_NULL_exp(d)) {
809
	    if ( !output_term ) {
854
			if (!output_term) {
810
		/* Set up terminator if necessary */
855
				/* Set up terminator if necessary */
811
		d1 = d ;
856
				d1 = d;
812
		d = NULL_exp ;
857
				d = NULL_exp;
813
		make_term_global ( t, &d1 ) ;
858
				make_term_global(t, &d1);
814
	    }
859
			}
815
	    term_no++ ;
860
			term_no++;
816
	}
861
		}
817
	bs = enc_tagdef_start ( id, n, t, var ) ;
862
		bs = enc_tagdef_start(id, n, t, var);
818
	unreached_code = 0 ;
863
		unreached_code = 0;
819
	if ( fn ) {
864
		if (fn) {
820
	    /* Function definition */
865
			/* Function definition */
821
	    bs = enc_func_defn ( bs, id, e ) ;
866
			bs = enc_func_defn(bs, id, e);
822
	} else if ( var ) {
867
		} else if (var) {
823
	    /* Variable definition */
868
			/* Variable definition */
824
	    bs = enc_init_global ( bs, e, d1, n, t ) ;
869
			bs = enc_init_global(bs, e, d1, n, t);
-
 
870
		} else {
-
 
871
			/* Identity definition */
-
 
872
			int i = in_static_init;
-
 
873
			in_static_init = 1;
-
 
874
			bs = enc_addr_exp(bs, t, e);
-
 
875
			in_static_init = i;
-
 
876
		}
-
 
877
		unreached_code = uc;
-
 
878
		enc_tagdef_end(bs);
-
 
879
 
-
 
880
		/* Check for destructor */
-
 
881
		if (!IS_NULL_exp(d)) {
-
 
882
			BITSTREAM *ts = term_func;
-
 
883
			ts = enc_term_global(ts, n, t, d, LINK_NONE);
-
 
884
			term_func = ts;
-
 
885
		}
825
	} else {
886
	} else {
826
	    /* Identity definition */
887
		/* Only declared */
827
	    int i = in_static_init ;
888
		if (!IS_NULL_id(id)) {
828
	    in_static_init = 1 ;
889
			string s = NULL;
829
	    bs = enc_addr_exp ( bs, t, e ) ;
890
			IGNORE capsule_name(n, &s, VAR_tag);
830
	    in_static_init = i ;
891
			if (s == NULL) {
831
	}
-
 
832
	unreached_code = uc ;
892
				if (has_linkage(id)) {
833
	enc_tagdef_end ( bs ) ;
893
					/* Doesn't have external name */
834
 
-
 
835
	/* Check for destructor */
894
					report(crt_loc,
836
	if ( !IS_NULL_exp ( d ) ) {
895
					       ERR_basic_odr_undef(id));
-
 
896
				}
837
	    BITSTREAM *ts = term_func ;
897
				s = mangle_anon();
-
 
898
			}
838
	    ts = enc_term_global ( ts, n, t, d, LINK_NONE ) ;
899
			IGNORE capsule_name(n, &s, VAR_tag);
839
	    term_func = ts ;
900
			def = 0;
-
 
901
		}
840
	}
902
	}
841
    } else {
-
 
842
	/* Only declared */
-
 
843
	if ( !IS_NULL_id ( id ) ) {
903
	if (!IS_NULL_id(id) && output_diag) {
844
	    string s = NULL ;
-
 
845
	    IGNORE capsule_name ( n, &s, VAR_tag ) ;
904
		HASHID nm = DEREF_hashid(id_name(id));
846
	    if ( s == NULL ) {
-
 
847
		if ( has_linkage ( id ) ) {
905
		if (!IS_hashid_anon(nm)) {
848
		    /* Doesn't have external name */
906
			enc_diag_id(id, def);
849
		    report ( crt_loc, ERR_basic_odr_undef ( id ) ) ;
-
 
850
		}
907
		}
851
		s = mangle_anon () ;
-
 
852
	    }
-
 
853
	    IGNORE capsule_name ( n, &s, VAR_tag ) ;
-
 
854
	    def = 0 ;
-
 
855
	}
908
	}
856
    }
-
 
857
    if ( !IS_NULL_id ( id ) && output_diag ) {
-
 
858
	HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
-
 
859
	if ( !IS_hashid_anon ( nm ) ) enc_diag_id ( id, def ) ;
-
 
860
    }
-
 
861
    crt_loc = loc ;
909
	crt_loc = loc;
862
    bad_crt_loc-- ;
910
	bad_crt_loc--;
863
    return ( n ) ;
911
	return (n);
864
}
912
}
865
 
913
 
866
 
914
 
867
/*
915
/*
868
    CREATE THE DYNAMIC INITIALISATION FUNCTIONS
916
    CREATE THE DYNAMIC INITIALISATION FUNCTIONS
869
 
917
 
870
    This routine creates the dynamic initialisation and termination
918
    This routine creates the dynamic initialisation and termination
871
    functions.
919
    functions.
872
*/
920
*/
873
 
921
 
874
void enc_dynamic_init
922
void
875
    PROTO_Z ()
923
enc_dynamic_init (void)
876
{
924
{
877
    BITSTREAM *bs ;
925
	BITSTREAM *bs;
878
    ulong m1 = LINK_NONE ;
926
	ulong m1 = LINK_NONE;
879
    ulong m2 = LINK_NONE ;
927
	ulong m2 = LINK_NONE;
880
    ulong init = init_no ;
928
	ulong init = init_no;
881
    ulong term = term_no ;
929
	ulong term = term_no;
882
    int diag = output_diag ;
930
	int diag = output_diag;
883
    if ( output_all ) diag = 1 ;
-
 
884
 
-
 
885
    /* Create the termination function */
-
 
886
    if ( term ) {
-
 
887
	if ( output_term ) {
931
	if (output_all) {
888
	    /* Define the termination function */
-
 
889
	    TYPE t = dummy_func ;
-
 
890
	    m1 = capsule_no ( NULL_string, VAR_tag ) ;
-
 
891
	    if ( diag ) enc_diag_init ( "__term", m1, t ) ;
-
 
892
	    enc_tagdec ( NULL_id, m1, t, 0 ) ;
-
 
893
	    bs = enc_tagdef_start ( NULL_id, m1, t, 0 ) ;
-
 
894
	    ENC_make_proc ( bs ) ;
-
 
895
	    ENC_top ( bs ) ;
-
 
896
	    ENC_LIST_SMALL ( bs, 0 ) ;
-
 
897
	    ENC_OFF ( bs ) ;
-
 
898
	    ENC_SEQUENCE ( bs, term ) ;
-
 
899
	    bs = join_bitstreams ( bs, term_static_func ) ;
-
 
900
	    bs = join_bitstreams ( bs, term_func ) ;
-
 
901
	    ENC_return ( bs ) ;
-
 
902
	    ENC_make_top ( bs ) ;
-
 
903
	    enc_tagdef_end ( bs ) ;
-
 
904
 
-
 
905
	    /* Define the termination link */
-
 
906
	    m2 = capsule_no ( NULL_string, VAR_tag ) ;
-
 
907
	    bs = enc_tagdec_start ( NULL_id, m2, NULL_type, 1 ) ;
-
 
908
	    bs = enc_special ( bs, TOK_destr_type ) ;
-
 
909
	    enc_tagdec_end ( bs ) ;
-
 
910
	    bs = enc_tagdef_start ( NULL_id, m2, NULL_type, 1 ) ;
-
 
911
	    bs = enc_special ( bs, TOK_destr_null ) ;
-
 
912
	    enc_tagdef_end ( bs ) ;
-
 
913
	    init++ ;
-
 
914
	}
-
 
915
	init++ ;
-
 
916
    }
-
 
917
 
-
 
918
    /* Create the initialisation function */
-
 
919
    if ( init ) {
-
 
920
	int var = 1 ;
932
		diag = 1;
921
	TYPE t = type_sint ;
-
 
922
	TYPE s = t ;
-
 
923
	string nm = mangle_init () ;
-
 
924
	ulong n1 = capsule_no ( nm, VAR_tag ) ;
-
 
925
	if ( output_init ) {
-
 
926
	    /* Initialisation function required */
-
 
927
	    t = dummy_func ;
-
 
928
	    var = 0 ;
-
 
929
	}
-
 
930
	if ( diag ) enc_diag_init ( "__init", n1, t ) ;
-
 
931
	enc_tagdec ( NULL_id, n1, t, var ) ;
-
 
932
	bs = enc_tagdef_start ( NULL_id, n1, t, var ) ;
-
 
933
	if ( var == 0 ) {
-
 
934
	    ENC_make_proc ( bs ) ;
-
 
935
	    bs = enc_shape ( bs, s ) ;
-
 
936
	    ENC_LIST_SMALL ( bs, 0 ) ;
-
 
937
	    ENC_OFF ( bs ) ;
-
 
938
	} else {
-
 
939
	    ENC_initial_value ( bs ) ;
-
 
940
	}
933
	}
-
 
934
 
941
	ENC_SEQUENCE ( bs, init ) ;
935
	/* Create the termination function */
942
	if ( term ) {
936
	if (term) {
-
 
937
		if (output_term) {
943
	    /* Initialise termination function */
938
			/* Define the termination function */
-
 
939
			TYPE t = dummy_func;
-
 
940
			m1 = capsule_no(NULL_string, VAR_tag);
-
 
941
			if (diag) {
-
 
942
				enc_diag_init("__term", m1, t);
-
 
943
			}
-
 
944
			enc_tagdec(NULL_id, m1, t, 0);
-
 
945
			bs = enc_tagdef_start(NULL_id, m1, t, 0);
-
 
946
			ENC_make_proc(bs);
-
 
947
			ENC_top(bs);
-
 
948
			ENC_LIST_SMALL(bs, 0);
-
 
949
			ENC_OFF(bs);
-
 
950
			ENC_SEQUENCE(bs, term);
-
 
951
			bs = join_bitstreams(bs, term_static_func);
-
 
952
			bs = join_bitstreams(bs, term_func);
-
 
953
			ENC_return(bs);
-
 
954
			ENC_make_top(bs);
-
 
955
			enc_tagdef_end(bs);
-
 
956
 
-
 
957
			/* Define the termination link */
-
 
958
			m2 = capsule_no(NULL_string, VAR_tag);
-
 
959
			bs = enc_tagdec_start(NULL_id, m2, NULL_type, 1);
-
 
960
			bs = enc_special(bs, TOK_destr_type);
-
 
961
			enc_tagdec_end(bs);
-
 
962
			bs = enc_tagdef_start(NULL_id, m2, NULL_type, 1);
944
	    bs = enc_special ( bs, TOK_destr_init ) ;
963
			bs = enc_special(bs, TOK_destr_null);
-
 
964
			enc_tagdef_end(bs);
-
 
965
			init++;
-
 
966
		}
-
 
967
		init++;
945
	}
968
	}
-
 
969
 
-
 
970
	/* Create the initialisation function */
-
 
971
	if (init) {
-
 
972
		int var = 1;
-
 
973
		TYPE t = type_sint;
-
 
974
		TYPE s = t;
-
 
975
		string nm = mangle_init();
-
 
976
		ulong n1 = capsule_no(nm, VAR_tag);
-
 
977
		if (output_init) {
-
 
978
			/* Initialisation function required */
-
 
979
			t = dummy_func;
-
 
980
			var = 0;
-
 
981
		}
-
 
982
		if (diag) {
-
 
983
			enc_diag_init("__init", n1, t);
-
 
984
		}
-
 
985
		enc_tagdec(NULL_id, n1, t, var);
-
 
986
		bs = enc_tagdef_start(NULL_id, n1, t, var);
-
 
987
		if (var == 0) {
-
 
988
			ENC_make_proc(bs);
-
 
989
			bs = enc_shape(bs, s);
-
 
990
			ENC_LIST_SMALL(bs, 0);
-
 
991
			ENC_OFF(bs);
-
 
992
		} else {
-
 
993
			ENC_initial_value(bs);
-
 
994
		}
-
 
995
		ENC_SEQUENCE(bs, init);
-
 
996
		if (term) {
-
 
997
			/* Initialise termination function */
-
 
998
			bs = enc_special(bs, TOK_destr_init);
-
 
999
		}
946
	bs = join_bitstreams ( bs, init_func ) ;
1000
		bs = join_bitstreams(bs, init_func);
947
	if ( m1 != LINK_NONE ) {
1001
		if (m1 != LINK_NONE) {
948
	    /* Set up termination function */
1002
			/* Set up termination function */
949
	    ulong n ;
1003
			ulong n;
950
	    BITSTREAM *ts ;
1004
			BITSTREAM *ts;
951
	    bs = enc_special ( bs, TOK_destr_global ) ;
1005
			bs = enc_special(bs, TOK_destr_global);
952
	    ts = start_bitstream ( NIL ( FILE ), bs->link ) ;
1006
			ts = start_bitstream(NIL(FILE), bs->link);
953
	    n = link_no ( ts, m2, VAR_tag ) ;
1007
			n = link_no(ts, m2, VAR_tag);
954
	    ENC_obtain_tag ( ts ) ;
1008
			ENC_obtain_tag(ts);
955
	    ENC_make_tag ( ts, n ) ;
1009
			ENC_make_tag(ts, n);
956
	    ENC_make_null_ptr ( ts ) ;
1010
			ENC_make_null_ptr(ts);
957
	    ts = enc_special ( ts, TOK_empty_align ) ;
1011
			ts = enc_special(ts, TOK_empty_align);
958
	    n = link_no ( ts, m1, VAR_tag ) ;
1012
			n = link_no(ts, m1, VAR_tag);
959
	    ENC_obtain_tag ( ts ) ;
1013
			ENC_obtain_tag(ts);
960
	    ENC_make_tag ( ts, n ) ;
1014
			ENC_make_tag(ts, n);
961
	    bs = enc_bitstream ( bs, ts ) ;
1015
			bs = enc_bitstream(bs, ts);
-
 
1016
		}
-
 
1017
		if (var == 0) {
-
 
1018
			ENC_return(bs);
-
 
1019
		}
-
 
1020
		bs = enc_make_int(bs, s, 1);
-
 
1021
		enc_tagdef_end(bs);
-
 
1022
 
-
 
1023
		/* Set up initialisation variable */
-
 
1024
		if (var == 0 && nm == NULL) {
-
 
1025
			ulong n2 = capsule_no(NULL_string, VAR_tag);
-
 
1026
			if (diag) {
-
 
1027
				enc_diag_init("__init2", n2, s);
-
 
1028
			}
-
 
1029
			enc_tagdec(NULL_id, n2, s, 1);
-
 
1030
			bs = enc_tagdef_start(NULL_id, n2, s, 1);
-
 
1031
			ENC_initial_value(bs);
-
 
1032
			ENC_apply_proc(bs);
-
 
1033
			bs = enc_shape(bs, s);
-
 
1034
			n1 = link_no(bs, n1, VAR_tag);
-
 
1035
			ENC_obtain_tag(bs);
-
 
1036
			ENC_make_tag(bs, n1);
-
 
1037
			ENC_LIST_SMALL(bs, 0);
-
 
1038
			ENC_OFF(bs);
-
 
1039
			enc_tagdef_end(bs);
-
 
1040
		}
962
	}
1041
	}
963
	if ( var == 0 ) ENC_return ( bs ) ;
-
 
964
	bs = enc_make_int ( bs, s, 1 ) ;
-
 
965
	enc_tagdef_end ( bs ) ;
-
 
966
 
-
 
967
	/* Set up initialisation variable */
-
 
968
	if ( var == 0 && nm == NULL ) {
-
 
969
	    ulong n2 = capsule_no ( NULL_string, VAR_tag ) ;
-
 
970
	    if ( diag ) enc_diag_init ( "__init2", n2, s ) ;
-
 
971
	    enc_tagdec ( NULL_id, n2, s, 1 ) ;
-
 
972
	    bs = enc_tagdef_start ( NULL_id, n2, s, 1 ) ;
-
 
973
	    ENC_initial_value ( bs ) ;
-
 
974
	    ENC_apply_proc ( bs ) ;
-
 
975
	    bs = enc_shape ( bs, s ) ;
-
 
976
	    n1 = link_no ( bs, n1, VAR_tag ) ;
-
 
977
	    ENC_obtain_tag ( bs ) ;
-
 
978
	    ENC_make_tag ( bs, n1 ) ;
-
 
979
	    ENC_LIST_SMALL ( bs, 0 ) ;
-
 
980
	    ENC_OFF ( bs ) ;
-
 
981
	    enc_tagdef_end ( bs ) ;
-
 
982
	}
-
 
983
    }
-
 
984
    return ;
1042
	return;
985
}
1043
}
986
 
1044
 
987
 
1045
 
988
/*
1046
/*
989
    CREATE A TOKEN DECLARATION
1047
    CREATE A TOKEN DECLARATION
990
 
1048
 
991
    This routine creates a token declaration body bitstream for a token
1049
    This routine creates a token declaration body bitstream for a token
992
    with external (capsule) number n and sort sorts.  This is only output
1050
    with external (capsule) number n and sort sorts.  This is only output
993
    for tokens with at least one parameter to aid in pretty-printing.
1051
    for tokens with at least one parameter to aid in pretty-printing.
994
*/
1052
*/
995
 
1053
 
996
void enc_tokdec
1054
void
997
    PROTO_N ( ( n, sorts ) )
-
 
998
    PROTO_T ( ulong n X CONST char *sorts )
1055
enc_tokdec(ulong n, CONST char *sorts)
999
{
1056
{
1000
    BITSTREAM *bs = tokdec_unit ;
1057
	BITSTREAM *bs = tokdec_unit;
1001
    if ( bs ) {
1058
	if (bs) {
1002
	char res = *( sorts++ ) ;
1059
		char res = *(sorts++);
1003
	char arg = *sorts ;
1060
		char arg = *sorts;
1004
	if ( arg ) {
1061
		if (arg) {
1005
	    ulong m = link_no ( bs, n, VAR_token ) ;
1062
			ulong m = link_no(bs, n, VAR_token);
1006
	    record_usage ( n, VAR_token, USAGE_DECL ) ;
1063
			record_usage(n, VAR_token, USAGE_DECL);
1007
	    ENC_make_tokdec ( bs ) ;
1064
			ENC_make_tokdec(bs);
1008
	    ENC_INT ( bs, m ) ;
1065
			ENC_INT(bs, m);
1009
	    bs = enc_signature ( bs, NULL_id ) ;
1066
			bs = enc_signature(bs, NULL_id);
1010
	    ENC_token ( bs ) ;
1067
			ENC_token(bs);
1011
#if ( TDF_major >= 4 )
1068
#if (TDF_major >= 4)
1012
	    /* Result sort first after TDF 4.0 */
1069
			/* Result sort first after TDF 4.0 */
1013
	    bs = enc_sort ( bs, ( int ) res ) ;
1070
			bs = enc_sort(bs,(int)res);
1014
#endif
1071
#endif
1015
	    ENC_LIST ( bs, strlen ( sorts ) ) ;
1072
			ENC_LIST(bs, strlen(sorts));
1016
	    while ( arg = *( sorts++ ), arg != 0 ) {
1073
			while (arg = *(sorts++), arg != 0) {
1017
		bs = enc_sort ( bs, ( int ) arg ) ;
1074
				bs = enc_sort(bs,(int)arg);
1018
	    }
1075
			}
1019
#if ( TDF_major < 4 )
1076
#if (TDF_major < 4)
1020
	    /* Result sort last before TDF 4.0 */
1077
			/* Result sort last before TDF 4.0 */
1021
	    bs = enc_sort ( bs, ( int ) res ) ;
1078
			bs = enc_sort(bs,(int)res);
1022
#endif
1079
#endif
1023
	    count_item ( bs ) ;
1080
			count_item(bs);
1024
	    tokdec_unit = bs ;
1081
			tokdec_unit = bs;
1025
	}
1082
		}
1026
    }
1083
	}
1027
    return ;
1084
	return;
1028
}
1085
}
1029
 
1086
 
1030
 
1087
 
1031
/*
1088
/*
1032
    START A TOKEN DEFINITION
1089
    START A TOKEN DEFINITION
1033
 
1090
 
1034
    This routine creates a token definition body bitstream for a token
1091
    This routine creates a token definition body bitstream for a token
1035
    with external (capsule) number n and sort given by sorts.  This
1092
    with external (capsule) number n and sort given by sorts.  This
1036
    includes the allocation of any parameter token numbers, which are
1093
    includes the allocation of any parameter token numbers, which are
1037
    returned via pars.
1094
    returned via pars.
1038
*/
1095
*/
1039
 
1096
 
1040
BITSTREAM *enc_tokdef_start
1097
BITSTREAM *
1041
    PROTO_N ( ( n, sorts, pars, d ) )
-
 
1042
    PROTO_T ( ulong n X CONST char *sorts X ulong *pars X int d )
1098
enc_tokdef_start(ulong n, CONST char *sorts, ulong *pars, int d)
1043
{
1099
{
1044
    char res ;
1100
	char res;
1045
    unsigned i, m ;
1101
	unsigned i, m;
1046
    BITSTREAM *bs ;
1102
	BITSTREAM *bs;
-
 
1103
	if (d) {
1047
    if ( d ) enc_tokdec ( n, sorts ) ;
1104
		enc_tokdec(n, sorts);
-
 
1105
	}
1048
    record_usage ( n, VAR_token, USAGE_DEFN ) ;
1106
	record_usage(n, VAR_token, USAGE_DEFN);
1049
    bs = start_bitstream ( NIL ( FILE ), tokdef_unit->link ) ;
1107
	bs = start_bitstream(NIL(FILE), tokdef_unit->link);
1050
    ENC_token_definition ( bs ) ;
1108
	ENC_token_definition(bs);
1051
    res = *( sorts++ ) ;
1109
	res = *(sorts++);
1052
    bs = enc_sort ( bs, ( int ) res ) ;
1110
	bs = enc_sort(bs,(int)res);
1053
    m = ( unsigned ) strlen ( sorts ) ;
1111
	m = (unsigned)strlen(sorts);
1054
    ENC_LIST ( bs, m ) ;
1112
	ENC_LIST(bs, m);
1055
    for ( i = 0 ; i < m ; i++ ) {
1113
	for (i = 0; i < m; i++) {
1056
	/* Encode token parameters */
1114
		/* Encode token parameters */
1057
	char arg = sorts [i] ;
1115
		char arg = sorts[i];
1058
	ulong r = unit_no ( bs, NULL_id, VAR_token, 1 ) ;
1116
		ulong r = unit_no(bs, NULL_id, VAR_token, 1);
1059
	bs = enc_sort ( bs, ( int ) arg ) ;
1117
		bs = enc_sort(bs,(int)arg);
1060
	ENC_INT ( bs, r ) ;
1118
		ENC_INT(bs, r);
1061
	pars [i] = r ;
1119
		pars[i] = r;
1062
    }
1120
	}
1063
    return ( bs ) ;
1121
	return (bs);
1064
}
1122
}
1065
 
1123
 
1066
 
1124
 
1067
/*
1125
/*
1068
    COMPLETE A TOKEN DEFINITION
1126
    COMPLETE A TOKEN DEFINITION
1069
 
1127
 
1070
    This routine adds the definition of the token with external (capsule)
1128
    This routine adds the definition of the token with external (capsule)
1071
    number n and token definition body ps to the main token definition unit.
1129
    number n and token definition body ps to the main token definition unit.
1072
*/
1130
*/
1073
 
1131
 
1074
void enc_tokdef_end
1132
void
1075
    PROTO_N ( ( n, ps ) )
-
 
1076
    PROTO_T ( ulong n X BITSTREAM *ps )
1133
enc_tokdef_end(ulong n, BITSTREAM *ps)
1077
{
1134
{
1078
    BITSTREAM *bs = tokdef_unit ;
1135
	BITSTREAM *bs = tokdef_unit;
1079
    ulong m = link_no ( bs, n, VAR_token ) ;
1136
	ulong m = link_no(bs, n, VAR_token);
1080
    ENC_make_tokdef ( bs ) ;
1137
	ENC_make_tokdef(bs);
1081
    ENC_INT ( bs, m ) ;
1138
	ENC_INT(bs, m);
1082
    bs = enc_signature ( bs, NULL_id ) ;
1139
	bs = enc_signature(bs, NULL_id);
1083
    bs = enc_bitstream ( bs, ps ) ;
1140
	bs = enc_bitstream(bs, ps);
1084
    count_item ( bs ) ;
1141
	count_item(bs);
1085
    tokdef_unit = bs ;
1142
	tokdef_unit = bs;
1086
    return ;
1143
	return;
1087
}
1144
}
1088
 
1145
 
1089
 
1146
 
1090
/*
1147
/*
1091
    ENCODE A TOKEN DEFINITION
1148
    ENCODE A TOKEN DEFINITION
1092
 
1149
 
1093
    This routine encodes the declaration and, if necessary, the definition
1150
    This routine encodes the declaration and, if necessary, the definition
1094
    of the token id.  If def is true then a dummy definition is output even
1151
    of the token id.  If def is true then a dummy definition is output even
1095
    if id is not defined. It returns the code letter of the return sort.
1152
    if id is not defined. It returns the code letter of the return sort.
1096
*/
1153
*/
1097
 
1154
 
1098
int enc_tokdef
1155
int
1099
    PROTO_N ( ( id, def ) )
-
 
1100
    PROTO_T ( IDENTIFIER id X int def )
1156
enc_tokdef(IDENTIFIER id, int def)
1101
{
1157
{
1102
    int dec ;
1158
	int dec;
1103
    ulong n ;
1159
	ulong n;
1104
    BUFFER *bf ;
1160
	BUFFER *bf;
1105
    unsigned npars = 0 ;
1161
	unsigned npars = 0;
1106
    IDENTIFIER fid = NULL_id ;
1162
	IDENTIFIER fid = NULL_id;
1107
    TOKEN tok = DEREF_tok ( id_token_sort ( id ) ) ;
1163
	TOKEN tok = DEREF_tok(id_token_sort(id));
1108
    unsigned tag = TAG_tok ( tok ) ;
1164
	unsigned tag = TAG_tok(tok);
1109
    int r = token_code ( tok ) ;
1165
	int r = token_code(tok);
1110
 
1166
 
1111
    /* Check for declaration and definition */
1167
	/* Check for declaration and definition */
1112
    DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
1168
	DECL_SPEC ds = DEREF_dspec(id_storage(id));
1113
    if ( ds & dspec_auto ) {
1169
	if (ds & dspec_auto) {
1114
	/* Token parameter */
1170
		/* Token parameter */
1115
	LOCATION loc ;
1171
		LOCATION loc;
1116
	if ( ds & dspec_register ) return ( r ) ;
1172
		if (ds & dspec_register) {
-
 
1173
			return (r);
-
 
1174
		}
1117
	DEREF_loc ( id_loc ( id ), loc ) ;
1175
		DEREF_loc(id_loc(id), loc);
1118
	report ( loc, ERR_token_scope ( id ) ) ;
1176
		report(loc, ERR_token_scope(id));
1119
	ds |= dspec_register ;
1177
		ds |= dspec_register;
1120
	COPY_dspec ( id_storage ( id ), ds ) ;
1178
		COPY_dspec(id_storage(id), ds);
1121
	clear_no ( id ) ;
1179
		clear_no(id);
1122
    }
-
 
1123
    if ( ds & dspec_defn ) def = 1 ;
-
 
1124
    dec = capsule_id ( id, VAR_token ) ;
-
 
1125
    if ( def ) {
-
 
1126
	if ( ds & dspec_done ) return ( r ) ;
-
 
1127
    } else if ( dec ) {
-
 
1128
	if ( tokdec_unit == NULL ) return ( r ) ;
-
 
1129
    } else {
-
 
1130
	return ( r ) ;
-
 
1131
    }
-
 
1132
 
-
 
1133
    /* Construct token sort */
-
 
1134
    bf = clear_buffer ( &mangle_buff, NIL ( FILE ) ) ;
-
 
1135
    bfputc ( bf, r ) ;
-
 
1136
    if ( tag == tok_func_tag ) {
-
 
1137
	/* Function token */
-
 
1138
	fid = DEREF_id ( tok_func_defn ( tok ) ) ;
-
 
1139
	tok = func_proc_token ( tok ) ;
-
 
1140
	tag = TAG_tok ( tok ) ;
-
 
1141
	if ( tag != tok_proc_tag ) {
-
 
1142
	    /* Ellipsis function */
-
 
1143
	    return ( r ) ;
-
 
1144
	}
-
 
1145
    }
-
 
1146
    if ( tag == tok_proc_tag ) {
-
 
1147
	/*  Parameters for procedure tokens */
-
 
1148
	LIST ( IDENTIFIER ) p = DEREF_list ( tok_proc_bids ( tok ) ) ;
-
 
1149
	while ( !IS_NULL_list ( p ) ) {
-
 
1150
	    IDENTIFIER pid = DEREF_id ( HEAD_list ( p ) ) ;
-
 
1151
	    if ( !IS_NULL_id ( pid ) && IS_id_token ( pid ) ) {
-
 
1152
		TOKEN ptok = DEREF_tok ( id_token_sort ( pid ) ) ;
-
 
1153
		int s = token_code ( ptok ) ;
-
 
1154
		npars++ ;
-
 
1155
		bfputc ( bf, s ) ;
-
 
1156
	    }
-
 
1157
	    p = TAIL_list ( p ) ;
-
 
1158
	}
1180
	}
1159
    }
-
 
1160
    bfputc ( bf, 0 ) ;
1181
	if (ds & dspec_defn) {
1161
 
-
 
1162
    /* Output declaration and definition */
-
 
1163
    n = DEREF_ulong ( id_no ( id ) ) ;
-
 
1164
    if ( dec ) {
1182
		def = 1;
1165
	enc_tokdec ( n, strlit ( bf->start ) ) ;
-
 
1166
    }
1183
	}
1167
    if ( def ) {
-
 
1168
	BITSTREAM *bs ;
-
 
1169
	ulong std_pars [20] ;
-
 
1170
	ulong *pars = std_pars ;
-
 
1171
	if ( npars >= 20 ) pars = xmalloc_nof ( ulong, npars ) ;
-
 
1172
	bs = enc_tokdef_start ( n, strlit ( bf->start ), pars, 0 ) ;
-
 
1173
	COPY_dspec ( id_storage ( id ), ( ds | dspec_done ) ) ;
-
 
1174
	COPY_ulong ( id_no ( id ), LINK_TOKDEF ) ;
-
 
1175
	last_params [ DUMMY_token ] = n ;
-
 
1176
	if ( tag == tok_proc_tag ) {
-
 
1177
	    unsigned i = 0 ;
-
 
1178
	    if ( IS_NULL_id ( fid ) ) {
1184
	dec = capsule_id(id, VAR_token);
1179
		/* Procedure tokens */
-
 
1180
		LIST ( IDENTIFIER ) p, q ;
-
 
1181
		p = DEREF_list ( tok_proc_bids ( tok ) ) ;
-
 
1182
		q = p ;
1185
	if (def) {
1183
		while ( !IS_NULL_list ( q ) ) {
-
 
1184
		    IDENTIFIER pid = DEREF_id ( HEAD_list ( q ) ) ;
-
 
1185
		    if ( !IS_NULL_id ( pid ) && IS_id_token ( pid ) ) {
-
 
1186
			DECL_SPEC pds = DEREF_dspec ( id_storage ( pid ) ) ;
-
 
1187
			pds |= dspec_register ;
1186
		if (ds & dspec_done) {
1188
			COPY_dspec ( id_storage ( pid ), pds ) ;
-
 
1189
			COPY_ulong ( id_no ( pid ), pars [i] ) ;
-
 
1190
			i++ ;
1187
			return (r);
1191
		    }
-
 
1192
		    q = TAIL_list ( q ) ;
-
 
1193
		}
1188
		}
1194
		bs = enc_tokdef_body ( bs, id, tok ) ;
-
 
1195
		set_proc_token ( p ) ;
-
 
1196
	    } else {
1189
	} else if (dec) {
1197
		/* Function tokens */
-
 
1198
		ulong m ;
-
 
1199
		TOKEN res = DEREF_tok ( tok_proc_res ( tok ) ) ;
-
 
1200
		TYPE ret = DEREF_type ( tok_exp_type ( res ) ) ;
-
 
1201
		ENC_apply_proc ( bs ) ;
-
 
1202
		bs = enc_shape ( bs, ret ) ;
-
 
1203
		IGNORE capsule_id ( fid, VAR_tag ) ;
-
 
1204
		m = unit_no ( bs, fid, VAR_tag, 1 ) ;
-
 
1205
		ENC_obtain_tag ( bs ) ;
-
 
1206
		ENC_make_tag ( bs, m ) ;
1190
		if (tokdec_unit == NULL) {
1207
		ENC_LIST ( bs, npars ) ;
-
 
1208
		while ( i < npars ) {
-
 
1209
		    ENC_exp_apply_token ( bs ) ;
-
 
1210
		    ENC_make_tok ( bs, pars [i] ) ;
-
 
1211
		    ENC_LEN_SMALL ( bs, 0 ) ;
-
 
1212
		    i++ ;
1191
			return (r);
1213
		}
1192
		}
1214
		ENC_OFF ( bs ) ;
-
 
1215
	    }
-
 
1216
	} else {
1193
	} else {
1217
	    /* Other tokens */
1194
		return (r);
1218
	    bs = enc_tokdef_body ( bs, id, tok ) ;
-
 
1219
	}
1195
	}
-
 
1196
 
-
 
1197
	/* Construct token sort */
-
 
1198
	bf = clear_buffer(&mangle_buff, NIL(FILE));
-
 
1199
	bfputc(bf, r);
-
 
1200
	if (tag == tok_func_tag) {
-
 
1201
		/* Function token */
-
 
1202
		fid = DEREF_id(tok_func_defn(tok));
-
 
1203
		tok = func_proc_token(tok);
-
 
1204
		tag = TAG_tok(tok);
-
 
1205
		if (tag != tok_proc_tag) {
-
 
1206
			/* Ellipsis function */
-
 
1207
			return (r);
-
 
1208
		}
-
 
1209
	}
-
 
1210
	if (tag == tok_proc_tag) {
-
 
1211
		/*  Parameters for procedure tokens */
-
 
1212
		LIST(IDENTIFIER)p = DEREF_list(tok_proc_bids(tok));
-
 
1213
		while (!IS_NULL_list(p)) {
-
 
1214
			IDENTIFIER pid = DEREF_id(HEAD_list(p));
-
 
1215
			if (!IS_NULL_id(pid) && IS_id_token(pid)) {
-
 
1216
				TOKEN ptok = DEREF_tok(id_token_sort(pid));
-
 
1217
				int s = token_code(ptok);
-
 
1218
				npars++;
-
 
1219
				bfputc(bf, s);
-
 
1220
			}
-
 
1221
			p = TAIL_list(p);
-
 
1222
		}
-
 
1223
	}
-
 
1224
	bfputc(bf, 0);
-
 
1225
 
-
 
1226
	/* Output declaration and definition */
-
 
1227
	n = DEREF_ulong(id_no(id));
-
 
1228
	if (dec) {
-
 
1229
		enc_tokdec(n, strlit(bf->start));
-
 
1230
	}
-
 
1231
	if (def) {
-
 
1232
		BITSTREAM *bs;
-
 
1233
		ulong std_pars[20];
-
 
1234
		ulong *pars = std_pars;
-
 
1235
		if (npars >= 20) {
-
 
1236
			pars = xmalloc_nof(ulong, npars);
-
 
1237
		}
-
 
1238
		bs = enc_tokdef_start(n, strlit(bf->start), pars, 0);
-
 
1239
		COPY_dspec(id_storage(id), (ds | dspec_done));
-
 
1240
		COPY_ulong(id_no(id), LINK_TOKDEF);
-
 
1241
		last_params[DUMMY_token] = n;
-
 
1242
		if (tag == tok_proc_tag) {
-
 
1243
			unsigned i = 0;
-
 
1244
			if (IS_NULL_id(fid)) {
-
 
1245
				/* Procedure tokens */
-
 
1246
				LIST(IDENTIFIER)p, q;
-
 
1247
				p = DEREF_list(tok_proc_bids(tok));
-
 
1248
				q = p;
-
 
1249
				while (!IS_NULL_list(q)) {
-
 
1250
					IDENTIFIER pid = DEREF_id(HEAD_list(q));
-
 
1251
					if (!IS_NULL_id(pid) && IS_id_token(pid)) {
-
 
1252
						DECL_SPEC pds = DEREF_dspec(id_storage(pid));
-
 
1253
						pds |= dspec_register;
-
 
1254
						COPY_dspec(id_storage(pid), pds);
-
 
1255
						COPY_ulong(id_no(pid), pars[i]);
-
 
1256
						i++;
-
 
1257
					}
-
 
1258
					q = TAIL_list(q);
-
 
1259
				}
-
 
1260
				bs = enc_tokdef_body(bs, id, tok);
-
 
1261
				set_proc_token(p);
-
 
1262
			} else {
-
 
1263
				/* Function tokens */
-
 
1264
				ulong m;
-
 
1265
				TOKEN res = DEREF_tok(tok_proc_res(tok));
-
 
1266
				TYPE ret = DEREF_type(tok_exp_type(res));
-
 
1267
				ENC_apply_proc(bs);
-
 
1268
				bs = enc_shape(bs, ret);
-
 
1269
				IGNORE capsule_id(fid, VAR_tag);
-
 
1270
				m = unit_no(bs, fid, VAR_tag, 1);
-
 
1271
				ENC_obtain_tag(bs);
-
 
1272
				ENC_make_tag(bs, m);
-
 
1273
				ENC_LIST(bs, npars);
-
 
1274
				while (i < npars) {
-
 
1275
					ENC_exp_apply_token(bs);
-
 
1276
					ENC_make_tok(bs, pars[i]);
-
 
1277
					ENC_LEN_SMALL(bs, 0);
-
 
1278
					i++;
-
 
1279
				}
-
 
1280
				ENC_OFF(bs);
-
 
1281
			}
-
 
1282
		} else {
-
 
1283
			/* Other tokens */
-
 
1284
			bs = enc_tokdef_body(bs, id, tok);
-
 
1285
		}
1220
	COPY_ulong ( id_no ( id ), n ) ;
1286
		COPY_ulong(id_no(id), n);
1221
	enc_tokdef_end ( n, bs ) ;
1287
		enc_tokdef_end(n, bs);
1222
	if ( pars != std_pars ) xfree_nof ( pars ) ;
1288
		if (pars != std_pars) {
-
 
1289
			xfree_nof(pars);
1223
    }
1290
		}
-
 
1291
	}
1224
    return ( r ) ;
1292
	return (r);
1225
}
1293
}
1226
 
1294
 
1227
 
1295
 
1228
/*
1296
/*
1229
    SHOULD A VARIABLE BE COMPILED?
1297
    SHOULD A VARIABLE BE COMPILED?
Line 1232... Line 1300...
1232
    ds and type t should be output.  It returns 1 if it should be output
1300
    ds and type t should be output.  It returns 1 if it should be output
1233
    immediately, 2 if the decision on whether to output should be deferred
1301
    immediately, 2 if the decision on whether to output should be deferred
1234
    until later, and 0 otherwise.
1302
    until later, and 0 otherwise.
1235
*/
1303
*/
1236
 
1304
 
1237
static int need_variable
1305
static int
1238
    PROTO_N ( ( ds, t, e, n ) )
-
 
1239
    PROTO_T ( DECL_SPEC ds X TYPE t X EXP e X ulong n )
1306
need_variable(DECL_SPEC ds, TYPE t, EXP e, ulong n)
1240
{
1307
{
1241
    if ( ds & dspec_temp ) {
1308
	if (ds & dspec_temp) {
1242
	/* Temporary variables */
1309
		/* Temporary variables */
1243
	if ( ds & dspec_ignore ) return ( 0 ) ;
1310
		if (ds & dspec_ignore) {
-
 
1311
			return (0);
-
 
1312
		}
1244
	if ( ds & dspec_explicit ) return ( 2 ) ;
1313
		if (ds & dspec_explicit) {
-
 
1314
			return (2);
1245
    }
1315
		}
-
 
1316
	}
1246
    if ( ds & dspec_defn ) {
1317
	if (ds & dspec_defn) {
1247
	/* Output defined variables */
1318
		/* Output defined variables */
1248
	if ( ds & dspec_extern ) return ( 1 ) ;
1319
		if (ds & dspec_extern) {
-
 
1320
			return (1);
-
 
1321
		}
1249
	if ( n == LINK_NONE ) {
1322
		if (n == LINK_NONE) {
1250
#if LANGUAGE_CPP
1323
#if LANGUAGE_CPP
1251
	    CV_SPEC qual = DEREF_cv ( type_qual ( t ) ) ;
1324
			CV_SPEC qual = DEREF_cv(type_qual(t));
1252
	    if ( qual == ( cv_lvalue | cv_const ) ) {
1325
			if (qual == (cv_lvalue | cv_const)) {
1253
		/* Defer literal constants */
1326
				/* Defer literal constants */
1254
		return ( 2 ) ;
1327
				return (2);
1255
	    }
1328
			}
1256
#else
1329
#else
1257
	    UNUSED ( t ) ;
1330
			UNUSED(t);
1258
#endif
1331
#endif
1259
	    if ( !output_unused ) return ( 2 ) ;
1332
			if (!output_unused) {
-
 
1333
				return (2);
-
 
1334
			}
1260
	    if ( !overflow_exp ( e ) ) return ( 2 ) ;
1335
			if (!overflow_exp(e)) {
-
 
1336
				return (2);
-
 
1337
			}
1261
	}
1338
		}
1262
	return ( 1 ) ;
1339
		return (1);
1263
    }
1340
	}
1264
    if ( ds & dspec_used ) {
1341
	if (ds & dspec_used) {
1265
	/* Defer used variables */
1342
		/* Defer used variables */
1266
	return ( 2 ) ;
1343
		return (2);
1267
    }
1344
	}
1268
    return ( 0 ) ;
1345
	return (0);
1269
}
1346
}
1270
 
1347
 
1271
 
1348
 
1272
/*
1349
/*
1273
    COMPILE A VARIABLE
1350
    COMPILE A VARIABLE
1274
 
1351
 
1275
    This routine compiles the global variable or static data member id.
1352
    This routine compiles the global variable or static data member id.
1276
*/
1353
*/
1277
 
1354
 
1278
void compile_variable
1355
void
1279
    PROTO_N ( ( id, force ) )
-
 
1280
    PROTO_T ( IDENTIFIER id X int force )
1356
compile_variable(IDENTIFIER id, int force)
1281
{
1357
{
1282
    if ( output_capsule ) {
1358
	if (output_capsule) {
1283
	IDENTIFIER lid = DEREF_id ( id_alias ( id ) ) ;
1359
		IDENTIFIER lid = DEREF_id(id_alias(id));
1284
	DECL_SPEC ds = DEREF_dspec ( id_storage ( lid ) ) ;
1360
		DECL_SPEC ds = DEREF_dspec(id_storage(lid));
1285
	if ( !( ds & dspec_done ) ) {
1361
		if (!(ds & dspec_done)) {
1286
	    TYPE t ;
1362
			TYPE t;
1287
	    EXP e, d ;
1363
			EXP e, d;
1288
	    int output ;
1364
			int output;
1289
	    switch ( TAG_id ( id ) ) {
1365
			switch (TAG_id(id)) {
1290
		case id_variable_tag :
1366
			case id_variable_tag:
1291
		case id_stat_member_tag : {
1367
			case id_stat_member_tag: {
1292
		    /* Variables and static data members */
1368
				/* Variables and static data members */
1293
		    t = DEREF_type ( id_variable_etc_type ( lid ) ) ;
1369
				t = DEREF_type(id_variable_etc_type(lid));
1294
		    e = DEREF_exp ( id_variable_etc_init ( lid ) ) ;
1370
				e = DEREF_exp(id_variable_etc_init(lid));
1295
		    d = DEREF_exp ( id_variable_etc_term ( lid ) ) ;
1371
				d = DEREF_exp(id_variable_etc_term(lid));
1296
		    if ( !IS_NULL_exp ( e ) && IS_exp_zero ( e ) ) {
1372
				if (!IS_NULL_exp(e) && IS_exp_zero(e)) {
1297
			/* Ignore tentative definitions */
1373
					/* Ignore tentative definitions */
1298
			ds &= ~dspec_defn ;
1374
					ds &= ~dspec_defn;
1299
		    }
1375
				}
1300
		    break ;
1376
				break;
1301
		}
1377
			}
1302
		case id_enumerator_tag : {
1378
			case id_enumerator_tag: {
1303
		    /* Dummy enumerator values */
1379
				/* Dummy enumerator values */
1304
		    if ( !output_unused ) return ;
1380
				if (!output_unused) {
-
 
1381
					return;
-
 
1382
				}
1305
		    e = DEREF_exp ( id_enumerator_value ( lid ) ) ;
1383
				e = DEREF_exp(id_enumerator_value(lid));
1306
		    e = eval_exp ( e, 1 ) ;
1384
				e = eval_exp(e, 1);
1307
		    if ( !overflow_exp ( e ) ) return ;
1385
				if (!overflow_exp(e)) {
-
 
1386
					return;
-
 
1387
				}
1308
		    t = DEREF_type ( exp_type ( e ) ) ;
1388
				t = DEREF_type(exp_type(e));
1309
		    d = NULL_exp ;
1389
				d = NULL_exp;
1310
		    force = 1 ;
1390
				force = 1;
1311
		    break ;
1391
				break;
1312
		}
1392
			}
1313
		default : {
1393
			default: {
1314
		    /* Shouldn't happen */
1394
				/* Shouldn't happen */
1315
		    return ;
1395
				return;
1316
		}
1396
			}
1317
	    }
1397
			}
1318
	    if ( !IS_NULL_exp ( d ) && IS_exp_paren ( d ) ) {
1398
			if (!IS_NULL_exp(d) && IS_exp_paren(d)) {
1319
		/* Ignore parenthesised type information */
1399
				/* Ignore parenthesised type information */
1320
		d = DEREF_exp ( exp_paren_arg ( d ) ) ;
1400
				d = DEREF_exp(exp_paren_arg(d));
1321
	    }
1401
			}
1322
	    if ( !( ds & dspec_defn ) ) {
1402
			if (!(ds & dspec_defn)) {
1323
		/* Object not defined */
1403
				/* Object not defined */
1324
		e = NULL_exp ;
1404
				e = NULL_exp;
1325
		d = NULL_exp ;
1405
				d = NULL_exp;
1326
	    }
1406
			}
1327
	    if ( ds & dspec_explicit ) {
1407
			if (ds & dspec_explicit) {
1328
		/* Explicitly initialised object */
1408
				/* Explicitly initialised object */
1329
		d = NULL_exp ;
1409
				d = NULL_exp;
1330
	    }
1410
			}
1331
	    if ( force ) {
1411
			if (force) {
1332
		/* Force output */
1412
				/* Force output */
1333
		output = 1 ;
1413
				output = 1;
1334
	    } else if ( !IS_NULL_exp ( e ) && IS_exp_dynamic ( e ) ) {
1414
			} else if (!IS_NULL_exp(e) && IS_exp_dynamic(e)) {
1335
		/* Dynamic initialiser */
1415
				/* Dynamic initialiser */
1336
		output = 1 ;
1416
				output = 1;
1337
	    } else if ( !IS_NULL_exp ( d ) ) {
1417
			} else if (!IS_NULL_exp(d)) {
1338
		/* Dynamic destructor */
1418
				/* Dynamic destructor */
1339
		output = 1 ;
1419
				output = 1;
1340
	    } else {
1420
			} else {
1341
		/* Determine whether to output */
1421
				/* Determine whether to output */
1342
		ulong n = DEREF_ulong ( id_no ( lid ) ) ;
1422
				ulong n = DEREF_ulong(id_no(lid));
1343
		output = need_variable ( ds, t, e, n ) ;
1423
				output = need_variable(ds, t, e, n);
1344
		if ( output == 2 ) {
1424
				if (output == 2) {
1345
		    /* Defer variable until later */
1425
					/* Defer variable until later */
1346
		    CONS_id ( lid, pending_funcs, pending_funcs ) ;
1426
					CONS_id(lid, pending_funcs, pending_funcs);
1347
		    output = 0 ;
1427
					output = 0;
1348
		}
1428
				}
1349
	    }
1429
			}
1350
	    if ( output ) {
1430
			if (output) {
1351
		/* Output variable definition */
1431
				/* Output variable definition */
1352
		ds |= dspec_done ;
1432
				ds |= dspec_done;
1353
		COPY_dspec ( id_storage ( lid ), ds ) ;
1433
				COPY_dspec(id_storage(lid), ds);
1354
		crt_enc_loc = id_loc ( lid ) ;
1434
				crt_enc_loc = id_loc(lid);
1355
		IGNORE make_tagdef ( lid, t, e, d, 1 ) ;
1435
				IGNORE make_tagdef(lid, t, e, d, 1);
1356
		crt_enc_loc = NULL_ptr ( LOCATION ) ;
1436
				crt_enc_loc = NULL_ptr(LOCATION);
1357
	    }
1437
			}
1358
	} else {
1438
		} else {
1359
	    /* Check for anonymous unions */
1439
			/* Check for anonymous unions */
1360
	    if ( !EQ_id ( id, lid ) ) {
1440
			if (!EQ_id(id, lid)) {
1361
		if ( output_diag && is_anon_member ( id ) ) {
1441
				if (output_diag && is_anon_member(id)) {
1362
		    enc_diag_id ( id, 1 ) ;
1442
					enc_diag_id(id, 1);
1363
		}
1443
				}
1364
	    }
1444
			}
1365
	}
1445
		}
1366
    } else {
1446
	} else {
1367
	check_mangled ( id ) ;
1447
		check_mangled(id);
1368
    }
1448
	}
1369
    return ;
1449
	return;
1370
}
1450
}
1371
 
1451
 
1372
 
1452
 
1373
/*
1453
/*
1374
    COMPILE ALL PENDING FUNCTIONS
1454
    COMPILE ALL PENDING FUNCTIONS
1375
 
1455
 
1376
    This routine compiles all the inline and implicit functions which
1456
    This routine compiles all the inline and implicit functions which
1377
    have been used in the program.  The usage information comes from
1457
    have been used in the program.  The usage information comes from
1378
    the fact that the function tag has actually been output rather than
1458
    the fact that the function tag has actually been output rather than
1379
    the function has been used (possibly in a function which is not
1459
    the function has been used (possibly in a function which is not
1380
    itself used).
1460
    itself used).
1381
*/
1461
*/
1382
 
1462
 
-
 
1463
void
1383
void compile_pending
1464
compile_pending(void)
1384
    PROTO_Z ()
-
 
1385
{
1465
{
1386
    int changed ;
1466
	int changed;
1387
    do {
1467
	do {
1388
	LIST ( IDENTIFIER ) p = pending_funcs ;
1468
		LIST(IDENTIFIER)p = pending_funcs;
1389
	if ( !output_capsule ) break ;
1469
		if (!output_capsule)break;
1390
	changed = 0 ;
1470
		changed = 0;
1391
	while ( !IS_NULL_list ( p ) ) {
1471
		while (!IS_NULL_list(p)) {
1392
	    IDENTIFIER id = DEREF_id ( HEAD_list ( p ) ) ;
1472
			IDENTIFIER id = DEREF_id(HEAD_list(p));
1393
	    if ( !IS_NULL_id ( id ) ) {
1473
			if (!IS_NULL_id(id)) {
1394
		ulong n = DEREF_ulong ( id_no ( id ) ) ;
1474
				ulong n = DEREF_ulong(id_no(id));
1395
		if ( n != LINK_NONE ) {
1475
				if (n != LINK_NONE) {
1396
		    DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
1476
					DECL_SPEC ds = DEREF_dspec(id_storage(id));
1397
		    if ( !( ds & dspec_done ) ) {
1477
					if (!(ds & dspec_done)) {
1398
			if ( IS_id_function_etc ( id ) ) {
1478
						if (IS_id_function_etc(id)) {
1399
			    if ( ds & dspec_trivial ) {
1479
							if (ds & dspec_trivial) {
1400
				/* It can happen ... */
1480
								/* It can happen ... */
1401
				ds &= ~( dspec_defn | dspec_trivial ) ;
1481
								ds &= ~(dspec_defn | dspec_trivial);
1402
				COPY_dspec ( id_storage ( id ), ds ) ;
1482
								COPY_dspec(id_storage(id), ds);
1403
			    }
1483
							}
1404
			    if ( !( ds & dspec_defn ) ) {
1484
							if (!(ds & dspec_defn)) {
1405
				/* Function not defined */
1485
								/* Function not defined */
1406
				if ( ds & dspec_implicit ) {
1486
								if (ds & dspec_implicit) {
1407
				    /* Compile implicit functions */
1487
									/* Compile implicit functions */
1408
				    LOCATION loc ;
1488
									LOCATION loc;
1409
				    bad_crt_loc++ ;
1489
									bad_crt_loc++;
1410
				    loc = crt_loc ;
1490
									loc = crt_loc;
1411
				    DEREF_loc ( id_loc ( id ), crt_loc ) ;
1491
									DEREF_loc(id_loc(id), crt_loc);
1412
				    implicit_defn ( id, DEFAULT_USR ) ;
1492
									implicit_defn(id, DEFAULT_USR);
1413
				    crt_loc = loc ;
1493
									crt_loc = loc;
1414
				    bad_crt_loc-- ;
1494
									bad_crt_loc--;
1415
				} else if ( ds & dspec_extern ) {
1495
								} else if (ds & dspec_extern) {
1416
				    /* External linkage */
1496
									/* External linkage */
1417
				    update_tag ( id, 1 ) ;
1497
									update_tag(id, 1);
1418
				}
1498
								}
1419
			    }
1499
							}
1420
			    compile_function ( id, 1 ) ;
1500
							compile_function(id, 1);
1421
			} else {
1501
						} else {
1422
			    compile_variable ( id, 1 ) ;
1502
							compile_variable(id, 1);
1423
			}
1503
						}
1424
			changed = 1 ;
1504
						changed = 1;
1425
		    }
1505
					}
1426
		    COPY_id ( HEAD_list ( p ), NULL_id ) ;
1506
					COPY_id(HEAD_list(p), NULL_id);
1427
		}
1507
				}
1428
	    }
1508
			}
1429
	    p = TAIL_list ( p ) ;
1509
			p = TAIL_list(p);
1430
	}
1510
		}
1431
	if ( !changed ) changed = enc_diag_pending () ;
1511
		if (!changed)changed = enc_diag_pending();
1432
    } while ( changed ) ;
1512
	} while (changed);
1433
    compile_incompl () ;
1513
	compile_incompl();
1434
    return ;
1514
	return;
1435
}
1515
}
1436
 
1516
 
1437
 
1517
 
1438
/*
1518
/*
1439
    SHOULD A FUNCTION BE COMPILED?
1519
    SHOULD A FUNCTION BE COMPILED?
1440
 
1520
 
1441
    This routine determines whether a function declared with specifiers
1521
    This routine determines whether a function declared with specifiers
1442
    ds should be output.  It returns 1 if it should be output immediately,
1522
    ds should be output.  It returns 1 if it should be output immediately,
1443
    2 if the decision on whether to output should be deferred until later,
1523
    2 if the decision on whether to output should be deferred until later,
1444
    and 0 otherwise.  The algorithm is somewhat complex to avoid outputting
1524
    and 0 otherwise.  The algorithm is somewhat complex to avoid outputting
1445
    inline and implicit function definitions unless absolutely necessary
1525
    inline and implicit function definitions unless absolutely necessary
1446
    and to only declare virtual functions when explicitly called or when
1526
    and to only declare virtual functions when explicitly called or when
1447
    defining a virtual function table.
1527
    defining a virtual function table.
1448
*/
1528
*/
1449
 
1529
 
1450
static int need_function
1530
static int
1451
    PROTO_N ( ( ds, n ) )
-
 
1452
    PROTO_T ( DECL_SPEC ds X ulong n )
1531
need_function(DECL_SPEC ds, ulong n)
1453
{
1532
{
1454
    if ( ds & ( dspec_inline | dspec_implicit | dspec_token ) ) {
1533
	if (ds & (dspec_inline | dspec_implicit | dspec_token)) {
1455
	/* Defer inline functions */
1534
		/* Defer inline functions */
1456
	if ( ( ds & dspec_defn ) && n != LINK_NONE ) return ( 1 ) ;
1535
		if ((ds & dspec_defn) && n != LINK_NONE) {
-
 
1536
			return (1);
-
 
1537
		}
1457
	return ( 2 ) ;
1538
		return (2);
1458
    }
1539
	}
1459
    if ( ds & dspec_defn ) {
1540
	if (ds & dspec_defn) {
1460
	/* Output defined functions */
1541
		/* Output defined functions */
1461
	if ( ( ds & dspec_extern ) || output_unused ) return ( 1 ) ;
1542
		if ((ds & dspec_extern) || output_unused) {
-
 
1543
			return (1);
-
 
1544
		}
1462
	if ( n != LINK_NONE ) return ( 1 ) ;
1545
		if (n != LINK_NONE) {
-
 
1546
			return (1);
-
 
1547
		}
1463
	return ( 2 ) ;
1548
		return (2);
1464
    }
1549
	}
1465
    if ( ds & ( dspec_used | dspec_called | dspec_virtual ) ) {
1550
	if (ds & (dspec_used | dspec_called | dspec_virtual)) {
1466
	/* Defer called functions */
1551
		/* Defer called functions */
1467
	return ( 2 ) ;
1552
		return (2);
1468
    }
1553
	}
1469
    return ( 0 ) ;
1554
	return (0);
1470
}
1555
}
1471
 
1556
 
1472
 
1557
 
1473
/*
1558
/*
1474
    COMPILE A FUNCTION
1559
    COMPILE A FUNCTION
1475
 
1560
 
1476
    This routine compiles the function or member function id.  If force
1561
    This routine compiles the function or member function id.  If force
1477
    is true then the definition of id is always output.
1562
    is true then the definition of id is always output.
1478
*/
1563
*/
1479
 
1564
 
1480
void compile_function
1565
void
1481
    PROTO_N ( ( id, force ) )
-
 
1482
    PROTO_T ( IDENTIFIER id X int force )
1566
compile_function(IDENTIFIER id, int force)
1483
{
1567
{
1484
    /* Check for template functions */
1568
	/* Check for template functions */
1485
    TYPE t ;
1569
	TYPE t;
1486
    IDENTIFIER lid = DEREF_id ( id_alias ( id ) ) ;
1570
	IDENTIFIER lid = DEREF_id(id_alias(id));
1487
    if ( IS_id_ambig ( lid ) ) return ;
1571
	if (IS_id_ambig(lid)) {
-
 
1572
		return;
-
 
1573
	}
1488
    t = DEREF_type ( id_function_etc_type ( lid ) ) ;
1574
	t = DEREF_type(id_function_etc_type(lid));
1489
    if ( IS_type_templ ( t ) ) return ;
1575
	if (IS_type_templ(t)) {
-
 
1576
		return;
-
 
1577
	}
1490
 
1578
 
1491
    /* Simple functions */
1579
	/* Simple functions */
1492
    if ( output_capsule ) {
1580
	if (output_capsule) {
1493
	DECL_SPEC ds = DEREF_dspec ( id_storage ( lid ) ) ;
1581
		DECL_SPEC ds = DEREF_dspec(id_storage(lid));
1494
	if ( !( ds & ( dspec_done | dspec_trivial ) ) ) {
1582
		if (!(ds & (dspec_done | dspec_trivial))) {
1495
	    int output ;
1583
			int output;
1496
	    if ( force ) {
1584
			if (force) {
1497
		/* Force output */
1585
				/* Force output */
1498
		output = 1 ;
1586
				output = 1;
1499
	    } else {
1587
			} else {
1500
		/* Determine whether to output */
1588
				/* Determine whether to output */
1501
		ulong n = DEREF_ulong ( id_no ( lid ) ) ;
1589
				ulong n = DEREF_ulong(id_no(lid));
1502
		output = need_function ( ds, n ) ;
1590
				output = need_function(ds, n);
1503
		if ( output == 2 ) {
1591
				if (output == 2) {
1504
		    /* Defer function until later */
1592
					/* Defer function until later */
1505
		    CONS_id ( lid, pending_funcs, pending_funcs ) ;
1593
					CONS_id(lid, pending_funcs, pending_funcs);
1506
		    output = 0 ;
1594
					output = 0;
-
 
1595
				}
-
 
1596
			}
-
 
1597
			if (output == 1) {
-
 
1598
				/* Output function definition */
-
 
1599
				EXP e = DEREF_exp(id_function_etc_defn(lid));
-
 
1600
				if (!(ds & dspec_defn)) {
-
 
1601
					e = NULL_exp;
-
 
1602
				}
-
 
1603
				ds |= dspec_done;
-
 
1604
				COPY_dspec(id_storage(lid), ds);
-
 
1605
				crt_enc_loc = id_loc(lid);
-
 
1606
				IGNORE make_tagdef(lid, t, e, NULL_exp, 0);
-
 
1607
				crt_enc_loc = NULL_ptr(LOCATION);
-
 
1608
				free_function(lid);
-
 
1609
			}
1507
		}
1610
		}
1508
	    }
1611
	} else {
1509
	    if ( output == 1 ) {
-
 
1510
		/* Output function definition */
-
 
1511
		EXP e = DEREF_exp ( id_function_etc_defn ( lid ) ) ;
-
 
1512
		if ( !( ds & dspec_defn ) ) e = NULL_exp ;
-
 
1513
		ds |= dspec_done ;
-
 
1514
		COPY_dspec ( id_storage ( lid ), ds ) ;
-
 
1515
		crt_enc_loc = id_loc ( lid ) ;
1612
		free_function(lid);
1516
		IGNORE make_tagdef ( lid, t, e, NULL_exp, 0 ) ;
-
 
1517
		crt_enc_loc = NULL_ptr ( LOCATION ) ;
-
 
1518
		free_function ( lid ) ;
1613
		check_mangled(lid);
1519
	    }
-
 
1520
	}
1614
	}
1521
    } else {
-
 
1522
	free_function ( lid ) ;
-
 
1523
	check_mangled ( lid ) ;
-
 
1524
    }
-
 
1525
    return ;
1615
	return;
1526
}
1616
}
1527
 
1617
 
1528
 
1618
 
1529
/*
1619
/*
1530
    VIRTUAL FUNCTION DECLARATION CHECK
1620
    VIRTUAL FUNCTION DECLARATION CHECK
Line 1532... Line 1622...
1532
    This value gives those virtual functions which are ignored when
1622
    This value gives those virtual functions which are ignored when
1533
    deciding whether to output a virtual function table.
1623
    deciding whether to output a virtual function table.
1534
*/
1624
*/
1535
 
1625
 
1536
#define dspec_ignore_virtual\
1626
#define dspec_ignore_virtual\
1537
    ( dspec_inherit | dspec_implicit | dspec_inline | dspec_pure )
1627
   (dspec_inherit | dspec_implicit | dspec_inline | dspec_pure)
1538
 
1628
 
1539
 
1629
 
1540
/*
1630
/*
1541
    COMPILE A VIRTUAL FUNCTION TABLE
1631
    COMPILE A VIRTUAL FUNCTION TABLE
1542
 
1632
 
Line 1549... Line 1639...
1549
    in the class.
1639
    in the class.
1550
*/
1640
*/
1551
 
1641
 
1552
#if LANGUAGE_CPP
1642
#if LANGUAGE_CPP
1553
 
1643
 
1554
void compile_virtual
1644
void
1555
    PROTO_N ( ( ct, anon ) )
-
 
1556
    PROTO_T ( CLASS_TYPE ct X int anon )
1645
compile_virtual(CLASS_TYPE ct, int anon)
1557
{
1646
{
1558
    if ( output_capsule ) {
1647
	if (output_capsule) {
1559
	IDENTIFIER cid = DEREF_id ( ctype_name ( ct ) ) ;
1648
		IDENTIFIER cid = DEREF_id(ctype_name(ct));
1560
	crt_enc_loc = id_loc ( cid ) ;
1649
		crt_enc_loc = id_loc(cid);
1561
	if ( anon == ANON_NONE && !output_virtual ) {
1650
		if (anon == ANON_NONE && !output_virtual) {
1562
	    LIST ( VIRTUAL ) pt ;
1651
			LIST(VIRTUAL)pt;
1563
	    VIRTUAL vt = DEREF_virt ( ctype_virt ( ct ) ) ;
1652
			VIRTUAL vt = DEREF_virt(ctype_virt(ct));
1564
	    if ( IS_NULL_virt ( vt ) ) return ;
1653
			if (IS_NULL_virt(vt)) {
-
 
1654
				return;
-
 
1655
			}
1565
	    pt = DEREF_list ( virt_table_entries ( vt ) ) ;
1656
			pt = DEREF_list(virt_table_entries(vt));
1566
	    while ( !IS_NULL_list ( pt ) ) {
1657
			while (!IS_NULL_list(pt)) {
1567
		VIRTUAL at = DEREF_virt ( HEAD_list ( pt ) ) ;
1658
				VIRTUAL at = DEREF_virt(HEAD_list(pt));
1568
		unsigned tag = TAG_virt ( at ) ;
1659
				unsigned tag = TAG_virt(at);
1569
		while ( tag == virt_link_tag ) {
1660
				while (tag == virt_link_tag) {
1570
		    /* Allow for symbolic links */
1661
					/* Allow for symbolic links */
1571
		    at = DEREF_virt ( DEREF_ptr ( virt_link_to ( at ) ) ) ;
1662
					at = DEREF_virt(DEREF_ptr(virt_link_to(at)));
1572
		    tag = TAG_virt ( at ) ;
1663
					tag = TAG_virt(at);
1573
		}
1664
				}
1574
		if ( tag == virt_simple_tag || tag == virt_override_tag ) {
1665
				if (tag == virt_simple_tag || tag == virt_override_tag) {
1575
		    /* Examine virtual functions */
1666
					/* Examine virtual functions */
1576
		    IDENTIFIER fn = DEREF_id ( virt_func ( at ) ) ;
1667
					IDENTIFIER fn = DEREF_id(virt_func(at));
1577
		    DECL_SPEC ds = DEREF_dspec ( id_storage ( fn ) ) ;
1668
					DECL_SPEC ds = DEREF_dspec(id_storage(fn));
1578
		    if ( !( ds & dspec_ignore_virtual ) ) {
1669
					if (!(ds & dspec_ignore_virtual)) {
1579
			if ( ds & dspec_defn ) {
1670
						if (ds & dspec_defn) {
1580
			    /* Define the table externally */
1671
							/* Define the table externally */
1581
			    define_vtable ( ct, 2, 1 ) ;
1672
							define_vtable(ct, 2, 1);
1582
			} else {
1673
						} else {
1583
			    /* Declare the table externally */
1674
							/* Declare the table externally */
1584
			    define_vtable ( ct, 0, 1 ) ;
1675
							define_vtable(ct, 0, 1);
1585
			}
1676
						}
1586
			return ;
1677
						return;
1587
		    }
1678
					}
1588
		}
1679
				}
1589
		pt = TAIL_list ( pt ) ;
1680
				pt = TAIL_list(pt);
1590
	    }
1681
			}
1591
	}
1682
		}
1592
	/* Define the table internally */
1683
		/* Define the table internally */
1593
	define_vtable ( ct, 1, 0 ) ;
1684
		define_vtable(ct, 1, 0);
1594
    }
1685
	}
1595
    return ;
1686
	return;
1596
}
1687
}
1597
 
1688
 
1598
#endif
1689
#endif
1599
 
1690
 
1600
 
1691
 
1601
/*
1692
/*
1602
    COMPILE A TOKEN
1693
    COMPILE A TOKEN
1603
 
1694
 
1604
    This routine compiles the token id.  It is only called if id is defined
1695
    This routine compiles the token id.  It is only called if id is defined
1605
    (in which case def is true) or should be defined.
1696
    (in which case def is true) or should be defined.
1606
*/
1697
*/
1607
 
1698
 
1608
void compile_token
1699
void
1609
    PROTO_N ( ( id, def ) )
-
 
1610
    PROTO_T ( IDENTIFIER id X int def )
1700
compile_token(IDENTIFIER id, int def)
1611
{
1701
{
-
 
1702
	if (!def) {
1612
    if ( !def ) report ( crt_loc, ERR_token_undef ( id ) ) ;
1703
		report(crt_loc, ERR_token_undef(id));
-
 
1704
	}
1613
    if ( output_capsule ) {
1705
	if (output_capsule) {
1614
	crt_enc_loc = id_loc ( id ) ;
1706
		crt_enc_loc = id_loc(id);
1615
	IGNORE enc_tokdef ( id, 1 ) ;
1707
		IGNORE enc_tokdef(id, 1);
-
 
1708
		if (output_diag) {
1616
	if ( output_diag ) enc_diag_token ( id, NULL_type ) ;
1709
			enc_diag_token(id, NULL_type);
-
 
1710
		}
1617
	crt_enc_loc = NULL_ptr ( LOCATION ) ;
1711
		crt_enc_loc = NULL_ptr(LOCATION);
1618
    }
1712
	}
1619
    return ;
1713
	return;
1620
}
1714
}
1621
 
1715
 
1622
 
1716
 
1623
/*
1717
/*
1624
    COMPILE A TYPE
1718
    COMPILE A TYPE
1625
 
1719
 
1626
    This routine compiles the type named id.  This only has an effect in
1720
    This routine compiles the type named id.  This only has an effect in
1627
    diagnostics mode.
1721
    diagnostics mode.
1628
*/
1722
*/
1629
 
1723
 
1630
void compile_type
1724
void
1631
    PROTO_N ( ( id ) )
-
 
1632
    PROTO_T ( IDENTIFIER id )
1725
compile_type(IDENTIFIER id)
1633
{
1726
{
1634
    if ( output_capsule && output_diag ) {
1727
	if (output_capsule && output_diag) {
1635
	DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
1728
		DECL_SPEC ds = DEREF_dspec(id_storage(id));
1636
	if ( ( ds & dspec_used ) && !( ds & dspec_done ) ) {
1729
		if ((ds & dspec_used) && !(ds & dspec_done)) {
1637
	    ds |= dspec_done ;
1730
			ds |= dspec_done;
1638
	    COPY_dspec ( id_storage ( id ), ds ) ;
1731
			COPY_dspec(id_storage(id), ds);
1639
	    if ( ds & dspec_token ) {
1732
			if (ds & dspec_token) {
1640
		/* Tokenised type */
1733
				/* Tokenised type */
1641
		/* EMPTY */
1734
				/* EMPTY */
1642
	    } else {
1735
			} else {
1643
		crt_enc_loc = id_loc ( id ) ;
1736
				crt_enc_loc = id_loc(id);
1644
		enc_diag_id ( id, 0 ) ;
1737
				enc_diag_id(id, 0);
1645
		crt_enc_loc = NULL_ptr ( LOCATION ) ;
1738
				crt_enc_loc = NULL_ptr(LOCATION);
1646
	    }
1739
			}
-
 
1740
		}
1647
	}
1741
	}
1648
    }
-
 
1649
    return ;
1742
	return;
1650
}
1743
}
1651
 
1744
 
1652
 
1745
 
1653
/*
1746
/*
1654
    COMPILE AN EXTERNAL ASSEMBLER DIRECTIVE
1747
    COMPILE AN EXTERNAL ASSEMBLER DIRECTIVE
1655
 
1748
 
1656
    This routine compiles the asm definition e which is declared outside
1749
    This routine compiles the asm definition e which is declared outside
1657
    any function definition.
1750
    any function definition.
1658
*/
1751
*/
1659
 
1752
 
1660
void compile_asm
1753
void
1661
    PROTO_N ( ( e ) )
-
 
1662
    PROTO_T ( EXP e )
1754
compile_asm(EXP e)
1663
{
1755
{
1664
    TYPE t = DEREF_type ( exp_type ( e ) ) ;
1756
	TYPE t = DEREF_type(exp_type(e));
1665
    IGNORE make_tagdef ( NULL_id, t, e, NULL_exp, 1 ) ;
1757
	IGNORE make_tagdef(NULL_id, t, e, NULL_exp, 1);
1666
    return ;
1758
	return;
1667
}
1759
}
1668
 
1760
 
1669
 
1761
 
1670
/*
1762
/*
1671
    COMPILE A COMMENT
1763
    COMPILE A COMMENT
1672
 
1764
 
1673
    This routine adds the comment string s of length n to the output
1765
    This routine adds the comment string s of length n to the output
1674
    capsule.  This is used in the implementation of the '#ident' directive.
1766
    capsule.  This is used in the implementation of the '#ident' directive.
1675
*/
1767
*/
1676
 
1768
 
1677
void compile_comment
1769
void
1678
    PROTO_N ( ( s, n ) )
-
 
1679
    PROTO_T ( string s X unsigned long n )
1770
compile_comment(string s, unsigned long n)
1680
{
1771
{
1681
    if ( output_capsule ) {
1772
	if (output_capsule) {
1682
	BITSTREAM *bs = linkinfo_unit ;
1773
		BITSTREAM *bs = linkinfo_unit;
1683
	ENC_make_comment ( bs ) ;
1774
		ENC_make_comment(bs);
1684
	bs = enc_tdfstring ( bs, n, s ) ;
1775
		bs = enc_tdfstring(bs, n, s);
1685
	count_item ( bs ) ;
1776
		count_item(bs);
1686
	linkinfo_unit = bs ;
1777
		linkinfo_unit = bs;
1687
    }
1778
	}
1688
    return ;
1779
	return;
1689
}
1780
}
1690
 
1781
 
1691
 
1782
 
1692
/*
1783
/*
1693
    COMPILE A PRESERVED STATIC IDENTIFIER
1784
    COMPILE A PRESERVED STATIC IDENTIFIER
1694
 
1785
 
1695
    This routine adds the preserved static identifier id to the output
1786
    This routine adds the preserved static identifier id to the output
1696
    capsule.
1787
    capsule.
1697
*/
1788
*/
1698
 
1789
 
1699
void compile_preserve
1790
void
1700
    PROTO_N ( ( id ) )
-
 
1701
    PROTO_T ( IDENTIFIER id )
1791
compile_preserve(IDENTIFIER id)
1702
{
1792
{
1703
    if ( output_capsule ) {
1793
	if (output_capsule) {
1704
	ulong n ;
1794
		ulong n;
1705
	BITSTREAM *bs = linkinfo_unit ;
1795
		BITSTREAM *bs = linkinfo_unit;
1706
	ENC_static_name_def ( bs ) ;
1796
		ENC_static_name_def(bs);
1707
	ENC_obtain_tag ( bs ) ;
1797
		ENC_obtain_tag(bs);
1708
	IGNORE capsule_id ( id, VAR_tag ) ;
1798
		IGNORE capsule_id(id, VAR_tag);
1709
	n = unit_no ( bs, id, VAR_tag, 1 ) ;
1799
		n = unit_no(bs, id, VAR_tag, 1);
1710
	ENC_make_tag ( bs, n ) ;
1800
		ENC_make_tag(bs, n);
1711
	bs = enc_diag_name ( bs, id, 1 ) ;
1801
		bs = enc_diag_name(bs, id, 1);
1712
	count_item ( bs ) ;
1802
		count_item(bs);
1713
	linkinfo_unit = bs ;
1803
		linkinfo_unit = bs;
1714
    }
1804
	}
1715
    return ;
1805
	return;
1716
}
1806
}
1717
 
1807
 
1718
 
1808
 
1719
/*
1809
/*
1720
    COMPILE A WEAK LINKAGE DIRECTIVE
1810
    COMPILE A WEAK LINKAGE DIRECTIVE
1721
 
1811
 
1722
    This routine adds a weak linkage directive '#pragma weak id = aid'
1812
    This routine adds a weak linkage directive '#pragma weak id = aid'
1723
    to the output capsule.
1813
    to the output capsule.
1724
*/
1814
*/
1725
 
1815
 
1726
void compile_weak
1816
void
1727
    PROTO_N ( ( id, aid ) )
-
 
1728
    PROTO_T ( IDENTIFIER id X IDENTIFIER aid )
1817
compile_weak(IDENTIFIER id, IDENTIFIER aid)
1729
{
1818
{
1730
    if ( output_capsule && !IS_NULL_id ( id ) ) {
1819
	if (output_capsule && !IS_NULL_id(id)) {
1731
	ulong n ;
1820
		ulong n;
1732
	string s = NULL ;
1821
		string s = NULL;
1733
	BITSTREAM *bs = linkinfo_unit ;
1822
		BITSTREAM *bs = linkinfo_unit;
1734
 
1823
 
1735
	/* Set up weak symbol name */
1824
		/* Set up weak symbol name */
1736
	id = DEREF_id ( id_alias ( id ) ) ;
1825
		id = DEREF_id(id_alias(id));
1737
	IGNORE capsule_id ( id, VAR_tag ) ;
1826
		IGNORE capsule_id(id, VAR_tag);
1738
	n = DEREF_ulong ( id_no ( id ) ) ;
1827
		n = DEREF_ulong(id_no(id));
1739
	IGNORE capsule_name ( n, &s, VAR_tag ) ;
1828
		IGNORE capsule_name(n, &s, VAR_tag);
1740
	if ( s ) {
1829
		if (s) {
1741
	    ENC_make_weak_symbol ( bs ) ;
1830
			ENC_make_weak_symbol(bs);
1742
	    bs = enc_ustring ( bs, s ) ;
1831
			bs = enc_ustring(bs, s);
1743
	    ENC_obtain_tag ( bs ) ;
1832
			ENC_obtain_tag(bs);
1744
	    n = unit_no ( bs, id, VAR_tag, 1 ) ;
1833
			n = unit_no(bs, id, VAR_tag, 1);
1745
	    ENC_make_tag ( bs, n ) ;
1834
			ENC_make_tag(bs, n);
1746
	    count_item ( bs ) ;
1835
			count_item(bs);
1747
	}
1836
		}
1748
 
1837
 
1749
	/* Set up weak symbol definition */
1838
		/* Set up weak symbol definition */
1750
	if ( !IS_NULL_id ( aid ) ) {
1839
		if (!IS_NULL_id(aid)) {
1751
	    aid = DEREF_id ( id_alias ( aid ) ) ;
1840
			aid = DEREF_id(id_alias(aid));
1752
	    ENC_make_weak_defn ( bs ) ;
1841
			ENC_make_weak_defn(bs);
1753
	    ENC_obtain_tag ( bs ) ;
1842
			ENC_obtain_tag(bs);
1754
	    n = unit_no ( bs, id, VAR_tag, 1 ) ;
1843
			n = unit_no(bs, id, VAR_tag, 1);
1755
	    ENC_make_tag ( bs, n ) ;
1844
			ENC_make_tag(bs, n);
1756
	    ENC_obtain_tag ( bs ) ;
1845
			ENC_obtain_tag(bs);
1757
	    IGNORE capsule_id ( aid, VAR_tag ) ;
1846
			IGNORE capsule_id(aid, VAR_tag);
1758
	    n = unit_no ( bs, aid, VAR_tag, 1 ) ;
1847
			n = unit_no(bs, aid, VAR_tag, 1);
1759
	    ENC_make_tag ( bs, n ) ;
1848
			ENC_make_tag(bs, n);
1760
	    count_item ( bs ) ;
1849
			count_item(bs);
-
 
1850
		}
-
 
1851
		linkinfo_unit = bs;
1761
	}
1852
	}
1762
	linkinfo_unit = bs ;
-
 
1763
    }
-
 
1764
    return ;
1853
	return;
1765
}
1854
}
1766
 
1855
 
1767
 
1856
 
1768
/*
1857
/*
1769
    UPDATE A TAG NAME
1858
    UPDATE A TAG NAME
1770
 
1859
 
1771
    This routine updates the external name of the identifier id forcing
1860
    This routine updates the external name of the identifier id forcing
1772
    it to become internal or external, depending on the value of ext.  It
1861
    it to become internal or external, depending on the value of ext.  It
1773
    is used to handle inline functions with external linkage.
1862
    is used to handle inline functions with external linkage.
1774
*/
1863
*/
1775
 
1864
 
1776
void update_tag
1865
void
1777
    PROTO_N ( ( id, ext ) )
-
 
1778
    PROTO_T ( IDENTIFIER id X int ext )
1866
update_tag(IDENTIFIER id, int ext)
1779
{
1867
{
1780
    IDENTIFIER lid = DEREF_id ( id_alias ( id ) ) ;
1868
	IDENTIFIER lid = DEREF_id(id_alias(id));
1781
    ulong n = DEREF_ulong ( id_no ( lid ) ) ;
1869
	ulong n = DEREF_ulong(id_no(lid));
1782
    if ( n != LINK_NONE && ( n & LINK_EXTERN ) ) {
1870
	if (n != LINK_NONE && (n & LINK_EXTERN)) {
1783
	string s = mangle_name ( lid, VAR_tag, ext ) ;
1871
		string s = mangle_name(lid, VAR_tag, ext);
1784
	n = capsule_name ( n, &s, VAR_tag ) ;
1872
		n = capsule_name(n, &s, VAR_tag);
1785
	COPY_ulong ( id_no ( lid ), n ) ;
1873
		COPY_ulong(id_no(lid), n);
1786
	COPY_ulong ( id_no ( id ), n ) ;
1874
		COPY_ulong(id_no(id), n);
1787
    }
1875
	}
1788
    return ;
1876
	return;
1789
}
1877
}
1790
 
1878
 
1791
 
1879
 
1792
/*
1880
/*
1793
    START OF DUMMY TDF OUTPUT ROUTINES
1881
    START OF DUMMY TDF OUTPUT ROUTINES
Line 1802... Line 1890...
1802
 
1890
 
1803
/*
1891
/*
1804
    COMPILE A VARIABLE (DUMMY VERSION)
1892
    COMPILE A VARIABLE (DUMMY VERSION)
1805
 
1893
 
1806
    This routine is a dummy for compiling the variable id when TDF
1894
    This routine is a dummy for compiling the variable id when TDF
1807
    output is disabled.
1895
    output is disabled.
1808
*/
1896
*/
1809
 
1897
 
1810
void compile_variable
1898
void
1811
    PROTO_N ( ( id, force ) )
-
 
1812
    PROTO_T ( IDENTIFIER id X int force )
1899
compile_variable(IDENTIFIER id, int force)
1813
{
1900
{
1814
    check_mangled ( id ) ;
1901
	check_mangled(id);
1815
    UNUSED ( force ) ;
1902
	UNUSED(force);
1816
    return ;
1903
	return;
1817
}
1904
}
1818
 
1905
 
1819
 
1906
 
1820
/*
1907
/*
1821
    COMPILE ALL PENDING FUNCTIONS (DUMMY VERSION)
1908
    COMPILE ALL PENDING FUNCTIONS (DUMMY VERSION)
1822
 
1909
 
1823
    This routine is a dummy for compiling all pending functions when
1910
    This routine is a dummy for compiling all pending functions when
1824
    TDF output is disabled.
1911
    TDF output is disabled.
1825
*/
1912
*/
1826
 
1913
 
-
 
1914
void
1827
void compile_pending
1915
compile_pending(void)
1828
    PROTO_Z ()
-
 
1829
{
1916
{
1830
    return ;
1917
	return;
1831
}
1918
}
1832
 
1919
 
1833
 
1920
 
1834
/*
1921
/*
1835
    COMPILE A FUNCTION (DUMMY VERSION)
1922
    COMPILE A FUNCTION (DUMMY VERSION)
1836
 
1923
 
1837
    This routine is a dummy for compiling the function id when TDF
1924
    This routine is a dummy for compiling the function id when TDF
1838
    output is disabled.
1925
    output is disabled.
1839
*/
1926
*/
1840
 
1927
 
1841
void compile_function
1928
void
1842
    PROTO_N ( ( id, force ) )
-
 
1843
    PROTO_T ( IDENTIFIER id X int force )
1929
compile_function(IDENTIFIER id, int force)
1844
{
1930
{
1845
    TYPE t = DEREF_type ( id_function_etc_type ( t ) ) ;
1931
	TYPE t = DEREF_type(id_function_etc_type(t));
1846
    if ( IS_type_func ( t ) ) free_function ( id ) ;
1932
	if (IS_type_func(t)) {
-
 
1933
		free_function(id);
-
 
1934
	}
1847
    check_mangled ( id ) ;
1935
	check_mangled(id);
1848
    UNUSED ( force ) ;
1936
	UNUSED(force);
1849
    return ;
1937
	return;
1850
}
1938
}
1851
 
1939
 
1852
 
1940
 
1853
/*
1941
/*
1854
    COMPILE A VIRTUAL FUNCTION TABLE (DUMMY VERSION)
1942
    COMPILE A VIRTUAL FUNCTION TABLE (DUMMY VERSION)
1855
 
1943
 
1856
    This routine is a dummy for compiling the virtual function table
1944
    This routine is a dummy for compiling the virtual function table
1857
    associated with the polymorphic class type ct when TDF output is
1945
    associated with the polymorphic class type ct when TDF output is
1858
    disabled.
1946
    disabled.
1859
*/
1947
*/
1860
 
1948
 
1861
#if LANGUAGE_CPP
1949
#if LANGUAGE_CPP
1862
 
1950
 
1863
void compile_virtual
1951
void
1864
    PROTO_N ( ( ct, anon ) )
-
 
1865
    PROTO_T ( CLASS_TYPE ct X int anon )
1952
compile_virtual(CLASS_TYPE ct, int anon)
1866
{
1953
{
1867
    UNUSED ( ct ) ;
1954
	UNUSED(ct);
1868
    UNUSED ( anon ) ;
1955
	UNUSED(anon);
1869
    return ;
1956
	return;
1870
}
1957
}
1871
 
1958
 
1872
#endif
1959
#endif
1873
 
1960
 
1874
 
1961
 
Line 1877... Line 1964...
1877
 
1964
 
1878
    This routine is a dummy for compiling the token id when TDF output
1965
    This routine is a dummy for compiling the token id when TDF output
1879
    is disabled.
1966
    is disabled.
1880
*/
1967
*/
1881
 
1968
 
1882
void compile_token
1969
void
1883
    PROTO_N ( ( id, def ) )
-
 
1884
    PROTO_T ( IDENTIFIER id X int def )
1970
compile_token(IDENTIFIER id, int def)
1885
{
1971
{
-
 
1972
	if (!def) {
1886
    if ( !def ) report ( crt_loc, ERR_token_undef ( id ) ) ;
1973
		report(crt_loc, ERR_token_undef(id));
-
 
1974
	}
1887
    return ;
1975
	return;
1888
}
1976
}
1889
 
1977
 
1890
 
1978
 
1891
/*
1979
/*
1892
    COMPILE A TYPE (DUMMY VERSION)
1980
    COMPILE A TYPE (DUMMY VERSION)
1893
 
1981
 
1894
    This routine is a dummy for compiling the type named id when TDF
1982
    This routine is a dummy for compiling the type named id when TDF
1895
    output is disabled.
1983
    output is disabled.
1896
*/
1984
*/
1897
 
1985
 
1898
void compile_type
1986
void
1899
    PROTO_N ( ( id ) )
-
 
1900
    PROTO_T ( IDENTIFIER id )
1987
compile_type(IDENTIFIER id)
1901
{
1988
{
1902
    UNUSED ( id ) ;
1989
	UNUSED(id);
1903
    return ;
1990
	return;
1904
}
1991
}
1905
 
1992
 
1906
 
1993
 
1907
/*
1994
/*
1908
    COMPILE AN EXTERNAL ASSEMBLER DIRECTIVE (DUMMY VERSION)
1995
    COMPILE AN EXTERNAL ASSEMBLER DIRECTIVE (DUMMY VERSION)
1909
 
1996
 
1910
    This routine is a dummy for compiling the asm definition e which is
1997
    This routine is a dummy for compiling the asm definition e which is
1911
    declared outside any function definition.
1998
    declared outside any function definition.
1912
*/
1999
*/
1913
 
2000
 
1914
void compile_asm
2001
void
1915
    PROTO_N ( ( e ) )
-
 
1916
    PROTO_T ( EXP e )
2002
compile_asm(EXP e)
1917
{
2003
{
1918
    UNUSED ( e ) ;
2004
	UNUSED(e);
1919
    return ;
2005
	return;
1920
}
2006
}
1921
 
2007
 
1922
 
2008
 
1923
/*
2009
/*
1924
    COMPILE A COMMENT (DUMMY VERSION)
2010
    COMPILE A COMMENT (DUMMY VERSION)
1925
 
2011
 
1926
    This routine is a dummy for compiling the comment given by s and n
2012
    This routine is a dummy for compiling the comment given by s and n
1927
    when TDF output is disabled.
2013
    when TDF output is disabled.
1928
*/
2014
*/
1929
 
2015
 
1930
void compile_comment
2016
void
1931
    PROTO_N ( ( s, n ) )
-
 
1932
    PROTO_T ( string s X unsigned long n )
2017
compile_comment(string s, unsigned long n)
1933
{
2018
{
1934
    UNUSED ( s ) ;
2019
	UNUSED(s);
1935
    UNUSED ( n ) ;
2020
	UNUSED(n);
1936
    return ;
2021
	return;
1937
}
2022
}
1938
 
2023
 
1939
 
2024
 
1940
/*
2025
/*
1941
    COMPILE A PRESERVED STATIC IDENTIFIER (DUMMY VERSION)
2026
    COMPILE A PRESERVED STATIC IDENTIFIER (DUMMY VERSION)
1942
 
2027
 
1943
    This routine is a dummy for compiling the preserved static identifier
2028
    This routine is a dummy for compiling the preserved static identifier
1944
    id when TDF output is disabled.
2029
    id when TDF output is disabled.
1945
*/
2030
*/
1946
 
2031
 
1947
void compile_preserve
2032
void
1948
    PROTO_N ( ( id ) )
-
 
1949
    PROTO_T ( IDENTIFIER id )
2033
compile_preserve(IDENTIFIER id)
1950
{
2034
{
1951
    UNUSED ( id ) ;
2035
	UNUSED(id);
1952
    return ;
2036
	return;
1953
}
2037
}
1954
 
2038
 
1955
 
2039
 
1956
/*
2040
/*
1957
    COMPILE A WEAK LINKAGE DIRECTIVE (DUMMY VERSION)
2041
    COMPILE A WEAK LINKAGE DIRECTIVE (DUMMY VERSION)
1958
 
2042
 
1959
    This routine is a dummy for compiling the weak linkage directive
2043
    This routine is a dummy for compiling the weak linkage directive
1960
    '#pragma weak id = aid' when TDF output is disabled.
2044
    '#pragma weak id = aid' when TDF output is disabled.
1961
*/
2045
*/
1962
 
2046
 
1963
void compile_weak
2047
void
1964
    PROTO_N ( ( id, aid ) )
-
 
1965
    PROTO_T ( IDENTIFIER id X IDENTIFIER aid )
2048
compile_weak(IDENTIFIER id, IDENTIFIER aid)
1966
{
2049
{
1967
    UNUSED ( id ) ;
2050
	UNUSED(id);
1968
    UNUSED ( aid ) ;
2051
	UNUSED(aid);
1969
    return ;
2052
	return;
1970
}
2053
}
1971
 
2054
 
1972
 
2055
 
1973
/*
2056
/*
1974
    UPDATE A TAG NAME (DUMMY VERSION)
2057
    UPDATE A TAG NAME (DUMMY VERSION)
1975
 
2058
 
1976
    This routine is a dummy for updating the external name of the
2059
    This routine is a dummy for updating the external name of the
1977
    identifier id when TDF output is disabled.
2060
    identifier id when TDF output is disabled.
1978
*/
2061
*/
1979
 
2062
 
1980
void update_tag
2063
void
1981
    PROTO_N ( ( id, ext ) )
-
 
1982
    PROTO_T ( IDENTIFIER id X int ext )
2064
update_tag(IDENTIFIER id, int ext)
1983
{
2065
{
1984
    UNUSED ( id ) ;
2066
	UNUSED(id);
1985
    UNUSED ( ext ) ;
2067
	UNUSED(ext);
1986
    return ;
2068
	return;
1987
}
2069
}
1988
 
2070
 
1989
 
2071
 
1990
#endif /* TDF_OUTPUT */
2072
#endif /* TDF_OUTPUT */