Warning: Undefined variable $n in /usr/local/www/websvn.planix.org/include/diff_util.php on line 243

Warning: Undefined variable $n in /usr/local/www/websvn.planix.org/include/diff_util.php on line 247

Warning: Undefined variable $m in /usr/local/www/websvn.planix.org/include/diff_util.php on line 251

Warning: Undefined variable $n in /usr/local/www/websvn.planix.org/include/diff_util.php on line 243

Warning: Undefined variable $n in /usr/local/www/websvn.planix.org/include/diff_util.php on line 247

Warning: Undefined variable $m in /usr/local/www/websvn.planix.org/include/diff_util.php on line 251
WebSVN – tendra.SVN – Diff – /trunk/src/producers/common/utility/print.c – Rev 2 and 7

Subversion Repositories tendra.SVN

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 7
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2006 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 76... Line 106...
76
    PRINT BUFFER
106
    PRINT BUFFER
77
 
107
 
78
    This buffer is used for the error output.
108
    This buffer is used for the error output.
79
*/
109
*/
80
 
110
 
81
BUFFER print_buff = NULL_buff ;
111
BUFFER print_buff = NULL_buff;
82
 
112
 
83
 
113
 
84
/*
114
/*
85
    FUNCTION DECLARATIONS
115
    FUNCTION DECLARATIONS
86
 
116
 
87
    A couple of forward function declarations are necessary.
117
    A couple of forward function declarations are necessary.
88
*/
118
*/
89
 
119
 
90
static int print_head PROTO_S ( ( TYPE, int, BUFFER *, int ) ) ;
120
static int print_head(TYPE, int, BUFFER *, int);
91
static int print_tail PROTO_S ( ( TYPE, BUFFER *, int ) ) ;
121
static int print_tail(TYPE, BUFFER *, int);
92
 
122
 
93
 
123
 
94
/*
124
/*
95
    PRINT FLAGS
125
    PRINT FLAGS
96
 
126
 
97
    These flags are used to control the form of the output.
127
    These flags are used to control the form of the output.
98
*/
128
*/
99
 
129
 
100
static int print_default_args = 0 ;
130
static int print_default_args = 0;
101
static int print_member_type = 0 ;
131
static int print_member_type = 0;
102
static int print_return_type = 1 ;
132
static int print_return_type = 1;
103
static int print_func_params = 0 ;
133
static int print_func_params = 0;
104
static int print_except = 0 ;
134
static int print_except = 0;
105
static int print_func_linkage = 0 ;
135
static int print_func_linkage = 0;
106
static int print_parent_namespace = 1 ;
136
static int print_parent_namespace = 1;
107
static int print_bitfield_sep = ':' ;
137
static int print_bitfield_sep = ':';
108
int print_c_style = LANGUAGE_C ;
138
int print_c_style = LANGUAGE_C;
109
int print_type_alias = 0 ;
139
int print_type_alias = 0;
110
int print_uniq_anon = 0 ;
140
int print_uniq_anon = 0;
111
int print_id_desc = 0 ;
141
int print_id_desc = 0;
112
 
142
 
113
 
143
 
114
/*
144
/*
115
    PRINT A LEXICAL TOKEN NAME
145
    PRINT A LEXICAL TOKEN NAME
116
 
146
 
117
    This routine prints the name of the lexical token t to the buffer bf.
147
    This routine prints the name of the lexical token t to the buffer bf.
118
    With all the routines in this file the sp argument is true if a space
148
    With all the routines in this file the sp argument is true if a space
119
    should be printed before the actual text, and the return value is true
149
    should be printed before the actual text, and the return value is true
120
    if a space should be printed after it.
150
    if a space should be printed after it.
121
*/
151
*/
122
 
152
 
123
int print_lex
153
int
124
    PROTO_N ( ( t, bf, sp ) )
-
 
125
    PROTO_T ( int t X BUFFER *bf X int sp )
154
print_lex(int t, BUFFER *bf, int sp)
126
{
155
{
127
    string s = token_name ( t ) ;
156
	string s = token_name(t);
128
    if ( s == NULL ) return ( sp ) ;
157
	if (s == NULL) {
-
 
158
		return (sp);
-
 
159
	}
-
 
160
	if (sp) {
129
    if ( sp ) bfputc ( bf, ' ' ) ;
161
		bfputc(bf, ' ');
-
 
162
	}
130
    bfputs ( bf, s ) ;
163
	bfputs(bf, s);
131
    return ( 1 ) ;
164
	return (1);
132
}
165
}
133
 
166
 
134
 
167
 
135
/*
168
/*
136
    PRINT AN ACCESS SPECIFIER
169
    PRINT AN ACCESS SPECIFIER
137
 
170
 
138
    This routine prints the access specifier n to the buffer bf.
171
    This routine prints the access specifier n to the buffer bf.
139
*/
172
*/
140
 
173
 
141
int print_access
174
int
142
    PROTO_N ( ( n, bf, sp ) )
-
 
143
    PROTO_T ( DECL_SPEC n X BUFFER *bf X int sp )
175
print_access(DECL_SPEC n, BUFFER *bf, int sp)
144
{
176
{
145
    int t ;
177
	int t;
146
    DECL_SPEC a = ( n & dspec_access ) ;
178
	DECL_SPEC a = (n & dspec_access);
147
    if ( a == dspec_private ) {
179
	if (a == dspec_private) {
148
	t = lex_private ;
180
		t = lex_private;
149
    } else if ( a == dspec_protected ) {
181
	} else if (a == dspec_protected) {
150
	t = lex_protected ;
182
		t = lex_protected;
151
    } else {
183
	} else {
152
	t = lex_public ;
184
		t = lex_public;
153
    }
185
	}
154
    sp = print_lex ( t, bf, sp ) ;
186
	sp = print_lex(t, bf, sp);
155
    return ( sp ) ;
187
	return (sp);
156
}
188
}
157
 
189
 
158
 
190
 
159
/*
191
/*
160
    BUILT-IN TYPE NAMES
192
    BUILT-IN TYPE NAMES
161
 
193
 
162
    This table gives the names of the built-in types.
194
    This table gives the names of the built-in types.
163
*/
195
*/
164
 
196
 
165
CONST char *ntype_name [ ORDER_ntype ] = {
197
CONST char *ntype_name[ORDER_ntype] = {
166
    "<error>",			/* ntype_none */
198
	"<error>",		/* ntype_none */
167
    "char",			/* ntype_char */
199
	"char",			/* ntype_char */
168
    "signed char",		/* ntype_schar */
200
	"signed char",		/* ntype_schar */
169
    "unsigned char",		/* ntype_uchar */
201
	"unsigned char",	/* ntype_uchar */
170
    "short",			/* ntype_sshort */
202
	"short",		/* ntype_sshort */
171
    "unsigned short",		/* ntype_ushort */
203
	"unsigned short",	/* ntype_ushort */
172
    "int",			/* ntype_sint */
204
	"int",			/* ntype_sint */
173
    "unsigned int",		/* ntype_uint */
205
	"unsigned int",		/* ntype_uint */
174
    "long",			/* ntype_slong */
206
	"long",			/* ntype_slong */
175
    "unsigned long",		/* ntype_ulong */
207
	"unsigned long",	/* ntype_ulong */
176
    "long long",		/* ntype_sllong */
208
	"long long",		/* ntype_sllong */
177
    "unsigned long long",	/* ntype_ullong */
209
	"unsigned long long",	/* ntype_ullong */
178
    "float",			/* ntype_float */
210
	"float",		/* ntype_float */
179
    "double",			/* ntype_double */
211
	"double",		/* ntype_double */
180
    "long double",		/* ntype_ldouble */
212
	"long double",		/* ntype_ldouble */
181
    "void",			/* ntype_void */
213
	"void",			/* ntype_void */
182
    "<bottom>",			/* ntype_bottom */
214
	"<bottom>",		/* ntype_bottom */
183
    "bool",			/* ntype_bool */
215
	"bool",			/* ntype_bool */
184
    "ptrdiff_t",		/* ntype_ptrdiff_t */
216
	"ptrdiff_t",		/* ntype_ptrdiff_t */
185
    "size_t",			/* ntype_size_t */
217
	"size_t",		/* ntype_size_t */
186
    "wchar_t",			/* ntype_wchar_t */
218
	"wchar_t",		/* ntype_wchar_t */
187
    "..."			/* ntype_ellipsis */
219
	"..."			/* ntype_ellipsis */
188
} ;
220
};
189
 
-
 
190
 
-
 
191
/*
-
 
192
    PRINT A BUILT-IN TYPE
-
 
193
 
-
 
194
    This routine prints the built-in type n to the buffer bf.
-
 
195
*/
-
 
196
 
-
 
197
int print_ntype
-
 
198
    PROTO_N ( ( n, bf, sp ) )
-
 
199
    PROTO_T ( BUILTIN_TYPE n X BUFFER *bf X int sp )
-
 
200
{
-
 
201
    if ( sp ) bfputc ( bf, ' ' ) ;
-
 
202
    bfputs ( bf, ustrlit ( ntype_name [n] ) ) ;
-
 
203
    return ( 1 ) ;
-
 
204
}
-
 
205
 
221
 
206
 
222
 
207
/*
223
/*
208
    PRINT A BASE TYPE
224
    PRINT A BUILT-IN TYPE
209
 
225
 
210
    This routine prints the base type n to the buffer bf.
226
    This routine prints the built-in type n to the buffer bf.
211
*/
227
*/
212
 
228
 
213
int print_btype
229
int
214
    PROTO_N ( ( n, bf, sp ) )
-
 
215
    PROTO_T ( BASE_TYPE n X BUFFER *bf X int sp )
230
print_ntype(BUILTIN_TYPE n, BUFFER *bf, int sp)
216
{
231
{
217
    BASE_TYPE key = ( n & btype_named ) ;
-
 
218
    if ( key ) {
232
	if (sp) {
219
	switch ( key ) {
233
		bfputc(bf, ' ');
220
	    case btype_class : sp = print_lex ( lex_class, bf, sp ) ; break ;
-
 
221
	    case btype_struct : sp = print_lex ( lex_struct, bf, sp ) ; break ;
-
 
222
	    case btype_union : sp = print_lex ( lex_union, bf, sp ) ; break ;
-
 
223
	    case btype_enum : sp = print_lex ( lex_enum, bf, sp ) ; break ;
-
 
224
	    case btype_any : sp = print_lex ( lex_tag_Hcap, bf, sp ) ; break ;
-
 
225
	}
234
	}
-
 
235
	bfputs(bf, ustrlit(ntype_name[n]));
-
 
236
	return (1);
-
 
237
}
-
 
238
 
-
 
239
 
-
 
240
/*
-
 
241
    PRINT A BASE TYPE
-
 
242
 
-
 
243
    This routine prints the base type n to the buffer bf.
-
 
244
*/
-
 
245
 
-
 
246
int
-
 
247
print_btype(BASE_TYPE n, BUFFER *bf, int sp)
-
 
248
{
-
 
249
	BASE_TYPE key = (n & btype_named);
-
 
250
	if (key) {
-
 
251
		switch (key) {
-
 
252
		case btype_class:
-
 
253
			sp = print_lex(lex_class, bf, sp);
-
 
254
			break;
-
 
255
		case btype_struct:
-
 
256
			sp = print_lex(lex_struct, bf, sp);
-
 
257
			break;
-
 
258
		case btype_union:
-
 
259
			sp = print_lex(lex_union, bf, sp);
-
 
260
			break;
-
 
261
		case btype_enum:
-
 
262
			sp = print_lex(lex_enum, bf, sp);
-
 
263
			break;
-
 
264
		case btype_any:
-
 
265
			sp = print_lex(lex_tag_Hcap, bf, sp);
-
 
266
			break;
-
 
267
		}
226
    } else {
268
	} else {
-
 
269
		if (n & btype_signed) {
227
	if ( n & btype_signed ) sp = print_lex ( lex_signed, bf, sp ) ;
270
			sp = print_lex(lex_signed, bf, sp);
-
 
271
		}
-
 
272
		if (n & btype_unsigned) {
228
	if ( n & btype_unsigned ) sp = print_lex ( lex_unsigned, bf, sp ) ;
273
			sp = print_lex(lex_unsigned, bf, sp);
-
 
274
		}
-
 
275
		if (n & btype_short) {
229
	if ( n & btype_short ) sp = print_lex ( lex_short, bf, sp ) ;
276
			sp = print_lex(lex_short, bf, sp);
-
 
277
		}
-
 
278
		if (n & btype_long) {
230
	if ( n & btype_long ) sp = print_lex ( lex_long, bf, sp ) ;
279
			sp = print_lex(lex_long, bf, sp);
-
 
280
		}
-
 
281
		if (n & btype_long2) {
231
	if ( n & btype_long2 ) sp = print_lex ( lex_long, bf, sp ) ;
282
			sp = print_lex(lex_long, bf, sp);
-
 
283
		}
-
 
284
		if (n & btype_char) {
232
	if ( n & btype_char ) sp = print_lex ( lex_char, bf, sp ) ;
285
			sp = print_lex(lex_char, bf, sp);
-
 
286
		}
-
 
287
		if (n & btype_int) {
233
	if ( n & btype_int ) sp = print_lex ( lex_int, bf, sp ) ;
288
			sp = print_lex(lex_int, bf, sp);
-
 
289
		}
-
 
290
		if (n & btype_float) {
234
	if ( n & btype_float ) sp = print_lex ( lex_float, bf, sp ) ;
291
			sp = print_lex(lex_float, bf, sp);
-
 
292
		}
-
 
293
		if (n & btype_double) {
235
	if ( n & btype_double ) sp = print_lex ( lex_double, bf, sp ) ;
294
			sp = print_lex(lex_double, bf, sp);
-
 
295
		}
-
 
296
		if (n & btype_void) {
236
	if ( n & btype_void ) sp = print_lex ( lex_void, bf, sp ) ;
297
			sp = print_lex(lex_void, bf, sp);
-
 
298
		}
-
 
299
		if (n & btype_bottom) {
237
	if ( n & btype_bottom ) sp = print_lex ( lex_bottom, bf, sp ) ;
300
			sp = print_lex(lex_bottom, bf, sp);
-
 
301
		}
-
 
302
		if (n & btype_bool) {
238
	if ( n & btype_bool ) sp = print_lex ( lex_bool, bf, sp ) ;
303
			sp = print_lex(lex_bool, bf, sp);
-
 
304
		}
-
 
305
		if (n & btype_ptrdiff_t) {
239
	if ( n & btype_ptrdiff_t ) sp = print_lex ( lex_ptrdiff_Ht, bf, sp ) ;
306
			sp = print_lex(lex_ptrdiff_Ht, bf, sp);
-
 
307
		}
-
 
308
		if (n & btype_size_t) {
240
	if ( n & btype_size_t ) sp = print_lex ( lex_size_Ht, bf, sp ) ;
309
			sp = print_lex(lex_size_Ht, bf, sp);
-
 
310
		}
-
 
311
		if (n & btype_wchar_t) {
241
	if ( n & btype_wchar_t ) sp = print_lex ( lex_wchar_Ht, bf, sp ) ;
312
			sp = print_lex(lex_wchar_Ht, bf, sp);
-
 
313
		}
-
 
314
		if (n & btype_ellipsis) {
242
	if ( n & btype_ellipsis ) sp = print_lex ( lex_ellipsis, bf, sp ) ;
315
			sp = print_lex(lex_ellipsis, bf, sp);
-
 
316
		}
-
 
317
		if (n & btype_star) {
243
	if ( n & btype_star ) sp = print_lex ( lex_star, bf, sp ) ;
318
			sp = print_lex(lex_star, bf, sp);
244
    }
319
		}
-
 
320
	}
245
    return ( sp ) ;
321
	return (sp);
246
}
322
}
247
 
323
 
248
 
324
 
249
/*
325
/*
250
    PRINT A CONST-VOLATILE QUALIFIER
326
    PRINT A CONST-VOLATILE QUALIFIER
251
 
327
 
252
    This routine prints the const-volatile qualifier n to the buffer bf.
328
    This routine prints the const-volatile qualifier n to the buffer bf.
253
*/
329
*/
254
 
330
 
255
int print_cv
331
int
256
    PROTO_N ( ( n, bf, sp ) )
-
 
257
    PROTO_T ( CV_SPEC n X BUFFER *bf X int sp )
332
print_cv(CV_SPEC n, BUFFER *bf, int sp)
258
{
333
{
259
    if ( n ) {
334
	if (n) {
-
 
335
		if (n & cv_const) {
260
	if ( n & cv_const ) sp = print_lex ( lex_const, bf, sp ) ;
336
			sp = print_lex(lex_const, bf, sp);
-
 
337
		}
-
 
338
		if (n & cv_volatile) {
261
	if ( n & cv_volatile ) sp = print_lex ( lex_volatile, bf, sp ) ;
339
			sp = print_lex(lex_volatile, bf, sp);
262
    }
340
		}
-
 
341
	}
263
    return ( sp ) ;
342
	return (sp);
264
}
343
}
265
 
344
 
266
 
345
 
267
/*
346
/*
268
    PRINT A DECLARATION SPECIFIER
347
    PRINT A DECLARATION SPECIFIER
269
 
348
 
270
    This routine prints the declaration specifier n to the buffer bf.  The
349
    This routine prints the declaration specifier n to the buffer bf.  The
271
    C and C++ linkage specifiers are not included.
350
    C and C++ linkage specifiers are not included.
272
*/
351
*/
273
 
352
 
274
int print_dspec
353
int
275
    PROTO_N ( ( n, bf, sp ) )
-
 
276
    PROTO_T ( DECL_SPEC n X BUFFER *bf X int sp )
354
print_dspec(DECL_SPEC n, BUFFER *bf, int sp)
277
{
355
{
-
 
356
	if (n & dspec_typedef) {
278
    if ( n & dspec_typedef ) sp = print_lex ( lex_typedef, bf, sp ) ;
357
		sp = print_lex(lex_typedef, bf, sp);
-
 
358
	}
279
    if ( n & dspec_storage ) {
359
	if (n & dspec_storage) {
-
 
360
		if (n & dspec_extern) {
280
	if ( n & dspec_extern ) sp = print_lex ( lex_extern, bf, sp ) ;
361
			sp = print_lex(lex_extern, bf, sp);
-
 
362
		}
-
 
363
		if (n & dspec_static) {
281
	if ( n & dspec_static ) sp = print_lex ( lex_static, bf, sp ) ;
364
			sp = print_lex(lex_static, bf, sp);
-
 
365
		}
-
 
366
		if (n & dspec_register) {
282
	if ( n & dspec_register ) sp = print_lex ( lex_register, bf, sp ) ;
367
			sp = print_lex(lex_register, bf, sp);
-
 
368
		}
-
 
369
		if (n & dspec_auto) {
283
	if ( n & dspec_auto ) sp = print_lex ( lex_auto, bf, sp ) ;
370
			sp = print_lex(lex_auto, bf, sp);
-
 
371
		}
-
 
372
		if (n & dspec_mutable) {
284
	if ( n & dspec_mutable ) sp = print_lex ( lex_mutable, bf, sp ) ;
373
			sp = print_lex(lex_mutable, bf, sp);
285
    }
374
		}
-
 
375
	}
286
    if ( n & dspec_function ) {
376
	if (n & dspec_function) {
-
 
377
		if (n & dspec_explicit) {
287
	if ( n & dspec_explicit ) sp = print_lex ( lex_explicit, bf, sp ) ;
378
			sp = print_lex(lex_explicit, bf, sp);
-
 
379
		}
-
 
380
		if (n & dspec_friend) {
288
	if ( n & dspec_friend ) sp = print_lex ( lex_friend, bf, sp ) ;
381
			sp = print_lex(lex_friend, bf, sp);
-
 
382
		}
-
 
383
		if (n & dspec_inline) {
289
	if ( n & dspec_inline ) sp = print_lex ( lex_inline, bf, sp ) ;
384
			sp = print_lex(lex_inline, bf, sp);
-
 
385
		}
-
 
386
		if (n & dspec_virtual) {
290
	if ( n & dspec_virtual ) sp = print_lex ( lex_virtual, bf, sp ) ;
387
			sp = print_lex(lex_virtual, bf, sp);
291
    }
388
		}
-
 
389
	}
292
    return ( sp ) ;
390
	return (sp);
293
}
391
}
294
 
392
 
295
 
393
 
296
/*
394
/*
297
    PRINT A LINKAGE SPECIFIER
395
    PRINT A LINKAGE SPECIFIER
298
 
396
 
299
    This routine prints the linkage specifier n to the buffer bf.
397
    This routine prints the linkage specifier n to the buffer bf.
300
*/
398
*/
301
 
399
 
302
static int print_linkage
400
static int
303
    PROTO_N ( ( n, bf, sp ) )
-
 
304
    PROTO_T ( CV_SPEC n X BUFFER *bf X int sp )
401
print_linkage(CV_SPEC n, BUFFER *bf, int sp)
305
{
402
{
306
    CV_SPEC m = ( n & cv_language ) ;
403
	CV_SPEC m = (n & cv_language);
307
    if ( m ) {
404
	if (m) {
308
	if ( m != cv_cpp && !print_c_style ) {
405
		if (m != cv_cpp && !print_c_style) {
309
	    string s = linkage_string ( dspec_none, m ) ;
406
			string s = linkage_string(dspec_none, m);
-
 
407
			if (sp) {
310
	    if ( sp ) bfputc ( bf, ' ' ) ;
408
				bfputc(bf, ' ');
-
 
409
			}
311
	    bfprintf ( bf, "extern \"%s\"", s ) ;
410
			bfprintf(bf, "extern \"%s\"", s);
312
	    sp = 1 ;
411
			sp = 1;
-
 
412
		}
313
	}
413
	}
314
    }
-
 
315
    return ( sp ) ;
414
	return (sp);
316
}
415
}
317
 
416
 
318
 
417
 
319
/*
418
/*
320
    PRINT A BUFFER LOCATION
419
    PRINT A BUFFER LOCATION
Line 322... Line 421...
322
    This routine prints the file location p to the buffer bf.  q gives
421
    This routine prints the file location p to the buffer bf.  q gives
323
    the main location.  If the file names from p and q match then only
422
    the main location.  If the file names from p and q match then only
324
    the line number is printed.
423
    the line number is printed.
325
*/
424
*/
326
 
425
 
