Subversion Repositories tendra.SVN

Rev

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

Rev 5 Rev 6
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 60... Line 90...
60
#include "type.h"
90
#include "type.h"
61
 
91
 
62
/*--------------------------------------------------------------------------*/
92
/*--------------------------------------------------------------------------*/
63
 
93
 
64
AltP
94
AltP
65
alt_create PROTO_Z ()
95
alt_create(void)
66
{
96
{
67
    AltP alt = ALLOCATE (AltT);
97
    AltP alt = ALLOCATE(AltT);
68
 
98
 
69
    alt->next      = NIL (AltP);
99
    alt->next      = NIL(AltP);
70
    types_init (alt_names (alt));
100
    types_init(alt_names(alt));
71
    bitvec_init (alt_first_set (alt));
101
    bitvec_init(alt_first_set(alt));
72
    alt->item_head = NIL (ItemP);
102
    alt->item_head = NIL(ItemP);
73
    alt->item_tail = &(alt->item_head);
103
    alt->item_tail = &(alt->item_head);
74
    return (alt);
104
    return(alt);
75
}
105
}
76
 
106
 
77
AltP
107
AltP
78
alt_create_merge PROTO_N ((initial_item, trailing_item, translator, table))
108
alt_create_merge(ItemP initial_item, ItemP trailing_item,
79
		 PROTO_T (ItemP      initial_item X
-
 
80
			  ItemP      trailing_item X
-
 
81
			  TypeTransP translator X
109
		 TypeTransP translator, TableP table)
82
			  TableP     table)
-
 
83
{
110
{
84
    AltP alt = alt_create ();
111
    AltP alt = alt_create();
85
 
112
 
86
    for (; initial_item; initial_item = item_next (initial_item)) {
113
    for (; initial_item; initial_item = item_next(initial_item)) {
87
	ItemP new_item = item_duplicate_and_translate (initial_item,
114
	ItemP new_item = item_duplicate_and_translate(initial_item, translator,
88
						       translator,
-
 
89
						       table);
115
						      table);
90
 
116
 
91
	alt_add_item (alt, new_item);
117
	alt_add_item(alt, new_item);
92
    }
118
    }
93
    for (; trailing_item; trailing_item = item_next (trailing_item)) {
119
    for (; trailing_item; trailing_item = item_next(trailing_item)) {
94
	ItemP new_item = item_duplicate (trailing_item);
120
	ItemP new_item = item_duplicate(trailing_item);
95
 
121
 
96
	alt_add_item (alt, new_item);
122
	alt_add_item(alt, new_item);
97
    }
123
    }
98
    return (alt);
124
    return(alt);
99
}
125
}
100
 
126
 
101
AltP
127
AltP
102
alt_duplicate PROTO_N ((alt))
128
alt_duplicate(AltP alt)
103
	      PROTO_T (AltP alt)
-
 
104
{
129
{
105
    AltP  new_alt = alt_create ();
130
    AltP  new_alt = alt_create();
106
    ItemP item;
131
    ItemP item;
107
 
132
 
108
    for (item = alt_item_head (alt); item; item = item_next (item)) {
133
    for (item = alt_item_head(alt); item; item = item_next(item)) {
109
	ItemP new_item = item_duplicate (item);
134
	ItemP new_item = item_duplicate(item);
110
 
135
 
111
	alt_add_item (new_alt, new_item);
136
	alt_add_item(new_alt, new_item);
112
    }
137
    }
113
    return (new_alt);
138
    return(new_alt);
114
}
139
}
115
 
140
 
116
BoolT
141
BoolT
117
alt_less_than PROTO_N ((alt1, alt2))
142
alt_less_than(AltP alt1, AltP alt2)
118
	      PROTO_T (AltP alt1 X
-
 
119
		       AltP alt2)
-
 
