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 63... Line 93...
63
#include "c-out-key.h"
93
#include "c-out-key.h"
64
#include "c-output.h"
94
#include "c-output.h"
65
#include "gen-errors.h"
95
#include "gen-errors.h"
66
#include "name.h"
96
#include "name.h"
67
 
97
 
68
/*--------------------------------------------------------------------------*/
98
/*--------------------------------------------------------------------------*/
69
 
99
 
70
static void
100
static void
71
c_code_set_labels PROTO_N ((code))
101
c_code_set_labels(CCodeP code)
72
		  PROTO_T (CCodeP code)
-
 
73
{
102
{
74
    CCodeItemP item;
103
    CCodeItemP item;
75
 
104
 
76
    for (item = code->head; item; item = item->next) {
105
    for (item = code->head; item; item = item->next) {
77
	if (item->type == CCT_LABEL) {
106
	if (item->type == CCT_LABEL) {
78
	    NameP name = entry_get_name (item->u.ident);
107
	    NameP name = entry_get_name(item->u.ident);
79
 
108
 
80
	    if (!name_has_label (name)) {
109
	    if (!name_has_label(name)) {
81
		name_set_label (name, c_out_next_label ());
110
		name_set_label(name, c_out_next_label());
82
	    }
111
	    }
83
	}
112
	}
84
    }
113
    }
85
}
114
}
86
 
115
 
87
static void
116
static void
88
c_code_reset_labels PROTO_N ((code))
117
c_code_reset_labels(CCodeP code)
89
		    PROTO_T (CCodeP code)
-
 
90
{
118
{
91
    CCodeItemP item;
119
    CCodeItemP item;
92
 
120
 
93
    for (item = code->head; item; item = item->next) {
121
    for (item = code->head; item; item = item->next) {
94
	if (item->type == CCT_LABEL) {
122
	if (item->type == CCT_LABEL) {
95
	    NameP name = entry_get_name (item->u.ident);
123
	    NameP name = entry_get_name(item->u.ident);
96
 
124
 
97
	    name_reset_label (name);
125
	    name_reset_label(name);
98
	}
126
	}
99
    }
127
    }
100
}
128
}
101
 
129
 
102
static EntryP
130
static EntryP
103
c_code_get_translation PROTO_N ((state, translator, ident, type_ref,
131
c_code_get_translation(SaveRStackP state, TypeBTransP translator, EntryP ident,
104
			      reference_ref, entry_ref))
132
		       EntryP *type_ref, BoolT *reference_ref,
105
		       PROTO_T (SaveRStackP state X
-
 
106
				TypeBTransP translator X
-
 
107
				EntryP      ident X
-
 
108
				EntryP     *type_ref X
-
 
109
				BoolT      *reference_ref X
-
 
110
				EntryP     *entry_ref)
133
		       EntryP *entry_ref)
111
{
134
{
112
    EntryP entry = btrans_get_translation (translator, ident);
135
    EntryP entry = btrans_get_translation(translator, ident);
113
    EntryP stack_entry;
136
    EntryP stack_entry;
114
 
137
 
115
    ASSERT (entry);
138
    ASSERT(entry);
116
    stack_entry = rstack_get_translation (state, entry, type_ref,
139
    stack_entry = rstack_get_translation(state, entry, type_ref,
117
					  reference_ref);
140
					 reference_ref);
118
    if ((stack_entry == NIL (EntryP)) && (entry_is_non_local (entry))) {
141
    if ((stack_entry == NIL(EntryP)) && (entry_is_non_local(entry))) {
119
	stack_entry    = entry;
142
	stack_entry    = entry;
120
	*type_ref      = entry_get_non_local (entry);
143
	*type_ref      = entry_get_non_local(entry);
121
	*reference_ref = FALSE;
144
	*reference_ref = FALSE;
122
    }
145
    }
123
    ASSERT (stack_entry);
146
    ASSERT(stack_entry);
124
    if (entry_ref) {
147
    if (entry_ref) {
125
	*entry_ref = entry;
148
	*entry_ref = entry;
126
    }
149
    }
127
    return (stack_entry);
150
    return(stack_entry);
128
}
151
}
129
 
152
 
130
/*--------------------------------------------------------------------------*/
153
/*--------------------------------------------------------------------------*/
131
 
154
 
132
CCodeP
155
CCodeP
133
c_code_create PROTO_N ((file, line))
156
c_code_create(CStringP file, unsigned line)
134
	      PROTO_T (CStringP file X
-
 
135
		       unsigned line)
-
 
136
{
157
{
137
    CCodeP code = ALLOCATE (CCodeT);
158
    CCodeP code = ALLOCATE(CCodeT);
138
 
159
 
139
    code->head = NIL (CCodeItemP);
160
    code->head = NIL(CCodeItemP);
140
    code->tail = &(code->head);
161
    code->tail = &(code->head);
141
    code->file = file;
162
    code->file = file;
142
    code->line = line;
163
    code->line = line;
143
    types_init (&(code->param));
164
    types_init(&(code->param));
144
    types_init (&(code->result));
165
    types_init(&(code->result));
145
    return (code);
166
    return(code);
146
}
167
}
147
 
168
 
148
void
169
void
149
c_code_append_string PROTO_N ((code, string))
170
c_code_append_string(CCodeP code, NStringP string)
150
		     PROTO_T (CCodeP   code X
-
 
151
			      NStringP string)
-
 
152
{
171
{
153
    CCodeItemP item = ALLOCATE (CCodeItemT);
172
    CCodeItemP item = ALLOCATE(CCodeItemT);
154
 
173
 
155
    item->next    = NIL (CCodeItemP);
174
    item->next    = NIL(CCodeItemP);
156
    item->type    = CCT_STRING;
175
    item->type    = CCT_STRING;
157
    nstring_assign (&(item->u.string), string);
176
    nstring_assign(&(item->u.string), string);
158
    *(code->tail) = item;
177
    *(code->tail) = item;
159
    code->tail    = &(item->next);
178
    code->tail    = &(item->next);
160
}
179
}
161
 
180
 
162
void
181
void
163
c_code_append_label PROTO_N ((code, string))
182
c_code_append_label(CCodeP code, NStringP string)
164
		    PROTO_T (CCodeP   code X
-
 
165
			     NStringP string)
