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/tendra5/src/tools/tnc/check.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 "alignment.h"
34
#include "eval.h"
35
#include "node.h"
36
#include "read.h"
37
#include "shape.h"
38
#include "table.h"
39
#include "tdf.h"
40
#include "utility.h"
41
 
42
 
43
/*
44
    SHAPE CHECKING FLAG
45
 
46
    This flag is true to indicate that shape checking should be applied.
47
*/
48
 
49
boolean do_check = 0 ;
50
 
51
 
52
/*
53
    THE NAME OF THE CURRENT EXPRESSION BEING CHECKED
54
 
55
    The shape checking does not always take place immediately.  By
56
    printing the name of the expression being checked it is easier
57
    to find any errors.
58
*/
59
 
60
char *checking = "????" ;
61
 
62
 
63
/*
64
    SHAPE CHECKING FOR EXP_APPLY_TOKEN
65
 
66
    The shape checking for the exp_apply_token construct p is implemented
67
    by this routine.
68
*/
69
 
70
static void chk_token
71
    PROTO_N ( ( p ) )
72
    PROTO_T ( node *p )
73
{
74
    tok_info *info = get_tok_info ( p->son->cons ) ;
75
    node *d = info->def ;
76
    if ( d ) {
77
	if ( d->cons->sortnum == SORT_completion ) d = d->son ;
78
	p->shape = normalize ( d->shape ) ;
79
    } else {
80
	p->shape = new_node () ;
81
	p->shape->cons = &shape_of ;
82
	p->shape->son = copy_node ( p->son ) ;
83
    }
84
    return ;
85
}
86
 
87
 
88
/*
89
    SHAPE CHECKING FOR EXP_COND
90
 
91
    The shape checking for the exp_cond construct p is implemented by
92
    this routine.  Checking that the control argument is an integer is
93
    carried out for all _cond constructs as part of the main reading
94
    and decoding routines for the decode letter '@'.
95
*/
96
 
97
static void chk_cond
98
    PROTO_N ( ( p ) )
99
    PROTO_T ( node *p )
100
{
101
    node *s ;
102
    node *q1 = p->son->bro->son ;
103
    node *q2 = p->son->bro->bro->son ;
104
    node *s1 = q1->shape ;
105
    node *s2 = q2->shape ;
106
    if ( q1->cons->encoding == ENC_fail_installer ) {
107
	p->shape = normalize ( s2 ) ;
108
	return ;
109
    }
110
    if ( q2->cons->encoding == ENC_fail_installer ) {
111
	p->shape = normalize ( s1 ) ;
112
	return ;
113
    }
114
    s = lub ( s1, s2 ) ;
115
    if ( s == null ) {
116
	p->shape = null ;
117
    } else {
118
	long n = s->cons->encoding ;
119
	if ( n == ENC_bottom || n == ENC_top ) {
120
	    p->shape = null ;
121
	} else {
122
	    p->shape = normalize ( s ) ;
123
	}
124
    }
125
    return ;
126
}
127
 
128
 
129
/*
130
    SHAPE CHECKING FOR OBTAIN_TAG
131
 
132
    The shape checking for the obtain_tag construct p is implemented by
133
    this routine.  a gives the actual tag.
134
*/
135
 
136
static void chk_tag
137
    PROTO_N ( ( p, a, intro ) )
138
    PROTO_T ( node *p X node *a X int intro )
139
{
140
    if ( !intro && a->cons->encoding == ENC_make_tag ) {
141
	tag_info *info = get_tag_info ( a->son->cons ) ;
142
	node *d = info->dec ;
143
	if ( d && d->cons->sortnum == SORT_completion ) d = d->son ;
144
	if ( d ) d = d->bro ;
145
	if ( d ) d = d->bro ;
146
	switch ( info->var ) {
147
	    case 0 : {
148
		p->shape = normalize ( d ) ;
149
		break ;
150
	    }
151
	    case 1 :
152
	    case 2 : {
153
		p->shape = sh_pointer ( d ) ;
154
		break ;
155
	    }
156
	    default : {
157
		if ( text_input ) {
158
		    char *nm = a->son->cons->name ;
159
		    is_fatal = 0 ;
160
		    input_error ( "Tag %s used but not declared", nm ) ;
161
		}
162
		p->shape = null ;
163
		break ;
164
	    }
165
	}
166
    } else {
167
	p->shape = null ;
168
    }
169
    return ;
170
}
171
 
172
 
173
/*
174
    SHAPE CHECKING MACRO DEFINITIONS
175
 
176
    The main body of the shape checking for expressions is in the
177
    automatically generated file check_exp.h.  This calls a macro of
178
    the form check_<cons> for each construct <cons>.  The actual
179
    definitions of these macros (which vary between TDF specification
180
    releases) are in check_def.h.
181
*/
182
 
183
#include "check_def.h"
184
#include "check_exp.h"
185
 
186
 
187
/*
188
    SHAPE CHECK A SHAPE
189
 
190
    The construct compound has an exp argument which needs to be
191
    shape checked.
192
*/
193
 
