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-2005 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 63... Line 93...
63
/*==========================================================================*\
93
/*==========================================================================*\
64
|| Type tuple handling fuctions.
94
|| Type tuple handling fuctions.
65
\*==========================================================================*/
95
\*==========================================================================*/
66
 
96
 
67
static void
97
static void
68
types_add_name_and_type_1 PROTO_N ((to, name, type, reference, assign))
98
types_add_name_and_type_1(TypeTupleP to, EntryP name, EntryP type,
69
			  PROTO_T (TypeTupleP  to X
-
 
70
				   EntryP      name X
-
 
71
				   EntryP      type X
-
 
72
				   BoolT       reference X
-
 
73
				   BoolT       assign)
99
			  BoolT reference, BoolT assign)
74
{
100
{
75
    TypeTupleEntryP link = ALLOCATE (TypeTupleEntryT);
101
    TypeTupleEntryP link = ALLOCATE(TypeTupleEntryT);
76
 
102
 
77
    link->next      = NIL (TypeTupleEntryP);
103
    link->next      = NIL(TypeTupleEntryP);
78
    link->type      = type;
104
    link->type      = type;
79
    link->name      = name;
105
    link->name      = name;
80
    link->reference = reference;
106
    link->reference = reference;
81
    link->mutated   = FALSE;
107
    link->mutated   = FALSE;
82
    link->assign    = assign;
108
    link->assign    = assign;
83
    *(to->tail)     = link;
109
    *(to->tail)    = link;
84
    to->tail        = &(link->next);
110
    to->tail        = &(link->next);
85
}
111
}
86
 
112
 
87
static void
113
static void
88
types_iter_alt_item_type_names PROTO_N ((alts, proc))
114
types_iter_alt_item_type_names(AltP alts, void(*proc)(NameP))
89
			       PROTO_T (AltP   alts X
-
 
90
					void (*proc) PROTO_S ((NameP)))
-
 
91
{
115
{
92
    AltP            alt;
116
    AltP            alt;
93
    TypeTupleEntryP type;
117
    TypeTupleEntryP type;
94
 
118
 
95
    for (alt = alts; alt; alt = alt_next (alt)) {
119
    for (alt = alts; alt; alt = alt_next(alt)) {
96
	ItemP item;
120
	ItemP item;
97
 
121
 
98
	for (item = alt_item_head (alt); item; item = item_next (item)) {
122
	for (item = alt_item_head(alt); item; item = item_next(item)) {
99
	    TypeTupleP param  = item_param (item);
123
	    TypeTupleP param  = item_param(item);
100
	    TypeTupleP result = item_result (item);
124
	    TypeTupleP result = item_result(item);
101
 
125
 
102
	    for (type = param->head; type; type = type->next) {
126
	    for (type = param->head; type; type = type->next) {
103
		(*proc) (entry_get_name (type->name));
127
		(*proc)(entry_get_name(type->name));
104
	    }
128
	    }
105
	    for (type = result->head; type; type = type->next) {
129
	    for (type = result->head; type; type = type->next) {
106
		(*proc) (entry_get_name (type->name));
130
		(*proc)(entry_get_name(type->name));
107
	    }
131
	    }
108
	}
132
	}
109
    }
133
    }
110
}
134
}
111
 
135
 
112
/*--------------------------------------------------------------------------*/
136
/*--------------------------------------------------------------------------*/
113
 
137
 
114
void
138
void
115
types_init PROTO_N ((tuple))
-
 
116
	   PROTO_T (TypeTupleP tuple)
139
types_init(TypeTupleP tuple)
117
{
140
{
118
    tuple->head = NIL (TypeTupleEntryP);
141
    tuple->head = NIL(TypeTupleEntryP);
119
    tuple->tail = &(tuple->head);
142
    tuple->tail = &(tuple->head);
120
}
143
}
121
 
144
 
122
void
145
void
123
types_copy PROTO_N ((to, from))
146
types_copy(TypeTupleP to, TypeTupleP from)
124
	   PROTO_T (TypeTupleP to X
-
 
125
		    TypeTupleP from)
-
 
126
{
147
{
127
    TypeTupleEntryP from_ptr;
148
    TypeTupleEntryP from_ptr;
128
 
149
 
129
    to->head = NIL (TypeTupleEntryP);
150
    to->head = NIL(TypeTupleEntryP);
130
    to->tail = &(to->head);
151
    to->tail = &(to->head);
131
    for (from_ptr = from->head; from_ptr; from_ptr = from_ptr->next) {
152
    for (from_ptr = from->head; from_ptr; from_ptr = from_ptr->next) {
132
	types_add_name_and_type_1 (to, from_ptr->name, from_ptr->type,
153
	types_add_name_and_type_1(to, from_ptr->name, from_ptr->type,
133
				   from_ptr->reference, from_ptr->assign);
154
				   from_ptr->reference, from_ptr->assign);
134
    }
155
    }
135
}
156
}
136
 
157
 
137
void
158
void
138
types_copy_and_translate PROTO_N ((to, from, translator, table))
159
types_copy_and_translate(TypeTupleP to, TypeTupleP from, TypeTransP translator,
139
			 PROTO_T (TypeTupleP to X
-
 
140
				  TypeTupleP from X
-
 
141
				  TypeTransP translator X
-
 
142
				  TableP     table)
160
			 TableP table)
143
{
161
{
144
    TypeTupleEntryP from_ptr;
162
    TypeTupleEntryP from_ptr;
145
 
163
 
146
    to->head = NIL (TypeTupleEntryP);
164
    to->head = NIL(TypeTupleEntryP);
147
    to->tail = &(to->head);
165
    to->tail = &(to->head);
148
    for (from_ptr = from->head; from_ptr; from_ptr = from_ptr->next) {
166
    for (from_ptr = from->head; from_ptr; from_ptr = from_ptr->next) {
149
	EntryP new_name;
167
	EntryP new_name;
150
 
168
 
151
	new_name = trans_get_translation (translator, from_ptr->name);
169
	new_name = trans_get_translation(translator, from_ptr->name);
152
	if (new_name == NIL (EntryP)) {
170
	if (new_name == NIL(EntryP)) {
153
	    new_name = table_add_generated_name (table);
171
	    new_name = table_add_generated_name(table);
154
	    trans_add_translation (translator, from_ptr->name, new_name);
172
	    trans_add_translation(translator, from_ptr->name, new_name);
155
	}
173
	}
156
	types_add_name_and_type_1 (to, new_name, from_ptr->type,
174
	types_add_name_and_type_1(to, new_name, from_ptr->type,
157
				   from_ptr->reference, from_ptr->assign);
175
				   from_ptr->reference, from_ptr->assign);
158
    }
176
    }
159
}
177
}
160
 
178
 
161
void
179
void
162
types_append_copy PROTO_N ((to, from))
180
types_append_copy(TypeTupleP to, TypeTupleP from)
163
		  PROTO_T (TypeTupleP to X
-
 
164
			   TypeTupleP from)
-
 
165
{
181
{
166
    TypeTupleEntryP from_ptr;
182
    TypeTupleEntryP from_ptr;
167
 
183
 
168
    for (from_ptr = from->head; from_ptr; from_ptr = from_ptr->next) {
184
    for (from_ptr = from->head; from_ptr; from_ptr = from_ptr->next) {
169
	types_add_name_and_type_1 (to, from_ptr->name, from_ptr->type,
185
	types_add_name_and_type_1(to, from_ptr->name, from_ptr->type,
170
				   from_ptr->reference, from_ptr->assign);
186
				   from_ptr->reference, from_ptr->assign);
171
    }
187
    }
172
}
188
}
173
 
189
 
174
void
190
void
175
types_translate PROTO_N ((tuple, translator))
191
types_translate(TypeTupleP tuple, TypeBTransP translator)
176
		PROTO_T (TypeTupleP  tuple X
-
 
177
			 TypeBTransP translator)
-
 
178
{
192
{
179
    TypeTupleEntryP tuple_ptr;
193
    TypeTupleEntryP tuple_ptr;
180
 
194
 
181
    for (tuple_ptr = tuple->head; tuple_ptr; tuple_ptr = tuple_ptr->next) {
195
    for (tuple_ptr = tuple->head; tuple_ptr; tuple_ptr = tuple_ptr->next) {
182
	EntryP new_name;
196
	EntryP new_name;
183
 
197
 
184
	new_name = btrans_get_translation (translator, tuple_ptr->name);
198
	new_name = btrans_get_translation(translator, tuple_ptr->name);
185
	if (new_name != NIL (EntryP)) {
199
	if (new_name != NIL(EntryP)) {
186
	    tuple_ptr->name = new_name;
200
	    tuple_ptr->name = new_name;
187
	}
201
	}
188
    }
202
    }
189
}
203
}
190
 
204
 
191
void
205
void
192
types_renumber PROTO_N ((tuple, translator))
206
types_renumber(TypeTupleP tuple, TypeNTransP translator)
193
	       PROTO_T (TypeTupleP  tuple X
-
 
194
			TypeNTransP translator)
-
 
195
{
207
{
196
    TypeTupleEntryP tuple_ptr;
208
    TypeTupleEntryP tuple_ptr;
197
 
209
 
198
    for (tuple_ptr = tuple->head; tuple_ptr; tuple_ptr = tuple_ptr->next) {
210
    for (tuple_ptr = tuple->head; tuple_ptr; tuple_ptr = tuple_ptr->next) {
199
	if (!entry_is_non_local (tuple_ptr->name)) {
211
	if (!entry_is_non_local(tuple_ptr->name)) {
200
	    tuple_ptr->number = ntrans_get_translation (translator,
212
	    tuple_ptr->number = ntrans_get_translation(translator,
201
							tuple_ptr->name);
213
							tuple_ptr->name);
202
	}
214
	}
203
    }
215
    }
204
}
216
}
205
 
217
 
206
void
218
void
207
types_assign PROTO_N ((to, from))
219
types_assign(TypeTupleP to, TypeTupleP from)
208
	     PROTO_T (TypeTupleP to X
-
 
209
		      TypeTupleP from)
-
 
210
{
220
{
211
    if ((to->head = from->head) != NIL (TypeTupleEntryP)) {
221
    if ((to->head = from->head) != NIL(TypeTupleEntryP)) {
212
	to->tail = from->tail;
222
	to->tail = from->tail;
213
    } else {
223
    } else {
214
	to->tail = &(to->head);
224
	to->tail = &(to->head);
215
    }
225
    }
216
}
226
}
217
 
227
 
218
EntryP
228
EntryP
219
types_find_name_type PROTO_N ((tuple, name, reference_ref))
229
types_find_name_type(TypeTupleP tuple, EntryP name, BoolT *reference_ref)
220
		     PROTO_T (TypeTupleP tuple X
-
 
221
			      EntryP     name X
-
 
222
			      BoolT     *reference_ref)
-
 
223
{
230
{
224
    TypeTupleEntryP type;
231
    TypeTupleEntryP type;
225
 
232
 
226
    for (type = tuple->head; type; type = type->next) {
233
    for (type = tuple->head; type; type = type->next) {
227
	if (type->name == name) {
234
	if (type->name == name) {
228
	    *reference_ref = type->reference;
235
	    *reference_ref = type->reference;
229
	    return (type->type);
236
	    return(type->type);
230
	}
237
	}
231
    }
238
    }
232
    return (NIL (EntryP));
239
    return(NIL(EntryP));
233
}
240
}
234
 
241
 
235
BoolT
242
BoolT
236
types_mutated PROTO_N ((tuple, name))
243
types_mutated(TypeTupleP tuple, EntryP name)
237
	      PROTO_T (TypeTupleP tuple X
-
 
238
		       EntryP     name)
-
 
239
{
244
{
240
    TypeTupleEntryP type;
245
    TypeTupleEntryP type;
241
 
246
 
242
    for (type = tuple->head; type; type = type->next) {
247
    for (type = tuple->head; type; type = type->next) {
243
	if (type->name == name) {
248
	if (type->name == name) {
244
	    type->mutated = TRUE;
249
	    type->mutated = TRUE;
245
	    return (TRUE);
250
	    return(TRUE);
246
	}
251
	}
247
    }
252
    }
248
    return (FALSE);
253
    return(FALSE);
249
}
254
}
250
 
255
 
251
BoolT
256
BoolT
252
types_compute_mutations PROTO_N ((rule, item, action))
257
types_compute_mutations(TypeTupleP rule, TypeTupleP item, TypeTupleP action)
253
			PROTO_T (TypeTupleP rule X
-
 
254
				 TypeTupleP item X
-
 
255
				 TypeTupleP action)
-
 
