Subversion Repositories tendra.SVN

Rev

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

Rev 2 Rev 7
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-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
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
32
    		 Crown Copyright (c) 1997
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
Line 31... Line 61...
31
#include "config.h"
61
#include "config.h"
32
#include "types.h"
62
#include "types.h"
33
#include "check.h"
63
#include "check.h"
34
#include "de_types.h"
64
#include "de_types.h"
35
#include "de_capsule.h"
65
#include "de_capsule.h"
-
 
66
#include "de_unit.h"
36
#include "decode.h"
67
#include "decode.h"
37
#include "fetch.h"
68
#include "fetch.h"
38
#include "high.h"
69
#include "high.h"
39
#include "node.h"
70
#include "node.h"
40
#include "table.h"
71
#include "table.h"
Line 46... Line 77...
46
    ARRAY OF ALL LABELS
77
    ARRAY OF ALL LABELS
47
 
78
 
48
    The labels in a unit are held in the table labels of size max_lab_no.
79
    The labels in a unit are held in the table labels of size max_lab_no.
49
*/
80
*/
50
 
81
 
51
static long max_lab_no = 0 ;
82
static long max_lab_no = 0;
52
static construct *labels ;
83
static construct *labels;
53
 
84
 
54
 
85
 
55
/*
86
/*
56
    SET UP LABELS
87
    SET UP LABELS
57
 
88
 
58
    A table of n labels is allocated and initialized.
89
    A table of n labels is allocated and initialized.
59
*/
90
*/
60
 
91
 
61
static void set_up_labels
92
static void
62
    PROTO_N ( ( n ) )
-
 
63
    PROTO_T ( long n )
93
set_up_labels(long n)
64
{
94
{
65
    long i ;
95
    long i;
66
    static long lno = 0 ;
96
    static long lno = 0;
67
    max_lab_no = n ;
97
    max_lab_no = n;
68
    labels = alloc_nof ( construct, n ) ;
98
    labels = alloc_nof(construct, n);
69
    for ( i = 0 ; i < n ; i++ ) {
99
    for (i = 0; i < n; i++) {
70
	char *nm = alloc_nof ( char, 32 ) ;
100
	char *nm = alloc_nof(char, 32);
71
	IGNORE sprintf ( nm, "~~label_%ld", lno ) ;
101
	IGNORE sprintf(nm, "~~label_%ld", lno);
72
	labels [i].sortnum = SORT_label ;
102
	labels[i].sortnum = SORT_label;
73
	labels [i].encoding = lno++ ;
103
	labels[i].encoding = lno++;
74
	labels [i].name = nm ;
104
	labels[i].name = nm;
75
	labels [i].alias = null ;
105
	labels[i].alias = null;
76
	labels [i].next = null ;
106
	labels[i].next = null;
77
	if ( add_to_var_hash ( labels + i, SORT_label ) ) {
107
	if (add_to_var_hash(labels + i, SORT_label)) {
78
	    input_error ( "Label %s already defined", nm ) ;
108
	    input_error("Label %s already defined", nm);
79
	}
109
	}
80
    }
110
    }
81
    return ;
111
    return;
82
}
112
}
83
 
113
 
84
 
114
 
85
/*
115
/*
86
    FIND A LABEL
116
    FIND A LABEL
87
 
117
 
88
    The nth label in the current unit is returned.
118
    The nth label in the current unit is returned.
89
*/
119
*/
90
 
120
 
91
construct *find_label
121
construct *
92
    PROTO_N ( ( n ) )
-
 
93
    PROTO_T ( long n )
122
find_label(long n)
94
{
123
{
95
    if ( n < 0 || n >= max_lab_no ) {
124
    if (n < 0 || n >= max_lab_no) {
96
	input_error ( "Label number %ld too big", n ) ;
125
	input_error("Label number %ld too big", n);
97
	return ( null ) ;
126
	return(null);
98
    }
127
    }
99
    return ( labels + n ) ;
128
    return(labels + n);
100
}
129
}
101
 
130
 
102
 
131
 
