Subversion Repositories tendra.SVN

Rev

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

Rev 5 Rev 6
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2006 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
32
    		 Crown Copyright (c) 1997
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
Line 67... Line 97...
67
 
97
 
68
    The following forward declarations are required in the spec output
98
    The following forward declarations are required in the spec output
69
    routines.
99
    routines.
70
*/
100
*/
71
 
101
 
72
static BITSTREAM *save_exp PROTO_S ( ( BITSTREAM *, EXP, TYPE ) ) ;
102
static BITSTREAM *save_exp(BITSTREAM *, EXP, TYPE);
73
static BITSTREAM *save_type PROTO_S ( ( BITSTREAM *, TYPE, IDENTIFIER ) ) ;
103
static BITSTREAM *save_type(BITSTREAM *, TYPE, IDENTIFIER);
74
static BITSTREAM *save_ctype PROTO_S ( ( BITSTREAM *, CLASS_TYPE, IDENTIFIER ) ) ;
104
static BITSTREAM *save_ctype(BITSTREAM *, CLASS_TYPE, IDENTIFIER);
75
static BITSTREAM *save_type_list PROTO_S ( ( BITSTREAM *, LIST ( TYPE ) ) ) ;
105
static BITSTREAM *save_type_list(BITSTREAM *, LIST(TYPE));
76
static BITSTREAM *save_tok PROTO_S ( ( BITSTREAM *, TOKEN, int ) ) ;
106
static BITSTREAM *save_tok(BITSTREAM *, TOKEN, int);
77
 
107
 
78
 
108
 
79
/*
109
/*
80
    SIMPLE WRITING ROUTINES
110
    SIMPLE WRITING ROUTINES
81
 
111
 
82
    These macros give the simple writing routines for the enumeration
112
    These macros give the simple writing routines for the enumeration
83
    types etc.  Note that ENC_BITS_2 is used when the values occupy more
113
    types etc.  Note that ENC_BITS_2 is used when the values occupy more
84
    than 16 bits.
114
    than 16 bits.
85
*/
115
*/
86
 
116
 
87
#define save_btype( A, B )	ENC_BITS_2 ( ( A ), BITS_btype, ( B ) )
117
#define save_btype(A, B)	ENC_BITS_2((A), BITS_btype,(B))
88
#define save_cinfo( A, B )	ENC_BITS_2 ( ( A ), BITS_cinfo, ( B ) )
118
#define save_cinfo(A, B)	ENC_BITS_2((A), BITS_cinfo,(B))
89
#define save_cusage( A, B )	ENC_BITS ( ( A ), BITS_cusage, ( B ) )
119
#define save_cusage(A, B)	ENC_BITS((A), BITS_cusage,(B))
90
#define save_cv( A, B )		ENC_BITS ( ( A ), BITS_cv_qual, ( B ) )
120
#define save_cv(A, B)		ENC_BITS((A), BITS_cv_qual,(B))
91
#define save_dspec( A, B )	ENC_BITS_2 ( ( A ), BITS_dspec, ( B ) )
121
#define save_dspec(A, B)	ENC_BITS_2((A), BITS_dspec,(B))
92
#define save_lex( A, B )	ENC_BITS ( ( A ), BITS_lex, ( B ) )
122
#define save_lex(A, B)		ENC_BITS((A), BITS_lex,(B))
93
#define save_mqual( A, B )	ENC_BITS ( ( A ), BITS_cv, ( B ) )
123
#define save_mqual(A, B)	ENC_BITS((A), BITS_cv,(B))
94
#define save_ntype( A, B )	ENC_BITS ( ( A ), BITS_ntype, ( B ) )
124
#define save_ntype(A, B)	ENC_BITS((A), BITS_ntype,(B))
95
#define save_qual( A, B )	ENC_BITS ( ( A ), BITS_qual, ( B ) )
125
#define save_qual(A, B)		ENC_BITS((A), BITS_qual,(B))
96
 
126
 
97
 
127
 
98
/*
128
/*
99
    WRITE A LIST OF PREPROCESSING TOKENS
129
    WRITE A LIST OF PREPROCESSING TOKENS
100
 
130
 
101
    This routine writes the list of preprocessing tokens p to the
131
    This routine writes the list of preprocessing tokens p to the
102
    bitstream bs.
132
    bitstream bs.
103
*/
133
*/
104
 
134
 
105
static BITSTREAM *save_pptoks
135
static BITSTREAM *
106
    PROTO_N ( ( bs, p ) )
-
 
107
    PROTO_T ( BITSTREAM *bs X PPTOKEN *p )
136
save_pptoks(BITSTREAM *bs, PPTOKEN *p)
108
{
137
{
109
    /* NOT YET IMPLEMENTED */
138
	/* NOT YET IMPLEMENTED */
110
    UNUSED ( p ) ;
139
	UNUSED(p);
111
    return ( bs ) ;
140
	return (bs);
112
}
141
}
113
 
142
 
114
 
143
 
115
/*
144
/*
116
    WRITE A LOCATION
145
    WRITE A LOCATION
117
 
146
 
118
    This routine writes the location ploc to the bitstream bs.
147
    This routine writes the location ploc to the bitstream bs.
119
*/
148
*/
120
 
149
 
121
static BITSTREAM *save_loc
150
static BITSTREAM *
122
    PROTO_N ( ( bs, ploc ) )
-
 
123
    PROTO_T ( BITSTREAM *bs X PTR ( LOCATION ) ploc )
151
save_loc(BITSTREAM *bs, PTR(LOCATION)ploc)
124
{
152
{
125
    static LOCATION last_loc = NULL_loc ;
153
	static LOCATION last_loc = NULL_loc;
126
    if ( !IS_NULL_ptr ( ploc ) ) {
154
	if (!IS_NULL_ptr(ploc)) {
127
	unsigned long ln = DEREF_ulong ( loc_line ( ploc ) ) ;
155
		unsigned long ln = DEREF_ulong(loc_line(ploc));
128
	PTR ( POSITION ) posn = DEREF_ptr ( loc_posn ( ploc ) ) ;
156
		PTR(POSITION)posn = DEREF_ptr(loc_posn(ploc));
129
	if ( EQ_ptr ( posn, last_loc.posn ) || IS_NULL_ptr ( posn ) ) {
157
		if (EQ_ptr(posn, last_loc.posn) || IS_NULL_ptr(posn)) {
130
	    if ( ln == last_loc.line ) {
158
			if (ln == last_loc.line) {
131
		/* Same position */
159
				/* Same position */
132
		ENC_OFF ( bs ) ;
160
				ENC_OFF(bs);
133
	    } else {
161
			} else {
134
		/* Different line */
162
				/* Different line */
135
		ENC_ON ( bs ) ;
163
				ENC_ON(bs);
136
		ENC_INT ( bs, ln ) ;
164
				ENC_INT(bs, ln);
137
		ENC_OFF ( bs ) ;
165
				ENC_OFF(bs);
138
		last_loc.line = ln ;
166
				last_loc.line = ln;
139
	    }
167
			}
140
	} else {
168
		} else {
141
	    int eq =0 ;
169
			int eq =0;
142
	    unsigned long off = DEREF_ulong ( posn_offset ( posn ) ) ;
170
			unsigned long off = DEREF_ulong(posn_offset(posn));
143
	    string a1 = DEREF_string ( posn_file ( posn ) ) ;
171
			string a1 = DEREF_string(posn_file(posn));
144
	    string b1 = DEREF_string ( posn_input ( posn ) ) ;
172
			string b1 = DEREF_string(posn_input(posn));
145
	    if ( !IS_NULL_ptr ( last_loc.posn ) ) {
173
			if (!IS_NULL_ptr(last_loc.posn)) {
-
 
174
				string a2 =
146
		string a2 = DEREF_string ( posn_file ( last_loc.posn ) ) ;
175
				    DEREF_string(posn_file(last_loc.posn));
-
 
176
				string b2 =
147
		string b2 = DEREF_string ( posn_input ( last_loc.posn ) ) ;
177
				    DEREF_string(posn_input(last_loc.posn));
148
		if ( ustreq ( a1, a2 ) && ustreq ( b1, b2 ) ) {
178
				if (ustreq(a1, a2) && ustreq(b1, b2)) {
149
		    eq = 1 ;
179
					eq = 1;
150
		}
180
				}
151
	    }
181
			}
152
	    ENC_ON ( bs ) ;
182
			ENC_ON(bs);
153
	    ENC_INT ( bs, ln ) ;
183
			ENC_INT(bs, ln);
154
	    ENC_ON ( bs ) ;
184
			ENC_ON(bs);
155
	    ENC_INT ( bs, off ) ;
185
			ENC_INT(bs, off);
156
	    if ( eq ) {
186
			if (eq) {
157
		/* Same file */
187
				/* Same file */
158
		ENC_OFF ( bs ) ;
188
				ENC_OFF(bs);
159
	    } else {
189
			} else {
160
		ulong date ;
190
				ulong date;
161
		ENC_ON ( bs ) ;
191
				ENC_ON(bs);
162
		bs = enc_ustring ( bs, a1 ) ;
192
				bs = enc_ustring(bs, a1);
163
		if ( ustreq ( a1, b1 ) ) {
193
				if (ustreq(a1, b1)) {
164
		    /* Same file names */
194
					/* Same file names */
165
		    ENC_OFF ( bs ) ;
195
					ENC_OFF(bs);
166
		} else {
196
				} else {
167
		    /* Different file names */
197
					/* Different file names */
168
		    ENC_ON ( bs ) ;
198
					ENC_ON(bs);
169
		    bs = enc_ustring ( bs, b1 ) ;
199
					bs = enc_ustring(bs, b1);
170
		}
200
				}
171
		date = DEREF_ulong ( posn_datestamp ( posn ) ) ;
201
				date = DEREF_ulong(posn_datestamp(posn));
172
		ENC_INT ( bs, date ) ;
202
				ENC_INT(bs, date);
173
	    }
203
			}
174
	    last_loc.line = ln ;
204
			last_loc.line = ln;
175
	    last_loc.posn = posn ;
205
			last_loc.posn = posn;
176
	}
206
		}
177
    } else {
207
	} else {
178
	ENC_OFF ( bs ) ;
208
		ENC_OFF(bs);
179
    }
209
	}
180
    return ( bs ) ;
210
	return (bs);
181
}
211
}
182
 
212
 
183
 
213
 
184
/*
214
/*
185
    WRITE AN IDENTIFIER NAME
215
    WRITE AN IDENTIFIER NAME
186
 
216
 
187
    This routine writes the identifier name nm to the bitstream bs.
217
    This routine writes the identifier name nm to the bitstream bs.
188
    ns gives the current namespace.
218
    ns gives the current namespace.
189
*/
219
*/
190
 
220
 
191
static BITSTREAM *save_hashid
221
static BITSTREAM *
192
    PROTO_N ( ( bs, nm, ns ) )
-
 
193
    PROTO_T ( BITSTREAM *bs X HASHID nm X NAMESPACE ns )
222
save_hashid(BITSTREAM *bs, HASHID nm, NAMESPACE ns)
194
{
223
{
195
    if ( IS_NULL_hashid ( nm ) ) {
224
	if (IS_NULL_hashid(nm)) {
196
	ENC_BITS ( bs, BITS_hashid, 0 ) ;
225
		ENC_BITS(bs, BITS_hashid, 0);
197
    } else {
226
	} else {
198
	unsigned tag = TAG_hashid ( nm ) ;
227
		unsigned tag = TAG_hashid(nm);
199
	ENC_BITS ( bs, BITS_hashid, tag + 1 ) ;
228
		ENC_BITS(bs, BITS_hashid, tag + 1);
200
	ASSERT ( ORDER_hashid == 7 ) ;
229
		ASSERT(ORDER_hashid == 7);
201
	switch ( tag ) {
230
		switch (tag) {
202
	    case hashid_name_tag :
231
		case hashid_name_tag:
203
	    case hashid_ename_tag : {
232
		case hashid_ename_tag: {
204
		string s = DEREF_string ( hashid_name_etc_text ( nm ) ) ;
233
			string s = DEREF_string(hashid_name_etc_text(nm));
205
		bs = enc_ustring ( bs, s ) ;
234
			bs = enc_ustring(bs, s);
206
		break ;
235
			break;
207
	    }
236
		}
208
	    case hashid_constr_tag : {
237
		case hashid_constr_tag: {
209
		UNUSED ( ns ) ;
238
			UNUSED(ns);
210
		break ;
239
			break;
211
	    }
240
		}
212
	    case hashid_destr_tag : {
241
		case hashid_destr_tag: {
213
		UNUSED ( ns ) ;
242
			UNUSED(ns);
214
		break ;
243
			break;
215
	    }
244
		}
216
	    case hashid_conv_tag : {
245
		case hashid_conv_tag: {
217
		TYPE t = DEREF_type ( hashid_conv_type ( nm ) ) ;
246
			TYPE t = DEREF_type(hashid_conv_type(nm));
218
		bs = save_type ( bs, t, NULL_id ) ;
247
			bs = save_type(bs, t, NULL_id);
219
		break ;
248
			break;
220
	    }
249
		}
221
	    case hashid_op_tag : {
250
		case hashid_op_tag: {
222
		int op = DEREF_int ( hashid_op_lex ( nm ) ) ;
251
			int op = DEREF_int(hashid_op_lex(nm));
223
		save_lex ( bs, op ) ;
252
			save_lex(bs, op);
224
		break ;
253
			break;
225
	    }
254
		}
226
	    case hashid_anon_tag : {
255
		case hashid_anon_tag: {
227
		break ;
256
			break;
228
	    }
257
		}
229
	}
258
		}
230
    }
259
	}
231
    return ( bs ) ;
260
	return (bs);
232
}
261
}
233
 
