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
33
 
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:-
42
 
43
        (1) Its Recipients shall ensure that this Notice is
44
        reproduced upon any copies or amended versions of it;
45
 
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;
49
 
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;
53
 
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
/**********************************************************************
62
$Author: release $
63
$Date: 1998/01/17 15:55:45 $
64
$Revision: 1.1.1.1 $
65
$Log: read_fns.c,v $
66
 * Revision 1.1.1.1  1998/01/17  15:55:45  release
67
 * First version to be checked into rolling release.
68
 *
69
 * Revision 1.16  1998/01/09  09:24:58  pwe
70
 * correct for dg_tags local to tagdef unit
71
 *
72
 * Revision 1.15  1997/12/04  19:49:59  pwe
73
 * ANDF-DE V1.9
74
 *
75
 * Revision 1.14  1997/11/04  18:30:02  pwe
76
 * ANDF-DE V1.8
77
 *
78
 * Revision 1.13  1997/08/23  13:30:47  pwe
79
 * no invert order, and initial ANDF-DE
80
 *
81
 * Revision 1.12  1996/10/21  08:54:10  currie
82
 * long_jump_access
83
 *
84
Revision 1.11  1996/06/17 15:30:45  currie
85
tok signatures
86
 
87
Revision 1.10  1996/06/04 15:40:52  currie
88
minor bug with repeated defs
89
 
90
Revision 1.9  1996/05/17 10:57:32  currie
91
signature bug
92
 
93
 * Revision 1.8  1995/10/11  17:09:17  currie
94
 * transfer token
95
 *
96
 * Revision 1.7  1995/09/27  12:39:49  currie
97
 * Peters PIC code
98
 *
99
 * Revision 1.6  1995/09/15  13:28:09  currie
100
 * add_prefix
101
 *
102
 * Revision 1.5  1995/09/11  15:36:20  currie
103
 * gcc pedantry
104
 *
105
 * Revision 1.4  1995/06/22  09:21:10  currie
106
 * Signatures on tokens
107
 *
108
 * Revision 1.3  1995/06/08  14:55:27  currie
109
 * changes inherited from v3
110
 *
111
 * Revision 1.2  1995/05/05  08:12:13  currie
112
 * initial_value + signtures
113
 *
114
 * Revision 1.1  1995/04/06  10:43:34  currie
115
 * Initial revision
116
 *
117
***********************************************************************/
118
 
119
 
120
 
121
 
122
/* this file contains the definitions of some of the functions
123
   called from decoder.c to set up the in-store representations of TDF.
124
   It defines those functions which are independent of the actual
125
   representation, particularly the token substitution and
126
   unit handling
127
*/
128
 
129
 
130
#include "config.h"
131
#include "common_types.h"
132
#include "basicread.h"
133
#include "toktypes.h"
134
#include "exp.h"
135
#include "expmacs.h"
136
#include "main_reads.h"
137
#include "tags.h"
138
#include "flags.h"
139
#include "me_fns.h"
140
#include "installglob.h"
141
#include "readglob.h"
142
#include "table_fns.h"
143
#include "flpttypes.h"
144
#include "flpt.h"
145
#include "xalloc.h"
146
#include "shapemacs.h"
147
#include "read_fns.h"
148
#include "sortmacs.h"
149
#include "machine.h"
150
#include "spec.h"
151
#include "check.h"
152
#include "aldefs.h"
153
#include "externs.h"
154
#include "diag_fns.h"	/* OLD DIAGS */
155
#include "dg_fns.h"	/* NEW DIAGS */
156
#include "messages_r.h"
157
#include "natmacs.h"
158
 
159
 
160
/* Some external declarations  */
161
 
7 7u83 162
extern diag_type_unit f_make_diagtype_unit(void);	/* OLD DIAGS */
163
extern int f_make_linkinfo_unit(void);
164
extern void start_make_linkinfo_unit(int, int, int, int);
165
extern int machine_toks(char *);
166
extern void tidy_initial_values(void);
2 7u83 167
 
168
/* MACROS */
169
 
170
    /* codes for the types of unit which are understood here */
7 7u83 171
#define UNKNOWN_UNIT	 0
172
#define TOKDEC_UNIT	 1
173
#define TOKDEF_UNIT	 2
174
#define AL_UNIT		 3
175
#define TAGDEC_UNIT	 4
176
#define TAGDEF_UNIT	 5
177
#define DIAGDEF_UNIT	 6	/* OLD DIAGS */
178
#define DIAGTYPE_UNIT	 7	/* OLD DIAGS */
179
#define LINKINFO_UNIT	 8
180
#define VERSIONS_UNIT	 9
181
#define DGCOMP_UNIT	10	/* NEW DIAGS */
2 7u83 182
 
183
  /* codes for the kinds of linkable variable which are understood here */
7 7u83 184
#define UNKNOWN_TYPE	0
185
#define TOK_TYPE	1
186
#define TAG_TYPE	2
187
#define AL_TYPE		3
188
#define DIAGTAG_TYPE	4	/* OLD DIAGS */
189
#define DGTAG_TYPE	5	/* NEW DIAGS */
2 7u83 190
 
191
/* VARIABLES */
192
/* All variables are initialised, jmf */
193
 
7 7u83 194
int crt_group_type;		/* the code for the current group of units */
195
int crt_links_type;		/* the code for the current type of linkable
196
				   variable */
197
int crt_extern_link_type;	/* the code for the current type of externally
198
				   linked variable */
199
tdfstring *crt_capsule_groups;	/* the identifier for the current group
200
				   of units */
201
int crt_capsule_group_no;	/* the number in the group */
202
int crt_capsule_link_no;	/* the number of linkable variables
203
				   of the current type */
2 7u83 204
capsule_link_list crt_capsule_linking;
205
 
206
static int no_of_local_tokens;
207
 
208
 
209
 
210
/* PROCEDURES */
211
 
212
  /* translates the name of a group of units into  its code */
7 7u83 213
int
214
group_type(char *s)
2 7u83 215
{
7 7u83 216
  if (!strcmp(s, "tokdec")) {
2 7u83 217
    return TOKDEC_UNIT;
7 7u83 218
  }
219
  if (!strcmp(s, "tokdef")) {
2 7u83 220
    return TOKDEF_UNIT;
7 7u83 221
  }
222
  if (!strcmp(s, "aldef")) {
2 7u83 223
    return AL_UNIT;
7 7u83 224
  }
225
  if (!strcmp(s, "tagdec")) {
2 7u83 226
    return TAGDEC_UNIT;
7 7u83 227
  }
228
  if (!strcmp(s, "tagdef")) {
2 7u83 229
    return TAGDEF_UNIT;
7 7u83 230
  }
231
  if (!strcmp(s, "diagdef")) {		/* OLD DIAGS */
2 7u83 232
    return DIAGDEF_UNIT;
7 7u83 233
  }
234
  if (!strcmp(s, "diagtype")) {		/* OLD DIAGS */
2 7u83 235
    return DIAGTYPE_UNIT;
7 7u83 236
  }
237
  if (!strcmp(s, "linkinfo")) {
2 7u83 238
    return LINKINFO_UNIT;
7 7u83 239
  }
240
  if (!strcmp(s, "versions")) {
2 7u83 241
    return VERSIONS_UNIT;
7 7u83 242
  }
243
  if (!strcmp(s, "dgcompunit")) {	/* NEW DIAGS */
2 7u83 244
    return DGCOMP_UNIT;
7 7u83 245
  }
2 7u83 246
  return UNKNOWN_UNIT;
247
}
248
 
249
  /* translates the name of a kind of linkable variable into its code */
7 7u83 250
int
251
links_type(char *s)
2 7u83 252
{
7 7u83 253
  if (!strcmp(s, "token")) {
2 7u83 254
    return TOK_TYPE;
7 7u83 255
  }
256
  if (!strcmp(s, "tag")) {
2 7u83 257
    return TAG_TYPE;
7 7u83 258
  }
259
  if (!strcmp(s, "alignment")) {
2 7u83 260
    return AL_TYPE;
7 7u83 261
  }
262
  if (!strcmp(s, "diagtag")) {		/* OLD DIAGS */
2 7u83 263
    return DIAGTAG_TYPE;
7 7u83 264
  }
265
  if (!strcmp(s, "dgtag")) {		/* NEW DIAGS */
2 7u83 266
    return DGTAG_TYPE;
7 7u83 267
  }
2 7u83 268
  return UNKNOWN_TYPE;
269
}
270
 
7 7u83 271
char *
272
external_to_string(external ext)
2 7u83 273
{
7 7u83 274
	char *res;
2 7u83 275
	int n, i, l;
7 7u83 276
	tdfstring *t;
2 7u83 277
	if (ext.isstring) {
7 7u83 278
		return (char *)ext.ex.id.ints.chars;
2 7u83 279
	}
280
	else {
281
		n = ext.ex.u.number;
282
		t = ext.ex.u.elems;
283
		l=n;
7 7u83 284
		for (i = 0; i < n; i++) {
285
			l += t[i].number *(t[i].size / 8);
286
		}
287
		res = (char *)xcalloc(l + 1, sizeof(char));
2 7u83 288
		l = 0;
7 7u83 289
		for (i = 0; i < n; i++) {
290
			IGNORE(strcpy(res + l, t[i].ints.chars));
291
			l += t[i].number * (t[i].size / 8);
2 7u83 292
			res[l++] = 'U';
293
		}
294
		return res;
295
	}
296
}
297
 
298
 
7 7u83 299
char *
300
make_local_name(void)
2 7u83 301
{
7 7u83 302
  /* invent a local label identifier */
2 7u83 303
  char *id;
7 7u83 304
  char *st = intchars(next_lab());
305
  int   l = (int)strlen(st);
2 7u83 306
  int lpl = (int)strlen(local_prefix);
7 7u83 307
  id = (char *)xcalloc(l + lpl + 1, sizeof(char));
2 7u83 308
  IGNORE strcpy(id, local_prefix);
309
  IGNORE strcpy(&id[lpl], st);
310
  return id;
311
}
312
 
7 7u83 313
static void
314
check_tok_sig(tok_define *t, string sig)
2 7u83 315
{
7 7u83 316
	char *sid = sig.ints.chars;
317
	int s = (sig.size * sig.number) / 8;
2 7u83 318
	if (t->signature != (char*)0) {
7 7u83 319
		char *id = t->signature;
320
		int i;
321
		for (i = 0; i < s; i++) {
322
			if (id[i] != sid[i])break;
2 7u83 323
		}
7 7u83 324
		if (i !=s || id[s] != 0) {
325
			IGNORE fprintf(stderr, "%s\n%s\n", id, sid);
326
			failer("Token signatures should be equal");
2 7u83 327
		}
7 7u83 328
	} else {
2 7u83 329
		t->signature = sid;
330
	}
331
}
332
 
7 7u83 333
/* all the _apply_token functions follow this pattern */
334
procprops
335
f_procprops_apply_token(token token_value, bitstream token_args)
2 7u83 336
{
337
   tokval v;
7 7u83 338
   v = apply_tok(token_value, token_args, PROCPROPS,(tokval *)0);
2 7u83 339
   return v.tk_procprops;
340
}
341
 
7 7u83 342
/* all the _cond functions follow this pattern */
343
procprops
344
f_procprops_cond(exp control, bitstream e1, bitstream e2)
2 7u83 345
{
346
  bitstream bs;
347
  procprops res;
348
  int n;
349
  bs = keep_place();
350
 
7 7u83 351
  /* the control must evaluate to a constant */
352
  if (name(control) != val_tag) {
2 7u83 353
    failer(CONTROL_EXP);
7 7u83 354
  }
2 7u83 355
  n = no(control);
356
  retcell(control);
7 7u83 357
  if (n == 0) {
358
     /* use the second bitstream */
2 7u83 359
     set_place(e2);
360
     res = d_procprops();
7 7u83 361
  } else {
362
     /* use the first bitstream */
2 7u83 363
     set_place(e1);
364
     res = d_procprops();
7 7u83 365
  }
2 7u83 366
 set_place(bs);
367
 return res;
368
}
369
 
7 7u83 370
string
371
f_string_apply_token(token token_value, bitstream token_args)
2 7u83 372
{
373
   tokval v;
7 7u83 374
   v = apply_tok(token_value, token_args, STRING,(tokval *)0);
2 7u83 375
   return v.tk_string;
376
}
377
 
7 7u83 378
/* all the _cond functions follow this pattern */
379
string
380
f_string_cond(exp control, bitstream e1, bitstream e2)
2 7u83 381
{
382
  bitstream bs;
383
  string res;
384
  int n;
385
  bs = keep_place();
386
 
7 7u83 387
  /* the control must evaluate to a constant */
388
  if (name(control) != val_tag) {
2 7u83 389
    failer(CONTROL_EXP);
7 7u83 390
  }
2 7u83 391
  n = no(control);
392
  retcell(control);
7 7u83 393
  if (n == 0) {
394
    /* use the second bitstream */
395
    set_place(e2);
396
    res = d_string();
397
  } else {
398
    /* use the first bitstream */
399
    set_place(e1);
400
    res = d_string();
401
  }
402
  set_place(bs);
403
  return res;
2 7u83 404
}
405
 
406
 
7 7u83 407
alignment
408
f_alignment_apply_token(token token_value, bitstream token_args)
2 7u83 409
{
7 7u83 410
  tokval v;
411
  v = apply_tok(token_value, token_args, ALIGNMENT_SORT,(tokval *)0);
412
  return v.tk_alignment;
2 7u83 413
}
414
 