103
/*
132
/*
104
    DECODE A SORT NAME
133
    DECODE A SORT NAME
105
 
134
 
106
    A sortname is decoded.  If expand is true the arguments of any high
135
    A sortname is decoded.  If expand is true the arguments of any high
107
    level sort will be stepped over.
136
    level sort will be stepped over.
108
*/
137
*/
109
 
138
 
110
static sortname de_sortname
139
static sortname
111
    PROTO_N ( ( expand ) )
-
 
112
    PROTO_T ( boolean expand )
140
de_sortname(boolean expand)
113
{
141
{
114
    long n = de_sortname_bits () ;
142
    long n = de_sortname_bits();
115
    if ( n == SORT_token && expand ) {
143
    if (n == SORT_token && expand) {
116
	long i, m ;
144
	long i, m;
117
	high_sort h, *hp ;
145
	high_sort h, *hp;
118
	static int made_up_sorts = 0 ;
146
	static int made_up_sorts = 0;
119
	h.res = de_sortname ( 1 ) ;
147
	h.res = de_sortname(1);
120
	de_list_start () ;
148
	de_list_start();
121
	m = tdf_int () ;
149
	m = tdf_int();
122
	h.no_args = ( int ) m ;
150
	h.no_args = (int)m;
123
	h.args = alloc_nof ( sortname, m ) ;
151
	h.args = alloc_nof(sortname, m);
124
	h.name = alloc_nof ( char, 32 ) ;
152
	h.name = alloc_nof(char, 32);
125
	IGNORE sprintf ( h.name, "~~sort_%d", made_up_sorts++ ) ;
153
	IGNORE sprintf(h.name, "~~sort_%d", made_up_sorts++);
126
	for ( i = 0 ; i < m ; i++ ) {
154
	for (i = 0; i < m; i++) {
127
	    h.args [i] = de_sortname ( 1 ) ;
155
	    h.args[i] = de_sortname(1);
128
	}
156
	}
129
	hp = new_high_sort ( &h ) ;
157
	hp = new_high_sort(&h);
130
	hp = unique_high_sort ( hp ) ;
158
	hp = unique_high_sort(hp);
131
	return ( hp->id ) ;
159
	return(hp->id);
132
    }
160
    }
133
    if ( n == SORT_foreign ) {
161
    if (n == SORT_foreign) {
134
	warning ( "Foreign sorts not supported" ) ;
162
	warning("Foreign sorts not supported");
135
	IGNORE de_node ( "X" ) ;
163
	IGNORE de_node("X");
136
	return ( SORT_unknown ) ;
164
	return(SORT_unknown);
137
    }
165
    }
138
    return ( ( sortname ) n ) ;
166
    return((sortname)n);
139
}
167
}
140
 
168
 
141
 
169
 
142
/*
170
/*
143
    DECODE AN ALIGNMENT TAG DEFINITION UNIT
171
    DECODE AN ALIGNMENT TAG DEFINITION UNIT
144
 
172
 
145
    A number of alignment tag definitions are decoded.
173
    A number of alignment tag definitions are decoded.
146
*/
174
*/
147
 
175
 
148
void de_aldef
176
void
149
    PROTO_Z ()
