Subversion Repositories tendra.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
2
    		 Crown Copyright (c) 1997
3
 
4
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
12
 
13
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
15
 
16
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
19
 
20
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
22
        these conditions;
23
 
24
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
27
        it may be put.
28
*/
29
 
30
 
31
#include "config.h"
32
#include "version.h"
33
#include "system.h"
34
#include "c_types.h"
35
#include "ctype_ops.h"
36
#include "etype_ops.h"
37
#include "exp_ops.h"
38
#include "ftype_ops.h"
39
#include "graph_ops.h"
40
#include "hashid_ops.h"
41
#include "id_ops.h"
42
#include "itype_ops.h"
43
#include "member_ops.h"
44
#include "nat_ops.h"
45
#include "nspace_ops.h"
46
#include "off_ops.h"
47
#include "tok_ops.h"
48
#include "type_ops.h"
49
#include "error.h"
50
#include "catalog.h"
51
#include "basetype.h"
52
#include "bits.h"
53
#include "buffer.h"
54
#include "char.h"
55
#include "chktype.h"
56
#include "class.h"
57
#include "constant.h"
58
#include "convert.h"
59
#include "decode.h"
60
#include "derive.h"
61
#include "dump.h"
62
#include "encode.h"
63
#include "exception.h"
64
#include "file.h"
65
#include "function.h"
66
#include "hash.h"
67
#include "inttype.h"
68
#include "lex.h"
69
#include "literal.h"
70
#include "load.h"
71
#include "merge.h"
72
#include "namespace.h"
73
#include "redeclare.h"
74
#include "save.h"
75
#include "symbols.h"
76
#include "syntax.h"
77
#include "token.h"
78
#include "ustring.h"
79
#include "xalloc.h"
80
 
81
 
82
/*
83
    FORWARD DECLARATIONS
84
 
85
    The following forward declarations are required in the spec input
86
    routines.
87
*/
88
 
89
static EXP load_exp PROTO_S ( ( BITSTREAM *, TYPE ) ) ;
90
static TYPE load_type PROTO_S ( ( BITSTREAM *, IDENTIFIER ) ) ;
91
static TYPE load_ctype PROTO_S ( ( BITSTREAM *, IDENTIFIER, CLASS_TYPE * ) ) ;
92
static IDENTIFIER load_id PROTO_S ( ( BITSTREAM *, NAMESPACE ) ) ;
93
static LIST ( TYPE ) load_type_list PROTO_S ( ( BITSTREAM * ) ) ;
94
static TOKEN load_tok PROTO_S ( ( BITSTREAM *, int ) ) ;
95
static void load_nspace PROTO_S ( ( BITSTREAM *, NAMESPACE, int ) ) ;
96
 
97
 
98
/*
99
    SPEC INPUT ERROR FLAG
100
 
101
    This flag is set to true to indicate a spec input error.
102
*/
103
 
104
static int spec_error = 0 ;
105
 
106
 
107
/*
108
    SPEC ERROR ROUTINE
109
 
110
    This routine is called when a spec input error occurs.  code gives
111
    the reason for the error.
112
*/
113
 
114
static void spec_fail
115
    PROTO_N ( ( code ) )
116
    PROTO_T ( int code )
117
{
118
    if ( !spec_error ) spec_error = code ;
119
    return ;
120
}
121
 
122
 
123
/*
124
    SPEC ERROR CODES
125
 
126
    The spec error codes are given by the corresponding source line.
127
    This macro gives a convenient shorthand for calling spec_fail.
128
*/
129
 
130
#ifdef __LINE__
131
#define SPEC_ERROR()		spec_fail ( __LINE__ )
132
#else
133
#define SPEC_ERROR()		spec_fail ( 100 )
134
#endif
135
 
136
 
137
/*
138
    SIMPLE READING ROUTINES
139
 
140
    These macros give the simple reading routines for the enumeration
141
    types etc.  Note that DE_BITS_2 is used for types which occupy more
142
    than 16 bits.
143
*/
144
 
145
#define load_btype( A )		( BASE_TYPE ) DE_BITS_2 ( ( A ), BITS_btype )
146
#define load_cinfo( A )		( CLASS_INFO ) DE_BITS_2 ( ( A ), BITS_cinfo )
147
#define load_cusage( A )	( CLASS_USAGE ) DE_BITS ( ( A ), BITS_cusage )
148
#define load_cv( A )		( CV_SPEC ) DE_BITS ( ( A ), BITS_cv_qual )
149
#define load_dspec( A )		( DECL_SPEC ) DE_BITS_2 ( ( A ), BITS_dspec )
150
#define load_mqual( A )		( CV_SPEC ) DE_BITS ( ( A ), BITS_cv )
151
#define load_qual( A )		( QUALIFIER ) DE_BITS ( ( A ), BITS_qual )
152
 
153
 
154
/*
155
    READ A LEXICAL TOKEN NUMBER
156
 
157
    This routine reads a lexical token number from the bitstream bs.
158
*/
159
 
160
static int load_lex
161
    PROTO_N ( ( bs ) )
162
    PROTO_T ( BITSTREAM *bs )
163
{
164
    int t = ( int ) DE_BITS ( bs, BITS_lex ) ;
165
    if ( t > LAST_TOKEN ) {
166
	t = lex_unknown ;
167
	SPEC_ERROR () ;
168
    }
169
    return ( t ) ;
170
}
171
 
172
 
173
/*
174
    READ A LIST OF PREPROCESSING TOKENS
175
 
176
    This routine reads a list of preprocessing tokens from the
177
    bitstream bs.
178
*/
179
 
180
static PPTOKEN *load_pptoks
181
    PROTO_N ( ( bs ) )
182
    PROTO_T ( BITSTREAM *bs )
183
{
184
    /* NOT YET IMPLEMENTED */
185
    UNUSED ( bs ) ;
186
    return ( NULL ) ;
187
}
188
 
189
 
190
/*
191
    READ A LOCATION
192
 
193
    This routine reads the current location from the bitstream bs.
194
*/
195
 
196
static void load_loc
197
    PROTO_N ( ( bs ) )
198
    PROTO_T ( BITSTREAM *bs )
199
{
200
    if ( DE_BOOL ( bs ) ) {
201
	/* Line number has changed */
202
	crt_loc.line = DE_INT ( bs ) ;
203
	crt_loc.column = 0 ;
204
	if ( DE_BOOL ( bs ) ) {
205
	    /* File position has changed */
206
	    string file ;
207
	    string input ;
208
	    ulong date, date2 ;
209
	    STAT_TYPE *fs = NULL ;
210
	    PTR ( POSITION ) posn ;
211
	    PTR ( LOCATION ) from = NULL_ptr ( LOCATION ) ;
212
	    unsigned long off = DE_INT ( bs ) ;
213
	    if ( DE_BOOL ( bs ) ) {
214
		STAT_TYPE fstr ;
215
		BUFFER *bf = clear_buffer ( &token_buff, NIL ( FILE ) ) ;
216
		de_tdfstring ( bs, bf ) ;
217
		file = xustrcpy ( bf->start ) ;
218
		if ( DE_BOOL ( bs ) ) {
219
		    bf = clear_buffer ( &token_buff, NIL ( FILE ) ) ;
220
		    de_tdfstring ( bs, bf ) ;
221
		    input = xustrcpy ( bf->start ) ;
222
		} else {
223
		    input = file ;
224
		}
225
		date = DE_INT ( bs ) ;
226
		fs = stat_func ( strlit ( input ), &fstr ) ;
227
		date2 = stat_date ( fs ) ;
228
	    } else {
229
		posn = crt_loc.posn ;
230
		file = DEREF_string ( posn_file ( posn ) ) ;
231
		input = DEREF_string ( posn_input ( posn ) ) ;
232
		date = DEREF_ulong ( posn_datestamp ( posn ) ) ;
233
		date2 = date ;
234
	    }
235
	    posn = MAKE_ptr ( SIZE_posn ) ;
236
	    MAKE_posn ( file, input, input, NULL, off, from, date, posn ) ;
237
	    crt_loc.posn = posn ;
238
	    if ( date && date2 && date != date2 ) {
239
		/* File has changed on disk */
240
		if ( !already_included ( input, fs, 4 ) ) {
241
		    report ( crt_loc, ERR_cpp_include_date () ) ;
242
		}
243
	    }
244
	}
245
    }
246
    return ;
247
}
248
 
249
 
250
/*
251
    READ AN IDENTIFIER NAME
252
 
253
    This routine reads an identifier name from the bitstream bs.  ns gives
254
    the current namespace.
255
*/
256
 
257
static HASHID load_hashid
258
    PROTO_N ( ( bs, ns ) )
259
    PROTO_T ( BITSTREAM *bs X NAMESPACE ns )
