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 37... Line 67...
37
#include "suffix.h"
67
#include "suffix.h"
38
#include "type_ops.h"
68
#include "type_ops.h"
39
 
69
 
40
 
70
 
41
/*
71
/*
42
    PRINT A PRIMITIVE PRINTING ROUTINE
72
 * PRINT A PRIMITIVE PRINTING ROUTINE
-
 
73
 *
-
 
74
 * This routine prints the body of the printing routine for the current
-
 
75
 * primitive.
-
 
76
 */
43
 
77
 
44
    This routine prints the body of the printing routine for the current
-
 
45
    primitive.
-
 
46
*/
-
 
47
 
-
 
48
static void printer_prim
78
static void
49
    PROTO_Z ()
79
printer_prim(void)
50
{
80
{
51
    output ( "    print_indent ( f_, d_ ) ;\n" ) ;
81
    output("    print_indent(f_, d_);\n");
52
    output ( "    ( void ) fprintf ( f_, \"%%s = \", nm_ ) ;\n" ) ;
82
    output("    (void)fprintf(f_, \"%%s = \", nm_);\n");
53
    output ( "    OUTPUT_%PM ( f_, x_ ) ;\n" ) ;
83
    output("    OUTPUT_%PM(f_, x_);\n");
54
    output ( "    ( void ) fprintf ( f_, \" ;\\n\" ) ;\n" ) ;
84
    output("    (void)fprintf(f_, \" ;\\n\");\n");
-
 
85
    return;
-
 
86
}
-
 
87
 
-
 
88
 
-
 
89
/*
-
 
90
 * PRINT AN ENUMERATION PRINTING ROUTINE
-
 
91
 *
-
 
92
 * This routine prints the body of the printing routine for the current
-
 
93
 * enumeration.
-
 
94
 */
-
 
95
 
-
 
96
static void
-
 
97
printer_enum(void)
-
 
98
{
-
 
99
    output("    print_indent(f_, d_);\n");
-
 
100
    output("    (void)fprintf(f_, \"%%s = \", nm_);\n");
-
 
101
    output("    switch (x_) {\n");
-
 
102
    LOOP_ENUM_CONST {
-
 
103
	output("\tcase %EM_%ES: {\n");
-
 
104
	output("\t    (void)fprintf(f_, \"%ES ;\\n\");\n");
-
 
105
	output("\t    break;\n");
-
 
106
	output("\t}\n");
-
 
107
    }
-
 
108
    output("\tdefault: {\n");
-
 
109
    output("\t    (void)fprintf(f_, \"%%lu ;\\n\",");
-
 
110
    output(" (unsigned long)x_);\n");
-
 
111
    output("\t    break;\n");
-
 
112
    output("\t}\n");
-
 
113
    output("    }\n");
55
    return ;
114
    return;
56
}
115
}
57
 
116
 
58
 
117
 
59
/*
118
/*
60
    PRINT AN ENUMERATION PRINTING ROUTINE
119
 * PRINT A STRUCTURE PRINTING ROUTINE
61
 
-
 
62
    This routine prints the body of the printing routine for the current
-
 
63
    enumeration.
-
 
64
*/
-
 
65
 
-
 
66
static void printer_enum
-
 
67
    PROTO_Z ()
-
 
68
{
-
 
69
    output ( "    print_indent ( f_, d_ ) ;\n" ) ;
-
 
70
    output ( "    ( void ) fprintf ( f_, \"%%s = \", nm_ ) ;\n" ) ;
-
 
71
    output ( "    switch ( x_ ) {\n" ) ;
-
 
72
    LOOP_ENUM_CONST {
-
 
73
	output ( "\tcase %EM_%ES : {\n" ) ;
-
 
74
	output ( "\t    ( void ) fprintf ( f_, \"%ES ;\\n\" ) ;\n" ) ;
-
 
75
	output ( "\t    break ;\n" ) ;
-
 
76
	output ( "\t}\n" ) ;
-
 
77
    }
-
 
78
    output ( "\tdefault : {\n" ) ;
-
 
79
    output ( "\t    ( void ) fprintf ( f_, \"%%lu ;\\n\"," ) ;
-
 
80
    output ( " ( unsigned long ) x_ ) ;\n" ) ;
-
 
81
    output ( "\t    break ;\n" ) ;
-
 
82
    output ( "\t}\n" ) ;
-
 
83
    output ( "    }\n" ) ;
-
 
84
    return ;
-
 
85
}
-
 
86
 
-
 
87
 
-
 
88
/*
120
 *
89
    PRINT A STRUCTURE PRINTING ROUTINE
-
 
90
 
-
 
91
    This routine prints the body of the printing routine for the current
121
 * This routine prints the body of the printing routine for the current
92
    structure.
122
 * structure.
93
*/
123
 */
94
 
124
 
95
static void printer_struct
125
static void
96
    PROTO_Z ()
