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 (template_placeholder_p (t
))
551 t
= TREE_TYPE (CLASS_PLACEHOLDER_TEMPLATE (t
));
552 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
553 pp_string (pp
, "<...auto...>");
555 else if (TYPE_IDENTIFIER (t
))
556 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
558 pp_cxx_canonical_template_parameter
559 (pp
, TEMPLATE_TYPE_PARM_INDEX (t
));
562 /* This is not always necessary for pointers and such, but doing this
563 reduces code size. */
572 dump_type_prefix (pp
, t
, flags
);
573 dump_type_suffix (pp
, t
, flags
);
577 if (! (flags
& TFF_CHASE_TYPEDEF
)
578 && DECL_ORIGINAL_TYPE (TYPE_NAME (t
)))
580 dump_decl (pp
, TYPE_NAME (t
), TFF_PLAIN_IDENTIFIER
);
583 pp_cxx_cv_qualifier_seq (pp
, t
);
584 pp_cxx_ws_string (pp
,
585 TYPENAME_IS_ENUM_P (t
) ? "enum"
586 : TYPENAME_IS_CLASS_P (t
) ? "class"
588 dump_typename (pp
, t
, flags
);
591 case UNBOUND_CLASS_TEMPLATE
:
592 if (! (flags
& TFF_UNQUALIFIED_NAME
))
594 dump_type (pp
, TYPE_CONTEXT (t
), flags
);
595 pp_cxx_colon_colon (pp
);
597 pp_cxx_ws_string (pp
, "template");
598 dump_type (pp
, TYPE_IDENTIFIER (t
), flags
);
602 pp_cxx_ws_string (pp
, "__typeof__");
603 pp_cxx_whitespace (pp
);
604 pp_cxx_left_paren (pp
);
605 dump_expr (pp
, TYPEOF_TYPE_EXPR (t
), flags
& ~TFF_EXPR_IN_PARENS
);
606 pp_cxx_right_paren (pp
);
609 case UNDERLYING_TYPE
:
610 pp_cxx_ws_string (pp
, "__underlying_type");
611 pp_cxx_whitespace (pp
);
612 pp_cxx_left_paren (pp
);
613 dump_expr (pp
, UNDERLYING_TYPE_TYPE (t
), flags
& ~TFF_EXPR_IN_PARENS
);
614 pp_cxx_right_paren (pp
);
617 case TYPE_PACK_EXPANSION
:
618 dump_type (pp
, PACK_EXPANSION_PATTERN (t
), flags
);
619 pp_cxx_ws_string (pp
, "...");
622 case TYPE_ARGUMENT_PACK
:
623 dump_template_argument (pp
, t
, flags
);
627 pp_cxx_ws_string (pp
, "decltype");
628 pp_cxx_whitespace (pp
);
629 pp_cxx_left_paren (pp
);
630 dump_expr (pp
, DECLTYPE_TYPE_EXPR (t
), flags
& ~TFF_EXPR_IN_PARENS
);
631 pp_cxx_right_paren (pp
);
635 pp_string (pp
, "std::nullptr_t");
639 pp_unsupported_tree (pp
, t
);
643 pp_string (pp
, M_("<type error>"));
648 /* Dump a TYPENAME_TYPE. We need to notice when the context is itself
652 dump_typename (cxx_pretty_printer
*pp
, tree t
, int flags
)
654 tree ctx
= TYPE_CONTEXT (t
);
656 if (TREE_CODE (ctx
) == TYPENAME_TYPE
)
657 dump_typename (pp
, ctx
, flags
);
659 dump_type (pp
, ctx
, flags
& ~TFF_CLASS_KEY_OR_ENUM
);
660 pp_cxx_colon_colon (pp
);
661 dump_decl (pp
, TYPENAME_TYPE_FULLNAME (t
), flags
);
664 /* Return the name of the supplied aggregate, or enumeral type. */
667 class_key_or_enum_as_string (tree t
)
669 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
671 if (SCOPED_ENUM_P (t
))
676 else if (TREE_CODE (t
) == UNION_TYPE
)
678 else if (TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_DECLARED_CLASS (t
))
684 /* Print out a class declaration T under the control of FLAGS,
685 in the form `class foo'. */
688 dump_aggr_type (cxx_pretty_printer
*pp
, tree t
, int flags
)
691 const char *variety
= class_key_or_enum_as_string (t
);
695 pp_cxx_cv_qualifier_seq (pp
, t
);
697 if (flags
& TFF_CLASS_KEY_OR_ENUM
)
698 pp_cxx_ws_string (pp
, variety
);
700 name
= TYPE_NAME (t
);
704 typdef
= (!DECL_ARTIFICIAL (name
)
705 /* An alias specialization is not considered to be a
707 && !alias_template_specialization_p (t
));
710 && ((flags
& TFF_CHASE_TYPEDEF
)
711 || (!flag_pretty_templates
&& DECL_LANG_SPECIFIC (name
)
712 && DECL_TEMPLATE_INFO (name
))))
713 || DECL_SELF_REFERENCE_P (name
))
715 t
= TYPE_MAIN_VARIANT (t
);
716 name
= TYPE_NAME (t
);
720 tmplate
= !typdef
&& TREE_CODE (t
) != ENUMERAL_TYPE
721 && TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_TEMPLATE_INFO (t
)
722 && (TREE_CODE (CLASSTYPE_TI_TEMPLATE (t
)) != TEMPLATE_DECL
723 || PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t
)));
725 if (! (flags
& TFF_UNQUALIFIED_NAME
))
726 dump_scope (pp
, CP_DECL_CONTEXT (name
), flags
| TFF_SCOPE
);
727 flags
&= ~TFF_UNQUALIFIED_NAME
;
730 /* Because the template names are mangled, we have to locate
731 the most general template, and use that name. */
732 tree tpl
= TYPE_TI_TEMPLATE (t
);
734 while (DECL_TEMPLATE_INFO (tpl
))
735 tpl
= DECL_TI_TEMPLATE (tpl
);
738 name
= DECL_NAME (name
);
741 if (!name
|| IDENTIFIER_ANON_P (name
))
743 if (flags
& TFF_CLASS_KEY_OR_ENUM
)
744 pp_string (pp
, M_("<unnamed>"));
746 pp_printf (pp
, M_("<unnamed %s>"), variety
);
748 else if (LAMBDA_TYPE_P (t
))
750 /* A lambda's "type" is essentially its signature. */
751 pp_string (pp
, M_("<lambda"));
752 if (lambda_function (t
))
754 FUNCTION_FIRST_USER_PARMTYPE (lambda_function (t
)),
759 pp_cxx_tree_identifier (pp
, name
);
761 dump_template_parms (pp
, TYPE_TEMPLATE_INFO (t
),
762 !CLASSTYPE_USE_TEMPLATE (t
),
763 flags
& ~TFF_TEMPLATE_HEADER
);
766 /* Dump into the obstack the initial part of the output for a given type.
767 This is necessary when dealing with things like functions returning
770 return type of `int (* fee ())()': pointer -> function -> int. Both
771 pointer (and reference and offset) and function (and member) types must
772 deal with prefix and suffix.
774 Arrays must also do this for DECL nodes, like int a[], and for things like
778 dump_type_prefix (cxx_pretty_printer
*pp
, tree t
, int flags
)
780 if (TYPE_PTRMEMFUNC_P (t
))
782 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
786 switch (TREE_CODE (t
))
791 tree sub
= TREE_TYPE (t
);
793 dump_type_prefix (pp
, sub
, flags
);
794 if (TREE_CODE (sub
) == ARRAY_TYPE
795 || TREE_CODE (sub
) == FUNCTION_TYPE
)
797 pp_cxx_whitespace (pp
);
798 pp_cxx_left_paren (pp
);
799 pp_c_attributes_display (pp
, TYPE_ATTRIBUTES (sub
));
803 else if (TYPE_REF_P (t
))
805 if (TYPE_REF_IS_RVALUE (t
))
806 pp_ampersand_ampersand (pp
);
810 pp
->padding
= pp_before
;
811 pp_cxx_cv_qualifier_seq (pp
, t
);
817 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
818 if (TREE_CODE (t
) == OFFSET_TYPE
) /* pmfs deal with this in d_t_p */
821 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
822 pp_cxx_left_paren (pp
);
823 dump_type (pp
, TYPE_OFFSET_BASETYPE (t
), flags
);
824 pp_cxx_colon_colon (pp
);
827 pp_cxx_cv_qualifier_seq (pp
, t
);
828 pp
->padding
= pp_before
;
831 /* This can be reached without a pointer when dealing with
832 templates, e.g. std::is_function. */
834 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
838 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
840 pp_cxx_left_paren (pp
);
841 dump_aggr_type (pp
, TYPE_METHOD_BASETYPE (t
), flags
);
842 pp_cxx_colon_colon (pp
);
846 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
850 case IDENTIFIER_NODE
:
855 case TEMPLATE_TYPE_PARM
:
856 case TEMPLATE_TEMPLATE_PARM
:
857 case BOUND_TEMPLATE_TEMPLATE_PARM
:
868 case UNDERLYING_TYPE
:
870 case TYPE_PACK_EXPANSION
:
871 case FIXED_POINT_TYPE
:
873 dump_type (pp
, t
, flags
);
874 pp
->padding
= pp_before
;
878 pp_unsupported_tree (pp
, t
);
881 pp_string (pp
, M_("<typeprefixerror>"));
886 /* Dump the suffix of type T, under control of FLAGS. This is the part
887 which appears after the identifier (or function parms). */
890 dump_type_suffix (cxx_pretty_printer
*pp
, tree t
, int flags
)
892 if (TYPE_PTRMEMFUNC_P (t
))
893 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
895 switch (TREE_CODE (t
))
900 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
901 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
902 pp_cxx_right_paren (pp
);
903 if (TREE_CODE (t
) == POINTER_TYPE
)
904 flags
|= TFF_POINTER
;
905 dump_type_suffix (pp
, TREE_TYPE (t
), flags
);
912 if (TREE_CODE (t
) == METHOD_TYPE
)
913 /* Can only be reached through a pointer. */
914 pp_cxx_right_paren (pp
);
915 arg
= TYPE_ARG_TYPES (t
);
916 if (TREE_CODE (t
) == METHOD_TYPE
)
917 arg
= TREE_CHAIN (arg
);
919 /* Function pointers don't have default args. Not in standard C++,
920 anyway; they may in g++, but we'll just pretend otherwise. */
921 dump_parameters (pp
, arg
, flags
& ~TFF_FUNCTION_DEFAULT_ARGUMENTS
);
923 pp
->padding
= pp_before
;
924 pp_cxx_cv_qualifiers (pp
, type_memfn_quals (t
),
925 TREE_CODE (t
) == FUNCTION_TYPE
926 && (flags
& TFF_POINTER
));
927 dump_ref_qualifier (pp
, t
, flags
);
928 if (tx_safe_fn_type_p (t
))
929 pp_cxx_ws_string (pp
, "transaction_safe");
930 dump_exception_spec (pp
, TYPE_RAISES_EXCEPTIONS (t
), flags
);
931 dump_type_suffix (pp
, TREE_TYPE (t
), flags
);
937 pp_cxx_left_bracket (pp
);
938 if (tree dtype
= TYPE_DOMAIN (t
))
940 tree max
= TYPE_MAX_VALUE (dtype
);
941 /* Zero-length arrays have an upper bound of SIZE_MAX. */
942 if (integer_all_onesp (max
))
943 pp_character (pp
, '0');
944 else if (tree_fits_shwi_p (max
))
945 pp_wide_integer (pp
, tree_to_shwi (max
) + 1);
949 if (TREE_CODE (max
) == SAVE_EXPR
)
950 max
= TREE_OPERAND (max
, 0);
951 if (TREE_CODE (max
) == MINUS_EXPR
952 || TREE_CODE (max
) == PLUS_EXPR
)
954 max
= TREE_OPERAND (max
, 0);
955 while (CONVERT_EXPR_P (max
))
956 max
= TREE_OPERAND (max
, 0);
959 max
= fold_build2_loc (input_location
,
960 PLUS_EXPR
, dtype
, max
,
961 build_int_cst (dtype
, 1));
962 dump_expr (pp
, max
, flags
& ~TFF_EXPR_IN_PARENS
);
965 pp_cxx_right_bracket (pp
);
966 dump_type_suffix (pp
, TREE_TYPE (t
), flags
);
970 case IDENTIFIER_NODE
:
975 case TEMPLATE_TYPE_PARM
:
976 case TEMPLATE_TEMPLATE_PARM
:
977 case BOUND_TEMPLATE_TEMPLATE_PARM
:
988 case UNDERLYING_TYPE
:
990 case TYPE_PACK_EXPANSION
:
991 case FIXED_POINT_TYPE
:
996 pp_unsupported_tree (pp
, t
);
998 /* Don't mark it here, we should have already done in
1005 dump_global_iord (cxx_pretty_printer
*pp
, tree t
)
1007 const char *p
= NULL
;
1009 if (DECL_GLOBAL_CTOR_P (t
))
1010 p
= M_("(static initializers for %s)");
1011 else if (DECL_GLOBAL_DTOR_P (t
))
1012 p
= M_("(static destructors for %s)");
1016 pp_printf (pp
, p
, DECL_SOURCE_FILE (t
));
1020 dump_simple_decl (cxx_pretty_printer
*pp
, tree t
, tree type
, int flags
)
1022 if (template_parm_object_p (t
))
1023 return dump_expr (pp
, DECL_INITIAL (t
), flags
);
1025 if (flags
& TFF_DECL_SPECIFIERS
)
1027 if (VAR_P (t
) && DECL_DECLARED_CONSTEXPR_P (t
))
1029 if (DECL_LANG_SPECIFIC (t
) && DECL_DECLARED_CONCEPT_P (t
))
1030 pp_cxx_ws_string (pp
, "concept");
1032 pp_cxx_ws_string (pp
, "constexpr");
1034 dump_type_prefix (pp
, type
, flags
& ~TFF_UNQUALIFIED_NAME
);
1035 pp_maybe_space (pp
);
1037 if (! (flags
& TFF_UNQUALIFIED_NAME
)
1038 && TREE_CODE (t
) != PARM_DECL
1039 && (!DECL_INITIAL (t
)
1040 || TREE_CODE (DECL_INITIAL (t
)) != TEMPLATE_PARM_INDEX
))
1041 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1042 flags
&= ~TFF_UNQUALIFIED_NAME
;
1043 if ((flags
& TFF_DECL_SPECIFIERS
)
1044 && DECL_TEMPLATE_PARM_P (t
)
1045 && TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (t
)))
1046 pp_string (pp
, "...");
1049 if (TREE_CODE (t
) == FIELD_DECL
&& DECL_NORMAL_CAPTURE_P (t
))
1052 pp_string (pp
, IDENTIFIER_POINTER (DECL_NAME (t
)) + 2);
1053 pp_string (pp
, " capture>");
1056 dump_decl (pp
, DECL_NAME (t
), flags
);
1058 else if (DECL_DECOMPOSITION_P (t
))
1059 pp_string (pp
, M_("<structured bindings>"));
1061 pp_string (pp
, M_("<anonymous>"));
1062 if (flags
& TFF_DECL_SPECIFIERS
)
1063 dump_type_suffix (pp
, type
, flags
);
1066 /* Print an IDENTIFIER_NODE that is the name of a declaration. */
1069 dump_decl_name (cxx_pretty_printer
*pp
, tree t
, int flags
)
1071 /* These special cases are duplicated here so that other functions
1072 can feed identifiers to error and get them demangled properly. */
1073 if (IDENTIFIER_CONV_OP_P (t
))
1075 pp_cxx_ws_string (pp
, "operator");
1076 /* Not exactly IDENTIFIER_TYPE_VALUE. */
1077 dump_type (pp
, TREE_TYPE (t
), flags
);
1080 if (dguide_name_p (t
))
1082 dump_decl (pp
, CLASSTYPE_TI_TEMPLATE (TREE_TYPE (t
)),
1083 TFF_UNQUALIFIED_NAME
);
1087 const char *str
= IDENTIFIER_POINTER (t
);
1088 if (!strncmp (str
, "_ZGR", 3))
1090 pp_cxx_ws_string (pp
, "<temporary>");
1094 pp_cxx_tree_identifier (pp
, t
);
1097 /* Dump a human readable string for the decl T under control of FLAGS. */
1100 dump_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
1105 /* If doing Objective-C++, give Objective-C a chance to demangle
1106 Objective-C method names. */
1107 if (c_dialect_objc ())
1109 const char *demangled
= objc_maybe_printable_name (t
, flags
);
1112 pp_string (pp
, demangled
);
1117 switch (TREE_CODE (t
))
1120 /* Don't say 'typedef class A' */
1121 if (DECL_ARTIFICIAL (t
) && !DECL_SELF_REFERENCE_P (t
))
1123 if ((flags
& TFF_DECL_SPECIFIERS
)
1124 && TREE_CODE (TREE_TYPE (t
)) == TEMPLATE_TYPE_PARM
)
1126 /* Say `class T' not just `T'. */
1127 pp_cxx_ws_string (pp
, "class");
1129 /* Emit the `...' for a parameter pack. */
1130 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t
)))
1131 pp_cxx_ws_string (pp
, "...");
1134 dump_type (pp
, TREE_TYPE (t
), flags
);
1137 if (TYPE_DECL_ALIAS_P (t
)
1138 && (flags
& TFF_DECL_SPECIFIERS
1139 || flags
& TFF_CLASS_KEY_OR_ENUM
))
1141 pp_cxx_ws_string (pp
, "using");
1142 dump_decl (pp
, DECL_NAME (t
), flags
);
1143 pp_cxx_whitespace (pp
);
1144 pp_cxx_ws_string (pp
, "=");
1145 pp_cxx_whitespace (pp
);
1146 dump_type (pp
, (DECL_ORIGINAL_TYPE (t
)
1147 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
)),
1151 if ((flags
& TFF_DECL_SPECIFIERS
)
1152 && !DECL_SELF_REFERENCE_P (t
))
1153 pp_cxx_ws_string (pp
, "typedef");
1154 dump_simple_decl (pp
, t
, DECL_ORIGINAL_TYPE (t
)
1155 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
),
1160 if (DECL_NAME (t
) && VTABLE_NAME_P (DECL_NAME (t
)))
1162 pp_string (pp
, M_("vtable for "));
1163 gcc_assert (TYPE_P (DECL_CONTEXT (t
)));
1164 dump_type (pp
, DECL_CONTEXT (t
), flags
);
1170 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1172 /* Handle variable template specializations. */
1174 && DECL_LANG_SPECIFIC (t
)
1175 && DECL_TEMPLATE_INFO (t
)
1176 && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t
)))
1178 pp_cxx_begin_template_argument_list (pp
);
1179 tree args
= INNERMOST_TEMPLATE_ARGS (DECL_TI_ARGS (t
));
1180 dump_template_argument_list (pp
, args
, flags
);
1181 pp_cxx_end_template_argument_list (pp
);
1186 pp_string (pp
, M_("<return value> "));
1187 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1190 case NAMESPACE_DECL
:
1191 if (flags
& TFF_DECL_SPECIFIERS
)
1192 pp
->declaration (t
);
1195 if (! (flags
& TFF_UNQUALIFIED_NAME
))
1196 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1197 flags
&= ~TFF_UNQUALIFIED_NAME
;
1198 if (DECL_NAME (t
) == NULL_TREE
)
1200 if (!(pp
->flags
& pp_c_flag_gnu_v3
))
1201 pp_cxx_ws_string (pp
, M_("{anonymous}"));
1203 pp_cxx_ws_string (pp
, M_("(anonymous namespace)"));
1206 pp_cxx_tree_identifier (pp
, DECL_NAME (t
));
1211 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
1212 pp_cxx_colon_colon (pp
);
1213 dump_decl (pp
, TREE_OPERAND (t
, 1), TFF_UNQUALIFIED_NAME
);
1217 dump_decl (pp
, TREE_OPERAND (t
, 0), flags
);
1218 pp_cxx_left_bracket (pp
);
1219 dump_decl (pp
, TREE_OPERAND (t
, 1), flags
);
1220 pp_cxx_right_bracket (pp
);
1223 /* So that we can do dump_decl on an aggr type. */
1227 dump_type (pp
, t
, flags
);
1231 /* This is a pseudo destructor call which has not been folded into
1232 a PSEUDO_DTOR_EXPR yet. */
1233 pp_cxx_complement (pp
);
1234 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
1241 case IDENTIFIER_NODE
:
1242 dump_decl_name (pp
, t
, flags
);
1246 if (!OVL_SINGLE_P (t
))
1248 tree ctx
= ovl_scope (t
);
1249 if (ctx
!= global_namespace
)
1252 dump_type (pp
, ctx
, flags
);
1254 dump_decl (pp
, ctx
, flags
);
1255 pp_cxx_colon_colon (pp
);
1257 dump_decl (pp
, OVL_NAME (t
), flags
);
1261 /* If there's only one function, just treat it like an ordinary
1267 if (! DECL_LANG_SPECIFIC (t
))
1269 if (DECL_ABSTRACT_ORIGIN (t
)
1270 && DECL_ABSTRACT_ORIGIN (t
) != t
)
1271 dump_decl (pp
, DECL_ABSTRACT_ORIGIN (t
), flags
);
1273 dump_function_name (pp
, t
, flags
);
1275 else if (DECL_GLOBAL_CTOR_P (t
) || DECL_GLOBAL_DTOR_P (t
))
1276 dump_global_iord (pp
, t
);
1278 dump_function_decl (pp
, t
, flags
);
1282 dump_template_decl (pp
, t
, flags
);
1285 case TEMPLATE_ID_EXPR
:
1287 tree name
= TREE_OPERAND (t
, 0);
1288 tree args
= TREE_OPERAND (t
, 1);
1290 if (!identifier_p (name
))
1291 name
= OVL_NAME (name
);
1292 dump_decl (pp
, name
, flags
);
1293 pp_cxx_begin_template_argument_list (pp
);
1294 if (args
== error_mark_node
)
1295 pp_string (pp
, M_("<template arguments error>"));
1297 dump_template_argument_list
1298 (pp
, args
, flags
|TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS
);
1299 pp_cxx_end_template_argument_list (pp
);
1304 pp_cxx_tree_identifier (pp
, DECL_NAME (t
));
1308 if ((TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == ENUMERAL_TYPE
)
1309 || (DECL_INITIAL (t
) &&
1310 TREE_CODE (DECL_INITIAL (t
)) == TEMPLATE_PARM_INDEX
))
1311 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1312 else if (DECL_NAME (t
))
1313 dump_decl (pp
, DECL_NAME (t
), flags
);
1314 else if (DECL_INITIAL (t
))
1315 dump_expr (pp
, DECL_INITIAL (t
), flags
| TFF_EXPR_IN_PARENS
);
1317 pp_string (pp
, M_("<enumerator>"));
1322 pp_cxx_ws_string (pp
, "using");
1323 tree scope
= USING_DECL_SCOPE (t
);
1324 bool variadic
= false;
1325 if (PACK_EXPANSION_P (scope
))
1327 scope
= PACK_EXPANSION_PATTERN (scope
);
1330 dump_type (pp
, scope
, flags
);
1331 pp_cxx_colon_colon (pp
);
1332 dump_decl (pp
, DECL_NAME (t
), flags
);
1334 pp_cxx_ws_string (pp
, "...");
1339 pp
->declaration (t
);
1343 dump_decl (pp
, BASELINK_FUNCTIONS (t
), flags
);
1346 case NON_DEPENDENT_EXPR
:
1347 dump_expr (pp
, t
, flags
);
1350 case TEMPLATE_TYPE_PARM
:
1351 if (flags
& TFF_DECL_SPECIFIERS
)
1352 pp
->declaration (t
);
1357 case UNBOUND_CLASS_TEMPLATE
:
1358 case TYPE_PACK_EXPANSION
:
1360 dump_type (pp
, t
, flags
);
1364 pp_unsupported_tree (pp
, t
);
1368 pp_string (pp
, M_("<declaration error>"));
1373 /* Dump a template declaration T under control of FLAGS. This means the
1374 'template <...> leaders plus the 'class X' or 'void fn(...)' part. */
1377 dump_template_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
1379 tree orig_parms
= DECL_TEMPLATE_PARMS (t
);
1383 if (flags
& TFF_TEMPLATE_HEADER
)
1385 for (parms
= orig_parms
= nreverse (orig_parms
);
1387 parms
= TREE_CHAIN (parms
))
1389 tree inner_parms
= INNERMOST_TEMPLATE_PARMS (parms
);
1390 int len
= TREE_VEC_LENGTH (inner_parms
);
1394 /* Skip over the dummy template levels of a template template
1396 gcc_assert (TREE_CODE (TREE_TYPE (t
)) == TEMPLATE_TEMPLATE_PARM
);
1400 pp_cxx_ws_string (pp
, "template");
1401 pp_cxx_begin_template_argument_list (pp
);
1403 /* If we've shown the template prefix, we'd better show the
1404 parameters' and decl's type too. */
1405 flags
|= TFF_DECL_SPECIFIERS
;
1407 for (i
= 0; i
< len
; i
++)
1410 pp_separate_with_comma (pp
);
1411 dump_template_parameter (pp
, TREE_VEC_ELT (inner_parms
, i
),
1414 pp_cxx_end_template_argument_list (pp
);
1415 pp_cxx_whitespace (pp
);
1417 nreverse(orig_parms
);
1419 if (DECL_TEMPLATE_TEMPLATE_PARM_P (t
))
1421 /* Say `template<arg> class TT' not just `template<arg> TT'. */
1422 pp_cxx_ws_string (pp
, "class");
1424 /* If this is a parameter pack, print the ellipsis. */
1425 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t
)))
1426 pp_cxx_ws_string (pp
, "...");
1429 /* Only print the requirements if we're also printing
1430 the template header. */
1432 if (tree ci
= get_constraints (t
))
1433 if (check_constraint_info (ci
))
1434 if (tree reqs
= CI_TEMPLATE_REQS (ci
))
1436 pp_cxx_requires_clause (pp
, reqs
);
1437 pp_cxx_whitespace (pp
);
1442 if (DECL_CLASS_TEMPLATE_P (t
))
1443 dump_type (pp
, TREE_TYPE (t
),
1444 ((flags
& ~TFF_CLASS_KEY_OR_ENUM
) | TFF_TEMPLATE_NAME
1445 | (flags
& TFF_DECL_SPECIFIERS
? TFF_CLASS_KEY_OR_ENUM
: 0)));
1446 else if (DECL_TEMPLATE_RESULT (t
)
1447 && (VAR_P (DECL_TEMPLATE_RESULT (t
))
1448 /* Alias template. */
1449 || DECL_TYPE_TEMPLATE_P (t
)))
1450 dump_decl (pp
, DECL_TEMPLATE_RESULT (t
), flags
| TFF_TEMPLATE_NAME
);
1453 gcc_assert (TREE_TYPE (t
));
1454 switch (NEXT_CODE (t
))
1458 dump_function_decl (pp
, t
, flags
| TFF_TEMPLATE_NAME
);
1461 /* This case can occur with some invalid code. */
1462 dump_type (pp
, TREE_TYPE (t
),
1463 (flags
& ~TFF_CLASS_KEY_OR_ENUM
) | TFF_TEMPLATE_NAME
1464 | (flags
& TFF_DECL_SPECIFIERS
1465 ? TFF_CLASS_KEY_OR_ENUM
: 0));
1470 /* find_typenames looks through the type of the function template T
1471 and returns a vec containing any typedefs, decltypes or TYPENAME_TYPEs
1474 struct find_typenames_t
1476 hash_set
<tree
> *p_set
;
1477 vec
<tree
, va_gc
> *typenames
;
1481 find_typenames_r (tree
*tp
, int *walk_subtrees
, void *data
)
1483 struct find_typenames_t
*d
= (struct find_typenames_t
*)data
;
1484 tree mv
= NULL_TREE
;
1486 if (TYPE_P (*tp
) && is_typedef_decl (TYPE_NAME (*tp
)))
1487 /* Add the type of the typedef without any additional cv-quals. */
1488 mv
= TREE_TYPE (TYPE_NAME (*tp
));
1489 else if (TREE_CODE (*tp
) == TYPENAME_TYPE
1490 || TREE_CODE (*tp
) == DECLTYPE_TYPE
)
1491 /* Add the typename without any cv-qualifiers. */
1492 mv
= TYPE_MAIN_VARIANT (*tp
);
1494 if (PACK_EXPANSION_P (*tp
))
1496 /* Don't mess with parameter packs since we don't remember
1497 the pack expansion context for a particular typename. */
1498 *walk_subtrees
= false;
1502 if (mv
&& (mv
== *tp
|| !d
->p_set
->add (mv
)))
1503 vec_safe_push (d
->typenames
, mv
);
1505 /* Search into class template arguments, which cp_walk_subtrees
1507 if (CLASS_TYPE_P (*tp
) && CLASSTYPE_TEMPLATE_INFO (*tp
))
1508 cp_walk_tree (&CLASSTYPE_TI_ARGS (*tp
), find_typenames_r
,
1514 static vec
<tree
, va_gc
> *
1515 find_typenames (tree t
)
1517 struct find_typenames_t ft
;
1518 ft
.p_set
= new hash_set
<tree
>;
1519 ft
.typenames
= NULL
;
1520 cp_walk_tree (&TREE_TYPE (DECL_TEMPLATE_RESULT (t
)),
1521 find_typenames_r
, &ft
, ft
.p_set
);
1523 return ft
.typenames
;
1526 /* Output the "[with ...]" clause for a template instantiation T iff
1527 TEMPLATE_PARMS, TEMPLATE_ARGS and FLAGS are suitable. T may be NULL if
1528 formatting a deduction/substitution diagnostic rather than an
1532 dump_substitution (cxx_pretty_printer
*pp
,
1533 tree t
, tree template_parms
, tree template_args
,
1536 if (template_parms
!= NULL_TREE
&& template_args
!= NULL_TREE
1537 && !(flags
& TFF_NO_TEMPLATE_BINDINGS
))
1539 vec
<tree
, va_gc
> *typenames
= t
? find_typenames (t
) : NULL
;
1540 pp_cxx_whitespace (pp
);
1541 pp_cxx_left_bracket (pp
);
1542 pp
->translate_string ("with");
1543 pp_cxx_whitespace (pp
);
1544 dump_template_bindings (pp
, template_parms
, template_args
, typenames
);
1545 pp_cxx_right_bracket (pp
);
1549 /* Dump the lambda function FN including its 'mutable' qualifier and any
1550 template bindings. */
1553 dump_lambda_function (cxx_pretty_printer
*pp
,
1554 tree fn
, tree template_parms
, tree template_args
,
1557 /* A lambda's signature is essentially its "type". */
1558 dump_type (pp
, DECL_CONTEXT (fn
), flags
);
1559 if (!(TYPE_QUALS (class_of_this_parm (TREE_TYPE (fn
))) & TYPE_QUAL_CONST
))
1561 pp
->padding
= pp_before
;
1562 pp_c_ws_string (pp
, "mutable");
1564 dump_substitution (pp
, fn
, template_parms
, template_args
, flags
);
1567 /* Pretty print a function decl. There are several ways we want to print a
1568 function declaration. The TFF_ bits in FLAGS tells us how to behave.
1569 As error can only apply the '#' flag once to give 0 and 1 for V, there
1570 is %D which doesn't print the throw specs, and %F which does. */
1573 dump_function_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
1577 tree cname
= NULL_TREE
;
1578 tree template_args
= NULL_TREE
;
1579 tree template_parms
= NULL_TREE
;
1580 int show_return
= flags
& TFF_RETURN_TYPE
|| flags
& TFF_DECL_SPECIFIERS
;
1581 int do_outer_scope
= ! (flags
& TFF_UNQUALIFIED_NAME
);
1584 tree ret
= NULL_TREE
;
1586 flags
&= ~(TFF_UNQUALIFIED_NAME
| TFF_TEMPLATE_NAME
);
1587 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1588 t
= DECL_TEMPLATE_RESULT (t
);
1590 /* Save the exceptions, in case t is a specialization and we are
1591 emitting an error about incompatible specifications. */
1592 exceptions
= TYPE_RAISES_EXCEPTIONS (TREE_TYPE (t
));
1594 /* Likewise for the constexpr specifier, in case t is a specialization. */
1595 constexpr_p
= DECL_DECLARED_CONSTEXPR_P (t
);
1597 /* Pretty print template instantiations only. */
1598 if (DECL_USE_TEMPLATE (t
) && DECL_TEMPLATE_INFO (t
)
1599 && !(flags
& TFF_NO_TEMPLATE_BINDINGS
)
1600 && flag_pretty_templates
)
1604 template_args
= DECL_TI_ARGS (t
);
1605 tmpl
= most_general_template (t
);
1606 if (tmpl
&& TREE_CODE (tmpl
) == TEMPLATE_DECL
)
1608 template_parms
= DECL_TEMPLATE_PARMS (tmpl
);
1613 if (DECL_NAME (t
) && LAMBDA_FUNCTION_P (t
))
1614 return dump_lambda_function (pp
, t
, template_parms
, template_args
, flags
);
1616 fntype
= TREE_TYPE (t
);
1617 parmtypes
= FUNCTION_FIRST_USER_PARMTYPE (t
);
1619 if (DECL_CLASS_SCOPE_P (t
))
1620 cname
= DECL_CONTEXT (t
);
1621 /* This is for partially instantiated template methods. */
1622 else if (TREE_CODE (fntype
) == METHOD_TYPE
)
1623 cname
= TREE_TYPE (TREE_VALUE (parmtypes
));
1625 if (flags
& TFF_DECL_SPECIFIERS
)
1627 if (DECL_STATIC_FUNCTION_P (t
))
1628 pp_cxx_ws_string (pp
, "static");
1629 else if (DECL_VIRTUAL_P (t
))
1630 pp_cxx_ws_string (pp
, "virtual");
1634 if (DECL_DECLARED_CONCEPT_P (t
))
1635 pp_cxx_ws_string (pp
, "concept");
1637 pp_cxx_ws_string (pp
, "constexpr");
1641 /* Print the return type? */
1643 show_return
= (!DECL_CONV_FN_P (t
) && !DECL_CONSTRUCTOR_P (t
)
1644 && !DECL_DESTRUCTOR_P (t
) && !deduction_guide_p (t
));
1647 ret
= fndecl_declared_return_type (t
);
1648 dump_type_prefix (pp
, ret
, flags
);
1651 /* Print the function name. */
1652 if (!do_outer_scope
)
1656 dump_type (pp
, cname
, flags
);
1657 pp_cxx_colon_colon (pp
);
1660 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1662 dump_function_name (pp
, t
, flags
);
1664 if (!(flags
& TFF_NO_FUNCTION_ARGUMENTS
))
1666 dump_parameters (pp
, parmtypes
, flags
);
1668 if (TREE_CODE (fntype
) == METHOD_TYPE
)
1670 pp
->padding
= pp_before
;
1671 pp_cxx_cv_qualifier_seq (pp
, class_of_this_parm (fntype
));
1672 dump_ref_qualifier (pp
, fntype
, flags
);
1675 if (tx_safe_fn_type_p (fntype
))
1677 pp
->padding
= pp_before
;
1678 pp_cxx_ws_string (pp
, "transaction_safe");
1681 if (flags
& TFF_EXCEPTION_SPECIFICATION
)
1683 pp
->padding
= pp_before
;
1684 dump_exception_spec (pp
, exceptions
, flags
);
1688 dump_type_suffix (pp
, ret
, flags
);
1689 else if (deduction_guide_p (t
))
1691 pp_cxx_ws_string (pp
, "->");
1692 dump_type (pp
, TREE_TYPE (TREE_TYPE (t
)), flags
);
1696 if (tree ci
= get_constraints (t
))
1697 if (tree reqs
= CI_DECLARATOR_REQS (ci
))
1698 pp_cxx_requires_clause (pp
, reqs
);
1700 dump_substitution (pp
, t
, template_parms
, template_args
, flags
);
1702 if (tree base
= DECL_INHERITED_CTOR_BASE (t
))
1704 pp_cxx_ws_string (pp
, "[inherited from");
1705 dump_type (pp
, base
, TFF_PLAIN_IDENTIFIER
);
1706 pp_character (pp
, ']');
1709 else if (template_args
)
1711 bool need_comma
= false;
1713 pp_cxx_begin_template_argument_list (pp
);
1714 template_args
= INNERMOST_TEMPLATE_ARGS (template_args
);
1715 for (i
= 0; i
< TREE_VEC_LENGTH (template_args
); ++i
)
1717 tree arg
= TREE_VEC_ELT (template_args
, i
);
1719 pp_separate_with_comma (pp
);
1720 if (ARGUMENT_PACK_P (arg
))
1721 pp_cxx_left_brace (pp
);
1722 dump_template_argument (pp
, arg
, TFF_PLAIN_IDENTIFIER
);
1723 if (ARGUMENT_PACK_P (arg
))
1724 pp_cxx_right_brace (pp
);
1727 pp_cxx_end_template_argument_list (pp
);
1731 /* Print a parameter list. If this is for a member function, the
1732 member object ptr (and any other hidden args) should have
1733 already been removed. */
1736 dump_parameters (cxx_pretty_printer
*pp
, tree parmtypes
, int flags
)
1739 flags
&= ~TFF_SCOPE
;
1740 pp_cxx_left_paren (pp
);
1742 for (first
= 1; parmtypes
!= void_list_node
;
1743 parmtypes
= TREE_CHAIN (parmtypes
))
1746 pp_separate_with_comma (pp
);
1750 pp_cxx_ws_string (pp
, "...");
1754 dump_type (pp
, TREE_VALUE (parmtypes
), flags
);
1756 if ((flags
& TFF_FUNCTION_DEFAULT_ARGUMENTS
) && TREE_PURPOSE (parmtypes
))
1758 pp_cxx_whitespace (pp
);
1760 pp_cxx_whitespace (pp
);
1761 dump_expr (pp
, TREE_PURPOSE (parmtypes
), flags
| TFF_EXPR_IN_PARENS
);
1765 pp_cxx_right_paren (pp
);
1768 /* Print ref-qualifier of a FUNCTION_TYPE or METHOD_TYPE. FLAGS are ignored. */
1771 dump_ref_qualifier (cxx_pretty_printer
*pp
, tree t
, int flags ATTRIBUTE_UNUSED
)
1773 if (FUNCTION_REF_QUALIFIED (t
))
1775 pp
->padding
= pp_before
;
1776 if (FUNCTION_RVALUE_QUALIFIED (t
))
1777 pp_cxx_ws_string (pp
, "&&");
1779 pp_cxx_ws_string (pp
, "&");
1783 /* Print an exception specification. T is the exception specification. */
1786 dump_exception_spec (cxx_pretty_printer
*pp
, tree t
, int flags
)
1788 if (t
&& TREE_PURPOSE (t
))
1790 pp_cxx_ws_string (pp
, "noexcept");
1791 if (!integer_onep (TREE_PURPOSE (t
)))
1793 pp_cxx_whitespace (pp
);
1794 pp_cxx_left_paren (pp
);
1795 if (DEFERRED_NOEXCEPT_SPEC_P (t
))
1796 pp_cxx_ws_string (pp
, "<uninstantiated>");
1798 dump_expr (pp
, TREE_PURPOSE (t
), flags
);
1799 pp_cxx_right_paren (pp
);
1804 pp_cxx_ws_string (pp
, "throw");
1805 pp_cxx_whitespace (pp
);
1806 pp_cxx_left_paren (pp
);
1807 if (TREE_VALUE (t
) != NULL_TREE
)
1810 dump_type (pp
, TREE_VALUE (t
), flags
);
1814 pp_separate_with_comma (pp
);
1816 pp_cxx_right_paren (pp
);
1820 /* Handle the function name for a FUNCTION_DECL node, grokking operators
1821 and destructors properly. */
1824 dump_function_name (cxx_pretty_printer
*pp
, tree t
, int flags
)
1826 tree name
= DECL_NAME (t
);
1828 /* We can get here with a decl that was synthesized by language-
1829 independent machinery (e.g. coverage.c) in which case it won't
1830 have a lang_specific structure attached and DECL_CONSTRUCTOR_P
1831 will crash. In this case it is safe just to print out the
1833 if (!DECL_LANG_SPECIFIC (t
))
1835 pp_cxx_tree_identifier (pp
, name
);
1839 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1840 t
= DECL_TEMPLATE_RESULT (t
);
1842 /* Don't let the user see __comp_ctor et al. */
1843 if (DECL_CONSTRUCTOR_P (t
)
1844 || DECL_DESTRUCTOR_P (t
))
1846 if (LAMBDA_TYPE_P (DECL_CONTEXT (t
)))
1847 name
= get_identifier ("<lambda>");
1848 else if (TYPE_UNNAMED_P (DECL_CONTEXT (t
)))
1849 name
= get_identifier ("<constructor>");
1851 name
= constructor_name (DECL_CONTEXT (t
));
1854 if (DECL_DESTRUCTOR_P (t
))
1856 pp_cxx_complement (pp
);
1857 dump_decl (pp
, name
, TFF_PLAIN_IDENTIFIER
);
1859 else if (DECL_CONV_FN_P (t
))
1861 /* This cannot use the hack that the operator's return
1862 type is stashed off of its name because it may be
1863 used for error reporting. In the case of conflicting
1864 declarations, both will have the same name, yet
1865 the types will be different, hence the TREE_TYPE field
1866 of the first name will be clobbered by the second. */
1867 pp_cxx_ws_string (pp
, "operator");
1868 dump_type (pp
, TREE_TYPE (TREE_TYPE (t
)), flags
);
1871 dump_decl (pp
, name
, flags
);
1873 if (DECL_TEMPLATE_INFO (t
)
1874 && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t
)
1875 && (TREE_CODE (DECL_TI_TEMPLATE (t
)) != TEMPLATE_DECL
1876 || PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t
))))
1877 dump_template_parms (pp
, DECL_TEMPLATE_INFO (t
), !DECL_USE_TEMPLATE (t
),
1881 /* Dump the template parameters from the template info INFO under control of
1882 FLAGS. PRIMARY indicates whether this is a primary template decl, or
1883 specialization (partial or complete). For partial specializations we show
1884 the specialized parameter values. For a primary template we show no
1888 dump_template_parms (cxx_pretty_printer
*pp
, tree info
,
1889 int primary
, int flags
)
1891 tree args
= info
? TI_ARGS (info
) : NULL_TREE
;
1893 if (primary
&& flags
& TFF_TEMPLATE_NAME
)
1895 flags
&= ~(TFF_CLASS_KEY_OR_ENUM
| TFF_TEMPLATE_NAME
);
1896 pp_cxx_begin_template_argument_list (pp
);
1898 /* Be careful only to print things when we have them, so as not
1899 to crash producing error messages. */
1900 if (args
&& !primary
)
1903 len
= get_non_default_template_args_count (args
, flags
);
1905 args
= INNERMOST_TEMPLATE_ARGS (args
);
1906 for (ix
= 0; ix
!= len
; ix
++)
1908 tree arg
= TREE_VEC_ELT (args
, ix
);
1910 /* Only print a comma if we know there is an argument coming. In
1911 the case of an empty template argument pack, no actual
1912 argument will be printed. */
1914 && (!ARGUMENT_PACK_P (arg
)
1915 || TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg
)) > 0))
1916 pp_separate_with_comma (pp
);
1919 pp_string (pp
, M_("<template parameter error>"));
1921 dump_template_argument (pp
, arg
, flags
);
1926 tree tpl
= TI_TEMPLATE (info
);
1927 tree parms
= DECL_TEMPLATE_PARMS (tpl
);
1930 parms
= TREE_CODE (parms
) == TREE_LIST
? TREE_VALUE (parms
) : NULL_TREE
;
1931 len
= parms
? TREE_VEC_LENGTH (parms
) : 0;
1933 for (ix
= 0; ix
!= len
; ix
++)
1937 if (TREE_VEC_ELT (parms
, ix
) == error_mark_node
)
1939 pp_string (pp
, M_("<template parameter error>"));
1943 parm
= TREE_VALUE (TREE_VEC_ELT (parms
, ix
));
1946 pp_separate_with_comma (pp
);
1948 dump_decl (pp
, parm
, flags
& ~TFF_DECL_SPECIFIERS
);
1951 pp_cxx_end_template_argument_list (pp
);
1954 /* Print out the arguments of CALL_EXPR T as a parenthesized list using
1955 flags FLAGS. Skip over the first argument if SKIPFIRST is true. */
1958 dump_call_expr_args (cxx_pretty_printer
*pp
, tree t
, int flags
, bool skipfirst
)
1961 call_expr_arg_iterator iter
;
1963 pp_cxx_left_paren (pp
);
1964 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, t
)
1970 dump_expr (pp
, arg
, flags
| TFF_EXPR_IN_PARENS
);
1971 if (more_call_expr_args_p (&iter
))
1972 pp_separate_with_comma (pp
);
1975 pp_cxx_right_paren (pp
);
1978 /* Print out the arguments of AGGR_INIT_EXPR T as a parenthesized list
1979 using flags FLAGS. Skip over the first argument if SKIPFIRST is
1983 dump_aggr_init_expr_args (cxx_pretty_printer
*pp
, tree t
, int flags
,
1987 aggr_init_expr_arg_iterator iter
;
1989 pp_cxx_left_paren (pp
);
1990 FOR_EACH_AGGR_INIT_EXPR_ARG (arg
, iter
, t
)
1996 dump_expr (pp
, arg
, flags
| TFF_EXPR_IN_PARENS
);
1997 if (more_aggr_init_expr_args_p (&iter
))
1998 pp_separate_with_comma (pp
);
2001 pp_cxx_right_paren (pp
);
2004 /* Print out a list of initializers (subr of dump_expr). */
2007 dump_expr_list (cxx_pretty_printer
*pp
, tree l
, int flags
)
2011 dump_expr (pp
, TREE_VALUE (l
), flags
| TFF_EXPR_IN_PARENS
);
2014 pp_separate_with_comma (pp
);
2018 /* Print out a vector of initializers (subr of dump_expr). */
2021 dump_expr_init_vec (cxx_pretty_printer
*pp
, vec
<constructor_elt
, va_gc
> *v
,
2024 unsigned HOST_WIDE_INT idx
;
2027 FOR_EACH_CONSTRUCTOR_VALUE (v
, idx
, value
)
2029 dump_expr (pp
, value
, flags
| TFF_EXPR_IN_PARENS
);
2030 if (idx
!= v
->length () - 1)
2031 pp_separate_with_comma (pp
);
2036 /* We've gotten an indirect REFERENCE (an OBJ_TYPE_REF) to a virtual
2037 function. Resolve it to a close relative -- in the sense of static
2038 type -- variant being overridden. That is close to what was written in
2039 the source code. Subroutine of dump_expr. */
2042 resolve_virtual_fun_from_obj_type_ref (tree ref
)
2044 tree obj_type
= TREE_TYPE (OBJ_TYPE_REF_OBJECT (ref
));
2045 HOST_WIDE_INT index
= tree_to_uhwi (OBJ_TYPE_REF_TOKEN (ref
));
2046 tree fun
= BINFO_VIRTUALS (TYPE_BINFO (TREE_TYPE (obj_type
)));
2049 fun
= TREE_CHAIN (fun
);
2050 index
-= (TARGET_VTABLE_USES_DESCRIPTORS
2051 ? TARGET_VTABLE_USES_DESCRIPTORS
: 1);
2057 /* Print out an expression E under control of FLAGS. */
2060 dump_expr (cxx_pretty_printer
*pp
, tree t
, int flags
)
2067 if (STATEMENT_CLASS_P (t
))
2069 pp_cxx_ws_string (pp
, M_("<statement>"));
2073 switch (TREE_CODE (t
))
2081 case NAMESPACE_DECL
:
2085 case IDENTIFIER_NODE
:
2086 dump_decl (pp
, t
, ((flags
& ~(TFF_DECL_SPECIFIERS
|TFF_RETURN_TYPE
2087 |TFF_TEMPLATE_HEADER
))
2088 | TFF_NO_TEMPLATE_BINDINGS
2089 | TFF_NO_FUNCTION_ARGUMENTS
));
2093 if (SSA_NAME_VAR (t
)
2094 && !DECL_ARTIFICIAL (SSA_NAME_VAR (t
)))
2095 dump_expr (pp
, SSA_NAME_VAR (t
), flags
);
2097 pp_cxx_ws_string (pp
, M_("<unknown>"));
2108 case USERDEF_LITERAL
:
2109 pp_cxx_userdef_literal (pp
, t
);
2113 /* While waiting for caret diagnostics, avoid printing
2114 __cxa_allocate_exception, __cxa_throw, and the like. */
2115 pp_cxx_ws_string (pp
, M_("<throw-expression>"));
2120 dump_type (pp
, PTRMEM_CST_CLASS (t
), flags
);
2121 pp_cxx_colon_colon (pp
);
2122 pp_cxx_tree_identifier (pp
, DECL_NAME (PTRMEM_CST_MEMBER (t
)));
2126 pp_cxx_left_paren (pp
);
2127 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2128 pp_separate_with_comma (pp
);
2129 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2130 pp_cxx_right_paren (pp
);
2135 pp_cxx_left_paren (pp
);
2136 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2137 pp_string (pp
, " ? ");
2138 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2139 pp_string (pp
, " : ");
2140 dump_expr (pp
, TREE_OPERAND (t
, 2), flags
| TFF_EXPR_IN_PARENS
);
2141 pp_cxx_right_paren (pp
);
2145 if (TREE_HAS_CONSTRUCTOR (t
))
2147 pp_cxx_ws_string (pp
, "new");
2148 pp_cxx_whitespace (pp
);
2149 dump_type (pp
, TREE_TYPE (TREE_TYPE (t
)), flags
);
2152 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2155 case AGGR_INIT_EXPR
:
2157 tree fn
= NULL_TREE
;
2159 if (TREE_CODE (AGGR_INIT_EXPR_FN (t
)) == ADDR_EXPR
)
2160 fn
= TREE_OPERAND (AGGR_INIT_EXPR_FN (t
), 0);
2162 if (fn
&& TREE_CODE (fn
) == FUNCTION_DECL
)
2164 if (DECL_CONSTRUCTOR_P (fn
))
2165 dump_type (pp
, DECL_CONTEXT (fn
), flags
);
2167 dump_decl (pp
, fn
, 0);
2170 dump_expr (pp
, AGGR_INIT_EXPR_FN (t
), 0);
2172 dump_aggr_init_expr_args (pp
, t
, flags
, true);
2177 tree fn
= CALL_EXPR_FN (t
);
2178 bool skipfirst
= false;
2180 /* Deal with internal functions. */
2181 if (fn
== NULL_TREE
)
2183 pp_string (pp
, internal_fn_name (CALL_EXPR_IFN (t
)));
2184 dump_call_expr_args (pp
, t
, flags
, skipfirst
);
2188 if (TREE_CODE (fn
) == ADDR_EXPR
)
2189 fn
= TREE_OPERAND (fn
, 0);
2191 /* Nobody is interested in seeing the guts of vcalls. */
2192 if (TREE_CODE (fn
) == OBJ_TYPE_REF
)
2193 fn
= resolve_virtual_fun_from_obj_type_ref (fn
);
2195 if (TREE_TYPE (fn
) != NULL_TREE
2196 && NEXT_CODE (fn
) == METHOD_TYPE
2197 && call_expr_nargs (t
))
2199 tree ob
= CALL_EXPR_ARG (t
, 0);
2200 if (TREE_CODE (ob
) == ADDR_EXPR
)
2202 dump_expr (pp
, TREE_OPERAND (ob
, 0),
2203 flags
| TFF_EXPR_IN_PARENS
);
2206 else if (!is_this_parameter (ob
))
2208 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2213 if (flag_sanitize
& SANITIZE_UNDEFINED
2214 && is_ubsan_builtin_p (fn
))
2216 pp_string (cxx_pp
, M_("<ubsan routine call>"));
2219 dump_expr (pp
, fn
, flags
| TFF_EXPR_IN_PARENS
);
2220 dump_call_expr_args (pp
, t
, flags
, skipfirst
);
2225 /* Note that this only works for G++ target exprs. If somebody
2226 builds a general TARGET_EXPR, there's no way to represent that
2227 it initializes anything other that the parameter slot for the
2228 default argument. Note we may have cleared out the first
2229 operand in expand_expr, so don't go killing ourselves. */
2230 if (TREE_OPERAND (t
, 1))
2231 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2234 case POINTER_PLUS_EXPR
:
2235 dump_binary_op (pp
, "+", t
, flags
);
2238 case POINTER_DIFF_EXPR
:
2239 dump_binary_op (pp
, "-", t
, flags
);
2244 dump_binary_op (pp
, OVL_OP_INFO (true, NOP_EXPR
)->name
, t
, flags
);
2250 case TRUNC_DIV_EXPR
:
2251 case TRUNC_MOD_EXPR
:
2259 case TRUTH_ANDIF_EXPR
:
2260 case TRUTH_ORIF_EXPR
:
2267 case EXACT_DIV_EXPR
:
2268 dump_binary_op (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
, t
, flags
);
2272 case FLOOR_DIV_EXPR
:
2273 case ROUND_DIV_EXPR
:
2275 dump_binary_op (pp
, "/", t
, flags
);
2279 case FLOOR_MOD_EXPR
:
2280 case ROUND_MOD_EXPR
:
2281 dump_binary_op (pp
, "%", t
, flags
);
2286 tree ob
= TREE_OPERAND (t
, 0);
2287 if (INDIRECT_REF_P (ob
))
2289 ob
= TREE_OPERAND (ob
, 0);
2290 if (!is_this_parameter (ob
))
2292 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2293 if (TYPE_REF_P (TREE_TYPE (ob
)))
2301 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2302 if (TREE_CODE (ob
) != ARROW_EXPR
)
2305 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
& ~TFF_EXPR_IN_PARENS
);
2310 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2311 pp_cxx_left_bracket (pp
);
2312 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2313 pp_cxx_right_bracket (pp
);
2316 case UNARY_PLUS_EXPR
:
2317 dump_unary_op (pp
, "+", t
, flags
);
2321 if (TREE_CODE (TREE_OPERAND (t
, 0)) == FUNCTION_DECL
2322 || TREE_CODE (TREE_OPERAND (t
, 0)) == STRING_CST
2323 /* An ADDR_EXPR can have reference type. In that case, we
2324 shouldn't print the `&' doing so indicates to the user
2325 that the expression has pointer type. */
2327 && TYPE_REF_P (TREE_TYPE (t
))))
2328 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2329 else if (TREE_CODE (TREE_OPERAND (t
, 0)) == LABEL_DECL
)
2330 dump_unary_op (pp
, "&&", t
, flags
);
2332 dump_unary_op (pp
, "&", t
, flags
);
2336 if (TREE_HAS_CONSTRUCTOR (t
))
2338 t
= TREE_OPERAND (t
, 0);
2339 gcc_assert (TREE_CODE (t
) == CALL_EXPR
);
2340 dump_expr (pp
, CALL_EXPR_FN (t
), flags
| TFF_EXPR_IN_PARENS
);
2341 dump_call_expr_args (pp
, t
, flags
, true);
2345 if (TREE_OPERAND (t
,0) != NULL_TREE
2346 && TREE_TYPE (TREE_OPERAND (t
, 0))
2347 && NEXT_CODE (TREE_OPERAND (t
, 0)) == REFERENCE_TYPE
)
2348 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2350 dump_unary_op (pp
, "*", t
, flags
);
2355 if (TREE_CODE (TREE_OPERAND (t
, 0)) == ADDR_EXPR
2356 && integer_zerop (TREE_OPERAND (t
, 1)))
2357 dump_expr (pp
, TREE_OPERAND (TREE_OPERAND (t
, 0), 0), flags
);
2361 if (!integer_zerop (TREE_OPERAND (t
, 1)))
2363 pp_cxx_left_paren (pp
);
2364 if (!integer_onep (TYPE_SIZE_UNIT
2365 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (t
, 0))))))
2367 pp_cxx_left_paren (pp
);
2368 dump_type (pp
, ptr_type_node
, flags
);
2369 pp_cxx_right_paren (pp
);
2372 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2373 if (!integer_zerop (TREE_OPERAND (t
, 1)))
2375 pp_cxx_ws_string (pp
, "+");
2376 dump_expr (pp
, fold_convert (ssizetype
, TREE_OPERAND (t
, 1)),
2378 pp_cxx_right_paren (pp
);
2385 case TRUTH_NOT_EXPR
:
2386 case PREDECREMENT_EXPR
:
2387 case PREINCREMENT_EXPR
:
2388 dump_unary_op (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
, t
, flags
);
2391 case POSTDECREMENT_EXPR
:
2392 case POSTINCREMENT_EXPR
:
2393 pp_cxx_left_paren (pp
);
2394 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2395 pp_cxx_ws_string (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
);
2396 pp_cxx_right_paren (pp
);
2399 case NON_LVALUE_EXPR
:
2400 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
2401 should be another level of INDIRECT_REF so that I don't have to do
2403 if (TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == POINTER_TYPE
)
2405 tree next
= TREE_TYPE (TREE_TYPE (t
));
2407 while (TYPE_PTR_P (next
))
2408 next
= TREE_TYPE (next
);
2410 if (TREE_CODE (next
) == FUNCTION_TYPE
)
2412 if (flags
& TFF_EXPR_IN_PARENS
)
2413 pp_cxx_left_paren (pp
);
2415 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2416 if (flags
& TFF_EXPR_IN_PARENS
)
2417 pp_cxx_right_paren (pp
);
2420 /* Else fall through. */
2422 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2426 case IMPLICIT_CONV_EXPR
:
2427 case VIEW_CONVERT_EXPR
:
2429 tree op
= TREE_OPERAND (t
, 0);
2430 tree ttype
= TREE_TYPE (t
);
2431 tree optype
= TREE_TYPE (op
);
2433 if (TREE_CODE (ttype
) != TREE_CODE (optype
)
2434 && INDIRECT_TYPE_P (ttype
)
2435 && INDIRECT_TYPE_P (optype
)
2436 && same_type_p (TREE_TYPE (optype
),
2439 if (TYPE_REF_P (ttype
))
2442 if (TREE_CODE (op
) == ADDR_EXPR
)
2443 dump_expr (pp
, TREE_OPERAND (op
, 0), flags
);
2445 dump_unary_op (pp
, "*", t
, flags
);
2448 dump_unary_op (pp
, "&", t
, flags
);
2450 else if (!same_type_p (TREE_TYPE (op
), TREE_TYPE (t
)))
2452 /* It is a cast, but we cannot tell whether it is a
2453 reinterpret or static cast. Use the C style notation. */
2454 if (flags
& TFF_EXPR_IN_PARENS
)
2455 pp_cxx_left_paren (pp
);
2456 pp_cxx_left_paren (pp
);
2457 dump_type (pp
, TREE_TYPE (t
), flags
);
2458 pp_cxx_right_paren (pp
);
2459 dump_expr (pp
, op
, flags
| TFF_EXPR_IN_PARENS
);
2460 if (flags
& TFF_EXPR_IN_PARENS
)
2461 pp_cxx_right_paren (pp
);
2464 dump_expr (pp
, op
, flags
);
2469 if (TREE_TYPE (t
) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t
)))
2471 tree idx
= build_ptrmemfunc_access_expr (t
, pfn_identifier
);
2473 if (integer_zerop (idx
))
2475 /* A NULL pointer-to-member constant. */
2476 pp_cxx_left_paren (pp
);
2477 pp_cxx_left_paren (pp
);
2478 dump_type (pp
, TREE_TYPE (t
), flags
);
2479 pp_cxx_right_paren (pp
);
2480 pp_character (pp
, '0');
2481 pp_cxx_right_paren (pp
);
2484 else if (tree_fits_shwi_p (idx
))
2487 unsigned HOST_WIDE_INT n
;
2489 t
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t
)));
2490 t
= TYPE_METHOD_BASETYPE (t
);
2491 virtuals
= BINFO_VIRTUALS (TYPE_BINFO (TYPE_MAIN_VARIANT (t
)));
2493 n
= tree_to_shwi (idx
);
2495 /* Map vtable index back one, to allow for the null pointer to
2499 while (n
> 0 && virtuals
)
2502 virtuals
= TREE_CHAIN (virtuals
);
2506 dump_expr (pp
, BV_FN (virtuals
),
2507 flags
| TFF_EXPR_IN_PARENS
);
2512 if (TREE_TYPE (t
) && LAMBDA_TYPE_P (TREE_TYPE (t
)))
2513 pp_string (pp
, "<lambda closure object>");
2514 if (TREE_TYPE (t
) && EMPTY_CONSTRUCTOR_P (t
))
2516 dump_type (pp
, TREE_TYPE (t
), 0);
2517 pp_cxx_left_paren (pp
);
2518 pp_cxx_right_paren (pp
);
2522 if (!BRACE_ENCLOSED_INITIALIZER_P (t
))
2523 dump_type (pp
, TREE_TYPE (t
), 0);
2524 pp_cxx_left_brace (pp
);
2525 dump_expr_init_vec (pp
, CONSTRUCTOR_ELTS (t
), flags
);
2526 pp_cxx_right_brace (pp
);
2533 tree ob
= TREE_OPERAND (t
, 0);
2534 if (is_dummy_object (ob
))
2536 t
= TREE_OPERAND (t
, 1);
2537 if (TREE_CODE (t
) == FUNCTION_DECL
)
2539 dump_expr (pp
, t
, flags
| TFF_EXPR_IN_PARENS
);
2540 else if (BASELINK_P (t
))
2541 dump_expr (pp
, OVL_FIRST (BASELINK_FUNCTIONS (t
)),
2542 flags
| TFF_EXPR_IN_PARENS
);
2544 dump_decl (pp
, t
, flags
);
2548 if (INDIRECT_REF_P (ob
))
2550 dump_expr (pp
, TREE_OPERAND (ob
, 0), flags
| TFF_EXPR_IN_PARENS
);
2556 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2560 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2565 case TEMPLATE_PARM_INDEX
:
2566 dump_decl (pp
, TEMPLATE_PARM_DECL (t
), flags
& ~TFF_DECL_SPECIFIERS
);
2570 if (TREE_OPERAND (t
, 0) == NULL_TREE
2571 || TREE_CHAIN (TREE_OPERAND (t
, 0)))
2573 dump_type (pp
, TREE_TYPE (t
), flags
);
2574 pp_cxx_left_paren (pp
);
2575 dump_expr_list (pp
, TREE_OPERAND (t
, 0), flags
);
2576 pp_cxx_right_paren (pp
);
2580 pp_cxx_left_paren (pp
);
2581 dump_type (pp
, TREE_TYPE (t
), flags
);
2582 pp_cxx_right_paren (pp
);
2583 pp_cxx_left_paren (pp
);
2584 dump_expr_list (pp
, TREE_OPERAND (t
, 0), flags
);
2585 pp_cxx_right_paren (pp
);
2589 case STATIC_CAST_EXPR
:
2590 pp_cxx_ws_string (pp
, "static_cast");
2592 case REINTERPRET_CAST_EXPR
:
2593 pp_cxx_ws_string (pp
, "reinterpret_cast");
2595 case CONST_CAST_EXPR
:
2596 pp_cxx_ws_string (pp
, "const_cast");
2598 case DYNAMIC_CAST_EXPR
:
2599 pp_cxx_ws_string (pp
, "dynamic_cast");
2601 pp_cxx_begin_template_argument_list (pp
);
2602 dump_type (pp
, TREE_TYPE (t
), flags
);
2603 pp_cxx_end_template_argument_list (pp
);
2604 pp_cxx_left_paren (pp
);
2605 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2606 pp_cxx_right_paren (pp
);
2610 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2616 if (TREE_CODE (t
) == SIZEOF_EXPR
)
2617 pp_cxx_ws_string (pp
, "sizeof");
2620 gcc_assert (TREE_CODE (t
) == ALIGNOF_EXPR
);
2621 pp_cxx_ws_string (pp
, "__alignof__");
2623 op
= TREE_OPERAND (t
, 0);
2624 if (PACK_EXPANSION_P (op
))
2626 pp_string (pp
, "...");
2627 op
= PACK_EXPANSION_PATTERN (op
);
2629 pp_cxx_whitespace (pp
);
2630 pp_cxx_left_paren (pp
);
2631 if (TREE_CODE (t
) == SIZEOF_EXPR
&& SIZEOF_EXPR_TYPE_P (t
))
2632 dump_type (pp
, TREE_TYPE (op
), flags
);
2633 else if (TYPE_P (TREE_OPERAND (t
, 0)))
2634 dump_type (pp
, op
, flags
);
2636 dump_expr (pp
, op
, flags
);
2637 pp_cxx_right_paren (pp
);
2640 case AT_ENCODE_EXPR
:
2641 pp_cxx_ws_string (pp
, "@encode");
2642 pp_cxx_whitespace (pp
);
2643 pp_cxx_left_paren (pp
);
2644 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
2645 pp_cxx_right_paren (pp
);
2649 pp_cxx_ws_string (pp
, "noexcept");
2650 pp_cxx_whitespace (pp
);
2651 pp_cxx_left_paren (pp
);
2652 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2653 pp_cxx_right_paren (pp
);
2658 pp_cxx_ws_string (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
);
2659 pp_cxx_whitespace (pp
);
2660 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2664 pp_string (pp
, M_("<unparsed>"));
2667 case TRY_CATCH_EXPR
:
2668 case CLEANUP_POINT_EXPR
:
2669 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2672 case PSEUDO_DTOR_EXPR
:
2673 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2675 if (TREE_OPERAND (t
, 1))
2677 dump_type (pp
, TREE_OPERAND (t
, 1), flags
);
2678 pp_cxx_colon_colon (pp
);
2680 pp_cxx_complement (pp
);
2681 dump_type (pp
, TREE_OPERAND (t
, 2), flags
);
2684 case TEMPLATE_ID_EXPR
:
2685 dump_decl (pp
, t
, flags
);
2691 case STATEMENT_LIST
:
2692 /* We don't yet have a way of dumping statements in a
2693 human-readable format. */
2694 pp_string (pp
, "({...})");
2698 pp_string (pp
, "while (1) { ");
2699 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2700 pp_cxx_right_brace (pp
);
2704 pp_string (pp
, "if (");
2705 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2706 pp_string (pp
, ") break; ");
2710 dump_expr (pp
, BASELINK_FUNCTIONS (t
), flags
& ~TFF_EXPR_IN_PARENS
);
2713 case EMPTY_CLASS_EXPR
:
2714 dump_type (pp
, TREE_TYPE (t
), flags
);
2715 pp_cxx_left_paren (pp
);
2716 pp_cxx_right_paren (pp
);
2719 case NON_DEPENDENT_EXPR
:
2720 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2723 case ARGUMENT_PACK_SELECT
:
2724 dump_template_argument (pp
, ARGUMENT_PACK_SELECT_FROM_PACK (t
), flags
);
2737 pp_type_specifier_seq (pp
, t
);
2741 /* We get here when we want to print a dependent type as an
2742 id-expression, without any disambiguator decoration. */
2743 pp
->id_expression (t
);
2746 case TEMPLATE_TYPE_PARM
:
2747 case TEMPLATE_TEMPLATE_PARM
:
2748 case BOUND_TEMPLATE_TEMPLATE_PARM
:
2749 dump_type (pp
, t
, flags
);
2753 pp_cxx_trait_expression (pp
, t
);
2757 pp_cxx_va_arg_expression (pp
, t
);
2761 pp_cxx_offsetof_expression (pp
, t
);
2764 case ADDRESSOF_EXPR
:
2765 pp_cxx_addressof_expression (pp
, t
);
2769 dump_decl (pp
, t
, flags
);
2772 case EXPR_PACK_EXPANSION
:
2773 case UNARY_LEFT_FOLD_EXPR
:
2774 case UNARY_RIGHT_FOLD_EXPR
:
2775 case BINARY_LEFT_FOLD_EXPR
:
2776 case BINARY_RIGHT_FOLD_EXPR
:
2783 case VEC_DELETE_EXPR
:
2790 case UNORDERED_EXPR
:
2800 case FIX_TRUNC_EXPR
:
2805 case TRUTH_AND_EXPR
:
2807 case TRUTH_XOR_EXPR
:
2808 if (flags
& TFF_EXPR_IN_PARENS
)
2809 pp_cxx_left_paren (pp
);
2811 if (flags
& TFF_EXPR_IN_PARENS
)
2812 pp_cxx_right_paren (pp
);
2816 dump_expr (pp
, resolve_virtual_fun_from_obj_type_ref (t
), flags
);
2820 pp_string (pp
, M_("<lambda>"));
2824 pp_cxx_left_paren (pp
);
2825 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2826 pp_cxx_right_paren (pp
);
2830 pp_cxx_requires_expr (cxx_pp
, t
);
2834 pp_cxx_simple_requirement (cxx_pp
, t
);
2838 pp_cxx_type_requirement (cxx_pp
, t
);
2842 pp_cxx_compound_requirement (cxx_pp
, t
);
2846 pp_cxx_nested_requirement (cxx_pp
, t
);
2859 pp_cxx_constraint (cxx_pp
, t
);
2862 case PLACEHOLDER_EXPR
:
2863 pp_string (pp
, M_("*this"));
2867 dump_expr_list (pp
, t
, flags
);
2870 /* This list is incomplete, but should suffice for now.
2871 It is very important that `sorry' does not call
2872 `report_error_function'. That could cause an infinite loop. */
2874 pp_unsupported_tree (pp
, t
);
2877 pp_string (pp
, M_("<expression error>"));
2883 dump_binary_op (cxx_pretty_printer
*pp
, const char *opstring
, tree t
,
2886 pp_cxx_left_paren (pp
);
2887 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2888 pp_cxx_whitespace (pp
);
2890 pp_cxx_ws_string (pp
, opstring
);
2892 pp_string (pp
, M_("<unknown operator>"));
2893 pp_cxx_whitespace (pp
);
2894 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2895 pp_cxx_right_paren (pp
);
2899 dump_unary_op (cxx_pretty_printer
*pp
, const char *opstring
, tree t
, int flags
)
2901 if (flags
& TFF_EXPR_IN_PARENS
)
2902 pp_cxx_left_paren (pp
);
2903 pp_cxx_ws_string (pp
, opstring
);
2904 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2905 if (flags
& TFF_EXPR_IN_PARENS
)
2906 pp_cxx_right_paren (pp
);
2910 reinit_cxx_pp (void)
2912 pp_clear_output_area (cxx_pp
);
2913 cxx_pp
->padding
= pp_none
;
2914 pp_indentation (cxx_pp
) = 0;
2915 pp_needs_newline (cxx_pp
) = false;
2916 cxx_pp
->enclosing_scope
= current_function_decl
;
2919 /* Same as pp_formatted_text, except the return string is a separate
2920 copy and has a GGC storage duration, e.g. an indefinite lifetime. */
2923 pp_ggc_formatted_text (pretty_printer
*pp
)
2925 return ggc_strdup (pp_formatted_text (pp
));
2928 /* Exported interface to stringifying types, exprs and decls under TFF_*
2932 type_as_string (tree typ
, int flags
)
2935 pp_translate_identifiers (cxx_pp
) = false;
2936 dump_type (cxx_pp
, typ
, flags
);
2937 return pp_ggc_formatted_text (cxx_pp
);
2941 type_as_string_translate (tree typ
, int flags
)
2944 dump_type (cxx_pp
, typ
, flags
);
2945 return pp_ggc_formatted_text (cxx_pp
);
2949 expr_as_string (tree decl
, int flags
)
2952 pp_translate_identifiers (cxx_pp
) = false;
2953 dump_expr (cxx_pp
, decl
, flags
);
2954 return pp_ggc_formatted_text (cxx_pp
);
2957 /* Wrap decl_as_string with options appropriate for dwarf. */
2960 decl_as_dwarf_string (tree decl
, int flags
)
2963 /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag
2964 here will be adequate to get the desired behavior. */
2965 cxx_pp
->flags
|= pp_c_flag_gnu_v3
;
2966 name
= decl_as_string (decl
, flags
);
2967 /* Subsequent calls to the pretty printer shouldn't use this style. */
2968 cxx_pp
->flags
&= ~pp_c_flag_gnu_v3
;
2973 decl_as_string (tree decl
, int flags
)
2976 pp_translate_identifiers (cxx_pp
) = false;
2977 dump_decl (cxx_pp
, decl
, flags
);
2978 return pp_ggc_formatted_text (cxx_pp
);
2982 decl_as_string_translate (tree decl
, int flags
)
2985 dump_decl (cxx_pp
, decl
, flags
);
2986 return pp_ggc_formatted_text (cxx_pp
);
2989 /* Wrap lang_decl_name with options appropriate for dwarf. */
2992 lang_decl_dwarf_name (tree decl
, int v
, bool translate
)
2995 /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag
2996 here will be adequate to get the desired behavior. */
2997 cxx_pp
->flags
|= pp_c_flag_gnu_v3
;
2998 name
= lang_decl_name (decl
, v
, translate
);
2999 /* Subsequent calls to the pretty printer shouldn't use this style. */
3000 cxx_pp
->flags
&= ~pp_c_flag_gnu_v3
;
3004 /* Generate the three forms of printable names for cxx_printable_name. */
3007 lang_decl_name (tree decl
, int v
, bool translate
)
3011 ? decl_as_string_translate (decl
, TFF_DECL_SPECIFIERS
)
3012 : decl_as_string (decl
, TFF_DECL_SPECIFIERS
));
3015 pp_translate_identifiers (cxx_pp
) = translate
;
3017 && (DECL_CLASS_SCOPE_P (decl
)
3018 || (DECL_NAMESPACE_SCOPE_P (decl
)
3019 && CP_DECL_CONTEXT (decl
) != global_namespace
)))
3021 dump_type (cxx_pp
, CP_DECL_CONTEXT (decl
), TFF_PLAIN_IDENTIFIER
);
3022 pp_cxx_colon_colon (cxx_pp
);
3025 if (TREE_CODE (decl
) == FUNCTION_DECL
)
3026 dump_function_name (cxx_pp
, decl
, TFF_PLAIN_IDENTIFIER
);
3027 else if ((DECL_NAME (decl
) == NULL_TREE
)
3028 && TREE_CODE (decl
) == NAMESPACE_DECL
)
3029 dump_decl (cxx_pp
, decl
, TFF_PLAIN_IDENTIFIER
| TFF_UNQUALIFIED_NAME
);
3031 dump_decl (cxx_pp
, DECL_NAME (decl
), TFF_PLAIN_IDENTIFIER
);
3033 return pp_ggc_formatted_text (cxx_pp
);
3036 /* Return the location of a tree passed to %+ formats. */
3039 location_of (tree t
)
3043 t
= TYPE_MAIN_DECL (t
);
3045 return input_location
;
3047 else if (TREE_CODE (t
) == OVERLOAD
)
3051 return DECL_SOURCE_LOCATION (t
);
3052 if (TREE_CODE (t
) == DEFAULT_ARG
)
3053 return defarg_location (t
);
3054 return cp_expr_loc_or_loc (t
, input_location
);
3057 /* Now the interfaces from error et al to dump_type et al. Each takes an
3058 on/off VERBOSE flag and supply the appropriate TFF_ flags to a dump_
3062 decl_to_string (tree decl
, int verbose
)
3066 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == RECORD_TYPE
3067 || TREE_CODE (decl
) == UNION_TYPE
|| TREE_CODE (decl
) == ENUMERAL_TYPE
)
3068 flags
= TFF_CLASS_KEY_OR_ENUM
;
3070 flags
|= TFF_DECL_SPECIFIERS
;
3071 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
3072 flags
|= TFF_DECL_SPECIFIERS
| TFF_RETURN_TYPE
;
3073 flags
|= TFF_TEMPLATE_HEADER
;
3076 dump_decl (cxx_pp
, decl
, flags
);
3077 return pp_ggc_formatted_text (cxx_pp
);
3081 expr_to_string (tree decl
)
3084 dump_expr (cxx_pp
, decl
, 0);
3085 return pp_ggc_formatted_text (cxx_pp
);
3089 fndecl_to_string (tree fndecl
, int verbose
)
3093 flags
= TFF_EXCEPTION_SPECIFICATION
| TFF_DECL_SPECIFIERS
3094 | TFF_TEMPLATE_HEADER
;
3096 flags
|= TFF_FUNCTION_DEFAULT_ARGUMENTS
;
3098 dump_decl (cxx_pp
, fndecl
, flags
);
3099 return pp_ggc_formatted_text (cxx_pp
);
3104 code_to_string (enum tree_code c
)
3106 return get_tree_code_name (c
);
3110 language_to_string (enum languages c
)
3117 case lang_cplusplus
:
3126 /* Return the proper printed version of a parameter to a C++ function. */
3129 parm_to_string (int p
)
3133 pp_string (cxx_pp
, "'this'");
3135 pp_decimal_int (cxx_pp
, p
+ 1);
3136 return pp_ggc_formatted_text (cxx_pp
);
3140 op_to_string (bool assop
, enum tree_code p
)
3142 tree id
= ovl_op_identifier (assop
, p
);
3143 return id
? IDENTIFIER_POINTER (id
) : M_("<unknown>");
3146 /* Return a GC-allocated representation of type TYP, with verbosity VERBOSE.
3148 If QUOTE is non-NULL and if *QUOTE is true, then quotes are added to the
3149 string in appropriate places, and *QUOTE is written to with false
3150 to suppress pp_format's trailing close quote so that e.g.
3151 foo_typedef {aka underlying_foo} {enum}
3152 can be printed by "%qT" as:
3153 `foo_typedef' {aka `underlying_foo'} {enum}
3155 `foo_typedef {aka underlying_foo} {enum}'
3156 When adding such quotes, if POSTPROCESSED is true (for handling %H and %I)
3157 then a leading open quote will be added, whereas if POSTPROCESSED is false
3158 (for handling %T) then any leading quote has already been added by
3159 pp_format, or is not needed due to QUOTE being NULL (for template arguments
3162 SHOW_COLOR is used to determine the colorization of any quotes that
3166 type_to_string (tree typ
, int verbose
, bool postprocessed
, bool *quote
,
3171 flags
|= TFF_CLASS_KEY_OR_ENUM
;
3172 flags
|= TFF_TEMPLATE_HEADER
;
3176 if (postprocessed
&& quote
&& *quote
)
3177 pp_begin_quote (cxx_pp
, show_color
);
3179 struct obstack
*ob
= pp_buffer (cxx_pp
)->obstack
;
3180 int type_start
, type_len
;
3181 type_start
= obstack_object_size (ob
);
3183 dump_type (cxx_pp
, typ
, flags
);
3185 /* Remember the end of the initial dump. */
3186 type_len
= obstack_object_size (ob
) - type_start
;
3188 /* If we're printing a type that involves typedefs, also print the
3189 stripped version. But sometimes the stripped version looks
3190 exactly the same, so we don't want it after all. To avoid printing
3191 it in that case, we play ugly obstack games. */
3192 if (typ
&& TYPE_P (typ
) && typ
!= TYPE_CANONICAL (typ
)
3193 && !uses_template_parms (typ
))
3195 int aka_start
, aka_len
; char *p
;
3196 tree aka
= strip_typedefs (typ
);
3197 if (quote
&& *quote
)
3198 pp_end_quote (cxx_pp
, show_color
);
3199 pp_string (cxx_pp
, " {aka");
3200 pp_cxx_whitespace (cxx_pp
);
3201 if (quote
&& *quote
)
3202 pp_begin_quote (cxx_pp
, show_color
);
3203 /* And remember the start of the aka dump. */
3204 aka_start
= obstack_object_size (ob
);
3205 dump_type (cxx_pp
, aka
, flags
);
3206 aka_len
= obstack_object_size (ob
) - aka_start
;
3207 if (quote
&& *quote
)
3208 pp_end_quote (cxx_pp
, show_color
);
3209 pp_right_brace (cxx_pp
);
3210 p
= (char*)obstack_base (ob
);
3211 /* If they are identical, cut off the aka by unwinding the obstack. */
3212 if (type_len
== aka_len
3213 && memcmp (p
+ type_start
, p
+aka_start
, type_len
) == 0)
3215 /* We can't add a '\0' here, since we may be adding a closing quote
3216 below, and it would be hidden by the '\0'.
3217 Instead, manually unwind the current object within the obstack
3218 so that the insertion point is at the end of the type, before
3220 int delta
= type_start
+ type_len
- obstack_object_size (ob
);
3221 gcc_assert (delta
<= 0);
3222 obstack_blank_fast (ob
, delta
);
3226 /* No further closing quotes are needed. */
3230 if (quote
&& *quote
)
3232 pp_end_quote (cxx_pp
, show_color
);
3235 return pp_ggc_formatted_text (cxx_pp
);
3239 args_to_string (tree p
, int verbose
)
3243 flags
|= TFF_CLASS_KEY_OR_ENUM
;
3248 if (TYPE_P (TREE_VALUE (p
)))
3249 return type_as_string_translate (p
, flags
);
3252 for (; p
; p
= TREE_CHAIN (p
))
3254 if (null_node_p (TREE_VALUE (p
)))
3255 pp_cxx_ws_string (cxx_pp
, "NULL");
3257 dump_type (cxx_pp
, error_type (TREE_VALUE (p
)), flags
);
3259 pp_separate_with_comma (cxx_pp
);
3261 return pp_ggc_formatted_text (cxx_pp
);
3264 /* Pretty-print a deduction substitution (from deduction_tsubst_fntype). P
3265 is a TREE_LIST with purpose the TEMPLATE_DECL, value the template
3269 subst_to_string (tree p
)
3271 tree decl
= TREE_PURPOSE (p
);
3272 tree targs
= TREE_VALUE (p
);
3273 tree tparms
= DECL_TEMPLATE_PARMS (decl
);
3274 int flags
= (TFF_DECL_SPECIFIERS
|TFF_TEMPLATE_HEADER
3275 |TFF_NO_TEMPLATE_BINDINGS
);
3281 dump_template_decl (cxx_pp
, TREE_PURPOSE (p
), flags
);
3282 dump_substitution (cxx_pp
, NULL
, tparms
, targs
, /*flags=*/0);
3283 return pp_ggc_formatted_text (cxx_pp
);
3287 cv_to_string (tree p
, int v
)
3290 cxx_pp
->padding
= v
? pp_before
: pp_none
;
3291 pp_cxx_cv_qualifier_seq (cxx_pp
, p
);
3292 return pp_ggc_formatted_text (cxx_pp
);
3296 eh_spec_to_string (tree p
, int /*v*/)
3300 dump_exception_spec (cxx_pp
, p
, flags
);
3301 return pp_ggc_formatted_text (cxx_pp
);
3304 /* Langhook for print_error_function. */
3306 cxx_print_error_function (diagnostic_context
*context
, const char *file
,
3307 diagnostic_info
*diagnostic
)
3311 prefix
= xstrdup (file
);
3314 lhd_print_error_function (context
, file
, diagnostic
);
3315 pp_set_prefix (context
->printer
, prefix
);
3316 maybe_print_instantiation_context (context
);
3320 cp_diagnostic_starter (diagnostic_context
*context
,
3321 diagnostic_info
*diagnostic
)
3323 diagnostic_report_current_module (context
, diagnostic_location (diagnostic
));
3324 cp_print_error_function (context
, diagnostic
);
3325 maybe_print_instantiation_context (context
);
3326 maybe_print_constexpr_context (context
);
3327 pp_set_prefix (context
->printer
, diagnostic_build_prefix (context
,
3331 /* Print current function onto BUFFER, in the process of reporting
3332 a diagnostic message. Called from cp_diagnostic_starter. */
3334 cp_print_error_function (diagnostic_context
*context
,
3335 diagnostic_info
*diagnostic
)
3337 /* If we are in an instantiation context, current_function_decl is likely
3338 to be wrong, so just rely on print_instantiation_full_context. */
3339 if (current_instantiation ())
3341 if (diagnostic_last_function_changed (context
, diagnostic
))
3343 char *old_prefix
= pp_take_prefix (context
->printer
);
3344 const char *file
= LOCATION_FILE (diagnostic_location (diagnostic
));
3345 tree abstract_origin
= diagnostic_abstract_origin (diagnostic
);
3346 char *new_prefix
= (file
&& abstract_origin
== NULL
)
3347 ? file_name_as_prefix (context
, file
) : NULL
;
3349 pp_set_prefix (context
->printer
, new_prefix
);
3351 if (current_function_decl
== NULL
)
3352 pp_string (context
->printer
, _("At global scope:"));
3357 if (abstract_origin
)
3359 ao
= BLOCK_ABSTRACT_ORIGIN (abstract_origin
);
3360 gcc_assert (TREE_CODE (ao
) == FUNCTION_DECL
);
3364 fndecl
= current_function_decl
;
3366 pp_printf (context
->printer
, function_category (fndecl
),
3367 cxx_printable_name_translate (fndecl
, 2));
3369 while (abstract_origin
)
3372 tree block
= abstract_origin
;
3374 locus
= &BLOCK_SOURCE_LOCATION (block
);
3376 block
= BLOCK_SUPERCONTEXT (block
);
3377 while (block
&& TREE_CODE (block
) == BLOCK
3378 && BLOCK_ABSTRACT_ORIGIN (block
))
3380 ao
= BLOCK_ABSTRACT_ORIGIN (block
);
3381 if (TREE_CODE (ao
) == FUNCTION_DECL
)
3386 else if (TREE_CODE (ao
) != BLOCK
)
3389 block
= BLOCK_SUPERCONTEXT (block
);
3392 abstract_origin
= block
;
3395 while (block
&& TREE_CODE (block
) == BLOCK
)
3396 block
= BLOCK_SUPERCONTEXT (block
);
3398 if (block
&& TREE_CODE (block
) == FUNCTION_DECL
)
3400 abstract_origin
= NULL
;
3404 expanded_location s
= expand_location (*locus
);
3405 pp_character (context
->printer
, ',');
3406 pp_newline (context
->printer
);
3409 if (context
->show_column
&& s
.column
!= 0)
3410 pp_printf (context
->printer
,
3411 _(" inlined from %qs at %r%s:%d:%d%R"),
3412 cxx_printable_name_translate (fndecl
, 2),
3413 "locus", s
.file
, s
.line
, s
.column
);
3415 pp_printf (context
->printer
,
3416 _(" inlined from %qs at %r%s:%d%R"),
3417 cxx_printable_name_translate (fndecl
, 2),
3418 "locus", s
.file
, s
.line
);
3422 pp_printf (context
->printer
, _(" inlined from %qs"),
3423 cxx_printable_name_translate (fndecl
, 2));
3426 pp_character (context
->printer
, ':');
3428 pp_newline (context
->printer
);
3430 diagnostic_set_last_function (context
, diagnostic
);
3431 pp_destroy_prefix (context
->printer
);
3432 context
->printer
->prefix
= old_prefix
;
3436 /* Returns a description of FUNCTION using standard terminology. The
3437 result is a format string of the form "In CATEGORY %qs". */
3439 function_category (tree fn
)
3441 /* We can get called from the middle-end for diagnostics of function
3442 clones. Make sure we have language specific information before
3443 dereferencing it. */
3444 if (DECL_LANG_SPECIFIC (STRIP_TEMPLATE (fn
))
3445 && DECL_FUNCTION_MEMBER_P (fn
))
3447 if (DECL_STATIC_FUNCTION_P (fn
))
3448 return _("In static member function %qs");
3449 else if (DECL_COPY_CONSTRUCTOR_P (fn
))
3450 return _("In copy constructor %qs");
3451 else if (DECL_CONSTRUCTOR_P (fn
))
3452 return _("In constructor %qs");
3453 else if (DECL_DESTRUCTOR_P (fn
))
3454 return _("In destructor %qs");
3455 else if (LAMBDA_FUNCTION_P (fn
))
3456 return _("In lambda function");
3458 return _("In member function %qs");
3461 return _("In function %qs");
3464 /* Report the full context of a current template instantiation,
3467 print_instantiation_full_context (diagnostic_context
*context
)
3469 struct tinst_level
*p
= current_instantiation ();
3470 location_t location
= input_location
;
3474 pp_verbatim (context
->printer
,
3476 ? _("%s: In substitution of %qS:\n")
3477 : _("%s: In instantiation of %q#D:\n"),
3478 LOCATION_FILE (location
),
3481 location
= p
->locus
;
3485 print_instantiation_partial_context (context
, p
, location
);
3488 /* Helper function of print_instantiation_partial_context() that
3489 prints a single line of instantiation context. */
3492 print_instantiation_partial_context_line (diagnostic_context
*context
,
3493 struct tinst_level
*t
,
3494 location_t loc
, bool recursive_p
)
3496 if (loc
== UNKNOWN_LOCATION
)
3499 expanded_location xloc
= expand_location (loc
);
3501 if (context
->show_column
)
3502 pp_verbatim (context
->printer
, _("%r%s:%d:%d:%R "),
3503 "locus", xloc
.file
, xloc
.line
, xloc
.column
);
3505 pp_verbatim (context
->printer
, _("%r%s:%d:%R "),
3506 "locus", xloc
.file
, xloc
.line
);
3511 pp_verbatim (context
->printer
,
3513 ? _("recursively required by substitution of %qS\n")
3514 : _("required by substitution of %qS\n"),
3517 pp_verbatim (context
->printer
,
3519 ? _("recursively required from %q#D\n")
3520 : _("required from %q#D\n"),
3525 pp_verbatim (context
->printer
,
3527 ? _("recursively required from here\n")
3528 : _("required from here\n"));
3532 /* Same as print_instantiation_full_context but less verbose. */
3535 print_instantiation_partial_context (diagnostic_context
*context
,
3536 struct tinst_level
*t0
, location_t loc
)
3538 struct tinst_level
*t
;
3541 location_t prev_loc
= loc
;
3543 for (t
= t0
; t
!= NULL
; t
= t
->next
)
3544 if (prev_loc
!= t
->locus
)
3546 prev_loc
= t
->locus
;
3552 if (template_backtrace_limit
3553 && n_total
> template_backtrace_limit
)
3555 int skip
= n_total
- template_backtrace_limit
;
3556 int head
= template_backtrace_limit
/ 2;
3558 /* Avoid skipping just 1. If so, skip 2. */
3562 head
= (template_backtrace_limit
- 1) / 2;
3565 for (n
= 0; n
< head
; n
++)
3567 gcc_assert (t
!= NULL
);
3568 if (loc
!= t
->locus
)
3569 print_instantiation_partial_context_line (context
, t
, loc
,
3570 /*recursive_p=*/false);
3574 if (t
!= NULL
&& skip
> 0)
3576 expanded_location xloc
;
3577 xloc
= expand_location (loc
);
3578 if (context
->show_column
)
3579 pp_verbatim (context
->printer
,
3580 _("%r%s:%d:%d:%R [ skipping %d instantiation "
3581 "contexts, use -ftemplate-backtrace-limit=0 to "
3583 "locus", xloc
.file
, xloc
.line
, xloc
.column
, skip
);
3585 pp_verbatim (context
->printer
,
3586 _("%r%s:%d:%R [ skipping %d instantiation "
3587 "contexts, use -ftemplate-backtrace-limit=0 to "
3589 "locus", xloc
.file
, xloc
.line
, skip
);
3594 } while (t
!= NULL
&& --skip
> 0);
3600 while (t
->next
!= NULL
&& t
->locus
== t
->next
->locus
)
3605 print_instantiation_partial_context_line (context
, t
, loc
,
3610 print_instantiation_partial_context_line (context
, NULL
, loc
,
3611 /*recursive_p=*/false);
3614 /* Called from cp_thing to print the template context for an error. */
3616 maybe_print_instantiation_context (diagnostic_context
*context
)
3618 if (!problematic_instantiation_changed () || current_instantiation () == 0)
3621 record_last_problematic_instantiation ();
3622 print_instantiation_full_context (context
);
3625 /* Report what constexpr call(s) we're trying to expand, if any. */
3628 maybe_print_constexpr_context (diagnostic_context
*context
)
3630 vec
<tree
> call_stack
= cx_error_context ();
3634 FOR_EACH_VEC_ELT (call_stack
, ix
, t
)
3636 expanded_location xloc
= expand_location (EXPR_LOCATION (t
));
3637 const char *s
= expr_as_string (t
, 0);
3638 if (context
->show_column
)
3639 pp_verbatim (context
->printer
,
3640 _("%r%s:%d:%d:%R in %<constexpr%> expansion of %qs"),
3641 "locus", xloc
.file
, xloc
.line
, xloc
.column
, s
);
3643 pp_verbatim (context
->printer
,
3644 _("%r%s:%d:%R in %<constexpr%> expansion of %qs"),
3645 "locus", xloc
.file
, xloc
.line
, s
);
3646 pp_newline (context
->printer
);
3651 /* Return true iff TYPE_A and TYPE_B are template types that are
3652 meaningful to compare. */
3655 comparable_template_types_p (tree type_a
, tree type_b
)
3657 if (!CLASS_TYPE_P (type_a
))
3659 if (!CLASS_TYPE_P (type_b
))
3662 tree tinfo_a
= TYPE_TEMPLATE_INFO (type_a
);
3663 tree tinfo_b
= TYPE_TEMPLATE_INFO (type_b
);
3664 if (!tinfo_a
|| !tinfo_b
)
3667 return TI_TEMPLATE (tinfo_a
) == TI_TEMPLATE (tinfo_b
);
3670 /* Start a new line indented by SPC spaces on PP. */
3673 newline_and_indent (pretty_printer
*pp
, int spc
)
3676 for (int i
= 0; i
< spc
; i
++)
3680 /* Generate a GC-allocated string for ARG, an expression or type. */
3683 arg_to_string (tree arg
, bool verbose
)
3686 return type_to_string (arg
, verbose
, true, NULL
, false);
3688 return expr_to_string (arg
);
3691 /* Subroutine to type_to_string_with_compare and
3692 print_template_tree_comparison.
3694 Print a representation of ARG (an expression or type) to PP,
3695 colorizing it as "type-diff" if PP->show_color. */
3698 print_nonequal_arg (pretty_printer
*pp
, tree arg
, bool verbose
)
3700 pp_printf (pp
, "%r%s%R",
3703 ? arg_to_string (arg
, verbose
)
3704 : G_("(no argument)")));
3707 /* Recursively print template TYPE_A to PP, as compared to template TYPE_B.
3709 The types must satisfy comparable_template_types_p.
3711 If INDENT is 0, then this is equivalent to type_to_string (TYPE_A), but
3712 potentially colorizing/eliding in comparison with TYPE_B.
3714 For example given types:
3715 vector<map<int,double>>
3717 vector<map<int,float>>
3718 then the result on PP would be:
3719 vector<map<[...],double>>
3720 with type elision, and:
3721 vector<map<int,double>>
3722 without type elision.
3724 In both cases the parts of TYPE that differ from PEER will be colorized
3725 if pp_show_color (pp) is true. In the above example, this would be
3728 If INDENT is non-zero, then the types are printed in a tree-like form
3729 which shows both types. In the above example, the result on PP would be:
3736 and without type-elision would be:
3743 As before, the differing parts of the types are colorized if
3744 pp_show_color (pp) is true ("double" and "float" in this example).
3746 Template arguments in which both types are using the default arguments
3747 are not printed; if at least one of the two types is using a non-default
3748 argument, then that argument is printed (or both arguments for the
3749 tree-like print format). */
3752 print_template_differences (pretty_printer
*pp
, tree type_a
, tree type_b
,
3753 bool verbose
, int indent
)
3756 newline_and_indent (pp
, indent
);
3758 tree tinfo_a
= TYPE_TEMPLATE_INFO (type_a
);
3759 tree tinfo_b
= TYPE_TEMPLATE_INFO (type_b
);
3761 pp_printf (pp
, "%s<",
3762 IDENTIFIER_POINTER (DECL_NAME (TI_TEMPLATE (tinfo_a
))));
3764 tree args_a
= TI_ARGS (tinfo_a
);
3765 tree args_b
= TI_ARGS (tinfo_b
);
3766 gcc_assert (TREE_CODE (args_a
) == TREE_VEC
);
3767 gcc_assert (TREE_CODE (args_b
) == TREE_VEC
);
3769 int len_a
= get_non_default_template_args_count (args_a
, flags
);
3770 args_a
= INNERMOST_TEMPLATE_ARGS (args_a
);
3771 int len_b
= get_non_default_template_args_count (args_b
, flags
);
3772 args_b
= INNERMOST_TEMPLATE_ARGS (args_b
);
3773 /* Determine the maximum range of args for which non-default template args
3774 were used; beyond this, only default args (if any) were used, and so
3775 they will be equal from this point onwards.
3776 One of the two peers might have used default arguments within this
3777 range, but the other will be using non-default arguments, and so
3778 it's more readable to print both within this range, to highlight
3780 int len_max
= MAX (len_a
, len_b
);
3781 gcc_assert (TREE_CODE (args_a
) == TREE_VEC
);
3782 gcc_assert (TREE_CODE (args_b
) == TREE_VEC
);
3783 for (int idx
= 0; idx
< len_max
; idx
++)
3786 pp_character (pp
, ',');
3788 tree arg_a
= TREE_VEC_ELT (args_a
, idx
);
3789 tree arg_b
= TREE_VEC_ELT (args_b
, idx
);
3793 newline_and_indent (pp
, indent
+ 2);
3794 /* Can do elision here, printing "[...]". */
3795 if (flag_elide_type
)
3796 pp_string (pp
, G_("[...]"));
3798 pp_string (pp
, arg_to_string (arg_a
, verbose
));
3802 int new_indent
= indent
? indent
+ 2 : 0;
3803 if (comparable_template_types_p (arg_a
, arg_b
))
3804 print_template_differences (pp
, arg_a
, arg_b
, verbose
, new_indent
);
3808 newline_and_indent (pp
, indent
+ 2);
3809 pp_character (pp
, '[');
3810 print_nonequal_arg (pp
, arg_a
, verbose
);
3811 pp_string (pp
, " != ");
3812 print_nonequal_arg (pp
, arg_b
, verbose
);
3813 pp_character (pp
, ']');
3816 print_nonequal_arg (pp
, arg_a
, verbose
);
3819 pp_printf (pp
, ">");
3822 /* As type_to_string, but for a template, potentially colorizing/eliding
3823 in comparison with PEER.
3824 For example, if TYPE is map<int,double> and PEER is map<int,int>,
3825 then the resulting string would be:
3827 with type elision, and:
3829 without type elision.
3831 In both cases the parts of TYPE that differ from PEER will be colorized
3832 if SHOW_COLOR is true. In the above example, this would be "double".
3834 Template arguments in which both types are using the default arguments
3835 are not printed; if at least one of the two types is using a non-default
3836 argument, then both arguments are printed.
3838 The resulting string is in a GC-allocated buffer. */
3841 type_to_string_with_compare (tree type
, tree peer
, bool verbose
,
3844 pretty_printer inner_pp
;
3845 pretty_printer
*pp
= &inner_pp
;
3846 pp_show_color (pp
) = show_color
;
3848 print_template_differences (pp
, type
, peer
, verbose
, 0);
3849 return pp_ggc_formatted_text (pp
);
3852 /* Recursively print a tree-like comparison of TYPE_A and TYPE_B to PP,
3853 indented by INDENT spaces.
3855 For example given types:
3857 vector<map<int,double>>
3861 vector<map<double,float>>
3863 the output with type elision would be:
3870 and without type-elision would be:
3877 TYPE_A and TYPE_B must both be comparable template types
3878 (as per comparable_template_types_p).
3880 Template arguments in which both types are using the default arguments
3881 are not printed; if at least one of the two types is using a non-default
3882 argument, then both arguments are printed. */
3885 print_template_tree_comparison (pretty_printer
*pp
, tree type_a
, tree type_b
,
3886 bool verbose
, int indent
)
3888 print_template_differences (pp
, type_a
, type_b
, verbose
, indent
);
3891 /* Subroutine for use in a format_postprocessor::handle
3892 implementation. Adds a chunk to the end of
3893 formatted output, so that it will be printed
3894 by pp_output_formatted_text. */
3897 append_formatted_chunk (pretty_printer
*pp
, const char *content
)
3899 output_buffer
*buffer
= pp_buffer (pp
);
3900 struct chunk_info
*chunk_array
= buffer
->cur_chunk_array
;
3901 const char **args
= chunk_array
->args
;
3903 unsigned int chunk_idx
;
3904 for (chunk_idx
= 0; args
[chunk_idx
]; chunk_idx
++)
3906 args
[chunk_idx
++] = content
;
3907 args
[chunk_idx
] = NULL
;
3910 /* Create a copy of CONTENT, with quotes added, and,
3911 potentially, with colorization.
3912 No escaped is performed on CONTENT.
3913 The result is in a GC-allocated buffer. */
3916 add_quotes (const char *content
, bool show_color
)
3918 pretty_printer tmp_pp
;
3919 pp_show_color (&tmp_pp
) = show_color
;
3921 /* We have to use "%<%s%>" rather than "%qs" here in order to avoid
3922 quoting colorization bytes within the results. */
3923 pp_printf (&tmp_pp
, "%<%s%>", content
);
3925 return pp_ggc_formatted_text (&tmp_pp
);
3928 /* If we had %H and %I, and hence deferred printing them,
3929 print them now, storing the result into the chunk_info
3930 for pp_format. Quote them if 'q' was provided.
3931 Also print the difference in tree form, adding it as
3932 an additional chunk. */
3935 cxx_format_postprocessor::handle (pretty_printer
*pp
)
3937 /* If we have one of %H and %I, the other should have
3939 if (m_type_a
.m_tree
|| m_type_b
.m_tree
)
3941 /* Avoid reentrancy issues by working with a copy of
3942 m_type_a and m_type_b, resetting them now. */
3943 deferred_printed_type type_a
= m_type_a
;
3944 deferred_printed_type type_b
= m_type_b
;
3945 m_type_a
= deferred_printed_type ();
3946 m_type_b
= deferred_printed_type ();
3948 gcc_assert (type_a
.m_buffer_ptr
);
3949 gcc_assert (type_b
.m_buffer_ptr
);
3951 bool show_color
= pp_show_color (pp
);
3953 const char *type_a_text
;
3954 const char *type_b_text
;
3956 if (comparable_template_types_p (type_a
.m_tree
, type_b
.m_tree
))
3959 = type_to_string_with_compare (type_a
.m_tree
, type_b
.m_tree
,
3960 type_a
.m_verbose
, show_color
);
3962 = type_to_string_with_compare (type_b
.m_tree
, type_a
.m_tree
,
3963 type_b
.m_verbose
, show_color
);
3965 if (flag_diagnostics_show_template_tree
)
3967 pretty_printer inner_pp
;
3968 pp_show_color (&inner_pp
) = pp_show_color (pp
);
3969 print_template_tree_comparison
3970 (&inner_pp
, type_a
.m_tree
, type_b
.m_tree
, type_a
.m_verbose
, 2);
3971 append_formatted_chunk (pp
, pp_ggc_formatted_text (&inner_pp
));
3976 /* If the types were not comparable (or if only one of %H/%I was
3977 provided), they are printed normally, and no difference tree
3979 type_a_text
= type_to_string (type_a
.m_tree
, type_a
.m_verbose
,
3980 true, &type_a
.m_quote
, show_color
);
3981 type_b_text
= type_to_string (type_b
.m_tree
, type_b
.m_verbose
,
3982 true, &type_b
.m_quote
, show_color
);
3986 type_a_text
= add_quotes (type_a_text
, show_color
);
3987 *type_a
.m_buffer_ptr
= type_a_text
;
3990 type_b_text
= add_quotes (type_b_text
, show_color
);
3991 *type_b
.m_buffer_ptr
= type_b_text
;
3995 /* Subroutine for handling %H and %I, to support i18n of messages like:
3997 error_at (loc, "could not convert %qE from %qH to %qI",
3998 expr, type_a, type_b);
4000 so that we can print things like:
4002 could not convert 'foo' from 'map<int,double>' to 'map<int,int>'
4004 and, with type-elision:
4006 could not convert 'foo' from 'map<[...],double>' to 'map<[...],int>'
4008 (with color-coding of the differences between the types).
4010 The %H and %I format codes are peers: both must be present,
4011 and they affect each other. Hence to handle them, we must
4012 delay printing until we have both, deferring the printing to
4013 pretty_printer's m_format_postprocessor hook.
4015 This is called in phase 2 of pp_format, when it is accumulating
4016 a series of formatted chunks. We stash the location of the chunk
4017 we're meant to have written to, so that we can write to it in the
4018 m_format_postprocessor hook.
4020 We also need to stash whether a 'q' prefix was provided (the QUOTE
4021 param) so that we can add the quotes when writing out the delayed
4025 defer_phase_2_of_type_diff (deferred_printed_type
*deferred
,
4026 tree type
, const char **buffer_ptr
,
4027 bool verbose
, bool quote
)
4029 gcc_assert (deferred
->m_tree
== NULL_TREE
);
4030 gcc_assert (deferred
->m_buffer_ptr
== NULL
);
4031 *deferred
= deferred_printed_type (type
, buffer_ptr
, verbose
, quote
);
4035 /* Called from output_format -- during diagnostic message processing --
4036 to handle C++ specific format specifier with the following meanings:
4037 %A function argument-list.
4041 %F function declaration.
4043 %H type difference (from).
4044 %I type difference (to).
4046 %L language as used in extern "lang".
4048 %P function parameter whose position is indicated by an integer.
4049 %Q assignment operator.
4050 %S substitution (template + args)
4053 %X exception-specification. */
4055 cp_printer (pretty_printer
*pp
, text_info
*text
, const char *spec
,
4056 int precision
, bool wide
, bool set_locus
, bool verbose
,
4057 bool *quoted
, const char **buffer_ptr
)
4059 gcc_assert (pp
->m_format_postprocessor
);
4060 cxx_format_postprocessor
*postprocessor
4061 = static_cast <cxx_format_postprocessor
*> (pp
->m_format_postprocessor
);
4065 #define next_tree (t = va_arg (*text->args_ptr, tree))
4066 #define next_tcode ((enum tree_code) va_arg (*text->args_ptr, int))
4067 #define next_lang ((enum languages) va_arg (*text->args_ptr, int))
4068 #define next_int va_arg (*text->args_ptr, int)
4070 if (precision
!= 0 || wide
)
4075 case 'A': result
= args_to_string (next_tree
, verbose
); break;
4076 case 'C': result
= code_to_string (next_tcode
); break;
4079 tree temp
= next_tree
;
4081 && DECL_HAS_DEBUG_EXPR_P (temp
))
4083 temp
= DECL_DEBUG_EXPR (temp
);
4086 result
= expr_to_string (temp
);
4090 result
= decl_to_string (temp
, verbose
);
4093 case 'E': result
= expr_to_string (next_tree
); break;
4094 case 'F': result
= fndecl_to_string (next_tree
, verbose
); break;
4096 percent_G_format (text
);
4099 defer_phase_2_of_type_diff (&postprocessor
->m_type_a
, next_tree
,
4100 buffer_ptr
, verbose
, *quoted
);
4103 defer_phase_2_of_type_diff (&postprocessor
->m_type_b
, next_tree
,
4104 buffer_ptr
, verbose
, *quoted
);
4107 t
= va_arg (*text
->args_ptr
, tree
);
4108 percent_K_format (text
, EXPR_LOCATION (t
), TREE_BLOCK (t
));
4110 case 'L': result
= language_to_string (next_lang
); break;
4111 case 'O': result
= op_to_string (false, next_tcode
); break;
4112 case 'P': result
= parm_to_string (next_int
); break;
4113 case 'Q': result
= op_to_string (true, next_tcode
); break;
4114 case 'S': result
= subst_to_string (next_tree
); break;
4117 result
= type_to_string (next_tree
, verbose
, false, quoted
,
4118 pp_show_color (pp
));
4121 case 'V': result
= cv_to_string (next_tree
, verbose
); break;
4122 case 'X': result
= eh_spec_to_string (next_tree
, verbose
); break;
4128 pp_string (pp
, result
);
4129 if (set_locus
&& t
!= NULL
)
4130 text
->set_location (0, location_of (t
), SHOW_RANGE_WITH_CARET
);
4138 /* Warn about the use of C++0x features when appropriate. */
4140 maybe_warn_cpp0x (cpp0x_warn_str str
)
4142 if ((cxx_dialect
== cxx98
) && !in_system_header_at (input_location
))
4143 /* We really want to suppress this warning in system headers,
4144 because libstdc++ uses variadic templates even when we aren't
4148 case CPP0X_INITIALIZER_LISTS
:
4149 pedwarn (input_location
, 0,
4150 "extended initializer lists "
4151 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4153 case CPP0X_EXPLICIT_CONVERSION
:
4154 pedwarn (input_location
, 0,
4155 "explicit conversion operators "
4156 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4158 case CPP0X_VARIADIC_TEMPLATES
:
4159 pedwarn (input_location
, 0,
4160 "variadic templates "
4161 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4163 case CPP0X_LAMBDA_EXPR
:
4164 pedwarn (input_location
, 0,
4165 "lambda expressions "
4166 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4169 pedwarn (input_location
, 0,
4170 "C++11 auto only available with %<-std=c++11%> or "
4171 "%<-std=gnu++11%>");
4173 case CPP0X_SCOPED_ENUMS
:
4174 pedwarn (input_location
, 0,
4175 "scoped enums only available with %<-std=c++11%> or "
4176 "%<-std=gnu++11%>");
4178 case CPP0X_DEFAULTED_DELETED
:
4179 pedwarn (input_location
, 0,
4180 "defaulted and deleted functions "
4181 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4183 case CPP0X_INLINE_NAMESPACES
:
4184 pedwarn (input_location
, OPT_Wpedantic
,
4185 "inline namespaces "
4186 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4188 case CPP0X_OVERRIDE_CONTROLS
:
4189 pedwarn (input_location
, 0,
4190 "override controls (override/final) "
4191 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4194 pedwarn (input_location
, 0,
4195 "non-static data member initializers "
4196 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4198 case CPP0X_USER_DEFINED_LITERALS
:
4199 pedwarn (input_location
, 0,
4200 "user-defined literals "
4201 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4203 case CPP0X_DELEGATING_CTORS
:
4204 pedwarn (input_location
, 0,
4205 "delegating constructors "
4206 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4208 case CPP0X_INHERITING_CTORS
:
4209 pedwarn (input_location
, 0,
4210 "inheriting constructors "
4211 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4213 case CPP0X_ATTRIBUTES
:
4214 pedwarn (input_location
, 0,
4216 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4218 case CPP0X_REF_QUALIFIER
:
4219 pedwarn (input_location
, 0,
4221 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4228 /* Warn about the use of variadic templates when appropriate. */
4230 maybe_warn_variadic_templates (void)
4232 maybe_warn_cpp0x (CPP0X_VARIADIC_TEMPLATES
);
4236 /* Issue an ISO C++98 pedantic warning at LOCATION, conditional on
4237 option OPT with text GMSGID. Use this function to report
4238 diagnostics for constructs that are invalid C++98, but valid
4241 pedwarn_cxx98 (location_t location
, int opt
, const char *gmsgid
, ...)
4243 diagnostic_info diagnostic
;
4246 rich_location
richloc (line_table
, location
);
4248 va_start (ap
, gmsgid
);
4249 diagnostic_set_info (&diagnostic
, gmsgid
, &ap
, &richloc
,
4250 (cxx_dialect
== cxx98
) ? DK_PEDWARN
: DK_WARNING
);
4251 diagnostic
.option_index
= opt
;
4252 ret
= diagnostic_report_diagnostic (global_dc
, &diagnostic
);
4257 /* Issue a diagnostic that NAME cannot be found in SCOPE. DECL is what
4258 we found when we tried to do the lookup. LOCATION is the location of
4259 the NAME identifier. */
4262 qualified_name_lookup_error (tree scope
, tree name
,
4263 tree decl
, location_t location
)
4265 if (scope
== error_mark_node
)
4266 ; /* We already complained. */
4267 else if (TYPE_P (scope
))
4269 if (!COMPLETE_TYPE_P (scope
))
4270 error_at (location
, "incomplete type %qT used in nested name specifier",
4272 else if (TREE_CODE (decl
) == TREE_LIST
)
4274 error_at (location
, "reference to %<%T::%D%> is ambiguous",
4276 print_candidates (decl
);
4281 if (SCOPED_ENUM_P (scope
) && TREE_CODE (name
) == IDENTIFIER_NODE
)
4282 hint
= suggest_alternative_in_scoped_enum (name
, scope
);
4283 if (const char *suggestion
= hint
.suggestion ())
4285 gcc_rich_location
richloc (location
);
4286 richloc
.add_fixit_replace (suggestion
);
4288 "%qD is not a member of %qT; did you mean %qs?",
4289 name
, scope
, suggestion
);
4292 error_at (location
, "%qD is not a member of %qT", name
, scope
);
4295 else if (scope
!= global_namespace
)
4297 auto_diagnostic_group d
;
4298 bool emit_fixit
= true;
4300 = suggest_alternative_in_explicit_scope (location
, name
, scope
);
4303 hint
= suggest_alternatives_in_other_namespaces (location
, name
);
4304 /* "location" is just the location of the name, not of the explicit
4305 scope, and it's not easy to get at the latter, so we can't issue
4306 fix-it hints for the suggestion. */
4309 if (const char *suggestion
= hint
.suggestion ())
4311 gcc_rich_location
richloc (location
);
4313 richloc
.add_fixit_replace (suggestion
);
4314 error_at (&richloc
, "%qD is not a member of %qD; did you mean %qs?",
4315 name
, scope
, suggestion
);
4318 error_at (location
, "%qD is not a member of %qD", name
, scope
);
4322 auto_diagnostic_group d
;
4323 name_hint hint
= suggest_alternatives_for (location
, name
, true);
4324 if (const char *suggestion
= hint
.suggestion ())
4326 gcc_rich_location
richloc (location
);
4327 richloc
.add_fixit_replace (suggestion
);
4329 "%<::%D%> has not been declared; did you mean %qs?",
4333 error_at (location
, "%<::%D%> has not been declared", name
);
4337 /* C++-specific implementation of range_label::get_text () vfunc for
4338 range_label_for_type_mismatch.
4340 Compare with print_template_differences above. */
4343 range_label_for_type_mismatch::get_text (unsigned /*range_idx*/) const
4345 if (m_labelled_type
== NULL_TREE
)
4346 return label_text (NULL
, false);
4348 const bool verbose
= false;
4349 const bool show_color
= false;
4353 && comparable_template_types_p (m_labelled_type
, m_other_type
))
4354 result
= type_to_string_with_compare (m_labelled_type
, m_other_type
,
4355 verbose
, show_color
);
4357 result
= type_to_string (m_labelled_type
, verbose
, true, NULL
, show_color
);
4359 /* Both of the above return GC-allocated buffers, so the caller mustn't
4361 return label_text (const_cast <char *> (result
), false);