-
 
166
{
183
{
167
    CCodeItemP item = ALLOCATE (CCodeItemT);
184
    CCodeItemP item = ALLOCATE(CCodeItemT);
168
 
185
 
169
    item->next    = NIL (CCodeItemP);
186
    item->next    = NIL(CCodeItemP);
170
    item->type    = CCT_LABEL;
187
    item->type    = CCT_LABEL;
171
    nstring_assign (&(item->u.string), string);
188
    nstring_assign(&(item->u.string), string);
172
    *(code->tail) = item;
189
    *(code->tail) = item;
173
    code->tail    = &(item->next);
190
    code->tail    = &(item->next);
174
}
191
}
175
 
192
 
176
void
193
void
177
c_code_append_identifier PROTO_N ((code, string))
194
c_code_append_identifier(CCodeP code, NStringP string)
178
			 PROTO_T (CCodeP   code X
-
 
179
				  NStringP string)
-
 
180
{
195
{
181
    CCodeItemP item = ALLOCATE (CCodeItemT);
196
    CCodeItemP item = ALLOCATE(CCodeItemT);
182
 
197
 
183
    item->next    = NIL (CCodeItemP);
198
    item->next    = NIL(CCodeItemP);
184
    item->type    = CCT_IDENT;
199
    item->type    = CCT_IDENT;
185
    nstring_assign (&(item->u.string), string);
200
    nstring_assign(&(item->u.string), string);
186
    *(code->tail) = item;
201
    *(code->tail) = item;
187
    code->tail    = &(item->next);
202
    code->tail    = &(item->next);
188
}
203
}
189
 
204
 
190
void
205
void
191
c_code_append_modifiable PROTO_N ((code, string))
206
c_code_append_modifiable(CCodeP code, NStringP string)
192
			 PROTO_T (CCodeP   code X
-
 
193
				  NStringP string)
-
 
194
{
207
{
195
    CCodeItemP item = ALLOCATE (CCodeItemT);
208
    CCodeItemP item = ALLOCATE(CCodeItemT);
196
 
209
 
197
    item->next    = NIL (CCodeItemP);
210
    item->next    = NIL(CCodeItemP);
198
    item->type    = CCT_MOD_IDENT;
211
    item->type    = CCT_MOD_IDENT;
199
    nstring_assign (&(item->u.string), string);
212
    nstring_assign(&(item->u.string), string);
200
    *(code->tail) = item;
213
    *(code->tail) = item;
201
    code->tail    = &(item->next);
214
    code->tail    = &(item->next);
202
}
215
}
203
 
216
 
204
void
217
void
205
c_code_append_reference PROTO_N ((code, string))
218
c_code_append_reference(CCodeP code, NStringP string)
206
			PROTO_T (CCodeP   code X
-
 
207
				 NStringP string)
-
 
208
{
219
{
209
    CCodeItemP item = ALLOCATE (CCodeItemT);
220
    CCodeItemP item = ALLOCATE(CCodeItemT);
210
 
221
 
211
    item->next    = NIL (CCodeItemP);
222
    item->next    = NIL(CCodeItemP);
212
    item->type    = CCT_REF_IDENT;
223
    item->type    = CCT_REF_IDENT;
213
    nstring_assign (&(item->u.string), string);
224
    nstring_assign(&(item->u.string), string);
214
    *(code->tail) = item;
225
    *(code->tail) = item;
215
    code->tail    = &(item->next);
226
    code->tail    = &(item->next);
216
}
227
}
217
 
228
 
218
void
229
void
219
c_code_append_exception PROTO_N ((code))
230
c_code_append_exception(CCodeP code)
220
			PROTO_T (CCodeP code)
-
 
221
{
231
{
222
    CCodeItemP item = ALLOCATE (CCodeItemT);
232
    CCodeItemP item = ALLOCATE(CCodeItemT);
223
 
233
 
224
    item->next    = NIL (CCodeItemP);
234
    item->next    = NIL(CCodeItemP);
225
    item->type    = CCT_EXCEPTION;
235
    item->type    = CCT_EXCEPTION;
226
    *(code->tail) = item;
236
    *(code->tail) = item;
227
    code->tail    = &(item->next);
237
    code->tail    = &(item->next);
228
}
238
}
229
 
239
 
230
void
240
void
231
c_code_append_advance PROTO_N ((code))
241
c_code_append_advance(CCodeP code)
232
		      PROTO_T (CCodeP code)
-
 
233
{
242
{
234
    CCodeItemP item = ALLOCATE (CCodeItemT);
243
    CCodeItemP item = ALLOCATE(CCodeItemT);
235
 
244
 
236
    item->next    = NIL (CCodeItemP);
245
    item->next    = NIL(CCodeItemP);
237
    item->type    = CCT_ADVANCE;
246
    item->type    = CCT_ADVANCE;
238
    *(code->tail) = item;
247
    *(code->tail) = item;
239
    code->tail    = &(item->next);
248
    code->tail    = &(item->next);
240
}
249
}
241
 
250
 
242
void
251
void
243
c_code_append_terminal PROTO_N ((code))
252
c_code_append_terminal(CCodeP code)
244
		       PROTO_T (CCodeP code)
-
 
245
{
253
{
246
    CCodeItemP item = ALLOCATE (CCodeItemT);
254
    CCodeItemP item = ALLOCATE(CCodeItemT);
247
 
255
 
248
    item->next    = NIL (CCodeItemP);
256
    item->next    = NIL(CCodeItemP);
249
    item->type    = CCT_TERMINAL;
257
    item->type    = CCT_TERMINAL;
250
    *(code->tail) = item;
258
    *(code->tail) = item;
251
    code->tail    = &(item->next);
259
    code->tail    = &(item->next);
252
}
260
}
253
 
261
 
254
void
262
void
255
c_code_check PROTO_N ((code, exceptions, param_op, param, result, table))
263
c_code_check(CCodeP code, BoolT exceptions, BoolT param_op, TypeTupleP param,
256
	     PROTO_T (CCodeP     code X
-
 
257
		      BoolT      exceptions X
-
 
258
		      BoolT      param_op X
-
 
259
		      TypeTupleP param X
-
 
260
		      TypeTupleP result X
264
	     TypeTupleP result, TableP table)
261
		      TableP     table)
