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
, NULL
, STF_USER_VISIBLE
);
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
)))
453 unsigned int stf_flags
= (!(pp
->flags
& pp_c_flag_gnu_v3
)
454 ? STF_USER_VISIBLE
: 0);
455 t
= strip_typedefs (t
, NULL
, stf_flags
);
457 else if (alias_template_specialization_p (t
))
459 dump_alias_template_specialization (pp
, t
, flags
);
462 else if (same_type_p (t
, TREE_TYPE (decl
)))
466 pp_cxx_cv_qualifier_seq (pp
, t
);
467 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
472 if (TYPE_PTRMEMFUNC_P (t
))
475 switch (TREE_CODE (t
))
478 if (t
== init_list_type_node
)
479 pp_string (pp
, M_("<brace-enclosed initializer list>"));
480 else if (t
== unknown_type_node
)
481 pp_string (pp
, M_("<unresolved overloaded function type>"));
484 pp_cxx_cv_qualifier_seq (pp
, t
);
485 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
490 /* A list of function parms. */
491 dump_parameters (pp
, t
, flags
);
494 case IDENTIFIER_NODE
:
495 pp_cxx_tree_identifier (pp
, t
);
499 dump_type (pp
, BINFO_TYPE (t
), flags
);
505 dump_aggr_type (pp
, t
, flags
);
509 if (flags
& TFF_CHASE_TYPEDEF
)
511 dump_type (pp
, DECL_ORIGINAL_TYPE (t
)
512 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
), flags
);
519 dump_decl (pp
, t
, flags
& ~TFF_DECL_SPECIFIERS
);
528 case FIXED_POINT_TYPE
:
529 pp_type_specifier_seq (pp
, t
);
532 case TEMPLATE_TEMPLATE_PARM
:
533 /* For parameters inside template signature. */
534 if (TYPE_IDENTIFIER (t
))
535 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
537 pp_cxx_canonical_template_parameter (pp
, t
);
540 case BOUND_TEMPLATE_TEMPLATE_PARM
:
542 tree args
= TYPE_TI_ARGS (t
);
543 pp_cxx_cv_qualifier_seq (pp
, t
);
544 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
545 pp_cxx_begin_template_argument_list (pp
);
546 dump_template_argument_list (pp
, args
, flags
);
547 pp_cxx_end_template_argument_list (pp
);
551 case TEMPLATE_TYPE_PARM
:
552 pp_cxx_cv_qualifier_seq (pp
, t
);
553 if (template_placeholder_p (t
))
555 t
= TREE_TYPE (CLASS_PLACEHOLDER_TEMPLATE (t
));
556 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
557 pp_string (pp
, "<...auto...>");
559 else if (TYPE_IDENTIFIER (t
))
560 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
562 pp_cxx_canonical_template_parameter
563 (pp
, TEMPLATE_TYPE_PARM_INDEX (t
));
564 /* If this is a constrained placeholder, add the requirements. */
565 if (tree c
= PLACEHOLDER_TYPE_CONSTRAINTS (t
))
566 pp_cxx_constrained_type_spec (pp
, c
);
569 /* This is not always necessary for pointers and such, but doing this
570 reduces code size. */
579 dump_type_prefix (pp
, t
, flags
);
580 dump_type_suffix (pp
, t
, flags
);
584 if (! (flags
& TFF_CHASE_TYPEDEF
)
585 && DECL_ORIGINAL_TYPE (TYPE_NAME (t
)))
587 dump_decl (pp
, TYPE_NAME (t
), TFF_PLAIN_IDENTIFIER
);
590 pp_cxx_cv_qualifier_seq (pp
, t
);
591 pp_cxx_ws_string (pp
,
592 TYPENAME_IS_ENUM_P (t
) ? "enum"
593 : TYPENAME_IS_CLASS_P (t
) ? "class"
595 dump_typename (pp
, t
, flags
);
598 case UNBOUND_CLASS_TEMPLATE
:
599 if (! (flags
& TFF_UNQUALIFIED_NAME
))
601 dump_type (pp
, TYPE_CONTEXT (t
), flags
);
602 pp_cxx_colon_colon (pp
);
604 pp_cxx_ws_string (pp
, "template");
605 dump_type (pp
, TYPE_IDENTIFIER (t
), flags
);
609 pp_cxx_ws_string (pp
, "__typeof__");
610 pp_cxx_whitespace (pp
);
611 pp_cxx_left_paren (pp
);
612 dump_expr (pp
, TYPEOF_TYPE_EXPR (t
), flags
& ~TFF_EXPR_IN_PARENS
);
613 pp_cxx_right_paren (pp
);
616 case UNDERLYING_TYPE
:
617 pp_cxx_ws_string (pp
, "__underlying_type");
618 pp_cxx_whitespace (pp
);
619 pp_cxx_left_paren (pp
);
620 dump_expr (pp
, UNDERLYING_TYPE_TYPE (t
), flags
& ~TFF_EXPR_IN_PARENS
);
621 pp_cxx_right_paren (pp
);
624 case TYPE_PACK_EXPANSION
:
625 dump_type (pp
, PACK_EXPANSION_PATTERN (t
), flags
);
626 pp_cxx_ws_string (pp
, "...");
629 case TYPE_ARGUMENT_PACK
:
630 dump_template_argument (pp
, t
, flags
);
634 pp_cxx_ws_string (pp
, "decltype");
635 pp_cxx_whitespace (pp
);
636 pp_cxx_left_paren (pp
);
637 dump_expr (pp
, DECLTYPE_TYPE_EXPR (t
), flags
& ~TFF_EXPR_IN_PARENS
);
638 pp_cxx_right_paren (pp
);
642 pp_string (pp
, "std::nullptr_t");
646 pp_unsupported_tree (pp
, t
);
650 pp_string (pp
, M_("<type error>"));
655 /* Dump a TYPENAME_TYPE. We need to notice when the context is itself
659 dump_typename (cxx_pretty_printer
*pp
, tree t
, int flags
)
661 tree ctx
= TYPE_CONTEXT (t
);
663 if (TREE_CODE (ctx
) == TYPENAME_TYPE
)
664 dump_typename (pp
, ctx
, flags
);
666 dump_type (pp
, ctx
, flags
& ~TFF_CLASS_KEY_OR_ENUM
);
667 pp_cxx_colon_colon (pp
);
668 dump_decl (pp
, TYPENAME_TYPE_FULLNAME (t
), flags
);
671 /* Return the name of the supplied aggregate, or enumeral type. */
674 class_key_or_enum_as_string (tree t
)
676 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
678 if (SCOPED_ENUM_P (t
))
683 else if (TREE_CODE (t
) == UNION_TYPE
)
685 else if (TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_DECLARED_CLASS (t
))
691 /* Print out a class declaration T under the control of FLAGS,
692 in the form `class foo'. */
695 dump_aggr_type (cxx_pretty_printer
*pp
, tree t
, int flags
)
698 const char *variety
= class_key_or_enum_as_string (t
);
702 pp_cxx_cv_qualifier_seq (pp
, t
);
704 if (flags
& TFF_CLASS_KEY_OR_ENUM
)
705 pp_cxx_ws_string (pp
, variety
);
707 name
= TYPE_NAME (t
);
711 typdef
= (!DECL_ARTIFICIAL (name
)
712 /* An alias specialization is not considered to be a
714 && !alias_template_specialization_p (t
));
717 && ((flags
& TFF_CHASE_TYPEDEF
)
718 || (!flag_pretty_templates
&& DECL_LANG_SPECIFIC (name
)
719 && DECL_TEMPLATE_INFO (name
))))
720 || DECL_SELF_REFERENCE_P (name
))
722 t
= TYPE_MAIN_VARIANT (t
);
723 name
= TYPE_NAME (t
);
727 tmplate
= !typdef
&& TREE_CODE (t
) != ENUMERAL_TYPE
728 && TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_TEMPLATE_INFO (t
)
729 && (TREE_CODE (CLASSTYPE_TI_TEMPLATE (t
)) != TEMPLATE_DECL
730 || PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t
)));
732 if (! (flags
& TFF_UNQUALIFIED_NAME
))
733 dump_scope (pp
, CP_DECL_CONTEXT (name
), flags
| TFF_SCOPE
);
734 flags
&= ~TFF_UNQUALIFIED_NAME
;
737 /* Because the template names are mangled, we have to locate
738 the most general template, and use that name. */
739 tree tpl
= TYPE_TI_TEMPLATE (t
);
741 while (DECL_TEMPLATE_INFO (tpl
))
742 tpl
= DECL_TI_TEMPLATE (tpl
);
745 name
= DECL_NAME (name
);
748 if (LAMBDA_TYPE_P (t
))
750 /* A lambda's "type" is essentially its signature. */
751 pp_string (pp
, M_("<lambda"));
752 if (lambda_function (t
))
754 FUNCTION_FIRST_USER_PARMTYPE (lambda_function (t
)),
758 else if (!name
|| IDENTIFIER_ANON_P (name
))
760 if (flags
& TFF_CLASS_KEY_OR_ENUM
)
761 pp_string (pp
, M_("<unnamed>"));
763 pp_printf (pp
, M_("<unnamed %s>"), variety
);
766 pp_cxx_tree_identifier (pp
, name
);
769 dump_template_parms (pp
, TYPE_TEMPLATE_INFO (t
),
770 !CLASSTYPE_USE_TEMPLATE (t
),
771 flags
& ~TFF_TEMPLATE_HEADER
);
774 /* Dump into the obstack the initial part of the output for a given type.
775 This is necessary when dealing with things like functions returning
778 return type of `int (* fee ())()': pointer -> function -> int. Both
779 pointer (and reference and offset) and function (and member) types must
780 deal with prefix and suffix.
782 Arrays must also do this for DECL nodes, like int a[], and for things like
786 dump_type_prefix (cxx_pretty_printer
*pp
, tree t
, int flags
)
788 if (TYPE_PTRMEMFUNC_P (t
))
790 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
794 switch (TREE_CODE (t
))
799 tree sub
= TREE_TYPE (t
);
801 dump_type_prefix (pp
, sub
, flags
);
802 if (TREE_CODE (sub
) == ARRAY_TYPE
803 || TREE_CODE (sub
) == FUNCTION_TYPE
)
805 pp_cxx_whitespace (pp
);
806 pp_cxx_left_paren (pp
);
807 pp_c_attributes_display (pp
, TYPE_ATTRIBUTES (sub
));
811 else if (TYPE_REF_P (t
))
813 if (TYPE_REF_IS_RVALUE (t
))
814 pp_ampersand_ampersand (pp
);
818 pp
->padding
= pp_before
;
819 pp_cxx_cv_qualifier_seq (pp
, t
);
825 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
826 if (TREE_CODE (t
) == OFFSET_TYPE
) /* pmfs deal with this in d_t_p */
829 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
830 pp_cxx_left_paren (pp
);
831 dump_type (pp
, TYPE_OFFSET_BASETYPE (t
), flags
);
832 pp_cxx_colon_colon (pp
);
835 pp_cxx_cv_qualifier_seq (pp
, t
);
836 pp
->padding
= pp_before
;
839 /* This can be reached without a pointer when dealing with
840 templates, e.g. std::is_function. */
842 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
846 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
848 pp_cxx_left_paren (pp
);
849 dump_aggr_type (pp
, TYPE_METHOD_BASETYPE (t
), flags
);
850 pp_cxx_colon_colon (pp
);
854 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
858 case IDENTIFIER_NODE
:
863 case TEMPLATE_TYPE_PARM
:
864 case TEMPLATE_TEMPLATE_PARM
:
865 case BOUND_TEMPLATE_TEMPLATE_PARM
:
876 case UNDERLYING_TYPE
:
878 case TYPE_PACK_EXPANSION
:
879 case FIXED_POINT_TYPE
:
881 dump_type (pp
, t
, flags
);
882 pp
->padding
= pp_before
;
886 pp_unsupported_tree (pp
, t
);
889 pp_string (pp
, M_("<typeprefixerror>"));
894 /* Dump the suffix of type T, under control of FLAGS. This is the part
895 which appears after the identifier (or function parms). */
898 dump_type_suffix (cxx_pretty_printer
*pp
, tree t
, int flags
)
900 if (TYPE_PTRMEMFUNC_P (t
))
901 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
903 switch (TREE_CODE (t
))
908 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
909 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
910 pp_cxx_right_paren (pp
);
911 if (TREE_CODE (t
) == POINTER_TYPE
)
912 flags
|= TFF_POINTER
;
913 dump_type_suffix (pp
, TREE_TYPE (t
), flags
);
920 if (TREE_CODE (t
) == METHOD_TYPE
)
921 /* Can only be reached through a pointer. */
922 pp_cxx_right_paren (pp
);
923 arg
= TYPE_ARG_TYPES (t
);
924 if (TREE_CODE (t
) == METHOD_TYPE
)
925 arg
= TREE_CHAIN (arg
);
927 /* Function pointers don't have default args. Not in standard C++,
928 anyway; they may in g++, but we'll just pretend otherwise. */
929 dump_parameters (pp
, arg
, flags
& ~TFF_FUNCTION_DEFAULT_ARGUMENTS
);
931 pp
->padding
= pp_before
;
932 pp_cxx_cv_qualifiers (pp
, type_memfn_quals (t
),
933 TREE_CODE (t
) == FUNCTION_TYPE
934 && (flags
& TFF_POINTER
));
935 dump_ref_qualifier (pp
, t
, flags
);
936 if (tx_safe_fn_type_p (t
))
937 pp_cxx_ws_string (pp
, "transaction_safe");
938 dump_exception_spec (pp
, TYPE_RAISES_EXCEPTIONS (t
), flags
);
939 dump_type_suffix (pp
, TREE_TYPE (t
), flags
);
945 pp_cxx_left_bracket (pp
);
946 if (tree dtype
= TYPE_DOMAIN (t
))
948 tree max
= TYPE_MAX_VALUE (dtype
);
949 /* Zero-length arrays have an upper bound of SIZE_MAX. */
950 if (integer_all_onesp (max
))
951 pp_character (pp
, '0');
952 else if (tree_fits_shwi_p (max
))
953 pp_wide_integer (pp
, tree_to_shwi (max
) + 1);
957 if (TREE_CODE (max
) == SAVE_EXPR
)
958 max
= TREE_OPERAND (max
, 0);
959 if (TREE_CODE (max
) == MINUS_EXPR
960 || TREE_CODE (max
) == PLUS_EXPR
)
962 max
= TREE_OPERAND (max
, 0);
963 while (CONVERT_EXPR_P (max
))
964 max
= TREE_OPERAND (max
, 0);
967 max
= fold_build2_loc (input_location
,
968 PLUS_EXPR
, dtype
, max
,
969 build_int_cst (dtype
, 1));
970 dump_expr (pp
, max
, flags
& ~TFF_EXPR_IN_PARENS
);
973 pp_cxx_right_bracket (pp
);
974 dump_type_suffix (pp
, TREE_TYPE (t
), flags
);
978 case IDENTIFIER_NODE
:
983 case TEMPLATE_TYPE_PARM
:
984 case TEMPLATE_TEMPLATE_PARM
:
985 case BOUND_TEMPLATE_TEMPLATE_PARM
:
996 case UNDERLYING_TYPE
:
998 case TYPE_PACK_EXPANSION
:
999 case FIXED_POINT_TYPE
:
1004 pp_unsupported_tree (pp
, t
);
1006 /* Don't mark it here, we should have already done in
1007 dump_type_prefix. */
1013 dump_global_iord (cxx_pretty_printer
*pp
, tree t
)
1015 const char *p
= NULL
;
1017 if (DECL_GLOBAL_CTOR_P (t
))
1018 p
= M_("(static initializers for %s)");
1019 else if (DECL_GLOBAL_DTOR_P (t
))
1020 p
= M_("(static destructors for %s)");
1024 pp_printf (pp
, p
, DECL_SOURCE_FILE (t
));
1028 dump_simple_decl (cxx_pretty_printer
*pp
, tree t
, tree type
, int flags
)
1030 if (template_parm_object_p (t
))
1031 return dump_expr (pp
, DECL_INITIAL (t
), flags
);
1033 if (flags
& TFF_DECL_SPECIFIERS
)
1035 if (VAR_P (t
) && DECL_DECLARED_CONSTEXPR_P (t
))
1037 if (DECL_LANG_SPECIFIC (t
) && DECL_DECLARED_CONCEPT_P (t
))
1038 pp_cxx_ws_string (pp
, "concept");
1040 pp_cxx_ws_string (pp
, "constexpr");
1042 dump_type_prefix (pp
, type
, flags
& ~TFF_UNQUALIFIED_NAME
);
1043 pp_maybe_space (pp
);
1045 if (! (flags
& TFF_UNQUALIFIED_NAME
)
1046 && TREE_CODE (t
) != PARM_DECL
1047 && (!DECL_INITIAL (t
)
1048 || TREE_CODE (DECL_INITIAL (t
)) != TEMPLATE_PARM_INDEX
))
1049 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1050 flags
&= ~TFF_UNQUALIFIED_NAME
;
1051 if ((flags
& TFF_DECL_SPECIFIERS
)
1052 && DECL_TEMPLATE_PARM_P (t
)
1053 && TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (t
)))
1054 pp_string (pp
, "...");
1057 if (TREE_CODE (t
) == FIELD_DECL
&& DECL_NORMAL_CAPTURE_P (t
))
1060 pp_string (pp
, IDENTIFIER_POINTER (DECL_NAME (t
)) + 2);
1061 pp_string (pp
, " capture>");
1064 dump_decl (pp
, DECL_NAME (t
), flags
);
1066 else if (DECL_DECOMPOSITION_P (t
))
1067 pp_string (pp
, M_("<structured bindings>"));
1069 pp_string (pp
, M_("<anonymous>"));
1070 if (flags
& TFF_DECL_SPECIFIERS
)
1071 dump_type_suffix (pp
, type
, flags
);
1074 /* Print an IDENTIFIER_NODE that is the name of a declaration. */
1077 dump_decl_name (cxx_pretty_printer
*pp
, tree t
, int flags
)
1079 /* These special cases are duplicated here so that other functions
1080 can feed identifiers to error and get them demangled properly. */
1081 if (IDENTIFIER_CONV_OP_P (t
))
1083 pp_cxx_ws_string (pp
, "operator");
1084 /* Not exactly IDENTIFIER_TYPE_VALUE. */
1085 dump_type (pp
, TREE_TYPE (t
), flags
);
1088 if (dguide_name_p (t
))
1090 dump_decl (pp
, CLASSTYPE_TI_TEMPLATE (TREE_TYPE (t
)),
1091 TFF_UNQUALIFIED_NAME
);
1095 const char *str
= IDENTIFIER_POINTER (t
);
1096 if (!strncmp (str
, "_ZGR", 3))
1098 pp_cxx_ws_string (pp
, "<temporary>");
1102 pp_cxx_tree_identifier (pp
, t
);
1105 /* Dump a human readable string for the decl T under control of FLAGS. */
1108 dump_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
1113 /* If doing Objective-C++, give Objective-C a chance to demangle
1114 Objective-C method names. */
1115 if (c_dialect_objc ())
1117 const char *demangled
= objc_maybe_printable_name (t
, flags
);
1120 pp_string (pp
, demangled
);
1125 switch (TREE_CODE (t
))
1128 /* Don't say 'typedef class A' */
1129 if (DECL_ARTIFICIAL (t
) && !DECL_SELF_REFERENCE_P (t
))
1131 if ((flags
& TFF_DECL_SPECIFIERS
)
1132 && TREE_CODE (TREE_TYPE (t
)) == TEMPLATE_TYPE_PARM
)
1134 /* Say `class T' not just `T'. */
1135 pp_cxx_ws_string (pp
, "class");
1137 /* Emit the `...' for a parameter pack. */
1138 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t
)))
1139 pp_cxx_ws_string (pp
, "...");
1142 dump_type (pp
, TREE_TYPE (t
), flags
);
1145 if (TYPE_DECL_ALIAS_P (t
)
1146 && (flags
& TFF_DECL_SPECIFIERS
1147 || flags
& TFF_CLASS_KEY_OR_ENUM
))
1149 pp_cxx_ws_string (pp
, "using");
1150 dump_decl (pp
, DECL_NAME (t
), flags
);
1151 pp_cxx_whitespace (pp
);
1152 pp_cxx_ws_string (pp
, "=");
1153 pp_cxx_whitespace (pp
);
1154 dump_type (pp
, (DECL_ORIGINAL_TYPE (t
)
1155 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
)),
1159 if ((flags
& TFF_DECL_SPECIFIERS
)
1160 && !DECL_SELF_REFERENCE_P (t
))
1161 pp_cxx_ws_string (pp
, "typedef");
1162 dump_simple_decl (pp
, t
, DECL_ORIGINAL_TYPE (t
)
1163 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
),
1168 if (DECL_NAME (t
) && VTABLE_NAME_P (DECL_NAME (t
)))
1170 pp_string (pp
, M_("vtable for "));
1171 gcc_assert (TYPE_P (DECL_CONTEXT (t
)));
1172 dump_type (pp
, DECL_CONTEXT (t
), flags
);
1178 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1180 /* Handle variable template specializations. */
1182 && DECL_LANG_SPECIFIC (t
)
1183 && DECL_TEMPLATE_INFO (t
)
1184 && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t
)))
1186 pp_cxx_begin_template_argument_list (pp
);
1187 tree args
= INNERMOST_TEMPLATE_ARGS (DECL_TI_ARGS (t
));
1188 dump_template_argument_list (pp
, args
, flags
);
1189 pp_cxx_end_template_argument_list (pp
);
1194 pp_string (pp
, M_("<return value> "));
1195 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1198 case NAMESPACE_DECL
:
1199 if (flags
& TFF_DECL_SPECIFIERS
)
1200 pp
->declaration (t
);
1203 if (! (flags
& TFF_UNQUALIFIED_NAME
))
1204 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1205 flags
&= ~TFF_UNQUALIFIED_NAME
;
1206 if (DECL_NAME (t
) == NULL_TREE
)
1208 if (!(pp
->flags
& pp_c_flag_gnu_v3
))
1209 pp_cxx_ws_string (pp
, M_("{anonymous}"));
1211 pp_cxx_ws_string (pp
, M_("(anonymous namespace)"));
1214 pp_cxx_tree_identifier (pp
, DECL_NAME (t
));
1219 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
1220 pp_cxx_colon_colon (pp
);
1221 dump_decl (pp
, TREE_OPERAND (t
, 1), TFF_UNQUALIFIED_NAME
);
1225 dump_decl (pp
, TREE_OPERAND (t
, 0), flags
);
1226 pp_cxx_left_bracket (pp
);
1227 dump_decl (pp
, TREE_OPERAND (t
, 1), flags
);
1228 pp_cxx_right_bracket (pp
);
1231 /* So that we can do dump_decl on an aggr type. */
1235 dump_type (pp
, t
, flags
);
1239 /* This is a pseudo destructor call which has not been folded into
1240 a PSEUDO_DTOR_EXPR yet. */
1241 pp_cxx_complement (pp
);
1242 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
1249 case IDENTIFIER_NODE
:
1250 dump_decl_name (pp
, t
, flags
);
1254 if (!OVL_SINGLE_P (t
))
1256 tree ctx
= ovl_scope (t
);
1257 if (ctx
!= global_namespace
)
1260 dump_type (pp
, ctx
, flags
);
1262 dump_decl (pp
, ctx
, flags
);
1263 pp_cxx_colon_colon (pp
);
1265 dump_decl (pp
, OVL_NAME (t
), flags
);
1269 /* If there's only one function, just treat it like an ordinary
1275 if (! DECL_LANG_SPECIFIC (t
))
1277 if (DECL_ABSTRACT_ORIGIN (t
)
1278 && DECL_ABSTRACT_ORIGIN (t
) != t
)
1279 dump_decl (pp
, DECL_ABSTRACT_ORIGIN (t
), flags
);
1281 dump_function_name (pp
, t
, flags
);
1283 else if (DECL_GLOBAL_CTOR_P (t
) || DECL_GLOBAL_DTOR_P (t
))
1284 dump_global_iord (pp
, t
);
1286 dump_function_decl (pp
, t
, flags
);
1290 dump_template_decl (pp
, t
, flags
);
1294 pp_cxx_ws_string (pp
, "concept");
1295 dump_decl_name (pp
, DECL_NAME (t
), flags
);
1299 pp_string (pp
, "<wildcard>");
1302 case TEMPLATE_ID_EXPR
:
1304 tree name
= TREE_OPERAND (t
, 0);
1305 tree args
= TREE_OPERAND (t
, 1);
1307 if (!identifier_p (name
))
1308 name
= OVL_NAME (name
);
1309 dump_decl (pp
, name
, flags
);
1310 pp_cxx_begin_template_argument_list (pp
);
1311 if (args
== error_mark_node
)
1312 pp_string (pp
, M_("<template arguments error>"));
1314 dump_template_argument_list
1315 (pp
, args
, flags
|TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS
);
1316 pp_cxx_end_template_argument_list (pp
);
1321 pp_cxx_tree_identifier (pp
, DECL_NAME (t
));
1325 if ((TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == ENUMERAL_TYPE
)
1326 || (DECL_INITIAL (t
) &&
1327 TREE_CODE (DECL_INITIAL (t
)) == TEMPLATE_PARM_INDEX
))
1328 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1329 else if (DECL_NAME (t
))
1330 dump_decl (pp
, DECL_NAME (t
), flags
);
1331 else if (DECL_INITIAL (t
))
1332 dump_expr (pp
, DECL_INITIAL (t
), flags
| TFF_EXPR_IN_PARENS
);
1334 pp_string (pp
, M_("<enumerator>"));
1339 pp_cxx_ws_string (pp
, "using");
1340 tree scope
= USING_DECL_SCOPE (t
);
1341 bool variadic
= false;
1342 if (PACK_EXPANSION_P (scope
))
1344 scope
= PACK_EXPANSION_PATTERN (scope
);
1347 dump_type (pp
, scope
, flags
);
1348 pp_cxx_colon_colon (pp
);
1349 dump_decl (pp
, DECL_NAME (t
), flags
);
1351 pp_cxx_ws_string (pp
, "...");
1356 pp
->declaration (t
);
1360 dump_decl (pp
, BASELINK_FUNCTIONS (t
), flags
);
1363 case NON_DEPENDENT_EXPR
:
1364 dump_expr (pp
, t
, flags
);
1367 case TEMPLATE_TYPE_PARM
:
1368 if (flags
& TFF_DECL_SPECIFIERS
)
1369 pp
->declaration (t
);
1374 case UNBOUND_CLASS_TEMPLATE
:
1375 case TYPE_PACK_EXPANSION
:
1377 dump_type (pp
, t
, flags
);
1381 pp_unsupported_tree (pp
, t
);
1385 pp_string (pp
, M_("<declaration error>"));
1390 /* Dump a template declaration T under control of FLAGS. This means the
1391 'template <...> leaders plus the 'class X' or 'void fn(...)' part. */
1394 dump_template_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
1396 tree orig_parms
= DECL_TEMPLATE_PARMS (t
);
1400 if (flags
& TFF_TEMPLATE_HEADER
)
1402 for (parms
= orig_parms
= nreverse (orig_parms
);
1404 parms
= TREE_CHAIN (parms
))
1406 tree inner_parms
= INNERMOST_TEMPLATE_PARMS (parms
);
1407 int len
= TREE_VEC_LENGTH (inner_parms
);
1411 /* Skip over the dummy template levels of a template template
1413 gcc_assert (TREE_CODE (TREE_TYPE (t
)) == TEMPLATE_TEMPLATE_PARM
);
1417 pp_cxx_ws_string (pp
, "template");
1418 pp_cxx_begin_template_argument_list (pp
);
1420 /* If we've shown the template prefix, we'd better show the
1421 parameters' and decl's type too. */
1422 flags
|= TFF_DECL_SPECIFIERS
;
1424 for (i
= 0; i
< len
; i
++)
1427 pp_separate_with_comma (pp
);
1428 dump_template_parameter (pp
, TREE_VEC_ELT (inner_parms
, i
),
1431 pp_cxx_end_template_argument_list (pp
);
1432 pp_cxx_whitespace (pp
);
1434 nreverse(orig_parms
);
1436 if (DECL_TEMPLATE_TEMPLATE_PARM_P (t
))
1438 /* Say `template<arg> class TT' not just `template<arg> TT'. */
1439 pp_cxx_ws_string (pp
, "class");
1441 /* If this is a parameter pack, print the ellipsis. */
1442 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t
)))
1443 pp_cxx_ws_string (pp
, "...");
1446 /* Only print the requirements if we're also printing
1447 the template header. */
1449 if (tree ci
= get_constraints (t
))
1450 if (check_constraint_info (ci
))
1451 if (tree reqs
= CI_TEMPLATE_REQS (ci
))
1453 pp_cxx_requires_clause (pp
, reqs
);
1454 pp_cxx_whitespace (pp
);
1459 if (DECL_CLASS_TEMPLATE_P (t
))
1460 dump_type (pp
, TREE_TYPE (t
),
1461 ((flags
& ~TFF_CLASS_KEY_OR_ENUM
) | TFF_TEMPLATE_NAME
1462 | (flags
& TFF_DECL_SPECIFIERS
? TFF_CLASS_KEY_OR_ENUM
: 0)));
1463 else if (DECL_TEMPLATE_RESULT (t
)
1464 && (VAR_P (DECL_TEMPLATE_RESULT (t
))
1465 /* Alias template. */
1466 || DECL_TYPE_TEMPLATE_P (t
)
1467 /* Concept definition. &*/
1468 || TREE_CODE (DECL_TEMPLATE_RESULT (t
)) == CONCEPT_DECL
))
1469 dump_decl (pp
, DECL_TEMPLATE_RESULT (t
), flags
| TFF_TEMPLATE_NAME
);
1472 gcc_assert (TREE_TYPE (t
));
1473 switch (NEXT_CODE (t
))
1477 dump_function_decl (pp
, t
, flags
| TFF_TEMPLATE_NAME
);
1480 /* This case can occur with some invalid code. */
1481 dump_type (pp
, TREE_TYPE (t
),
1482 (flags
& ~TFF_CLASS_KEY_OR_ENUM
) | TFF_TEMPLATE_NAME
1483 | (flags
& TFF_DECL_SPECIFIERS
1484 ? TFF_CLASS_KEY_OR_ENUM
: 0));
1489 /* find_typenames looks through the type of the function template T
1490 and returns a vec containing any typedefs, decltypes or TYPENAME_TYPEs
1493 struct find_typenames_t
1495 hash_set
<tree
> *p_set
;
1496 vec
<tree
, va_gc
> *typenames
;
1500 find_typenames_r (tree
*tp
, int *walk_subtrees
, void *data
)
1502 struct find_typenames_t
*d
= (struct find_typenames_t
*)data
;
1503 tree mv
= NULL_TREE
;
1505 if (TYPE_P (*tp
) && is_typedef_decl (TYPE_NAME (*tp
)))
1506 /* Add the type of the typedef without any additional cv-quals. */
1507 mv
= TREE_TYPE (TYPE_NAME (*tp
));
1508 else if (TREE_CODE (*tp
) == TYPENAME_TYPE
1509 || TREE_CODE (*tp
) == DECLTYPE_TYPE
)
1510 /* Add the typename without any cv-qualifiers. */
1511 mv
= TYPE_MAIN_VARIANT (*tp
);
1513 if (PACK_EXPANSION_P (*tp
))
1515 /* Don't mess with parameter packs since we don't remember
1516 the pack expansion context for a particular typename. */
1517 *walk_subtrees
= false;
1521 if (mv
&& (mv
== *tp
|| !d
->p_set
->add (mv
)))
1522 vec_safe_push (d
->typenames
, mv
);
1524 /* Search into class template arguments, which cp_walk_subtrees
1526 if (CLASS_TYPE_P (*tp
) && CLASSTYPE_TEMPLATE_INFO (*tp
))
1527 cp_walk_tree (&CLASSTYPE_TI_ARGS (*tp
), find_typenames_r
,
1533 static vec
<tree
, va_gc
> *
1534 find_typenames (tree t
)
1536 struct find_typenames_t ft
;
1537 ft
.p_set
= new hash_set
<tree
>;
1538 ft
.typenames
= NULL
;
1539 cp_walk_tree (&TREE_TYPE (DECL_TEMPLATE_RESULT (t
)),
1540 find_typenames_r
, &ft
, ft
.p_set
);
1542 return ft
.typenames
;
1545 /* Output the "[with ...]" clause for a template instantiation T iff
1546 TEMPLATE_PARMS, TEMPLATE_ARGS and FLAGS are suitable. T may be NULL if
1547 formatting a deduction/substitution diagnostic rather than an
1551 dump_substitution (cxx_pretty_printer
*pp
,
1552 tree t
, tree template_parms
, tree template_args
,
1555 if (template_parms
!= NULL_TREE
&& template_args
!= NULL_TREE
1556 && !(flags
& TFF_NO_TEMPLATE_BINDINGS
))
1558 vec
<tree
, va_gc
> *typenames
= t
? find_typenames (t
) : NULL
;
1559 pp_cxx_whitespace (pp
);
1560 pp_cxx_left_bracket (pp
);
1561 pp
->translate_string ("with");
1562 pp_cxx_whitespace (pp
);
1563 dump_template_bindings (pp
, template_parms
, template_args
, typenames
);
1564 pp_cxx_right_bracket (pp
);
1568 /* Dump the lambda function FN including its 'mutable' qualifier and any
1569 template bindings. */
1572 dump_lambda_function (cxx_pretty_printer
*pp
,
1573 tree fn
, tree template_parms
, tree template_args
,
1576 /* A lambda's signature is essentially its "type". */
1577 dump_type (pp
, DECL_CONTEXT (fn
), flags
);
1578 if (!(TYPE_QUALS (class_of_this_parm (TREE_TYPE (fn
))) & TYPE_QUAL_CONST
))
1580 pp
->padding
= pp_before
;
1581 pp_c_ws_string (pp
, "mutable");
1583 dump_substitution (pp
, fn
, template_parms
, template_args
, flags
);
1586 /* Pretty print a function decl. There are several ways we want to print a
1587 function declaration. The TFF_ bits in FLAGS tells us how to behave.
1588 As error can only apply the '#' flag once to give 0 and 1 for V, there
1589 is %D which doesn't print the throw specs, and %F which does. */
1592 dump_function_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
1596 tree cname
= NULL_TREE
;
1597 tree template_args
= NULL_TREE
;
1598 tree template_parms
= NULL_TREE
;
1599 int show_return
= flags
& TFF_RETURN_TYPE
|| flags
& TFF_DECL_SPECIFIERS
;
1600 int do_outer_scope
= ! (flags
& TFF_UNQUALIFIED_NAME
);
1603 tree ret
= NULL_TREE
;
1605 flags
&= ~(TFF_UNQUALIFIED_NAME
| TFF_TEMPLATE_NAME
);
1606 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1607 t
= DECL_TEMPLATE_RESULT (t
);
1609 /* Save the exceptions, in case t is a specialization and we are
1610 emitting an error about incompatible specifications. */
1611 exceptions
= TYPE_RAISES_EXCEPTIONS (TREE_TYPE (t
));
1613 /* Likewise for the constexpr specifier, in case t is a specialization. */
1614 constexpr_p
= DECL_DECLARED_CONSTEXPR_P (t
);
1616 /* Pretty print template instantiations only. */
1617 if (DECL_USE_TEMPLATE (t
) && DECL_TEMPLATE_INFO (t
)
1618 && !(flags
& TFF_NO_TEMPLATE_BINDINGS
)
1619 && flag_pretty_templates
)
1623 template_args
= DECL_TI_ARGS (t
);
1624 tmpl
= most_general_template (t
);
1625 if (tmpl
&& TREE_CODE (tmpl
) == TEMPLATE_DECL
)
1627 template_parms
= DECL_TEMPLATE_PARMS (tmpl
);
1632 if (DECL_NAME (t
) && LAMBDA_FUNCTION_P (t
))
1633 return dump_lambda_function (pp
, t
, template_parms
, template_args
, flags
);
1635 fntype
= TREE_TYPE (t
);
1636 parmtypes
= FUNCTION_FIRST_USER_PARMTYPE (t
);
1638 if (DECL_CLASS_SCOPE_P (t
))
1639 cname
= DECL_CONTEXT (t
);
1640 /* This is for partially instantiated template methods. */
1641 else if (TREE_CODE (fntype
) == METHOD_TYPE
)
1642 cname
= TREE_TYPE (TREE_VALUE (parmtypes
));
1644 if (flags
& TFF_DECL_SPECIFIERS
)
1646 if (DECL_STATIC_FUNCTION_P (t
))
1647 pp_cxx_ws_string (pp
, "static");
1648 else if (DECL_VIRTUAL_P (t
))
1649 pp_cxx_ws_string (pp
, "virtual");
1653 if (DECL_DECLARED_CONCEPT_P (t
))
1654 pp_cxx_ws_string (pp
, "concept");
1655 else if (DECL_IMMEDIATE_FUNCTION_P (t
))
1656 pp_cxx_ws_string (pp
, "consteval");
1658 pp_cxx_ws_string (pp
, "constexpr");
1662 /* Print the return type? */
1664 show_return
= (!DECL_CONV_FN_P (t
) && !DECL_CONSTRUCTOR_P (t
)
1665 && !DECL_DESTRUCTOR_P (t
) && !deduction_guide_p (t
));
1668 ret
= fndecl_declared_return_type (t
);
1669 dump_type_prefix (pp
, ret
, flags
);
1672 /* Print the function name. */
1673 if (!do_outer_scope
)
1677 dump_type (pp
, cname
, flags
);
1678 pp_cxx_colon_colon (pp
);
1681 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1683 dump_function_name (pp
, t
, flags
);
1685 if (!(flags
& TFF_NO_FUNCTION_ARGUMENTS
))
1687 dump_parameters (pp
, parmtypes
, flags
);
1689 if (TREE_CODE (fntype
) == METHOD_TYPE
)
1691 pp
->padding
= pp_before
;
1692 pp_cxx_cv_qualifier_seq (pp
, class_of_this_parm (fntype
));
1693 dump_ref_qualifier (pp
, fntype
, flags
);
1696 if (tx_safe_fn_type_p (fntype
))
1698 pp
->padding
= pp_before
;
1699 pp_cxx_ws_string (pp
, "transaction_safe");
1702 if (flags
& TFF_EXCEPTION_SPECIFICATION
)
1704 pp
->padding
= pp_before
;
1705 dump_exception_spec (pp
, exceptions
, flags
);
1709 dump_type_suffix (pp
, ret
, flags
);
1710 else if (deduction_guide_p (t
))
1712 pp_cxx_ws_string (pp
, "->");
1713 dump_type (pp
, TREE_TYPE (TREE_TYPE (t
)), flags
);
1717 if (tree ci
= get_constraints (t
))
1718 if (tree reqs
= CI_DECLARATOR_REQS (ci
))
1719 pp_cxx_requires_clause (pp
, reqs
);
1721 dump_substitution (pp
, t
, template_parms
, template_args
, flags
);
1723 if (tree base
= DECL_INHERITED_CTOR_BASE (t
))
1725 pp_cxx_ws_string (pp
, "[inherited from");
1726 dump_type (pp
, base
, TFF_PLAIN_IDENTIFIER
);
1727 pp_character (pp
, ']');
1730 else if (template_args
)
1732 bool need_comma
= false;
1734 pp_cxx_begin_template_argument_list (pp
);
1735 template_args
= INNERMOST_TEMPLATE_ARGS (template_args
);
1736 for (i
= 0; i
< TREE_VEC_LENGTH (template_args
); ++i
)
1738 tree arg
= TREE_VEC_ELT (template_args
, i
);
1740 pp_separate_with_comma (pp
);
1741 if (ARGUMENT_PACK_P (arg
))
1742 pp_cxx_left_brace (pp
);
1743 dump_template_argument (pp
, arg
, TFF_PLAIN_IDENTIFIER
);
1744 if (ARGUMENT_PACK_P (arg
))
1745 pp_cxx_right_brace (pp
);
1748 pp_cxx_end_template_argument_list (pp
);
1752 /* Print a parameter list. If this is for a member function, the
1753 member object ptr (and any other hidden args) should have
1754 already been removed. */
1757 dump_parameters (cxx_pretty_printer
*pp
, tree parmtypes
, int flags
)
1760 flags
&= ~TFF_SCOPE
;
1761 pp_cxx_left_paren (pp
);
1763 for (first
= 1; parmtypes
!= void_list_node
;
1764 parmtypes
= TREE_CHAIN (parmtypes
))
1767 pp_separate_with_comma (pp
);
1771 pp_cxx_ws_string (pp
, "...");
1775 dump_type (pp
, TREE_VALUE (parmtypes
), flags
);
1777 if ((flags
& TFF_FUNCTION_DEFAULT_ARGUMENTS
) && TREE_PURPOSE (parmtypes
))
1779 pp_cxx_whitespace (pp
);
1781 pp_cxx_whitespace (pp
);
1782 dump_expr (pp
, TREE_PURPOSE (parmtypes
), flags
| TFF_EXPR_IN_PARENS
);
1786 pp_cxx_right_paren (pp
);
1789 /* Print ref-qualifier of a FUNCTION_TYPE or METHOD_TYPE. FLAGS are ignored. */
1792 dump_ref_qualifier (cxx_pretty_printer
*pp
, tree t
, int flags ATTRIBUTE_UNUSED
)
1794 if (FUNCTION_REF_QUALIFIED (t
))
1796 pp
->padding
= pp_before
;
1797 if (FUNCTION_RVALUE_QUALIFIED (t
))
1798 pp_cxx_ws_string (pp
, "&&");
1800 pp_cxx_ws_string (pp
, "&");
1804 /* Print an exception specification. T is the exception specification. */
1807 dump_exception_spec (cxx_pretty_printer
*pp
, tree t
, int flags
)
1809 if (t
&& TREE_PURPOSE (t
))
1811 pp_cxx_ws_string (pp
, "noexcept");
1812 if (!integer_onep (TREE_PURPOSE (t
)))
1814 pp_cxx_whitespace (pp
);
1815 pp_cxx_left_paren (pp
);
1816 if (DEFERRED_NOEXCEPT_SPEC_P (t
))
1817 pp_cxx_ws_string (pp
, "<uninstantiated>");
1819 dump_expr (pp
, TREE_PURPOSE (t
), flags
);
1820 pp_cxx_right_paren (pp
);
1825 pp_cxx_ws_string (pp
, "throw");
1826 pp_cxx_whitespace (pp
);
1827 pp_cxx_left_paren (pp
);
1828 if (TREE_VALUE (t
) != NULL_TREE
)
1831 dump_type (pp
, TREE_VALUE (t
), flags
);
1835 pp_separate_with_comma (pp
);
1837 pp_cxx_right_paren (pp
);
1841 /* Handle the function name for a FUNCTION_DECL node, grokking operators
1842 and destructors properly. */
1845 dump_function_name (cxx_pretty_printer
*pp
, tree t
, int flags
)
1847 tree name
= DECL_NAME (t
);
1849 /* We can get here with a decl that was synthesized by language-
1850 independent machinery (e.g. coverage.c) in which case it won't
1851 have a lang_specific structure attached and DECL_CONSTRUCTOR_P
1852 will crash. In this case it is safe just to print out the
1854 if (!DECL_LANG_SPECIFIC (t
))
1856 pp_cxx_tree_identifier (pp
, name
);
1860 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1861 t
= DECL_TEMPLATE_RESULT (t
);
1863 /* Don't let the user see __comp_ctor et al. */
1864 if (DECL_CONSTRUCTOR_P (t
)
1865 || DECL_DESTRUCTOR_P (t
))
1867 if (LAMBDA_TYPE_P (DECL_CONTEXT (t
)))
1868 name
= get_identifier ("<lambda>");
1869 else if (TYPE_UNNAMED_P (DECL_CONTEXT (t
)))
1870 name
= get_identifier ("<constructor>");
1872 name
= constructor_name (DECL_CONTEXT (t
));
1875 if (DECL_DESTRUCTOR_P (t
))
1877 pp_cxx_complement (pp
);
1878 dump_decl (pp
, name
, TFF_PLAIN_IDENTIFIER
);
1880 else if (DECL_CONV_FN_P (t
))
1882 /* This cannot use the hack that the operator's return
1883 type is stashed off of its name because it may be
1884 used for error reporting. In the case of conflicting
1885 declarations, both will have the same name, yet
1886 the types will be different, hence the TREE_TYPE field
1887 of the first name will be clobbered by the second. */
1888 pp_cxx_ws_string (pp
, "operator");
1889 dump_type (pp
, TREE_TYPE (TREE_TYPE (t
)), flags
);
1892 dump_decl (pp
, name
, flags
);
1894 if (DECL_TEMPLATE_INFO (t
)
1895 && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t
)
1896 && (TREE_CODE (DECL_TI_TEMPLATE (t
)) != TEMPLATE_DECL
1897 || PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t
))))
1898 dump_template_parms (pp
, DECL_TEMPLATE_INFO (t
), !DECL_USE_TEMPLATE (t
),
1902 /* Dump the template parameters from the template info INFO under control of
1903 FLAGS. PRIMARY indicates whether this is a primary template decl, or
1904 specialization (partial or complete). For partial specializations we show
1905 the specialized parameter values. For a primary template we show no
1909 dump_template_parms (cxx_pretty_printer
*pp
, tree info
,
1910 int primary
, int flags
)
1912 tree args
= info
? TI_ARGS (info
) : NULL_TREE
;
1914 if (primary
&& flags
& TFF_TEMPLATE_NAME
)
1916 flags
&= ~(TFF_CLASS_KEY_OR_ENUM
| TFF_TEMPLATE_NAME
);
1917 pp_cxx_begin_template_argument_list (pp
);
1919 /* Be careful only to print things when we have them, so as not
1920 to crash producing error messages. */
1921 if (args
&& !primary
)
1924 len
= get_non_default_template_args_count (args
, flags
);
1926 args
= INNERMOST_TEMPLATE_ARGS (args
);
1927 for (ix
= 0; ix
!= len
; ix
++)
1929 tree arg
= TREE_VEC_ELT (args
, ix
);
1931 /* Only print a comma if we know there is an argument coming. In
1932 the case of an empty template argument pack, no actual
1933 argument will be printed. */
1935 && (!ARGUMENT_PACK_P (arg
)
1936 || TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg
)) > 0))
1937 pp_separate_with_comma (pp
);
1940 pp_string (pp
, M_("<template parameter error>"));
1942 dump_template_argument (pp
, arg
, flags
);
1947 tree tpl
= TI_TEMPLATE (info
);
1948 tree parms
= DECL_TEMPLATE_PARMS (tpl
);
1951 parms
= TREE_CODE (parms
) == TREE_LIST
? TREE_VALUE (parms
) : NULL_TREE
;
1952 len
= parms
? TREE_VEC_LENGTH (parms
) : 0;
1954 for (ix
= 0; ix
!= len
; ix
++)
1958 if (TREE_VEC_ELT (parms
, ix
) == error_mark_node
)
1960 pp_string (pp
, M_("<template parameter error>"));
1964 parm
= TREE_VALUE (TREE_VEC_ELT (parms
, ix
));
1967 pp_separate_with_comma (pp
);
1969 dump_decl (pp
, parm
, flags
& ~TFF_DECL_SPECIFIERS
);
1972 pp_cxx_end_template_argument_list (pp
);
1975 /* Print out the arguments of CALL_EXPR T as a parenthesized list using
1976 flags FLAGS. Skip over the first argument if SKIPFIRST is true. */
1979 dump_call_expr_args (cxx_pretty_printer
*pp
, tree t
, int flags
, bool skipfirst
)
1982 call_expr_arg_iterator iter
;
1984 pp_cxx_left_paren (pp
);
1985 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, t
)
1991 dump_expr (pp
, arg
, flags
| TFF_EXPR_IN_PARENS
);
1992 if (more_call_expr_args_p (&iter
))
1993 pp_separate_with_comma (pp
);
1996 pp_cxx_right_paren (pp
);
1999 /* Print out the arguments of AGGR_INIT_EXPR T as a parenthesized list
2000 using flags FLAGS. Skip over the first argument if SKIPFIRST is
2004 dump_aggr_init_expr_args (cxx_pretty_printer
*pp
, tree t
, int flags
,
2008 aggr_init_expr_arg_iterator iter
;
2010 pp_cxx_left_paren (pp
);
2011 FOR_EACH_AGGR_INIT_EXPR_ARG (arg
, iter
, t
)
2017 dump_expr (pp
, arg
, flags
| TFF_EXPR_IN_PARENS
);
2018 if (more_aggr_init_expr_args_p (&iter
))
2019 pp_separate_with_comma (pp
);
2022 pp_cxx_right_paren (pp
);
2025 /* Print out a list of initializers (subr of dump_expr). */
2028 dump_expr_list (cxx_pretty_printer
*pp
, tree l
, int flags
)
2032 dump_expr (pp
, TREE_VALUE (l
), flags
| TFF_EXPR_IN_PARENS
);
2035 pp_separate_with_comma (pp
);
2039 /* Print out a vector of initializers (subr of dump_expr). */
2042 dump_expr_init_vec (cxx_pretty_printer
*pp
, vec
<constructor_elt
, va_gc
> *v
,
2045 unsigned HOST_WIDE_INT idx
;
2048 FOR_EACH_CONSTRUCTOR_VALUE (v
, idx
, value
)
2050 dump_expr (pp
, value
, flags
| TFF_EXPR_IN_PARENS
);
2051 if (idx
!= v
->length () - 1)
2052 pp_separate_with_comma (pp
);
2057 /* We've gotten an indirect REFERENCE (an OBJ_TYPE_REF) to a virtual
2058 function. Resolve it to a close relative -- in the sense of static
2059 type -- variant being overridden. That is close to what was written in
2060 the source code. Subroutine of dump_expr. */
2063 resolve_virtual_fun_from_obj_type_ref (tree ref
)
2065 tree obj_type
= TREE_TYPE (OBJ_TYPE_REF_OBJECT (ref
));
2066 HOST_WIDE_INT index
= tree_to_uhwi (OBJ_TYPE_REF_TOKEN (ref
));
2067 tree fun
= BINFO_VIRTUALS (TYPE_BINFO (TREE_TYPE (obj_type
)));
2070 fun
= TREE_CHAIN (fun
);
2071 index
-= (TARGET_VTABLE_USES_DESCRIPTORS
2072 ? TARGET_VTABLE_USES_DESCRIPTORS
: 1);
2078 /* Print out an expression E under control of FLAGS. */
2081 dump_expr (cxx_pretty_printer
*pp
, tree t
, int flags
)
2088 if (STATEMENT_CLASS_P (t
))
2090 pp_cxx_ws_string (pp
, M_("<statement>"));
2094 switch (TREE_CODE (t
))
2102 case NAMESPACE_DECL
:
2107 case IDENTIFIER_NODE
:
2108 dump_decl (pp
, t
, ((flags
& ~(TFF_DECL_SPECIFIERS
|TFF_RETURN_TYPE
2109 |TFF_TEMPLATE_HEADER
))
2110 | TFF_NO_TEMPLATE_BINDINGS
2111 | TFF_NO_FUNCTION_ARGUMENTS
));
2115 if (SSA_NAME_VAR (t
)
2116 && !DECL_ARTIFICIAL (SSA_NAME_VAR (t
)))
2117 dump_expr (pp
, SSA_NAME_VAR (t
), flags
);
2119 pp_cxx_ws_string (pp
, M_("<unknown>"));
2130 case USERDEF_LITERAL
:
2131 pp_cxx_userdef_literal (pp
, t
);
2135 /* While waiting for caret diagnostics, avoid printing
2136 __cxa_allocate_exception, __cxa_throw, and the like. */
2137 pp_cxx_ws_string (pp
, M_("<throw-expression>"));
2142 dump_type (pp
, PTRMEM_CST_CLASS (t
), flags
);
2143 pp_cxx_colon_colon (pp
);
2144 pp_cxx_tree_identifier (pp
, DECL_NAME (PTRMEM_CST_MEMBER (t
)));
2148 pp_cxx_left_paren (pp
);
2149 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2150 pp_separate_with_comma (pp
);
2151 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2152 pp_cxx_right_paren (pp
);
2157 pp_cxx_left_paren (pp
);
2158 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2159 pp_string (pp
, " ? ");
2160 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2161 pp_string (pp
, " : ");
2162 dump_expr (pp
, TREE_OPERAND (t
, 2), flags
| TFF_EXPR_IN_PARENS
);
2163 pp_cxx_right_paren (pp
);
2167 if (TREE_HAS_CONSTRUCTOR (t
))
2169 pp_cxx_ws_string (pp
, "new");
2170 pp_cxx_whitespace (pp
);
2171 dump_type (pp
, TREE_TYPE (TREE_TYPE (t
)), flags
);
2174 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2177 case AGGR_INIT_EXPR
:
2179 tree fn
= NULL_TREE
;
2181 if (TREE_CODE (AGGR_INIT_EXPR_FN (t
)) == ADDR_EXPR
)
2182 fn
= TREE_OPERAND (AGGR_INIT_EXPR_FN (t
), 0);
2184 if (fn
&& TREE_CODE (fn
) == FUNCTION_DECL
)
2186 if (DECL_CONSTRUCTOR_P (fn
))
2187 dump_type (pp
, DECL_CONTEXT (fn
), flags
);
2189 dump_decl (pp
, fn
, 0);
2192 dump_expr (pp
, AGGR_INIT_EXPR_FN (t
), 0);
2194 dump_aggr_init_expr_args (pp
, t
, flags
, true);
2199 tree fn
= CALL_EXPR_FN (t
);
2200 bool skipfirst
= false;
2202 /* Deal with internal functions. */
2203 if (fn
== NULL_TREE
)
2205 pp_string (pp
, internal_fn_name (CALL_EXPR_IFN (t
)));
2206 dump_call_expr_args (pp
, t
, flags
, skipfirst
);
2210 if (TREE_CODE (fn
) == ADDR_EXPR
)
2211 fn
= TREE_OPERAND (fn
, 0);
2213 /* Nobody is interested in seeing the guts of vcalls. */
2214 if (TREE_CODE (fn
) == OBJ_TYPE_REF
)
2215 fn
= resolve_virtual_fun_from_obj_type_ref (fn
);
2217 if (TREE_TYPE (fn
) != NULL_TREE
2218 && NEXT_CODE (fn
) == METHOD_TYPE
2219 && call_expr_nargs (t
))
2221 tree ob
= CALL_EXPR_ARG (t
, 0);
2222 if (TREE_CODE (ob
) == ADDR_EXPR
)
2224 dump_expr (pp
, TREE_OPERAND (ob
, 0),
2225 flags
| TFF_EXPR_IN_PARENS
);
2228 else if (!is_this_parameter (ob
))
2230 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2235 if (flag_sanitize
& SANITIZE_UNDEFINED
2236 && is_ubsan_builtin_p (fn
))
2238 pp_string (cxx_pp
, M_("<ubsan routine call>"));
2241 dump_expr (pp
, fn
, flags
| TFF_EXPR_IN_PARENS
);
2242 dump_call_expr_args (pp
, t
, flags
, skipfirst
);
2247 /* Note that this only works for G++ target exprs. If somebody
2248 builds a general TARGET_EXPR, there's no way to represent that
2249 it initializes anything other that the parameter slot for the
2250 default argument. Note we may have cleared out the first
2251 operand in expand_expr, so don't go killing ourselves. */
2252 if (TREE_OPERAND (t
, 1))
2253 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2256 case POINTER_PLUS_EXPR
:
2257 dump_binary_op (pp
, "+", t
, flags
);
2260 case POINTER_DIFF_EXPR
:
2261 dump_binary_op (pp
, "-", t
, flags
);
2266 dump_binary_op (pp
, OVL_OP_INFO (true, NOP_EXPR
)->name
, t
, flags
);
2272 case TRUNC_DIV_EXPR
:
2273 case TRUNC_MOD_EXPR
:
2281 case TRUTH_ANDIF_EXPR
:
2282 case TRUTH_ORIF_EXPR
:
2289 case SPACESHIP_EXPR
:
2290 case EXACT_DIV_EXPR
:
2291 dump_binary_op (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
, t
, flags
);
2295 case FLOOR_DIV_EXPR
:
2296 case ROUND_DIV_EXPR
:
2298 dump_binary_op (pp
, "/", t
, flags
);
2302 case FLOOR_MOD_EXPR
:
2303 case ROUND_MOD_EXPR
:
2304 dump_binary_op (pp
, "%", t
, flags
);
2309 tree ob
= TREE_OPERAND (t
, 0);
2310 if (INDIRECT_REF_P (ob
))
2312 ob
= TREE_OPERAND (ob
, 0);
2313 if (!is_this_parameter (ob
))
2315 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2316 if (TYPE_REF_P (TREE_TYPE (ob
)))
2324 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2325 if (TREE_CODE (ob
) != ARROW_EXPR
)
2328 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
& ~TFF_EXPR_IN_PARENS
);
2333 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2334 pp_cxx_left_bracket (pp
);
2335 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2336 pp_cxx_right_bracket (pp
);
2339 case UNARY_PLUS_EXPR
:
2340 dump_unary_op (pp
, "+", t
, flags
);
2344 if (TREE_CODE (TREE_OPERAND (t
, 0)) == FUNCTION_DECL
2345 || TREE_CODE (TREE_OPERAND (t
, 0)) == STRING_CST
2346 /* An ADDR_EXPR can have reference type. In that case, we
2347 shouldn't print the `&' doing so indicates to the user
2348 that the expression has pointer type. */
2350 && TYPE_REF_P (TREE_TYPE (t
))))
2351 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2352 else if (TREE_CODE (TREE_OPERAND (t
, 0)) == LABEL_DECL
)
2353 dump_unary_op (pp
, "&&", t
, flags
);
2355 dump_unary_op (pp
, "&", t
, flags
);
2359 if (TREE_HAS_CONSTRUCTOR (t
))
2361 t
= TREE_OPERAND (t
, 0);
2362 gcc_assert (TREE_CODE (t
) == CALL_EXPR
);
2363 dump_expr (pp
, CALL_EXPR_FN (t
), flags
| TFF_EXPR_IN_PARENS
);
2364 dump_call_expr_args (pp
, t
, flags
, true);
2368 if (TREE_OPERAND (t
,0) != NULL_TREE
2369 && TREE_TYPE (TREE_OPERAND (t
, 0))
2370 && NEXT_CODE (TREE_OPERAND (t
, 0)) == REFERENCE_TYPE
)
2371 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2373 dump_unary_op (pp
, "*", t
, flags
);
2378 if (TREE_CODE (TREE_OPERAND (t
, 0)) == ADDR_EXPR
2379 && integer_zerop (TREE_OPERAND (t
, 1)))
2380 dump_expr (pp
, TREE_OPERAND (TREE_OPERAND (t
, 0), 0), flags
);
2384 if (!integer_zerop (TREE_OPERAND (t
, 1)))
2386 pp_cxx_left_paren (pp
);
2387 if (!integer_onep (TYPE_SIZE_UNIT
2388 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (t
, 0))))))
2390 pp_cxx_left_paren (pp
);
2391 dump_type (pp
, ptr_type_node
, flags
);
2392 pp_cxx_right_paren (pp
);
2395 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2396 if (!integer_zerop (TREE_OPERAND (t
, 1)))
2398 pp_cxx_ws_string (pp
, "+");
2399 dump_expr (pp
, fold_convert (ssizetype
, TREE_OPERAND (t
, 1)),
2401 pp_cxx_right_paren (pp
);
2408 case TRUTH_NOT_EXPR
:
2409 case PREDECREMENT_EXPR
:
2410 case PREINCREMENT_EXPR
:
2411 dump_unary_op (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
, t
, flags
);
2414 case POSTDECREMENT_EXPR
:
2415 case POSTINCREMENT_EXPR
:
2416 pp_cxx_left_paren (pp
);
2417 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2418 pp_cxx_ws_string (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
);
2419 pp_cxx_right_paren (pp
);
2422 case NON_LVALUE_EXPR
:
2423 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
2424 should be another level of INDIRECT_REF so that I don't have to do
2426 if (TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == POINTER_TYPE
)
2428 tree next
= TREE_TYPE (TREE_TYPE (t
));
2430 while (TYPE_PTR_P (next
))
2431 next
= TREE_TYPE (next
);
2433 if (TREE_CODE (next
) == FUNCTION_TYPE
)
2435 if (flags
& TFF_EXPR_IN_PARENS
)
2436 pp_cxx_left_paren (pp
);
2438 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2439 if (flags
& TFF_EXPR_IN_PARENS
)
2440 pp_cxx_right_paren (pp
);
2443 /* Else fall through. */
2445 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2449 case IMPLICIT_CONV_EXPR
:
2450 case VIEW_CONVERT_EXPR
:
2452 tree op
= TREE_OPERAND (t
, 0);
2453 tree ttype
= TREE_TYPE (t
);
2454 tree optype
= TREE_TYPE (op
);
2456 if (TREE_CODE (ttype
) != TREE_CODE (optype
)
2457 && INDIRECT_TYPE_P (ttype
)
2458 && INDIRECT_TYPE_P (optype
)
2459 && same_type_p (TREE_TYPE (optype
),
2462 if (TYPE_REF_P (ttype
))
2465 if (TREE_CODE (op
) == ADDR_EXPR
)
2466 dump_expr (pp
, TREE_OPERAND (op
, 0), flags
);
2468 dump_unary_op (pp
, "*", t
, flags
);
2471 dump_unary_op (pp
, "&", t
, flags
);
2473 else if (!same_type_p (TREE_TYPE (op
), TREE_TYPE (t
)))
2475 /* It is a cast, but we cannot tell whether it is a
2476 reinterpret or static cast. Use the C style notation. */
2477 if (flags
& TFF_EXPR_IN_PARENS
)
2478 pp_cxx_left_paren (pp
);
2479 pp_cxx_left_paren (pp
);
2480 dump_type (pp
, TREE_TYPE (t
), flags
);
2481 pp_cxx_right_paren (pp
);
2482 dump_expr (pp
, op
, flags
| TFF_EXPR_IN_PARENS
);
2483 if (flags
& TFF_EXPR_IN_PARENS
)
2484 pp_cxx_right_paren (pp
);
2487 dump_expr (pp
, op
, flags
);
2492 if (TREE_TYPE (t
) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t
)))
2494 tree idx
= build_ptrmemfunc_access_expr (t
, pfn_identifier
);
2496 if (integer_zerop (idx
))
2498 /* A NULL pointer-to-member constant. */
2499 pp_cxx_left_paren (pp
);
2500 pp_cxx_left_paren (pp
);
2501 dump_type (pp
, TREE_TYPE (t
), flags
);
2502 pp_cxx_right_paren (pp
);
2503 pp_character (pp
, '0');
2504 pp_cxx_right_paren (pp
);
2507 else if (tree_fits_shwi_p (idx
))
2510 unsigned HOST_WIDE_INT n
;
2512 t
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t
)));
2513 t
= TYPE_METHOD_BASETYPE (t
);
2514 virtuals
= BINFO_VIRTUALS (TYPE_BINFO (TYPE_MAIN_VARIANT (t
)));
2516 n
= tree_to_shwi (idx
);
2518 /* Map vtable index back one, to allow for the null pointer to
2522 while (n
> 0 && virtuals
)
2525 virtuals
= TREE_CHAIN (virtuals
);
2529 dump_expr (pp
, BV_FN (virtuals
),
2530 flags
| TFF_EXPR_IN_PARENS
);
2535 if (TREE_TYPE (t
) && LAMBDA_TYPE_P (TREE_TYPE (t
)))
2536 pp_string (pp
, "<lambda closure object>");
2537 if (TREE_TYPE (t
) && EMPTY_CONSTRUCTOR_P (t
))
2539 dump_type (pp
, TREE_TYPE (t
), 0);
2540 pp_cxx_left_paren (pp
);
2541 pp_cxx_right_paren (pp
);
2545 if (!BRACE_ENCLOSED_INITIALIZER_P (t
))
2546 dump_type (pp
, TREE_TYPE (t
), 0);
2547 pp_cxx_left_brace (pp
);
2548 dump_expr_init_vec (pp
, CONSTRUCTOR_ELTS (t
), flags
);
2549 pp_cxx_right_brace (pp
);
2556 tree ob
= TREE_OPERAND (t
, 0);
2557 if (is_dummy_object (ob
))
2559 t
= TREE_OPERAND (t
, 1);
2560 if (TREE_CODE (t
) == FUNCTION_DECL
)
2562 dump_expr (pp
, t
, flags
| TFF_EXPR_IN_PARENS
);
2563 else if (BASELINK_P (t
))
2564 dump_expr (pp
, OVL_FIRST (BASELINK_FUNCTIONS (t
)),
2565 flags
| TFF_EXPR_IN_PARENS
);
2567 dump_decl (pp
, t
, flags
);
2571 if (INDIRECT_REF_P (ob
))
2573 dump_expr (pp
, TREE_OPERAND (ob
, 0), flags
| TFF_EXPR_IN_PARENS
);
2579 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2583 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2588 case TEMPLATE_PARM_INDEX
:
2589 dump_decl (pp
, TEMPLATE_PARM_DECL (t
), flags
& ~TFF_DECL_SPECIFIERS
);
2593 if (TREE_OPERAND (t
, 0) == NULL_TREE
2594 || TREE_CHAIN (TREE_OPERAND (t
, 0)))
2596 dump_type (pp
, TREE_TYPE (t
), flags
);
2597 pp_cxx_left_paren (pp
);
2598 dump_expr_list (pp
, TREE_OPERAND (t
, 0), flags
);
2599 pp_cxx_right_paren (pp
);
2603 pp_cxx_left_paren (pp
);
2604 dump_type (pp
, TREE_TYPE (t
), flags
);
2605 pp_cxx_right_paren (pp
);
2606 pp_cxx_left_paren (pp
);
2607 dump_expr_list (pp
, TREE_OPERAND (t
, 0), flags
);
2608 pp_cxx_right_paren (pp
);
2612 case STATIC_CAST_EXPR
:
2613 pp_cxx_ws_string (pp
, "static_cast");
2615 case REINTERPRET_CAST_EXPR
:
2616 pp_cxx_ws_string (pp
, "reinterpret_cast");
2618 case CONST_CAST_EXPR
:
2619 pp_cxx_ws_string (pp
, "const_cast");
2621 case DYNAMIC_CAST_EXPR
:
2622 pp_cxx_ws_string (pp
, "dynamic_cast");
2624 pp_cxx_begin_template_argument_list (pp
);
2625 dump_type (pp
, TREE_TYPE (t
), flags
);
2626 pp_cxx_end_template_argument_list (pp
);
2627 pp_cxx_left_paren (pp
);
2628 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2629 pp_cxx_right_paren (pp
);
2633 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2639 if (TREE_CODE (t
) == SIZEOF_EXPR
)
2640 pp_cxx_ws_string (pp
, "sizeof");
2643 gcc_assert (TREE_CODE (t
) == ALIGNOF_EXPR
);
2644 pp_cxx_ws_string (pp
, "__alignof__");
2646 op
= TREE_OPERAND (t
, 0);
2647 if (PACK_EXPANSION_P (op
))
2649 pp_string (pp
, "...");
2650 op
= PACK_EXPANSION_PATTERN (op
);
2652 pp_cxx_whitespace (pp
);
2653 pp_cxx_left_paren (pp
);
2654 if (TREE_CODE (t
) == SIZEOF_EXPR
&& SIZEOF_EXPR_TYPE_P (t
))
2655 dump_type (pp
, TREE_TYPE (op
), flags
);
2656 else if (TYPE_P (TREE_OPERAND (t
, 0)))
2657 dump_type (pp
, op
, flags
);
2659 dump_expr (pp
, op
, flags
);
2660 pp_cxx_right_paren (pp
);
2663 case AT_ENCODE_EXPR
:
2664 pp_cxx_ws_string (pp
, "@encode");
2665 pp_cxx_whitespace (pp
);
2666 pp_cxx_left_paren (pp
);
2667 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
2668 pp_cxx_right_paren (pp
);
2672 pp_cxx_ws_string (pp
, "noexcept");
2673 pp_cxx_whitespace (pp
);
2674 pp_cxx_left_paren (pp
);
2675 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2676 pp_cxx_right_paren (pp
);
2681 pp_cxx_ws_string (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
);
2682 pp_cxx_whitespace (pp
);
2683 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2686 case DEFERRED_PARSE
:
2687 pp_string (pp
, M_("<unparsed>"));
2690 case TRY_CATCH_EXPR
:
2691 case CLEANUP_POINT_EXPR
:
2692 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2695 case PSEUDO_DTOR_EXPR
:
2696 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2698 if (TREE_OPERAND (t
, 1))
2700 dump_type (pp
, TREE_OPERAND (t
, 1), flags
);
2701 pp_cxx_colon_colon (pp
);
2703 pp_cxx_complement (pp
);
2704 dump_type (pp
, TREE_OPERAND (t
, 2), flags
);
2707 case TEMPLATE_ID_EXPR
:
2708 dump_decl (pp
, t
, flags
);
2714 case STATEMENT_LIST
:
2715 /* We don't yet have a way of dumping statements in a
2716 human-readable format. */
2717 pp_string (pp
, "({...})");
2721 pp_string (pp
, "while (1) { ");
2722 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2723 pp_cxx_right_brace (pp
);
2727 pp_string (pp
, "if (");
2728 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2729 pp_string (pp
, ") break; ");
2733 dump_expr (pp
, BASELINK_FUNCTIONS (t
), flags
& ~TFF_EXPR_IN_PARENS
);
2736 case EMPTY_CLASS_EXPR
:
2737 dump_type (pp
, TREE_TYPE (t
), flags
);
2738 pp_cxx_left_paren (pp
);
2739 pp_cxx_right_paren (pp
);
2742 case NON_DEPENDENT_EXPR
:
2743 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2746 case ARGUMENT_PACK_SELECT
:
2747 dump_template_argument (pp
, ARGUMENT_PACK_SELECT_FROM_PACK (t
), flags
);
2760 pp_type_specifier_seq (pp
, t
);
2764 /* We get here when we want to print a dependent type as an
2765 id-expression, without any disambiguator decoration. */
2766 pp
->id_expression (t
);
2769 case TEMPLATE_TYPE_PARM
:
2770 case TEMPLATE_TEMPLATE_PARM
:
2771 case BOUND_TEMPLATE_TEMPLATE_PARM
:
2772 dump_type (pp
, t
, flags
);
2776 pp_cxx_trait_expression (pp
, t
);
2780 pp_cxx_va_arg_expression (pp
, t
);
2784 pp_cxx_offsetof_expression (pp
, t
);
2787 case ADDRESSOF_EXPR
:
2788 pp_cxx_addressof_expression (pp
, t
);
2792 dump_decl (pp
, t
, flags
);
2795 case EXPR_PACK_EXPANSION
:
2796 case UNARY_LEFT_FOLD_EXPR
:
2797 case UNARY_RIGHT_FOLD_EXPR
:
2798 case BINARY_LEFT_FOLD_EXPR
:
2799 case BINARY_RIGHT_FOLD_EXPR
:
2806 case VEC_DELETE_EXPR
:
2813 case UNORDERED_EXPR
:
2823 case FIX_TRUNC_EXPR
:
2828 case TRUTH_AND_EXPR
:
2830 case TRUTH_XOR_EXPR
:
2831 if (flags
& TFF_EXPR_IN_PARENS
)
2832 pp_cxx_left_paren (pp
);
2834 if (flags
& TFF_EXPR_IN_PARENS
)
2835 pp_cxx_right_paren (pp
);
2839 dump_expr (pp
, resolve_virtual_fun_from_obj_type_ref (t
), flags
);
2843 pp_string (pp
, M_("<lambda>"));
2847 pp_cxx_left_paren (pp
);
2848 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2849 pp_cxx_right_paren (pp
);
2853 pp_cxx_requires_expr (cxx_pp
, t
);
2857 pp_cxx_simple_requirement (cxx_pp
, t
);
2861 pp_cxx_type_requirement (cxx_pp
, t
);
2865 pp_cxx_compound_requirement (cxx_pp
, t
);
2869 pp_cxx_nested_requirement (cxx_pp
, t
);
2877 pp_cxx_constraint (cxx_pp
, t
);
2881 case PLACEHOLDER_EXPR
:
2882 pp_string (pp
, M_("*this"));
2886 dump_expr_list (pp
, t
, flags
);
2889 /* This list is incomplete, but should suffice for now.
2890 It is very important that `sorry' does not call
2891 `report_error_function'. That could cause an infinite loop. */
2893 pp_unsupported_tree (pp
, t
);
2896 pp_string (pp
, M_("<expression error>"));
2902 dump_binary_op (cxx_pretty_printer
*pp
, const char *opstring
, tree t
,
2905 pp_cxx_left_paren (pp
);
2906 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2907 pp_cxx_whitespace (pp
);
2909 pp_cxx_ws_string (pp
, opstring
);
2911 pp_string (pp
, M_("<unknown operator>"));
2912 pp_cxx_whitespace (pp
);
2913 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2914 pp_cxx_right_paren (pp
);
2918 dump_unary_op (cxx_pretty_printer
*pp
, const char *opstring
, tree t
, int flags
)
2920 if (flags
& TFF_EXPR_IN_PARENS
)
2921 pp_cxx_left_paren (pp
);
2922 pp_cxx_ws_string (pp
, opstring
);
2923 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2924 if (flags
& TFF_EXPR_IN_PARENS
)
2925 pp_cxx_right_paren (pp
);
2929 reinit_cxx_pp (void)
2931 pp_clear_output_area (cxx_pp
);
2932 cxx_pp
->padding
= pp_none
;
2933 pp_indentation (cxx_pp
) = 0;
2934 pp_needs_newline (cxx_pp
) = false;
2935 cxx_pp
->enclosing_scope
= current_function_decl
;
2938 /* Same as pp_formatted_text, except the return string is a separate
2939 copy and has a GGC storage duration, e.g. an indefinite lifetime. */
2942 pp_ggc_formatted_text (pretty_printer
*pp
)
2944 return ggc_strdup (pp_formatted_text (pp
));
2947 /* Exported interface to stringifying types, exprs and decls under TFF_*
2951 type_as_string (tree typ
, int flags
)
2954 pp_translate_identifiers (cxx_pp
) = false;
2955 dump_type (cxx_pp
, typ
, flags
);
2956 return pp_ggc_formatted_text (cxx_pp
);
2960 type_as_string_translate (tree typ
, int flags
)
2963 dump_type (cxx_pp
, typ
, flags
);
2964 return pp_ggc_formatted_text (cxx_pp
);
2968 expr_as_string (tree decl
, int flags
)
2971 pp_translate_identifiers (cxx_pp
) = false;
2972 dump_expr (cxx_pp
, decl
, flags
);
2973 return pp_ggc_formatted_text (cxx_pp
);
2976 /* Wrap decl_as_string with options appropriate for dwarf. */
2979 decl_as_dwarf_string (tree decl
, int flags
)
2982 /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag
2983 here will be adequate to get the desired behavior. */
2984 cxx_pp
->flags
|= pp_c_flag_gnu_v3
;
2985 name
= decl_as_string (decl
, flags
);
2986 /* Subsequent calls to the pretty printer shouldn't use this style. */
2987 cxx_pp
->flags
&= ~pp_c_flag_gnu_v3
;
2992 decl_as_string (tree decl
, int flags
)
2995 pp_translate_identifiers (cxx_pp
) = false;
2996 dump_decl (cxx_pp
, decl
, flags
);
2997 return pp_ggc_formatted_text (cxx_pp
);
3001 decl_as_string_translate (tree decl
, int flags
)
3004 dump_decl (cxx_pp
, decl
, flags
);
3005 return pp_ggc_formatted_text (cxx_pp
);
3008 /* Wrap lang_decl_name with options appropriate for dwarf. */
3011 lang_decl_dwarf_name (tree decl
, int v
, bool translate
)
3014 /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag
3015 here will be adequate to get the desired behavior. */
3016 cxx_pp
->flags
|= pp_c_flag_gnu_v3
;
3017 name
= lang_decl_name (decl
, v
, translate
);
3018 /* Subsequent calls to the pretty printer shouldn't use this style. */
3019 cxx_pp
->flags
&= ~pp_c_flag_gnu_v3
;
3023 /* Generate the three forms of printable names for cxx_printable_name. */
3026 lang_decl_name (tree decl
, int v
, bool translate
)
3030 ? decl_as_string_translate (decl
, TFF_DECL_SPECIFIERS
)
3031 : decl_as_string (decl
, TFF_DECL_SPECIFIERS
));
3034 pp_translate_identifiers (cxx_pp
) = translate
;
3036 && (DECL_CLASS_SCOPE_P (decl
)
3037 || (DECL_NAMESPACE_SCOPE_P (decl
)
3038 && CP_DECL_CONTEXT (decl
) != global_namespace
)))
3040 dump_type (cxx_pp
, CP_DECL_CONTEXT (decl
), TFF_PLAIN_IDENTIFIER
);
3041 pp_cxx_colon_colon (cxx_pp
);
3044 if (TREE_CODE (decl
) == FUNCTION_DECL
)
3045 dump_function_name (cxx_pp
, decl
, TFF_PLAIN_IDENTIFIER
);
3046 else if ((DECL_NAME (decl
) == NULL_TREE
)
3047 && TREE_CODE (decl
) == NAMESPACE_DECL
)
3048 dump_decl (cxx_pp
, decl
, TFF_PLAIN_IDENTIFIER
| TFF_UNQUALIFIED_NAME
);
3050 dump_decl (cxx_pp
, DECL_NAME (decl
), TFF_PLAIN_IDENTIFIER
);
3052 return pp_ggc_formatted_text (cxx_pp
);
3055 /* Return the location of a tree passed to %+ formats. */
3058 location_of (tree t
)
3062 t
= TYPE_MAIN_DECL (t
);
3064 return input_location
;
3066 else if (TREE_CODE (t
) == OVERLOAD
)
3070 return DECL_SOURCE_LOCATION (t
);
3071 if (TREE_CODE (t
) == DEFERRED_PARSE
)
3072 return defparse_location (t
);
3073 return cp_expr_loc_or_input_loc (t
);
3076 /* Now the interfaces from error et al to dump_type et al. Each takes an
3077 on/off VERBOSE flag and supply the appropriate TFF_ flags to a dump_
3081 decl_to_string (tree decl
, int verbose
)
3085 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == RECORD_TYPE
3086 || TREE_CODE (decl
) == UNION_TYPE
|| TREE_CODE (decl
) == ENUMERAL_TYPE
)
3087 flags
= TFF_CLASS_KEY_OR_ENUM
;
3089 flags
|= TFF_DECL_SPECIFIERS
;
3090 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
3091 flags
|= TFF_DECL_SPECIFIERS
| TFF_RETURN_TYPE
;
3092 flags
|= TFF_TEMPLATE_HEADER
;
3095 dump_decl (cxx_pp
, decl
, flags
);
3096 return pp_ggc_formatted_text (cxx_pp
);
3100 expr_to_string (tree decl
)
3103 dump_expr (cxx_pp
, decl
, 0);
3104 return pp_ggc_formatted_text (cxx_pp
);
3108 fndecl_to_string (tree fndecl
, int verbose
)
3112 flags
= TFF_EXCEPTION_SPECIFICATION
| TFF_DECL_SPECIFIERS
3113 | TFF_TEMPLATE_HEADER
;
3115 flags
|= TFF_FUNCTION_DEFAULT_ARGUMENTS
;
3117 dump_decl (cxx_pp
, fndecl
, flags
);
3118 return pp_ggc_formatted_text (cxx_pp
);
3123 code_to_string (enum tree_code c
)
3125 return get_tree_code_name (c
);
3129 language_to_string (enum languages c
)
3136 case lang_cplusplus
:
3145 /* Return the proper printed version of a parameter to a C++ function. */
3148 parm_to_string (int p
)
3152 pp_string (cxx_pp
, "'this'");
3154 pp_decimal_int (cxx_pp
, p
+ 1);
3155 return pp_ggc_formatted_text (cxx_pp
);
3159 op_to_string (bool assop
, enum tree_code p
)
3161 tree id
= ovl_op_identifier (assop
, p
);
3162 return id
? IDENTIFIER_POINTER (id
) : M_("<unknown>");
3165 /* Return a GC-allocated representation of type TYP, with verbosity VERBOSE.
3167 If QUOTE is non-NULL and if *QUOTE is true, then quotes are added to the
3168 string in appropriate places, and *QUOTE is written to with false
3169 to suppress pp_format's trailing close quote so that e.g.
3170 foo_typedef {aka underlying_foo} {enum}
3171 can be printed by "%qT" as:
3172 `foo_typedef' {aka `underlying_foo'} {enum}
3174 `foo_typedef {aka underlying_foo} {enum}'
3175 When adding such quotes, if POSTPROCESSED is true (for handling %H and %I)
3176 then a leading open quote will be added, whereas if POSTPROCESSED is false
3177 (for handling %T) then any leading quote has already been added by
3178 pp_format, or is not needed due to QUOTE being NULL (for template arguments
3181 SHOW_COLOR is used to determine the colorization of any quotes that
3185 type_to_string (tree typ
, int verbose
, bool postprocessed
, bool *quote
,
3190 flags
|= TFF_CLASS_KEY_OR_ENUM
;
3191 flags
|= TFF_TEMPLATE_HEADER
;
3195 if (postprocessed
&& quote
&& *quote
)
3196 pp_begin_quote (cxx_pp
, show_color
);
3198 struct obstack
*ob
= pp_buffer (cxx_pp
)->obstack
;
3199 int type_start
, type_len
;
3200 type_start
= obstack_object_size (ob
);
3202 dump_type (cxx_pp
, typ
, flags
);
3204 /* Remember the end of the initial dump. */
3205 type_len
= obstack_object_size (ob
) - type_start
;
3207 /* If we're printing a type that involves typedefs, also print the
3208 stripped version. But sometimes the stripped version looks
3209 exactly the same, so we don't want it after all. To avoid printing
3210 it in that case, we play ugly obstack games. */
3211 if (typ
&& TYPE_P (typ
) && typ
!= TYPE_CANONICAL (typ
)
3212 && !uses_template_parms (typ
))
3214 int aka_start
, aka_len
; char *p
;
3215 tree aka
= strip_typedefs (typ
, NULL
, STF_USER_VISIBLE
);
3216 if (quote
&& *quote
)
3217 pp_end_quote (cxx_pp
, show_color
);
3218 pp_string (cxx_pp
, " {aka");
3219 pp_cxx_whitespace (cxx_pp
);
3220 if (quote
&& *quote
)
3221 pp_begin_quote (cxx_pp
, show_color
);
3222 /* And remember the start of the aka dump. */
3223 aka_start
= obstack_object_size (ob
);
3224 dump_type (cxx_pp
, aka
, flags
);
3225 aka_len
= obstack_object_size (ob
) - aka_start
;
3226 if (quote
&& *quote
)
3227 pp_end_quote (cxx_pp
, show_color
);
3228 pp_right_brace (cxx_pp
);
3229 p
= (char*)obstack_base (ob
);
3230 /* If they are identical, cut off the aka by unwinding the obstack. */
3231 if (type_len
== aka_len
3232 && memcmp (p
+ type_start
, p
+aka_start
, type_len
) == 0)
3234 /* We can't add a '\0' here, since we may be adding a closing quote
3235 below, and it would be hidden by the '\0'.
3236 Instead, manually unwind the current object within the obstack
3237 so that the insertion point is at the end of the type, before
3239 int delta
= type_start
+ type_len
- obstack_object_size (ob
);
3240 gcc_assert (delta
<= 0);
3241 obstack_blank_fast (ob
, delta
);
3245 /* No further closing quotes are needed. */
3249 if (quote
&& *quote
)
3251 pp_end_quote (cxx_pp
, show_color
);
3254 return pp_ggc_formatted_text (cxx_pp
);
3258 args_to_string (tree p
, int verbose
)
3262 flags
|= TFF_CLASS_KEY_OR_ENUM
;
3267 if (TYPE_P (TREE_VALUE (p
)))
3268 return type_as_string_translate (p
, flags
);
3271 for (; p
; p
= TREE_CHAIN (p
))
3273 if (null_node_p (TREE_VALUE (p
)))
3274 pp_cxx_ws_string (cxx_pp
, "NULL");
3276 dump_type (cxx_pp
, error_type (TREE_VALUE (p
)), flags
);
3278 pp_separate_with_comma (cxx_pp
);
3280 return pp_ggc_formatted_text (cxx_pp
);
3283 /* Pretty-print a deduction substitution (from deduction_tsubst_fntype). P
3284 is a TREE_LIST with purpose the TEMPLATE_DECL, value the template
3288 subst_to_string (tree p
)
3290 tree decl
= TREE_PURPOSE (p
);
3291 tree targs
= TREE_VALUE (p
);
3292 tree tparms
= DECL_TEMPLATE_PARMS (decl
);
3293 int flags
= (TFF_DECL_SPECIFIERS
|TFF_TEMPLATE_HEADER
3294 |TFF_NO_TEMPLATE_BINDINGS
);
3300 dump_template_decl (cxx_pp
, TREE_PURPOSE (p
), flags
);
3301 dump_substitution (cxx_pp
, NULL
, tparms
, targs
, /*flags=*/0);
3302 return pp_ggc_formatted_text (cxx_pp
);
3306 cv_to_string (tree p
, int v
)
3309 cxx_pp
->padding
= v
? pp_before
: pp_none
;
3310 pp_cxx_cv_qualifier_seq (cxx_pp
, p
);
3311 return pp_ggc_formatted_text (cxx_pp
);
3315 eh_spec_to_string (tree p
, int /*v*/)
3319 dump_exception_spec (cxx_pp
, p
, flags
);
3320 return pp_ggc_formatted_text (cxx_pp
);
3323 /* Langhook for print_error_function. */
3325 cxx_print_error_function (diagnostic_context
*context
, const char *file
,
3326 diagnostic_info
*diagnostic
)
3330 prefix
= xstrdup (file
);
3333 lhd_print_error_function (context
, file
, diagnostic
);
3334 pp_set_prefix (context
->printer
, prefix
);
3335 maybe_print_instantiation_context (context
);
3339 cp_diagnostic_starter (diagnostic_context
*context
,
3340 diagnostic_info
*diagnostic
)
3342 diagnostic_report_current_module (context
, diagnostic_location (diagnostic
));
3343 cp_print_error_function (context
, diagnostic
);
3344 maybe_print_instantiation_context (context
);
3345 maybe_print_constexpr_context (context
);
3346 maybe_print_constraint_context (context
);
3347 pp_set_prefix (context
->printer
, diagnostic_build_prefix (context
,
3351 /* Print current function onto BUFFER, in the process of reporting
3352 a diagnostic message. Called from cp_diagnostic_starter. */
3354 cp_print_error_function (diagnostic_context
*context
,
3355 diagnostic_info
*diagnostic
)
3357 /* If we are in an instantiation context, current_function_decl is likely
3358 to be wrong, so just rely on print_instantiation_full_context. */
3359 if (current_instantiation ())
3361 /* The above is true for constraint satisfaction also. */
3362 if (current_failed_constraint
)
3364 if (diagnostic_last_function_changed (context
, diagnostic
))
3366 char *old_prefix
= pp_take_prefix (context
->printer
);
3367 const char *file
= LOCATION_FILE (diagnostic_location (diagnostic
));
3368 tree abstract_origin
= diagnostic_abstract_origin (diagnostic
);
3369 char *new_prefix
= (file
&& abstract_origin
== NULL
)
3370 ? file_name_as_prefix (context
, file
) : NULL
;
3372 pp_set_prefix (context
->printer
, new_prefix
);
3374 if (current_function_decl
== NULL
)
3375 pp_string (context
->printer
, _("At global scope:"));
3380 if (abstract_origin
)
3382 ao
= BLOCK_ABSTRACT_ORIGIN (abstract_origin
);
3383 gcc_assert (TREE_CODE (ao
) == FUNCTION_DECL
);
3387 fndecl
= current_function_decl
;
3389 pp_printf (context
->printer
, function_category (fndecl
),
3390 cxx_printable_name_translate (fndecl
, 2));
3392 while (abstract_origin
)
3395 tree block
= abstract_origin
;
3397 locus
= &BLOCK_SOURCE_LOCATION (block
);
3399 block
= BLOCK_SUPERCONTEXT (block
);
3400 while (block
&& TREE_CODE (block
) == BLOCK
3401 && BLOCK_ABSTRACT_ORIGIN (block
))
3403 ao
= BLOCK_ABSTRACT_ORIGIN (block
);
3404 if (TREE_CODE (ao
) == FUNCTION_DECL
)
3409 else if (TREE_CODE (ao
) != BLOCK
)
3412 block
= BLOCK_SUPERCONTEXT (block
);
3415 abstract_origin
= block
;
3418 while (block
&& TREE_CODE (block
) == BLOCK
)
3419 block
= BLOCK_SUPERCONTEXT (block
);
3421 if (block
&& TREE_CODE (block
) == FUNCTION_DECL
)
3423 abstract_origin
= NULL
;
3427 expanded_location s
= expand_location (*locus
);
3428 pp_character (context
->printer
, ',');
3429 pp_newline (context
->printer
);
3432 if (context
->show_column
&& s
.column
!= 0)
3433 pp_printf (context
->printer
,
3434 _(" inlined from %qs at %r%s:%d:%d%R"),
3435 cxx_printable_name_translate (fndecl
, 2),
3436 "locus", s
.file
, s
.line
, s
.column
);
3438 pp_printf (context
->printer
,
3439 _(" inlined from %qs at %r%s:%d%R"),
3440 cxx_printable_name_translate (fndecl
, 2),
3441 "locus", s
.file
, s
.line
);
3445 pp_printf (context
->printer
, _(" inlined from %qs"),
3446 cxx_printable_name_translate (fndecl
, 2));
3449 pp_character (context
->printer
, ':');
3451 pp_newline (context
->printer
);
3453 diagnostic_set_last_function (context
, diagnostic
);
3454 pp_destroy_prefix (context
->printer
);
3455 context
->printer
->prefix
= old_prefix
;
3459 /* Returns a description of FUNCTION using standard terminology. The
3460 result is a format string of the form "In CATEGORY %qs". */
3462 function_category (tree fn
)
3464 /* We can get called from the middle-end for diagnostics of function
3465 clones. Make sure we have language specific information before
3466 dereferencing it. */
3467 if (DECL_LANG_SPECIFIC (STRIP_TEMPLATE (fn
))
3468 && DECL_FUNCTION_MEMBER_P (fn
))
3470 if (DECL_STATIC_FUNCTION_P (fn
))
3471 return _("In static member function %qs");
3472 else if (DECL_COPY_CONSTRUCTOR_P (fn
))
3473 return _("In copy constructor %qs");
3474 else if (DECL_CONSTRUCTOR_P (fn
))
3475 return _("In constructor %qs");
3476 else if (DECL_DESTRUCTOR_P (fn
))
3477 return _("In destructor %qs");
3478 else if (LAMBDA_FUNCTION_P (fn
))
3479 return _("In lambda function");
3481 return _("In member function %qs");
3484 return _("In function %qs");
3487 /* Report the full context of a current template instantiation,
3490 print_instantiation_full_context (diagnostic_context
*context
)
3492 struct tinst_level
*p
= current_instantiation ();
3493 location_t location
= input_location
;
3497 pp_verbatim (context
->printer
,
3499 ? _("%s: In substitution of %qS:\n")
3500 : _("%s: In instantiation of %q#D:\n"),
3501 LOCATION_FILE (location
),
3504 location
= p
->locus
;
3508 print_instantiation_partial_context (context
, p
, location
);
3511 /* Helper function of print_instantiation_partial_context() that
3512 prints a single line of instantiation context. */
3515 print_instantiation_partial_context_line (diagnostic_context
*context
,
3516 struct tinst_level
*t
,
3517 location_t loc
, bool recursive_p
)
3519 if (loc
== UNKNOWN_LOCATION
)
3522 expanded_location xloc
= expand_location (loc
);
3524 if (context
->show_column
)
3525 pp_verbatim (context
->printer
, _("%r%s:%d:%d:%R "),
3526 "locus", xloc
.file
, xloc
.line
, xloc
.column
);
3528 pp_verbatim (context
->printer
, _("%r%s:%d:%R "),
3529 "locus", xloc
.file
, xloc
.line
);
3534 pp_verbatim (context
->printer
,
3536 ? _("recursively required by substitution of %qS\n")
3537 : _("required by substitution of %qS\n"),
3540 pp_verbatim (context
->printer
,
3542 ? _("recursively required from %q#D\n")
3543 : _("required from %q#D\n"),
3548 pp_verbatim (context
->printer
,
3550 ? _("recursively required from here\n")
3551 : _("required from here\n"));
3555 /* Same as print_instantiation_full_context but less verbose. */
3558 print_instantiation_partial_context (diagnostic_context
*context
,
3559 struct tinst_level
*t0
, location_t loc
)
3561 struct tinst_level
*t
;
3564 location_t prev_loc
= loc
;
3566 for (t
= t0
; t
!= NULL
; t
= t
->next
)
3567 if (prev_loc
!= t
->locus
)
3569 prev_loc
= t
->locus
;
3575 if (template_backtrace_limit
3576 && n_total
> template_backtrace_limit
)
3578 int skip
= n_total
- template_backtrace_limit
;
3579 int head
= template_backtrace_limit
/ 2;
3581 /* Avoid skipping just 1. If so, skip 2. */
3585 head
= (template_backtrace_limit
- 1) / 2;
3588 for (n
= 0; n
< head
; n
++)
3590 gcc_assert (t
!= NULL
);
3591 if (loc
!= t
->locus
)
3592 print_instantiation_partial_context_line (context
, t
, loc
,
3593 /*recursive_p=*/false);
3597 if (t
!= NULL
&& skip
> 0)
3599 expanded_location xloc
;
3600 xloc
= expand_location (loc
);
3601 if (context
->show_column
)
3602 pp_verbatim (context
->printer
,
3603 _("%r%s:%d:%d:%R [ skipping %d instantiation "
3604 "contexts, use -ftemplate-backtrace-limit=0 to "
3606 "locus", xloc
.file
, xloc
.line
, xloc
.column
, skip
);
3608 pp_verbatim (context
->printer
,
3609 _("%r%s:%d:%R [ skipping %d instantiation "
3610 "contexts, use -ftemplate-backtrace-limit=0 to "
3612 "locus", xloc
.file
, xloc
.line
, skip
);
3617 } while (t
!= NULL
&& --skip
> 0);
3623 while (t
->next
!= NULL
&& t
->locus
== t
->next
->locus
)
3628 print_instantiation_partial_context_line (context
, t
, loc
,
3633 print_instantiation_partial_context_line (context
, NULL
, loc
,
3634 /*recursive_p=*/false);
3637 /* Called from cp_thing to print the template context for an error. */
3639 maybe_print_instantiation_context (diagnostic_context
*context
)
3641 if (!problematic_instantiation_changed () || current_instantiation () == 0)
3644 record_last_problematic_instantiation ();
3645 print_instantiation_full_context (context
);
3648 /* Report what constexpr call(s) we're trying to expand, if any. */
3651 maybe_print_constexpr_context (diagnostic_context
*context
)
3653 vec
<tree
> call_stack
= cx_error_context ();
3657 FOR_EACH_VEC_ELT (call_stack
, ix
, t
)
3659 expanded_location xloc
= expand_location (EXPR_LOCATION (t
));
3660 const char *s
= expr_as_string (t
, 0);
3661 if (context
->show_column
)
3662 pp_verbatim (context
->printer
,
3663 _("%r%s:%d:%d:%R in %<constexpr%> expansion of %qs"),
3664 "locus", xloc
.file
, xloc
.line
, xloc
.column
, s
);
3666 pp_verbatim (context
->printer
,
3667 _("%r%s:%d:%R in %<constexpr%> expansion of %qs"),
3668 "locus", xloc
.file
, xloc
.line
, s
);
3669 pp_newline (context
->printer
);
3675 print_location (diagnostic_context
*context
, location_t loc
)
3677 expanded_location xloc
= expand_location (loc
);
3678 if (context
->show_column
)
3679 pp_verbatim (context
->printer
, _("%r%s:%d:%d:%R "),
3680 "locus", xloc
.file
, xloc
.line
, xloc
.column
);
3682 pp_verbatim (context
->printer
, _("%r%s:%d:%R "),
3683 "locus", xloc
.file
, xloc
.line
);
3686 /* Instantiate the concept check for the purpose of diagnosing an error. */
3689 rebuild_concept_check (tree expr
, tree map
, tree args
)
3691 /* Instantiate the parameter mapping for the template-id. */
3692 map
= tsubst_parameter_mapping (map
, args
, tf_none
, NULL_TREE
);
3693 if (map
== error_mark_node
)
3694 return error_mark_node
;
3695 args
= get_mapped_args (map
);
3697 /* Rebuild the template id using substituted arguments. Substituting
3698 directly through the expression will trigger recursive satisfaction,
3699 so don't do that. */
3700 tree id
= unpack_concept_check (expr
);
3701 args
= tsubst_template_args (TREE_OPERAND (id
, 1), args
, tf_none
, NULL_TREE
);
3702 if (args
== error_mark_node
)
3703 return error_mark_node
;
3704 return build_nt (TEMPLATE_ID_EXPR
, TREE_OPERAND (id
, 0), args
);
3708 print_constrained_decl_info (diagnostic_context
*context
, tree decl
)
3710 print_location (context
, DECL_SOURCE_LOCATION (decl
));
3711 pp_verbatim (context
->printer
, "required by the constraints of %q#D\n", decl
);
3715 print_concept_check_info (diagnostic_context
*context
, tree expr
, tree map
, tree args
)
3717 gcc_assert (concept_check_p (expr
));
3719 tree id
= unpack_concept_check (expr
);
3720 tree tmpl
= TREE_OPERAND (id
, 0);
3722 tmpl
= OVL_FIRST (tmpl
);
3723 tree check
= rebuild_concept_check (expr
, map
, args
);
3724 if (check
== error_mark_node
)
3727 print_location (context
, DECL_SOURCE_LOCATION (tmpl
));
3728 pp_verbatim (context
->printer
, "required for the satisfaction of %qE\n", check
);
3731 /* Diagnose the entry point into the satisfaction error. Returns the next
3735 print_constraint_context_head (diagnostic_context
*context
, tree cxt
, tree args
)
3737 tree src
= TREE_VALUE (cxt
);
3740 print_location (context
, input_location
);
3741 pp_verbatim (context
->printer
, "required for constraint satisfaction\n");
3746 print_constrained_decl_info (context
, src
);
3751 print_concept_check_info (context
, src
, TREE_PURPOSE (cxt
), args
);
3752 return TREE_CHAIN (cxt
);
3757 print_requires_expression_info (diagnostic_context
*context
, tree constr
, tree args
)
3760 tree expr
= ATOMIC_CONSTR_EXPR (constr
);
3761 tree map
= ATOMIC_CONSTR_MAP (constr
);
3762 map
= tsubst_parameter_mapping (map
, args
, tf_none
, NULL_TREE
);
3763 if (map
== error_mark_node
)
3765 args
= get_mapped_args (map
);
3767 print_location (context
, cp_expr_loc_or_input_loc (expr
));
3768 pp_verbatim (context
->printer
, "in requirements ");
3770 tree parms
= TREE_OPERAND (expr
, 0);
3772 pp_verbatim (context
->printer
, "with ");
3775 tree next
= TREE_CHAIN (parms
);
3777 TREE_CHAIN (parms
) = NULL_TREE
;
3779 tree p
= tsubst (parms
, args
, tf_none
, NULL_TREE
);
3780 pp_verbatim (context
->printer
, "%q#D", p
);
3781 TREE_CHAIN (parms
) = next
;
3784 pp_separate_with_comma ((cxx_pretty_printer
*)context
->printer
);
3789 pp_verbatim (context
->printer
, "\n");
3793 maybe_print_single_constraint_context (diagnostic_context
*context
, tree failed
)
3798 tree constr
= TREE_VALUE (failed
);
3799 if (!constr
|| constr
== error_mark_node
)
3801 tree cxt
= CONSTR_CONTEXT (constr
);
3804 tree args
= TREE_PURPOSE (failed
);
3806 /* Print the stack of requirements. */
3807 cxt
= print_constraint_context_head (context
, cxt
, args
);
3808 while (cxt
&& !DECL_P (TREE_VALUE (cxt
)))
3810 tree expr
= TREE_VALUE (cxt
);
3811 tree map
= TREE_PURPOSE (cxt
);
3812 print_concept_check_info (context
, expr
, map
, args
);
3813 cxt
= TREE_CHAIN (cxt
);
3816 /* For certain constraints, we can provide additional context. */
3817 if (TREE_CODE (constr
) == ATOMIC_CONSTR
3818 && TREE_CODE (ATOMIC_CONSTR_EXPR (constr
)) == REQUIRES_EXPR
)
3819 print_requires_expression_info (context
, constr
, args
);
3823 maybe_print_constraint_context (diagnostic_context
*context
)
3825 if (!current_failed_constraint
)
3828 tree cur
= current_failed_constraint
;
3830 /* Recursively print nested contexts. */
3831 current_failed_constraint
= TREE_CHAIN (current_failed_constraint
);
3832 if (current_failed_constraint
)
3833 maybe_print_constraint_context (context
);
3835 /* Print this context. */
3836 maybe_print_single_constraint_context (context
, cur
);
3839 /* Return true iff TYPE_A and TYPE_B are template types that are
3840 meaningful to compare. */
3843 comparable_template_types_p (tree type_a
, tree type_b
)
3845 if (!CLASS_TYPE_P (type_a
))
3847 if (!CLASS_TYPE_P (type_b
))
3850 tree tinfo_a
= TYPE_TEMPLATE_INFO (type_a
);
3851 tree tinfo_b
= TYPE_TEMPLATE_INFO (type_b
);
3852 if (!tinfo_a
|| !tinfo_b
)
3855 return TI_TEMPLATE (tinfo_a
) == TI_TEMPLATE (tinfo_b
);
3858 /* Start a new line indented by SPC spaces on PP. */
3861 newline_and_indent (pretty_printer
*pp
, int spc
)
3864 for (int i
= 0; i
< spc
; i
++)
3868 /* Generate a GC-allocated string for ARG, an expression or type. */
3871 arg_to_string (tree arg
, bool verbose
)
3874 return type_to_string (arg
, verbose
, true, NULL
, false);
3876 return expr_to_string (arg
);
3879 /* Subroutine to type_to_string_with_compare and
3880 print_template_tree_comparison.
3882 Print a representation of ARG (an expression or type) to PP,
3883 colorizing it as "type-diff" if PP->show_color. */
3886 print_nonequal_arg (pretty_printer
*pp
, tree arg
, bool verbose
)
3888 pp_printf (pp
, "%r%s%R",
3891 ? arg_to_string (arg
, verbose
)
3892 : G_("(no argument)")));
3895 /* Recursively print template TYPE_A to PP, as compared to template TYPE_B.
3897 The types must satisfy comparable_template_types_p.
3899 If INDENT is 0, then this is equivalent to type_to_string (TYPE_A), but
3900 potentially colorizing/eliding in comparison with TYPE_B.
3902 For example given types:
3903 vector<map<int,double>>
3905 vector<map<int,float>>
3906 then the result on PP would be:
3907 vector<map<[...],double>>
3908 with type elision, and:
3909 vector<map<int,double>>
3910 without type elision.
3912 In both cases the parts of TYPE that differ from PEER will be colorized
3913 if pp_show_color (pp) is true. In the above example, this would be
3916 If INDENT is non-zero, then the types are printed in a tree-like form
3917 which shows both types. In the above example, the result on PP would be:
3924 and without type-elision would be:
3931 As before, the differing parts of the types are colorized if
3932 pp_show_color (pp) is true ("double" and "float" in this example).
3934 Template arguments in which both types are using the default arguments
3935 are not printed; if at least one of the two types is using a non-default
3936 argument, then that argument is printed (or both arguments for the
3937 tree-like print format). */
3940 print_template_differences (pretty_printer
*pp
, tree type_a
, tree type_b
,
3941 bool verbose
, int indent
)
3944 newline_and_indent (pp
, indent
);
3946 tree tinfo_a
= TYPE_TEMPLATE_INFO (type_a
);
3947 tree tinfo_b
= TYPE_TEMPLATE_INFO (type_b
);
3949 pp_printf (pp
, "%s<",
3950 IDENTIFIER_POINTER (DECL_NAME (TI_TEMPLATE (tinfo_a
))));
3952 tree args_a
= TI_ARGS (tinfo_a
);
3953 tree args_b
= TI_ARGS (tinfo_b
);
3954 gcc_assert (TREE_CODE (args_a
) == TREE_VEC
);
3955 gcc_assert (TREE_CODE (args_b
) == TREE_VEC
);
3957 int len_a
= get_non_default_template_args_count (args_a
, flags
);
3958 args_a
= INNERMOST_TEMPLATE_ARGS (args_a
);
3959 int len_b
= get_non_default_template_args_count (args_b
, flags
);
3960 args_b
= INNERMOST_TEMPLATE_ARGS (args_b
);
3961 /* Determine the maximum range of args for which non-default template args
3962 were used; beyond this, only default args (if any) were used, and so
3963 they will be equal from this point onwards.
3964 One of the two peers might have used default arguments within this
3965 range, but the other will be using non-default arguments, and so
3966 it's more readable to print both within this range, to highlight
3968 int len_max
= MAX (len_a
, len_b
);
3969 gcc_assert (TREE_CODE (args_a
) == TREE_VEC
);
3970 gcc_assert (TREE_CODE (args_b
) == TREE_VEC
);
3971 for (int idx
= 0; idx
< len_max
; idx
++)
3974 pp_character (pp
, ',');
3976 tree arg_a
= TREE_VEC_ELT (args_a
, idx
);
3977 tree arg_b
= TREE_VEC_ELT (args_b
, idx
);
3981 newline_and_indent (pp
, indent
+ 2);
3982 /* Can do elision here, printing "[...]". */
3983 if (flag_elide_type
)
3984 pp_string (pp
, G_("[...]"));
3986 pp_string (pp
, arg_to_string (arg_a
, verbose
));
3990 int new_indent
= indent
? indent
+ 2 : 0;
3991 if (comparable_template_types_p (arg_a
, arg_b
))
3992 print_template_differences (pp
, arg_a
, arg_b
, verbose
, new_indent
);
3996 newline_and_indent (pp
, indent
+ 2);
3997 pp_character (pp
, '[');
3998 print_nonequal_arg (pp
, arg_a
, verbose
);
3999 pp_string (pp
, " != ");
4000 print_nonequal_arg (pp
, arg_b
, verbose
);
4001 pp_character (pp
, ']');
4004 print_nonequal_arg (pp
, arg_a
, verbose
);
4007 pp_printf (pp
, ">");
4010 /* As type_to_string, but for a template, potentially colorizing/eliding
4011 in comparison with PEER.
4012 For example, if TYPE is map<int,double> and PEER is map<int,int>,
4013 then the resulting string would be:
4015 with type elision, and:
4017 without type elision.
4019 In both cases the parts of TYPE that differ from PEER will be colorized
4020 if SHOW_COLOR is true. In the above example, this would be "double".
4022 Template arguments in which both types are using the default arguments
4023 are not printed; if at least one of the two types is using a non-default
4024 argument, then both arguments are printed.
4026 The resulting string is in a GC-allocated buffer. */
4029 type_to_string_with_compare (tree type
, tree peer
, bool verbose
,
4032 pretty_printer inner_pp
;
4033 pretty_printer
*pp
= &inner_pp
;
4034 pp_show_color (pp
) = show_color
;
4036 print_template_differences (pp
, type
, peer
, verbose
, 0);
4037 return pp_ggc_formatted_text (pp
);
4040 /* Recursively print a tree-like comparison of TYPE_A and TYPE_B to PP,
4041 indented by INDENT spaces.
4043 For example given types:
4045 vector<map<int,double>>
4049 vector<map<double,float>>
4051 the output with type elision would be:
4058 and without type-elision would be:
4065 TYPE_A and TYPE_B must both be comparable template types
4066 (as per comparable_template_types_p).
4068 Template arguments in which both types are using the default arguments
4069 are not printed; if at least one of the two types is using a non-default
4070 argument, then both arguments are printed. */
4073 print_template_tree_comparison (pretty_printer
*pp
, tree type_a
, tree type_b
,
4074 bool verbose
, int indent
)
4076 print_template_differences (pp
, type_a
, type_b
, verbose
, indent
);
4079 /* Subroutine for use in a format_postprocessor::handle
4080 implementation. Adds a chunk to the end of
4081 formatted output, so that it will be printed
4082 by pp_output_formatted_text. */
4085 append_formatted_chunk (pretty_printer
*pp
, const char *content
)
4087 output_buffer
*buffer
= pp_buffer (pp
);
4088 struct chunk_info
*chunk_array
= buffer
->cur_chunk_array
;
4089 const char **args
= chunk_array
->args
;
4091 unsigned int chunk_idx
;
4092 for (chunk_idx
= 0; args
[chunk_idx
]; chunk_idx
++)
4094 args
[chunk_idx
++] = content
;
4095 args
[chunk_idx
] = NULL
;
4098 /* Create a copy of CONTENT, with quotes added, and,
4099 potentially, with colorization.
4100 No escaped is performed on CONTENT.
4101 The result is in a GC-allocated buffer. */
4104 add_quotes (const char *content
, bool show_color
)
4106 pretty_printer tmp_pp
;
4107 pp_show_color (&tmp_pp
) = show_color
;
4109 /* We have to use "%<%s%>" rather than "%qs" here in order to avoid
4110 quoting colorization bytes within the results. */
4111 pp_printf (&tmp_pp
, "%<%s%>", content
);
4113 return pp_ggc_formatted_text (&tmp_pp
);
4116 /* If we had %H and %I, and hence deferred printing them,
4117 print them now, storing the result into the chunk_info
4118 for pp_format. Quote them if 'q' was provided.
4119 Also print the difference in tree form, adding it as
4120 an additional chunk. */
4123 cxx_format_postprocessor::handle (pretty_printer
*pp
)
4125 /* If we have one of %H and %I, the other should have
4127 if (m_type_a
.m_tree
|| m_type_b
.m_tree
)
4129 /* Avoid reentrancy issues by working with a copy of
4130 m_type_a and m_type_b, resetting them now. */
4131 deferred_printed_type type_a
= m_type_a
;
4132 deferred_printed_type type_b
= m_type_b
;
4133 m_type_a
= deferred_printed_type ();
4134 m_type_b
= deferred_printed_type ();
4136 gcc_assert (type_a
.m_buffer_ptr
);
4137 gcc_assert (type_b
.m_buffer_ptr
);
4139 bool show_color
= pp_show_color (pp
);
4141 const char *type_a_text
;
4142 const char *type_b_text
;
4144 if (comparable_template_types_p (type_a
.m_tree
, type_b
.m_tree
))
4147 = type_to_string_with_compare (type_a
.m_tree
, type_b
.m_tree
,
4148 type_a
.m_verbose
, show_color
);
4150 = type_to_string_with_compare (type_b
.m_tree
, type_a
.m_tree
,
4151 type_b
.m_verbose
, show_color
);
4153 if (flag_diagnostics_show_template_tree
)
4155 pretty_printer inner_pp
;
4156 pp_show_color (&inner_pp
) = pp_show_color (pp
);
4157 print_template_tree_comparison
4158 (&inner_pp
, type_a
.m_tree
, type_b
.m_tree
, type_a
.m_verbose
, 2);
4159 append_formatted_chunk (pp
, pp_ggc_formatted_text (&inner_pp
));
4164 /* If the types were not comparable (or if only one of %H/%I was
4165 provided), they are printed normally, and no difference tree
4167 type_a_text
= type_to_string (type_a
.m_tree
, type_a
.m_verbose
,
4168 true, &type_a
.m_quote
, show_color
);
4169 type_b_text
= type_to_string (type_b
.m_tree
, type_b
.m_verbose
,
4170 true, &type_b
.m_quote
, show_color
);
4174 type_a_text
= add_quotes (type_a_text
, show_color
);
4175 *type_a
.m_buffer_ptr
= type_a_text
;
4178 type_b_text
= add_quotes (type_b_text
, show_color
);
4179 *type_b
.m_buffer_ptr
= type_b_text
;
4183 /* Subroutine for handling %H and %I, to support i18n of messages like:
4185 error_at (loc, "could not convert %qE from %qH to %qI",
4186 expr, type_a, type_b);
4188 so that we can print things like:
4190 could not convert 'foo' from 'map<int,double>' to 'map<int,int>'
4192 and, with type-elision:
4194 could not convert 'foo' from 'map<[...],double>' to 'map<[...],int>'
4196 (with color-coding of the differences between the types).
4198 The %H and %I format codes are peers: both must be present,
4199 and they affect each other. Hence to handle them, we must
4200 delay printing until we have both, deferring the printing to
4201 pretty_printer's m_format_postprocessor hook.
4203 This is called in phase 2 of pp_format, when it is accumulating
4204 a series of formatted chunks. We stash the location of the chunk
4205 we're meant to have written to, so that we can write to it in the
4206 m_format_postprocessor hook.
4208 We also need to stash whether a 'q' prefix was provided (the QUOTE
4209 param) so that we can add the quotes when writing out the delayed
4213 defer_phase_2_of_type_diff (deferred_printed_type
*deferred
,
4214 tree type
, const char **buffer_ptr
,
4215 bool verbose
, bool quote
)
4217 gcc_assert (deferred
->m_tree
== NULL_TREE
);
4218 gcc_assert (deferred
->m_buffer_ptr
== NULL
);
4219 *deferred
= deferred_printed_type (type
, buffer_ptr
, verbose
, quote
);
4223 /* Called from output_format -- during diagnostic message processing --
4224 to handle C++ specific format specifier with the following meanings:
4225 %A function argument-list.
4229 %F function declaration.
4231 %H type difference (from).
4232 %I type difference (to).
4234 %L language as used in extern "lang".
4236 %P function parameter whose position is indicated by an integer.
4237 %Q assignment operator.
4238 %S substitution (template + args)
4241 %X exception-specification. */
4243 cp_printer (pretty_printer
*pp
, text_info
*text
, const char *spec
,
4244 int precision
, bool wide
, bool set_locus
, bool verbose
,
4245 bool *quoted
, const char **buffer_ptr
)
4247 gcc_assert (pp
->m_format_postprocessor
);
4248 cxx_format_postprocessor
*postprocessor
4249 = static_cast <cxx_format_postprocessor
*> (pp
->m_format_postprocessor
);
4253 #define next_tree (t = va_arg (*text->args_ptr, tree))
4254 #define next_tcode ((enum tree_code) va_arg (*text->args_ptr, int))
4255 #define next_lang ((enum languages) va_arg (*text->args_ptr, int))
4256 #define next_int va_arg (*text->args_ptr, int)
4258 if (precision
!= 0 || wide
)
4263 case 'A': result
= args_to_string (next_tree
, verbose
); break;
4264 case 'C': result
= code_to_string (next_tcode
); break;
4267 tree temp
= next_tree
;
4269 && DECL_HAS_DEBUG_EXPR_P (temp
))
4271 temp
= DECL_DEBUG_EXPR (temp
);
4274 result
= expr_to_string (temp
);
4278 result
= decl_to_string (temp
, verbose
);
4281 case 'E': result
= expr_to_string (next_tree
); break;
4282 case 'F': result
= fndecl_to_string (next_tree
, verbose
); break;
4284 percent_G_format (text
);
4287 defer_phase_2_of_type_diff (&postprocessor
->m_type_a
, next_tree
,
4288 buffer_ptr
, verbose
, *quoted
);
4291 defer_phase_2_of_type_diff (&postprocessor
->m_type_b
, next_tree
,
4292 buffer_ptr
, verbose
, *quoted
);
4295 t
= va_arg (*text
->args_ptr
, tree
);
4296 percent_K_format (text
, EXPR_LOCATION (t
), TREE_BLOCK (t
));
4298 case 'L': result
= language_to_string (next_lang
); break;
4299 case 'O': result
= op_to_string (false, next_tcode
); break;
4300 case 'P': result
= parm_to_string (next_int
); break;
4301 case 'Q': result
= op_to_string (true, next_tcode
); break;
4302 case 'S': result
= subst_to_string (next_tree
); break;
4305 result
= type_to_string (next_tree
, verbose
, false, quoted
,
4306 pp_show_color (pp
));
4309 case 'V': result
= cv_to_string (next_tree
, verbose
); break;
4310 case 'X': result
= eh_spec_to_string (next_tree
, verbose
); break;
4316 pp_string (pp
, result
);
4317 if (set_locus
&& t
!= NULL
)
4318 text
->set_location (0, location_of (t
), SHOW_RANGE_WITH_CARET
);
4326 /* Warn about the use of C++0x features when appropriate. */
4328 maybe_warn_cpp0x (cpp0x_warn_str str
)
4330 if (cxx_dialect
== cxx98
)
4333 case CPP0X_INITIALIZER_LISTS
:
4334 pedwarn (input_location
, 0,
4335 "extended initializer lists "
4336 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4338 case CPP0X_EXPLICIT_CONVERSION
:
4339 pedwarn (input_location
, 0,
4340 "explicit conversion operators "
4341 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4343 case CPP0X_VARIADIC_TEMPLATES
:
4344 pedwarn (input_location
, 0,
4345 "variadic templates "
4346 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4348 case CPP0X_LAMBDA_EXPR
:
4349 pedwarn (input_location
, 0,
4350 "lambda expressions "
4351 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4354 pedwarn (input_location
, 0,
4355 "C++11 auto only available with %<-std=c++11%> or "
4356 "%<-std=gnu++11%>");
4358 case CPP0X_SCOPED_ENUMS
:
4359 pedwarn (input_location
, 0,
4360 "scoped enums only available with %<-std=c++11%> or "
4361 "%<-std=gnu++11%>");
4363 case CPP0X_DEFAULTED_DELETED
:
4364 pedwarn (input_location
, 0,
4365 "defaulted and deleted functions "
4366 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4368 case CPP0X_INLINE_NAMESPACES
:
4369 pedwarn (input_location
, OPT_Wpedantic
,
4370 "inline namespaces "
4371 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4373 case CPP0X_OVERRIDE_CONTROLS
:
4374 pedwarn (input_location
, 0,
4375 "override controls (override/final) "
4376 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4379 pedwarn (input_location
, 0,
4380 "non-static data member initializers "
4381 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4383 case CPP0X_USER_DEFINED_LITERALS
:
4384 pedwarn (input_location
, 0,
4385 "user-defined literals "
4386 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4388 case CPP0X_DELEGATING_CTORS
:
4389 pedwarn (input_location
, 0,
4390 "delegating constructors "
4391 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4393 case CPP0X_INHERITING_CTORS
:
4394 pedwarn (input_location
, 0,
4395 "inheriting constructors "
4396 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4398 case CPP0X_ATTRIBUTES
:
4399 pedwarn (input_location
, 0,
4401 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4403 case CPP0X_REF_QUALIFIER
:
4404 pedwarn (input_location
, 0,
4406 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4413 /* Warn about the use of variadic templates when appropriate. */
4415 maybe_warn_variadic_templates (void)
4417 maybe_warn_cpp0x (CPP0X_VARIADIC_TEMPLATES
);
4421 /* Issue an ISO C++98 pedantic warning at LOCATION, conditional on
4422 option OPT with text GMSGID. Use this function to report
4423 diagnostics for constructs that are invalid C++98, but valid
4426 pedwarn_cxx98 (location_t location
, int opt
, const char *gmsgid
, ...)
4428 diagnostic_info diagnostic
;
4431 rich_location
richloc (line_table
, location
);
4433 va_start (ap
, gmsgid
);
4434 diagnostic_set_info (&diagnostic
, gmsgid
, &ap
, &richloc
,
4435 (cxx_dialect
== cxx98
) ? DK_PEDWARN
: DK_WARNING
);
4436 diagnostic
.option_index
= opt
;
4437 ret
= diagnostic_report_diagnostic (global_dc
, &diagnostic
);
4442 /* Issue a diagnostic that NAME cannot be found in SCOPE. DECL is what
4443 we found when we tried to do the lookup. LOCATION is the location of
4444 the NAME identifier. */
4447 qualified_name_lookup_error (tree scope
, tree name
,
4448 tree decl
, location_t location
)
4450 if (scope
== error_mark_node
)
4451 ; /* We already complained. */
4452 else if (TYPE_P (scope
))
4454 if (!COMPLETE_TYPE_P (scope
))
4455 error_at (location
, "incomplete type %qT used in nested name specifier",
4457 else if (TREE_CODE (decl
) == TREE_LIST
)
4459 error_at (location
, "reference to %<%T::%D%> is ambiguous",
4461 print_candidates (decl
);
4466 if (SCOPED_ENUM_P (scope
) && TREE_CODE (name
) == IDENTIFIER_NODE
)
4467 hint
= suggest_alternative_in_scoped_enum (name
, scope
);
4468 if (const char *suggestion
= hint
.suggestion ())
4470 gcc_rich_location
richloc (location
);
4471 richloc
.add_fixit_replace (suggestion
);
4473 "%qD is not a member of %qT; did you mean %qs?",
4474 name
, scope
, suggestion
);
4477 error_at (location
, "%qD is not a member of %qT", name
, scope
);
4480 else if (scope
!= global_namespace
)
4482 auto_diagnostic_group d
;
4483 bool emit_fixit
= true;
4485 = suggest_alternative_in_explicit_scope (location
, name
, scope
);
4488 hint
= suggest_alternatives_in_other_namespaces (location
, name
);
4489 /* "location" is just the location of the name, not of the explicit
4490 scope, and it's not easy to get at the latter, so we can't issue
4491 fix-it hints for the suggestion. */
4494 if (const char *suggestion
= hint
.suggestion ())
4496 gcc_rich_location
richloc (location
);
4498 richloc
.add_fixit_replace (suggestion
);
4499 error_at (&richloc
, "%qD is not a member of %qD; did you mean %qs?",
4500 name
, scope
, suggestion
);
4503 error_at (location
, "%qD is not a member of %qD", name
, scope
);
4507 auto_diagnostic_group d
;
4508 name_hint hint
= suggest_alternatives_for (location
, name
, true);
4509 if (const char *suggestion
= hint
.suggestion ())
4511 gcc_rich_location
richloc (location
);
4512 richloc
.add_fixit_replace (suggestion
);
4514 "%<::%D%> has not been declared; did you mean %qs?",
4518 error_at (location
, "%<::%D%> has not been declared", name
);
4522 /* C++-specific implementation of range_label::get_text () vfunc for
4523 range_label_for_type_mismatch.
4525 Compare with print_template_differences above. */
4528 range_label_for_type_mismatch::get_text (unsigned /*range_idx*/) const
4530 if (m_labelled_type
== NULL_TREE
)
4531 return label_text (NULL
, false);
4533 const bool verbose
= false;
4534 const bool show_color
= false;
4538 && comparable_template_types_p (m_labelled_type
, m_other_type
))
4539 result
= type_to_string_with_compare (m_labelled_type
, m_other_type
,
4540 verbose
, show_color
);
4542 result
= type_to_string (m_labelled_type
, verbose
, true, NULL
, show_color
);
4544 /* Both of the above return GC-allocated buffers, so the caller mustn't
4546 return label_text (const_cast <char *> (result
), false);