126
printer_struct(void)
97
{
127
{
98
    output ( "    print_indent ( f_, d_ ) ;\n" ) ;
128
    output("    print_indent(f_, d_);\n");
99
    output ( "    ( void ) fprintf ( f_, \"%%s = {\\n\", nm_ ) ;\n" ) ;
129
    output("    (void)fprintf(f_, \"%%s = {\\n\", nm_);\n");
100
    LOOP_STRUCTURE_COMPONENT {
130
    LOOP_STRUCTURE_COMPONENT {
101
	TYPE_P t = DEREF_ptr ( cmp_type ( CRT_COMPONENT ) ) ;
131
	TYPE_P t = DEREF_ptr(cmp_type(CRT_COMPONENT));
102
	output ( "    PRINT_%TI ( f_, x_.%CN, \"%CN\", d_ + 1 ) ;\n", t ) ;
132
	output("    PRINT_%TI(f_, x_.%CN, \"%CN\", d_ + 1);\n", t);
103
    }
133
    }
104
    output ( "    print_indent ( f_, d_ ) ;\n" ) ;
134
    output("    print_indent(f_, d_);\n");
105
    output ( "    ( void ) fprintf ( f_, \"}\\n\" ) ;\n" ) ;
135
    output("    (void)fprintf(f_, \"}\\n\");\n");
106
    return ;
136
    return;
107
}
137
}
108
 
-
 
109
 
138
 
110
/*
-
 
111
    PRINT A UNION COMPONENT PRINTING ROUTINE
-
 
112
 
-
 
113
    This routine prints the code for printing a component of a union.
-
 
114
    The argument d gives the token for accessing the component.
-
 
115
*/
-
 
116
 
-
 
117
static void printer_component
-
 
118
    PROTO_N ( ( d ) )
-
 
119
    PROTO_T ( char *d )
-
 
120
{
-
 
121
    TYPE_P t = DEREF_ptr ( cmp_type ( CRT_COMPONENT ) ) ;
-
 
122
    output ( "\t\t{\n" ) ;
-
 
123
    output ( "\t\t    %TT z_ ;\n", t ) ;
-
 
124
    output ( "\t\t    " ) ;
-
 
125
    print_deref ( t, d, "z_" ) ;
-
 
126
    output ( "\t\t    PRINT_%TI ( f_, z_, \"%CN\", d_ + 1 ) ;\n", t ) ;
-
 
127
    output ( "\t\t}\n" ) ;
-
 
128
    return ;
-
 
129
}
-
 
130
 
-
 
131
 
139
 
132
/*
140
/*
133
    PRINT A UNION PRINTING ROUTINE
141
 * PRINT A UNION COMPONENT PRINTING ROUTINE
134
 
142
 *
135
    This routine prints the body of the printing routine for the current
143
 * This routine prints the code for printing a component of a union.
136
    primitive.
144
 * The argument d gives the token for accessing the component.
137
*/
145
 */
138
 
146
 
139
static void printer_union
147
static void
140
    PROTO_Z ()
