Subversion Repositories tendra.SVN

Rev

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

Rev 2 Rev 7
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 61... Line 91...
61
#include "type.h"
91
#include "type.h"
62
 
92
 
63
/*--------------------------------------------------------------------------*/
93
/*--------------------------------------------------------------------------*/
64
 
94
 
65
void
95
void
66
rstack_init PROTO_N ((rstack))
96
rstack_init(RStackP rstack)
67
	    PROTO_T (RStackP rstack)
-
 
68
{
97
{
69
    rstack->head = NIL (TransStackEntryP);
98
    rstack->head = NIL(TransStackEntryP);
70
}
99
}
71
 
100
 
72
void
101
void
73
rstack_push_frame PROTO_N ((rstack))
102
rstack_push_frame(RStackP rstack)
74
		  PROTO_T (RStackP rstack)
-
 
75
{
103
{
76
    TransStackEntryP frame = ALLOCATE (TransStackEntryT);
104
    TransStackEntryP frame = ALLOCATE(TransStackEntryT);
77
 
105
 
78
    frame->next = rstack->head;
106
    frame->next = rstack->head;
79
    rtrans_init (&(frame->translator));
107
    rtrans_init(&(frame->translator));
80
    rstack->head = frame;
108
    rstack->head = frame;
81
}
109
}
82
 
110
 
83
void
111
void
84
rstack_compute_formal_renaming PROTO_N ((rstack, names))
112
rstack_compute_formal_renaming(RStackP rstack, TypeTupleP names)
85
			       PROTO_T (RStackP    rstack X
-
 
86
					TypeTupleP names)
-
 
87
{
113
{
88
    ASSERT (rstack->head);
114
    ASSERT(rstack->head);
89
    types_compute_formal_renaming (names, &(rstack->head->translator));
115
    types_compute_formal_renaming(names, &(rstack->head->translator));
90
}
116
}
91
 
117
 
92
void
118
void
93
rstack_compute_formal_inlining PROTO_N ((rstack, names, renames))
119
rstack_compute_formal_inlining(RStackP rstack, TypeTupleP names,
94
			       PROTO_T (RStackP    rstack X
-
 
95
					TypeTupleP names X
-
 
96
					TypeTupleP renames)
120
			       TypeTupleP renames)
97
{
121
{
98
    SaveRStackT state;
122
    SaveRStackT state;
99
 
123
 
100
    ASSERT (rstack->head);
124
    ASSERT(rstack->head);
101
    state.head = rstack->head->next;
125
    state.head = rstack->head->next;
102
    types_compute_formal_inlining (names, renames, &(rstack->head->translator),
126
    types_compute_formal_inlining(names, renames, &(rstack->head->translator),
103
				   &state);
127
				  &state);
104
}
128
}
105
 
129
 
106
void
130
void
107
rstack_compute_local_renaming PROTO_N ((rstack, names, exclude, table))
131
rstack_compute_local_renaming(RStackP rstack, TypeTupleP names,
108
			      PROTO_T (RStackP    rstack X
-
 
109
				       TypeTupleP names X
-
 
110
				       TypeTupleP exclude X
132
			      TypeTupleP exclude, TableP table)
111
				       TableP     table)
-
 
112
{
133
{
113
    SaveRStackT state;
134
    SaveRStackT state;
114
 
135
 
115
    ASSERT (rstack->head);
136
    ASSERT(rstack->head);
116
    state.head = rstack->head->next;
137
    state.head = rstack->head->next;
117
    types_compute_local_renaming (names, exclude, &(rstack->head->translator),
138
    types_compute_local_renaming(names, exclude, &(rstack->head->translator),
118
				  &state, table);
139
				 &state, table);
119
}
140
}
120
 
141
 
121
void
142
void
122
rstack_add_translation PROTO_N ((rstack, from, to, type, reference))
143
rstack_add_translation(RStackP rstack, EntryP from, EntryP to, EntryP type,
123
		       PROTO_T (RStackP rstack X
-
 
124
				EntryP  from X
-
 
125
				EntryP  to X
-
 
126
				EntryP  type X
-
 
127
				BoolT   reference)
144
		       BoolT reference)
128
{
145
{
129
    ASSERT (rstack->head);
146
    ASSERT(rstack->head);
130
    rtrans_add_translation (&(rstack->head->translator), from, to, type,
147
    rtrans_add_translation(&(rstack->head->translator), from, to, type,
131
			    reference);
148
			   reference);
132
}
149
}
133
 
