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
/*** shape-table.c --- Shape table ADT.
32
 *
33
 ** Author: Steve Folkes <smf@hermes.mod.uk>
34
 *
35
 *** Commentary:
36
 *
37
 * This file implements the shape table routines used by the TDF linker.
38
 *
39
 *** Change Log:
40
 * $Log: shape-table.c,v $
41
 * Revision 1.1.1.1  1998/01/17  15:57:20  release
42
 * First version to be checked into rolling release.
43
 *
44
 * Revision 1.3  1995/09/22  08:39:34  smf
45
 * Fixed problems with incomplete structures (to shut "tcc" up).
46
 * Fixed some problems in "name-key.c" (no real problems, but rewritten to
47
 * reduce the warnings that were output by "tcc" and "gcc").
48
 * Fixed bug CR95_354.tld-common-id-problem (library capsules could be loaded
49
 * more than once).
50
 *
51
 * Revision 1.2  1994/12/12  11:46:50  smf
52
 * Performing changes for 'CR94_178.sid+tld-update' - bringing in line with
53
 * OSSG C Coding Standards.
54
 *
55
 * Revision 1.1.1.1  1994/07/25  16:03:38  smf
56
 * Initial import of TDF linker 3.5 non shared files.
57
 *
58
**/
59
 
60
/****************************************************************************/
61
 
62
#include "shape-table.h"
63
 
64
#include "solve-cycles.h"
65
 
66
/*--------------------------------------------------------------------------*/
67
 
68
ShapeTableP
69
shape_table_create PROTO_Z ()
70
{
71
    ShapeTableP table = ALLOCATE (ShapeTableT);
72
    unsigned    i;
73
 
74
    for (i = 0; i < SHAPE_TABLE_SIZE; i ++) {
75
	table->contents [i] = NIL (ShapeEntryP);
76
    }
77
    table->token_entry = NIL (ShapeEntryP);
78
    table->tag_entry   = NIL (ShapeEntryP);
79
    return (table);
80
}
81
 
82
ShapeEntryP
83
shape_table_add PROTO_N ((table, key))
84
		PROTO_T (ShapeTableP table X
85
			 NStringP    key)
86
{
87
    unsigned     hash_value = (nstring_hash_value (key) % SHAPE_TABLE_SIZE);
88
    ShapeEntryP *entryp     = &(table->contents [hash_value]);
89
    ShapeEntryP  entry;
90
 
91
    while ((entry = *entryp) != NIL (ShapeEntryP)) {
92
	if (nstring_equal (key, shape_entry_key (entry))) {
93
	    return (entry);
94
	}
95
	entryp = shape_entry_next_ref (entry);
96
    }
97
    entry   = shape_entry_create (key);
98
    *entryp = entry;
99
    return (entry);
100
}
101
 
102
ShapeEntryP
103
shape_table_get PROTO_N ((table, key))
104
		PROTO_T (ShapeTableP table X
105
			 NStringP    key)
106
{
107
    unsigned    hash_value = (nstring_hash_value (key) % SHAPE_TABLE_SIZE);
108
    ShapeEntryP entry      = (table->contents [hash_value]);
109
 
110
    while (entry) {
111
	if (nstring_equal (key, shape_entry_key (entry))) {
112
	    return (entry);
113
	}
114
	entry = shape_entry_next (entry);
115
    }
116
    return (NIL (ShapeEntryP));
117
}
118
 
119
ShapeEntryP
120
shape_table_get_token_entry PROTO_N ((table))
121
			    PROTO_T (ShapeTableP table)
122
{
123
    if (table->token_entry == NIL (ShapeEntryP)) {
124
	NStringT nstring;
125
 
126
	nstring_copy_cstring (&nstring, "token");
127
	table->token_entry = shape_table_get (table, &nstring);
128
	nstring_destroy (&nstring);
129
    }
130
    return (table->token_entry);
131
}
132
 
133
ShapeEntryP
134
shape_table_get_tag_entry PROTO_N ((table))
135
			  PROTO_T (ShapeTableP table)
136
{
137
    if (table->tag_entry == NIL (ShapeEntryP)) {
138
	NStringT nstring;
139
 
140
	nstring_copy_cstring (&nstring, "tag");
141
	table->tag_entry = shape_table_get (table, &nstring);
142
	nstring_destroy (&nstring);
143
    }
144
    return (table->tag_entry);
145
}
146
 
147
void
148
shape_table_iter PROTO_N ((table, proc, closure))
149
		 PROTO_T (ShapeTableP table X
150
			  void      (*proc) PROTO_S ((ShapeEntryP, GenericP)) X
151
			  GenericP    closure)
152
{
153
    unsigned i;
154
 
155
    for (i = 0; i < SHAPE_TABLE_SIZE; i ++) {
156
	ShapeEntryP entry = (table->contents [i]);
157
 
158
	while (entry) {
159
	    (*proc) (entry, closure);
160
	    entry = shape_entry_next (entry);
161
	}
162
    }
163
}
164
 
165
void
166
shape_table_deallocate PROTO_N ((table))
167
		       PROTO_T (ShapeTableP table)
168
{
169
    unsigned i;
170
 
171
    for (i = 0; i < SHAPE_TABLE_SIZE; i ++) {
172
	ShapeEntryP entry = (table->contents [i]);
173
 
174
	while (entry) {
175
	    entry = shape_entry_deallocate (entry);
176
	}
177
    }
178
}
179
 
180
/*
181
 * Local variables(smf):
182
 * eval: (include::add-path-entry "../os-interface" "../library")
183
 * eval: (include::add-path-entry "../generated")
184
 * end:
185
**/