7 7u83 415
/* all the _cond functions follow this pattern */
416
alignment
417
f_alignment_cond(exp control, bitstream e1, bitstream e2)
2 7u83 418
{
419
  bitstream bs;
420
  alignment res;
421
  int n;
422
  bs = keep_place();
423
 
7 7u83 424
  /* the control must evaluate to a constant */
425
  if (name(control) != val_tag) {
2 7u83 426
    failer(CONTROL_EXP);
7 7u83 427
  }
2 7u83 428
  n = no(control);
429
  retcell(control);
7 7u83 430
  if (n == 0) {
431
    /* use the second bitstream */
432
    set_place(e2);
433
    res = d_alignment();
434
  } else {
435
    /* use the first bitstream */
436
    set_place(e1);
437
    res = d_alignment();
438
  }
439
  set_place(bs);
440
  return res;
2 7u83 441
}
442
 
7 7u83 443
access
444
f_access_apply_token(token token_value, bitstream token_args)
2 7u83 445
{
7 7u83 446
  tokval v;
447
  v = apply_tok(token_value, token_args, ACCESS_SORT,(tokval *)0);
448
  return v.tk_access;
2 7u83 449
}
450
 
451
 
7 7u83 452
access
453
f_access_cond(exp control, bitstream e1, bitstream e2)
2 7u83 454
{
455
  bitstream bs;
456
  access res;
457
  int n;
458
  bs = keep_place();
459
 
7 7u83 460
  /* the control must evaluate to a constant */
461
  if (name(control) != val_tag) {
2 7u83 462
    failer(CONTROL_EXP);
7 7u83 463
  }
2 7u83 464
  n = no(control);
465
  retcell(control);
7 7u83 466
  if (n == 0) {
467
    /* use the second bitstream */
468
    set_place(e2);
469
    res = d_access();
470
  } else {
471
    /* use the first bitstream */
472
    set_place(e1);
473
    res = d_access();
474
  }
475
  set_place(bs);
476
  return res;
2 7u83 477
}
478
 
7 7u83 479
transfer_mode
480
f_transfer_mode_apply_token(token token_value, bitstream token_args)
2 7u83 481
{
482
   tokval v;
7 7u83 483
   v = apply_tok(token_value, token_args, TRANSFER_MODE_SORT,(tokval *)0);
2 7u83 484
   return v.tk_transfer_mode;
485
}
486
 
487
 
7 7u83 488
transfer_mode
489
f_transfer_mode_cond(exp control, bitstream e1, bitstream e2)
2 7u83 490
{
491
  bitstream bs;
492
  transfer_mode res;
493
  int n;
494
  bs = keep_place();
495
 
7 7u83 496
  /* the control must evaluate to a constant */
497
  if (name(control) != val_tag) {
2 7u83 498
    failer(CONTROL_EXP);
7 7u83 499
  }
2 7u83 500
  n = no(control);
501
  retcell(control);
7 7u83 502
  if (n == 0) {
503
    /* use the second bitstream */
504
    set_place(e2);
505
    res = d_transfer_mode();
506
  } else {
507
    /* use the first bitstream */
508
    set_place(e1);
509
    res = d_transfer_mode();
510
  }
511
  set_place(bs);
512
  return res;
2 7u83 513
}
514
 
515
 
7 7u83 516
bitfield_variety
517
f_bfvar_apply_token(token token_value, bitstream token_args)
2 7u83 518
{
519
   tokval v;
7 7u83 520
   v = apply_tok(token_value, token_args, BITFIELD_VARIETY,(tokval*)0);
2 7u83 521
   return v.tk_bitfield_variety;
522
}
523
 
7 7u83 524
bitfield_variety
525
f_bfvar_cond(exp control, bitstream e1, bitstream e2)
2 7u83 526
{
527
  bitstream bs;
528
  bitfield_variety res;
529
  int n;
530
  bs = keep_place();
7 7u83 531
  if (name(control) != val_tag) {
2 7u83 532
    failer(CONTROL_EXP);
7 7u83 533
  }
2 7u83 534
  n = no(control);
535
  retcell(control);
7 7u83 536
  if (n == 0) {
537
    set_place(e2);
538
    res = d_bitfield_variety();
539
  } else {
540
    set_place(e1);
541
    res = d_bitfield_variety();
542
  }
543
  set_place(bs);
544
  return res;
2 7u83 545
}
546
 
7 7u83 547
bool
548
f_bool_apply_token
549
(token token_value, bitstream token_args)
2 7u83 550
{
551
   tokval v;
7 7u83 552
   v = apply_tok(token_value, token_args, BOOL,(tokval *)0);
2 7u83 553
   return v.tk_bool;
554
}
555
 
7 7u83 556
bool
557
f_bool_cond(exp control, bitstream e1, bitstream e2)
2 7u83 558
{
559
  bitstream bs;
560
  bool res;
561
  int n;
562
  bs = keep_place();
7 7u83 563
  if (name(control) != val_tag) {
2 7u83 564
    failer(CONTROL_EXP);
7 7u83 565
  }
2 7u83 566
  n = no(control);
567
  retcell(control);
7 7u83 568
  if (n == 0) {
569
    set_place(e2);
570
    res = d_bool();
571
  } else {
572
    set_place(e1);
573
    res = d_bool();
574
  }
575
  set_place(bs);
576
  return res;
2 7u83 577
}
578
 
579
 
7 7u83 580
/* locate the index number of the linkable variable */
581
int
582
find_index
583
(char *nm)
2 7u83 584
{
585
  int i;
7 7u83 586
  for (i = 0; i < crt_capsule_linking.number; ++i) {
587
    if (!strcmp((crt_capsule_linking.members[i]).id, nm)) {
588
      return i;
589
    }
590
  }
2 7u83 591
  return -1;
592
}
593
 
594
 
7 7u83 595
void
596
start_make_capsule
597
(tdfstring_list prop_names, capsule_link_list capsule_linking)
2 7u83 598
{
599
  int i;
600
 
601
  while (capsule_freelist) {
602
    capsule_frees * cf = capsule_freelist -> next;
603
    xfree((void*)capsule_freelist->ptr);
604
    xfree((void*)capsule_freelist);
605
    capsule_freelist = cf;
7 7u83 606
  }
2 7u83 607
 
608
  crt_tagdef_unit_no = -1;
609
  unit_index = 0;
610
  top_aldef = (aldef *)0;
611
  doing_aldefs = 0;
612
 
613
  crt_capsule_groups = prop_names.elems;
614
  crt_capsule_group_no = prop_names.number;
615
 
616
  crt_capsule_linking = capsule_linking;
617
  crt_capsule_link_no = capsule_linking.number;
618
 
619
  i = find_index("token");
7 7u83 620
  capsule_no_of_tokens = (i == -1) ? 0 : natint((capsule_linking.members[i]).n);
2 7u83 621
 
622
  i = find_index("tag");
7 7u83 623
  capsule_no_of_tags = (i == -1) ? 0 : natint((capsule_linking.members[i]).n);
2 7u83 624
 
625
  i = find_index("alignment");
7 7u83 626
  capsule_no_of_als = (i == -1) ? 0 : natint((capsule_linking.members[i]).n);
2 7u83 627
 
628
  i = find_index("diagtag");		/* OLD DIAGS */
629
  capsule_no_of_diagtags = (i == -1) ? 0 :
7 7u83 630
      natint((capsule_linking.members[i]).n);
2 7u83 631
 
632
  i = find_index("dgtag");		/* NEW DIAGS */
7 7u83 633
  capsule_no_of_dgtags = (i == -1) ? 0 : natint((capsule_linking.members[i]).n);
2 7u83 634
 
7 7u83 635
  capsule_toktab = (tok_define *)xcalloc(capsule_no_of_tokens,
636
					 sizeof(tok_define));
637
  capsule_tagtab = (dec *)xcalloc(capsule_no_of_tags, sizeof(dec));
638
  capsule_altab = (aldef *)xcalloc(capsule_no_of_als, sizeof(aldef));
639
  capsule_diag_tagtab = (diag_tagdef *)xcalloc(capsule_no_of_diagtags,
640
					       sizeof(diag_tagdef));	 
641
  /* OLD DIAGS */
642
  capsule_dgtab = (dgtag_struct *)xcalloc(capsule_no_of_dgtags,
643
					 sizeof(dgtag_struct));	/* NEW DIAGS */
2 7u83 644
 
645
  for (i = 0; i < capsule_no_of_tokens; ++i) {
7 7u83 646
     /* initialise the table of tokens */
647
    tok_define *tp = &capsule_toktab[i];
648
    tp->tok_special = 0;
649
    tp->valpresent = 0;
650
    tp->unit_number = crt_tagdef_unit_no;
651
    tp->defined = 0;
652
    tp->tok_index = i;
653
    tp->is_capsule_token = 1;
654
    tp->recursive = 0;
655
  }
2 7u83 656
 
657
  for (i = 0; i < capsule_no_of_tags; ++i) {
7 7u83 658
    /* initialise the table of tags */
659
    dec *dp = &capsule_tagtab[i];
660
    dp->dec_u.dec_val.dec_outermost = 0;
661
    dp->dec_u.dec_val.dec_id = (char *)0;
662
    dp->dec_u.dec_val.extnamed = 0;
663
    dp->dec_u.dec_val.diag_info = (diag_global *)0;
664
    dp->dec_u.dec_val.have_def = 0;
665
    dp->dec_u.dec_val.dec_shape = nilexp;
666
    dp->dec_u.dec_val.processed = 0;
667
    dp->dec_u.dec_val.isweak = 0;
668
  }
2 7u83 669
 
670
  for (i = 0; i < capsule_no_of_als; ++i) {
7 7u83 671
    /* initialise the table of alignment tags */
672
    aldef *ap = &capsule_altab[i];
673
    ap->al.al_n = 0;
674
  }
2 7u83 675
 
676
  init_capsule_diagtags();	/* OLD DIAGS */
677
  init_capsule_dgtags();	/* NEW DIAGS */
678
 
679
  return;
680
}
681
 
7 7u83 682
capsule
683
f_make_capsule(tdfstring_list prop_names, capsule_link_list capsule_linking,
684
	       extern_link_list external_linkage, unit_list units)
2 7u83 685
{
7 7u83 686
  UNUSED(prop_names);
687
  UNUSED(capsule_linking);
688
  UNUSED(external_linkage);
689
  UNUSED(units);
2 7u83 690
 
691
  translate_capsule();
692
  return 0;
693
}
694
 
7 7u83 695
void
696
init_capsule(void)
2 7u83 697
{
698
  return;
699
}
700
 
7 7u83 701
capsule_link
702
f_make_capsule_link(tdfstring sn, tdfint n)
2 7u83 703
{
704
  capsule_link res;
705
  res.n = n;
7 7u83 706
  res.id = (char *)sn.ints.chars;
2 7u83 707
  return res;
708
}
709
 
7 7u83 710
error_treatment
711
f_errt_apply_token(token token_value, bitstream token_args)
2 7u83 712
{
713
   tokval v;
7 7u83 714
   v = apply_tok(token_value, token_args, ERROR_TREATMENT,(tokval *)0);
2 7u83 715
   return v.tk_error_treatment;
716
}
717
 
7 7u83 718
error_treatment
719
f_errt_cond(exp control, bitstream e1, bitstream e2)
2 7u83 720
{
721
  bitstream bs;
722
  error_treatment res;
723
  int n;
724
  bs = keep_place();
7 7u83 725
  if (name(control) != val_tag) {
2 7u83 726
    failer(CONTROL_EXP);
7 7u83 727
  }
2 7u83 728
  n = no(control);
729
  retcell(control);
7 7u83 730
  if (n==0) {
2 7u83 731
     set_place(e2);
732
     res = d_error_treatment();
7 7u83 733
  } else {
2 7u83 734
     set_place(e1);
735
     res = d_error_treatment();
7 7u83 736
  }
737
  set_place(bs);
738
  return res;
2 7u83 739
}
740
 
741
 
7 7u83 742
exp
743
f_exp_apply_token(token token_value, bitstream token_args)
2 7u83 744
{
745
   tokval v;
7 7u83 746
   v = apply_tok(token_value, token_args, EXP_S,(tokval *)0);
2 7u83 747
   return v.tk_exp;
748
}
749
 
7 7u83 750
exp
751
f_exp_cond(exp control, bitstream e1, bitstream e2)
2 7u83 752
{
753
  bitstream bs;
754
  exp res;
755
  int n;
756
  bs = keep_place();
7 7u83 757
  if (name(control) != val_tag) {
2 7u83 758
    failer(CONTROL_EXP);
7 7u83 759
  }
2 7u83 760
  n = no(control);
761
  retcell(control);
7 7u83 762
  if (n==0) {
2 7u83 763
     set_place(e2);
764
     res = d_exp();
7 7u83 765
  } else {
2 7u83 766
     set_place(e1);
767
     res = d_exp();
7 7u83 768
  }
769
  set_place(bs);
770
  return res;
2 7u83 771
}
772
 
7 7u83 773
external
774
f_string_extern(tdfstring s)
2 7u83 775
{
776
  external e;
777
  e.isstring = 1;
778
  e.ex.id = s;
779
  return e;
780
}
781
 
7 7u83 782
external
783
f_unique_extern(unique u)
2 7u83 784
{
785
  external e;
786
  e.isstring = 0;
787
  e.ex.u = u;
788
  return e;
789
}
790
 
7 7u83 791
external
792
f_chain_extern(tdfstring s, tdfint i)
2 7u83 793
{
7 7u83 794
	UNUSED(s);
795
	UNUSED(i);
2 7u83 796
	failer("chain_extern not yet done");
797
	return f_dummy_external;
798
}
799
 
7 7u83 800
void
801
init_external(void)
2 7u83 802
{
803
  return;
804
}
805
 
806
external f_dummy_external;
807
 
7 7u83 808
floating_variety
809
f_flvar_apply_token(token token_value, bitstream token_args)
2 7u83 810
{
811
   tokval v;
7 7u83 812
   v = apply_tok(token_value, token_args, FLOATING_VARIETY,(tokval *)0);
2 7u83 813
   return v.tk_floating_variety;
814
}
815
 
