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/utilities/sid/table.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
/*** table.c --- Identifier table ADT.
32
 *
33
 ** Author: Steve Folkes <smf@hermes.mod.uk>
34
 *
35
 *** Commentary:
36
 *
37
 * This file implements the identifier table routines used by SID.
38
 *
39
 *** Change Log:
40
 * $Log: table.c,v $
41
 * Revision 1.1.1.1  1998/01/17  15:57:47  release
42
 * First version to be checked into rolling release.
43
 *
44
 * Revision 1.3  1994/12/15  09:59:05  smf
45
 * Brought into line with OSSG C Coding Standards Document, as per
46
 * "CR94_178.sid+tld-update".
47
 *
48
 * Revision 1.2  1994/08/22  09:37:32  smf
49
 * Fixed bug DR114:ids-too-long.
50
 *
51
 * Revision 1.1.1.1  1994/07/25  16:04:43  smf
52
 * Initial import of SID 1.8 non shared files.
53
 *
54
**/
55
 
56
/****************************************************************************/
57
 
58
#include "table.h"
59
#include "action.h"
60
#include "basic.h"
61
#include "gen-errors.h"
62
#include "grammar.h"
63
#include "name.h"
64
#include "rule.h"
65
#include "type.h"
66
 
67
/*--------------------------------------------------------------------------*/
68
 
69
static unsigned
70
table_next_generated_key PROTO_Z ()
71
{
72
    static unsigned sequence = 0;
73
 
74
    if (sequence == UINT_MAX) {
75
	E_too_many_generated_ids ();
76
	UNREACHED;
77
    }
78
    return (sequence ++);
79
}
80
 
81
static EntryP
82
table_add_entry PROTO_N ((table, key, type, found_ref))
83
		PROTO_T (TableP     table X
84
			 NStringP   key X
85
			 EntryTypeT type X
86
			 BoolT     *found_ref)
87
{
88
    unsigned hash   = (nstring_hash_value (key) % TABLE_SIZE);
89
    EntryP  *entryp = &(table->contents [hash]);
90
    EntryP   entry;
91
    unsigned number;
92
 
93
    *found_ref = FALSE;
94
    while ((entry = *entryp) != NIL (EntryP)) {
95
	KeyP ent_key = entry_key (entry);
96
 
97
	if ((key_is_string (ent_key)) &&
98
	    (nstring_equal (key_get_string (ent_key), key))) {
99
	    if (type == ET_NAME) {
100
		nstring_destroy (key);
101
		return (entry);
102
	    } else if (entry_type (entry) == ET_NAME) {
103
		nstring_destroy (key);
104
		entry_change_type (entry, type);
105
		return (entry);
106
	    } else if ((entry_type (entry) == type) &&
107
		       ((type == ET_ACTION) || (type == ET_RULE))) {
108
		*found_ref = TRUE;
109
		nstring_destroy (key);
110
		return (entry);
111
	    } else {
112
		return (NIL (EntryP));
113
	    }
114
	}
115
	entryp = entry_next_ref (entry);
116
    }
117
    number  = table_next_generated_key ();
118
    entry   = entry_create_from_string (key, number, type);
119
    *entryp = entry;
120
    return (entry);
121
}
122
 
123
/*--------------------------------------------------------------------------*/
124
 
125
void
126
table_init PROTO_N ((table))
127
	   PROTO_T (TableP table)
128
{
129
    unsigned i;
130
 
131
    for (i = 0; i < TABLE_SIZE; i ++) {
132
	table->contents [i] = NIL (EntryP);
133
    }
134
}
135
 
136
EntryP
137
table_add_type PROTO_N ((table, key))
138
	       PROTO_T (TableP   table X
139
			NStringP key)
140
{
141
    BoolT  found;
142
    EntryP entry = table_add_entry (table, key, ET_TYPE, &found);
143
 
144
    if (entry) {
145
	entry_set_type (entry, type_create ());
146
    }
147
    return (entry);
148
}
149
 
150
EntryP
151
table_add_basic PROTO_N ((table, key, grammar, ignored))
152
		PROTO_T (TableP   table X
153
			 NStringP key X
154
			 GrammarP grammar X
155
			 BoolT    ignored)
