Subversion Repositories tendra.SVN

Rev

Rev 5 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5 Rev 6
Line -... Line 1...
-
 
1
/*
-
 
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
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
32
    		 Crown Copyright (c) 1997
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
Line 65... Line 95...
65
#include "solve-cycles.h"
95
#include "solve-cycles.h"
66
 
96
 
67
/*--------------------------------------------------------------------------*/
97
/*--------------------------------------------------------------------------*/
68
 
98
 
69
NameTableP
99
NameTableP
70
name_table_create PROTO_Z ()
100
name_table_create(void)
71
{
101
{
72
    NameTableP table = ALLOCATE (NameTableT);
102
    NameTableP table = ALLOCATE(NameTableT);
73
    unsigned   i;
103
    unsigned   i;
74
 
104
 
75
    for (i = 0; i < NAME_TABLE_SIZE; i ++) {
105
    for (i = 0; i < NAME_TABLE_SIZE; i++) {
76
	table->contents [i] = NIL (NameEntryP);
106
	table->contents[i] = NIL(NameEntryP);
77
    }
107
    }
78
    return (table);
108
    return(table);
79
}
109
}
80
 
110
 
81
void
111
void
82
name_table_add_rename PROTO_N ((table, from, to))
112
name_table_add_rename(NameTableP table,			       NameKeyP   from, 
83
		      PROTO_T (NameTableP table X
-
 
84
			       NameKeyP   from X
-
 
85
			       NameKeyP   to)
113
			       NameKeyP   to)
86
{
114
{
87
    unsigned    to_hash_value = (name_key_hash_value (to) % NAME_TABLE_SIZE);
115
    unsigned    to_hash_value = (name_key_hash_value(to)% NAME_TABLE_SIZE);
88
    NameEntryP *to_entryp     = &(table->contents [to_hash_value]);
116
    NameEntryP *to_entryp     = & (table->contents[to_hash_value]);
89
    unsigned    hash_value    = (name_key_hash_value (from) % NAME_TABLE_SIZE);
117
    unsigned    hash_value    = (name_key_hash_value(from)% NAME_TABLE_SIZE);
90
    NameEntryP *from_entryp   = &(table->contents [hash_value]);
118
    NameEntryP *from_entryp   = & (table->contents[hash_value]);
91
    NameEntryP  to_entry;
119
    NameEntryP  to_entry;
92
    NameEntryP  from_entry;
120
    NameEntryP  from_entry;
93
 
121
 
94
    while ((to_entry = *to_entryp) != NIL (NameEntryP)) {
122
    while ((to_entry = *to_entryp) != NIL(NameEntryP)) {
95
	if (name_key_equal (to, name_entry_key (to_entry))) {
123
	if (name_key_equal(to, name_entry_key(to_entry))) {
96
	    goto found;
124
	    goto found;
97
	}
125
	}
98
	to_entryp = name_entry_next_ref (to_entry);
126
	to_entryp = name_entry_next_ref(to_entry);
99
    }
127
    }
100
    to_entry   = name_entry_create_place (to);
128
    to_entry   = name_entry_create_place(to);
101
    *to_entryp = to_entry;
129
    *to_entryp = to_entry;
102
  found:
130
  found:
103
    while ((from_entry = *from_entryp) != NIL (NameEntryP)) {
131
    while ((from_entry = *from_entryp) != NIL(NameEntryP)) {
104
	if (name_key_equal (from, name_entry_key (from_entry))) {
132
	if (name_key_equal(from, name_entry_key(from_entry))) {
105
	    name_entry_make_indirect (from_entry, to_entry);
133
	    name_entry_make_indirect(from_entry, to_entry);
106
	    return;
134
	    return;
107
	}
135
	}
108
	from_entryp = name_entry_next_ref (from_entry);
136
	from_entryp = name_entry_next_ref(from_entry);
109
    }
137
    }
110
    from_entry   = name_entry_create_indirect (from, to_entry);
138
    from_entry   = name_entry_create_indirect(from, to_entry);
111
    *from_entryp = from_entry;
139
    *from_entryp = from_entry;
112
}
140
}
113
 
141
 
114
void
142
void
115
name_table_resolve_renames PROTO_N ((table, shape, report))
143
name_table_resolve_renames(NameTableP table,				    NStringP   shape, 
116
			   PROTO_T (NameTableP table X
-
 
117
				    NStringP   shape X
-
 
118
				    BoolT      report)
144
				    BoolT      report)
119
{
145
{
120
    unsigned i;
146
    unsigned i;
121
 
147
 
122
    for (i = 0; i < NAME_TABLE_SIZE; i ++) {
148
    for (i = 0; i < NAME_TABLE_SIZE; i++) {
123
	NameEntryP entry = (table->contents [i]);
149
	NameEntryP entry = (table->contents[i]);
124
 
150
 
125
	while (entry) {
151
	while (entry) {
126
	    (void) name_entry_resolve_renames (entry, shape, report);
152
	   (void)name_entry_resolve_renames(entry, shape, report);
127
	    entry = name_entry_next (entry);
153
	    entry = name_entry_next(entry);
128
	}
154
	}
129
    }
155
    }
130
}
156
}
131
 
157
 
132
NameEntryP
158
NameEntryP
133
name_table_add PROTO_N ((table, key, shape_entry))
159
name_table_add(NameTableP  table,			NameKeyP    key, 
134
	       PROTO_T (NameTableP  table X
-
 
135
			NameKeyP    key X
-
 
136
			ShapeEntryP shape_entry)
160
			ShapeEntryP shape_entry)