327
int print_loc
426
int
328
    PROTO_N ( ( p, q, bf, sp ) )
-
 
329
    PROTO_T ( LOCATION *p X LOCATION *q X BUFFER *bf X int sp )
427
print_loc(LOCATION *p, LOCATION *q, BUFFER *bf, int sp)
330
{
428
{
331
    string fn ;
429
	string fn;
332
    unsigned long ln ;
430
	unsigned long ln;
333
    if ( sp ) bfputc ( bf, ' ' ) ;
-
 
334
    if ( p == NULL ) {
-
 
335
	fn = ustrlit ( "<unknown>" ) ;
-
 
336
	ln = 0 ;
-
 
337
    } else {
-
 
338
	PTR ( POSITION ) pa = p->posn ;
-
 
339
	if ( IS_NULL_ptr ( pa ) ) {
-
 
340
	    fn = ustrlit ( "<unknown>" ) ;
-
 
341
	} else {
-
 
342
	    fn = DEREF_string ( posn_file ( pa ) ) ;
-
 
343
	    if ( q ) {
431
	if (sp) {
344
		/* Check previous location */
-
 
345
		PTR ( POSITION ) qa = q->posn ;
-
 
346
		if ( EQ_ptr ( qa, pa ) ) {
432
		bfputc(bf, ' ');
347
		    fn = NULL ;
-
 
348
		} else if ( !IS_NULL_ptr ( qa ) ) {
-
 
349
		    string gn = DEREF_string ( posn_file ( qa ) ) ;
-
 
350
		    if ( ustreq ( gn, fn ) ) fn = NULL ;
-
 
351
		}
-
 
352
	    }
-
 
353
	}
433
	}
-
 
434
	if (p == NULL) {
-
 
435
		fn = ustrlit("<unknown>");
-
 
436
		ln = 0;
-
 
437
	} else {
-
 
438
		PTR(POSITION)pa = p->posn;
-
 
439
		if (IS_NULL_ptr(pa)) {
-
 
440
			fn = ustrlit("<unknown>");
-
 
441
		} else {
-
 
442
			fn = DEREF_string(posn_file(pa));
-
 
443
			if (q) {
-
 
444
				/* Check previous location */
-
 
445
				PTR(POSITION)qa = q->posn;
-
 
446
				if (EQ_ptr(qa, pa)) {
-
 
447
					fn = NULL;
-
 
448
				} else if (!IS_NULL_ptr(qa)) {
-
 
449
					string gn = DEREF_string(posn_file(qa));
-
 
450
					if (ustreq(gn, fn)) {
-
 
451
						fn = NULL;
-
 
452
					}
-
 
453
				}
-
 
454
			}
-
 
455
		}
354
	ln = p->line ;
456
		ln = p->line;
355
    }
457
	}
356
    if ( fn ) {
458
	if (fn) {
357
	bfprintf ( bf, "\"%s\"", fn ) ;
459
		bfprintf(bf, "\"%s\"", fn);
-
 
460
		if (ln) {
358
	if ( ln ) bfprintf ( bf, ", line %lu", ln ) ;
461
			bfprintf(bf, ", line %lu", ln);
-
 
462
		}
359
    } else {
463
	} else {
360
	bfprintf ( bf, "line %lu", ln ) ;
464
		bfprintf(bf, "line %lu", ln);
361
    }
465
	}
362
    return ( 1 ) ;
466
	return (1);
363
}
467
}
364
 
468
 
365
 
469
 
366
/*
470
/*
367
    PRINT A HASH TABLE ENTRY
471
    PRINT A HASH TABLE ENTRY
368
 
472
 
369
    This routine prints the identifier name corresponding to the hash
473
    This routine prints the identifier name corresponding to the hash
370
    table entry p to the buffer bf.
474
    table entry p to the buffer bf.
371
*/
475
*/
372
 
476
 
373
int print_hashid
477
int
374
    PROTO_N ( ( p, sep, anon, bf, sp ) )
-
 
375
    PROTO_T ( HASHID p X int sep X int anon X BUFFER *bf X int sp )
478
print_hashid(HASHID p, int sep, int anon, BUFFER *bf, int sp)
376
{
479
{
377
    unsigned tag ;
480
	unsigned tag;
378
    if ( IS_NULL_hashid ( p ) ) return ( sp ) ;
481
	if (IS_NULL_hashid(p)) {
-
 
482
		return (sp);
-
 
483
	}
379
    tag = TAG_hashid ( p ) ;
484
	tag = TAG_hashid(p);
380
    ASSERT ( ORDER_hashid == 7 ) ;
485
	ASSERT(ORDER_hashid == 7);
381
    switch ( tag ) {
486
	switch (tag) {
382
	case hashid_name_tag :
487
	case hashid_name_tag:
383
	case hashid_ename_tag : {
488
	case hashid_ename_tag: {
384
	    /* Simple name */
489
		/* Simple name */
385
	    string s = DEREF_string ( hashid_name_etc_text ( p ) ) ;
490
		string s = DEREF_string(hashid_name_etc_text(p));
-
 
491
		if (sp) {
386
	    if ( sp ) bfputc ( bf, ' ' ) ;
492
			bfputc(bf, ' ');
-
 
493
		}
387
	    bfputs ( bf, s ) ;
494
		bfputs(bf, s);
388
	    sp = 1 ;
495
		sp = 1;
389
	    break ;
496
		break;
390
	}
497
	}
391
	case hashid_constr_tag :
498
	case hashid_constr_tag:
392
	case hashid_destr_tag : {
499
	case hashid_destr_tag: {
393
	    /* Class destructor name */
500
		/* Class destructor name */
394
	    IDENTIFIER tid = DEREF_id ( hashid_constr_etc_tid ( p ) ) ;
501
		IDENTIFIER tid = DEREF_id(hashid_constr_etc_tid(p));
395
	    if ( IS_NULL_id ( tid ) ) {
502
		if (IS_NULL_id(tid)) {
396
		/* Unnamed constructor or destructor */
503
			/* Unnamed constructor or destructor */
397
		TYPE t = DEREF_type ( hashid_constr_etc_type ( p ) ) ;
504
			TYPE t = DEREF_type(hashid_constr_etc_type(p));
398
		if ( sep ) {
505
			if (sep) {
399
		    IGNORE print_type ( t, bf, sp ) ;
506
				IGNORE print_type(t, bf, sp);
400
		    bfprintf ( bf, "::" ) ;
507
				bfprintf(bf, "::");
401
		} else {
508
			} else {
402
		    if ( sp ) bfputc ( bf, ' ' ) ;
509
				if (sp)bfputc(bf, ' ');
403
		}
510
			}
404
		if ( tag == hashid_destr_tag ) bfputc ( bf, '~' ) ;
511
			if (tag == hashid_destr_tag) {
-
 
512
				bfputc(bf, '~');
-
 
513
			}
405
		sp = print_type ( t, bf, 0 ) ;
514
			sp = print_type(t, bf, 0);
406
	    } else {
515
		} else {
407
		/* Named constructor or destructor */
516
			/* Named constructor or destructor */
408
		static HASHID lastp = NULL_hashid ;
517
			static HASHID lastp = NULL_hashid;
409
		if ( sep && !EQ_hashid ( p, lastp ) ) {
518
			if (sep && !EQ_hashid(p, lastp)) {
410
		    lastp = p ;
519
				lastp = p;
411
		    tid = DEREF_id ( hashid_id ( p ) ) ;
520
				tid = DEREF_id(hashid_id(p));
412
		    sp = print_id_short ( tid, qual_none, bf, sp ) ;
521
				sp = print_id_short(tid, qual_none, bf, sp);
413
		    lastp = NULL_hashid ;
522
				lastp = NULL_hashid;
414
		    break ;
523
				break;
-
 
524
			}
-
 
525
			p = DEREF_hashid(id_name(tid));
-
 
526
			if (sp) {
-
 
527
				bfputc(bf, ' ');
-
 
528
			}
-
 
529
			if (sep) {
-
 
530
				IGNORE print_hashid(p, 0, 1, bf, 0);
-
 
531
				bfprintf(bf, "::");
-
 
532
			}
-
 
533
			if (tag == hashid_destr_tag) {
-
 
534
				bfputc(bf, '~');
-
 
535
			}
-
 
536
			sp = print_hashid(p, 0, 1, bf, 0);
415
		}
537
		}
-
 
538
		break;
-
 
539
	}
-
 
540
	case hashid_conv_tag: {
-
 
541
		/* Overloaded conversion name */
-
 
542
		int prt = print_return_type;
416
		p = DEREF_hashid ( id_name ( tid ) ) ;
543
		TYPE t = DEREF_type(hashid_conv_type(p));
-
 
544
		sp = print_lex(lex_operator, bf, sp);
-
 
545
		print_return_type = 1;
417
		if ( sp ) bfputc ( bf, ' ' ) ;
546
		sp = print_type(t, bf, sp);
-
 
547
		print_return_type = prt;
-
 
548
		break;
-
 
549
	}
-
 
550
	case hashid_op_tag: {
-
 
551
		/* Overloaded operator name */
-
 
552
		int op = DEREF_int(hashid_op_lex(p));
-
 
553
		string s = token_name(op);
-
 
554
		sp = print_lex(lex_operator, bf, sp);
418
		if ( sep ) {
555
		if (s) {
-
 
556
			int c = (int)*s;
-
 
557
			if (isalpha(c)) {
419
		    IGNORE print_hashid ( p, 0, 1, bf, 0 ) ;
558
				bfputc(bf, ' ');
-
 
559
			}
420
		    bfprintf ( bf, "::" ) ;
560
			bfputs(bf, s);
421
		}
561
		}
422
		if ( tag == hashid_destr_tag ) bfputc ( bf, '~' ) ;
-
 
423
		sp = print_hashid ( p, 0, 1, bf, 0 ) ;
-
 
424
	    }
-
 
425
	    break ;
562
		break;
426
	}
563
	}
427
	case hashid_conv_tag : {
564
	case hashid_anon_tag: {
428
	    /* Overloaded conversion name */
565
		/* Anonymous identifier */
429
	    int prt = print_return_type ;
566
		if (anon) {
430
	    TYPE t = DEREF_type ( hashid_conv_type ( p ) ) ;
567
			unsigned long u = DEREF_ulong(hashid_anon_uniq(p));
-
 
568
			if (sp) {
431
	    sp = print_lex ( lex_operator, bf, sp ) ;
569
				bfputc(bf, ' ');
-
 
570
			}
432
	    print_return_type = 1 ;
571
			if (print_uniq_anon) {
433
	    sp = print_type ( t, bf, sp ) ;
572
				bfprintf(bf, "<anon%x.%lu>", uniq_string, u);
-
 
573
			} else {
434
	    print_return_type = prt ;
574
				bfprintf(bf, "<anon%lu>", u);
-
 
575
			}
-
 
576
			sp = 1;
-
 
577
		}
435
	    break ;
578
		break;
436
	}
579
	}
437
	case hashid_op_tag : {
-
 
438
	    /* Overloaded operator name */
-
 
439
	    int op = DEREF_int ( hashid_op_lex ( p ) ) ;
-
 
440
	    string s = token_name ( op ) ;
-
 
441
	    sp = print_lex ( lex_operator, bf, sp ) ;
-
 
442
	    if ( s ) {
-
 
443
		int c = ( int ) *s ;
-
 
444
		if ( isalpha ( c ) ) bfputc ( bf, ' ' ) ;
-
 
445
		bfputs ( bf, s ) ;
-
 
446
	    }
-
 
447
	    break ;
-
 
448
	}
580
	}
449
	case hashid_anon_tag : {
-
 
450
	    /* Anonymous identifier */
-
 
451
	    if ( anon ) {
-
 
452
		unsigned long u = DEREF_ulong ( hashid_anon_uniq ( p ) ) ;
-
 
453
		if ( sp ) bfputc ( bf, ' ' ) ;
-
 
454
		if ( print_uniq_anon ) {
-
 
455
		    bfprintf ( bf, "<anon%x.%lu>", uniq_string, u ) ;
-
 
456
		} else {
-
 
457
		    bfprintf ( bf, "<anon%lu>", u ) ;
-
 
458
		}
-
 
459
		sp = 1 ;
-
 
460
	    }
-
 
461
	    break ;
-
 
462
	}
-
 
463
    }
-
 
464
    return ( sp ) ;
581
	return (sp);
465
}
582
}
466
 
583
 
467
 
584
 
468
/*
585
/*
469
    PRINT AN IDENTIFIER (SHORT FORM)
586
    PRINT AN IDENTIFIER (SHORT FORM)
470
 
587
 
471
    This routines prints the short form of the identifier id to the buffer bf.
588
    This routines prints the short form of the identifier id to the buffer bf.
472
*/
589
*/
473
 
590
 
474
int print_id_short
591
int
475
    PROTO_N ( ( id, qual, bf, sp ) )
-
 
476
    PROTO_T ( IDENTIFIER id X QUALIFIER qual X BUFFER *bf X int sp )
592
print_id_short(IDENTIFIER id, QUALIFIER qual, BUFFER *bf, int sp)
477
{
593
{
478
    if ( !IS_NULL_id ( id ) ) {
594
	if (!IS_NULL_id(id)) {
479
	int sep = 0 ;
595
		int sep = 0;
480
	HASHID p = DEREF_hashid ( id_name ( id ) ) ;
596
		HASHID p = DEREF_hashid(id_name(id));
481
 
-
 
482
	/* Print enclosing namespace name */
-
 
483
	NAMESPACE ns = DEREF_nspace ( id_parent ( id ) ) ;
-
 
484
	if ( sp ) bfputc ( bf, ' ' ) ;
-
 
485
	if ( print_parent_namespace && !print_c_style ) {
-
 
486
	    if ( IS_NULL_nspace ( ns ) ) {
-
 
487
		if ( qual == qual_full || qual == qual_top ) {
-
 
488
		    bfprintf ( bf, "::" ) ;
-
 
489
		}
-
 
490
		sep = 1 ;
-
 
491
	    } else {
-
 
492
		IGNORE print_nspace ( ns, qual, 1, bf, 0 ) ;
-
 
493
	    }
-
 
494
	}
-
 
495
 
597
 
-
 
598
		/* Print enclosing namespace name */
-
 
599
		NAMESPACE ns = DEREF_nspace(id_parent(id));
-
 
600
		if (sp) {
-
 
601
			bfputc(bf, ' ');
-
 
602
		}
-
 
603
		if (print_parent_namespace && !print_c_style) {
-
 
604
			if (IS_NULL_nspace(ns)) {
-
 
605
				if (qual == qual_full || qual == qual_top) {
-
 
606
					bfprintf(bf, "::");
-
 
607
				}
-
 
608
				sep = 1;
-
 
609
			} else {
-
 
610
				IGNORE print_nspace(ns, qual, 1, bf, 0);
-
 
611
			}
-
 
612
		}
-
 
613
 
496
	/* Print identifier name */
614
		/* Print identifier name */
497
	if ( IS_hashid_anon ( p ) ) {
615
		if (IS_hashid_anon(p)) {
498
	    /* Print anonymous identifier names */
616
			/* Print anonymous identifier names */
499
	    IDENTIFIER alt = id ;
617
			IDENTIFIER alt = id;
500
	    unsigned tag = TAG_id ( id ) ;
618
			unsigned tag = TAG_id(id);
501
	    if ( tag == id_token_tag ) {
619
			if (tag == id_token_tag) {
502
		DECL_SPEC ds = DEREF_dspec ( id_storage ( id ) ) ;
620
				DECL_SPEC ds = DEREF_dspec(id_storage(id));
503
		if ( ds & dspec_auto ) {
621
				if (ds & dspec_auto) {
504
		    alt = DEREF_id ( id_token_alt ( id ) ) ;
622
					alt = DEREF_id(id_token_alt(id));
505
		    tag = id_parameter_tag ;
623
					tag = id_parameter_tag;
-
 
624
				}
-
 
625
			}
-
 
626
			if (tag == id_parameter_tag) {
-
 
627
				/* Parameter names */
-
 
628
				unsigned long n = 0;
-
 
629
				MEMBER mem = DEREF_member(nspace_last(ns));
-
 
630
				id = DEREF_id(id_alias(id));
-
 
631
				alt = DEREF_id(id_alias(alt));
-
 
632
				while (!IS_NULL_member(mem)) {
-
 
633
					IDENTIFIER mid =
-
 
634
					    DEREF_id(member_id(mem));
-
 
635
					if (!IS_NULL_id(mid)) {
-
 
636
						if (EQ_id(mid, id)) {
-
 
637
							n = 0;
-
 
638
						}
-
 
639
						if (EQ_id(mid, alt)) {
-
 
640
							n = 0;
-
 
641
						}
-
 
642
						n++;
-
 
643
					}
-
 
644
					mem = DEREF_member(member_next(mem));
-
 
645
				}
-
 
646
				bfprintf(bf, "<param%lu>", n);
-
 
647
			} else {
-
 
648
				/* Other identifiers */
-
 
649
				LOCATION loc;
-
 
650
				string fn, fs;
-
 
651
				DEREF_loc(id_loc(id), loc);
-
 
652
				fs = DEREF_string(posn_file(loc.posn));
-
 
653
				fn = ustrrchr(fs, '/');
-
 
654
				fn = (fn ? fn + 1 : fs);
-
 
655
				bfprintf(bf, "(\"%s\":%lu)", fn, loc.line );
-
 
656
			}
-
 
657
		} else {
-
 
658
			/* Print other identifier names */
-
 
659
			IGNORE print_hashid(p, sep, 0, bf, 0);
506
		}
660
		}
507
	    }
-
 
508
	    if ( tag == id_parameter_tag ) {
-
 
509
		/* Parameter names */
-
 
510
		unsigned long n = 0 ;
-
 
511
		MEMBER mem = DEREF_member ( nspace_last ( ns ) ) ;
-
 
512
		id = DEREF_id ( id_alias ( id ) ) ;
-
 
513
		alt = DEREF_id ( id_alias ( alt ) ) ;
-
 
514
		while ( !IS_NULL_member ( mem ) ) {
-
 
515
		    IDENTIFIER mid = DEREF_id ( member_id ( mem ) ) ;
-
 
516
		    if ( !IS_NULL_id ( mid ) ) {
-
 
517
			if ( EQ_id ( mid, id ) ) n = 0 ;
-
 
518
			if ( EQ_id ( mid, alt ) ) n = 0 ;
-
 
519
			n++ ;
661
		sp = 1;
520
		    }
-
 
521
		    mem = DEREF_member ( member_next ( mem ) ) ;
-
 
522
		}
-
 
523
		bfprintf ( bf, "<param%lu>", n ) ;
-
 
524
	    } else {
-
 
525
		/* Other identifiers */
-
 
526
		LOCATION loc ;
-
 
527
		string fn, fs ;
-
 
528
		DEREF_loc ( id_loc ( id ), loc ) ;
-
 
529
		fs = DEREF_string ( posn_file ( loc.posn ) ) ;
-
 
530
		fn = ustrrchr ( fs, '/' ) ;
-
 
531
		fn = ( fn ? fn + 1 : fs ) ;
-
 
532
		bfprintf ( bf, "(\"%s\":%lu)", fn, loc.line ) ;
-
 
533
	    }
-
 
534
	} else {
-
 
535
	    /* Print other identifier names */
-
 
536
	    IGNORE print_hashid ( p, sep, 0, bf, 0 ) ;
-
 
537
	}
662
	}
538
	sp = 1 ;
-
 
539
    }
-
 
540
    return ( sp ) ;
663
	return (sp);
541
}
664
}
542
 
665
 
543
 
666
 
544
/*
667
/*
545
    PRINT AN IDENTIFIER (LONG FORM)
668
    PRINT AN IDENTIFIER (LONG FORM)
546
 
669
 
547
    This routines prints the long form of the identifier id to the buffer bf.
670
    This routines prints the long form of the identifier id to the buffer bf.
763
	}
910
	}
764
    }
-
 
765
    return ( sp ) ;
911
	return (sp);
766
}
912
}
767
 
913
 
768
 
914
 
769
/*
915
/*
770
    PRINT A NAMESPACE
916
    PRINT A NAMESPACE
771
 
917
 
772
    This routines prints the namespace ns to the buffer bf.  The argument
918
    This routines prints the namespace ns to the buffer bf.  The argument
773
    pre is true if this a prefix to an identifier and false if the namespace
919
    pre is true if this a prefix to an identifier and false if the namespace
774
    itself is what is required.
920
    itself is what is required.
775
*/
921
*/
776
 
922
 
777
int print_nspace
923
int
778
    PROTO_N ( ( ns, qual, pre, bf, sp ) )
-
 
779
    PROTO_T ( NAMESPACE ns X QUALIFIER qual X int pre X BUFFER *bf X int sp )
