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 67... Line 97...
67
} NonLocalClosureT, *NonLocalClosureP;
97
} NonLocalClosureT, *NonLocalClosureP;
68
 
98
 
69
/*--------------------------------------------------------------------------*/
99
/*--------------------------------------------------------------------------*/
70
 
100
 
71
static void
101
static void
72
c_output_save_non_locals_1 PROTO_N ((info, non_local, non_local_state, rstack,
102
c_output_save_non_locals_1(COutputInfoP info, NonLocalEntryP non_local,
73
				     handler_rule, table, indent))
-
 
74
			   PROTO_T (COutputInfoP   info X
-
 
75
				    NonLocalEntryP non_local X
-
 
76
				    SaveRStackP    non_local_state X
103
			   SaveRStackP non_local_state, RStackP rstack,
77
				    RStackP        rstack X
-
 
78
				    RuleP          handler_rule X
-
 
79
				    TableP         table X
-
 
80
				    unsigned       indent)
104
			   RuleP handler_rule, TableP table, unsigned indent)
81
{
105
{
82
    OStreamP ostream = c_out_info_ostream (info);
106
    OStreamP ostream = c_out_info_ostream(info);
83
    EntryP   entry   = non_local_entry_get_initialiser (non_local);
107
    EntryP   entry   = non_local_entry_get_initialiser(non_local);
84
 
108
 
85
    if (entry) {
109
    if (entry) {
86
	EntryP      type;
110
	EntryP      type;
87
	BoolT       reference;
111
	BoolT       reference;
88
	EntryP      translation = rstack_get_translation (non_local_state,
112
	EntryP      translation = rstack_get_translation(non_local_state,
89
							  non_local->name,
113
							 non_local->name,
90
							  &type,
-
 
91
							  &reference);
114
							 &type, &reference);
92
	KeyP        key         = entry_key (entry);
115
	KeyP        key         = entry_key(entry);
93
	ActionP     action      = entry_get_action (entry);
116
	ActionP     action      = entry_get_action(entry);
94
	TypeTupleP  param       = action_param (action);
117
	TypeTupleP  param       = action_param(action);
95
	CCodeP      code        = action_get_code (action);
118
	CCodeP      code        = action_get_code(action);
96
	BoolT       copies;
119
	BoolT       copies;
97
	TypeTupleT  args;
120
	TypeTupleT  args;
98
	TypeTupleT  result_args;
121
	TypeTupleT  result_args;
99
	SaveRStackT state;
122
	SaveRStackT state;
100
 
123
 
101
	c_output_key_message (info, "/* BEGINNING OF INITIALISER: ", key,
124
	c_output_key_message (info, "/* BEGINNING OF INITIALISER: ", key,
102
			      " */", indent);
125
			      " */", indent);
103
	c_output_open (info, indent);
126
	c_output_open(info, indent);
104
	rstack_save_state (rstack, &state);
127
	rstack_save_state(rstack, &state);
105
	rstack_push_frame (rstack);
128
	rstack_push_frame(rstack);
106
	types_init (&args);
129
	types_init(&args);
107
	if (!types_equal_zero_tuple (param)) {
130
	if (!types_equal_zero_tuple(param)) {
108
	    types_add_name_and_type (&args, translation, type, reference);
131
	    types_add_name_and_type(&args, translation, type, reference);
109
	}
132
	}
110
	types_init (&result_args);
133
	types_init(&result_args);
111
	types_add_name_and_type (&result_args, non_local->name, type, FALSE);
134
	types_add_name_and_type(&result_args, non_local->name, type, FALSE);
112
	copies = c_output_required_copies (info, c_code_param (code),
135
	copies = c_output_required_copies(info, c_code_param(code),
113
					   &args, rstack, &state,
136
					  &args, rstack, &state,
114
					   indent + C_INDENT_STEP, table);
137
					  indent + C_INDENT_STEP, table);
115
	if (copies) {
138
	if (copies) {
116
	    c_output_open (info, indent + C_INDENT_STEP);
139
	    c_output_open(info, indent + C_INDENT_STEP);
117
	}
140
	}
118
	rstack_save_state (rstack, &state);
141
	rstack_save_state(rstack, &state);
119
	c_output_location (info, c_code_file (code), c_code_line (code));
142
	c_output_location(info, c_code_file(code), c_code_line(code));
120
	c_output_c_code_action (info, code, &args, &result_args, &state,
143
	c_output_c_code_action(info, code, &args, &result_args, &state,
121
				handler_rule);
144
			       handler_rule);
122
	c_output_location (info, ostream_name (ostream),
145
	c_output_location(info, ostream_name(ostream),
123
			   ostream_line (ostream) + 1);
146
			  ostream_line(ostream) + 1);
124
	rstack_pop_frame (rstack);
147
	rstack_pop_frame(rstack);
125
	if (copies) {
148
	if (copies) {
126
	    c_output_close (info, indent + C_INDENT_STEP);
149
	    c_output_close(info, indent + C_INDENT_STEP);
127
	}
150
	}
128
	c_output_close (info, indent);
151
	c_output_close(info, indent);
129
	c_output_key_message (info, "/* END OF INITIALISER: ", key, " */",
152
	c_output_key_message (info, "/* END OF INITIALISER: ", key, " */",
130
			      indent);
153
			      indent);
131
	types_destroy (&result_args);
154
	types_destroy(&result_args);
132
	types_destroy (&args);
155
	types_destroy(&args);
133
    }
156
    }
134
}
157
}
135
 