262
 
234
 
263
 
235
/*
264
/*
236
    WRITE A LIST OF IDENTIFIER NAMES
265
    WRITE A LIST OF IDENTIFIER NAMES
237
 
266
 
238
    This routine saves a list of identifier names to the bitstream bs.
267
    This routine saves a list of identifier names to the bitstream bs.
239
*/
268
*/
240
 
269
 
241
static BITSTREAM *save_hashid_list
270
static BITSTREAM *
242
    PROTO_N ( ( bs, p, ns ) )
-
 
243
    PROTO_T ( BITSTREAM *bs X LIST ( HASHID ) p X NAMESPACE ns )
271
save_hashid_list(BITSTREAM *bs, LIST(HASHID)p, NAMESPACE ns)
244
{
272
{
245
    while ( !IS_NULL_list ( p ) ) {
273
	while (!IS_NULL_list(p)) {
246
	HASHID nm = DEREF_hashid ( HEAD_list ( p ) ) ;
274
		HASHID nm = DEREF_hashid(HEAD_list(p));
247
	ENC_ON ( bs ) ;
275
		ENC_ON(bs);
248
	bs = save_hashid ( bs, nm, ns ) ;
276
		bs = save_hashid(bs, nm, ns);
249
	p = TAIL_list ( p ) ;
277
		p = TAIL_list(p);
250
    }
278
	}
251
    ENC_OFF ( bs ) ;
279
	ENC_OFF(bs);
252
    return ( bs ) ;
280
	return (bs);
253
}
281
}
254
 
282
 
255
 
283
 
256
/*
284
/*
257
    WRITE AN IDENTIFIER NUMBER
285
    WRITE AN IDENTIFIER NUMBER
258
 
286
 
259
    This routine writes the identifier number for the identifier id to
287
    This routine writes the identifier number for the identifier id to
260
    the bitstream bs.  The spec and dump output formats share the same
288
    the bitstream bs.  The spec and dump output formats share the same
261
    identifier numbers, with zero representing the null identifier.
289
    identifier numbers, with zero representing the null identifier.
262
*/
290
*/
263
 
291
 
264
static BITSTREAM *save_use
292
static BITSTREAM *
265
    PROTO_N ( ( bs, id ) )
-
 
266
    PROTO_T ( BITSTREAM *bs X IDENTIFIER id )
293
save_use(BITSTREAM *bs, IDENTIFIER id)
267
{
294
{
268
    ulong d = 0 ;
295
	ulong d = 0;
269
    if ( !IS_NULL_id ( id ) ) {
296
	if (!IS_NULL_id(id)) {
270
	d = DEREF_ulong ( id_dump ( id ) ) ;
297
		d = DEREF_ulong(id_dump(id));
271
	if ( d == LINK_NONE ) {
298
		if (d == LINK_NONE) {
272
	    d = dump_id_next++ ;
299
			d = dump_id_next++;
273
	    d |= LINK_EXTERN ;
300
			d |= LINK_EXTERN;
274
	    COPY_ulong ( id_dump ( id ), d ) ;
301
			COPY_ulong(id_dump(id), d);
-
 
302
		}
-
 
303
		d &= ~LINK_EXTERN;
275
	}
304
	}
276
	d &= ~LINK_EXTERN ;
-
 
277
    }
-
 
278
    ENC_INT ( bs, d ) ;
305
	ENC_INT(bs, d);
279
    return ( bs ) ;
306
	return (bs);
280
}
307
}
281
 
308
 
282
 
309
 
283
/*
310
/*
284
    WRITE A LIST OF IDENTIFIER NUMBERS
311
    WRITE A LIST OF IDENTIFIER NUMBERS
285
 
312
 
286
    This routine saves a list of identifier numbers to the bitstream bs.
313
    This routine saves a list of identifier numbers to the bitstream bs.
287
*/
314
*/
288
 
315
 
289
static BITSTREAM *save_use_list
316
static BITSTREAM *
290
    PROTO_N ( ( bs, p ) )
-
 
291
    PROTO_T ( BITSTREAM *bs X LIST ( IDENTIFIER ) p )
317
save_use_list(BITSTREAM *bs, LIST(IDENTIFIER)p)
292
{
318
{
293
    while ( !IS_NULL_list ( p ) ) {
319
	while (!IS_NULL_list(p)) {
294
	IDENTIFIER id = DEREF_id ( HEAD_list ( p ) ) ;
320
		IDENTIFIER id = DEREF_id(HEAD_list(p));
295
	ENC_ON ( bs ) ;
321
		ENC_ON(bs);
296
	bs = save_use ( bs, id ) ;
322
		bs = save_use(bs, id);
297
	p = TAIL_list ( p ) ;
323
		p = TAIL_list(p);
298
    }
324
	}
299
    ENC_OFF ( bs ) ;
325
	ENC_OFF(bs);
300
    return ( bs ) ;
326
	return (bs);
301
}
327
}
302
 
328
 
303
 
329
 
304
/*
330
/*
305
    WRITE A LIST OF IDENTIFIERS
331
    WRITE A LIST OF IDENTIFIERS
306
 
332
 
307
    This routine saves a list of identifiers to the bitstream bs.
333
    This routine saves a list of identifiers to the bitstream bs.
308
*/
334
*/
309
 
335
 
310
static BITSTREAM *save_id_list
336
static BITSTREAM *
311
    PROTO_N ( ( bs, p, ns ) )
-
 
312
    PROTO_T ( BITSTREAM *bs X LIST ( IDENTIFIER ) p X NAMESPACE ns )
337
save_id_list(BITSTREAM *bs, LIST(IDENTIFIER)p, NAMESPACE ns)
313
{
338
{
314
    while ( !IS_NULL_list ( p ) ) {
339
	while (!IS_NULL_list(p)) {
315
	IDENTIFIER id = DEREF_id ( HEAD_list ( p ) ) ;
340
		IDENTIFIER id = DEREF_id(HEAD_list(p));
316
	ENC_ON ( bs ) ;
341
		ENC_ON(bs);
317
	bs = save_id ( bs, id, ns ) ;
342
		bs = save_id(bs, id, ns);
318
	p = TAIL_list ( p ) ;
343
		p = TAIL_list(p);
319
    }
344
	}
320
    ENC_OFF ( bs ) ;
345
	ENC_OFF(bs);
321
    return ( bs ) ;
346
	return (bs);
322
}
347
}
323
 
348
 
324
 
349
 
325
/*
350
/*
326
    WRITE A LIST OF TOKENS
351
    WRITE A LIST OF TOKENS
327
 
352
 
328
    This routine writes the list of tokens p to the bitstream bs.  def
353
    This routine writes the list of tokens p to the bitstream bs.  def
329
    is as in save_tok.
354
    is as in save_tok.
330
*/
355
*/
331
 
356
 
332
static BITSTREAM *save_tok_list
357
static BITSTREAM *
333
    PROTO_N ( ( bs, p, def ) )
-
 
334
    PROTO_T ( BITSTREAM *bs X LIST ( TOKEN ) p X int def )
358
save_tok_list(BITSTREAM *bs, LIST(TOKEN)p, int def)
335
{
359
{
336
    while ( !IS_NULL_list ( p ) ) {
360
	while (!IS_NULL_list(p)) {
337
	TOKEN tok = DEREF_tok ( HEAD_list ( p ) ) ;
361
		TOKEN tok = DEREF_tok(HEAD_list(p));
338
	ENC_ON ( bs ) ;
362
		ENC_ON(bs);
339
	bs = save_tok ( bs, tok, def ) ;
363
		bs = save_tok(bs, tok, def);
340
	p = TAIL_list ( p ) ;
364
		p = TAIL_list(p);
341
    }
365
	}
342
    ENC_OFF ( bs ) ;
366
	ENC_OFF(bs);
343
    return ( bs ) ;
367
	return (bs);
344
}
368
}
345
 
369
 
346
 
370
 
347
/*
371
/*
348
    WRITE AN INTEGER CONSTANT
372
    WRITE AN INTEGER CONSTANT
349
 
373
 
350
    This routine writes the integer constant n to the bitstream bs.
374
    This routine writes the integer constant n to the bitstream bs.
351
*/
375
*/
352
 
376
 
353
static BITSTREAM *save_nat
377
static BITSTREAM *
354
    PROTO_N ( ( bs, n ) )
-
 
355
    PROTO_T ( BITSTREAM *bs X NAT n )
378
save_nat(BITSTREAM *bs, NAT n)
356
{
-
 
357
    unsigned tag ;
-
 
358
    if ( IS_NULL_nat ( n ) ) {
-
 
359
	ENC_BITS ( bs, BITS_nat, 0 ) ;
-
 
360
	return ( bs ) ;
-
 
361
    }
-
 
362
    tag = TAG_nat ( n ) ;
-
 
363
    ENC_BITS ( bs, BITS_nat, tag + 1 ) ;
-
 
364
    ASSERT ( ORDER_nat == 5 ) ;
-
 
365
    switch ( tag ) {
-
 
366
	case nat_small_tag : {
-
 
367
	    unsigned v = DEREF_unsigned ( nat_small_value ( n ) ) ;
-
 
368
	    ENC_INT ( bs, v ) ;
-
 
369
	    break ;
-
 
370
	}
-
 
371
	case nat_large_tag : {
-
 
372
	    LIST ( unsigned ) p = DEREF_list ( nat_large_values ( n ) ) ;
-
 
373
	    while ( !IS_NULL_list ( p ) ) {
-
 
374
		unsigned v = DEREF_unsigned ( HEAD_list ( p ) ) ;
-
 
375
		ENC_ON ( bs ) ;
-
 
376
		ENC_INT ( bs, v ) ;
-
 
377
		p = TAIL_list ( p ) ;
-
 
378
	    }
-
 
379
	    ENC_OFF ( bs ) ;
-
 
380
	    break ;
-
 
381
	}
-
 
382
	case nat_calc_tag : {
-
 
383
	    EXP e = DEREF_exp ( nat_calc_value ( n ) ) ;
-
 
384
	    bs = save_exp ( bs, e, type_sint ) ;
-
 
385
	    break ;
-
 
386
	}
-
 
387
	case nat_neg_tag : {
-
 
388
	    NAT m = DEREF_nat ( nat_neg_arg ( n ) ) ;
-
 
389
	    bs = save_nat ( bs, m ) ;
-
 
390
	    break ;
-
 
391
	}
-
 
392
	case nat_token_tag : {
-
 
393
	    IDENTIFIER tok = DEREF_id ( nat_token_tok ( n ) ) ;
-
 
394
	    LIST ( TOKEN ) args = DEREF_list ( nat_token_args ( n ) ) ;
-
 
395
	    bs = save_use ( bs, tok ) ;
-
 
396
	    bs = save_tok_list ( bs, args, 1 ) ;
-
 
397
	    break ;
-
 
398
	}
-
 
399
    }
-
 
400
    return ( bs ) ;
-
 
401
}
-
 
402
 
-
 
403
 
-
 
404
/*
-
 
405
    WRITE AN OFFSET
-
 
406
 
-
 
407
    This routine writes the offset off to the bitstream bs.
-
 
408
*/
-
 
409
 
-
 
410
static BITSTREAM *save_off
-
 
411
    PROTO_N ( ( bs, off ) )
-
 
412
    PROTO_T ( BITSTREAM *bs X OFFSET off )
-
 
413
{
-
 
414
    /* NOT YET IMPLEMENTED */
-
 
415
    UNUSED ( off ) ;
-
 
416
    return ( bs ) ;
-
 
417
}
-
 
418
 
-
 
419
 
-
 
420
/*
-
 
421
    WRITE AN EXPRESSION
-
 
422
 
-
 
423
    This routine writes the expression e to the bitstream bs.
-
 
424
*/
-
 
425
 
-
 
426
static BITSTREAM *save_exp
-
 
427
    PROTO_N ( ( bs, e, t ) )
-
 
428
    PROTO_T ( BITSTREAM *bs X EXP e X TYPE t )
-
 
