Subversion Repositories tendra.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
7 7u83 2
 * Copyright (c) 2002-2005 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
 */
31
/*
2 7u83 32
    		 Crown Copyright (c) 1997
7 7u83 33
 
2 7u83 34
    This TenDRA(r) Computer Program is subject to Copyright
35
    owned by the United Kingdom Secretary of State for Defence
36
    acting through the Defence Evaluation and Research Agency
37
    (DERA).  It is made available to Recipients with a
38
    royalty-free licence for its use, reproduction, transfer
39
    to other parties and amendment for any purpose not excluding
40
    product development provided that any such use et cetera
41
    shall be deemed to be acceptance of the following conditions:-
7 7u83 42
 
2 7u83 43
        (1) Its Recipients shall ensure that this Notice is
44
        reproduced upon any copies or amended versions of it;
7 7u83 45
 
2 7u83 46
        (2) Any amended version of it shall be clearly marked to
47
        show both the nature of and the organisation responsible
48
        for the relevant amendment or amendments;
7 7u83 49
 
2 7u83 50
        (3) Its onward transfer from a recipient to another
51
        party shall be deemed to be that party's acceptance of
52
        these conditions;
7 7u83 53
 
2 7u83 54
        (4) DERA gives no warranty or assurance as to its
55
        quality or suitability for any purpose and DERA accepts
56
        no liability whatsoever in relation to any use to which
57
        it may be put.
58
*/
59
 
60
 
61
#include "config.h"
62
#include "types.h"
63
#include "basic.h"
64
#include "binding.h"
65
#include "capsule.h"
66
#include "file.h"
67
#include "sort.h"
68
#include "tdf.h"
69
#include "tree.h"
7 7u83 70
#include "unit.h"
2 7u83 71
#include "utility.h"
72
 
73
 
74
/*
75
    CURRENT MAXIMUM LABEL NUMBER
76
 
77
    This gives the number of labels in the current unit.
78
*/
79
 
7 7u83 80
long max_lab_no = 0;
2 7u83 81
 
82
 
83
/*
84
    READ NUMBER OF LABELS
85
 
86
    This routine reads the number of labels in a unit.
87
*/
88
 
7 7u83 89
void
90
read_no_labs(void)
2 7u83 91
{
7 7u83 92
    long n = tdf_int();
93
    if (show_stuff) {
94
	word *w = new_word(HORIZ_NONE);
95
	out_string("label x ");
96
	out_int(n);
97
	end_word(w);
98
	blank_line();
2 7u83 99
    }
7 7u83 100
    max_lab_no = n;
101
    return;
2 7u83 102
}
103
 
104
 
105
/*
106
    SET TOKEN SORTS, CHECKING FOR COMPATIBILITY
107
 
108
    The token t (with number n) is set to have result sort rs and
109
    argument sorts args.  If t has already been initialized these values
110
    are checked against the existing values.  This routine also sets
111
    the foreign field of t.
112
*/
113
 
7 7u83 114
void
115
token_sort(object *t, sortname rs, char *args, long n)
2 7u83 116
{
7 7u83 117
    sortid s;
118
    s = find_sort(rs);
119
    if (s.decode == 'F')is_foreign(t) = 1;
120
    if (args) {
121
	char *p;
122
	for (p = args; *p; p++) {
123
	    if (*p == 'F')is_foreign(t) = 1;
2 7u83 124
	}
125
    }
7 7u83 126
    if (res_sort(t) == sort_unknown) {
127
	sortname is = implicit_sort(t);
128
	if (is != sort_unknown && is != rs) {
129
	    input_error("Token %s inconsistent with previous use",
130
			  object_name(var_token, n));
2 7u83 131
	}
132
    } else {
7 7u83 133
	int good = 1;
134
	if (res_sort(t)!= rs)good = 0;
135
	if (args) {
136
	    if (arg_sorts(t)) {
137
		good = streq(args, arg_sorts(t));
2 7u83 138
	    } else {
7 7u83 139
		good = 0;
2 7u83 140
	    }
141
	} else {
7 7u83 142
	    if (arg_sorts(t))good = 0;
2 7u83 143
	}
7 7u83 144
	if (!good) {
145
	    input_error("Token %s declared inconsistently",
146
			  object_name(var_token, n));
2 7u83 147
	}
148
    }
7 7u83 149
    res_sort(t) = rs;
150
    arg_sorts(t) = args;
151
    return;
2 7u83 152
}
153
 
