Subversion Repositories tendra.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
7 7u83 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
 */
31
/*
2 7u83 32
    		 Crown Copyright (c) 1997
7 7u83 33
 
2 7u83 34
    This TenDRA(r) Computer Program is subject to Copyright
35
    owned by the United Kingdom Secretary of State for Defence
36
    acting through the Defence Evaluation and Research Agency
37
    (DERA).  It is made available to Recipients with a
38
    royalty-free licence for its use, reproduction, transfer
39
    to other parties and amendment for any purpose not excluding
40
    product development provided that any such use et cetera
41
    shall be deemed to be acceptance of the following conditions:-
7 7u83 42
 
2 7u83 43
        (1) Its Recipients shall ensure that this Notice is
44
        reproduced upon any copies or amended versions of it;
7 7u83 45
 
2 7u83 46
        (2) Any amended version of it shall be clearly marked to
47
        show both the nature of and the organisation responsible
48
        for the relevant amendment or amendments;
7 7u83 49
 
2 7u83 50
        (3) Its onward transfer from a recipient to another
51
        party shall be deemed to be that party's acceptance of
52
        these conditions;
7 7u83 53
 
2 7u83 54
        (4) DERA gives no warranty or assurance as to its
55
        quality or suitability for any purpose and DERA accepts
56
        no liability whatsoever in relation to any use to which
57
        it may be put.
58
*/
59
 
60
 
61
/*** item.c --- Item ADT.
62
 *
63
 ** Author: Steve Folkes <smf@hermes.mod.uk>
64
 *
65
 *** Commentary:
66
 *
67
 * This file implements the item manipulation routines.  These are specified
68
 * in the file "rule.h".
69
 *
70
 *** Change Log:
71
 * $Log: item.c,v $
72
 * Revision 1.1.1.1  1998/01/17  15:57:46  release
73
 * First version to be checked into rolling release.
74
 *
75
 * Revision 1.2  1994/12/15  09:58:17  smf
76
 * Brought into line with OSSG C Coding Standards Document, as per
77
 * "CR94_178.sid+tld-update".
78
 *
79
 * Revision 1.1.1.1  1994/07/25  16:04:34  smf
80
 * Initial import of SID 1.8 non shared files.
81
 *
82
**/
83
 
84
/****************************************************************************/
85
 
86
#include "rule.h"
87
#include "action.h"
88
#include "basic.h"
89
#include "name.h"
90
#include "type.h"
91
 
92
/*--------------------------------------------------------------------------*/
93
 
94
ItemP
7 7u83 95
item_create(EntryP entry)
2 7u83 96
{
7 7u83 97
    ItemP item = ALLOCATE(ItemT);
2 7u83 98
 
7 7u83 99
    item->next         = NIL(ItemP);
100
    types_init(item_param(item));
101
    types_init(item_result(item));
102
    item->type         = entry_type(entry);
2 7u83 103
    item->entry        = entry;
104
    item->inlinable    = FALSE;
105
    item->tail_call    = FALSE;
7 7u83 106
    return(item);
2 7u83 107
}
108
 
109
ItemP
7 7u83 110
item_duplicate(ItemP item)
2 7u83 111
{
7 7u83 112
    ItemP new_item = ALLOCATE(ItemT);
2 7u83 113
 
7 7u83 114
    new_item->next         = NIL(ItemP);
115
    types_copy(item_param(new_item), item_param(item));
116
    types_copy(item_result(new_item), item_result(item));
2 7u83 117
    new_item->type         = item->type;
118
    new_item->entry        = item->entry;
119
    new_item->inlinable    = item->inlinable;
120
    new_item->tail_call    = item->tail_call;
7 7u83 121
    return(new_item);
2 7u83 122
}
123
 
124
ItemP
7 7u83 125
item_duplicate_and_translate(ItemP item, TypeTransP translator, TableP table)
2 7u83 126
{
7 7u83 127
    ItemP new_item = ALLOCATE(ItemT);
2 7u83 128
 
7 7u83 129
    new_item->next         = NIL(ItemP);
130
    types_copy_and_translate(item_param(new_item), item_param(item),
2 7u83 131
			      translator, table);
7 7u83 132
    types_copy_and_translate(item_result(new_item), item_result(item),
2 7u83 133
			      translator, table);
134
    new_item->type         = item->type;
135
    new_item->entry        = item->entry;
136
    new_item->inlinable    = item->inlinable;
137
    new_item->tail_call    = item->tail_call;
7 7u83 138
    return(new_item);
2 7u83 139
}
140
 
