Subversion Repositories tendra.SVN

Rev

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

Rev Author Line No. Line
2 7u83 1
/*
7 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
7 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:-
7 7u83 42
 
2 7u83 43
        (1) Its Recipients shall ensure that this Notice is
44
        reproduced upon any copies or amended versions of it;
7 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;
7 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;
7 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-types.c --- Output type objects.
62
 *
63
 ** Author: Steve Folkes <smf@hermes.mod.uk>
64
 *
65
 *** Commentary:
66
 *
67
 * This file implements the type output routines for C.
68
 *
69
 *** Change Log:
70
 * $Log: c-out-types.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:40  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-types.h"
86
#include "action.h"
87
#include "basic.h"
88
#include "c-code.h"
89
#include "c-out-key.h"
90
#include "entry.h"
91
#include "name.h"
92
#include "output.h"
93
#include "rstack.h"
94
#include "type.h"
95
 
96
/*--------------------------------------------------------------------------*/
97
 
98
static void
7 7u83 99
c_output_param_assign(COutputInfoP info, TypeTupleP inputs)
2 7u83 100
{
7 7u83 101
    OStreamP        ostream = c_out_info_ostream(info);
2 7u83 102
    TypeTupleEntryP ptr;
103
 
104
    for (ptr = inputs->head; ptr; ptr = ptr->next) {
7 7u83 105
	TypeP  type = entry_get_type(ptr->type);
2 7u83 106
	CCodeP code;
107
 
108
	if ((!(ptr->reference)) &&
7 7u83 109
	    ((code = type_get_param_assign_code(type)) != NIL(CCodeP))) {
110
	    KeyP key = entry_key(ptr->type);
2 7u83 111
 
7 7u83 112
	    c_output_key_message(info, "/* BEGINNING OF PARAM ASSIGNMENT: ",
113
				 key, " */", C_INDENT_STEP);
114
	    c_output_open(info, C_INDENT_STEP);
115
	    c_output_location(info, c_code_file(code), c_code_line(code));
116
	    c_output_c_code_param_assign(info, code, ptr->type, ptr->name);
117
	    c_output_location(info, ostream_name(ostream),
118
			      ostream_line(ostream) + 1);
119
	    c_output_close(info, C_INDENT_STEP);
120
	    c_output_key_message(info, "/* END OF PARAM ASSIGNMENT: ",
121
				 key, " */", C_INDENT_STEP);
2 7u83 122
	}
123
    }
124
}
125
 
126
static void
7 7u83 127
c_output_non_ansi_params(COutputInfoP info, TypeTupleP inputs,
128
			 TypeTupleP outputs)
2 7u83 129
{
7 7u83 130
    OStreamP        ostream    = c_out_info_ostream(info);
131
    NStringP        in_prefix  = c_out_info_in_prefix(info);
132
    NStringP        out_prefix = c_out_info_out_prefix(info);
2 7u83 133
    CStringP        sep        = "";
134
    TypeTupleEntryP ptr;
135
 
7 7u83 136
    write_char(ostream, '(');
2 7u83 137
    for (ptr = inputs->head; ptr; ptr = ptr->next) {
7 7u83 138
	write_cstring(ostream, sep);
2 7u83 139
	if ((!(ptr->reference)) &&
7 7u83 140
	    (type_get_assign_code(entry_get_type(ptr->type)) !=
141
	     NIL(GenericP))) {
142
	    c_output_key(info, entry_key(ptr->name), out_prefix);
2 7u83 143
	} else {
7 7u83 144
	    c_output_key(info, entry_key(ptr->name), in_prefix);
2 7u83 145
	}
146
	sep = ", ";
147
    }
148
    for (ptr = outputs->head; ptr; ptr = ptr->next) {
7 7u83 149
	write_cstring(ostream, sep);
150
	c_output_key(info, entry_key(ptr->name), out_prefix);
2 7u83 151
	sep = ", ";
152
    }
7 7u83 153
    write_char(ostream, ')');
2 7u83 154
}
155
 