148
printer_component(char *d)
141
{
149
{
-
 
150
    TYPE_P t = DEREF_ptr(cmp_type(CRT_COMPONENT));
-
 
151
    output("\t\t{\n");
-
 
152
    output("\t\t    %TT z_;\n", t);
-
 
153
    output("\t\t    ");
-
 
154
    print_deref(t, d, "z_");
-
 
155
    output("\t\t    PRINT_%TI(f_, z_, \"%CN\", d_ + 1);\n", t);
-
 
156
    output("\t\t}\n");
-
 
157
    return;
-
 
158
}
-
 
159
 
-
 
160
 
-
 
161
/*
-
 
162
 * PRINT A UNION PRINTING ROUTINE
-
 
163
 *
-
 
164
 * This routine prints the body of the printing routine for the current
-
 
165
 * primitive.
-
 
166
 */
-
 
167
 
-
 
168
static void
-
 
169
printer_union(void)
-
 
170
{
142
    output ( "    print_indent ( f_, d_ ) ;\n" ) ;
171
    output("    print_indent(f_, d_);\n");
143
    output ( "    if ( IS_NULL_%UM ( x_ ) ) {\n" ) ;
172
    output("    if (IS_NULL_%UM(x_)) {\n");
144
    output ( "\t( void ) fprintf ( f_, \"%%s = NULL_%UM ;\\n\", nm_ ) ;\n" ) ;
173
    output("\t(void)fprintf(f_, \"%%s = NULL_%UM ;\\n\", nm_);\n");
145
    output ( "    } else {\n" ) ;
174
    output("    } else {\n");
146
    output ( "\tswitch ( TAG_%UM ( x_ ) ) {\n" ) ;
175
    output("\tswitch (TAG_%UM(x_)) {\n");
147
    LOOP_UNION_FIELD {
176
    LOOP_UNION_FIELD {
148
	int al = DEREF_int ( fld_flag ( CRT_FIELD ) ) ;
177
	int al = DEREF_int(fld_flag(CRT_FIELD));
149
	output ( "\t    case %UM_%FN_tag : {\n" ) ;
178
	output("\t    case %UM_%FN_tag: {\n");
150
	if ( al ) {
179
	if (al) {
151
	    output ( "\t\tunsigned alias_ = GET_ALIAS_%UM_%FN ( x_ ) ;\n" ) ;
180
	    output("\t\tunsigned alias_ = GET_ALIAS_%UM_%FN(x_);\n");
152
	    output ( "\t\tif ( alias_ ) {\n" ) ;
181
	    output("\t\tif (alias_) {\n");
153
	    output ( "\t\t    ( void ) fprintf ( f_, \"%%s = " ) ;
182
	    output("\t\t    (void)fprintf(f_, \"%%s = ");
154
	    output ( "[%%u] ;\\n\", nm_, alias_ ) ;\n" ) ;
183
	    output("[%%u] ;\\n\", nm_, alias_);\n");
155
	    output ( "\t\t    break ;\n" ) ;
184
	    output("\t\t    break;\n");
156
	    output ( "\t\t}\n" ) ;
185
	    output("\t\t}\n");
157
	    output ( "\t\talias_ = ++crt_%X_alias ;\n" ) ;
186
	    output("\t\talias_ = ++crt_%X_alias ;\n");
158
	    output ( "\t\tSET_ALIAS_%UM_%FN ( x_, alias_ ) ;\n" ) ;
187
	    output("\t\tSET_ALIAS_%UM_%FN(x_, alias_);\n");
159
	    output ( "\t\t( void ) fprintf ( f_, \"%%s = [%%u] = {\\n\", " ) ;
188
	    output("\t\t(void)fprintf(f_, \"%%s = [%%u] = {\\n\", ");
160
	    output ( "nm_, alias_ ) ;\n" ) ;
189
	    output("nm_, alias_);\n");
161
	} else {
190
	} else {
162
	    output ( "\t\t( void ) fprintf ( f_, \"%%s = {\\n\", nm_ ) ;\n" ) ;
191
	    output("\t\t(void)fprintf(f_, \"%%s = {\\n\", nm_);\n");
163
	}
192
	}
164
	output ( "\t\tprint_indent ( f_, d_ + 1 ) ;\n" ) ;
193
	output("\t\tprint_indent(f_, d_ + 1);\n");
165
	output ( "\t\t( void ) fprintf ( f_, \"(tag) = %FN ;\\n\" ) ;\n" ) ;
194
	output("\t\t(void)fprintf(f_, \"(tag) = %FN ;\\n\");\n");
166
	LOOP_UNION_COMPONENT printer_component ( "%UM_%CN ( x_ )" ) ;
195
	LOOP_UNION_COMPONENT printer_component("%UM_%CN(x_)");
167
	LOOP_FIELD_COMPONENT printer_component ( "%UM_%FN_%CN ( x_ )" ) ;
196
	LOOP_FIELD_COMPONENT printer_component("%UM_%FN_%CN(x_)");
168
	output ( "\t\tprint_indent ( f_, d_ ) ;\n" ) ;
197
	output("\t\tprint_indent(f_, d_);\n");
169
	output ( "\t\t( void ) fprintf ( f_, \"}\\n\" ) ;\n" ) ;
198
	output("\t\t(void)fprintf(f_, \"}\\n\");\n");
170
	output ( "\t\tbreak ;\n" ) ;
199
	output("\t\tbreak;\n");
171
	output ( "\t    }\n" ) ;
200
	output("\t    }\n");
172
    }
201
    }
173
    output ( "\t    default : {\n" ) ;
202
    output("\t    default : {\n");
174
    output ( "\t\t( void ) fprintf ( f_, \"%%s = ERROR!\\n\", nm_ ) ;\n" ) ;
203
    output("\t\t(void)fprintf(f_, \"%%s = ERROR!\\n\", nm_);\n");
175
    output ( "\t\tbreak ;\n" ) ;
204
    output("\t\tbreak;\n");
176
    output ( "\t    }\n" ) ;
205
    output("\t    }\n");
177
    output ( "\t}\n" ) ;
206
    output("\t}\n");
178
    output ( "    }\n" ) ;
207
    output("    }\n");
179
    return ;
208
    return;
180
}
209
}
181
 
210
 
182
 
211
 
183
/*
212
/*
184
    PRINT A POINTER PRINTING ROUTINE
213
 * PRINT A POINTER PRINTING ROUTINE
185
 
-
 
186
    This routine prints the body of the printing routine for a pointer
-
 
187
    to s.
-
 
188
*/
-
 
189
 
-
 
190
static void printer_ptr
-
 
191
    PROTO_N ( ( s, ptr, nm, i ) )
-
 
192
    PROTO_T ( TYPE_P s X char *ptr X char *nm X char *i )
