1 /* Call-backs for C++ error reporting.
2 This code is non-reentrant.
3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000
4 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
28 #include "diagnostic.h"
30 enum pad { none, before, after };
32 /* These constants can used as bit flags in the process of tree formatting.
34 TFF_PLAIN_IDENTIFER: unqualified part of a name.
35 TFF_NAMESPACE_SCOPE: the complete qualified-id form of a name.
36 TFF_CLASS_SCOPE: if possible, include the class-name part of a
37 qualified-id. This flag may be implied in some circumstances by
39 TFF_SCOPE: the combinaison of the two above.
40 TFF_CHASE_TYPDEF: print the original type-id instead of the typedef-name.
41 TFF_DECL_SPECIFIERS: print decl-specifiers.
42 TFF_CLASS_KEY_OR_ENUM: precede a class-type name (resp. enum name) with
43 a class-key (resp. `enum').
44 TFF_RETURN_TYPE: include function return type.
45 TFF_FUNCTION_DEFAULT_ARGUMENTS: include function default parameter values.
46 TFF_EXCEPTION_SPECIFICATION: show function exception specification.
47 TFF_TEMPLATE_HEADER: show the template<...> hearder in a
49 TFF_TEMPLATE_DEFAULT_ARGUMENTS: show template paramter default values. */
51 #define TFF_PLAIN_IDENTIFIER (0)
52 #define TFF_NAMESPACE_SCOPE (1)
53 #define TFF_CLASS_SCOPE (1 << 1)
54 #define TFF_CHASE_NAMESPACE_ALIAS (1 << 2)
55 #define TFF_CHASE_TYPEDEF (1 << 3)
56 #define TFF_DECL_SPECIFIERS (1 << 4)
57 #define TFF_CLASS_KEY_OR_ENUM (1 << 5)
58 #define TFF_RETURN_TYPE (1 << 6)
59 #define TFF_FUNCTION_DEFAULT_ARGUMENTS (1 << 7)
60 #define TFF_EXCEPTION_SPECIFICATION (1 << 8)
61 #define TFF_TEMPLATE_HEADER (1 << 9)
62 #define TFF_TEMPLATE_DEFAULT_ARGUMENTS (1 << 10)
63 #define TFF_SCOPE (TFF_NAMESPACE_SCOPE | TFF_CLASS_SCOPE)
65 /* This data structure bundles altogether, all the information necessary
66 for pretty-printing a C++ source-level entity represented by a tree. */
72 } tree_formatting_info, *tfi_t;
74 #define tree_being_formatted(TFI) (TFI)->decl
75 #define tree_formatting_flags(TFI) (TFI)->flags
76 #define put_whitespace(TFI) (TFI)->pad
78 #define sorry_for_unsupported_tree(T) \
79 sorry ("`%s' not supported by %s", tree_code_name[(int) TREE_CODE (T)], \
82 #define print_scope_operator(BUFFER) output_add_string (BUFFER, "::")
83 #define print_left_paren(BUFFER) output_add_character (BUFFER, '(')
84 #define print_right_paren(BUFFER) output_add_character (BUFFER, ')')
85 #define print_left_bracket(BUFFER) output_add_character (BUFFER, '[')
86 #define print_right_bracket(BUFFER) output_add_character (BUFFER, ']')
87 #define print_whitespace(BUFFER, TFI) \
89 output_add_space (BUFFER); \
90 put_whitespace (TFI) = none; \
93 #define obstack_chunk_alloc xmalloc
94 #define obstack_chunk_free free
96 #define print_tree_identifier(BUFFER, TID) \
97 output_add_string (BUFFER, IDENTIFIER_POINTER (TID))
98 #define print_identifier(BUFFER, ID) output_add_string (BUFFER, ID)
100 /* Obstack where we build text strings for overloading, etc. */
101 static struct obstack scratch_obstack;
102 static char *scratch_firstobj;
104 # define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
105 # define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
106 # define OB_PUTC2(C1,C2) \
107 (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
108 # define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
109 # define OB_PUTID(ID) \
110 (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \
111 IDENTIFIER_LENGTH (ID)))
112 # define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
113 # define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
114 # define OB_PUTI(CST) do { sprintf (digit_buffer, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT)(CST)); \
115 OB_PUTCP (digit_buffer); } while (0)
117 # define OB_END_TEMPLATE_ID() \
118 (((obstack_next_free (&scratch_obstack) != obstack_base (&scratch_obstack) \
119 && obstack_next_free (&scratch_obstack)[-1] == '>') \
120 ? OB_PUTC (' ') : (void)0), OB_PUTC ('>'))
122 # define NEXT_CODE(t) (TREE_CODE (TREE_TYPE (t)))
124 static const char *args_to_string PARAMS ((tree, int));
125 static const char *assop_to_string PARAMS ((enum tree_code, int));
126 static const char *code_to_string PARAMS ((enum tree_code, int));
127 static const char *cv_to_string PARAMS ((tree, int));
128 static const char *decl_to_string PARAMS ((tree, int));
129 static const char *expr_to_string PARAMS ((tree, int));
130 static const char *fndecl_to_string PARAMS ((tree, int));
131 static const char *op_to_string PARAMS ((enum tree_code, int));
132 static const char *parm_to_string PARAMS ((int, int));
133 static const char *type_to_string PARAMS ((tree, int));
135 static void dump_type PARAMS ((tree, enum tree_string_flags));
136 static void dump_typename PARAMS ((tree, enum tree_string_flags));
137 static void dump_simple_decl PARAMS ((tree, tree, enum tree_string_flags));
138 static void dump_decl PARAMS ((tree, enum tree_string_flags));
139 static void dump_template_decl PARAMS ((tree, enum tree_string_flags));
140 static void dump_function_decl PARAMS ((tree, enum tree_string_flags));
141 static void dump_expr PARAMS ((tree, enum tree_string_flags));
142 static void dump_unary_op PARAMS ((const char *, tree, enum tree_string_flags));
143 static void dump_binary_op PARAMS ((const char *, tree, enum tree_string_flags));
144 static void dump_aggr_type PARAMS ((tree, enum tree_string_flags));
145 static enum pad dump_type_prefix PARAMS ((tree, enum tree_string_flags));
146 static void dump_type_suffix PARAMS ((tree, enum tree_string_flags));
147 static void dump_function_name PARAMS ((tree, enum tree_string_flags));
148 static void dump_expr_list PARAMS ((tree, enum tree_string_flags));
149 static void dump_global_iord PARAMS ((tree));
150 static enum pad dump_qualifiers PARAMS ((tree, enum pad));
151 static void dump_char PARAMS ((int));
152 static void dump_parameters PARAMS ((tree, enum tree_string_flags));
153 static void dump_exception_spec PARAMS ((tree, enum tree_string_flags));
154 static const char *class_key_or_enum PARAMS ((tree));
155 static tree ident_fndecl PARAMS ((tree));
156 static void dump_template_argument PARAMS ((tree, enum tree_string_flags));
157 static void dump_template_argument_list PARAMS ((tree, enum tree_string_flags));
158 static void dump_template_parameter PARAMS ((tree, enum tree_string_flags));
159 static void dump_template_bindings PARAMS ((tree, tree));
160 static void dump_scope PARAMS ((tree, enum tree_string_flags));
161 static void dump_template_parms PARAMS ((tree, int, enum tree_string_flags));
163 static const char *function_category PARAMS ((tree));
164 static void lang_print_error_function PARAMS ((const char *));
165 static void maybe_print_instantiation_context PARAMS ((output_buffer *));
166 static void print_instantiation_full_context PARAMS ((output_buffer *));
167 static void print_instantiation_partial_context PARAMS ((output_buffer *, tree,
169 static void cp_diagnostic_starter PARAMS ((output_buffer *,
170 diagnostic_context *));
171 static void cp_diagnostic_finalizer PARAMS ((output_buffer *,
172 diagnostic_context *));
173 static void cp_print_error_function PARAMS ((output_buffer *,
174 diagnostic_context *));
176 static int cp_tree_printer PARAMS ((output_buffer *));
177 static void print_function_argument_list PARAMS ((output_buffer *, tfi_t));
178 static void print_declaration PARAMS ((output_buffer *, tfi_t));
179 static void print_expression PARAMS ((output_buffer *, tfi_t));
180 static void print_function_declaration PARAMS ((output_buffer *, tfi_t));
181 static void print_function_parameter PARAMS ((output_buffer *, int));
182 static void print_type_id PARAMS ((output_buffer *, tfi_t));
183 static void print_cv_qualifier_seq PARAMS ((output_buffer *, tfi_t));
184 static void print_type_specifier_seq PARAMS ((output_buffer *, tfi_t));
185 static void print_simple_type_specifier PARAMS ((output_buffer *, tfi_t));
186 static void print_elaborated_type_specifier PARAMS ((output_buffer *, tfi_t));
187 static void print_rest_of_abstract_declarator PARAMS ((output_buffer *,
189 static void print_parameter_declaration_clause PARAMS ((output_buffer *,
191 static void print_exception_specification PARAMS ((output_buffer *, tfi_t));
192 static void print_nested_name_specifier PARAMS ((output_buffer *, tfi_t));
193 static void print_template_id PARAMS ((output_buffer *, tfi_t));
194 static void print_template_argument_list_start PARAMS ((output_buffer *));
195 static void print_template_argument_list_end PARAMS ((output_buffer *));
196 static tree typedef_original_name PARAMS ((tree));
198 #define A args_to_string
199 #define C code_to_string
200 #define D decl_to_string
201 #define E expr_to_string
202 #define F fndecl_to_string
203 #define L language_to_string
204 #define O op_to_string
205 #define P parm_to_string
206 #define Q assop_to_string
207 #define T type_to_string
208 #define V cv_to_string
210 #define o (cp_printer *) 0
211 cp_printer * cp_printers[256] =
213 /*0 1 2 3 4 5 6 7 8 9 A B C D E F */
214 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x00 */
215 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x10 */
216 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x20 */
217 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x30 */
218 o, A, o, C, D, E, F, o, o, o, o, o, L, o, o, O, /* 0x40 */
219 P, Q, o, o, T, o, V, o, o, o, o, o, o, o, o, o, /* 0x50 */
220 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x60 */
221 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x70 */
238 gcc_obstack_init (&scratch_obstack);
239 scratch_firstobj = (char *)obstack_alloc (&scratch_obstack, 0);
241 print_error_function = lang_print_error_function;
242 lang_diagnostic_starter = cp_diagnostic_starter;
243 lang_diagnostic_finalizer = cp_diagnostic_finalizer;
245 lang_printer = cp_tree_printer;
248 /* Dump a scope, if deemed necessary. */
251 dump_scope (scope, flags)
253 enum tree_string_flags flags;
255 if (scope == NULL_TREE)
258 if (TREE_CODE (scope) == NAMESPACE_DECL)
260 if (scope != global_namespace)
262 dump_decl (scope, (flags & (TS_PEDANTIC_NAME | TS_FUNC_SCOPE | TS_CHASE_TYPEDEFS))
263 | TS_FUNC_NORETURN | TS_DECL_TYPE);
266 else if (flags & TS_PEDANTIC_NAME)
269 else if (AGGREGATE_TYPE_P (scope))
271 dump_type (scope, (flags & (TS_PEDANTIC_NAME | TS_FUNC_SCOPE | TS_CHASE_TYPEDEFS))
272 | TS_FUNC_NORETURN | TS_DECL_TYPE);
275 else if ((flags & (TS_PEDANTIC_NAME | TS_FUNC_SCOPE))
276 && TREE_CODE (scope) == FUNCTION_DECL)
278 dump_function_decl (scope, (flags & (TS_PEDANTIC_NAME | TS_FUNC_SCOPE | TS_CHASE_TYPEDEFS))
279 | TS_FUNC_NORETURN | TS_DECL_TYPE);
284 /* Dump type qualifiers, providing padding as requested. Return an
285 indication of whether we dumped something. */
288 dump_qualifiers (t, p)
292 static const int masks[] =
293 {TYPE_QUAL_CONST, TYPE_QUAL_VOLATILE, TYPE_QUAL_RESTRICT};
294 static const char *const names[] =
295 {"const", "volatile", "__restrict"};
297 int quals = TYPE_QUALS (t);
298 int do_after = p == after;
302 for (ix = 0; ix != 3; ix++)
303 if (masks[ix] & quals)
308 OB_PUTCP (names[ix]);
318 /* This must be large enough to hold any printed integer or floating-point
320 static char digit_buffer[128];
322 /* Dump the template ARGument under control of FLAGS. */
325 dump_template_argument (arg, flags)
327 enum tree_string_flags flags;
329 if (TYPE_P (arg) || TREE_CODE (arg) == TEMPLATE_DECL)
330 dump_type (arg, flags & ~TS_AGGR_TAGS);
332 dump_expr (arg, (flags | TS_EXPR_PARENS) & ~TS_AGGR_TAGS);
335 /* Dump a template-argument-list ARGS (always a TREE_VEC) under control
339 dump_template_argument_list (args, flags)
341 enum tree_string_flags flags;
343 int n = TREE_VEC_LENGTH (args);
347 for (i = 0; i< n; ++i)
351 dump_template_argument (TREE_VEC_ELT (args, i), flags);
356 /* Dump a template parameter PARM (a TREE_LIST) under control of FLAGS. */
359 dump_template_parameter (parm, flags)
361 enum tree_string_flags flags;
363 tree p = TREE_VALUE (parm);
364 tree a = TREE_PURPOSE (parm);
366 if (TREE_CODE (p) == TYPE_DECL)
368 if (flags & TS_DECL_TYPE)
374 OB_PUTID (DECL_NAME (p));
377 else if (DECL_NAME (p))
378 OB_PUTID (DECL_NAME (p));
380 OB_PUTS ("{template default argument error}");
383 dump_decl (p, flags | TS_DECL_TYPE);
385 if ((flags & TS_PARM_DEFAULTS) && a != NULL_TREE)
388 if (TREE_CODE (a) == TYPE_DECL || TREE_CODE (a) == TEMPLATE_DECL)
389 dump_type (a, flags & ~TS_CHASE_TYPEDEFS);
391 dump_expr (a, flags | TS_EXPR_PARENS);
395 /* Dump, under control of FLAGS, a template-parameter-list binding.
396 PARMS is a TREE_LIST of TREE_VEC of TREE_LIST and ARGS is a
400 dump_template_bindings (parms, args)
407 tree p = TREE_VALUE (parms);
408 int lvl = TMPL_PARMS_DEPTH (parms);
412 for (i = 0; i < TREE_VEC_LENGTH (p); ++i)
414 tree arg = NULL_TREE;
416 /* Don't crash if we had an invalid argument list. */
417 if (TMPL_ARGS_DEPTH (args) >= lvl)
419 tree lvl_args = TMPL_ARGS_LEVEL (args, lvl);
420 if (NUM_TMPL_ARGS (lvl_args) > arg_idx)
421 arg = TREE_VEC_ELT (lvl_args, arg_idx);
426 dump_template_parameter (TREE_VEC_ELT (p, i), TS_PLAIN);
429 dump_template_argument (arg, TS_PLAIN);
431 OB_PUTS ("{missing}");
437 parms = TREE_CHAIN (parms);
441 /* Dump into the obstack a human-readable equivalent of TYPE. FLAGS
442 controls the format. */
447 enum tree_string_flags flags;
452 if (TYPE_PTRMEMFUNC_P (t))
455 switch (TREE_CODE (t))
458 OB_PUTS ("{unknown type}");
462 /* A list of function parms. */
463 dump_parameters (t, flags);
466 case IDENTIFIER_NODE:
471 dump_type (BINFO_TYPE (t), flags);
477 dump_aggr_type (t, flags);
481 if (flags & TS_CHASE_TYPEDEFS)
483 dump_type (DECL_ORIGINAL_TYPE (t)
484 ? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t), flags);
487 /* else fallthrough */
491 dump_decl (t, flags & ~TS_DECL_TYPE);
495 OB_PUTS ("complex ");
496 dump_type (TREE_TYPE (t), flags);
500 if (!TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)) && TREE_UNSIGNED (t))
501 OB_PUTS ("unsigned ");
502 else if (TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)) && !TREE_UNSIGNED (t))
511 dump_qualifiers (t, after);
512 type = flags & TS_CHASE_TYPEDEFS ? TYPE_MAIN_VARIANT (t) : t;
513 if (TYPE_NAME (type) && TYPE_IDENTIFIER (type))
514 OB_PUTID (TYPE_IDENTIFIER (type));
516 /* Types like intQI_type_node and friends have no names.
517 These don't come up in user error messages, but it's nice
518 to be able to print them from the debugger. */
519 OB_PUTS ("{anonymous}");
523 case TEMPLATE_TEMPLATE_PARM:
524 /* For parameters inside template signature. */
525 if (TYPE_IDENTIFIER (t))
526 OB_PUTID (TYPE_IDENTIFIER (t));
528 OB_PUTS ("{anonymous template template parameter}");
531 case BOUND_TEMPLATE_TEMPLATE_PARM:
533 tree args = TYPE_TI_ARGS (t);
534 OB_PUTID (TYPE_IDENTIFIER (t));
536 dump_template_argument_list (args, flags);
537 OB_END_TEMPLATE_ID ();
541 case TEMPLATE_TYPE_PARM:
542 dump_qualifiers (t, after);
543 if (TYPE_IDENTIFIER (t))
544 OB_PUTID (TYPE_IDENTIFIER (t));
546 OB_PUTS ("{anonymous template type parameter}");
549 /* This is not always necessary for pointers and such, but doing this
550 reduces code size. */
559 dump_type_prefix (t, flags);
560 dump_type_suffix (t, flags);
564 OB_PUTS ("typename ");
565 dump_typename (t, flags);
569 OB_PUTS ("__typeof (");
570 dump_expr (TYPE_FIELDS (t), flags & ~TS_EXPR_PARENS);
575 sorry ("`%s' not supported by dump_type",
576 tree_code_name[(int) TREE_CODE (t)]);
577 /* Fall through to error. */
580 OB_PUTS ("{type error}");
585 /* Dump a TYPENAME_TYPE. We need to notice when the context is itself
589 dump_typename (t, flags)
591 enum tree_string_flags flags;
593 tree ctx = TYPE_CONTEXT (t);
595 if (TREE_CODE (ctx) == TYPENAME_TYPE)
596 dump_typename (ctx, flags);
598 dump_type (ctx, flags & ~TS_AGGR_TAGS);
600 dump_decl (TYPENAME_TYPE_FULLNAME (t), flags);
603 /* Return the name of the supplied aggregate, or enumeral type. */
606 class_key_or_enum (t)
609 if (TREE_CODE (t) == ENUMERAL_TYPE)
611 else if (TREE_CODE (t) == UNION_TYPE)
613 else if (TYPE_LANG_SPECIFIC (t) && CLASSTYPE_DECLARED_CLASS (t))
619 /* Print out a class declaration T under the control of FLAGS,
620 in the form `class foo'. */
623 dump_aggr_type (t, flags)
625 enum tree_string_flags flags;
628 const char *variety = class_key_or_enum (t);
632 dump_qualifiers (t, after);
634 if (flags & TS_AGGR_TAGS)
640 if (flags & TS_CHASE_TYPEDEFS)
641 t = TYPE_MAIN_VARIANT (t);
643 name = TYPE_NAME (t);
647 typdef = !DECL_ARTIFICIAL (name);
648 tmplate = !typdef && TREE_CODE (t) != ENUMERAL_TYPE
649 && TYPE_LANG_SPECIFIC (t) && CLASSTYPE_TEMPLATE_INFO (t)
650 && (CLASSTYPE_TEMPLATE_SPECIALIZATION (t)
651 || TREE_CODE (CLASSTYPE_TI_TEMPLATE (t)) != TEMPLATE_DECL
652 || DECL_TEMPLATE_SPECIALIZATION (CLASSTYPE_TI_TEMPLATE (t))
653 || PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t)));
654 dump_scope (CP_DECL_CONTEXT (name), flags | TS_FUNC_SCOPE);
657 /* Because the template names are mangled, we have to locate
658 the most general template, and use that name. */
659 tree tpl = CLASSTYPE_TI_TEMPLATE (t);
661 while (DECL_TEMPLATE_INFO (tpl))
662 tpl = DECL_TI_TEMPLATE (tpl);
665 name = DECL_NAME (name);
668 if (name == 0 || ANON_AGGRNAME_P (name))
670 OB_PUTS ("{anonymous");
671 if (!(flags & TS_AGGR_TAGS))
681 dump_template_parms (TYPE_TEMPLATE_INFO (t),
682 !CLASSTYPE_USE_TEMPLATE (t),
683 flags & ~TS_TEMPLATE_PREFIX);
686 /* Dump into the obstack the initial part of the output for a given type.
687 This is necessary when dealing with things like functions returning
690 return type of `int (* fee ())()': pointer -> function -> int. Both
691 pointer (and reference and offset) and function (and member) types must
692 deal with prefix and suffix.
694 Arrays must also do this for DECL nodes, like int a[], and for things like
697 Return indicates how you should pad an object name after this. I.e. you
698 want to pad non-*, non-& cores, but not pad * or & types. */
701 dump_type_prefix (t, flags)
703 enum tree_string_flags flags;
705 enum pad padding = before;
707 if (TYPE_PTRMEMFUNC_P (t))
709 t = TYPE_PTRMEMFUNC_FN_TYPE (t);
713 switch (TREE_CODE (t))
718 tree sub = TREE_TYPE (t);
720 padding = dump_type_prefix (sub, flags);
721 /* A tree for a member pointer looks like pointer to offset,
722 so let the OFFSET_TYPE case handle it. */
723 if (!TYPE_PTRMEM_P (t))
727 if (TREE_CODE (sub) == ARRAY_TYPE)
729 OB_PUTC ("&*"[TREE_CODE (t) == POINTER_TYPE]);
730 padding = dump_qualifiers (t, none);
737 padding = dump_type_prefix (TREE_TYPE (t), flags);
738 if (TREE_CODE (t) == OFFSET_TYPE) /* pmfs deal with this in d_t_p */
742 dump_type (TYPE_OFFSET_BASETYPE (t), flags);
746 padding = dump_qualifiers (t, none);
749 /* Can only be reached through function pointer -- this would not be
750 correct if FUNCTION_DECLs used it. */
752 padding = dump_type_prefix (TREE_TYPE (t), flags);
760 padding = dump_type_prefix (TREE_TYPE (t), flags);
765 dump_aggr_type (TYPE_METHOD_BASETYPE (t), flags);
770 padding = dump_type_prefix (TREE_TYPE (t), flags);
774 case IDENTIFIER_NODE:
779 case TEMPLATE_TYPE_PARM:
780 case TEMPLATE_TEMPLATE_PARM:
781 case BOUND_TEMPLATE_TEMPLATE_PARM:
790 dump_type (t, flags);
795 sorry ("`%s' not supported by dump_type_prefix",
796 tree_code_name[(int) TREE_CODE (t)]);
799 OB_PUTS ("{typeprefixerror}");
805 /* Dump the suffix of type T, under control of FLAGS. This is the part
806 which appears after the identifier (or function parms). */
809 dump_type_suffix (t, flags)
811 enum tree_string_flags flags;
813 if (TYPE_PTRMEMFUNC_P (t))
814 t = TYPE_PTRMEMFUNC_FN_TYPE (t);
816 switch (TREE_CODE (t))
821 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
823 dump_type_suffix (TREE_TYPE (t), flags);
826 /* Can only be reached through function pointer */
832 arg = TYPE_ARG_TYPES (t);
833 if (TREE_CODE (t) == METHOD_TYPE)
834 arg = TREE_CHAIN (arg);
836 /* Function pointers don't have default args. Not in standard C++,
837 anyway; they may in g++, but we'll just pretend otherwise. */
838 dump_parameters (arg, flags & ~TS_PARM_DEFAULTS);
840 if (TREE_CODE (t) == METHOD_TYPE)
842 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t))), before);
843 dump_type_suffix (TREE_TYPE (t), flags);
844 dump_exception_spec (TYPE_RAISES_EXCEPTIONS (t), flags);
852 if (host_integerp (TYPE_MAX_VALUE (TYPE_DOMAIN (t)), 0))
853 OB_PUTI (tree_low_cst (TYPE_MAX_VALUE (TYPE_DOMAIN (t)), 0) + 1);
854 else if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (t))) == MINUS_EXPR)
855 dump_expr (TREE_OPERAND (TYPE_MAX_VALUE (TYPE_DOMAIN (t)), 0),
856 flags & ~TS_EXPR_PARENS);
858 dump_expr (fold (cp_build_binary_op
859 (PLUS_EXPR, TYPE_MAX_VALUE (TYPE_DOMAIN (t)),
861 flags & ~TS_EXPR_PARENS);
864 dump_type_suffix (TREE_TYPE (t), flags);
868 case IDENTIFIER_NODE:
873 case TEMPLATE_TYPE_PARM:
874 case TEMPLATE_TEMPLATE_PARM:
875 case BOUND_TEMPLATE_TEMPLATE_PARM:
887 sorry ("`%s' not supported by dump_type_suffix",
888 tree_code_name[(int) TREE_CODE (t)]);
891 /* Don't mark it here, we should have already done in
897 /* Return a function declaration which corresponds to the IDENTIFIER_NODE
904 tree n = lookup_name (t, 0);
909 if (TREE_CODE (n) == FUNCTION_DECL)
911 else if (TREE_CODE (n) == TREE_LIST
912 && TREE_CODE (TREE_VALUE (n)) == FUNCTION_DECL)
913 return TREE_VALUE (n);
915 my_friendly_abort (66);
919 #ifndef NO_DOLLAR_IN_LABEL
920 # define GLOBAL_THING "_GLOBAL_$"
922 # ifndef NO_DOT_IN_LABEL
923 # define GLOBAL_THING "_GLOBAL_."
925 # define GLOBAL_THING "_GLOBAL__"
929 #define GLOBAL_IORD_P(NODE) \
930 ! strncmp (IDENTIFIER_POINTER(NODE), GLOBAL_THING, sizeof (GLOBAL_THING) - 1)
936 const char *name = IDENTIFIER_POINTER (t);
938 OB_PUTS ("(static ");
939 if (name [sizeof (GLOBAL_THING) - 1] == 'I')
940 OB_PUTS ("initializers");
941 else if (name [sizeof (GLOBAL_THING) - 1] == 'D')
942 OB_PUTS ("destructors");
944 my_friendly_abort (352);
947 OB_PUTCP (input_filename);
952 dump_simple_decl (t, type, flags)
955 enum tree_string_flags flags;
957 if (flags & TS_DECL_TYPE)
959 if (dump_type_prefix (type, flags) != none)
962 if (!DECL_INITIAL (t) || TREE_CODE (DECL_INITIAL (t)) != TEMPLATE_PARM_INDEX)
963 dump_scope (CP_DECL_CONTEXT (t), flags);
965 dump_decl (DECL_NAME (t), flags);
967 OB_PUTS ("{anonymous}");
968 if (flags & TS_DECL_TYPE)
969 dump_type_suffix (type, flags);
972 /* Dump a human readable string for the decl T under control of FLAGS. */
977 enum tree_string_flags flags;
982 switch (TREE_CODE (t))
986 /* Don't say 'typedef class A' */
987 if (DECL_ARTIFICIAL (t))
989 if ((flags & TS_DECL_TYPE)
990 && TREE_CODE (TREE_TYPE (t)) == TEMPLATE_TYPE_PARM)
991 /* Say `class T' not just `T'. */
994 dump_type (TREE_TYPE (t), flags);
998 if (flags & TS_DECORATE)
999 OB_PUTS ("typedef ");
1000 dump_simple_decl (t, DECL_ORIGINAL_TYPE (t)
1001 ? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t),
1006 if (DECL_NAME (t) && VTABLE_NAME_P (DECL_NAME (t)))
1008 OB_PUTS ("vtable for ");
1009 if (TYPE_P (DECL_CONTEXT (t)))
1010 dump_type (DECL_CONTEXT (t), flags);
1012 /* This case can arise with -fno-vtable-thunks. See
1013 expand_upcast_fixups. It's not clear what to print
1015 OB_PUTS ("{unknown type}");
1018 /* else fall through */
1021 dump_simple_decl (t, TREE_TYPE (t), flags);
1025 OB_PUTS ("{return} ");
1026 dump_simple_decl (t, TREE_TYPE (t), flags);
1029 case NAMESPACE_DECL:
1030 dump_scope (CP_DECL_CONTEXT (t), flags);
1031 if (DECL_NAME (t) == anonymous_namespace_name)
1032 OB_PUTS ("{unnamed}");
1034 OB_PUTID (DECL_NAME (t));
1038 dump_decl (TREE_OPERAND (t, 0), flags & ~TS_DECL_TYPE);
1040 dump_decl (TREE_OPERAND (t, 1), flags);
1044 dump_decl (TREE_OPERAND (t, 0), flags);
1046 dump_decl (TREE_OPERAND (t, 1), flags);
1050 /* So that we can do dump_decl on an aggr type. */
1054 dump_type (t, flags);
1058 my_friendly_abort (69);
1061 /* These special cases are duplicated here so that other functions
1062 can feed identifiers to cp_error and get them demangled properly. */
1063 case IDENTIFIER_NODE:
1065 if (DESTRUCTOR_NAME_P (t)
1066 && (f = ident_fndecl (t))
1067 && DECL_LANGUAGE (f) == lang_cplusplus)
1070 dump_decl (DECL_NAME (f), flags);
1072 else if (IDENTIFIER_TYPENAME_P (t))
1074 OB_PUTS ("operator ");
1075 /* Not exactly IDENTIFIER_TYPE_VALUE. */
1076 dump_type (TREE_TYPE (t), flags);
1085 t = OVL_CURRENT (t);
1089 if (GLOBAL_IORD_P (DECL_ASSEMBLER_NAME (t)))
1090 dump_global_iord (DECL_ASSEMBLER_NAME (t));
1091 else if (! DECL_LANG_SPECIFIC (t))
1092 OB_PUTS ("{internal}");
1093 else if (flags & TS_PEDANTIC_NAME)
1094 dump_function_decl (t, flags | TS_FUNC_NORETURN | TS_DECL_TYPE);
1096 dump_function_decl (t, flags);
1100 if (flags & TS_PEDANTIC_NAME)
1101 dump_template_decl (t, flags | TS_FUNC_NORETURN | TS_DECL_TYPE);
1103 dump_template_decl (t, flags);
1106 case TEMPLATE_ID_EXPR:
1109 tree name = TREE_OPERAND (t, 0);
1110 if (is_overloaded_fn (name))
1111 name = DECL_NAME (get_first_fn (name));
1112 dump_decl (name, flags);
1114 for (args = TREE_OPERAND (t, 1); args; args = TREE_CHAIN (args))
1116 dump_template_argument (TREE_VALUE (args), flags);
1117 if (TREE_CHAIN (args))
1120 OB_END_TEMPLATE_ID ();
1125 dump_decl (TREE_OPERAND (t, 0), flags);
1129 OB_PUTID (DECL_NAME (t));
1133 if ((TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == ENUMERAL_TYPE)
1134 || (DECL_INITIAL (t) &&
1135 TREE_CODE (DECL_INITIAL (t)) == TEMPLATE_PARM_INDEX))
1136 dump_simple_decl (t, TREE_TYPE (t), flags);
1137 else if (DECL_NAME (t))
1138 dump_decl (DECL_NAME (t), flags);
1139 else if (DECL_INITIAL (t))
1140 dump_expr (DECL_INITIAL (t), flags | TS_EXPR_PARENS);
1142 OB_PUTS ("enumerator");
1147 dump_type (DECL_INITIAL (t), flags);
1149 OB_PUTID (DECL_NAME (t));
1153 sorry ("`%s' not supported by dump_decl",
1154 tree_code_name[(int) TREE_CODE (t)]);
1155 /* Fallthrough to error. */
1158 OB_PUTS ("{declaration error}");
1163 /* Dump a template declaration T under control of FLAGS. This means the
1164 'template <...> leaders plus the 'class X' or 'void fn(...)' part. */
1167 dump_template_decl (t, flags)
1169 enum tree_string_flags flags;
1171 tree orig_parms = DECL_TEMPLATE_PARMS (t);
1175 if (flags & TS_TEMPLATE_PREFIX)
1177 for (parms = orig_parms = nreverse (orig_parms);
1179 parms = TREE_CHAIN (parms))
1181 tree inner_parms = INNERMOST_TEMPLATE_PARMS (parms);
1182 int len = TREE_VEC_LENGTH (inner_parms);
1184 OB_PUTS ("template <");
1185 for (i = 0; i < len; i++)
1189 dump_template_parameter (TREE_VEC_ELT (inner_parms, i), flags);
1191 OB_END_TEMPLATE_ID ();
1194 nreverse(orig_parms);
1195 /* If we've shown the template<args> prefix, we'd better show the
1197 flags |= TS_DECL_TYPE;
1199 if (TREE_CODE (DECL_TEMPLATE_RESULT (t)) == TYPE_DECL)
1200 dump_type (TREE_TYPE (t),
1201 ((flags & ~TS_AGGR_TAGS) | TS_TEMPLATE_PLAIN
1202 | (flags & TS_DECL_TYPE ? TS_AGGR_TAGS : 0)));
1203 else if (TREE_CODE (DECL_TEMPLATE_RESULT (t)) == VAR_DECL)
1204 dump_decl (DECL_TEMPLATE_RESULT (t), flags | TS_TEMPLATE_PLAIN);
1205 else if (TREE_TYPE (t) == NULL_TREE)
1206 my_friendly_abort (353);
1208 switch (NEXT_CODE (t))
1212 dump_function_decl (t, flags | TS_TEMPLATE_PLAIN);
1215 /* This case can occur with some illegal code. */
1216 dump_type (TREE_TYPE (t),
1217 (flags & ~TS_AGGR_TAGS) | TS_TEMPLATE_PLAIN
1218 | (flags & TS_DECL_TYPE ? TS_AGGR_TAGS : 0));
1222 /* Pretty print a function decl. There are several ways we want to print a
1223 function declaration. The TS_FUNC bits in FLAGS tells us how to behave.
1224 As cp_error can only apply the '#' flag once to give 0 and 1 for V, there
1225 is %D which doesn't print the throw specs, and %F which does. */
1228 dump_function_decl (t, flags)
1230 enum tree_string_flags flags;
1234 tree cname = NULL_TREE;
1235 tree template_args = NULL_TREE;
1236 tree template_parms = NULL_TREE;
1237 int show_return = !(flags & TS_FUNC_NORETURN) && (flags & TS_DECL_TYPE);
1239 if (TREE_CODE (t) == TEMPLATE_DECL)
1240 t = DECL_TEMPLATE_RESULT (t);
1242 /* Pretty print template instantiations only. */
1243 if (DECL_USE_TEMPLATE (t) && DECL_TEMPLATE_INFO (t))
1247 template_args = DECL_TI_ARGS (t);
1248 tmpl = most_general_template (t);
1249 if (tmpl && TREE_CODE (tmpl) == TEMPLATE_DECL)
1251 template_parms = DECL_TEMPLATE_PARMS (tmpl);
1256 fntype = TREE_TYPE (t);
1257 parmtypes = TYPE_ARG_TYPES (fntype);
1259 if (DECL_CLASS_SCOPE_P (t))
1260 cname = DECL_CONTEXT (t);
1261 /* this is for partially instantiated template methods */
1262 else if (TREE_CODE (fntype) == METHOD_TYPE)
1263 cname = TREE_TYPE (TREE_VALUE (parmtypes));
1265 if (!(flags & TS_DECORATE))
1267 else if (DECL_STATIC_FUNCTION_P (t))
1268 OB_PUTS ("static ");
1269 else if (TYPE_POLYMORPHIC_P (t))
1270 OB_PUTS ("virtual ");
1272 /* Print the return type? */
1274 show_return = !DECL_CONV_FN_P (t) && !DECL_CONSTRUCTOR_P (t)
1275 && !DECL_DESTRUCTOR_P (t);
1278 if (dump_type_prefix (TREE_TYPE (fntype), flags) != none)
1282 /* Print the function name. */
1285 dump_type (cname, flags);
1289 dump_scope (CP_DECL_CONTEXT (t), flags);
1291 dump_function_name (t, flags);
1293 if (!(flags & TS_DECL_TYPE))
1295 if (TREE_CODE (fntype) == METHOD_TYPE && parmtypes)
1296 /* Skip "this" parameter. */
1297 parmtypes = TREE_CHAIN (parmtypes);
1299 /* Skip past the "in_charge" parameter. */
1300 if (DECL_HAS_IN_CHARGE_PARM_P (t))
1301 parmtypes = TREE_CHAIN (parmtypes);
1303 dump_parameters (parmtypes, flags);
1306 dump_type_suffix (TREE_TYPE (fntype), flags);
1308 if (TREE_CODE (fntype) == METHOD_TYPE)
1309 dump_qualifiers (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype))),
1312 if (flags & TS_FUNC_THROW)
1313 dump_exception_spec (TYPE_RAISES_EXCEPTIONS (fntype), flags);
1315 /* If T is a template instantiation, dump the parameter binding. */
1316 if (template_parms != NULL_TREE && template_args != NULL_TREE)
1318 OB_PUTS (" [with ");
1319 dump_template_bindings (template_parms, template_args);
1324 /* Print a parameter list. If this is for a member function, the
1325 member object ptr (and any other hidden args) should have
1326 already been removed. */
1329 dump_parameters (parmtypes, flags)
1331 enum tree_string_flags flags;
1336 for (first = 1; parmtypes != void_list_node;
1337 parmtypes = TREE_CHAIN (parmtypes))
1347 dump_type (TREE_VALUE (parmtypes), flags);
1349 if ((flags & TS_PARM_DEFAULTS) && TREE_PURPOSE (parmtypes))
1352 dump_expr (TREE_PURPOSE (parmtypes), flags | TS_EXPR_PARENS);
1359 /* Print an exception specification. T is the exception specification. */
1362 dump_exception_spec (t, flags)
1364 enum tree_string_flags flags;
1368 OB_PUTS (" throw (");
1369 if (TREE_VALUE (t) != NULL_TREE)
1372 dump_type (TREE_VALUE (t), flags);
1382 /* Handle the function name for a FUNCTION_DECL node, grokking operators
1383 and destructors properly. */
1386 dump_function_name (t, flags)
1388 enum tree_string_flags flags;
1390 tree name = DECL_NAME (t);
1392 if (DECL_DESTRUCTOR_P (t))
1395 dump_decl (name, TS_PLAIN);
1397 else if (DECL_CONV_FN_P (t))
1399 /* This cannot use the hack that the operator's return
1400 type is stashed off of its name because it may be
1401 used for error reporting. In the case of conflicting
1402 declarations, both will have the same name, yet
1403 the types will be different, hence the TREE_TYPE field
1404 of the first name will be clobbered by the second. */
1405 OB_PUTS ("operator ");
1406 dump_type (TREE_TYPE (TREE_TYPE (t)), flags);
1408 else if (IDENTIFIER_OPNAME_P (name))
1411 dump_decl (name, flags);
1413 if (DECL_LANG_SPECIFIC (t) && DECL_TEMPLATE_INFO (t)
1414 && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t)
1415 && (DECL_TEMPLATE_SPECIALIZATION (t)
1416 || TREE_CODE (DECL_TI_TEMPLATE (t)) != TEMPLATE_DECL
1417 || DECL_TEMPLATE_SPECIALIZATION (DECL_TI_TEMPLATE (t))
1418 || PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t))))
1419 dump_template_parms (DECL_TEMPLATE_INFO (t), !DECL_USE_TEMPLATE (t), flags);
1422 /* Dump the template parameters from the template info INFO under control of
1423 FLAGS. PRIMARY indicates whether this is a primary template decl, or
1424 specialization (partial or complete). For partial specializations we show
1425 the specialized parameter values. For a primary template we show no
1429 dump_template_parms (info, primary, flags)
1432 enum tree_string_flags flags;
1434 tree args = info ? TI_ARGS (info) : NULL_TREE;
1436 if (primary && flags & TS_TEMPLATE_PLAIN)
1438 flags &= ~(TS_AGGR_TAGS | TS_TEMPLATE_PLAIN);
1441 /* Be careful only to print things when we have them, so as not
1442 to crash producing error messages. */
1443 if (args && !primary)
1449 if (TREE_CODE (args) == TREE_VEC)
1451 if (TREE_VEC_LENGTH (args) > 0
1452 && TREE_CODE (TREE_VEC_ELT (args, 0)) == TREE_VEC)
1453 args = TREE_VEC_ELT (args, TREE_VEC_LENGTH (args) - 1);
1455 len = TREE_VEC_LENGTH (args);
1457 else if (TREE_CODE (args) == TREE_LIST)
1459 while (ix != len && args)
1464 arg = TREE_VEC_ELT (args, ix);
1469 arg = TREE_VALUE (args);
1470 args = TREE_CHAIN (args);
1476 OB_PUTS ("{template parameter error}");
1478 dump_template_argument (arg, flags);
1484 tree tpl = TI_TEMPLATE (info);
1485 tree parms = DECL_TEMPLATE_PARMS (tpl);
1488 parms = TREE_CODE (parms) == TREE_LIST ? TREE_VALUE (parms) : NULL_TREE;
1489 len = parms ? TREE_VEC_LENGTH (parms) : 0;
1491 for (ix = 0; ix != len; ix++)
1493 tree parm = TREE_VALUE (TREE_VEC_ELT (parms, ix));
1498 dump_decl (parm, flags & ~TS_DECL_TYPE);
1501 OB_END_TEMPLATE_ID ();
1510 case TARGET_NEWLINE:
1545 sprintf (digit_buffer, "\\%03o", (int) c);
1546 OB_PUTCP (digit_buffer);
1551 /* Print out a list of initializers (subr of dump_expr) */
1554 dump_expr_list (l, flags)
1556 enum tree_string_flags flags;
1560 dump_expr (TREE_VALUE (l), flags | TS_EXPR_PARENS);
1567 /* Print out an expression E under control of FLAGS. */
1570 dump_expr (t, flags)
1572 enum tree_string_flags flags;
1574 switch (TREE_CODE (t))
1582 case NAMESPACE_DECL:
1584 dump_decl (t, flags & ~TS_DECL_TYPE);
1589 tree type = TREE_TYPE (t);
1590 my_friendly_assert (type != 0, 81);
1592 /* If it's an enum, output its tag, rather than its value. */
1593 if (TREE_CODE (type) == ENUMERAL_TYPE)
1595 tree values = TYPE_VALUES (type);
1598 values = TREE_CHAIN (values))
1599 if (tree_int_cst_equal (TREE_VALUE (values), t))
1603 OB_PUTID (TREE_PURPOSE (values));
1606 /* Value must have been cast. */
1608 dump_type (type, flags);
1613 else if (type == boolean_type_node)
1615 if (t == boolean_false_node || integer_zerop (t))
1617 else if (t == boolean_true_node)
1620 else if (type == char_type_node)
1623 dump_char (tree_low_cst (t, 0));
1629 if ((unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (t)
1630 != (TREE_INT_CST_LOW (t) >> (HOST_BITS_PER_WIDE_INT - 1)))
1634 if (tree_int_cst_sgn (val) < 0)
1637 val = build_int_2 (-TREE_INT_CST_LOW (val),
1638 ~TREE_INT_CST_HIGH (val)
1639 + !TREE_INT_CST_LOW (val));
1641 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
1644 static char format[10]; /* "%x%09999x\0" */
1646 sprintf (format, "%%x%%0%dx", HOST_BITS_PER_INT / 4);
1647 sprintf (digit_buffer, format, TREE_INT_CST_HIGH (val),
1648 TREE_INT_CST_LOW (val));
1649 OB_PUTCP (digit_buffer);
1653 OB_PUTI (TREE_INT_CST_LOW (t));
1659 #ifndef REAL_IS_NOT_DOUBLE
1660 sprintf (digit_buffer, "%g", TREE_REAL_CST (t));
1663 const unsigned char *p = (const unsigned char *) &TREE_REAL_CST (t);
1665 strcpy (digit_buffer, "0x");
1666 for (i = 0; i < sizeof TREE_REAL_CST (t); i++)
1667 sprintf (digit_buffer + 2 + 2*i, "%02x", *p++);
1670 OB_PUTCP (digit_buffer);
1675 dump_type (PTRMEM_CST_CLASS (t), flags);
1677 OB_PUTID (DECL_NAME (PTRMEM_CST_MEMBER (t)));
1682 const char *p = TREE_STRING_POINTER (t);
1683 int len = TREE_STRING_LENGTH (t) - 1;
1687 for (i = 0; i < len; i++)
1695 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
1697 dump_expr (TREE_OPERAND (t, 1), flags | TS_EXPR_PARENS);
1703 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
1705 dump_expr (TREE_OPERAND (t, 1), flags | TS_EXPR_PARENS);
1707 dump_expr (TREE_OPERAND (t, 2), flags | TS_EXPR_PARENS);
1712 if (TREE_HAS_CONSTRUCTOR (t))
1715 dump_type (TREE_TYPE (TREE_TYPE (t)), flags);
1719 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
1723 case AGGR_INIT_EXPR:
1725 tree fn = NULL_TREE;
1727 if (TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR)
1728 fn = TREE_OPERAND (TREE_OPERAND (t, 0), 0);
1730 if (fn && TREE_CODE (fn) == FUNCTION_DECL)
1732 if (DECL_CONSTRUCTOR_P (fn))
1733 OB_PUTID (TYPE_IDENTIFIER (TREE_TYPE (t)));
1738 dump_expr (TREE_OPERAND (t, 0), 0);
1741 if (TREE_OPERAND (t, 1))
1742 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)), flags);
1748 tree fn = TREE_OPERAND (t, 0);
1749 tree args = TREE_OPERAND (t, 1);
1751 if (TREE_CODE (fn) == ADDR_EXPR)
1752 fn = TREE_OPERAND (fn, 0);
1754 if (TREE_TYPE (fn) != NULL_TREE && NEXT_CODE (fn) == METHOD_TYPE)
1756 tree ob = TREE_VALUE (args);
1757 if (TREE_CODE (ob) == ADDR_EXPR)
1759 dump_expr (TREE_OPERAND (ob, 0), flags | TS_EXPR_PARENS);
1762 else if (TREE_CODE (ob) != PARM_DECL
1763 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
1765 dump_expr (ob, flags | TS_EXPR_PARENS);
1768 args = TREE_CHAIN (args);
1770 dump_expr (fn, flags | TS_EXPR_PARENS);
1772 dump_expr_list (args, flags);
1779 tree type = TREE_OPERAND (t, 1);
1780 if (NEW_EXPR_USE_GLOBAL (t))
1783 if (TREE_OPERAND (t, 0))
1786 dump_expr_list (TREE_OPERAND (t, 0), flags);
1789 if (TREE_CODE (type) == ARRAY_REF)
1790 type = build_cplus_array_type
1791 (TREE_OPERAND (type, 0),
1792 build_index_type (fold (build (MINUS_EXPR, integer_type_node,
1793 TREE_OPERAND (type, 1),
1794 integer_one_node))));
1795 dump_type (type, flags);
1796 if (TREE_OPERAND (t, 2))
1799 dump_expr_list (TREE_OPERAND (t, 2), flags);
1806 /* Note that this only works for G++ target exprs. If somebody
1807 builds a general TARGET_EXPR, there's no way to represent that
1808 it initializes anything other that the parameter slot for the
1809 default argument. Note we may have cleared out the first
1810 operand in expand_expr, so don't go killing ourselves. */
1811 if (TREE_OPERAND (t, 1))
1812 dump_expr (TREE_OPERAND (t, 1), flags | TS_EXPR_PARENS);
1820 case TRUNC_DIV_EXPR:
1821 case TRUNC_MOD_EXPR:
1829 case BIT_ANDTC_EXPR:
1830 case TRUTH_ANDIF_EXPR:
1831 case TRUTH_ORIF_EXPR:
1838 case EXACT_DIV_EXPR:
1839 dump_binary_op (operator_name_info[(int) TREE_CODE (t)].name, t, flags);
1843 case FLOOR_DIV_EXPR:
1844 case ROUND_DIV_EXPR:
1845 dump_binary_op ("/", t, flags);
1849 case FLOOR_MOD_EXPR:
1850 case ROUND_MOD_EXPR:
1851 dump_binary_op ("%", t, flags);
1856 tree ob = TREE_OPERAND (t, 0);
1857 if (TREE_CODE (ob) == INDIRECT_REF)
1859 ob = TREE_OPERAND (ob, 0);
1860 if (TREE_CODE (ob) != PARM_DECL
1861 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
1863 dump_expr (ob, flags | TS_EXPR_PARENS);
1869 dump_expr (ob, flags | TS_EXPR_PARENS);
1872 dump_expr (TREE_OPERAND (t, 1), flags & ~TS_EXPR_PARENS);
1877 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
1879 dump_expr (TREE_OPERAND (t, 1), flags | TS_EXPR_PARENS);
1884 if (VOID_TYPE_P (TREE_TYPE (t)))
1887 dump_type (TREE_TYPE (t), flags);
1889 dump_expr (TREE_OPERAND (t, 0), flags);
1892 dump_unary_op ("+", t, flags);
1896 if (TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
1897 || TREE_CODE (TREE_OPERAND (t, 0)) == STRING_CST
1898 /* An ADDR_EXPR can have reference type. In that case, we
1899 shouldn't print the `&' doing so indicates to the user
1900 that the expression has pointer type. */
1902 && TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE))
1903 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
1905 dump_unary_op ("&", t, flags);
1909 if (TREE_HAS_CONSTRUCTOR (t))
1911 t = TREE_OPERAND (t, 0);
1912 my_friendly_assert (TREE_CODE (t) == CALL_EXPR, 237);
1913 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
1915 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)), flags);
1920 if (TREE_OPERAND (t,0) != NULL_TREE
1921 && TREE_TYPE (TREE_OPERAND (t, 0))
1922 && NEXT_CODE (TREE_OPERAND (t, 0)) == REFERENCE_TYPE)
1923 dump_expr (TREE_OPERAND (t, 0), flags);
1925 dump_unary_op ("*", t, flags);
1931 case TRUTH_NOT_EXPR:
1932 case PREDECREMENT_EXPR:
1933 case PREINCREMENT_EXPR:
1934 dump_unary_op (operator_name_info [(int)TREE_CODE (t)].name, t, flags);
1937 case POSTDECREMENT_EXPR:
1938 case POSTINCREMENT_EXPR:
1940 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
1941 OB_PUTCP (operator_name_info[(int)TREE_CODE (t)].name);
1945 case NON_LVALUE_EXPR:
1946 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
1947 should be another level of INDIRECT_REF so that I don't have to do
1949 if (TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == POINTER_TYPE)
1951 tree next = TREE_TYPE (TREE_TYPE (t));
1953 while (TREE_CODE (next) == POINTER_TYPE)
1954 next = TREE_TYPE (next);
1956 if (TREE_CODE (next) == FUNCTION_TYPE)
1958 if (flags & TS_EXPR_PARENS)
1961 dump_expr (TREE_OPERAND (t, 0), flags & ~TS_EXPR_PARENS);
1962 if (flags & TS_EXPR_PARENS)
1968 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
1972 dump_expr (TREE_OPERAND (t, 0), flags);
1975 case EXPR_WITH_FILE_LOCATION:
1976 dump_expr (EXPR_WFL_NODE (t), flags);
1980 if (TREE_TYPE (t) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t)))
1982 tree idx = build_component_ref (t, index_identifier, NULL_TREE, 0);
1984 if (integer_all_onesp (idx))
1986 tree pfn = PFN_FROM_PTRMEMFUNC (t);
1987 dump_unary_op ("&", pfn, flags | TS_EXPR_PARENS);
1990 else if (TREE_CODE (idx) == INTEGER_CST
1991 && tree_int_cst_equal (idx, integer_zero_node))
1993 /* A NULL pointer-to-member constant. */
1995 dump_type (TREE_TYPE (t), flags);
1999 else if (host_integerp (idx, 0))
2002 unsigned HOST_WIDE_INT n;
2004 t = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t)));
2005 t = TYPE_METHOD_BASETYPE (t);
2006 virtuals = TYPE_BINFO_VIRTUALS (TYPE_MAIN_VARIANT (t));
2008 n = tree_low_cst (idx, 0) - first_vfun_index (t);
2010 /* Map vtable index back one, to allow for the null pointer to
2014 while (n > 0 && virtuals)
2017 virtuals = TREE_CHAIN (virtuals);
2021 dump_expr (BV_FN (virtuals),
2022 flags | TS_EXPR_PARENS);
2028 dump_expr_list (CONSTRUCTOR_ELTS (t), flags);
2034 tree ob = TREE_OPERAND (t, 0);
2035 if (is_dummy_object (ob))
2037 t = TREE_OPERAND (t, 1);
2038 if (TREE_CODE (t) == FUNCTION_DECL)
2040 dump_expr (t, flags | TS_EXPR_PARENS);
2041 else if (BASELINK_P (t))
2042 dump_expr (OVL_CURRENT (TREE_VALUE (t)), flags | TS_EXPR_PARENS);
2044 dump_decl (t, flags);
2048 if (TREE_CODE (ob) == INDIRECT_REF)
2050 dump_expr (TREE_OPERAND (ob, 0), flags | TS_EXPR_PARENS);
2055 dump_expr (ob, flags | TS_EXPR_PARENS);
2058 dump_expr (TREE_OPERAND (t, 1), flags | TS_EXPR_PARENS);
2063 case TEMPLATE_PARM_INDEX:
2064 dump_decl (TEMPLATE_PARM_DECL (t), flags & ~TS_DECL_TYPE);
2067 case IDENTIFIER_NODE:
2072 dump_type (TREE_OPERAND (t, 0), flags);
2074 dump_expr (TREE_OPERAND (t, 1), flags | TS_EXPR_PARENS);
2078 if (TREE_OPERAND (t, 0) == NULL_TREE
2079 || TREE_CHAIN (TREE_OPERAND (t, 0)))
2081 dump_type (TREE_TYPE (t), flags);
2083 dump_expr_list (TREE_OPERAND (t, 0), flags);
2089 dump_type (TREE_TYPE (t), flags);
2092 dump_expr_list (TREE_OPERAND (t, 0), flags);
2098 OB_PUTID (TREE_OPERAND (t, 0));
2102 dump_expr (TREE_OPERAND (t, 0), flags);
2108 if (TREE_CODE (t) == SIZEOF_EXPR)
2109 OB_PUTS ("sizeof (");
2112 my_friendly_assert (TREE_CODE (t) == ALIGNOF_EXPR, 0);
2113 OB_PUTS ("__alignof__ (");
2115 if (TYPE_P (TREE_OPERAND (t, 0)))
2116 dump_type (TREE_OPERAND (t, 0), flags);
2118 dump_unary_op ("*", t, flags | TS_EXPR_PARENS);
2123 OB_PUTS ("{unparsed}");
2126 case TRY_CATCH_EXPR:
2127 case WITH_CLEANUP_EXPR:
2128 case CLEANUP_POINT_EXPR:
2129 dump_expr (TREE_OPERAND (t, 0), flags);
2132 case PSEUDO_DTOR_EXPR:
2133 dump_expr (TREE_OPERAND (t, 2), flags);
2135 dump_type (TREE_OPERAND (t, 0), flags);
2137 dump_type (TREE_OPERAND (t, 1), flags);
2140 case TEMPLATE_ID_EXPR:
2141 dump_decl (t, flags);
2145 /* We don't yet have a way of dumping statements in a
2146 human-readable format. */
2147 OB_PUTS ("{ ... }");
2152 dump_expr (TREE_OPERAND (t, 1), flags & ~TS_EXPR_PARENS);
2157 OB_PUTS ("while (1) { ");
2158 dump_expr (TREE_OPERAND (t, 0), flags & ~TS_EXPR_PARENS);
2164 dump_expr (TREE_OPERAND (t, 0), flags & ~TS_EXPR_PARENS);
2165 OB_PUTS (") break; ");
2169 if (TREE_VALUE (t) && TREE_CODE (TREE_VALUE (t)) == FUNCTION_DECL)
2171 OB_PUTID (DECL_NAME (TREE_VALUE (t)));
2174 /* else fall through */
2176 /* This list is incomplete, but should suffice for now.
2177 It is very important that `sorry' does not call
2178 `report_error_function'. That could cause an infinite loop. */
2180 sorry ("`%s' not supported by dump_expr",
2181 tree_code_name[(int) TREE_CODE (t)]);
2183 /* fall through to ERROR_MARK... */
2185 OB_PUTCP ("{expression error}");
2191 dump_binary_op (opstring, t, flags)
2192 const char *opstring;
2194 enum tree_string_flags flags;
2197 dump_expr (TREE_OPERAND (t, 0), flags | TS_EXPR_PARENS);
2200 OB_PUTCP (opstring);
2202 OB_PUTS ("<unknown operator>");
2204 dump_expr (TREE_OPERAND (t, 1), flags | TS_EXPR_PARENS);
2209 dump_unary_op (opstring, t, flags)
2210 const char *opstring;
2212 enum tree_string_flags flags;
2214 if (flags & TS_EXPR_PARENS)
2216 OB_PUTCP (opstring);
2217 dump_expr (TREE_OPERAND (t, 0), flags & ~TS_EXPR_PARENS);
2218 if (flags & TS_EXPR_PARENS)
2222 /* Exported interface to stringifying types, exprs and decls under TS_*
2226 type_as_string (typ, flags)
2228 enum tree_string_flags flags;
2232 dump_type (typ, flags);
2236 return (char *)obstack_base (&scratch_obstack);
2240 expr_as_string (decl, flags)
2242 enum tree_string_flags flags;
2246 dump_expr (decl, flags);
2250 return (char *)obstack_base (&scratch_obstack);
2254 decl_as_string (decl, flags)
2256 enum tree_string_flags flags;
2260 dump_decl (decl, flags);
2264 return (char *)obstack_base (&scratch_obstack);
2268 context_as_string (context, flags)
2270 enum tree_string_flags flags;
2274 dump_scope (context, flags);
2278 return (char *)obstack_base (&scratch_obstack);
2281 /* Generate the three forms of printable names for lang_printable_name. */
2284 lang_decl_name (decl, v)
2289 return decl_as_string (decl, TS_DECL_TYPE);
2293 if (v == 1 && DECL_CLASS_SCOPE_P (decl))
2295 dump_type (CP_DECL_CONTEXT (decl), TS_PLAIN);
2299 if (TREE_CODE (decl) == FUNCTION_DECL)
2300 dump_function_name (decl, TS_PLAIN);
2302 dump_decl (DECL_NAME (decl), TS_PLAIN);
2306 return (char *)obstack_base (&scratch_obstack);
2313 if (TREE_CODE (t) == PARM_DECL && DECL_CONTEXT (t))
2314 return DECL_SOURCE_FILE (DECL_CONTEXT (t));
2315 else if (TYPE_P (t))
2316 return DECL_SOURCE_FILE (TYPE_MAIN_DECL (t));
2317 else if (TREE_CODE (t) == OVERLOAD)
2318 return DECL_SOURCE_FILE (OVL_FUNCTION (t));
2320 return DECL_SOURCE_FILE (t);
2328 if (TREE_CODE (t) == PARM_DECL && DECL_CONTEXT (t))
2329 line = DECL_SOURCE_LINE (DECL_CONTEXT (t));
2330 if (TREE_CODE (t) == TYPE_DECL && DECL_ARTIFICIAL (t)
2331 && TYPE_MAIN_DECL (TREE_TYPE (t)))
2335 line = DECL_SOURCE_LINE (TYPE_MAIN_DECL (t));
2336 else if (TREE_CODE (t) == OVERLOAD)
2337 line = DECL_SOURCE_LINE (OVL_FUNCTION (t));
2339 line = DECL_SOURCE_LINE (t);
2347 /* Now the interfaces from cp_error et al to dump_type et al. Each takes an
2348 on/off VERBOSE flag and supply the appropriate TS_ flags to a dump_
2352 decl_to_string (decl, verbose)
2356 enum tree_string_flags flags = 0;
2358 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == RECORD_TYPE
2359 || TREE_CODE (decl) == UNION_TYPE || TREE_CODE (decl) == ENUMERAL_TYPE)
2360 flags = TS_AGGR_TAGS;
2362 flags |= TS_DECL_TYPE | TS_DECORATE | TS_PARM_DEFAULTS;
2363 else if (TREE_CODE (decl) == FUNCTION_DECL)
2364 flags |= TS_DECL_TYPE | TS_FUNC_NORETURN;
2365 flags |= TS_TEMPLATE_PREFIX;
2369 dump_decl (decl, flags);
2373 return (char *)obstack_base (&scratch_obstack);
2377 expr_to_string (decl, verbose)
2379 int verbose ATTRIBUTE_UNUSED;
2383 dump_expr (decl, 0);
2387 return (char *)obstack_base (&scratch_obstack);
2391 fndecl_to_string (fndecl, verbose)
2395 enum tree_string_flags flags;
2397 flags = TS_FUNC_THROW | TS_DECL_TYPE;
2399 flags |= TS_PARM_DEFAULTS;
2402 dump_decl (fndecl, flags);
2406 return (char *)obstack_base (&scratch_obstack);
2411 code_to_string (c, v)
2413 int v ATTRIBUTE_UNUSED;
2415 return tree_code_name [c];
2419 language_to_string (c, v)
2421 int v ATTRIBUTE_UNUSED;
2428 case lang_cplusplus:
2435 my_friendly_abort (355);
2440 /* Return the proper printed version of a parameter to a C++ function. */
2443 parm_to_string (p, v)
2445 int v ATTRIBUTE_UNUSED;
2450 sprintf (digit_buffer, "%d", p+1);
2451 return digit_buffer;
2457 int v ATTRIBUTE_UNUSED;
2461 id = operator_name_info[(int) p].identifier;
2462 return id ? IDENTIFIER_POINTER (id) : "{unknown}";
2466 type_to_string (typ, verbose)
2470 enum tree_string_flags flags;
2474 flags |= TS_AGGR_TAGS;
2475 flags |= TS_TEMPLATE_PREFIX;
2479 dump_type (typ, flags);
2483 return (char *)obstack_base (&scratch_obstack);
2487 assop_to_string (p, v)
2489 int v ATTRIBUTE_UNUSED;
2493 id = assignment_operator_name_info[(int) p].identifier;
2494 return id ? IDENTIFIER_POINTER (id) : "{unknown}";
2498 args_to_string (p, verbose)
2502 enum tree_string_flags flags = 0;
2504 flags |= TS_AGGR_TAGS;
2509 if (TYPE_P (TREE_VALUE (p)))
2510 return type_as_string (p, flags);
2513 for (; p; p = TREE_CHAIN (p))
2515 if (TREE_VALUE (p) == null_node)
2518 dump_type (error_type (TREE_VALUE (p)), flags);
2523 return (char *)obstack_base (&scratch_obstack);
2529 int v ATTRIBUTE_UNUSED;
2533 dump_qualifiers (p, before);
2537 return (char *)obstack_base (&scratch_obstack);
2541 lang_print_error_function (file)
2546 default_print_error_function (file);
2547 os = output_buffer_state (diagnostic_buffer);
2548 output_set_prefix (diagnostic_buffer, file);
2549 maybe_print_instantiation_context (diagnostic_buffer);
2550 output_buffer_state (diagnostic_buffer) = os;
2554 cp_diagnostic_starter (buffer, dc)
2555 output_buffer *buffer;
2556 diagnostic_context *dc;
2558 report_problematic_module (buffer);
2559 cp_print_error_function (buffer, dc);
2560 maybe_print_instantiation_context (buffer);
2561 output_set_prefix (buffer,
2562 context_as_prefix (diagnostic_file_location (dc),
2563 diagnostic_line_location (dc),
2564 diagnostic_is_warning (dc)));
2568 cp_diagnostic_finalizer (buffer, dc)
2569 output_buffer *buffer;
2570 diagnostic_context *dc __attribute__ ((__unused__));
2572 output_destroy_prefix (buffer);
2575 /* Print current function onto BUFFER, in the process of reporting
2576 a diagnostic message. Called from cp_diagnostic_starter. */
2578 cp_print_error_function (buffer, dc)
2579 output_buffer *buffer;
2580 diagnostic_context *dc;
2582 if (error_function_changed ())
2584 char *prefix = diagnostic_file_location (dc)
2585 ? file_name_as_prefix (diagnostic_file_location (dc))
2589 os = output_buffer_state (buffer);
2590 output_set_prefix (buffer, prefix);
2592 if (current_function_decl == NULL)
2593 output_add_string (buffer, "At global scope:");
2596 (buffer, "In %s `%s':", function_category (current_function_decl),
2597 (*decl_printable_name) (current_function_decl, 2));
2598 output_add_newline (buffer);
2600 record_last_error_function ();
2601 output_destroy_prefix (buffer);
2602 output_buffer_state (buffer) = os;
2606 /* Returns a description of FUNCTION using standard terminology. */
2608 function_category (fn)
2611 if (DECL_FUNCTION_MEMBER_P (fn))
2613 if (DECL_STATIC_FUNCTION_P (fn))
2614 return "static member function";
2615 else if (DECL_COPY_CONSTRUCTOR_P (fn))
2616 return "copy constructor";
2617 else if (DECL_CONSTRUCTOR_P (fn))
2618 return "constructor";
2619 else if (DECL_DESTRUCTOR_P (fn))
2620 return "destructor";
2622 return "member function";
2628 /* Report the full context of a current template instantiation,
2631 print_instantiation_full_context (buffer)
2632 output_buffer *buffer;
2634 tree p = current_instantiation ();
2636 const char *file = input_filename;
2640 if (current_function_decl != TINST_DECL (p)
2641 && current_function_decl != NULL_TREE)
2642 /* We can get here during the processing of some synthesized
2643 method. Then, TINST_DECL (p) will be the function that's causing
2648 if (current_function_decl == TINST_DECL (p))
2649 /* Avoid redundancy with the the "In function" line. */;
2651 output_verbatim (buffer, "%s: In instantiation of `%s':\n", file,
2652 decl_as_string (TINST_DECL (p),
2653 TS_DECL_TYPE | TS_FUNC_NORETURN));
2655 line = TINST_LINE (p);
2656 file = TINST_FILE (p);
2661 print_instantiation_partial_context (buffer, p, file, line);
2664 /* Same as above but less verbose. */
2666 print_instantiation_partial_context (buffer, t, file, line)
2667 output_buffer *buffer;
2672 for (; t; t = TREE_CHAIN (t))
2675 (buffer, "%s:%d: instantiated from `%s'\n", file, line,
2676 decl_as_string (TINST_DECL (t), TS_DECL_TYPE | TS_FUNC_NORETURN));
2677 line = TINST_LINE (t);
2678 file = TINST_FILE (t);
2680 output_verbatim (buffer, "%s:%d: instantiated from here\n", file, line);
2683 /* Called from cp_thing to print the template context for an error. */
2685 maybe_print_instantiation_context (buffer)
2686 output_buffer *buffer;
2688 if (!problematic_instantiation_changed () || current_instantiation () == 0)
2691 record_last_problematic_instantiation ();
2692 print_instantiation_full_context (buffer);
2695 /* Report the bare minimum context of a template instantiation. */
2697 print_instantiation_context ()
2699 print_instantiation_partial_context
2700 (diagnostic_buffer, current_instantiation (), input_filename, lineno);
2701 flush_diagnostic_buffer ();
2704 /* Called from output_format -- during diagnostic message processing --
2705 to handle C++ specific format specifier with the following meanings:
2706 %A function argument-list.
2709 %F function declaration.
2710 %P function parameter whose position is indicated by an integer.
2714 cp_tree_printer (buffer)
2715 output_buffer *buffer;
2718 tree_formatting_info tfi;
2720 bzero (&tfi, sizeof (tree_formatting_info));
2722 if (*output_buffer_text_cursor (buffer) == '+')
2723 ++output_buffer_text_cursor (buffer);
2724 if (*output_buffer_text_cursor (buffer) == '#')
2727 ++output_buffer_text_cursor (buffer);
2730 switch (*output_buffer_text_cursor (buffer))
2733 tree_being_formatted (&tfi) =
2734 va_arg (output_buffer_format_args (buffer), tree);
2736 tree_formatting_flags (&tfi) = TFF_SCOPE
2737 | TFF_FUNCTION_DEFAULT_ARGUMENTS;
2738 print_function_argument_list (buffer, &tfi);
2742 tree_being_formatted (&tfi) =
2743 va_arg (output_buffer_format_args (buffer), tree);
2745 tree_formatting_flags (&tfi) = TFF_SCOPE | TFF_DECL_SPECIFIERS
2746 | TFF_CLASS_KEY_OR_ENUM | TFF_RETURN_TYPE
2747 | TFF_FUNCTION_DEFAULT_ARGUMENTS | TFF_TEMPLATE_DEFAULT_ARGUMENTS
2748 | TFF_EXCEPTION_SPECIFICATION | TFF_CHASE_NAMESPACE_ALIAS;
2749 print_declaration (buffer, &tfi);
2753 tree_being_formatted (&tfi) =
2754 va_arg (output_buffer_format_args (buffer), tree);
2756 tree_formatting_flags (&tfi) = TFF_SCOPE;
2757 print_expression (buffer, &tfi);
2761 tree_being_formatted (&tfi) =
2762 va_arg (output_buffer_format_args (buffer), tree);
2764 tree_formatting_flags (&tfi) = TFF_SCOPE | TFF_DECL_SPECIFIERS
2765 | TFF_RETURN_TYPE | TFF_FUNCTION_DEFAULT_ARGUMENTS
2766 | TFF_EXCEPTION_SPECIFICATION;
2767 print_function_declaration (buffer, &tfi);
2771 print_function_parameter
2772 (buffer, va_arg (output_buffer_format_args (buffer), int));
2776 tree_being_formatted (&tfi) =
2777 va_arg (output_buffer_format_args (buffer), tree);
2779 tree_formatting_flags (&tfi) = TFF_SCOPE | TFF_CLASS_KEY_OR_ENUM
2780 | TFF_RETURN_TYPE | TFF_EXCEPTION_SPECIFICATION;
2781 print_type_id (buffer, &tfi);
2785 tree_being_formatted (&tfi) =
2786 va_arg (output_buffer_format_args (buffer), tree);
2787 print_cv_qualifier_seq (buffer, &tfi);
2797 /* Print a function argument-list represented by tree_being_formatted (TFI)
2800 print_function_argument_list (buffer, tfi)
2801 output_buffer *buffer __attribute__ ((__unused__));
2802 tfi_t tfi __attribute__ ((__unused__));
2806 /* Print a declaration represented by tree_being_formatted (TFI)
2809 print_declaration (buffer, tfi)
2810 output_buffer *buffer __attribute__ ((__unused__));
2811 tfi_t tfi __attribute__ ((__unused__));
2815 /* Print an expression represented by tree_being_formatted (TFI)
2818 print_expression (buffer, tfi)
2819 output_buffer *buffer __attribute__ ((__unused__));
2820 tfi_t tfi __attribute__ ((__unused__));
2824 /* Print a function declaration represented by tree_being_formatted (TFI)
2827 print_function_declaration (buffer, tfi)
2828 output_buffer *buffer __attribute__ ((__unused__));
2829 tfi_t tfi __attribute__ ((__unused__));
2833 /* Print the N'th function parameter onto BUFFER. A negative value of N
2834 means the implicit "this" parameter of a member function. */
2836 print_function_parameter (buffer, n)
2837 output_buffer *buffer;
2841 print_identifier (buffer, "this");
2843 output_decimal (buffer, n + 1);
2846 /* Print a type represented by tree_being_formatted (TFI) onto BUFFER. */
2848 print_type_id (buffer, tfi)
2849 output_buffer *buffer;
2852 tree t = tree_being_formatted (tfi);
2853 int flags = tree_formatting_flags (tfi);
2857 if (flags & TFF_CHASE_TYPEDEF)
2858 tree_being_formatted (tfi) =
2859 typedef_original_name (tree_being_formatted (tfi));
2861 /* A type-id is of the form:
2863 type-specifier-seq abstract-declarator(opt) */
2864 print_type_specifier_seq (buffer, tfi);
2866 if (TYPE_PTRMEMFUNC_P (t))
2869 /* For types with abstract-declarator, print_type_specifier_seq prints
2870 the start of the abstract-declarator. Fiinish the job. */
2871 switch (TREE_CODE (t))
2875 case REFERENCE_TYPE:
2880 print_rest_of_abstract_declarator (buffer, tfi);
2886 tree_being_formatted (tfi) = t;
2889 /* Print the type-specifier-seq part of a type-id. If appropriate, print
2890 also the prefix of the abstract-declarator. */
2892 print_type_specifier_seq (buffer, tfi)
2893 output_buffer *buffer;
2896 int flags = tree_formatting_flags (tfi);
2897 tree t = tree_being_formatted (tfi);
2898 enum tree_code code = TREE_CODE (t);
2900 /* A type-speficier-seq is:
2901 type-specifier type-specifier-seq(opt)
2904 simple-type-specifier
2907 elaborated-type-specifier
2910 We do not, however, pretty-print class-specifier nor enum-specifier. */
2915 case IDENTIFIER_NODE:
2925 case TEMPLATE_TYPE_PARM:
2927 case TEMPLATE_TEMPLATE_PARM:
2930 print_cv_qualifier_seq (buffer, tfi);
2931 if ((flags & TFF_DECL_SPECIFIERS)
2932 && (code == TYPENAME_TYPE || IS_AGGR_TYPE (t)))
2933 print_elaborated_type_specifier (buffer, tfi);
2935 print_simple_type_specifier (buffer, tfi);
2938 /* Because the abstract-declarator can modify the type-specifier-seq
2939 in a highly non linear manner, we pretty-print its prefix here.
2940 The suffix part is handled by print_rest_of_abstract_declarator. */
2942 /* A RECORD_TYPE is also used to represent a pointer to member
2945 if (TYPE_PTRMEMFUNC_P (t))
2947 /* Print the return type. */
2948 tree_being_formatted (tfi) =
2949 TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (t));
2950 print_type_id (buffer, tfi);
2951 print_whitespace (buffer, tfi);
2953 /* Then the beginning of the abstract-declarator part. */
2954 tree_being_formatted (tfi) =
2955 TYPE_METHOD_BASETYPE (TYPE_PTRMEMFUNC_FN_TYPE (t));
2956 print_left_paren (buffer);
2957 print_nested_name_specifier (buffer, tfi);
2964 if (TYPE_PTRMEM_P (t))
2965 goto ptr_data_member;
2967 goto non_ptr_data_member;
2971 case REFERENCE_TYPE:
2974 non_ptr_data_member:
2975 tree_being_formatted (tfi) = TREE_TYPE (t);
2976 print_type_specifier_seq (buffer, tfi);
2977 if (code == POINTER_TYPE || code == REFERENCE_TYPE)
2979 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
2980 print_left_paren (buffer);
2982 else if (code == FUNCTION_TYPE || code == METHOD_TYPE)
2984 print_whitespace (buffer, tfi);
2985 print_left_paren (buffer);
2986 if (code == METHOD_TYPE)
2988 tree_being_formatted (tfi) = TYPE_METHOD_BASETYPE (t);
2989 print_nested_name_specifier (buffer, tfi);
2990 tree_being_formatted (tfi) = t;
2993 tree_being_formatted (tfi) = t;
2998 /* Firstly, the type of the member. */
2999 tree_being_formatted (tfi) = TREE_TYPE (t);
3000 print_type_id (buffer, tfi);
3001 print_whitespace (buffer, tfi);
3003 /* Then, the containing class. */
3004 tree_being_formatted (tfi) = TYPE_OFFSET_BASETYPE (t);
3005 print_nested_name_specifier (buffer, tfi);
3006 tree_being_formatted (tfi) = t;
3010 sorry_for_unsupported_tree (t);
3014 print_identifier (buffer, "{type-specifier-seq error}");
3018 tree_being_formatted (tfi) = t;
3021 /* Print the simpe-type-specifier component of a type-specifier. */
3023 print_simple_type_specifier (buffer, tfi)
3024 output_buffer *buffer;
3027 int flags = tree_formatting_flags (tfi);
3028 tree t = tree_being_formatted (tfi);
3029 enum tree_code code = TREE_CODE (t);
3034 print_identifier (buffer, "{unknown type}");
3037 case IDENTIFIER_NODE:
3038 print_tree_identifier (buffer, t);
3042 print_identifier (buffer, "__complex__ ");
3043 tree_being_formatted (tfi) = TREE_TYPE (t);
3044 print_type_id (buffer, tfi);
3048 tree_being_formatted (tfi) = TYPE_CONTEXT (t);
3049 print_nested_name_specifier (buffer, tfi);
3050 tree_being_formatted (tfi) = TYPENAME_TYPE_FULLNAME (t);
3051 tree_formatting_flags (tfi) |= ~TFF_CHASE_TYPEDEF;
3052 print_type_id (buffer, tfi);
3056 print_identifier (buffer, "__typeof__");
3057 tree_being_formatted (tfi) = TYPE_FIELDS (t);
3058 print_left_paren (buffer);
3059 print_expression (buffer, tfi);
3060 print_right_paren (buffer);
3064 if (TREE_UNSIGNED (t))
3066 if (TYPE_MAIN_VARIANT (t) == integer_type_node)
3067 /* We don't want pedantry like `unsigned int'. */;
3068 else if (!TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)))
3070 print_identifier (buffer, "unsigned");
3071 print_whitespace (buffer, tfi);
3074 else if (TYPE_MAIN_VARIANT (t) == char_type_node)
3076 print_identifier (buffer, "signed");
3077 print_whitespace (buffer, tfi);
3083 tree s = (flags & TFF_CHASE_TYPEDEF) ? TYPE_MAIN_VARIANT (t) : t;
3085 if (TYPE_NAME (s) && TYPE_IDENTIFIER (s))
3086 print_tree_identifier (buffer, TYPE_IDENTIFIER (s));
3088 /* Types like intQI_type_node and friends have no names.
3089 These don't come up in user error messages, but it's nice
3090 to be able to print them from the debugger. */
3091 print_identifier (buffer, "{anonymous}");
3095 case TEMPLATE_TEMPLATE_PARM:
3096 if (TYPE_IDENTIFIER (t))
3097 print_tree_identifier (buffer, TYPE_IDENTIFIER (t));
3099 print_identifier (buffer, "{anonymous template template parameter}");
3103 if (flags & TFF_CHASE_TYPEDEF)
3104 print_type_id (buffer, tfi);
3106 print_tree_identifier (buffer, DECL_NAME (t));
3109 case BOUND_TEMPLATE_TEMPLATE_PARM:
3111 print_template_id (buffer, tfi);
3114 case TEMPLATE_TYPE_PARM:
3115 if (TYPE_IDENTIFIER (t))
3116 print_tree_identifier (buffer, TYPE_IDENTIFIER (t));
3118 print_identifier (buffer, "{anonymous template type parameter}");
3125 tree_being_formatted (tfi) = t;
3126 tree_formatting_flags (tfi) = flags;
3129 /* Print the elaborated-type-specifier form of a type-specifier. */
3131 print_elaborated_type_specifier (buffer, tfi)
3132 output_buffer *buffer;
3135 int flags = tree_formatting_flags (tfi);
3136 tree t = tree_being_formatted (tfi);
3138 switch (TREE_CODE (t))
3141 print_identifier (buffer, "typename");
3142 print_whitespace (buffer, tfi);
3143 tree_formatting_flags (tfi) |= ~TFF_DECL_SPECIFIERS;
3144 print_simple_type_specifier (buffer, tfi);
3150 tree name = NULL_TREE;
3152 if (flags & TFF_CHASE_TYPEDEF)
3153 tree_being_formatted (tfi) = typedef_original_name (t);
3156 (buffer, class_key_or_enum (tree_being_formatted (tfi)));
3157 print_whitespace (buffer, tfi);
3159 name = TYPE_NAME (tree_being_formatted (tfi));
3162 if (flags & TFF_SCOPE)
3164 tree_being_formatted (tfi) = CP_DECL_CONTEXT (name);
3165 print_nested_name_specifier (buffer, tfi);
3167 print_tree_identifier (buffer, DECL_NAME (name));
3170 print_identifier (buffer, "{anonymous}");
3175 sorry_for_unsupported_tree (t);
3179 tree_being_formatted (tfi) = t;
3180 tree_formatting_flags (tfi) = flags;
3183 /* Finish the job of printing the abstract-declarator part of a
3186 print_rest_of_abstract_declarator (buffer, tfi)
3187 output_buffer *buffer;
3190 tree t = tree_being_formatted (tfi);
3191 enum tree_code code = TREE_CODE (t);
3193 /* An abstract-declarator has the form:
3195 abstract-declarator:
3196 ptr-operator abstract-declarator(opt)
3197 direct-abstract-declarator
3199 direct-abstract-declarator:
3200 direct-abstract-declarator(opt)
3201 ( parameter-declaration-clause ) cv-qualifier-seq(opt)
3202 exception-specification(opt)
3203 direct-abstract-declarator(opt) [ constant-expression(opt) ]
3204 ( direct-abstract-declarator ) */
3209 print_left_bracket (buffer);
3210 if (TYPE_DOMAIN (t))
3212 tree s = TYPE_DOMAIN (t);
3214 if (host_integerp (TYPE_MAX_VALUE (s), 0))
3215 output_decimal (buffer, tree_low_cst (TYPE_MAX_VALUE (s), 0) + 1);
3216 else if (TREE_CODE (TYPE_MAX_VALUE (s)) == MINUS_EXPR)
3218 tree_being_formatted (tfi) =
3219 TREE_OPERAND (TYPE_MAX_VALUE (s), 0);
3220 print_expression (buffer, tfi);
3221 tree_being_formatted (tfi) = t;
3225 tree_being_formatted (tfi) = fold
3226 (cp_build_binary_op (PLUS_EXPR, TYPE_MAX_VALUE (s),
3228 print_expression (buffer, tfi);
3229 tree_being_formatted (tfi) = t;
3232 print_right_bracket (buffer);
3233 put_whitespace (tfi) = none;
3234 tree_being_formatted (tfi) = TREE_TYPE (t);
3235 print_rest_of_abstract_declarator (buffer, tfi);
3236 tree_being_formatted (tfi) = t;
3240 case REFERENCE_TYPE:
3242 if (code == POINTER_TYPE || code == REFERENCE_TYPE)
3244 output_add_character (buffer, "&*"[code == POINTER_TYPE]);
3245 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
3246 print_right_paren (buffer);
3248 put_whitespace (tfi) = before;
3249 print_cv_qualifier_seq (buffer, tfi);
3250 tree_being_formatted (tfi) = TREE_TYPE (t);
3251 print_rest_of_abstract_declarator (buffer, tfi);
3252 tree_being_formatted (tfi) = t;
3257 print_right_paren (buffer);
3258 print_whitespace (buffer, tfi);
3260 /* Skip the `this' implicit parameter if present. */
3261 tree_being_formatted (tfi) = TYPE_ARG_TYPES (t);
3262 if (code == METHOD_TYPE)
3263 tree_being_formatted (tfi) = TREE_CHAIN (tree_being_formatted (tfi));
3265 /* Print the parameter-list. */
3266 print_left_paren (buffer);
3267 print_parameter_declaration_clause (buffer, tfi);
3268 print_right_paren (buffer);
3270 print_whitespace (buffer, tfi);
3272 if (code == METHOD_TYPE)
3274 tree_being_formatted (tfi) =
3275 TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t)));
3276 print_cv_qualifier_seq (buffer, tfi);
3279 /* Finish the abstract-declarator. */
3280 tree_being_formatted (tfi) = TREE_TYPE (t);
3281 print_rest_of_abstract_declarator (buffer, tfi);
3283 /* Print the exception-specification for documentaion purpose. */
3284 tree_being_formatted (tfi) = TYPE_RAISES_EXCEPTIONS (t);
3285 print_exception_specification (buffer, tfi);
3286 tree_being_formatted (tfi) = t;
3289 /* These types don't have abstract-declarator. */
3291 case IDENTIFIER_NODE:
3301 case TEMPLATE_TYPE_PARM:
3303 case TEMPLATE_TEMPLATE_PARM:
3308 sorry_for_unsupported_tree (t);
3309 /* fall throught. */
3315 /* Print the cv-quafilers of tree_being_formatted (TFI) onto BUFFER. */
3317 print_cv_qualifier_seq (buffer, tfi)
3318 output_buffer *buffer;
3319 tree_formatting_info *tfi;
3321 int cv = TYPE_QUALS (tree_being_formatted (tfi));
3322 int pad_after = after == put_whitespace (tfi);
3323 static const int mask[]
3324 = {TYPE_QUAL_CONST, TYPE_QUAL_VOLATILE, TYPE_QUAL_RESTRICT};
3325 static const char *const qualifier[]
3326 = { "const", "volatile", "__restrict__" };
3331 for (i = 0; i != 3; ++i)
3334 if (put_whitespace (tfi) == before)
3335 output_add_space (buffer);
3336 print_identifier (buffer, qualifier[i]);
3337 put_whitespace (tfi) = before;
3342 output_add_space (buffer);
3343 put_whitespace (tfi) = none;
3349 print_parameter_declaration_clause (buffer, tfi)
3350 output_buffer *buffer __attribute__ ((__unused__));
3351 tfi_t tfi __attribute__ ((__unused__));
3356 print_exception_specification (buffer, tfi)
3357 output_buffer *buffer __attribute__ ((__unused__));
3358 tfi_t tfi __attribute__ ((__unused__));
3363 print_nested_name_specifier (buffer, tfi)
3364 output_buffer *buffer;
3367 int flags = tree_formatting_flags (tfi);
3368 tree t = tree_being_formatted (tfi);
3369 /* A nested-name-specifier is:
3370 class-or-namespace-name :: nested-name-specifier(opt)
3371 class-or-namespace-name :: template nested-name-specifier
3373 The latter form being the correct syntax for a name designating
3374 a template member, where the preceding class-or-namespace-name part
3375 is name-dependent. For the time being, we do not do such a
3376 sophisticated pretty-printing.
3378 class-or-namespace-name:
3382 if (t == NULL_TREE || t == global_namespace)
3385 if (CLASS_TYPE_P (t) && !(flags & TFF_CLASS_SCOPE))
3388 if (TREE_CODE (t) == NAMESPACE_DECL && !(flags & TFF_NAMESPACE_SCOPE))
3391 tree_being_formatted (tfi) = DECL_CONTEXT (t);
3392 print_nested_name_specifier (buffer, tfi);
3393 print_scope_operator (buffer);
3394 if (TREE_CODE (t) == NAMESPACE_DECL)
3395 print_tree_identifier (buffer, DECL_NAME (t));
3396 else if (CLASS_TYPE_P (t))
3398 if (!DECL_USE_TEMPLATE (t))
3399 print_tree_identifier (buffer, TYPE_IDENTIFIER (t));
3402 tree_being_formatted (tfi) = t;
3403 print_template_id (buffer, tfi);
3407 tree_being_formatted (tfi) = t;
3411 print_template_id (buffer, tfi)
3412 output_buffer *buffer;
3413 tfi_t tfi __attribute__ ((__unused__));
3415 print_template_argument_list_start (buffer);
3417 print_template_argument_list_end (buffer);
3421 typedef_original_name (t)
3424 return DECL_ORIGINAL_TYPE (t) ? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t);
3428 print_template_argument_list_start (buffer)
3429 output_buffer *buffer __attribute__ ((__unused__));
3434 print_template_argument_list_end (buffer)
3435 output_buffer *buffer __attribute__ ((__unused__));