150
 
134
void
151
void
135
rstack_save_state PROTO_N ((rstack, state))
152
rstack_save_state(RStackP rstack, SaveRStackP state)
136
		  PROTO_T (RStackP     rstack X
-
 
137
			   SaveRStackP state)
-
 
138
{
153
{
139
    state->head = rstack->head;
154
    state->head = rstack->head;
140
}
155
}
141
 
156
 
142
EntryP
157
EntryP
143
rstack_get_translation PROTO_N ((state, entry, type_ref, reference_ref))
158
rstack_get_translation(SaveRStackP state, EntryP entry, EntryP *type_ref,
144
		       PROTO_T (SaveRStackP state X
-
 
145
				EntryP      entry X
-
 
146
				EntryP     *type_ref X
-
 
147
				BoolT      *reference_ref)
159
		       BoolT *reference_ref)
148
{
160
{
149
    TransStackEntryP frame = state->head;
161
    TransStackEntryP frame = state->head;
150
 
162
 
151
    while (frame) {
163
    while (frame) {
152
	EntryP translation;
164
	EntryP translation;
153
 
165
 
154
	translation = rtrans_get_translation (&(frame->translator), entry,
166
	translation = rtrans_get_translation(&(frame->translator), entry,
155
					      type_ref, reference_ref);
167
					     type_ref, reference_ref);
156
	if (translation) {
168
	if (translation) {
157
	    return (translation);
169
	    return(translation);
158
	}
170
	}
159
	frame = frame->next;
171
	frame = frame->next;
160
    }
172
    }
161
    return (NIL (EntryP));
173
    return(NIL(EntryP));
162
}
174
}
163
 
175
 
164
void
176
void
165
rstack_apply_for_non_locals PROTO_N ((non_local_stack, state, proc, closure))
177
rstack_apply_for_non_locals(RStackP non_local_stack, SaveRStackP state,
166
			    PROTO_T (RStackP     non_local_stack X
-
 
167
				     SaveRStackP state X
-
 
168
				     void      (*proc) PROTO_S ((EntryP,
178
			    void (*proc)(EntryP, EntryP, GenericP),
169
								 EntryP,
-
 
170
								 GenericP)) X
-
 
171
				     GenericP    closure)
179
			    GenericP closure)
172
{
180
{
173
    TransStackEntryP frame = non_local_stack->head;
181
    TransStackEntryP frame = non_local_stack->head;
174
 
182
 
175
    if ((frame != NIL (TransStackEntryP)) && (state->head)) {
183
    if ((frame != NIL(TransStackEntryP)) && (state->head)) {
176
	TransStackEntryP limit = state->head->next;
184
	TransStackEntryP limit = state->head->next;
177
 
185
 
178
	for (; frame != limit; frame = frame->next) {
186
	for (; frame != limit; frame = frame->next) {
179
	    rtrans_apply_for_non_locals (&(frame->translator), proc, closure);
187
	    rtrans_apply_for_non_locals(&(frame->translator), proc, closure);
180
	}
188
	}
181
    }
189
    }
182
}
190
}
183
 
191
 
184
void
192
void
185
rstack_pop_frame PROTO_N ((rstack))
193
rstack_pop_frame(RStackP rstack)
186
		 PROTO_T (RStackP rstack)
-
 
187
{
194
{
188
    TransStackEntryP frame = rstack->head;
195
    TransStackEntryP frame = rstack->head;
189
 
196
 
190
    rstack->head = frame->next;
197
    rstack->head = frame->next;
191
    rtrans_destroy (&(frame->translator));
198
    rtrans_destroy(&(frame->translator));
192
    DEALLOCATE (frame);
199
    DEALLOCATE(frame);
193
}
200
}
194
 
201
 
195
void
202
void
196
rstack_destroy PROTO_N ((rstack))
203
rstack_destroy(RStackP rstack)
197
	       PROTO_T (RStackP rstack)
-
 
198
{
204
{
199
    while (rstack->head) {
205
    while (rstack->head) {
200
	rstack_pop_frame (rstack);
206
	rstack_pop_frame(rstack);
201
    }
207
    }
202
}
208
}
203

209

204
/*
210
/*
205
 * Local variables(smf):
211
 * Local variables(smf):