156
static void
7 7u83 157
c_output_non_ansi_type_defn(COutputInfoP info, TypeTupleP inputs,
158
			    TypeTupleP outputs)
2 7u83 159
{
7 7u83 160
    OStreamP        ostream    = c_out_info_ostream(info);
161
    NStringP        in_prefix  = c_out_info_in_prefix(info);
162
    NStringP        out_prefix = c_out_info_out_prefix(info);
2 7u83 163
    BoolT           specials   = FALSE;
164
    TypeTupleEntryP ptr;
165
 
7 7u83 166
    c_output_non_ansi_params(info, inputs, outputs);
167
    write_newline(ostream);
2 7u83 168
    for (ptr = inputs->head; ptr; ptr = ptr->next) {
7 7u83 169
	output_indent(c_out_info_info(info), C_INDENT_FOR_PARAM);
170
	c_output_mapped_key(info, ptr->type);
171
	write_char(ostream, ' ');
2 7u83 172
	if (ptr->reference) {
7 7u83 173
	    write_char(ostream, '*');
174
	    c_output_key(info, entry_key(ptr->name), in_prefix);
175
	} else if (type_get_assign_code(entry_get_type(ptr->type)) !=
176
		   NIL(GenericP)) {
177
	    write_char(ostream, '*');
178
	    c_output_key(info, entry_key(ptr->name), out_prefix);
2 7u83 179
	    specials = TRUE;
180
	} else {
7 7u83 181
	    c_output_key(info, entry_key(ptr->name), in_prefix);
2 7u83 182
	}
7 7u83 183
	write_char(ostream, ';');
184
	write_newline(ostream);
2 7u83 185
    }
186
    for (ptr = outputs->head; ptr; ptr = ptr->next) {
7 7u83 187
	output_indent(c_out_info_info(info), C_INDENT_FOR_PARAM);
188
	c_output_mapped_key(info, ptr->type);
189
	write_cstring(ostream, " *");
190
	c_output_key(info, entry_key(ptr->name), out_prefix);
191
	write_char(ostream, ';');
192
	write_newline(ostream);
2 7u83 193
    }
7 7u83 194
    write_char(ostream, '{');
195
    write_newline(ostream);
2 7u83 196
    if (specials) {
197
	for (ptr = inputs->head; ptr; ptr = ptr->next) {
198
	    if ((!(ptr->reference)) &&
7 7u83 199
		(type_get_assign_code(entry_get_type(ptr->type)) !=
200
		 NIL(GenericP))) {
201
		output_indent(c_out_info_info(info), C_INDENT_STEP);
202
		c_output_mapped_key(info, ptr->type);
203
		write_char(ostream, ' ');
204
		c_output_key(info, entry_key(ptr->name), in_prefix);
205
		write_char(ostream, ';');
206
		write_newline(ostream);
2 7u83 207
	    }
208
	}
209
    }
210
    if (outputs->head) {
211
	for (ptr = outputs->head; ptr; ptr = ptr->next) {
7 7u83 212
	    output_indent(c_out_info_info(info), C_INDENT_STEP);
213
	    c_output_mapped_key(info, ptr->type);
214
	    write_char(ostream, ' ');
215
	    c_output_key(info, entry_key(ptr->name), in_prefix);
216
	    write_char(ostream, ';');
217
	    write_newline(ostream);
2 7u83 218
	}
219
    }
7 7u83 220
    if (specials || (outputs->head != NIL(TypeTupleEntryP))) {
221
	write_newline(ostream);
2 7u83 222
    }
223
    if (specials) {
7 7u83 224
	c_output_param_assign(info, inputs);
2 7u83 225
    }
226
}
227
 
228
static void
7 7u83 229
c_output_ansi_type_defn(COutputInfoP info, TypeTupleP inputs,
230
			TypeTupleP outputs)