156
{
157
    BoolT  found;
158
    EntryP entry = table_add_entry (table, key, ET_BASIC, &found);
159
 
160
    if (entry) {
161
	entry_set_basic (entry, basic_create (grammar, ignored));
162
    }
163
    return (entry);
164
}
165
 
166
EntryP
167
table_add_action PROTO_N ((table, key))
168
		 PROTO_T (TableP   table X
169
			  NStringP key)
170
{
171
    BoolT  found;
172
    EntryP entry = table_add_entry (table, key, ET_ACTION, &found);
173
 
174
    if ((entry != NIL (EntryP)) && (!found)) {
175
	entry_set_action (entry, action_create ());
176
    }
177
    return (entry);
178
}
179
 
180
EntryP
181
table_add_rule PROTO_N ((table, key))
182
	       PROTO_T (TableP   table X
183
			NStringP key)
184
{
185
    BoolT  found;
186
    EntryP entry = table_add_entry (table, key, ET_RULE, &found);
187
 
188
    if ((entry != NIL (EntryP)) && (!found)) {
189
	entry_set_rule (entry, rule_create (entry));
190
    }
191
    return (entry);
192
}
193
 
194
EntryP
195
table_add_generated_rule PROTO_N ((table, traced))
196
			 PROTO_T (TableP table X
197
				  BoolT  traced)
198
{
199
    unsigned sequence = table_next_generated_key ();
200
    unsigned hash     = (sequence % TABLE_SIZE);
201
    EntryP  *entryp   = &(table->contents [hash]);
202
    EntryP   entry;
203
 
204
    entry = entry_create_from_number (sequence, ET_RULE, traced, *entryp);
205
    entry_set_rule (entry, rule_create (entry));
206
    *entryp = entry;
207
    return (entry);
208
}
209
 
210
EntryP
211
table_add_name PROTO_N ((table, key))
212
	       PROTO_T (TableP   table X
213
			NStringP key)
214
{
215
    BoolT found;
216
 
217
    return (table_add_entry (table, key, ET_NAME, &found));
218
}
219
 
220
EntryP
221
table_add_generated_name PROTO_N ((table))
222
			 PROTO_T (TableP table)
223
{
224
    unsigned sequence = table_next_generated_key ();
225
    unsigned hash     = (sequence % TABLE_SIZE);
226
    EntryP  *entryp   = &(table->contents [hash]);
227
    EntryP   entry;
228
 
229
    entry = entry_create_from_number (sequence, ET_NAME, FALSE, *entryp);
230
    *entryp = entry;
231
    return (entry);
232
}
233
 
234
EntryP
235
table_add_rename PROTO_N ((table))
236
		 PROTO_T (TableP table)
237
{
238
    unsigned sequence = table_next_generated_key ();
239
    unsigned hash     = (sequence % TABLE_SIZE);
240
    EntryP  *entryp   = &(table->contents [hash]);
241
    EntryP   entry;
242
 
243
    entry = entry_create_from_number (sequence, ET_RENAME, TRUE, *entryp);
244
    *entryp = entry;
245
    return (entry);
246
}
247
 
248
EntryP
249
table_add_non_local PROTO_N ((table, key, type))
250
		    PROTO_T (TableP   table X
251
			     NStringP key X
252
			     EntryP   type)
253
{
254
    BoolT  found;
255
    EntryP entry = table_add_entry (table, key, ET_NON_LOCAL, &found);
256
 
257
    if (entry) {
258
	entry_set_non_local (entry, type);
259
    }
260
    return (entry);
261
}
262
 
263
EntryP
264
table_get_entry PROTO_N ((table, key))
265
		PROTO_T (TableP   table X
266
			 NStringP key)
267
{
268
    unsigned hash  = (nstring_hash_value (key) % TABLE_SIZE);
269
    EntryP   entry = (table->contents [hash]);
270
 
271
    while (entry) {
272
	KeyP ent_key = entry_key (entry);
273
 
274
	if ((key_is_string (ent_key)) &&
275
	    (nstring_equal (key_get_string (ent_key), key))) {
276
	    return (entry);
277
	}
278
	entry = entry->next;
279
    }
280
    return (NIL (EntryP));
281
}
282
 