260
{
261
    HASHID nm = NULL_hashid ;
262
    unsigned n = DE_BITS ( bs, BITS_hashid ) ;
263
    if ( n ) {
264
	if ( n <= ORDER_hashid ) {
265
	    unsigned tag = n - 1 ;
266
	    ASSERT ( ORDER_hashid == 7 ) ;
267
	    switch ( tag ) {
268
		case hashid_name_tag :
269
		case hashid_ename_tag : {
270
		    string s ;
271
		    int ext = 0 ;
272
		    unsigned long h ;
273
		    BUFFER *bf = clear_buffer ( &token_buff, NIL ( FILE ) ) ;
274
		    de_tdfstring ( bs, bf ) ;
275
		    s = bf->start ;
276
		    h = hash ( s ) ;
277
		    if ( tag == hashid_ename_tag ) ext = 1 ;
278
		    nm = lookup_name ( s, h, ext, lex_unknown ) ;
279
		    break ;
280
		}
281
		case hashid_constr_tag : {
282
		    if ( IS_nspace_ctype ( ns ) ) {
283
			IDENTIFIER cid = DEREF_id ( nspace_name ( ns ) ) ;
284
			if ( IS_id_class_name ( cid ) ) {
285
			    TYPE t ;
286
			    t = DEREF_type ( id_class_name_defn ( cid ) ) ;
287
			    nm = lookup_constr ( t, cid ) ;
288
			    break ;
289
			}
290
		    }
291
		    SPEC_ERROR () ;
292
		    break ;
293
		}
294
		case hashid_destr_tag : {
295
		    if ( IS_nspace_ctype ( ns ) ) {
296
			IDENTIFIER cid = DEREF_id ( nspace_name ( ns ) ) ;
297
			if ( IS_id_class_name ( cid ) ) {
298
			    TYPE t ;
299
			    t = DEREF_type ( id_class_name_defn ( cid ) ) ;
300
			    nm = lookup_destr ( t, cid ) ;
301
			    break ;
302
			}
303
		    }
304
		    SPEC_ERROR () ;
305
		    break ;
306
		}
307
		case hashid_conv_tag : {
308
		    TYPE t = load_type ( bs, NULL_id ) ;
309
		    if ( !IS_NULL_type ( t ) ) {
310
			nm = lookup_conv ( t ) ;
311
			break ;
312
		    }
313
		    SPEC_ERROR () ;
314
		    break ;
315
		}
316
		case hashid_op_tag : {
317
		    int op = load_lex ( bs ) ;
318
		    nm = lookup_op ( op ) ;
319
		    break ;
320
		}
321
		case hashid_anon_tag : {
322
		    nm = lookup_anon () ;
323
		    break ;
324
		}
325
	    }
326
	} else {
327
	    SPEC_ERROR () ;
328
	}
329
    }
330
    return ( nm ) ;
331
}
332
 
333
 
334
/*
335
    READ A LIST OF IDENTIFIER NAMES
336
 
337
    This routine reads a list of identifier names from the bitstream bs.
338
*/
339
 
340
static LIST ( HASHID ) load_hashid_list
341
    PROTO_N ( ( bs, ns ) )
342
    PROTO_T ( BITSTREAM *bs X NAMESPACE ns )
343
{
344
    LIST ( HASHID ) p = NULL_list ( HASHID ) ;
345
    while ( DE_BOOL ( bs ) ) {
346
	HASHID nm = load_hashid ( bs, ns ) ;
347
	if ( IS_NULL_hashid ( nm ) ) {
348
	    SPEC_ERROR () ;
349
	    break ;
350
	}
351
	CONS_hashid ( nm, p, p ) ;
352
    }
353
    p = REVERSE_list ( p ) ;
354
    return ( p ) ;
355
}
356
 
357
 
358
/*
359
    IDENTIFIER LOOK-UP TABLE
360
 
361
    These variables give the table which gives the mapping between identifier
362
    numbers and identifiers.
363
*/
364
 
365
static IDENTIFIER *id_table = NULL ;
366
static ulong id_table_size = 0 ;
367
static ulong ids_pending = 0 ;
368
 
369
 
370
/*
371
    LOOK UP IDENTIFIER IN TABLE
372
 
373
    This routine returns a pointer to the dth element of the table above,
374
    extending it if necessary.
375
*/
376
 
377
static IDENTIFIER *id_lookup
378
    PROTO_N ( ( d ) )
379
    PROTO_T ( ulong d )
380
{
381
    ulong m = id_table_size ;
382
    IDENTIFIER *p = id_table ;
383
    if ( d >= m ) {
384
	ulong n = d + 100 ;
385
	p = xrealloc_nof ( p, IDENTIFIER, n ) ;
386
	while ( m < n ) {
387
	    p [m] = NULL_id ;
388
	    m++ ;
389
	}
390
	id_table_size = n ;
391
	id_table = p ;
392
    }
393
    return ( p + d ) ;
394
}
395
 
396
 
397
/*
398
    READ AN IDENTIFIER NUMBER
399
 
400
    This routine reads an identifier number from the bitstream bs.  It is
401
    possible for an identifier to be used before it is declared using
402
    load_id.
403
*/
404
 
405
static IDENTIFIER load_use
406
    PROTO_N ( ( bs, tag ) )
407
    PROTO_T ( BITSTREAM *bs X unsigned tag )
408
{
409
    IDENTIFIER id ;
410
    IDENTIFIER *pid ;
411
    ulong d = DE_INT ( bs ) ;
412
    if ( d == 0 ) {
413
	/* Null identifier */
414
	return ( NULL_id ) ;
415
    }
416
    pid = id_lookup ( d ) ;
417
    id = *pid ;
418
    if ( IS_NULL_id ( id ) ) {
419
	/* Create dummy identifier */
420
	HASHID nm = KEYWORD ( lex_zzzz ) ;
421
	MAKE_id_pending ( nm, dspec_none, NULL_nspace, crt_loc,
422
			  tag, NULL_type, id ) ;
423
	COPY_ulong ( id_dump ( id ), d ) ;
424
	ids_pending++ ;
425
	*pid = id ;
426
    }
427
    return ( id ) ;
428
}
429
 
430
 
431
/*
432
    READ A LIST OF IDENTIFIER NUMBERS
433
 
434
    This routine reads a list of identifier numbers from the bitstream bs.
435
*/
436
 
437
static LIST ( IDENTIFIER ) load_use_list
438
    PROTO_N ( ( bs ) )
439
    PROTO_T ( BITSTREAM *bs )
440
{
441
    LIST ( IDENTIFIER ) p = NULL_list ( IDENTIFIER ) ;
442
    while ( DE_BOOL ( bs ) ) {
443
	IDENTIFIER id = load_use ( bs, null_tag ) ;
444
	if ( spec_error ) break ;
445
	CONS_id ( id, p, p ) ;
446
    }
447
    p = REVERSE_list ( p ) ;
448
    return ( p ) ;
449
}
450
 
451
 
452
/*
453
    READ A LIST OF TOKENS
454
 
455
    This routine reads a list of tokens from the bitstream bs.  def is
456
    as in load_tok.
457
*/
458
 
459
static LIST ( TOKEN ) load_tok_list
460
    PROTO_N ( ( bs, def ) )
461
    PROTO_T ( BITSTREAM *bs X int def )
462
{
463
    LIST ( TOKEN ) p = NULL_list ( TOKEN ) ;
464
    while ( DE_BOOL ( bs ) ) {
465
	TOKEN tok = load_tok ( bs, def ) ;
466
	if ( spec_error ) break ;
467
	CONS_tok ( tok, p, p ) ;
468
    }
469
    p = REVERSE_list ( p ) ;
470
    return ( p ) ;
471
}
472
 
473
 
474
/*
475
    READ AN INTEGER CONSTANT
476
 
477
    This routine reads an integer constant from the bitstream bs.
478
*/
479
 
480
static NAT load_nat
481
    PROTO_N ( ( bs ) )
482
    PROTO_T ( BITSTREAM *bs )
483
{
484
    NAT m = NULL_nat ;
485
    unsigned n = DE_BITS ( bs, BITS_nat ) ;
486
    if ( n == 0 ) {
487
	/* Null constants */
488
	return ( m ) ;
489
    }
490
    if ( n > ORDER_nat ) {
491
	SPEC_ERROR () ;
492
	return ( m ) ;
493
    }
494
    ASSERT ( ORDER_nat == 5 ) ;
495
    switch ( n - 1 ) {
496
	case nat_small_tag : {
497
	    unsigned long v = DE_INT ( bs ) ;
498
	    m = make_nat_value ( v ) ;
499
	    break ;
500
	}
501
	case nat_large_tag : {
502
	    int count = 0 ;
503
	    LIST ( unsigned ) p = NULL_list ( unsigned ) ;
504
	    while ( DE_BOOL ( bs ) ) {
505
		unsigned v = ( unsigned ) DE_INT ( bs ) ;
506
		CONS_unsigned ( v, p, p ) ;
507
		if ( ++count == 10 ) {
508
		    /* Check for end of file */
509
		    if ( de_eof ( bs ) ) {
510
			SPEC_ERROR () ;
511
			break ;
512
		    }
513
		    count = 0 ;
514
		}
515
	    }
516
	    p = REVERSE_list ( p ) ;
517
	    m = make_large_nat ( p ) ;
518
	    break ;
519
	}
520
	case nat_calc_tag : {
521
	    EXP e = load_exp ( bs, type_sint ) ;
522
	    if ( !IS_NULL_exp ( e ) ) {
523
		MAKE_nat_calc ( e, m ) ;
524
		break ;
525
	    }
526
	    SPEC_ERROR () ;
527
	    break ;
528
	}
529
	case nat_neg_tag : {
530
	    m = load_nat ( bs ) ;
531
	    if ( !IS_NULL_nat ( m ) ) {
532
		m = negate_nat ( m ) ;
533
		break ;
534
	    }
535
	    SPEC_ERROR () ;
536
	    break ;
537
	}
538
	case nat_token_tag : {
539
	    IDENTIFIER tok = load_use ( bs, null_tag ) ;
540
	    if ( !IS_NULL_id ( tok ) ) {
541
		LIST ( TOKEN ) args = load_tok_list ( bs, 1 ) ;
542
		MAKE_nat_token ( tok, args, m ) ;
543
		break ;
544
	    }
545
	    SPEC_ERROR () ;
546
	    break ;
547
	}
548
    }
549
    return ( m ) ;
550
}
551
 