-
 
193
{
-
 
194
    output ( "%s    print_indent ( f_, d_ ) ;\n", i ) ;
-
 
195
    output ( "%s    if ( IS_NULL_ptr ( %s ) ) {\n", i, nm ) ;
-
 
196
    output ( "%s\t( void ) fprintf ( f_, ", i ) ;
-
 
197
    output ( "\"%%s = NULL_ptr ;\\n\", nm_ ) ;\n" ) ;
-
 
198
    output ( "%s    } else if ( d_ < print_ptr_depth ) {\n", i ) ;
-
 
199
    output ( "%s\t%TT z_ ;\n", i, s ) ;
-
 
200
    output ( "%s\t", i ) ;
-
 
201
    print_deref ( s, nm, "z_" ) ;
-
 
202
    output ( "%s\t( void ) fprintf ( f_, ", i ) ;
-
 
203
    output ( "\"%%s = %s {\\n\", nm_ ) ;\n", ptr ) ;
-
 
204
    output ( "%s\tPRINT_%TI ( f_, z_, \"(%TI)\", d_ + 1 ) ;\n", i, s, s ) ;
-
 
205
    output ( "%s\tprint_indent ( f_, d_ ) ;\n", i ) ;
-
 
206
    output ( "%s\t( void ) fprintf ( f_, \"}\\n\" ) ;\n", i ) ;
-
 
207
    output ( "%s    } else {\n", i ) ;
-
 
208
    output ( "%s\t( void ) fprintf ( f_, \"%%s = ", i ) ;
-
 
209
    output ( "0x%%p ;\\n\", nm_, VOIDSTAR_ptr ( %s ) ) ;\n", nm ) ;
-
 
210
    output ( "%s    }\n", i ) ;
-
 
211
    return ;
-
 
212
}
-
 
213
 
-
 
214
 
-
 
215
/*
214
 *
216
    PRINT A LIST PRINTING ROUTINE
-
 
217
 
-
 
218
    This routine prints the body of the printing routine for a list
-
 
219
    of s named nm.
-
 
220
*/
-
 
221
 
-
 
222
static void printer_list
-
 
223
    PROTO_N ( ( s, nm ) )
-
 
224
    PROTO_T ( TYPE_P s X char *nm )
-
 
225
{
-
 
226
    output ( "    print_indent ( f_, d_ ) ;\n" ) ;
-
 
227
    output ( "    ( void ) fprintf ( f_, \"%%s = LIST {\\n\", nm_ ) ;\n" ) ;
-
 
228
    output ( "    while ( !IS_NULL_list ( %s ) ) {\n", nm ) ;
-
 
229
    output ( "\t%TT z_ ;\n", s ) ;
-
 
230
    output ( "\tUN_CONS_%TM ( z_, %s, %s ) ;\n", s, nm, nm ) ;
-
 
231
    output ( "\tPRINT_%TI ( f_, z_, \"(%TI)\", d_ + 1 ) ;\n", s, s ) ;
-
 
232
    output ( "\tif ( !print_list_expand && !IS_NULL_list ( %s ) ) {\n", nm ) ;
-
 
233
    output ( "\t    print_indent ( f_, d_ + 1 ) ;\n" ) ;
-
 
234
    output ( "\t    ( void ) fprintf ( f_, \"(tail) = " ) ;
-
 
235
    output ( "0x%%p ;\\n\", VOIDSTAR_list ( %s ) ) ;\n", nm ) ;
-
 
236
    output ( "\t    break ;\n" ) ;
-
 
237
    output ( "\t}\n" ) ;
-
 
238
    output ( "    }\n" ) ;
-
 
239
    output ( "    print_indent ( f_, d_ ) ;\n" ) ;
-
 
240
    output ( "    ( void ) fprintf ( f_, \"}\\n\" ) ;\n" ) ;
-
 
241
    return ;
-
 
242
}
-
 
243
 
-
 
244
 
-
 
245
/*
-
 
246
    PRINT A VECTOR PRINTING ROUTINE
-
 
247
 
-
 
248
    This routine prints the body of the printing routine for a vector
215
 * This routine prints the body of the printing routine for a pointer
249
    of s.
216
 * to s.
250
*/
217
 */
251
 
-
 
252
static void printer_vec
-
 
253
    PROTO_N ( ( s ) )
-
 
254
    PROTO_T ( TYPE_P s )
-
 