120
{
143
{
121
    ItemP      item1 = alt_item_head (alt1);
144
    ItemP      item1 = alt_item_head(alt1);
122
    ItemP      item2 = alt_item_head (alt2);
145
    ItemP      item2 = alt_item_head(alt2);
123
    KeyP       key1;
146
    KeyP       key1;
124
    KeyP       key2;
147
    KeyP       key2;
125
    TypeTupleP type1;
148
    TypeTupleP type1;
126
    TypeTupleP type2;
149
    TypeTupleP type2;
127
 
150
 
128
    if (item_type (item1) < item_type (item2)) {
151
    if (item_type(item1) < item_type(item2)) {
129
	return (TRUE);
152
	return(TRUE);
130
    } else if (item_type (item1) > item_type (item2)) {
153
    } else if (item_type(item1) > item_type(item2)) {
131
	return (FALSE);
154
	return(FALSE);
132
    }
155
    }
133
    key1 = entry_key (item_entry (item1));
156
    key1 = entry_key(item_entry(item1));
134
    key2 = entry_key (item_entry (item2));
157
    key2 = entry_key(item_entry(item2));
135
    switch (key_compare (key1, key2)) EXHAUSTIVE {
158
    switch (key_compare(key1, key2)) EXHAUSTIVE {
136
      case CMP_LT:
159
      case CMP_LT:
137
	return (TRUE);
160
	return(TRUE);
138
      case CMP_GT:
161
      case CMP_GT:
139
	return (FALSE);
162
	return(FALSE);
140
      case CMP_EQ:
163
      case CMP_EQ:
141
	break;
164
	break;
142
    }
165
    }
143
    type1 = item_param (item1);
166
    type1 = item_param(item1);
144
    type2 = item_param (item2);
167
    type2 = item_param(item2);
145
    switch (types_compare (type1, type2)) EXHAUSTIVE {
168
    switch (types_compare(type1, type2)) EXHAUSTIVE {
146
      case CMP_LT:
169
      case CMP_LT:
147
	return (TRUE);
170
	return(TRUE);
148
      case CMP_GT:
171
      case CMP_GT:
149
	return (FALSE);
172
	return(FALSE);
150
      case CMP_EQ:
173
      case CMP_EQ:
151
	break;
174
	break;
152
    }
175
    }
153
    type1 = item_result (item1);
176
    type1 = item_result(item1);
154
    type2 = item_result (item2);
177
    type2 = item_result(item2);
155
    switch (types_compare (type1, type2)) EXHAUSTIVE {
178
    switch (types_compare(type1, type2)) EXHAUSTIVE {
156
      case CMP_LT:
179
      case CMP_LT:
157
	return (TRUE);
180
	return(TRUE);
158
      case CMP_GT:
181
      case CMP_GT:
159
	return (FALSE);
182
	return(FALSE);
160
      case CMP_EQ:
183
      case CMP_EQ:
161
	break;
184
	break;
162
    }
185
    }
163
    UNREACHED;
186
    UNREACHED;
164
}
187
}
165
 
188
 
166
BoolT
189
BoolT
167
alt_equal PROTO_N ((alt1, alt2))
190
alt_equal(AltP alt1, AltP alt2)
168
	  PROTO_T (AltP alt1 X
-
 
169
		   AltP alt2)
-
 
170
{
191
{
171
    ItemP item1;
192
    ItemP item1;
172
    ItemP item2;
193
    ItemP item2;
173
 
194
 
174
    if ((alt1 == NIL (AltP)) && (alt2 == NIL (AltP))) {
195
    if ((alt1 == NIL(AltP)) && (alt2 == NIL(AltP))) {
175
	return (TRUE);
196
	return(TRUE);
176
    } else if ((alt1 == NIL (AltP)) || (alt2 == NIL (AltP))) {
197
    } else if ((alt1 == NIL(AltP)) || (alt2 == NIL(AltP))) {
177
	return (FALSE);
198
	return(FALSE);
178
    }
199
    }
179
    item1 = alt_item_head (alt1);
200
    item1 = alt_item_head(alt1);
180
    item2 = alt_item_head (alt2);
201
    item2 = alt_item_head(alt2);
181
    while (item1 && item2) {
202
    while (item1 && item2) {
182
	if ((item_entry (item1) == item_entry (item2)) &&
203
	if ((item_entry(item1) == item_entry(item2)) &&
183
	    (types_equal_numbers (item_param (item1), item_param (item2))) &&
204
	    (types_equal_numbers(item_param(item1), item_param(item2))) &&
184
	    (types_equal_numbers (item_result (item1), item_result (item2)))) {
205
	    (types_equal_numbers(item_result(item1), item_result(item2)))) {
185
	    item1 = item_next (item1);
206
	    item1 = item_next(item1);
186
	    item2 = item_next (item2);
207
	    item2 = item_next(item2);
187
	} else {
208
	} else {
188
	    return (FALSE);
209
	    return(FALSE);
189
	}
210
	}
190
    }
211
    }
191
    return (item1 == item2);
212
    return(item1 == item2);
192
}
213
}
193
 
214
 