-
 
262
{
265
{
263
    CCodeItemP item;
266
    CCodeItemP item;
264
    EntryP     entry;
267
    EntryP     entry;
265
 
268
 
266
    for (item = code->head; item; item = item->next) {
269
    for (item = code->head; item; item = item->next) {
267
	switch (item->type) EXHAUSTIVE {
270
	switch (item->type)EXHAUSTIVE {
268
	  case CCT_IDENT:
271
	  case CCT_IDENT:
269
	    entry         = table_add_name (table, &(item->u.string));
272
	    entry         = table_add_name(table, &(item->u.string));
270
	    item->u.ident = entry;
273
	    item->u.ident = entry;
271
	    if (((param == NIL (TypeTupleP)) ||
274
	    if (((param == NIL(TypeTupleP)) ||
272
		 (!types_contains (param, entry))) &&
275
		 (!types_contains(param, entry))) &&
273
		((result == NIL (TypeTupleP)) ||
276
		((result == NIL(TypeTupleP)) ||
274
		 (!types_contains (result, entry)))) {
277
		 (!types_contains(result, entry)))) {
275
		E_bad_id_substitution (c_code_file (code), c_code_line (code),
278
		E_bad_id_substitution(c_code_file(code), c_code_line(code),
276
				       entry);
279
				      entry);
277
	    } else if (result) {
280
	    } else if (result) {
278
		name_used (entry_get_name (entry));
281
		name_used(entry_get_name(entry));
279
	    }
282
	    }
280
	    break;
283
	    break;
281
	  case CCT_MOD_IDENT:
284
	  case CCT_MOD_IDENT:
282
	    entry         = table_add_name (table, &(item->u.string));
285
	    entry         = table_add_name(table, &(item->u.string));
283
	    item->u.ident = entry;
286
	    item->u.ident = entry;
284
	    if (exceptions) {
287
	    if (exceptions) {
285
		if ((param == NIL (TypeTupleP)) ||
288
		if ((param == NIL(TypeTupleP)) ||
286
		    (!types_mutated (param, entry))) {
289
		    (!types_mutated(param, entry))) {
287
		    E_bad_mod_id_substitution (c_code_file (code),
290
		    E_bad_mod_id_substitution(c_code_file(code),
288
					       c_code_line (code), entry);
291
					      c_code_line(code), entry);
289
		}
292
		}
290
	    } else {
293
	    } else {
291
		E_mod_id_in_assign (c_code_file (code), c_code_line (code),
294
		E_mod_id_in_assign(c_code_file(code), c_code_line(code),
292
				    entry);
295
				   entry);
293
	    }
296
	    }
294
	    break;
297
	    break;
295
	  case CCT_REF_IDENT:
298
	  case CCT_REF_IDENT:
296
	    entry         = table_add_name (table, &(item->u.string));
299
	    entry         = table_add_name(table, &(item->u.string));
297
	    item->u.ident = entry;
300
	    item->u.ident = entry;
298
	    if (!param_op) {
301
	    if (!param_op) {
299
		if ((param == NIL (TypeTupleP)) ||
302
		if ((param == NIL(TypeTupleP)) ||
300
		    (!types_contains (param, entry))) {
303
		    (!types_contains(param, entry))) {
301
		    E_bad_ref_id_substitution (c_code_file (code),
304
		    E_bad_ref_id_substitution(c_code_file(code),
302
					       c_code_line (code), entry);
305
					      c_code_line(code), entry);
303
		}
306
		}
304
	    } else {
307
	    } else {
305
		E_ref_id_in_param_op (c_code_file (code), c_code_line (code),
308
		E_ref_id_in_param_op(c_code_file(code), c_code_line(code),
306
				      entry);
309
				     entry);
307
	    }
310
	    }
308
	    break;
311
	    break;
309
	  case CCT_LABEL:
312
	  case CCT_LABEL:
310
	    entry         = table_add_name (table, &(item->u.string));
313
	    entry         = table_add_name(table, &(item->u.string));
311
	    item->u.ident = entry;
314
	    item->u.ident = entry;
312
	    if ((param == NIL (TypeTupleP)) && (result == NIL (TypeTupleP))) {
315
	    if ((param == NIL(TypeTupleP)) && (result == NIL(TypeTupleP))) {
313
		E_bad_label_substitution (c_code_file (code),
316
		E_bad_label_substitution(c_code_file(code),
314
					  c_code_line (code), entry);
317
					 c_code_line(code), entry);
315
	    }
318
	    }
316
	    break;
319
	    break;
317
	  case CCT_EXCEPTION:
320
	  case CCT_EXCEPTION:
318
	    if (!exceptions) {
321
	    if (!exceptions) {
319
		E_bad_exception_substitution (c_code_file (code),
322
		E_bad_exception_substitution(c_code_file(code),
320
					      c_code_line (code));
323
					     c_code_line(code));
321
	    }
324
	    }
322
	    break;
325
	    break;
323
	  case CCT_ADVANCE:
326
	  case CCT_ADVANCE:
324
	    if (!exceptions) {
327
	    if (!exceptions) {
325
		E_bad_advance_substitution (c_code_file (code),
328
		E_bad_advance_substitution(c_code_file(code),
326
					    c_code_line (code));
329
					   c_code_line(code));
327
	    }
330
	    }
328
	    break;
331
	    break;
329
	  case CCT_TERMINAL:
332
	  case CCT_TERMINAL:
330
	    if (!exceptions) {
333
	    if (!exceptions) {
331
		E_bad_terminal_substitution (c_code_file (code),
334
		E_bad_terminal_substitution(c_code_file(code),
332
					     c_code_line (code));
335
					    c_code_line(code));
333
	    }
336
	    }
334
	    break;
337
	    break;
335
	  case CCT_STRING:
338
	  case CCT_STRING:
336
	    break;
339
	    break;
337
	}
340
	}
338
    }
341
    }
339
    if (result) {
342
    if (result) {
340
	types_check_used (result, E_code_undefined_result, (GenericP) code);
343
	types_check_used(result, E_code_undefined_result, (GenericP)code);
341
	for (item = code->head; item; item = item->next) {
344
	for (item = code->head; item; item = item->next) {
342
	    if (item->type == CCT_IDENT) {
345
	    if (item->type == CCT_IDENT) {
343
		name_not_used (entry_get_name (item->u.ident));
346
		name_not_used(entry_get_name(item->u.ident));
344
	    }
347
	    }
345
	}
348
	}
346
    }
349
    }
347
    if (param) {
350
    if (param) {
348
	types_assign (&(code->param), param);
351
	types_assign(&(code->param), param);
349
    }
352
    }
350
    if (result) {
353
    if (result) {
351
	types_assign (&(code->result), result);
354
	types_assign(&(code->result), result);
352
    }
355
    }
353
}
356
}
354
 