283
EntryP
284
table_get_type PROTO_N ((table, key))
285
	       PROTO_T (TableP   table X
286
			NStringP key)
287
{
288
    EntryP entry = table_get_entry (table, key);
289
 
290
    if ((entry) && (entry_is_type (entry))) {
291
	return (entry);
292
    } else {
293
	return (NIL (EntryP));
294
    }
295
}
296
 
297
EntryP
298
table_get_basic PROTO_N ((table, key))
299
		PROTO_T (TableP   table X
300
			 NStringP key)
301
{
302
    EntryP entry = table_get_entry (table, key);
303
 
304
    if ((entry) && (entry_is_basic (entry))) {
305
	return (entry);
306
    } else {
307
	return (NIL (EntryP));
308
    }
309
}
310
 
311
EntryP
312
table_get_basic_by_number PROTO_N ((table, number))
313
			  PROTO_T (TableP   table X
314
				   unsigned number)
315
{
316
    unsigned i;
317
 
318
    for (i = 0; i < TABLE_SIZE; i ++) {
319
	EntryP entry;
320
 
321
	for (entry = table->contents [i]; entry; entry = entry_next (entry)) {
322
	    if (entry_is_basic (entry)) {
323
		BasicP basic = entry_get_basic (entry);
324
 
325
		if (basic_terminal (basic) == number) {
326
		    return (entry);
327
		}
328
	    }
329
	}
330
    }
331
    return (NIL (EntryP));
332
}
333
 
334
EntryP
335
table_get_action PROTO_N ((table, key))
336
		 PROTO_T (TableP   table X
337
			  NStringP key)
338
{
339
    EntryP entry = table_get_entry (table, key);
340
 
341
    if ((entry) && (entry_is_action (entry))) {
342
	return (entry);
343
    } else {
344
	return (NIL (EntryP));
345
    }
346
}
347
 
348
EntryP
349
table_get_rule PROTO_N ((table, key))
350
	       PROTO_T (TableP   table X
351
			NStringP key)
352
{
353
    EntryP entry = table_get_entry (table, key);
354
 
355
    if ((entry) && (entry_is_rule (entry))) {
356
	return (entry);
357
    } else {
358
	return (NIL (EntryP));
359
    }
360
}
361
 
362
void
363
table_iter PROTO_N ((table, proc, closure))
364
	   PROTO_T (TableP  table X
365
		    void   (*proc) PROTO_S ((EntryP, GenericP)) X
366
		    GenericP closure)
367
{
368
    unsigned i;
369
 
370
    for (i = 0; i < TABLE_SIZE; i ++) {
371
	EntryP entry;
372
 
373
	for (entry = table->contents [i]; entry; entry = entry_next (entry)) {
374
	    (*proc) (entry, closure);
375
	}
376
    }
377
}
378
 
379
void
380
table_untrace PROTO_N ((table))
381
	      PROTO_T (TableP table)
382
{
383
    unsigned i;
384
 
385
    for (i = 0; i < TABLE_SIZE; i ++) {
386
	EntryP entry;
387
 
388
	for (entry = table->contents [i]; entry; entry = entry_next (entry)) {
389
	    entry_not_traced (entry);
390
	}
391
    }
392
}
393
 
394
void
395
table_unlink_untraced_rules PROTO_N ((table))
396
			    PROTO_T (TableP table)
397
{
398
    unsigned i;
399
 
400
    for (i = 0; i < TABLE_SIZE; i ++) {
401
	EntryP entry = (table->contents [i]);
402
 
403
	while (entry) {
404
	    if (entry_is_rule (entry) && (!entry_is_traced (entry))) {
405
		rule_deallocate (entry_get_rule (entry));
406
		entry_change_type (entry, ET_NAME);
407
	    }
408
	    entry = entry_next (entry);
409
	}
410
    }
411
}
412
 
413
/*
414
 * Local variables(smf):
415
 * eval: (include::add-path-entry "../os-interface" "../library")
416
 * eval: (include::add-path-entry "../generated")
417
 * end:
418
**/