154
 
155
/*
156
    DECODE A TOKEN DECLARATION
157
 
158
    A single token declaration is decoded.
159
*/
160
 
7 7u83 161
static void
162
de_tokdec_aux(void)
2 7u83 163
{
7 7u83 164
    long t;
165
    sortid s;
166
    object *obj;
167
    char *args = null;
168
    word *w = new_word(HORIZ_NONE);
2 7u83 169
 
170
    /* Find declaration type */
7 7u83 171
    IGNORE de_tokdec();
2 7u83 172
 
173
    /* Find token number */
7 7u83 174
    t = tdf_int();
175
    obj = find_binding(crt_binding, var_token, t);
176
    if (obj == null) {
177
	obj = new_object(var_token);
178
	set_binding(crt_binding, var_token, t, obj);
2 7u83 179
    }
7 7u83 180
    out_object(t, obj, var_token);
181
    out(":");
2 7u83 182
 
183
    /* Deal with signature */
7 7u83 184
    out("[");
185
    decode("?[X]");
186
    out("] :");
2 7u83 187
 
188
    /* Decode token sort */
7 7u83 189
    s = de_sort_name(0);
190
    if (s.res == sort_token) {
191
	long i, m;
192
	s = de_sort_name(1);
193
	check_list();
194
	m = tdf_int();
195
	if (m == 0) {
196
	    out("()");
197
	    args = "";
2 7u83 198
	} else {
7 7u83 199
	    word *wp = new_word(HORIZ_BRACKETS);
200
	    args = alloc_nof(char, m + 1);
201
	    for (i = 0; i < m; i++) {
202
		sortid p;
203
		p = de_sort_name(1);
204
		args[i] = p.decode;
205
		out(p.name);
2 7u83 206
	    }
7 7u83 207
	    args[m] = 0;
208
	    end_word(wp);
2 7u83 209
	}
7 7u83 210
	out_string("->");
2 7u83 211
    }
7 7u83 212
    out(s.name);
213
    end_word(w);
214
    if (obj)token_sort(obj, s.res, args, t);
215
    return;
2 7u83 216
}
217
 
218
 
219
/*
220
    DECODE A TOKEN DEFINITION
221
 
222
    A single token definition is decoded.  If skipping is true then only
223
    the declaration information will be extracted.
224
*/
225
 