2 7u83 231
{
7 7u83 232
    OStreamP        ostream    = c_out_info_ostream(info);
233
    NStringP        in_prefix  = c_out_info_in_prefix(info);
234
    NStringP        out_prefix = c_out_info_out_prefix(info);
2 7u83 235
    CStringP        sep        = "";
236
    BoolT           specials   = FALSE;
237
    TypeTupleEntryP ptr;
238
 
7 7u83 239
    if ((inputs->head == NIL(TypeTupleEntryP)) &&
240
	(outputs->head == NIL(TypeTupleEntryP))) {
241
	    write_cstring(ostream, "(void)");
2 7u83 242
    } else {
7 7u83 243
	write_char(ostream, '(');
2 7u83 244
	for (ptr = inputs->head; ptr; ptr = ptr->next) {
7 7u83 245
	    write_cstring(ostream, sep);
246
	    c_output_mapped_key(info, ptr->type);
247
	    write_char(ostream, ' ');
2 7u83 248
	    if (ptr->reference) {
7 7u83 249
		write_char(ostream, '*');
250
		c_output_key(info, entry_key(ptr->name), in_prefix);
251
	    } else if (type_get_assign_code(entry_get_type(ptr->type)) !=
252
		       NIL(GenericP)) {
253
		write_char(ostream, '*');
254
		c_output_key(info, entry_key(ptr->name), out_prefix);
2 7u83 255
		specials = TRUE;
256
	    } else {
7 7u83 257
		c_output_key(info, entry_key(ptr->name), in_prefix);
2 7u83 258
	    }
7 7u83 259
	    sep = ", ";
2 7u83 260
	}
261
	for (ptr = outputs->head; ptr; ptr = ptr->next) {
7 7u83 262
	    write_cstring(ostream, sep);
263
	    c_output_mapped_key(info, ptr->type);
264
	    write_cstring(ostream, " *");
265
	    c_output_key(info, entry_key(ptr->name), out_prefix);
266
	    sep = ", ";
2 7u83 267
	}
7 7u83 268
	write_char(ostream, ')');
2 7u83 269
    }
7 7u83 270
    write_newline(ostream);
271
    write_char(ostream, '{');
272
    write_newline(ostream);
2 7u83 273
    if (specials) {
274
	for (ptr = inputs->head; ptr; ptr = ptr->next) {
275
	    if ((!(ptr->reference)) &&
7 7u83 276
		(type_get_assign_code(entry_get_type(ptr->type)) !=
277
		 NIL(GenericP))) {
278
		output_indent(c_out_info_info(info), C_INDENT_STEP);
279
		c_output_mapped_key(info, ptr->type);
280
		write_char(ostream, ' ');
281
		c_output_key(info, entry_key(ptr->name), in_prefix);
282
		write_char(ostream, ';');
283
		write_newline(ostream);
2 7u83 284
	    }
285
	}
286
    }
287
    if (outputs->head) {
288
	for (ptr = outputs->head; ptr; ptr = ptr->next) {
7 7u83 289
	    output_indent(c_out_info_info(info), C_INDENT_STEP);
290
	    c_output_mapped_key(info, ptr->type);
291
	    write_char(ostream, ' ');
292
	    c_output_key(info, entry_key(ptr->name), in_prefix);
293
	    write_char(ostream, ';');
294
	    write_newline(ostream);
2 7u83 295
	}
296
    }
7 7u83 297
    if (specials || (outputs->head != NIL(TypeTupleEntryP))) {
298
	write_newline(ostream);
2 7u83 299
    }
300
    if (specials) {
7 7u83 301
	c_output_param_assign(info, inputs);
2 7u83 302
    }
303
}
304
 
305
static EntryP
7 7u83 306
types_get_entry(EntryP entry, SaveRStackP state, EntryP *type_ref,
307
		BoolT *reference_ref)
