Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – tendra.SVN – Blame – /branches/tendra4/src/tools/disp/capsule.c – Rev 2

Subversion Repositories tendra.SVN

Rev

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

Rev Author Line No. Line
2 7u83 1
/*
2
    		 Crown Copyright (c) 1997
3
 
4
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
12
 
13
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
15
 
16
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
19
 
20
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
22
        these conditions;
23
 
24
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
27
        it may be put.
28
*/
29
 
30
 
31
#include "config.h"
32
#include "types.h"
33
#include "basic.h"
34
#include "binding.h"
35
#include "file.h"
36
#include "sort.h"
37
#include "tdf.h"
38
#include "tree.h"
39
#include "unit.h"
40
#include "utility.h"
41
 
42
 
43
/*
44
    EXPANSION MODE
45
 
46
    The flag dumb_mode determines whether the pretty-printer will
47
    attempt to rationalize its input, or whether it will just blindly
48
    output what it reads.  If show_stuff is true information on the
49
    number of tags and tokens etc will be output.
50
*/
51
 
52
int dumb_mode = 0 ;
53
int show_stuff = 0 ;
54
 
55
 
56
/*
57
    SKIP PASS FOR TOKEN DEFINITIONS FLAG
58
 
59
    Tokens may be defined recursively without the necessary previous
60
    declarations to make this simple.  Thus the token definitions are
61
    given a preliminary pass to extract the declaration information.
62
    This feature can be switch on and off using the skip_pass flag.
63
    If show_skip is true the information read on the skip pass is
64
    displayed.  skipping is true iff we are in the skip pass.
65
*/
66
 
67
int skip_pass = 1 ;
68
int show_skip = 0 ;
69
int skipping = 0 ;
70
 
71
 
72
/*
73
    ARRAYS OF EQUATION AND VARIABLE NAMES
74
 
75
    These arrays store the names of the types of equations (e.g. tokdefs)
76
    and the types of variables these equations are in (e.g. tags and tokens).
77
    The number of types of variables is given by no_variables.
78
*/
79
 
80
string *eqn_types = null ;
81
string *var_types = null ;
82
char *var_letters = "" ;
83
long *var_count = null ;
84
long no_variables = 0 ;
85
 
86
 
87
/*
88
    CURRENT BINDINGS
89
 
90
    The current binding table is given by crt_binding.
91
*/
92
 
93
binding *crt_binding ;
94
 
95
 
96
/*
97
    DECODE AN EXTERNAL LINKAGE
98
 
99
    An external name is decoded and associated with a variable of type v.
100
    r gives the order information.
101
*/
102
 
103
static void de_linkextern
104
    PROTO_N ( ( v, r ) )
105
    PROTO_T ( long v X long r )
106
{
107
    object *p ;
108
    external ext ;
109
    long n = tdf_int () ;
110
    ext = de_extern_name () ;
111
    p = new_object ( v ) ;
112
    set_binding ( crt_binding, v, n, p ) ;
113
    p->named = 1 ;
114
    p->name = ext ;
115
    p->order = r ;
116
    if ( v == var_token && ext.simple ) {
117
	/* Look for special tokens */
118
	char *nm = ext.val.str ;
119
	if ( nm [0] == '~' && diagnostics ) {
120
	    if ( streq ( nm, "~dg_exp" ) ) {
121
		token_sort ( p, sort_exp, "xG", n ) ;
122
	    } else if ( streq ( nm, "~exp_to_source" ) ) {
123
		token_sort ( p, sort_exp, "xMM", n ) ;
124
	    } else if ( streq ( nm, "~diag_id_scope" ) ) {
125
		token_sort ( p, sort_exp, "x$xd", n ) ;
126
	    } else if ( streq ( nm, "~diag_type_scope" ) ) {
127
		token_sort ( p, sort_exp, "x$d", n ) ;
128
	    } else if ( streq ( nm, "~diag_tag_scope" ) ) {
129
		token_sort ( p, sort_exp, "x$d", n ) ;
130
	    }
131
	}
132
    }
133
    if ( dumb_mode ) {
134
	word *w1, *w2 ;
135
	w1 = new_word ( HORIZ_NONE ) ;
136
	out_string ( var_types [v] ) ;
137
	w2 = new_word ( HORIZ_BRACKETS ) ;
138
	out_int ( n ) ;
139
	end_word ( w2 ) ;
140
	out_string ( "represents " ) ;
141
	if ( ext.simple ) {
142
	    out ( ext.val.str ) ;
143
	} else {
144
	    out_unique ( ext.val.uniq ) ;
145
	}
146
	end_word ( w1 ) ;
147
    }
148
    return ;
149
}
150
 