7 7u83 226
static void
227
de_tokdef_aux(void)
2 7u83 228
{
7 7u83 229
    long t;
230
    sortid s;
231
    char *args;
232
    object *obj;
233
    long end, m;
234
    word *w = new_word(HORIZ_NONE);
2 7u83 235
 
236
    /* Find definition type */
7 7u83 237
    IGNORE de_tokdef();
2 7u83 238
 
239
    /* Find token number */
7 7u83 240
    t = tdf_int();
241
    obj = find_binding(crt_binding, var_token, t);
242
    if (obj == null) {
243
	obj = new_object(var_token);
244
	set_binding(crt_binding, var_token, t, obj);
2 7u83 245
    }
7 7u83 246
    out_object(t, obj, var_token);
247
    out(":");
2 7u83 248
 
249
    /* Deal with signature */
7 7u83 250
    out("[");
251
    decode("?[X]");
252
    out("] :");
2 7u83 253
 
254
    /* Read definition length and work out end */
7 7u83 255
    end = tdf_int();
256
    end += posn(here);
2 7u83 257
 
258
    /* Find definition type */
7 7u83 259
    IGNORE de_token_defn();
2 7u83 260
 
261
    /* Decode token sort */
7 7u83 262
    s = de_sort_name(1);
263
    check_list();
264
    m = tdf_int();
265
    if (m == 0) {
266
	out("()");
267
	args = "";
2 7u83 268
    } else {
7 7u83 269
	long i;
270
	word *wp = new_word(HORIZ_BRACKETS);
271
	args = alloc_nof(char, m + 1);
272
	for (i = 0; i < m; i++) {
273
	    long pn;
274
	    sortid p;
275
	    object *tp;
276
	    p = de_sort_name(1);
277
	    pn = tdf_int();
278
	    tp = find_binding(crt_binding, var_token, pn);
279
	    if (tp == null) {
280
		tp = new_object(var_token);
281
		set_binding(crt_binding, var_token, pn, tp);
2 7u83 282
	    }
7 7u83 283
	    res_sort(tp) = p.res;
284
	    arg_sorts(tp) = null;
285
	    if (p.res == sort_token) {
286
		object *tpa = alloc_nof(object, 1);
287
		*tpa = *tp;
288
		res_sort(tpa) = p.res;
289
		arg_sorts(tpa) = p.args;
290
		tp->aux = tpa;
2 7u83 291
	    }
7 7u83 292
	    args[i] = p.decode;
293
	    if (!dumb_mode && !(tp->named)) {
294
		tp->named = 1;
295
		tp->name.simple = 1;
296
		tp->name.val.str = alloc_nof(char, 10);
297
		IGNORE sprintf(tp->name.val.str, "~par_%ld", i);
2 7u83 298
	    }
7 7u83 299
	    out_string(p.name);
300
	    out_string(" ");
301
	    out_object(pn, tp, var_token);
2 7u83 302
	}
7 7u83 303
	args[m] = 0;
304
	end_word(wp);
2 7u83 305
    }
7 7u83 306
    out_string("->");
2 7u83 307
 
308
    /* Set result sort */
7 7u83 309
    out(s.name);
310
    end_word(w);
311
    token_sort(obj, s.res, args, t);
2 7u83 312
 
313
    /* Main definition body */
7 7u83 314
    out("Definition :");
315
    if (skipping || is_foreign(obj)) {
316
	long bits = end - posn(here);
317
	out("....");
318
	if (bits < 0) {
319
	    input_error("Token definition size wrong");
2 7u83 320
	} else {
7 7u83 321
	    skip_bits(bits);
2 7u83 322
	}
323
    } else {
7 7u83 324
	char buff[2];
325
	buff[0] = s.decode;
326
	buff[1] = 0;
327
	decode(buff);
328
	if (posn(here)!= end) {
329
	    input_error("Token definition size wrong");
2 7u83 330
	}
331
    }
7 7u83 332
    return;
2 7u83 333
}
334
 
335
 
336
/*
337
    DECODE A TAG DECLARATION
338
 
339
    A single tag declaration is decoded.
340
*/
341
 
7 7u83 342
static void
343
de_tagdec_aux(void)
2 7u83 344
{
7 7u83 345
    long t;
346
    char m;
347
    word *wa;
348
    object *obj;
349
    word *w = new_word(HORIZ_NONE);
2 7u83 350
 
351
    /* Find declaration type */
7 7u83 352
    long n = de_tagdec();
2 7u83 353
 
354
    /* Get tag number */
7 7u83 355
    t = tdf_int();
356
    obj = find_binding(crt_binding, var_tag, t);
357
    if (obj == null) {
358
	obj = new_object(var_tag);
359
	set_binding(crt_binding, var_tag, t, obj);
2 7u83 360
    }
7 7u83 361
    out_object(t, obj, var_tag);
2 7u83 362
 
363
    /* Check consistency */
7 7u83 364
    switch (n) {
365
	case tagdec_make_var_tagdec: out("(variable)"); m = 0; break;
366
	case tagdec_make_id_tagdec: out("(identity)"); m = 1; break;
367
	default : out("(common)"); m = 2; break;
2 7u83 368
    }
7 7u83 369
    if (obj) {
370
	if (var(obj)!= m && var(obj)!= 3) {
371
	    string s = object_name(var_tag, t);
372
	    input_error("Tag %s declared inconsistently", s);
2 7u83 373
	}
7 7u83 374
	var(obj) = m;
2 7u83 375
    }
376
 
377
    /* Decode declaration body */
7 7u83 378
    wa = new_word(VERT_NONE);
379
    format(HORIZ_NONE, "has access : ", "?[u]");
380
    format(HORIZ_NONE, " and signature : ", "?[X]");
381
    format(HORIZ_NONE, " and shape : ", "S");
382
    end_word(wa);
383
    end_word(w);
384
    return;
2 7u83 385
}
386
 
387
 
388
/*
389
    DECODE A TAG DEFINITION
390
 
391
    A single tag definition is decoded.
392
*/
393
 