255
{
-
 
256
    output ( "    print_indent ( f_, d_ ) ;\n" ) ;
-
 
257
    output ( "    {\n" ) ;
-
 
258
    output ( "\t%X_dim n = DIM_vec ( x_ ) ;\n" ) ;
-
 
259
    output ( "\tPTR ( %TT ) y_ = PTR_vec_ptr ( VEC_PTR_vec ( x_ ) ) ;\n", s ) ;
-
 
260
    output ( "\t( void ) fprintf ( f_, \"%%s = {\\n\", nm_ ) ;\n" ) ;
-
 
261
    output ( "\twhile ( n-- ) {\n" ) ;
-
 
262
    printer_ptr ( s, "VEC", "y_", "\t" ) ;
-
 
263
    output ( "\t    y_ = STEP_ptr ( y_, SIZE_%TM ) ;\n", s ) ;
-
 
264
    output ( "\t}\n" ) ;
-
 
265
    output ( "\tprint_indent ( f_, d_ ) ;\n" ) ;
-
 
266
    output ( "\t( void ) fprintf ( f_, \"}\\n\" ) ;\n" ) ;
-
 
267
    output ( "    }\n" ) ;
-
 
268
    return ;
-
 
269
}
-
 
270
 
-
 
271
 
218
 
-
 
219
static void
-
 
220
printer_ptr(TYPE_P s, char *ptr, char *nm, char *i)
272
/*
221
{
-
 
222
    output("%s    print_indent(f_, d_);\n", i);
-
 
223
    output("%s    if (IS_NULL_ptr(%s)) {\n", i, nm);
-
 
224
    output("%s\t(void)fprintf(f_, ", i);
-
 
225
    output("\"%%s = NULL_ptr;\\n\", nm_);\n");
-
 
226
    output("%s    } else if (d_ < print_ptr_depth) {\n", i);
-
 
227
    output("%s\t%TT z_;\n", i, s);
-
 
228
    output("%s\t", i);
-
 
229
    print_deref(s, nm, "z_");
273
    PRINT A VECTOR POINTER PRINTING ROUTINE
230
    output("%s\t(void)fprintf(f_, ", i);
-
 
231
    output("\"%%s = %s {\\n\", nm_);\n", ptr);
-
 
232
    output("%s\tPRINT_%TI(f_, z_, \"(%TI)\", d_ + 1);\n", i, s, s);
-
 
233
    output("%s\tprint_indent(f_, d_);\n", i);
-
 
234
    output("%s\t(void)fprintf(f_, \"}\\n\");\n", i);
-
 
235
    output("%s    } else {\n", i);
-
 
236
    output("%s\t(void)fprintf(f_, \"%%s = ", i);
-
 
237
    output("0x%%p ;\\n\", nm_, VOIDSTAR_ptr(%s));\n", nm);
-
 
238
    output("%s    }\n", i);
-
 
239
    return;
-
 
240
}
274
 
241
 
275
    This routine prints the body of the printing routine for a vector
-
 
276
    pointer to s.
-
 
277
*/
-
 
278
 
242
 
-
 
243
/*
279
static void printer_vec_ptr
244
 * PRINT A LIST PRINTING ROUTINE
-
 
245
 *
-
 
246
 * This routine prints the body of the printing routine for a list
280
    PROTO_N ( ( s ) )
247
 * of s named nm.
-
 
248
 */
-
 
249
 
-
 
250
static void
281
    PROTO_T ( TYPE_P s )
251
printer_list(TYPE_P s, char *nm)
282
{
252
{
-
 
253
    output("    print_indent(f_, d_);\n");
-
 
254
    output("    (void)fprintf(f_, \"%%s = LIST {\\n\", nm_);\n");
283
    output ( "    PTR ( %TT ) y_ = PTR_vec_ptr ( x_ ) ;\n", s ) ;
255
    output("    while (!IS_NULL_list(%s)) {\n", nm);
-
 
256
    output("\t%TT z_;\n", s);
-
 
257
    output("\tUN_CONS_%TM(z_, %s, %s);\n", s, nm, nm);
-
 
258
    output("\tPRINT_%TI(f_, z_, \"(%TI)\", d_ + 1);\n", s, s);
-
 
259
    output("\tif (!print_list_expand && !IS_NULL_list(%s)) {\n", nm);
-
 
260
    output("\t    print_indent(f_, d_ + 1);\n");
-
 
261
    output("\t    (void)fprintf(f_, \"(tail) = ");
-
 
262
    output("0x%%p ;\\n\", VOIDSTAR_list(%s));\n", nm);
-
 
263
    output("\t    break;\n");
-
 
264
    output("\t}\n");
-
 
265
    output("    }\n");
284
    printer_ptr ( s, "VEC_PTR", "y_", "" ) ;
266
    output("    print_indent(f_, d_);\n");
-
 
267
    output("    (void)fprintf(f_, \"}\\n\");\n");
285
    return ;
268
    return;
286
}
269
}
287
 
270
 
288
 
271
 
289
/*
272
/*
290
    PRINT ALL PRINTING ROUTINES
273
 * PRINT A VECTOR PRINTING ROUTINE
-
 
274
 *
-
 
275
 * This routine prints the body of the printing routine for a vector
-
 
276
 * of s.
-
 
277
 */
-
 
278
 
-
 
279
static void
-
 
280
printer_vec(TYPE_P s)
-
 