177
de_aldef(void)
150
{
178
{
151
    long i, n = tdf_int () ;
179
    long i, n = tdf_int();
152
    set_up_labels ( n ) ;
180
    set_up_labels(n);
153
    n = tdf_int () ;
181
    n = tdf_int();
154
    for ( i = 0 ; i < n ; i++ ) {
182
    for (i = 0; i < n; i++) {
155
	long t ;
183
	long t;
156
	node *d ;
184
	node *d;
157
	construct *p ;
185
	construct *p;
158
	al_tag_info *info ;
186
	al_tag_info *info;
159
 
187
 
160
	/* Find the definition type */
188
	/* Find the definition type */
161
	IGNORE de_al_tagdef_bits () ;
189
	IGNORE de_al_tagdef_bits();
162
 
190
 
163
	/* Find the alignment tag */
191
	/* Find the alignment tag */
164
	t = tdf_int () ;
192
	t = tdf_int();
165
	p = find_binding ( crt_binding, al_tag_var, t ) ;
193
	p = find_binding(crt_binding, al_tag_var, t);
166
	info = get_al_tag_info ( p ) ;
194
	info = get_al_tag_info(p);
167
 
195
 
168
	/* Decode the definition (an alignment) */
196
	/* Decode the definition (an alignment) */
169
	d = completion ( de_alignment () ) ;
197
	d = completion(de_alignment());
170
	if ( info->def ) {
198
	if (info->def) {
171
	    if ( !eq_node ( info->def, d ) ) {
199
	    if (!eq_node(info->def, d)) {
172
		is_fatal = 0 ;
200
		is_fatal = 0;
173
		input_error ( "Alignment tag %s defined inconsistently",
201
		input_error("Alignment tag %s defined inconsistently",
174
			      p->name ) ;
202
			      p->name);
175
	    }
203
	    }
176
	    free_node ( d ) ;
204
	    free_node(d);
177
	} else {
205
	} else {
178
	    info->def = d ;
206
	    info->def = d;
179
	}
207
	}
180
    }
208
    }
181
    return ;
209
    return;
182
}
210
}
183
 
211
 
184
 
212
 
185
/*
213
/*
186
    DECODE A TAG DECLARATION UNIT
214
    DECODE A TAG DECLARATION UNIT
187
 
215
 
188
    A number of tag declarations are decoded.
216
    A number of tag declarations are decoded.
189
*/
217
*/
190
 
218
 
191
void de_tagdec
219
void
192
    PROTO_Z ()
220
de_tagdec(void)
193
{
221
{
194
    long i, n = tdf_int () ;
222
    long i, n = tdf_int();
195
    set_up_labels ( n ) ;
223
    set_up_labels(n);
196
    n = tdf_int () ;
224
    n = tdf_int();
197
    for ( i = 0 ; i < n ; i++ ) {
225
    for (i = 0; i < n; i++) {
198
	long t ;
226
	long t;
199
	node *d ;
227
	node *d;
200
	boolean is_var ;
228
	boolean is_var;
201
	construct *p ;
229
	construct *p;
202
	tag_info *info ;
230
	tag_info *info;
203
 
231
 
204
	/* Find the declaration type */
232
	/* Find the declaration type */
205
	long m = de_tagdec_bits () ;
233
	long m = de_tagdec_bits();
206
	if ( m == ENC_make_id_tagdec ) {
234
	if (m == ENC_make_id_tagdec) {
207
	    is_var = 0 ;
235
	    is_var = 0;
208
	} else if ( m == ENC_make_var_tagdec ) {
236
	} else if (m == ENC_make_var_tagdec) {
209
	    is_var = 1 ;
237
	    is_var = 1;
210
	} else {
238
	} else {
211
	    is_var = 2 ;
239
	    is_var = 2;
212
	}
240
	}
213
 
241
 
214
	/* Find the tag */
242
	/* Find the tag */
215
	t = tdf_int () ;
243
	t = tdf_int();
216
	p = find_binding ( crt_binding, tag_var, t ) ;
244
	p = find_binding(crt_binding, tag_var, t);
217
	set_tag_type ( p, is_var ) ;
245
	set_tag_type(p, is_var);
218
	info = get_tag_info ( p ) ;
246
	info = get_tag_info(p);
219
 
247
 
220
	/* Declaration = optional access + optional string + shape from 4.0 */
248
	/* Declaration = optional access + optional string + shape from 4.0 */
221
	d = completion ( de_node ( "?[u]?[X]S" ) ) ;
249
	d = completion(de_node("?[u]?[X]S"));
222
	info->var = is_var ;
250
	info->var = is_var;
223
	if ( info->dec ) {
251
	if (info->dec) {
224
	    if ( !eq_node ( info->dec, d ) ) {
252
	    if (!eq_node(info->dec, d)) {
225
		is_fatal = 0 ;
253
		is_fatal = 0;
226
		input_error ( "Tag %s declared inconsistently", p->name ) ;
254
		input_error("Tag %s declared inconsistently", p->name);
227
	    }
255
	    }
228
	    free_node ( d ) ;
256
	    free_node(d);
229
	} else {
257
	} else {
230
	    info->dec = d ;
258
	    info->dec = d;
231
	}
259
	}
232
    }
260
    }
233
    return ;
261
    return;
234
}
262
}
235
 