2 7u83 308
{
309
    EntryP trans_entry;
310
 
7 7u83 311
    trans_entry = rstack_get_translation(state, entry, type_ref,
312
					 reference_ref);
313
    if ((trans_entry == NIL(EntryP)) && (entry_is_non_local(entry))) {
2 7u83 314
	trans_entry    = entry;
7 7u83 315
	*type_ref      = entry_get_non_local(entry);
2 7u83 316
	*reference_ref = FALSE;
317
    }
7 7u83 318
    ASSERT(trans_entry);
319
    return(trans_entry);
2 7u83 320
}
321
 
322
static KeyP
7 7u83 323
types_get_key(EntryP entry, SaveRStackP state, EntryP *type_ref,
324
	      BoolT *reference_ref)
2 7u83 325
{
7 7u83 326
    EntryP trans = types_get_entry(entry, state, type_ref, reference_ref);
2 7u83 327
 
7 7u83 328
    return(entry_key(trans));
2 7u83 329
}
330
 
331
/*--------------------------------------------------------------------------*/
332
 
333
void
7 7u83 334
c_output_assign(COutputInfoP info, EntryP in_entry, EntryP out_entry,
335
		SaveRStackP in_state, SaveRStackP out_state, unsigned indent)
2 7u83 336
{
7 7u83 337
    OStreamP ostream  = c_out_info_ostream(info);
2 7u83 338
    EntryP   in_type;
339
    EntryP   out_type;
340
    BoolT    in_reference;
341
    BoolT    out_reference;
7 7u83 342
    EntryP   in_name  = types_get_entry(in_entry, in_state, &in_type,
343
					&in_reference);
344
    EntryP   out_name = types_get_entry(out_entry, out_state, &out_type,
345
					&out_reference);
2 7u83 346
 
7 7u83 347
    ASSERT(in_type == out_type);
2 7u83 348
    if (in_name != out_name) {
7 7u83 349
	TypeP  type = entry_get_type(in_type);
2 7u83 350
	CCodeP code;
351
 
7 7u83 352
	if ((code = type_get_assign_code(type)) != NIL(CCodeP)) {
353
	    KeyP key = entry_key(in_type);
2 7u83 354
 
355
	    c_output_key_message (info, "/* BEGINNING OF ASSIGNMENT: ", key,
356
				  " */", indent);
7 7u83 357
	    c_output_open(info, indent);
358
	    c_output_location(info, c_code_file(code), c_code_line(code));
359
	    c_output_c_code_assign(info, code, in_type, in_name, out_name,
360
				   in_reference, out_reference);
361
	    c_output_location(info, ostream_name(ostream),
362
			      ostream_line(ostream) + 1);
363
	    c_output_close(info, indent);
2 7u83 364
	    c_output_key_message (info, "/* END OF ASSIGNMENT: ", key, " */",
365
				  indent);
366
	} else {
7 7u83 367
	    KeyP     in_key    = entry_key(in_name);
368
	    KeyP     out_key   = entry_key(out_name);
369
	    NStringP in_prefix = c_out_info_in_prefix(info);
2 7u83 370
 
7 7u83 371
	    output_indent(c_out_info_info(info), indent);
2 7u83 372
	    if (out_reference) {
7 7u83 373
		write_char(ostream, '*');
2 7u83 374
	    }
7 7u83 375
	    c_output_key(info, out_key, in_prefix);
376
	    write_cstring(ostream, " = ");
2 7u83 377
	    if (in_reference) {
7 7u83 378
		write_char(ostream, '*');
2 7u83 379
	    }
7 7u83 380
	    c_output_key(info, in_key, in_prefix);
381
	    write_char(ostream, ';');
382
	    write_newline(ostream);
2 7u83 383
	}
384
    }
385
}
386
 