158
 
136
static void
159
static void
137
c_output_restore_non_locals_1 PROTO_N ((from, to, gclosure))
160
c_output_restore_non_locals_1(EntryP from, EntryP to, GenericP gclosure)
138
			      PROTO_T (EntryP   from X
-
 
139
				       EntryP   to X
-
 
140
				       GenericP gclosure)
-
 
141
{
161
{
142
    NonLocalClosureP closure = (NonLocalClosureP) gclosure;
162
    NonLocalClosureP closure = (NonLocalClosureP)gclosure;
143
    COutputInfoP     info    = closure->info;
163
    COutputInfoP     info    = closure->info;
144
    SaveRStackP      state   = closure->state;
164
    SaveRStackP      state   = closure->state;
145
    unsigned         indent  = closure->indent;
165
    unsigned         indent  = closure->indent;
146
 
166
 
147
    c_output_assign (info, to, from, state, state, indent);
167
    c_output_assign(info, to, from, state, state, indent);
148
}
168
}
149
 
169
 
150
/*--------------------------------------------------------------------------*/
170
/*--------------------------------------------------------------------------*/
151
 
171
 
152
void
172
void
153
c_output_non_locals PROTO_N ((info, non_locals))
173
c_output_non_locals(COutputInfoP info, NonLocalListP non_locals)
154
		    PROTO_T (COutputInfoP  info X
-
 
155
			     NonLocalListP non_locals)
-
 
156
{
174
{
157
    OStreamP       ostream = c_out_info_ostream (info);
175
    OStreamP       ostream = c_out_info_ostream(info);
158
    NonLocalEntryP non_local;
176
    NonLocalEntryP non_local;
159
 
177
 
160
    for (non_local = non_locals->head; non_local;
178
    for (non_local = non_locals->head; non_local;
161
	 non_local = non_local->next) {
179
	 non_local = non_local->next) {
162
	if (!c_out_info_get_split (info)) {
180
	if (!c_out_info_get_split(info)) {
163
	    write_cstring (ostream, "static ");
181
	    write_cstring(ostream, "static ");
164
	}
182
	}
165
	c_output_mapped_key (info, non_local->type);
183
	c_output_mapped_key(info, non_local->type);
166
	write_char (ostream, ' ');
184
	write_char(ostream, ' ');
167
	c_output_mapped_key (info, non_local->name);
185
	c_output_mapped_key(info, non_local->name);
168
	write_char (ostream, ';');
186
	write_char(ostream, ';');
169
	write_newline (ostream);
187
	write_newline(ostream);
170
    }
188
    }
171
}
189
}
172
 