263
 
236
 
264
 
237
/*
265
/*
238
    DECODE A TAG DEFINITION UNIT
266
    DECODE A TAG DEFINITION UNIT
239
 
267
 
240
    A number of tag definitions are decoded.
268
    A number of tag definitions are decoded.
241
*/
269
*/
242
 
270
 
243
void de_tagdef
271
void
244
    PROTO_Z ()
272
de_tagdef(void)
245
{
273
{
246
    long i, n = tdf_int () ;
274
    long i, n = tdf_int();
247
    set_up_labels ( n ) ;
275
    set_up_labels(n);
248
    n = tdf_int () ;
276
    n = tdf_int();
249
    for ( i = 0 ; i < n ; i++ ) {
277
    for (i = 0; i < n; i++) {
250
	long t ;
278
	long t;
251
	node *d ;
279
	node *d;
252
	construct *p ;
280
	construct *p;
253
	tag_info *info ;
281
	tag_info *info;
254
	boolean is_var ;
282
	boolean is_var;
255
 
283
 
256
	/* Find the definition type */
284
	/* Find the definition type */
257
	long m = de_tagdef_bits () ;
285
	long m = de_tagdef_bits();
258
	if ( m == ENC_make_id_tagdef ) {
286
	if (m == ENC_make_id_tagdef) {
259
	    is_var = 0 ;
287
	    is_var = 0;
260
	} else if ( m == ENC_make_var_tagdef ) {
288
	} else if (m == ENC_make_var_tagdef) {
261
	    is_var = 1 ;
289
	    is_var = 1;
262
	} else {
290
	} else {
263
	    is_var = 2 ;
291
	    is_var = 2;
264
	}
292
	}
265
 
293
 
266
	/* Find the tag */
294
	/* Find the tag */
267
	t = tdf_int () ;
295
	t = tdf_int();
268
	p = find_binding ( crt_binding, tag_var, t ) ;
296
	p = find_binding(crt_binding, tag_var, t);
269
	info = get_tag_info ( p ) ;
297
	info = get_tag_info(p);
270
	if ( info->dec == null ) {
298
	if (info->dec == null) {
271
	    input_error ( "Tag %s defined but not declared", p->name ) ;
299
	    input_error("Tag %s defined but not declared", p->name);
272
	}
300
	}
273
	set_tag_type ( p, is_var ) ;
301
	set_tag_type(p, is_var);
274
 
302
 
275
	/* Added signature in 4.0 */
303
	/* Added signature in 4.0 */
276
	d = completion ( de_node ( is_var ? "?[u]?[X]x" : "?[X]x" ) ) ;
304
	d = completion(de_node(is_var ? "?[u]?[X]x" : "?[X]x"));
277
	info->var = is_var ;
305
	info->var = is_var;
278
	if ( info->def ) {
306
	if (info->def) {
279
	    if ( is_var == 2 ) {
307
	    if (is_var == 2) {
280
		node *dp = info->def ;
308
		node *dp = info->def;
281
		while ( dp->bro ) dp = dp->bro ;
309
		while (dp->bro)dp = dp->bro;
282
		dp->bro = d ;
310
		dp->bro = d;
283
	    } else {
311
	    } else {
284
		if ( !eq_node ( info->def, d ) ) {
312
		if (!eq_node(info->def, d)) {
285
		    is_fatal = 0 ;
313
		    is_fatal = 0;
286
		    input_error ( "Tag %s defined inconsistently", p->name ) ;
314
		    input_error("Tag %s defined inconsistently", p->name);
287
		}
315
		}
288
		free_node ( d ) ;
316
		free_node(d);
289
	    }
317
	    }
290
	} else {
318
	} else {
291
	    info->def = d ;
319
	    info->def = d;
292
	    if ( do_check ) check_tagdef ( p ) ;
320
	    if (do_check)check_tagdef(p);
293
	}
321
	}
294
    }
322
    }
295
    return ;
323
    return;
296
}
324
}
297
 
