1 /* Call-backs for C++ error reporting.
2 This code is non-reentrant.
3 Copyright (C) 1993-2018 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/>. */
22 #include "coretypes.h"
24 #include "stringpool.h"
25 #include "tree-diagnostic.h"
26 #include "langhooks-def.h"
28 #include "cxx-pretty-print.h"
29 #include "tree-pretty-print.h"
30 #include "gimple-pretty-print.h"
31 #include "c-family/c-objc.h"
33 #include "internal-fn.h"
34 #include "gcc-rich-location.h"
36 #define pp_separate_with_comma(PP) pp_cxx_separate_with (PP, ',')
37 #define pp_separate_with_semicolon(PP) pp_cxx_separate_with (PP, ';')
39 /* cxx_pp is a C++ front-end-specific pretty printer: this is where we
40 dump C++ ASTs as strings. It is mostly used only by the various
41 tree -> string functions that are occasionally called from the
42 debugger or by the front-end for things like
43 __PRETTY_FUNCTION__. */
44 static cxx_pretty_printer actual_pretty_printer
;
45 static cxx_pretty_printer
* const cxx_pp
= &actual_pretty_printer
;
47 /* Translate if being used for diagnostics, but not for dump files or
49 #define M_(msgid) (pp_translate_identifiers (cxx_pp) ? _(msgid) : (msgid))
51 # define NEXT_CODE(T) (TREE_CODE (TREE_TYPE (T)))
53 static const char *args_to_string (tree
, int);
54 static const char *code_to_string (enum tree_code
);
55 static const char *cv_to_string (tree
, int);
56 static const char *decl_to_string (tree
, int);
57 static const char *expr_to_string (tree
);
58 static const char *fndecl_to_string (tree
, int);
59 static const char *op_to_string (bool, enum tree_code
);
60 static const char *parm_to_string (int);
61 static const char *type_to_string (tree
, int, bool, bool *, bool);
63 static void dump_alias_template_specialization (cxx_pretty_printer
*, tree
, int);
64 static void dump_type (cxx_pretty_printer
*, tree
, int);
65 static void dump_typename (cxx_pretty_printer
*, tree
, int);
66 static void dump_simple_decl (cxx_pretty_printer
*, tree
, tree
, int);
67 static void dump_decl (cxx_pretty_printer
*, tree
, int);
68 static void dump_template_decl (cxx_pretty_printer
*, tree
, int);
69 static void dump_function_decl (cxx_pretty_printer
*, tree
, int);
70 static void dump_expr (cxx_pretty_printer
*, tree
, int);
71 static void dump_unary_op (cxx_pretty_printer
*, const char *, tree
, int);
72 static void dump_binary_op (cxx_pretty_printer
*, const char *, tree
, int);
73 static void dump_aggr_type (cxx_pretty_printer
*, tree
, int);
74 static void dump_type_prefix (cxx_pretty_printer
*, tree
, int);
75 static void dump_type_suffix (cxx_pretty_printer
*, tree
, int);
76 static void dump_function_name (cxx_pretty_printer
*, tree
, int);
77 static void dump_call_expr_args (cxx_pretty_printer
*, tree
, int, bool);
78 static void dump_aggr_init_expr_args (cxx_pretty_printer
*, tree
, int, bool);
79 static void dump_expr_list (cxx_pretty_printer
*, tree
, int);
80 static void dump_global_iord (cxx_pretty_printer
*, tree
);
81 static void dump_parameters (cxx_pretty_printer
*, tree
, int);
82 static void dump_ref_qualifier (cxx_pretty_printer
*, tree
, int);
83 static void dump_exception_spec (cxx_pretty_printer
*, tree
, int);
84 static void dump_template_argument (cxx_pretty_printer
*, tree
, int);
85 static void dump_template_argument_list (cxx_pretty_printer
*, tree
, int);
86 static void dump_template_parameter (cxx_pretty_printer
*, tree
, int);
87 static void dump_template_bindings (cxx_pretty_printer
*, tree
, tree
,
89 static void dump_scope (cxx_pretty_printer
*, tree
, int);
90 static void dump_template_parms (cxx_pretty_printer
*, tree
, int, int);
91 static int get_non_default_template_args_count (tree
, int);
92 static const char *function_category (tree
);
93 static void maybe_print_constexpr_context (diagnostic_context
*);
94 static void maybe_print_instantiation_context (diagnostic_context
*);
95 static void print_instantiation_full_context (diagnostic_context
*);
96 static void print_instantiation_partial_context (diagnostic_context
*,
99 static void cp_diagnostic_starter (diagnostic_context
*, diagnostic_info
*);
100 static void cp_print_error_function (diagnostic_context
*, diagnostic_info
*);
102 static bool cp_printer (pretty_printer
*, text_info
*, const char *,
103 int, bool, bool, bool, bool *, const char **);
105 /* Struct for handling %H or %I, which require delaying printing the
106 type until a postprocessing stage. */
108 struct deferred_printed_type
110 deferred_printed_type ()
111 : m_tree (NULL_TREE
), m_buffer_ptr (NULL
), m_verbose (false), m_quote (false)
114 deferred_printed_type (tree type
, const char **buffer_ptr
, bool verbose
,
116 : m_tree (type
), m_buffer_ptr (buffer_ptr
), m_verbose (verbose
),
120 gcc_assert (buffer_ptr
);
123 /* The tree is not GTY-marked: they are only non-NULL within a
124 call to pp_format. */
126 const char **m_buffer_ptr
;
131 /* Subclass of format_postprocessor for the C++ frontend.
132 This handles the %H and %I formatting codes, printing them
133 in a postprocessing phase (since they affect each other). */
135 class cxx_format_postprocessor
: public format_postprocessor
138 cxx_format_postprocessor ()
139 : m_type_a (), m_type_b ()
142 void handle (pretty_printer
*pp
) FINAL OVERRIDE
;
144 deferred_printed_type m_type_a
;
145 deferred_printed_type m_type_b
;
148 /* CONTEXT->printer is a basic pretty printer that was constructed
149 presumably by diagnostic_initialize(), called early in the
150 compiler's initialization process (in general_init) Before the FE
151 is initialized. This (C++) FE-specific diagnostic initializer is
152 thus replacing the basic pretty printer with one that has C++-aware
156 cxx_initialize_diagnostics (diagnostic_context
*context
)
158 pretty_printer
*base
= context
->printer
;
159 cxx_pretty_printer
*pp
= XNEW (cxx_pretty_printer
);
160 context
->printer
= new (pp
) cxx_pretty_printer ();
162 /* It is safe to free this object because it was previously XNEW()'d. */
163 base
->~pretty_printer ();
166 c_common_diagnostics_set_defaults (context
);
167 diagnostic_starter (context
) = cp_diagnostic_starter
;
168 /* diagnostic_finalizer is already c_diagnostic_finalizer. */
169 diagnostic_format_decoder (context
) = cp_printer
;
170 pp
->m_format_postprocessor
= new cxx_format_postprocessor ();
173 /* Dump a scope, if deemed necessary. */
176 dump_scope (cxx_pretty_printer
*pp
, tree scope
, int flags
)
178 int f
= flags
& (TFF_SCOPE
| TFF_CHASE_TYPEDEF
);
180 if (scope
== NULL_TREE
)
183 if (TREE_CODE (scope
) == NAMESPACE_DECL
)
185 if (scope
!= global_namespace
)
187 dump_decl (pp
, scope
, f
);
188 pp_cxx_colon_colon (pp
);
191 else if (AGGREGATE_TYPE_P (scope
))
193 dump_type (pp
, scope
, f
);
194 pp_cxx_colon_colon (pp
);
196 else if ((flags
& TFF_SCOPE
) && TREE_CODE (scope
) == FUNCTION_DECL
)
198 dump_function_decl (pp
, scope
, f
);
199 pp_cxx_colon_colon (pp
);
203 /* Dump the template ARGument under control of FLAGS. */
206 dump_template_argument (cxx_pretty_printer
*pp
, tree arg
, int flags
)
208 if (ARGUMENT_PACK_P (arg
))
209 dump_template_argument_list (pp
, ARGUMENT_PACK_ARGS (arg
),
210 /* No default args in argument packs. */
211 flags
|TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS
);
212 else if (TYPE_P (arg
) || TREE_CODE (arg
) == TEMPLATE_DECL
)
213 dump_type (pp
, arg
, flags
& ~TFF_CLASS_KEY_OR_ENUM
);
216 if (TREE_CODE (arg
) == TREE_LIST
)
217 arg
= TREE_VALUE (arg
);
219 /* Strip implicit conversions. */
220 while (CONVERT_EXPR_P (arg
))
221 arg
= TREE_OPERAND (arg
, 0);
223 dump_expr (pp
, arg
, (flags
| TFF_EXPR_IN_PARENS
) & ~TFF_CLASS_KEY_OR_ENUM
);
227 /* Count the number of template arguments ARGS whose value does not
228 match the (optional) default template parameter in PARAMS */
231 get_non_default_template_args_count (tree args
, int flags
)
233 int n
= TREE_VEC_LENGTH (INNERMOST_TEMPLATE_ARGS (args
));
235 if (/* We use this flag when generating debug information. We don't
236 want to expand templates at this point, for this may generate
237 new decls, which gets decl counts out of sync, which may in
238 turn cause codegen differences between compilations with and
240 (flags
& TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS
) != 0
241 || !flag_pretty_templates
)
244 return GET_NON_DEFAULT_TEMPLATE_ARGS_COUNT (INNERMOST_TEMPLATE_ARGS (args
));
247 /* Dump a template-argument-list ARGS (always a TREE_VEC) under control
251 dump_template_argument_list (cxx_pretty_printer
*pp
, tree args
, int flags
)
253 int n
= get_non_default_template_args_count (args
, flags
);
257 for (i
= 0; i
< n
; ++i
)
259 tree arg
= TREE_VEC_ELT (args
, i
);
261 /* Only print a comma if we know there is an argument coming. In
262 the case of an empty template argument pack, no actual
263 argument will be printed. */
265 && (!ARGUMENT_PACK_P (arg
)
266 || TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg
)) > 0))
267 pp_separate_with_comma (pp
);
269 dump_template_argument (pp
, arg
, flags
);
274 /* Dump a template parameter PARM (a TREE_LIST) under control of FLAGS. */
277 dump_template_parameter (cxx_pretty_printer
*pp
, tree parm
, int flags
)
282 if (parm
== error_mark_node
)
285 p
= TREE_VALUE (parm
);
286 a
= TREE_PURPOSE (parm
);
288 if (TREE_CODE (p
) == TYPE_DECL
)
290 if (flags
& TFF_DECL_SPECIFIERS
)
292 pp_cxx_ws_string (pp
, "class");
293 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (p
)))
294 pp_cxx_ws_string (pp
, "...");
296 pp_cxx_tree_identifier (pp
, DECL_NAME (p
));
298 else if (DECL_NAME (p
))
299 pp_cxx_tree_identifier (pp
, DECL_NAME (p
));
301 pp_cxx_canonical_template_parameter (pp
, TREE_TYPE (p
));
304 dump_decl (pp
, p
, flags
| TFF_DECL_SPECIFIERS
);
306 if ((flags
& TFF_FUNCTION_DEFAULT_ARGUMENTS
) && a
!= NULL_TREE
)
308 pp_cxx_whitespace (pp
);
310 pp_cxx_whitespace (pp
);
311 if (TREE_CODE (p
) == TYPE_DECL
|| TREE_CODE (p
) == TEMPLATE_DECL
)
312 dump_type (pp
, a
, flags
& ~TFF_CHASE_TYPEDEF
);
314 dump_expr (pp
, a
, flags
| TFF_EXPR_IN_PARENS
);
318 /* Dump, under control of FLAGS, a template-parameter-list binding.
319 PARMS is a TREE_LIST of TREE_VEC of TREE_LIST and ARGS is a
323 dump_template_bindings (cxx_pretty_printer
*pp
, tree parms
, tree args
,
324 vec
<tree
, va_gc
> *typenames
)
326 bool need_semicolon
= false;
332 tree p
= TREE_VALUE (parms
);
333 int lvl
= TMPL_PARMS_DEPTH (parms
);
336 tree lvl_args
= NULL_TREE
;
338 /* Don't crash if we had an invalid argument list. */
339 if (TMPL_ARGS_DEPTH (args
) >= lvl
)
340 lvl_args
= TMPL_ARGS_LEVEL (args
, lvl
);
342 for (i
= 0; i
< TREE_VEC_LENGTH (p
); ++i
)
344 tree arg
= NULL_TREE
;
346 /* Don't crash if we had an invalid argument list. */
347 if (lvl_args
&& NUM_TMPL_ARGS (lvl_args
) > arg_idx
)
348 arg
= TREE_VEC_ELT (lvl_args
, arg_idx
);
351 pp_separate_with_semicolon (pp
);
352 dump_template_parameter (pp
, TREE_VEC_ELT (p
, i
),
353 TFF_PLAIN_IDENTIFIER
);
354 pp_cxx_whitespace (pp
);
356 pp_cxx_whitespace (pp
);
359 if (ARGUMENT_PACK_P (arg
))
360 pp_cxx_left_brace (pp
);
361 dump_template_argument (pp
, arg
, TFF_PLAIN_IDENTIFIER
);
362 if (ARGUMENT_PACK_P (arg
))
363 pp_cxx_right_brace (pp
);
366 pp_string (pp
, M_("<missing>"));
369 need_semicolon
= true;
372 parms
= TREE_CHAIN (parms
);
375 /* Don't bother with typenames for a partial instantiation. */
376 if (vec_safe_is_empty (typenames
) || uses_template_parms (args
))
379 /* Don't try to print typenames when we're processing a clone. */
380 if (current_function_decl
381 && !DECL_LANG_SPECIFIC (current_function_decl
))
384 /* Don't try to do this once cgraph starts throwing away front-end
389 FOR_EACH_VEC_SAFE_ELT (typenames
, i
, t
)
392 pp_separate_with_semicolon (pp
);
393 dump_type (pp
, t
, TFF_PLAIN_IDENTIFIER
);
394 pp_cxx_whitespace (pp
);
396 pp_cxx_whitespace (pp
);
397 push_deferring_access_checks (dk_no_check
);
398 t
= tsubst (t
, args
, tf_none
, NULL_TREE
);
399 pop_deferring_access_checks ();
400 /* Strip typedefs. We can't just use TFF_CHASE_TYPEDEF because
401 pp_simple_type_specifier doesn't know about it. */
402 t
= strip_typedefs (t
);
403 dump_type (pp
, t
, TFF_PLAIN_IDENTIFIER
);
407 /* Dump a human-readable equivalent of the alias template
408 specialization of T. */
411 dump_alias_template_specialization (cxx_pretty_printer
*pp
, tree t
, int flags
)
413 gcc_assert (alias_template_specialization_p (t
));
415 tree decl
= TYPE_NAME (t
);
416 if (!(flags
& TFF_UNQUALIFIED_NAME
))
417 dump_scope (pp
, CP_DECL_CONTEXT (decl
), flags
);
418 pp_cxx_tree_identifier (pp
, DECL_NAME (decl
));
419 dump_template_parms (pp
, DECL_TEMPLATE_INFO (decl
),
421 flags
& ~TFF_TEMPLATE_HEADER
);
424 /* Dump a human-readable equivalent of TYPE. FLAGS controls the
428 dump_type (cxx_pretty_printer
*pp
, tree t
, int flags
)
433 /* Don't print e.g. "struct mytypedef". */
434 if (TYPE_P (t
) && typedef_variant_p (t
))
436 tree decl
= TYPE_NAME (t
);
437 if ((flags
& TFF_CHASE_TYPEDEF
)
438 || DECL_SELF_REFERENCE_P (decl
)
439 || (!flag_pretty_templates
440 && DECL_LANG_SPECIFIC (decl
) && DECL_TEMPLATE_INFO (decl
)))
441 t
= strip_typedefs (t
);
442 else if (alias_template_specialization_p (t
))
444 dump_alias_template_specialization (pp
, t
, flags
);
447 else if (same_type_p (t
, TREE_TYPE (decl
)))
451 pp_cxx_cv_qualifier_seq (pp
, t
);
452 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
457 if (TYPE_PTRMEMFUNC_P (t
))
460 switch (TREE_CODE (t
))
463 if (t
== init_list_type_node
)
464 pp_string (pp
, M_("<brace-enclosed initializer list>"));
465 else if (t
== unknown_type_node
)
466 pp_string (pp
, M_("<unresolved overloaded function type>"));
469 pp_cxx_cv_qualifier_seq (pp
, t
);
470 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
475 /* A list of function parms. */
476 dump_parameters (pp
, t
, flags
);
479 case IDENTIFIER_NODE
:
480 pp_cxx_tree_identifier (pp
, t
);
484 dump_type (pp
, BINFO_TYPE (t
), flags
);
490 dump_aggr_type (pp
, t
, flags
);
494 if (flags
& TFF_CHASE_TYPEDEF
)
496 dump_type (pp
, DECL_ORIGINAL_TYPE (t
)
497 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
), flags
);
504 dump_decl (pp
, t
, flags
& ~TFF_DECL_SPECIFIERS
);
513 case FIXED_POINT_TYPE
:
514 pp_type_specifier_seq (pp
, t
);
517 case TEMPLATE_TEMPLATE_PARM
:
518 /* For parameters inside template signature. */
519 if (TYPE_IDENTIFIER (t
))
520 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
522 pp_cxx_canonical_template_parameter (pp
, t
);
525 case BOUND_TEMPLATE_TEMPLATE_PARM
:
527 tree args
= TYPE_TI_ARGS (t
);
528 pp_cxx_cv_qualifier_seq (pp
, t
);
529 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
530 pp_cxx_begin_template_argument_list (pp
);
531 dump_template_argument_list (pp
, args
, flags
);
532 pp_cxx_end_template_argument_list (pp
);
536 case TEMPLATE_TYPE_PARM
:
537 pp_cxx_cv_qualifier_seq (pp
, t
);
538 if (tree c
= PLACEHOLDER_TYPE_CONSTRAINTS (t
))
539 pp_cxx_constrained_type_spec (pp
, c
);
540 else if (TYPE_IDENTIFIER (t
))
541 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
543 pp_cxx_canonical_template_parameter
544 (pp
, TEMPLATE_TYPE_PARM_INDEX (t
));
547 /* This is not always necessary for pointers and such, but doing this
548 reduces code size. */
557 dump_type_prefix (pp
, t
, flags
);
558 dump_type_suffix (pp
, t
, flags
);
562 if (! (flags
& TFF_CHASE_TYPEDEF
)
563 && DECL_ORIGINAL_TYPE (TYPE_NAME (t
)))
565 dump_decl (pp
, TYPE_NAME (t
), TFF_PLAIN_IDENTIFIER
);
568 pp_cxx_cv_qualifier_seq (pp
, t
);
569 pp_cxx_ws_string (pp
,
570 TYPENAME_IS_ENUM_P (t
) ? "enum"
571 : TYPENAME_IS_CLASS_P (t
) ? "class"
573 dump_typename (pp
, t
, flags
);
576 case UNBOUND_CLASS_TEMPLATE
:
577 if (! (flags
& TFF_UNQUALIFIED_NAME
))
579 dump_type (pp
, TYPE_CONTEXT (t
), flags
);
580 pp_cxx_colon_colon (pp
);
582 pp_cxx_ws_string (pp
, "template");
583 dump_type (pp
, TYPE_IDENTIFIER (t
), flags
);
587 pp_cxx_ws_string (pp
, "__typeof__");
588 pp_cxx_whitespace (pp
);
589 pp_cxx_left_paren (pp
);
590 dump_expr (pp
, TYPEOF_TYPE_EXPR (t
), flags
& ~TFF_EXPR_IN_PARENS
);
591 pp_cxx_right_paren (pp
);
594 case UNDERLYING_TYPE
:
595 pp_cxx_ws_string (pp
, "__underlying_type");
596 pp_cxx_whitespace (pp
);
597 pp_cxx_left_paren (pp
);
598 dump_expr (pp
, UNDERLYING_TYPE_TYPE (t
), flags
& ~TFF_EXPR_IN_PARENS
);
599 pp_cxx_right_paren (pp
);
602 case TYPE_PACK_EXPANSION
:
603 dump_type (pp
, PACK_EXPANSION_PATTERN (t
), flags
);
604 pp_cxx_ws_string (pp
, "...");
607 case TYPE_ARGUMENT_PACK
:
608 dump_template_argument (pp
, t
, flags
);
612 pp_cxx_ws_string (pp
, "decltype");
613 pp_cxx_whitespace (pp
);
614 pp_cxx_left_paren (pp
);
615 dump_expr (pp
, DECLTYPE_TYPE_EXPR (t
), flags
& ~TFF_EXPR_IN_PARENS
);
616 pp_cxx_right_paren (pp
);
620 pp_string (pp
, "std::nullptr_t");
624 pp_unsupported_tree (pp
, t
);
628 pp_string (pp
, M_("<type error>"));
633 /* Dump a TYPENAME_TYPE. We need to notice when the context is itself
637 dump_typename (cxx_pretty_printer
*pp
, tree t
, int flags
)
639 tree ctx
= TYPE_CONTEXT (t
);
641 if (TREE_CODE (ctx
) == TYPENAME_TYPE
)
642 dump_typename (pp
, ctx
, flags
);
644 dump_type (pp
, ctx
, flags
& ~TFF_CLASS_KEY_OR_ENUM
);
645 pp_cxx_colon_colon (pp
);
646 dump_decl (pp
, TYPENAME_TYPE_FULLNAME (t
), flags
);
649 /* Return the name of the supplied aggregate, or enumeral type. */
652 class_key_or_enum_as_string (tree t
)
654 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
656 if (SCOPED_ENUM_P (t
))
661 else if (TREE_CODE (t
) == UNION_TYPE
)
663 else if (TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_DECLARED_CLASS (t
))
669 /* Print out a class declaration T under the control of FLAGS,
670 in the form `class foo'. */
673 dump_aggr_type (cxx_pretty_printer
*pp
, tree t
, int flags
)
676 const char *variety
= class_key_or_enum_as_string (t
);
680 pp_cxx_cv_qualifier_seq (pp
, t
);
682 if (flags
& TFF_CLASS_KEY_OR_ENUM
)
683 pp_cxx_ws_string (pp
, variety
);
685 name
= TYPE_NAME (t
);
689 typdef
= (!DECL_ARTIFICIAL (name
)
690 /* An alias specialization is not considered to be a
692 && !alias_template_specialization_p (t
));
695 && ((flags
& TFF_CHASE_TYPEDEF
)
696 || (!flag_pretty_templates
&& DECL_LANG_SPECIFIC (name
)
697 && DECL_TEMPLATE_INFO (name
))))
698 || DECL_SELF_REFERENCE_P (name
))
700 t
= TYPE_MAIN_VARIANT (t
);
701 name
= TYPE_NAME (t
);
705 tmplate
= !typdef
&& TREE_CODE (t
) != ENUMERAL_TYPE
706 && TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_TEMPLATE_INFO (t
)
707 && (TREE_CODE (CLASSTYPE_TI_TEMPLATE (t
)) != TEMPLATE_DECL
708 || PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t
)));
710 if (! (flags
& TFF_UNQUALIFIED_NAME
))
711 dump_scope (pp
, CP_DECL_CONTEXT (name
), flags
| TFF_SCOPE
);
712 flags
&= ~TFF_UNQUALIFIED_NAME
;
715 /* Because the template names are mangled, we have to locate
716 the most general template, and use that name. */
717 tree tpl
= TYPE_TI_TEMPLATE (t
);
719 while (DECL_TEMPLATE_INFO (tpl
))
720 tpl
= DECL_TI_TEMPLATE (tpl
);
723 name
= DECL_NAME (name
);
726 if (name
== 0 || anon_aggrname_p (name
))
728 if (flags
& TFF_CLASS_KEY_OR_ENUM
)
729 pp_string (pp
, M_("<unnamed>"));
731 pp_printf (pp
, M_("<unnamed %s>"), variety
);
733 else if (LAMBDA_TYPE_P (t
))
735 /* A lambda's "type" is essentially its signature. */
736 pp_string (pp
, M_("<lambda"));
737 if (lambda_function (t
))
739 FUNCTION_FIRST_USER_PARMTYPE (lambda_function (t
)),
744 pp_cxx_tree_identifier (pp
, name
);
746 dump_template_parms (pp
, TYPE_TEMPLATE_INFO (t
),
747 !CLASSTYPE_USE_TEMPLATE (t
),
748 flags
& ~TFF_TEMPLATE_HEADER
);
751 /* Dump into the obstack the initial part of the output for a given type.
752 This is necessary when dealing with things like functions returning
755 return type of `int (* fee ())()': pointer -> function -> int. Both
756 pointer (and reference and offset) and function (and member) types must
757 deal with prefix and suffix.
759 Arrays must also do this for DECL nodes, like int a[], and for things like
763 dump_type_prefix (cxx_pretty_printer
*pp
, tree t
, int flags
)
765 if (TYPE_PTRMEMFUNC_P (t
))
767 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
771 switch (TREE_CODE (t
))
776 tree sub
= TREE_TYPE (t
);
778 dump_type_prefix (pp
, sub
, flags
);
779 if (TREE_CODE (sub
) == ARRAY_TYPE
780 || TREE_CODE (sub
) == FUNCTION_TYPE
)
782 pp_cxx_whitespace (pp
);
783 pp_cxx_left_paren (pp
);
784 pp_c_attributes_display (pp
, TYPE_ATTRIBUTES (sub
));
788 else if (TYPE_REF_P (t
))
790 if (TYPE_REF_IS_RVALUE (t
))
791 pp_ampersand_ampersand (pp
);
795 pp
->padding
= pp_before
;
796 pp_cxx_cv_qualifier_seq (pp
, t
);
802 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
803 if (TREE_CODE (t
) == OFFSET_TYPE
) /* pmfs deal with this in d_t_p */
806 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
807 pp_cxx_left_paren (pp
);
808 dump_type (pp
, TYPE_OFFSET_BASETYPE (t
), flags
);
809 pp_cxx_colon_colon (pp
);
812 pp_cxx_cv_qualifier_seq (pp
, t
);
813 pp
->padding
= pp_before
;
816 /* This can be reached without a pointer when dealing with
817 templates, e.g. std::is_function. */
819 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
823 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
825 pp_cxx_left_paren (pp
);
826 dump_aggr_type (pp
, TYPE_METHOD_BASETYPE (t
), flags
);
827 pp_cxx_colon_colon (pp
);
831 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
835 case IDENTIFIER_NODE
:
840 case TEMPLATE_TYPE_PARM
:
841 case TEMPLATE_TEMPLATE_PARM
:
842 case BOUND_TEMPLATE_TEMPLATE_PARM
:
853 case UNDERLYING_TYPE
:
855 case TYPE_PACK_EXPANSION
:
856 case FIXED_POINT_TYPE
:
858 dump_type (pp
, t
, flags
);
859 pp
->padding
= pp_before
;
863 pp_unsupported_tree (pp
, t
);
866 pp_string (pp
, M_("<typeprefixerror>"));
871 /* Dump the suffix of type T, under control of FLAGS. This is the part
872 which appears after the identifier (or function parms). */
875 dump_type_suffix (cxx_pretty_printer
*pp
, tree t
, int flags
)
877 if (TYPE_PTRMEMFUNC_P (t
))
878 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
880 switch (TREE_CODE (t
))
885 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
886 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
887 pp_cxx_right_paren (pp
);
888 if (TREE_CODE (t
) == POINTER_TYPE
)
889 flags
|= TFF_POINTER
;
890 dump_type_suffix (pp
, TREE_TYPE (t
), flags
);
897 if (TREE_CODE (t
) == METHOD_TYPE
)
898 /* Can only be reached through a pointer. */
899 pp_cxx_right_paren (pp
);
900 arg
= TYPE_ARG_TYPES (t
);
901 if (TREE_CODE (t
) == METHOD_TYPE
)
902 arg
= TREE_CHAIN (arg
);
904 /* Function pointers don't have default args. Not in standard C++,
905 anyway; they may in g++, but we'll just pretend otherwise. */
906 dump_parameters (pp
, arg
, flags
& ~TFF_FUNCTION_DEFAULT_ARGUMENTS
);
908 pp
->padding
= pp_before
;
909 pp_cxx_cv_qualifiers (pp
, type_memfn_quals (t
),
910 TREE_CODE (t
) == FUNCTION_TYPE
911 && (flags
& TFF_POINTER
));
912 dump_ref_qualifier (pp
, t
, flags
);
913 if (tx_safe_fn_type_p (t
))
914 pp_cxx_ws_string (pp
, "transaction_safe");
915 dump_exception_spec (pp
, TYPE_RAISES_EXCEPTIONS (t
), flags
);
916 dump_type_suffix (pp
, TREE_TYPE (t
), flags
);
922 pp_cxx_left_bracket (pp
);
923 if (tree dtype
= TYPE_DOMAIN (t
))
925 tree max
= TYPE_MAX_VALUE (dtype
);
926 /* Zero-length arrays have an upper bound of SIZE_MAX. */
927 if (integer_all_onesp (max
))
928 pp_character (pp
, '0');
929 else if (tree_fits_shwi_p (max
))
930 pp_wide_integer (pp
, tree_to_shwi (max
) + 1);
934 if (TREE_CODE (max
) == SAVE_EXPR
)
935 max
= TREE_OPERAND (max
, 0);
936 if (TREE_CODE (max
) == MINUS_EXPR
937 || TREE_CODE (max
) == PLUS_EXPR
)
939 max
= TREE_OPERAND (max
, 0);
940 while (CONVERT_EXPR_P (max
))
941 max
= TREE_OPERAND (max
, 0);
944 max
= fold_build2_loc (input_location
,
945 PLUS_EXPR
, dtype
, max
,
946 build_int_cst (dtype
, 1));
947 dump_expr (pp
, max
, flags
& ~TFF_EXPR_IN_PARENS
);
950 pp_cxx_right_bracket (pp
);
951 dump_type_suffix (pp
, TREE_TYPE (t
), flags
);
955 case IDENTIFIER_NODE
:
960 case TEMPLATE_TYPE_PARM
:
961 case TEMPLATE_TEMPLATE_PARM
:
962 case BOUND_TEMPLATE_TEMPLATE_PARM
:
973 case UNDERLYING_TYPE
:
975 case TYPE_PACK_EXPANSION
:
976 case FIXED_POINT_TYPE
:
981 pp_unsupported_tree (pp
, t
);
983 /* Don't mark it here, we should have already done in
990 dump_global_iord (cxx_pretty_printer
*pp
, tree t
)
992 const char *p
= NULL
;
994 if (DECL_GLOBAL_CTOR_P (t
))
995 p
= M_("(static initializers for %s)");
996 else if (DECL_GLOBAL_DTOR_P (t
))
997 p
= M_("(static destructors for %s)");
1001 pp_printf (pp
, p
, DECL_SOURCE_FILE (t
));
1005 dump_simple_decl (cxx_pretty_printer
*pp
, tree t
, tree type
, int flags
)
1007 if (flags
& TFF_DECL_SPECIFIERS
)
1009 if (VAR_P (t
) && DECL_DECLARED_CONSTEXPR_P (t
))
1011 if (DECL_LANG_SPECIFIC (t
) && DECL_DECLARED_CONCEPT_P (t
))
1012 pp_cxx_ws_string (pp
, "concept");
1014 pp_cxx_ws_string (pp
, "constexpr");
1016 dump_type_prefix (pp
, type
, flags
& ~TFF_UNQUALIFIED_NAME
);
1017 pp_maybe_space (pp
);
1019 if (! (flags
& TFF_UNQUALIFIED_NAME
)
1020 && TREE_CODE (t
) != PARM_DECL
1021 && (!DECL_INITIAL (t
)
1022 || TREE_CODE (DECL_INITIAL (t
)) != TEMPLATE_PARM_INDEX
))
1023 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1024 flags
&= ~TFF_UNQUALIFIED_NAME
;
1025 if ((flags
& TFF_DECL_SPECIFIERS
)
1026 && DECL_TEMPLATE_PARM_P (t
)
1027 && TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (t
)))
1028 pp_string (pp
, "...");
1031 if (TREE_CODE (t
) == FIELD_DECL
&& DECL_NORMAL_CAPTURE_P (t
))
1034 pp_string (pp
, IDENTIFIER_POINTER (DECL_NAME (t
)) + 2);
1035 pp_string (pp
, " capture>");
1038 dump_decl (pp
, DECL_NAME (t
), flags
);
1040 else if (DECL_DECOMPOSITION_P (t
))
1041 pp_string (pp
, M_("<structured bindings>"));
1043 pp_string (pp
, M_("<anonymous>"));
1044 if (flags
& TFF_DECL_SPECIFIERS
)
1045 dump_type_suffix (pp
, type
, flags
);
1048 /* Print an IDENTIFIER_NODE that is the name of a declaration. */
1051 dump_decl_name (cxx_pretty_printer
*pp
, tree t
, int flags
)
1053 /* These special cases are duplicated here so that other functions
1054 can feed identifiers to error and get them demangled properly. */
1055 if (IDENTIFIER_CONV_OP_P (t
))
1057 pp_cxx_ws_string (pp
, "operator");
1058 /* Not exactly IDENTIFIER_TYPE_VALUE. */
1059 dump_type (pp
, TREE_TYPE (t
), flags
);
1062 if (dguide_name_p (t
))
1064 dump_decl (pp
, CLASSTYPE_TI_TEMPLATE (TREE_TYPE (t
)),
1065 TFF_UNQUALIFIED_NAME
);
1069 const char *str
= IDENTIFIER_POINTER (t
);
1070 if (!strncmp (str
, "_ZGR", 3))
1072 pp_cxx_ws_string (pp
, "<temporary>");
1076 pp_cxx_tree_identifier (pp
, t
);
1079 /* Dump a human readable string for the decl T under control of FLAGS. */
1082 dump_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
1087 /* If doing Objective-C++, give Objective-C a chance to demangle
1088 Objective-C method names. */
1089 if (c_dialect_objc ())
1091 const char *demangled
= objc_maybe_printable_name (t
, flags
);
1094 pp_string (pp
, demangled
);
1099 switch (TREE_CODE (t
))
1102 /* Don't say 'typedef class A' */
1103 if (DECL_ARTIFICIAL (t
) && !DECL_SELF_REFERENCE_P (t
))
1105 if ((flags
& TFF_DECL_SPECIFIERS
)
1106 && TREE_CODE (TREE_TYPE (t
)) == TEMPLATE_TYPE_PARM
)
1108 /* Say `class T' not just `T'. */
1109 pp_cxx_ws_string (pp
, "class");
1111 /* Emit the `...' for a parameter pack. */
1112 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t
)))
1113 pp_cxx_ws_string (pp
, "...");
1116 dump_type (pp
, TREE_TYPE (t
), flags
);
1119 if (TYPE_DECL_ALIAS_P (t
)
1120 && (flags
& TFF_DECL_SPECIFIERS
1121 || flags
& TFF_CLASS_KEY_OR_ENUM
))
1123 pp_cxx_ws_string (pp
, "using");
1124 dump_decl (pp
, DECL_NAME (t
), flags
);
1125 pp_cxx_whitespace (pp
);
1126 pp_cxx_ws_string (pp
, "=");
1127 pp_cxx_whitespace (pp
);
1128 dump_type (pp
, (DECL_ORIGINAL_TYPE (t
)
1129 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
)),
1133 if ((flags
& TFF_DECL_SPECIFIERS
)
1134 && !DECL_SELF_REFERENCE_P (t
))
1135 pp_cxx_ws_string (pp
, "typedef");
1136 dump_simple_decl (pp
, t
, DECL_ORIGINAL_TYPE (t
)
1137 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
),
1142 if (DECL_NAME (t
) && VTABLE_NAME_P (DECL_NAME (t
)))
1144 pp_string (pp
, M_("vtable for "));
1145 gcc_assert (TYPE_P (DECL_CONTEXT (t
)));
1146 dump_type (pp
, DECL_CONTEXT (t
), flags
);
1152 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1154 /* Handle variable template specializations. */
1156 && DECL_LANG_SPECIFIC (t
)
1157 && DECL_TEMPLATE_INFO (t
)
1158 && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t
)))
1160 pp_cxx_begin_template_argument_list (pp
);
1161 tree args
= INNERMOST_TEMPLATE_ARGS (DECL_TI_ARGS (t
));
1162 dump_template_argument_list (pp
, args
, flags
);
1163 pp_cxx_end_template_argument_list (pp
);
1168 pp_string (pp
, M_("<return value> "));
1169 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1172 case NAMESPACE_DECL
:
1173 if (flags
& TFF_DECL_SPECIFIERS
)
1174 pp
->declaration (t
);
1177 if (! (flags
& TFF_UNQUALIFIED_NAME
))
1178 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1179 flags
&= ~TFF_UNQUALIFIED_NAME
;
1180 if (DECL_NAME (t
) == NULL_TREE
)
1182 if (!(pp
->flags
& pp_c_flag_gnu_v3
))
1183 pp_cxx_ws_string (pp
, M_("{anonymous}"));
1185 pp_cxx_ws_string (pp
, M_("(anonymous namespace)"));
1188 pp_cxx_tree_identifier (pp
, DECL_NAME (t
));
1193 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
1194 pp_cxx_colon_colon (pp
);
1195 dump_decl (pp
, TREE_OPERAND (t
, 1), TFF_UNQUALIFIED_NAME
);
1199 dump_decl (pp
, TREE_OPERAND (t
, 0), flags
);
1200 pp_cxx_left_bracket (pp
);
1201 dump_decl (pp
, TREE_OPERAND (t
, 1), flags
);
1202 pp_cxx_right_bracket (pp
);
1205 /* So that we can do dump_decl on an aggr type. */
1209 dump_type (pp
, t
, flags
);
1213 /* This is a pseudo destructor call which has not been folded into
1214 a PSEUDO_DTOR_EXPR yet. */
1215 pp_cxx_complement (pp
);
1216 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
1223 case IDENTIFIER_NODE
:
1224 dump_decl_name (pp
, t
, flags
);
1228 if (!OVL_SINGLE_P (t
))
1230 tree ctx
= ovl_scope (t
);
1231 if (ctx
!= global_namespace
)
1234 dump_type (pp
, ctx
, flags
);
1236 dump_decl (pp
, ctx
, flags
);
1237 pp_cxx_colon_colon (pp
);
1239 dump_decl (pp
, OVL_NAME (t
), flags
);
1243 /* If there's only one function, just treat it like an ordinary
1249 if (! DECL_LANG_SPECIFIC (t
))
1251 if (DECL_ABSTRACT_ORIGIN (t
)
1252 && DECL_ABSTRACT_ORIGIN (t
) != t
)
1253 dump_decl (pp
, DECL_ABSTRACT_ORIGIN (t
), flags
);
1255 dump_function_name (pp
, t
, flags
);
1257 else if (DECL_GLOBAL_CTOR_P (t
) || DECL_GLOBAL_DTOR_P (t
))
1258 dump_global_iord (pp
, t
);
1260 dump_function_decl (pp
, t
, flags
);
1264 dump_template_decl (pp
, t
, flags
);
1267 case TEMPLATE_ID_EXPR
:
1269 tree name
= TREE_OPERAND (t
, 0);
1270 tree args
= TREE_OPERAND (t
, 1);
1272 if (!identifier_p (name
))
1273 name
= OVL_NAME (name
);
1274 dump_decl (pp
, name
, flags
);
1275 pp_cxx_begin_template_argument_list (pp
);
1276 if (args
== error_mark_node
)
1277 pp_string (pp
, M_("<template arguments error>"));
1279 dump_template_argument_list
1280 (pp
, args
, flags
|TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS
);
1281 pp_cxx_end_template_argument_list (pp
);
1286 pp_cxx_tree_identifier (pp
, DECL_NAME (t
));
1290 if ((TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == ENUMERAL_TYPE
)
1291 || (DECL_INITIAL (t
) &&
1292 TREE_CODE (DECL_INITIAL (t
)) == TEMPLATE_PARM_INDEX
))
1293 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1294 else if (DECL_NAME (t
))
1295 dump_decl (pp
, DECL_NAME (t
), flags
);
1296 else if (DECL_INITIAL (t
))
1297 dump_expr (pp
, DECL_INITIAL (t
), flags
| TFF_EXPR_IN_PARENS
);
1299 pp_string (pp
, M_("<enumerator>"));
1304 pp_cxx_ws_string (pp
, "using");
1305 tree scope
= USING_DECL_SCOPE (t
);
1306 bool variadic
= false;
1307 if (PACK_EXPANSION_P (scope
))
1309 scope
= PACK_EXPANSION_PATTERN (scope
);
1312 dump_type (pp
, scope
, flags
);
1313 pp_cxx_colon_colon (pp
);
1314 dump_decl (pp
, DECL_NAME (t
), flags
);
1316 pp_cxx_ws_string (pp
, "...");
1321 pp
->declaration (t
);
1325 dump_decl (pp
, BASELINK_FUNCTIONS (t
), flags
);
1328 case NON_DEPENDENT_EXPR
:
1329 dump_expr (pp
, t
, flags
);
1332 case TEMPLATE_TYPE_PARM
:
1333 if (flags
& TFF_DECL_SPECIFIERS
)
1334 pp
->declaration (t
);
1339 case UNBOUND_CLASS_TEMPLATE
:
1340 case TYPE_PACK_EXPANSION
:
1342 dump_type (pp
, t
, flags
);
1346 pp_unsupported_tree (pp
, t
);
1350 pp_string (pp
, M_("<declaration error>"));
1355 /* Dump a template declaration T under control of FLAGS. This means the
1356 'template <...> leaders plus the 'class X' or 'void fn(...)' part. */
1359 dump_template_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
1361 tree orig_parms
= DECL_TEMPLATE_PARMS (t
);
1365 if (flags
& TFF_TEMPLATE_HEADER
)
1367 for (parms
= orig_parms
= nreverse (orig_parms
);
1369 parms
= TREE_CHAIN (parms
))
1371 tree inner_parms
= INNERMOST_TEMPLATE_PARMS (parms
);
1372 int len
= TREE_VEC_LENGTH (inner_parms
);
1376 /* Skip over the dummy template levels of a template template
1378 gcc_assert (TREE_CODE (TREE_TYPE (t
)) == TEMPLATE_TEMPLATE_PARM
);
1382 pp_cxx_ws_string (pp
, "template");
1383 pp_cxx_begin_template_argument_list (pp
);
1385 /* If we've shown the template prefix, we'd better show the
1386 parameters' and decl's type too. */
1387 flags
|= TFF_DECL_SPECIFIERS
;
1389 for (i
= 0; i
< len
; i
++)
1392 pp_separate_with_comma (pp
);
1393 dump_template_parameter (pp
, TREE_VEC_ELT (inner_parms
, i
),
1396 pp_cxx_end_template_argument_list (pp
);
1397 pp_cxx_whitespace (pp
);
1399 nreverse(orig_parms
);
1401 if (DECL_TEMPLATE_TEMPLATE_PARM_P (t
))
1403 /* Say `template<arg> class TT' not just `template<arg> TT'. */
1404 pp_cxx_ws_string (pp
, "class");
1406 /* If this is a parameter pack, print the ellipsis. */
1407 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t
)))
1408 pp_cxx_ws_string (pp
, "...");
1411 /* Only print the requirements if we're also printing
1412 the template header. */
1414 if (tree ci
= get_constraints (t
))
1415 if (check_constraint_info (ci
))
1416 if (tree reqs
= CI_TEMPLATE_REQS (ci
))
1418 pp_cxx_requires_clause (pp
, reqs
);
1419 pp_cxx_whitespace (pp
);
1424 if (DECL_CLASS_TEMPLATE_P (t
))
1425 dump_type (pp
, TREE_TYPE (t
),
1426 ((flags
& ~TFF_CLASS_KEY_OR_ENUM
) | TFF_TEMPLATE_NAME
1427 | (flags
& TFF_DECL_SPECIFIERS
? TFF_CLASS_KEY_OR_ENUM
: 0)));
1428 else if (DECL_TEMPLATE_RESULT (t
)
1429 && (VAR_P (DECL_TEMPLATE_RESULT (t
))
1430 /* Alias template. */
1431 || DECL_TYPE_TEMPLATE_P (t
)))
1432 dump_decl (pp
, DECL_TEMPLATE_RESULT (t
), flags
| TFF_TEMPLATE_NAME
);
1435 gcc_assert (TREE_TYPE (t
));
1436 switch (NEXT_CODE (t
))
1440 dump_function_decl (pp
, t
, flags
| TFF_TEMPLATE_NAME
);
1443 /* This case can occur with some invalid code. */
1444 dump_type (pp
, TREE_TYPE (t
),
1445 (flags
& ~TFF_CLASS_KEY_OR_ENUM
) | TFF_TEMPLATE_NAME
1446 | (flags
& TFF_DECL_SPECIFIERS
1447 ? TFF_CLASS_KEY_OR_ENUM
: 0));
1452 /* find_typenames looks through the type of the function template T
1453 and returns a vec containing any typedefs, decltypes or TYPENAME_TYPEs
1456 struct find_typenames_t
1458 hash_set
<tree
> *p_set
;
1459 vec
<tree
, va_gc
> *typenames
;
1463 find_typenames_r (tree
*tp
, int *walk_subtrees
, void *data
)
1465 struct find_typenames_t
*d
= (struct find_typenames_t
*)data
;
1466 tree mv
= NULL_TREE
;
1468 if (TYPE_P (*tp
) && is_typedef_decl (TYPE_NAME (*tp
)))
1469 /* Add the type of the typedef without any additional cv-quals. */
1470 mv
= TREE_TYPE (TYPE_NAME (*tp
));
1471 else if (TREE_CODE (*tp
) == TYPENAME_TYPE
1472 || TREE_CODE (*tp
) == DECLTYPE_TYPE
)
1473 /* Add the typename without any cv-qualifiers. */
1474 mv
= TYPE_MAIN_VARIANT (*tp
);
1476 if (PACK_EXPANSION_P (*tp
))
1478 /* Don't mess with parameter packs since we don't remember
1479 the pack expansion context for a particular typename. */
1480 *walk_subtrees
= false;
1484 if (mv
&& (mv
== *tp
|| !d
->p_set
->add (mv
)))
1485 vec_safe_push (d
->typenames
, mv
);
1487 /* Search into class template arguments, which cp_walk_subtrees
1489 if (CLASS_TYPE_P (*tp
) && CLASSTYPE_TEMPLATE_INFO (*tp
))
1490 cp_walk_tree (&CLASSTYPE_TI_ARGS (*tp
), find_typenames_r
,
1496 static vec
<tree
, va_gc
> *
1497 find_typenames (tree t
)
1499 struct find_typenames_t ft
;
1500 ft
.p_set
= new hash_set
<tree
>;
1501 ft
.typenames
= NULL
;
1502 cp_walk_tree (&TREE_TYPE (DECL_TEMPLATE_RESULT (t
)),
1503 find_typenames_r
, &ft
, ft
.p_set
);
1505 return ft
.typenames
;
1508 /* Output the "[with ...]" clause for a template instantiation T iff
1509 TEMPLATE_PARMS, TEMPLATE_ARGS and FLAGS are suitable. T may be NULL if
1510 formatting a deduction/substitution diagnostic rather than an
1514 dump_substitution (cxx_pretty_printer
*pp
,
1515 tree t
, tree template_parms
, tree template_args
,
1518 if (template_parms
!= NULL_TREE
&& template_args
!= NULL_TREE
1519 && !(flags
& TFF_NO_TEMPLATE_BINDINGS
))
1521 vec
<tree
, va_gc
> *typenames
= t
? find_typenames (t
) : NULL
;
1522 pp_cxx_whitespace (pp
);
1523 pp_cxx_left_bracket (pp
);
1524 pp
->translate_string ("with");
1525 pp_cxx_whitespace (pp
);
1526 dump_template_bindings (pp
, template_parms
, template_args
, typenames
);
1527 pp_cxx_right_bracket (pp
);
1531 /* Dump the lambda function FN including its 'mutable' qualifier and any
1532 template bindings. */
1535 dump_lambda_function (cxx_pretty_printer
*pp
,
1536 tree fn
, tree template_parms
, tree template_args
,
1539 /* A lambda's signature is essentially its "type". */
1540 dump_type (pp
, DECL_CONTEXT (fn
), flags
);
1541 if (!(TYPE_QUALS (class_of_this_parm (TREE_TYPE (fn
))) & TYPE_QUAL_CONST
))
1543 pp
->padding
= pp_before
;
1544 pp_c_ws_string (pp
, "mutable");
1546 dump_substitution (pp
, fn
, template_parms
, template_args
, flags
);
1549 /* Pretty print a function decl. There are several ways we want to print a
1550 function declaration. The TFF_ bits in FLAGS tells us how to behave.
1551 As error can only apply the '#' flag once to give 0 and 1 for V, there
1552 is %D which doesn't print the throw specs, and %F which does. */
1555 dump_function_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
1559 tree cname
= NULL_TREE
;
1560 tree template_args
= NULL_TREE
;
1561 tree template_parms
= NULL_TREE
;
1562 int show_return
= flags
& TFF_RETURN_TYPE
|| flags
& TFF_DECL_SPECIFIERS
;
1563 int do_outer_scope
= ! (flags
& TFF_UNQUALIFIED_NAME
);
1566 tree ret
= NULL_TREE
;
1568 flags
&= ~(TFF_UNQUALIFIED_NAME
| TFF_TEMPLATE_NAME
);
1569 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1570 t
= DECL_TEMPLATE_RESULT (t
);
1572 /* Save the exceptions, in case t is a specialization and we are
1573 emitting an error about incompatible specifications. */
1574 exceptions
= TYPE_RAISES_EXCEPTIONS (TREE_TYPE (t
));
1576 /* Likewise for the constexpr specifier, in case t is a specialization. */
1577 constexpr_p
= DECL_DECLARED_CONSTEXPR_P (t
);
1579 /* Pretty print template instantiations only. */
1580 if (DECL_USE_TEMPLATE (t
) && DECL_TEMPLATE_INFO (t
)
1581 && !(flags
& TFF_NO_TEMPLATE_BINDINGS
)
1582 && flag_pretty_templates
)
1586 template_args
= DECL_TI_ARGS (t
);
1587 tmpl
= most_general_template (t
);
1588 if (tmpl
&& TREE_CODE (tmpl
) == TEMPLATE_DECL
)
1590 template_parms
= DECL_TEMPLATE_PARMS (tmpl
);
1595 if (DECL_NAME (t
) && LAMBDA_FUNCTION_P (t
))
1596 return dump_lambda_function (pp
, t
, template_parms
, template_args
, flags
);
1598 fntype
= TREE_TYPE (t
);
1599 parmtypes
= FUNCTION_FIRST_USER_PARMTYPE (t
);
1601 if (DECL_CLASS_SCOPE_P (t
))
1602 cname
= DECL_CONTEXT (t
);
1603 /* This is for partially instantiated template methods. */
1604 else if (TREE_CODE (fntype
) == METHOD_TYPE
)
1605 cname
= TREE_TYPE (TREE_VALUE (parmtypes
));
1607 if (flags
& TFF_DECL_SPECIFIERS
)
1609 if (DECL_STATIC_FUNCTION_P (t
))
1610 pp_cxx_ws_string (pp
, "static");
1611 else if (DECL_VIRTUAL_P (t
))
1612 pp_cxx_ws_string (pp
, "virtual");
1616 if (DECL_DECLARED_CONCEPT_P (t
))
1617 pp_cxx_ws_string (pp
, "concept");
1619 pp_cxx_ws_string (pp
, "constexpr");
1623 /* Print the return type? */
1625 show_return
= (!DECL_CONV_FN_P (t
) && !DECL_CONSTRUCTOR_P (t
)
1626 && !DECL_DESTRUCTOR_P (t
) && !deduction_guide_p (t
));
1629 ret
= fndecl_declared_return_type (t
);
1630 dump_type_prefix (pp
, ret
, flags
);
1633 /* Print the function name. */
1634 if (!do_outer_scope
)
1638 dump_type (pp
, cname
, flags
);
1639 pp_cxx_colon_colon (pp
);
1642 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1644 dump_function_name (pp
, t
, flags
);
1646 if (!(flags
& TFF_NO_FUNCTION_ARGUMENTS
))
1648 dump_parameters (pp
, parmtypes
, flags
);
1650 if (TREE_CODE (fntype
) == METHOD_TYPE
)
1652 pp
->padding
= pp_before
;
1653 pp_cxx_cv_qualifier_seq (pp
, class_of_this_parm (fntype
));
1654 dump_ref_qualifier (pp
, fntype
, flags
);
1657 if (tx_safe_fn_type_p (fntype
))
1659 pp
->padding
= pp_before
;
1660 pp_cxx_ws_string (pp
, "transaction_safe");
1663 if (flags
& TFF_EXCEPTION_SPECIFICATION
)
1665 pp
->padding
= pp_before
;
1666 dump_exception_spec (pp
, exceptions
, flags
);
1670 dump_type_suffix (pp
, ret
, flags
);
1671 else if (deduction_guide_p (t
))
1673 pp_cxx_ws_string (pp
, "->");
1674 dump_type (pp
, TREE_TYPE (TREE_TYPE (t
)), flags
);
1678 if (tree ci
= get_constraints (t
))
1679 if (tree reqs
= CI_DECLARATOR_REQS (ci
))
1680 pp_cxx_requires_clause (pp
, reqs
);
1682 dump_substitution (pp
, t
, template_parms
, template_args
, flags
);
1684 if (tree base
= DECL_INHERITED_CTOR_BASE (t
))
1686 pp_cxx_ws_string (pp
, "[inherited from");
1687 dump_type (pp
, base
, TFF_PLAIN_IDENTIFIER
);
1688 pp_character (pp
, ']');
1691 else if (template_args
)
1693 bool need_comma
= false;
1695 pp_cxx_begin_template_argument_list (pp
);
1696 template_args
= INNERMOST_TEMPLATE_ARGS (template_args
);
1697 for (i
= 0; i
< TREE_VEC_LENGTH (template_args
); ++i
)
1699 tree arg
= TREE_VEC_ELT (template_args
, i
);
1701 pp_separate_with_comma (pp
);
1702 if (ARGUMENT_PACK_P (arg
))
1703 pp_cxx_left_brace (pp
);
1704 dump_template_argument (pp
, arg
, TFF_PLAIN_IDENTIFIER
);
1705 if (ARGUMENT_PACK_P (arg
))
1706 pp_cxx_right_brace (pp
);
1709 pp_cxx_end_template_argument_list (pp
);
1713 /* Print a parameter list. If this is for a member function, the
1714 member object ptr (and any other hidden args) should have
1715 already been removed. */
1718 dump_parameters (cxx_pretty_printer
*pp
, tree parmtypes
, int flags
)
1721 flags
&= ~TFF_SCOPE
;
1722 pp_cxx_left_paren (pp
);
1724 for (first
= 1; parmtypes
!= void_list_node
;
1725 parmtypes
= TREE_CHAIN (parmtypes
))
1728 pp_separate_with_comma (pp
);
1732 pp_cxx_ws_string (pp
, "...");
1736 dump_type (pp
, TREE_VALUE (parmtypes
), flags
);
1738 if ((flags
& TFF_FUNCTION_DEFAULT_ARGUMENTS
) && TREE_PURPOSE (parmtypes
))
1740 pp_cxx_whitespace (pp
);
1742 pp_cxx_whitespace (pp
);
1743 dump_expr (pp
, TREE_PURPOSE (parmtypes
), flags
| TFF_EXPR_IN_PARENS
);
1747 pp_cxx_right_paren (pp
);
1750 /* Print ref-qualifier of a FUNCTION_TYPE or METHOD_TYPE. FLAGS are ignored. */
1753 dump_ref_qualifier (cxx_pretty_printer
*pp
, tree t
, int flags ATTRIBUTE_UNUSED
)
1755 if (FUNCTION_REF_QUALIFIED (t
))
1757 pp
->padding
= pp_before
;
1758 if (FUNCTION_RVALUE_QUALIFIED (t
))
1759 pp_cxx_ws_string (pp
, "&&");
1761 pp_cxx_ws_string (pp
, "&");
1765 /* Print an exception specification. T is the exception specification. */
1768 dump_exception_spec (cxx_pretty_printer
*pp
, tree t
, int flags
)
1770 if (t
&& TREE_PURPOSE (t
))
1772 pp_cxx_ws_string (pp
, "noexcept");
1773 if (!integer_onep (TREE_PURPOSE (t
)))
1775 pp_cxx_whitespace (pp
);
1776 pp_cxx_left_paren (pp
);
1777 if (DEFERRED_NOEXCEPT_SPEC_P (t
))
1778 pp_cxx_ws_string (pp
, "<uninstantiated>");
1780 dump_expr (pp
, TREE_PURPOSE (t
), flags
);
1781 pp_cxx_right_paren (pp
);
1786 pp_cxx_ws_string (pp
, "throw");
1787 pp_cxx_whitespace (pp
);
1788 pp_cxx_left_paren (pp
);
1789 if (TREE_VALUE (t
) != NULL_TREE
)
1792 dump_type (pp
, TREE_VALUE (t
), flags
);
1796 pp_separate_with_comma (pp
);
1798 pp_cxx_right_paren (pp
);
1802 /* Handle the function name for a FUNCTION_DECL node, grokking operators
1803 and destructors properly. */
1806 dump_function_name (cxx_pretty_printer
*pp
, tree t
, int flags
)
1808 tree name
= DECL_NAME (t
);
1810 /* We can get here with a decl that was synthesized by language-
1811 independent machinery (e.g. coverage.c) in which case it won't
1812 have a lang_specific structure attached and DECL_CONSTRUCTOR_P
1813 will crash. In this case it is safe just to print out the
1815 if (!DECL_LANG_SPECIFIC (t
))
1817 pp_cxx_tree_identifier (pp
, name
);
1821 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1822 t
= DECL_TEMPLATE_RESULT (t
);
1824 /* Don't let the user see __comp_ctor et al. */
1825 if (DECL_CONSTRUCTOR_P (t
)
1826 || DECL_DESTRUCTOR_P (t
))
1828 if (LAMBDA_TYPE_P (DECL_CONTEXT (t
)))
1829 name
= get_identifier ("<lambda>");
1830 else if (TYPE_UNNAMED_P (DECL_CONTEXT (t
)))
1831 name
= get_identifier ("<constructor>");
1833 name
= constructor_name (DECL_CONTEXT (t
));
1836 if (DECL_DESTRUCTOR_P (t
))
1838 pp_cxx_complement (pp
);
1839 dump_decl (pp
, name
, TFF_PLAIN_IDENTIFIER
);
1841 else if (DECL_CONV_FN_P (t
))
1843 /* This cannot use the hack that the operator's return
1844 type is stashed off of its name because it may be
1845 used for error reporting. In the case of conflicting
1846 declarations, both will have the same name, yet
1847 the types will be different, hence the TREE_TYPE field
1848 of the first name will be clobbered by the second. */
1849 pp_cxx_ws_string (pp
, "operator");
1850 dump_type (pp
, TREE_TYPE (TREE_TYPE (t
)), flags
);
1853 dump_decl (pp
, name
, flags
);
1855 if (DECL_TEMPLATE_INFO (t
)
1856 && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t
)
1857 && (TREE_CODE (DECL_TI_TEMPLATE (t
)) != TEMPLATE_DECL
1858 || PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t
))))
1859 dump_template_parms (pp
, DECL_TEMPLATE_INFO (t
), !DECL_USE_TEMPLATE (t
),
1863 /* Dump the template parameters from the template info INFO under control of
1864 FLAGS. PRIMARY indicates whether this is a primary template decl, or
1865 specialization (partial or complete). For partial specializations we show
1866 the specialized parameter values. For a primary template we show no
1870 dump_template_parms (cxx_pretty_printer
*pp
, tree info
,
1871 int primary
, int flags
)
1873 tree args
= info
? TI_ARGS (info
) : NULL_TREE
;
1875 if (primary
&& flags
& TFF_TEMPLATE_NAME
)
1877 flags
&= ~(TFF_CLASS_KEY_OR_ENUM
| TFF_TEMPLATE_NAME
);
1878 pp_cxx_begin_template_argument_list (pp
);
1880 /* Be careful only to print things when we have them, so as not
1881 to crash producing error messages. */
1882 if (args
&& !primary
)
1885 len
= get_non_default_template_args_count (args
, flags
);
1887 args
= INNERMOST_TEMPLATE_ARGS (args
);
1888 for (ix
= 0; ix
!= len
; ix
++)
1890 tree arg
= TREE_VEC_ELT (args
, ix
);
1892 /* Only print a comma if we know there is an argument coming. In
1893 the case of an empty template argument pack, no actual
1894 argument will be printed. */
1896 && (!ARGUMENT_PACK_P (arg
)
1897 || TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg
)) > 0))
1898 pp_separate_with_comma (pp
);
1901 pp_string (pp
, M_("<template parameter error>"));
1903 dump_template_argument (pp
, arg
, flags
);
1908 tree tpl
= TI_TEMPLATE (info
);
1909 tree parms
= DECL_TEMPLATE_PARMS (tpl
);
1912 parms
= TREE_CODE (parms
) == TREE_LIST
? TREE_VALUE (parms
) : NULL_TREE
;
1913 len
= parms
? TREE_VEC_LENGTH (parms
) : 0;
1915 for (ix
= 0; ix
!= len
; ix
++)
1919 if (TREE_VEC_ELT (parms
, ix
) == error_mark_node
)
1921 pp_string (pp
, M_("<template parameter error>"));
1925 parm
= TREE_VALUE (TREE_VEC_ELT (parms
, ix
));
1928 pp_separate_with_comma (pp
);
1930 dump_decl (pp
, parm
, flags
& ~TFF_DECL_SPECIFIERS
);
1933 pp_cxx_end_template_argument_list (pp
);
1936 /* Print out the arguments of CALL_EXPR T as a parenthesized list using
1937 flags FLAGS. Skip over the first argument if SKIPFIRST is true. */
1940 dump_call_expr_args (cxx_pretty_printer
*pp
, tree t
, int flags
, bool skipfirst
)
1943 call_expr_arg_iterator iter
;
1945 pp_cxx_left_paren (pp
);
1946 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, t
)
1952 dump_expr (pp
, arg
, flags
| TFF_EXPR_IN_PARENS
);
1953 if (more_call_expr_args_p (&iter
))
1954 pp_separate_with_comma (pp
);
1957 pp_cxx_right_paren (pp
);
1960 /* Print out the arguments of AGGR_INIT_EXPR T as a parenthesized list
1961 using flags FLAGS. Skip over the first argument if SKIPFIRST is
1965 dump_aggr_init_expr_args (cxx_pretty_printer
*pp
, tree t
, int flags
,
1969 aggr_init_expr_arg_iterator iter
;
1971 pp_cxx_left_paren (pp
);
1972 FOR_EACH_AGGR_INIT_EXPR_ARG (arg
, iter
, t
)
1978 dump_expr (pp
, arg
, flags
| TFF_EXPR_IN_PARENS
);
1979 if (more_aggr_init_expr_args_p (&iter
))
1980 pp_separate_with_comma (pp
);
1983 pp_cxx_right_paren (pp
);
1986 /* Print out a list of initializers (subr of dump_expr). */
1989 dump_expr_list (cxx_pretty_printer
*pp
, tree l
, int flags
)
1993 dump_expr (pp
, TREE_VALUE (l
), flags
| TFF_EXPR_IN_PARENS
);
1996 pp_separate_with_comma (pp
);
2000 /* Print out a vector of initializers (subr of dump_expr). */
2003 dump_expr_init_vec (cxx_pretty_printer
*pp
, vec
<constructor_elt
, va_gc
> *v
,
2006 unsigned HOST_WIDE_INT idx
;
2009 FOR_EACH_CONSTRUCTOR_VALUE (v
, idx
, value
)
2011 dump_expr (pp
, value
, flags
| TFF_EXPR_IN_PARENS
);
2012 if (idx
!= v
->length () - 1)
2013 pp_separate_with_comma (pp
);
2018 /* We've gotten an indirect REFERENCE (an OBJ_TYPE_REF) to a virtual
2019 function. Resolve it to a close relative -- in the sense of static
2020 type -- variant being overridden. That is close to what was written in
2021 the source code. Subroutine of dump_expr. */
2024 resolve_virtual_fun_from_obj_type_ref (tree ref
)
2026 tree obj_type
= TREE_TYPE (OBJ_TYPE_REF_OBJECT (ref
));
2027 HOST_WIDE_INT index
= tree_to_uhwi (OBJ_TYPE_REF_TOKEN (ref
));
2028 tree fun
= BINFO_VIRTUALS (TYPE_BINFO (TREE_TYPE (obj_type
)));
2031 fun
= TREE_CHAIN (fun
);
2032 index
-= (TARGET_VTABLE_USES_DESCRIPTORS
2033 ? TARGET_VTABLE_USES_DESCRIPTORS
: 1);
2039 /* Print out an expression E under control of FLAGS. */
2042 dump_expr (cxx_pretty_printer
*pp
, tree t
, int flags
)
2049 if (STATEMENT_CLASS_P (t
))
2051 pp_cxx_ws_string (pp
, M_("<statement>"));
2055 switch (TREE_CODE (t
))
2063 case NAMESPACE_DECL
:
2067 case IDENTIFIER_NODE
:
2068 dump_decl (pp
, t
, ((flags
& ~(TFF_DECL_SPECIFIERS
|TFF_RETURN_TYPE
2069 |TFF_TEMPLATE_HEADER
))
2070 | TFF_NO_TEMPLATE_BINDINGS
2071 | TFF_NO_FUNCTION_ARGUMENTS
));
2075 if (SSA_NAME_VAR (t
)
2076 && !DECL_ARTIFICIAL (SSA_NAME_VAR (t
)))
2077 dump_expr (pp
, SSA_NAME_VAR (t
), flags
);
2079 pp_cxx_ws_string (pp
, M_("<unknown>"));
2090 case USERDEF_LITERAL
:
2091 pp_cxx_userdef_literal (pp
, t
);
2095 /* While waiting for caret diagnostics, avoid printing
2096 __cxa_allocate_exception, __cxa_throw, and the like. */
2097 pp_cxx_ws_string (pp
, M_("<throw-expression>"));
2102 dump_type (pp
, PTRMEM_CST_CLASS (t
), flags
);
2103 pp_cxx_colon_colon (pp
);
2104 pp_cxx_tree_identifier (pp
, DECL_NAME (PTRMEM_CST_MEMBER (t
)));
2108 pp_cxx_left_paren (pp
);
2109 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2110 pp_separate_with_comma (pp
);
2111 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2112 pp_cxx_right_paren (pp
);
2117 pp_cxx_left_paren (pp
);
2118 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2119 pp_string (pp
, " ? ");
2120 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2121 pp_string (pp
, " : ");
2122 dump_expr (pp
, TREE_OPERAND (t
, 2), flags
| TFF_EXPR_IN_PARENS
);
2123 pp_cxx_right_paren (pp
);
2127 if (TREE_HAS_CONSTRUCTOR (t
))
2129 pp_cxx_ws_string (pp
, "new");
2130 pp_cxx_whitespace (pp
);
2131 dump_type (pp
, TREE_TYPE (TREE_TYPE (t
)), flags
);
2134 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2137 case AGGR_INIT_EXPR
:
2139 tree fn
= NULL_TREE
;
2141 if (TREE_CODE (AGGR_INIT_EXPR_FN (t
)) == ADDR_EXPR
)
2142 fn
= TREE_OPERAND (AGGR_INIT_EXPR_FN (t
), 0);
2144 if (fn
&& TREE_CODE (fn
) == FUNCTION_DECL
)
2146 if (DECL_CONSTRUCTOR_P (fn
))
2147 dump_type (pp
, DECL_CONTEXT (fn
), flags
);
2149 dump_decl (pp
, fn
, 0);
2152 dump_expr (pp
, AGGR_INIT_EXPR_FN (t
), 0);
2154 dump_aggr_init_expr_args (pp
, t
, flags
, true);
2159 tree fn
= CALL_EXPR_FN (t
);
2160 bool skipfirst
= false;
2162 /* Deal with internal functions. */
2163 if (fn
== NULL_TREE
)
2165 pp_string (pp
, internal_fn_name (CALL_EXPR_IFN (t
)));
2166 dump_call_expr_args (pp
, t
, flags
, skipfirst
);
2170 if (TREE_CODE (fn
) == ADDR_EXPR
)
2171 fn
= TREE_OPERAND (fn
, 0);
2173 /* Nobody is interested in seeing the guts of vcalls. */
2174 if (TREE_CODE (fn
) == OBJ_TYPE_REF
)
2175 fn
= resolve_virtual_fun_from_obj_type_ref (fn
);
2177 if (TREE_TYPE (fn
) != NULL_TREE
2178 && NEXT_CODE (fn
) == METHOD_TYPE
2179 && call_expr_nargs (t
))
2181 tree ob
= CALL_EXPR_ARG (t
, 0);
2182 if (TREE_CODE (ob
) == ADDR_EXPR
)
2184 dump_expr (pp
, TREE_OPERAND (ob
, 0),
2185 flags
| TFF_EXPR_IN_PARENS
);
2188 else if (!is_this_parameter (ob
))
2190 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2195 if (flag_sanitize
& SANITIZE_UNDEFINED
2196 && is_ubsan_builtin_p (fn
))
2198 pp_string (cxx_pp
, M_("<ubsan routine call>"));
2201 dump_expr (pp
, fn
, flags
| TFF_EXPR_IN_PARENS
);
2202 dump_call_expr_args (pp
, t
, flags
, skipfirst
);
2207 /* Note that this only works for G++ target exprs. If somebody
2208 builds a general TARGET_EXPR, there's no way to represent that
2209 it initializes anything other that the parameter slot for the
2210 default argument. Note we may have cleared out the first
2211 operand in expand_expr, so don't go killing ourselves. */
2212 if (TREE_OPERAND (t
, 1))
2213 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2216 case POINTER_PLUS_EXPR
:
2217 dump_binary_op (pp
, "+", t
, flags
);
2220 case POINTER_DIFF_EXPR
:
2221 dump_binary_op (pp
, "-", t
, flags
);
2226 dump_binary_op (pp
, OVL_OP_INFO (true, NOP_EXPR
)->name
, t
, flags
);
2232 case TRUNC_DIV_EXPR
:
2233 case TRUNC_MOD_EXPR
:
2241 case TRUTH_ANDIF_EXPR
:
2242 case TRUTH_ORIF_EXPR
:
2249 case EXACT_DIV_EXPR
:
2250 dump_binary_op (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
, t
, flags
);
2254 case FLOOR_DIV_EXPR
:
2255 case ROUND_DIV_EXPR
:
2257 dump_binary_op (pp
, "/", t
, flags
);
2261 case FLOOR_MOD_EXPR
:
2262 case ROUND_MOD_EXPR
:
2263 dump_binary_op (pp
, "%", t
, flags
);
2268 tree ob
= TREE_OPERAND (t
, 0);
2269 if (INDIRECT_REF_P (ob
))
2271 ob
= TREE_OPERAND (ob
, 0);
2272 if (!is_this_parameter (ob
))
2274 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2275 if (TYPE_REF_P (TREE_TYPE (ob
)))
2283 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2284 if (TREE_CODE (ob
) != ARROW_EXPR
)
2287 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
& ~TFF_EXPR_IN_PARENS
);
2292 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2293 pp_cxx_left_bracket (pp
);
2294 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2295 pp_cxx_right_bracket (pp
);
2298 case UNARY_PLUS_EXPR
:
2299 dump_unary_op (pp
, "+", t
, flags
);
2303 if (TREE_CODE (TREE_OPERAND (t
, 0)) == FUNCTION_DECL
2304 || TREE_CODE (TREE_OPERAND (t
, 0)) == STRING_CST
2305 /* An ADDR_EXPR can have reference type. In that case, we
2306 shouldn't print the `&' doing so indicates to the user
2307 that the expression has pointer type. */
2309 && TYPE_REF_P (TREE_TYPE (t
))))
2310 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2311 else if (TREE_CODE (TREE_OPERAND (t
, 0)) == LABEL_DECL
)
2312 dump_unary_op (pp
, "&&", t
, flags
);
2314 dump_unary_op (pp
, "&", t
, flags
);
2318 if (TREE_HAS_CONSTRUCTOR (t
))
2320 t
= TREE_OPERAND (t
, 0);
2321 gcc_assert (TREE_CODE (t
) == CALL_EXPR
);
2322 dump_expr (pp
, CALL_EXPR_FN (t
), flags
| TFF_EXPR_IN_PARENS
);
2323 dump_call_expr_args (pp
, t
, flags
, true);
2327 if (TREE_OPERAND (t
,0) != NULL_TREE
2328 && TREE_TYPE (TREE_OPERAND (t
, 0))
2329 && NEXT_CODE (TREE_OPERAND (t
, 0)) == REFERENCE_TYPE
)
2330 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2332 dump_unary_op (pp
, "*", t
, flags
);
2337 if (TREE_CODE (TREE_OPERAND (t
, 0)) == ADDR_EXPR
2338 && integer_zerop (TREE_OPERAND (t
, 1)))
2339 dump_expr (pp
, TREE_OPERAND (TREE_OPERAND (t
, 0), 0), flags
);
2343 if (!integer_zerop (TREE_OPERAND (t
, 1)))
2345 pp_cxx_left_paren (pp
);
2346 if (!integer_onep (TYPE_SIZE_UNIT
2347 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (t
, 0))))))
2349 pp_cxx_left_paren (pp
);
2350 dump_type (pp
, ptr_type_node
, flags
);
2351 pp_cxx_right_paren (pp
);
2354 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2355 if (!integer_zerop (TREE_OPERAND (t
, 1)))
2357 pp_cxx_ws_string (pp
, "+");
2358 dump_expr (pp
, fold_convert (ssizetype
, TREE_OPERAND (t
, 1)),
2360 pp_cxx_right_paren (pp
);
2367 case TRUTH_NOT_EXPR
:
2368 case PREDECREMENT_EXPR
:
2369 case PREINCREMENT_EXPR
:
2370 dump_unary_op (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
, t
, flags
);
2373 case POSTDECREMENT_EXPR
:
2374 case POSTINCREMENT_EXPR
:
2375 pp_cxx_left_paren (pp
);
2376 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2377 pp_cxx_ws_string (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
);
2378 pp_cxx_right_paren (pp
);
2381 case NON_LVALUE_EXPR
:
2382 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
2383 should be another level of INDIRECT_REF so that I don't have to do
2385 if (TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == POINTER_TYPE
)
2387 tree next
= TREE_TYPE (TREE_TYPE (t
));
2389 while (TYPE_PTR_P (next
))
2390 next
= TREE_TYPE (next
);
2392 if (TREE_CODE (next
) == FUNCTION_TYPE
)
2394 if (flags
& TFF_EXPR_IN_PARENS
)
2395 pp_cxx_left_paren (pp
);
2397 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2398 if (flags
& TFF_EXPR_IN_PARENS
)
2399 pp_cxx_right_paren (pp
);
2402 /* Else fall through. */
2404 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2408 case IMPLICIT_CONV_EXPR
:
2409 case VIEW_CONVERT_EXPR
:
2411 tree op
= TREE_OPERAND (t
, 0);
2412 tree ttype
= TREE_TYPE (t
);
2413 tree optype
= TREE_TYPE (op
);
2415 if (TREE_CODE (ttype
) != TREE_CODE (optype
)
2416 && INDIRECT_TYPE_P (ttype
)
2417 && INDIRECT_TYPE_P (optype
)
2418 && same_type_p (TREE_TYPE (optype
),
2421 if (TYPE_REF_P (ttype
))
2424 if (TREE_CODE (op
) == ADDR_EXPR
)
2425 dump_expr (pp
, TREE_OPERAND (op
, 0), flags
);
2427 dump_unary_op (pp
, "*", t
, flags
);
2430 dump_unary_op (pp
, "&", t
, flags
);
2432 else if (!same_type_p (TREE_TYPE (op
), TREE_TYPE (t
)))
2434 /* It is a cast, but we cannot tell whether it is a
2435 reinterpret or static cast. Use the C style notation. */
2436 if (flags
& TFF_EXPR_IN_PARENS
)
2437 pp_cxx_left_paren (pp
);
2438 pp_cxx_left_paren (pp
);
2439 dump_type (pp
, TREE_TYPE (t
), flags
);
2440 pp_cxx_right_paren (pp
);
2441 dump_expr (pp
, op
, flags
| TFF_EXPR_IN_PARENS
);
2442 if (flags
& TFF_EXPR_IN_PARENS
)
2443 pp_cxx_right_paren (pp
);
2446 dump_expr (pp
, op
, flags
);
2451 if (TREE_TYPE (t
) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t
)))
2453 tree idx
= build_ptrmemfunc_access_expr (t
, pfn_identifier
);
2455 if (integer_zerop (idx
))
2457 /* A NULL pointer-to-member constant. */
2458 pp_cxx_left_paren (pp
);
2459 pp_cxx_left_paren (pp
);
2460 dump_type (pp
, TREE_TYPE (t
), flags
);
2461 pp_cxx_right_paren (pp
);
2462 pp_character (pp
, '0');
2463 pp_cxx_right_paren (pp
);
2466 else if (tree_fits_shwi_p (idx
))
2469 unsigned HOST_WIDE_INT n
;
2471 t
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t
)));
2472 t
= TYPE_METHOD_BASETYPE (t
);
2473 virtuals
= BINFO_VIRTUALS (TYPE_BINFO (TYPE_MAIN_VARIANT (t
)));
2475 n
= tree_to_shwi (idx
);
2477 /* Map vtable index back one, to allow for the null pointer to
2481 while (n
> 0 && virtuals
)
2484 virtuals
= TREE_CHAIN (virtuals
);
2488 dump_expr (pp
, BV_FN (virtuals
),
2489 flags
| TFF_EXPR_IN_PARENS
);
2494 if (TREE_TYPE (t
) && LAMBDA_TYPE_P (TREE_TYPE (t
)))
2495 pp_string (pp
, "<lambda closure object>");
2496 if (TREE_TYPE (t
) && EMPTY_CONSTRUCTOR_P (t
))
2498 dump_type (pp
, TREE_TYPE (t
), 0);
2499 pp_cxx_left_paren (pp
);
2500 pp_cxx_right_paren (pp
);
2504 if (!BRACE_ENCLOSED_INITIALIZER_P (t
))
2505 dump_type (pp
, TREE_TYPE (t
), 0);
2506 pp_cxx_left_brace (pp
);
2507 dump_expr_init_vec (pp
, CONSTRUCTOR_ELTS (t
), flags
);
2508 pp_cxx_right_brace (pp
);
2515 tree ob
= TREE_OPERAND (t
, 0);
2516 if (is_dummy_object (ob
))
2518 t
= TREE_OPERAND (t
, 1);
2519 if (TREE_CODE (t
) == FUNCTION_DECL
)
2521 dump_expr (pp
, t
, flags
| TFF_EXPR_IN_PARENS
);
2522 else if (BASELINK_P (t
))
2523 dump_expr (pp
, OVL_FIRST (BASELINK_FUNCTIONS (t
)),
2524 flags
| TFF_EXPR_IN_PARENS
);
2526 dump_decl (pp
, t
, flags
);
2530 if (INDIRECT_REF_P (ob
))
2532 dump_expr (pp
, TREE_OPERAND (ob
, 0), flags
| TFF_EXPR_IN_PARENS
);
2538 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2542 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2547 case TEMPLATE_PARM_INDEX
:
2548 dump_decl (pp
, TEMPLATE_PARM_DECL (t
), flags
& ~TFF_DECL_SPECIFIERS
);
2552 if (TREE_OPERAND (t
, 0) == NULL_TREE
2553 || TREE_CHAIN (TREE_OPERAND (t
, 0)))
2555 dump_type (pp
, TREE_TYPE (t
), flags
);
2556 pp_cxx_left_paren (pp
);
2557 dump_expr_list (pp
, TREE_OPERAND (t
, 0), flags
);
2558 pp_cxx_right_paren (pp
);
2562 pp_cxx_left_paren (pp
);
2563 dump_type (pp
, TREE_TYPE (t
), flags
);
2564 pp_cxx_right_paren (pp
);
2565 pp_cxx_left_paren (pp
);
2566 dump_expr_list (pp
, TREE_OPERAND (t
, 0), flags
);
2567 pp_cxx_right_paren (pp
);
2571 case STATIC_CAST_EXPR
:
2572 pp_cxx_ws_string (pp
, "static_cast");
2574 case REINTERPRET_CAST_EXPR
:
2575 pp_cxx_ws_string (pp
, "reinterpret_cast");
2577 case CONST_CAST_EXPR
:
2578 pp_cxx_ws_string (pp
, "const_cast");
2580 case DYNAMIC_CAST_EXPR
:
2581 pp_cxx_ws_string (pp
, "dynamic_cast");
2583 pp_cxx_begin_template_argument_list (pp
);
2584 dump_type (pp
, TREE_TYPE (t
), flags
);
2585 pp_cxx_end_template_argument_list (pp
);
2586 pp_cxx_left_paren (pp
);
2587 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2588 pp_cxx_right_paren (pp
);
2592 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2598 if (TREE_CODE (t
) == SIZEOF_EXPR
)
2599 pp_cxx_ws_string (pp
, "sizeof");
2602 gcc_assert (TREE_CODE (t
) == ALIGNOF_EXPR
);
2603 pp_cxx_ws_string (pp
, "__alignof__");
2605 op
= TREE_OPERAND (t
, 0);
2606 if (PACK_EXPANSION_P (op
))
2608 pp_string (pp
, "...");
2609 op
= PACK_EXPANSION_PATTERN (op
);
2611 pp_cxx_whitespace (pp
);
2612 pp_cxx_left_paren (pp
);
2613 if (TREE_CODE (t
) == SIZEOF_EXPR
&& SIZEOF_EXPR_TYPE_P (t
))
2614 dump_type (pp
, TREE_TYPE (op
), flags
);
2615 else if (TYPE_P (TREE_OPERAND (t
, 0)))
2616 dump_type (pp
, op
, flags
);
2618 dump_expr (pp
, op
, flags
);
2619 pp_cxx_right_paren (pp
);
2622 case AT_ENCODE_EXPR
:
2623 pp_cxx_ws_string (pp
, "@encode");
2624 pp_cxx_whitespace (pp
);
2625 pp_cxx_left_paren (pp
);
2626 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
2627 pp_cxx_right_paren (pp
);
2631 pp_cxx_ws_string (pp
, "noexcept");
2632 pp_cxx_whitespace (pp
);
2633 pp_cxx_left_paren (pp
);
2634 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2635 pp_cxx_right_paren (pp
);
2640 pp_cxx_ws_string (pp
, OVL_OP_INFO (false, TREE_CODE (t
))->name
);
2641 pp_cxx_whitespace (pp
);
2642 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2646 pp_string (pp
, M_("<unparsed>"));
2649 case TRY_CATCH_EXPR
:
2650 case CLEANUP_POINT_EXPR
:
2651 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2654 case PSEUDO_DTOR_EXPR
:
2655 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2657 if (TREE_OPERAND (t
, 1))
2659 dump_type (pp
, TREE_OPERAND (t
, 1), flags
);
2660 pp_cxx_colon_colon (pp
);
2662 pp_cxx_complement (pp
);
2663 dump_type (pp
, TREE_OPERAND (t
, 2), flags
);
2666 case TEMPLATE_ID_EXPR
:
2667 dump_decl (pp
, t
, flags
);
2673 case STATEMENT_LIST
:
2674 /* We don't yet have a way of dumping statements in a
2675 human-readable format. */
2676 pp_string (pp
, "({...})");
2680 pp_string (pp
, "while (1) { ");
2681 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2682 pp_cxx_right_brace (pp
);
2686 pp_string (pp
, "if (");
2687 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2688 pp_string (pp
, ") break; ");
2692 dump_expr (pp
, BASELINK_FUNCTIONS (t
), flags
& ~TFF_EXPR_IN_PARENS
);
2695 case EMPTY_CLASS_EXPR
:
2696 dump_type (pp
, TREE_TYPE (t
), flags
);
2697 pp_cxx_left_paren (pp
);
2698 pp_cxx_right_paren (pp
);
2701 case NON_DEPENDENT_EXPR
:
2702 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2705 case ARGUMENT_PACK_SELECT
:
2706 dump_template_argument (pp
, ARGUMENT_PACK_SELECT_FROM_PACK (t
), flags
);
2719 pp_type_specifier_seq (pp
, t
);
2723 /* We get here when we want to print a dependent type as an
2724 id-expression, without any disambiguator decoration. */
2725 pp
->id_expression (t
);
2728 case TEMPLATE_TYPE_PARM
:
2729 case TEMPLATE_TEMPLATE_PARM
:
2730 case BOUND_TEMPLATE_TEMPLATE_PARM
:
2731 dump_type (pp
, t
, flags
);
2735 pp_cxx_trait_expression (pp
, t
);
2739 pp_cxx_va_arg_expression (pp
, t
);
2743 pp_cxx_offsetof_expression (pp
, t
);
2746 case ADDRESSOF_EXPR
:
2747 pp_cxx_addressof_expression (pp
, t
);
2751 dump_decl (pp
, t
, flags
);
2754 case EXPR_PACK_EXPANSION
:
2755 case UNARY_LEFT_FOLD_EXPR
:
2756 case UNARY_RIGHT_FOLD_EXPR
:
2757 case BINARY_LEFT_FOLD_EXPR
:
2758 case BINARY_RIGHT_FOLD_EXPR
:
2765 case VEC_DELETE_EXPR
:
2772 case UNORDERED_EXPR
:
2782 case FIX_TRUNC_EXPR
:
2787 case TRUTH_AND_EXPR
:
2789 case TRUTH_XOR_EXPR
:
2790 if (flags
& TFF_EXPR_IN_PARENS
)
2791 pp_cxx_left_paren (pp
);
2793 if (flags
& TFF_EXPR_IN_PARENS
)
2794 pp_cxx_right_paren (pp
);
2798 dump_expr (pp
, resolve_virtual_fun_from_obj_type_ref (t
), flags
);
2802 pp_string (pp
, M_("<lambda>"));
2806 pp_cxx_left_paren (pp
);
2807 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2808 pp_cxx_right_paren (pp
);
2812 pp_cxx_requires_expr (cxx_pp
, t
);
2816 pp_cxx_simple_requirement (cxx_pp
, t
);
2820 pp_cxx_type_requirement (cxx_pp
, t
);
2824 pp_cxx_compound_requirement (cxx_pp
, t
);
2828 pp_cxx_nested_requirement (cxx_pp
, t
);
2841 pp_cxx_constraint (cxx_pp
, t
);
2844 case PLACEHOLDER_EXPR
:
2845 pp_string (pp
, M_("*this"));
2849 dump_expr_list (pp
, t
, flags
);
2852 /* This list is incomplete, but should suffice for now.
2853 It is very important that `sorry' does not call
2854 `report_error_function'. That could cause an infinite loop. */
2856 pp_unsupported_tree (pp
, t
);
2859 pp_string (pp
, M_("<expression error>"));
2865 dump_binary_op (cxx_pretty_printer
*pp
, const char *opstring
, tree t
,
2868 pp_cxx_left_paren (pp
);
2869 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2870 pp_cxx_whitespace (pp
);
2872 pp_cxx_ws_string (pp
, opstring
);
2874 pp_string (pp
, M_("<unknown operator>"));
2875 pp_cxx_whitespace (pp
);
2876 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2877 pp_cxx_right_paren (pp
);
2881 dump_unary_op (cxx_pretty_printer
*pp
, const char *opstring
, tree t
, int flags
)
2883 if (flags
& TFF_EXPR_IN_PARENS
)
2884 pp_cxx_left_paren (pp
);
2885 pp_cxx_ws_string (pp
, opstring
);
2886 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2887 if (flags
& TFF_EXPR_IN_PARENS
)
2888 pp_cxx_right_paren (pp
);
2892 reinit_cxx_pp (void)
2894 pp_clear_output_area (cxx_pp
);
2895 cxx_pp
->padding
= pp_none
;
2896 pp_indentation (cxx_pp
) = 0;
2897 pp_needs_newline (cxx_pp
) = false;
2898 cxx_pp
->enclosing_scope
= current_function_decl
;
2901 /* Same as pp_formatted_text, except the return string is a separate
2902 copy and has a GGC storage duration, e.g. an indefinite lifetime. */
2905 pp_ggc_formatted_text (pretty_printer
*pp
)
2907 return ggc_strdup (pp_formatted_text (pp
));
2910 /* Exported interface to stringifying types, exprs and decls under TFF_*
2914 type_as_string (tree typ
, int flags
)
2917 pp_translate_identifiers (cxx_pp
) = false;
2918 dump_type (cxx_pp
, typ
, flags
);
2919 return pp_ggc_formatted_text (cxx_pp
);
2923 type_as_string_translate (tree typ
, int flags
)
2926 dump_type (cxx_pp
, typ
, flags
);
2927 return pp_ggc_formatted_text (cxx_pp
);
2931 expr_as_string (tree decl
, int flags
)
2934 pp_translate_identifiers (cxx_pp
) = false;
2935 dump_expr (cxx_pp
, decl
, flags
);
2936 return pp_ggc_formatted_text (cxx_pp
);
2939 /* Wrap decl_as_string with options appropriate for dwarf. */
2942 decl_as_dwarf_string (tree decl
, int flags
)
2945 /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag
2946 here will be adequate to get the desired behavior. */
2947 cxx_pp
->flags
|= pp_c_flag_gnu_v3
;
2948 name
= decl_as_string (decl
, flags
);
2949 /* Subsequent calls to the pretty printer shouldn't use this style. */
2950 cxx_pp
->flags
&= ~pp_c_flag_gnu_v3
;
2955 decl_as_string (tree decl
, int flags
)
2958 pp_translate_identifiers (cxx_pp
) = false;
2959 dump_decl (cxx_pp
, decl
, flags
);
2960 return pp_ggc_formatted_text (cxx_pp
);
2964 decl_as_string_translate (tree decl
, int flags
)
2967 dump_decl (cxx_pp
, decl
, flags
);
2968 return pp_ggc_formatted_text (cxx_pp
);
2971 /* Wrap lang_decl_name with options appropriate for dwarf. */
2974 lang_decl_dwarf_name (tree decl
, int v
, bool translate
)
2977 /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag
2978 here will be adequate to get the desired behavior. */
2979 cxx_pp
->flags
|= pp_c_flag_gnu_v3
;
2980 name
= lang_decl_name (decl
, v
, translate
);
2981 /* Subsequent calls to the pretty printer shouldn't use this style. */
2982 cxx_pp
->flags
&= ~pp_c_flag_gnu_v3
;
2986 /* Generate the three forms of printable names for cxx_printable_name. */
2989 lang_decl_name (tree decl
, int v
, bool translate
)
2993 ? decl_as_string_translate (decl
, TFF_DECL_SPECIFIERS
)
2994 : decl_as_string (decl
, TFF_DECL_SPECIFIERS
));
2997 pp_translate_identifiers (cxx_pp
) = translate
;
2999 && (DECL_CLASS_SCOPE_P (decl
)
3000 || (DECL_NAMESPACE_SCOPE_P (decl
)
3001 && CP_DECL_CONTEXT (decl
) != global_namespace
)))
3003 dump_type (cxx_pp
, CP_DECL_CONTEXT (decl
), TFF_PLAIN_IDENTIFIER
);
3004 pp_cxx_colon_colon (cxx_pp
);
3007 if (TREE_CODE (decl
) == FUNCTION_DECL
)
3008 dump_function_name (cxx_pp
, decl
, TFF_PLAIN_IDENTIFIER
);
3009 else if ((DECL_NAME (decl
) == NULL_TREE
)
3010 && TREE_CODE (decl
) == NAMESPACE_DECL
)
3011 dump_decl (cxx_pp
, decl
, TFF_PLAIN_IDENTIFIER
| TFF_UNQUALIFIED_NAME
);
3013 dump_decl (cxx_pp
, DECL_NAME (decl
), TFF_PLAIN_IDENTIFIER
);
3015 return pp_ggc_formatted_text (cxx_pp
);
3018 /* Return the location of a tree passed to %+ formats. */
3021 location_of (tree t
)
3025 t
= TYPE_MAIN_DECL (t
);
3027 return input_location
;
3029 else if (TREE_CODE (t
) == OVERLOAD
)
3033 return DECL_SOURCE_LOCATION (t
);
3034 if (TREE_CODE (t
) == DEFAULT_ARG
)
3035 return defarg_location (t
);
3036 return cp_expr_loc_or_loc (t
, input_location
);
3039 /* Now the interfaces from error et al to dump_type et al. Each takes an
3040 on/off VERBOSE flag and supply the appropriate TFF_ flags to a dump_
3044 decl_to_string (tree decl
, int verbose
)
3048 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == RECORD_TYPE
3049 || TREE_CODE (decl
) == UNION_TYPE
|| TREE_CODE (decl
) == ENUMERAL_TYPE
)
3050 flags
= TFF_CLASS_KEY_OR_ENUM
;
3052 flags
|= TFF_DECL_SPECIFIERS
;
3053 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
3054 flags
|= TFF_DECL_SPECIFIERS
| TFF_RETURN_TYPE
;
3055 flags
|= TFF_TEMPLATE_HEADER
;
3058 dump_decl (cxx_pp
, decl
, flags
);
3059 return pp_ggc_formatted_text (cxx_pp
);
3063 expr_to_string (tree decl
)
3066 dump_expr (cxx_pp
, decl
, 0);
3067 return pp_ggc_formatted_text (cxx_pp
);
3071 fndecl_to_string (tree fndecl
, int verbose
)
3075 flags
= TFF_EXCEPTION_SPECIFICATION
| TFF_DECL_SPECIFIERS
3076 | TFF_TEMPLATE_HEADER
;
3078 flags
|= TFF_FUNCTION_DEFAULT_ARGUMENTS
;
3080 dump_decl (cxx_pp
, fndecl
, flags
);
3081 return pp_ggc_formatted_text (cxx_pp
);
3086 code_to_string (enum tree_code c
)
3088 return get_tree_code_name (c
);
3092 language_to_string (enum languages c
)
3099 case lang_cplusplus
:
3108 /* Return the proper printed version of a parameter to a C++ function. */
3111 parm_to_string (int p
)
3115 pp_string (cxx_pp
, "'this'");
3117 pp_decimal_int (cxx_pp
, p
+ 1);
3118 return pp_ggc_formatted_text (cxx_pp
);
3122 op_to_string (bool assop
, enum tree_code p
)
3124 tree id
= ovl_op_identifier (assop
, p
);
3125 return id
? IDENTIFIER_POINTER (id
) : M_("<unknown>");
3128 /* Return a GC-allocated representation of type TYP, with verbosity VERBOSE.
3130 If QUOTE is non-NULL and if *QUOTE is true, then quotes are added to the
3131 string in appropriate places, and *QUOTE is written to with false
3132 to suppress pp_format's trailing close quote so that e.g.
3133 foo_typedef {aka underlying_foo} {enum}
3134 can be printed by "%qT" as:
3135 `foo_typedef' {aka `underlying_foo'} {enum}
3137 `foo_typedef {aka underlying_foo} {enum}'
3138 When adding such quotes, if POSTPROCESSED is true (for handling %H and %I)
3139 then a leading open quote will be added, whereas if POSTPROCESSED is false
3140 (for handling %T) then any leading quote has already been added by
3141 pp_format, or is not needed due to QUOTE being NULL (for template arguments
3144 SHOW_COLOR is used to determine the colorization of any quotes that
3148 type_to_string (tree typ
, int verbose
, bool postprocessed
, bool *quote
,
3153 flags
|= TFF_CLASS_KEY_OR_ENUM
;
3154 flags
|= TFF_TEMPLATE_HEADER
;
3158 if (postprocessed
&& quote
&& *quote
)
3159 pp_begin_quote (cxx_pp
, show_color
);
3161 struct obstack
*ob
= pp_buffer (cxx_pp
)->obstack
;
3162 int type_start
, type_len
;
3163 type_start
= obstack_object_size (ob
);
3165 dump_type (cxx_pp
, typ
, flags
);
3167 /* Remember the end of the initial dump. */
3168 type_len
= obstack_object_size (ob
) - type_start
;
3170 /* If we're printing a type that involves typedefs, also print the
3171 stripped version. But sometimes the stripped version looks
3172 exactly the same, so we don't want it after all. To avoid printing
3173 it in that case, we play ugly obstack games. */
3174 if (typ
&& TYPE_P (typ
) && typ
!= TYPE_CANONICAL (typ
)
3175 && !uses_template_parms (typ
))
3177 int aka_start
, aka_len
; char *p
;
3178 tree aka
= strip_typedefs (typ
);
3179 if (quote
&& *quote
)
3180 pp_end_quote (cxx_pp
, show_color
);
3181 pp_string (cxx_pp
, " {aka");
3182 pp_cxx_whitespace (cxx_pp
);
3183 if (quote
&& *quote
)
3184 pp_begin_quote (cxx_pp
, show_color
);
3185 /* And remember the start of the aka dump. */
3186 aka_start
= obstack_object_size (ob
);
3187 dump_type (cxx_pp
, aka
, flags
);
3188 aka_len
= obstack_object_size (ob
) - aka_start
;
3189 if (quote
&& *quote
)
3190 pp_end_quote (cxx_pp
, show_color
);
3191 pp_right_brace (cxx_pp
);
3192 p
= (char*)obstack_base (ob
);
3193 /* If they are identical, cut off the aka by unwinding the obstack. */
3194 if (type_len
== aka_len
3195 && memcmp (p
+ type_start
, p
+aka_start
, type_len
) == 0)
3197 /* We can't add a '\0' here, since we may be adding a closing quote
3198 below, and it would be hidden by the '\0'.
3199 Instead, manually unwind the current object within the obstack
3200 so that the insertion point is at the end of the type, before
3202 int delta
= type_start
+ type_len
- obstack_object_size (ob
);
3203 gcc_assert (delta
<= 0);
3204 obstack_blank_fast (ob
, delta
);
3208 /* No further closing quotes are needed. */
3212 if (quote
&& *quote
)
3214 pp_end_quote (cxx_pp
, show_color
);
3217 return pp_ggc_formatted_text (cxx_pp
);
3221 args_to_string (tree p
, int verbose
)
3225 flags
|= TFF_CLASS_KEY_OR_ENUM
;
3230 if (TYPE_P (TREE_VALUE (p
)))
3231 return type_as_string_translate (p
, flags
);
3234 for (; p
; p
= TREE_CHAIN (p
))
3236 if (null_node_p (TREE_VALUE (p
)))
3237 pp_cxx_ws_string (cxx_pp
, "NULL");
3239 dump_type (cxx_pp
, error_type (TREE_VALUE (p
)), flags
);
3241 pp_separate_with_comma (cxx_pp
);
3243 return pp_ggc_formatted_text (cxx_pp
);
3246 /* Pretty-print a deduction substitution (from deduction_tsubst_fntype). P
3247 is a TREE_LIST with purpose the TEMPLATE_DECL, value the template
3251 subst_to_string (tree p
)
3253 tree decl
= TREE_PURPOSE (p
);
3254 tree targs
= TREE_VALUE (p
);
3255 tree tparms
= DECL_TEMPLATE_PARMS (decl
);
3256 int flags
= (TFF_DECL_SPECIFIERS
|TFF_TEMPLATE_HEADER
3257 |TFF_NO_TEMPLATE_BINDINGS
);
3263 dump_template_decl (cxx_pp
, TREE_PURPOSE (p
), flags
);
3264 dump_substitution (cxx_pp
, NULL
, tparms
, targs
, /*flags=*/0);
3265 return pp_ggc_formatted_text (cxx_pp
);
3269 cv_to_string (tree p
, int v
)
3272 cxx_pp
->padding
= v
? pp_before
: pp_none
;
3273 pp_cxx_cv_qualifier_seq (cxx_pp
, p
);
3274 return pp_ggc_formatted_text (cxx_pp
);
3278 eh_spec_to_string (tree p
, int /*v*/)
3282 dump_exception_spec (cxx_pp
, p
, flags
);
3283 return pp_ggc_formatted_text (cxx_pp
);
3286 /* Langhook for print_error_function. */
3288 cxx_print_error_function (diagnostic_context
*context
, const char *file
,
3289 diagnostic_info
*diagnostic
)
3293 prefix
= xstrdup (file
);
3296 lhd_print_error_function (context
, file
, diagnostic
);
3297 pp_set_prefix (context
->printer
, prefix
);
3298 maybe_print_instantiation_context (context
);
3302 cp_diagnostic_starter (diagnostic_context
*context
,
3303 diagnostic_info
*diagnostic
)
3305 diagnostic_report_current_module (context
, diagnostic_location (diagnostic
));
3306 cp_print_error_function (context
, diagnostic
);
3307 maybe_print_instantiation_context (context
);
3308 maybe_print_constexpr_context (context
);
3309 pp_set_prefix (context
->printer
, diagnostic_build_prefix (context
,
3313 /* Print current function onto BUFFER, in the process of reporting
3314 a diagnostic message. Called from cp_diagnostic_starter. */
3316 cp_print_error_function (diagnostic_context
*context
,
3317 diagnostic_info
*diagnostic
)
3319 /* If we are in an instantiation context, current_function_decl is likely
3320 to be wrong, so just rely on print_instantiation_full_context. */
3321 if (current_instantiation ())
3323 if (diagnostic_last_function_changed (context
, diagnostic
))
3325 char *old_prefix
= pp_take_prefix (context
->printer
);
3326 const char *file
= LOCATION_FILE (diagnostic_location (diagnostic
));
3327 tree abstract_origin
= diagnostic_abstract_origin (diagnostic
);
3328 char *new_prefix
= (file
&& abstract_origin
== NULL
)
3329 ? file_name_as_prefix (context
, file
) : NULL
;
3331 pp_set_prefix (context
->printer
, new_prefix
);
3333 if (current_function_decl
== NULL
)
3334 pp_string (context
->printer
, _("At global scope:"));
3339 if (abstract_origin
)
3341 ao
= BLOCK_ABSTRACT_ORIGIN (abstract_origin
);
3342 while (TREE_CODE (ao
) == BLOCK
3343 && BLOCK_ABSTRACT_ORIGIN (ao
)
3344 && BLOCK_ABSTRACT_ORIGIN (ao
) != ao
)
3345 ao
= BLOCK_ABSTRACT_ORIGIN (ao
);
3346 gcc_assert (TREE_CODE (ao
) == FUNCTION_DECL
);
3350 fndecl
= current_function_decl
;
3352 pp_printf (context
->printer
, function_category (fndecl
),
3353 cxx_printable_name_translate (fndecl
, 2));
3355 while (abstract_origin
)
3358 tree block
= abstract_origin
;
3360 locus
= &BLOCK_SOURCE_LOCATION (block
);
3362 block
= BLOCK_SUPERCONTEXT (block
);
3363 while (block
&& TREE_CODE (block
) == BLOCK
3364 && BLOCK_ABSTRACT_ORIGIN (block
))
3366 ao
= BLOCK_ABSTRACT_ORIGIN (block
);
3368 while (TREE_CODE (ao
) == BLOCK
3369 && BLOCK_ABSTRACT_ORIGIN (ao
)
3370 && BLOCK_ABSTRACT_ORIGIN (ao
) != ao
)
3371 ao
= BLOCK_ABSTRACT_ORIGIN (ao
);
3373 if (TREE_CODE (ao
) == FUNCTION_DECL
)
3378 else if (TREE_CODE (ao
) != BLOCK
)
3381 block
= BLOCK_SUPERCONTEXT (block
);
3384 abstract_origin
= block
;
3387 while (block
&& TREE_CODE (block
) == BLOCK
)
3388 block
= BLOCK_SUPERCONTEXT (block
);
3390 if (block
&& TREE_CODE (block
) == FUNCTION_DECL
)
3392 abstract_origin
= NULL
;
3396 expanded_location s
= expand_location (*locus
);
3397 pp_character (context
->printer
, ',');
3398 pp_newline (context
->printer
);
3401 if (context
->show_column
&& s
.column
!= 0)
3402 pp_printf (context
->printer
,
3403 _(" inlined from %qs at %r%s:%d:%d%R"),
3404 cxx_printable_name_translate (fndecl
, 2),
3405 "locus", s
.file
, s
.line
, s
.column
);
3407 pp_printf (context
->printer
,
3408 _(" inlined from %qs at %r%s:%d%R"),
3409 cxx_printable_name_translate (fndecl
, 2),
3410 "locus", s
.file
, s
.line
);
3414 pp_printf (context
->printer
, _(" inlined from %qs"),
3415 cxx_printable_name_translate (fndecl
, 2));
3418 pp_character (context
->printer
, ':');
3420 pp_newline (context
->printer
);
3422 diagnostic_set_last_function (context
, diagnostic
);
3423 pp_destroy_prefix (context
->printer
);
3424 context
->printer
->prefix
= old_prefix
;
3428 /* Returns a description of FUNCTION using standard terminology. The
3429 result is a format string of the form "In CATEGORY %qs". */
3431 function_category (tree fn
)
3433 /* We can get called from the middle-end for diagnostics of function
3434 clones. Make sure we have language specific information before
3435 dereferencing it. */
3436 if (DECL_LANG_SPECIFIC (STRIP_TEMPLATE (fn
))
3437 && DECL_FUNCTION_MEMBER_P (fn
))
3439 if (DECL_STATIC_FUNCTION_P (fn
))
3440 return _("In static member function %qs");
3441 else if (DECL_COPY_CONSTRUCTOR_P (fn
))
3442 return _("In copy constructor %qs");
3443 else if (DECL_CONSTRUCTOR_P (fn
))
3444 return _("In constructor %qs");
3445 else if (DECL_DESTRUCTOR_P (fn
))
3446 return _("In destructor %qs");
3447 else if (LAMBDA_FUNCTION_P (fn
))
3448 return _("In lambda function");
3450 return _("In member function %qs");
3453 return _("In function %qs");
3456 /* Report the full context of a current template instantiation,
3459 print_instantiation_full_context (diagnostic_context
*context
)
3461 struct tinst_level
*p
= current_instantiation ();
3462 location_t location
= input_location
;
3466 pp_verbatim (context
->printer
,
3468 ? _("%s: In substitution of %qS:\n")
3469 : _("%s: In instantiation of %q#D:\n"),
3470 LOCATION_FILE (location
),
3473 location
= p
->locus
;
3477 print_instantiation_partial_context (context
, p
, location
);
3480 /* Helper function of print_instantiation_partial_context() that
3481 prints a single line of instantiation context. */
3484 print_instantiation_partial_context_line (diagnostic_context
*context
,
3485 struct tinst_level
*t
,
3486 location_t loc
, bool recursive_p
)
3488 if (loc
== UNKNOWN_LOCATION
)
3491 expanded_location xloc
= expand_location (loc
);
3493 if (context
->show_column
)
3494 pp_verbatim (context
->printer
, _("%r%s:%d:%d:%R "),
3495 "locus", xloc
.file
, xloc
.line
, xloc
.column
);
3497 pp_verbatim (context
->printer
, _("%r%s:%d:%R "),
3498 "locus", xloc
.file
, xloc
.line
);
3503 pp_verbatim (context
->printer
,
3505 ? _("recursively required by substitution of %qS\n")
3506 : _("required by substitution of %qS\n"),
3509 pp_verbatim (context
->printer
,
3511 ? _("recursively required from %q#D\n")
3512 : _("required from %q#D\n"),
3517 pp_verbatim (context
->printer
,
3519 ? _("recursively required from here\n")
3520 : _("required from here\n"));
3524 /* Same as print_instantiation_full_context but less verbose. */
3527 print_instantiation_partial_context (diagnostic_context
*context
,
3528 struct tinst_level
*t0
, location_t loc
)
3530 struct tinst_level
*t
;
3533 location_t prev_loc
= loc
;
3535 for (t
= t0
; t
!= NULL
; t
= t
->next
)
3536 if (prev_loc
!= t
->locus
)
3538 prev_loc
= t
->locus
;
3544 if (template_backtrace_limit
3545 && n_total
> template_backtrace_limit
)
3547 int skip
= n_total
- template_backtrace_limit
;
3548 int head
= template_backtrace_limit
/ 2;
3550 /* Avoid skipping just 1. If so, skip 2. */
3554 head
= (template_backtrace_limit
- 1) / 2;
3557 for (n
= 0; n
< head
; n
++)
3559 gcc_assert (t
!= NULL
);
3560 if (loc
!= t
->locus
)
3561 print_instantiation_partial_context_line (context
, t
, loc
,
3562 /*recursive_p=*/false);
3566 if (t
!= NULL
&& skip
> 0)
3568 expanded_location xloc
;
3569 xloc
= expand_location (loc
);
3570 if (context
->show_column
)
3571 pp_verbatim (context
->printer
,
3572 _("%r%s:%d:%d:%R [ skipping %d instantiation "
3573 "contexts, use -ftemplate-backtrace-limit=0 to "
3575 "locus", xloc
.file
, xloc
.line
, xloc
.column
, skip
);
3577 pp_verbatim (context
->printer
,
3578 _("%r%s:%d:%R [ skipping %d instantiation "
3579 "contexts, use -ftemplate-backtrace-limit=0 to "
3581 "locus", xloc
.file
, xloc
.line
, skip
);
3586 } while (t
!= NULL
&& --skip
> 0);
3592 while (t
->next
!= NULL
&& t
->locus
== t
->next
->locus
)
3597 print_instantiation_partial_context_line (context
, t
, loc
,
3602 print_instantiation_partial_context_line (context
, NULL
, loc
,
3603 /*recursive_p=*/false);
3606 /* Called from cp_thing to print the template context for an error. */
3608 maybe_print_instantiation_context (diagnostic_context
*context
)
3610 if (!problematic_instantiation_changed () || current_instantiation () == 0)
3613 record_last_problematic_instantiation ();
3614 print_instantiation_full_context (context
);
3617 /* Report what constexpr call(s) we're trying to expand, if any. */
3620 maybe_print_constexpr_context (diagnostic_context
*context
)
3622 vec
<tree
> call_stack
= cx_error_context ();
3626 FOR_EACH_VEC_ELT (call_stack
, ix
, t
)
3628 expanded_location xloc
= expand_location (EXPR_LOCATION (t
));
3629 const char *s
= expr_as_string (t
, 0);
3630 if (context
->show_column
)
3631 pp_verbatim (context
->printer
,
3632 _("%r%s:%d:%d:%R in %<constexpr%> expansion of %qs"),
3633 "locus", xloc
.file
, xloc
.line
, xloc
.column
, s
);
3635 pp_verbatim (context
->printer
,
3636 _("%r%s:%d:%R in %<constexpr%> expansion of %qs"),
3637 "locus", xloc
.file
, xloc
.line
, s
);
3638 pp_newline (context
->printer
);
3643 /* Return true iff TYPE_A and TYPE_B are template types that are
3644 meaningful to compare. */
3647 comparable_template_types_p (tree type_a
, tree type_b
)
3649 if (!CLASS_TYPE_P (type_a
))
3651 if (!CLASS_TYPE_P (type_b
))
3654 tree tinfo_a
= TYPE_TEMPLATE_INFO (type_a
);
3655 tree tinfo_b
= TYPE_TEMPLATE_INFO (type_b
);
3656 if (!tinfo_a
|| !tinfo_b
)
3659 return TI_TEMPLATE (tinfo_a
) == TI_TEMPLATE (tinfo_b
);
3662 /* Start a new line indented by SPC spaces on PP. */
3665 newline_and_indent (pretty_printer
*pp
, int spc
)
3668 for (int i
= 0; i
< spc
; i
++)
3672 /* Generate a GC-allocated string for ARG, an expression or type. */
3675 arg_to_string (tree arg
, bool verbose
)
3678 return type_to_string (arg
, verbose
, true, NULL
, false);
3680 return expr_to_string (arg
);
3683 /* Subroutine to type_to_string_with_compare and
3684 print_template_tree_comparison.
3686 Print a representation of ARG (an expression or type) to PP,
3687 colorizing it as "type-diff" if PP->show_color. */
3690 print_nonequal_arg (pretty_printer
*pp
, tree arg
, bool verbose
)
3692 pp_printf (pp
, "%r%s%R",
3695 ? arg_to_string (arg
, verbose
)
3696 : G_("(no argument)")));
3699 /* Recursively print template TYPE_A to PP, as compared to template TYPE_B.
3701 The types must satisfy comparable_template_types_p.
3703 If INDENT is 0, then this is equivalent to type_to_string (TYPE_A), but
3704 potentially colorizing/eliding in comparison with TYPE_B.
3706 For example given types:
3707 vector<map<int,double>>
3709 vector<map<int,float>>
3710 then the result on PP would be:
3711 vector<map<[...],double>>
3712 with type elision, and:
3713 vector<map<int,double>>
3714 without type elision.
3716 In both cases the parts of TYPE that differ from PEER will be colorized
3717 if pp_show_color (pp) is true. In the above example, this would be
3720 If INDENT is non-zero, then the types are printed in a tree-like form
3721 which shows both types. In the above example, the result on PP would be:
3728 and without type-elision would be:
3735 As before, the differing parts of the types are colorized if
3736 pp_show_color (pp) is true ("double" and "float" in this example).
3738 Template arguments in which both types are using the default arguments
3739 are not printed; if at least one of the two types is using a non-default
3740 argument, then that argument is printed (or both arguments for the
3741 tree-like print format). */
3744 print_template_differences (pretty_printer
*pp
, tree type_a
, tree type_b
,
3745 bool verbose
, int indent
)
3748 newline_and_indent (pp
, indent
);
3750 tree tinfo_a
= TYPE_TEMPLATE_INFO (type_a
);
3751 tree tinfo_b
= TYPE_TEMPLATE_INFO (type_b
);
3753 pp_printf (pp
, "%s<",
3754 IDENTIFIER_POINTER (DECL_NAME (TI_TEMPLATE (tinfo_a
))));
3756 tree args_a
= TI_ARGS (tinfo_a
);
3757 tree args_b
= TI_ARGS (tinfo_b
);
3758 gcc_assert (TREE_CODE (args_a
) == TREE_VEC
);
3759 gcc_assert (TREE_CODE (args_b
) == TREE_VEC
);
3761 int len_a
= get_non_default_template_args_count (args_a
, flags
);
3762 args_a
= INNERMOST_TEMPLATE_ARGS (args_a
);
3763 int len_b
= get_non_default_template_args_count (args_b
, flags
);
3764 args_b
= INNERMOST_TEMPLATE_ARGS (args_b
);
3765 /* Determine the maximum range of args for which non-default template args
3766 were used; beyond this, only default args (if any) were used, and so
3767 they will be equal from this point onwards.
3768 One of the two peers might have used default arguments within this
3769 range, but the other will be using non-default arguments, and so
3770 it's more readable to print both within this range, to highlight
3772 int len_max
= MAX (len_a
, len_b
);
3773 gcc_assert (TREE_CODE (args_a
) == TREE_VEC
);
3774 gcc_assert (TREE_CODE (args_b
) == TREE_VEC
);
3775 for (int idx
= 0; idx
< len_max
; idx
++)
3778 pp_character (pp
, ',');
3780 tree arg_a
= TREE_VEC_ELT (args_a
, idx
);
3781 tree arg_b
= TREE_VEC_ELT (args_b
, idx
);
3785 newline_and_indent (pp
, indent
+ 2);
3786 /* Can do elision here, printing "[...]". */
3787 if (flag_elide_type
)
3788 pp_string (pp
, G_("[...]"));
3790 pp_string (pp
, arg_to_string (arg_a
, verbose
));
3794 int new_indent
= indent
? indent
+ 2 : 0;
3795 if (comparable_template_types_p (arg_a
, arg_b
))
3796 print_template_differences (pp
, arg_a
, arg_b
, verbose
, new_indent
);
3800 newline_and_indent (pp
, indent
+ 2);
3801 pp_character (pp
, '[');
3802 print_nonequal_arg (pp
, arg_a
, verbose
);
3803 pp_string (pp
, " != ");
3804 print_nonequal_arg (pp
, arg_b
, verbose
);
3805 pp_character (pp
, ']');
3808 print_nonequal_arg (pp
, arg_a
, verbose
);
3811 pp_printf (pp
, ">");
3814 /* As type_to_string, but for a template, potentially colorizing/eliding
3815 in comparison with PEER.
3816 For example, if TYPE is map<int,double> and PEER is map<int,int>,
3817 then the resulting string would be:
3819 with type elision, and:
3821 without type elision.
3823 In both cases the parts of TYPE that differ from PEER will be colorized
3824 if SHOW_COLOR is true. In the above example, this would be "double".
3826 Template arguments in which both types are using the default arguments
3827 are not printed; if at least one of the two types is using a non-default
3828 argument, then both arguments are printed.
3830 The resulting string is in a GC-allocated buffer. */
3833 type_to_string_with_compare (tree type
, tree peer
, bool verbose
,
3836 pretty_printer inner_pp
;
3837 pretty_printer
*pp
= &inner_pp
;
3838 pp_show_color (pp
) = show_color
;
3840 print_template_differences (pp
, type
, peer
, verbose
, 0);
3841 return pp_ggc_formatted_text (pp
);
3844 /* Recursively print a tree-like comparison of TYPE_A and TYPE_B to PP,
3845 indented by INDENT spaces.
3847 For example given types:
3849 vector<map<int,double>>
3853 vector<map<double,float>>
3855 the output with type elision would be:
3862 and without type-elision would be:
3869 TYPE_A and TYPE_B must both be comparable template types
3870 (as per comparable_template_types_p).
3872 Template arguments in which both types are using the default arguments
3873 are not printed; if at least one of the two types is using a non-default
3874 argument, then both arguments are printed. */
3877 print_template_tree_comparison (pretty_printer
*pp
, tree type_a
, tree type_b
,
3878 bool verbose
, int indent
)
3880 print_template_differences (pp
, type_a
, type_b
, verbose
, indent
);
3883 /* Subroutine for use in a format_postprocessor::handle
3884 implementation. Adds a chunk to the end of
3885 formatted output, so that it will be printed
3886 by pp_output_formatted_text. */
3889 append_formatted_chunk (pretty_printer
*pp
, const char *content
)
3891 output_buffer
*buffer
= pp_buffer (pp
);
3892 struct chunk_info
*chunk_array
= buffer
->cur_chunk_array
;
3893 const char **args
= chunk_array
->args
;
3895 unsigned int chunk_idx
;
3896 for (chunk_idx
= 0; args
[chunk_idx
]; chunk_idx
++)
3898 args
[chunk_idx
++] = content
;
3899 args
[chunk_idx
] = NULL
;
3902 /* Create a copy of CONTENT, with quotes added, and,
3903 potentially, with colorization.
3904 No escaped is performed on CONTENT.
3905 The result is in a GC-allocated buffer. */
3908 add_quotes (const char *content
, bool show_color
)
3910 pretty_printer tmp_pp
;
3911 pp_show_color (&tmp_pp
) = show_color
;
3913 /* We have to use "%<%s%>" rather than "%qs" here in order to avoid
3914 quoting colorization bytes within the results. */
3915 pp_printf (&tmp_pp
, "%<%s%>", content
);
3917 return pp_ggc_formatted_text (&tmp_pp
);
3920 /* If we had %H and %I, and hence deferred printing them,
3921 print them now, storing the result into the chunk_info
3922 for pp_format. Quote them if 'q' was provided.
3923 Also print the difference in tree form, adding it as
3924 an additional chunk. */
3927 cxx_format_postprocessor::handle (pretty_printer
*pp
)
3929 /* If we have one of %H and %I, the other should have
3931 if (m_type_a
.m_tree
|| m_type_b
.m_tree
)
3933 /* Avoid reentrancy issues by working with a copy of
3934 m_type_a and m_type_b, resetting them now. */
3935 deferred_printed_type type_a
= m_type_a
;
3936 deferred_printed_type type_b
= m_type_b
;
3937 m_type_a
= deferred_printed_type ();
3938 m_type_b
= deferred_printed_type ();
3940 gcc_assert (type_a
.m_buffer_ptr
);
3941 gcc_assert (type_b
.m_buffer_ptr
);
3943 bool show_color
= pp_show_color (pp
);
3945 const char *type_a_text
;
3946 const char *type_b_text
;
3948 if (comparable_template_types_p (type_a
.m_tree
, type_b
.m_tree
))
3951 = type_to_string_with_compare (type_a
.m_tree
, type_b
.m_tree
,
3952 type_a
.m_verbose
, show_color
);
3954 = type_to_string_with_compare (type_b
.m_tree
, type_a
.m_tree
,
3955 type_b
.m_verbose
, show_color
);
3957 if (flag_diagnostics_show_template_tree
)
3959 pretty_printer inner_pp
;
3960 pp_show_color (&inner_pp
) = pp_show_color (pp
);
3961 print_template_tree_comparison
3962 (&inner_pp
, type_a
.m_tree
, type_b
.m_tree
, type_a
.m_verbose
, 2);
3963 append_formatted_chunk (pp
, pp_ggc_formatted_text (&inner_pp
));
3968 /* If the types were not comparable (or if only one of %H/%I was
3969 provided), they are printed normally, and no difference tree
3971 type_a_text
= type_to_string (type_a
.m_tree
, type_a
.m_verbose
,
3972 true, &type_a
.m_quote
, show_color
);
3973 type_b_text
= type_to_string (type_b
.m_tree
, type_b
.m_verbose
,
3974 true, &type_b
.m_quote
, show_color
);
3978 type_a_text
= add_quotes (type_a_text
, show_color
);
3979 *type_a
.m_buffer_ptr
= type_a_text
;
3982 type_b_text
= add_quotes (type_b_text
, show_color
);
3983 *type_b
.m_buffer_ptr
= type_b_text
;
3987 /* Subroutine for handling %H and %I, to support i18n of messages like:
3989 error_at (loc, "could not convert %qE from %qH to %qI",
3990 expr, type_a, type_b);
3992 so that we can print things like:
3994 could not convert 'foo' from 'map<int,double>' to 'map<int,int>'
3996 and, with type-elision:
3998 could not convert 'foo' from 'map<[...],double>' to 'map<[...],int>'
4000 (with color-coding of the differences between the types).
4002 The %H and %I format codes are peers: both must be present,
4003 and they affect each other. Hence to handle them, we must
4004 delay printing until we have both, deferring the printing to
4005 pretty_printer's m_format_postprocessor hook.
4007 This is called in phase 2 of pp_format, when it is accumulating
4008 a series of formatted chunks. We stash the location of the chunk
4009 we're meant to have written to, so that we can write to it in the
4010 m_format_postprocessor hook.
4012 We also need to stash whether a 'q' prefix was provided (the QUOTE
4013 param) so that we can add the quotes when writing out the delayed
4017 defer_phase_2_of_type_diff (deferred_printed_type
*deferred
,
4018 tree type
, const char **buffer_ptr
,
4019 bool verbose
, bool quote
)
4021 gcc_assert (deferred
->m_tree
== NULL_TREE
);
4022 gcc_assert (deferred
->m_buffer_ptr
== NULL
);
4023 *deferred
= deferred_printed_type (type
, buffer_ptr
, verbose
, quote
);
4027 /* Called from output_format -- during diagnostic message processing --
4028 to handle C++ specific format specifier with the following meanings:
4029 %A function argument-list.
4033 %F function declaration.
4035 %H type difference (from).
4036 %I type difference (to).
4038 %L language as used in extern "lang".
4040 %P function parameter whose position is indicated by an integer.
4041 %Q assignment operator.
4042 %S substitution (template + args)
4045 %X exception-specification. */
4047 cp_printer (pretty_printer
*pp
, text_info
*text
, const char *spec
,
4048 int precision
, bool wide
, bool set_locus
, bool verbose
,
4049 bool *quoted
, const char **buffer_ptr
)
4051 gcc_assert (pp
->m_format_postprocessor
);
4052 cxx_format_postprocessor
*postprocessor
4053 = static_cast <cxx_format_postprocessor
*> (pp
->m_format_postprocessor
);
4057 #define next_tree (t = va_arg (*text->args_ptr, tree))
4058 #define next_tcode ((enum tree_code) va_arg (*text->args_ptr, int))
4059 #define next_lang ((enum languages) va_arg (*text->args_ptr, int))
4060 #define next_int va_arg (*text->args_ptr, int)
4062 if (precision
!= 0 || wide
)
4067 case 'A': result
= args_to_string (next_tree
, verbose
); break;
4068 case 'C': result
= code_to_string (next_tcode
); break;
4071 tree temp
= next_tree
;
4073 && DECL_HAS_DEBUG_EXPR_P (temp
))
4075 temp
= DECL_DEBUG_EXPR (temp
);
4078 result
= expr_to_string (temp
);
4082 result
= decl_to_string (temp
, verbose
);
4085 case 'E': result
= expr_to_string (next_tree
); break;
4086 case 'F': result
= fndecl_to_string (next_tree
, verbose
); break;
4088 percent_G_format (text
);
4091 defer_phase_2_of_type_diff (&postprocessor
->m_type_a
, next_tree
,
4092 buffer_ptr
, verbose
, *quoted
);
4095 defer_phase_2_of_type_diff (&postprocessor
->m_type_b
, next_tree
,
4096 buffer_ptr
, verbose
, *quoted
);
4099 t
= va_arg (*text
->args_ptr
, tree
);
4100 percent_K_format (text
, EXPR_LOCATION (t
), TREE_BLOCK (t
));
4102 case 'L': result
= language_to_string (next_lang
); break;
4103 case 'O': result
= op_to_string (false, next_tcode
); break;
4104 case 'P': result
= parm_to_string (next_int
); break;
4105 case 'Q': result
= op_to_string (true, next_tcode
); break;
4106 case 'S': result
= subst_to_string (next_tree
); break;
4109 result
= type_to_string (next_tree
, verbose
, false, quoted
,
4110 pp_show_color (pp
));
4113 case 'V': result
= cv_to_string (next_tree
, verbose
); break;
4114 case 'X': result
= eh_spec_to_string (next_tree
, verbose
); break;
4120 pp_string (pp
, result
);
4121 if (set_locus
&& t
!= NULL
)
4122 text
->set_location (0, location_of (t
), SHOW_RANGE_WITH_CARET
);
4130 /* Warn about the use of C++0x features when appropriate. */
4132 maybe_warn_cpp0x (cpp0x_warn_str str
)
4134 if ((cxx_dialect
== cxx98
) && !in_system_header_at (input_location
))
4135 /* We really want to suppress this warning in system headers,
4136 because libstdc++ uses variadic templates even when we aren't
4140 case CPP0X_INITIALIZER_LISTS
:
4141 pedwarn (input_location
, 0,
4142 "extended initializer lists "
4143 "only available with -std=c++11 or -std=gnu++11");
4145 case CPP0X_EXPLICIT_CONVERSION
:
4146 pedwarn (input_location
, 0,
4147 "explicit conversion operators "
4148 "only available with -std=c++11 or -std=gnu++11");
4150 case CPP0X_VARIADIC_TEMPLATES
:
4151 pedwarn (input_location
, 0,
4152 "variadic templates "
4153 "only available with -std=c++11 or -std=gnu++11");
4155 case CPP0X_LAMBDA_EXPR
:
4156 pedwarn (input_location
, 0,
4157 "lambda expressions "
4158 "only available with -std=c++11 or -std=gnu++11");
4161 pedwarn (input_location
, 0,
4162 "C++11 auto only available with -std=c++11 or -std=gnu++11");
4164 case CPP0X_SCOPED_ENUMS
:
4165 pedwarn (input_location
, 0,
4166 "scoped enums only available with -std=c++11 or -std=gnu++11");
4168 case CPP0X_DEFAULTED_DELETED
:
4169 pedwarn (input_location
, 0,
4170 "defaulted and deleted functions "
4171 "only available with -std=c++11 or -std=gnu++11");
4173 case CPP0X_INLINE_NAMESPACES
:
4174 pedwarn (input_location
, OPT_Wpedantic
,
4175 "inline namespaces "
4176 "only available with -std=c++11 or -std=gnu++11");
4178 case CPP0X_OVERRIDE_CONTROLS
:
4179 pedwarn (input_location
, 0,
4180 "override controls (override/final) "
4181 "only available with -std=c++11 or -std=gnu++11");
4184 pedwarn (input_location
, 0,
4185 "non-static data member initializers "
4186 "only available with -std=c++11 or -std=gnu++11");
4188 case CPP0X_USER_DEFINED_LITERALS
:
4189 pedwarn (input_location
, 0,
4190 "user-defined literals "
4191 "only available with -std=c++11 or -std=gnu++11");
4193 case CPP0X_DELEGATING_CTORS
:
4194 pedwarn (input_location
, 0,
4195 "delegating constructors "
4196 "only available with -std=c++11 or -std=gnu++11");
4198 case CPP0X_INHERITING_CTORS
:
4199 pedwarn (input_location
, 0,
4200 "inheriting constructors "
4201 "only available with -std=c++11 or -std=gnu++11");
4203 case CPP0X_ATTRIBUTES
:
4204 pedwarn (input_location
, 0,
4206 "only available with -std=c++11 or -std=gnu++11");
4208 case CPP0X_REF_QUALIFIER
:
4209 pedwarn (input_location
, 0,
4211 "only available with -std=c++11 or -std=gnu++11");
4218 /* Warn about the use of variadic templates when appropriate. */
4220 maybe_warn_variadic_templates (void)
4222 maybe_warn_cpp0x (CPP0X_VARIADIC_TEMPLATES
);
4226 /* Issue an ISO C++98 pedantic warning at LOCATION, conditional on
4227 option OPT with text GMSGID. Use this function to report
4228 diagnostics for constructs that are invalid C++98, but valid
4231 pedwarn_cxx98 (location_t location
, int opt
, const char *gmsgid
, ...)
4233 diagnostic_info diagnostic
;
4236 rich_location
richloc (line_table
, location
);
4238 va_start (ap
, gmsgid
);
4239 diagnostic_set_info (&diagnostic
, gmsgid
, &ap
, &richloc
,
4240 (cxx_dialect
== cxx98
) ? DK_PEDWARN
: DK_WARNING
);
4241 diagnostic
.option_index
= opt
;
4242 ret
= diagnostic_report_diagnostic (global_dc
, &diagnostic
);
4247 /* Issue a diagnostic that NAME cannot be found in SCOPE. DECL is what
4248 we found when we tried to do the lookup. LOCATION is the location of
4249 the NAME identifier. */
4252 qualified_name_lookup_error (tree scope
, tree name
,
4253 tree decl
, location_t location
)
4255 if (scope
== error_mark_node
)
4256 ; /* We already complained. */
4257 else if (TYPE_P (scope
))
4259 if (!COMPLETE_TYPE_P (scope
))
4260 error_at (location
, "incomplete type %qT used in nested name specifier",
4262 else if (TREE_CODE (decl
) == TREE_LIST
)
4264 error_at (location
, "reference to %<%T::%D%> is ambiguous",
4266 print_candidates (decl
);
4269 error_at (location
, "%qD is not a member of %qT", name
, scope
);
4271 else if (scope
!= global_namespace
)
4273 auto_diagnostic_group d
;
4274 error_at (location
, "%qD is not a member of %qD", name
, scope
);
4275 if (!suggest_alternative_in_explicit_scope (location
, name
, scope
))
4276 suggest_alternatives_for (location
, name
, false);
4280 auto_diagnostic_group d
;
4281 error_at (location
, "%<::%D%> has not been declared", name
);
4282 suggest_alternatives_for (location
, name
, true);
4286 /* C++-specific implementation of range_label::get_text () vfunc for
4287 range_label_for_type_mismatch.
4289 Compare with print_template_differences above. */
4292 range_label_for_type_mismatch::get_text () const
4294 if (m_labelled_type
== NULL_TREE
)
4295 return label_text (NULL
, false);
4297 const bool verbose
= false;
4298 const bool show_color
= false;
4302 && comparable_template_types_p (m_labelled_type
, m_other_type
))
4303 result
= type_to_string_with_compare (m_labelled_type
, m_other_type
,
4304 verbose
, show_color
);
4306 result
= type_to_string (m_labelled_type
, verbose
, true, NULL
, show_color
);
4308 /* Both of the above return GC-allocated buffers, so the caller mustn't
4310 return label_text (const_cast <char *> (result
), false);