141
void
7 7u83 142
item_translate_list(ItemP item, TypeBTransP translator)
2 7u83 143
{
7 7u83 144
    for (; item; item = item_next(item)) {
145
	types_translate(item_param(item), translator);
146
	types_translate(item_result(item), translator);
2 7u83 147
    }
148
}
149
 
150
void
7 7u83 151
item_to_predicate(ItemP item)
2 7u83 152
{
7 7u83 153
    ASSERT(item_is_action(item));
2 7u83 154
    item->type = ET_PREDICATE;
155
}
156
 
157
#ifdef FS_FAST
158
#undef item_next
159
#endif /* defined (FS_FAST) */
160
ItemP
7 7u83 161
item_next(ItemP item)
2 7u83 162
{
7 7u83 163
    return(item->next);
2 7u83 164
}
165
#ifdef FS_FAST
7 7u83 166
#define item_next(i)	((i)->next)
2 7u83 167
#endif /* defined (FS_FAST) */
168
 
169
#ifdef FS_FAST
170
#undef item_next_ref
171
#endif /* defined (FS_FAST) */
172
ItemP *
7 7u83 173
item_next_ref(ItemP item)
2 7u83 174
{
7 7u83 175
    return(&(item->next));
2 7u83 176
}
177
#ifdef FS_FAST
7 7u83 178
#define item_next_ref(i)	(&((i)->next))
2 7u83 179
#endif /* defined (FS_FAST) */
180
 
181
#ifdef FS_FAST
182
#undef item_set_next
183
#endif /* defined (FS_FAST) */
184
void
7 7u83 185
item_set_next(ItemP item1, ItemP item2)
2 7u83 186
{
187
    item1->next = item2;
188
}
189
#ifdef FS_FAST
7 7u83 190
#define item_set_next(i1, i2)	((i1)->next = (i2))
2 7u83 191
#endif /* defined (FS_FAST) */
192
 
193
#ifdef FS_FAST
194
#undef item_entry
195
#endif /* defined (FS_FAST) */
196
EntryP
7 7u83 197
item_entry(ItemP item)
2 7u83 198
{
7 7u83 199
    return(item->entry);
2 7u83 200
}
201
#ifdef FS_FAST
7 7u83 202
#define item_entry(i)	((i)->entry)
2 7u83 203
#endif /* defined (FS_FAST) */
204
 
205
#ifdef FS_FAST
206
#undef item_set_entry
207
#endif /* defined (FS_FAST) */
208
void
7 7u83 209
item_set_entry(ItemP item, EntryP entry)
2 7u83 210
{
211
    item->entry = entry;
212
}
213
#ifdef FS_FAST
7 7u83 214
#define item_set_entry(i, e)	((i)->entry = (e))
2 7u83 215
#endif /* defined (FS_FAST) */
216
 
217
#ifdef FS_FAST
218
#undef item_type
219
#endif /* defined (FS_FAST) */
220
EntryTypeT
7 7u83 221
item_type(ItemP item)
2 7u83 222
{
7 7u83 223
    return(item->type);
2 7u83 224
}
225
#ifdef FS_FAST
7 7u83 226
#define item_type(i)	((i)->type)
2 7u83 227
#endif /* defined (FS_FAST) */
228
 
229
#ifdef FS_FAST
230
#undef item_is_rule
231
#endif /* defined (FS_FAST) */
232
BoolT
7 7u83 233
item_is_rule(ItemP item)
2 7u83 234
{
7 7u83 235
    return(item->type == ET_RULE);
2 7u83 236
}
237
#ifdef FS_FAST
7 7u83 238
#define item_is_rule(i)	((i)->type == ET_RULE)
2 7u83 239
#endif /* defined (FS_FAST) */
240
 
241
#ifdef FS_FAST
242
#undef item_is_action
243
#endif /* defined (FS_FAST) */
244
BoolT
7 7u83 245
item_is_action(ItemP item)
2 7u83 246
{
7 7u83 247
    return(item->type == ET_ACTION);
2 7u83 248
}
249
#ifdef FS_FAST
7 7u83 250
#define item_is_action(i)	((i)->type == ET_ACTION)
2 7u83 251
#endif /* defined (FS_FAST) */
252
 