552
 
553
/*
554
    READ AN OFFSET
555
 
556
    This routine reads an offset from the bitstream bs.
557
*/
558
 
559
static OFFSET load_off
560
    PROTO_N ( ( bs ) )
561
    PROTO_T ( BITSTREAM *bs )
562
{
563
    /* NOT YET IMPLEMENTED */
564
    UNUSED ( bs ) ;
565
    return ( NULL_off ) ;
566
}
567
 
568
 
569
/*
570
    READ AN EXPRESSION
571
 
572
    This routine reads an expression from the bitstream bs.
573
*/
574
 
575
static EXP load_exp
576
    PROTO_N ( ( bs, t ) )
577
    PROTO_T ( BITSTREAM *bs X TYPE t )
578
{
579
    unsigned tag ;
580
    EXP e = NULL_exp ;
581
    unsigned n = DE_BITS ( bs, BITS_exp ) ;
582
    if ( n == 0 ) {
583
	/* Null expressions */
584
	return ( e ) ;
585
    }
586
    if ( n > ORDER_exp ) {
587
	SPEC_ERROR () ;
588
	return ( e ) ;
589
    }
590
    tag = n - 1 ;
591
    switch ( tag ) {
592
	case exp_int_lit_tag : {
593
	    NAT m = load_nat ( bs ) ;
594
	    if ( !IS_NULL_nat ( m ) ) {
595
		unsigned etag = DE_BITS ( bs, BITS_exp ) ;
596
		if ( etag < ORDER_exp ) {
597
		    MAKE_exp_int_lit ( t, m, etag, e ) ;
598
		    break ;
599
		}
600
	    }
601
	    SPEC_ERROR () ;
602
	    break ;
603
	}
604
	case exp_token_tag : {
605
	    IDENTIFIER tok = load_use ( bs, null_tag ) ;
606
	    if ( !IS_NULL_id ( tok ) ) {
607
		LIST ( TOKEN ) args = load_tok_list ( bs, 1 ) ;
608
		MAKE_exp_token ( t, tok, args, e ) ;
609
		break ;
610
	    }
611
	    SPEC_ERROR () ;
612
	    break ;
613
	}
614
	default : {
615
	    /* NOT YET IMPLEMENTED */
616
	    MAKE_exp_value ( t, e ) ;
617
	    break ;
618
	}
619
    }
620
    return ( e ) ;
621
}
622
 
623
 
624
/*
625
    READ A BUILT-IN TYPE
626
 
627
    This routine reads a built-in type number from the bitstream bs.
628
*/
629
 
630
static BUILTIN_TYPE load_ntype
631
    PROTO_N ( ( bs ) )
632
    PROTO_T ( BITSTREAM *bs )
633
{
634
    BUILTIN_TYPE nt = ( BUILTIN_TYPE ) DE_BITS ( bs, BITS_ntype ) ;
635
    if ( nt >= ORDER_ntype ) {
636
	nt = ntype_none ;
637
	SPEC_ERROR () ;
638
    }
639
    return ( nt ) ;
640
}
641
 
642
 
643
/*
644
    READ AN INTEGRAL TYPE
645
 
646
    This routine reads a integral type from the bitstream bs.  Note that
647
    the result is returned as a type rather than an integral type.
648
*/
649
 
650
static TYPE load_itype
651
    PROTO_N ( ( bs, cv, tag ) )
652
    PROTO_T ( BITSTREAM *bs X CV_SPEC cv X unsigned tag )
653
{
654
    TYPE t = NULL_type ;
655
    unsigned n = DE_BITS ( bs, BITS_itype ) ;
656
    if ( n == 0 ) {
657
	/* Null types */
658
	return ( t ) ;
659
    }
660
    if ( n > ORDER_itype ) {
661
	SPEC_ERROR () ;
662
	return ( t ) ;
663
    }
664
    switch ( n - 1 ) {
665
	case itype_basic_tag : {
666
	    BUILTIN_TYPE nt = load_ntype ( bs ) ;
667
	    t = type_builtin [ nt ] ;
668
	    break ;
669
	}
670
	case itype_bitfield_tag : {
671
	    TYPE s = load_type ( bs, NULL_id ) ;
672
	    if ( !IS_NULL_type ( s ) ) {
673
		BASE_TYPE bt = load_btype ( bs ) ;
674
		NAT m = load_nat ( bs ) ;
675
		if ( !IS_NULL_nat ( m ) ) {
676
		    t = check_bitfield_type ( cv, s, bt, m, 1 ) ;
677
		    cv = cv_none ;
678
		    break ;
679
		}
680
	    }
681
	    SPEC_ERROR () ;
682
	    break ;
683
	}
684
	case itype_promote_tag : {
685
	    TYPE s = load_itype ( bs, cv_none, type_integer_tag ) ;
686
	    if ( !IS_NULL_type ( s ) ) {
687
		t = promote_type ( s ) ;
688
		break ;
689
	    }
690
	    SPEC_ERROR () ;
691
	    break ;
692
	}
693
	case itype_arith_tag : {
694
	    TYPE s = load_itype ( bs, cv_none, type_integer_tag ) ;
695
	    if ( !IS_NULL_type ( s ) ) {
696
		TYPE r = load_itype ( bs, cv_none, type_integer_tag ) ;
697
		if ( !IS_NULL_type ( r ) ) {
698
		    t = arith_itype ( s, r, NULL_exp, NULL_exp ) ;
699
		    break ;
700
		}
701
	    }
702
	    SPEC_ERROR () ;
703
	    break ;
704
	}
705
	case itype_literal_tag : {
706
	    NAT m = load_nat ( bs ) ;
707
	    if ( !IS_NULL_nat ( m ) ) {
708
		int form = ( int ) DE_BITS ( bs, 2 ) ;
709
		if ( form >= 0 && form < BASE_NO ) {
710
		    int suff = ( int ) DE_BITS ( bs, 3 ) ;
711
		    if ( suff >= 0 && suff < SUFFIX_NO ) {
712
			int fit = 0 ;
713
			string str = NULL_string ;
714
			t = find_literal_type ( m, form, suff, str, &fit ) ;
715
			break ;
716
		    }
717
		}
718
	    }
719
	    SPEC_ERROR () ;
720
	    break ;
721
	}
722
	case itype_token_tag : {
723
	    IDENTIFIER tok = load_use ( bs, null_tag ) ;
724
	    if ( !IS_NULL_id ( tok ) ) {
725
		LIST ( TOKEN ) args = load_tok_list ( bs, 1 ) ;
726
		t = apply_itype_token ( tok, args ) ;
727
		break ;
728
	    }
729
	    SPEC_ERROR () ;
730
	    break ;
731
	}
732
    }
733
    if ( !IS_NULL_type ( t ) ) {
734
	if ( TAG_type ( t ) == tag ) {
735
	    if ( cv ) t = qualify_type ( t, cv, 0 ) ;
736
	} else {
737
	    SPEC_ERROR () ;
738
	}
739
    }
740
    return ( t ) ;
741
}
742
 
743
 
744
/*
745
    READ A FLOATING POINT TYPE
746
 
747
    This routine reads a floating point type from the bitstream bs.  Note
748
    that the result is returned as a type rather than a floating point type.
749
*/
750
 
751
static TYPE load_ftype
752
    PROTO_N ( ( bs, cv ) )
753
    PROTO_T ( BITSTREAM *bs X CV_SPEC cv )
754
{
755
    TYPE t = NULL_type ;
756
    unsigned n = DE_BITS ( bs, BITS_ftype ) ;
757
    if ( n == 0 ) {
758
	/* Null types */
759
	return ( t ) ;
760
    }
761
    if ( n > ORDER_ftype ) {
762
	SPEC_ERROR () ;
763
	return ( t ) ;
764
    }
765
    ASSERT ( ORDER_ftype == 4 ) ;
766
    switch ( n - 1 ) {
767
	case ftype_basic_tag : {
768
	    BUILTIN_TYPE nt = load_ntype ( bs ) ;
769
	    t = type_builtin [ nt ] ;
770
	    break ;
771
	}
772
	case ftype_arg_promote_tag : {
773
	    TYPE s = load_ftype ( bs, cv_none ) ;
774
	    if ( !IS_NULL_type ( s ) ) {
775
		t = arg_promote_type ( s, KILL_err ) ;
776
		break ;
777
	    }
778
	    SPEC_ERROR () ;
779
	    break ;
780
	}
781
	case ftype_arith_tag : {
782
	    TYPE s = load_ftype ( bs, cv_none ) ;
783
	    if ( !IS_NULL_type ( s ) ) {
784
		TYPE r = load_ftype ( bs, cv_none ) ;
785
		if ( !IS_NULL_type ( r ) ) {
786
		    t = arith_ftype ( s, r ) ;
787
		    break ;
788
		}
789
	    }
790
	    SPEC_ERROR () ;
791
	    break ;
792
	}
793
	case ftype_token_tag : {
794
	    IDENTIFIER tok = load_use ( bs, null_tag ) ;
795
	    if ( !IS_NULL_id ( tok ) ) {
796
		LIST ( TOKEN ) args = load_tok_list ( bs, 1 ) ;
797
		t = apply_ftype_token ( tok, args ) ;
798
		break ;
799
	    }
800
	    break ;
801
	}
802
    }
803
    if ( !IS_NULL_type ( t ) ) {
804
	if ( IS_type_floating ( t ) ) {
805
	    if ( cv ) t = qualify_type ( t, cv, 0 ) ;
806
	} else {
807
	    SPEC_ERROR () ;
808
	    t = NULL_type ;
809
	}
810
    }
811
    return ( t ) ;
812
}
813
 