190
 
173
void
191
void
174
c_output_declare_non_locals PROTO_N ((info, non_locals))
192
c_output_declare_non_locals(COutputInfoP info, NonLocalListP non_locals)
175
			    PROTO_T (COutputInfoP  info X
-
 
176
				     NonLocalListP non_locals)
-
 
177
{
193
{
178
    OStreamP       ostream = c_out_info_ostream (info);
194
    OStreamP       ostream = c_out_info_ostream(info);
179
    NonLocalEntryP non_local;
195
    NonLocalEntryP non_local;
180
 
196
 
181
    for (non_local = non_locals->head; non_local;
197
    for (non_local = non_locals->head; non_local;
182
	 non_local = non_local->next) {
198
	 non_local = non_local->next) {
183
	write_cstring (ostream, "extern ");
199
	write_cstring(ostream, "extern ");
184
	c_output_mapped_key (info, non_local->type);
200
	c_output_mapped_key(info, non_local->type);
185
	write_char (ostream, ' ');
201
	write_char(ostream, ' ');
186
	c_output_mapped_key (info, non_local->name);
202
	c_output_mapped_key(info, non_local->name);
187
	write_char (ostream, ';');
203
	write_char(ostream, ';');
188
	write_newline (ostream);
204
	write_newline(ostream);
189
    }
205
    }
190
}
206
}
191
 
207
 
192
void
208
void
193
c_output_save_non_locals PROTO_N ((info, rule, indent, rstack, non_local_stack,
209
c_output_save_non_locals(COutputInfoP info, RuleP rule, unsigned indent,
194
				   handler_rule, table))
-
 
195
			 PROTO_T (COutputInfoP info X
-
 
196
				  RuleP        rule X
-
 
197
				  unsigned     indent X
-
 
198
				  RStackP      rstack X
-
 
199
				  RStackP      non_local_stack X
210
			 RStackP rstack, RStackP non_local_stack,
200
				  RuleP        handler_rule X
211
			 RuleP handler_rule, TableP table)
201
				  TableP       table)
-
 
