Subversion Repositories tendra.SVN

Rev

Rev 2 | Go to most recent revision | Details | Compare with Previous | 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
/*** alt.c --- Alternative ADT.
32
 *
33
 ** Author: Steve Folkes <smf@hermes.mod.uk>
34
 *
35
 *** Commentary:
36
 *
37
 * This file implements the alternative manipulation routines.  They are
38
 * specified in the file "rule.h".
39
 *
40
 *** Change Log:
41
 * $Log: alt.c,v $
42
 * Revision 1.1.1.1  1998/01/17  15:57:42  release
43
 * First version to be checked into rolling release.
44
 *
45
 * Revision 1.2  1994/12/15  09:57:59  smf
46
 * Brought into line with OSSG C Coding Standards Document, as per
47
 * "CR94_178.sid+tld-update".
48
 *
49
 * Revision 1.1.1.1  1994/07/25  16:04:31  smf
50
 * Initial import of SID 1.8 non shared files.
51
 *
52
**/
53
 
54
/****************************************************************************/
55
 
56
#include "rule.h"
57
#include "action.h"
58
#include "basic.h"
59
#include "name.h"
60
#include "type.h"
61
 
62
/*--------------------------------------------------------------------------*/
63
 
64
AltP
65
alt_create PROTO_Z ()
66
{
67
    AltP alt = ALLOCATE (AltT);
68
 
69
    alt->next      = NIL (AltP);
70
    types_init (alt_names (alt));
71
    bitvec_init (alt_first_set (alt));
72
    alt->item_head = NIL (ItemP);
73
    alt->item_tail = &(alt->item_head);
74
    return (alt);
75
}
76
 
77
AltP
78
alt_create_merge PROTO_N ((initial_item, trailing_item, translator, table))
79
		 PROTO_T (ItemP      initial_item X
80
			  ItemP      trailing_item X
81
			  TypeTransP translator X
82
			  TableP     table)
83
{
84
    AltP alt = alt_create ();
85
 
86
    for (; initial_item; initial_item = item_next (initial_item)) {
87
	ItemP new_item = item_duplicate_and_translate (initial_item,
88
						       translator,
89
						       table);
90
 
91
	alt_add_item (alt, new_item);
92
    }
93
    for (; trailing_item; trailing_item = item_next (trailing_item)) {
94
	ItemP new_item = item_duplicate (trailing_item);
95
 
96
	alt_add_item (alt, new_item);
97
    }
98
    return (alt);
99
}
100
 
101
AltP
102
alt_duplicate PROTO_N ((alt))
103
	      PROTO_T (AltP alt)
104
{
105
    AltP  new_alt = alt_create ();
106
    ItemP item;
107
 
108
    for (item = alt_item_head (alt); item; item = item_next (item)) {
109
	ItemP new_item = item_duplicate (item);
110
 
111
	alt_add_item (new_alt, new_item);
112
    }
113
    return (new_alt);
114
}
115
 
116
BoolT
117
alt_less_than PROTO_N ((alt1, alt2))
118
	      PROTO_T (AltP alt1 X
119
		       AltP alt2)
120
{
121
    ItemP      item1 = alt_item_head (alt1);
122
    ItemP      item2 = alt_item_head (alt2);
123
    KeyP       key1;
124
    KeyP       key2;
125
    TypeTupleP type1;
126
    TypeTupleP type2;
127
 
128
    if (item_type (item1) < item_type (item2)) {
129
	return (TRUE);
130
    } else if (item_type (item1) > item_type (item2)) {
131
	return (FALSE);
132
    }
133
    key1 = entry_key (item_entry (item1));
134
    key2 = entry_key (item_entry (item2));
135
    switch (key_compare (key1, key2)) EXHAUSTIVE {
136
      case CMP_LT:
137
	return (TRUE);
138
      case CMP_GT:
139
	return (FALSE);
140
      case CMP_EQ:
141
	break;
142
    }
143
    type1 = item_param (item1);
144
    type2 = item_param (item2);
145
    switch (types_compare (type1, type2)) EXHAUSTIVE {
146
      case CMP_LT:
147
	return (TRUE);
148
      case CMP_GT:
149
	return (FALSE);
150
      case CMP_EQ:
151
	break;
152
    }
153
    type1 = item_result (item1);
154
    type2 = item_result (item2);
155
    switch (types_compare (type1, type2)) EXHAUSTIVE {
156
      case CMP_LT:
157
	return (TRUE);
158
      case CMP_GT:
159
	return (FALSE);
160
      case CMP_EQ:
161
	break;
162
    }
163
    UNREACHED;
164
}
165
 
166
BoolT
167
alt_equal PROTO_N ((alt1, alt2))
168
	  PROTO_T (AltP alt1 X
169
		   AltP alt2)
170
{
171
    ItemP item1;
172
    ItemP item2;
173
 
174
    if ((alt1 == NIL (AltP)) && (alt2 == NIL (AltP))) {
175
	return (TRUE);
176
    } else if ((alt1 == NIL (AltP)) || (alt2 == NIL (AltP))) {
177
	return (FALSE);
178
    }
179
    item1 = alt_item_head (alt1);
180
    item2 = alt_item_head (alt2);
181
    while (item1 && item2) {
182
	if ((item_entry (item1) == item_entry (item2)) &&
183
	    (types_equal_numbers (item_param (item1), item_param (item2))) &&
184
	    (types_equal_numbers (item_result (item1), item_result (item2)))) {
185
	    item1 = item_next (item1);
186
	    item2 = item_next (item2);
187
	} else {
188
	    return (FALSE);
189
	}
190
    }
191
    return (item1 == item2);
192
}
193
 