814
 
815
/*
816
    READ A BASE CLASS GRAPH
817
 
818
    This routine reads a base class from the bitstream bs.  gu gives the
819
    parent graph and gt gives the top of the graph.
820
*/
821
 
822
static GRAPH load_graph
823
    PROTO_N ( ( bs, gu, gt ) )
824
    PROTO_T ( BITSTREAM *bs X GRAPH gu X GRAPH gt )
825
{
826
    GRAPH gr ;
827
    LIST ( GRAPH ) br = NULL_list ( GRAPH ) ;
828
    if ( IS_NULL_graph ( gu ) ) {
829
	/* Top graph node */
830
	gr = gt ;
831
    } else {
832
	/* Read graph node */
833
	CLASS_TYPE ct = NULL_ctype ;
834
	IGNORE load_ctype ( bs, NULL_id, &ct ) ;
835
	if ( !IS_NULL_ctype ( ct ) ) {
836
	    DECL_SPEC acc = load_dspec ( bs ) ;
837
	    MAKE_graph_basic ( ct, acc, gr ) ;
838
	} else {
839
	    SPEC_ERROR () ;
840
	    return ( NULL_graph ) ;
841
	}
842
    }
843
    while ( DE_BOOL ( bs ) ) {
844
	/* Read base classes */
845
	GRAPH gs = load_graph ( bs, gr, gt ) ;
846
	if ( IS_NULL_graph ( gs ) ) break ;
847
	CONS_graph ( gs, br, br ) ;
848
    }
849
    br = REVERSE_list ( br ) ;
850
    COPY_list ( graph_tails ( gr ), br ) ;
851
    COPY_graph ( graph_top ( gr ), gt ) ;
852
    COPY_graph ( graph_up ( gr ), gu ) ;
853
    return ( gr ) ;
854
}
855
 
856
 
857
/*
858
    READ A CLASS TYPE
859
 
860
    This routine reads a class type from the bitstream bs.  If def is not
861
    null then the full class definition is read, otherwise just a use is
862
    read.
863
*/
864
 
865
static TYPE load_ctype
866
    PROTO_N ( ( bs, def, pct ) )
867
    PROTO_T ( BITSTREAM *bs X IDENTIFIER def X CLASS_TYPE *pct )
868
{
869
    TYPE t = NULL_type ;
870
    if ( !IS_NULL_id ( def ) ) {
871
	if ( IS_id_class_name ( def ) ) {
872
	    /* Read class definition */
873
	    GRAPH gr ;
874
	    CLASS_TYPE ct ;
875
	    DECL_SPEC acc ;
876
	    NAMESPACE mns ;
877
 
878
	    /* Read the class information */
879
	    CLASS_INFO ci = load_cinfo ( bs ) ;
880
	    CLASS_USAGE cu = load_cusage ( bs ) ;
881
 
882
	    /* Create the class type */
883
	    acc = ( dspec_public | dspec_defn ) ;
884
	    MAKE_graph_basic ( NULL_ctype, acc, gr ) ;
885
	    mns = make_namespace ( def, nspace_ctype_tag, 20 ) ;
886
	    MAKE_ctype_basic ( def, ci, cu, mns, gr, 1, NULL_type, ct ) ;
887
	    COPY_ctype ( graph_head ( gr ), ct ) ;
888
	    MAKE_type_compound ( cv_none, ct, t ) ;
889
	    COPY_type ( id_class_name_defn ( def ), t ) ;
890
	    COPY_id ( type_name ( t ), def ) ;
891
	    IGNORE lookup_constr ( t, def ) ;
892
	    IGNORE lookup_destr ( t, def ) ;
893
	    crt_class = ct ;
894
	    *pct = ct ;
895
 
896
	    /* Read the base class graph */
897
	    IGNORE load_graph ( bs, NULL_graph, gr ) ;
898
	    end_base_class ( ct, 1 ) ;
899
 
900
	    /* Read template form */
901
	    if ( DE_BOOL ( bs ) ) {
902
		TYPE form = load_type ( bs, NULL_id ) ;
903
		COPY_type ( ctype_form ( ct ), form ) ;
904
	    }
905
 
906
	} else {
907
	    SPEC_ERROR () ;
908
	}
909
 
910
    } else {
911
	/* Read class name */
912
	IDENTIFIER cid = load_use ( bs, id_class_name_tag ) ;
913
	if ( !IS_NULL_id ( cid ) ) {
914
	    if ( IS_id_class_name ( cid ) ) {
915
		t = DEREF_type ( id_class_name_defn ( cid ) ) ;
916
	    }
917
	}
918
	if ( !IS_NULL_type ( t ) ) {
919
	    while ( IS_type_templ ( t ) ) {
920
		t = DEREF_type ( type_templ_defn ( t ) ) ;
921
	    }
922
	    if ( IS_type_compound ( t ) ) {
923
		CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
924
		*pct = ct ;
925
	    } else {
926
		t = NULL_type ;
927
		SPEC_ERROR () ;
928
	    }
929
	} else {
930
	    SPEC_ERROR () ;
931
	}
932
    }
933
    return ( t ) ;
934
}
935
 
936
 
937
/*
938
    READ AN ENUMERATION TYPE
939
 
940
    This routine reads an enumeration type from the bitstream bs.  If def
941
    is not null then the full enumeration definition is read, otherwise
942
    just a use is read.
943
*/
944
 
945
static TYPE load_etype
946
    PROTO_N ( ( bs, def, pet ) )
947
    PROTO_T ( BITSTREAM *bs X IDENTIFIER def X ENUM_TYPE *pet )
948
{
949
    TYPE t = NULL_type ;
950
    if ( !IS_NULL_id ( def ) ) {
951
	if ( IS_id_enum_name ( def ) ) {
952
	    /* Read enumeration definition */
953
	    ENUM_TYPE et ;
954
	    CLASS_INFO ei = load_cinfo ( bs ) ;
955
	    TYPE s = load_type ( bs, NULL_id ) ;
956
	    if ( !IS_NULL_type ( s ) ) {
957
		MAKE_etype_basic ( def, ei, s, et ) ;
958
		if ( DE_BOOL ( bs ) ) {
959
		    TYPE form = load_type ( bs, NULL_id ) ;
960
		    COPY_type ( etype_form ( et ), form ) ;
961
		}
962
		MAKE_type_enumerate ( cv_none, et, t ) ;
963
		COPY_type ( id_enum_name_defn ( def ), t ) ;
964
		COPY_id ( type_name ( t ), def ) ;
965
		*pet = et ;
966
	    } else {
967
		SPEC_ERROR () ;
968
	    }
969
	} else {
970
	    SPEC_ERROR () ;
971
	}
972
    } else {
973
	/* Read enumeration name */
974
	IDENTIFIER eid = load_use ( bs, id_enum_name_tag ) ;
975
	if ( !IS_NULL_id ( eid ) ) {
976
	    if ( IS_id_enum_name ( eid ) ) {
977
		t = DEREF_type ( id_enum_name_defn ( eid ) ) ;
978
	    }
979
	}
980
	if ( !IS_NULL_type ( t ) && IS_type_enumerate ( t ) ) {
981
	    ENUM_TYPE et ;
982
	    et = DEREF_etype ( type_enumerate_defn ( t ) ) ;
983
	    *pet = et ;
984
	} else {
985
	    t = NULL_type ;
986
	    SPEC_ERROR () ;
987
	}
988
    }
989
    return ( t ) ;
990
}
991
 
992
 
993
/*
994
    READ A FUNCTION PARAMETER LIST
995
 
996
    This routine reads a list of function or template parameters (as
997
    indicated by tag) from the bitstream bs into the namespace ns.
998
*/
999
 
1000
static LIST ( IDENTIFIER ) load_param_list
1001
    PROTO_N ( ( bs, ns, tag ) )
1002
    PROTO_T ( BITSTREAM *bs X NAMESPACE ns X unsigned tag )
1003
{
1004
    LIST ( IDENTIFIER ) pids = NULL_list ( IDENTIFIER ) ;
1005
    while ( DE_BOOL ( bs ) ) {
1006
	HASHID nm ;
1007
	MEMBER mem ;
1008
	IDENTIFIER pid = load_id ( bs, ns ) ;
1009
	if ( IS_NULL_id ( pid ) || TAG_id ( pid ) != tag ) {
1010
	    SPEC_ERROR () ;
1011
	    break ;
1012
	}
1013
	nm = DEREF_hashid ( id_name ( pid ) ) ;
1014
	mem = search_member ( ns, nm, 1 ) ;
1015
	COPY_id ( member_id ( mem ), pid ) ;
1016
	CONS_id ( pid, pids, pids ) ;
1017
    }
1018
    pids = REVERSE_list ( pids ) ;
1019
    return ( pids ) ;
1020
}
1021
 
1022
 