194
void check_shape_fn
195
    PROTO_N ( ( p ) )
196
    PROTO_T ( node *p )
197
{
198
    if ( p && p->cons->encoding == ENC_compound ) {
199
	if ( do_check ) {
200
	    checking = p->cons->name ;
201
	    IGNORE check1 ( ENC_offset, p->son ) ;
202
	}
203
    }
204
    return ;
205
}
206
 
207
 
208
/*
209
    SHAPE CHECK A NAT
210
 
211
    The construct computed_nat has an exp argument which needs to be
212
    shape checked.
213
*/
214
 
215
void check_nat_fn
216
    PROTO_N ( ( p ) )
217
    PROTO_T ( node *p )
218
{
219
    if ( p && p->cons->encoding == ENC_computed_nat ) {
220
	if ( do_check ) {
221
	    checking = p->cons->name ;
222
	    IGNORE check1 ( ENC_integer, p->son ) ;
223
	}
224
    }
225
    return ;
226
}
227
 
228
 
229
/*
230
    SHAPE CHECK A SIGNED NAT
231
 
232
    The construct computed_signed_nat has an exp argument which needs
233
    to be shape checked.
234
*/
235
 
236
void check_snat_fn
237
    PROTO_N ( ( p ) )
238
    PROTO_T ( node *p )
239
{
240
    if ( p && p->cons->encoding == ENC_computed_signed_nat ) {
241
	if ( do_check ) {
242
	    checking = p->cons->name ;
243
	    IGNORE check1 ( ENC_integer, p->son ) ;
244
	}
245
    }
246
    return ;
247
}
248
 
249
 
250
/*
251
    SHAPE CHECK AN ACCESS
252
 
253
    The flag intro_visible is set whenever a visible construct is
254
    encountered.
255
*/
256
 
257
void check_access_fn
258
    PROTO_N ( ( p ) )
259
    PROTO_T ( node *p )
260
{
261
    if ( p && p->cons->encoding == ENC_visible ) intro_visible = 1 ;
262
    return ;
263
}
264
 
265
 
266
/*
267
    IS A SHAPE COMPLETELY KNOWN?
268
 
269
    This routine returns true if p is not null and does not contain
270
    any unknown constructs.  In encode mode we can't have any constructs
271
    which introduce local tags or tokens either.
272
*/
273
 
274
static boolean is_known
275
    PROTO_N ( ( p ) )
276
    PROTO_T ( node *p )
277
{
278
    if ( p == null ) return ( 0 ) ;
279
    while ( p ) {
280
	sortname s = p->cons->sortnum ;
281
	if ( s == SORT_unknown ) return ( 0 ) ;
282
	if ( !text_output && s == SORT_exp ) {
283
	    switch ( p->cons->encoding ) {
284
		case ENC_conditional : return ( 0 ) ;
285
		case ENC_identify : return ( 0 ) ;
286
		case ENC_labelled : return ( 0 ) ;
287
		case ENC_make_proc : return ( 0 ) ;
288
		case ENC_repeat : return ( 0 ) ;
289
		case ENC_variable : return ( 0 ) ;
290
	    }
291
	}
292
	if ( p->son && !is_known ( p->son ) ) return ( 0 ) ;
293
	p = p->bro ;
294
    }
295
    return ( 1 ) ;
296
}
297
 
298
 
299
/*
300
    CHECK THAT A TAG DECLARATION AND DEFINITION MATCH
301
 
302
    The construct p, representing a declared and defined tag, is checked
303
    for shape correctness.
304
*/
305
 
306
void check_tagdef
307
    PROTO_N ( ( p ) )
308
    PROTO_T ( construct *p )
309
{
310
    char *nm = p->name ;
311
    tag_info *info = get_tag_info ( p ) ;
312
    node *dc = info->dec ;
313
    node *df = info->def ;
314
    if ( df == null ) return ;
315
    if ( df->cons->sortnum == SORT_completion ) df = df->son ;
316
    if ( info->var ) df = df->bro ;
317
    if ( dc == null ) {
318
	if ( is_known ( df->shape ) ) {
319
	    /* Declaration = ?[u]?[X]S (from 4.0) */
320
	    node *q = new_node () ;
321
	    q->cons = &false_cons ;
322
	    q->bro = new_node () ;
323
	    q->bro->cons = &false_cons ;
324
	    q->bro->bro = df->shape ;
325
	    info->dec->bro = completion ( q ) ;
326
	} else {
327
	    is_fatal = 0 ;
328
	    input_error ( "Can't deduce shape of %s from definition", nm ) ;
329
	}
330
    } else {
331
	if ( dc->cons->sortnum == SORT_completion ) dc = dc->son ;
332
	/* Declaration = ?[u]?[X]S (from 4.0) */
333
	dc = dc->bro->bro ;
334
	checking = nm ;
335
	IGNORE check_shapes ( dc, df->shape, 1 ) ;
336
    }
337
    return ;
338
}