325
 
298
 
326
 
299
/*
327
/*
300
    DECODE A TOKEN DECLARATION UNIT
328
    DECODE A TOKEN DECLARATION UNIT
301
 
329
 
302
    A number of token declarations are decoded.
330
    A number of token declarations are decoded.
303
*/
331
*/
304
 
332
 
305
void de_tokdec
333
void
306
    PROTO_Z ()
334
de_tokdec(void)
307
{
335
{
308
    long i, n = tdf_int () ;
336
    long i, n = tdf_int();
309
    for ( i = 0 ; i < n ; i++ ) {
337
    for (i = 0; i < n; i++) {
310
	long t ;
338
	long t;
311
	node *sig ;
339
	node *sig;
312
	char *args ;
340
	char *args;
313
	sortname rs ;
341
	sortname rs;
314
	construct *p ;
342
	construct *p;
315
	tok_info *info ;
343
	tok_info *info;
316
 
344
 
317
	/* Find the declaration type */
345
	/* Find the declaration type */
318
	IGNORE de_tokdec_bits () ;
346
	IGNORE de_tokdec_bits();
319
 
347
 
320
	/* Find the token */
348
	/* Find the token */
321
	t = tdf_int () ;
349
	t = tdf_int();
322
	p = find_binding ( crt_binding, tok_var, t ) ;
350
	p = find_binding(crt_binding, tok_var, t);
323
	info = get_tok_info ( p ) ;
351
	info = get_tok_info(p);
324
 
352
 
325
	/* Deal with signature */
353
	/* Deal with signature */
326
	sig = de_node ( "?[X]" ) ;
354
	sig = de_node("?[X]");
327
 
355
 
328
	/* Decode token sort */
356
	/* Decode token sort */
329
	rs = de_sortname ( 0 ) ;
357
	rs = de_sortname(0);
330
	if ( rs == SORT_token ) {
358
	if (rs == SORT_token) {
331
	    long m ;
359
	    long m;
332
	    rs = de_sortname ( 1 ) ;
360
	    rs = de_sortname(1);
333
	    de_list_start () ;
361
	    de_list_start();
334
	    m = tdf_int () ;
362
	    m = tdf_int();
335
	    if ( m == 0 ) {
363
	    if (m == 0) {
336
		args = null ;
364
		args = null;
337
	    } else {
365
	    } else {
338
		long j ;
366
		long j;
339
		char abuff [100], *a = abuff ;
367
		char abuff[100], *a = abuff;
340
		for ( j = 0 ; j < m ; j++ ) {
368
		for (j = 0; j < m; j++) {
341
		    sortname ps = de_sortname ( 1 ) ;
369
		    sortname ps = de_sortname(1);
342
		    if ( is_high ( ps ) ) {
370
		    if (is_high(ps)) {
343
			sprint_high_sort ( a, ps ) ;
371
			sprint_high_sort(a, ps);
344
			while ( *a ) a++ ;
372
			while (*a)a++;
345
		    } else {
373
		    } else {
346
			*( a++ ) = sort_letters [ps] ;
374
			*(a++) = sort_letters[ps];
347
		    }
375
		    }
348
		}
376
		}
349
		*a = 0 ;
377
		*a = 0;
350
		args = string_copy_aux ( abuff ) ;
378
		args = string_copy_aux(abuff);
351
	    }
379
	    }
352
	} else {
380
	} else {
353
	    args = null ;
381
	    args = null;
354
	}
382
	}
355
	if ( is_high ( rs ) ) {
383
	if (is_high(rs)) {
356
	    input_error ( "Token %s has high-level result sort", p->name ) ;
384
	    input_error("Token %s has high-level result sort", p->name);
357
	}
385
	}
358
	set_token_sort ( p, rs, args, sig ) ;
386
	set_token_sort(p, rs, args, sig);
359
	info->dec = 1 ;
387
	info->dec = 1;
360
    }
388
    }
361
    return ;
389
    return;
362
}
390
}
363
 
391
 
364
 
392
 
