1 /* Call-backs for C++ error reporting.
2 This code is non-reentrant.
3 Copyright (C) 1993-2023 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_MEMORY
24 #include "coretypes.h"
26 #include "stringpool.h"
27 #include "tree-diagnostic.h"
28 #include "diagnostic-color.h"
29 #include "langhooks-def.h"
31 #include "cxx-pretty-print.h"
32 #include "tree-pretty-print.h"
33 #include "gimple-pretty-print.h"
34 #include "c-family/c-objc.h"
36 #include "internal-fn.h"
37 #include "gcc-rich-location.h"
38 #include "cp-name-hint.h"
41 #define pp_separate_with_comma(PP) pp_cxx_separate_with (PP, ',')
42 #define pp_separate_with_semicolon(PP) pp_cxx_separate_with (PP, ';')
44 /* cxx_pp is a C++ front-end-specific pretty printer: this is where we
45 dump C++ ASTs as strings. It is mostly used only by the various
46 tree -> string functions that are occasionally called from the
47 debugger or by the front-end for things like
48 __PRETTY_FUNCTION__. */
49 static cxx_pretty_printer actual_pretty_printer
;
50 static cxx_pretty_printer
* const cxx_pp
= &actual_pretty_printer
;
52 /* Translate if being used for diagnostics, but not for dump files or
54 #define M_(msgid) (pp_translate_identifiers (cxx_pp) ? _(msgid) : (msgid))
56 # define NEXT_CODE(T) (TREE_CODE (TREE_TYPE (T)))
58 static const char *args_to_string (tree
, int);
59 static const char *code_to_string (enum tree_code
);
60 static const char *cv_to_string (tree
, int);
61 static const char *decl_to_string (tree
, int, bool);
62 static const char *fndecl_to_string (tree
, int);
63 static const char *op_to_string (bool, enum tree_code
);
64 static const char *parm_to_string (int);
65 static const char *type_to_string (tree
, int, bool, bool *, bool);
67 static void dump_alias_template_specialization (cxx_pretty_printer
*, tree
, int);
68 static void dump_type (cxx_pretty_printer
*, tree
, int);
69 static void dump_typename (cxx_pretty_printer
*, tree
, int);
70 static void dump_simple_decl (cxx_pretty_printer
*, tree
, tree
, int);
71 static void dump_decl (cxx_pretty_printer
*, tree
, int);
72 static void dump_template_decl (cxx_pretty_printer
*, tree
, int);
73 static void dump_function_decl (cxx_pretty_printer
*, tree
, int);
74 static void dump_expr (cxx_pretty_printer
*, tree
, int);
75 static void dump_unary_op (cxx_pretty_printer
*, const char *, tree
, int);
76 static void dump_binary_op (cxx_pretty_printer
*, const char *, tree
, int);
77 static void dump_aggr_type (cxx_pretty_printer
*, tree
, int);
78 static void dump_type_prefix (cxx_pretty_printer
*, tree
, int);
79 static void dump_type_suffix (cxx_pretty_printer
*, tree
, int);
80 static void dump_function_name (cxx_pretty_printer
*, tree
, int);
81 static void dump_call_expr_args (cxx_pretty_printer
*, tree
, int, bool);
82 static void dump_aggr_init_expr_args (cxx_pretty_printer
*, tree
, int, bool);
83 static void dump_expr_list (cxx_pretty_printer
*, tree
, int);
84 static void dump_global_iord (cxx_pretty_printer
*, tree
);
85 static void dump_parameters (cxx_pretty_printer
*, tree
, int);
86 static void dump_ref_qualifier (cxx_pretty_printer
*, tree
, int);
87 static void dump_exception_spec (cxx_pretty_printer
*, tree
, int);
88 static void dump_template_argument (cxx_pretty_printer
*, tree
, int);
89 static void dump_template_argument_list (cxx_pretty_printer
*, tree
, int);
90 static void dump_template_parameter (cxx_pretty_printer
*, tree
, int);
91 static void dump_template_bindings (cxx_pretty_printer
*, tree
, tree
,
93 static void dump_scope (cxx_pretty_printer
*, tree
, int);
94 static void dump_template_parms (cxx_pretty_printer
*, tree
, int, int);
95 static int get_non_default_template_args_count (tree
, int);
96 static const char *function_category (tree
);
97 static void maybe_print_constexpr_context (diagnostic_context
*);
98 static void maybe_print_instantiation_context (diagnostic_context
*);
99 static void print_instantiation_full_context (diagnostic_context
*);
100 static void print_instantiation_partial_context (diagnostic_context
*,
101 struct tinst_level
*,
103 static void maybe_print_constraint_context (diagnostic_context
*);
104 static void cp_diagnostic_starter (diagnostic_context
*, diagnostic_info
*);
105 static void cp_print_error_function (diagnostic_context
*, diagnostic_info
*);
107 static bool cp_printer (pretty_printer
*, text_info
*, const char *,
108 int, bool, bool, bool, bool *, const char **);
110 /* Struct for handling %H or %I, which require delaying printing the
111 type until a postprocessing stage. */
113 class deferred_printed_type
116 deferred_printed_type ()
117 : m_tree (NULL_TREE
), m_buffer_ptr (NULL
), m_verbose (false), m_quote (false)
120 deferred_printed_type (tree type
, const char **buffer_ptr
, bool verbose
,
122 : m_tree (type
), m_buffer_ptr (buffer_ptr
), m_verbose (verbose
),
126 gcc_assert (buffer_ptr
);
129 /* The tree is not GTY-marked: they are only non-NULL within a
130 call to pp_format. */
132 const char **m_buffer_ptr
;
137 /* Subclass of format_postprocessor for the C++ frontend.
138 This handles the %H and %I formatting codes, printing them
139 in a postprocessing phase (since they affect each other). */
141 class cxx_format_postprocessor
: public format_postprocessor
144 cxx_format_postprocessor ()
145 : m_type_a (), m_type_b ()
148 format_postprocessor
*clone() const final override
150 return new cxx_format_postprocessor ();
153 void handle (pretty_printer
*pp
) final override
;
155 deferred_printed_type m_type_a
;
156 deferred_printed_type m_type_b
;
159 /* CONTEXT->printer is a basic pretty printer that was constructed
160 presumably by diagnostic_initialize(), called early in the
161 compiler's initialization process (in general_init) Before the FE
162 is initialized. This (C++) FE-specific diagnostic initializer is
163 thus replacing the basic pretty printer with one that has C++-aware
167 cxx_initialize_diagnostics (diagnostic_context
*context
)
169 pretty_printer
*base
= context
->printer
;
170 cxx_pretty_printer
*pp
= XNEW (cxx_pretty_printer
);
171 context
->printer
= new (pp
) cxx_pretty_printer ();
173 /* It is safe to free this object because it was previously XNEW()'d. */
174 base
->~pretty_printer ();
177 c_common_diagnostics_set_defaults (context
);
178 diagnostic_starter (context
) = cp_diagnostic_starter
;
179 /* diagnostic_finalizer is already c_diagnostic_finalizer. */
180 diagnostic_format_decoder (context
) = cp_printer
;
181 pp
->m_format_postprocessor
= new cxx_format_postprocessor ();
184 /* Dump an '@module' name suffix for DECL, if any. */
187 dump_module_suffix (cxx_pretty_printer
*pp
, tree decl
)
192 if (!DECL_CONTEXT (decl
))
195 if (TREE_CODE (decl
) != CONST_DECL
196 || !UNSCOPED_ENUM_P (DECL_CONTEXT (decl
)))
198 if (!DECL_NAMESPACE_SCOPE_P (decl
))
201 if (TREE_CODE (decl
) == NAMESPACE_DECL
202 && !DECL_NAMESPACE_ALIAS (decl
)
203 && (TREE_PUBLIC (decl
) || !TREE_PUBLIC (CP_DECL_CONTEXT (decl
))))
207 if (unsigned m
= get_originating_module (decl
))
208 if (const char *n
= module_name (m
, false))
210 pp_character (pp
, '@');
211 pp
->padding
= pp_none
;
216 /* The scope of the declaration we're currently printing, to avoid redundantly
217 dumping the same scope on parameter types. */
218 static tree current_dump_scope
;
220 /* Dump a scope, if deemed necessary. */
223 dump_scope (cxx_pretty_printer
*pp
, tree scope
, int flags
)
225 int f
= flags
& (TFF_SCOPE
| TFF_CHASE_TYPEDEF
);
227 if (scope
== NULL_TREE
|| scope
== current_dump_scope
)
230 /* Enum values within an unscoped enum will be CONST_DECL with an
231 ENUMERAL_TYPE as their "scope". Use CP_TYPE_CONTEXT of the
232 ENUMERAL_TYPE, so as to print any enclosing namespace. */
233 if (UNSCOPED_ENUM_P (scope
))
234 scope
= CP_TYPE_CONTEXT (scope
);
236 if (TREE_CODE (scope
) == NAMESPACE_DECL
)
238 if (scope
!= global_namespace
)
240 dump_decl (pp
, scope
, f
);
241 pp_cxx_colon_colon (pp
);
244 else if (AGGREGATE_TYPE_P (scope
)
245 || SCOPED_ENUM_P (scope
))
247 dump_type (pp
, scope
, f
);
248 pp_cxx_colon_colon (pp
);
250 else if ((flags
& TFF_SCOPE
) && TREE_CODE (scope
) == FUNCTION_DECL
)
252 dump_function_decl (pp
, scope
, f
| TFF_NO_TEMPLATE_BINDINGS
);
253 pp_cxx_colon_colon (pp
);
257 /* Dump the template ARGument under control of FLAGS. */
260 dump_template_argument (cxx_pretty_printer
*pp
, tree arg
, int flags
)
262 if (ARGUMENT_PACK_P (arg
))
263 dump_template_argument_list (pp
, ARGUMENT_PACK_ARGS (arg
),
264 /* No default args in argument packs. */
265 flags
|TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS
);
266 else if (TYPE_P (arg
) || TREE_CODE (arg
) == TEMPLATE_DECL
)
267 dump_type (pp
, arg
, flags
& ~TFF_CLASS_KEY_OR_ENUM
);
270 if (TREE_CODE (arg
) == TREE_LIST
)
271 arg
= TREE_VALUE (arg
);
273 /* Strip implicit conversions. */
274 while (CONVERT_EXPR_P (arg
))
275 arg
= TREE_OPERAND (arg
, 0);
277 dump_expr (pp
, arg
, (flags
| TFF_EXPR_IN_PARENS
) & ~TFF_CLASS_KEY_OR_ENUM
);
281 /* Count the number of template arguments ARGS whose value does not
282 match the (optional) default template parameter in PARAMS */
285 get_non_default_template_args_count (tree args
, int flags
)
287 int n
= TREE_VEC_LENGTH (INNERMOST_TEMPLATE_ARGS (args
));
289 if (/* We use this flag when generating debug information. We don't
290 want to expand templates at this point, for this may generate
291 new decls, which gets decl counts out of sync, which may in
292 turn cause codegen differences between compilations with and
294 (flags
& TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS
) != 0
295 || !flag_pretty_templates
)
298 return GET_NON_DEFAULT_TEMPLATE_ARGS_COUNT (INNERMOST_TEMPLATE_ARGS (args
));
301 /* Dump a template-argument-list ARGS (always a TREE_VEC) under control
305 dump_template_argument_list (cxx_pretty_printer
*pp
, tree args
, int flags
)
307 int n
= get_non_default_template_args_count (args
, flags
);
311 for (i
= 0; i
< n
; ++i
)
313 tree arg
= TREE_VEC_ELT (args
, i
);
315 /* Only print a comma if we know there is an argument coming. In
316 the case of an empty template argument pack, no actual
317 argument will be printed. */
319 && (!ARGUMENT_PACK_P (arg
)
320 || TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg
)) > 0))
321 pp_separate_with_comma (pp
);
323 dump_template_argument (pp
, arg
, flags
);
328 /* Dump a template parameter PARM (a TREE_LIST) under control of FLAGS. */
331 dump_template_parameter (cxx_pretty_printer
*pp
, tree parm
, int flags
)
336 if (parm
== error_mark_node
)
339 p
= TREE_VALUE (parm
);
340 a
= TREE_PURPOSE (parm
);
342 if (TREE_CODE (p
) == TYPE_DECL
)
344 if (flags
& TFF_DECL_SPECIFIERS
)
346 pp_cxx_ws_string (pp
, "class");
347 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (p
)))
348 pp_cxx_ws_string (pp
, "...");
350 pp_cxx_tree_identifier (pp
, DECL_NAME (p
));
352 else if (DECL_NAME (p
))
353 pp_cxx_tree_identifier (pp
, DECL_NAME (p
));
355 pp_cxx_canonical_template_parameter (pp
, TREE_TYPE (p
));
358 dump_decl (pp
, p
, flags
| TFF_DECL_SPECIFIERS
);
360 if ((flags
& TFF_FUNCTION_DEFAULT_ARGUMENTS
) && a
!= NULL_TREE
)
362 pp_cxx_whitespace (pp
);
364 pp_cxx_whitespace (pp
);
365 if (TREE_CODE (p
) == TYPE_DECL
|| TREE_CODE (p
) == TEMPLATE_DECL
)
366 dump_type (pp
, a
, flags
& ~TFF_CHASE_TYPEDEF
);
368 dump_expr (pp
, a
, flags
| TFF_EXPR_IN_PARENS
);
372 /* Dump, under control of FLAGS, a template-parameter-list binding.
373 PARMS is a TREE_LIST of TREE_VEC of TREE_LIST and ARGS is a
377 dump_template_bindings (cxx_pretty_printer
*pp
, tree parms
, tree args
,
378 vec
<tree
, va_gc
> *typenames
)
380 /* Print "[with" and ']', conditional on whether anything is printed at all.
381 This is tied to whether a semicolon is needed to separate multiple template
383 struct prepost_semicolon
385 cxx_pretty_printer
*pp
;
391 pp_separate_with_semicolon (pp
);
394 pp_cxx_whitespace (pp
);
395 pp_string (pp
, colorize_start (pp_show_color (pp
), "targs"));
396 pp_cxx_left_bracket (pp
);
397 pp
->translate_string ("with");
398 pp_cxx_whitespace (pp
);
399 need_semicolon
= true;
403 ~prepost_semicolon ()
407 pp_cxx_right_bracket (pp
);
408 pp_string (pp
, colorize_stop (pp_show_color (pp
)));
411 } semicolon_or_introducer
= {pp
, false};
418 tree p
= TREE_VALUE (parms
);
419 int lvl
= TMPL_PARMS_DEPTH (parms
);
422 tree lvl_args
= NULL_TREE
;
424 /* Don't crash if we had an invalid argument list. */
425 if (TMPL_ARGS_DEPTH (args
) >= lvl
)
426 lvl_args
= TMPL_ARGS_LEVEL (args
, lvl
);
428 for (i
= 0; i
< TREE_VEC_LENGTH (p
); ++i
)
430 tree arg
= NULL_TREE
;
432 /* Don't crash if we had an invalid argument list. */
433 if (lvl_args
&& NUM_TMPL_ARGS (lvl_args
) > arg_idx
)
434 arg
= TREE_VEC_ELT (lvl_args
, arg_idx
);
436 tree parm_i
= TREE_VEC_ELT (p
, i
);
437 /* If the template argument repeats the template parameter (T = T),
438 skip the parameter.*/
439 if (arg
&& TREE_CODE (arg
) == TEMPLATE_TYPE_PARM
440 && TREE_CODE (parm_i
) == TREE_LIST
441 && TREE_CODE (TREE_VALUE (parm_i
)) == TYPE_DECL
442 && TREE_CODE (TREE_TYPE (TREE_VALUE (parm_i
)))
443 == TEMPLATE_TYPE_PARM
444 && DECL_NAME (TREE_VALUE (parm_i
))
445 == DECL_NAME (TREE_CHAIN (arg
)))
448 semicolon_or_introducer ();
449 dump_template_parameter (pp
, parm_i
, TFF_PLAIN_IDENTIFIER
);
450 pp_cxx_whitespace (pp
);
452 pp_cxx_whitespace (pp
);
455 if (ARGUMENT_PACK_P (arg
))
456 pp_cxx_left_brace (pp
);
457 dump_template_argument (pp
, arg
, TFF_PLAIN_IDENTIFIER
);
458 if (ARGUMENT_PACK_P (arg
))
459 pp_cxx_right_brace (pp
);
462 pp_string (pp
, M_("<missing>"));
467 parms
= TREE_CHAIN (parms
);
470 /* Don't bother with typenames for a partial instantiation. */
471 if (vec_safe_is_empty (typenames
) || uses_template_parms (args
))
474 /* Don't try to print typenames when we're processing a clone. */
475 if (current_function_decl
476 && !DECL_LANG_SPECIFIC (current_function_decl
))
479 /* Don't try to do this once cgraph starts throwing away front-end
484 FOR_EACH_VEC_SAFE_ELT (typenames
, i
, t
)
486 semicolon_or_introducer ();
487 dump_type (pp
, t
, TFF_PLAIN_IDENTIFIER
);
488 pp_cxx_whitespace (pp
);
490 pp_cxx_whitespace (pp
);
491 push_deferring_access_checks (dk_no_check
);
492 t
= tsubst (t
, args
, tf_none
, NULL_TREE
);
493 pop_deferring_access_checks ();
494 /* Strip typedefs. We can't just use TFF_CHASE_TYPEDEF because
495 pp_simple_type_specifier doesn't know about it. */
496 t
= strip_typedefs (t
, NULL
, STF_USER_VISIBLE
);
497 dump_type (pp
, t
, TFF_PLAIN_IDENTIFIER
);
501 /* Dump a human-readable equivalent of the alias template
502 specialization of T. */
505 dump_alias_template_specialization (cxx_pretty_printer
*pp
, tree t
, int flags
)
507 gcc_assert (alias_template_specialization_p (t
, nt_opaque
));
509 tree decl
= TYPE_NAME (t
);
510 if (!(flags
& TFF_UNQUALIFIED_NAME
))
511 dump_scope (pp
, CP_DECL_CONTEXT (decl
), flags
);
512 pp_cxx_tree_identifier (pp
, DECL_NAME (decl
));
513 dump_template_parms (pp
, DECL_TEMPLATE_INFO (decl
),
515 flags
& ~TFF_TEMPLATE_HEADER
);
518 /* Dump a human-readable equivalent of TYPE. FLAGS controls the
522 dump_type (cxx_pretty_printer
*pp
, tree t
, int flags
)
527 /* Don't print e.g. "struct mytypedef". */
528 if (TYPE_P (t
) && typedef_variant_p (t
))
530 tree decl
= TYPE_NAME (t
);
531 if ((flags
& TFF_CHASE_TYPEDEF
)
532 || DECL_SELF_REFERENCE_P (decl
)
533 || (!flag_pretty_templates
534 && DECL_LANG_SPECIFIC (decl
) && DECL_TEMPLATE_INFO (decl
)))
536 unsigned int stf_flags
= (!(pp
->flags
& pp_c_flag_gnu_v3
)
537 ? STF_USER_VISIBLE
: 0);
538 t
= strip_typedefs (t
, NULL
, stf_flags
);
540 else if (alias_template_specialization_p (t
, nt_opaque
))
542 dump_alias_template_specialization (pp
, t
, flags
);
545 else if (same_type_p (t
, TREE_TYPE (decl
)))
549 pp_cxx_cv_qualifier_seq (pp
, t
);
550 if (! (flags
& TFF_UNQUALIFIED_NAME
))
551 dump_scope (pp
, CP_DECL_CONTEXT (decl
), flags
);
552 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
557 if (TYPE_PTRMEMFUNC_P (t
))
560 switch (TREE_CODE (t
))
563 if (t
== init_list_type_node
)
564 pp_string (pp
, M_("<brace-enclosed initializer list>"));
565 else if (t
== unknown_type_node
)
566 pp_string (pp
, M_("<unresolved overloaded function type>"));
569 pp_cxx_cv_qualifier_seq (pp
, t
);
570 if (tree id
= TYPE_IDENTIFIER (t
))
571 pp_cxx_tree_identifier (pp
, id
);
576 /* A list of function parms. */
577 dump_parameters (pp
, t
, flags
);
580 case IDENTIFIER_NODE
:
581 pp_cxx_tree_identifier (pp
, t
);
585 dump_type (pp
, BINFO_TYPE (t
), flags
);
591 dump_aggr_type (pp
, t
, flags
);
595 if (flags
& TFF_CHASE_TYPEDEF
)
597 dump_type (pp
, DECL_ORIGINAL_TYPE (t
)
598 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
), flags
);
605 dump_decl (pp
, t
, flags
& ~TFF_DECL_SPECIFIERS
);
615 case FIXED_POINT_TYPE
:
616 pp_type_specifier_seq (pp
, t
);
619 case TEMPLATE_TEMPLATE_PARM
:
620 /* For parameters inside template signature. */
621 if (TYPE_IDENTIFIER (t
))
622 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
624 pp_cxx_canonical_template_parameter (pp
, t
);
627 case BOUND_TEMPLATE_TEMPLATE_PARM
:
629 tree args
= TYPE_TI_ARGS (t
);
630 pp_cxx_cv_qualifier_seq (pp
, t
);
631 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
632 pp_cxx_begin_template_argument_list (pp
);
633 dump_template_argument_list (pp
, args
, flags
);
634 pp_cxx_end_template_argument_list (pp
);
638 case TEMPLATE_TYPE_PARM
:
639 pp_cxx_cv_qualifier_seq (pp
, t
);
640 if (template_placeholder_p (t
))
642 tree tmpl
= TREE_TYPE (CLASS_PLACEHOLDER_TEMPLATE (t
));
643 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (tmpl
));
644 pp_string (pp
, "<...auto...>");
646 else if (TYPE_IDENTIFIER (t
))
647 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
649 pp_cxx_canonical_template_parameter
650 (pp
, TEMPLATE_TYPE_PARM_INDEX (t
));
651 /* If this is a constrained placeholder, add the requirements. */
652 if (tree c
= PLACEHOLDER_TYPE_CONSTRAINTS (t
))
653 pp_cxx_constrained_type_spec (pp
, c
);
656 /* This is not always necessary for pointers and such, but doing this
657 reduces code size. */
666 dump_type_prefix (pp
, t
, flags
);
667 dump_type_suffix (pp
, t
, flags
);
671 if (! (flags
& TFF_CHASE_TYPEDEF
)
672 && DECL_ORIGINAL_TYPE (TYPE_NAME (t
)))
674 dump_decl (pp
, TYPE_NAME (t
), TFF_PLAIN_IDENTIFIER
);
677 pp_cxx_cv_qualifier_seq (pp
, t
);
678 pp_cxx_ws_string (pp
,
679 TYPENAME_IS_ENUM_P (t
) ? "enum"
680 : TYPENAME_IS_CLASS_P (t
) ? "class"
682 dump_typename (pp
, t
, flags
);
685 case UNBOUND_CLASS_TEMPLATE
:
686 if (! (flags
& TFF_UNQUALIFIED_NAME
))
688 dump_type (pp
, TYPE_CONTEXT (t
), flags
);
689 pp_cxx_colon_colon (pp
);
691 pp_cxx_ws_string (pp
, "template");
692 dump_type (pp
, TYPE_IDENTIFIER (t
), flags
);
696 pp_cxx_ws_string (pp
, "__typeof__");
697 pp_cxx_whitespace (pp
);
698 pp_cxx_left_paren (pp
);
699 dump_expr (pp
, TYPEOF_TYPE_EXPR (t
), flags
& ~TFF_EXPR_IN_PARENS
);
700 pp_cxx_right_paren (pp
);
704 pp_cxx_trait (pp
, t
);
707 case TYPE_PACK_EXPANSION
:
708 dump_type (pp
, PACK_EXPANSION_PATTERN (t
), flags
);
709 pp_cxx_ws_string (pp
, "...");
712 case TYPE_ARGUMENT_PACK
:
713 dump_template_argument (pp
, t
, flags
);
717 pp_cxx_ws_string (pp
, "decltype");
718 pp_cxx_whitespace (pp
);
719 pp_cxx_left_paren (pp
);
720 dump_expr (pp
, DECLTYPE_TYPE_EXPR (t
), flags
& ~TFF_EXPR_IN_PARENS
);
721 pp_cxx_right_paren (pp
);
725 pp_string (pp
, "std::nullptr_t");
729 pp_unsupported_tree (pp
, t
);
733 pp_string (pp
, M_("<type error>"));
738 /* Dump a TYPENAME_TYPE. We need to notice when the context is itself
742 dump_typename (cxx_pretty_printer
*pp
, tree t
, int flags
)
744 tree ctx
= TYPE_CONTEXT (t
);
746 if (TREE_CODE (ctx
) == TYPENAME_TYPE
)
747 dump_typename (pp
, ctx
, flags
);
749 dump_type (pp
, ctx
, flags
& ~TFF_CLASS_KEY_OR_ENUM
);
750 pp_cxx_colon_colon (pp
);
751 dump_decl (pp
, TYPENAME_TYPE_FULLNAME (t
), flags
);
754 /* Return the name of the supplied aggregate, or enumeral type. */
757 class_key_or_enum_as_string (tree t
)
759 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
761 if (SCOPED_ENUM_P (t
))
766 else if (TREE_CODE (t
) == UNION_TYPE
)
768 else if (TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_DECLARED_CLASS (t
))
774 /* Disable warnings about missing quoting in GCC diagnostics for
775 the pp_verbatim call. Their format strings deliberately don't
776 follow GCC diagnostic conventions. */
778 #pragma GCC diagnostic push
779 #pragma GCC diagnostic ignored "-Wformat-diag"
782 /* Print out a class declaration T under the control of FLAGS,
783 in the form `class foo'. */
786 dump_aggr_type (cxx_pretty_printer
*pp
, tree t
, int flags
)
788 const char *variety
= class_key_or_enum_as_string (t
);
792 pp_cxx_cv_qualifier_seq (pp
, t
);
794 if (flags
& TFF_CLASS_KEY_OR_ENUM
)
795 pp_cxx_ws_string (pp
, variety
);
797 tree decl
= TYPE_NAME (t
);
801 typdef
= (!DECL_ARTIFICIAL (decl
)
802 /* An alias specialization is not considered to be a
804 && !alias_template_specialization_p (t
, nt_opaque
));
807 && ((flags
& TFF_CHASE_TYPEDEF
)
808 || (!flag_pretty_templates
&& DECL_LANG_SPECIFIC (decl
)
809 && DECL_TEMPLATE_INFO (decl
))))
810 || DECL_SELF_REFERENCE_P (decl
))
812 t
= TYPE_MAIN_VARIANT (t
);
813 decl
= TYPE_NAME (t
);
817 tmplate
= !typdef
&& TREE_CODE (t
) != ENUMERAL_TYPE
818 && TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_TEMPLATE_INFO (t
)
819 && (TREE_CODE (CLASSTYPE_TI_TEMPLATE (t
)) != TEMPLATE_DECL
820 || PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t
)));
822 if (! (flags
& TFF_UNQUALIFIED_NAME
))
823 dump_scope (pp
, CP_DECL_CONTEXT (decl
), flags
| TFF_SCOPE
);
824 flags
&= ~TFF_UNQUALIFIED_NAME
;
827 /* Because the template names are mangled, we have to locate
828 the most general template, and use that name. */
829 tree tpl
= TYPE_TI_TEMPLATE (t
);
831 while (DECL_TEMPLATE_INFO (tpl
))
832 tpl
= DECL_TI_TEMPLATE (tpl
);
837 if (LAMBDA_TYPE_P (t
))
839 /* A lambda's "type" is essentially its signature. */
840 pp_string (pp
, M_("<lambda"));
841 if (lambda_function (t
))
843 FUNCTION_FIRST_USER_PARMTYPE (lambda_function (t
)),
847 else if (!decl
|| IDENTIFIER_ANON_P (DECL_NAME (decl
)))
849 if (flags
& TFF_CLASS_KEY_OR_ENUM
)
850 pp_string (pp
, M_("<unnamed>"));
852 pp_printf (pp
, M_("<unnamed %s>"), variety
);
855 pp_cxx_tree_identifier (pp
, DECL_NAME (decl
));
857 dump_module_suffix (pp
, decl
);
860 dump_template_parms (pp
, TYPE_TEMPLATE_INFO (t
),
861 !CLASSTYPE_USE_TEMPLATE (t
),
862 flags
& ~TFF_TEMPLATE_HEADER
);
866 #pragma GCC diagnostic pop
869 /* Dump into the obstack the initial part of the output for a given type.
870 This is necessary when dealing with things like functions returning
873 return type of `int (* fee ())()': pointer -> function -> int. Both
874 pointer (and reference and offset) and function (and member) types must
875 deal with prefix and suffix.
877 Arrays must also do this for DECL nodes, like int a[], and for things like
881 dump_type_prefix (cxx_pretty_printer
*pp
, tree t
, int flags
)
883 if (TYPE_PTRMEMFUNC_P (t
))
885 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
889 switch (TREE_CODE (t
))
894 tree sub
= TREE_TYPE (t
);
896 dump_type_prefix (pp
, sub
, flags
);
897 if (TREE_CODE (sub
) == ARRAY_TYPE
898 || TREE_CODE (sub
) == FUNCTION_TYPE
)
900 pp_cxx_whitespace (pp
);
901 pp_cxx_left_paren (pp
);
902 /* If we're dealing with the GNU form of attributes, print this:
903 void (__attribute__((noreturn)) *f) ();
904 If it is the standard [[]] attribute, we'll print the attribute
905 in dump_type_suffix. */
906 if (!cxx11_attribute_p (TYPE_ATTRIBUTES (sub
)))
907 pp_c_attributes_display (pp
, TYPE_ATTRIBUTES (sub
));
911 else if (TYPE_REF_P (t
))
913 if (TYPE_REF_IS_RVALUE (t
))
914 pp_ampersand_ampersand (pp
);
918 pp
->padding
= pp_before
;
919 pp_cxx_cv_qualifier_seq (pp
, t
);
925 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
926 if (TREE_CODE (t
) == OFFSET_TYPE
) /* pmfs deal with this in d_t_p */
929 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
930 pp_cxx_left_paren (pp
);
931 dump_type (pp
, TYPE_OFFSET_BASETYPE (t
), flags
);
932 pp_cxx_colon_colon (pp
);
935 pp_cxx_cv_qualifier_seq (pp
, t
);
936 pp
->padding
= pp_before
;
939 /* This can be reached without a pointer when dealing with
940 templates, e.g. std::is_function. */
942 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
946 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
948 pp_cxx_left_paren (pp
);
949 dump_aggr_type (pp
, TYPE_METHOD_BASETYPE (t
), flags
);
950 pp_cxx_colon_colon (pp
);
954 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
958 case IDENTIFIER_NODE
:
963 case TEMPLATE_TYPE_PARM
:
964 case TEMPLATE_TEMPLATE_PARM
:
965 case BOUND_TEMPLATE_TEMPLATE_PARM
:
979 case TYPE_PACK_EXPANSION
:
980 case FIXED_POINT_TYPE
:
982 dump_type (pp
, t
, flags
);
983 pp
->padding
= pp_before
;
987 pp_unsupported_tree (pp
, t
);
990 pp_string (pp
, M_("<typeprefixerror>"));
995 /* Dump the suffix of type T, under control of FLAGS. This is the part
996 which appears after the identifier (or function parms). */
999 dump_type_suffix (cxx_pretty_printer
*pp
, tree t
, int flags
)
1001 if (TYPE_PTRMEMFUNC_P (t
))
1002 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
1004 switch (TREE_CODE (t
))
1007 case REFERENCE_TYPE
:
1009 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
1010 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
1011 pp_cxx_right_paren (pp
);
1012 if (TREE_CODE (t
) == POINTER_TYPE
)
1013 flags
|= TFF_POINTER
;
1014 dump_type_suffix (pp
, TREE_TYPE (t
), flags
);
1021 if (TREE_CODE (t
) == METHOD_TYPE
)
1022 /* Can only be reached through a pointer. */
1023 pp_cxx_right_paren (pp
);
1024 arg
= TYPE_ARG_TYPES (t
);
1025 if (TREE_CODE (t
) == METHOD_TYPE
)
1026 arg
= TREE_CHAIN (arg
);
1028 /* Function pointers don't have default args. Not in standard C++,
1029 anyway; they may in g++, but we'll just pretend otherwise. */
1030 dump_parameters (pp
, arg
, flags
& ~TFF_FUNCTION_DEFAULT_ARGUMENTS
);
1032 pp
->padding
= pp_before
;
1033 pp_cxx_cv_qualifiers (pp
, type_memfn_quals (t
),
1034 TREE_CODE (t
) == FUNCTION_TYPE
1035 && (flags
& TFF_POINTER
));
1036 dump_ref_qualifier (pp
, t
, flags
);
1037 if (tx_safe_fn_type_p (t
))
1038 pp_cxx_ws_string (pp
, "transaction_safe");
1039 dump_exception_spec (pp
, TYPE_RAISES_EXCEPTIONS (t
), flags
);
1040 /* If this is the standard [[]] attribute, print
1041 void (*)() [[noreturn]]; */
1042 if (cxx11_attribute_p (TYPE_ATTRIBUTES (t
)))
1045 pp_c_attributes_display (pp
, TYPE_ATTRIBUTES (t
));
1046 pp
->padding
= pp_before
;
1048 dump_type_suffix (pp
, TREE_TYPE (t
), flags
);
1053 pp_maybe_space (pp
);
1054 pp_cxx_left_bracket (pp
);
1055 if (tree dtype
= TYPE_DOMAIN (t
))
1057 tree max
= TYPE_MAX_VALUE (dtype
);
1058 /* Zero-length arrays have a null upper bound in C and SIZE_MAX
1059 in C++. Handle both since the type might be constructed by
1060 the middle end and end up here as a result of a warning (see
1062 if (!max
|| integer_all_onesp (max
))
1063 pp_character (pp
, '0');
1064 else if (tree_fits_shwi_p (max
))
1065 pp_wide_integer (pp
, tree_to_shwi (max
) + 1);
1069 if (TREE_CODE (max
) == SAVE_EXPR
)
1070 max
= TREE_OPERAND (max
, 0);
1071 if (TREE_CODE (max
) == MINUS_EXPR
1072 || TREE_CODE (max
) == PLUS_EXPR
)
1074 max
= TREE_OPERAND (max
, 0);
1075 while (CONVERT_EXPR_P (max
))
1076 max
= TREE_OPERAND (max
, 0);
1079 max
= fold_build2_loc (input_location
,
1080 PLUS_EXPR
, dtype
, max
,
1081 build_int_cst (dtype
, 1));
1082 dump_expr (pp
, max
, flags
& ~TFF_EXPR_IN_PARENS
);
1085 pp_cxx_right_bracket (pp
);
1086 dump_type_suffix (pp
, TREE_TYPE (t
), flags
);
1090 case IDENTIFIER_NODE
:
1095 case TEMPLATE_TYPE_PARM
:
1096 case TEMPLATE_TEMPLATE_PARM
:
1097 case BOUND_TEMPLATE_TEMPLATE_PARM
:
1111 case TYPE_PACK_EXPANSION
:
1112 case FIXED_POINT_TYPE
:
1117 pp_unsupported_tree (pp
, t
);
1119 /* Don't mark it here, we should have already done in
1120 dump_type_prefix. */
1126 dump_global_iord (cxx_pretty_printer
*pp
, tree t
)
1128 const char *p
= NULL
;
1130 if (DECL_GLOBAL_CTOR_P (t
))
1131 p
= M_("(static initializers for %s)");
1132 else if (DECL_GLOBAL_DTOR_P (t
))
1133 p
= M_("(static destructors for %s)");
1137 pp_printf (pp
, p
, DECL_SOURCE_FILE (t
));
1141 dump_simple_decl (cxx_pretty_printer
*pp
, tree t
, tree type
, int flags
)
1143 if (VAR_P (t
) && DECL_NTTP_OBJECT_P (t
))
1144 return dump_expr (pp
, DECL_INITIAL (t
), flags
);
1146 if (flags
& TFF_DECL_SPECIFIERS
)
1148 if (concept_definition_p (t
))
1149 pp_cxx_ws_string (pp
, "concept");
1150 else if (VAR_P (t
) && DECL_DECLARED_CONSTEXPR_P (t
))
1151 pp_cxx_ws_string (pp
, "constexpr");
1153 if (!standard_concept_p (t
))
1154 dump_type_prefix (pp
, type
, flags
& ~TFF_UNQUALIFIED_NAME
);
1155 pp_maybe_space (pp
);
1157 if (! (flags
& TFF_UNQUALIFIED_NAME
)
1158 && TREE_CODE (t
) != PARM_DECL
1159 && (!DECL_INITIAL (t
)
1160 || TREE_CODE (DECL_INITIAL (t
)) != TEMPLATE_PARM_INDEX
))
1161 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1162 flags
&= ~TFF_UNQUALIFIED_NAME
;
1163 if ((flags
& TFF_DECL_SPECIFIERS
)
1164 && DECL_TEMPLATE_PARM_P (t
)
1165 && TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (t
)))
1166 pp_string (pp
, "...");
1169 if (TREE_CODE (t
) == FIELD_DECL
&& DECL_NORMAL_CAPTURE_P (t
))
1172 pp_string (pp
, IDENTIFIER_POINTER (DECL_NAME (t
)) + 2);
1173 pp_string (pp
, " capture>");
1176 dump_decl (pp
, DECL_NAME (t
), flags
);
1178 else if (DECL_DECOMPOSITION_P (t
))
1179 pp_string (pp
, M_("<structured bindings>"));
1180 else if (TREE_CODE (t
) == FIELD_DECL
&& DECL_FIELD_IS_BASE (t
))
1181 dump_type (pp
, TREE_TYPE (t
), flags
);
1183 pp_string (pp
, M_("<anonymous>"));
1185 dump_module_suffix (pp
, t
);
1187 if (flags
& TFF_DECL_SPECIFIERS
)
1188 dump_type_suffix (pp
, type
, flags
);
1191 class colorize_guard
1194 cxx_pretty_printer
*pp
;
1196 colorize_guard (bool _colorize
, cxx_pretty_printer
*pp
, const char *name
)
1197 : colorize (_colorize
&& pp_show_color (pp
)), pp (pp
)
1199 pp_string (pp
, colorize_start (colorize
, name
));
1203 pp_string (pp
, colorize_stop (colorize
));
1207 /* Print an IDENTIFIER_NODE that is the name of a declaration. */
1210 dump_decl_name (cxx_pretty_printer
*pp
, tree t
, int flags
)
1212 /* These special cases are duplicated here so that other functions
1213 can feed identifiers to error and get them demangled properly. */
1214 if (IDENTIFIER_CONV_OP_P (t
))
1216 pp_cxx_ws_string (pp
, "operator");
1217 /* Not exactly IDENTIFIER_TYPE_VALUE. */
1218 dump_type (pp
, TREE_TYPE (t
), flags
);
1221 if (dguide_name_p (t
))
1223 dump_decl (pp
, CLASSTYPE_TI_TEMPLATE (TREE_TYPE (t
)),
1224 TFF_UNQUALIFIED_NAME
);
1228 const char *str
= IDENTIFIER_POINTER (t
);
1229 if (startswith (str
, "_ZGR"))
1231 pp_cxx_ws_string (pp
, "<temporary>");
1235 pp_cxx_tree_identifier (pp
, t
);
1238 /* Dump a human readable string for the decl T under control of FLAGS. */
1241 dump_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
1246 /* If doing Objective-C++, give Objective-C a chance to demangle
1247 Objective-C method names. */
1248 if (c_dialect_objc ())
1250 const char *demangled
= objc_maybe_printable_name (t
, flags
);
1253 pp_string (pp
, demangled
);
1258 switch (TREE_CODE (t
))
1261 /* Don't say 'typedef class A' */
1262 if (DECL_ARTIFICIAL (t
) && !DECL_SELF_REFERENCE_P (t
))
1264 if ((flags
& TFF_DECL_SPECIFIERS
)
1265 && TREE_CODE (TREE_TYPE (t
)) == TEMPLATE_TYPE_PARM
)
1267 /* Say `class T' not just `T'. */
1268 pp_cxx_ws_string (pp
, "class");
1270 /* Emit the `...' for a parameter pack. */
1271 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t
)))
1272 pp_cxx_ws_string (pp
, "...");
1275 dump_type (pp
, TREE_TYPE (t
), flags
);
1278 if (TYPE_DECL_ALIAS_P (t
)
1279 && (flags
& TFF_DECL_SPECIFIERS
1280 || flags
& TFF_CLASS_KEY_OR_ENUM
))
1282 pp_cxx_ws_string (pp
, "using");
1283 if (! (flags
& TFF_UNQUALIFIED_NAME
))
1284 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1285 dump_decl (pp
, DECL_NAME (t
), flags
);
1286 pp_cxx_whitespace (pp
);
1287 pp_cxx_ws_string (pp
, "=");
1288 pp_cxx_whitespace (pp
);
1289 dump_type (pp
, (DECL_ORIGINAL_TYPE (t
)
1290 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
)),
1294 if ((flags
& TFF_DECL_SPECIFIERS
)
1295 && !DECL_SELF_REFERENCE_P (t
))
1296 pp_cxx_ws_string (pp
, "typedef");
1297 dump_simple_decl (pp
, t
, DECL_ORIGINAL_TYPE (t
)
1298 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
),
1303 if (DECL_NAME (t
) && VTABLE_NAME_P (DECL_NAME (t
)))
1305 pp_string (pp
, M_("vtable for "));
1306 gcc_assert (TYPE_P (DECL_CONTEXT (t
)));
1307 dump_type (pp
, DECL_CONTEXT (t
), flags
);
1313 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1315 /* Handle variable template specializations. */
1317 && DECL_LANG_SPECIFIC (t
)
1318 && DECL_TEMPLATE_INFO (t
)
1319 && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t
)))
1321 pp_cxx_begin_template_argument_list (pp
);
1322 tree args
= INNERMOST_TEMPLATE_ARGS (DECL_TI_ARGS (t
));
1323 dump_template_argument_list (pp
, args
, flags
);
1324 pp_cxx_end_template_argument_list (pp
);
1329 pp_string (pp
, M_("<return value> "));
1330 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1333 case NAMESPACE_DECL
:
1334 if (flags
& TFF_DECL_SPECIFIERS
)
1335 pp
->declaration (t
);
1338 if (! (flags
& TFF_UNQUALIFIED_NAME
))
1339 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1340 flags
&= ~TFF_UNQUALIFIED_NAME
;
1341 if (DECL_NAME (t
) == NULL_TREE
)
1343 if (!(pp
->flags
& pp_c_flag_gnu_v3
))
1344 pp_cxx_ws_string (pp
, M_("{anonymous}"));
1346 pp_cxx_ws_string (pp
, M_("(anonymous namespace)"));
1349 pp_cxx_tree_identifier (pp
, DECL_NAME (t
));
1354 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
1355 pp_cxx_colon_colon (pp
);
1356 dump_decl (pp
, TREE_OPERAND (t
, 1), TFF_UNQUALIFIED_NAME
);
1360 dump_decl (pp
, TREE_OPERAND (t
, 0), flags
);
1361 pp_cxx_left_bracket (pp
);
1362 dump_decl (pp
, TREE_OPERAND (t
, 1), flags
);
1363 pp_cxx_right_bracket (pp
);
1366 /* So that we can do dump_decl on an aggr type. */
1370 dump_type (pp
, t
, flags
);
1374 /* This is a pseudo destructor call which has not been folded into
1375 a PSEUDO_DTOR_EXPR yet. */
1376 pp_cxx_complement (pp
);
1377 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
1384 case IDENTIFIER_NODE
:
1385 dump_decl_name (pp
, t
, flags
);
1389 if (!OVL_SINGLE_P (t
))
1391 tree ctx
= ovl_scope (t
);
1392 if (ctx
!= global_namespace
)
1395 dump_type (pp
, ctx
, flags
);
1397 dump_decl (pp
, ctx
, flags
);
1398 pp_cxx_colon_colon (pp
);
1400 dump_decl (pp
, OVL_NAME (t
), flags
);
1404 /* If there's only one function, just treat it like an ordinary
1410 if (! DECL_LANG_SPECIFIC (t
))
1412 if (DECL_ABSTRACT_ORIGIN (t
)
1413 && DECL_ABSTRACT_ORIGIN (t
) != t
)
1414 dump_decl (pp
, DECL_ABSTRACT_ORIGIN (t
), flags
);
1416 dump_function_name (pp
, t
, flags
);
1418 else if (DECL_GLOBAL_CTOR_P (t
) || DECL_GLOBAL_DTOR_P (t
))
1419 dump_global_iord (pp
, t
);
1421 dump_function_decl (pp
, t
, flags
);
1425 dump_template_decl (pp
, t
, flags
);
1429 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1433 pp_string (pp
, "<wildcard>");
1436 case TEMPLATE_ID_EXPR
:
1438 tree name
= TREE_OPERAND (t
, 0);
1439 tree args
= TREE_OPERAND (t
, 1);
1441 if (!identifier_p (name
))
1442 name
= OVL_NAME (name
);
1443 dump_decl (pp
, name
, flags
);
1444 pp_cxx_begin_template_argument_list (pp
);
1445 if (args
== error_mark_node
)
1446 pp_string (pp
, M_("<template arguments error>"));
1448 dump_template_argument_list
1449 (pp
, args
, flags
|TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS
);
1450 pp_cxx_end_template_argument_list (pp
);
1456 pp_cxx_tree_identifier (pp
, DECL_NAME (t
));
1458 dump_generic_node (pp
, t
, 0, TDF_SLIM
, false);
1462 if ((TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == ENUMERAL_TYPE
)
1463 || (DECL_INITIAL (t
) &&
1464 TREE_CODE (DECL_INITIAL (t
)) == TEMPLATE_PARM_INDEX
))
1465 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1466 else if (DECL_NAME (t
))
1467 dump_decl (pp
, DECL_NAME (t
), flags
);
1468 else if (DECL_INITIAL (t
))
1469 dump_expr (pp
, DECL_INITIAL (t
), flags
| TFF_EXPR_IN_PARENS
);
1471 pp_string (pp
, M_("<enumerator>"));
1476 if (flags
& TFF_DECL_SPECIFIERS
)
1477 pp_cxx_ws_string (pp
, "using");
1478 bool variadic
= false;
1479 if (!(flags
& TFF_UNQUALIFIED_NAME
))
1481 tree scope
= USING_DECL_SCOPE (t
);
1482 tree name
= DECL_NAME (t
);
1483 if (PACK_EXPANSION_P (scope
))
1485 scope
= PACK_EXPANSION_PATTERN (scope
);
1488 if (identifier_p (name
)
1489 && IDENTIFIER_CONV_OP_P (name
)
1490 && PACK_EXPANSION_P (TREE_TYPE (name
)))
1492 name
= make_conv_op_name (PACK_EXPANSION_PATTERN
1493 (TREE_TYPE (name
)));
1496 dump_type (pp
, scope
, flags
);
1497 pp_cxx_colon_colon (pp
);
1499 dump_decl (pp
, DECL_NAME (t
), flags
);
1501 pp_cxx_ws_string (pp
, "...");
1506 pp
->declaration (t
);
1510 dump_decl (pp
, BASELINK_FUNCTIONS (t
), flags
);
1513 case NON_DEPENDENT_EXPR
:
1514 dump_expr (pp
, t
, flags
);
1517 case TEMPLATE_TYPE_PARM
:
1518 if (flags
& TFF_DECL_SPECIFIERS
)
1519 pp
->declaration (t
);
1524 case UNBOUND_CLASS_TEMPLATE
:
1525 case TYPE_PACK_EXPANSION
:
1527 dump_type (pp
, t
, flags
);
1531 pp_unsupported_tree (pp
, t
);
1535 pp_string (pp
, M_("<declaration error>"));
1540 /* Dump a template declaration T under control of FLAGS. This means the
1541 'template <...> leaders plus the 'class X' or 'void fn(...)' part. */
1544 dump_template_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
1546 tree orig_parms
= DECL_TEMPLATE_PARMS (t
);
1550 if (flags
& TFF_TEMPLATE_HEADER
)
1552 for (parms
= orig_parms
= nreverse (orig_parms
);
1554 parms
= TREE_CHAIN (parms
))
1556 tree inner_parms
= INNERMOST_TEMPLATE_PARMS (parms
);
1557 int len
= TREE_VEC_LENGTH (inner_parms
);
1561 /* Skip over the dummy template levels of a template template
1563 gcc_assert (TREE_CODE (TREE_TYPE (t
)) == TEMPLATE_TEMPLATE_PARM
);
1567 pp_cxx_ws_string (pp
, "template");
1568 pp_cxx_begin_template_argument_list (pp
);
1570 /* If we've shown the template prefix, we'd better show the
1571 parameters' and decl's type too. */
1572 flags
|= TFF_DECL_SPECIFIERS
;
1574 for (i
= 0; i
< len
; i
++)
1577 pp_separate_with_comma (pp
);
1578 dump_template_parameter (pp
, TREE_VEC_ELT (inner_parms
, i
),
1581 pp_cxx_end_template_argument_list (pp
);
1582 pp_cxx_whitespace (pp
);
1584 nreverse(orig_parms
);
1586 if (DECL_TEMPLATE_TEMPLATE_PARM_P (t
))
1588 /* Say `template<arg> class TT' not just `template<arg> TT'. */
1589 pp_cxx_ws_string (pp
, "class");
1591 /* If this is a parameter pack, print the ellipsis. */
1592 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t
)))
1593 pp_cxx_ws_string (pp
, "...");
1596 /* Only print the requirements if we're also printing
1597 the template header. */
1599 if (tree ci
= get_constraints (t
))
1600 if (check_constraint_info (ci
))
1601 if (tree reqs
= CI_TEMPLATE_REQS (ci
))
1603 pp_cxx_requires_clause (pp
, reqs
);
1604 pp_cxx_whitespace (pp
);
1609 if (DECL_CLASS_TEMPLATE_P (t
))
1610 dump_type (pp
, TREE_TYPE (t
),
1611 ((flags
& ~TFF_CLASS_KEY_OR_ENUM
) | TFF_TEMPLATE_NAME
1612 | (flags
& TFF_DECL_SPECIFIERS
? TFF_CLASS_KEY_OR_ENUM
: 0)));
1613 else if (DECL_TEMPLATE_RESULT (t
)
1614 && (VAR_P (DECL_TEMPLATE_RESULT (t
))
1615 /* Alias template. */
1616 || DECL_TYPE_TEMPLATE_P (t
)
1617 /* Concept definition. &*/
1618 || TREE_CODE (DECL_TEMPLATE_RESULT (t
)) == CONCEPT_DECL
))
1619 dump_decl (pp
, DECL_TEMPLATE_RESULT (t
), flags
| TFF_TEMPLATE_NAME
);
1622 gcc_assert (TREE_TYPE (t
));
1623 switch (NEXT_CODE (t
))
1627 dump_function_decl (pp
, t
, flags
| TFF_TEMPLATE_NAME
);
1630 /* This case can occur with some invalid code. */
1631 dump_type (pp
, TREE_TYPE (t
),
1632 (flags
& ~TFF_CLASS_KEY_OR_ENUM
) | TFF_TEMPLATE_NAME
1633 | (flags
& TFF_DECL_SPECIFIERS
1634 ? TFF_CLASS_KEY_OR_ENUM
: 0));
1639 /* find_typenames looks through the type of the function template T
1640 and returns a vec containing any typedefs, decltypes or TYPENAME_TYPEs
1643 struct find_typenames_t
1645 hash_set
<tree
> *p_set
;
1646 vec
<tree
, va_gc
> *typenames
;
1650 find_typenames_r (tree
*tp
, int *walk_subtrees
, void *data
)
1652 struct find_typenames_t
*d
= (struct find_typenames_t
*)data
;
1653 tree mv
= NULL_TREE
;
1655 if (TYPE_P (*tp
) && is_typedef_decl (TYPE_NAME (*tp
)))
1656 /* Add the type of the typedef without any additional cv-quals. */
1657 mv
= TREE_TYPE (TYPE_NAME (*tp
));
1658 else if (TREE_CODE (*tp
) == TYPENAME_TYPE
1659 || TREE_CODE (*tp
) == DECLTYPE_TYPE
)
1660 /* Add the typename without any cv-qualifiers. */
1661 mv
= TYPE_MAIN_VARIANT (*tp
);
1663 if (PACK_EXPANSION_P (*tp
))
1665 /* Don't mess with parameter packs since we don't remember
1666 the pack expansion context for a particular typename. */
1667 *walk_subtrees
= false;
1671 if (mv
&& (mv
== *tp
|| !d
->p_set
->add (mv
)))
1672 vec_safe_push (d
->typenames
, mv
);
1677 static vec
<tree
, va_gc
> *
1678 find_typenames (tree t
)
1680 struct find_typenames_t ft
;
1681 ft
.p_set
= new hash_set
<tree
>;
1682 ft
.typenames
= NULL
;
1683 cp_walk_tree (&TREE_TYPE (DECL_TEMPLATE_RESULT (t
)),
1684 find_typenames_r
, &ft
, ft
.p_set
);
1686 return ft
.typenames
;
1689 /* Output the "[with ...]" clause for a template instantiation T iff
1690 TEMPLATE_PARMS, TEMPLATE_ARGS and FLAGS are suitable. T may be NULL if
1691 formatting a deduction/substitution diagnostic rather than an
1695 dump_substitution (cxx_pretty_printer
*pp
,
1696 tree t
, tree template_parms
, tree template_args
,
1699 if (template_parms
!= NULL_TREE
&& template_args
!= NULL_TREE
1700 && !(flags
& TFF_NO_TEMPLATE_BINDINGS
))
1702 vec
<tree
, va_gc
> *typenames
= t
? find_typenames (t
) : NULL
;
1703 dump_template_bindings (pp
, template_parms
, template_args
, typenames
);
1707 /* Dump the lambda function FN including its 'mutable' qualifier and any
1708 template bindings. */
1711 dump_lambda_function (cxx_pretty_printer
*pp
,
1712 tree fn
, tree template_parms
, tree template_args
,
1715 /* A lambda's signature is essentially its "type". */
1716 dump_type (pp
, DECL_CONTEXT (fn
), flags
);
1717 if (TREE_CODE (TREE_TYPE (fn
)) == FUNCTION_TYPE
)
1719 pp
->padding
= pp_before
;
1720 pp_c_ws_string (pp
, "static");
1722 else if (!(TYPE_QUALS (class_of_this_parm (TREE_TYPE (fn
)))
1725 pp
->padding
= pp_before
;
1726 pp_c_ws_string (pp
, "mutable");
1728 dump_substitution (pp
, fn
, template_parms
, template_args
, flags
);
1731 /* Pretty print a function decl. There are several ways we want to print a
1732 function declaration. The TFF_ bits in FLAGS tells us how to behave.
1733 As error can only apply the '#' flag once to give 0 and 1 for V, there
1734 is %D which doesn't print the throw specs, and %F which does. */
1737 dump_function_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
1741 tree cname
= NULL_TREE
;
1742 tree template_args
= NULL_TREE
;
1743 tree template_parms
= NULL_TREE
;
1744 int show_return
= flags
& TFF_RETURN_TYPE
|| flags
& TFF_DECL_SPECIFIERS
;
1745 int do_outer_scope
= ! (flags
& TFF_UNQUALIFIED_NAME
);
1748 tree ret
= NULL_TREE
;
1750 int dump_function_name_flags
= flags
& ~TFF_UNQUALIFIED_NAME
;
1751 flags
= dump_function_name_flags
& ~TFF_TEMPLATE_NAME
;
1752 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1753 t
= DECL_TEMPLATE_RESULT (t
);
1755 /* Save the exceptions, in case t is a specialization and we are
1756 emitting an error about incompatible specifications. */
1757 exceptions
= TYPE_RAISES_EXCEPTIONS (TREE_TYPE (t
));
1759 /* Likewise for the constexpr specifier, in case t is a specialization. */
1760 constexpr_p
= (DECL_DECLARED_CONSTEXPR_P (t
)
1761 && !decl_implicit_constexpr_p (t
));
1763 /* Pretty print template instantiations only. */
1764 if (DECL_USE_TEMPLATE (t
) && DECL_TEMPLATE_INFO (t
)
1765 && !(flags
& TFF_NO_TEMPLATE_BINDINGS
)
1766 && flag_pretty_templates
)
1770 template_args
= DECL_TI_ARGS (t
);
1771 tmpl
= most_general_template (t
);
1772 if (tmpl
&& TREE_CODE (tmpl
) == TEMPLATE_DECL
)
1774 template_parms
= DECL_TEMPLATE_PARMS (tmpl
);
1779 if (DECL_NAME (t
) && LAMBDA_FUNCTION_P (t
))
1780 return dump_lambda_function (pp
, t
, template_parms
, template_args
, flags
);
1782 fntype
= TREE_TYPE (t
);
1783 parmtypes
= FUNCTION_FIRST_USER_PARMTYPE (t
);
1785 if (DECL_CLASS_SCOPE_P (t
))
1786 cname
= DECL_CONTEXT (t
);
1787 /* This is for partially instantiated template methods. */
1788 else if (TREE_CODE (fntype
) == METHOD_TYPE
)
1789 cname
= TREE_TYPE (TREE_VALUE (parmtypes
));
1791 if (flags
& TFF_DECL_SPECIFIERS
)
1793 if (DECL_STATIC_FUNCTION_P (t
))
1794 pp_cxx_ws_string (pp
, "static");
1795 else if (DECL_VIRTUAL_P (t
))
1796 pp_cxx_ws_string (pp
, "virtual");
1800 if (DECL_DECLARED_CONCEPT_P (t
))
1801 pp_cxx_ws_string (pp
, "concept");
1802 else if (DECL_IMMEDIATE_FUNCTION_P (t
))
1803 pp_cxx_ws_string (pp
, "consteval");
1805 pp_cxx_ws_string (pp
, "constexpr");
1809 /* Print the return type? */
1811 show_return
= (!DECL_CONV_FN_P (t
) && !DECL_CONSTRUCTOR_P (t
)
1812 && !DECL_DESTRUCTOR_P (t
) && !deduction_guide_p (t
));
1815 ret
= fndecl_declared_return_type (t
);
1816 dump_type_prefix (pp
, ret
, flags
);
1819 /* Print the function name. */
1820 if (!do_outer_scope
)
1824 dump_type (pp
, cname
, flags
);
1825 pp_cxx_colon_colon (pp
);
1828 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1830 /* Name lookup for the rest of the function declarator is implicitly in the
1831 scope of the function, so avoid printing redundant scope qualifiers. */
1832 auto cds
= make_temp_override (current_dump_scope
, CP_DECL_CONTEXT (t
));
1834 dump_function_name (pp
, t
, dump_function_name_flags
);
1836 if (!(flags
& TFF_NO_FUNCTION_ARGUMENTS
))
1838 dump_parameters (pp
, parmtypes
, flags
);
1840 if (TREE_CODE (fntype
) == METHOD_TYPE
)
1842 pp
->padding
= pp_before
;
1843 pp_cxx_cv_qualifier_seq (pp
, class_of_this_parm (fntype
));
1844 dump_ref_qualifier (pp
, fntype
, flags
);
1847 if (tx_safe_fn_type_p (fntype
))
1849 pp
->padding
= pp_before
;
1850 pp_cxx_ws_string (pp
, "transaction_safe");
1853 if (flags
& TFF_EXCEPTION_SPECIFICATION
)
1855 pp
->padding
= pp_before
;
1856 dump_exception_spec (pp
, exceptions
, flags
);
1860 dump_type_suffix (pp
, ret
, flags
);
1861 else if (deduction_guide_p (t
))
1863 pp_cxx_ws_string (pp
, "->");
1864 dump_type (pp
, TREE_TYPE (TREE_TYPE (t
)), flags
);
1868 if (tree ci
= get_constraints (t
))
1869 if (tree reqs
= CI_DECLARATOR_REQS (ci
))
1870 pp_cxx_requires_clause (pp
, reqs
);
1872 dump_substitution (pp
, t
, template_parms
, template_args
, flags
);
1874 if (tree base
= DECL_INHERITED_CTOR_BASE (t
))
1876 pp_cxx_ws_string (pp
, "[inherited from");
1877 dump_type (pp
, base
, TFF_PLAIN_IDENTIFIER
);
1878 pp_character (pp
, ']');
1881 else if (template_args
)
1883 bool need_comma
= false;
1885 pp_cxx_begin_template_argument_list (pp
);
1886 template_args
= INNERMOST_TEMPLATE_ARGS (template_args
);
1887 for (i
= 0; i
< TREE_VEC_LENGTH (template_args
); ++i
)
1889 tree arg
= TREE_VEC_ELT (template_args
, i
);
1891 pp_separate_with_comma (pp
);
1892 if (ARGUMENT_PACK_P (arg
))
1893 pp_cxx_left_brace (pp
);
1894 dump_template_argument (pp
, arg
, TFF_PLAIN_IDENTIFIER
);
1895 if (ARGUMENT_PACK_P (arg
))
1896 pp_cxx_right_brace (pp
);
1899 pp_cxx_end_template_argument_list (pp
);
1903 /* Print a parameter list. If this is for a member function, the
1904 member object ptr (and any other hidden args) should have
1905 already been removed. */
1908 dump_parameters (cxx_pretty_printer
*pp
, tree parmtypes
, int flags
)
1911 flags
&= ~TFF_SCOPE
;
1912 pp_cxx_left_paren (pp
);
1914 for (first
= 1; parmtypes
!= void_list_node
;
1915 parmtypes
= TREE_CHAIN (parmtypes
))
1918 pp_separate_with_comma (pp
);
1922 pp_cxx_ws_string (pp
, "...");
1926 dump_type (pp
, TREE_VALUE (parmtypes
), flags
);
1928 if ((flags
& TFF_FUNCTION_DEFAULT_ARGUMENTS
) && TREE_PURPOSE (parmtypes
))
1930 pp_cxx_whitespace (pp
);
1932 pp_cxx_whitespace (pp
);
1933 dump_expr (pp
, TREE_PURPOSE (parmtypes
), flags
| TFF_EXPR_IN_PARENS
);
1937 pp_cxx_right_paren (pp
);
1940 /* Print ref-qualifier of a FUNCTION_TYPE or METHOD_TYPE. FLAGS are ignored. */
1943 dump_ref_qualifier (cxx_pretty_printer
*pp
, tree t
, int flags ATTRIBUTE_UNUSED
)
1945 if (FUNCTION_REF_QUALIFIED (t
))
1947 pp
->padding
= pp_before
;
1948 if (FUNCTION_RVALUE_QUALIFIED (t
))
1949 pp_cxx_ws_string (pp
, "&&");
1951 pp_cxx_ws_string (pp
, "&");
1955 /* Print an exception specification. T is the exception specification. */
1958 dump_exception_spec (cxx_pretty_printer
*pp
, tree t
, int flags
)
1960 if (t
&& TREE_PURPOSE (t
))
1962 pp_cxx_ws_string (pp
, "noexcept");
1963 if (!integer_onep (TREE_PURPOSE (t
)))
1965 pp_cxx_whitespace (pp
);
1966 pp_cxx_left_paren (pp
);
1967 if (DEFERRED_NOEXCEPT_SPEC_P (t
))
1968 pp_cxx_ws_string (pp
, "<uninstantiated>");
1970 dump_expr (pp
, TREE_PURPOSE (t
), flags
);
1971 pp_cxx_right_paren (pp
);
1976 pp_cxx_ws_string (pp
, "throw");
1977 pp_cxx_whitespace (pp
);
1978 pp_cxx_left_paren (pp
);
1979 if (TREE_VALUE (t
) != NULL_TREE
)
1982 dump_type (pp
, TREE_VALUE (t
), flags
);
1986 pp_separate_with_comma (pp
);
1988 pp_cxx_right_paren (pp
);
1992 /* Handle the function name for a FUNCTION_DECL node, grokking operators
1993 and destructors properly. */
1996 dump_function_name (cxx_pretty_printer
*pp
, tree t
, int flags
)
1998 /* Only colorize when we're printing something before the name; in
1999 particular, not when printing a CALL_EXPR. */
2000 bool colorize
= flags
& (TFF_DECL_SPECIFIERS
| TFF_RETURN_TYPE
2001 | TFF_TEMPLATE_HEADER
);
2003 colorize_guard
g (colorize
, pp
, "fnname");
2005 tree name
= DECL_NAME (t
);
2007 /* We can get here with a decl that was synthesized by language-
2008 independent machinery (e.g. coverage.cc) in which case it won't
2009 have a lang_specific structure attached and DECL_CONSTRUCTOR_P
2010 will crash. In this case it is safe just to print out the
2012 if (!DECL_LANG_SPECIFIC (t
))
2014 pp_cxx_tree_identifier (pp
, name
);
2018 if (TREE_CODE (t
) == TEMPLATE_DECL
)
2019 t
= DECL_TEMPLATE_RESULT (t
);
2021 /* Don't let the user see __comp_ctor et al. */
2022 if (DECL_CONSTRUCTOR_P (t
)
2023 || DECL_DESTRUCTOR_P (t
))
2025 if (LAMBDA_TYPE_P (DECL_CONTEXT (t
)))
2026 name
= get_identifier ("<lambda>");
2027 else if (TYPE_UNNAMED_P (DECL_CONTEXT (t
)))
2028 name
= get_identifier ("<constructor>");
2030 name
= constructor_name (DECL_CONTEXT (t
));
2033 if (DECL_DESTRUCTOR_P (t
))
2035 pp_cxx_complement (pp
);
2036 dump_decl (pp
, name
, TFF_PLAIN_IDENTIFIER
);
2038 else if (DECL_CONV_FN_P (t
))
2040 /* This cannot use the hack that the operator's return
2041 type is stashed off of its name because it may be
2042 used for error reporting. In the case of conflicting
2043 declarations, both will have the same name, yet
2044 the types will be different, hence the TREE_TYPE field
2045 of the first name will be clobbered by the second. */
2046 pp_cxx_ws_string (pp
, "operator");
2047 dump_type (pp
, TREE_TYPE (TREE_TYPE (t
)), flags
);
2050 dump_decl (pp
, name
, flags
);
2052 dump_module_suffix (pp
, t
);
2054 if (DECL_TEMPLATE_INFO (t
)
2055 && !(flags
& TFF_TEMPLATE_NAME
)
2056 && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t
)
2057 && (TREE_CODE (DECL_TI_TEMPLATE (t
)) != TEMPLATE_DECL
2058 || PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t
))))
2059 dump_template_parms (pp
, DECL_TEMPLATE_INFO (t
), !DECL_USE_TEMPLATE (t
),
2063 /* Dump the template parameters from the template info INFO under control of
2064 FLAGS. PRIMARY indicates whether this is a primary template decl, or
2065 specialization (partial or complete). For partial specializations we show
2066 the specialized parameter values. For a primary template we show no
2070 dump_template_parms (cxx_pretty_printer
*pp
, tree info
,
2071 int primary
, int flags
)
2073 tree args
= info
? TI_ARGS (info
) : NULL_TREE
;
2075 if (primary
&& flags
& TFF_TEMPLATE_NAME
)
2077 flags
&= ~(TFF_CLASS_KEY_OR_ENUM
| TFF_TEMPLATE_NAME
);
2078 pp_cxx_begin_template_argument_list (pp
);
2080 /* Be careful only to print things when we have them, so as not
2081 to crash producing error messages. */
2082 if (args
&& !primary
)
2085 len
= get_non_default_template_args_count (args
, flags
);
2087 args
= INNERMOST_TEMPLATE_ARGS (args
);
2088 for (ix
= 0; ix
!= len
; ix
++)
2090 tree arg
= TREE_VEC_ELT (args
, ix
);
2092 /* Only print a comma if we know there is an argument coming. In
2093 the case of an empty template argument pack, no actual
2094 argument will be printed. */
2096 && (!ARGUMENT_PACK_P (arg
)
2097 || TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg
)) > 0))
2098 pp_separate_with_comma (pp
);
2101 pp_string (pp
, M_("<template parameter error>"));
2103 dump_template_argument (pp
, arg
, flags
);
2108 tree tpl
= TI_TEMPLATE (info
);
2109 tree parms
= DECL_TEMPLATE_PARMS (tpl
);
2112 parms
= TREE_CODE (parms
) == TREE_LIST
? TREE_VALUE (parms
) : NULL_TREE
;
2113 len
= parms
? TREE_VEC_LENGTH (parms
) : 0;
2115 for (ix
= 0; ix
!= len
; ix
++)
2119 if (TREE_VEC_ELT (parms
, ix
) == error_mark_node
)
2121 pp_string (pp
, M_("<template parameter error>"));
2125 parm
= TREE_VALUE (TREE_VEC_ELT (parms
, ix
));
2128 pp_separate_with_comma (pp
);
2130 dump_decl (pp
, parm
, flags
& ~TFF_DECL_SPECIFIERS
);
2133 pp_cxx_end_template_argument_list (pp
);
2136 /* Print out the arguments of CALL_EXPR T as a parenthesized list using
2137 flags FLAGS. Skip over the first argument if SKIPFIRST is true. */
2140 dump_call_expr_args (cxx_pretty_printer
*pp
, tree t
, int flags
, bool skipfirst
)
2143 call_expr_arg_iterator iter
;
2145 pp_cxx_left_paren (pp
);
2146 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, t
)
2152 dump_expr (pp
, arg
, flags
| TFF_EXPR_IN_PARENS
);
2153 if (more_call_expr_args_p (&iter
))
2154 pp_separate_with_comma (pp
);
2157 pp_cxx_right_paren (pp
);
2160 /* Print out the arguments of AGGR_INIT_EXPR T as a parenthesized list
2161 using flags FLAGS. Skip over the first argument if SKIPFIRST is
2165 dump_aggr_init_expr_args (cxx_pretty_printer
*pp
, tree t
, int flags
,
2169 aggr_init_expr_arg_iterator iter
;
2171 pp_cxx_left_paren (pp
);
2172 FOR_EACH_AGGR_INIT_EXPR_ARG (arg
, iter
, t
)
2178 dump_expr (pp
, arg
, flags
| TFF_EXPR_IN_PARENS
);
2179 if (more_aggr_init_expr_args_p (&iter
))
2180 pp_separate_with_comma (pp
);
2183 pp_cxx_right_paren (pp
);
2186 /* Print out a list of initializers (subr of dump_expr). */
2189 dump_expr_list (cxx_pretty_printer
*pp
, tree l
, int flags
)
2193 dump_expr (pp
, TREE_VALUE (l
), flags
| TFF_EXPR_IN_PARENS
);
2196 pp_separate_with_comma (pp
);
2200 /* Print out a vector of initializers (subr of dump_expr). */
2203 dump_expr_init_vec (cxx_pretty_printer
*pp
, vec
<constructor_elt
, va_gc
> *v
,
2206 unsigned HOST_WIDE_INT idx
;
2209 FOR_EACH_CONSTRUCTOR_VALUE (v
, idx
, value
)
2211 dump_expr (pp
, value
, flags
| TFF_EXPR_IN_PARENS
);
2212 if (idx
!= v
->length () - 1)
2213 pp_separate_with_comma (pp
);
2218 /* We've gotten an indirect REFERENCE (an OBJ_TYPE_REF) to a virtual
2219 function. Resolve it to a close relative -- in the sense of static
2220 type -- variant being overridden. That is close to what was written in
2221 the source code. Subroutine of dump_expr. */
2224 resolve_virtual_fun_from_obj_type_ref (tree ref
)
2226 tree obj_type
= TREE_TYPE (OBJ_TYPE_REF_TOKEN (ref
));
2227 HOST_WIDE_INT index
= tree_to_uhwi (OBJ_TYPE_REF_TOKEN (ref
));
2228 tree fun
= BINFO_VIRTUALS (TYPE_BINFO (TREE_TYPE (obj_type
)));
2231 fun
= TREE_CHAIN (fun
);
2232 index
-= (TARGET_VTABLE_USES_DESCRIPTORS
2233 ? TARGET_VTABLE_USES_DESCRIPTORS
: 1);
2239 /* Print out an expression E under control of FLAGS. */
2242 dump_expr (cxx_pretty_printer
*pp
, tree t
, int flags
)
2249 if (STATEMENT_CLASS_P (t
))
2251 pp_cxx_ws_string (pp
, M_("<statement>"));
2255 switch (TREE_CODE (t
))
2263 case NAMESPACE_DECL
:
2269 case IDENTIFIER_NODE
:
2270 dump_decl (pp
, t
, ((flags
& ~(TFF_DECL_SPECIFIERS
|TFF_RETURN_TYPE
2271 |TFF_TEMPLATE_HEADER
))
2272 | TFF_NO_TEMPLATE_BINDINGS
2273 | TFF_NO_FUNCTION_ARGUMENTS
));
2277 if (SSA_NAME_VAR (t
)
2278 && !DECL_ARTIFICIAL (SSA_NAME_VAR (t
)))
2279 dump_expr (pp
, SSA_NAME_VAR (t
), flags
);
2281 pp_cxx_ws_string (pp
, M_("<unknown>"));
2292 case USERDEF_LITERAL
:
2293 pp_cxx_userdef_literal (pp
, t
);
2297 /* While waiting for caret diagnostics, avoid printing
2298 __cxa_allocate_exception, __cxa_throw, and the like. */
2299 pp_cxx_ws_string (pp
, M_("<throw-expression>"));
2304 dump_type (pp
, PTRMEM_CST_CLASS (t
), flags
);
2305 pp_cxx_colon_colon (pp
);
2306 pp_cxx_tree_identifier (pp
, DECL_NAME (PTRMEM_CST_MEMBER (t
)));
2310 pp_cxx_left_paren (pp
);
2311 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2312 pp_separate_with_comma (pp
);
2313 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2314 pp_cxx_right_paren (pp
);
2319 pp_cxx_left_paren (pp
);
2320 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2321 pp_string (pp
, " ? ");
2322 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2323 pp_string (pp
, " : ");
2324 dump_expr (pp
, TREE_OPERAND (t
, 2), flags
| TFF_EXPR_IN_PARENS
);
2325 pp_cxx_right_paren (pp
);
2329 if (TREE_HAS_CONSTRUCTOR (t
))
2331 pp_cxx_ws_string (pp
, "new");
2332 pp_cxx_whitespace (pp
);
2333 dump_type (pp
, TREE_TYPE (TREE_TYPE (t
)), flags
);
2336 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2339 case AGGR_INIT_EXPR
:
2341 tree fn
= NULL_TREE
;
2343 if (TREE_CODE (AGGR_INIT_EXPR_FN (t
)) == ADDR_EXPR
)
2344 fn
= TREE_OPERAND (AGGR_INIT_EXPR_FN (t
), 0);
2346 if (fn
&& TREE_CODE (fn
) == FUNCTION_DECL
)
2348 if (DECL_CONSTRUCTOR_P (fn
))
2349 dump_type (pp
, DECL_CONTEXT (fn
), flags
);
2351 dump_decl (pp
, fn
, 0);
2354 dump_expr (pp
, AGGR_INIT_EXPR_FN (t
), 0);
2356 dump_aggr_init_expr_args (pp
, t
, flags
, true);
2361 tree fn
= CALL_EXPR_FN (t
);
2362 bool skipfirst
= false;
2364 /* Deal with internal functions. */
2365 if (fn
== NULL_TREE
)
2367 pp_string (pp
, internal_fn_name (CALL_EXPR_IFN (t
)));
2368 dump_call_expr_args (pp
, t
, flags
, skipfirst
);
2372 if (TREE_CODE (fn
) == ADDR_EXPR
)
2373 fn
= TREE_OPERAND (fn
, 0);
2375 /* Nobody is interested in seeing the guts of vcalls. */
2376 if (TREE_CODE (fn
) == OBJ_TYPE_REF
)
2377 fn
= resolve_virtual_fun_from_obj_type_ref (fn
);
2379 if (TREE_TYPE (fn
) != NULL_TREE
2380 && NEXT_CODE (fn
) == METHOD_TYPE
2381 && call_expr_nargs (t
))
2383 tree ob
= CALL_EXPR_ARG (t
, 0);
2384 if (TREE_CODE (ob
) == ADDR_EXPR
)
2386 dump_expr (pp
, TREE_OPERAND (ob
, 0),
2387 flags
| TFF_EXPR_IN_PARENS
);
2390 else if (!is_this_parameter (ob
))
2392 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2397 if (flag_sanitize
& SANITIZE_UNDEFINED
2398 && is_ubsan_builtin_p (fn
))
2400 pp_string (cxx_pp
, M_("<ubsan routine call>"));
2403 dump_expr (pp
, fn
, flags
| TFF_EXPR_IN_PARENS
);
2404 dump_call_expr_args (pp
, t
, flags
, skipfirst
);
2409 /* Note that this only works for G++ target exprs. If somebody
2410 builds a general TARGET_EXPR, there's no way to represent that
2411 it initializes anything other that the parameter slot for the
2412 default argument. Note we may have cleared out the first
2413 operand in expand_expr, so don't go killing ourselves. */
2414 if (TREE_OPERAND (t
, 1))
2415 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2418 case POINTER_PLUS_EXPR
:
2419 dump_binary_op (pp
, "+", t
, flags
);
2422 case POINTER_DIFF_EXPR
:
2423 dump_binary_op (pp
, "-", t
, flags
);
2428 dump_binary_op (pp
, OVL_OP_INFO (true, NOP_EXPR
)->name
, t
, flags
);
2434 case TRUNC_DIV_EXPR
:
2435 case TRUNC_MOD_EXPR
:
2443 case TRUTH_ANDIF_EXPR
:
2444 case TRUTH_ORIF_EXPR
:
2451 case SPACESHIP_EXPR
:
2452 case EXACT_DIV_EXPR
:
2453 dump_binary_op (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
, t
, flags
);
2457 case FLOOR_DIV_EXPR
:
2458 case ROUND_DIV_EXPR
:
2460 dump_binary_op (pp
, "/", t
, flags
);
2464 case FLOOR_MOD_EXPR
:
2465 case ROUND_MOD_EXPR
:
2466 dump_binary_op (pp
, "%", t
, flags
);
2471 tree ob
= TREE_OPERAND (t
, 0);
2472 if (INDIRECT_REF_P (ob
))
2474 ob
= TREE_OPERAND (ob
, 0);
2475 if (!is_this_parameter (ob
)
2476 && !is_dummy_object (ob
))
2478 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2479 if (TYPE_REF_P (TREE_TYPE (ob
)))
2487 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2488 if (TREE_CODE (ob
) != ARROW_EXPR
)
2491 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
& ~TFF_EXPR_IN_PARENS
);
2496 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2497 pp_cxx_left_bracket (pp
);
2498 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2499 pp_cxx_right_bracket (pp
);
2502 case UNARY_PLUS_EXPR
:
2503 dump_unary_op (pp
, "+", t
, flags
);
2507 if (TREE_CODE (TREE_OPERAND (t
, 0)) == FUNCTION_DECL
2508 || TREE_CODE (TREE_OPERAND (t
, 0)) == STRING_CST
2509 /* An ADDR_EXPR can have reference type. In that case, we
2510 shouldn't print the `&' doing so indicates to the user
2511 that the expression has pointer type. */
2513 && TYPE_REF_P (TREE_TYPE (t
))))
2514 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2515 else if (TREE_CODE (TREE_OPERAND (t
, 0)) == LABEL_DECL
)
2516 dump_unary_op (pp
, "&&", t
, flags
);
2518 dump_unary_op (pp
, "&", t
, flags
);
2522 if (TREE_HAS_CONSTRUCTOR (t
))
2524 t
= TREE_OPERAND (t
, 0);
2525 gcc_assert (TREE_CODE (t
) == CALL_EXPR
);
2526 dump_expr (pp
, CALL_EXPR_FN (t
), flags
| TFF_EXPR_IN_PARENS
);
2527 dump_call_expr_args (pp
, t
, flags
, true);
2531 if (TREE_OPERAND (t
,0) != NULL_TREE
2532 && TREE_TYPE (TREE_OPERAND (t
, 0))
2533 && NEXT_CODE (TREE_OPERAND (t
, 0)) == REFERENCE_TYPE
)
2534 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2536 dump_unary_op (pp
, "*", t
, flags
);
2541 /* Delegate to the base "C" pretty printer. */
2542 pp
->c_pretty_printer::unary_expression (t
);
2545 case TARGET_MEM_REF
:
2546 /* TARGET_MEM_REF can't appear directly from source, but can appear
2547 during late GIMPLE optimizations and through late diagnostic we might
2548 need to support it. Print it as dereferencing of a pointer after
2549 cast to the TARGET_MEM_REF type, with pointer arithmetics on some
2550 pointer to single byte types, so
2551 *(type *)((char *) ptr + step * index + index2) if all the operands
2552 are present and the casts are needed. */
2554 pp_cxx_left_paren (pp
);
2555 if (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (TMR_BASE (t
)))) == NULL_TREE
2556 || !integer_onep (TYPE_SIZE_UNIT
2557 (TREE_TYPE (TREE_TYPE (TMR_BASE (t
))))))
2559 if (TYPE_SIZE_UNIT (TREE_TYPE (t
))
2560 && integer_onep (TYPE_SIZE_UNIT (TREE_TYPE (t
))))
2562 pp_cxx_left_paren (pp
);
2563 dump_type (pp
, build_pointer_type (TREE_TYPE (t
)), flags
);
2567 dump_type (pp
, build_pointer_type (TREE_TYPE (t
)), flags
);
2568 pp_cxx_right_paren (pp
);
2569 pp_cxx_left_paren (pp
);
2570 pp_cxx_left_paren (pp
);
2571 dump_type (pp
, build_pointer_type (char_type_node
), flags
);
2573 pp_cxx_right_paren (pp
);
2575 else if (!same_type_p (TREE_TYPE (t
),
2576 TREE_TYPE (TREE_TYPE (TMR_BASE (t
)))))
2578 dump_type (pp
, build_pointer_type (TREE_TYPE (t
)), flags
);
2579 pp_cxx_right_paren (pp
);
2580 pp_cxx_left_paren (pp
);
2582 dump_expr (pp
, TMR_BASE (t
), flags
);
2583 if (TMR_STEP (t
) && TMR_INDEX (t
))
2585 pp_cxx_ws_string (pp
, "+");
2586 dump_expr (pp
, TMR_INDEX (t
), flags
);
2587 pp_cxx_ws_string (pp
, "*");
2588 dump_expr (pp
, TMR_STEP (t
), flags
);
2592 pp_cxx_ws_string (pp
, "+");
2593 dump_expr (pp
, TMR_INDEX2 (t
), flags
);
2595 if (!integer_zerop (TMR_OFFSET (t
)))
2597 pp_cxx_ws_string (pp
, "+");
2598 dump_expr (pp
, fold_convert (ssizetype
, TMR_OFFSET (t
)), flags
);
2600 pp_cxx_right_paren (pp
);
2605 case TRUTH_NOT_EXPR
:
2606 case PREDECREMENT_EXPR
:
2607 case PREINCREMENT_EXPR
:
2608 dump_unary_op (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
, t
, flags
);
2611 case POSTDECREMENT_EXPR
:
2612 case POSTINCREMENT_EXPR
:
2613 pp_cxx_left_paren (pp
);
2614 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2615 pp_cxx_ws_string (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
);
2616 pp_cxx_right_paren (pp
);
2619 case NON_LVALUE_EXPR
:
2620 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
2621 should be another level of INDIRECT_REF so that I don't have to do
2623 if (TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == POINTER_TYPE
)
2625 tree next
= TREE_TYPE (TREE_TYPE (t
));
2627 while (TYPE_PTR_P (next
))
2628 next
= TREE_TYPE (next
);
2630 if (TREE_CODE (next
) == FUNCTION_TYPE
)
2632 if (flags
& TFF_EXPR_IN_PARENS
)
2633 pp_cxx_left_paren (pp
);
2635 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2636 if (flags
& TFF_EXPR_IN_PARENS
)
2637 pp_cxx_right_paren (pp
);
2640 /* Else fall through. */
2642 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2646 case IMPLICIT_CONV_EXPR
:
2647 case VIEW_CONVERT_EXPR
:
2649 tree op
= TREE_OPERAND (t
, 0);
2651 if (location_wrapper_p (t
))
2653 dump_expr (pp
, op
, flags
);
2657 tree ttype
= TREE_TYPE (t
);
2658 tree optype
= TREE_TYPE (op
);
2660 if (TREE_CODE (ttype
) != TREE_CODE (optype
)
2661 && INDIRECT_TYPE_P (ttype
)
2662 && INDIRECT_TYPE_P (optype
)
2663 && same_type_p (TREE_TYPE (optype
),
2666 if (TYPE_REF_P (ttype
))
2669 if (TREE_CODE (op
) == ADDR_EXPR
)
2670 dump_expr (pp
, TREE_OPERAND (op
, 0), flags
);
2672 dump_unary_op (pp
, "*", t
, flags
);
2675 dump_unary_op (pp
, "&", t
, flags
);
2677 else if (!same_type_p (TREE_TYPE (op
), TREE_TYPE (t
)))
2679 /* It is a cast, but we cannot tell whether it is a
2680 reinterpret or static cast. Use the C style notation. */
2681 if (flags
& TFF_EXPR_IN_PARENS
)
2682 pp_cxx_left_paren (pp
);
2683 pp_cxx_left_paren (pp
);
2684 dump_type (pp
, TREE_TYPE (t
), flags
);
2685 pp_cxx_right_paren (pp
);
2686 dump_expr (pp
, op
, flags
| TFF_EXPR_IN_PARENS
);
2687 if (flags
& TFF_EXPR_IN_PARENS
)
2688 pp_cxx_right_paren (pp
);
2691 dump_expr (pp
, op
, flags
);
2696 if (TREE_TYPE (t
) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t
)))
2698 tree idx
= build_ptrmemfunc_access_expr (t
, pfn_identifier
);
2700 if (integer_zerop (idx
))
2702 /* A NULL pointer-to-member constant. */
2703 pp_cxx_left_paren (pp
);
2704 pp_cxx_left_paren (pp
);
2705 dump_type (pp
, TREE_TYPE (t
), flags
);
2706 pp_cxx_right_paren (pp
);
2707 pp_character (pp
, '0');
2708 pp_cxx_right_paren (pp
);
2711 else if (tree_fits_shwi_p (idx
))
2714 unsigned HOST_WIDE_INT n
;
2716 t
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t
)));
2717 t
= TYPE_METHOD_BASETYPE (t
);
2718 virtuals
= BINFO_VIRTUALS (TYPE_BINFO (TYPE_MAIN_VARIANT (t
)));
2720 n
= tree_to_shwi (idx
);
2722 /* Map vtable index back one, to allow for the null pointer to
2726 while (n
> 0 && virtuals
)
2729 virtuals
= TREE_CHAIN (virtuals
);
2733 dump_expr (pp
, BV_FN (virtuals
),
2734 flags
| TFF_EXPR_IN_PARENS
);
2739 if (TREE_TYPE (t
) && LAMBDA_TYPE_P (TREE_TYPE (t
)))
2740 pp_string (pp
, "<lambda closure object>");
2741 if (TREE_TYPE (t
) && EMPTY_CONSTRUCTOR_P (t
))
2743 dump_type (pp
, TREE_TYPE (t
), 0);
2744 pp_cxx_left_paren (pp
);
2745 pp_cxx_right_paren (pp
);
2749 if (!BRACE_ENCLOSED_INITIALIZER_P (t
))
2750 dump_type (pp
, TREE_TYPE (t
), 0);
2751 pp_cxx_left_brace (pp
);
2752 dump_expr_init_vec (pp
, CONSTRUCTOR_ELTS (t
), flags
);
2753 pp_cxx_right_brace (pp
);
2760 tree ob
= TREE_OPERAND (t
, 0);
2761 if (is_dummy_object (ob
))
2763 t
= TREE_OPERAND (t
, 1);
2764 if (TREE_CODE (t
) == FUNCTION_DECL
)
2766 dump_expr (pp
, t
, flags
| TFF_EXPR_IN_PARENS
);
2767 else if (BASELINK_P (t
))
2768 dump_expr (pp
, OVL_FIRST (BASELINK_FUNCTIONS (t
)),
2769 flags
| TFF_EXPR_IN_PARENS
);
2771 dump_decl (pp
, t
, flags
);
2775 if (INDIRECT_REF_P (ob
))
2777 dump_expr (pp
, TREE_OPERAND (ob
, 0), flags
| TFF_EXPR_IN_PARENS
);
2783 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2787 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2792 case TEMPLATE_PARM_INDEX
:
2793 dump_decl (pp
, TEMPLATE_PARM_DECL (t
), flags
& ~TFF_DECL_SPECIFIERS
);
2797 if (TREE_OPERAND (t
, 0) == NULL_TREE
2798 || TREE_CHAIN (TREE_OPERAND (t
, 0)))
2800 dump_type (pp
, TREE_TYPE (t
), flags
);
2801 pp_cxx_left_paren (pp
);
2802 dump_expr_list (pp
, TREE_OPERAND (t
, 0), flags
);
2803 pp_cxx_right_paren (pp
);
2807 pp_cxx_left_paren (pp
);
2808 dump_type (pp
, TREE_TYPE (t
), flags
);
2809 pp_cxx_right_paren (pp
);
2810 pp_cxx_left_paren (pp
);
2811 dump_expr_list (pp
, TREE_OPERAND (t
, 0), flags
);
2812 pp_cxx_right_paren (pp
);
2816 case STATIC_CAST_EXPR
:
2817 pp_cxx_ws_string (pp
, "static_cast");
2819 case REINTERPRET_CAST_EXPR
:
2820 pp_cxx_ws_string (pp
, "reinterpret_cast");
2822 case CONST_CAST_EXPR
:
2823 pp_cxx_ws_string (pp
, "const_cast");
2825 case DYNAMIC_CAST_EXPR
:
2826 pp_cxx_ws_string (pp
, "dynamic_cast");
2828 pp_cxx_begin_template_argument_list (pp
);
2829 dump_type (pp
, TREE_TYPE (t
), flags
);
2830 pp_cxx_end_template_argument_list (pp
);
2831 pp_cxx_left_paren (pp
);
2832 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2833 pp_cxx_right_paren (pp
);
2837 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2843 if (TREE_CODE (t
) == SIZEOF_EXPR
)
2844 pp_cxx_ws_string (pp
, "sizeof");
2845 else if (ALIGNOF_EXPR_STD_P (t
))
2846 pp_cxx_ws_string (pp
, "alignof");
2848 pp_cxx_ws_string (pp
, "__alignof__");
2849 op
= TREE_OPERAND (t
, 0);
2850 if (PACK_EXPANSION_P (op
))
2852 pp_string (pp
, "...");
2853 op
= PACK_EXPANSION_PATTERN (op
);
2855 pp_cxx_whitespace (pp
);
2856 pp_cxx_left_paren (pp
);
2857 if (TREE_CODE (t
) == SIZEOF_EXPR
&& SIZEOF_EXPR_TYPE_P (t
))
2858 dump_type (pp
, TREE_TYPE (op
), flags
);
2859 else if (TYPE_P (TREE_OPERAND (t
, 0)))
2860 dump_type (pp
, op
, flags
);
2862 dump_expr (pp
, op
, flags
);
2863 pp_cxx_right_paren (pp
);
2866 case AT_ENCODE_EXPR
:
2867 pp_cxx_ws_string (pp
, "@encode");
2868 pp_cxx_whitespace (pp
);
2869 pp_cxx_left_paren (pp
);
2870 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
2871 pp_cxx_right_paren (pp
);
2875 pp_cxx_ws_string (pp
, "noexcept");
2876 pp_cxx_whitespace (pp
);
2877 pp_cxx_left_paren (pp
);
2878 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2879 pp_cxx_right_paren (pp
);
2884 pp_cxx_ws_string (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
);
2885 pp_cxx_whitespace (pp
);
2886 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2889 case DEFERRED_PARSE
:
2890 pp_string (pp
, M_("<unparsed>"));
2893 case TRY_CATCH_EXPR
:
2894 case CLEANUP_POINT_EXPR
:
2895 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2898 case PSEUDO_DTOR_EXPR
:
2899 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2901 if (TREE_OPERAND (t
, 1))
2903 dump_type (pp
, TREE_OPERAND (t
, 1), flags
);
2904 pp_cxx_colon_colon (pp
);
2906 pp_cxx_complement (pp
);
2907 dump_type (pp
, TREE_OPERAND (t
, 2), flags
);
2910 case TEMPLATE_ID_EXPR
:
2911 dump_decl (pp
, t
, flags
);
2917 case STATEMENT_LIST
:
2918 /* We don't yet have a way of dumping statements in a
2919 human-readable format. */
2920 pp_string (pp
, "({...})");
2924 pp_string (pp
, "while (1) { ");
2925 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2926 pp_cxx_right_brace (pp
);
2930 pp_string (pp
, "if (");
2931 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2932 pp_string (pp
, ") break; ");
2936 dump_expr (pp
, BASELINK_FUNCTIONS (t
), flags
& ~TFF_EXPR_IN_PARENS
);
2939 case EMPTY_CLASS_EXPR
:
2940 dump_type (pp
, TREE_TYPE (t
), flags
);
2941 pp_cxx_left_paren (pp
);
2942 pp_cxx_right_paren (pp
);
2945 case NON_DEPENDENT_EXPR
:
2946 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2949 case ARGUMENT_PACK_SELECT
:
2950 dump_template_argument (pp
, ARGUMENT_PACK_SELECT_FROM_PACK (t
), flags
);
2964 pp_type_specifier_seq (pp
, t
);
2968 /* We get here when we want to print a dependent type as an
2969 id-expression, without any disambiguator decoration. */
2970 pp
->id_expression (t
);
2973 case TEMPLATE_TYPE_PARM
:
2974 case TEMPLATE_TEMPLATE_PARM
:
2975 case BOUND_TEMPLATE_TEMPLATE_PARM
:
2976 dump_type (pp
, t
, flags
);
2980 pp_cxx_trait (pp
, t
);
2984 pp_cxx_va_arg_expression (pp
, t
);
2988 pp_cxx_offsetof_expression (pp
, t
);
2991 case ADDRESSOF_EXPR
:
2992 pp_cxx_addressof_expression (pp
, t
);
2996 dump_decl (pp
, t
, flags
);
2999 case EXPR_PACK_EXPANSION
:
3000 case UNARY_LEFT_FOLD_EXPR
:
3001 case UNARY_RIGHT_FOLD_EXPR
:
3002 case BINARY_LEFT_FOLD_EXPR
:
3003 case BINARY_RIGHT_FOLD_EXPR
:
3010 case VEC_DELETE_EXPR
:
3017 case UNORDERED_EXPR
:
3027 case FIX_TRUNC_EXPR
:
3032 case TRUTH_AND_EXPR
:
3034 case TRUTH_XOR_EXPR
:
3035 if (flags
& TFF_EXPR_IN_PARENS
)
3036 pp_cxx_left_paren (pp
);
3038 if (flags
& TFF_EXPR_IN_PARENS
)
3039 pp_cxx_right_paren (pp
);
3043 dump_expr (pp
, resolve_virtual_fun_from_obj_type_ref (t
), flags
);
3047 pp_string (pp
, M_("<lambda>"));
3051 pp_cxx_left_paren (pp
);
3052 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
3053 pp_cxx_right_paren (pp
);
3057 pp_cxx_requires_expr (cxx_pp
, t
);
3061 pp_cxx_simple_requirement (cxx_pp
, t
);
3065 pp_cxx_type_requirement (cxx_pp
, t
);
3069 pp_cxx_compound_requirement (cxx_pp
, t
);
3073 pp_cxx_nested_requirement (cxx_pp
, t
);
3081 pp_cxx_constraint (cxx_pp
, t
);
3085 case PLACEHOLDER_EXPR
:
3086 pp_string (pp
, M_("*this"));
3090 dump_expr_list (pp
, t
, flags
);
3093 /* This list is incomplete, but should suffice for now.
3094 It is very important that `sorry' does not call
3095 `report_error_function'. That could cause an infinite loop. */
3097 pp_unsupported_tree (pp
, t
);
3100 pp_string (pp
, M_("<expression error>"));
3106 dump_binary_op (cxx_pretty_printer
*pp
, const char *opstring
, tree t
,
3109 pp_cxx_left_paren (pp
);
3110 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
3111 pp_cxx_whitespace (pp
);
3113 pp_cxx_ws_string (pp
, opstring
);
3115 pp_string (pp
, M_("<unknown operator>"));
3116 pp_cxx_whitespace (pp
);
3117 tree op1
= TREE_OPERAND (t
, 1);
3118 if (TREE_CODE (t
) == POINTER_PLUS_EXPR
3119 && TREE_CODE (op1
) == INTEGER_CST
3120 && tree_int_cst_sign_bit (op1
))
3121 /* A pointer minus an integer is represented internally as plus a very
3122 large number, don't expose that to users. */
3123 op1
= convert (ssizetype
, op1
);
3124 dump_expr (pp
, op1
, flags
| TFF_EXPR_IN_PARENS
);
3125 pp_cxx_right_paren (pp
);
3129 dump_unary_op (cxx_pretty_printer
*pp
, const char *opstring
, tree t
, int flags
)
3131 if (flags
& TFF_EXPR_IN_PARENS
)
3132 pp_cxx_left_paren (pp
);
3133 pp_cxx_ws_string (pp
, opstring
);
3134 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
3135 if (flags
& TFF_EXPR_IN_PARENS
)
3136 pp_cxx_right_paren (pp
);
3140 reinit_cxx_pp (void)
3142 pp_clear_output_area (cxx_pp
);
3143 cxx_pp
->padding
= pp_none
;
3144 pp_indentation (cxx_pp
) = 0;
3145 pp_needs_newline (cxx_pp
) = false;
3146 pp_show_color (cxx_pp
) = false;
3147 cxx_pp
->enclosing_scope
= current_function_decl
;
3150 /* Same as pp_formatted_text, except the return string is a separate
3151 copy and has a GGC storage duration, e.g. an indefinite lifetime. */
3154 pp_ggc_formatted_text (pretty_printer
*pp
)
3156 return ggc_strdup (pp_formatted_text (pp
));
3159 /* Exported interface to stringifying types, exprs and decls under TFF_*
3163 type_as_string (tree typ
, int flags
)
3166 pp_translate_identifiers (cxx_pp
) = false;
3167 dump_type (cxx_pp
, typ
, flags
);
3168 return pp_ggc_formatted_text (cxx_pp
);
3172 type_as_string_translate (tree typ
, int flags
)
3175 dump_type (cxx_pp
, typ
, flags
);
3176 return pp_ggc_formatted_text (cxx_pp
);
3180 expr_as_string (tree decl
, int flags
)
3183 pp_translate_identifiers (cxx_pp
) = false;
3184 dump_expr (cxx_pp
, decl
, flags
);
3185 return pp_ggc_formatted_text (cxx_pp
);
3188 /* Wrap decl_as_string with options appropriate for dwarf. */
3191 decl_as_dwarf_string (tree decl
, int flags
)
3194 /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag
3195 here will be adequate to get the desired behavior. */
3196 cxx_pp
->flags
|= pp_c_flag_gnu_v3
;
3197 name
= decl_as_string (decl
, flags
);
3198 /* Subsequent calls to the pretty printer shouldn't use this style. */
3199 cxx_pp
->flags
&= ~pp_c_flag_gnu_v3
;
3204 decl_as_string (tree decl
, int flags
)
3207 pp_translate_identifiers (cxx_pp
) = false;
3208 dump_decl (cxx_pp
, decl
, flags
);
3209 return pp_ggc_formatted_text (cxx_pp
);
3213 decl_as_string_translate (tree decl
, int flags
)
3216 dump_decl (cxx_pp
, decl
, flags
);
3217 return pp_ggc_formatted_text (cxx_pp
);
3220 /* Wrap lang_decl_name with options appropriate for dwarf. */
3223 lang_decl_dwarf_name (tree decl
, int v
, bool translate
)
3226 /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag
3227 here will be adequate to get the desired behavior. */
3228 cxx_pp
->flags
|= pp_c_flag_gnu_v3
;
3229 name
= lang_decl_name (decl
, v
, translate
);
3230 /* Subsequent calls to the pretty printer shouldn't use this style. */
3231 cxx_pp
->flags
&= ~pp_c_flag_gnu_v3
;
3235 /* Generate the three forms of printable names for cxx_printable_name. */
3238 lang_decl_name (tree decl
, int v
, bool translate
)
3242 ? decl_as_string_translate (decl
, TFF_DECL_SPECIFIERS
)
3243 : decl_as_string (decl
, TFF_DECL_SPECIFIERS
));
3246 pp_translate_identifiers (cxx_pp
) = translate
;
3248 && (DECL_CLASS_SCOPE_P (decl
)
3249 || (DECL_NAMESPACE_SCOPE_P (decl
)
3250 && CP_DECL_CONTEXT (decl
) != global_namespace
)))
3252 dump_type (cxx_pp
, CP_DECL_CONTEXT (decl
), TFF_PLAIN_IDENTIFIER
);
3253 pp_cxx_colon_colon (cxx_pp
);
3256 if (TREE_CODE (decl
) == FUNCTION_DECL
)
3257 dump_function_name (cxx_pp
, decl
, TFF_PLAIN_IDENTIFIER
);
3258 else if ((DECL_NAME (decl
) == NULL_TREE
)
3259 && TREE_CODE (decl
) == NAMESPACE_DECL
)
3260 dump_decl (cxx_pp
, decl
, TFF_PLAIN_IDENTIFIER
| TFF_UNQUALIFIED_NAME
);
3262 dump_decl (cxx_pp
, DECL_NAME (decl
), TFF_PLAIN_IDENTIFIER
);
3264 return pp_ggc_formatted_text (cxx_pp
);
3267 /* Return the location of a tree passed to %+ formats. */
3270 location_of (tree t
)
3274 t
= TYPE_MAIN_DECL (t
);
3276 return input_location
;
3278 else if (TREE_CODE (t
) == OVERLOAD
)
3282 return DECL_SOURCE_LOCATION (t
);
3283 if (TREE_CODE (t
) == DEFERRED_PARSE
)
3284 return defparse_location (t
);
3285 return cp_expr_loc_or_input_loc (t
);
3288 /* Now the interfaces from error et al to dump_type et al. Each takes an
3289 on/off VERBOSE flag and supply the appropriate TFF_ flags to a dump_
3293 decl_to_string (tree decl
, int verbose
, bool show_color
)
3297 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == RECORD_TYPE
3298 || TREE_CODE (decl
) == UNION_TYPE
|| TREE_CODE (decl
) == ENUMERAL_TYPE
)
3299 flags
= TFF_CLASS_KEY_OR_ENUM
;
3301 flags
|= TFF_DECL_SPECIFIERS
;
3302 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
3303 flags
|= TFF_DECL_SPECIFIERS
| TFF_RETURN_TYPE
;
3304 flags
|= TFF_TEMPLATE_HEADER
;
3307 pp_show_color (cxx_pp
) = show_color
;
3308 dump_decl (cxx_pp
, decl
, flags
);
3309 return pp_ggc_formatted_text (cxx_pp
);
3313 expr_to_string (tree decl
)
3316 dump_expr (cxx_pp
, decl
, 0);
3317 return pp_ggc_formatted_text (cxx_pp
);
3321 fndecl_to_string (tree fndecl
, int verbose
)
3325 flags
= TFF_EXCEPTION_SPECIFICATION
| TFF_DECL_SPECIFIERS
3326 | TFF_TEMPLATE_HEADER
;
3328 flags
|= TFF_FUNCTION_DEFAULT_ARGUMENTS
;
3330 dump_decl (cxx_pp
, fndecl
, flags
);
3331 return pp_ggc_formatted_text (cxx_pp
);
3336 code_to_string (enum tree_code c
)
3338 return get_tree_code_name (c
);
3342 language_to_string (enum languages c
)
3349 case lang_cplusplus
:
3358 /* Return the proper printed version of a parameter to a C++ function. */
3361 parm_to_string (int p
)
3365 pp_string (cxx_pp
, "'this'");
3367 pp_decimal_int (cxx_pp
, p
+ 1);
3368 return pp_ggc_formatted_text (cxx_pp
);
3372 op_to_string (bool assop
, enum tree_code p
)
3374 tree id
= ovl_op_identifier (assop
, p
);
3375 return id
? IDENTIFIER_POINTER (id
) : M_("<unknown>");
3378 /* Return a GC-allocated representation of type TYP, with verbosity VERBOSE.
3380 If QUOTE is non-NULL and if *QUOTE is true, then quotes are added to the
3381 string in appropriate places, and *QUOTE is written to with false
3382 to suppress pp_format's trailing close quote so that e.g.
3383 foo_typedef {aka underlying_foo} {enum}
3384 can be printed by "%qT" as:
3385 `foo_typedef' {aka `underlying_foo'} {enum}
3387 `foo_typedef {aka underlying_foo} {enum}'
3388 When adding such quotes, if POSTPROCESSED is true (for handling %H and %I)
3389 then a leading open quote will be added, whereas if POSTPROCESSED is false
3390 (for handling %T) then any leading quote has already been added by
3391 pp_format, or is not needed due to QUOTE being NULL (for template arguments
3394 SHOW_COLOR is used to determine the colorization of any quotes that
3398 type_to_string (tree typ
, int verbose
, bool postprocessed
, bool *quote
,
3403 flags
|= TFF_CLASS_KEY_OR_ENUM
;
3404 flags
|= TFF_TEMPLATE_HEADER
;
3407 pp_show_color (cxx_pp
) = show_color
;
3409 if (postprocessed
&& quote
&& *quote
)
3410 pp_begin_quote (cxx_pp
, show_color
);
3412 struct obstack
*ob
= pp_buffer (cxx_pp
)->obstack
;
3413 int type_start
, type_len
;
3414 type_start
= obstack_object_size (ob
);
3416 dump_type (cxx_pp
, typ
, flags
);
3418 /* Remember the end of the initial dump. */
3419 type_len
= obstack_object_size (ob
) - type_start
;
3421 /* If we're printing a type that involves typedefs, also print the
3422 stripped version. But sometimes the stripped version looks
3423 exactly the same, so we don't want it after all. To avoid printing
3424 it in that case, we play ugly obstack games. */
3425 if (typ
&& TYPE_P (typ
) && typ
!= TYPE_CANONICAL (typ
)
3426 && !uses_template_parms (typ
))
3428 int aka_start
, aka_len
; char *p
;
3429 tree aka
= strip_typedefs (typ
, NULL
, STF_USER_VISIBLE
);
3430 if (quote
&& *quote
)
3431 pp_end_quote (cxx_pp
, show_color
);
3432 pp_string (cxx_pp
, " {aka");
3433 pp_cxx_whitespace (cxx_pp
);
3434 if (quote
&& *quote
)
3435 pp_begin_quote (cxx_pp
, show_color
);
3436 /* And remember the start of the aka dump. */
3437 aka_start
= obstack_object_size (ob
);
3438 dump_type (cxx_pp
, aka
, flags
);
3439 aka_len
= obstack_object_size (ob
) - aka_start
;
3440 if (quote
&& *quote
)
3441 pp_end_quote (cxx_pp
, show_color
);
3442 pp_right_brace (cxx_pp
);
3443 p
= (char*)obstack_base (ob
);
3444 /* If they are identical, cut off the aka by unwinding the obstack. */
3445 if (type_len
== aka_len
3446 && memcmp (p
+ type_start
, p
+aka_start
, type_len
) == 0)
3448 /* We can't add a '\0' here, since we may be adding a closing quote
3449 below, and it would be hidden by the '\0'.
3450 Instead, manually unwind the current object within the obstack
3451 so that the insertion point is at the end of the type, before
3453 int delta
= type_start
+ type_len
- obstack_object_size (ob
);
3454 gcc_assert (delta
<= 0);
3455 obstack_blank_fast (ob
, delta
);
3459 /* No further closing quotes are needed. */
3463 if (quote
&& *quote
)
3465 pp_end_quote (cxx_pp
, show_color
);
3468 return pp_ggc_formatted_text (cxx_pp
);
3472 args_to_string (tree p
, int verbose
)
3476 flags
|= TFF_CLASS_KEY_OR_ENUM
;
3481 if (TYPE_P (TREE_VALUE (p
)))
3482 return type_as_string_translate (p
, flags
);
3485 for (; p
; p
= TREE_CHAIN (p
))
3487 if (null_node_p (TREE_VALUE (p
)))
3488 pp_cxx_ws_string (cxx_pp
, "NULL");
3490 dump_type (cxx_pp
, error_type (TREE_VALUE (p
)), flags
);
3492 pp_separate_with_comma (cxx_pp
);
3494 return pp_ggc_formatted_text (cxx_pp
);
3497 /* Pretty-print a deduction substitution (from deduction_tsubst_fntype). P
3498 is a TREE_LIST with purpose the TEMPLATE_DECL, value the template
3502 subst_to_string (tree p
, bool show_color
)
3504 tree decl
= TREE_PURPOSE (p
);
3505 tree targs
= TREE_VALUE (p
);
3506 tree tparms
= DECL_TEMPLATE_PARMS (decl
);
3507 int flags
= (TFF_DECL_SPECIFIERS
|TFF_TEMPLATE_HEADER
3508 |TFF_NO_TEMPLATE_BINDINGS
);
3514 pp_show_color (cxx_pp
) = show_color
;
3515 dump_template_decl (cxx_pp
, TREE_PURPOSE (p
), flags
);
3516 dump_substitution (cxx_pp
, NULL
, tparms
, targs
, /*flags=*/0);
3517 return pp_ggc_formatted_text (cxx_pp
);
3521 cv_to_string (tree p
, int v
)
3524 cxx_pp
->padding
= v
? pp_before
: pp_none
;
3525 pp_cxx_cv_qualifier_seq (cxx_pp
, p
);
3526 return pp_ggc_formatted_text (cxx_pp
);
3530 eh_spec_to_string (tree p
, int /*v*/)
3534 dump_exception_spec (cxx_pp
, p
, flags
);
3535 return pp_ggc_formatted_text (cxx_pp
);
3538 /* Langhook for print_error_function. */
3540 cxx_print_error_function (diagnostic_context
*context
, const char *file
,
3541 diagnostic_info
*diagnostic
)
3545 prefix
= xstrdup (file
);
3548 lhd_print_error_function (context
, file
, diagnostic
);
3549 pp_set_prefix (context
->printer
, prefix
);
3550 maybe_print_instantiation_context (context
);
3554 cp_diagnostic_starter (diagnostic_context
*context
,
3555 diagnostic_info
*diagnostic
)
3557 diagnostic_report_current_module (context
, diagnostic_location (diagnostic
));
3558 cp_print_error_function (context
, diagnostic
);
3559 maybe_print_instantiation_context (context
);
3560 maybe_print_constexpr_context (context
);
3561 maybe_print_constraint_context (context
);
3562 pp_set_prefix (context
->printer
, diagnostic_build_prefix (context
,
3566 /* Print current function onto BUFFER, in the process of reporting
3567 a diagnostic message. Called from cp_diagnostic_starter. */
3569 cp_print_error_function (diagnostic_context
*context
,
3570 diagnostic_info
*diagnostic
)
3572 /* If we are in an instantiation context, current_function_decl is likely
3573 to be wrong, so just rely on print_instantiation_full_context. */
3574 if (current_instantiation ())
3576 /* The above is true for constraint satisfaction also. */
3577 if (current_failed_constraint
)
3579 if (diagnostic_last_function_changed (context
, diagnostic
))
3581 char *old_prefix
= pp_take_prefix (context
->printer
);
3582 const char *file
= LOCATION_FILE (diagnostic_location (diagnostic
));
3583 tree abstract_origin
= diagnostic_abstract_origin (diagnostic
);
3584 char *new_prefix
= (file
&& abstract_origin
== NULL
)
3585 ? file_name_as_prefix (context
, file
) : NULL
;
3587 pp_set_prefix (context
->printer
, new_prefix
);
3589 if (current_function_decl
== NULL
)
3590 pp_string (context
->printer
, _("At global scope:"));
3595 if (abstract_origin
)
3597 ao
= BLOCK_ABSTRACT_ORIGIN (abstract_origin
);
3598 gcc_assert (TREE_CODE (ao
) == FUNCTION_DECL
);
3602 fndecl
= current_function_decl
;
3604 pp_printf (context
->printer
, function_category (fndecl
),
3607 while (abstract_origin
)
3610 tree block
= abstract_origin
;
3612 locus
= &BLOCK_SOURCE_LOCATION (block
);
3614 block
= BLOCK_SUPERCONTEXT (block
);
3615 while (block
&& TREE_CODE (block
) == BLOCK
3616 && BLOCK_ABSTRACT_ORIGIN (block
))
3618 ao
= BLOCK_ABSTRACT_ORIGIN (block
);
3619 if (TREE_CODE (ao
) == FUNCTION_DECL
)
3624 else if (TREE_CODE (ao
) != BLOCK
)
3627 block
= BLOCK_SUPERCONTEXT (block
);
3630 abstract_origin
= block
;
3633 while (block
&& TREE_CODE (block
) == BLOCK
)
3634 block
= BLOCK_SUPERCONTEXT (block
);
3636 if (block
&& TREE_CODE (block
) == FUNCTION_DECL
)
3638 abstract_origin
= NULL
;
3642 expanded_location s
= expand_location (*locus
);
3643 pp_character (context
->printer
, ',');
3644 pp_newline (context
->printer
);
3647 if (context
->show_column
&& s
.column
!= 0)
3648 pp_printf (context
->printer
,
3649 _(" inlined from %qD at %r%s:%d:%d%R"),
3651 "locus", s
.file
, s
.line
, s
.column
);
3653 pp_printf (context
->printer
,
3654 _(" inlined from %qD at %r%s:%d%R"),
3656 "locus", s
.file
, s
.line
);
3660 pp_printf (context
->printer
, _(" inlined from %qD"),
3664 pp_character (context
->printer
, ':');
3666 pp_newline (context
->printer
);
3668 diagnostic_set_last_function (context
, diagnostic
);
3669 pp_destroy_prefix (context
->printer
);
3670 context
->printer
->prefix
= old_prefix
;
3674 /* Returns a description of FUNCTION using standard terminology. The
3675 result is a format string of the form "In CATEGORY %qD". */
3678 function_category (tree fn
)
3680 /* We can get called from the middle-end for diagnostics of function
3681 clones. Make sure we have language specific information before
3682 dereferencing it. */
3683 if (DECL_LANG_SPECIFIC (STRIP_TEMPLATE (fn
))
3684 && DECL_FUNCTION_MEMBER_P (fn
))
3686 if (DECL_STATIC_FUNCTION_P (fn
))
3687 return _("In static member function %qD");
3688 else if (DECL_COPY_CONSTRUCTOR_P (fn
))
3689 return _("In copy constructor %qD");
3690 else if (DECL_CONSTRUCTOR_P (fn
))
3691 return _("In constructor %qD");
3692 else if (DECL_DESTRUCTOR_P (fn
))
3693 return _("In destructor %qD");
3694 else if (LAMBDA_FUNCTION_P (fn
))
3695 return _("In lambda function");
3697 return _("In member function %qD");
3700 return _("In function %qD");
3703 /* Disable warnings about missing quoting in GCC diagnostics for
3704 the pp_verbatim calls. Their format strings deliberately don't
3705 follow GCC diagnostic conventions. */
3707 #pragma GCC diagnostic push
3708 #pragma GCC diagnostic ignored "-Wformat-diag"
3711 /* Report the full context of a current template instantiation,
3714 print_instantiation_full_context (diagnostic_context
*context
)
3716 struct tinst_level
*p
= current_instantiation ();
3717 location_t location
= input_location
;
3721 pp_verbatim (context
->printer
,
3723 ? _("%s: In substitution of %qS:\n")
3724 : _("%s: In instantiation of %q#D:\n"),
3725 LOCATION_FILE (location
),
3728 location
= p
->locus
;
3732 print_instantiation_partial_context (context
, p
, location
);
3735 /* Helper function of print_instantiation_partial_context() that
3736 prints a single line of instantiation context. */
3739 print_instantiation_partial_context_line (diagnostic_context
*context
,
3740 struct tinst_level
*t
,
3741 location_t loc
, bool recursive_p
)
3743 if (loc
== UNKNOWN_LOCATION
)
3746 expanded_location xloc
= expand_location (loc
);
3748 if (context
->show_column
)
3749 pp_verbatim (context
->printer
, _("%r%s:%d:%d:%R "),
3750 "locus", xloc
.file
, xloc
.line
, xloc
.column
);
3752 pp_verbatim (context
->printer
, _("%r%s:%d:%R "),
3753 "locus", xloc
.file
, xloc
.line
);
3758 pp_verbatim (context
->printer
,
3760 ? _("recursively required by substitution of %qS\n")
3761 : _("required by substitution of %qS\n"),
3764 pp_verbatim (context
->printer
,
3766 ? _("recursively required from %q#D\n")
3767 : _("required from %q#D\n"),
3772 pp_verbatim (context
->printer
,
3774 ? _("recursively required from here\n")
3775 : _("required from here\n"));
3779 /* Same as print_instantiation_full_context but less verbose. */
3782 print_instantiation_partial_context (diagnostic_context
*context
,
3783 struct tinst_level
*t0
, location_t loc
)
3785 struct tinst_level
*t
;
3788 location_t prev_loc
= loc
;
3790 for (t
= t0
; t
!= NULL
; t
= t
->next
)
3791 if (prev_loc
!= t
->locus
)
3793 prev_loc
= t
->locus
;
3799 if (template_backtrace_limit
3800 && n_total
> template_backtrace_limit
)
3802 int skip
= n_total
- template_backtrace_limit
;
3803 int head
= template_backtrace_limit
/ 2;
3805 /* Avoid skipping just 1. If so, skip 2. */
3809 head
= (template_backtrace_limit
- 1) / 2;
3812 for (n
= 0; n
< head
; n
++)
3814 gcc_assert (t
!= NULL
);
3815 if (loc
!= t
->locus
)
3816 print_instantiation_partial_context_line (context
, t
, loc
,
3817 /*recursive_p=*/false);
3821 if (t
!= NULL
&& skip
> 0)
3823 expanded_location xloc
;
3824 xloc
= expand_location (loc
);
3825 if (context
->show_column
)
3826 pp_verbatim (context
->printer
,
3827 _("%r%s:%d:%d:%R [ skipping %d instantiation "
3828 "contexts, use -ftemplate-backtrace-limit=0 to "
3830 "locus", xloc
.file
, xloc
.line
, xloc
.column
, skip
);
3832 pp_verbatim (context
->printer
,
3833 _("%r%s:%d:%R [ skipping %d instantiation "
3834 "contexts, use -ftemplate-backtrace-limit=0 to "
3836 "locus", xloc
.file
, xloc
.line
, skip
);
3841 } while (t
!= NULL
&& --skip
> 0);
3847 while (t
->next
!= NULL
&& t
->locus
== t
->next
->locus
)
3852 print_instantiation_partial_context_line (context
, t
, loc
,
3857 print_instantiation_partial_context_line (context
, NULL
, loc
,
3858 /*recursive_p=*/false);
3861 /* Called from cp_thing to print the template context for an error. */
3863 maybe_print_instantiation_context (diagnostic_context
*context
)
3865 if (!problematic_instantiation_changed () || current_instantiation () == 0)
3868 record_last_problematic_instantiation ();
3869 print_instantiation_full_context (context
);
3872 /* Report what constexpr call(s) we're trying to expand, if any. */
3875 maybe_print_constexpr_context (diagnostic_context
*context
)
3877 vec
<tree
> call_stack
= cx_error_context ();
3881 FOR_EACH_VEC_ELT (call_stack
, ix
, t
)
3883 expanded_location xloc
= expand_location (EXPR_LOCATION (t
));
3884 const char *s
= expr_as_string (t
, 0);
3885 if (context
->show_column
)
3886 pp_verbatim (context
->printer
,
3887 _("%r%s:%d:%d:%R in %<constexpr%> expansion of %qs"),
3888 "locus", xloc
.file
, xloc
.line
, xloc
.column
, s
);
3890 pp_verbatim (context
->printer
,
3891 _("%r%s:%d:%R in %<constexpr%> expansion of %qs"),
3892 "locus", xloc
.file
, xloc
.line
, s
);
3893 pp_newline (context
->printer
);
3899 print_location (diagnostic_context
*context
, location_t loc
)
3901 expanded_location xloc
= expand_location (loc
);
3902 if (context
->show_column
)
3903 pp_verbatim (context
->printer
, _("%r%s:%d:%d:%R "),
3904 "locus", xloc
.file
, xloc
.line
, xloc
.column
);
3906 pp_verbatim (context
->printer
, _("%r%s:%d:%R "),
3907 "locus", xloc
.file
, xloc
.line
);
3911 print_constrained_decl_info (diagnostic_context
*context
, tree decl
)
3913 print_location (context
, DECL_SOURCE_LOCATION (decl
));
3914 pp_verbatim (context
->printer
, "required by the constraints of %q#D\n", decl
);
3918 print_concept_check_info (diagnostic_context
*context
, tree expr
, tree map
, tree args
)
3920 gcc_assert (concept_check_p (expr
));
3922 tree id
= unpack_concept_check (expr
);
3923 tree tmpl
= TREE_OPERAND (id
, 0);
3925 tmpl
= OVL_FIRST (tmpl
);
3927 print_location (context
, DECL_SOURCE_LOCATION (tmpl
));
3929 cxx_pretty_printer
*pp
= (cxx_pretty_printer
*)context
->printer
;
3930 pp_verbatim (pp
, "required for the satisfaction of %qE", expr
);
3931 if (map
&& map
!= error_mark_node
)
3933 tree subst_map
= tsubst_parameter_mapping (map
, args
, tf_none
, NULL_TREE
);
3934 pp_cxx_parameter_mapping (pp
, (subst_map
!= error_mark_node
3935 ? subst_map
: map
));
3940 /* Diagnose the entry point into the satisfaction error. Returns the next
3944 print_constraint_context_head (diagnostic_context
*context
, tree cxt
, tree args
)
3946 tree src
= TREE_VALUE (cxt
);
3949 print_location (context
, input_location
);
3950 pp_verbatim (context
->printer
, "required for constraint satisfaction\n");
3955 print_constrained_decl_info (context
, src
);
3960 print_concept_check_info (context
, src
, TREE_PURPOSE (cxt
), args
);
3961 return TREE_CHAIN (cxt
);
3966 print_requires_expression_info (diagnostic_context
*context
, tree constr
, tree args
)
3969 tree expr
= ATOMIC_CONSTR_EXPR (constr
);
3970 tree map
= ATOMIC_CONSTR_MAP (constr
);
3971 map
= tsubst_parameter_mapping (map
, args
, tf_none
, NULL_TREE
);
3972 if (map
== error_mark_node
)
3975 print_location (context
, cp_expr_loc_or_input_loc (expr
));
3976 pp_verbatim (context
->printer
, "in requirements ");
3978 tree parms
= TREE_OPERAND (expr
, 0);
3980 pp_verbatim (context
->printer
, "with ");
3983 pp_verbatim (context
->printer
, "%q#D", parms
);
3984 if (TREE_CHAIN (parms
))
3985 pp_separate_with_comma ((cxx_pretty_printer
*)context
->printer
);
3986 parms
= TREE_CHAIN (parms
);
3988 pp_cxx_parameter_mapping ((cxx_pretty_printer
*)context
->printer
, map
);
3990 pp_verbatim (context
->printer
, "\n");
3994 maybe_print_single_constraint_context (diagnostic_context
*context
, tree failed
)
3999 tree constr
= TREE_VALUE (failed
);
4000 if (!constr
|| constr
== error_mark_node
)
4002 tree cxt
= CONSTR_CONTEXT (constr
);
4005 tree args
= TREE_PURPOSE (failed
);
4007 /* Print the stack of requirements. */
4008 cxt
= print_constraint_context_head (context
, cxt
, args
);
4009 while (cxt
&& !DECL_P (TREE_VALUE (cxt
)))
4011 tree expr
= TREE_VALUE (cxt
);
4012 tree map
= TREE_PURPOSE (cxt
);
4013 print_concept_check_info (context
, expr
, map
, args
);
4014 cxt
= TREE_CHAIN (cxt
);
4017 /* For certain constraints, we can provide additional context. */
4018 if (TREE_CODE (constr
) == ATOMIC_CONSTR
4019 && TREE_CODE (ATOMIC_CONSTR_EXPR (constr
)) == REQUIRES_EXPR
)
4020 print_requires_expression_info (context
, constr
, args
);
4024 maybe_print_constraint_context (diagnostic_context
*context
)
4026 if (!current_failed_constraint
)
4029 tree cur
= current_failed_constraint
;
4031 /* Recursively print nested contexts. */
4032 current_failed_constraint
= TREE_CHAIN (current_failed_constraint
);
4033 if (current_failed_constraint
)
4034 maybe_print_constraint_context (context
);
4036 /* Print this context. */
4037 maybe_print_single_constraint_context (context
, cur
);
4040 /* Return true iff TYPE_A and TYPE_B are template types that are
4041 meaningful to compare. */
4044 comparable_template_types_p (tree type_a
, tree type_b
)
4046 if (!CLASS_TYPE_P (type_a
))
4048 if (!CLASS_TYPE_P (type_b
))
4051 tree tinfo_a
= TYPE_TEMPLATE_INFO (type_a
);
4052 tree tinfo_b
= TYPE_TEMPLATE_INFO (type_b
);
4053 if (!tinfo_a
|| !tinfo_b
)
4056 return TI_TEMPLATE (tinfo_a
) == TI_TEMPLATE (tinfo_b
);
4059 /* Start a new line indented by SPC spaces on PP. */
4062 newline_and_indent (pretty_printer
*pp
, int spc
)
4065 for (int i
= 0; i
< spc
; i
++)
4069 /* Generate a GC-allocated string for ARG, an expression or type. */
4072 arg_to_string (tree arg
, bool verbose
)
4075 return type_to_string (arg
, verbose
, true, NULL
, false);
4077 return expr_to_string (arg
);
4080 /* Subroutine to type_to_string_with_compare and
4081 print_template_tree_comparison.
4083 Print a representation of ARG (an expression or type) to PP,
4084 colorizing it as "type-diff" if PP->show_color. */
4087 print_nonequal_arg (pretty_printer
*pp
, tree arg
, bool verbose
)
4089 pp_printf (pp
, "%r%s%R",
4092 ? arg_to_string (arg
, verbose
)
4093 : G_("(no argument)")));
4096 /* Recursively print template TYPE_A to PP, as compared to template TYPE_B.
4098 The types must satisfy comparable_template_types_p.
4100 If INDENT is 0, then this is equivalent to type_to_string (TYPE_A), but
4101 potentially colorizing/eliding in comparison with TYPE_B.
4103 For example given types:
4104 vector<map<int,double>>
4106 vector<map<int,float>>
4107 then the result on PP would be:
4108 vector<map<[...],double>>
4109 with type elision, and:
4110 vector<map<int,double>>
4111 without type elision.
4113 In both cases the parts of TYPE that differ from PEER will be colorized
4114 if pp_show_color (pp) is true. In the above example, this would be
4117 If INDENT is non-zero, then the types are printed in a tree-like form
4118 which shows both types. In the above example, the result on PP would be:
4125 and without type-elision would be:
4132 As before, the differing parts of the types are colorized if
4133 pp_show_color (pp) is true ("double" and "float" in this example).
4135 Template arguments in which both types are using the default arguments
4136 are not printed; if at least one of the two types is using a non-default
4137 argument, then that argument is printed (or both arguments for the
4138 tree-like print format). */
4141 print_template_differences (pretty_printer
*pp
, tree type_a
, tree type_b
,
4142 bool verbose
, int indent
)
4145 newline_and_indent (pp
, indent
);
4147 tree tinfo_a
= TYPE_TEMPLATE_INFO (type_a
);
4148 tree tinfo_b
= TYPE_TEMPLATE_INFO (type_b
);
4150 pp_printf (pp
, "%s<",
4151 IDENTIFIER_POINTER (DECL_NAME (TI_TEMPLATE (tinfo_a
))));
4153 tree args_a
= TI_ARGS (tinfo_a
);
4154 tree args_b
= TI_ARGS (tinfo_b
);
4155 gcc_assert (TREE_CODE (args_a
) == TREE_VEC
);
4156 gcc_assert (TREE_CODE (args_b
) == TREE_VEC
);
4158 int len_a
= get_non_default_template_args_count (args_a
, flags
);
4159 args_a
= INNERMOST_TEMPLATE_ARGS (args_a
);
4160 int len_b
= get_non_default_template_args_count (args_b
, flags
);
4161 args_b
= INNERMOST_TEMPLATE_ARGS (args_b
);
4162 /* Determine the maximum range of args for which non-default template args
4163 were used; beyond this, only default args (if any) were used, and so
4164 they will be equal from this point onwards.
4165 One of the two peers might have used default arguments within this
4166 range, but the other will be using non-default arguments, and so
4167 it's more readable to print both within this range, to highlight
4169 int len_max
= MAX (len_a
, len_b
);
4170 gcc_assert (TREE_CODE (args_a
) == TREE_VEC
);
4171 gcc_assert (TREE_CODE (args_b
) == TREE_VEC
);
4172 for (int idx
= 0; idx
< len_max
; idx
++)
4175 pp_character (pp
, ',');
4177 tree arg_a
= TREE_VEC_ELT (args_a
, idx
);
4178 tree arg_b
= TREE_VEC_ELT (args_b
, idx
);
4182 newline_and_indent (pp
, indent
+ 2);
4183 /* Can do elision here, printing "[...]". */
4184 if (flag_elide_type
)
4185 pp_string (pp
, G_("[...]"));
4187 pp_string (pp
, arg_to_string (arg_a
, verbose
));
4191 int new_indent
= indent
? indent
+ 2 : 0;
4192 if (comparable_template_types_p (arg_a
, arg_b
))
4193 print_template_differences (pp
, arg_a
, arg_b
, verbose
, new_indent
);
4197 newline_and_indent (pp
, indent
+ 2);
4198 pp_character (pp
, '[');
4199 print_nonequal_arg (pp
, arg_a
, verbose
);
4200 pp_string (pp
, " != ");
4201 print_nonequal_arg (pp
, arg_b
, verbose
);
4202 pp_character (pp
, ']');
4205 print_nonequal_arg (pp
, arg_a
, verbose
);
4208 pp_printf (pp
, ">");
4211 /* As type_to_string, but for a template, potentially colorizing/eliding
4212 in comparison with PEER.
4213 For example, if TYPE is map<int,double> and PEER is map<int,int>,
4214 then the resulting string would be:
4216 with type elision, and:
4218 without type elision.
4220 In both cases the parts of TYPE that differ from PEER will be colorized
4221 if SHOW_COLOR is true. In the above example, this would be "double".
4223 Template arguments in which both types are using the default arguments
4224 are not printed; if at least one of the two types is using a non-default
4225 argument, then both arguments are printed.
4227 The resulting string is in a GC-allocated buffer. */
4230 type_to_string_with_compare (tree type
, tree peer
, bool verbose
,
4233 pretty_printer inner_pp
;
4234 pretty_printer
*pp
= &inner_pp
;
4235 pp_show_color (pp
) = show_color
;
4237 print_template_differences (pp
, type
, peer
, verbose
, 0);
4238 return pp_ggc_formatted_text (pp
);
4241 /* Recursively print a tree-like comparison of TYPE_A and TYPE_B to PP,
4242 indented by INDENT spaces.
4244 For example given types:
4246 vector<map<int,double>>
4250 vector<map<double,float>>
4252 the output with type elision would be:
4259 and without type-elision would be:
4266 TYPE_A and TYPE_B must both be comparable template types
4267 (as per comparable_template_types_p).
4269 Template arguments in which both types are using the default arguments
4270 are not printed; if at least one of the two types is using a non-default
4271 argument, then both arguments are printed. */
4274 print_template_tree_comparison (pretty_printer
*pp
, tree type_a
, tree type_b
,
4275 bool verbose
, int indent
)
4277 print_template_differences (pp
, type_a
, type_b
, verbose
, indent
);
4280 /* Subroutine for use in a format_postprocessor::handle
4281 implementation. Adds a chunk to the end of
4282 formatted output, so that it will be printed
4283 by pp_output_formatted_text. */
4286 append_formatted_chunk (pretty_printer
*pp
, const char *content
)
4288 output_buffer
*buffer
= pp_buffer (pp
);
4289 struct chunk_info
*chunk_array
= buffer
->cur_chunk_array
;
4290 const char **args
= chunk_array
->args
;
4292 unsigned int chunk_idx
;
4293 for (chunk_idx
= 0; args
[chunk_idx
]; chunk_idx
++)
4295 args
[chunk_idx
++] = content
;
4296 args
[chunk_idx
] = NULL
;
4299 /* Create a copy of CONTENT, with quotes added, and,
4300 potentially, with colorization.
4301 No escaped is performed on CONTENT.
4302 The result is in a GC-allocated buffer. */
4305 add_quotes (const char *content
, bool show_color
)
4307 pretty_printer tmp_pp
;
4308 pp_show_color (&tmp_pp
) = show_color
;
4310 /* We have to use "%<%s%>" rather than "%qs" here in order to avoid
4311 quoting colorization bytes within the results and using either
4312 pp_quote or pp_begin_quote doesn't work the same. */
4313 pp_printf (&tmp_pp
, "%<%s%>", content
);
4315 return pp_ggc_formatted_text (&tmp_pp
);
4319 #pragma GCC diagnostic pop
4322 /* If we had %H and %I, and hence deferred printing them,
4323 print them now, storing the result into the chunk_info
4324 for pp_format. Quote them if 'q' was provided.
4325 Also print the difference in tree form, adding it as
4326 an additional chunk. */
4329 cxx_format_postprocessor::handle (pretty_printer
*pp
)
4331 /* If we have one of %H and %I, the other should have
4333 if (m_type_a
.m_tree
|| m_type_b
.m_tree
)
4335 /* Avoid reentrancy issues by working with a copy of
4336 m_type_a and m_type_b, resetting them now. */
4337 deferred_printed_type type_a
= m_type_a
;
4338 deferred_printed_type type_b
= m_type_b
;
4339 m_type_a
= deferred_printed_type ();
4340 m_type_b
= deferred_printed_type ();
4342 gcc_assert (type_a
.m_buffer_ptr
);
4343 gcc_assert (type_b
.m_buffer_ptr
);
4345 bool show_color
= pp_show_color (pp
);
4347 const char *type_a_text
;
4348 const char *type_b_text
;
4350 if (comparable_template_types_p (type_a
.m_tree
, type_b
.m_tree
))
4353 = type_to_string_with_compare (type_a
.m_tree
, type_b
.m_tree
,
4354 type_a
.m_verbose
, show_color
);
4356 = type_to_string_with_compare (type_b
.m_tree
, type_a
.m_tree
,
4357 type_b
.m_verbose
, show_color
);
4359 if (flag_diagnostics_show_template_tree
)
4361 pretty_printer inner_pp
;
4362 pp_show_color (&inner_pp
) = pp_show_color (pp
);
4363 print_template_tree_comparison
4364 (&inner_pp
, type_a
.m_tree
, type_b
.m_tree
, type_a
.m_verbose
, 2);
4365 append_formatted_chunk (pp
, pp_ggc_formatted_text (&inner_pp
));
4370 /* If the types were not comparable (or if only one of %H/%I was
4371 provided), they are printed normally, and no difference tree
4373 type_a_text
= type_to_string (type_a
.m_tree
, type_a
.m_verbose
,
4374 true, &type_a
.m_quote
, show_color
);
4375 type_b_text
= type_to_string (type_b
.m_tree
, type_b
.m_verbose
,
4376 true, &type_b
.m_quote
, show_color
);
4380 type_a_text
= add_quotes (type_a_text
, show_color
);
4381 *type_a
.m_buffer_ptr
= type_a_text
;
4384 type_b_text
= add_quotes (type_b_text
, show_color
);
4385 *type_b
.m_buffer_ptr
= type_b_text
;
4389 /* Subroutine for handling %H and %I, to support i18n of messages like:
4391 error_at (loc, "could not convert %qE from %qH to %qI",
4392 expr, type_a, type_b);
4394 so that we can print things like:
4396 could not convert 'foo' from 'map<int,double>' to 'map<int,int>'
4398 and, with type-elision:
4400 could not convert 'foo' from 'map<[...],double>' to 'map<[...],int>'
4402 (with color-coding of the differences between the types).
4404 The %H and %I format codes are peers: both must be present,
4405 and they affect each other. Hence to handle them, we must
4406 delay printing until we have both, deferring the printing to
4407 pretty_printer's m_format_postprocessor hook.
4409 This is called in phase 2 of pp_format, when it is accumulating
4410 a series of formatted chunks. We stash the location of the chunk
4411 we're meant to have written to, so that we can write to it in the
4412 m_format_postprocessor hook.
4414 We also need to stash whether a 'q' prefix was provided (the QUOTE
4415 param) so that we can add the quotes when writing out the delayed
4419 defer_phase_2_of_type_diff (deferred_printed_type
*deferred
,
4420 tree type
, const char **buffer_ptr
,
4421 bool verbose
, bool quote
)
4423 gcc_assert (deferred
->m_tree
== NULL_TREE
);
4424 gcc_assert (deferred
->m_buffer_ptr
== NULL
);
4425 *deferred
= deferred_printed_type (type
, buffer_ptr
, verbose
, quote
);
4429 /* Called from output_format -- during diagnostic message processing --
4430 to handle C++ specific format specifier with the following meanings:
4431 %A function argument-list.
4435 %F function declaration.
4436 %H type difference (from).
4437 %I type difference (to).
4438 %L language as used in extern "lang".
4440 %P function parameter whose position is indicated by an integer.
4441 %Q assignment operator.
4442 %S substitution (template + args)
4445 %X exception-specification. */
4447 cp_printer (pretty_printer
*pp
, text_info
*text
, const char *spec
,
4448 int precision
, bool wide
, bool set_locus
, bool verbose
,
4449 bool *quoted
, const char **buffer_ptr
)
4451 gcc_assert (pp
->m_format_postprocessor
);
4452 cxx_format_postprocessor
*postprocessor
4453 = static_cast <cxx_format_postprocessor
*> (pp
->m_format_postprocessor
);
4457 #define next_tree (t = va_arg (*text->args_ptr, tree))
4458 #define next_tcode ((enum tree_code) va_arg (*text->args_ptr, int))
4459 #define next_lang ((enum languages) va_arg (*text->args_ptr, int))
4460 #define next_int va_arg (*text->args_ptr, int)
4462 if (precision
!= 0 || wide
)
4467 case 'A': result
= args_to_string (next_tree
, verbose
); break;
4468 case 'C': result
= code_to_string (next_tcode
); break;
4471 tree temp
= next_tree
;
4473 && DECL_HAS_DEBUG_EXPR_P (temp
))
4475 temp
= DECL_DEBUG_EXPR (temp
);
4478 result
= expr_to_string (temp
);
4482 result
= decl_to_string (temp
, verbose
, pp_show_color (pp
));
4485 case 'E': result
= expr_to_string (next_tree
); break;
4486 case 'F': result
= fndecl_to_string (next_tree
, verbose
); break;
4488 defer_phase_2_of_type_diff (&postprocessor
->m_type_a
, next_tree
,
4489 buffer_ptr
, verbose
, *quoted
);
4492 defer_phase_2_of_type_diff (&postprocessor
->m_type_b
, next_tree
,
4493 buffer_ptr
, verbose
, *quoted
);
4495 case 'L': result
= language_to_string (next_lang
); break;
4496 case 'O': result
= op_to_string (false, next_tcode
); break;
4497 case 'P': result
= parm_to_string (next_int
); break;
4498 case 'Q': result
= op_to_string (true, next_tcode
); break;
4499 case 'S': result
= subst_to_string (next_tree
, pp_show_color (pp
)); break;
4502 result
= type_to_string (next_tree
, verbose
, false, quoted
,
4503 pp_show_color (pp
));
4506 case 'V': result
= cv_to_string (next_tree
, verbose
); break;
4507 case 'X': result
= eh_spec_to_string (next_tree
, verbose
); break;
4513 pp_string (pp
, result
);
4514 if (set_locus
&& t
!= NULL
)
4515 text
->set_location (0, location_of (t
), SHOW_RANGE_WITH_CARET
);
4523 /* Warn about the use of C++0x features when appropriate. */
4525 maybe_warn_cpp0x (cpp0x_warn_str str
, location_t loc
/*=input_location*/)
4527 if (cxx_dialect
== cxx98
)
4530 case CPP0X_INITIALIZER_LISTS
:
4531 pedwarn (loc
, OPT_Wc__11_extensions
,
4532 "extended initializer lists "
4533 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4535 case CPP0X_EXPLICIT_CONVERSION
:
4536 pedwarn (loc
, OPT_Wc__11_extensions
,
4537 "explicit conversion operators "
4538 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4540 case CPP0X_VARIADIC_TEMPLATES
:
4541 pedwarn (loc
, OPT_Wc__11_extensions
,
4542 "variadic templates "
4543 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4545 case CPP0X_LAMBDA_EXPR
:
4546 pedwarn (loc
, OPT_Wc__11_extensions
,
4547 "lambda expressions "
4548 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4551 pedwarn (loc
, OPT_Wc__11_extensions
,
4552 "C++11 auto only available with %<-std=c++11%> or "
4553 "%<-std=gnu++11%>");
4555 case CPP0X_SCOPED_ENUMS
:
4556 pedwarn (loc
, OPT_Wc__11_extensions
,
4557 "scoped enums only available with %<-std=c++11%> or "
4558 "%<-std=gnu++11%>");
4560 case CPP0X_DEFAULTED_DELETED
:
4561 pedwarn (loc
, OPT_Wc__11_extensions
,
4562 "defaulted and deleted functions "
4563 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4565 case CPP0X_INLINE_NAMESPACES
:
4567 pedwarn (loc
, OPT_Wc__11_extensions
,
4568 "inline namespaces "
4569 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4571 case CPP0X_OVERRIDE_CONTROLS
:
4572 pedwarn (loc
, OPT_Wc__11_extensions
,
4573 "override controls (override/final) "
4574 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4577 pedwarn (loc
, OPT_Wc__11_extensions
,
4578 "non-static data member initializers "
4579 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4581 case CPP0X_USER_DEFINED_LITERALS
:
4582 pedwarn (loc
, OPT_Wc__11_extensions
,
4583 "user-defined literals "
4584 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4586 case CPP0X_DELEGATING_CTORS
:
4587 pedwarn (loc
, OPT_Wc__11_extensions
,
4588 "delegating constructors "
4589 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4591 case CPP0X_INHERITING_CTORS
:
4592 pedwarn (loc
, OPT_Wc__11_extensions
,
4593 "inheriting constructors "
4594 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4596 case CPP0X_ATTRIBUTES
:
4597 pedwarn (loc
, OPT_Wc__11_extensions
,
4599 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4601 case CPP0X_REF_QUALIFIER
:
4602 pedwarn (loc
, OPT_Wc__11_extensions
,
4604 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4611 /* Warn about the use of variadic templates when appropriate. */
4613 maybe_warn_variadic_templates (void)
4615 maybe_warn_cpp0x (CPP0X_VARIADIC_TEMPLATES
);
4619 /* Issue an ISO C++98 pedantic warning at LOCATION, conditional on
4620 option OPT with text GMSGID. Use this function to report
4621 diagnostics for constructs that are invalid C++98, but valid
4624 pedwarn_cxx98 (location_t location
, int opt
, const char *gmsgid
, ...)
4626 diagnostic_info diagnostic
;
4629 rich_location
richloc (line_table
, location
);
4631 va_start (ap
, gmsgid
);
4632 diagnostic_set_info (&diagnostic
, gmsgid
, &ap
, &richloc
,
4633 (cxx_dialect
== cxx98
) ? DK_PEDWARN
: DK_WARNING
);
4634 diagnostic
.option_index
= opt
;
4635 ret
= diagnostic_report_diagnostic (global_dc
, &diagnostic
);
4640 /* Issue a diagnostic that NAME cannot be found in SCOPE. DECL is what
4641 we found when we tried to do the lookup. LOCATION is the location of
4642 the NAME identifier. */
4645 qualified_name_lookup_error (tree scope
, tree name
,
4646 tree decl
, location_t location
)
4648 if (scope
== error_mark_node
)
4649 ; /* We already complained. */
4650 else if (TYPE_P (scope
))
4652 if (!COMPLETE_TYPE_P (scope
))
4653 error_at (location
, "incomplete type %qT used in nested name specifier",
4655 else if (TREE_CODE (decl
) == TREE_LIST
)
4657 error_at (location
, "reference to %<%T::%D%> is ambiguous",
4659 print_candidates (decl
);
4664 if (SCOPED_ENUM_P (scope
) && TREE_CODE (name
) == IDENTIFIER_NODE
)
4665 hint
= suggest_alternative_in_scoped_enum (name
, scope
);
4666 if (const char *suggestion
= hint
.suggestion ())
4668 gcc_rich_location
richloc (location
);
4669 richloc
.add_fixit_replace (suggestion
);
4671 "%qD is not a member of %qT; did you mean %qs?",
4672 name
, scope
, suggestion
);
4675 error_at (location
, "%qD is not a member of %qT", name
, scope
);
4678 else if (scope
!= global_namespace
)
4680 auto_diagnostic_group d
;
4681 bool emit_fixit
= true;
4683 = suggest_alternative_in_explicit_scope (location
, name
, scope
);
4686 hint
= suggest_alternatives_in_other_namespaces (location
, name
);
4687 /* "location" is just the location of the name, not of the explicit
4688 scope, and it's not easy to get at the latter, so we can't issue
4689 fix-it hints for the suggestion. */
4692 if (const char *suggestion
= hint
.suggestion ())
4694 gcc_rich_location
richloc (location
);
4696 richloc
.add_fixit_replace (suggestion
);
4697 error_at (&richloc
, "%qD is not a member of %qD; did you mean %qs?",
4698 name
, scope
, suggestion
);
4701 error_at (location
, "%qD is not a member of %qD", name
, scope
);
4705 auto_diagnostic_group d
;
4706 name_hint hint
= suggest_alternatives_for (location
, name
, true);
4707 if (const char *suggestion
= hint
.suggestion ())
4709 gcc_rich_location
richloc (location
);
4710 richloc
.add_fixit_replace (suggestion
);
4712 "%<::%D%> has not been declared; did you mean %qs?",
4716 error_at (location
, "%<::%D%> has not been declared", name
);
4720 /* C++-specific implementation of range_label::get_text () vfunc for
4721 range_label_for_type_mismatch.
4723 Compare with print_template_differences above. */
4726 range_label_for_type_mismatch::get_text (unsigned /*range_idx*/) const
4728 if (m_labelled_type
== NULL_TREE
)
4729 return label_text::borrow (NULL
);
4731 const bool verbose
= false;
4732 const bool show_color
= false;
4736 && comparable_template_types_p (m_labelled_type
, m_other_type
))
4737 result
= type_to_string_with_compare (m_labelled_type
, m_other_type
,
4738 verbose
, show_color
);
4740 result
= type_to_string (m_labelled_type
, verbose
, true, NULL
, show_color
);
4742 /* Both of the above return GC-allocated buffers, so the caller mustn't
4744 return label_text::borrow (result
);