1 /* Call-backs for C++ error reporting.
2 This code is non-reentrant.
3 Copyright (C) 1993-2019 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
21 /* For use with name_hint. */
22 #define INCLUDE_UNIQUE_PTR
24 #include "coretypes.h"
26 #include "stringpool.h"
27 #include "tree-diagnostic.h"
28 #include "langhooks-def.h"
30 #include "cxx-pretty-print.h"
31 #include "tree-pretty-print.h"
32 #include "gimple-pretty-print.h"
33 #include "c-family/c-objc.h"
35 #include "internal-fn.h"
36 #include "gcc-rich-location.h"
37 #include "cp-name-hint.h"
39 #define pp_separate_with_comma(PP) pp_cxx_separate_with (PP, ',')
40 #define pp_separate_with_semicolon(PP) pp_cxx_separate_with (PP, ';')
42 /* cxx_pp is a C++ front-end-specific pretty printer: this is where we
43 dump C++ ASTs as strings. It is mostly used only by the various
44 tree -> string functions that are occasionally called from the
45 debugger or by the front-end for things like
46 __PRETTY_FUNCTION__. */
47 static cxx_pretty_printer actual_pretty_printer
;
48 static cxx_pretty_printer
* const cxx_pp
= &actual_pretty_printer
;
50 /* Translate if being used for diagnostics, but not for dump files or
52 #define M_(msgid) (pp_translate_identifiers (cxx_pp) ? _(msgid) : (msgid))
54 # define NEXT_CODE(T) (TREE_CODE (TREE_TYPE (T)))
56 static const char *args_to_string (tree
, int);
57 static const char *code_to_string (enum tree_code
);
58 static const char *cv_to_string (tree
, int);
59 static const char *decl_to_string (tree
, int);
60 static const char *fndecl_to_string (tree
, int);
61 static const char *op_to_string (bool, enum tree_code
);
62 static const char *parm_to_string (int);
63 static const char *type_to_string (tree
, int, bool, bool *, bool);
65 static void dump_alias_template_specialization (cxx_pretty_printer
*, tree
, int);
66 static void dump_type (cxx_pretty_printer
*, tree
, int);
67 static void dump_typename (cxx_pretty_printer
*, tree
, int);
68 static void dump_simple_decl (cxx_pretty_printer
*, tree
, tree
, int);
69 static void dump_decl (cxx_pretty_printer
*, tree
, int);
70 static void dump_template_decl (cxx_pretty_printer
*, tree
, int);
71 static void dump_function_decl (cxx_pretty_printer
*, tree
, int);
72 static void dump_expr (cxx_pretty_printer
*, tree
, int);
73 static void dump_unary_op (cxx_pretty_printer
*, const char *, tree
, int);
74 static void dump_binary_op (cxx_pretty_printer
*, const char *, tree
, int);
75 static void dump_aggr_type (cxx_pretty_printer
*, tree
, int);
76 static void dump_type_prefix (cxx_pretty_printer
*, tree
, int);
77 static void dump_type_suffix (cxx_pretty_printer
*, tree
, int);
78 static void dump_function_name (cxx_pretty_printer
*, tree
, int);
79 static void dump_call_expr_args (cxx_pretty_printer
*, tree
, int, bool);
80 static void dump_aggr_init_expr_args (cxx_pretty_printer
*, tree
, int, bool);
81 static void dump_expr_list (cxx_pretty_printer
*, tree
, int);
82 static void dump_global_iord (cxx_pretty_printer
*, tree
);
83 static void dump_parameters (cxx_pretty_printer
*, tree
, int);
84 static void dump_ref_qualifier (cxx_pretty_printer
*, tree
, int);
85 static void dump_exception_spec (cxx_pretty_printer
*, tree
, int);
86 static void dump_template_argument (cxx_pretty_printer
*, tree
, int);
87 static void dump_template_argument_list (cxx_pretty_printer
*, tree
, int);
88 static void dump_template_parameter (cxx_pretty_printer
*, tree
, int);
89 static void dump_template_bindings (cxx_pretty_printer
*, tree
, tree
,
91 static void dump_scope (cxx_pretty_printer
*, tree
, int);
92 static void dump_template_parms (cxx_pretty_printer
*, tree
, int, int);
93 static int get_non_default_template_args_count (tree
, int);
94 static const char *function_category (tree
);
95 static void maybe_print_constexpr_context (diagnostic_context
*);
96 static void maybe_print_instantiation_context (diagnostic_context
*);
97 static void print_instantiation_full_context (diagnostic_context
*);
98 static void print_instantiation_partial_context (diagnostic_context
*,
101 static void cp_diagnostic_starter (diagnostic_context
*, diagnostic_info
*);
102 static void cp_print_error_function (diagnostic_context
*, diagnostic_info
*);
104 static bool cp_printer (pretty_printer
*, text_info
*, const char *,
105 int, bool, bool, bool, bool *, const char **);
107 /* Struct for handling %H or %I, which require delaying printing the
108 type until a postprocessing stage. */
110 struct deferred_printed_type
112 deferred_printed_type ()
113 : m_tree (NULL_TREE
), m_buffer_ptr (NULL
), m_verbose (false), m_quote (false)
116 deferred_printed_type (tree type
, const char **buffer_ptr
, bool verbose
,
118 : m_tree (type
), m_buffer_ptr (buffer_ptr
), m_verbose (verbose
),
122 gcc_assert (buffer_ptr
);
125 /* The tree is not GTY-marked: they are only non-NULL within a
126 call to pp_format. */
128 const char **m_buffer_ptr
;
133 /* Subclass of format_postprocessor for the C++ frontend.
134 This handles the %H and %I formatting codes, printing them
135 in a postprocessing phase (since they affect each other). */
137 class cxx_format_postprocessor
: public format_postprocessor
140 cxx_format_postprocessor ()
141 : m_type_a (), m_type_b ()
144 void handle (pretty_printer
*pp
) FINAL OVERRIDE
;
146 deferred_printed_type m_type_a
;
147 deferred_printed_type m_type_b
;
150 /* CONTEXT->printer is a basic pretty printer that was constructed
151 presumably by diagnostic_initialize(), called early in the
152 compiler's initialization process (in general_init) Before the FE
153 is initialized. This (C++) FE-specific diagnostic initializer is
154 thus replacing the basic pretty printer with one that has C++-aware
158 cxx_initialize_diagnostics (diagnostic_context
*context
)
160 pretty_printer
*base
= context
->printer
;
161 cxx_pretty_printer
*pp
= XNEW (cxx_pretty_printer
);
162 context
->printer
= new (pp
) cxx_pretty_printer ();
164 /* It is safe to free this object because it was previously XNEW()'d. */
165 base
->~pretty_printer ();
168 c_common_diagnostics_set_defaults (context
);
169 diagnostic_starter (context
) = cp_diagnostic_starter
;
170 /* diagnostic_finalizer is already c_diagnostic_finalizer. */
171 diagnostic_format_decoder (context
) = cp_printer
;
172 pp
->m_format_postprocessor
= new cxx_format_postprocessor ();
175 /* Dump a scope, if deemed necessary. */
178 dump_scope (cxx_pretty_printer
*pp
, tree scope
, int flags
)
180 int f
= flags
& (TFF_SCOPE
| TFF_CHASE_TYPEDEF
);
182 if (scope
== NULL_TREE
)
185 /* Enum values within an unscoped enum will be CONST_DECL with an
186 ENUMERAL_TYPE as their "scope". Use CP_TYPE_CONTEXT of the
187 ENUMERAL_TYPE, so as to print any enclosing namespace. */
188 if (UNSCOPED_ENUM_P (scope
))
189 scope
= CP_TYPE_CONTEXT (scope
);
191 if (TREE_CODE (scope
) == NAMESPACE_DECL
)
193 if (scope
!= global_namespace
)
195 dump_decl (pp
, scope
, f
);
196 pp_cxx_colon_colon (pp
);
199 else if (AGGREGATE_TYPE_P (scope
)
200 || SCOPED_ENUM_P (scope
))
202 dump_type (pp
, scope
, f
);
203 pp_cxx_colon_colon (pp
);
205 else if ((flags
& TFF_SCOPE
) && TREE_CODE (scope
) == FUNCTION_DECL
)
207 dump_function_decl (pp
, scope
, f
);
208 pp_cxx_colon_colon (pp
);
212 /* Dump the template ARGument under control of FLAGS. */
215 dump_template_argument (cxx_pretty_printer
*pp
, tree arg
, int flags
)
217 if (ARGUMENT_PACK_P (arg
))
218 dump_template_argument_list (pp
, ARGUMENT_PACK_ARGS (arg
),
219 /* No default args in argument packs. */
220 flags
|TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS
);
221 else if (TYPE_P (arg
) || TREE_CODE (arg
) == TEMPLATE_DECL
)
222 dump_type (pp
, arg
, flags
& ~TFF_CLASS_KEY_OR_ENUM
);
225 if (TREE_CODE (arg
) == TREE_LIST
)
226 arg
= TREE_VALUE (arg
);
228 /* Strip implicit conversions. */
229 while (CONVERT_EXPR_P (arg
))
230 arg
= TREE_OPERAND (arg
, 0);
232 dump_expr (pp
, arg
, (flags
| TFF_EXPR_IN_PARENS
) & ~TFF_CLASS_KEY_OR_ENUM
);
236 /* Count the number of template arguments ARGS whose value does not
237 match the (optional) default template parameter in PARAMS */
240 get_non_default_template_args_count (tree args
, int flags
)
242 int n
= TREE_VEC_LENGTH (INNERMOST_TEMPLATE_ARGS (args
));
244 if (/* We use this flag when generating debug information. We don't
245 want to expand templates at this point, for this may generate
246 new decls, which gets decl counts out of sync, which may in
247 turn cause codegen differences between compilations with and
249 (flags
& TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS
) != 0
250 || !flag_pretty_templates
)
253 return GET_NON_DEFAULT_TEMPLATE_ARGS_COUNT (INNERMOST_TEMPLATE_ARGS (args
));
256 /* Dump a template-argument-list ARGS (always a TREE_VEC) under control
260 dump_template_argument_list (cxx_pretty_printer
*pp
, tree args
, int flags
)
262 int n
= get_non_default_template_args_count (args
, flags
);
266 for (i
= 0; i
< n
; ++i
)
268 tree arg
= TREE_VEC_ELT (args
, i
);
270 /* Only print a comma if we know there is an argument coming. In
271 the case of an empty template argument pack, no actual
272 argument will be printed. */
274 && (!ARGUMENT_PACK_P (arg
)
275 || TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg
)) > 0))
276 pp_separate_with_comma (pp
);
278 dump_template_argument (pp
, arg
, flags
);
283 /* Dump a template parameter PARM (a TREE_LIST) under control of FLAGS. */
286 dump_template_parameter (cxx_pretty_printer
*pp
, tree parm
, int flags
)
291 if (parm
== error_mark_node
)
294 p
= TREE_VALUE (parm
);
295 a
= TREE_PURPOSE (parm
);
297 if (TREE_CODE (p
) == TYPE_DECL
)
299 if (flags
& TFF_DECL_SPECIFIERS
)
301 pp_cxx_ws_string (pp
, "class");
302 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (p
)))
303 pp_cxx_ws_string (pp
, "...");
305 pp_cxx_tree_identifier (pp
, DECL_NAME (p
));
307 else if (DECL_NAME (p
))
308 pp_cxx_tree_identifier (pp
, DECL_NAME (p
));
310 pp_cxx_canonical_template_parameter (pp
, TREE_TYPE (p
));
313 dump_decl (pp
, p
, flags
| TFF_DECL_SPECIFIERS
);
315 if ((flags
& TFF_FUNCTION_DEFAULT_ARGUMENTS
) && a
!= NULL_TREE
)
317 pp_cxx_whitespace (pp
);
319 pp_cxx_whitespace (pp
);
320 if (TREE_CODE (p
) == TYPE_DECL
|| TREE_CODE (p
) == TEMPLATE_DECL
)
321 dump_type (pp
, a
, flags
& ~TFF_CHASE_TYPEDEF
);
323 dump_expr (pp
, a
, flags
| TFF_EXPR_IN_PARENS
);
327 /* Dump, under control of FLAGS, a template-parameter-list binding.
328 PARMS is a TREE_LIST of TREE_VEC of TREE_LIST and ARGS is a
332 dump_template_bindings (cxx_pretty_printer
*pp
, tree parms
, tree args
,
333 vec
<tree
, va_gc
> *typenames
)
335 bool need_semicolon
= false;
341 tree p
= TREE_VALUE (parms
);
342 int lvl
= TMPL_PARMS_DEPTH (parms
);
345 tree lvl_args
= NULL_TREE
;
347 /* Don't crash if we had an invalid argument list. */
348 if (TMPL_ARGS_DEPTH (args
) >= lvl
)
349 lvl_args
= TMPL_ARGS_LEVEL (args
, lvl
);
351 for (i
= 0; i
< TREE_VEC_LENGTH (p
); ++i
)
353 tree arg
= NULL_TREE
;
355 /* Don't crash if we had an invalid argument list. */
356 if (lvl_args
&& NUM_TMPL_ARGS (lvl_args
) > arg_idx
)
357 arg
= TREE_VEC_ELT (lvl_args
, arg_idx
);
360 pp_separate_with_semicolon (pp
);
361 dump_template_parameter (pp
, TREE_VEC_ELT (p
, i
),
362 TFF_PLAIN_IDENTIFIER
);
363 pp_cxx_whitespace (pp
);
365 pp_cxx_whitespace (pp
);
368 if (ARGUMENT_PACK_P (arg
))
369 pp_cxx_left_brace (pp
);
370 dump_template_argument (pp
, arg
, TFF_PLAIN_IDENTIFIER
);
371 if (ARGUMENT_PACK_P (arg
))
372 pp_cxx_right_brace (pp
);
375 pp_string (pp
, M_("<missing>"));
378 need_semicolon
= true;
381 parms
= TREE_CHAIN (parms
);
384 /* Don't bother with typenames for a partial instantiation. */
385 if (vec_safe_is_empty (typenames
) || uses_template_parms (args
))
388 /* Don't try to print typenames when we're processing a clone. */
389 if (current_function_decl
390 && !DECL_LANG_SPECIFIC (current_function_decl
))
393 /* Don't try to do this once cgraph starts throwing away front-end
398 FOR_EACH_VEC_SAFE_ELT (typenames
, i
, t
)
401 pp_separate_with_semicolon (pp
);
402 dump_type (pp
, t
, TFF_PLAIN_IDENTIFIER
);
403 pp_cxx_whitespace (pp
);
405 pp_cxx_whitespace (pp
);
406 push_deferring_access_checks (dk_no_check
);
407 t
= tsubst (t
, args
, tf_none
, NULL_TREE
);
408 pop_deferring_access_checks ();
409 /* Strip typedefs. We can't just use TFF_CHASE_TYPEDEF because
410 pp_simple_type_specifier doesn't know about it. */
411 t
= strip_typedefs (t
);
412 dump_type (pp
, t
, TFF_PLAIN_IDENTIFIER
);
416 /* Dump a human-readable equivalent of the alias template
417 specialization of T. */
420 dump_alias_template_specialization (cxx_pretty_printer
*pp
, tree t
, int flags
)
422 gcc_assert (alias_template_specialization_p (t
));
424 tree decl
= TYPE_NAME (t
);
425 if (!(flags
& TFF_UNQUALIFIED_NAME
))
426 dump_scope (pp
, CP_DECL_CONTEXT (decl
), flags
);
427 pp_cxx_tree_identifier (pp
, DECL_NAME (decl
));
428 dump_template_parms (pp
, DECL_TEMPLATE_INFO (decl
),
430 flags
& ~TFF_TEMPLATE_HEADER
);
433 /* Dump a human-readable equivalent of TYPE. FLAGS controls the
437 dump_type (cxx_pretty_printer
*pp
, tree t
, int flags
)
442 /* Don't print e.g. "struct mytypedef". */
443 if (TYPE_P (t
) && typedef_variant_p (t
))
445 tree decl
= TYPE_NAME (t
);
446 if ((flags
& TFF_CHASE_TYPEDEF
)
447 || DECL_SELF_REFERENCE_P (decl
)
448 || (!flag_pretty_templates
449 && DECL_LANG_SPECIFIC (decl
) && DECL_TEMPLATE_INFO (decl
)))
450 t
= strip_typedefs (t
);
451 else if (alias_template_specialization_p (t
))
453 dump_alias_template_specialization (pp
, t
, flags
);
456 else if (same_type_p (t
, TREE_TYPE (decl
)))
460 pp_cxx_cv_qualifier_seq (pp
, t
);
461 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
466 if (TYPE_PTRMEMFUNC_P (t
))
469 switch (TREE_CODE (t
))
472 if (t
== init_list_type_node
)
473 pp_string (pp
, M_("<brace-enclosed initializer list>"));
474 else if (t
== unknown_type_node
)
475 pp_string (pp
, M_("<unresolved overloaded function type>"));
478 pp_cxx_cv_qualifier_seq (pp
, t
);
479 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
484 /* A list of function parms. */
485 dump_parameters (pp
, t
, flags
);
488 case IDENTIFIER_NODE
:
489 pp_cxx_tree_identifier (pp
, t
);
493 dump_type (pp
, BINFO_TYPE (t
), flags
);
499 dump_aggr_type (pp
, t
, flags
);
503 if (flags
& TFF_CHASE_TYPEDEF
)
505 dump_type (pp
, DECL_ORIGINAL_TYPE (t
)
506 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
), flags
);
513 dump_decl (pp
, t
, flags
& ~TFF_DECL_SPECIFIERS
);
522 case FIXED_POINT_TYPE
:
523 pp_type_specifier_seq (pp
, t
);
526 case TEMPLATE_TEMPLATE_PARM
:
527 /* For parameters inside template signature. */
528 if (TYPE_IDENTIFIER (t
))
529 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
531 pp_cxx_canonical_template_parameter (pp
, t
);
534 case BOUND_TEMPLATE_TEMPLATE_PARM
:
536 tree args
= TYPE_TI_ARGS (t
);
537 pp_cxx_cv_qualifier_seq (pp
, t
);
538 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
539 pp_cxx_begin_template_argument_list (pp
);
540 dump_template_argument_list (pp
, args
, flags
);
541 pp_cxx_end_template_argument_list (pp
);
545 case TEMPLATE_TYPE_PARM
:
546 pp_cxx_cv_qualifier_seq (pp
, t
);
547 if (tree c
= PLACEHOLDER_TYPE_CONSTRAINTS (t
))
548 pp_cxx_constrained_type_spec (pp
, c
);
549 else if (TYPE_IDENTIFIER (t
))
550 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
552 pp_cxx_canonical_template_parameter
553 (pp
, TEMPLATE_TYPE_PARM_INDEX (t
));
556 /* This is not always necessary for pointers and such, but doing this
557 reduces code size. */
566 dump_type_prefix (pp
, t
, flags
);
567 dump_type_suffix (pp
, t
, flags
);
571 if (! (flags
& TFF_CHASE_TYPEDEF
)
572 && DECL_ORIGINAL_TYPE (TYPE_NAME (t
)))
574 dump_decl (pp
, TYPE_NAME (t
), TFF_PLAIN_IDENTIFIER
);
577 pp_cxx_cv_qualifier_seq (pp
, t
);
578 pp_cxx_ws_string (pp
,
579 TYPENAME_IS_ENUM_P (t
) ? "enum"
580 : TYPENAME_IS_CLASS_P (t
) ? "class"
582 dump_typename (pp
, t
, flags
);
585 case UNBOUND_CLASS_TEMPLATE
:
586 if (! (flags
& TFF_UNQUALIFIED_NAME
))
588 dump_type (pp
, TYPE_CONTEXT (t
), flags
);
589 pp_cxx_colon_colon (pp
);
591 pp_cxx_ws_string (pp
, "template");
592 dump_type (pp
, TYPE_IDENTIFIER (t
), flags
);
596 pp_cxx_ws_string (pp
, "__typeof__");
597 pp_cxx_whitespace (pp
);
598 pp_cxx_left_paren (pp
);
599 dump_expr (pp
, TYPEOF_TYPE_EXPR (t
), flags
& ~TFF_EXPR_IN_PARENS
);
600 pp_cxx_right_paren (pp
);
603 case UNDERLYING_TYPE
:
604 pp_cxx_ws_string (pp
, "__underlying_type");
605 pp_cxx_whitespace (pp
);
606 pp_cxx_left_paren (pp
);
607 dump_expr (pp
, UNDERLYING_TYPE_TYPE (t
), flags
& ~TFF_EXPR_IN_PARENS
);
608 pp_cxx_right_paren (pp
);
611 case TYPE_PACK_EXPANSION
:
612 dump_type (pp
, PACK_EXPANSION_PATTERN (t
), flags
);
613 pp_cxx_ws_string (pp
, "...");
616 case TYPE_ARGUMENT_PACK
:
617 dump_template_argument (pp
, t
, flags
);
621 pp_cxx_ws_string (pp
, "decltype");
622 pp_cxx_whitespace (pp
);
623 pp_cxx_left_paren (pp
);
624 dump_expr (pp
, DECLTYPE_TYPE_EXPR (t
), flags
& ~TFF_EXPR_IN_PARENS
);
625 pp_cxx_right_paren (pp
);
629 pp_string (pp
, "std::nullptr_t");
633 pp_unsupported_tree (pp
, t
);
637 pp_string (pp
, M_("<type error>"));
642 /* Dump a TYPENAME_TYPE. We need to notice when the context is itself
646 dump_typename (cxx_pretty_printer
*pp
, tree t
, int flags
)
648 tree ctx
= TYPE_CONTEXT (t
);
650 if (TREE_CODE (ctx
) == TYPENAME_TYPE
)
651 dump_typename (pp
, ctx
, flags
);
653 dump_type (pp
, ctx
, flags
& ~TFF_CLASS_KEY_OR_ENUM
);
654 pp_cxx_colon_colon (pp
);
655 dump_decl (pp
, TYPENAME_TYPE_FULLNAME (t
), flags
);
658 /* Return the name of the supplied aggregate, or enumeral type. */
661 class_key_or_enum_as_string (tree t
)
663 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
665 if (SCOPED_ENUM_P (t
))
670 else if (TREE_CODE (t
) == UNION_TYPE
)
672 else if (TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_DECLARED_CLASS (t
))
678 /* Print out a class declaration T under the control of FLAGS,
679 in the form `class foo'. */
682 dump_aggr_type (cxx_pretty_printer
*pp
, tree t
, int flags
)
685 const char *variety
= class_key_or_enum_as_string (t
);
689 pp_cxx_cv_qualifier_seq (pp
, t
);
691 if (flags
& TFF_CLASS_KEY_OR_ENUM
)
692 pp_cxx_ws_string (pp
, variety
);
694 name
= TYPE_NAME (t
);
698 typdef
= (!DECL_ARTIFICIAL (name
)
699 /* An alias specialization is not considered to be a
701 && !alias_template_specialization_p (t
));
704 && ((flags
& TFF_CHASE_TYPEDEF
)
705 || (!flag_pretty_templates
&& DECL_LANG_SPECIFIC (name
)
706 && DECL_TEMPLATE_INFO (name
))))
707 || DECL_SELF_REFERENCE_P (name
))
709 t
= TYPE_MAIN_VARIANT (t
);
710 name
= TYPE_NAME (t
);
714 tmplate
= !typdef
&& TREE_CODE (t
) != ENUMERAL_TYPE
715 && TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_TEMPLATE_INFO (t
)
716 && (TREE_CODE (CLASSTYPE_TI_TEMPLATE (t
)) != TEMPLATE_DECL
717 || PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t
)));
719 if (! (flags
& TFF_UNQUALIFIED_NAME
))
720 dump_scope (pp
, CP_DECL_CONTEXT (name
), flags
| TFF_SCOPE
);
721 flags
&= ~TFF_UNQUALIFIED_NAME
;
724 /* Because the template names are mangled, we have to locate
725 the most general template, and use that name. */
726 tree tpl
= TYPE_TI_TEMPLATE (t
);
728 while (DECL_TEMPLATE_INFO (tpl
))
729 tpl
= DECL_TI_TEMPLATE (tpl
);
732 name
= DECL_NAME (name
);
735 if (name
== 0 || anon_aggrname_p (name
))
737 if (flags
& TFF_CLASS_KEY_OR_ENUM
)
738 pp_string (pp
, M_("<unnamed>"));
740 pp_printf (pp
, M_("<unnamed %s>"), variety
);
742 else if (LAMBDA_TYPE_P (t
))
744 /* A lambda's "type" is essentially its signature. */
745 pp_string (pp
, M_("<lambda"));
746 if (lambda_function (t
))
748 FUNCTION_FIRST_USER_PARMTYPE (lambda_function (t
)),
753 pp_cxx_tree_identifier (pp
, name
);
755 dump_template_parms (pp
, TYPE_TEMPLATE_INFO (t
),
756 !CLASSTYPE_USE_TEMPLATE (t
),
757 flags
& ~TFF_TEMPLATE_HEADER
);
760 /* Dump into the obstack the initial part of the output for a given type.
761 This is necessary when dealing with things like functions returning
764 return type of `int (* fee ())()': pointer -> function -> int. Both
765 pointer (and reference and offset) and function (and member) types must
766 deal with prefix and suffix.
768 Arrays must also do this for DECL nodes, like int a[], and for things like
772 dump_type_prefix (cxx_pretty_printer
*pp
, tree t
, int flags
)
774 if (TYPE_PTRMEMFUNC_P (t
))
776 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
780 switch (TREE_CODE (t
))
785 tree sub
= TREE_TYPE (t
);
787 dump_type_prefix (pp
, sub
, flags
);
788 if (TREE_CODE (sub
) == ARRAY_TYPE
789 || TREE_CODE (sub
) == FUNCTION_TYPE
)
791 pp_cxx_whitespace (pp
);
792 pp_cxx_left_paren (pp
);
793 pp_c_attributes_display (pp
, TYPE_ATTRIBUTES (sub
));
797 else if (TYPE_REF_P (t
))
799 if (TYPE_REF_IS_RVALUE (t
))
800 pp_ampersand_ampersand (pp
);
804 pp
->padding
= pp_before
;
805 pp_cxx_cv_qualifier_seq (pp
, t
);
811 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
812 if (TREE_CODE (t
) == OFFSET_TYPE
) /* pmfs deal with this in d_t_p */
815 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
816 pp_cxx_left_paren (pp
);
817 dump_type (pp
, TYPE_OFFSET_BASETYPE (t
), flags
);
818 pp_cxx_colon_colon (pp
);
821 pp_cxx_cv_qualifier_seq (pp
, t
);
822 pp
->padding
= pp_before
;
825 /* This can be reached without a pointer when dealing with
826 templates, e.g. std::is_function. */
828 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
832 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
834 pp_cxx_left_paren (pp
);
835 dump_aggr_type (pp
, TYPE_METHOD_BASETYPE (t
), flags
);
836 pp_cxx_colon_colon (pp
);
840 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
844 case IDENTIFIER_NODE
:
849 case TEMPLATE_TYPE_PARM
:
850 case TEMPLATE_TEMPLATE_PARM
:
851 case BOUND_TEMPLATE_TEMPLATE_PARM
:
862 case UNDERLYING_TYPE
:
864 case TYPE_PACK_EXPANSION
:
865 case FIXED_POINT_TYPE
:
867 dump_type (pp
, t
, flags
);
868 pp
->padding
= pp_before
;
872 pp_unsupported_tree (pp
, t
);
875 pp_string (pp
, M_("<typeprefixerror>"));
880 /* Dump the suffix of type T, under control of FLAGS. This is the part
881 which appears after the identifier (or function parms). */
884 dump_type_suffix (cxx_pretty_printer
*pp
, tree t
, int flags
)
886 if (TYPE_PTRMEMFUNC_P (t
))
887 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
889 switch (TREE_CODE (t
))
894 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
895 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
896 pp_cxx_right_paren (pp
);
897 if (TREE_CODE (t
) == POINTER_TYPE
)
898 flags
|= TFF_POINTER
;
899 dump_type_suffix (pp
, TREE_TYPE (t
), flags
);
906 if (TREE_CODE (t
) == METHOD_TYPE
)
907 /* Can only be reached through a pointer. */
908 pp_cxx_right_paren (pp
);
909 arg
= TYPE_ARG_TYPES (t
);
910 if (TREE_CODE (t
) == METHOD_TYPE
)
911 arg
= TREE_CHAIN (arg
);
913 /* Function pointers don't have default args. Not in standard C++,
914 anyway; they may in g++, but we'll just pretend otherwise. */
915 dump_parameters (pp
, arg
, flags
& ~TFF_FUNCTION_DEFAULT_ARGUMENTS
);
917 pp
->padding
= pp_before
;
918 pp_cxx_cv_qualifiers (pp
, type_memfn_quals (t
),
919 TREE_CODE (t
) == FUNCTION_TYPE
920 && (flags
& TFF_POINTER
));
921 dump_ref_qualifier (pp
, t
, flags
);
922 if (tx_safe_fn_type_p (t
))
923 pp_cxx_ws_string (pp
, "transaction_safe");
924 dump_exception_spec (pp
, TYPE_RAISES_EXCEPTIONS (t
), flags
);
925 dump_type_suffix (pp
, TREE_TYPE (t
), flags
);
931 pp_cxx_left_bracket (pp
);
932 if (tree dtype
= TYPE_DOMAIN (t
))
934 tree max
= TYPE_MAX_VALUE (dtype
);
935 /* Zero-length arrays have an upper bound of SIZE_MAX. */
936 if (integer_all_onesp (max
))
937 pp_character (pp
, '0');
938 else if (tree_fits_shwi_p (max
))
939 pp_wide_integer (pp
, tree_to_shwi (max
) + 1);
943 if (TREE_CODE (max
) == SAVE_EXPR
)
944 max
= TREE_OPERAND (max
, 0);
945 if (TREE_CODE (max
) == MINUS_EXPR
946 || TREE_CODE (max
) == PLUS_EXPR
)
948 max
= TREE_OPERAND (max
, 0);
949 while (CONVERT_EXPR_P (max
))
950 max
= TREE_OPERAND (max
, 0);
953 max
= fold_build2_loc (input_location
,
954 PLUS_EXPR
, dtype
, max
,
955 build_int_cst (dtype
, 1));
956 dump_expr (pp
, max
, flags
& ~TFF_EXPR_IN_PARENS
);
959 pp_cxx_right_bracket (pp
);
960 dump_type_suffix (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
:
982 case UNDERLYING_TYPE
:
984 case TYPE_PACK_EXPANSION
:
985 case FIXED_POINT_TYPE
:
990 pp_unsupported_tree (pp
, t
);
992 /* Don't mark it here, we should have already done in
999 dump_global_iord (cxx_pretty_printer
*pp
, tree t
)
1001 const char *p
= NULL
;
1003 if (DECL_GLOBAL_CTOR_P (t
))
1004 p
= M_("(static initializers for %s)");
1005 else if (DECL_GLOBAL_DTOR_P (t
))
1006 p
= M_("(static destructors for %s)");
1010 pp_printf (pp
, p
, DECL_SOURCE_FILE (t
));
1014 dump_simple_decl (cxx_pretty_printer
*pp
, tree t
, tree type
, int flags
)
1016 if (template_parm_object_p (t
))
1017 return dump_expr (pp
, DECL_INITIAL (t
), flags
);
1019 if (flags
& TFF_DECL_SPECIFIERS
)
1021 if (VAR_P (t
) && DECL_DECLARED_CONSTEXPR_P (t
))
1023 if (DECL_LANG_SPECIFIC (t
) && DECL_DECLARED_CONCEPT_P (t
))
1024 pp_cxx_ws_string (pp
, "concept");
1026 pp_cxx_ws_string (pp
, "constexpr");
1028 dump_type_prefix (pp
, type
, flags
& ~TFF_UNQUALIFIED_NAME
);
1029 pp_maybe_space (pp
);
1031 if (! (flags
& TFF_UNQUALIFIED_NAME
)
1032 && TREE_CODE (t
) != PARM_DECL
1033 && (!DECL_INITIAL (t
)
1034 || TREE_CODE (DECL_INITIAL (t
)) != TEMPLATE_PARM_INDEX
))
1035 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1036 flags
&= ~TFF_UNQUALIFIED_NAME
;
1037 if ((flags
& TFF_DECL_SPECIFIERS
)
1038 && DECL_TEMPLATE_PARM_P (t
)
1039 && TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (t
)))
1040 pp_string (pp
, "...");
1043 if (TREE_CODE (t
) == FIELD_DECL
&& DECL_NORMAL_CAPTURE_P (t
))
1046 pp_string (pp
, IDENTIFIER_POINTER (DECL_NAME (t
)) + 2);
1047 pp_string (pp
, " capture>");
1050 dump_decl (pp
, DECL_NAME (t
), flags
);
1052 else if (DECL_DECOMPOSITION_P (t
))
1053 pp_string (pp
, M_("<structured bindings>"));
1055 pp_string (pp
, M_("<anonymous>"));
1056 if (flags
& TFF_DECL_SPECIFIERS
)
1057 dump_type_suffix (pp
, type
, flags
);
1060 /* Print an IDENTIFIER_NODE that is the name of a declaration. */
1063 dump_decl_name (cxx_pretty_printer
*pp
, tree t
, int flags
)
1065 /* These special cases are duplicated here so that other functions
1066 can feed identifiers to error and get them demangled properly. */
1067 if (IDENTIFIER_CONV_OP_P (t
))
1069 pp_cxx_ws_string (pp
, "operator");
1070 /* Not exactly IDENTIFIER_TYPE_VALUE. */
1071 dump_type (pp
, TREE_TYPE (t
), flags
);
1074 if (dguide_name_p (t
))
1076 dump_decl (pp
, CLASSTYPE_TI_TEMPLATE (TREE_TYPE (t
)),
1077 TFF_UNQUALIFIED_NAME
);
1081 const char *str
= IDENTIFIER_POINTER (t
);
1082 if (!strncmp (str
, "_ZGR", 3))
1084 pp_cxx_ws_string (pp
, "<temporary>");
1088 pp_cxx_tree_identifier (pp
, t
);
1091 /* Dump a human readable string for the decl T under control of FLAGS. */
1094 dump_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
1099 /* If doing Objective-C++, give Objective-C a chance to demangle
1100 Objective-C method names. */
1101 if (c_dialect_objc ())
1103 const char *demangled
= objc_maybe_printable_name (t
, flags
);
1106 pp_string (pp
, demangled
);
1111 switch (TREE_CODE (t
))
1114 /* Don't say 'typedef class A' */
1115 if (DECL_ARTIFICIAL (t
) && !DECL_SELF_REFERENCE_P (t
))
1117 if ((flags
& TFF_DECL_SPECIFIERS
)
1118 && TREE_CODE (TREE_TYPE (t
)) == TEMPLATE_TYPE_PARM
)
1120 /* Say `class T' not just `T'. */
1121 pp_cxx_ws_string (pp
, "class");
1123 /* Emit the `...' for a parameter pack. */
1124 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t
)))
1125 pp_cxx_ws_string (pp
, "...");
1128 dump_type (pp
, TREE_TYPE (t
), flags
);
1131 if (TYPE_DECL_ALIAS_P (t
)
1132 && (flags
& TFF_DECL_SPECIFIERS
1133 || flags
& TFF_CLASS_KEY_OR_ENUM
))
1135 pp_cxx_ws_string (pp
, "using");
1136 dump_decl (pp
, DECL_NAME (t
), flags
);
1137 pp_cxx_whitespace (pp
);
1138 pp_cxx_ws_string (pp
, "=");
1139 pp_cxx_whitespace (pp
);
1140 dump_type (pp
, (DECL_ORIGINAL_TYPE (t
)
1141 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
)),
1145 if ((flags
& TFF_DECL_SPECIFIERS
)
1146 && !DECL_SELF_REFERENCE_P (t
))
1147 pp_cxx_ws_string (pp
, "typedef");
1148 dump_simple_decl (pp
, t
, DECL_ORIGINAL_TYPE (t
)
1149 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
),
1154 if (DECL_NAME (t
) && VTABLE_NAME_P (DECL_NAME (t
)))
1156 pp_string (pp
, M_("vtable for "));
1157 gcc_assert (TYPE_P (DECL_CONTEXT (t
)));
1158 dump_type (pp
, DECL_CONTEXT (t
), flags
);
1164 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1166 /* Handle variable template specializations. */
1168 && DECL_LANG_SPECIFIC (t
)
1169 && DECL_TEMPLATE_INFO (t
)
1170 && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t
)))
1172 pp_cxx_begin_template_argument_list (pp
);
1173 tree args
= INNERMOST_TEMPLATE_ARGS (DECL_TI_ARGS (t
));
1174 dump_template_argument_list (pp
, args
, flags
);
1175 pp_cxx_end_template_argument_list (pp
);
1180 pp_string (pp
, M_("<return value> "));
1181 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1184 case NAMESPACE_DECL
:
1185 if (flags
& TFF_DECL_SPECIFIERS
)
1186 pp
->declaration (t
);
1189 if (! (flags
& TFF_UNQUALIFIED_NAME
))
1190 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1191 flags
&= ~TFF_UNQUALIFIED_NAME
;
1192 if (DECL_NAME (t
) == NULL_TREE
)
1194 if (!(pp
->flags
& pp_c_flag_gnu_v3
))
1195 pp_cxx_ws_string (pp
, M_("{anonymous}"));
1197 pp_cxx_ws_string (pp
, M_("(anonymous namespace)"));
1200 pp_cxx_tree_identifier (pp
, DECL_NAME (t
));
1205 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
1206 pp_cxx_colon_colon (pp
);
1207 dump_decl (pp
, TREE_OPERAND (t
, 1), TFF_UNQUALIFIED_NAME
);
1211 dump_decl (pp
, TREE_OPERAND (t
, 0), flags
);
1212 pp_cxx_left_bracket (pp
);
1213 dump_decl (pp
, TREE_OPERAND (t
, 1), flags
);
1214 pp_cxx_right_bracket (pp
);
1217 /* So that we can do dump_decl on an aggr type. */
1221 dump_type (pp
, t
, flags
);
1225 /* This is a pseudo destructor call which has not been folded into
1226 a PSEUDO_DTOR_EXPR yet. */
1227 pp_cxx_complement (pp
);
1228 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
1235 case IDENTIFIER_NODE
:
1236 dump_decl_name (pp
, t
, flags
);
1240 if (!OVL_SINGLE_P (t
))
1242 tree ctx
= ovl_scope (t
);
1243 if (ctx
!= global_namespace
)
1246 dump_type (pp
, ctx
, flags
);
1248 dump_decl (pp
, ctx
, flags
);
1249 pp_cxx_colon_colon (pp
);
1251 dump_decl (pp
, OVL_NAME (t
), flags
);
1255 /* If there's only one function, just treat it like an ordinary
1261 if (! DECL_LANG_SPECIFIC (t
))
1263 if (DECL_ABSTRACT_ORIGIN (t
)
1264 && DECL_ABSTRACT_ORIGIN (t
) != t
)
1265 dump_decl (pp
, DECL_ABSTRACT_ORIGIN (t
), flags
);
1267 dump_function_name (pp
, t
, flags
);
1269 else if (DECL_GLOBAL_CTOR_P (t
) || DECL_GLOBAL_DTOR_P (t
))
1270 dump_global_iord (pp
, t
);
1272 dump_function_decl (pp
, t
, flags
);
1276 dump_template_decl (pp
, t
, flags
);
1279 case TEMPLATE_ID_EXPR
:
1281 tree name
= TREE_OPERAND (t
, 0);
1282 tree args
= TREE_OPERAND (t
, 1);
1284 if (!identifier_p (name
))
1285 name
= OVL_NAME (name
);
1286 dump_decl (pp
, name
, flags
);
1287 pp_cxx_begin_template_argument_list (pp
);
1288 if (args
== error_mark_node
)
1289 pp_string (pp
, M_("<template arguments error>"));
1291 dump_template_argument_list
1292 (pp
, args
, flags
|TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS
);
1293 pp_cxx_end_template_argument_list (pp
);
1298 pp_cxx_tree_identifier (pp
, DECL_NAME (t
));
1302 if ((TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == ENUMERAL_TYPE
)
1303 || (DECL_INITIAL (t
) &&
1304 TREE_CODE (DECL_INITIAL (t
)) == TEMPLATE_PARM_INDEX
))
1305 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1306 else if (DECL_NAME (t
))
1307 dump_decl (pp
, DECL_NAME (t
), flags
);
1308 else if (DECL_INITIAL (t
))
1309 dump_expr (pp
, DECL_INITIAL (t
), flags
| TFF_EXPR_IN_PARENS
);
1311 pp_string (pp
, M_("<enumerator>"));
1316 pp_cxx_ws_string (pp
, "using");
1317 tree scope
= USING_DECL_SCOPE (t
);
1318 bool variadic
= false;
1319 if (PACK_EXPANSION_P (scope
))
1321 scope
= PACK_EXPANSION_PATTERN (scope
);
1324 dump_type (pp
, scope
, flags
);
1325 pp_cxx_colon_colon (pp
);
1326 dump_decl (pp
, DECL_NAME (t
), flags
);
1328 pp_cxx_ws_string (pp
, "...");
1333 pp
->declaration (t
);
1337 dump_decl (pp
, BASELINK_FUNCTIONS (t
), flags
);
1340 case NON_DEPENDENT_EXPR
:
1341 dump_expr (pp
, t
, flags
);
1344 case TEMPLATE_TYPE_PARM
:
1345 if (flags
& TFF_DECL_SPECIFIERS
)
1346 pp
->declaration (t
);
1351 case UNBOUND_CLASS_TEMPLATE
:
1352 case TYPE_PACK_EXPANSION
:
1354 dump_type (pp
, t
, flags
);
1358 pp_unsupported_tree (pp
, t
);
1362 pp_string (pp
, M_("<declaration error>"));
1367 /* Dump a template declaration T under control of FLAGS. This means the
1368 'template <...> leaders plus the 'class X' or 'void fn(...)' part. */
1371 dump_template_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
1373 tree orig_parms
= DECL_TEMPLATE_PARMS (t
);
1377 if (flags
& TFF_TEMPLATE_HEADER
)
1379 for (parms
= orig_parms
= nreverse (orig_parms
);
1381 parms
= TREE_CHAIN (parms
))
1383 tree inner_parms
= INNERMOST_TEMPLATE_PARMS (parms
);
1384 int len
= TREE_VEC_LENGTH (inner_parms
);
1388 /* Skip over the dummy template levels of a template template
1390 gcc_assert (TREE_CODE (TREE_TYPE (t
)) == TEMPLATE_TEMPLATE_PARM
);
1394 pp_cxx_ws_string (pp
, "template");
1395 pp_cxx_begin_template_argument_list (pp
);
1397 /* If we've shown the template prefix, we'd better show the
1398 parameters' and decl's type too. */
1399 flags
|= TFF_DECL_SPECIFIERS
;
1401 for (i
= 0; i
< len
; i
++)
1404 pp_separate_with_comma (pp
);
1405 dump_template_parameter (pp
, TREE_VEC_ELT (inner_parms
, i
),
1408 pp_cxx_end_template_argument_list (pp
);
1409 pp_cxx_whitespace (pp
);
1411 nreverse(orig_parms
);
1413 if (DECL_TEMPLATE_TEMPLATE_PARM_P (t
))
1415 /* Say `template<arg> class TT' not just `template<arg> TT'. */
1416 pp_cxx_ws_string (pp
, "class");
1418 /* If this is a parameter pack, print the ellipsis. */
1419 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t
)))
1420 pp_cxx_ws_string (pp
, "...");
1423 /* Only print the requirements if we're also printing
1424 the template header. */
1426 if (tree ci
= get_constraints (t
))
1427 if (check_constraint_info (ci
))
1428 if (tree reqs
= CI_TEMPLATE_REQS (ci
))
1430 pp_cxx_requires_clause (pp
, reqs
);
1431 pp_cxx_whitespace (pp
);
1436 if (DECL_CLASS_TEMPLATE_P (t
))
1437 dump_type (pp
, TREE_TYPE (t
),
1438 ((flags
& ~TFF_CLASS_KEY_OR_ENUM
) | TFF_TEMPLATE_NAME
1439 | (flags
& TFF_DECL_SPECIFIERS
? TFF_CLASS_KEY_OR_ENUM
: 0)));
1440 else if (DECL_TEMPLATE_RESULT (t
)
1441 && (VAR_P (DECL_TEMPLATE_RESULT (t
))
1442 /* Alias template. */
1443 || DECL_TYPE_TEMPLATE_P (t
)))
1444 dump_decl (pp
, DECL_TEMPLATE_RESULT (t
), flags
| TFF_TEMPLATE_NAME
);
1447 gcc_assert (TREE_TYPE (t
));
1448 switch (NEXT_CODE (t
))
1452 dump_function_decl (pp
, t
, flags
| TFF_TEMPLATE_NAME
);
1455 /* This case can occur with some invalid code. */
1456 dump_type (pp
, TREE_TYPE (t
),
1457 (flags
& ~TFF_CLASS_KEY_OR_ENUM
) | TFF_TEMPLATE_NAME
1458 | (flags
& TFF_DECL_SPECIFIERS
1459 ? TFF_CLASS_KEY_OR_ENUM
: 0));
1464 /* find_typenames looks through the type of the function template T
1465 and returns a vec containing any typedefs, decltypes or TYPENAME_TYPEs
1468 struct find_typenames_t
1470 hash_set
<tree
> *p_set
;
1471 vec
<tree
, va_gc
> *typenames
;
1475 find_typenames_r (tree
*tp
, int *walk_subtrees
, void *data
)
1477 struct find_typenames_t
*d
= (struct find_typenames_t
*)data
;
1478 tree mv
= NULL_TREE
;
1480 if (TYPE_P (*tp
) && is_typedef_decl (TYPE_NAME (*tp
)))
1481 /* Add the type of the typedef without any additional cv-quals. */
1482 mv
= TREE_TYPE (TYPE_NAME (*tp
));
1483 else if (TREE_CODE (*tp
) == TYPENAME_TYPE
1484 || TREE_CODE (*tp
) == DECLTYPE_TYPE
)
1485 /* Add the typename without any cv-qualifiers. */
1486 mv
= TYPE_MAIN_VARIANT (*tp
);
1488 if (PACK_EXPANSION_P (*tp
))
1490 /* Don't mess with parameter packs since we don't remember
1491 the pack expansion context for a particular typename. */
1492 *walk_subtrees
= false;
1496 if (mv
&& (mv
== *tp
|| !d
->p_set
->add (mv
)))
1497 vec_safe_push (d
->typenames
, mv
);
1499 /* Search into class template arguments, which cp_walk_subtrees
1501 if (CLASS_TYPE_P (*tp
) && CLASSTYPE_TEMPLATE_INFO (*tp
))
1502 cp_walk_tree (&CLASSTYPE_TI_ARGS (*tp
), find_typenames_r
,
1508 static vec
<tree
, va_gc
> *
1509 find_typenames (tree t
)
1511 struct find_typenames_t ft
;
1512 ft
.p_set
= new hash_set
<tree
>;
1513 ft
.typenames
= NULL
;
1514 cp_walk_tree (&TREE_TYPE (DECL_TEMPLATE_RESULT (t
)),
1515 find_typenames_r
, &ft
, ft
.p_set
);
1517 return ft
.typenames
;
1520 /* Output the "[with ...]" clause for a template instantiation T iff
1521 TEMPLATE_PARMS, TEMPLATE_ARGS and FLAGS are suitable. T may be NULL if
1522 formatting a deduction/substitution diagnostic rather than an
1526 dump_substitution (cxx_pretty_printer
*pp
,
1527 tree t
, tree template_parms
, tree template_args
,
1530 if (template_parms
!= NULL_TREE
&& template_args
!= NULL_TREE
1531 && !(flags
& TFF_NO_TEMPLATE_BINDINGS
))
1533 vec
<tree
, va_gc
> *typenames
= t
? find_typenames (t
) : NULL
;
1534 pp_cxx_whitespace (pp
);
1535 pp_cxx_left_bracket (pp
);
1536 pp
->translate_string ("with");
1537 pp_cxx_whitespace (pp
);
1538 dump_template_bindings (pp
, template_parms
, template_args
, typenames
);
1539 pp_cxx_right_bracket (pp
);
1543 /* Dump the lambda function FN including its 'mutable' qualifier and any
1544 template bindings. */
1547 dump_lambda_function (cxx_pretty_printer
*pp
,
1548 tree fn
, tree template_parms
, tree template_args
,
1551 /* A lambda's signature is essentially its "type". */
1552 dump_type (pp
, DECL_CONTEXT (fn
), flags
);
1553 if (!(TYPE_QUALS (class_of_this_parm (TREE_TYPE (fn
))) & TYPE_QUAL_CONST
))
1555 pp
->padding
= pp_before
;
1556 pp_c_ws_string (pp
, "mutable");
1558 dump_substitution (pp
, fn
, template_parms
, template_args
, flags
);
1561 /* Pretty print a function decl. There are several ways we want to print a
1562 function declaration. The TFF_ bits in FLAGS tells us how to behave.
1563 As error can only apply the '#' flag once to give 0 and 1 for V, there
1564 is %D which doesn't print the throw specs, and %F which does. */
1567 dump_function_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
1571 tree cname
= NULL_TREE
;
1572 tree template_args
= NULL_TREE
;
1573 tree template_parms
= NULL_TREE
;
1574 int show_return
= flags
& TFF_RETURN_TYPE
|| flags
& TFF_DECL_SPECIFIERS
;
1575 int do_outer_scope
= ! (flags
& TFF_UNQUALIFIED_NAME
);
1578 tree ret
= NULL_TREE
;
1580 flags
&= ~(TFF_UNQUALIFIED_NAME
| TFF_TEMPLATE_NAME
);
1581 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1582 t
= DECL_TEMPLATE_RESULT (t
);
1584 /* Save the exceptions, in case t is a specialization and we are
1585 emitting an error about incompatible specifications. */
1586 exceptions
= TYPE_RAISES_EXCEPTIONS (TREE_TYPE (t
));
1588 /* Likewise for the constexpr specifier, in case t is a specialization. */
1589 constexpr_p
= DECL_DECLARED_CONSTEXPR_P (t
);
1591 /* Pretty print template instantiations only. */
1592 if (DECL_USE_TEMPLATE (t
) && DECL_TEMPLATE_INFO (t
)
1593 && !(flags
& TFF_NO_TEMPLATE_BINDINGS
)
1594 && flag_pretty_templates
)
1598 template_args
= DECL_TI_ARGS (t
);
1599 tmpl
= most_general_template (t
);
1600 if (tmpl
&& TREE_CODE (tmpl
) == TEMPLATE_DECL
)
1602 template_parms
= DECL_TEMPLATE_PARMS (tmpl
);
1607 if (DECL_NAME (t
) && LAMBDA_FUNCTION_P (t
))
1608 return dump_lambda_function (pp
, t
, template_parms
, template_args
, flags
);
1610 fntype
= TREE_TYPE (t
);
1611 parmtypes
= FUNCTION_FIRST_USER_PARMTYPE (t
);
1613 if (DECL_CLASS_SCOPE_P (t
))
1614 cname
= DECL_CONTEXT (t
);
1615 /* This is for partially instantiated template methods. */
1616 else if (TREE_CODE (fntype
) == METHOD_TYPE
)
1617 cname
= TREE_TYPE (TREE_VALUE (parmtypes
));
1619 if (flags
& TFF_DECL_SPECIFIERS
)
1621 if (DECL_STATIC_FUNCTION_P (t
))
1622 pp_cxx_ws_string (pp
, "static");
1623 else if (DECL_VIRTUAL_P (t
))
1624 pp_cxx_ws_string (pp
, "virtual");
1628 if (DECL_DECLARED_CONCEPT_P (t
))
1629 pp_cxx_ws_string (pp
, "concept");
1631 pp_cxx_ws_string (pp
, "constexpr");
1635 /* Print the return type? */
1637 show_return
= (!DECL_CONV_FN_P (t
) && !DECL_CONSTRUCTOR_P (t
)
1638 && !DECL_DESTRUCTOR_P (t
) && !deduction_guide_p (t
));
1641 ret
= fndecl_declared_return_type (t
);
1642 dump_type_prefix (pp
, ret
, flags
);
1645 /* Print the function name. */
1646 if (!do_outer_scope
)
1650 dump_type (pp
, cname
, flags
);
1651 pp_cxx_colon_colon (pp
);
1654 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1656 dump_function_name (pp
, t
, flags
);
1658 if (!(flags
& TFF_NO_FUNCTION_ARGUMENTS
))
1660 dump_parameters (pp
, parmtypes
, flags
);
1662 if (TREE_CODE (fntype
) == METHOD_TYPE
)
1664 pp
->padding
= pp_before
;
1665 pp_cxx_cv_qualifier_seq (pp
, class_of_this_parm (fntype
));
1666 dump_ref_qualifier (pp
, fntype
, flags
);
1669 if (tx_safe_fn_type_p (fntype
))
1671 pp
->padding
= pp_before
;
1672 pp_cxx_ws_string (pp
, "transaction_safe");
1675 if (flags
& TFF_EXCEPTION_SPECIFICATION
)
1677 pp
->padding
= pp_before
;
1678 dump_exception_spec (pp
, exceptions
, flags
);
1682 dump_type_suffix (pp
, ret
, flags
);
1683 else if (deduction_guide_p (t
))
1685 pp_cxx_ws_string (pp
, "->");
1686 dump_type (pp
, TREE_TYPE (TREE_TYPE (t
)), flags
);
1690 if (tree ci
= get_constraints (t
))
1691 if (tree reqs
= CI_DECLARATOR_REQS (ci
))
1692 pp_cxx_requires_clause (pp
, reqs
);
1694 dump_substitution (pp
, t
, template_parms
, template_args
, flags
);
1696 if (tree base
= DECL_INHERITED_CTOR_BASE (t
))
1698 pp_cxx_ws_string (pp
, "[inherited from");
1699 dump_type (pp
, base
, TFF_PLAIN_IDENTIFIER
);
1700 pp_character (pp
, ']');
1703 else if (template_args
)
1705 bool need_comma
= false;
1707 pp_cxx_begin_template_argument_list (pp
);
1708 template_args
= INNERMOST_TEMPLATE_ARGS (template_args
);
1709 for (i
= 0; i
< TREE_VEC_LENGTH (template_args
); ++i
)
1711 tree arg
= TREE_VEC_ELT (template_args
, i
);
1713 pp_separate_with_comma (pp
);
1714 if (ARGUMENT_PACK_P (arg
))
1715 pp_cxx_left_brace (pp
);
1716 dump_template_argument (pp
, arg
, TFF_PLAIN_IDENTIFIER
);
1717 if (ARGUMENT_PACK_P (arg
))
1718 pp_cxx_right_brace (pp
);
1721 pp_cxx_end_template_argument_list (pp
);
1725 /* Print a parameter list. If this is for a member function, the
1726 member object ptr (and any other hidden args) should have
1727 already been removed. */
1730 dump_parameters (cxx_pretty_printer
*pp
, tree parmtypes
, int flags
)
1733 flags
&= ~TFF_SCOPE
;
1734 pp_cxx_left_paren (pp
);
1736 for (first
= 1; parmtypes
!= void_list_node
;
1737 parmtypes
= TREE_CHAIN (parmtypes
))
1740 pp_separate_with_comma (pp
);
1744 pp_cxx_ws_string (pp
, "...");
1748 dump_type (pp
, TREE_VALUE (parmtypes
), flags
);
1750 if ((flags
& TFF_FUNCTION_DEFAULT_ARGUMENTS
) && TREE_PURPOSE (parmtypes
))
1752 pp_cxx_whitespace (pp
);
1754 pp_cxx_whitespace (pp
);
1755 dump_expr (pp
, TREE_PURPOSE (parmtypes
), flags
| TFF_EXPR_IN_PARENS
);
1759 pp_cxx_right_paren (pp
);
1762 /* Print ref-qualifier of a FUNCTION_TYPE or METHOD_TYPE. FLAGS are ignored. */
1765 dump_ref_qualifier (cxx_pretty_printer
*pp
, tree t
, int flags ATTRIBUTE_UNUSED
)
1767 if (FUNCTION_REF_QUALIFIED (t
))
1769 pp
->padding
= pp_before
;
1770 if (FUNCTION_RVALUE_QUALIFIED (t
))
1771 pp_cxx_ws_string (pp
, "&&");
1773 pp_cxx_ws_string (pp
, "&");
1777 /* Print an exception specification. T is the exception specification. */
1780 dump_exception_spec (cxx_pretty_printer
*pp
, tree t
, int flags
)
1782 if (t
&& TREE_PURPOSE (t
))
1784 pp_cxx_ws_string (pp
, "noexcept");
1785 if (!integer_onep (TREE_PURPOSE (t
)))
1787 pp_cxx_whitespace (pp
);
1788 pp_cxx_left_paren (pp
);
1789 if (DEFERRED_NOEXCEPT_SPEC_P (t
))
1790 pp_cxx_ws_string (pp
, "<uninstantiated>");
1792 dump_expr (pp
, TREE_PURPOSE (t
), flags
);
1793 pp_cxx_right_paren (pp
);
1798 pp_cxx_ws_string (pp
, "throw");
1799 pp_cxx_whitespace (pp
);
1800 pp_cxx_left_paren (pp
);
1801 if (TREE_VALUE (t
) != NULL_TREE
)
1804 dump_type (pp
, TREE_VALUE (t
), flags
);
1808 pp_separate_with_comma (pp
);
1810 pp_cxx_right_paren (pp
);
1814 /* Handle the function name for a FUNCTION_DECL node, grokking operators
1815 and destructors properly. */
1818 dump_function_name (cxx_pretty_printer
*pp
, tree t
, int flags
)
1820 tree name
= DECL_NAME (t
);
1822 /* We can get here with a decl that was synthesized by language-
1823 independent machinery (e.g. coverage.c) in which case it won't
1824 have a lang_specific structure attached and DECL_CONSTRUCTOR_P
1825 will crash. In this case it is safe just to print out the
1827 if (!DECL_LANG_SPECIFIC (t
))
1829 pp_cxx_tree_identifier (pp
, name
);
1833 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1834 t
= DECL_TEMPLATE_RESULT (t
);
1836 /* Don't let the user see __comp_ctor et al. */
1837 if (DECL_CONSTRUCTOR_P (t
)
1838 || DECL_DESTRUCTOR_P (t
))
1840 if (LAMBDA_TYPE_P (DECL_CONTEXT (t
)))
1841 name
= get_identifier ("<lambda>");
1842 else if (TYPE_UNNAMED_P (DECL_CONTEXT (t
)))
1843 name
= get_identifier ("<constructor>");
1845 name
= constructor_name (DECL_CONTEXT (t
));
1848 if (DECL_DESTRUCTOR_P (t
))
1850 pp_cxx_complement (pp
);
1851 dump_decl (pp
, name
, TFF_PLAIN_IDENTIFIER
);
1853 else if (DECL_CONV_FN_P (t
))
1855 /* This cannot use the hack that the operator's return
1856 type is stashed off of its name because it may be
1857 used for error reporting. In the case of conflicting
1858 declarations, both will have the same name, yet
1859 the types will be different, hence the TREE_TYPE field
1860 of the first name will be clobbered by the second. */
1861 pp_cxx_ws_string (pp
, "operator");
1862 dump_type (pp
, TREE_TYPE (TREE_TYPE (t
)), flags
);
1865 dump_decl (pp
, name
, flags
);
1867 if (DECL_TEMPLATE_INFO (t
)
1868 && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t
)
1869 && (TREE_CODE (DECL_TI_TEMPLATE (t
)) != TEMPLATE_DECL
1870 || PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t
))))
1871 dump_template_parms (pp
, DECL_TEMPLATE_INFO (t
), !DECL_USE_TEMPLATE (t
),
1875 /* Dump the template parameters from the template info INFO under control of
1876 FLAGS. PRIMARY indicates whether this is a primary template decl, or
1877 specialization (partial or complete). For partial specializations we show
1878 the specialized parameter values. For a primary template we show no
1882 dump_template_parms (cxx_pretty_printer
*pp
, tree info
,
1883 int primary
, int flags
)
1885 tree args
= info
? TI_ARGS (info
) : NULL_TREE
;
1887 if (primary
&& flags
& TFF_TEMPLATE_NAME
)
1889 flags
&= ~(TFF_CLASS_KEY_OR_ENUM
| TFF_TEMPLATE_NAME
);
1890 pp_cxx_begin_template_argument_list (pp
);
1892 /* Be careful only to print things when we have them, so as not
1893 to crash producing error messages. */
1894 if (args
&& !primary
)
1897 len
= get_non_default_template_args_count (args
, flags
);
1899 args
= INNERMOST_TEMPLATE_ARGS (args
);
1900 for (ix
= 0; ix
!= len
; ix
++)
1902 tree arg
= TREE_VEC_ELT (args
, ix
);
1904 /* Only print a comma if we know there is an argument coming. In
1905 the case of an empty template argument pack, no actual
1906 argument will be printed. */
1908 && (!ARGUMENT_PACK_P (arg
)
1909 || TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg
)) > 0))
1910 pp_separate_with_comma (pp
);
1913 pp_string (pp
, M_("<template parameter error>"));
1915 dump_template_argument (pp
, arg
, flags
);
1920 tree tpl
= TI_TEMPLATE (info
);
1921 tree parms
= DECL_TEMPLATE_PARMS (tpl
);
1924 parms
= TREE_CODE (parms
) == TREE_LIST
? TREE_VALUE (parms
) : NULL_TREE
;
1925 len
= parms
? TREE_VEC_LENGTH (parms
) : 0;
1927 for (ix
= 0; ix
!= len
; ix
++)
1931 if (TREE_VEC_ELT (parms
, ix
) == error_mark_node
)
1933 pp_string (pp
, M_("<template parameter error>"));
1937 parm
= TREE_VALUE (TREE_VEC_ELT (parms
, ix
));
1940 pp_separate_with_comma (pp
);
1942 dump_decl (pp
, parm
, flags
& ~TFF_DECL_SPECIFIERS
);
1945 pp_cxx_end_template_argument_list (pp
);
1948 /* Print out the arguments of CALL_EXPR T as a parenthesized list using
1949 flags FLAGS. Skip over the first argument if SKIPFIRST is true. */
1952 dump_call_expr_args (cxx_pretty_printer
*pp
, tree t
, int flags
, bool skipfirst
)
1955 call_expr_arg_iterator iter
;
1957 pp_cxx_left_paren (pp
);
1958 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, t
)
1964 dump_expr (pp
, arg
, flags
| TFF_EXPR_IN_PARENS
);
1965 if (more_call_expr_args_p (&iter
))
1966 pp_separate_with_comma (pp
);
1969 pp_cxx_right_paren (pp
);
1972 /* Print out the arguments of AGGR_INIT_EXPR T as a parenthesized list
1973 using flags FLAGS. Skip over the first argument if SKIPFIRST is
1977 dump_aggr_init_expr_args (cxx_pretty_printer
*pp
, tree t
, int flags
,
1981 aggr_init_expr_arg_iterator iter
;
1983 pp_cxx_left_paren (pp
);
1984 FOR_EACH_AGGR_INIT_EXPR_ARG (arg
, iter
, t
)
1990 dump_expr (pp
, arg
, flags
| TFF_EXPR_IN_PARENS
);
1991 if (more_aggr_init_expr_args_p (&iter
))
1992 pp_separate_with_comma (pp
);
1995 pp_cxx_right_paren (pp
);
1998 /* Print out a list of initializers (subr of dump_expr). */
2001 dump_expr_list (cxx_pretty_printer
*pp
, tree l
, int flags
)
2005 dump_expr (pp
, TREE_VALUE (l
), flags
| TFF_EXPR_IN_PARENS
);
2008 pp_separate_with_comma (pp
);
2012 /* Print out a vector of initializers (subr of dump_expr). */
2015 dump_expr_init_vec (cxx_pretty_printer
*pp
, vec
<constructor_elt
, va_gc
> *v
,
2018 unsigned HOST_WIDE_INT idx
;
2021 FOR_EACH_CONSTRUCTOR_VALUE (v
, idx
, value
)
2023 dump_expr (pp
, value
, flags
| TFF_EXPR_IN_PARENS
);
2024 if (idx
!= v
->length () - 1)
2025 pp_separate_with_comma (pp
);
2030 /* We've gotten an indirect REFERENCE (an OBJ_TYPE_REF) to a virtual
2031 function. Resolve it to a close relative -- in the sense of static
2032 type -- variant being overridden. That is close to what was written in
2033 the source code. Subroutine of dump_expr. */
2036 resolve_virtual_fun_from_obj_type_ref (tree ref
)
2038 tree obj_type
= TREE_TYPE (OBJ_TYPE_REF_OBJECT (ref
));
2039 HOST_WIDE_INT index
= tree_to_uhwi (OBJ_TYPE_REF_TOKEN (ref
));
2040 tree fun
= BINFO_VIRTUALS (TYPE_BINFO (TREE_TYPE (obj_type
)));
2043 fun
= TREE_CHAIN (fun
);
2044 index
-= (TARGET_VTABLE_USES_DESCRIPTORS
2045 ? TARGET_VTABLE_USES_DESCRIPTORS
: 1);
2051 /* Print out an expression E under control of FLAGS. */
2054 dump_expr (cxx_pretty_printer
*pp
, tree t
, int flags
)
2061 if (STATEMENT_CLASS_P (t
))
2063 pp_cxx_ws_string (pp
, M_("<statement>"));
2067 switch (TREE_CODE (t
))
2075 case NAMESPACE_DECL
:
2079 case IDENTIFIER_NODE
:
2080 dump_decl (pp
, t
, ((flags
& ~(TFF_DECL_SPECIFIERS
|TFF_RETURN_TYPE
2081 |TFF_TEMPLATE_HEADER
))
2082 | TFF_NO_TEMPLATE_BINDINGS
2083 | TFF_NO_FUNCTION_ARGUMENTS
));
2087 if (SSA_NAME_VAR (t
)
2088 && !DECL_ARTIFICIAL (SSA_NAME_VAR (t
)))
2089 dump_expr (pp
, SSA_NAME_VAR (t
), flags
);
2091 pp_cxx_ws_string (pp
, M_("<unknown>"));
2102 case USERDEF_LITERAL
:
2103 pp_cxx_userdef_literal (pp
, t
);
2107 /* While waiting for caret diagnostics, avoid printing
2108 __cxa_allocate_exception, __cxa_throw, and the like. */
2109 pp_cxx_ws_string (pp
, M_("<throw-expression>"));
2114 dump_type (pp
, PTRMEM_CST_CLASS (t
), flags
);
2115 pp_cxx_colon_colon (pp
);
2116 pp_cxx_tree_identifier (pp
, DECL_NAME (PTRMEM_CST_MEMBER (t
)));
2120 pp_cxx_left_paren (pp
);
2121 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2122 pp_separate_with_comma (pp
);
2123 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2124 pp_cxx_right_paren (pp
);
2129 pp_cxx_left_paren (pp
);
2130 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2131 pp_string (pp
, " ? ");
2132 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2133 pp_string (pp
, " : ");
2134 dump_expr (pp
, TREE_OPERAND (t
, 2), flags
| TFF_EXPR_IN_PARENS
);
2135 pp_cxx_right_paren (pp
);
2139 if (TREE_HAS_CONSTRUCTOR (t
))
2141 pp_cxx_ws_string (pp
, "new");
2142 pp_cxx_whitespace (pp
);
2143 dump_type (pp
, TREE_TYPE (TREE_TYPE (t
)), flags
);
2146 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2149 case AGGR_INIT_EXPR
:
2151 tree fn
= NULL_TREE
;
2153 if (TREE_CODE (AGGR_INIT_EXPR_FN (t
)) == ADDR_EXPR
)
2154 fn
= TREE_OPERAND (AGGR_INIT_EXPR_FN (t
), 0);
2156 if (fn
&& TREE_CODE (fn
) == FUNCTION_DECL
)
2158 if (DECL_CONSTRUCTOR_P (fn
))
2159 dump_type (pp
, DECL_CONTEXT (fn
), flags
);
2161 dump_decl (pp
, fn
, 0);
2164 dump_expr (pp
, AGGR_INIT_EXPR_FN (t
), 0);
2166 dump_aggr_init_expr_args (pp
, t
, flags
, true);
2171 tree fn
= CALL_EXPR_FN (t
);
2172 bool skipfirst
= false;
2174 /* Deal with internal functions. */
2175 if (fn
== NULL_TREE
)
2177 pp_string (pp
, internal_fn_name (CALL_EXPR_IFN (t
)));
2178 dump_call_expr_args (pp
, t
, flags
, skipfirst
);
2182 if (TREE_CODE (fn
) == ADDR_EXPR
)
2183 fn
= TREE_OPERAND (fn
, 0);
2185 /* Nobody is interested in seeing the guts of vcalls. */
2186 if (TREE_CODE (fn
) == OBJ_TYPE_REF
)
2187 fn
= resolve_virtual_fun_from_obj_type_ref (fn
);
2189 if (TREE_TYPE (fn
) != NULL_TREE
2190 && NEXT_CODE (fn
) == METHOD_TYPE
2191 && call_expr_nargs (t
))
2193 tree ob
= CALL_EXPR_ARG (t
, 0);
2194 if (TREE_CODE (ob
) == ADDR_EXPR
)
2196 dump_expr (pp
, TREE_OPERAND (ob
, 0),
2197 flags
| TFF_EXPR_IN_PARENS
);
2200 else if (!is_this_parameter (ob
))
2202 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2207 if (flag_sanitize
& SANITIZE_UNDEFINED
2208 && is_ubsan_builtin_p (fn
))
2210 pp_string (cxx_pp
, M_("<ubsan routine call>"));
2213 dump_expr (pp
, fn
, flags
| TFF_EXPR_IN_PARENS
);
2214 dump_call_expr_args (pp
, t
, flags
, skipfirst
);
2219 /* Note that this only works for G++ target exprs. If somebody
2220 builds a general TARGET_EXPR, there's no way to represent that
2221 it initializes anything other that the parameter slot for the
2222 default argument. Note we may have cleared out the first
2223 operand in expand_expr, so don't go killing ourselves. */
2224 if (TREE_OPERAND (t
, 1))
2225 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2228 case POINTER_PLUS_EXPR
:
2229 dump_binary_op (pp
, "+", t
, flags
);
2232 case POINTER_DIFF_EXPR
:
2233 dump_binary_op (pp
, "-", t
, flags
);
2238 dump_binary_op (pp
, OVL_OP_INFO (true, NOP_EXPR
)->name
, t
, flags
);
2244 case TRUNC_DIV_EXPR
:
2245 case TRUNC_MOD_EXPR
:
2253 case TRUTH_ANDIF_EXPR
:
2254 case TRUTH_ORIF_EXPR
:
2261 case EXACT_DIV_EXPR
:
2262 dump_binary_op (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
, t
, flags
);
2266 case FLOOR_DIV_EXPR
:
2267 case ROUND_DIV_EXPR
:
2269 dump_binary_op (pp
, "/", t
, flags
);
2273 case FLOOR_MOD_EXPR
:
2274 case ROUND_MOD_EXPR
:
2275 dump_binary_op (pp
, "%", t
, flags
);
2280 tree ob
= TREE_OPERAND (t
, 0);
2281 if (INDIRECT_REF_P (ob
))
2283 ob
= TREE_OPERAND (ob
, 0);
2284 if (!is_this_parameter (ob
))
2286 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2287 if (TYPE_REF_P (TREE_TYPE (ob
)))
2295 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2296 if (TREE_CODE (ob
) != ARROW_EXPR
)
2299 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
& ~TFF_EXPR_IN_PARENS
);
2304 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2305 pp_cxx_left_bracket (pp
);
2306 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2307 pp_cxx_right_bracket (pp
);
2310 case UNARY_PLUS_EXPR
:
2311 dump_unary_op (pp
, "+", t
, flags
);
2315 if (TREE_CODE (TREE_OPERAND (t
, 0)) == FUNCTION_DECL
2316 || TREE_CODE (TREE_OPERAND (t
, 0)) == STRING_CST
2317 /* An ADDR_EXPR can have reference type. In that case, we
2318 shouldn't print the `&' doing so indicates to the user
2319 that the expression has pointer type. */
2321 && TYPE_REF_P (TREE_TYPE (t
))))
2322 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2323 else if (TREE_CODE (TREE_OPERAND (t
, 0)) == LABEL_DECL
)
2324 dump_unary_op (pp
, "&&", t
, flags
);
2326 dump_unary_op (pp
, "&", t
, flags
);
2330 if (TREE_HAS_CONSTRUCTOR (t
))
2332 t
= TREE_OPERAND (t
, 0);
2333 gcc_assert (TREE_CODE (t
) == CALL_EXPR
);
2334 dump_expr (pp
, CALL_EXPR_FN (t
), flags
| TFF_EXPR_IN_PARENS
);
2335 dump_call_expr_args (pp
, t
, flags
, true);
2339 if (TREE_OPERAND (t
,0) != NULL_TREE
2340 && TREE_TYPE (TREE_OPERAND (t
, 0))
2341 && NEXT_CODE (TREE_OPERAND (t
, 0)) == REFERENCE_TYPE
)
2342 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2344 dump_unary_op (pp
, "*", t
, flags
);
2349 if (TREE_CODE (TREE_OPERAND (t
, 0)) == ADDR_EXPR
2350 && integer_zerop (TREE_OPERAND (t
, 1)))
2351 dump_expr (pp
, TREE_OPERAND (TREE_OPERAND (t
, 0), 0), flags
);
2355 if (!integer_zerop (TREE_OPERAND (t
, 1)))
2357 pp_cxx_left_paren (pp
);
2358 if (!integer_onep (TYPE_SIZE_UNIT
2359 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (t
, 0))))))
2361 pp_cxx_left_paren (pp
);
2362 dump_type (pp
, ptr_type_node
, flags
);
2363 pp_cxx_right_paren (pp
);
2366 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2367 if (!integer_zerop (TREE_OPERAND (t
, 1)))
2369 pp_cxx_ws_string (pp
, "+");
2370 dump_expr (pp
, fold_convert (ssizetype
, TREE_OPERAND (t
, 1)),
2372 pp_cxx_right_paren (pp
);
2379 case TRUTH_NOT_EXPR
:
2380 case PREDECREMENT_EXPR
:
2381 case PREINCREMENT_EXPR
:
2382 dump_unary_op (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
, t
, flags
);
2385 case POSTDECREMENT_EXPR
:
2386 case POSTINCREMENT_EXPR
:
2387 pp_cxx_left_paren (pp
);
2388 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2389 pp_cxx_ws_string (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
);
2390 pp_cxx_right_paren (pp
);
2393 case NON_LVALUE_EXPR
:
2394 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
2395 should be another level of INDIRECT_REF so that I don't have to do
2397 if (TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == POINTER_TYPE
)
2399 tree next
= TREE_TYPE (TREE_TYPE (t
));
2401 while (TYPE_PTR_P (next
))
2402 next
= TREE_TYPE (next
);
2404 if (TREE_CODE (next
) == FUNCTION_TYPE
)
2406 if (flags
& TFF_EXPR_IN_PARENS
)
2407 pp_cxx_left_paren (pp
);
2409 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2410 if (flags
& TFF_EXPR_IN_PARENS
)
2411 pp_cxx_right_paren (pp
);
2414 /* Else fall through. */
2416 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2420 case IMPLICIT_CONV_EXPR
:
2421 case VIEW_CONVERT_EXPR
:
2423 tree op
= TREE_OPERAND (t
, 0);
2424 tree ttype
= TREE_TYPE (t
);
2425 tree optype
= TREE_TYPE (op
);
2427 if (TREE_CODE (ttype
) != TREE_CODE (optype
)
2428 && INDIRECT_TYPE_P (ttype
)
2429 && INDIRECT_TYPE_P (optype
)
2430 && same_type_p (TREE_TYPE (optype
),
2433 if (TYPE_REF_P (ttype
))
2436 if (TREE_CODE (op
) == ADDR_EXPR
)
2437 dump_expr (pp
, TREE_OPERAND (op
, 0), flags
);
2439 dump_unary_op (pp
, "*", t
, flags
);
2442 dump_unary_op (pp
, "&", t
, flags
);
2444 else if (!same_type_p (TREE_TYPE (op
), TREE_TYPE (t
)))
2446 /* It is a cast, but we cannot tell whether it is a
2447 reinterpret or static cast. Use the C style notation. */
2448 if (flags
& TFF_EXPR_IN_PARENS
)
2449 pp_cxx_left_paren (pp
);
2450 pp_cxx_left_paren (pp
);
2451 dump_type (pp
, TREE_TYPE (t
), flags
);
2452 pp_cxx_right_paren (pp
);
2453 dump_expr (pp
, op
, flags
| TFF_EXPR_IN_PARENS
);
2454 if (flags
& TFF_EXPR_IN_PARENS
)
2455 pp_cxx_right_paren (pp
);
2458 dump_expr (pp
, op
, flags
);
2463 if (TREE_TYPE (t
) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t
)))
2465 tree idx
= build_ptrmemfunc_access_expr (t
, pfn_identifier
);
2467 if (integer_zerop (idx
))
2469 /* A NULL pointer-to-member constant. */
2470 pp_cxx_left_paren (pp
);
2471 pp_cxx_left_paren (pp
);
2472 dump_type (pp
, TREE_TYPE (t
), flags
);
2473 pp_cxx_right_paren (pp
);
2474 pp_character (pp
, '0');
2475 pp_cxx_right_paren (pp
);
2478 else if (tree_fits_shwi_p (idx
))
2481 unsigned HOST_WIDE_INT n
;
2483 t
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t
)));
2484 t
= TYPE_METHOD_BASETYPE (t
);
2485 virtuals
= BINFO_VIRTUALS (TYPE_BINFO (TYPE_MAIN_VARIANT (t
)));
2487 n
= tree_to_shwi (idx
);
2489 /* Map vtable index back one, to allow for the null pointer to
2493 while (n
> 0 && virtuals
)
2496 virtuals
= TREE_CHAIN (virtuals
);
2500 dump_expr (pp
, BV_FN (virtuals
),
2501 flags
| TFF_EXPR_IN_PARENS
);
2506 if (TREE_TYPE (t
) && LAMBDA_TYPE_P (TREE_TYPE (t
)))
2507 pp_string (pp
, "<lambda closure object>");
2508 if (TREE_TYPE (t
) && EMPTY_CONSTRUCTOR_P (t
))
2510 dump_type (pp
, TREE_TYPE (t
), 0);
2511 pp_cxx_left_paren (pp
);
2512 pp_cxx_right_paren (pp
);
2516 if (!BRACE_ENCLOSED_INITIALIZER_P (t
))
2517 dump_type (pp
, TREE_TYPE (t
), 0);
2518 pp_cxx_left_brace (pp
);
2519 dump_expr_init_vec (pp
, CONSTRUCTOR_ELTS (t
), flags
);
2520 pp_cxx_right_brace (pp
);
2527 tree ob
= TREE_OPERAND (t
, 0);
2528 if (is_dummy_object (ob
))
2530 t
= TREE_OPERAND (t
, 1);
2531 if (TREE_CODE (t
) == FUNCTION_DECL
)
2533 dump_expr (pp
, t
, flags
| TFF_EXPR_IN_PARENS
);
2534 else if (BASELINK_P (t
))
2535 dump_expr (pp
, OVL_FIRST (BASELINK_FUNCTIONS (t
)),
2536 flags
| TFF_EXPR_IN_PARENS
);
2538 dump_decl (pp
, t
, flags
);
2542 if (INDIRECT_REF_P (ob
))
2544 dump_expr (pp
, TREE_OPERAND (ob
, 0), flags
| TFF_EXPR_IN_PARENS
);
2550 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2554 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2559 case TEMPLATE_PARM_INDEX
:
2560 dump_decl (pp
, TEMPLATE_PARM_DECL (t
), flags
& ~TFF_DECL_SPECIFIERS
);
2564 if (TREE_OPERAND (t
, 0) == NULL_TREE
2565 || TREE_CHAIN (TREE_OPERAND (t
, 0)))
2567 dump_type (pp
, TREE_TYPE (t
), flags
);
2568 pp_cxx_left_paren (pp
);
2569 dump_expr_list (pp
, TREE_OPERAND (t
, 0), flags
);
2570 pp_cxx_right_paren (pp
);
2574 pp_cxx_left_paren (pp
);
2575 dump_type (pp
, TREE_TYPE (t
), flags
);
2576 pp_cxx_right_paren (pp
);
2577 pp_cxx_left_paren (pp
);
2578 dump_expr_list (pp
, TREE_OPERAND (t
, 0), flags
);
2579 pp_cxx_right_paren (pp
);
2583 case STATIC_CAST_EXPR
:
2584 pp_cxx_ws_string (pp
, "static_cast");
2586 case REINTERPRET_CAST_EXPR
:
2587 pp_cxx_ws_string (pp
, "reinterpret_cast");
2589 case CONST_CAST_EXPR
:
2590 pp_cxx_ws_string (pp
, "const_cast");
2592 case DYNAMIC_CAST_EXPR
:
2593 pp_cxx_ws_string (pp
, "dynamic_cast");
2595 pp_cxx_begin_template_argument_list (pp
);
2596 dump_type (pp
, TREE_TYPE (t
), flags
);
2597 pp_cxx_end_template_argument_list (pp
);
2598 pp_cxx_left_paren (pp
);
2599 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2600 pp_cxx_right_paren (pp
);
2604 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2610 if (TREE_CODE (t
) == SIZEOF_EXPR
)
2611 pp_cxx_ws_string (pp
, "sizeof");
2614 gcc_assert (TREE_CODE (t
) == ALIGNOF_EXPR
);
2615 pp_cxx_ws_string (pp
, "__alignof__");
2617 op
= TREE_OPERAND (t
, 0);
2618 if (PACK_EXPANSION_P (op
))
2620 pp_string (pp
, "...");
2621 op
= PACK_EXPANSION_PATTERN (op
);
2623 pp_cxx_whitespace (pp
);
2624 pp_cxx_left_paren (pp
);
2625 if (TREE_CODE (t
) == SIZEOF_EXPR
&& SIZEOF_EXPR_TYPE_P (t
))
2626 dump_type (pp
, TREE_TYPE (op
), flags
);
2627 else if (TYPE_P (TREE_OPERAND (t
, 0)))
2628 dump_type (pp
, op
, flags
);
2630 dump_expr (pp
, op
, flags
);
2631 pp_cxx_right_paren (pp
);
2634 case AT_ENCODE_EXPR
:
2635 pp_cxx_ws_string (pp
, "@encode");
2636 pp_cxx_whitespace (pp
);
2637 pp_cxx_left_paren (pp
);
2638 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
2639 pp_cxx_right_paren (pp
);
2643 pp_cxx_ws_string (pp
, "noexcept");
2644 pp_cxx_whitespace (pp
);
2645 pp_cxx_left_paren (pp
);
2646 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2647 pp_cxx_right_paren (pp
);
2652 pp_cxx_ws_string (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
);
2653 pp_cxx_whitespace (pp
);
2654 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2658 pp_string (pp
, M_("<unparsed>"));
2661 case TRY_CATCH_EXPR
:
2662 case CLEANUP_POINT_EXPR
:
2663 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2666 case PSEUDO_DTOR_EXPR
:
2667 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2669 if (TREE_OPERAND (t
, 1))
2671 dump_type (pp
, TREE_OPERAND (t
, 1), flags
);
2672 pp_cxx_colon_colon (pp
);
2674 pp_cxx_complement (pp
);
2675 dump_type (pp
, TREE_OPERAND (t
, 2), flags
);
2678 case TEMPLATE_ID_EXPR
:
2679 dump_decl (pp
, t
, flags
);
2685 case STATEMENT_LIST
:
2686 /* We don't yet have a way of dumping statements in a
2687 human-readable format. */
2688 pp_string (pp
, "({...})");
2692 pp_string (pp
, "while (1) { ");
2693 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2694 pp_cxx_right_brace (pp
);
2698 pp_string (pp
, "if (");
2699 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2700 pp_string (pp
, ") break; ");
2704 dump_expr (pp
, BASELINK_FUNCTIONS (t
), flags
& ~TFF_EXPR_IN_PARENS
);
2707 case EMPTY_CLASS_EXPR
:
2708 dump_type (pp
, TREE_TYPE (t
), flags
);
2709 pp_cxx_left_paren (pp
);
2710 pp_cxx_right_paren (pp
);
2713 case NON_DEPENDENT_EXPR
:
2714 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2717 case ARGUMENT_PACK_SELECT
:
2718 dump_template_argument (pp
, ARGUMENT_PACK_SELECT_FROM_PACK (t
), flags
);
2731 pp_type_specifier_seq (pp
, t
);
2735 /* We get here when we want to print a dependent type as an
2736 id-expression, without any disambiguator decoration. */
2737 pp
->id_expression (t
);
2740 case TEMPLATE_TYPE_PARM
:
2741 case TEMPLATE_TEMPLATE_PARM
:
2742 case BOUND_TEMPLATE_TEMPLATE_PARM
:
2743 dump_type (pp
, t
, flags
);
2747 pp_cxx_trait_expression (pp
, t
);
2751 pp_cxx_va_arg_expression (pp
, t
);
2755 pp_cxx_offsetof_expression (pp
, t
);
2758 case ADDRESSOF_EXPR
:
2759 pp_cxx_addressof_expression (pp
, t
);
2763 dump_decl (pp
, t
, flags
);
2766 case EXPR_PACK_EXPANSION
:
2767 case UNARY_LEFT_FOLD_EXPR
:
2768 case UNARY_RIGHT_FOLD_EXPR
:
2769 case BINARY_LEFT_FOLD_EXPR
:
2770 case BINARY_RIGHT_FOLD_EXPR
:
2777 case VEC_DELETE_EXPR
:
2784 case UNORDERED_EXPR
:
2794 case FIX_TRUNC_EXPR
:
2799 case TRUTH_AND_EXPR
:
2801 case TRUTH_XOR_EXPR
:
2802 if (flags
& TFF_EXPR_IN_PARENS
)
2803 pp_cxx_left_paren (pp
);
2805 if (flags
& TFF_EXPR_IN_PARENS
)
2806 pp_cxx_right_paren (pp
);
2810 dump_expr (pp
, resolve_virtual_fun_from_obj_type_ref (t
), flags
);
2814 pp_string (pp
, M_("<lambda>"));
2818 pp_cxx_left_paren (pp
);
2819 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2820 pp_cxx_right_paren (pp
);
2824 pp_cxx_requires_expr (cxx_pp
, t
);
2828 pp_cxx_simple_requirement (cxx_pp
, t
);
2832 pp_cxx_type_requirement (cxx_pp
, t
);
2836 pp_cxx_compound_requirement (cxx_pp
, t
);
2840 pp_cxx_nested_requirement (cxx_pp
, t
);
2853 pp_cxx_constraint (cxx_pp
, t
);
2856 case PLACEHOLDER_EXPR
:
2857 pp_string (pp
, M_("*this"));
2861 dump_expr_list (pp
, t
, flags
);
2864 /* This list is incomplete, but should suffice for now.
2865 It is very important that `sorry' does not call
2866 `report_error_function'. That could cause an infinite loop. */
2868 pp_unsupported_tree (pp
, t
);
2871 pp_string (pp
, M_("<expression error>"));
2877 dump_binary_op (cxx_pretty_printer
*pp
, const char *opstring
, tree t
,
2880 pp_cxx_left_paren (pp
);
2881 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2882 pp_cxx_whitespace (pp
);
2884 pp_cxx_ws_string (pp
, opstring
);
2886 pp_string (pp
, M_("<unknown operator>"));
2887 pp_cxx_whitespace (pp
);
2888 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2889 pp_cxx_right_paren (pp
);
2893 dump_unary_op (cxx_pretty_printer
*pp
, const char *opstring
, tree t
, int flags
)
2895 if (flags
& TFF_EXPR_IN_PARENS
)
2896 pp_cxx_left_paren (pp
);
2897 pp_cxx_ws_string (pp
, opstring
);
2898 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2899 if (flags
& TFF_EXPR_IN_PARENS
)
2900 pp_cxx_right_paren (pp
);
2904 reinit_cxx_pp (void)
2906 pp_clear_output_area (cxx_pp
);
2907 cxx_pp
->padding
= pp_none
;
2908 pp_indentation (cxx_pp
) = 0;
2909 pp_needs_newline (cxx_pp
) = false;
2910 cxx_pp
->enclosing_scope
= current_function_decl
;
2913 /* Same as pp_formatted_text, except the return string is a separate
2914 copy and has a GGC storage duration, e.g. an indefinite lifetime. */
2917 pp_ggc_formatted_text (pretty_printer
*pp
)
2919 return ggc_strdup (pp_formatted_text (pp
));
2922 /* Exported interface to stringifying types, exprs and decls under TFF_*
2926 type_as_string (tree typ
, int flags
)
2929 pp_translate_identifiers (cxx_pp
) = false;
2930 dump_type (cxx_pp
, typ
, flags
);
2931 return pp_ggc_formatted_text (cxx_pp
);
2935 type_as_string_translate (tree typ
, int flags
)
2938 dump_type (cxx_pp
, typ
, flags
);
2939 return pp_ggc_formatted_text (cxx_pp
);
2943 expr_as_string (tree decl
, int flags
)
2946 pp_translate_identifiers (cxx_pp
) = false;
2947 dump_expr (cxx_pp
, decl
, flags
);
2948 return pp_ggc_formatted_text (cxx_pp
);
2951 /* Wrap decl_as_string with options appropriate for dwarf. */
2954 decl_as_dwarf_string (tree decl
, int flags
)
2957 /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag
2958 here will be adequate to get the desired behavior. */
2959 cxx_pp
->flags
|= pp_c_flag_gnu_v3
;
2960 name
= decl_as_string (decl
, flags
);
2961 /* Subsequent calls to the pretty printer shouldn't use this style. */
2962 cxx_pp
->flags
&= ~pp_c_flag_gnu_v3
;
2967 decl_as_string (tree decl
, int flags
)
2970 pp_translate_identifiers (cxx_pp
) = false;
2971 dump_decl (cxx_pp
, decl
, flags
);
2972 return pp_ggc_formatted_text (cxx_pp
);
2976 decl_as_string_translate (tree decl
, int flags
)
2979 dump_decl (cxx_pp
, decl
, flags
);
2980 return pp_ggc_formatted_text (cxx_pp
);
2983 /* Wrap lang_decl_name with options appropriate for dwarf. */
2986 lang_decl_dwarf_name (tree decl
, int v
, bool translate
)
2989 /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag
2990 here will be adequate to get the desired behavior. */
2991 cxx_pp
->flags
|= pp_c_flag_gnu_v3
;
2992 name
= lang_decl_name (decl
, v
, translate
);
2993 /* Subsequent calls to the pretty printer shouldn't use this style. */
2994 cxx_pp
->flags
&= ~pp_c_flag_gnu_v3
;
2998 /* Generate the three forms of printable names for cxx_printable_name. */
3001 lang_decl_name (tree decl
, int v
, bool translate
)
3005 ? decl_as_string_translate (decl
, TFF_DECL_SPECIFIERS
)
3006 : decl_as_string (decl
, TFF_DECL_SPECIFIERS
));
3009 pp_translate_identifiers (cxx_pp
) = translate
;
3011 && (DECL_CLASS_SCOPE_P (decl
)
3012 || (DECL_NAMESPACE_SCOPE_P (decl
)
3013 && CP_DECL_CONTEXT (decl
) != global_namespace
)))
3015 dump_type (cxx_pp
, CP_DECL_CONTEXT (decl
), TFF_PLAIN_IDENTIFIER
);
3016 pp_cxx_colon_colon (cxx_pp
);
3019 if (TREE_CODE (decl
) == FUNCTION_DECL
)
3020 dump_function_name (cxx_pp
, decl
, TFF_PLAIN_IDENTIFIER
);
3021 else if ((DECL_NAME (decl
) == NULL_TREE
)
3022 && TREE_CODE (decl
) == NAMESPACE_DECL
)
3023 dump_decl (cxx_pp
, decl
, TFF_PLAIN_IDENTIFIER
| TFF_UNQUALIFIED_NAME
);
3025 dump_decl (cxx_pp
, DECL_NAME (decl
), TFF_PLAIN_IDENTIFIER
);
3027 return pp_ggc_formatted_text (cxx_pp
);
3030 /* Return the location of a tree passed to %+ formats. */
3033 location_of (tree t
)
3037 t
= TYPE_MAIN_DECL (t
);
3039 return input_location
;
3041 else if (TREE_CODE (t
) == OVERLOAD
)
3045 return DECL_SOURCE_LOCATION (t
);
3046 if (TREE_CODE (t
) == DEFAULT_ARG
)
3047 return defarg_location (t
);
3048 return cp_expr_loc_or_loc (t
, input_location
);
3051 /* Now the interfaces from error et al to dump_type et al. Each takes an
3052 on/off VERBOSE flag and supply the appropriate TFF_ flags to a dump_
3056 decl_to_string (tree decl
, int verbose
)
3060 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == RECORD_TYPE
3061 || TREE_CODE (decl
) == UNION_TYPE
|| TREE_CODE (decl
) == ENUMERAL_TYPE
)
3062 flags
= TFF_CLASS_KEY_OR_ENUM
;
3064 flags
|= TFF_DECL_SPECIFIERS
;
3065 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
3066 flags
|= TFF_DECL_SPECIFIERS
| TFF_RETURN_TYPE
;
3067 flags
|= TFF_TEMPLATE_HEADER
;
3070 dump_decl (cxx_pp
, decl
, flags
);
3071 return pp_ggc_formatted_text (cxx_pp
);
3075 expr_to_string (tree decl
)
3078 dump_expr (cxx_pp
, decl
, 0);
3079 return pp_ggc_formatted_text (cxx_pp
);
3083 fndecl_to_string (tree fndecl
, int verbose
)
3087 flags
= TFF_EXCEPTION_SPECIFICATION
| TFF_DECL_SPECIFIERS
3088 | TFF_TEMPLATE_HEADER
;
3090 flags
|= TFF_FUNCTION_DEFAULT_ARGUMENTS
;
3092 dump_decl (cxx_pp
, fndecl
, flags
);
3093 return pp_ggc_formatted_text (cxx_pp
);
3098 code_to_string (enum tree_code c
)
3100 return get_tree_code_name (c
);
3104 language_to_string (enum languages c
)
3111 case lang_cplusplus
:
3120 /* Return the proper printed version of a parameter to a C++ function. */
3123 parm_to_string (int p
)
3127 pp_string (cxx_pp
, "'this'");
3129 pp_decimal_int (cxx_pp
, p
+ 1);
3130 return pp_ggc_formatted_text (cxx_pp
);
3134 op_to_string (bool assop
, enum tree_code p
)
3136 tree id
= ovl_op_identifier (assop
, p
);
3137 return id
? IDENTIFIER_POINTER (id
) : M_("<unknown>");
3140 /* Return a GC-allocated representation of type TYP, with verbosity VERBOSE.
3142 If QUOTE is non-NULL and if *QUOTE is true, then quotes are added to the
3143 string in appropriate places, and *QUOTE is written to with false
3144 to suppress pp_format's trailing close quote so that e.g.
3145 foo_typedef {aka underlying_foo} {enum}
3146 can be printed by "%qT" as:
3147 `foo_typedef' {aka `underlying_foo'} {enum}
3149 `foo_typedef {aka underlying_foo} {enum}'
3150 When adding such quotes, if POSTPROCESSED is true (for handling %H and %I)
3151 then a leading open quote will be added, whereas if POSTPROCESSED is false
3152 (for handling %T) then any leading quote has already been added by
3153 pp_format, or is not needed due to QUOTE being NULL (for template arguments
3156 SHOW_COLOR is used to determine the colorization of any quotes that
3160 type_to_string (tree typ
, int verbose
, bool postprocessed
, bool *quote
,
3165 flags
|= TFF_CLASS_KEY_OR_ENUM
;
3166 flags
|= TFF_TEMPLATE_HEADER
;
3170 if (postprocessed
&& quote
&& *quote
)
3171 pp_begin_quote (cxx_pp
, show_color
);
3173 struct obstack
*ob
= pp_buffer (cxx_pp
)->obstack
;
3174 int type_start
, type_len
;
3175 type_start
= obstack_object_size (ob
);
3177 dump_type (cxx_pp
, typ
, flags
);
3179 /* Remember the end of the initial dump. */
3180 type_len
= obstack_object_size (ob
) - type_start
;
3182 /* If we're printing a type that involves typedefs, also print the
3183 stripped version. But sometimes the stripped version looks
3184 exactly the same, so we don't want it after all. To avoid printing
3185 it in that case, we play ugly obstack games. */
3186 if (typ
&& TYPE_P (typ
) && typ
!= TYPE_CANONICAL (typ
)
3187 && !uses_template_parms (typ
))
3189 int aka_start
, aka_len
; char *p
;
3190 tree aka
= strip_typedefs (typ
);
3191 if (quote
&& *quote
)
3192 pp_end_quote (cxx_pp
, show_color
);
3193 pp_string (cxx_pp
, " {aka");
3194 pp_cxx_whitespace (cxx_pp
);
3195 if (quote
&& *quote
)
3196 pp_begin_quote (cxx_pp
, show_color
);
3197 /* And remember the start of the aka dump. */
3198 aka_start
= obstack_object_size (ob
);
3199 dump_type (cxx_pp
, aka
, flags
);
3200 aka_len
= obstack_object_size (ob
) - aka_start
;
3201 if (quote
&& *quote
)
3202 pp_end_quote (cxx_pp
, show_color
);
3203 pp_right_brace (cxx_pp
);
3204 p
= (char*)obstack_base (ob
);
3205 /* If they are identical, cut off the aka by unwinding the obstack. */
3206 if (type_len
== aka_len
3207 && memcmp (p
+ type_start
, p
+aka_start
, type_len
) == 0)
3209 /* We can't add a '\0' here, since we may be adding a closing quote
3210 below, and it would be hidden by the '\0'.
3211 Instead, manually unwind the current object within the obstack
3212 so that the insertion point is at the end of the type, before
3214 int delta
= type_start
+ type_len
- obstack_object_size (ob
);
3215 gcc_assert (delta
<= 0);
3216 obstack_blank_fast (ob
, delta
);
3220 /* No further closing quotes are needed. */
3224 if (quote
&& *quote
)
3226 pp_end_quote (cxx_pp
, show_color
);
3229 return pp_ggc_formatted_text (cxx_pp
);
3233 args_to_string (tree p
, int verbose
)
3237 flags
|= TFF_CLASS_KEY_OR_ENUM
;
3242 if (TYPE_P (TREE_VALUE (p
)))
3243 return type_as_string_translate (p
, flags
);
3246 for (; p
; p
= TREE_CHAIN (p
))
3248 if (null_node_p (TREE_VALUE (p
)))
3249 pp_cxx_ws_string (cxx_pp
, "NULL");
3251 dump_type (cxx_pp
, error_type (TREE_VALUE (p
)), flags
);
3253 pp_separate_with_comma (cxx_pp
);
3255 return pp_ggc_formatted_text (cxx_pp
);
3258 /* Pretty-print a deduction substitution (from deduction_tsubst_fntype). P
3259 is a TREE_LIST with purpose the TEMPLATE_DECL, value the template
3263 subst_to_string (tree p
)
3265 tree decl
= TREE_PURPOSE (p
);
3266 tree targs
= TREE_VALUE (p
);
3267 tree tparms
= DECL_TEMPLATE_PARMS (decl
);
3268 int flags
= (TFF_DECL_SPECIFIERS
|TFF_TEMPLATE_HEADER
3269 |TFF_NO_TEMPLATE_BINDINGS
);
3275 dump_template_decl (cxx_pp
, TREE_PURPOSE (p
), flags
);
3276 dump_substitution (cxx_pp
, NULL
, tparms
, targs
, /*flags=*/0);
3277 return pp_ggc_formatted_text (cxx_pp
);
3281 cv_to_string (tree p
, int v
)
3284 cxx_pp
->padding
= v
? pp_before
: pp_none
;
3285 pp_cxx_cv_qualifier_seq (cxx_pp
, p
);
3286 return pp_ggc_formatted_text (cxx_pp
);
3290 eh_spec_to_string (tree p
, int /*v*/)
3294 dump_exception_spec (cxx_pp
, p
, flags
);
3295 return pp_ggc_formatted_text (cxx_pp
);
3298 /* Langhook for print_error_function. */
3300 cxx_print_error_function (diagnostic_context
*context
, const char *file
,
3301 diagnostic_info
*diagnostic
)
3305 prefix
= xstrdup (file
);
3308 lhd_print_error_function (context
, file
, diagnostic
);
3309 pp_set_prefix (context
->printer
, prefix
);
3310 maybe_print_instantiation_context (context
);
3314 cp_diagnostic_starter (diagnostic_context
*context
,
3315 diagnostic_info
*diagnostic
)
3317 diagnostic_report_current_module (context
, diagnostic_location (diagnostic
));
3318 cp_print_error_function (context
, diagnostic
);
3319 maybe_print_instantiation_context (context
);
3320 maybe_print_constexpr_context (context
);
3321 pp_set_prefix (context
->printer
, diagnostic_build_prefix (context
,
3325 /* Print current function onto BUFFER, in the process of reporting
3326 a diagnostic message. Called from cp_diagnostic_starter. */
3328 cp_print_error_function (diagnostic_context
*context
,
3329 diagnostic_info
*diagnostic
)
3331 /* If we are in an instantiation context, current_function_decl is likely
3332 to be wrong, so just rely on print_instantiation_full_context. */
3333 if (current_instantiation ())
3335 if (diagnostic_last_function_changed (context
, diagnostic
))
3337 char *old_prefix
= pp_take_prefix (context
->printer
);
3338 const char *file
= LOCATION_FILE (diagnostic_location (diagnostic
));
3339 tree abstract_origin
= diagnostic_abstract_origin (diagnostic
);
3340 char *new_prefix
= (file
&& abstract_origin
== NULL
)
3341 ? file_name_as_prefix (context
, file
) : NULL
;
3343 pp_set_prefix (context
->printer
, new_prefix
);
3345 if (current_function_decl
== NULL
)
3346 pp_string (context
->printer
, _("At global scope:"));
3351 if (abstract_origin
)
3353 ao
= BLOCK_ABSTRACT_ORIGIN (abstract_origin
);
3354 gcc_assert (TREE_CODE (ao
) == FUNCTION_DECL
);
3358 fndecl
= current_function_decl
;
3360 pp_printf (context
->printer
, function_category (fndecl
),
3361 cxx_printable_name_translate (fndecl
, 2));
3363 while (abstract_origin
)
3366 tree block
= abstract_origin
;
3368 locus
= &BLOCK_SOURCE_LOCATION (block
);
3370 block
= BLOCK_SUPERCONTEXT (block
);
3371 while (block
&& TREE_CODE (block
) == BLOCK
3372 && BLOCK_ABSTRACT_ORIGIN (block
))
3374 ao
= BLOCK_ABSTRACT_ORIGIN (block
);
3375 if (TREE_CODE (ao
) == FUNCTION_DECL
)
3380 else if (TREE_CODE (ao
) != BLOCK
)
3383 block
= BLOCK_SUPERCONTEXT (block
);
3386 abstract_origin
= block
;
3389 while (block
&& TREE_CODE (block
) == BLOCK
)
3390 block
= BLOCK_SUPERCONTEXT (block
);
3392 if (block
&& TREE_CODE (block
) == FUNCTION_DECL
)
3394 abstract_origin
= NULL
;
3398 expanded_location s
= expand_location (*locus
);
3399 pp_character (context
->printer
, ',');
3400 pp_newline (context
->printer
);
3403 if (context
->show_column
&& s
.column
!= 0)
3404 pp_printf (context
->printer
,
3405 _(" inlined from %qs at %r%s:%d:%d%R"),
3406 cxx_printable_name_translate (fndecl
, 2),
3407 "locus", s
.file
, s
.line
, s
.column
);
3409 pp_printf (context
->printer
,
3410 _(" inlined from %qs at %r%s:%d%R"),
3411 cxx_printable_name_translate (fndecl
, 2),
3412 "locus", s
.file
, s
.line
);
3416 pp_printf (context
->printer
, _(" inlined from %qs"),
3417 cxx_printable_name_translate (fndecl
, 2));
3420 pp_character (context
->printer
, ':');
3422 pp_newline (context
->printer
);
3424 diagnostic_set_last_function (context
, diagnostic
);
3425 pp_destroy_prefix (context
->printer
);
3426 context
->printer
->prefix
= old_prefix
;
3430 /* Returns a description of FUNCTION using standard terminology. The
3431 result is a format string of the form "In CATEGORY %qs". */
3433 function_category (tree fn
)
3435 /* We can get called from the middle-end for diagnostics of function
3436 clones. Make sure we have language specific information before
3437 dereferencing it. */
3438 if (DECL_LANG_SPECIFIC (STRIP_TEMPLATE (fn
))
3439 && DECL_FUNCTION_MEMBER_P (fn
))
3441 if (DECL_STATIC_FUNCTION_P (fn
))
3442 return _("In static member function %qs");
3443 else if (DECL_COPY_CONSTRUCTOR_P (fn
))
3444 return _("In copy constructor %qs");
3445 else if (DECL_CONSTRUCTOR_P (fn
))
3446 return _("In constructor %qs");
3447 else if (DECL_DESTRUCTOR_P (fn
))
3448 return _("In destructor %qs");
3449 else if (LAMBDA_FUNCTION_P (fn
))
3450 return _("In lambda function");
3452 return _("In member function %qs");
3455 return _("In function %qs");
3458 /* Report the full context of a current template instantiation,
3461 print_instantiation_full_context (diagnostic_context
*context
)
3463 struct tinst_level
*p
= current_instantiation ();
3464 location_t location
= input_location
;
3468 pp_verbatim (context
->printer
,
3470 ? _("%s: In substitution of %qS:\n")
3471 : _("%s: In instantiation of %q#D:\n"),
3472 LOCATION_FILE (location
),
3475 location
= p
->locus
;
3479 print_instantiation_partial_context (context
, p
, location
);
3482 /* Helper function of print_instantiation_partial_context() that
3483 prints a single line of instantiation context. */
3486 print_instantiation_partial_context_line (diagnostic_context
*context
,
3487 struct tinst_level
*t
,
3488 location_t loc
, bool recursive_p
)
3490 if (loc
== UNKNOWN_LOCATION
)
3493 expanded_location xloc
= expand_location (loc
);
3495 if (context
->show_column
)
3496 pp_verbatim (context
->printer
, _("%r%s:%d:%d:%R "),
3497 "locus", xloc
.file
, xloc
.line
, xloc
.column
);
3499 pp_verbatim (context
->printer
, _("%r%s:%d:%R "),
3500 "locus", xloc
.file
, xloc
.line
);
3505 pp_verbatim (context
->printer
,
3507 ? _("recursively required by substitution of %qS\n")
3508 : _("required by substitution of %qS\n"),
3511 pp_verbatim (context
->printer
,
3513 ? _("recursively required from %q#D\n")
3514 : _("required from %q#D\n"),
3519 pp_verbatim (context
->printer
,
3521 ? _("recursively required from here\n")
3522 : _("required from here\n"));
3526 /* Same as print_instantiation_full_context but less verbose. */
3529 print_instantiation_partial_context (diagnostic_context
*context
,
3530 struct tinst_level
*t0
, location_t loc
)
3532 struct tinst_level
*t
;
3535 location_t prev_loc
= loc
;
3537 for (t
= t0
; t
!= NULL
; t
= t
->next
)
3538 if (prev_loc
!= t
->locus
)
3540 prev_loc
= t
->locus
;
3546 if (template_backtrace_limit
3547 && n_total
> template_backtrace_limit
)
3549 int skip
= n_total
- template_backtrace_limit
;
3550 int head
= template_backtrace_limit
/ 2;
3552 /* Avoid skipping just 1. If so, skip 2. */
3556 head
= (template_backtrace_limit
- 1) / 2;
3559 for (n
= 0; n
< head
; n
++)
3561 gcc_assert (t
!= NULL
);
3562 if (loc
!= t
->locus
)
3563 print_instantiation_partial_context_line (context
, t
, loc
,
3564 /*recursive_p=*/false);
3568 if (t
!= NULL
&& skip
> 0)
3570 expanded_location xloc
;
3571 xloc
= expand_location (loc
);
3572 if (context
->show_column
)
3573 pp_verbatim (context
->printer
,
3574 _("%r%s:%d:%d:%R [ skipping %d instantiation "
3575 "contexts, use -ftemplate-backtrace-limit=0 to "
3577 "locus", xloc
.file
, xloc
.line
, xloc
.column
, skip
);
3579 pp_verbatim (context
->printer
,
3580 _("%r%s:%d:%R [ skipping %d instantiation "
3581 "contexts, use -ftemplate-backtrace-limit=0 to "
3583 "locus", xloc
.file
, xloc
.line
, skip
);
3588 } while (t
!= NULL
&& --skip
> 0);
3594 while (t
->next
!= NULL
&& t
->locus
== t
->next
->locus
)
3599 print_instantiation_partial_context_line (context
, t
, loc
,
3604 print_instantiation_partial_context_line (context
, NULL
, loc
,
3605 /*recursive_p=*/false);
3608 /* Called from cp_thing to print the template context for an error. */
3610 maybe_print_instantiation_context (diagnostic_context
*context
)
3612 if (!problematic_instantiation_changed () || current_instantiation () == 0)
3615 record_last_problematic_instantiation ();
3616 print_instantiation_full_context (context
);
3619 /* Report what constexpr call(s) we're trying to expand, if any. */
3622 maybe_print_constexpr_context (diagnostic_context
*context
)
3624 vec
<tree
> call_stack
= cx_error_context ();
3628 FOR_EACH_VEC_ELT (call_stack
, ix
, t
)
3630 expanded_location xloc
= expand_location (EXPR_LOCATION (t
));
3631 const char *s
= expr_as_string (t
, 0);
3632 if (context
->show_column
)
3633 pp_verbatim (context
->printer
,
3634 _("%r%s:%d:%d:%R in %<constexpr%> expansion of %qs"),
3635 "locus", xloc
.file
, xloc
.line
, xloc
.column
, s
);
3637 pp_verbatim (context
->printer
,
3638 _("%r%s:%d:%R in %<constexpr%> expansion of %qs"),
3639 "locus", xloc
.file
, xloc
.line
, s
);
3640 pp_newline (context
->printer
);
3645 /* Return true iff TYPE_A and TYPE_B are template types that are
3646 meaningful to compare. */
3649 comparable_template_types_p (tree type_a
, tree type_b
)
3651 if (!CLASS_TYPE_P (type_a
))
3653 if (!CLASS_TYPE_P (type_b
))
3656 tree tinfo_a
= TYPE_TEMPLATE_INFO (type_a
);
3657 tree tinfo_b
= TYPE_TEMPLATE_INFO (type_b
);
3658 if (!tinfo_a
|| !tinfo_b
)
3661 return TI_TEMPLATE (tinfo_a
) == TI_TEMPLATE (tinfo_b
);
3664 /* Start a new line indented by SPC spaces on PP. */
3667 newline_and_indent (pretty_printer
*pp
, int spc
)
3670 for (int i
= 0; i
< spc
; i
++)
3674 /* Generate a GC-allocated string for ARG, an expression or type. */
3677 arg_to_string (tree arg
, bool verbose
)
3680 return type_to_string (arg
, verbose
, true, NULL
, false);
3682 return expr_to_string (arg
);
3685 /* Subroutine to type_to_string_with_compare and
3686 print_template_tree_comparison.
3688 Print a representation of ARG (an expression or type) to PP,
3689 colorizing it as "type-diff" if PP->show_color. */
3692 print_nonequal_arg (pretty_printer
*pp
, tree arg
, bool verbose
)
3694 pp_printf (pp
, "%r%s%R",
3697 ? arg_to_string (arg
, verbose
)
3698 : G_("(no argument)")));
3701 /* Recursively print template TYPE_A to PP, as compared to template TYPE_B.
3703 The types must satisfy comparable_template_types_p.
3705 If INDENT is 0, then this is equivalent to type_to_string (TYPE_A), but
3706 potentially colorizing/eliding in comparison with TYPE_B.
3708 For example given types:
3709 vector<map<int,double>>
3711 vector<map<int,float>>
3712 then the result on PP would be:
3713 vector<map<[...],double>>
3714 with type elision, and:
3715 vector<map<int,double>>
3716 without type elision.
3718 In both cases the parts of TYPE that differ from PEER will be colorized
3719 if pp_show_color (pp) is true. In the above example, this would be
3722 If INDENT is non-zero, then the types are printed in a tree-like form
3723 which shows both types. In the above example, the result on PP would be:
3730 and without type-elision would be:
3737 As before, the differing parts of the types are colorized if
3738 pp_show_color (pp) is true ("double" and "float" in this example).
3740 Template arguments in which both types are using the default arguments
3741 are not printed; if at least one of the two types is using a non-default
3742 argument, then that argument is printed (or both arguments for the
3743 tree-like print format). */
3746 print_template_differences (pretty_printer
*pp
, tree type_a
, tree type_b
,
3747 bool verbose
, int indent
)
3750 newline_and_indent (pp
, indent
);
3752 tree tinfo_a
= TYPE_TEMPLATE_INFO (type_a
);
3753 tree tinfo_b
= TYPE_TEMPLATE_INFO (type_b
);
3755 pp_printf (pp
, "%s<",
3756 IDENTIFIER_POINTER (DECL_NAME (TI_TEMPLATE (tinfo_a
))));
3758 tree args_a
= TI_ARGS (tinfo_a
);
3759 tree args_b
= TI_ARGS (tinfo_b
);
3760 gcc_assert (TREE_CODE (args_a
) == TREE_VEC
);
3761 gcc_assert (TREE_CODE (args_b
) == TREE_VEC
);
3763 int len_a
= get_non_default_template_args_count (args_a
, flags
);
3764 args_a
= INNERMOST_TEMPLATE_ARGS (args_a
);
3765 int len_b
= get_non_default_template_args_count (args_b
, flags
);
3766 args_b
= INNERMOST_TEMPLATE_ARGS (args_b
);
3767 /* Determine the maximum range of args for which non-default template args
3768 were used; beyond this, only default args (if any) were used, and so
3769 they will be equal from this point onwards.
3770 One of the two peers might have used default arguments within this
3771 range, but the other will be using non-default arguments, and so
3772 it's more readable to print both within this range, to highlight
3774 int len_max
= MAX (len_a
, len_b
);
3775 gcc_assert (TREE_CODE (args_a
) == TREE_VEC
);
3776 gcc_assert (TREE_CODE (args_b
) == TREE_VEC
);
3777 for (int idx
= 0; idx
< len_max
; idx
++)
3780 pp_character (pp
, ',');
3782 tree arg_a
= TREE_VEC_ELT (args_a
, idx
);
3783 tree arg_b
= TREE_VEC_ELT (args_b
, idx
);
3787 newline_and_indent (pp
, indent
+ 2);
3788 /* Can do elision here, printing "[...]". */
3789 if (flag_elide_type
)
3790 pp_string (pp
, G_("[...]"));
3792 pp_string (pp
, arg_to_string (arg_a
, verbose
));
3796 int new_indent
= indent
? indent
+ 2 : 0;
3797 if (comparable_template_types_p (arg_a
, arg_b
))
3798 print_template_differences (pp
, arg_a
, arg_b
, verbose
, new_indent
);
3802 newline_and_indent (pp
, indent
+ 2);
3803 pp_character (pp
, '[');
3804 print_nonequal_arg (pp
, arg_a
, verbose
);
3805 pp_string (pp
, " != ");
3806 print_nonequal_arg (pp
, arg_b
, verbose
);
3807 pp_character (pp
, ']');
3810 print_nonequal_arg (pp
, arg_a
, verbose
);
3813 pp_printf (pp
, ">");
3816 /* As type_to_string, but for a template, potentially colorizing/eliding
3817 in comparison with PEER.
3818 For example, if TYPE is map<int,double> and PEER is map<int,int>,
3819 then the resulting string would be:
3821 with type elision, and:
3823 without type elision.
3825 In both cases the parts of TYPE that differ from PEER will be colorized
3826 if SHOW_COLOR is true. In the above example, this would be "double".
3828 Template arguments in which both types are using the default arguments
3829 are not printed; if at least one of the two types is using a non-default
3830 argument, then both arguments are printed.
3832 The resulting string is in a GC-allocated buffer. */
3835 type_to_string_with_compare (tree type
, tree peer
, bool verbose
,
3838 pretty_printer inner_pp
;
3839 pretty_printer
*pp
= &inner_pp
;
3840 pp_show_color (pp
) = show_color
;
3842 print_template_differences (pp
, type
, peer
, verbose
, 0);
3843 return pp_ggc_formatted_text (pp
);
3846 /* Recursively print a tree-like comparison of TYPE_A and TYPE_B to PP,
3847 indented by INDENT spaces.
3849 For example given types:
3851 vector<map<int,double>>
3855 vector<map<double,float>>
3857 the output with type elision would be:
3864 and without type-elision would be:
3871 TYPE_A and TYPE_B must both be comparable template types
3872 (as per comparable_template_types_p).
3874 Template arguments in which both types are using the default arguments
3875 are not printed; if at least one of the two types is using a non-default
3876 argument, then both arguments are printed. */
3879 print_template_tree_comparison (pretty_printer
*pp
, tree type_a
, tree type_b
,
3880 bool verbose
, int indent
)
3882 print_template_differences (pp
, type_a
, type_b
, verbose
, indent
);
3885 /* Subroutine for use in a format_postprocessor::handle
3886 implementation. Adds a chunk to the end of
3887 formatted output, so that it will be printed
3888 by pp_output_formatted_text. */
3891 append_formatted_chunk (pretty_printer
*pp
, const char *content
)
3893 output_buffer
*buffer
= pp_buffer (pp
);
3894 struct chunk_info
*chunk_array
= buffer
->cur_chunk_array
;
3895 const char **args
= chunk_array
->args
;
3897 unsigned int chunk_idx
;
3898 for (chunk_idx
= 0; args
[chunk_idx
]; chunk_idx
++)
3900 args
[chunk_idx
++] = content
;
3901 args
[chunk_idx
] = NULL
;
3904 /* Create a copy of CONTENT, with quotes added, and,
3905 potentially, with colorization.
3906 No escaped is performed on CONTENT.
3907 The result is in a GC-allocated buffer. */
3910 add_quotes (const char *content
, bool show_color
)
3912 pretty_printer tmp_pp
;
3913 pp_show_color (&tmp_pp
) = show_color
;
3915 /* We have to use "%<%s%>" rather than "%qs" here in order to avoid
3916 quoting colorization bytes within the results. */
3917 pp_printf (&tmp_pp
, "%<%s%>", content
);
3919 return pp_ggc_formatted_text (&tmp_pp
);
3922 /* If we had %H and %I, and hence deferred printing them,
3923 print them now, storing the result into the chunk_info
3924 for pp_format. Quote them if 'q' was provided.
3925 Also print the difference in tree form, adding it as
3926 an additional chunk. */
3929 cxx_format_postprocessor::handle (pretty_printer
*pp
)
3931 /* If we have one of %H and %I, the other should have
3933 if (m_type_a
.m_tree
|| m_type_b
.m_tree
)
3935 /* Avoid reentrancy issues by working with a copy of
3936 m_type_a and m_type_b, resetting them now. */
3937 deferred_printed_type type_a
= m_type_a
;
3938 deferred_printed_type type_b
= m_type_b
;
3939 m_type_a
= deferred_printed_type ();
3940 m_type_b
= deferred_printed_type ();
3942 gcc_assert (type_a
.m_buffer_ptr
);
3943 gcc_assert (type_b
.m_buffer_ptr
);
3945 bool show_color
= pp_show_color (pp
);
3947 const char *type_a_text
;
3948 const char *type_b_text
;
3950 if (comparable_template_types_p (type_a
.m_tree
, type_b
.m_tree
))
3953 = type_to_string_with_compare (type_a
.m_tree
, type_b
.m_tree
,
3954 type_a
.m_verbose
, show_color
);
3956 = type_to_string_with_compare (type_b
.m_tree
, type_a
.m_tree
,
3957 type_b
.m_verbose
, show_color
);
3959 if (flag_diagnostics_show_template_tree
)
3961 pretty_printer inner_pp
;
3962 pp_show_color (&inner_pp
) = pp_show_color (pp
);
3963 print_template_tree_comparison
3964 (&inner_pp
, type_a
.m_tree
, type_b
.m_tree
, type_a
.m_verbose
, 2);
3965 append_formatted_chunk (pp
, pp_ggc_formatted_text (&inner_pp
));
3970 /* If the types were not comparable (or if only one of %H/%I was
3971 provided), they are printed normally, and no difference tree
3973 type_a_text
= type_to_string (type_a
.m_tree
, type_a
.m_verbose
,
3974 true, &type_a
.m_quote
, show_color
);
3975 type_b_text
= type_to_string (type_b
.m_tree
, type_b
.m_verbose
,
3976 true, &type_b
.m_quote
, show_color
);
3980 type_a_text
= add_quotes (type_a_text
, show_color
);
3981 *type_a
.m_buffer_ptr
= type_a_text
;
3984 type_b_text
= add_quotes (type_b_text
, show_color
);
3985 *type_b
.m_buffer_ptr
= type_b_text
;
3989 /* Subroutine for handling %H and %I, to support i18n of messages like:
3991 error_at (loc, "could not convert %qE from %qH to %qI",
3992 expr, type_a, type_b);
3994 so that we can print things like:
3996 could not convert 'foo' from 'map<int,double>' to 'map<int,int>'
3998 and, with type-elision:
4000 could not convert 'foo' from 'map<[...],double>' to 'map<[...],int>'
4002 (with color-coding of the differences between the types).
4004 The %H and %I format codes are peers: both must be present,
4005 and they affect each other. Hence to handle them, we must
4006 delay printing until we have both, deferring the printing to
4007 pretty_printer's m_format_postprocessor hook.
4009 This is called in phase 2 of pp_format, when it is accumulating
4010 a series of formatted chunks. We stash the location of the chunk
4011 we're meant to have written to, so that we can write to it in the
4012 m_format_postprocessor hook.
4014 We also need to stash whether a 'q' prefix was provided (the QUOTE
4015 param) so that we can add the quotes when writing out the delayed
4019 defer_phase_2_of_type_diff (deferred_printed_type
*deferred
,
4020 tree type
, const char **buffer_ptr
,
4021 bool verbose
, bool quote
)
4023 gcc_assert (deferred
->m_tree
== NULL_TREE
);
4024 gcc_assert (deferred
->m_buffer_ptr
== NULL
);
4025 *deferred
= deferred_printed_type (type
, buffer_ptr
, verbose
, quote
);
4029 /* Called from output_format -- during diagnostic message processing --
4030 to handle C++ specific format specifier with the following meanings:
4031 %A function argument-list.
4035 %F function declaration.
4037 %H type difference (from).
4038 %I type difference (to).
4040 %L language as used in extern "lang".
4042 %P function parameter whose position is indicated by an integer.
4043 %Q assignment operator.
4044 %S substitution (template + args)
4047 %X exception-specification. */
4049 cp_printer (pretty_printer
*pp
, text_info
*text
, const char *spec
,
4050 int precision
, bool wide
, bool set_locus
, bool verbose
,
4051 bool *quoted
, const char **buffer_ptr
)
4053 gcc_assert (pp
->m_format_postprocessor
);
4054 cxx_format_postprocessor
*postprocessor
4055 = static_cast <cxx_format_postprocessor
*> (pp
->m_format_postprocessor
);
4059 #define next_tree (t = va_arg (*text->args_ptr, tree))
4060 #define next_tcode ((enum tree_code) va_arg (*text->args_ptr, int))
4061 #define next_lang ((enum languages) va_arg (*text->args_ptr, int))
4062 #define next_int va_arg (*text->args_ptr, int)
4064 if (precision
!= 0 || wide
)
4069 case 'A': result
= args_to_string (next_tree
, verbose
); break;
4070 case 'C': result
= code_to_string (next_tcode
); break;
4073 tree temp
= next_tree
;
4075 && DECL_HAS_DEBUG_EXPR_P (temp
))
4077 temp
= DECL_DEBUG_EXPR (temp
);
4080 result
= expr_to_string (temp
);
4084 result
= decl_to_string (temp
, verbose
);
4087 case 'E': result
= expr_to_string (next_tree
); break;
4088 case 'F': result
= fndecl_to_string (next_tree
, verbose
); break;
4090 percent_G_format (text
);
4093 defer_phase_2_of_type_diff (&postprocessor
->m_type_a
, next_tree
,
4094 buffer_ptr
, verbose
, *quoted
);
4097 defer_phase_2_of_type_diff (&postprocessor
->m_type_b
, next_tree
,
4098 buffer_ptr
, verbose
, *quoted
);
4101 t
= va_arg (*text
->args_ptr
, tree
);
4102 percent_K_format (text
, EXPR_LOCATION (t
), TREE_BLOCK (t
));
4104 case 'L': result
= language_to_string (next_lang
); break;
4105 case 'O': result
= op_to_string (false, next_tcode
); break;
4106 case 'P': result
= parm_to_string (next_int
); break;
4107 case 'Q': result
= op_to_string (true, next_tcode
); break;
4108 case 'S': result
= subst_to_string (next_tree
); break;
4111 result
= type_to_string (next_tree
, verbose
, false, quoted
,
4112 pp_show_color (pp
));
4115 case 'V': result
= cv_to_string (next_tree
, verbose
); break;
4116 case 'X': result
= eh_spec_to_string (next_tree
, verbose
); break;
4122 pp_string (pp
, result
);
4123 if (set_locus
&& t
!= NULL
)
4124 text
->set_location (0, location_of (t
), SHOW_RANGE_WITH_CARET
);
4132 /* Warn about the use of C++0x features when appropriate. */
4134 maybe_warn_cpp0x (cpp0x_warn_str str
)
4136 if ((cxx_dialect
== cxx98
) && !in_system_header_at (input_location
))
4137 /* We really want to suppress this warning in system headers,
4138 because libstdc++ uses variadic templates even when we aren't
4142 case CPP0X_INITIALIZER_LISTS
:
4143 pedwarn (input_location
, 0,
4144 "extended initializer lists "
4145 "only available with -std=c++11 or -std=gnu++11");
4147 case CPP0X_EXPLICIT_CONVERSION
:
4148 pedwarn (input_location
, 0,
4149 "explicit conversion operators "
4150 "only available with -std=c++11 or -std=gnu++11");
4152 case CPP0X_VARIADIC_TEMPLATES
:
4153 pedwarn (input_location
, 0,
4154 "variadic templates "
4155 "only available with -std=c++11 or -std=gnu++11");
4157 case CPP0X_LAMBDA_EXPR
:
4158 pedwarn (input_location
, 0,
4159 "lambda expressions "
4160 "only available with -std=c++11 or -std=gnu++11");
4163 pedwarn (input_location
, 0,
4164 "C++11 auto only available with -std=c++11 or -std=gnu++11");
4166 case CPP0X_SCOPED_ENUMS
:
4167 pedwarn (input_location
, 0,
4168 "scoped enums only available with -std=c++11 or -std=gnu++11");
4170 case CPP0X_DEFAULTED_DELETED
:
4171 pedwarn (input_location
, 0,
4172 "defaulted and deleted functions "
4173 "only available with -std=c++11 or -std=gnu++11");
4175 case CPP0X_INLINE_NAMESPACES
:
4176 pedwarn (input_location
, OPT_Wpedantic
,
4177 "inline namespaces "
4178 "only available with -std=c++11 or -std=gnu++11");
4180 case CPP0X_OVERRIDE_CONTROLS
:
4181 pedwarn (input_location
, 0,
4182 "override controls (override/final) "
4183 "only available with -std=c++11 or -std=gnu++11");
4186 pedwarn (input_location
, 0,
4187 "non-static data member initializers "
4188 "only available with -std=c++11 or -std=gnu++11");
4190 case CPP0X_USER_DEFINED_LITERALS
:
4191 pedwarn (input_location
, 0,
4192 "user-defined literals "
4193 "only available with -std=c++11 or -std=gnu++11");
4195 case CPP0X_DELEGATING_CTORS
:
4196 pedwarn (input_location
, 0,
4197 "delegating constructors "
4198 "only available with -std=c++11 or -std=gnu++11");
4200 case CPP0X_INHERITING_CTORS
:
4201 pedwarn (input_location
, 0,
4202 "inheriting constructors "
4203 "only available with -std=c++11 or -std=gnu++11");
4205 case CPP0X_ATTRIBUTES
:
4206 pedwarn (input_location
, 0,
4208 "only available with -std=c++11 or -std=gnu++11");
4210 case CPP0X_REF_QUALIFIER
:
4211 pedwarn (input_location
, 0,
4213 "only available with -std=c++11 or -std=gnu++11");
4220 /* Warn about the use of variadic templates when appropriate. */
4222 maybe_warn_variadic_templates (void)
4224 maybe_warn_cpp0x (CPP0X_VARIADIC_TEMPLATES
);
4228 /* Issue an ISO C++98 pedantic warning at LOCATION, conditional on
4229 option OPT with text GMSGID. Use this function to report
4230 diagnostics for constructs that are invalid C++98, but valid
4233 pedwarn_cxx98 (location_t location
, int opt
, const char *gmsgid
, ...)
4235 diagnostic_info diagnostic
;
4238 rich_location
richloc (line_table
, location
);
4240 va_start (ap
, gmsgid
);
4241 diagnostic_set_info (&diagnostic
, gmsgid
, &ap
, &richloc
,
4242 (cxx_dialect
== cxx98
) ? DK_PEDWARN
: DK_WARNING
);
4243 diagnostic
.option_index
= opt
;
4244 ret
= diagnostic_report_diagnostic (global_dc
, &diagnostic
);
4249 /* Issue a diagnostic that NAME cannot be found in SCOPE. DECL is what
4250 we found when we tried to do the lookup. LOCATION is the location of
4251 the NAME identifier. */
4254 qualified_name_lookup_error (tree scope
, tree name
,
4255 tree decl
, location_t location
)
4257 if (scope
== error_mark_node
)
4258 ; /* We already complained. */
4259 else if (TYPE_P (scope
))
4261 if (!COMPLETE_TYPE_P (scope
))
4262 error_at (location
, "incomplete type %qT used in nested name specifier",
4264 else if (TREE_CODE (decl
) == TREE_LIST
)
4266 error_at (location
, "reference to %<%T::%D%> is ambiguous",
4268 print_candidates (decl
);
4273 if (SCOPED_ENUM_P (scope
))
4274 hint
= suggest_alternative_in_scoped_enum (name
, scope
);
4275 if (const char *suggestion
= hint
.suggestion ())
4277 gcc_rich_location
richloc (location
);
4278 richloc
.add_fixit_replace (suggestion
);
4280 "%qD is not a member of %qT; did you mean %qs?",
4281 name
, scope
, suggestion
);
4284 error_at (location
, "%qD is not a member of %qT", name
, scope
);
4287 else if (scope
!= global_namespace
)
4289 auto_diagnostic_group d
;
4290 bool emit_fixit
= true;
4292 = suggest_alternative_in_explicit_scope (location
, name
, scope
);
4295 hint
= suggest_alternatives_in_other_namespaces (location
, name
);
4296 /* "location" is just the location of the name, not of the explicit
4297 scope, and it's not easy to get at the latter, so we can't issue
4298 fix-it hints for the suggestion. */
4301 if (const char *suggestion
= hint
.suggestion ())
4303 gcc_rich_location
richloc (location
);
4305 richloc
.add_fixit_replace (suggestion
);
4306 error_at (&richloc
, "%qD is not a member of %qD; did you mean %qs?",
4307 name
, scope
, suggestion
);
4310 error_at (location
, "%qD is not a member of %qD", name
, scope
);
4314 auto_diagnostic_group d
;
4315 name_hint hint
= suggest_alternatives_for (location
, name
, true);
4316 if (const char *suggestion
= hint
.suggestion ())
4318 gcc_rich_location
richloc (location
);
4319 richloc
.add_fixit_replace (suggestion
);
4321 "%<::%D%> has not been declared; did you mean %qs?",
4325 error_at (location
, "%<::%D%> has not been declared", name
);
4329 /* C++-specific implementation of range_label::get_text () vfunc for
4330 range_label_for_type_mismatch.
4332 Compare with print_template_differences above. */
4335 range_label_for_type_mismatch::get_text (unsigned /*range_idx*/) const
4337 if (m_labelled_type
== NULL_TREE
)
4338 return label_text (NULL
, false);
4340 const bool verbose
= false;
4341 const bool show_color
= false;
4345 && comparable_template_types_p (m_labelled_type
, m_other_type
))
4346 result
= type_to_string_with_compare (m_labelled_type
, m_other_type
,
4347 verbose
, show_color
);
4349 result
= type_to_string (m_labelled_type
, verbose
, true, NULL
, show_color
);
4351 /* Both of the above return GC-allocated buffers, so the caller mustn't
4353 return label_text (const_cast <char *> (result
), false);