1023
/*
1024
    READ A TYPE
1025
 
1026
    This routine reads a type from the bitstream bs.  def is passed to
1027
    load_ctype and load_etype.
1028
*/
1029
 
1030
static TYPE load_type
1031
    PROTO_N ( ( bs, def ) )
1032
    PROTO_T ( BITSTREAM *bs X IDENTIFIER def )
1033
{
1034
    unsigned n ;
1035
    CV_SPEC cv ;
1036
    unsigned tag ;
1037
    TYPE t = NULL_type ;
1038
    if ( DE_BOOL ( bs ) ) {
1039
	/* Built-in types */
1040
	BUILTIN_TYPE nt ;
1041
	cv = load_cv ( bs ) ;
1042
	nt = load_ntype ( bs ) ;
1043
	t = type_builtin [ nt ] ;
1044
	if ( cv ) t = qualify_type ( t, cv, 0 ) ;
1045
	return ( t ) ;
1046
    }
1047
 
1048
    /* Read type independent fields */
1049
    n = DE_BITS ( bs, BITS_type ) ;
1050
    if ( n == 0 ) {
1051
	/* Null types */
1052
	return ( t ) ;
1053
    }
1054
    if ( n > ORDER_type ) {
1055
	SPEC_ERROR () ;
1056
	return ( NULL_type ) ;
1057
    }
1058
    tag = n - 1 ;
1059
    cv = load_cv ( bs ) ;
1060
 
1061
    /* Read type dependent fields */
1062
    ASSERT ( ORDER_type == 18 ) ;
1063
    switch ( tag ) {
1064
 
1065
	case type_pre_tag : {
1066
	    IDENTIFIER tid = load_use ( bs, null_tag ) ;
1067
	    QUALIFIER qual = load_qual ( bs ) ;
1068
	    BASE_TYPE bt = load_btype ( bs ) ;
1069
	    MAKE_type_pre ( cv, bt, qual, t ) ;
1070
	    COPY_id ( type_name ( t ), tid ) ;
1071
	    break ;
1072
	}
1073
 
1074
	case type_integer_tag : {
1075
	    t = load_itype ( bs, cv, tag ) ;
1076
	    if ( !IS_NULL_type ( t ) ) {
1077
		if ( DE_BOOL ( bs ) ) {
1078
		    TYPE s = load_itype ( bs, cv_none, tag ) ;
1079
		    if ( !IS_NULL_type ( s ) ) {
1080
			INT_TYPE it, is ;
1081
			it = DEREF_itype ( type_integer_rep ( t ) ) ;
1082
			is = DEREF_itype ( type_integer_rep ( s ) ) ;
1083
			t = make_itype ( it, is ) ;
1084
		    }
1085
		}
1086
		break ;
1087
	    }
1088
	    SPEC_ERROR () ;
1089
	    break ;
1090
	}
1091
 
1092
	case type_floating_tag : {
1093
	    t = load_ftype ( bs, cv ) ;
1094
	    break ;
1095
	}
1096
 
1097
	case type_top_tag :
1098
	case type_bottom_tag : {
1099
	    /* Should not happen */
1100
	    MAKE_type_top_etc ( tag, cv, t ) ;
1101
	    break ;
1102
	}
1103
 
1104
	case type_ptr_tag :
1105
	case type_ref_tag : {
1106
	    /* Pointer and reference types */
1107
	    TYPE s = load_type ( bs, NULL_id ) ;
1108
	    if ( !IS_NULL_type ( s ) ) {
1109
		MAKE_type_ptr_etc ( tag, cv, s, t ) ;
1110
		break ;
1111
	    }
1112
	    SPEC_ERROR () ;
1113
	    break ;
1114
	}
1115
 
1116
	case type_ptr_mem_tag : {
1117
	    /* Pointer to member types */
1118
	    CLASS_TYPE cs = NULL_ctype ;
1119
	    IGNORE load_ctype ( bs, NULL_id, &cs ) ;
1120
	    if ( !IS_NULL_ctype ( cs ) ) {
1121
		TYPE r = load_type ( bs, NULL_id ) ;
1122
		if ( !IS_NULL_type ( r ) ) {
1123
		    MAKE_type_ptr_mem ( cv, cs, r, t ) ;
1124
		    break ;
1125
		}
1126
	    }
1127
	    SPEC_ERROR () ;
1128
	    break ;
1129
	}
1130
 
1131
	case type_func_tag : {
1132
	    /* Function types */
1133
	    TYPE r = load_type ( bs, NULL_id ) ;
1134
	    if ( !IS_NULL_type ( r ) ) {
1135
		int ell ;
1136
		NAMESPACE pns ;
1137
		CV_SPEC mqual ;
1138
		LIST ( IDENTIFIER ) pids ;
1139
		CLASS_TYPE cs = NULL_ctype ;
1140
		LIST ( TYPE ) ex = univ_type_set ;
1141
		begin_param ( NULL_id ) ;
1142
		pns = crt_namespace ;
1143
		pids = load_param_list ( bs, pns, id_parameter_tag ) ;
1144
		DESTROY_list ( pids, SIZE_id ) ;
1145
		ell = ( int ) DE_BITS ( bs, BITS_ellipsis ) ;
1146
		mqual = load_mqual ( bs ) ;
1147
		if ( DE_BOOL ( bs ) ) {
1148
		    /* Read member function type */
1149
		    IGNORE load_ctype ( bs, NULL_id, &cs ) ;
1150
		}
1151
		if ( DE_BOOL ( bs ) ) {
1152
		    /* Read exception specifier */
1153
		    ex = load_type_list ( bs ) ;
1154
		}
1155
		t = make_func_type ( r, ell, mqual, ex ) ;
1156
		end_param () ;
1157
		if ( !IS_NULL_ctype ( cs ) ) {
1158
		    member_func_type ( cs, id_mem_func_tag, t ) ;
1159
		}
1160
		break ;
1161
	    }
1162
	    SPEC_ERROR () ;
1163
	    break ;
1164
	}
1165
 
1166
	case type_array_tag : {
1167
	    /* Array types */
1168
	    TYPE s = load_type ( bs, NULL_id ) ;
1169
	    if ( !IS_NULL_type ( s ) ) {
1170
		NAT m = load_nat ( bs ) ;
1171
		MAKE_type_array ( cv, s, m, t ) ;
1172
		break ;
1173
	    }
1174
	    SPEC_ERROR () ;
1175
	    break ;
1176
	}
1177
 
1178
	case type_bitfield_tag : {
1179
	    /* Bitfield types */
1180
	    t = load_itype ( bs, cv, tag ) ;
1181
	    break ;
1182
	}
1183
 
1184
	case type_compound_tag : {
1185
	    /* Class types */
1186
	    CLASS_TYPE ct = NULL_ctype ;
1187
	    t = load_ctype ( bs, def, &ct ) ;
1188
	    if ( !IS_NULL_type ( t ) ) {
1189
		if ( cv ) t = qualify_type ( t, cv, 0 ) ;
1190
		break ;
1191
	    }
1192
	    SPEC_ERROR () ;
1193
	    break ;
1194
	}
1195
 
1196
	case type_enumerate_tag : {
1197
	    /* Enumeration types */
1198
	    ENUM_TYPE et = NULL_etype ;
1199
	    t = load_etype ( bs, def, &et ) ;
1200
	    if ( !IS_NULL_type ( t ) ) {
1201
		if ( cv ) t = qualify_type ( t, cv, 0 ) ;
1202
		break ;
1203
	    }
1204
	    SPEC_ERROR () ;
1205
	    break ;
1206
	}
1207
 
1208
	case type_token_tag : {
1209
	    IDENTIFIER tok = load_use ( bs, null_tag ) ;
1210
	    if ( !IS_NULL_id ( tok ) ) {
1211
		LIST ( TOKEN ) args = load_tok_list ( bs, 1 ) ;
1212
		MAKE_type_token ( cv, tok, args, t ) ;
1213
		break ;
1214
	    }
1215
	    SPEC_ERROR () ;
1216
	    break ;
1217
	}
1218
 
1219
	case type_templ_tag : {
1220
	    TOKEN tok = load_tok ( bs, 0 ) ;
1221
	    if ( !IS_NULL_tok ( tok ) && IS_tok_templ ( tok ) ) {
1222
		TYPE s = load_type ( bs, def ) ;
1223
		if ( !IS_NULL_type ( s ) ) {
1224
		    int fix = DE_BOOL ( bs ) ;
1225
		    MAKE_type_templ ( cv, tok, s, fix, t ) ;
1226
		    break ;
1227
		}
1228
	    }
1229
	    SPEC_ERROR () ;
1230
	    break ;
1231
	}
1232
 
1233
	case type_instance_tag : {
1234
	    IDENTIFIER tid = load_use ( bs, null_tag ) ;
1235
	    if ( !IS_NULL_id ( tid ) ) {
1236
		IDENTIFIER id = load_use ( bs, null_tag ) ;
1237
		if ( !IS_NULL_id ( id ) ) {
1238
		    DECL_SPEC acc = load_dspec ( bs ) ;
1239
		    MAKE_type_instance ( cv, id, acc, t ) ;
1240
		    COPY_id ( type_name ( t ), tid ) ;
1241
		    break ;
1242
		}
1243
	    }
1244
	    SPEC_ERROR () ;
1245
	    break ;
1246
	}
1247
 
1248
	case type_dummy_tag : {
1249
	    int tok = ( int ) DE_INT ( bs ) ;
1250
	    MAKE_type_dummy ( cv, tok, t ) ;
1251
	    break ;
1252
	}
1253
 
1254
	case type_error_tag : {
1255
	    t = type_error ;
1256
	    if ( cv ) t = qualify_type ( t, cv, 0 ) ;
1257
	    break ;
1258
	}
1259
    }
1260
    return ( t ) ;
1261
}
1262
 