924
print_nspace(NAMESPACE ns, QUALIFIER qual, int pre, BUFFER *bf, int sp)
780
{
925
{
781
    if ( !IS_NULL_nspace ( ns ) ) {
926
	if (!IS_NULL_nspace(ns)) {
782
	IDENTIFIER id = DEREF_id ( nspace_name ( ns ) ) ;
927
		IDENTIFIER id = DEREF_id(nspace_name(ns));
783
	switch ( TAG_nspace ( ns ) ) {
928
		switch (TAG_nspace(ns)) {
784
	    case nspace_named_tag :
929
		case nspace_named_tag:
785
	    case nspace_ctype_tag : {
930
		case nspace_ctype_tag: {
786
		/* Named and class namespaces */
931
			/* Named and class namespaces */
-
 
932
			if (sp) {
787
		if ( sp ) bfputc ( bf, ' ' ) ;
933
				bfputc(bf, ' ');
-
 
934
			}
788
		if ( IS_id_class_name ( id ) ) {
935
			if (IS_id_class_name(id)) {
789
		    TYPE t = DEREF_type ( id_class_name_defn ( id ) ) ;
936
				TYPE t = DEREF_type(id_class_name_defn(id));
790
		    if ( IS_type_compound ( t ) ) {
937
				if (IS_type_compound(t)) {
791
			int key = 0 ;
938
					int key = 0;
792
			CLASS_TYPE ct ;
939
					CLASS_TYPE ct;
-
 
940
					if (!pre) {
793
			if ( !pre ) key = print_c_style ;
941
						key = print_c_style;
-
 
942
					}
794
			ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
943
					ct = DEREF_ctype(type_compound_defn(t));
795
			IGNORE print_ctype ( ct, qual, key, bf, 0 ) ;
944
					IGNORE print_ctype(ct, qual, key, bf,
-
 
945
							   0);
796
		    } else {
946
				} else {
797
			IGNORE print_id_short ( id, qual, bf, 0 ) ;
947
					IGNORE print_id_short(id, qual, bf, 0);
798
		    }
948
				}
799
		} else {
949
			} else {
800
		    IGNORE print_id_short ( id, qual, bf, 0 ) ;
950
				IGNORE print_id_short(id, qual, bf, 0);
801
		}
951
			}
-
 
952
			if (pre) {
802
		if ( pre ) bfprintf ( bf, "::" ) ;
953
				bfprintf(bf, "::");
-
 
954
			}
803
		sp = 1 ;
955
			sp = 1;
804
		break ;
956
			break;
805
	    }
957
		}
806
	    case nspace_unnamed_tag : {
958
		case nspace_unnamed_tag: {
807
		/* Unnamed namespaces */
959
			/* Unnamed namespaces */
-
 
960
			if (sp) {
808
		if ( sp ) bfputc ( bf, ' ' ) ;
961
				bfputc(bf, ' ');
-
 
962
			}
809
		ns = DEREF_nspace ( id_parent ( id ) ) ;
963
			ns = DEREF_nspace(id_parent(id));
810
		IGNORE print_nspace ( ns, qual, 1, bf, 0 ) ;
964
			IGNORE print_nspace(ns, qual, 1, bf, 0);
811
		if ( print_uniq_anon ) {
965
			if (print_uniq_anon) {
812
		    bfprintf ( bf, "<anon%x>", uniq_string ) ;
966
				bfprintf(bf, "<anon%x>", uniq_string);
813
		} else {
967
			} else {
814
		    bfprintf ( bf, "<anon>" ) ;
968
				bfprintf(bf, "<anon>");
815
		}
969
			}
-
 
970
			if (pre) {
816
		if ( pre ) bfprintf ( bf, "::" ) ;
971
				bfprintf(bf, "::");
-
 
972
			}
817
		sp = 1 ;
973
			sp = 1;
818
		break ;
974
			break;
819
	    }
975
		}
820
	    case nspace_global_tag : {
976
		case nspace_global_tag: {
821
		/* The global namespace */
977
			/* The global namespace */
822
		if ( !pre || qual == qual_full || qual == qual_top ) {
978
			if (!pre || qual == qual_full || qual == qual_top) {
-
 
979
				if (sp) {
823
		    if ( sp ) bfputc ( bf, ' ' ) ;
980
					bfputc(bf, ' ');
-
 
981
				}
824
		    bfprintf ( bf, "::" ) ;
982
				bfprintf(bf, "::");
825
		    sp = 1 ;
983
				sp = 1;
-
 
984
			}
-
 
985
			break;
-
 
986
		}
-
 
987
		default : {
-
 
988
			/* Other namespaces */
-
 
989
			if (!pre) {
-
 
990
				sp = print_id_short(id, qual, bf, sp);
-
 
991
			}
-
 
992
			break;
-
 
993
		}
826
		}
994
		}
827
		break ;
-
 
828
	    }
-
 
829
	    default : {
-
 
830
		/* Other namespaces */
-
 
831
		if ( !pre ) sp = print_id_short ( id, qual, bf, sp ) ;
-
 
832
		break ;
-
 
833
	    }
-
 
834
	}
995
	}
835
    }
-
 
836
    return ( sp ) ;
996
	return (sp);
837
}
997
}
838
 
998
 
839
 
999
 
840
/*
1000
/*
841
    PRINT A GRAPH
1001
    PRINT A GRAPH
842
 
1002
 
843
    This routines prints the graph gr to the buffer bf.  The argument sep is
1003
    This routines prints the graph gr to the buffer bf.  The argument sep is
844
    true to indicate that a terminal '::' should be included.
1004
    true to indicate that a terminal '::' should be included.
845
*/
1005
*/
846
 
1006
 
847
int print_graph
1007
int
848
    PROTO_N ( ( gr, sep, bf, sp ) )
-
 
849
    PROTO_T ( GRAPH gr X int sep X BUFFER *bf X int sp )
1008
print_graph(GRAPH gr, int sep, BUFFER *bf, int sp)
850
{
1009
{
851
    if ( !IS_NULL_graph ( gr ) ) {
1010
	if (!IS_NULL_graph(gr)) {
852
	CLASS_TYPE ct = DEREF_ctype ( graph_head ( gr ) ) ;
1011
		CLASS_TYPE ct = DEREF_ctype(graph_head(gr));
853
	GRAPH gs = DEREF_graph ( graph_up ( gr ) ) ;
1012
		GRAPH gs = DEREF_graph(graph_up(gr));
854
	if ( sp ) {
1013
		if (sp) {
855
	    bfputc ( bf, ' ' ) ;
1014
			bfputc(bf, ' ');
856
	    sp = 0 ;
1015
			sp = 0;
857
	}
1016
		}
858
	if ( !IS_NULL_graph ( gs ) ) {
1017
		if (!IS_NULL_graph(gs)) {
859
	    IGNORE print_graph ( gs, 1, bf, 0 ) ;
1018
			IGNORE print_graph(gs, 1, bf, 0);
860
	    print_parent_namespace = 0 ;
1019
			print_parent_namespace = 0;
861
	}
1020
		}
862
	IGNORE print_ctype ( ct, qual_none, 0, bf, 0 ) ;
1021
		IGNORE print_ctype(ct, qual_none, 0, bf, 0);
863
	print_parent_namespace = 1 ;
1022
		print_parent_namespace = 1;
-
 
1023
		if (sep) {
864
	if ( sep ) bfprintf ( bf, "::" ) ;
1024
			bfprintf(bf, "::");
865
    }
1025
		}
-
 
1026
	}
866
    return ( sp ) ;
1027
	return (sp);
867
}
1028
}
868
 
1029
 
869
 
1030
 
870
/*
1031
/*
871
    PRINT A PREPROCESSING TOKEN
1032
    PRINT A PREPROCESSING TOKEN
872
 
1033
 
873
    This routine prints the preprocessing token p to the buffer bf.  It
1034
    This routine prints the preprocessing token p to the buffer bf.  It
874
    is used not only in the error reporting routines, but also in the
1035
    is used not only in the error reporting routines, but also in the
875
    preprocessing action.
1036
    preprocessing action.
876
*/
1037
*/
877
 
1038
 
878
int print_pptok
1039
int
879
    PROTO_N ( ( p, bf, sp ) )
-
 
880
    PROTO_T ( PPTOKEN *p X BUFFER *bf X int sp )
1040
print_pptok(PPTOKEN *p, BUFFER *bf, int sp)
881
{
1041
{
882
    int q ;
1042
	int q;
883
    int t = p->tok ;
1043
	int t = p->tok;
884
    if ( sp ) bfputc ( bf, ' ' ) ;
-
 
885
    switch ( t ) {
-
 
886
	case lex_identifier :
-
 
887
	case lex_type_Hname :
-
 
888
	case lex_namespace_Hname :
-
 
889
	case lex_statement_Hname :
-
 
890
	identifier_label : {
-
 
891
	    /* Identifiers */
-
 
892
	    HASHID nm = p->pp_data.id.hash ;
-
 
893
	    string s = DEREF_string ( hashid_name_etc_text ( nm ) ) ;
-
 
894
	    bfputs ( bf, s ) ;
-
 
895
	    break ;
-
 
896
	}
-
 
897
	case lex_destructor_Hname : {
-
 
898
	    /* Destructor names */
-
 
899
	    bfputc ( bf, '~' ) ;
-
 
900
	    goto identifier_label ;
-
 
901
	}
-
 
902
	case lex_template_Hid :
-
 
903
	case lex_template_Htype : {
-
 
904
	    /* Template names */
-
 
905
	    IDENTIFIER id = p->pp_data.tok.id ;
-
 
906
	    IGNORE print_id_short ( id, qual_none, bf, 0 ) ;
-
 
907
	    break ;
-
 
908
	}
-
 
909
	case lex_integer_Hlit : {
-
 
910
	    /* Integer and floating point literals */
-
 
911
	    string s = p->pp_data.text ;
-
 
912
	    bfputs ( bf, s ) ;
-
 
913
	    break ;
-
 
914
	}
-
 
915
	case lex_char_Hlit : {
-
 
916
	    /* Character literals */
-
 
917
	    q = '\'' ;
-
 
918
	    string_label : {
-
 
919
		string s = p->pp_data.str.start ;
-
 
920
		string e = p->pp_data.str.end ;
-
 
921
		bfputc ( bf, q ) ;
-
 
922
		while ( s != e ) {
-
 
923
		    bfputc ( bf, ( int ) *s ) ;
-
 
924
		    s++ ;
1044
	if (sp) {
925
		}
-
 
926
		bfputc ( bf, q ) ;
1045
		bfputc(bf, ' ');
927
	    }
-
 
928
	    break ;
-
 
929
	}
-
 
930
	case lex_wchar_Hlit : {
-
 
931
	    /* Wide character literals */
-
 
932
	    bfputc ( bf, 'L' ) ;
-
 
933
	    q = '\'' ;
-
 
934
	    goto string_label ;
-
 
935
	}
-
 
936
	case lex_string_Hlit : {
-
 
937
	    /* String literals */
-
 
938
	    q = '"' ;
-
 
939
	    goto string_label ;
-
 
940
	}
-
 
941
	case lex_wstring_Hlit : {
-
 
942
	    /* Wide string literals */
-
 
943
	    bfputc ( bf, 'L' ) ;
-
 
944
	    q = '"' ;
-
 
945
	    goto string_label ;
-
 
946
	}
-
 
947
	case lex_integer_Hexp :
-
 
948
	case lex_floating_Hexp :
-
 
949
	case lex_char_Hexp :
-
 
950
	case lex_wchar_Hexp :
-
 
951
	case lex_string_Hexp :
-
 
952
	case lex_wstring_Hexp : {
-
 
953
	    /* Literal expressions */
-
 
954
	    IGNORE print_exp ( p->pp_data.exp, 0, bf, 0 ) ;
-
 
955
	    break ;
-
 
956
	}
1046
	}
-
 
1047
	switch (t) {
-
 
1048
	case lex_identifier:
957
	case lex_unknown : {
1049
	case lex_type_Hname:
958
	    /* Unknown characters */
1050
	case lex_namespace_Hname:
-
 
1051
	case lex_statement_Hname:
959
	    unsigned long u ;
1052
identifier_label: {
960
	    int ch = CHAR_SIMPLE ;
1053
			  /* Identifiers */
961
	    u = get_multi_char ( p->pp_data.buff, &ch ) ;
1054
			  HASHID nm = p->pp_data.id.hash;
962
	    if ( ch == CHAR_SIMPLE ) {
1055
			  string s = DEREF_string(hashid_name_etc_text(nm));
963
		bfputc ( bf, ( int ) u ) ;
1056
			  bfputs(bf, s);
964
	    } else {
1057
			  break;
965
		print_char ( u, ch, 0, bf ) ;
-
 
966
	    }
1058
		  }
-
 
1059
	case lex_destructor_Hname: {
-
 
1060
		/* Destructor names */
967
	    break ;
1061
		bfputc(bf, '~');
-
 
1062
		goto identifier_label;
968
	}
1063
	}
-
 
1064
	case lex_template_Hid:
969
	case lex_nested_Hname : {
1065
	case lex_template_Htype: {
970
	    /* Nested name qualifier */
1066
		/* Template names */
971
	    NAMESPACE ns = p->pp_data.ns ;
1067
		IDENTIFIER id = p->pp_data.tok.id;
972
	    IGNORE print_nspace ( ns, qual_nested, 1, bf, 0 ) ;
1068
		IGNORE print_id_short(id, qual_none, bf, 0);
973
	    break ;
1069
		break;
974
	}
1070
	}
975
	case lex_full_Hname : {
1071
	case lex_integer_Hlit: {
976
	    /* Nested name qualifier */
1072
		/* Integer and floating point literals */
977
	    NAMESPACE ns = p->pp_data.ns ;
1073
		string s = p->pp_data.text;
978
	    IGNORE print_nspace ( ns, qual_full, 1, bf, 0 ) ;
1074
		bfputs(bf, s);
979
	    break ;
1075
		break;
980
	}
1076
	}
981
	case lex_nested_Hname_Hstar : {
1077
	case lex_char_Hlit: {
982
	    /* Nested member qualifier */
1078
		/* Character literals */
-
 
1079
		q = '\'';
-
 
1080
string_label: {
983
	    IDENTIFIER id = p->pp_data.id.use ;
1081
		      string s = p->pp_data.str.start;
984
	    IGNORE print_id_short ( id, qual_nested, bf, 0 ) ;
1082
		      string e = p->pp_data.str.end;
-
 
1083
		      bfputc(bf, q);
-
 
1084
		      while (s != e) {
-
 
1085
			      bfputc(bf,(int)*s);
-
 
1086
			      s++;
-
 
1087
		      }
985
	    bfprintf ( bf, "::*" ) ;
1088
		      bfputc(bf, q);
-
 
1089
	      }
986
	    break ;
1090
	      break;
987
	}
1091
	}
988
	case lex_full_Hname_Hstar : {
1092
	case lex_wchar_Hlit: {
989
	    /* Nested member qualifier */
1093
		/* Wide character literals */
990
	    IDENTIFIER id = p->pp_data.id.use ;
-
 
991
	    IGNORE print_id_short ( id, qual_full, bf, 0 ) ;
-
 
992
	    bfprintf ( bf, "::*" ) ;
1094
		bfputc(bf, 'L');
993
	    break ;
1095
		q = '\'';
-
 
1096
		goto string_label;
994
	}
1097
	}
995
	case lex_complex_Hexp :
-
 
996
	case lex_complex_Htype : {
1098
	case lex_string_Hlit: {
997
	    /* Token applications etc. */
1099
		/* String literals */
998
	    IDENTIFIER id = p->pp_data.tok.id ;
1100
		q = '"';
999
	    IGNORE print_id_short ( id, qual_none, bf, 0 ) ;
-
 
1000
	    break ;
1101
		goto string_label;
1001
	}
1102
	}
-
 
1103
	case lex_wstring_Hlit: {
-
 
1104
		/* Wide string literals */
-
 
1105
		bfputc(bf, 'L');
-
 
1106
		q = '"';
-
 
1107
		goto string_label;
-
 
1108
	}
-
 
1109
	case lex_integer_Hexp:
-
 
1110
	case lex_floating_Hexp:
-
 
1111
	case lex_char_Hexp:
-
 
1112
	case lex_wchar_Hexp:
-
 
1113
	case lex_string_Hexp:
-
 
1114
	case lex_wstring_Hexp: {
-
 
1115
		/* Literal expressions */
-
 
1116
		IGNORE print_exp(p->pp_data.exp, 0, bf, 0);
-
 
1117
		break;
-
 
1118
	}
-
 
1119
	case lex_unknown: {
-
 
1120
		/* Unknown characters */
-
 
1121
		unsigned long u;
-
 
1122
		int ch = CHAR_SIMPLE;
-
 
1123
		u = get_multi_char(p->pp_data.buff, &ch);
-
 
1124
		if (ch == CHAR_SIMPLE) {
-
 
1125
			bfputc(bf,(int)u);
-
 
1126
		} else {
-
 
1127
			print_char(u, ch, 0, bf);
-
 
1128
		}
-
 
1129
		break;
-
 
1130
	}
-
 
1131
	case lex_nested_Hname: {
-
 
1132
		/* Nested name qualifier */
-
 
1133
		NAMESPACE ns = p->pp_data.ns;
-
 
1134
		IGNORE print_nspace(ns, qual_nested, 1, bf, 0);
-
 
1135
		break;
-
 
1136
	}
-
 
1137
	case lex_full_Hname: {
-
 
1138
		/* Nested name qualifier */
-
 
1139
		NAMESPACE ns = p->pp_data.ns;
-
 
1140
		IGNORE print_nspace(ns, qual_full, 1, bf, 0);
-
 
1141
		break;
-
 
1142
	}
-
 
1143
	case lex_nested_Hname_Hstar: {
-
 
1144
		/* Nested member qualifier */
-
 
1145
		IDENTIFIER id = p->pp_data.id.use;
-
 
1146
		IGNORE print_id_short(id, qual_nested, bf, 0);
-
 
1147
		bfprintf(bf, "::*");
-
 
1148
		break;
-
 
1149
	}
-
 
1150
	case lex_full_Hname_Hstar: {
-
 
1151
		/* Nested member qualifier */
-
 
1152
		IDENTIFIER id = p->pp_data.id.use;
-
 
1153
		IGNORE print_id_short(id, qual_full, bf, 0);
-
 
1154
		bfprintf(bf, "::*");
-
 
1155
		break;
-
 
1156
	}
-
 
1157
	case lex_complex_Hexp:
-
 
1158
	case lex_complex_Htype: {
-
 
1159
		/* Token applications etc. */
-
 
1160
		IDENTIFIER id = p->pp_data.tok.id;
-
 
1161
		IGNORE print_id_short(id, qual_none, bf, 0);
-
 
1162
		break;
-
 
1163
	}
1002
	case lex_macro_Harg : {
1164
	case lex_macro_Harg: {
1003
	    /* Macro parameters */
1165
		/* Macro parameters */
1004
	    HASHID nm = p->pp_data.par.hash ;
1166
		HASHID nm = p->pp_data.par.hash;
1005
	    string s = DEREF_string ( hashid_name_etc_text ( nm ) ) ;
1167
		string s = DEREF_string(hashid_name_etc_text(nm));
1006
	    bfputs ( bf, s ) ;
1168
		bfputs(bf, s);
1007
	    break ;
1169
		break;
1008
	}
1170
	}
1009
	default : {
1171
	default : {
1010
	    /* Simple token */
1172
		/* Simple token */
1011
	    if ( t >= 0 ) {
1173
		if (t >= 0) {
1012
		string s = token_name ( t ) ;
1174
			string s = token_name(t);
1013
		bfputs ( bf, s ) ;
1175
			bfputs(bf, s);
1014
	    } else {
1176
		} else {
1015
		bfprintf ( bf, "<ignore>" ) ;
1177
			bfprintf(bf, "<ignore>");
1016
	    }
1178
		}
1017
	    break ;
1179
		break;
-
 
1180
	}
1018
	}
1181
	}
1019
    }
-
 
1020
    return ( 1 ) ;
1182
	return (1);
1021
}
1183
}
1022
 
1184
 
1023
 
1185
 
1024
/*
1186
/*
1025
    INTEGER LITERAL PRINTING
1187
    INTEGER LITERAL PRINTING
Line 1028... Line 1190...
1028
    is when a large literal will not fit into an unsigned long.  The digits
1190
    is when a large literal will not fit into an unsigned long.  The digits
1029
    need to be printed in reverse order, and it is again quickest to reverse
1191
    need to be printed in reverse order, and it is again quickest to reverse
1030
    the order of the list twice.
1192
    the order of the list twice.
1031
*/
1193
*/
1032
 
1194
 
1033
int print_nat
1195
int
1034
    PROTO_N ( ( n, paren, bf, sp ) )
-
 
1035
    PROTO_T ( NAT n X int paren X BUFFER *bf X int sp )