7 7u83 816
floating_variety
817
f_flvar_cond(exp control, bitstream e1, bitstream e2)
2 7u83 818
{
819
  bitstream bs;
820
  floating_variety res;
821
  int n;
822
  bs = keep_place();
7 7u83 823
  if (name(control) != val_tag) {
2 7u83 824
    failer(CONTROL_EXP);
7 7u83 825
  }
2 7u83 826
  n = no(control);
827
  retcell(control);
7 7u83 828
  if (n == 0) {
2 7u83 829
     set_place(e2);
830
     res = d_floating_variety();
7 7u83 831
  } else {
2 7u83 832
     set_place(e1);
833
     res = d_floating_variety();
7 7u83 834
  }
835
  set_place(bs);
836
  return res;
2 7u83 837
}
838
 
839
 
7 7u83 840
label
841
f_label_apply_token(token token_value, bitstream token_args)
2 7u83 842
{
843
   tokval v;
7 7u83 844
   v = apply_tok(token_value, token_args, LABEL,(tokval *)0);
2 7u83 845
   return v.tk_label;
846
}
847
 
7 7u83 848
label
849
f_make_label(tdfint labelno)
2 7u83 850
{
851
  return &unit_labtab[natint(labelno)];
852
}
853
 
7 7u83 854
void
855
init_label(void)
2 7u83 856
{
857
  return;
858
}
859
 
860
label f_dummy_label;
861
 
7 7u83 862
nat
863
f_nat_apply_token(token token_value, bitstream token_args)
2 7u83 864
{
865
   tokval v;
7 7u83 866
   v = apply_tok(token_value, token_args, NAT, (tokval *)0);
2 7u83 867
   return v.tk_nat;
868
}
869
 
7 7u83 870
nat
871
f_nat_cond(exp control, bitstream e1, bitstream e2)
2 7u83 872
{
873
  bitstream bs;
874
  nat res;
875
  int n;
876
  bs = keep_place();
7 7u83 877
  if (name(control) != val_tag) {
2 7u83 878
    failer(CONTROL_EXP);
7 7u83 879
  }
2 7u83 880
  n = no(control);
881
  retcell(control);
7 7u83 882
  if (n == 0) {
2 7u83 883
     set_place(e2);
884
     res = d_nat();
7 7u83 885
  } else {
2 7u83 886
     set_place(e1);
887
     res = d_nat();
7 7u83 888
  }
889
  set_place(bs);
890
  return res;
2 7u83 891
}
892
 
7 7u83 893
ntest
894
f_ntest_apply_token(token token_value, bitstream token_args)
2 7u83 895
{
896
   tokval v;
7 7u83 897
   v = apply_tok(token_value, token_args, NTEST, (tokval *)0);
2 7u83 898
   return v.tk_ntest;
899
}
900
 
7 7u83 901
ntest
902
f_ntest_cond(exp control, bitstream e1, bitstream e2)
2 7u83 903
{
904
  bitstream bs;
905
  ntest res;
906
  int n;
907
  bs = keep_place();
7 7u83 908
  if (name(control) != val_tag) {
2 7u83 909
    failer(CONTROL_EXP);
7 7u83 910
  }
2 7u83 911
  n = no(control);
912
  retcell(control);
7 7u83 913
  if (n == 0) {
2 7u83 914
     set_place(e2);
915
     res = d_ntest();
7 7u83 916
  } else {
2 7u83 917
     set_place(e1);
918
     res = d_ntest();
7 7u83 919
  }
920
  set_place(bs);
921
  return res;
2 7u83 922
}
923
 
7 7u83 924
rounding_mode
925
f_rounding_mode_apply_token(token token_value, bitstream token_args)
2 7u83 926
{
927
   tokval v;
7 7u83 928
   v = apply_tok(token_value, token_args, ROUNDING_MODE, (tokval *)0);
2 7u83 929
   return v.tk_rounding_mode;
930
}
931
 
7 7u83 932
rounding_mode
933
f_rounding_mode_cond(exp control, bitstream e1, bitstream e2)
2 7u83 934
{
935
  bitstream bs;
936
  rounding_mode res;
937
  int n;
938
  bs = keep_place();
939
  if (name(control) != val_tag)
940
    failer(CONTROL_EXP);
941
  n = no(control);
942
  retcell(control);
7 7u83 943
  if (n == 0) {
2 7u83 944
     set_place(e2);
945
     res = d_rounding_mode();
7 7u83 946
  } else {
2 7u83 947
     set_place(e1);
948
     res = d_rounding_mode();
7 7u83 949
  }
950
  set_place(bs);
951
  return res;
2 7u83 952
}
953
 
7 7u83 954
shape
955
f_shape_apply_token(token token_value, bitstream token_args)
2 7u83 956
{
957
   tokval v;
7 7u83 958
   v = apply_tok(token_value, token_args, SHAPE, (tokval *)0);
2 7u83 959
   return v.tk_shape;
960
}
961
 
7 7u83 962
shape
963
f_shape_cond(exp control, bitstream e1, bitstream e2)
2 7u83 964
{
965
  bitstream bs;
966
  shape res;
967
  int n;
968
  bs = keep_place();
7 7u83 969
  if (name(control) != val_tag) {
2 7u83 970
    failer(CONTROL_EXP);
7 7u83 971
  }
2 7u83 972
  n = no(control);
973
  retcell(control);
7 7u83 974
  if (n == 0) {
2 7u83 975
     set_place(e2);
976
     res = d_shape();
7 7u83 977
  } else {
2 7u83 978
     set_place(e1);
979
     res = d_shape();
7 7u83 980
  }
981
  set_place(bs);
982
  return res;
2 7u83 983
}
984
 
7 7u83 985
signed_nat
986
f_signed_nat_apply_token(token token_value, bitstream token_args)
2 7u83 987
{
988
   tokval v;
7 7u83 989
   v = apply_tok(token_value, token_args, SIGNED_NAT, (tokval *)0);
2 7u83 990
   return v.tk_signed_nat;
991
}
992
 
7 7u83 993
signed_nat
994
f_signed_nat_cond(exp control, bitstream e1, bitstream e2)
2 7u83 995
{
996
  bitstream bs;
997
  signed_nat res;
998
  int n;
999
  bs = keep_place();
7 7u83 1000
  if (name(control) != val_tag) {
2 7u83 1001
    failer(CONTROL_EXP);
7 7u83 1002
  }
2 7u83 1003
  n = no(control);
1004
  retcell(control);
7 7u83 1005
  if (n == 0) {
2 7u83 1006
     set_place(e2);
1007
     res = d_signed_nat();
7 7u83 1008
  } else {
2 7u83 1009
     set_place(e1);
1010
     res = d_signed_nat();
7 7u83 1011
  }
1012
  set_place(bs);
1013
  return res;
2 7u83 1014
 
1015
}
1016
 
1017
 
1018
sortname f_alignment_sort;
1019
sortname f_bitfield_variety;
1020
sortname f_bool;
1021
sortname f_error_treatment;
1022
sortname f_exp;
1023
sortname f_floating_variety;
1024
sortname f_label;
1025
sortname f_nat;
1026
sortname f_ntest;
1027
sortname f_rounding_mode;
1028
sortname f_shape;
1029
sortname f_signed_nat;
1030
sortname f_tag;
1031
sortname f_al_tag;
1032
sortname f_diag_filename;	/* OLD DIAGS */
1033
sortname f_diag_type;		/* OLD DIAGS */
1034
sortname f_foreign;
1035
sortname f_access;
1036
sortname f_transfer_mode;
1037
sortname f_procprops;
1038
sortname f_string;
1039
sortname f_dg;			/* NEW DIAGS */
1040
sortname f_dg_dim;		/* NEW DIAGS */
1041
sortname f_dg_filename;		/* NEW DIAGS */
1042
sortname f_dg_idname;		/* NEW DIAGS */
1043
sortname f_dg_name;		/* NEW DIAGS */
1044
sortname f_dg_type;		/* NEW DIAGS */
1045
 
7 7u83 1046
sortname
1047
f_foreign_sort(tdfstring foreign_name)
2 7u83 1048
{
7 7u83 1049
  if (!strcmp(foreign_name.ints.chars, "~diag_file")) {	/* OLD DIAGS */
2 7u83 1050
    return f_diag_filename;
7 7u83 1051
  }
1052
  if (!strcmp(foreign_name.ints.chars, "~diag_type")) {	/* OLD DIAGS */
2 7u83 1053
    return f_diag_type;
7 7u83 1054
  }
1055
  if (!strcmp(foreign_name.ints.chars, "DG")) {		/* NEW DIAGS */
2 7u83 1056
    return f_dg;
7 7u83 1057
  }
1058
  if (!strcmp(foreign_name.ints.chars, "DG_DIM")) {	/* NEW DIAGS */
2 7u83 1059
    return f_dg_dim;
7 7u83 1060
  }
1061
  if (!strcmp(foreign_name.ints.chars, "DG_FILENAME")) {/* NEW DIAGS */
2 7u83 1062
    return f_dg_filename;
7 7u83 1063
  }
1064
  if (!strcmp(foreign_name.ints.chars, "DG_IDNAME")) {	/* NEW DIAGS */
2 7u83 1065
    return f_dg_idname;
7 7u83 1066
  }
1067
  if (!strcmp(foreign_name.ints.chars, "DG_NAME")) {	/* NEW DIAGS */
2 7u83 1068
    return f_dg_name;
7 7u83 1069
  }
1070
  if (!strcmp(foreign_name.ints.chars, "DG_TYPE")) {	/* NEW DIAGS */
2 7u83 1071
    return f_dg_type;
7 7u83 1072
  }
2 7u83 1073
  return f_foreign;
1074
}
1075
 
7 7u83 1076
sortname
1077
f_token(sortname result, sortname_list params)
2 7u83 1078
{
1079
   sortname res;
1080
   res.code = TOKEN;
1081
   res.result = result.code;
1082
   res.pars = params;
1083
   return res;
1084
}
1085
 
1086
sortname f_variety;
7 7u83 1087
void
1088
init_sortname(void)
2 7u83 1089
{
1090
   f_alignment_sort.code = ALIGNMENT_SORT;
7 7u83 1091
   f_bitfield_variety.code = BITFIELD_VARIETY;
1092
   f_bool.code = BOOL;
1093
   f_error_treatment.code = ERROR_TREATMENT;
1094
   f_exp.code = EXP_S;
1095
   f_floating_variety.code = FLOATING_VARIETY;
2 7u83 1096
   f_label.code = LABEL;
7 7u83 1097
   f_nat.code = NAT;
1098
   f_ntest.code = NTEST;
1099
   f_rounding_mode.code = ROUNDING_MODE;
1100
   f_shape.code = SHAPE;
1101
   f_signed_nat.code = SIGNED_NAT;
2 7u83 1102
   f_tag.code = TAG;
1103
   f_al_tag.code = AL_TAG;
1104
   f_variety.code = VARIETY;
1105
   f_diag_filename.code = DIAG_FILENAME;	/* OLD DIAGS */
1106
   f_diag_type.code = DIAG_TYPE_SORT;		/* OLD DIAGS */
1107
   f_foreign.code = FOREIGN;
1108
   f_access.code = ACCESS_SORT;
1109
   f_transfer_mode.code = TRANSFER_MODE_SORT;
1110
   f_procprops.code = PROCPROPS;
1111
   f_string.code = STRING;
1112
   f_dg.code = DG_SORT;				/* NEW DIAGS */
1113
   f_dg_dim.code = DG_DIM_SORT;			/* NEW DIAGS */
1114
   f_dg_filename.code = DG_FILENAME_SORT;	/* NEW DIAGS */
1115
   f_dg_idname.code = DG_IDNAME_SORT;		/* NEW DIAGS */
1116
   f_dg_name.code = DG_NAME_SORT;		/* NEW DIAGS */
1117
   f_dg_type.code = DG_TYPE_SORT;		/* NEW DIAGS */
1118
 
1119
   return;
1120
}
1121
 
1122
sortname f_dummy_sortname;
1123
 
7 7u83 1124
tag
1125
f_tag_apply_token(token token_value, bitstream token_args)
2 7u83 1126
{
1127
   tokval v;
7 7u83 1128
   v = apply_tok(token_value, token_args, TAG, (tokval *)0);
2 7u83 1129
   return v.tk_tag;
1130
}
1131
 
7 7u83 1132
al_tag
1133
f_al_tag_apply_token(token token_value, bitstream token_args)
2 7u83 1134
{
1135
   tokval v;
7 7u83 1136
   v = apply_tok(token_value, token_args, AL_TAG, (tokval *)0);
2 7u83 1137
   return v.tk_al_tag;
1138
}
1139
 
7 7u83 1140
tag
1141
f_make_tag(tdfint tagno)
2 7u83 1142
{
1143
  return get_dec(natint(tagno));
1144
}
1145
 
7 7u83 1146
void
1147
init_tag(void)
2 7u83 1148
{
1149
  return;
1150
}
1151
 
7 7u83 1152
al_tag
1153
f_make_al_tag(tdfint tagno)
2 7u83 1154
{
1155
  return get_aldef(natint(tagno));
1156
}
1157
 
7 7u83 1158
void
1159
init_al_tag(void)
2 7u83 1160
{
1161
  return;
1162
}
1163
 
1164
tag f_dummy_tag;
1165
al_tag f_dummy_al_tag;
1166
 