194
#ifdef FS_FAST
215
#ifdef FS_FAST
195
#undef alt_next
216
#undef alt_next
196
#endif /* defined (FS_FAST) */
217
#endif /* defined (FS_FAST) */
197
AltP
218
AltP
198
alt_next PROTO_N ((alt))
-
 
199
	 PROTO_T (AltP alt)
219
alt_next(AltP alt)
200
{
220
{
201
    return (alt->next);
221
    return(alt->next);
202
}
222
}
203
#ifdef FS_FAST
223
#ifdef FS_FAST
204
#define alt_next(a) ((a)->next)
224
#define alt_next(a)	((a)->next)
205
#endif /* defined (FS_FAST) */
225
#endif /* defined (FS_FAST) */
206
 
226
 
207
#ifdef FS_FAST
227
#ifdef FS_FAST
208
#undef alt_next_ref
228
#undef alt_next_ref
209
#endif /* defined (FS_FAST) */
229
#endif /* defined (FS_FAST) */
210
AltP *
230
AltP *
211
alt_next_ref PROTO_N ((alt))
231
alt_next_ref(AltP alt)
212
	     PROTO_T (AltP alt)
-
 
213
{
232
{
214
    return (&(alt->next));
233
    return(&(alt->next));
215
}
234
}
216
#ifdef FS_FAST
235
#ifdef FS_FAST
217
#define alt_next_ref(a) (&((a)->next))
236
#define alt_next_ref(a)	(&((a)->next))
218
#endif /* defined (FS_FAST) */
237
#endif /* defined (FS_FAST) */
219
 
238
 
220
#ifdef FS_FAST
239
#ifdef FS_FAST
221
#undef alt_set_next
240
#undef alt_set_next
222
#endif /* defined (FS_FAST) */
241
#endif /* defined (FS_FAST) */
223
void
242
void
224
alt_set_next PROTO_N ((alt1, alt2))
243
alt_set_next(AltP alt1, AltP alt2)
225
	     PROTO_T (AltP alt1 X
-
 
226
		      AltP alt2)
-
 
227
{
244
{
228
    alt1->next = alt2;
245
    alt1->next = alt2;
229
}
246
}
230
#ifdef FS_FAST
247
#ifdef FS_FAST
231
#define alt_set_next(a1, a2) ((a1)->next = (a2))
248
#define alt_set_next(a1, a2)	((a1)->next = (a2))
232
#endif /* defined (FS_FAST) */
249
#endif /* defined (FS_FAST) */
233
 
250
 
234
#ifdef FS_FAST
251
#ifdef FS_FAST
235
#undef alt_names
252
#undef alt_names
236
#endif /* defined (FS_FAST) */
253
#endif /* defined (FS_FAST) */
237
TypeTupleP
254
TypeTupleP
238
alt_names PROTO_N ((alt))
255
alt_names(AltP alt)
239
	  PROTO_T (AltP alt)
-
 
240
{
256
{
241
    return (&(alt->names));
257
    return(&(alt->names));
242
}
258
}
243
#ifdef FS_FAST
259
#ifdef FS_FAST
244
#define alt_names(a) (&((a)->names))
260
#define alt_names(a)	(&((a)->names))
245
#endif /* defined (FS_FAST) */
261
#endif /* defined (FS_FAST) */
246
 
262
 
247
#ifdef FS_FAST
263
#ifdef FS_FAST
248
#undef alt_first_set
264
#undef alt_first_set
249
#endif /* defined (FS_FAST) */
265
#endif /* defined (FS_FAST) */
250
BitVecP
266
BitVecP
251
alt_first_set PROTO_N ((alt))
267
alt_first_set(AltP alt)
252
	      PROTO_T (AltP alt)
-
 
253
{
268
{
254
    return (&(alt->first_set));
269
    return(&(alt->first_set));
255
}
270
}
256
#ifdef FS_FAST
271
#ifdef FS_FAST
257
#define alt_first_set(a) (&((a)->first_set))
272
#define alt_first_set(a)	(&((a)->first_set))
258
#endif /* defined (FS_FAST) */
273
#endif /* defined (FS_FAST) */
259
 
274
 
260
#ifdef FS_FAST
275
#ifdef FS_FAST
261
#undef alt_item_head
276
#undef alt_item_head
262
#endif /* defined (FS_FAST) */
277
#endif /* defined (FS_FAST) */
263
ItemP
278
ItemP
264
alt_item_head PROTO_N ((alt))
279
alt_item_head(AltP alt)
265
	      PROTO_T (AltP alt)
-
 