1263
 
1264
/*
1265
    READ A LIST OF TYPES
1266
 
1267
    This routine reads a list of types from the bitstream bs.
1268
*/
1269
 
1270
static LIST ( TYPE ) load_type_list
1271
    PROTO_N ( ( bs ) )
1272
    PROTO_T ( BITSTREAM *bs )
1273
{
1274
    LIST ( TYPE ) p = NULL_list ( TYPE ) ;
1275
    while ( DE_BOOL ( bs ) ) {
1276
	TYPE t = load_type ( bs, NULL_id ) ;
1277
	if ( spec_error ) break ;
1278
	CONS_type ( t, p, p ) ;
1279
    }
1280
    p = REVERSE_list ( p ) ;
1281
    return ( p ) ;
1282
}
1283
 
1284
 
1285
/*
1286
    READ A TOKEN
1287
 
1288
    This routine reads a token from the bitstream bs.  If def is true
1289
    then the token value is also read.
1290
*/
1291
 
1292
static TOKEN load_tok
1293
    PROTO_N ( ( bs, def ) )
1294
    PROTO_T ( BITSTREAM *bs X int def )
1295
{
1296
    unsigned tag ;
1297
    TOKEN tok = NULL_tok ;
1298
    unsigned n = DE_BITS ( bs, BITS_tok ) ;
1299
    if ( n == 0 ) {
1300
	return ( tok ) ;
1301
    }
1302
    if ( n > ORDER_tok ) {
1303
	SPEC_ERROR () ;
1304
	return ( tok ) ;
1305
    }
1306
    ASSERT ( ORDER_tok == 10 ) ;
1307
    tag = n - 1 ;
1308
    switch ( tag ) {
1309
	case tok_exp_tag : {
1310
	    TYPE t = load_type ( bs, NULL_id ) ;
1311
	    if ( !IS_NULL_type ( t ) ) {
1312
		EXP e = NULL_exp ;
1313
		int c = DE_BOOL ( bs ) ;
1314
		if ( def ) e = load_exp ( bs, t ) ;
1315
		MAKE_tok_exp ( t, c, e, tok ) ;
1316
		break ;
1317
	    }
1318
	    SPEC_ERROR () ;
1319
	    break ;
1320
	}
1321
	case tok_stmt_tag : {
1322
	    EXP e = NULL_exp ;
1323
	    if ( def ) e = load_exp ( bs, type_void ) ;
1324
	    MAKE_tok_stmt ( e, tok ) ;
1325
	    break ;
1326
	}
1327
	case tok_nat_tag :
1328
	case tok_snat_tag : {
1329
	    NAT m = NULL_nat ;
1330
	    if ( def ) m = load_nat ( bs ) ;
1331
	    MAKE_tok_nat_etc ( tag, m, tok ) ;
1332
	    break ;
1333
	}
1334
	case tok_type_tag : {
1335
	    BASE_TYPE kind = load_btype ( bs ) ;
1336
	    TYPE s = load_type ( bs, NULL_id ) ;
1337
	    TYPE t = NULL_type ;
1338
	    if ( def ) t = load_type ( bs, NULL_id ) ;
1339
	    MAKE_tok_type ( kind, t, tok ) ;
1340
	    COPY_type ( tok_type_alt ( tok ), s ) ;
1341
	    break ;
1342
	}
1343
	case tok_func_tag : {
1344
	    TYPE t = load_type ( bs, NULL_id ) ;
1345
	    if ( !IS_NULL_type ( t ) && IS_type_func ( t ) ) {
1346
		TOKEN proc = load_tok ( bs, 0 ) ;
1347
		IDENTIFIER id = NULL_id ;
1348
		if ( def ) id = load_use ( bs, null_tag ) ;
1349
		MAKE_tok_func ( t, tok ) ;
1350
		COPY_tok ( tok_func_proc ( tok ), proc ) ;
1351
		COPY_id ( tok_func_defn ( tok ), id ) ;
1352
		break ;
1353
	    }
1354
	    SPEC_ERROR () ;
1355
	    break ;
1356
	}
1357
	case tok_member_tag : {
1358
	    TYPE s = load_type ( bs, NULL_id ) ;
1359
	    if ( !IS_NULL_type ( s ) ) {
1360
		TYPE t = load_type ( bs, NULL_id ) ;
1361
		if ( !IS_NULL_type ( t ) ) {
1362
		    OFFSET off = NULL_off ;
1363
		    if ( def ) off = load_off ( bs ) ;
1364
		    MAKE_tok_member ( s, t, off, tok ) ;
1365
		    break ;
1366
		}
1367
	    }
1368
	    SPEC_ERROR () ;
1369
	    break ;
1370
	}
1371
	case tok_class_tag : {
1372
	    TYPE t = load_type ( bs, NULL_id ) ;
1373
	    if ( !IS_NULL_type ( t ) ) {
1374
		TYPE s = load_type ( bs, NULL_id ) ;
1375
		IDENTIFIER id = NULL_id ;
1376
		if ( def ) id = load_use ( bs, null_tag ) ;
1377
		MAKE_tok_class ( t, id, tok ) ;
1378
		COPY_type ( tok_class_alt ( tok ), s ) ;
1379
		break ;
1380
	    }
1381
	    SPEC_ERROR () ;
1382
	    break ;
1383
	}
1384
	case tok_proc_tag : {
1385
	    TOKEN res ;
1386
	    NAMESPACE pns ;
1387
	    int key = lex_identifier ;
1388
	    LIST ( IDENTIFIER ) bids ;
1389
	    LIST ( IDENTIFIER ) pids ;
1390
	    begin_param ( NULL_id ) ;
1391
	    pns = crt_namespace ;
1392
	    bids = load_param_list ( bs, pns, id_token_tag ) ;
1393
	    if ( DE_BOOL ( bs ) ) {
1394
		pids = bids ;
1395
	    } else {
1396
		pids = load_use_list ( bs ) ;
1397
	    }
1398
	    end_param () ;
1399
	    res = load_tok ( bs, def ) ;
1400
	    if ( DE_BOOL ( bs ) ) key = load_lex ( bs ) ;
1401
	    if ( !IS_NULL_tok ( res ) ) {
1402
		MAKE_tok_proc ( res, pns, key, tok ) ;
1403
		tok = cont_proc_token ( tok, bids, pids ) ;
1404
	    } else {
1405
		SPEC_ERROR () ;
1406
	    }
1407
	    break ;
1408
	}
1409
	case tok_templ_tag : {
1410
	    DECL_SPEC ex = load_dspec ( bs ) ;
1411
	    if ( DE_BOOL ( bs ) ) {
1412
		NAMESPACE pns ;
1413
		LIST ( TOKEN ) dargs ;
1414
		LIST ( IDENTIFIER ) pids ;
1415
		pns = make_namespace ( NULL_id, nspace_templ_tag, 0 ) ;
1416
		pids = load_param_list ( bs, pns, id_token_tag ) ;
1417
		set_proc_token ( pids ) ;
1418
		dargs = load_tok_list ( bs, 1 ) ;
1419
		MAKE_tok_templ ( ex, pns, tok ) ;
1420
		COPY_list ( tok_templ_pids ( tok ), pids ) ;
1421
		COPY_list ( tok_templ_dargs ( tok ), dargs ) ;
1422
	    } else {
1423
		MAKE_tok_templ ( ex, NULL_nspace, tok ) ;
1424
	    }
1425
	    break ;
1426
	}
1427
    }
1428
    return ( tok ) ;
1429
}
1430
 
1431
 
1432
/*
1433
    READ AN IDENTIFIER
1434
 
1435
    This routine reads a member of the namespace ns from the bitstream bs.
1436
*/
1437
 
1438
static IDENTIFIER load_id
1439
    PROTO_N ( ( bs, ns ) )
1440
    PROTO_T ( BITSTREAM *bs X NAMESPACE ns )
1441
{
1442
    ulong d ;
1443
    HASHID nm ;
1444
    unsigned n ;
1445
    unsigned tag ;
1446
    DECL_SPEC ds ;
1447
    IDENTIFIER qid ;
1448
    IDENTIFIER *pid ;
1449
    IDENTIFIER id = NULL_id ;
1450
    IDENTIFIER lid = NULL_id ;
1451
 
1452
    /* Read identifier number */
1453
    d = DE_INT ( bs ) ;
1454
    if ( d == 0 ) {
1455
	/* Null identifiers */
1456
	return ( id ) ;
1457
    }
1458
 
1459
    /* Read identifier tag */
1460
    n = DE_BITS ( bs, BITS_id ) ;
1461
    if ( n == 0 ) {
1462
	/* Null identifiers */
1463
	return ( id ) ;
1464
    }
1465
    if ( n > ORDER_id ) {
1466
	SPEC_ERROR () ;
1467
	return ( id ) ;
1468
    }
1469
 
1470
    /* Check previous look-up */
1471
    pid = id_lookup ( d ) ;
1472
    qid = *pid ;
1473
    if ( !IS_NULL_id ( qid ) ) {
1474
	if ( !IS_id_pending ( qid ) ) {
1475
	    SPEC_ERROR () ;
1476
	    qid = NULL_id ;
1477
	}
1478
    }
1479
 
1480
    /* Read identifier independent information */
1481
    nm = load_hashid ( bs, ns ) ;
1482
    if ( IS_NULL_hashid ( nm ) ) {
1483
	SPEC_ERROR () ;
1484
	return ( id ) ;
1485
    }
1486
    tag = n - 1 ;
1487
    ds = load_dspec ( bs ) ;
1488
    load_loc ( bs ) ;
1489
    if ( DE_BOOL ( bs ) ) {
1490
	/* Read alias */
1491
	lid = load_use ( bs, tag ) ;
1492
    }
1493
 
1494
    /* Read identifier dependent information */
1495
    ASSERT ( ORDER_id == 28 ) ;
1496
    switch ( tag ) {
1497
 
1498
	case id_dummy_tag : {
1499
	    id = DEREF_id ( hashid_id ( nm ) ) ;
1500
	    id = underlying_id ( id ) ;
1501
	    break ;
1502
	}
1503
 
1504
	case id_keyword_tag :
1505
	case id_iso_keyword_tag :
1506
	case id_reserved_tag : {
1507
	    int key = load_lex ( bs ) ;
1508
	    id = make_keyword ( nm, key, NULL_id ) ;
1509
	    break ;
1510
	}
1511
 
1512
	case id_builtin_tag : {
1513
	    TYPE r = load_type ( bs, NULL_id ) ;
1514
	    if ( !IS_NULL_type ( r ) ) {
1515
		LIST ( TYPE ) p = load_type_list ( bs ) ;
1516
		MAKE_id_builtin ( nm, ds, ns, crt_loc, r, p, id ) ;
1517
		break ;
1518
	    }
1519
	    SPEC_ERROR () ;
1520
	    break ;
1521
	}
1522
 
1523
	case id_obj_macro_tag : {
1524
	    PPTOKEN *def = load_pptoks ( bs ) ;
1525
	    MAKE_id_obj_macro ( nm, ds, ns, crt_loc, def, id ) ;
1526
	    break ;
1527
	}
1528
 
1529
	case id_func_macro_tag : {
1530
	    PPTOKEN *def = load_pptoks ( bs ) ;
1531
	    LIST ( HASHID ) pars = load_hashid_list ( bs, NULL_nspace ) ;
1532
	    unsigned npars = LENGTH_list ( pars ) ;
1533
	    MAKE_id_func_macro ( nm, ds, ns, crt_loc, def, pars, npars, id ) ;
1534
	    break ;
1535
	}
1536
 
1537
	case id_predicate_tag : {
1538
	    /* NOT YET IMPLEMENTED */
1539
	    MAKE_id_undef ( nm, ds, ns, crt_loc, id ) ;
1540
	    break ;
1541
	}
1542
 
1543
	case id_class_name_tag : {
1544
	    /* Class names */
1545
	    TYPE t = type_error ;
1546
	    MAKE_id_class_name ( nm, ds, ns, crt_loc, t, id ) ;
1547
	    if ( ds & dspec_implicit ) {
1548
		if ( !IS_NULL_id ( lid ) && IS_id_class_name ( lid ) ) {
1549
		    t = DEREF_type ( id_class_name_defn ( lid ) ) ;
1550
		}
1551
	    } else {
1552
		*pid = id ;
1553
		t = load_type ( bs, id ) ;
1554
	    }
1555
	    if ( type_tag ( t ) == type_compound_tag ) {
1556
		COPY_type ( id_class_name_defn ( id ), t ) ;
1557
		break ;
1558
	    }
1559
	    SPEC_ERROR () ;
1560
	    break ;
1561
	}
1562
 
1563
	case id_enum_name_tag : {
1564
	    /* Enumeration names */
1565
	    TYPE t = type_error ;
1566
	    MAKE_id_enum_name ( nm, ds, ns, crt_loc, t, id ) ;
1567
	    t = load_type ( bs, id ) ;
1568
	    if ( type_tag ( t ) == type_enumerate_tag ) {
1569
		COPY_type ( id_enum_name_defn ( id ), t ) ;
1570
		break ;
1571
	    }
1572
	    SPEC_ERROR () ;
1573
	    break ;
1574
	}
1575
 
1576
	case id_class_alias_tag :
1577
	case id_enum_alias_tag :
1578
	case id_type_alias_tag : {
1579
	    /* Type aliases */
1580
	    TYPE t = load_type ( bs, NULL_id ) ;
1581
	    if ( !IS_NULL_type ( t ) ) {
1582
		id = make_typedef ( ns, nm, t, ds ) ;
1583
		if ( TAG_id ( id ) != tag ) SPEC_ERROR () ;
1584
		break ;
1585
	    }
1586
	    SPEC_ERROR () ;
1587
	    break ;
1588
	}
1589
 
1590
	case id_nspace_name_tag : {
1591
	    /* Namespace names */
1592
	    NAMESPACE pns = NULL_nspace ;
1593
	    unsigned ntag = nspace_named_tag ;
1594
	    if ( IS_hashid_anon ( nm ) ) ntag = nspace_unnamed_tag ;
1595
	    MAKE_id_nspace_name ( nm, ds, ns, crt_loc, pns, id ) ;
1596
	    pns = make_namespace ( id, ntag, 50 ) ;
1597
	    COPY_nspace ( id_nspace_name_defn ( id ), pns ) ;
1598
	    break ;
1599
	}
1600
 
1601
	case id_nspace_alias_tag : {
1602
	    /* Namespace aliases */
1603
	    IDENTIFIER nid = load_use ( bs, id_nspace_name_tag ) ;
1604
	    if ( !IS_NULL_id ( nid ) ) {
1605
		NAMESPACE pns = find_namespace ( nid ) ;
1606
		if ( !IS_NULL_nspace ( pns ) ) {
1607
		    MAKE_id_nspace_alias ( nm, ds, ns, crt_loc, pns, id ) ;
1608
		    break ;
1609
		}
1610
	    }
1611
	    SPEC_ERROR () ;
1612
	    break ;
1613
	}
1614
 
1615
	case id_variable_tag :
1616
	case id_parameter_tag :
1617
	case id_stat_member_tag : {
1618
	    TYPE t = load_type ( bs, NULL_id ) ;
1619
	    if ( !IS_NULL_type ( t ) ) {
1620
		MAKE_id_variable_etc ( tag, nm, ds, ns, crt_loc, t, id ) ;
1621
		break ;
1622
	    }
1623
	    SPEC_ERROR () ;
1624
	    break ;
1625
	}
1626
 
1627
	case id_function_tag :
1628
	case id_mem_func_tag :
1629
	case id_stat_mem_func_tag : {
1630
	    TYPE t = load_type ( bs, NULL_id ) ;
1631
	    if ( !IS_NULL_type ( t ) ) {
1632
		MAKE_id_function_etc ( tag, nm, ds, ns, crt_loc, t,
1633
				       NULL_id, id ) ;
1634
		*pid = id ;
1635
		if ( DE_BOOL ( bs ) ) {
1636
		    /* Read function template form */
1637
		    TYPE form = load_type ( bs, NULL_id ) ;
1638
		    COPY_type ( id_function_etc_form ( id ), form ) ;
1639
		}
1640
		break ;
1641
	    }
1642
	    SPEC_ERROR () ;
1643
	    break ;
1644
	}
1645
 
1646
	case id_member_tag : {
1647
	    TYPE t = load_type ( bs, NULL_id ) ;
1648
	    if ( !IS_NULL_type ( t ) ) {
1649
		MAKE_id_member ( nm, ds, ns, crt_loc, t, id ) ;
1650
		break ;
1651
	    }
1652
	    SPEC_ERROR () ;
1653
	    break ;
1654
	}
1655
 
1656
	case id_enumerator_tag : {
1657
	    TYPE t = load_type ( bs, NULL_id ) ;
1658
	    if ( !IS_NULL_type ( t ) ) {
1659
		EXP e = load_exp ( bs, t ) ;
1660
		if ( !IS_NULL_exp ( e ) ) {
1661
		    MAKE_id_enumerator ( nm, ds, ns, crt_loc, t, e, id ) ;
1662
		    break ;
1663
		}
1664
	    }
1665
	    SPEC_ERROR () ;
1666
	    break ;
1667
	}
1668
 
1669
	case id_label_tag :
1670
	case id_weak_param_tag : {
1671
	    /* NOT YET IMPLEMENTED */
1672
	    MAKE_id_undef ( nm, ds, ns, crt_loc, id ) ;
1673
	    break ;
1674
	}
1675
 
1676
	case id_token_tag : {
1677
	    TOKEN tok = load_tok ( bs, 0 ) ;
1678
	    if ( !IS_NULL_tok ( tok ) ) {
1679
		MAKE_id_token ( nm, ds, ns, crt_loc, tok, NULL_id, id ) ;
1680
		COPY_id ( id_token_alt ( id ), id ) ;
1681
		break ;
1682
	    }
1683
	    break ;
1684
	}
1685
 
1686
	case id_ambig_tag : {
1687
	    LIST ( IDENTIFIER ) ids = load_use_list ( bs ) ;
1688
	    int over = DE_BOOL ( bs ) ;
1689
	    MAKE_id_ambig ( nm, ds, ns, crt_loc, ids, over, id ) ;
1690
	    break ;
1691
	}
1692
 
1693
	case id_undef_tag : {
1694
	    MAKE_id_undef ( nm, ds, ns, crt_loc, id ) ;
1695
	    if ( DE_BOOL ( bs ) ) {
1696
		TYPE form = load_type ( bs, NULL_id ) ;
1697
		COPY_type ( id_undef_form ( id ), form ) ;
1698
	    }
1699
	    break ;
1700
	}
1701
 
1702
	case id_pending_tag : {
1703
	    /* This shouldn't happen */
1704
	    SPEC_ERROR () ;
1705
	    break ;
1706
	}
1707
    }
1708
 
1709
    /* Set identifier look up */
1710
    if ( !IS_NULL_id ( id ) ) {
1711
	if ( !IS_NULL_id ( lid ) ) {
1712
	    COPY_id ( id_alias ( id ), lid ) ;
1713
	}
1714
	if ( !IS_NULL_id ( qid ) ) {
1715
	    COPY_id ( id_alias ( qid ), id ) ;
1716
	    ids_pending-- ;
1717
	}
1718
	*pid = id ;
1719
    }
1720
    return ( id ) ;
1721
}
1722
 