429
{
379
{
430
    unsigned tag ;
380
	unsigned tag;
431
    if ( IS_NULL_exp ( e ) ) {
381
	if (IS_NULL_nat(n)) {
432
	ENC_BITS ( bs, BITS_exp, 0 ) ;
382
		ENC_BITS(bs, BITS_nat, 0);
433
	return ( bs ) ;
383
		return (bs);
434
    }
-
 
435
    tag = TAG_exp ( e ) ;
-
 
436
    ENC_BITS ( bs, BITS_exp, tag + 1 ) ;
-
 
437
    switch ( tag ) {
-
 
438
	case exp_int_lit_tag : {
-
 
439
	    NAT m = DEREF_nat ( exp_int_lit_nat ( e ) ) ;
-
 
440
	    unsigned etag = DEREF_unsigned ( exp_int_lit_etag ( e ) ) ;
-
 
441
	    bs = save_nat ( bs, m ) ;
-
 
442
	    ENC_BITS ( bs, BITS_exp, etag ) ;
-
 
443
	    break ;
-
 
444
	}
384
	}
-
 
385
	tag = TAG_nat(n);
-
 
386
	ENC_BITS(bs, BITS_nat, tag + 1);
-
 
387
	ASSERT(ORDER_nat == 5);
-
 
388
	switch (tag) {
-
 
389
	case nat_small_tag: {
-
 
390
		unsigned v = DEREF_unsigned(nat_small_value(n));
-
 
391
		ENC_INT(bs, v);
-
 
392
		break;
-
 
393
	}
-
 
394
	case nat_large_tag: {
-
 
395
		LIST(unsigned)p = DEREF_list(nat_large_values(n));
-
 
396
		while (!IS_NULL_list(p)) {
-
 
397
			unsigned v = DEREF_unsigned(HEAD_list(p));
-
 
398
			ENC_ON(bs);
-
 
399
			ENC_INT(bs, v);
-
 
400
			p = TAIL_list(p);
-
 
401
		}
-
 
402
		ENC_OFF(bs);
-
 
403
		break;
-
 
404
	}
-
 
405
	case nat_calc_tag: {
-
 
406
		EXP e = DEREF_exp(nat_calc_value(n));
-
 
407
		bs = save_exp(bs, e, type_sint);
-
 
408
		break;
-
 
409
	}
-
 
410
	case nat_neg_tag: {
-
 
411
		NAT m = DEREF_nat(nat_neg_arg(n));
-
 
412
		bs = save_nat(bs, m);
-
 
413
		break;
-
 
414
	}
-
 
415
	case nat_token_tag: {
-
 
416
		IDENTIFIER tok = DEREF_id(nat_token_tok(n));
-
 
417
		LIST(TOKEN)args = DEREF_list(nat_token_args(n));
-
 
418
		bs = save_use(bs, tok);
-
 
419
		bs = save_tok_list(bs, args, 1);
-
 
420
		break;
-
 
421
	}
-
 
422
	}
-
 
423
	return (bs);
-
 
424
}
-
 
425
 
-
 
426
 
-
 
427
/*
-
 
428
    WRITE AN OFFSET
-
 
429
 
-
 
430
    This routine writes the offset off to the bitstream bs.
-
 
431
*/
-
 
432
 
-
 
433
static BITSTREAM *
-
 
434
save_off(BITSTREAM *bs, OFFSET off)
-
 
435
{
-
 
436
	/* NOT YET IMPLEMENTED */
-
 
437
	UNUSED(off);
-
 
438
	return (bs);
-
 
439
}
-
 
440
 
-
 
441
 
-
 
442
/*
-
 
443
    WRITE AN EXPRESSION
-
 
444
 
-
 
445
    This routine writes the expression e to the bitstream bs.
-
 
446
*/
-
 
447
 
-
 
448
static BITSTREAM *
-
 
449
save_exp(BITSTREAM *bs, EXP e, TYPE t)
-
 
450
{
-
 
451
	unsigned tag;
-
 
452
	if (IS_NULL_exp(e)) {
-
 
453
		ENC_BITS(bs, BITS_exp, 0);
-
 
454
		return (bs);
-
 
455
	}
-
 
456
	tag = TAG_exp(e);
-
 
457
	ENC_BITS(bs, BITS_exp, tag + 1);
-
 
458
	switch (tag) {
-
 
459
	case exp_int_lit_tag: {
-
 
460
		NAT m = DEREF_nat(exp_int_lit_nat(e));
-
 
461
		unsigned etag = DEREF_unsigned(exp_int_lit_etag(e));
-
 
462
		bs = save_nat(bs, m);
-
 
463
		ENC_BITS(bs, BITS_exp, etag);
-
 
464
		break;
-
 
465
	}
445
	case exp_token_tag : {
466
	case exp_token_tag: {
446
	    IDENTIFIER tok = DEREF_id ( exp_token_tok ( e ) ) ;
467
		IDENTIFIER tok = DEREF_id(exp_token_tok(e));
447
	    LIST ( TOKEN ) args = DEREF_list ( exp_token_args ( e ) ) ;
468
		LIST(TOKEN)args = DEREF_list(exp_token_args(e));
448
	    bs = save_use ( bs, tok ) ;
469
		bs = save_use(bs, tok);
449
	    bs = save_tok_list ( bs, args, 1 ) ;
470
		bs = save_tok_list(bs, args, 1);
-
 
471
		break;
-
 
472
	}
-
 
473
	default: {
-
 
474
		/* NOT YET IMPLEMENTED */
450
	    break ;
475
		break;
451
	}
476
	}
452
	default : {
-
 
453
	    /* NOT YET IMPLEMENTED */
-
 
454
	    break ;
-
 
455
	}
477
	}
456
    }
-
 
457
    UNUSED ( t ) ;
478
	UNUSED(t);
458
    return ( bs ) ;
479
	return (bs);
459
}
480
}
460
 
481
 
461
 
482
 
462
/*
483
/*
463
    WRITE AN INTEGRAL TYPE
484
    WRITE AN INTEGRAL TYPE
464
 
485
 
465
    This routine writes the integral type it to the bitstream bs.
486
    This routine writes the integral type it to the bitstream bs.
466
*/
487
*/
467
 
488
 
468
static BITSTREAM *save_itype
489
static BITSTREAM *
469
    PROTO_N ( ( bs, it ) )
-
 
470
    PROTO_T ( BITSTREAM *bs X INT_TYPE it )
490
save_itype(BITSTREAM *bs, INT_TYPE it)
471
{
491
{
472
    unsigned tag ;
492
	unsigned tag;
473
    if ( IS_NULL_itype ( it ) ) {
493
	if (IS_NULL_itype(it)) {
474
	ENC_BITS ( bs, BITS_itype, 0 ) ;
494
		ENC_BITS(bs, BITS_itype, 0);
475
	return ( bs ) ;
495
		return (bs);
476
    }
496
	}
477
    tag = TAG_itype ( it ) ;
497
	tag = TAG_itype(it);
478
    ENC_BITS ( bs, BITS_itype, tag + 1 ) ;
498
	ENC_BITS(bs, BITS_itype, tag + 1);
479
    ASSERT ( ORDER_itype == 6 ) ;
499
	ASSERT(ORDER_itype == 6);
480
    switch ( tag ) {
500
	switch (tag) {
481
	case itype_basic_tag : {
501
	case itype_basic_tag: {
482
	    BUILTIN_TYPE nt = DEREF_ntype ( itype_basic_no ( it ) ) ;
502
		BUILTIN_TYPE nt = DEREF_ntype(itype_basic_no(it));
483
	    save_ntype ( bs, nt ) ;
503
		save_ntype(bs, nt);
484
	    break ;
504
		break;
485
	}
505
	}
486
	case itype_bitfield_tag : {
506
	case itype_bitfield_tag: {
487
	    NAT m = DEREF_nat ( itype_bitfield_size ( it ) ) ;
507
		NAT m = DEREF_nat(itype_bitfield_size(it));
488
	    TYPE s = DEREF_type ( itype_bitfield_sub ( it ) ) ;
508
		TYPE s = DEREF_type(itype_bitfield_sub(it));
489
	    BASE_TYPE bt = DEREF_btype ( itype_bitfield_rep ( it ) ) ;
509
		BASE_TYPE bt = DEREF_btype(itype_bitfield_rep(it));
490
	    bs = save_type ( bs, s, NULL_id ) ;
510
		bs = save_type(bs, s, NULL_id);
491
	    save_btype ( bs, bt ) ;
511
		save_btype(bs, bt);
492
	    bs = save_nat ( bs, m ) ;
512
		bs = save_nat(bs, m);
493
	    break ;
513
		break;
494
	}
514
	}
495
	case itype_promote_tag : {
515
	case itype_promote_tag: {
496
	    INT_TYPE is = DEREF_itype ( itype_promote_arg ( it ) ) ;
516
		INT_TYPE is = DEREF_itype(itype_promote_arg(it));
497
	    bs = save_itype ( bs, is ) ;
517
		bs = save_itype(bs, is);
498
	    break ;
518
		break;
499
	}
519
	}
500
	case itype_arith_tag : {
520
	case itype_arith_tag: {
501
	    INT_TYPE is = DEREF_itype ( itype_arith_arg1 ( it ) ) ;
521
		INT_TYPE is = DEREF_itype(itype_arith_arg1(it));
502
	    INT_TYPE ir = DEREF_itype ( itype_arith_arg2 ( it ) ) ;
522
		INT_TYPE ir = DEREF_itype(itype_arith_arg2(it));
503
	    bs = save_itype ( bs, is ) ;
523
		bs = save_itype(bs, is);
504
	    bs = save_itype ( bs, ir ) ;
524
		bs = save_itype(bs, ir);
505
	    break ;
525
		break;
506
	}
526
	}
507
	case itype_literal_tag : {
527
	case itype_literal_tag: {
508
	    NAT m = DEREF_nat ( itype_literal_nat ( it ) ) ;
528
		NAT m = DEREF_nat(itype_literal_nat(it));
509
	    int form = DEREF_int ( itype_literal_form ( it ) ) ;
529
		int form = DEREF_int(itype_literal_form(it));
510
	    int suff = DEREF_int ( itype_literal_suff ( it ) ) ;
530
		int suff = DEREF_int(itype_literal_suff(it));
511
	    bs = save_nat ( bs, m ) ;
531
		bs = save_nat(bs, m);
512
	    ENC_BITS ( bs, 2, form ) ;
532
		ENC_BITS(bs, 2, form);
513
	    ENC_BITS ( bs, 3, suff ) ;
533
		ENC_BITS(bs, 3, suff);
514
	    break ;
534
		break;
515
	}
535
	}
516
	case itype_token_tag : {
536
	case itype_token_tag: {
517
	    IDENTIFIER tok = DEREF_id ( itype_token_tok ( it ) ) ;
537
		IDENTIFIER tok = DEREF_id(itype_token_tok(it));
518
	    LIST ( TOKEN ) args = DEREF_list ( itype_token_args ( it ) ) ;
538
		LIST(TOKEN)args = DEREF_list(itype_token_args(it));
519
	    bs = save_use ( bs, tok ) ;
539
		bs = save_use(bs, tok);
520
	    bs = save_tok_list ( bs, args, 1 ) ;
540
		bs = save_tok_list(bs, args, 1);
521
	    break ;
541
		break;
522
	}
542
	}
523
    }
543
	}
524
    return ( bs ) ;
544
	return (bs);
525
}
545
}
526
 
546
 
527
 
547
 
528
/*
548
/*
529
    WRITE A FLOATING POINT TYPE
549
    WRITE A FLOATING POINT TYPE
530
 
550
 
531
    This routine writes the floating point type ft to the bitstream bs.
551
    This routine writes the floating point type ft to the bitstream bs.
532
*/
552
*/
533
 
553
 
534
static BITSTREAM *save_ftype
554
static BITSTREAM *
535
    PROTO_N ( ( bs, ft ) )
-
 
536
    PROTO_T ( BITSTREAM *bs X FLOAT_TYPE ft )