365
/*
393
/*
366
    DECODE A TOKEN DEFINITION BODY
394
    DECODE A TOKEN DEFINITION BODY
367
 
395
 
368
    The actual body of a token definition is decoded.
396
    The actual body of a token definition is decoded.
369
*/
397
*/
370
 
398
 
371
void de_token_defn
399
void
372
    PROTO_N ( ( p, sig ) )
-
 
373
    PROTO_T ( construct *p X node *sig )
400
de_token_defn(construct *p, node *sig)
374
{
401
{
375
    long m ;
402
    long m;
376
    node *d ;
403
    node *d;
377
    char *args ;
404
    char *args;
378
    sortname rs ;
405
    sortname rs;
379
    tok_info *info = get_tok_info ( p ) ;
406
    tok_info *info = get_tok_info(p);
380
    construct **old_pars = info->pars ;
407
    construct **old_pars = info->pars;
381
 
408
 
382
    /* Find the end of the definition */
409
    /* Find the end of the definition */
383
    long end_posn = tdf_int () ;
410
    long end_posn = tdf_int();
384
    end_posn += input_posn () ;
411
    end_posn += input_posn();
385
 
412
 
386
    /* Find the definition type */
413
    /* Find the definition type */
387
    IGNORE de_token_defn_bits () ;
414
    IGNORE de_token_defn_bits();
388
 
415
 
389
    /* Decode the token sort */
416
    /* Decode the token sort */
390
    rs = de_sortname ( 1 ) ;
417
    rs = de_sortname(1);
391
    de_list_start () ;
418
    de_list_start();
392
    m = tdf_int () ;
419
    m = tdf_int();
393
    if ( m == 0 ) {
420
    if (m == 0) {
394
	args = null ;
421
	args = null;
395
    } else {
422
    } else {
396
	long j ;
423
	long j;
397
	char abuff [100], *a = abuff ;
424
	char abuff[100], *a = abuff;
398
	if ( !in_skip_pass ) {
425
	if (!in_skip_pass) {
399
	    info->pars = alloc_nof ( construct *, m + 1 ) ;
426
	    info->pars = alloc_nof(construct *, m + 1);
400
	}
427
	}
401
	for ( j = 0 ; j < m ; j++ ) {
428
	for (j = 0; j < m; j++) {
402
	    /* Decode the token arguments */
429
	    /* Decode the token arguments */
403
	    sortname ps = de_sortname ( 1 ) ;
430
	    sortname ps = de_sortname(1);
404
	    long pn = tdf_int () ;
431
	    long pn = tdf_int();
405
	    construct *q = find_binding ( crt_binding, tok_var, pn ) ;
432
	    construct *q = find_binding(crt_binding, tok_var, pn);
406
	    set_token_sort ( q, ps, ( char * ) null, ( node * ) null ) ;
433
	    set_token_sort(q, ps,(char *)null,(node *)null);
407
	    if ( is_high ( ps ) ) {
434
	    if (is_high(ps)) {
408
		sprint_high_sort ( a, ps ) ;
435
		sprint_high_sort(a, ps);
409
		while ( *a ) a++ ;
436
		while (*a)a++;
410
	    } else {
437
	    } else {
411
		*( a++ ) = sort_letters [ps] ;
438
		*(a++) = sort_letters[ps];
412
	    }
439
	    }
413
	    if ( !in_skip_pass ) info->pars [j] = q ;
440
	    if (!in_skip_pass)info->pars[j] = q;
414
	}
441
	}
415
	*a = 0 ;
442
	*a = 0;
416
	args = string_copy_aux ( abuff ) ;
443
	args = string_copy_aux(abuff);
417
	if ( !in_skip_pass ) info->pars [j] = null ;
444
	if (!in_skip_pass)info->pars[j] = null;
418
    }
445
    }
419
    if ( is_high ( rs ) ) {
446
    if (is_high(rs)) {
420
	input_error ( "Token %s has high-level result sort", p->name ) ;
447
	input_error("Token %s has high-level result sort", p->name);
421
    }
448
    }
422
    set_token_sort ( p, rs, args, sig ) ;
449
    set_token_sort(p, rs, args, sig);
423
    info->dec = 1 ;
450
    info->dec = 1;
424
 
451
 
425
    /* Decode the actual definition */
452
    /* Decode the actual definition */
426
    if ( in_skip_pass ) {
453
    if (in_skip_pass) {
427
	long bits = end_posn - input_posn () ;
454
	long bits = end_posn - input_posn();
428
	input_skip ( bits ) ;
455
	input_skip(bits);
429
    } else {
456
    } else {
430
	char buff [2] ;
457
	char buff[2];
431
	buff [0] = sort_letters [rs] ;
458
	buff[0] = sort_letters[rs];
432
	buff [1] = 0 ;
459
	buff[1] = 0;
433
	d = completion ( de_node ( buff ) ) ;
460
	d = completion(de_node(buff));
434
	if ( info->def ) {
461
	if (info->def) {
435
	    if ( !eq_node ( info->def, d ) ) {
462
	    if (!eq_node(info->def, d)) {
436
		is_fatal = 0 ;
463
		is_fatal = 0;
437
		input_error ( "Token %s defined inconsistently",
464
		input_error("Token %s defined inconsistently",
438
			      p->name ) ;
465
			      p->name);
439
	    }
466
	    }
440
	    free_node ( d ) ;
467
	    free_node(d);
441
	    info->pars = old_pars ;
468
	    info->pars = old_pars;
442
	} else {
469
	} else {
443
	    info->def = d ;
470
	    info->def = d;
444
	}
471
	}
445
	if ( rs == SORT_unknown ) {
472
	if (rs == SORT_unknown) {
446
	    long bits = end_posn - input_posn () ;
473
	    long bits = end_posn - input_posn();
447
	    input_skip ( bits ) ;
474
	    input_skip(bits);
448
	}
475
	}
449
	if ( input_posn () != end_posn ) {
476
	if (input_posn()!= end_posn) {
450
	    input_error ( "Token %s definition length wrong", p->name ) ;
477
	    input_error("Token %s definition length wrong", p->name);
451
	}
478
	}
452
	if ( info->pars ) {
479
	if (info->pars) {
453
	    /* Mark the formal arguments as unused */
480
	    /* Mark the formal arguments as unused */
454
	    construct **ps ;
481
	    construct **ps;
455
	    for ( ps = info->pars ; *ps ; ps++ ) {
482
	    for (ps = info->pars; *ps; ps++) {
456
		info = get_tok_info ( *ps ) ;
483
		info = get_tok_info(*ps);
457
		info->dec = 0 ;
484
		info->dec = 0;
458
	    }
485
	    }
459
	}
486
	}
460
    }
487
    }
461
    return ;
488
    return;
462
}
489
}
463
 