7 7u83 1167
void
1168
check_sig(tag tg, string sig)
2 7u83 1169
{
7 7u83 1170
	char *sid = sig.ints.chars;
1171
	int s = (sig.size * sig.number) / 8;
2 7u83 1172
	if (tg->dec_u.dec_val.has_signature) {
7 7u83 1173
		char *id = tg->dec_u.dec_val.dec_id;
2 7u83 1174
	    	int i;
7 7u83 1175
		for (i = 0; i < s; i++) {
1176
			if (id[i] != sid[i]) {
1177
				break;
1178
			}
2 7u83 1179
		}
7 7u83 1180
		if (i != s || id[s] != 0) {
2 7u83 1181
			   IGNORE fprintf(stderr, "%s\n%s\n", id, sid);
1182
			   failer("Signatures should be equal");
1183
		}
7 7u83 1184
	} else {
2 7u83 1185
		tg->dec_u.dec_val.dec_id = sid;
1186
		tg->dec_u.dec_val.has_signature = 1;
1187
	}
1188
}
1189
 
1190
 
1191
 
1192
 
1193
 
7 7u83 1194
tagdec
1195
f_make_id_tagdec(tdfint t_intro, access_option acc, string_option sig, shape x)
2 7u83 1196
{
1197
  tagdec res;
1198
  res.tg = get_dec(natint(t_intro));
1199
  res.sha = x;
1200
  res.acc = acc;
1201
  res.is_variable = 0;
1202
  res.is_common = 0;
7 7u83 1203
  res.tg->dec_u.dec_val.is_common = 0;
1204
  if (sig.present) {
1205
    check_sig(res.tg, sig.val);
1206
  }
2 7u83 1207
  return res;
1208
}
1209
 
7 7u83 1210
tagdec
1211
f_make_var_tagdec(tdfint t_intro, access_option acc, string_option sig, shape x)
2 7u83 1212
{
1213
  tagdec res;
1214
  res.tg = get_dec(natint(t_intro));
1215
  res.sha = x;
1216
  res.acc = acc;
1217
  res.is_variable = 1;
1218
  res.is_common = 0;
7 7u83 1219
  res.tg->dec_u.dec_val.is_common = 0;
1220
  if (sig.present) {
1221
    check_sig(res.tg, sig.val);
1222
  }
2 7u83 1223
  return res;
1224
}
1225
 
7 7u83 1226
tagdec
1227
f_common_tagdec(tdfint t_intro, access_option acc, string_option sig, shape x)
2 7u83 1228
{
1229
  tagdec res;
1230
  res.tg = get_dec(natint(t_intro));
1231
  res.sha = x;
1232
  res.acc = acc;
1233
  res.is_variable = 1;
1234
  res.is_common = 1;
7 7u83 1235
  res.tg->dec_u.dec_val.is_common = 0;
1236
  if (sig.present) {
1237
    check_sig(res.tg, sig.val);
1238
  }
2 7u83 1239
  return res;
1240
}
1241
 
7 7u83 1242
void
1243
init_tagdec(void)
2 7u83 1244
{
1245
  return;
1246
}
1247
 
1248
tagdec f_dummy_tagdec;
1249
 
1250
 
7 7u83 1251
void
1252
start_make_id_tagdef(tdfint t)
2 7u83 1253
{
1254
  UNUSED(t);
1255
  rep_make_proc = 0;
1256
  return;
1257
}
1258
 
7 7u83 1259
tagdef
1260
f_make_id_tagdef(tdfint t, string_option sig, exp e)
2 7u83 1261
{
7 7u83 1262
  dec *dp = get_dec(natint(t));
2 7u83 1263
  tagdef res;
1264
  res.tg = dp;
7 7u83 1265
  if (dp->dec_u.dec_val.processed ||
1266
      son(dp->dec_u.dec_val.dec_exp) != nilexp) {
2 7u83 1267
    res.def = nilexp; /* set to nilexp if already output */
7 7u83 1268
  } else {
2 7u83 1269
    res.def = e;
7 7u83 1270
  }
2 7u83 1271
  res.var = 0;
1272
  res.is_common = 0;
7 7u83 1273
  if (sig.present) {
1274
    check_sig(dp, sig.val);
1275
  }
2 7u83 1276
  rep_make_proc = 1;
1277
  return res;
1278
}
1279
 
7 7u83 1280
void
1281
start_make_var_tagdef(tdfint t)
2 7u83 1282
{
1283
  UNUSED(t);
1284
 
1285
  return;
1286
}
1287
 
7 7u83 1288
tagdef
1289
f_make_var_tagdef(tdfint t, access_option opt_access, string_option sig, exp e)
2 7u83 1290
{
7 7u83 1291
  dec *dp = get_dec(natint(t));
2 7u83 1292
  tagdef res;
1293
  UNUSED(opt_access);
1294
  res.tg = dp;
7 7u83 1295
  if (dp->dec_u.dec_val.processed ||
1296
      son(dp->dec_u.dec_val.dec_exp) != nilexp) {
2 7u83 1297
    res.def = nilexp; /* set to nilexp if already output */
7 7u83 1298
  } else {
2 7u83 1299
    res.def = e;
7 7u83 1300
  }
2 7u83 1301
  res.var = 1;
1302
  res.is_common = 0;
7 7u83 1303
  if (sig.present) {
1304
    check_sig(dp, sig.val);
1305
  }
2 7u83 1306
  return res;
1307
}
1308
 
7 7u83 1309
void
1310
start_common_tagdef(tdfint t)
2 7u83 1311
{
1312
  UNUSED(t);
1313
  return;
1314
}
1315
 
7 7u83 1316
tagdef
1317
f_common_tagdef(tdfint t, access_option opt_access, string_option sig, exp e)
2 7u83 1318
{
7 7u83 1319
  dec *dp = get_dec(natint(t));
2 7u83 1320
  tagdef res;
1321
  UNUSED(opt_access);
1322
  res.tg = dp;
1323
  res.def = e;
1324
  res.var = 1;
1325
  res.is_common = 1;
7 7u83 1326
  if (sig.present) {
1327
    check_sig(dp, sig.val);
1328
  }
2 7u83 1329
  return res;
1330
}
1331
 
7 7u83 1332
void
1333
init_tagdef(void)
2 7u83 1334
{
1335
  return;
1336
}
1337
 
7 7u83 1338
void
1339
init_al_tagdef(void)
2 7u83 1340
{
1341
  return;
1342
}
1343
 
1344
tagdef f_dummy_tagdef;
1345
al_tagdef f_dummy_al_tagdef;
1346
 
7 7u83 1347
char *
1348
add_prefix(char *nm)
2 7u83 1349
{
7 7u83 1350
  char *id;
2 7u83 1351
  int idl = (int)strlen(nm);
7 7u83 1352
  int j;
2 7u83 1353
  int npl = (int)strlen(name_prefix);
7 7u83 1354
  if (npl == 0) {
1355
    return nm;
1356
  }
1357
  id = (char *)xcalloc((idl + npl + 1), sizeof(char));
2 7u83 1358
  id[idl + npl] = 0;
7 7u83 1359
  for (j = npl; j < (idl + npl); ++j) {
1360
    id[j] = nm[j - npl];
1361
  }
1362
  for (j = 0; j < npl; ++j) {
2 7u83 1363
    id[j] = name_prefix[j];
7 7u83 1364
  }
2 7u83 1365
  return id;
1366
}
1367
 
7 7u83 1368
tagextern
1369
f_make_tagextern(tdfint internal, external ext)
2 7u83 1370
{
7 7u83 1371
  dec *dp = &capsule_tagtab[natint(internal)];
2 7u83 1372
  char *nm = external_to_string(ext);
7 7u83 1373
  char *id = add_prefix(nm);
1374
  dp->dec_u.dec_val.dec_id = id;
1375
  dp->dec_u.dec_val.dec_outermost = 1;
1376
  dp->dec_u.dec_val.extnamed = 1;
2 7u83 1377
 
1378
  return 0;
1379
}
1380
 
7 7u83 1381
taglink
1382
f_make_taglink(tdfint internal, tdfint ext)
2 7u83 1383
{
7 7u83 1384
  unit_ind_tags[natint(internal)] = &capsule_tagtab[natint(ext)];
2 7u83 1385
  return 0;
1386
}
1387
 
1388
 
7 7u83 1389
allink
1390
f_make_allink(tdfint internal, tdfint ext)
2 7u83 1391
{
7 7u83 1392
  unit_ind_als[natint(internal)] = &capsule_altab[natint(ext)];
2 7u83 1393
  return 0;
1394
}
1395
 
1396
 
7 7u83 1397
tokdec
1398
f_make_tokdec(tdfint tok, string_option sig, sortname s)
2 7u83 1399
{
7 7u83 1400
  tok_define *tok_d = get_tok(natint(tok));
1401
  if (sig.present) {
1402
    check_tok_sig(tok_d, sig.val);
1403
  }
2 7u83 1404
  UNUSED(s);
1405
  return 0;
1406
}
1407
 
7 7u83 1408
void
1409
init_tokdec(void)
2 7u83 1410
{
1411
  return;
1412
}
1413
 
1414
tokdec f_dummy_tokdec;
1415
 
7 7u83 1416
tokdef
1417
f_make_tokdef(tdfint tokn, string_option sig, bitstream def)
2 7u83 1418
{
1419
  sortname result_sort;
1420
  tokformals_list params;
1421
  place old_place;
7 7u83 1422
  tok_define *tok = get_tok(natint(tokn));
1423
  if (sig.present) {
1424
    check_tok_sig(tok, sig.val);
1425
  }
2 7u83 1426
  old_place = keep_place();
1427
  set_place(def);
1428
  IGNORE getcode(1);
1429
  result_sort = d_sortname();
1430
  params = d_tokformals_list();
7 7u83 1431
  tok->tdsort = result_sort;
1432
  tok->params = params;
1433
  tok->tdplace = keep_place();
1434
  tok->defined = 1;
1435
  tok->tok_context = (context *)0;
2 7u83 1436
 
1437
    /* record the tables which are current so that they can be
1438
       used when the token is applied */
7 7u83 1439
  tok->my_labtab = unit_labtab;
1440
  tok->my_tagtab = unit_ind_tags;
1441
  tok->my_toktab = unit_ind_tokens;
1442
  tok->my_altab = unit_ind_als;
1443
  tok->my_diagtab = unit_ind_diagtags;	/* OLD DIAGS */
1444
  tok->my_dgtab = unit_ind_dgtags;	/* NEW DIAGS */
1445
  if (params.number == 0) {
2 7u83 1446
    tok -> re_evaluate = 0;
7 7u83 1447
  } else {
2 7u83 1448
    tok -> re_evaluate = 1;
7 7u83 1449
  }
2 7u83 1450
 
1451
  set_place(old_place);
1452
  return 0;
1453
}
1454
 
7 7u83 1455
token
1456
f_use_tokdef(bitstream def)
2 7u83 1457
{
1458
  token tok = (token)xcalloc(1, sizeof(tok_define)) /* space thief ?*/;
1459
  sortname result_sort;
1460
  tokformals_list params;
1461
  place old_place;
1462
 
1463
  old_place = keep_place();
1464
  set_place(def);
1465
  IGNORE getcode(1);
1466
  result_sort = d_sortname();
1467
  params = d_tokformals_list();
7 7u83 1468
  tok->tok_special = 0;
1469
  tok->valpresent = 0;
1470
  tok->unit_number = crt_tagdef_unit_no;
1471
  tok->defined = 0;
1472
  tok->is_capsule_token = 0;
1473
  tok->recursive = 0;
1474
  tok->tdsort = result_sort;
1475
  tok->params = params;
1476
  tok->tdplace = keep_place();
1477
  tok->defined = 1;
2 7u83 1478
  tok->tok_context = crt_context;
1479
 
7 7u83 1480
  /* record the tables which are current so that they can be used when
1481
     the token is applied */
1482
  tok->my_labtab = unit_labtab;
1483
  tok->my_tagtab = unit_ind_tags;
1484
  tok->my_toktab = unit_ind_tokens;
1485
  tok->my_altab = unit_ind_als;
1486
  tok->my_diagtab = unit_ind_diagtags;	/* OLD DIAGS */
1487
  tok->my_dgtab = unit_ind_dgtags;	/* NEW DIAGS */
2 7u83 1488
 
7 7u83 1489
  if (params.number == 0) {
1490
    tok->re_evaluate = 0;
1491
  } else {
1492
    tok->re_evaluate = 1;
1493
  }
2 7u83 1494
 
1495
  set_place(old_place);
1496
  return tok;
1497
}
1498
 
1499
 
7 7u83 1500
void
1501
init_tokdef(void)
2 7u83 1502
{
1503
  return;
1504
}
1505
 
1506
tokdef f_dummy_tokdef;
1507
 
7 7u83 1508
token
1509
f_token_apply_token(token token_value, bitstream token_args)
2 7u83 1510
{
1511
   tokval v;
7 7u83 1512
   v = apply_tok(token_value, token_args, TOKEN, (tokval *)0);
2 7u83 1513
   return v.tk_token;
1514
}
1515
 
7 7u83 1516
token
1517
f_make_tok(tdfint tokno)
2 7u83 1518
{
1519
  return get_tok(natint(tokno));
1520
}
1521
 
7 7u83 1522
void
1523
init_token(void)
2 7u83 1524
{
1525
  return;
1526
}
1527
 
1528
token f_dummy_token;
1529
 
7 7u83 1530
token_defn
1531
f_token_definition(sortname result_sort, tokformals_list tok_params)
2 7u83 1532
{
7 7u83 1533
  UNUSED(result_sort);
1534
  UNUSED(tok_params);
1535
  failer("dummy");
2 7u83 1536
  return f_dummy_token_defn;
1537
}
1538
 
7 7u83 1539
void
1540
init_token_defn(void)
2 7u83 1541
{
1542
  return;
1543
}
1544
 
1545
token_defn f_dummy_token_defn;
1546
 
