1 /* Call-backs for C++ error reporting.
2 This code is non-reentrant.
3 Copyright (C) 1993-2019 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
21 /* For use with name_hint. */
22 #define INCLUDE_UNIQUE_PTR
24 #include "coretypes.h"
26 #include "stringpool.h"
27 #include "tree-diagnostic.h"
28 #include "langhooks-def.h"
30 #include "cxx-pretty-print.h"
31 #include "tree-pretty-print.h"
32 #include "gimple-pretty-print.h"
33 #include "c-family/c-objc.h"
35 #include "internal-fn.h"
36 #include "gcc-rich-location.h"
37 #include "cp-name-hint.h"
39 #define pp_separate_with_comma(PP) pp_cxx_separate_with (PP, ',')
40 #define pp_separate_with_semicolon(PP) pp_cxx_separate_with (PP, ';')
42 /* cxx_pp is a C++ front-end-specific pretty printer: this is where we
43 dump C++ ASTs as strings. It is mostly used only by the various
44 tree -> string functions that are occasionally called from the
45 debugger or by the front-end for things like
46 __PRETTY_FUNCTION__. */
47 static cxx_pretty_printer actual_pretty_printer
;
48 static cxx_pretty_printer
* const cxx_pp
= &actual_pretty_printer
;
50 /* Translate if being used for diagnostics, but not for dump files or
52 #define M_(msgid) (pp_translate_identifiers (cxx_pp) ? _(msgid) : (msgid))
54 # define NEXT_CODE(T) (TREE_CODE (TREE_TYPE (T)))
56 static const char *args_to_string (tree
, int);
57 static const char *code_to_string (enum tree_code
);
58 static const char *cv_to_string (tree
, int);
59 static const char *decl_to_string (tree
, int);
60 static const char *fndecl_to_string (tree
, int);
61 static const char *op_to_string (bool, enum tree_code
);
62 static const char *parm_to_string (int);
63 static const char *type_to_string (tree
, int, bool, bool *, bool);
65 static void dump_alias_template_specialization (cxx_pretty_printer
*, tree
, int);
66 static void dump_type (cxx_pretty_printer
*, tree
, int);
67 static void dump_typename (cxx_pretty_printer
*, tree
, int);
68 static void dump_simple_decl (cxx_pretty_printer
*, tree
, tree
, int);
69 static void dump_decl (cxx_pretty_printer
*, tree
, int);
70 static void dump_template_decl (cxx_pretty_printer
*, tree
, int);
71 static void dump_function_decl (cxx_pretty_printer
*, tree
, int);
72 static void dump_expr (cxx_pretty_printer
*, tree
, int);
73 static void dump_unary_op (cxx_pretty_printer
*, const char *, tree
, int);
74 static void dump_binary_op (cxx_pretty_printer
*, const char *, tree
, int);
75 static void dump_aggr_type (cxx_pretty_printer
*, tree
, int);
76 static void dump_type_prefix (cxx_pretty_printer
*, tree
, int);
77 static void dump_type_suffix (cxx_pretty_printer
*, tree
, int);
78 static void dump_function_name (cxx_pretty_printer
*, tree
, int);
79 static void dump_call_expr_args (cxx_pretty_printer
*, tree
, int, bool);
80 static void dump_aggr_init_expr_args (cxx_pretty_printer
*, tree
, int, bool);
81 static void dump_expr_list (cxx_pretty_printer
*, tree
, int);
82 static void dump_global_iord (cxx_pretty_printer
*, tree
);
83 static void dump_parameters (cxx_pretty_printer
*, tree
, int);
84 static void dump_ref_qualifier (cxx_pretty_printer
*, tree
, int);
85 static void dump_exception_spec (cxx_pretty_printer
*, tree
, int);
86 static void dump_template_argument (cxx_pretty_printer
*, tree
, int);
87 static void dump_template_argument_list (cxx_pretty_printer
*, tree
, int);
88 static void dump_template_parameter (cxx_pretty_printer
*, tree
, int);
89 static void dump_template_bindings (cxx_pretty_printer
*, tree
, tree
,
91 static void dump_scope (cxx_pretty_printer
*, tree
, int);
92 static void dump_template_parms (cxx_pretty_printer
*, tree
, int, int);
93 static int get_non_default_template_args_count (tree
, int);
94 static const char *function_category (tree
);
95 static void maybe_print_constexpr_context (diagnostic_context
*);
96 static void maybe_print_instantiation_context (diagnostic_context
*);
97 static void print_instantiation_full_context (diagnostic_context
*);
98 static void print_instantiation_partial_context (diagnostic_context
*,
101 static void maybe_print_constraint_context (diagnostic_context
*);
102 static void cp_diagnostic_starter (diagnostic_context
*, diagnostic_info
*);
103 static void cp_print_error_function (diagnostic_context
*, diagnostic_info
*);
105 static bool cp_printer (pretty_printer
*, text_info
*, const char *,
106 int, bool, bool, bool, bool *, const char **);
108 /* Struct for handling %H or %I, which require delaying printing the
109 type until a postprocessing stage. */
111 class deferred_printed_type
114 deferred_printed_type ()
115 : m_tree (NULL_TREE
), m_buffer_ptr (NULL
), m_verbose (false), m_quote (false)
118 deferred_printed_type (tree type
, const char **buffer_ptr
, bool verbose
,
120 : m_tree (type
), m_buffer_ptr (buffer_ptr
), m_verbose (verbose
),
124 gcc_assert (buffer_ptr
);
127 /* The tree is not GTY-marked: they are only non-NULL within a
128 call to pp_format. */
130 const char **m_buffer_ptr
;
135 /* Subclass of format_postprocessor for the C++ frontend.
136 This handles the %H and %I formatting codes, printing them
137 in a postprocessing phase (since they affect each other). */
139 class cxx_format_postprocessor
: public format_postprocessor
142 cxx_format_postprocessor ()
143 : m_type_a (), m_type_b ()
146 void handle (pretty_printer
*pp
) FINAL OVERRIDE
;
148 deferred_printed_type m_type_a
;
149 deferred_printed_type m_type_b
;
152 /* CONTEXT->printer is a basic pretty printer that was constructed
153 presumably by diagnostic_initialize(), called early in the
154 compiler's initialization process (in general_init) Before the FE
155 is initialized. This (C++) FE-specific diagnostic initializer is
156 thus replacing the basic pretty printer with one that has C++-aware
160 cxx_initialize_diagnostics (diagnostic_context
*context
)
162 pretty_printer
*base
= context
->printer
;
163 cxx_pretty_printer
*pp
= XNEW (cxx_pretty_printer
);
164 context
->printer
= new (pp
) cxx_pretty_printer ();
166 /* It is safe to free this object because it was previously XNEW()'d. */
167 base
->~pretty_printer ();
170 c_common_diagnostics_set_defaults (context
);
171 diagnostic_starter (context
) = cp_diagnostic_starter
;
172 /* diagnostic_finalizer is already c_diagnostic_finalizer. */
173 diagnostic_format_decoder (context
) = cp_printer
;
174 pp
->m_format_postprocessor
= new cxx_format_postprocessor ();
177 /* Dump a scope, if deemed necessary. */
180 dump_scope (cxx_pretty_printer
*pp
, tree scope
, int flags
)
182 int f
= flags
& (TFF_SCOPE
| TFF_CHASE_TYPEDEF
);
184 if (scope
== NULL_TREE
)
187 /* Enum values within an unscoped enum will be CONST_DECL with an
188 ENUMERAL_TYPE as their "scope". Use CP_TYPE_CONTEXT of the
189 ENUMERAL_TYPE, so as to print any enclosing namespace. */
190 if (UNSCOPED_ENUM_P (scope
))
191 scope
= CP_TYPE_CONTEXT (scope
);
193 if (TREE_CODE (scope
) == NAMESPACE_DECL
)
195 if (scope
!= global_namespace
)
197 dump_decl (pp
, scope
, f
);
198 pp_cxx_colon_colon (pp
);
201 else if (AGGREGATE_TYPE_P (scope
)
202 || SCOPED_ENUM_P (scope
))
204 dump_type (pp
, scope
, f
);
205 pp_cxx_colon_colon (pp
);
207 else if ((flags
& TFF_SCOPE
) && TREE_CODE (scope
) == FUNCTION_DECL
)
209 dump_function_decl (pp
, scope
, f
);
210 pp_cxx_colon_colon (pp
);
214 /* Dump the template ARGument under control of FLAGS. */
217 dump_template_argument (cxx_pretty_printer
*pp
, tree arg
, int flags
)
219 if (ARGUMENT_PACK_P (arg
))
220 dump_template_argument_list (pp
, ARGUMENT_PACK_ARGS (arg
),
221 /* No default args in argument packs. */
222 flags
|TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS
);
223 else if (TYPE_P (arg
) || TREE_CODE (arg
) == TEMPLATE_DECL
)
224 dump_type (pp
, arg
, flags
& ~TFF_CLASS_KEY_OR_ENUM
);
227 if (TREE_CODE (arg
) == TREE_LIST
)
228 arg
= TREE_VALUE (arg
);
230 /* Strip implicit conversions. */
231 while (CONVERT_EXPR_P (arg
))
232 arg
= TREE_OPERAND (arg
, 0);
234 dump_expr (pp
, arg
, (flags
| TFF_EXPR_IN_PARENS
) & ~TFF_CLASS_KEY_OR_ENUM
);
238 /* Count the number of template arguments ARGS whose value does not
239 match the (optional) default template parameter in PARAMS */
242 get_non_default_template_args_count (tree args
, int flags
)
244 int n
= TREE_VEC_LENGTH (INNERMOST_TEMPLATE_ARGS (args
));
246 if (/* We use this flag when generating debug information. We don't
247 want to expand templates at this point, for this may generate
248 new decls, which gets decl counts out of sync, which may in
249 turn cause codegen differences between compilations with and
251 (flags
& TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS
) != 0
252 || !flag_pretty_templates
)
255 return GET_NON_DEFAULT_TEMPLATE_ARGS_COUNT (INNERMOST_TEMPLATE_ARGS (args
));
258 /* Dump a template-argument-list ARGS (always a TREE_VEC) under control
262 dump_template_argument_list (cxx_pretty_printer
*pp
, tree args
, int flags
)
264 int n
= get_non_default_template_args_count (args
, flags
);
268 for (i
= 0; i
< n
; ++i
)
270 tree arg
= TREE_VEC_ELT (args
, i
);
272 /* Only print a comma if we know there is an argument coming. In
273 the case of an empty template argument pack, no actual
274 argument will be printed. */
276 && (!ARGUMENT_PACK_P (arg
)
277 || TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg
)) > 0))
278 pp_separate_with_comma (pp
);
280 dump_template_argument (pp
, arg
, flags
);
285 /* Dump a template parameter PARM (a TREE_LIST) under control of FLAGS. */
288 dump_template_parameter (cxx_pretty_printer
*pp
, tree parm
, int flags
)
293 if (parm
== error_mark_node
)
296 p
= TREE_VALUE (parm
);
297 a
= TREE_PURPOSE (parm
);
299 if (TREE_CODE (p
) == TYPE_DECL
)
301 if (flags
& TFF_DECL_SPECIFIERS
)
303 pp_cxx_ws_string (pp
, "class");
304 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (p
)))
305 pp_cxx_ws_string (pp
, "...");
307 pp_cxx_tree_identifier (pp
, DECL_NAME (p
));
309 else if (DECL_NAME (p
))
310 pp_cxx_tree_identifier (pp
, DECL_NAME (p
));
312 pp_cxx_canonical_template_parameter (pp
, TREE_TYPE (p
));
315 dump_decl (pp
, p
, flags
| TFF_DECL_SPECIFIERS
);
317 if ((flags
& TFF_FUNCTION_DEFAULT_ARGUMENTS
) && a
!= NULL_TREE
)
319 pp_cxx_whitespace (pp
);
321 pp_cxx_whitespace (pp
);
322 if (TREE_CODE (p
) == TYPE_DECL
|| TREE_CODE (p
) == TEMPLATE_DECL
)
323 dump_type (pp
, a
, flags
& ~TFF_CHASE_TYPEDEF
);
325 dump_expr (pp
, a
, flags
| TFF_EXPR_IN_PARENS
);
329 /* Dump, under control of FLAGS, a template-parameter-list binding.
330 PARMS is a TREE_LIST of TREE_VEC of TREE_LIST and ARGS is a
334 dump_template_bindings (cxx_pretty_printer
*pp
, tree parms
, tree args
,
335 vec
<tree
, va_gc
> *typenames
)
337 bool need_semicolon
= false;
343 tree p
= TREE_VALUE (parms
);
344 int lvl
= TMPL_PARMS_DEPTH (parms
);
347 tree lvl_args
= NULL_TREE
;
349 /* Don't crash if we had an invalid argument list. */
350 if (TMPL_ARGS_DEPTH (args
) >= lvl
)
351 lvl_args
= TMPL_ARGS_LEVEL (args
, lvl
);
353 for (i
= 0; i
< TREE_VEC_LENGTH (p
); ++i
)
355 tree arg
= NULL_TREE
;
357 /* Don't crash if we had an invalid argument list. */
358 if (lvl_args
&& NUM_TMPL_ARGS (lvl_args
) > arg_idx
)
359 arg
= TREE_VEC_ELT (lvl_args
, arg_idx
);
362 pp_separate_with_semicolon (pp
);
363 dump_template_parameter (pp
, TREE_VEC_ELT (p
, i
),
364 TFF_PLAIN_IDENTIFIER
);
365 pp_cxx_whitespace (pp
);
367 pp_cxx_whitespace (pp
);
370 if (ARGUMENT_PACK_P (arg
))
371 pp_cxx_left_brace (pp
);
372 dump_template_argument (pp
, arg
, TFF_PLAIN_IDENTIFIER
);
373 if (ARGUMENT_PACK_P (arg
))
374 pp_cxx_right_brace (pp
);
377 pp_string (pp
, M_("<missing>"));
380 need_semicolon
= true;
383 parms
= TREE_CHAIN (parms
);
386 /* Don't bother with typenames for a partial instantiation. */
387 if (vec_safe_is_empty (typenames
) || uses_template_parms (args
))
390 /* Don't try to print typenames when we're processing a clone. */
391 if (current_function_decl
392 && !DECL_LANG_SPECIFIC (current_function_decl
))
395 /* Don't try to do this once cgraph starts throwing away front-end
400 FOR_EACH_VEC_SAFE_ELT (typenames
, i
, t
)
403 pp_separate_with_semicolon (pp
);
404 dump_type (pp
, t
, TFF_PLAIN_IDENTIFIER
);
405 pp_cxx_whitespace (pp
);
407 pp_cxx_whitespace (pp
);
408 push_deferring_access_checks (dk_no_check
);
409 t
= tsubst (t
, args
, tf_none
, NULL_TREE
);
410 pop_deferring_access_checks ();
411 /* Strip typedefs. We can't just use TFF_CHASE_TYPEDEF because
412 pp_simple_type_specifier doesn't know about it. */
413 t
= strip_typedefs (t
);
414 dump_type (pp
, t
, TFF_PLAIN_IDENTIFIER
);
418 /* Dump a human-readable equivalent of the alias template
419 specialization of T. */
422 dump_alias_template_specialization (cxx_pretty_printer
*pp
, tree t
, int flags
)
424 gcc_assert (alias_template_specialization_p (t
));
426 tree decl
= TYPE_NAME (t
);
427 if (!(flags
& TFF_UNQUALIFIED_NAME
))
428 dump_scope (pp
, CP_DECL_CONTEXT (decl
), flags
);
429 pp_cxx_tree_identifier (pp
, DECL_NAME (decl
));
430 dump_template_parms (pp
, DECL_TEMPLATE_INFO (decl
),
432 flags
& ~TFF_TEMPLATE_HEADER
);
435 /* Dump a human-readable equivalent of TYPE. FLAGS controls the
439 dump_type (cxx_pretty_printer
*pp
, tree t
, int flags
)
444 /* Don't print e.g. "struct mytypedef". */
445 if (TYPE_P (t
) && typedef_variant_p (t
))
447 tree decl
= TYPE_NAME (t
);
448 if ((flags
& TFF_CHASE_TYPEDEF
)
449 || DECL_SELF_REFERENCE_P (decl
)
450 || (!flag_pretty_templates
451 && DECL_LANG_SPECIFIC (decl
) && DECL_TEMPLATE_INFO (decl
)))
452 t
= strip_typedefs (t
);
453 else if (alias_template_specialization_p (t
))
455 dump_alias_template_specialization (pp
, t
, flags
);
458 else if (same_type_p (t
, TREE_TYPE (decl
)))
462 pp_cxx_cv_qualifier_seq (pp
, t
);
463 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
468 if (TYPE_PTRMEMFUNC_P (t
))
471 switch (TREE_CODE (t
))
474 if (t
== init_list_type_node
)
475 pp_string (pp
, M_("<brace-enclosed initializer list>"));
476 else if (t
== unknown_type_node
)
477 pp_string (pp
, M_("<unresolved overloaded function type>"));
480 pp_cxx_cv_qualifier_seq (pp
, t
);
481 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
486 /* A list of function parms. */
487 dump_parameters (pp
, t
, flags
);
490 case IDENTIFIER_NODE
:
491 pp_cxx_tree_identifier (pp
, t
);
495 dump_type (pp
, BINFO_TYPE (t
), flags
);
501 dump_aggr_type (pp
, t
, flags
);
505 if (flags
& TFF_CHASE_TYPEDEF
)
507 dump_type (pp
, DECL_ORIGINAL_TYPE (t
)
508 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
), flags
);
515 dump_decl (pp
, t
, flags
& ~TFF_DECL_SPECIFIERS
);
524 case FIXED_POINT_TYPE
:
525 pp_type_specifier_seq (pp
, t
);
528 case TEMPLATE_TEMPLATE_PARM
:
529 /* For parameters inside template signature. */
530 if (TYPE_IDENTIFIER (t
))
531 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
533 pp_cxx_canonical_template_parameter (pp
, t
);
536 case BOUND_TEMPLATE_TEMPLATE_PARM
:
538 tree args
= TYPE_TI_ARGS (t
);
539 pp_cxx_cv_qualifier_seq (pp
, t
);
540 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
541 pp_cxx_begin_template_argument_list (pp
);
542 dump_template_argument_list (pp
, args
, flags
);
543 pp_cxx_end_template_argument_list (pp
);
547 case TEMPLATE_TYPE_PARM
:
548 pp_cxx_cv_qualifier_seq (pp
, t
);
549 if (template_placeholder_p (t
))
551 t
= TREE_TYPE (CLASS_PLACEHOLDER_TEMPLATE (t
));
552 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
553 pp_string (pp
, "<...auto...>");
555 else if (TYPE_IDENTIFIER (t
))
556 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
558 pp_cxx_canonical_template_parameter
559 (pp
, TEMPLATE_TYPE_PARM_INDEX (t
));
560 /* If this is a constrained placeholder, add the requirements. */
561 if (tree c
= PLACEHOLDER_TYPE_CONSTRAINTS (t
))
562 pp_cxx_constrained_type_spec (pp
, c
);
565 /* This is not always necessary for pointers and such, but doing this
566 reduces code size. */
575 dump_type_prefix (pp
, t
, flags
);
576 dump_type_suffix (pp
, t
, flags
);
580 if (! (flags
& TFF_CHASE_TYPEDEF
)
581 && DECL_ORIGINAL_TYPE (TYPE_NAME (t
)))
583 dump_decl (pp
, TYPE_NAME (t
), TFF_PLAIN_IDENTIFIER
);
586 pp_cxx_cv_qualifier_seq (pp
, t
);
587 pp_cxx_ws_string (pp
,
588 TYPENAME_IS_ENUM_P (t
) ? "enum"
589 : TYPENAME_IS_CLASS_P (t
) ? "class"
591 dump_typename (pp
, t
, flags
);
594 case UNBOUND_CLASS_TEMPLATE
:
595 if (! (flags
& TFF_UNQUALIFIED_NAME
))
597 dump_type (pp
, TYPE_CONTEXT (t
), flags
);
598 pp_cxx_colon_colon (pp
);
600 pp_cxx_ws_string (pp
, "template");
601 dump_type (pp
, TYPE_IDENTIFIER (t
), flags
);
605 pp_cxx_ws_string (pp
, "__typeof__");
606 pp_cxx_whitespace (pp
);
607 pp_cxx_left_paren (pp
);
608 dump_expr (pp
, TYPEOF_TYPE_EXPR (t
), flags
& ~TFF_EXPR_IN_PARENS
);
609 pp_cxx_right_paren (pp
);
612 case UNDERLYING_TYPE
:
613 pp_cxx_ws_string (pp
, "__underlying_type");
614 pp_cxx_whitespace (pp
);
615 pp_cxx_left_paren (pp
);
616 dump_expr (pp
, UNDERLYING_TYPE_TYPE (t
), flags
& ~TFF_EXPR_IN_PARENS
);
617 pp_cxx_right_paren (pp
);
620 case TYPE_PACK_EXPANSION
:
621 dump_type (pp
, PACK_EXPANSION_PATTERN (t
), flags
);
622 pp_cxx_ws_string (pp
, "...");
625 case TYPE_ARGUMENT_PACK
:
626 dump_template_argument (pp
, t
, flags
);
630 pp_cxx_ws_string (pp
, "decltype");
631 pp_cxx_whitespace (pp
);
632 pp_cxx_left_paren (pp
);
633 dump_expr (pp
, DECLTYPE_TYPE_EXPR (t
), flags
& ~TFF_EXPR_IN_PARENS
);
634 pp_cxx_right_paren (pp
);
638 pp_string (pp
, "std::nullptr_t");
642 pp_unsupported_tree (pp
, t
);
646 pp_string (pp
, M_("<type error>"));
651 /* Dump a TYPENAME_TYPE. We need to notice when the context is itself
655 dump_typename (cxx_pretty_printer
*pp
, tree t
, int flags
)
657 tree ctx
= TYPE_CONTEXT (t
);
659 if (TREE_CODE (ctx
) == TYPENAME_TYPE
)
660 dump_typename (pp
, ctx
, flags
);
662 dump_type (pp
, ctx
, flags
& ~TFF_CLASS_KEY_OR_ENUM
);
663 pp_cxx_colon_colon (pp
);
664 dump_decl (pp
, TYPENAME_TYPE_FULLNAME (t
), flags
);
667 /* Return the name of the supplied aggregate, or enumeral type. */
670 class_key_or_enum_as_string (tree t
)
672 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
674 if (SCOPED_ENUM_P (t
))
679 else if (TREE_CODE (t
) == UNION_TYPE
)
681 else if (TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_DECLARED_CLASS (t
))
687 /* Print out a class declaration T under the control of FLAGS,
688 in the form `class foo'. */
691 dump_aggr_type (cxx_pretty_printer
*pp
, tree t
, int flags
)
694 const char *variety
= class_key_or_enum_as_string (t
);
698 pp_cxx_cv_qualifier_seq (pp
, t
);
700 if (flags
& TFF_CLASS_KEY_OR_ENUM
)
701 pp_cxx_ws_string (pp
, variety
);
703 name
= TYPE_NAME (t
);
707 typdef
= (!DECL_ARTIFICIAL (name
)
708 /* An alias specialization is not considered to be a
710 && !alias_template_specialization_p (t
));
713 && ((flags
& TFF_CHASE_TYPEDEF
)
714 || (!flag_pretty_templates
&& DECL_LANG_SPECIFIC (name
)
715 && DECL_TEMPLATE_INFO (name
))))
716 || DECL_SELF_REFERENCE_P (name
))
718 t
= TYPE_MAIN_VARIANT (t
);
719 name
= TYPE_NAME (t
);
723 tmplate
= !typdef
&& TREE_CODE (t
) != ENUMERAL_TYPE
724 && TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_TEMPLATE_INFO (t
)
725 && (TREE_CODE (CLASSTYPE_TI_TEMPLATE (t
)) != TEMPLATE_DECL
726 || PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t
)));
728 if (! (flags
& TFF_UNQUALIFIED_NAME
))
729 dump_scope (pp
, CP_DECL_CONTEXT (name
), flags
| TFF_SCOPE
);
730 flags
&= ~TFF_UNQUALIFIED_NAME
;
733 /* Because the template names are mangled, we have to locate
734 the most general template, and use that name. */
735 tree tpl
= TYPE_TI_TEMPLATE (t
);
737 while (DECL_TEMPLATE_INFO (tpl
))
738 tpl
= DECL_TI_TEMPLATE (tpl
);
741 name
= DECL_NAME (name
);
744 if (LAMBDA_TYPE_P (t
))
746 /* A lambda's "type" is essentially its signature. */
747 pp_string (pp
, M_("<lambda"));
748 if (lambda_function (t
))
750 FUNCTION_FIRST_USER_PARMTYPE (lambda_function (t
)),
754 else if (!name
|| IDENTIFIER_ANON_P (name
))
756 if (flags
& TFF_CLASS_KEY_OR_ENUM
)
757 pp_string (pp
, M_("<unnamed>"));
759 pp_printf (pp
, M_("<unnamed %s>"), variety
);
762 pp_cxx_tree_identifier (pp
, name
);
765 dump_template_parms (pp
, TYPE_TEMPLATE_INFO (t
),
766 !CLASSTYPE_USE_TEMPLATE (t
),
767 flags
& ~TFF_TEMPLATE_HEADER
);
770 /* Dump into the obstack the initial part of the output for a given type.
771 This is necessary when dealing with things like functions returning
774 return type of `int (* fee ())()': pointer -> function -> int. Both
775 pointer (and reference and offset) and function (and member) types must
776 deal with prefix and suffix.
778 Arrays must also do this for DECL nodes, like int a[], and for things like
782 dump_type_prefix (cxx_pretty_printer
*pp
, tree t
, int flags
)
784 if (TYPE_PTRMEMFUNC_P (t
))
786 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
790 switch (TREE_CODE (t
))
795 tree sub
= TREE_TYPE (t
);
797 dump_type_prefix (pp
, sub
, flags
);
798 if (TREE_CODE (sub
) == ARRAY_TYPE
799 || TREE_CODE (sub
) == FUNCTION_TYPE
)
801 pp_cxx_whitespace (pp
);
802 pp_cxx_left_paren (pp
);
803 pp_c_attributes_display (pp
, TYPE_ATTRIBUTES (sub
));
807 else if (TYPE_REF_P (t
))
809 if (TYPE_REF_IS_RVALUE (t
))
810 pp_ampersand_ampersand (pp
);
814 pp
->padding
= pp_before
;
815 pp_cxx_cv_qualifier_seq (pp
, t
);
821 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
822 if (TREE_CODE (t
) == OFFSET_TYPE
) /* pmfs deal with this in d_t_p */
825 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
826 pp_cxx_left_paren (pp
);
827 dump_type (pp
, TYPE_OFFSET_BASETYPE (t
), flags
);
828 pp_cxx_colon_colon (pp
);
831 pp_cxx_cv_qualifier_seq (pp
, t
);
832 pp
->padding
= pp_before
;
835 /* This can be reached without a pointer when dealing with
836 templates, e.g. std::is_function. */
838 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
842 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
844 pp_cxx_left_paren (pp
);
845 dump_aggr_type (pp
, TYPE_METHOD_BASETYPE (t
), flags
);
846 pp_cxx_colon_colon (pp
);
850 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
854 case IDENTIFIER_NODE
:
859 case TEMPLATE_TYPE_PARM
:
860 case TEMPLATE_TEMPLATE_PARM
:
861 case BOUND_TEMPLATE_TEMPLATE_PARM
:
872 case UNDERLYING_TYPE
:
874 case TYPE_PACK_EXPANSION
:
875 case FIXED_POINT_TYPE
:
877 dump_type (pp
, t
, flags
);
878 pp
->padding
= pp_before
;
882 pp_unsupported_tree (pp
, t
);
885 pp_string (pp
, M_("<typeprefixerror>"));
890 /* Dump the suffix of type T, under control of FLAGS. This is the part
891 which appears after the identifier (or function parms). */
894 dump_type_suffix (cxx_pretty_printer
*pp
, tree t
, int flags
)
896 if (TYPE_PTRMEMFUNC_P (t
))
897 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
899 switch (TREE_CODE (t
))
904 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
905 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
906 pp_cxx_right_paren (pp
);
907 if (TREE_CODE (t
) == POINTER_TYPE
)
908 flags
|= TFF_POINTER
;
909 dump_type_suffix (pp
, TREE_TYPE (t
), flags
);
916 if (TREE_CODE (t
) == METHOD_TYPE
)
917 /* Can only be reached through a pointer. */
918 pp_cxx_right_paren (pp
);
919 arg
= TYPE_ARG_TYPES (t
);
920 if (TREE_CODE (t
) == METHOD_TYPE
)
921 arg
= TREE_CHAIN (arg
);
923 /* Function pointers don't have default args. Not in standard C++,
924 anyway; they may in g++, but we'll just pretend otherwise. */
925 dump_parameters (pp
, arg
, flags
& ~TFF_FUNCTION_DEFAULT_ARGUMENTS
);
927 pp
->padding
= pp_before
;
928 pp_cxx_cv_qualifiers (pp
, type_memfn_quals (t
),
929 TREE_CODE (t
) == FUNCTION_TYPE
930 && (flags
& TFF_POINTER
));
931 dump_ref_qualifier (pp
, t
, flags
);
932 if (tx_safe_fn_type_p (t
))
933 pp_cxx_ws_string (pp
, "transaction_safe");
934 dump_exception_spec (pp
, TYPE_RAISES_EXCEPTIONS (t
), flags
);
935 dump_type_suffix (pp
, TREE_TYPE (t
), flags
);
941 pp_cxx_left_bracket (pp
);
942 if (tree dtype
= TYPE_DOMAIN (t
))
944 tree max
= TYPE_MAX_VALUE (dtype
);
945 /* Zero-length arrays have an upper bound of SIZE_MAX. */
946 if (integer_all_onesp (max
))
947 pp_character (pp
, '0');
948 else if (tree_fits_shwi_p (max
))
949 pp_wide_integer (pp
, tree_to_shwi (max
) + 1);
953 if (TREE_CODE (max
) == SAVE_EXPR
)
954 max
= TREE_OPERAND (max
, 0);
955 if (TREE_CODE (max
) == MINUS_EXPR
956 || TREE_CODE (max
) == PLUS_EXPR
)
958 max
= TREE_OPERAND (max
, 0);
959 while (CONVERT_EXPR_P (max
))
960 max
= TREE_OPERAND (max
, 0);
963 max
= fold_build2_loc (input_location
,
964 PLUS_EXPR
, dtype
, max
,
965 build_int_cst (dtype
, 1));
966 dump_expr (pp
, max
, flags
& ~TFF_EXPR_IN_PARENS
);
969 pp_cxx_right_bracket (pp
);
970 dump_type_suffix (pp
, TREE_TYPE (t
), flags
);
974 case IDENTIFIER_NODE
:
979 case TEMPLATE_TYPE_PARM
:
980 case TEMPLATE_TEMPLATE_PARM
:
981 case BOUND_TEMPLATE_TEMPLATE_PARM
:
992 case UNDERLYING_TYPE
:
994 case TYPE_PACK_EXPANSION
:
995 case FIXED_POINT_TYPE
:
1000 pp_unsupported_tree (pp
, t
);
1002 /* Don't mark it here, we should have already done in
1003 dump_type_prefix. */
1009 dump_global_iord (cxx_pretty_printer
*pp
, tree t
)
1011 const char *p
= NULL
;
1013 if (DECL_GLOBAL_CTOR_P (t
))
1014 p
= M_("(static initializers for %s)");
1015 else if (DECL_GLOBAL_DTOR_P (t
))
1016 p
= M_("(static destructors for %s)");
1020 pp_printf (pp
, p
, DECL_SOURCE_FILE (t
));
1024 dump_simple_decl (cxx_pretty_printer
*pp
, tree t
, tree type
, int flags
)
1026 if (template_parm_object_p (t
))
1027 return dump_expr (pp
, DECL_INITIAL (t
), flags
);
1029 if (flags
& TFF_DECL_SPECIFIERS
)
1031 if (VAR_P (t
) && DECL_DECLARED_CONSTEXPR_P (t
))
1033 if (DECL_LANG_SPECIFIC (t
) && DECL_DECLARED_CONCEPT_P (t
))
1034 pp_cxx_ws_string (pp
, "concept");
1036 pp_cxx_ws_string (pp
, "constexpr");
1038 dump_type_prefix (pp
, type
, flags
& ~TFF_UNQUALIFIED_NAME
);
1039 pp_maybe_space (pp
);
1041 if (! (flags
& TFF_UNQUALIFIED_NAME
)
1042 && TREE_CODE (t
) != PARM_DECL
1043 && (!DECL_INITIAL (t
)
1044 || TREE_CODE (DECL_INITIAL (t
)) != TEMPLATE_PARM_INDEX
))
1045 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1046 flags
&= ~TFF_UNQUALIFIED_NAME
;
1047 if ((flags
& TFF_DECL_SPECIFIERS
)
1048 && DECL_TEMPLATE_PARM_P (t
)
1049 && TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (t
)))
1050 pp_string (pp
, "...");
1053 if (TREE_CODE (t
) == FIELD_DECL
&& DECL_NORMAL_CAPTURE_P (t
))
1056 pp_string (pp
, IDENTIFIER_POINTER (DECL_NAME (t
)) + 2);
1057 pp_string (pp
, " capture>");
1060 dump_decl (pp
, DECL_NAME (t
), flags
);
1062 else if (DECL_DECOMPOSITION_P (t
))
1063 pp_string (pp
, M_("<structured bindings>"));
1065 pp_string (pp
, M_("<anonymous>"));
1066 if (flags
& TFF_DECL_SPECIFIERS
)
1067 dump_type_suffix (pp
, type
, flags
);
1070 /* Print an IDENTIFIER_NODE that is the name of a declaration. */
1073 dump_decl_name (cxx_pretty_printer
*pp
, tree t
, int flags
)
1075 /* These special cases are duplicated here so that other functions
1076 can feed identifiers to error and get them demangled properly. */
1077 if (IDENTIFIER_CONV_OP_P (t
))
1079 pp_cxx_ws_string (pp
, "operator");
1080 /* Not exactly IDENTIFIER_TYPE_VALUE. */
1081 dump_type (pp
, TREE_TYPE (t
), flags
);
1084 if (dguide_name_p (t
))
1086 dump_decl (pp
, CLASSTYPE_TI_TEMPLATE (TREE_TYPE (t
)),
1087 TFF_UNQUALIFIED_NAME
);
1091 const char *str
= IDENTIFIER_POINTER (t
);
1092 if (!strncmp (str
, "_ZGR", 3))
1094 pp_cxx_ws_string (pp
, "<temporary>");
1098 pp_cxx_tree_identifier (pp
, t
);
1101 /* Dump a human readable string for the decl T under control of FLAGS. */
1104 dump_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
1109 /* If doing Objective-C++, give Objective-C a chance to demangle
1110 Objective-C method names. */
1111 if (c_dialect_objc ())
1113 const char *demangled
= objc_maybe_printable_name (t
, flags
);
1116 pp_string (pp
, demangled
);
1121 switch (TREE_CODE (t
))
1124 /* Don't say 'typedef class A' */
1125 if (DECL_ARTIFICIAL (t
) && !DECL_SELF_REFERENCE_P (t
))
1127 if ((flags
& TFF_DECL_SPECIFIERS
)
1128 && TREE_CODE (TREE_TYPE (t
)) == TEMPLATE_TYPE_PARM
)
1130 /* Say `class T' not just `T'. */
1131 pp_cxx_ws_string (pp
, "class");
1133 /* Emit the `...' for a parameter pack. */
1134 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t
)))
1135 pp_cxx_ws_string (pp
, "...");
1138 dump_type (pp
, TREE_TYPE (t
), flags
);
1141 if (TYPE_DECL_ALIAS_P (t
)
1142 && (flags
& TFF_DECL_SPECIFIERS
1143 || flags
& TFF_CLASS_KEY_OR_ENUM
))
1145 pp_cxx_ws_string (pp
, "using");
1146 dump_decl (pp
, DECL_NAME (t
), flags
);
1147 pp_cxx_whitespace (pp
);
1148 pp_cxx_ws_string (pp
, "=");
1149 pp_cxx_whitespace (pp
);
1150 dump_type (pp
, (DECL_ORIGINAL_TYPE (t
)
1151 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
)),
1155 if ((flags
& TFF_DECL_SPECIFIERS
)
1156 && !DECL_SELF_REFERENCE_P (t
))
1157 pp_cxx_ws_string (pp
, "typedef");
1158 dump_simple_decl (pp
, t
, DECL_ORIGINAL_TYPE (t
)
1159 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
),
1164 if (DECL_NAME (t
) && VTABLE_NAME_P (DECL_NAME (t
)))
1166 pp_string (pp
, M_("vtable for "));
1167 gcc_assert (TYPE_P (DECL_CONTEXT (t
)));
1168 dump_type (pp
, DECL_CONTEXT (t
), flags
);
1174 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1176 /* Handle variable template specializations. */
1178 && DECL_LANG_SPECIFIC (t
)
1179 && DECL_TEMPLATE_INFO (t
)
1180 && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t
)))
1182 pp_cxx_begin_template_argument_list (pp
);
1183 tree args
= INNERMOST_TEMPLATE_ARGS (DECL_TI_ARGS (t
));
1184 dump_template_argument_list (pp
, args
, flags
);
1185 pp_cxx_end_template_argument_list (pp
);
1190 pp_string (pp
, M_("<return value> "));
1191 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1194 case NAMESPACE_DECL
:
1195 if (flags
& TFF_DECL_SPECIFIERS
)
1196 pp
->declaration (t
);
1199 if (! (flags
& TFF_UNQUALIFIED_NAME
))
1200 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1201 flags
&= ~TFF_UNQUALIFIED_NAME
;
1202 if (DECL_NAME (t
) == NULL_TREE
)
1204 if (!(pp
->flags
& pp_c_flag_gnu_v3
))
1205 pp_cxx_ws_string (pp
, M_("{anonymous}"));
1207 pp_cxx_ws_string (pp
, M_("(anonymous namespace)"));
1210 pp_cxx_tree_identifier (pp
, DECL_NAME (t
));
1215 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
1216 pp_cxx_colon_colon (pp
);
1217 dump_decl (pp
, TREE_OPERAND (t
, 1), TFF_UNQUALIFIED_NAME
);
1221 dump_decl (pp
, TREE_OPERAND (t
, 0), flags
);
1222 pp_cxx_left_bracket (pp
);
1223 dump_decl (pp
, TREE_OPERAND (t
, 1), flags
);
1224 pp_cxx_right_bracket (pp
);
1227 /* So that we can do dump_decl on an aggr type. */
1231 dump_type (pp
, t
, flags
);
1235 /* This is a pseudo destructor call which has not been folded into
1236 a PSEUDO_DTOR_EXPR yet. */
1237 pp_cxx_complement (pp
);
1238 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
1245 case IDENTIFIER_NODE
:
1246 dump_decl_name (pp
, t
, flags
);
1250 if (!OVL_SINGLE_P (t
))
1252 tree ctx
= ovl_scope (t
);
1253 if (ctx
!= global_namespace
)
1256 dump_type (pp
, ctx
, flags
);
1258 dump_decl (pp
, ctx
, flags
);
1259 pp_cxx_colon_colon (pp
);
1261 dump_decl (pp
, OVL_NAME (t
), flags
);
1265 /* If there's only one function, just treat it like an ordinary
1271 if (! DECL_LANG_SPECIFIC (t
))
1273 if (DECL_ABSTRACT_ORIGIN (t
)
1274 && DECL_ABSTRACT_ORIGIN (t
) != t
)
1275 dump_decl (pp
, DECL_ABSTRACT_ORIGIN (t
), flags
);
1277 dump_function_name (pp
, t
, flags
);
1279 else if (DECL_GLOBAL_CTOR_P (t
) || DECL_GLOBAL_DTOR_P (t
))
1280 dump_global_iord (pp
, t
);
1282 dump_function_decl (pp
, t
, flags
);
1286 dump_template_decl (pp
, t
, flags
);
1290 pp_cxx_ws_string (pp
, "concept");
1291 dump_decl_name (pp
, DECL_NAME (t
), flags
);
1295 pp_string (pp
, "<wildcard>");
1298 case TEMPLATE_ID_EXPR
:
1300 tree name
= TREE_OPERAND (t
, 0);
1301 tree args
= TREE_OPERAND (t
, 1);
1303 if (!identifier_p (name
))
1304 name
= OVL_NAME (name
);
1305 dump_decl (pp
, name
, flags
);
1306 pp_cxx_begin_template_argument_list (pp
);
1307 if (args
== error_mark_node
)
1308 pp_string (pp
, M_("<template arguments error>"));
1310 dump_template_argument_list
1311 (pp
, args
, flags
|TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS
);
1312 pp_cxx_end_template_argument_list (pp
);
1317 pp_cxx_tree_identifier (pp
, DECL_NAME (t
));
1321 if ((TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == ENUMERAL_TYPE
)
1322 || (DECL_INITIAL (t
) &&
1323 TREE_CODE (DECL_INITIAL (t
)) == TEMPLATE_PARM_INDEX
))
1324 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1325 else if (DECL_NAME (t
))
1326 dump_decl (pp
, DECL_NAME (t
), flags
);
1327 else if (DECL_INITIAL (t
))
1328 dump_expr (pp
, DECL_INITIAL (t
), flags
| TFF_EXPR_IN_PARENS
);
1330 pp_string (pp
, M_("<enumerator>"));
1335 pp_cxx_ws_string (pp
, "using");
1336 tree scope
= USING_DECL_SCOPE (t
);
1337 bool variadic
= false;
1338 if (PACK_EXPANSION_P (scope
))
1340 scope
= PACK_EXPANSION_PATTERN (scope
);
1343 dump_type (pp
, scope
, flags
);
1344 pp_cxx_colon_colon (pp
);
1345 dump_decl (pp
, DECL_NAME (t
), flags
);
1347 pp_cxx_ws_string (pp
, "...");
1352 pp
->declaration (t
);
1356 dump_decl (pp
, BASELINK_FUNCTIONS (t
), flags
);
1359 case NON_DEPENDENT_EXPR
:
1360 dump_expr (pp
, t
, flags
);
1363 case TEMPLATE_TYPE_PARM
:
1364 if (flags
& TFF_DECL_SPECIFIERS
)
1365 pp
->declaration (t
);
1370 case UNBOUND_CLASS_TEMPLATE
:
1371 case TYPE_PACK_EXPANSION
:
1373 dump_type (pp
, t
, flags
);
1377 pp_unsupported_tree (pp
, t
);
1381 pp_string (pp
, M_("<declaration error>"));
1386 /* Dump a template declaration T under control of FLAGS. This means the
1387 'template <...> leaders plus the 'class X' or 'void fn(...)' part. */
1390 dump_template_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
1392 tree orig_parms
= DECL_TEMPLATE_PARMS (t
);
1396 if (flags
& TFF_TEMPLATE_HEADER
)
1398 for (parms
= orig_parms
= nreverse (orig_parms
);
1400 parms
= TREE_CHAIN (parms
))
1402 tree inner_parms
= INNERMOST_TEMPLATE_PARMS (parms
);
1403 int len
= TREE_VEC_LENGTH (inner_parms
);
1407 /* Skip over the dummy template levels of a template template
1409 gcc_assert (TREE_CODE (TREE_TYPE (t
)) == TEMPLATE_TEMPLATE_PARM
);
1413 pp_cxx_ws_string (pp
, "template");
1414 pp_cxx_begin_template_argument_list (pp
);
1416 /* If we've shown the template prefix, we'd better show the
1417 parameters' and decl's type too. */
1418 flags
|= TFF_DECL_SPECIFIERS
;
1420 for (i
= 0; i
< len
; i
++)
1423 pp_separate_with_comma (pp
);
1424 dump_template_parameter (pp
, TREE_VEC_ELT (inner_parms
, i
),
1427 pp_cxx_end_template_argument_list (pp
);
1428 pp_cxx_whitespace (pp
);
1430 nreverse(orig_parms
);
1432 if (DECL_TEMPLATE_TEMPLATE_PARM_P (t
))
1434 /* Say `template<arg> class TT' not just `template<arg> TT'. */
1435 pp_cxx_ws_string (pp
, "class");
1437 /* If this is a parameter pack, print the ellipsis. */
1438 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t
)))
1439 pp_cxx_ws_string (pp
, "...");
1442 /* Only print the requirements if we're also printing
1443 the template header. */
1445 if (tree ci
= get_constraints (t
))
1446 if (check_constraint_info (ci
))
1447 if (tree reqs
= CI_TEMPLATE_REQS (ci
))
1449 pp_cxx_requires_clause (pp
, reqs
);
1450 pp_cxx_whitespace (pp
);
1455 if (DECL_CLASS_TEMPLATE_P (t
))
1456 dump_type (pp
, TREE_TYPE (t
),
1457 ((flags
& ~TFF_CLASS_KEY_OR_ENUM
) | TFF_TEMPLATE_NAME
1458 | (flags
& TFF_DECL_SPECIFIERS
? TFF_CLASS_KEY_OR_ENUM
: 0)));
1459 else if (DECL_TEMPLATE_RESULT (t
)
1460 && (VAR_P (DECL_TEMPLATE_RESULT (t
))
1461 /* Alias template. */
1462 || DECL_TYPE_TEMPLATE_P (t
)
1463 /* Concept definition. &*/
1464 || TREE_CODE (DECL_TEMPLATE_RESULT (t
)) == CONCEPT_DECL
))
1465 dump_decl (pp
, DECL_TEMPLATE_RESULT (t
), flags
| TFF_TEMPLATE_NAME
);
1468 gcc_assert (TREE_TYPE (t
));
1469 switch (NEXT_CODE (t
))
1473 dump_function_decl (pp
, t
, flags
| TFF_TEMPLATE_NAME
);
1476 /* This case can occur with some invalid code. */
1477 dump_type (pp
, TREE_TYPE (t
),
1478 (flags
& ~TFF_CLASS_KEY_OR_ENUM
) | TFF_TEMPLATE_NAME
1479 | (flags
& TFF_DECL_SPECIFIERS
1480 ? TFF_CLASS_KEY_OR_ENUM
: 0));
1485 /* find_typenames looks through the type of the function template T
1486 and returns a vec containing any typedefs, decltypes or TYPENAME_TYPEs
1489 struct find_typenames_t
1491 hash_set
<tree
> *p_set
;
1492 vec
<tree
, va_gc
> *typenames
;
1496 find_typenames_r (tree
*tp
, int *walk_subtrees
, void *data
)
1498 struct find_typenames_t
*d
= (struct find_typenames_t
*)data
;
1499 tree mv
= NULL_TREE
;
1501 if (TYPE_P (*tp
) && is_typedef_decl (TYPE_NAME (*tp
)))
1502 /* Add the type of the typedef without any additional cv-quals. */
1503 mv
= TREE_TYPE (TYPE_NAME (*tp
));
1504 else if (TREE_CODE (*tp
) == TYPENAME_TYPE
1505 || TREE_CODE (*tp
) == DECLTYPE_TYPE
)
1506 /* Add the typename without any cv-qualifiers. */
1507 mv
= TYPE_MAIN_VARIANT (*tp
);
1509 if (PACK_EXPANSION_P (*tp
))
1511 /* Don't mess with parameter packs since we don't remember
1512 the pack expansion context for a particular typename. */
1513 *walk_subtrees
= false;
1517 if (mv
&& (mv
== *tp
|| !d
->p_set
->add (mv
)))
1518 vec_safe_push (d
->typenames
, mv
);
1520 /* Search into class template arguments, which cp_walk_subtrees
1522 if (CLASS_TYPE_P (*tp
) && CLASSTYPE_TEMPLATE_INFO (*tp
))
1523 cp_walk_tree (&CLASSTYPE_TI_ARGS (*tp
), find_typenames_r
,
1529 static vec
<tree
, va_gc
> *
1530 find_typenames (tree t
)
1532 struct find_typenames_t ft
;
1533 ft
.p_set
= new hash_set
<tree
>;
1534 ft
.typenames
= NULL
;
1535 cp_walk_tree (&TREE_TYPE (DECL_TEMPLATE_RESULT (t
)),
1536 find_typenames_r
, &ft
, ft
.p_set
);
1538 return ft
.typenames
;
1541 /* Output the "[with ...]" clause for a template instantiation T iff
1542 TEMPLATE_PARMS, TEMPLATE_ARGS and FLAGS are suitable. T may be NULL if
1543 formatting a deduction/substitution diagnostic rather than an
1547 dump_substitution (cxx_pretty_printer
*pp
,
1548 tree t
, tree template_parms
, tree template_args
,
1551 if (template_parms
!= NULL_TREE
&& template_args
!= NULL_TREE
1552 && !(flags
& TFF_NO_TEMPLATE_BINDINGS
))
1554 vec
<tree
, va_gc
> *typenames
= t
? find_typenames (t
) : NULL
;
1555 pp_cxx_whitespace (pp
);
1556 pp_cxx_left_bracket (pp
);
1557 pp
->translate_string ("with");
1558 pp_cxx_whitespace (pp
);
1559 dump_template_bindings (pp
, template_parms
, template_args
, typenames
);
1560 pp_cxx_right_bracket (pp
);
1564 /* Dump the lambda function FN including its 'mutable' qualifier and any
1565 template bindings. */
1568 dump_lambda_function (cxx_pretty_printer
*pp
,
1569 tree fn
, tree template_parms
, tree template_args
,
1572 /* A lambda's signature is essentially its "type". */
1573 dump_type (pp
, DECL_CONTEXT (fn
), flags
);
1574 if (!(TYPE_QUALS (class_of_this_parm (TREE_TYPE (fn
))) & TYPE_QUAL_CONST
))
1576 pp
->padding
= pp_before
;
1577 pp_c_ws_string (pp
, "mutable");
1579 dump_substitution (pp
, fn
, template_parms
, template_args
, flags
);
1582 /* Pretty print a function decl. There are several ways we want to print a
1583 function declaration. The TFF_ bits in FLAGS tells us how to behave.
1584 As error can only apply the '#' flag once to give 0 and 1 for V, there
1585 is %D which doesn't print the throw specs, and %F which does. */
1588 dump_function_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
1592 tree cname
= NULL_TREE
;
1593 tree template_args
= NULL_TREE
;
1594 tree template_parms
= NULL_TREE
;
1595 int show_return
= flags
& TFF_RETURN_TYPE
|| flags
& TFF_DECL_SPECIFIERS
;
1596 int do_outer_scope
= ! (flags
& TFF_UNQUALIFIED_NAME
);
1599 tree ret
= NULL_TREE
;
1601 flags
&= ~(TFF_UNQUALIFIED_NAME
| TFF_TEMPLATE_NAME
);
1602 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1603 t
= DECL_TEMPLATE_RESULT (t
);
1605 /* Save the exceptions, in case t is a specialization and we are
1606 emitting an error about incompatible specifications. */
1607 exceptions
= TYPE_RAISES_EXCEPTIONS (TREE_TYPE (t
));
1609 /* Likewise for the constexpr specifier, in case t is a specialization. */
1610 constexpr_p
= DECL_DECLARED_CONSTEXPR_P (t
);
1612 /* Pretty print template instantiations only. */
1613 if (DECL_USE_TEMPLATE (t
) && DECL_TEMPLATE_INFO (t
)
1614 && !(flags
& TFF_NO_TEMPLATE_BINDINGS
)
1615 && flag_pretty_templates
)
1619 template_args
= DECL_TI_ARGS (t
);
1620 tmpl
= most_general_template (t
);
1621 if (tmpl
&& TREE_CODE (tmpl
) == TEMPLATE_DECL
)
1623 template_parms
= DECL_TEMPLATE_PARMS (tmpl
);
1628 if (DECL_NAME (t
) && LAMBDA_FUNCTION_P (t
))
1629 return dump_lambda_function (pp
, t
, template_parms
, template_args
, flags
);
1631 fntype
= TREE_TYPE (t
);
1632 parmtypes
= FUNCTION_FIRST_USER_PARMTYPE (t
);
1634 if (DECL_CLASS_SCOPE_P (t
))
1635 cname
= DECL_CONTEXT (t
);
1636 /* This is for partially instantiated template methods. */
1637 else if (TREE_CODE (fntype
) == METHOD_TYPE
)
1638 cname
= TREE_TYPE (TREE_VALUE (parmtypes
));
1640 if (flags
& TFF_DECL_SPECIFIERS
)
1642 if (DECL_STATIC_FUNCTION_P (t
))
1643 pp_cxx_ws_string (pp
, "static");
1644 else if (DECL_VIRTUAL_P (t
))
1645 pp_cxx_ws_string (pp
, "virtual");
1649 if (DECL_DECLARED_CONCEPT_P (t
))
1650 pp_cxx_ws_string (pp
, "concept");
1652 pp_cxx_ws_string (pp
, "constexpr");
1656 /* Print the return type? */
1658 show_return
= (!DECL_CONV_FN_P (t
) && !DECL_CONSTRUCTOR_P (t
)
1659 && !DECL_DESTRUCTOR_P (t
) && !deduction_guide_p (t
));
1662 ret
= fndecl_declared_return_type (t
);
1663 dump_type_prefix (pp
, ret
, flags
);
1666 /* Print the function name. */
1667 if (!do_outer_scope
)
1671 dump_type (pp
, cname
, flags
);
1672 pp_cxx_colon_colon (pp
);
1675 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1677 dump_function_name (pp
, t
, flags
);
1679 if (!(flags
& TFF_NO_FUNCTION_ARGUMENTS
))
1681 dump_parameters (pp
, parmtypes
, flags
);
1683 if (TREE_CODE (fntype
) == METHOD_TYPE
)
1685 pp
->padding
= pp_before
;
1686 pp_cxx_cv_qualifier_seq (pp
, class_of_this_parm (fntype
));
1687 dump_ref_qualifier (pp
, fntype
, flags
);
1690 if (tx_safe_fn_type_p (fntype
))
1692 pp
->padding
= pp_before
;
1693 pp_cxx_ws_string (pp
, "transaction_safe");
1696 if (flags
& TFF_EXCEPTION_SPECIFICATION
)
1698 pp
->padding
= pp_before
;
1699 dump_exception_spec (pp
, exceptions
, flags
);
1703 dump_type_suffix (pp
, ret
, flags
);
1704 else if (deduction_guide_p (t
))
1706 pp_cxx_ws_string (pp
, "->");
1707 dump_type (pp
, TREE_TYPE (TREE_TYPE (t
)), flags
);
1711 if (tree ci
= get_constraints (t
))
1712 if (tree reqs
= CI_DECLARATOR_REQS (ci
))
1713 pp_cxx_requires_clause (pp
, reqs
);
1715 dump_substitution (pp
, t
, template_parms
, template_args
, flags
);
1717 if (tree base
= DECL_INHERITED_CTOR_BASE (t
))
1719 pp_cxx_ws_string (pp
, "[inherited from");
1720 dump_type (pp
, base
, TFF_PLAIN_IDENTIFIER
);
1721 pp_character (pp
, ']');
1724 else if (template_args
)
1726 bool need_comma
= false;
1728 pp_cxx_begin_template_argument_list (pp
);
1729 template_args
= INNERMOST_TEMPLATE_ARGS (template_args
);
1730 for (i
= 0; i
< TREE_VEC_LENGTH (template_args
); ++i
)
1732 tree arg
= TREE_VEC_ELT (template_args
, i
);
1734 pp_separate_with_comma (pp
);
1735 if (ARGUMENT_PACK_P (arg
))
1736 pp_cxx_left_brace (pp
);
1737 dump_template_argument (pp
, arg
, TFF_PLAIN_IDENTIFIER
);
1738 if (ARGUMENT_PACK_P (arg
))
1739 pp_cxx_right_brace (pp
);
1742 pp_cxx_end_template_argument_list (pp
);
1746 /* Print a parameter list. If this is for a member function, the
1747 member object ptr (and any other hidden args) should have
1748 already been removed. */
1751 dump_parameters (cxx_pretty_printer
*pp
, tree parmtypes
, int flags
)
1754 flags
&= ~TFF_SCOPE
;
1755 pp_cxx_left_paren (pp
);
1757 for (first
= 1; parmtypes
!= void_list_node
;
1758 parmtypes
= TREE_CHAIN (parmtypes
))
1761 pp_separate_with_comma (pp
);
1765 pp_cxx_ws_string (pp
, "...");
1769 dump_type (pp
, TREE_VALUE (parmtypes
), flags
);
1771 if ((flags
& TFF_FUNCTION_DEFAULT_ARGUMENTS
) && TREE_PURPOSE (parmtypes
))
1773 pp_cxx_whitespace (pp
);
1775 pp_cxx_whitespace (pp
);
1776 dump_expr (pp
, TREE_PURPOSE (parmtypes
), flags
| TFF_EXPR_IN_PARENS
);
1780 pp_cxx_right_paren (pp
);
1783 /* Print ref-qualifier of a FUNCTION_TYPE or METHOD_TYPE. FLAGS are ignored. */
1786 dump_ref_qualifier (cxx_pretty_printer
*pp
, tree t
, int flags ATTRIBUTE_UNUSED
)
1788 if (FUNCTION_REF_QUALIFIED (t
))
1790 pp
->padding
= pp_before
;
1791 if (FUNCTION_RVALUE_QUALIFIED (t
))
1792 pp_cxx_ws_string (pp
, "&&");
1794 pp_cxx_ws_string (pp
, "&");
1798 /* Print an exception specification. T is the exception specification. */
1801 dump_exception_spec (cxx_pretty_printer
*pp
, tree t
, int flags
)
1803 if (t
&& TREE_PURPOSE (t
))
1805 pp_cxx_ws_string (pp
, "noexcept");
1806 if (!integer_onep (TREE_PURPOSE (t
)))
1808 pp_cxx_whitespace (pp
);
1809 pp_cxx_left_paren (pp
);
1810 if (DEFERRED_NOEXCEPT_SPEC_P (t
))
1811 pp_cxx_ws_string (pp
, "<uninstantiated>");
1813 dump_expr (pp
, TREE_PURPOSE (t
), flags
);
1814 pp_cxx_right_paren (pp
);
1819 pp_cxx_ws_string (pp
, "throw");
1820 pp_cxx_whitespace (pp
);
1821 pp_cxx_left_paren (pp
);
1822 if (TREE_VALUE (t
) != NULL_TREE
)
1825 dump_type (pp
, TREE_VALUE (t
), flags
);
1829 pp_separate_with_comma (pp
);
1831 pp_cxx_right_paren (pp
);
1835 /* Handle the function name for a FUNCTION_DECL node, grokking operators
1836 and destructors properly. */
1839 dump_function_name (cxx_pretty_printer
*pp
, tree t
, int flags
)
1841 tree name
= DECL_NAME (t
);
1843 /* We can get here with a decl that was synthesized by language-
1844 independent machinery (e.g. coverage.c) in which case it won't
1845 have a lang_specific structure attached and DECL_CONSTRUCTOR_P
1846 will crash. In this case it is safe just to print out the
1848 if (!DECL_LANG_SPECIFIC (t
))
1850 pp_cxx_tree_identifier (pp
, name
);
1854 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1855 t
= DECL_TEMPLATE_RESULT (t
);
1857 /* Don't let the user see __comp_ctor et al. */
1858 if (DECL_CONSTRUCTOR_P (t
)
1859 || DECL_DESTRUCTOR_P (t
))
1861 if (LAMBDA_TYPE_P (DECL_CONTEXT (t
)))
1862 name
= get_identifier ("<lambda>");
1863 else if (TYPE_UNNAMED_P (DECL_CONTEXT (t
)))
1864 name
= get_identifier ("<constructor>");
1866 name
= constructor_name (DECL_CONTEXT (t
));
1869 if (DECL_DESTRUCTOR_P (t
))
1871 pp_cxx_complement (pp
);
1872 dump_decl (pp
, name
, TFF_PLAIN_IDENTIFIER
);
1874 else if (DECL_CONV_FN_P (t
))
1876 /* This cannot use the hack that the operator's return
1877 type is stashed off of its name because it may be
1878 used for error reporting. In the case of conflicting
1879 declarations, both will have the same name, yet
1880 the types will be different, hence the TREE_TYPE field
1881 of the first name will be clobbered by the second. */
1882 pp_cxx_ws_string (pp
, "operator");
1883 dump_type (pp
, TREE_TYPE (TREE_TYPE (t
)), flags
);
1886 dump_decl (pp
, name
, flags
);
1888 if (DECL_TEMPLATE_INFO (t
)
1889 && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t
)
1890 && (TREE_CODE (DECL_TI_TEMPLATE (t
)) != TEMPLATE_DECL
1891 || PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t
))))
1892 dump_template_parms (pp
, DECL_TEMPLATE_INFO (t
), !DECL_USE_TEMPLATE (t
),
1896 /* Dump the template parameters from the template info INFO under control of
1897 FLAGS. PRIMARY indicates whether this is a primary template decl, or
1898 specialization (partial or complete). For partial specializations we show
1899 the specialized parameter values. For a primary template we show no
1903 dump_template_parms (cxx_pretty_printer
*pp
, tree info
,
1904 int primary
, int flags
)
1906 tree args
= info
? TI_ARGS (info
) : NULL_TREE
;
1908 if (primary
&& flags
& TFF_TEMPLATE_NAME
)
1910 flags
&= ~(TFF_CLASS_KEY_OR_ENUM
| TFF_TEMPLATE_NAME
);
1911 pp_cxx_begin_template_argument_list (pp
);
1913 /* Be careful only to print things when we have them, so as not
1914 to crash producing error messages. */
1915 if (args
&& !primary
)
1918 len
= get_non_default_template_args_count (args
, flags
);
1920 args
= INNERMOST_TEMPLATE_ARGS (args
);
1921 for (ix
= 0; ix
!= len
; ix
++)
1923 tree arg
= TREE_VEC_ELT (args
, ix
);
1925 /* Only print a comma if we know there is an argument coming. In
1926 the case of an empty template argument pack, no actual
1927 argument will be printed. */
1929 && (!ARGUMENT_PACK_P (arg
)
1930 || TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg
)) > 0))
1931 pp_separate_with_comma (pp
);
1934 pp_string (pp
, M_("<template parameter error>"));
1936 dump_template_argument (pp
, arg
, flags
);
1941 tree tpl
= TI_TEMPLATE (info
);
1942 tree parms
= DECL_TEMPLATE_PARMS (tpl
);
1945 parms
= TREE_CODE (parms
) == TREE_LIST
? TREE_VALUE (parms
) : NULL_TREE
;
1946 len
= parms
? TREE_VEC_LENGTH (parms
) : 0;
1948 for (ix
= 0; ix
!= len
; ix
++)
1952 if (TREE_VEC_ELT (parms
, ix
) == error_mark_node
)
1954 pp_string (pp
, M_("<template parameter error>"));
1958 parm
= TREE_VALUE (TREE_VEC_ELT (parms
, ix
));
1961 pp_separate_with_comma (pp
);
1963 dump_decl (pp
, parm
, flags
& ~TFF_DECL_SPECIFIERS
);
1966 pp_cxx_end_template_argument_list (pp
);
1969 /* Print out the arguments of CALL_EXPR T as a parenthesized list using
1970 flags FLAGS. Skip over the first argument if SKIPFIRST is true. */
1973 dump_call_expr_args (cxx_pretty_printer
*pp
, tree t
, int flags
, bool skipfirst
)
1976 call_expr_arg_iterator iter
;
1978 pp_cxx_left_paren (pp
);
1979 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, t
)
1985 dump_expr (pp
, arg
, flags
| TFF_EXPR_IN_PARENS
);
1986 if (more_call_expr_args_p (&iter
))
1987 pp_separate_with_comma (pp
);
1990 pp_cxx_right_paren (pp
);
1993 /* Print out the arguments of AGGR_INIT_EXPR T as a parenthesized list
1994 using flags FLAGS. Skip over the first argument if SKIPFIRST is
1998 dump_aggr_init_expr_args (cxx_pretty_printer
*pp
, tree t
, int flags
,
2002 aggr_init_expr_arg_iterator iter
;
2004 pp_cxx_left_paren (pp
);
2005 FOR_EACH_AGGR_INIT_EXPR_ARG (arg
, iter
, t
)
2011 dump_expr (pp
, arg
, flags
| TFF_EXPR_IN_PARENS
);
2012 if (more_aggr_init_expr_args_p (&iter
))
2013 pp_separate_with_comma (pp
);
2016 pp_cxx_right_paren (pp
);
2019 /* Print out a list of initializers (subr of dump_expr). */
2022 dump_expr_list (cxx_pretty_printer
*pp
, tree l
, int flags
)
2026 dump_expr (pp
, TREE_VALUE (l
), flags
| TFF_EXPR_IN_PARENS
);
2029 pp_separate_with_comma (pp
);
2033 /* Print out a vector of initializers (subr of dump_expr). */
2036 dump_expr_init_vec (cxx_pretty_printer
*pp
, vec
<constructor_elt
, va_gc
> *v
,
2039 unsigned HOST_WIDE_INT idx
;
2042 FOR_EACH_CONSTRUCTOR_VALUE (v
, idx
, value
)
2044 dump_expr (pp
, value
, flags
| TFF_EXPR_IN_PARENS
);
2045 if (idx
!= v
->length () - 1)
2046 pp_separate_with_comma (pp
);
2051 /* We've gotten an indirect REFERENCE (an OBJ_TYPE_REF) to a virtual
2052 function. Resolve it to a close relative -- in the sense of static
2053 type -- variant being overridden. That is close to what was written in
2054 the source code. Subroutine of dump_expr. */
2057 resolve_virtual_fun_from_obj_type_ref (tree ref
)
2059 tree obj_type
= TREE_TYPE (OBJ_TYPE_REF_OBJECT (ref
));
2060 HOST_WIDE_INT index
= tree_to_uhwi (OBJ_TYPE_REF_TOKEN (ref
));
2061 tree fun
= BINFO_VIRTUALS (TYPE_BINFO (TREE_TYPE (obj_type
)));
2064 fun
= TREE_CHAIN (fun
);
2065 index
-= (TARGET_VTABLE_USES_DESCRIPTORS
2066 ? TARGET_VTABLE_USES_DESCRIPTORS
: 1);
2072 /* Print out an expression E under control of FLAGS. */
2075 dump_expr (cxx_pretty_printer
*pp
, tree t
, int flags
)
2082 if (STATEMENT_CLASS_P (t
))
2084 pp_cxx_ws_string (pp
, M_("<statement>"));
2088 switch (TREE_CODE (t
))
2096 case NAMESPACE_DECL
:
2101 case IDENTIFIER_NODE
:
2102 dump_decl (pp
, t
, ((flags
& ~(TFF_DECL_SPECIFIERS
|TFF_RETURN_TYPE
2103 |TFF_TEMPLATE_HEADER
))
2104 | TFF_NO_TEMPLATE_BINDINGS
2105 | TFF_NO_FUNCTION_ARGUMENTS
));
2109 if (SSA_NAME_VAR (t
)
2110 && !DECL_ARTIFICIAL (SSA_NAME_VAR (t
)))
2111 dump_expr (pp
, SSA_NAME_VAR (t
), flags
);
2113 pp_cxx_ws_string (pp
, M_("<unknown>"));
2124 case USERDEF_LITERAL
:
2125 pp_cxx_userdef_literal (pp
, t
);
2129 /* While waiting for caret diagnostics, avoid printing
2130 __cxa_allocate_exception, __cxa_throw, and the like. */
2131 pp_cxx_ws_string (pp
, M_("<throw-expression>"));
2136 dump_type (pp
, PTRMEM_CST_CLASS (t
), flags
);
2137 pp_cxx_colon_colon (pp
);
2138 pp_cxx_tree_identifier (pp
, DECL_NAME (PTRMEM_CST_MEMBER (t
)));
2142 pp_cxx_left_paren (pp
);
2143 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2144 pp_separate_with_comma (pp
);
2145 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2146 pp_cxx_right_paren (pp
);
2151 pp_cxx_left_paren (pp
);
2152 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2153 pp_string (pp
, " ? ");
2154 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2155 pp_string (pp
, " : ");
2156 dump_expr (pp
, TREE_OPERAND (t
, 2), flags
| TFF_EXPR_IN_PARENS
);
2157 pp_cxx_right_paren (pp
);
2161 if (TREE_HAS_CONSTRUCTOR (t
))
2163 pp_cxx_ws_string (pp
, "new");
2164 pp_cxx_whitespace (pp
);
2165 dump_type (pp
, TREE_TYPE (TREE_TYPE (t
)), flags
);
2168 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2171 case AGGR_INIT_EXPR
:
2173 tree fn
= NULL_TREE
;
2175 if (TREE_CODE (AGGR_INIT_EXPR_FN (t
)) == ADDR_EXPR
)
2176 fn
= TREE_OPERAND (AGGR_INIT_EXPR_FN (t
), 0);
2178 if (fn
&& TREE_CODE (fn
) == FUNCTION_DECL
)
2180 if (DECL_CONSTRUCTOR_P (fn
))
2181 dump_type (pp
, DECL_CONTEXT (fn
), flags
);
2183 dump_decl (pp
, fn
, 0);
2186 dump_expr (pp
, AGGR_INIT_EXPR_FN (t
), 0);
2188 dump_aggr_init_expr_args (pp
, t
, flags
, true);
2193 tree fn
= CALL_EXPR_FN (t
);
2194 bool skipfirst
= false;
2196 /* Deal with internal functions. */
2197 if (fn
== NULL_TREE
)
2199 pp_string (pp
, internal_fn_name (CALL_EXPR_IFN (t
)));
2200 dump_call_expr_args (pp
, t
, flags
, skipfirst
);
2204 if (TREE_CODE (fn
) == ADDR_EXPR
)
2205 fn
= TREE_OPERAND (fn
, 0);
2207 /* Nobody is interested in seeing the guts of vcalls. */
2208 if (TREE_CODE (fn
) == OBJ_TYPE_REF
)
2209 fn
= resolve_virtual_fun_from_obj_type_ref (fn
);
2211 if (TREE_TYPE (fn
) != NULL_TREE
2212 && NEXT_CODE (fn
) == METHOD_TYPE
2213 && call_expr_nargs (t
))
2215 tree ob
= CALL_EXPR_ARG (t
, 0);
2216 if (TREE_CODE (ob
) == ADDR_EXPR
)
2218 dump_expr (pp
, TREE_OPERAND (ob
, 0),
2219 flags
| TFF_EXPR_IN_PARENS
);
2222 else if (!is_this_parameter (ob
))
2224 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2229 if (flag_sanitize
& SANITIZE_UNDEFINED
2230 && is_ubsan_builtin_p (fn
))
2232 pp_string (cxx_pp
, M_("<ubsan routine call>"));
2235 dump_expr (pp
, fn
, flags
| TFF_EXPR_IN_PARENS
);
2236 dump_call_expr_args (pp
, t
, flags
, skipfirst
);
2241 /* Note that this only works for G++ target exprs. If somebody
2242 builds a general TARGET_EXPR, there's no way to represent that
2243 it initializes anything other that the parameter slot for the
2244 default argument. Note we may have cleared out the first
2245 operand in expand_expr, so don't go killing ourselves. */
2246 if (TREE_OPERAND (t
, 1))
2247 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2250 case POINTER_PLUS_EXPR
:
2251 dump_binary_op (pp
, "+", t
, flags
);
2254 case POINTER_DIFF_EXPR
:
2255 dump_binary_op (pp
, "-", t
, flags
);
2260 dump_binary_op (pp
, OVL_OP_INFO (true, NOP_EXPR
)->name
, t
, flags
);
2266 case TRUNC_DIV_EXPR
:
2267 case TRUNC_MOD_EXPR
:
2275 case TRUTH_ANDIF_EXPR
:
2276 case TRUTH_ORIF_EXPR
:
2283 case EXACT_DIV_EXPR
:
2284 dump_binary_op (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
, t
, flags
);
2288 case FLOOR_DIV_EXPR
:
2289 case ROUND_DIV_EXPR
:
2291 dump_binary_op (pp
, "/", t
, flags
);
2295 case FLOOR_MOD_EXPR
:
2296 case ROUND_MOD_EXPR
:
2297 dump_binary_op (pp
, "%", t
, flags
);
2302 tree ob
= TREE_OPERAND (t
, 0);
2303 if (INDIRECT_REF_P (ob
))
2305 ob
= TREE_OPERAND (ob
, 0);
2306 if (!is_this_parameter (ob
))
2308 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2309 if (TYPE_REF_P (TREE_TYPE (ob
)))
2317 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2318 if (TREE_CODE (ob
) != ARROW_EXPR
)
2321 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
& ~TFF_EXPR_IN_PARENS
);
2326 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2327 pp_cxx_left_bracket (pp
);
2328 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2329 pp_cxx_right_bracket (pp
);
2332 case UNARY_PLUS_EXPR
:
2333 dump_unary_op (pp
, "+", t
, flags
);
2337 if (TREE_CODE (TREE_OPERAND (t
, 0)) == FUNCTION_DECL
2338 || TREE_CODE (TREE_OPERAND (t
, 0)) == STRING_CST
2339 /* An ADDR_EXPR can have reference type. In that case, we
2340 shouldn't print the `&' doing so indicates to the user
2341 that the expression has pointer type. */
2343 && TYPE_REF_P (TREE_TYPE (t
))))
2344 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2345 else if (TREE_CODE (TREE_OPERAND (t
, 0)) == LABEL_DECL
)
2346 dump_unary_op (pp
, "&&", t
, flags
);
2348 dump_unary_op (pp
, "&", t
, flags
);
2352 if (TREE_HAS_CONSTRUCTOR (t
))
2354 t
= TREE_OPERAND (t
, 0);
2355 gcc_assert (TREE_CODE (t
) == CALL_EXPR
);
2356 dump_expr (pp
, CALL_EXPR_FN (t
), flags
| TFF_EXPR_IN_PARENS
);
2357 dump_call_expr_args (pp
, t
, flags
, true);
2361 if (TREE_OPERAND (t
,0) != NULL_TREE
2362 && TREE_TYPE (TREE_OPERAND (t
, 0))
2363 && NEXT_CODE (TREE_OPERAND (t
, 0)) == REFERENCE_TYPE
)
2364 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2366 dump_unary_op (pp
, "*", t
, flags
);
2371 if (TREE_CODE (TREE_OPERAND (t
, 0)) == ADDR_EXPR
2372 && integer_zerop (TREE_OPERAND (t
, 1)))
2373 dump_expr (pp
, TREE_OPERAND (TREE_OPERAND (t
, 0), 0), flags
);
2377 if (!integer_zerop (TREE_OPERAND (t
, 1)))
2379 pp_cxx_left_paren (pp
);
2380 if (!integer_onep (TYPE_SIZE_UNIT
2381 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (t
, 0))))))
2383 pp_cxx_left_paren (pp
);
2384 dump_type (pp
, ptr_type_node
, flags
);
2385 pp_cxx_right_paren (pp
);
2388 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2389 if (!integer_zerop (TREE_OPERAND (t
, 1)))
2391 pp_cxx_ws_string (pp
, "+");
2392 dump_expr (pp
, fold_convert (ssizetype
, TREE_OPERAND (t
, 1)),
2394 pp_cxx_right_paren (pp
);
2401 case TRUTH_NOT_EXPR
:
2402 case PREDECREMENT_EXPR
:
2403 case PREINCREMENT_EXPR
:
2404 dump_unary_op (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
, t
, flags
);
2407 case POSTDECREMENT_EXPR
:
2408 case POSTINCREMENT_EXPR
:
2409 pp_cxx_left_paren (pp
);
2410 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2411 pp_cxx_ws_string (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
);
2412 pp_cxx_right_paren (pp
);
2415 case NON_LVALUE_EXPR
:
2416 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
2417 should be another level of INDIRECT_REF so that I don't have to do
2419 if (TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == POINTER_TYPE
)
2421 tree next
= TREE_TYPE (TREE_TYPE (t
));
2423 while (TYPE_PTR_P (next
))
2424 next
= TREE_TYPE (next
);
2426 if (TREE_CODE (next
) == FUNCTION_TYPE
)
2428 if (flags
& TFF_EXPR_IN_PARENS
)
2429 pp_cxx_left_paren (pp
);
2431 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2432 if (flags
& TFF_EXPR_IN_PARENS
)
2433 pp_cxx_right_paren (pp
);
2436 /* Else fall through. */
2438 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2442 case IMPLICIT_CONV_EXPR
:
2443 case VIEW_CONVERT_EXPR
:
2445 tree op
= TREE_OPERAND (t
, 0);
2446 tree ttype
= TREE_TYPE (t
);
2447 tree optype
= TREE_TYPE (op
);
2449 if (TREE_CODE (ttype
) != TREE_CODE (optype
)
2450 && INDIRECT_TYPE_P (ttype
)
2451 && INDIRECT_TYPE_P (optype
)
2452 && same_type_p (TREE_TYPE (optype
),
2455 if (TYPE_REF_P (ttype
))
2458 if (TREE_CODE (op
) == ADDR_EXPR
)
2459 dump_expr (pp
, TREE_OPERAND (op
, 0), flags
);
2461 dump_unary_op (pp
, "*", t
, flags
);
2464 dump_unary_op (pp
, "&", t
, flags
);
2466 else if (!same_type_p (TREE_TYPE (op
), TREE_TYPE (t
)))
2468 /* It is a cast, but we cannot tell whether it is a
2469 reinterpret or static cast. Use the C style notation. */
2470 if (flags
& TFF_EXPR_IN_PARENS
)
2471 pp_cxx_left_paren (pp
);
2472 pp_cxx_left_paren (pp
);
2473 dump_type (pp
, TREE_TYPE (t
), flags
);
2474 pp_cxx_right_paren (pp
);
2475 dump_expr (pp
, op
, flags
| TFF_EXPR_IN_PARENS
);
2476 if (flags
& TFF_EXPR_IN_PARENS
)
2477 pp_cxx_right_paren (pp
);
2480 dump_expr (pp
, op
, flags
);
2485 if (TREE_TYPE (t
) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t
)))
2487 tree idx
= build_ptrmemfunc_access_expr (t
, pfn_identifier
);
2489 if (integer_zerop (idx
))
2491 /* A NULL pointer-to-member constant. */
2492 pp_cxx_left_paren (pp
);
2493 pp_cxx_left_paren (pp
);
2494 dump_type (pp
, TREE_TYPE (t
), flags
);
2495 pp_cxx_right_paren (pp
);
2496 pp_character (pp
, '0');
2497 pp_cxx_right_paren (pp
);
2500 else if (tree_fits_shwi_p (idx
))
2503 unsigned HOST_WIDE_INT n
;
2505 t
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t
)));
2506 t
= TYPE_METHOD_BASETYPE (t
);
2507 virtuals
= BINFO_VIRTUALS (TYPE_BINFO (TYPE_MAIN_VARIANT (t
)));
2509 n
= tree_to_shwi (idx
);
2511 /* Map vtable index back one, to allow for the null pointer to
2515 while (n
> 0 && virtuals
)
2518 virtuals
= TREE_CHAIN (virtuals
);
2522 dump_expr (pp
, BV_FN (virtuals
),
2523 flags
| TFF_EXPR_IN_PARENS
);
2528 if (TREE_TYPE (t
) && LAMBDA_TYPE_P (TREE_TYPE (t
)))
2529 pp_string (pp
, "<lambda closure object>");
2530 if (TREE_TYPE (t
) && EMPTY_CONSTRUCTOR_P (t
))
2532 dump_type (pp
, TREE_TYPE (t
), 0);
2533 pp_cxx_left_paren (pp
);
2534 pp_cxx_right_paren (pp
);
2538 if (!BRACE_ENCLOSED_INITIALIZER_P (t
))
2539 dump_type (pp
, TREE_TYPE (t
), 0);
2540 pp_cxx_left_brace (pp
);
2541 dump_expr_init_vec (pp
, CONSTRUCTOR_ELTS (t
), flags
);
2542 pp_cxx_right_brace (pp
);
2549 tree ob
= TREE_OPERAND (t
, 0);
2550 if (is_dummy_object (ob
))
2552 t
= TREE_OPERAND (t
, 1);
2553 if (TREE_CODE (t
) == FUNCTION_DECL
)
2555 dump_expr (pp
, t
, flags
| TFF_EXPR_IN_PARENS
);
2556 else if (BASELINK_P (t
))
2557 dump_expr (pp
, OVL_FIRST (BASELINK_FUNCTIONS (t
)),
2558 flags
| TFF_EXPR_IN_PARENS
);
2560 dump_decl (pp
, t
, flags
);
2564 if (INDIRECT_REF_P (ob
))
2566 dump_expr (pp
, TREE_OPERAND (ob
, 0), flags
| TFF_EXPR_IN_PARENS
);
2572 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2576 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2581 case TEMPLATE_PARM_INDEX
:
2582 dump_decl (pp
, TEMPLATE_PARM_DECL (t
), flags
& ~TFF_DECL_SPECIFIERS
);
2586 if (TREE_OPERAND (t
, 0) == NULL_TREE
2587 || TREE_CHAIN (TREE_OPERAND (t
, 0)))
2589 dump_type (pp
, TREE_TYPE (t
), flags
);
2590 pp_cxx_left_paren (pp
);
2591 dump_expr_list (pp
, TREE_OPERAND (t
, 0), flags
);
2592 pp_cxx_right_paren (pp
);
2596 pp_cxx_left_paren (pp
);
2597 dump_type (pp
, TREE_TYPE (t
), flags
);
2598 pp_cxx_right_paren (pp
);
2599 pp_cxx_left_paren (pp
);
2600 dump_expr_list (pp
, TREE_OPERAND (t
, 0), flags
);
2601 pp_cxx_right_paren (pp
);
2605 case STATIC_CAST_EXPR
:
2606 pp_cxx_ws_string (pp
, "static_cast");
2608 case REINTERPRET_CAST_EXPR
:
2609 pp_cxx_ws_string (pp
, "reinterpret_cast");
2611 case CONST_CAST_EXPR
:
2612 pp_cxx_ws_string (pp
, "const_cast");
2614 case DYNAMIC_CAST_EXPR
:
2615 pp_cxx_ws_string (pp
, "dynamic_cast");
2617 pp_cxx_begin_template_argument_list (pp
);
2618 dump_type (pp
, TREE_TYPE (t
), flags
);
2619 pp_cxx_end_template_argument_list (pp
);
2620 pp_cxx_left_paren (pp
);
2621 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2622 pp_cxx_right_paren (pp
);
2626 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2632 if (TREE_CODE (t
) == SIZEOF_EXPR
)
2633 pp_cxx_ws_string (pp
, "sizeof");
2636 gcc_assert (TREE_CODE (t
) == ALIGNOF_EXPR
);
2637 pp_cxx_ws_string (pp
, "__alignof__");
2639 op
= TREE_OPERAND (t
, 0);
2640 if (PACK_EXPANSION_P (op
))
2642 pp_string (pp
, "...");
2643 op
= PACK_EXPANSION_PATTERN (op
);
2645 pp_cxx_whitespace (pp
);
2646 pp_cxx_left_paren (pp
);
2647 if (TREE_CODE (t
) == SIZEOF_EXPR
&& SIZEOF_EXPR_TYPE_P (t
))
2648 dump_type (pp
, TREE_TYPE (op
), flags
);
2649 else if (TYPE_P (TREE_OPERAND (t
, 0)))
2650 dump_type (pp
, op
, flags
);
2652 dump_expr (pp
, op
, flags
);
2653 pp_cxx_right_paren (pp
);
2656 case AT_ENCODE_EXPR
:
2657 pp_cxx_ws_string (pp
, "@encode");
2658 pp_cxx_whitespace (pp
);
2659 pp_cxx_left_paren (pp
);
2660 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
2661 pp_cxx_right_paren (pp
);
2665 pp_cxx_ws_string (pp
, "noexcept");
2666 pp_cxx_whitespace (pp
);
2667 pp_cxx_left_paren (pp
);
2668 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2669 pp_cxx_right_paren (pp
);
2674 pp_cxx_ws_string (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
);
2675 pp_cxx_whitespace (pp
);
2676 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2679 case DEFERRED_PARSE
:
2680 pp_string (pp
, M_("<unparsed>"));
2683 case TRY_CATCH_EXPR
:
2684 case CLEANUP_POINT_EXPR
:
2685 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2688 case PSEUDO_DTOR_EXPR
:
2689 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2691 if (TREE_OPERAND (t
, 1))
2693 dump_type (pp
, TREE_OPERAND (t
, 1), flags
);
2694 pp_cxx_colon_colon (pp
);
2696 pp_cxx_complement (pp
);
2697 dump_type (pp
, TREE_OPERAND (t
, 2), flags
);
2700 case TEMPLATE_ID_EXPR
:
2701 dump_decl (pp
, t
, flags
);
2707 case STATEMENT_LIST
:
2708 /* We don't yet have a way of dumping statements in a
2709 human-readable format. */
2710 pp_string (pp
, "({...})");
2714 pp_string (pp
, "while (1) { ");
2715 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2716 pp_cxx_right_brace (pp
);
2720 pp_string (pp
, "if (");
2721 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2722 pp_string (pp
, ") break; ");
2726 dump_expr (pp
, BASELINK_FUNCTIONS (t
), flags
& ~TFF_EXPR_IN_PARENS
);
2729 case EMPTY_CLASS_EXPR
:
2730 dump_type (pp
, TREE_TYPE (t
), flags
);
2731 pp_cxx_left_paren (pp
);
2732 pp_cxx_right_paren (pp
);
2735 case NON_DEPENDENT_EXPR
:
2736 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2739 case ARGUMENT_PACK_SELECT
:
2740 dump_template_argument (pp
, ARGUMENT_PACK_SELECT_FROM_PACK (t
), flags
);
2753 pp_type_specifier_seq (pp
, t
);
2757 /* We get here when we want to print a dependent type as an
2758 id-expression, without any disambiguator decoration. */
2759 pp
->id_expression (t
);
2762 case TEMPLATE_TYPE_PARM
:
2763 case TEMPLATE_TEMPLATE_PARM
:
2764 case BOUND_TEMPLATE_TEMPLATE_PARM
:
2765 dump_type (pp
, t
, flags
);
2769 pp_cxx_trait_expression (pp
, t
);
2773 pp_cxx_va_arg_expression (pp
, t
);
2777 pp_cxx_offsetof_expression (pp
, t
);
2780 case ADDRESSOF_EXPR
:
2781 pp_cxx_addressof_expression (pp
, t
);
2785 dump_decl (pp
, t
, flags
);
2788 case EXPR_PACK_EXPANSION
:
2789 case UNARY_LEFT_FOLD_EXPR
:
2790 case UNARY_RIGHT_FOLD_EXPR
:
2791 case BINARY_LEFT_FOLD_EXPR
:
2792 case BINARY_RIGHT_FOLD_EXPR
:
2799 case VEC_DELETE_EXPR
:
2806 case UNORDERED_EXPR
:
2816 case FIX_TRUNC_EXPR
:
2821 case TRUTH_AND_EXPR
:
2823 case TRUTH_XOR_EXPR
:
2824 if (flags
& TFF_EXPR_IN_PARENS
)
2825 pp_cxx_left_paren (pp
);
2827 if (flags
& TFF_EXPR_IN_PARENS
)
2828 pp_cxx_right_paren (pp
);
2832 dump_expr (pp
, resolve_virtual_fun_from_obj_type_ref (t
), flags
);
2836 pp_string (pp
, M_("<lambda>"));
2840 pp_cxx_left_paren (pp
);
2841 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2842 pp_cxx_right_paren (pp
);
2846 pp_cxx_requires_expr (cxx_pp
, t
);
2850 pp_cxx_simple_requirement (cxx_pp
, t
);
2854 pp_cxx_type_requirement (cxx_pp
, t
);
2858 pp_cxx_compound_requirement (cxx_pp
, t
);
2862 pp_cxx_nested_requirement (cxx_pp
, t
);
2870 pp_cxx_constraint (cxx_pp
, t
);
2874 case PLACEHOLDER_EXPR
:
2875 pp_string (pp
, M_("*this"));
2879 dump_expr_list (pp
, t
, flags
);
2882 /* This list is incomplete, but should suffice for now.
2883 It is very important that `sorry' does not call
2884 `report_error_function'. That could cause an infinite loop. */
2886 pp_unsupported_tree (pp
, t
);
2889 pp_string (pp
, M_("<expression error>"));
2895 dump_binary_op (cxx_pretty_printer
*pp
, const char *opstring
, tree t
,
2898 pp_cxx_left_paren (pp
);
2899 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2900 pp_cxx_whitespace (pp
);
2902 pp_cxx_ws_string (pp
, opstring
);
2904 pp_string (pp
, M_("<unknown operator>"));
2905 pp_cxx_whitespace (pp
);
2906 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2907 pp_cxx_right_paren (pp
);
2911 dump_unary_op (cxx_pretty_printer
*pp
, const char *opstring
, tree t
, int flags
)
2913 if (flags
& TFF_EXPR_IN_PARENS
)
2914 pp_cxx_left_paren (pp
);
2915 pp_cxx_ws_string (pp
, opstring
);
2916 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2917 if (flags
& TFF_EXPR_IN_PARENS
)
2918 pp_cxx_right_paren (pp
);
2922 reinit_cxx_pp (void)
2924 pp_clear_output_area (cxx_pp
);
2925 cxx_pp
->padding
= pp_none
;
2926 pp_indentation (cxx_pp
) = 0;
2927 pp_needs_newline (cxx_pp
) = false;
2928 cxx_pp
->enclosing_scope
= current_function_decl
;
2931 /* Same as pp_formatted_text, except the return string is a separate
2932 copy and has a GGC storage duration, e.g. an indefinite lifetime. */
2935 pp_ggc_formatted_text (pretty_printer
*pp
)
2937 return ggc_strdup (pp_formatted_text (pp
));
2940 /* Exported interface to stringifying types, exprs and decls under TFF_*
2944 type_as_string (tree typ
, int flags
)
2947 pp_translate_identifiers (cxx_pp
) = false;
2948 dump_type (cxx_pp
, typ
, flags
);
2949 return pp_ggc_formatted_text (cxx_pp
);
2953 type_as_string_translate (tree typ
, int flags
)
2956 dump_type (cxx_pp
, typ
, flags
);
2957 return pp_ggc_formatted_text (cxx_pp
);
2961 expr_as_string (tree decl
, int flags
)
2964 pp_translate_identifiers (cxx_pp
) = false;
2965 dump_expr (cxx_pp
, decl
, flags
);
2966 return pp_ggc_formatted_text (cxx_pp
);
2969 /* Wrap decl_as_string with options appropriate for dwarf. */
2972 decl_as_dwarf_string (tree decl
, int flags
)
2975 /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag
2976 here will be adequate to get the desired behavior. */
2977 cxx_pp
->flags
|= pp_c_flag_gnu_v3
;
2978 name
= decl_as_string (decl
, flags
);
2979 /* Subsequent calls to the pretty printer shouldn't use this style. */
2980 cxx_pp
->flags
&= ~pp_c_flag_gnu_v3
;
2985 decl_as_string (tree decl
, int flags
)
2988 pp_translate_identifiers (cxx_pp
) = false;
2989 dump_decl (cxx_pp
, decl
, flags
);
2990 return pp_ggc_formatted_text (cxx_pp
);
2994 decl_as_string_translate (tree decl
, int flags
)
2997 dump_decl (cxx_pp
, decl
, flags
);
2998 return pp_ggc_formatted_text (cxx_pp
);
3001 /* Wrap lang_decl_name with options appropriate for dwarf. */
3004 lang_decl_dwarf_name (tree decl
, int v
, bool translate
)
3007 /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag
3008 here will be adequate to get the desired behavior. */
3009 cxx_pp
->flags
|= pp_c_flag_gnu_v3
;
3010 name
= lang_decl_name (decl
, v
, translate
);
3011 /* Subsequent calls to the pretty printer shouldn't use this style. */
3012 cxx_pp
->flags
&= ~pp_c_flag_gnu_v3
;
3016 /* Generate the three forms of printable names for cxx_printable_name. */
3019 lang_decl_name (tree decl
, int v
, bool translate
)
3023 ? decl_as_string_translate (decl
, TFF_DECL_SPECIFIERS
)
3024 : decl_as_string (decl
, TFF_DECL_SPECIFIERS
));
3027 pp_translate_identifiers (cxx_pp
) = translate
;
3029 && (DECL_CLASS_SCOPE_P (decl
)
3030 || (DECL_NAMESPACE_SCOPE_P (decl
)
3031 && CP_DECL_CONTEXT (decl
) != global_namespace
)))
3033 dump_type (cxx_pp
, CP_DECL_CONTEXT (decl
), TFF_PLAIN_IDENTIFIER
);
3034 pp_cxx_colon_colon (cxx_pp
);
3037 if (TREE_CODE (decl
) == FUNCTION_DECL
)
3038 dump_function_name (cxx_pp
, decl
, TFF_PLAIN_IDENTIFIER
);
3039 else if ((DECL_NAME (decl
) == NULL_TREE
)
3040 && TREE_CODE (decl
) == NAMESPACE_DECL
)
3041 dump_decl (cxx_pp
, decl
, TFF_PLAIN_IDENTIFIER
| TFF_UNQUALIFIED_NAME
);
3043 dump_decl (cxx_pp
, DECL_NAME (decl
), TFF_PLAIN_IDENTIFIER
);
3045 return pp_ggc_formatted_text (cxx_pp
);
3048 /* Return the location of a tree passed to %+ formats. */
3051 location_of (tree t
)
3055 t
= TYPE_MAIN_DECL (t
);
3057 return input_location
;
3059 else if (TREE_CODE (t
) == OVERLOAD
)
3063 return DECL_SOURCE_LOCATION (t
);
3064 if (TREE_CODE (t
) == DEFERRED_PARSE
)
3065 return defparse_location (t
);
3066 return cp_expr_loc_or_input_loc (t
);
3069 /* Now the interfaces from error et al to dump_type et al. Each takes an
3070 on/off VERBOSE flag and supply the appropriate TFF_ flags to a dump_
3074 decl_to_string (tree decl
, int verbose
)
3078 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == RECORD_TYPE
3079 || TREE_CODE (decl
) == UNION_TYPE
|| TREE_CODE (decl
) == ENUMERAL_TYPE
)
3080 flags
= TFF_CLASS_KEY_OR_ENUM
;
3082 flags
|= TFF_DECL_SPECIFIERS
;
3083 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
3084 flags
|= TFF_DECL_SPECIFIERS
| TFF_RETURN_TYPE
;
3085 flags
|= TFF_TEMPLATE_HEADER
;
3088 dump_decl (cxx_pp
, decl
, flags
);
3089 return pp_ggc_formatted_text (cxx_pp
);
3093 expr_to_string (tree decl
)
3096 dump_expr (cxx_pp
, decl
, 0);
3097 return pp_ggc_formatted_text (cxx_pp
);
3101 fndecl_to_string (tree fndecl
, int verbose
)
3105 flags
= TFF_EXCEPTION_SPECIFICATION
| TFF_DECL_SPECIFIERS
3106 | TFF_TEMPLATE_HEADER
;
3108 flags
|= TFF_FUNCTION_DEFAULT_ARGUMENTS
;
3110 dump_decl (cxx_pp
, fndecl
, flags
);
3111 return pp_ggc_formatted_text (cxx_pp
);
3116 code_to_string (enum tree_code c
)
3118 return get_tree_code_name (c
);
3122 language_to_string (enum languages c
)
3129 case lang_cplusplus
:
3138 /* Return the proper printed version of a parameter to a C++ function. */
3141 parm_to_string (int p
)
3145 pp_string (cxx_pp
, "'this'");
3147 pp_decimal_int (cxx_pp
, p
+ 1);
3148 return pp_ggc_formatted_text (cxx_pp
);
3152 op_to_string (bool assop
, enum tree_code p
)
3154 tree id
= ovl_op_identifier (assop
, p
);
3155 return id
? IDENTIFIER_POINTER (id
) : M_("<unknown>");
3158 /* Return a GC-allocated representation of type TYP, with verbosity VERBOSE.
3160 If QUOTE is non-NULL and if *QUOTE is true, then quotes are added to the
3161 string in appropriate places, and *QUOTE is written to with false
3162 to suppress pp_format's trailing close quote so that e.g.
3163 foo_typedef {aka underlying_foo} {enum}
3164 can be printed by "%qT" as:
3165 `foo_typedef' {aka `underlying_foo'} {enum}
3167 `foo_typedef {aka underlying_foo} {enum}'
3168 When adding such quotes, if POSTPROCESSED is true (for handling %H and %I)
3169 then a leading open quote will be added, whereas if POSTPROCESSED is false
3170 (for handling %T) then any leading quote has already been added by
3171 pp_format, or is not needed due to QUOTE being NULL (for template arguments
3174 SHOW_COLOR is used to determine the colorization of any quotes that
3178 type_to_string (tree typ
, int verbose
, bool postprocessed
, bool *quote
,
3183 flags
|= TFF_CLASS_KEY_OR_ENUM
;
3184 flags
|= TFF_TEMPLATE_HEADER
;
3188 if (postprocessed
&& quote
&& *quote
)
3189 pp_begin_quote (cxx_pp
, show_color
);
3191 struct obstack
*ob
= pp_buffer (cxx_pp
)->obstack
;
3192 int type_start
, type_len
;
3193 type_start
= obstack_object_size (ob
);
3195 dump_type (cxx_pp
, typ
, flags
);
3197 /* Remember the end of the initial dump. */
3198 type_len
= obstack_object_size (ob
) - type_start
;
3200 /* If we're printing a type that involves typedefs, also print the
3201 stripped version. But sometimes the stripped version looks
3202 exactly the same, so we don't want it after all. To avoid printing
3203 it in that case, we play ugly obstack games. */
3204 if (typ
&& TYPE_P (typ
) && typ
!= TYPE_CANONICAL (typ
)
3205 && !uses_template_parms (typ
))
3207 int aka_start
, aka_len
; char *p
;
3208 tree aka
= strip_typedefs (typ
);
3209 if (quote
&& *quote
)
3210 pp_end_quote (cxx_pp
, show_color
);
3211 pp_string (cxx_pp
, " {aka");
3212 pp_cxx_whitespace (cxx_pp
);
3213 if (quote
&& *quote
)
3214 pp_begin_quote (cxx_pp
, show_color
);
3215 /* And remember the start of the aka dump. */
3216 aka_start
= obstack_object_size (ob
);
3217 dump_type (cxx_pp
, aka
, flags
);
3218 aka_len
= obstack_object_size (ob
) - aka_start
;
3219 if (quote
&& *quote
)
3220 pp_end_quote (cxx_pp
, show_color
);
3221 pp_right_brace (cxx_pp
);
3222 p
= (char*)obstack_base (ob
);
3223 /* If they are identical, cut off the aka by unwinding the obstack. */
3224 if (type_len
== aka_len
3225 && memcmp (p
+ type_start
, p
+aka_start
, type_len
) == 0)
3227 /* We can't add a '\0' here, since we may be adding a closing quote
3228 below, and it would be hidden by the '\0'.
3229 Instead, manually unwind the current object within the obstack
3230 so that the insertion point is at the end of the type, before
3232 int delta
= type_start
+ type_len
- obstack_object_size (ob
);
3233 gcc_assert (delta
<= 0);
3234 obstack_blank_fast (ob
, delta
);
3238 /* No further closing quotes are needed. */
3242 if (quote
&& *quote
)
3244 pp_end_quote (cxx_pp
, show_color
);
3247 return pp_ggc_formatted_text (cxx_pp
);
3251 args_to_string (tree p
, int verbose
)
3255 flags
|= TFF_CLASS_KEY_OR_ENUM
;
3260 if (TYPE_P (TREE_VALUE (p
)))
3261 return type_as_string_translate (p
, flags
);
3264 for (; p
; p
= TREE_CHAIN (p
))
3266 if (null_node_p (TREE_VALUE (p
)))
3267 pp_cxx_ws_string (cxx_pp
, "NULL");
3269 dump_type (cxx_pp
, error_type (TREE_VALUE (p
)), flags
);
3271 pp_separate_with_comma (cxx_pp
);
3273 return pp_ggc_formatted_text (cxx_pp
);
3276 /* Pretty-print a deduction substitution (from deduction_tsubst_fntype). P
3277 is a TREE_LIST with purpose the TEMPLATE_DECL, value the template
3281 subst_to_string (tree p
)
3283 tree decl
= TREE_PURPOSE (p
);
3284 tree targs
= TREE_VALUE (p
);
3285 tree tparms
= DECL_TEMPLATE_PARMS (decl
);
3286 int flags
= (TFF_DECL_SPECIFIERS
|TFF_TEMPLATE_HEADER
3287 |TFF_NO_TEMPLATE_BINDINGS
);
3293 dump_template_decl (cxx_pp
, TREE_PURPOSE (p
), flags
);
3294 dump_substitution (cxx_pp
, NULL
, tparms
, targs
, /*flags=*/0);
3295 return pp_ggc_formatted_text (cxx_pp
);
3299 cv_to_string (tree p
, int v
)
3302 cxx_pp
->padding
= v
? pp_before
: pp_none
;
3303 pp_cxx_cv_qualifier_seq (cxx_pp
, p
);
3304 return pp_ggc_formatted_text (cxx_pp
);
3308 eh_spec_to_string (tree p
, int /*v*/)
3312 dump_exception_spec (cxx_pp
, p
, flags
);
3313 return pp_ggc_formatted_text (cxx_pp
);
3316 /* Langhook for print_error_function. */
3318 cxx_print_error_function (diagnostic_context
*context
, const char *file
,
3319 diagnostic_info
*diagnostic
)
3323 prefix
= xstrdup (file
);
3326 lhd_print_error_function (context
, file
, diagnostic
);
3327 pp_set_prefix (context
->printer
, prefix
);
3328 maybe_print_instantiation_context (context
);
3332 cp_diagnostic_starter (diagnostic_context
*context
,
3333 diagnostic_info
*diagnostic
)
3335 diagnostic_report_current_module (context
, diagnostic_location (diagnostic
));
3336 cp_print_error_function (context
, diagnostic
);
3337 maybe_print_instantiation_context (context
);
3338 maybe_print_constexpr_context (context
);
3339 maybe_print_constraint_context (context
);
3340 pp_set_prefix (context
->printer
, diagnostic_build_prefix (context
,
3344 /* Print current function onto BUFFER, in the process of reporting
3345 a diagnostic message. Called from cp_diagnostic_starter. */
3347 cp_print_error_function (diagnostic_context
*context
,
3348 diagnostic_info
*diagnostic
)
3350 /* If we are in an instantiation context, current_function_decl is likely
3351 to be wrong, so just rely on print_instantiation_full_context. */
3352 if (current_instantiation ())
3354 if (diagnostic_last_function_changed (context
, diagnostic
))
3356 char *old_prefix
= pp_take_prefix (context
->printer
);
3357 const char *file
= LOCATION_FILE (diagnostic_location (diagnostic
));
3358 tree abstract_origin
= diagnostic_abstract_origin (diagnostic
);
3359 char *new_prefix
= (file
&& abstract_origin
== NULL
)
3360 ? file_name_as_prefix (context
, file
) : NULL
;
3362 pp_set_prefix (context
->printer
, new_prefix
);
3364 if (current_function_decl
== NULL
)
3365 pp_string (context
->printer
, _("At global scope:"));
3370 if (abstract_origin
)
3372 ao
= BLOCK_ABSTRACT_ORIGIN (abstract_origin
);
3373 gcc_assert (TREE_CODE (ao
) == FUNCTION_DECL
);
3377 fndecl
= current_function_decl
;
3379 pp_printf (context
->printer
, function_category (fndecl
),
3380 cxx_printable_name_translate (fndecl
, 2));
3382 while (abstract_origin
)
3385 tree block
= abstract_origin
;
3387 locus
= &BLOCK_SOURCE_LOCATION (block
);
3389 block
= BLOCK_SUPERCONTEXT (block
);
3390 while (block
&& TREE_CODE (block
) == BLOCK
3391 && BLOCK_ABSTRACT_ORIGIN (block
))
3393 ao
= BLOCK_ABSTRACT_ORIGIN (block
);
3394 if (TREE_CODE (ao
) == FUNCTION_DECL
)
3399 else if (TREE_CODE (ao
) != BLOCK
)
3402 block
= BLOCK_SUPERCONTEXT (block
);
3405 abstract_origin
= block
;
3408 while (block
&& TREE_CODE (block
) == BLOCK
)
3409 block
= BLOCK_SUPERCONTEXT (block
);
3411 if (block
&& TREE_CODE (block
) == FUNCTION_DECL
)
3413 abstract_origin
= NULL
;
3417 expanded_location s
= expand_location (*locus
);
3418 pp_character (context
->printer
, ',');
3419 pp_newline (context
->printer
);
3422 if (context
->show_column
&& s
.column
!= 0)
3423 pp_printf (context
->printer
,
3424 _(" inlined from %qs at %r%s:%d:%d%R"),
3425 cxx_printable_name_translate (fndecl
, 2),
3426 "locus", s
.file
, s
.line
, s
.column
);
3428 pp_printf (context
->printer
,
3429 _(" inlined from %qs at %r%s:%d%R"),
3430 cxx_printable_name_translate (fndecl
, 2),
3431 "locus", s
.file
, s
.line
);
3435 pp_printf (context
->printer
, _(" inlined from %qs"),
3436 cxx_printable_name_translate (fndecl
, 2));
3439 pp_character (context
->printer
, ':');
3441 pp_newline (context
->printer
);
3443 diagnostic_set_last_function (context
, diagnostic
);
3444 pp_destroy_prefix (context
->printer
);
3445 context
->printer
->prefix
= old_prefix
;
3449 /* Returns a description of FUNCTION using standard terminology. The
3450 result is a format string of the form "In CATEGORY %qs". */
3452 function_category (tree fn
)
3454 /* We can get called from the middle-end for diagnostics of function
3455 clones. Make sure we have language specific information before
3456 dereferencing it. */
3457 if (DECL_LANG_SPECIFIC (STRIP_TEMPLATE (fn
))
3458 && DECL_FUNCTION_MEMBER_P (fn
))
3460 if (DECL_STATIC_FUNCTION_P (fn
))
3461 return _("In static member function %qs");
3462 else if (DECL_COPY_CONSTRUCTOR_P (fn
))
3463 return _("In copy constructor %qs");
3464 else if (DECL_CONSTRUCTOR_P (fn
))
3465 return _("In constructor %qs");
3466 else if (DECL_DESTRUCTOR_P (fn
))
3467 return _("In destructor %qs");
3468 else if (LAMBDA_FUNCTION_P (fn
))
3469 return _("In lambda function");
3471 return _("In member function %qs");
3474 return _("In function %qs");
3477 /* Report the full context of a current template instantiation,
3480 print_instantiation_full_context (diagnostic_context
*context
)
3482 struct tinst_level
*p
= current_instantiation ();
3483 location_t location
= input_location
;
3487 pp_verbatim (context
->printer
,
3489 ? _("%s: In substitution of %qS:\n")
3490 : _("%s: In instantiation of %q#D:\n"),
3491 LOCATION_FILE (location
),
3494 location
= p
->locus
;
3498 print_instantiation_partial_context (context
, p
, location
);
3501 /* Helper function of print_instantiation_partial_context() that
3502 prints a single line of instantiation context. */
3505 print_instantiation_partial_context_line (diagnostic_context
*context
,
3506 struct tinst_level
*t
,
3507 location_t loc
, bool recursive_p
)
3509 if (loc
== UNKNOWN_LOCATION
)
3512 expanded_location xloc
= expand_location (loc
);
3514 if (context
->show_column
)
3515 pp_verbatim (context
->printer
, _("%r%s:%d:%d:%R "),
3516 "locus", xloc
.file
, xloc
.line
, xloc
.column
);
3518 pp_verbatim (context
->printer
, _("%r%s:%d:%R "),
3519 "locus", xloc
.file
, xloc
.line
);
3524 pp_verbatim (context
->printer
,
3526 ? _("recursively required by substitution of %qS\n")
3527 : _("required by substitution of %qS\n"),
3530 pp_verbatim (context
->printer
,
3532 ? _("recursively required from %q#D\n")
3533 : _("required from %q#D\n"),
3538 pp_verbatim (context
->printer
,
3540 ? _("recursively required from here\n")
3541 : _("required from here\n"));
3545 /* Same as print_instantiation_full_context but less verbose. */
3548 print_instantiation_partial_context (diagnostic_context
*context
,
3549 struct tinst_level
*t0
, location_t loc
)
3551 struct tinst_level
*t
;
3554 location_t prev_loc
= loc
;
3556 for (t
= t0
; t
!= NULL
; t
= t
->next
)
3557 if (prev_loc
!= t
->locus
)
3559 prev_loc
= t
->locus
;
3565 if (template_backtrace_limit
3566 && n_total
> template_backtrace_limit
)
3568 int skip
= n_total
- template_backtrace_limit
;
3569 int head
= template_backtrace_limit
/ 2;
3571 /* Avoid skipping just 1. If so, skip 2. */
3575 head
= (template_backtrace_limit
- 1) / 2;
3578 for (n
= 0; n
< head
; n
++)
3580 gcc_assert (t
!= NULL
);
3581 if (loc
!= t
->locus
)
3582 print_instantiation_partial_context_line (context
, t
, loc
,
3583 /*recursive_p=*/false);
3587 if (t
!= NULL
&& skip
> 0)
3589 expanded_location xloc
;
3590 xloc
= expand_location (loc
);
3591 if (context
->show_column
)
3592 pp_verbatim (context
->printer
,
3593 _("%r%s:%d:%d:%R [ skipping %d instantiation "
3594 "contexts, use -ftemplate-backtrace-limit=0 to "
3596 "locus", xloc
.file
, xloc
.line
, xloc
.column
, skip
);
3598 pp_verbatim (context
->printer
,
3599 _("%r%s:%d:%R [ skipping %d instantiation "
3600 "contexts, use -ftemplate-backtrace-limit=0 to "
3602 "locus", xloc
.file
, xloc
.line
, skip
);
3607 } while (t
!= NULL
&& --skip
> 0);
3613 while (t
->next
!= NULL
&& t
->locus
== t
->next
->locus
)
3618 print_instantiation_partial_context_line (context
, t
, loc
,
3623 print_instantiation_partial_context_line (context
, NULL
, loc
,
3624 /*recursive_p=*/false);
3627 /* Called from cp_thing to print the template context for an error. */
3629 maybe_print_instantiation_context (diagnostic_context
*context
)
3631 if (!problematic_instantiation_changed () || current_instantiation () == 0)
3634 record_last_problematic_instantiation ();
3635 print_instantiation_full_context (context
);
3638 /* Report what constexpr call(s) we're trying to expand, if any. */
3641 maybe_print_constexpr_context (diagnostic_context
*context
)
3643 vec
<tree
> call_stack
= cx_error_context ();
3647 FOR_EACH_VEC_ELT (call_stack
, ix
, t
)
3649 expanded_location xloc
= expand_location (EXPR_LOCATION (t
));
3650 const char *s
= expr_as_string (t
, 0);
3651 if (context
->show_column
)
3652 pp_verbatim (context
->printer
,
3653 _("%r%s:%d:%d:%R in %<constexpr%> expansion of %qs"),
3654 "locus", xloc
.file
, xloc
.line
, xloc
.column
, s
);
3656 pp_verbatim (context
->printer
,
3657 _("%r%s:%d:%R in %<constexpr%> expansion of %qs"),
3658 "locus", xloc
.file
, xloc
.line
, s
);
3659 pp_newline (context
->printer
);
3665 print_location (diagnostic_context
*context
, location_t loc
)
3667 expanded_location xloc
= expand_location (loc
);
3668 if (context
->show_column
)
3669 pp_verbatim (context
->printer
, _("%r%s:%d:%d:%R "),
3670 "locus", xloc
.file
, xloc
.line
, xloc
.column
);
3672 pp_verbatim (context
->printer
, _("%r%s:%d:%R "),
3673 "locus", xloc
.file
, xloc
.line
);
3676 /* Instantiate the concept check for the purpose of diagnosing an error. */
3679 rebuild_concept_check (tree expr
, tree map
, tree args
)
3681 /* Instantiate the parameter mapping for the template-id. */
3682 map
= tsubst_parameter_mapping (map
, args
, tf_none
, NULL_TREE
);
3683 if (map
== error_mark_node
)
3684 return error_mark_node
;
3685 args
= get_mapped_args (map
);
3687 /* Rebuild the template id using substituted arguments. Substituting
3688 directly through the expression will trigger recursive satisfaction,
3689 so don't do that. */
3690 tree id
= unpack_concept_check (expr
);
3691 args
= tsubst_template_args (TREE_OPERAND (id
, 1), args
, tf_none
, NULL_TREE
);
3692 if (args
== error_mark_node
)
3693 return error_mark_node
;
3694 return build_nt (TEMPLATE_ID_EXPR
, TREE_OPERAND (id
, 0), args
);
3698 print_constrained_decl_info (diagnostic_context
*context
, tree decl
)
3700 print_location (context
, DECL_SOURCE_LOCATION (decl
));
3701 pp_verbatim (context
->printer
, "required by the constraints of %q#D\n", decl
);
3705 print_concept_check_info (diagnostic_context
*context
, tree expr
, tree map
, tree args
)
3707 gcc_assert (concept_check_p (expr
));
3709 tree id
= unpack_concept_check (expr
);
3710 tree tmpl
= TREE_OPERAND (id
, 0);
3712 tmpl
= OVL_FIRST (tmpl
);
3713 tree check
= rebuild_concept_check (expr
, map
, args
);
3714 if (check
== error_mark_node
)
3717 print_location (context
, DECL_SOURCE_LOCATION (tmpl
));
3718 pp_verbatim (context
->printer
, "required for the satisfaction of %qE\n", check
);
3721 /* Diagnose the entry point into the satisfaction error. Returns the next
3725 print_constraint_context_head (diagnostic_context
*context
, tree cxt
, tree args
)
3727 tree src
= TREE_VALUE (cxt
);
3730 print_location (context
, input_location
);
3731 pp_verbatim (context
->printer
, "required for constraint satisfaction\n");
3736 print_constrained_decl_info (context
, src
);
3741 print_concept_check_info (context
, src
, TREE_PURPOSE (cxt
), args
);
3742 return TREE_CHAIN (cxt
);
3747 print_requires_expression_info (diagnostic_context
*context
, tree constr
, tree args
)
3750 tree expr
= ATOMIC_CONSTR_EXPR (constr
);
3751 tree map
= ATOMIC_CONSTR_MAP (constr
);
3752 map
= tsubst_parameter_mapping (map
, args
, tf_none
, NULL_TREE
);
3753 if (map
== error_mark_node
)
3755 args
= get_mapped_args (map
);
3757 print_location (context
, cp_expr_loc_or_input_loc (expr
));
3758 pp_verbatim (context
->printer
, "in requirements ");
3760 tree parms
= TREE_OPERAND (expr
, 0);
3762 pp_verbatim (context
->printer
, "with ");
3765 tree next
= TREE_CHAIN (parms
);
3767 TREE_CHAIN (parms
) = NULL_TREE
;
3769 tree p
= tsubst (parms
, args
, tf_none
, NULL_TREE
);
3770 pp_verbatim (context
->printer
, "%q#D", p
);
3771 TREE_CHAIN (parms
) = next
;
3774 pp_separate_with_comma ((cxx_pretty_printer
*)context
->printer
);
3779 pp_verbatim (context
->printer
, "\n");
3783 maybe_print_single_constraint_context (diagnostic_context
*context
, tree failed
)
3788 tree constr
= TREE_VALUE (failed
);
3789 if (!constr
|| constr
== error_mark_node
)
3791 tree cxt
= CONSTR_CONTEXT (constr
);
3794 tree args
= TREE_PURPOSE (failed
);
3796 /* Print the stack of requirements. */
3797 cxt
= print_constraint_context_head (context
, cxt
, args
);
3798 while (cxt
&& !DECL_P (TREE_VALUE (cxt
)))
3800 tree expr
= TREE_VALUE (cxt
);
3801 tree map
= TREE_PURPOSE (cxt
);
3802 print_concept_check_info (context
, expr
, map
, args
);
3803 cxt
= TREE_CHAIN (cxt
);
3806 /* For certain constraints, we can provide additional context. */
3807 if (TREE_CODE (constr
) == ATOMIC_CONSTR
3808 && TREE_CODE (ATOMIC_CONSTR_EXPR (constr
)) == REQUIRES_EXPR
)
3809 print_requires_expression_info (context
, constr
, args
);
3813 maybe_print_constraint_context (diagnostic_context
*context
)
3815 if (!current_failed_constraint
)
3818 tree cur
= current_failed_constraint
;
3820 /* Recursively print nested contexts. */
3821 current_failed_constraint
= TREE_CHAIN (current_failed_constraint
);
3822 if (current_failed_constraint
)
3823 maybe_print_constraint_context (context
);
3825 /* Print this context. */
3826 maybe_print_single_constraint_context (context
, cur
);
3829 /* Return true iff TYPE_A and TYPE_B are template types that are
3830 meaningful to compare. */
3833 comparable_template_types_p (tree type_a
, tree type_b
)
3835 if (!CLASS_TYPE_P (type_a
))
3837 if (!CLASS_TYPE_P (type_b
))
3840 tree tinfo_a
= TYPE_TEMPLATE_INFO (type_a
);
3841 tree tinfo_b
= TYPE_TEMPLATE_INFO (type_b
);
3842 if (!tinfo_a
|| !tinfo_b
)
3845 return TI_TEMPLATE (tinfo_a
) == TI_TEMPLATE (tinfo_b
);
3848 /* Start a new line indented by SPC spaces on PP. */
3851 newline_and_indent (pretty_printer
*pp
, int spc
)
3854 for (int i
= 0; i
< spc
; i
++)
3858 /* Generate a GC-allocated string for ARG, an expression or type. */
3861 arg_to_string (tree arg
, bool verbose
)
3864 return type_to_string (arg
, verbose
, true, NULL
, false);
3866 return expr_to_string (arg
);
3869 /* Subroutine to type_to_string_with_compare and
3870 print_template_tree_comparison.
3872 Print a representation of ARG (an expression or type) to PP,
3873 colorizing it as "type-diff" if PP->show_color. */
3876 print_nonequal_arg (pretty_printer
*pp
, tree arg
, bool verbose
)
3878 pp_printf (pp
, "%r%s%R",
3881 ? arg_to_string (arg
, verbose
)
3882 : G_("(no argument)")));
3885 /* Recursively print template TYPE_A to PP, as compared to template TYPE_B.
3887 The types must satisfy comparable_template_types_p.
3889 If INDENT is 0, then this is equivalent to type_to_string (TYPE_A), but
3890 potentially colorizing/eliding in comparison with TYPE_B.
3892 For example given types:
3893 vector<map<int,double>>
3895 vector<map<int,float>>
3896 then the result on PP would be:
3897 vector<map<[...],double>>
3898 with type elision, and:
3899 vector<map<int,double>>
3900 without type elision.
3902 In both cases the parts of TYPE that differ from PEER will be colorized
3903 if pp_show_color (pp) is true. In the above example, this would be
3906 If INDENT is non-zero, then the types are printed in a tree-like form
3907 which shows both types. In the above example, the result on PP would be:
3914 and without type-elision would be:
3921 As before, the differing parts of the types are colorized if
3922 pp_show_color (pp) is true ("double" and "float" in this example).
3924 Template arguments in which both types are using the default arguments
3925 are not printed; if at least one of the two types is using a non-default
3926 argument, then that argument is printed (or both arguments for the
3927 tree-like print format). */
3930 print_template_differences (pretty_printer
*pp
, tree type_a
, tree type_b
,
3931 bool verbose
, int indent
)
3934 newline_and_indent (pp
, indent
);
3936 tree tinfo_a
= TYPE_TEMPLATE_INFO (type_a
);
3937 tree tinfo_b
= TYPE_TEMPLATE_INFO (type_b
);
3939 pp_printf (pp
, "%s<",
3940 IDENTIFIER_POINTER (DECL_NAME (TI_TEMPLATE (tinfo_a
))));
3942 tree args_a
= TI_ARGS (tinfo_a
);
3943 tree args_b
= TI_ARGS (tinfo_b
);
3944 gcc_assert (TREE_CODE (args_a
) == TREE_VEC
);
3945 gcc_assert (TREE_CODE (args_b
) == TREE_VEC
);
3947 int len_a
= get_non_default_template_args_count (args_a
, flags
);
3948 args_a
= INNERMOST_TEMPLATE_ARGS (args_a
);
3949 int len_b
= get_non_default_template_args_count (args_b
, flags
);
3950 args_b
= INNERMOST_TEMPLATE_ARGS (args_b
);
3951 /* Determine the maximum range of args for which non-default template args
3952 were used; beyond this, only default args (if any) were used, and so
3953 they will be equal from this point onwards.
3954 One of the two peers might have used default arguments within this
3955 range, but the other will be using non-default arguments, and so
3956 it's more readable to print both within this range, to highlight
3958 int len_max
= MAX (len_a
, len_b
);
3959 gcc_assert (TREE_CODE (args_a
) == TREE_VEC
);
3960 gcc_assert (TREE_CODE (args_b
) == TREE_VEC
);
3961 for (int idx
= 0; idx
< len_max
; idx
++)
3964 pp_character (pp
, ',');
3966 tree arg_a
= TREE_VEC_ELT (args_a
, idx
);
3967 tree arg_b
= TREE_VEC_ELT (args_b
, idx
);
3971 newline_and_indent (pp
, indent
+ 2);
3972 /* Can do elision here, printing "[...]". */
3973 if (flag_elide_type
)
3974 pp_string (pp
, G_("[...]"));
3976 pp_string (pp
, arg_to_string (arg_a
, verbose
));
3980 int new_indent
= indent
? indent
+ 2 : 0;
3981 if (comparable_template_types_p (arg_a
, arg_b
))
3982 print_template_differences (pp
, arg_a
, arg_b
, verbose
, new_indent
);
3986 newline_and_indent (pp
, indent
+ 2);
3987 pp_character (pp
, '[');
3988 print_nonequal_arg (pp
, arg_a
, verbose
);
3989 pp_string (pp
, " != ");
3990 print_nonequal_arg (pp
, arg_b
, verbose
);
3991 pp_character (pp
, ']');
3994 print_nonequal_arg (pp
, arg_a
, verbose
);
3997 pp_printf (pp
, ">");
4000 /* As type_to_string, but for a template, potentially colorizing/eliding
4001 in comparison with PEER.
4002 For example, if TYPE is map<int,double> and PEER is map<int,int>,
4003 then the resulting string would be:
4005 with type elision, and:
4007 without type elision.
4009 In both cases the parts of TYPE that differ from PEER will be colorized
4010 if SHOW_COLOR is true. In the above example, this would be "double".
4012 Template arguments in which both types are using the default arguments
4013 are not printed; if at least one of the two types is using a non-default
4014 argument, then both arguments are printed.
4016 The resulting string is in a GC-allocated buffer. */
4019 type_to_string_with_compare (tree type
, tree peer
, bool verbose
,
4022 pretty_printer inner_pp
;
4023 pretty_printer
*pp
= &inner_pp
;
4024 pp_show_color (pp
) = show_color
;
4026 print_template_differences (pp
, type
, peer
, verbose
, 0);
4027 return pp_ggc_formatted_text (pp
);
4030 /* Recursively print a tree-like comparison of TYPE_A and TYPE_B to PP,
4031 indented by INDENT spaces.
4033 For example given types:
4035 vector<map<int,double>>
4039 vector<map<double,float>>
4041 the output with type elision would be:
4048 and without type-elision would be:
4055 TYPE_A and TYPE_B must both be comparable template types
4056 (as per comparable_template_types_p).
4058 Template arguments in which both types are using the default arguments
4059 are not printed; if at least one of the two types is using a non-default
4060 argument, then both arguments are printed. */
4063 print_template_tree_comparison (pretty_printer
*pp
, tree type_a
, tree type_b
,
4064 bool verbose
, int indent
)
4066 print_template_differences (pp
, type_a
, type_b
, verbose
, indent
);
4069 /* Subroutine for use in a format_postprocessor::handle
4070 implementation. Adds a chunk to the end of
4071 formatted output, so that it will be printed
4072 by pp_output_formatted_text. */
4075 append_formatted_chunk (pretty_printer
*pp
, const char *content
)
4077 output_buffer
*buffer
= pp_buffer (pp
);
4078 struct chunk_info
*chunk_array
= buffer
->cur_chunk_array
;
4079 const char **args
= chunk_array
->args
;
4081 unsigned int chunk_idx
;
4082 for (chunk_idx
= 0; args
[chunk_idx
]; chunk_idx
++)
4084 args
[chunk_idx
++] = content
;
4085 args
[chunk_idx
] = NULL
;
4088 /* Create a copy of CONTENT, with quotes added, and,
4089 potentially, with colorization.
4090 No escaped is performed on CONTENT.
4091 The result is in a GC-allocated buffer. */
4094 add_quotes (const char *content
, bool show_color
)
4096 pretty_printer tmp_pp
;
4097 pp_show_color (&tmp_pp
) = show_color
;
4099 /* We have to use "%<%s%>" rather than "%qs" here in order to avoid
4100 quoting colorization bytes within the results. */
4101 pp_printf (&tmp_pp
, "%<%s%>", content
);
4103 return pp_ggc_formatted_text (&tmp_pp
);
4106 /* If we had %H and %I, and hence deferred printing them,
4107 print them now, storing the result into the chunk_info
4108 for pp_format. Quote them if 'q' was provided.
4109 Also print the difference in tree form, adding it as
4110 an additional chunk. */
4113 cxx_format_postprocessor::handle (pretty_printer
*pp
)
4115 /* If we have one of %H and %I, the other should have
4117 if (m_type_a
.m_tree
|| m_type_b
.m_tree
)
4119 /* Avoid reentrancy issues by working with a copy of
4120 m_type_a and m_type_b, resetting them now. */
4121 deferred_printed_type type_a
= m_type_a
;
4122 deferred_printed_type type_b
= m_type_b
;
4123 m_type_a
= deferred_printed_type ();
4124 m_type_b
= deferred_printed_type ();
4126 gcc_assert (type_a
.m_buffer_ptr
);
4127 gcc_assert (type_b
.m_buffer_ptr
);
4129 bool show_color
= pp_show_color (pp
);
4131 const char *type_a_text
;
4132 const char *type_b_text
;
4134 if (comparable_template_types_p (type_a
.m_tree
, type_b
.m_tree
))
4137 = type_to_string_with_compare (type_a
.m_tree
, type_b
.m_tree
,
4138 type_a
.m_verbose
, show_color
);
4140 = type_to_string_with_compare (type_b
.m_tree
, type_a
.m_tree
,
4141 type_b
.m_verbose
, show_color
);
4143 if (flag_diagnostics_show_template_tree
)
4145 pretty_printer inner_pp
;
4146 pp_show_color (&inner_pp
) = pp_show_color (pp
);
4147 print_template_tree_comparison
4148 (&inner_pp
, type_a
.m_tree
, type_b
.m_tree
, type_a
.m_verbose
, 2);
4149 append_formatted_chunk (pp
, pp_ggc_formatted_text (&inner_pp
));
4154 /* If the types were not comparable (or if only one of %H/%I was
4155 provided), they are printed normally, and no difference tree
4157 type_a_text
= type_to_string (type_a
.m_tree
, type_a
.m_verbose
,
4158 true, &type_a
.m_quote
, show_color
);
4159 type_b_text
= type_to_string (type_b
.m_tree
, type_b
.m_verbose
,
4160 true, &type_b
.m_quote
, show_color
);
4164 type_a_text
= add_quotes (type_a_text
, show_color
);
4165 *type_a
.m_buffer_ptr
= type_a_text
;
4168 type_b_text
= add_quotes (type_b_text
, show_color
);
4169 *type_b
.m_buffer_ptr
= type_b_text
;
4173 /* Subroutine for handling %H and %I, to support i18n of messages like:
4175 error_at (loc, "could not convert %qE from %qH to %qI",
4176 expr, type_a, type_b);
4178 so that we can print things like:
4180 could not convert 'foo' from 'map<int,double>' to 'map<int,int>'
4182 and, with type-elision:
4184 could not convert 'foo' from 'map<[...],double>' to 'map<[...],int>'
4186 (with color-coding of the differences between the types).
4188 The %H and %I format codes are peers: both must be present,
4189 and they affect each other. Hence to handle them, we must
4190 delay printing until we have both, deferring the printing to
4191 pretty_printer's m_format_postprocessor hook.
4193 This is called in phase 2 of pp_format, when it is accumulating
4194 a series of formatted chunks. We stash the location of the chunk
4195 we're meant to have written to, so that we can write to it in the
4196 m_format_postprocessor hook.
4198 We also need to stash whether a 'q' prefix was provided (the QUOTE
4199 param) so that we can add the quotes when writing out the delayed
4203 defer_phase_2_of_type_diff (deferred_printed_type
*deferred
,
4204 tree type
, const char **buffer_ptr
,
4205 bool verbose
, bool quote
)
4207 gcc_assert (deferred
->m_tree
== NULL_TREE
);
4208 gcc_assert (deferred
->m_buffer_ptr
== NULL
);
4209 *deferred
= deferred_printed_type (type
, buffer_ptr
, verbose
, quote
);
4213 /* Called from output_format -- during diagnostic message processing --
4214 to handle C++ specific format specifier with the following meanings:
4215 %A function argument-list.
4219 %F function declaration.
4221 %H type difference (from).
4222 %I type difference (to).
4224 %L language as used in extern "lang".
4226 %P function parameter whose position is indicated by an integer.
4227 %Q assignment operator.
4228 %S substitution (template + args)
4231 %X exception-specification. */
4233 cp_printer (pretty_printer
*pp
, text_info
*text
, const char *spec
,
4234 int precision
, bool wide
, bool set_locus
, bool verbose
,
4235 bool *quoted
, const char **buffer_ptr
)
4237 gcc_assert (pp
->m_format_postprocessor
);
4238 cxx_format_postprocessor
*postprocessor
4239 = static_cast <cxx_format_postprocessor
*> (pp
->m_format_postprocessor
);
4243 #define next_tree (t = va_arg (*text->args_ptr, tree))
4244 #define next_tcode ((enum tree_code) va_arg (*text->args_ptr, int))
4245 #define next_lang ((enum languages) va_arg (*text->args_ptr, int))
4246 #define next_int va_arg (*text->args_ptr, int)
4248 if (precision
!= 0 || wide
)
4253 case 'A': result
= args_to_string (next_tree
, verbose
); break;
4254 case 'C': result
= code_to_string (next_tcode
); break;
4257 tree temp
= next_tree
;
4259 && DECL_HAS_DEBUG_EXPR_P (temp
))
4261 temp
= DECL_DEBUG_EXPR (temp
);
4264 result
= expr_to_string (temp
);
4268 result
= decl_to_string (temp
, verbose
);
4271 case 'E': result
= expr_to_string (next_tree
); break;
4272 case 'F': result
= fndecl_to_string (next_tree
, verbose
); break;
4274 percent_G_format (text
);
4277 defer_phase_2_of_type_diff (&postprocessor
->m_type_a
, next_tree
,
4278 buffer_ptr
, verbose
, *quoted
);
4281 defer_phase_2_of_type_diff (&postprocessor
->m_type_b
, next_tree
,
4282 buffer_ptr
, verbose
, *quoted
);
4285 t
= va_arg (*text
->args_ptr
, tree
);
4286 percent_K_format (text
, EXPR_LOCATION (t
), TREE_BLOCK (t
));
4288 case 'L': result
= language_to_string (next_lang
); break;
4289 case 'O': result
= op_to_string (false, next_tcode
); break;
4290 case 'P': result
= parm_to_string (next_int
); break;
4291 case 'Q': result
= op_to_string (true, next_tcode
); break;
4292 case 'S': result
= subst_to_string (next_tree
); break;
4295 result
= type_to_string (next_tree
, verbose
, false, quoted
,
4296 pp_show_color (pp
));
4299 case 'V': result
= cv_to_string (next_tree
, verbose
); break;
4300 case 'X': result
= eh_spec_to_string (next_tree
, verbose
); break;
4306 pp_string (pp
, result
);
4307 if (set_locus
&& t
!= NULL
)
4308 text
->set_location (0, location_of (t
), SHOW_RANGE_WITH_CARET
);
4316 /* Warn about the use of C++0x features when appropriate. */
4318 maybe_warn_cpp0x (cpp0x_warn_str str
)
4320 if ((cxx_dialect
== cxx98
) && !in_system_header_at (input_location
))
4321 /* We really want to suppress this warning in system headers,
4322 because libstdc++ uses variadic templates even when we aren't
4326 case CPP0X_INITIALIZER_LISTS
:
4327 pedwarn (input_location
, 0,
4328 "extended initializer lists "
4329 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4331 case CPP0X_EXPLICIT_CONVERSION
:
4332 pedwarn (input_location
, 0,
4333 "explicit conversion operators "
4334 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4336 case CPP0X_VARIADIC_TEMPLATES
:
4337 pedwarn (input_location
, 0,
4338 "variadic templates "
4339 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4341 case CPP0X_LAMBDA_EXPR
:
4342 pedwarn (input_location
, 0,
4343 "lambda expressions "
4344 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4347 pedwarn (input_location
, 0,
4348 "C++11 auto only available with %<-std=c++11%> or "
4349 "%<-std=gnu++11%>");
4351 case CPP0X_SCOPED_ENUMS
:
4352 pedwarn (input_location
, 0,
4353 "scoped enums only available with %<-std=c++11%> or "
4354 "%<-std=gnu++11%>");
4356 case CPP0X_DEFAULTED_DELETED
:
4357 pedwarn (input_location
, 0,
4358 "defaulted and deleted functions "
4359 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4361 case CPP0X_INLINE_NAMESPACES
:
4362 pedwarn (input_location
, OPT_Wpedantic
,
4363 "inline namespaces "
4364 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4366 case CPP0X_OVERRIDE_CONTROLS
:
4367 pedwarn (input_location
, 0,
4368 "override controls (override/final) "
4369 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4372 pedwarn (input_location
, 0,
4373 "non-static data member initializers "
4374 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4376 case CPP0X_USER_DEFINED_LITERALS
:
4377 pedwarn (input_location
, 0,
4378 "user-defined literals "
4379 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4381 case CPP0X_DELEGATING_CTORS
:
4382 pedwarn (input_location
, 0,
4383 "delegating constructors "
4384 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4386 case CPP0X_INHERITING_CTORS
:
4387 pedwarn (input_location
, 0,
4388 "inheriting constructors "
4389 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4391 case CPP0X_ATTRIBUTES
:
4392 pedwarn (input_location
, 0,
4394 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4396 case CPP0X_REF_QUALIFIER
:
4397 pedwarn (input_location
, 0,
4399 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4406 /* Warn about the use of variadic templates when appropriate. */
4408 maybe_warn_variadic_templates (void)
4410 maybe_warn_cpp0x (CPP0X_VARIADIC_TEMPLATES
);
4414 /* Issue an ISO C++98 pedantic warning at LOCATION, conditional on
4415 option OPT with text GMSGID. Use this function to report
4416 diagnostics for constructs that are invalid C++98, but valid
4419 pedwarn_cxx98 (location_t location
, int opt
, const char *gmsgid
, ...)
4421 diagnostic_info diagnostic
;
4424 rich_location
richloc (line_table
, location
);
4426 va_start (ap
, gmsgid
);
4427 diagnostic_set_info (&diagnostic
, gmsgid
, &ap
, &richloc
,
4428 (cxx_dialect
== cxx98
) ? DK_PEDWARN
: DK_WARNING
);
4429 diagnostic
.option_index
= opt
;
4430 ret
= diagnostic_report_diagnostic (global_dc
, &diagnostic
);
4435 /* Issue a diagnostic that NAME cannot be found in SCOPE. DECL is what
4436 we found when we tried to do the lookup. LOCATION is the location of
4437 the NAME identifier. */
4440 qualified_name_lookup_error (tree scope
, tree name
,
4441 tree decl
, location_t location
)
4443 if (scope
== error_mark_node
)
4444 ; /* We already complained. */
4445 else if (TYPE_P (scope
))
4447 if (!COMPLETE_TYPE_P (scope
))
4448 error_at (location
, "incomplete type %qT used in nested name specifier",
4450 else if (TREE_CODE (decl
) == TREE_LIST
)
4452 error_at (location
, "reference to %<%T::%D%> is ambiguous",
4454 print_candidates (decl
);
4459 if (SCOPED_ENUM_P (scope
) && TREE_CODE (name
) == IDENTIFIER_NODE
)
4460 hint
= suggest_alternative_in_scoped_enum (name
, scope
);
4461 if (const char *suggestion
= hint
.suggestion ())
4463 gcc_rich_location
richloc (location
);
4464 richloc
.add_fixit_replace (suggestion
);
4466 "%qD is not a member of %qT; did you mean %qs?",
4467 name
, scope
, suggestion
);
4470 error_at (location
, "%qD is not a member of %qT", name
, scope
);
4473 else if (scope
!= global_namespace
)
4475 auto_diagnostic_group d
;
4476 bool emit_fixit
= true;
4478 = suggest_alternative_in_explicit_scope (location
, name
, scope
);
4481 hint
= suggest_alternatives_in_other_namespaces (location
, name
);
4482 /* "location" is just the location of the name, not of the explicit
4483 scope, and it's not easy to get at the latter, so we can't issue
4484 fix-it hints for the suggestion. */
4487 if (const char *suggestion
= hint
.suggestion ())
4489 gcc_rich_location
richloc (location
);
4491 richloc
.add_fixit_replace (suggestion
);
4492 error_at (&richloc
, "%qD is not a member of %qD; did you mean %qs?",
4493 name
, scope
, suggestion
);
4496 error_at (location
, "%qD is not a member of %qD", name
, scope
);
4500 auto_diagnostic_group d
;
4501 name_hint hint
= suggest_alternatives_for (location
, name
, true);
4502 if (const char *suggestion
= hint
.suggestion ())
4504 gcc_rich_location
richloc (location
);
4505 richloc
.add_fixit_replace (suggestion
);
4507 "%<::%D%> has not been declared; did you mean %qs?",
4511 error_at (location
, "%<::%D%> has not been declared", name
);
4515 /* C++-specific implementation of range_label::get_text () vfunc for
4516 range_label_for_type_mismatch.
4518 Compare with print_template_differences above. */
4521 range_label_for_type_mismatch::get_text (unsigned /*range_idx*/) const
4523 if (m_labelled_type
== NULL_TREE
)
4524 return label_text (NULL
, false);
4526 const bool verbose
= false;
4527 const bool show_color
= false;
4531 && comparable_template_types_p (m_labelled_type
, m_other_type
))
4532 result
= type_to_string_with_compare (m_labelled_type
, m_other_type
,
4533 verbose
, show_color
);
4535 result
= type_to_string (m_labelled_type
, verbose
, true, NULL
, show_color
);
4537 /* Both of the above return GC-allocated buffers, so the caller mustn't
4539 return label_text (const_cast <char *> (result
), false);