387
void
7 7u83 388
c_output_type_decl(COutputInfoP info, TypeTupleP inputs, TypeTupleP outputs)
2 7u83 389
{
7 7u83 390
    OStreamP ostream = c_out_info_ostream(info);
2 7u83 391
 
7 7u83 392
    if (c_out_info_get_prototypes(info)) {
2 7u83 393
	CStringP        sep  = "";
394
	TypeTupleEntryP ptr;
395
 
7 7u83 396
	write_char(ostream, '(');
2 7u83 397
	for (ptr = inputs->head; ptr; ptr = ptr->next) {
7 7u83 398
	    write_cstring(ostream, sep);
399
	    c_output_mapped_key(info, ptr->type);
2 7u83 400
	    if ((ptr->reference) ||
7 7u83 401
		(type_get_assign_code(entry_get_type(ptr->type)) !=
402
		 NIL(GenericP))) {
403
		write_cstring(ostream, " *");
2 7u83 404
	    }
405
	    sep = ", ";
406
	}
407
	for (ptr = outputs->head; ptr; ptr = ptr->next) {
7 7u83 408
	    write_cstring(ostream, sep);
409
	    c_output_mapped_key(info, ptr->type);
410
	    write_cstring(ostream, " *");
2 7u83 411
	    sep = ", ";
412
	}
7 7u83 413
	if ((inputs->head == NIL(TypeTupleEntryP)) &&
414
	   (outputs->head == NIL(TypeTupleEntryP))) {
415
	    write_cstring(ostream, "void");
2 7u83 416
	}
7 7u83 417
	write_char(ostream, ')');
2 7u83 418
    } else {
7 7u83 419
	write_cstring(ostream, " ()");
2 7u83 420
    }
421
}
422
 
423
void
7 7u83 424
c_output_type_defn(COutputInfoP info, TypeTupleP inputs, TypeTupleP outputs)
2 7u83 425
{
7 7u83 426
    if (c_out_info_get_prototypes(info)) {
427
	c_output_ansi_type_defn(info, inputs, outputs);
2 7u83 428
    } else {
7 7u83 429
	c_output_non_ansi_type_defn(info, inputs, outputs);
2 7u83 430
    }
431
}
432
 
433
void
7 7u83 434
c_output_result_assign(COutputInfoP info, TypeTupleP outputs, unsigned indent)
2 7u83 435
{
7 7u83 436
    OStreamP        ostream    = c_out_info_ostream(info);
437
    NStringP        in_prefix  = c_out_info_in_prefix(info);
438
    NStringP        out_prefix = c_out_info_out_prefix(info);
2 7u83 439
    TypeTupleEntryP ptr;
440
 
441
    for (ptr = outputs->head; ptr; ptr = ptr->next) {
7 7u83 442
	TypeP  type = entry_get_type(ptr->type);
2 7u83 443
	CCodeP code;
444
 
7 7u83 445
	if ((code = type_get_result_assign_code(type)) != NIL(CCodeP)) {
446
	    KeyP key = entry_key(ptr->type);
2 7u83 447
 
448
	    c_output_key_message (info, "/* BEGINNING OF RESULT ASSIGNMENT: ",
449
				  key, " */", indent);
7 7u83 450
	    c_output_open(info, indent);
451
	    c_output_location(info, c_code_file(code), c_code_line(code));
452
	    c_output_c_code_result_assign(info, code, ptr->type, ptr->name);
453
	    c_output_location(info, ostream_name(ostream),
454
			      ostream_line(ostream) + 1);
455
	    c_output_close(info, indent);
2 7u83 456
	    c_output_key_message (info, "/* END OF RESULT ASSIGNMENT: ", key,
457
				  " */", indent);
458
	} else {
7 7u83 459
	    output_indent(c_out_info_info(info), indent);
460
	    write_char(ostream, '*');
461
	    c_output_key(info, entry_key(ptr->name), out_prefix);
462
	    write_cstring(ostream, " = ");
463
	    c_output_key(info, entry_key(ptr->name), in_prefix);
464
	    write_char(ostream, ';');
465
	    write_newline(ostream);
2 7u83 466
	}
467
    }
468
}
469
 
