1 /* Call-backs for C++ error reporting.
2 This code is non-reentrant.
3 Copyright (C) 1993-2024 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
*,
105 const diagnostic_info
*);
106 static void cp_print_error_function (diagnostic_context
*,
107 const diagnostic_info
*);
109 static bool cp_printer (pretty_printer
*, text_info
*, const char *,
110 int, bool, bool, bool, bool *, const char **);
112 /* Struct for handling %H or %I, which require delaying printing the
113 type until a postprocessing stage. */
115 class deferred_printed_type
118 deferred_printed_type ()
119 : m_tree (NULL_TREE
), m_buffer_ptr (NULL
), m_verbose (false), m_quote (false)
122 deferred_printed_type (tree type
, const char **buffer_ptr
, bool verbose
,
124 : m_tree (type
), m_buffer_ptr (buffer_ptr
), m_verbose (verbose
),
128 gcc_assert (buffer_ptr
);
131 /* The tree is not GTY-marked: they are only non-NULL within a
132 call to pp_format. */
134 const char **m_buffer_ptr
;
139 /* Subclass of format_postprocessor for the C++ frontend.
140 This handles the %H and %I formatting codes, printing them
141 in a postprocessing phase (since they affect each other). */
143 class cxx_format_postprocessor
: public format_postprocessor
146 cxx_format_postprocessor ()
147 : m_type_a (), m_type_b ()
150 format_postprocessor
*clone() const final override
152 return new cxx_format_postprocessor ();
155 void handle (pretty_printer
*pp
) final override
;
157 deferred_printed_type m_type_a
;
158 deferred_printed_type m_type_b
;
161 /* CONTEXT->printer is a basic pretty printer that was constructed
162 presumably by diagnostic_initialize(), called early in the
163 compiler's initialization process (in general_init) Before the FE
164 is initialized. This (C++) FE-specific diagnostic initializer is
165 thus replacing the basic pretty printer with one that has C++-aware
169 cxx_initialize_diagnostics (diagnostic_context
*context
)
171 pretty_printer
*base
= context
->printer
;
172 cxx_pretty_printer
*pp
= XNEW (cxx_pretty_printer
);
173 context
->printer
= new (pp
) cxx_pretty_printer ();
175 /* It is safe to free this object because it was previously XNEW()'d. */
176 base
->~pretty_printer ();
179 c_common_diagnostics_set_defaults (context
);
180 diagnostic_starter (context
) = cp_diagnostic_starter
;
181 /* diagnostic_finalizer is already c_diagnostic_finalizer. */
182 diagnostic_format_decoder (context
) = cp_printer
;
183 pp
->m_format_postprocessor
= new cxx_format_postprocessor ();
186 /* Dump an '@module' name suffix for DECL, if any. */
189 dump_module_suffix (cxx_pretty_printer
*pp
, tree decl
)
194 if (!DECL_CONTEXT (decl
))
197 if (TREE_CODE (decl
) != CONST_DECL
198 || !UNSCOPED_ENUM_P (DECL_CONTEXT (decl
)))
200 if (!DECL_NAMESPACE_SCOPE_P (decl
))
203 if (TREE_CODE (decl
) == NAMESPACE_DECL
204 && !DECL_NAMESPACE_ALIAS (decl
)
205 && (TREE_PUBLIC (decl
) || !TREE_PUBLIC (CP_DECL_CONTEXT (decl
))))
209 if (unsigned m
= get_originating_module (decl
))
210 if (const char *n
= module_name (m
, false))
212 pp_character (pp
, '@');
213 pp
->padding
= pp_none
;
218 /* The scope of the declaration we're currently printing, to avoid redundantly
219 dumping the same scope on parameter types. */
220 static tree current_dump_scope
;
222 /* Dump a scope, if deemed necessary. */
225 dump_scope (cxx_pretty_printer
*pp
, tree scope
, int flags
)
227 int f
= flags
& (TFF_SCOPE
| TFF_CHASE_TYPEDEF
);
229 if (scope
== NULL_TREE
|| scope
== current_dump_scope
)
232 /* Enum values within an unscoped enum will be CONST_DECL with an
233 ENUMERAL_TYPE as their "scope". Use CP_TYPE_CONTEXT of the
234 ENUMERAL_TYPE, so as to print any enclosing namespace. */
235 if (UNSCOPED_ENUM_P (scope
))
236 scope
= CP_TYPE_CONTEXT (scope
);
238 if (TREE_CODE (scope
) == NAMESPACE_DECL
)
240 if (scope
!= global_namespace
)
242 dump_decl (pp
, scope
, f
);
243 pp_cxx_colon_colon (pp
);
246 else if (AGGREGATE_TYPE_P (scope
)
247 || SCOPED_ENUM_P (scope
))
249 dump_type (pp
, scope
, f
);
250 pp_cxx_colon_colon (pp
);
252 else if ((flags
& TFF_SCOPE
) && TREE_CODE (scope
) == FUNCTION_DECL
)
254 dump_function_decl (pp
, scope
, f
| TFF_NO_TEMPLATE_BINDINGS
);
255 pp_cxx_colon_colon (pp
);
259 /* Dump the template ARGument under control of FLAGS. */
262 dump_template_argument (cxx_pretty_printer
*pp
, tree arg
, int flags
)
264 if (ARGUMENT_PACK_P (arg
))
265 dump_template_argument_list (pp
, ARGUMENT_PACK_ARGS (arg
),
266 /* No default args in argument packs. */
267 flags
|TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS
);
268 else if (TYPE_P (arg
) || TREE_CODE (arg
) == TEMPLATE_DECL
)
269 dump_type (pp
, arg
, flags
& ~TFF_CLASS_KEY_OR_ENUM
);
272 if (TREE_CODE (arg
) == TREE_LIST
)
273 arg
= TREE_VALUE (arg
);
275 /* Strip implicit conversions. */
276 while (CONVERT_EXPR_P (arg
))
277 arg
= TREE_OPERAND (arg
, 0);
279 dump_expr (pp
, arg
, (flags
| TFF_EXPR_IN_PARENS
) & ~TFF_CLASS_KEY_OR_ENUM
);
283 /* Count the number of template arguments ARGS whose value does not
284 match the (optional) default template parameter in PARAMS */
287 get_non_default_template_args_count (tree args
, int flags
)
289 int n
= TREE_VEC_LENGTH (INNERMOST_TEMPLATE_ARGS (args
));
291 if (/* We use this flag when generating debug information. We don't
292 want to expand templates at this point, for this may generate
293 new decls, which gets decl counts out of sync, which may in
294 turn cause codegen differences between compilations with and
296 (flags
& TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS
) != 0
297 || !flag_pretty_templates
)
300 return GET_NON_DEFAULT_TEMPLATE_ARGS_COUNT (INNERMOST_TEMPLATE_ARGS (args
));
303 /* Dump a template-argument-list ARGS (always a TREE_VEC) under control
307 dump_template_argument_list (cxx_pretty_printer
*pp
, tree args
, int flags
)
309 int n
= get_non_default_template_args_count (args
, flags
);
313 for (i
= 0; i
< n
; ++i
)
315 tree arg
= TREE_VEC_ELT (args
, i
);
317 /* Only print a comma if we know there is an argument coming. In
318 the case of an empty template argument pack, no actual
319 argument will be printed. */
321 && (!ARGUMENT_PACK_P (arg
)
322 || TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg
)) > 0))
323 pp_separate_with_comma (pp
);
325 dump_template_argument (pp
, arg
, flags
);
330 /* Dump a template parameter PARM (a TREE_LIST) under control of FLAGS. */
333 dump_template_parameter (cxx_pretty_printer
*pp
, tree parm
, int flags
)
338 if (parm
== error_mark_node
)
341 p
= TREE_VALUE (parm
);
342 a
= TREE_PURPOSE (parm
);
344 if (TREE_CODE (p
) == TYPE_DECL
)
346 if (flags
& TFF_DECL_SPECIFIERS
)
348 pp_cxx_ws_string (pp
, "class");
349 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (p
)))
350 pp_cxx_ws_string (pp
, "...");
352 pp_cxx_tree_identifier (pp
, DECL_NAME (p
));
354 else if (DECL_NAME (p
))
355 pp_cxx_tree_identifier (pp
, DECL_NAME (p
));
357 pp_cxx_canonical_template_parameter (pp
, TREE_TYPE (p
));
360 dump_decl (pp
, p
, flags
| TFF_DECL_SPECIFIERS
);
362 if ((flags
& TFF_FUNCTION_DEFAULT_ARGUMENTS
) && a
!= NULL_TREE
)
364 pp_cxx_whitespace (pp
);
366 pp_cxx_whitespace (pp
);
367 if (TREE_CODE (p
) == TYPE_DECL
|| TREE_CODE (p
) == TEMPLATE_DECL
)
368 dump_type (pp
, a
, flags
& ~TFF_CHASE_TYPEDEF
);
370 dump_expr (pp
, a
, flags
| TFF_EXPR_IN_PARENS
);
374 /* Dump, under control of FLAGS, a template-parameter-list binding.
375 PARMS is a TREE_LIST of TREE_VEC of TREE_LIST and ARGS is a
379 dump_template_bindings (cxx_pretty_printer
*pp
, tree parms
, tree args
,
380 vec
<tree
, va_gc
> *typenames
)
382 /* Print "[with" and ']', conditional on whether anything is printed at all.
383 This is tied to whether a semicolon is needed to separate multiple template
385 struct prepost_semicolon
387 cxx_pretty_printer
*pp
;
393 pp_separate_with_semicolon (pp
);
396 pp_cxx_whitespace (pp
);
397 pp_string (pp
, colorize_start (pp_show_color (pp
), "targs"));
398 pp_cxx_left_bracket (pp
);
399 pp
->translate_string ("with");
400 pp_cxx_whitespace (pp
);
401 need_semicolon
= true;
405 ~prepost_semicolon ()
409 pp_cxx_right_bracket (pp
);
410 pp_string (pp
, colorize_stop (pp_show_color (pp
)));
413 } semicolon_or_introducer
= {pp
, false};
420 tree p
= TREE_VALUE (parms
);
421 int lvl
= TMPL_PARMS_DEPTH (parms
);
424 tree lvl_args
= NULL_TREE
;
426 /* Don't crash if we had an invalid argument list. */
427 if (TMPL_ARGS_DEPTH (args
) >= lvl
)
428 lvl_args
= TMPL_ARGS_LEVEL (args
, lvl
);
430 for (i
= 0; i
< TREE_VEC_LENGTH (p
); ++i
)
432 tree arg
= NULL_TREE
;
434 /* Don't crash if we had an invalid argument list. */
435 if (lvl_args
&& NUM_TMPL_ARGS (lvl_args
) > arg_idx
)
436 arg
= TREE_VEC_ELT (lvl_args
, arg_idx
);
438 tree parm_i
= TREE_VEC_ELT (p
, i
);
439 /* If the template argument repeats the template parameter (T = T),
440 skip the parameter.*/
441 if (arg
&& TREE_CODE (arg
) == TEMPLATE_TYPE_PARM
442 && TREE_CODE (parm_i
) == TREE_LIST
443 && TREE_CODE (TREE_VALUE (parm_i
)) == TYPE_DECL
444 && TREE_CODE (TREE_TYPE (TREE_VALUE (parm_i
)))
445 == TEMPLATE_TYPE_PARM
446 && DECL_NAME (TREE_VALUE (parm_i
))
447 == DECL_NAME (TREE_CHAIN (arg
)))
450 semicolon_or_introducer ();
451 dump_template_parameter (pp
, parm_i
, TFF_PLAIN_IDENTIFIER
);
452 pp_cxx_whitespace (pp
);
454 pp_cxx_whitespace (pp
);
457 if (ARGUMENT_PACK_P (arg
))
458 pp_cxx_left_brace (pp
);
459 dump_template_argument (pp
, arg
, TFF_PLAIN_IDENTIFIER
);
460 if (ARGUMENT_PACK_P (arg
))
461 pp_cxx_right_brace (pp
);
464 pp_string (pp
, M_("<missing>"));
469 parms
= TREE_CHAIN (parms
);
472 /* Don't bother with typenames for a partial instantiation. */
473 if (vec_safe_is_empty (typenames
) || uses_template_parms (args
))
476 /* Don't try to print typenames when we're processing a clone. */
477 if (current_function_decl
478 && !DECL_LANG_SPECIFIC (current_function_decl
))
481 /* Don't try to do this once cgraph starts throwing away front-end
486 FOR_EACH_VEC_SAFE_ELT (typenames
, i
, t
)
488 semicolon_or_introducer ();
489 dump_type (pp
, t
, TFF_PLAIN_IDENTIFIER
);
490 pp_cxx_whitespace (pp
);
492 pp_cxx_whitespace (pp
);
493 push_deferring_access_checks (dk_no_check
);
494 t
= tsubst (t
, args
, tf_none
, NULL_TREE
);
495 pop_deferring_access_checks ();
496 /* Strip typedefs. We can't just use TFF_CHASE_TYPEDEF because
497 pp_simple_type_specifier doesn't know about it. */
498 t
= strip_typedefs (t
, NULL
, STF_USER_VISIBLE
);
499 dump_type (pp
, t
, TFF_PLAIN_IDENTIFIER
);
503 /* Dump a human-readable equivalent of the alias template
504 specialization of T. */
507 dump_alias_template_specialization (cxx_pretty_printer
*pp
, tree t
, int flags
)
509 gcc_assert (alias_template_specialization_p (t
, nt_opaque
));
511 tree decl
= TYPE_NAME (t
);
512 if (!(flags
& TFF_UNQUALIFIED_NAME
))
513 dump_scope (pp
, CP_DECL_CONTEXT (decl
), flags
);
514 pp_cxx_tree_identifier (pp
, DECL_NAME (decl
));
515 dump_template_parms (pp
, DECL_TEMPLATE_INFO (decl
),
517 flags
& ~TFF_TEMPLATE_HEADER
);
520 /* Dump a human-readable equivalent of TYPE. FLAGS controls the
524 dump_type (cxx_pretty_printer
*pp
, tree t
, int flags
)
529 /* Don't print e.g. "struct mytypedef". */
530 if (TYPE_P (t
) && typedef_variant_p (t
))
532 tree decl
= TYPE_NAME (t
);
533 if ((flags
& TFF_CHASE_TYPEDEF
)
534 || DECL_SELF_REFERENCE_P (decl
)
535 || (!flag_pretty_templates
536 && DECL_LANG_SPECIFIC (decl
) && DECL_TEMPLATE_INFO (decl
)))
538 unsigned int stf_flags
= (!(pp
->flags
& pp_c_flag_gnu_v3
)
539 ? STF_USER_VISIBLE
: 0);
540 t
= strip_typedefs (t
, NULL
, stf_flags
);
542 else if (alias_template_specialization_p (t
, nt_opaque
))
544 dump_alias_template_specialization (pp
, t
, flags
);
547 else if (same_type_p (t
, TREE_TYPE (decl
)))
551 pp_cxx_cv_qualifier_seq (pp
, t
);
552 if (! (flags
& TFF_UNQUALIFIED_NAME
))
553 dump_scope (pp
, CP_DECL_CONTEXT (decl
), flags
);
554 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
559 if (TYPE_PTRMEMFUNC_P (t
))
562 switch (TREE_CODE (t
))
565 if (t
== init_list_type_node
)
566 pp_string (pp
, M_("<brace-enclosed initializer list>"));
567 else if (t
== unknown_type_node
)
568 pp_string (pp
, M_("<unresolved overloaded function type>"));
571 pp_cxx_cv_qualifier_seq (pp
, t
);
572 if (tree id
= TYPE_IDENTIFIER (t
))
573 pp_cxx_tree_identifier (pp
, id
);
578 /* A list of function parms. */
579 dump_parameters (pp
, t
, flags
);
582 case IDENTIFIER_NODE
:
583 pp_cxx_tree_identifier (pp
, t
);
587 dump_type (pp
, BINFO_TYPE (t
), flags
);
593 dump_aggr_type (pp
, t
, flags
);
597 if (flags
& TFF_CHASE_TYPEDEF
)
599 dump_type (pp
, DECL_ORIGINAL_TYPE (t
)
600 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
), flags
);
607 dump_decl (pp
, t
, flags
& ~TFF_DECL_SPECIFIERS
);
617 case FIXED_POINT_TYPE
:
618 pp_type_specifier_seq (pp
, t
);
621 case TEMPLATE_TEMPLATE_PARM
:
622 /* For parameters inside template signature. */
623 if (TYPE_IDENTIFIER (t
))
624 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
626 pp_cxx_canonical_template_parameter (pp
, t
);
629 case BOUND_TEMPLATE_TEMPLATE_PARM
:
631 tree args
= TYPE_TI_ARGS (t
);
632 pp_cxx_cv_qualifier_seq (pp
, t
);
633 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
634 pp_cxx_begin_template_argument_list (pp
);
635 dump_template_argument_list (pp
, args
, flags
);
636 pp_cxx_end_template_argument_list (pp
);
640 case TEMPLATE_TYPE_PARM
:
641 pp_cxx_cv_qualifier_seq (pp
, t
);
642 if (template_placeholder_p (t
))
644 tree tmpl
= TREE_TYPE (CLASS_PLACEHOLDER_TEMPLATE (t
));
645 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (tmpl
));
646 pp_string (pp
, "<...auto...>");
648 else if (TYPE_IDENTIFIER (t
))
649 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
651 pp_cxx_canonical_template_parameter
652 (pp
, TEMPLATE_TYPE_PARM_INDEX (t
));
653 /* If this is a constrained placeholder, add the requirements. */
654 if (tree c
= PLACEHOLDER_TYPE_CONSTRAINTS (t
))
655 pp_cxx_constrained_type_spec (pp
, c
);
658 /* This is not always necessary for pointers and such, but doing this
659 reduces code size. */
668 dump_type_prefix (pp
, t
, flags
);
669 dump_type_suffix (pp
, t
, flags
);
673 if (! (flags
& TFF_CHASE_TYPEDEF
)
674 && DECL_ORIGINAL_TYPE (TYPE_NAME (t
)))
676 dump_decl (pp
, TYPE_NAME (t
), TFF_PLAIN_IDENTIFIER
);
679 pp_cxx_cv_qualifier_seq (pp
, t
);
680 pp_cxx_ws_string (pp
,
681 TYPENAME_IS_ENUM_P (t
) ? "enum"
682 : TYPENAME_IS_CLASS_P (t
) ? "class"
684 dump_typename (pp
, t
, flags
);
687 case UNBOUND_CLASS_TEMPLATE
:
688 if (! (flags
& TFF_UNQUALIFIED_NAME
))
690 dump_type (pp
, TYPE_CONTEXT (t
), flags
);
691 pp_cxx_colon_colon (pp
);
693 pp_cxx_ws_string (pp
, "template");
694 dump_type (pp
, TYPE_IDENTIFIER (t
), flags
);
698 pp_cxx_ws_string (pp
, "__typeof__");
699 pp_cxx_whitespace (pp
);
700 pp_cxx_left_paren (pp
);
701 dump_expr (pp
, TYPEOF_TYPE_EXPR (t
), flags
& ~TFF_EXPR_IN_PARENS
);
702 pp_cxx_right_paren (pp
);
706 pp_cxx_trait (pp
, t
);
709 case TYPE_PACK_EXPANSION
:
710 dump_type (pp
, PACK_EXPANSION_PATTERN (t
), flags
);
711 pp_cxx_ws_string (pp
, "...");
714 case TYPE_ARGUMENT_PACK
:
715 dump_template_argument (pp
, t
, flags
);
719 pp_cxx_ws_string (pp
, "decltype");
720 pp_cxx_whitespace (pp
);
721 pp_cxx_left_paren (pp
);
722 dump_expr (pp
, DECLTYPE_TYPE_EXPR (t
), flags
& ~TFF_EXPR_IN_PARENS
);
723 pp_cxx_right_paren (pp
);
727 pp_string (pp
, "std::nullptr_t");
731 pp_unsupported_tree (pp
, t
);
735 pp_string (pp
, M_("<type error>"));
740 /* Dump a TYPENAME_TYPE. We need to notice when the context is itself
744 dump_typename (cxx_pretty_printer
*pp
, tree t
, int flags
)
746 tree ctx
= TYPE_CONTEXT (t
);
748 if (TREE_CODE (ctx
) == TYPENAME_TYPE
)
749 dump_typename (pp
, ctx
, flags
);
751 dump_type (pp
, ctx
, flags
& ~TFF_CLASS_KEY_OR_ENUM
);
752 pp_cxx_colon_colon (pp
);
753 dump_decl (pp
, TYPENAME_TYPE_FULLNAME (t
), flags
);
756 /* Return the name of the supplied aggregate, or enumeral type. */
759 class_key_or_enum_as_string (tree t
)
761 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
763 if (SCOPED_ENUM_P (t
))
768 else if (TREE_CODE (t
) == UNION_TYPE
)
770 else if (TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_DECLARED_CLASS (t
))
776 /* Disable warnings about missing quoting in GCC diagnostics for
777 the pp_verbatim call. Their format strings deliberately don't
778 follow GCC diagnostic conventions. */
780 #pragma GCC diagnostic push
781 #pragma GCC diagnostic ignored "-Wformat-diag"
784 /* Print out a class declaration T under the control of FLAGS,
785 in the form `class foo'. */
788 dump_aggr_type (cxx_pretty_printer
*pp
, tree t
, int flags
)
790 const char *variety
= class_key_or_enum_as_string (t
);
794 pp_cxx_cv_qualifier_seq (pp
, t
);
796 if (flags
& TFF_CLASS_KEY_OR_ENUM
)
797 pp_cxx_ws_string (pp
, variety
);
799 tree decl
= TYPE_NAME (t
);
803 typdef
= (!DECL_ARTIFICIAL (decl
)
804 /* An alias specialization is not considered to be a
806 && !alias_template_specialization_p (t
, nt_opaque
));
809 && ((flags
& TFF_CHASE_TYPEDEF
)
810 || (!flag_pretty_templates
&& DECL_LANG_SPECIFIC (decl
)
811 && DECL_TEMPLATE_INFO (decl
))))
812 || DECL_SELF_REFERENCE_P (decl
))
814 t
= TYPE_MAIN_VARIANT (t
);
815 decl
= TYPE_NAME (t
);
819 tmplate
= !typdef
&& TREE_CODE (t
) != ENUMERAL_TYPE
820 && TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_TEMPLATE_INFO (t
)
821 && (TREE_CODE (CLASSTYPE_TI_TEMPLATE (t
)) != TEMPLATE_DECL
822 || PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t
)));
824 if (! (flags
& TFF_UNQUALIFIED_NAME
))
825 dump_scope (pp
, CP_DECL_CONTEXT (decl
), flags
| TFF_SCOPE
);
826 flags
&= ~TFF_UNQUALIFIED_NAME
;
829 /* Because the template names are mangled, we have to locate
830 the most general template, and use that name. */
831 tree tpl
= TYPE_TI_TEMPLATE (t
);
833 while (DECL_TEMPLATE_INFO (tpl
))
834 tpl
= DECL_TI_TEMPLATE (tpl
);
839 if (LAMBDA_TYPE_P (t
))
841 /* A lambda's "type" is essentially its signature. */
842 pp_string (pp
, M_("<lambda"));
843 tree
const fn
= lambda_function (t
);
847 = DECL_XOBJ_MEMBER_FUNCTION_P (fn
) ? TFF_XOBJ_FUNC
| flags
849 dump_parameters (pp
, FUNCTION_FIRST_USER_PARMTYPE (fn
), parm_flags
);
853 else if (!decl
|| IDENTIFIER_ANON_P (DECL_NAME (decl
)))
855 if (flags
& TFF_CLASS_KEY_OR_ENUM
)
856 pp_string (pp
, M_("<unnamed>"));
858 pp_printf (pp
, M_("<unnamed %s>"), variety
);
861 pp_cxx_tree_identifier (pp
, DECL_NAME (decl
));
863 dump_module_suffix (pp
, decl
);
866 dump_template_parms (pp
, TYPE_TEMPLATE_INFO (t
),
867 !CLASSTYPE_USE_TEMPLATE (t
),
868 flags
& ~TFF_TEMPLATE_HEADER
);
872 #pragma GCC diagnostic pop
875 /* Dump into the obstack the initial part of the output for a given type.
876 This is necessary when dealing with things like functions returning
879 return type of `int (* fee ())()': pointer -> function -> int. Both
880 pointer (and reference and offset) and function (and member) types must
881 deal with prefix and suffix.
883 Arrays must also do this for DECL nodes, like int a[], and for things like
887 dump_type_prefix (cxx_pretty_printer
*pp
, tree t
, int flags
)
889 if (TYPE_PTRMEMFUNC_P (t
))
891 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
895 switch (TREE_CODE (t
))
900 tree sub
= TREE_TYPE (t
);
902 dump_type_prefix (pp
, sub
, flags
);
903 if (TREE_CODE (sub
) == ARRAY_TYPE
904 || TREE_CODE (sub
) == FUNCTION_TYPE
)
906 pp_cxx_whitespace (pp
);
907 pp_cxx_left_paren (pp
);
908 /* If we're dealing with the GNU form of attributes, print this:
909 void (__attribute__((noreturn)) *f) ();
910 If it is the standard [[]] attribute, we'll print the attribute
911 in dump_type_suffix. */
912 if (!cxx11_attribute_p (TYPE_ATTRIBUTES (sub
)))
913 pp_c_attributes_display (pp
, TYPE_ATTRIBUTES (sub
));
917 else if (TYPE_REF_P (t
))
919 if (TYPE_REF_IS_RVALUE (t
))
920 pp_ampersand_ampersand (pp
);
924 pp
->padding
= pp_before
;
925 pp_cxx_cv_qualifier_seq (pp
, t
);
931 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
932 if (TREE_CODE (t
) == OFFSET_TYPE
) /* pmfs deal with this in d_t_p */
935 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
936 pp_cxx_left_paren (pp
);
937 dump_type (pp
, TYPE_OFFSET_BASETYPE (t
), flags
);
938 pp_cxx_colon_colon (pp
);
941 pp_cxx_cv_qualifier_seq (pp
, t
);
942 pp
->padding
= pp_before
;
945 /* This can be reached without a pointer when dealing with
946 templates, e.g. std::is_function. */
948 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
952 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
954 pp_cxx_left_paren (pp
);
955 dump_aggr_type (pp
, TYPE_METHOD_BASETYPE (t
), flags
);
956 pp_cxx_colon_colon (pp
);
960 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
964 case IDENTIFIER_NODE
:
969 case TEMPLATE_TYPE_PARM
:
970 case TEMPLATE_TEMPLATE_PARM
:
971 case BOUND_TEMPLATE_TEMPLATE_PARM
:
985 case TYPE_PACK_EXPANSION
:
986 case FIXED_POINT_TYPE
:
988 dump_type (pp
, t
, flags
);
989 pp
->padding
= pp_before
;
993 pp_unsupported_tree (pp
, t
);
996 pp_string (pp
, M_("<typeprefixerror>"));
1001 /* Dump the suffix of type T, under control of FLAGS. This is the part
1002 which appears after the identifier (or function parms). */
1005 dump_type_suffix (cxx_pretty_printer
*pp
, tree t
, int flags
)
1007 if (TYPE_PTRMEMFUNC_P (t
))
1008 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
1010 switch (TREE_CODE (t
))
1013 case REFERENCE_TYPE
:
1015 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
1016 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
1017 pp_cxx_right_paren (pp
);
1018 if (TREE_CODE (t
) == POINTER_TYPE
)
1019 flags
|= TFF_POINTER
;
1020 dump_type_suffix (pp
, TREE_TYPE (t
), flags
);
1027 if (TREE_CODE (t
) == METHOD_TYPE
)
1028 /* Can only be reached through a pointer. */
1029 pp_cxx_right_paren (pp
);
1030 arg
= TYPE_ARG_TYPES (t
);
1031 if (TREE_CODE (t
) == METHOD_TYPE
)
1032 arg
= TREE_CHAIN (arg
);
1034 /* Function pointers don't have default args. Not in standard C++,
1035 anyway; they may in g++, but we'll just pretend otherwise. */
1036 dump_parameters (pp
, arg
, flags
& ~TFF_FUNCTION_DEFAULT_ARGUMENTS
);
1038 pp
->padding
= pp_before
;
1039 pp_cxx_cv_qualifiers (pp
, type_memfn_quals (t
),
1040 TREE_CODE (t
) == FUNCTION_TYPE
1041 && (flags
& TFF_POINTER
));
1042 dump_ref_qualifier (pp
, t
, flags
);
1043 if (tx_safe_fn_type_p (t
))
1044 pp_cxx_ws_string (pp
, "transaction_safe");
1045 dump_exception_spec (pp
, TYPE_RAISES_EXCEPTIONS (t
), flags
);
1046 /* If this is the standard [[]] attribute, print
1047 void (*)() [[noreturn]]; */
1048 if (cxx11_attribute_p (TYPE_ATTRIBUTES (t
)))
1051 pp_c_attributes_display (pp
, TYPE_ATTRIBUTES (t
));
1052 pp
->padding
= pp_before
;
1054 dump_type_suffix (pp
, TREE_TYPE (t
), flags
);
1059 pp_maybe_space (pp
);
1060 pp_cxx_left_bracket (pp
);
1061 if (tree dtype
= TYPE_DOMAIN (t
))
1063 tree max
= TYPE_MAX_VALUE (dtype
);
1064 /* Zero-length arrays have a null upper bound in C and SIZE_MAX
1065 in C++. Handle both since the type might be constructed by
1066 the middle end and end up here as a result of a warning (see
1068 if (!max
|| integer_all_onesp (max
))
1069 pp_character (pp
, '0');
1070 else if (tree_fits_shwi_p (max
))
1071 pp_wide_integer (pp
, tree_to_shwi (max
) + 1);
1075 if (TREE_CODE (max
) == SAVE_EXPR
)
1076 max
= TREE_OPERAND (max
, 0);
1077 if (TREE_CODE (max
) == MINUS_EXPR
1078 || TREE_CODE (max
) == PLUS_EXPR
)
1080 max
= TREE_OPERAND (max
, 0);
1081 while (CONVERT_EXPR_P (max
))
1082 max
= TREE_OPERAND (max
, 0);
1085 max
= fold_build2_loc (input_location
,
1086 PLUS_EXPR
, dtype
, max
,
1087 build_int_cst (dtype
, 1));
1088 dump_expr (pp
, max
, flags
& ~TFF_EXPR_IN_PARENS
);
1091 pp_cxx_right_bracket (pp
);
1092 dump_type_suffix (pp
, TREE_TYPE (t
), flags
);
1096 case IDENTIFIER_NODE
:
1101 case TEMPLATE_TYPE_PARM
:
1102 case TEMPLATE_TEMPLATE_PARM
:
1103 case BOUND_TEMPLATE_TEMPLATE_PARM
:
1117 case TYPE_PACK_EXPANSION
:
1118 case FIXED_POINT_TYPE
:
1123 pp_unsupported_tree (pp
, t
);
1125 /* Don't mark it here, we should have already done in
1126 dump_type_prefix. */
1132 dump_global_iord (cxx_pretty_printer
*pp
, tree t
)
1134 const char *p
= NULL
;
1136 if (DECL_GLOBAL_CTOR_P (t
))
1137 p
= M_("(static initializers for %s)");
1138 else if (DECL_GLOBAL_DTOR_P (t
))
1139 p
= M_("(static destructors for %s)");
1143 pp_printf (pp
, p
, DECL_SOURCE_FILE (t
));
1147 dump_simple_decl (cxx_pretty_printer
*pp
, tree t
, tree type
, int flags
)
1149 if (VAR_P (t
) && DECL_NTTP_OBJECT_P (t
))
1150 return dump_expr (pp
, DECL_INITIAL (t
), flags
);
1152 if (flags
& TFF_DECL_SPECIFIERS
)
1154 if (concept_definition_p (t
))
1155 pp_cxx_ws_string (pp
, "concept");
1156 else if (VAR_P (t
) && DECL_DECLARED_CONSTEXPR_P (t
))
1157 pp_cxx_ws_string (pp
, "constexpr");
1159 if (!standard_concept_p (t
))
1160 dump_type_prefix (pp
, type
, flags
& ~TFF_UNQUALIFIED_NAME
);
1161 pp_maybe_space (pp
);
1163 if (! (flags
& TFF_UNQUALIFIED_NAME
)
1164 && TREE_CODE (t
) != PARM_DECL
1165 && (!DECL_INITIAL (t
)
1166 || TREE_CODE (DECL_INITIAL (t
)) != TEMPLATE_PARM_INDEX
))
1167 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1168 flags
&= ~TFF_UNQUALIFIED_NAME
;
1169 if ((flags
& TFF_DECL_SPECIFIERS
)
1170 && DECL_TEMPLATE_PARM_P (t
)
1171 && TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (t
)))
1172 pp_string (pp
, "...");
1175 if (TREE_CODE (t
) == FIELD_DECL
&& DECL_NORMAL_CAPTURE_P (t
))
1178 pp_string (pp
, IDENTIFIER_POINTER (DECL_NAME (t
)) + 2);
1179 pp_string (pp
, " capture>");
1182 dump_decl (pp
, DECL_NAME (t
), flags
);
1184 else if (DECL_DECOMPOSITION_P (t
))
1185 pp_string (pp
, M_("<structured bindings>"));
1186 else if (TREE_CODE (t
) == FIELD_DECL
&& DECL_FIELD_IS_BASE (t
))
1187 dump_type (pp
, TREE_TYPE (t
), flags
);
1189 pp_string (pp
, M_("<anonymous>"));
1191 dump_module_suffix (pp
, t
);
1193 if (flags
& TFF_DECL_SPECIFIERS
)
1194 dump_type_suffix (pp
, type
, flags
);
1197 class colorize_guard
1200 cxx_pretty_printer
*pp
;
1202 colorize_guard (bool _colorize
, cxx_pretty_printer
*pp
, const char *name
)
1203 : colorize (_colorize
&& pp_show_color (pp
)), pp (pp
)
1205 pp_string (pp
, colorize_start (colorize
, name
));
1209 pp_string (pp
, colorize_stop (colorize
));
1213 /* Print an IDENTIFIER_NODE that is the name of a declaration. */
1216 dump_decl_name (cxx_pretty_printer
*pp
, tree t
, int flags
)
1218 /* These special cases are duplicated here so that other functions
1219 can feed identifiers to error and get them demangled properly. */
1220 if (IDENTIFIER_CONV_OP_P (t
))
1222 pp_cxx_ws_string (pp
, "operator");
1223 /* Not exactly IDENTIFIER_TYPE_VALUE. */
1224 dump_type (pp
, TREE_TYPE (t
), flags
);
1227 if (dguide_name_p (t
))
1229 dump_decl (pp
, CLASSTYPE_TI_TEMPLATE (TREE_TYPE (t
)),
1230 TFF_UNQUALIFIED_NAME
);
1234 const char *str
= IDENTIFIER_POINTER (t
);
1235 if (startswith (str
, "_ZGR"))
1237 pp_cxx_ws_string (pp
, "<temporary>");
1241 pp_cxx_tree_identifier (pp
, t
);
1244 /* Dump a human readable string for the decl T under control of FLAGS. */
1247 dump_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
1252 /* If doing Objective-C++, give Objective-C a chance to demangle
1253 Objective-C method names. */
1254 if (c_dialect_objc ())
1256 const char *demangled
= objc_maybe_printable_name (t
, flags
);
1259 pp_string (pp
, demangled
);
1264 switch (TREE_CODE (t
))
1267 /* Don't say 'typedef class A' */
1268 if (DECL_ARTIFICIAL (t
) && !DECL_SELF_REFERENCE_P (t
))
1270 if ((flags
& TFF_DECL_SPECIFIERS
)
1271 && TREE_CODE (TREE_TYPE (t
)) == TEMPLATE_TYPE_PARM
)
1273 /* Say `class T' not just `T'. */
1274 pp_cxx_ws_string (pp
, "class");
1276 /* Emit the `...' for a parameter pack. */
1277 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t
)))
1278 pp_cxx_ws_string (pp
, "...");
1281 dump_type (pp
, TREE_TYPE (t
), flags
);
1284 if (TYPE_DECL_ALIAS_P (t
)
1285 && (flags
& TFF_DECL_SPECIFIERS
1286 || flags
& TFF_CLASS_KEY_OR_ENUM
))
1288 pp_cxx_ws_string (pp
, "using");
1289 if (! (flags
& TFF_UNQUALIFIED_NAME
))
1290 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1291 dump_decl (pp
, DECL_NAME (t
), flags
);
1292 pp_cxx_whitespace (pp
);
1293 pp_cxx_ws_string (pp
, "=");
1294 pp_cxx_whitespace (pp
);
1295 dump_type (pp
, (DECL_ORIGINAL_TYPE (t
)
1296 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
)),
1300 if ((flags
& TFF_DECL_SPECIFIERS
)
1301 && !DECL_SELF_REFERENCE_P (t
))
1302 pp_cxx_ws_string (pp
, "typedef");
1303 dump_simple_decl (pp
, t
, DECL_ORIGINAL_TYPE (t
)
1304 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
),
1309 if (DECL_NAME (t
) && VTABLE_NAME_P (DECL_NAME (t
)))
1311 pp_string (pp
, M_("vtable for "));
1312 gcc_assert (TYPE_P (DECL_CONTEXT (t
)));
1313 dump_type (pp
, DECL_CONTEXT (t
), flags
);
1319 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1321 /* Handle variable template specializations. */
1323 && DECL_LANG_SPECIFIC (t
)
1324 && DECL_TEMPLATE_INFO (t
)
1325 && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t
)))
1327 pp_cxx_begin_template_argument_list (pp
);
1328 tree args
= INNERMOST_TEMPLATE_ARGS (DECL_TI_ARGS (t
));
1329 dump_template_argument_list (pp
, args
, flags
);
1330 pp_cxx_end_template_argument_list (pp
);
1335 pp_string (pp
, M_("<return value> "));
1336 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1339 case NAMESPACE_DECL
:
1340 if (flags
& TFF_DECL_SPECIFIERS
)
1341 pp
->declaration (t
);
1344 if (! (flags
& TFF_UNQUALIFIED_NAME
))
1345 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1346 flags
&= ~TFF_UNQUALIFIED_NAME
;
1347 if (DECL_NAME (t
) == NULL_TREE
)
1349 if (!(pp
->flags
& pp_c_flag_gnu_v3
))
1350 pp_cxx_ws_string (pp
, M_("{anonymous}"));
1352 pp_cxx_ws_string (pp
, M_("(anonymous namespace)"));
1355 pp_cxx_tree_identifier (pp
, DECL_NAME (t
));
1360 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
1361 pp_cxx_colon_colon (pp
);
1362 dump_decl (pp
, TREE_OPERAND (t
, 1), TFF_UNQUALIFIED_NAME
);
1366 dump_decl (pp
, TREE_OPERAND (t
, 0), flags
);
1367 pp_cxx_left_bracket (pp
);
1368 dump_decl (pp
, TREE_OPERAND (t
, 1), flags
);
1369 pp_cxx_right_bracket (pp
);
1372 /* So that we can do dump_decl on an aggr type. */
1376 dump_type (pp
, t
, flags
);
1380 /* This is a pseudo destructor call which has not been folded into
1381 a PSEUDO_DTOR_EXPR yet. */
1382 pp_cxx_complement (pp
);
1383 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
1390 case IDENTIFIER_NODE
:
1391 dump_decl_name (pp
, t
, flags
);
1395 if (!OVL_SINGLE_P (t
))
1397 tree ctx
= ovl_scope (t
);
1398 if (ctx
!= global_namespace
)
1401 dump_type (pp
, ctx
, flags
);
1403 dump_decl (pp
, ctx
, flags
);
1404 pp_cxx_colon_colon (pp
);
1406 dump_decl (pp
, OVL_NAME (t
), flags
);
1410 /* If there's only one function, just treat it like an ordinary
1416 if (! DECL_LANG_SPECIFIC (t
))
1418 if (DECL_ABSTRACT_ORIGIN (t
)
1419 && DECL_ABSTRACT_ORIGIN (t
) != t
)
1420 dump_decl (pp
, DECL_ABSTRACT_ORIGIN (t
), flags
);
1422 dump_function_name (pp
, t
, flags
);
1424 else if (DECL_GLOBAL_CTOR_P (t
) || DECL_GLOBAL_DTOR_P (t
))
1425 dump_global_iord (pp
, t
);
1427 dump_function_decl (pp
, t
, flags
);
1431 dump_template_decl (pp
, t
, flags
);
1435 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1439 pp_string (pp
, "<wildcard>");
1442 case TEMPLATE_ID_EXPR
:
1444 tree name
= TREE_OPERAND (t
, 0);
1445 tree args
= TREE_OPERAND (t
, 1);
1447 if (!identifier_p (name
))
1448 name
= OVL_NAME (name
);
1449 dump_decl (pp
, name
, flags
);
1450 pp_cxx_begin_template_argument_list (pp
);
1451 if (args
== error_mark_node
)
1452 pp_string (pp
, M_("<template arguments error>"));
1454 dump_template_argument_list
1455 (pp
, args
, flags
|TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS
);
1456 pp_cxx_end_template_argument_list (pp
);
1462 pp_cxx_tree_identifier (pp
, DECL_NAME (t
));
1464 dump_generic_node (pp
, t
, 0, TDF_SLIM
, false);
1468 if ((TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == ENUMERAL_TYPE
)
1469 || (DECL_INITIAL (t
) &&
1470 TREE_CODE (DECL_INITIAL (t
)) == TEMPLATE_PARM_INDEX
))
1471 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1472 else if (DECL_NAME (t
))
1473 dump_decl (pp
, DECL_NAME (t
), flags
);
1474 else if (DECL_INITIAL (t
))
1475 dump_expr (pp
, DECL_INITIAL (t
), flags
| TFF_EXPR_IN_PARENS
);
1477 pp_string (pp
, M_("<enumerator>"));
1482 if (flags
& TFF_DECL_SPECIFIERS
)
1483 pp_cxx_ws_string (pp
, "using");
1484 bool variadic
= false;
1485 if (!(flags
& TFF_UNQUALIFIED_NAME
))
1487 tree scope
= USING_DECL_SCOPE (t
);
1488 tree name
= DECL_NAME (t
);
1489 if (PACK_EXPANSION_P (scope
))
1491 scope
= PACK_EXPANSION_PATTERN (scope
);
1494 if (identifier_p (name
)
1495 && IDENTIFIER_CONV_OP_P (name
)
1496 && PACK_EXPANSION_P (TREE_TYPE (name
)))
1498 name
= make_conv_op_name (PACK_EXPANSION_PATTERN
1499 (TREE_TYPE (name
)));
1502 dump_type (pp
, scope
, flags
);
1503 pp_cxx_colon_colon (pp
);
1505 dump_decl (pp
, DECL_NAME (t
), flags
);
1507 pp_cxx_ws_string (pp
, "...");
1512 pp
->declaration (t
);
1516 dump_decl (pp
, BASELINK_FUNCTIONS (t
), flags
);
1519 case TEMPLATE_TYPE_PARM
:
1520 if (flags
& TFF_DECL_SPECIFIERS
)
1521 pp
->declaration (t
);
1526 case UNBOUND_CLASS_TEMPLATE
:
1527 case TYPE_PACK_EXPANSION
:
1529 dump_type (pp
, t
, flags
);
1533 pp_unsupported_tree (pp
, t
);
1537 pp_string (pp
, M_("<declaration error>"));
1542 /* Dump a template declaration T under control of FLAGS. This means the
1543 'template <...> leaders plus the 'class X' or 'void fn(...)' part. */
1546 dump_template_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
1548 tree orig_parms
= DECL_TEMPLATE_PARMS (t
);
1552 if (flags
& TFF_TEMPLATE_HEADER
)
1554 for (parms
= orig_parms
= nreverse (orig_parms
);
1556 parms
= TREE_CHAIN (parms
))
1558 tree inner_parms
= INNERMOST_TEMPLATE_PARMS (parms
);
1559 int len
= TREE_VEC_LENGTH (inner_parms
);
1563 /* Skip over the dummy template levels of a template template
1565 gcc_assert (TREE_CODE (TREE_TYPE (t
)) == TEMPLATE_TEMPLATE_PARM
);
1569 pp_cxx_ws_string (pp
, "template");
1570 pp_cxx_begin_template_argument_list (pp
);
1572 /* If we've shown the template prefix, we'd better show the
1573 parameters' and decl's type too. */
1574 flags
|= TFF_DECL_SPECIFIERS
;
1576 for (i
= 0; i
< len
; i
++)
1579 pp_separate_with_comma (pp
);
1580 dump_template_parameter (pp
, TREE_VEC_ELT (inner_parms
, i
),
1583 pp_cxx_end_template_argument_list (pp
);
1584 pp_cxx_whitespace (pp
);
1586 nreverse(orig_parms
);
1588 if (DECL_TEMPLATE_TEMPLATE_PARM_P (t
))
1590 /* Say `template<arg> class TT' not just `template<arg> TT'. */
1591 pp_cxx_ws_string (pp
, "class");
1593 /* If this is a parameter pack, print the ellipsis. */
1594 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t
)))
1595 pp_cxx_ws_string (pp
, "...");
1598 /* Only print the requirements if we're also printing
1599 the template header. */
1601 if (tree ci
= get_constraints (t
))
1602 if (check_constraint_info (ci
))
1603 if (tree reqs
= CI_TEMPLATE_REQS (ci
))
1605 pp_cxx_requires_clause (pp
, reqs
);
1606 pp_cxx_whitespace (pp
);
1611 if (DECL_CLASS_TEMPLATE_P (t
))
1612 dump_type (pp
, TREE_TYPE (t
),
1613 ((flags
& ~TFF_CLASS_KEY_OR_ENUM
) | TFF_TEMPLATE_NAME
1614 | (flags
& TFF_DECL_SPECIFIERS
? TFF_CLASS_KEY_OR_ENUM
: 0)));
1615 else if (DECL_TEMPLATE_RESULT (t
)
1616 && (VAR_P (DECL_TEMPLATE_RESULT (t
))
1617 /* Alias template. */
1618 || DECL_TYPE_TEMPLATE_P (t
)
1619 /* Concept definition. &*/
1620 || TREE_CODE (DECL_TEMPLATE_RESULT (t
)) == CONCEPT_DECL
))
1621 dump_decl (pp
, DECL_TEMPLATE_RESULT (t
), flags
| TFF_TEMPLATE_NAME
);
1624 gcc_assert (TREE_TYPE (t
));
1625 switch (NEXT_CODE (t
))
1629 dump_function_decl (pp
, t
, flags
| TFF_TEMPLATE_NAME
);
1632 /* This case can occur with some invalid code. */
1633 dump_type (pp
, TREE_TYPE (t
),
1634 (flags
& ~TFF_CLASS_KEY_OR_ENUM
) | TFF_TEMPLATE_NAME
1635 | (flags
& TFF_DECL_SPECIFIERS
1636 ? TFF_CLASS_KEY_OR_ENUM
: 0));
1641 /* find_typenames looks through the type of the function template T
1642 and returns a vec containing any typedefs, decltypes or TYPENAME_TYPEs
1645 struct find_typenames_t
1647 hash_set
<tree
> *p_set
;
1648 vec
<tree
, va_gc
> *typenames
;
1652 find_typenames_r (tree
*tp
, int *walk_subtrees
, void *data
)
1654 struct find_typenames_t
*d
= (struct find_typenames_t
*)data
;
1655 tree mv
= NULL_TREE
;
1657 if (TYPE_P (*tp
) && is_typedef_decl (TYPE_NAME (*tp
)))
1658 /* Add the type of the typedef without any additional cv-quals. */
1659 mv
= TREE_TYPE (TYPE_NAME (*tp
));
1660 else if (TREE_CODE (*tp
) == TYPENAME_TYPE
1661 || TREE_CODE (*tp
) == DECLTYPE_TYPE
)
1662 /* Add the typename without any cv-qualifiers. */
1663 mv
= TYPE_MAIN_VARIANT (*tp
);
1665 if (PACK_EXPANSION_P (*tp
))
1667 /* Don't mess with parameter packs since we don't remember
1668 the pack expansion context for a particular typename. */
1669 *walk_subtrees
= false;
1673 if (mv
&& (mv
== *tp
|| !d
->p_set
->add (mv
)))
1674 vec_safe_push (d
->typenames
, mv
);
1679 static vec
<tree
, va_gc
> *
1680 find_typenames (tree t
)
1682 struct find_typenames_t ft
;
1683 ft
.p_set
= new hash_set
<tree
>;
1684 ft
.typenames
= NULL
;
1685 cp_walk_tree (&TREE_TYPE (DECL_TEMPLATE_RESULT (t
)),
1686 find_typenames_r
, &ft
, ft
.p_set
);
1688 return ft
.typenames
;
1691 /* Output the "[with ...]" clause for a template instantiation T iff
1692 TEMPLATE_PARMS, TEMPLATE_ARGS and FLAGS are suitable. T may be NULL if
1693 formatting a deduction/substitution diagnostic rather than an
1697 dump_substitution (cxx_pretty_printer
*pp
,
1698 tree t
, tree template_parms
, tree template_args
,
1701 if (template_parms
!= NULL_TREE
&& template_args
!= NULL_TREE
1702 && !(flags
& TFF_NO_TEMPLATE_BINDINGS
))
1704 vec
<tree
, va_gc
> *typenames
= t
? find_typenames (t
) : NULL
;
1705 dump_template_bindings (pp
, template_parms
, template_args
, typenames
);
1709 /* Dump the lambda function FN including its 'mutable' qualifier and any
1710 template bindings. */
1713 dump_lambda_function (cxx_pretty_printer
*pp
,
1714 tree fn
, tree template_parms
, tree template_args
,
1717 /* A lambda's signature is essentially its "type". */
1718 dump_type (pp
, DECL_CONTEXT (fn
), flags
);
1719 if (DECL_XOBJ_MEMBER_FUNCTION_P (fn
))
1720 /* Early escape. */;
1721 else if (TREE_CODE (TREE_TYPE (fn
)) == FUNCTION_TYPE
)
1723 pp
->padding
= pp_before
;
1724 pp_c_ws_string (pp
, "static");
1726 else if (!(TYPE_QUALS (class_of_this_parm (TREE_TYPE (fn
)))
1729 pp
->padding
= pp_before
;
1730 pp_c_ws_string (pp
, "mutable");
1732 dump_substitution (pp
, fn
, template_parms
, template_args
, flags
);
1735 /* Pretty print a function decl. There are several ways we want to print a
1736 function declaration. The TFF_ bits in FLAGS tells us how to behave.
1737 As error can only apply the '#' flag once to give 0 and 1 for V, there
1738 is %D which doesn't print the throw specs, and %F which does. */
1741 dump_function_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
1745 tree cname
= NULL_TREE
;
1746 tree template_args
= NULL_TREE
;
1747 tree template_parms
= NULL_TREE
;
1748 int show_return
= flags
& TFF_RETURN_TYPE
|| flags
& TFF_DECL_SPECIFIERS
;
1749 int do_outer_scope
= ! (flags
& TFF_UNQUALIFIED_NAME
);
1752 tree ret
= NULL_TREE
;
1754 int dump_function_name_flags
= flags
& ~TFF_UNQUALIFIED_NAME
;
1755 flags
= dump_function_name_flags
& ~TFF_TEMPLATE_NAME
;
1756 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1757 t
= DECL_TEMPLATE_RESULT (t
);
1759 /* Save the exceptions, in case t is a specialization and we are
1760 emitting an error about incompatible specifications. */
1761 exceptions
= TYPE_RAISES_EXCEPTIONS (TREE_TYPE (t
));
1763 /* Likewise for the constexpr specifier, in case t is a specialization. */
1764 constexpr_p
= (DECL_DECLARED_CONSTEXPR_P (t
)
1765 && !decl_implicit_constexpr_p (t
));
1767 /* Pretty print template instantiations only. */
1768 if (DECL_USE_TEMPLATE (t
) && DECL_TEMPLATE_INFO (t
)
1769 && !(flags
& TFF_NO_TEMPLATE_BINDINGS
)
1770 && flag_pretty_templates
)
1774 template_args
= DECL_TI_ARGS (t
);
1775 tmpl
= most_general_template (t
);
1776 if (tmpl
&& TREE_CODE (tmpl
) == TEMPLATE_DECL
)
1778 template_parms
= DECL_TEMPLATE_PARMS (tmpl
);
1783 if (DECL_NAME (t
) && LAMBDA_FUNCTION_P (t
))
1784 return dump_lambda_function (pp
, t
, template_parms
, template_args
, flags
);
1786 fntype
= TREE_TYPE (t
);
1787 parmtypes
= FUNCTION_FIRST_USER_PARMTYPE (t
);
1789 if (DECL_CLASS_SCOPE_P (t
))
1790 cname
= DECL_CONTEXT (t
);
1791 /* This is for partially instantiated template methods. */
1792 else if (TREE_CODE (fntype
) == METHOD_TYPE
)
1793 cname
= TREE_TYPE (TREE_VALUE (parmtypes
));
1795 if (flags
& TFF_DECL_SPECIFIERS
)
1797 if (DECL_STATIC_FUNCTION_P (t
))
1798 pp_cxx_ws_string (pp
, "static");
1799 else if (DECL_VIRTUAL_P (t
))
1800 pp_cxx_ws_string (pp
, "virtual");
1804 if (DECL_DECLARED_CONCEPT_P (t
))
1805 pp_cxx_ws_string (pp
, "concept");
1806 else if (DECL_IMMEDIATE_FUNCTION_P (t
))
1807 pp_cxx_ws_string (pp
, "consteval");
1809 pp_cxx_ws_string (pp
, "constexpr");
1813 /* Print the return type? */
1815 show_return
= (!DECL_CONV_FN_P (t
) && !DECL_CONSTRUCTOR_P (t
)
1816 && !DECL_DESTRUCTOR_P (t
) && !deduction_guide_p (t
));
1819 ret
= fndecl_declared_return_type (t
);
1820 dump_type_prefix (pp
, ret
, flags
);
1823 /* Print the function name. */
1824 if (!do_outer_scope
)
1828 dump_type (pp
, cname
, flags
);
1829 pp_cxx_colon_colon (pp
);
1832 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1834 /* Name lookup for the rest of the function declarator is implicitly in the
1835 scope of the function, so avoid printing redundant scope qualifiers. */
1836 auto cds
= make_temp_override (current_dump_scope
, CP_DECL_CONTEXT (t
));
1838 dump_function_name (pp
, t
, dump_function_name_flags
);
1840 if (!(flags
& TFF_NO_FUNCTION_ARGUMENTS
))
1842 int const parm_flags
1843 = DECL_XOBJ_MEMBER_FUNCTION_P (t
) ? TFF_XOBJ_FUNC
| flags
: flags
;
1844 dump_parameters (pp
, parmtypes
, parm_flags
);
1846 if (TREE_CODE (fntype
) == METHOD_TYPE
)
1848 pp
->padding
= pp_before
;
1849 pp_cxx_cv_qualifier_seq (pp
, class_of_this_parm (fntype
));
1850 dump_ref_qualifier (pp
, fntype
, flags
);
1853 if (tx_safe_fn_type_p (fntype
))
1855 pp
->padding
= pp_before
;
1856 pp_cxx_ws_string (pp
, "transaction_safe");
1859 if (flags
& TFF_EXCEPTION_SPECIFICATION
)
1861 pp
->padding
= pp_before
;
1862 dump_exception_spec (pp
, exceptions
, flags
);
1866 dump_type_suffix (pp
, ret
, flags
);
1867 else if (deduction_guide_p (t
))
1869 pp_cxx_ws_string (pp
, "->");
1870 dump_type (pp
, TREE_TYPE (TREE_TYPE (t
)), flags
);
1874 if (tree ci
= get_constraints (t
))
1875 if (tree reqs
= CI_DECLARATOR_REQS (ci
))
1876 pp_cxx_requires_clause (pp
, reqs
);
1878 dump_substitution (pp
, t
, template_parms
, template_args
, flags
);
1880 if (tree base
= DECL_INHERITED_CTOR_BASE (t
))
1882 pp_cxx_ws_string (pp
, "[inherited from");
1883 dump_type (pp
, base
, TFF_PLAIN_IDENTIFIER
);
1884 pp_character (pp
, ']');
1887 else if (template_args
)
1889 bool need_comma
= false;
1891 pp_cxx_begin_template_argument_list (pp
);
1892 template_args
= INNERMOST_TEMPLATE_ARGS (template_args
);
1893 for (i
= 0; i
< TREE_VEC_LENGTH (template_args
); ++i
)
1895 tree arg
= TREE_VEC_ELT (template_args
, i
);
1897 pp_separate_with_comma (pp
);
1898 if (ARGUMENT_PACK_P (arg
))
1899 pp_cxx_left_brace (pp
);
1900 dump_template_argument (pp
, arg
, TFF_PLAIN_IDENTIFIER
);
1901 if (ARGUMENT_PACK_P (arg
))
1902 pp_cxx_right_brace (pp
);
1905 pp_cxx_end_template_argument_list (pp
);
1909 /* Print a parameter list. If this is for a member function, the
1910 member object ptr (and any other hidden args) should have
1911 already been removed. */
1914 dump_parameters (cxx_pretty_printer
*pp
, tree parmtypes
, int flags
)
1917 flags
&= ~TFF_SCOPE
;
1918 pp_cxx_left_paren (pp
);
1920 for (first
= 1; parmtypes
!= void_list_node
;
1921 parmtypes
= TREE_CHAIN (parmtypes
))
1923 if (first
&& flags
& TFF_XOBJ_FUNC
)
1924 pp_string (pp
, "this ");
1926 pp_separate_with_comma (pp
);
1930 pp_cxx_ws_string (pp
, "...");
1934 dump_type (pp
, TREE_VALUE (parmtypes
), flags
);
1936 if ((flags
& TFF_FUNCTION_DEFAULT_ARGUMENTS
) && TREE_PURPOSE (parmtypes
))
1938 pp_cxx_whitespace (pp
);
1940 pp_cxx_whitespace (pp
);
1941 dump_expr (pp
, TREE_PURPOSE (parmtypes
), flags
| TFF_EXPR_IN_PARENS
);
1945 pp_cxx_right_paren (pp
);
1948 /* Print ref-qualifier of a FUNCTION_TYPE or METHOD_TYPE. FLAGS are ignored. */
1951 dump_ref_qualifier (cxx_pretty_printer
*pp
, tree t
, int flags ATTRIBUTE_UNUSED
)
1953 if (FUNCTION_REF_QUALIFIED (t
))
1955 pp
->padding
= pp_before
;
1956 if (FUNCTION_RVALUE_QUALIFIED (t
))
1957 pp_cxx_ws_string (pp
, "&&");
1959 pp_cxx_ws_string (pp
, "&");
1963 /* Print an exception specification. T is the exception specification. */
1966 dump_exception_spec (cxx_pretty_printer
*pp
, tree t
, int flags
)
1968 if (t
&& TREE_PURPOSE (t
))
1970 pp_cxx_ws_string (pp
, "noexcept");
1971 if (!integer_onep (TREE_PURPOSE (t
)))
1973 pp_cxx_whitespace (pp
);
1974 pp_cxx_left_paren (pp
);
1975 if (DEFERRED_NOEXCEPT_SPEC_P (t
))
1976 pp_cxx_ws_string (pp
, "<uninstantiated>");
1978 dump_expr (pp
, TREE_PURPOSE (t
), flags
);
1979 pp_cxx_right_paren (pp
);
1984 pp_cxx_ws_string (pp
, "throw");
1985 pp_cxx_whitespace (pp
);
1986 pp_cxx_left_paren (pp
);
1987 if (TREE_VALUE (t
) != NULL_TREE
)
1990 dump_type (pp
, TREE_VALUE (t
), flags
);
1994 pp_separate_with_comma (pp
);
1996 pp_cxx_right_paren (pp
);
2000 /* Handle the function name for a FUNCTION_DECL node, grokking operators
2001 and destructors properly. */
2004 dump_function_name (cxx_pretty_printer
*pp
, tree t
, int flags
)
2006 /* Only colorize when we're printing something before the name; in
2007 particular, not when printing a CALL_EXPR. */
2008 bool colorize
= flags
& (TFF_DECL_SPECIFIERS
| TFF_RETURN_TYPE
2009 | TFF_TEMPLATE_HEADER
);
2011 colorize_guard
g (colorize
, pp
, "fnname");
2013 tree name
= DECL_NAME (t
);
2015 /* We can get here with a decl that was synthesized by language-
2016 independent machinery (e.g. coverage.cc) in which case it won't
2017 have a lang_specific structure attached and DECL_CONSTRUCTOR_P
2018 will crash. In this case it is safe just to print out the
2020 if (!DECL_LANG_SPECIFIC (t
))
2022 pp_cxx_tree_identifier (pp
, name
);
2026 if (TREE_CODE (t
) == TEMPLATE_DECL
)
2027 t
= DECL_TEMPLATE_RESULT (t
);
2029 /* Don't let the user see __comp_ctor et al. */
2030 if (DECL_CONSTRUCTOR_P (t
)
2031 || DECL_DESTRUCTOR_P (t
))
2033 if (LAMBDA_TYPE_P (DECL_CONTEXT (t
)))
2034 name
= get_identifier ("<lambda>");
2035 else if (TYPE_UNNAMED_P (DECL_CONTEXT (t
)))
2036 name
= get_identifier ("<constructor>");
2038 name
= constructor_name (DECL_CONTEXT (t
));
2041 if (DECL_DESTRUCTOR_P (t
))
2043 pp_cxx_complement (pp
);
2044 dump_decl (pp
, name
, TFF_PLAIN_IDENTIFIER
);
2046 else if (DECL_CONV_FN_P (t
))
2048 /* This cannot use the hack that the operator's return
2049 type is stashed off of its name because it may be
2050 used for error reporting. In the case of conflicting
2051 declarations, both will have the same name, yet
2052 the types will be different, hence the TREE_TYPE field
2053 of the first name will be clobbered by the second. */
2054 pp_cxx_ws_string (pp
, "operator");
2055 dump_type (pp
, TREE_TYPE (TREE_TYPE (t
)), flags
);
2058 dump_decl (pp
, name
, flags
);
2060 dump_module_suffix (pp
, t
);
2062 if (DECL_TEMPLATE_INFO (t
)
2063 && !(flags
& TFF_TEMPLATE_NAME
)
2064 && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t
)
2065 && (TREE_CODE (DECL_TI_TEMPLATE (t
)) != TEMPLATE_DECL
2066 || PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t
))))
2067 dump_template_parms (pp
, DECL_TEMPLATE_INFO (t
), !DECL_USE_TEMPLATE (t
),
2071 /* Dump the template parameters from the template info INFO under control of
2072 FLAGS. PRIMARY indicates whether this is a primary template decl, or
2073 specialization (partial or complete). For partial specializations we show
2074 the specialized parameter values. For a primary template we show no
2078 dump_template_parms (cxx_pretty_printer
*pp
, tree info
,
2079 int primary
, int flags
)
2081 tree args
= info
? TI_ARGS (info
) : NULL_TREE
;
2083 if (primary
&& flags
& TFF_TEMPLATE_NAME
)
2085 flags
&= ~(TFF_CLASS_KEY_OR_ENUM
| TFF_TEMPLATE_NAME
);
2086 pp_cxx_begin_template_argument_list (pp
);
2088 /* Be careful only to print things when we have them, so as not
2089 to crash producing error messages. */
2090 if (args
&& !primary
)
2093 len
= get_non_default_template_args_count (args
, flags
);
2095 args
= INNERMOST_TEMPLATE_ARGS (args
);
2096 for (ix
= 0; ix
!= len
; ix
++)
2098 tree arg
= TREE_VEC_ELT (args
, ix
);
2100 /* Only print a comma if we know there is an argument coming. In
2101 the case of an empty template argument pack, no actual
2102 argument will be printed. */
2104 && (!ARGUMENT_PACK_P (arg
)
2105 || TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg
)) > 0))
2106 pp_separate_with_comma (pp
);
2109 pp_string (pp
, M_("<template parameter error>"));
2111 dump_template_argument (pp
, arg
, flags
);
2116 tree tpl
= TI_TEMPLATE (info
);
2117 tree parms
= DECL_TEMPLATE_PARMS (tpl
);
2120 parms
= TREE_CODE (parms
) == TREE_LIST
? TREE_VALUE (parms
) : NULL_TREE
;
2121 len
= parms
? TREE_VEC_LENGTH (parms
) : 0;
2123 for (ix
= 0; ix
!= len
; ix
++)
2127 if (TREE_VEC_ELT (parms
, ix
) == error_mark_node
)
2129 pp_string (pp
, M_("<template parameter error>"));
2133 parm
= TREE_VALUE (TREE_VEC_ELT (parms
, ix
));
2136 pp_separate_with_comma (pp
);
2138 dump_decl (pp
, parm
, flags
& ~TFF_DECL_SPECIFIERS
);
2141 pp_cxx_end_template_argument_list (pp
);
2144 /* Print out the arguments of CALL_EXPR T as a parenthesized list using
2145 flags FLAGS. Skip over the first argument if SKIPFIRST is true. */
2148 dump_call_expr_args (cxx_pretty_printer
*pp
, tree t
, int flags
, bool skipfirst
)
2151 call_expr_arg_iterator iter
;
2153 pp_cxx_left_paren (pp
);
2154 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, t
)
2160 dump_expr (pp
, arg
, flags
| TFF_EXPR_IN_PARENS
);
2161 if (more_call_expr_args_p (&iter
))
2162 pp_separate_with_comma (pp
);
2165 pp_cxx_right_paren (pp
);
2168 /* Print out the arguments of AGGR_INIT_EXPR T as a parenthesized list
2169 using flags FLAGS. Skip over the first argument if SKIPFIRST is
2173 dump_aggr_init_expr_args (cxx_pretty_printer
*pp
, tree t
, int flags
,
2177 aggr_init_expr_arg_iterator iter
;
2179 pp_cxx_left_paren (pp
);
2180 FOR_EACH_AGGR_INIT_EXPR_ARG (arg
, iter
, t
)
2186 dump_expr (pp
, arg
, flags
| TFF_EXPR_IN_PARENS
);
2187 if (more_aggr_init_expr_args_p (&iter
))
2188 pp_separate_with_comma (pp
);
2191 pp_cxx_right_paren (pp
);
2194 /* Print out a list of initializers (subr of dump_expr). */
2197 dump_expr_list (cxx_pretty_printer
*pp
, tree l
, int flags
)
2201 dump_expr (pp
, TREE_VALUE (l
), flags
| TFF_EXPR_IN_PARENS
);
2204 pp_separate_with_comma (pp
);
2208 /* Print out a vector of initializers (subr of dump_expr). */
2211 dump_expr_init_vec (cxx_pretty_printer
*pp
, vec
<constructor_elt
, va_gc
> *v
,
2214 unsigned HOST_WIDE_INT idx
;
2217 FOR_EACH_CONSTRUCTOR_VALUE (v
, idx
, value
)
2219 dump_expr (pp
, value
, flags
| TFF_EXPR_IN_PARENS
);
2220 if (idx
!= v
->length () - 1)
2221 pp_separate_with_comma (pp
);
2226 /* We've gotten an indirect REFERENCE (an OBJ_TYPE_REF) to a virtual
2227 function. Resolve it to a close relative -- in the sense of static
2228 type -- variant being overridden. That is close to what was written in
2229 the source code. Subroutine of dump_expr. */
2232 resolve_virtual_fun_from_obj_type_ref (tree ref
)
2234 tree obj_type
= TREE_TYPE (OBJ_TYPE_REF_TOKEN (ref
));
2235 HOST_WIDE_INT index
= tree_to_uhwi (OBJ_TYPE_REF_TOKEN (ref
));
2236 tree fun
= BINFO_VIRTUALS (TYPE_BINFO (TREE_TYPE (obj_type
)));
2239 fun
= TREE_CHAIN (fun
);
2240 index
-= (TARGET_VTABLE_USES_DESCRIPTORS
2241 ? TARGET_VTABLE_USES_DESCRIPTORS
: 1);
2247 /* Print out an expression E under control of FLAGS. */
2250 dump_expr (cxx_pretty_printer
*pp
, tree t
, int flags
)
2257 if (STATEMENT_CLASS_P (t
))
2259 pp_cxx_ws_string (pp
, M_("<statement>"));
2263 switch (TREE_CODE (t
))
2271 case NAMESPACE_DECL
:
2277 case IDENTIFIER_NODE
:
2278 dump_decl (pp
, t
, ((flags
& ~(TFF_DECL_SPECIFIERS
|TFF_RETURN_TYPE
2279 |TFF_TEMPLATE_HEADER
))
2280 | TFF_NO_TEMPLATE_BINDINGS
2281 | TFF_NO_FUNCTION_ARGUMENTS
));
2285 if (SSA_NAME_VAR (t
)
2286 && !DECL_ARTIFICIAL (SSA_NAME_VAR (t
)))
2287 dump_expr (pp
, SSA_NAME_VAR (t
), flags
);
2289 pp_cxx_ws_string (pp
, M_("<unknown>"));
2300 case USERDEF_LITERAL
:
2301 pp_cxx_userdef_literal (pp
, t
);
2305 /* While waiting for caret diagnostics, avoid printing
2306 __cxa_allocate_exception, __cxa_throw, and the like. */
2307 pp_cxx_ws_string (pp
, M_("<throw-expression>"));
2312 dump_type (pp
, PTRMEM_CST_CLASS (t
), flags
);
2313 pp_cxx_colon_colon (pp
);
2314 pp_cxx_tree_identifier (pp
, DECL_NAME (PTRMEM_CST_MEMBER (t
)));
2318 pp_cxx_left_paren (pp
);
2319 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2320 pp_separate_with_comma (pp
);
2321 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2322 pp_cxx_right_paren (pp
);
2327 pp_cxx_left_paren (pp
);
2328 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2329 pp_string (pp
, " ? ");
2330 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2331 pp_string (pp
, " : ");
2332 dump_expr (pp
, TREE_OPERAND (t
, 2), flags
| TFF_EXPR_IN_PARENS
);
2333 pp_cxx_right_paren (pp
);
2337 if (TREE_HAS_CONSTRUCTOR (t
))
2339 pp_cxx_ws_string (pp
, "new");
2340 pp_cxx_whitespace (pp
);
2341 dump_type (pp
, TREE_TYPE (TREE_TYPE (t
)), flags
);
2344 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2347 case AGGR_INIT_EXPR
:
2349 tree fn
= NULL_TREE
;
2351 if (TREE_CODE (AGGR_INIT_EXPR_FN (t
)) == ADDR_EXPR
)
2352 fn
= TREE_OPERAND (AGGR_INIT_EXPR_FN (t
), 0);
2354 if (fn
&& TREE_CODE (fn
) == FUNCTION_DECL
)
2356 if (DECL_CONSTRUCTOR_P (fn
))
2357 dump_type (pp
, DECL_CONTEXT (fn
), flags
);
2359 dump_decl (pp
, fn
, 0);
2362 dump_expr (pp
, AGGR_INIT_EXPR_FN (t
), 0);
2364 dump_aggr_init_expr_args (pp
, t
, flags
, true);
2369 tree fn
= CALL_EXPR_FN (t
);
2370 bool skipfirst
= false;
2372 /* Deal with internal functions. */
2373 if (fn
== NULL_TREE
)
2375 pp_string (pp
, internal_fn_name (CALL_EXPR_IFN (t
)));
2376 dump_call_expr_args (pp
, t
, flags
, skipfirst
);
2380 if (TREE_CODE (fn
) == ADDR_EXPR
)
2381 fn
= TREE_OPERAND (fn
, 0);
2383 /* Nobody is interested in seeing the guts of vcalls. */
2384 if (TREE_CODE (fn
) == OBJ_TYPE_REF
)
2385 fn
= resolve_virtual_fun_from_obj_type_ref (fn
);
2387 if (TREE_TYPE (fn
) != NULL_TREE
2388 && NEXT_CODE (fn
) == METHOD_TYPE
2389 && call_expr_nargs (t
))
2391 tree ob
= CALL_EXPR_ARG (t
, 0);
2392 if (TREE_CODE (ob
) == ADDR_EXPR
)
2394 dump_expr (pp
, TREE_OPERAND (ob
, 0),
2395 flags
| TFF_EXPR_IN_PARENS
);
2398 else if (!is_this_parameter (ob
))
2400 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2405 if (flag_sanitize
& SANITIZE_UNDEFINED
2406 && is_ubsan_builtin_p (fn
))
2408 pp_string (cxx_pp
, M_("<ubsan routine call>"));
2411 dump_expr (pp
, fn
, flags
| TFF_EXPR_IN_PARENS
);
2412 dump_call_expr_args (pp
, t
, flags
, skipfirst
);
2417 /* Note that this only works for G++ target exprs. If somebody
2418 builds a general TARGET_EXPR, there's no way to represent that
2419 it initializes anything other that the parameter slot for the
2420 default argument. Note we may have cleared out the first
2421 operand in expand_expr, so don't go killing ourselves. */
2422 if (TREE_OPERAND (t
, 1))
2423 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2426 case POINTER_PLUS_EXPR
:
2427 dump_binary_op (pp
, "+", t
, flags
);
2430 case POINTER_DIFF_EXPR
:
2431 dump_binary_op (pp
, "-", t
, flags
);
2436 dump_binary_op (pp
, OVL_OP_INFO (true, NOP_EXPR
)->name
, t
, flags
);
2442 case TRUNC_DIV_EXPR
:
2443 case TRUNC_MOD_EXPR
:
2451 case TRUTH_ANDIF_EXPR
:
2452 case TRUTH_ORIF_EXPR
:
2459 case SPACESHIP_EXPR
:
2460 case EXACT_DIV_EXPR
:
2461 dump_binary_op (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
, t
, flags
);
2465 case FLOOR_DIV_EXPR
:
2466 case ROUND_DIV_EXPR
:
2468 dump_binary_op (pp
, "/", t
, flags
);
2472 case FLOOR_MOD_EXPR
:
2473 case ROUND_MOD_EXPR
:
2474 dump_binary_op (pp
, "%", t
, flags
);
2479 tree ob
= TREE_OPERAND (t
, 0);
2480 if (INDIRECT_REF_P (ob
))
2482 ob
= TREE_OPERAND (ob
, 0);
2483 if (!is_this_parameter (ob
)
2484 && !is_dummy_object (ob
))
2486 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2487 if (TYPE_REF_P (TREE_TYPE (ob
)))
2495 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2496 if (TREE_CODE (ob
) != ARROW_EXPR
)
2499 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
& ~TFF_EXPR_IN_PARENS
);
2504 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2505 pp_cxx_left_bracket (pp
);
2506 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2507 pp_cxx_right_bracket (pp
);
2510 case OMP_ARRAY_SECTION
:
2511 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2512 pp_cxx_left_bracket (pp
);
2513 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
);
2515 dump_expr (pp
, TREE_OPERAND (t
, 2), flags
);
2516 pp_cxx_right_bracket (pp
);
2519 case UNARY_PLUS_EXPR
:
2520 dump_unary_op (pp
, "+", t
, flags
);
2524 if (TREE_CODE (TREE_OPERAND (t
, 0)) == FUNCTION_DECL
2525 || TREE_CODE (TREE_OPERAND (t
, 0)) == STRING_CST
2526 /* An ADDR_EXPR can have reference type. In that case, we
2527 shouldn't print the `&' doing so indicates to the user
2528 that the expression has pointer type. */
2530 && TYPE_REF_P (TREE_TYPE (t
))))
2531 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2532 else if (TREE_CODE (TREE_OPERAND (t
, 0)) == LABEL_DECL
)
2533 dump_unary_op (pp
, "&&", t
, flags
);
2535 dump_unary_op (pp
, "&", t
, flags
);
2539 if (TREE_HAS_CONSTRUCTOR (t
))
2541 t
= TREE_OPERAND (t
, 0);
2542 gcc_assert (TREE_CODE (t
) == CALL_EXPR
);
2543 dump_expr (pp
, CALL_EXPR_FN (t
), flags
| TFF_EXPR_IN_PARENS
);
2544 dump_call_expr_args (pp
, t
, flags
, true);
2548 if (TREE_OPERAND (t
,0) != NULL_TREE
2549 && TREE_TYPE (TREE_OPERAND (t
, 0))
2550 && NEXT_CODE (TREE_OPERAND (t
, 0)) == REFERENCE_TYPE
)
2551 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2553 dump_unary_op (pp
, "*", t
, flags
);
2558 /* Delegate to the base "C" pretty printer. */
2559 pp
->c_pretty_printer::unary_expression (t
);
2562 case TARGET_MEM_REF
:
2563 /* TARGET_MEM_REF can't appear directly from source, but can appear
2564 during late GIMPLE optimizations and through late diagnostic we might
2565 need to support it. Print it as dereferencing of a pointer after
2566 cast to the TARGET_MEM_REF type, with pointer arithmetics on some
2567 pointer to single byte types, so
2568 *(type *)((char *) ptr + step * index + index2) if all the operands
2569 are present and the casts are needed. */
2571 pp_cxx_left_paren (pp
);
2572 if (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (TMR_BASE (t
)))) == NULL_TREE
2573 || !integer_onep (TYPE_SIZE_UNIT
2574 (TREE_TYPE (TREE_TYPE (TMR_BASE (t
))))))
2576 if (TYPE_SIZE_UNIT (TREE_TYPE (t
))
2577 && integer_onep (TYPE_SIZE_UNIT (TREE_TYPE (t
))))
2579 pp_cxx_left_paren (pp
);
2580 dump_type (pp
, build_pointer_type (TREE_TYPE (t
)), flags
);
2584 dump_type (pp
, build_pointer_type (TREE_TYPE (t
)), flags
);
2585 pp_cxx_right_paren (pp
);
2586 pp_cxx_left_paren (pp
);
2587 pp_cxx_left_paren (pp
);
2588 dump_type (pp
, build_pointer_type (char_type_node
), flags
);
2590 pp_cxx_right_paren (pp
);
2592 else if (!same_type_p (TREE_TYPE (t
),
2593 TREE_TYPE (TREE_TYPE (TMR_BASE (t
)))))
2595 dump_type (pp
, build_pointer_type (TREE_TYPE (t
)), flags
);
2596 pp_cxx_right_paren (pp
);
2597 pp_cxx_left_paren (pp
);
2599 dump_expr (pp
, TMR_BASE (t
), flags
);
2600 if (TMR_STEP (t
) && TMR_INDEX (t
))
2602 pp_cxx_ws_string (pp
, "+");
2603 dump_expr (pp
, TMR_INDEX (t
), flags
);
2604 pp_cxx_ws_string (pp
, "*");
2605 dump_expr (pp
, TMR_STEP (t
), flags
);
2609 pp_cxx_ws_string (pp
, "+");
2610 dump_expr (pp
, TMR_INDEX2 (t
), flags
);
2612 if (!integer_zerop (TMR_OFFSET (t
)))
2614 pp_cxx_ws_string (pp
, "+");
2615 dump_expr (pp
, fold_convert (ssizetype
, TMR_OFFSET (t
)), flags
);
2617 pp_cxx_right_paren (pp
);
2622 case TRUTH_NOT_EXPR
:
2623 case PREDECREMENT_EXPR
:
2624 case PREINCREMENT_EXPR
:
2625 dump_unary_op (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
, t
, flags
);
2628 case POSTDECREMENT_EXPR
:
2629 case POSTINCREMENT_EXPR
:
2630 pp_cxx_left_paren (pp
);
2631 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2632 pp_cxx_ws_string (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
);
2633 pp_cxx_right_paren (pp
);
2636 case NON_LVALUE_EXPR
:
2637 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
2638 should be another level of INDIRECT_REF so that I don't have to do
2640 if (TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == POINTER_TYPE
)
2642 tree next
= TREE_TYPE (TREE_TYPE (t
));
2644 while (TYPE_PTR_P (next
))
2645 next
= TREE_TYPE (next
);
2647 if (TREE_CODE (next
) == FUNCTION_TYPE
)
2649 if (flags
& TFF_EXPR_IN_PARENS
)
2650 pp_cxx_left_paren (pp
);
2652 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2653 if (flags
& TFF_EXPR_IN_PARENS
)
2654 pp_cxx_right_paren (pp
);
2657 /* Else fall through. */
2659 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2663 case IMPLICIT_CONV_EXPR
:
2664 case VIEW_CONVERT_EXPR
:
2666 tree op
= TREE_OPERAND (t
, 0);
2668 if (location_wrapper_p (t
))
2670 dump_expr (pp
, op
, flags
);
2674 tree ttype
= TREE_TYPE (t
);
2675 tree optype
= TREE_TYPE (op
);
2677 if (TREE_CODE (ttype
) != TREE_CODE (optype
)
2678 && INDIRECT_TYPE_P (ttype
)
2679 && INDIRECT_TYPE_P (optype
)
2680 && same_type_p (TREE_TYPE (optype
),
2683 if (TYPE_REF_P (ttype
))
2686 if (TREE_CODE (op
) == ADDR_EXPR
)
2687 dump_expr (pp
, TREE_OPERAND (op
, 0), flags
);
2689 dump_unary_op (pp
, "*", t
, flags
);
2692 dump_unary_op (pp
, "&", t
, flags
);
2694 else if (!same_type_p (TREE_TYPE (op
), TREE_TYPE (t
)))
2696 /* It is a cast, but we cannot tell whether it is a
2697 reinterpret or static cast. Use the C style notation. */
2698 if (flags
& TFF_EXPR_IN_PARENS
)
2699 pp_cxx_left_paren (pp
);
2700 pp_cxx_left_paren (pp
);
2701 dump_type (pp
, TREE_TYPE (t
), flags
);
2702 pp_cxx_right_paren (pp
);
2703 dump_expr (pp
, op
, flags
| TFF_EXPR_IN_PARENS
);
2704 if (flags
& TFF_EXPR_IN_PARENS
)
2705 pp_cxx_right_paren (pp
);
2708 dump_expr (pp
, op
, flags
);
2713 if (TREE_TYPE (t
) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t
)))
2715 tree idx
= build_ptrmemfunc_access_expr (t
, pfn_identifier
);
2717 if (integer_zerop (idx
))
2719 /* A NULL pointer-to-member constant. */
2720 pp_cxx_left_paren (pp
);
2721 pp_cxx_left_paren (pp
);
2722 dump_type (pp
, TREE_TYPE (t
), flags
);
2723 pp_cxx_right_paren (pp
);
2724 pp_character (pp
, '0');
2725 pp_cxx_right_paren (pp
);
2728 else if (tree_fits_shwi_p (idx
))
2731 unsigned HOST_WIDE_INT n
;
2733 t
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t
)));
2734 t
= TYPE_METHOD_BASETYPE (t
);
2735 virtuals
= BINFO_VIRTUALS (TYPE_BINFO (TYPE_MAIN_VARIANT (t
)));
2737 n
= tree_to_shwi (idx
);
2739 /* Map vtable index back one, to allow for the null pointer to
2743 while (n
> 0 && virtuals
)
2746 virtuals
= TREE_CHAIN (virtuals
);
2750 dump_expr (pp
, BV_FN (virtuals
),
2751 flags
| TFF_EXPR_IN_PARENS
);
2756 if (TREE_TYPE (t
) && LAMBDA_TYPE_P (TREE_TYPE (t
)))
2757 pp_string (pp
, "<lambda closure object>");
2758 if (TREE_TYPE (t
) && EMPTY_CONSTRUCTOR_P (t
))
2760 dump_type (pp
, TREE_TYPE (t
), 0);
2761 pp_cxx_left_paren (pp
);
2762 pp_cxx_right_paren (pp
);
2766 if (!BRACE_ENCLOSED_INITIALIZER_P (t
))
2767 dump_type (pp
, TREE_TYPE (t
), 0);
2768 pp_cxx_left_brace (pp
);
2769 dump_expr_init_vec (pp
, CONSTRUCTOR_ELTS (t
), flags
);
2770 pp_cxx_right_brace (pp
);
2777 tree ob
= TREE_OPERAND (t
, 0);
2778 if (is_dummy_object (ob
))
2780 t
= TREE_OPERAND (t
, 1);
2781 if (TREE_CODE (t
) == FUNCTION_DECL
)
2783 dump_expr (pp
, t
, flags
| TFF_EXPR_IN_PARENS
);
2784 else if (BASELINK_P (t
))
2785 dump_expr (pp
, OVL_FIRST (BASELINK_FUNCTIONS (t
)),
2786 flags
| TFF_EXPR_IN_PARENS
);
2788 dump_decl (pp
, t
, flags
);
2792 if (INDIRECT_REF_P (ob
))
2794 dump_expr (pp
, TREE_OPERAND (ob
, 0), flags
| TFF_EXPR_IN_PARENS
);
2800 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2804 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2809 case TEMPLATE_PARM_INDEX
:
2810 dump_decl (pp
, TEMPLATE_PARM_DECL (t
), flags
& ~TFF_DECL_SPECIFIERS
);
2814 if (TREE_OPERAND (t
, 0) == NULL_TREE
2815 || TREE_CHAIN (TREE_OPERAND (t
, 0)))
2817 dump_type (pp
, TREE_TYPE (t
), flags
);
2818 pp_cxx_left_paren (pp
);
2819 dump_expr_list (pp
, TREE_OPERAND (t
, 0), flags
);
2820 pp_cxx_right_paren (pp
);
2824 pp_cxx_left_paren (pp
);
2825 dump_type (pp
, TREE_TYPE (t
), flags
);
2826 pp_cxx_right_paren (pp
);
2827 pp_cxx_left_paren (pp
);
2828 dump_expr_list (pp
, TREE_OPERAND (t
, 0), flags
);
2829 pp_cxx_right_paren (pp
);
2833 case STATIC_CAST_EXPR
:
2834 pp_cxx_ws_string (pp
, "static_cast");
2836 case REINTERPRET_CAST_EXPR
:
2837 pp_cxx_ws_string (pp
, "reinterpret_cast");
2839 case CONST_CAST_EXPR
:
2840 pp_cxx_ws_string (pp
, "const_cast");
2842 case DYNAMIC_CAST_EXPR
:
2843 pp_cxx_ws_string (pp
, "dynamic_cast");
2845 pp_cxx_begin_template_argument_list (pp
);
2846 dump_type (pp
, TREE_TYPE (t
), flags
);
2847 pp_cxx_end_template_argument_list (pp
);
2848 pp_cxx_left_paren (pp
);
2849 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2850 pp_cxx_right_paren (pp
);
2854 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2860 if (TREE_CODE (t
) == SIZEOF_EXPR
)
2861 pp_cxx_ws_string (pp
, "sizeof");
2862 else if (ALIGNOF_EXPR_STD_P (t
))
2863 pp_cxx_ws_string (pp
, "alignof");
2865 pp_cxx_ws_string (pp
, "__alignof__");
2866 op
= TREE_OPERAND (t
, 0);
2867 if (PACK_EXPANSION_P (op
))
2869 pp_string (pp
, "...");
2870 op
= PACK_EXPANSION_PATTERN (op
);
2872 pp_cxx_whitespace (pp
);
2873 pp_cxx_left_paren (pp
);
2874 if (TREE_CODE (t
) == SIZEOF_EXPR
&& SIZEOF_EXPR_TYPE_P (t
))
2875 dump_type (pp
, TREE_TYPE (op
), flags
);
2876 else if (TYPE_P (TREE_OPERAND (t
, 0)))
2877 dump_type (pp
, op
, flags
);
2879 dump_expr (pp
, op
, flags
);
2880 pp_cxx_right_paren (pp
);
2883 case AT_ENCODE_EXPR
:
2884 pp_cxx_ws_string (pp
, "@encode");
2885 pp_cxx_whitespace (pp
);
2886 pp_cxx_left_paren (pp
);
2887 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
2888 pp_cxx_right_paren (pp
);
2892 pp_cxx_ws_string (pp
, "noexcept");
2893 pp_cxx_whitespace (pp
);
2894 pp_cxx_left_paren (pp
);
2895 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2896 pp_cxx_right_paren (pp
);
2901 pp_cxx_ws_string (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
);
2902 pp_cxx_whitespace (pp
);
2903 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2906 case DEFERRED_PARSE
:
2907 pp_string (pp
, M_("<unparsed>"));
2910 case TRY_CATCH_EXPR
:
2911 case CLEANUP_POINT_EXPR
:
2912 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2915 case PSEUDO_DTOR_EXPR
:
2916 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2918 if (TREE_OPERAND (t
, 1))
2920 dump_type (pp
, TREE_OPERAND (t
, 1), flags
);
2921 pp_cxx_colon_colon (pp
);
2923 pp_cxx_complement (pp
);
2924 dump_type (pp
, TREE_OPERAND (t
, 2), flags
);
2927 case TEMPLATE_ID_EXPR
:
2928 dump_decl (pp
, t
, flags
);
2934 case STATEMENT_LIST
:
2935 /* We don't yet have a way of dumping statements in a
2936 human-readable format. */
2937 pp_string (pp
, "({...})");
2941 pp_string (pp
, "while (1) { ");
2942 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2943 pp_cxx_right_brace (pp
);
2947 pp_string (pp
, "if (");
2948 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2949 pp_string (pp
, ") break; ");
2953 dump_expr (pp
, BASELINK_FUNCTIONS (t
), flags
& ~TFF_EXPR_IN_PARENS
);
2956 case EMPTY_CLASS_EXPR
:
2957 dump_type (pp
, TREE_TYPE (t
), flags
);
2958 pp_cxx_left_paren (pp
);
2959 pp_cxx_right_paren (pp
);
2962 case ARGUMENT_PACK_SELECT
:
2963 dump_template_argument (pp
, ARGUMENT_PACK_SELECT_FROM_PACK (t
), flags
);
2977 pp_type_specifier_seq (pp
, t
);
2981 /* We get here when we want to print a dependent type as an
2982 id-expression, without any disambiguator decoration. */
2983 pp
->id_expression (t
);
2986 case TEMPLATE_TYPE_PARM
:
2987 case TEMPLATE_TEMPLATE_PARM
:
2988 case BOUND_TEMPLATE_TEMPLATE_PARM
:
2989 dump_type (pp
, t
, flags
);
2993 pp_cxx_trait (pp
, t
);
2997 pp_cxx_va_arg_expression (pp
, t
);
3001 pp_cxx_offsetof_expression (pp
, t
);
3004 case ADDRESSOF_EXPR
:
3005 pp_cxx_addressof_expression (pp
, t
);
3009 dump_decl (pp
, t
, flags
);
3012 case EXPR_PACK_EXPANSION
:
3013 case UNARY_LEFT_FOLD_EXPR
:
3014 case UNARY_RIGHT_FOLD_EXPR
:
3015 case BINARY_LEFT_FOLD_EXPR
:
3016 case BINARY_RIGHT_FOLD_EXPR
:
3023 case VEC_DELETE_EXPR
:
3030 case UNORDERED_EXPR
:
3040 case FIX_TRUNC_EXPR
:
3045 case TRUTH_AND_EXPR
:
3047 case TRUTH_XOR_EXPR
:
3048 if (flags
& TFF_EXPR_IN_PARENS
)
3049 pp_cxx_left_paren (pp
);
3051 if (flags
& TFF_EXPR_IN_PARENS
)
3052 pp_cxx_right_paren (pp
);
3056 dump_expr (pp
, resolve_virtual_fun_from_obj_type_ref (t
), flags
);
3060 pp_string (pp
, M_("<lambda>"));
3064 pp_cxx_left_paren (pp
);
3065 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
3066 pp_cxx_right_paren (pp
);
3070 pp_cxx_requires_expr (cxx_pp
, t
);
3074 pp_cxx_simple_requirement (cxx_pp
, t
);
3078 pp_cxx_type_requirement (cxx_pp
, t
);
3082 pp_cxx_compound_requirement (cxx_pp
, t
);
3086 pp_cxx_nested_requirement (cxx_pp
, t
);
3094 pp_cxx_constraint (cxx_pp
, t
);
3098 case PLACEHOLDER_EXPR
:
3099 pp_string (pp
, M_("*this"));
3103 dump_expr_list (pp
, t
, flags
);
3106 /* This list is incomplete, but should suffice for now.
3107 It is very important that `sorry' does not call
3108 `report_error_function'. That could cause an infinite loop. */
3110 pp_unsupported_tree (pp
, t
);
3113 pp_string (pp
, M_("<expression error>"));
3119 dump_binary_op (cxx_pretty_printer
*pp
, const char *opstring
, tree t
,
3122 pp_cxx_left_paren (pp
);
3123 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
3124 pp_cxx_whitespace (pp
);
3126 pp_cxx_ws_string (pp
, opstring
);
3128 pp_string (pp
, M_("<unknown operator>"));
3129 pp_cxx_whitespace (pp
);
3130 tree op1
= TREE_OPERAND (t
, 1);
3131 if (TREE_CODE (t
) == POINTER_PLUS_EXPR
3132 && TREE_CODE (op1
) == INTEGER_CST
3133 && tree_int_cst_sign_bit (op1
))
3134 /* A pointer minus an integer is represented internally as plus a very
3135 large number, don't expose that to users. */
3136 op1
= convert (ssizetype
, op1
);
3137 dump_expr (pp
, op1
, flags
| TFF_EXPR_IN_PARENS
);
3138 pp_cxx_right_paren (pp
);
3142 dump_unary_op (cxx_pretty_printer
*pp
, const char *opstring
, tree t
, int flags
)
3144 if (flags
& TFF_EXPR_IN_PARENS
)
3145 pp_cxx_left_paren (pp
);
3146 pp_cxx_ws_string (pp
, opstring
);
3147 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
3148 if (flags
& TFF_EXPR_IN_PARENS
)
3149 pp_cxx_right_paren (pp
);
3153 reinit_cxx_pp (void)
3155 pp_clear_output_area (cxx_pp
);
3156 cxx_pp
->padding
= pp_none
;
3157 pp_indentation (cxx_pp
) = 0;
3158 pp_needs_newline (cxx_pp
) = false;
3159 pp_show_color (cxx_pp
) = false;
3160 cxx_pp
->enclosing_scope
= current_function_decl
;
3163 /* Same as pp_formatted_text, except the return string is a separate
3164 copy and has a GGC storage duration, e.g. an indefinite lifetime. */
3167 pp_ggc_formatted_text (pretty_printer
*pp
)
3169 return ggc_strdup (pp_formatted_text (pp
));
3172 /* Exported interface to stringifying types, exprs and decls under TFF_*
3176 type_as_string (tree typ
, int flags
)
3179 pp_translate_identifiers (cxx_pp
) = false;
3180 dump_type (cxx_pp
, typ
, flags
);
3181 return pp_ggc_formatted_text (cxx_pp
);
3185 type_as_string_translate (tree typ
, int flags
)
3188 dump_type (cxx_pp
, typ
, flags
);
3189 return pp_ggc_formatted_text (cxx_pp
);
3193 expr_as_string (tree decl
, int flags
)
3196 pp_translate_identifiers (cxx_pp
) = false;
3197 dump_expr (cxx_pp
, decl
, flags
);
3198 return pp_ggc_formatted_text (cxx_pp
);
3201 /* Wrap decl_as_string with options appropriate for dwarf. */
3204 decl_as_dwarf_string (tree decl
, int flags
)
3207 /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag
3208 here will be adequate to get the desired behavior. */
3209 cxx_pp
->flags
|= pp_c_flag_gnu_v3
;
3210 name
= decl_as_string (decl
, flags
);
3211 /* Subsequent calls to the pretty printer shouldn't use this style. */
3212 cxx_pp
->flags
&= ~pp_c_flag_gnu_v3
;
3217 decl_as_string (tree decl
, int flags
)
3220 pp_translate_identifiers (cxx_pp
) = false;
3221 dump_decl (cxx_pp
, decl
, flags
);
3222 return pp_ggc_formatted_text (cxx_pp
);
3226 decl_as_string_translate (tree decl
, int flags
)
3229 dump_decl (cxx_pp
, decl
, flags
);
3230 return pp_ggc_formatted_text (cxx_pp
);
3233 /* Wrap lang_decl_name with options appropriate for dwarf. */
3236 lang_decl_dwarf_name (tree decl
, int v
, bool translate
)
3239 /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag
3240 here will be adequate to get the desired behavior. */
3241 cxx_pp
->flags
|= pp_c_flag_gnu_v3
;
3242 name
= lang_decl_name (decl
, v
, translate
);
3243 /* Subsequent calls to the pretty printer shouldn't use this style. */
3244 cxx_pp
->flags
&= ~pp_c_flag_gnu_v3
;
3248 /* Generate the three forms of printable names for cxx_printable_name. */
3251 lang_decl_name (tree decl
, int v
, bool translate
)
3255 ? decl_as_string_translate (decl
, TFF_DECL_SPECIFIERS
)
3256 : decl_as_string (decl
, TFF_DECL_SPECIFIERS
));
3259 pp_translate_identifiers (cxx_pp
) = translate
;
3261 && (DECL_CLASS_SCOPE_P (decl
)
3262 || (DECL_NAMESPACE_SCOPE_P (decl
)
3263 && CP_DECL_CONTEXT (decl
) != global_namespace
)))
3265 dump_type (cxx_pp
, CP_DECL_CONTEXT (decl
), TFF_PLAIN_IDENTIFIER
);
3266 pp_cxx_colon_colon (cxx_pp
);
3269 if (TREE_CODE (decl
) == FUNCTION_DECL
)
3270 dump_function_name (cxx_pp
, decl
, TFF_PLAIN_IDENTIFIER
);
3271 else if ((DECL_NAME (decl
) == NULL_TREE
)
3272 && TREE_CODE (decl
) == NAMESPACE_DECL
)
3273 dump_decl (cxx_pp
, decl
, TFF_PLAIN_IDENTIFIER
| TFF_UNQUALIFIED_NAME
);
3275 dump_decl (cxx_pp
, DECL_NAME (decl
), TFF_PLAIN_IDENTIFIER
);
3277 return pp_ggc_formatted_text (cxx_pp
);
3280 /* Return the location of a tree passed to %+ formats. */
3283 location_of (tree t
)
3287 t
= TYPE_MAIN_DECL (t
);
3289 return input_location
;
3291 else if (TREE_CODE (t
) == OVERLOAD
)
3295 return DECL_SOURCE_LOCATION (t
);
3296 if (TREE_CODE (t
) == DEFERRED_PARSE
)
3297 return defparse_location (t
);
3298 return cp_expr_loc_or_input_loc (t
);
3301 /* Now the interfaces from error et al to dump_type et al. Each takes an
3302 on/off VERBOSE flag and supply the appropriate TFF_ flags to a dump_
3306 decl_to_string (tree decl
, int verbose
, bool show_color
)
3310 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == RECORD_TYPE
3311 || TREE_CODE (decl
) == UNION_TYPE
|| TREE_CODE (decl
) == ENUMERAL_TYPE
)
3312 flags
= TFF_CLASS_KEY_OR_ENUM
;
3314 flags
|= TFF_DECL_SPECIFIERS
;
3315 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
3316 flags
|= TFF_DECL_SPECIFIERS
| TFF_RETURN_TYPE
;
3317 flags
|= TFF_TEMPLATE_HEADER
;
3320 pp_show_color (cxx_pp
) = show_color
;
3321 dump_decl (cxx_pp
, decl
, flags
);
3322 return pp_ggc_formatted_text (cxx_pp
);
3326 expr_to_string (tree decl
)
3329 dump_expr (cxx_pp
, decl
, 0);
3330 return pp_ggc_formatted_text (cxx_pp
);
3334 fndecl_to_string (tree fndecl
, int verbose
)
3338 flags
= TFF_EXCEPTION_SPECIFICATION
| TFF_DECL_SPECIFIERS
3339 | TFF_TEMPLATE_HEADER
;
3341 flags
|= TFF_FUNCTION_DEFAULT_ARGUMENTS
;
3343 dump_decl (cxx_pp
, fndecl
, flags
);
3344 return pp_ggc_formatted_text (cxx_pp
);
3349 code_to_string (enum tree_code c
)
3351 return get_tree_code_name (c
);
3355 language_to_string (enum languages c
)
3362 case lang_cplusplus
:
3371 /* Return the proper printed version of a parameter to a C++ function. */
3374 parm_to_string (int p
)
3378 pp_string (cxx_pp
, "'this'");
3380 pp_decimal_int (cxx_pp
, p
+ 1);
3381 return pp_ggc_formatted_text (cxx_pp
);
3385 op_to_string (bool assop
, enum tree_code p
)
3387 tree id
= ovl_op_identifier (assop
, p
);
3388 return id
? IDENTIFIER_POINTER (id
) : M_("<unknown>");
3391 /* Return a GC-allocated representation of type TYP, with verbosity VERBOSE.
3393 If QUOTE is non-NULL and if *QUOTE is true, then quotes are added to the
3394 string in appropriate places, and *QUOTE is written to with false
3395 to suppress pp_format's trailing close quote so that e.g.
3396 foo_typedef {aka underlying_foo} {enum}
3397 can be printed by "%qT" as:
3398 `foo_typedef' {aka `underlying_foo'} {enum}
3400 `foo_typedef {aka underlying_foo} {enum}'
3401 When adding such quotes, if POSTPROCESSED is true (for handling %H and %I)
3402 then a leading open quote will be added, whereas if POSTPROCESSED is false
3403 (for handling %T) then any leading quote has already been added by
3404 pp_format, or is not needed due to QUOTE being NULL (for template arguments
3407 SHOW_COLOR is used to determine the colorization of any quotes that
3411 type_to_string (tree typ
, int verbose
, bool postprocessed
, bool *quote
,
3416 flags
|= TFF_CLASS_KEY_OR_ENUM
;
3417 flags
|= TFF_TEMPLATE_HEADER
;
3420 pp_show_color (cxx_pp
) = show_color
;
3422 if (postprocessed
&& quote
&& *quote
)
3423 pp_begin_quote (cxx_pp
, show_color
);
3425 struct obstack
*ob
= pp_buffer (cxx_pp
)->obstack
;
3426 int type_start
, type_len
;
3427 type_start
= obstack_object_size (ob
);
3429 dump_type (cxx_pp
, typ
, flags
);
3431 /* Remember the end of the initial dump. */
3432 type_len
= obstack_object_size (ob
) - type_start
;
3434 /* If we're printing a type that involves typedefs, also print the
3435 stripped version. But sometimes the stripped version looks
3436 exactly the same, so we don't want it after all. To avoid printing
3437 it in that case, we play ugly obstack games. */
3438 if (typ
&& TYPE_P (typ
) && typ
!= TYPE_CANONICAL (typ
)
3439 && !uses_template_parms (typ
))
3441 int aka_start
, aka_len
; char *p
;
3442 tree aka
= strip_typedefs (typ
, NULL
, STF_USER_VISIBLE
);
3443 if (quote
&& *quote
)
3444 pp_end_quote (cxx_pp
, show_color
);
3445 pp_string (cxx_pp
, " {aka");
3446 pp_cxx_whitespace (cxx_pp
);
3447 if (quote
&& *quote
)
3448 pp_begin_quote (cxx_pp
, show_color
);
3449 /* And remember the start of the aka dump. */
3450 aka_start
= obstack_object_size (ob
);
3451 dump_type (cxx_pp
, aka
, flags
);
3452 aka_len
= obstack_object_size (ob
) - aka_start
;
3453 if (quote
&& *quote
)
3454 pp_end_quote (cxx_pp
, show_color
);
3455 pp_right_brace (cxx_pp
);
3456 p
= (char*)obstack_base (ob
);
3457 /* If they are identical, cut off the aka by unwinding the obstack. */
3458 if (type_len
== aka_len
3459 && memcmp (p
+ type_start
, p
+aka_start
, type_len
) == 0)
3461 /* We can't add a '\0' here, since we may be adding a closing quote
3462 below, and it would be hidden by the '\0'.
3463 Instead, manually unwind the current object within the obstack
3464 so that the insertion point is at the end of the type, before
3466 int delta
= type_start
+ type_len
- obstack_object_size (ob
);
3467 gcc_assert (delta
<= 0);
3468 obstack_blank_fast (ob
, delta
);
3472 /* No further closing quotes are needed. */
3476 if (quote
&& *quote
)
3478 pp_end_quote (cxx_pp
, show_color
);
3481 return pp_ggc_formatted_text (cxx_pp
);
3485 args_to_string (tree p
, int verbose
)
3489 flags
|= TFF_CLASS_KEY_OR_ENUM
;
3494 if (TYPE_P (TREE_VALUE (p
)))
3495 return type_as_string_translate (p
, flags
);
3498 for (; p
; p
= TREE_CHAIN (p
))
3500 if (null_node_p (TREE_VALUE (p
)))
3501 pp_cxx_ws_string (cxx_pp
, "NULL");
3503 dump_type (cxx_pp
, error_type (TREE_VALUE (p
)), flags
);
3505 pp_separate_with_comma (cxx_pp
);
3507 return pp_ggc_formatted_text (cxx_pp
);
3510 /* Pretty-print a deduction substitution (from deduction_tsubst_fntype). P
3511 is a TREE_LIST with purpose the TEMPLATE_DECL, value the template
3515 subst_to_string (tree p
, bool show_color
)
3517 tree decl
= TREE_PURPOSE (p
);
3518 tree targs
= TREE_VALUE (p
);
3519 tree tparms
= DECL_TEMPLATE_PARMS (decl
);
3520 int flags
= (TFF_DECL_SPECIFIERS
|TFF_TEMPLATE_HEADER
3521 |TFF_NO_TEMPLATE_BINDINGS
);
3527 pp_show_color (cxx_pp
) = show_color
;
3528 dump_template_decl (cxx_pp
, TREE_PURPOSE (p
), flags
);
3529 dump_substitution (cxx_pp
, NULL
, tparms
, targs
, /*flags=*/0);
3530 return pp_ggc_formatted_text (cxx_pp
);
3534 cv_to_string (tree p
, int v
)
3537 cxx_pp
->padding
= v
? pp_before
: pp_none
;
3538 pp_cxx_cv_qualifier_seq (cxx_pp
, p
);
3539 return pp_ggc_formatted_text (cxx_pp
);
3543 eh_spec_to_string (tree p
, int /*v*/)
3547 dump_exception_spec (cxx_pp
, p
, flags
);
3548 return pp_ggc_formatted_text (cxx_pp
);
3551 /* Langhook for print_error_function. */
3553 cxx_print_error_function (diagnostic_context
*context
, const char *file
,
3554 const diagnostic_info
*diagnostic
)
3558 prefix
= xstrdup (file
);
3561 lhd_print_error_function (context
, file
, diagnostic
);
3562 pp_set_prefix (context
->printer
, prefix
);
3563 maybe_print_instantiation_context (context
);
3567 cp_diagnostic_starter (diagnostic_context
*context
,
3568 const diagnostic_info
*diagnostic
)
3570 diagnostic_report_current_module (context
, diagnostic_location (diagnostic
));
3571 cp_print_error_function (context
, diagnostic
);
3572 maybe_print_instantiation_context (context
);
3573 maybe_print_constexpr_context (context
);
3574 maybe_print_constraint_context (context
);
3575 pp_set_prefix (context
->printer
, diagnostic_build_prefix (context
,
3579 /* Print current function onto BUFFER, in the process of reporting
3580 a diagnostic message. Called from cp_diagnostic_starter. */
3582 cp_print_error_function (diagnostic_context
*context
,
3583 const diagnostic_info
*diagnostic
)
3585 /* If we are in an instantiation context, current_function_decl is likely
3586 to be wrong, so just rely on print_instantiation_full_context. */
3587 if (current_instantiation ())
3589 /* The above is true for constraint satisfaction also. */
3590 if (current_failed_constraint
)
3592 if (diagnostic_last_function_changed (context
, diagnostic
))
3594 char *old_prefix
= pp_take_prefix (context
->printer
);
3595 const char *file
= LOCATION_FILE (diagnostic_location (diagnostic
));
3596 tree abstract_origin
= diagnostic_abstract_origin (diagnostic
);
3597 char *new_prefix
= (file
&& abstract_origin
== NULL
)
3598 ? file_name_as_prefix (context
, file
) : NULL
;
3600 pp_set_prefix (context
->printer
, new_prefix
);
3602 if (current_function_decl
== NULL
)
3603 pp_string (context
->printer
, _("At global scope:"));
3608 if (abstract_origin
)
3610 ao
= BLOCK_ABSTRACT_ORIGIN (abstract_origin
);
3611 gcc_assert (TREE_CODE (ao
) == FUNCTION_DECL
);
3615 fndecl
= current_function_decl
;
3617 pp_printf (context
->printer
, function_category (fndecl
),
3620 while (abstract_origin
)
3623 tree block
= abstract_origin
;
3625 locus
= &BLOCK_SOURCE_LOCATION (block
);
3627 block
= BLOCK_SUPERCONTEXT (block
);
3628 while (block
&& TREE_CODE (block
) == BLOCK
3629 && BLOCK_ABSTRACT_ORIGIN (block
))
3631 ao
= BLOCK_ABSTRACT_ORIGIN (block
);
3632 if (TREE_CODE (ao
) == FUNCTION_DECL
)
3637 else if (TREE_CODE (ao
) != BLOCK
)
3640 block
= BLOCK_SUPERCONTEXT (block
);
3643 abstract_origin
= block
;
3646 while (block
&& TREE_CODE (block
) == BLOCK
)
3647 block
= BLOCK_SUPERCONTEXT (block
);
3649 if (block
&& TREE_CODE (block
) == FUNCTION_DECL
)
3651 abstract_origin
= NULL
;
3655 expanded_location s
= expand_location (*locus
);
3656 pp_character (context
->printer
, ',');
3657 pp_newline (context
->printer
);
3660 if (context
->m_show_column
&& s
.column
!= 0)
3661 pp_printf (context
->printer
,
3662 _(" inlined from %qD at %r%s:%d:%d%R"),
3664 "locus", s
.file
, s
.line
, s
.column
);
3666 pp_printf (context
->printer
,
3667 _(" inlined from %qD at %r%s:%d%R"),
3669 "locus", s
.file
, s
.line
);
3673 pp_printf (context
->printer
, _(" inlined from %qD"),
3677 pp_character (context
->printer
, ':');
3679 pp_newline (context
->printer
);
3681 diagnostic_set_last_function (context
, diagnostic
);
3682 pp_destroy_prefix (context
->printer
);
3683 context
->printer
->prefix
= old_prefix
;
3687 /* Returns a description of FUNCTION using standard terminology. The
3688 result is a format string of the form "In CATEGORY %qD". */
3691 function_category (tree fn
)
3693 /* We can get called from the middle-end for diagnostics of function
3694 clones. Make sure we have language specific information before
3695 dereferencing it. */
3696 if (DECL_LANG_SPECIFIC (STRIP_TEMPLATE (fn
))
3697 && DECL_FUNCTION_MEMBER_P (fn
))
3699 if (DECL_STATIC_FUNCTION_P (fn
))
3700 return _("In static member function %qD");
3701 else if (DECL_COPY_CONSTRUCTOR_P (fn
))
3702 return _("In copy constructor %qD");
3703 else if (DECL_CONSTRUCTOR_P (fn
))
3704 return _("In constructor %qD");
3705 else if (DECL_DESTRUCTOR_P (fn
))
3706 return _("In destructor %qD");
3707 else if (LAMBDA_FUNCTION_P (fn
))
3708 return _("In lambda function");
3709 else if (DECL_XOBJ_MEMBER_FUNCTION_P (fn
))
3710 return _("In explicit object member function %qD");
3712 return _("In member function %qD");
3715 return _("In function %qD");
3718 /* Disable warnings about missing quoting in GCC diagnostics for
3719 the pp_verbatim calls. Their format strings deliberately don't
3720 follow GCC diagnostic conventions. */
3722 #pragma GCC diagnostic push
3723 #pragma GCC diagnostic ignored "-Wformat-diag"
3726 /* Report the full context of a current template instantiation,
3729 print_instantiation_full_context (diagnostic_context
*context
)
3731 struct tinst_level
*p
= current_instantiation ();
3732 location_t location
= input_location
;
3736 pp_verbatim (context
->printer
,
3738 ? _("%s: In substitution of %qS:\n")
3739 : _("%s: In instantiation of %q#D:\n"),
3740 LOCATION_FILE (location
),
3743 location
= p
->locus
;
3747 print_instantiation_partial_context (context
, p
, location
);
3750 /* Helper function of print_instantiation_partial_context() that
3751 prints a single line of instantiation context. */
3754 print_instantiation_partial_context_line (diagnostic_context
*context
,
3755 struct tinst_level
*t
,
3756 location_t loc
, bool recursive_p
)
3758 if (loc
== UNKNOWN_LOCATION
)
3761 expanded_location xloc
= expand_location (loc
);
3763 if (context
->m_show_column
)
3764 pp_verbatim (context
->printer
, _("%r%s:%d:%d:%R "),
3765 "locus", xloc
.file
, xloc
.line
, xloc
.column
);
3767 pp_verbatim (context
->printer
, _("%r%s:%d:%R "),
3768 "locus", xloc
.file
, xloc
.line
);
3773 pp_verbatim (context
->printer
,
3775 ? _("recursively required by substitution of %qS\n")
3776 : _("required by substitution of %qS\n"),
3779 pp_verbatim (context
->printer
,
3781 ? _("recursively required from %q#D\n")
3782 : _("required from %q#D\n"),
3787 pp_verbatim (context
->printer
,
3789 ? _("recursively required from here\n")
3790 : _("required from here\n"));
3792 gcc_rich_location
rich_loc (loc
);
3793 diagnostic_show_locus (context
, &rich_loc
, DK_NOTE
);
3796 /* Same as print_instantiation_full_context but less verbose. */
3799 print_instantiation_partial_context (diagnostic_context
*context
,
3800 struct tinst_level
*t0
, location_t loc
)
3802 struct tinst_level
*t
;
3805 location_t prev_loc
= loc
;
3807 for (t
= t0
; t
!= NULL
; t
= t
->next
)
3808 if (prev_loc
!= t
->locus
)
3810 prev_loc
= t
->locus
;
3816 if (template_backtrace_limit
3817 && n_total
> template_backtrace_limit
)
3819 int skip
= n_total
- template_backtrace_limit
;
3820 int head
= template_backtrace_limit
/ 2;
3822 /* Avoid skipping just 1. If so, skip 2. */
3826 head
= (template_backtrace_limit
- 1) / 2;
3829 for (n
= 0; n
< head
; n
++)
3831 gcc_assert (t
!= NULL
);
3832 if (loc
!= t
->locus
)
3833 print_instantiation_partial_context_line (context
, t
, loc
,
3834 /*recursive_p=*/false);
3838 if (t
!= NULL
&& skip
> 0)
3840 expanded_location xloc
;
3841 xloc
= expand_location (loc
);
3842 if (context
->m_show_column
)
3843 pp_verbatim (context
->printer
,
3844 _("%r%s:%d:%d:%R [ skipping %d instantiation "
3845 "contexts, use -ftemplate-backtrace-limit=0 to "
3847 "locus", xloc
.file
, xloc
.line
, xloc
.column
, skip
);
3849 pp_verbatim (context
->printer
,
3850 _("%r%s:%d:%R [ skipping %d instantiation "
3851 "contexts, use -ftemplate-backtrace-limit=0 to "
3853 "locus", xloc
.file
, xloc
.line
, skip
);
3858 } while (t
!= NULL
&& --skip
> 0);
3864 while (t
->next
!= NULL
&& t
->locus
== t
->next
->locus
)
3869 print_instantiation_partial_context_line (context
, t
, loc
,
3874 print_instantiation_partial_context_line (context
, NULL
, loc
,
3875 /*recursive_p=*/false);
3878 /* Called from cp_thing to print the template context for an error. */
3880 maybe_print_instantiation_context (diagnostic_context
*context
)
3882 if (!problematic_instantiation_changed () || current_instantiation () == 0)
3885 record_last_problematic_instantiation ();
3886 print_instantiation_full_context (context
);
3889 /* Report what constexpr call(s) we're trying to expand, if any. */
3892 maybe_print_constexpr_context (diagnostic_context
*context
)
3894 vec
<tree
> call_stack
= cx_error_context ();
3898 FOR_EACH_VEC_ELT (call_stack
, ix
, t
)
3900 expanded_location xloc
= expand_location (EXPR_LOCATION (t
));
3901 const char *s
= expr_as_string (t
, 0);
3902 if (context
->m_show_column
)
3903 pp_verbatim (context
->printer
,
3904 _("%r%s:%d:%d:%R in %<constexpr%> expansion of %qs"),
3905 "locus", xloc
.file
, xloc
.line
, xloc
.column
, s
);
3907 pp_verbatim (context
->printer
,
3908 _("%r%s:%d:%R in %<constexpr%> expansion of %qs"),
3909 "locus", xloc
.file
, xloc
.line
, s
);
3910 pp_newline (context
->printer
);
3916 print_location (diagnostic_context
*context
, location_t loc
)
3918 expanded_location xloc
= expand_location (loc
);
3919 if (context
->m_show_column
)
3920 pp_verbatim (context
->printer
, _("%r%s:%d:%d:%R "),
3921 "locus", xloc
.file
, xloc
.line
, xloc
.column
);
3923 pp_verbatim (context
->printer
, _("%r%s:%d:%R "),
3924 "locus", xloc
.file
, xloc
.line
);
3928 print_constrained_decl_info (diagnostic_context
*context
, tree decl
)
3930 print_location (context
, DECL_SOURCE_LOCATION (decl
));
3931 pp_verbatim (context
->printer
, "required by the constraints of %q#D\n", decl
);
3935 print_concept_check_info (diagnostic_context
*context
, tree expr
, tree map
, tree args
)
3937 gcc_assert (concept_check_p (expr
));
3939 tree id
= unpack_concept_check (expr
);
3940 tree tmpl
= TREE_OPERAND (id
, 0);
3942 tmpl
= OVL_FIRST (tmpl
);
3944 print_location (context
, DECL_SOURCE_LOCATION (tmpl
));
3946 cxx_pretty_printer
*pp
= (cxx_pretty_printer
*)context
->printer
;
3947 pp_verbatim (pp
, "required for the satisfaction of %qE", expr
);
3948 if (map
&& map
!= error_mark_node
)
3950 tree subst_map
= tsubst_parameter_mapping (map
, args
, tf_none
, NULL_TREE
);
3951 pp_cxx_parameter_mapping (pp
, (subst_map
!= error_mark_node
3952 ? subst_map
: map
));
3957 /* Diagnose the entry point into the satisfaction error. Returns the next
3961 print_constraint_context_head (diagnostic_context
*context
, tree cxt
, tree args
)
3963 tree src
= TREE_VALUE (cxt
);
3966 print_location (context
, input_location
);
3967 pp_verbatim (context
->printer
, "required for constraint satisfaction\n");
3972 print_constrained_decl_info (context
, src
);
3977 print_concept_check_info (context
, src
, TREE_PURPOSE (cxt
), args
);
3978 return TREE_CHAIN (cxt
);
3983 print_requires_expression_info (diagnostic_context
*context
, tree constr
, tree args
)
3986 tree expr
= ATOMIC_CONSTR_EXPR (constr
);
3987 tree map
= ATOMIC_CONSTR_MAP (constr
);
3988 map
= tsubst_parameter_mapping (map
, args
, tf_none
, NULL_TREE
);
3989 if (map
== error_mark_node
)
3992 print_location (context
, cp_expr_loc_or_input_loc (expr
));
3993 pp_verbatim (context
->printer
, "in requirements ");
3995 tree parms
= TREE_OPERAND (expr
, 0);
3997 pp_verbatim (context
->printer
, "with ");
4000 pp_verbatim (context
->printer
, "%q#D", parms
);
4001 if (TREE_CHAIN (parms
))
4002 pp_separate_with_comma ((cxx_pretty_printer
*)context
->printer
);
4003 parms
= TREE_CHAIN (parms
);
4005 pp_cxx_parameter_mapping ((cxx_pretty_printer
*)context
->printer
, map
);
4007 pp_verbatim (context
->printer
, "\n");
4011 maybe_print_single_constraint_context (diagnostic_context
*context
, tree failed
)
4016 tree constr
= TREE_VALUE (failed
);
4017 if (!constr
|| constr
== error_mark_node
)
4019 tree cxt
= CONSTR_CONTEXT (constr
);
4022 tree args
= TREE_PURPOSE (failed
);
4024 /* Print the stack of requirements. */
4025 cxt
= print_constraint_context_head (context
, cxt
, args
);
4026 while (cxt
&& !DECL_P (TREE_VALUE (cxt
)))
4028 tree expr
= TREE_VALUE (cxt
);
4029 tree map
= TREE_PURPOSE (cxt
);
4030 print_concept_check_info (context
, expr
, map
, args
);
4031 cxt
= TREE_CHAIN (cxt
);
4034 /* For certain constraints, we can provide additional context. */
4035 if (TREE_CODE (constr
) == ATOMIC_CONSTR
4036 && TREE_CODE (ATOMIC_CONSTR_EXPR (constr
)) == REQUIRES_EXPR
)
4037 print_requires_expression_info (context
, constr
, args
);
4041 maybe_print_constraint_context (diagnostic_context
*context
)
4043 if (!current_failed_constraint
)
4046 tree cur
= current_failed_constraint
;
4048 /* Recursively print nested contexts. */
4049 current_failed_constraint
= TREE_CHAIN (current_failed_constraint
);
4050 if (current_failed_constraint
)
4051 maybe_print_constraint_context (context
);
4053 /* Print this context. */
4054 maybe_print_single_constraint_context (context
, cur
);
4057 /* Return true iff TYPE_A and TYPE_B are template types that are
4058 meaningful to compare. */
4061 comparable_template_types_p (tree type_a
, tree type_b
)
4063 if (!CLASS_TYPE_P (type_a
))
4065 if (!CLASS_TYPE_P (type_b
))
4068 tree tinfo_a
= TYPE_TEMPLATE_INFO (type_a
);
4069 tree tinfo_b
= TYPE_TEMPLATE_INFO (type_b
);
4070 if (!tinfo_a
|| !tinfo_b
)
4073 return TI_TEMPLATE (tinfo_a
) == TI_TEMPLATE (tinfo_b
);
4076 /* Start a new line indented by SPC spaces on PP. */
4079 newline_and_indent (pretty_printer
*pp
, int spc
)
4082 for (int i
= 0; i
< spc
; i
++)
4086 /* Generate a GC-allocated string for ARG, an expression or type. */
4089 arg_to_string (tree arg
, bool verbose
)
4092 return type_to_string (arg
, verbose
, true, NULL
, false);
4094 return expr_to_string (arg
);
4097 /* Subroutine to type_to_string_with_compare and
4098 print_template_tree_comparison.
4100 Print a representation of ARG (an expression or type) to PP,
4101 colorizing it as "type-diff" if PP->show_color. */
4104 print_nonequal_arg (pretty_printer
*pp
, tree arg
, bool verbose
)
4106 pp_printf (pp
, "%r%s%R",
4109 ? arg_to_string (arg
, verbose
)
4110 : G_("(no argument)")));
4113 /* Recursively print template TYPE_A to PP, as compared to template TYPE_B.
4115 The types must satisfy comparable_template_types_p.
4117 If INDENT is 0, then this is equivalent to type_to_string (TYPE_A), but
4118 potentially colorizing/eliding in comparison with TYPE_B.
4120 For example given types:
4121 vector<map<int,double>>
4123 vector<map<int,float>>
4124 then the result on PP would be:
4125 vector<map<[...],double>>
4126 with type elision, and:
4127 vector<map<int,double>>
4128 without type elision.
4130 In both cases the parts of TYPE that differ from PEER will be colorized
4131 if pp_show_color (pp) is true. In the above example, this would be
4134 If INDENT is non-zero, then the types are printed in a tree-like form
4135 which shows both types. In the above example, the result on PP would be:
4142 and without type-elision would be:
4149 As before, the differing parts of the types are colorized if
4150 pp_show_color (pp) is true ("double" and "float" in this example).
4152 Template arguments in which both types are using the default arguments
4153 are not printed; if at least one of the two types is using a non-default
4154 argument, then that argument is printed (or both arguments for the
4155 tree-like print format). */
4158 print_template_differences (pretty_printer
*pp
, tree type_a
, tree type_b
,
4159 bool verbose
, int indent
)
4162 newline_and_indent (pp
, indent
);
4164 tree tinfo_a
= TYPE_TEMPLATE_INFO (type_a
);
4165 tree tinfo_b
= TYPE_TEMPLATE_INFO (type_b
);
4167 pp_printf (pp
, "%s<",
4168 IDENTIFIER_POINTER (DECL_NAME (TI_TEMPLATE (tinfo_a
))));
4170 tree args_a
= TI_ARGS (tinfo_a
);
4171 tree args_b
= TI_ARGS (tinfo_b
);
4172 gcc_assert (TREE_CODE (args_a
) == TREE_VEC
);
4173 gcc_assert (TREE_CODE (args_b
) == TREE_VEC
);
4175 int len_a
= get_non_default_template_args_count (args_a
, flags
);
4176 args_a
= INNERMOST_TEMPLATE_ARGS (args_a
);
4177 int len_b
= get_non_default_template_args_count (args_b
, flags
);
4178 args_b
= INNERMOST_TEMPLATE_ARGS (args_b
);
4179 /* Determine the maximum range of args for which non-default template args
4180 were used; beyond this, only default args (if any) were used, and so
4181 they will be equal from this point onwards.
4182 One of the two peers might have used default arguments within this
4183 range, but the other will be using non-default arguments, and so
4184 it's more readable to print both within this range, to highlight
4186 int len_max
= MAX (len_a
, len_b
);
4187 gcc_assert (TREE_CODE (args_a
) == TREE_VEC
);
4188 gcc_assert (TREE_CODE (args_b
) == TREE_VEC
);
4189 for (int idx
= 0; idx
< len_max
; idx
++)
4192 pp_character (pp
, ',');
4194 tree arg_a
= TREE_VEC_ELT (args_a
, idx
);
4195 tree arg_b
= TREE_VEC_ELT (args_b
, idx
);
4199 newline_and_indent (pp
, indent
+ 2);
4200 /* Can do elision here, printing "[...]". */
4201 if (flag_elide_type
)
4202 pp_string (pp
, G_("[...]"));
4204 pp_string (pp
, arg_to_string (arg_a
, verbose
));
4208 int new_indent
= indent
? indent
+ 2 : 0;
4209 if (comparable_template_types_p (arg_a
, arg_b
))
4210 print_template_differences (pp
, arg_a
, arg_b
, verbose
, new_indent
);
4214 newline_and_indent (pp
, indent
+ 2);
4215 pp_character (pp
, '[');
4216 print_nonequal_arg (pp
, arg_a
, verbose
);
4217 pp_string (pp
, " != ");
4218 print_nonequal_arg (pp
, arg_b
, verbose
);
4219 pp_character (pp
, ']');
4222 print_nonequal_arg (pp
, arg_a
, verbose
);
4225 pp_printf (pp
, ">");
4228 /* As type_to_string, but for a template, potentially colorizing/eliding
4229 in comparison with PEER.
4230 For example, if TYPE is map<int,double> and PEER is map<int,int>,
4231 then the resulting string would be:
4233 with type elision, and:
4235 without type elision.
4237 In both cases the parts of TYPE that differ from PEER will be colorized
4238 if SHOW_COLOR is true. In the above example, this would be "double".
4240 Template arguments in which both types are using the default arguments
4241 are not printed; if at least one of the two types is using a non-default
4242 argument, then both arguments are printed.
4244 The resulting string is in a GC-allocated buffer. */
4247 type_to_string_with_compare (tree type
, tree peer
, bool verbose
,
4250 pretty_printer inner_pp
;
4251 pretty_printer
*pp
= &inner_pp
;
4252 pp_show_color (pp
) = show_color
;
4254 print_template_differences (pp
, type
, peer
, verbose
, 0);
4255 return pp_ggc_formatted_text (pp
);
4258 /* Recursively print a tree-like comparison of TYPE_A and TYPE_B to PP,
4259 indented by INDENT spaces.
4261 For example given types:
4263 vector<map<int,double>>
4267 vector<map<double,float>>
4269 the output with type elision would be:
4276 and without type-elision would be:
4283 TYPE_A and TYPE_B must both be comparable template types
4284 (as per comparable_template_types_p).
4286 Template arguments in which both types are using the default arguments
4287 are not printed; if at least one of the two types is using a non-default
4288 argument, then both arguments are printed. */
4291 print_template_tree_comparison (pretty_printer
*pp
, tree type_a
, tree type_b
,
4292 bool verbose
, int indent
)
4294 print_template_differences (pp
, type_a
, type_b
, verbose
, indent
);
4297 /* Subroutine for use in a format_postprocessor::handle
4298 implementation. Adds a chunk to the end of
4299 formatted output, so that it will be printed
4300 by pp_output_formatted_text. */
4303 append_formatted_chunk (pretty_printer
*pp
, const char *content
)
4305 output_buffer
*buffer
= pp_buffer (pp
);
4306 struct chunk_info
*chunk_array
= buffer
->cur_chunk_array
;
4307 const char **args
= chunk_array
->args
;
4309 unsigned int chunk_idx
;
4310 for (chunk_idx
= 0; args
[chunk_idx
]; chunk_idx
++)
4312 args
[chunk_idx
++] = content
;
4313 args
[chunk_idx
] = NULL
;
4316 /* Create a copy of CONTENT, with quotes added, and,
4317 potentially, with colorization.
4318 No escaped is performed on CONTENT.
4319 The result is in a GC-allocated buffer. */
4322 add_quotes (const char *content
, bool show_color
)
4324 pretty_printer tmp_pp
;
4325 pp_show_color (&tmp_pp
) = show_color
;
4327 /* We have to use "%<%s%>" rather than "%qs" here in order to avoid
4328 quoting colorization bytes within the results and using either
4329 pp_quote or pp_begin_quote doesn't work the same. */
4330 pp_printf (&tmp_pp
, "%<%s%>", content
);
4332 return pp_ggc_formatted_text (&tmp_pp
);
4336 #pragma GCC diagnostic pop
4339 /* If we had %H and %I, and hence deferred printing them,
4340 print them now, storing the result into the chunk_info
4341 for pp_format. Quote them if 'q' was provided.
4342 Also print the difference in tree form, adding it as
4343 an additional chunk. */
4346 cxx_format_postprocessor::handle (pretty_printer
*pp
)
4348 /* If we have one of %H and %I, the other should have
4350 if (m_type_a
.m_tree
|| m_type_b
.m_tree
)
4352 /* Avoid reentrancy issues by working with a copy of
4353 m_type_a and m_type_b, resetting them now. */
4354 deferred_printed_type type_a
= m_type_a
;
4355 deferred_printed_type type_b
= m_type_b
;
4356 m_type_a
= deferred_printed_type ();
4357 m_type_b
= deferred_printed_type ();
4359 gcc_assert (type_a
.m_buffer_ptr
);
4360 gcc_assert (type_b
.m_buffer_ptr
);
4362 bool show_color
= pp_show_color (pp
);
4364 const char *type_a_text
;
4365 const char *type_b_text
;
4367 if (comparable_template_types_p (type_a
.m_tree
, type_b
.m_tree
))
4370 = type_to_string_with_compare (type_a
.m_tree
, type_b
.m_tree
,
4371 type_a
.m_verbose
, show_color
);
4373 = type_to_string_with_compare (type_b
.m_tree
, type_a
.m_tree
,
4374 type_b
.m_verbose
, show_color
);
4376 if (flag_diagnostics_show_template_tree
)
4378 pretty_printer inner_pp
;
4379 pp_show_color (&inner_pp
) = pp_show_color (pp
);
4380 print_template_tree_comparison
4381 (&inner_pp
, type_a
.m_tree
, type_b
.m_tree
, type_a
.m_verbose
, 2);
4382 append_formatted_chunk (pp
, pp_ggc_formatted_text (&inner_pp
));
4387 /* If the types were not comparable (or if only one of %H/%I was
4388 provided), they are printed normally, and no difference tree
4390 type_a_text
= type_to_string (type_a
.m_tree
, type_a
.m_verbose
,
4391 true, &type_a
.m_quote
, show_color
);
4392 type_b_text
= type_to_string (type_b
.m_tree
, type_b
.m_verbose
,
4393 true, &type_b
.m_quote
, show_color
);
4397 type_a_text
= add_quotes (type_a_text
, show_color
);
4398 *type_a
.m_buffer_ptr
= type_a_text
;
4401 type_b_text
= add_quotes (type_b_text
, show_color
);
4402 *type_b
.m_buffer_ptr
= type_b_text
;
4406 /* Subroutine for handling %H and %I, to support i18n of messages like:
4408 error_at (loc, "could not convert %qE from %qH to %qI",
4409 expr, type_a, type_b);
4411 so that we can print things like:
4413 could not convert 'foo' from 'map<int,double>' to 'map<int,int>'
4415 and, with type-elision:
4417 could not convert 'foo' from 'map<[...],double>' to 'map<[...],int>'
4419 (with color-coding of the differences between the types).
4421 The %H and %I format codes are peers: both must be present,
4422 and they affect each other. Hence to handle them, we must
4423 delay printing until we have both, deferring the printing to
4424 pretty_printer's m_format_postprocessor hook.
4426 This is called in phase 2 of pp_format, when it is accumulating
4427 a series of formatted chunks. We stash the location of the chunk
4428 we're meant to have written to, so that we can write to it in the
4429 m_format_postprocessor hook.
4431 We also need to stash whether a 'q' prefix was provided (the QUOTE
4432 param) so that we can add the quotes when writing out the delayed
4436 defer_phase_2_of_type_diff (deferred_printed_type
*deferred
,
4437 tree type
, const char **buffer_ptr
,
4438 bool verbose
, bool quote
)
4440 gcc_assert (deferred
->m_tree
== NULL_TREE
);
4441 gcc_assert (deferred
->m_buffer_ptr
== NULL
);
4442 *deferred
= deferred_printed_type (type
, buffer_ptr
, verbose
, quote
);
4446 /* Called from output_format -- during diagnostic message processing --
4447 to handle C++ specific format specifier with the following meanings:
4448 %A function argument-list.
4452 %F function declaration.
4453 %H type difference (from).
4454 %I type difference (to).
4455 %L language as used in extern "lang".
4457 %P function parameter whose position is indicated by an integer.
4458 %Q assignment operator.
4459 %S substitution (template + args)
4462 %X exception-specification. */
4464 cp_printer (pretty_printer
*pp
, text_info
*text
, const char *spec
,
4465 int precision
, bool wide
, bool set_locus
, bool verbose
,
4466 bool *quoted
, const char **buffer_ptr
)
4468 gcc_assert (pp
->m_format_postprocessor
);
4469 cxx_format_postprocessor
*postprocessor
4470 = static_cast <cxx_format_postprocessor
*> (pp
->m_format_postprocessor
);
4474 #define next_tree (t = va_arg (*text->m_args_ptr, tree))
4475 #define next_tcode ((enum tree_code) va_arg (*text->m_args_ptr, int))
4476 #define next_lang ((enum languages) va_arg (*text->m_args_ptr, int))
4477 #define next_int va_arg (*text->m_args_ptr, int)
4479 if (precision
!= 0 || wide
)
4484 case 'A': result
= args_to_string (next_tree
, verbose
); break;
4485 case 'C': result
= code_to_string (next_tcode
); break;
4488 tree temp
= next_tree
;
4490 && DECL_HAS_DEBUG_EXPR_P (temp
))
4492 temp
= DECL_DEBUG_EXPR (temp
);
4495 result
= expr_to_string (temp
);
4499 result
= decl_to_string (temp
, verbose
, pp_show_color (pp
));
4502 case 'E': result
= expr_to_string (next_tree
); break;
4503 case 'F': result
= fndecl_to_string (next_tree
, verbose
); break;
4505 defer_phase_2_of_type_diff (&postprocessor
->m_type_a
, next_tree
,
4506 buffer_ptr
, verbose
, *quoted
);
4509 defer_phase_2_of_type_diff (&postprocessor
->m_type_b
, next_tree
,
4510 buffer_ptr
, verbose
, *quoted
);
4512 case 'L': result
= language_to_string (next_lang
); break;
4513 case 'O': result
= op_to_string (false, next_tcode
); break;
4514 case 'P': result
= parm_to_string (next_int
); break;
4515 case 'Q': result
= op_to_string (true, next_tcode
); break;
4516 case 'S': result
= subst_to_string (next_tree
, pp_show_color (pp
)); break;
4519 result
= type_to_string (next_tree
, verbose
, false, quoted
,
4520 pp_show_color (pp
));
4523 case 'V': result
= cv_to_string (next_tree
, verbose
); break;
4524 case 'X': result
= eh_spec_to_string (next_tree
, verbose
); break;
4530 pp_string (pp
, result
);
4531 if (set_locus
&& t
!= NULL
)
4532 text
->set_location (0, location_of (t
), SHOW_RANGE_WITH_CARET
);
4540 /* Warn about the use of C++0x features when appropriate. */
4542 maybe_warn_cpp0x (cpp0x_warn_str str
, location_t loc
/*=input_location*/)
4544 if (cxx_dialect
== cxx98
)
4547 case CPP0X_INITIALIZER_LISTS
:
4548 pedwarn (loc
, OPT_Wc__11_extensions
,
4549 "extended initializer lists "
4550 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4552 case CPP0X_EXPLICIT_CONVERSION
:
4553 pedwarn (loc
, OPT_Wc__11_extensions
,
4554 "explicit conversion operators "
4555 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4557 case CPP0X_VARIADIC_TEMPLATES
:
4558 pedwarn (loc
, OPT_Wc__11_extensions
,
4559 "variadic templates "
4560 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4562 case CPP0X_LAMBDA_EXPR
:
4563 pedwarn (loc
, OPT_Wc__11_extensions
,
4564 "lambda expressions "
4565 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4568 pedwarn (loc
, OPT_Wc__11_extensions
,
4569 "C++11 auto only available with %<-std=c++11%> or "
4570 "%<-std=gnu++11%>");
4572 case CPP0X_SCOPED_ENUMS
:
4573 pedwarn (loc
, OPT_Wc__11_extensions
,
4574 "scoped enums only available with %<-std=c++11%> or "
4575 "%<-std=gnu++11%>");
4577 case CPP0X_DEFAULTED_DELETED
:
4578 pedwarn (loc
, OPT_Wc__11_extensions
,
4579 "defaulted and deleted functions "
4580 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4582 case CPP0X_INLINE_NAMESPACES
:
4584 pedwarn (loc
, OPT_Wc__11_extensions
,
4585 "inline namespaces "
4586 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4588 case CPP0X_OVERRIDE_CONTROLS
:
4589 pedwarn (loc
, OPT_Wc__11_extensions
,
4590 "override controls (override/final) "
4591 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4594 pedwarn (loc
, OPT_Wc__11_extensions
,
4595 "non-static data member initializers "
4596 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4598 case CPP0X_USER_DEFINED_LITERALS
:
4599 pedwarn (loc
, OPT_Wc__11_extensions
,
4600 "user-defined literals "
4601 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4603 case CPP0X_DELEGATING_CTORS
:
4604 pedwarn (loc
, OPT_Wc__11_extensions
,
4605 "delegating constructors "
4606 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4608 case CPP0X_INHERITING_CTORS
:
4609 pedwarn (loc
, OPT_Wc__11_extensions
,
4610 "inheriting constructors "
4611 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4613 case CPP0X_ATTRIBUTES
:
4614 pedwarn (loc
, OPT_Wc__11_extensions
,
4616 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4618 case CPP0X_REF_QUALIFIER
:
4619 pedwarn (loc
, OPT_Wc__11_extensions
,
4621 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4628 /* Warn about the use of variadic templates when appropriate. */
4630 maybe_warn_variadic_templates (void)
4632 maybe_warn_cpp0x (CPP0X_VARIADIC_TEMPLATES
);
4636 /* Issue an ISO C++98 pedantic warning at LOCATION, conditional on
4637 option OPT with text GMSGID. Use this function to report
4638 diagnostics for constructs that are invalid C++98, but valid
4641 pedwarn_cxx98 (location_t location
, int opt
, const char *gmsgid
, ...)
4643 diagnostic_info diagnostic
;
4646 rich_location
richloc (line_table
, location
);
4648 va_start (ap
, gmsgid
);
4649 diagnostic_set_info (&diagnostic
, gmsgid
, &ap
, &richloc
,
4650 (cxx_dialect
== cxx98
) ? DK_PEDWARN
: DK_WARNING
);
4651 diagnostic
.option_index
= opt
;
4652 ret
= diagnostic_report_diagnostic (global_dc
, &diagnostic
);
4657 /* Issue a diagnostic that NAME cannot be found in SCOPE. DECL is what
4658 we found when we tried to do the lookup. LOCATION is the location of
4659 the NAME identifier. */
4662 qualified_name_lookup_error (tree scope
, tree name
,
4663 tree decl
, location_t location
)
4665 if (scope
== error_mark_node
)
4666 ; /* We already complained. */
4667 else if (TYPE_P (scope
))
4669 if (!COMPLETE_TYPE_P (scope
))
4670 error_at (location
, "incomplete type %qT used in nested name specifier",
4672 else if (TREE_CODE (decl
) == TREE_LIST
)
4674 error_at (location
, "reference to %<%T::%D%> is ambiguous",
4676 print_candidates (decl
);
4681 if (SCOPED_ENUM_P (scope
) && TREE_CODE (name
) == IDENTIFIER_NODE
)
4682 hint
= suggest_alternative_in_scoped_enum (name
, scope
);
4683 if (const char *suggestion
= hint
.suggestion ())
4685 gcc_rich_location
richloc (location
);
4686 richloc
.add_fixit_replace (suggestion
);
4688 "%qD is not a member of %qT; did you mean %qs?",
4689 name
, scope
, suggestion
);
4692 error_at (location
, "%qD is not a member of %qT", name
, scope
);
4695 else if (scope
!= global_namespace
)
4697 auto_diagnostic_group d
;
4698 bool emit_fixit
= true;
4700 = suggest_alternative_in_explicit_scope (location
, name
, scope
);
4703 hint
= suggest_alternatives_in_other_namespaces (location
, name
);
4704 /* "location" is just the location of the name, not of the explicit
4705 scope, and it's not easy to get at the latter, so we can't issue
4706 fix-it hints for the suggestion. */
4709 if (const char *suggestion
= hint
.suggestion ())
4711 gcc_rich_location
richloc (location
);
4713 richloc
.add_fixit_replace (suggestion
);
4714 error_at (&richloc
, "%qD is not a member of %qD; did you mean %qs?",
4715 name
, scope
, suggestion
);
4718 error_at (location
, "%qD is not a member of %qD", name
, scope
);
4722 auto_diagnostic_group d
;
4723 name_hint hint
= suggest_alternatives_for (location
, name
, true);
4724 if (const char *suggestion
= hint
.suggestion ())
4726 gcc_rich_location
richloc (location
);
4727 richloc
.add_fixit_replace (suggestion
);
4729 "%<::%D%> has not been declared; did you mean %qs?",
4733 error_at (location
, "%<::%D%> has not been declared", name
);
4737 /* C++-specific implementation of range_label::get_text () vfunc for
4738 range_label_for_type_mismatch.
4740 Compare with print_template_differences above. */
4743 range_label_for_type_mismatch::get_text (unsigned /*range_idx*/) const
4745 if (m_labelled_type
== NULL_TREE
)
4746 return label_text::borrow (NULL
);
4748 const bool verbose
= false;
4749 const bool show_color
= false;
4753 && comparable_template_types_p (m_labelled_type
, m_other_type
))
4754 result
= type_to_string_with_compare (m_labelled_type
, m_other_type
,
4755 verbose
, show_color
);
4757 result
= type_to_string (m_labelled_type
, verbose
, true, NULL
, show_color
);
4759 /* Both of the above return GC-allocated buffers, so the caller mustn't
4761 return label_text::borrow (result
);