1196
print_nat(NAT n, int paren, BUFFER *bf, int sp)
1036
{
1197
{
1037
    if ( !IS_NULL_nat ( n ) ) {
1198
	if (!IS_NULL_nat(n)) {
1038
	ASSERT ( ORDER_nat == 5 ) ;
1199
		ASSERT(ORDER_nat == 5);
1039
	switch ( TAG_nat ( n ) ) {
1200
		switch (TAG_nat(n)) {
1040
	    case nat_small_tag : {
1201
		case nat_small_tag: {
1041
		/* Small values */
1202
			/* Small values */
1042
		unsigned v = DEREF_unsigned ( nat_small_value ( n ) ) ;
1203
			unsigned v = DEREF_unsigned(nat_small_value(n));
-
 
1204
			if (sp) {
1043
		if ( sp ) bfputc ( bf, ' ' ) ;
1205
				bfputc(bf, ' ');
-
 
1206
			}
1044
		bfprintf ( bf, "%u", v ) ;
1207
			bfprintf(bf, "%u", v);
1045
		sp = 1 ;
1208
			sp = 1;
1046
		break ;
1209
			break;
1047
	    }
1210
		}
1048
	    case nat_large_tag : {
1211
		case nat_large_tag: {
1049
		/* Large values */
1212
			/* Large values */
1050
		LIST ( unsigned ) p ;
1213
			LIST(unsigned)p;
1051
		p = DEREF_list ( nat_large_values ( n ) ) ;
1214
			p = DEREF_list(nat_large_values(n));
-
 
1215
			if (sp) {
1052
		if ( sp ) bfputc ( bf, ' ' ) ;
1216
				bfputc(bf, ' ');
-
 
1217
			}
1053
		if ( LENGTH_list ( p ) <= 2 ) {
1218
			if (LENGTH_list(p) <= 2) {
1054
		    /* Two digit literals will fit into a unsigned long */
1219
				/* Two digit literals will fit into a unsigned
-
 
1220
				 * long */
1055
		    unsigned long v = get_nat_value ( n ) ;
1221
				unsigned long v = get_nat_value(n);
1056
		    bfprintf ( bf, "%lu", v ) ;
1222
				bfprintf(bf, "%lu", v);
1057
		} else {
1223
			} else {
1058
		    /* Print large literals by scanning through digits */
1224
				/* Print large literals by scanning through
-
 
1225
				 * digits */
1059
		    char buff [50] ;
1226
				char buff[50];
1060
		    CONST char *fmt = "0x%x" ;
1227
				CONST char *fmt = "0x%x";
1061
		    LIST ( unsigned ) q ;
1228
				LIST(unsigned)q;
1062
		    p = REVERSE_list ( p ) ;
1229
				p = REVERSE_list(p);
1063
		    q = p ;
1230
				q = p;
1064
		    while ( !IS_NULL_list ( q ) ) {
1231
				while (!IS_NULL_list(q)) {
-
 
1232
					unsigned v =
1065
			unsigned v = DEREF_unsigned ( HEAD_list ( q ) ) ;
1233
					    DEREF_unsigned(HEAD_list(q));
1066
			sprintf_v ( buff, fmt, v ) ;
1234
					sprintf_v(buff, fmt, v);
1067
			bfputs ( bf, ustrlit ( buff ) ) ;
1235
					bfputs(bf, ustrlit(buff));
1068
			fmt = "%04x" ;
1236
					fmt = "%04x";
1069
			q = TAIL_list ( q ) ;
1237
					q = TAIL_list(q);
1070
		    }
1238
				}
1071
		    IGNORE REVERSE_list ( p ) ;
1239
				IGNORE REVERSE_list(p);
1072
		}
1240
			}
1073
		sp = 1 ;
1241
			sp = 1;
1074
		break ;
1242
			break;
1075
	    }
1243
		}
1076
	    case nat_calc_tag : {
1244
		case nat_calc_tag: {
1077
		/* Calculated values */
1245
			/* Calculated values */
1078
		EXP e = DEREF_exp ( nat_calc_value ( n ) ) ;
1246
			EXP e = DEREF_exp(nat_calc_value(n));
1079
		while ( !IS_NULL_exp ( e ) && IS_exp_cast ( e ) ) {
1247
			while (!IS_NULL_exp(e) && IS_exp_cast(e)) {
1080
		    e = DEREF_exp ( exp_cast_arg ( e ) ) ;
1248
				e = DEREF_exp(exp_cast_arg(e));
-
 
1249
			}
-
 
1250
			sp = print_exp(e, paren, bf, sp);
-
 
1251
			break;
-
 
1252
		}
-
 
1253
		case nat_neg_tag: {
-
 
1254
			/* Negative values */
-
 
1255
			NAT m = DEREF_nat(nat_neg_arg(n));
-
 
1256
			if (sp) {
-
 
1257
				bfputc(bf, ' ');
-
 
1258
			}
-
 
1259
			bfputc(bf, '-');
-
 
1260
			IGNORE print_nat(m, 1, bf, 0);
-
 
1261
			break;
-
 
1262
		}
-
 
1263
		case nat_token_tag: {
-
 
1264
			IDENTIFIER id = DEREF_id(nat_token_tok(n));
-
 
1265
			LIST(TOKEN)args = DEREF_list(nat_token_args(n));
-
 
1266
			sp = print_token(id, qual_none, args, bf, sp);
-
 
1267
			break;
-
 
1268
		}
1081
		}
1269
		}
1082
		sp = print_exp ( e, paren, bf, sp ) ;
-
 
1083
		break ;
-
 
1084
	    }
-
 
1085
	    case nat_neg_tag : {
-
 
1086
		/* Negative values */
-
 
1087
		NAT m = DEREF_nat ( nat_neg_arg ( n ) ) ;
-
 
1088
		if ( sp ) bfputc ( bf, ' ' ) ;
-
 
1089
		bfputc ( bf, '-' ) ;
-
 
1090
		IGNORE print_nat ( m, 1, bf, 0 ) ;
-
 
1091
		break ;
-
 
1092
	    }
-
 
1093
	    case nat_token_tag : {
-
 
1094
		IDENTIFIER id = DEREF_id ( nat_token_tok ( n ) ) ;
-
 
1095
		LIST ( TOKEN ) args = DEREF_list ( nat_token_args ( n ) ) ;
-
 
1096
		sp = print_token ( id, qual_none, args, bf, sp ) ;
-
 
1097
		break ;
-
 
1098
	    }
-
 
1099
	}
1270
	}
1100
    }
-
 
1101
    return ( sp ) ;
1271
	return (sp);
1102
}
1272
}
1103
 
1273
 
1104
 
1274
 
1105
/*
1275
/*
1106
    FLOATING-POINT LITERAL PRINTING
1276
    FLOATING-POINT LITERAL PRINTING
1107
 
1277
 
1108
    This routine prints a floating-point literal to the buffer bf.
1278
    This routine prints a floating-point literal to the buffer bf.
1109
*/
1279
*/
1110
 
1280
 
1111
int print_flt
1281
int
1112
    PROTO_N ( ( n, bf, sp ) )
-
 
1113
    PROTO_T ( FLOAT n X BUFFER *bf X int sp )
1282
print_flt(FLOAT n, BUFFER *bf, int sp)
1114
{
1283
{
1115
    if ( !IS_NULL_flt ( n ) ) {
1284
	if (!IS_NULL_flt(n)) {
1116
	string i = DEREF_string ( flt_simple_int_part ( n ) ) ;
1285
		string i = DEREF_string(flt_simple_int_part(n));
1117
	string d = DEREF_string ( flt_simple_frac_part ( n ) ) ;
1286
		string d = DEREF_string(flt_simple_frac_part(n));
1118
	NAT e = DEREF_nat ( flt_simple_exponent ( n ) ) ;
1287
		NAT e = DEREF_nat(flt_simple_exponent(n));
-
 
1288
		if (sp) {
1119
	if ( sp ) bfputc ( bf, ' ' ) ;
1289
			bfputc(bf, ' ');
-
 
1290
		}
1120
	bfprintf ( bf, "%s.%s", i, d ) ;
1291
		bfprintf(bf, "%s.%s", i, d);
1121
	if ( !is_zero_nat ( e ) ) {
1292
		if (!is_zero_nat(e)) {
1122
	    bfputc ( bf, 'e' ) ;
1293
			bfputc(bf, 'e');
1123
	    IGNORE print_nat ( e, 0, bf, 0 ) ;
1294
			IGNORE print_nat(e, 0, bf, 0);
1124
	}
1295
		}
1125
	sp = 1 ;
1296
		sp = 1;
1126
    }
1297
	}
1127
    return ( sp ) ;
1298
	return (sp);
1128
}
1299
}
1129
 
1300
 
1130
 
1301
 
1131
/*
1302
/*
1132
    CHARACTER PRINTING
1303
    CHARACTER PRINTING
1133
 
1304
 
1134
    This routine prints the character c to the buffer bf as a string
1305
    This routine prints the character c to the buffer bf as a string
1135
    character of type ch enclosed by the quote character q.
1306
    character of type ch enclosed by the quote character q.
1136
*/
1307
*/
1137
 
1308
 
1138
void print_char
1309
void
1139
    PROTO_N ( ( c, ch, q, bf ) )
-
 
1140
    PROTO_T ( unsigned long c X int ch X int q X BUFFER *bf )
1310
print_char(unsigned long c, int ch, int q, BUFFER *bf)
1141
{
1311
{
1142
    char buff [20] ;
1312
	char buff[20];
1143
    if ( ch == CHAR_SIMPLE ) {
1313
	if (ch == CHAR_SIMPLE) {
1144
	switch ( c ) {
1314
		switch (c) {
-
 
1315
		case char_alert:
-
 
1316
			bfprintf(bf, "\\a");
1145
 
1317
			break;
-
 
1318
		case char_backspace:
1146
	    case char_alert : bfprintf ( bf, "\\a") ; break ;
1319
			bfprintf(bf, "\\b");
-
 
1320
			break;
1147
	    case char_backspace : bfprintf ( bf, "\\b") ; break ;
1321
		case char_form_feed:
1148
	    case char_form_feed : bfprintf ( bf, "\\f") ; break ;
1322
			bfprintf(bf, "\\f");
-
 
1323
			break;
-
 
1324
		case char_newline:
1149
	    case char_newline : bfprintf ( bf, "\\n") ; break ;
1325
			bfprintf(bf, "\\n");
-
 
1326
			break;
-
 
1327
		case char_return:
1150
	    case char_return : bfprintf ( bf, "\\r") ; break ;
1328
			bfprintf(bf, "\\r");
-
 
1329
			break;
-
 
1330
		case char_tab:
1151
	    case char_tab : bfprintf ( bf, "\\t") ; break ;
1331
			bfprintf(bf, "\\t");
-
 
1332
			break;
-
 
1333
		case char_vert_tab:
1152
	    case char_vert_tab : bfprintf ( bf, "\\v") ; break ;
1334
			bfprintf(bf, "\\v");
-
 
1335
			break;
1153
 
1336
 
1154
	    case char_backslash :
1337
		case char_backslash:
1155
	    case char_question : {
1338
		case char_question: {
-
 
1339
			if (q) {
1156
		if ( q ) bfputc ( bf, '\\' ) ;
1340
				bfputc(bf, '\\');
-
 
1341
			}
1157
		bfputc ( bf, ( int ) c ) ;
1342
			bfputc(bf,(int)c);
1158
		break ;
1343
			break;
1159
	    }
1344
		}
1160
 
1345
 
1161
	    case char_quote :
1346
		case char_quote:
1162
	    case char_single_quote : {
1347
		case char_single_quote: {
1163
		int a = ( int ) c ;
1348
			int a = (int)c;
-
 
1349
			if (a == q) {
1164
		if ( a == q ) bfputc ( bf, '\\' ) ;
1350
				bfputc(bf, '\\');
-
 
1351
			}
1165
		bfputc ( bf, a ) ;
1352
			bfputc(bf, a);
1166
		break ;
1353
			break;
1167
	    }
1354
		}
1168
 
1355
 
1169
	    default : {
1356
		default : {
1170
		int a = ( int ) c ;
1357
			int a = (int)c;
1171
		if ( isprint ( a ) ) {
1358
			if (isprint(a)) {
1172
		    bfputc ( bf, a ) ;
1359
				bfputc(bf, a);
1173
		} else {
1360
			} else {
1174
		    sprintf_v ( buff, "\\%03lo", c ) ;
1361
				sprintf_v(buff, "\\%03lo", c );
1175
		    bfputs ( bf, ustrlit ( buff ) ) ;
1362
				bfputs(bf, ustrlit(buff));
1176
		}
1363
			}
1177
		break ;
1364
			break;
1178
	    }
1365
		}
1179
	}
1366
		}
1180
    } else {
1367
	} else {
1181
	CONST char *fmt ;
1368
		CONST char *fmt;
1182
	switch ( ch ) {
1369
		switch (ch) {
-
 
1370
		case CHAR_OCTAL:
1183
	    case CHAR_OCTAL : fmt = "\\%03lo" ; break ;
1371
			fmt = "\\%03lo";
-
 
1372
			break;
-
 
1373
		case CHAR_UNI4:
1184
	    case CHAR_UNI4 : fmt = "\\u%04lx" ; break ;
1374
			fmt = "\\u%04lx";
-
 
1375
			break;
-
 
1376
		case CHAR_UNI8:
1185
	    case CHAR_UNI8 : fmt = "\\U%08lx" ; break ;
1377
			fmt = "\\U%08lx";
-
 
1378
			break;
-
 
1379
		default:
1186
	    default : fmt = "\\x%lx" ; break ;
1380
			fmt = "\\x%lx";
-
 
1381
			break;
1187
	}
1382
		}
1188
	sprintf_v ( buff, fmt, c ) ;
1383
		sprintf_v(buff, fmt, c);
1189
	bfputs ( bf, ustrlit ( buff ) ) ;
1384
		bfputs(bf, ustrlit(buff));
1190
    }
1385
	}
1191
    return ;
1386
	return;
1192
}
1387
}
1193
 
1388
 
1194
 
1389
 
1195
/*
1390
/*
1196
    STRING LITERAL PRINTING
1391
    STRING LITERAL PRINTING
1197
 
1392
 
1198
    This routine prints a string or character literal to the buffer bf.
1393
    This routine prints a string or character literal to the buffer bf.
1199
*/
1394
*/
1200
 
1395
 
1201
int print_str
1396
int
1202
    PROTO_N ( ( s, bf, sp ) )
-
 
1203
    PROTO_T ( STRING s X BUFFER *bf X int sp )
1397
print_str(STRING s, BUFFER *bf, int sp)
1204
{
1398
{
1205
    string text ;
1399
	string text;
1206
    int q = '"' ;
1400
	int q = '"';
1207
    unsigned kind ;
1401
	unsigned kind;
1208
    unsigned long i, len ;
1402
	unsigned long i, len;
1209
 
1403
 
1210
    if ( IS_NULL_str ( s ) ) return ( sp ) ;
1404
	if (IS_NULL_str(s)) {
-
 
1405
		return (sp);
-
 
1406
	}
1211
 
1407
 
1212
    /* Print the opening quote */
1408
	/* Print the opening quote */
1213
    if ( sp ) bfputc ( bf, ' ' ) ;
1409
	if (sp) {
1214
    kind = DEREF_unsigned ( str_simple_kind ( s ) ) ;
-
 
1215
    if ( kind & STRING_CHAR ) q = '\'' ;
-
 
1216
    if ( kind & STRING_WIDE ) bfputc ( bf, 'L' ) ;
1410
		bfputc(bf, ' ');
1217
 
1411
	}
1218
    /* Print the string text */
-
 
1219
    text = DEREF_string ( str_simple_text ( s ) ) ;
-
 
1220
    len = DEREF_ulong ( str_simple_len ( s ) ) ;
1412
	kind = DEREF_unsigned(str_simple_kind(s));
1221
    bfputc ( bf, q ) ;
-
 
1222
    if ( kind & STRING_MULTI ) {
1413
	if (kind & STRING_CHAR) {
1223
	/* Multi-byte strings */
-
 
1224
	for ( i = 0 ; i < len ; i++ ) {
-
 
1225
	    int ch = CHAR_SIMPLE ;
-
 
1226
	    unsigned long c = get_multi_char ( text, &ch ) ;
-
 
1227
	    print_char ( c, ch, q, bf ) ;
-
 
1228
	    text += MULTI_WIDTH ;
1414
		q = '\'';
1229
	}
1415
	}
1230
    } else {
-
 
1231
	/* Simple strings */
-
 
1232
	for ( i = 0 ; i < len ; i++ ) {
1416
	if (kind & STRING_WIDE) {
1233
	    unsigned long c = ( unsigned long ) text [i] ;
-
 
1234
	    print_char ( c, CHAR_SIMPLE, q, bf ) ;
1417
		bfputc(bf, 'L');
1235
	}
1418
	}
-
 
1419
 
-
 
1420
	/* Print the string text */
-
 
1421
	text = DEREF_string(str_simple_text(s));
-
 
1422
	len = DEREF_ulong(str_simple_len(s));
-
 
1423
	bfputc(bf, q);
-
 
1424
	if (kind & STRING_MULTI) {
-
 
1425
		/* Multi-byte strings */
-
 
1426
		for (i = 0; i < len; i++) {
-
 
1427
			int ch = CHAR_SIMPLE;
-
 
1428
			unsigned long c = get_multi_char(text, &ch);
-
 
1429
			print_char(c, ch, q, bf);
-
 
1430
			text += MULTI_WIDTH;
1236
    }
1431
		}
-
 
1432
	} else {
-
 
1433
		/* Simple strings */
-
 
1434
		for (i = 0; i < len; i++) {
-
 
1435
			unsigned long c = (unsigned long)text[i];
-
 
1436
			print_char(c, CHAR_SIMPLE, q, bf);
-
 
1437
		}
-
 
1438
	}
1237
    bfputc ( bf, q ) ;
1439
	bfputc(bf, q);
1238
    return ( 1 ) ;
1440
	return (1);
1239
}
1441
}
1240
 
1442
 
1241
 
1443
 
1242
/*
1444
/*
1243
    EXPRESSION PRINTING
1445
    EXPRESSION PRINTING
1244
 
1446
 
1245
    This routine prints an expression to the buffer bf.
1447
    This routine prints an expression to the buffer bf.
1246
*/
1448
*/
1247
 
1449
 
1248
int print_exp
1450
int
1249
    PROTO_N ( ( e, paren, bf, sp ) )
-
 
1250
    PROTO_T ( EXP e X int paren X BUFFER *bf X int sp )
1451
print_exp(EXP e, int paren, BUFFER *bf, int sp)
1251
{
1452
{
1252
    if ( !IS_NULL_exp ( e ) ) {
1453
	if (!IS_NULL_exp(e)) {
1253
	switch ( TAG_exp ( e ) ) {
1454
		switch (TAG_exp(e)) {
1254
	    case exp_identifier_tag :
1455
		case exp_identifier_tag:
1255
	    case exp_member_tag :
1456
		case exp_member_tag:
1256
	    case exp_ambiguous_tag :
1457
		case exp_ambiguous_tag:
1257
	    case exp_undeclared_tag : {
1458
		case exp_undeclared_tag: {
1258
		IDENTIFIER id = DEREF_id ( exp_identifier_etc_id ( e ) ) ;
1459
			IDENTIFIER id = DEREF_id(exp_identifier_etc_id(e));
1259
		QUALIFIER q = DEREF_qual ( exp_identifier_etc_qual ( e ) ) ;
1460
			QUALIFIER q = DEREF_qual(exp_identifier_etc_qual(e));
1260
		q &= qual_explicit ;
1461
			q &= qual_explicit;
1261
		sp = print_id_short ( id, q, bf, sp ) ;
1462
			sp = print_id_short(id, q, bf, sp);
1262
		break ;
1463
			break;
1263
	    }
1464
		}
1264
	    case exp_int_lit_tag : {
1465
		case exp_int_lit_tag: {
1265
		NAT n = DEREF_nat ( exp_int_lit_nat ( e ) ) ;
1466
			NAT n = DEREF_nat(exp_int_lit_nat(e));
1266
		sp = print_nat ( n, paren, bf, sp ) ;
1467
			sp = print_nat(n, paren, bf, sp);
1267
		break ;
1468
			break;
1268
	    }
1469
		}
1269
	    case exp_float_lit_tag : {
1470
		case exp_float_lit_tag: {
1270
		FLOAT flt = DEREF_flt ( exp_float_lit_flt ( e ) ) ;
1471
			FLOAT flt = DEREF_flt(exp_float_lit_flt(e));
1271
		sp = print_flt ( flt, bf, sp ) ;
1472
			sp = print_flt(flt, bf, sp);
1272
		break ;
1473
			break;
1273
	    }
1474
		}
1274
	    case exp_char_lit_tag : {
1475
		case exp_char_lit_tag: {
1275
		STRING s = DEREF_str ( exp_char_lit_str ( e ) ) ;
1476
			STRING s = DEREF_str(exp_char_lit_str(e));
1276
		sp = print_str ( s, bf, sp ) ;
1477
			sp = print_str(s, bf, sp);
1277
		break ;
1478
			break;
1278
	    }
1479
		}
1279
	    case exp_string_lit_tag : {
1480
		case exp_string_lit_tag: {
1280
		STRING s = DEREF_str ( exp_string_lit_str ( e ) ) ;
1481
			STRING s = DEREF_str(exp_string_lit_str(e));
1281
		sp = print_str ( s, bf, sp ) ;
1482
			sp = print_str(s, bf, sp);
1282
		break ;
1483
			break;
1283
	    }
1484
		}
1284
	    case exp_null_tag :
1485
		case exp_null_tag:
1285
	    case exp_zero_tag :
1486
		case exp_zero_tag:
1286
	    case exp_value_tag : {
1487
		case exp_value_tag: {
-
 
1488
			if (sp) {
1287
		if ( sp ) bfputc ( bf, ' ' ) ;
1489
				bfputc(bf, ' ');
-
 
1490
			}
1288
		bfputc ( bf, '0' ) ;
1491
			bfputc(bf, '0');
1289
		break ;
1492
			break;
1290
	    }
1493
		}
1291
	    case exp_contents_tag : {
1494
		case exp_contents_tag: {
1292
		EXP a = DEREF_exp ( exp_contents_ptr ( e ) ) ;
1495
			EXP a = DEREF_exp(exp_contents_ptr(e));
1293
		sp = print_exp ( a, 0, bf, sp ) ;
1496
			sp = print_exp(a, 0, bf, sp);
1294
		break ;
1497
			break;
1295
	    }
1498
		}
1296
	    case exp_token_tag : {
1499
		case exp_token_tag: {
1297
		IDENTIFIER id = DEREF_id ( exp_token_tok ( e ) ) ;
1500
			IDENTIFIER id = DEREF_id(exp_token_tok(e));
1298
		LIST ( TOKEN ) args = DEREF_list ( exp_token_args ( e ) ) ;
1501
			LIST(TOKEN)args = DEREF_list(exp_token_args(e));
1299
		sp = print_token ( id, qual_none, args, bf, sp ) ;
1502
			sp = print_token(id, qual_none, args, bf, sp);
1300
		break ;
1503
			break;
1301
	    }
1504
		}
1302
	    default : {
1505
		default: {
1303
		static unsigned long exp_no = 0 ;
1506
			static unsigned long exp_no = 0;
1304
#ifdef RUNTIME
1507
#ifdef RUNTIME
1305
		if ( debugging ) {
1508
			if (debugging) {
1306
		    /* Debug expression printing routine */
1509
				/* Debug expression printing routine */
1307
		    sp = print_exp_aux ( e, paren, bf, sp ) ;
1510
				sp = print_exp_aux(e, paren, bf, sp);
1308
		    break ;
1511
				break;
1309
		}
1512
			}
1310
#endif
1513
#endif
-
 
1514
			if (sp) {
1311
		if ( sp ) bfputc ( bf, ' ' ) ;
1515
				bfputc(bf, ' ');
-
 
1516
			}
1312
		bfprintf ( bf, "<exp%lu>", ++exp_no ) ;
1517
			bfprintf(bf, "<exp%lu>", ++exp_no);
1313
		sp = 1 ;
1518
			sp = 1;
1314
		break ;
1519
			break;
-
 
1520
		}
1315
	    }
1521
		}
1316
	}
1522
	}
1317
    }
-
 
1318
    return ( sp ) ;
1523
	return (sp);
1319
}
1524
}
1320
 
1525
 
1321
 
1526
 
1322
/*
1527
/*
1323
    TOKEN VALUE PRINTING
1528
    TOKEN VALUE PRINTING
1324
 
1529
 
1325
    This routine prints the value of the token tok to the buffer bf.
1530
    This routine prints the value of the token tok to the buffer bf.
1326
*/
1531
*/
1327
 
1532
 
1328
int print_tok_value
1533
int
1329
    PROTO_N ( ( tok, bf, sp ) )
-
 
1330
    PROTO_T ( TOKEN tok X BUFFER *bf X int sp )