357
 
355
#ifdef FS_FAST
358
#ifdef FS_FAST
356
#undef c_code_file
359
#undef c_code_file
357
#endif /* defined (FS_FAST) */
360
#endif /* defined (FS_FAST) */
358
CStringP
361
CStringP
359
c_code_file PROTO_N ((code))
362
c_code_file(CCodeP code)
360
	    PROTO_T (CCodeP code)
-
 
361
{
363
{
362
    return (code->file);
364
    return(code->file);
363
}
365
}
364
#ifdef FS_FAST
366
#ifdef FS_FAST
365
#define c_code_file(c) ((c)->file)
367
#define c_code_file(c)	((c)->file)
366
#endif /* defined(FS_FAST) */
368
#endif /* defined(FS_FAST) */
367
 
369
 
368
#ifdef FS_FAST
370
#ifdef FS_FAST
369
#undef c_code_line
371
#undef c_code_line
370
#endif /* defined (FS_FAST) */
372
#endif /* defined (FS_FAST) */
371
unsigned
373
unsigned
372
c_code_line PROTO_N ((code))
374
c_code_line(CCodeP code)
373
	    PROTO_T (CCodeP code)
-
 
374
{
375
{
375
    return (code->line);
376
    return(code->line);
376
}
377
}
377
#ifdef FS_FAST
378
#ifdef FS_FAST
378
#define c_code_line(c) ((c)->line)
379
#define c_code_line(c)	((c)->line)
379
#endif /* defined(FS_FAST) */
380
#endif /* defined(FS_FAST) */
380
 
381
 
381
TypeTupleP
382
TypeTupleP
382
c_code_param PROTO_N ((code))
383
c_code_param(CCodeP code)
383
	     PROTO_T (CCodeP code)
-
 
384
{
384
{
385
    return (&(code->param));
385
    return(&(code->param));
386
}
386
}
387
 
387
 
388
TypeTupleP
388
TypeTupleP
389
c_code_result PROTO_N ((code))
389
c_code_result(CCodeP code)
390
	      PROTO_T (CCodeP code)
-
 
391
{
390
{
392
    return (&(code->result));
391
    return(&(code->result));
393
}
392
}
394
 
393
 
395
void
394
void
396
c_code_deallocate PROTO_N ((code))
395
c_code_deallocate(CCodeP code)
397
		  PROTO_T (CCodeP code)
-
 
398
{
396
{
399
    CCodeItemP item = code->head;
397
    CCodeItemP item = code->head;
400
 
398
 
401
    while (item) {
399
    while (item) {
402
	CCodeItemP next = item->next;
400
	CCodeItemP next = item->next;
403
 
401
 
404
	switch (item->type) EXHAUSTIVE {
402
	switch (item->type)EXHAUSTIVE {
405
	  case CCT_STRING:
403
	  case CCT_STRING:
406
	    nstring_destroy (&(item->u.string));
404
	    nstring_destroy(&(item->u.string));
407
	    break;
405
	    break;
408
	  case CCT_IDENT:
406
	  case CCT_IDENT:
409
	  case CCT_MOD_IDENT:
407
	  case CCT_MOD_IDENT:
410
	  case CCT_REF_IDENT:
408
	  case CCT_REF_IDENT:
411
	  case CCT_LABEL:
409
	  case CCT_LABEL:
412
	  case CCT_EXCEPTION:
410
	  case CCT_EXCEPTION:
413
	  case CCT_TERMINAL:
411
	  case CCT_TERMINAL:
414
	  case CCT_ADVANCE:
412
	  case CCT_ADVANCE:
415
	    break;
413
	    break;
416
	}
414
	}
417
	DEALLOCATE (item);
415
	DEALLOCATE(item);
418
	item = next;
416
	item = next;
419
    }
417
    }
420
    types_destroy (&(code->param));
418
    types_destroy(&(code->param));
421
    types_destroy (&(code->result));
419
    types_destroy(&(code->result));
422
    DEALLOCATE (code);
420
    DEALLOCATE(code);
423
}
421
}
424
 
422
 
425
void
423
void
426
c_output_c_code_action PROTO_N ((info, code, param, result, state,
424
c_output_c_code_action(COutputInfoP info, CCodeP code, TypeTupleP param,
427
				 handler_rule))
-
 
428
		       PROTO_T (COutputInfoP info X
425
		       TypeTupleP result, SaveRStackP state,
429
				CCodeP       code X
-
 
430
				TypeTupleP   param X
-
 
431
				TypeTupleP   result X
-
 
432
				SaveRStackP  state X
-
 
433
				RuleP        handler_rule)
426
		       RuleP handler_rule)
