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 /* This data structure bundles altogether, all the information necessary
33 for pretty-printing a C++ source-level entity represented by a tree. */
39 } tree_formatting_info
, *tfi_t
;
41 #define tree_being_formatted(TFI) (TFI)->decl
42 #define tree_formatting_flags(TFI) (TFI)->flags
43 #define put_whitespace(TFI) (TFI)->pad
45 #define sorry_for_unsupported_tree(T) \
46 sorry ("`%s' not supported by %s", tree_code_name[(int) TREE_CODE (T)], \
49 #define print_scope_operator(BUFFER) output_add_string (BUFFER, "::")
50 #define print_left_paren(BUFFER) output_add_character (BUFFER, '(')
51 #define print_right_paren(BUFFER) output_add_character (BUFFER, ')')
52 #define print_left_bracket(BUFFER) output_add_character (BUFFER, '[')
53 #define print_right_bracket(BUFFER) output_add_character (BUFFER, ']')
54 #define print_template_argument_list_start(BUFFER) \
55 print_non_consecutive_character (BUFFER, '<')
56 #define print_template_argument_list_end(BUFFER) \
57 print_non_consecutive_character (BUFFER, '>')
58 #define print_whitespace(BUFFER, TFI) \
60 output_add_space (BUFFER); \
61 put_whitespace (TFI) = none; \
63 #define print_tree_identifier(BUFFER, TID) \
64 output_add_string (BUFFER, IDENTIFIER_POINTER (TID))
65 #define print_identifier(BUFFER, ID) output_add_string (BUFFER, ID)
66 #define separate_with_comma(BUFFER) output_add_string (BUFFER, ", ")
68 /* The global buffer where we dump everything. It is there only for
69 transitional purpose. It is expected, in the near future, to be
70 completely removed. */
71 static output_buffer scratch_buffer_rec
;
72 static output_buffer
*scratch_buffer
= &scratch_buffer_rec
;
74 # define NEXT_CODE(t) (TREE_CODE (TREE_TYPE (t)))
76 #define reinit_global_formatting_buffer() \
77 output_clear_message_text (scratch_buffer)
79 static const char *args_to_string
PARAMS ((tree
, int));
80 static const char *assop_to_string
PARAMS ((enum tree_code
, int));
81 static const char *code_to_string
PARAMS ((enum tree_code
, int));
82 static const char *cv_to_string
PARAMS ((tree
, int));
83 static const char *decl_to_string
PARAMS ((tree
, int));
84 static const char *expr_to_string
PARAMS ((tree
, int));
85 static const char *fndecl_to_string
PARAMS ((tree
, int));
86 static const char *op_to_string
PARAMS ((enum tree_code
, int));
87 static const char *parm_to_string
PARAMS ((int, int));
88 static const char *type_to_string
PARAMS ((tree
, int));
90 static void dump_type
PARAMS ((tree
, int));
91 static void dump_typename
PARAMS ((tree
, int));
92 static void dump_simple_decl
PARAMS ((tree
, tree
, int));
93 static void dump_decl
PARAMS ((tree
, int));
94 static void dump_template_decl
PARAMS ((tree
, int));
95 static void dump_function_decl
PARAMS ((tree
, int));
96 static void dump_expr
PARAMS ((tree
, int));
97 static void dump_unary_op
PARAMS ((const char *, tree
, int));
98 static void dump_binary_op
PARAMS ((const char *, tree
, int));
99 static void dump_aggr_type
PARAMS ((tree
, int));
100 static enum pad dump_type_prefix
PARAMS ((tree
, int));
101 static void dump_type_suffix
PARAMS ((tree
, int));
102 static void dump_function_name
PARAMS ((tree
, int));
103 static void dump_expr_list
PARAMS ((tree
, int));
104 static void dump_global_iord
PARAMS ((tree
));
105 static enum pad dump_qualifiers
PARAMS ((tree
, enum pad
));
106 static void dump_char
PARAMS ((int));
107 static void dump_parameters
PARAMS ((tree
, int));
108 static void dump_exception_spec
PARAMS ((tree
, int));
109 static const char *class_key_or_enum
PARAMS ((tree
));
110 static tree ident_fndecl
PARAMS ((tree
));
111 static void dump_template_argument
PARAMS ((tree
, int));
112 static void dump_template_argument_list
PARAMS ((tree
, int));
113 static void dump_template_parameter
PARAMS ((tree
, int));
114 static void dump_template_bindings
PARAMS ((tree
, tree
));
115 static void dump_scope
PARAMS ((tree
, int));
116 static void dump_template_parms
PARAMS ((tree
, int, int));
118 static const char *function_category
PARAMS ((tree
));
119 static void lang_print_error_function
PARAMS ((const char *));
120 static void maybe_print_instantiation_context
PARAMS ((output_buffer
*));
121 static void print_instantiation_full_context
PARAMS ((output_buffer
*));
122 static void print_instantiation_partial_context
PARAMS ((output_buffer
*, tree
,
124 static void cp_diagnostic_starter
PARAMS ((output_buffer
*,
125 diagnostic_context
*));
126 static void cp_diagnostic_finalizer
PARAMS ((output_buffer
*,
127 diagnostic_context
*));
128 static void cp_print_error_function
PARAMS ((output_buffer
*,
129 diagnostic_context
*));
131 static int cp_tree_printer
PARAMS ((output_buffer
*));
132 static void print_function_argument_list
PARAMS ((output_buffer
*, tfi_t
));
133 static void print_declaration
PARAMS ((output_buffer
*, tfi_t
));
134 static void print_expression
PARAMS ((output_buffer
*, tfi_t
));
135 static void print_integer
PARAMS ((output_buffer
*, HOST_WIDE_INT
));
136 static void print_function_declaration
PARAMS ((output_buffer
*, tfi_t
));
137 static void print_function_parameter
PARAMS ((output_buffer
*, int));
138 static void print_type_id
PARAMS ((output_buffer
*, tfi_t
));
139 static void print_cv_qualifier_seq
PARAMS ((output_buffer
*, tfi_t
));
140 static void print_type_specifier_seq
PARAMS ((output_buffer
*, tfi_t
));
141 static void print_simple_type_specifier
PARAMS ((output_buffer
*, tfi_t
));
142 static void print_elaborated_type_specifier
PARAMS ((output_buffer
*, tfi_t
));
143 static void print_rest_of_abstract_declarator
PARAMS ((output_buffer
*,
145 static void print_parameter_declaration_clause
PARAMS ((output_buffer
*,
147 static void print_exception_specification
PARAMS ((output_buffer
*, tfi_t
));
148 static void print_nested_name_specifier
PARAMS ((output_buffer
*, tfi_t
));
149 static void print_template_id
PARAMS ((output_buffer
*, tfi_t
));
150 static tree typedef_original_name
PARAMS ((tree
));
151 static void print_non_consecutive_character
PARAMS ((output_buffer
*, int));
153 #define A args_to_string
154 #define C code_to_string
155 #define D decl_to_string
156 #define E expr_to_string
157 #define F fndecl_to_string
158 #define L language_to_string
159 #define O op_to_string
160 #define P parm_to_string
161 #define Q assop_to_string
162 #define T type_to_string
163 #define V cv_to_string
165 #define o (cp_printer *) 0
166 cp_printer
* cp_printers
[256] =
168 /*0 1 2 3 4 5 6 7 8 9 A B C D E F */
169 o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, /* 0x00 */
170 o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, /* 0x10 */
171 o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, /* 0x20 */
172 o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, /* 0x30 */
173 o
, A
, o
, C
, D
, E
, F
, o
, o
, o
, o
, o
, L
, o
, o
, O
, /* 0x40 */
174 P
, Q
, o
, o
, T
, o
, V
, o
, o
, o
, o
, o
, o
, o
, o
, o
, /* 0x50 */
175 o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, /* 0x60 */
176 o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, /* 0x70 */
193 init_output_buffer (scratch_buffer
, /* prefix */NULL
, /* line-width */0);
195 print_error_function
= lang_print_error_function
;
196 lang_diagnostic_starter
= cp_diagnostic_starter
;
197 lang_diagnostic_finalizer
= cp_diagnostic_finalizer
;
199 lang_printer
= cp_tree_printer
;
202 /* Dump a scope, if deemed necessary. */
205 dump_scope (scope
, flags
)
209 int f
= ~TFF_RETURN_TYPE
& (TFF_DECL_SPECIFIERS
210 | (flags
& (TFF_SCOPE
| TFF_CHASE_TYPEDEF
)));
212 if (scope
== NULL_TREE
)
215 if (TREE_CODE (scope
) == NAMESPACE_DECL
)
217 if (scope
!= global_namespace
)
219 dump_decl (scope
, f
);
220 print_scope_operator (scratch_buffer
);
223 else if (AGGREGATE_TYPE_P (scope
))
225 dump_type (scope
, f
);
226 print_scope_operator (scratch_buffer
);
228 else if ((flags
& TFF_SCOPE
) && TREE_CODE (scope
) == FUNCTION_DECL
)
230 dump_function_decl (scope
, f
);
231 print_scope_operator (scratch_buffer
);
235 /* Dump type qualifiers, providing padding as requested. Return an
236 indication of whether we dumped something. */
239 dump_qualifiers (t
, p
)
243 static const int masks
[] =
244 {TYPE_QUAL_CONST
, TYPE_QUAL_VOLATILE
, TYPE_QUAL_RESTRICT
};
245 static const char *const names
[] =
246 {"const", "volatile", "__restrict"};
248 int quals
= TYPE_QUALS (t
);
249 int do_after
= p
== after
;
253 for (ix
= 0; ix
!= 3; ix
++)
254 if (masks
[ix
] & quals
)
257 output_add_space (scratch_buffer
);
259 print_identifier (scratch_buffer
, names
[ix
]);
262 output_add_space (scratch_buffer
);
269 /* This must be large enough to hold any printed integer or floating-point
271 static char digit_buffer
[128];
273 /* Dump the template ARGument under control of FLAGS. */
276 dump_template_argument (arg
, flags
)
280 if (TYPE_P (arg
) || TREE_CODE (arg
) == TEMPLATE_DECL
)
281 dump_type (arg
, flags
& ~TFF_CLASS_KEY_OR_ENUM
);
283 dump_expr (arg
, (flags
| TFF_EXPR_IN_PARENS
) & ~TFF_CLASS_KEY_OR_ENUM
);
286 /* Dump a template-argument-list ARGS (always a TREE_VEC) under control
290 dump_template_argument_list (args
, flags
)
294 int n
= TREE_VEC_LENGTH (args
);
298 for (i
= 0; i
< n
; ++i
)
301 separate_with_comma (scratch_buffer
);
302 dump_template_argument (TREE_VEC_ELT (args
, i
), flags
);
307 /* Dump a template parameter PARM (a TREE_LIST) under control of FLAGS. */
310 dump_template_parameter (parm
, flags
)
314 tree p
= TREE_VALUE (parm
);
315 tree a
= TREE_PURPOSE (parm
);
317 if (TREE_CODE (p
) == TYPE_DECL
)
319 if (flags
& TFF_DECL_SPECIFIERS
)
321 print_identifier (scratch_buffer
, "class");
324 output_add_space (scratch_buffer
);
325 print_tree_identifier (scratch_buffer
, DECL_NAME (p
));
328 else if (DECL_NAME (p
))
329 print_tree_identifier (scratch_buffer
, DECL_NAME (p
));
331 print_identifier (scratch_buffer
, "{template default argument error}");
334 dump_decl (p
, flags
| TFF_DECL_SPECIFIERS
);
336 if ((flags
& TFF_FUNCTION_DEFAULT_ARGUMENTS
) && a
!= NULL_TREE
)
338 output_add_string (scratch_buffer
, " = ");
339 if (TREE_CODE (p
) == TYPE_DECL
|| TREE_CODE (p
) == TEMPLATE_DECL
)
340 dump_type (a
, flags
& ~TFF_CHASE_TYPEDEF
);
342 dump_expr (a
, flags
| TFF_EXPR_IN_PARENS
);
346 /* Dump, under control of FLAGS, a template-parameter-list binding.
347 PARMS is a TREE_LIST of TREE_VEC of TREE_LIST and ARGS is a
351 dump_template_bindings (parms
, args
)
358 tree p
= TREE_VALUE (parms
);
359 int lvl
= TMPL_PARMS_DEPTH (parms
);
363 for (i
= 0; i
< TREE_VEC_LENGTH (p
); ++i
)
365 tree arg
= NULL_TREE
;
367 /* Don't crash if we had an invalid argument list. */
368 if (TMPL_ARGS_DEPTH (args
) >= lvl
)
370 tree lvl_args
= TMPL_ARGS_LEVEL (args
, lvl
);
371 if (NUM_TMPL_ARGS (lvl_args
) > arg_idx
)
372 arg
= TREE_VEC_ELT (lvl_args
, arg_idx
);
376 separate_with_comma (scratch_buffer
);
377 dump_template_parameter (TREE_VEC_ELT (p
, i
), TFF_PLAIN_IDENTIFIER
);
378 output_add_string (scratch_buffer
, " = ");
380 dump_template_argument (arg
, TFF_PLAIN_IDENTIFIER
);
382 print_identifier (scratch_buffer
, "<missing>");
388 parms
= TREE_CHAIN (parms
);
392 /* Dump into the obstack a human-readable equivalent of TYPE. FLAGS
393 controls the format. */
403 if (TYPE_PTRMEMFUNC_P (t
))
406 switch (TREE_CODE (t
))
409 print_identifier (scratch_buffer
, "<unknown type>");
413 /* A list of function parms. */
414 dump_parameters (t
, flags
);
417 case IDENTIFIER_NODE
:
418 print_tree_identifier (scratch_buffer
, t
);
422 dump_type (BINFO_TYPE (t
), flags
);
428 dump_aggr_type (t
, flags
);
432 if (flags
& TFF_CHASE_TYPEDEF
)
434 dump_type (DECL_ORIGINAL_TYPE (t
)
435 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
), flags
);
438 /* else fallthrough */
442 dump_decl (t
, flags
& ~TFF_DECL_SPECIFIERS
);
446 output_add_string (scratch_buffer
, "__complex__ ");
447 dump_type (TREE_TYPE (t
), flags
);
451 output_add_string (scratch_buffer
, "vector ");
452 dump_type (TREE_TYPE (t
), flags
);
456 if (!TREE_UNSIGNED (TYPE_MAIN_VARIANT (t
)) && TREE_UNSIGNED (t
))
457 output_add_string (scratch_buffer
, "unsigned ");
458 else if (TREE_UNSIGNED (TYPE_MAIN_VARIANT (t
)) && !TREE_UNSIGNED (t
))
459 output_add_string (scratch_buffer
, "signed ");
467 dump_qualifiers (t
, after
);
468 type
= flags
& TFF_CHASE_TYPEDEF
? TYPE_MAIN_VARIANT (t
) : t
;
469 if (TYPE_NAME (type
) && TYPE_IDENTIFIER (type
))
470 print_tree_identifier (scratch_buffer
, TYPE_IDENTIFIER (type
));
472 /* Types like intQI_type_node and friends have no names.
473 These don't come up in user error messages, but it's nice
474 to be able to print them from the debugger. */
475 print_identifier (scratch_buffer
, "<anonymous>");
479 case TEMPLATE_TEMPLATE_PARM
:
480 /* For parameters inside template signature. */
481 if (TYPE_IDENTIFIER (t
))
482 print_tree_identifier (scratch_buffer
, TYPE_IDENTIFIER (t
));
485 (scratch_buffer
, "<anonymous template template parameter>");
488 case BOUND_TEMPLATE_TEMPLATE_PARM
:
490 tree args
= TYPE_TI_ARGS (t
);
491 print_tree_identifier (scratch_buffer
, TYPE_IDENTIFIER (t
));
492 print_template_argument_list_start (scratch_buffer
);
493 dump_template_argument_list (args
, flags
);
494 print_template_argument_list_end (scratch_buffer
);
498 case TEMPLATE_TYPE_PARM
:
499 dump_qualifiers (t
, after
);
500 if (TYPE_IDENTIFIER (t
))
501 print_tree_identifier (scratch_buffer
, TYPE_IDENTIFIER (t
));
504 (scratch_buffer
, "<anonymous template type parameter>");
507 /* This is not always necessary for pointers and such, but doing this
508 reduces code size. */
517 dump_type_prefix (t
, flags
);
518 dump_type_suffix (t
, flags
);
522 output_add_string (scratch_buffer
, "typename ");
523 dump_typename (t
, flags
);
527 output_add_string (scratch_buffer
, "__typeof (");
528 dump_expr (TYPE_FIELDS (t
), flags
& ~TFF_EXPR_IN_PARENS
);
529 print_left_paren (scratch_buffer
);
533 sorry_for_unsupported_tree (t
);
534 /* Fall through to error. */
537 print_identifier (scratch_buffer
, "<type error>");
542 /* Dump a TYPENAME_TYPE. We need to notice when the context is itself
546 dump_typename (t
, flags
)
550 tree ctx
= TYPE_CONTEXT (t
);
552 if (TREE_CODE (ctx
) == TYPENAME_TYPE
)
553 dump_typename (ctx
, flags
);
555 dump_type (ctx
, flags
& ~TFF_CLASS_KEY_OR_ENUM
);
556 print_scope_operator (scratch_buffer
);
557 dump_decl (TYPENAME_TYPE_FULLNAME (t
), flags
);
560 /* Return the name of the supplied aggregate, or enumeral type. */
563 class_key_or_enum (t
)
566 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
568 else if (TREE_CODE (t
) == UNION_TYPE
)
570 else if (TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_DECLARED_CLASS (t
))
576 /* Print out a class declaration T under the control of FLAGS,
577 in the form `class foo'. */
580 dump_aggr_type (t
, flags
)
585 const char *variety
= class_key_or_enum (t
);
589 dump_qualifiers (t
, after
);
591 if (flags
& TFF_CLASS_KEY_OR_ENUM
)
593 print_identifier (scratch_buffer
, variety
);
594 output_add_space (scratch_buffer
);
597 if (flags
& TFF_CHASE_TYPEDEF
)
598 t
= TYPE_MAIN_VARIANT (t
);
600 name
= TYPE_NAME (t
);
604 typdef
= !DECL_ARTIFICIAL (name
);
605 tmplate
= !typdef
&& TREE_CODE (t
) != ENUMERAL_TYPE
606 && TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_TEMPLATE_INFO (t
)
607 && (CLASSTYPE_TEMPLATE_SPECIALIZATION (t
)
608 || TREE_CODE (CLASSTYPE_TI_TEMPLATE (t
)) != TEMPLATE_DECL
609 || DECL_TEMPLATE_SPECIALIZATION (CLASSTYPE_TI_TEMPLATE (t
))
610 || PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t
)));
611 dump_scope (CP_DECL_CONTEXT (name
), flags
| TFF_SCOPE
);
614 /* Because the template names are mangled, we have to locate
615 the most general template, and use that name. */
616 tree tpl
= CLASSTYPE_TI_TEMPLATE (t
);
618 while (DECL_TEMPLATE_INFO (tpl
))
619 tpl
= DECL_TI_TEMPLATE (tpl
);
622 name
= DECL_NAME (name
);
625 if (name
== 0 || ANON_AGGRNAME_P (name
))
627 if (flags
& TFF_CLASS_KEY_OR_ENUM
)
628 print_identifier (scratch_buffer
, "<anonymous>");
630 output_printf (scratch_buffer
, "<anonymous %s>", variety
);
633 print_tree_identifier (scratch_buffer
, name
);
635 dump_template_parms (TYPE_TEMPLATE_INFO (t
),
636 !CLASSTYPE_USE_TEMPLATE (t
),
637 flags
& ~TFF_TEMPLATE_HEADER
);
640 /* Dump into the obstack the initial part of the output for a given type.
641 This is necessary when dealing with things like functions returning
644 return type of `int (* fee ())()': pointer -> function -> int. Both
645 pointer (and reference and offset) and function (and member) types must
646 deal with prefix and suffix.
648 Arrays must also do this for DECL nodes, like int a[], and for things like
651 Return indicates how you should pad an object name after this. I.e. you
652 want to pad non-*, non-& cores, but not pad * or & types. */
655 dump_type_prefix (t
, flags
)
659 enum pad padding
= before
;
661 if (TYPE_PTRMEMFUNC_P (t
))
663 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
667 switch (TREE_CODE (t
))
672 tree sub
= TREE_TYPE (t
);
674 padding
= dump_type_prefix (sub
, flags
);
675 /* A tree for a member pointer looks like pointer to offset,
676 so let the OFFSET_TYPE case handle it. */
677 if (!TYPE_PTRMEM_P (t
))
679 if (TREE_CODE (sub
) == ARRAY_TYPE
)
681 output_add_space (scratch_buffer
);
682 print_left_paren (scratch_buffer
);
685 (scratch_buffer
, "&*"[TREE_CODE (t
) == POINTER_TYPE
]);
686 padding
= dump_qualifiers (t
, before
);
693 padding
= dump_type_prefix (TREE_TYPE (t
), flags
);
694 if (TREE_CODE (t
) == OFFSET_TYPE
) /* pmfs deal with this in d_t_p */
697 output_add_space (scratch_buffer
);
698 dump_type (TYPE_OFFSET_BASETYPE (t
), flags
);
699 print_scope_operator (scratch_buffer
);
701 output_add_character (scratch_buffer
, '*');
702 padding
= dump_qualifiers (t
, none
);
705 /* Can only be reached through function pointer -- this would not be
706 correct if FUNCTION_DECLs used it. */
708 padding
= dump_type_prefix (TREE_TYPE (t
), flags
);
710 output_add_space (scratch_buffer
);
711 print_left_paren (scratch_buffer
);
716 padding
= dump_type_prefix (TREE_TYPE (t
), flags
);
718 output_add_space (scratch_buffer
);
719 print_left_paren (scratch_buffer
);
721 dump_aggr_type (TYPE_METHOD_BASETYPE (t
), flags
);
722 print_scope_operator (scratch_buffer
);
726 padding
= dump_type_prefix (TREE_TYPE (t
), flags
);
730 case IDENTIFIER_NODE
:
735 case TEMPLATE_TYPE_PARM
:
736 case TEMPLATE_TEMPLATE_PARM
:
737 case BOUND_TEMPLATE_TEMPLATE_PARM
:
747 dump_type (t
, flags
);
752 sorry_for_unsupported_tree (t
);
755 print_identifier (scratch_buffer
, "<typeprefixerror>");
761 /* Dump the suffix of type T, under control of FLAGS. This is the part
762 which appears after the identifier (or function parms). */
765 dump_type_suffix (t
, flags
)
769 if (TYPE_PTRMEMFUNC_P (t
))
770 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
772 switch (TREE_CODE (t
))
777 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
778 print_right_paren (scratch_buffer
);
779 dump_type_suffix (TREE_TYPE (t
), flags
);
782 /* Can only be reached through function pointer */
787 print_right_paren (scratch_buffer
);
788 arg
= TYPE_ARG_TYPES (t
);
789 if (TREE_CODE (t
) == METHOD_TYPE
)
790 arg
= TREE_CHAIN (arg
);
792 /* Function pointers don't have default args. Not in standard C++,
793 anyway; they may in g++, but we'll just pretend otherwise. */
794 dump_parameters (arg
, flags
& ~TFF_FUNCTION_DEFAULT_ARGUMENTS
);
796 if (TREE_CODE (t
) == METHOD_TYPE
)
798 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t
))), before
);
799 dump_type_suffix (TREE_TYPE (t
), flags
);
800 dump_exception_spec (TYPE_RAISES_EXCEPTIONS (t
), flags
);
805 print_left_bracket (scratch_buffer
);
808 if (host_integerp (TYPE_MAX_VALUE (TYPE_DOMAIN (t
)), 0))
811 tree_low_cst (TYPE_MAX_VALUE (TYPE_DOMAIN (t
)), 0) + 1);
812 else if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (t
))) == MINUS_EXPR
)
813 dump_expr (TREE_OPERAND (TYPE_MAX_VALUE (TYPE_DOMAIN (t
)), 0),
814 flags
& ~TFF_EXPR_IN_PARENS
);
816 dump_expr (fold (cp_build_binary_op
817 (PLUS_EXPR
, TYPE_MAX_VALUE (TYPE_DOMAIN (t
)),
819 flags
& ~TFF_EXPR_IN_PARENS
);
821 print_right_bracket (scratch_buffer
);
822 dump_type_suffix (TREE_TYPE (t
), flags
);
826 case IDENTIFIER_NODE
:
831 case TEMPLATE_TYPE_PARM
:
832 case TEMPLATE_TEMPLATE_PARM
:
833 case BOUND_TEMPLATE_TEMPLATE_PARM
:
846 sorry_for_unsupported_tree (t
);
848 /* Don't mark it here, we should have already done in
854 /* Return a function declaration which corresponds to the IDENTIFIER_NODE
861 tree n
= lookup_name (t
, 0);
866 if (TREE_CODE (n
) == FUNCTION_DECL
)
868 else if (TREE_CODE (n
) == TREE_LIST
869 && TREE_CODE (TREE_VALUE (n
)) == FUNCTION_DECL
)
870 return TREE_VALUE (n
);
872 my_friendly_abort (66);
876 #ifndef NO_DOLLAR_IN_LABEL
877 # define GLOBAL_THING "_GLOBAL_$"
879 # ifndef NO_DOT_IN_LABEL
880 # define GLOBAL_THING "_GLOBAL_."
882 # define GLOBAL_THING "_GLOBAL__"
886 #define GLOBAL_IORD_P(NODE) \
887 ! strncmp (IDENTIFIER_POINTER(NODE), GLOBAL_THING, sizeof (GLOBAL_THING) - 1)
893 const char *name
= IDENTIFIER_POINTER (t
);
894 const char *p
= NULL
;
896 if (name
[sizeof (GLOBAL_THING
) - 1] == 'I')
898 else if (name
[sizeof (GLOBAL_THING
) - 1] == 'D')
901 my_friendly_abort (352);
903 output_printf (scratch_buffer
, "(static %s for %s)", p
, input_filename
);
907 dump_simple_decl (t
, type
, flags
)
912 if (flags
& TFF_DECL_SPECIFIERS
)
914 if (dump_type_prefix (type
, flags
) != none
)
915 output_add_space (scratch_buffer
);
917 if (!DECL_INITIAL (t
) || TREE_CODE (DECL_INITIAL (t
)) != TEMPLATE_PARM_INDEX
)
918 dump_scope (CP_DECL_CONTEXT (t
), flags
);
920 dump_decl (DECL_NAME (t
), flags
);
922 print_identifier (scratch_buffer
, "<anonymous>");
923 if (flags
& TFF_DECL_SPECIFIERS
)
924 dump_type_suffix (type
, flags
);
927 /* Dump a human readable string for the decl T under control of FLAGS. */
937 switch (TREE_CODE (t
))
941 /* Don't say 'typedef class A' */
942 if (DECL_ARTIFICIAL (t
))
944 if ((flags
& TFF_DECL_SPECIFIERS
)
945 && TREE_CODE (TREE_TYPE (t
)) == TEMPLATE_TYPE_PARM
)
946 /* Say `class T' not just `T'. */
947 output_add_string (scratch_buffer
, "class ");
949 dump_type (TREE_TYPE (t
), flags
);
953 if (flags
& TFF_DECL_SPECIFIERS
)
954 output_add_string (scratch_buffer
, "typedef ");
955 dump_simple_decl (t
, DECL_ORIGINAL_TYPE (t
)
956 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
),
961 if (DECL_NAME (t
) && VTABLE_NAME_P (DECL_NAME (t
)))
963 output_add_string (scratch_buffer
, "vtable for ");
964 if (TYPE_P (DECL_CONTEXT (t
)))
965 dump_type (DECL_CONTEXT (t
), flags
);
967 /* This case can arise with -fno-vtable-thunks. See
968 expand_upcast_fixups. It's not clear what to print
970 print_identifier (scratch_buffer
, "<unknown type>");
973 /* else fall through */
976 dump_simple_decl (t
, TREE_TYPE (t
), flags
);
980 output_add_string (scratch_buffer
, "<return value> ");
981 dump_simple_decl (t
, TREE_TYPE (t
), flags
);
985 dump_scope (CP_DECL_CONTEXT (t
), flags
);
986 if (DECL_NAME (t
) == anonymous_namespace_name
)
987 print_identifier (scratch_buffer
, "<unnamed>");
989 print_tree_identifier (scratch_buffer
, DECL_NAME (t
));
993 dump_decl (TREE_OPERAND (t
, 0), flags
& ~TFF_DECL_SPECIFIERS
);
994 print_scope_operator (scratch_buffer
);
995 dump_decl (TREE_OPERAND (t
, 1), flags
);
999 dump_decl (TREE_OPERAND (t
, 0), flags
);
1000 print_left_bracket (scratch_buffer
);
1001 dump_decl (TREE_OPERAND (t
, 1), flags
);
1002 print_right_bracket (scratch_buffer
);
1005 /* So that we can do dump_decl on an aggr type. */
1009 dump_type (t
, flags
);
1013 my_friendly_abort (69);
1016 /* These special cases are duplicated here so that other functions
1017 can feed identifiers to cp_error and get them demangled properly. */
1018 case IDENTIFIER_NODE
:
1020 if (DESTRUCTOR_NAME_P (t
)
1021 && (f
= ident_fndecl (t
))
1022 && DECL_LANGUAGE (f
) == lang_cplusplus
)
1024 output_add_character (scratch_buffer
, '~');
1025 dump_decl (DECL_NAME (f
), flags
);
1027 else if (IDENTIFIER_TYPENAME_P (t
))
1029 output_add_string (scratch_buffer
, "operator ");
1030 /* Not exactly IDENTIFIER_TYPE_VALUE. */
1031 dump_type (TREE_TYPE (t
), flags
);
1035 print_tree_identifier (scratch_buffer
, t
);
1040 t
= OVL_CURRENT (t
);
1044 if (GLOBAL_IORD_P (DECL_ASSEMBLER_NAME (t
)))
1045 dump_global_iord (DECL_ASSEMBLER_NAME (t
));
1046 else if (! DECL_LANG_SPECIFIC (t
))
1047 print_identifier (scratch_buffer
, "<internal>");
1049 dump_function_decl (t
, flags
);
1053 dump_template_decl (t
, flags
);
1056 case TEMPLATE_ID_EXPR
:
1059 tree name
= TREE_OPERAND (t
, 0);
1060 if (is_overloaded_fn (name
))
1061 name
= DECL_NAME (get_first_fn (name
));
1062 dump_decl (name
, flags
);
1063 print_template_argument_list_start (scratch_buffer
);
1064 for (args
= TREE_OPERAND (t
, 1); args
; args
= TREE_CHAIN (args
))
1066 dump_template_argument (TREE_VALUE (args
), flags
);
1067 if (TREE_CHAIN (args
))
1068 separate_with_comma (scratch_buffer
);
1070 print_template_argument_list_end (scratch_buffer
);
1075 dump_decl (TREE_OPERAND (t
, 0), flags
);
1079 print_tree_identifier (scratch_buffer
, DECL_NAME (t
));
1083 if ((TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == ENUMERAL_TYPE
)
1084 || (DECL_INITIAL (t
) &&
1085 TREE_CODE (DECL_INITIAL (t
)) == TEMPLATE_PARM_INDEX
))
1086 dump_simple_decl (t
, TREE_TYPE (t
), flags
);
1087 else if (DECL_NAME (t
))
1088 dump_decl (DECL_NAME (t
), flags
);
1089 else if (DECL_INITIAL (t
))
1090 dump_expr (DECL_INITIAL (t
), flags
| TFF_EXPR_IN_PARENS
);
1092 print_identifier (scratch_buffer
, "enumerator");
1096 output_add_string (scratch_buffer
, "using ");
1097 dump_type (DECL_INITIAL (t
), flags
);
1098 print_scope_operator (scratch_buffer
);
1099 print_tree_identifier (scratch_buffer
, DECL_NAME (t
));
1103 sorry_for_unsupported_tree (t
);
1104 /* Fallthrough to error. */
1107 print_identifier (scratch_buffer
, "<declaration error>");
1112 /* Dump a template declaration T under control of FLAGS. This means the
1113 'template <...> leaders plus the 'class X' or 'void fn(...)' part. */
1116 dump_template_decl (t
, flags
)
1120 tree orig_parms
= DECL_TEMPLATE_PARMS (t
);
1124 if (flags
& TFF_TEMPLATE_HEADER
)
1126 for (parms
= orig_parms
= nreverse (orig_parms
);
1128 parms
= TREE_CHAIN (parms
))
1130 tree inner_parms
= INNERMOST_TEMPLATE_PARMS (parms
);
1131 int len
= TREE_VEC_LENGTH (inner_parms
);
1133 output_add_string (scratch_buffer
, "template<");
1134 for (i
= 0; i
< len
; i
++)
1137 separate_with_comma (scratch_buffer
);
1138 dump_template_parameter (TREE_VEC_ELT (inner_parms
, i
), flags
);
1140 print_template_argument_list_end (scratch_buffer
);
1141 output_add_space (scratch_buffer
);
1143 nreverse(orig_parms
);
1144 /* If we've shown the template<args> prefix, we'd better show the
1146 flags
|= TFF_DECL_SPECIFIERS
;
1148 if (TREE_CODE (DECL_TEMPLATE_RESULT (t
)) == TYPE_DECL
)
1149 dump_type (TREE_TYPE (t
),
1150 ((flags
& ~TFF_CLASS_KEY_OR_ENUM
) | TFF_TEMPLATE_NAME
1151 | (flags
& TFF_DECL_SPECIFIERS
? TFF_CLASS_KEY_OR_ENUM
: 0)));
1152 else if (TREE_CODE (DECL_TEMPLATE_RESULT (t
)) == VAR_DECL
)
1153 dump_decl (DECL_TEMPLATE_RESULT (t
), flags
| TFF_TEMPLATE_NAME
);
1154 else if (TREE_TYPE (t
) == NULL_TREE
)
1155 my_friendly_abort (353);
1157 switch (NEXT_CODE (t
))
1161 dump_function_decl (t
, flags
| TFF_TEMPLATE_NAME
);
1164 /* This case can occur with some illegal code. */
1165 dump_type (TREE_TYPE (t
),
1166 (flags
& ~TFF_CLASS_KEY_OR_ENUM
) | TFF_TEMPLATE_NAME
1167 | (flags
& TFF_DECL_SPECIFIERS
? TFF_CLASS_KEY_OR_ENUM
: 0));
1171 /* Pretty print a function decl. There are several ways we want to print a
1172 function declaration. The TFF_ bits in FLAGS tells us how to behave.
1173 As cp_error can only apply the '#' flag once to give 0 and 1 for V, there
1174 is %D which doesn't print the throw specs, and %F which does. */
1177 dump_function_decl (t
, flags
)
1183 tree cname
= NULL_TREE
;
1184 tree template_args
= NULL_TREE
;
1185 tree template_parms
= NULL_TREE
;
1186 int show_return
= flags
& TFF_RETURN_TYPE
|| flags
& TFF_DECL_SPECIFIERS
;
1188 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1189 t
= DECL_TEMPLATE_RESULT (t
);
1191 /* Pretty print template instantiations only. */
1192 if (DECL_USE_TEMPLATE (t
) && DECL_TEMPLATE_INFO (t
))
1196 template_args
= DECL_TI_ARGS (t
);
1197 tmpl
= most_general_template (t
);
1198 if (tmpl
&& TREE_CODE (tmpl
) == TEMPLATE_DECL
)
1200 template_parms
= DECL_TEMPLATE_PARMS (tmpl
);
1205 fntype
= TREE_TYPE (t
);
1206 parmtypes
= TYPE_ARG_TYPES (fntype
);
1208 if (DECL_CLASS_SCOPE_P (t
))
1209 cname
= DECL_CONTEXT (t
);
1210 /* this is for partially instantiated template methods */
1211 else if (TREE_CODE (fntype
) == METHOD_TYPE
)
1212 cname
= TREE_TYPE (TREE_VALUE (parmtypes
));
1214 if (!(flags
& TFF_DECL_SPECIFIERS
))
1216 else if (DECL_STATIC_FUNCTION_P (t
))
1217 print_identifier (scratch_buffer
, "static ");
1218 else if (DECL_VIRTUAL_P (t
))
1219 print_identifier (scratch_buffer
, "virtual ");
1221 /* Print the return type? */
1223 show_return
= !DECL_CONV_FN_P (t
) && !DECL_CONSTRUCTOR_P (t
)
1224 && !DECL_DESTRUCTOR_P (t
);
1227 dump_type_prefix (TREE_TYPE (fntype
), flags
);
1228 output_add_space (scratch_buffer
);
1231 /* Print the function name. */
1234 dump_type (cname
, flags
);
1235 print_scope_operator (scratch_buffer
);
1238 dump_scope (CP_DECL_CONTEXT (t
), flags
);
1240 dump_function_name (t
, flags
);
1242 if (flags
& TFF_DECL_SPECIFIERS
)
1244 if (TREE_CODE (fntype
) == METHOD_TYPE
&& parmtypes
)
1245 /* Skip "this" parameter. */
1246 parmtypes
= TREE_CHAIN (parmtypes
);
1248 /* Skip past the "in_charge" parameter. */
1249 if (DECL_HAS_IN_CHARGE_PARM_P (t
))
1250 parmtypes
= TREE_CHAIN (parmtypes
);
1252 dump_parameters (parmtypes
, flags
);
1255 dump_type_suffix (TREE_TYPE (fntype
), flags
);
1257 if (TREE_CODE (fntype
) == METHOD_TYPE
)
1258 dump_qualifiers (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype
))),
1261 if (flags
& TFF_EXCEPTION_SPECIFICATION
)
1262 dump_exception_spec (TYPE_RAISES_EXCEPTIONS (fntype
), flags
);
1265 /* If T is a template instantiation, dump the parameter binding. */
1266 if (template_parms
!= NULL_TREE
&& template_args
!= NULL_TREE
)
1268 output_add_string (scratch_buffer
, " [with ");
1269 dump_template_bindings (template_parms
, template_args
);
1270 print_right_bracket (scratch_buffer
);
1274 /* Print a parameter list. If this is for a member function, the
1275 member object ptr (and any other hidden args) should have
1276 already been removed. */
1279 dump_parameters (parmtypes
, flags
)
1285 print_left_paren (scratch_buffer
);
1287 for (first
= 1; parmtypes
!= void_list_node
;
1288 parmtypes
= TREE_CHAIN (parmtypes
))
1291 separate_with_comma (scratch_buffer
);
1295 print_identifier (scratch_buffer
, "...");
1298 dump_type (TREE_VALUE (parmtypes
), flags
);
1300 if ((flags
& TFF_FUNCTION_DEFAULT_ARGUMENTS
) && TREE_PURPOSE (parmtypes
))
1302 output_add_string (scratch_buffer
, " = ");
1303 dump_expr (TREE_PURPOSE (parmtypes
), flags
| TFF_EXPR_IN_PARENS
);
1307 print_right_paren (scratch_buffer
);
1310 /* Print an exception specification. T is the exception specification. */
1313 dump_exception_spec (t
, flags
)
1319 output_add_string (scratch_buffer
, " throw (");
1320 if (TREE_VALUE (t
) != NULL_TREE
)
1323 dump_type (TREE_VALUE (t
), flags
);
1327 separate_with_comma (scratch_buffer
);
1329 print_right_paren (scratch_buffer
);
1333 /* Handle the function name for a FUNCTION_DECL node, grokking operators
1334 and destructors properly. */
1337 dump_function_name (t
, flags
)
1341 tree name
= DECL_NAME (t
);
1343 /* Don't let the user see __comp_ctor et al. */
1344 if (DECL_CONSTRUCTOR_P (t
)
1345 || DECL_DESTRUCTOR_P (t
))
1346 name
= constructor_name (DECL_CONTEXT (t
));
1348 if (DECL_DESTRUCTOR_P (t
))
1350 output_add_character (scratch_buffer
, '~');
1351 dump_decl (name
, TFF_PLAIN_IDENTIFIER
);
1353 else if (DECL_CONV_FN_P (t
))
1355 /* This cannot use the hack that the operator's return
1356 type is stashed off of its name because it may be
1357 used for error reporting. In the case of conflicting
1358 declarations, both will have the same name, yet
1359 the types will be different, hence the TREE_TYPE field
1360 of the first name will be clobbered by the second. */
1361 output_add_string (scratch_buffer
, "operator ");
1362 dump_type (TREE_TYPE (TREE_TYPE (t
)), flags
);
1364 else if (IDENTIFIER_OPNAME_P (name
))
1365 print_tree_identifier (scratch_buffer
, name
);
1367 dump_decl (name
, flags
);
1369 if (DECL_LANG_SPECIFIC (t
) && DECL_TEMPLATE_INFO (t
)
1370 && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t
)
1371 && (DECL_TEMPLATE_SPECIALIZATION (t
)
1372 || TREE_CODE (DECL_TI_TEMPLATE (t
)) != TEMPLATE_DECL
1373 || DECL_TEMPLATE_SPECIALIZATION (DECL_TI_TEMPLATE (t
))
1374 || PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t
))))
1375 dump_template_parms (DECL_TEMPLATE_INFO (t
), !DECL_USE_TEMPLATE (t
), flags
);
1378 /* Dump the template parameters from the template info INFO under control of
1379 FLAGS. PRIMARY indicates whether this is a primary template decl, or
1380 specialization (partial or complete). For partial specializations we show
1381 the specialized parameter values. For a primary template we show no
1385 dump_template_parms (info
, primary
, flags
)
1390 tree args
= info
? TI_ARGS (info
) : NULL_TREE
;
1392 if (primary
&& flags
& TFF_TEMPLATE_NAME
)
1394 flags
&= ~(TFF_CLASS_KEY_OR_ENUM
| TFF_TEMPLATE_NAME
);
1395 print_template_argument_list_start (scratch_buffer
);
1397 /* Be careful only to print things when we have them, so as not
1398 to crash producing error messages. */
1399 if (args
&& !primary
)
1405 if (TREE_CODE (args
) == TREE_VEC
)
1407 if (TREE_VEC_LENGTH (args
) > 0
1408 && TREE_CODE (TREE_VEC_ELT (args
, 0)) == TREE_VEC
)
1409 args
= TREE_VEC_ELT (args
, TREE_VEC_LENGTH (args
) - 1);
1411 len
= TREE_VEC_LENGTH (args
);
1413 else if (TREE_CODE (args
) == TREE_LIST
)
1415 while (ix
!= len
&& args
)
1420 arg
= TREE_VEC_ELT (args
, ix
);
1425 arg
= TREE_VALUE (args
);
1426 args
= TREE_CHAIN (args
);
1429 separate_with_comma (scratch_buffer
);
1432 print_identifier (scratch_buffer
, "<template parameter error>");
1434 dump_template_argument (arg
, flags
);
1440 tree tpl
= TI_TEMPLATE (info
);
1441 tree parms
= DECL_TEMPLATE_PARMS (tpl
);
1444 parms
= TREE_CODE (parms
) == TREE_LIST
? TREE_VALUE (parms
) : NULL_TREE
;
1445 len
= parms
? TREE_VEC_LENGTH (parms
) : 0;
1447 for (ix
= 0; ix
!= len
; ix
++)
1449 tree parm
= TREE_VALUE (TREE_VEC_ELT (parms
, ix
));
1452 separate_with_comma (scratch_buffer
);
1454 dump_decl (parm
, flags
& ~TFF_DECL_SPECIFIERS
);
1457 print_template_argument_list_end (scratch_buffer
);
1466 case TARGET_NEWLINE
:
1467 output_add_string (scratch_buffer
, "\\n");
1470 output_add_string (scratch_buffer
, "\\t");
1473 output_add_string (scratch_buffer
, "\\v");
1476 output_add_string (scratch_buffer
, "\\b");
1479 output_add_string (scratch_buffer
, "\\r");
1482 output_add_string (scratch_buffer
, "\\f");
1485 output_add_string (scratch_buffer
, "\\a");
1488 output_add_string (scratch_buffer
, "\\\\");
1491 output_add_string (scratch_buffer
, "\\'");
1494 output_add_string (scratch_buffer
, "\\\"");
1498 output_add_character (scratch_buffer
, c
);
1501 sprintf (digit_buffer
, "\\%03o", (int) c
);
1502 output_add_string (scratch_buffer
, digit_buffer
);
1507 /* Print out a list of initializers (subr of dump_expr) */
1510 dump_expr_list (l
, flags
)
1516 dump_expr (TREE_VALUE (l
), flags
| TFF_EXPR_IN_PARENS
);
1519 separate_with_comma (scratch_buffer
);
1523 /* Print out an expression E under control of FLAGS. */
1526 dump_expr (t
, flags
)
1530 switch (TREE_CODE (t
))
1538 case NAMESPACE_DECL
:
1540 dump_decl (t
, flags
& ~TFF_DECL_SPECIFIERS
);
1545 tree type
= TREE_TYPE (t
);
1546 my_friendly_assert (type
!= 0, 81);
1548 /* If it's an enum, output its tag, rather than its value. */
1549 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1551 tree values
= TYPE_VALUES (type
);
1554 values
= TREE_CHAIN (values
))
1555 if (tree_int_cst_equal (TREE_VALUE (values
), t
))
1559 print_tree_identifier (scratch_buffer
, TREE_PURPOSE (values
));
1562 /* Value must have been cast. */
1563 print_left_paren (scratch_buffer
);
1564 dump_type (type
, flags
);
1565 print_right_paren (scratch_buffer
);
1569 else if (type
== boolean_type_node
)
1571 if (t
== boolean_false_node
|| integer_zerop (t
))
1572 print_identifier (scratch_buffer
, "false");
1573 else if (t
== boolean_true_node
)
1574 print_identifier (scratch_buffer
, "true");
1576 else if (type
== char_type_node
)
1578 output_add_character (scratch_buffer
, '\'');
1579 dump_char (tree_low_cst (t
, 0));
1580 output_add_character (scratch_buffer
, '\'');
1585 if (! host_integerp (t
, 0))
1589 if (tree_int_cst_sgn (val
) < 0)
1591 output_add_character (scratch_buffer
, '-');
1592 val
= build_int_2 (-TREE_INT_CST_LOW (val
),
1593 ~TREE_INT_CST_HIGH (val
)
1594 + !TREE_INT_CST_LOW (val
));
1596 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
1599 static char format
[10]; /* "%x%09999x\0" */
1601 sprintf (format
, "%%x%%0%dx", HOST_BITS_PER_INT
/ 4);
1602 sprintf (digit_buffer
, format
, TREE_INT_CST_HIGH (val
),
1603 TREE_INT_CST_LOW (val
));
1604 output_add_string (scratch_buffer
, digit_buffer
);
1608 print_integer (scratch_buffer
, TREE_INT_CST_LOW (t
));
1614 #ifndef REAL_IS_NOT_DOUBLE
1615 sprintf (digit_buffer
, "%g", TREE_REAL_CST (t
));
1618 const unsigned char *p
= (const unsigned char *) &TREE_REAL_CST (t
);
1620 strcpy (digit_buffer
, "0x");
1621 for (i
= 0; i
< sizeof TREE_REAL_CST (t
); i
++)
1622 sprintf (digit_buffer
+ 2 + 2*i
, "%02x", *p
++);
1625 output_add_string (scratch_buffer
, digit_buffer
);
1629 output_add_character (scratch_buffer
, '&');
1630 dump_type (PTRMEM_CST_CLASS (t
), flags
);
1631 print_scope_operator (scratch_buffer
);
1632 print_tree_identifier
1633 (scratch_buffer
, DECL_NAME (PTRMEM_CST_MEMBER (t
)));
1638 const char *p
= TREE_STRING_POINTER (t
);
1639 int len
= TREE_STRING_LENGTH (t
) - 1;
1642 output_add_character (scratch_buffer
, '\"');
1643 for (i
= 0; i
< len
; i
++)
1645 output_add_character (scratch_buffer
, '\"');
1650 print_left_paren (scratch_buffer
);
1651 dump_expr (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
1652 separate_with_comma (scratch_buffer
);
1653 dump_expr (TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
1654 print_right_paren (scratch_buffer
);
1658 print_left_paren (scratch_buffer
);
1659 dump_expr (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
1660 output_add_string (scratch_buffer
, " ? ");
1661 dump_expr (TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
1662 output_add_string (scratch_buffer
, " : ");
1663 dump_expr (TREE_OPERAND (t
, 2), flags
| TFF_EXPR_IN_PARENS
);
1664 print_right_paren (scratch_buffer
);
1668 if (TREE_HAS_CONSTRUCTOR (t
))
1670 output_add_string (scratch_buffer
, "new ");
1671 dump_type (TREE_TYPE (TREE_TYPE (t
)), flags
);
1675 dump_expr (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
1679 case AGGR_INIT_EXPR
:
1681 tree fn
= NULL_TREE
;
1683 if (TREE_CODE (TREE_OPERAND (t
, 0)) == ADDR_EXPR
)
1684 fn
= TREE_OPERAND (TREE_OPERAND (t
, 0), 0);
1686 if (fn
&& TREE_CODE (fn
) == FUNCTION_DECL
)
1688 if (DECL_CONSTRUCTOR_P (fn
))
1689 print_tree_identifier
1690 (scratch_buffer
, TYPE_IDENTIFIER (TREE_TYPE (t
)));
1695 dump_expr (TREE_OPERAND (t
, 0), 0);
1697 print_left_paren (scratch_buffer
);
1698 if (TREE_OPERAND (t
, 1))
1699 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t
, 1)), flags
);
1700 print_right_paren (scratch_buffer
);
1705 tree fn
= TREE_OPERAND (t
, 0);
1706 tree args
= TREE_OPERAND (t
, 1);
1708 if (TREE_CODE (fn
) == ADDR_EXPR
)
1709 fn
= TREE_OPERAND (fn
, 0);
1711 if (TREE_TYPE (fn
) != NULL_TREE
&& NEXT_CODE (fn
) == METHOD_TYPE
)
1713 tree ob
= TREE_VALUE (args
);
1714 if (TREE_CODE (ob
) == ADDR_EXPR
)
1716 dump_expr (TREE_OPERAND (ob
, 0), flags
| TFF_EXPR_IN_PARENS
);
1717 output_add_character (scratch_buffer
, '.');
1719 else if (TREE_CODE (ob
) != PARM_DECL
1720 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob
)), "this"))
1722 dump_expr (ob
, flags
| TFF_EXPR_IN_PARENS
);
1723 output_add_string (scratch_buffer
, "->");
1725 args
= TREE_CHAIN (args
);
1727 dump_expr (fn
, flags
| TFF_EXPR_IN_PARENS
);
1728 print_left_paren (scratch_buffer
);
1729 dump_expr_list (args
, flags
);
1730 print_right_paren (scratch_buffer
);
1736 tree type
= TREE_OPERAND (t
, 1);
1737 if (NEW_EXPR_USE_GLOBAL (t
))
1738 print_scope_operator (scratch_buffer
);
1739 output_add_string (scratch_buffer
, "new ");
1740 if (TREE_OPERAND (t
, 0))
1742 print_left_paren (scratch_buffer
);
1743 dump_expr_list (TREE_OPERAND (t
, 0), flags
);
1744 output_add_string (scratch_buffer
, ") ");
1746 if (TREE_CODE (type
) == ARRAY_REF
)
1747 type
= build_cplus_array_type
1748 (TREE_OPERAND (type
, 0),
1749 build_index_type (fold (build (MINUS_EXPR
, integer_type_node
,
1750 TREE_OPERAND (type
, 1),
1751 integer_one_node
))));
1752 dump_type (type
, flags
);
1753 if (TREE_OPERAND (t
, 2))
1755 print_left_paren (scratch_buffer
);
1756 dump_expr_list (TREE_OPERAND (t
, 2), flags
);
1757 print_right_paren (scratch_buffer
);
1763 /* Note that this only works for G++ target exprs. If somebody
1764 builds a general TARGET_EXPR, there's no way to represent that
1765 it initializes anything other that the parameter slot for the
1766 default argument. Note we may have cleared out the first
1767 operand in expand_expr, so don't go killing ourselves. */
1768 if (TREE_OPERAND (t
, 1))
1769 dump_expr (TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
1777 case TRUNC_DIV_EXPR
:
1778 case TRUNC_MOD_EXPR
:
1786 case BIT_ANDTC_EXPR
:
1787 case TRUTH_ANDIF_EXPR
:
1788 case TRUTH_ORIF_EXPR
:
1795 case EXACT_DIV_EXPR
:
1796 dump_binary_op (operator_name_info
[(int) TREE_CODE (t
)].name
, t
, flags
);
1800 case FLOOR_DIV_EXPR
:
1801 case ROUND_DIV_EXPR
:
1802 dump_binary_op ("/", t
, flags
);
1806 case FLOOR_MOD_EXPR
:
1807 case ROUND_MOD_EXPR
:
1808 dump_binary_op ("%", t
, flags
);
1813 tree ob
= TREE_OPERAND (t
, 0);
1814 if (TREE_CODE (ob
) == INDIRECT_REF
)
1816 ob
= TREE_OPERAND (ob
, 0);
1817 if (TREE_CODE (ob
) != PARM_DECL
1818 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob
)), "this"))
1820 dump_expr (ob
, flags
| TFF_EXPR_IN_PARENS
);
1821 output_add_string (scratch_buffer
, "->");
1826 dump_expr (ob
, flags
| TFF_EXPR_IN_PARENS
);
1827 output_add_character (scratch_buffer
, '.');
1829 dump_expr (TREE_OPERAND (t
, 1), flags
& ~TFF_EXPR_IN_PARENS
);
1834 dump_expr (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
1835 print_left_bracket (scratch_buffer
);
1836 dump_expr (TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
1837 print_right_bracket (scratch_buffer
);
1841 if (VOID_TYPE_P (TREE_TYPE (t
)))
1843 print_left_paren (scratch_buffer
);
1844 dump_type (TREE_TYPE (t
), flags
);
1845 print_right_paren (scratch_buffer
);
1846 dump_expr (TREE_OPERAND (t
, 0), flags
);
1849 dump_unary_op ("+", t
, flags
);
1853 if (TREE_CODE (TREE_OPERAND (t
, 0)) == FUNCTION_DECL
1854 || TREE_CODE (TREE_OPERAND (t
, 0)) == STRING_CST
1855 /* An ADDR_EXPR can have reference type. In that case, we
1856 shouldn't print the `&' doing so indicates to the user
1857 that the expression has pointer type. */
1859 && TREE_CODE (TREE_TYPE (t
)) == REFERENCE_TYPE
))
1860 dump_expr (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
1862 dump_unary_op ("&", t
, flags
);
1866 if (TREE_HAS_CONSTRUCTOR (t
))
1868 t
= TREE_OPERAND (t
, 0);
1869 my_friendly_assert (TREE_CODE (t
) == CALL_EXPR
, 237);
1870 dump_expr (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
1871 print_left_paren (scratch_buffer
);
1872 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t
, 1)), flags
);
1873 print_right_paren (scratch_buffer
);
1877 if (TREE_OPERAND (t
,0) != NULL_TREE
1878 && TREE_TYPE (TREE_OPERAND (t
, 0))
1879 && NEXT_CODE (TREE_OPERAND (t
, 0)) == REFERENCE_TYPE
)
1880 dump_expr (TREE_OPERAND (t
, 0), flags
);
1882 dump_unary_op ("*", t
, flags
);
1888 case TRUTH_NOT_EXPR
:
1889 case PREDECREMENT_EXPR
:
1890 case PREINCREMENT_EXPR
:
1891 dump_unary_op (operator_name_info
[(int)TREE_CODE (t
)].name
, t
, flags
);
1894 case POSTDECREMENT_EXPR
:
1895 case POSTINCREMENT_EXPR
:
1896 print_left_paren (scratch_buffer
);
1897 dump_expr (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
1899 (scratch_buffer
, operator_name_info
[(int)TREE_CODE (t
)].name
);
1900 print_right_paren (scratch_buffer
);
1903 case NON_LVALUE_EXPR
:
1904 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
1905 should be another level of INDIRECT_REF so that I don't have to do
1907 if (TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == POINTER_TYPE
)
1909 tree next
= TREE_TYPE (TREE_TYPE (t
));
1911 while (TREE_CODE (next
) == POINTER_TYPE
)
1912 next
= TREE_TYPE (next
);
1914 if (TREE_CODE (next
) == FUNCTION_TYPE
)
1916 if (flags
& TFF_EXPR_IN_PARENS
)
1917 print_left_paren (scratch_buffer
);
1918 output_add_character (scratch_buffer
, '*');
1919 dump_expr (TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
1920 if (flags
& TFF_EXPR_IN_PARENS
)
1921 print_right_paren (scratch_buffer
);
1926 dump_expr (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
1930 dump_expr (TREE_OPERAND (t
, 0), flags
);
1933 case EXPR_WITH_FILE_LOCATION
:
1934 dump_expr (EXPR_WFL_NODE (t
), flags
);
1938 if (TREE_TYPE (t
) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t
)))
1940 tree idx
= build_component_ref (t
, index_identifier
, NULL_TREE
, 0);
1942 if (integer_all_onesp (idx
))
1944 tree pfn
= PFN_FROM_PTRMEMFUNC (t
);
1945 dump_unary_op ("&", pfn
, flags
| TFF_EXPR_IN_PARENS
);
1948 else if (TREE_CODE (idx
) == INTEGER_CST
1949 && tree_int_cst_equal (idx
, integer_zero_node
))
1951 /* A NULL pointer-to-member constant. */
1952 output_add_string (scratch_buffer
, "((");
1953 dump_type (TREE_TYPE (t
), flags
);
1954 output_add_string (scratch_buffer
, ") 0)");
1957 else if (host_integerp (idx
, 0))
1960 unsigned HOST_WIDE_INT n
;
1962 t
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t
)));
1963 t
= TYPE_METHOD_BASETYPE (t
);
1964 virtuals
= TYPE_BINFO_VIRTUALS (TYPE_MAIN_VARIANT (t
));
1966 n
= tree_low_cst (idx
, 0);
1968 /* Map vtable index back one, to allow for the null pointer to
1972 while (n
> 0 && virtuals
)
1975 virtuals
= TREE_CHAIN (virtuals
);
1979 dump_expr (BV_FN (virtuals
),
1980 flags
| TFF_EXPR_IN_PARENS
);
1985 output_add_character (scratch_buffer
, '{');
1986 dump_expr_list (CONSTRUCTOR_ELTS (t
), flags
);
1987 output_add_character (scratch_buffer
, '}');
1992 tree ob
= TREE_OPERAND (t
, 0);
1993 if (is_dummy_object (ob
))
1995 t
= TREE_OPERAND (t
, 1);
1996 if (TREE_CODE (t
) == FUNCTION_DECL
)
1998 dump_expr (t
, flags
| TFF_EXPR_IN_PARENS
);
1999 else if (BASELINK_P (t
))
2000 dump_expr (OVL_CURRENT (TREE_VALUE (t
)), flags
| TFF_EXPR_IN_PARENS
);
2002 dump_decl (t
, flags
);
2006 if (TREE_CODE (ob
) == INDIRECT_REF
)
2008 dump_expr (TREE_OPERAND (ob
, 0), flags
| TFF_EXPR_IN_PARENS
);
2009 output_add_string (scratch_buffer
, "->*");
2013 dump_expr (ob
, flags
| TFF_EXPR_IN_PARENS
);
2014 output_add_string (scratch_buffer
, ".*");
2016 dump_expr (TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2021 case TEMPLATE_PARM_INDEX
:
2022 dump_decl (TEMPLATE_PARM_DECL (t
), flags
& ~TFF_DECL_SPECIFIERS
);
2025 case IDENTIFIER_NODE
:
2026 print_tree_identifier (scratch_buffer
, t
);
2030 dump_type (TREE_OPERAND (t
, 0), flags
);
2031 print_scope_operator (scratch_buffer
);
2032 dump_expr (TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2036 if (TREE_OPERAND (t
, 0) == NULL_TREE
2037 || TREE_CHAIN (TREE_OPERAND (t
, 0)))
2039 dump_type (TREE_TYPE (t
), flags
);
2040 print_left_paren (scratch_buffer
);
2041 dump_expr_list (TREE_OPERAND (t
, 0), flags
);
2042 print_right_paren (scratch_buffer
);
2046 print_left_paren (scratch_buffer
);
2047 dump_type (TREE_TYPE (t
), flags
);
2048 output_add_string (scratch_buffer
, ")(");
2049 dump_expr_list (TREE_OPERAND (t
, 0), flags
);
2050 print_right_paren (scratch_buffer
);
2054 case STATIC_CAST_EXPR
:
2055 output_add_string (scratch_buffer
, "static_cast<");
2057 case REINTERPRET_CAST_EXPR
:
2058 output_add_string (scratch_buffer
, "reinterpret_cast<");
2060 case CONST_CAST_EXPR
:
2061 output_add_string (scratch_buffer
, "const_cast<");
2063 case DYNAMIC_CAST_EXPR
:
2064 output_add_string (scratch_buffer
, "dynamic_cast<");
2066 dump_type (TREE_TYPE (t
), flags
);
2067 output_add_string (scratch_buffer
, ">(");
2068 dump_expr (TREE_OPERAND (t
, 0), flags
);
2069 print_right_paren (scratch_buffer
);
2073 print_tree_identifier (scratch_buffer
, TREE_OPERAND (t
, 0));
2077 dump_expr (TREE_OPERAND (t
, 0), flags
);
2078 output_add_string (scratch_buffer
, "->");
2083 if (TREE_CODE (t
) == SIZEOF_EXPR
)
2084 output_add_string (scratch_buffer
, "sizeof (");
2087 my_friendly_assert (TREE_CODE (t
) == ALIGNOF_EXPR
, 0);
2088 output_add_string (scratch_buffer
, "__alignof__ (");
2090 if (TYPE_P (TREE_OPERAND (t
, 0)))
2091 dump_type (TREE_OPERAND (t
, 0), flags
);
2093 dump_unary_op ("*", t
, flags
| TFF_EXPR_IN_PARENS
);
2094 print_right_paren (scratch_buffer
);
2098 print_identifier (scratch_buffer
, "<unparsed>");
2101 case TRY_CATCH_EXPR
:
2102 case WITH_CLEANUP_EXPR
:
2103 case CLEANUP_POINT_EXPR
:
2104 dump_expr (TREE_OPERAND (t
, 0), flags
);
2107 case PSEUDO_DTOR_EXPR
:
2108 dump_expr (TREE_OPERAND (t
, 2), flags
);
2109 output_add_character (scratch_buffer
, '.');
2110 dump_type (TREE_OPERAND (t
, 0), flags
);
2111 output_add_string (scratch_buffer
, "::~");
2112 dump_type (TREE_OPERAND (t
, 1), flags
);
2115 case TEMPLATE_ID_EXPR
:
2116 dump_decl (t
, flags
);
2120 /* We don't yet have a way of dumping statements in a
2121 human-readable format. */
2122 output_add_string (scratch_buffer
, "({...})");
2126 output_add_character (scratch_buffer
, '}');
2127 dump_expr (TREE_OPERAND (t
, 1), flags
& ~TFF_EXPR_IN_PARENS
);
2128 output_add_character (scratch_buffer
, '}');
2132 output_add_string (scratch_buffer
, "while (1) { ");
2133 dump_expr (TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2134 output_add_character (scratch_buffer
, '}');
2138 output_add_string (scratch_buffer
, "if (");
2139 dump_expr (TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2140 output_add_string (scratch_buffer
, ") break; ");
2144 if (TREE_VALUE (t
) && TREE_CODE (TREE_VALUE (t
)) == FUNCTION_DECL
)
2146 print_tree_identifier (scratch_buffer
, DECL_NAME (TREE_VALUE (t
)));
2149 /* else fall through */
2151 /* This list is incomplete, but should suffice for now.
2152 It is very important that `sorry' does not call
2153 `report_error_function'. That could cause an infinite loop. */
2155 sorry_for_unsupported_tree (t
);
2156 /* fall through to ERROR_MARK... */
2158 print_identifier (scratch_buffer
, "<expression error>");
2164 dump_binary_op (opstring
, t
, flags
)
2165 const char *opstring
;
2169 print_left_paren (scratch_buffer
);
2170 dump_expr (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2171 output_add_space (scratch_buffer
);
2173 print_identifier (scratch_buffer
, opstring
);
2175 print_identifier (scratch_buffer
, "<unknown operator>");
2176 output_add_space (scratch_buffer
);
2177 dump_expr (TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2178 print_right_paren (scratch_buffer
);
2182 dump_unary_op (opstring
, t
, flags
)
2183 const char *opstring
;
2187 if (flags
& TFF_EXPR_IN_PARENS
)
2188 print_left_paren (scratch_buffer
);
2189 print_identifier (scratch_buffer
, opstring
);
2190 dump_expr (TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2191 if (flags
& TFF_EXPR_IN_PARENS
)
2192 print_right_paren (scratch_buffer
);
2195 /* Exported interface to stringifying types, exprs and decls under TFF_*
2199 type_as_string (typ
, flags
)
2203 reinit_global_formatting_buffer ();
2205 dump_type (typ
, flags
);
2207 return output_finalize_message (scratch_buffer
);
2211 expr_as_string (decl
, flags
)
2215 reinit_global_formatting_buffer ();
2217 dump_expr (decl
, flags
);
2219 return output_finalize_message (scratch_buffer
);
2223 decl_as_string (decl
, flags
)
2227 reinit_global_formatting_buffer ();
2229 dump_decl (decl
, flags
);
2231 return output_finalize_message (scratch_buffer
);
2235 context_as_string (context
, flags
)
2239 reinit_global_formatting_buffer ();
2241 dump_scope (context
, flags
);
2243 return output_finalize_message (scratch_buffer
);
2246 /* Generate the three forms of printable names for lang_printable_name. */
2249 lang_decl_name (decl
, v
)
2254 return decl_as_string (decl
, TFF_DECL_SPECIFIERS
);
2256 reinit_global_formatting_buffer ();
2258 if (v
== 1 && DECL_CLASS_SCOPE_P (decl
))
2260 dump_type (CP_DECL_CONTEXT (decl
), TFF_PLAIN_IDENTIFIER
);
2261 print_scope_operator (scratch_buffer
);
2264 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2265 dump_function_name (decl
, TFF_PLAIN_IDENTIFIER
);
2267 dump_decl (DECL_NAME (decl
), TFF_PLAIN_IDENTIFIER
);
2269 return output_finalize_message (scratch_buffer
);
2276 if (TREE_CODE (t
) == PARM_DECL
&& DECL_CONTEXT (t
))
2277 return DECL_SOURCE_FILE (DECL_CONTEXT (t
));
2278 else if (TYPE_P (t
))
2279 return DECL_SOURCE_FILE (TYPE_MAIN_DECL (t
));
2280 else if (TREE_CODE (t
) == OVERLOAD
)
2281 return DECL_SOURCE_FILE (OVL_FUNCTION (t
));
2283 return DECL_SOURCE_FILE (t
);
2291 if (TREE_CODE (t
) == PARM_DECL
&& DECL_CONTEXT (t
))
2292 line
= DECL_SOURCE_LINE (DECL_CONTEXT (t
));
2293 if (TREE_CODE (t
) == TYPE_DECL
&& DECL_ARTIFICIAL (t
)
2294 && TYPE_MAIN_DECL (TREE_TYPE (t
)))
2298 line
= DECL_SOURCE_LINE (TYPE_MAIN_DECL (t
));
2299 else if (TREE_CODE (t
) == OVERLOAD
)
2300 line
= DECL_SOURCE_LINE (OVL_FUNCTION (t
));
2302 line
= DECL_SOURCE_LINE (t
);
2310 /* Now the interfaces from cp_error et al to dump_type et al. Each takes an
2311 on/off VERBOSE flag and supply the appropriate TFF_ flags to a dump_
2315 decl_to_string (decl
, verbose
)
2321 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == RECORD_TYPE
2322 || TREE_CODE (decl
) == UNION_TYPE
|| TREE_CODE (decl
) == ENUMERAL_TYPE
)
2323 flags
= TFF_CLASS_KEY_OR_ENUM
;
2325 flags
|= TFF_DECL_SPECIFIERS
| TFF_FUNCTION_DEFAULT_ARGUMENTS
;
2326 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
2327 flags
|= TFF_DECL_SPECIFIERS
| TFF_RETURN_TYPE
;
2328 flags
|= TFF_TEMPLATE_HEADER
;
2330 reinit_global_formatting_buffer ();
2332 dump_decl (decl
, flags
);
2334 return output_finalize_message (scratch_buffer
);
2338 expr_to_string (decl
, verbose
)
2340 int verbose ATTRIBUTE_UNUSED
;
2342 reinit_global_formatting_buffer ();
2344 dump_expr (decl
, 0);
2346 return output_finalize_message (scratch_buffer
);
2350 fndecl_to_string (fndecl
, verbose
)
2356 flags
= TFF_EXCEPTION_SPECIFICATION
| TFF_DECL_SPECIFIERS
;
2358 flags
|= TFF_FUNCTION_DEFAULT_ARGUMENTS
;
2359 reinit_global_formatting_buffer ();
2361 dump_decl (fndecl
, flags
);
2363 return output_finalize_message (scratch_buffer
);
2368 code_to_string (c
, v
)
2370 int v ATTRIBUTE_UNUSED
;
2372 return tree_code_name
[c
];
2376 language_to_string (c
, v
)
2378 int v ATTRIBUTE_UNUSED
;
2385 case lang_cplusplus
:
2392 my_friendly_abort (355);
2397 /* Return the proper printed version of a parameter to a C++ function. */
2400 parm_to_string (p
, v
)
2402 int v ATTRIBUTE_UNUSED
;
2407 sprintf (digit_buffer
, "%d", p
+1);
2408 return digit_buffer
;
2414 int v ATTRIBUTE_UNUSED
;
2418 id
= operator_name_info
[(int) p
].identifier
;
2419 return id
? IDENTIFIER_POINTER (id
) : "{unknown}";
2423 type_to_string (typ
, verbose
)
2431 flags
|= TFF_CLASS_KEY_OR_ENUM
;
2432 flags
|= TFF_TEMPLATE_HEADER
;
2434 reinit_global_formatting_buffer ();
2436 dump_type (typ
, flags
);
2438 return output_finalize_message (scratch_buffer
);
2442 assop_to_string (p
, v
)
2444 int v ATTRIBUTE_UNUSED
;
2448 id
= assignment_operator_name_info
[(int) p
].identifier
;
2449 return id
? IDENTIFIER_POINTER (id
) : "{unknown}";
2453 args_to_string (p
, verbose
)
2459 flags
|= TFF_CLASS_KEY_OR_ENUM
;
2464 if (TYPE_P (TREE_VALUE (p
)))
2465 return type_as_string (p
, flags
);
2467 reinit_global_formatting_buffer ();
2468 for (; p
; p
= TREE_CHAIN (p
))
2470 if (TREE_VALUE (p
) == null_node
)
2471 print_identifier (scratch_buffer
, "NULL");
2473 dump_type (error_type (TREE_VALUE (p
)), flags
);
2475 separate_with_comma (scratch_buffer
);
2477 return output_finalize_message (scratch_buffer
);
2483 int v ATTRIBUTE_UNUSED
;
2485 reinit_global_formatting_buffer ();
2487 dump_qualifiers (p
, before
);
2489 return output_finalize_message (scratch_buffer
);
2493 lang_print_error_function (file
)
2498 default_print_error_function (file
);
2499 os
= output_buffer_state (diagnostic_buffer
);
2500 output_set_prefix (diagnostic_buffer
, file
);
2501 maybe_print_instantiation_context (diagnostic_buffer
);
2502 output_buffer_state (diagnostic_buffer
) = os
;
2506 cp_diagnostic_starter (buffer
, dc
)
2507 output_buffer
*buffer
;
2508 diagnostic_context
*dc
;
2510 report_problematic_module (buffer
);
2511 cp_print_error_function (buffer
, dc
);
2512 maybe_print_instantiation_context (buffer
);
2513 output_set_prefix (buffer
,
2514 context_as_prefix (diagnostic_file_location (dc
),
2515 diagnostic_line_location (dc
),
2516 diagnostic_is_warning (dc
)));
2520 cp_diagnostic_finalizer (buffer
, dc
)
2521 output_buffer
*buffer
;
2522 diagnostic_context
*dc
__attribute__ ((__unused__
));
2524 output_destroy_prefix (buffer
);
2527 /* Print current function onto BUFFER, in the process of reporting
2528 a diagnostic message. Called from cp_diagnostic_starter. */
2530 cp_print_error_function (buffer
, dc
)
2531 output_buffer
*buffer
;
2532 diagnostic_context
*dc
;
2534 if (error_function_changed ())
2536 char *prefix
= diagnostic_file_location (dc
)
2537 ? file_name_as_prefix (diagnostic_file_location (dc
))
2541 os
= output_buffer_state (buffer
);
2542 output_set_prefix (buffer
, prefix
);
2544 if (current_function_decl
== NULL
)
2545 output_add_string (buffer
, "At global scope:");
2548 (buffer
, "In %s `%s':", function_category (current_function_decl
),
2549 (*decl_printable_name
) (current_function_decl
, 2));
2550 output_add_newline (buffer
);
2552 record_last_error_function ();
2553 output_destroy_prefix (buffer
);
2554 output_buffer_state (buffer
) = os
;
2558 /* Returns a description of FUNCTION using standard terminology. */
2560 function_category (fn
)
2563 if (DECL_FUNCTION_MEMBER_P (fn
))
2565 if (DECL_STATIC_FUNCTION_P (fn
))
2566 return "static member function";
2567 else if (DECL_COPY_CONSTRUCTOR_P (fn
))
2568 return "copy constructor";
2569 else if (DECL_CONSTRUCTOR_P (fn
))
2570 return "constructor";
2571 else if (DECL_DESTRUCTOR_P (fn
))
2572 return "destructor";
2574 return "member function";
2580 /* Report the full context of a current template instantiation,
2583 print_instantiation_full_context (buffer
)
2584 output_buffer
*buffer
;
2586 tree p
= current_instantiation ();
2588 const char *file
= input_filename
;
2592 if (current_function_decl
!= TINST_DECL (p
)
2593 && current_function_decl
!= NULL_TREE
)
2594 /* We can get here during the processing of some synthesized
2595 method. Then, TINST_DECL (p) will be the function that's causing
2600 if (current_function_decl
== TINST_DECL (p
))
2601 /* Avoid redundancy with the the "In function" line. */;
2603 output_verbatim (buffer
, "%s: In instantiation of `%s':\n", file
,
2604 decl_as_string (TINST_DECL (p
),
2605 TFF_DECL_SPECIFIERS
| TFF_RETURN_TYPE
));
2607 line
= TINST_LINE (p
);
2608 file
= TINST_FILE (p
);
2613 print_instantiation_partial_context (buffer
, p
, file
, line
);
2616 /* Same as above but less verbose. */
2618 print_instantiation_partial_context (buffer
, t
, file
, line
)
2619 output_buffer
*buffer
;
2624 for (; t
; t
= TREE_CHAIN (t
))
2627 (buffer
, "%s:%d: instantiated from `%s'\n", file
, line
,
2628 decl_as_string (TINST_DECL (t
), TFF_DECL_SPECIFIERS
| TFF_RETURN_TYPE
));
2629 line
= TINST_LINE (t
);
2630 file
= TINST_FILE (t
);
2632 output_verbatim (buffer
, "%s:%d: instantiated from here\n", file
, line
);
2635 /* Called from cp_thing to print the template context for an error. */
2637 maybe_print_instantiation_context (buffer
)
2638 output_buffer
*buffer
;
2640 if (!problematic_instantiation_changed () || current_instantiation () == 0)
2643 record_last_problematic_instantiation ();
2644 print_instantiation_full_context (buffer
);
2647 /* Report the bare minimum context of a template instantiation. */
2649 print_instantiation_context ()
2651 print_instantiation_partial_context
2652 (diagnostic_buffer
, current_instantiation (), input_filename
, lineno
);
2653 flush_diagnostic_buffer ();
2656 /* Called from output_format -- during diagnostic message processing --
2657 to handle C++ specific format specifier with the following meanings:
2658 %A function argument-list.
2661 %F function declaration.
2662 %P function parameter whose position is indicated by an integer.
2666 cp_tree_printer (buffer
)
2667 output_buffer
*buffer
;
2670 tree_formatting_info tfi
;
2672 memset (&tfi
, 0, sizeof (tree_formatting_info
));
2674 if (*output_buffer_text_cursor (buffer
) == '+')
2675 ++output_buffer_text_cursor (buffer
);
2676 if (*output_buffer_text_cursor (buffer
) == '#')
2679 ++output_buffer_text_cursor (buffer
);
2682 switch (*output_buffer_text_cursor (buffer
))
2685 tree_being_formatted (&tfi
) =
2686 va_arg (output_buffer_format_args (buffer
), tree
);
2688 tree_formatting_flags (&tfi
) = TFF_SCOPE
2689 | TFF_FUNCTION_DEFAULT_ARGUMENTS
;
2690 print_function_argument_list (buffer
, &tfi
);
2694 tree_being_formatted (&tfi
) =
2695 va_arg (output_buffer_format_args (buffer
), tree
);
2697 tree_formatting_flags (&tfi
) = TFF_SCOPE
| TFF_DECL_SPECIFIERS
2698 | TFF_CLASS_KEY_OR_ENUM
| TFF_RETURN_TYPE
2699 | TFF_FUNCTION_DEFAULT_ARGUMENTS
| TFF_TEMPLATE_DEFAULT_ARGUMENTS
2700 | TFF_EXCEPTION_SPECIFICATION
| TFF_CHASE_NAMESPACE_ALIAS
;
2701 print_declaration (buffer
, &tfi
);
2705 tree_being_formatted (&tfi
) =
2706 va_arg (output_buffer_format_args (buffer
), tree
);
2708 tree_formatting_flags (&tfi
) = TFF_SCOPE
;
2709 print_expression (buffer
, &tfi
);
2713 tree_being_formatted (&tfi
) =
2714 va_arg (output_buffer_format_args (buffer
), tree
);
2716 tree_formatting_flags (&tfi
) = TFF_SCOPE
| TFF_DECL_SPECIFIERS
2717 | TFF_RETURN_TYPE
| TFF_FUNCTION_DEFAULT_ARGUMENTS
2718 | TFF_EXCEPTION_SPECIFICATION
;
2719 print_function_declaration (buffer
, &tfi
);
2723 print_function_parameter
2724 (buffer
, va_arg (output_buffer_format_args (buffer
), int));
2728 tree_being_formatted (&tfi
) =
2729 va_arg (output_buffer_format_args (buffer
), tree
);
2731 tree_formatting_flags (&tfi
) = TFF_SCOPE
| TFF_CLASS_KEY_OR_ENUM
2732 | TFF_RETURN_TYPE
| TFF_EXCEPTION_SPECIFICATION
;
2733 print_type_id (buffer
, &tfi
);
2737 tree_being_formatted (&tfi
) =
2738 va_arg (output_buffer_format_args (buffer
), tree
);
2739 print_cv_qualifier_seq (buffer
, &tfi
);
2749 /* Print a function argument-list represented by tree_being_formatted (TFI)
2752 print_function_argument_list (buffer
, tfi
)
2753 output_buffer
*buffer
__attribute__ ((__unused__
));
2754 tfi_t tfi
__attribute__ ((__unused__
));
2758 /* Print a declaration represented by tree_being_formatted (TFI)
2761 print_declaration (buffer
, tfi
)
2762 output_buffer
*buffer
__attribute__ ((__unused__
));
2763 tfi_t tfi
__attribute__ ((__unused__
));
2767 /* Print an expression represented by tree_being_formatted (TFI)
2770 print_expression (buffer
, tfi
)
2771 output_buffer
*buffer
__attribute__ ((__unused__
));
2772 tfi_t tfi
__attribute__ ((__unused__
));
2777 print_integer (buffer
, i
)
2778 output_buffer
*buffer
;
2781 sprintf (digit_buffer
, HOST_WIDE_INT_PRINT_DEC
, (HOST_WIDE_INT
) i
);
2782 output_add_string (buffer
, digit_buffer
);
2785 /* Print a function declaration represented by tree_being_formatted (TFI)
2788 print_function_declaration (buffer
, tfi
)
2789 output_buffer
*buffer
__attribute__ ((__unused__
));
2790 tfi_t tfi
__attribute__ ((__unused__
));
2794 /* Print the N'th function parameter onto BUFFER. A negative value of N
2795 means the implicit "this" parameter of a member function. */
2797 print_function_parameter (buffer
, n
)
2798 output_buffer
*buffer
;
2802 print_identifier (buffer
, "this");
2804 output_decimal (buffer
, n
+ 1);
2807 /* Print a type represented by tree_being_formatted (TFI) onto BUFFER. */
2809 print_type_id (buffer
, tfi
)
2810 output_buffer
*buffer
;
2813 tree t
= tree_being_formatted (tfi
);
2814 int flags
= tree_formatting_flags (tfi
);
2818 if (flags
& TFF_CHASE_TYPEDEF
)
2819 tree_being_formatted (tfi
) =
2820 typedef_original_name (tree_being_formatted (tfi
));
2822 /* A type-id is of the form:
2824 type-specifier-seq abstract-declarator(opt) */
2825 print_type_specifier_seq (buffer
, tfi
);
2827 if (TYPE_PTRMEMFUNC_P (t
))
2830 /* For types with abstract-declarator, print_type_specifier_seq prints
2831 the start of the abstract-declarator. Fiinish the job. */
2832 switch (TREE_CODE (t
))
2836 case REFERENCE_TYPE
:
2841 print_rest_of_abstract_declarator (buffer
, tfi
);
2847 tree_being_formatted (tfi
) = t
;
2850 /* Print the type-specifier-seq part of a type-id. If appropriate, print
2851 also the prefix of the abstract-declarator. */
2853 print_type_specifier_seq (buffer
, tfi
)
2854 output_buffer
*buffer
;
2857 int flags
= tree_formatting_flags (tfi
);
2858 tree t
= tree_being_formatted (tfi
);
2859 enum tree_code code
= TREE_CODE (t
);
2861 /* A type-speficier-seq is:
2862 type-specifier type-specifier-seq(opt)
2865 simple-type-specifier
2868 elaborated-type-specifier
2871 We do not, however, pretty-print class-specifier nor enum-specifier. */
2876 case IDENTIFIER_NODE
:
2886 case TEMPLATE_TYPE_PARM
:
2888 case TEMPLATE_TEMPLATE_PARM
:
2891 print_cv_qualifier_seq (buffer
, tfi
);
2892 if ((flags
& TFF_DECL_SPECIFIERS
)
2893 && (code
== TYPENAME_TYPE
|| IS_AGGR_TYPE (t
)))
2894 print_elaborated_type_specifier (buffer
, tfi
);
2896 print_simple_type_specifier (buffer
, tfi
);
2899 /* Because the abstract-declarator can modify the type-specifier-seq
2900 in a highly non linear manner, we pretty-print its prefix here.
2901 The suffix part is handled by print_rest_of_abstract_declarator. */
2903 /* A RECORD_TYPE is also used to represent a pointer to member
2906 if (TYPE_PTRMEMFUNC_P (t
))
2908 /* Print the return type. */
2909 tree_being_formatted (tfi
) =
2910 TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (t
));
2911 print_type_id (buffer
, tfi
);
2912 print_whitespace (buffer
, tfi
);
2914 /* Then the beginning of the abstract-declarator part. */
2915 tree_being_formatted (tfi
) =
2916 TYPE_METHOD_BASETYPE (TYPE_PTRMEMFUNC_FN_TYPE (t
));
2917 print_left_paren (buffer
);
2918 print_nested_name_specifier (buffer
, tfi
);
2925 if (TYPE_PTRMEM_P (t
))
2926 goto ptr_data_member
;
2928 goto non_ptr_data_member
;
2932 case REFERENCE_TYPE
:
2935 non_ptr_data_member
:
2936 tree_being_formatted (tfi
) = TREE_TYPE (t
);
2937 print_type_specifier_seq (buffer
, tfi
);
2938 if (code
== POINTER_TYPE
|| code
== REFERENCE_TYPE
)
2940 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
2941 print_left_paren (buffer
);
2943 else if (code
== FUNCTION_TYPE
|| code
== METHOD_TYPE
)
2945 print_whitespace (buffer
, tfi
);
2946 print_left_paren (buffer
);
2947 if (code
== METHOD_TYPE
)
2949 tree_being_formatted (tfi
) = TYPE_METHOD_BASETYPE (t
);
2950 print_nested_name_specifier (buffer
, tfi
);
2951 tree_being_formatted (tfi
) = t
;
2954 tree_being_formatted (tfi
) = t
;
2959 /* Firstly, the type of the member. */
2960 tree_being_formatted (tfi
) = TREE_TYPE (t
);
2961 print_type_id (buffer
, tfi
);
2962 print_whitespace (buffer
, tfi
);
2964 /* Then, the containing class. */
2965 tree_being_formatted (tfi
) = TYPE_OFFSET_BASETYPE (t
);
2966 print_nested_name_specifier (buffer
, tfi
);
2967 tree_being_formatted (tfi
) = t
;
2971 sorry_for_unsupported_tree (t
);
2975 print_identifier (buffer
, "{type-specifier-seq error}");
2979 tree_being_formatted (tfi
) = t
;
2982 /* Print the simpe-type-specifier component of a type-specifier. */
2984 print_simple_type_specifier (buffer
, tfi
)
2985 output_buffer
*buffer
;
2988 int flags
= tree_formatting_flags (tfi
);
2989 tree t
= tree_being_formatted (tfi
);
2990 enum tree_code code
= TREE_CODE (t
);
2995 print_identifier (buffer
, "{unknown type}");
2998 case IDENTIFIER_NODE
:
2999 print_tree_identifier (buffer
, t
);
3003 print_identifier (buffer
, "__complex__ ");
3004 tree_being_formatted (tfi
) = TREE_TYPE (t
);
3005 print_type_id (buffer
, tfi
);
3009 tree_being_formatted (tfi
) = TYPE_CONTEXT (t
);
3010 print_nested_name_specifier (buffer
, tfi
);
3011 tree_being_formatted (tfi
) = TYPENAME_TYPE_FULLNAME (t
);
3012 tree_formatting_flags (tfi
) |= ~TFF_CHASE_TYPEDEF
;
3013 print_type_id (buffer
, tfi
);
3017 print_identifier (buffer
, "__typeof__");
3018 tree_being_formatted (tfi
) = TYPE_FIELDS (t
);
3019 print_left_paren (buffer
);
3020 print_expression (buffer
, tfi
);
3021 print_right_paren (buffer
);
3025 if (TREE_UNSIGNED (t
))
3027 if (TYPE_MAIN_VARIANT (t
) == integer_type_node
)
3028 /* We don't want pedantry like `unsigned int'. */;
3029 else if (!TREE_UNSIGNED (TYPE_MAIN_VARIANT (t
)))
3031 print_identifier (buffer
, "unsigned");
3032 print_whitespace (buffer
, tfi
);
3035 else if (TYPE_MAIN_VARIANT (t
) == char_type_node
)
3037 print_identifier (buffer
, "signed");
3038 print_whitespace (buffer
, tfi
);
3044 tree s
= (flags
& TFF_CHASE_TYPEDEF
) ? TYPE_MAIN_VARIANT (t
) : t
;
3046 if (TYPE_NAME (s
) && TYPE_IDENTIFIER (s
))
3047 print_tree_identifier (buffer
, TYPE_IDENTIFIER (s
));
3049 /* Types like intQI_type_node and friends have no names.
3050 These don't come up in user error messages, but it's nice
3051 to be able to print them from the debugger. */
3052 print_identifier (buffer
, "{anonymous}");
3056 case TEMPLATE_TEMPLATE_PARM
:
3057 if (TYPE_IDENTIFIER (t
))
3058 print_tree_identifier (buffer
, TYPE_IDENTIFIER (t
));
3060 print_identifier (buffer
, "{anonymous template template parameter}");
3064 if (flags
& TFF_CHASE_TYPEDEF
)
3065 print_type_id (buffer
, tfi
);
3067 print_tree_identifier (buffer
, DECL_NAME (t
));
3070 case BOUND_TEMPLATE_TEMPLATE_PARM
:
3072 print_template_id (buffer
, tfi
);
3075 case TEMPLATE_TYPE_PARM
:
3076 if (TYPE_IDENTIFIER (t
))
3077 print_tree_identifier (buffer
, TYPE_IDENTIFIER (t
));
3079 print_identifier (buffer
, "{anonymous template type parameter}");
3086 tree_being_formatted (tfi
) = t
;
3087 tree_formatting_flags (tfi
) = flags
;
3090 /* Print the elaborated-type-specifier form of a type-specifier. */
3092 print_elaborated_type_specifier (buffer
, tfi
)
3093 output_buffer
*buffer
;
3096 int flags
= tree_formatting_flags (tfi
);
3097 tree t
= tree_being_formatted (tfi
);
3099 switch (TREE_CODE (t
))
3102 print_identifier (buffer
, "typename");
3103 print_whitespace (buffer
, tfi
);
3104 tree_formatting_flags (tfi
) |= ~TFF_DECL_SPECIFIERS
;
3105 print_simple_type_specifier (buffer
, tfi
);
3111 tree name
= NULL_TREE
;
3113 if (flags
& TFF_CHASE_TYPEDEF
)
3114 tree_being_formatted (tfi
) = typedef_original_name (t
);
3117 (buffer
, class_key_or_enum (tree_being_formatted (tfi
)));
3118 print_whitespace (buffer
, tfi
);
3120 name
= TYPE_NAME (tree_being_formatted (tfi
));
3123 if (flags
& TFF_SCOPE
)
3125 tree_being_formatted (tfi
) = CP_DECL_CONTEXT (name
);
3126 print_nested_name_specifier (buffer
, tfi
);
3128 print_tree_identifier (buffer
, DECL_NAME (name
));
3131 print_identifier (buffer
, "{anonymous}");
3136 sorry_for_unsupported_tree (t
);
3140 tree_being_formatted (tfi
) = t
;
3141 tree_formatting_flags (tfi
) = flags
;
3144 /* Finish the job of printing the abstract-declarator part of a
3147 print_rest_of_abstract_declarator (buffer
, tfi
)
3148 output_buffer
*buffer
;
3151 tree t
= tree_being_formatted (tfi
);
3152 enum tree_code code
= TREE_CODE (t
);
3154 /* An abstract-declarator has the form:
3156 abstract-declarator:
3157 ptr-operator abstract-declarator(opt)
3158 direct-abstract-declarator
3160 direct-abstract-declarator:
3161 direct-abstract-declarator(opt)
3162 ( parameter-declaration-clause ) cv-qualifier-seq(opt)
3163 exception-specification(opt)
3164 direct-abstract-declarator(opt) [ constant-expression(opt) ]
3165 ( direct-abstract-declarator ) */
3170 print_left_bracket (buffer
);
3171 if (TYPE_DOMAIN (t
))
3173 tree s
= TYPE_DOMAIN (t
);
3175 if (host_integerp (TYPE_MAX_VALUE (s
), 0))
3176 output_decimal (buffer
, tree_low_cst (TYPE_MAX_VALUE (s
), 0) + 1);
3177 else if (TREE_CODE (TYPE_MAX_VALUE (s
)) == MINUS_EXPR
)
3179 tree_being_formatted (tfi
) =
3180 TREE_OPERAND (TYPE_MAX_VALUE (s
), 0);
3181 print_expression (buffer
, tfi
);
3182 tree_being_formatted (tfi
) = t
;
3186 tree_being_formatted (tfi
) = fold
3187 (cp_build_binary_op (PLUS_EXPR
, TYPE_MAX_VALUE (s
),
3189 print_expression (buffer
, tfi
);
3190 tree_being_formatted (tfi
) = t
;
3193 print_right_bracket (buffer
);
3194 put_whitespace (tfi
) = none
;
3195 tree_being_formatted (tfi
) = TREE_TYPE (t
);
3196 print_rest_of_abstract_declarator (buffer
, tfi
);
3197 tree_being_formatted (tfi
) = t
;
3201 case REFERENCE_TYPE
:
3203 if (code
== POINTER_TYPE
|| code
== REFERENCE_TYPE
)
3205 output_add_character (buffer
, "&*"[code
== POINTER_TYPE
]);
3206 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
3207 print_right_paren (buffer
);
3209 put_whitespace (tfi
) = before
;
3210 print_cv_qualifier_seq (buffer
, tfi
);
3211 tree_being_formatted (tfi
) = TREE_TYPE (t
);
3212 print_rest_of_abstract_declarator (buffer
, tfi
);
3213 tree_being_formatted (tfi
) = t
;
3218 print_right_paren (buffer
);
3219 print_whitespace (buffer
, tfi
);
3221 /* Skip the `this' implicit parameter if present. */
3222 tree_being_formatted (tfi
) = TYPE_ARG_TYPES (t
);
3223 if (code
== METHOD_TYPE
)
3224 tree_being_formatted (tfi
) = TREE_CHAIN (tree_being_formatted (tfi
));
3226 /* Print the parameter-list. */
3227 print_left_paren (buffer
);
3228 print_parameter_declaration_clause (buffer
, tfi
);
3229 print_right_paren (buffer
);
3231 print_whitespace (buffer
, tfi
);
3233 if (code
== METHOD_TYPE
)
3235 tree_being_formatted (tfi
) =
3236 TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t
)));
3237 print_cv_qualifier_seq (buffer
, tfi
);
3240 /* Finish the abstract-declarator. */
3241 tree_being_formatted (tfi
) = TREE_TYPE (t
);
3242 print_rest_of_abstract_declarator (buffer
, tfi
);
3244 /* Print the exception-specification for documentaion purpose. */
3245 tree_being_formatted (tfi
) = TYPE_RAISES_EXCEPTIONS (t
);
3246 print_exception_specification (buffer
, tfi
);
3247 tree_being_formatted (tfi
) = t
;
3250 /* These types don't have abstract-declarator. */
3252 case IDENTIFIER_NODE
:
3262 case TEMPLATE_TYPE_PARM
:
3264 case TEMPLATE_TEMPLATE_PARM
:
3269 sorry_for_unsupported_tree (t
);
3270 /* fall throught. */
3276 /* Print the cv-quafilers of tree_being_formatted (TFI) onto BUFFER. */
3278 print_cv_qualifier_seq (buffer
, tfi
)
3279 output_buffer
*buffer
;
3280 tree_formatting_info
*tfi
;
3282 int cv
= TYPE_QUALS (tree_being_formatted (tfi
));
3283 int pad_after
= after
== put_whitespace (tfi
);
3284 static const int mask
[]
3285 = {TYPE_QUAL_CONST
, TYPE_QUAL_VOLATILE
, TYPE_QUAL_RESTRICT
};
3286 static const char *const qualifier
[]
3287 = { "const", "volatile", "__restrict__" };
3292 for (i
= 0; i
!= 3; ++i
)
3295 if (put_whitespace (tfi
) == before
)
3296 output_add_space (buffer
);
3297 print_identifier (buffer
, qualifier
[i
]);
3298 put_whitespace (tfi
) = before
;
3303 output_add_space (buffer
);
3304 put_whitespace (tfi
) = none
;
3310 print_parameter_declaration_clause (buffer
, tfi
)
3311 output_buffer
*buffer
__attribute__ ((__unused__
));
3312 tfi_t tfi
__attribute__ ((__unused__
));
3317 print_exception_specification (buffer
, tfi
)
3318 output_buffer
*buffer
__attribute__ ((__unused__
));
3319 tfi_t tfi
__attribute__ ((__unused__
));
3324 print_nested_name_specifier (buffer
, tfi
)
3325 output_buffer
*buffer
;
3328 int flags
= tree_formatting_flags (tfi
);
3329 tree t
= tree_being_formatted (tfi
);
3330 /* A nested-name-specifier is:
3331 class-or-namespace-name :: nested-name-specifier(opt)
3332 class-or-namespace-name :: template nested-name-specifier
3334 The latter form being the correct syntax for a name designating
3335 a template member, where the preceding class-or-namespace-name part
3336 is name-dependent. For the time being, we do not do such a
3337 sophisticated pretty-printing.
3339 class-or-namespace-name:
3343 if (t
== NULL_TREE
|| t
== global_namespace
)
3346 if (CLASS_TYPE_P (t
) && !(flags
& TFF_CLASS_SCOPE
))
3349 if (TREE_CODE (t
) == NAMESPACE_DECL
&& !(flags
& TFF_NAMESPACE_SCOPE
))
3352 tree_being_formatted (tfi
) = DECL_CONTEXT (t
);
3353 print_nested_name_specifier (buffer
, tfi
);
3354 print_scope_operator (buffer
);
3355 if (TREE_CODE (t
) == NAMESPACE_DECL
)
3356 print_tree_identifier (buffer
, DECL_NAME (t
));
3357 else if (CLASS_TYPE_P (t
))
3359 if (!DECL_USE_TEMPLATE (t
))
3360 print_tree_identifier (buffer
, TYPE_IDENTIFIER (t
));
3363 tree_being_formatted (tfi
) = t
;
3364 print_template_id (buffer
, tfi
);
3368 tree_being_formatted (tfi
) = t
;
3372 print_template_id (buffer
, tfi
)
3373 output_buffer
*buffer
;
3374 tfi_t tfi
__attribute__ ((__unused__
));
3376 print_template_argument_list_start (buffer
);
3378 print_template_argument_list_end (buffer
);
3382 typedef_original_name (t
)
3385 return DECL_ORIGINAL_TYPE (t
) ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
);
3389 print_non_consecutive_character (buffer
, c
)
3390 output_buffer
*buffer
;
3393 const char *p
= output_last_position (buffer
);
3395 if (p
!= NULL
&& *p
== c
)
3396 output_add_space (buffer
);
3397 output_add_character (buffer
, c
);