1723
 
1724
/*
1725
    READ NAMESPACE MEMBERS
1726
 
1727
    This routine reads the members of a class or namespace and the instances
1728
    of a template class or template function.
1729
*/
1730
 
1731
static void load_members
1732
    PROTO_N ( ( bs, id ) )
1733
    PROTO_T ( BITSTREAM *bs X IDENTIFIER id )
1734
{
1735
    switch ( TAG_id ( id ) ) {
1736
	case id_class_name_tag : {
1737
	    /* Read class members */
1738
	    DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
1739
	    if ( !( ds & dspec_implicit ) ) {
1740
		int templ = 0 ;
1741
		TYPE t = DEREF_type ( id_class_name_defn ( id ) ) ;
1742
		while ( IS_type_templ ( t ) ) {
1743
		    templ = 1 ;
1744
		    t = DEREF_type ( type_templ_defn ( t ) ) ;
1745
		}
1746
		if ( IS_type_compound ( t ) ) {
1747
		    CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
1748
		    NAMESPACE cns = DEREF_nspace ( ctype_member ( ct ) ) ;
1749
		    load_nspace ( bs, cns, 0 ) ;
1750
		    if ( templ ) {
1751
			/* Read template class instances */
1752
			NAMESPACE ns = DEREF_nspace ( id_parent ( id ) ) ;
1753
			load_nspace ( bs, ns, 1 ) ;
1754
		    }
1755
		}
1756
	    }
1757
	    break ;
1758
	}
1759
	case id_nspace_name_tag : {
1760
	    /* Read namespace members */
1761
	    NAMESPACE cns = DEREF_nspace ( id_nspace_name_defn ( id ) ) ;
1762
	    load_nspace ( bs, cns, 0 ) ;
1763
	    break ;
1764
	}
1765
	case id_function_tag :
1766
	case id_mem_func_tag :
1767
	case id_stat_mem_func_tag : {
1768
	    TYPE t = DEREF_type ( id_function_etc_type ( id ) ) ;
1769
	    if ( IS_type_templ ( t ) ) {
1770
		/* Read template function instances */
1771
		NAMESPACE ns = DEREF_nspace ( id_parent ( id ) ) ;
1772
		load_nspace ( bs, ns, 1 ) ;
1773
	    }
1774
	    break ;
1775
	}
1776
    }
1777
    return ;
1778
}
1779
 
1780
 
1781
/*
1782
    READ A LIST OF NAMESPACE MEMBERS
1783
 
1784
    This routine reads the members of the namespace ns from the bitstream
1785
    bs.  The list is terminated by a null identifier.  The routine is
1786
    also used with inst true to read a list of template instances.
1787
*/
1788
 
1789
static void load_nspace
1790
    PROTO_N ( ( bs, ns, inst ) )
1791
    PROTO_T ( BITSTREAM *bs X NAMESPACE ns X int inst )
1792
{
1793
    int v = verbose ;
1794
    for ( ; ; ) {
1795
	/* Read identifier */
1796
	IDENTIFIER id = load_id ( bs, ns ) ;
1797
	if ( IS_NULL_id ( id ) || spec_error ) break ;
1798
	if ( v ) commentary ( id ) ;
1799
 
1800
	/* Set namespace member */
1801
	if ( !IS_NULL_nspace ( ns ) && !inst ) {
1802
	    DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
1803
	    if ( ( ds & dspec_extern ) || IS_nspace_block_etc ( ns ) ) {
1804
		/* External linkage */
1805
		HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
1806
		MEMBER mem = search_member ( ns, nm, 1 ) ;
1807
		IDENTIFIER pid = DEREF_id ( member_id ( mem ) ) ;
1808
		if ( is_tagged_type ( id ) ) {
1809
		    /* Type members */
1810
		    COPY_id ( member_alt ( mem ), id ) ;
1811
		    if ( IS_NULL_id ( pid ) ) {
1812
			COPY_id ( member_id ( mem ), id ) ;
1813
		    }
1814
		} else {
1815
		    /* Non-type members */
1816
		    if ( !IS_NULL_id ( pid ) && IS_id_function_etc ( pid ) ) {
1817
			if ( IS_id_function_etc ( id ) ) {
1818
			    /* Allow for overloaded functions */
1819
			    COPY_id ( id_function_etc_over ( id ), pid ) ;
1820
			}
1821
		    }
1822
		    COPY_id ( member_id ( mem ), id ) ;
1823
		}
1824
	    } else {
1825
		/* Internal linkage */
1826
		LIST ( IDENTIFIER ) ids ;
1827
		ids = DEREF_list ( nspace_named_etc_extra ( ns ) ) ;
1828
		CONS_id ( id, ids, ids ) ;
1829
		COPY_list ( nspace_named_etc_extra ( ns ), ids ) ;
1830
	    }
1831
	}
1832
 
1833
	/* Check for classes, namespaces and templates */
1834
	load_members ( bs, id ) ;
1835
    }
1836
    return ;
1837
}
1838
 
1839
 
1840
/*
1841
    READ A SPEC FILE
1842
 
1843
    This routine reads a spec file from the input file.  It returns zero
1844
    for a legal spec file.  The identifiers are initially read into a
1845
    dummy namespace which is then merged with the existing namespace.
1846
*/
1847
 
1848
int read_spec
1849
    PROTO_Z ()
1850
{
1851
    /* Read file identifier */
1852
    int e = 0 ;
1853
    char buff [20] ;
1854
    CONST char *msg = NULL ;
1855
    NAMESPACE gns = NULL_nspace ;
1856
    BITSTREAM *bs = start_bitstream ( input_file, NULL_gen_ptr ) ;
1857
    unsigned c1 = DE_BITS ( bs, BYTE_SIZE ) ;
1858
    unsigned c2 = DE_BITS ( bs, BYTE_SIZE ) ;
1859
    unsigned c3 = DE_BITS ( bs, BYTE_SIZE ) ;
1860
    unsigned c4 = DE_BITS ( bs, BYTE_SIZE ) ;
1861
    if ( c1 == ascii_T && c2 == ascii_D && c3 == ascii_F && c4 == ascii_K ) {
1862
	unsigned long n1 = DE_INT ( bs ) ;
1863
	unsigned long n2 = DE_INT ( bs ) ;
1864
	unsigned long n3 = DE_INT ( bs ) ;
1865
	DE_ALIGN ( bs ) ;
1866
	if ( n1 == SPEC_major && n2 <= SPEC_minor ) {
1867
	    /* Read main file body */
1868
	    if ( n3 > LANGUAGE_CPP ) {
1869
		msg = "bad source language" ;
1870
		e = 1 ;
1871
	    }
1872
	    if ( e == 0 ) {
1873
		int d = do_dump ;
1874
		do_dump = 0 ;
1875
		spec_error = 0 ;
1876
		gns = make_global_nspace ( "<global>", 50 ) ;
1877
		load_nspace ( bs, gns, 0 ) ;
1878
		if ( ids_pending ) SPEC_ERROR () ;
1879
		crt_class = NULL_ctype ;
1880
		e = spec_error ;
1881
		if ( e == 0 ) {
1882
		    DE_ALIGN ( bs ) ;
1883
		    if ( !de_eof ( bs ) ) {
1884
			msg = "end of file expected" ;
1885
			e = 1 ;
1886
		    }
1887
		} else {
1888
		    sprintf_v ( buff, "code %d", e ) ;
1889
		    msg = buff ;
1890
		}
1891
		do_dump = d ;
1892
	    }
1893
	} else {
1894
	    msg = "bad version number" ;
1895
	    e = 1 ;
1896
	}
1897
    } else {
1898
	msg = "bad magic number" ;
1899
	e = 1 ;
1900
    }
1901
 
1902
    /* Check for errors */
1903
    if ( msg ) fail ( ERR_fail_spec_bad ( input_name, ustrlit ( msg ) ) ) ;
1904
    if ( !output_spec ) e = 1 ;
1905
    xfree_nof ( id_table ) ;
1906
    id_table_size = 0 ;
1907
    id_table = NULL ;
1908
    spec_error = 0 ;
1909
 
1910
    /* Merge read identifiers */
1911
    if ( !IS_NULL_nspace ( gns ) ) {
1912
	merge_namespaces ( global_namespace, gns ) ;
1913
    }
1914
    return ( e ) ;
1915
}