253
#ifdef FS_FAST
254
#undef item_is_predicate
255
#endif /* defined (FS_FAST) */
256
BoolT
7 7u83 257
item_is_predicate(ItemP item)
2 7u83 258
{
7 7u83 259
    return(item->type == ET_PREDICATE);
2 7u83 260
}
261
#ifdef FS_FAST
7 7u83 262
#define item_is_predicate(i)	((i)->type == ET_PREDICATE)
2 7u83 263
#endif /* defined (FS_FAST) */
264
 
265
#ifdef FS_FAST
266
#undef item_is_basic
267
#endif /* defined (FS_FAST) */
268
BoolT
7 7u83 269
item_is_basic(ItemP item)
2 7u83 270
{
7 7u83 271
    return(item->type == ET_BASIC);
2 7u83 272
}
273
#ifdef FS_FAST
7 7u83 274
#define item_is_basic(i)	((i)->type == ET_BASIC)
2 7u83 275
#endif /* defined (FS_FAST) */
276
 
277
#ifdef FS_FAST
278
#undef item_is_rename
279
#endif /* defined (FS_FAST) */
280
BoolT
7 7u83 281
item_is_rename(ItemP item)
2 7u83 282
{
7 7u83 283
    return(item->type == ET_RENAME);
2 7u83 284
}
285
#ifdef FS_FAST
7 7u83 286
#define item_is_rename(i)	((i)->type == ET_RENAME)
2 7u83 287
#endif /* defined (FS_FAST) */
288
 
289
#ifdef FS_FAST
290
#undef item_param
291
#endif /* defined (FS_FAST) */
292
TypeTupleP
7 7u83 293
item_param(ItemP item)
2 7u83 294
{
7 7u83 295
    return(&(item->param));
2 7u83 296
}
297
#ifdef FS_FAST
7 7u83 298
#define item_param(i)	(&((i)->param))
2 7u83 299
#endif /* defined (FS_FAST) */
300
 
301
#ifdef FS_FAST
302
#undef item_add_param
303
#endif /* defined (FS_FAST) */
304
void
7 7u83 305
item_add_param(ItemP item, TypeTupleP param)
2 7u83 306
{
7 7u83 307
    types_assign(item_param(item), param);
2 7u83 308
}
309
#ifdef FS_FAST
7 7u83 310
#define item_add_param(i, t)	(types_assign(&((i)->param), (t)))
2 7u83 311
#endif /* defined (FS_FAST) */
312
 
313
#ifdef FS_FAST
314
#undef item_result
315
#endif /* defined (FS_FAST) */
316
TypeTupleP
7 7u83 317
item_result(ItemP item)
2 7u83 318
{
7 7u83 319
    return(&(item->result));
2 7u83 320
}
321
#ifdef FS_FAST
7 7u83 322
#define item_result(i)	(&((i)->result))
2 7u83 323
#endif /* defined (FS_FAST) */
324
 
325
#ifdef FS_FAST
326
#undef item_add_result
327
#endif /* defined (FS_FAST) */
328
void
7 7u83 329
item_add_result(ItemP item, TypeTupleP result)
2 7u83 330
{
7 7u83 331
    types_assign(item_result(item), result);
2 7u83 332
}
333
#ifdef FS_FAST
7 7u83 334
#define item_add_result(i, t)	(types_assign(&((i)->result), (t)))
2 7u83 335
#endif /* defined (FS_FAST) */
336
 
337
#ifdef FS_FAST
338
#undef item_is_inlinable
339
#endif /* defined (FS_FAST) */
340
BoolT
7 7u83 341
item_is_inlinable(ItemP item)
2 7u83 342
{
7 7u83 343
    return(item->inlinable);
2 7u83 344
}
345
#ifdef FS_FAST
7 7u83 346
#define item_is_inlinable(i)	((i)->inlinable)
2 7u83 347
#endif /* defined (FS_FAST) */
348
 
349
#ifdef FS_FAST
350
#undef item_inlinable
351
#endif /* defined (FS_FAST) */
352
void
7 7u83 353
item_inlinable(ItemP item)
2 7u83 354
{
355
    item->inlinable = TRUE;
356
}
357
#ifdef FS_FAST
7 7u83 358
#define item_inlinable(i)	((i)->inlinable = TRUE)
2 7u83 359
#endif /* defined (FS_FAST) */
360
 