7 7u83 394
static void
395
de_tagdef_aux(void)
2 7u83 396
{
7 7u83 397
    long t;
398
    char m;
399
    object *obj;
400
    word *w = new_word(HORIZ_NONE);
2 7u83 401
 
402
    /* Find definition type */
7 7u83 403
    long n = de_tagdef();
2 7u83 404
 
405
    /* Get tag number */
7 7u83 406
    t = tdf_int();
407
    obj = find_binding(crt_binding, var_tag, t);
408
    if (obj == null) {
409
	input_error("Tag %s defined but not declared",
410
		      object_name(var_tag, t));
411
	obj = new_object(var_tag);
412
	set_binding(crt_binding, var_tag, t, obj);
2 7u83 413
    }
7 7u83 414
    out_object(t, obj, var_tag);
2 7u83 415
 
416
    /* Check consistency */
7 7u83 417
    switch (n) {
418
	case tagdef_make_var_tagdef: out("(variable)"); m = 0; break;
419
	case tagdef_make_id_tagdef: out("(identity)"); m = 1; break;
420
	default : out("(common)"); m = 2; break;
2 7u83 421
    }
7 7u83 422
    if (obj) {
423
	if (var(obj)!= m && var(obj)!= 3) {
424
	    input_error("Tag %s declared inconsistently",
425
			  object_name(var_tag, t));
2 7u83 426
	}
7 7u83 427
	var(obj) = m;
2 7u83 428
    }
429
 
430
    /* Decode definition body */
7 7u83 431
    out("is :");
432
    end_word(w);
433
    if (m != 1) format(HORIZ_NONE, "access : ", "?[u]");
434
    format(HORIZ_NONE, "signature : ", "?[X]");
435
    IGNORE de_exp();
436
    return;
2 7u83 437
}
438
 
439
 
440
/*
441
    DECODE AN ALIGNMENT TAG DEFINITION
442
 
443
    A single alignment tag definition is decoded.
444
*/
445
 
7 7u83 446
static void
447
de_al_tagdef_aux(void)
2 7u83 448
{
7 7u83 449
    long t;
450
    object *obj;
451
    word *w = new_word(HORIZ_NONE);
2 7u83 452
 
453
    /* Find definition type */
7 7u83 454
    IGNORE de_al_tagdef();
2 7u83 455
 
456
    /* Get alignment tag number */
7 7u83 457
    t = tdf_int();
458
    obj = find_binding(crt_binding, var_al_tag, t);
459
    if (obj == null) {
460
	obj = new_object(var_al_tag);
461
	set_binding(crt_binding, var_al_tag, t, obj);
2 7u83 462
    }
7 7u83 463
    out_object(t, obj, var_al_tag);
2 7u83 464
 
465
    /* Decode alignment body */
7 7u83 466
    out("is :");
467
    end_word(w);
468
    IGNORE de_alignment();
469
    return;
2 7u83 470
}
471
 
472
 
473
/*
474
    DECODE A TOKEN DECLARATION UNIT
475
 
476
    This routine decodes a list of token declarations.
477
*/
478
 
7 7u83 479
void
480
de_tokdec_props(void)
2 7u83 481
{
7 7u83 482
    long i;
483
    long n = tdf_int();
484
    for (i = 0; i < n; i++) {
485
	de_tokdec_aux();
486
	blank_lines = 0;
2 7u83 487
    }
7 7u83 488
    total += n;
489
    return;
2 7u83 490
}
491
 
492
 
493
/*
494
    DECODE A TOKEN DEFINITION UNIT
495
 
496
    This routine decodes a list of token definitions.
497
*/
498
 
7 7u83 499
void
500
de_tokdef_props(void)
2 7u83 501
{
7 7u83 502
    long i, n;
503
    read_no_labs();
504
    n = tdf_int();
505
    for (i = 0; i < n; i++) {
506
	de_tokdef_aux();
507
	blank_line();
508
	blank_lines = 1;
2 7u83 509
    }
7 7u83 510
    total += n;
511
    return;
2 7u83 512
}
513
 
514
 
515
/*
516
    DECODE A TAG DECLARATION UNIT
517
 
518
    This routine decodes a list of tag declarations.
519
*/
520
 