151
 
152
/*
153
    COUNT OF TOTAL NUMBER OF EQUATIONS OF A PARTICULAR TYPE
154
 
155
    This should be increased appropriately by each unit decoding function.
156
*/
157
 
158
long total = 0 ;
159
long blank_lines = 0 ;
160
 
161
 
162
/*
163
    DECODE A SET OF EQUATIONS
164
 
165
    A set of equations is decoded.  f gives the procedure which is to be
166
    used to decode the equation body.
167
*/
168
 
169
static void de_equation
170
    PROTO_N ( ( f ) )
171
    PROTO_T ( equation_func f )
172
{
173
    long i, n ;
174
    long no_var ;
175
    int needs_it = 0 ;
176
    static long unitno = 1 ;
177
 
178
    /* Record old bindings */
179
    binding *old_binding = crt_binding ;
180
 
181
    /* Read the number of each type of variable */
182
    no_var = tdf_int () ;
183
    if ( no_var ) {
184
	if ( no_var != no_variables ) {
185
	    input_error ( "Number of local variables wrong" ) ;
186
	}
187
	crt_binding = new_binding_table () ;
188
	for ( i = 0 ; i < no_var ; i++ ) {
189
	    long sz = tdf_int () ;
190
	    set_binding_size ( crt_binding, i, sz ) ;
191
	    if ( show_stuff ) {
192
		out_string ( var_types [i] ) ;
193
		out_string ( " x " ) ;
194
		out_int ( sz ) ;
195
	    }
196
	}
197
	if ( show_stuff ) blank_line () ;
198
    }
199
 
200
    /* Read linkage for each type of variable */
201
    n = tdf_int () ;
202
    if ( n != no_var ) input_error ( "Number of linkage units wrong" ) ;
203
    if ( no_var ) {
204
	if ( dumb_mode ) {
205
	    word *w = new_word ( HORIZ_NONE ) ;
206
	    out_string ( "Bindings for Unit " ) ;
207
	    out_int ( unitno ) ;
208
	    out ( "(inner->outer)" ) ;
209
	    end_word ( w ) ;
210
	    blank_line () ;
211
	}
212
	for ( i = 0 ; i < no_var ; i++ ) {
213
	    long j, no_links = tdf_int () ;
214
	    for ( j = 0 ; j < no_links ; j++ ) {
215
		object *p ;
216
		long inner = tdf_int () ;
217
		long outer = tdf_int () ;
218
		if ( dumb_mode ) {
219
		    /* Output the linkage information */
220
		    word *w1, *w2 ;
221
		    w1 = new_word ( HORIZ_NONE ) ;
222
		    out_string ( var_types [i] ) ;
223
		    w2 = new_word ( HORIZ_BRACKETS ) ;
224
		    out_int ( inner ) ;
225
		    end_word ( w2 ) ;
226
		    out_string ( "is bound to " ) ;
227
		    out_string ( var_types [i] ) ;
228
		    w2 = new_word ( HORIZ_BRACKETS ) ;
229
		    out_int ( outer ) ;
230
		    end_word ( w2 ) ;
231
		    end_word ( w1 ) ;
232
		    needs_it = 1 ;
233
		}
234
		p = find_binding ( old_binding, i, outer ) ;
235
		set_binding ( crt_binding, i, inner, p ) ;
236
	    }
237
	}
238
	if ( dumb_mode ) {
239
	    if ( needs_it ) blank_line () ;
240
	    blank_lines = 1 ;
241
	}
242
 
243
	/* Complete the bindings */
244
	complete_binding ( crt_binding ) ;
245
    }
246
 
247
    /* Read the unit body */
248
    n = BYTESIZE * tdf_int () ;
249
    byte_align () ;
250
    if ( f == null ) {
251
	skip_bits ( n ) ;
252
	if ( dumb_mode ) {
253
	    out ( "(skipped)" ) ;
254
	    blank_line () ;
255
	    blank_lines = 1 ;
256
	}
257
	total++ ;
258
    } else {
259
	long end = posn ( here ) + n ;
260
	( *f ) () ;
261
	byte_align () ;
262
	if ( posn ( here ) != end ) input_error ( "Unit length wrong" ) ;
263
    }
264
 
265
    /* Restore old bindings */
266
    if ( no_var ) {
267
	free_binding_table ( crt_binding ) ;
268
	crt_binding = old_binding ;
269
	if ( dumb_mode ) {
270
	    for ( i = blank_lines ; i < 2 ; i++ ) blank_line () ;
271
	    out_string ( "End of Bindings for Unit " ) ;
272
	    out_int ( unitno++ ) ;
273
	    blank_line () ;
274
	    blank_line () ;
275
	    blank_lines = 2 ;
276
	}
277
    }
278
    return ;
279
}
280
 