1534
print_tok_value(TOKEN tok, BUFFER *bf, int sp)
1331
{
1535
{
1332
    if ( !IS_NULL_tok ( tok ) ) {
1536
	if (!IS_NULL_tok(tok)) {
1333
	ASSERT ( ORDER_tok == 10 ) ;
1537
		ASSERT(ORDER_tok == 10);
1334
	switch ( TAG_tok ( tok ) ) {
1538
		switch (TAG_tok(tok)) {
1335
	    case tok_exp_tag : {
1539
		case tok_exp_tag: {
1336
		EXP e = DEREF_exp ( tok_exp_value ( tok ) ) ;
1540
			EXP e = DEREF_exp(tok_exp_value(tok));
1337
		sp = print_exp ( e, 0, bf, sp ) ;
1541
			sp = print_exp(e, 0, bf, sp);
1338
		break ;
1542
			break;
1339
	    }
1543
		}
1340
	    case tok_stmt_tag : {
1544
		case tok_stmt_tag: {
1341
		EXP e = DEREF_exp ( tok_stmt_value ( tok ) ) ;
1545
			EXP e = DEREF_exp(tok_stmt_value(tok));
1342
		sp = print_exp ( e, 0, bf, sp ) ;
1546
			sp = print_exp(e, 0, bf, sp);
1343
		break ;
1547
			break;
1344
	    }
1548
		}
1345
	    case tok_nat_tag :
1549
		case tok_nat_tag:
1346
	    case tok_snat_tag : {
1550
		case tok_snat_tag: {
1347
		NAT n = DEREF_nat ( tok_nat_etc_value ( tok ) ) ;
1551
			NAT n = DEREF_nat(tok_nat_etc_value(tok));
1348
		sp = print_nat ( n, 0, bf, sp ) ;
1552
			sp = print_nat(n, 0, bf, sp);
1349
		break ;
1553
			break;
1350
	    }
1554
		}
1351
	    case tok_type_tag : {
1555
		case tok_type_tag: {
1352
		TYPE t = DEREF_type ( tok_type_value ( tok ) ) ;
1556
			TYPE t = DEREF_type(tok_type_value(tok));
1353
		sp = print_type ( t, bf, sp ) ;
1557
			sp = print_type(t, bf, sp);
1354
		break ;
1558
			break;
1355
	    }
1559
		}
1356
	    case tok_member_tag : {
1560
		case tok_member_tag: {
1357
		OFFSET off = DEREF_off ( tok_member_value ( tok ) ) ;
1561
			OFFSET off = DEREF_off(tok_member_value(tok));
1358
		sp = print_offset ( off, bf, sp ) ;
1562
			sp = print_offset(off, bf, sp);
1359
		break ;
1563
			break;
1360
	    }
1564
		}
1361
	    case tok_class_tag : {
1565
		case tok_class_tag: {
1362
		IDENTIFIER cid = DEREF_id ( tok_class_value ( tok ) ) ;
1566
			IDENTIFIER cid = DEREF_id(tok_class_value(tok));
1363
		sp = print_id_short ( cid, qual_none, bf, sp ) ;
1567
			sp = print_id_short(cid, qual_none, bf, sp);
1364
		break ;
1568
			break;
1365
	    }
1569
		}
1366
	    default : {
1570
		default : {
1367
		if ( sp ) bfputc ( bf, ' ' ) ;
1571
			if (sp)bfputc(bf, ' ');
1368
		bfprintf ( bf, "<arg>" ) ;
1572
			bfprintf(bf, "<arg>");
1369
		sp = 1 ;
1573
			sp = 1;
1370
		break ;
1574
			break;
-
 
1575
		}
1371
	    }
1576
		}
1372
	}
1577
	}
1373
    }
-
 
1374
    return ( sp ) ;
1578
	return (sp);
1375
}
1579
}
1376
 
1580
 
1377
 
1581
 
1378
/*
1582
/*
1379
    TOKEN APPLICATION PRINTING
1583
    TOKEN APPLICATION PRINTING
1380
 
1584
 
1381
    This routine prints the token application 'id ( args )' or the template
1585
    This routine prints the token application 'id ( args )' or the template
1382
    application 'id < args >' to the buffer bf.
1586
    application 'id < args >' to the buffer bf.
1383
*/
1587
*/
1384
 
1588
 
1385
int print_token
1589
int
1386
    PROTO_N ( ( id, qual, args, bf, sp ) )
-
 
1387
    PROTO_T ( IDENTIFIER id X QUALIFIER qual X LIST ( TOKEN ) args X
1590
print_token(IDENTIFIER id, QUALIFIER qual, LIST(TOKEN)args, BUFFER *bf, int sp)
1388
	      BUFFER *bf X int sp )
-
 
1389
{
1591
{
1390
    int open_bracket = 0 ;
1592
	int open_bracket = 0;
1391
    int close_bracket = 0 ;
1593
	int close_bracket = 0;
1392
    if ( IS_id_token ( id ) ) {
1594
	if (IS_id_token(id)) {
1393
	/* Token application */
1595
		/* Token application */
1394
	TOKEN tok = DEREF_tok ( id_token_sort ( id ) ) ;
1596
		TOKEN tok = DEREF_tok(id_token_sort(id));
1395
	unsigned tag = TAG_tok ( tok ) ;
1597
		unsigned tag = TAG_tok(tok);
1396
	IDENTIFIER alt = DEREF_id ( id_token_alt ( id ) ) ;
1598
		IDENTIFIER alt = DEREF_id(id_token_alt(id));
1397
	if ( !IS_NULL_id ( alt ) ) id = alt ;
1599
		if (!IS_NULL_id(alt)) {
-
 
1600
			id = alt;
-
 
1601
		}
1398
	if ( tag == tok_proc_tag || !IS_NULL_list ( args ) ) {
1602
		if (tag == tok_proc_tag || !IS_NULL_list(args)) {
1399
	    open_bracket = '(' ;
1603
			open_bracket = '(';
1400
	    close_bracket = ')' ;
1604
			close_bracket = ')';
1401
	} else if ( tag == tok_class_tag ) {
1605
		} else if (tag == tok_class_tag) {
1402
	    open_bracket = '<' ;
1606
			open_bracket = '<';
1403
	    close_bracket = '>' ;
1607
			close_bracket = '>';
1404
	}
1608
		}
1405
    } else {
1609
	} else {
1406
	/* Template application */
1610
		/* Template application */
1407
	open_bracket = '<' ;
1611
		open_bracket = '<';
1408
	close_bracket = '>' ;
1612
		close_bracket = '>';
1409
    }
-
 
1410
    sp = print_id_short ( id, qual, bf, sp ) ;
-
 
1411
    if ( open_bracket ) {
-
 
1412
	int first = 1 ;
-
 
1413
	bfputc ( bf, ' ' ) ;
-
 
1414
	bfputc ( bf, open_bracket ) ;
-
 
1415
	while ( !IS_NULL_list ( args ) ) {
-
 
1416
	    TOKEN ptok = DEREF_tok ( HEAD_list ( args ) ) ;
-
 
1417
	    if ( !IS_NULL_tok ( ptok ) ) {
-
 
1418
		if ( !first ) bfputc ( bf, ',' ) ;
-
 
1419
		IGNORE print_tok_value ( ptok, bf, 1 ) ;
-
 
1420
		first = 0 ;
-
 
1421
	    }
-
 
1422
	    args = TAIL_list ( args ) ;
-
 
1423
	}
1613
	}
-
 
1614
	sp = print_id_short(id, qual, bf, sp);
-
 
1615
	if (open_bracket) {
-
 
1616
		int first = 1;
-
 
1617
		bfputc(bf, ' ');
-
 
1618
		bfputc(bf, open_bracket);
-
 
1619
		while (!IS_NULL_list(args)) {
-
 
1620
			TOKEN ptok = DEREF_tok(HEAD_list(args));
-
 
1621
			if (!IS_NULL_tok(ptok)) {
-
 
1622
				if (!first) {
-
 
1623
					bfputc(bf, ',');
-
 
1624
				}
-
 
1625
				IGNORE print_tok_value(ptok, bf, 1);
-
 
1626
				first = 0;
-
 
1627
			}
-
 
1628
			args = TAIL_list(args);
-
 
1629
		}
-
 
1630
		if (!first) {
1424
	if ( !first ) bfputc ( bf, ' ' ) ;
1631
			bfputc(bf, ' ');
-
 
1632
		}
1425
	bfputc ( bf, close_bracket ) ;
1633
		bfputc(bf, close_bracket);
1426
	sp = 1 ;
1634
		sp = 1;
1427
    }
1635
	}
1428
    return ( sp ) ;
1636
	return (sp);
1429
}
1637
}
1430
 
1638
 
1431
 
1639
 
1432
/*
1640
/*
1433
    TOKEN SORT PRINTING
1641
    TOKEN SORT PRINTING
1434
 
1642
 
1435
    This routine prints the token sort tok to the buffer bf.
1643
    This routine prints the token sort tok to the buffer bf.
1656
		}
1798
		}
-
 
1799
		if (simple) {
-
 
1800
			if (sp) {
-
 
1801
				bfputc(bf, ' ');
-
 
1802
			}
-
 
1803
			bfputc(bf, ')');
-
 
1804
		} else {
-
 
1805
			bfprintf(bf, " |");
-
 
1806
			sp = 0;
-
 
1807
			while (!IS_NULL_list(p)) {
-
 
1808
				IDENTIFIER id = DEREF_id(HEAD_list(p));
-
 
1809
				if (!IS_NULL_id(id)) {
-
 
1810
					if (sp) {
-
 
1811
						bfputc(bf, ',');
-
 
1812
					}
-
 
1813
					if (IS_id_token(id)) {
-
 
1814
						/* Simple token parameter */
-
 
1815
						HASHID nm =
-
 
1816
						    DEREF_hashid(id_name(id));
-
 
1817
						TOKEN par = DEREF_tok(id_token_sort(id));
-
 
1818
						IGNORE print_sort(par, 1, bf,
-
 
1819
								  1);
-
 
1820
						IGNORE print_hashid(nm, 0, 0,
-
 
1821
								    bf, 1);
-
 
1822
					} else {
-
 
1823
						/* Complex type parameter */
-
 
1824
						TYPE r;
-
 
1825
						r = DEREF_type(id_class_name_etc_defn(id));
-
 
1826
						IGNORE print_lex(lex_type_Hcap,
-
 
1827
								 bf, 1);
-
 
1828
						IGNORE print_type(r, bf, 1);
-
 
1829
					}
-
 
1830
					sp = 1;
-
 
1831
				}
-
 
1832
				p = TAIL_list(p);
-
 
1833
			}
-
 
1834
			bfprintf(bf, " }");
-
 
1835
		}
-
 
1836
		sp = print_sort(res, 0, bf, 1);
-
 
1837
		break;
-
 
1838
	}
-
 
1839
 
-
 
1840
	case tok_templ_tag: {
-
 
1841
		/* Template tokens */
-
 
1842
		LIST(TOKEN)q;
-
 
1843
		LIST(IDENTIFIER)p;
-
 
1844
		DECL_SPEC ex = DEREF_dspec(tok_templ_usage(tok));
-
 
1845
		NAMESPACE ns = DEREF_nspace(tok_templ_pars(tok));
-
 
1846
		if (ex & dspec_extern) {
-
 
1847
			/* Exported templates */
-
 
1848
			sp = print_lex(lex_export, bf, sp);
-
 
1849
		}
-
 
1850
		IGNORE print_lex(lex_template, bf, sp);
-
 
1851
		if (IS_NULL_nspace(ns)) {
-
 
1852
			sp = 1;
-
 
1853
			break;
-
 
1854
		}
-
 
1855
		p = DEREF_list(tok_templ_pids(tok));
-
 
1856
		q = DEREF_list(tok_templ_dargs(tok));
-
 
1857
		bfprintf(bf, " <");
-
 
1858
		sp = 0;
-
 
1859
		while (!IS_NULL_list(p)) {
-
 
1860
			TOKEN val = NULL_tok;
-
 
1861
			IDENTIFIER id = DEREF_id(HEAD_list(p));
-
 
1862
			HASHID nm = DEREF_hashid(id_name(id));
-
 
1863
			if (!IS_NULL_list(q)) {
-
 
1864
				val = DEREF_tok(HEAD_list(q));
-
 
1865
				q = TAIL_list(q);
-
 
1866
			}
-
 
1867
			tok = DEREF_tok(id_token_sort(id));
-
 
1868
			tag = TAG_tok(tok);
-
 
1869
			if (tag == tok_exp_tag) {
-
 
1870
				TYPE t = DEREF_type(tok_exp_type(tok));
-
 
1871
				int sp2 = print_head(t, 0, bf, 1);
-
 
1872
				sp2 = print_hashid(nm, 0, 0, bf, sp2);
-
 
1873
				IGNORE print_tail(t, bf, sp2);
-
 
1874
			} else if (tag == tok_type_tag) {
-
 
1875
				IGNORE print_lex(lex_class, bf, 1);
-
 
1876
				IGNORE print_hashid(nm, 0, 0, bf, 1);
-
 
1877
			} else {
-
 
1878
				IGNORE print_sort(tok, 0, bf, 1);
-
 
1879
				IGNORE print_hashid(nm, 0, 0, bf, 1);
-
 
1880
			}
1657
		if ( !IS_NULL_tok ( val ) ) {
1881
			if (!IS_NULL_tok(val)) {
1658
		    bfprintf ( bf, " =" ) ;
1882
				bfprintf(bf, " =");
1659
		    IGNORE print_tok_value ( val, bf, 1 ) ;
1883
				IGNORE print_tok_value(val, bf, 1);
-
 
1884
			}
-
 
1885
			p = TAIL_list(p);
-
 
1886
			if (!IS_NULL_list(p)) {
-
 
1887
				bfputc(bf, ',');
-
 
1888
			}
-
 
1889
			sp = 1;
1660
		}
1890
		}
1661
		p = TAIL_list ( p ) ;
1891
		if (sp) {
1662
		if ( !IS_NULL_list ( p ) ) bfputc ( bf, ',' ) ;
-
 
1663
		sp = 1 ;
1892
			bfputc(bf, ' ');
1664
	    }
1893
		}
1665
	    if ( sp ) bfputc ( bf, ' ' ) ;
-
 
1666
	    bfputc ( bf, '>' ) ;
1894
		bfputc(bf, '>');
1667
	    sp = 1 ;
1895
		sp = 1;
1668
	    break ;
1896
		break;
-
 
1897
	}
1669
	}
1898
	}
1670
    }
-
 
1671
    return ( sp ) ;
1899
	return (sp);
1672
}
1900
}
1673
 
1901
 
1674
 
1902
 
1675
/*
1903
/*
1676
    INTEGRAL TYPE PRINTING
1904
    INTEGRAL TYPE PRINTING
1677
 
1905
 
1678
    This routine prints an integral type to the buffer bf.  Note that the
1906
    This routine prints an integral type to the buffer bf.  Note that the
1679
    standard full forms, such as 'signed short int', are translated into
1907
    standard full forms, such as 'signed short int', are translated into
1680
    shorter forms, such as 'short'.
1908
    shorter forms, such as 'short'.
1681
*/
1909
*/
1682
 
1910
 
1683
int print_itype
1911
int
1684
    PROTO_N ( ( t, bf, sp ) )
-
 
1685
    PROTO_T ( INT_TYPE t X BUFFER *bf X int sp )
1912
print_itype(INT_TYPE t, BUFFER *bf, int sp)
1686
{
1913
{
1687
    if ( !IS_NULL_itype ( t ) ) {
1914
	if (!IS_NULL_itype(t)) {
1688
	ASSERT ( ORDER_itype == 6 ) ;
1915
		ASSERT(ORDER_itype == 6);
1689
	switch ( TAG_itype ( t ) ) {
1916
		switch (TAG_itype(t)) {
1690
	    case itype_basic_tag : {
1917
		case itype_basic_tag: {
1691
		BUILTIN_TYPE n = DEREF_ntype ( itype_basic_no ( t ) ) ;
1918
			BUILTIN_TYPE n = DEREF_ntype(itype_basic_no(t));
1692
		sp = print_ntype ( n, bf, sp ) ;
1919
			sp = print_ntype(n, bf, sp);
1693
		break ;
1920
			break;
1694
	    }
1921
		}
1695
	    case itype_bitfield_tag : {
1922
		case itype_bitfield_tag: {
1696
		BASE_TYPE bt = DEREF_btype ( itype_bitfield_rep ( t ) ) ;
1923
			BASE_TYPE bt = DEREF_btype(itype_bitfield_rep(t));
1697
		if ( bt & btype_named ) {
1924
			if (bt & btype_named) {
1698
		    TYPE s = DEREF_type ( itype_bitfield_sub ( t ) ) ;
1925
				TYPE s = DEREF_type(itype_bitfield_sub(t));
1699
		    sp = print_type ( s, bf, sp ) ;
1926
				sp = print_type(s, bf, sp);
1700
		} else {
1927
			} else {
1701
		    sp = print_btype ( bt, bf, sp ) ;
1928
				sp = print_btype(bt, bf, sp);
1702
		}
1929
			}
1703
		break ;
1930
			break;
1704
	    }
1931
		}
1705
	    case itype_promote_tag : {
1932
		case itype_promote_tag: {
1706
		INT_TYPE s = DEREF_itype ( itype_promote_arg ( t ) ) ;
1933
			INT_TYPE s = DEREF_itype(itype_promote_arg(t));
-
 
1934
			if (sp) {
1707
		if ( sp ) bfputc ( bf, ' ' ) ;
1935
				bfputc(bf, ' ');
-
 
1936
			}
1708
		bfprintf ( bf, "%s ( ", special_name ( TOK_promote ) ) ;
1937
			bfprintf(bf, "%s ( ", special_name(TOK_promote));
1709
		IGNORE print_itype ( s, bf, 0 ) ;
1938
			IGNORE print_itype(s, bf, 0);
1710
		bfprintf ( bf, " )" ) ;
1939
			bfprintf(bf, " )");
1711
		sp = 1 ;
1940
			sp = 1;
1712
		break ;
1941
			break;
1713
	    }
1942
		}
1714
	    case itype_arith_tag : {
1943
		case itype_arith_tag: {
1715
		INT_TYPE s1 = DEREF_itype ( itype_arith_arg1 ( t ) ) ;
1944
			INT_TYPE s1 = DEREF_itype(itype_arith_arg1(t));
1716
		INT_TYPE s2 = DEREF_itype ( itype_arith_arg2 ( t ) ) ;
1945
			INT_TYPE s2 = DEREF_itype(itype_arith_arg2(t));
-
 
1946
			if (sp) {
1717
		if ( sp ) bfputc ( bf, ' ' ) ;
1947
				bfputc(bf, ' ');
-
 
1948
			}
1718
		bfprintf ( bf, "%s ( ", special_name ( TOK_arith_type ) ) ;
1949
			bfprintf(bf, "%s ( ", special_name(TOK_arith_type));
1719
		IGNORE print_itype ( s1, bf, 0 ) ;
1950
			IGNORE print_itype(s1, bf, 0);
1720
		bfprintf ( bf, ", " ) ;
1951
			bfprintf(bf, ", ");
1721
		IGNORE print_itype ( s2, bf, 0 ) ;
1952
			IGNORE print_itype(s2, bf, 0);
1722
		bfprintf ( bf, " )" ) ;
1953
			bfprintf(bf, " )");
1723
		sp = 1 ;
1954
			sp = 1;
1724
		break ;
1955
			break;
1725
	    }
1956
		}
1726
	    case itype_literal_tag : {
1957
		case itype_literal_tag: {
1727
		NAT n = DEREF_nat ( itype_literal_nat ( t ) ) ;
1958
			NAT n = DEREF_nat(itype_literal_nat(t));
1728
		int tok = DEREF_int ( itype_literal_spec ( t ) ) ;
1959
			int tok = DEREF_int(itype_literal_spec(t));
-
 
1960
			if (sp) {
1729
		if ( sp ) bfputc ( bf, ' ' ) ;
1961
				bfputc(bf, ' ');
-
 
1962
			}
1730
		bfprintf ( bf, "%s ( ", special_name ( tok ) ) ;
1963
			bfprintf(bf, "%s ( ", special_name(tok));
1731
		IGNORE print_nat ( n, 0, bf, 0 ) ;
1964
			IGNORE print_nat(n, 0, bf, 0);
1732
		bfprintf ( bf, " )" ) ;
1965
			bfprintf(bf, " )");
1733
		sp = 1 ;
1966
			sp = 1;
1734
		break ;
1967
			break;
1735
	    }
1968
		}
1736
	    case itype_token_tag : {
1969
		case itype_token_tag: {
1737
		BUILTIN_TYPE n = DEREF_ntype ( itype_unprom ( t ) ) ;
1970
			BUILTIN_TYPE n = DEREF_ntype(itype_unprom(t));
1738
		if ( n == ntype_none || n == ntype_ellipsis ) {
1971
			if (n == ntype_none || n == ntype_ellipsis) {
1739
		    IDENTIFIER id ;
1972
				IDENTIFIER id;
1740
		    LIST ( TOKEN ) args ;
1973
				LIST(TOKEN)args;
1741
		    id = DEREF_id ( itype_token_tok ( t ) ) ;
1974
				id = DEREF_id(itype_token_tok(t));
1742
		    args = DEREF_list ( itype_token_args ( t ) ) ;
1975
				args = DEREF_list(itype_token_args(t));
1743
		    sp = print_token ( id, qual_none, args, bf, sp ) ;
1976
				sp = print_token(id, qual_none, args, bf, sp);
1744
		} else {
1977
			} else {
1745
		    if ( sp ) bfputc ( bf, ' ' ) ;
1978
				if (sp)bfputc(bf, ' ');
-
 
1979
				bfprintf(bf, "%s ( ",
1746
		    bfprintf ( bf, "%s ( ", special_name ( TOK_promote ) ) ;
1980
					 special_name(TOK_promote));
1747
		    IGNORE print_ntype ( n, bf, 0 ) ;
1981
				IGNORE print_ntype(n, bf, 0);
1748
		    bfprintf ( bf, " )" ) ;
1982
				bfprintf(bf, " )");
1749
		    sp = 1 ;
1983
				sp = 1;
-
 
1984
			}
-
 
1985
			break;
-
 
1986
		}
1750
		}
1987
		}
1751
		break ;
-
 
1752
	    }
-
 
1753
	}
1988
	}
1754
    }
-
 
1755
    return ( sp ) ;
1989
	return (sp);
1756
}
1990
}
1757
 
1991
 
1758
 
1992
 
1759
/*
1993
/*
1760
    FLOATING-POINT TYPE PRINTING
1994
    FLOATING-POINT TYPE PRINTING
1761
 
1995
 
1762
    This routine prints a floating-point type to the buffer bf.
1996
    This routine prints a floating-point type to the buffer bf.
1763
*/
1997
*/
1764
 
1998
 
1765
int print_ftype
1999
int
1766
    PROTO_N ( ( t, bf, sp ) )
-
 
1767
    PROTO_T ( FLOAT_TYPE t X BUFFER *bf X int sp )
2000
print_ftype(FLOAT_TYPE t, BUFFER *bf, int sp)
1768
{
2001
{
1769
    if ( !IS_NULL_ftype ( t ) ) {
2002
	if (!IS_NULL_ftype(t)) {
1770
	ASSERT ( ORDER_ftype == 4 ) ;
2003
		ASSERT(ORDER_ftype == 4);
1771
	switch ( TAG_ftype ( t ) ) {
2004
		switch (TAG_ftype(t)) {
1772
	    case ftype_basic_tag : {
2005
		case ftype_basic_tag: {
1773
		BUILTIN_TYPE n = DEREF_ntype ( ftype_basic_no ( t ) ) ;
2006
			BUILTIN_TYPE n = DEREF_ntype(ftype_basic_no(t));
1774
		sp = print_ntype ( n, bf, sp ) ;
2007
			sp = print_ntype(n, bf, sp);
1775
		break ;
2008
			break;
1776
	    }
2009
		}
1777
	    case ftype_arg_promote_tag : {
2010
		case ftype_arg_promote_tag: {
1778
		FLOAT_TYPE s = DEREF_ftype ( ftype_arg_promote_arg ( t ) ) ;
2011
			FLOAT_TYPE s = DEREF_ftype(ftype_arg_promote_arg(t));
-
 
2012
			if (sp) {
1779
		if ( sp ) bfputc ( bf, ' ' ) ;
2013
				bfputc(bf, ' ');
-
 
2014
			}
1780
		bfprintf ( bf, "%s ( ", special_name ( TOK_promote ) ) ;
2015
			bfprintf(bf, "%s ( ", special_name(TOK_promote));
1781
		IGNORE print_ftype ( s, bf, 0 ) ;
2016
			IGNORE print_ftype(s, bf, 0);
1782
		bfprintf ( bf, " )" ) ;
2017
			bfprintf(bf, " )");
1783
		sp = 1 ;
2018
			sp = 1;
1784
		break ;
2019
			break;
1785
	    }
2020
		}
1786
	    case ftype_arith_tag : {
2021
		case ftype_arith_tag: {
1787
		FLOAT_TYPE s1 = DEREF_ftype ( ftype_arith_arg1 ( t ) ) ;
2022
			FLOAT_TYPE s1 = DEREF_ftype(ftype_arith_arg1(t));
1788
		FLOAT_TYPE s2 = DEREF_ftype ( ftype_arith_arg2 ( t ) ) ;
2023
			FLOAT_TYPE s2 = DEREF_ftype(ftype_arith_arg2(t));
-
 
2024
			if (sp) {
1789
		if ( sp ) bfputc ( bf, ' ' ) ;
2025
				bfputc(bf, ' ');
-
 
2026
			}
1790
		bfprintf ( bf, "%s ( ", special_name ( TOK_arith_type ) ) ;
2027
			bfprintf(bf, "%s ( ", special_name(TOK_arith_type));
1791
		IGNORE print_ftype ( s1, bf, 0 ) ;
2028
			IGNORE print_ftype(s1, bf, 0);
1792
		bfprintf ( bf, ", " ) ;
2029
			bfprintf(bf, ", ");
1793
		IGNORE print_ftype ( s2, bf, 0 ) ;
2030
			IGNORE print_ftype(s2, bf, 0);
1794
		bfprintf ( bf, " )" ) ;
2031
			bfprintf(bf, " )");
1795
		sp = 1 ;
2032
			sp = 1;
1796
		break ;
2033
			break;
1797
	    }
2034
		}
1798
	    case ftype_token_tag : {
2035
		case ftype_token_tag: {
1799
		IDENTIFIER id = DEREF_id ( ftype_token_tok ( t ) ) ;
2036
			IDENTIFIER id = DEREF_id(ftype_token_tok(t));
1800
		LIST ( TOKEN ) args = DEREF_list ( ftype_token_args ( t ) ) ;
2037
			LIST(TOKEN)args = DEREF_list(ftype_token_args(t));
1801
		sp = print_token ( id, qual_none, args, bf, sp ) ;
2038
			sp = print_token(id, qual_none, args, bf, sp);
1802
		break ;
2039
			break;
-
 
2040
		}
1803
	    }
2041
		}
1804
	}
2042
	}
1805
    }
-
 
1806
    return ( sp ) ;
2043
	return (sp);
1807
}
2044
}
1808
 
2045
 
1809
 
2046
 
1810
/*
2047
/*
1811
    CLASS TYPE PRINTING
2048
    CLASS TYPE PRINTING
1812
 
2049
 
1813
    This routines prints the class type ct to the buffer bf.
2050
    This routines prints the class type ct to the buffer bf.
1814
*/
2051
*/
1815
 
2052
 
1816
int print_ctype
2053
int
1817
    PROTO_N ( ( ct, qual, key, bf, sp ) )
-
 
1818
    PROTO_T ( CLASS_TYPE ct X QUALIFIER qual X int key X BUFFER *bf X int sp )
2054
print_ctype(CLASS_TYPE ct, QUALIFIER qual, int key, BUFFER *bf, int sp)
1819
{
2055
{
1820
    if ( !IS_NULL_ctype ( ct ) ) {
2056
	if (!IS_NULL_ctype(ct)) {
1821
	TYPE t = DEREF_type ( ctype_form ( ct ) ) ;
2057
		TYPE t = DEREF_type(ctype_form(ct));
1822
	IDENTIFIER id = DEREF_id ( ctype_name ( ct ) ) ;
2058
		IDENTIFIER id = DEREF_id(ctype_name(ct));
1823
	if ( key && IS_id_class_name ( id ) ) {
2059
		if (key && IS_id_class_name(id)) {
1824
	    BASE_TYPE bt = find_class_key ( ct ) ;
2060
			BASE_TYPE bt = find_class_key(ct);
1825
	    sp = print_btype ( bt, bf, sp ) ;
2061
			sp = print_btype(bt, bf, sp);
1826
	}
2062
		}
1827
	if ( !IS_NULL_type ( t ) && IS_type_token ( t ) ) {
2063
		if (!IS_NULL_type(t) && IS_type_token(t)) {
1828
	    IDENTIFIER tid = DEREF_id ( type_token_tok ( t ) ) ;
2064
			IDENTIFIER tid = DEREF_id(type_token_tok(t));
1829
	    LIST ( TOKEN ) args = DEREF_list ( type_token_args ( t ) ) ;
2065
			LIST(TOKEN)args = DEREF_list(type_token_args(t));
1830
	    sp = print_token ( tid, qual, args, bf, sp ) ;
2066
			sp = print_token(tid, qual, args, bf, sp);
1831
	} else {
2067
		} else {
1832
	    sp = print_id_short ( id, qual, bf, sp ) ;
2068
			sp = print_id_short(id, qual, bf, sp);
1833
	}
2069
		}
1834
    }
2070
	}
1835
    return ( sp ) ;
2071
	return (sp);
1836
}
2072
}
1837
 
2073
 
1838
 
2074
 
1839
/*
2075
/*
1840
    ENUMERATION TYPE PRINTING
2076
    ENUMERATION TYPE PRINTING
1841
 
2077
 
1842
    This routines prints the enumeration type et to the buffer bf.
2078
    This routines prints the enumeration type et to the buffer bf.
1843
*/
2079
*/
1844
 
2080
 
1845
int print_etype
2081
int
1846
    PROTO_N ( ( et, key, bf, sp ) )
-
 
1847
    PROTO_T ( ENUM_TYPE et X int key X BUFFER *bf X int sp )
2082
print_etype(ENUM_TYPE et, int key, BUFFER *bf, int sp)
1848
{
2083
{
1849
    if ( !IS_NULL_etype ( et ) ) {
2084
	if (!IS_NULL_etype(et)) {
1850
	IDENTIFIER id = DEREF_id ( etype_name ( et ) ) ;
2085
		IDENTIFIER id = DEREF_id(etype_name(et));
1851
	if ( key && IS_id_enum_name ( id ) ) {
2086
		if (key && IS_id_enum_name(id)) {
1852
	    sp = print_lex ( lex_enum, bf, sp ) ;
2087
			sp = print_lex(lex_enum, bf, sp);
1853
	}
2088
		}
1854
	sp = print_id_short ( id, qual_none, bf, sp ) ;
2089
		sp = print_id_short(id, qual_none, bf, sp);
1855
    }
2090
	}
1856
    return ( sp ) ;
2091
	return (sp);
1857
}
2092
}
1858
 
2093
 
1859
 
2094
 
1860
/*
2095
/*
1861
    CHECK FOR TAILED TYPES
2096
    CHECK FOR TAILED TYPES
1862
 
2097
 
1863
    This routine tested whether the type t is a tailed type, that is an
2098
    This routine tested whether the type t is a tailed type, that is an
1864
    array, bitfield, or function type.
2099
    array, bitfield, or function type.
1865
*/
2100
*/
1866
 
2101
 
1867
static int is_tailed_type
2102
static int
1868
    PROTO_N ( ( t ) )
-
 
1869
    PROTO_T ( TYPE t )
2103
is_tailed_type(TYPE t)
1870
{
2104
{
1871
    if ( !IS_NULL_type ( t ) ) {
2105
	if (!IS_NULL_type(t)) {
1872
	IDENTIFIER tid = DEREF_id ( type_name ( t ) ) ;
2106
		IDENTIFIER tid = DEREF_id(type_name(t));
1873
	if ( IS_NULL_id ( tid ) || !print_type_alias ) {
2107
		if (IS_NULL_id(tid) || !print_type_alias) {
1874
	    switch ( TAG_type ( t ) ) {
2108
			switch (TAG_type(t)) {
1875
		case type_func_tag :
2109
			case type_func_tag:
1876
		case type_array_tag :
2110
			case type_array_tag:
1877
		case type_bitfield_tag : {
2111
			case type_bitfield_tag: {
1878
		    return ( 1 ) ;
2112
				return (1);
1879
		}
2113
			}
1880
		case type_templ_tag : {
2114
			case type_templ_tag: {
1881
		    TYPE s = DEREF_type ( type_templ_defn ( t ) ) ;
2115
				TYPE s = DEREF_type(type_templ_defn(t));
1882
		    return ( is_tailed_type ( s ) ) ;
2116
				return (is_tailed_type(s));
1883
		}
2117
			}
1884
	    }
2118
			}
1885
	}
2119
		}
1886
    }
2120
	}
1887
    return ( 0 ) ;
2121
	return (0);
1888
}
2122
}
1889
 
2123
 
1890
 
2124
 
1891
/*
2125
/*
1892
    TYPE HEAD PRINTING
2126
    TYPE HEAD PRINTING
1893
 
2127
 
1894
    This routine prints the head of a type (i.e. the main part and any
2128
    This routine prints the head of a type (i.e. the main part and any
1895
    pointer or reference components) to the buffer bf.
2129
    pointer or reference components) to the buffer bf.
1896
*/
2130
*/
1897
 
2131
 
1898
static int print_head
2132
static int
1899
    PROTO_N ( ( t, key, bf, sp ) )
-
 
1900
    PROTO_T ( TYPE t X int key X BUFFER *bf X int sp )
2133
print_head(TYPE t, int key, BUFFER *bf, int sp)
1901
{
2134
{
1902
    if ( IS_NULL_type ( t ) ) {
2135
	if (IS_NULL_type(t)) {
1903
	static unsigned long type_no = 0 ;
2136
		static unsigned long type_no = 0;
-
 
2137
		if (sp) {
1904
	if ( sp ) bfputc ( bf, ' ' ) ;
2138
			bfputc(bf, ' ');
-
 
2139
		}
1905
	bfprintf ( bf, "<type%lu>", ++type_no ) ;
2140
		bfprintf(bf, "<type%lu>", ++type_no);
1906
	sp = 1 ;
2141
		sp = 1;
1907
    } else {
2142
	} else {
1908
	CV_SPEC qual = DEREF_cv ( type_qual ( t ) ) ;
2143
		CV_SPEC qual = DEREF_cv(type_qual(t));
1909
	IDENTIFIER tid = DEREF_id ( type_name ( t ) ) ;
2144
		IDENTIFIER tid = DEREF_id(type_name(t));
1910
	qual &= cv_qual ;
2145
		qual &= cv_qual;
1911
	if ( !IS_NULL_id ( tid ) && print_type_alias ) {
2146
		if (!IS_NULL_id(tid) && print_type_alias) {
1912
	    switch ( TAG_id ( tid ) ) {
2147
			switch (TAG_id(tid)) {
1913
		case id_class_alias_tag :
2148
			case id_class_alias_tag:
1914
		case id_enum_alias_tag :
2149
			case id_enum_alias_tag:
1915
		case id_type_alias_tag : {
2150
			case id_type_alias_tag: {
1916
		    /* Print type aliases */
2151
				/* Print type aliases */
1917
		    if ( !IS_type_pre ( t ) ) {
2152
				if (!IS_type_pre(t)) {
1918
			sp = print_cv ( qual, bf, sp ) ;
2153
					sp = print_cv(qual, bf, sp);
1919
			sp = print_id_short ( tid, qual_none, bf, sp ) ;
2154
					sp = print_id_short(tid, qual_none, bf,
-
 
2155
							    sp);
1920
			return ( sp ) ;
2156
					return (sp);
1921
		    }
2157
				}
1922
		    break ;
2158
				break;
-
 
2159
			}
-
 
2160
			}
-
 
2161
		}
-
 
2162
		ASSERT(ORDER_type == 18);
-
 
2163
		switch (TAG_type(t)) {
-
 
2164
		case type_pre_tag: {
-
 
2165
			/* Pre-types */
-
 
2166
			BASE_TYPE bt = DEREF_btype(type_pre_rep(t));
-
 
2167
			BASE_TYPE kt = (bt & btype_named);
-
 
2168
			sp = print_cv(qual, bf, sp);
-
 
2169
			if (kt) {
-
 
2170
				if (kt == btype_alias) {
-
 
2171
					sp = print_id_short(tid, qual_none, bf,
-
 
2172
							    sp);
-
 
2173
				} else {
-
 
2174
					HASHID nm = DEREF_hashid(id_name(tid));
-
 
2175
					sp = print_btype(kt, bf, sp);
-
 
2176
					sp = print_hashid(nm, 0, 0, bf, sp);
-
 
2177
				}
-
 
2178
			} else {
-
 
2179
				sp = print_btype(bt, bf, sp);
-
 
2180
			}
-
 
2181
			break;
-
 
2182
		}
-
 
2183
		case type_integer_tag: {
-
 
2184
			/* Integral types */
-
 
2185
			INT_TYPE it = DEREF_itype(type_integer_rep(t));
-
 
2186
			sp = print_cv(qual, bf, sp);
-
 
2187
			sp = print_itype(it, bf, sp);
-
 
2188
			break;
-
 
2189
		}
-
 
2190
		case type_floating_tag: {
-
 
2191
			/* Floating-point types */
-
 
2192
			FLOAT_TYPE ft = DEREF_ftype(type_floating_rep(t));
-
 
2193
			sp = print_cv(qual, bf, sp);
-
 
2194
			sp = print_ftype(ft, bf, sp);
-
 
2195
			break;
-
 
2196
		}
-
 
2197
		case type_top_tag: {
-
 
2198
			/* Top type */
-
 
2199
			sp = print_cv(qual, bf, sp);
-
 
2200
			sp = print_ntype(ntype_void, bf, sp);
-
 
2201
			break;
-
 
2202
		}
-
 
2203
		case type_bottom_tag: {
-
 
2204
			/* Bottom type */
-
 
2205
			sp = print_cv(qual, bf, sp);
-
 
2206
			sp = print_ntype(ntype_bottom, bf, sp);
-
 
2207
			break;
-
 
2208
		}
-
 
2209
		case type_ptr_tag: {
-
 
2210
			/* Pointer type */
-
 
2211
			TYPE s = DEREF_type(type_ptr_sub(t));
-
 
2212
			sp = print_head(s, key, bf, sp);
-
 
2213
			if (is_tailed_type(s)) {
-
 
2214
				bfprintf(bf, " ( *");
-
 
2215
			} else {
-
 
2216
				if (sp) {
-
 
2217
					bfputc(bf, ' ');
-
 
2218
				}
-
 
2219
				bfputc(bf, '*');
-
 
2220
			}
-
 
2221
			sp = (qual ? print_cv(qual, bf, 1) : 0);
-
 
2222
			break;
-
 
2223
		}
-
 
2224
		case type_ref_tag: {
-
 
2225
			/* Reference type */
-
 
2226
			TYPE s = DEREF_type(type_ref_sub(t));
-
 
2227
			sp = print_head(s, key, bf, sp);
-
 
2228
			if (is_tailed_type(s)) {
-
 
2229
				bfprintf(bf, " ( &");
-
 
2230
			} else {
-
 
2231
				if (sp) {
-
 
2232
					bfputc(bf, ' ');
-
 
2233
				}
-
 
2234
				bfputc(bf, '&');
-
 
2235
			}
-
 
2236
			sp = (qual ? print_cv(qual, bf, 1) : 0);
-
 
2237
			break;
-
 
2238
		}
-
 
2239
		case type_ptr_mem_tag: {
-
 
2240
			/* Pointer to member type */
-
 
2241
			TYPE s = DEREF_type(type_ptr_mem_sub(t));
-
 
2242
			CLASS_TYPE ct = DEREF_ctype(type_ptr_mem_of(t));
-
 
2243
			sp = print_head(s, key, bf, sp);
-
 
2244
			if (is_tailed_type(s)) {
-
 
2245
				bfprintf(bf, " ( ");
-
 
2246
				sp = 0;
-
 
2247
			}
-
 
2248
			IGNORE print_ctype(ct, qual_none, 0, bf, sp);
-
 
2249
			bfprintf(bf, "::*");
-
 
2250
			sp = (qual ? print_cv(qual, bf, 1) : 0);
-
 
2251
			break;
-
 
2252
		}
-
 
2253
		case type_func_tag: {
-
 
2254
			/* Function type */
-
 
2255
			qual = DEREF_cv(type_func_mqual(t));
-
 
2256
			if (qual && print_func_linkage) {
-
 
2257
				sp = print_linkage(qual, bf, sp);
-
 
2258
			}
-
 
2259
			if (print_return_type) {
-
 
2260
				TYPE r = DEREF_type(type_func_ret(t));
-
 
2261
				if (!IS_NULL_type(r)) {
-
 
2262
					sp = print_head(r, 0, bf, sp);
-
 
2263
				}
-
 
2264
			}
-
 
2265
			break;
-
 
2266
		}
-
 
2267
		case type_array_tag: {
-
 
2268
			/* Array type */
-
 
2269
			TYPE s = DEREF_type(type_array_sub(t));
-
 
2270
			sp = print_head(s, key, bf, sp);
-
 
2271
			break;
-
 
2272
		}
-
 
2273
		case type_bitfield_tag: {
-
 
2274
			/* Bitfield type */
-
 
2275
			INT_TYPE it = DEREF_itype(type_bitfield_defn(t));
-
 
2276
			sp = print_cv(qual, bf, sp);
-
 
2277
			sp = print_itype(it, bf, sp);
-
 
2278
			break;
-
 
2279
		}
-
 
2280
		case type_compound_tag: {
-
 
2281
			/* Class type */
-
 
2282
			CLASS_TYPE ct = DEREF_ctype(type_compound_defn(t));
-
 
2283
			sp = print_cv(qual, bf, sp);
-
 
2284
			sp = print_ctype(ct, qual_none, key, bf, sp);
-
 
2285
			break;
-
 
2286
		}
-
 
2287
		case type_enumerate_tag: {
-
 
2288
			/* Enumeration type */
-
 
2289
			ENUM_TYPE et = DEREF_etype(type_enumerate_defn(t));
-
 
2290
			sp = print_cv(qual, bf, sp);
-
 
2291
			sp = print_etype(et, key, bf, sp);
-
 
2292
			break;
-
 
2293
		}
-
 
2294
		case type_token_tag: {
-
 
2295
			/* Tokenised type */
-
 
2296
			IDENTIFIER id = DEREF_id(type_token_tok(t));
-
 
2297
			LIST(TOKEN)args = DEREF_list(type_token_args(t));
-
 
2298
			sp = print_cv(qual, bf, sp);
-
 
2299
			sp = print_token(id, qual_none, args, bf, sp);
-
 
2300
			break;
-
 
2301
		}
-
 
2302
		case type_templ_tag: {
-
 
2303
			/* Template type */
-
 
2304
			TYPE s = DEREF_type(type_templ_defn(t));
-
 
2305
			TOKEN tok = DEREF_tok(type_templ_sort(t));
-
 
2306
			sp = print_sort(tok, 0, bf, sp);
-
 
2307
			sp = print_cv(qual, bf, sp);
-
 
2308
			sp = print_head(s, 1, bf, sp);
-
 
2309
			break;
-
 
2310
		}
-
 
2311
		case type_instance_tag: {
-
 
2312
			/* Instance type */
-
 
2313
			IDENTIFIER id = DEREF_id(type_name(t));
-
 
2314
			sp = print_id_short(id, qual_none, bf, sp);
-
 
2315
			break;
-
 
2316
		}
-
 
2317
		default : {
-
 
2318
			/* Error type */
-
 
2319
			sp = print_cv(qual, bf, sp);
-
 
2320
			if (sp) {
-
 
2321
				bfputc(bf, ' ');
-
 
2322
			}
-
 
2323
			bfprintf(bf, "<error_type>");
-
 
2324
			sp = 1;
-
 
2325
			break;
-
 
2326
		}
1923
		}
2327
		}
1924
	    }
-
 
1925
	}
2328
	}
1926
	ASSERT ( ORDER_type == 18 ) ;
-
 
1927
	switch ( TAG_type ( t ) ) {
-
 
1928
	    case type_pre_tag : {
-
 
1929
		/* Pre-types */
-
 
1930
		BASE_TYPE bt = DEREF_btype ( type_pre_rep ( t ) ) ;
-
 
1931
		BASE_TYPE kt = ( bt & btype_named ) ;
-
 
1932
		sp = print_cv ( qual, bf, sp ) ;
-
 
1933
		if ( kt ) {
-
 
1934
		    if ( kt == btype_alias ) {
-
 
1935
			sp = print_id_short ( tid, qual_none, bf, sp ) ;
-
 
1936
		    } else {
-
 
1937
			HASHID nm = DEREF_hashid ( id_name ( tid ) ) ;
-
 
1938
			sp = print_btype ( kt, bf, sp ) ;
-
 
1939
			sp = print_hashid ( nm, 0, 0, bf, sp ) ;
-
 
1940
		    }
-
 
1941
		} else {
-
 
1942
		    sp = print_btype ( bt, bf, sp ) ;
-
 
1943
		}
-
 
1944
		break ;
-
 
1945
	    }
-
 
1946
	    case type_integer_tag : {
-
 
1947
		/* Integral types */
-
 
1948
		INT_TYPE it = DEREF_itype ( type_integer_rep ( t ) ) ;
-
 
1949
		sp = print_cv ( qual, bf, sp ) ;
-
 
1950
		sp = print_itype ( it, bf, sp ) ;
-
 
1951
		break ;
-
 
1952
	    }
-
 
1953
	    case type_floating_tag : {
-
 
1954
		/* Floating-point types */
-
 
1955
		FLOAT_TYPE ft = DEREF_ftype ( type_floating_rep ( t ) ) ;
-
 
1956
		sp = print_cv ( qual, bf, sp ) ;
-
 
1957
		sp = print_ftype ( ft, bf, sp ) ;
-
 
1958
		break ;
-
 
1959
	    }
-
 
1960
	    case type_top_tag : {
-
 
1961
		/* Top type */
-
 
1962
		sp = print_cv ( qual, bf, sp ) ;
-
 
1963
		sp = print_ntype ( ntype_void, bf, sp ) ;
-
 
1964
		break ;
-
 
1965
	    }
-
 
1966
	    case type_bottom_tag : {
-
 
1967
		/* Bottom type */
-
 
1968
		sp = print_cv ( qual, bf, sp ) ;
-
 
1969
		sp = print_ntype ( ntype_bottom, bf, sp ) ;
-
 
1970
		break ;
-
 
1971
	    }
-
 
1972
	    case type_ptr_tag : {
-
 
1973
		/* Pointer type */
-
 
1974
		TYPE s = DEREF_type ( type_ptr_sub ( t ) ) ;
-
 
1975
		sp = print_head ( s, key, bf, sp ) ;
-
 
1976
		if ( is_tailed_type ( s ) ) {
-
 
1977
		    bfprintf ( bf, " ( *" ) ;
-
 
1978
		} else {
-
 
1979
		    if ( sp ) bfputc ( bf, ' ' ) ;
-
 
1980
		    bfputc ( bf, '*' ) ;
-
 
1981
		}
-
 
1982
		sp = ( qual ? print_cv ( qual, bf, 1 ) : 0 ) ;
-
 
1983
		break ;
-
 
1984
	    }
-
 
1985
	    case type_ref_tag : {
-
 
1986
		/* Reference type */
-
 
1987
		TYPE s = DEREF_type ( type_ref_sub ( t ) ) ;
-
 
1988
		sp = print_head ( s, key, bf, sp ) ;
-
 
1989
		if ( is_tailed_type ( s ) ) {
-
 
1990
		    bfprintf ( bf, " ( &" ) ;
-
 
1991
		} else {
-
 
1992
		    if ( sp ) bfputc ( bf, ' ' ) ;
-
 
1993
		    bfputc ( bf, '&' ) ;
-
 
1994
		}
-
 
1995
		sp = ( qual ? print_cv ( qual, bf, 1 ) : 0 ) ;
-
 
1996
		break ;
-
 
1997
	    }
-
 
1998
	    case type_ptr_mem_tag : {
-
 
1999
		/* Pointer to member type */
-
 
2000
		TYPE s = DEREF_type ( type_ptr_mem_sub ( t ) ) ;
-
 
2001
		CLASS_TYPE ct = DEREF_ctype ( type_ptr_mem_of ( t ) ) ;
-
 
2002
		sp = print_head ( s, key, bf, sp ) ;
-
 
2003
		if ( is_tailed_type ( s ) ) {
-
 
2004
		    bfprintf ( bf, " ( " ) ;
-
 
2005
		    sp = 0 ;
-
 
2006
		}
-
 
2007
		IGNORE print_ctype ( ct, qual_none, 0, bf, sp ) ;
-
 
2008
		bfprintf ( bf, "::*" ) ;
-
 
2009
		sp = ( qual ? print_cv ( qual, bf, 1 ) : 0 ) ;
-
 
2010
		break ;
-
 
2011
	    }
-
 
2012
	    case type_func_tag : {
-
 
2013
		/* Function type */
-
 
2014
		qual = DEREF_cv ( type_func_mqual ( t ) ) ;
-
 
2015
		if ( qual && print_func_linkage ) {
-
 
2016
		    sp = print_linkage ( qual, bf, sp ) ;
-
 
2017
		}
-
 
2018
		if ( print_return_type ) {
-
 
2019
		    TYPE r = DEREF_type ( type_func_ret ( t ) ) ;
-
 
2020
		    if ( !IS_NULL_type ( r ) ) {
-
 
2021
			sp = print_head ( r, 0, bf, sp ) ;
-
 
2022
		    }
-
 
2023
		}
-
 
2024
		break ;
-
 
2025
	    }
-
 
2026
	    case type_array_tag : {
-
 
2027
		/* Array type */
-
 
2028
		TYPE s = DEREF_type ( type_array_sub ( t ) ) ;
-
 
2029
		sp = print_head ( s, key, bf, sp ) ;
-
 
2030
		break ;
-
 
2031
	    }
-
 
2032
	    case type_bitfield_tag : {
-
 
2033
		/* Bitfield type */
-
 
2034
		INT_TYPE it = DEREF_itype ( type_bitfield_defn ( t ) ) ;
-
 
2035
		sp = print_cv ( qual, bf, sp ) ;
-
 
2036
		sp = print_itype ( it, bf, sp ) ;
-
 
2037
		break ;
-
 
2038
	    }
-
 
2039
	    case type_compound_tag : {
-
 
2040
		/* Class type */
-
 
2041
		CLASS_TYPE ct = DEREF_ctype ( type_compound_defn ( t ) ) ;
-
 
2042
		sp = print_cv ( qual, bf, sp ) ;
-
 
2043
		sp = print_ctype ( ct, qual_none, key, bf, sp ) ;
-
 
2044
		break ;
-
 
2045
	    }
-
 
2046
	    case type_enumerate_tag : {
-
 
2047
		/* Enumeration type */
-
 
2048
		ENUM_TYPE et = DEREF_etype ( type_enumerate_defn ( t ) ) ;
-
 
2049
		sp = print_cv ( qual, bf, sp ) ;
-
 
2050
		sp = print_etype ( et, key, bf, sp ) ;
-
 
2051
		break ;
-
 
2052
	    }
-
 
2053
	    case type_token_tag : {
-
 
2054
		/* Tokenised type */
-
 
2055
		IDENTIFIER id = DEREF_id ( type_token_tok ( t ) ) ;
-
 
2056
		LIST ( TOKEN ) args = DEREF_list ( type_token_args ( t ) ) ;
-
 
2057
		sp = print_cv ( qual, bf, sp ) ;
-
 
2058
		sp = print_token ( id, qual_none, args, bf, sp ) ;
-
 
2059
		break ;
-
 
2060
	    }
-
 
2061
	    case type_templ_tag : {
-
 
2062
		/* Template type */
-
 
2063
		TYPE s = DEREF_type ( type_templ_defn ( t ) ) ;
-
 
2064
		TOKEN tok = DEREF_tok ( type_templ_sort ( t ) ) ;
-
 
2065
		sp = print_sort ( tok, 0, bf, sp ) ;
-
 
2066
		sp = print_cv ( qual, bf, sp ) ;
-
 
2067
		sp = print_head ( s, 1, bf, sp ) ;
-
 
2068
		break ;
-
 
2069
	    }
-
 
2070
	    case type_instance_tag : {
-
 
2071
		/* Instance type */
-
 
2072
		IDENTIFIER id = DEREF_id ( type_name ( t ) ) ;
-
 
2073
		sp = print_id_short ( id, qual_none, bf, sp ) ;
-
 
2074
		break ;
-
 
2075
	    }
-
 
2076
	    default : {
-
 
2077
		/* Error type */
-
 
2078
		sp = print_cv ( qual, bf, sp ) ;
-
 
2079
		if ( sp ) bfputc ( bf, ' ' ) ;
-
 
2080
		bfprintf ( bf, "<error_type>" ) ;
-
 
2081
		sp = 1 ;
-
 
2082
		break ;
-
 
2083
	    }
-
 
2084
	}
-
 
2085
    }
-
 
2086
    return ( sp ) ;
2329
	return (sp);
2087
}
2330
}
2088
 
2331
 
2089
 
2332
 
2090
/*
2333
/*
2091
    TYPE TAIL PRINTING
2334
    TYPE TAIL PRINTING
2092
 
2335
 
2093
    This routine prints the tail of a type (i.e. any array, bitfield or
2336
    This routine prints the tail of a type (i.e. any array, bitfield or
2094
    function components) to the buffer bf.
2337
    function components) to the buffer bf.
2095
*/
2338
*/
2096
 
2339
 
2097
static int print_tail
2340
static int
2098
    PROTO_N ( ( t, bf, sp ) )
-
 
2099
    PROTO_T ( TYPE t X BUFFER *bf X int sp )
2341
print_tail(TYPE t, BUFFER *bf, int sp)
2100
{
2342
{
2101
    if ( !IS_NULL_type ( t ) ) {
2343
	if (!IS_NULL_type(t)) {
2102
	IDENTIFIER tid = DEREF_id ( type_name ( t ) ) ;
2344
		IDENTIFIER tid = DEREF_id(type_name(t));
2103
	if ( !IS_NULL_id ( tid ) && print_type_alias ) {
2345
		if (!IS_NULL_id(tid) && print_type_alias) {
2104
	    return ( sp ) ;
2346
			return (sp);
2105
	}
2347
		}
2106
	switch ( TAG_type ( t ) ) {
2348
		switch (TAG_type(t)) {
2107
	    case type_ptr_tag :
2349
		case type_ptr_tag:
2108
	    case type_ref_tag : {
2350
		case type_ref_tag: {
2109
		/* Pointer and reference types */
2351
			/* Pointer and reference types */
2110
		TYPE s = DEREF_type ( type_ptr_etc_sub ( t ) ) ;
2352
			TYPE s = DEREF_type(type_ptr_etc_sub(t));
2111
		if ( is_tailed_type ( s ) ) bfprintf ( bf, " )" ) ;
2353
			if (is_tailed_type(s)) {
-
 
2354
				bfprintf(bf, " )");
-
 
2355
			}
2112
		sp = print_tail ( s, bf, sp ) ;
2356
			sp = print_tail(s, bf, sp);
2113
		break ;
2357
			break;
2114
	    }
2358
		}
2115
	    case type_ptr_mem_tag : {
2359
		case type_ptr_mem_tag: {
2116
		/* Pointer to member type */
2360
			/* Pointer to member type */
2117
		TYPE s = DEREF_type ( type_ptr_mem_sub ( t ) ) ;
2361
			TYPE s = DEREF_type(type_ptr_mem_sub(t));
2118
		if ( is_tailed_type ( s ) ) bfprintf ( bf, " )" ) ;
2362
			if (is_tailed_type(s)) {
-
 
2363
				bfprintf(bf, " )");
-
 
2364
			}
2119
		sp = print_tail ( s, bf, sp ) ;
2365
			sp = print_tail(s, bf, sp);
2120
		break ;
2366
			break;
2121
	    }
2367
		}
2122
	    case type_func_tag : {
2368
		case type_func_tag: {
2123
		/* Function type */
2369
			/* Function type */
2124
		int prt = print_return_type ;
2370
			int prt = print_return_type;
2125
		int ell = DEREF_int ( type_func_ellipsis ( t ) ) ;
2371
			int ell = DEREF_int(type_func_ellipsis(t));
2126
		CV_SPEC qual = DEREF_cv ( type_func_mqual ( t ) ) ;
2372
			CV_SPEC qual = DEREF_cv(type_func_mqual(t));
2127
		LIST ( TYPE ) p = DEREF_list ( type_func_ptypes ( t ) ) ;
2373
			LIST(TYPE)p = DEREF_list(type_func_ptypes(t));
2128
		LIST ( IDENTIFIER ) q = DEREF_list ( type_func_pids ( t ) ) ;
2374
			LIST(IDENTIFIER)q = DEREF_list(type_func_pids(t));
2129
		LIST ( TYPE ) ex = DEREF_list ( type_func_except ( t ) ) ;
2375
			LIST(TYPE)ex = DEREF_list(type_func_except(t));
2130
		sp = 0 ;
2376
			sp = 0;
2131
		if ( print_member_type ) {
2377
			if (print_member_type) {
2132
		    /* Print member parameter types */
2378
				/* Print member parameter types */
2133
		    p = DEREF_list ( type_func_mtypes ( t ) ) ;
2379
				p = DEREF_list(type_func_mtypes(t));
2134
		}
2380
			}
2135
		if ( ell & FUNC_WEAK ) {
2381
			if (ell & FUNC_WEAK) {
2136
		    /* Weak function prototype */
2382
				/* Weak function prototype */
2137
		    bfprintf ( bf, " WEAK" ) ;
2383
				bfprintf(bf, " WEAK");
2138
		}
2384
			}
2139
		bfprintf ( bf, " (" ) ;
2385
			bfprintf(bf, " (");
2140
		if ( IS_NULL_list ( p ) && !( ell & FUNC_ELLIPSIS ) ) {
2386
			if (IS_NULL_list(p) && !(ell & FUNC_ELLIPSIS)) {
2141
		    /* There are no parameters */
2387
				/* There are no parameters */
2142
		    if ( !( ell & FUNC_NO_PARAMS ) && print_c_style ) {
2388
				if (!(ell & FUNC_NO_PARAMS) && print_c_style) {
2143
			bfprintf ( bf, " void" ) ;
2389
					bfprintf(bf, " void");
2144
			sp = 1 ;
2390
					sp = 1;
2145
		    }
2391
				}
2146
		} else {
2392
			} else {
2147
		    /* Print parameters */
2393
				/* Print parameters */
2148
		    int pars = print_func_params ;
2394
				int pars = print_func_params;
2149
		    int dargs = print_default_args ;
2395
				int dargs = print_default_args;
2150
		    if ( LENGTH_list ( p ) != LENGTH_list ( q ) ) dargs = 0 ;
2396
				if (LENGTH_list(p) != LENGTH_list(q)) {
-
 
2397
					dargs = 0;
-
 
2398
				}
2151
		    print_return_type = 1 ;
2399
				print_return_type = 1;
2152
		    while ( !IS_NULL_list ( p ) ) {
2400
				while (!IS_NULL_list(p)) {
2153
			TYPE s = DEREF_type ( HEAD_list ( p ) ) ;
2401
					TYPE s = DEREF_type(HEAD_list(p));
-
 
2402
					if (ell & FUNC_PARAMS) {
2154
			if ( ell & FUNC_PARAMS ) s = unpromote_type ( s ) ;
2403
						s = unpromote_type(s);
-
 
2404
					}
2155
			IGNORE print_type ( s, bf, 1 ) ;
2405
					IGNORE print_type(s, bf, 1);
2156
			if ( dargs ) {
2406
					if (dargs) {
2157
			    /* Print default argument */
2407
						/* Print default argument */
-
 
2408
						IDENTIFIER id =
2158
			    IDENTIFIER id = DEREF_id ( HEAD_list ( q ) ) ;
2409
						    DEREF_id(HEAD_list(q));
2159
			    EXP e = DEREF_exp ( id_parameter_init ( id ) ) ;
2410
						EXP e = DEREF_exp(id_parameter_init(id));
2160
			    if ( pars ) {
2411
						if (pars) {
2161
				HASHID nm = DEREF_hashid ( id_name ( id ) ) ;
2412
							HASHID nm = DEREF_hashid(id_name(id));
2162
				IGNORE print_hashid ( nm, 0, 0, bf, 1 ) ;
2413
							IGNORE print_hashid(nm, 0, 0, bf, 1);
2163
			    }
2414
						}
2164
			    if ( !IS_NULL_exp ( e ) ) {
2415
						if (!IS_NULL_exp(e)) {
2165
				bfprintf ( bf, " = " ) ;
2416
							bfprintf(bf, " = ");
2166
				IGNORE print_exp ( e, 0, bf, 0 ) ;
2417
							IGNORE print_exp(e, 0, bf, 0);
2167
			    }
2418
						}
2168
			    q = TAIL_list ( q ) ;
2419
						q = TAIL_list(q);
2169
			}
2420
					}
2170
			p = TAIL_list ( p ) ;
2421
					p = TAIL_list(p);
2171
			if ( !IS_NULL_list ( p ) ) {
2422
					if (!IS_NULL_list(p)) {
2172
			    bfputc ( bf, ',' ) ;
2423
						bfputc(bf, ',');
2173
			} else if ( ell & FUNC_ELLIPSIS ) {
2424
					} else if (ell & FUNC_ELLIPSIS) {
2174
			    bfputc ( bf, ',' ) ;
2425
						bfputc(bf, ',');
-
 
2426
					}
-
 
2427
					sp = 1;
-
 
2428
				}
-
 
2429
				if (ell & FUNC_ELLIPSIS) {
-
 
2430
					bfprintf(bf, " ...");
-
 
2431
					sp = 1;
-
 
2432
				}
-
 
2433
				print_return_type = prt;
-
 
2434
			}
-
 
2435
			if (sp) {
-
 
2436
				bfputc(bf, ' ');
-
 
2437
			}
-
 
2438
			bfputc(bf, ')');
-
 
2439
			sp = print_cv(qual, bf, 1);
-
 
2440
			if (prt) {
-
 
2441
				TYPE r = DEREF_type(type_func_ret(t));
-
 
2442
				if (!IS_NULL_type(r)) {
-
 
2443
					sp = print_tail(r, bf, sp);
-
 
2444
				}
2175
			}
2445
			}
-
 
2446
			if (!EQ_list(ex, univ_type_set) && print_except) {
-
 
2447
				/* Print exception specifier */
-
 
2448
				sp = print_lex(lex_throw, bf, sp);
-
 
2449
				sp = print_type_list(ex, bf, sp);
-
 
2450
			}
2176
			sp = 1 ;
2451
			break;
2177
		    }
2452
		}
2178
		    if ( ell & FUNC_ELLIPSIS ) {
2453
		case type_array_tag: {
-
 
2454
			/* Array type */
-
 
2455
			TYPE s = DEREF_type(type_array_sub(t));
-
 
2456
			NAT n = DEREF_nat(type_array_size(t));
2179
			bfprintf ( bf, " ..." ) ;
2457
			bfprintf(bf, " [");
-
 
2458
			IGNORE print_nat(n, 0, bf, 0);
-
 
2459
			bfprintf(bf, "]");
-
 
2460
			sp = print_tail(s, bf, 1);
2180
			sp = 1 ;
2461
			break;
2181
		    }
2462
		}
-
 
2463
		case type_bitfield_tag: {
-
 
2464
			/* Bitfield type */
-
 
2465
			INT_TYPE it = DEREF_itype(type_bitfield_defn(t));
-
 
2466
			NAT n = DEREF_nat(itype_bitfield_size(it));
-
 
2467
			bfputc(bf, ' ');
-
 
2468
			bfputc(bf, print_bitfield_sep);
2182
		    print_return_type = prt ;
2469
			IGNORE print_nat(n, 0, bf, 1);
-
 
2470
			break;
2183
		}
2471
		}
2184
		if ( sp ) bfputc ( bf, ' ' ) ;
-
 
2185
		bfputc ( bf, ')' ) ;
2472
		case type_templ_tag: {
2186
		sp = print_cv ( qual, bf, 1 ) ;
-
 
2187
		if ( prt ) {
2473
			/* Template type */
2188
		    TYPE r = DEREF_type ( type_func_ret ( t ) ) ;
2474
			TYPE s = DEREF_type(type_templ_defn(t));
2189
		    if ( !IS_NULL_type ( r ) ) {
-
 
2190
			sp = print_tail ( r, bf, sp ) ;
2475
			sp = print_tail(s, bf, sp);
2191
		    }
2476
			break;
2192
		}
2477
		}
2193
		if ( !EQ_list ( ex, univ_type_set ) && print_except ) {
-
 
2194
		    /* Print exception specifier */
-
 
2195
		    sp = print_lex ( lex_throw, bf, sp ) ;
-
 
2196
		    sp = print_type_list ( ex, bf, sp ) ;
-
 
2197
		}
2478
		}
2198
		break ;
-
 
2199
	    }
-
 
2200
	    case type_array_tag : {
-
 
2201
		/* Array type */
-
 
2202
		TYPE s = DEREF_type ( type_array_sub ( t ) ) ;
-
 
2203
		NAT n = DEREF_nat ( type_array_size ( t ) ) ;
-
 
2204
		bfprintf ( bf, " [" ) ;
-
 
2205
		IGNORE print_nat ( n, 0, bf, 0 ) ;
-
 
2206
		bfprintf ( bf, "]" ) ;
-
 
2207
		sp = print_tail ( s, bf, 1 ) ;
-
 
2208
		break ;
-
 
2209
	    }
-
 
2210
	    case type_bitfield_tag : {
-
 
2211
		/* Bitfield type */
-
 
2212
		INT_TYPE it = DEREF_itype ( type_bitfield_defn ( t ) ) ;
-
 
2213
		NAT n = DEREF_nat ( itype_bitfield_size ( it ) ) ;
-
 
2214
		bfputc ( bf, ' ' ) ;
-
 
2215
		bfputc ( bf, print_bitfield_sep ) ;
-
 
2216
		IGNORE print_nat ( n, 0, bf, 1 ) ;
-
 
2217
		break ;
-
 
2218
	    }
-
 
2219
	    case type_templ_tag : {
-
 
2220
		/* Template type */
-
 
2221
		TYPE s = DEREF_type ( type_templ_defn ( t ) ) ;
-
 
2222
		sp = print_tail ( s, bf, sp ) ;
-
 
2223
		break ;
-
 
2224
	    }
-
 
2225
	}
2479
	}
2226
    }
-
 
2227
    return ( sp ) ;
2480
	return (sp);
2228
}
2481
}
2229
 