361
#ifdef FS_FAST
362
#undef item_is_tail_call
363
#endif /* defined (FS_FAST) */
364
BoolT
7 7u83 365
item_is_tail_call(ItemP item)
2 7u83 366
{
7 7u83 367
    return(item->tail_call);
2 7u83 368
}
369
#ifdef FS_FAST
7 7u83 370
#define item_is_tail_call(i)	((i)->tail_call)
2 7u83 371
#endif /* defined (FS_FAST) */
372
 
373
#ifdef FS_FAST
374
#undef item_tail_call
375
#endif /* defined (FS_FAST) */
376
void
7 7u83 377
item_tail_call(ItemP item)
2 7u83 378
{
379
    item->tail_call = TRUE;
380
}
381
#ifdef FS_FAST
7 7u83 382
#define item_tail_call(i)	((i)->tail_call = TRUE)
2 7u83 383
#endif /* defined (FS_FAST) */
384
 
385
BoolT
7 7u83 386
item_names_used_in_list(ItemP item, TypeTupleP names)
2 7u83 387
{
388
    while (item) {
7 7u83 389
	if ((types_intersect(item_param(item), names)) ||
390
	    (types_intersect(item_result(item), names))) {
391
	    return(TRUE);
2 7u83 392
	}
7 7u83 393
	item = item_next(item);
2 7u83 394
    }
7 7u83 395
    return(FALSE);
2 7u83 396
}
397
 
398
void
7 7u83 399
item_compute_minimal_dataflow(ItemP item, TypeTupleP used)
2 7u83 400
{
401
    if (item) {
7 7u83 402
	ItemP next = item_next(item);
2 7u83 403
 
404
	if (next) {
7 7u83 405
	    item_compute_minimal_dataflow(next, used);
2 7u83 406
	}
7 7u83 407
	if (item_is_inlinable(item)) {
408
	    RuleP rule = entry_get_rule(item_entry(item));
2 7u83 409
 
7 7u83 410
	    types_inplace_intersection(item_result(item), used);
411
	    types_inplace_intersection(rule_result(rule), used);
412
	    rule_compute_minimal_dataflow(rule, item_param(item));
2 7u83 413
	}
7 7u83 414
	types_add_new_names(used, item_param(item), NIL(EntryP));
2 7u83 415
    }
416
}
417
 
418
ItemP
7 7u83 419
item_deallocate(ItemP item)
2 7u83 420
{
7 7u83 421
    ItemP next = item_next(item);
2 7u83 422
 
7 7u83 423
    types_destroy(item_param(item));
424
    types_destroy(item_result(item));
425
    DEALLOCATE(item);
426
    return(next);
2 7u83 427
}
428
 
429
void
7 7u83 430
write_item(OStreamP ostream, ItemP item)
2 7u83 431
{
7 7u83 432
    EntryP entry = item_entry(item);
2 7u83 433
 
7 7u83 434
    write_type_names(ostream, item_result(item), TRUE);
435
    if (item_is_predicate(item)) {
436
	write_cstring(ostream, " ?");
2 7u83 437
    }
7 7u83 438
    write_cstring(ostream, " = ");
439
    switch (item_type(item))EXHAUSTIVE {
2 7u83 440
      case ET_ACTION:
441
      case ET_PREDICATE:
7 7u83 442
	write_char(ostream, '<');
443
	write_key(ostream, entry_key(entry));
444
	write_cstring(ostream, "> ");
2 7u83 445
	break;
446
      case ET_RULE:
7 7u83 447
	if (item_is_inlinable(item)) {
448
	    if (item_is_tail_call(item)) {
449
		write_char(ostream, '*');
2 7u83 450
	    } else {
7 7u83 451
		write_char(ostream, '+');
2 7u83 452
	    }
453
	}
454
	FALL_THROUGH;
455
      case ET_BASIC:
7 7u83 456
	write_key(ostream, entry_key(item_entry(item)));
457
	write_char(ostream, ' ');
2 7u83 458
	break;
459
      case ET_RENAME:
460
	break;
461
      case ET_NON_LOCAL:
462
      case ET_NAME:
463
      case ET_TYPE:
464
	UNREACHED;
465
    }
7 7u83 466
    write_type_names(ostream, item_param(item), TRUE);
467
    write_char(ostream, ';');
2 7u83 468
}
469
 
470
/*
471
 * Local variables(smf):
472
 * eval: (include::add-path-entry "../os-interface" "../library")
473
 * eval: (include::add-path-entry "../generated")
474
 * end:
475
**/