470
void
7 7u83 471
c_output_alt_names(COutputInfoP info, TypeTupleP names, TypeTupleP exclude,
472
		   SaveRStackP state, unsigned indent)
2 7u83 473
{
7 7u83 474
    OStreamP        ostream   = c_out_info_ostream(info);
475
    NStringP        in_prefix = c_out_info_in_prefix(info);
2 7u83 476
    BoolT           want_nl   = FALSE;
477
    TypeTupleEntryP ptr;
478
 
479
    for (ptr = names->head; ptr; ptr = ptr->next) {
7 7u83 480
	if (!types_contains(exclude, ptr->name)) {
2 7u83 481
	    EntryP type;
482
	    BoolT  reference;
483
 
7 7u83 484
	    output_indent(c_out_info_info(info), indent);
485
	    c_output_mapped_key(info, ptr->type);
486
	    write_char(ostream, ' ');
487
	    c_output_key(info, types_get_key(ptr->name, state, &type,
488
					     &reference), in_prefix);
489
	    ASSERT((type == ptr->type) && (!reference));
490
	    write_char(ostream, ';');
491
	    write_newline(ostream);
2 7u83 492
	    want_nl = TRUE;
493
	}
494
    }
495
    if (want_nl) {
7 7u83 496
	write_newline(ostream);
2 7u83 497
    }
498
}
499
 
500
void
7 7u83 501
c_output_rule_params(COutputInfoP info, TypeTupleP inputs,
502
		     TypeTupleP outputs, SaveRStackP state)
2 7u83 503
{
7 7u83 504
    OStreamP        ostream   = c_out_info_ostream(info);
505
    NStringP        in_prefix = c_out_info_in_prefix(info);
2 7u83 506
    CStringP        sep       = "";
507
    TypeTupleEntryP ptr;
508
 
509
    for (ptr = inputs->head; ptr; ptr = ptr->next) {
7 7u83 510
	TypeP  type = entry_get_type(ptr->type);
511
	CCodeP code = type_get_param_assign_code(type);
2 7u83 512
	EntryP type_entry;
513
	BoolT  reference;
7 7u83 514
	KeyP   key  = types_get_key(ptr->name, state, &type_entry,
2 7u83 515
				     &reference);
516
 
7 7u83 517
	write_cstring(ostream, sep);
2 7u83 518
	if ((ptr->reference && (!reference)) ||
7 7u83 519
	    ((!ptr->reference) && (!reference) && (code != NIL(CCodeP)))) {
520
	    write_char(ostream, '&');
521
	} else if ((!ptr->reference) && reference && (code == NIL(CCodeP))) {
522
	    write_char(ostream, '*');
2 7u83 523
	}
7 7u83 524
	c_output_key(info, key, in_prefix);
2 7u83 525
	sep = ", ";
526
    }
527
    for (ptr = outputs->head; ptr; ptr = ptr->next) {
528
	EntryP type_entry;
529
	BoolT  reference;
530
 
7 7u83 531
	write_cstring(ostream, sep);
532
	write_char(ostream, '&');
533
	c_output_key(info, types_get_key(ptr->name, state, &type_entry,
534
					 &reference), in_prefix);
535
	ASSERT((type_entry == ptr->type) && (!reference));
2 7u83 536
	sep = ", ";
537
    }
538
}
539
 
540
void
7 7u83 541
c_output_rename(COutputInfoP info, TypeTupleP inputs, TypeTupleP outputs,
542
		SaveRStackP state, unsigned indent)
2 7u83 543
{
544
    TypeTupleEntryP in_ptr  = inputs->head;
545
    TypeTupleEntryP out_ptr = outputs->head;
546
 
547
    while (in_ptr) {
7 7u83 548
	ASSERT(out_ptr);
549
	c_output_assign(info, in_ptr->name, out_ptr->name, state, state,
550
			indent);
2 7u83 551
	in_ptr  = in_ptr->next;
552
	out_ptr = out_ptr->next;
553
    }
7 7u83 554
    ASSERT(out_ptr == NIL(TypeTupleEntryP));
2 7u83 555
}
556
 