434
{
427
{
435
    OStreamP    ostream      = c_out_info_ostream (info);
428
    OStreamP    ostream      = c_out_info_ostream(info);
436
    NStringP    label_prefix = c_out_info_label_prefix (info);
429
    NStringP    label_prefix = c_out_info_label_prefix(info);
437
    NStringP    in_prefix    = c_out_info_in_prefix (info);
430
    NStringP    in_prefix    = c_out_info_in_prefix(info);
438
    CCodeItemP  item;
431
    CCodeItemP  item;
439
    EntryP      stack_entry;
432
    EntryP      stack_entry;
440
    EntryP      entry;
433
    EntryP      entry;
441
    EntryP      stack_type;
434
    EntryP      stack_type;
442
    BoolT       stack_reference;
435
    BoolT       stack_reference;
443
    BoolT       use_cast;
436
    BoolT       use_cast;
444
    TypeBTransT translator;
437
    TypeBTransT translator;
445
 
438
 
446
    c_code_set_labels (code);
439
    c_code_set_labels(code);
447
    btrans_init (&translator);
440
    btrans_init(&translator);
448
    btrans_add_translations (&translator, &(code->param), param);
441
    btrans_add_translations(&translator, &(code->param), param);
449
    btrans_add_translations (&translator, &(code->result), result);
442
    btrans_add_translations(&translator, &(code->result), result);
450
    for (item = code->head; item; item = item->next) {
443
    for (item = code->head; item; item = item->next) {
451
	switch (item->type) EXHAUSTIVE {
444
	switch (item->type)EXHAUSTIVE {
452
	  case CCT_STRING:
445
	  case CCT_STRING:
453
	    write_nstring (ostream, &(item->u.string));
446
	    write_nstring(ostream, &(item->u.string));
454
	    break;
447
	    break;
455
	  case CCT_LABEL:
448
	  case CCT_LABEL:
456
	    write_nstring (ostream, label_prefix);
449
	    write_nstring(ostream, label_prefix);
457
	    write_unsigned (ostream,
450
	    write_unsigned(ostream,
458
			    name_get_label (entry_get_name (item->u.ident)));
451
			   name_get_label(entry_get_name(item->u.ident)));
459
	    break;
452
	    break;
460
	  case CCT_IDENT:
453
	  case CCT_IDENT:
461
	    stack_entry = c_code_get_translation (state, &translator,
454
	    stack_entry = c_code_get_translation(state, &translator,
462
						  item->u.ident, &stack_type,
455
						 item->u.ident, &stack_type,
463
						  &stack_reference, &entry);
456
						 &stack_reference, &entry);
464
	    use_cast = (types_contains (param, entry) &&
457
	    use_cast = (types_contains(param, entry) &&
465
			c_out_info_get_casts (info));
458
			c_out_info_get_casts(info));
466
	    if (use_cast) {
459
	    if (use_cast) {
467
		write_cstring (ostream, "((");
460
		write_cstring(ostream, "((");
468
		c_output_mapped_key (info, stack_type);
461
		c_output_mapped_key(info, stack_type);
469
		write_cstring (ostream, ") (");
462
		write_cstring(ostream, ") (");
470
	    } else {
463
	    } else {
471
		write_char (ostream, '(');
464
		write_char(ostream, '(');
472
	    }
465
	    }
473
	    if (stack_reference) {
466
	    if (stack_reference) {
474
		write_char (ostream, '*');
467
		write_char(ostream, '*');
475
	    }
468
	    }
476
	    c_output_key (info, entry_key (stack_entry), in_prefix);
469
	    c_output_key(info, entry_key(stack_entry), in_prefix);
477
	    if (use_cast) {
470
	    if (use_cast) {
478
		write_cstring (ostream, "))");
471
		write_cstring(ostream, "))");
479
	    } else {
472
	    } else {
480
		write_char (ostream, ')');
473
		write_char(ostream, ')');
481
	    }
474
	    }
482
	    break;
475
	    break;
483
	  case CCT_MOD_IDENT:
476
	  case CCT_MOD_IDENT:
484
	    stack_entry = c_code_get_translation (state, &translator,
477
	    stack_entry = c_code_get_translation(state, &translator,
485
						  item->u.ident, &stack_type,
478
						 item->u.ident, &stack_type,
486
						  &stack_reference,
479
						 &stack_reference,
487
						  NIL (EntryP *));
480
						 NIL(EntryP *));
488
	    write_char (ostream, '(');
481
	    write_char(ostream, '(');
489
	    if (stack_reference) {
482
	    if (stack_reference) {
490
		write_char (ostream, '*');
483
		write_char(ostream, '*');
491
	    }
484
	    }
492
	    c_output_key (info, entry_key (stack_entry), in_prefix);
485
	    c_output_key(info, entry_key(stack_entry), in_prefix);
493
	    write_char (ostream, ')');
486
	    write_char(ostream, ')');
494
	    break;
487
	    break;
495
	  case CCT_REF_IDENT:
488
	  case CCT_REF_IDENT:
496
	    stack_entry = c_code_get_translation (state, &translator,
489
	    stack_entry = c_code_get_translation(state, &translator,
497
						  item->u.ident, &stack_type,
490
						 item->u.ident, &stack_type,
498
						  &stack_reference,
491
						 &stack_reference,
499
						  NIL (EntryP *));
492
						 NIL(EntryP *));
500
	    write_char (ostream, '(');
493
	    write_char(ostream, '(');
501
	    if (!stack_reference) {
494
	    if (!stack_reference) {
502
		write_char (ostream, '&');
495
		write_char(ostream, '&');
503
	    }
496
	    }
504
	    c_output_key (info, entry_key (stack_entry), in_prefix);
497
	    c_output_key(info, entry_key(stack_entry), in_prefix);
505
	    write_char (ostream, ')');
498
	    write_char(ostream, ')');
506
	    break;
499
	    break;
507
	  case CCT_EXCEPTION:
500
	  case CCT_EXCEPTION:
508
	    write_cstring (ostream, "goto ");
501
	    write_cstring(ostream, "goto ");
509
	    write_nstring (ostream, label_prefix);
502
	    write_nstring(ostream, label_prefix);
510
	    write_unsigned (ostream, rule_get_handler_label (handler_rule));
503
	    write_unsigned(ostream, rule_get_handler_label(handler_rule));
511
	    break;
504
	    break;
512
	  case CCT_ADVANCE:
505
	  case CCT_ADVANCE:
513
	    write_cstring (ostream, "ADVANCE_LEXER");
506
	    write_cstring(ostream, "ADVANCE_LEXER");
514
	    break;
507
	    break;
515
	  case CCT_TERMINAL:
508
	  case CCT_TERMINAL:
516
	    write_cstring (ostream, "CURRENT_TERMINAL");
509
	    write_cstring(ostream, "CURRENT_TERMINAL");
517
	    break;
510
	    break;
518
	}
511
	}
519
    }
512
    }
520
    btrans_destroy (&translator);
513
    btrans_destroy(&translator);
521
    c_code_reset_labels (code);
514
    c_code_reset_labels(code);
522
}
515
}
523
 