281
{
-
 
282
    output("    print_indent(f_, d_);\n");
-
 
283
    output("    {\n");
-
 
284
    output("\t%X_dim n = DIM_vec(x_);\n");
-
 
285
    output("\tPTR(%TT) y_ = PTR_vec_ptr(VEC_PTR_vec(x_));\n", s);
-
 
286
    output("\t(void)fprintf(f_, \"%%s = {\\n\", nm_);\n");
-
 
287
    output("\twhile (n--) {\n");
-
 
288
    printer_ptr(s, "VEC", "y_", "\t");
-
 
289
    output("\t    y_ = STEP_ptr(y_, SIZE_%TM);\n", s);
-
 
290
    output("\t}\n");
-
 
291
    output("\tprint_indent(f_, d_);\n");
-
 
292
    output("\t(void)fprintf(f_, \"}\\n\");\n");
-
 
293
    output("    }\n");
-
 
294
    return;
-
 
295
}
-
 
296
 
-
 
297
 
-
 
298
/*
-
 
299
 * PRINT A VECTOR POINTER PRINTING ROUTINE
-
 
300
 *
-
 
301
 * This routine prints the body of the printing routine for a vector
-
 
302
 * pointer to s.
-
 
303
 */
-
 
304
 
-
 
305
static void
-
 
306
printer_vec_ptr(TYPE_P s)
-
 
307
{
-
 
308
    output("    PTR(%TT) y_ = PTR_vec_ptr(x_);\n", s);
-
 
309
    printer_ptr(s, "VEC_PTR", "y_", "");
-
 
310
    return;
-
 
311
}
-
 
312
 
291
 
313
 
-
 
314
/*
-
 
315
 * PRINT ALL PRINTING ROUTINES
-
 
316
 *
292
    This routine prints all the printing routines.
317
 * This routine prints all the printing routines.
293
*/
318
 */
294
 
319
 
295
void print_action
320
void
296
    PROTO_N ( ( dir ) )
-
 
297
    PROTO_T ( char *dir )