202
{
212
{
203
    OStreamP       ostream    = c_out_info_ostream (info);
213
    OStreamP       ostream    = c_out_info_ostream(info);
204
    NStringP       in_prefix  = c_out_info_in_prefix (info);
214
    NStringP       in_prefix  = c_out_info_in_prefix(info);
205
    NonLocalListP  non_locals = rule_non_locals (rule);
215
    NonLocalListP  non_locals = rule_non_locals(rule);
206
    NonLocalEntryP non_local;
216
    NonLocalEntryP non_local;
207
    SaveRStackT    state;
217
    SaveRStackT    state;
208
    SaveRStackT    non_local_state;
218
    SaveRStackT    non_local_state;
209
 
219
 
210
    for (non_local = non_locals->head; non_local;
220
    for (non_local = non_locals->head; non_local;
211
	 non_local = non_local->next) {
221
	 non_local = non_local->next) {
212
	EntryP entry = table_add_generated_name (table);
222
	EntryP entry = table_add_generated_name(table);
213
 
223
 
214
	output_indent (c_out_info_info (info), indent);
224
	output_indent(c_out_info_info(info), indent);
215
	c_output_mapped_key (info, non_local->type);
225
	c_output_mapped_key(info, non_local->type);
216
	write_char (ostream, ' ');
226
	write_char(ostream, ' ');
217
	c_output_key (info, entry_key (entry), in_prefix);
227
	c_output_key(info, entry_key(entry), in_prefix);
218
	write_newline (ostream);
228
	write_newline(ostream);
219
	rstack_add_translation (non_local_stack, non_local->name, entry,
229
	rstack_add_translation(non_local_stack, non_local->name, entry,
220
				non_local->type, FALSE);
230
			       non_local->type, FALSE);
221
	rstack_add_translation (rstack, entry, entry, non_local->type, FALSE);
231
	rstack_add_translation(rstack, entry, entry, non_local->type, FALSE);
222
    }
232
    }
223
    write_newline (ostream);
233
    write_newline(ostream);
224
    rstack_save_state (rstack, &state);
234
    rstack_save_state(rstack, &state);
225
    rstack_save_state (non_local_stack, &non_local_state);
235
    rstack_save_state(non_local_stack, &non_local_state);
226
    for (non_local = non_locals->head; non_local;
236
    for (non_local = non_locals->head; non_local;
227
	 non_local = non_local->next) {
237
	 non_local = non_local->next) {
228
	EntryP type;
238
	EntryP type;
229
	BoolT  reference;
239
	BoolT  reference;
230
	EntryP entry = rstack_get_translation (&non_local_state,
240
	EntryP entry = rstack_get_translation(&non_local_state,
231
					       non_local->name, &type,
241
					      non_local->name, &type,
232
					       &reference);
242
					      &reference);
233
 
243
 
234
	ASSERT ((entry != NIL (EntryP)) && (type == non_local->type) &&
244
	ASSERT((entry != NIL(EntryP)) && (type == non_local->type) &&
235
		(!reference));
245
	       (!reference));
236
	c_output_assign (info, non_local->name, entry, &state, &state, indent);
246
	c_output_assign(info, non_local->name, entry, &state, &state, indent);
237
    }
247
    }
238
    for (non_local = non_locals->head; non_local;
248
    for (non_local = non_locals->head; non_local;
239
	 non_local = non_local->next) {
249
	 non_local = non_local->next) {
240
	c_output_save_non_locals_1 (info, non_local, &non_local_state,
250
	c_output_save_non_locals_1(info, non_local, &non_local_state,
241
				    rstack, handler_rule, table, indent);
251
				   rstack, handler_rule, table, indent);
242
    }
252
    }
243
    rstack_save_state (non_local_stack, rule_non_local_state (rule));
253
    rstack_save_state(non_local_stack, rule_non_local_state(rule));
244
}
254
}
245
 
255
 
246
void
256
void
247
c_output_restore_non_locals PROTO_N ((info, rule, indent, rstack,
257
c_output_restore_non_locals(COutputInfoP info, RuleP rule, unsigned indent,
248
				      non_local_stack))
-
 
249
			    PROTO_T (COutputInfoP info X
-
 
250
				     RuleP        rule X
-
 
251
				     unsigned     indent X
-
 
252
				     RStackP      rstack X
-
 
253
				     RStackP      non_local_stack)
258
			    RStackP rstack, RStackP non_local_stack)
254
{
259
{
255
    NonLocalClosureT closure;
260
    NonLocalClosureT closure;
256
    SaveRStackT      state;
261
    SaveRStackT      state;
257
 
262
 
258
    rstack_save_state (rstack, &state);
263
    rstack_save_state(rstack, &state);
259
    closure.info   = info;
264
    closure.info   = info;
260
    closure.state  = &state;
265
    closure.state  = &state;
261
    closure.indent = indent;
266
    closure.indent = indent;
262
    rstack_apply_for_non_locals (non_local_stack, rule_non_local_state (rule),
267
    rstack_apply_for_non_locals(non_local_stack, rule_non_local_state(rule),
263
				 c_output_restore_non_locals_1,
268
				c_output_restore_non_locals_1,
264
				 (GenericP) &closure);
269
				(GenericP) &closure);
265
}
270
}
266

271

267
/*
272
/*
268
 * Local variables(smf):
273
 * Local variables(smf):
269
 * eval: (include::add-path-entry "../os-interface" "../library")
274
 * eval: (include::add-path-entry "../os-interface" "../library")