2 |
7u83 |
1 |
/*
|
7 |
7u83 |
2 |
* Copyright (c) 2002-2006 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 |
/*** name-table.c --- Name table ADT.
|
|
|
62 |
*
|
|
|
63 |
** Author: Steve Folkes <smf@hermes.mod.uk>
|
|
|
64 |
*
|
|
|
65 |
*** Commentary:
|
|
|
66 |
*
|
|
|
67 |
* This file implements the name table routines used by the TDF linker.
|
|
|
68 |
*
|
|
|
69 |
*** Change Log:
|
|
|
70 |
* $Log: name-table.c,v $
|
|
|
71 |
* Revision 1.1.1.1 1998/01/17 15:57:19 release
|
|
|
72 |
* First version to be checked into rolling release.
|
|
|
73 |
*
|
|
|
74 |
* Revision 1.3 1995/09/22 08:39:29 smf
|
|
|
75 |
* Fixed problems with incomplete structures (to shut "tcc" up).
|
|
|
76 |
* Fixed some problems in "name-key.c" (no real problems, but rewritten to
|
|
|
77 |
* reduce the warnings that were output by "tcc" and "gcc").
|
|
|
78 |
* Fixed bug CR95_354.tld-common-id-problem (library capsules could be loaded
|
|
|
79 |
* more than once).
|
|
|
80 |
*
|
|
|
81 |
* Revision 1.2 1994/12/12 11:46:42 smf
|
|
|
82 |
* Performing changes for 'CR94_178.sid+tld-update' - bringing in line with
|
|
|
83 |
* OSSG C Coding Standards.
|
|
|
84 |
*
|
|
|
85 |
* Revision 1.1.1.1 1994/07/25 16:03:36 smf
|
|
|
86 |
* Initial import of TDF linker 3.5 non shared files.
|
|
|
87 |
*
|
|
|
88 |
**/
|
|
|
89 |
|
|
|
90 |
/****************************************************************************/
|
|
|
91 |
|
|
|
92 |
#include "name-table.h"
|
|
|
93 |
#include "shape-entry.h"
|
|
|
94 |
|
|
|
95 |
#include "solve-cycles.h"
|
|
|
96 |
|
|
|
97 |
/*--------------------------------------------------------------------------*/
|
|
|
98 |
|
|
|
99 |
NameTableP
|
7 |
7u83 |
100 |
name_table_create(void)
|
2 |
7u83 |
101 |
{
|
7 |
7u83 |
102 |
NameTableP table = ALLOCATE(NameTableT);
|
2 |
7u83 |
103 |
unsigned i;
|
|
|
104 |
|
7 |
7u83 |
105 |
for (i = 0; i < NAME_TABLE_SIZE; i++) {
|
|
|
106 |
table->contents[i] = NIL(NameEntryP);
|
2 |
7u83 |
107 |
}
|
7 |
7u83 |
108 |
return(table);
|
2 |
7u83 |
109 |
}
|
|
|
110 |
|
|
|
111 |
void
|
7 |
7u83 |
112 |
name_table_add_rename(NameTableP table, NameKeyP from,
|
2 |
7u83 |
113 |
NameKeyP to)
|
|
|
114 |
{
|
7 |
7u83 |
115 |
unsigned to_hash_value = (name_key_hash_value(to)% NAME_TABLE_SIZE);
|
|
|
116 |
NameEntryP *to_entryp = & (table->contents[to_hash_value]);
|
|
|
117 |
unsigned hash_value = (name_key_hash_value(from)% NAME_TABLE_SIZE);
|
|
|
118 |
NameEntryP *from_entryp = & (table->contents[hash_value]);
|
2 |
7u83 |
119 |
NameEntryP to_entry;
|
|
|
120 |
NameEntryP from_entry;
|
|
|
121 |
|
7 |
7u83 |
122 |
while ((to_entry = *to_entryp) != NIL(NameEntryP)) {
|
|
|
123 |
if (name_key_equal(to, name_entry_key(to_entry))) {
|
2 |
7u83 |
124 |
goto found;
|
|
|
125 |
}
|
7 |
7u83 |
126 |
to_entryp = name_entry_next_ref(to_entry);
|
2 |
7u83 |
127 |
}
|
7 |
7u83 |
128 |
to_entry = name_entry_create_place(to);
|
2 |
7u83 |
129 |
*to_entryp = to_entry;
|
|
|
130 |
found:
|
7 |
7u83 |
131 |
while ((from_entry = *from_entryp) != NIL(NameEntryP)) {
|
|
|
132 |
if (name_key_equal(from, name_entry_key(from_entry))) {
|
|
|
133 |
name_entry_make_indirect(from_entry, to_entry);
|
2 |
7u83 |
134 |
return;
|
|
|
135 |
}
|
7 |
7u83 |
136 |
from_entryp = name_entry_next_ref(from_entry);
|
2 |
7u83 |
137 |
}
|
7 |
7u83 |
138 |
from_entry = name_entry_create_indirect(from, to_entry);
|
2 |
7u83 |
139 |
*from_entryp = from_entry;
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
void
|
7 |
7u83 |
143 |
name_table_resolve_renames(NameTableP table, NStringP shape,
|
2 |
7u83 |
144 |
BoolT report)
|
|
|
145 |
{
|
|
|
146 |
unsigned i;
|
|
|
147 |
|
7 |
7u83 |
148 |
for (i = 0; i < NAME_TABLE_SIZE; i++) {
|
|
|
149 |
NameEntryP entry = (table->contents[i]);
|
2 |
7u83 |
150 |
|
|
|
151 |
while (entry) {
|
7 |
7u83 |
152 |
(void)name_entry_resolve_renames(entry, shape, report);
|
|
|
153 |
entry = name_entry_next(entry);
|
2 |
7u83 |
154 |
}
|
|
|
155 |
}
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
NameEntryP
|
7 |
7u83 |
159 |
name_table_add(NameTableP table, NameKeyP key,
|
2 |
7u83 |
160 |
ShapeEntryP shape_entry)
|
|
|
161 |
{
|
7 |
7u83 |
162 |
unsigned hash_value = (name_key_hash_value(key)% NAME_TABLE_SIZE);
|
|
|
163 |
NameEntryP *entryp = & (table->contents[hash_value]);
|
2 |
7u83 |
164 |
NameEntryP entry;
|
|
|
165 |
|
7 |
7u83 |
166 |
while ((entry = *entryp) != NIL(NameEntryP)) {
|
|
|
167 |
if (name_key_equal(key, name_entry_key(entry))) {
|
|
|
168 |
if (name_entry_is_indirect(entry)) {
|
|
|
169 |
entry = name_entry_get_indirect(entry);
|
2 |
7u83 |
170 |
}
|
7 |
7u83 |
171 |
if (name_entry_is_place(entry)) {
|
|
|
172 |
name_entry_make_direct(entry, shape_entry);
|
2 |
7u83 |
173 |
}
|
7 |
7u83 |
174 |
return(entry);
|
2 |
7u83 |
175 |
}
|
7 |
7u83 |
176 |
entryp = name_entry_next_ref(entry);
|
2 |
7u83 |
177 |
}
|
7 |
7u83 |
178 |
entry = name_entry_create_direct(key, shape_entry);
|
2 |
7u83 |
179 |
*entryp = entry;
|
7 |
7u83 |
180 |
return(entry);
|
2 |
7u83 |
181 |
}
|
|
|
182 |
|
|
|
183 |
NameEntryP
|
7 |
7u83 |
184 |
name_table_get(NameTableP table, NameKeyP key)
|
2 |
7u83 |
185 |
{
|
7 |
7u83 |
186 |
unsigned hash_value = (name_key_hash_value(key)% NAME_TABLE_SIZE);
|
|
|
187 |
NameEntryP entry = table->contents[hash_value];
|
2 |
7u83 |
188 |
|
|
|
189 |
while (entry) {
|
7 |
7u83 |
190 |
if (name_key_equal(key, name_entry_key(entry))) {
|
|
|
191 |
if (name_entry_is_indirect(entry)) {
|
|
|
192 |
entry = name_entry_get_indirect(entry);
|
2 |
7u83 |
193 |
}
|
7 |
7u83 |
194 |
if (name_entry_is_place(entry)) {
|
|
|
195 |
return(NIL(NameEntryP));
|
2 |
7u83 |
196 |
}
|
7 |
7u83 |
197 |
return(entry);
|
2 |
7u83 |
198 |
}
|
7 |
7u83 |
199 |
entry = name_entry_next(entry);
|
2 |
7u83 |
200 |
}
|
7 |
7u83 |
201 |
return(NIL(NameEntryP));
|
2 |
7u83 |
202 |
}
|
|
|
203 |
|
|
|
204 |
void
|
7 |
7u83 |
205 |
name_table_iter(NameTableP table, void(*proc)(NameEntryP, GenericP),
|
|
|
206 |
GenericP closure)
|
2 |
7u83 |
207 |
{
|
|
|
208 |
unsigned i;
|
|
|
209 |
|
7 |
7u83 |
210 |
for (i = 0; i < NAME_TABLE_SIZE; i++) {
|
|
|
211 |
NameEntryP entry = (table->contents[i]);
|
2 |
7u83 |
212 |
|
|
|
213 |
while (entry) {
|
7 |
7u83 |
214 |
if (name_entry_is_direct(entry)) {
|
|
|
215 |
(*proc)(entry, closure);
|
2 |
7u83 |
216 |
}
|
7 |
7u83 |
217 |
entry = name_entry_next(entry);
|
2 |
7u83 |
218 |
}
|
|
|
219 |
}
|
|
|
220 |
}
|
|
|
221 |
|
|
|
222 |
void
|
7 |
7u83 |
223 |
name_table_deallocate(NameTableP table)
|
2 |
7u83 |
224 |
{
|
|
|
225 |
unsigned i;
|
|
|
226 |
|
7 |
7u83 |
227 |
for (i = 0; i < NAME_TABLE_SIZE; i++) {
|
|
|
228 |
NameEntryP entry = (table->contents[i]);
|
2 |
7u83 |
229 |
|
|
|
230 |
while (entry) {
|
7 |
7u83 |
231 |
entry = name_entry_deallocate(entry);
|
2 |
7u83 |
232 |
}
|
|
|
233 |
}
|
|
|
234 |
}
|
|
|
235 |
|
|
|
236 |
/*
|
|
|
237 |
* Local variables(smf):
|
|
|
238 |
* eval: (include::add-path-entry "../os-interface" "../library")
|
|
|
239 |
* eval: (include::add-path-entry "../generated")
|
|
|
240 |
* end:
|
|
|
241 |
**/
|