321
print_action(char *dir)
298
{
322
{
299
    open_file ( dir, PRINT_PREFIX, DEF_SUFFIX ) ;
323
    open_file(dir, PRINT_PREFIX, DEF_SUFFIX);
300
    print_include () ;
324
    print_include();
301
 
325
 
302
    comment ( "Printing function declarations" ) ;
326
    comment("Printing function declarations");
303
    LOOP_TYPE {
327
    LOOP_TYPE {
304
	TYPE_P t = CRT_TYPE ;
328
	TYPE_P t = CRT_TYPE;
305
	if ( is_identity_type ( t ) ) {
329
	if (is_identity_type(t)) {
306
	    output ( "#ifndef PRINT_%TI\n", t ) ;
330
	    output("#ifndef PRINT_%TI\n", t);
307
	    output ( "#define PRINT_%TI( A, B, C, D ) ", t ) ;
331
	    output("#define PRINT_%TI(A, B, C, D)", t);
308
	    output ( "PRINT_%TJ ( ( A ), ( B ), ( C ), ( D ) )\n", t ) ;
332
	    output("PRINT_%TJ((A), (B), (C), (D))\n", t);
309
	    output ( "#endif\n\n" ) ;
333
	    output("#endif\n\n");
310
	} else {
334
	} else {
311
	    output ( "#ifndef PRINT_%TI\n", t ) ;
335
	    output("#ifndef PRINT_%TI\n", t);
312
	    output ( "static void PRINT_%TI ", t ) ;
336
	    output("static void PRINT_%TI ", t);
313
	    output ( "PROTO_S ( ( FILE *, %TT, char *, int ) ) ;\n", t ) ;
337
	    output("(FILE *, %TT, char *, int);\n", t);
314
	    output ( "#endif\n\n" ) ;
338
	    output("#endif\n\n");
315
	}
339
	}
316
    }
340
    }
317
    output ( "\n\n" ) ;
341
    output("\n\n");
318
 
342
 
319
    comment ( "Printing variables" ) ;
343
    comment("Printing variables");
320
    output ( "static int print_indent_step = 4 ;\n" ) ;
344
    output("static int print_indent_step = 4;\n");
321
    output ( "static int print_ptr_depth = 1 ;\n" ) ;
345
    output("static int print_ptr_depth = 1;\n");
322
    output ( "static int print_list_expand = 0 ;\n\n\n" ) ;
346
    output("static int print_list_expand = 0;\n\n\n");
323
 
347
 
324
    comment ( "Printing indentation routine" ) ;
348
    comment("Printing indentation routine");
325
    output ( "static void print_indent\n" ) ;
349
    output("static void print_indent\n");
326
    output ( "    PROTO_N ( ( f, d ) )\n" ) ;
350
    output("\n");
327
    output ( "    PROTO_T ( FILE *f X int d )\n" ) ;
351
    output("(FILE *f, int d)\n");
328
    output ( "{\n" ) ;
352
    output("{\n");
329
    output ( "    int i = print_indent_step * d ;\n" ) ;
353
    output("    int i = print_indent_step * d;\n");
330
    output ( "    while ( i-- ) ( void ) fputc ( ' ', f ) ;\n" ) ;
354
    output("    while (i--) (void)fputc(' ', f);\n");
331
    output ( "    return ;\n" ) ;
355
    output("    return;\n");
332
    output ( "}\n\n\n" ) ;
356
    output("}\n\n\n");
333
 
357
 
334
    /* Function definitions */
358
    /* Function definitions */
335
    LOOP_TYPE {
359
    LOOP_TYPE {
336
	TYPE_P t = CRT_TYPE ;
360
	TYPE_P t = CRT_TYPE;
337
	TYPE t0 = DEREF_type ( t ) ;
361
	TYPE t0 = DEREF_type(t);
338
	unsigned tag = TAG_type ( t0 ) ;
362
	unsigned tag = TAG_type(t0);
339
	if ( !is_identity_type ( t ) ) {
363
	if (!is_identity_type(t)) {
340
	    /* Function header */
364
	    /* Function header */
341
	    int is_struct = 0 ;
365
	    int is_struct = 0;
342
	    output ( "/* Printing routines for %TT */\n\n", t ) ;
366
	    output("/* Printing routines for %TT */\n\n", t);
343
	    output ( "#ifndef PRINT_%TI\n\n", t ) ;
367
	    output("#ifndef PRINT_%TI\n\n", t);
344
	    output ( "static void PRINT_%TI\n", t ) ;
368
	    output("static void\n");
345
	    output ( "    PROTO_N ( ( f_, x_, nm_, d_ ) )\n" ) ;
369
	    output("PRINT_%TI(FILE *f_, %TT x_, char *nm_, int d_)\n", t, t);
346
	    output ( "    PROTO_T ( FILE *f_ X %TT x_ X", t ) ;
-
 
347
	    output ( " char *nm_ X int d_ )\n" ) ;
-
 
348
	    output ( "{\n" ) ;
370
	    output("{\n");
349
 
371
 
350
	    /* Function body */
372
	    /* Function body */
351
	    switch ( tag ) {
373
	    switch (tag) {
352
		case type_primitive_tag : {
374
		case type_primitive_tag: {
353
		    PRIMITIVE_P p = DEREF_ptr ( type_primitive_prim ( t0 ) ) ;
375
		    PRIMITIVE_P p = DEREF_ptr(type_primitive_prim(t0));
354
		    LOOP_PRIMITIVE {
376
		    LOOP_PRIMITIVE {
355
			if ( EQ_ptr ( CRT_PRIMITIVE, p ) ) {
377
			if (EQ_ptr(CRT_PRIMITIVE, p)) {
356
			    printer_prim () ;
378
			    printer_prim();
357
			    break ;
379
			    break;
358
			}
380
			}
359
		    }
381
		    }
360
		    break ;
382
		    break;
361
		}
383
		}
362
		case type_enumeration_tag : {
384
		case type_enumeration_tag: {
363
		    ENUM_P p = DEREF_ptr ( type_enumeration_en ( t0 ) ) ;
385
		    ENUM_P p = DEREF_ptr(type_enumeration_en(t0));
364
		    LOOP_ENUM {
386
		    LOOP_ENUM {
365
			if ( EQ_ptr ( CRT_ENUM, p ) ) {
387
			if (EQ_ptr(CRT_ENUM, p)) {
366
			    printer_enum () ;
388
			    printer_enum();
367
			    break ;
389
			    break;
368
			}
390
			}
369
		    }
391
		    }
370
		    break ;
392
		    break;
371
		}
393
		}
372
		case type_structure_tag : {
394
		case type_structure_tag: {
373
		    STRUCTURE_P p = DEREF_ptr ( type_structure_struc ( t0 ) ) ;
395
		    STRUCTURE_P p = DEREF_ptr(type_structure_struc(t0));
374
		    LOOP_STRUCTURE {
396
		    LOOP_STRUCTURE {
375
			if ( EQ_ptr ( CRT_STRUCTURE, p ) ) {
397
			if (EQ_ptr(CRT_STRUCTURE, p)) {
376
			    printer_struct () ;
398
			    printer_struct();
377
			    break ;
399
			    break;
378
			}
400
			}
379
		    }
401
		    }
380
		    is_struct = 1 ;
402
		    is_struct = 1;
381
		    break ;
403
		    break;
382
		}
404
		}
383
		case type_onion_tag : {
405
		case type_onion_tag: {
384
		    UNION_P p = DEREF_ptr ( type_onion_un ( t0 ) ) ;
406
		    UNION_P p = DEREF_ptr(type_onion_un(t0));
385
		    LOOP_UNION {
407
		    LOOP_UNION {
386
			if ( EQ_ptr ( CRT_UNION, p ) ) {
408
			if (EQ_ptr(CRT_UNION, p)) {
387
			    printer_union () ;
409
			    printer_union();
388
			    break ;
410
			    break;
389
			}
411
			}
390
		    }
412
		    }
391
		    break ;
413
		    break;
392
		}
414
		}
393
		case type_ptr_tag : {
415
		case type_ptr_tag: {
394
		    TYPE_P s = DEREF_ptr ( type_ptr_sub ( t0 ) ) ;
416
		    TYPE_P s = DEREF_ptr(type_ptr_sub(t0));
395
		    printer_ptr ( s, "PTR", "x_", "" ) ;
417
		    printer_ptr(s, "PTR", "x_", "");
396
		    break ;
418
		    break;
397
		}
419
		}
398
		case type_list_tag : {
420
		case type_list_tag: {
399
		    TYPE_P s = DEREF_ptr ( type_list_sub ( t0 ) ) ;
421
		    TYPE_P s = DEREF_ptr(type_list_sub(t0));
400
		    printer_list ( s, "x_" ) ;
422
		    printer_list(s, "x_");
401
		    break ;
423
		    break;
402
		}
424
		}
403
		case type_stack_tag : {
425
		case type_stack_tag: {
404
		    TYPE_P s = DEREF_ptr ( type_stack_sub ( t0 ) ) ;
426
		    TYPE_P s = DEREF_ptr(type_stack_sub(t0));
405
		    output ( "    LIST ( %TT ) y_ = LIST_stack ( x_ ) ;\n", s ) ;
427
		    output("    LIST(%TT) y_ = LIST_stack(x_);\n", s);
406
		    printer_list ( s, "y_" ) ;
428
		    printer_list(s, "y_");
407
		    break ;
429
		    break;
408
		}
430
		}
409
		case type_vec_tag : {
431
		case type_vec_tag: {
410
		    TYPE_P s = DEREF_ptr ( type_vec_sub ( t0 ) ) ;
432
		    TYPE_P s = DEREF_ptr(type_vec_sub(t0));
411
		    printer_vec ( s ) ;
433
		    printer_vec(s);
412
		    is_struct = 1 ;
434
		    is_struct = 1;
413
		    break ;
435
		    break;
414
		}
436
		}
415
		case type_vec_ptr_tag : {
437
		case type_vec_ptr_tag: {
416
		    TYPE_P s = DEREF_ptr ( type_vec_ptr_sub ( t0 ) ) ;
438
		    TYPE_P s = DEREF_ptr(type_vec_ptr_sub(t0));
417
		    printer_vec_ptr ( s ) ;
439
		    printer_vec_ptr(s);
418
		    is_struct = 1 ;
440
		    is_struct = 1;
419
		    break ;
441
		    break;
420
		}
442
		}
421
	    }
443
	    }
422
 
444
 
423
	    /* Function trailer */
445
	    /* Function trailer */
424
	    output ( "    return ;\n" ) ;
446
	    output("    return;\n");
425
	    output ( "}\n\n" ) ;
447
	    output("}\n\n");
426
 
448
 
427
	    /* Debugging routine */
449
	    /* Debugging routine */
428
	    if ( extra_asserts ) {
450
	    if (extra_asserts) {
429
		char *star = ( is_struct ? "*" : "" ) ;
451
		char *star = (is_struct ? "*" : "");
430
		output ( "#ifdef DEBUG\n\n" ) ;
452
		output("#ifdef DEBUG\n\n");
431
		output ( "void DEBUG_%TI\n", t ) ;
453
		output("void\n");
432
		output ( "    PROTO_N ( ( x_ ) )\n" ) ;
-
 
433
		output ( "    PROTO_T ( %TT %sx_ )\n", t, star ) ;
454
		output("DEBUG_%TI(%TT %sx_)\n", t, t, star);
434
		output ( "{\n    " ) ;
455
		output("{\n    ");
-
 
456
		if (is_struct) {
435
		if ( is_struct ) output ( "if ( x_ ) " ) ;
457
			output("if (x_)");
-
 
458
		}
436
		output ( "PRINT_%TI ( stdout, %sx_, ", t, star ) ;
459
		output("PRINT_%TI(stdout, %sx_, ", t, star);
437
		output ( "\"%TI\", 0 ) ;\n", t ) ;
460
		output("\"%TI\", 0);\n", t);
438
		output ( "    return ;\n" ) ;
461
		output("    return;\n");
439
		output ( "}\n\n" ) ;
462
		output("}\n\n");
440
		output ( "#endif\n\n" ) ;
463
		output("#endif\n\n");
441
	    }
464
	    }
442
	    output ( "#endif\n\n\n" ) ;
465
	    output("#endif\n\n\n");
443
	}
466
	}
444
    }
467
    }
445
 
468
 
446
    close_file () ;
469
    close_file();
447
    return ;
470
    return;
448
}
471
}