281
 
282
/*
283
    DECODE A CAPSULE
284
 
285
    A capsule consists of a number of equation types, a number of variable
286
    sorts, a number of external names for variables and a number of
287
    equations of certain types.
288
*/
289
 
290
void de_capsule
291
    PROTO_Z ()
292
{
293
    long i, n ;
294
    long no_eqn, no_var ;
295
    if ( dumb_mode ) show_stuff = 1 ;
296
 
297
    /* Read the magic number */
298
    out ( "MAGIC NUMBER" ) ;
299
    blank_line () ;
300
    de_magic ( version_magic ) ;
301
    blank_line () ;
302
    blank_line () ;
303
 
304
    /* Read the equation types */
305
    no_eqn = tdf_int () ;
306
    if ( no_eqn ) {
307
	if ( show_stuff ) {
308
	    out ( "EQUATION TYPES" ) ;
309
	    blank_line () ;
310
	}
311
	eqn_types = alloc_nof ( string, no_eqn ) ;
312
	for ( i = 0 ; i < no_eqn ; i++ ) {
313
	    string s = de_tdfstring_align () ;
314
	    eqn_types [i] = s ;
315
	    if ( show_stuff ) out ( s ) ;
316
	}
317
	if ( show_stuff ) {
318
	    blank_line () ;
319
	    blank_line () ;
320
	}
321
    }
322
 
323
    /* Read the variable types and initialize the bindings */
324
    no_var = tdf_int () ;
325
    no_variables = no_var ;
326
    crt_binding = new_binding_table () ;
327
    if ( no_var ) {
328
	if ( show_stuff ) {
329
	    out ( "VARIABLE TYPES" ) ;
330
	    blank_line () ;
331
	}
332
	var_types = alloc_nof ( string, no_var ) ;
333
	var_letters = alloc_nof ( char, no_var + 1 ) ;
334
	var_count = alloc_nof ( long, no_var ) ;
335
	var_letters [ no_var ] = 0 ;
336
 
337
	for ( i = 0 ; i < no_var ; i++ ) {
338
	    string sv = de_tdfstring_align () ;
339
	    long sz = tdf_int () ;
340
	    var_letters [i] = find_variable ( sv, i ) ;
341
	    var_types [i] = sv ;
342
	    var_count [i] = 0 ;
343
	    set_binding_size ( crt_binding, i, sz ) ;
344
	    if ( show_stuff ) {
345
		out_string ( sv ) ;
346
		out_string ( " x " ) ;
347
		out_int ( sz ) ;
348
	    }
349
	}
350
	if ( show_stuff ) {
351
	    blank_line () ;
352
	    blank_line () ;
353
	}
354
    }
355
 
356
    /* Read the external variable names */
357
    n = tdf_int () ;
358
    if ( n != no_var ) input_error ( "Number of variables wrong" ) ;
359
    if ( no_var ) {
360
	if ( dumb_mode ) {
361
	    out ( "EXTERNAL NAMES" ) ;
362
	    blank_line () ;
363
	}
364
	for ( i = 0 ; i < no_var ; i++ ) {
365
	    long j, no_links = tdf_int () ;
366
	    for ( j = 0 ; j < no_links ; j++ ) de_linkextern ( i, j ) ;
367
	}
368
	if ( dumb_mode ) {
369
	    blank_line () ;
370
	    blank_line () ;
371
	}
372
    }
373
 
374
    /* Complete the bindings */
375
    complete_binding ( crt_binding ) ;
376
 
377
    /* Read the equations */
378
    n = tdf_int () ;
379
    if ( n != no_eqn ) input_error ( "Number of equations wrong" ) ;
380
    for ( i = 0 ; i < no_eqn ; i++ ) {
381
	int used = 0 ;
382
	char *title = null ;
383
	long j, no_units = tdf_int () ;
384
	string se = eqn_types [i] ;
385
	equation_func f = find_equation ( se, &title, &used ) ;
386
	if ( !used ) {
387
	    title = null ;
388
	    f = null ;
389
	}
390
	total = 0 ;
391
	if ( f == de_tokdef_props && no_units ) {
392
	    /* Skip pass */
393
	    place pl ;
394
	    int old_pf = printflag ;
395
	    if ( !show_skip ) printflag = 0 ;
396
	    skipping = 1 ;
397
	    pl.byte = here.byte ;
398
	    pl.bit = here.bit ;
399
	    if ( printflag && ( dumb_mode || f ) ) {
400
		if ( title && !show_stuff ) {
401
		    out_string ( title ) ;
402
		} else {
403
		    out_string ( "EQUATIONS OF TYPE " ) ;
404
		    out_string ( se ) ;
405
		}
406
		out ( " (SKIP PASS)" ) ;
407
		blank_line () ;
408
		blank_lines = 1 ;
409
	    }
410
	    for ( j = 0 ; j < no_units ; j++ ) de_equation ( f ) ;
411
	    if ( printflag && ( dumb_mode || f ) ) {
412
		if ( total == 0 ) {
413
		    out ( "(none)" ) ;
414
		    blank_lines = 0 ;
415
		}
416
		for ( j = blank_lines ; j < 2 ; j++ ) blank_line () ;
417
		blank_lines = 2 ;
418
	    }
419
	    total = 0 ;
420
	    set_place ( &pl ) ;
421
	    skipping = 0 ;
422
	    printflag = old_pf ;
423
	}
424
 
425
	/* Main pass */
426
	if ( dumb_mode || f ) {
427
	    if ( title && !show_stuff ) {
428
		out ( title ) ;
429
	    } else {
430
		out_string ( "EQUATIONS OF TYPE " ) ;
431
		out ( se ) ;
432
	    }
433
	    blank_line () ;
434
	    blank_lines = 1 ;
435
	}
436
	for ( j = 0 ; j < no_units ; j++ ) de_equation ( f ) ;
437
	if ( dumb_mode || f ) {
438
	    if ( total == 0 ) {
439
		out ( "(none)" ) ;
440
		blank_lines = 0 ;
441
	    }
442
	    for ( j = blank_lines ; j < 2 ; j++ ) blank_line () ;
443
	    blank_lines = 2 ;
444
	}
445
    }
446
    return ;
447
}