256
{
258
{
257
    BoolT           propogate  = FALSE;
259
    BoolT           propogate  = FALSE;
258
    TypeTupleEntryP item_ptr   = item->head;
260
    TypeTupleEntryP item_ptr   = item->head;
259
    TypeTupleEntryP action_ptr = action->head;
261
    TypeTupleEntryP action_ptr = action->head;
260
 
262
 
261
    while (action_ptr) {
263
    while (action_ptr) {
262
	ASSERT (item_ptr);
264
	ASSERT(item_ptr);
263
	if (action_ptr->mutated) {
265
	if (action_ptr->mutated) {
264
	    TypeTupleEntryP rule_ptr = rule->head;
266
	    TypeTupleEntryP rule_ptr = rule->head;
265
 
267
 
266
	    while (rule_ptr) {
268
	    while (rule_ptr) {
267
		if ((rule_ptr->name == item_ptr->name) &&
269
		if ((rule_ptr->name == item_ptr->name) &&
268
		    (!(rule_ptr->mutated))) {
270
		   (!(rule_ptr->mutated))) {
269
		    rule_ptr->mutated = TRUE;
271
		    rule_ptr->mutated = TRUE;
270
		    if (rule_ptr->reference) {
272
		    if (rule_ptr->reference) {
271
			propogate = TRUE;
273
			propogate = TRUE;
272
		    }
274
		    }
273
		    break;
275
		    break;
Line 276... Line 278...
276
	    }
278
	    }
277
	}
279
	}
278
	item_ptr   = item_ptr->next;
280
	item_ptr   = item_ptr->next;
279
	action_ptr = action_ptr->next;
281
	action_ptr = action_ptr->next;
280
    }
282
    }
281
    ASSERT (item_ptr == NIL (TypeTupleEntryP));
283
    ASSERT(item_ptr == NIL(TypeTupleEntryP));
282
    return (propogate);
284
    return(propogate);
283
}
285
}
284
 
286
 
285
BoolT
287
BoolT
286
types_compute_assign_mutations PROTO_N ((rule, item))
288
types_compute_assign_mutations(TypeTupleP rule, TypeTupleP item)
287
			       PROTO_T (TypeTupleP rule X
-
 
288
					TypeTupleP item)
-
 
289
{
289
{
290
    BoolT           propogate  = FALSE;
290
    BoolT           propogate  = FALSE;
291
    TypeTupleEntryP item_ptr   = item->head;
291
    TypeTupleEntryP item_ptr   = item->head;
292
 
292
 
293
    while (item_ptr) {
293
    while (item_ptr) {
294
	if (item_ptr->assign) {
294
	if (item_ptr->assign) {
295
	    TypeTupleEntryP rule_ptr = rule->head;
295
	    TypeTupleEntryP rule_ptr = rule->head;
296
 
296
 
297
	    while (rule_ptr) {
297
	    while (rule_ptr) {
298
		if ((rule_ptr->name == item_ptr->name) &&
298
		if ((rule_ptr->name == item_ptr->name) &&
299
		    (!(rule_ptr->mutated))) {
299
		   (!(rule_ptr->mutated))) {
300
		    rule_ptr->mutated = TRUE;
300
		    rule_ptr->mutated = TRUE;
301
		    if (rule_ptr->reference) {
301
		    if (rule_ptr->reference) {
302
			propogate = TRUE;
302
			propogate = TRUE;
303
		    }
303
		    }
304
		    break;
304
		    break;
Line 306... Line 306...
306
		rule_ptr = rule_ptr->next;
306
		rule_ptr = rule_ptr->next;
307
	    }
307
	    }
308
	}
308
	}
309
	item_ptr = item_ptr->next;
309
	item_ptr = item_ptr->next;
310
    }
310
    }
311
    return (propogate);
311
    return(propogate);
312
}
312
}
313
 
313
 
314
void
314
void
315
types_propogate_mutations PROTO_N ((to, from))
315
types_propogate_mutations(TypeTupleP to, TypeTupleP from)
316
			  PROTO_T (TypeTupleP to X
-
 
317
				   TypeTupleP from)
-
 
318
{
316
{
319
    TypeTupleEntryP to_ptr   = to->head;
317
    TypeTupleEntryP to_ptr   = to->head;
320
    TypeTupleEntryP from_ptr = from->head;
318
    TypeTupleEntryP from_ptr = from->head;
321
 
319
 
322
    while (to_ptr) {
320
    while (to_ptr) {
323
	ASSERT (from_ptr);
321
	ASSERT(from_ptr);
324
	to_ptr->mutated = from_ptr->mutated;
322
	to_ptr->mutated = from_ptr->mutated;
325
	to_ptr          = to_ptr->next;
323
	to_ptr          = to_ptr->next;
326
	from_ptr        = from_ptr->next;
324
	from_ptr        = from_ptr->next;
327
    }
325
    }
328
    ASSERT (from_ptr == NIL (TypeTupleEntryP));
326
    ASSERT(from_ptr == NIL(TypeTupleEntryP));
329
}
327
}
330
 
328
 
331
BoolT
329
BoolT
332
types_contains PROTO_N ((tuple, name))
330
types_contains(TypeTupleP tuple, EntryP name)
333
	       PROTO_T (TypeTupleP tuple X
-
 
334
			EntryP     name)
-
 
335
{
331
{
336
    TypeTupleEntryP type;
332
    TypeTupleEntryP type;
337
 
333
 
338
    for (type = tuple->head; type; type = type->next) {
334
    for (type = tuple->head; type; type = type->next) {
339
	if (type->name == name) {
335
	if (type->name == name) {
340
	    return (TRUE);
336
	    return(TRUE);
341
	}
337
	}
342
    }
338
    }
343
    return (FALSE);
339
    return(FALSE);
344
}
340
}
345
 
341
 
346
BoolT
342
BoolT
347
types_contains_names PROTO_N ((tuple))
343
types_contains_names(TypeTupleP tuple)
348
		     PROTO_T (TypeTupleP tuple)
-
 
349
{
344
{
350
    TypeTupleEntryP type;
345
    TypeTupleEntryP type;
351
 
346
 
352
    for (type = tuple->head; type; type = type->next) {
347
    for (type = tuple->head; type; type = type->next) {
353
	if (type->name) {
348
	if (type->name) {
354
	    return (TRUE);
349
	    return(TRUE);
355
	}
350
	}
356
    }
351
    }
357
    return (FALSE);
352
    return(FALSE);
358
}
353
}
359
 
354
 
360
BoolT
355
BoolT
361
types_contains_references PROTO_N ((tuple))
356
types_contains_references(TypeTupleP tuple)
362
			  PROTO_T (TypeTupleP tuple)
-
 
363
{
357
{
364
    TypeTupleEntryP type;
358
    TypeTupleEntryP type;
365
 
359
 
366
    for (type = tuple->head; type; type = type->next) {
360
    for (type = tuple->head; type; type = type->next) {
367
	if (type->reference) {
361
	if (type->reference) {
368
	    return (TRUE);
362
	    return(TRUE);
369
	}
363
	}
370
    }
364
    }
371
    return (FALSE);
365
    return(FALSE);
372
}
366
}
373
 
367
 
374
void
368
void
375
types_make_references PROTO_N ((param, args))
369
types_make_references(TypeTupleP param, TypeTupleP args)
376
		      PROTO_T (TypeTupleP param X
-
 
377
			       TypeTupleP args)
-
 
378
{
370
{
379
    TypeTupleEntryP ptr;
371
    TypeTupleEntryP ptr;
380
 
372
 
381
    for (ptr = param->head; ptr; ptr = ptr->next) {
373
    for (ptr = param->head; ptr; ptr = ptr->next) {
382
	ptr->reference = TRUE;
374
	ptr->reference = TRUE;
Line 385... Line 377...
385
	ptr->reference = TRUE;
377
	ptr->reference = TRUE;
386
    }
378
    }
387
}
379
}
388
 
380
 
389
BoolT
381
BoolT
390
types_intersect PROTO_N ((tuple1, tuple2))
382
types_intersect(TypeTupleP tuple1, TypeTupleP tuple2)
391
		PROTO_T (TypeTupleP tuple1 X
-
 
392
			 TypeTupleP tuple2)
-
 
393
{
383
{
394
    TypeTupleEntryP type;
384
    TypeTupleEntryP type;
395
 
385
 
396
    for (type = tuple1->head; type; type = type->next) {
386
    for (type = tuple1->head; type; type = type->next) {
397
	if (types_contains (tuple2, type->name)) {
387
	if (types_contains(tuple2, type->name)) {
398
	    return (TRUE);
388
	    return(TRUE);
399
	}
389
	}
400
    }
390
    }
401
    return (FALSE);
391
    return(FALSE);
402
}
392
}
403
 
393
 
404
void
394
void
405
types_inplace_intersection PROTO_N ((to, from))
395
types_inplace_intersection(TypeTupleP to, TypeTupleP from)
406
			   PROTO_T (TypeTupleP to X
-
 
407
				    TypeTupleP from)
-
 
408
{
396
{
409
    TypeTupleEntryP type;
397
    TypeTupleEntryP type;
410
 
398
 
411
    to->tail = &(to->head);
399
    to->tail = &(to->head);
412
    while ((type = *(to->tail)) != NIL (TypeTupleEntryP)) {
400
    while ((type = *(to->tail)) != NIL(TypeTupleEntryP)) {
413
	if (!types_contains (from, type->name)) {
401
	if (!types_contains(from, type->name)) {
414
	    *(to->tail) = type->next;
402
	    *(to->tail) = type->next;
415
	    DEALLOCATE (type);
403
	    DEALLOCATE(type);
416
	} else {
404
	} else {
417
	    to->tail = &(type->next);
405
	    to->tail = &(type->next);
418
	}
406
	}
419
    }
407
    }
420
}
408
}
421
 
409
 
422
void
410
void
423
types_compute_intersection PROTO_N ((to, tuple1, tuple2))
411
types_compute_intersection(TypeTupleP to, TypeTupleP tuple1, TypeTupleP tuple2)
424
			   PROTO_T (TypeTupleP to X
-
 
425
				    TypeTupleP tuple1 X
-
 
426
				    TypeTupleP tuple2)
-
 
427
{
412
{
428
    TypeTupleEntryP type;
413
    TypeTupleEntryP type;
429
 
414
 
430
    for (type = tuple1->head; type; type = type->next) {
415
    for (type = tuple1->head; type; type = type->next) {
431
	if ((types_contains (tuple2, type->name)) &&
416
	if ((types_contains(tuple2, type->name)) &&
432
	    (!types_contains (to, type->name))) {
417
	    (!types_contains(to, type->name))) {
433
	    types_add_name_and_type_1 (to, type->name, type->type,
418
	    types_add_name_and_type_1(to, type->name, type->type,
434
				       type->reference, type->assign);
419
				       type->reference, type->assign);
435
	}
420
	}
436
    }
421
    }
437
}
422
}
438
 
423
 
439
CmpT
424
CmpT
440
types_compare PROTO_N ((tuple1, tuple2))
425
types_compare(TypeTupleP tuple1, TypeTupleP tuple2)
441
	      PROTO_T (TypeTupleP tuple1 X
-
 
442
		       TypeTupleP tuple2)
-
 
443
{
426
{
444
    TypeTupleEntryP tuple1_ptr = (tuple1->head);
427
    TypeTupleEntryP tuple1_ptr = (tuple1->head);
445
    TypeTupleEntryP tuple2_ptr = (tuple2->head);
428
    TypeTupleEntryP tuple2_ptr = (tuple2->head);
446
 
429
 
447
    while (tuple1_ptr && tuple2_ptr) {
430
    while (tuple1_ptr && tuple2_ptr) {
448
	if (tuple1_ptr->number < tuple2_ptr->number) {
431
	if (tuple1_ptr->number < tuple2_ptr->number) {
449
	    return (CMP_LT);
432
	    return(CMP_LT);
450
	} else if (tuple1_ptr->number > tuple2_ptr->number) {
433
	} else if (tuple1_ptr->number > tuple2_ptr->number) {
451
	    return (CMP_GT);
434
	    return(CMP_GT);
452
	}
435
	}
453
	switch (key_compare (entry_key (tuple1_ptr->type),
436
	switch (key_compare(entry_key(tuple1_ptr->type),
454
			     entry_key (tuple2_ptr->type))) EXHAUSTIVE {
437
			     entry_key(tuple2_ptr->type)))EXHAUSTIVE {
455
	  case CMP_LT:
438
	  case CMP_LT:
456
	    return (CMP_LT);
439
	    return(CMP_LT);
457
	  case CMP_GT:
440
	  case CMP_GT:
458
	    return (CMP_GT);
441
	    return(CMP_GT);
459
	  case CMP_EQ:
442
	  case CMP_EQ:
460
	    break;
443
	    break;
461
	}
444
	}
462
	if (tuple1_ptr->reference != tuple2_ptr->reference) {
445
	if (tuple1_ptr->reference != tuple2_ptr->reference) {
463
	    return ((CmpT) ((tuple1_ptr->reference) ? CMP_GT : CMP_LT));
446
	    return((CmpT)((tuple1_ptr->reference)? CMP_GT : CMP_LT));
464
	} else if (tuple1_ptr->assign != tuple2_ptr->assign) {
447
	} else if (tuple1_ptr->assign != tuple2_ptr->assign) {
465
	    return ((CmpT) ((tuple1_ptr->assign) ? CMP_GT : CMP_LT));
448
	    return((CmpT)((tuple1_ptr->assign)? CMP_GT : CMP_LT));
466
	}
449
	}
467
	tuple1_ptr = tuple1_ptr->next;
450
	tuple1_ptr = tuple1_ptr->next;
468
	tuple2_ptr = tuple2_ptr->next;
451
	tuple2_ptr = tuple2_ptr->next;
469
    }
452
    }
470
    if (tuple1_ptr != NIL (TypeTupleEntryP)) {
453
    if (tuple1_ptr != NIL(TypeTupleEntryP)) {
471
	return (CMP_GT);
454
	return(CMP_GT);
472
    } else if (tuple2_ptr != NIL (TypeTupleEntryP)) {
455
    } else if (tuple2_ptr != NIL(TypeTupleEntryP)) {
473
	return (CMP_LT);
456
	return(CMP_LT);
474
    } else {
457
    } else {
475
	return (CMP_EQ);
458
	return(CMP_EQ);
476
    }
459
    }
477
}
460
}
478
 
461
 
479
BoolT
462
BoolT
480
types_equal PROTO_N ((tuple1, tuple2))
463
types_equal(TypeTupleP tuple1, TypeTupleP tuple2)
481
	    PROTO_T (TypeTupleP tuple1 X
-
 
482
		     TypeTupleP tuple2)
-
 
483
{
464
{
484
    TypeTupleEntryP tuple1_ptr = (tuple1->head);
465
    TypeTupleEntryP tuple1_ptr = (tuple1->head);
485
    TypeTupleEntryP tuple2_ptr = (tuple2->head);
466
    TypeTupleEntryP tuple2_ptr = (tuple2->head);
486
 
467
 
487
    while ((tuple1_ptr) && (tuple2_ptr)) {
468
    while ((tuple1_ptr) && (tuple2_ptr)) {
488
	if (((tuple1_ptr->type) != (tuple2_ptr->type)) ||
469
	if (((tuple1_ptr->type) != (tuple2_ptr->type)) ||
489
	    ((tuple1_ptr->reference) != (tuple2_ptr->reference)) ||
470
	    ((tuple1_ptr->reference) != (tuple2_ptr->reference)) ||
490
	    ((tuple1_ptr->assign) != (tuple2_ptr->assign))) {
471
	    ((tuple1_ptr->assign) != (tuple2_ptr->assign))) {
491
	    return (FALSE);
472
	    return(FALSE);
492
	}
473
	}
493
	tuple1_ptr = (tuple1_ptr->next);
474
	tuple1_ptr = (tuple1_ptr->next);
494
	tuple2_ptr = (tuple2_ptr->next);
475
	tuple2_ptr = (tuple2_ptr->next);
495
    }
476
    }
496
    return ((tuple1_ptr == NIL (TypeTupleEntryP)) &&
477
    return((tuple1_ptr == NIL(TypeTupleEntryP)) &&
497
	    (tuple2_ptr == NIL (TypeTupleEntryP)));
478
	   (tuple2_ptr == NIL(TypeTupleEntryP)));
498
}
479
}
499
 
480
 
500
#ifdef FS_FAST
481
#ifdef FS_FAST
501
#undef types_equal_zero_tuple
482
#undef types_equal_zero_tuple
502
#endif /* defined (FS_FAST) */
483
#endif /* defined (FS_FAST) */
503
BoolT
484
BoolT
504
types_equal_zero_tuple PROTO_N ((tuple))
485
types_equal_zero_tuple(TypeTupleP tuple)
505
		       PROTO_T (TypeTupleP tuple)
-
 
506
{
486
{
507
    return (tuple->head == NIL (TypeTupleEntryP));
487
    return(tuple->head == NIL(TypeTupleEntryP));
508
}
488
}
509
#ifdef FS_FAST
489
#ifdef FS_FAST
510
#define types_equal_zero_tuple(t) ((t)->head == NIL (TypeTupleEntryP))
490
#define types_equal_zero_tuple(t)	((t)->head == NIL(TypeTupleEntryP))
511
#endif /* defined (FS_FAST) */
491
#endif /* defined (FS_FAST) */
512
 
492
 
513
BoolT
493
BoolT
514
types_equal_names PROTO_N ((tuple1, tuple2))
494
types_equal_names(TypeTupleP tuple1,			   TypeTupleP tuple2)
515
		  PROTO_T (TypeTupleP tuple1 X
-
 
516
			   TypeTupleP tuple2)
-
 
517
{
495
{
518
    TypeTupleEntryP tuple1_ptr = (tuple1->head);
496
    TypeTupleEntryP tuple1_ptr = (tuple1->head);
519
    TypeTupleEntryP tuple2_ptr = (tuple2->head);
497
    TypeTupleEntryP tuple2_ptr = (tuple2->head);
520
 
498
 
521
    while ((tuple1_ptr) && (tuple2_ptr)) {
499
    while ((tuple1_ptr) && (tuple2_ptr)) {
522
	if (((tuple1_ptr->type) != (tuple2_ptr->type)) ||
500
	if (((tuple1_ptr->type) != (tuple2_ptr->type)) ||
523
	    ((tuple1_ptr->reference) != (tuple2_ptr->reference)) ||
501
	    ((tuple1_ptr->reference) != (tuple2_ptr->reference)) ||
524
	    ((tuple1_ptr->assign) != (tuple2_ptr->assign)) ||
502
	    ((tuple1_ptr->assign) != (tuple2_ptr->assign)) ||
525
	    ((tuple1_ptr->name) != (tuple2_ptr->name))) {
503
	    ((tuple1_ptr->name) != (tuple2_ptr->name))) {
526
	    return (FALSE);
504
	    return(FALSE);
527
	}
505
	}
528
	tuple1_ptr = (tuple1_ptr->next);
506
	tuple1_ptr = (tuple1_ptr->next);
529
	tuple2_ptr = (tuple2_ptr->next);
507
	tuple2_ptr = (tuple2_ptr->next);
530
    }
508
    }
531
    return ((tuple1_ptr == NIL (TypeTupleEntryP)) &&
509
    return((tuple1_ptr == NIL(TypeTupleEntryP)) &&
532
	    (tuple2_ptr == NIL (TypeTupleEntryP)));
510
	   (tuple2_ptr == NIL(TypeTupleEntryP)));
533
}
511
}
534
 
512
 
535
BoolT
513
BoolT
536
types_equal_numbers PROTO_N ((tuple1, tuple2))
514
types_equal_numbers(TypeTupleP tuple1, TypeTupleP tuple2)
537
		    PROTO_T (TypeTupleP tuple1 X
-
 
538
			     TypeTupleP tuple2)
-
 
539
{
515
{
540
    TypeTupleEntryP tuple1_ptr = (tuple1->head);
516
    TypeTupleEntryP tuple1_ptr = (tuple1->head);
541
    TypeTupleEntryP tuple2_ptr = (tuple2->head);
517
    TypeTupleEntryP tuple2_ptr = (tuple2->head);
542
 
518
 
543
    while ((tuple1_ptr) && (tuple2_ptr)) {
519
    while ((tuple1_ptr) && (tuple2_ptr)) {
544
	if ((tuple1_ptr->type != tuple2_ptr->type) ||
520
	if ((tuple1_ptr->type != tuple2_ptr->type) ||
545
	    (tuple1_ptr->reference != tuple2_ptr->reference) ||
521
	    (tuple1_ptr->reference != tuple2_ptr->reference) ||
546
	    (tuple1_ptr->assign != tuple2_ptr->assign)) {
522
	    (tuple1_ptr->assign != tuple2_ptr->assign)) {
547
	    return (FALSE);
523
	    return(FALSE);
548
	} else if (entry_is_non_local (tuple1_ptr->name) ||
524
	} else if (entry_is_non_local(tuple1_ptr->name) ||
549
		   entry_is_non_local (tuple2_ptr->name)) {
525
		   entry_is_non_local(tuple2_ptr->name)) {
550
	    if (tuple1_ptr->name != tuple2_ptr->name) {
526
	    if (tuple1_ptr->name != tuple2_ptr->name) {
551
		return (FALSE);
527
		return(FALSE);
552
	    }
528
	    }
553
	} else if (tuple1_ptr->number != tuple2_ptr->number) {
529
	} else if (tuple1_ptr->number != tuple2_ptr->number) {
554
	    return (FALSE);
530
	    return(FALSE);
555
	}
531
	}
556
	tuple1_ptr = (tuple1_ptr->next);
532
	tuple1_ptr = (tuple1_ptr->next);
557
	tuple2_ptr = (tuple2_ptr->next);
533
	tuple2_ptr = (tuple2_ptr->next);
558
    }
534
    }
559
    return ((tuple1_ptr == NIL (TypeTupleEntryP)) &&
535
    return((tuple1_ptr == NIL(TypeTupleEntryP)) &&
560
	    (tuple2_ptr == NIL (TypeTupleEntryP)));
536
	   (tuple2_ptr == NIL(TypeTupleEntryP)));
561
}
537
}
562
 
538
 
563
void
539
void
564
types_add_name_and_type PROTO_N ((to, name, type, reference))
540
types_add_name_and_type(TypeTupleP to, EntryP name, EntryP type,
565
			PROTO_T (TypeTupleP  to X
-
 
566
				 EntryP      name X
-
 
567
				 EntryP      type X
-
 
568
				 BoolT       reference)
541
			BoolT reference)
569
{
542
{
570
    types_add_name_and_type_1 (to, name, type, reference, FALSE);
543
    types_add_name_and_type_1(to, name, type, reference, FALSE);
571
}
544
}
572
 
545
 
573
void
546
void
574
types_add_name_and_type_var PROTO_N ((to, name, type))
547
types_add_name_and_type_var(TypeTupleP to, EntryP name, EntryP type)
575
			    PROTO_T (TypeTupleP  to X
-
 
576
				     EntryP      name X
-
 
577
				     EntryP      type)
-
 
578
{
548
{
579
    types_add_name_and_type_1 (to, name, type, FALSE, TRUE);
549
    types_add_name_and_type_1(to, name, type, FALSE, TRUE);
580
}
550
}
581
 
551
 
582
BoolT
552
BoolT
583
types_add_type PROTO_N ((tuple, table, name, reference))
553
types_add_type(TypeTupleP tuple, TableP table, NStringP name, BoolT reference)
584
	       PROTO_T (TypeTupleP tuple X
-
 
585
			TableP     table X
-
 
586
			NStringP   name X
-
 
587
			BoolT      reference)
-
 
588
{
554
{
589
    EntryP entry = table_get_type (table, name);
555
    EntryP entry = table_get_type(table, name);
590
 
556
 
591
    if (entry) {
557
    if (entry) {
592
	types_add_name_and_type (tuple, NIL (EntryP), entry, reference);
558
	types_add_name_and_type(tuple, NIL(EntryP), entry, reference);
593
	return (TRUE);
559
	return(TRUE);
594
    }
560
    }
595
    return (FALSE);
561
    return(FALSE);
596
}
562
}
597
 
563
 
598
void
564
void
599
types_add_name PROTO_N ((tuple, table, name, reference))
565
types_add_name(TypeTupleP tuple, TableP table, NStringP name, BoolT reference)
600
	       PROTO_T (TypeTupleP tuple X
-
 
601
			TableP     table X
-
 
602
			NStringP   name X
-
 
603
			BoolT      reference)
-
 
604
{
566
{
605
    EntryP entry = table_add_name (table, name);
567
    EntryP entry = table_add_name(table, name);
606
 
568
 
607
    types_add_name_and_type (tuple, entry, NIL (EntryP), reference);
569
    types_add_name_and_type(tuple, entry, NIL(EntryP), reference);
608
}
570
}
609
 
571
 
610
BoolT
572
BoolT
611
types_add_typed_name PROTO_N ((tuple, table, name, type, reference))
573
types_add_typed_name(TypeTupleP tuple, TableP table, NStringP name,
612
		     PROTO_T (TypeTupleP tuple X
-
 
613
			      TableP     table X
-
 
614
			      NStringP   name X
-
 
615
			      NStringP   type X
-
 
616
			      BoolT      reference)
574
		     NStringP type, BoolT reference)
617
{
575
{
618
    EntryP type_entry = table_get_type (table, type);
576
    EntryP type_entry = table_get_type(table, type);
619
    EntryP name_entry = table_add_name (table, name);
577
    EntryP name_entry = table_add_name(table, name);
620
 
578
 
621
    if (type_entry) {
579
    if (type_entry) {
622
	types_add_name_and_type (tuple, name_entry, type_entry, reference);
580
	types_add_name_and_type(tuple, name_entry, type_entry, reference);
623
	return (TRUE);
581
	return(TRUE);
624
    }
582
    }
625
    return (FALSE);
583
    return(FALSE);
626
}
584
}
627
 
585
 
628
void
586
void
629
types_add_name_entry PROTO_N ((tuple, entry))
587
types_add_name_entry(TypeTupleP tuple, EntryP entry)
630
		     PROTO_T (TypeTupleP tuple X
-
 
631
			      EntryP     entry)
-
 
632
{
588
{
633
    types_add_name_and_type (tuple, entry, NIL (EntryP), FALSE);
589
    types_add_name_and_type(tuple, entry, NIL(EntryP), FALSE);
634
}
590
}
635
 
591
 
636
void
592
void
637
types_add_type_entry PROTO_N ((tuple, entry, reference))
593
types_add_type_entry(TypeTupleP tuple, EntryP entry, BoolT reference)
638
		     PROTO_T (TypeTupleP tuple X
-
 
639
			      EntryP     entry X
-
 
640
			      BoolT      reference)
-
 
641
{
594
{
642
    types_add_name_and_type (tuple, NIL (EntryP), entry, reference);
595
    types_add_name_and_type(tuple, NIL(EntryP), entry, reference);
643
}
596
}
644
 
597
 
645
void
598
void
646
types_add_new_names PROTO_N ((to, from, exclude))
599
types_add_new_names(TypeTupleP to, TypeTupleP from, EntryP exclude)
647
		    PROTO_T (TypeTupleP to X
-
 
648
			     TypeTupleP from X
-
 
649
			     EntryP     exclude)
-
 
650
{
600
{
651
    TypeTupleEntryP from_ptr;
601
    TypeTupleEntryP from_ptr;
652
 
602
 
653
    for (from_ptr = from->head; from_ptr; from_ptr = from_ptr->next) {
603
    for (from_ptr = from->head; from_ptr; from_ptr = from_ptr->next) {
654
	if ((from_ptr->name != exclude) &&
604
	if ((from_ptr->name != exclude) &&
655
	    (!(from_ptr->assign)) &&
605
	    (!(from_ptr->assign)) &&
656
	    (!types_contains (to, from_ptr->name))) {
606
	    (!types_contains(to, from_ptr->name))) {
657
	    types_add_name_and_type (to, from_ptr->name, from_ptr->type,
607
	    types_add_name_and_type(to, from_ptr->name, from_ptr->type,
658
				     from_ptr->reference);
608
				     from_ptr->reference);
659
	}
609
	}
660
    }
610
    }
661
}
611
}
662
 
612
 
663
BoolT
613
BoolT
664
types_disjoint_names PROTO_N ((tuple))
614
types_disjoint_names(TypeTupleP tuple)
665
		     PROTO_T (TypeTupleP tuple)
-
 
666
{
615
{
667
    BoolT           disjoint = TRUE;
616
    BoolT           disjoint = TRUE;
668
    TypeTupleEntryP ptr;
617
    TypeTupleEntryP ptr;
669
 
618
 
670
    for (ptr = tuple->head; ptr; ptr = ptr->next) {
619
    for (ptr = tuple->head; ptr; ptr = ptr->next) {
671
	if (ptr->name) {
620
	if (ptr->name) {
672
	    if (name_test_and_set_clash (entry_get_name (ptr->name))) {
621
	    if (name_test_and_set_clash(entry_get_name(ptr->name))) {
673
		disjoint = FALSE;
622
		disjoint = FALSE;
674
		goto done;
623
		goto done;
675
	    }
624
	    }
676
	} else {
625
	} else {
677
	    disjoint = FALSE;
626
	    disjoint = FALSE;
Line 679... Line 628...
679
	}
628
	}
680
    }
629
    }
681
  done:
630
  done:
682
    for (ptr = tuple->head; ptr; ptr = ptr->next) {
631
    for (ptr = tuple->head; ptr; ptr = ptr->next) {
683
	if (ptr->name) {
632
	if (ptr->name) {
684
	    name_reset_clash (entry_get_name (ptr->name));
633
	    name_reset_clash(entry_get_name(ptr->name));
685
	}
634
	}
686
    }
635
    }
687
    return (disjoint);
636
    return(disjoint);
688
}
637
}
689
 
638
 
690
BoolT
639
BoolT
691
types_resolve PROTO_N ((to, args, locals, unknown_proc, rule, alt))
640
types_resolve(TypeTupleP to, TypeTupleP args, TypeTupleP locals,
692
	      PROTO_T (TypeTupleP to X
-
 
693
		       TypeTupleP args X
-
 
694
		       TypeTupleP locals X
-
 
695
		       void     (*unknown_proc) PROTO_S ((KeyP, KeyP,
641
	      void (*unknown_proc)(KeyP, KeyP, unsigned), KeyP rule,
696
							  unsigned)) X
-
 
697
		       KeyP       rule X
-
 
698
		       unsigned   alt)
642
	      unsigned alt)
699
{
643
{
700
    BoolT           ok = TRUE;
644
    BoolT           ok = TRUE;
701
    TypeTupleEntryP name;
645
    TypeTupleEntryP name;
702
 
646
 
703
    for (name = to->head; name; name = name->next) {
647
    for (name = to->head; name; name = name->next) {
704
	BoolT reference;
648
	BoolT reference;
705
 
649
 
706
	if (entry_is_non_local (name->name)) {
650
	if (entry_is_non_local(name->name)) {
707
	    name->type = entry_get_non_local (name->name);
651
	    name->type = entry_get_non_local(name->name);
708
	} else if (((name->type = types_find_name_type (args, name->name,
652
	} else if (((name->type = types_find_name_type(args, name->name,
709
							&reference)) ==
653
						       &reference)) ==
710
		    NIL (EntryP)) &&
654
		    NIL(EntryP)) &&
711
		   ((name->type = types_find_name_type (locals, name->name,
655
		   ((name->type = types_find_name_type(locals, name->name,
712
							&reference)) ==
656
						       &reference)) ==
713
		    NIL (EntryP))) {
657
		    NIL(EntryP))) {
714
	    (*unknown_proc) (entry_key (name->name), rule, alt);
658
	   (*unknown_proc)(entry_key(name->name), rule, alt);
715
	    ok = FALSE;
659
	    ok = FALSE;
716
	}
660
	}
717
    }
661
    }
718
    return (ok);
662
    return(ok);
719
}
663
}
720
 
664
 
721
BoolT
665
BoolT
722
types_check_undefined PROTO_N ((to, args, locals, error_proc, rule, alt))
666
types_check_undefined(TypeTupleP to, TypeTupleP args, TypeTupleP locals,
723
		      PROTO_T (TypeTupleP to X
-
 
724
			       TypeTupleP args X
-
 
725
			       TypeTupleP locals X
-
 
726
			       void     (*error_proc) PROTO_S ((KeyP, KeyP,
667
		      void (*error_proc)(KeyP, KeyP, unsigned), KeyP rule,
727
								unsigned)) X
-
 
728
			       KeyP       rule X
-
 
729
			       unsigned   alt)
668
		      unsigned alt)
730
{
669
{
731
    BoolT           ok = TRUE;
670
    BoolT           ok = TRUE;
732
    TypeTupleEntryP name;
671
    TypeTupleEntryP name;
733
 
672
 
734
    for (name = to->head; name; name = name->next) {
673
    for (name = to->head; name; name = name->next) {
735
	if ((!(name->assign)) &&
674
	if ((!(name->assign)) &&
736
	    (entry_is_non_local (name->name) ||
675
	   (entry_is_non_local(name->name) ||
737
	     types_contains (args, name->name) ||
676
	    types_contains(args, name->name) ||
738
	     types_contains (locals, name->name))) {
677
	    types_contains(locals, name->name))) {
739
	    (*error_proc) (entry_key (name->name), rule, alt);
678
	   (*error_proc)(entry_key(name->name), rule, alt);
740
	    ok = FALSE;
679
	    ok = FALSE;
741
	}
680
	}
742
    }
681
    }
743
    return (ok);
682
    return(ok);
744
}
683
}
745
 
684
 
746
BoolT
685
BoolT
747
types_fillin_types PROTO_N ((to, from))
686
types_fillin_types(TypeTupleP to, TypeTupleP from)
748
		   PROTO_T (TypeTupleP to X
-
 
749
			    TypeTupleP from)
-
 
750
{
687
{
751
    TypeTupleEntryP to_ptr   = to->head;
688
    TypeTupleEntryP to_ptr   = to->head;
752
    TypeTupleEntryP from_ptr = from->head;
689
    TypeTupleEntryP from_ptr = from->head;
753
 
690
 
754
    while ((to_ptr) && (from_ptr)) {
691
    while ((to_ptr) && (from_ptr)) {
755
	if (to_ptr->type == NIL (EntryP)) {
692
	if (to_ptr->type == NIL(EntryP)) {
756
	    to_ptr->type      = from_ptr->type;
693
	    to_ptr->type      = from_ptr->type;
757
	    to_ptr->reference = from_ptr->reference;
694
	    to_ptr->reference = from_ptr->reference;
758
	} else if ((to_ptr->type != from_ptr->type) ||
695
	} else if ((to_ptr->type != from_ptr->type) ||
759
		   (to_ptr->reference != from_ptr->reference)) {
696
		   (to_ptr->reference != from_ptr->reference)) {
760
	    return (FALSE);
697
	    return(FALSE);
761
	}
698
	}
762
	to_ptr   = to_ptr->next;
699
	to_ptr   = to_ptr->next;
763
	from_ptr = from_ptr->next;
700
	from_ptr = from_ptr->next;
764
    }
701
    }
765
    return ((to_ptr == NIL (TypeTupleEntryP)) &&
702
    return((to_ptr == NIL(TypeTupleEntryP)) &&
766
	    (from_ptr == NIL (TypeTupleEntryP)));
703
	   (from_ptr == NIL(TypeTupleEntryP)));
767
}
704
}
768
 
705
 
769
BoolT
706
BoolT
770
types_fillin_names PROTO_N ((to, from))
707
types_fillin_names(TypeTupleP to, TypeTupleP from)
771
		   PROTO_T (TypeTupleP to X
-
 
772
			    TypeTupleP from)
-
 
773
{
708
{
774
    TypeTupleEntryP to_ptr   = to->head;
709
    TypeTupleEntryP to_ptr   = to->head;
775
    TypeTupleEntryP from_ptr = from->head;
710
    TypeTupleEntryP from_ptr = from->head;
776
 
711
 
777
    while ((to_ptr) && (from_ptr)) {
712
    while ((to_ptr) && (from_ptr)) {
778
	ASSERT (to_ptr->name == NIL (EntryP));
713
	ASSERT(to_ptr->name == NIL(EntryP));
779
	to_ptr->name = from_ptr->name;
714
	to_ptr->name = from_ptr->name;
780
	if ((from_ptr->type) &&
715
	if ((from_ptr->type) &&
781
	    ((to_ptr->type != from_ptr->type) ||
716
	    ((to_ptr->type != from_ptr->type) ||
782
	     (to_ptr->reference != from_ptr->reference))) {
717
	     (to_ptr->reference != from_ptr->reference))) {
783
	    return (FALSE);
718
	    return(FALSE);
784
	}
719
	}
785
	to_ptr   = to_ptr->next;
720
	to_ptr   = to_ptr->next;
786
	from_ptr = from_ptr->next;
721
	from_ptr = from_ptr->next;
787
    }
722
    }
788
    return ((to_ptr == NIL (TypeTupleEntryP)) &&
723
    return((to_ptr == NIL(TypeTupleEntryP)) &&
789
	    (from_ptr == NIL (TypeTupleEntryP)));
724
	   (from_ptr == NIL(TypeTupleEntryP)));
790
}
725
}
791
 
726
 
792
BoolT
727
BoolT
793
types_check_names PROTO_N ((to, from))
728
types_check_names(TypeTupleP to, TypeTupleP from)
794
		  PROTO_T (TypeTupleP to X
-
 
795
			   TypeTupleP from)
-
 
796
{
729
{
797
    TypeTupleEntryP to_ptr;
730
    TypeTupleEntryP to_ptr;
798
 
731
 
799
    for (to_ptr = to->head; to_ptr; to_ptr = to_ptr->next) {
732
    for (to_ptr = to->head; to_ptr; to_ptr = to_ptr->next) {
800
	BoolT reference;
733
	BoolT reference;
801
 
734
 
802
	if ((types_find_name_type (from, to_ptr->name, &reference) !=
735
	if ((types_find_name_type(from, to_ptr->name, &reference) !=
803
	     to_ptr->type) ||
-
 
804
	    (reference != to_ptr->reference)) {
736
	     to_ptr->type) || (reference != to_ptr->reference)) {
805
	    return (FALSE);
737
	    return(FALSE);
806
	}
738
	}
807
    }
739
    }
808
    return (TRUE);
740
    return(TRUE);
809
}
741
}
810
 
742
 
811
void
743
void
812
types_check_used PROTO_N ((tuple, error_proc, gclosure))
744
types_check_used(TypeTupleP tuple, void (*error_proc)(GenericP, EntryP),
813
		 PROTO_T (TypeTupleP tuple X
-
 
814
			  void     (*error_proc) PROTO_S ((GenericP, EntryP)) X
-
 
815
			  GenericP   gclosure)
745
		 GenericP gclosure)
816
{
746
{
817
    TypeTupleEntryP ptr;
747
    TypeTupleEntryP ptr;
818
 
748
 
819
    for (ptr = tuple->head; ptr; ptr = ptr->next) {
749
    for (ptr = tuple->head; ptr; ptr = ptr->next) {
820
	ASSERT (!entry_is_non_local (ptr->name));
750
	ASSERT(!entry_is_non_local(ptr->name));
821
	if (!name_is_used (entry_get_name (ptr->name))) {
751
	if (!name_is_used(entry_get_name(ptr->name))) {
822
	    (*error_proc) (gclosure, ptr->name);
752
	   (*error_proc)(gclosure, ptr->name);
823
	}
753
	}
824
    }
754
    }
825
}
755
}
826
 
756
 
827
void
757
void
828
types_unlink_used PROTO_N ((to, from))
758
types_unlink_used(TypeTupleP to, TypeTupleP from)
829
		  PROTO_T (TypeTupleP to X
-
 
830
			   TypeTupleP from)
-
 
831
{
759
{
832
    TypeTupleEntryP type;
760
    TypeTupleEntryP type;
833
 
761
 
834
    to->tail = &(to->head);
762
    to->tail = &(to->head);
835
    while ((type = *(to->tail)) != NIL (TypeTupleEntryP)) {
763
    while ((type = *(to->tail)) != NIL(TypeTupleEntryP)) {
836
	if (types_contains (from, type->name)) {
764
	if (types_contains(from, type->name)) {
837
	    *(to->tail) = type->next;
765
	    *(to->tail) = type->next;
838
	    DEALLOCATE (type);
766
	    DEALLOCATE(type);
839
	} else {
767
	} else {
840
	    to->tail = &(type->next);
768
	    to->tail = &(type->next);
841
	}
769
	}
842
    }
770
    }
843
}
771
}
844
 
772
 
845
void
773
void
846
types_unlink_unused PROTO_N ((tuple, alts))
774
types_unlink_unused(TypeTupleP tuple, AltP alts)
847
		    PROTO_T (TypeTupleP tuple X
-
 
848
			     AltP       alts)
-
 
849
{
775
{
850
    TypeTupleEntryP type;
776
    TypeTupleEntryP type;
851
 
777
 
852
    types_iter_alt_item_type_names (alts, name_used);
778
    types_iter_alt_item_type_names(alts, name_used);
853
    tuple->tail = &(tuple->head);
779
    tuple->tail = &(tuple->head);
854
    while ((type = *(tuple->tail)) != NIL (TypeTupleEntryP)) {
780
    while ((type = *(tuple->tail)) != NIL(TypeTupleEntryP)) {
855
	ASSERT (!entry_is_non_local (type->name));
781
	ASSERT(!entry_is_non_local(type->name));
856
	if (name_is_used (entry_get_name (type->name))) {
782
	if (name_is_used(entry_get_name(type->name))) {
857
	    tuple->tail = &(type->next);
783
	    tuple->tail = &(type->next);
858
	} else {
784
	} else {
859
	    *(tuple->tail) = type->next;
785
	    *(tuple->tail) = type->next;
860
	    DEALLOCATE (type);
786
	    DEALLOCATE(type);
861
	}
787
	}
862
    }
788
    }
863
    types_iter_alt_item_type_names (alts, name_not_used);
789
    types_iter_alt_item_type_names(alts, name_not_used);
864
}
790
}
865
 
791
 
866
void
792
void
867
types_compute_formal_renaming PROTO_N ((names, translator))
793
types_compute_formal_renaming(TypeTupleP names, TypeRTransP translator)
868
			      PROTO_T (TypeTupleP  names X
-
 
869
				       TypeRTransP translator)
-
 
870
{
794
{
871
    TypeTupleEntryP ptr;
795
    TypeTupleEntryP ptr;
872
 
796
 
873
    for (ptr = names->head; ptr; ptr = ptr->next) {
797
    for (ptr = names->head; ptr; ptr = ptr->next) {
874
	rtrans_add_translation (translator, ptr->name, ptr->name, ptr->type,
798
	rtrans_add_translation(translator, ptr->name, ptr->name, ptr->type,
875
				ptr->reference);
799
				ptr->reference);
876
    }
800
    }
877
}
801
}
878
 
802
 
879
void
803
void
880
types_compute_formal_inlining PROTO_N ((names, renames, translator, state))
804
types_compute_formal_inlining(TypeTupleP names, TypeTupleP renames,
881
			      PROTO_T (TypeTupleP  names X
-
 
882
				       TypeTupleP  renames X
-
 
883
				       TypeRTransP translator X
805
			      TypeRTransP translator, SaveRStackP state)
884
				       SaveRStackP state)
-
 
885
{
806
{
886
    TypeTupleEntryP ptr   = names->head;
807
    TypeTupleEntryP ptr   = names->head;
887
    TypeTupleEntryP reptr = renames->head;
808
    TypeTupleEntryP reptr = renames->head;
888
 
809
 
889
    while (ptr) {
810
    while (ptr) {
890
	EntryP entry;
811
	EntryP entry;
891
	EntryP type;
812
	EntryP type;
892
	BoolT  reference;
813
	BoolT  reference;
893
 
814
 
894
	ASSERT (reptr);
815
	ASSERT(reptr);
895
	entry = rstack_get_translation (state, reptr->name, &type, &reference);
816
	entry = rstack_get_translation(state, reptr->name, &type, &reference);
896
	ASSERT (entry);
817
	ASSERT(entry);
897
	rtrans_add_translation (translator, ptr->name, entry, type, reference);
818
	rtrans_add_translation(translator, ptr->name, entry, type, reference);
898
	ptr   = ptr->next;
819
	ptr   = ptr->next;
899
	reptr = reptr->next;
820
	reptr = reptr->next;
900
    }
821
    }
901
    ASSERT (reptr == NIL (TypeTupleEntryP));
822
    ASSERT(reptr == NIL(TypeTupleEntryP));
902
}
823
}
903
 
824
 
904
void
825
void
905
types_compute_local_renaming PROTO_N ((names, exclude, translator, state,
826
types_compute_local_renaming(TypeTupleP names, TypeTupleP exclude,
906
				       table))
-
 
907
			     PROTO_T (TypeTupleP  names X
-
 
908
				      TypeTupleP  exclude X
-
 
909
				      TypeRTransP translator X
827
			     TypeRTransP translator, SaveRStackP state,
910
				      SaveRStackP state X
-
 
911
				      TableP      table)
828
			     TableP table)
912
{
829
{
913
    TypeTupleEntryP ptr;
830
    TypeTupleEntryP ptr;
914
 
831
 
915
    for (ptr = names->head; ptr; ptr = ptr->next) {
832
    for (ptr = names->head; ptr; ptr = ptr->next) {
916
	if (!types_contains (exclude, ptr->name)) {
833
	if (!types_contains(exclude, ptr->name)) {
917
	    EntryP type;
834
	    EntryP type;
918
	    BoolT  reference;
835
	    BoolT  reference;
919
 
836
 
920
	    if (rstack_get_translation (state, ptr->name, &type,
837
	    if (rstack_get_translation(state, ptr->name, &type,
921
					&reference) != NIL (EntryP)) {
838
				       &reference) != NIL(EntryP)) {
922
		EntryP entry = table_add_generated_name (table);
839
		EntryP entry = table_add_generated_name(table);
923
 
840
 
924
		rtrans_add_translation (translator, ptr->name, entry,
841
		rtrans_add_translation(translator, ptr->name, entry,
925
					ptr->type, ptr->reference);
842
				       ptr->type, ptr->reference);
926
	    } else {
843
	    } else {
927
		rtrans_add_translation (translator, ptr->name, ptr->name,
844
		rtrans_add_translation(translator, ptr->name, ptr->name,
928
					ptr->type, ptr->reference);
845
				       ptr->type, ptr->reference);
929
	    }
846
	    }
930
	}
847
	}
931
    }
848
    }
932
}
849
}
933
 
850
 
934
void
851
void
935
types_compute_param_from_trans PROTO_N ((new_param, from_translator,
852
types_compute_param_from_trans(TypeTupleP new_param,
936
					 to_translator, old_param))
-
 
937
			       PROTO_T (TypeTupleP  new_param X
-
 
938
					TypeNTransP from_translator X
853
			       TypeNTransP from_translator,
939
					TypeNTransP to_translator X
854
			       TypeNTransP to_translator, TypeTupleP old_param)
940
					TypeTupleP  old_param)
-
 
941
{
855
{
942
    TypeTupleEntryP ptr;
856
    TypeTupleEntryP ptr;
943
 
857
 
944
    types_init (new_param);
858
    types_init(new_param);
945
    for (ptr = old_param->head; ptr; ptr = ptr->next) {
859
    for (ptr = old_param->head; ptr; ptr = ptr->next) {
946
	EntryP entry = ntrans_get_indirect_translation (from_translator,
860
	EntryP entry = ntrans_get_indirect_translation(from_translator,
947
							to_translator,
861
						       to_translator,
948
							ptr->name);
862
						       ptr->name);
949
 
863
 
950
	if (entry) {
864
	if (entry) {
951
	    types_add_name_and_type (new_param, entry, ptr->type,
865
	    types_add_name_and_type(new_param, entry, ptr->type,
952
				     ptr->reference);
866
				    ptr->reference);
953
	}
867
	}
954
    }
868
    }
955
}
869
}
956
 
870
 
957
BoolT
871
BoolT
958
types_check_shadowing PROTO_N ((tuple, stack, rule))
872
types_check_shadowing(TypeTupleP tuple, ScopeStackP stack, RuleP rule)
959
		      PROTO_T (TypeTupleP  tuple X
-
 
960
			       ScopeStackP stack X
-
 
961
			       RuleP       rule)
-
 
962
{
873
{
963
    BoolT           errored = FALSE;
874
    BoolT           errored = FALSE;
964
    TypeTupleEntryP ptr;
875
    TypeTupleEntryP ptr;
965
 
876
 
966
    for (ptr = tuple->head; ptr; ptr = ptr->next) {
877
    for (ptr = tuple->head; ptr; ptr = ptr->next) {
967
	if (scope_stack_check_shadowing (stack, ptr->name, rule)) {
878
	if (scope_stack_check_shadowing(stack, ptr->name, rule)) {
968
	    errored = TRUE;
879
	    errored = TRUE;
969
	}
880
	}
970
    }
881
    }
971
    return (errored);
882
    return(errored);
972
}
883
}
973
 
884
 
974
void
885
void
975
types_iter_for_table PROTO_N ((tuple, proc, closure))
886
types_iter_for_table(TypeTupleP tuple, void (*proc)(EntryP, GenericP),
976
		     PROTO_T (TypeTupleP tuple X
-
 
977
			      void     (*proc) PROTO_S ((EntryP, GenericP)) X
-
 
978
			      GenericP   closure)
887
		     GenericP closure)
979
{
888
{
980
    TypeTupleEntryP ptr;
889
    TypeTupleEntryP ptr;
981
 
890
 
982
    for (ptr = tuple->head; ptr; ptr = ptr->next) {
891
    for (ptr = tuple->head; ptr; ptr = ptr->next) {
983
	if (ptr->type) {
892
	if (ptr->type) {
984
	    entry_iter (ptr->type, TRUE, proc, closure);
893
	    entry_iter(ptr->type, TRUE, proc, closure);
985
	}
894
	}
986
	if (ptr->name) {
895
	if (ptr->name) {
987
	    entry_iter (ptr->name, TRUE, proc, closure);
896
	    entry_iter(ptr->name, TRUE, proc, closure);
988
	}
897
	}
989
    }
898
    }
990
}
899
}
991
 
900
 
992
void
901
void
993
types_destroy PROTO_N ((tuple))
902
types_destroy(TypeTupleP tuple)
994
	      PROTO_T (TypeTupleP tuple)
-
 
995
{
903
{
996
    TypeTupleEntryP tuple_ptr = (tuple->head);
904
    TypeTupleEntryP tuple_ptr = (tuple->head);
997
 
905
 
998
    while (tuple_ptr) {
906
    while (tuple_ptr) {
999
	TypeTupleEntryP tmp_ptr = (tuple_ptr->next);
907
	TypeTupleEntryP tmp_ptr = (tuple_ptr->next);
1000
 
908
 
1001
	DEALLOCATE (tuple_ptr);
909
	DEALLOCATE(tuple_ptr);
1002
	tuple_ptr = tmp_ptr;
910
	tuple_ptr = tmp_ptr;
1003
    }
911
    }
1004
}
912
}
1005
 
913
 
1006
void
914
void
1007
write_type_types PROTO_N ((ostream, tuple))
915
write_type_types(OStreamP ostream, TypeTupleP tuple)
1008
		 PROTO_T (OStreamP   ostream X
-
 
1009
			  TypeTupleP tuple)
-
 
1010
{
916
{
1011
    TypeTupleEntryP type;
917
    TypeTupleEntryP type;
1012
 
918
 
1013
    write_char (ostream, '(');
919
    write_char(ostream, '(');
1014
    for (type = tuple->head; type; type = type->next) {
920
    for (type = tuple->head; type; type = type->next) {
1015
	if (type->type) {
921
	if (type->type) {
1016
	    write_cstring (ostream, ": ");
922
	    write_cstring(ostream, ": ");
1017
	    write_key (ostream, entry_key (type->type));
923
	    write_key(ostream, entry_key(type->type));
1018
	    if (type->reference) {
924
	    if (type->reference) {
1019
		write_cstring (ostream, " &");
925
		write_cstring(ostream, " &");
1020
	    }
926
	    }
1021
	} else {
927
	} else {
1022
	    write_cstring (ostream, ": <unknown>");
928
	    write_cstring(ostream, ": <unknown>");
1023
	}
929
	}
1024
	if (type->next) {
930
	if (type->next) {
1025
	    write_cstring (ostream, ", ");
931
	    write_cstring(ostream, ", ");
1026
	}
932
	}
1027
    }
933
    }
1028
    write_char (ostream, ')');
934
    write_char(ostream, ')');
1029
}
935
}
1030
 
936
 
1031
void
937
void
1032
write_type_names PROTO_N ((ostream, tuple, call))
938
write_type_names(OStreamP ostream, TypeTupleP tuple, BoolT call)
1033
		 PROTO_T (OStreamP   ostream X
-
 
1034
			  TypeTupleP tuple X
-
 
1035
			  BoolT      call)
-
 
1036
{
939
{
1037
    TypeTupleEntryP type;
940
    TypeTupleEntryP type;
1038
 
941
 
1039
    write_char (ostream, '(');
942
    write_char(ostream, '(');
1040
    for (type = tuple->head; type; type = type->next) {
943
    for (type = tuple->head; type; type = type->next) {
1041
	if (type->name) {
944
	if (type->name) {
1042
	    if ((call && type->reference) || (type->assign)) {
945
	    if ((call && type->reference) || (type->assign)) {
1043
		write_char (ostream, '&');
946
		write_char(ostream, '&');
1044
	    }
947
	    }
1045
	    write_key (ostream, entry_key (type->name));
948
	    write_key(ostream, entry_key(type->name));
1046
	}
949
	}
1047
	if (type->type) {
950
	if (type->type) {
1048
	    write_cstring (ostream, ": ");
951
	    write_cstring(ostream, ": ");
1049
	    write_key (ostream, entry_key (type->type));
952
	    write_key(ostream, entry_key(type->type));
1050
	    if (type->reference) {
953
	    if (type->reference) {
1051
		write_cstring (ostream, " &");
954
		write_cstring(ostream, " &");
1052
	    }
955
	    }
1053
	}
956
	}
1054
	if (type->next) {
957
	if (type->next) {
1055
	    write_cstring (ostream, ", ");
958
	    write_cstring(ostream, ", ");
1056
	}
959
	}
1057
    }
960
    }
1058
    write_char (ostream, ')');
961
    write_char(ostream, ')');
1059
}
962
}
1060
 
963
 
1061
/*==========================================================================*\
964
/*==========================================================================*\
1062
|| Basic name translator handling functions.
965
|| Basic name translator handling functions.
1063
\*==========================================================================*/
966
\*==========================================================================*/
1064
 
967
 
1065
void
968
void
1066
btrans_init PROTO_N ((translator))
-
 
1067
	    PROTO_T (TypeBTransP translator)
969
btrans_init(TypeBTransP translator)
1068
{
970
{
1069
    translator->head = NIL (TransP);
971
    translator->head = NIL(TransP);
1070
    translator->tail = &(translator->head);
972
    translator->tail = &(translator->head);
1071
}
973
}
1072
 
974
 
1073
void
975
void
1074
btrans_add_translations PROTO_N ((translator, from, to))
976
btrans_add_translations(TypeBTransP translator, TypeTupleP from, TypeTupleP to)
1075
			PROTO_T (TypeBTransP translator X
-
 
1076
				 TypeTupleP  from X
-
 
1077
				 TypeTupleP  to)
-
 
1078
{
977
{
1079
    TypeTupleEntryP from_ptr = from->head;
978
    TypeTupleEntryP from_ptr = from->head;
1080
    TypeTupleEntryP to_ptr   = to->head;
979
    TypeTupleEntryP to_ptr   = to->head;
1081
 
980
 
1082
    while (from_ptr) {
981
    while (from_ptr) {
1083
	ASSERT (to_ptr != NIL (TypeTupleEntryP));
982
	ASSERT(to_ptr != NIL(TypeTupleEntryP));
1084
	btrans_add_translation (translator, from_ptr->name, to_ptr->name);
983
	btrans_add_translation(translator, from_ptr->name, to_ptr->name);
1085
	from_ptr = from_ptr->next;
984
	from_ptr = from_ptr->next;
1086
	to_ptr   = to_ptr->next;
985
	to_ptr   = to_ptr->next;
1087
    }
986
    }
1088
    ASSERT (to_ptr == NIL (TypeTupleEntryP));
987
    ASSERT(to_ptr == NIL(TypeTupleEntryP));
1089
}
988
}
1090
 
989
 
1091
void
990
void
1092
btrans_add_translation PROTO_N ((translator, from, to))
991
btrans_add_translation(TypeBTransP translator, EntryP from, EntryP to)
1093
		       PROTO_T (TypeBTransP translator X
-
 
1094
				EntryP      from X
-
 
1095
				EntryP      to)
-
 
1096
{
992
{
1097
    TransP link = ALLOCATE (TransT);
993
    TransP link = ALLOCATE(TransT);
1098
 
994
 
1099
    link->to            = to;
995
    link->to            = to;
1100
    link->from          = from;
996
    link->from          = from;
1101
    link->next          = NIL (TransP);
997
    link->next          = NIL(TransP);
1102
    *(translator->tail) = link;
998
    *(translator->tail) = link;
1103
    translator->tail    = &(link->next);
999
    translator->tail    = &(link->next);
1104
}
1000
}
1105
 
1001
 
1106
void
1002
void
1107
btrans_generate_names PROTO_N ((translator, tuple, table))
1003
btrans_generate_names(TypeBTransP translator, TypeTupleP tuple, TableP table)
1108
		      PROTO_T (TypeBTransP translator X
-
 
1109
			       TypeTupleP  tuple X
-
 
1110
			       TableP      table)
-
 
1111
{
1004
{
1112
    TypeTupleEntryP tuple_ptr = tuple->head;
1005
    TypeTupleEntryP tuple_ptr = tuple->head;
1113
 
1006
 
1114
    while (tuple_ptr) {
1007
    while (tuple_ptr) {
1115
	btrans_add_translation (translator, tuple_ptr->name,
1008
	btrans_add_translation(translator, tuple_ptr->name,
1116
				table_add_generated_name (table));
1009
				table_add_generated_name(table));
1117
	tuple_ptr = tuple_ptr->next;
1010
	tuple_ptr = tuple_ptr->next;
1118
    }
1011
    }
1119
}
1012
}
1120
 
1013
 
1121
void
1014
void
1122
btrans_regenerate_names PROTO_N ((translator, tuple))
1015
btrans_regenerate_names(TypeBTransP translator, TypeTupleP tuple)
1123
			PROTO_T (TypeBTransP translator X
-
 
1124
				 TypeTupleP  tuple)
-
 
1125
{
1016
{
1126
    TypeTupleEntryP  tuple_ptr = tuple->head;
1017
    TypeTupleEntryP  tuple_ptr = tuple->head;
1127
    TransP           trans_ptr = translator->head;
1018
    TransP           trans_ptr = translator->head;
1128
 
1019
 
1129
    while (tuple_ptr) {
1020
    while (tuple_ptr) {
1130
	ASSERT (trans_ptr != NIL (TransP));
1021
	ASSERT(trans_ptr != NIL(TransP));
1131
	trans_ptr->from = tuple_ptr->name;
1022
	trans_ptr->from = tuple_ptr->name;
1132
	trans_ptr       = trans_ptr->next;
1023
	trans_ptr       = trans_ptr->next;
1133
	tuple_ptr       = tuple_ptr->next;
1024
	tuple_ptr       = tuple_ptr->next;
1134
    }
1025
    }
1135
    ASSERT (trans_ptr == NIL (TransP));
1026
    ASSERT(trans_ptr == NIL(TransP));
1136
}
1027
}
1137
 
1028
 
1138
ItemP
1029
ItemP
1139
btrans_generate_non_pred_names PROTO_N ((translator, tuple, result,
1030
btrans_generate_non_pred_names(TypeBTransP translator, TypeTupleP tuple,
1140
					 predicate_id, table))
-
 
1141
			       PROTO_T (TypeBTransP translator X
1031
			       TypeTupleP result, EntryP predicate_id,
1142
					TypeTupleP  tuple X
-
 
1143
					TypeTupleP  result X
-
 
1144
					EntryP      predicate_id X
-
 
1145
					TableP      table)
1032
			       TableP table)
1146
{
1033
{
1147
    TypeTupleEntryP ptr = tuple->head;
1034
    TypeTupleEntryP ptr = tuple->head;
1148
    TypeTupleT      from;
1035
    TypeTupleT      from;
1149
    TypeTupleT      to;
1036
    TypeTupleT      to;
1150
 
1037
 
1151
    types_init (&from);
1038
    types_init(&from);
1152
    types_init (&to);
1039
    types_init(&to);
1153
    while (ptr) {
1040
    while (ptr) {
1154
	if (ptr->name == predicate_id) {
1041
	if (ptr->name == predicate_id) {
1155
	    btrans_add_translation (translator, predicate_id, predicate_id);
1042
	    btrans_add_translation(translator, predicate_id, predicate_id);
1156
	} else {
1043
	} else {
1157
	    EntryP entry = table_add_generated_name (table);
1044
	    EntryP entry = table_add_generated_name(table);
1158
 
1045
 
1159
	    btrans_add_translation (translator, ptr->name, entry);
1046
	    btrans_add_translation(translator, ptr->name, entry);
1160
	    if (types_contains (result, ptr->name)) {
1047
	    if (types_contains(result, ptr->name)) {
1161
		types_add_name_and_type (&from, entry, ptr->type,
1048
		types_add_name_and_type(&from, entry, ptr->type,
1162
					 ptr->reference);
1049
					ptr->reference);
1163
		types_add_name_and_type (&to, ptr->name, ptr->type,
1050
		types_add_name_and_type(&to, ptr->name, ptr->type,
1164
					 ptr->reference);
1051
					ptr->reference);
1165
	    }
1052
	    }
1166
	}
1053
	}
1167
	ptr = ptr->next;
1054
	ptr = ptr->next;
1168
    }
1055
    }
1169
    if (types_equal_zero_tuple (&from)) {
1056
    if (types_equal_zero_tuple(&from)) {
1170
	types_destroy (&from);
1057
	types_destroy(&from);
1171
	types_destroy (&to);
1058
	types_destroy(&to);
1172
	return (NIL (ItemP));
1059
	return(NIL(ItemP));
1173
    } else {
1060
    } else {
1174
	ItemP item = item_create (table_add_rename (table));
1061
	ItemP item = item_create(table_add_rename(table));
1175
 
1062
 
1176
	types_assign (item_param (item), &from);
1063
	types_assign(item_param(item), &from);
1177
	types_assign (item_result (item), &to);
1064
	types_assign(item_result(item), &to);
1178
	return (item);
1065
	return(item);
1179
    }
1066
    }
1180
}
1067
}
1181
 
1068
 
1182
ItemP
1069
ItemP
1183
btrans_regen_non_pred_names PROTO_N ((translator, tuple, result, table))
1070
btrans_regen_non_pred_names(TypeBTransP translator, TypeTupleP tuple,
1184
			    PROTO_T (TypeBTransP translator X
-
 
1185
				     TypeTupleP  tuple X
-
 
1186
				     TypeTupleP  result X
1071
			    TypeTupleP result, TableP table)
1187
				     TableP      table)
-
 
1188
{
1072
{
1189
    TypeTupleEntryP tuple_ptr = tuple->head;
1073
    TypeTupleEntryP tuple_ptr = tuple->head;
1190
    TransP          trans_ptr = translator->head;
1074
    TransP          trans_ptr = translator->head;
1191
    TypeTupleT      from;
1075
    TypeTupleT      from;
1192
    TypeTupleT      to;
1076
    TypeTupleT      to;
1193
 
1077
 
1194
    types_init (&from);
1078
    types_init(&from);
1195
    types_init (&to);
1079
    types_init(&to);
1196
    while (tuple_ptr) {
1080
    while (tuple_ptr) {
1197
	ASSERT (trans_ptr != NIL (TransP));
1081
	ASSERT(trans_ptr != NIL(TransP));
1198
	trans_ptr->from = tuple_ptr->name;
1082
	trans_ptr->from = tuple_ptr->name;
1199
	if (types_contains (result, tuple_ptr->name)) {
1083
	if (types_contains(result, tuple_ptr->name)) {
1200
	    types_add_name_and_type (&from, trans_ptr->to, tuple_ptr->type,
1084
	    types_add_name_and_type(&from, trans_ptr->to, tuple_ptr->type,
1201
				     tuple_ptr->reference);
1085
				    tuple_ptr->reference);
1202
	    types_add_name_and_type (&to, trans_ptr->from, tuple_ptr->type,
1086
	    types_add_name_and_type(&to, trans_ptr->from, tuple_ptr->type,
1203
				     tuple_ptr->reference);
1087
				    tuple_ptr->reference);
1204
	}
1088
	}
1205
	trans_ptr       = trans_ptr->next;
1089
	trans_ptr       = trans_ptr->next;
1206
	tuple_ptr       = tuple_ptr->next;
1090
	tuple_ptr       = tuple_ptr->next;
1207
    }
1091
    }
1208
    ASSERT (trans_ptr == NIL (TransP));
1092
    ASSERT(trans_ptr == NIL(TransP));
1209
    if (types_equal_zero_tuple (&from)) {
1093
    if (types_equal_zero_tuple(&from)) {
1210
	types_destroy (&from);
1094
	types_destroy(&from);
1211
	types_destroy (&to);
1095
	types_destroy(&to);
1212
	return (NIL (ItemP));
1096
	return(NIL(ItemP));
1213
    } else {
1097
    } else {
1214
	ItemP item = item_create (table_add_rename (table));
1098
	ItemP item = item_create(table_add_rename(table));
1215
 
1099
 
1216
	types_assign (item_param (item), &from);
1100
	types_assign(item_param(item), &from);
1217
	types_assign (item_result (item), &to);
1101
	types_assign(item_result(item), &to);
1218
	return (item);
1102
	return(item);
1219
    }
1103
    }
1220
}
1104
}
1221
 
1105
 
1222
EntryP
1106
EntryP
1223
btrans_get_translation PROTO_N ((translator, entry))
1107
btrans_get_translation(TypeBTransP translator, EntryP entry)
1224
		       PROTO_T (TypeBTransP translator X
-
 
1225
				EntryP      entry)
-
 
1226
{
1108
{
1227
    EntryP translation = NIL (EntryP);
1109
    EntryP translation = NIL(EntryP);
1228
    TransP ptr;
1110
    TransP ptr;
1229
 
1111
 
1230
    for (ptr = translator->head; ptr; ptr = ptr->next) {
1112
    for (ptr = translator->head; ptr; ptr = ptr->next) {
1231
	if (ptr->from == entry) {
1113
	if (ptr->from == entry) {
1232
	    translation = ptr->to;
1114
	    translation = ptr->to;
1233
	}
1115
	}
1234
    }
1116
    }
1235
    return (translation);
1117
    return(translation);
1236
}
1118
}
1237
 
1119
 
1238
void
1120
void
1239
btrans_destroy PROTO_N ((translator))
1121
btrans_destroy(TypeBTransP translator)
1240
	       PROTO_T (TypeBTransP translator)
-
 
1241
{
1122
{
1242
    TransP ptr = (translator->head);
1123
    TransP ptr = (translator->head);
1243
    TransP tmp;
1124
    TransP tmp;
1244
 
1125
 
1245
    while ((tmp = ptr) != NIL (TransP)) {
1126
    while ((tmp = ptr) != NIL(TransP)) {
1246
	ptr = ptr->next;
1127
	ptr = ptr->next;
1247
	DEALLOCATE (tmp);
1128
	DEALLOCATE(tmp);
1248
    }
1129
    }
1249
}
1130
}
1250
 
1131
 
1251
/*==========================================================================*\
1132
/*==========================================================================*\
1252
|| Rename stack name translator handling functions.
1133
|| Rename stack name translator handling functions.
1253
\*==========================================================================*/
1134
\*==========================================================================*/
1254
 
1135
 
1255
void
1136
void
1256
rtrans_init PROTO_N ((translator))
-
 
1257
	    PROTO_T (TypeRTransP translator)
1137
rtrans_init(TypeRTransP translator)
1258
{
1138
{
1259
    translator->head = NIL (RTransP);
1139
    translator->head = NIL(RTransP);
1260
    translator->tail = &(translator->head);
1140
    translator->tail = &(translator->head);
1261
}
1141
}
1262
 
1142
 
1263
void
1143
void
1264
rtrans_add_translation PROTO_N ((translator, from, to, type, reference))
1144
rtrans_add_translation(TypeRTransP translator, EntryP from, EntryP to,
1265
		       PROTO_T (TypeRTransP translator X
1145
		       EntryP type, BoolT reference)
1266
				EntryP      from X
-
 
1267
				EntryP      to X
-
 
1268
				EntryP      type X
-
 
1269
				BoolT       reference)
-
 
1270
{
1146
{
1271
    RTransP link = ALLOCATE (RTransT);
1147
    RTransP link = ALLOCATE(RTransT);
1272
 
1148
 
1273
    link->next          = NIL (RTransP);
1149
    link->next          = NIL(RTransP);
1274
    link->to            = to;
1150
    link->to            = to;
1275
    link->from          = from;
1151
    link->from          = from;
1276
    link->type          = type;
1152
    link->type          = type;
1277
    link->reference     = reference;
1153
    link->reference     = reference;
1278
    *(translator->tail) = link;
1154
    *(translator->tail) = link;
1279
    translator->tail    = &(link->next);
1155
    translator->tail    = &(link->next);
1280
}
1156
}
1281
 
1157
 
1282
EntryP
1158
EntryP
1283
rtrans_get_translation PROTO_N ((translator, entry, type_ref, reference_ref))
1159
rtrans_get_translation(TypeRTransP translator, EntryP entry, EntryP *type_ref,
1284
		       PROTO_T (TypeRTransP translator X
-
 
1285
				EntryP      entry X
-
 
1286
				EntryP     *type_ref X
-
 
1287
				BoolT      *reference_ref)
1160
		       BoolT *reference_ref)
1288
{
1161
{
1289
    RTransP ptr;
1162
    RTransP ptr;
1290
 
1163
 
1291
    for (ptr = translator->head; ptr; ptr = ptr->next) {
1164
    for (ptr = translator->head; ptr; ptr = ptr->next) {
1292
	if (ptr->from == entry) {
1165
	if (ptr->from == entry) {
1293
	    *type_ref      = ptr->type;
1166
	    *type_ref      = ptr->type;
1294
	    *reference_ref = ptr->reference;
1167
	    *reference_ref = ptr->reference;
1295
	    return (ptr->to);
1168
	    return(ptr->to);
1296
	}
1169
	}
1297
    }
1170
    }
1298
    return (NIL (EntryP));
1171
    return(NIL(EntryP));
1299
}
1172
}
1300
 
1173
 
1301
void
1174
void
1302
rtrans_apply_for_non_locals PROTO_N ((translator, proc, closure))
1175
rtrans_apply_for_non_locals(TypeRTransP translator,
1303
			    PROTO_T (TypeRTransP translator X
-
 
1304
				     void      (*proc) PROTO_S ((EntryP,
1176
			    void (*proc)(EntryP, EntryP, GenericP),
1305
								 EntryP,
-
 
1306
								 GenericP)) X
-
 
1307
				     GenericP    closure)
1177
			    GenericP closure)
1308
{
1178
{
1309
    RTransP ptr;
1179
    RTransP ptr;
1310
 
1180
 
1311
    for (ptr = translator->head; ptr; ptr = ptr->next) {
1181
    for (ptr = translator->head; ptr; ptr = ptr->next) {
1312
	(*proc) (ptr->from, ptr->to, closure);
1182
	(*proc)(ptr->from, ptr->to, closure);
1313
    }
1183
    }
1314
}
1184
}
1315
 
1185
 
1316
void
1186
void
1317
rtrans_destroy PROTO_N ((translator))
1187
rtrans_destroy(TypeRTransP translator)
1318
	       PROTO_T (TypeRTransP translator)
-
 
1319
{
1188
{
1320
    RTransP ptr = (translator->head);
1189
    RTransP ptr = (translator->head);
1321
    RTransP tmp;
1190
    RTransP tmp;
1322
 
1191
 
1323
    while ((tmp = ptr) != NIL (RTransP)) {
1192
    while ((tmp = ptr) != NIL(RTransP)) {
1324
	ptr = ptr->next;
1193
	ptr = ptr->next;
1325
	DEALLOCATE (tmp);
1194
	DEALLOCATE(tmp);
1326
    }
1195
    }
1327
}
1196
}
1328
 
1197
 
1329
/*==========================================================================*\
1198
/*==========================================================================*\
1330
|| Name translator handling functions.
1199
|| Name translator handling functions.
1331
\*==========================================================================*/
1200
\*==========================================================================*/
1332
 
1201
 
1333
void
1202
void
1334
trans_init PROTO_N ((translator, param, result, alt))
1203
trans_init(TypeTransP translator, TypeTupleP param, TypeTupleP result,
1335
	   PROTO_T (TypeTransP translator X
-
 
1336
		    TypeTupleP param X
-
 
1337
		    TypeTupleP result X
-
 
1338
		    AltP       alt)
1204
	   AltP alt)
1339
{
1205
{
1340
    TypeTupleEntryP ptr;
1206
    TypeTupleEntryP ptr;
1341
    ItemP           item;
1207
    ItemP           item;
1342
 
1208
 
1343
    translator->head = NIL (TransP);
1209
    translator->head = NIL(TransP);
1344
    translator->tail = &(translator->head);
1210
    translator->tail = &(translator->head);
1345
    entry_list_init (&(translator->used_names));
1211
    entry_list_init(&(translator->used_names));
1346
    for (ptr = param->head; ptr; ptr = ptr->next) {
1212
    for (ptr = param->head; ptr; ptr = ptr->next) {
1347
        entry_list_add_if_missing (&(translator->used_names), ptr->name);
1213
        entry_list_add_if_missing(&(translator->used_names), ptr->name);
1348
    }
1214
    }
1349
    for (ptr = result->head; ptr; ptr = ptr->next) {
1215
    for (ptr = result->head; ptr; ptr = ptr->next) {
1350
	entry_list_add_if_missing (&(translator->used_names), ptr->name);
1216
	entry_list_add_if_missing(&(translator->used_names), ptr->name);
1351
    }
1217
    }
1352
    for (item = alt_item_head (alt); item; item = item_next (item)) {
1218
    for (item = alt_item_head(alt); item; item = item_next(item)) {
1353
        TypeTupleP type = item_result (item);
1219
        TypeTupleP type = item_result(item);
1354
 
1220
 
1355
	for (ptr = type->head; ptr; ptr = ptr->next) {
1221
	for (ptr = type->head; ptr; ptr = ptr->next) {
1356
	    entry_list_add_if_missing (&(translator->used_names), ptr->name);
1222
	    entry_list_add_if_missing(&(translator->used_names), ptr->name);
1357
	}
1223
	}
1358
    }
1224
    }
1359
}
1225
}
1360
 
1226
 
1361
void
1227
void
1362
trans_add_translation PROTO_N ((translator, from, to))
1228
trans_add_translation(TypeTransP translator, EntryP from, EntryP to)
1363
		      PROTO_T (TypeTransP translator X
-
 
1364
			       EntryP     from X
-
 
1365
			       EntryP     to)
-
 
1366
{
1229
{
1367
    TransP link = ALLOCATE (TransT);
1230
    TransP link = ALLOCATE(TransT);
1368
 
1231
 
1369
    link->to            = to;
1232
    link->to            = to;
1370
    link->from          = from;
1233
    link->from          = from;
1371
    link->next          = NIL (TransP);
1234
    link->next          = NIL(TransP);
1372
    *(translator->tail) = link;
1235
    *(translator->tail) = link;
1373
    translator->tail    = &(link->next);
1236
    translator->tail    = &(link->next);
1374
}
1237
}
1375
 
1238
 
1376
void
1239
void
1377
trans_add_translations PROTO_N ((translator, from, to))
1240
trans_add_translations(TypeTransP translator, TypeTupleP from, TypeTupleP to)
1378
		       PROTO_T (TypeTransP translator X
-
 
1379
				TypeTupleP from X
-
 
1380
				TypeTupleP to)
-
 
1381
{
1241
{
1382
    TypeTupleEntryP from_ptr = from->head;
1242
    TypeTupleEntryP from_ptr = from->head;
1383
    TypeTupleEntryP to_ptr   = to->head;
1243
    TypeTupleEntryP to_ptr   = to->head;
1384
 
1244
 
1385
    while (from_ptr) {
1245
    while (from_ptr) {
1386
	ASSERT (to_ptr != NIL (TypeTupleEntryP));
1246
	ASSERT(to_ptr != NIL(TypeTupleEntryP));
1387
	trans_add_translation (translator, from_ptr->name, to_ptr->name);
1247
	trans_add_translation(translator, from_ptr->name, to_ptr->name);
1388
	from_ptr = from_ptr->next;
1248
	from_ptr = from_ptr->next;
1389
	to_ptr   = to_ptr->next;
1249
	to_ptr   = to_ptr->next;
1390
    }
1250
    }
1391
    ASSERT (to_ptr == NIL (TypeTupleEntryP));
1251
    ASSERT(to_ptr == NIL(TypeTupleEntryP));
1392
}
1252
}
1393
 
1253
 
1394
void
1254
void
1395
trans_save_state PROTO_N ((translator, state))
1255
trans_save_state(TypeTransP translator, SaveTransP state)
1396
		 PROTO_T (TypeTransP translator X
-
 
1397
			  SaveTransP state)
-
 
1398
{
1256
{
1399
    state->last_ref = translator->tail;
1257
    state->last_ref = translator->tail;
1400
}
1258
}
1401
 
1259
 
1402
EntryP
1260
EntryP
1403
trans_get_translation PROTO_N ((translator, entry))
1261
trans_get_translation(TypeTransP translator, EntryP entry)
1404
		      PROTO_T (TypeTransP translator X
-
 
1405
			       EntryP     entry)
-
 
1406
{
1262
{
1407
    EntryP translation = NIL (EntryP);
1263
    EntryP translation = NIL(EntryP);
1408
    TransP      ptr;
1264
    TransP      ptr;
1409
 
1265
 
1410
    for (ptr = translator->head; ptr; ptr = ptr->next) {
1266
    for (ptr = translator->head; ptr; ptr = ptr->next) {
1411
	if (ptr->from == entry) {
1267
	if (ptr->from == entry) {
1412
	    translation = ptr->to;
1268
	    translation = ptr->to;
1413
	}
1269
	}
1414
    }
1270
    }
1415
    if (translation) {
1271
    if (translation) {
1416
	return (translation);
1272
	return(translation);
1417
    }
1273
    }
1418
    if (!entry_list_contains (&(translator->used_names), entry)) {
1274
    if (!entry_list_contains(&(translator->used_names), entry)) {
1419
        return (entry);
1275
        return(entry);
1420
    }
1276
    }
1421
    return (NIL (EntryP));
1277
    return(NIL(EntryP));
1422
}
1278
}
1423
 
1279
 
1424
void
1280
void
1425
trans_restore_state PROTO_N ((translator, state))
1281
trans_restore_state(TypeTransP translator, SaveTransP state)
1426
		    PROTO_T (TypeTransP translator X
-
 
1427
			     SaveTransP state)
-
 
1428
{
1282
{
1429
    TransP ptr = (*(state->last_ref));
1283
    TransP ptr = (*(state->last_ref));
1430
    TransP tmp;
1284
    TransP tmp;
1431
 
1285
 
1432
    *(state->last_ref) = NIL (TransP);
1286
    *(state->last_ref) = NIL(TransP);
1433
    while ((tmp = ptr) != NIL (TransP)) {
1287
    while ((tmp = ptr) != NIL(TransP)) {
1434
	ptr = ptr->next;
1288
	ptr = ptr->next;
1435
	DEALLOCATE (tmp);
1289
	DEALLOCATE(tmp);
1436
    }
1290
    }
1437
    translator->tail = state->last_ref;
1291
    translator->tail = state->last_ref;
1438
}
1292
}
1439
 
1293
 
1440
void
1294
void
1441
trans_destroy PROTO_N ((translator))
1295
trans_destroy(TypeTransP translator)
1442
	      PROTO_T (TypeTransP translator)
-
 
1443
{
1296
{
1444
    TransP ptr = (translator->head);
1297
    TransP ptr = (translator->head);
1445
    TransP tmp;
1298
    TransP tmp;
1446
 
1299
 
1447
    while ((tmp = ptr) != NIL (TransP)) {
1300
    while ((tmp = ptr) != NIL(TransP)) {
1448
	ptr = ptr->next;
1301
	ptr = ptr->next;
1449
	DEALLOCATE (tmp);
1302
	DEALLOCATE(tmp);
1450
    }
1303
    }
1451
    entry_list_destroy (&(translator->used_names));
1304
    entry_list_destroy(&(translator->used_names));
1452
}
1305
}
1453
 
1306
 
1454
/*==========================================================================*\
1307
/*==========================================================================*\
1455
|| Numeric translator handling functions.
1308
|| Numeric translator handling functions.
1456
\*==========================================================================*/
1309
\*==========================================================================*/
1457
 
1310
 
1458
static unsigned
1311
static unsigned
1459
ntrans_add_translation PROTO_N ((translator, from))
1312
ntrans_add_translation(TypeNTransP translator, EntryP from)
1460
		       PROTO_T (TypeNTransP translator X
-
 
1461
				EntryP      from)
-
 
1462
{
1313
{
1463
    NTransP link = ALLOCATE (NTransT);
1314
    NTransP link = ALLOCATE(NTransT);
1464
 
1315
 
1465
    if (translator->count == UINT_MAX) {
1316
    if (translator->count == UINT_MAX) {
1466
	E_too_many_generated_names ();
1317
	E_too_many_generated_names();
1467
	UNREACHED;
1318
	UNREACHED;
1468
    }
1319
    }
1469
    link->to            = (translator->count) ++;
1320
    link->to            = (translator->count)++;
1470
    link->from          = from;
1321
    link->from          = from;
1471
    link->next          = NIL (NTransP);
1322
    link->next          = NIL(NTransP);
1472
    *(translator->tail) = link;
1323
    *(translator->tail) = link;
1473
    translator->tail    = &(link->next);
1324
    translator->tail    = &(link->next);
1474
    return (link->to);
1325
    return(link->to);
1475
}
1326
}
1476
 
1327
 
1477
/*--------------------------------------------------------------------------*/
1328
/*--------------------------------------------------------------------------*/
1478
 
1329
 
1479
void
1330
void
1480
ntrans_init PROTO_N ((translator))
-
 
1481
	    PROTO_T (TypeNTransP translator)
1331
ntrans_init(TypeNTransP translator)
1482
{
1332
{
1483
    translator->count      = 0;
1333
    translator->count      = 0;
1484
    translator->head       = NIL (NTransP);
1334
    translator->head       = NIL(NTransP);
1485
    translator->tail       = &(translator->head);
1335
    translator->tail       = &(translator->head);
1486
}
1336
}
1487
 
1337
 
1488
void
1338
void
1489
ntrans_save_state PROTO_N ((translator, state))
1339
ntrans_save_state(TypeNTransP translator, SaveNTransP state)
1490
		  PROTO_T (TypeNTransP translator X
-
 
1491
			   SaveNTransP state)
-
 
1492
{
1340
{
1493
    state->last_count = translator->count;
1341
    state->last_count = translator->count;
1494
    state->last_ref   = translator->tail;
1342
    state->last_ref   = translator->tail;
1495
}
1343
}
1496
 
1344
 
1497
unsigned
1345
unsigned
1498
ntrans_get_translation PROTO_N ((translator, entry))
1346
ntrans_get_translation(TypeNTransP translator, EntryP entry)
1499
		       PROTO_T (TypeNTransP translator X
-
 
1500
				EntryP      entry)
-
 
1501
{
1347
{
1502
    NTransP ptr;
1348
    NTransP ptr;
1503
 
1349
 
1504
    for (ptr = translator->head; ptr; ptr = ptr->next) {
1350
    for (ptr = translator->head; ptr; ptr = ptr->next) {
1505
	if (ptr->from == entry) {
1351
	if (ptr->from == entry) {
1506
	    return (ptr->to);
1352
	    return(ptr->to);
1507
	}
1353
	}
1508
    }
1354
    }
1509
    return (ntrans_add_translation (translator, entry));
1355
    return(ntrans_add_translation(translator, entry));
1510
}
1356
}
1511
 
1357
 
1512
EntryP
1358
EntryP
1513
ntrans_get_indirect_translation PROTO_N ((from_translator, to_translator,
1359
ntrans_get_indirect_translation(TypeNTransP from_translator,
1514
					  entry))
-
 
1515
				PROTO_T (TypeNTransP from_translator X
-
 
1516
					 TypeNTransP to_translator X
1360
				TypeNTransP to_translator, EntryP entry)
1517
					 EntryP      entry)
-
 
1518
{
1361
{
1519
    NTransP  ptr;
1362
    NTransP  ptr;
1520
    unsigned name;
1363
    unsigned name;
1521
 
1364
 
1522
    for (ptr = from_translator->head; ptr; ptr = ptr->next) {
1365
    for (ptr = from_translator->head; ptr; ptr = ptr->next) {
1523
	if (ptr->from == entry) {
1366
	if (ptr->from == entry) {
1524
	    name = ptr->to;
1367
	    name = ptr->to;
1525
	    goto found;
1368
	    goto found;
1526
	}
1369
	}
1527
    }
1370
    }
1528
    return (NIL (EntryP));
1371
    return(NIL(EntryP));
1529
  found:
1372
  found:
1530
    for (ptr = to_translator->head; ptr; ptr = ptr->next) {
1373
    for (ptr = to_translator->head; ptr; ptr = ptr->next) {
1531
	if (ptr->to == name) {
1374
	if (ptr->to == name) {
1532
	    return (ptr->from);
1375
	    return(ptr->from);
1533
	}
1376
	}
1534
    }
1377
    }
1535
    UNREACHED;
1378
    UNREACHED;
1536
}
1379
}
1537
 
1380
 
1538
void
1381
void
1539
ntrans_restore_state PROTO_N ((translator, state))
1382
ntrans_restore_state(TypeNTransP translator, SaveNTransP state)
1540
		     PROTO_T (TypeNTransP translator X
-
 
1541
			      SaveNTransP state)
-
 
1542
{
1383
{
1543
    NTransP ptr = (*(state->last_ref));
1384
    NTransP ptr = (*(state->last_ref));
1544
    NTransP tmp;
1385
    NTransP tmp;
1545
 
1386
 
1546
    *(state->last_ref) = NIL (NTransP);
1387
    *(state->last_ref) = NIL(NTransP);
1547
    translator->count  = state->last_count;
1388
    translator->count  = state->last_count;
1548
    while ((tmp = ptr) != NIL (NTransP)) {
1389
    while ((tmp = ptr) != NIL(NTransP)) {
1549
	ptr = ptr->next;
1390
	ptr = ptr->next;
1550
	DEALLOCATE (tmp);
1391
	DEALLOCATE(tmp);
1551
    }
1392
    }
1552
    translator->tail = state->last_ref;
1393
    translator->tail = state->last_ref;
1553
}
1394
}
1554
 
1395
 
1555
void
1396
void
1556
ntrans_destroy PROTO_N ((translator))
1397
ntrans_destroy(TypeNTransP translator)
1557
	       PROTO_T (TypeNTransP translator)
-
 
1558
{
1398
{
1559
    NTransP ptr = (translator->head);
1399
    NTransP ptr = (translator->head);
1560
    NTransP tmp;
1400
    NTransP tmp;
1561
 
1401
 
1562
    while ((tmp = ptr) != NIL (NTransP)) {
1402
    while ((tmp = ptr) != NIL(NTransP)) {
1563
	ptr = ptr->next;
1403
	ptr = ptr->next;
1564
	DEALLOCATE (tmp);
1404
	DEALLOCATE(tmp);
1565
    }
1405
    }
1566
}
1406
}
1567

1407

1568
/*
1408
/*
1569
 * Local variables(smf):
1409
 * Local variables(smf):