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 |
/*** name-table.c --- Name table ADT.
|
|
|
32 |
*
|
|
|
33 |
** Author: Steve Folkes <smf@hermes.mod.uk>
|
|
|
34 |
*
|
|
|
35 |
*** Commentary:
|
|
|
36 |
*
|
|
|
37 |
* This file implements the name table routines used by the TDF linker.
|
|
|
38 |
*
|
|
|
39 |
*** Change Log:
|
|
|
40 |
* $Log: name-table.c,v $
|
|
|
41 |
* Revision 1.1.1.1 1998/01/17 15:57:19 release
|
|
|
42 |
* First version to be checked into rolling release.
|
|
|
43 |
*
|
|
|
44 |
* Revision 1.3 1995/09/22 08:39:29 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:42 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:36 smf
|
|
|
56 |
* Initial import of TDF linker 3.5 non shared files.
|
|
|
57 |
*
|
|
|
58 |
**/
|
|
|
59 |
|
|
|
60 |
/****************************************************************************/
|
|
|
61 |
|
|
|
62 |
#include "name-table.h"
|
|
|
63 |
#include "shape-entry.h"
|
|
|
64 |
|
|
|
65 |
#include "solve-cycles.h"
|
|
|
66 |
|
|
|
67 |
/*--------------------------------------------------------------------------*/
|
|
|
68 |
|
|
|
69 |
NameTableP
|
|
|
70 |
name_table_create PROTO_Z ()
|
|
|
71 |
{
|
|
|
72 |
NameTableP table = ALLOCATE (NameTableT);
|
|
|
73 |
unsigned i;
|
|
|
74 |
|
|
|
75 |
for (i = 0; i < NAME_TABLE_SIZE; i ++) {
|
|
|
76 |
table->contents [i] = NIL (NameEntryP);
|
|
|
77 |
}
|
|
|
78 |
return (table);
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
void
|
|
|
82 |
name_table_add_rename PROTO_N ((table, from, to))
|
|
|
83 |
PROTO_T (NameTableP table X
|
|
|
84 |
NameKeyP from X
|
|
|
85 |
NameKeyP to)
|
|
|
86 |
{
|
|
|
87 |
unsigned to_hash_value = (name_key_hash_value (to) % NAME_TABLE_SIZE);
|
|
|
88 |
NameEntryP *to_entryp = &(table->contents [to_hash_value]);
|
|
|
89 |
unsigned hash_value = (name_key_hash_value (from) % NAME_TABLE_SIZE);
|
|
|
90 |
NameEntryP *from_entryp = &(table->contents [hash_value]);
|
|
|
91 |
NameEntryP to_entry;
|
|
|
92 |
NameEntryP from_entry;
|
|
|
93 |
|
|
|
94 |
while ((to_entry = *to_entryp) != NIL (NameEntryP)) {
|
|
|
95 |
if (name_key_equal (to, name_entry_key (to_entry))) {
|
|
|
96 |
goto found;
|
|
|
97 |
}
|
|
|
98 |
to_entryp = name_entry_next_ref (to_entry);
|
|
|
99 |
}
|
|
|
100 |
to_entry = name_entry_create_place (to);
|
|
|
101 |
*to_entryp = to_entry;
|
|
|
102 |
found:
|
|
|
103 |
while ((from_entry = *from_entryp) != NIL (NameEntryP)) {
|
|
|
104 |
if (name_key_equal (from, name_entry_key (from_entry))) {
|
|
|
105 |
name_entry_make_indirect (from_entry, to_entry);
|
|
|
106 |
return;
|
|
|
107 |
}
|
|
|
108 |
from_entryp = name_entry_next_ref (from_entry);
|
|
|
109 |
}
|
|
|
110 |
from_entry = name_entry_create_indirect (from, to_entry);
|
|
|
111 |
*from_entryp = from_entry;
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
void
|
|
|
115 |
name_table_resolve_renames PROTO_N ((table, shape, report))
|
|
|
116 |
PROTO_T (NameTableP table X
|
|
|
117 |
NStringP shape X
|
|
|
118 |
BoolT report)
|
|
|
119 |
{
|
|
|
120 |
unsigned i;
|
|
|
121 |
|
|
|
122 |
for (i = 0; i < NAME_TABLE_SIZE; i ++) {
|
|
|
123 |
NameEntryP entry = (table->contents [i]);
|
|
|
124 |
|
|
|
125 |
while (entry) {
|
|
|
126 |
(void) name_entry_resolve_renames (entry, shape, report);
|
|
|
127 |
entry = name_entry_next (entry);
|
|
|
128 |
}
|
|
|
129 |
}
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
NameEntryP
|
|
|
133 |
name_table_add PROTO_N ((table, key, shape_entry))
|
|
|
134 |
PROTO_T (NameTableP table X
|
|
|
135 |
NameKeyP key X
|
|
|
136 |
ShapeEntryP shape_entry)
|
|
|
137 |
{
|
|
|
138 |
unsigned hash_value = (name_key_hash_value (key) % NAME_TABLE_SIZE);
|
|
|
139 |
NameEntryP *entryp = &(table->contents [hash_value]);
|
|
|
140 |
NameEntryP entry;
|
|
|
141 |
|
|
|
142 |
while ((entry = *entryp) != NIL (NameEntryP)) {
|
|
|
143 |
if (name_key_equal (key, name_entry_key (entry))) {
|
|
|
144 |
if (name_entry_is_indirect (entry)) {
|
|
|
145 |
entry = name_entry_get_indirect (entry);
|
|
|
146 |
}
|
|
|
147 |
if (name_entry_is_place (entry)) {
|
|
|
148 |
name_entry_make_direct (entry, shape_entry);
|
|
|
149 |
}
|
|
|
150 |
return (entry);
|
|
|
151 |
}
|
|
|
152 |
entryp = name_entry_next_ref (entry);
|
|
|
153 |
}
|
|
|
154 |
entry = name_entry_create_direct (key, shape_entry);
|
|
|
155 |
*entryp = entry;
|
|
|
156 |
return (entry);
|
|
|
157 |
}
|
|
|
158 |
|
|
|
159 |
NameEntryP
|
|
|
160 |
name_table_get PROTO_N ((table, key))
|
|
|
161 |
PROTO_T (NameTableP table X
|
|
|
162 |
NameKeyP key)
|
|
|
163 |
{
|
|
|
164 |
unsigned hash_value = (name_key_hash_value (key) % NAME_TABLE_SIZE);
|
|
|
165 |
NameEntryP entry = table->contents [hash_value];
|
|
|
166 |
|
|
|
167 |
while (entry) {
|
|
|
168 |
if (name_key_equal (key, name_entry_key (entry))) {
|
|
|
169 |
if (name_entry_is_indirect (entry)) {
|
|
|
170 |
entry = name_entry_get_indirect (entry);
|
|
|
171 |
}
|
|
|
172 |
if (name_entry_is_place (entry)) {
|
|
|
173 |
return (NIL (NameEntryP));
|
|
|
174 |
}
|
|
|
175 |
return (entry);
|
|
|
176 |
}
|
|
|
177 |
entry = name_entry_next (entry);
|
|
|
178 |
}
|
|
|
179 |
return (NIL (NameEntryP));
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
void
|
|
|
183 |
name_table_iter PROTO_N ((table, proc, closure))
|
|
|
184 |
PROTO_T (NameTableP table X
|
|
|
185 |
void (*proc) PROTO_S ((NameEntryP, GenericP)) X
|
|
|
186 |
GenericP closure)
|
|
|
187 |
{
|
|
|
188 |
unsigned i;
|
|
|
189 |
|
|
|
190 |
for (i = 0; i < NAME_TABLE_SIZE; i ++) {
|
|
|
191 |
NameEntryP entry = (table->contents [i]);
|
|
|
192 |
|
|
|
193 |
while (entry) {
|
|
|
194 |
if (name_entry_is_direct (entry)) {
|
|
|
195 |
(*proc) (entry, closure);
|
|
|
196 |
}
|
|
|
197 |
entry = name_entry_next (entry);
|
|
|
198 |
}
|
|
|
199 |
}
|
|
|
200 |
}
|
|
|
201 |
|
|
|
202 |
void
|
|
|
203 |
name_table_deallocate PROTO_N ((table))
|
|
|
204 |
PROTO_T (NameTableP table)
|
|
|
205 |
{
|
|
|
206 |
unsigned i;
|
|
|
207 |
|
|
|
208 |
for (i = 0; i < NAME_TABLE_SIZE; i ++) {
|
|
|
209 |
NameEntryP entry = (table->contents [i]);
|
|
|
210 |
|
|
|
211 |
while (entry) {
|
|
|
212 |
entry = name_entry_deallocate (entry);
|
|
|
213 |
}
|
|
|
214 |
}
|
|
|
215 |
}
|
|
|
216 |
|
|
|
217 |
/*
|
|
|
218 |
* Local variables(smf):
|
|
|
219 |
* eval: (include::add-path-entry "../os-interface" "../library")
|
|
|
220 |
* eval: (include::add-path-entry "../generated")
|
|
|
221 |
* end:
|
|
|
222 |
**/
|