137
{
161
{
138
    unsigned    hash_value = (name_key_hash_value (key) % NAME_TABLE_SIZE);
162
    unsigned    hash_value = (name_key_hash_value(key)% NAME_TABLE_SIZE);
139
    NameEntryP *entryp     = &(table->contents [hash_value]);
163
    NameEntryP *entryp     = & (table->contents[hash_value]);
140
    NameEntryP  entry;
164
    NameEntryP  entry;
141
 
165
 
142
    while ((entry = *entryp) != NIL (NameEntryP)) {
166
    while ((entry = *entryp) != NIL(NameEntryP)) {
143
	if (name_key_equal (key, name_entry_key (entry))) {
167
	if (name_key_equal(key, name_entry_key(entry))) {
144
	    if (name_entry_is_indirect (entry)) {
168
	    if (name_entry_is_indirect(entry)) {
145
		entry = name_entry_get_indirect (entry);
169
		entry = name_entry_get_indirect(entry);
146
	    }
170
	    }
147
	    if (name_entry_is_place (entry)) {
171
	    if (name_entry_is_place(entry)) {
148
		name_entry_make_direct (entry, shape_entry);
172
		name_entry_make_direct(entry, shape_entry);
149
	    }
173
	    }
150
	    return (entry);
174
	    return(entry);
151
	}
175
	}
152
	entryp = name_entry_next_ref (entry);
176
	entryp = name_entry_next_ref(entry);
153
    }
177
    }
154
    entry   = name_entry_create_direct (key, shape_entry);
178
    entry   = name_entry_create_direct(key, shape_entry);
155
    *entryp = entry;
179
    *entryp = entry;
156
    return (entry);
180
    return(entry);
157
}
181
}
158
 
182
 
159
NameEntryP
183
NameEntryP
160
name_table_get PROTO_N ((table, key))
184
name_table_get(NameTableP table,			NameKeyP   key)
161
	       PROTO_T (NameTableP table X
-
 
162
			NameKeyP   key)
-
 
163
{
185
{
164
    unsigned   hash_value = (name_key_hash_value (key) % NAME_TABLE_SIZE);
186
    unsigned   hash_value = (name_key_hash_value(key)% NAME_TABLE_SIZE);
165
    NameEntryP entry      = table->contents [hash_value];
187
    NameEntryP entry      = table->contents[hash_value];
166
 
188
 
167
    while (entry) {
189
    while (entry) {
168
	if (name_key_equal (key, name_entry_key (entry))) {
190
	if (name_key_equal(key, name_entry_key(entry))) {
169
	    if (name_entry_is_indirect (entry)) {
191
	    if (name_entry_is_indirect(entry)) {
170
		entry = name_entry_get_indirect (entry);
192
		entry = name_entry_get_indirect(entry);
171
	    }
193
	    }
172
	    if (name_entry_is_place (entry)) {
194
	    if (name_entry_is_place(entry)) {
173
		return (NIL (NameEntryP));
195
		return(NIL(NameEntryP));
174
	    }
196
	    }
175
	    return (entry);
197
	    return(entry);
176
	}
198
	}
177
	entry = name_entry_next (entry);
199
	entry = name_entry_next(entry);
178
    }
200
    }
179
    return (NIL (NameEntryP));
201
    return(NIL(NameEntryP));
180
}
202
}
181
 
203
 
182
void
204
void
183
name_table_iter PROTO_N ((table, proc, closure))
205
name_table_iter(NameTableP table, void(*proc)(NameEntryP, GenericP),
184
		PROTO_T (NameTableP table X
-
 
185
			 void     (*proc) PROTO_S ((NameEntryP, GenericP)) X
-
 
186
			 GenericP   closure)
206
		GenericP closure)
187
{
207
{
188
    unsigned i;
208
    unsigned i;
189
 
209
 
190
    for (i = 0; i < NAME_TABLE_SIZE; i ++) {
210
    for (i = 0; i < NAME_TABLE_SIZE; i++) {
191
	NameEntryP entry = (table->contents [i]);
211
	NameEntryP entry = (table->contents[i]);
192
 
212
 
193
	while (entry) {
213
	while (entry) {
194
	    if (name_entry_is_direct (entry)) {
214
	    if (name_entry_is_direct(entry)) {
195
		(*proc) (entry, closure);
215
		(*proc)(entry, closure);
196
	    }
216
	    }
197
	    entry = name_entry_next (entry);
217
	    entry = name_entry_next(entry);
198
	}
218
	}
199
    }
219
    }
200
}
220
}
201
 
221
 
202
void
222
void
203
name_table_deallocate PROTO_N ((table))
223
name_table_deallocate(NameTableP table)
204
		      PROTO_T (NameTableP table)
-
 
205
{
224
{
206
    unsigned i;
225
    unsigned i;
207
 
226
 
208
    for (i = 0; i < NAME_TABLE_SIZE; i ++) {
227
    for (i = 0; i < NAME_TABLE_SIZE; i++) {
209
	NameEntryP entry = (table->contents [i]);
228
	NameEntryP entry = (table->contents[i]);
210
 
229
 
211
	while (entry) {
230
	while (entry) {
212
	    entry = name_entry_deallocate (entry);
231
	    entry = name_entry_deallocate(entry);
213
	}
232
	}
214
    }
233
    }
215
}
234
}
216

235

217
/*
236
/*