194
#ifdef FS_FAST
195
#undef alt_next
196
#endif /* defined (FS_FAST) */
197
AltP
198
alt_next PROTO_N ((alt))
199
	 PROTO_T (AltP alt)
200
{
201
    return (alt->next);
202
}
203
#ifdef FS_FAST
204
#define alt_next(a) ((a)->next)
205
#endif /* defined (FS_FAST) */
206
 
207
#ifdef FS_FAST
208
#undef alt_next_ref
209
#endif /* defined (FS_FAST) */
210
AltP *
211
alt_next_ref PROTO_N ((alt))
212
	     PROTO_T (AltP alt)
213
{
214
    return (&(alt->next));
215
}
216
#ifdef FS_FAST
217
#define alt_next_ref(a) (&((a)->next))
218
#endif /* defined (FS_FAST) */
219
 
220
#ifdef FS_FAST
221
#undef alt_set_next
222
#endif /* defined (FS_FAST) */
223
void
224
alt_set_next PROTO_N ((alt1, alt2))
225
	     PROTO_T (AltP alt1 X
226
		      AltP alt2)
227
{
228
    alt1->next = alt2;
229
}
230
#ifdef FS_FAST
231
#define alt_set_next(a1, a2) ((a1)->next = (a2))
232
#endif /* defined (FS_FAST) */
233
 
234
#ifdef FS_FAST
235
#undef alt_names
236
#endif /* defined (FS_FAST) */
237
TypeTupleP
238
alt_names PROTO_N ((alt))
239
	  PROTO_T (AltP alt)
240
{
241
    return (&(alt->names));
242
}
243
#ifdef FS_FAST
244
#define alt_names(a) (&((a)->names))
245
#endif /* defined (FS_FAST) */
246
 
247
#ifdef FS_FAST
248
#undef alt_first_set
249
#endif /* defined (FS_FAST) */
250
BitVecP
251
alt_first_set PROTO_N ((alt))
252
	      PROTO_T (AltP alt)
253
{
254
    return (&(alt->first_set));
255
}
256
#ifdef FS_FAST
257
#define alt_first_set(a) (&((a)->first_set))
258
#endif /* defined (FS_FAST) */
259
 
260
#ifdef FS_FAST
261
#undef alt_item_head
262
#endif /* defined (FS_FAST) */
263
ItemP
264
alt_item_head PROTO_N ((alt))
265
	      PROTO_T (AltP alt)
266
{
267
    return (alt->item_head);
268
}
269
#ifdef FS_FAST
270
#define alt_item_head(a) ((a)->item_head)
271
#endif /* defined (FS_FAST) */
272
 
273
ItemP
274
alt_unlink_item_head PROTO_N ((alt))
275
		     PROTO_T (AltP alt)
276
{
277
    ItemP item = alt_item_head (alt);
278
 
279
    alt->item_head = item_next (item);
280
    item_set_next (item, NIL (ItemP));
281
    if (alt->item_tail == item_next_ref (item)) {
282
	alt->item_tail = &(alt->item_head);
283
    }
284
    return (item);
285
}
286
 
287
void
288
alt_add_item PROTO_N ((alt, item))
289
	     PROTO_T (AltP  alt X
290
		      ItemP item)
291
{
292
    *(alt->item_tail) = item;
293
    alt->item_tail    = item_next_ref (item);
294
}
295
 
296
AltP
297
alt_deallocate PROTO_N ((alt))
298
	       PROTO_T (AltP alt)
299
{
300
    AltP  next = alt_next (alt);
301
    ItemP item;
302
 
303
    for (item = alt_item_head (alt); item; item = item_deallocate (item)) {
304
	/*NOTHING*/
305
    }
306
    types_destroy (alt_names (alt));
307
    bitvec_destroy (alt_first_set (alt));
308
    DEALLOCATE (alt);
309
    return (next);
310
}
311
 
312
void
313
write_alt PROTO_N ((ostream, alt))
314
	  PROTO_T (OStreamP ostream X
315
		   AltP     alt)
316
{
317
    ItemP item;
318
 
319
    for (item = alt_item_head (alt); item; item = item_next (item)) {
320
	write_tab (ostream);
321
	write_item (ostream, item);
322
	write_newline (ostream);
323
    }
324
}
325
 
326
void
327
write_alt_highlighting PROTO_N ((ostream, alt, highlight))
328
		       PROTO_T (OStreamP ostream X
329
				AltP     alt X
330
				ItemP    highlight)
331
{
332
    ItemP item;
333
 
334
    for (item = alt_item_head (alt); item; item = item_next (item)) {
335
	if (item == highlight) {
336
	    write_cstring (ostream, "==>>");
337
	}
338
	write_tab (ostream);
339
	write_item (ostream, item);
340
	write_newline (ostream);
341
    }
342
}
343
 
344
/*
345
 * Local variables(smf):
346
 * eval: (include::add-path-entry "../os-interface" "../library")
347
 * eval: (include::add-path-entry "../generated")
348
 * end:
349
**/