7 7u83 1547
tokextern
1548
f_make_tokextern(tdfint internal, external ext)
2 7u83 1549
{
7 7u83 1550
  tok_define *t = &capsule_toktab[natint(internal)];
1551
  char *s = external_to_string(ext);
1552
  t->tok_name = s;
2 7u83 1553
 
7 7u83 1554
  /* determines special tokens specific to each machine */
1555
  if (machine_toks(s)) {
1556
    t->tok_special = 1;
1557
  }
2 7u83 1558
 
7 7u83 1559
  if (replace_arith_type) {
1560
    if (!strcmp(s, "~arith_type")) {
1561
      t->tok_special = 1;
1562
    }
1563
    if (!strcmp(s, "~promote")) {
1564
      t->tok_special = 1;
1565
    }
1566
    if (!strcmp(s, "~sign_promote")) {
1567
      t->tok_special = 1;
1568
    }
1569
    if (!strcmp(s, "~convert")) {
1570
      t->tok_special = 1;
1571
    }
1572
  }
1573
  if (do_alloca && !strcmp(s, "~alloca")) {
1574
    t->tok_special = 1;
1575
  }
2 7u83 1576
  return 0;
1577
}
1578
 
7 7u83 1579
alextern
1580
f_make_alextern(tdfint internal, external ext)
2 7u83 1581
{
7 7u83 1582
  UNUSED(internal);
1583
  UNUSED(ext);
2 7u83 1584
  return 0;
1585
}
1586
 
1587
 
7 7u83 1588
tokformals
1589
f_make_tokformals(sortname sn, tdfint tk)
2 7u83 1590
{
1591
  tokformals res;
1592
  res.sn = sn;
1593
  res.tk = natint(tk);
1594
  return res;
1595
}
1596
 
7 7u83 1597
void
1598
init_tokformals(void)
2 7u83 1599
{
1600
  return;
1601
}
1602
 
7 7u83 1603
toklink
1604
f_make_toklink(tdfint internal, tdfint ext)
2 7u83 1605
{
7 7u83 1606
  unit_ind_tokens[natint(internal)] = &capsule_toktab[natint(ext)];
2 7u83 1607
  return 0;
1608
}
1609
 
7 7u83 1610
link
1611
f_make_link(tdfint internal, tdfint ext)
2 7u83 1612
{
1613
  switch (crt_links_type)
1614
   {
1615
     case TOK_TYPE:
1616
       IGNORE f_make_toklink(internal, ext);
1617
       return 0;
1618
     case TAG_TYPE:
1619
       IGNORE f_make_taglink(internal, ext);
1620
       return 0;
1621
     case AL_TYPE:
1622
       IGNORE f_make_allink(internal, ext);
1623
       return 0;
1624
     case DIAGTAG_TYPE:		/* OLD DIAGS */
1625
       IGNORE f_make_diagtaglink(internal, ext);
1626
       return 0;
1627
     case DGTAG_TYPE:		/* NEW DIAGS */
1628
       IGNORE f_make_dglink(internal, ext);
1629
       return 0;
1630
     default:
1631
       failer(VARIABLE_TYPE);
1632
       return 0;
7 7u83 1633
   }
2 7u83 1634
}
1635
 
7 7u83 1636
unique
1637
f_make_unique(tdfstring_list text)
2 7u83 1638
{
1639
  return text;
1640
}
1641
 
7 7u83 1642
void
1643
init_unique(void)
2 7u83 1644
{
1645
   return;
1646
}
1647
 
1648
 
7 7u83 1649
variety
1650
f_var_apply_token(token token_value, bitstream token_args)
2 7u83 1651
{
1652
   tokval v;
7 7u83 1653
   v = apply_tok(token_value, token_args, VARIETY,(tokval *)0);
2 7u83 1654
   return v.tk_variety;
1655
}
1656
 
7 7u83 1657
variety
1658
f_var_cond(exp control, bitstream e1, bitstream e2)
2 7u83 1659
{
1660
  bitstream bs;
1661
  variety res;
1662
  int n;
1663
  bs = keep_place();
7 7u83 1664
  if (name(control) != val_tag) {
2 7u83 1665
    failer(CONTROL_EXP);
7 7u83 1666
  }
2 7u83 1667
  n = no(control);
1668
  retcell(control);
7 7u83 1669
  if (n==0) {
1670
    set_place(e2);
1671
    res = d_variety();
1672
  } else {
1673
    set_place(e1);
1674
    res = d_variety();
1675
  }
1676
 
1677
  set_place(bs); return res;
2 7u83 1678
}
1679
 
1680
 
7 7u83 1681
void
1682
start_make_tokdec_unit(int no_of_tokens, int no_of_tags, int no_of_als,
1683
		       int no_of_diagtags, int no_of_dgtags)
2 7u83 1684
{
1685
  int i;
1686
 
1687
  unit_no_of_tokens = no_of_tokens;
7 7u83 1688
  unit_ind_tokens = (tok_define **)xcalloc(unit_no_of_tokens,
1689
					   sizeof(tok_define *));
1690
  for (i = 0; i < unit_no_of_tokens; ++i) {
1691
    unit_ind_tokens[i] = (tok_define *)0;
1692
  }
2 7u83 1693
 
1694
  unit_no_of_tags = no_of_tags;
7 7u83 1695
  unit_ind_tags = (dec **)xcalloc(unit_no_of_tags, sizeof(dec *));
1696
  for (i = 0; i < unit_no_of_tags; ++i) {
1697
    unit_ind_tags[i] = (dec *)0;
1698
  }
2 7u83 1699
 
1700
  unit_no_of_als = no_of_als;
7 7u83 1701
  unit_ind_als = (aldef **)xcalloc(unit_no_of_als, sizeof(aldef *));
1702
  for (i = 0; i < unit_no_of_als; ++i) {
1703
    unit_ind_als[i] = (aldef *)0;
1704
  }
2 7u83 1705
 
1706
  unit_no_of_diagtags = no_of_diagtags;		/* OLD DIAGS */
7 7u83 1707
  unit_ind_diagtags = (diag_tagdef **)xcalloc(unit_no_of_diagtags,
1708
					      sizeof(diag_tagdef *));
1709
  for (i = 0; i < unit_no_of_diagtags; ++i) {
2 7u83 1710
    unit_ind_diagtags[i] = (diag_tagdef *)0;
7 7u83 1711
  }
2 7u83 1712
 
1713
  unit_no_of_dgtags = no_of_dgtags;		/* NEW DIAGS */
7 7u83 1714
  unit_ind_dgtags = (dgtag_struct **)xcalloc(unit_no_of_dgtags,
1715
					     sizeof(dgtag_struct *));
1716
  for (i = 0; i < unit_no_of_dgtags; ++i) {
2 7u83 1717
    unit_ind_dgtags[i] = (dgtag_struct *)0;
7 7u83 1718
  }
2 7u83 1719
 
1720
  return;
1721
}
1722
 
7 7u83 1723
tokdec_unit
1724
f_make_tokdec_unit(void)
2 7u83 1725
{
1726
  int i;
1727
  int j = 0;
7 7u83 1728
  for (i = 0; i < unit_no_of_tokens; ++i) {
1729
    if (unit_ind_tokens[i] == (tok_define *)0) {
2 7u83 1730
      unit_ind_tokens[i] = &unit_toktab[j++];
7 7u83 1731
    }
1732
  }
2 7u83 1733
  start_bytestream();
1734
  IGNORE d_tokdec_list();
1735
  end_bytestream();
1736
  return 0;
1737
}
1738
 
7 7u83 1739
void
1740
start_make_tokdef_unit(int no_of_tokens, int no_of_tags, int no_of_als,
1741
		       int no_of_diagtags, int no_of_dgtags)
2 7u83 1742
{
1743
  int i;
1744
 
1745
  unit_no_of_tokens = no_of_tokens;
7 7u83 1746
  unit_ind_tokens = (tok_define **)xcalloc(unit_no_of_tokens,
1747
					   sizeof(tok_define *));
1748
  for (i = 0; i < unit_no_of_tokens; ++i) {
1749
    unit_ind_tokens[i] = (tok_define *)0;
1750
  }
2 7u83 1751
 
1752
  unit_no_of_tags = no_of_tags;
7 7u83 1753
  unit_ind_tags = (dec **)xcalloc(unit_no_of_tags, sizeof(dec *));
1754
  for (i = 0; i < unit_no_of_tags; ++i) {
1755
    unit_ind_tags[i] = (dec *)0;
1756
  }
2 7u83 1757
 
1758
  unit_no_of_als = no_of_als;
7 7u83 1759
  unit_ind_als = (aldef **)xcalloc(unit_no_of_als, sizeof(aldef *));
1760
  for (i = 0; i < unit_no_of_als; ++i) {
1761
    unit_ind_als[i] = (aldef *)0;
1762
  }
2 7u83 1763
 
1764
  unit_no_of_diagtags = no_of_diagtags;		/* OLD DIAGS */
7 7u83 1765
  unit_ind_diagtags = (diag_tagdef **)xcalloc(unit_no_of_diagtags,
1766
					      sizeof(diag_tagdef *));
1767
  for (i = 0; i < unit_no_of_diagtags; ++i) {
2 7u83 1768
    unit_ind_diagtags[i] = (diag_tagdef *)0;
7 7u83 1769
  }
2 7u83 1770
 
1771
  unit_no_of_dgtags = no_of_dgtags;		/* NEW DIAGS */
7 7u83 1772
  unit_ind_dgtags = (dgtag_struct **)xcalloc(unit_no_of_dgtags,
1773
					     sizeof(dgtag_struct *));
1774
  for (i = 0; i < unit_no_of_dgtags; ++i) {
2 7u83 1775
    unit_ind_dgtags[i] = (dgtag_struct *)0;
7 7u83 1776
  }
2 7u83 1777
 
1778
  return;
1779
}
1780
 
7 7u83 1781
tokdef_unit
1782
f_make_tokdef_unit(void)
2 7u83 1783
{
1784
  int i;
1785
  int j = 0;
1786
  int no_of_labels;
7 7u83 1787
  for (i = 0; i < unit_no_of_tokens; ++i) {
1788
    if (unit_ind_tokens[i] == (tok_define *)0) {
2 7u83 1789
      unit_ind_tokens[i] = &unit_toktab[j++];
7 7u83 1790
    }
1791
  }
2 7u83 1792
  j = 0;
7 7u83 1793
  for (i = 0; i < unit_no_of_tags; ++i) {
1794
    if (unit_ind_tags[i] == (dec *)0) {
2 7u83 1795
      unit_ind_tags[i] = &unit_tagtab[j++];
7 7u83 1796
    }
1797
  }
2 7u83 1798
  j = 0;
7 7u83 1799
  for (i = 0; i < unit_no_of_als; ++i) {
1800
    if (unit_ind_als[i] == (aldef *)0) {
2 7u83 1801
      unit_ind_als[i] = &unit_altab[j++];
7 7u83 1802
    }
1803
  }
2 7u83 1804
  j = 0;
7 7u83 1805
  for (i = 0; i < unit_no_of_dgtags; ++i) {	/* NEW DIAGS */
1806
    if (unit_ind_dgtags[i] == (dgtag_struct *)0) {
2 7u83 1807
      unit_ind_dgtags[i] = &unit_dgtagtab[j++];
7 7u83 1808
    }
1809
  }
2 7u83 1810
  start_bytestream();
1811
  no_of_labels = small_dtdfint();
1812
  unit_no_of_labels = no_of_labels;
7 7u83 1813
  unit_labtab = (exp *)xcalloc(unit_no_of_labels, sizeof(exp));
2 7u83 1814
  IGNORE d_tokdef_list();
1815
  end_bytestream();
1816
 
1817
  /* tables must be kept for use during token application */
1818
 
1819
  return 0;
1820
}
1821
 
7 7u83 1822
void
1823
start_make_tagdec_unit(int no_of_tokens, int no_of_tags, int no_of_als,
1824
		       int no_of_diagtags, int no_of_dgtags)
2 7u83 1825
{
1826
  int i;
1827
 
1828
  unit_no_of_tokens = no_of_tokens;
7 7u83 1829
  unit_ind_tokens = (tok_define **)xcalloc(unit_no_of_tokens,
1830
					   sizeof(tok_define *));
1831
  for (i = 0; i < unit_no_of_tokens; ++i) {
1832
    unit_ind_tokens[i] = (tok_define *)0;
1833
  }
2 7u83 1834
 
1835
  unit_no_of_tags = no_of_tags;
7 7u83 1836
  unit_ind_tags = (dec **)xcalloc(unit_no_of_tags, sizeof(dec *));
1837
  for (i = 0; i < unit_no_of_tags; ++i) {
1838
    unit_ind_tags[i] = (dec *)0;
1839
  }
2 7u83 1840
 
1841
  unit_no_of_als = no_of_als;
7 7u83 1842
  unit_ind_als = (aldef **)xcalloc(unit_no_of_als, sizeof(aldef *));
1843
  for (i = 0; i < unit_no_of_als; ++i) {
1844
    unit_ind_als[i] = (aldef *)0;
1845
  }
2 7u83 1846
 
1847
  unit_no_of_diagtags = no_of_diagtags;		/* OLD DIAGS */
7 7u83 1848
  unit_ind_diagtags = (diag_tagdef **)xcalloc(unit_no_of_diagtags,
1849
					      sizeof(diag_tagdef *));
1850
  for (i = 0; i < unit_no_of_diagtags; ++i) {
2 7u83 1851
    unit_ind_diagtags[i] = (diag_tagdef *)0;
7 7u83 1852
  }
2 7u83 1853
 
1854
  unit_no_of_dgtags = no_of_dgtags;		/* NEW DIAGS */
7 7u83 1855
  unit_ind_dgtags = (dgtag_struct **)xcalloc(unit_no_of_dgtags,
1856
					     sizeof(dgtag_struct *));
1857
  for (i = 0; i < unit_no_of_dgtags; ++i) {
2 7u83 1858
    unit_ind_dgtags[i] = (dgtag_struct *)0;
7 7u83 1859
  }
2 7u83 1860
 
1861
  return;
1862
}
1863
 
