Subversion Repositories tendra.SVN

Rev

Rev 5 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
6 7u83 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
 */
31
/*
2 7u83 32
    		 Crown Copyright (c) 1997
6 7u83 33
 
2 7u83 34
    This TenDRA(r) Computer Program is subject to Copyright
35
    owned by the United Kingdom Secretary of State for Defence
36
    acting through the Defence Evaluation and Research Agency
37
    (DERA).  It is made available to Recipients with a
38
    royalty-free licence for its use, reproduction, transfer
39
    to other parties and amendment for any purpose not excluding
40
    product development provided that any such use et cetera
41
    shall be deemed to be acceptance of the following conditions:-
6 7u83 42
 
2 7u83 43
        (1) Its Recipients shall ensure that this Notice is
44
        reproduced upon any copies or amended versions of it;
6 7u83 45
 
2 7u83 46
        (2) Any amended version of it shall be clearly marked to
47
        show both the nature of and the organisation responsible
48
        for the relevant amendment or amendments;
6 7u83 49
 
2 7u83 50
        (3) Its onward transfer from a recipient to another
51
        party shall be deemed to be that party's acceptance of
52
        these conditions;
6 7u83 53
 
2 7u83 54
        (4) DERA gives no warranty or assurance as to its
55
        quality or suitability for any purpose and DERA accepts
56
        no liability whatsoever in relation to any use to which
57
        it may be put.
58
*/
59
 
60
 
61
/*** c-out-nl.c --- Output of non local name list ADT objects.
62
 *
63
 ** Author: Steve Folkes <smf@hermes.mod.uk>
64
 *
65
 *** Commentary:
66
 *
67
 * This file implements the non local name list output routines used by SID.
68
 *
69
 *** Change Log:
70
 * $Log: c-out-nl.c,v $
71
 * Revision 1.1.1.1  1998/01/17  15:57:43  release
72
 * First version to be checked into rolling release.
73
 *
74
 * Revision 1.2  1994/12/15  09:56:34  smf
75
 * Brought into line with OSSG C Coding Standards Document, as per
76
 * "CR94_178.sid+tld-update".
77
 *
78
 * Revision 1.1.1.1  1994/07/25  16:04:20  smf
79
 * Initial import of SID 1.8 non shared files.
80
 *
81
**/
82
 
83
/****************************************************************************/
84
 
85
#include "c-out-nl.h"
86
#include "action.h"
87
#include "c-code.h"
88
#include "c-out-key.h"
89
#include "c-out-types.h"
90
 
91
/*--------------------------------------------------------------------------*/
92
 
93
typedef struct NonLocalClosureT {
94
    COutputInfoP	info;
95
    SaveRStackP		state;
96
    unsigned		indent;
97
} NonLocalClosureT, *NonLocalClosureP;
98
 
99
/*--------------------------------------------------------------------------*/
100
 
101
static void
6 7u83 102
c_output_save_non_locals_1(COutputInfoP info, NonLocalEntryP non_local,
103
			   SaveRStackP non_local_state, RStackP rstack,
104
			   RuleP handler_rule, TableP table, unsigned indent)
2 7u83 105
{
6 7u83 106
    OStreamP ostream = c_out_info_ostream(info);
107
    EntryP   entry   = non_local_entry_get_initialiser(non_local);
2 7u83 108
 
109
    if (entry) {
110
	EntryP      type;
111
	BoolT       reference;
6 7u83 112
	EntryP      translation = rstack_get_translation(non_local_state,
113
							 non_local->name,
114
							 &type, &reference);
115
	KeyP        key         = entry_key(entry);
116
	ActionP     action      = entry_get_action(entry);
117
	TypeTupleP  param       = action_param(action);
118
	CCodeP      code        = action_get_code(action);
2 7u83 119
	BoolT       copies;
120
	TypeTupleT  args;
121
	TypeTupleT  result_args;
122
	SaveRStackT state;
123
 
124
	c_output_key_message (info, "/* BEGINNING OF INITIALISER: ", key,
125
			      " */", indent);
6 7u83 126
	c_output_open(info, indent);
127
	rstack_save_state(rstack, &state);
128
	rstack_push_frame(rstack);
129
	types_init(&args);
130
	if (!types_equal_zero_tuple(param)) {
131
	    types_add_name_and_type(&args, translation, type, reference);
2 7u83 132
	}
6 7u83 133
	types_init(&result_args);
134
	types_add_name_and_type(&result_args, non_local->name, type, FALSE);
135
	copies = c_output_required_copies(info, c_code_param(code),
136
					  &args, rstack, &state,
137
					  indent + C_INDENT_STEP, table);
2 7u83 138
	if (copies) {
6 7u83 139
	    c_output_open(info, indent + C_INDENT_STEP);
2 7u83 140
	}
6 7u83 141
	rstack_save_state(rstack, &state);
142
	c_output_location(info, c_code_file(code), c_code_line(code));
143
	c_output_c_code_action(info, code, &args, &result_args, &state,
144
			       handler_rule);
145
	c_output_location(info, ostream_name(ostream),
146
			  ostream_line(ostream) + 1);
147
	rstack_pop_frame(rstack);
2 7u83 148
	if (copies) {
6 7u83 149
	    c_output_close(info, indent + C_INDENT_STEP);
2 7u83 150
	}
6 7u83 151
	c_output_close(info, indent);
2 7u83 152
	c_output_key_message (info, "/* END OF INITIALISER: ", key, " */",
153
			      indent);
6 7u83 154
	types_destroy(&result_args);
155
	types_destroy(&args);
2 7u83 156
    }
157
}
158
 