516
 
524
void
517
void
525
c_output_c_code_basic PROTO_N ((info, code, result, state))
518
c_output_c_code_basic(COutputInfoP info, CCodeP code, TypeTupleP result,
526
		      PROTO_T (COutputInfoP info X
-
 
527
			       CCodeP       code X
-
 
528
			       TypeTupleP   result X
-
 
529
			       SaveRStackP  state)
519
		      SaveRStackP state)
530
{
520
{
531
    OStreamP    ostream      = c_out_info_ostream (info);
521
    OStreamP    ostream      = c_out_info_ostream(info);
532
    NStringP    label_prefix = c_out_info_label_prefix (info);
522
    NStringP    label_prefix = c_out_info_label_prefix(info);
533
    NStringP    in_prefix    = c_out_info_in_prefix (info);
523
    NStringP    in_prefix    = c_out_info_in_prefix(info);
534
    CCodeItemP  item;
524
    CCodeItemP  item;
535
    EntryP      stack_entry;
525
    EntryP      stack_entry;
536
    EntryP      stack_type;
526
    EntryP      stack_type;
537
    BoolT       stack_reference;
527
    BoolT       stack_reference;
538
    TypeBTransT translator;
528
    TypeBTransT translator;
539
 
529
 
540
    c_code_set_labels (code);
530
    c_code_set_labels(code);
541
    btrans_init (&translator);
531
    btrans_init(&translator);
542
    btrans_add_translations (&translator, &(code->result), result);
532
    btrans_add_translations(&translator, &(code->result), result);
543
    for (item = code->head; item; item = item->next) {
533
    for (item = code->head; item; item = item->next) {
544
	switch (item->type) EXHAUSTIVE {
534
	switch (item->type)EXHAUSTIVE {
545
	  case CCT_STRING:
535
	  case CCT_STRING:
546
	    write_nstring (ostream, &(item->u.string));
536
	    write_nstring(ostream, &(item->u.string));
547
	    break;
537
	    break;
548
	  case CCT_LABEL:
538
	  case CCT_LABEL:
549
	    write_nstring (ostream, label_prefix);
539
	    write_nstring(ostream, label_prefix);
550
	    write_unsigned (ostream,
540
	    write_unsigned(ostream,
551
			    name_get_label (entry_get_name (item->u.ident)));
541
			   name_get_label(entry_get_name(item->u.ident)));
552
	    break;
542
	    break;
553
	  case CCT_IDENT:
543
	  case CCT_IDENT:
554
	    stack_entry = c_code_get_translation (state, &translator,
544
	    stack_entry = c_code_get_translation(state, &translator,
555
						  item->u.ident, &stack_type,
545
						 item->u.ident, &stack_type,
556
						  &stack_reference,
546
						 &stack_reference,
557
						  NIL (EntryP *));
547
						 NIL(EntryP *));
558
	    c_output_key (info, entry_key (stack_entry), in_prefix);
548
	    c_output_key(info, entry_key(stack_entry), in_prefix);
559
	    break;
549
	    break;
560
	  case CCT_MOD_IDENT:
550
	  case CCT_MOD_IDENT:
561
	  case CCT_REF_IDENT:
551
	  case CCT_REF_IDENT:
562
	  case CCT_EXCEPTION:
552
	  case CCT_EXCEPTION:
563
	  case CCT_ADVANCE:
553
	  case CCT_ADVANCE:
564
	  case CCT_TERMINAL:
554
	  case CCT_TERMINAL:
565
	    UNREACHED;
555
	    UNREACHED;
566
	}
556
	}
567
    }
557
    }
568
    btrans_destroy (&translator);
558
    btrans_destroy(&translator);
569
    c_code_reset_labels (code);
559
    c_code_reset_labels(code);
570
}
560
}
571
 
561
 
572
void
562
void
573
c_output_c_code_assign PROTO_N ((info, code, type, from, to, from_reference,
563
c_output_c_code_assign(COutputInfoP info, CCodeP code, EntryP type,
574
			      to_reference))
-
 
575
		       PROTO_T (COutputInfoP info X
-
 
576
				CCodeP       code X
-
 
577
				EntryP       type X
-
 
578
				EntryP       from X
-
 
579
				EntryP       to X
-
 
580
				BoolT        from_reference X
564
		       EntryP from, EntryP to, BoolT from_reference,
581
				BoolT        to_reference)
565
		       BoolT to_reference)