7 7u83 1864
tagdec_unit
1865
f_make_tagdec_unit(void)
2 7u83 1866
{
1867
  int i;
1868
  int j = 0;
1869
  int no_of_labels;
7 7u83 1870
  for (i = 0; i < unit_no_of_tokens; ++i) {
1871
    if (unit_ind_tokens[i] == (tok_define *)0) {
2 7u83 1872
      unit_ind_tokens[i] = &unit_toktab[j++];
7 7u83 1873
    }
1874
  }
2 7u83 1875
  j = 0;
7 7u83 1876
  for (i = 0; i < unit_no_of_tags; ++i) {
1877
    if (unit_ind_tags[i] == (dec *)0) {
2 7u83 1878
      unit_ind_tags[i] = &unit_tagtab[j++];
7 7u83 1879
    }
1880
  }
2 7u83 1881
  j = 0;
7 7u83 1882
  for (i = 0; i < unit_no_of_als; ++i) {
1883
    if (unit_ind_als[i] == (aldef *)0) {
2 7u83 1884
      unit_ind_als[i] = &unit_altab[j++];
7 7u83 1885
    }
1886
  }
2 7u83 1887
  j = 0;
7 7u83 1888
  for (i = 0; i < unit_no_of_dgtags; ++i) {	/* NEW DIAGS */
1889
    if (unit_ind_dgtags[i] == (dgtag_struct *)0) {
2 7u83 1890
      unit_ind_dgtags[i] = &unit_dgtagtab[j++];
7 7u83 1891
    }
1892
  }
2 7u83 1893
  start_bytestream();
1894
  no_of_labels = small_dtdfint();
1895
  unit_no_of_labels = no_of_labels;
7 7u83 1896
  unit_labtab = (exp *)xcalloc(unit_no_of_labels, sizeof(exp));
2 7u83 1897
  IGNORE d_tagdec_list();
1898
  end_bytestream();
1899
 
7 7u83 1900
  xfree((void *)unit_ind_tokens);
1901
  xfree((void *)unit_ind_tags);
1902
  xfree((void *)unit_ind_als);
1903
  xfree((void *)unit_labtab);
2 7u83 1904
 
7 7u83 1905
  xfree((void *)unit_toktab);
2 7u83 1906
 
1907
  return 0;
1908
}
1909
 
7 7u83 1910
void
1911
start_make_versions_unit(int no_of_tokens, int no_of_tags, int no_of_als,
1912
			 int no_of_diagtags, int no_of_dgtags)
2 7u83 1913
{
1914
  int i;
1915
 
1916
  unit_no_of_tokens = no_of_tokens;
7 7u83 1917
  unit_ind_tokens = (tok_define **)xcalloc(unit_no_of_tokens,
1918
					   sizeof(tok_define *));
1919
  for (i = 0; i < unit_no_of_tokens; ++i) {
1920
    unit_ind_tokens[i] = (tok_define *)0;
1921
  }
2 7u83 1922
 
1923
  unit_no_of_tags = no_of_tags;
7 7u83 1924
  unit_ind_tags = (dec **)xcalloc(unit_no_of_tags, sizeof(dec *));
1925
  for (i = 0; i < unit_no_of_tags; ++i) {
1926
    unit_ind_tags[i] = (dec *)0;
1927
  }
2 7u83 1928
 
1929
  unit_no_of_als = no_of_als;
7 7u83 1930
  unit_ind_als = (aldef **)xcalloc(unit_no_of_als, sizeof(aldef *));
1931
  for (i = 0; i < unit_no_of_als; ++i) {
1932
    unit_ind_als[i] = (aldef *)0;
1933
  }
2 7u83 1934
 
1935
  unit_no_of_diagtags = no_of_diagtags;		/* OLD DIAGS */
7 7u83 1936
  unit_ind_diagtags = (diag_tagdef **)xcalloc(unit_no_of_diagtags,
1937
					      sizeof(diag_tagdef *));
1938
  for (i = 0; i < unit_no_of_diagtags; ++i) {
2 7u83 1939
    unit_ind_diagtags[i] = (diag_tagdef *)0;
7 7u83 1940
  }
2 7u83 1941
 
1942
  unit_no_of_dgtags = no_of_dgtags;		/* NEW DIAGS */
7 7u83 1943
  unit_ind_dgtags = (dgtag_struct **)xcalloc(unit_no_of_dgtags,
1944
					     sizeof(dgtag_struct *));
1945
  for (i = 0; i < unit_no_of_dgtags; ++i) {
2 7u83 1946
    unit_ind_dgtags[i] = (dgtag_struct *)0;
7 7u83 1947
  }
2 7u83 1948
 
1949
  return;
1950
}
1951
 
7 7u83 1952
version_props
1953
f_make_versions_unit(void)
2 7u83 1954
{
1955
  int i;
1956
  int j = 0;
7 7u83 1957
  for (i = 0; i < unit_no_of_tokens; ++i) {
1958
    if (unit_ind_tokens[i] == (tok_define *)0) {
2 7u83 1959
      unit_ind_tokens[i] = &unit_toktab[j++];
7 7u83 1960
    }
1961
  }
2 7u83 1962
  j = 0;
7 7u83 1963
  for (i = 0; i < unit_no_of_tags; ++i) {
1964
    if (unit_ind_tags[i] == (dec *)0) {
2 7u83 1965
      unit_ind_tags[i] = &unit_tagtab[j++];
7 7u83 1966
    }
1967
  }
2 7u83 1968
  j = 0;
7 7u83 1969
  for (i = 0; i < unit_no_of_als; ++i) {
1970
    if (unit_ind_als[i] == (aldef *)0) {
2 7u83 1971
      unit_ind_als[i] = &unit_altab[j++];
7 7u83 1972
    }
1973
  }
2 7u83 1974
  start_bytestream();
1975
  IGNORE d_version_list();
1976
  end_bytestream();
1977
 
7 7u83 1978
  xfree((void *)unit_ind_tokens);
1979
  xfree((void *)unit_ind_tags);
1980
  xfree((void *)unit_ind_als);
2 7u83 1981
 
7 7u83 1982
  xfree((void *)unit_toktab);
1983
  xfree((void *)unit_tagtab);
2 7u83 1984
 
1985
  return 0;
1986
}
1987
 
7 7u83 1988
void
1989
start_make_tagdef_unit(int no_of_tokens, int no_of_tags, int no_of_als,
1990
		       int no_of_diagtags, int no_of_dgtags)
2 7u83 1991
{
1992
  int i;
1993
 
7 7u83 1994
  if (separate_units) {
2 7u83 1995
    ++crt_tagdef_unit_no;
1996
    set_large_alloc();
7 7u83 1997
  }
2 7u83 1998
 
1999
  unit_no_of_tokens = no_of_tokens;
7 7u83 2000
  unit_ind_tokens = (tok_define **)xcalloc(unit_no_of_tokens,
2001
					   sizeof(tok_define *));
2002
  for (i = 0; i < unit_no_of_tokens; ++i) {
2003
    unit_ind_tokens[i] = (tok_define *)0;
2004
  }
2 7u83 2005
 
2006
  unit_no_of_tags = no_of_tags;
7 7u83 2007
  unit_ind_tags = (dec **)xcalloc(unit_no_of_tags, sizeof(dec *));
2008
  for (i = 0; i < unit_no_of_tags; ++i) {
2009
    unit_ind_tags[i] = (dec *)0;
2010
  }
2 7u83 2011
 
2012
  unit_no_of_als = no_of_als;
7 7u83 2013
  unit_ind_als = (aldef **)xcalloc(unit_no_of_als, sizeof(aldef *));
2014
  for (i = 0; i < unit_no_of_als; ++i) {
2015
    unit_ind_als[i] = (aldef *)0;
2016
  }
2 7u83 2017
 
2018
  unit_no_of_diagtags = no_of_diagtags;		/* OLD DIAGS */
7 7u83 2019
  unit_ind_diagtags = (diag_tagdef **)xcalloc(unit_no_of_diagtags,
2020
					      sizeof(diag_tagdef *));
2021
  for (i = 0; i < unit_no_of_diagtags; ++i) {
2 7u83 2022
    unit_ind_diagtags[i] = (diag_tagdef *)0;
7 7u83 2023
  }
2 7u83 2024
 
2025
  unit_no_of_dgtags = no_of_dgtags;		/* NEW DIAGS */
7 7u83 2026
  unit_ind_dgtags = (dgtag_struct **)xcalloc(unit_no_of_dgtags,
2027
					     sizeof(dgtag_struct *));
2028
  for (i = 0; i < unit_no_of_dgtags; ++i) {
2 7u83 2029
    unit_ind_dgtags[i] = (dgtag_struct *)0;
7 7u83 2030
  }
2 7u83 2031
 
2032
  return;
2033
}
2034
 
2035
 
2036
 
2037
 
7 7u83 2038
tagdef_unit
2039
f_make_tagdef_unit(void)
2 7u83 2040
{
2041
  int i;
2042
  int j = 0;
2043
  int no_of_labels;
7 7u83 2044
  for (i = 0; i < unit_no_of_tokens; ++i) {
2045
    if (unit_ind_tokens[i] == (tok_define *)0) {
2 7u83 2046
      unit_ind_tokens[i] = &unit_toktab[j++];
7 7u83 2047
    }
2048
  }
2 7u83 2049
  j = 0;
7 7u83 2050
  for (i = 0; i < unit_no_of_tags; ++i) {
2051
    if (unit_ind_tags[i] == (dec *)0) {
2 7u83 2052
      unit_ind_tags[i] = &unit_tagtab[j++];
7 7u83 2053
    }
2054
  }
2 7u83 2055
  j = 0;
7 7u83 2056
  for (i = 0; i < unit_no_of_als; ++i) {
2057
    if (unit_ind_als[i] == (aldef *)0) {
2 7u83 2058
      unit_ind_als[i] = &unit_altab[j++];
7 7u83 2059
    }
2060
  }
2 7u83 2061
  j = 0;
7 7u83 2062
  for (i = 0; i < unit_no_of_dgtags; ++i) {	/* NEW DIAGS */
2063
    if (unit_ind_dgtags[i] == (dgtag_struct *)0) {
2 7u83 2064
      unit_ind_dgtags[i] = &unit_dgtagtab[j++];
7 7u83 2065
    }
2066
  }
2 7u83 2067
  start_bytestream();
2068
  no_of_labels = small_dtdfint();
2069
  unit_no_of_labels = no_of_labels;
7 7u83 2070
  unit_labtab = (exp *)xcalloc(unit_no_of_labels, sizeof(exp));
2 7u83 2071
  IGNORE d_tagdef_list();
2072
  tidy_initial_values();
2073
  translate_unit();
2074
  end_bytestream();
2075
 
7 7u83 2076
  xfree((void *)unit_ind_tokens);
2077
  xfree((void *)unit_ind_tags);
2078
  xfree((void *)unit_ind_als);
2079
  xfree((void *)unit_labtab);
2 7u83 2080
 
7 7u83 2081
  xfree((void *)unit_toktab);
2082
  xfree((void *)unit_tagtab);
2 7u83 2083
 
2084
  return 0;
2085
}
2086
 
7 7u83 2087
void
2088
start_make_aldef_unit(int no_of_tokens, int no_of_tags, int no_of_als,
2089
		      int no_of_diagtags, int no_of_dgtags)
2 7u83 2090
{
2091
  int i;
2092
 
2093
  unit_no_of_tokens = no_of_tokens;
7 7u83 2094
  unit_ind_tokens = (tok_define **)xcalloc(unit_no_of_tokens,
2095
					   sizeof(tok_define *));
2096
  for (i = 0; i < unit_no_of_tokens; ++i) {
2097
    unit_ind_tokens[i] = (tok_define *)0;
2098
  }
2 7u83 2099
 
2100
  unit_no_of_tags = no_of_tags;
7 7u83 2101
  unit_ind_tags = (dec **)xcalloc(unit_no_of_tags, sizeof(dec *));
2102
  for (i = 0; i < unit_no_of_tags; ++i) {
2103
    unit_ind_tags[i] = (dec *)0;
2104
  }
2 7u83 2105
 
2106
  unit_no_of_als = no_of_als;
7 7u83 2107
  unit_ind_als = (aldef **)xcalloc(unit_no_of_als, sizeof(aldef *));
2108
  for (i = 0; i < unit_no_of_als; ++i) {
2109
    unit_ind_als[i] = (aldef *)0;
2110
  }
2 7u83 2111
 
2112
  unit_no_of_diagtags = no_of_diagtags;		/* OLD DIAGS */
7 7u83 2113
  unit_ind_diagtags = (diag_tagdef **)xcalloc(unit_no_of_diagtags,
2114
					      sizeof(diag_tagdef *));
2115
  for (i = 0; i < unit_no_of_diagtags; ++i) {
2 7u83 2116
    unit_ind_diagtags[i] = (diag_tagdef *)0;
7 7u83 2117
  }
2 7u83 2118
 
2119
  unit_no_of_dgtags = no_of_dgtags;		/* NEW DIAGS */
7 7u83 2120
  unit_ind_dgtags = (dgtag_struct **)xcalloc(unit_no_of_dgtags,
2121
					     sizeof(dgtag_struct *));
2122
  for (i = 0; i < unit_no_of_dgtags; ++i) {
2 7u83 2123
    unit_ind_dgtags[i] = (dgtag_struct *)0;
7 7u83 2124
  }
2 7u83 2125
 
2126
  return;
2127
}
2128
 
