Use -static when testing --gc-sections on native targets
[official-gcc.git] / gcc / cp / error.c
blobd0196f58f7d09c880f767ee5d7a07e1414529bdc
1 /* Call-backs for C++ error reporting.
2 This code is non-reentrant.
3 Copyright (C) 1993, 94, 95, 96, 97, 98, 99, 2000
4 Free Software Foundation, Inc.
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 #include "config.h"
24 #include "system.h"
25 #include "tree.h"
26 #include "cp-tree.h"
27 #include "obstack.h"
28 #include "toplev.h"
30 typedef const char *cp_printer ();
32 #define obstack_chunk_alloc xmalloc
33 #define obstack_chunk_free free
35 /* Obstack where we build text strings for overloading, etc. */
36 static struct obstack scratch_obstack;
37 static char *scratch_firstobj;
39 # define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
40 # define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
41 # define OB_PUTC2(C1,C2) \
42 (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
43 # define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
44 # define OB_PUTID(ID) \
45 (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \
46 IDENTIFIER_LENGTH (ID)))
47 # define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
48 # define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
49 # define OB_PUTI(CST) do { sprintf (digit_buffer, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT)(CST)); \
50 OB_PUTCP (digit_buffer); } while (0)
52 # define OB_END_TEMPLATE_ID() \
53 (((obstack_next_free (&scratch_obstack) != obstack_base (&scratch_obstack) \
54 && obstack_next_free (&scratch_obstack)[-1] == '>') \
55 ? OB_PUTC (' ') : (void)0), OB_PUTC ('>'))
57 # define NEXT_CODE(t) (TREE_CODE (TREE_TYPE (t)))
59 enum pad { none, before, after };
61 static const char *args_to_string PARAMS ((tree, int));
62 static const char *assop_to_string PARAMS ((enum tree_code, int));
63 static const char *code_to_string PARAMS ((enum tree_code, int));
64 static const char *cv_to_string PARAMS ((tree, int));
65 static const char *decl_to_string PARAMS ((tree, int));
66 static const char *expr_to_string PARAMS ((tree, int));
67 static const char *fndecl_to_string PARAMS ((tree, int));
68 static const char *language_to_string PARAMS ((enum languages, int));
69 static const char *op_to_string PARAMS ((enum tree_code, int));
70 static const char *parm_to_string PARAMS ((int, int));
71 static const char *type_to_string PARAMS ((tree, int));
73 static void dump_type PARAMS ((tree, enum tree_string_flags));
74 static void dump_simple_decl PARAMS ((tree, tree, enum tree_string_flags));
75 static void dump_decl PARAMS ((tree, enum tree_string_flags));
76 static void dump_template_decl PARAMS ((tree, enum tree_string_flags));
77 static void dump_function_decl PARAMS ((tree, enum tree_string_flags));
78 static void dump_expr PARAMS ((tree, enum tree_string_flags));
79 static void dump_unary_op PARAMS ((const char *, tree, enum tree_string_flags));
80 static void dump_binary_op PARAMS ((const char *, tree, enum tree_string_flags));
81 static void dump_aggr_type PARAMS ((tree, enum tree_string_flags));
82 static enum pad dump_type_prefix PARAMS ((tree, enum tree_string_flags));
83 static void dump_type_suffix PARAMS ((tree, enum tree_string_flags));
84 static void dump_function_name PARAMS ((tree, enum tree_string_flags));
85 static void dump_expr_list PARAMS ((tree, enum tree_string_flags));
86 static void dump_global_iord PARAMS ((tree));
87 static enum pad dump_qualifiers PARAMS ((tree, enum pad));
88 static void dump_char PARAMS ((int));
89 static void dump_parameters PARAMS ((tree, enum tree_string_flags));
90 static void dump_exception_spec PARAMS ((tree, enum tree_string_flags));
91 static const char *aggr_variety PARAMS ((tree));
92 static tree ident_fndecl PARAMS ((tree));
93 static void dump_template_argument PARAMS ((tree, enum tree_string_flags));
94 static void dump_template_argument_list PARAMS ((tree, enum tree_string_flags));
95 static void dump_template_parameter PARAMS ((tree, enum tree_string_flags));
96 static void dump_template_bindings PARAMS ((tree, tree));
97 static void dump_scope PARAMS ((tree, enum tree_string_flags));
98 static void dump_template_parms PARAMS ((tree, int, enum tree_string_flags));
100 #define A args_to_string
101 #define C code_to_string
102 #define D decl_to_string
103 #define E expr_to_string
104 #define F fndecl_to_string
105 #define L language_to_string
106 #define O op_to_string
107 #define P parm_to_string
108 #define Q assop_to_string
109 #define T type_to_string
110 #define V cv_to_string
112 #define o (cp_printer *) 0
113 cp_printer * cp_printers[256] =
115 /*0 1 2 3 4 5 6 7 8 9 A B C D E F */
116 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x00 */
117 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x10 */
118 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x20 */
119 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x30 */
120 o, A, o, C, D, E, F, o, o, o, o, o, L, o, o, O, /* 0x40 */
121 P, Q, o, o, T, o, V, o, o, o, o, o, o, o, o, o, /* 0x50 */
122 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x60 */
123 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x70 */
125 #undef C
126 #undef D
127 #undef E
128 #undef F
129 #undef L
130 #undef O
131 #undef P
132 #undef Q
133 #undef T
134 #undef V
135 #undef o
137 void
138 init_error ()
140 gcc_obstack_init (&scratch_obstack);
141 scratch_firstobj = (char *)obstack_alloc (&scratch_obstack, 0);
144 /* Dump a scope, if deemed necessary. */
146 static void
147 dump_scope (scope, flags)
148 tree scope;
149 enum tree_string_flags flags;
151 if (scope == NULL_TREE)
152 return;
154 if (TREE_CODE (scope) == NAMESPACE_DECL)
156 if (scope != global_namespace)
158 dump_decl (scope, (flags & (TS_PEDANTIC_NAME | TS_FUNC_SCOPE | TS_CHASE_TYPEDEFS))
159 | TS_FUNC_NORETURN | TS_DECL_TYPE);
160 OB_PUTS ("::");
162 else if (flags & TS_PEDANTIC_NAME)
163 OB_PUTS ("::");
165 else if (AGGREGATE_TYPE_P (scope))
167 dump_type (scope, (flags & (TS_PEDANTIC_NAME | TS_FUNC_SCOPE | TS_CHASE_TYPEDEFS))
168 | TS_FUNC_NORETURN | TS_DECL_TYPE);
169 OB_PUTS ("::");
171 else if ((flags & (TS_PEDANTIC_NAME | TS_FUNC_SCOPE))
172 && TREE_CODE (scope) == FUNCTION_DECL)
174 dump_function_decl (scope, (flags & (TS_PEDANTIC_NAME | TS_FUNC_SCOPE | TS_CHASE_TYPEDEFS))
175 | TS_FUNC_NORETURN | TS_DECL_TYPE);
176 OB_PUTS ("::");
180 /* Dump type qualifiers, providing padding as requested. Return an
181 indication of whether we dumped something. */
183 static enum pad
184 dump_qualifiers (t, p)
185 tree t;
186 enum pad p;
188 static const int masks[] =
189 {TYPE_QUAL_CONST, TYPE_QUAL_VOLATILE, TYPE_QUAL_RESTRICT};
190 static const char *const names[] =
191 {"const", "volatile", "__restrict"};
192 int ix;
193 int quals = TYPE_QUALS (t);
194 int do_after = p == after;
196 if (quals)
198 for (ix = 0; ix != 3; ix++)
199 if (masks[ix] & quals)
201 if (p == before)
202 OB_PUTC (' ');
203 p = before;
204 OB_PUTCP (names[ix]);
206 if (do_after)
207 OB_PUTC (' ');
209 else
210 p = none;
211 return p;
214 /* This must be large enough to hold any printed integer or floating-point
215 value. */
216 static char digit_buffer[128];
218 /* Dump the template ARGument under control of FLAGS. */
220 static void
221 dump_template_argument (arg, flags)
222 tree arg;
223 enum tree_string_flags flags;
225 if (TREE_CODE_CLASS (TREE_CODE (arg)) == 't'
226 || TREE_CODE (arg) == TEMPLATE_DECL)
227 dump_type (arg, flags & ~TS_AGGR_TAGS);
228 else
229 dump_expr (arg, (flags | TS_EXPR_PARENS) & ~TS_AGGR_TAGS);
232 /* Dump a template-argument-list ARGS (always a TREE_VEC) under control
233 of FLAGS. */
235 static void
236 dump_template_argument_list (args, flags)
237 tree args;
238 enum tree_string_flags flags;
240 int n = TREE_VEC_LENGTH (args);
241 int need_comma = 0;
242 int i;
244 for (i = 0; i< n; ++i)
246 if (need_comma)
247 OB_PUTS (", ");
248 dump_template_argument (TREE_VEC_ELT (args, i), flags);
249 need_comma = 1;
253 /* Dump a template parameter PARM (a TREE_LIST) under control of FLAGS. */
255 static void
256 dump_template_parameter (parm, flags)
257 tree parm;
258 enum tree_string_flags flags;
260 tree p = TREE_VALUE (parm);
261 tree a = TREE_PURPOSE (parm);
263 if (TREE_CODE (p) == TYPE_DECL)
265 if (flags & TS_DECL_TYPE)
267 OB_PUTS ("class");
268 if (DECL_NAME (p))
270 OB_PUTC (' ');
271 OB_PUTID (DECL_NAME (p));
274 else if (DECL_NAME (p))
275 OB_PUTID (DECL_NAME (p));
276 else
277 OB_PUTS ("{template default argument error}");
279 else
280 dump_decl (p, flags | TS_DECL_TYPE);
282 if ((flags & TS_PARM_DEFAULTS) && a != NULL_TREE)
284 OB_PUTS (" = ");
285 if (TREE_CODE (a) == TYPE_DECL || TREE_CODE (a) == TEMPLATE_DECL)
286 dump_type (a, flags & ~TS_CHASE_TYPEDEFS);
287 else
288 dump_expr (a, flags | TS_EXPR_PARENS);
292 /* Dump, under control of FLAGS, a template-parameter-list binding.
293 PARMS is a TREE_LIST of TREE_VEC of TREE_LIST and ARGS is a
294 TREE_VEC. */
296 static void
297 dump_template_bindings (parms, args)
298 tree parms, args;
300 int need_comma = 0;
302 while (parms)
304 tree p = TREE_VALUE (parms);
305 int lvl = TMPL_PARMS_DEPTH (parms);
306 int arg_idx = 0;
307 int i;
309 for (i = 0; i < TREE_VEC_LENGTH (p); ++i)
311 tree arg = TMPL_ARG (args, lvl, arg_idx);
313 if (need_comma)
314 OB_PUTS (", ");
315 dump_template_parameter (TREE_VEC_ELT (p, i), TS_PLAIN);
316 OB_PUTS (" = ");
317 if (arg)
318 dump_template_argument (arg, TS_PLAIN);
319 else
320 OB_PUTS ("{missing}");
322 ++arg_idx;
323 need_comma = 1;
326 parms = TREE_CHAIN (parms);
330 /* Dump into the obstack a human-readable equivalent of TYPE. FLAGS
331 controls the format. */
333 static void
334 dump_type (t, flags)
335 tree t;
336 enum tree_string_flags flags;
338 if (t == NULL_TREE)
339 return;
341 if (TYPE_PTRMEMFUNC_P (t))
342 goto offset_type;
344 switch (TREE_CODE (t))
346 case UNKNOWN_TYPE:
347 OB_PUTS ("{unknown type}");
348 break;
350 case TREE_LIST:
351 /* A list of function parms. */
352 dump_parameters (t, flags);
353 break;
355 case IDENTIFIER_NODE:
356 OB_PUTID (t);
357 break;
359 case TREE_VEC:
360 dump_type (BINFO_TYPE (t), flags);
361 break;
363 case RECORD_TYPE:
364 case UNION_TYPE:
365 case ENUMERAL_TYPE:
366 dump_aggr_type (t, flags);
367 break;
369 case TYPE_DECL:
370 if (flags & TS_CHASE_TYPEDEFS)
372 dump_type (DECL_ORIGINAL_TYPE (t)
373 ? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t), flags);
374 break;
376 /* else fallthrough */
378 case TEMPLATE_DECL:
379 case NAMESPACE_DECL:
380 dump_decl (t, flags & ~TS_DECL_TYPE);
381 break;
383 case COMPLEX_TYPE:
384 OB_PUTS ("complex ");
385 dump_type (TREE_TYPE (t), flags);
386 break;
388 case INTEGER_TYPE:
389 if (!TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)) && TREE_UNSIGNED (t))
390 OB_PUTS ("unsigned ");
391 else if (TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)) && !TREE_UNSIGNED (t))
392 OB_PUTS ("signed ");
394 /* fall through. */
395 case REAL_TYPE:
396 case VOID_TYPE:
397 case BOOLEAN_TYPE:
399 tree type;
400 dump_qualifiers (t, after);
401 type = flags & TS_CHASE_TYPEDEFS ? TYPE_MAIN_VARIANT (t) : t;
402 if (TYPE_NAME (type) && TYPE_IDENTIFIER (type))
403 OB_PUTID (TYPE_IDENTIFIER (type));
404 else
405 /* Types like intQI_type_node and friends have no names.
406 These don't come up in user error messages, but it's nice
407 to be able to print them from the debugger. */
408 OB_PUTS ("{anonymous}");
410 break;
412 case TEMPLATE_TEMPLATE_PARM:
413 if (!TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t))
415 /* For parameters inside template signature. */
416 if (TYPE_IDENTIFIER (t))
417 OB_PUTID (TYPE_IDENTIFIER (t));
418 else
419 OB_PUTS ("{anonymous template template parameter}");
421 else
423 tree args = TYPE_TI_ARGS (t);
424 OB_PUTID (TYPE_IDENTIFIER (t));
425 OB_PUTC ('<');
426 dump_template_argument_list (args, flags);
427 OB_END_TEMPLATE_ID ();
429 break;
431 case TEMPLATE_TYPE_PARM:
432 dump_qualifiers (t, after);
433 if (TYPE_IDENTIFIER (t))
434 OB_PUTID (TYPE_IDENTIFIER (t));
435 else
436 OB_PUTS ("{anonymous template type parameter}");
437 break;
439 /* This is not always necessary for pointers and such, but doing this
440 reduces code size. */
441 case ARRAY_TYPE:
442 case POINTER_TYPE:
443 case REFERENCE_TYPE:
444 case OFFSET_TYPE:
445 offset_type:
446 case FUNCTION_TYPE:
447 case METHOD_TYPE:
449 dump_type_prefix (t, flags);
450 dump_type_suffix (t, flags);
451 break;
453 case TYPENAME_TYPE:
454 OB_PUTS ("typename ");
455 dump_type (TYPE_CONTEXT (t), flags);
456 OB_PUTS ("::");
457 dump_decl (TYPENAME_TYPE_FULLNAME (t), flags);
458 break;
460 case TYPEOF_TYPE:
461 OB_PUTS ("__typeof (");
462 dump_expr (TYPE_FIELDS (t), flags & ~TS_EXPR_PARENS);
463 OB_PUTC (')');
464 break;
466 default:
467 sorry ("`%s' not supported by dump_type",
468 tree_code_name[(int) TREE_CODE (t)]);
469 /* Fall through to error. */
471 case ERROR_MARK:
472 OB_PUTS ("{type error}");
473 break;
477 /* Return the name of the supplied aggregate, or enumeral type. */
479 static const char *
480 aggr_variety (t)
481 tree t;
483 if (TREE_CODE (t) == ENUMERAL_TYPE)
484 return "enum";
485 else if (TREE_CODE (t) == UNION_TYPE)
486 return "union";
487 else if (TYPE_LANG_SPECIFIC (t) && CLASSTYPE_DECLARED_CLASS (t))
488 return "class";
489 else
490 return "struct";
493 /* Print out a class declaration T under the control of FLAGS,
494 in the form `class foo'. */
496 static void
497 dump_aggr_type (t, flags)
498 tree t;
499 enum tree_string_flags flags;
501 tree name;
502 const char *variety = aggr_variety (t);
503 int typdef = 0;
504 int tmplate = 0;
506 dump_qualifiers (t, after);
508 if (flags & TS_AGGR_TAGS)
510 OB_PUTCP (variety);
511 OB_PUTC (' ');
514 if (flags & TS_CHASE_TYPEDEFS)
515 t = TYPE_MAIN_VARIANT (t);
517 name = TYPE_NAME (t);
519 if (name)
521 typdef = !DECL_ARTIFICIAL (name);
522 tmplate = !typdef && TREE_CODE (t) != ENUMERAL_TYPE
523 && TYPE_LANG_SPECIFIC (t) && CLASSTYPE_TEMPLATE_INFO (t)
524 && (CLASSTYPE_TEMPLATE_SPECIALIZATION (t)
525 || TREE_CODE (CLASSTYPE_TI_TEMPLATE (t)) != TEMPLATE_DECL
526 || DECL_TEMPLATE_SPECIALIZATION (CLASSTYPE_TI_TEMPLATE (t))
527 || PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t)));
528 dump_scope (CP_DECL_CONTEXT (name), flags | TS_FUNC_SCOPE);
529 if (tmplate)
531 /* Because the template names are mangled, we have to locate
532 the most general template, and use that name. */
533 tree tpl = CLASSTYPE_TI_TEMPLATE (t);
535 while (DECL_TEMPLATE_INFO (tpl))
536 tpl = DECL_TI_TEMPLATE (tpl);
537 name = tpl;
539 name = DECL_NAME (name);
542 if (name == 0 || ANON_AGGRNAME_P (name))
544 OB_PUTS ("{anonymous");
545 if (!(flags & TS_AGGR_TAGS))
547 OB_PUTC (' ');
548 OB_PUTCP (variety);
550 OB_PUTC ('}');
552 else
553 OB_PUTID (name);
554 if (tmplate)
555 dump_template_parms (TYPE_TEMPLATE_INFO (t),
556 !CLASSTYPE_USE_TEMPLATE (t),
557 flags & ~TS_TEMPLATE_PREFIX);
560 /* Dump into the obstack the initial part of the output for a given type.
561 This is necessary when dealing with things like functions returning
562 functions. Examples:
564 return type of `int (* fee ())()': pointer -> function -> int. Both
565 pointer (and reference and offset) and function (and member) types must
566 deal with prefix and suffix.
568 Arrays must also do this for DECL nodes, like int a[], and for things like
569 int *[]&.
571 Return indicates how you should pad an object name after this. I.e. you
572 want to pad non-*, non-& cores, but not pad * or & types. */
574 static enum pad
575 dump_type_prefix (t, flags)
576 tree t;
577 enum tree_string_flags flags;
579 enum pad padding = before;
581 if (TYPE_PTRMEMFUNC_P (t))
583 t = TYPE_PTRMEMFUNC_FN_TYPE (t);
584 goto offset_type;
587 switch (TREE_CODE (t))
589 case POINTER_TYPE:
590 case REFERENCE_TYPE:
592 tree sub = TREE_TYPE (t);
594 padding = dump_type_prefix (sub, flags);
595 /* A tree for a member pointer looks like pointer to offset,
596 so let the OFFSET_TYPE case handle it. */
597 if (!TYPE_PTRMEM_P (t))
599 if (padding != none)
600 OB_PUTC (' ');
601 if (TREE_CODE (sub) == ARRAY_TYPE)
602 OB_PUTC ('(');
603 OB_PUTC ("&*"[TREE_CODE (t) == POINTER_TYPE]);
604 padding = dump_qualifiers (t, none);
607 break;
609 case OFFSET_TYPE:
610 offset_type:
611 padding = dump_type_prefix (TREE_TYPE (t), flags);
612 if (TREE_CODE (t) == OFFSET_TYPE) /* pmfs deal with this in d_t_p */
614 if (padding != none)
615 OB_PUTC (' ');
616 dump_type (TYPE_OFFSET_BASETYPE (t), flags);
617 OB_PUTS ("::");
619 OB_PUTC ('*');
620 padding = dump_qualifiers (t, none);
621 break;
623 /* Can only be reached through function pointer -- this would not be
624 correct if FUNCTION_DECLs used it. */
625 case FUNCTION_TYPE:
626 padding = dump_type_prefix (TREE_TYPE (t), flags);
627 if (padding != none)
628 OB_PUTC (' ');
629 OB_PUTC ('(');
630 padding = none;
631 break;
633 case METHOD_TYPE:
634 padding = dump_type_prefix (TREE_TYPE (t), flags);
635 if (padding != none)
636 OB_PUTC (' ');
637 OB_PUTC ('(');
638 padding = none;
639 dump_aggr_type (TYPE_METHOD_BASETYPE (t), flags);
640 OB_PUTS ("::");
641 break;
643 case ARRAY_TYPE:
644 padding = dump_type_prefix (TREE_TYPE (t), flags);
645 break;
647 case ENUMERAL_TYPE:
648 case IDENTIFIER_NODE:
649 case INTEGER_TYPE:
650 case BOOLEAN_TYPE:
651 case REAL_TYPE:
652 case RECORD_TYPE:
653 case TEMPLATE_TYPE_PARM:
654 case TEMPLATE_TEMPLATE_PARM:
655 case TREE_LIST:
656 case TYPE_DECL:
657 case TREE_VEC:
658 case UNION_TYPE:
659 case UNKNOWN_TYPE:
660 case VOID_TYPE:
661 case TYPENAME_TYPE:
662 case COMPLEX_TYPE:
663 dump_type (t, flags);
664 padding = before;
665 break;
667 default:
668 sorry ("`%s' not supported by dump_type_prefix",
669 tree_code_name[(int) TREE_CODE (t)]);
671 case ERROR_MARK:
672 OB_PUTS ("{typeprefixerror}");
673 break;
675 return padding;
678 /* Dump the suffix of type T, under control of FLAGS. This is the part
679 which appears after the identifier (or function parms). */
681 static void
682 dump_type_suffix (t, flags)
683 tree t;
684 enum tree_string_flags flags;
686 if (TYPE_PTRMEMFUNC_P (t))
687 t = TYPE_PTRMEMFUNC_FN_TYPE (t);
689 switch (TREE_CODE (t))
691 case POINTER_TYPE:
692 case REFERENCE_TYPE:
693 case OFFSET_TYPE:
694 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
695 OB_PUTC (')');
696 dump_type_suffix (TREE_TYPE (t), flags);
697 break;
699 /* Can only be reached through function pointer */
700 case FUNCTION_TYPE:
701 case METHOD_TYPE:
703 tree arg;
704 OB_PUTC (')');
705 arg = TYPE_ARG_TYPES (t);
706 if (TREE_CODE (t) == METHOD_TYPE)
707 arg = TREE_CHAIN (arg);
709 /* Function pointers don't have default args. Not in standard C++,
710 anyway; they may in g++, but we'll just pretend otherwise. */
711 dump_parameters (arg, flags & ~TS_PARM_DEFAULTS);
713 if (TREE_CODE (t) == METHOD_TYPE)
714 dump_qualifiers
715 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t))), before);
716 dump_type_suffix (TREE_TYPE (t), flags);
717 dump_exception_spec (TYPE_RAISES_EXCEPTIONS (t), flags);
718 break;
721 case ARRAY_TYPE:
722 OB_PUTC ('[');
723 if (TYPE_DOMAIN (t))
725 if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (t))) == INTEGER_CST)
726 OB_PUTI (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (t))) + 1);
727 else if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (t))) == MINUS_EXPR)
728 dump_expr (TREE_OPERAND (TYPE_MAX_VALUE (TYPE_DOMAIN (t)), 0),
729 flags & ~TS_EXPR_PARENS);
730 else
731 dump_expr (fold (build_binary_op
732 (PLUS_EXPR, TYPE_MAX_VALUE (TYPE_DOMAIN (t)),
733 integer_one_node)),
734 flags & ~TS_EXPR_PARENS);
736 OB_PUTC (']');
737 dump_type_suffix (TREE_TYPE (t), flags);
738 break;
740 case ENUMERAL_TYPE:
741 case IDENTIFIER_NODE:
742 case INTEGER_TYPE:
743 case BOOLEAN_TYPE:
744 case REAL_TYPE:
745 case RECORD_TYPE:
746 case TEMPLATE_TYPE_PARM:
747 case TEMPLATE_TEMPLATE_PARM:
748 case TREE_LIST:
749 case TYPE_DECL:
750 case TREE_VEC:
751 case UNION_TYPE:
752 case UNKNOWN_TYPE:
753 case VOID_TYPE:
754 case TYPENAME_TYPE:
755 case COMPLEX_TYPE:
756 break;
758 default:
759 sorry ("`%s' not supported by dump_type_suffix",
760 tree_code_name[(int) TREE_CODE (t)]);
762 case ERROR_MARK:
763 /* Don't mark it here, we should have already done in
764 dump_type_prefix. */
765 break;
769 /* Return a function declaration which corresponds to the IDENTIFIER_NODE
770 argument. */
772 static tree
773 ident_fndecl (t)
774 tree t;
776 tree n = lookup_name (t, 0);
778 if (n == NULL_TREE)
779 return NULL_TREE;
781 if (TREE_CODE (n) == FUNCTION_DECL)
782 return n;
783 else if (TREE_CODE (n) == TREE_LIST
784 && TREE_CODE (TREE_VALUE (n)) == FUNCTION_DECL)
785 return TREE_VALUE (n);
787 my_friendly_abort (66);
788 return NULL_TREE;
791 #ifndef NO_DOLLAR_IN_LABEL
792 # define GLOBAL_THING "_GLOBAL_$"
793 #else
794 # ifndef NO_DOT_IN_LABEL
795 # define GLOBAL_THING "_GLOBAL_."
796 # else
797 # define GLOBAL_THING "_GLOBAL__"
798 # endif
799 #endif
801 #define GLOBAL_IORD_P(NODE) \
802 ! strncmp (IDENTIFIER_POINTER(NODE), GLOBAL_THING, sizeof (GLOBAL_THING) - 1)
804 static void
805 dump_global_iord (t)
806 tree t;
808 const char *name = IDENTIFIER_POINTER (t);
810 OB_PUTS ("(static ");
811 if (name [sizeof (GLOBAL_THING) - 1] == 'I')
812 OB_PUTS ("initializers");
813 else if (name [sizeof (GLOBAL_THING) - 1] == 'D')
814 OB_PUTS ("destructors");
815 else
816 my_friendly_abort (352);
818 OB_PUTS (" for ");
819 OB_PUTCP (input_filename);
820 OB_PUTC (')');
823 static void
824 dump_simple_decl (t, type, flags)
825 tree t;
826 tree type;
827 enum tree_string_flags flags;
829 if (flags & TS_DECL_TYPE)
831 if (dump_type_prefix (type, flags) != none)
832 OB_PUTC (' ');
834 if (!DECL_INITIAL (t) || TREE_CODE (DECL_INITIAL (t)) != TEMPLATE_PARM_INDEX)
835 dump_scope (CP_DECL_CONTEXT (t), flags);
836 if (DECL_NAME (t))
837 dump_decl (DECL_NAME (t), flags);
838 else
839 OB_PUTS ("{anonymous}");
840 if (flags & TS_DECL_TYPE)
841 dump_type_suffix (type, flags);
844 /* Dump a human readable string for the decl T under control of FLAGS. */
846 static void
847 dump_decl (t, flags)
848 tree t;
849 enum tree_string_flags flags;
851 if (t == NULL_TREE)
852 return;
854 switch (TREE_CODE (t))
856 case TYPE_DECL:
858 /* Don't say 'typedef class A' */
859 if (DECL_ARTIFICIAL (t))
861 if ((flags & TS_DECL_TYPE)
862 && TREE_CODE (TREE_TYPE (t)) == TEMPLATE_TYPE_PARM)
863 /* Say `class T' not just `T'. */
864 OB_PUTS ("class ");
866 dump_type (TREE_TYPE (t), flags);
867 break;
870 if (flags & TS_DECORATE)
871 OB_PUTS ("typedef ");
872 dump_simple_decl (t, DECL_ORIGINAL_TYPE (t)
873 ? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t),
874 flags);
875 break;
877 case VAR_DECL:
878 if (DECL_NAME (t) && VTABLE_NAME_P (DECL_NAME (t)))
880 OB_PUTS ("vtable for ");
881 if (TYPE_P (DECL_CONTEXT (t)))
882 dump_type (DECL_CONTEXT (t), flags);
883 else
884 /* This case can arise with -fno-vtable-thunks. See
885 expand_upcast_fixups. It's not clear what to print
886 here. */
887 OB_PUTS ("{unknown type}");
888 break;
890 /* else fall through */
891 case FIELD_DECL:
892 case PARM_DECL:
893 dump_simple_decl (t, TREE_TYPE (t), flags);
894 break;
896 case RESULT_DECL:
897 OB_PUTS ("{return} ");
898 dump_simple_decl (t, TREE_TYPE (t), flags);
899 break;
901 case NAMESPACE_DECL:
902 dump_scope (CP_DECL_CONTEXT (t), flags);
903 if (DECL_NAME (t) == anonymous_namespace_name)
904 OB_PUTS ("{unnamed}");
905 else
906 OB_PUTID (DECL_NAME (t));
907 break;
909 case SCOPE_REF:
910 dump_decl (TREE_OPERAND (t, 0), flags & ~TS_DECL_TYPE);
911 OB_PUTS ("::");
912 dump_decl (TREE_OPERAND (t, 1), flags);
913 break;
915 case ARRAY_REF:
916 dump_decl (TREE_OPERAND (t, 0), flags);
917 OB_PUTC ('[');
918 dump_decl (TREE_OPERAND (t, 1), flags);
919 OB_PUTC (']');
920 break;
922 /* So that we can do dump_decl on an aggr type. */
923 case RECORD_TYPE:
924 case UNION_TYPE:
925 case ENUMERAL_TYPE:
926 dump_type (t, flags);
927 break;
929 case TYPE_EXPR:
930 my_friendly_abort (69);
931 break;
933 /* These special cases are duplicated here so that other functions
934 can feed identifiers to cp_error and get them demangled properly. */
935 case IDENTIFIER_NODE:
936 { tree f;
937 if (DESTRUCTOR_NAME_P (t)
938 && (f = ident_fndecl (t))
939 && DECL_LANGUAGE (f) == lang_cplusplus)
941 OB_PUTC ('~');
942 dump_decl (DECL_NAME (f), flags);
944 else if (IDENTIFIER_TYPENAME_P (t))
946 OB_PUTS ("operator ");
947 /* Not exactly IDENTIFIER_TYPE_VALUE. */
948 dump_type (TREE_TYPE (t), flags);
949 break;
951 else if (IDENTIFIER_OPNAME_P (t))
953 const char *name_string = operator_name_string (t);
954 OB_PUTS ("operator");
955 if (ISALPHA (name_string[0]))
956 OB_PUTC (' ');
957 OB_PUTCP (name_string);
959 else
960 OB_PUTID (t);
962 break;
964 case OVERLOAD:
965 t = OVL_CURRENT (t);
966 /* Fall through. */
968 case FUNCTION_DECL:
969 if (GLOBAL_IORD_P (DECL_ASSEMBLER_NAME (t)))
970 dump_global_iord (DECL_ASSEMBLER_NAME (t));
971 else if (! DECL_LANG_SPECIFIC (t))
972 OB_PUTS ("{internal}");
973 else if (flags & TS_PEDANTIC_NAME)
974 dump_function_decl (t, flags | TS_FUNC_NORETURN | TS_DECL_TYPE);
975 else
976 dump_function_decl (t, flags);
977 break;
979 case TEMPLATE_DECL:
980 if (flags & TS_PEDANTIC_NAME)
981 dump_template_decl (t, flags | TS_FUNC_NORETURN | TS_DECL_TYPE);
982 else
983 dump_template_decl (t, flags);
984 break;
986 case TEMPLATE_ID_EXPR:
988 tree args;
989 tree name = TREE_OPERAND (t, 0);
990 if (is_overloaded_fn (name))
991 name = DECL_NAME (get_first_fn (name));
992 dump_decl (name, flags);
993 OB_PUTC ('<');
994 for (args = TREE_OPERAND (t, 1); args; args = TREE_CHAIN (args))
996 dump_template_argument (TREE_VALUE (args), flags);
997 if (TREE_CHAIN (args))
998 OB_PUTS (", ");
1000 OB_END_TEMPLATE_ID ();
1002 break;
1004 case LOOKUP_EXPR:
1005 dump_decl (TREE_OPERAND (t, 0), flags);
1006 break;
1008 case LABEL_DECL:
1009 OB_PUTID (DECL_NAME (t));
1010 break;
1012 case CONST_DECL:
1013 if ((TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == ENUMERAL_TYPE)
1014 || (DECL_INITIAL (t) &&
1015 TREE_CODE (DECL_INITIAL (t)) == TEMPLATE_PARM_INDEX))
1016 dump_simple_decl (t, TREE_TYPE (t), flags);
1017 else if (DECL_NAME (t))
1018 dump_decl (DECL_NAME (t), flags);
1019 else if (DECL_INITIAL (t))
1020 dump_expr (DECL_INITIAL (t), flags | TS_EXPR_PARENS);
1021 else
1022 OB_PUTS ("enumerator");
1023 break;
1025 case USING_DECL:
1026 OB_PUTS ("using ");
1027 dump_type (DECL_INITIAL (t), flags);
1028 OB_PUTS ("::");
1029 OB_PUTID (DECL_NAME (t));
1030 break;
1032 default:
1033 sorry ("`%s' not supported by dump_decl",
1034 tree_code_name[(int) TREE_CODE (t)]);
1035 /* Fallthrough to error. */
1037 case ERROR_MARK:
1038 OB_PUTS ("{declaration error}");
1039 break;
1043 /* Dump a template declaration T under control of FLAGS. This means the
1044 'template <...> leaders plus the 'class X' or 'void fn(...)' part. */
1046 static void
1047 dump_template_decl (t, flags)
1048 tree t;
1049 enum tree_string_flags flags;
1051 tree orig_parms = DECL_TEMPLATE_PARMS (t);
1052 tree parms;
1053 int i;
1055 if (flags & TS_TEMPLATE_PREFIX)
1057 for (parms = orig_parms = nreverse (orig_parms);
1058 parms;
1059 parms = TREE_CHAIN (parms))
1061 tree inner_parms = INNERMOST_TEMPLATE_PARMS (parms);
1062 int len = TREE_VEC_LENGTH (inner_parms);
1064 OB_PUTS ("template <");
1065 for (i = 0; i < len; i++)
1067 if (i)
1068 OB_PUTS (", ");
1069 dump_template_parameter (TREE_VEC_ELT (inner_parms, i), flags);
1071 OB_END_TEMPLATE_ID ();
1072 OB_PUTC (' ');
1074 nreverse(orig_parms);
1075 /* If we've shown the template<args> prefix, we'd better show the
1076 decl's type too. */
1077 flags |= TS_DECL_TYPE;
1079 if (TREE_CODE (DECL_TEMPLATE_RESULT (t)) == TYPE_DECL)
1080 dump_type (TREE_TYPE (t),
1081 ((flags & ~TS_AGGR_TAGS) | TS_TEMPLATE_PLAIN
1082 | (flags & TS_DECL_TYPE ? TS_AGGR_TAGS : 0)));
1083 else if (TREE_CODE (DECL_TEMPLATE_RESULT (t)) == VAR_DECL)
1084 dump_decl (DECL_TEMPLATE_RESULT (t), flags | TS_TEMPLATE_PLAIN);
1085 else if (TREE_TYPE (t) == NULL_TREE)
1086 my_friendly_abort (353);
1087 else
1088 switch (NEXT_CODE (t))
1090 case METHOD_TYPE:
1091 case FUNCTION_TYPE:
1092 dump_function_decl (t, flags | TS_TEMPLATE_PLAIN);
1093 break;
1094 default:
1095 /* This case can occur with some illegal code. */
1096 dump_type (TREE_TYPE (t),
1097 (flags & ~TS_AGGR_TAGS) | TS_TEMPLATE_PLAIN
1098 | (flags & TS_DECL_TYPE ? TS_AGGR_TAGS : 0));
1102 /* Pretty print a function decl. There are several ways we want to print a
1103 function declaration. The TS_FUNC bits in FLAGS tells us how to behave.
1104 As cp_error can only apply the '#' flag once to give 0 and 1 for V, there
1105 is %D which doesn't print the throw specs, and %F which does. */
1107 static void
1108 dump_function_decl (t, flags)
1109 tree t;
1110 enum tree_string_flags flags;
1112 tree fntype;
1113 tree parmtypes;
1114 tree cname = NULL_TREE;
1115 tree template_args = NULL_TREE;
1116 tree template_parms = NULL_TREE;
1117 int show_return = !(flags & TS_FUNC_NORETURN) && (flags & TS_DECL_TYPE);
1119 if (TREE_CODE (t) == TEMPLATE_DECL)
1120 t = DECL_TEMPLATE_RESULT (t);
1122 /* Pretty print template instantiations only. */
1123 if (DECL_USE_TEMPLATE (t) && DECL_TEMPLATE_INFO (t))
1125 template_args = DECL_TI_ARGS (t);
1126 t = most_general_template (t);
1127 if (TREE_CODE (t) == TEMPLATE_DECL)
1128 template_parms = DECL_TEMPLATE_PARMS (t);
1131 fntype = TREE_TYPE (t);
1132 parmtypes = TYPE_ARG_TYPES (fntype);
1134 /* Friends have DECL_CLASS_CONTEXT set, but not DECL_CONTEXT. */
1135 if (DECL_CLASS_SCOPE_P (t))
1136 cname = DECL_CLASS_CONTEXT (t);
1137 /* this is for partially instantiated template methods */
1138 else if (TREE_CODE (fntype) == METHOD_TYPE)
1139 cname = TREE_TYPE (TREE_VALUE (parmtypes));
1141 if (!(flags & TS_DECORATE))
1142 /* OK */;
1143 else if (DECL_STATIC_FUNCTION_P (t))
1144 OB_PUTS ("static ");
1145 else if (TYPE_POLYMORPHIC_P (t))
1146 OB_PUTS ("virtual ");
1148 /* Print the return type? */
1149 if (show_return)
1150 show_return = !DECL_CONV_FN_P (t) && !DECL_CONSTRUCTOR_P (t)
1151 && !DECL_DESTRUCTOR_P (t);
1152 if (show_return)
1154 if (dump_type_prefix (TREE_TYPE (fntype), flags) != none)
1155 OB_PUTC (' ');
1158 /* Print the function name. */
1159 if (cname)
1161 dump_type (cname, flags);
1162 OB_PUTS ("::");
1164 else
1165 dump_scope (CP_DECL_CONTEXT (t), flags);
1167 dump_function_name (t, flags);
1169 if (!(flags & TS_DECL_TYPE))
1170 return;
1171 if (TREE_CODE (fntype) == METHOD_TYPE && parmtypes)
1172 /* Skip "this" parameter. */
1173 parmtypes = TREE_CHAIN (parmtypes);
1175 if (DECL_DESTRUCTOR_P (t) || DECL_CONSTRUCTOR_FOR_VBASE_P (t))
1176 /* Skip past "in_charge" identifier. */
1177 parmtypes = TREE_CHAIN (parmtypes);
1179 dump_parameters (parmtypes, flags);
1181 if (show_return)
1182 dump_type_suffix (TREE_TYPE (fntype), flags);
1184 if (TREE_CODE (fntype) == METHOD_TYPE)
1185 dump_qualifiers (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype))),
1186 before);
1188 if (flags & TS_FUNC_THROW)
1189 dump_exception_spec (TYPE_RAISES_EXCEPTIONS (fntype), flags);
1191 /* If T is a template instantiation, dump the parameter binding. */
1192 if (template_parms != NULL_TREE && template_args != NULL_TREE)
1194 OB_PUTS (" [with ");
1195 dump_template_bindings (template_parms, template_args);
1196 OB_PUTC (']');
1200 /* Print a parameter list. If this is for a member function, the
1201 member object ptr (and any other hidden args) should have
1202 already been removed. */
1204 static void
1205 dump_parameters (parmtypes, flags)
1206 tree parmtypes;
1207 enum tree_string_flags flags;
1209 int first;
1210 OB_PUTS (" (");
1212 for (first = 1; parmtypes != void_list_node;
1213 parmtypes = TREE_CHAIN (parmtypes))
1215 if (!first)
1216 OB_PUTS (", ");
1217 first = 0;
1218 if (!parmtypes)
1220 OB_PUTS ("...");
1221 break;
1223 dump_type (TREE_VALUE (parmtypes), flags);
1225 if ((flags & TS_PARM_DEFAULTS) && TREE_PURPOSE (parmtypes))
1227 OB_PUTS (" = ");
1228 dump_expr (TREE_PURPOSE (parmtypes), flags | TS_EXPR_PARENS);
1232 OB_PUTC (')');
1235 /* Print an exception specification. T is the exception specification. */
1237 static void
1238 dump_exception_spec (t, flags)
1239 tree t;
1240 enum tree_string_flags flags;
1242 if (t)
1244 OB_PUTS (" throw (");
1245 if (TREE_VALUE (t) != NULL_TREE)
1246 while (1)
1248 dump_type (TREE_VALUE (t), flags);
1249 t = TREE_CHAIN (t);
1250 if (!t)
1251 break;
1252 OB_PUTS (", ");
1254 OB_PUTC (')');
1258 /* Handle the function name for a FUNCTION_DECL node, grokking operators
1259 and destructors properly. */
1261 static void
1262 dump_function_name (t, flags)
1263 tree t;
1264 enum tree_string_flags flags;
1266 tree name = DECL_NAME (t);
1268 if (DECL_DESTRUCTOR_P (t))
1270 OB_PUTC ('~');
1271 dump_decl (name, TS_PLAIN);
1273 else if (DECL_CONV_FN_P (t))
1275 /* This cannot use the hack that the operator's return
1276 type is stashed off of its name because it may be
1277 used for error reporting. In the case of conflicting
1278 declarations, both will have the same name, yet
1279 the types will be different, hence the TREE_TYPE field
1280 of the first name will be clobbered by the second. */
1281 OB_PUTS ("operator ");
1282 dump_type (TREE_TYPE (TREE_TYPE (t)), flags);
1284 else if (IDENTIFIER_OPNAME_P (name))
1286 const char *name_string = operator_name_string (name);
1287 OB_PUTS ("operator");
1288 if (ISALPHA (name_string[0]))
1289 OB_PUTC (' ');
1290 OB_PUTCP (name_string);
1292 else
1293 dump_decl (name, flags);
1295 if (DECL_LANG_SPECIFIC (t) && DECL_TEMPLATE_INFO (t)
1296 && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t)
1297 && (DECL_TEMPLATE_SPECIALIZATION (t)
1298 || TREE_CODE (DECL_TI_TEMPLATE (t)) != TEMPLATE_DECL
1299 || DECL_TEMPLATE_SPECIALIZATION (DECL_TI_TEMPLATE (t))
1300 || PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t))))
1301 dump_template_parms (DECL_TEMPLATE_INFO (t), !DECL_USE_TEMPLATE (t), flags);
1304 /* Dump the template parameters from the template info INFO under control of
1305 FLAGS. PRIMARY indicates whether this is a primary template decl, or
1306 specialization (partial or complete). For partial specializations we show
1307 the specialized parameter values. For a primary template we show no
1308 decoration. */
1310 static void
1311 dump_template_parms (info, primary, flags)
1312 tree info;
1313 int primary;
1314 enum tree_string_flags flags;
1316 tree args = info ? TI_ARGS (info) : NULL_TREE;
1318 if (primary && flags & TS_TEMPLATE_PLAIN)
1319 return;
1320 flags &= ~(TS_AGGR_TAGS | TS_TEMPLATE_PLAIN);
1321 OB_PUTC ('<');
1323 /* Be careful only to print things when we have them, so as not
1324 to crash producing error messages. */
1325 if (args && !primary)
1327 int len = 0;
1328 int ix = 0;
1329 int need_comma = 0;
1331 if (TREE_CODE (args) == TREE_VEC)
1333 if (TREE_VEC_LENGTH (args) > 0
1334 && TREE_CODE (TREE_VEC_ELT (args, 0)) == TREE_VEC)
1335 args = TREE_VEC_ELT (args, TREE_VEC_LENGTH (args) - 1);
1337 len = TREE_VEC_LENGTH (args);
1339 else if (TREE_CODE (args) == TREE_LIST)
1340 len = -1;
1341 while (ix != len && args)
1343 tree arg;
1344 if (len >= 0)
1346 arg = TREE_VEC_ELT (args, ix);
1347 ix++;
1349 else
1351 arg = TREE_VALUE (args);
1352 args = TREE_CHAIN (args);
1354 if (need_comma)
1355 OB_PUTS (", ");
1357 if (!arg)
1358 OB_PUTS ("{template parameter error}");
1359 else
1360 dump_template_argument (arg, flags);
1361 need_comma = 1;
1364 else if (primary)
1366 tree tpl = TI_TEMPLATE (info);
1367 tree parms = DECL_TEMPLATE_PARMS (tpl);
1368 int len, ix;
1370 parms = TREE_CODE (parms) == TREE_LIST ? TREE_VALUE (parms) : NULL_TREE;
1371 len = parms ? TREE_VEC_LENGTH (parms) : 0;
1373 for (ix = 0; ix != len; ix++)
1375 tree parm = TREE_VALUE (TREE_VEC_ELT (parms, ix));
1377 if (ix)
1378 OB_PUTS (", ");
1380 dump_decl (parm, flags & ~TS_DECL_TYPE);
1383 OB_END_TEMPLATE_ID ();
1386 static void
1387 dump_char (c)
1388 int c;
1390 switch (c)
1392 case TARGET_NEWLINE:
1393 OB_PUTS ("\\n");
1394 break;
1395 case TARGET_TAB:
1396 OB_PUTS ("\\t");
1397 break;
1398 case TARGET_VT:
1399 OB_PUTS ("\\v");
1400 break;
1401 case TARGET_BS:
1402 OB_PUTS ("\\b");
1403 break;
1404 case TARGET_CR:
1405 OB_PUTS ("\\r");
1406 break;
1407 case TARGET_FF:
1408 OB_PUTS ("\\f");
1409 break;
1410 case TARGET_BELL:
1411 OB_PUTS ("\\a");
1412 break;
1413 case '\\':
1414 OB_PUTS ("\\\\");
1415 break;
1416 case '\'':
1417 OB_PUTS ("\\'");
1418 break;
1419 case '\"':
1420 OB_PUTS ("\\\"");
1421 break;
1422 default:
1423 if (ISPRINT (c))
1424 OB_PUTC (c);
1425 else
1427 sprintf (digit_buffer, "\\%03o", (int) c);
1428 OB_PUTCP (digit_buffer);
1433 /* Print out a list of initializers (subr of dump_expr) */
1435 static void
1436 dump_expr_list (l, flags)
1437 tree l;
1438 enum tree_string_flags flags;
1440 while (l)
1442 dump_expr (TREE_VALUE (l), flags | TS_EXPR_PARENS);
1443 l = TREE_CHAIN (l);
1444 if (l)
1445 OB_PUTS (", ");
1449 /* Print out an expression E under control of FLAGS. */
1451 static void
1452 dump_expr (t, flags)
1453 tree t;
1454 enum tree_string_flags flags;
1456 switch (TREE_CODE (t))
1458 case VAR_DECL:
1459 case PARM_DECL:
1460 case FIELD_DECL:
1461 case CONST_DECL:
1462 case FUNCTION_DECL:
1463 case TEMPLATE_DECL:
1464 case NAMESPACE_DECL:
1465 case OVERLOAD:
1466 dump_decl (t, flags & ~TS_DECL_TYPE);
1467 break;
1469 case INTEGER_CST:
1471 tree type = TREE_TYPE (t);
1472 my_friendly_assert (type != 0, 81);
1474 /* If it's an enum, output its tag, rather than its value. */
1475 if (TREE_CODE (type) == ENUMERAL_TYPE)
1477 const char *p = enum_name_string (t, type);
1478 OB_PUTCP (p);
1480 else if (type == boolean_type_node)
1482 if (t == boolean_false_node
1483 || (TREE_INT_CST_LOW (t) == 0
1484 && TREE_INT_CST_HIGH (t) == 0))
1485 OB_PUTS ("false");
1486 else if (t == boolean_true_node)
1487 OB_PUTS ("true");
1489 else if (type == char_type_node)
1491 OB_PUTC ('\'');
1492 dump_char (TREE_INT_CST_LOW (t));
1493 OB_PUTC ('\'');
1495 else if (TREE_INT_CST_HIGH (t)
1496 != (TREE_INT_CST_LOW (t) >> (HOST_BITS_PER_WIDE_INT - 1)))
1498 tree val = t;
1499 if (TREE_INT_CST_HIGH (val) < 0)
1501 OB_PUTC ('-');
1502 val = build_int_2 (~TREE_INT_CST_LOW (val),
1503 -TREE_INT_CST_HIGH (val));
1505 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
1506 systems? */
1508 static char format[10]; /* "%x%09999x\0" */
1509 if (!format[0])
1510 sprintf (format, "%%x%%0%dx", HOST_BITS_PER_INT / 4);
1511 sprintf (digit_buffer, format, TREE_INT_CST_HIGH (val),
1512 TREE_INT_CST_LOW (val));
1513 OB_PUTCP (digit_buffer);
1516 else
1517 OB_PUTI (TREE_INT_CST_LOW (t));
1519 break;
1521 case REAL_CST:
1522 #ifndef REAL_IS_NOT_DOUBLE
1523 sprintf (digit_buffer, "%g", TREE_REAL_CST (t));
1524 #else
1526 const unsigned char *p = (const unsigned char *) &TREE_REAL_CST (t);
1527 size_t i;
1528 strcpy (digit_buffer, "0x");
1529 for (i = 0; i < sizeof TREE_REAL_CST (t); i++)
1530 sprintf (digit_buffer + 2 + 2*i, "%02x", *p++);
1532 #endif
1533 OB_PUTCP (digit_buffer);
1534 break;
1536 case PTRMEM_CST:
1537 OB_PUTC ('&');
1538 dump_type (PTRMEM_CST_CLASS (t), flags);
1539 OB_PUTS ("::");
1540 OB_PUTID (DECL_NAME (PTRMEM_CST_MEMBER (t)));
1541 break;
1543 case STRING_CST:
1545 const char *p = TREE_STRING_POINTER (t);
1546 int len = TREE_STRING_LENGTH (t) - 1;
1547 int i;
1549 OB_PUTC ('\"');
1550 for (i = 0; i < len; i++)
1551 dump_char (p[i]);
1552 OB_PUTC ('\"');
1554 break;
1556 case COMPOUND_EXPR:
1557 OB_PUTC ('(');
1558 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
1559 OB_PUTS (", ");
1560 dump_expr (TREE_OPERAND (t, 1), flags | TS_EXPR_PARENS);
1561 OB_PUTC (')');
1562 break;
1564 case COND_EXPR:
1565 OB_PUTC ('(');
1566 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
1567 OB_PUTS (" ? ");
1568 dump_expr (TREE_OPERAND (t, 1), flags | TS_EXPR_PARENS);
1569 OB_PUTS (" : ");
1570 dump_expr (TREE_OPERAND (t, 2), flags | TS_EXPR_PARENS);
1571 OB_PUTC (')');
1572 break;
1574 case SAVE_EXPR:
1575 if (TREE_HAS_CONSTRUCTOR (t))
1577 OB_PUTS ("new ");
1578 dump_type (TREE_TYPE (TREE_TYPE (t)), flags);
1580 else
1582 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
1584 break;
1586 case AGGR_INIT_EXPR:
1588 tree fn = NULL_TREE;
1590 if (TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR)
1591 fn = TREE_OPERAND (TREE_OPERAND (t, 0), 0);
1593 if (fn && TREE_CODE (fn) == FUNCTION_DECL)
1595 if (DECL_CONSTRUCTOR_P (fn))
1596 OB_PUTID (TYPE_IDENTIFIER (TREE_TYPE (t)));
1597 else
1598 dump_decl (fn, 0);
1600 else
1601 dump_expr (TREE_OPERAND (t, 0), 0);
1603 OB_PUTC ('(');
1604 if (TREE_OPERAND (t, 1))
1605 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)), flags);
1606 OB_PUTC (')');
1607 break;
1609 case CALL_EXPR:
1611 tree fn = TREE_OPERAND (t, 0);
1612 tree args = TREE_OPERAND (t, 1);
1614 if (TREE_CODE (fn) == ADDR_EXPR)
1615 fn = TREE_OPERAND (fn, 0);
1617 if (TREE_TYPE (fn) != NULL_TREE && NEXT_CODE (fn) == METHOD_TYPE)
1619 tree ob = TREE_VALUE (args);
1620 if (TREE_CODE (ob) == ADDR_EXPR)
1622 dump_expr (TREE_OPERAND (ob, 0), flags | TS_EXPR_PARENS);
1623 OB_PUTC ('.');
1625 else if (TREE_CODE (ob) != PARM_DECL
1626 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
1628 dump_expr (ob, flags | TS_EXPR_PARENS);
1629 OB_PUTS ("->");
1631 args = TREE_CHAIN (args);
1633 dump_expr (fn, flags | TS_EXPR_PARENS);
1634 OB_PUTC ('(');
1635 dump_expr_list (args, flags);
1636 OB_PUTC (')');
1638 break;
1640 case NEW_EXPR:
1642 tree type = TREE_OPERAND (t, 1);
1643 if (NEW_EXPR_USE_GLOBAL (t))
1644 OB_PUTS ("::");
1645 OB_PUTS ("new ");
1646 if (TREE_OPERAND (t, 0))
1648 OB_PUTC ('(');
1649 dump_expr_list (TREE_OPERAND (t, 0), flags);
1650 OB_PUTS (") ");
1652 if (TREE_CODE (type) == ARRAY_REF)
1653 type = build_cplus_array_type
1654 (TREE_OPERAND (type, 0),
1655 build_index_type (size_binop (MINUS_EXPR, TREE_OPERAND (type, 1),
1656 integer_one_node)));
1657 dump_type (type, flags);
1658 if (TREE_OPERAND (t, 2))
1660 OB_PUTC ('(');
1661 dump_expr_list (TREE_OPERAND (t, 2), flags);
1662 OB_PUTC (')');
1665 break;
1667 case TARGET_EXPR:
1668 /* Note that this only works for G++ target exprs. If somebody
1669 builds a general TARGET_EXPR, there's no way to represent that
1670 it initializes anything other that the parameter slot for the
1671 default argument. Note we may have cleared out the first
1672 operand in expand_expr, so don't go killing ourselves. */
1673 if (TREE_OPERAND (t, 1))
1674 dump_expr (TREE_OPERAND (t, 1), flags | TS_EXPR_PARENS);
1675 break;
1677 case INIT_EXPR:
1678 case MODIFY_EXPR:
1679 case PLUS_EXPR:
1680 case MINUS_EXPR:
1681 case MULT_EXPR:
1682 case TRUNC_DIV_EXPR:
1683 case TRUNC_MOD_EXPR:
1684 case MIN_EXPR:
1685 case MAX_EXPR:
1686 case LSHIFT_EXPR:
1687 case RSHIFT_EXPR:
1688 case BIT_IOR_EXPR:
1689 case BIT_XOR_EXPR:
1690 case BIT_AND_EXPR:
1691 case BIT_ANDTC_EXPR:
1692 case TRUTH_ANDIF_EXPR:
1693 case TRUTH_ORIF_EXPR:
1694 case LT_EXPR:
1695 case LE_EXPR:
1696 case GT_EXPR:
1697 case GE_EXPR:
1698 case EQ_EXPR:
1699 case NE_EXPR:
1700 case EXACT_DIV_EXPR:
1701 dump_binary_op (opname_tab[(int) TREE_CODE (t)], t, flags);
1702 break;
1704 case CEIL_DIV_EXPR:
1705 case FLOOR_DIV_EXPR:
1706 case ROUND_DIV_EXPR:
1707 dump_binary_op ("/", t, flags);
1708 break;
1710 case CEIL_MOD_EXPR:
1711 case FLOOR_MOD_EXPR:
1712 case ROUND_MOD_EXPR:
1713 dump_binary_op ("%", t, flags);
1714 break;
1716 case COMPONENT_REF:
1718 tree ob = TREE_OPERAND (t, 0);
1719 if (TREE_CODE (ob) == INDIRECT_REF)
1721 ob = TREE_OPERAND (ob, 0);
1722 if (TREE_CODE (ob) != PARM_DECL
1723 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
1725 dump_expr (ob, flags | TS_EXPR_PARENS);
1726 OB_PUTS ("->");
1729 else
1731 dump_expr (ob, flags | TS_EXPR_PARENS);
1732 OB_PUTC ('.');
1734 dump_expr (TREE_OPERAND (t, 1), flags & ~TS_EXPR_PARENS);
1736 break;
1738 case ARRAY_REF:
1739 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
1740 OB_PUTC ('[');
1741 dump_expr (TREE_OPERAND (t, 1), flags | TS_EXPR_PARENS);
1742 OB_PUTC (']');
1743 break;
1745 case CONVERT_EXPR:
1746 if (same_type_p (TREE_TYPE (t), void_type_node))
1748 OB_PUTS ("(void)");
1749 dump_expr (TREE_OPERAND (t, 0), flags);
1751 else
1752 dump_unary_op ("+", t, flags);
1753 break;
1755 case ADDR_EXPR:
1756 if (TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
1757 || TREE_CODE (TREE_OPERAND (t, 0)) == STRING_CST)
1758 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
1759 else
1760 dump_unary_op ("&", t, flags);
1761 break;
1763 case INDIRECT_REF:
1764 if (TREE_HAS_CONSTRUCTOR (t))
1766 t = TREE_OPERAND (t, 0);
1767 my_friendly_assert (TREE_CODE (t) == CALL_EXPR, 237);
1768 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
1769 OB_PUTC ('(');
1770 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)), flags);
1771 OB_PUTC (')');
1773 else
1775 if (TREE_OPERAND (t,0) != NULL_TREE
1776 && TREE_TYPE (TREE_OPERAND (t, 0))
1777 && NEXT_CODE (TREE_OPERAND (t, 0)) == REFERENCE_TYPE)
1778 dump_expr (TREE_OPERAND (t, 0), flags);
1779 else
1780 dump_unary_op ("*", t, flags);
1782 break;
1784 case NEGATE_EXPR:
1785 case BIT_NOT_EXPR:
1786 case TRUTH_NOT_EXPR:
1787 case PREDECREMENT_EXPR:
1788 case PREINCREMENT_EXPR:
1789 dump_unary_op (opname_tab [(int)TREE_CODE (t)], t, flags);
1790 break;
1792 case POSTDECREMENT_EXPR:
1793 case POSTINCREMENT_EXPR:
1794 OB_PUTC ('(');
1795 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
1796 OB_PUTCP (opname_tab[(int)TREE_CODE (t)]);
1797 OB_PUTC (')');
1798 break;
1800 case NON_LVALUE_EXPR:
1801 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
1802 should be another level of INDIRECT_REF so that I don't have to do
1803 this. */
1804 if (TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == POINTER_TYPE)
1806 tree next = TREE_TYPE (TREE_TYPE (t));
1808 while (TREE_CODE (next) == POINTER_TYPE)
1809 next = TREE_TYPE (next);
1811 if (TREE_CODE (next) == FUNCTION_TYPE)
1813 if (flags & TS_EXPR_PARENS)
1814 OB_PUTC ('(');
1815 OB_PUTC ('*');
1816 dump_expr (TREE_OPERAND (t, 0), flags & ~TS_EXPR_PARENS);
1817 if (flags & TS_EXPR_PARENS)
1818 OB_PUTC (')');
1819 break;
1821 /* else FALLTHRU */
1823 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
1824 break;
1826 case NOP_EXPR:
1827 dump_expr (TREE_OPERAND (t, 0), flags);
1828 break;
1830 case EXPR_WITH_FILE_LOCATION:
1831 dump_expr (EXPR_WFL_NODE (t), flags);
1832 break;
1834 case CONSTRUCTOR:
1835 if (TREE_TYPE (t) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t)))
1837 tree idx = build_component_ref (t, index_identifier, NULL_TREE, 0);
1839 if (integer_all_onesp (idx))
1841 tree pfn = PFN_FROM_PTRMEMFUNC (t);
1842 dump_unary_op ("&", pfn, flags | TS_EXPR_PARENS);
1843 break;
1845 else if (TREE_CODE (idx) == INTEGER_CST
1846 && tree_int_cst_equal (idx, integer_zero_node))
1848 /* A NULL pointer-to-member constant. */
1849 OB_PUTS ("((");
1850 dump_type (TREE_TYPE (t), flags);
1851 OB_PUTS (") 0)");
1852 break;
1854 else if (TREE_CODE (idx) == INTEGER_CST
1855 && TREE_INT_CST_HIGH (idx) == 0)
1857 tree virtuals;
1858 unsigned HOST_WIDE_INT n;
1860 t = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t)));
1861 t = TYPE_METHOD_BASETYPE (t);
1862 virtuals = TYPE_BINFO_VIRTUALS (TYPE_MAIN_VARIANT (t));
1864 n = TREE_INT_CST_LOW (idx);
1866 /* Map vtable index back one, to allow for the null pointer to
1867 member. */
1868 --n;
1870 while (n > 0 && virtuals)
1872 --n;
1873 virtuals = TREE_CHAIN (virtuals);
1875 if (virtuals)
1877 dump_expr (TREE_VALUE (virtuals),
1878 flags | TS_EXPR_PARENS);
1879 break;
1883 OB_PUTC ('{');
1884 dump_expr_list (CONSTRUCTOR_ELTS (t), flags);
1885 OB_PUTC ('}');
1886 break;
1888 case OFFSET_REF:
1890 tree ob = TREE_OPERAND (t, 0);
1891 if (is_dummy_object (ob))
1893 t = TREE_OPERAND (t, 1);
1894 if (TREE_CODE (t) == FUNCTION_DECL)
1895 /* A::f */
1896 dump_expr (t, flags | TS_EXPR_PARENS);
1897 else if (BASELINK_P (t))
1898 dump_expr (OVL_CURRENT (TREE_VALUE (t)), flags | TS_EXPR_PARENS);
1899 else
1900 dump_decl (t, flags);
1902 else
1904 if (TREE_CODE (ob) == INDIRECT_REF)
1906 dump_expr (TREE_OPERAND (ob, 0), flags | TS_EXPR_PARENS);
1907 OB_PUTS (" ->* ");
1909 else
1911 dump_expr (ob, flags | TS_EXPR_PARENS);
1912 OB_PUTS (" .* ");
1914 dump_expr (TREE_OPERAND (t, 1), flags | TS_EXPR_PARENS);
1916 break;
1919 case TEMPLATE_PARM_INDEX:
1920 dump_decl (TEMPLATE_PARM_DECL (t), flags & ~TS_DECL_TYPE);
1921 break;
1923 case IDENTIFIER_NODE:
1924 OB_PUTID (t);
1925 break;
1927 case SCOPE_REF:
1928 dump_type (TREE_OPERAND (t, 0), flags);
1929 OB_PUTS ("::");
1930 dump_expr (TREE_OPERAND (t, 1), flags | TS_EXPR_PARENS);
1931 break;
1933 case CAST_EXPR:
1934 if (TREE_OPERAND (t, 0) == NULL_TREE
1935 || TREE_CHAIN (TREE_OPERAND (t, 0)))
1937 dump_type (TREE_TYPE (t), flags);
1938 OB_PUTC ('(');
1939 dump_expr_list (TREE_OPERAND (t, 0), flags);
1940 OB_PUTC (')');
1942 else
1944 OB_PUTC ('(');
1945 dump_type (TREE_TYPE (t), flags);
1946 OB_PUTC (')');
1947 OB_PUTC ('(');
1948 dump_expr_list (TREE_OPERAND (t, 0), flags);
1949 OB_PUTC (')');
1951 break;
1953 case LOOKUP_EXPR:
1954 OB_PUTID (TREE_OPERAND (t, 0));
1955 break;
1957 case ARROW_EXPR:
1958 dump_expr (TREE_OPERAND (t, 0), flags);
1959 OB_PUTS ("->");
1960 break;
1962 case SIZEOF_EXPR:
1963 case ALIGNOF_EXPR:
1964 if (TREE_CODE (t) == SIZEOF_EXPR)
1965 OB_PUTS ("sizeof (");
1966 else
1968 my_friendly_assert (TREE_CODE (t) == ALIGNOF_EXPR, 0);
1969 OB_PUTS ("__alignof__ (");
1971 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t, 0))) == 't')
1972 dump_type (TREE_OPERAND (t, 0), flags);
1973 else
1974 dump_unary_op ("*", t, flags | TS_EXPR_PARENS);
1975 OB_PUTC (')');
1976 break;
1978 case DEFAULT_ARG:
1979 OB_PUTS ("{unparsed}");
1980 break;
1982 case TRY_CATCH_EXPR:
1983 case WITH_CLEANUP_EXPR:
1984 case CLEANUP_POINT_EXPR:
1985 dump_expr (TREE_OPERAND (t, 0), flags);
1986 break;
1988 case PSEUDO_DTOR_EXPR:
1989 dump_expr (TREE_OPERAND (t, 2), flags);
1990 OB_PUTS (".");
1991 dump_type (TREE_OPERAND (t, 0), flags);
1992 OB_PUTS ("::~");
1993 dump_type (TREE_OPERAND (t, 1), flags);
1994 break;
1996 case TEMPLATE_ID_EXPR:
1997 dump_decl (t, flags);
1998 break;
2000 case STMT_EXPR:
2001 /* We don't yet have a way of dumping statements in a
2002 human-readable format. */
2003 OB_PUTS ("{ ... }");
2004 break;
2006 case BIND_EXPR:
2007 OB_PUTS ("{ ");
2008 dump_expr (TREE_OPERAND (t, 1), flags & ~TS_EXPR_PARENS);
2009 OB_PUTS ("} ");
2010 break;
2012 case LOOP_EXPR:
2013 OB_PUTS ("while (1) { ");
2014 dump_expr (TREE_OPERAND (t, 0), flags & ~TS_EXPR_PARENS);
2015 OB_PUTS ("} ");
2016 break;
2018 case EXIT_EXPR:
2019 OB_PUTS ("if (");
2020 dump_expr (TREE_OPERAND (t, 0), flags & ~TS_EXPR_PARENS);
2021 OB_PUTS (") break; ");
2022 break;
2024 case TREE_LIST:
2025 if (TREE_VALUE (t) && TREE_CODE (TREE_VALUE (t)) == FUNCTION_DECL)
2027 OB_PUTID (DECL_NAME (TREE_VALUE (t)));
2028 break;
2030 /* else fall through */
2032 /* This list is incomplete, but should suffice for now.
2033 It is very important that `sorry' does not call
2034 `report_error_function'. That could cause an infinite loop. */
2035 default:
2036 sorry ("`%s' not supported by dump_expr",
2037 tree_code_name[(int) TREE_CODE (t)]);
2039 /* fall through to ERROR_MARK... */
2040 case ERROR_MARK:
2041 OB_PUTCP ("{expression error}");
2042 break;
2046 static void
2047 dump_binary_op (opstring, t, flags)
2048 const char *opstring;
2049 tree t;
2050 enum tree_string_flags flags;
2052 OB_PUTC ('(');
2053 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
2054 OB_PUTC (' ');
2055 if (opstring)
2056 OB_PUTCP (opstring);
2057 else
2058 OB_PUTS ("<unknown operator>");
2059 OB_PUTC (' ');
2060 dump_expr (TREE_OPERAND (t, 1), flags | TS_EXPR_PARENS);
2061 OB_PUTC (')');
2064 static void
2065 dump_unary_op (opstring, t, flags)
2066 const char *opstring;
2067 tree t;
2068 enum tree_string_flags flags;
2070 if (flags & TS_EXPR_PARENS)
2071 OB_PUTC ('(');
2072 OB_PUTCP (opstring);
2073 dump_expr (TREE_OPERAND (t, 0), flags & ~TS_EXPR_PARENS);
2074 if (flags & TS_EXPR_PARENS)
2075 OB_PUTC (')');
2078 /* Exported interface to stringifying types, exprs and decls under TS_*
2079 control. */
2081 const char *
2082 type_as_string (typ, flags)
2083 tree typ;
2084 enum tree_string_flags flags;
2086 OB_INIT ();
2088 dump_type (typ, flags);
2090 OB_FINISH ();
2092 return (char *)obstack_base (&scratch_obstack);
2095 const char *
2096 expr_as_string (decl, flags)
2097 tree decl;
2098 enum tree_string_flags flags;
2100 OB_INIT ();
2102 dump_expr (decl, flags);
2104 OB_FINISH ();
2106 return (char *)obstack_base (&scratch_obstack);
2109 const char *
2110 decl_as_string (decl, flags)
2111 tree decl;
2112 enum tree_string_flags flags;
2114 OB_INIT ();
2116 dump_decl (decl, flags);
2118 OB_FINISH ();
2120 return (char *)obstack_base (&scratch_obstack);
2123 const char *
2124 context_as_string (context, flags)
2125 tree context;
2126 enum tree_string_flags flags;
2128 OB_INIT ();
2130 dump_scope (context, flags);
2132 OB_FINISH ();
2134 return (char *)obstack_base (&scratch_obstack);
2137 /* Generate the three forms of printable names for lang_printable_name. */
2139 const char *
2140 lang_decl_name (decl, v)
2141 tree decl;
2142 int v;
2144 if (v >= 2)
2145 return decl_as_string (decl, TS_DECL_TYPE);
2147 OB_INIT ();
2149 if (v == 1 && DECL_CLASS_SCOPE_P (decl))
2151 tree cname;
2152 if (TREE_CODE (decl) == FUNCTION_DECL)
2153 cname = DECL_CLASS_CONTEXT (decl);
2154 else
2155 cname = DECL_CONTEXT (decl);
2156 dump_type (cname, TS_PLAIN);
2157 OB_PUTS ("::");
2160 if (TREE_CODE (decl) == FUNCTION_DECL)
2161 dump_function_name (decl, TS_PLAIN);
2162 else
2163 dump_decl (DECL_NAME (decl), TS_PLAIN);
2165 OB_FINISH ();
2167 return (char *)obstack_base (&scratch_obstack);
2170 const char *
2171 cp_file_of (t)
2172 tree t;
2174 if (TREE_CODE (t) == PARM_DECL && DECL_CONTEXT (t))
2175 return DECL_SOURCE_FILE (DECL_CONTEXT (t));
2176 else if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
2177 return DECL_SOURCE_FILE (TYPE_MAIN_DECL (t));
2178 else if (TREE_CODE (t) == OVERLOAD)
2179 return DECL_SOURCE_FILE (OVL_FUNCTION (t));
2180 else
2181 return DECL_SOURCE_FILE (t);
2185 cp_line_of (t)
2186 tree t;
2188 int line = 0;
2189 if (TREE_CODE (t) == PARM_DECL && DECL_CONTEXT (t))
2190 line = DECL_SOURCE_LINE (DECL_CONTEXT (t));
2191 if (TREE_CODE (t) == TYPE_DECL && DECL_ARTIFICIAL (t)
2192 && TYPE_MAIN_DECL (TREE_TYPE (t)))
2193 t = TREE_TYPE (t);
2195 if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
2196 line = DECL_SOURCE_LINE (TYPE_MAIN_DECL (t));
2197 else if (TREE_CODE (t) == OVERLOAD)
2198 line = DECL_SOURCE_LINE (OVL_FUNCTION (t));
2199 else
2200 line = DECL_SOURCE_LINE (t);
2202 if (line == 0)
2203 return lineno;
2205 return line;
2208 /* Now the interfaces from cp_error et al to dump_type et al. Each takes an
2209 on/off VERBOSE flag and supply the appropriate TS_ flags to a dump_
2210 function. */
2212 static const char *
2213 decl_to_string (decl, verbose)
2214 tree decl;
2215 int verbose;
2217 enum tree_string_flags flags = 0;
2219 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == RECORD_TYPE
2220 || TREE_CODE (decl) == UNION_TYPE || TREE_CODE (decl) == ENUMERAL_TYPE)
2221 flags = TS_AGGR_TAGS;
2222 if (verbose)
2223 flags |= TS_DECL_TYPE | TS_DECORATE | TS_PARM_DEFAULTS;
2224 else if (TREE_CODE (decl) == FUNCTION_DECL)
2225 flags |= TS_DECL_TYPE | TS_FUNC_NORETURN;
2226 flags |= TS_TEMPLATE_PREFIX;
2228 OB_INIT ();
2230 dump_decl (decl, flags);
2232 OB_FINISH ();
2234 return (char *)obstack_base (&scratch_obstack);
2237 static const char *
2238 expr_to_string (decl, verbose)
2239 tree decl;
2240 int verbose ATTRIBUTE_UNUSED;
2242 OB_INIT ();
2244 dump_expr (decl, 0);
2246 OB_FINISH ();
2248 return (char *)obstack_base (&scratch_obstack);
2251 static const char *
2252 fndecl_to_string (fndecl, verbose)
2253 tree fndecl;
2254 int verbose;
2256 enum tree_string_flags flags;
2258 flags = TS_FUNC_THROW | TS_DECL_TYPE;
2259 if (verbose)
2260 flags |= TS_PARM_DEFAULTS;
2261 OB_INIT ();
2263 dump_decl (fndecl, flags);
2265 OB_FINISH ();
2267 return (char *)obstack_base (&scratch_obstack);
2271 static const char *
2272 code_to_string (c, v)
2273 enum tree_code c;
2274 int v ATTRIBUTE_UNUSED;
2276 return tree_code_name [c];
2279 static const char *
2280 language_to_string (c, v)
2281 enum languages c;
2282 int v ATTRIBUTE_UNUSED;
2284 switch (c)
2286 case lang_c:
2287 return "C";
2289 case lang_cplusplus:
2290 return "C++";
2292 case lang_java:
2293 return "Java";
2295 default:
2296 my_friendly_abort (355);
2297 return 0;
2301 /* Return the proper printed version of a parameter to a C++ function. */
2303 static const char *
2304 parm_to_string (p, v)
2305 int p;
2306 int v ATTRIBUTE_UNUSED;
2308 if (p < 0)
2309 return "`this'";
2311 sprintf (digit_buffer, "%d", p+1);
2312 return digit_buffer;
2315 static const char *
2316 op_to_string (p, v)
2317 enum tree_code p;
2318 int v ATTRIBUTE_UNUSED;
2320 static char buf[] = "operator ";
2322 if (p == 0)
2323 return "{unknown}";
2325 strcpy (buf + 8, opname_tab [p]);
2326 return buf;
2329 static const char *
2330 type_to_string (typ, verbose)
2331 tree typ;
2332 int verbose;
2334 enum tree_string_flags flags;
2336 flags = 0;
2337 if (verbose)
2338 flags |= TS_AGGR_TAGS;
2339 flags |= TS_TEMPLATE_PREFIX;
2341 OB_INIT ();
2343 dump_type (typ, flags);
2345 OB_FINISH ();
2347 return (char *)obstack_base (&scratch_obstack);
2350 static const char *
2351 assop_to_string (p, v)
2352 enum tree_code p;
2353 int v ATTRIBUTE_UNUSED;
2355 static char buf[] = "operator ";
2357 if (p == 0)
2358 return "{unknown}";
2360 strcpy (buf + 9, assignop_tab [p]);
2361 return buf;
2364 static const char *
2365 args_to_string (p, verbose)
2366 tree p;
2367 int verbose;
2369 enum tree_string_flags flags = 0;
2370 if (verbose)
2371 flags |= TS_AGGR_TAGS;
2373 if (p == NULL_TREE)
2374 return "";
2376 if (TREE_CODE_CLASS (TREE_CODE (TREE_VALUE (p))) == 't')
2377 return type_as_string (p, flags);
2379 OB_INIT ();
2380 for (; p; p = TREE_CHAIN (p))
2382 if (TREE_VALUE (p) == null_node)
2383 OB_PUTS ("NULL");
2384 else
2385 dump_type (error_type (TREE_VALUE (p)), flags);
2386 if (TREE_CHAIN (p))
2387 OB_PUTS (", ");
2389 OB_FINISH ();
2390 return (char *)obstack_base (&scratch_obstack);
2393 static const char *
2394 cv_to_string (p, v)
2395 tree p;
2396 int v ATTRIBUTE_UNUSED;
2398 OB_INIT ();
2400 dump_qualifiers (p, before);
2402 OB_FINISH ();
2404 return (char *)obstack_base (&scratch_obstack);