582
{
566
{
583
    OStreamP   ostream      = c_out_info_ostream (info);
567
    OStreamP   ostream      = c_out_info_ostream(info);
584
    NStringP   label_prefix = c_out_info_label_prefix (info);
568
    NStringP   label_prefix = c_out_info_label_prefix(info);
585
    NStringP   in_prefix    = c_out_info_in_prefix (info);
569
    NStringP   in_prefix    = c_out_info_in_prefix(info);
586
    BoolT      is_param;
570
    BoolT      is_param;
587
    BoolT      use_cast;
571
    BoolT      use_cast;
588
    CCodeItemP item;
572
    CCodeItemP item;
589
 
573
 
590
    c_code_set_labels (code);
574
    c_code_set_labels(code);
591
    for (item = code->head; item; item = item->next) {
575
    for (item = code->head; item; item = item->next) {
592
	switch (item->type) EXHAUSTIVE {
576
	switch (item->type)EXHAUSTIVE {
593
	  case CCT_STRING:
577
	  case CCT_STRING:
594
	    write_nstring (ostream, &(item->u.string));
578
	    write_nstring(ostream, &(item->u.string));
595
	    break;
579
	    break;
596
	  case CCT_LABEL:
580
	  case CCT_LABEL:
597
	    write_nstring (ostream, label_prefix);
581
	    write_nstring(ostream, label_prefix);
598
	    write_unsigned (ostream,
582
	    write_unsigned(ostream,
599
			    name_get_label (entry_get_name (item->u.ident)));
583
			   name_get_label(entry_get_name(item->u.ident)));
600
	    break;
584
	    break;
601
	  case CCT_IDENT:
585
	  case CCT_IDENT:
602
	    is_param = types_contains (&(code->param), item->u.ident);
586
	    is_param = types_contains(&(code->param), item->u.ident);
603
	    use_cast = (is_param && c_out_info_get_casts (info));
587
	    use_cast = (is_param && c_out_info_get_casts(info));
604
	    if (use_cast) {
588
	    if (use_cast) {
605
		write_cstring (ostream, "((");
589
		write_cstring(ostream, "((");
606
		c_output_mapped_key (info, type);
590
		c_output_mapped_key(info, type);
607
		write_cstring (ostream, ") (");
591
		write_cstring(ostream, ") (");
608
	    } else {
592
	    } else {
609
		write_char (ostream, '(');
593
		write_char(ostream, '(');
610
	    }
594
	    }
611
	    if (is_param) {
595
	    if (is_param) {
612
		if (from_reference) {
596
		if (from_reference) {
613
		    write_char (ostream, '*');
597
		    write_char(ostream, '*');
614
		}
598
		}
615
		c_output_key (info, entry_key (from), in_prefix);
599
		c_output_key(info, entry_key(from), in_prefix);
616
	    } else {
600
	    } else {
617
		if (to_reference) {
601
		if (to_reference) {
618
		    write_char (ostream, '*');
602
		    write_char(ostream, '*');
619
		}
603
		}
620
		c_output_key (info, entry_key (to), in_prefix);
604
		c_output_key(info, entry_key(to), in_prefix);
621
	    }
605
	    }
622
	    if (use_cast) {
606
	    if (use_cast) {
623
		write_cstring (ostream, "))");
607
		write_cstring(ostream, "))");
624
	    } else {
608
	    } else {
625
		write_char (ostream, ')');
609
		write_char(ostream, ')');
626
	    }
610
	    }
627
	    break;
611
	    break;
628
	  case CCT_REF_IDENT:
612
	  case CCT_REF_IDENT:
629
	    write_char (ostream, '(');
613
	    write_char(ostream, '(');
630
	    if (!from_reference) {
614
	    if (!from_reference) {
631
		write_char (ostream, '&');
615
		write_char(ostream, '&');
632
	    }
616
	    }
633
	    c_output_key (info, entry_key (from), in_prefix);
617
	    c_output_key(info, entry_key(from), in_prefix);
634
	    write_char (ostream, ')');
618
	    write_char(ostream, ')');
635
	    break;
619
	    break;
636
	  case CCT_MOD_IDENT:
620
	  case CCT_MOD_IDENT:
637
	  case CCT_EXCEPTION:
621
	  case CCT_EXCEPTION:
638
	  case CCT_ADVANCE:
622
	  case CCT_ADVANCE:
639
	  case CCT_TERMINAL:
623
	  case CCT_TERMINAL:
640
	    UNREACHED;
624
	    UNREACHED;
641
	}
625
	}
642
    }
626
    }
643
    c_code_reset_labels (code);
627
    c_code_reset_labels(code);
644
}
628
}
645
 
629
 
646
void
630
void
647
c_output_c_code_param_assign PROTO_N ((info, code, type, entry))
631
c_output_c_code_param_assign(COutputInfoP info, CCodeP code, EntryP type,
648
			     PROTO_T (COutputInfoP info X
-
 
649
				      CCodeP       code X
-
 
650
				      EntryP       type X
-
 
651
				      EntryP       entry)
632
			     EntryP entry)
652
{
633
{
653
    OStreamP   ostream      = c_out_info_ostream (info);
634
    OStreamP   ostream      = c_out_info_ostream(info);
654
    NStringP   label_prefix = c_out_info_label_prefix (info);
635
    NStringP   label_prefix = c_out_info_label_prefix(info);
655
    NStringP   in_prefix    = c_out_info_in_prefix (info);
636
    NStringP   in_prefix    = c_out_info_in_prefix(info);
656
    NStringP   out_prefix   = c_out_info_out_prefix (info);
637
    NStringP   out_prefix   = c_out_info_out_prefix(info);
657
    CCodeItemP item;
638
    CCodeItemP item;
658
 
639
 
659
    c_code_set_labels (code);
640
    c_code_set_labels(code);
660
    for (item = code->head; item; item = item->next) {
641
    for (item = code->head; item; item = item->next) {
661
	switch (item->type) EXHAUSTIVE {
642
	switch (item->type)EXHAUSTIVE {
662
	  case CCT_STRING:
643
	  case CCT_STRING:
663
	    write_nstring (ostream, &(item->u.string));
644
	    write_nstring(ostream, &(item->u.string));
664
	    break;
645
	    break;
665
	  case CCT_LABEL:
646
	  case CCT_LABEL:
666
	    write_nstring (ostream, label_prefix);
647
	    write_nstring(ostream, label_prefix);
667
	    write_unsigned (ostream,
648
	    write_unsigned(ostream,
668
			    name_get_label (entry_get_name (item->u.ident)));
649
			   name_get_label(entry_get_name(item->u.ident)));
669
	    break;
650
	    break;
670
	  case CCT_IDENT:
651
	  case CCT_IDENT:
671
	    if (types_contains (&(code->param), item->u.ident)) {
652
	    if (types_contains(&(code->param), item->u.ident)) {
672
		BoolT use_cast = c_out_info_get_casts (info);
653
		BoolT use_cast = c_out_info_get_casts(info);
673
 
654
 
674
		if (use_cast) {
655
		if (use_cast) {
675
		    write_cstring (ostream, "((");
656
		    write_cstring(ostream, "((");
676
		    c_output_mapped_key (info, type);
657
		    c_output_mapped_key(info, type);
677
		    write_cstring (ostream, " *) (");
658
		    write_cstring(ostream, " *) (");
678
		}
659
		}
679
		c_output_key (info, entry_key (entry), out_prefix);
660
		c_output_key(info, entry_key(entry), out_prefix);
680
		if (use_cast) {
661
		if (use_cast) {
681
		    write_cstring (ostream, "))");
662
		    write_cstring(ostream, "))");
682
		}
663
		}
683
	    } else {
664
	    } else {
684
		c_output_key (info, entry_key (entry), in_prefix);
665
		c_output_key(info, entry_key(entry), in_prefix);
685
	    }
666
	    }
686
	    break;
667
	    break;
687
	  case CCT_MOD_IDENT:
668
	  case CCT_MOD_IDENT:
688
	  case CCT_REF_IDENT:
669
	  case CCT_REF_IDENT:
689
	  case CCT_EXCEPTION:
670
	  case CCT_EXCEPTION:
690
	  case CCT_ADVANCE:
671
	  case CCT_ADVANCE:
691
	  case CCT_TERMINAL:
672
	  case CCT_TERMINAL:
692
	    UNREACHED;
673
	    UNREACHED;
693
	}
674
	}
694
    }
675
    }
695
    c_code_reset_labels (code);
676
    c_code_reset_labels(code);
696
}
677
}
697
 