7 7u83 2129
aldef_unit
2130
f_make_aldef_unit(void)
2 7u83 2131
{
2132
  int i;
2133
  int j = 0;
2134
  int no_of_labels;
7 7u83 2135
  for (i = 0; i < unit_no_of_tokens; ++i) {
2136
    if (unit_ind_tokens[i] == (tok_define *)0) {
2 7u83 2137
      unit_ind_tokens[i] = &unit_toktab[j++];
7 7u83 2138
    }
2139
  }
2 7u83 2140
  j = 0;
7 7u83 2141
  for (i = 0; i < unit_no_of_als; ++i) {
2142
    if (unit_ind_als[i] == (aldef *)0) {
2 7u83 2143
      unit_ind_als[i] = &unit_altab[j++];
7 7u83 2144
    }
2145
  }
2 7u83 2146
  start_bytestream();
2147
  no_of_labels = small_dtdfint();
2148
  unit_no_of_labels = no_of_labels;
7 7u83 2149
  unit_labtab = (exp *)xcalloc(unit_no_of_labels, sizeof(exp));
2 7u83 2150
  IGNORE d_al_tagdef_list();
2151
  end_bytestream();
2152
 
7 7u83 2153
  xfree((void *)unit_ind_tokens);
2154
  xfree((void *)unit_ind_tags);
2155
  xfree((void *)unit_ind_als);
2156
  xfree((void *)unit_labtab);
2 7u83 2157
 
7 7u83 2158
  xfree((void *)unit_toktab);
2159
  xfree((void *)unit_tagtab);
2 7u83 2160
 
2161
  return 0;
2162
}
2163
 
7 7u83 2164
void
2165
start_make_unit(tdfint_list lvl)
2 7u83 2166
{
2167
  int w;
2168
  int ntok = 0;
2169
  int ntag = 0;
2170
  int nal = 0;
2171
  int ndiagtype = 0;	/* OLD DIAGS */
2172
  int ndgtag = 0;	/* NEW DIAGS */
2173
 
2174
  ++unit_index;
2175
 
2176
  if (lvl.number != 0) {
2177
    w = find_index("token");
2178
    ntok = (w == -1) ? 0 : natint(lvl.members[w]);
2179
    w = find_index("tag");
2180
    ntag = (w == -1) ? 0 : natint(lvl.members[w]);
2181
    w = find_index("alignment");
2182
    nal = (w == -1) ? 0 : natint(lvl.members[w]);
2183
    w = find_index("diagtag");		/* OLD DIAGS */
2184
    ndiagtype = (w == -1) ? 0 : natint(lvl.members[w]);
2185
    w = find_index("dgtag");		/* NEW DIAGS */
2186
    ndgtag = (w == -1) ? 0 : natint(lvl.members[w]);
7 7u83 2187
  }
2 7u83 2188
 
7 7u83 2189
  switch (crt_group_type)
2 7u83 2190
   {
2191
     case TOKDEC_UNIT:
2192
              start_make_tokdec_unit(ntok, ntag, nal, ndiagtype, ndgtag);
2193
              return;
2194
     case TOKDEF_UNIT:
2195
              start_make_tokdef_unit(ntok, ntag, nal, ndiagtype, ndgtag);
2196
              return;
2197
     case AL_UNIT:
2198
	      doing_aldefs = 1;
2199
              start_make_aldef_unit(ntok, ntag, nal, ndiagtype, ndgtag);
2200
              return;
2201
     case TAGDEC_UNIT:
2202
	      if (doing_aldefs) {
2203
                process_aldefs();
2204
	        doing_aldefs = 0;
7 7u83 2205
	      }
2 7u83 2206
              start_make_tagdec_unit(ntok, ntag, nal, ndiagtype, ndgtag);
2207
              return;
2208
     case TAGDEF_UNIT:
2209
              start_make_tagdef_unit(ntok, ntag, nal, ndiagtype, ndgtag);
2210
              return;
2211
     case DIAGDEF_UNIT:		/* OLD DIAGS */
2212
              start_make_diagdef_unit(ntok, ntag, nal, ndiagtype);
2213
              return;
2214
     case DIAGTYPE_UNIT:	/* OLD DIAGS */
2215
	      if (doing_aldefs) {
2216
                process_aldefs();
2217
	        doing_aldefs = 0;
7 7u83 2218
	      }
2 7u83 2219
              start_make_diagtype_unit(ntok, ntag, nal, ndiagtype);
2220
              return;
2221
     case LINKINFO_UNIT:
2222
              start_make_linkinfo_unit(ntok, ntag, nal, 0 /* discarded */);
2223
              return;
2224
     case VERSIONS_UNIT:
2225
              start_make_versions_unit(ntok, ntag, nal, ndiagtype, ndgtag);
2226
              return;
2227
     case DGCOMP_UNIT:	/* NEW DIAGS */
2228
	      if (doing_aldefs) {
2229
                process_aldefs();
2230
	        doing_aldefs = 0;
7 7u83 2231
	      }
2 7u83 2232
              start_make_dg_comp_unit(ntok, ntag, nal, ndgtag);
2233
              return;
2234
     default:
2235
              return;
7 7u83 2236
   }
2 7u83 2237
}
2238
 
7 7u83 2239
unit
2240
f_make_unit(tdfint_list lvl, links_list lks, bytestream prs)
2 7u83 2241
{
7 7u83 2242
  UNUSED(lvl);
2243
  UNUSED(lks);
2244
  UNUSED(prs);
2245
  switch (crt_group_type)
2 7u83 2246
   {
2247
     case TOKDEC_UNIT:
2248
              IGNORE f_make_tokdec_unit();
2249
              break;
2250
     case TOKDEF_UNIT:
2251
              IGNORE f_make_tokdef_unit();
2252
              break;
2253
     case AL_UNIT:
2254
              IGNORE f_make_aldef_unit();
2255
              break;
2256
     case TAGDEC_UNIT:
2257
              IGNORE f_make_tagdec_unit();
2258
              break;
2259
     case TAGDEF_UNIT:
2260
              IGNORE f_make_tagdef_unit();
2261
              break;
2262
     case DIAGDEF_UNIT:		/* OLD DIAGS */
7 7u83 2263
              if (diagnose) {
2 7u83 2264
                IGNORE f_make_diagdef_unit();
7 7u83 2265
	      } else {
2 7u83 2266
                ignore_bytestream();
7 7u83 2267
	      }
2 7u83 2268
              break;
2269
     case DIAGTYPE_UNIT:	/* OLD DIAGS */
7 7u83 2270
              if (diagnose) {
2 7u83 2271
                IGNORE f_make_diagtype_unit();
7 7u83 2272
	      } else {
2 7u83 2273
                ignore_bytestream();
7 7u83 2274
	      }
2 7u83 2275
              break;
2276
     case LINKINFO_UNIT:
2277
              IGNORE f_make_linkinfo_unit();
2278
              break;
2279
     case VERSIONS_UNIT:
2280
	      IGNORE f_make_versions_unit();
2281
	      break;
2282
     case DGCOMP_UNIT:	/* NEW DIAGS */
7 7u83 2283
              if (diagnose) {
2 7u83 2284
                IGNORE f_make_dg_comp_unit();
7 7u83 2285
	      } else {
2 7u83 2286
                ignore_bytestream();
7 7u83 2287
	      }
2 7u83 2288
              break;
2289
     default:
2290
              ignore_bytestream();
2291
              break;
7 7u83 2292
   }
2 7u83 2293
  return 0;
2294
}
2295
 
7 7u83 2296
linkextern
2297
f_make_linkextern(tdfint internal, external ext)
2 7u83 2298
{
2299
  switch (crt_extern_link_type)
2300
   {
2301
     case TOK_TYPE:
2302
       return f_make_tokextern(internal, ext);
2303
     case TAG_TYPE:
2304
       return f_make_tagextern(internal, ext);
2305
     case AL_TYPE:
2306
       return f_make_alextern(internal, ext);
2307
     case DIAGTAG_TYPE:		/* OLD DIAGS */
2308
       return f_make_diagtagextern(internal, ext);
2309
     case DGTAG_TYPE:		/* NEW DIAGS */
2310
       return f_make_dgtagextern(internal, ext);
2311
     default:
2312
       failer(VARIABLE_TYPE);
2313
       return 0;
7 7u83 2314
   }
2 7u83 2315
}
2316
 
7 7u83 2317
group
2318
f_make_group(unit_list us)
2 7u83 2319
{
2320
  UNUSED(us);
2321
  return 0;
2322
}
2323
 
7 7u83 2324
links
2325
f_make_links(link_list ls)
2 7u83 2326
{
2327
  UNUSED(ls);
2328
  return 0;
2329
}
2330
 
7 7u83 2331
extern_link
2332
f_make_extern_link(linkextern_list el)
2 7u83 2333
{
2334
  UNUSED(el);
2335
  return 0;
2336
}
2337
 
7 7u83 2338
tokdef_props
2339
f_make_tokdefs(tdfint nl, tokdef_list tds)
2 7u83 2340
{
7 7u83 2341
  UNUSED(nl);
2342
  UNUSED(tds);
2 7u83 2343
  return 0;
2344
}
2345
 
7 7u83 2346
tokdec_props
2347
f_make_tokdecs(tokdec_list tds)
2 7u83 2348
{
2349
  UNUSED(tds);
2350
  return 0;
2351
}
2352
 
7 7u83 2353
tagdef_props
2354
f_make_tagdefs(tdfint nl, tagdef_list tds)
2 7u83 2355
{
7 7u83 2356
  UNUSED(nl);
2357
  UNUSED(tds);
2 7u83 2358
  return 0;
2359
}
2360
 
7 7u83 2361
al_tagdef_props
2362
f_make_al_tagdefs(tdfint nl, al_tagdef_list tds)
2 7u83 2363
{
7 7u83 2364
  UNUSED(nl);
2365
  UNUSED(tds);
2 7u83 2366
  return 0;
2367
}
2368
 
7 7u83 2369
tagdec_props
2370
f_make_tagdecs(tdfint nl, tagdec_list tds)
2 7u83 2371
{
7 7u83 2372
 UNUSED(nl);
2373
 UNUSED(tds);
2 7u83 2374
 return 0;
2375
}
2376
 
2377
 
2378
 
7 7u83 2379
sortname_list
2380
new_sortname_list(int n)
2 7u83 2381
{
2382
  sortname_list res;
2383
  res.number = n;
7 7u83 2384
  res.elems = (sortname *)xcalloc(n, sizeof(sortname));
2 7u83 2385
  return res;
2386
}
2387
 
7 7u83 2388
sortname_list
2389
add_sortname_list(sortname_list list, sortname elem, int index)
2 7u83 2390
{
2391
  list.elems[index] = elem;
2392
  return list;
2393
}
2394
 
7 7u83 2395
tokformals_list
2396
new_tokformals_list(int n)
2 7u83 2397
{
2398
  tokformals_list res;
2399
  res.number = n;
2400
  res.par_sorts = (sortname *)xcalloc(n, sizeof(sortname));
2401
  res.par_names = (int *)xcalloc(n, sizeof(int));
2402
  return res;
2403
}
2404
 
7 7u83 2405
tokformals_list
2406
add_tokformals_list(tokformals_list list, tokformals elem, int index)
2 7u83 2407
{
2408
  list.par_sorts[index] = elem.sn;
2409
  list.par_names[index] = elem.tk;
2410
  return list;
2411
}
2412
 
7 7u83 2413
tokdec_list
2414
new_tokdec_list(int n)
2 7u83 2415
{
2416
  UNUSED(n);
2417
  return 0;
2418
}
2419
 
7 7u83 2420
tokdec_list
2421
add_tokdec_list(tokdec_list list, tokdec elem, int index)
2 7u83 2422
{
7 7u83 2423
  UNUSED(list);
2424
  UNUSED(elem);
2425
  UNUSED(index);
2 7u83 2426
  return 0;
2427
}
2428
 
7 7u83 2429
tokdef_list
2430
new_tokdef_list(int n)
2 7u83 2431
{
2432
  UNUSED(n);
2433
  return 0;
2434
}
2435
 
7 7u83 2436
tokdef_list
2437
add_tokdef_list(tokdef_list list, tokdef elem, int index)
2 7u83 2438
{
7 7u83 2439
  UNUSED(list);
2440
  UNUSED(elem);
2441
  UNUSED(index);
2 7u83 2442
  return 0;
2443
}
2444
 
7 7u83 2445
al_tagdef_list
2446
new_al_tagdef_list(int n)
2 7u83 2447
{
2448
  UNUSED(n);
2449
  return 0;
2450
}
2451
 
7 7u83 2452
al_tagdef_list
2453
add_al_tagdef_list(al_tagdef_list list, al_tagdef elem, int index)
2 7u83 2454
{
7 7u83 2455
  UNUSED(list);
2456
  UNUSED(elem);
2457
  UNUSED(index);
2 7u83 2458
  return 0;
2459
}
2460
 
2461
 
7 7u83 2462
al_tagdef
2463
f_make_al_tagdef(tdfint t, alignment a)
2 7u83 2464
{
7 7u83 2465
  aldef *ap = get_aldef(natint(t));
2466
  ap->next_aldef = top_aldef;
2 7u83 2467
  top_aldef = ap;
7 7u83 2468
  ap->al = a->al;
2 7u83 2469
  return 0;
2470
}
2471
 
2472
 
2473
 
7 7u83 2474
tagdec_list
2475
new_tagdec_list(int n)
2 7u83 2476
{
2477
  UNUSED(n);
2478
  return 0;
2479
}
2480
 