7 7u83 521
void
522
de_tagdec_props(void)
2 7u83 523
{
7 7u83 524
    long i, n;
525
    read_no_labs();
526
    n = tdf_int();
527
    for (i = 0; i < n; i++) {
528
	de_tagdec_aux();
529
	blank_line();
530
	blank_lines = 1;
2 7u83 531
    }
7 7u83 532
    total += n;
533
    return;
2 7u83 534
}
535
 
536
 
537
/*
538
    DECODE A TAG DEFINITION UNIT
539
 
540
    This routine decodes a list of tag definitions.
541
*/
542
 
7 7u83 543
void
544
de_tagdef_props(void)
2 7u83 545
{
7 7u83 546
    long i, n;
547
    read_no_labs();
548
    n = tdf_int();
549
    for (i = 0; i < n; i++) {
550
	de_tagdef_aux();
551
	blank_line();
552
	blank_lines = 1;
2 7u83 553
    }
7 7u83 554
    total += n;
555
    return;
2 7u83 556
}
557
 
558
 
559
/*
560
    DECODE AN ALIGNMENT TAG DEFINITION UNIT
561
 
562
    This routine decodes a list of alignment tag definitions.
563
*/
564
 
7 7u83 565
void
566
de_al_tagdef_props(void)
2 7u83 567
{
7 7u83 568
    long i, n;
569
    read_no_labs();
570
    n = tdf_int();
571
    for (i = 0; i < n; i++) {
572
	de_al_tagdef_aux();
573
	blank_line();
574
	blank_lines = 1;
2 7u83 575
    }
7 7u83 576
    total += n;
577
    return;
2 7u83 578
}
579
 
580
 
581
/*
582
    FLAGS FOR LINKER INFORMATION AND DIAGNOSTICS
583
 
584
    These flags control the output of the various non-core units.
585
*/
586
 
7 7u83 587
int show_usage = 0;
588
int diagnostics = 0;
589
int versions = 1;
2 7u83 590
 
591
 
592
/*
593
    OUTPUT USAGE INFORMATION
594
 
595
    Given a usage n this routine outputs the corresponding usage
596
    information.
597
*/
598
 
7 7u83 599
static void
600
out_usage(long n)
2 7u83 601
{
7 7u83 602
    static char *usage_info[] = {
2 7u83 603
	"used", "declared", "defined", "multiply-defined"
7 7u83 604
    };
605
    int i;
606
    int used = 0;
607
    word *w = new_word(HORIZ_BRACKETS);
608
    for (i = 0; i < 4; i++) {
609
	if (n & (1 << i)) {
610
	    out(usage_info[i]);
611
	    used = 1;
2 7u83 612
	}
613
    }
7 7u83 614
    if (!used)out("unused");
615
    end_word(w);
616
    return;
2 7u83 617
}
618
 
619
 
620
/*
621
    DECODE USAGE INFORMATION
622
 
623
    This routine decodes the usage information for the external variables
624
    of type v.  This consists of a set of usage values in 1-1 correspondence
625
    with the externally named objects of this type.
626
*/
627
 
7 7u83 628
static void
629
de_usage(long v)
2 7u83 630
{
7 7u83 631
    object **p;
632
    long i, n;
633
    binding *b;
634
    long total_ext = 0, max_ext = -1;
635
    if (v < 0 || v >= no_variables) return;
636
    b = crt_binding + v;
637
    n = b->sz;
638
    if (n == 0) return;
639
    p = alloc_nof(object *, n);
640
    for (i = 0; i < n; i++) {
641
	object *q = b->table[i];
642
	long rank = (q ? q->order : -1);
643
	if (rank != -1 && b->table[i]->named) {
644
	    p[rank] = b->table[i];
645
	    if (rank >= max_ext)max_ext = rank;
646
	    total_ext++;
2 7u83 647
	}
648
    }
7 7u83 649
    if (total_ext != max_ext + 1) {
650
	input_error("Usage information wrong");
651
	return;
2 7u83 652
    }
7 7u83 653
    if (total_ext) {
654
	out_string(var_types[v]);
655
	out(" Usage Information");
656
	blank_line();
657
	for (i = 0; i < total_ext; i++) {
658
	    long use = tdf_int();
659
	    word *w = new_word(HORIZ_NONE);
660
	    if (p[i]->name.simple) {
661
		out(p[i]->name.val.str);
2 7u83 662
	    } else {
7 7u83 663
		out_unique(p[i]->name.val.uniq);
2 7u83 664
	    }
7 7u83 665
	    out_usage(use);
666
	    end_word(w);
2 7u83 667
	}
7 7u83 668
	blank_line();
669
	blank_line();
670
	blank_lines = 2;
671
	total += total_ext;
2 7u83 672
    }
7 7u83 673
    free(p);
674
    return;
2 7u83 675
}
676
 