678
 
698
void
679
void
699
c_output_c_code_result_assign PROTO_N ((info, code, type, entry))
680
c_output_c_code_result_assign(COutputInfoP info, CCodeP code, EntryP type,
700
			      PROTO_T (COutputInfoP info X
-
 
701
				       CCodeP       code X
-
 
702
				       EntryP       type X
-
 
703
				       EntryP       entry)
681
			      EntryP entry)
704
{
682
{
705
    OStreamP   ostream      = c_out_info_ostream (info);
683
    OStreamP   ostream      = c_out_info_ostream(info);
706
    NStringP   label_prefix = c_out_info_label_prefix (info);
684
    NStringP   label_prefix = c_out_info_label_prefix(info);
707
    NStringP   in_prefix    = c_out_info_in_prefix (info);
685
    NStringP   in_prefix    = c_out_info_in_prefix(info);
708
    NStringP   out_prefix   = c_out_info_out_prefix (info);
686
    NStringP   out_prefix   = c_out_info_out_prefix(info);
709
    CCodeItemP item;
687
    CCodeItemP item;
710
 
688
 
711
    c_code_set_labels (code);
689
    c_code_set_labels(code);
712
    for (item = code->head; item; item = item->next) {
690
    for (item = code->head; item; item = item->next) {
713
	switch (item->type) EXHAUSTIVE {
691
	switch (item->type)EXHAUSTIVE {
714
	  case CCT_STRING:
692
	  case CCT_STRING:
715
	    write_nstring (ostream, &(item->u.string));
693
	    write_nstring(ostream, &(item->u.string));
716
	    break;
694
	    break;
717
	  case CCT_LABEL:
695
	  case CCT_LABEL:
718
	    write_nstring (ostream, label_prefix);
696
	    write_nstring(ostream, label_prefix);
719
	    write_unsigned (ostream,
697
	    write_unsigned(ostream,
720
			    name_get_label (entry_get_name (item->u.ident)));
698
			   name_get_label(entry_get_name(item->u.ident)));
721
	    break;
699
	    break;
722
	  case CCT_IDENT:
700
	  case CCT_IDENT:
723
	    if (types_contains (&(code->param), item->u.ident)) {
701
	    if (types_contains(&(code->param), item->u.ident)) {
724
		BoolT use_cast = c_out_info_get_casts (info);
702
		BoolT use_cast = c_out_info_get_casts(info);
725
 
703
 
726
		if (use_cast) {
704
		if (use_cast) {
727
		    write_cstring (ostream, "((");
705
		    write_cstring(ostream, "((");
728
		    c_output_mapped_key (info, type);
706
		    c_output_mapped_key(info, type);
729
		    write_cstring (ostream, ") (");
707
		    write_cstring(ostream, ") (");
730
		}
708
		}
731
		c_output_key (info, entry_key (entry), in_prefix);
709
		c_output_key(info, entry_key(entry), in_prefix);
732
		if (use_cast) {
710
		if (use_cast) {
733
		    write_cstring (ostream, "))");
711
		    write_cstring(ostream, "))");
734
		}
712
		}
735
	    } else {
713
	    } else {
736
		c_output_key (info, entry_key (entry), out_prefix);
714
		c_output_key(info, entry_key(entry), out_prefix);
737
	    }
715
	    }
738
	    break;
716
	    break;
739
	  case CCT_REF_IDENT:
717
	  case CCT_REF_IDENT:
740
	    write_cstring (ostream, "(&");
718
	    write_cstring(ostream, "(&");
741
	    c_output_key (info, entry_key (entry), in_prefix);
719
	    c_output_key(info, entry_key(entry), in_prefix);
742
	    write_char (ostream, ')');
720
	    write_char(ostream, ')');
743
	    break;
721
	    break;
744
	  case CCT_MOD_IDENT:
722
	  case CCT_MOD_IDENT:
745
	  case CCT_EXCEPTION:
723
	  case CCT_EXCEPTION:
746
	  case CCT_ADVANCE:
724
	  case CCT_ADVANCE:
747
	  case CCT_TERMINAL:
725
	  case CCT_TERMINAL:
748
	    UNREACHED;
726
	    UNREACHED;
749
	}
727
	}
750
    }
728
    }
751
    c_code_reset_labels (code);
729
    c_code_reset_labels(code);
752
}
730
}
753
 
731
 
754
void
732
void
755
c_output_c_code PROTO_N ((info, code))
733
c_output_c_code(COutputInfoP info, CCodeP code)
756
		PROTO_T (COutputInfoP info X
-
 
757
			 CCodeP       code)
-
 
758
{
734
{
759
    OStreamP   ostream = c_out_info_ostream (info);
735
    OStreamP   ostream = c_out_info_ostream(info);
760
    CCodeItemP item;
736
    CCodeItemP item;
761
 
737
 
762
    for (item = code->head; item; item = item->next) {
738
    for (item = code->head; item; item = item->next) {
763
	switch (item->type) EXHAUSTIVE {
739
	switch (item->type)EXHAUSTIVE {
764
	  case CCT_STRING:
740
	  case CCT_STRING:
765
	    write_nstring (ostream, &(item->u.string));
741
	    write_nstring(ostream, &(item->u.string));
766
	    break;
742
	    break;
767
	  case CCT_LABEL:
743
	  case CCT_LABEL:
768
	  case CCT_IDENT:
744
	  case CCT_IDENT:
769
	  case CCT_MOD_IDENT:
745
	  case CCT_MOD_IDENT:
770
	  case CCT_REF_IDENT:
746
	  case CCT_REF_IDENT: