]> gcc.gnu.org Git - gcc.git/blame - gcc/cp/error.c
dwarf2out.c (die_struct): Remove die_attr_last and die_child_last.
[gcc.git] / gcc / cp / error.c
CommitLineData
8d08fdba
MS
1/* Call-backs for C++ error reporting.
2 This code is non-reentrant.
4995028c 3 Copyright (C) 1993, 94-97, 1998, 1999 Free Software Foundation, Inc.
8d08fdba
MS
4
5 This file is part of GNU CC.
6
7GNU CC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GNU CC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU CC; see the file COPYING. If not, write to
e9fa0c7c
RK
19the Free Software Foundation, 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
8d08fdba
MS
21
22#include "config.h"
8d052bc7 23#include "system.h"
8d08fdba
MS
24#include "tree.h"
25#include "cp-tree.h"
26#include "obstack.h"
54f92bfb 27#include "toplev.h"
8d08fdba 28
e1def31b 29typedef const char *cp_printer ();
8d08fdba 30
8d08fdba
MS
31#define obstack_chunk_alloc xmalloc
32#define obstack_chunk_free free
33
34/* Obstack where we build text strings for overloading, etc. */
35static struct obstack scratch_obstack;
36static char *scratch_firstobj;
37
38# define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
39# define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
40# define OB_PUTC2(C1,C2) \
41 (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
42# define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
43# define OB_PUTID(ID) \
44 (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \
45 IDENTIFIER_LENGTH (ID)))
46# define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
47# define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
71e89f27 48# define OB_PUTI(CST) do { sprintf (digit_buffer, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT)(CST)); \
8d08fdba
MS
49 OB_PUTCP (digit_buffer); } while (0)
50
0aafb128 51# define OB_END_TEMPLATE_ID() \
9e93bc9d 52 (((obstack_next_free (&scratch_obstack) != obstack_base (&scratch_obstack) \
0aafb128 53 && obstack_next_free (&scratch_obstack)[-1] == '>') \
9e93bc9d 54 ? OB_PUTC (' ') : (void)0), OB_PUTC ('>'))
0aafb128 55
8d08fdba
MS
56# define NEXT_CODE(t) (TREE_CODE (TREE_TYPE (t)))
57
49c249e1
JM
58enum pad { none, before, after };
59
9e93bc9d
NS
60static const char *args_to_string PROTO((tree, int));
61static const char *assop_to_string PROTO((enum tree_code, int));
62static const char *code_to_string PROTO((enum tree_code, int));
63static const char *cv_to_string PROTO((tree, int));
64static const char *decl_to_string PROTO((tree, int));
65static const char *expr_to_string PROTO((tree, int));
66static const char *fndecl_to_string PROTO((tree, int));
67static const char *language_to_string PROTO((enum languages, int));
68static const char *op_to_string PROTO((enum tree_code, int));
69static const char *parm_to_string PROTO((int, int));
70static const char *type_to_string PROTO((tree, int));
71
72static void dump_type PROTO((tree, enum tree_string_flags));
73static void dump_simple_decl PROTO((tree, tree, enum tree_string_flags));
74static void dump_decl PROTO((tree, enum tree_string_flags));
75static void dump_template_decl PROTO((tree, enum tree_string_flags));
76static void dump_function_decl PROTO((tree, enum tree_string_flags));
77static void dump_expr PROTO((tree, enum tree_string_flags));
78static void dump_unary_op PROTO((const char *, tree, enum tree_string_flags));
79static void dump_binary_op PROTO((const char *, tree, enum tree_string_flags));
80static void dump_aggr_type PROTO((tree, enum tree_string_flags));
81static enum pad dump_type_prefix PROTO((tree, enum tree_string_flags));
82static void dump_type_suffix PROTO((tree, enum tree_string_flags));
83static void dump_function_name PROTO((tree, enum tree_string_flags));
84static void dump_expr_list PROTO((tree, enum tree_string_flags));
49c249e1 85static void dump_global_iord PROTO((tree));
9e93bc9d 86static enum pad dump_qualifiers PROTO((tree, enum pad));
b2bb2710 87static void dump_char PROTO((int));
9e93bc9d
NS
88static void dump_parameters PROTO((tree, enum tree_string_flags));
89static void dump_exception_spec PROTO((tree, enum tree_string_flags));
9c0758dd 90static const char *aggr_variety PROTO((tree));
49c249e1 91static tree ident_fndecl PROTO((tree));
612c671a
GDR
92static void dump_template_argument PROTO((tree, enum tree_string_flags));
93static void dump_template_argument_list PROTO((tree, enum tree_string_flags));
94static void dump_template_parameter PROTO((tree, enum tree_string_flags));
b5ac18ea 95static void dump_template_bindings PROTO((tree, tree));
9e93bc9d
NS
96static void dump_scope PROTO((tree, enum tree_string_flags));
97static void dump_template_parms PROTO((tree, int, enum tree_string_flags));
98
99#define A args_to_string
100#define C code_to_string
101#define D decl_to_string
102#define E expr_to_string
103#define F fndecl_to_string
104#define L language_to_string
105#define O op_to_string
106#define P parm_to_string
107#define Q assop_to_string
108#define T type_to_string
109#define V cv_to_string
110
111#define o (cp_printer *) 0
112cp_printer * cp_printers[256] =
113{
114/*0 1 2 3 4 5 6 7 8 9 A B C D E F */
115 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x00 */
116 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x10 */
117 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x20 */
118 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x30 */
119 o, A, o, C, D, E, F, o, o, o, o, o, L, o, o, O, /* 0x40 */
120 P, Q, o, o, T, o, V, o, o, o, o, o, o, o, o, o, /* 0x50 */
121 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x60 */
122 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x70 */
123};
124#undef C
125#undef D
126#undef E
127#undef F
128#undef L
129#undef O
130#undef P
131#undef Q
132#undef T
133#undef V
134#undef o
8d08fdba
MS
135
136void
137init_error ()
138{
139 gcc_obstack_init (&scratch_obstack);
140 scratch_firstobj = (char *)obstack_alloc (&scratch_obstack, 0);
141}
142
9e93bc9d 143/* Dump a scope, if deemed necessary. */
bbcec105 144
9e93bc9d
NS
145static void
146dump_scope (scope, flags)
bbcec105 147 tree scope;
9e93bc9d 148 enum tree_string_flags flags;
bbcec105 149{
9e93bc9d
NS
150 if (scope == NULL_TREE)
151 return;
152
153 if (TREE_CODE (scope) == NAMESPACE_DECL)
154 {
155 if (scope != global_namespace)
156 {
157 dump_decl (scope, (flags & (TS_PEDANTIC_NAME | TS_FUNC_SCOPE | TS_CHASE_TYPEDEFS))
158 | TS_FUNC_NORETURN | TS_DECL_TYPE);
159 OB_PUTS ("::");
160 }
161 else if (flags & TS_PEDANTIC_NAME)
162 OB_PUTS ("::");
163 }
164 else if (AGGREGATE_TYPE_P (scope))
165 {
166 dump_type (scope, (flags & (TS_PEDANTIC_NAME | TS_FUNC_SCOPE | TS_CHASE_TYPEDEFS))
167 | TS_FUNC_NORETURN | TS_DECL_TYPE);
168 OB_PUTS ("::");
169 }
170 else if ((flags & (TS_PEDANTIC_NAME | TS_FUNC_SCOPE))
171 && TREE_CODE (scope) == FUNCTION_DECL)
172 {
173 dump_function_decl (scope, (flags & (TS_PEDANTIC_NAME | TS_FUNC_SCOPE | TS_CHASE_TYPEDEFS))
174 | TS_FUNC_NORETURN | TS_DECL_TYPE);
175 OB_PUTS ("::");
176 }
bbcec105
JM
177}
178
9e93bc9d
NS
179/* Dump type qualifiers, providing padding as requested. Return an
180 indication of whether we dumped something. */
181
182static enum pad
91063b51 183dump_qualifiers (t, p)
8d08fdba
MS
184 tree t;
185 enum pad p;
186{
9e93bc9d
NS
187 static const int masks[] =
188 {TYPE_QUAL_CONST, TYPE_QUAL_VOLATILE, TYPE_QUAL_RESTRICT};
189 static const char *const names[] =
190 {"const", "volatile", "__restrict"};
191 int ix;
192 int quals = TYPE_QUALS (t);
193 int do_after = p == after;
194
195 if (quals)
8d08fdba 196 {
9e93bc9d
NS
197 for (ix = 0; ix != 3; ix++)
198 if (masks[ix] & quals)
199 {
200 if (p == before)
201 OB_PUTC (' ');
202 p = before;
203 OB_PUTCP (names[ix]);
204 }
205 if (do_after)
206 OB_PUTC (' ');
8d08fdba 207 }
9e93bc9d
NS
208 else
209 p = none;
210 return p;
8d08fdba
MS
211}
212
213/* This must be large enough to hold any printed integer or floating-point
214 value. */
215static char digit_buffer[128];
216
612c671a 217/* Dump the template ARGument under control of FLAGS. */
5f77d6cc
GDR
218
219static void
612c671a
GDR
220dump_template_argument (arg, flags)
221 tree arg;
9e93bc9d 222 enum tree_string_flags flags;
5f77d6cc 223{
612c671a
GDR
224 if (TREE_CODE_CLASS (TREE_CODE (arg)) == 't'
225 || TREE_CODE (arg) == TEMPLATE_DECL)
226 dump_type (arg, flags & ~TS_AGGR_TAGS);
5f77d6cc 227 else
612c671a 228 dump_expr (arg, (flags | TS_EXPR_PARENS) & ~TS_AGGR_TAGS);
5f77d6cc
GDR
229}
230
612c671a
GDR
231/* Dump a template-argument-list ARGS (always a TREE_VEC) under control
232 of FLAGS. */
233
234static void
235dump_template_argument_list (args, flags)
236 tree args;
237 enum tree_string_flags flags;
238{
239 int n = TREE_VEC_LENGTH (args);
240 int need_comma = 0;
241 int i;
242
243 for (i = 0; i< n; ++i)
244 {
245 if (need_comma)
246 OB_PUTS (", ");
247 dump_template_argument (TREE_VEC_ELT (args, i), flags);
248 need_comma = 1;
249 }
250}
251
252/* Dump a template parameter PARM (a TREE_LIST) under control of FLAGS. */
253
254static void
255dump_template_parameter (parm, flags)
256 tree parm;
257 enum tree_string_flags flags;
258{
259 tree p = TREE_VALUE (parm);
260 tree a = TREE_PURPOSE (parm);
261
262 if (TREE_CODE (p) == TYPE_DECL)
263 {
264 if (flags & TS_DECL_TYPE)
265 {
266 OB_PUTS ("class");
267 if (DECL_NAME (p))
268 {
269 OB_PUTC (' ');
270 OB_PUTID (DECL_NAME (p));
271 }
272 }
273 else if (DECL_NAME (p))
274 OB_PUTID (DECL_NAME (p));
275 else
276 OB_PUTS ("{template default argument error}");
277 }
278 else
279 dump_decl (p, flags | TS_DECL_TYPE);
280
281 if ((flags & TS_PARM_DEFAULTS) && a != NULL_TREE)
282 {
283 OB_PUTS (" = ");
284 if (TREE_CODE (a) == TYPE_DECL || TREE_CODE (a) == TEMPLATE_DECL)
285 dump_type (a, flags & ~TS_CHASE_TYPEDEFS);
286 else
287 dump_expr (a, flags | TS_EXPR_PARENS);
288 }
289}
290
291/* Dump, under control of FLAGS, a template-parameter-list binding.
292 PARMS is a TREE_LIST of TREE_VEC of TREE_LIST and ARGS is a
293 TREE_VEC. */
294
295static void
b5ac18ea 296dump_template_bindings (parms, args)
612c671a 297 tree parms, args;
612c671a 298{
612c671a
GDR
299 int need_comma = 0;
300
301 while (parms)
302 {
303 tree p = TREE_VALUE (parms);
b5ac18ea
MM
304 int lvl = TMPL_PARMS_DEPTH (parms);
305 int arg_idx = 0;
612c671a
GDR
306 int i;
307
308 for (i = 0; i < TREE_VEC_LENGTH (p); ++i)
b5ac18ea
MM
309 {
310 tree arg = TMPL_ARG (args, lvl, arg_idx);
311
312 if (need_comma)
313 OB_PUTS (", ");
314 dump_template_parameter (TREE_VEC_ELT (p, i), TS_PLAIN);
315 OB_PUTS (" = ");
316 if (arg)
317 dump_template_argument (arg, TS_PLAIN);
318 else
319 OB_PUTS ("{missing}");
612c671a 320
b5ac18ea
MM
321 ++arg_idx;
322 need_comma = 1;
323 }
612c671a
GDR
324
325 parms = TREE_CHAIN (parms);
326 }
327}
328
9e93bc9d
NS
329/* Dump into the obstack a human-readable equivalent of TYPE. FLAGS
330 controls the format. */
e92cc029 331
8d08fdba 332static void
9e93bc9d 333dump_type (t, flags)
8d08fdba 334 tree t;
9e93bc9d 335 enum tree_string_flags flags;
8d08fdba
MS
336{
337 if (t == NULL_TREE)
338 return;
339
340 if (TYPE_PTRMEMFUNC_P (t))
341 goto offset_type;
342
343 switch (TREE_CODE (t))
344 {
8d08fdba 345 case UNKNOWN_TYPE:
51c184be 346 OB_PUTS ("{unknown type}");
8d08fdba
MS
347 break;
348
dcd08efc
JM
349 case TREE_LIST:
350 /* A list of function parms. */
9e93bc9d 351 dump_parameters (t, flags);
dcd08efc
JM
352 break;
353
8d08fdba
MS
354 case IDENTIFIER_NODE:
355 OB_PUTID (t);
356 break;
357
358 case TREE_VEC:
9e93bc9d 359 dump_type (BINFO_TYPE (t), flags);
8d08fdba
MS
360 break;
361
362 case RECORD_TYPE:
363 case UNION_TYPE:
364 case ENUMERAL_TYPE:
9e93bc9d 365 dump_aggr_type (t, flags);
8d08fdba
MS
366 break;
367
368 case TYPE_DECL:
9e93bc9d
NS
369 if (flags & TS_CHASE_TYPEDEFS)
370 {
371 dump_type (DECL_ORIGINAL_TYPE (t)
372 ? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t), flags);
373 break;
374 }
375 /* else fallthrough */
376
67c2a928 377 case TEMPLATE_DECL:
009425e1 378 case NAMESPACE_DECL:
9e93bc9d 379 dump_decl (t, flags & ~TS_DECL_TYPE);
8d08fdba 380 break;
9e93bc9d 381
37c46b43
MS
382 case COMPLEX_TYPE:
383 OB_PUTS ("complex ");
9e93bc9d 384 dump_type (TREE_TYPE (t), flags);
37c46b43
MS
385 break;
386
8d08fdba
MS
387 case INTEGER_TYPE:
388 if (!TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)) && TREE_UNSIGNED (t))
389 OB_PUTS ("unsigned ");
390 else if (TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)) && !TREE_UNSIGNED (t))
391 OB_PUTS ("signed ");
392
393 /* fall through. */
394 case REAL_TYPE:
395 case VOID_TYPE:
2986ae00 396 case BOOLEAN_TYPE:
3df095e2
MM
397 {
398 tree type;
91063b51 399 dump_qualifiers (t, after);
9e93bc9d 400 type = flags & TS_CHASE_TYPEDEFS ? TYPE_MAIN_VARIANT (t) : t;
3df095e2
MM
401 if (TYPE_NAME (type) && TYPE_IDENTIFIER (type))
402 OB_PUTID (TYPE_IDENTIFIER (type));
403 else
404 /* Types like intQI_type_node and friends have no names.
405 These don't come up in user error messages, but it's nice
406 to be able to print them from the debugger. */
407 OB_PUTS ("{anonymous}");
408 }
8d08fdba
MS
409 break;
410
73b0fce8 411 case TEMPLATE_TEMPLATE_PARM:
7ddedda4 412 if (!TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t))
73b0fce8
KL
413 {
414 /* For parameters inside template signature. */
415 if (TYPE_IDENTIFIER (t))
416 OB_PUTID (TYPE_IDENTIFIER (t));
417 else
612c671a 418 OB_PUTS ("{anonymous template template parameter}");
73b0fce8
KL
419 }
420 else
421 {
7ddedda4 422 tree args = TYPE_TI_ARGS (t);
73b0fce8
KL
423 OB_PUTID (TYPE_IDENTIFIER (t));
424 OB_PUTC ('<');
612c671a 425 dump_template_argument_list (args, flags);
0aafb128 426 OB_END_TEMPLATE_ID ();
73b0fce8
KL
427 }
428 break;
429
8d08fdba 430 case TEMPLATE_TYPE_PARM:
91063b51 431 dump_qualifiers (t, after);
ec255269
MS
432 if (TYPE_IDENTIFIER (t))
433 OB_PUTID (TYPE_IDENTIFIER (t));
434 else
612c671a 435 OB_PUTS ("{anonymous template type parameter}");
8d08fdba
MS
436 break;
437
8d08fdba
MS
438 /* This is not always necessary for pointers and such, but doing this
439 reduces code size. */
440 case ARRAY_TYPE:
441 case POINTER_TYPE:
442 case REFERENCE_TYPE:
443 case OFFSET_TYPE:
444 offset_type:
445 case FUNCTION_TYPE:
446 case METHOD_TYPE:
9e93bc9d
NS
447 {
448 dump_type_prefix (t, flags);
449 dump_type_suffix (t, flags);
8d08fdba 450 break;
9e93bc9d 451 }
5566b478
MS
452 case TYPENAME_TYPE:
453 OB_PUTS ("typename ");
9e93bc9d 454 dump_type (TYPE_CONTEXT (t), flags);
5566b478 455 OB_PUTS ("::");
9e93bc9d 456 dump_decl (TYPENAME_TYPE_FULLNAME (t), flags);
5566b478
MS
457 break;
458
b894fc05
JM
459 case TYPEOF_TYPE:
460 OB_PUTS ("__typeof (");
9e93bc9d 461 dump_expr (TYPE_FIELDS (t), flags & ~TS_EXPR_PARENS);
b894fc05
JM
462 OB_PUTC (')');
463 break;
464
8d08fdba 465 default:
51c184be
MS
466 sorry ("`%s' not supported by dump_type",
467 tree_code_name[(int) TREE_CODE (t)]);
9e93bc9d
NS
468 /* Fall through to error. */
469
470 case ERROR_MARK:
612c671a 471 OB_PUTS ("{type error}");
9e93bc9d 472 break;
8d08fdba
MS
473 }
474}
475
9e93bc9d
NS
476/* Return the name of the supplied aggregate, or enumeral type. */
477
9c0758dd 478static const char *
51c184be 479aggr_variety (t)
8d08fdba 480 tree t;
8d08fdba 481{
8d08fdba 482 if (TREE_CODE (t) == ENUMERAL_TYPE)
51c184be 483 return "enum";
8d08fdba 484 else if (TREE_CODE (t) == UNION_TYPE)
51c184be 485 return "union";
8d08fdba 486 else if (TYPE_LANG_SPECIFIC (t) && CLASSTYPE_DECLARED_CLASS (t))
51c184be 487 return "class";
8d08fdba 488 else
51c184be
MS
489 return "struct";
490}
491
9e93bc9d
NS
492/* Print out a class declaration T under the control of FLAGS,
493 in the form `class foo'. */
e92cc029 494
51c184be 495static void
9e93bc9d 496dump_aggr_type (t, flags)
51c184be 497 tree t;
9e93bc9d 498 enum tree_string_flags flags;
51c184be
MS
499{
500 tree name;
9c0758dd 501 const char *variety = aggr_variety (t);
9e93bc9d
NS
502 int typdef = 0;
503 int tmplate = 0;
8d08fdba 504
91063b51 505 dump_qualifiers (t, after);
8d08fdba 506
9e93bc9d 507 if (flags & TS_AGGR_TAGS)
8d08fdba
MS
508 {
509 OB_PUTCP (variety);
510 OB_PUTC (' ');
511 }
512
9e93bc9d
NS
513 if (flags & TS_CHASE_TYPEDEFS)
514 t = TYPE_MAIN_VARIANT (t);
8d08fdba 515
9e93bc9d
NS
516 name = TYPE_NAME (t);
517
518 if (name)
8d08fdba 519 {
9e93bc9d
NS
520 typdef = !DECL_ARTIFICIAL (name);
521 tmplate = !typdef && TREE_CODE (t) != ENUMERAL_TYPE
522 && TYPE_LANG_SPECIFIC (t) && CLASSTYPE_TEMPLATE_INFO (t)
523 && (CLASSTYPE_TEMPLATE_SPECIALIZATION (t)
524 || TREE_CODE (CLASSTYPE_TI_TEMPLATE (t)) != TEMPLATE_DECL
525 || DECL_TEMPLATE_SPECIALIZATION (CLASSTYPE_TI_TEMPLATE (t))
526 || PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t)));
527 dump_scope (CP_DECL_CONTEXT (name), flags | TS_FUNC_SCOPE);
528 if (tmplate)
529 {
530 /* Because the template names are mangled, we have to locate
531 the most general template, and use that name. */
532 tree tpl = CLASSTYPE_TI_TEMPLATE (t);
533
534 while (DECL_TEMPLATE_INFO (tpl))
535 tpl = DECL_TI_TEMPLATE (tpl);
536 name = tpl;
537 }
538 name = DECL_NAME (name);
8d08fdba
MS
539 }
540
f30432d7 541 if (name == 0 || ANON_AGGRNAME_P (name))
8d08fdba 542 {
51c184be 543 OB_PUTS ("{anonymous");
9e93bc9d 544 if (!(flags & TS_AGGR_TAGS))
8d08fdba
MS
545 {
546 OB_PUTC (' ');
547 OB_PUTCP (variety);
548 }
51c184be 549 OB_PUTC ('}');
8d08fdba
MS
550 }
551 else
552 OB_PUTID (name);
9e93bc9d
NS
553 if (tmplate)
554 dump_template_parms (TYPE_TEMPLATE_INFO (t),
555 !CLASSTYPE_USE_TEMPLATE (t),
556 flags & ~TS_TEMPLATE_PREFIX);
8d08fdba
MS
557}
558
559/* Dump into the obstack the initial part of the output for a given type.
560 This is necessary when dealing with things like functions returning
561 functions. Examples:
562
563 return type of `int (* fee ())()': pointer -> function -> int. Both
564 pointer (and reference and offset) and function (and member) types must
565 deal with prefix and suffix.
566
567 Arrays must also do this for DECL nodes, like int a[], and for things like
9e93bc9d
NS
568 int *[]&.
569
570 Return indicates how you should pad an object name after this. I.e. you
571 want to pad non-*, non-& cores, but not pad * or & types. */
8d08fdba 572
9e93bc9d
NS
573static enum pad
574dump_type_prefix (t, flags)
8d08fdba 575 tree t;
9e93bc9d 576 enum tree_string_flags flags;
8d08fdba 577{
9e93bc9d
NS
578 enum pad padding = before;
579
8d08fdba
MS
580 if (TYPE_PTRMEMFUNC_P (t))
581 {
582 t = TYPE_PTRMEMFUNC_FN_TYPE (t);
583 goto offset_type;
584 }
585
586 switch (TREE_CODE (t))
587 {
588 case POINTER_TYPE:
91063b51 589 case REFERENCE_TYPE:
8d08fdba
MS
590 {
591 tree sub = TREE_TYPE (t);
592
9e93bc9d 593 padding = dump_type_prefix (sub, flags);
8d08fdba
MS
594 /* A tree for a member pointer looks like pointer to offset,
595 so let the OFFSET_TYPE case handle it. */
91063b51 596 if (!TYPE_PTRMEM_P (t))
8d08fdba 597 {
9e93bc9d
NS
598 if (padding != none)
599 OB_PUTC (' ');
600 if (TREE_CODE (sub) == ARRAY_TYPE)
601 OB_PUTC ('(');
602 OB_PUTC ("&*"[TREE_CODE (t) == POINTER_TYPE]);
603 padding = dump_qualifiers (t, none);
8d08fdba
MS
604 }
605 }
8d08fdba
MS
606 break;
607
608 case OFFSET_TYPE:
609 offset_type:
9e93bc9d 610 padding = dump_type_prefix (TREE_TYPE (t), flags);
51c184be
MS
611 if (TREE_CODE (t) == OFFSET_TYPE) /* pmfs deal with this in d_t_p */
612 {
9e93bc9d
NS
613 if (padding != none)
614 OB_PUTC (' ');
615 dump_type (TYPE_OFFSET_BASETYPE (t), flags);
616 OB_PUTS ("::");
51c184be 617 }
8d08fdba 618 OB_PUTC ('*');
9e93bc9d 619 padding = dump_qualifiers (t, none);
8d08fdba
MS
620 break;
621
622 /* Can only be reached through function pointer -- this would not be
623 correct if FUNCTION_DECLs used it. */
624 case FUNCTION_TYPE:
9e93bc9d
NS
625 padding = dump_type_prefix (TREE_TYPE (t), flags);
626 if (padding != none)
627 OB_PUTC (' ');
628 OB_PUTC ('(');
629 padding = none;
8d08fdba
MS
630 break;
631
632 case METHOD_TYPE:
9e93bc9d
NS
633 padding = dump_type_prefix (TREE_TYPE (t), flags);
634 if (padding != none)
635 OB_PUTC (' ');
636 OB_PUTC ('(');
637 padding = none;
638 dump_aggr_type (TYPE_METHOD_BASETYPE (t), flags);
639 OB_PUTS ("::");
8d08fdba
MS
640 break;
641
642 case ARRAY_TYPE:
9e93bc9d 643 padding = dump_type_prefix (TREE_TYPE (t), flags);
8d08fdba
MS
644 break;
645
646 case ENUMERAL_TYPE:
8d08fdba
MS
647 case IDENTIFIER_NODE:
648 case INTEGER_TYPE:
2986ae00 649 case BOOLEAN_TYPE:
8d08fdba
MS
650 case REAL_TYPE:
651 case RECORD_TYPE:
652 case TEMPLATE_TYPE_PARM:
73b0fce8 653 case TEMPLATE_TEMPLATE_PARM:
8d08fdba
MS
654 case TREE_LIST:
655 case TYPE_DECL:
656 case TREE_VEC:
8d08fdba
MS
657 case UNION_TYPE:
658 case UNKNOWN_TYPE:
659 case VOID_TYPE:
5566b478 660 case TYPENAME_TYPE:
37c46b43 661 case COMPLEX_TYPE:
9e93bc9d
NS
662 dump_type (t, flags);
663 padding = before;
8d08fdba
MS
664 break;
665
666 default:
51c184be
MS
667 sorry ("`%s' not supported by dump_type_prefix",
668 tree_code_name[(int) TREE_CODE (t)]);
9e93bc9d
NS
669
670 case ERROR_MARK:
671 OB_PUTS ("{typeprefixerror}");
672 break;
8d08fdba 673 }
9e93bc9d 674 return padding;
8d08fdba
MS
675}
676
9e93bc9d
NS
677/* Dump the suffix of type T, under control of FLAGS. This is the part
678 which appears after the identifier (or function parms). */
679
8d08fdba 680static void
9e93bc9d 681dump_type_suffix (t, flags)
8d08fdba 682 tree t;
9e93bc9d 683 enum tree_string_flags flags;
8d08fdba
MS
684{
685 if (TYPE_PTRMEMFUNC_P (t))
686 t = TYPE_PTRMEMFUNC_FN_TYPE (t);
687
688 switch (TREE_CODE (t))
689 {
690 case POINTER_TYPE:
691 case REFERENCE_TYPE:
692 case OFFSET_TYPE:
39211cd5
MS
693 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
694 OB_PUTC (')');
9e93bc9d 695 dump_type_suffix (TREE_TYPE (t), flags);
8d08fdba
MS
696 break;
697
698 /* Can only be reached through function pointer */
699 case FUNCTION_TYPE:
700 case METHOD_TYPE:
701 {
702 tree arg;
4995028c 703 OB_PUTC (')');
8d08fdba
MS
704 arg = TYPE_ARG_TYPES (t);
705 if (TREE_CODE (t) == METHOD_TYPE)
706 arg = TREE_CHAIN (arg);
707
4995028c
NS
708 /* Function pointers don't have default args. Not in standard C++,
709 anyway; they may in g++, but we'll just pretend otherwise. */
9e93bc9d 710 dump_parameters (arg, flags & ~TS_PARM_DEFAULTS);
4995028c 711
8d08fdba 712 if (TREE_CODE (t) == METHOD_TYPE)
91063b51 713 dump_qualifiers
8d08fdba 714 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t))), before);
9e93bc9d
NS
715 dump_type_suffix (TREE_TYPE (t), flags);
716 dump_exception_spec (TYPE_RAISES_EXCEPTIONS (t), flags);
8d08fdba
MS
717 break;
718 }
719
720 case ARRAY_TYPE:
721 OB_PUTC ('[');
722 if (TYPE_DOMAIN (t))
5156628f
MS
723 {
724 if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (t))) == INTEGER_CST)
725 OB_PUTI (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (t))) + 1);
726 else if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (t))) == MINUS_EXPR)
9e93bc9d
NS
727 dump_expr (TREE_OPERAND (TYPE_MAX_VALUE (TYPE_DOMAIN (t)), 0),
728 flags & ~TS_EXPR_PARENS);
5156628f
MS
729 else
730 dump_expr (fold (build_binary_op
731 (PLUS_EXPR, TYPE_MAX_VALUE (TYPE_DOMAIN (t)),
9e93bc9d
NS
732 integer_one_node)),
733 flags & ~TS_EXPR_PARENS);
5156628f 734 }
8d08fdba 735 OB_PUTC (']');
9e93bc9d 736 dump_type_suffix (TREE_TYPE (t), flags);
8d08fdba
MS
737 break;
738
739 case ENUMERAL_TYPE:
8d08fdba
MS
740 case IDENTIFIER_NODE:
741 case INTEGER_TYPE:
2986ae00 742 case BOOLEAN_TYPE:
8d08fdba
MS
743 case REAL_TYPE:
744 case RECORD_TYPE:
745 case TEMPLATE_TYPE_PARM:
73b0fce8 746 case TEMPLATE_TEMPLATE_PARM:
8d08fdba
MS
747 case TREE_LIST:
748 case TYPE_DECL:
749 case TREE_VEC:
8d08fdba
MS
750 case UNION_TYPE:
751 case UNKNOWN_TYPE:
752 case VOID_TYPE:
5566b478 753 case TYPENAME_TYPE:
37c46b43 754 case COMPLEX_TYPE:
8d08fdba
MS
755 break;
756
757 default:
51c184be
MS
758 sorry ("`%s' not supported by dump_type_suffix",
759 tree_code_name[(int) TREE_CODE (t)]);
9e93bc9d
NS
760
761 case ERROR_MARK:
762 /* Don't mark it here, we should have already done in
763 dump_type_prefix. */
764 break;
8d08fdba
MS
765 }
766}
767
768/* Return a function declaration which corresponds to the IDENTIFIER_NODE
769 argument. */
e92cc029 770
49c249e1 771static tree
8d08fdba
MS
772ident_fndecl (t)
773 tree t;
774{
700f8a87 775 tree n = lookup_name (t, 0);
8d08fdba 776
f30432d7
MS
777 if (n == NULL_TREE)
778 return NULL_TREE;
779
8d08fdba
MS
780 if (TREE_CODE (n) == FUNCTION_DECL)
781 return n;
782 else if (TREE_CODE (n) == TREE_LIST
783 && TREE_CODE (TREE_VALUE (n)) == FUNCTION_DECL)
784 return TREE_VALUE (n);
8926095f
MS
785
786 my_friendly_abort (66);
787 return NULL_TREE;
8d08fdba
MS
788}
789
790#ifndef NO_DOLLAR_IN_LABEL
791# define GLOBAL_THING "_GLOBAL_$"
792#else
793# ifndef NO_DOT_IN_LABEL
794# define GLOBAL_THING "_GLOBAL_."
795# else
796# define GLOBAL_THING "_GLOBAL__"
797# endif
798#endif
799
800#define GLOBAL_IORD_P(NODE) \
fc378698 801 ! strncmp (IDENTIFIER_POINTER(NODE), GLOBAL_THING, sizeof (GLOBAL_THING) - 1)
8d08fdba 802
49c249e1 803static void
8d08fdba
MS
804dump_global_iord (t)
805 tree t;
806{
9c0758dd 807 const char *name = IDENTIFIER_POINTER (t);
8d08fdba
MS
808
809 OB_PUTS ("(static ");
810 if (name [sizeof (GLOBAL_THING) - 1] == 'I')
811 OB_PUTS ("initializers");
812 else if (name [sizeof (GLOBAL_THING) - 1] == 'D')
813 OB_PUTS ("destructors");
814 else
815 my_friendly_abort (352);
816
817 OB_PUTS (" for ");
818 OB_PUTCP (input_filename);
819 OB_PUTC (')');
820}
821
07389efe 822static void
9e93bc9d 823dump_simple_decl (t, type, flags)
07389efe
MM
824 tree t;
825 tree type;
9e93bc9d 826 enum tree_string_flags flags;
07389efe 827{
9e93bc9d 828 if (flags & TS_DECL_TYPE)
07389efe 829 {
9e93bc9d
NS
830 if (dump_type_prefix (type, flags) != none)
831 OB_PUTC (' ');
07389efe 832 }
9e93bc9d
NS
833 if (!DECL_INITIAL (t) || TREE_CODE (DECL_INITIAL (t)) != TEMPLATE_PARM_INDEX)
834 dump_scope (CP_DECL_CONTEXT (t), flags);
07389efe 835 if (DECL_NAME (t))
9e93bc9d 836 dump_decl (DECL_NAME (t), flags);
07389efe 837 else
612c671a 838 OB_PUTS ("{anonymous}");
9e93bc9d
NS
839 if (flags & TS_DECL_TYPE)
840 dump_type_suffix (type, flags);
07389efe
MM
841}
842
9e93bc9d
NS
843/* Dump a human readable string for the decl T under control of FLAGS. */
844
8d08fdba 845static void
9e93bc9d 846dump_decl (t, flags)
8d08fdba 847 tree t;
9e93bc9d 848 enum tree_string_flags flags;
8d08fdba
MS
849{
850 if (t == NULL_TREE)
851 return;
852
853 switch (TREE_CODE (t))
854 {
7177d104 855 case TYPE_DECL:
8d2733ca
MS
856 {
857 /* Don't say 'typedef class A' */
fc378698 858 if (DECL_ARTIFICIAL (t))
8d2733ca 859 {
9e93bc9d
NS
860 if ((flags & TS_DECL_TYPE)
861 && TREE_CODE (TREE_TYPE (t)) == TEMPLATE_TYPE_PARM)
a9936d39
MM
862 /* Say `class T' not just `T'. */
863 OB_PUTS ("class ");
864
9e93bc9d 865 dump_type (TREE_TYPE (t), flags);
8d2733ca
MS
866 break;
867 }
868 }
9e93bc9d 869 if (flags & TS_DECORATE)
8d2733ca 870 OB_PUTS ("typedef ");
07389efe 871 dump_simple_decl (t, DECL_ORIGINAL_TYPE (t)
9e93bc9d
NS
872 ? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t),
873 flags);
7177d104
MS
874 break;
875
8d08fdba 876 case VAR_DECL:
b7484fbe 877 if (DECL_NAME (t) && VTABLE_NAME_P (DECL_NAME (t)))
8d08fdba
MS
878 {
879 OB_PUTS ("vtable for ");
52bf7d5d 880 if (TYPE_P (DECL_CONTEXT (t)))
9e93bc9d 881 dump_type (DECL_CONTEXT (t), flags);
52bf7d5d
MM
882 else
883 /* This case can arise with -fno-vtable-thunks. See
884 expand_upcast_fixups. It's not clear what to print
885 here. */
886 OB_PUTS ("{unknown type}");
8d08fdba
MS
887 break;
888 }
889 /* else fall through */
890 case FIELD_DECL:
891 case PARM_DECL:
9e93bc9d 892 dump_simple_decl (t, TREE_TYPE (t), flags);
8d08fdba
MS
893 break;
894
a9aedbc2 895 case NAMESPACE_DECL:
9e93bc9d 896 dump_scope (CP_DECL_CONTEXT (t), flags);
0c8feefe 897 if (DECL_NAME (t) == anonymous_namespace_name)
612c671a 898 OB_PUTS ("{unnamed}");
0c8feefe
MM
899 else
900 OB_PUTID (DECL_NAME (t));
a9aedbc2
MS
901 break;
902
3e3f722c 903 case SCOPE_REF:
9e93bc9d 904 dump_decl (TREE_OPERAND (t, 0), flags & ~TS_DECL_TYPE);
3e3f722c 905 OB_PUTS ("::");
9e93bc9d 906 dump_decl (TREE_OPERAND (t, 1), flags);
3e3f722c
ML
907 break;
908
8d08fdba 909 case ARRAY_REF:
9e93bc9d 910 dump_decl (TREE_OPERAND (t, 0), flags);
8d08fdba 911 OB_PUTC ('[');
9e93bc9d 912 dump_decl (TREE_OPERAND (t, 1), flags);
8d08fdba
MS
913 OB_PUTC (']');
914 break;
915
9e93bc9d 916 /* So that we can do dump_decl on an aggr type. */
8d08fdba
MS
917 case RECORD_TYPE:
918 case UNION_TYPE:
919 case ENUMERAL_TYPE:
9e93bc9d 920 dump_type (t, flags);
8d08fdba
MS
921 break;
922
8d08fdba
MS
923 case TYPE_EXPR:
924 my_friendly_abort (69);
925 break;
926
927 /* These special cases are duplicated here so that other functions
e92cc029 928 can feed identifiers to cp_error and get them demangled properly. */
8d08fdba 929 case IDENTIFIER_NODE:
f30432d7
MS
930 { tree f;
931 if (DESTRUCTOR_NAME_P (t)
932 && (f = ident_fndecl (t))
933 && DECL_LANGUAGE (f) == lang_cplusplus)
934 {
935 OB_PUTC ('~');
9e93bc9d 936 dump_decl (DECL_NAME (f), flags);
f30432d7
MS
937 }
938 else if (IDENTIFIER_TYPENAME_P (t))
939 {
940 OB_PUTS ("operator ");
941 /* Not exactly IDENTIFIER_TYPE_VALUE. */
9e93bc9d 942 dump_type (TREE_TYPE (t), flags);
f30432d7
MS
943 break;
944 }
945 else if (IDENTIFIER_OPNAME_P (t))
946 {
9c0758dd 947 const char *name_string = operator_name_string (t);
f30432d7
MS
948 OB_PUTS ("operator ");
949 OB_PUTCP (name_string);
950 }
951 else
952 OB_PUTID (t);
953 }
8d08fdba
MS
954 break;
955
8f032717
MM
956 case OVERLOAD:
957 t = OVL_CURRENT (t);
958 /* Fall through. */
959
8d08fdba
MS
960 case FUNCTION_DECL:
961 if (GLOBAL_IORD_P (DECL_ASSEMBLER_NAME (t)))
962 dump_global_iord (DECL_ASSEMBLER_NAME (t));
da20811c
JM
963 else if (! DECL_LANG_SPECIFIC (t))
964 OB_PUTS ("{internal}");
9e93bc9d
NS
965 else if (flags & TS_PEDANTIC_NAME)
966 dump_function_decl (t, flags | TS_FUNC_NORETURN | TS_DECL_TYPE);
8d08fdba 967 else
9e93bc9d 968 dump_function_decl (t, flags);
8d08fdba
MS
969 break;
970
971 case TEMPLATE_DECL:
9e93bc9d
NS
972 if (flags & TS_PEDANTIC_NAME)
973 dump_template_decl (t, flags | TS_FUNC_NORETURN | TS_DECL_TYPE);
974 else
975 dump_template_decl (t, flags);
8d08fdba
MS
976 break;
977
74cd8397
JM
978 case TEMPLATE_ID_EXPR:
979 {
980 tree args;
aa36c081
JM
981 tree name = TREE_OPERAND (t, 0);
982 if (is_overloaded_fn (name))
983 name = DECL_NAME (get_first_fn (name));
9e93bc9d 984 dump_decl (name, flags);
74cd8397
JM
985 OB_PUTC ('<');
986 for (args = TREE_OPERAND (t, 1); args; args = TREE_CHAIN (args))
987 {
612c671a 988 dump_template_argument (TREE_VALUE (args), flags);
74cd8397 989 if (TREE_CHAIN (args))
9e93bc9d 990 OB_PUTS (", ");
74cd8397 991 }
0aafb128 992 OB_END_TEMPLATE_ID ();
74cd8397
JM
993 }
994 break;
995
0fb9f1c3 996 case LOOKUP_EXPR:
9e93bc9d 997 dump_decl (TREE_OPERAND (t, 0), flags);
0fb9f1c3
JM
998 break;
999
8d08fdba
MS
1000 case LABEL_DECL:
1001 OB_PUTID (DECL_NAME (t));
1002 break;
1003
1004 case CONST_DECL:
6467930b 1005 if ((TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == ENUMERAL_TYPE)
03555413 1006 || (DECL_INITIAL (t) &&
f84b4be9 1007 TREE_CODE (DECL_INITIAL (t)) == TEMPLATE_PARM_INDEX))
9e93bc9d 1008 dump_simple_decl (t, TREE_TYPE (t), flags);
224c649b 1009 else if (DECL_NAME (t))
9e93bc9d 1010 dump_decl (DECL_NAME (t), flags);
03555413 1011 else if (DECL_INITIAL (t))
9e93bc9d 1012 dump_expr (DECL_INITIAL (t), flags | TS_EXPR_PARENS);
03555413
MM
1013 else
1014 OB_PUTS ("enumerator");
8d08fdba
MS
1015 break;
1016
cffa8729
MS
1017 case USING_DECL:
1018 OB_PUTS ("using ");
9e93bc9d 1019 dump_type (DECL_INITIAL (t), flags);
cffa8729
MS
1020 OB_PUTS ("::");
1021 OB_PUTID (DECL_NAME (t));
1022 break;
1023
8d08fdba 1024 default:
51c184be
MS
1025 sorry ("`%s' not supported by dump_decl",
1026 tree_code_name[(int) TREE_CODE (t)]);
9e93bc9d
NS
1027 /* Fallthrough to error. */
1028
1029 case ERROR_MARK:
612c671a 1030 OB_PUTS ("{declaration error}");
9e93bc9d
NS
1031 break;
1032 }
1033}
1034
1035/* Dump a template declaration T under control of FLAGS. This means the
1036 'template <...> leaders plus the 'class X' or 'void fn(...)' part. */
1037
1038static void
1039dump_template_decl (t, flags)
1040 tree t;
1041 enum tree_string_flags flags;
1042{
b5ac18ea
MM
1043 tree orig_parms = DECL_TEMPLATE_PARMS (t);
1044 tree parms;
9e93bc9d
NS
1045 int i;
1046
1047 if (flags & TS_TEMPLATE_PREFIX)
1048 {
b5ac18ea
MM
1049 for (parms = orig_parms = nreverse (orig_parms);
1050 parms;
1051 parms = TREE_CHAIN (parms))
9e93bc9d 1052 {
b5ac18ea
MM
1053 tree inner_parms = INNERMOST_TEMPLATE_PARMS (parms);
1054 int len = TREE_VEC_LENGTH (inner_parms);
9e93bc9d
NS
1055
1056 OB_PUTS ("template <");
1057 for (i = 0; i < len; i++)
1058 {
9e93bc9d
NS
1059 if (i)
1060 OB_PUTS (", ");
b5ac18ea 1061 dump_template_parameter (TREE_VEC_ELT (inner_parms, i), flags);
9e93bc9d
NS
1062 }
1063 OB_END_TEMPLATE_ID ();
1064 OB_PUTC (' ');
1065 }
b5ac18ea 1066 nreverse(orig_parms);
9e93bc9d 1067 /* If we've shown the template<args> prefix, we'd better show the
b5ac18ea 1068 decl's type too. */
9e93bc9d
NS
1069 flags |= TS_DECL_TYPE;
1070 }
1071 if (TREE_CODE (DECL_TEMPLATE_RESULT (t)) == TYPE_DECL)
1072 dump_type (TREE_TYPE (t),
1073 ((flags & ~TS_AGGR_TAGS) | TS_TEMPLATE_PLAIN
1074 | (flags & TS_DECL_TYPE ? TS_AGGR_TAGS : 0)));
1075 else if (TREE_CODE (DECL_TEMPLATE_RESULT (t)) == VAR_DECL)
1076 dump_decl (DECL_TEMPLATE_RESULT (t), flags | TS_TEMPLATE_PLAIN);
1077 else if (TREE_TYPE (t) == NULL_TREE)
1078 my_friendly_abort (353);
1079 else
1080 switch (NEXT_CODE (t))
1081 {
1082 case METHOD_TYPE:
1083 case FUNCTION_TYPE:
1084 dump_function_decl (t, flags | TS_TEMPLATE_PLAIN);
1085 break;
1086 default:
1087 /* This case can occur with some illegal code. */
1088 dump_type (TREE_TYPE (t),
1089 (flags & ~TS_AGGR_TAGS) | TS_TEMPLATE_PLAIN
1090 | (flags & TS_DECL_TYPE ? TS_AGGR_TAGS : 0));
8d08fdba
MS
1091 }
1092}
1093
4995028c 1094/* Pretty print a function decl. There are several ways we want to print a
9e93bc9d 1095 function declaration. The TS_FUNC bits in FLAGS tells us how to behave.
4995028c
NS
1096 As cp_error can only apply the '#' flag once to give 0 and 1 for V, there
1097 is %D which doesn't print the throw specs, and %F which does. */
8d08fdba
MS
1098
1099static void
9e93bc9d 1100dump_function_decl (t, flags)
8d08fdba 1101 tree t;
9e93bc9d 1102 enum tree_string_flags flags;
8d08fdba 1103{
98c1c668
JM
1104 tree fntype;
1105 tree parmtypes;
8d08fdba 1106 tree cname = NULL_TREE;
612c671a
GDR
1107 tree template_args = NULL_TREE;
1108 tree template_parms = NULL_TREE;
9e93bc9d 1109 int show_return = !(flags & TS_FUNC_NORETURN) && (flags & TS_DECL_TYPE);
8d08fdba 1110
98c1c668
JM
1111 if (TREE_CODE (t) == TEMPLATE_DECL)
1112 t = DECL_TEMPLATE_RESULT (t);
1113
612c671a 1114 /* Pretty print template instantiations only. */
b5ac18ea 1115 if (DECL_TEMPLATE_INSTANTIATION (t))
612c671a
GDR
1116 {
1117 template_args = DECL_TI_ARGS (t);
1118 t = most_general_template (t);
b5ac18ea
MM
1119 if (TREE_CODE (t) == TEMPLATE_DECL)
1120 template_parms = DECL_TEMPLATE_PARMS (t);
612c671a
GDR
1121 }
1122
98c1c668
JM
1123 fntype = TREE_TYPE (t);
1124 parmtypes = TYPE_ARG_TYPES (fntype);
1125
8d08fdba 1126 /* Friends have DECL_CLASS_CONTEXT set, but not DECL_CONTEXT. */
2642b9bf 1127 if (DECL_CLASS_SCOPE_P (t))
8d08fdba
MS
1128 cname = DECL_CLASS_CONTEXT (t);
1129 /* this is for partially instantiated template methods */
1130 else if (TREE_CODE (fntype) == METHOD_TYPE)
1131 cname = TREE_TYPE (TREE_VALUE (parmtypes));
1132
9e93bc9d
NS
1133 if (!(flags & TS_DECORATE))
1134 /* OK */;
1135 else if (DECL_STATIC_FUNCTION_P (t))
1136 OB_PUTS ("static ");
1137 else if (TYPE_VIRTUAL_P (t))
1138 OB_PUTS ("virtual ");
1139
1140 /* Print the return type? */
1141 if (show_return)
1142 show_return = !DECL_CONV_FN_P (t) && !DECL_CONSTRUCTOR_P (t)
1143 && !DECL_DESTRUCTOR_P (t);
1144 if (show_return)
8d08fdba 1145 {
9e93bc9d
NS
1146 if (dump_type_prefix (TREE_TYPE (fntype), flags) != none)
1147 OB_PUTC (' ');
8d08fdba
MS
1148 }
1149
61cd552e 1150 /* Print the function name. */
8d08fdba
MS
1151 if (cname)
1152 {
9e93bc9d
NS
1153 dump_type (cname, flags);
1154 OB_PUTS ("::");
2642b9bf 1155 }
9e93bc9d
NS
1156 else
1157 dump_scope (CP_DECL_CONTEXT (t), flags);
8d08fdba 1158
9e93bc9d 1159 dump_function_name (t, flags);
8d08fdba 1160
9e93bc9d 1161 if (!(flags & TS_DECL_TYPE))
61cd552e 1162 return;
9e93bc9d
NS
1163 if (TREE_CODE (fntype) == METHOD_TYPE && parmtypes)
1164 /* Skip "this" parameter. */
1165 parmtypes = TREE_CHAIN (parmtypes);
1166
1167 if (DECL_DESTRUCTOR_P (t) || DECL_CONSTRUCTOR_FOR_VBASE_P (t))
1168 /* Skip past "in_charge" identifier. */
1169 parmtypes = TREE_CHAIN (parmtypes);
1170
1171 dump_parameters (parmtypes, flags);
4995028c 1172
9e93bc9d
NS
1173 if (show_return)
1174 dump_type_suffix (TREE_TYPE (fntype), flags);
8d08fdba
MS
1175
1176 if (TREE_CODE (fntype) == METHOD_TYPE)
6eabb241
MM
1177 dump_qualifiers (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype))),
1178 before);
4995028c 1179
9e93bc9d
NS
1180 if (flags & TS_FUNC_THROW)
1181 dump_exception_spec (TYPE_RAISES_EXCEPTIONS (fntype), flags);
612c671a
GDR
1182
1183 /* If T is a template instantiation, dump the parameter binding. */
1184 if (template_parms != NULL_TREE && template_args != NULL_TREE)
1185 {
1186 OB_PUTS (" [with ");
b5ac18ea 1187 dump_template_bindings (template_parms, template_args);
612c671a
GDR
1188 OB_PUTC (']');
1189 }
4995028c
NS
1190}
1191
9e93bc9d
NS
1192/* Print a parameter list. If this is for a member function, the
1193 member object ptr (and any other hidden args) should have
1194 already been removed. */
4995028c
NS
1195
1196static void
9e93bc9d 1197dump_parameters (parmtypes, flags)
4995028c 1198 tree parmtypes;
9e93bc9d 1199 enum tree_string_flags flags;
4995028c
NS
1200{
1201 int first;
9e93bc9d 1202 OB_PUTS (" (");
4995028c
NS
1203
1204 for (first = 1; parmtypes != void_list_node;
1205 parmtypes = TREE_CHAIN (parmtypes))
1206 {
1207 if (!first)
9e93bc9d 1208 OB_PUTS (", ");
4995028c
NS
1209 first = 0;
1210 if (!parmtypes)
1211 {
1212 OB_PUTS ("...");
1213 break;
1214 }
9e93bc9d 1215 dump_type (TREE_VALUE (parmtypes), flags);
4995028c 1216
9e93bc9d 1217 if ((flags & TS_PARM_DEFAULTS) && TREE_PURPOSE (parmtypes))
4995028c
NS
1218 {
1219 OB_PUTS (" = ");
9e93bc9d 1220 dump_expr (TREE_PURPOSE (parmtypes), flags | TS_EXPR_PARENS);
4995028c
NS
1221 }
1222 }
1223
1224 OB_PUTC (')');
1225}
1226
1227/* Print an exception specification. T is the exception specification. */
1228
1229static void
9e93bc9d 1230dump_exception_spec (t, flags)
4995028c 1231 tree t;
9e93bc9d 1232 enum tree_string_flags flags;
4995028c
NS
1233{
1234 if (t)
1235 {
1236 OB_PUTS (" throw (");
1237 if (TREE_VALUE (t) != NULL_TREE)
1238 while (1)
1239 {
9e93bc9d 1240 dump_type (TREE_VALUE (t), flags);
4995028c
NS
1241 t = TREE_CHAIN (t);
1242 if (!t)
1243 break;
9e93bc9d 1244 OB_PUTS (", ");
4995028c
NS
1245 }
1246 OB_PUTC (')');
1247 }
8d08fdba
MS
1248}
1249
1250/* Handle the function name for a FUNCTION_DECL node, grokking operators
1251 and destructors properly. */
e92cc029 1252
8d08fdba 1253static void
9e93bc9d 1254dump_function_name (t, flags)
8d08fdba 1255 tree t;
9e93bc9d 1256 enum tree_string_flags flags;
8d08fdba
MS
1257{
1258 tree name = DECL_NAME (t);
1259
aa45967f 1260 if (DECL_DESTRUCTOR_P (t))
8d08fdba
MS
1261 {
1262 OB_PUTC ('~');
9e93bc9d 1263 dump_decl (name, TS_PLAIN);
8d08fdba 1264 }
aa45967f 1265 else if (DECL_CONV_FN_P (t))
8d08fdba
MS
1266 {
1267 /* This cannot use the hack that the operator's return
1268 type is stashed off of its name because it may be
1269 used for error reporting. In the case of conflicting
1270 declarations, both will have the same name, yet
1271 the types will be different, hence the TREE_TYPE field
1272 of the first name will be clobbered by the second. */
1273 OB_PUTS ("operator ");
9e93bc9d 1274 dump_type (TREE_TYPE (TREE_TYPE (t)), flags);
8d08fdba
MS
1275 }
1276 else if (IDENTIFIER_OPNAME_P (name))
1277 {
9c0758dd 1278 const char *name_string = operator_name_string (name);
8d08fdba
MS
1279 OB_PUTS ("operator ");
1280 OB_PUTCP (name_string);
1281 }
1282 else
9e93bc9d 1283 dump_decl (name, flags);
386b8a85 1284
9e93bc9d 1285 if (DECL_LANG_SPECIFIC (t) && DECL_TEMPLATE_INFO (t)
05fd666b 1286 && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t)
36a117a5
MM
1287 && (DECL_TEMPLATE_SPECIALIZATION (t)
1288 || TREE_CODE (DECL_TI_TEMPLATE (t)) != TEMPLATE_DECL
1289 || DECL_TEMPLATE_SPECIALIZATION (DECL_TI_TEMPLATE (t))
1290 || PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t))))
9e93bc9d
NS
1291 dump_template_parms (DECL_TEMPLATE_INFO (t), !DECL_USE_TEMPLATE (t), flags);
1292}
75650646 1293
9e93bc9d
NS
1294/* Dump the template parameters from the template info INFO under control of
1295 FLAGS. PRIMARY indicates whether this is a primary template decl, or
1296 specialization (partial or complete). For partial specializations we show
1297 the specialized parameter values. For a primary template we show no
1298 decoration. */
1299
1300static void
1301dump_template_parms (info, primary, flags)
1302 tree info;
1303 int primary;
1304 enum tree_string_flags flags;
1305{
1306 tree args = info ? TI_ARGS (info) : NULL_TREE;
1307
1308 if (primary && flags & TS_TEMPLATE_PLAIN)
1309 return;
1310 flags &= ~(TS_AGGR_TAGS | TS_TEMPLATE_PLAIN);
1311 OB_PUTC ('<');
1312
1313 /* Be careful only to print things when we have them, so as not
36a117a5 1314 to crash producing error messages. */
9e93bc9d
NS
1315 if (args && !primary)
1316 {
1317 int len = 0;
1318 int ix = 0;
1319 int need_comma = 0;
1320
1321 if (TREE_CODE (args) == TREE_VEC)
1322 {
1323 if (TREE_VEC_LENGTH (args) > 0
1324 && TREE_CODE (TREE_VEC_ELT (args, 0)) == TREE_VEC)
1325 args = TREE_VEC_ELT (args, TREE_VEC_LENGTH (args) - 1);
1326
1327 len = TREE_VEC_LENGTH (args);
1328 }
1329 else if (TREE_CODE (args) == TREE_LIST)
1330 len = -1;
1331 while (ix != len && args)
1332 {
1333 tree arg;
1334 if (len >= 0)
1335 {
1336 arg = TREE_VEC_ELT (args, ix);
1337 ix++;
1338 }
1339 else
1340 {
1341 arg = TREE_VALUE (args);
1342 args = TREE_CHAIN (args);
1343 }
1344 if (need_comma)
1345 OB_PUTS (", ");
1346
1347 if (!arg)
612c671a 1348 OB_PUTS ("{template parameter error}");
9e93bc9d 1349 else
612c671a 1350 dump_template_argument (arg, flags);
9e93bc9d
NS
1351 need_comma = 1;
1352 }
1353 }
9e93bc9d
NS
1354 else if (primary)
1355 {
1356 tree tpl = TI_TEMPLATE (info);
1357 tree parms = DECL_TEMPLATE_PARMS (tpl);
1358 int len, ix;
1359
1360 parms = TREE_CODE (parms) == TREE_LIST ? TREE_VALUE (parms) : NULL_TREE;
1361 len = parms ? TREE_VEC_LENGTH (parms) : 0;
1362
1363 for (ix = 0; ix != len; ix++)
1364 {
1365 tree parm = TREE_VALUE (TREE_VEC_ELT (parms, ix));
1366
1367 if (ix)
1368 OB_PUTS (", ");
1369
1370 dump_decl (parm, flags & ~TS_DECL_TYPE);
1371 }
386b8a85 1372 }
9e93bc9d 1373 OB_END_TEMPLATE_ID ();
8d08fdba
MS
1374}
1375
1376static void
1377dump_char (c)
b2bb2710 1378 int c;
8d08fdba
MS
1379{
1380 switch (c)
1381 {
a0a33927 1382 case TARGET_NEWLINE:
8d08fdba
MS
1383 OB_PUTS ("\\n");
1384 break;
a0a33927 1385 case TARGET_TAB:
8d08fdba
MS
1386 OB_PUTS ("\\t");
1387 break;
a0a33927 1388 case TARGET_VT:
8d08fdba
MS
1389 OB_PUTS ("\\v");
1390 break;
a0a33927 1391 case TARGET_BS:
8d08fdba
MS
1392 OB_PUTS ("\\b");
1393 break;
a0a33927 1394 case TARGET_CR:
8d08fdba
MS
1395 OB_PUTS ("\\r");
1396 break;
a0a33927 1397 case TARGET_FF:
8d08fdba
MS
1398 OB_PUTS ("\\f");
1399 break;
a0a33927 1400 case TARGET_BELL:
8d08fdba
MS
1401 OB_PUTS ("\\a");
1402 break;
1403 case '\\':
1404 OB_PUTS ("\\\\");
1405 break;
1406 case '\'':
1407 OB_PUTS ("\\'");
1408 break;
1409 case '\"':
1410 OB_PUTS ("\\\"");
1411 break;
1412 default:
faa25e97 1413 if (ISPRINT (c))
8d08fdba
MS
1414 OB_PUTC (c);
1415 else
1416 {
1417 sprintf (digit_buffer, "\\%03o", (int) c);
1418 OB_PUTCP (digit_buffer);
1419 }
1420 }
1421}
1422
1423/* Print out a list of initializers (subr of dump_expr) */
e92cc029 1424
8d08fdba 1425static void
9e93bc9d 1426dump_expr_list (l, flags)
8d08fdba 1427 tree l;
9e93bc9d 1428 enum tree_string_flags flags;
8d08fdba
MS
1429{
1430 while (l)
1431 {
9e93bc9d 1432 dump_expr (TREE_VALUE (l), flags | TS_EXPR_PARENS);
8d08fdba 1433 l = TREE_CHAIN (l);
9e93bc9d
NS
1434 if (l)
1435 OB_PUTS (", ");
8d08fdba
MS
1436 }
1437}
1438
9e93bc9d 1439/* Print out an expression E under control of FLAGS. */
e92cc029 1440
8d08fdba 1441static void
9e93bc9d 1442dump_expr (t, flags)
8d08fdba 1443 tree t;
9e93bc9d 1444 enum tree_string_flags flags;
8d08fdba
MS
1445{
1446 switch (TREE_CODE (t))
1447 {
1448 case VAR_DECL:
1449 case PARM_DECL:
1450 case FIELD_DECL:
1451 case CONST_DECL:
1452 case FUNCTION_DECL:
ec255269 1453 case TEMPLATE_DECL:
6b57ac29 1454 case NAMESPACE_DECL:
5d73aa63 1455 case OVERLOAD:
9e93bc9d 1456 dump_decl (t, flags & ~TS_DECL_TYPE);
8d08fdba
MS
1457 break;
1458
1459 case INTEGER_CST:
1460 {
1461 tree type = TREE_TYPE (t);
1462 my_friendly_assert (type != 0, 81);
1463
1464 /* If it's an enum, output its tag, rather than its value. */
1465 if (TREE_CODE (type) == ENUMERAL_TYPE)
1466 {
9c0758dd 1467 const char *p = enum_name_string (t, type);
8d08fdba
MS
1468 OB_PUTCP (p);
1469 }
b7484fbe
MS
1470 else if (type == boolean_type_node)
1471 {
72b7eeff
MS
1472 if (t == boolean_false_node
1473 || (TREE_INT_CST_LOW (t) == 0
1474 && TREE_INT_CST_HIGH (t) == 0))
b7484fbe
MS
1475 OB_PUTS ("false");
1476 else if (t == boolean_true_node)
1477 OB_PUTS ("true");
b7484fbe
MS
1478 }
1479 else if (type == char_type_node)
8d08fdba
MS
1480 {
1481 OB_PUTC ('\'');
1482 dump_char (TREE_INT_CST_LOW (t));
1483 OB_PUTC ('\'');
1484 }
1485 else if (TREE_INT_CST_HIGH (t)
1486 != (TREE_INT_CST_LOW (t) >> (HOST_BITS_PER_WIDE_INT - 1)))
1487 {
1488 tree val = t;
1489 if (TREE_INT_CST_HIGH (val) < 0)
1490 {
1491 OB_PUTC ('-');
1492 val = build_int_2 (~TREE_INT_CST_LOW (val),
1493 -TREE_INT_CST_HIGH (val));
1494 }
1495 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
1496 systems? */
1497 {
1498 static char format[10]; /* "%x%09999x\0" */
1499 if (!format[0])
1500 sprintf (format, "%%x%%0%dx", HOST_BITS_PER_INT / 4);
1501 sprintf (digit_buffer, format, TREE_INT_CST_HIGH (val),
1502 TREE_INT_CST_LOW (val));
1503 OB_PUTCP (digit_buffer);
1504 }
1505 }
1506 else
1507 OB_PUTI (TREE_INT_CST_LOW (t));
1508 }
1509 break;
1510
1511 case REAL_CST:
1512#ifndef REAL_IS_NOT_DOUBLE
1513 sprintf (digit_buffer, "%g", TREE_REAL_CST (t));
1514#else
1515 {
9c0758dd 1516 const unsigned char *p = (const unsigned char *) &TREE_REAL_CST (t);
a703fb38 1517 size_t i;
8d08fdba
MS
1518 strcpy (digit_buffer, "0x");
1519 for (i = 0; i < sizeof TREE_REAL_CST (t); i++)
1520 sprintf (digit_buffer + 2 + 2*i, "%02x", *p++);
1521 }
1522#endif
1523 OB_PUTCP (digit_buffer);
1524 break;
1525
61a127b3
MM
1526 case PTRMEM_CST:
1527 OB_PUTC ('&');
9e93bc9d 1528 dump_type (PTRMEM_CST_CLASS (t), flags);
61a127b3
MM
1529 OB_PUTS ("::");
1530 OB_PUTID (DECL_NAME (PTRMEM_CST_MEMBER (t)));
1531 break;
1532
8d08fdba
MS
1533 case STRING_CST:
1534 {
9c0758dd 1535 const char *p = TREE_STRING_POINTER (t);
8d08fdba
MS
1536 int len = TREE_STRING_LENGTH (t) - 1;
1537 int i;
1538
1539 OB_PUTC ('\"');
1540 for (i = 0; i < len; i++)
1541 dump_char (p[i]);
1542 OB_PUTC ('\"');
1543 }
1544 break;
1545
1546 case COMPOUND_EXPR:
9e93bc9d
NS
1547 OB_PUTC ('(');
1548 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
1549 OB_PUTS (", ");
1550 dump_expr (TREE_OPERAND (t, 1), flags | TS_EXPR_PARENS);
1551 OB_PUTC (')');
8d08fdba
MS
1552 break;
1553
1554 case COND_EXPR:
1555 OB_PUTC ('(');
9e93bc9d 1556 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
8d08fdba 1557 OB_PUTS (" ? ");
9e93bc9d 1558 dump_expr (TREE_OPERAND (t, 1), flags | TS_EXPR_PARENS);
8d08fdba 1559 OB_PUTS (" : ");
9e93bc9d 1560 dump_expr (TREE_OPERAND (t, 2), flags | TS_EXPR_PARENS);
8d08fdba
MS
1561 OB_PUTC (')');
1562 break;
1563
1564 case SAVE_EXPR:
1565 if (TREE_HAS_CONSTRUCTOR (t))
1566 {
1567 OB_PUTS ("new ");
9e93bc9d 1568 dump_type (TREE_TYPE (TREE_TYPE (t)), flags);
8d08fdba
MS
1569 }
1570 else
1571 {
9e93bc9d 1572 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
8d08fdba
MS
1573 }
1574 break;
1575
02531345 1576 case AGGR_INIT_EXPR:
27b8d0cd
MM
1577 {
1578 tree fn = NULL_TREE;
1579
1580 if (TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR)
1581 fn = TREE_OPERAND (TREE_OPERAND (t, 0), 0);
1582
1583 if (fn && TREE_CODE (fn) == FUNCTION_DECL)
1584 {
1585 if (DECL_CONSTRUCTOR_P (fn))
1586 OB_PUTID (TYPE_IDENTIFIER (TREE_TYPE (t)));
1587 else
1588 dump_decl (fn, 0);
1589 }
1590 else
1591 dump_expr (TREE_OPERAND (t, 0), 0);
1592 }
8d08fdba 1593 OB_PUTC ('(');
42976354 1594 if (TREE_OPERAND (t, 1))
9e93bc9d 1595 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)), flags);
8d08fdba
MS
1596 OB_PUTC (')');
1597 break;
1598
1599 case CALL_EXPR:
1600 {
1601 tree fn = TREE_OPERAND (t, 0);
1602 tree args = TREE_OPERAND (t, 1);
1603
1604 if (TREE_CODE (fn) == ADDR_EXPR)
1605 fn = TREE_OPERAND (fn, 0);
1606
6467930b 1607 if (TREE_TYPE (fn) != NULL_TREE && NEXT_CODE (fn) == METHOD_TYPE)
8d08fdba
MS
1608 {
1609 tree ob = TREE_VALUE (args);
1610 if (TREE_CODE (ob) == ADDR_EXPR)
1611 {
9e93bc9d 1612 dump_expr (TREE_OPERAND (ob, 0), flags | TS_EXPR_PARENS);
8d08fdba
MS
1613 OB_PUTC ('.');
1614 }
1615 else if (TREE_CODE (ob) != PARM_DECL
1616 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
1617 {
9e93bc9d
NS
1618 dump_expr (ob, flags | TS_EXPR_PARENS);
1619 OB_PUTS ("->");
8d08fdba
MS
1620 }
1621 args = TREE_CHAIN (args);
1622 }
9e93bc9d 1623 dump_expr (fn, flags | TS_EXPR_PARENS);
fc378698 1624 OB_PUTC ('(');
9e93bc9d 1625 dump_expr_list (args, flags);
8d08fdba
MS
1626 OB_PUTC (')');
1627 }
1628 break;
1629
285baa06
JM
1630 case NEW_EXPR:
1631 {
1632 tree type = TREE_OPERAND (t, 1);
1633 if (NEW_EXPR_USE_GLOBAL (t))
1634 OB_PUTS ("::");
1635 OB_PUTS ("new ");
1636 if (TREE_OPERAND (t, 0))
1637 {
1638 OB_PUTC ('(');
9e93bc9d 1639 dump_expr_list (TREE_OPERAND (t, 0), flags);
285baa06
JM
1640 OB_PUTS (") ");
1641 }
1642 if (TREE_CODE (type) == ARRAY_REF)
1643 type = build_cplus_array_type
1644 (TREE_OPERAND (type, 0),
1645 build_index_type (size_binop (MINUS_EXPR, TREE_OPERAND (type, 1),
1646 integer_one_node)));
9e93bc9d 1647 dump_type (type, flags);
285baa06
JM
1648 if (TREE_OPERAND (t, 2))
1649 {
1650 OB_PUTC ('(');
9e93bc9d 1651 dump_expr_list (TREE_OPERAND (t, 2), flags);
285baa06
JM
1652 OB_PUTC (')');
1653 }
1654 }
1655 break;
1656
8d08fdba
MS
1657 case TARGET_EXPR:
1658 /* Note that this only works for G++ target exprs. If somebody
1659 builds a general TARGET_EXPR, there's no way to represent that
1660 it initializes anything other that the parameter slot for the
1661 default argument. Note we may have cleared out the first
1662 operand in expand_expr, so don't go killing ourselves. */
1663 if (TREE_OPERAND (t, 1))
9e93bc9d 1664 dump_expr (TREE_OPERAND (t, 1), flags | TS_EXPR_PARENS);
8d08fdba
MS
1665 break;
1666
b3ab27f3 1667 case INIT_EXPR:
8d08fdba
MS
1668 case MODIFY_EXPR:
1669 case PLUS_EXPR:
1670 case MINUS_EXPR:
1671 case MULT_EXPR:
1672 case TRUNC_DIV_EXPR:
1673 case TRUNC_MOD_EXPR:
1674 case MIN_EXPR:
1675 case MAX_EXPR:
1676 case LSHIFT_EXPR:
1677 case RSHIFT_EXPR:
1678 case BIT_IOR_EXPR:
1679 case BIT_XOR_EXPR:
1680 case BIT_AND_EXPR:
1681 case BIT_ANDTC_EXPR:
1682 case TRUTH_ANDIF_EXPR:
1683 case TRUTH_ORIF_EXPR:
1684 case LT_EXPR:
1685 case LE_EXPR:
1686 case GT_EXPR:
1687 case GE_EXPR:
1688 case EQ_EXPR:
1689 case NE_EXPR:
2adeacc9 1690 case EXACT_DIV_EXPR:
9e93bc9d 1691 dump_binary_op (opname_tab[(int) TREE_CODE (t)], t, flags);
8d08fdba
MS
1692 break;
1693
1694 case CEIL_DIV_EXPR:
1695 case FLOOR_DIV_EXPR:
1696 case ROUND_DIV_EXPR:
9e93bc9d 1697 dump_binary_op ("/", t, flags);
8d08fdba
MS
1698 break;
1699
1700 case CEIL_MOD_EXPR:
1701 case FLOOR_MOD_EXPR:
1702 case ROUND_MOD_EXPR:
9e93bc9d 1703 dump_binary_op ("%", t, flags);
8d08fdba
MS
1704 break;
1705
1706 case COMPONENT_REF:
1707 {
1708 tree ob = TREE_OPERAND (t, 0);
1709 if (TREE_CODE (ob) == INDIRECT_REF)
1710 {
1711 ob = TREE_OPERAND (ob, 0);
1712 if (TREE_CODE (ob) != PARM_DECL
1713 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
1714 {
9e93bc9d
NS
1715 dump_expr (ob, flags | TS_EXPR_PARENS);
1716 OB_PUTS ("->");
8d08fdba
MS
1717 }
1718 }
1719 else
1720 {
9e93bc9d 1721 dump_expr (ob, flags | TS_EXPR_PARENS);
8d08fdba
MS
1722 OB_PUTC ('.');
1723 }
9e93bc9d 1724 dump_expr (TREE_OPERAND (t, 1), flags & ~TS_EXPR_PARENS);
8d08fdba
MS
1725 }
1726 break;
1727
28cbf42c 1728 case ARRAY_REF:
9e93bc9d 1729 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
28cbf42c 1730 OB_PUTC ('[');
9e93bc9d 1731 dump_expr (TREE_OPERAND (t, 1), flags | TS_EXPR_PARENS);
28cbf42c
MS
1732 OB_PUTC (']');
1733 break;
1734
8d08fdba 1735 case CONVERT_EXPR:
df39af7d
JM
1736 if (same_type_p (TREE_TYPE (t), void_type_node))
1737 {
1738 OB_PUTS ("(void)");
9e93bc9d 1739 dump_expr (TREE_OPERAND (t, 0), flags);
df39af7d
JM
1740 }
1741 else
9e93bc9d 1742 dump_unary_op ("+", t, flags);
8d08fdba
MS
1743 break;
1744
1745 case ADDR_EXPR:
1746 if (TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
1747 || TREE_CODE (TREE_OPERAND (t, 0)) == STRING_CST)
9e93bc9d 1748 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
8d08fdba 1749 else
9e93bc9d 1750 dump_unary_op ("&", t, flags);
8d08fdba
MS
1751 break;
1752
1753 case INDIRECT_REF:
1754 if (TREE_HAS_CONSTRUCTOR (t))
1755 {
1756 t = TREE_OPERAND (t, 0);
1757 my_friendly_assert (TREE_CODE (t) == CALL_EXPR, 237);
9e93bc9d 1758 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
8d08fdba 1759 OB_PUTC ('(');
9e93bc9d 1760 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)), flags);
8d08fdba
MS
1761 OB_PUTC (')');
1762 }
1763 else
1764 {
6467930b 1765 if (TREE_OPERAND (t,0) != NULL_TREE
5082a355 1766 && TREE_TYPE (TREE_OPERAND (t, 0))
6467930b 1767 && NEXT_CODE (TREE_OPERAND (t, 0)) == REFERENCE_TYPE)
9e93bc9d 1768 dump_expr (TREE_OPERAND (t, 0), flags);
8d08fdba 1769 else
9e93bc9d 1770 dump_unary_op ("*", t, flags);
8d08fdba
MS
1771 }
1772 break;
1773
1774 case NEGATE_EXPR:
1775 case BIT_NOT_EXPR:
1776 case TRUTH_NOT_EXPR:
1777 case PREDECREMENT_EXPR:
1778 case PREINCREMENT_EXPR:
9e93bc9d 1779 dump_unary_op (opname_tab [(int)TREE_CODE (t)], t, flags);
8d08fdba
MS
1780 break;
1781
1782 case POSTDECREMENT_EXPR:
1783 case POSTINCREMENT_EXPR:
1784 OB_PUTC ('(');
9e93bc9d 1785 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
8d08fdba
MS
1786 OB_PUTCP (opname_tab[(int)TREE_CODE (t)]);
1787 OB_PUTC (')');
1788 break;
1789
1790 case NON_LVALUE_EXPR:
1791 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
1792 should be another level of INDIRECT_REF so that I don't have to do
1793 this. */
6467930b 1794 if (TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == POINTER_TYPE)
8d08fdba
MS
1795 {
1796 tree next = TREE_TYPE (TREE_TYPE (t));
1797
1798 while (TREE_CODE (next) == POINTER_TYPE)
1799 next = TREE_TYPE (next);
1800
1801 if (TREE_CODE (next) == FUNCTION_TYPE)
1802 {
9e93bc9d
NS
1803 if (flags & TS_EXPR_PARENS)
1804 OB_PUTC ('(');
8d08fdba 1805 OB_PUTC ('*');
9e93bc9d
NS
1806 dump_expr (TREE_OPERAND (t, 0), flags & ~TS_EXPR_PARENS);
1807 if (flags & TS_EXPR_PARENS)
1808 OB_PUTC (')');
8d08fdba
MS
1809 break;
1810 }
1811 /* else FALLTHRU */
1812 }
9e93bc9d 1813 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
8d08fdba
MS
1814 break;
1815
1816 case NOP_EXPR:
9e93bc9d 1817 dump_expr (TREE_OPERAND (t, 0), flags);
8d08fdba
MS
1818 break;
1819
1820 case CONSTRUCTOR:
9a3b49ac
MS
1821 if (TREE_TYPE (t) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t)))
1822 {
1823 tree idx = build_component_ref (t, index_identifier, NULL_TREE, 0);
1824
1825 if (integer_all_onesp (idx))
1826 {
1827 tree pfn = PFN_FROM_PTRMEMFUNC (t);
9e93bc9d 1828 dump_unary_op ("&", pfn, flags | TS_EXPR_PARENS);
9a3b49ac
MS
1829 break;
1830 }
e08a8f45
MM
1831 else if (TREE_CODE (idx) == INTEGER_CST
1832 && tree_int_cst_equal (idx, integer_zero_node))
1833 {
1834 /* A NULL pointer-to-member constant. */
1835 OB_PUTS ("((");
9e93bc9d 1836 dump_type (TREE_TYPE (t), flags);
e08a8f45
MM
1837 OB_PUTS (") 0)");
1838 break;
1839 }
1840 else if (TREE_CODE (idx) == INTEGER_CST
1841 && TREE_INT_CST_HIGH (idx) == 0)
9a3b49ac
MS
1842 {
1843 tree virtuals;
1844 unsigned HOST_WIDE_INT n;
1845
1846 t = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t)));
1847 t = TYPE_METHOD_BASETYPE (t);
83f2ccf4 1848 virtuals = TYPE_BINFO_VIRTUALS (TYPE_MAIN_VARIANT (t));
9a3b49ac
MS
1849
1850 n = TREE_INT_CST_LOW (idx);
1851
1852 /* Map vtable index back one, to allow for the null pointer to
1853 member. */
1854 --n;
1855
1856 while (n > 0 && virtuals)
1857 {
1858 --n;
1859 virtuals = TREE_CHAIN (virtuals);
1860 }
1861 if (virtuals)
1862 {
9e93bc9d
NS
1863 dump_expr (TREE_VALUE (virtuals),
1864 flags | TS_EXPR_PARENS);
9a3b49ac
MS
1865 break;
1866 }
1867 }
1868 }
8d08fdba 1869 OB_PUTC ('{');
9e93bc9d 1870 dump_expr_list (CONSTRUCTOR_ELTS (t), flags);
8d08fdba
MS
1871 OB_PUTC ('}');
1872 break;
1873
51c184be
MS
1874 case OFFSET_REF:
1875 {
1876 tree ob = TREE_OPERAND (t, 0);
51924768 1877 if (is_dummy_object (ob))
61a127b3 1878 {
05e0b2f4
JM
1879 t = TREE_OPERAND (t, 1);
1880 if (TREE_CODE (t) == FUNCTION_DECL)
61a127b3 1881 /* A::f */
9e93bc9d 1882 dump_expr (t, flags | TS_EXPR_PARENS);
05e0b2f4 1883 else if (BASELINK_P (t))
9e93bc9d 1884 dump_expr (OVL_CURRENT (TREE_VALUE (t)), flags | TS_EXPR_PARENS);
61a127b3 1885 else
9e93bc9d 1886 dump_decl (t, flags);
61a127b3 1887 }
51c184be
MS
1888 else
1889 {
bbcec105
JM
1890 if (TREE_CODE (ob) == INDIRECT_REF)
1891 {
9e93bc9d 1892 dump_expr (TREE_OPERAND (ob, 0), flags | TS_EXPR_PARENS);
bbcec105
JM
1893 OB_PUTS (" ->* ");
1894 }
1895 else
1896 {
9e93bc9d 1897 dump_expr (ob, flags | TS_EXPR_PARENS);
bbcec105
JM
1898 OB_PUTS (" .* ");
1899 }
9e93bc9d 1900 dump_expr (TREE_OPERAND (t, 1), flags | TS_EXPR_PARENS);
51c184be
MS
1901 }
1902 break;
1903 }
1904
f84b4be9 1905 case TEMPLATE_PARM_INDEX:
9e93bc9d 1906 dump_decl (TEMPLATE_PARM_DECL (t), flags & ~TS_DECL_TYPE);
de22184b 1907 break;
5566b478
MS
1908
1909 case IDENTIFIER_NODE:
1910 OB_PUTID (t);
1911 break;
1912
1913 case SCOPE_REF:
9e93bc9d 1914 dump_type (TREE_OPERAND (t, 0), flags);
5566b478 1915 OB_PUTS ("::");
9e93bc9d 1916 dump_expr (TREE_OPERAND (t, 1), flags | TS_EXPR_PARENS);
5566b478
MS
1917 break;
1918
1919 case CAST_EXPR:
e349ee73
MS
1920 if (TREE_OPERAND (t, 0) == NULL_TREE
1921 || TREE_CHAIN (TREE_OPERAND (t, 0)))
e76a2646 1922 {
9e93bc9d 1923 dump_type (TREE_TYPE (t), flags);
e76a2646 1924 OB_PUTC ('(');
9e93bc9d 1925 dump_expr_list (TREE_OPERAND (t, 0), flags);
e76a2646
MS
1926 OB_PUTC (')');
1927 }
1928 else
1929 {
1930 OB_PUTC ('(');
9e93bc9d 1931 dump_type (TREE_TYPE (t), flags);
e76a2646
MS
1932 OB_PUTC (')');
1933 OB_PUTC ('(');
9e93bc9d 1934 dump_expr_list (TREE_OPERAND (t, 0), flags);
e76a2646
MS
1935 OB_PUTC (')');
1936 }
1937 break;
1938
1939 case LOOKUP_EXPR:
1940 OB_PUTID (TREE_OPERAND (t, 0));
1941 break;
1942
5a11e05b 1943 case ARROW_EXPR:
9e93bc9d 1944 dump_expr (TREE_OPERAND (t, 0), flags);
5a11e05b
BK
1945 OB_PUTS ("->");
1946 break;
1947
e76a2646 1948 case SIZEOF_EXPR:
abff8e06
JM
1949 case ALIGNOF_EXPR:
1950 if (TREE_CODE (t) == SIZEOF_EXPR)
1951 OB_PUTS ("sizeof (");
1952 else
1953 {
1954 my_friendly_assert (TREE_CODE (t) == ALIGNOF_EXPR, 0);
1955 OB_PUTS ("__alignof__ (");
1956 }
e76a2646 1957 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t, 0))) == 't')
9e93bc9d 1958 dump_type (TREE_OPERAND (t, 0), flags);
e76a2646 1959 else
9e93bc9d 1960 dump_unary_op ("*", t, flags | TS_EXPR_PARENS);
e76a2646
MS
1961 OB_PUTC (')');
1962 break;
5566b478 1963
da20811c
JM
1964 case DEFAULT_ARG:
1965 OB_PUTS ("{unparsed}");
1966 break;
1967
6748b643
JM
1968 case TRY_CATCH_EXPR:
1969 case WITH_CLEANUP_EXPR:
1970 case CLEANUP_POINT_EXPR:
9e93bc9d 1971 dump_expr (TREE_OPERAND (t, 0), flags);
6748b643
JM
1972 break;
1973
40242ccf 1974 case PSEUDO_DTOR_EXPR:
9e93bc9d 1975 dump_expr (TREE_OPERAND (t, 2), flags);
40242ccf 1976 OB_PUTS (".");
9e93bc9d 1977 dump_type (TREE_OPERAND (t, 0), flags);
40242ccf 1978 OB_PUTS ("::~");
9e93bc9d 1979 dump_type (TREE_OPERAND (t, 1), flags);
40242ccf
MM
1980 break;
1981
7ac7b28f 1982 case TEMPLATE_ID_EXPR:
9e93bc9d 1983 dump_decl (t, flags);
7ac7b28f
MM
1984 break;
1985
558475f0
MM
1986 case STMT_EXPR:
1987 /* We don't yet have a way of dumping statements in a
1988 human-readable format. */
1989 OB_PUTS ("{ ... }");
1990 break;
1991
0045e0bc
MM
1992 case BIND_EXPR:
1993 OB_PUTS ("{ ");
9e93bc9d 1994 dump_expr (TREE_OPERAND (t, 1), flags & ~TS_EXPR_PARENS);
0045e0bc
MM
1995 OB_PUTS ("} ");
1996 break;
1997
1998 case LOOP_EXPR:
1999 OB_PUTS ("while (1) { ");
9e93bc9d 2000 dump_expr (TREE_OPERAND (t, 0), flags & ~TS_EXPR_PARENS);
0045e0bc
MM
2001 OB_PUTS ("} ");
2002 break;
2003
2004 case EXIT_EXPR:
2005 OB_PUTS ("if (");
9e93bc9d 2006 dump_expr (TREE_OPERAND (t, 0), flags & ~TS_EXPR_PARENS);
0045e0bc
MM
2007 OB_PUTS (") break; ");
2008 break;
2009
00595019
MS
2010 case TREE_LIST:
2011 if (TREE_VALUE (t) && TREE_CODE (TREE_VALUE (t)) == FUNCTION_DECL)
2012 {
2013 OB_PUTID (DECL_NAME (TREE_VALUE (t)));
2014 break;
2015 }
2016 /* else fall through */
2017
8d08fdba
MS
2018 /* This list is incomplete, but should suffice for now.
2019 It is very important that `sorry' does not call
2020 `report_error_function'. That could cause an infinite loop. */
2021 default:
2022 sorry ("`%s' not supported by dump_expr",
2023 tree_code_name[(int) TREE_CODE (t)]);
2024
2025 /* fall through to ERROR_MARK... */
2026 case ERROR_MARK:
612c671a 2027 OB_PUTCP ("{expression error}");
8d08fdba
MS
2028 break;
2029 }
2030}
2031
2032static void
9e93bc9d 2033dump_binary_op (opstring, t, flags)
9c0758dd 2034 const char *opstring;
8d08fdba 2035 tree t;
9e93bc9d 2036 enum tree_string_flags flags;
8d08fdba
MS
2037{
2038 OB_PUTC ('(');
9e93bc9d 2039 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
8d08fdba 2040 OB_PUTC (' ');
2adeacc9
MM
2041 if (opstring)
2042 OB_PUTCP (opstring);
2043 else
2044 OB_PUTS ("<unknown operator>");
8d08fdba 2045 OB_PUTC (' ');
9e93bc9d 2046 dump_expr (TREE_OPERAND (t, 1), flags | TS_EXPR_PARENS);
8d08fdba
MS
2047 OB_PUTC (')');
2048}
2049
2050static void
9e93bc9d 2051dump_unary_op (opstring, t, flags)
9c0758dd 2052 const char *opstring;
8d08fdba 2053 tree t;
9e93bc9d 2054 enum tree_string_flags flags;
8d08fdba 2055{
9e93bc9d
NS
2056 if (flags & TS_EXPR_PARENS)
2057 OB_PUTC ('(');
8d08fdba 2058 OB_PUTCP (opstring);
9e93bc9d
NS
2059 dump_expr (TREE_OPERAND (t, 0), flags & ~TS_EXPR_PARENS);
2060 if (flags & TS_EXPR_PARENS)
2061 OB_PUTC (')');
8d08fdba
MS
2062}
2063
9e93bc9d
NS
2064/* Exported interface to stringifying types, exprs and decls under TS_*
2065 control. */
4995028c 2066
e1def31b 2067const char *
9e93bc9d
NS
2068type_as_string (typ, flags)
2069 tree typ;
2070 enum tree_string_flags flags;
8d08fdba 2071{
4995028c
NS
2072 OB_INIT ();
2073
9e93bc9d
NS
2074 dump_type (typ, flags);
2075
4995028c
NS
2076 OB_FINISH ();
2077
2078 return (char *)obstack_base (&scratch_obstack);
8d08fdba
MS
2079}
2080
e1def31b 2081const char *
9e93bc9d
NS
2082expr_as_string (decl, flags)
2083 tree decl;
2084 enum tree_string_flags flags;
8d08fdba
MS
2085{
2086 OB_INIT ();
2087
9e93bc9d 2088 dump_expr (decl, flags);
8d08fdba
MS
2089
2090 OB_FINISH ();
2091
2092 return (char *)obstack_base (&scratch_obstack);
2093}
2094
e1def31b 2095const char *
9e93bc9d 2096decl_as_string (decl, flags)
8d08fdba 2097 tree decl;
9e93bc9d 2098 enum tree_string_flags flags;
8d08fdba
MS
2099{
2100 OB_INIT ();
2101
9e93bc9d 2102 dump_decl (decl, flags);
8d08fdba
MS
2103
2104 OB_FINISH ();
2105
2106 return (char *)obstack_base (&scratch_obstack);
2107}
2108
e1def31b 2109const char *
9e93bc9d
NS
2110context_as_string (context, flags)
2111 tree context;
2112 enum tree_string_flags flags;
8d08fdba
MS
2113{
2114 OB_INIT ();
9e93bc9d
NS
2115
2116 dump_scope (context, flags);
2117
8d08fdba
MS
2118 OB_FINISH ();
2119
2120 return (char *)obstack_base (&scratch_obstack);
2121}
2122
2ba25f50
MS
2123/* Generate the three forms of printable names for lang_printable_name. */
2124
e1def31b 2125const char *
2ba25f50
MS
2126lang_decl_name (decl, v)
2127 tree decl;
2128 int v;
2129{
2130 if (v >= 2)
9e93bc9d 2131 return decl_as_string (decl, TS_DECL_TYPE);
2ba25f50
MS
2132
2133 OB_INIT ();
2134
6eb3bb27 2135 if (v == 1 && DECL_CLASS_SCOPE_P (decl))
2ba25f50
MS
2136 {
2137 tree cname;
2138 if (TREE_CODE (decl) == FUNCTION_DECL)
2139 cname = DECL_CLASS_CONTEXT (decl);
2140 else
2141 cname = DECL_CONTEXT (decl);
9e93bc9d
NS
2142 dump_type (cname, TS_PLAIN);
2143 OB_PUTS ("::");
2ba25f50
MS
2144 }
2145
2146 if (TREE_CODE (decl) == FUNCTION_DECL)
9e93bc9d 2147 dump_function_name (decl, TS_PLAIN);
2ba25f50 2148 else
9e93bc9d 2149 dump_decl (DECL_NAME (decl), TS_PLAIN);
2ba25f50
MS
2150
2151 OB_FINISH ();
2152
2153 return (char *)obstack_base (&scratch_obstack);
2154}
2ba25f50 2155
e1def31b 2156const char *
8d08fdba
MS
2157cp_file_of (t)
2158 tree t;
2159{
741f2839 2160 if (TREE_CODE (t) == PARM_DECL && DECL_CONTEXT (t))
8d08fdba
MS
2161 return DECL_SOURCE_FILE (DECL_CONTEXT (t));
2162 else if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
d2e5ee5c 2163 return DECL_SOURCE_FILE (TYPE_MAIN_DECL (t));
8f032717
MM
2164 else if (TREE_CODE (t) == OVERLOAD)
2165 return DECL_SOURCE_FILE (OVL_FUNCTION (t));
8d08fdba
MS
2166 else
2167 return DECL_SOURCE_FILE (t);
2168}
2169
2170int
2171cp_line_of (t)
2172 tree t;
2173{
f376e137 2174 int line = 0;
741f2839 2175 if (TREE_CODE (t) == PARM_DECL && DECL_CONTEXT (t))
f376e137 2176 line = DECL_SOURCE_LINE (DECL_CONTEXT (t));
f3400fe2
JM
2177 if (TREE_CODE (t) == TYPE_DECL && DECL_ARTIFICIAL (t)
2178 && TYPE_MAIN_DECL (TREE_TYPE (t)))
f376e137
MS
2179 t = TREE_TYPE (t);
2180
2181 if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
d2e5ee5c 2182 line = DECL_SOURCE_LINE (TYPE_MAIN_DECL (t));
8f032717
MM
2183 else if (TREE_CODE (t) == OVERLOAD)
2184 line = DECL_SOURCE_LINE (OVL_FUNCTION (t));
8d08fdba 2185 else
f376e137
MS
2186 line = DECL_SOURCE_LINE (t);
2187
2188 if (line == 0)
2189 return lineno;
2190
2191 return line;
8d08fdba
MS
2192}
2193
9e93bc9d
NS
2194/* Now the interfaces from cp_error et al to dump_type et al. Each takes an
2195 on/off VERBOSE flag and supply the appropriate TS_ flags to a dump_
2196 function. */
2197
2198static const char *
2199decl_to_string (decl, verbose)
2200 tree decl;
2201 int verbose;
2202{
2203 enum tree_string_flags flags = 0;
2204
2205 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == RECORD_TYPE
2206 || TREE_CODE (decl) == UNION_TYPE || TREE_CODE (decl) == ENUMERAL_TYPE)
2207 flags = TS_AGGR_TAGS;
2208 if (verbose)
2209 flags |= TS_DECL_TYPE | TS_DECORATE | TS_PARM_DEFAULTS;
2210 else if (TREE_CODE (decl) == FUNCTION_DECL)
2211 flags |= TS_DECL_TYPE | TS_FUNC_NORETURN;
2212 flags |= TS_TEMPLATE_PREFIX;
2213
2214 OB_INIT ();
2215
2216 dump_decl (decl, flags);
2217
2218 OB_FINISH ();
2219
2220 return (char *)obstack_base (&scratch_obstack);
2221}
2222
2223static const char *
2224expr_to_string (decl, verbose)
2225 tree decl;
2226 int verbose ATTRIBUTE_UNUSED;
2227{
2228 OB_INIT ();
2229
2230 dump_expr (decl, 0);
2231
2232 OB_FINISH ();
2233
2234 return (char *)obstack_base (&scratch_obstack);
2235}
2236
2237static const char *
2238fndecl_to_string (fndecl, verbose)
2239 tree fndecl;
2240 int verbose;
2241{
2242 enum tree_string_flags flags;
2243
2244 flags = TS_FUNC_THROW | TS_DECL_TYPE;
2245 if (verbose)
2246 flags |= TS_PARM_DEFAULTS;
2247 OB_INIT ();
2248
2249 dump_decl (fndecl, flags);
2250
2251 OB_FINISH ();
2252
2253 return (char *)obstack_base (&scratch_obstack);
2254}
2255
2256
2257static const char *
2258code_to_string (c, v)
8d08fdba 2259 enum tree_code c;
7dee3f36 2260 int v ATTRIBUTE_UNUSED;
8d08fdba
MS
2261{
2262 return tree_code_name [c];
2263}
2264
9e93bc9d
NS
2265static const char *
2266language_to_string (c, v)
8d08fdba 2267 enum languages c;
7dee3f36 2268 int v ATTRIBUTE_UNUSED;
8d08fdba
MS
2269{
2270 switch (c)
2271 {
2272 case lang_c:
2273 return "C";
2274
2275 case lang_cplusplus:
2276 return "C++";
2277
31b72b87
PB
2278 case lang_java:
2279 return "Java";
2280
8d08fdba
MS
2281 default:
2282 my_friendly_abort (355);
8926095f 2283 return 0;
8d08fdba
MS
2284 }
2285}
2286
2287/* Return the proper printed version of a parameter to a C++ function. */
e92cc029 2288
9e93bc9d
NS
2289static const char *
2290parm_to_string (p, v)
7dee3f36
KG
2291 int p;
2292 int v ATTRIBUTE_UNUSED;
8d08fdba
MS
2293{
2294 if (p < 0)
2295 return "`this'";
2296
2297 sprintf (digit_buffer, "%d", p+1);
2298 return digit_buffer;
2299}
2300
9e93bc9d
NS
2301static const char *
2302op_to_string (p, v)
8d08fdba 2303 enum tree_code p;
7dee3f36 2304 int v ATTRIBUTE_UNUSED;
8d08fdba
MS
2305{
2306 static char buf[] = "operator ";
2307
2308 if (p == 0)
51c184be 2309 return "{unknown}";
8d08fdba
MS
2310
2311 strcpy (buf + 9, opname_tab [p]);
2312 return buf;
2313}
2314
9e93bc9d
NS
2315static const char *
2316type_to_string (typ, verbose)
2317 tree typ;
2318 int verbose;
2319{
2320 enum tree_string_flags flags;
2321
2322 flags = 0;
2323 if (verbose)
2324 flags |= TS_AGGR_TAGS;
2325 flags |= TS_TEMPLATE_PREFIX;
2326
2327 OB_INIT ();
2328
2329 dump_type (typ, flags);
2330
2331 OB_FINISH ();
2332
2333 return (char *)obstack_base (&scratch_obstack);
2334}
2335
2336static const char *
2337assop_to_string (p, v)
c91a56d2 2338 enum tree_code p;
7dee3f36 2339 int v ATTRIBUTE_UNUSED;
c91a56d2
MS
2340{
2341 static char buf[] = "operator ";
2342
2343 if (p == 0)
2344 return "{unknown}";
2345
2346 strcpy (buf + 9, assignop_tab [p]);
2347 return buf;
2348}
2349
9e93bc9d
NS
2350static const char *
2351args_to_string (p, verbose)
8d08fdba 2352 tree p;
9e93bc9d 2353 int verbose;
8d08fdba 2354{
9e93bc9d
NS
2355 enum tree_string_flags flags = 0;
2356 if (verbose)
2357 flags |= TS_AGGR_TAGS;
2358
8d08fdba 2359 if (p == NULL_TREE)
c73964b2 2360 return "";
8d08fdba 2361
c73964b2 2362 if (TREE_CODE_CLASS (TREE_CODE (TREE_VALUE (p))) == 't')
9e93bc9d 2363 return type_as_string (p, flags);
c73964b2
MS
2364
2365 OB_INIT ();
2366 for (; p; p = TREE_CHAIN (p))
2367 {
a6967cc0
JM
2368 if (TREE_VALUE (p) == null_node)
2369 OB_PUTS ("NULL");
2370 else
9e93bc9d 2371 dump_type (error_type (TREE_VALUE (p)), flags);
c73964b2
MS
2372 if (TREE_CHAIN (p))
2373 OB_PUTS (", ");
2374 }
2375 OB_FINISH ();
2376 return (char *)obstack_base (&scratch_obstack);
8d08fdba 2377}
f30432d7 2378
9e93bc9d
NS
2379static const char *
2380cv_to_string (p, v)
f30432d7 2381 tree p;
7dee3f36 2382 int v ATTRIBUTE_UNUSED;
f30432d7
MS
2383{
2384 OB_INIT ();
2385
91063b51 2386 dump_qualifiers (p, before);
f30432d7
MS
2387
2388 OB_FINISH ();
2389
2390 return (char *)obstack_base (&scratch_obstack);
2391}
This page took 0.885304 seconds and 5 git commands to generate.