555
save_ftype(BITSTREAM *bs, FLOAT_TYPE ft)
537
{
556
{
538
    unsigned tag ;
557
	unsigned tag;
539
    if ( IS_NULL_ftype ( ft ) ) {
558
	if (IS_NULL_ftype(ft)) {
540
	ENC_BITS ( bs, BITS_ftype, 0 ) ;
559
		ENC_BITS(bs, BITS_ftype, 0);
541
	return ( bs ) ;
560
		return (bs);
542
    }
561
	}
543
    tag = TAG_ftype ( ft ) ;
562
	tag = TAG_ftype(ft);
544
    ENC_BITS ( bs, BITS_ftype, tag + 1 ) ;
563
	ENC_BITS(bs, BITS_ftype, tag + 1);
545
    switch ( tag ) {
564
	switch (tag) {
546
	case ftype_basic_tag : {
565
	case ftype_basic_tag: {
547
	    BUILTIN_TYPE no = DEREF_ntype ( ftype_basic_no ( ft ) ) ;
566
		BUILTIN_TYPE no = DEREF_ntype(ftype_basic_no(ft));
548
	    save_ntype ( bs, no ) ;
567
		save_ntype(bs, no);
549
	    break ;
568
		break;
550
	}
569
	}
551
	case ftype_arg_promote_tag : {
570
	case ftype_arg_promote_tag: {
552
	    FLOAT_TYPE fs = DEREF_ftype ( ftype_arg_promote_arg ( ft ) ) ;
571
		FLOAT_TYPE fs = DEREF_ftype(ftype_arg_promote_arg(ft));
-
 
572
		bs = save_ftype(bs, fs);
-
 
573
		break;
-
 
574
	}
-
 
575
	case ftype_arith_tag: {
-
 
576
		FLOAT_TYPE fs = DEREF_ftype(ftype_arith_arg1(ft));
-
 
577
		FLOAT_TYPE fr = DEREF_ftype(ftype_arith_arg2(ft));
553
	    bs = save_ftype ( bs, fs ) ;
578
		bs = save_ftype(bs, fs);
-
 
579
		bs = save_ftype(bs, fr);
-
 
580
		break;
-
 
581
	}
-
 
582
	case ftype_token_tag: {
-
 
583
		IDENTIFIER tok = DEREF_id(ftype_token_tok(ft));
-
 
584
		LIST(TOKEN)args = DEREF_list(ftype_token_args(ft));
-
 
585
		bs = save_use(bs, tok);
-
 
586
		bs = save_tok_list(bs, args, 1);
554
	    break ;
587
		break;
555
	}
588
	}
556
	case ftype_arith_tag : {
-
 
557
	    FLOAT_TYPE fs = DEREF_ftype ( ftype_arith_arg1 ( ft ) ) ;
-
 
558
	    FLOAT_TYPE fr = DEREF_ftype ( ftype_arith_arg2 ( ft ) ) ;
-
 
559
	    bs = save_ftype ( bs, fs ) ;
-
 
560
	    bs = save_ftype ( bs, fr ) ;
-
 
561
	    break ;
-
 
562
	}
589
	}
563
	case ftype_token_tag : {
-
 
564
	    IDENTIFIER tok = DEREF_id ( ftype_token_tok ( ft ) ) ;
-
 
565
	    LIST ( TOKEN ) args = DEREF_list ( ftype_token_args ( ft ) ) ;
-
 
566
	    bs = save_use ( bs, tok ) ;
-
 
567
	    bs = save_tok_list ( bs, args, 1 ) ;
-
 
568
	    break ;
-
 
569
	}
-
 
570
    }
-
 
571
    return ( bs ) ;
590
	return (bs);
572
}
591
}
573
 
592
 
574
 
593
 
575
/*
594
/*
576
    WRITE A BASE CLASS GRAPH
595
    WRITE A BASE CLASS GRAPH
577
 
596
 
578
    This routine writes the base class graph gr to the bitstream bs.
597
    This routine writes the base class graph gr to the bitstream bs.
579
    The graph gt gives the top of the graph which is not output.
598
    The graph gt gives the top of the graph which is not output.
580
*/
599
*/
581
 
600
 
582
static BITSTREAM *save_graph
601
static BITSTREAM *
583
    PROTO_N ( ( bs, gr, gt ) )
-
 
584
    PROTO_T ( BITSTREAM *bs X GRAPH gr X GRAPH gt )
602
save_graph(BITSTREAM *bs, GRAPH gr, GRAPH gt)
585
{
603
{
586
    LIST ( GRAPH ) br = DEREF_list ( graph_tails ( gr ) ) ;
604
	LIST(GRAPH)br = DEREF_list(graph_tails(gr));
587
    if ( !EQ_graph ( gr, gt ) ) {
605
	if (!EQ_graph(gr, gt)) {
588
	CLASS_TYPE ct = DEREF_ctype ( graph_head ( gr ) ) ;
606
		CLASS_TYPE ct = DEREF_ctype(graph_head(gr));
589
	DECL_SPEC acc = DEREF_dspec ( graph_access ( gr ) ) ;
607
		DECL_SPEC acc = DEREF_dspec(graph_access(gr));
590
	bs = save_ctype ( bs, ct, NULL_id ) ;
608
		bs = save_ctype(bs, ct, NULL_id);
591
	save_dspec ( bs, acc ) ;
609
		save_dspec(bs, acc);
592
    }
610
	}
593
    while ( !IS_NULL_list ( br ) ) {
611
	while (!IS_NULL_list(br)) {
594
	GRAPH gs = DEREF_graph ( HEAD_list ( br ) ) ;
612
		GRAPH gs = DEREF_graph(HEAD_list(br));
595
	ENC_ON ( bs ) ;
613
		ENC_ON(bs);
596
	bs = save_graph ( bs, gs, gt ) ;
614
		bs = save_graph(bs, gs, gt);
597
	br = TAIL_list ( br ) ;
615
		br = TAIL_list(br);
598
    }
616
	}
599
    ENC_OFF ( bs ) ;
617
	ENC_OFF(bs);
600
    return ( bs ) ;
618
	return (bs);
601
}
619
}
602
 
620
 
603
 
621
 
604
/*
622
/*
605
    WRITE A CLASS TYPE
623
    WRITE A CLASS TYPE
Line 607... Line 625...
607
    This routine writes the class type ct to the bitstream bs.  If def
625
    This routine writes the class type ct to the bitstream bs.  If def
608
    is not null then the full definition is written, otherwise just a use
626
    is not null then the full definition is written, otherwise just a use
609
    is written.
627
    is written.
610
*/
628
*/
611
 
629
 
612
static BITSTREAM *save_ctype
630
static BITSTREAM *
613
    PROTO_N ( ( bs, ct, def ) )
-
 
614
    PROTO_T ( BITSTREAM *bs X CLASS_TYPE ct X IDENTIFIER def )
631
save_ctype(BITSTREAM *bs, CLASS_TYPE ct, IDENTIFIER def)
615
{
632
{
616
    if ( !IS_NULL_id ( def ) ) {
633
	if (!IS_NULL_id(def)) {
617
	CLASS_INFO ci = DEREF_cinfo ( ctype_info ( ct ) ) ;
634
		CLASS_INFO ci = DEREF_cinfo(ctype_info(ct));
618
	CLASS_USAGE cu = DEREF_cusage ( ctype_usage ( ct ) ) ;
635
		CLASS_USAGE cu = DEREF_cusage(ctype_usage(ct));
619
	GRAPH gr = DEREF_graph ( ctype_base ( ct ) ) ;
636
		GRAPH gr = DEREF_graph(ctype_base(ct));
620
	TYPE form = DEREF_type ( ctype_form ( ct ) ) ;
637
		TYPE form = DEREF_type(ctype_form(ct));
621
	save_cinfo ( bs, ci ) ;
638
		save_cinfo(bs, ci);
622
	save_cusage ( bs, cu ) ;
639
		save_cusage(bs, cu);
623
	bs = save_graph ( bs, gr, gr ) ;
640
		bs = save_graph(bs, gr, gr);
624
	if ( !IS_NULL_type ( form ) ) {
641
		if (!IS_NULL_type(form)) {
625
	    ENC_ON ( bs ) ;
642
			ENC_ON(bs);
626
	    bs = save_type ( bs, form, NULL_id ) ;
643
			bs = save_type(bs, form, NULL_id);
627
	} else {
644
		} else {
628
	    ENC_OFF ( bs ) ;
645
			ENC_OFF(bs);
629
	}
646
		}
630
    } else {
647
	} else {
631
	IDENTIFIER cid = DEREF_id ( ctype_name ( ct ) ) ;
648
		IDENTIFIER cid = DEREF_id(ctype_name(ct));
632
	bs = save_use ( bs, cid ) ;
649
		bs = save_use(bs, cid);
633
    }
650
	}
634
    return ( bs ) ;
651
	return (bs);
635
}
652
}
636
 
653
 
637
 
654
 
638
/*
655
/*
639
    WRITE AN ENUMERATION TYPE
656
    WRITE AN ENUMERATION TYPE
640
 
657
 
641
    This routine writes the enumeration type et to the bitstream bs.  If
658
    This routine writes the enumeration type et to the bitstream bs.  If
642
    def is not null then the full definition is written, otherwise just a
659
    def is not null then the full definition is written, otherwise just a
643
    use is written.
660
    use is written.
644
*/
661
*/
645
 
662
 
646
static BITSTREAM *save_etype
663
static BITSTREAM *
647
    PROTO_N ( ( bs, et, def ) )
-
 
648
    PROTO_T ( BITSTREAM *bs X ENUM_TYPE et X IDENTIFIER def )
664
save_etype(BITSTREAM *bs, ENUM_TYPE et, IDENTIFIER def)
649
{
-
 
650
    if ( !IS_NULL_id ( def ) ) {
-
 
651
	CLASS_INFO ei = DEREF_cinfo ( etype_info ( et ) ) ;
-
 
652
	TYPE t = DEREF_type ( etype_rep ( et ) ) ;
-
 
653
	TYPE form = DEREF_type ( etype_form ( et ) ) ;
-
 
654
	save_cinfo ( bs, ei ) ;
-
 
655
	bs = save_type ( bs, t, NULL_id ) ;
-
 
656
	if ( !IS_NULL_type ( form ) ) {
-
 
657
	    ENC_ON ( bs ) ;
-
 
658
	    bs = save_type ( bs, form, NULL_id ) ;
-
 
659
	} else {
-
 
660
	    ENC_OFF ( bs ) ;
-
 
661
	}
-
 
662
    } else {
-
 
663
	IDENTIFIER eid = DEREF_id ( etype_name ( et ) ) ;
-
 
664
	bs = save_use ( bs, eid ) ;
-
 
665
    }
-
 
666
    return ( bs ) ;
-
 
667
}
-
 
668
 
-
 
669
 
-
 
670
/*
-
 
671
    WRITE A TYPE
-
 
672
 
-
 
673
    This routine writes the type t to the bitstream bs.  def is passed to
-
 
674
    save_ctype and save_etype.
-
 
675
*/
-
 
676
 
-
 
677
static BITSTREAM *save_type
-
 
678
    PROTO_N ( ( bs, t, def ) )
-
 
679
    PROTO_T ( BITSTREAM *bs X TYPE t X IDENTIFIER def )
-
 
680
{
665
{
681
    CV_SPEC cv ;
-
 
682
    unsigned tag ;
-
 
683
    BUILTIN_TYPE nt = is_builtin_type ( t, 1 ) ;
-
 
684
    if ( nt != ntype_none ) {
-
 
685
	/* Built-in types */
-
 
686
	ENC_ON ( bs ) ;
-
 
687
	cv = DEREF_cv ( type_qual ( t ) ) ;
-
 
688
	save_cv ( bs, cv ) ;
-
 
689
	save_ntype ( bs, nt ) ;
-
 
690
	return ( bs ) ;
-
 
691
    }
-
 
692
    ENC_OFF ( bs ) ;
-
 
693
    if ( IS_NULL_type ( t ) ) {
666
	if (!IS_NULL_id(def)) {
694
	/* Null types */
-
 
695
	ENC_BITS ( bs, BITS_type, 0 ) ;
-
 
696
	return ( bs ) ;
-
 
697
    }
-
 
698
 
-
 
699
    /* Save type independent fields */
-
 
700
    tag = TAG_type ( t ) ;
-
 
701
    ENC_BITS ( bs, BITS_type, tag + 1 ) ;
-
 
702
    cv = DEREF_cv ( type_qual ( t ) ) ;
-
 
703
    save_cv ( bs, cv ) ;
-
 
704
 
-
 
705
    /* Save type dependent fields */
-
 
706
    ASSERT ( ORDER_type == 18 ) ;
-
 
707
    switch ( TAG_type ( t ) ) {
-
 
708
	case type_pre_tag : {
-
 
709
	    IDENTIFIER tid = DEREF_id ( type_name ( t ) ) ;
667
		CLASS_INFO ei = DEREF_cinfo(etype_info(et));
710
	    QUALIFIER qual = DEREF_qual ( type_pre_nqual ( t ) ) ;
-
 
711
	    BASE_TYPE bt = DEREF_btype ( type_pre_rep ( t ) ) ;
668
		TYPE t = DEREF_type(etype_rep(et));
712
	    bs = save_use ( bs, tid ) ;
-
 
713
	    save_qual ( bs, qual ) ;
-
 
714
	    save_btype ( bs, bt ) ;
-
 
715
	    break ;
-
 
716
	}
-
 
717
	case type_integer_tag : {
-
 
718
	    INT_TYPE it = DEREF_itype ( type_integer_rep ( t ) ) ;
-
 
719
	    INT_TYPE is = DEREF_itype ( type_integer_sem ( t ) ) ;
669
		TYPE form = DEREF_type(etype_form(et));
720
	    INT_TYPE ir = it ;
-
 
721
	    bs = save_itype ( bs, it ) ;
-
 
722
	    if ( IS_itype_promote ( ir ) ) {
-
 
723
		/* Find default semantic type for it */
-
 
724
		ir = DEREF_itype ( itype_promote_arg ( ir ) ) ;
-
 
725
	    }
-
 
726
	    if ( EQ_itype ( ir, is ) || eq_itype ( ir, is ) ) {
-
 
727
		/* Default semantics */
-
 
728
		ENC_OFF ( bs ) ;
-
 
729
	    } else {
-
 
730
		/* Non-standard semantic type */
-
 
731
		ENC_ON ( bs ) ;
-
 
732
		bs = save_itype ( bs, is ) ;
670
		save_cinfo(bs, ei);
733
	    }
-
 
734
	    break ;
-
 
735
	}
-
 
736
	case type_floating_tag : {
-
 
737
	    FLOAT_TYPE ft = DEREF_ftype ( type_floating_rep ( t ) ) ;
-
 
738
	    bs = save_ftype ( bs, ft ) ;
-
 
739
	    break ;
-
 
740
	}
-
 
741
	case type_top_tag :
-
 
742
	case type_bottom_tag : {
-
 
743
	    /* Already handled */
-
 
744
	    break ;
-
 
745
	}
-
 
746
	case type_ptr_tag :
-
 
747
	case type_ref_tag : {
-
 
748
	    TYPE s = DEREF_type ( type_ptr_etc_sub ( t ) ) ;
-
 
749
	    bs = save_type ( bs, s, NULL_id ) ;
-
 
750
	    break ;
-
 
751
	}
-
 
752
	case type_ptr_mem_tag : {
-
 
753
	    CLASS_TYPE cs = DEREF_ctype ( type_ptr_mem_of ( t ) ) ;
-
 
754
	    TYPE s = DEREF_type ( type_ptr_mem_sub ( t ) ) ;
-
 
755
	    bs = save_ctype ( bs, cs, NULL_id ) ;
-
 
756
	    bs = save_type ( bs, s, NULL_id ) ;
-
 
757
	    break ;
-
 
758
	}
-
 
759
	case type_func_tag : {
-
 
760
	    TYPE r = DEREF_type ( type_func_ret ( t ) ) ;
-
 
761
	    LIST ( IDENTIFIER ) pids = DEREF_list ( type_func_pids ( t ) ) ;
-
 
762
	    int ell = DEREF_int ( type_func_ellipsis ( t ) ) ;
-
 
763
	    LIST ( TYPE ) p = DEREF_list ( type_func_ptypes ( t ) ) ;
-
 
764
	    LIST ( TYPE ) m = DEREF_list ( type_func_mtypes ( t ) ) ;
-
 
765
	    LIST ( TYPE ) ex = DEREF_list ( type_func_except ( t ) ) ;
-
 
766
	    CV_SPEC mqual = DEREF_cv ( type_func_mqual ( t ) ) ;
-
 
767
	    bs = save_type ( bs, r, NULL_id ) ;
671
		bs = save_type(bs, t, NULL_id);
768
	    bs = save_id_list ( bs, pids, NULL_nspace ) ;
-
 
769
	    ENC_BITS ( bs, BITS_ellipsis, ell ) ;
-
 
770
	    save_mqual ( bs, mqual ) ;
-
 
771
	    if ( EQ_list ( p, m ) ) {
672
		if (!IS_NULL_type(form)) {
772
		ENC_OFF ( bs ) ;
-
 
773
	    } else {
-
 
774
		CLASS_TYPE cs ;
-
 
775
		TYPE s = DEREF_type ( HEAD_list ( m ) ) ;
-
 
776
		s = DEREF_type ( type_ref_sub ( s ) ) ;
-
 
777
		cs = DEREF_ctype ( type_compound_defn ( s ) ) ;
-
 
778
		ENC_ON ( bs ) ;
673
			ENC_ON(bs);
779
		bs = save_ctype ( bs, cs, NULL_id ) ;
674
			bs = save_type(bs, form, NULL_id);
780
	    }
-
 
781
	    if ( EQ_list ( ex, univ_type_set ) ) {
-
 
782
		ENC_OFF ( bs ) ;
-
 
783
	    } else {
675
		} else {
784
		ENC_ON ( bs ) ;
676
			ENC_OFF(bs);
785
		bs = save_type_list ( bs, ex ) ;
-
 
786
	    }
-
 
787
	    break ;
-
 
788
	}
-
 
789
	case type_array_tag : {
-
 
790
	    TYPE s = DEREF_type ( type_array_sub ( t ) ) ;
-
 
791
	    NAT m = DEREF_nat ( type_array_size ( t ) ) ;
-
 
792
	    bs = save_type ( bs, s, NULL_id ) ;
-
 
793
	    bs = save_nat ( bs, m ) ;
-
 
794
	    break ;
-
 
795
	}
-
 
796
	case type_bitfield_tag : {
-
 
797
	    INT_TYPE it = DEREF_itype ( type_bitfield_defn ( t ) ) ;
-
 
798
	    bs = save_itype ( bs, it ) ;
-
 
799
	    break ;
-
 
800
	}
-
 
801
	case type_compound_tag : {
-
 
802
	    CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
-
 
803
	    bs = save_ctype ( bs, ct, def ) ;
-
 
804
	    break ;
-
 
805
	}
-
 
806
	case type_enumerate_tag : {
-
 
807
	    ENUM_TYPE et = DEREF_etype ( type_enumerate_defn ( t ) ) ;
-
 
808
	    bs = save_etype ( bs, et, def ) ;
-
 
809
	    break ;
-
 
810
	}
-
 
811
	case type_token_tag : {
-
 
812
	    IDENTIFIER tok = DEREF_id ( type_token_tok ( t ) ) ;
-
 
813
	    LIST ( TOKEN ) args = DEREF_list ( type_token_args ( t ) ) ;
-
 
814
	    bs = save_use ( bs, tok ) ;
-
 
815
	    bs = save_tok_list ( bs, args, 1 ) ;
-
 
816
	    break ;
-
 
817
	}
677
		}
818
	case type_templ_tag : {
-
 
819
	    TOKEN tok = DEREF_tok ( type_templ_sort ( t ) ) ;
-
 
820
	    TYPE s = DEREF_type ( type_templ_defn ( t ) ) ;
-
 
821
	    int fix = DEREF_int ( type_templ_fix ( t ) ) ;
-
 
822
	    bs = save_tok ( bs, tok, 0 ) ;
-
 
823
	    bs = save_type ( bs, s, def ) ;
-
 
824
	    ENC_BOOL ( bs, fix ) ;
-
 
825
	    break ;
678
	} else {
826
	}
-
 
827
	case type_instance_tag : {
-
 
828
	    IDENTIFIER tid = DEREF_id ( type_name ( t ) ) ;
679
		IDENTIFIER eid = DEREF_id(etype_name(et));
829
	    IDENTIFIER id = DEREF_id ( type_instance_id ( t ) ) ;
-
 
830
	    DECL_SPEC acc = DEREF_dspec ( type_instance_access ( t ) ) ;
-
 
831
	    bs = save_use ( bs, tid ) ;
680
		bs = save_use(bs, eid);
832
	    bs = save_use ( bs, id ) ;
-
 
833
	    save_dspec ( bs, acc ) ;
-
 
834
	    break ;
-
 
835
	}
-
 
836
	case type_dummy_tag : {
-
 
837
	    int tok = DEREF_int ( type_dummy_tok ( t ) ) ;
-
 
838
	    ENC_INT ( bs, tok ) ;
-
 
839
	    break ;
-
 
840
	}
-
 
841
	case type_error_tag : {
-
 
842
	    break ;
-
 
843
	}
681
	}
-
 
682
	return (bs);
-
 
683
}
-
 
684
 
-
 
685
 
-
 
686
/*
-
 
687
    WRITE A TYPE
-
 
688
 
-
 
689
    This routine writes the type t to the bitstream bs.  def is passed to
-
 
690
    save_ctype and save_etype.
-
 
691
*/
-
 
692
 
-
 
693
static BITSTREAM *
-
 
694
save_type(BITSTREAM *bs, TYPE t, IDENTIFIER def)
-
 
695
{
-
 
696
	CV_SPEC cv;
-
 
697
	unsigned tag;
-
 
698
	BUILTIN_TYPE nt = is_builtin_type(t, 1);
-
 
699
	if (nt != ntype_none) {
-
 
700
		/* Built-in types */
-
 
701
		ENC_ON(bs);
-
 
702
		cv = DEREF_cv(type_qual(t));
-
 
703
		save_cv(bs, cv);
-
 
704
		save_ntype(bs, nt);
-
 
705
		return (bs);
-
 
706
	}
-
 
707
	ENC_OFF(bs);
-
 
708
	if (IS_NULL_type(t)) {
-
 
709
		/* Null types */
-
 
710
		ENC_BITS(bs, BITS_type, 0);
-
 
711
		return (bs);
-
 
712
	}
-
 
713
 
-
 
714
	/* Save type independent fields */
-
 
715
	tag = TAG_type(t);
-
 
716
	ENC_BITS(bs, BITS_type, tag + 1);
-
 
717
	cv = DEREF_cv(type_qual(t));
-
 
718
	save_cv(bs, cv);
-
 
719
 
-
 
720
	/* Save type dependent fields */
-
 
721
	ASSERT(ORDER_type == 18);
-
 
722
	switch (TAG_type(t)) {
-
 
723
	case type_pre_tag: {
-
 
724
		IDENTIFIER tid = DEREF_id(type_name(t));
-
 
725
		QUALIFIER qual = DEREF_qual(type_pre_nqual(t));
-
 
726
		BASE_TYPE bt = DEREF_btype(type_pre_rep(t));
-
 
727
		bs = save_use(bs, tid);
-
 
728
		save_qual(bs, qual);
-
 
729
		save_btype(bs, bt);
-
 
730
		break;
-
 
731
	}
-
 
732
	case type_integer_tag: {
-
 
733
		INT_TYPE it = DEREF_itype(type_integer_rep(t));
-
 
734
		INT_TYPE is = DEREF_itype(type_integer_sem(t));
-
 
735
		INT_TYPE ir = it;
-
 
736
		bs = save_itype(bs, it);
-
 
737
		if (IS_itype_promote(ir)) {
-
 
738
			/* Find default semantic type for it */
-
 
739
			ir = DEREF_itype(itype_promote_arg(ir));
-
 
740
		}
-
 
741
		if (EQ_itype(ir, is) || eq_itype(ir, is)) {
-
 
742
			/* Default semantics */
-
 
743
			ENC_OFF(bs);
-
 
744
		} else {
-
 
745
			/* Non-standard semantic type */
-
 
746
			ENC_ON(bs);
-
 
747
			bs = save_itype(bs, is);
-
 
748
		}
-
 
749
		break;
-
 
750
	}
-
 
751
	case type_floating_tag: {
-
 
752
		FLOAT_TYPE ft = DEREF_ftype(type_floating_rep(t));
-
 
753
		bs = save_ftype(bs, ft);
-
 
754
		break;
-
 
755
	}
-
 
756
	case type_top_tag:
-
 
757
	case type_bottom_tag: {
-
 
758
		/* Already handled */
-
 
759
		break;
-
 
760
	}
-
 
761
	case type_ptr_tag:
-
 
762
	case type_ref_tag: {
-
 
763
		TYPE s = DEREF_type(type_ptr_etc_sub(t));
-
 
764
		bs = save_type(bs, s, NULL_id);
-
 
765
		break;
-
 
766
	}
-
 
767
	case type_ptr_mem_tag: {
-
 
768
		CLASS_TYPE cs = DEREF_ctype(type_ptr_mem_of(t));
-
 
769
		TYPE s = DEREF_type(type_ptr_mem_sub(t));
-
 
770
		bs = save_ctype(bs, cs, NULL_id);
-
 
771
		bs = save_type(bs, s, NULL_id);
-
 
772
		break;
-
 
773
	}
-
 
774
	case type_func_tag: {
-
 
775
		TYPE r = DEREF_type(type_func_ret(t));
-
 
776
		LIST(IDENTIFIER)pids = DEREF_list(type_func_pids(t));
-
 
777
		int ell = DEREF_int(type_func_ellipsis(t));
-
 
778
		LIST(TYPE)p = DEREF_list(type_func_ptypes(t));
-
 
779
		LIST(TYPE)m = DEREF_list(type_func_mtypes(t));
-
 
780
		LIST(TYPE)ex = DEREF_list(type_func_except(t));
-
 
781
		CV_SPEC mqual = DEREF_cv(type_func_mqual(t));
-
 
782
		bs = save_type(bs, r, NULL_id);
-
 
783
		bs = save_id_list(bs, pids, NULL_nspace);
-
 
784
		ENC_BITS(bs, BITS_ellipsis, ell);
-
 
785
		save_mqual(bs, mqual);
-
 
786
		if (EQ_list(p, m)) {
-
 
787
			ENC_OFF(bs);
-
 
788
		} else {
-
 
789
			CLASS_TYPE cs;
-
 
790
			TYPE s = DEREF_type(HEAD_list(m));
-
 
791
			s = DEREF_type(type_ref_sub(s));
-
 
792
			cs = DEREF_ctype(type_compound_defn(s));
-
 
793
			ENC_ON(bs);
-
 
794
			bs = save_ctype(bs, cs, NULL_id);
-
 
795
		}
-
 
796
		if (EQ_list(ex, univ_type_set)) {
-
 
797
			ENC_OFF(bs);
-
 
798
		} else {
-
 
799
			ENC_ON(bs);
-
 
800
			bs = save_type_list(bs, ex);
844
    }
801
		}
-
 
802
		break;
-
 
803
	}
-
 
804
	case type_array_tag: {
-
 
805
		TYPE s = DEREF_type(type_array_sub(t));
-
 
806
		NAT m = DEREF_nat(type_array_size(t));
-
 
807
		bs = save_type(bs, s, NULL_id);
-
 
808
		bs = save_nat(bs, m);
-
 
809
		break;
-
 
810
	}
-
 
811
	case type_bitfield_tag: {
-
 
812
		INT_TYPE it = DEREF_itype(type_bitfield_defn(t));
-
 
813
		bs = save_itype(bs, it);
-
 
814
		break;
-
 
815
	}
-
 
816
	case type_compound_tag: {
-
 
817
		CLASS_TYPE ct = DEREF_ctype(type_compound_defn(t));
-
 
818
		bs = save_ctype(bs, ct, def);
-
 
819
		break;
-
 
820
	}
-
 
821
	case type_enumerate_tag: {
-
 
822
		ENUM_TYPE et = DEREF_etype(type_enumerate_defn(t));
-
 
823
		bs = save_etype(bs, et, def);
-
 
824
		break;
-
 
825
	}
-
 
826
	case type_token_tag: {
-
 
827
		IDENTIFIER tok = DEREF_id(type_token_tok(t));
-
 
828
		LIST(TOKEN)args = DEREF_list(type_token_args(t));
-
 
829
		bs = save_use(bs, tok);
-
 
830
		bs = save_tok_list(bs, args, 1);
-
 
831
		break;
-
 
832
	}
-
 
833
	case type_templ_tag: {
-
 
834
		TOKEN tok = DEREF_tok(type_templ_sort(t));
-
 
835
		TYPE s = DEREF_type(type_templ_defn(t));
-
 
836
		int fix = DEREF_int(type_templ_fix(t));
-
 
837
		bs = save_tok(bs, tok, 0);
-
 
838
		bs = save_type(bs, s, def);
-
 
839
		ENC_BOOL(bs, fix);
-
 
840
		break;
-
 
841
	}
-
 
842
	case type_instance_tag: {
-
 
843
		IDENTIFIER tid = DEREF_id(type_name(t));
-
 
844
		IDENTIFIER id = DEREF_id(type_instance_id(t));
-
 
845
		DECL_SPEC acc = DEREF_dspec(type_instance_access(t));
-
 
846
		bs = save_use(bs, tid);
-
 
847
		bs = save_use(bs, id);
-
 
848
		save_dspec(bs, acc);
-
 
849
		break;
-
 
850
	}
-
 
851
	case type_dummy_tag: {
-
 
852
		int tok = DEREF_int(type_dummy_tok(t));
-
 
853
		ENC_INT(bs, tok);
-
 
854
		break;
-
 
855
	}
-
 
856
	case type_error_tag: {
-
 
857
		break;
-
 
858
	}
-
 
859
	}
845
    return ( bs ) ;
860
	return (bs);
846
}
861
}
847
 