677
 
678
/*
679
    DECODE LINKER INFORMATION
680
 
681
    This routine decodes the linker information (tld2) units.  These are
682
    used to give the linker information on the usage of tokens and tags.
683
*/
684
 
7 7u83 685
void
686
de_tld2_unit(void)
2 7u83 687
{
7 7u83 688
    de_usage(var_token);
689
    de_usage(var_tag);
690
    return;
2 7u83 691
}
692
 
693
 
694
/*
695
    DECODE LINKER INFORMATION - NEW VERSION
696
 
697
    This routine decodes the linker information (tld) units.  These are
698
    used to give the linker information on the usage of the externally
699
    named objects.
700
*/
701
 
7 7u83 702
void
703
de_tld_unit(void)
2 7u83 704
{
7 7u83 705
    long n = tdf_int();
706
    switch (n) {
707
	case 0: {
708
	    de_tld2_unit();
709
	    break;
2 7u83 710
	}
7 7u83 711
	case 1: {
712
	    long v;
713
	    for (v = 0; v < no_variables; v++)de_usage(v);
714
	    break;
2 7u83 715
	}
716
	default : {
7 7u83 717
	    input_error("Illegal TLD version number %ld", n);
718
	    break;
2 7u83 719
	}
720
    }
7 7u83 721
    return;
2 7u83 722
}
723
 
724
 
725
/*
726
    DECODE A DIAGNOSTIC TAG DEFINITION
727
 
728
    This routine decodes a single diagnostic tag definition.
729
*/
730
 
731
#ifdef HAVE_diag_type_unit
732
 
7 7u83 733
static void
734
de_diag_tagdef_aux(void)
2 7u83 735
{
7 7u83 736
    long t;
737
    object *obj;
738
    word *w = new_word(HORIZ_NONE);
739
    IGNORE de_diag_tagdef();
2 7u83 740
 
741
    /* Get alignment tag number */
7 7u83 742
    t = tdf_int();
743
    obj = find_binding(crt_binding, var_diag_tag, t);
744
    if (obj == null) {
745
	obj = new_object(var_diag_tag);
746
	set_binding(crt_binding, var_diag_tag, t, obj);
2 7u83 747
    }
7 7u83 748
    out_object(t, obj, var_diag_tag);
2 7u83 749
 
750
    /* Decode body */
7 7u83 751
    out("is :");
752
    end_word(w);
753
    IGNORE de_diag_type();
754
    return;
2 7u83 755
}
756
 
757
#endif
758
 
759
 
760
/*
761
    DECODE DIAGNOSTIC TYPE INFORMATION
762
 
763
    This routine decodes a diagnostic type unit.
764
*/
765
 
766
#ifdef HAVE_diag_type_unit
767
 
7 7u83 768
void
769
de_diag_type_unit(void)
2 7u83 770
{
7 7u83 771
    long i, n;
772
    read_no_labs();
773
    n = tdf_int();
774
    for (i = 0; i < n; i++) {
775
	de_diag_tagdef_aux();
776
	blank_line();
777
	blank_lines = 1;
2 7u83 778
    }
7 7u83 779
    total += n;
780
    return;
2 7u83 781
}
782
 
783
#endif
784
 
785
 
786
/*
787
    DECODE DIAGNOSTIC INFORMATION
788
 
789
    This routine decodes a diagnostic unit.
790
*/
791
 
792
#ifdef HAVE_diag_unit
793
 
7 7u83 794
void
795
de_diag_unit(void)
2 7u83 796
{
7 7u83 797
    long i, n;
798
    read_no_labs();
799
    n = tdf_int();
800
    for (i = 0; i < n; i++) {
801
	IGNORE de_diag_descriptor();
802
	blank_line();
803
	blank_lines = 1;
2 7u83 804
    }
7 7u83 805
    total += n;
806
    return;
2 7u83 807
}
808
 
809
#endif
810
 
811
 
812
/*
813
    DECODE NEW DIAGNOSTIC INFORMATION
814
 
815
    This routine decodes a new diagnostic unit.
816
*/
817
 
818
#ifdef HAVE_dg_comp_props
819
 
7 7u83 820
void
821
de_dg_comp_props(void)
2 7u83 822
{
7 7u83 823
    long i, n;
824
    read_no_labs();
825
    IGNORE de_dg_compilation();
826
    blank_line();
827
    blank_lines = 1;
828
    n = tdf_int();
829
    for (i = 0; i < n; i++) {
830
	IGNORE de_dg_append();
831
	blank_line();
832
	blank_lines = 1;
2 7u83 833
    }
7 7u83 834
    total += (n + 1);
835
    return;
2 7u83 836
}
837
 
838
#endif
839
 
840
 
841
/*
842
    DECODE LINKING INFORMATION
843
 
844
    This routine decode a linkage information unit.
845
*/
846
 
847
#ifdef HAVE_linkinfo_props
848
 
7 7u83 849
void
850
de_linkinfo_props(void)
2 7u83 851
{
7 7u83 852
    long i, n;
853
    read_no_labs();
854
    n = tdf_int();
855
    for (i = 0; i < n; i++) {
856
	IGNORE de_linkinfo();
857
	blank_line();
858
	blank_lines = 1;
2 7u83 859
    }
7 7u83 860
    total += n;
861
    return;
2 7u83 862
}
863
 
864
#endif
865
 
866
 
867
/*
868
    PREVIOUS VERSION NUMBER
869
 
870
    These variables are used to store the last version number read so
871
    that duplicate version numbers can be suppressed.
872
*/
873
 
7 7u83 874
static long last_major = -1;
875
static long last_minor = -1;
2 7u83 876
 
877
 
878
/*
879
    DECODE A VERSION NUMBER
880
 
881
    This routine decodes a version number for an s construct.
882
*/
883
 
7 7u83 884
void
885
de_make_version(char *s)
2 7u83 886
{
7 7u83 887
    long v1 = tdf_int();
888
    long v2 = tdf_int();
889
    if (v1 != last_major || v2 != last_minor || dumb_mode) {
890
	word *w;
891
	out_string(s);
892
	w = new_word(HORIZ_BRACKETS);
893
	out_int(v1);
894
	out_int(v2);
895
	end_word(w);
896
	last_major = v1;
897
	last_minor = v2;
2 7u83 898
    }
7 7u83 899
    if (v1 != version_major || v2 > version_minor) {
900
	input_error(
2 7u83 901
	    "Illegal version number, %ld.%ld (supported version is %d.%d)",
7 7u83 902
	    v1, v2, version_major, version_minor);
2 7u83 903
    }
7 7u83 904
    return;
2 7u83 905
}
906
 
907
 
908
/*
909
    DECODE A VERSION UNIT
910
 
911
    This routine decodes a list of version numbers.
912
*/
913
 
914
#ifdef HAVE_version_props
915
 
7 7u83 916
void
917
de_version_props(void)
2 7u83 918
{
7 7u83 919
    long i, n;
920
    n = tdf_int();
921
    for (i = 0; i < n; i++) {
922
	IGNORE de_version();
923
	blank_lines = 0;
2 7u83 924
    }
7 7u83 925
    total += n;
926
    return;
2 7u83 927
}
928
 
929
#endif
930
 
931
 
932
/*
933
    DECODE A MAGIC NUMBER
934
 
935
    This routine reads the magic number s.
936
*/
937
 
7 7u83 938
void
939
de_magic(char *s)
2 7u83 940
{
7 7u83 941
    int i, n = (int)strlen(s);
942
    for (i = 0; i < n; i++) {
943
	long c = fetch(8);
944
	if (c != (long)s[i]) {
945
	    input_error("Bad magic number, %s expected", s);
946
	    exit(EXIT_FAILURE);
2 7u83 947
	}
948
    }
7 7u83 949
    de_make_version(s);
950
    last_major = -1;
951
    last_minor = -1;
952
    byte_align();
953
    return;
2 7u83 954
}