2482
 
2230
 
2483
 
2231
/*
2484
/*
2232
    PRINT A TYPE
2485
    PRINT A TYPE
Line 2235... Line 2488...
2235
    two passes - the first prints the head of the type, comprising the
2488
    two passes - the first prints the head of the type, comprising the
2236
    base type and any pointer or reference qualifiers, while the second
2489
    base type and any pointer or reference qualifiers, while the second
2237
    prints the tail of the type, comprising any array or function qualifiers.
2490
    prints the tail of the type, comprising any array or function qualifiers.
2238
*/
2491
*/
2239
 
2492
 
2240
int print_type
2493
int
2241
    PROTO_N ( ( t, bf, sp ) )
-
 
2242
    PROTO_T ( TYPE t X BUFFER *bf X int sp )
2494
print_type(TYPE t, BUFFER *bf, int sp)
2243
{
2495
{
2244
    sp = print_head ( t, print_c_style, bf, sp ) ;
2496
	sp = print_head(t, print_c_style, bf, sp);
2245
    sp = print_tail ( t, bf, sp ) ;
2497
	sp = print_tail(t, bf, sp);
2246
    return ( sp ) ;
2498
	return (sp);
2247
}
2499
}
2248
 
2500
 
2249
 
2501
 
2250
/*
2502
/*
2251
    PRINT A LIST OF TYPES
2503
    PRINT A LIST OF TYPES
2252
 
2504
 
2253
    This routine prints the list of types p, enclosed in brackets, to the
2505
    This routine prints the list of types p, enclosed in brackets, to the
2254
    buffer bf.
2506
    buffer bf.
2255
*/
2507
*/
2256
 
2508
 
2257
int print_type_list
2509
int
2258
    PROTO_N ( ( p, bf, sp ) )
-
 
2259
    PROTO_T ( LIST ( TYPE ) p X BUFFER *bf X int sp )
2510
print_type_list(LIST(TYPE)p, BUFFER *bf, int sp)
2260
{
2511
{
2261
    if ( sp ) bfputc ( bf, ' ' ) ;
2512
	if (sp)bfputc(bf, ' ');
2262
    bfputc ( bf, '(' ) ;
2513
	bfputc(bf, '(');
2263
    if ( !IS_NULL_list ( p ) ) {
2514
	if (!IS_NULL_list(p)) {
2264
	for ( ; ; ) {
2515
		for (;;) {
2265
	    TYPE t = DEREF_type ( HEAD_list ( p ) ) ;
2516
			TYPE t = DEREF_type(HEAD_list(p));
2266
	    IGNORE print_type ( t, bf, 1 ) ;
2517
			IGNORE print_type(t, bf, 1);
2267
	    p = TAIL_list ( p ) ;
2518
			p = TAIL_list(p);
2268
	    if ( IS_NULL_list ( p ) ) break ;
2519
			if (IS_NULL_list(p)) {
-
 
2520
				break;
-
 
2521
			}
2269
	    bfputc ( bf, ',' ) ;
2522
			bfputc(bf, ',');
-
 
2523
		}
-
 
2524
		bfputc(bf, ' ');
2270
	}
2525
	}
2271
	bfputc ( bf, ' ' ) ;
2526
	bfputc(bf, ')');
2272
    }
-
 
2273
    bfputc ( bf, ')' ) ;
-
 
2274
    return ( 1 ) ;
2527
	return (1);
2275
}
2528
}
2276
 
2529
 
2277
 
2530
 
2278
/*
2531
/*
2279
    OFFSET PRINTING
2532
    OFFSET PRINTING
2280
 
2533
 
2281
    This routine prints an offset to the buffer bf.
2534
    This routine prints an offset to the buffer bf.
2282
*/
2535
*/
2283
 
2536
 
2284
int print_offset
2537
int
2285
    PROTO_N ( ( off, bf, sp ) )
-
 
2286
    PROTO_T ( OFFSET off X BUFFER *bf X int sp )
2538
print_offset(OFFSET off, BUFFER *bf, int sp)
2287
{
2539
{
2288
    if ( !IS_NULL_off ( off ) ) {
2540
	if (!IS_NULL_off(off)) {
2289
	switch ( TAG_off ( off ) ) {
2541
		switch (TAG_off(off)) {
2290
	    case off_base_tag : {
2542
		case off_base_tag: {
2291
		GRAPH gr = DEREF_graph ( off_base_graph ( off ) ) ;
2543
			GRAPH gr = DEREF_graph(off_base_graph(off));
2292
		sp = print_graph ( gr, 0, bf, sp ) ;
-
 
2293
		break ;
-
 
2294
	    }
-
 
2295
	    case off_deriv_tag : {
-
 
2296
		GRAPH gr = DEREF_graph ( off_deriv_graph ( off ) ) ;
-
 
2297
		sp = print_graph ( gr, 0, bf, sp ) ;
2544
			sp = print_graph(gr, 0, bf, sp);
2298
		break ;
-
 
2299
	    }
-
 
2300
	    case off_member_tag : {
-
 
2301
		IDENTIFIER id = DEREF_id ( off_member_id ( off ) ) ;
-
 
2302
		sp = print_id_short ( id, qual_none, bf, sp ) ;
-
 
2303
		break ;
-
 
2304
	    }
-
 
2305
	    case off_token_tag : {
-
 
2306
		IDENTIFIER id = DEREF_id ( off_token_tok ( off ) ) ;
-
 
2307
		LIST ( TOKEN ) args = DEREF_list ( off_token_args ( off ) ) ;
-
 
2308
		sp = print_token ( id, qual_none, args, bf, sp ) ;
-
 
2309
		break ;
2545
			break;
2310
	    }
-
 
2311
	    default : {
-
 
2312
		static unsigned long off_no = 0 ;
-
 
2313
#ifdef RUNTIME
-
 
2314
		if ( debugging ) {
-
 
2315
		    /* Debug offset printing routine */
-
 
2316
		    sp = print_offset_aux ( off, bf, sp ) ;
-
 
2317
		    break ;
-
 
2318
		}
2546
		}
-
 
2547
		case off_deriv_tag: {
-
 
2548
			GRAPH gr = DEREF_graph(off_deriv_graph(off));
-
 
2549
			sp = print_graph(gr, 0, bf, sp);
-
 
2550
			break;
-
 
2551
		}
-
 
2552
		case off_member_tag: {
-
 
2553
			IDENTIFIER id = DEREF_id(off_member_id(off));
-
 
2554
			sp = print_id_short(id, qual_none, bf, sp);
-
 
2555
			break;
-
 
2556
		}
-
 
2557
		case off_token_tag: {
-
 
2558
			IDENTIFIER id = DEREF_id(off_token_tok(off));
-
 
2559
			LIST(TOKEN)args = DEREF_list(off_token_args(off));
-
 
2560
			sp = print_token(id, qual_none, args, bf, sp);
-
 
2561
			break;
-
 
2562
		}
-
 
2563
		default: {
-
 
2564
			static unsigned long off_no = 0;
-
 
2565
#ifdef RUNTIME
-
 
2566
			if (debugging) {
-
 
2567
				/* Debug offset printing routine */
-
 
2568
				sp = print_offset_aux(off, bf, sp);
-
 
2569
				break;
-
 
2570
			}
2319
#endif
2571
#endif
-
 
2572
			if (sp) {
2320
		if ( sp ) bfputc ( bf, ' ' ) ;
2573
				bfputc(bf, ' ');
-
 
2574
			}
2321
		bfprintf ( bf, "<off%lu>", ++off_no ) ;
2575
			bfprintf(bf, "<off%lu>", ++off_no);
2322
		sp = 1 ;
2576
			sp = 1;
2323
		break ;
2577
			break;
2324
	    }
2578
		}
2325
	}
2579
		}
2326
    }
2580
	}
2327
    return ( sp ) ;
2581
	return (sp);
2328
}
2582
}
2329
 
2583
 
2330
 
2584
 
2331
/*
2585
/*
2332
    FIND A LINE WITHIN THE CURRENT FILE BUFFER
2586
    FIND A LINE WITHIN THE CURRENT FILE BUFFER
2333
 
2587
 
2334
    This routine checks whether the start of line n lies within the
2588
    This routine checks whether the start of line n lies within the
2335
    current file buffer.  If so it returns a pointer to the start of
2589
    current file buffer.  If so it returns a pointer to the start of
2336
    the line.  m gives the line number of the current position.
2590
    the line.  m gives the line number of the current position.
2337
*/
2591
*/
2338
 
2592
 
2339
static string find_buffer_line
2593
static string
2340
    PROTO_N ( ( n, m ) )
-
 
2341
    PROTO_T ( unsigned long n X unsigned long m )
2594
find_buffer_line(unsigned long n, unsigned long m)
2342
{
2595
{
2343
    string p = input_posn - 1 ;
2596
	string p = input_posn - 1;
2344
    if ( n <= m ) {
2597
	if (n <= m) {
2345
	/* Scan backwards */
2598
		/* Scan backwards */
2346
	while ( p >= input_start ) {
2599
		while (p >= input_start) {
2347
	    character c = *( p-- ) ;
2600
			character c = *(p--);
2348
	    if ( c == char_newline ) {
2601
			if (c == char_newline) {
-
 
2602
				if (n == m) {
2349
		if ( n == m ) return ( p + 2 ) ;
2603
					return (p + 2);
-
 
2604
				}
2350
		m-- ;
2605
				m--;
-
 
2606
			}
-
 
2607
		}
-
 
2608
		if (m == 1) {
-
 
2609
			/* Allow falling off start */
-
 
2610
			return (input_start);
-
 
2611
		}
-
 
2612
	} else {
-
 
2613
		while (p < input_end) {
-
 
2614
			character c = *(p++);
-
 
2615
			if (c == char_newline) {
-
 
2616
				if (n == m) {
-
 
2617
					return (p);
2351
	    }
2618
				}
-
 
2619
				m++;
-
 
2620
			}
-
 
2621
		}
-
 
2622
		if (p == input_eof) {
-
 
2623
			/* Allow falling off end */
-
 
2624
			return (p);
-
 
2625
		}
2352
	}
2626
	}
2353
	if ( m == 1 ) {
-
 
2354
	    /* Allow falling off start */
-
 
2355
	    return ( input_start ) ;
-
 
2356
	}
-
 
2357
    } else {
-
 
2358
	while ( p < input_end ) {
-
 
2359
	    character c = *( p++ ) ;
-
 
2360
	    if ( c == char_newline ) {
-
 
2361
		if ( n == m ) return ( p ) ;
-
 
2362
		m++ ;
-
 
2363
	    }
-
 
2364
	}
-
 
2365
	if ( p == input_eof ) {
-
 
2366
	    /* Allow falling off end */
-
 
2367
	    return ( p ) ;
-
 
2368
	}
-
 
2369
    }
-
 
2370
    return ( NULL ) ;
2627
	return (NULL);
2371
}
2628
}
2372
 
2629
 
2373
 
2630
 
2374
/*
2631
/*
2375
    FIND A LOCATION WITHIN THE CURRENT FILE BUFFER
2632
    FIND A LOCATION WITHIN THE CURRENT FILE BUFFER
2376
 
2633
 
2377
    This routine checks whether the n lines following line ln of file fn
2634
    This routine checks whether the n lines following line ln of file fn
2378
    lie within the input buffer.  If so it returns the position of the
2635
    lie within the input buffer.  If so it returns the position of the
2379
    first line within the buffer.
2636
    first line within the buffer.
2380
*/
2637
*/
2381
 
2638
 
2382
static string find_buffer_loc
2639
static string
2383
    PROTO_N ( ( fn, ln, n ) )
-
 
2384
    PROTO_T ( string fn X unsigned long ln X unsigned long n )
2640
find_buffer_loc(string fn, unsigned long ln, unsigned long n)
2385
{
2641
{
2386
    if ( input_start && !bad_crt_loc ) {
2642
	if (input_start && !bad_crt_loc) {
2387
	PTR ( POSITION ) pm = crt_loc.posn ;
2643
		PTR(POSITION)pm = crt_loc.posn;
2388
	if ( !IS_NULL_ptr ( pm ) ) {
2644
		if (!IS_NULL_ptr(pm)) {
2389
	    string fm = DEREF_string ( posn_input ( pm ) ) ;
2645
			string fm = DEREF_string(posn_input(pm));
2390
	    if ( ustreq ( fn, fm ) ) {
2646
			if (ustreq(fn, fm)) {
2391
		unsigned long om = DEREF_ulong ( posn_offset ( pm ) ) ;
2647
				unsigned long om = DEREF_ulong(posn_offset(pm));
2392
		unsigned long lm = crt_loc.line - om ;
2648
				unsigned long lm = crt_loc.line - om;
2393
		string p = find_buffer_line ( ln, lm ) ;
2649
				string p = find_buffer_line(ln, lm);
2394
		if ( p ) {
2650
				if (p) {
2395
		    string q = find_buffer_line ( ln + n, lm ) ;
2651
					string q = find_buffer_line(ln + n, lm);
-
 
2652
					if (q) {
2396
		    if ( q ) return ( p ) ;
2653
						return (p);
-
 
2654
					}
-
 
2655
				}
-
 
2656
			}
2397
		}
2657
		}
2398
	    }
-
 
2399
	}
2658
	}
2400
    }
-
 
2401
    return ( NULL ) ;
2659
	return (NULL);
2402
}
2660
}
2403
 
2661
 
2404
 
2662
 
2405
/*
2663
/*
2406
    PRINT SOURCE LINES
2664
    PRINT SOURCE LINES
Line 2408... Line 2666...
2408
    This routine prints a number of lines from the input buffer centred
2666
    This routine prints a number of lines from the input buffer centred
2409
    on the location loc to the file f.  If loc does not correspond to a
2667
    on the location loc to the file f.  If loc does not correspond to a
2410
    position within the current buffer then no text is output.
2668
    position within the current buffer then no text is output.
2411
*/
2669
*/
2412
 
2670
 
2413
void print_source
2671
void
2414
    PROTO_N ( ( loc, lines, full, pre, f ) )
-
 
2415
    PROTO_T ( LOCATION *loc X int lines X int full X CONST char *pre X FILE *f )
2672
print_source(LOCATION *loc, int lines, int full, CONST char *pre, FILE *f)
2416
{
2673
{
2417
    PTR ( POSITION ) pn = loc->posn ;
2674
	PTR(POSITION)pn = loc->posn;
2418
    if ( lines > 0 && !IS_NULL_ptr ( pn ) ) {
2675
	if (lines > 0 && !IS_NULL_ptr(pn)) {
2419
	string p ;
2676
		string p;
2420
	int nl = 0 ;
2677
		int nl = 0;
2421
	FILE *g = NULL ;
2678
		FILE *g = NULL;
2422
	CONST char *mark = "!!!!" ;
2679
		CONST char *mark = "!!!!";
2423
	unsigned long n = ( unsigned long ) lines ;
2680
		unsigned long n = (unsigned long)lines;
2424
	unsigned long b = n / 2 ;
2681
		unsigned long b = n / 2;
2425
	string fn = DEREF_string ( posn_input ( pn ) ) ;
2682
		string fn = DEREF_string(posn_input(pn));
2426
	unsigned long on = DEREF_ulong ( posn_offset ( pn ) ) ;
2683
		unsigned long on = DEREF_ulong(posn_offset(pn));
2427
	unsigned long ln = loc->line - on ;
2684
		unsigned long ln = loc->line - on;
2428
	unsigned long cn = loc->column ;
2685
		unsigned long cn = loc->column;
2429
	unsigned long lc = ln ;
2686
		unsigned long lc = ln;
2430
	unsigned long cc = 0 ;
2687
		unsigned long cc = 0;
2431
	if ( ln <= b ) {
2688
		if (ln <= b) {
2432
	    ln = 1 ;
2689
			ln = 1;
2433
	} else {
2690
		} else {
2434
	    ln -= b ;
2691
			ln -= b;
-
 
2692
		}
-
 
2693
 
-
 
2694
		/* Find start of source */
-
 
2695
		p = find_buffer_loc(fn, ln, n);
-
 
2696
		if (p == NULL) {
-
 
2697
			g = fopen(strlit(fn), "r");
-
 
2698
			if (g) {
-
 
2699
				/* Skip to correct line in file */
-
 
2700
				unsigned long lm = 1;
-
 
2701
				while (lm != ln) {
-
 
2702
					int c = fgetc(g);
-
 
2703
					if (c == EOF) {
-
 
2704
						fclose_v(g);
-
 
2705
						g = NULL;
-
 
2706
						break;
-
 
2707
					}
-
 
2708
					if (c == '\n')lm++;
-
 
2709
				}
-
 
2710
			}
2435
	}
2711
		}
2436
 
2712
 
2437
	/* Find start of source */
2713
		/* Print source */
-
 
2714
		if (full) {
-
 
2715
			if (pre) {
-
 
2716
				fputs_v(pre, f);
-
 
2717
			}
-
 
2718
			fn = DEREF_string(posn_file(pn));
2438
	p = find_buffer_loc ( fn, ln, n ) ;
2719
			fprintf_v(f, "FILE: %s\n", strlit(fn));
-
 
2720
		}
-
 
2721
		while (n) {
-
 
2722
			int c;
2439
	if ( p == NULL ) {
2723
			if (nl == 0) {
-
 
2724
				if (pre) {
-
 
2725
					fputs_v(pre, f);
-
 
2726
				}
-
 
2727
				if (full) {
-
 
2728
					fprintf_v(f, "%lu:\t", ln + on);
-
 
2729
				}
-
 
2730
				nl = 1;
-
 
2731
			}
2440
	    g = fopen ( strlit ( fn ), "r" ) ;
2732
			if (ln == lc && cn == cc) {
-
 
2733
				fputs_v(mark, f);
-
 
2734
				mark = NULL;
-
 
2735
			}
2441
	    if ( g ) {
2736
			if (p) {
2442
		/* Skip to correct line in file */
2737
				/* Read from buffer */
2443
		unsigned long lm = 1 ;
2738
				if (p >= input_end) {
-
 
2739
					break;
-
 
2740
				}
-
 
2741
				c = (int)*(p++);
2444
		while ( lm != ln ) {
2742
			} else if (g) {
-
 
2743
				/* Read from file */
2445
		    int c = fgetc ( g ) ;
2744
				c = fgetc(g);
2446
		    if ( c == EOF ) {
2745
				if (c == EOF) {
-
 
2746
					break;
-
 
2747
				}
-
 
2748
			} else {
-
 
2749
				break;
-
 
2750
			}
-
 
2751
			if (c == char_newline) {
-
 
2752
				/* Newline characters */
-
 
2753
				if (ln == lc && mark) {
2447
			fclose_v ( g ) ;
2754
					fputs_v(mark, f);
2448
			g = NULL ;
2755
					mark = NULL;
-
 
2756
				}
-
 
2757
				if (--n == 0) {
2449
			break ;
2758
					break;
2450
		    }
2759
				}
-
 
2760
				nl = 0;
-
 
2761
				ln++;
-
 
2762
				cc = 0;
-
 
2763
			} else {
-
 
2764
				cc++;
-
 
2765
			}
-
 
2766
			fputc_v((int)c, f);
-
 
2767
		}
-
 
2768
		if (mark) {
-
 
2769
			fputs_v(mark, f);
-
 
2770
			nl = 1;
-
 
2771
		}
-
 
2772
		if (nl) {
2451
		    if ( c == '\n' ) lm++ ;
2773
			fputc_v('\n', f);
-
 
2774
		}
-
 
2775
		if (g) {
-
 
2776
			fclose_v(g);
2452
		}
2777
		}
2453
	    }
-
 
2454
	}
-
 
2455
 
-
 
2456
	/* Print source */
-
 
2457
	if ( full ) {
-
 
2458
	    if ( pre ) fputs_v ( pre, f ) ;
-
 
2459
	    fn = DEREF_string ( posn_file ( pn ) ) ;
-
 
2460
	    fprintf_v ( f, "FILE: %s\n", strlit ( fn ) ) ;
-
 
2461
	}
-
 
2462
	while ( n ) {
-
 
2463
	    int c ;
-
 
2464
	    if ( nl == 0 ) {
-
 
2465
		if ( pre ) fputs_v ( pre, f ) ;
-
 
2466
		if ( full ) fprintf_v ( f, "%lu:\t", ln + on ) ;
-
 
2467
		nl = 1 ;
-
 
2468
	    }
-
 
2469
	    if ( ln == lc && cn == cc ) {
-
 
2470
		fputs_v ( mark, f ) ;
-
 
2471
		mark = NULL ;
-
 
2472
	    }
-
 
2473
	    if ( p ) {
-
 
2474
		/* Read from buffer */
-
 
2475
		if ( p >= input_end ) break ;
-
 
2476
		c = ( int ) *( p++ ) ;
-
 
2477
	    } else if ( g ) {
-
 
2478
		/* Read from file */
-
 
2479
		c = fgetc ( g ) ;
-
 
2480
		if ( c == EOF ) break ;
-
 
2481
	    } else {
-
 
2482
		break ;
-
 
2483
	    }
-
 
2484
	    if ( c == char_newline ) {
-
 
2485
		/* Newline characters */
-
 
2486
		if ( ln == lc && mark ) {
-
 
2487
		    fputs_v ( mark, f ) ;
-
 
2488
		    mark = NULL ;
-
 
2489
		}
-
 
2490
		if ( --n == 0 ) break ;
-
 
2491
		nl = 0 ;
-
 
2492
		ln++ ;
-
 
2493
		cc = 0 ;
-
 
2494
	    } else {
-
 
2495
		cc++ ;
-
 
2496
	    }
-
 
2497
	    fputc_v ( ( int ) c, f ) ;
-
 
2498
	}
-
 
2499
	if ( mark ) {
-
 
2500
	    fputs_v ( mark, f ) ;
-
 
2501
	    nl = 1 ;
-
 
2502
	}
2778
	}
2503
	if ( nl ) fputc_v ( '\n', f ) ;
-
 
2504
	if ( g ) fclose_v ( g ) ;
-
 
2505
    }
-
 
2506
    return ;
2779
	return;
2507
}
2780
}