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 class deferred_printed_type
113 deferred_printed_type ()
114 : m_tree (NULL_TREE
), m_buffer_ptr (NULL
), m_verbose (false), m_quote (false)
117 deferred_printed_type (tree type
, const char **buffer_ptr
, bool verbose
,
119 : m_tree (type
), m_buffer_ptr (buffer_ptr
), m_verbose (verbose
),
123 gcc_assert (buffer_ptr
);
126 /* The tree is not GTY-marked: they are only non-NULL within a
127 call to pp_format. */
129 const char **m_buffer_ptr
;
134 /* Subclass of format_postprocessor for the C++ frontend.
135 This handles the %H and %I formatting codes, printing them
136 in a postprocessing phase (since they affect each other). */
138 class cxx_format_postprocessor
: public format_postprocessor
141 cxx_format_postprocessor ()
142 : m_type_a (), m_type_b ()
145 void handle (pretty_printer
*pp
) FINAL OVERRIDE
;
147 deferred_printed_type m_type_a
;
148 deferred_printed_type m_type_b
;
151 /* CONTEXT->printer is a basic pretty printer that was constructed
152 presumably by diagnostic_initialize(), called early in the
153 compiler's initialization process (in general_init) Before the FE
154 is initialized. This (C++) FE-specific diagnostic initializer is
155 thus replacing the basic pretty printer with one that has C++-aware
159 cxx_initialize_diagnostics (diagnostic_context
*context
)
161 pretty_printer
*base
= context
->printer
;
162 cxx_pretty_printer
*pp
= XNEW (cxx_pretty_printer
);
163 context
->printer
= new (pp
) cxx_pretty_printer ();
165 /* It is safe to free this object because it was previously XNEW()'d. */
166 base
->~pretty_printer ();
169 c_common_diagnostics_set_defaults (context
);
170 diagnostic_starter (context
) = cp_diagnostic_starter
;
171 /* diagnostic_finalizer is already c_diagnostic_finalizer. */
172 diagnostic_format_decoder (context
) = cp_printer
;
173 pp
->m_format_postprocessor
= new cxx_format_postprocessor ();
176 /* Dump a scope, if deemed necessary. */
179 dump_scope (cxx_pretty_printer
*pp
, tree scope
, int flags
)
181 int f
= flags
& (TFF_SCOPE
| TFF_CHASE_TYPEDEF
);
183 if (scope
== NULL_TREE
)
186 /* Enum values within an unscoped enum will be CONST_DECL with an
187 ENUMERAL_TYPE as their "scope". Use CP_TYPE_CONTEXT of the
188 ENUMERAL_TYPE, so as to print any enclosing namespace. */
189 if (UNSCOPED_ENUM_P (scope
))
190 scope
= CP_TYPE_CONTEXT (scope
);
192 if (TREE_CODE (scope
) == NAMESPACE_DECL
)
194 if (scope
!= global_namespace
)
196 dump_decl (pp
, scope
, f
);
197 pp_cxx_colon_colon (pp
);
200 else if (AGGREGATE_TYPE_P (scope
)
201 || SCOPED_ENUM_P (scope
))
203 dump_type (pp
, scope
, f
);
204 pp_cxx_colon_colon (pp
);
206 else if ((flags
& TFF_SCOPE
) && TREE_CODE (scope
) == FUNCTION_DECL
)
208 dump_function_decl (pp
, scope
, f
);
209 pp_cxx_colon_colon (pp
);
213 /* Dump the template ARGument under control of FLAGS. */
216 dump_template_argument (cxx_pretty_printer
*pp
, tree arg
, int flags
)
218 if (ARGUMENT_PACK_P (arg
))
219 dump_template_argument_list (pp
, ARGUMENT_PACK_ARGS (arg
),
220 /* No default args in argument packs. */
221 flags
|TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS
);
222 else if (TYPE_P (arg
) || TREE_CODE (arg
) == TEMPLATE_DECL
)
223 dump_type (pp
, arg
, flags
& ~TFF_CLASS_KEY_OR_ENUM
);
226 if (TREE_CODE (arg
) == TREE_LIST
)
227 arg
= TREE_VALUE (arg
);
229 /* Strip implicit conversions. */
230 while (CONVERT_EXPR_P (arg
))
231 arg
= TREE_OPERAND (arg
, 0);
233 dump_expr (pp
, arg
, (flags
| TFF_EXPR_IN_PARENS
) & ~TFF_CLASS_KEY_OR_ENUM
);
237 /* Count the number of template arguments ARGS whose value does not
238 match the (optional) default template parameter in PARAMS */
241 get_non_default_template_args_count (tree args
, int flags
)
243 int n
= TREE_VEC_LENGTH (INNERMOST_TEMPLATE_ARGS (args
));
245 if (/* We use this flag when generating debug information. We don't
246 want to expand templates at this point, for this may generate
247 new decls, which gets decl counts out of sync, which may in
248 turn cause codegen differences between compilations with and
250 (flags
& TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS
) != 0
251 || !flag_pretty_templates
)
254 return GET_NON_DEFAULT_TEMPLATE_ARGS_COUNT (INNERMOST_TEMPLATE_ARGS (args
));
257 /* Dump a template-argument-list ARGS (always a TREE_VEC) under control
261 dump_template_argument_list (cxx_pretty_printer
*pp
, tree args
, int flags
)
263 int n
= get_non_default_template_args_count (args
, flags
);
267 for (i
= 0; i
< n
; ++i
)
269 tree arg
= TREE_VEC_ELT (args
, i
);
271 /* Only print a comma if we know there is an argument coming. In
272 the case of an empty template argument pack, no actual
273 argument will be printed. */
275 && (!ARGUMENT_PACK_P (arg
)
276 || TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg
)) > 0))
277 pp_separate_with_comma (pp
);
279 dump_template_argument (pp
, arg
, flags
);
284 /* Dump a template parameter PARM (a TREE_LIST) under control of FLAGS. */
287 dump_template_parameter (cxx_pretty_printer
*pp
, tree parm
, int flags
)
292 if (parm
== error_mark_node
)
295 p
= TREE_VALUE (parm
);
296 a
= TREE_PURPOSE (parm
);
298 if (TREE_CODE (p
) == TYPE_DECL
)
300 if (flags
& TFF_DECL_SPECIFIERS
)
302 pp_cxx_ws_string (pp
, "class");
303 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (p
)))
304 pp_cxx_ws_string (pp
, "...");
306 pp_cxx_tree_identifier (pp
, DECL_NAME (p
));
308 else if (DECL_NAME (p
))
309 pp_cxx_tree_identifier (pp
, DECL_NAME (p
));
311 pp_cxx_canonical_template_parameter (pp
, TREE_TYPE (p
));
314 dump_decl (pp
, p
, flags
| TFF_DECL_SPECIFIERS
);
316 if ((flags
& TFF_FUNCTION_DEFAULT_ARGUMENTS
) && a
!= NULL_TREE
)
318 pp_cxx_whitespace (pp
);
320 pp_cxx_whitespace (pp
);
321 if (TREE_CODE (p
) == TYPE_DECL
|| TREE_CODE (p
) == TEMPLATE_DECL
)
322 dump_type (pp
, a
, flags
& ~TFF_CHASE_TYPEDEF
);
324 dump_expr (pp
, a
, flags
| TFF_EXPR_IN_PARENS
);
328 /* Dump, under control of FLAGS, a template-parameter-list binding.
329 PARMS is a TREE_LIST of TREE_VEC of TREE_LIST and ARGS is a
333 dump_template_bindings (cxx_pretty_printer
*pp
, tree parms
, tree args
,
334 vec
<tree
, va_gc
> *typenames
)
336 bool need_semicolon
= false;
342 tree p
= TREE_VALUE (parms
);
343 int lvl
= TMPL_PARMS_DEPTH (parms
);
346 tree lvl_args
= NULL_TREE
;
348 /* Don't crash if we had an invalid argument list. */
349 if (TMPL_ARGS_DEPTH (args
) >= lvl
)
350 lvl_args
= TMPL_ARGS_LEVEL (args
, lvl
);
352 for (i
= 0; i
< TREE_VEC_LENGTH (p
); ++i
)
354 tree arg
= NULL_TREE
;
356 /* Don't crash if we had an invalid argument list. */
357 if (lvl_args
&& NUM_TMPL_ARGS (lvl_args
) > arg_idx
)
358 arg
= TREE_VEC_ELT (lvl_args
, arg_idx
);
361 pp_separate_with_semicolon (pp
);
362 dump_template_parameter (pp
, TREE_VEC_ELT (p
, i
),
363 TFF_PLAIN_IDENTIFIER
);
364 pp_cxx_whitespace (pp
);
366 pp_cxx_whitespace (pp
);
369 if (ARGUMENT_PACK_P (arg
))
370 pp_cxx_left_brace (pp
);
371 dump_template_argument (pp
, arg
, TFF_PLAIN_IDENTIFIER
);
372 if (ARGUMENT_PACK_P (arg
))
373 pp_cxx_right_brace (pp
);
376 pp_string (pp
, M_("<missing>"));
379 need_semicolon
= true;
382 parms
= TREE_CHAIN (parms
);
385 /* Don't bother with typenames for a partial instantiation. */
386 if (vec_safe_is_empty (typenames
) || uses_template_parms (args
))
389 /* Don't try to print typenames when we're processing a clone. */
390 if (current_function_decl
391 && !DECL_LANG_SPECIFIC (current_function_decl
))
394 /* Don't try to do this once cgraph starts throwing away front-end
399 FOR_EACH_VEC_SAFE_ELT (typenames
, i
, t
)
402 pp_separate_with_semicolon (pp
);
403 dump_type (pp
, t
, TFF_PLAIN_IDENTIFIER
);
404 pp_cxx_whitespace (pp
);
406 pp_cxx_whitespace (pp
);
407 push_deferring_access_checks (dk_no_check
);
408 t
= tsubst (t
, args
, tf_none
, NULL_TREE
);
409 pop_deferring_access_checks ();
410 /* Strip typedefs. We can't just use TFF_CHASE_TYPEDEF because
411 pp_simple_type_specifier doesn't know about it. */
412 t
= strip_typedefs (t
);
413 dump_type (pp
, t
, TFF_PLAIN_IDENTIFIER
);
417 /* Dump a human-readable equivalent of the alias template
418 specialization of T. */
421 dump_alias_template_specialization (cxx_pretty_printer
*pp
, tree t
, int flags
)
423 gcc_assert (alias_template_specialization_p (t
));
425 tree decl
= TYPE_NAME (t
);
426 if (!(flags
& TFF_UNQUALIFIED_NAME
))
427 dump_scope (pp
, CP_DECL_CONTEXT (decl
), flags
);
428 pp_cxx_tree_identifier (pp
, DECL_NAME (decl
));
429 dump_template_parms (pp
, DECL_TEMPLATE_INFO (decl
),
431 flags
& ~TFF_TEMPLATE_HEADER
);
434 /* Dump a human-readable equivalent of TYPE. FLAGS controls the
438 dump_type (cxx_pretty_printer
*pp
, tree t
, int flags
)
443 /* Don't print e.g. "struct mytypedef". */
444 if (TYPE_P (t
) && typedef_variant_p (t
))
446 tree decl
= TYPE_NAME (t
);
447 if ((flags
& TFF_CHASE_TYPEDEF
)
448 || DECL_SELF_REFERENCE_P (decl
)
449 || (!flag_pretty_templates
450 && DECL_LANG_SPECIFIC (decl
) && DECL_TEMPLATE_INFO (decl
)))
451 t
= strip_typedefs (t
);
452 else if (alias_template_specialization_p (t
))
454 dump_alias_template_specialization (pp
, t
, flags
);
457 else if (same_type_p (t
, TREE_TYPE (decl
)))
461 pp_cxx_cv_qualifier_seq (pp
, t
);
462 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
467 if (TYPE_PTRMEMFUNC_P (t
))
470 switch (TREE_CODE (t
))
473 if (t
== init_list_type_node
)
474 pp_string (pp
, M_("<brace-enclosed initializer list>"));
475 else if (t
== unknown_type_node
)
476 pp_string (pp
, M_("<unresolved overloaded function type>"));
479 pp_cxx_cv_qualifier_seq (pp
, t
);
480 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
485 /* A list of function parms. */
486 dump_parameters (pp
, t
, flags
);
489 case IDENTIFIER_NODE
:
490 pp_cxx_tree_identifier (pp
, t
);
494 dump_type (pp
, BINFO_TYPE (t
), flags
);
500 dump_aggr_type (pp
, t
, flags
);
504 if (flags
& TFF_CHASE_TYPEDEF
)
506 dump_type (pp
, DECL_ORIGINAL_TYPE (t
)
507 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
), flags
);
514 dump_decl (pp
, t
, flags
& ~TFF_DECL_SPECIFIERS
);
523 case FIXED_POINT_TYPE
:
524 pp_type_specifier_seq (pp
, t
);
527 case TEMPLATE_TEMPLATE_PARM
:
528 /* For parameters inside template signature. */
529 if (TYPE_IDENTIFIER (t
))
530 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
532 pp_cxx_canonical_template_parameter (pp
, t
);
535 case BOUND_TEMPLATE_TEMPLATE_PARM
:
537 tree args
= TYPE_TI_ARGS (t
);
538 pp_cxx_cv_qualifier_seq (pp
, t
);
539 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
540 pp_cxx_begin_template_argument_list (pp
);
541 dump_template_argument_list (pp
, args
, flags
);
542 pp_cxx_end_template_argument_list (pp
);
546 case TEMPLATE_TYPE_PARM
:
547 pp_cxx_cv_qualifier_seq (pp
, t
);
548 if (tree c
= PLACEHOLDER_TYPE_CONSTRAINTS (t
))
549 pp_cxx_constrained_type_spec (pp
, c
);
550 else if (template_placeholder_p (t
))
552 t
= TREE_TYPE (CLASS_PLACEHOLDER_TEMPLATE (t
));
553 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
554 pp_string (pp
, "<...auto...>");
556 else if (TYPE_IDENTIFIER (t
))
557 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
559 pp_cxx_canonical_template_parameter
560 (pp
, TEMPLATE_TYPE_PARM_INDEX (t
));
563 /* This is not always necessary for pointers and such, but doing this
564 reduces code size. */
573 dump_type_prefix (pp
, t
, flags
);
574 dump_type_suffix (pp
, t
, flags
);
578 if (! (flags
& TFF_CHASE_TYPEDEF
)
579 && DECL_ORIGINAL_TYPE (TYPE_NAME (t
)))
581 dump_decl (pp
, TYPE_NAME (t
), TFF_PLAIN_IDENTIFIER
);
584 pp_cxx_cv_qualifier_seq (pp
, t
);
585 pp_cxx_ws_string (pp
,
586 TYPENAME_IS_ENUM_P (t
) ? "enum"
587 : TYPENAME_IS_CLASS_P (t
) ? "class"
589 dump_typename (pp
, t
, flags
);
592 case UNBOUND_CLASS_TEMPLATE
:
593 if (! (flags
& TFF_UNQUALIFIED_NAME
))
595 dump_type (pp
, TYPE_CONTEXT (t
), flags
);
596 pp_cxx_colon_colon (pp
);
598 pp_cxx_ws_string (pp
, "template");
599 dump_type (pp
, TYPE_IDENTIFIER (t
), flags
);
603 pp_cxx_ws_string (pp
, "__typeof__");
604 pp_cxx_whitespace (pp
);
605 pp_cxx_left_paren (pp
);
606 dump_expr (pp
, TYPEOF_TYPE_EXPR (t
), flags
& ~TFF_EXPR_IN_PARENS
);
607 pp_cxx_right_paren (pp
);
610 case UNDERLYING_TYPE
:
611 pp_cxx_ws_string (pp
, "__underlying_type");
612 pp_cxx_whitespace (pp
);
613 pp_cxx_left_paren (pp
);
614 dump_expr (pp
, UNDERLYING_TYPE_TYPE (t
), flags
& ~TFF_EXPR_IN_PARENS
);
615 pp_cxx_right_paren (pp
);
618 case TYPE_PACK_EXPANSION
:
619 dump_type (pp
, PACK_EXPANSION_PATTERN (t
), flags
);
620 pp_cxx_ws_string (pp
, "...");
623 case TYPE_ARGUMENT_PACK
:
624 dump_template_argument (pp
, t
, flags
);
628 pp_cxx_ws_string (pp
, "decltype");
629 pp_cxx_whitespace (pp
);
630 pp_cxx_left_paren (pp
);
631 dump_expr (pp
, DECLTYPE_TYPE_EXPR (t
), flags
& ~TFF_EXPR_IN_PARENS
);
632 pp_cxx_right_paren (pp
);
636 pp_string (pp
, "std::nullptr_t");
640 pp_unsupported_tree (pp
, t
);
644 pp_string (pp
, M_("<type error>"));
649 /* Dump a TYPENAME_TYPE. We need to notice when the context is itself
653 dump_typename (cxx_pretty_printer
*pp
, tree t
, int flags
)
655 tree ctx
= TYPE_CONTEXT (t
);
657 if (TREE_CODE (ctx
) == TYPENAME_TYPE
)
658 dump_typename (pp
, ctx
, flags
);
660 dump_type (pp
, ctx
, flags
& ~TFF_CLASS_KEY_OR_ENUM
);
661 pp_cxx_colon_colon (pp
);
662 dump_decl (pp
, TYPENAME_TYPE_FULLNAME (t
), flags
);
665 /* Return the name of the supplied aggregate, or enumeral type. */
668 class_key_or_enum_as_string (tree t
)
670 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
672 if (SCOPED_ENUM_P (t
))
677 else if (TREE_CODE (t
) == UNION_TYPE
)
679 else if (TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_DECLARED_CLASS (t
))
685 /* Print out a class declaration T under the control of FLAGS,
686 in the form `class foo'. */
689 dump_aggr_type (cxx_pretty_printer
*pp
, tree t
, int flags
)
692 const char *variety
= class_key_or_enum_as_string (t
);
696 pp_cxx_cv_qualifier_seq (pp
, t
);
698 if (flags
& TFF_CLASS_KEY_OR_ENUM
)
699 pp_cxx_ws_string (pp
, variety
);
701 name
= TYPE_NAME (t
);
705 typdef
= (!DECL_ARTIFICIAL (name
)
706 /* An alias specialization is not considered to be a
708 && !alias_template_specialization_p (t
));
711 && ((flags
& TFF_CHASE_TYPEDEF
)
712 || (!flag_pretty_templates
&& DECL_LANG_SPECIFIC (name
)
713 && DECL_TEMPLATE_INFO (name
))))
714 || DECL_SELF_REFERENCE_P (name
))
716 t
= TYPE_MAIN_VARIANT (t
);
717 name
= TYPE_NAME (t
);
721 tmplate
= !typdef
&& TREE_CODE (t
) != ENUMERAL_TYPE
722 && TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_TEMPLATE_INFO (t
)
723 && (TREE_CODE (CLASSTYPE_TI_TEMPLATE (t
)) != TEMPLATE_DECL
724 || PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t
)));
726 if (! (flags
& TFF_UNQUALIFIED_NAME
))
727 dump_scope (pp
, CP_DECL_CONTEXT (name
), flags
| TFF_SCOPE
);
728 flags
&= ~TFF_UNQUALIFIED_NAME
;
731 /* Because the template names are mangled, we have to locate
732 the most general template, and use that name. */
733 tree tpl
= TYPE_TI_TEMPLATE (t
);
735 while (DECL_TEMPLATE_INFO (tpl
))
736 tpl
= DECL_TI_TEMPLATE (tpl
);
739 name
= DECL_NAME (name
);
742 if (LAMBDA_TYPE_P (t
))
744 /* A lambda's "type" is essentially its signature. */
745 pp_string (pp
, M_("<lambda"));
746 if (lambda_function (t
))
748 FUNCTION_FIRST_USER_PARMTYPE (lambda_function (t
)),
752 else if (!name
|| IDENTIFIER_ANON_P (name
))
754 if (flags
& TFF_CLASS_KEY_OR_ENUM
)
755 pp_string (pp
, M_("<unnamed>"));
757 pp_printf (pp
, M_("<unnamed %s>"), variety
);
760 pp_cxx_tree_identifier (pp
, name
);
763 dump_template_parms (pp
, TYPE_TEMPLATE_INFO (t
),
764 !CLASSTYPE_USE_TEMPLATE (t
),
765 flags
& ~TFF_TEMPLATE_HEADER
);
768 /* Dump into the obstack the initial part of the output for a given type.
769 This is necessary when dealing with things like functions returning
772 return type of `int (* fee ())()': pointer -> function -> int. Both
773 pointer (and reference and offset) and function (and member) types must
774 deal with prefix and suffix.
776 Arrays must also do this for DECL nodes, like int a[], and for things like
780 dump_type_prefix (cxx_pretty_printer
*pp
, tree t
, int flags
)
782 if (TYPE_PTRMEMFUNC_P (t
))
784 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
788 switch (TREE_CODE (t
))
793 tree sub
= TREE_TYPE (t
);
795 dump_type_prefix (pp
, sub
, flags
);
796 if (TREE_CODE (sub
) == ARRAY_TYPE
797 || TREE_CODE (sub
) == FUNCTION_TYPE
)
799 pp_cxx_whitespace (pp
);
800 pp_cxx_left_paren (pp
);
801 pp_c_attributes_display (pp
, TYPE_ATTRIBUTES (sub
));
805 else if (TYPE_REF_P (t
))
807 if (TYPE_REF_IS_RVALUE (t
))
808 pp_ampersand_ampersand (pp
);
812 pp
->padding
= pp_before
;
813 pp_cxx_cv_qualifier_seq (pp
, t
);
819 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
820 if (TREE_CODE (t
) == OFFSET_TYPE
) /* pmfs deal with this in d_t_p */
823 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
824 pp_cxx_left_paren (pp
);
825 dump_type (pp
, TYPE_OFFSET_BASETYPE (t
), flags
);
826 pp_cxx_colon_colon (pp
);
829 pp_cxx_cv_qualifier_seq (pp
, t
);
830 pp
->padding
= pp_before
;
833 /* This can be reached without a pointer when dealing with
834 templates, e.g. std::is_function. */
836 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
840 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
842 pp_cxx_left_paren (pp
);
843 dump_aggr_type (pp
, TYPE_METHOD_BASETYPE (t
), flags
);
844 pp_cxx_colon_colon (pp
);
848 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
852 case IDENTIFIER_NODE
:
857 case TEMPLATE_TYPE_PARM
:
858 case TEMPLATE_TEMPLATE_PARM
:
859 case BOUND_TEMPLATE_TEMPLATE_PARM
:
870 case UNDERLYING_TYPE
:
872 case TYPE_PACK_EXPANSION
:
873 case FIXED_POINT_TYPE
:
875 dump_type (pp
, t
, flags
);
876 pp
->padding
= pp_before
;
880 pp_unsupported_tree (pp
, t
);
883 pp_string (pp
, M_("<typeprefixerror>"));
888 /* Dump the suffix of type T, under control of FLAGS. This is the part
889 which appears after the identifier (or function parms). */
892 dump_type_suffix (cxx_pretty_printer
*pp
, tree t
, int flags
)
894 if (TYPE_PTRMEMFUNC_P (t
))
895 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
897 switch (TREE_CODE (t
))
902 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
903 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
904 pp_cxx_right_paren (pp
);
905 if (TREE_CODE (t
) == POINTER_TYPE
)
906 flags
|= TFF_POINTER
;
907 dump_type_suffix (pp
, TREE_TYPE (t
), flags
);
914 if (TREE_CODE (t
) == METHOD_TYPE
)
915 /* Can only be reached through a pointer. */
916 pp_cxx_right_paren (pp
);
917 arg
= TYPE_ARG_TYPES (t
);
918 if (TREE_CODE (t
) == METHOD_TYPE
)
919 arg
= TREE_CHAIN (arg
);
921 /* Function pointers don't have default args. Not in standard C++,
922 anyway; they may in g++, but we'll just pretend otherwise. */
923 dump_parameters (pp
, arg
, flags
& ~TFF_FUNCTION_DEFAULT_ARGUMENTS
);
925 pp
->padding
= pp_before
;
926 pp_cxx_cv_qualifiers (pp
, type_memfn_quals (t
),
927 TREE_CODE (t
) == FUNCTION_TYPE
928 && (flags
& TFF_POINTER
));
929 dump_ref_qualifier (pp
, t
, flags
);
930 if (tx_safe_fn_type_p (t
))
931 pp_cxx_ws_string (pp
, "transaction_safe");
932 dump_exception_spec (pp
, TYPE_RAISES_EXCEPTIONS (t
), flags
);
933 dump_type_suffix (pp
, TREE_TYPE (t
), flags
);
939 pp_cxx_left_bracket (pp
);
940 if (tree dtype
= TYPE_DOMAIN (t
))
942 tree max
= TYPE_MAX_VALUE (dtype
);
943 /* Zero-length arrays have an upper bound of SIZE_MAX. */
944 if (integer_all_onesp (max
))
945 pp_character (pp
, '0');
946 else if (tree_fits_shwi_p (max
))
947 pp_wide_integer (pp
, tree_to_shwi (max
) + 1);
951 if (TREE_CODE (max
) == SAVE_EXPR
)
952 max
= TREE_OPERAND (max
, 0);
953 if (TREE_CODE (max
) == MINUS_EXPR
954 || TREE_CODE (max
) == PLUS_EXPR
)
956 max
= TREE_OPERAND (max
, 0);
957 while (CONVERT_EXPR_P (max
))
958 max
= TREE_OPERAND (max
, 0);
961 max
= fold_build2_loc (input_location
,
962 PLUS_EXPR
, dtype
, max
,
963 build_int_cst (dtype
, 1));
964 dump_expr (pp
, max
, flags
& ~TFF_EXPR_IN_PARENS
);
967 pp_cxx_right_bracket (pp
);
968 dump_type_suffix (pp
, TREE_TYPE (t
), flags
);
972 case IDENTIFIER_NODE
:
977 case TEMPLATE_TYPE_PARM
:
978 case TEMPLATE_TEMPLATE_PARM
:
979 case BOUND_TEMPLATE_TEMPLATE_PARM
:
990 case UNDERLYING_TYPE
:
992 case TYPE_PACK_EXPANSION
:
993 case FIXED_POINT_TYPE
:
998 pp_unsupported_tree (pp
, t
);
1000 /* Don't mark it here, we should have already done in
1001 dump_type_prefix. */
1007 dump_global_iord (cxx_pretty_printer
*pp
, tree t
)
1009 const char *p
= NULL
;
1011 if (DECL_GLOBAL_CTOR_P (t
))
1012 p
= M_("(static initializers for %s)");
1013 else if (DECL_GLOBAL_DTOR_P (t
))
1014 p
= M_("(static destructors for %s)");
1018 pp_printf (pp
, p
, DECL_SOURCE_FILE (t
));
1022 dump_simple_decl (cxx_pretty_printer
*pp
, tree t
, tree type
, int flags
)
1024 if (template_parm_object_p (t
))
1025 return dump_expr (pp
, DECL_INITIAL (t
), flags
);
1027 if (flags
& TFF_DECL_SPECIFIERS
)
1029 if (VAR_P (t
) && DECL_DECLARED_CONSTEXPR_P (t
))
1031 if (DECL_LANG_SPECIFIC (t
) && DECL_DECLARED_CONCEPT_P (t
))
1032 pp_cxx_ws_string (pp
, "concept");
1034 pp_cxx_ws_string (pp
, "constexpr");
1036 dump_type_prefix (pp
, type
, flags
& ~TFF_UNQUALIFIED_NAME
);
1037 pp_maybe_space (pp
);
1039 if (! (flags
& TFF_UNQUALIFIED_NAME
)
1040 && TREE_CODE (t
) != PARM_DECL
1041 && (!DECL_INITIAL (t
)
1042 || TREE_CODE (DECL_INITIAL (t
)) != TEMPLATE_PARM_INDEX
))
1043 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1044 flags
&= ~TFF_UNQUALIFIED_NAME
;
1045 if ((flags
& TFF_DECL_SPECIFIERS
)
1046 && DECL_TEMPLATE_PARM_P (t
)
1047 && TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (t
)))
1048 pp_string (pp
, "...");
1051 if (TREE_CODE (t
) == FIELD_DECL
&& DECL_NORMAL_CAPTURE_P (t
))
1054 pp_string (pp
, IDENTIFIER_POINTER (DECL_NAME (t
)) + 2);
1055 pp_string (pp
, " capture>");
1058 dump_decl (pp
, DECL_NAME (t
), flags
);
1060 else if (DECL_DECOMPOSITION_P (t
))
1061 pp_string (pp
, M_("<structured bindings>"));
1063 pp_string (pp
, M_("<anonymous>"));
1064 if (flags
& TFF_DECL_SPECIFIERS
)
1065 dump_type_suffix (pp
, type
, flags
);
1068 /* Print an IDENTIFIER_NODE that is the name of a declaration. */
1071 dump_decl_name (cxx_pretty_printer
*pp
, tree t
, int flags
)
1073 /* These special cases are duplicated here so that other functions
1074 can feed identifiers to error and get them demangled properly. */
1075 if (IDENTIFIER_CONV_OP_P (t
))
1077 pp_cxx_ws_string (pp
, "operator");
1078 /* Not exactly IDENTIFIER_TYPE_VALUE. */
1079 dump_type (pp
, TREE_TYPE (t
), flags
);
1082 if (dguide_name_p (t
))
1084 dump_decl (pp
, CLASSTYPE_TI_TEMPLATE (TREE_TYPE (t
)),
1085 TFF_UNQUALIFIED_NAME
);
1089 const char *str
= IDENTIFIER_POINTER (t
);
1090 if (!strncmp (str
, "_ZGR", 3))
1092 pp_cxx_ws_string (pp
, "<temporary>");
1096 pp_cxx_tree_identifier (pp
, t
);
1099 /* Dump a human readable string for the decl T under control of FLAGS. */
1102 dump_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
1107 /* If doing Objective-C++, give Objective-C a chance to demangle
1108 Objective-C method names. */
1109 if (c_dialect_objc ())
1111 const char *demangled
= objc_maybe_printable_name (t
, flags
);
1114 pp_string (pp
, demangled
);
1119 switch (TREE_CODE (t
))
1122 /* Don't say 'typedef class A' */
1123 if (DECL_ARTIFICIAL (t
) && !DECL_SELF_REFERENCE_P (t
))
1125 if ((flags
& TFF_DECL_SPECIFIERS
)
1126 && TREE_CODE (TREE_TYPE (t
)) == TEMPLATE_TYPE_PARM
)
1128 /* Say `class T' not just `T'. */
1129 pp_cxx_ws_string (pp
, "class");
1131 /* Emit the `...' for a parameter pack. */
1132 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t
)))
1133 pp_cxx_ws_string (pp
, "...");
1136 dump_type (pp
, TREE_TYPE (t
), flags
);
1139 if (TYPE_DECL_ALIAS_P (t
)
1140 && (flags
& TFF_DECL_SPECIFIERS
1141 || flags
& TFF_CLASS_KEY_OR_ENUM
))
1143 pp_cxx_ws_string (pp
, "using");
1144 dump_decl (pp
, DECL_NAME (t
), flags
);
1145 pp_cxx_whitespace (pp
);
1146 pp_cxx_ws_string (pp
, "=");
1147 pp_cxx_whitespace (pp
);
1148 dump_type (pp
, (DECL_ORIGINAL_TYPE (t
)
1149 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
)),
1153 if ((flags
& TFF_DECL_SPECIFIERS
)
1154 && !DECL_SELF_REFERENCE_P (t
))
1155 pp_cxx_ws_string (pp
, "typedef");
1156 dump_simple_decl (pp
, t
, DECL_ORIGINAL_TYPE (t
)
1157 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
),
1162 if (DECL_NAME (t
) && VTABLE_NAME_P (DECL_NAME (t
)))
1164 pp_string (pp
, M_("vtable for "));
1165 gcc_assert (TYPE_P (DECL_CONTEXT (t
)));
1166 dump_type (pp
, DECL_CONTEXT (t
), flags
);
1172 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1174 /* Handle variable template specializations. */
1176 && DECL_LANG_SPECIFIC (t
)
1177 && DECL_TEMPLATE_INFO (t
)
1178 && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t
)))
1180 pp_cxx_begin_template_argument_list (pp
);
1181 tree args
= INNERMOST_TEMPLATE_ARGS (DECL_TI_ARGS (t
));
1182 dump_template_argument_list (pp
, args
, flags
);
1183 pp_cxx_end_template_argument_list (pp
);
1188 pp_string (pp
, M_("<return value> "));
1189 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1192 case NAMESPACE_DECL
:
1193 if (flags
& TFF_DECL_SPECIFIERS
)
1194 pp
->declaration (t
);
1197 if (! (flags
& TFF_UNQUALIFIED_NAME
))
1198 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1199 flags
&= ~TFF_UNQUALIFIED_NAME
;
1200 if (DECL_NAME (t
) == NULL_TREE
)
1202 if (!(pp
->flags
& pp_c_flag_gnu_v3
))
1203 pp_cxx_ws_string (pp
, M_("{anonymous}"));
1205 pp_cxx_ws_string (pp
, M_("(anonymous namespace)"));
1208 pp_cxx_tree_identifier (pp
, DECL_NAME (t
));
1213 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
1214 pp_cxx_colon_colon (pp
);
1215 dump_decl (pp
, TREE_OPERAND (t
, 1), TFF_UNQUALIFIED_NAME
);
1219 dump_decl (pp
, TREE_OPERAND (t
, 0), flags
);
1220 pp_cxx_left_bracket (pp
);
1221 dump_decl (pp
, TREE_OPERAND (t
, 1), flags
);
1222 pp_cxx_right_bracket (pp
);
1225 /* So that we can do dump_decl on an aggr type. */
1229 dump_type (pp
, t
, flags
);
1233 /* This is a pseudo destructor call which has not been folded into
1234 a PSEUDO_DTOR_EXPR yet. */
1235 pp_cxx_complement (pp
);
1236 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
1243 case IDENTIFIER_NODE
:
1244 dump_decl_name (pp
, t
, flags
);
1248 if (!OVL_SINGLE_P (t
))
1250 tree ctx
= ovl_scope (t
);
1251 if (ctx
!= global_namespace
)
1254 dump_type (pp
, ctx
, flags
);
1256 dump_decl (pp
, ctx
, flags
);
1257 pp_cxx_colon_colon (pp
);
1259 dump_decl (pp
, OVL_NAME (t
), flags
);
1263 /* If there's only one function, just treat it like an ordinary
1269 if (! DECL_LANG_SPECIFIC (t
))
1271 if (DECL_ABSTRACT_ORIGIN (t
)
1272 && DECL_ABSTRACT_ORIGIN (t
) != t
)
1273 dump_decl (pp
, DECL_ABSTRACT_ORIGIN (t
), flags
);
1275 dump_function_name (pp
, t
, flags
);
1277 else if (DECL_GLOBAL_CTOR_P (t
) || DECL_GLOBAL_DTOR_P (t
))
1278 dump_global_iord (pp
, t
);
1280 dump_function_decl (pp
, t
, flags
);
1284 dump_template_decl (pp
, t
, flags
);
1287 case TEMPLATE_ID_EXPR
:
1289 tree name
= TREE_OPERAND (t
, 0);
1290 tree args
= TREE_OPERAND (t
, 1);
1292 if (!identifier_p (name
))
1293 name
= OVL_NAME (name
);
1294 dump_decl (pp
, name
, flags
);
1295 pp_cxx_begin_template_argument_list (pp
);
1296 if (args
== error_mark_node
)
1297 pp_string (pp
, M_("<template arguments error>"));
1299 dump_template_argument_list
1300 (pp
, args
, flags
|TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS
);
1301 pp_cxx_end_template_argument_list (pp
);
1306 pp_cxx_tree_identifier (pp
, DECL_NAME (t
));
1310 if ((TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == ENUMERAL_TYPE
)
1311 || (DECL_INITIAL (t
) &&
1312 TREE_CODE (DECL_INITIAL (t
)) == TEMPLATE_PARM_INDEX
))
1313 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1314 else if (DECL_NAME (t
))
1315 dump_decl (pp
, DECL_NAME (t
), flags
);
1316 else if (DECL_INITIAL (t
))
1317 dump_expr (pp
, DECL_INITIAL (t
), flags
| TFF_EXPR_IN_PARENS
);
1319 pp_string (pp
, M_("<enumerator>"));
1324 pp_cxx_ws_string (pp
, "using");
1325 tree scope
= USING_DECL_SCOPE (t
);
1326 bool variadic
= false;
1327 if (PACK_EXPANSION_P (scope
))
1329 scope
= PACK_EXPANSION_PATTERN (scope
);
1332 dump_type (pp
, scope
, flags
);
1333 pp_cxx_colon_colon (pp
);
1334 dump_decl (pp
, DECL_NAME (t
), flags
);
1336 pp_cxx_ws_string (pp
, "...");
1341 pp
->declaration (t
);
1345 dump_decl (pp
, BASELINK_FUNCTIONS (t
), flags
);
1348 case NON_DEPENDENT_EXPR
:
1349 dump_expr (pp
, t
, flags
);
1352 case TEMPLATE_TYPE_PARM
:
1353 if (flags
& TFF_DECL_SPECIFIERS
)
1354 pp
->declaration (t
);
1359 case UNBOUND_CLASS_TEMPLATE
:
1360 case TYPE_PACK_EXPANSION
:
1362 dump_type (pp
, t
, flags
);
1366 pp_unsupported_tree (pp
, t
);
1370 pp_string (pp
, M_("<declaration error>"));
1375 /* Dump a template declaration T under control of FLAGS. This means the
1376 'template <...> leaders plus the 'class X' or 'void fn(...)' part. */
1379 dump_template_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
1381 tree orig_parms
= DECL_TEMPLATE_PARMS (t
);
1385 if (flags
& TFF_TEMPLATE_HEADER
)
1387 for (parms
= orig_parms
= nreverse (orig_parms
);
1389 parms
= TREE_CHAIN (parms
))
1391 tree inner_parms
= INNERMOST_TEMPLATE_PARMS (parms
);
1392 int len
= TREE_VEC_LENGTH (inner_parms
);
1396 /* Skip over the dummy template levels of a template template
1398 gcc_assert (TREE_CODE (TREE_TYPE (t
)) == TEMPLATE_TEMPLATE_PARM
);
1402 pp_cxx_ws_string (pp
, "template");
1403 pp_cxx_begin_template_argument_list (pp
);
1405 /* If we've shown the template prefix, we'd better show the
1406 parameters' and decl's type too. */
1407 flags
|= TFF_DECL_SPECIFIERS
;
1409 for (i
= 0; i
< len
; i
++)
1412 pp_separate_with_comma (pp
);
1413 dump_template_parameter (pp
, TREE_VEC_ELT (inner_parms
, i
),
1416 pp_cxx_end_template_argument_list (pp
);
1417 pp_cxx_whitespace (pp
);
1419 nreverse(orig_parms
);
1421 if (DECL_TEMPLATE_TEMPLATE_PARM_P (t
))
1423 /* Say `template<arg> class TT' not just `template<arg> TT'. */
1424 pp_cxx_ws_string (pp
, "class");
1426 /* If this is a parameter pack, print the ellipsis. */
1427 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t
)))
1428 pp_cxx_ws_string (pp
, "...");
1431 /* Only print the requirements if we're also printing
1432 the template header. */
1434 if (tree ci
= get_constraints (t
))
1435 if (check_constraint_info (ci
))
1436 if (tree reqs
= CI_TEMPLATE_REQS (ci
))
1438 pp_cxx_requires_clause (pp
, reqs
);
1439 pp_cxx_whitespace (pp
);
1444 if (DECL_CLASS_TEMPLATE_P (t
))
1445 dump_type (pp
, TREE_TYPE (t
),
1446 ((flags
& ~TFF_CLASS_KEY_OR_ENUM
) | TFF_TEMPLATE_NAME
1447 | (flags
& TFF_DECL_SPECIFIERS
? TFF_CLASS_KEY_OR_ENUM
: 0)));
1448 else if (DECL_TEMPLATE_RESULT (t
)
1449 && (VAR_P (DECL_TEMPLATE_RESULT (t
))
1450 /* Alias template. */
1451 || DECL_TYPE_TEMPLATE_P (t
)))
1452 dump_decl (pp
, DECL_TEMPLATE_RESULT (t
), flags
| TFF_TEMPLATE_NAME
);
1455 gcc_assert (TREE_TYPE (t
));
1456 switch (NEXT_CODE (t
))
1460 dump_function_decl (pp
, t
, flags
| TFF_TEMPLATE_NAME
);
1463 /* This case can occur with some invalid code. */
1464 dump_type (pp
, TREE_TYPE (t
),
1465 (flags
& ~TFF_CLASS_KEY_OR_ENUM
) | TFF_TEMPLATE_NAME
1466 | (flags
& TFF_DECL_SPECIFIERS
1467 ? TFF_CLASS_KEY_OR_ENUM
: 0));
1472 /* find_typenames looks through the type of the function template T
1473 and returns a vec containing any typedefs, decltypes or TYPENAME_TYPEs
1476 struct find_typenames_t
1478 hash_set
<tree
> *p_set
;
1479 vec
<tree
, va_gc
> *typenames
;
1483 find_typenames_r (tree
*tp
, int *walk_subtrees
, void *data
)
1485 struct find_typenames_t
*d
= (struct find_typenames_t
*)data
;
1486 tree mv
= NULL_TREE
;
1488 if (TYPE_P (*tp
) && is_typedef_decl (TYPE_NAME (*tp
)))
1489 /* Add the type of the typedef without any additional cv-quals. */
1490 mv
= TREE_TYPE (TYPE_NAME (*tp
));
1491 else if (TREE_CODE (*tp
) == TYPENAME_TYPE
1492 || TREE_CODE (*tp
) == DECLTYPE_TYPE
)
1493 /* Add the typename without any cv-qualifiers. */
1494 mv
= TYPE_MAIN_VARIANT (*tp
);
1496 if (PACK_EXPANSION_P (*tp
))
1498 /* Don't mess with parameter packs since we don't remember
1499 the pack expansion context for a particular typename. */
1500 *walk_subtrees
= false;
1504 if (mv
&& (mv
== *tp
|| !d
->p_set
->add (mv
)))
1505 vec_safe_push (d
->typenames
, mv
);
1507 /* Search into class template arguments, which cp_walk_subtrees
1509 if (CLASS_TYPE_P (*tp
) && CLASSTYPE_TEMPLATE_INFO (*tp
))
1510 cp_walk_tree (&CLASSTYPE_TI_ARGS (*tp
), find_typenames_r
,
1516 static vec
<tree
, va_gc
> *
1517 find_typenames (tree t
)
1519 struct find_typenames_t ft
;
1520 ft
.p_set
= new hash_set
<tree
>;
1521 ft
.typenames
= NULL
;
1522 cp_walk_tree (&TREE_TYPE (DECL_TEMPLATE_RESULT (t
)),
1523 find_typenames_r
, &ft
, ft
.p_set
);
1525 return ft
.typenames
;
1528 /* Output the "[with ...]" clause for a template instantiation T iff
1529 TEMPLATE_PARMS, TEMPLATE_ARGS and FLAGS are suitable. T may be NULL if
1530 formatting a deduction/substitution diagnostic rather than an
1534 dump_substitution (cxx_pretty_printer
*pp
,
1535 tree t
, tree template_parms
, tree template_args
,
1538 if (template_parms
!= NULL_TREE
&& template_args
!= NULL_TREE
1539 && !(flags
& TFF_NO_TEMPLATE_BINDINGS
))
1541 vec
<tree
, va_gc
> *typenames
= t
? find_typenames (t
) : NULL
;
1542 pp_cxx_whitespace (pp
);
1543 pp_cxx_left_bracket (pp
);
1544 pp
->translate_string ("with");
1545 pp_cxx_whitespace (pp
);
1546 dump_template_bindings (pp
, template_parms
, template_args
, typenames
);
1547 pp_cxx_right_bracket (pp
);
1551 /* Dump the lambda function FN including its 'mutable' qualifier and any
1552 template bindings. */
1555 dump_lambda_function (cxx_pretty_printer
*pp
,
1556 tree fn
, tree template_parms
, tree template_args
,
1559 /* A lambda's signature is essentially its "type". */
1560 dump_type (pp
, DECL_CONTEXT (fn
), flags
);
1561 if (!(TYPE_QUALS (class_of_this_parm (TREE_TYPE (fn
))) & TYPE_QUAL_CONST
))
1563 pp
->padding
= pp_before
;
1564 pp_c_ws_string (pp
, "mutable");
1566 dump_substitution (pp
, fn
, template_parms
, template_args
, flags
);
1569 /* Pretty print a function decl. There are several ways we want to print a
1570 function declaration. The TFF_ bits in FLAGS tells us how to behave.
1571 As error can only apply the '#' flag once to give 0 and 1 for V, there
1572 is %D which doesn't print the throw specs, and %F which does. */
1575 dump_function_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
1579 tree cname
= NULL_TREE
;
1580 tree template_args
= NULL_TREE
;
1581 tree template_parms
= NULL_TREE
;
1582 int show_return
= flags
& TFF_RETURN_TYPE
|| flags
& TFF_DECL_SPECIFIERS
;
1583 int do_outer_scope
= ! (flags
& TFF_UNQUALIFIED_NAME
);
1586 tree ret
= NULL_TREE
;
1588 flags
&= ~(TFF_UNQUALIFIED_NAME
| TFF_TEMPLATE_NAME
);
1589 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1590 t
= DECL_TEMPLATE_RESULT (t
);
1592 /* Save the exceptions, in case t is a specialization and we are
1593 emitting an error about incompatible specifications. */
1594 exceptions
= TYPE_RAISES_EXCEPTIONS (TREE_TYPE (t
));
1596 /* Likewise for the constexpr specifier, in case t is a specialization. */
1597 constexpr_p
= DECL_DECLARED_CONSTEXPR_P (t
);
1599 /* Pretty print template instantiations only. */
1600 if (DECL_USE_TEMPLATE (t
) && DECL_TEMPLATE_INFO (t
)
1601 && !(flags
& TFF_NO_TEMPLATE_BINDINGS
)
1602 && flag_pretty_templates
)
1606 template_args
= DECL_TI_ARGS (t
);
1607 tmpl
= most_general_template (t
);
1608 if (tmpl
&& TREE_CODE (tmpl
) == TEMPLATE_DECL
)
1610 template_parms
= DECL_TEMPLATE_PARMS (tmpl
);
1615 if (DECL_NAME (t
) && LAMBDA_FUNCTION_P (t
))
1616 return dump_lambda_function (pp
, t
, template_parms
, template_args
, flags
);
1618 fntype
= TREE_TYPE (t
);
1619 parmtypes
= FUNCTION_FIRST_USER_PARMTYPE (t
);
1621 if (DECL_CLASS_SCOPE_P (t
))
1622 cname
= DECL_CONTEXT (t
);
1623 /* This is for partially instantiated template methods. */
1624 else if (TREE_CODE (fntype
) == METHOD_TYPE
)
1625 cname
= TREE_TYPE (TREE_VALUE (parmtypes
));
1627 if (flags
& TFF_DECL_SPECIFIERS
)
1629 if (DECL_STATIC_FUNCTION_P (t
))
1630 pp_cxx_ws_string (pp
, "static");
1631 else if (DECL_VIRTUAL_P (t
))
1632 pp_cxx_ws_string (pp
, "virtual");
1636 if (DECL_DECLARED_CONCEPT_P (t
))
1637 pp_cxx_ws_string (pp
, "concept");
1639 pp_cxx_ws_string (pp
, "constexpr");
1643 /* Print the return type? */
1645 show_return
= (!DECL_CONV_FN_P (t
) && !DECL_CONSTRUCTOR_P (t
)
1646 && !DECL_DESTRUCTOR_P (t
) && !deduction_guide_p (t
));
1649 ret
= fndecl_declared_return_type (t
);
1650 dump_type_prefix (pp
, ret
, flags
);
1653 /* Print the function name. */
1654 if (!do_outer_scope
)
1658 dump_type (pp
, cname
, flags
);
1659 pp_cxx_colon_colon (pp
);
1662 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1664 dump_function_name (pp
, t
, flags
);
1666 if (!(flags
& TFF_NO_FUNCTION_ARGUMENTS
))
1668 dump_parameters (pp
, parmtypes
, flags
);
1670 if (TREE_CODE (fntype
) == METHOD_TYPE
)
1672 pp
->padding
= pp_before
;
1673 pp_cxx_cv_qualifier_seq (pp
, class_of_this_parm (fntype
));
1674 dump_ref_qualifier (pp
, fntype
, flags
);
1677 if (tx_safe_fn_type_p (fntype
))
1679 pp
->padding
= pp_before
;
1680 pp_cxx_ws_string (pp
, "transaction_safe");
1683 if (flags
& TFF_EXCEPTION_SPECIFICATION
)
1685 pp
->padding
= pp_before
;
1686 dump_exception_spec (pp
, exceptions
, flags
);
1690 dump_type_suffix (pp
, ret
, flags
);
1691 else if (deduction_guide_p (t
))
1693 pp_cxx_ws_string (pp
, "->");
1694 dump_type (pp
, TREE_TYPE (TREE_TYPE (t
)), flags
);
1698 if (tree ci
= get_constraints (t
))
1699 if (tree reqs
= CI_DECLARATOR_REQS (ci
))
1700 pp_cxx_requires_clause (pp
, reqs
);
1702 dump_substitution (pp
, t
, template_parms
, template_args
, flags
);
1704 if (tree base
= DECL_INHERITED_CTOR_BASE (t
))
1706 pp_cxx_ws_string (pp
, "[inherited from");
1707 dump_type (pp
, base
, TFF_PLAIN_IDENTIFIER
);
1708 pp_character (pp
, ']');
1711 else if (template_args
)
1713 bool need_comma
= false;
1715 pp_cxx_begin_template_argument_list (pp
);
1716 template_args
= INNERMOST_TEMPLATE_ARGS (template_args
);
1717 for (i
= 0; i
< TREE_VEC_LENGTH (template_args
); ++i
)
1719 tree arg
= TREE_VEC_ELT (template_args
, i
);
1721 pp_separate_with_comma (pp
);
1722 if (ARGUMENT_PACK_P (arg
))
1723 pp_cxx_left_brace (pp
);
1724 dump_template_argument (pp
, arg
, TFF_PLAIN_IDENTIFIER
);
1725 if (ARGUMENT_PACK_P (arg
))
1726 pp_cxx_right_brace (pp
);
1729 pp_cxx_end_template_argument_list (pp
);
1733 /* Print a parameter list. If this is for a member function, the
1734 member object ptr (and any other hidden args) should have
1735 already been removed. */
1738 dump_parameters (cxx_pretty_printer
*pp
, tree parmtypes
, int flags
)
1741 flags
&= ~TFF_SCOPE
;
1742 pp_cxx_left_paren (pp
);
1744 for (first
= 1; parmtypes
!= void_list_node
;
1745 parmtypes
= TREE_CHAIN (parmtypes
))
1748 pp_separate_with_comma (pp
);
1752 pp_cxx_ws_string (pp
, "...");
1756 dump_type (pp
, TREE_VALUE (parmtypes
), flags
);
1758 if ((flags
& TFF_FUNCTION_DEFAULT_ARGUMENTS
) && TREE_PURPOSE (parmtypes
))
1760 pp_cxx_whitespace (pp
);
1762 pp_cxx_whitespace (pp
);
1763 dump_expr (pp
, TREE_PURPOSE (parmtypes
), flags
| TFF_EXPR_IN_PARENS
);
1767 pp_cxx_right_paren (pp
);
1770 /* Print ref-qualifier of a FUNCTION_TYPE or METHOD_TYPE. FLAGS are ignored. */
1773 dump_ref_qualifier (cxx_pretty_printer
*pp
, tree t
, int flags ATTRIBUTE_UNUSED
)
1775 if (FUNCTION_REF_QUALIFIED (t
))
1777 pp
->padding
= pp_before
;
1778 if (FUNCTION_RVALUE_QUALIFIED (t
))
1779 pp_cxx_ws_string (pp
, "&&");
1781 pp_cxx_ws_string (pp
, "&");
1785 /* Print an exception specification. T is the exception specification. */
1788 dump_exception_spec (cxx_pretty_printer
*pp
, tree t
, int flags
)
1790 if (t
&& TREE_PURPOSE (t
))
1792 pp_cxx_ws_string (pp
, "noexcept");
1793 if (!integer_onep (TREE_PURPOSE (t
)))
1795 pp_cxx_whitespace (pp
);
1796 pp_cxx_left_paren (pp
);
1797 if (DEFERRED_NOEXCEPT_SPEC_P (t
))
1798 pp_cxx_ws_string (pp
, "<uninstantiated>");
1800 dump_expr (pp
, TREE_PURPOSE (t
), flags
);
1801 pp_cxx_right_paren (pp
);
1806 pp_cxx_ws_string (pp
, "throw");
1807 pp_cxx_whitespace (pp
);
1808 pp_cxx_left_paren (pp
);
1809 if (TREE_VALUE (t
) != NULL_TREE
)
1812 dump_type (pp
, TREE_VALUE (t
), flags
);
1816 pp_separate_with_comma (pp
);
1818 pp_cxx_right_paren (pp
);
1822 /* Handle the function name for a FUNCTION_DECL node, grokking operators
1823 and destructors properly. */
1826 dump_function_name (cxx_pretty_printer
*pp
, tree t
, int flags
)
1828 tree name
= DECL_NAME (t
);
1830 /* We can get here with a decl that was synthesized by language-
1831 independent machinery (e.g. coverage.c) in which case it won't
1832 have a lang_specific structure attached and DECL_CONSTRUCTOR_P
1833 will crash. In this case it is safe just to print out the
1835 if (!DECL_LANG_SPECIFIC (t
))
1837 pp_cxx_tree_identifier (pp
, name
);
1841 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1842 t
= DECL_TEMPLATE_RESULT (t
);
1844 /* Don't let the user see __comp_ctor et al. */
1845 if (DECL_CONSTRUCTOR_P (t
)
1846 || DECL_DESTRUCTOR_P (t
))
1848 if (LAMBDA_TYPE_P (DECL_CONTEXT (t
)))
1849 name
= get_identifier ("<lambda>");
1850 else if (TYPE_UNNAMED_P (DECL_CONTEXT (t
)))
1851 name
= get_identifier ("<constructor>");
1853 name
= constructor_name (DECL_CONTEXT (t
));
1856 if (DECL_DESTRUCTOR_P (t
))
1858 pp_cxx_complement (pp
);
1859 dump_decl (pp
, name
, TFF_PLAIN_IDENTIFIER
);
1861 else if (DECL_CONV_FN_P (t
))
1863 /* This cannot use the hack that the operator's return
1864 type is stashed off of its name because it may be
1865 used for error reporting. In the case of conflicting
1866 declarations, both will have the same name, yet
1867 the types will be different, hence the TREE_TYPE field
1868 of the first name will be clobbered by the second. */
1869 pp_cxx_ws_string (pp
, "operator");
1870 dump_type (pp
, TREE_TYPE (TREE_TYPE (t
)), flags
);
1873 dump_decl (pp
, name
, flags
);
1875 if (DECL_TEMPLATE_INFO (t
)
1876 && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t
)
1877 && (TREE_CODE (DECL_TI_TEMPLATE (t
)) != TEMPLATE_DECL
1878 || PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t
))))
1879 dump_template_parms (pp
, DECL_TEMPLATE_INFO (t
), !DECL_USE_TEMPLATE (t
),
1883 /* Dump the template parameters from the template info INFO under control of
1884 FLAGS. PRIMARY indicates whether this is a primary template decl, or
1885 specialization (partial or complete). For partial specializations we show
1886 the specialized parameter values. For a primary template we show no
1890 dump_template_parms (cxx_pretty_printer
*pp
, tree info
,
1891 int primary
, int flags
)
1893 tree args
= info
? TI_ARGS (info
) : NULL_TREE
;
1895 if (primary
&& flags
& TFF_TEMPLATE_NAME
)
1897 flags
&= ~(TFF_CLASS_KEY_OR_ENUM
| TFF_TEMPLATE_NAME
);
1898 pp_cxx_begin_template_argument_list (pp
);
1900 /* Be careful only to print things when we have them, so as not
1901 to crash producing error messages. */
1902 if (args
&& !primary
)
1905 len
= get_non_default_template_args_count (args
, flags
);
1907 args
= INNERMOST_TEMPLATE_ARGS (args
);
1908 for (ix
= 0; ix
!= len
; ix
++)
1910 tree arg
= TREE_VEC_ELT (args
, ix
);
1912 /* Only print a comma if we know there is an argument coming. In
1913 the case of an empty template argument pack, no actual
1914 argument will be printed. */
1916 && (!ARGUMENT_PACK_P (arg
)
1917 || TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg
)) > 0))
1918 pp_separate_with_comma (pp
);
1921 pp_string (pp
, M_("<template parameter error>"));
1923 dump_template_argument (pp
, arg
, flags
);
1928 tree tpl
= TI_TEMPLATE (info
);
1929 tree parms
= DECL_TEMPLATE_PARMS (tpl
);
1932 parms
= TREE_CODE (parms
) == TREE_LIST
? TREE_VALUE (parms
) : NULL_TREE
;
1933 len
= parms
? TREE_VEC_LENGTH (parms
) : 0;
1935 for (ix
= 0; ix
!= len
; ix
++)
1939 if (TREE_VEC_ELT (parms
, ix
) == error_mark_node
)
1941 pp_string (pp
, M_("<template parameter error>"));
1945 parm
= TREE_VALUE (TREE_VEC_ELT (parms
, ix
));
1948 pp_separate_with_comma (pp
);
1950 dump_decl (pp
, parm
, flags
& ~TFF_DECL_SPECIFIERS
);
1953 pp_cxx_end_template_argument_list (pp
);
1956 /* Print out the arguments of CALL_EXPR T as a parenthesized list using
1957 flags FLAGS. Skip over the first argument if SKIPFIRST is true. */
1960 dump_call_expr_args (cxx_pretty_printer
*pp
, tree t
, int flags
, bool skipfirst
)
1963 call_expr_arg_iterator iter
;
1965 pp_cxx_left_paren (pp
);
1966 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, t
)
1972 dump_expr (pp
, arg
, flags
| TFF_EXPR_IN_PARENS
);
1973 if (more_call_expr_args_p (&iter
))
1974 pp_separate_with_comma (pp
);
1977 pp_cxx_right_paren (pp
);
1980 /* Print out the arguments of AGGR_INIT_EXPR T as a parenthesized list
1981 using flags FLAGS. Skip over the first argument if SKIPFIRST is
1985 dump_aggr_init_expr_args (cxx_pretty_printer
*pp
, tree t
, int flags
,
1989 aggr_init_expr_arg_iterator iter
;
1991 pp_cxx_left_paren (pp
);
1992 FOR_EACH_AGGR_INIT_EXPR_ARG (arg
, iter
, t
)
1998 dump_expr (pp
, arg
, flags
| TFF_EXPR_IN_PARENS
);
1999 if (more_aggr_init_expr_args_p (&iter
))
2000 pp_separate_with_comma (pp
);
2003 pp_cxx_right_paren (pp
);
2006 /* Print out a list of initializers (subr of dump_expr). */
2009 dump_expr_list (cxx_pretty_printer
*pp
, tree l
, int flags
)
2013 dump_expr (pp
, TREE_VALUE (l
), flags
| TFF_EXPR_IN_PARENS
);
2016 pp_separate_with_comma (pp
);
2020 /* Print out a vector of initializers (subr of dump_expr). */
2023 dump_expr_init_vec (cxx_pretty_printer
*pp
, vec
<constructor_elt
, va_gc
> *v
,
2026 unsigned HOST_WIDE_INT idx
;
2029 FOR_EACH_CONSTRUCTOR_VALUE (v
, idx
, value
)
2031 dump_expr (pp
, value
, flags
| TFF_EXPR_IN_PARENS
);
2032 if (idx
!= v
->length () - 1)
2033 pp_separate_with_comma (pp
);
2038 /* We've gotten an indirect REFERENCE (an OBJ_TYPE_REF) to a virtual
2039 function. Resolve it to a close relative -- in the sense of static
2040 type -- variant being overridden. That is close to what was written in
2041 the source code. Subroutine of dump_expr. */
2044 resolve_virtual_fun_from_obj_type_ref (tree ref
)
2046 tree obj_type
= TREE_TYPE (OBJ_TYPE_REF_OBJECT (ref
));
2047 HOST_WIDE_INT index
= tree_to_uhwi (OBJ_TYPE_REF_TOKEN (ref
));
2048 tree fun
= BINFO_VIRTUALS (TYPE_BINFO (TREE_TYPE (obj_type
)));
2051 fun
= TREE_CHAIN (fun
);
2052 index
-= (TARGET_VTABLE_USES_DESCRIPTORS
2053 ? TARGET_VTABLE_USES_DESCRIPTORS
: 1);
2059 /* Print out an expression E under control of FLAGS. */
2062 dump_expr (cxx_pretty_printer
*pp
, tree t
, int flags
)
2069 if (STATEMENT_CLASS_P (t
))
2071 pp_cxx_ws_string (pp
, M_("<statement>"));
2075 switch (TREE_CODE (t
))
2083 case NAMESPACE_DECL
:
2087 case IDENTIFIER_NODE
:
2088 dump_decl (pp
, t
, ((flags
& ~(TFF_DECL_SPECIFIERS
|TFF_RETURN_TYPE
2089 |TFF_TEMPLATE_HEADER
))
2090 | TFF_NO_TEMPLATE_BINDINGS
2091 | TFF_NO_FUNCTION_ARGUMENTS
));
2095 if (SSA_NAME_VAR (t
)
2096 && !DECL_ARTIFICIAL (SSA_NAME_VAR (t
)))
2097 dump_expr (pp
, SSA_NAME_VAR (t
), flags
);
2099 pp_cxx_ws_string (pp
, M_("<unknown>"));
2110 case USERDEF_LITERAL
:
2111 pp_cxx_userdef_literal (pp
, t
);
2115 /* While waiting for caret diagnostics, avoid printing
2116 __cxa_allocate_exception, __cxa_throw, and the like. */
2117 pp_cxx_ws_string (pp
, M_("<throw-expression>"));
2122 dump_type (pp
, PTRMEM_CST_CLASS (t
), flags
);
2123 pp_cxx_colon_colon (pp
);
2124 pp_cxx_tree_identifier (pp
, DECL_NAME (PTRMEM_CST_MEMBER (t
)));
2128 pp_cxx_left_paren (pp
);
2129 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2130 pp_separate_with_comma (pp
);
2131 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2132 pp_cxx_right_paren (pp
);
2137 pp_cxx_left_paren (pp
);
2138 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2139 pp_string (pp
, " ? ");
2140 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2141 pp_string (pp
, " : ");
2142 dump_expr (pp
, TREE_OPERAND (t
, 2), flags
| TFF_EXPR_IN_PARENS
);
2143 pp_cxx_right_paren (pp
);
2147 if (TREE_HAS_CONSTRUCTOR (t
))
2149 pp_cxx_ws_string (pp
, "new");
2150 pp_cxx_whitespace (pp
);
2151 dump_type (pp
, TREE_TYPE (TREE_TYPE (t
)), flags
);
2154 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2157 case AGGR_INIT_EXPR
:
2159 tree fn
= NULL_TREE
;
2161 if (TREE_CODE (AGGR_INIT_EXPR_FN (t
)) == ADDR_EXPR
)
2162 fn
= TREE_OPERAND (AGGR_INIT_EXPR_FN (t
), 0);
2164 if (fn
&& TREE_CODE (fn
) == FUNCTION_DECL
)
2166 if (DECL_CONSTRUCTOR_P (fn
))
2167 dump_type (pp
, DECL_CONTEXT (fn
), flags
);
2169 dump_decl (pp
, fn
, 0);
2172 dump_expr (pp
, AGGR_INIT_EXPR_FN (t
), 0);
2174 dump_aggr_init_expr_args (pp
, t
, flags
, true);
2179 tree fn
= CALL_EXPR_FN (t
);
2180 bool skipfirst
= false;
2182 /* Deal with internal functions. */
2183 if (fn
== NULL_TREE
)
2185 pp_string (pp
, internal_fn_name (CALL_EXPR_IFN (t
)));
2186 dump_call_expr_args (pp
, t
, flags
, skipfirst
);
2190 if (TREE_CODE (fn
) == ADDR_EXPR
)
2191 fn
= TREE_OPERAND (fn
, 0);
2193 /* Nobody is interested in seeing the guts of vcalls. */
2194 if (TREE_CODE (fn
) == OBJ_TYPE_REF
)
2195 fn
= resolve_virtual_fun_from_obj_type_ref (fn
);
2197 if (TREE_TYPE (fn
) != NULL_TREE
2198 && NEXT_CODE (fn
) == METHOD_TYPE
2199 && call_expr_nargs (t
))
2201 tree ob
= CALL_EXPR_ARG (t
, 0);
2202 if (TREE_CODE (ob
) == ADDR_EXPR
)
2204 dump_expr (pp
, TREE_OPERAND (ob
, 0),
2205 flags
| TFF_EXPR_IN_PARENS
);
2208 else if (!is_this_parameter (ob
))
2210 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2215 if (flag_sanitize
& SANITIZE_UNDEFINED
2216 && is_ubsan_builtin_p (fn
))
2218 pp_string (cxx_pp
, M_("<ubsan routine call>"));
2221 dump_expr (pp
, fn
, flags
| TFF_EXPR_IN_PARENS
);
2222 dump_call_expr_args (pp
, t
, flags
, skipfirst
);
2227 /* Note that this only works for G++ target exprs. If somebody
2228 builds a general TARGET_EXPR, there's no way to represent that
2229 it initializes anything other that the parameter slot for the
2230 default argument. Note we may have cleared out the first
2231 operand in expand_expr, so don't go killing ourselves. */
2232 if (TREE_OPERAND (t
, 1))
2233 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2236 case POINTER_PLUS_EXPR
:
2237 dump_binary_op (pp
, "+", t
, flags
);
2240 case POINTER_DIFF_EXPR
:
2241 dump_binary_op (pp
, "-", t
, flags
);
2246 dump_binary_op (pp
, OVL_OP_INFO (true, NOP_EXPR
)->name
, t
, flags
);
2252 case TRUNC_DIV_EXPR
:
2253 case TRUNC_MOD_EXPR
:
2261 case TRUTH_ANDIF_EXPR
:
2262 case TRUTH_ORIF_EXPR
:
2269 case EXACT_DIV_EXPR
:
2270 dump_binary_op (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
, t
, flags
);
2274 case FLOOR_DIV_EXPR
:
2275 case ROUND_DIV_EXPR
:
2277 dump_binary_op (pp
, "/", t
, flags
);
2281 case FLOOR_MOD_EXPR
:
2282 case ROUND_MOD_EXPR
:
2283 dump_binary_op (pp
, "%", t
, flags
);
2288 tree ob
= TREE_OPERAND (t
, 0);
2289 if (INDIRECT_REF_P (ob
))
2291 ob
= TREE_OPERAND (ob
, 0);
2292 if (!is_this_parameter (ob
))
2294 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2295 if (TYPE_REF_P (TREE_TYPE (ob
)))
2303 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2304 if (TREE_CODE (ob
) != ARROW_EXPR
)
2307 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
& ~TFF_EXPR_IN_PARENS
);
2312 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2313 pp_cxx_left_bracket (pp
);
2314 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2315 pp_cxx_right_bracket (pp
);
2318 case UNARY_PLUS_EXPR
:
2319 dump_unary_op (pp
, "+", t
, flags
);
2323 if (TREE_CODE (TREE_OPERAND (t
, 0)) == FUNCTION_DECL
2324 || TREE_CODE (TREE_OPERAND (t
, 0)) == STRING_CST
2325 /* An ADDR_EXPR can have reference type. In that case, we
2326 shouldn't print the `&' doing so indicates to the user
2327 that the expression has pointer type. */
2329 && TYPE_REF_P (TREE_TYPE (t
))))
2330 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2331 else if (TREE_CODE (TREE_OPERAND (t
, 0)) == LABEL_DECL
)
2332 dump_unary_op (pp
, "&&", t
, flags
);
2334 dump_unary_op (pp
, "&", t
, flags
);
2338 if (TREE_HAS_CONSTRUCTOR (t
))
2340 t
= TREE_OPERAND (t
, 0);
2341 gcc_assert (TREE_CODE (t
) == CALL_EXPR
);
2342 dump_expr (pp
, CALL_EXPR_FN (t
), flags
| TFF_EXPR_IN_PARENS
);
2343 dump_call_expr_args (pp
, t
, flags
, true);
2347 if (TREE_OPERAND (t
,0) != NULL_TREE
2348 && TREE_TYPE (TREE_OPERAND (t
, 0))
2349 && NEXT_CODE (TREE_OPERAND (t
, 0)) == REFERENCE_TYPE
)
2350 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2352 dump_unary_op (pp
, "*", t
, flags
);
2357 if (TREE_CODE (TREE_OPERAND (t
, 0)) == ADDR_EXPR
2358 && integer_zerop (TREE_OPERAND (t
, 1)))
2359 dump_expr (pp
, TREE_OPERAND (TREE_OPERAND (t
, 0), 0), flags
);
2363 if (!integer_zerop (TREE_OPERAND (t
, 1)))
2365 pp_cxx_left_paren (pp
);
2366 if (!integer_onep (TYPE_SIZE_UNIT
2367 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (t
, 0))))))
2369 pp_cxx_left_paren (pp
);
2370 dump_type (pp
, ptr_type_node
, flags
);
2371 pp_cxx_right_paren (pp
);
2374 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2375 if (!integer_zerop (TREE_OPERAND (t
, 1)))
2377 pp_cxx_ws_string (pp
, "+");
2378 dump_expr (pp
, fold_convert (ssizetype
, TREE_OPERAND (t
, 1)),
2380 pp_cxx_right_paren (pp
);
2387 case TRUTH_NOT_EXPR
:
2388 case PREDECREMENT_EXPR
:
2389 case PREINCREMENT_EXPR
:
2390 dump_unary_op (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
, t
, flags
);
2393 case POSTDECREMENT_EXPR
:
2394 case POSTINCREMENT_EXPR
:
2395 pp_cxx_left_paren (pp
);
2396 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2397 pp_cxx_ws_string (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
);
2398 pp_cxx_right_paren (pp
);
2401 case NON_LVALUE_EXPR
:
2402 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
2403 should be another level of INDIRECT_REF so that I don't have to do
2405 if (TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == POINTER_TYPE
)
2407 tree next
= TREE_TYPE (TREE_TYPE (t
));
2409 while (TYPE_PTR_P (next
))
2410 next
= TREE_TYPE (next
);
2412 if (TREE_CODE (next
) == FUNCTION_TYPE
)
2414 if (flags
& TFF_EXPR_IN_PARENS
)
2415 pp_cxx_left_paren (pp
);
2417 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2418 if (flags
& TFF_EXPR_IN_PARENS
)
2419 pp_cxx_right_paren (pp
);
2422 /* Else fall through. */
2424 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2428 case IMPLICIT_CONV_EXPR
:
2429 case VIEW_CONVERT_EXPR
:
2431 tree op
= TREE_OPERAND (t
, 0);
2432 tree ttype
= TREE_TYPE (t
);
2433 tree optype
= TREE_TYPE (op
);
2435 if (TREE_CODE (ttype
) != TREE_CODE (optype
)
2436 && INDIRECT_TYPE_P (ttype
)
2437 && INDIRECT_TYPE_P (optype
)
2438 && same_type_p (TREE_TYPE (optype
),
2441 if (TYPE_REF_P (ttype
))
2444 if (TREE_CODE (op
) == ADDR_EXPR
)
2445 dump_expr (pp
, TREE_OPERAND (op
, 0), flags
);
2447 dump_unary_op (pp
, "*", t
, flags
);
2450 dump_unary_op (pp
, "&", t
, flags
);
2452 else if (!same_type_p (TREE_TYPE (op
), TREE_TYPE (t
)))
2454 /* It is a cast, but we cannot tell whether it is a
2455 reinterpret or static cast. Use the C style notation. */
2456 if (flags
& TFF_EXPR_IN_PARENS
)
2457 pp_cxx_left_paren (pp
);
2458 pp_cxx_left_paren (pp
);
2459 dump_type (pp
, TREE_TYPE (t
), flags
);
2460 pp_cxx_right_paren (pp
);
2461 dump_expr (pp
, op
, flags
| TFF_EXPR_IN_PARENS
);
2462 if (flags
& TFF_EXPR_IN_PARENS
)
2463 pp_cxx_right_paren (pp
);
2466 dump_expr (pp
, op
, flags
);
2471 if (TREE_TYPE (t
) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t
)))
2473 tree idx
= build_ptrmemfunc_access_expr (t
, pfn_identifier
);
2475 if (integer_zerop (idx
))
2477 /* A NULL pointer-to-member constant. */
2478 pp_cxx_left_paren (pp
);
2479 pp_cxx_left_paren (pp
);
2480 dump_type (pp
, TREE_TYPE (t
), flags
);
2481 pp_cxx_right_paren (pp
);
2482 pp_character (pp
, '0');
2483 pp_cxx_right_paren (pp
);
2486 else if (tree_fits_shwi_p (idx
))
2489 unsigned HOST_WIDE_INT n
;
2491 t
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t
)));
2492 t
= TYPE_METHOD_BASETYPE (t
);
2493 virtuals
= BINFO_VIRTUALS (TYPE_BINFO (TYPE_MAIN_VARIANT (t
)));
2495 n
= tree_to_shwi (idx
);
2497 /* Map vtable index back one, to allow for the null pointer to
2501 while (n
> 0 && virtuals
)
2504 virtuals
= TREE_CHAIN (virtuals
);
2508 dump_expr (pp
, BV_FN (virtuals
),
2509 flags
| TFF_EXPR_IN_PARENS
);
2514 if (TREE_TYPE (t
) && LAMBDA_TYPE_P (TREE_TYPE (t
)))
2515 pp_string (pp
, "<lambda closure object>");
2516 if (TREE_TYPE (t
) && EMPTY_CONSTRUCTOR_P (t
))
2518 dump_type (pp
, TREE_TYPE (t
), 0);
2519 pp_cxx_left_paren (pp
);
2520 pp_cxx_right_paren (pp
);
2524 if (!BRACE_ENCLOSED_INITIALIZER_P (t
))
2525 dump_type (pp
, TREE_TYPE (t
), 0);
2526 pp_cxx_left_brace (pp
);
2527 dump_expr_init_vec (pp
, CONSTRUCTOR_ELTS (t
), flags
);
2528 pp_cxx_right_brace (pp
);
2535 tree ob
= TREE_OPERAND (t
, 0);
2536 if (is_dummy_object (ob
))
2538 t
= TREE_OPERAND (t
, 1);
2539 if (TREE_CODE (t
) == FUNCTION_DECL
)
2541 dump_expr (pp
, t
, flags
| TFF_EXPR_IN_PARENS
);
2542 else if (BASELINK_P (t
))
2543 dump_expr (pp
, OVL_FIRST (BASELINK_FUNCTIONS (t
)),
2544 flags
| TFF_EXPR_IN_PARENS
);
2546 dump_decl (pp
, t
, flags
);
2550 if (INDIRECT_REF_P (ob
))
2552 dump_expr (pp
, TREE_OPERAND (ob
, 0), flags
| TFF_EXPR_IN_PARENS
);
2558 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2562 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2567 case TEMPLATE_PARM_INDEX
:
2568 dump_decl (pp
, TEMPLATE_PARM_DECL (t
), flags
& ~TFF_DECL_SPECIFIERS
);
2572 if (TREE_OPERAND (t
, 0) == NULL_TREE
2573 || TREE_CHAIN (TREE_OPERAND (t
, 0)))
2575 dump_type (pp
, TREE_TYPE (t
), flags
);
2576 pp_cxx_left_paren (pp
);
2577 dump_expr_list (pp
, TREE_OPERAND (t
, 0), flags
);
2578 pp_cxx_right_paren (pp
);
2582 pp_cxx_left_paren (pp
);
2583 dump_type (pp
, TREE_TYPE (t
), flags
);
2584 pp_cxx_right_paren (pp
);
2585 pp_cxx_left_paren (pp
);
2586 dump_expr_list (pp
, TREE_OPERAND (t
, 0), flags
);
2587 pp_cxx_right_paren (pp
);
2591 case STATIC_CAST_EXPR
:
2592 pp_cxx_ws_string (pp
, "static_cast");
2594 case REINTERPRET_CAST_EXPR
:
2595 pp_cxx_ws_string (pp
, "reinterpret_cast");
2597 case CONST_CAST_EXPR
:
2598 pp_cxx_ws_string (pp
, "const_cast");
2600 case DYNAMIC_CAST_EXPR
:
2601 pp_cxx_ws_string (pp
, "dynamic_cast");
2603 pp_cxx_begin_template_argument_list (pp
);
2604 dump_type (pp
, TREE_TYPE (t
), flags
);
2605 pp_cxx_end_template_argument_list (pp
);
2606 pp_cxx_left_paren (pp
);
2607 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2608 pp_cxx_right_paren (pp
);
2612 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2618 if (TREE_CODE (t
) == SIZEOF_EXPR
)
2619 pp_cxx_ws_string (pp
, "sizeof");
2622 gcc_assert (TREE_CODE (t
) == ALIGNOF_EXPR
);
2623 pp_cxx_ws_string (pp
, "__alignof__");
2625 op
= TREE_OPERAND (t
, 0);
2626 if (PACK_EXPANSION_P (op
))
2628 pp_string (pp
, "...");
2629 op
= PACK_EXPANSION_PATTERN (op
);
2631 pp_cxx_whitespace (pp
);
2632 pp_cxx_left_paren (pp
);
2633 if (TREE_CODE (t
) == SIZEOF_EXPR
&& SIZEOF_EXPR_TYPE_P (t
))
2634 dump_type (pp
, TREE_TYPE (op
), flags
);
2635 else if (TYPE_P (TREE_OPERAND (t
, 0)))
2636 dump_type (pp
, op
, flags
);
2638 dump_expr (pp
, op
, flags
);
2639 pp_cxx_right_paren (pp
);
2642 case AT_ENCODE_EXPR
:
2643 pp_cxx_ws_string (pp
, "@encode");
2644 pp_cxx_whitespace (pp
);
2645 pp_cxx_left_paren (pp
);
2646 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
2647 pp_cxx_right_paren (pp
);
2651 pp_cxx_ws_string (pp
, "noexcept");
2652 pp_cxx_whitespace (pp
);
2653 pp_cxx_left_paren (pp
);
2654 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2655 pp_cxx_right_paren (pp
);
2660 pp_cxx_ws_string (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
);
2661 pp_cxx_whitespace (pp
);
2662 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2665 case DEFERRED_PARSE
:
2666 pp_string (pp
, M_("<unparsed>"));
2669 case TRY_CATCH_EXPR
:
2670 case CLEANUP_POINT_EXPR
:
2671 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2674 case PSEUDO_DTOR_EXPR
:
2675 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2677 if (TREE_OPERAND (t
, 1))
2679 dump_type (pp
, TREE_OPERAND (t
, 1), flags
);
2680 pp_cxx_colon_colon (pp
);
2682 pp_cxx_complement (pp
);
2683 dump_type (pp
, TREE_OPERAND (t
, 2), flags
);
2686 case TEMPLATE_ID_EXPR
:
2687 dump_decl (pp
, t
, flags
);
2693 case STATEMENT_LIST
:
2694 /* We don't yet have a way of dumping statements in a
2695 human-readable format. */
2696 pp_string (pp
, "({...})");
2700 pp_string (pp
, "while (1) { ");
2701 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2702 pp_cxx_right_brace (pp
);
2706 pp_string (pp
, "if (");
2707 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2708 pp_string (pp
, ") break; ");
2712 dump_expr (pp
, BASELINK_FUNCTIONS (t
), flags
& ~TFF_EXPR_IN_PARENS
);
2715 case EMPTY_CLASS_EXPR
:
2716 dump_type (pp
, TREE_TYPE (t
), flags
);
2717 pp_cxx_left_paren (pp
);
2718 pp_cxx_right_paren (pp
);
2721 case NON_DEPENDENT_EXPR
:
2722 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2725 case ARGUMENT_PACK_SELECT
:
2726 dump_template_argument (pp
, ARGUMENT_PACK_SELECT_FROM_PACK (t
), flags
);
2739 pp_type_specifier_seq (pp
, t
);
2743 /* We get here when we want to print a dependent type as an
2744 id-expression, without any disambiguator decoration. */
2745 pp
->id_expression (t
);
2748 case TEMPLATE_TYPE_PARM
:
2749 case TEMPLATE_TEMPLATE_PARM
:
2750 case BOUND_TEMPLATE_TEMPLATE_PARM
:
2751 dump_type (pp
, t
, flags
);
2755 pp_cxx_trait_expression (pp
, t
);
2759 pp_cxx_va_arg_expression (pp
, t
);
2763 pp_cxx_offsetof_expression (pp
, t
);
2766 case ADDRESSOF_EXPR
:
2767 pp_cxx_addressof_expression (pp
, t
);
2771 dump_decl (pp
, t
, flags
);
2774 case EXPR_PACK_EXPANSION
:
2775 case UNARY_LEFT_FOLD_EXPR
:
2776 case UNARY_RIGHT_FOLD_EXPR
:
2777 case BINARY_LEFT_FOLD_EXPR
:
2778 case BINARY_RIGHT_FOLD_EXPR
:
2785 case VEC_DELETE_EXPR
:
2792 case UNORDERED_EXPR
:
2802 case FIX_TRUNC_EXPR
:
2807 case TRUTH_AND_EXPR
:
2809 case TRUTH_XOR_EXPR
:
2810 if (flags
& TFF_EXPR_IN_PARENS
)
2811 pp_cxx_left_paren (pp
);
2813 if (flags
& TFF_EXPR_IN_PARENS
)
2814 pp_cxx_right_paren (pp
);
2818 dump_expr (pp
, resolve_virtual_fun_from_obj_type_ref (t
), flags
);
2822 pp_string (pp
, M_("<lambda>"));
2826 pp_cxx_left_paren (pp
);
2827 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2828 pp_cxx_right_paren (pp
);
2832 pp_cxx_requires_expr (cxx_pp
, t
);
2836 pp_cxx_simple_requirement (cxx_pp
, t
);
2840 pp_cxx_type_requirement (cxx_pp
, t
);
2844 pp_cxx_compound_requirement (cxx_pp
, t
);
2848 pp_cxx_nested_requirement (cxx_pp
, t
);
2861 pp_cxx_constraint (cxx_pp
, t
);
2864 case PLACEHOLDER_EXPR
:
2865 pp_string (pp
, M_("*this"));
2869 dump_expr_list (pp
, t
, flags
);
2872 /* This list is incomplete, but should suffice for now.
2873 It is very important that `sorry' does not call
2874 `report_error_function'. That could cause an infinite loop. */
2876 pp_unsupported_tree (pp
, t
);
2879 pp_string (pp
, M_("<expression error>"));
2885 dump_binary_op (cxx_pretty_printer
*pp
, const char *opstring
, tree t
,
2888 pp_cxx_left_paren (pp
);
2889 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2890 pp_cxx_whitespace (pp
);
2892 pp_cxx_ws_string (pp
, opstring
);
2894 pp_string (pp
, M_("<unknown operator>"));
2895 pp_cxx_whitespace (pp
);
2896 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2897 pp_cxx_right_paren (pp
);
2901 dump_unary_op (cxx_pretty_printer
*pp
, const char *opstring
, tree t
, int flags
)
2903 if (flags
& TFF_EXPR_IN_PARENS
)
2904 pp_cxx_left_paren (pp
);
2905 pp_cxx_ws_string (pp
, opstring
);
2906 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2907 if (flags
& TFF_EXPR_IN_PARENS
)
2908 pp_cxx_right_paren (pp
);
2912 reinit_cxx_pp (void)
2914 pp_clear_output_area (cxx_pp
);
2915 cxx_pp
->padding
= pp_none
;
2916 pp_indentation (cxx_pp
) = 0;
2917 pp_needs_newline (cxx_pp
) = false;
2918 cxx_pp
->enclosing_scope
= current_function_decl
;
2921 /* Same as pp_formatted_text, except the return string is a separate
2922 copy and has a GGC storage duration, e.g. an indefinite lifetime. */
2925 pp_ggc_formatted_text (pretty_printer
*pp
)
2927 return ggc_strdup (pp_formatted_text (pp
));
2930 /* Exported interface to stringifying types, exprs and decls under TFF_*
2934 type_as_string (tree typ
, int flags
)
2937 pp_translate_identifiers (cxx_pp
) = false;
2938 dump_type (cxx_pp
, typ
, flags
);
2939 return pp_ggc_formatted_text (cxx_pp
);
2943 type_as_string_translate (tree typ
, int flags
)
2946 dump_type (cxx_pp
, typ
, flags
);
2947 return pp_ggc_formatted_text (cxx_pp
);
2951 expr_as_string (tree decl
, int flags
)
2954 pp_translate_identifiers (cxx_pp
) = false;
2955 dump_expr (cxx_pp
, decl
, flags
);
2956 return pp_ggc_formatted_text (cxx_pp
);
2959 /* Wrap decl_as_string with options appropriate for dwarf. */
2962 decl_as_dwarf_string (tree decl
, int flags
)
2965 /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag
2966 here will be adequate to get the desired behavior. */
2967 cxx_pp
->flags
|= pp_c_flag_gnu_v3
;
2968 name
= decl_as_string (decl
, flags
);
2969 /* Subsequent calls to the pretty printer shouldn't use this style. */
2970 cxx_pp
->flags
&= ~pp_c_flag_gnu_v3
;
2975 decl_as_string (tree decl
, int flags
)
2978 pp_translate_identifiers (cxx_pp
) = false;
2979 dump_decl (cxx_pp
, decl
, flags
);
2980 return pp_ggc_formatted_text (cxx_pp
);
2984 decl_as_string_translate (tree decl
, int flags
)
2987 dump_decl (cxx_pp
, decl
, flags
);
2988 return pp_ggc_formatted_text (cxx_pp
);
2991 /* Wrap lang_decl_name with options appropriate for dwarf. */
2994 lang_decl_dwarf_name (tree decl
, int v
, bool translate
)
2997 /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag
2998 here will be adequate to get the desired behavior. */
2999 cxx_pp
->flags
|= pp_c_flag_gnu_v3
;
3000 name
= lang_decl_name (decl
, v
, translate
);
3001 /* Subsequent calls to the pretty printer shouldn't use this style. */
3002 cxx_pp
->flags
&= ~pp_c_flag_gnu_v3
;
3006 /* Generate the three forms of printable names for cxx_printable_name. */
3009 lang_decl_name (tree decl
, int v
, bool translate
)
3013 ? decl_as_string_translate (decl
, TFF_DECL_SPECIFIERS
)
3014 : decl_as_string (decl
, TFF_DECL_SPECIFIERS
));
3017 pp_translate_identifiers (cxx_pp
) = translate
;
3019 && (DECL_CLASS_SCOPE_P (decl
)
3020 || (DECL_NAMESPACE_SCOPE_P (decl
)
3021 && CP_DECL_CONTEXT (decl
) != global_namespace
)))
3023 dump_type (cxx_pp
, CP_DECL_CONTEXT (decl
), TFF_PLAIN_IDENTIFIER
);
3024 pp_cxx_colon_colon (cxx_pp
);
3027 if (TREE_CODE (decl
) == FUNCTION_DECL
)
3028 dump_function_name (cxx_pp
, decl
, TFF_PLAIN_IDENTIFIER
);
3029 else if ((DECL_NAME (decl
) == NULL_TREE
)
3030 && TREE_CODE (decl
) == NAMESPACE_DECL
)
3031 dump_decl (cxx_pp
, decl
, TFF_PLAIN_IDENTIFIER
| TFF_UNQUALIFIED_NAME
);
3033 dump_decl (cxx_pp
, DECL_NAME (decl
), TFF_PLAIN_IDENTIFIER
);
3035 return pp_ggc_formatted_text (cxx_pp
);
3038 /* Return the location of a tree passed to %+ formats. */
3041 location_of (tree t
)
3045 t
= TYPE_MAIN_DECL (t
);
3047 return input_location
;
3049 else if (TREE_CODE (t
) == OVERLOAD
)
3053 return DECL_SOURCE_LOCATION (t
);
3054 if (TREE_CODE (t
) == DEFERRED_PARSE
)
3055 return defparse_location (t
);
3056 return cp_expr_loc_or_loc (t
, input_location
);
3059 /* Now the interfaces from error et al to dump_type et al. Each takes an
3060 on/off VERBOSE flag and supply the appropriate TFF_ flags to a dump_
3064 decl_to_string (tree decl
, int verbose
)
3068 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == RECORD_TYPE
3069 || TREE_CODE (decl
) == UNION_TYPE
|| TREE_CODE (decl
) == ENUMERAL_TYPE
)
3070 flags
= TFF_CLASS_KEY_OR_ENUM
;
3072 flags
|= TFF_DECL_SPECIFIERS
;
3073 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
3074 flags
|= TFF_DECL_SPECIFIERS
| TFF_RETURN_TYPE
;
3075 flags
|= TFF_TEMPLATE_HEADER
;
3078 dump_decl (cxx_pp
, decl
, flags
);
3079 return pp_ggc_formatted_text (cxx_pp
);
3083 expr_to_string (tree decl
)
3086 dump_expr (cxx_pp
, decl
, 0);
3087 return pp_ggc_formatted_text (cxx_pp
);
3091 fndecl_to_string (tree fndecl
, int verbose
)
3095 flags
= TFF_EXCEPTION_SPECIFICATION
| TFF_DECL_SPECIFIERS
3096 | TFF_TEMPLATE_HEADER
;
3098 flags
|= TFF_FUNCTION_DEFAULT_ARGUMENTS
;
3100 dump_decl (cxx_pp
, fndecl
, flags
);
3101 return pp_ggc_formatted_text (cxx_pp
);
3106 code_to_string (enum tree_code c
)
3108 return get_tree_code_name (c
);
3112 language_to_string (enum languages c
)
3119 case lang_cplusplus
:
3128 /* Return the proper printed version of a parameter to a C++ function. */
3131 parm_to_string (int p
)
3135 pp_string (cxx_pp
, "'this'");
3137 pp_decimal_int (cxx_pp
, p
+ 1);
3138 return pp_ggc_formatted_text (cxx_pp
);
3142 op_to_string (bool assop
, enum tree_code p
)
3144 tree id
= ovl_op_identifier (assop
, p
);
3145 return id
? IDENTIFIER_POINTER (id
) : M_("<unknown>");
3148 /* Return a GC-allocated representation of type TYP, with verbosity VERBOSE.
3150 If QUOTE is non-NULL and if *QUOTE is true, then quotes are added to the
3151 string in appropriate places, and *QUOTE is written to with false
3152 to suppress pp_format's trailing close quote so that e.g.
3153 foo_typedef {aka underlying_foo} {enum}
3154 can be printed by "%qT" as:
3155 `foo_typedef' {aka `underlying_foo'} {enum}
3157 `foo_typedef {aka underlying_foo} {enum}'
3158 When adding such quotes, if POSTPROCESSED is true (for handling %H and %I)
3159 then a leading open quote will be added, whereas if POSTPROCESSED is false
3160 (for handling %T) then any leading quote has already been added by
3161 pp_format, or is not needed due to QUOTE being NULL (for template arguments
3164 SHOW_COLOR is used to determine the colorization of any quotes that
3168 type_to_string (tree typ
, int verbose
, bool postprocessed
, bool *quote
,
3173 flags
|= TFF_CLASS_KEY_OR_ENUM
;
3174 flags
|= TFF_TEMPLATE_HEADER
;
3178 if (postprocessed
&& quote
&& *quote
)
3179 pp_begin_quote (cxx_pp
, show_color
);
3181 struct obstack
*ob
= pp_buffer (cxx_pp
)->obstack
;
3182 int type_start
, type_len
;
3183 type_start
= obstack_object_size (ob
);
3185 dump_type (cxx_pp
, typ
, flags
);
3187 /* Remember the end of the initial dump. */
3188 type_len
= obstack_object_size (ob
) - type_start
;
3190 /* If we're printing a type that involves typedefs, also print the
3191 stripped version. But sometimes the stripped version looks
3192 exactly the same, so we don't want it after all. To avoid printing
3193 it in that case, we play ugly obstack games. */
3194 if (typ
&& TYPE_P (typ
) && typ
!= TYPE_CANONICAL (typ
)
3195 && !uses_template_parms (typ
))
3197 int aka_start
, aka_len
; char *p
;
3198 tree aka
= strip_typedefs (typ
);
3199 if (quote
&& *quote
)
3200 pp_end_quote (cxx_pp
, show_color
);
3201 pp_string (cxx_pp
, " {aka");
3202 pp_cxx_whitespace (cxx_pp
);
3203 if (quote
&& *quote
)
3204 pp_begin_quote (cxx_pp
, show_color
);
3205 /* And remember the start of the aka dump. */
3206 aka_start
= obstack_object_size (ob
);
3207 dump_type (cxx_pp
, aka
, flags
);
3208 aka_len
= obstack_object_size (ob
) - aka_start
;
3209 if (quote
&& *quote
)
3210 pp_end_quote (cxx_pp
, show_color
);
3211 pp_right_brace (cxx_pp
);
3212 p
= (char*)obstack_base (ob
);
3213 /* If they are identical, cut off the aka by unwinding the obstack. */
3214 if (type_len
== aka_len
3215 && memcmp (p
+ type_start
, p
+aka_start
, type_len
) == 0)
3217 /* We can't add a '\0' here, since we may be adding a closing quote
3218 below, and it would be hidden by the '\0'.
3219 Instead, manually unwind the current object within the obstack
3220 so that the insertion point is at the end of the type, before
3222 int delta
= type_start
+ type_len
- obstack_object_size (ob
);
3223 gcc_assert (delta
<= 0);
3224 obstack_blank_fast (ob
, delta
);
3228 /* No further closing quotes are needed. */
3232 if (quote
&& *quote
)
3234 pp_end_quote (cxx_pp
, show_color
);
3237 return pp_ggc_formatted_text (cxx_pp
);
3241 args_to_string (tree p
, int verbose
)
3245 flags
|= TFF_CLASS_KEY_OR_ENUM
;
3250 if (TYPE_P (TREE_VALUE (p
)))
3251 return type_as_string_translate (p
, flags
);
3254 for (; p
; p
= TREE_CHAIN (p
))
3256 if (null_node_p (TREE_VALUE (p
)))
3257 pp_cxx_ws_string (cxx_pp
, "NULL");
3259 dump_type (cxx_pp
, error_type (TREE_VALUE (p
)), flags
);
3261 pp_separate_with_comma (cxx_pp
);
3263 return pp_ggc_formatted_text (cxx_pp
);
3266 /* Pretty-print a deduction substitution (from deduction_tsubst_fntype). P
3267 is a TREE_LIST with purpose the TEMPLATE_DECL, value the template
3271 subst_to_string (tree p
)
3273 tree decl
= TREE_PURPOSE (p
);
3274 tree targs
= TREE_VALUE (p
);
3275 tree tparms
= DECL_TEMPLATE_PARMS (decl
);
3276 int flags
= (TFF_DECL_SPECIFIERS
|TFF_TEMPLATE_HEADER
3277 |TFF_NO_TEMPLATE_BINDINGS
);
3283 dump_template_decl (cxx_pp
, TREE_PURPOSE (p
), flags
);
3284 dump_substitution (cxx_pp
, NULL
, tparms
, targs
, /*flags=*/0);
3285 return pp_ggc_formatted_text (cxx_pp
);
3289 cv_to_string (tree p
, int v
)
3292 cxx_pp
->padding
= v
? pp_before
: pp_none
;
3293 pp_cxx_cv_qualifier_seq (cxx_pp
, p
);
3294 return pp_ggc_formatted_text (cxx_pp
);
3298 eh_spec_to_string (tree p
, int /*v*/)
3302 dump_exception_spec (cxx_pp
, p
, flags
);
3303 return pp_ggc_formatted_text (cxx_pp
);
3306 /* Langhook for print_error_function. */
3308 cxx_print_error_function (diagnostic_context
*context
, const char *file
,
3309 diagnostic_info
*diagnostic
)
3313 prefix
= xstrdup (file
);
3316 lhd_print_error_function (context
, file
, diagnostic
);
3317 pp_set_prefix (context
->printer
, prefix
);
3318 maybe_print_instantiation_context (context
);
3322 cp_diagnostic_starter (diagnostic_context
*context
,
3323 diagnostic_info
*diagnostic
)
3325 diagnostic_report_current_module (context
, diagnostic_location (diagnostic
));
3326 cp_print_error_function (context
, diagnostic
);
3327 maybe_print_instantiation_context (context
);
3328 maybe_print_constexpr_context (context
);
3329 pp_set_prefix (context
->printer
, diagnostic_build_prefix (context
,
3333 /* Print current function onto BUFFER, in the process of reporting
3334 a diagnostic message. Called from cp_diagnostic_starter. */
3336 cp_print_error_function (diagnostic_context
*context
,
3337 diagnostic_info
*diagnostic
)
3339 /* If we are in an instantiation context, current_function_decl is likely
3340 to be wrong, so just rely on print_instantiation_full_context. */
3341 if (current_instantiation ())
3343 if (diagnostic_last_function_changed (context
, diagnostic
))
3345 char *old_prefix
= pp_take_prefix (context
->printer
);
3346 const char *file
= LOCATION_FILE (diagnostic_location (diagnostic
));
3347 tree abstract_origin
= diagnostic_abstract_origin (diagnostic
);
3348 char *new_prefix
= (file
&& abstract_origin
== NULL
)
3349 ? file_name_as_prefix (context
, file
) : NULL
;
3351 pp_set_prefix (context
->printer
, new_prefix
);
3353 if (current_function_decl
== NULL
)
3354 pp_string (context
->printer
, _("At global scope:"));
3359 if (abstract_origin
)
3361 ao
= BLOCK_ABSTRACT_ORIGIN (abstract_origin
);
3362 gcc_assert (TREE_CODE (ao
) == FUNCTION_DECL
);
3366 fndecl
= current_function_decl
;
3368 pp_printf (context
->printer
, function_category (fndecl
),
3369 cxx_printable_name_translate (fndecl
, 2));
3371 while (abstract_origin
)
3374 tree block
= abstract_origin
;
3376 locus
= &BLOCK_SOURCE_LOCATION (block
);
3378 block
= BLOCK_SUPERCONTEXT (block
);
3379 while (block
&& TREE_CODE (block
) == BLOCK
3380 && BLOCK_ABSTRACT_ORIGIN (block
))
3382 ao
= BLOCK_ABSTRACT_ORIGIN (block
);
3383 if (TREE_CODE (ao
) == FUNCTION_DECL
)
3388 else if (TREE_CODE (ao
) != BLOCK
)
3391 block
= BLOCK_SUPERCONTEXT (block
);
3394 abstract_origin
= block
;
3397 while (block
&& TREE_CODE (block
) == BLOCK
)
3398 block
= BLOCK_SUPERCONTEXT (block
);
3400 if (block
&& TREE_CODE (block
) == FUNCTION_DECL
)
3402 abstract_origin
= NULL
;
3406 expanded_location s
= expand_location (*locus
);
3407 pp_character (context
->printer
, ',');
3408 pp_newline (context
->printer
);
3411 if (context
->show_column
&& s
.column
!= 0)
3412 pp_printf (context
->printer
,
3413 _(" inlined from %qs at %r%s:%d:%d%R"),
3414 cxx_printable_name_translate (fndecl
, 2),
3415 "locus", s
.file
, s
.line
, s
.column
);
3417 pp_printf (context
->printer
,
3418 _(" inlined from %qs at %r%s:%d%R"),
3419 cxx_printable_name_translate (fndecl
, 2),
3420 "locus", s
.file
, s
.line
);
3424 pp_printf (context
->printer
, _(" inlined from %qs"),
3425 cxx_printable_name_translate (fndecl
, 2));
3428 pp_character (context
->printer
, ':');
3430 pp_newline (context
->printer
);
3432 diagnostic_set_last_function (context
, diagnostic
);
3433 pp_destroy_prefix (context
->printer
);
3434 context
->printer
->prefix
= old_prefix
;
3438 /* Returns a description of FUNCTION using standard terminology. The
3439 result is a format string of the form "In CATEGORY %qs". */
3441 function_category (tree fn
)
3443 /* We can get called from the middle-end for diagnostics of function
3444 clones. Make sure we have language specific information before
3445 dereferencing it. */
3446 if (DECL_LANG_SPECIFIC (STRIP_TEMPLATE (fn
))
3447 && DECL_FUNCTION_MEMBER_P (fn
))
3449 if (DECL_STATIC_FUNCTION_P (fn
))
3450 return _("In static member function %qs");
3451 else if (DECL_COPY_CONSTRUCTOR_P (fn
))
3452 return _("In copy constructor %qs");
3453 else if (DECL_CONSTRUCTOR_P (fn
))
3454 return _("In constructor %qs");
3455 else if (DECL_DESTRUCTOR_P (fn
))
3456 return _("In destructor %qs");
3457 else if (LAMBDA_FUNCTION_P (fn
))
3458 return _("In lambda function");
3460 return _("In member function %qs");
3463 return _("In function %qs");
3466 /* Report the full context of a current template instantiation,
3469 print_instantiation_full_context (diagnostic_context
*context
)
3471 struct tinst_level
*p
= current_instantiation ();
3472 location_t location
= input_location
;
3476 pp_verbatim (context
->printer
,
3478 ? _("%s: In substitution of %qS:\n")
3479 : _("%s: In instantiation of %q#D:\n"),
3480 LOCATION_FILE (location
),
3483 location
= p
->locus
;
3487 print_instantiation_partial_context (context
, p
, location
);
3490 /* Helper function of print_instantiation_partial_context() that
3491 prints a single line of instantiation context. */
3494 print_instantiation_partial_context_line (diagnostic_context
*context
,
3495 struct tinst_level
*t
,
3496 location_t loc
, bool recursive_p
)
3498 if (loc
== UNKNOWN_LOCATION
)
3501 expanded_location xloc
= expand_location (loc
);
3503 if (context
->show_column
)
3504 pp_verbatim (context
->printer
, _("%r%s:%d:%d:%R "),
3505 "locus", xloc
.file
, xloc
.line
, xloc
.column
);
3507 pp_verbatim (context
->printer
, _("%r%s:%d:%R "),
3508 "locus", xloc
.file
, xloc
.line
);
3513 pp_verbatim (context
->printer
,
3515 ? _("recursively required by substitution of %qS\n")
3516 : _("required by substitution of %qS\n"),
3519 pp_verbatim (context
->printer
,
3521 ? _("recursively required from %q#D\n")
3522 : _("required from %q#D\n"),
3527 pp_verbatim (context
->printer
,
3529 ? _("recursively required from here\n")
3530 : _("required from here\n"));
3534 /* Same as print_instantiation_full_context but less verbose. */
3537 print_instantiation_partial_context (diagnostic_context
*context
,
3538 struct tinst_level
*t0
, location_t loc
)
3540 struct tinst_level
*t
;
3543 location_t prev_loc
= loc
;
3545 for (t
= t0
; t
!= NULL
; t
= t
->next
)
3546 if (prev_loc
!= t
->locus
)
3548 prev_loc
= t
->locus
;
3554 if (template_backtrace_limit
3555 && n_total
> template_backtrace_limit
)
3557 int skip
= n_total
- template_backtrace_limit
;
3558 int head
= template_backtrace_limit
/ 2;
3560 /* Avoid skipping just 1. If so, skip 2. */
3564 head
= (template_backtrace_limit
- 1) / 2;
3567 for (n
= 0; n
< head
; n
++)
3569 gcc_assert (t
!= NULL
);
3570 if (loc
!= t
->locus
)
3571 print_instantiation_partial_context_line (context
, t
, loc
,
3572 /*recursive_p=*/false);
3576 if (t
!= NULL
&& skip
> 0)
3578 expanded_location xloc
;
3579 xloc
= expand_location (loc
);
3580 if (context
->show_column
)
3581 pp_verbatim (context
->printer
,
3582 _("%r%s:%d:%d:%R [ skipping %d instantiation "
3583 "contexts, use -ftemplate-backtrace-limit=0 to "
3585 "locus", xloc
.file
, xloc
.line
, xloc
.column
, skip
);
3587 pp_verbatim (context
->printer
,
3588 _("%r%s:%d:%R [ skipping %d instantiation "
3589 "contexts, use -ftemplate-backtrace-limit=0 to "
3591 "locus", xloc
.file
, xloc
.line
, skip
);
3596 } while (t
!= NULL
&& --skip
> 0);
3602 while (t
->next
!= NULL
&& t
->locus
== t
->next
->locus
)
3607 print_instantiation_partial_context_line (context
, t
, loc
,
3612 print_instantiation_partial_context_line (context
, NULL
, loc
,
3613 /*recursive_p=*/false);
3616 /* Called from cp_thing to print the template context for an error. */
3618 maybe_print_instantiation_context (diagnostic_context
*context
)
3620 if (!problematic_instantiation_changed () || current_instantiation () == 0)
3623 record_last_problematic_instantiation ();
3624 print_instantiation_full_context (context
);
3627 /* Report what constexpr call(s) we're trying to expand, if any. */
3630 maybe_print_constexpr_context (diagnostic_context
*context
)
3632 vec
<tree
> call_stack
= cx_error_context ();
3636 FOR_EACH_VEC_ELT (call_stack
, ix
, t
)
3638 expanded_location xloc
= expand_location (EXPR_LOCATION (t
));
3639 const char *s
= expr_as_string (t
, 0);
3640 if (context
->show_column
)
3641 pp_verbatim (context
->printer
,
3642 _("%r%s:%d:%d:%R in %<constexpr%> expansion of %qs"),
3643 "locus", xloc
.file
, xloc
.line
, xloc
.column
, s
);
3645 pp_verbatim (context
->printer
,
3646 _("%r%s:%d:%R in %<constexpr%> expansion of %qs"),
3647 "locus", xloc
.file
, xloc
.line
, s
);
3648 pp_newline (context
->printer
);
3653 /* Return true iff TYPE_A and TYPE_B are template types that are
3654 meaningful to compare. */
3657 comparable_template_types_p (tree type_a
, tree type_b
)
3659 if (!CLASS_TYPE_P (type_a
))
3661 if (!CLASS_TYPE_P (type_b
))
3664 tree tinfo_a
= TYPE_TEMPLATE_INFO (type_a
);
3665 tree tinfo_b
= TYPE_TEMPLATE_INFO (type_b
);
3666 if (!tinfo_a
|| !tinfo_b
)
3669 return TI_TEMPLATE (tinfo_a
) == TI_TEMPLATE (tinfo_b
);
3672 /* Start a new line indented by SPC spaces on PP. */
3675 newline_and_indent (pretty_printer
*pp
, int spc
)
3678 for (int i
= 0; i
< spc
; i
++)
3682 /* Generate a GC-allocated string for ARG, an expression or type. */
3685 arg_to_string (tree arg
, bool verbose
)
3688 return type_to_string (arg
, verbose
, true, NULL
, false);
3690 return expr_to_string (arg
);
3693 /* Subroutine to type_to_string_with_compare and
3694 print_template_tree_comparison.
3696 Print a representation of ARG (an expression or type) to PP,
3697 colorizing it as "type-diff" if PP->show_color. */
3700 print_nonequal_arg (pretty_printer
*pp
, tree arg
, bool verbose
)
3702 pp_printf (pp
, "%r%s%R",
3705 ? arg_to_string (arg
, verbose
)
3706 : G_("(no argument)")));
3709 /* Recursively print template TYPE_A to PP, as compared to template TYPE_B.
3711 The types must satisfy comparable_template_types_p.
3713 If INDENT is 0, then this is equivalent to type_to_string (TYPE_A), but
3714 potentially colorizing/eliding in comparison with TYPE_B.
3716 For example given types:
3717 vector<map<int,double>>
3719 vector<map<int,float>>
3720 then the result on PP would be:
3721 vector<map<[...],double>>
3722 with type elision, and:
3723 vector<map<int,double>>
3724 without type elision.
3726 In both cases the parts of TYPE that differ from PEER will be colorized
3727 if pp_show_color (pp) is true. In the above example, this would be
3730 If INDENT is non-zero, then the types are printed in a tree-like form
3731 which shows both types. In the above example, the result on PP would be:
3738 and without type-elision would be:
3745 As before, the differing parts of the types are colorized if
3746 pp_show_color (pp) is true ("double" and "float" in this example).
3748 Template arguments in which both types are using the default arguments
3749 are not printed; if at least one of the two types is using a non-default
3750 argument, then that argument is printed (or both arguments for the
3751 tree-like print format). */
3754 print_template_differences (pretty_printer
*pp
, tree type_a
, tree type_b
,
3755 bool verbose
, int indent
)
3758 newline_and_indent (pp
, indent
);
3760 tree tinfo_a
= TYPE_TEMPLATE_INFO (type_a
);
3761 tree tinfo_b
= TYPE_TEMPLATE_INFO (type_b
);
3763 pp_printf (pp
, "%s<",
3764 IDENTIFIER_POINTER (DECL_NAME (TI_TEMPLATE (tinfo_a
))));
3766 tree args_a
= TI_ARGS (tinfo_a
);
3767 tree args_b
= TI_ARGS (tinfo_b
);
3768 gcc_assert (TREE_CODE (args_a
) == TREE_VEC
);
3769 gcc_assert (TREE_CODE (args_b
) == TREE_VEC
);
3771 int len_a
= get_non_default_template_args_count (args_a
, flags
);
3772 args_a
= INNERMOST_TEMPLATE_ARGS (args_a
);
3773 int len_b
= get_non_default_template_args_count (args_b
, flags
);
3774 args_b
= INNERMOST_TEMPLATE_ARGS (args_b
);
3775 /* Determine the maximum range of args for which non-default template args
3776 were used; beyond this, only default args (if any) were used, and so
3777 they will be equal from this point onwards.
3778 One of the two peers might have used default arguments within this
3779 range, but the other will be using non-default arguments, and so
3780 it's more readable to print both within this range, to highlight
3782 int len_max
= MAX (len_a
, len_b
);
3783 gcc_assert (TREE_CODE (args_a
) == TREE_VEC
);
3784 gcc_assert (TREE_CODE (args_b
) == TREE_VEC
);
3785 for (int idx
= 0; idx
< len_max
; idx
++)
3788 pp_character (pp
, ',');
3790 tree arg_a
= TREE_VEC_ELT (args_a
, idx
);
3791 tree arg_b
= TREE_VEC_ELT (args_b
, idx
);
3795 newline_and_indent (pp
, indent
+ 2);
3796 /* Can do elision here, printing "[...]". */
3797 if (flag_elide_type
)
3798 pp_string (pp
, G_("[...]"));
3800 pp_string (pp
, arg_to_string (arg_a
, verbose
));
3804 int new_indent
= indent
? indent
+ 2 : 0;
3805 if (comparable_template_types_p (arg_a
, arg_b
))
3806 print_template_differences (pp
, arg_a
, arg_b
, verbose
, new_indent
);
3810 newline_and_indent (pp
, indent
+ 2);
3811 pp_character (pp
, '[');
3812 print_nonequal_arg (pp
, arg_a
, verbose
);
3813 pp_string (pp
, " != ");
3814 print_nonequal_arg (pp
, arg_b
, verbose
);
3815 pp_character (pp
, ']');
3818 print_nonequal_arg (pp
, arg_a
, verbose
);
3821 pp_printf (pp
, ">");
3824 /* As type_to_string, but for a template, potentially colorizing/eliding
3825 in comparison with PEER.
3826 For example, if TYPE is map<int,double> and PEER is map<int,int>,
3827 then the resulting string would be:
3829 with type elision, and:
3831 without type elision.
3833 In both cases the parts of TYPE that differ from PEER will be colorized
3834 if SHOW_COLOR is true. In the above example, this would be "double".
3836 Template arguments in which both types are using the default arguments
3837 are not printed; if at least one of the two types is using a non-default
3838 argument, then both arguments are printed.
3840 The resulting string is in a GC-allocated buffer. */
3843 type_to_string_with_compare (tree type
, tree peer
, bool verbose
,
3846 pretty_printer inner_pp
;
3847 pretty_printer
*pp
= &inner_pp
;
3848 pp_show_color (pp
) = show_color
;
3850 print_template_differences (pp
, type
, peer
, verbose
, 0);
3851 return pp_ggc_formatted_text (pp
);
3854 /* Recursively print a tree-like comparison of TYPE_A and TYPE_B to PP,
3855 indented by INDENT spaces.
3857 For example given types:
3859 vector<map<int,double>>
3863 vector<map<double,float>>
3865 the output with type elision would be:
3872 and without type-elision would be:
3879 TYPE_A and TYPE_B must both be comparable template types
3880 (as per comparable_template_types_p).
3882 Template arguments in which both types are using the default arguments
3883 are not printed; if at least one of the two types is using a non-default
3884 argument, then both arguments are printed. */
3887 print_template_tree_comparison (pretty_printer
*pp
, tree type_a
, tree type_b
,
3888 bool verbose
, int indent
)
3890 print_template_differences (pp
, type_a
, type_b
, verbose
, indent
);
3893 /* Subroutine for use in a format_postprocessor::handle
3894 implementation. Adds a chunk to the end of
3895 formatted output, so that it will be printed
3896 by pp_output_formatted_text. */
3899 append_formatted_chunk (pretty_printer
*pp
, const char *content
)
3901 output_buffer
*buffer
= pp_buffer (pp
);
3902 struct chunk_info
*chunk_array
= buffer
->cur_chunk_array
;
3903 const char **args
= chunk_array
->args
;
3905 unsigned int chunk_idx
;
3906 for (chunk_idx
= 0; args
[chunk_idx
]; chunk_idx
++)
3908 args
[chunk_idx
++] = content
;
3909 args
[chunk_idx
] = NULL
;
3912 /* Create a copy of CONTENT, with quotes added, and,
3913 potentially, with colorization.
3914 No escaped is performed on CONTENT.
3915 The result is in a GC-allocated buffer. */
3918 add_quotes (const char *content
, bool show_color
)
3920 pretty_printer tmp_pp
;
3921 pp_show_color (&tmp_pp
) = show_color
;
3923 /* We have to use "%<%s%>" rather than "%qs" here in order to avoid
3924 quoting colorization bytes within the results. */
3925 pp_printf (&tmp_pp
, "%<%s%>", content
);
3927 return pp_ggc_formatted_text (&tmp_pp
);
3930 /* If we had %H and %I, and hence deferred printing them,
3931 print them now, storing the result into the chunk_info
3932 for pp_format. Quote them if 'q' was provided.
3933 Also print the difference in tree form, adding it as
3934 an additional chunk. */
3937 cxx_format_postprocessor::handle (pretty_printer
*pp
)
3939 /* If we have one of %H and %I, the other should have
3941 if (m_type_a
.m_tree
|| m_type_b
.m_tree
)
3943 /* Avoid reentrancy issues by working with a copy of
3944 m_type_a and m_type_b, resetting them now. */
3945 deferred_printed_type type_a
= m_type_a
;
3946 deferred_printed_type type_b
= m_type_b
;
3947 m_type_a
= deferred_printed_type ();
3948 m_type_b
= deferred_printed_type ();
3950 gcc_assert (type_a
.m_buffer_ptr
);
3951 gcc_assert (type_b
.m_buffer_ptr
);
3953 bool show_color
= pp_show_color (pp
);
3955 const char *type_a_text
;
3956 const char *type_b_text
;
3958 if (comparable_template_types_p (type_a
.m_tree
, type_b
.m_tree
))
3961 = type_to_string_with_compare (type_a
.m_tree
, type_b
.m_tree
,
3962 type_a
.m_verbose
, show_color
);
3964 = type_to_string_with_compare (type_b
.m_tree
, type_a
.m_tree
,
3965 type_b
.m_verbose
, show_color
);
3967 if (flag_diagnostics_show_template_tree
)
3969 pretty_printer inner_pp
;
3970 pp_show_color (&inner_pp
) = pp_show_color (pp
);
3971 print_template_tree_comparison
3972 (&inner_pp
, type_a
.m_tree
, type_b
.m_tree
, type_a
.m_verbose
, 2);
3973 append_formatted_chunk (pp
, pp_ggc_formatted_text (&inner_pp
));
3978 /* If the types were not comparable (or if only one of %H/%I was
3979 provided), they are printed normally, and no difference tree
3981 type_a_text
= type_to_string (type_a
.m_tree
, type_a
.m_verbose
,
3982 true, &type_a
.m_quote
, show_color
);
3983 type_b_text
= type_to_string (type_b
.m_tree
, type_b
.m_verbose
,
3984 true, &type_b
.m_quote
, show_color
);
3988 type_a_text
= add_quotes (type_a_text
, show_color
);
3989 *type_a
.m_buffer_ptr
= type_a_text
;
3992 type_b_text
= add_quotes (type_b_text
, show_color
);
3993 *type_b
.m_buffer_ptr
= type_b_text
;
3997 /* Subroutine for handling %H and %I, to support i18n of messages like:
3999 error_at (loc, "could not convert %qE from %qH to %qI",
4000 expr, type_a, type_b);
4002 so that we can print things like:
4004 could not convert 'foo' from 'map<int,double>' to 'map<int,int>'
4006 and, with type-elision:
4008 could not convert 'foo' from 'map<[...],double>' to 'map<[...],int>'
4010 (with color-coding of the differences between the types).
4012 The %H and %I format codes are peers: both must be present,
4013 and they affect each other. Hence to handle them, we must
4014 delay printing until we have both, deferring the printing to
4015 pretty_printer's m_format_postprocessor hook.
4017 This is called in phase 2 of pp_format, when it is accumulating
4018 a series of formatted chunks. We stash the location of the chunk
4019 we're meant to have written to, so that we can write to it in the
4020 m_format_postprocessor hook.
4022 We also need to stash whether a 'q' prefix was provided (the QUOTE
4023 param) so that we can add the quotes when writing out the delayed
4027 defer_phase_2_of_type_diff (deferred_printed_type
*deferred
,
4028 tree type
, const char **buffer_ptr
,
4029 bool verbose
, bool quote
)
4031 gcc_assert (deferred
->m_tree
== NULL_TREE
);
4032 gcc_assert (deferred
->m_buffer_ptr
== NULL
);
4033 *deferred
= deferred_printed_type (type
, buffer_ptr
, verbose
, quote
);
4037 /* Called from output_format -- during diagnostic message processing --
4038 to handle C++ specific format specifier with the following meanings:
4039 %A function argument-list.
4043 %F function declaration.
4045 %H type difference (from).
4046 %I type difference (to).
4048 %L language as used in extern "lang".
4050 %P function parameter whose position is indicated by an integer.
4051 %Q assignment operator.
4052 %S substitution (template + args)
4055 %X exception-specification. */
4057 cp_printer (pretty_printer
*pp
, text_info
*text
, const char *spec
,
4058 int precision
, bool wide
, bool set_locus
, bool verbose
,
4059 bool *quoted
, const char **buffer_ptr
)
4061 gcc_assert (pp
->m_format_postprocessor
);
4062 cxx_format_postprocessor
*postprocessor
4063 = static_cast <cxx_format_postprocessor
*> (pp
->m_format_postprocessor
);
4067 #define next_tree (t = va_arg (*text->args_ptr, tree))
4068 #define next_tcode ((enum tree_code) va_arg (*text->args_ptr, int))
4069 #define next_lang ((enum languages) va_arg (*text->args_ptr, int))
4070 #define next_int va_arg (*text->args_ptr, int)
4072 if (precision
!= 0 || wide
)
4077 case 'A': result
= args_to_string (next_tree
, verbose
); break;
4078 case 'C': result
= code_to_string (next_tcode
); break;
4081 tree temp
= next_tree
;
4083 && DECL_HAS_DEBUG_EXPR_P (temp
))
4085 temp
= DECL_DEBUG_EXPR (temp
);
4088 result
= expr_to_string (temp
);
4092 result
= decl_to_string (temp
, verbose
);
4095 case 'E': result
= expr_to_string (next_tree
); break;
4096 case 'F': result
= fndecl_to_string (next_tree
, verbose
); break;
4098 percent_G_format (text
);
4101 defer_phase_2_of_type_diff (&postprocessor
->m_type_a
, next_tree
,
4102 buffer_ptr
, verbose
, *quoted
);
4105 defer_phase_2_of_type_diff (&postprocessor
->m_type_b
, next_tree
,
4106 buffer_ptr
, verbose
, *quoted
);
4109 t
= va_arg (*text
->args_ptr
, tree
);
4110 percent_K_format (text
, EXPR_LOCATION (t
), TREE_BLOCK (t
));
4112 case 'L': result
= language_to_string (next_lang
); break;
4113 case 'O': result
= op_to_string (false, next_tcode
); break;
4114 case 'P': result
= parm_to_string (next_int
); break;
4115 case 'Q': result
= op_to_string (true, next_tcode
); break;
4116 case 'S': result
= subst_to_string (next_tree
); break;
4119 result
= type_to_string (next_tree
, verbose
, false, quoted
,
4120 pp_show_color (pp
));
4123 case 'V': result
= cv_to_string (next_tree
, verbose
); break;
4124 case 'X': result
= eh_spec_to_string (next_tree
, verbose
); break;
4130 pp_string (pp
, result
);
4131 if (set_locus
&& t
!= NULL
)
4132 text
->set_location (0, location_of (t
), SHOW_RANGE_WITH_CARET
);
4140 /* Warn about the use of C++0x features when appropriate. */
4142 maybe_warn_cpp0x (cpp0x_warn_str str
)
4144 if ((cxx_dialect
== cxx98
) && !in_system_header_at (input_location
))
4145 /* We really want to suppress this warning in system headers,
4146 because libstdc++ uses variadic templates even when we aren't
4150 case CPP0X_INITIALIZER_LISTS
:
4151 pedwarn (input_location
, 0,
4152 "extended initializer lists "
4153 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4155 case CPP0X_EXPLICIT_CONVERSION
:
4156 pedwarn (input_location
, 0,
4157 "explicit conversion operators "
4158 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4160 case CPP0X_VARIADIC_TEMPLATES
:
4161 pedwarn (input_location
, 0,
4162 "variadic templates "
4163 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4165 case CPP0X_LAMBDA_EXPR
:
4166 pedwarn (input_location
, 0,
4167 "lambda expressions "
4168 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4171 pedwarn (input_location
, 0,
4172 "C++11 auto only available with %<-std=c++11%> or "
4173 "%<-std=gnu++11%>");
4175 case CPP0X_SCOPED_ENUMS
:
4176 pedwarn (input_location
, 0,
4177 "scoped enums only available with %<-std=c++11%> or "
4178 "%<-std=gnu++11%>");
4180 case CPP0X_DEFAULTED_DELETED
:
4181 pedwarn (input_location
, 0,
4182 "defaulted and deleted functions "
4183 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4185 case CPP0X_INLINE_NAMESPACES
:
4186 pedwarn (input_location
, OPT_Wpedantic
,
4187 "inline namespaces "
4188 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4190 case CPP0X_OVERRIDE_CONTROLS
:
4191 pedwarn (input_location
, 0,
4192 "override controls (override/final) "
4193 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4196 pedwarn (input_location
, 0,
4197 "non-static data member initializers "
4198 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4200 case CPP0X_USER_DEFINED_LITERALS
:
4201 pedwarn (input_location
, 0,
4202 "user-defined literals "
4203 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4205 case CPP0X_DELEGATING_CTORS
:
4206 pedwarn (input_location
, 0,
4207 "delegating constructors "
4208 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4210 case CPP0X_INHERITING_CTORS
:
4211 pedwarn (input_location
, 0,
4212 "inheriting constructors "
4213 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4215 case CPP0X_ATTRIBUTES
:
4216 pedwarn (input_location
, 0,
4218 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4220 case CPP0X_REF_QUALIFIER
:
4221 pedwarn (input_location
, 0,
4223 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
4230 /* Warn about the use of variadic templates when appropriate. */
4232 maybe_warn_variadic_templates (void)
4234 maybe_warn_cpp0x (CPP0X_VARIADIC_TEMPLATES
);
4238 /* Issue an ISO C++98 pedantic warning at LOCATION, conditional on
4239 option OPT with text GMSGID. Use this function to report
4240 diagnostics for constructs that are invalid C++98, but valid
4243 pedwarn_cxx98 (location_t location
, int opt
, const char *gmsgid
, ...)
4245 diagnostic_info diagnostic
;
4248 rich_location
richloc (line_table
, location
);
4250 va_start (ap
, gmsgid
);
4251 diagnostic_set_info (&diagnostic
, gmsgid
, &ap
, &richloc
,
4252 (cxx_dialect
== cxx98
) ? DK_PEDWARN
: DK_WARNING
);
4253 diagnostic
.option_index
= opt
;
4254 ret
= diagnostic_report_diagnostic (global_dc
, &diagnostic
);
4259 /* Issue a diagnostic that NAME cannot be found in SCOPE. DECL is what
4260 we found when we tried to do the lookup. LOCATION is the location of
4261 the NAME identifier. */
4264 qualified_name_lookup_error (tree scope
, tree name
,
4265 tree decl
, location_t location
)
4267 if (scope
== error_mark_node
)
4268 ; /* We already complained. */
4269 else if (TYPE_P (scope
))
4271 if (!COMPLETE_TYPE_P (scope
))
4272 error_at (location
, "incomplete type %qT used in nested name specifier",
4274 else if (TREE_CODE (decl
) == TREE_LIST
)
4276 error_at (location
, "reference to %<%T::%D%> is ambiguous",
4278 print_candidates (decl
);
4283 if (SCOPED_ENUM_P (scope
) && TREE_CODE (name
) == IDENTIFIER_NODE
)
4284 hint
= suggest_alternative_in_scoped_enum (name
, scope
);
4285 if (const char *suggestion
= hint
.suggestion ())
4287 gcc_rich_location
richloc (location
);
4288 richloc
.add_fixit_replace (suggestion
);
4290 "%qD is not a member of %qT; did you mean %qs?",
4291 name
, scope
, suggestion
);
4294 error_at (location
, "%qD is not a member of %qT", name
, scope
);
4297 else if (scope
!= global_namespace
)
4299 auto_diagnostic_group d
;
4300 bool emit_fixit
= true;
4302 = suggest_alternative_in_explicit_scope (location
, name
, scope
);
4305 hint
= suggest_alternatives_in_other_namespaces (location
, name
);
4306 /* "location" is just the location of the name, not of the explicit
4307 scope, and it's not easy to get at the latter, so we can't issue
4308 fix-it hints for the suggestion. */
4311 if (const char *suggestion
= hint
.suggestion ())
4313 gcc_rich_location
richloc (location
);
4315 richloc
.add_fixit_replace (suggestion
);
4316 error_at (&richloc
, "%qD is not a member of %qD; did you mean %qs?",
4317 name
, scope
, suggestion
);
4320 error_at (location
, "%qD is not a member of %qD", name
, scope
);
4324 auto_diagnostic_group d
;
4325 name_hint hint
= suggest_alternatives_for (location
, name
, true);
4326 if (const char *suggestion
= hint
.suggestion ())
4328 gcc_rich_location
richloc (location
);
4329 richloc
.add_fixit_replace (suggestion
);
4331 "%<::%D%> has not been declared; did you mean %qs?",
4335 error_at (location
, "%<::%D%> has not been declared", name
);
4339 /* C++-specific implementation of range_label::get_text () vfunc for
4340 range_label_for_type_mismatch.
4342 Compare with print_template_differences above. */
4345 range_label_for_type_mismatch::get_text (unsigned /*range_idx*/) const
4347 if (m_labelled_type
== NULL_TREE
)
4348 return label_text (NULL
, false);
4350 const bool verbose
= false;
4351 const bool show_color
= false;
4355 && comparable_template_types_p (m_labelled_type
, m_other_type
))
4356 result
= type_to_string_with_compare (m_labelled_type
, m_other_type
,
4357 verbose
, show_color
);
4359 result
= type_to_string (m_labelled_type
, verbose
, true, NULL
, show_color
);
4361 /* Both of the above return GC-allocated buffers, so the caller mustn't
4363 return label_text (const_cast <char *> (result
), false);