490
 
464
 
491
 
465
/*
492
/*
466
    DECODE A TOKEN DEFINITION UNIT
493
    DECODE A TOKEN DEFINITION UNIT
467
 
494
 
468
    A number of token definitions are decoded.
495
    A number of token definitions are decoded.
469
*/
496
*/
470
 
497
 
471
void de_tokdef
498
void
472
    PROTO_Z ()
499
de_tokdef(void)
473
{
500
{
474
    long i, n = tdf_int () ;
501
    long i, n = tdf_int();
475
    set_up_labels ( n ) ;
502
    set_up_labels(n);
476
    n = tdf_int () ;
503
    n = tdf_int();
477
    for ( i = 0 ; i < n ; i++ ) {
504
    for (i = 0; i < n; i++) {
478
	long t ;
505
	long t;
479
	node *sig ;
506
	node *sig;
480
	construct *p ;
507
	construct *p;
481
 
508
 
482
	/* Find the definition type */
509
	/* Find the definition type */
483
	IGNORE de_tokdef_bits () ;
510
	IGNORE de_tokdef_bits();
484
 
511
 
485
	/* Find the token */
512
	/* Find the token */
486
	t = tdf_int () ;
513
	t = tdf_int();
487
	p = find_binding ( crt_binding, tok_var, t ) ;
514
	p = find_binding(crt_binding, tok_var, t);
488
 
515
 
489
	/* Deal with signature */
516
	/* Deal with signature */
490
	sig = de_node ( "?[X]" ) ;
517
	sig = de_node("?[X]");
491
 
518
 
492
	/* Decode token definition */
519
	/* Decode token definition */
493
	de_token_defn ( p, sig ) ;
520
	de_token_defn(p, sig);
494
    }
521
    }
495
    return ;
522
    return;
496
}
523
}
497
 
