Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – tendra.SVN – Blame – //branches/tendra4/src/utilities/sid/c-out-nl.c – Rev 2

Subversion Repositories tendra.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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