862
 
848
 
863
 
849
/*
864
/*
850
    WRITE A LIST OF TYPES
865
    WRITE A LIST OF TYPES
851
 
866
 
852
    This routine saves a list of types to the bitstream bs.
867
    This routine saves a list of types to the bitstream bs.
853
*/
868
*/
854
 
869
 
855
static BITSTREAM *save_type_list
870
static BITSTREAM *
856
    PROTO_N ( ( bs, p ) )
-
 
857
    PROTO_T ( BITSTREAM *bs X LIST ( TYPE ) p )
871
save_type_list(BITSTREAM *bs, LIST(TYPE)p)
858
{
872
{
859
    while ( !IS_NULL_list ( p ) ) {
873
	while (!IS_NULL_list(p)) {
860
	TYPE t = DEREF_type ( HEAD_list ( p ) ) ;
874
		TYPE t = DEREF_type(HEAD_list(p));
861
	ENC_ON ( bs ) ;
875
		ENC_ON(bs);
862
	bs = save_type ( bs, t, NULL_id ) ;
876
		bs = save_type(bs, t, NULL_id);
863
	p = TAIL_list ( p ) ;
877
		p = TAIL_list(p);
864
    }
878
	}
865
    ENC_OFF ( bs ) ;
879
	ENC_OFF(bs);
866
    return ( bs ) ;
880
	return (bs);
867
}
881
}
868
 
882
 
869
 
883
 
870
/*
884
/*
871
    WRITE A TOKEN
885
    WRITE A TOKEN
872
 
886
 
873
    This routine writes the token tok to the bitstream bs.  If def is
887
    This routine writes the token tok to the bitstream bs.  If def is
874
    true then the token value is included.
888
    true then the token value is included.
875
*/
889
*/
876
 
890
 
877
static BITSTREAM *save_tok
891
static BITSTREAM *
878
    PROTO_N ( ( bs, tok, def ) )
-
 
879
    PROTO_T ( BITSTREAM *bs X TOKEN tok X int def )
892
save_tok(BITSTREAM *bs, TOKEN tok, int def)
880
{
893
{
881
    unsigned tag ;
894
	unsigned tag;
882
    if ( IS_NULL_tok ( tok ) ) {
895
	if (IS_NULL_tok(tok)) {
883
	ENC_BITS ( bs, BITS_tok, 0 ) ;
896
		ENC_BITS(bs, BITS_tok, 0);
884
	return ( bs ) ;
897
		return (bs);
885
    }
-
 
886
    tag = TAG_tok ( tok ) ;
-
 
887
    ENC_BITS ( bs, BITS_tok, tag + 1 ) ;
-
 
888
    ASSERT ( ORDER_tok == 10 ) ;
-
 
889
    switch ( tag ) {
-
 
890
	case tok_exp_tag : {
-
 
891
	    TYPE t = DEREF_type ( tok_exp_type ( tok ) ) ;
-
 
892
	    int c = DEREF_int ( tok_exp_constant ( tok ) ) ;
-
 
893
	    bs = save_type ( bs, t, NULL_id ) ;
-
 
894
	    ENC_BOOL ( bs, c ) ;
-
 
895
	    if ( def ) {
-
 
896
		EXP e = DEREF_exp ( tok_exp_value ( tok ) ) ;
-
 
897
		bs = save_exp ( bs, e, t ) ;
-
 
898
	    }
-
 
899
	    break ;
-
 
900
	}
-
 
901
	case tok_stmt_tag : {
-
 
902
	    if ( def ) {
-
 
903
		EXP e = DEREF_exp ( tok_stmt_value ( tok ) ) ;
-
 
904
		bs = save_exp ( bs, e, type_void ) ;
-
 
905
	    }
-
 
906
	    break ;
-
 
907
	}
-
 
908
	case tok_nat_tag :
-
 
909
	case tok_snat_tag : {
-
 
910
	    if ( def ) {
-
 
911
		NAT m = DEREF_nat ( tok_nat_etc_value ( tok ) ) ;
-
 
912
		bs = save_nat ( bs, m ) ;
-
 
913
	    }
-
 
914
	    break ;
-
 
915
	}
898
	}
-
 
899
	tag = TAG_tok(tok);
-
 
900
	ENC_BITS(bs, BITS_tok, tag + 1);
-
 
901
	ASSERT(ORDER_tok == 10);
-
 
902
	switch (tag) {
-
 
903
	case tok_exp_tag: {
-
 
904
		TYPE t = DEREF_type(tok_exp_type(tok));
-
 
905
		int c = DEREF_int(tok_exp_constant(tok));
-
 
906
		bs = save_type(bs, t, NULL_id);
-
 
907
		ENC_BOOL(bs, c);
-
 
908
		if (def) {
-
 
909
			EXP e = DEREF_exp(tok_exp_value(tok));
-
 
910
			bs = save_exp(bs, e, t);
-
 
911
		}
-
 
912
		break;
-
 
913
	}
-
 
914
	case tok_stmt_tag: {
-
 
915
		if (def) {
-
 
916
			EXP e = DEREF_exp(tok_stmt_value(tok));
-
 
917
			bs = save_exp(bs, e, type_void);
-
 
918
		}
-
 
919
		break;
-
 
920
	}
-
 
921
	case tok_nat_tag:
-
 
922
	case tok_snat_tag: {
-
 
923
		if (def) {
-
 
924
			NAT m = DEREF_nat(tok_nat_etc_value(tok));
-
 
925
			bs = save_nat(bs, m);
-
 
926
		}
-
 
927
		break;
-
 
928
	}
916
	case tok_type_tag : {
929
	case tok_type_tag: {
917
	    BASE_TYPE kind = DEREF_btype ( tok_type_kind ( tok ) ) ;
930
		BASE_TYPE kind = DEREF_btype(tok_type_kind(tok));
918
	    TYPE s = DEREF_type ( tok_type_alt ( tok ) ) ;
931
		TYPE s = DEREF_type(tok_type_alt(tok));
919
	    save_btype ( bs, kind ) ;
932
		save_btype(bs, kind);
920
	    bs = save_type ( bs, s, NULL_id ) ;
933
		bs = save_type(bs, s, NULL_id);
921
	    if ( def ) {
934
		if (def) {
922
		TYPE t = DEREF_type ( tok_type_value ( tok ) ) ;
935
			TYPE t = DEREF_type(tok_type_value(tok));
923
		bs = save_type ( bs, t, NULL_id ) ;
936
			bs = save_type(bs, t, NULL_id);
924
	    }
937
		}
925
	    break ;
938
		break;
926
	}
939
	}
927
	case tok_func_tag : {
940
	case tok_func_tag: {
928
	    TYPE t = DEREF_type ( tok_func_type ( tok ) ) ;
941
		TYPE t = DEREF_type(tok_func_type(tok));
929
	    TOKEN proc = DEREF_tok ( tok_func_proc ( tok ) ) ;
942
		TOKEN proc = DEREF_tok(tok_func_proc(tok));
930
	    bs = save_type ( bs, t, NULL_id ) ;
943
		bs = save_type(bs, t, NULL_id);
931
	    bs = save_tok ( bs, proc, 0 ) ;
944
		bs = save_tok(bs, proc, 0);
932
	    if ( def ) {
945
		if (def) {
933
		IDENTIFIER id = DEREF_id ( tok_func_defn ( tok ) ) ;
946
			IDENTIFIER id = DEREF_id(tok_func_defn(tok));
-
 
947
			bs = save_use(bs, id);
-
 
948
		}
-
 
949
		break;
-
 
950
	}
-
 
951
	case tok_member_tag: {
-
 
952
		TYPE s = DEREF_type(tok_member_of(tok));
-
 
953
		TYPE t = DEREF_type(tok_member_type(tok));
-
 
954
		bs = save_type(bs, s, NULL_id);
-
 
955
		bs = save_type(bs, t, NULL_id);
-
 
956
		if (def) {
-
 
957
			OFFSET off = DEREF_off(tok_member_value(tok));
-
 
958
			bs = save_off(bs, off);
-
 
959
		}
-
 
960
		break;
-
 
961
	}
-
 
962
	case tok_class_tag: {
-
 
963
		TYPE t = DEREF_type(tok_class_type(tok));
-
 
964
		TYPE s = DEREF_type(tok_class_alt(tok));
-
 
965
		bs = save_type(bs, t, NULL_id);
-
 
966
		bs = save_type(bs, s, NULL_id);
-
 
967
		if (def) {
-
 
968
			IDENTIFIER id = DEREF_id(tok_class_value(tok));
934
		bs = save_use ( bs, id ) ;
969
			bs = save_use(bs, id);
935
	    }
970
		}
936
	    break ;
971
		break;
937
	}
972
	}
938
	case tok_member_tag : {
973
	case tok_proc_tag: {
-
 
974
		LIST(IDENTIFIER)bids;
-
 
975
		LIST(IDENTIFIER)pids;
939
	    TYPE s = DEREF_type ( tok_member_of ( tok ) ) ;
976
		int key = DEREF_int(tok_proc_key(tok));
940
	    TYPE t = DEREF_type ( tok_member_type ( tok ) ) ;
977
		TOKEN res = DEREF_tok(tok_proc_res(tok));
-
 
978
		bids = DEREF_list(tok_proc_bids(tok));
941
	    bs = save_type ( bs, s, NULL_id ) ;
979
		pids = DEREF_list(tok_proc_pids(tok));
942
	    bs = save_type ( bs, t, NULL_id ) ;
980
		bs = save_id_list(bs, bids, NULL_nspace);
-
 
981
		if (EQ_list(pids, bids)) {
-
 
982
			ENC_ON(bs);
943
	    if ( def ) {
983
		} else {
-
 
984
			ENC_OFF(bs);
944
		OFFSET off = DEREF_off ( tok_member_value ( tok ) ) ;
985
			bs = save_use_list(bs, pids);
-
 
986
		}
945
		bs = save_off ( bs, off ) ;
987
		bs = save_tok(bs, res, def);
-
 
988
		if (key == lex_identifier) {
-
 
989
			ENC_OFF(bs);
-
 
990
		} else {
-
 
991
			ENC_ON(bs);
-
 
992
			save_lex(bs, key);
946
	    }
993
		}
947
	    break ;
994
		break;
948
	}
995
	}
949
	case tok_class_tag : {
996
	case tok_templ_tag: {
950
	    TYPE t = DEREF_type ( tok_class_type ( tok ) ) ;
997
		DECL_SPEC ex = DEREF_dspec(tok_templ_usage(tok));
951
	    TYPE s = DEREF_type ( tok_class_alt ( tok ) ) ;
998
		NAMESPACE pns = DEREF_nspace(tok_templ_pars(tok));
952
	    bs = save_type ( bs, t, NULL_id ) ;
-
 
953
	    bs = save_type ( bs, s, NULL_id ) ;
-
 
954
	    if ( def ) {
-
 
955
		IDENTIFIER id = DEREF_id ( tok_class_value ( tok ) ) ;
-
 
956
		bs = save_use ( bs, id ) ;
999
		save_dspec(bs, ex);
957
	    }
-
 
958
	    break ;
-
 
959
	}
-
 
960
	case tok_proc_tag : {
1000
		if (!IS_NULL_nspace(pns)) {
961
	    LIST ( IDENTIFIER ) bids ;
1001
			LIST(TOKEN)dargs;
962
	    LIST ( IDENTIFIER ) pids ;
1002
			LIST(IDENTIFIER)pids;
963
	    int key = DEREF_int ( tok_proc_key ( tok ) ) ;
-
 
964
	    TOKEN res = DEREF_tok ( tok_proc_res ( tok ) ) ;
-
 
965
	    bids = DEREF_list ( tok_proc_bids ( tok ) ) ;
1003
			pids = DEREF_list(tok_templ_pids(tok));
966
	    pids = DEREF_list ( tok_proc_pids ( tok ) ) ;
1004
			dargs = DEREF_list(tok_templ_dargs(tok));
967
	    bs = save_id_list ( bs, bids, NULL_nspace ) ;
-
 
968
	    if ( EQ_list ( pids, bids ) ) {
-
 
969
		ENC_ON ( bs ) ;
1005
			ENC_ON(bs);
970
	    } else {
-
 
971
		ENC_OFF ( bs ) ;
-
 
972
		bs = save_use_list ( bs, pids ) ;
1006
			bs = save_id_list(bs, pids, NULL_nspace);
973
	    }
-
 
974
	    bs = save_tok ( bs, res, def ) ;
1007
			bs = save_tok_list(bs, dargs, 1);
975
	    if ( key == lex_identifier ) {
-
 
976
		ENC_OFF ( bs ) ;
-
 
977
	    } else {
1008
		} else {
978
		ENC_ON ( bs ) ;
1009
			ENC_OFF(bs);
979
		save_lex ( bs, key ) ;
-
 
980
	    }
1010
		}
981
	    break ;
1011
		break;
982
	}
1012
	}
983
	case tok_templ_tag : {
-
 
984
	    DECL_SPEC ex = DEREF_dspec ( tok_templ_usage ( tok ) ) ;
-
 
985
	    NAMESPACE pns = DEREF_nspace ( tok_templ_pars ( tok ) ) ;
-
 
986
	    save_dspec ( bs, ex ) ;
-
 
987
	    if ( !IS_NULL_nspace ( pns ) ) {
-
 
988
		LIST ( TOKEN ) dargs ;
-
 
989
		LIST ( IDENTIFIER ) pids ;
-
 
990
		pids = DEREF_list ( tok_templ_pids ( tok ) ) ;
-
 
991
		dargs = DEREF_list ( tok_templ_dargs ( tok ) ) ;
-
 
992
		ENC_ON ( bs ) ;
-
 
993
		bs = save_id_list ( bs, pids, NULL_nspace ) ;
-
 
994
		bs = save_tok_list ( bs, dargs, 1 ) ;
-
 
995
	    } else {
-
 
996
		ENC_OFF ( bs ) ;
-
 
997
	    }
-
 
998
	    break ;
-
 
999
	}
1013
	}
1000
    }
-
 
1001
    return ( bs ) ;
1014
	return (bs);
1002
}
1015
}
1003
 
