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 (LAMBDA_TYPE_P (t
))
743 /* A lambda's "type" is essentially its signature. */
744 pp_string (pp
, M_("<lambda"));
745 if (lambda_function (t
))
747 FUNCTION_FIRST_USER_PARMTYPE (lambda_function (t
)),
751 else if (!name
|| IDENTIFIER_ANON_P (name
))
753 if (flags
& TFF_CLASS_KEY_OR_ENUM
)
754 pp_string (pp
, M_("<unnamed>"));
756 pp_printf (pp
, M_("<unnamed %s>"), variety
);
759 pp_cxx_tree_identifier (pp
, name
);
762 dump_template_parms (pp
, TYPE_TEMPLATE_INFO (t
),
763 !CLASSTYPE_USE_TEMPLATE (t
),
764 flags
& ~TFF_TEMPLATE_HEADER
);
767 /* Dump into the obstack the initial part of the output for a given type.
768 This is necessary when dealing with things like functions returning
771 return type of `int (* fee ())()': pointer -> function -> int. Both
772 pointer (and reference and offset) and function (and member) types must
773 deal with prefix and suffix.
775 Arrays must also do this for DECL nodes, like int a[], and for things like
779 dump_type_prefix (cxx_pretty_printer
*pp
, tree t
, int flags
)
781 if (TYPE_PTRMEMFUNC_P (t
))
783 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
787 switch (TREE_CODE (t
))
792 tree sub
= TREE_TYPE (t
);
794 dump_type_prefix (pp
, sub
, flags
);
795 if (TREE_CODE (sub
) == ARRAY_TYPE
796 || TREE_CODE (sub
) == FUNCTION_TYPE
)
798 pp_cxx_whitespace (pp
);
799 pp_cxx_left_paren (pp
);
800 pp_c_attributes_display (pp
, TYPE_ATTRIBUTES (sub
));
804 else if (TYPE_REF_P (t
))
806 if (TYPE_REF_IS_RVALUE (t
))
807 pp_ampersand_ampersand (pp
);
811 pp
->padding
= pp_before
;
812 pp_cxx_cv_qualifier_seq (pp
, t
);
818 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
819 if (TREE_CODE (t
) == OFFSET_TYPE
) /* pmfs deal with this in d_t_p */
822 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
823 pp_cxx_left_paren (pp
);
824 dump_type (pp
, TYPE_OFFSET_BASETYPE (t
), flags
);
825 pp_cxx_colon_colon (pp
);
828 pp_cxx_cv_qualifier_seq (pp
, t
);
829 pp
->padding
= pp_before
;
832 /* This can be reached without a pointer when dealing with
833 templates, e.g. std::is_function. */
835 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
839 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
841 pp_cxx_left_paren (pp
);
842 dump_aggr_type (pp
, TYPE_METHOD_BASETYPE (t
), flags
);
843 pp_cxx_colon_colon (pp
);
847 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
851 case IDENTIFIER_NODE
:
856 case TEMPLATE_TYPE_PARM
:
857 case TEMPLATE_TEMPLATE_PARM
:
858 case BOUND_TEMPLATE_TEMPLATE_PARM
:
869 case UNDERLYING_TYPE
:
871 case TYPE_PACK_EXPANSION
:
872 case FIXED_POINT_TYPE
:
874 dump_type (pp
, t
, flags
);
875 pp
->padding
= pp_before
;
879 pp_unsupported_tree (pp
, t
);
882 pp_string (pp
, M_("<typeprefixerror>"));
887 /* Dump the suffix of type T, under control of FLAGS. This is the part
888 which appears after the identifier (or function parms). */
891 dump_type_suffix (cxx_pretty_printer
*pp
, tree t
, int flags
)
893 if (TYPE_PTRMEMFUNC_P (t
))
894 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
896 switch (TREE_CODE (t
))
901 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
902 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
903 pp_cxx_right_paren (pp
);
904 if (TREE_CODE (t
) == POINTER_TYPE
)
905 flags
|= TFF_POINTER
;
906 dump_type_suffix (pp
, TREE_TYPE (t
), flags
);
913 if (TREE_CODE (t
) == METHOD_TYPE
)
914 /* Can only be reached through a pointer. */
915 pp_cxx_right_paren (pp
);
916 arg
= TYPE_ARG_TYPES (t
);
917 if (TREE_CODE (t
) == METHOD_TYPE
)
918 arg
= TREE_CHAIN (arg
);
920 /* Function pointers don't have default args. Not in standard C++,
921 anyway; they may in g++, but we'll just pretend otherwise. */
922 dump_parameters (pp
, arg
, flags
& ~TFF_FUNCTION_DEFAULT_ARGUMENTS
);
924 pp
->padding
= pp_before
;
925 pp_cxx_cv_qualifiers (pp
, type_memfn_quals (t
),
926 TREE_CODE (t
) == FUNCTION_TYPE
927 && (flags
& TFF_POINTER
));
928 dump_ref_qualifier (pp
, t
, flags
);
929 if (tx_safe_fn_type_p (t
))
930 pp_cxx_ws_string (pp
, "transaction_safe");
931 dump_exception_spec (pp
, TYPE_RAISES_EXCEPTIONS (t
), flags
);
932 dump_type_suffix (pp
, TREE_TYPE (t
), flags
);
938 pp_cxx_left_bracket (pp
);
939 if (tree dtype
= TYPE_DOMAIN (t
))
941 tree max
= TYPE_MAX_VALUE (dtype
);
942 /* Zero-length arrays have an upper bound of SIZE_MAX. */
943 if (integer_all_onesp (max
))
944 pp_character (pp
, '0');
945 else if (tree_fits_shwi_p (max
))
946 pp_wide_integer (pp
, tree_to_shwi (max
) + 1);
950 if (TREE_CODE (max
) == SAVE_EXPR
)
951 max
= TREE_OPERAND (max
, 0);
952 if (TREE_CODE (max
) == MINUS_EXPR
953 || TREE_CODE (max
) == PLUS_EXPR
)
955 max
= TREE_OPERAND (max
, 0);
956 while (CONVERT_EXPR_P (max
))
957 max
= TREE_OPERAND (max
, 0);
960 max
= fold_build2_loc (input_location
,
961 PLUS_EXPR
, dtype
, max
,
962 build_int_cst (dtype
, 1));
963 dump_expr (pp
, max
, flags
& ~TFF_EXPR_IN_PARENS
);
966 pp_cxx_right_bracket (pp
);
967 dump_type_suffix (pp
, TREE_TYPE (t
), flags
);
971 case IDENTIFIER_NODE
:
976 case TEMPLATE_TYPE_PARM
:
977 case TEMPLATE_TEMPLATE_PARM
:
978 case BOUND_TEMPLATE_TEMPLATE_PARM
:
989 case UNDERLYING_TYPE
:
991 case TYPE_PACK_EXPANSION
:
992 case FIXED_POINT_TYPE
:
997 pp_unsupported_tree (pp
, t
);
999 /* Don't mark it here, we should have already done in
1000 dump_type_prefix. */
1006 dump_global_iord (cxx_pretty_printer
*pp
, tree t
)
1008 const char *p
= NULL
;
1010 if (DECL_GLOBAL_CTOR_P (t
))
1011 p
= M_("(static initializers for %s)");
1012 else if (DECL_GLOBAL_DTOR_P (t
))
1013 p
= M_("(static destructors for %s)");
1017 pp_printf (pp
, p
, DECL_SOURCE_FILE (t
));
1021 dump_simple_decl (cxx_pretty_printer
*pp
, tree t
, tree type
, int flags
)
1023 if (template_parm_object_p (t
))
1024 return dump_expr (pp
, DECL_INITIAL (t
), flags
);
1026 if (flags
& TFF_DECL_SPECIFIERS
)
1028 if (VAR_P (t
) && DECL_DECLARED_CONSTEXPR_P (t
))
1030 if (DECL_LANG_SPECIFIC (t
) && DECL_DECLARED_CONCEPT_P (t
))
1031 pp_cxx_ws_string (pp
, "concept");
1033 pp_cxx_ws_string (pp
, "constexpr");
1035 dump_type_prefix (pp
, type
, flags
& ~TFF_UNQUALIFIED_NAME
);
1036 pp_maybe_space (pp
);
1038 if (! (flags
& TFF_UNQUALIFIED_NAME
)
1039 && TREE_CODE (t
) != PARM_DECL
1040 && (!DECL_INITIAL (t
)
1041 || TREE_CODE (DECL_INITIAL (t
)) != TEMPLATE_PARM_INDEX
))
1042 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1043 flags
&= ~TFF_UNQUALIFIED_NAME
;
1044 if ((flags
& TFF_DECL_SPECIFIERS
)
1045 && DECL_TEMPLATE_PARM_P (t
)
1046 && TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (t
)))
1047 pp_string (pp
, "...");
1050 if (TREE_CODE (t
) == FIELD_DECL
&& DECL_NORMAL_CAPTURE_P (t
))
1053 pp_string (pp
, IDENTIFIER_POINTER (DECL_NAME (t
)) + 2);
1054 pp_string (pp
, " capture>");
1057 dump_decl (pp
, DECL_NAME (t
), flags
);
1059 else if (DECL_DECOMPOSITION_P (t
))
1060 pp_string (pp
, M_("<structured bindings>"));
1062 pp_string (pp
, M_("<anonymous>"));
1063 if (flags
& TFF_DECL_SPECIFIERS
)
1064 dump_type_suffix (pp
, type
, flags
);
1067 /* Print an IDENTIFIER_NODE that is the name of a declaration. */
1070 dump_decl_name (cxx_pretty_printer
*pp
, tree t
, int flags
)
1072 /* These special cases are duplicated here so that other functions
1073 can feed identifiers to error and get them demangled properly. */
1074 if (IDENTIFIER_CONV_OP_P (t
))
1076 pp_cxx_ws_string (pp
, "operator");
1077 /* Not exactly IDENTIFIER_TYPE_VALUE. */
1078 dump_type (pp
, TREE_TYPE (t
), flags
);
1081 if (dguide_name_p (t
))
1083 dump_decl (pp
, CLASSTYPE_TI_TEMPLATE (TREE_TYPE (t
)),
1084 TFF_UNQUALIFIED_NAME
);
1088 const char *str
= IDENTIFIER_POINTER (t
);
1089 if (!strncmp (str
, "_ZGR", 3))
1091 pp_cxx_ws_string (pp
, "<temporary>");
1095 pp_cxx_tree_identifier (pp
, t
);
1098 /* Dump a human readable string for the decl T under control of FLAGS. */
1101 dump_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
1106 /* If doing Objective-C++, give Objective-C a chance to demangle
1107 Objective-C method names. */
1108 if (c_dialect_objc ())
1110 const char *demangled
= objc_maybe_printable_name (t
, flags
);
1113 pp_string (pp
, demangled
);
1118 switch (TREE_CODE (t
))
1121 /* Don't say 'typedef class A' */
1122 if (DECL_ARTIFICIAL (t
) && !DECL_SELF_REFERENCE_P (t
))
1124 if ((flags
& TFF_DECL_SPECIFIERS
)
1125 && TREE_CODE (TREE_TYPE (t
)) == TEMPLATE_TYPE_PARM
)
1127 /* Say `class T' not just `T'. */
1128 pp_cxx_ws_string (pp
, "class");
1130 /* Emit the `...' for a parameter pack. */
1131 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t
)))
1132 pp_cxx_ws_string (pp
, "...");
1135 dump_type (pp
, TREE_TYPE (t
), flags
);
1138 if (TYPE_DECL_ALIAS_P (t
)
1139 && (flags
& TFF_DECL_SPECIFIERS
1140 || flags
& TFF_CLASS_KEY_OR_ENUM
))
1142 pp_cxx_ws_string (pp
, "using");
1143 dump_decl (pp
, DECL_NAME (t
), flags
);
1144 pp_cxx_whitespace (pp
);
1145 pp_cxx_ws_string (pp
, "=");
1146 pp_cxx_whitespace (pp
);
1147 dump_type (pp
, (DECL_ORIGINAL_TYPE (t
)
1148 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
)),
1152 if ((flags
& TFF_DECL_SPECIFIERS
)
1153 && !DECL_SELF_REFERENCE_P (t
))
1154 pp_cxx_ws_string (pp
, "typedef");
1155 dump_simple_decl (pp
, t
, DECL_ORIGINAL_TYPE (t
)
1156 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
),
1161 if (DECL_NAME (t
) && VTABLE_NAME_P (DECL_NAME (t
)))
1163 pp_string (pp
, M_("vtable for "));
1164 gcc_assert (TYPE_P (DECL_CONTEXT (t
)));
1165 dump_type (pp
, DECL_CONTEXT (t
), flags
);
1171 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1173 /* Handle variable template specializations. */
1175 && DECL_LANG_SPECIFIC (t
)
1176 && DECL_TEMPLATE_INFO (t
)
1177 && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t
)))
1179 pp_cxx_begin_template_argument_list (pp
);
1180 tree args
= INNERMOST_TEMPLATE_ARGS (DECL_TI_ARGS (t
));
1181 dump_template_argument_list (pp
, args
, flags
);
1182 pp_cxx_end_template_argument_list (pp
);
1187 pp_string (pp
, M_("<return value> "));
1188 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1191 case NAMESPACE_DECL
:
1192 if (flags
& TFF_DECL_SPECIFIERS
)
1193 pp
->declaration (t
);
1196 if (! (flags
& TFF_UNQUALIFIED_NAME
))
1197 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1198 flags
&= ~TFF_UNQUALIFIED_NAME
;
1199 if (DECL_NAME (t
) == NULL_TREE
)
1201 if (!(pp
->flags
& pp_c_flag_gnu_v3
))
1202 pp_cxx_ws_string (pp
, M_("{anonymous}"));
1204 pp_cxx_ws_string (pp
, M_("(anonymous namespace)"));
1207 pp_cxx_tree_identifier (pp
, DECL_NAME (t
));
1212 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
1213 pp_cxx_colon_colon (pp
);
1214 dump_decl (pp
, TREE_OPERAND (t
, 1), TFF_UNQUALIFIED_NAME
);
1218 dump_decl (pp
, TREE_OPERAND (t
, 0), flags
);
1219 pp_cxx_left_bracket (pp
);
1220 dump_decl (pp
, TREE_OPERAND (t
, 1), flags
);
1221 pp_cxx_right_bracket (pp
);
1224 /* So that we can do dump_decl on an aggr type. */
1228 dump_type (pp
, t
, flags
);
1232 /* This is a pseudo destructor call which has not been folded into
1233 a PSEUDO_DTOR_EXPR yet. */
1234 pp_cxx_complement (pp
);
1235 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
1242 case IDENTIFIER_NODE
:
1243 dump_decl_name (pp
, t
, flags
);
1247 if (!OVL_SINGLE_P (t
))
1249 tree ctx
= ovl_scope (t
);
1250 if (ctx
!= global_namespace
)
1253 dump_type (pp
, ctx
, flags
);
1255 dump_decl (pp
, ctx
, flags
);
1256 pp_cxx_colon_colon (pp
);
1258 dump_decl (pp
, OVL_NAME (t
), flags
);
1262 /* If there's only one function, just treat it like an ordinary
1268 if (! DECL_LANG_SPECIFIC (t
))
1270 if (DECL_ABSTRACT_ORIGIN (t
)
1271 && DECL_ABSTRACT_ORIGIN (t
) != t
)
1272 dump_decl (pp
, DECL_ABSTRACT_ORIGIN (t
), flags
);
1274 dump_function_name (pp
, t
, flags
);
1276 else if (DECL_GLOBAL_CTOR_P (t
) || DECL_GLOBAL_DTOR_P (t
))
1277 dump_global_iord (pp
, t
);
1279 dump_function_decl (pp
, t
, flags
);
1283 dump_template_decl (pp
, t
, flags
);
1286 case TEMPLATE_ID_EXPR
:
1288 tree name
= TREE_OPERAND (t
, 0);
1289 tree args
= TREE_OPERAND (t
, 1);
1291 if (!identifier_p (name
))
1292 name
= OVL_NAME (name
);
1293 dump_decl (pp
, name
, flags
);
1294 pp_cxx_begin_template_argument_list (pp
);
1295 if (args
== error_mark_node
)
1296 pp_string (pp
, M_("<template arguments error>"));
1298 dump_template_argument_list
1299 (pp
, args
, flags
|TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS
);
1300 pp_cxx_end_template_argument_list (pp
);
1305 pp_cxx_tree_identifier (pp
, DECL_NAME (t
));
1309 if ((TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == ENUMERAL_TYPE
)
1310 || (DECL_INITIAL (t
) &&
1311 TREE_CODE (DECL_INITIAL (t
)) == TEMPLATE_PARM_INDEX
))
1312 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1313 else if (DECL_NAME (t
))
1314 dump_decl (pp
, DECL_NAME (t
), flags
);
1315 else if (DECL_INITIAL (t
))
1316 dump_expr (pp
, DECL_INITIAL (t
), flags
| TFF_EXPR_IN_PARENS
);
1318 pp_string (pp
, M_("<enumerator>"));
1323 pp_cxx_ws_string (pp
, "using");
1324 tree scope
= USING_DECL_SCOPE (t
);
1325 bool variadic
= false;
1326 if (PACK_EXPANSION_P (scope
))
1328 scope
= PACK_EXPANSION_PATTERN (scope
);
1331 dump_type (pp
, scope
, flags
);
1332 pp_cxx_colon_colon (pp
);
1333 dump_decl (pp
, DECL_NAME (t
), flags
);
1335 pp_cxx_ws_string (pp
, "...");
1340 pp
->declaration (t
);
1344 dump_decl (pp
, BASELINK_FUNCTIONS (t
), flags
);
1347 case NON_DEPENDENT_EXPR
:
1348 dump_expr (pp
, t
, flags
);
1351 case TEMPLATE_TYPE_PARM
:
1352 if (flags
& TFF_DECL_SPECIFIERS
)
1353 pp
->declaration (t
);
1358 case UNBOUND_CLASS_TEMPLATE
:
1359 case TYPE_PACK_EXPANSION
:
1361 dump_type (pp
, t
, flags
);
1365 pp_unsupported_tree (pp
, t
);
1369 pp_string (pp
, M_("<declaration error>"));
1374 /* Dump a template declaration T under control of FLAGS. This means the
1375 'template <...> leaders plus the 'class X' or 'void fn(...)' part. */
1378 dump_template_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
1380 tree orig_parms
= DECL_TEMPLATE_PARMS (t
);
1384 if (flags
& TFF_TEMPLATE_HEADER
)
1386 for (parms
= orig_parms
= nreverse (orig_parms
);
1388 parms
= TREE_CHAIN (parms
))
1390 tree inner_parms
= INNERMOST_TEMPLATE_PARMS (parms
);
1391 int len
= TREE_VEC_LENGTH (inner_parms
);
1395 /* Skip over the dummy template levels of a template template
1397 gcc_assert (TREE_CODE (TREE_TYPE (t
)) == TEMPLATE_TEMPLATE_PARM
);
1401 pp_cxx_ws_string (pp
, "template");
1402 pp_cxx_begin_template_argument_list (pp
);
1404 /* If we've shown the template prefix, we'd better show the
1405 parameters' and decl's type too. */
1406 flags
|= TFF_DECL_SPECIFIERS
;
1408 for (i
= 0; i
< len
; i
++)
1411 pp_separate_with_comma (pp
);
1412 dump_template_parameter (pp
, TREE_VEC_ELT (inner_parms
, i
),
1415 pp_cxx_end_template_argument_list (pp
);
1416 pp_cxx_whitespace (pp
);
1418 nreverse(orig_parms
);
1420 if (DECL_TEMPLATE_TEMPLATE_PARM_P (t
))
1422 /* Say `template<arg> class TT' not just `template<arg> TT'. */
1423 pp_cxx_ws_string (pp
, "class");
1425 /* If this is a parameter pack, print the ellipsis. */
1426 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t
)))
1427 pp_cxx_ws_string (pp
, "...");
1430 /* Only print the requirements if we're also printing
1431 the template header. */
1433 if (tree ci
= get_constraints (t
))
1434 if (check_constraint_info (ci
))
1435 if (tree reqs
= CI_TEMPLATE_REQS (ci
))
1437 pp_cxx_requires_clause (pp
, reqs
);
1438 pp_cxx_whitespace (pp
);
1443 if (DECL_CLASS_TEMPLATE_P (t
))
1444 dump_type (pp
, TREE_TYPE (t
),
1445 ((flags
& ~TFF_CLASS_KEY_OR_ENUM
) | TFF_TEMPLATE_NAME
1446 | (flags
& TFF_DECL_SPECIFIERS
? TFF_CLASS_KEY_OR_ENUM
: 0)));
1447 else if (DECL_TEMPLATE_RESULT (t
)
1448 && (VAR_P (DECL_TEMPLATE_RESULT (t
))
1449 /* Alias template. */
1450 || DECL_TYPE_TEMPLATE_P (t
)))
1451 dump_decl (pp
, DECL_TEMPLATE_RESULT (t
), flags
| TFF_TEMPLATE_NAME
);
1454 gcc_assert (TREE_TYPE (t
));
1455 switch (NEXT_CODE (t
))
1459 dump_function_decl (pp
, t
, flags
| TFF_TEMPLATE_NAME
);
1462 /* This case can occur with some invalid code. */
1463 dump_type (pp
, TREE_TYPE (t
),
1464 (flags
& ~TFF_CLASS_KEY_OR_ENUM
) | TFF_TEMPLATE_NAME
1465 | (flags
& TFF_DECL_SPECIFIERS
1466 ? TFF_CLASS_KEY_OR_ENUM
: 0));
1471 /* find_typenames looks through the type of the function template T
1472 and returns a vec containing any typedefs, decltypes or TYPENAME_TYPEs
1475 struct find_typenames_t
1477 hash_set
<tree
> *p_set
;
1478 vec
<tree
, va_gc
> *typenames
;
1482 find_typenames_r (tree
*tp
, int *walk_subtrees
, void *data
)
1484 struct find_typenames_t
*d
= (struct find_typenames_t
*)data
;
1485 tree mv
= NULL_TREE
;
1487 if (TYPE_P (*tp
) && is_typedef_decl (TYPE_NAME (*tp
)))
1488 /* Add the type of the typedef without any additional cv-quals. */
1489 mv
= TREE_TYPE (TYPE_NAME (*tp
));
1490 else if (TREE_CODE (*tp
) == TYPENAME_TYPE
1491 || TREE_CODE (*tp
) == DECLTYPE_TYPE
)
1492 /* Add the typename without any cv-qualifiers. */
1493 mv
= TYPE_MAIN_VARIANT (*tp
);
1495 if (PACK_EXPANSION_P (*tp
))
1497 /* Don't mess with parameter packs since we don't remember
1498 the pack expansion context for a particular typename. */
1499 *walk_subtrees
= false;
1503 if (mv
&& (mv
== *tp
|| !d
->p_set
->add (mv
)))
1504 vec_safe_push (d
->typenames
, mv
);
1506 /* Search into class template arguments, which cp_walk_subtrees
1508 if (CLASS_TYPE_P (*tp
) && CLASSTYPE_TEMPLATE_INFO (*tp
))
1509 cp_walk_tree (&CLASSTYPE_TI_ARGS (*tp
), find_typenames_r
,
1515 static vec
<tree
, va_gc
> *
1516 find_typenames (tree t
)
1518 struct find_typenames_t ft
;
1519 ft
.p_set
= new hash_set
<tree
>;
1520 ft
.typenames
= NULL
;
1521 cp_walk_tree (&TREE_TYPE (DECL_TEMPLATE_RESULT (t
)),
1522 find_typenames_r
, &ft
, ft
.p_set
);
1524 return ft
.typenames
;
1527 /* Output the "[with ...]" clause for a template instantiation T iff
1528 TEMPLATE_PARMS, TEMPLATE_ARGS and FLAGS are suitable. T may be NULL if
1529 formatting a deduction/substitution diagnostic rather than an
1533 dump_substitution (cxx_pretty_printer
*pp
,
1534 tree t
, tree template_parms
, tree template_args
,
1537 if (template_parms
!= NULL_TREE
&& template_args
!= NULL_TREE
1538 && !(flags
& TFF_NO_TEMPLATE_BINDINGS
))
1540 vec
<tree
, va_gc
> *typenames
= t
? find_typenames (t
) : NULL
;
1541 pp_cxx_whitespace (pp
);
1542 pp_cxx_left_bracket (pp
);
1543 pp
->translate_string ("with");
1544 pp_cxx_whitespace (pp
);
1545 dump_template_bindings (pp
, template_parms
, template_args
, typenames
);
1546 pp_cxx_right_bracket (pp
);
1550 /* Dump the lambda function FN including its 'mutable' qualifier and any
1551 template bindings. */
1554 dump_lambda_function (cxx_pretty_printer
*pp
,
1555 tree fn
, tree template_parms
, tree template_args
,
1558 /* A lambda's signature is essentially its "type". */
1559 dump_type (pp
, DECL_CONTEXT (fn
), flags
);
1560 if (!(TYPE_QUALS (class_of_this_parm (TREE_TYPE (fn
))) & TYPE_QUAL_CONST
))
1562 pp
->padding
= pp_before
;
1563 pp_c_ws_string (pp
, "mutable");
1565 dump_substitution (pp
, fn
, template_parms
, template_args
, flags
);
1568 /* Pretty print a function decl. There are several ways we want to print a
1569 function declaration. The TFF_ bits in FLAGS tells us how to behave.
1570 As error can only apply the '#' flag once to give 0 and 1 for V, there
1571 is %D which doesn't print the throw specs, and %F which does. */
1574 dump_function_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
1578 tree cname
= NULL_TREE
;
1579 tree template_args
= NULL_TREE
;
1580 tree template_parms
= NULL_TREE
;
1581 int show_return
= flags
& TFF_RETURN_TYPE
|| flags
& TFF_DECL_SPECIFIERS
;
1582 int do_outer_scope
= ! (flags
& TFF_UNQUALIFIED_NAME
);
1585 tree ret
= NULL_TREE
;
1587 flags
&= ~(TFF_UNQUALIFIED_NAME
| TFF_TEMPLATE_NAME
);
1588 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1589 t
= DECL_TEMPLATE_RESULT (t
);
1591 /* Save the exceptions, in case t is a specialization and we are
1592 emitting an error about incompatible specifications. */
1593 exceptions
= TYPE_RAISES_EXCEPTIONS (TREE_TYPE (t
));
1595 /* Likewise for the constexpr specifier, in case t is a specialization. */
1596 constexpr_p
= DECL_DECLARED_CONSTEXPR_P (t
);
1598 /* Pretty print template instantiations only. */
1599 if (DECL_USE_TEMPLATE (t
) && DECL_TEMPLATE_INFO (t
)
1600 && !(flags
& TFF_NO_TEMPLATE_BINDINGS
)
1601 && flag_pretty_templates
)
1605 template_args
= DECL_TI_ARGS (t
);
1606 tmpl
= most_general_template (t
);
1607 if (tmpl
&& TREE_CODE (tmpl
) == TEMPLATE_DECL
)
1609 template_parms
= DECL_TEMPLATE_PARMS (tmpl
);
1614 if (DECL_NAME (t
) && LAMBDA_FUNCTION_P (t
))
1615 return dump_lambda_function (pp
, t
, template_parms
, template_args
, flags
);
1617 fntype
= TREE_TYPE (t
);
1618 parmtypes
= FUNCTION_FIRST_USER_PARMTYPE (t
);
1620 if (DECL_CLASS_SCOPE_P (t
))
1621 cname
= DECL_CONTEXT (t
);
1622 /* This is for partially instantiated template methods. */
1623 else if (TREE_CODE (fntype
) == METHOD_TYPE
)
1624 cname
= TREE_TYPE (TREE_VALUE (parmtypes
));
1626 if (flags
& TFF_DECL_SPECIFIERS
)
1628 if (DECL_STATIC_FUNCTION_P (t
))
1629 pp_cxx_ws_string (pp
, "static");
1630 else if (DECL_VIRTUAL_P (t
))
1631 pp_cxx_ws_string (pp
, "virtual");
1635 if (DECL_DECLARED_CONCEPT_P (t
))
1636 pp_cxx_ws_string (pp
, "concept");
1638 pp_cxx_ws_string (pp
, "constexpr");
1642 /* Print the return type? */
1644 show_return
= (!DECL_CONV_FN_P (t
) && !DECL_CONSTRUCTOR_P (t
)
1645 && !DECL_DESTRUCTOR_P (t
) && !deduction_guide_p (t
));
1648 ret
= fndecl_declared_return_type (t
);
1649 dump_type_prefix (pp
, ret
, flags
);
1652 /* Print the function name. */
1653 if (!do_outer_scope
)
1657 dump_type (pp
, cname
, flags
);
1658 pp_cxx_colon_colon (pp
);
1661 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1663 dump_function_name (pp
, t
, flags
);
1665 if (!(flags
& TFF_NO_FUNCTION_ARGUMENTS
))
1667 dump_parameters (pp
, parmtypes
, flags
);
1669 if (TREE_CODE (fntype
) == METHOD_TYPE
)
1671 pp
->padding
= pp_before
;
1672 pp_cxx_cv_qualifier_seq (pp
, class_of_this_parm (fntype
));
1673 dump_ref_qualifier (pp
, fntype
, flags
);
1676 if (tx_safe_fn_type_p (fntype
))
1678 pp
->padding
= pp_before
;
1679 pp_cxx_ws_string (pp
, "transaction_safe");
1682 if (flags
& TFF_EXCEPTION_SPECIFICATION
)
1684 pp
->padding
= pp_before
;
1685 dump_exception_spec (pp
, exceptions
, flags
);
1689 dump_type_suffix (pp
, ret
, flags
);
1690 else if (deduction_guide_p (t
))
1692 pp_cxx_ws_string (pp
, "->");
1693 dump_type (pp
, TREE_TYPE (TREE_TYPE (t
)), flags
);
1697 if (tree ci
= get_constraints (t
))
1698 if (tree reqs
= CI_DECLARATOR_REQS (ci
))
1699 pp_cxx_requires_clause (pp
, reqs
);
1701 dump_substitution (pp
, t
, template_parms
, template_args
, flags
);
1703 if (tree base
= DECL_INHERITED_CTOR_BASE (t
))
1705 pp_cxx_ws_string (pp
, "[inherited from");
1706 dump_type (pp
, base
, TFF_PLAIN_IDENTIFIER
);
1707 pp_character (pp
, ']');
1710 else if (template_args
)
1712 bool need_comma
= false;
1714 pp_cxx_begin_template_argument_list (pp
);
1715 template_args
= INNERMOST_TEMPLATE_ARGS (template_args
);
1716 for (i
= 0; i
< TREE_VEC_LENGTH (template_args
); ++i
)
1718 tree arg
= TREE_VEC_ELT (template_args
, i
);
1720 pp_separate_with_comma (pp
);
1721 if (ARGUMENT_PACK_P (arg
))
1722 pp_cxx_left_brace (pp
);
1723 dump_template_argument (pp
, arg
, TFF_PLAIN_IDENTIFIER
);
1724 if (ARGUMENT_PACK_P (arg
))
1725 pp_cxx_right_brace (pp
);
1728 pp_cxx_end_template_argument_list (pp
);
1732 /* Print a parameter list. If this is for a member function, the
1733 member object ptr (and any other hidden args) should have
1734 already been removed. */
1737 dump_parameters (cxx_pretty_printer
*pp
, tree parmtypes
, int flags
)
1740 flags
&= ~TFF_SCOPE
;
1741 pp_cxx_left_paren (pp
);
1743 for (first
= 1; parmtypes
!= void_list_node
;
1744 parmtypes
= TREE_CHAIN (parmtypes
))
1747 pp_separate_with_comma (pp
);
1751 pp_cxx_ws_string (pp
, "...");
1755 dump_type (pp
, TREE_VALUE (parmtypes
), flags
);
1757 if ((flags
& TFF_FUNCTION_DEFAULT_ARGUMENTS
) && TREE_PURPOSE (parmtypes
))
1759 pp_cxx_whitespace (pp
);
1761 pp_cxx_whitespace (pp
);
1762 dump_expr (pp
, TREE_PURPOSE (parmtypes
), flags
| TFF_EXPR_IN_PARENS
);
1766 pp_cxx_right_paren (pp
);
1769 /* Print ref-qualifier of a FUNCTION_TYPE or METHOD_TYPE. FLAGS are ignored. */
1772 dump_ref_qualifier (cxx_pretty_printer
*pp
, tree t
, int flags ATTRIBUTE_UNUSED
)
1774 if (FUNCTION_REF_QUALIFIED (t
))
1776 pp
->padding
= pp_before
;
1777 if (FUNCTION_RVALUE_QUALIFIED (t
))
1778 pp_cxx_ws_string (pp
, "&&");
1780 pp_cxx_ws_string (pp
, "&");
1784 /* Print an exception specification. T is the exception specification. */
1787 dump_exception_spec (cxx_pretty_printer
*pp
, tree t
, int flags
)
1789 if (t
&& TREE_PURPOSE (t
))
1791 pp_cxx_ws_string (pp
, "noexcept");
1792 if (!integer_onep (TREE_PURPOSE (t
)))
1794 pp_cxx_whitespace (pp
);
1795 pp_cxx_left_paren (pp
);
1796 if (DEFERRED_NOEXCEPT_SPEC_P (t
))
1797 pp_cxx_ws_string (pp
, "<uninstantiated>");
1799 dump_expr (pp
, TREE_PURPOSE (t
), flags
);
1800 pp_cxx_right_paren (pp
);
1805 pp_cxx_ws_string (pp
, "throw");
1806 pp_cxx_whitespace (pp
);
1807 pp_cxx_left_paren (pp
);
1808 if (TREE_VALUE (t
) != NULL_TREE
)
1811 dump_type (pp
, TREE_VALUE (t
), flags
);
1815 pp_separate_with_comma (pp
);
1817 pp_cxx_right_paren (pp
);
1821 /* Handle the function name for a FUNCTION_DECL node, grokking operators
1822 and destructors properly. */
1825 dump_function_name (cxx_pretty_printer
*pp
, tree t
, int flags
)
1827 tree name
= DECL_NAME (t
);
1829 /* We can get here with a decl that was synthesized by language-
1830 independent machinery (e.g. coverage.c) in which case it won't
1831 have a lang_specific structure attached and DECL_CONSTRUCTOR_P
1832 will crash. In this case it is safe just to print out the
1834 if (!DECL_LANG_SPECIFIC (t
))
1836 pp_cxx_tree_identifier (pp
, name
);
1840 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1841 t
= DECL_TEMPLATE_RESULT (t
);
1843 /* Don't let the user see __comp_ctor et al. */
1844 if (DECL_CONSTRUCTOR_P (t
)
1845 || DECL_DESTRUCTOR_P (t
))
1847 if (LAMBDA_TYPE_P (DECL_CONTEXT (t
)))
1848 name
= get_identifier ("<lambda>");
1849 else if (TYPE_UNNAMED_P (DECL_CONTEXT (t
)))
1850 name
= get_identifier ("<constructor>");
1852 name
= constructor_name (DECL_CONTEXT (t
));
1855 if (DECL_DESTRUCTOR_P (t
))
1857 pp_cxx_complement (pp
);
1858 dump_decl (pp
, name
, TFF_PLAIN_IDENTIFIER
);
1860 else if (DECL_CONV_FN_P (t
))
1862 /* This cannot use the hack that the operator's return
1863 type is stashed off of its name because it may be
1864 used for error reporting. In the case of conflicting
1865 declarations, both will have the same name, yet
1866 the types will be different, hence the TREE_TYPE field
1867 of the first name will be clobbered by the second. */
1868 pp_cxx_ws_string (pp
, "operator");
1869 dump_type (pp
, TREE_TYPE (TREE_TYPE (t
)), flags
);
1872 dump_decl (pp
, name
, flags
);
1874 if (DECL_TEMPLATE_INFO (t
)
1875 && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t
)
1876 && (TREE_CODE (DECL_TI_TEMPLATE (t
)) != TEMPLATE_DECL
1877 || PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t
))))
1878 dump_template_parms (pp
, DECL_TEMPLATE_INFO (t
), !DECL_USE_TEMPLATE (t
),
1882 /* Dump the template parameters from the template info INFO under control of
1883 FLAGS. PRIMARY indicates whether this is a primary template decl, or
1884 specialization (partial or complete). For partial specializations we show
1885 the specialized parameter values. For a primary template we show no
1889 dump_template_parms (cxx_pretty_printer
*pp
, tree info
,
1890 int primary
, int flags
)
1892 tree args
= info
? TI_ARGS (info
) : NULL_TREE
;
1894 if (primary
&& flags
& TFF_TEMPLATE_NAME
)
1896 flags
&= ~(TFF_CLASS_KEY_OR_ENUM
| TFF_TEMPLATE_NAME
);
1897 pp_cxx_begin_template_argument_list (pp
);
1899 /* Be careful only to print things when we have them, so as not
1900 to crash producing error messages. */
1901 if (args
&& !primary
)
1904 len
= get_non_default_template_args_count (args
, flags
);
1906 args
= INNERMOST_TEMPLATE_ARGS (args
);
1907 for (ix
= 0; ix
!= len
; ix
++)
1909 tree arg
= TREE_VEC_ELT (args
, ix
);
1911 /* Only print a comma if we know there is an argument coming. In
1912 the case of an empty template argument pack, no actual
1913 argument will be printed. */
1915 && (!ARGUMENT_PACK_P (arg
)
1916 || TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg
)) > 0))
1917 pp_separate_with_comma (pp
);
1920 pp_string (pp
, M_("<template parameter error>"));
1922 dump_template_argument (pp
, arg
, flags
);
1927 tree tpl
= TI_TEMPLATE (info
);
1928 tree parms
= DECL_TEMPLATE_PARMS (tpl
);
1931 parms
= TREE_CODE (parms
) == TREE_LIST
? TREE_VALUE (parms
) : NULL_TREE
;
1932 len
= parms
? TREE_VEC_LENGTH (parms
) : 0;
1934 for (ix
= 0; ix
!= len
; ix
++)
1938 if (TREE_VEC_ELT (parms
, ix
) == error_mark_node
)
1940 pp_string (pp
, M_("<template parameter error>"));
1944 parm
= TREE_VALUE (TREE_VEC_ELT (parms
, ix
));
1947 pp_separate_with_comma (pp
);
1949 dump_decl (pp
, parm
, flags
& ~TFF_DECL_SPECIFIERS
);
1952 pp_cxx_end_template_argument_list (pp
);
1955 /* Print out the arguments of CALL_EXPR T as a parenthesized list using
1956 flags FLAGS. Skip over the first argument if SKIPFIRST is true. */
1959 dump_call_expr_args (cxx_pretty_printer
*pp
, tree t
, int flags
, bool skipfirst
)
1962 call_expr_arg_iterator iter
;
1964 pp_cxx_left_paren (pp
);
1965 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, t
)
1971 dump_expr (pp
, arg
, flags
| TFF_EXPR_IN_PARENS
);
1972 if (more_call_expr_args_p (&iter
))
1973 pp_separate_with_comma (pp
);
1976 pp_cxx_right_paren (pp
);
1979 /* Print out the arguments of AGGR_INIT_EXPR T as a parenthesized list
1980 using flags FLAGS. Skip over the first argument if SKIPFIRST is
1984 dump_aggr_init_expr_args (cxx_pretty_printer
*pp
, tree t
, int flags
,
1988 aggr_init_expr_arg_iterator iter
;
1990 pp_cxx_left_paren (pp
);
1991 FOR_EACH_AGGR_INIT_EXPR_ARG (arg
, iter
, t
)
1997 dump_expr (pp
, arg
, flags
| TFF_EXPR_IN_PARENS
);
1998 if (more_aggr_init_expr_args_p (&iter
))
1999 pp_separate_with_comma (pp
);
2002 pp_cxx_right_paren (pp
);
2005 /* Print out a list of initializers (subr of dump_expr). */
2008 dump_expr_list (cxx_pretty_printer
*pp
, tree l
, int flags
)
2012 dump_expr (pp
, TREE_VALUE (l
), flags
| TFF_EXPR_IN_PARENS
);
2015 pp_separate_with_comma (pp
);
2019 /* Print out a vector of initializers (subr of dump_expr). */
2022 dump_expr_init_vec (cxx_pretty_printer
*pp
, vec
<constructor_elt
, va_gc
> *v
,
2025 unsigned HOST_WIDE_INT idx
;
2028 FOR_EACH_CONSTRUCTOR_VALUE (v
, idx
, value
)
2030 dump_expr (pp
, value
, flags
| TFF_EXPR_IN_PARENS
);
2031 if (idx
!= v
->length () - 1)
2032 pp_separate_with_comma (pp
);
2037 /* We've gotten an indirect REFERENCE (an OBJ_TYPE_REF) to a virtual
2038 function. Resolve it to a close relative -- in the sense of static
2039 type -- variant being overridden. That is close to what was written in
2040 the source code. Subroutine of dump_expr. */
2043 resolve_virtual_fun_from_obj_type_ref (tree ref
)
2045 tree obj_type
= TREE_TYPE (OBJ_TYPE_REF_OBJECT (ref
));
2046 HOST_WIDE_INT index
= tree_to_uhwi (OBJ_TYPE_REF_TOKEN (ref
));
2047 tree fun
= BINFO_VIRTUALS (TYPE_BINFO (TREE_TYPE (obj_type
)));
2050 fun
= TREE_CHAIN (fun
);
2051 index
-= (TARGET_VTABLE_USES_DESCRIPTORS
2052 ? TARGET_VTABLE_USES_DESCRIPTORS
: 1);
2058 /* Print out an expression E under control of FLAGS. */
2061 dump_expr (cxx_pretty_printer
*pp
, tree t
, int flags
)
2068 if (STATEMENT_CLASS_P (t
))
2070 pp_cxx_ws_string (pp
, M_("<statement>"));
2074 switch (TREE_CODE (t
))
2082 case NAMESPACE_DECL
:
2086 case IDENTIFIER_NODE
:
2087 dump_decl (pp
, t
, ((flags
& ~(TFF_DECL_SPECIFIERS
|TFF_RETURN_TYPE
2088 |TFF_TEMPLATE_HEADER
))
2089 | TFF_NO_TEMPLATE_BINDINGS
2090 | TFF_NO_FUNCTION_ARGUMENTS
));
2094 if (SSA_NAME_VAR (t
)
2095 && !DECL_ARTIFICIAL (SSA_NAME_VAR (t
)))
2096 dump_expr (pp
, SSA_NAME_VAR (t
), flags
);
2098 pp_cxx_ws_string (pp
, M_("<unknown>"));
2109 case USERDEF_LITERAL
:
2110 pp_cxx_userdef_literal (pp
, t
);
2114 /* While waiting for caret diagnostics, avoid printing
2115 __cxa_allocate_exception, __cxa_throw, and the like. */
2116 pp_cxx_ws_string (pp
, M_("<throw-expression>"));
2121 dump_type (pp
, PTRMEM_CST_CLASS (t
), flags
);
2122 pp_cxx_colon_colon (pp
);
2123 pp_cxx_tree_identifier (pp
, DECL_NAME (PTRMEM_CST_MEMBER (t
)));
2127 pp_cxx_left_paren (pp
);
2128 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2129 pp_separate_with_comma (pp
);
2130 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2131 pp_cxx_right_paren (pp
);
2136 pp_cxx_left_paren (pp
);
2137 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2138 pp_string (pp
, " ? ");
2139 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2140 pp_string (pp
, " : ");
2141 dump_expr (pp
, TREE_OPERAND (t
, 2), flags
| TFF_EXPR_IN_PARENS
);
2142 pp_cxx_right_paren (pp
);
2146 if (TREE_HAS_CONSTRUCTOR (t
))
2148 pp_cxx_ws_string (pp
, "new");
2149 pp_cxx_whitespace (pp
);
2150 dump_type (pp
, TREE_TYPE (TREE_TYPE (t
)), flags
);
2153 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2156 case AGGR_INIT_EXPR
:
2158 tree fn
= NULL_TREE
;
2160 if (TREE_CODE (AGGR_INIT_EXPR_FN (t
)) == ADDR_EXPR
)
2161 fn
= TREE_OPERAND (AGGR_INIT_EXPR_FN (t
), 0);
2163 if (fn
&& TREE_CODE (fn
) == FUNCTION_DECL
)
2165 if (DECL_CONSTRUCTOR_P (fn
))
2166 dump_type (pp
, DECL_CONTEXT (fn
), flags
);
2168 dump_decl (pp
, fn
, 0);
2171 dump_expr (pp
, AGGR_INIT_EXPR_FN (t
), 0);
2173 dump_aggr_init_expr_args (pp
, t
, flags
, true);
2178 tree fn
= CALL_EXPR_FN (t
);
2179 bool skipfirst
= false;
2181 /* Deal with internal functions. */
2182 if (fn
== NULL_TREE
)
2184 pp_string (pp
, internal_fn_name (CALL_EXPR_IFN (t
)));
2185 dump_call_expr_args (pp
, t
, flags
, skipfirst
);
2189 if (TREE_CODE (fn
) == ADDR_EXPR
)
2190 fn
= TREE_OPERAND (fn
, 0);
2192 /* Nobody is interested in seeing the guts of vcalls. */
2193 if (TREE_CODE (fn
) == OBJ_TYPE_REF
)
2194 fn
= resolve_virtual_fun_from_obj_type_ref (fn
);
2196 if (TREE_TYPE (fn
) != NULL_TREE
2197 && NEXT_CODE (fn
) == METHOD_TYPE
2198 && call_expr_nargs (t
))
2200 tree ob
= CALL_EXPR_ARG (t
, 0);
2201 if (TREE_CODE (ob
) == ADDR_EXPR
)
2203 dump_expr (pp
, TREE_OPERAND (ob
, 0),
2204 flags
| TFF_EXPR_IN_PARENS
);
2207 else if (!is_this_parameter (ob
))
2209 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2214 if (flag_sanitize
& SANITIZE_UNDEFINED
2215 && is_ubsan_builtin_p (fn
))
2217 pp_string (cxx_pp
, M_("<ubsan routine call>"));
2220 dump_expr (pp
, fn
, flags
| TFF_EXPR_IN_PARENS
);
2221 dump_call_expr_args (pp
, t
, flags
, skipfirst
);
2226 /* Note that this only works for G++ target exprs. If somebody
2227 builds a general TARGET_EXPR, there's no way to represent that
2228 it initializes anything other that the parameter slot for the
2229 default argument. Note we may have cleared out the first
2230 operand in expand_expr, so don't go killing ourselves. */
2231 if (TREE_OPERAND (t
, 1))
2232 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2235 case POINTER_PLUS_EXPR
:
2236 dump_binary_op (pp
, "+", t
, flags
);
2239 case POINTER_DIFF_EXPR
:
2240 dump_binary_op (pp
, "-", t
, flags
);
2245 dump_binary_op (pp
, OVL_OP_INFO (true, NOP_EXPR
)->name
, t
, flags
);
2251 case TRUNC_DIV_EXPR
:
2252 case TRUNC_MOD_EXPR
:
2260 case TRUTH_ANDIF_EXPR
:
2261 case TRUTH_ORIF_EXPR
:
2268 case EXACT_DIV_EXPR
:
2269 dump_binary_op (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
, t
, flags
);
2273 case FLOOR_DIV_EXPR
:
2274 case ROUND_DIV_EXPR
:
2276 dump_binary_op (pp
, "/", t
, flags
);
2280 case FLOOR_MOD_EXPR
:
2281 case ROUND_MOD_EXPR
:
2282 dump_binary_op (pp
, "%", t
, flags
);
2287 tree ob
= TREE_OPERAND (t
, 0);
2288 if (INDIRECT_REF_P (ob
))
2290 ob
= TREE_OPERAND (ob
, 0);
2291 if (!is_this_parameter (ob
))
2293 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2294 if (TYPE_REF_P (TREE_TYPE (ob
)))
2302 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2303 if (TREE_CODE (ob
) != ARROW_EXPR
)
2306 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
& ~TFF_EXPR_IN_PARENS
);
2311 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2312 pp_cxx_left_bracket (pp
);
2313 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2314 pp_cxx_right_bracket (pp
);
2317 case UNARY_PLUS_EXPR
:
2318 dump_unary_op (pp
, "+", t
, flags
);
2322 if (TREE_CODE (TREE_OPERAND (t
, 0)) == FUNCTION_DECL
2323 || TREE_CODE (TREE_OPERAND (t
, 0)) == STRING_CST
2324 /* An ADDR_EXPR can have reference type. In that case, we
2325 shouldn't print the `&' doing so indicates to the user
2326 that the expression has pointer type. */
2328 && TYPE_REF_P (TREE_TYPE (t
))))
2329 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2330 else if (TREE_CODE (TREE_OPERAND (t
, 0)) == LABEL_DECL
)
2331 dump_unary_op (pp
, "&&", t
, flags
);
2333 dump_unary_op (pp
, "&", t
, flags
);
2337 if (TREE_HAS_CONSTRUCTOR (t
))
2339 t
= TREE_OPERAND (t
, 0);
2340 gcc_assert (TREE_CODE (t
) == CALL_EXPR
);
2341 dump_expr (pp
, CALL_EXPR_FN (t
), flags
| TFF_EXPR_IN_PARENS
);
2342 dump_call_expr_args (pp
, t
, flags
, true);
2346 if (TREE_OPERAND (t
,0) != NULL_TREE
2347 && TREE_TYPE (TREE_OPERAND (t
, 0))
2348 && NEXT_CODE (TREE_OPERAND (t
, 0)) == REFERENCE_TYPE
)
2349 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2351 dump_unary_op (pp
, "*", t
, flags
);
2356 if (TREE_CODE (TREE_OPERAND (t
, 0)) == ADDR_EXPR
2357 && integer_zerop (TREE_OPERAND (t
, 1)))
2358 dump_expr (pp
, TREE_OPERAND (TREE_OPERAND (t
, 0), 0), flags
);
2362 if (!integer_zerop (TREE_OPERAND (t
, 1)))
2364 pp_cxx_left_paren (pp
);
2365 if (!integer_onep (TYPE_SIZE_UNIT
2366 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (t
, 0))))))
2368 pp_cxx_left_paren (pp
);
2369 dump_type (pp
, ptr_type_node
, flags
);
2370 pp_cxx_right_paren (pp
);
2373 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2374 if (!integer_zerop (TREE_OPERAND (t
, 1)))
2376 pp_cxx_ws_string (pp
, "+");
2377 dump_expr (pp
, fold_convert (ssizetype
, TREE_OPERAND (t
, 1)),
2379 pp_cxx_right_paren (pp
);
2386 case TRUTH_NOT_EXPR
:
2387 case PREDECREMENT_EXPR
:
2388 case PREINCREMENT_EXPR
:
2389 dump_unary_op (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
, t
, flags
);
2392 case POSTDECREMENT_EXPR
:
2393 case POSTINCREMENT_EXPR
:
2394 pp_cxx_left_paren (pp
);
2395 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2396 pp_cxx_ws_string (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
);
2397 pp_cxx_right_paren (pp
);
2400 case NON_LVALUE_EXPR
:
2401 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
2402 should be another level of INDIRECT_REF so that I don't have to do
2404 if (TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == POINTER_TYPE
)
2406 tree next
= TREE_TYPE (TREE_TYPE (t
));
2408 while (TYPE_PTR_P (next
))
2409 next
= TREE_TYPE (next
);
2411 if (TREE_CODE (next
) == FUNCTION_TYPE
)
2413 if (flags
& TFF_EXPR_IN_PARENS
)
2414 pp_cxx_left_paren (pp
);
2416 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2417 if (flags
& TFF_EXPR_IN_PARENS
)
2418 pp_cxx_right_paren (pp
);
2421 /* Else fall through. */
2423 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2427 case IMPLICIT_CONV_EXPR
:
2428 case VIEW_CONVERT_EXPR
:
2430 tree op
= TREE_OPERAND (t
, 0);
2431 tree ttype
= TREE_TYPE (t
);
2432 tree optype
= TREE_TYPE (op
);
2434 if (TREE_CODE (ttype
) != TREE_CODE (optype
)
2435 && INDIRECT_TYPE_P (ttype
)
2436 && INDIRECT_TYPE_P (optype
)
2437 && same_type_p (TREE_TYPE (optype
),
2440 if (TYPE_REF_P (ttype
))
2443 if (TREE_CODE (op
) == ADDR_EXPR
)
2444 dump_expr (pp
, TREE_OPERAND (op
, 0), flags
);
2446 dump_unary_op (pp
, "*", t
, flags
);
2449 dump_unary_op (pp
, "&", t
, flags
);
2451 else if (!same_type_p (TREE_TYPE (op
), TREE_TYPE (t
)))
2453 /* It is a cast, but we cannot tell whether it is a
2454 reinterpret or static cast. Use the C style notation. */
2455 if (flags
& TFF_EXPR_IN_PARENS
)
2456 pp_cxx_left_paren (pp
);
2457 pp_cxx_left_paren (pp
);
2458 dump_type (pp
, TREE_TYPE (t
), flags
);
2459 pp_cxx_right_paren (pp
);
2460 dump_expr (pp
, op
, flags
| TFF_EXPR_IN_PARENS
);
2461 if (flags
& TFF_EXPR_IN_PARENS
)
2462 pp_cxx_right_paren (pp
);
2465 dump_expr (pp
, op
, flags
);
2470 if (TREE_TYPE (t
) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t
)))
2472 tree idx
= build_ptrmemfunc_access_expr (t
, pfn_identifier
);
2474 if (integer_zerop (idx
))
2476 /* A NULL pointer-to-member constant. */
2477 pp_cxx_left_paren (pp
);
2478 pp_cxx_left_paren (pp
);
2479 dump_type (pp
, TREE_TYPE (t
), flags
);
2480 pp_cxx_right_paren (pp
);
2481 pp_character (pp
, '0');
2482 pp_cxx_right_paren (pp
);
2485 else if (tree_fits_shwi_p (idx
))
2488 unsigned HOST_WIDE_INT n
;
2490 t
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t
)));
2491 t
= TYPE_METHOD_BASETYPE (t
);
2492 virtuals
= BINFO_VIRTUALS (TYPE_BINFO (TYPE_MAIN_VARIANT (t
)));
2494 n
= tree_to_shwi (idx
);
2496 /* Map vtable index back one, to allow for the null pointer to
2500 while (n
> 0 && virtuals
)
2503 virtuals
= TREE_CHAIN (virtuals
);
2507 dump_expr (pp
, BV_FN (virtuals
),
2508 flags
| TFF_EXPR_IN_PARENS
);
2513 if (TREE_TYPE (t
) && LAMBDA_TYPE_P (TREE_TYPE (t
)))
2514 pp_string (pp
, "<lambda closure object>");
2515 if (TREE_TYPE (t
) && EMPTY_CONSTRUCTOR_P (t
))
2517 dump_type (pp
, TREE_TYPE (t
), 0);
2518 pp_cxx_left_paren (pp
);
2519 pp_cxx_right_paren (pp
);
2523 if (!BRACE_ENCLOSED_INITIALIZER_P (t
))
2524 dump_type (pp
, TREE_TYPE (t
), 0);
2525 pp_cxx_left_brace (pp
);
2526 dump_expr_init_vec (pp
, CONSTRUCTOR_ELTS (t
), flags
);
2527 pp_cxx_right_brace (pp
);
2534 tree ob
= TREE_OPERAND (t
, 0);
2535 if (is_dummy_object (ob
))
2537 t
= TREE_OPERAND (t
, 1);
2538 if (TREE_CODE (t
) == FUNCTION_DECL
)
2540 dump_expr (pp
, t
, flags
| TFF_EXPR_IN_PARENS
);
2541 else if (BASELINK_P (t
))
2542 dump_expr (pp
, OVL_FIRST (BASELINK_FUNCTIONS (t
)),
2543 flags
| TFF_EXPR_IN_PARENS
);
2545 dump_decl (pp
, t
, flags
);
2549 if (INDIRECT_REF_P (ob
))
2551 dump_expr (pp
, TREE_OPERAND (ob
, 0), flags
| TFF_EXPR_IN_PARENS
);
2557 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2561 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2566 case TEMPLATE_PARM_INDEX
:
2567 dump_decl (pp
, TEMPLATE_PARM_DECL (t
), flags
& ~TFF_DECL_SPECIFIERS
);
2571 if (TREE_OPERAND (t
, 0) == NULL_TREE
2572 || TREE_CHAIN (TREE_OPERAND (t
, 0)))
2574 dump_type (pp
, TREE_TYPE (t
), flags
);
2575 pp_cxx_left_paren (pp
);
2576 dump_expr_list (pp
, TREE_OPERAND (t
, 0), flags
);
2577 pp_cxx_right_paren (pp
);
2581 pp_cxx_left_paren (pp
);
2582 dump_type (pp
, TREE_TYPE (t
), flags
);
2583 pp_cxx_right_paren (pp
);
2584 pp_cxx_left_paren (pp
);
2585 dump_expr_list (pp
, TREE_OPERAND (t
, 0), flags
);
2586 pp_cxx_right_paren (pp
);
2590 case STATIC_CAST_EXPR
:
2591 pp_cxx_ws_string (pp
, "static_cast");
2593 case REINTERPRET_CAST_EXPR
:
2594 pp_cxx_ws_string (pp
, "reinterpret_cast");
2596 case CONST_CAST_EXPR
:
2597 pp_cxx_ws_string (pp
, "const_cast");
2599 case DYNAMIC_CAST_EXPR
:
2600 pp_cxx_ws_string (pp
, "dynamic_cast");
2602 pp_cxx_begin_template_argument_list (pp
);
2603 dump_type (pp
, TREE_TYPE (t
), flags
);
2604 pp_cxx_end_template_argument_list (pp
);
2605 pp_cxx_left_paren (pp
);
2606 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2607 pp_cxx_right_paren (pp
);
2611 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2617 if (TREE_CODE (t
) == SIZEOF_EXPR
)
2618 pp_cxx_ws_string (pp
, "sizeof");
2621 gcc_assert (TREE_CODE (t
) == ALIGNOF_EXPR
);
2622 pp_cxx_ws_string (pp
, "__alignof__");
2624 op
= TREE_OPERAND (t
, 0);
2625 if (PACK_EXPANSION_P (op
))
2627 pp_string (pp
, "...");
2628 op
= PACK_EXPANSION_PATTERN (op
);
2630 pp_cxx_whitespace (pp
);
2631 pp_cxx_left_paren (pp
);
2632 if (TREE_CODE (t
) == SIZEOF_EXPR
&& SIZEOF_EXPR_TYPE_P (t
))
2633 dump_type (pp
, TREE_TYPE (op
), flags
);
2634 else if (TYPE_P (TREE_OPERAND (t
, 0)))
2635 dump_type (pp
, op
, flags
);
2637 dump_expr (pp
, op
, flags
);
2638 pp_cxx_right_paren (pp
);
2641 case AT_ENCODE_EXPR
:
2642 pp_cxx_ws_string (pp
, "@encode");
2643 pp_cxx_whitespace (pp
);
2644 pp_cxx_left_paren (pp
);
2645 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
2646 pp_cxx_right_paren (pp
);
2650 pp_cxx_ws_string (pp
, "noexcept");
2651 pp_cxx_whitespace (pp
);
2652 pp_cxx_left_paren (pp
);
2653 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2654 pp_cxx_right_paren (pp
);
2659 pp_cxx_ws_string (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
);
2660 pp_cxx_whitespace (pp
);
2661 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2664 case DEFERRED_PARSE
:
2665 pp_string (pp
, M_("<unparsed>"));
2668 case TRY_CATCH_EXPR
:
2669 case CLEANUP_POINT_EXPR
:
2670 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2673 case PSEUDO_DTOR_EXPR
:
2674 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2676 if (TREE_OPERAND (t
, 1))
2678 dump_type (pp
, TREE_OPERAND (t
, 1), flags
);
2679 pp_cxx_colon_colon (pp
);
2681 pp_cxx_complement (pp
);
2682 dump_type (pp
, TREE_OPERAND (t
, 2), flags
);
2685 case TEMPLATE_ID_EXPR
:
2686 dump_decl (pp
, t
, flags
);
2692 case STATEMENT_LIST
:
2693 /* We don't yet have a way of dumping statements in a
2694 human-readable format. */
2695 pp_string (pp
, "({...})");
2699 pp_string (pp
, "while (1) { ");
2700 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2701 pp_cxx_right_brace (pp
);
2705 pp_string (pp
, "if (");
2706 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2707 pp_string (pp
, ") break; ");
2711 dump_expr (pp
, BASELINK_FUNCTIONS (t
), flags
& ~TFF_EXPR_IN_PARENS
);
2714 case EMPTY_CLASS_EXPR
:
2715 dump_type (pp
, TREE_TYPE (t
), flags
);
2716 pp_cxx_left_paren (pp
);
2717 pp_cxx_right_paren (pp
);
2720 case NON_DEPENDENT_EXPR
:
2721 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2724 case ARGUMENT_PACK_SELECT
:
2725 dump_template_argument (pp
, ARGUMENT_PACK_SELECT_FROM_PACK (t
), flags
);
2738 pp_type_specifier_seq (pp
, t
);
2742 /* We get here when we want to print a dependent type as an
2743 id-expression, without any disambiguator decoration. */
2744 pp
->id_expression (t
);
2747 case TEMPLATE_TYPE_PARM
:
2748 case TEMPLATE_TEMPLATE_PARM
:
2749 case BOUND_TEMPLATE_TEMPLATE_PARM
:
2750 dump_type (pp
, t
, flags
);
2754 pp_cxx_trait_expression (pp
, t
);
2758 pp_cxx_va_arg_expression (pp
, t
);
2762 pp_cxx_offsetof_expression (pp
, t
);
2765 case ADDRESSOF_EXPR
:
2766 pp_cxx_addressof_expression (pp
, t
);
2770 dump_decl (pp
, t
, flags
);
2773 case EXPR_PACK_EXPANSION
:
2774 case UNARY_LEFT_FOLD_EXPR
:
2775 case UNARY_RIGHT_FOLD_EXPR
:
2776 case BINARY_LEFT_FOLD_EXPR
:
2777 case BINARY_RIGHT_FOLD_EXPR
:
2784 case VEC_DELETE_EXPR
:
2791 case UNORDERED_EXPR
:
2801 case FIX_TRUNC_EXPR
:
2806 case TRUTH_AND_EXPR
:
2808 case TRUTH_XOR_EXPR
:
2809 if (flags
& TFF_EXPR_IN_PARENS
)
2810 pp_cxx_left_paren (pp
);
2812 if (flags
& TFF_EXPR_IN_PARENS
)
2813 pp_cxx_right_paren (pp
);
2817 dump_expr (pp
, resolve_virtual_fun_from_obj_type_ref (t
), flags
);
2821 pp_string (pp
, M_("<lambda>"));
2825 pp_cxx_left_paren (pp
);
2826 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2827 pp_cxx_right_paren (pp
);
2831 pp_cxx_requires_expr (cxx_pp
, t
);
2835 pp_cxx_simple_requirement (cxx_pp
, t
);
2839 pp_cxx_type_requirement (cxx_pp
, t
);
2843 pp_cxx_compound_requirement (cxx_pp
, t
);
2847 pp_cxx_nested_requirement (cxx_pp
, t
);
2860 pp_cxx_constraint (cxx_pp
, t
);
2863 case PLACEHOLDER_EXPR
:
2864 pp_string (pp
, M_("*this"));
2868 dump_expr_list (pp
, t
, flags
);
2871 /* This list is incomplete, but should suffice for now.
2872 It is very important that `sorry' does not call
2873 `report_error_function'. That could cause an infinite loop. */
2875 pp_unsupported_tree (pp
, t
);
2878 pp_string (pp
, M_("<expression error>"));
2884 dump_binary_op (cxx_pretty_printer
*pp
, const char *opstring
, tree t
,
2887 pp_cxx_left_paren (pp
);
2888 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2889 pp_cxx_whitespace (pp
);
2891 pp_cxx_ws_string (pp
, opstring
);
2893 pp_string (pp
, M_("<unknown operator>"));
2894 pp_cxx_whitespace (pp
);
2895 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2896 pp_cxx_right_paren (pp
);
2900 dump_unary_op (cxx_pretty_printer
*pp
, const char *opstring
, tree t
, int flags
)
2902 if (flags
& TFF_EXPR_IN_PARENS
)
2903 pp_cxx_left_paren (pp
);
2904 pp_cxx_ws_string (pp
, opstring
);
2905 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2906 if (flags
& TFF_EXPR_IN_PARENS
)
2907 pp_cxx_right_paren (pp
);
2911 reinit_cxx_pp (void)
2913 pp_clear_output_area (cxx_pp
);
2914 cxx_pp
->padding
= pp_none
;
2915 pp_indentation (cxx_pp
) = 0;
2916 pp_needs_newline (cxx_pp
) = false;
2917 cxx_pp
->enclosing_scope
= current_function_decl
;
2920 /* Same as pp_formatted_text, except the return string is a separate
2921 copy and has a GGC storage duration, e.g. an indefinite lifetime. */
2924 pp_ggc_formatted_text (pretty_printer
*pp
)
2926 return ggc_strdup (pp_formatted_text (pp
));
2929 /* Exported interface to stringifying types, exprs and decls under TFF_*
2933 type_as_string (tree typ
, int flags
)
2936 pp_translate_identifiers (cxx_pp
) = false;
2937 dump_type (cxx_pp
, typ
, flags
);
2938 return pp_ggc_formatted_text (cxx_pp
);
2942 type_as_string_translate (tree typ
, int flags
)
2945 dump_type (cxx_pp
, typ
, flags
);
2946 return pp_ggc_formatted_text (cxx_pp
);
2950 expr_as_string (tree decl
, int flags
)
2953 pp_translate_identifiers (cxx_pp
) = false;
2954 dump_expr (cxx_pp
, decl
, flags
);
2955 return pp_ggc_formatted_text (cxx_pp
);
2958 /* Wrap decl_as_string with options appropriate for dwarf. */
2961 decl_as_dwarf_string (tree decl
, int flags
)
2964 /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag
2965 here will be adequate to get the desired behavior. */
2966 cxx_pp
->flags
|= pp_c_flag_gnu_v3
;
2967 name
= decl_as_string (decl
, flags
);
2968 /* Subsequent calls to the pretty printer shouldn't use this style. */
2969 cxx_pp
->flags
&= ~pp_c_flag_gnu_v3
;
2974 decl_as_string (tree decl
, int flags
)
2977 pp_translate_identifiers (cxx_pp
) = false;
2978 dump_decl (cxx_pp
, decl
, flags
);
2979 return pp_ggc_formatted_text (cxx_pp
);
2983 decl_as_string_translate (tree decl
, int flags
)
2986 dump_decl (cxx_pp
, decl
, flags
);
2987 return pp_ggc_formatted_text (cxx_pp
);
2990 /* Wrap lang_decl_name with options appropriate for dwarf. */
2993 lang_decl_dwarf_name (tree decl
, int v
, bool translate
)
2996 /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag
2997 here will be adequate to get the desired behavior. */
2998 cxx_pp
->flags
|= pp_c_flag_gnu_v3
;
2999 name
= lang_decl_name (decl
, v
, translate
);
3000 /* Subsequent calls to the pretty printer shouldn't use this style. */
3001 cxx_pp
->flags
&= ~pp_c_flag_gnu_v3
;
3005 /* Generate the three forms of printable names for cxx_printable_name. */
3008 lang_decl_name (tree decl
, int v
, bool translate
)
3012 ? decl_as_string_translate (decl
, TFF_DECL_SPECIFIERS
)
3013 : decl_as_string (decl
, TFF_DECL_SPECIFIERS
));
3016 pp_translate_identifiers (cxx_pp
) = translate
;
3018 && (DECL_CLASS_SCOPE_P (decl
)
3019 || (DECL_NAMESPACE_SCOPE_P (decl
)
3020 && CP_DECL_CONTEXT (decl
) != global_namespace
)))
3022 dump_type (cxx_pp
, CP_DECL_CONTEXT (decl
), TFF_PLAIN_IDENTIFIER
);
3023 pp_cxx_colon_colon (cxx_pp
);
3026 if (TREE_CODE (decl
) == FUNCTION_DECL
)
3027 dump_function_name (cxx_pp
, decl
, TFF_PLAIN_IDENTIFIER
);
3028 else if ((DECL_NAME (decl
) == NULL_TREE
)
3029 && TREE_CODE (decl
) == NAMESPACE_DECL
)
3030 dump_decl (cxx_pp
, decl
, TFF_PLAIN_IDENTIFIER
| TFF_UNQUALIFIED_NAME
);
3032 dump_decl (cxx_pp
, DECL_NAME (decl
), TFF_PLAIN_IDENTIFIER
);
3034 return pp_ggc_formatted_text (cxx_pp
);
3037 /* Return the location of a tree passed to %+ formats. */
3040 location_of (tree t
)
3044 t
= TYPE_MAIN_DECL (t
);
3046 return input_location
;
3048 else if (TREE_CODE (t
) == OVERLOAD
)
3052 return DECL_SOURCE_LOCATION (t
);
3053 if (TREE_CODE (t
) == DEFERRED_PARSE
)
3054 return defparse_location (t
);
3055 return cp_expr_loc_or_loc (t
, input_location
);
3058 /* Now the interfaces from error et al to dump_type et al. Each takes an
3059 on/off VERBOSE flag and supply the appropriate TFF_ flags to a dump_
3063 decl_to_string (tree decl
, int verbose
)
3067 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == RECORD_TYPE
3068 || TREE_CODE (decl
) == UNION_TYPE
|| TREE_CODE (decl
) == ENUMERAL_TYPE
)
3069 flags
= TFF_CLASS_KEY_OR_ENUM
;
3071 flags
|= TFF_DECL_SPECIFIERS
;
3072 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
3073 flags
|= TFF_DECL_SPECIFIERS
| TFF_RETURN_TYPE
;
3074 flags
|= TFF_TEMPLATE_HEADER
;
3077 dump_decl (cxx_pp
, decl
, flags
);
3078 return pp_ggc_formatted_text (cxx_pp
);
3082 expr_to_string (tree decl
)
3085 dump_expr (cxx_pp
, decl
, 0);
3086 return pp_ggc_formatted_text (cxx_pp
);
3090 fndecl_to_string (tree fndecl
, int verbose
)
3094 flags
= TFF_EXCEPTION_SPECIFICATION
| TFF_DECL_SPECIFIERS
3095 | TFF_TEMPLATE_HEADER
;
3097 flags
|= TFF_FUNCTION_DEFAULT_ARGUMENTS
;
3099 dump_decl (cxx_pp
, fndecl
, flags
);
3100 return pp_ggc_formatted_text (cxx_pp
);
3105 code_to_string (enum tree_code c
)
3107 return get_tree_code_name (c
);
3111 language_to_string (enum languages c
)
3118 case lang_cplusplus
:
3127 /* Return the proper printed version of a parameter to a C++ function. */
3130 parm_to_string (int p
)
3134 pp_string (cxx_pp
, "'this'");
3136 pp_decimal_int (cxx_pp
, p
+ 1);
3137 return pp_ggc_formatted_text (cxx_pp
);
3141 op_to_string (bool assop
, enum tree_code p
)
3143 tree id
= ovl_op_identifier (assop
, p
);
3144 return id
? IDENTIFIER_POINTER (id
) : M_("<unknown>");
3147 /* Return a GC-allocated representation of type TYP, with verbosity VERBOSE.
3149 If QUOTE is non-NULL and if *QUOTE is true, then quotes are added to the
3150 string in appropriate places, and *QUOTE is written to with false
3151 to suppress pp_format's trailing close quote so that e.g.
3152 foo_typedef {aka underlying_foo} {enum}
3153 can be printed by "%qT" as:
3154 `foo_typedef' {aka `underlying_foo'} {enum}
3156 `foo_typedef {aka underlying_foo} {enum}'
3157 When adding such quotes, if POSTPROCESSED is true (for handling %H and %I)
3158 then a leading open quote will be added, whereas if POSTPROCESSED is false
3159 (for handling %T) then any leading quote has already been added by
3160 pp_format, or is not needed due to QUOTE being NULL (for template arguments
3163 SHOW_COLOR is used to determine the colorization of any quotes that
3167 type_to_string (tree typ
, int verbose
, bool postprocessed
, bool *quote
,
3172 flags
|= TFF_CLASS_KEY_OR_ENUM
;
3173 flags
|= TFF_TEMPLATE_HEADER
;
3177 if (postprocessed
&& quote
&& *quote
)
3178 pp_begin_quote (cxx_pp
, show_color
);
3180 struct obstack
*ob
= pp_buffer (cxx_pp
)->obstack
;
3181 int type_start
, type_len
;
3182 type_start
= obstack_object_size (ob
);
3184 dump_type (cxx_pp
, typ
, flags
);
3186 /* Remember the end of the initial dump. */
3187 type_len
= obstack_object_size (ob
) - type_start
;
3189 /* If we're printing a type that involves typedefs, also print the
3190 stripped version. But sometimes the stripped version looks
3191 exactly the same, so we don't want it after all. To avoid printing
3192 it in that case, we play ugly obstack games. */
3193 if (typ
&& TYPE_P (typ
) && typ
!= TYPE_CANONICAL (typ
)
3194 && !uses_template_parms (typ
))
3196 int aka_start
, aka_len
; char *p
;
3197 tree aka
= strip_typedefs (typ
);
3198 if (quote
&& *quote
)
3199 pp_end_quote (cxx_pp
, show_color
);
3200 pp_string (cxx_pp
, " {aka");
3201 pp_cxx_whitespace (cxx_pp
);
3202 if (quote
&& *quote
)
3203 pp_begin_quote (cxx_pp
, show_color
);
3204 /* And remember the start of the aka dump. */
3205 aka_start
= obstack_object_size (ob
);
3206 dump_type (cxx_pp
, aka
, flags
);
3207 aka_len
= obstack_object_size (ob
) - aka_start
;
3208 if (quote
&& *quote
)
3209 pp_end_quote (cxx_pp
, show_color
);
3210 pp_right_brace (cxx_pp
);
3211 p
= (char*)obstack_base (ob
);
3212 /* If they are identical, cut off the aka by unwinding the obstack. */
3213 if (type_len
== aka_len
3214 && memcmp (p
+ type_start
, p
+aka_start
, type_len
) == 0)
3216 /* We can't add a '\0' here, since we may be adding a closing quote
3217 below, and it would be hidden by the '\0'.
3218 Instead, manually unwind the current object within the obstack
3219 so that the insertion point is at the end of the type, before
3221 int delta
= type_start
+ type_len
- obstack_object_size (ob
);
3222 gcc_assert (delta
<= 0);
3223 obstack_blank_fast (ob
, delta
);
3227 /* No further closing quotes are needed. */
3231 if (quote
&& *quote
)
3233 pp_end_quote (cxx_pp
, show_color
);
3236 return pp_ggc_formatted_text (cxx_pp
);
3240 args_to_string (tree p
, int verbose
)
3244 flags
|= TFF_CLASS_KEY_OR_ENUM
;
3249 if (TYPE_P (TREE_VALUE (p
)))
3250 return type_as_string_translate (p
, flags
);
3253 for (; p
; p
= TREE_CHAIN (p
))
3255 if (null_node_p (TREE_VALUE (p
)))
3256 pp_cxx_ws_string (cxx_pp
, "NULL");
3258 dump_type (cxx_pp
, error_type (TREE_VALUE (p
)), flags
);
3260 pp_separate_with_comma (cxx_pp
);
3262 return pp_ggc_formatted_text (cxx_pp
);
3265 /* Pretty-print a deduction substitution (from deduction_tsubst_fntype). P
3266 is a TREE_LIST with purpose the TEMPLATE_DECL, value the template
3270 subst_to_string (tree p
)
3272 tree decl
= TREE_PURPOSE (p
);
3273 tree targs
= TREE_VALUE (p
);
3274 tree tparms
= DECL_TEMPLATE_PARMS (decl
);
3275 int flags
= (TFF_DECL_SPECIFIERS
|TFF_TEMPLATE_HEADER
3276 |TFF_NO_TEMPLATE_BINDINGS
);
3282 dump_template_decl (cxx_pp
, TREE_PURPOSE (p
), flags
);
3283 dump_substitution (cxx_pp
, NULL
, tparms
, targs
, /*flags=*/0);
3284 return pp_ggc_formatted_text (cxx_pp
);
3288 cv_to_string (tree p
, int v
)
3291 cxx_pp
->padding
= v
? pp_before
: pp_none
;
3292 pp_cxx_cv_qualifier_seq (cxx_pp
, p
);
3293 return pp_ggc_formatted_text (cxx_pp
);
3297 eh_spec_to_string (tree p
, int /*v*/)
3301 dump_exception_spec (cxx_pp
, p
, flags
);
3302 return pp_ggc_formatted_text (cxx_pp
);
3305 /* Langhook for print_error_function. */
3307 cxx_print_error_function (diagnostic_context
*context
, const char *file
,
3308 diagnostic_info
*diagnostic
)
3312 prefix
= xstrdup (file
);
3315 lhd_print_error_function (context
, file
, diagnostic
);
3316 pp_set_prefix (context
->printer
, prefix
);
3317 maybe_print_instantiation_context (context
);
3321 cp_diagnostic_starter (diagnostic_context
*context
,
3322 diagnostic_info
*diagnostic
)
3324 diagnostic_report_current_module (context
, diagnostic_location (diagnostic
));
3325 cp_print_error_function (context
, diagnostic
);
3326 maybe_print_instantiation_context (context
);
3327 maybe_print_constexpr_context (context
);
3328 pp_set_prefix (context
->printer
, diagnostic_build_prefix (context
,
3332 /* Print current function onto BUFFER, in the process of reporting
3333 a diagnostic message. Called from cp_diagnostic_starter. */
3335 cp_print_error_function (diagnostic_context
*context
,
3336 diagnostic_info
*diagnostic
)
3338 /* If we are in an instantiation context, current_function_decl is likely
3339 to be wrong, so just rely on print_instantiation_full_context. */
3340 if (current_instantiation ())
3342 if (diagnostic_last_function_changed (context
, diagnostic
))
3344 char *old_prefix
= pp_take_prefix (context
->printer
);
3345 const char *file
= LOCATION_FILE (diagnostic_location (diagnostic
));
3346 tree abstract_origin
= diagnostic_abstract_origin (diagnostic
);
3347 char *new_prefix
= (file
&& abstract_origin
== NULL
)
3348 ? file_name_as_prefix (context
, file
) : NULL
;
3350 pp_set_prefix (context
->printer
, new_prefix
);
3352 if (current_function_decl
== NULL
)
3353 pp_string (context
->printer
, _("At global scope:"));
3358 if (abstract_origin
)
3360 ao
= BLOCK_ABSTRACT_ORIGIN (abstract_origin
);
3361 gcc_assert (TREE_CODE (ao
) == FUNCTION_DECL
);
3365 fndecl
= current_function_decl
;
3367 pp_printf (context
->printer
, function_category (fndecl
),
3368 cxx_printable_name_translate (fndecl
, 2));
3370 while (abstract_origin
)
3373 tree block
= abstract_origin
;
3375 locus
= &BLOCK_SOURCE_LOCATION (block
);
3377 block
= BLOCK_SUPERCONTEXT (block
);
3378 while (block
&& TREE_CODE (block
) == BLOCK
3379 && BLOCK_ABSTRACT_ORIGIN (block
))
3381 ao
= BLOCK_ABSTRACT_ORIGIN (block
);
3382 if (TREE_CODE (ao
) == FUNCTION_DECL
)
3387 else if (TREE_CODE (ao
) != BLOCK
)
3390 block
= BLOCK_SUPERCONTEXT (block
);
3393 abstract_origin
= block
;
3396 while (block
&& TREE_CODE (block
) == BLOCK
)
3397 block
= BLOCK_SUPERCONTEXT (block
);
3399 if (block
&& TREE_CODE (block
) == FUNCTION_DECL
)
3401 abstract_origin
= NULL
;
3405 expanded_location s
= expand_location (*locus
);
3406 pp_character (context
->printer
, ',');
3407 pp_newline (context
->printer
);
3410 if (context
->show_column
&& s
.column
!= 0)
3411 pp_printf (context
->printer
,
3412 _(" inlined from %qs at %r%s:%d:%d%R"),
3413 cxx_printable_name_translate (fndecl
, 2),
3414 "locus", s
.file
, s
.line
, s
.column
);
3416 pp_printf (context
->printer
,
3417 _(" inlined from %qs at %r%s:%d%R"),
3418 cxx_printable_name_translate (fndecl
, 2),
3419 "locus", s
.file
, s
.line
);
3423 pp_printf (context
->printer
, _(" inlined from %qs"),
3424 cxx_printable_name_translate (fndecl
, 2));
3427 pp_character (context
->printer
, ':');
3429 pp_newline (context
->printer
);
3431 diagnostic_set_last_function (context
, diagnostic
);
3432 pp_destroy_prefix (context
->printer
);
3433 context
->printer
->prefix
= old_prefix
;
3437 /* Returns a description of FUNCTION using standard terminology. The
3438 result is a format string of the form "In CATEGORY %qs". */
3440 function_category (tree fn
)
3442 /* We can get called from the middle-end for diagnostics of function
3443 clones. Make sure we have language specific information before
3444 dereferencing it. */
3445 if (DECL_LANG_SPECIFIC (STRIP_TEMPLATE (fn
))
3446 && DECL_FUNCTION_MEMBER_P (fn
))
3448 if (DECL_STATIC_FUNCTION_P (fn
))
3449 return _("In static member function %qs");
3450 else if (DECL_COPY_CONSTRUCTOR_P (fn
))
3451 return _("In copy constructor %qs");
3452 else if (DECL_CONSTRUCTOR_P (fn
))
3453 return _("In constructor %qs");
3454 else if (DECL_DESTRUCTOR_P (fn
))
3455 return _("In destructor %qs");
3456 else if (LAMBDA_FUNCTION_P (fn
))
3457 return _("In lambda function");
3459 return _("In member function %qs");
3462 return _("In function %qs");
3465 /* Report the full context of a current template instantiation,
3468 print_instantiation_full_context (diagnostic_context
*context
)
3470 struct tinst_level
*p
= current_instantiation ();
3471 location_t location
= input_location
;
3475 pp_verbatim (context
->printer
,
3477 ? _("%s: In substitution of %qS:\n")
3478 : _("%s: In instantiation of %q#D:\n"),
3479 LOCATION_FILE (location
),
3482 location
= p
->locus
;
3486 print_instantiation_partial_context (context
, p
, location
);
3489 /* Helper function of print_instantiation_partial_context() that
3490 prints a single line of instantiation context. */
3493 print_instantiation_partial_context_line (diagnostic_context
*context
,
3494 struct tinst_level
*t
,
3495 location_t loc
, bool recursive_p
)
3497 if (loc
== UNKNOWN_LOCATION
)
3500 expanded_location xloc
= expand_location (loc
);
3502 if (context
->show_column
)
3503 pp_verbatim (context
->printer
, _("%r%s:%d:%d:%R "),
3504 "locus", xloc
.file
, xloc
.line
, xloc
.column
);
3506 pp_verbatim (context
->printer
, _("%r%s:%d:%R "),
3507 "locus", xloc
.file
, xloc
.line
);
3512 pp_verbatim (context
->printer
,
3514 ? _("recursively required by substitution of %qS\n")
3515 : _("required by substitution of %qS\n"),
3518 pp_verbatim (context
->printer
,
3520 ? _("recursively required from %q#D\n")
3521 : _("required from %q#D\n"),
3526 pp_verbatim (context
->printer
,
3528 ? _("recursively required from here\n")
3529 : _("required from here\n"));
3533 /* Same as print_instantiation_full_context but less verbose. */
3536 print_instantiation_partial_context (diagnostic_context
*context
,
3537 struct tinst_level
*t0
, location_t loc
)
3539 struct tinst_level
*t
;
3542 location_t prev_loc
= loc
;
3544 for (t
= t0
; t
!= NULL
; t
= t
->next
)
3545 if (prev_loc
!= t
->locus
)
3547 prev_loc
= t
->locus
;
3553 if (template_backtrace_limit
3554 && n_total
> template_backtrace_limit
)
3556 int skip
= n_total
- template_backtrace_limit
;
3557 int head
= template_backtrace_limit
/ 2;
3559 /* Avoid skipping just 1. If so, skip 2. */
3563 head
= (template_backtrace_limit
- 1) / 2;
3566 for (n
= 0; n
< head
; n
++)
3568 gcc_assert (t
!= NULL
);
3569 if (loc
!= t
->locus
)
3570 print_instantiation_partial_context_line (context
, t
, loc
,
3571 /*recursive_p=*/false);
3575 if (t
!= NULL
&& skip
> 0)
3577 expanded_location xloc
;
3578 xloc
= expand_location (loc
);
3579 if (context
->show_column
)
3580 pp_verbatim (context
->printer
,
3581 _("%r%s:%d:%d:%R [ skipping %d instantiation "
3582 "contexts, use -ftemplate-backtrace-limit=0 to "
3584 "locus", xloc
.file
, xloc
.line
, xloc
.column
, skip
);
3586 pp_verbatim (context
->printer
,
3587 _("%r%s:%d:%R [ skipping %d instantiation "
3588 "contexts, use -ftemplate-backtrace-limit=0 to "
3590 "locus", xloc
.file
, xloc
.line
, skip
);
3595 } while (t
!= NULL
&& --skip
> 0);
3601 while (t
->next
!= NULL
&& t
->locus
== t
->next
->locus
)
3606 print_instantiation_partial_context_line (context
, t
, loc
,
3611 print_instantiation_partial_context_line (context
, NULL
, loc
,
3612 /*recursive_p=*/false);
3615 /* Called from cp_thing to print the template context for an error. */
3617 maybe_print_instantiation_context (diagnostic_context
*context
)
3619 if (!problematic_instantiation_changed () || current_instantiation () == 0)
3622 record_last_problematic_instantiation ();
3623 print_instantiation_full_context (context
);
3626 /* Report what constexpr call(s) we're trying to expand, if any. */
3629 maybe_print_constexpr_context (diagnostic_context
*context
)
3631 vec
<tree
> call_stack
= cx_error_context ();
3635 FOR_EACH_VEC_ELT (call_stack
, ix
, t
)
3637 expanded_location xloc
= expand_location (EXPR_LOCATION (t
));
3638 const char *s
= expr_as_string (t
, 0);
3639 if (context
->show_column
)
3640 pp_verbatim (context
->printer
,
3641 _("%r%s:%d:%d:%R in %<constexpr%> expansion of %qs"),
3642 "locus", xloc
.file
, xloc
.line
, xloc
.column
, s
);
3644 pp_verbatim (context
->printer
,
3645 _("%r%s:%d:%R in %<constexpr%> expansion of %qs"),
3646 "locus", xloc
.file
, xloc
.line
, s
);
3647 pp_newline (context
->printer
);
3652 /* Return true iff TYPE_A and TYPE_B are template types that are
3653 meaningful to compare. */
3656 comparable_template_types_p (tree type_a
, tree type_b
)
3658 if (!CLASS_TYPE_P (type_a
))
3660 if (!CLASS_TYPE_P (type_b
))
3663 tree tinfo_a
= TYPE_TEMPLATE_INFO (type_a
);
3664 tree tinfo_b
= TYPE_TEMPLATE_INFO (type_b
);
3665 if (!tinfo_a
|| !tinfo_b
)
3668 return TI_TEMPLATE (tinfo_a
) == TI_TEMPLATE (tinfo_b
);
3671 /* Start a new line indented by SPC spaces on PP. */
3674 newline_and_indent (pretty_printer
*pp
, int spc
)
3677 for (int i
= 0; i
< spc
; i
++)
3681 /* Generate a GC-allocated string for ARG, an expression or type. */
3684 arg_to_string (tree arg
, bool verbose
)
3687 return type_to_string (arg
, verbose
, true, NULL
, false);
3689 return expr_to_string (arg
);
3692 /* Subroutine to type_to_string_with_compare and
3693 print_template_tree_comparison.
3695 Print a representation of ARG (an expression or type) to PP,
3696 colorizing it as "type-diff" if PP->show_color. */
3699 print_nonequal_arg (pretty_printer
*pp
, tree arg
, bool verbose
)
3701 pp_printf (pp
, "%r%s%R",
3704 ? arg_to_string (arg
, verbose
)
3705 : G_("(no argument)")));
3708 /* Recursively print template TYPE_A to PP, as compared to template TYPE_B.
3710 The types must satisfy comparable_template_types_p.
3712 If INDENT is 0, then this is equivalent to type_to_string (TYPE_A), but
3713 potentially colorizing/eliding in comparison with TYPE_B.
3715 For example given types:
3716 vector<map<int,double>>
3718 vector<map<int,float>>
3719 then the result on PP would be:
3720 vector<map<[...],double>>
3721 with type elision, and:
3722 vector<map<int,double>>
3723 without type elision.
3725 In both cases the parts of TYPE that differ from PEER will be colorized
3726 if pp_show_color (pp) is true. In the above example, this would be
3729 If INDENT is non-zero, then the types are printed in a tree-like form
3730 which shows both types. In the above example, the result on PP would be:
3737 and without type-elision would be:
3744 As before, the differing parts of the types are colorized if
3745 pp_show_color (pp) is true ("double" and "float" in this example).
3747 Template arguments in which both types are using the default arguments
3748 are not printed; if at least one of the two types is using a non-default
3749 argument, then that argument is printed (or both arguments for the
3750 tree-like print format). */
3753 print_template_differences (pretty_printer
*pp
, tree type_a
, tree type_b
,
3754 bool verbose
, int indent
)
3757 newline_and_indent (pp
, indent
);
3759 tree tinfo_a
= TYPE_TEMPLATE_INFO (type_a
);
3760 tree tinfo_b
= TYPE_TEMPLATE_INFO (type_b
);
3762 pp_printf (pp
, "%s<",
3763 IDENTIFIER_POINTER (DECL_NAME (TI_TEMPLATE (tinfo_a
))));
3765 tree args_a
= TI_ARGS (tinfo_a
);
3766 tree args_b
= TI_ARGS (tinfo_b
);
3767 gcc_assert (TREE_CODE (args_a
) == TREE_VEC
);
3768 gcc_assert (TREE_CODE (args_b
) == TREE_VEC
);
3770 int len_a
= get_non_default_template_args_count (args_a
, flags
);
3771 args_a
= INNERMOST_TEMPLATE_ARGS (args_a
);
3772 int len_b
= get_non_default_template_args_count (args_b
, flags
);
3773 args_b
= INNERMOST_TEMPLATE_ARGS (args_b
);
3774 /* Determine the maximum range of args for which non-default template args
3775 were used; beyond this, only default args (if any) were used, and so
3776 they will be equal from this point onwards.
3777 One of the two peers might have used default arguments within this
3778 range, but the other will be using non-default arguments, and so
3779 it's more readable to print both within this range, to highlight
3781 int len_max
= MAX (len_a
, len_b
);
3782 gcc_assert (TREE_CODE (args_a
) == TREE_VEC
);
3783 gcc_assert (TREE_CODE (args_b
) == TREE_VEC
);
3784 for (int idx
= 0; idx
< len_max
; idx
++)
3787 pp_character (pp
, ',');
3789 tree arg_a
= TREE_VEC_ELT (args_a
, idx
);
3790 tree arg_b
= TREE_VEC_ELT (args_b
, idx
);
3794 newline_and_indent (pp
, indent
+ 2);
3795 /* Can do elision here, printing "[...]". */
3796 if (flag_elide_type
)
3797 pp_string (pp
, G_("[...]"));
3799 pp_string (pp
, arg_to_string (arg_a
, verbose
));
3803 int new_indent
= indent
? indent
+ 2 : 0;
3804 if (comparable_template_types_p (arg_a
, arg_b
))
3805 print_template_differences (pp
, arg_a
, arg_b
, verbose
, new_indent
);
3809 newline_and_indent (pp
, indent
+ 2);
3810 pp_character (pp
, '[');
3811 print_nonequal_arg (pp
, arg_a
, verbose
);
3812 pp_string (pp
, " != ");
3813 print_nonequal_arg (pp
, arg_b
, verbose
);
3814 pp_character (pp
, ']');
3817 print_nonequal_arg (pp
, arg_a
, verbose
);
3820 pp_printf (pp
, ">");
3823 /* As type_to_string, but for a template, potentially colorizing/eliding
3824 in comparison with PEER.
3825 For example, if TYPE is map<int,double> and PEER is map<int,int>,
3826 then the resulting string would be:
3828 with type elision, and:
3830 without type elision.
3832 In both cases the parts of TYPE that differ from PEER will be colorized
3833 if SHOW_COLOR is true. In the above example, this would be "double".
3835 Template arguments in which both types are using the default arguments
3836 are not printed; if at least one of the two types is using a non-default
3837 argument, then both arguments are printed.
3839 The resulting string is in a GC-allocated buffer. */
3842 type_to_string_with_compare (tree type
, tree peer
, bool verbose
,
3845 pretty_printer inner_pp
;
3846 pretty_printer
*pp
= &inner_pp
;
3847 pp_show_color (pp
) = show_color
;
3849 print_template_differences (pp
, type
, peer
, verbose
, 0);
3850 return pp_ggc_formatted_text (pp
);
3853 /* Recursively print a tree-like comparison of TYPE_A and TYPE_B to PP,
3854 indented by INDENT spaces.
3856 For example given types:
3858 vector<map<int,double>>
3862 vector<map<double,float>>
3864 the output with type elision would be:
3871 and without type-elision would be:
3878 TYPE_A and TYPE_B must both be comparable template types
3879 (as per comparable_template_types_p).
3881 Template arguments in which both types are using the default arguments
3882 are not printed; if at least one of the two types is using a non-default
3883 argument, then both arguments are printed. */
3886 print_template_tree_comparison (pretty_printer
*pp
, tree type_a
, tree type_b
,
3887 bool verbose
, int indent
)
3889 print_template_differences (pp
, type_a
, type_b
, verbose
, indent
);
3892 /* Subroutine for use in a format_postprocessor::handle
3893 implementation. Adds a chunk to the end of
3894 formatted output, so that it will be printed
3895 by pp_output_formatted_text. */
3898 append_formatted_chunk (pretty_printer
*pp
, const char *content
)
3900 output_buffer
*buffer
= pp_buffer (pp
);
3901 struct chunk_info
*chunk_array
= buffer
->cur_chunk_array
;
3902 const char **args
= chunk_array
->args
;
3904 unsigned int chunk_idx
;
3905 for (chunk_idx
= 0; args
[chunk_idx
]; chunk_idx
++)
3907 args
[chunk_idx
++] = content
;
3908 args
[chunk_idx
] = NULL
;
3911 /* Create a copy of CONTENT, with quotes added, and,
3912 potentially, with colorization.
3913 No escaped is performed on CONTENT.
3914 The result is in a GC-allocated buffer. */
3917 add_quotes (const char *content
, bool show_color
)
3919 pretty_printer tmp_pp
;
3920 pp_show_color (&tmp_pp
) = show_color
;
3922 /* We have to use "%<%s%>" rather than "%qs" here in order to avoid
3923 quoting colorization bytes within the results. */
3924 pp_printf (&tmp_pp
, "%<%s%>", content
);
3926 return pp_ggc_formatted_text (&tmp_pp
);
3929 /* If we had %H and %I, and hence deferred printing them,
3930 print them now, storing the result into the chunk_info
3931 for pp_format. Quote them if 'q' was provided.
3932 Also print the difference in tree form, adding it as
3933 an additional chunk. */
3936 cxx_format_postprocessor::handle (pretty_printer
*pp
)
3938 /* If we have one of %H and %I, the other should have
3940 if (m_type_a
.m_tree
|| m_type_b
.m_tree
)
3942 /* Avoid reentrancy issues by working with a copy of
3943 m_type_a and m_type_b, resetting them now. */
3944 deferred_printed_type type_a
= m_type_a
;
3945 deferred_printed_type type_b
= m_type_b
;
3946 m_type_a
= deferred_printed_type ();
3947 m_type_b
= deferred_printed_type ();
3949 gcc_assert (type_a
.m_buffer_ptr
);
3950 gcc_assert (type_b
.m_buffer_ptr
);
3952 bool show_color
= pp_show_color (pp
);
3954 const char *type_a_text
;
3955 const char *type_b_text
;
3957 if (comparable_template_types_p (type_a
.m_tree
, type_b
.m_tree
))
3960 = type_to_string_with_compare (type_a
.m_tree
, type_b
.m_tree
,
3961 type_a
.m_verbose
, show_color
);
3963 = type_to_string_with_compare (type_b
.m_tree
, type_a
.m_tree
,
3964 type_b
.m_verbose
, show_color
);
3966 if (flag_diagnostics_show_template_tree
)
3968 pretty_printer inner_pp
;
3969 pp_show_color (&inner_pp
) = pp_show_color (pp
);
3970 print_template_tree_comparison
3971 (&inner_pp
, type_a
.m_tree
, type_b
.m_tree
, type_a
.m_verbose
, 2);
3972 append_formatted_chunk (pp
, pp_ggc_formatted_text (&inner_pp
));
3977 /* If the types were not comparable (or if only one of %H/%I was
3978 provided), they are printed normally, and no difference tree
3980 type_a_text
= type_to_string (type_a
.m_tree
, type_a
.m_verbose
,
3981 true, &type_a
.m_quote
, show_color
);
3982 type_b_text
= type_to_string (type_b
.m_tree
, type_b
.m_verbose
,
3983 true, &type_b
.m_quote
, show_color
);
3987 type_a_text
= add_quotes (type_a_text
, show_color
);
3988 *type_a
.m_buffer_ptr
= type_a_text
;
3991 type_b_text
= add_quotes (type_b_text
, show_color
);
3992 *type_b
.m_buffer_ptr
= type_b_text
;
3996 /* Subroutine for handling %H and %I, to support i18n of messages like:
3998 error_at (loc, "could not convert %qE from %qH to %qI",
3999 expr, type_a, type_b);
4001 so that we can print things like:
4003 could not convert 'foo' from 'map<int,double>' to 'map<int,int>'
4005 and, with type-elision:
4007 could not convert 'foo' from 'map<[...],double>' to 'map<[...],int>'
4009 (with color-coding of the differences between the types).
4011 The %H and %I format codes are peers: both must be present,
4012 and they affect each other. Hence to handle them, we must
4013 delay printing until we have both, deferring the printing to
4014 pretty_printer's m_format_postprocessor hook.
4016 This is called in phase 2 of pp_format, when it is accumulating
4017 a series of formatted chunks. We stash the location of the chunk
4018 we're meant to have written to, so that we can write to it in the
4019 m_format_postprocessor hook.
4021 We also need to stash whether a 'q' prefix was provided (the QUOTE
4022 param) so that we can add the quotes when writing out the delayed
4026 defer_phase_2_of_type_diff (deferred_printed_type
*deferred
,
4027 tree type
, const char **buffer_ptr
,
4028 bool verbose
, bool quote
)
4030 gcc_assert (deferred
->m_tree
== NULL_TREE
);
4031 gcc_assert (deferred
->m_buffer_ptr
== NULL
);
4032 *deferred
= deferred_printed_type (type
, buffer_ptr
, verbose
, quote
);
4036 /* Called from output_format -- during diagnostic message processing --
4037 to handle C++ specific format specifier with the following meanings:
4038 %A function argument-list.
4042 %F function declaration.
4044 %H type difference (from).
4045 %I type difference (to).
4047 %L language as used in extern "lang".
4049 %P function parameter whose position is indicated by an integer.
4050 %Q assignment operator.
4051 %S substitution (template + args)
4054 %X exception-specification. */
4056 cp_printer (pretty_printer
*pp
, text_info
*text
, const char *spec
,
4057 int precision
, bool wide
, bool set_locus
, bool verbose
,
4058 bool *quoted
, const char **buffer_ptr
)
4060 gcc_assert (pp
->m_format_postprocessor
);
4061 cxx_format_postprocessor
*postprocessor
4062 = static_cast <cxx_format_postprocessor
*> (pp
->m_format_postprocessor
);
4066 #define next_tree (t = va_arg (*text->args_ptr, tree))
4067 #define next_tcode ((enum tree_code) va_arg (*text->args_ptr, int))
4068 #define next_lang ((enum languages) va_arg (*text->args_ptr, int))
4069 #define next_int va_arg (*text->args_ptr, int)
4071 if (precision
!= 0 || wide
)
4076 case 'A': result
= args_to_string (next_tree
, verbose
); break;
4077 case 'C': result
= code_to_string (next_tcode
); break;
4080 tree temp
= next_tree
;
4082 && DECL_HAS_DEBUG_EXPR_P (temp
))
4084 temp
= DECL_DEBUG_EXPR (temp
);
4087 result
= expr_to_string (temp
);
4091 result
= decl_to_string (temp
, verbose
);
4094 case 'E': result
= expr_to_string (next_tree
); break;
4095 case 'F': result
= fndecl_to_string (next_tree
, verbose
); break;
4097 percent_G_format (text
);
4100 defer_phase_2_of_type_diff (&postprocessor
->m_type_a
, next_tree
,
4101 buffer_ptr
, verbose
, *quoted
);
4104 defer_phase_2_of_type_diff (&postprocessor
->m_type_b
, next_tree
,
4105 buffer_ptr
, verbose
, *quoted
);
4108 t
= va_arg (*text
->args_ptr
, tree
);
4109 percent_K_format (text
, EXPR_LOCATION (t
), TREE_BLOCK (t
));
4111 case 'L': result
= language_to_string (next_lang
); break;
4112 case 'O': result
= op_to_string (false, next_tcode
); break;
4113 case 'P': result
= parm_to_string (next_int
); break;
4114 case 'Q': result
= op_to_string (true, next_tcode
); break;
4115 case 'S': result
= subst_to_string (next_tree
); break;
4118 result
= type_to_string (next_tree
, verbose
, false, quoted
,
4119 pp_show_color (pp
));
4122 case 'V': result
= cv_to_string (next_tree
, verbose
); break;
4123 case 'X': result
= eh_spec_to_string (next_tree
, verbose
); break;
4129 pp_string (pp
, result
);
4130 if (set_locus
&& t
!= NULL
)
4131 text
->set_location (0, location_of (t
), SHOW_RANGE_WITH_CARET
);
4139 /* Warn about the use of C++0x features when appropriate. */
4141 maybe_warn_cpp0x (cpp0x_warn_str str
)
4143 if ((cxx_dialect
== cxx98
) && !in_system_header_at (input_location
))
4144 /* We really want to suppress this warning in system headers,
4145 because libstdc++ uses variadic templates even when we aren't
4149 case CPP0X_INITIALIZER_LISTS
:
4150 pedwarn (input_location
, 0,
4151 "extended initializer lists "
4152 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4154 case CPP0X_EXPLICIT_CONVERSION
:
4155 pedwarn (input_location
, 0,
4156 "explicit conversion operators "
4157 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4159 case CPP0X_VARIADIC_TEMPLATES
:
4160 pedwarn (input_location
, 0,
4161 "variadic templates "
4162 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4164 case CPP0X_LAMBDA_EXPR
:
4165 pedwarn (input_location
, 0,
4166 "lambda expressions "
4167 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4170 pedwarn (input_location
, 0,
4171 "C++11 auto only available with %<-std=c++11%> or "
4172 "%<-std=gnu++11%>");
4174 case CPP0X_SCOPED_ENUMS
:
4175 pedwarn (input_location
, 0,
4176 "scoped enums only available with %<-std=c++11%> or "
4177 "%<-std=gnu++11%>");
4179 case CPP0X_DEFAULTED_DELETED
:
4180 pedwarn (input_location
, 0,
4181 "defaulted and deleted functions "
4182 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4184 case CPP0X_INLINE_NAMESPACES
:
4185 pedwarn (input_location
, OPT_Wpedantic
,
4186 "inline namespaces "
4187 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4189 case CPP0X_OVERRIDE_CONTROLS
:
4190 pedwarn (input_location
, 0,
4191 "override controls (override/final) "
4192 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4195 pedwarn (input_location
, 0,
4196 "non-static data member initializers "
4197 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4199 case CPP0X_USER_DEFINED_LITERALS
:
4200 pedwarn (input_location
, 0,
4201 "user-defined literals "
4202 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4204 case CPP0X_DELEGATING_CTORS
:
4205 pedwarn (input_location
, 0,
4206 "delegating constructors "
4207 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4209 case CPP0X_INHERITING_CTORS
:
4210 pedwarn (input_location
, 0,
4211 "inheriting constructors "
4212 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4214 case CPP0X_ATTRIBUTES
:
4215 pedwarn (input_location
, 0,
4217 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4219 case CPP0X_REF_QUALIFIER
:
4220 pedwarn (input_location
, 0,
4222 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4229 /* Warn about the use of variadic templates when appropriate. */
4231 maybe_warn_variadic_templates (void)
4233 maybe_warn_cpp0x (CPP0X_VARIADIC_TEMPLATES
);
4237 /* Issue an ISO C++98 pedantic warning at LOCATION, conditional on
4238 option OPT with text GMSGID. Use this function to report
4239 diagnostics for constructs that are invalid C++98, but valid
4242 pedwarn_cxx98 (location_t location
, int opt
, const char *gmsgid
, ...)
4244 diagnostic_info diagnostic
;
4247 rich_location
richloc (line_table
, location
);
4249 va_start (ap
, gmsgid
);
4250 diagnostic_set_info (&diagnostic
, gmsgid
, &ap
, &richloc
,
4251 (cxx_dialect
== cxx98
) ? DK_PEDWARN
: DK_WARNING
);
4252 diagnostic
.option_index
= opt
;
4253 ret
= diagnostic_report_diagnostic (global_dc
, &diagnostic
);
4258 /* Issue a diagnostic that NAME cannot be found in SCOPE. DECL is what
4259 we found when we tried to do the lookup. LOCATION is the location of
4260 the NAME identifier. */
4263 qualified_name_lookup_error (tree scope
, tree name
,
4264 tree decl
, location_t location
)
4266 if (scope
== error_mark_node
)
4267 ; /* We already complained. */
4268 else if (TYPE_P (scope
))
4270 if (!COMPLETE_TYPE_P (scope
))
4271 error_at (location
, "incomplete type %qT used in nested name specifier",
4273 else if (TREE_CODE (decl
) == TREE_LIST
)
4275 error_at (location
, "reference to %<%T::%D%> is ambiguous",
4277 print_candidates (decl
);
4282 if (SCOPED_ENUM_P (scope
) && TREE_CODE (name
) == IDENTIFIER_NODE
)
4283 hint
= suggest_alternative_in_scoped_enum (name
, scope
);
4284 if (const char *suggestion
= hint
.suggestion ())
4286 gcc_rich_location
richloc (location
);
4287 richloc
.add_fixit_replace (suggestion
);
4289 "%qD is not a member of %qT; did you mean %qs?",
4290 name
, scope
, suggestion
);
4293 error_at (location
, "%qD is not a member of %qT", name
, scope
);
4296 else if (scope
!= global_namespace
)
4298 auto_diagnostic_group d
;
4299 bool emit_fixit
= true;
4301 = suggest_alternative_in_explicit_scope (location
, name
, scope
);
4304 hint
= suggest_alternatives_in_other_namespaces (location
, name
);
4305 /* "location" is just the location of the name, not of the explicit
4306 scope, and it's not easy to get at the latter, so we can't issue
4307 fix-it hints for the suggestion. */
4310 if (const char *suggestion
= hint
.suggestion ())
4312 gcc_rich_location
richloc (location
);
4314 richloc
.add_fixit_replace (suggestion
);
4315 error_at (&richloc
, "%qD is not a member of %qD; did you mean %qs?",
4316 name
, scope
, suggestion
);
4319 error_at (location
, "%qD is not a member of %qD", name
, scope
);
4323 auto_diagnostic_group d
;
4324 name_hint hint
= suggest_alternatives_for (location
, name
, true);
4325 if (const char *suggestion
= hint
.suggestion ())
4327 gcc_rich_location
richloc (location
);
4328 richloc
.add_fixit_replace (suggestion
);
4330 "%<::%D%> has not been declared; did you mean %qs?",
4334 error_at (location
, "%<::%D%> has not been declared", name
);
4338 /* C++-specific implementation of range_label::get_text () vfunc for
4339 range_label_for_type_mismatch.
4341 Compare with print_template_differences above. */
4344 range_label_for_type_mismatch::get_text (unsigned /*range_idx*/) const
4346 if (m_labelled_type
== NULL_TREE
)
4347 return label_text (NULL
, false);
4349 const bool verbose
= false;
4350 const bool show_color
= false;
4354 && comparable_template_types_p (m_labelled_type
, m_other_type
))
4355 result
= type_to_string_with_compare (m_labelled_type
, m_other_type
,
4356 verbose
, show_color
);
4358 result
= type_to_string (m_labelled_type
, verbose
, true, NULL
, show_color
);
4360 /* Both of the above return GC-allocated buffers, so the caller mustn't
4362 return label_text (const_cast <char *> (result
), false);