524
 
498
 
525
 
499
/*
526
/*
500
    FLAG
527
    FLAG
501
 
528
 
502
    Has a version number been read?
529
    Has a version number been read?
503
*/
530
*/
504
 
531
 
505
int have_version = 0 ;
532
int have_version = 0;
506
 
533
 
507
 
534
 
508
/*
535
/*
509
    CHECK A VERSION NUMBER
536
    CHECK A VERSION NUMBER
510
 
537
 
511
    This routine reads and checks a version number.
538
    This routine reads and checks a version number.
512
*/
539
*/
513
 
540
 
514
static void de_version_number
541
static void
515
    PROTO_Z ()
542
de_version_number(void)
516
{
543
{
517
    long v1 = tdf_int () ;
544
    long v1 = tdf_int();
518
    long v2 = tdf_int () ;
545
    long v2 = tdf_int();
519
    if ( v1 != VERSION_major || v2 > VERSION_minor ) {
546
    if (v1 != VERSION_major || v2 > VERSION_minor) {
520
	input_error ( "Illegal version number, %ld.%ld", v1, v2 ) ;
547
	input_error("Illegal version number, %ld.%ld", v1, v2);
521
    }
548
    }
522
    have_version = 1 ;
549
    have_version = 1;
523
    return ;
550
    return;
524
}
551
}
525
 
552
 
526
 
553
 
527
/*
554
/*
528
    DECODE A VERSION UNIT
555
    DECODE A VERSION UNIT
529
 
556
 
530
    A number of TDF version numbers are decoded.  These were only
557
    A number of TDF version numbers are decoded.  These were only
531
    introduced for version 2.1 of the TDF specification.
558
    introduced for version 2.1 of the TDF specification.
532
*/
559
*/
533
 
560
 
534
void de_version
561
void
535
    PROTO_Z ()
562
de_version(void)
536
{
563
{
537
    long i, n = tdf_int () ;
564
    long i, n = tdf_int();
538
    for ( i = 0 ; i < n ; i++ ) {
565
    for (i = 0; i < n; i++) {
539
	long m = de_version_bits () ;
566
	long m = de_version_bits();
540
	if ( m == ENC_make_version ) {
567
	if (m == ENC_make_version) {
541
	    de_version_number () ;
568
	    de_version_number();
542
	} else if ( m == ENC_user_info ) {
569
	} else if (m == ENC_user_info) {
543
	    IGNORE de_node ( "X" ) ;
570
	    IGNORE de_node("X");
544
	}
571
	}
545
    }
572
    }
546
    return ;
573
    return;
547
}
574
}
548
 
575
 
549
 
576
 
550
/*
577
/*
551
    DECODE A MAGIC NUMBER
578
    DECODE A MAGIC NUMBER
552
*/
579
*/
553
 
580
 
554
void de_magic
581
void
555
    PROTO_N ( ( m ) )
-
 
556
    PROTO_T ( char *m )
582
de_magic(char *m)
557
{
583
{
558
    int i, n = ( int ) strlen ( m ) ;
584
    int i, n = (int)strlen(m);
559
    for ( i = 0 ; i < n ; i++ ) {
585
    for (i = 0; i < n; i++) {
560
	long c = fetch ( 8 ) ;
586
	long c = fetch(8);
561
	if ( c != ( long ) m [i] ) {
587
	if (c != (long)m[i]) {
562
	    input_error ( "Bad magic number" ) ;
588
	    input_error("Bad magic number");
563
	    return ;
589
	    return;
564
	}
590
	}
565
    }
591
    }
566
    de_version_number () ;
592
    de_version_number();
567
    byte_align () ;
593
    byte_align();
568
    return ;
594
    return;
569
}
595
}