1016
 
1004
 
1017
 
1005
/*
1018
/*
1006
    STANDARD BITSTREAM
1019
    STANDARD BITSTREAM
1007
 
1020
 
1008
    This bitstream is used to write the spec output file.
1021
    This bitstream is used to write the spec output file.
1009
*/
1022
*/
1010
 
1023
 
1011
BITSTREAM *spec_unit = NULL ;
1024
BITSTREAM *spec_unit = NULL;
1012
static int written_spec = 0 ;
1025
static int written_spec = 0;
1013
int output_spec = 0 ;
1026
int output_spec = 0;
1014
 
1027
 
1015
 
1028
 
1016
/*
1029
/*
1017
    WRITE AN IDENTIFIER SPEC
1030
    WRITE AN IDENTIFIER SPEC
1018
 
1031
 
1019
    This routine writes the spec of the identifier id from the namespace ns
1032
    This routine writes the spec of the identifier id from the namespace ns
1020
    to the bitstream bs.
1033
    to the bitstream bs.
1021
*/
1034
*/
1022
 
1035
 
1023
BITSTREAM *save_id
1036
BITSTREAM *
1024
    PROTO_N ( ( bs, id, ns ) )
-
 
1025
    PROTO_T ( BITSTREAM *bs X IDENTIFIER id X NAMESPACE ns )
1037
save_id(BITSTREAM *bs, IDENTIFIER id, NAMESPACE ns)
1026
{
1038
{
1027
    if ( bs && output_spec ) {
1039
	if (bs && output_spec) {
1028
	bs = save_use ( bs, id ) ;
1040
		bs = save_use(bs, id);
1029
	if ( !IS_NULL_id ( id ) ) {
1041
		if (!IS_NULL_id(id)) {
1030
	    /* Save identifier independent fields */
1042
			/* Save identifier independent fields */
1031
	    unsigned tag = TAG_id ( id ) ;
1043
			unsigned tag = TAG_id(id);
1032
	    HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
1044
			HASHID nm = DEREF_hashid(id_name(id));
1033
	    DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
1045
			DECL_SPEC ds = DEREF_dspec(id_storage(id));
1034
	    IDENTIFIER lid = DEREF_id ( id_alias ( id ) ) ;
1046
			IDENTIFIER lid = DEREF_id(id_alias(id));
1035
	    ENC_BITS ( bs, BITS_id, tag + 1 ) ;
1047
			ENC_BITS(bs, BITS_id, tag + 1);
1036
	    bs = save_hashid ( bs, nm, ns ) ;
1048
			bs = save_hashid(bs, nm, ns);
1037
	    save_dspec ( bs, ds ) ;
1049
			save_dspec(bs, ds);
1038
	    bs = save_loc ( bs, id_loc ( id ) ) ;
1050
			bs = save_loc(bs, id_loc(id));
1039
	    if ( EQ_id ( id, lid ) ) {
1051
			if (EQ_id(id, lid)) {
1040
		ENC_OFF ( bs ) ;
1052
				ENC_OFF(bs);
1041
	    } else {
1053
			} else {
1042
		ENC_ON ( bs ) ;
1054
				ENC_ON(bs);
1043
		bs = save_use ( bs, lid ) ;
1055
				bs = save_use(bs, lid);
1044
	    }
1056
			}
1045
 
1057
 
1046
	    /* Save identifier dependent fields */
1058
			/* Save identifier dependent fields */
1047
	    ASSERT ( ORDER_id == 29 ) ;
1059
			ASSERT(ORDER_id == 29);
1048
	    switch ( tag ) {
1060
			switch (tag) {
1049
		case id_dummy_tag : {
1061
			case id_dummy_tag: {
1050
		    break ;
1062
				break;
1051
		}
1063
			}
1052
		case id_keyword_tag :
1064
			case id_keyword_tag:
1053
		case id_iso_keyword_tag :
1065
			case id_iso_keyword_tag:
1054
		case id_reserved_tag : {
1066
			case id_reserved_tag: {
1055
		    int key = ( int ) DEREF_ulong ( id_no ( id ) ) ;
1067
				int key = (int)DEREF_ulong(id_no(id));
1056
		    save_lex ( bs, key ) ;
1068
				save_lex(bs, key);
1057
		    break ;
1069
				break;
1058
		}
1070
			}
1059
		case id_builtin_tag : {
1071
			case id_builtin_tag: {
1060
		    LIST ( TYPE ) p ;
1072
				LIST(TYPE)p;
1061
		    TYPE r = DEREF_type ( id_builtin_ret ( id ) ) ;
1073
				TYPE r = DEREF_type(id_builtin_ret(id));
1062
		    p = DEREF_list ( id_builtin_ptypes ( id ) ) ;
1074
				p = DEREF_list(id_builtin_ptypes(id));
1063
		    bs = save_type ( bs, r, NULL_id ) ;
1075
				bs = save_type(bs, r, NULL_id);
1064
		    bs = save_type_list ( bs, p ) ;
1076
				bs = save_type_list(bs, p);
1065
		    break ;
1077
				break;
1066
		}
1078
			}
1067
		case id_obj_macro_tag : {
1079
			case id_obj_macro_tag: {
1068
		    PPTOKEN *def ;
1080
				PPTOKEN *def;
1069
		    def = DEREF_pptok ( id_obj_macro_defn ( id ) ) ;
1081
				def = DEREF_pptok(id_obj_macro_defn(id));
1070
		    bs = save_pptoks ( bs, def ) ;
1082
				bs = save_pptoks(bs, def);
1071
		    break ;
1083
				break;
1072
		}
1084
			}
1073
		case id_func_macro_tag : {
1085
			case id_func_macro_tag: {
1074
		    PPTOKEN *def ;
1086
				PPTOKEN *def;
1075
		    LIST ( HASHID ) pars ;
1087
				LIST(HASHID)pars;
1076
		    def = DEREF_pptok ( id_func_macro_defn ( id ) ) ;
1088
				def = DEREF_pptok(id_func_macro_defn(id));
1077
		    pars = DEREF_list ( id_func_macro_params ( id ) ) ;
1089
				pars = DEREF_list(id_func_macro_params(id));
1078
		    bs = save_hashid_list ( bs, pars, NULL_nspace ) ;
1090
				bs = save_hashid_list(bs, pars, NULL_nspace);
1079
		    bs = save_pptoks ( bs, def ) ;
1091
				bs = save_pptoks(bs, def);
-
 
1092
				break;
-
 
1093
			}
-
 
1094
			case id_predicate_tag: {
-
 
1095
				/* NOT YET IMPLEMENTED */
-
 
1096
				break;
-
 
1097
			}
-
 
1098
			case id_class_name_tag:
-
 
1099
			case id_enum_name_tag: {
-
 
1100
				TYPE t = DEREF_type(id_class_name_etc_defn(id));
-
 
1101
				if (!(ds & dspec_implicit)) {
-
 
1102
					bs = save_type(bs, t, id);
-
 
1103
				}
-
 
1104
				break;
-
 
1105
			}
-
 
1106
			case id_class_alias_tag:
-
 
1107
			case id_enum_alias_tag:
-
 
1108
			case id_type_alias_tag: {
-
 
1109
				TYPE t = DEREF_type(id_class_name_etc_defn(id));
-
 
1110
				bs = save_type(bs, t, NULL_id);
-
 
1111
				break;
-
 
1112
			}
-
 
1113
			case id_nspace_name_tag: {
-
 
1114
				break;
-
 
1115
			}
-
 
1116
			case id_nspace_alias_tag: {
-
 
1117
				NAMESPACE pns;
-
 
1118
				IDENTIFIER pid;
-
 
1119
				pns = DEREF_nspace(id_nspace_alias_defn(id));
-
 
1120
				pid = DEREF_id(nspace_name(pns));
-
 
1121
				bs = save_use(bs, pid);
-
 
1122
				break;
-
 
1123
			}
-
 
1124
			case id_variable_tag:
-
 
1125
			case id_parameter_tag:
-
 
1126
			case id_stat_member_tag: {
-
 
1127
				TYPE t = DEREF_type(id_variable_etc_type(id));
-
 
1128
				bs = save_type(bs, t, NULL_id);
-
 
1129
				/* NOT YET IMPLEMENTED */
-
 
1130
				break;
-
 
1131
			}
-
 
1132
			case id_function_tag:
-
 
1133
			case id_mem_func_tag:
-
 
1134
			case id_stat_mem_func_tag: {
-
 
1135
				TYPE t = DEREF_type(id_function_etc_type(id));
-
 
1136
				TYPE form = DEREF_type(id_function_etc_form(id));
-
 
1137
				bs = save_type(bs, t, NULL_id);
-
 
1138
				if (!IS_NULL_type(form)) {
-
 
1139
					ENC_ON(bs);
-
 
1140
					bs = save_type(bs, form, NULL_id);
-
 
1141
				} else {
-
 
1142
					ENC_OFF(bs);
-
 
1143
				}
-
 
1144
				/* NOT YET IMPLEMENTED */
-
 
1145
				break;
-
 
1146
			}
-
 
1147
			case id_member_tag: {
-
 
1148
				TYPE t = DEREF_type(id_member_type(id));
-
 
1149
				bs = save_type(bs, t, NULL_id);
-
 
1150
				/* NOT YET IMPLEMENTED */
-
 
1151
				break;
-
 
1152
			}
-
 
1153
			case id_enumerator_tag: {
-
 
1154
				EXP e;
-
 
1155
				TYPE t;
-
 
1156
				t = DEREF_type(id_enumerator_etype(id));
-
 
1157
				e = DEREF_exp(id_enumerator_value(id));
-
 
1158
				bs = save_type(bs, t, NULL_id);
-
 
1159
				bs = save_exp(bs, e, t);
-
 
1160
				break;
-
 
1161
			}
-
 
1162
			case id_label_tag:
-
 
1163
			case id_weak_param_tag: {
-
 
1164
				/* NOT YET IMPLEMENTED */
-
 
1165
				break;
-
 
1166
			}
-
 
1167
			case id_token_tag: {
-
 
1168
				TOKEN tok = DEREF_tok(id_token_sort(id));
-
 
1169
				bs = save_tok(bs, tok, 0);
-
 
1170
				break;
-
 
1171
			}
-
 
1172
			case id_ambig_tag: {
-
 
1173
				LIST(IDENTIFIER)ids;
-
 
1174
				int over = DEREF_int(id_ambig_over(id));
-
 
1175
				ids = DEREF_list(id_ambig_ids(id));
-
 
1176
				bs = save_use_list(bs, ids);
-
 
1177
				ENC_BOOL(bs, over);
-
 
1178
				break;
-
 
1179
			}
-
 
1180
			case id_undef_tag: {
-
 
1181
				TYPE form = DEREF_type(id_undef_form(id));
-
 
1182
				if (!IS_NULL_type(form)) {
-
 
1183
					ENC_ON(bs);
-
 
1184
					bs = save_type(bs, form, NULL_id);
-
 
1185
				} else {
-
 
1186
					ENC_OFF(bs);
-
 
1187
				}
-
 
1188
				break;
-
 
1189
			}
-
 
1190
			case id_pending_tag: {
-
 
1191
				/* This shouldn't happen */
1080
		    break ;
1192
				break;
-
 
1193
			}
-
 
1194
			}
1081
		}
1195
		}
1082
		case id_predicate_tag : {
-
 
1083
		    /* NOT YET IMPLEMENTED */
-
 
1084
		    break ;
-
 
1085
		}
-
 
1086
		case id_class_name_tag :
-
 
1087
		case id_enum_name_tag : {
-
 
1088
		    TYPE t = DEREF_type ( id_class_name_etc_defn ( id ) ) ;
-
 
1089
		    if ( !( ds & dspec_implicit ) ) {
-
 
1090
			bs = save_type ( bs, t, id ) ;
-
 
1091
		    }
-
 
1092
		    break ;
-
 
1093
		}
-
 
1094
		case id_class_alias_tag :
-
 
1095
		case id_enum_alias_tag :
-
 
1096
		case id_type_alias_tag : {
-
 
1097
		    TYPE t = DEREF_type ( id_class_name_etc_defn ( id ) ) ;
-
 
1098
		    bs = save_type ( bs, t, NULL_id ) ;
-
 
1099
		    break ;
-
 
1100
		}
-
 
1101
		case id_nspace_name_tag : {
-
 
1102
		    break ;
-
 
1103
		}
-
 
1104
		case id_nspace_alias_tag : {
-
 
1105
		    NAMESPACE pns ;
-
 
1106
		    IDENTIFIER pid ;
-
 
1107
		    pns = DEREF_nspace ( id_nspace_alias_defn ( id ) ) ;
-
 
1108
		    pid = DEREF_id ( nspace_name ( pns ) ) ;
-
 
1109
		    bs = save_use ( bs, pid ) ;
-
 
1110
		    break ;
-
 
1111
		}
-
 
1112
		case id_variable_tag :
-
 
1113
		case id_parameter_tag :
-
 
1114
		case id_stat_member_tag : {
-
 
1115
		    TYPE t = DEREF_type ( id_variable_etc_type ( id ) ) ;
-
 
1116
		    bs = save_type ( bs, t, NULL_id ) ;
-
 
1117
		    /* NOT YET IMPLEMENTED */
-
 
1118
		    break ;
-
 
1119
		}
-
 
1120
		case id_function_tag :
-
 
1121
		case id_mem_func_tag :
-
 
1122
		case id_stat_mem_func_tag : {
-
 
1123
		    TYPE t = DEREF_type ( id_function_etc_type ( id ) ) ;
-
 
1124
		    TYPE form = DEREF_type ( id_function_etc_form ( id ) ) ;
-
 
1125
		    bs = save_type ( bs, t, NULL_id ) ;
-
 
1126
		    if ( !IS_NULL_type ( form ) ) {
-
 
1127
			ENC_ON ( bs ) ;
-
 
1128
			bs = save_type ( bs, form, NULL_id ) ;
-
 
1129
		    } else {
-
 
1130
			ENC_OFF ( bs ) ;
-
 
1131
		    }
-
 
1132
		    /* NOT YET IMPLEMENTED */
-
 
1133
		    break ;
-
 
1134
		}
-
 
1135
		case id_member_tag : {
-
 
1136
		    TYPE t = DEREF_type ( id_member_type ( id ) ) ;
-
 
1137
		    bs = save_type ( bs, t, NULL_id ) ;
-
 
1138
		    /* NOT YET IMPLEMENTED */
-
 
1139
		    break ;
-
 
1140
		}
-
 
1141
		case id_enumerator_tag : {
-
 
1142
		    EXP e ;
-
 
1143
		    TYPE t ;
-
 
1144
		    t = DEREF_type ( id_enumerator_etype ( id ) ) ;
-
 
1145
		    e = DEREF_exp ( id_enumerator_value ( id ) ) ;
-
 
1146
		    bs = save_type ( bs, t, NULL_id ) ;
-
 
1147
		    bs = save_exp ( bs, e, t ) ;
-
 
1148
		    break ;
-
 
1149
		}
-
 
1150
		case id_label_tag :
-
 
1151
		case id_weak_param_tag : {
-
 
1152
		    /* NOT YET IMPLEMENTED */
-
 
1153
		    break ;
-
 
1154
		}
-
 
1155
		case id_token_tag : {
-
 
1156
		    TOKEN tok = DEREF_tok ( id_token_sort ( id ) ) ;
-
 
1157
		    bs = save_tok ( bs, tok, 0 ) ;
-
 
1158
		    break ;
-
 
1159
		}
-
 
1160
		case id_ambig_tag : {
-
 
1161
		    LIST ( IDENTIFIER ) ids ;
-
 
1162
		    int over = DEREF_int ( id_ambig_over ( id ) ) ;
-
 
1163
		    ids = DEREF_list ( id_ambig_ids ( id ) ) ;
-
 
1164
		    bs = save_use_list ( bs, ids ) ;
-
 
1165
		    ENC_BOOL ( bs, over ) ;
-
 
1166
		    break ;
-
 
1167
		}
-
 
1168
		case id_undef_tag : {
-
 
1169
		    TYPE form = DEREF_type ( id_undef_form ( id ) ) ;
-
 
1170
		    if ( !IS_NULL_type ( form ) ) {
-
 
1171
			ENC_ON ( bs ) ;
-
 
1172
			bs = save_type ( bs, form, NULL_id ) ;
-
 
1173
		    } else {
-
 
1174
			ENC_OFF ( bs ) ;
-
 
1175
		    }
-
 
1176
		    break ;
-
 
1177
		}
-
 
1178
		case id_pending_tag : {
-
 
1179
		    /* This shouldn't happen */
-
 
1180
		    break ;
-
 
1181
		}
-
 
1182
	    }
-
 
1183
	}
1196
	}
1184
    }
-
 
1185
    return ( bs ) ;
1197
	return (bs);
1186
}
1198
}
1187
 