266
{
280
{
267
    return (alt->item_head);
281
    return(alt->item_head);
268
}
282
}
269
#ifdef FS_FAST
283
#ifdef FS_FAST
270
#define alt_item_head(a) ((a)->item_head)
284
#define alt_item_head(a)	((a)->item_head)
271
#endif /* defined (FS_FAST) */
285
#endif /* defined (FS_FAST) */
272
 
286
 
273
ItemP
287
ItemP
274
alt_unlink_item_head PROTO_N ((alt))
288
alt_unlink_item_head(AltP alt)
275
		     PROTO_T (AltP alt)
-
 
276
{
289
{
277
    ItemP item = alt_item_head (alt);
290
    ItemP item = alt_item_head(alt);
278
 
291
 
279
    alt->item_head = item_next (item);
292
    alt->item_head = item_next(item);
280
    item_set_next (item, NIL (ItemP));
293
    item_set_next(item, NIL(ItemP));
281
    if (alt->item_tail == item_next_ref (item)) {
294
    if (alt->item_tail == item_next_ref(item)) {
282
	alt->item_tail = &(alt->item_head);
295
	alt->item_tail = &(alt->item_head);
283
    }
296
    }
284
    return (item);
297
    return(item);
285
}
298
}
286
 
299
 
287
void
300
void
288
alt_add_item PROTO_N ((alt, item))
301
alt_add_item(AltP alt, ItemP item)
289
	     PROTO_T (AltP  alt X
-
 
290
		      ItemP item)
-
 
291
{
302
{
292
    *(alt->item_tail) = item;
303
    *(alt->item_tail) = item;
293
    alt->item_tail    = item_next_ref (item);
304
    alt->item_tail    = item_next_ref(item);
294
}
305
}
295
 
306
 
296
AltP
307
AltP
297
alt_deallocate PROTO_N ((alt))
308
alt_deallocate(AltP alt)
298
	       PROTO_T (AltP alt)
-
 
299
{
309
{
300
    AltP  next = alt_next (alt);
310
    AltP  next = alt_next(alt);
301
    ItemP item;
311
    ItemP item;
302
 
312
 
303
    for (item = alt_item_head (alt); item; item = item_deallocate (item)) {
313
    for (item = alt_item_head(alt); item; item = item_deallocate(item)) {
304
	/*NOTHING*/
314
	/*NOTHING*/
305
    }
315
    }
306
    types_destroy (alt_names (alt));
316
    types_destroy(alt_names(alt));
307
    bitvec_destroy (alt_first_set (alt));
317
    bitvec_destroy(alt_first_set(alt));
308
    DEALLOCATE (alt);
318
    DEALLOCATE(alt);
309
    return (next);
319
    return(next);
310
}
320
}
311
 
321
 
312
void
322
void
313
write_alt PROTO_N ((ostream, alt))
323
write_alt(OStreamP ostream, AltP alt)
314
	  PROTO_T (OStreamP ostream X
-
 
315
		   AltP     alt)
-
 
316
{
324
{
317
    ItemP item;
325
    ItemP item;
318
 
326
 
319
    for (item = alt_item_head (alt); item; item = item_next (item)) {
327
    for (item = alt_item_head(alt); item; item = item_next(item)) {
320
	write_tab (ostream);
328
	write_tab(ostream);
321
	write_item (ostream, item);
329
	write_item(ostream, item);
322
	write_newline (ostream);
330
	write_newline(ostream);
323
    }
331
    }
324
}
332
}
325
 
333
 
326
void
334
void
327
write_alt_highlighting PROTO_N ((ostream, alt, highlight))
335
write_alt_highlighting(OStreamP ostream, AltP alt, ItemP highlight)
328
		       PROTO_T (OStreamP ostream X
-
 
329
				AltP     alt X
-
 
330
				ItemP    highlight)
-
 
331
{
336
{
332
    ItemP item;
337
    ItemP item;
333
 
338
 
334
    for (item = alt_item_head (alt); item; item = item_next (item)) {
339
    for (item = alt_item_head(alt); item; item = item_next(item)) {
335
	if (item == highlight) {
340
	if (item == highlight) {
336
	    write_cstring (ostream, "==>>");
341
	    write_cstring(ostream, "==>>");
337
	}
342
	}
338
	write_tab (ostream);
343
	write_tab(ostream);
339
	write_item (ostream, item);
344
	write_item(ostream, item);
340
	write_newline (ostream);
345
	write_newline(ostream);
341
    }
346
    }
342
}
347
}
343

348

344
/*
349
/*
345
 * Local variables(smf):
350
 * Local variables(smf):