557
void
7 7u83 558
c_output_tail_decls(COutputInfoP info, TypeTupleP inputs, SaveRStackP in_state,
559
		    TypeTupleP outputs, SaveRStackP out_state, unsigned indent)
2 7u83 560
{
561
    TypeTupleEntryP in_ptr  = inputs->head;
562
    TypeTupleEntryP out_ptr = outputs->head;
563
 
564
    while (in_ptr) {
7 7u83 565
	ASSERT(out_ptr);
566
	c_output_assign(info, in_ptr->name, out_ptr->name, in_state,
567
			out_state, indent);
2 7u83 568
	in_ptr  = in_ptr->next;
569
	out_ptr = out_ptr->next;
570
    }
7 7u83 571
    ASSERT(out_ptr == NIL(TypeTupleEntryP));
2 7u83 572
}
573
 
574
BoolT
7 7u83 575
c_output_required_copies(COutputInfoP info, TypeTupleP param, TypeTupleP args,
576
			 RStackP rstack, SaveRStackP astate, unsigned indent,
577
			 TableP table)
2 7u83 578
{
7 7u83 579
    OStreamP        ostream   = c_out_info_ostream(info);
580
    NStringP        in_prefix = c_out_info_in_prefix(info);
2 7u83 581
    TypeTupleEntryP ptr       = param->head;
582
    TypeTupleEntryP aptr      = args->head;
583
    BoolT           copies    = FALSE;
584
    SaveRStackT     state;
585
 
7 7u83 586
    rstack_save_state(rstack, &state);
2 7u83 587
    while (ptr) {
7 7u83 588
	ASSERT(aptr);
2 7u83 589
	if (ptr->mutated && (!ptr->reference)) {
7 7u83 590
	    EntryP entry = table_add_generated_name(table);
2 7u83 591
 
7 7u83 592
	    output_indent(c_out_info_info(info), indent);
593
	    c_output_mapped_key(info, ptr->type);
594
	    write_char(ostream, ' ');
595
	    c_output_key(info, entry_key(entry), in_prefix);
596
	    write_char(ostream, ';');
597
	    write_newline(ostream);
2 7u83 598
	    copies = TRUE;
7 7u83 599
	    rstack_add_translation(rstack, aptr->name, entry, aptr->type,
600
				   FALSE);
601
	    rstack_add_translation(rstack, entry, entry, aptr->type, FALSE);
2 7u83 602
	}
603
	ptr  = ptr->next;
604
	aptr = aptr->next;
605
    }
7 7u83 606
    ASSERT(aptr == NIL(TypeTupleEntryP));
2 7u83 607
    if (copies) {
7 7u83 608
	write_newline(ostream);
2 7u83 609
	for (aptr = args->head, ptr = param->head; ptr;
610
	     ptr = ptr->next, aptr = aptr->next) {
7 7u83 611
	    ASSERT(aptr);
2 7u83 612
	    if (ptr->mutated && (!ptr->reference)) {
613
		EntryP type;
614
		BoolT  reference;
7 7u83 615
		EntryP entry = rstack_get_translation(&state, aptr->name,
616
						      &type, &reference);
2 7u83 617
 
7 7u83 618
		ASSERT(entry);
619
		c_output_assign(info, aptr->name, entry, astate, &state,
620
				indent);
2 7u83 621
	    }
622
	}
7 7u83 623
	ASSERT(aptr == NIL(TypeTupleEntryP));
2 7u83 624
    }
7 7u83 625
    return(copies);
2 7u83 626
}
627
 
628
/*
629
 * Local variables(smf):
630
 * eval: (include::add-path-entry "../os-interface" "../library")
631
 * eval: (include::add-path-entry "../transforms" "../output" "../generated")
632
 * end:
633
**/