159
static void
6 7u83 160
c_output_restore_non_locals_1(EntryP from, EntryP to, GenericP gclosure)
2 7u83 161
{
6 7u83 162
    NonLocalClosureP closure = (NonLocalClosureP)gclosure;
2 7u83 163
    COutputInfoP     info    = closure->info;
164
    SaveRStackP      state   = closure->state;
165
    unsigned         indent  = closure->indent;
166
 
6 7u83 167
    c_output_assign(info, to, from, state, state, indent);
2 7u83 168
}
169
 
170
/*--------------------------------------------------------------------------*/
171
 
172
void
6 7u83 173
c_output_non_locals(COutputInfoP info, NonLocalListP non_locals)
2 7u83 174
{
6 7u83 175
    OStreamP       ostream = c_out_info_ostream(info);
2 7u83 176
    NonLocalEntryP non_local;
177
 
178
    for (non_local = non_locals->head; non_local;
179
	 non_local = non_local->next) {
6 7u83 180
	if (!c_out_info_get_split(info)) {
181
	    write_cstring(ostream, "static ");
2 7u83 182
	}
6 7u83 183
	c_output_mapped_key(info, non_local->type);
184
	write_char(ostream, ' ');
185
	c_output_mapped_key(info, non_local->name);
186
	write_char(ostream, ';');
187
	write_newline(ostream);
2 7u83 188
    }
189
}
190
 
191
void
6 7u83 192
c_output_declare_non_locals(COutputInfoP info, NonLocalListP non_locals)
2 7u83 193
{
6 7u83 194
    OStreamP       ostream = c_out_info_ostream(info);
2 7u83 195
    NonLocalEntryP non_local;
196
 
197
    for (non_local = non_locals->head; non_local;
198
	 non_local = non_local->next) {
6 7u83 199
	write_cstring(ostream, "extern ");
200
	c_output_mapped_key(info, non_local->type);
201
	write_char(ostream, ' ');
202
	c_output_mapped_key(info, non_local->name);
203
	write_char(ostream, ';');
204
	write_newline(ostream);
2 7u83 205
    }
206
}
207
 
208
void
6 7u83 209
c_output_save_non_locals(COutputInfoP info, RuleP rule, unsigned indent,
210
			 RStackP rstack, RStackP non_local_stack,
211
			 RuleP handler_rule, TableP table)
2 7u83 212
{
6 7u83 213
    OStreamP       ostream    = c_out_info_ostream(info);
214
    NStringP       in_prefix  = c_out_info_in_prefix(info);
215
    NonLocalListP  non_locals = rule_non_locals(rule);
2 7u83 216
    NonLocalEntryP non_local;
217
    SaveRStackT    state;
218
    SaveRStackT    non_local_state;
219
 
220
    for (non_local = non_locals->head; non_local;
221
	 non_local = non_local->next) {
6 7u83 222
	EntryP entry = table_add_generated_name(table);
2 7u83 223
 
6 7u83 224
	output_indent(c_out_info_info(info), indent);
225
	c_output_mapped_key(info, non_local->type);
226
	write_char(ostream, ' ');
227
	c_output_key(info, entry_key(entry), in_prefix);
228
	write_newline(ostream);
229
	rstack_add_translation(non_local_stack, non_local->name, entry,
230
			       non_local->type, FALSE);
231
	rstack_add_translation(rstack, entry, entry, non_local->type, FALSE);
2 7u83 232
    }
6 7u83 233
    write_newline(ostream);
234
    rstack_save_state(rstack, &state);
235
    rstack_save_state(non_local_stack, &non_local_state);
2 7u83 236
    for (non_local = non_locals->head; non_local;
237
	 non_local = non_local->next) {
238
	EntryP type;
239
	BoolT  reference;
6 7u83 240
	EntryP entry = rstack_get_translation(&non_local_state,
241
					      non_local->name, &type,
242
					      &reference);
2 7u83 243
 
6 7u83 244
	ASSERT((entry != NIL(EntryP)) && (type == non_local->type) &&
245
	       (!reference));
246
	c_output_assign(info, non_local->name, entry, &state, &state, indent);
2 7u83 247
    }
248
    for (non_local = non_locals->head; non_local;
249
	 non_local = non_local->next) {
6 7u83 250
	c_output_save_non_locals_1(info, non_local, &non_local_state,
251
				   rstack, handler_rule, table, indent);
2 7u83 252
    }
6 7u83 253
    rstack_save_state(non_local_stack, rule_non_local_state(rule));
2 7u83 254
}
255
 
256
void
6 7u83 257
c_output_restore_non_locals(COutputInfoP info, RuleP rule, unsigned indent,
258
			    RStackP rstack, RStackP non_local_stack)
2 7u83 259
{
260
    NonLocalClosureT closure;
261
    SaveRStackT      state;
262
 
6 7u83 263
    rstack_save_state(rstack, &state);
2 7u83 264
    closure.info   = info;
265
    closure.state  = &state;
266
    closure.indent = indent;
6 7u83 267
    rstack_apply_for_non_locals(non_local_stack, rule_non_local_state(rule),
268
				c_output_restore_non_locals_1,
269
				(GenericP) &closure);
2 7u83 270
}
271
 
272
/*
273
 * Local variables(smf):
274
 * eval: (include::add-path-entry "../os-interface" "../library")
275
 * eval: (include::add-path-entry "../transforms" "../output" "../generated")
276
 * end:
277
**/