7 7u83 2481
tagdec_list
2482
add_tagdec_list(tagdec_list list, tagdec elem, int index)
2 7u83 2483
{
7 7u83 2484
    dec *dp = elem.tg;
2 7u83 2485
    shape s;
2486
    exp e;
7 7u83 2487
    UNUSED(list);
2488
    UNUSED(index);
2 7u83 2489
    s = elem.sha;
2490
 
2491
    e = getexp(s, nilexp, 0, nilexp, nilexp, 0, 0, ident_tag);
2492
 
7 7u83 2493
    if (elem.is_variable) {
2 7u83 2494
#if keep_PIC_vars
2495
       setvar(e);
2496
#else
7 7u83 2497
       if (PIC_code && dp -> dec_u.dec_val.extnamed) {
2 7u83 2498
         sh(e) = f_pointer(f_alignment(s));
7 7u83 2499
       } else {
2 7u83 2500
         setvar(e);
7 7u83 2501
       }
2 7u83 2502
#endif
7 7u83 2503
    }
2 7u83 2504
 
7 7u83 2505
    if (elem.acc & (f_visible | f_long_jump_access)) {
2 7u83 2506
      setvis(e);
7 7u83 2507
    }
2508
    if (elem.acc & f_constant) {
2 7u83 2509
      setcaonly(e);
7 7u83 2510
    }
2 7u83 2511
 
7 7u83 2512
    dp->dec_u.dec_val.acc = elem.acc;
2 7u83 2513
 
7 7u83 2514
    dp->dec_u.dec_val.dec_exp = e;
2 7u83 2515
 
7 7u83 2516
    if (dp->dec_u.dec_val.dec_shape != nilexp) {
2517
      if (shape_size(s) > shape_size(dp->dec_u.dec_val.dec_shape)) {
2518
        dp->dec_u.dec_val.dec_shape = s;
2519
      }
2520
    }
2 7u83 2521
 
7 7u83 2522
    if (dp->dec_u.dec_val.dec_shape == nilexp) {
2523
      dp->dec_u.dec_val.dec_shape = s;
2524
      dp->def_next = (dec *)0;
2 7u83 2525
      *deflist_end = dp;
7 7u83 2526
      deflist_end = & ((*deflist_end)->def_next);
2527
    }
2 7u83 2528
 
7 7u83 2529
    dp->dec_u.dec_val.dec_var = (unsigned int)(isvar(e) || elem.is_variable);
2530
    if (!dp->dec_u.dec_val.have_def) {
2 7u83 2531
      setglob(e);
7 7u83 2532
    }
2 7u83 2533
    /* the defining exp */
7 7u83 2534
    brog(dp->dec_u.dec_val.dec_exp) = dp;
2535
    if (dp->dec_u.dec_val.dec_id == (char *)0) {
2536
      dp->dec_u.dec_val.dec_id = make_local_name();
2537
    }
2 7u83 2538
 
2539
  return 0;
2540
}
2541
 
7 7u83 2542
tagdef_list
2543
new_tagdef_list(int n)
2 7u83 2544
{
2545
  UNUSED(n);
2546
  return 0;
2547
}
2548
 
7 7u83 2549
tagdef_list
2550
add_tagdef_list(tagdef_list list, tagdef elem, int index)
2 7u83 2551
{
7 7u83 2552
  dec *dp = elem.tg;
2553
  exp old_def = son(dp->dec_u.dec_val.dec_exp);
2 7u83 2554
  exp new_def = elem.def;
7 7u83 2555
  UNUSED(list);
2556
  UNUSED(index);
2557
  if (dp->dec_u.dec_val.processed || new_def == nilexp) {
2 7u83 2558
    return 0;
7 7u83 2559
  }
2 7u83 2560
 
2561
  if (old_def == nilexp ||
7 7u83 2562
      shape_size(sh(new_def)) > shape_size(sh(old_def)) ||
2563
      (name(new_def) != clear_tag && name(old_def) == clear_tag)) {
2564
    son(dp->dec_u.dec_val.dec_exp) = new_def;
2565
    setfather(dp->dec_u.dec_val.dec_exp, elem.def);
2566
  }
2 7u83 2567
 
2568
  return 0;
2569
}
2570
 
7 7u83 2571
tdfident_list
2572
new_tdfident_list(int n)
2 7u83 2573
{
2574
  tdfstring_list res;
2575
  res.elems = (tdfstring *)xcalloc(n, sizeof(tdfstring));
2576
  res.number = n;
2577
  return res;
2578
}
2579
 
7 7u83 2580
tdfident_list
2581
add_tdfident_list(tdfident_list list, tdfident elem, int index)
2 7u83 2582
{
2583
  list.elems[index] = elem;
2584
  return list;
2585
}
2586
 
7 7u83 2587
tdfint_list
2588
new_tdfint_list(int n)
2 7u83 2589
{
2590
  tdfint_list res;
2591
  res.members = (tdfint *)xcalloc(n, sizeof(tdfint));
2592
  res.number = n;
2593
  return res;
2594
}
2595
 
7 7u83 2596
tdfint_list
2597
add_tdfint_list(tdfint_list list, tdfint elem, int index)
2 7u83 2598
{
2599
  list.members[index] = elem;
2600
  return list;
2601
}
2602
 
7 7u83 2603
group_list
2604
new_group_list(int n)
2 7u83 2605
{
2606
  UNUSED(n);
2607
  crt_group_type = group_type(crt_capsule_groups[0].ints.chars);
2608
  return 0;
2609
}
2610
 
7 7u83 2611
group_list
2612
add_group_list(group_list list, group elem, int index)
2 7u83 2613
{
7 7u83 2614
  UNUSED(list);
2615
  UNUSED(elem);
2616
  if (index < (crt_capsule_group_no - 1)) {
2617
    crt_group_type = group_type(crt_capsule_groups[index + 1].ints.chars);
2618
  }
2 7u83 2619
  return 0;
2620
}
2621
 
7 7u83 2622
links_list
2623
new_links_list(int n)
2 7u83 2624
{
2625
  UNUSED(n);
7 7u83 2626
  if (crt_capsule_link_no != 0) {
2 7u83 2627
    crt_links_type = links_type(crt_capsule_linking.members[0].id);
7 7u83 2628
  }
2 7u83 2629
  return 0;
2630
}
2631
 
7 7u83 2632
links_list
2633
add_links_list(links_list list, links elem, int index)
2 7u83 2634
{
7 7u83 2635
  UNUSED(list);
2636
  UNUSED(elem);
2637
  if (index < (crt_capsule_linking.number - 1)) {
2638
    crt_links_type = links_type(crt_capsule_linking.members[index + 1].id);
2639
  }
2 7u83 2640
  return 0;
2641
}
2642
 
7 7u83 2643
extern_link_list
2644
new_extern_link_list(int n)
2 7u83 2645
{
2646
  UNUSED(n);
7 7u83 2647
  if (crt_capsule_link_no != 0) {
2 7u83 2648
    crt_extern_link_type = links_type(crt_capsule_linking.members[0].id);
7 7u83 2649
  }
2 7u83 2650
  return 0;
2651
}
2652
 
7 7u83 2653
extern_link_list
2654
add_extern_link_list(extern_link_list list, extern_link elem, int index)
2 7u83 2655
{
7 7u83 2656
  UNUSED(list);
2657
  UNUSED(elem);
2658
  if (index < (crt_capsule_linking.number - 1)) {
2659
    crt_extern_link_type =
2660
	links_type(crt_capsule_linking.members[index + 1].id);
2661
  }
2 7u83 2662
  return 0;
2663
}
2664
 
7 7u83 2665
capsule_link_list
2666
new_capsule_link_list(int n)
2 7u83 2667
{
2668
  capsule_link_list res;
2669
  res.members = (capsule_link *)xcalloc(n, sizeof(capsule_link));
2670
  res.number = n;
2671
  return res;
2672
}
2673
 
7 7u83 2674
capsule_link_list
2675
add_capsule_link_list(capsule_link_list list, capsule_link elem, int index)
2 7u83 2676
{
2677
  list.members[index] = elem;
2678
  return list;
2679
}
2680
 
7 7u83 2681
unit_list
2682
new_unit_list(int n)
2 7u83 2683
{
2684
  UNUSED(n);
2685
  return 0;
2686
}
2687
 
7 7u83 2688
unit_list
2689
add_unit_list(unit_list list, unit elem, int index)
2 7u83 2690
{
7 7u83 2691
  UNUSED(list);
2692
  UNUSED(elem);
2693
  UNUSED(index);
2 7u83 2694
  return 0;
2695
}
2696
 
7 7u83 2697
link_list
2698
new_link_list(int n)
2 7u83 2699
{
2700
  int i;
2701
  switch (crt_links_type)
2702
   {
2703
       /* initialise the table */
2704
     case TOK_TYPE:
2705
       no_of_local_tokens = unit_no_of_tokens - n;
2706
       unit_toktab = (tok_define *)xcalloc(no_of_local_tokens,
7 7u83 2707
					   sizeof(tok_define));
2 7u83 2708
       for (i = 0; i < no_of_local_tokens; ++i) {
7 7u83 2709
         tok_define *tp = &unit_toktab[i];
2710
         tp->tok_special = 0;
2711
         tp->valpresent = 0;
2712
         tp->unit_number = crt_tagdef_unit_no;
2713
         tp->defined = 0;
2714
         tp->tok_index = i;
2715
         tp->is_capsule_token = 0;
2716
         tp->recursive = 0;
2717
       }
2 7u83 2718
       return 0;
2719
     case TAG_TYPE:
7 7u83 2720
       unit_tagtab = (dec *)xcalloc(unit_no_of_tags - n, sizeof(dec));
2 7u83 2721
       for (i = 0; i < unit_no_of_tags - n; ++i) {
7 7u83 2722
         dec *dp = &unit_tagtab[i];
2723
         dp->dec_u.dec_val.dec_outermost = 0;
2724
         dp->dec_u.dec_val.dec_id = (char *)0;
2725
         dp->dec_u.dec_val.extnamed = 0;
2726
         dp->dec_u.dec_val.diag_info = (diag_global *)0;
2727
         dp->dec_u.dec_val.have_def = 0;
2728
         dp->dec_u.dec_val.dec_shape = nilexp;
2729
         dp->dec_u.dec_val.processed = 0;
2730
         dp->dec_u.dec_val.isweak = 0;
2731
         dp->dec_u.dec_val.dec_exp = nilexp;
2732
       }
2 7u83 2733
       return 0;
2734
     case AL_TYPE:
7 7u83 2735
       unit_altab = (aldef *)xcalloc(unit_no_of_als - n, sizeof(aldef));
2 7u83 2736
       for (i = 0; i < unit_no_of_als - n; ++i) {
7 7u83 2737
         aldef *ap = &unit_altab[i];
2738
         ap->al.al_n = 0;
2739
       }
2 7u83 2740
       return 0;
2741
     case DIAGTAG_TYPE:		/* OLD DIAGS */
2742
       init_unit_diagtags(n);
2743
       return 0;
2744
     case DGTAG_TYPE:		/* NEW DIAGS */
2745
       init_unit_dgtags(n);
2746
       return 0;
2747
     default:
2748
       failer(LINK_TYPE);
2749
       return 0;
7 7u83 2750
   }
2 7u83 2751
}
2752
 
7 7u83 2753
link_list
2754
add_link_list(link_list list, link elem, int index)
2 7u83 2755
{
7 7u83 2756
  UNUSED(list);
2757
  UNUSED(elem);
2758
  UNUSED(index);
2 7u83 2759
  return 0;
2760
}
2761
 
7 7u83 2762
linkextern_list
2763
new_linkextern_list(int n)
2 7u83 2764
{
2765
  UNUSED(n);
2766
  return 0;
2767
}
2768
 
7 7u83 2769
linkextern_list
2770
add_linkextern_list(linkextern_list list, linkextern elem, int index)
2 7u83 2771
{
7 7u83 2772
  UNUSED(list);
2773
  UNUSED(elem);
2774
  UNUSED(index);
2 7u83 2775
  return 0;
2776
}
2777
 
2778
exp_option no_exp_option;
2779
 
7 7u83 2780
exp_option
2781
yes_exp_option(exp elem)
2 7u83 2782
{
2783
  exp_option res;
2784
  res.present = 1;
2785
  res.val = elem;
2786
  return res;
2787
}
2788
 
7 7u83 2789
void
2790
init_exp_option(void)
2 7u83 2791
{
2792
   no_exp_option.present = 0;
2793
   return;
2794
}
2795
 
2796
tag_option no_tag_option;
2797
 
7 7u83 2798
tag_option
2799
yes_tag_option(tag elem)
2 7u83 2800
{
2801
  tag_option res;
2802
  res.present = 1;
2803
  res.val = elem;
2804
  return res;
2805
}
2806
 
7 7u83 2807
void
2808
init_tag_option(void)
2 7u83 2809
{
2810
   no_tag_option.present = 0;
2811
   return;
2812
}
2813
 
7 7u83 2814
void
2815
init_capsule_link(void)
2 7u83 2816
{
2817
  return;
2818
}
2819
 
2820
 
7 7u83 2821
void
2822
init_extern_link(void)
2 7u83 2823
{
2824
  return;
2825
}
2826
 
7 7u83 2827
void
2828
init_group(void)
2 7u83 2829
{
2830
  return;
2831
}
2832
 
7 7u83 2833
void
2834
init_unit(void)
2 7u83 2835
{
2836
  return;
2837
}
2838
 
7 7u83 2839
void
2840
init_link(void)
2 7u83 2841
{
2842
  return;
2843
}
2844
 
7 7u83 2845
void
2846
init_linkextern(void)
2 7u83 2847
{
2848
  return;
2849
}
2850
 
7 7u83 2851
void
2852
init_links(void)
2 7u83 2853
{
2854
  return;
2855
}
2856
 
7 7u83 2857
void
2858
init_tagdec_props(void)
2 7u83 2859
{
2860
  return;
2861
}
2862
 
7 7u83 2863
void
2864
init_tagdef_props(void)
2 7u83 2865
{
2866
  return;
2867
}
2868
 
7 7u83 2869
void
2870
init_al_tagdef_props(void)
2 7u83 2871
{
2872
  return;
2873
}
2874
 
7 7u83 2875
void
2876
init_tokdec_props(void)
2 7u83 2877
{
2878
  return;
2879
}
2880
 
7 7u83 2881
void
2882
init_tokdef_props(void)
2 7u83 2883
{
2884
  return;
2885
}