1199
 
1188
 
1200
 
1189
/*
1201
/*
1190
    WRITE THE END OF A NAMESPACE
1202
    WRITE THE END OF A NAMESPACE
1191
 
1203
 
1192
    This routine marks the end of the namespace ns by writing the null
1204
    This routine marks the end of the namespace ns by writing the null
1193
    identifier to the bitstream bs.
1205
    identifier to the bitstream bs.
1194
*/
1206
*/
1195
 
1207
 
1196
BITSTREAM *save_end
1208
BITSTREAM *
1197
    PROTO_N ( ( bs, ns ) )
-
 
1198
    PROTO_T ( BITSTREAM *bs X NAMESPACE ns )
1209
save_end(BITSTREAM *bs, NAMESPACE ns)
1199
{
1210
{
1200
    bs = save_id ( bs, NULL_id, ns ) ;
1211
	bs = save_id(bs, NULL_id, ns);
1201
    return ( bs ) ;
1212
	return (bs);
1202
}
1213
}
1203
 
1214
 
1204
 
1215
 
1205
/*
1216
/*
1206
    WRITE A SPEC FILE
1217
    WRITE A SPEC FILE
1207
 
1218
 
1208
    This routine begins the writing of a spec file to the second output
1219
    This routine begins the writing of a spec file to the second output
1209
    file.
1220
    file.
1210
*/
1221
*/
1211
 
1222
 
1212
void begin_spec
1223
void
1213
    PROTO_Z ()
1224
begin_spec(void)
1214
{
1225
{
1215
    string nm = output_name [ OUTPUT_SPEC ] ;
1226
	string nm = output_name[OUTPUT_SPEC];
1216
    if ( nm && !written_spec ) {
1227
	if (nm && !written_spec) {
1217
	/* Open output file */
1228
		/* Open output file */
1218
	FILE *f ;
1229
		FILE *f;
1219
	BITSTREAM *bs ;
1230
		BITSTREAM *bs;
1220
	written_spec = 1 ;
1231
		written_spec = 1;
1221
	if ( !open_output ( OUTPUT_SPEC, binary_mode ) ) {
1232
		if (!open_output(OUTPUT_SPEC, binary_mode)) {
1222
	    fail ( ERR_fail_spec ( nm ) ) ;
1233
			fail(ERR_fail_spec(nm));
1223
	    spec_unit = NULL ;
1234
			spec_unit = NULL;
1224
	    term_error ( 0 ) ;
1235
			term_error(0);
1225
	    return ;
1236
			return;
-
 
1237
		}
-
 
1238
		f = output_file[OUTPUT_SPEC];
-
 
1239
		bs = start_bitstream(f, NULL_gen_ptr);
-
 
1240
 
-
 
1241
		/* Write file identifier */
-
 
1242
		ENC_BITS(bs, BYTE_SIZE, ascii_T);
-
 
1243
		ENC_BITS(bs, BYTE_SIZE, ascii_D);
-
 
1244
		ENC_BITS(bs, BYTE_SIZE, ascii_F);
-
 
1245
		ENC_BITS(bs, BYTE_SIZE, ascii_K);
-
 
1246
		ENC_INT(bs, SPEC_major);
-
 
1247
		ENC_INT(bs, SPEC_minor);
-
 
1248
		ENC_INT(bs, LANGUAGE_CPP);
-
 
1249
		ENC_ALIGN(bs);
-
 
1250
		spec_unit = bs;
1226
	}
1251
	}
1227
	f = output_file [ OUTPUT_SPEC ] ;
-
 
1228
	bs = start_bitstream ( f, NULL_gen_ptr ) ;
-
 
1229
 
-
 
1230
	/* Write file identifier */
-
 
1231
	ENC_BITS ( bs, BYTE_SIZE, ascii_T ) ;
-
 
1232
	ENC_BITS ( bs, BYTE_SIZE, ascii_D ) ;
-
 
1233
	ENC_BITS ( bs, BYTE_SIZE, ascii_F ) ;
-
 
1234
	ENC_BITS ( bs, BYTE_SIZE, ascii_K ) ;
-
 
1235
	ENC_INT ( bs, SPEC_major ) ;
-
 
1236
	ENC_INT ( bs, SPEC_minor ) ;
-
 
1237
	ENC_INT ( bs, LANGUAGE_CPP ) ;
-
 
1238
	ENC_ALIGN ( bs ) ;
-
 
1239
	spec_unit = bs ;
-
 
1240
    }
-
 
1241
    return ;
1252
	return;
1242
}
1253
}
1243
 
1254
 
1244
 
1255
 
1245
/*
1256
/*
1246
    END A SPEC FILE
1257
    END A SPEC FILE
1247
 
1258
 
1248
    This routine completes the output of a spec file.
1259
    This routine completes the output of a spec file.
1249
*/
1260
*/
1250
 
1261
 
1251
void end_spec
1262
void
1252
    PROTO_Z ()
1263
end_spec(void)
1253
{
1264
{
1254
    BITSTREAM *bs = spec_unit ;
1265
	BITSTREAM *bs = spec_unit;
1255
    if ( bs ) {
1266
	if (bs) {
1256
	if ( !output_spec ) ENC_INT ( bs, 0 ) ;
1267
		if (!output_spec)ENC_INT(bs, 0);
1257
	end_bitstream ( bs, 1 ) ;
1268
		end_bitstream(bs, 1);
1258
	close_output ( OUTPUT_SPEC ) ;
1269
		close_output(OUTPUT_SPEC);
1259
	spec_unit = NULL ;
1270
		spec_unit = NULL;
1260
    }
1271
	}
1261
    return ;
1272
	return;
1262
}
1273
}