1 /* Call-backs for C++ error reporting.
2 This code is non-reentrant.
3 Copyright (C) 1993-2013 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"
27 #include "diagnostic.h"
28 #include "tree-diagnostic.h"
29 #include "langhooks-def.h"
31 #include "cxx-pretty-print.h"
32 #include "tree-pretty-print.h"
33 #include "pointer-set.h"
34 #include "c-family/c-objc.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 /* The global buffer where we dump everything. It is there only for
40 transitional purpose. It is expected, in the near future, to be
41 completely removed. */
42 static cxx_pretty_printer scratch_pretty_printer
;
43 #define cxx_pp (&scratch_pretty_printer)
45 /* Translate if being used for diagnostics, but not for dump files or
47 #define M_(msgid) (pp_translate_identifiers (cxx_pp) ? _(msgid) : (msgid))
49 # define NEXT_CODE(T) (TREE_CODE (TREE_TYPE (T)))
51 static const char *args_to_string (tree
, int);
52 static const char *assop_to_string (enum tree_code
);
53 static const char *code_to_string (enum tree_code
);
54 static const char *cv_to_string (tree
, int);
55 static const char *decl_to_string (tree
, int);
56 static const char *expr_to_string (tree
);
57 static const char *fndecl_to_string (tree
, int);
58 static const char *op_to_string (enum tree_code
);
59 static const char *parm_to_string (int);
60 static const char *type_to_string (tree
, int);
62 static void dump_alias_template_specialization (cxx_pretty_printer
*, tree
, int);
63 static void dump_type (cxx_pretty_printer
*, tree
, int);
64 static void dump_typename (cxx_pretty_printer
*, tree
, int);
65 static void dump_simple_decl (cxx_pretty_printer
*, tree
, tree
, int);
66 static void dump_decl (cxx_pretty_printer
*, tree
, int);
67 static void dump_template_decl (cxx_pretty_printer
*, tree
, int);
68 static void dump_function_decl (cxx_pretty_printer
*, tree
, int);
69 static void dump_expr (cxx_pretty_printer
*, tree
, int);
70 static void dump_unary_op (cxx_pretty_printer
*, const char *, tree
, int);
71 static void dump_binary_op (cxx_pretty_printer
*, const char *, tree
, int);
72 static void dump_aggr_type (cxx_pretty_printer
*, tree
, int);
73 static void dump_type_prefix (cxx_pretty_printer
*, tree
, int);
74 static void dump_type_suffix (cxx_pretty_printer
*, tree
, int);
75 static void dump_function_name (cxx_pretty_printer
*, tree
, int);
76 static void dump_call_expr_args (cxx_pretty_printer
*, tree
, int, bool);
77 static void dump_aggr_init_expr_args (cxx_pretty_printer
*, tree
, int, bool);
78 static void dump_expr_list (cxx_pretty_printer
*, tree
, int);
79 static void dump_global_iord (cxx_pretty_printer
*, tree
);
80 static void dump_parameters (cxx_pretty_printer
*, tree
, int);
81 static void dump_ref_qualifier (cxx_pretty_printer
*, tree
, int);
82 static void dump_exception_spec (cxx_pretty_printer
*, tree
, int);
83 static void dump_template_argument (cxx_pretty_printer
*, tree
, int);
84 static void dump_template_argument_list (cxx_pretty_printer
*, tree
, int);
85 static void dump_template_parameter (cxx_pretty_printer
*, tree
, int);
86 static void dump_template_bindings (cxx_pretty_printer
*, tree
, tree
,
88 static void dump_scope (cxx_pretty_printer
*, tree
, int);
89 static void dump_template_parms (cxx_pretty_printer
*, tree
, int, int);
90 static int get_non_default_template_args_count (tree
, int);
91 static const char *function_category (tree
);
92 static void maybe_print_constexpr_context (diagnostic_context
*);
93 static void maybe_print_instantiation_context (diagnostic_context
*);
94 static void print_instantiation_full_context (diagnostic_context
*);
95 static void print_instantiation_partial_context (diagnostic_context
*,
98 static void cp_diagnostic_starter (diagnostic_context
*, diagnostic_info
*);
99 static void cp_diagnostic_finalizer (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);
108 diagnostic_starter (global_dc
) = cp_diagnostic_starter
;
109 diagnostic_finalizer (global_dc
) = cp_diagnostic_finalizer
;
110 diagnostic_format_decoder (global_dc
) = cp_printer
;
112 pp_construct (cxx_pp
, NULL
, 0);
113 pp_cxx_pretty_printer_init (cxx_pp
);
116 /* Dump a scope, if deemed necessary. */
119 dump_scope (cxx_pretty_printer
*pp
, tree scope
, int flags
)
121 int f
= flags
& (TFF_SCOPE
| TFF_CHASE_TYPEDEF
);
123 if (scope
== NULL_TREE
)
126 if (TREE_CODE (scope
) == NAMESPACE_DECL
)
128 if (scope
!= global_namespace
)
130 dump_decl (pp
, scope
, f
);
131 pp_cxx_colon_colon (pp
);
134 else if (AGGREGATE_TYPE_P (scope
))
136 dump_type (pp
, scope
, f
);
137 pp_cxx_colon_colon (pp
);
139 else if ((flags
& TFF_SCOPE
) && TREE_CODE (scope
) == FUNCTION_DECL
)
141 dump_function_decl (pp
, scope
, f
);
142 pp_cxx_colon_colon (pp
);
146 /* Dump the template ARGument under control of FLAGS. */
149 dump_template_argument (cxx_pretty_printer
*pp
, tree arg
, int flags
)
151 if (ARGUMENT_PACK_P (arg
))
152 dump_template_argument_list (pp
, ARGUMENT_PACK_ARGS (arg
),
153 /* No default args in argument packs. */
154 flags
|TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS
);
155 else if (TYPE_P (arg
) || TREE_CODE (arg
) == TEMPLATE_DECL
)
156 dump_type (pp
, arg
, flags
& ~TFF_CLASS_KEY_OR_ENUM
);
159 if (TREE_CODE (arg
) == TREE_LIST
)
160 arg
= TREE_VALUE (arg
);
162 dump_expr (pp
, arg
, (flags
| TFF_EXPR_IN_PARENS
) & ~TFF_CLASS_KEY_OR_ENUM
);
166 /* Count the number of template arguments ARGS whose value does not
167 match the (optional) default template parameter in PARAMS */
170 get_non_default_template_args_count (tree args
, int flags
)
172 int n
= TREE_VEC_LENGTH (INNERMOST_TEMPLATE_ARGS (args
));
174 if (/* We use this flag when generating debug information. We don't
175 want to expand templates at this point, for this may generate
176 new decls, which gets decl counts out of sync, which may in
177 turn cause codegen differences between compilations with and
179 (flags
& TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS
) != 0
180 || !flag_pretty_templates
)
183 return GET_NON_DEFAULT_TEMPLATE_ARGS_COUNT (INNERMOST_TEMPLATE_ARGS (args
));
186 /* Dump a template-argument-list ARGS (always a TREE_VEC) under control
190 dump_template_argument_list (cxx_pretty_printer
*pp
, tree args
, int flags
)
192 int n
= get_non_default_template_args_count (args
, flags
);
196 for (i
= 0; i
< n
; ++i
)
198 tree arg
= TREE_VEC_ELT (args
, i
);
200 /* Only print a comma if we know there is an argument coming. In
201 the case of an empty template argument pack, no actual
202 argument will be printed. */
204 && (!ARGUMENT_PACK_P (arg
)
205 || TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg
)) > 0))
206 pp_separate_with_comma (pp
);
208 dump_template_argument (pp
, arg
, flags
);
213 /* Dump a template parameter PARM (a TREE_LIST) under control of FLAGS. */
216 dump_template_parameter (cxx_pretty_printer
*pp
, tree parm
, int flags
)
221 if (parm
== error_mark_node
)
224 p
= TREE_VALUE (parm
);
225 a
= TREE_PURPOSE (parm
);
227 if (TREE_CODE (p
) == TYPE_DECL
)
229 if (flags
& TFF_DECL_SPECIFIERS
)
231 pp_cxx_ws_string (pp
, "class");
232 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (p
)))
233 pp_cxx_ws_string (pp
, "...");
235 pp_cxx_tree_identifier (pp
, DECL_NAME (p
));
237 else if (DECL_NAME (p
))
238 pp_cxx_tree_identifier (pp
, DECL_NAME (p
));
240 pp_cxx_canonical_template_parameter (pp
, TREE_TYPE (p
));
243 dump_decl (pp
, p
, flags
| TFF_DECL_SPECIFIERS
);
245 if ((flags
& TFF_FUNCTION_DEFAULT_ARGUMENTS
) && a
!= NULL_TREE
)
247 pp_cxx_whitespace (pp
);
249 pp_cxx_whitespace (pp
);
250 if (TREE_CODE (p
) == TYPE_DECL
|| TREE_CODE (p
) == TEMPLATE_DECL
)
251 dump_type (pp
, a
, flags
& ~TFF_CHASE_TYPEDEF
);
253 dump_expr (pp
, a
, flags
| TFF_EXPR_IN_PARENS
);
257 /* Dump, under control of FLAGS, a template-parameter-list binding.
258 PARMS is a TREE_LIST of TREE_VEC of TREE_LIST and ARGS is a
262 dump_template_bindings (cxx_pretty_printer
*pp
, tree parms
, tree args
,
263 vec
<tree
, va_gc
> *typenames
)
265 bool need_semicolon
= false;
271 tree p
= TREE_VALUE (parms
);
272 int lvl
= TMPL_PARMS_DEPTH (parms
);
275 tree lvl_args
= NULL_TREE
;
277 /* Don't crash if we had an invalid argument list. */
278 if (TMPL_ARGS_DEPTH (args
) >= lvl
)
279 lvl_args
= TMPL_ARGS_LEVEL (args
, lvl
);
281 for (i
= 0; i
< TREE_VEC_LENGTH (p
); ++i
)
283 tree arg
= NULL_TREE
;
285 /* Don't crash if we had an invalid argument list. */
286 if (lvl_args
&& NUM_TMPL_ARGS (lvl_args
) > arg_idx
)
287 arg
= TREE_VEC_ELT (lvl_args
, arg_idx
);
290 pp_separate_with_semicolon (pp
);
291 dump_template_parameter (pp
, TREE_VEC_ELT (p
, i
),
292 TFF_PLAIN_IDENTIFIER
);
293 pp_cxx_whitespace (pp
);
295 pp_cxx_whitespace (pp
);
298 if (ARGUMENT_PACK_P (arg
))
299 pp_cxx_left_brace (pp
);
300 dump_template_argument (pp
, arg
, TFF_PLAIN_IDENTIFIER
);
301 if (ARGUMENT_PACK_P (arg
))
302 pp_cxx_right_brace (pp
);
305 pp_string (pp
, M_("<missing>"));
308 need_semicolon
= true;
311 parms
= TREE_CHAIN (parms
);
314 /* Don't bother with typenames for a partial instantiation. */
315 if (vec_safe_is_empty (typenames
) || uses_template_parms (args
))
318 FOR_EACH_VEC_SAFE_ELT (typenames
, i
, t
)
321 pp_separate_with_semicolon (pp
);
322 dump_type (pp
, t
, TFF_PLAIN_IDENTIFIER
);
323 pp_cxx_whitespace (pp
);
325 pp_cxx_whitespace (pp
);
326 push_deferring_access_checks (dk_no_check
);
327 t
= tsubst (t
, args
, tf_none
, NULL_TREE
);
328 pop_deferring_access_checks ();
329 /* Strip typedefs. We can't just use TFF_CHASE_TYPEDEF because
330 pp_simple_type_specifier doesn't know about it. */
331 t
= strip_typedefs (t
);
332 dump_type (pp
, t
, TFF_PLAIN_IDENTIFIER
);
336 /* Dump a human-readable equivalent of the alias template
337 specialization of T. */
340 dump_alias_template_specialization (cxx_pretty_printer
*pp
, tree t
, int flags
)
344 gcc_assert (alias_template_specialization_p (t
));
346 if (!(flags
& TFF_UNQUALIFIED_NAME
))
347 dump_scope (pp
, CP_DECL_CONTEXT (TYPE_NAME (t
)), flags
);
348 name
= TYPE_IDENTIFIER (t
);
349 pp_cxx_tree_identifier (pp
, name
);
350 dump_template_parms (pp
, TYPE_TEMPLATE_INFO (t
),
352 flags
& ~TFF_TEMPLATE_HEADER
);
355 /* Dump a human-readable equivalent of TYPE. FLAGS controls the
359 dump_type (cxx_pretty_printer
*pp
, tree t
, int flags
)
364 /* Don't print e.g. "struct mytypedef". */
365 if (TYPE_P (t
) && typedef_variant_p (t
))
367 tree decl
= TYPE_NAME (t
);
368 if ((flags
& TFF_CHASE_TYPEDEF
)
369 || DECL_SELF_REFERENCE_P (decl
)
370 || (!flag_pretty_templates
371 && DECL_LANG_SPECIFIC (decl
) && DECL_TEMPLATE_INFO (decl
)))
372 t
= strip_typedefs (t
);
373 else if (alias_template_specialization_p (t
))
375 dump_alias_template_specialization (pp
, t
, flags
);
378 else if (same_type_p (t
, TREE_TYPE (decl
)))
382 pp_cxx_cv_qualifier_seq (pp
, t
);
383 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
388 if (TYPE_PTRMEMFUNC_P (t
))
391 switch (TREE_CODE (t
))
394 if (t
== init_list_type_node
)
395 pp_string (pp
, M_("<brace-enclosed initializer list>"));
396 else if (t
== unknown_type_node
)
397 pp_string (pp
, M_("<unresolved overloaded function type>"));
400 pp_cxx_cv_qualifier_seq (pp
, t
);
401 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
406 /* A list of function parms. */
407 dump_parameters (pp
, t
, flags
);
410 case IDENTIFIER_NODE
:
411 pp_cxx_tree_identifier (pp
, t
);
415 dump_type (pp
, BINFO_TYPE (t
), flags
);
421 dump_aggr_type (pp
, t
, flags
);
425 if (flags
& TFF_CHASE_TYPEDEF
)
427 dump_type (pp
, DECL_ORIGINAL_TYPE (t
)
428 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
), flags
);
431 /* Else fall through. */
435 dump_decl (pp
, t
, flags
& ~TFF_DECL_SPECIFIERS
);
444 case FIXED_POINT_TYPE
:
445 pp_type_specifier_seq (pp
, t
);
448 case TEMPLATE_TEMPLATE_PARM
:
449 /* For parameters inside template signature. */
450 if (TYPE_IDENTIFIER (t
))
451 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
453 pp_cxx_canonical_template_parameter (pp
, t
);
456 case BOUND_TEMPLATE_TEMPLATE_PARM
:
458 tree args
= TYPE_TI_ARGS (t
);
459 pp_cxx_cv_qualifier_seq (pp
, t
);
460 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
461 pp_cxx_begin_template_argument_list (pp
);
462 dump_template_argument_list (pp
, args
, flags
);
463 pp_cxx_end_template_argument_list (pp
);
467 case TEMPLATE_TYPE_PARM
:
468 pp_cxx_cv_qualifier_seq (pp
, t
);
469 if (TYPE_IDENTIFIER (t
))
470 pp_cxx_tree_identifier (pp
, TYPE_IDENTIFIER (t
));
472 pp_cxx_canonical_template_parameter
473 (pp
, TEMPLATE_TYPE_PARM_INDEX (t
));
476 /* This is not always necessary for pointers and such, but doing this
477 reduces code size. */
486 dump_type_prefix (pp
, t
, flags
);
487 dump_type_suffix (pp
, t
, flags
);
491 if (! (flags
& TFF_CHASE_TYPEDEF
)
492 && DECL_ORIGINAL_TYPE (TYPE_NAME (t
)))
494 dump_decl (pp
, TYPE_NAME (t
), TFF_PLAIN_IDENTIFIER
);
497 pp_cxx_cv_qualifier_seq (pp
, t
);
498 pp_cxx_ws_string (pp
,
499 TYPENAME_IS_ENUM_P (t
) ? "enum"
500 : TYPENAME_IS_CLASS_P (t
) ? "class"
502 dump_typename (pp
, t
, flags
);
505 case UNBOUND_CLASS_TEMPLATE
:
506 if (! (flags
& TFF_UNQUALIFIED_NAME
))
508 dump_type (pp
, TYPE_CONTEXT (t
), flags
);
509 pp_cxx_colon_colon (pp
);
511 pp_cxx_ws_string (pp
, "template");
512 dump_type (pp
, DECL_NAME (TYPE_NAME (t
)), flags
);
516 pp_cxx_ws_string (pp
, "__typeof__");
517 pp_cxx_whitespace (pp
);
518 pp_cxx_left_paren (pp
);
519 dump_expr (pp
, TYPEOF_TYPE_EXPR (t
), flags
& ~TFF_EXPR_IN_PARENS
);
520 pp_cxx_right_paren (pp
);
523 case UNDERLYING_TYPE
:
524 pp_cxx_ws_string (pp
, "__underlying_type");
525 pp_cxx_whitespace (pp
);
526 pp_cxx_left_paren (pp
);
527 dump_expr (pp
, UNDERLYING_TYPE_TYPE (t
), flags
& ~TFF_EXPR_IN_PARENS
);
528 pp_cxx_right_paren (pp
);
531 case TYPE_PACK_EXPANSION
:
532 dump_type (pp
, PACK_EXPANSION_PATTERN (t
), flags
);
533 pp_cxx_ws_string (pp
, "...");
536 case TYPE_ARGUMENT_PACK
:
537 dump_template_argument (pp
, t
, flags
);
541 pp_cxx_ws_string (pp
, "decltype");
542 pp_cxx_whitespace (pp
);
543 pp_cxx_left_paren (pp
);
544 dump_expr (pp
, DECLTYPE_TYPE_EXPR (t
), flags
& ~TFF_EXPR_IN_PARENS
);
545 pp_cxx_right_paren (pp
);
549 pp_string (pp
, "std::nullptr_t");
553 pp_unsupported_tree (pp
, t
);
554 /* Fall through to error. */
557 pp_string (pp
, M_("<type error>"));
562 /* Dump a TYPENAME_TYPE. We need to notice when the context is itself
566 dump_typename (cxx_pretty_printer
*pp
, tree t
, int flags
)
568 tree ctx
= TYPE_CONTEXT (t
);
570 if (TREE_CODE (ctx
) == TYPENAME_TYPE
)
571 dump_typename (pp
, ctx
, flags
);
573 dump_type (pp
, ctx
, flags
& ~TFF_CLASS_KEY_OR_ENUM
);
574 pp_cxx_colon_colon (pp
);
575 dump_decl (pp
, TYPENAME_TYPE_FULLNAME (t
), flags
);
578 /* Return the name of the supplied aggregate, or enumeral type. */
581 class_key_or_enum_as_string (tree t
)
583 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
585 if (SCOPED_ENUM_P (t
))
590 else if (TREE_CODE (t
) == UNION_TYPE
)
592 else if (TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_DECLARED_CLASS (t
))
598 /* Print out a class declaration T under the control of FLAGS,
599 in the form `class foo'. */
602 dump_aggr_type (cxx_pretty_printer
*pp
, tree t
, int flags
)
605 const char *variety
= class_key_or_enum_as_string (t
);
609 pp_cxx_cv_qualifier_seq (pp
, t
);
611 if (flags
& TFF_CLASS_KEY_OR_ENUM
)
612 pp_cxx_ws_string (pp
, variety
);
614 name
= TYPE_NAME (t
);
618 typdef
= (!DECL_ARTIFICIAL (name
)
619 /* An alias specialization is not considered to be a
621 && !alias_template_specialization_p (t
));
624 && ((flags
& TFF_CHASE_TYPEDEF
)
625 || (!flag_pretty_templates
&& DECL_LANG_SPECIFIC (name
)
626 && DECL_TEMPLATE_INFO (name
))))
627 || DECL_SELF_REFERENCE_P (name
))
629 t
= TYPE_MAIN_VARIANT (t
);
630 name
= TYPE_NAME (t
);
634 tmplate
= !typdef
&& TREE_CODE (t
) != ENUMERAL_TYPE
635 && TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_TEMPLATE_INFO (t
)
636 && (TREE_CODE (CLASSTYPE_TI_TEMPLATE (t
)) != TEMPLATE_DECL
637 || PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t
)));
639 if (! (flags
& TFF_UNQUALIFIED_NAME
))
640 dump_scope (pp
, CP_DECL_CONTEXT (name
), flags
| TFF_SCOPE
);
641 flags
&= ~TFF_UNQUALIFIED_NAME
;
644 /* Because the template names are mangled, we have to locate
645 the most general template, and use that name. */
646 tree tpl
= TYPE_TI_TEMPLATE (t
);
648 while (DECL_TEMPLATE_INFO (tpl
))
649 tpl
= DECL_TI_TEMPLATE (tpl
);
652 name
= DECL_NAME (name
);
655 if (name
== 0 || ANON_AGGRNAME_P (name
))
657 if (flags
& TFF_CLASS_KEY_OR_ENUM
)
658 pp_string (pp
, M_("<anonymous>"));
660 pp_printf (pp
, M_("<anonymous %s>"), variety
);
662 else if (LAMBDA_TYPE_P (t
))
664 /* A lambda's "type" is essentially its signature. */
665 pp_string (pp
, M_("<lambda"));
666 if (lambda_function (t
))
668 FUNCTION_FIRST_USER_PARMTYPE (lambda_function (t
)),
673 pp_cxx_tree_identifier (pp
, name
);
675 dump_template_parms (pp
, TYPE_TEMPLATE_INFO (t
),
676 !CLASSTYPE_USE_TEMPLATE (t
),
677 flags
& ~TFF_TEMPLATE_HEADER
);
680 /* Dump into the obstack the initial part of the output for a given type.
681 This is necessary when dealing with things like functions returning
684 return type of `int (* fee ())()': pointer -> function -> int. Both
685 pointer (and reference and offset) and function (and member) types must
686 deal with prefix and suffix.
688 Arrays must also do this for DECL nodes, like int a[], and for things like
692 dump_type_prefix (cxx_pretty_printer
*pp
, tree t
, int flags
)
694 if (TYPE_PTRMEMFUNC_P (t
))
696 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
700 switch (TREE_CODE (t
))
705 tree sub
= TREE_TYPE (t
);
707 dump_type_prefix (pp
, sub
, flags
);
708 if (TREE_CODE (sub
) == ARRAY_TYPE
709 || TREE_CODE (sub
) == FUNCTION_TYPE
)
711 pp_cxx_whitespace (pp
);
712 pp_cxx_left_paren (pp
);
713 pp_c_attributes_display (pp
, TYPE_ATTRIBUTES (sub
));
717 else if (TREE_CODE (t
) == REFERENCE_TYPE
)
719 if (TYPE_REF_IS_RVALUE (t
))
720 pp_ampersand_ampersand (pp
);
724 pp
->padding
= pp_before
;
725 pp_cxx_cv_qualifier_seq (pp
, t
);
731 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
732 if (TREE_CODE (t
) == OFFSET_TYPE
) /* pmfs deal with this in d_t_p */
735 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
736 pp_cxx_left_paren (pp
);
737 dump_type (pp
, TYPE_OFFSET_BASETYPE (t
), flags
);
738 pp_cxx_colon_colon (pp
);
741 pp_cxx_cv_qualifier_seq (pp
, t
);
742 pp
->padding
= pp_before
;
745 /* This can be reached without a pointer when dealing with
746 templates, e.g. std::is_function. */
748 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
752 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
754 pp_cxx_left_paren (pp
);
755 dump_aggr_type (pp
, TYPE_METHOD_BASETYPE (t
), flags
);
756 pp_cxx_colon_colon (pp
);
760 dump_type_prefix (pp
, TREE_TYPE (t
), flags
);
764 case IDENTIFIER_NODE
:
769 case TEMPLATE_TYPE_PARM
:
770 case TEMPLATE_TEMPLATE_PARM
:
771 case BOUND_TEMPLATE_TEMPLATE_PARM
:
782 case UNDERLYING_TYPE
:
784 case TYPE_PACK_EXPANSION
:
785 case FIXED_POINT_TYPE
:
787 dump_type (pp
, t
, flags
);
788 pp
->padding
= pp_before
;
792 pp_unsupported_tree (pp
, t
);
795 pp_string (pp
, M_("<typeprefixerror>"));
800 /* Dump the suffix of type T, under control of FLAGS. This is the part
801 which appears after the identifier (or function parms). */
804 dump_type_suffix (cxx_pretty_printer
*pp
, tree t
, int flags
)
806 if (TYPE_PTRMEMFUNC_P (t
))
807 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
809 switch (TREE_CODE (t
))
814 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
815 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
816 pp_cxx_right_paren (pp
);
817 dump_type_suffix (pp
, TREE_TYPE (t
), flags
);
824 if (TREE_CODE (t
) == METHOD_TYPE
)
825 /* Can only be reached through a pointer. */
826 pp_cxx_right_paren (pp
);
827 arg
= TYPE_ARG_TYPES (t
);
828 if (TREE_CODE (t
) == METHOD_TYPE
)
829 arg
= TREE_CHAIN (arg
);
831 /* Function pointers don't have default args. Not in standard C++,
832 anyway; they may in g++, but we'll just pretend otherwise. */
833 dump_parameters (pp
, arg
, flags
& ~TFF_FUNCTION_DEFAULT_ARGUMENTS
);
835 pp
->padding
= pp_before
;
836 pp_cxx_cv_qualifiers (pp
, type_memfn_quals (t
));
837 dump_ref_qualifier (pp
, t
, flags
);
838 dump_exception_spec (pp
, TYPE_RAISES_EXCEPTIONS (t
), flags
);
839 dump_type_suffix (pp
, TREE_TYPE (t
), flags
);
845 pp_cxx_left_bracket (pp
);
848 tree dtype
= TYPE_DOMAIN (t
);
849 tree max
= TYPE_MAX_VALUE (dtype
);
850 if (integer_all_onesp (max
))
851 pp_character (pp
, '0');
852 else if (host_integerp (max
, 0))
853 pp_wide_integer (pp
, tree_low_cst (max
, 0) + 1);
857 if (TREE_CODE (max
) == SAVE_EXPR
)
858 max
= TREE_OPERAND (max
, 0);
859 if (TREE_CODE (max
) == MINUS_EXPR
860 || TREE_CODE (max
) == PLUS_EXPR
)
862 max
= TREE_OPERAND (max
, 0);
863 while (CONVERT_EXPR_P (max
))
864 max
= TREE_OPERAND (max
, 0);
867 max
= fold_build2_loc (input_location
,
868 PLUS_EXPR
, dtype
, max
,
869 build_int_cst (dtype
, 1));
870 dump_expr (pp
, max
, flags
& ~TFF_EXPR_IN_PARENS
);
873 pp_cxx_right_bracket (pp
);
874 dump_type_suffix (pp
, TREE_TYPE (t
), flags
);
878 case IDENTIFIER_NODE
:
883 case TEMPLATE_TYPE_PARM
:
884 case TEMPLATE_TEMPLATE_PARM
:
885 case BOUND_TEMPLATE_TEMPLATE_PARM
:
896 case UNDERLYING_TYPE
:
898 case TYPE_PACK_EXPANSION
:
899 case FIXED_POINT_TYPE
:
904 pp_unsupported_tree (pp
, t
);
906 /* Don't mark it here, we should have already done in
913 dump_global_iord (cxx_pretty_printer
*pp
, tree t
)
915 const char *p
= NULL
;
917 if (DECL_GLOBAL_CTOR_P (t
))
918 p
= M_("(static initializers for %s)");
919 else if (DECL_GLOBAL_DTOR_P (t
))
920 p
= M_("(static destructors for %s)");
924 pp_printf (pp
, p
, input_filename
);
928 dump_simple_decl (cxx_pretty_printer
*pp
, tree t
, tree type
, int flags
)
930 if (flags
& TFF_DECL_SPECIFIERS
)
933 && DECL_DECLARED_CONSTEXPR_P (t
))
934 pp_cxx_ws_string (pp
, "constexpr");
935 dump_type_prefix (pp
, type
, flags
& ~TFF_UNQUALIFIED_NAME
);
938 if (! (flags
& TFF_UNQUALIFIED_NAME
)
939 && TREE_CODE (t
) != PARM_DECL
940 && (!DECL_INITIAL (t
)
941 || TREE_CODE (DECL_INITIAL (t
)) != TEMPLATE_PARM_INDEX
))
942 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
943 flags
&= ~TFF_UNQUALIFIED_NAME
;
944 if ((flags
& TFF_DECL_SPECIFIERS
)
945 && DECL_TEMPLATE_PARM_P (t
)
946 && TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (t
)))
947 pp_string (pp
, "...");
950 if (TREE_CODE (t
) == FIELD_DECL
&& DECL_NORMAL_CAPTURE_P (t
))
953 pp_string (pp
, IDENTIFIER_POINTER (DECL_NAME (t
)) + 2);
954 pp_string (pp
, " capture>");
957 dump_decl (pp
, DECL_NAME (t
), flags
);
960 pp_string (pp
, M_("<anonymous>"));
961 if (flags
& TFF_DECL_SPECIFIERS
)
962 dump_type_suffix (pp
, type
, flags
);
965 /* Dump a human readable string for the decl T under control of FLAGS. */
968 dump_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
973 /* If doing Objective-C++, give Objective-C a chance to demangle
974 Objective-C method names. */
975 if (c_dialect_objc ())
977 const char *demangled
= objc_maybe_printable_name (t
, flags
);
980 pp_string (pp
, demangled
);
985 switch (TREE_CODE (t
))
988 /* Don't say 'typedef class A' */
989 if (DECL_ARTIFICIAL (t
) && !DECL_SELF_REFERENCE_P (t
))
991 if ((flags
& TFF_DECL_SPECIFIERS
)
992 && TREE_CODE (TREE_TYPE (t
)) == TEMPLATE_TYPE_PARM
)
994 /* Say `class T' not just `T'. */
995 pp_cxx_ws_string (pp
, "class");
997 /* Emit the `...' for a parameter pack. */
998 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t
)))
999 pp_cxx_ws_string (pp
, "...");
1002 dump_type (pp
, TREE_TYPE (t
), flags
);
1005 if (TYPE_DECL_ALIAS_P (t
)
1006 && (flags
& TFF_DECL_SPECIFIERS
1007 || flags
& TFF_CLASS_KEY_OR_ENUM
))
1009 pp_cxx_ws_string (pp
, "using");
1010 dump_decl (pp
, DECL_NAME (t
), flags
);
1011 pp_cxx_whitespace (pp
);
1012 pp_cxx_ws_string (pp
, "=");
1013 pp_cxx_whitespace (pp
);
1014 dump_type (pp
, DECL_ORIGINAL_TYPE (t
), flags
);
1017 if ((flags
& TFF_DECL_SPECIFIERS
)
1018 && !DECL_SELF_REFERENCE_P (t
))
1019 pp_cxx_ws_string (pp
, "typedef");
1020 dump_simple_decl (pp
, t
, DECL_ORIGINAL_TYPE (t
)
1021 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
),
1026 if (DECL_NAME (t
) && VTABLE_NAME_P (DECL_NAME (t
)))
1028 pp_string (pp
, M_("vtable for "));
1029 gcc_assert (TYPE_P (DECL_CONTEXT (t
)));
1030 dump_type (pp
, DECL_CONTEXT (t
), flags
);
1033 /* Else fall through. */
1036 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1040 pp_string (pp
, M_("<return value> "));
1041 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1044 case NAMESPACE_DECL
:
1045 if (flags
& TFF_DECL_SPECIFIERS
)
1046 pp_cxx_declaration (pp
, t
);
1049 if (! (flags
& TFF_UNQUALIFIED_NAME
))
1050 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1051 flags
&= ~TFF_UNQUALIFIED_NAME
;
1052 if (DECL_NAME (t
) == NULL_TREE
)
1054 if (!(pp
->flags
& pp_c_flag_gnu_v3
))
1055 pp_cxx_ws_string (pp
, M_("{anonymous}"));
1057 pp_cxx_ws_string (pp
, M_("(anonymous namespace)"));
1060 pp_cxx_tree_identifier (pp
, DECL_NAME (t
));
1065 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
1066 pp_colon_colon (pp
);
1067 dump_decl (pp
, TREE_OPERAND (t
, 1), TFF_UNQUALIFIED_NAME
);
1071 dump_decl (pp
, TREE_OPERAND (t
, 0), flags
);
1072 pp_cxx_left_bracket (pp
);
1073 dump_decl (pp
, TREE_OPERAND (t
, 1), flags
);
1074 pp_cxx_right_bracket (pp
);
1077 case ARRAY_NOTATION_REF
:
1078 dump_decl (pp
, ARRAY_NOTATION_ARRAY (t
), flags
| TFF_EXPR_IN_PARENS
);
1079 pp_cxx_left_bracket (pp
);
1080 dump_decl (pp
, ARRAY_NOTATION_START (t
), flags
| TFF_EXPR_IN_PARENS
);
1082 dump_decl (pp
, ARRAY_NOTATION_LENGTH (t
), flags
| TFF_EXPR_IN_PARENS
);
1084 dump_decl (pp
, ARRAY_NOTATION_STRIDE (t
), flags
| TFF_EXPR_IN_PARENS
);
1085 pp_cxx_right_bracket (pp
);
1088 /* So that we can do dump_decl on an aggr type. */
1092 dump_type (pp
, t
, flags
);
1096 /* This is a pseudo destructor call which has not been folded into
1097 a PSEUDO_DTOR_EXPR yet. */
1098 pp_cxx_complement (pp
);
1099 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
1106 /* These special cases are duplicated here so that other functions
1107 can feed identifiers to error and get them demangled properly. */
1108 case IDENTIFIER_NODE
:
1109 if (IDENTIFIER_TYPENAME_P (t
))
1111 pp_cxx_ws_string (pp
, "operator");
1112 /* Not exactly IDENTIFIER_TYPE_VALUE. */
1113 dump_type (pp
, TREE_TYPE (t
), flags
);
1117 pp_cxx_tree_identifier (pp
, t
);
1123 t
= OVL_CURRENT (t
);
1124 if (DECL_CLASS_SCOPE_P (t
))
1126 dump_type (pp
, DECL_CONTEXT (t
), flags
);
1127 pp_cxx_colon_colon (pp
);
1129 else if (!DECL_FILE_SCOPE_P (t
))
1131 dump_decl (pp
, DECL_CONTEXT (t
), flags
);
1132 pp_cxx_colon_colon (pp
);
1134 dump_decl (pp
, DECL_NAME (t
), flags
);
1138 /* If there's only one function, just treat it like an ordinary
1140 t
= OVL_CURRENT (t
);
1144 if (! DECL_LANG_SPECIFIC (t
))
1145 pp_string (pp
, M_("<built-in>"));
1146 else if (DECL_GLOBAL_CTOR_P (t
) || DECL_GLOBAL_DTOR_P (t
))
1147 dump_global_iord (pp
, t
);
1149 dump_function_decl (pp
, t
, flags
);
1153 dump_template_decl (pp
, t
, flags
);
1156 case TEMPLATE_ID_EXPR
:
1158 tree name
= TREE_OPERAND (t
, 0);
1159 tree args
= TREE_OPERAND (t
, 1);
1161 if (is_overloaded_fn (name
))
1162 name
= DECL_NAME (get_first_fn (name
));
1163 dump_decl (pp
, name
, flags
);
1164 pp_cxx_begin_template_argument_list (pp
);
1165 if (args
== error_mark_node
)
1166 pp_string (pp
, M_("<template arguments error>"));
1168 dump_template_argument_list (pp
, args
, flags
);
1169 pp_cxx_end_template_argument_list (pp
);
1174 pp_cxx_tree_identifier (pp
, DECL_NAME (t
));
1178 if ((TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == ENUMERAL_TYPE
)
1179 || (DECL_INITIAL (t
) &&
1180 TREE_CODE (DECL_INITIAL (t
)) == TEMPLATE_PARM_INDEX
))
1181 dump_simple_decl (pp
, t
, TREE_TYPE (t
), flags
);
1182 else if (DECL_NAME (t
))
1183 dump_decl (pp
, DECL_NAME (t
), flags
);
1184 else if (DECL_INITIAL (t
))
1185 dump_expr (pp
, DECL_INITIAL (t
), flags
| TFF_EXPR_IN_PARENS
);
1187 pp_string (pp
, M_("<enumerator>"));
1191 pp_cxx_ws_string (pp
, "using");
1192 dump_type (pp
, USING_DECL_SCOPE (t
), flags
);
1193 pp_cxx_colon_colon (pp
);
1194 dump_decl (pp
, DECL_NAME (t
), flags
);
1198 pp_cxx_declaration (pp
, t
);
1202 dump_decl (pp
, BASELINK_FUNCTIONS (t
), flags
);
1205 case NON_DEPENDENT_EXPR
:
1206 dump_expr (pp
, t
, flags
);
1209 case TEMPLATE_TYPE_PARM
:
1210 if (flags
& TFF_DECL_SPECIFIERS
)
1211 pp_cxx_declaration (pp
, t
);
1216 case UNBOUND_CLASS_TEMPLATE
:
1217 case TYPE_PACK_EXPANSION
:
1219 dump_type (pp
, t
, flags
);
1223 pp_unsupported_tree (pp
, t
);
1224 /* Fall through to error. */
1227 pp_string (pp
, M_("<declaration error>"));
1232 /* Dump a template declaration T under control of FLAGS. This means the
1233 'template <...> leaders plus the 'class X' or 'void fn(...)' part. */
1236 dump_template_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
1238 tree orig_parms
= DECL_TEMPLATE_PARMS (t
);
1242 if (flags
& TFF_TEMPLATE_HEADER
)
1244 for (parms
= orig_parms
= nreverse (orig_parms
);
1246 parms
= TREE_CHAIN (parms
))
1248 tree inner_parms
= INNERMOST_TEMPLATE_PARMS (parms
);
1249 int len
= TREE_VEC_LENGTH (inner_parms
);
1251 pp_cxx_ws_string (pp
, "template");
1252 pp_cxx_begin_template_argument_list (pp
);
1254 /* If we've shown the template prefix, we'd better show the
1255 parameters' and decl's type too. */
1256 flags
|= TFF_DECL_SPECIFIERS
;
1258 for (i
= 0; i
< len
; i
++)
1261 pp_separate_with_comma (pp
);
1262 dump_template_parameter (pp
, TREE_VEC_ELT (inner_parms
, i
),
1265 pp_cxx_end_template_argument_list (pp
);
1266 pp_cxx_whitespace (pp
);
1268 nreverse(orig_parms
);
1270 if (DECL_TEMPLATE_TEMPLATE_PARM_P (t
))
1272 /* Say `template<arg> class TT' not just `template<arg> TT'. */
1273 pp_cxx_ws_string (pp
, "class");
1275 /* If this is a parameter pack, print the ellipsis. */
1276 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t
)))
1277 pp_cxx_ws_string (pp
, "...");
1281 if (DECL_CLASS_TEMPLATE_P (t
))
1282 dump_type (pp
, TREE_TYPE (t
),
1283 ((flags
& ~TFF_CLASS_KEY_OR_ENUM
) | TFF_TEMPLATE_NAME
1284 | (flags
& TFF_DECL_SPECIFIERS
? TFF_CLASS_KEY_OR_ENUM
: 0)));
1285 else if (DECL_TEMPLATE_RESULT (t
)
1286 && (VAR_P (DECL_TEMPLATE_RESULT (t
))
1287 /* Alias template. */
1288 || DECL_TYPE_TEMPLATE_P (t
)))
1289 dump_decl (pp
, DECL_TEMPLATE_RESULT (t
), flags
| TFF_TEMPLATE_NAME
);
1292 gcc_assert (TREE_TYPE (t
));
1293 switch (NEXT_CODE (t
))
1297 dump_function_decl (pp
, t
, flags
| TFF_TEMPLATE_NAME
);
1300 /* This case can occur with some invalid code. */
1301 dump_type (pp
, TREE_TYPE (t
),
1302 (flags
& ~TFF_CLASS_KEY_OR_ENUM
) | TFF_TEMPLATE_NAME
1303 | (flags
& TFF_DECL_SPECIFIERS
1304 ? TFF_CLASS_KEY_OR_ENUM
: 0));
1309 /* find_typenames looks through the type of the function template T
1310 and returns a vec containing any typedefs, decltypes or TYPENAME_TYPEs
1313 struct find_typenames_t
1315 struct pointer_set_t
*p_set
;
1316 vec
<tree
, va_gc
> *typenames
;
1320 find_typenames_r (tree
*tp
, int *walk_subtrees
, void *data
)
1322 struct find_typenames_t
*d
= (struct find_typenames_t
*)data
;
1323 tree mv
= NULL_TREE
;
1325 if (TYPE_P (*tp
) && is_typedef_decl (TYPE_NAME (*tp
)))
1326 /* Add the type of the typedef without any additional cv-quals. */
1327 mv
= TREE_TYPE (TYPE_NAME (*tp
));
1328 else if (TREE_CODE (*tp
) == TYPENAME_TYPE
1329 || TREE_CODE (*tp
) == DECLTYPE_TYPE
)
1330 /* Add the typename without any cv-qualifiers. */
1331 mv
= TYPE_MAIN_VARIANT (*tp
);
1333 if (TREE_CODE (*tp
) == TYPE_PACK_EXPANSION
)
1335 /* Don't mess with parameter packs since we don't remember
1336 the pack expansion context for a particular typename. */
1337 *walk_subtrees
= false;
1341 if (mv
&& (mv
== *tp
|| !pointer_set_insert (d
->p_set
, mv
)))
1342 vec_safe_push (d
->typenames
, mv
);
1344 /* Search into class template arguments, which cp_walk_subtrees
1346 if (CLASS_TYPE_P (*tp
) && CLASSTYPE_TEMPLATE_INFO (*tp
))
1347 cp_walk_tree (&CLASSTYPE_TI_ARGS (*tp
), find_typenames_r
,
1353 static vec
<tree
, va_gc
> *
1354 find_typenames (tree t
)
1356 struct find_typenames_t ft
;
1357 ft
.p_set
= pointer_set_create ();
1358 ft
.typenames
= NULL
;
1359 cp_walk_tree (&TREE_TYPE (DECL_TEMPLATE_RESULT (t
)),
1360 find_typenames_r
, &ft
, ft
.p_set
);
1361 pointer_set_destroy (ft
.p_set
);
1362 return ft
.typenames
;
1365 /* Pretty print a function decl. There are several ways we want to print a
1366 function declaration. The TFF_ bits in FLAGS tells us how to behave.
1367 As error can only apply the '#' flag once to give 0 and 1 for V, there
1368 is %D which doesn't print the throw specs, and %F which does. */
1371 dump_function_decl (cxx_pretty_printer
*pp
, tree t
, int flags
)
1375 tree cname
= NULL_TREE
;
1376 tree template_args
= NULL_TREE
;
1377 tree template_parms
= NULL_TREE
;
1378 int show_return
= flags
& TFF_RETURN_TYPE
|| flags
& TFF_DECL_SPECIFIERS
;
1379 int do_outer_scope
= ! (flags
& TFF_UNQUALIFIED_NAME
);
1381 vec
<tree
, va_gc
> *typenames
= NULL
;
1383 if (DECL_NAME (t
) && LAMBDA_FUNCTION_P (t
))
1385 /* A lambda's signature is essentially its "type", so defer. */
1386 gcc_assert (LAMBDA_TYPE_P (DECL_CONTEXT (t
)));
1387 dump_type (pp
, DECL_CONTEXT (t
), flags
);
1391 flags
&= ~(TFF_UNQUALIFIED_NAME
| TFF_TEMPLATE_NAME
);
1392 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1393 t
= DECL_TEMPLATE_RESULT (t
);
1395 /* Save the exceptions, in case t is a specialization and we are
1396 emitting an error about incompatible specifications. */
1397 exceptions
= TYPE_RAISES_EXCEPTIONS (TREE_TYPE (t
));
1399 /* Pretty print template instantiations only. */
1400 if (DECL_USE_TEMPLATE (t
) && DECL_TEMPLATE_INFO (t
)
1401 && flag_pretty_templates
)
1405 template_args
= DECL_TI_ARGS (t
);
1406 tmpl
= most_general_template (t
);
1407 if (tmpl
&& TREE_CODE (tmpl
) == TEMPLATE_DECL
)
1409 template_parms
= DECL_TEMPLATE_PARMS (tmpl
);
1411 typenames
= find_typenames (t
);
1415 fntype
= TREE_TYPE (t
);
1416 parmtypes
= FUNCTION_FIRST_USER_PARMTYPE (t
);
1418 if (DECL_CLASS_SCOPE_P (t
))
1419 cname
= DECL_CONTEXT (t
);
1420 /* This is for partially instantiated template methods. */
1421 else if (TREE_CODE (fntype
) == METHOD_TYPE
)
1422 cname
= TREE_TYPE (TREE_VALUE (parmtypes
));
1424 if (flags
& TFF_DECL_SPECIFIERS
)
1426 if (DECL_STATIC_FUNCTION_P (t
))
1427 pp_cxx_ws_string (pp
, "static");
1428 else if (DECL_VIRTUAL_P (t
))
1429 pp_cxx_ws_string (pp
, "virtual");
1431 if (DECL_DECLARED_CONSTEXPR_P (STRIP_TEMPLATE (t
)))
1432 pp_cxx_ws_string (pp
, "constexpr");
1435 /* Print the return type? */
1437 show_return
= !DECL_CONV_FN_P (t
) && !DECL_CONSTRUCTOR_P (t
)
1438 && !DECL_DESTRUCTOR_P (t
);
1441 tree ret
= fndecl_declared_return_type (t
);
1442 dump_type_prefix (pp
, ret
, flags
);
1445 /* Print the function name. */
1446 if (!do_outer_scope
)
1450 dump_type (pp
, cname
, flags
);
1451 pp_cxx_colon_colon (pp
);
1454 dump_scope (pp
, CP_DECL_CONTEXT (t
), flags
);
1456 dump_function_name (pp
, t
, flags
);
1458 if (!(flags
& TFF_NO_FUNCTION_ARGUMENTS
))
1460 dump_parameters (pp
, parmtypes
, flags
);
1462 if (TREE_CODE (fntype
) == METHOD_TYPE
)
1464 pp
->padding
= pp_before
;
1465 pp_cxx_cv_qualifier_seq (pp
, class_of_this_parm (fntype
));
1466 dump_ref_qualifier (pp
, fntype
, flags
);
1469 if (flags
& TFF_EXCEPTION_SPECIFICATION
)
1471 pp
->padding
= pp_before
;
1472 dump_exception_spec (pp
, exceptions
, flags
);
1476 dump_type_suffix (pp
, TREE_TYPE (fntype
), flags
);
1478 /* If T is a template instantiation, dump the parameter binding. */
1479 if (template_parms
!= NULL_TREE
&& template_args
!= NULL_TREE
1480 && !(flags
& TFF_NO_TEMPLATE_BINDINGS
))
1482 pp_cxx_whitespace (pp
);
1483 pp_cxx_left_bracket (pp
);
1484 pp_cxx_ws_string (pp
, M_("with"));
1485 pp_cxx_whitespace (pp
);
1486 dump_template_bindings (pp
, template_parms
, template_args
, typenames
);
1487 pp_cxx_right_bracket (pp
);
1490 else if (template_args
)
1492 bool need_comma
= false;
1494 pp_cxx_begin_template_argument_list (pp
);
1495 template_args
= INNERMOST_TEMPLATE_ARGS (template_args
);
1496 for (i
= 0; i
< TREE_VEC_LENGTH (template_args
); ++i
)
1498 tree arg
= TREE_VEC_ELT (template_args
, i
);
1500 pp_separate_with_comma (pp
);
1501 if (ARGUMENT_PACK_P (arg
))
1502 pp_cxx_left_brace (pp
);
1503 dump_template_argument (pp
, arg
, TFF_PLAIN_IDENTIFIER
);
1504 if (ARGUMENT_PACK_P (arg
))
1505 pp_cxx_right_brace (pp
);
1508 pp_cxx_end_template_argument_list (pp
);
1512 /* Print a parameter list. If this is for a member function, the
1513 member object ptr (and any other hidden args) should have
1514 already been removed. */
1517 dump_parameters (cxx_pretty_printer
*pp
, tree parmtypes
, int flags
)
1520 flags
&= ~TFF_SCOPE
;
1521 pp_cxx_left_paren (pp
);
1523 for (first
= 1; parmtypes
!= void_list_node
;
1524 parmtypes
= TREE_CHAIN (parmtypes
))
1527 pp_separate_with_comma (pp
);
1531 pp_cxx_ws_string (pp
, "...");
1535 dump_type (pp
, TREE_VALUE (parmtypes
), flags
);
1537 if ((flags
& TFF_FUNCTION_DEFAULT_ARGUMENTS
) && TREE_PURPOSE (parmtypes
))
1539 pp_cxx_whitespace (pp
);
1541 pp_cxx_whitespace (pp
);
1542 dump_expr (pp
, TREE_PURPOSE (parmtypes
), flags
| TFF_EXPR_IN_PARENS
);
1546 pp_cxx_right_paren (pp
);
1549 /* Print ref-qualifier of a FUNCTION_TYPE or METHOD_TYPE. FLAGS are ignored. */
1552 dump_ref_qualifier (cxx_pretty_printer
*pp
, tree t
, int flags ATTRIBUTE_UNUSED
)
1554 if (FUNCTION_REF_QUALIFIED (t
))
1556 pp
->padding
= pp_before
;
1557 if (FUNCTION_RVALUE_QUALIFIED (t
))
1558 pp_cxx_ws_string (pp
, "&&");
1560 pp_cxx_ws_string (pp
, "&");
1564 /* Print an exception specification. T is the exception specification. */
1567 dump_exception_spec (cxx_pretty_printer
*pp
, tree t
, int flags
)
1569 if (t
&& TREE_PURPOSE (t
))
1571 pp_cxx_ws_string (pp
, "noexcept");
1572 pp_cxx_whitespace (pp
);
1573 pp_cxx_left_paren (pp
);
1574 if (DEFERRED_NOEXCEPT_SPEC_P (t
))
1575 pp_cxx_ws_string (pp
, "<uninstantiated>");
1577 dump_expr (pp
, TREE_PURPOSE (t
), flags
);
1578 pp_cxx_right_paren (pp
);
1582 pp_cxx_ws_string (pp
, "throw");
1583 pp_cxx_whitespace (pp
);
1584 pp_cxx_left_paren (pp
);
1585 if (TREE_VALUE (t
) != NULL_TREE
)
1588 dump_type (pp
, TREE_VALUE (t
), flags
);
1592 pp_separate_with_comma (pp
);
1594 pp_cxx_right_paren (pp
);
1598 /* Handle the function name for a FUNCTION_DECL node, grokking operators
1599 and destructors properly. */
1602 dump_function_name (cxx_pretty_printer
*pp
, tree t
, int flags
)
1604 tree name
= DECL_NAME (t
);
1606 /* We can get here with a decl that was synthesized by language-
1607 independent machinery (e.g. coverage.c) in which case it won't
1608 have a lang_specific structure attached and DECL_CONSTRUCTOR_P
1609 will crash. In this case it is safe just to print out the
1611 if (!DECL_LANG_SPECIFIC (t
))
1613 pp_cxx_tree_identifier (pp
, name
);
1617 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1618 t
= DECL_TEMPLATE_RESULT (t
);
1620 /* Don't let the user see __comp_ctor et al. */
1621 if (DECL_CONSTRUCTOR_P (t
)
1622 || DECL_DESTRUCTOR_P (t
))
1624 if (LAMBDA_TYPE_P (DECL_CONTEXT (t
)))
1625 name
= get_identifier ("<lambda>");
1626 else if (TYPE_ANONYMOUS_P (DECL_CONTEXT (t
)))
1627 name
= get_identifier ("<constructor>");
1629 name
= constructor_name (DECL_CONTEXT (t
));
1632 if (DECL_DESTRUCTOR_P (t
))
1634 pp_cxx_complement (pp
);
1635 dump_decl (pp
, name
, TFF_PLAIN_IDENTIFIER
);
1637 else if (DECL_CONV_FN_P (t
))
1639 /* This cannot use the hack that the operator's return
1640 type is stashed off of its name because it may be
1641 used for error reporting. In the case of conflicting
1642 declarations, both will have the same name, yet
1643 the types will be different, hence the TREE_TYPE field
1644 of the first name will be clobbered by the second. */
1645 pp_cxx_ws_string (pp
, "operator");
1646 dump_type (pp
, TREE_TYPE (TREE_TYPE (t
)), flags
);
1648 else if (name
&& IDENTIFIER_OPNAME_P (name
))
1649 pp_cxx_tree_identifier (pp
, name
);
1650 else if (name
&& UDLIT_OPER_P (name
))
1651 pp_cxx_tree_identifier (pp
, name
);
1653 dump_decl (pp
, name
, flags
);
1655 if (DECL_TEMPLATE_INFO (t
)
1656 && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t
)
1657 && (TREE_CODE (DECL_TI_TEMPLATE (t
)) != TEMPLATE_DECL
1658 || PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t
))))
1659 dump_template_parms (pp
, DECL_TEMPLATE_INFO (t
), !DECL_USE_TEMPLATE (t
),
1663 /* Dump the template parameters from the template info INFO under control of
1664 FLAGS. PRIMARY indicates whether this is a primary template decl, or
1665 specialization (partial or complete). For partial specializations we show
1666 the specialized parameter values. For a primary template we show no
1670 dump_template_parms (cxx_pretty_printer
*pp
, tree info
,
1671 int primary
, int flags
)
1673 tree args
= info
? TI_ARGS (info
) : NULL_TREE
;
1675 if (primary
&& flags
& TFF_TEMPLATE_NAME
)
1677 flags
&= ~(TFF_CLASS_KEY_OR_ENUM
| TFF_TEMPLATE_NAME
);
1678 pp_cxx_begin_template_argument_list (pp
);
1680 /* Be careful only to print things when we have them, so as not
1681 to crash producing error messages. */
1682 if (args
&& !primary
)
1685 len
= get_non_default_template_args_count (args
, flags
);
1687 args
= INNERMOST_TEMPLATE_ARGS (args
);
1688 for (ix
= 0; ix
!= len
; ix
++)
1690 tree arg
= TREE_VEC_ELT (args
, ix
);
1692 /* Only print a comma if we know there is an argument coming. In
1693 the case of an empty template argument pack, no actual
1694 argument will be printed. */
1696 && (!ARGUMENT_PACK_P (arg
)
1697 || TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg
)) > 0))
1698 pp_separate_with_comma (pp
);
1701 pp_string (pp
, M_("<template parameter error>"));
1703 dump_template_argument (pp
, arg
, flags
);
1708 tree tpl
= TI_TEMPLATE (info
);
1709 tree parms
= DECL_TEMPLATE_PARMS (tpl
);
1712 parms
= TREE_CODE (parms
) == TREE_LIST
? TREE_VALUE (parms
) : NULL_TREE
;
1713 len
= parms
? TREE_VEC_LENGTH (parms
) : 0;
1715 for (ix
= 0; ix
!= len
; ix
++)
1719 if (TREE_VEC_ELT (parms
, ix
) == error_mark_node
)
1721 pp_string (pp
, M_("<template parameter error>"));
1725 parm
= TREE_VALUE (TREE_VEC_ELT (parms
, ix
));
1728 pp_separate_with_comma (pp
);
1730 dump_decl (pp
, parm
, flags
& ~TFF_DECL_SPECIFIERS
);
1733 pp_cxx_end_template_argument_list (pp
);
1736 /* Print out the arguments of CALL_EXPR T as a parenthesized list using
1737 flags FLAGS. Skip over the first argument if SKIPFIRST is true. */
1740 dump_call_expr_args (cxx_pretty_printer
*pp
, tree t
, int flags
, bool skipfirst
)
1743 call_expr_arg_iterator iter
;
1745 pp_cxx_left_paren (pp
);
1746 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, t
)
1752 dump_expr (pp
, arg
, flags
| TFF_EXPR_IN_PARENS
);
1753 if (more_call_expr_args_p (&iter
))
1754 pp_separate_with_comma (pp
);
1757 pp_cxx_right_paren (pp
);
1760 /* Print out the arguments of AGGR_INIT_EXPR T as a parenthesized list
1761 using flags FLAGS. Skip over the first argument if SKIPFIRST is
1765 dump_aggr_init_expr_args (cxx_pretty_printer
*pp
, tree t
, int flags
,
1769 aggr_init_expr_arg_iterator iter
;
1771 pp_cxx_left_paren (pp
);
1772 FOR_EACH_AGGR_INIT_EXPR_ARG (arg
, iter
, t
)
1778 dump_expr (pp
, arg
, flags
| TFF_EXPR_IN_PARENS
);
1779 if (more_aggr_init_expr_args_p (&iter
))
1780 pp_separate_with_comma (pp
);
1783 pp_cxx_right_paren (pp
);
1786 /* Print out a list of initializers (subr of dump_expr). */
1789 dump_expr_list (cxx_pretty_printer
*pp
, tree l
, int flags
)
1793 dump_expr (pp
, TREE_VALUE (l
), flags
| TFF_EXPR_IN_PARENS
);
1796 pp_separate_with_comma (pp
);
1800 /* Print out a vector of initializers (subr of dump_expr). */
1803 dump_expr_init_vec (cxx_pretty_printer
*pp
, vec
<constructor_elt
, va_gc
> *v
,
1806 unsigned HOST_WIDE_INT idx
;
1809 FOR_EACH_CONSTRUCTOR_VALUE (v
, idx
, value
)
1811 dump_expr (pp
, value
, flags
| TFF_EXPR_IN_PARENS
);
1812 if (idx
!= v
->length () - 1)
1813 pp_separate_with_comma (pp
);
1818 /* We've gotten an indirect REFERENCE (an OBJ_TYPE_REF) to a virtual
1819 function. Resolve it to a close relative -- in the sense of static
1820 type -- variant being overridden. That is close to what was written in
1821 the source code. Subroutine of dump_expr. */
1824 resolve_virtual_fun_from_obj_type_ref (tree ref
)
1826 tree obj_type
= TREE_TYPE (OBJ_TYPE_REF_OBJECT (ref
));
1827 HOST_WIDE_INT index
= tree_low_cst (OBJ_TYPE_REF_TOKEN (ref
), 1);
1828 tree fun
= BINFO_VIRTUALS (TYPE_BINFO (TREE_TYPE (obj_type
)));
1831 fun
= TREE_CHAIN (fun
);
1832 index
-= (TARGET_VTABLE_USES_DESCRIPTORS
1833 ? TARGET_VTABLE_USES_DESCRIPTORS
: 1);
1839 /* Print out an expression E under control of FLAGS. */
1842 dump_expr (cxx_pretty_printer
*pp
, tree t
, int flags
)
1849 if (STATEMENT_CLASS_P (t
))
1851 pp_cxx_ws_string (pp
, M_("<statement>"));
1855 switch (TREE_CODE (t
))
1863 case NAMESPACE_DECL
:
1867 case IDENTIFIER_NODE
:
1868 dump_decl (pp
, t
, ((flags
& ~(TFF_DECL_SPECIFIERS
|TFF_RETURN_TYPE
1869 |TFF_TEMPLATE_HEADER
))
1870 | TFF_NO_FUNCTION_ARGUMENTS
));
1874 if (SSA_NAME_VAR (t
)
1875 && !DECL_ARTIFICIAL (SSA_NAME_VAR (t
)))
1876 dump_expr (pp
, SSA_NAME_VAR (t
), flags
);
1878 pp_cxx_ws_string (pp
, M_("<unknown>"));
1885 pp_constant (pp
, t
);
1888 case USERDEF_LITERAL
:
1889 pp_cxx_userdef_literal (pp
, t
);
1893 /* While waiting for caret diagnostics, avoid printing
1894 __cxa_allocate_exception, __cxa_throw, and the like. */
1895 pp_cxx_ws_string (pp
, M_("<throw-expression>"));
1900 dump_type (pp
, PTRMEM_CST_CLASS (t
), flags
);
1901 pp_cxx_colon_colon (pp
);
1902 pp_cxx_tree_identifier (pp
, DECL_NAME (PTRMEM_CST_MEMBER (t
)));
1906 pp_cxx_left_paren (pp
);
1907 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
1908 pp_separate_with_comma (pp
);
1909 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
1910 pp_cxx_right_paren (pp
);
1914 pp_cxx_left_paren (pp
);
1915 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
1916 pp_string (pp
, " ? ");
1917 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
1918 pp_string (pp
, " : ");
1919 dump_expr (pp
, TREE_OPERAND (t
, 2), flags
| TFF_EXPR_IN_PARENS
);
1920 pp_cxx_right_paren (pp
);
1924 if (TREE_HAS_CONSTRUCTOR (t
))
1926 pp_cxx_ws_string (pp
, "new");
1927 pp_cxx_whitespace (pp
);
1928 dump_type (pp
, TREE_TYPE (TREE_TYPE (t
)), flags
);
1931 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
1934 case AGGR_INIT_EXPR
:
1936 tree fn
= NULL_TREE
;
1938 if (TREE_CODE (AGGR_INIT_EXPR_FN (t
)) == ADDR_EXPR
)
1939 fn
= TREE_OPERAND (AGGR_INIT_EXPR_FN (t
), 0);
1941 if (fn
&& TREE_CODE (fn
) == FUNCTION_DECL
)
1943 if (DECL_CONSTRUCTOR_P (fn
))
1944 dump_type (pp
, DECL_CONTEXT (fn
), flags
);
1946 dump_decl (pp
, fn
, 0);
1949 dump_expr (pp
, AGGR_INIT_EXPR_FN (t
), 0);
1951 dump_aggr_init_expr_args (pp
, t
, flags
, true);
1956 tree fn
= CALL_EXPR_FN (t
);
1957 bool skipfirst
= false;
1959 if (TREE_CODE (fn
) == ADDR_EXPR
)
1960 fn
= TREE_OPERAND (fn
, 0);
1962 /* Nobody is interested in seeing the guts of vcalls. */
1963 if (TREE_CODE (fn
) == OBJ_TYPE_REF
)
1964 fn
= resolve_virtual_fun_from_obj_type_ref (fn
);
1966 if (TREE_TYPE (fn
) != NULL_TREE
1967 && NEXT_CODE (fn
) == METHOD_TYPE
1968 && call_expr_nargs (t
))
1970 tree ob
= CALL_EXPR_ARG (t
, 0);
1971 if (TREE_CODE (ob
) == ADDR_EXPR
)
1973 dump_expr (pp
, TREE_OPERAND (ob
, 0),
1974 flags
| TFF_EXPR_IN_PARENS
);
1977 else if (TREE_CODE (ob
) != PARM_DECL
1978 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob
)), "this"))
1980 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
1985 dump_expr (pp
, fn
, flags
| TFF_EXPR_IN_PARENS
);
1986 dump_call_expr_args (pp
, t
, flags
, skipfirst
);
1991 /* Note that this only works for G++ target exprs. If somebody
1992 builds a general TARGET_EXPR, there's no way to represent that
1993 it initializes anything other that the parameter slot for the
1994 default argument. Note we may have cleared out the first
1995 operand in expand_expr, so don't go killing ourselves. */
1996 if (TREE_OPERAND (t
, 1))
1997 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2000 case POINTER_PLUS_EXPR
:
2001 dump_binary_op (pp
, "+", t
, flags
);
2006 dump_binary_op (pp
, assignment_operator_name_info
[NOP_EXPR
].name
,
2013 case TRUNC_DIV_EXPR
:
2014 case TRUNC_MOD_EXPR
:
2022 case TRUTH_ANDIF_EXPR
:
2023 case TRUTH_ORIF_EXPR
:
2030 case EXACT_DIV_EXPR
:
2031 dump_binary_op (pp
, operator_name_info
[TREE_CODE (t
)].name
, t
, flags
);
2035 case FLOOR_DIV_EXPR
:
2036 case ROUND_DIV_EXPR
:
2038 dump_binary_op (pp
, "/", t
, flags
);
2042 case FLOOR_MOD_EXPR
:
2043 case ROUND_MOD_EXPR
:
2044 dump_binary_op (pp
, "%", t
, flags
);
2049 tree ob
= TREE_OPERAND (t
, 0);
2050 if (INDIRECT_REF_P (ob
))
2052 ob
= TREE_OPERAND (ob
, 0);
2053 if (TREE_CODE (ob
) != PARM_DECL
2055 && strcmp (IDENTIFIER_POINTER (DECL_NAME (ob
)), "this")))
2057 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2058 if (TREE_CODE (TREE_TYPE (ob
)) == REFERENCE_TYPE
)
2066 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2069 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
& ~TFF_EXPR_IN_PARENS
);
2074 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2075 pp_cxx_left_bracket (pp
);
2076 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2077 pp_cxx_right_bracket (pp
);
2080 case ARRAY_NOTATION_REF
:
2081 dump_expr (pp
, ARRAY_NOTATION_ARRAY (t
), flags
| TFF_EXPR_IN_PARENS
);
2082 pp_cxx_left_bracket (pp
);
2083 dump_expr (pp
, ARRAY_NOTATION_START (t
), flags
| TFF_EXPR_IN_PARENS
);
2085 dump_expr (pp
, ARRAY_NOTATION_LENGTH (t
), flags
| TFF_EXPR_IN_PARENS
);
2087 dump_expr (pp
, ARRAY_NOTATION_STRIDE (t
), flags
| TFF_EXPR_IN_PARENS
);
2088 pp_cxx_right_bracket (pp
);
2091 case UNARY_PLUS_EXPR
:
2092 dump_unary_op (pp
, "+", t
, flags
);
2096 if (TREE_CODE (TREE_OPERAND (t
, 0)) == FUNCTION_DECL
2097 || TREE_CODE (TREE_OPERAND (t
, 0)) == STRING_CST
2098 /* An ADDR_EXPR can have reference type. In that case, we
2099 shouldn't print the `&' doing so indicates to the user
2100 that the expression has pointer type. */
2102 && TREE_CODE (TREE_TYPE (t
)) == REFERENCE_TYPE
))
2103 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2104 else if (TREE_CODE (TREE_OPERAND (t
, 0)) == LABEL_DECL
)
2105 dump_unary_op (pp
, "&&", t
, flags
);
2107 dump_unary_op (pp
, "&", t
, flags
);
2111 if (TREE_HAS_CONSTRUCTOR (t
))
2113 t
= TREE_OPERAND (t
, 0);
2114 gcc_assert (TREE_CODE (t
) == CALL_EXPR
);
2115 dump_expr (pp
, CALL_EXPR_FN (t
), flags
| TFF_EXPR_IN_PARENS
);
2116 dump_call_expr_args (pp
, t
, flags
, true);
2120 if (TREE_OPERAND (t
,0) != NULL_TREE
2121 && TREE_TYPE (TREE_OPERAND (t
, 0))
2122 && NEXT_CODE (TREE_OPERAND (t
, 0)) == REFERENCE_TYPE
)
2123 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2125 dump_unary_op (pp
, "*", t
, flags
);
2130 if (TREE_CODE (TREE_OPERAND (t
, 0)) == ADDR_EXPR
2131 && integer_zerop (TREE_OPERAND (t
, 1)))
2132 dump_expr (pp
, TREE_OPERAND (TREE_OPERAND (t
, 0), 0), flags
);
2136 if (!integer_zerop (TREE_OPERAND (t
, 1)))
2138 pp_cxx_left_paren (pp
);
2139 if (!integer_onep (TYPE_SIZE_UNIT
2140 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (t
, 0))))))
2142 pp_cxx_left_paren (pp
);
2143 dump_type (pp
, ptr_type_node
, flags
);
2144 pp_cxx_right_paren (pp
);
2147 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2148 if (!integer_zerop (TREE_OPERAND (t
, 1)))
2150 pp_cxx_ws_string (pp
, "+");
2151 dump_expr (pp
, fold_convert (ssizetype
, TREE_OPERAND (t
, 1)),
2153 pp_cxx_right_paren (pp
);
2160 case TRUTH_NOT_EXPR
:
2161 case PREDECREMENT_EXPR
:
2162 case PREINCREMENT_EXPR
:
2163 dump_unary_op (pp
, operator_name_info
[TREE_CODE (t
)].name
, t
, flags
);
2166 case POSTDECREMENT_EXPR
:
2167 case POSTINCREMENT_EXPR
:
2168 pp_cxx_left_paren (pp
);
2169 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2170 pp_cxx_ws_string (pp
, operator_name_info
[TREE_CODE (t
)].name
);
2171 pp_cxx_right_paren (pp
);
2174 case NON_LVALUE_EXPR
:
2175 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
2176 should be another level of INDIRECT_REF so that I don't have to do
2178 if (TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == POINTER_TYPE
)
2180 tree next
= TREE_TYPE (TREE_TYPE (t
));
2182 while (TYPE_PTR_P (next
))
2183 next
= TREE_TYPE (next
);
2185 if (TREE_CODE (next
) == FUNCTION_TYPE
)
2187 if (flags
& TFF_EXPR_IN_PARENS
)
2188 pp_cxx_left_paren (pp
);
2190 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2191 if (flags
& TFF_EXPR_IN_PARENS
)
2192 pp_cxx_right_paren (pp
);
2195 /* Else fall through. */
2197 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2201 case IMPLICIT_CONV_EXPR
:
2202 case VIEW_CONVERT_EXPR
:
2204 tree op
= TREE_OPERAND (t
, 0);
2205 tree ttype
= TREE_TYPE (t
);
2206 tree optype
= TREE_TYPE (op
);
2208 if (TREE_CODE (ttype
) != TREE_CODE (optype
)
2209 && POINTER_TYPE_P (ttype
)
2210 && POINTER_TYPE_P (optype
)
2211 && same_type_p (TREE_TYPE (optype
),
2214 if (TREE_CODE (ttype
) == REFERENCE_TYPE
)
2215 dump_unary_op (pp
, "*", t
, flags
);
2217 dump_unary_op (pp
, "&", t
, flags
);
2219 else if (!same_type_p (TREE_TYPE (op
), TREE_TYPE (t
)))
2221 /* It is a cast, but we cannot tell whether it is a
2222 reinterpret or static cast. Use the C style notation. */
2223 if (flags
& TFF_EXPR_IN_PARENS
)
2224 pp_cxx_left_paren (pp
);
2225 pp_cxx_left_paren (pp
);
2226 dump_type (pp
, TREE_TYPE (t
), flags
);
2227 pp_cxx_right_paren (pp
);
2228 dump_expr (pp
, op
, flags
| TFF_EXPR_IN_PARENS
);
2229 if (flags
& TFF_EXPR_IN_PARENS
)
2230 pp_cxx_right_paren (pp
);
2233 dump_expr (pp
, op
, flags
);
2238 if (TREE_TYPE (t
) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t
)))
2240 tree idx
= build_ptrmemfunc_access_expr (t
, pfn_identifier
);
2242 if (integer_zerop (idx
))
2244 /* A NULL pointer-to-member constant. */
2245 pp_cxx_left_paren (pp
);
2246 pp_cxx_left_paren (pp
);
2247 dump_type (pp
, TREE_TYPE (t
), flags
);
2248 pp_cxx_right_paren (pp
);
2249 pp_character (pp
, '0');
2250 pp_cxx_right_paren (pp
);
2253 else if (host_integerp (idx
, 0))
2256 unsigned HOST_WIDE_INT n
;
2258 t
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t
)));
2259 t
= TYPE_METHOD_BASETYPE (t
);
2260 virtuals
= BINFO_VIRTUALS (TYPE_BINFO (TYPE_MAIN_VARIANT (t
)));
2262 n
= tree_low_cst (idx
, 0);
2264 /* Map vtable index back one, to allow for the null pointer to
2268 while (n
> 0 && virtuals
)
2271 virtuals
= TREE_CHAIN (virtuals
);
2275 dump_expr (pp
, BV_FN (virtuals
),
2276 flags
| TFF_EXPR_IN_PARENS
);
2281 if (TREE_TYPE (t
) && LAMBDA_TYPE_P (TREE_TYPE (t
)))
2282 pp_string (pp
, "<lambda closure object>");
2283 if (TREE_TYPE (t
) && EMPTY_CONSTRUCTOR_P (t
))
2285 dump_type (pp
, TREE_TYPE (t
), 0);
2286 pp_cxx_left_paren (pp
);
2287 pp_cxx_right_paren (pp
);
2291 if (!BRACE_ENCLOSED_INITIALIZER_P (t
))
2292 dump_type (pp
, TREE_TYPE (t
), 0);
2293 pp_cxx_left_brace (pp
);
2294 dump_expr_init_vec (pp
, CONSTRUCTOR_ELTS (t
), flags
);
2295 pp_cxx_right_brace (pp
);
2302 tree ob
= TREE_OPERAND (t
, 0);
2303 if (is_dummy_object (ob
))
2305 t
= TREE_OPERAND (t
, 1);
2306 if (TREE_CODE (t
) == FUNCTION_DECL
)
2308 dump_expr (pp
, t
, flags
| TFF_EXPR_IN_PARENS
);
2309 else if (BASELINK_P (t
))
2310 dump_expr (pp
, OVL_CURRENT (BASELINK_FUNCTIONS (t
)),
2311 flags
| TFF_EXPR_IN_PARENS
);
2313 dump_decl (pp
, t
, flags
);
2317 if (INDIRECT_REF_P (ob
))
2319 dump_expr (pp
, TREE_OPERAND (ob
, 0), flags
| TFF_EXPR_IN_PARENS
);
2325 dump_expr (pp
, ob
, flags
| TFF_EXPR_IN_PARENS
);
2329 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2334 case TEMPLATE_PARM_INDEX
:
2335 dump_decl (pp
, TEMPLATE_PARM_DECL (t
), flags
& ~TFF_DECL_SPECIFIERS
);
2339 if (TREE_OPERAND (t
, 0) == NULL_TREE
2340 || TREE_CHAIN (TREE_OPERAND (t
, 0)))
2342 dump_type (pp
, TREE_TYPE (t
), flags
);
2343 pp_cxx_left_paren (pp
);
2344 dump_expr_list (pp
, TREE_OPERAND (t
, 0), flags
);
2345 pp_cxx_right_paren (pp
);
2349 pp_cxx_left_paren (pp
);
2350 dump_type (pp
, TREE_TYPE (t
), flags
);
2351 pp_cxx_right_paren (pp
);
2352 pp_cxx_left_paren (pp
);
2353 dump_expr_list (pp
, TREE_OPERAND (t
, 0), flags
);
2354 pp_cxx_right_paren (pp
);
2358 case STATIC_CAST_EXPR
:
2359 pp_cxx_ws_string (pp
, "static_cast");
2361 case REINTERPRET_CAST_EXPR
:
2362 pp_cxx_ws_string (pp
, "reinterpret_cast");
2364 case CONST_CAST_EXPR
:
2365 pp_cxx_ws_string (pp
, "const_cast");
2367 case DYNAMIC_CAST_EXPR
:
2368 pp_cxx_ws_string (pp
, "dynamic_cast");
2370 pp_cxx_begin_template_argument_list (pp
);
2371 dump_type (pp
, TREE_TYPE (t
), flags
);
2372 pp_cxx_end_template_argument_list (pp
);
2373 pp_cxx_left_paren (pp
);
2374 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2375 pp_cxx_right_paren (pp
);
2379 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2385 if (TREE_CODE (t
) == SIZEOF_EXPR
)
2386 pp_cxx_ws_string (pp
, "sizeof");
2389 gcc_assert (TREE_CODE (t
) == ALIGNOF_EXPR
);
2390 pp_cxx_ws_string (pp
, "__alignof__");
2392 op
= TREE_OPERAND (t
, 0);
2393 if (PACK_EXPANSION_P (op
))
2395 pp_string (pp
, "...");
2396 op
= PACK_EXPANSION_PATTERN (op
);
2398 pp_cxx_whitespace (pp
);
2399 pp_cxx_left_paren (pp
);
2400 if (TREE_CODE (t
) == SIZEOF_EXPR
&& SIZEOF_EXPR_TYPE_P (t
))
2401 dump_type (pp
, TREE_TYPE (op
), flags
);
2402 else if (TYPE_P (TREE_OPERAND (t
, 0)))
2403 dump_type (pp
, op
, flags
);
2405 dump_expr (pp
, op
, flags
);
2406 pp_cxx_right_paren (pp
);
2409 case AT_ENCODE_EXPR
:
2410 pp_cxx_ws_string (pp
, "@encode");
2411 pp_cxx_whitespace (pp
);
2412 pp_cxx_left_paren (pp
);
2413 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
2414 pp_cxx_right_paren (pp
);
2418 pp_cxx_ws_string (pp
, "noexcept");
2419 pp_cxx_whitespace (pp
);
2420 pp_cxx_left_paren (pp
);
2421 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2422 pp_cxx_right_paren (pp
);
2427 pp_cxx_ws_string (pp
, operator_name_info
[TREE_CODE (t
)].name
);
2428 pp_cxx_whitespace (pp
);
2429 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2433 pp_string (pp
, M_("<unparsed>"));
2436 case TRY_CATCH_EXPR
:
2437 case WITH_CLEANUP_EXPR
:
2438 case CLEANUP_POINT_EXPR
:
2439 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2442 case PSEUDO_DTOR_EXPR
:
2443 dump_expr (pp
, TREE_OPERAND (t
, 2), flags
);
2445 dump_type (pp
, TREE_OPERAND (t
, 0), flags
);
2446 pp_cxx_colon_colon (pp
);
2447 pp_cxx_complement (pp
);
2448 dump_type (pp
, TREE_OPERAND (t
, 1), flags
);
2451 case TEMPLATE_ID_EXPR
:
2452 dump_decl (pp
, t
, flags
);
2458 case STATEMENT_LIST
:
2459 /* We don't yet have a way of dumping statements in a
2460 human-readable format. */
2461 pp_string (pp
, "({...})");
2465 pp_string (pp
, "while (1) { ");
2466 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2467 pp_cxx_right_brace (pp
);
2471 pp_string (pp
, "if (");
2472 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2473 pp_string (pp
, ") break; ");
2477 dump_expr (pp
, BASELINK_FUNCTIONS (t
), flags
& ~TFF_EXPR_IN_PARENS
);
2480 case EMPTY_CLASS_EXPR
:
2481 dump_type (pp
, TREE_TYPE (t
), flags
);
2482 pp_cxx_left_paren (pp
);
2483 pp_cxx_right_paren (pp
);
2486 case NON_DEPENDENT_EXPR
:
2487 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
);
2490 case ARGUMENT_PACK_SELECT
:
2491 dump_template_argument (pp
, ARGUMENT_PACK_SELECT_FROM_PACK (t
), flags
);
2503 pp_type_specifier_seq (pp
, t
);
2507 /* We get here when we want to print a dependent type as an
2508 id-expression, without any disambiguator decoration. */
2509 pp_id_expression (pp
, t
);
2512 case TEMPLATE_TYPE_PARM
:
2513 case TEMPLATE_TEMPLATE_PARM
:
2514 case BOUND_TEMPLATE_TEMPLATE_PARM
:
2515 dump_type (pp
, t
, flags
);
2519 pp_cxx_trait_expression (pp
, t
);
2523 pp_cxx_va_arg_expression (pp
, t
);
2527 pp_cxx_offsetof_expression (pp
, t
);
2531 dump_decl (pp
, t
, flags
);
2534 case EXPR_PACK_EXPANSION
:
2541 case VEC_DELETE_EXPR
:
2547 case UNORDERED_EXPR
:
2557 case FIX_TRUNC_EXPR
:
2559 pp_expression (pp
, t
);
2562 case TRUTH_AND_EXPR
:
2564 case TRUTH_XOR_EXPR
:
2565 if (flags
& TFF_EXPR_IN_PARENS
)
2566 pp_cxx_left_paren (pp
);
2567 pp_expression (pp
, t
);
2568 if (flags
& TFF_EXPR_IN_PARENS
)
2569 pp_cxx_right_paren (pp
);
2573 dump_expr (pp
, resolve_virtual_fun_from_obj_type_ref (t
), flags
);
2577 pp_string (pp
, M_("<lambda>"));
2581 pp_cxx_left_paren (pp
);
2582 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2583 pp_cxx_right_paren (pp
);
2586 /* This list is incomplete, but should suffice for now.
2587 It is very important that `sorry' does not call
2588 `report_error_function'. That could cause an infinite loop. */
2590 pp_unsupported_tree (pp
, t
);
2591 /* fall through to ERROR_MARK... */
2593 pp_string (pp
, M_("<expression error>"));
2599 dump_binary_op (cxx_pretty_printer
*pp
, const char *opstring
, tree t
,
2602 pp_cxx_left_paren (pp
);
2603 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2604 pp_cxx_whitespace (pp
);
2606 pp_cxx_ws_string (pp
, opstring
);
2608 pp_string (pp
, M_("<unknown operator>"));
2609 pp_cxx_whitespace (pp
);
2610 dump_expr (pp
, TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2611 pp_cxx_right_paren (pp
);
2615 dump_unary_op (cxx_pretty_printer
*pp
, const char *opstring
, tree t
, int flags
)
2617 if (flags
& TFF_EXPR_IN_PARENS
)
2618 pp_cxx_left_paren (pp
);
2619 pp_cxx_ws_string (pp
, opstring
);
2620 dump_expr (pp
, TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2621 if (flags
& TFF_EXPR_IN_PARENS
)
2622 pp_cxx_right_paren (pp
);
2626 reinit_cxx_pp (void)
2628 pp_clear_output_area (cxx_pp
);
2629 cxx_pp
->padding
= pp_none
;
2630 pp_indentation (cxx_pp
) = 0;
2631 pp_needs_newline (cxx_pp
) = false;
2632 cxx_pp
->enclosing_scope
= current_function_decl
;
2636 /* Exported interface to stringifying types, exprs and decls under TFF_*
2640 type_as_string (tree typ
, int flags
)
2643 pp_translate_identifiers (cxx_pp
) = false;
2644 dump_type (cxx_pp
, typ
, flags
);
2645 return pp_formatted_text (cxx_pp
);
2649 type_as_string_translate (tree typ
, int flags
)
2652 dump_type (cxx_pp
, typ
, flags
);
2653 return pp_formatted_text (cxx_pp
);
2657 expr_as_string (tree decl
, int flags
)
2660 pp_translate_identifiers (cxx_pp
) = false;
2661 dump_expr (cxx_pp
, decl
, flags
);
2662 return pp_formatted_text (cxx_pp
);
2665 /* Wrap decl_as_string with options appropriate for dwarf. */
2668 decl_as_dwarf_string (tree decl
, int flags
)
2671 /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag
2672 here will be adequate to get the desired behaviour. */
2673 cxx_pp
->flags
|= pp_c_flag_gnu_v3
;
2674 name
= decl_as_string (decl
, flags
);
2675 /* Subsequent calls to the pretty printer shouldn't use this style. */
2676 cxx_pp
->flags
&= ~pp_c_flag_gnu_v3
;
2681 decl_as_string (tree decl
, int flags
)
2684 pp_translate_identifiers (cxx_pp
) = false;
2685 dump_decl (cxx_pp
, decl
, flags
);
2686 return pp_formatted_text (cxx_pp
);
2690 decl_as_string_translate (tree decl
, int flags
)
2693 dump_decl (cxx_pp
, decl
, flags
);
2694 return pp_formatted_text (cxx_pp
);
2697 /* Wrap lang_decl_name with options appropriate for dwarf. */
2700 lang_decl_dwarf_name (tree decl
, int v
, bool translate
)
2703 /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag
2704 here will be adequate to get the desired behaviour. */
2705 cxx_pp
->flags
|= pp_c_flag_gnu_v3
;
2706 name
= lang_decl_name (decl
, v
, translate
);
2707 /* Subsequent calls to the pretty printer shouldn't use this style. */
2708 cxx_pp
->flags
&= ~pp_c_flag_gnu_v3
;
2712 /* Generate the three forms of printable names for cxx_printable_name. */
2715 lang_decl_name (tree decl
, int v
, bool translate
)
2719 ? decl_as_string_translate (decl
, TFF_DECL_SPECIFIERS
)
2720 : decl_as_string (decl
, TFF_DECL_SPECIFIERS
));
2723 pp_translate_identifiers (cxx_pp
) = translate
;
2725 && (DECL_CLASS_SCOPE_P (decl
)
2726 || (DECL_NAMESPACE_SCOPE_P (decl
)
2727 && CP_DECL_CONTEXT (decl
) != global_namespace
)))
2729 dump_type (cxx_pp
, CP_DECL_CONTEXT (decl
), TFF_PLAIN_IDENTIFIER
);
2730 pp_cxx_colon_colon (cxx_pp
);
2733 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2734 dump_function_name (cxx_pp
, decl
, TFF_PLAIN_IDENTIFIER
);
2735 else if ((DECL_NAME (decl
) == NULL_TREE
)
2736 && TREE_CODE (decl
) == NAMESPACE_DECL
)
2737 dump_decl (cxx_pp
, decl
, TFF_PLAIN_IDENTIFIER
| TFF_UNQUALIFIED_NAME
);
2739 dump_decl (cxx_pp
, DECL_NAME (decl
), TFF_PLAIN_IDENTIFIER
);
2741 return pp_formatted_text (cxx_pp
);
2744 /* Return the location of a tree passed to %+ formats. */
2747 location_of (tree t
)
2749 if (TREE_CODE (t
) == PARM_DECL
&& DECL_CONTEXT (t
))
2750 t
= DECL_CONTEXT (t
);
2751 else if (TYPE_P (t
))
2753 t
= TYPE_MAIN_DECL (t
);
2755 return input_location
;
2757 else if (TREE_CODE (t
) == OVERLOAD
)
2758 t
= OVL_FUNCTION (t
);
2761 return DECL_SOURCE_LOCATION (t
);
2762 return EXPR_LOC_OR_HERE (t
);
2765 /* Now the interfaces from error et al to dump_type et al. Each takes an
2766 on/off VERBOSE flag and supply the appropriate TFF_ flags to a dump_
2770 decl_to_string (tree decl
, int verbose
)
2774 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == RECORD_TYPE
2775 || TREE_CODE (decl
) == UNION_TYPE
|| TREE_CODE (decl
) == ENUMERAL_TYPE
)
2776 flags
= TFF_CLASS_KEY_OR_ENUM
;
2778 flags
|= TFF_DECL_SPECIFIERS
;
2779 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
2780 flags
|= TFF_DECL_SPECIFIERS
| TFF_RETURN_TYPE
;
2781 flags
|= TFF_TEMPLATE_HEADER
;
2784 dump_decl (cxx_pp
, decl
, flags
);
2785 return pp_formatted_text (cxx_pp
);
2789 expr_to_string (tree decl
)
2792 dump_expr (cxx_pp
, decl
, 0);
2793 return pp_formatted_text (cxx_pp
);
2797 fndecl_to_string (tree fndecl
, int verbose
)
2801 flags
= TFF_EXCEPTION_SPECIFICATION
| TFF_DECL_SPECIFIERS
2802 | TFF_TEMPLATE_HEADER
;
2804 flags
|= TFF_FUNCTION_DEFAULT_ARGUMENTS
;
2806 dump_decl (cxx_pp
, fndecl
, flags
);
2807 return pp_formatted_text (cxx_pp
);
2812 code_to_string (enum tree_code c
)
2814 return tree_code_name
[c
];
2818 language_to_string (enum languages c
)
2825 case lang_cplusplus
:
2837 /* Return the proper printed version of a parameter to a C++ function. */
2840 parm_to_string (int p
)
2844 pp_string (cxx_pp
, "'this'");
2846 pp_decimal_int (cxx_pp
, p
+ 1);
2847 return pp_formatted_text (cxx_pp
);
2851 op_to_string (enum tree_code p
)
2853 tree id
= operator_name_info
[p
].identifier
;
2854 return id
? IDENTIFIER_POINTER (id
) : M_("<unknown>");
2858 type_to_string (tree typ
, int verbose
)
2862 flags
|= TFF_CLASS_KEY_OR_ENUM
;
2863 flags
|= TFF_TEMPLATE_HEADER
;
2866 dump_type (cxx_pp
, typ
, flags
);
2867 /* If we're printing a type that involves typedefs, also print the
2868 stripped version. But sometimes the stripped version looks
2869 exactly the same, so we don't want it after all. To avoid printing
2870 it in that case, we play ugly obstack games. */
2871 if (typ
&& TYPE_P (typ
) && typ
!= TYPE_CANONICAL (typ
)
2872 && !uses_template_parms (typ
))
2874 int aka_start
; char *p
;
2875 struct obstack
*ob
= cxx_pp
->buffer
->obstack
;
2876 /* Remember the end of the initial dump. */
2877 int len
= obstack_object_size (ob
);
2878 tree aka
= strip_typedefs (typ
);
2879 pp_string (cxx_pp
, " {aka");
2880 pp_cxx_whitespace (cxx_pp
);
2881 /* And remember the start of the aka dump. */
2882 aka_start
= obstack_object_size (ob
);
2883 dump_type (cxx_pp
, aka
, flags
);
2884 pp_right_brace (cxx_pp
);
2885 p
= (char*)obstack_base (ob
);
2886 /* If they are identical, cut off the aka with a NUL. */
2887 if (memcmp (p
, p
+aka_start
, len
) == 0)
2890 return pp_formatted_text (cxx_pp
);
2894 assop_to_string (enum tree_code p
)
2896 tree id
= assignment_operator_name_info
[(int) p
].identifier
;
2897 return id
? IDENTIFIER_POINTER (id
) : M_("{unknown}");
2901 args_to_string (tree p
, int verbose
)
2905 flags
|= TFF_CLASS_KEY_OR_ENUM
;
2910 if (TYPE_P (TREE_VALUE (p
)))
2911 return type_as_string_translate (p
, flags
);
2914 for (; p
; p
= TREE_CHAIN (p
))
2916 if (TREE_VALUE (p
) == null_node
)
2917 pp_cxx_ws_string (cxx_pp
, "NULL");
2919 dump_type (cxx_pp
, error_type (TREE_VALUE (p
)), flags
);
2921 pp_separate_with_comma (cxx_pp
);
2923 return pp_formatted_text (cxx_pp
);
2926 /* Pretty-print a deduction substitution (from deduction_tsubst_fntype). P
2927 is a TREE_LIST with purpose the TEMPLATE_DECL, value the template
2931 subst_to_string (tree p
)
2933 tree decl
= TREE_PURPOSE (p
);
2934 tree targs
= TREE_VALUE (p
);
2935 tree tparms
= DECL_TEMPLATE_PARMS (decl
);
2936 int flags
= (TFF_DECL_SPECIFIERS
|TFF_TEMPLATE_HEADER
2937 |TFF_NO_TEMPLATE_BINDINGS
);
2943 dump_template_decl (cxx_pp
, TREE_PURPOSE (p
), flags
);
2944 pp_cxx_whitespace (cxx_pp
);
2945 pp_cxx_left_bracket (cxx_pp
);
2946 pp_cxx_ws_string (cxx_pp
, M_("with"));
2947 pp_cxx_whitespace (cxx_pp
);
2948 dump_template_bindings (cxx_pp
, tparms
, targs
, NULL
);
2949 pp_cxx_right_bracket (cxx_pp
);
2950 return pp_formatted_text (cxx_pp
);
2954 cv_to_string (tree p
, int v
)
2957 cxx_pp
->padding
= v
? pp_before
: pp_none
;
2958 pp_cxx_cv_qualifier_seq (cxx_pp
, p
);
2959 return pp_formatted_text (cxx_pp
);
2962 /* Langhook for print_error_function. */
2964 cxx_print_error_function (diagnostic_context
*context
, const char *file
,
2965 diagnostic_info
*diagnostic
)
2967 lhd_print_error_function (context
, file
, diagnostic
);
2968 pp_set_prefix (context
->printer
, file
);
2969 maybe_print_instantiation_context (context
);
2973 cp_diagnostic_starter (diagnostic_context
*context
,
2974 diagnostic_info
*diagnostic
)
2976 diagnostic_report_current_module (context
, diagnostic
->location
);
2977 cp_print_error_function (context
, diagnostic
);
2978 maybe_print_instantiation_context (context
);
2979 maybe_print_constexpr_context (context
);
2980 pp_set_prefix (context
->printer
, diagnostic_build_prefix (context
,
2985 cp_diagnostic_finalizer (diagnostic_context
*context
,
2986 diagnostic_info
*diagnostic
)
2988 virt_loc_aware_diagnostic_finalizer (context
, diagnostic
);
2989 pp_destroy_prefix (context
->printer
);
2992 /* Print current function onto BUFFER, in the process of reporting
2993 a diagnostic message. Called from cp_diagnostic_starter. */
2995 cp_print_error_function (diagnostic_context
*context
,
2996 diagnostic_info
*diagnostic
)
2998 /* If we are in an instantiation context, current_function_decl is likely
2999 to be wrong, so just rely on print_instantiation_full_context. */
3000 if (current_instantiation ())
3002 if (diagnostic_last_function_changed (context
, diagnostic
))
3004 const char *old_prefix
= context
->printer
->prefix
;
3005 const char *file
= LOCATION_FILE (diagnostic
->location
);
3006 tree abstract_origin
= diagnostic_abstract_origin (diagnostic
);
3007 char *new_prefix
= (file
&& abstract_origin
== NULL
)
3008 ? file_name_as_prefix (context
, file
) : NULL
;
3010 pp_set_prefix (context
->printer
, new_prefix
);
3012 if (current_function_decl
== NULL
)
3013 pp_string (context
->printer
, _("At global scope:"));
3018 if (abstract_origin
)
3020 ao
= BLOCK_ABSTRACT_ORIGIN (abstract_origin
);
3021 while (TREE_CODE (ao
) == BLOCK
3022 && BLOCK_ABSTRACT_ORIGIN (ao
)
3023 && BLOCK_ABSTRACT_ORIGIN (ao
) != ao
)
3024 ao
= BLOCK_ABSTRACT_ORIGIN (ao
);
3025 gcc_assert (TREE_CODE (ao
) == FUNCTION_DECL
);
3029 fndecl
= current_function_decl
;
3031 pp_printf (context
->printer
, function_category (fndecl
),
3032 cxx_printable_name_translate (fndecl
, 2));
3034 while (abstract_origin
)
3037 tree block
= abstract_origin
;
3039 locus
= &BLOCK_SOURCE_LOCATION (block
);
3041 block
= BLOCK_SUPERCONTEXT (block
);
3042 while (block
&& TREE_CODE (block
) == BLOCK
3043 && BLOCK_ABSTRACT_ORIGIN (block
))
3045 ao
= BLOCK_ABSTRACT_ORIGIN (block
);
3047 while (TREE_CODE (ao
) == BLOCK
3048 && BLOCK_ABSTRACT_ORIGIN (ao
)
3049 && BLOCK_ABSTRACT_ORIGIN (ao
) != ao
)
3050 ao
= BLOCK_ABSTRACT_ORIGIN (ao
);
3052 if (TREE_CODE (ao
) == FUNCTION_DECL
)
3057 else if (TREE_CODE (ao
) != BLOCK
)
3060 block
= BLOCK_SUPERCONTEXT (block
);
3063 abstract_origin
= block
;
3066 while (block
&& TREE_CODE (block
) == BLOCK
)
3067 block
= BLOCK_SUPERCONTEXT (block
);
3069 if (block
&& TREE_CODE (block
) == FUNCTION_DECL
)
3071 abstract_origin
= NULL
;
3075 expanded_location s
= expand_location (*locus
);
3076 pp_character (context
->printer
, ',');
3077 pp_newline (context
->printer
);
3080 if (context
->show_column
&& s
.column
!= 0)
3081 pp_printf (context
->printer
,
3082 _(" inlined from %qs at %r%s:%d:%d%R"),
3083 cxx_printable_name_translate (fndecl
, 2),
3084 "locus", s
.file
, s
.line
, s
.column
);
3086 pp_printf (context
->printer
,
3087 _(" inlined from %qs at %r%s:%d%R"),
3088 cxx_printable_name_translate (fndecl
, 2),
3089 "locus", s
.file
, s
.line
);
3093 pp_printf (context
->printer
, _(" inlined from %qs"),
3094 cxx_printable_name_translate (fndecl
, 2));
3097 pp_character (context
->printer
, ':');
3099 pp_newline (context
->printer
);
3101 diagnostic_set_last_function (context
, diagnostic
);
3102 pp_destroy_prefix (context
->printer
);
3103 context
->printer
->prefix
= old_prefix
;
3107 /* Returns a description of FUNCTION using standard terminology. The
3108 result is a format string of the form "In CATEGORY %qs". */
3110 function_category (tree fn
)
3112 /* We can get called from the middle-end for diagnostics of function
3113 clones. Make sure we have language specific information before
3114 dereferencing it. */
3115 if (DECL_LANG_SPECIFIC (STRIP_TEMPLATE (fn
))
3116 && DECL_FUNCTION_MEMBER_P (fn
))
3118 if (DECL_STATIC_FUNCTION_P (fn
))
3119 return _("In static member function %qs");
3120 else if (DECL_COPY_CONSTRUCTOR_P (fn
))
3121 return _("In copy constructor %qs");
3122 else if (DECL_CONSTRUCTOR_P (fn
))
3123 return _("In constructor %qs");
3124 else if (DECL_DESTRUCTOR_P (fn
))
3125 return _("In destructor %qs");
3126 else if (LAMBDA_FUNCTION_P (fn
))
3127 return _("In lambda function");
3129 return _("In member function %qs");
3132 return _("In function %qs");
3135 /* Report the full context of a current template instantiation,
3138 print_instantiation_full_context (diagnostic_context
*context
)
3140 struct tinst_level
*p
= current_instantiation ();
3141 location_t location
= input_location
;
3145 pp_verbatim (context
->printer
,
3146 TREE_CODE (p
->decl
) == TREE_LIST
3147 ? _("%s: In substitution of %qS:\n")
3148 : _("%s: In instantiation of %q#D:\n"),
3149 LOCATION_FILE (location
),
3152 location
= p
->locus
;
3156 print_instantiation_partial_context (context
, p
, location
);
3159 /* Helper function of print_instantiation_partial_context() that
3160 prints a single line of instantiation context. */
3163 print_instantiation_partial_context_line (diagnostic_context
*context
,
3164 const struct tinst_level
*t
,
3165 location_t loc
, bool recursive_p
)
3167 expanded_location xloc
;
3168 xloc
= expand_location (loc
);
3170 if (context
->show_column
)
3171 pp_verbatim (context
->printer
, _("%r%s:%d:%d:%R "),
3172 "locus", xloc
.file
, xloc
.line
, xloc
.column
);
3174 pp_verbatim (context
->printer
, _("%r%s:%d:%R "),
3175 "locus", xloc
.file
, xloc
.line
);
3179 if (TREE_CODE (t
->decl
) == TREE_LIST
)
3180 pp_verbatim (context
->printer
,
3182 ? _("recursively required by substitution of %qS\n")
3183 : _("required by substitution of %qS\n"),
3186 pp_verbatim (context
->printer
,
3188 ? _("recursively required from %q#D\n")
3189 : _("required from %q#D\n"),
3194 pp_verbatim (context
->printer
,
3196 ? _("recursively required from here")
3197 : _("required from here"));
3201 /* Same as print_instantiation_full_context but less verbose. */
3204 print_instantiation_partial_context (diagnostic_context
*context
,
3205 struct tinst_level
*t0
, location_t loc
)
3207 struct tinst_level
*t
;
3210 location_t prev_loc
= loc
;
3212 for (t
= t0
; t
!= NULL
; t
= t
->next
)
3213 if (prev_loc
!= t
->locus
)
3215 prev_loc
= t
->locus
;
3221 if (template_backtrace_limit
3222 && n_total
> template_backtrace_limit
)
3224 int skip
= n_total
- template_backtrace_limit
;
3225 int head
= template_backtrace_limit
/ 2;
3227 /* Avoid skipping just 1. If so, skip 2. */
3231 head
= (template_backtrace_limit
- 1) / 2;
3234 for (n
= 0; n
< head
; n
++)
3236 gcc_assert (t
!= NULL
);
3237 if (loc
!= t
->locus
)
3238 print_instantiation_partial_context_line (context
, t
, loc
,
3239 /*recursive_p=*/false);
3243 if (t
!= NULL
&& skip
> 0)
3245 expanded_location xloc
;
3246 xloc
= expand_location (loc
);
3247 if (context
->show_column
)
3248 pp_verbatim (context
->printer
,
3249 _("%r%s:%d:%d:%R [ skipping %d instantiation "
3250 "contexts, use -ftemplate-backtrace-limit=0 to "
3252 "locus", xloc
.file
, xloc
.line
, xloc
.column
, skip
);
3254 pp_verbatim (context
->printer
,
3255 _("%r%s:%d:%R [ skipping %d instantiation "
3256 "contexts, use -ftemplate-backtrace-limit=0 to "
3258 "locus", xloc
.file
, xloc
.line
, skip
);
3263 } while (t
!= NULL
&& --skip
> 0);
3269 while (t
->next
!= NULL
&& t
->locus
== t
->next
->locus
)
3274 print_instantiation_partial_context_line (context
, t
, loc
,
3279 print_instantiation_partial_context_line (context
, NULL
, loc
,
3280 /*recursive_p=*/false);
3281 pp_newline (context
->printer
);
3284 /* Called from cp_thing to print the template context for an error. */
3286 maybe_print_instantiation_context (diagnostic_context
*context
)
3288 if (!problematic_instantiation_changed () || current_instantiation () == 0)
3291 record_last_problematic_instantiation ();
3292 print_instantiation_full_context (context
);
3295 /* Report the bare minimum context of a template instantiation. */
3297 print_instantiation_context (void)
3299 print_instantiation_partial_context
3300 (global_dc
, current_instantiation (), input_location
);
3301 pp_newline (global_dc
->printer
);
3302 diagnostic_flush_buffer (global_dc
);
3305 /* Report what constexpr call(s) we're trying to expand, if any. */
3308 maybe_print_constexpr_context (diagnostic_context
*context
)
3310 vec
<tree
> call_stack
= cx_error_context ();
3314 FOR_EACH_VEC_ELT (call_stack
, ix
, t
)
3316 expanded_location xloc
= expand_location (EXPR_LOCATION (t
));
3317 const char *s
= expr_as_string (t
, 0);
3318 if (context
->show_column
)
3319 pp_verbatim (context
->printer
,
3320 _("%r%s:%d:%d:%R in constexpr expansion of %qs"),
3321 "locus", xloc
.file
, xloc
.line
, xloc
.column
, s
);
3323 pp_verbatim (context
->printer
,
3324 _("%r%s:%d:%R in constexpr expansion of %qs"),
3325 "locus", xloc
.file
, xloc
.line
, s
);
3326 pp_newline (context
->printer
);
3330 /* Called from output_format -- during diagnostic message processing --
3331 to handle C++ specific format specifier with the following meanings:
3332 %A function argument-list.
3336 %F function declaration.
3337 %L language as used in extern "lang".
3339 %P function parameter whose position is indicated by an integer.
3340 %Q assignment operator.
3344 cp_printer (pretty_printer
*pp
, text_info
*text
, const char *spec
,
3345 int precision
, bool wide
, bool set_locus
, bool verbose
)
3349 #define next_tree (t = va_arg (*text->args_ptr, tree))
3350 #define next_tcode ((enum tree_code) va_arg (*text->args_ptr, int))
3351 #define next_lang ((enum languages) va_arg (*text->args_ptr, int))
3352 #define next_int va_arg (*text->args_ptr, int)
3354 if (precision
!= 0 || wide
)
3357 if (text
->locus
== NULL
)
3362 case 'A': result
= args_to_string (next_tree
, verbose
); break;
3363 case 'C': result
= code_to_string (next_tcode
); break;
3366 tree temp
= next_tree
;
3368 && DECL_HAS_DEBUG_EXPR_P (temp
))
3370 temp
= DECL_DEBUG_EXPR (temp
);
3373 result
= expr_to_string (temp
);
3377 result
= decl_to_string (temp
, verbose
);
3380 case 'E': result
= expr_to_string (next_tree
); break;
3381 case 'F': result
= fndecl_to_string (next_tree
, verbose
); break;
3382 case 'L': result
= language_to_string (next_lang
); break;
3383 case 'O': result
= op_to_string (next_tcode
); break;
3384 case 'P': result
= parm_to_string (next_int
); break;
3385 case 'Q': result
= assop_to_string (next_tcode
); break;
3386 case 'S': result
= subst_to_string (next_tree
); break;
3387 case 'T': result
= type_to_string (next_tree
, verbose
); break;
3388 case 'V': result
= cv_to_string (next_tree
, verbose
); break;
3391 percent_K_format (text
);
3398 pp_string (pp
, result
);
3399 if (set_locus
&& t
!= NULL
)
3400 *text
->locus
= location_of (t
);
3408 /* Warn about the use of C++0x features when appropriate. */
3410 maybe_warn_cpp0x (cpp0x_warn_str str
)
3412 if ((cxx_dialect
== cxx98
) && !in_system_header
)
3413 /* We really want to suppress this warning in system headers,
3414 because libstdc++ uses variadic templates even when we aren't
3418 case CPP0X_INITIALIZER_LISTS
:
3419 pedwarn (input_location
, 0,
3420 "extended initializer lists "
3421 "only available with -std=c++11 or -std=gnu++11");
3423 case CPP0X_EXPLICIT_CONVERSION
:
3424 pedwarn (input_location
, 0,
3425 "explicit conversion operators "
3426 "only available with -std=c++11 or -std=gnu++11");
3428 case CPP0X_VARIADIC_TEMPLATES
:
3429 pedwarn (input_location
, 0,
3430 "variadic templates "
3431 "only available with -std=c++11 or -std=gnu++11");
3433 case CPP0X_LAMBDA_EXPR
:
3434 pedwarn (input_location
, 0,
3435 "lambda expressions "
3436 "only available with -std=c++11 or -std=gnu++11");
3439 pedwarn (input_location
, 0,
3440 "C++11 auto only available with -std=c++11 or -std=gnu++11");
3442 case CPP0X_SCOPED_ENUMS
:
3443 pedwarn (input_location
, 0,
3444 "scoped enums only available with -std=c++11 or -std=gnu++11");
3446 case CPP0X_DEFAULTED_DELETED
:
3447 pedwarn (input_location
, 0,
3448 "defaulted and deleted functions "
3449 "only available with -std=c++11 or -std=gnu++11");
3451 case CPP0X_INLINE_NAMESPACES
:
3452 pedwarn (input_location
, OPT_Wpedantic
,
3453 "inline namespaces "
3454 "only available with -std=c++11 or -std=gnu++11");
3456 case CPP0X_OVERRIDE_CONTROLS
:
3457 pedwarn (input_location
, 0,
3458 "override controls (override/final) "
3459 "only available with -std=c++11 or -std=gnu++11");
3462 pedwarn (input_location
, 0,
3463 "non-static data member initializers "
3464 "only available with -std=c++11 or -std=gnu++11");
3466 case CPP0X_USER_DEFINED_LITERALS
:
3467 pedwarn (input_location
, 0,
3468 "user-defined literals "
3469 "only available with -std=c++11 or -std=gnu++11");
3471 case CPP0X_DELEGATING_CTORS
:
3472 pedwarn (input_location
, 0,
3473 "delegating constructors "
3474 "only available with -std=c++11 or -std=gnu++11");
3476 case CPP0X_INHERITING_CTORS
:
3477 pedwarn (input_location
, 0,
3478 "inheriting constructors "
3479 "only available with -std=c++11 or -std=gnu++11");
3481 case CPP0X_ATTRIBUTES
:
3482 pedwarn (input_location
, 0,
3484 "only available with -std=c++11 or -std=gnu++11");
3486 case CPP0X_REF_QUALIFIER
:
3487 pedwarn (input_location
, 0,
3489 "only available with -std=c++11 or -std=gnu++11");
3496 /* Warn about the use of variadic templates when appropriate. */
3498 maybe_warn_variadic_templates (void)
3500 maybe_warn_cpp0x (CPP0X_VARIADIC_TEMPLATES
);
3504 /* Issue an ISO C++98 pedantic warning at LOCATION, conditional on
3505 option OPT with text GMSGID. Use this function to report
3506 diagnostics for constructs that are invalid C++98, but valid
3509 pedwarn_cxx98 (location_t location
, int opt
, const char *gmsgid
, ...)
3511 diagnostic_info diagnostic
;
3515 va_start (ap
, gmsgid
);
3516 diagnostic_set_info (&diagnostic
, gmsgid
, &ap
, location
,
3517 (cxx_dialect
== cxx98
) ? DK_PEDWARN
: DK_WARNING
);
3518 diagnostic
.option_index
= opt
;
3519 ret
= report_diagnostic (&diagnostic
);
3524 /* Issue a diagnostic that NAME cannot be found in SCOPE. DECL is what
3525 we found when we tried to do the lookup. LOCATION is the location of
3526 the NAME identifier. */
3529 qualified_name_lookup_error (tree scope
, tree name
,
3530 tree decl
, location_t location
)
3532 if (scope
== error_mark_node
)
3533 ; /* We already complained. */
3534 else if (TYPE_P (scope
))
3536 if (!COMPLETE_TYPE_P (scope
))
3537 error_at (location
, "incomplete type %qT used in nested name specifier",
3539 else if (TREE_CODE (decl
) == TREE_LIST
)
3541 error_at (location
, "reference to %<%T::%D%> is ambiguous",
3543 print_candidates (decl
);
3546 error_at (location
, "%qD is not a member of %qT", name
, scope
);
3548 else if (scope
!= global_namespace
)
3550 error_at (location
, "%qD is not a member of %qD", name
, scope
);
3551 suggest_alternatives_for (location
, name
);
3555 error_at (location
, "%<::%D%> has not been declared", name
);
3556 suggest_alternatives_for (location
, name
);