1 /* Call-backs for C++ error reporting.
2 This code is non-reentrant.
3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
5 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
24 #include "coretypes.h"
29 #include "diagnostic.h"
30 #include "tree-diagnostic.h"
31 #include "langhooks-def.h"
33 #include "cxx-pretty-print.h"
34 #include "tree-pretty-print.h"
35 #include "pointer-set.h"
36 #include "c-family/c-objc.h"
38 #define pp_separate_with_comma(PP) pp_cxx_separate_with (PP, ',')
39 #define pp_separate_with_semicolon(PP) pp_cxx_separate_with (PP, ';')
41 /* The global buffer where we dump everything. It is there only for
42 transitional purpose. It is expected, in the near future, to be
43 completely removed. */
44 static cxx_pretty_printer scratch_pretty_printer
;
45 #define cxx_pp (&scratch_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 *assop_to_string (enum tree_code
);
55 static const char *code_to_string (enum tree_code
);
56 static const char *cv_to_string (tree
, int);
57 static const char *decl_to_string (tree
, int);
58 static const char *expr_to_string (tree
);
59 static const char *fndecl_to_string (tree
, int);
60 static const char *op_to_string (enum tree_code
);
61 static const char *parm_to_string (int);
62 static const char *type_to_string (tree
, int);
64 static void dump_alias_template_specialization (tree
, int);
65 static void dump_type (tree
, int);
66 static void dump_typename (tree
, int);
67 static void dump_simple_decl (tree
, tree
, int);
68 static void dump_decl (tree
, int);
69 static void dump_template_decl (tree
, int);
70 static void dump_function_decl (tree
, int);
71 static void dump_expr (tree
, int);
72 static void dump_unary_op (const char *, tree
, int);
73 static void dump_binary_op (const char *, tree
, int);
74 static void dump_aggr_type (tree
, int);
75 static void dump_type_prefix (tree
, int);
76 static void dump_type_suffix (tree
, int);
77 static void dump_function_name (tree
, int);
78 static void dump_call_expr_args (tree
, int, bool);
79 static void dump_aggr_init_expr_args (tree
, int, bool);
80 static void dump_expr_list (tree
, int);
81 static void dump_global_iord (tree
);
82 static void dump_parameters (tree
, int);
83 static void dump_exception_spec (tree
, int);
84 static void dump_template_argument (tree
, int);
85 static void dump_template_argument_list (tree
, int);
86 static void dump_template_parameter (tree
, int);
87 static void dump_template_bindings (tree
, tree
, VEC(tree
,gc
) *);
88 static void dump_scope (tree
, int);
89 static void dump_template_parms (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 (pp_base (cxx_pp
), NULL
, 0);
113 pp_cxx_pretty_printer_init (cxx_pp
);
116 /* Dump a scope, if deemed necessary. */
119 dump_scope (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 (scope
, f
);
131 pp_cxx_colon_colon (cxx_pp
);
134 else if (AGGREGATE_TYPE_P (scope
))
136 dump_type (scope
, f
);
137 pp_cxx_colon_colon (cxx_pp
);
139 else if ((flags
& TFF_SCOPE
) && TREE_CODE (scope
) == FUNCTION_DECL
)
141 dump_function_decl (scope
, f
);
142 pp_cxx_colon_colon (cxx_pp
);
146 /* Dump the template ARGument under control of FLAGS. */
149 dump_template_argument (tree arg
, int flags
)
151 if (ARGUMENT_PACK_P (arg
))
152 dump_template_argument_list (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 (arg
, flags
& ~TFF_CLASS_KEY_OR_ENUM
);
159 if (TREE_CODE (arg
) == TREE_LIST
)
160 arg
= TREE_VALUE (arg
);
162 dump_expr (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 (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 (cxx_pp
);
208 dump_template_argument (arg
, flags
);
213 /* Dump a template parameter PARM (a TREE_LIST) under control of FLAGS. */
216 dump_template_parameter (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 (cxx_pp
, "class");
232 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (p
)))
233 pp_cxx_ws_string (cxx_pp
, "...");
235 pp_cxx_tree_identifier (cxx_pp
, DECL_NAME (p
));
237 else if (DECL_NAME (p
))
238 pp_cxx_tree_identifier (cxx_pp
, DECL_NAME (p
));
240 pp_cxx_canonical_template_parameter (cxx_pp
, TREE_TYPE (p
));
243 dump_decl (p
, flags
| TFF_DECL_SPECIFIERS
);
245 if ((flags
& TFF_FUNCTION_DEFAULT_ARGUMENTS
) && a
!= NULL_TREE
)
247 pp_cxx_whitespace (cxx_pp
);
249 pp_cxx_whitespace (cxx_pp
);
250 if (TREE_CODE (p
) == TYPE_DECL
|| TREE_CODE (p
) == TEMPLATE_DECL
)
251 dump_type (a
, flags
& ~TFF_CHASE_TYPEDEF
);
253 dump_expr (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 (tree parms
, tree args
, VEC(tree
,gc
)* typenames
)
264 bool need_semicolon
= false;
270 tree p
= TREE_VALUE (parms
);
271 int lvl
= TMPL_PARMS_DEPTH (parms
);
274 tree lvl_args
= NULL_TREE
;
276 /* Don't crash if we had an invalid argument list. */
277 if (TMPL_ARGS_DEPTH (args
) >= lvl
)
278 lvl_args
= TMPL_ARGS_LEVEL (args
, lvl
);
280 for (i
= 0; i
< TREE_VEC_LENGTH (p
); ++i
)
282 tree arg
= NULL_TREE
;
284 /* Don't crash if we had an invalid argument list. */
285 if (lvl_args
&& NUM_TMPL_ARGS (lvl_args
) > arg_idx
)
286 arg
= TREE_VEC_ELT (lvl_args
, arg_idx
);
289 pp_separate_with_semicolon (cxx_pp
);
290 dump_template_parameter (TREE_VEC_ELT (p
, i
), TFF_PLAIN_IDENTIFIER
);
291 pp_cxx_whitespace (cxx_pp
);
293 pp_cxx_whitespace (cxx_pp
);
296 if (ARGUMENT_PACK_P (arg
))
297 pp_cxx_left_brace (cxx_pp
);
298 dump_template_argument (arg
, TFF_PLAIN_IDENTIFIER
);
299 if (ARGUMENT_PACK_P (arg
))
300 pp_cxx_right_brace (cxx_pp
);
303 pp_string (cxx_pp
, M_("<missing>"));
306 need_semicolon
= true;
309 parms
= TREE_CHAIN (parms
);
312 /* Don't bother with typenames for a partial instantiation. */
313 if (VEC_empty (tree
, typenames
) || uses_template_parms (args
))
316 FOR_EACH_VEC_ELT (tree
, typenames
, i
, t
)
319 pp_separate_with_semicolon (cxx_pp
);
320 dump_type (t
, TFF_PLAIN_IDENTIFIER
);
321 pp_cxx_whitespace (cxx_pp
);
323 pp_cxx_whitespace (cxx_pp
);
324 push_deferring_access_checks (dk_no_check
);
325 t
= tsubst (t
, args
, tf_none
, NULL_TREE
);
326 pop_deferring_access_checks ();
327 /* Strip typedefs. We can't just use TFF_CHASE_TYPEDEF because
328 pp_simple_type_specifier doesn't know about it. */
329 t
= strip_typedefs (t
);
330 dump_type (t
, TFF_PLAIN_IDENTIFIER
);
334 /* Dump a human-readable equivalent of the alias template
335 specialization of T. */
338 dump_alias_template_specialization (tree t
, int flags
)
342 gcc_assert (alias_template_specialization_p (t
));
344 if (!(flags
& TFF_UNQUALIFIED_NAME
))
345 dump_scope (CP_DECL_CONTEXT (TYPE_NAME (t
)), flags
);
346 name
= TYPE_IDENTIFIER (t
);
347 pp_cxx_tree_identifier (cxx_pp
, name
);
348 dump_template_parms (TYPE_TEMPLATE_INFO (t
),
350 flags
& ~TFF_TEMPLATE_HEADER
);
353 /* Dump a human-readable equivalent of TYPE. FLAGS controls the
357 dump_type (tree t
, int flags
)
362 /* Don't print e.g. "struct mytypedef". */
363 if (TYPE_P (t
) && typedef_variant_p (t
))
365 tree decl
= TYPE_NAME (t
);
366 if ((flags
& TFF_CHASE_TYPEDEF
)
367 || DECL_SELF_REFERENCE_P (decl
)
368 || (!flag_pretty_templates
369 && DECL_LANG_SPECIFIC (decl
) && DECL_TEMPLATE_INFO (decl
)))
370 t
= strip_typedefs (t
);
371 else if (alias_template_specialization_p (t
))
373 dump_alias_template_specialization (t
, flags
);
376 else if (same_type_p (t
, TREE_TYPE (decl
)))
380 pp_cxx_cv_qualifier_seq (cxx_pp
, t
);
381 pp_cxx_tree_identifier (cxx_pp
, TYPE_IDENTIFIER (t
));
386 if (TYPE_PTRMEMFUNC_P (t
))
389 switch (TREE_CODE (t
))
392 if (t
== init_list_type_node
)
393 pp_string (cxx_pp
, M_("<brace-enclosed initializer list>"));
394 else if (t
== unknown_type_node
)
395 pp_string (cxx_pp
, M_("<unresolved overloaded function type>"));
398 pp_cxx_cv_qualifier_seq (cxx_pp
, t
);
399 pp_cxx_tree_identifier (cxx_pp
, TYPE_IDENTIFIER (t
));
404 /* A list of function parms. */
405 dump_parameters (t
, flags
);
408 case IDENTIFIER_NODE
:
409 pp_cxx_tree_identifier (cxx_pp
, t
);
413 dump_type (BINFO_TYPE (t
), flags
);
419 dump_aggr_type (t
, flags
);
423 if (flags
& TFF_CHASE_TYPEDEF
)
425 dump_type (DECL_ORIGINAL_TYPE (t
)
426 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
), flags
);
429 /* Else fall through. */
433 dump_decl (t
, flags
& ~TFF_DECL_SPECIFIERS
);
442 case FIXED_POINT_TYPE
:
443 pp_type_specifier_seq (cxx_pp
, t
);
446 case TEMPLATE_TEMPLATE_PARM
:
447 /* For parameters inside template signature. */
448 if (TYPE_IDENTIFIER (t
))
449 pp_cxx_tree_identifier (cxx_pp
, TYPE_IDENTIFIER (t
));
451 pp_cxx_canonical_template_parameter (cxx_pp
, t
);
454 case BOUND_TEMPLATE_TEMPLATE_PARM
:
456 tree args
= TYPE_TI_ARGS (t
);
457 pp_cxx_cv_qualifier_seq (cxx_pp
, t
);
458 pp_cxx_tree_identifier (cxx_pp
, TYPE_IDENTIFIER (t
));
459 pp_cxx_begin_template_argument_list (cxx_pp
);
460 dump_template_argument_list (args
, flags
);
461 pp_cxx_end_template_argument_list (cxx_pp
);
465 case TEMPLATE_TYPE_PARM
:
466 pp_cxx_cv_qualifier_seq (cxx_pp
, t
);
467 if (TYPE_IDENTIFIER (t
))
468 pp_cxx_tree_identifier (cxx_pp
, TYPE_IDENTIFIER (t
));
470 pp_cxx_canonical_template_parameter
471 (cxx_pp
, TEMPLATE_TYPE_PARM_INDEX (t
));
474 /* This is not always necessary for pointers and such, but doing this
475 reduces code size. */
484 dump_type_prefix (t
, flags
);
485 dump_type_suffix (t
, flags
);
489 if (! (flags
& TFF_CHASE_TYPEDEF
)
490 && DECL_ORIGINAL_TYPE (TYPE_NAME (t
)))
492 dump_decl (TYPE_NAME (t
), TFF_PLAIN_IDENTIFIER
);
495 pp_cxx_cv_qualifier_seq (cxx_pp
, t
);
496 pp_cxx_ws_string (cxx_pp
,
497 TYPENAME_IS_ENUM_P (t
) ? "enum"
498 : TYPENAME_IS_CLASS_P (t
) ? "class"
500 dump_typename (t
, flags
);
503 case UNBOUND_CLASS_TEMPLATE
:
504 if (! (flags
& TFF_UNQUALIFIED_NAME
))
506 dump_type (TYPE_CONTEXT (t
), flags
);
507 pp_cxx_colon_colon (cxx_pp
);
509 pp_cxx_ws_string (cxx_pp
, "template");
510 dump_type (DECL_NAME (TYPE_NAME (t
)), flags
);
514 pp_cxx_ws_string (cxx_pp
, "__typeof__");
515 pp_cxx_whitespace (cxx_pp
);
516 pp_cxx_left_paren (cxx_pp
);
517 dump_expr (TYPEOF_TYPE_EXPR (t
), flags
& ~TFF_EXPR_IN_PARENS
);
518 pp_cxx_right_paren (cxx_pp
);
521 case UNDERLYING_TYPE
:
522 pp_cxx_ws_string (cxx_pp
, "__underlying_type");
523 pp_cxx_whitespace (cxx_pp
);
524 pp_cxx_left_paren (cxx_pp
);
525 dump_expr (UNDERLYING_TYPE_TYPE (t
), flags
& ~TFF_EXPR_IN_PARENS
);
526 pp_cxx_right_paren (cxx_pp
);
529 case TYPE_PACK_EXPANSION
:
530 dump_type (PACK_EXPANSION_PATTERN (t
), flags
);
531 pp_cxx_ws_string (cxx_pp
, "...");
534 case TYPE_ARGUMENT_PACK
:
535 dump_template_argument (t
, flags
);
539 pp_cxx_ws_string (cxx_pp
, "decltype");
540 pp_cxx_whitespace (cxx_pp
);
541 pp_cxx_left_paren (cxx_pp
);
542 dump_expr (DECLTYPE_TYPE_EXPR (t
), flags
& ~TFF_EXPR_IN_PARENS
);
543 pp_cxx_right_paren (cxx_pp
);
547 pp_string (cxx_pp
, "std::nullptr_t");
551 pp_unsupported_tree (cxx_pp
, t
);
552 /* Fall through to error. */
555 pp_string (cxx_pp
, M_("<type error>"));
560 /* Dump a TYPENAME_TYPE. We need to notice when the context is itself
564 dump_typename (tree t
, int flags
)
566 tree ctx
= TYPE_CONTEXT (t
);
568 if (TREE_CODE (ctx
) == TYPENAME_TYPE
)
569 dump_typename (ctx
, flags
);
571 dump_type (ctx
, flags
& ~TFF_CLASS_KEY_OR_ENUM
);
572 pp_cxx_colon_colon (cxx_pp
);
573 dump_decl (TYPENAME_TYPE_FULLNAME (t
), flags
);
576 /* Return the name of the supplied aggregate, or enumeral type. */
579 class_key_or_enum_as_string (tree t
)
581 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
583 if (SCOPED_ENUM_P (t
))
588 else if (TREE_CODE (t
) == UNION_TYPE
)
590 else if (TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_DECLARED_CLASS (t
))
596 /* Print out a class declaration T under the control of FLAGS,
597 in the form `class foo'. */
600 dump_aggr_type (tree t
, int flags
)
603 const char *variety
= class_key_or_enum_as_string (t
);
607 pp_cxx_cv_qualifier_seq (cxx_pp
, t
);
609 if (flags
& TFF_CLASS_KEY_OR_ENUM
)
610 pp_cxx_ws_string (cxx_pp
, variety
);
612 name
= TYPE_NAME (t
);
616 typdef
= (!DECL_ARTIFICIAL (name
)
617 /* An alias specialization is not considered to be a
619 && !alias_template_specialization_p (t
));
622 && ((flags
& TFF_CHASE_TYPEDEF
)
623 || (!flag_pretty_templates
&& DECL_LANG_SPECIFIC (name
)
624 && DECL_TEMPLATE_INFO (name
))))
625 || DECL_SELF_REFERENCE_P (name
))
627 t
= TYPE_MAIN_VARIANT (t
);
628 name
= TYPE_NAME (t
);
632 tmplate
= !typdef
&& TREE_CODE (t
) != ENUMERAL_TYPE
633 && TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_TEMPLATE_INFO (t
)
634 && (TREE_CODE (CLASSTYPE_TI_TEMPLATE (t
)) != TEMPLATE_DECL
635 || PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t
)));
637 if (! (flags
& TFF_UNQUALIFIED_NAME
))
638 dump_scope (CP_DECL_CONTEXT (name
), flags
| TFF_SCOPE
);
639 flags
&= ~TFF_UNQUALIFIED_NAME
;
642 /* Because the template names are mangled, we have to locate
643 the most general template, and use that name. */
644 tree tpl
= TYPE_TI_TEMPLATE (t
);
646 while (DECL_TEMPLATE_INFO (tpl
))
647 tpl
= DECL_TI_TEMPLATE (tpl
);
650 name
= DECL_NAME (name
);
653 if (name
== 0 || ANON_AGGRNAME_P (name
))
655 if (flags
& TFF_CLASS_KEY_OR_ENUM
)
656 pp_string (cxx_pp
, M_("<anonymous>"));
658 pp_printf (pp_base (cxx_pp
), M_("<anonymous %s>"), variety
);
660 else if (LAMBDANAME_P (name
))
662 /* A lambda's "type" is essentially its signature. */
663 pp_string (cxx_pp
, M_("<lambda"));
664 if (lambda_function (t
))
665 dump_parameters (FUNCTION_FIRST_USER_PARMTYPE (lambda_function (t
)),
667 pp_character(cxx_pp
, '>');
670 pp_cxx_tree_identifier (cxx_pp
, name
);
672 dump_template_parms (TYPE_TEMPLATE_INFO (t
),
673 !CLASSTYPE_USE_TEMPLATE (t
),
674 flags
& ~TFF_TEMPLATE_HEADER
);
677 /* Dump into the obstack the initial part of the output for a given type.
678 This is necessary when dealing with things like functions returning
681 return type of `int (* fee ())()': pointer -> function -> int. Both
682 pointer (and reference and offset) and function (and member) types must
683 deal with prefix and suffix.
685 Arrays must also do this for DECL nodes, like int a[], and for things like
689 dump_type_prefix (tree t
, int flags
)
691 if (TYPE_PTRMEMFUNC_P (t
))
693 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
697 switch (TREE_CODE (t
))
702 tree sub
= TREE_TYPE (t
);
704 dump_type_prefix (sub
, flags
);
705 if (TREE_CODE (sub
) == ARRAY_TYPE
706 || TREE_CODE (sub
) == FUNCTION_TYPE
)
708 pp_cxx_whitespace (cxx_pp
);
709 pp_cxx_left_paren (cxx_pp
);
710 pp_c_attributes_display (pp_c_base (cxx_pp
),
711 TYPE_ATTRIBUTES (sub
));
713 if (TREE_CODE (t
) == POINTER_TYPE
)
714 pp_character(cxx_pp
, '*');
715 else if (TREE_CODE (t
) == REFERENCE_TYPE
)
717 if (TYPE_REF_IS_RVALUE (t
))
718 pp_string (cxx_pp
, "&&");
720 pp_character (cxx_pp
, '&');
722 pp_base (cxx_pp
)->padding
= pp_before
;
723 pp_cxx_cv_qualifier_seq (cxx_pp
, t
);
729 dump_type_prefix (TREE_TYPE (t
), flags
);
730 if (TREE_CODE (t
) == OFFSET_TYPE
) /* pmfs deal with this in d_t_p */
732 pp_maybe_space (cxx_pp
);
733 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
734 pp_cxx_left_paren (cxx_pp
);
735 dump_type (TYPE_OFFSET_BASETYPE (t
), flags
);
736 pp_cxx_colon_colon (cxx_pp
);
738 pp_cxx_star (cxx_pp
);
739 pp_cxx_cv_qualifier_seq (cxx_pp
, t
);
740 pp_base (cxx_pp
)->padding
= pp_before
;
743 /* This can be reached without a pointer when dealing with
744 templates, e.g. std::is_function. */
746 dump_type_prefix (TREE_TYPE (t
), flags
);
750 dump_type_prefix (TREE_TYPE (t
), flags
);
751 pp_maybe_space (cxx_pp
);
752 pp_cxx_left_paren (cxx_pp
);
753 dump_aggr_type (TYPE_METHOD_BASETYPE (t
), flags
);
754 pp_cxx_colon_colon (cxx_pp
);
758 dump_type_prefix (TREE_TYPE (t
), flags
);
762 case IDENTIFIER_NODE
:
767 case TEMPLATE_TYPE_PARM
:
768 case TEMPLATE_TEMPLATE_PARM
:
769 case BOUND_TEMPLATE_TEMPLATE_PARM
:
780 case UNDERLYING_TYPE
:
782 case TYPE_PACK_EXPANSION
:
783 case FIXED_POINT_TYPE
:
785 dump_type (t
, flags
);
786 pp_base (cxx_pp
)->padding
= pp_before
;
790 pp_unsupported_tree (cxx_pp
, t
);
793 pp_string (cxx_pp
, M_("<typeprefixerror>"));
798 /* Dump the suffix of type T, under control of FLAGS. This is the part
799 which appears after the identifier (or function parms). */
802 dump_type_suffix (tree t
, int flags
)
804 if (TYPE_PTRMEMFUNC_P (t
))
805 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
807 switch (TREE_CODE (t
))
812 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
813 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
814 pp_cxx_right_paren (cxx_pp
);
815 dump_type_suffix (TREE_TYPE (t
), flags
);
822 if (TREE_CODE (t
) == METHOD_TYPE
)
823 /* Can only be reached through a pointer. */
824 pp_cxx_right_paren (cxx_pp
);
825 arg
= TYPE_ARG_TYPES (t
);
826 if (TREE_CODE (t
) == METHOD_TYPE
)
827 arg
= TREE_CHAIN (arg
);
829 /* Function pointers don't have default args. Not in standard C++,
830 anyway; they may in g++, but we'll just pretend otherwise. */
831 dump_parameters (arg
, flags
& ~TFF_FUNCTION_DEFAULT_ARGUMENTS
);
833 if (TREE_CODE (t
) == METHOD_TYPE
)
834 pp_cxx_cv_qualifier_seq (cxx_pp
, class_of_this_parm (t
));
836 pp_cxx_cv_qualifier_seq (cxx_pp
, t
);
837 dump_exception_spec (TYPE_RAISES_EXCEPTIONS (t
), flags
);
838 dump_type_suffix (TREE_TYPE (t
), flags
);
843 pp_maybe_space (cxx_pp
);
844 pp_cxx_left_bracket (cxx_pp
);
847 tree dtype
= TYPE_DOMAIN (t
);
848 tree max
= TYPE_MAX_VALUE (dtype
);
849 if (host_integerp (max
, 0))
850 pp_wide_integer (cxx_pp
, tree_low_cst (max
, 0) + 1);
851 else if (TREE_CODE (max
) == MINUS_EXPR
)
852 dump_expr (TREE_OPERAND (max
, 0),
853 flags
& ~TFF_EXPR_IN_PARENS
);
855 dump_expr (fold_build2_loc (input_location
,
856 PLUS_EXPR
, dtype
, max
,
857 build_int_cst (dtype
, 1)),
858 flags
& ~TFF_EXPR_IN_PARENS
);
860 pp_cxx_right_bracket (cxx_pp
);
861 dump_type_suffix (TREE_TYPE (t
), flags
);
865 case IDENTIFIER_NODE
:
870 case TEMPLATE_TYPE_PARM
:
871 case TEMPLATE_TEMPLATE_PARM
:
872 case BOUND_TEMPLATE_TEMPLATE_PARM
:
883 case UNDERLYING_TYPE
:
885 case TYPE_PACK_EXPANSION
:
886 case FIXED_POINT_TYPE
:
891 pp_unsupported_tree (cxx_pp
, t
);
893 /* Don't mark it here, we should have already done in
900 dump_global_iord (tree t
)
902 const char *p
= NULL
;
904 if (DECL_GLOBAL_CTOR_P (t
))
905 p
= M_("(static initializers for %s)");
906 else if (DECL_GLOBAL_DTOR_P (t
))
907 p
= M_("(static destructors for %s)");
911 pp_printf (pp_base (cxx_pp
), p
, input_filename
);
915 dump_simple_decl (tree t
, tree type
, int flags
)
917 if (flags
& TFF_DECL_SPECIFIERS
)
919 if (TREE_CODE (t
) == VAR_DECL
920 && DECL_DECLARED_CONSTEXPR_P (t
))
921 pp_cxx_ws_string (cxx_pp
, "constexpr");
922 dump_type_prefix (type
, flags
& ~TFF_UNQUALIFIED_NAME
);
923 pp_maybe_space (cxx_pp
);
925 if (! (flags
& TFF_UNQUALIFIED_NAME
)
926 && TREE_CODE (t
) != PARM_DECL
927 && (!DECL_INITIAL (t
)
928 || TREE_CODE (DECL_INITIAL (t
)) != TEMPLATE_PARM_INDEX
))
929 dump_scope (CP_DECL_CONTEXT (t
), flags
);
930 flags
&= ~TFF_UNQUALIFIED_NAME
;
931 if ((flags
& TFF_DECL_SPECIFIERS
)
932 && DECL_TEMPLATE_PARM_P (t
)
933 && TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (t
)))
934 pp_string (cxx_pp
, "...");
936 dump_decl (DECL_NAME (t
), flags
);
938 pp_string (cxx_pp
, M_("<anonymous>"));
939 if (flags
& TFF_DECL_SPECIFIERS
)
940 dump_type_suffix (type
, flags
);
943 /* Dump a human readable string for the decl T under control of FLAGS. */
946 dump_decl (tree t
, int flags
)
951 /* If doing Objective-C++, give Objective-C a chance to demangle
952 Objective-C method names. */
953 if (c_dialect_objc ())
955 const char *demangled
= objc_maybe_printable_name (t
, flags
);
958 pp_string (cxx_pp
, demangled
);
963 switch (TREE_CODE (t
))
966 /* Don't say 'typedef class A' */
967 if (DECL_ARTIFICIAL (t
) && !DECL_SELF_REFERENCE_P (t
))
969 if ((flags
& TFF_DECL_SPECIFIERS
)
970 && TREE_CODE (TREE_TYPE (t
)) == TEMPLATE_TYPE_PARM
)
972 /* Say `class T' not just `T'. */
973 pp_cxx_ws_string (cxx_pp
, "class");
975 /* Emit the `...' for a parameter pack. */
976 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t
)))
977 pp_cxx_ws_string (cxx_pp
, "...");
980 dump_type (TREE_TYPE (t
), flags
);
983 if (TYPE_DECL_ALIAS_P (t
)
984 && (flags
& TFF_DECL_SPECIFIERS
985 || flags
& TFF_CLASS_KEY_OR_ENUM
))
987 pp_cxx_ws_string (cxx_pp
, "using");
988 dump_decl (DECL_NAME (t
), flags
);
989 pp_cxx_whitespace (cxx_pp
);
990 pp_cxx_ws_string (cxx_pp
, "=");
991 pp_cxx_whitespace (cxx_pp
);
992 dump_type (DECL_ORIGINAL_TYPE (t
), flags
);
995 if ((flags
& TFF_DECL_SPECIFIERS
)
996 && !DECL_SELF_REFERENCE_P (t
))
997 pp_cxx_ws_string (cxx_pp
, "typedef");
998 dump_simple_decl (t
, DECL_ORIGINAL_TYPE (t
)
999 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
),
1004 if (DECL_NAME (t
) && VTABLE_NAME_P (DECL_NAME (t
)))
1006 pp_string (cxx_pp
, M_("vtable for "));
1007 gcc_assert (TYPE_P (DECL_CONTEXT (t
)));
1008 dump_type (DECL_CONTEXT (t
), flags
);
1011 /* Else fall through. */
1014 dump_simple_decl (t
, TREE_TYPE (t
), flags
);
1018 pp_string (cxx_pp
, M_("<return value> "));
1019 dump_simple_decl (t
, TREE_TYPE (t
), flags
);
1022 case NAMESPACE_DECL
:
1023 if (flags
& TFF_DECL_SPECIFIERS
)
1024 pp_cxx_declaration (cxx_pp
, t
);
1027 if (! (flags
& TFF_UNQUALIFIED_NAME
))
1028 dump_scope (CP_DECL_CONTEXT (t
), flags
);
1029 flags
&= ~TFF_UNQUALIFIED_NAME
;
1030 if (DECL_NAME (t
) == NULL_TREE
)
1032 if (!(pp_c_base (cxx_pp
)->flags
& pp_c_flag_gnu_v3
))
1033 pp_cxx_ws_string (cxx_pp
, M_("{anonymous}"));
1035 pp_cxx_ws_string (cxx_pp
, M_("(anonymous namespace)"));
1038 pp_cxx_tree_identifier (cxx_pp
, DECL_NAME (t
));
1043 dump_type (TREE_OPERAND (t
, 0), flags
);
1044 pp_string (cxx_pp
, "::");
1045 dump_decl (TREE_OPERAND (t
, 1), TFF_UNQUALIFIED_NAME
);
1049 dump_decl (TREE_OPERAND (t
, 0), flags
);
1050 pp_cxx_left_bracket (cxx_pp
);
1051 dump_decl (TREE_OPERAND (t
, 1), flags
);
1052 pp_cxx_right_bracket (cxx_pp
);
1055 /* So that we can do dump_decl on an aggr type. */
1059 dump_type (t
, flags
);
1063 /* This is a pseudo destructor call which has not been folded into
1064 a PSEUDO_DTOR_EXPR yet. */
1065 pp_cxx_complement (cxx_pp
);
1066 dump_type (TREE_OPERAND (t
, 0), flags
);
1073 /* These special cases are duplicated here so that other functions
1074 can feed identifiers to error and get them demangled properly. */
1075 case IDENTIFIER_NODE
:
1076 if (IDENTIFIER_TYPENAME_P (t
))
1078 pp_cxx_ws_string (cxx_pp
, "operator");
1079 /* Not exactly IDENTIFIER_TYPE_VALUE. */
1080 dump_type (TREE_TYPE (t
), flags
);
1084 pp_cxx_tree_identifier (cxx_pp
, t
);
1090 t
= OVL_CURRENT (t
);
1091 if (DECL_CLASS_SCOPE_P (t
))
1093 dump_type (DECL_CONTEXT (t
), flags
);
1094 pp_cxx_colon_colon (cxx_pp
);
1096 else if (!DECL_FILE_SCOPE_P (t
))
1098 dump_decl (DECL_CONTEXT (t
), flags
);
1099 pp_cxx_colon_colon (cxx_pp
);
1101 dump_decl (DECL_NAME (t
), flags
);
1105 /* If there's only one function, just treat it like an ordinary
1107 t
= OVL_CURRENT (t
);
1111 if (! DECL_LANG_SPECIFIC (t
))
1112 pp_string (cxx_pp
, M_("<built-in>"));
1113 else if (DECL_GLOBAL_CTOR_P (t
) || DECL_GLOBAL_DTOR_P (t
))
1114 dump_global_iord (t
);
1116 dump_function_decl (t
, flags
);
1120 dump_template_decl (t
, flags
);
1123 case TEMPLATE_ID_EXPR
:
1125 tree name
= TREE_OPERAND (t
, 0);
1126 tree args
= TREE_OPERAND (t
, 1);
1128 if (is_overloaded_fn (name
))
1129 name
= DECL_NAME (get_first_fn (name
));
1130 dump_decl (name
, flags
);
1131 pp_cxx_begin_template_argument_list (cxx_pp
);
1132 if (args
== error_mark_node
)
1133 pp_string (cxx_pp
, M_("<template arguments error>"));
1135 dump_template_argument_list (args
, flags
);
1136 pp_cxx_end_template_argument_list (cxx_pp
);
1141 pp_cxx_tree_identifier (cxx_pp
, DECL_NAME (t
));
1145 if ((TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == ENUMERAL_TYPE
)
1146 || (DECL_INITIAL (t
) &&
1147 TREE_CODE (DECL_INITIAL (t
)) == TEMPLATE_PARM_INDEX
))
1148 dump_simple_decl (t
, TREE_TYPE (t
), flags
);
1149 else if (DECL_NAME (t
))
1150 dump_decl (DECL_NAME (t
), flags
);
1151 else if (DECL_INITIAL (t
))
1152 dump_expr (DECL_INITIAL (t
), flags
| TFF_EXPR_IN_PARENS
);
1154 pp_string (cxx_pp
, M_("<enumerator>"));
1158 pp_cxx_ws_string (cxx_pp
, "using");
1159 dump_type (USING_DECL_SCOPE (t
), flags
);
1160 pp_cxx_colon_colon (cxx_pp
);
1161 dump_decl (DECL_NAME (t
), flags
);
1165 pp_cxx_declaration (cxx_pp
, t
);
1169 dump_decl (BASELINK_FUNCTIONS (t
), flags
);
1172 case NON_DEPENDENT_EXPR
:
1173 dump_expr (t
, flags
);
1176 case TEMPLATE_TYPE_PARM
:
1177 if (flags
& TFF_DECL_SPECIFIERS
)
1178 pp_cxx_declaration (cxx_pp
, t
);
1180 pp_type_id (cxx_pp
, t
);
1183 case UNBOUND_CLASS_TEMPLATE
:
1184 case TYPE_PACK_EXPANSION
:
1186 dump_type (t
, flags
);
1190 pp_unsupported_tree (cxx_pp
, t
);
1191 /* Fall through to error. */
1194 pp_string (cxx_pp
, M_("<declaration error>"));
1199 /* Dump a template declaration T under control of FLAGS. This means the
1200 'template <...> leaders plus the 'class X' or 'void fn(...)' part. */
1203 dump_template_decl (tree t
, int flags
)
1205 tree orig_parms
= DECL_TEMPLATE_PARMS (t
);
1209 if (flags
& TFF_TEMPLATE_HEADER
)
1211 for (parms
= orig_parms
= nreverse (orig_parms
);
1213 parms
= TREE_CHAIN (parms
))
1215 tree inner_parms
= INNERMOST_TEMPLATE_PARMS (parms
);
1216 int len
= TREE_VEC_LENGTH (inner_parms
);
1218 pp_cxx_ws_string (cxx_pp
, "template");
1219 pp_cxx_begin_template_argument_list (cxx_pp
);
1221 /* If we've shown the template prefix, we'd better show the
1222 parameters' and decl's type too. */
1223 flags
|= TFF_DECL_SPECIFIERS
;
1225 for (i
= 0; i
< len
; i
++)
1228 pp_separate_with_comma (cxx_pp
);
1229 dump_template_parameter (TREE_VEC_ELT (inner_parms
, i
), flags
);
1231 pp_cxx_end_template_argument_list (cxx_pp
);
1232 pp_cxx_whitespace (cxx_pp
);
1234 nreverse(orig_parms
);
1236 if (DECL_TEMPLATE_TEMPLATE_PARM_P (t
))
1238 /* Say `template<arg> class TT' not just `template<arg> TT'. */
1239 pp_cxx_ws_string (cxx_pp
, "class");
1241 /* If this is a parameter pack, print the ellipsis. */
1242 if (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (t
)))
1243 pp_cxx_ws_string (cxx_pp
, "...");
1247 if (DECL_CLASS_TEMPLATE_P (t
))
1248 dump_type (TREE_TYPE (t
),
1249 ((flags
& ~TFF_CLASS_KEY_OR_ENUM
) | TFF_TEMPLATE_NAME
1250 | (flags
& TFF_DECL_SPECIFIERS
? TFF_CLASS_KEY_OR_ENUM
: 0)));
1251 else if (DECL_TEMPLATE_RESULT (t
)
1252 && (TREE_CODE (DECL_TEMPLATE_RESULT (t
)) == VAR_DECL
1253 /* Alias template. */
1254 || DECL_TYPE_TEMPLATE_P (t
)))
1255 dump_decl (DECL_TEMPLATE_RESULT (t
), flags
| TFF_TEMPLATE_NAME
);
1258 gcc_assert (TREE_TYPE (t
));
1259 switch (NEXT_CODE (t
))
1263 dump_function_decl (t
, flags
| TFF_TEMPLATE_NAME
);
1266 /* This case can occur with some invalid code. */
1267 dump_type (TREE_TYPE (t
),
1268 (flags
& ~TFF_CLASS_KEY_OR_ENUM
) | TFF_TEMPLATE_NAME
1269 | (flags
& TFF_DECL_SPECIFIERS
1270 ? TFF_CLASS_KEY_OR_ENUM
: 0));
1275 /* find_typenames looks through the type of the function template T
1276 and returns a VEC containing any typedefs, decltypes or TYPENAME_TYPEs
1279 struct find_typenames_t
1281 struct pointer_set_t
*p_set
;
1282 VEC (tree
,gc
) *typenames
;
1286 find_typenames_r (tree
*tp
, int *walk_subtrees ATTRIBUTE_UNUSED
, void *data
)
1288 struct find_typenames_t
*d
= (struct find_typenames_t
*)data
;
1289 tree mv
= NULL_TREE
;
1291 if (TYPE_P (*tp
) && is_typedef_decl (TYPE_NAME (*tp
)))
1292 /* Add the type of the typedef without any additional cv-quals. */
1293 mv
= TREE_TYPE (TYPE_NAME (*tp
));
1294 else if (TREE_CODE (*tp
) == TYPENAME_TYPE
1295 || TREE_CODE (*tp
) == DECLTYPE_TYPE
)
1296 /* Add the typename without any cv-qualifiers. */
1297 mv
= TYPE_MAIN_VARIANT (*tp
);
1299 if (mv
&& (mv
== *tp
|| !pointer_set_insert (d
->p_set
, mv
)))
1300 VEC_safe_push (tree
, gc
, d
->typenames
, mv
);
1302 /* Search into class template arguments, which cp_walk_subtrees
1304 if (CLASS_TYPE_P (*tp
) && CLASSTYPE_TEMPLATE_INFO (*tp
))
1305 cp_walk_tree (&CLASSTYPE_TI_ARGS (*tp
), find_typenames_r
,
1311 static VEC(tree
,gc
) *
1312 find_typenames (tree t
)
1314 struct find_typenames_t ft
;
1315 ft
.p_set
= pointer_set_create ();
1316 ft
.typenames
= NULL
;
1317 cp_walk_tree (&TREE_TYPE (DECL_TEMPLATE_RESULT (t
)),
1318 find_typenames_r
, &ft
, ft
.p_set
);
1319 pointer_set_destroy (ft
.p_set
);
1320 return ft
.typenames
;
1323 /* Pretty print a function decl. There are several ways we want to print a
1324 function declaration. The TFF_ bits in FLAGS tells us how to behave.
1325 As error can only apply the '#' flag once to give 0 and 1 for V, there
1326 is %D which doesn't print the throw specs, and %F which does. */
1329 dump_function_decl (tree t
, int flags
)
1333 tree cname
= NULL_TREE
;
1334 tree template_args
= NULL_TREE
;
1335 tree template_parms
= NULL_TREE
;
1336 int show_return
= flags
& TFF_RETURN_TYPE
|| flags
& TFF_DECL_SPECIFIERS
;
1337 int do_outer_scope
= ! (flags
& TFF_UNQUALIFIED_NAME
);
1339 VEC(tree
,gc
) *typenames
= NULL
;
1341 if (DECL_NAME (t
) && LAMBDA_FUNCTION_P (t
))
1343 /* A lambda's signature is essentially its "type", so defer. */
1344 gcc_assert (LAMBDA_TYPE_P (DECL_CONTEXT (t
)));
1345 dump_type (DECL_CONTEXT (t
), flags
);
1349 flags
&= ~TFF_UNQUALIFIED_NAME
;
1350 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1351 t
= DECL_TEMPLATE_RESULT (t
);
1353 /* Save the exceptions, in case t is a specialization and we are
1354 emitting an error about incompatible specifications. */
1355 exceptions
= TYPE_RAISES_EXCEPTIONS (TREE_TYPE (t
));
1357 /* Pretty print template instantiations only. */
1358 if (DECL_USE_TEMPLATE (t
) && DECL_TEMPLATE_INFO (t
)
1359 && flag_pretty_templates
)
1363 template_args
= DECL_TI_ARGS (t
);
1364 tmpl
= most_general_template (t
);
1365 if (tmpl
&& TREE_CODE (tmpl
) == TEMPLATE_DECL
)
1367 template_parms
= DECL_TEMPLATE_PARMS (tmpl
);
1369 typenames
= find_typenames (t
);
1373 fntype
= TREE_TYPE (t
);
1374 parmtypes
= FUNCTION_FIRST_USER_PARMTYPE (t
);
1376 if (DECL_CLASS_SCOPE_P (t
))
1377 cname
= DECL_CONTEXT (t
);
1378 /* This is for partially instantiated template methods. */
1379 else if (TREE_CODE (fntype
) == METHOD_TYPE
)
1380 cname
= TREE_TYPE (TREE_VALUE (parmtypes
));
1382 if (flags
& TFF_DECL_SPECIFIERS
)
1384 if (DECL_STATIC_FUNCTION_P (t
))
1385 pp_cxx_ws_string (cxx_pp
, "static");
1386 else if (DECL_VIRTUAL_P (t
))
1387 pp_cxx_ws_string (cxx_pp
, "virtual");
1389 if (DECL_DECLARED_CONSTEXPR_P (STRIP_TEMPLATE (t
)))
1390 pp_cxx_ws_string (cxx_pp
, "constexpr");
1393 /* Print the return type? */
1395 show_return
= !DECL_CONV_FN_P (t
) && !DECL_CONSTRUCTOR_P (t
)
1396 && !DECL_DESTRUCTOR_P (t
);
1398 dump_type_prefix (TREE_TYPE (fntype
), flags
);
1400 /* Print the function name. */
1401 if (!do_outer_scope
)
1405 dump_type (cname
, flags
);
1406 pp_cxx_colon_colon (cxx_pp
);
1409 dump_scope (CP_DECL_CONTEXT (t
), flags
);
1411 dump_function_name (t
, flags
);
1413 if (!(flags
& TFF_NO_FUNCTION_ARGUMENTS
))
1415 dump_parameters (parmtypes
, flags
);
1417 if (TREE_CODE (fntype
) == METHOD_TYPE
)
1419 pp_base (cxx_pp
)->padding
= pp_before
;
1420 pp_cxx_cv_qualifier_seq (cxx_pp
, class_of_this_parm (fntype
));
1423 if (flags
& TFF_EXCEPTION_SPECIFICATION
)
1425 pp_base (cxx_pp
)->padding
= pp_before
;
1426 dump_exception_spec (exceptions
, flags
);
1430 dump_type_suffix (TREE_TYPE (fntype
), flags
);
1432 /* If T is a template instantiation, dump the parameter binding. */
1433 if (template_parms
!= NULL_TREE
&& template_args
!= NULL_TREE
)
1435 pp_cxx_whitespace (cxx_pp
);
1436 pp_cxx_left_bracket (cxx_pp
);
1437 pp_cxx_ws_string (cxx_pp
, M_("with"));
1438 pp_cxx_whitespace (cxx_pp
);
1439 dump_template_bindings (template_parms
, template_args
, typenames
);
1440 pp_cxx_right_bracket (cxx_pp
);
1443 else if (template_args
)
1445 bool need_comma
= false;
1447 pp_cxx_begin_template_argument_list (cxx_pp
);
1448 template_args
= INNERMOST_TEMPLATE_ARGS (template_args
);
1449 for (i
= 0; i
< TREE_VEC_LENGTH (template_args
); ++i
)
1451 tree arg
= TREE_VEC_ELT (template_args
, i
);
1453 pp_separate_with_comma (cxx_pp
);
1454 if (ARGUMENT_PACK_P (arg
))
1455 pp_cxx_left_brace (cxx_pp
);
1456 dump_template_argument (arg
, TFF_PLAIN_IDENTIFIER
);
1457 if (ARGUMENT_PACK_P (arg
))
1458 pp_cxx_right_brace (cxx_pp
);
1461 pp_cxx_end_template_argument_list (cxx_pp
);
1465 /* Print a parameter list. If this is for a member function, the
1466 member object ptr (and any other hidden args) should have
1467 already been removed. */
1470 dump_parameters (tree parmtypes
, int flags
)
1473 flags
&= ~TFF_SCOPE
;
1474 pp_cxx_left_paren (cxx_pp
);
1476 for (first
= 1; parmtypes
!= void_list_node
;
1477 parmtypes
= TREE_CHAIN (parmtypes
))
1480 pp_separate_with_comma (cxx_pp
);
1484 pp_cxx_ws_string (cxx_pp
, "...");
1488 dump_type (TREE_VALUE (parmtypes
), flags
);
1490 if ((flags
& TFF_FUNCTION_DEFAULT_ARGUMENTS
) && TREE_PURPOSE (parmtypes
))
1492 pp_cxx_whitespace (cxx_pp
);
1494 pp_cxx_whitespace (cxx_pp
);
1495 dump_expr (TREE_PURPOSE (parmtypes
), flags
| TFF_EXPR_IN_PARENS
);
1499 pp_cxx_right_paren (cxx_pp
);
1502 /* Print an exception specification. T is the exception specification. */
1505 dump_exception_spec (tree t
, int flags
)
1507 if (t
&& TREE_PURPOSE (t
))
1509 pp_cxx_ws_string (cxx_pp
, "noexcept");
1510 pp_cxx_whitespace (cxx_pp
);
1511 pp_cxx_left_paren (cxx_pp
);
1512 if (DEFERRED_NOEXCEPT_SPEC_P (t
))
1513 pp_cxx_ws_string (cxx_pp
, "<uninstantiated>");
1515 dump_expr (TREE_PURPOSE (t
), flags
);
1516 pp_cxx_right_paren (cxx_pp
);
1520 pp_cxx_ws_string (cxx_pp
, "throw");
1521 pp_cxx_whitespace (cxx_pp
);
1522 pp_cxx_left_paren (cxx_pp
);
1523 if (TREE_VALUE (t
) != NULL_TREE
)
1526 dump_type (TREE_VALUE (t
), flags
);
1530 pp_separate_with_comma (cxx_pp
);
1532 pp_cxx_right_paren (cxx_pp
);
1536 /* Handle the function name for a FUNCTION_DECL node, grokking operators
1537 and destructors properly. */
1540 dump_function_name (tree t
, int flags
)
1542 tree name
= DECL_NAME (t
);
1544 /* We can get here with a decl that was synthesized by language-
1545 independent machinery (e.g. coverage.c) in which case it won't
1546 have a lang_specific structure attached and DECL_CONSTRUCTOR_P
1547 will crash. In this case it is safe just to print out the
1549 if (!DECL_LANG_SPECIFIC (t
))
1551 pp_cxx_tree_identifier (cxx_pp
, name
);
1555 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1556 t
= DECL_TEMPLATE_RESULT (t
);
1558 /* Don't let the user see __comp_ctor et al. */
1559 if (DECL_CONSTRUCTOR_P (t
)
1560 || DECL_DESTRUCTOR_P (t
))
1562 if (LAMBDA_TYPE_P (DECL_CONTEXT (t
)))
1563 name
= get_identifier ("<lambda>");
1564 else if (TYPE_ANONYMOUS_P (DECL_CONTEXT (t
)))
1565 name
= get_identifier ("<constructor>");
1567 name
= constructor_name (DECL_CONTEXT (t
));
1570 if (DECL_DESTRUCTOR_P (t
))
1572 pp_cxx_complement (cxx_pp
);
1573 dump_decl (name
, TFF_PLAIN_IDENTIFIER
);
1575 else if (DECL_CONV_FN_P (t
))
1577 /* This cannot use the hack that the operator's return
1578 type is stashed off of its name because it may be
1579 used for error reporting. In the case of conflicting
1580 declarations, both will have the same name, yet
1581 the types will be different, hence the TREE_TYPE field
1582 of the first name will be clobbered by the second. */
1583 pp_cxx_ws_string (cxx_pp
, "operator");
1584 dump_type (TREE_TYPE (TREE_TYPE (t
)), flags
);
1586 else if (name
&& IDENTIFIER_OPNAME_P (name
))
1587 pp_cxx_tree_identifier (cxx_pp
, name
);
1588 else if (name
&& UDLIT_OPER_P (name
))
1589 pp_cxx_tree_identifier (cxx_pp
, name
);
1591 dump_decl (name
, flags
);
1593 if (DECL_TEMPLATE_INFO (t
)
1594 && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t
)
1595 && (TREE_CODE (DECL_TI_TEMPLATE (t
)) != TEMPLATE_DECL
1596 || PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t
))))
1597 dump_template_parms (DECL_TEMPLATE_INFO (t
), !DECL_USE_TEMPLATE (t
), flags
);
1600 /* Dump the template parameters from the template info INFO under control of
1601 FLAGS. PRIMARY indicates whether this is a primary template decl, or
1602 specialization (partial or complete). For partial specializations we show
1603 the specialized parameter values. For a primary template we show no
1607 dump_template_parms (tree info
, int primary
, int flags
)
1609 tree args
= info
? TI_ARGS (info
) : NULL_TREE
;
1611 if (primary
&& flags
& TFF_TEMPLATE_NAME
)
1613 flags
&= ~(TFF_CLASS_KEY_OR_ENUM
| TFF_TEMPLATE_NAME
);
1614 pp_cxx_begin_template_argument_list (cxx_pp
);
1616 /* Be careful only to print things when we have them, so as not
1617 to crash producing error messages. */
1618 if (args
&& !primary
)
1621 len
= get_non_default_template_args_count (args
, flags
);
1623 args
= INNERMOST_TEMPLATE_ARGS (args
);
1624 for (ix
= 0; ix
!= len
; ix
++)
1626 tree arg
= TREE_VEC_ELT (args
, ix
);
1628 /* Only print a comma if we know there is an argument coming. In
1629 the case of an empty template argument pack, no actual
1630 argument will be printed. */
1632 && (!ARGUMENT_PACK_P (arg
)
1633 || TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg
)) > 0))
1634 pp_separate_with_comma (cxx_pp
);
1637 pp_string (cxx_pp
, M_("<template parameter error>"));
1639 dump_template_argument (arg
, flags
);
1644 tree tpl
= TI_TEMPLATE (info
);
1645 tree parms
= DECL_TEMPLATE_PARMS (tpl
);
1648 parms
= TREE_CODE (parms
) == TREE_LIST
? TREE_VALUE (parms
) : NULL_TREE
;
1649 len
= parms
? TREE_VEC_LENGTH (parms
) : 0;
1651 for (ix
= 0; ix
!= len
; ix
++)
1655 if (TREE_VEC_ELT (parms
, ix
) == error_mark_node
)
1657 pp_string (cxx_pp
, M_("<template parameter error>"));
1661 parm
= TREE_VALUE (TREE_VEC_ELT (parms
, ix
));
1664 pp_separate_with_comma (cxx_pp
);
1666 dump_decl (parm
, flags
& ~TFF_DECL_SPECIFIERS
);
1669 pp_cxx_end_template_argument_list (cxx_pp
);
1672 /* Print out the arguments of CALL_EXPR T as a parenthesized list using
1673 flags FLAGS. Skip over the first argument if SKIPFIRST is true. */
1676 dump_call_expr_args (tree t
, int flags
, bool skipfirst
)
1679 call_expr_arg_iterator iter
;
1681 pp_cxx_left_paren (cxx_pp
);
1682 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, t
)
1688 dump_expr (arg
, flags
| TFF_EXPR_IN_PARENS
);
1689 if (more_call_expr_args_p (&iter
))
1690 pp_separate_with_comma (cxx_pp
);
1693 pp_cxx_right_paren (cxx_pp
);
1696 /* Print out the arguments of AGGR_INIT_EXPR T as a parenthesized list
1697 using flags FLAGS. Skip over the first argument if SKIPFIRST is
1701 dump_aggr_init_expr_args (tree t
, int flags
, bool skipfirst
)
1704 aggr_init_expr_arg_iterator iter
;
1706 pp_cxx_left_paren (cxx_pp
);
1707 FOR_EACH_AGGR_INIT_EXPR_ARG (arg
, iter
, t
)
1713 dump_expr (arg
, flags
| TFF_EXPR_IN_PARENS
);
1714 if (more_aggr_init_expr_args_p (&iter
))
1715 pp_separate_with_comma (cxx_pp
);
1718 pp_cxx_right_paren (cxx_pp
);
1721 /* Print out a list of initializers (subr of dump_expr). */
1724 dump_expr_list (tree l
, int flags
)
1728 dump_expr (TREE_VALUE (l
), flags
| TFF_EXPR_IN_PARENS
);
1731 pp_separate_with_comma (cxx_pp
);
1735 /* Print out a vector of initializers (subr of dump_expr). */
1738 dump_expr_init_vec (VEC(constructor_elt
,gc
) *v
, int flags
)
1740 unsigned HOST_WIDE_INT idx
;
1743 FOR_EACH_CONSTRUCTOR_VALUE (v
, idx
, value
)
1745 dump_expr (value
, flags
| TFF_EXPR_IN_PARENS
);
1746 if (idx
!= VEC_length (constructor_elt
, v
) - 1)
1747 pp_separate_with_comma (cxx_pp
);
1752 /* We've gotten an indirect REFERENCE (an OBJ_TYPE_REF) to a virtual
1753 function. Resolve it to a close relative -- in the sense of static
1754 type -- variant being overridden. That is close to what was written in
1755 the source code. Subroutine of dump_expr. */
1758 resolve_virtual_fun_from_obj_type_ref (tree ref
)
1760 tree obj_type
= TREE_TYPE (OBJ_TYPE_REF_OBJECT (ref
));
1761 HOST_WIDE_INT index
= tree_low_cst (OBJ_TYPE_REF_TOKEN (ref
), 1);
1762 tree fun
= BINFO_VIRTUALS (TYPE_BINFO (TREE_TYPE (obj_type
)));
1765 fun
= TREE_CHAIN (fun
);
1766 index
-= (TARGET_VTABLE_USES_DESCRIPTORS
1767 ? TARGET_VTABLE_USES_DESCRIPTORS
: 1);
1773 /* Print out an expression E under control of FLAGS. */
1776 dump_expr (tree t
, int flags
)
1781 if (STATEMENT_CLASS_P (t
))
1783 pp_cxx_ws_string (cxx_pp
, M_("<statement>"));
1787 switch (TREE_CODE (t
))
1795 case NAMESPACE_DECL
:
1799 case IDENTIFIER_NODE
:
1800 dump_decl (t
, ((flags
& ~(TFF_DECL_SPECIFIERS
|TFF_RETURN_TYPE
1801 |TFF_TEMPLATE_HEADER
))
1802 | TFF_NO_FUNCTION_ARGUMENTS
));
1806 if (SSA_NAME_VAR (t
)
1807 && !DECL_ARTIFICIAL (SSA_NAME_VAR (t
)))
1808 dump_expr (SSA_NAME_VAR (t
), flags
);
1810 pp_cxx_ws_string (cxx_pp
, M_("<unknown>"));
1817 pp_constant (cxx_pp
, t
);
1820 case USERDEF_LITERAL
:
1821 pp_cxx_userdef_literal (cxx_pp
, t
);
1825 /* While waiting for caret diagnostics, avoid printing
1826 __cxa_allocate_exception, __cxa_throw, and the like. */
1827 pp_cxx_ws_string (cxx_pp
, M_("<throw-expression>"));
1831 pp_ampersand (cxx_pp
);
1832 dump_type (PTRMEM_CST_CLASS (t
), flags
);
1833 pp_cxx_colon_colon (cxx_pp
);
1834 pp_cxx_tree_identifier (cxx_pp
, DECL_NAME (PTRMEM_CST_MEMBER (t
)));
1838 pp_cxx_left_paren (cxx_pp
);
1839 dump_expr (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
1840 pp_separate_with_comma (cxx_pp
);
1841 dump_expr (TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
1842 pp_cxx_right_paren (cxx_pp
);
1846 pp_cxx_left_paren (cxx_pp
);
1847 dump_expr (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
1848 pp_string (cxx_pp
, " ? ");
1849 dump_expr (TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
1850 pp_string (cxx_pp
, " : ");
1851 dump_expr (TREE_OPERAND (t
, 2), flags
| TFF_EXPR_IN_PARENS
);
1852 pp_cxx_right_paren (cxx_pp
);
1856 if (TREE_HAS_CONSTRUCTOR (t
))
1858 pp_cxx_ws_string (cxx_pp
, "new");
1859 pp_cxx_whitespace (cxx_pp
);
1860 dump_type (TREE_TYPE (TREE_TYPE (t
)), flags
);
1863 dump_expr (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
1866 case AGGR_INIT_EXPR
:
1868 tree fn
= NULL_TREE
;
1870 if (TREE_CODE (AGGR_INIT_EXPR_FN (t
)) == ADDR_EXPR
)
1871 fn
= TREE_OPERAND (AGGR_INIT_EXPR_FN (t
), 0);
1873 if (fn
&& TREE_CODE (fn
) == FUNCTION_DECL
)
1875 if (DECL_CONSTRUCTOR_P (fn
))
1876 dump_type (DECL_CONTEXT (fn
), flags
);
1881 dump_expr (AGGR_INIT_EXPR_FN (t
), 0);
1883 dump_aggr_init_expr_args (t
, flags
, true);
1888 tree fn
= CALL_EXPR_FN (t
);
1889 bool skipfirst
= false;
1891 if (TREE_CODE (fn
) == ADDR_EXPR
)
1892 fn
= TREE_OPERAND (fn
, 0);
1894 /* Nobody is interested in seeing the guts of vcalls. */
1895 if (TREE_CODE (fn
) == OBJ_TYPE_REF
)
1896 fn
= resolve_virtual_fun_from_obj_type_ref (fn
);
1898 if (TREE_TYPE (fn
) != NULL_TREE
1899 && NEXT_CODE (fn
) == METHOD_TYPE
1900 && call_expr_nargs (t
))
1902 tree ob
= CALL_EXPR_ARG (t
, 0);
1903 if (TREE_CODE (ob
) == ADDR_EXPR
)
1905 dump_expr (TREE_OPERAND (ob
, 0), flags
| TFF_EXPR_IN_PARENS
);
1906 pp_cxx_dot (cxx_pp
);
1908 else if (TREE_CODE (ob
) != PARM_DECL
1909 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob
)), "this"))
1911 dump_expr (ob
, flags
| TFF_EXPR_IN_PARENS
);
1912 pp_cxx_arrow (cxx_pp
);
1916 dump_expr (fn
, flags
| TFF_EXPR_IN_PARENS
);
1917 dump_call_expr_args (t
, flags
, skipfirst
);
1922 /* Note that this only works for G++ target exprs. If somebody
1923 builds a general TARGET_EXPR, there's no way to represent that
1924 it initializes anything other that the parameter slot for the
1925 default argument. Note we may have cleared out the first
1926 operand in expand_expr, so don't go killing ourselves. */
1927 if (TREE_OPERAND (t
, 1))
1928 dump_expr (TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
1931 case POINTER_PLUS_EXPR
:
1932 dump_binary_op ("+", t
, flags
);
1937 dump_binary_op (assignment_operator_name_info
[(int)NOP_EXPR
].name
,
1944 case TRUNC_DIV_EXPR
:
1945 case TRUNC_MOD_EXPR
:
1953 case TRUTH_ANDIF_EXPR
:
1954 case TRUTH_ORIF_EXPR
:
1961 case EXACT_DIV_EXPR
:
1962 dump_binary_op (operator_name_info
[(int) TREE_CODE (t
)].name
, t
, flags
);
1966 case FLOOR_DIV_EXPR
:
1967 case ROUND_DIV_EXPR
:
1969 dump_binary_op ("/", t
, flags
);
1973 case FLOOR_MOD_EXPR
:
1974 case ROUND_MOD_EXPR
:
1975 dump_binary_op ("%", t
, flags
);
1980 tree ob
= TREE_OPERAND (t
, 0);
1981 if (TREE_CODE (ob
) == INDIRECT_REF
)
1983 ob
= TREE_OPERAND (ob
, 0);
1984 if (TREE_CODE (ob
) != PARM_DECL
1986 && strcmp (IDENTIFIER_POINTER (DECL_NAME (ob
)), "this")))
1988 dump_expr (ob
, flags
| TFF_EXPR_IN_PARENS
);
1989 if (TREE_CODE (TREE_TYPE (ob
)) == REFERENCE_TYPE
)
1990 pp_cxx_dot (cxx_pp
);
1992 pp_cxx_arrow (cxx_pp
);
1997 dump_expr (ob
, flags
| TFF_EXPR_IN_PARENS
);
1998 pp_cxx_dot (cxx_pp
);
2000 dump_expr (TREE_OPERAND (t
, 1), flags
& ~TFF_EXPR_IN_PARENS
);
2005 dump_expr (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2006 pp_cxx_left_bracket (cxx_pp
);
2007 dump_expr (TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2008 pp_cxx_right_bracket (cxx_pp
);
2011 case UNARY_PLUS_EXPR
:
2012 dump_unary_op ("+", t
, flags
);
2016 if (TREE_CODE (TREE_OPERAND (t
, 0)) == FUNCTION_DECL
2017 || TREE_CODE (TREE_OPERAND (t
, 0)) == STRING_CST
2018 /* An ADDR_EXPR can have reference type. In that case, we
2019 shouldn't print the `&' doing so indicates to the user
2020 that the expression has pointer type. */
2022 && TREE_CODE (TREE_TYPE (t
)) == REFERENCE_TYPE
))
2023 dump_expr (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2024 else if (TREE_CODE (TREE_OPERAND (t
, 0)) == LABEL_DECL
)
2025 dump_unary_op ("&&", t
, flags
);
2027 dump_unary_op ("&", t
, flags
);
2031 if (TREE_HAS_CONSTRUCTOR (t
))
2033 t
= TREE_OPERAND (t
, 0);
2034 gcc_assert (TREE_CODE (t
) == CALL_EXPR
);
2035 dump_expr (CALL_EXPR_FN (t
), flags
| TFF_EXPR_IN_PARENS
);
2036 dump_call_expr_args (t
, flags
, true);
2040 if (TREE_OPERAND (t
,0) != NULL_TREE
2041 && TREE_TYPE (TREE_OPERAND (t
, 0))
2042 && NEXT_CODE (TREE_OPERAND (t
, 0)) == REFERENCE_TYPE
)
2043 dump_expr (TREE_OPERAND (t
, 0), flags
);
2045 dump_unary_op ("*", t
, flags
);
2050 if (TREE_CODE (TREE_OPERAND (t
, 0)) == ADDR_EXPR
2051 && integer_zerop (TREE_OPERAND (t
, 1)))
2052 dump_expr (TREE_OPERAND (TREE_OPERAND (t
, 0), 0), flags
);
2055 pp_cxx_star (cxx_pp
);
2056 if (!integer_zerop (TREE_OPERAND (t
, 1)))
2058 pp_cxx_left_paren (cxx_pp
);
2059 if (!integer_onep (TYPE_SIZE_UNIT
2060 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (t
, 0))))))
2062 pp_cxx_left_paren (cxx_pp
);
2063 dump_type (ptr_type_node
, flags
);
2064 pp_cxx_right_paren (cxx_pp
);
2067 dump_expr (TREE_OPERAND (t
, 0), flags
);
2068 if (!integer_zerop (TREE_OPERAND (t
, 1)))
2070 pp_cxx_ws_string (cxx_pp
, "+");
2071 dump_expr (fold_convert (ssizetype
, TREE_OPERAND (t
, 1)), flags
);
2072 pp_cxx_right_paren (cxx_pp
);
2079 case TRUTH_NOT_EXPR
:
2080 case PREDECREMENT_EXPR
:
2081 case PREINCREMENT_EXPR
:
2082 dump_unary_op (operator_name_info
[(int)TREE_CODE (t
)].name
, t
, flags
);
2085 case POSTDECREMENT_EXPR
:
2086 case POSTINCREMENT_EXPR
:
2087 pp_cxx_left_paren (cxx_pp
);
2088 dump_expr (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2089 pp_cxx_ws_string (cxx_pp
, operator_name_info
[(int)TREE_CODE (t
)].name
);
2090 pp_cxx_right_paren (cxx_pp
);
2093 case NON_LVALUE_EXPR
:
2094 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
2095 should be another level of INDIRECT_REF so that I don't have to do
2097 if (TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == POINTER_TYPE
)
2099 tree next
= TREE_TYPE (TREE_TYPE (t
));
2101 while (TREE_CODE (next
) == POINTER_TYPE
)
2102 next
= TREE_TYPE (next
);
2104 if (TREE_CODE (next
) == FUNCTION_TYPE
)
2106 if (flags
& TFF_EXPR_IN_PARENS
)
2107 pp_cxx_left_paren (cxx_pp
);
2108 pp_cxx_star (cxx_pp
);
2109 dump_expr (TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2110 if (flags
& TFF_EXPR_IN_PARENS
)
2111 pp_cxx_right_paren (cxx_pp
);
2114 /* Else fall through. */
2116 dump_expr (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2120 case IMPLICIT_CONV_EXPR
:
2121 case VIEW_CONVERT_EXPR
:
2123 tree op
= TREE_OPERAND (t
, 0);
2124 tree ttype
= TREE_TYPE (t
);
2125 tree optype
= TREE_TYPE (op
);
2127 if (TREE_CODE (ttype
) != TREE_CODE (optype
)
2128 && POINTER_TYPE_P (ttype
)
2129 && POINTER_TYPE_P (optype
)
2130 && same_type_p (TREE_TYPE (optype
),
2133 if (TREE_CODE (ttype
) == REFERENCE_TYPE
)
2134 dump_unary_op ("*", t
, flags
);
2136 dump_unary_op ("&", t
, flags
);
2138 else if (!same_type_p (TREE_TYPE (op
), TREE_TYPE (t
)))
2140 /* It is a cast, but we cannot tell whether it is a
2141 reinterpret or static cast. Use the C style notation. */
2142 if (flags
& TFF_EXPR_IN_PARENS
)
2143 pp_cxx_left_paren (cxx_pp
);
2144 pp_cxx_left_paren (cxx_pp
);
2145 dump_type (TREE_TYPE (t
), flags
);
2146 pp_cxx_right_paren (cxx_pp
);
2147 dump_expr (op
, flags
| TFF_EXPR_IN_PARENS
);
2148 if (flags
& TFF_EXPR_IN_PARENS
)
2149 pp_cxx_right_paren (cxx_pp
);
2152 dump_expr (op
, flags
);
2157 if (TREE_TYPE (t
) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t
)))
2159 tree idx
= build_ptrmemfunc_access_expr (t
, pfn_identifier
);
2161 if (integer_zerop (idx
))
2163 /* A NULL pointer-to-member constant. */
2164 pp_cxx_left_paren (cxx_pp
);
2165 pp_cxx_left_paren (cxx_pp
);
2166 dump_type (TREE_TYPE (t
), flags
);
2167 pp_cxx_right_paren (cxx_pp
);
2168 pp_character (cxx_pp
, '0');
2169 pp_cxx_right_paren (cxx_pp
);
2172 else if (host_integerp (idx
, 0))
2175 unsigned HOST_WIDE_INT n
;
2177 t
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t
)));
2178 t
= TYPE_METHOD_BASETYPE (t
);
2179 virtuals
= BINFO_VIRTUALS (TYPE_BINFO (TYPE_MAIN_VARIANT (t
)));
2181 n
= tree_low_cst (idx
, 0);
2183 /* Map vtable index back one, to allow for the null pointer to
2187 while (n
> 0 && virtuals
)
2190 virtuals
= TREE_CHAIN (virtuals
);
2194 dump_expr (BV_FN (virtuals
),
2195 flags
| TFF_EXPR_IN_PARENS
);
2200 if (TREE_TYPE (t
) && LAMBDA_TYPE_P (TREE_TYPE (t
)))
2201 pp_string (cxx_pp
, "<lambda closure object>");
2202 if (TREE_TYPE (t
) && EMPTY_CONSTRUCTOR_P (t
))
2204 dump_type (TREE_TYPE (t
), 0);
2205 pp_cxx_left_paren (cxx_pp
);
2206 pp_cxx_right_paren (cxx_pp
);
2210 if (!BRACE_ENCLOSED_INITIALIZER_P (t
))
2211 dump_type (TREE_TYPE (t
), 0);
2212 pp_cxx_left_brace (cxx_pp
);
2213 dump_expr_init_vec (CONSTRUCTOR_ELTS (t
), flags
);
2214 pp_cxx_right_brace (cxx_pp
);
2221 tree ob
= TREE_OPERAND (t
, 0);
2222 if (is_dummy_object (ob
))
2224 t
= TREE_OPERAND (t
, 1);
2225 if (TREE_CODE (t
) == FUNCTION_DECL
)
2227 dump_expr (t
, flags
| TFF_EXPR_IN_PARENS
);
2228 else if (BASELINK_P (t
))
2229 dump_expr (OVL_CURRENT (BASELINK_FUNCTIONS (t
)),
2230 flags
| TFF_EXPR_IN_PARENS
);
2232 dump_decl (t
, flags
);
2236 if (TREE_CODE (ob
) == INDIRECT_REF
)
2238 dump_expr (TREE_OPERAND (ob
, 0), flags
| TFF_EXPR_IN_PARENS
);
2239 pp_cxx_arrow (cxx_pp
);
2240 pp_cxx_star (cxx_pp
);
2244 dump_expr (ob
, flags
| TFF_EXPR_IN_PARENS
);
2245 pp_cxx_dot (cxx_pp
);
2246 pp_cxx_star (cxx_pp
);
2248 dump_expr (TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2253 case TEMPLATE_PARM_INDEX
:
2254 dump_decl (TEMPLATE_PARM_DECL (t
), flags
& ~TFF_DECL_SPECIFIERS
);
2258 if (TREE_OPERAND (t
, 0) == NULL_TREE
2259 || TREE_CHAIN (TREE_OPERAND (t
, 0)))
2261 dump_type (TREE_TYPE (t
), flags
);
2262 pp_cxx_left_paren (cxx_pp
);
2263 dump_expr_list (TREE_OPERAND (t
, 0), flags
);
2264 pp_cxx_right_paren (cxx_pp
);
2268 pp_cxx_left_paren (cxx_pp
);
2269 dump_type (TREE_TYPE (t
), flags
);
2270 pp_cxx_right_paren (cxx_pp
);
2271 pp_cxx_left_paren (cxx_pp
);
2272 dump_expr_list (TREE_OPERAND (t
, 0), flags
);
2273 pp_cxx_right_paren (cxx_pp
);
2277 case STATIC_CAST_EXPR
:
2278 pp_cxx_ws_string (cxx_pp
, "static_cast");
2280 case REINTERPRET_CAST_EXPR
:
2281 pp_cxx_ws_string (cxx_pp
, "reinterpret_cast");
2283 case CONST_CAST_EXPR
:
2284 pp_cxx_ws_string (cxx_pp
, "const_cast");
2286 case DYNAMIC_CAST_EXPR
:
2287 pp_cxx_ws_string (cxx_pp
, "dynamic_cast");
2289 pp_cxx_begin_template_argument_list (cxx_pp
);
2290 dump_type (TREE_TYPE (t
), flags
);
2291 pp_cxx_end_template_argument_list (cxx_pp
);
2292 pp_cxx_left_paren (cxx_pp
);
2293 dump_expr (TREE_OPERAND (t
, 0), flags
);
2294 pp_cxx_right_paren (cxx_pp
);
2298 dump_expr (TREE_OPERAND (t
, 0), flags
);
2299 pp_cxx_arrow (cxx_pp
);
2304 if (TREE_CODE (t
) == SIZEOF_EXPR
)
2305 pp_cxx_ws_string (cxx_pp
, "sizeof");
2308 gcc_assert (TREE_CODE (t
) == ALIGNOF_EXPR
);
2309 pp_cxx_ws_string (cxx_pp
, "__alignof__");
2311 pp_cxx_whitespace (cxx_pp
);
2312 pp_cxx_left_paren (cxx_pp
);
2313 if (TYPE_P (TREE_OPERAND (t
, 0)))
2314 dump_type (TREE_OPERAND (t
, 0), flags
);
2316 dump_expr (TREE_OPERAND (t
, 0), flags
);
2317 pp_cxx_right_paren (cxx_pp
);
2320 case AT_ENCODE_EXPR
:
2321 pp_cxx_ws_string (cxx_pp
, "@encode");
2322 pp_cxx_whitespace (cxx_pp
);
2323 pp_cxx_left_paren (cxx_pp
);
2324 dump_type (TREE_OPERAND (t
, 0), flags
);
2325 pp_cxx_right_paren (cxx_pp
);
2329 pp_cxx_ws_string (cxx_pp
, "noexcept");
2330 pp_cxx_whitespace (cxx_pp
);
2331 pp_cxx_left_paren (cxx_pp
);
2332 dump_expr (TREE_OPERAND (t
, 0), flags
);
2333 pp_cxx_right_paren (cxx_pp
);
2338 pp_cxx_ws_string (cxx_pp
, operator_name_info
[TREE_CODE (t
)].name
);
2339 pp_cxx_whitespace (cxx_pp
);
2340 dump_expr (TREE_OPERAND (t
, 0), flags
);
2344 pp_string (cxx_pp
, M_("<unparsed>"));
2347 case TRY_CATCH_EXPR
:
2348 case WITH_CLEANUP_EXPR
:
2349 case CLEANUP_POINT_EXPR
:
2350 dump_expr (TREE_OPERAND (t
, 0), flags
);
2353 case PSEUDO_DTOR_EXPR
:
2354 dump_expr (TREE_OPERAND (t
, 2), flags
);
2355 pp_cxx_dot (cxx_pp
);
2356 dump_type (TREE_OPERAND (t
, 0), flags
);
2357 pp_cxx_colon_colon (cxx_pp
);
2358 pp_cxx_complement (cxx_pp
);
2359 dump_type (TREE_OPERAND (t
, 1), flags
);
2362 case TEMPLATE_ID_EXPR
:
2363 dump_decl (t
, flags
);
2369 case STATEMENT_LIST
:
2370 /* We don't yet have a way of dumping statements in a
2371 human-readable format. */
2372 pp_string (cxx_pp
, "({...})");
2376 pp_string (cxx_pp
, "while (1) { ");
2377 dump_expr (TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2378 pp_cxx_right_brace (cxx_pp
);
2382 pp_string (cxx_pp
, "if (");
2383 dump_expr (TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2384 pp_string (cxx_pp
, ") break; ");
2388 dump_expr (BASELINK_FUNCTIONS (t
), flags
& ~TFF_EXPR_IN_PARENS
);
2391 case EMPTY_CLASS_EXPR
:
2392 dump_type (TREE_TYPE (t
), flags
);
2393 pp_cxx_left_paren (cxx_pp
);
2394 pp_cxx_right_paren (cxx_pp
);
2397 case NON_DEPENDENT_EXPR
:
2398 dump_expr (TREE_OPERAND (t
, 0), flags
);
2401 case ARGUMENT_PACK_SELECT
:
2402 dump_template_argument (ARGUMENT_PACK_SELECT_FROM_PACK (t
), flags
);
2414 pp_type_specifier_seq (cxx_pp
, t
);
2418 /* We get here when we want to print a dependent type as an
2419 id-expression, without any disambiguator decoration. */
2420 pp_id_expression (cxx_pp
, t
);
2423 case TEMPLATE_TYPE_PARM
:
2424 case TEMPLATE_TEMPLATE_PARM
:
2425 case BOUND_TEMPLATE_TEMPLATE_PARM
:
2426 dump_type (t
, flags
);
2430 pp_cxx_trait_expression (cxx_pp
, t
);
2434 pp_cxx_va_arg_expression (cxx_pp
, t
);
2438 pp_cxx_offsetof_expression (cxx_pp
, t
);
2442 dump_decl (t
, flags
);
2445 case EXPR_PACK_EXPANSION
:
2452 case VEC_DELETE_EXPR
:
2458 case UNORDERED_EXPR
:
2468 case FIX_TRUNC_EXPR
:
2470 pp_expression (cxx_pp
, t
);
2473 case TRUTH_AND_EXPR
:
2475 case TRUTH_XOR_EXPR
:
2476 if (flags
& TFF_EXPR_IN_PARENS
)
2477 pp_cxx_left_paren (cxx_pp
);
2478 pp_expression (cxx_pp
, t
);
2479 if (flags
& TFF_EXPR_IN_PARENS
)
2480 pp_cxx_right_paren (cxx_pp
);
2484 dump_expr (resolve_virtual_fun_from_obj_type_ref (t
), flags
);
2487 /* This list is incomplete, but should suffice for now.
2488 It is very important that `sorry' does not call
2489 `report_error_function'. That could cause an infinite loop. */
2491 pp_unsupported_tree (cxx_pp
, t
);
2492 /* fall through to ERROR_MARK... */
2494 pp_string (cxx_pp
, M_("<expression error>"));
2500 dump_binary_op (const char *opstring
, tree t
, int flags
)
2502 pp_cxx_left_paren (cxx_pp
);
2503 dump_expr (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2504 pp_cxx_whitespace (cxx_pp
);
2506 pp_cxx_ws_string (cxx_pp
, opstring
);
2508 pp_string (cxx_pp
, M_("<unknown operator>"));
2509 pp_cxx_whitespace (cxx_pp
);
2510 dump_expr (TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2511 pp_cxx_right_paren (cxx_pp
);
2515 dump_unary_op (const char *opstring
, tree t
, int flags
)
2517 if (flags
& TFF_EXPR_IN_PARENS
)
2518 pp_cxx_left_paren (cxx_pp
);
2519 pp_cxx_ws_string (cxx_pp
, opstring
);
2520 dump_expr (TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2521 if (flags
& TFF_EXPR_IN_PARENS
)
2522 pp_cxx_right_paren (cxx_pp
);
2526 reinit_cxx_pp (void)
2528 pp_clear_output_area (cxx_pp
);
2529 pp_base (cxx_pp
)->padding
= pp_none
;
2530 pp_indentation (cxx_pp
) = 0;
2531 pp_needs_newline (cxx_pp
) = false;
2532 cxx_pp
->enclosing_scope
= current_function_decl
;
2536 /* Exported interface to stringifying types, exprs and decls under TFF_*
2540 type_as_string (tree typ
, int flags
)
2543 pp_translate_identifiers (cxx_pp
) = false;
2544 dump_type (typ
, flags
);
2545 return pp_formatted_text (cxx_pp
);
2549 type_as_string_translate (tree typ
, int flags
)
2552 dump_type (typ
, flags
);
2553 return pp_formatted_text (cxx_pp
);
2557 expr_as_string (tree decl
, int flags
)
2560 pp_translate_identifiers (cxx_pp
) = false;
2561 dump_expr (decl
, flags
);
2562 return pp_formatted_text (cxx_pp
);
2565 /* Wrap decl_as_string with options appropriate for dwarf. */
2568 decl_as_dwarf_string (tree decl
, int flags
)
2571 /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag
2572 here will be adequate to get the desired behaviour. */
2573 pp_c_base (cxx_pp
)->flags
|= pp_c_flag_gnu_v3
;
2574 name
= decl_as_string (decl
, flags
);
2575 /* Subsequent calls to the pretty printer shouldn't use this style. */
2576 pp_c_base (cxx_pp
)->flags
&= ~pp_c_flag_gnu_v3
;
2581 decl_as_string (tree decl
, int flags
)
2584 pp_translate_identifiers (cxx_pp
) = false;
2585 dump_decl (decl
, flags
);
2586 return pp_formatted_text (cxx_pp
);
2590 decl_as_string_translate (tree decl
, int flags
)
2593 dump_decl (decl
, flags
);
2594 return pp_formatted_text (cxx_pp
);
2597 /* Wrap lang_decl_name with options appropriate for dwarf. */
2600 lang_decl_dwarf_name (tree decl
, int v
, bool translate
)
2603 /* Curiously, reinit_cxx_pp doesn't reset the flags field, so setting the flag
2604 here will be adequate to get the desired behaviour. */
2605 pp_c_base (cxx_pp
)->flags
|= pp_c_flag_gnu_v3
;
2606 name
= lang_decl_name (decl
, v
, translate
);
2607 /* Subsequent calls to the pretty printer shouldn't use this style. */
2608 pp_c_base (cxx_pp
)->flags
&= ~pp_c_flag_gnu_v3
;
2612 /* Generate the three forms of printable names for cxx_printable_name. */
2615 lang_decl_name (tree decl
, int v
, bool translate
)
2619 ? decl_as_string_translate (decl
, TFF_DECL_SPECIFIERS
)
2620 : decl_as_string (decl
, TFF_DECL_SPECIFIERS
));
2623 pp_translate_identifiers (cxx_pp
) = translate
;
2625 && (DECL_CLASS_SCOPE_P (decl
)
2626 || (DECL_NAMESPACE_SCOPE_P (decl
)
2627 && CP_DECL_CONTEXT (decl
) != global_namespace
)))
2629 dump_type (CP_DECL_CONTEXT (decl
), TFF_PLAIN_IDENTIFIER
);
2630 pp_cxx_colon_colon (cxx_pp
);
2633 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2634 dump_function_name (decl
, TFF_PLAIN_IDENTIFIER
);
2635 else if ((DECL_NAME (decl
) == NULL_TREE
)
2636 && TREE_CODE (decl
) == NAMESPACE_DECL
)
2637 dump_decl (decl
, TFF_PLAIN_IDENTIFIER
| TFF_UNQUALIFIED_NAME
);
2639 dump_decl (DECL_NAME (decl
), TFF_PLAIN_IDENTIFIER
);
2641 return pp_formatted_text (cxx_pp
);
2644 /* Return the location of a tree passed to %+ formats. */
2647 location_of (tree t
)
2649 if (TREE_CODE (t
) == PARM_DECL
&& DECL_CONTEXT (t
))
2650 t
= DECL_CONTEXT (t
);
2651 else if (TYPE_P (t
))
2653 t
= TYPE_MAIN_DECL (t
);
2655 return input_location
;
2657 else if (TREE_CODE (t
) == OVERLOAD
)
2658 t
= OVL_FUNCTION (t
);
2661 return DECL_SOURCE_LOCATION (t
);
2662 return EXPR_LOC_OR_HERE (t
);
2665 /* Now the interfaces from error et al to dump_type et al. Each takes an
2666 on/off VERBOSE flag and supply the appropriate TFF_ flags to a dump_
2670 decl_to_string (tree decl
, int verbose
)
2674 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == RECORD_TYPE
2675 || TREE_CODE (decl
) == UNION_TYPE
|| TREE_CODE (decl
) == ENUMERAL_TYPE
)
2676 flags
= TFF_CLASS_KEY_OR_ENUM
;
2678 flags
|= TFF_DECL_SPECIFIERS
;
2679 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
2680 flags
|= TFF_DECL_SPECIFIERS
| TFF_RETURN_TYPE
;
2681 flags
|= TFF_TEMPLATE_HEADER
;
2684 dump_decl (decl
, flags
);
2685 return pp_formatted_text (cxx_pp
);
2689 expr_to_string (tree decl
)
2692 dump_expr (decl
, 0);
2693 return pp_formatted_text (cxx_pp
);
2697 fndecl_to_string (tree fndecl
, int verbose
)
2701 flags
= TFF_EXCEPTION_SPECIFICATION
| TFF_DECL_SPECIFIERS
2702 | TFF_TEMPLATE_HEADER
;
2704 flags
|= TFF_FUNCTION_DEFAULT_ARGUMENTS
;
2706 dump_decl (fndecl
, flags
);
2707 return pp_formatted_text (cxx_pp
);
2712 code_to_string (enum tree_code c
)
2714 return tree_code_name
[c
];
2718 language_to_string (enum languages c
)
2725 case lang_cplusplus
:
2737 /* Return the proper printed version of a parameter to a C++ function. */
2740 parm_to_string (int p
)
2744 pp_string (cxx_pp
, "'this'");
2746 pp_decimal_int (cxx_pp
, p
+ 1);
2747 return pp_formatted_text (cxx_pp
);
2751 op_to_string (enum tree_code p
)
2753 tree id
= operator_name_info
[(int) p
].identifier
;
2754 return id
? IDENTIFIER_POINTER (id
) : M_("<unknown>");
2758 type_to_string (tree typ
, int verbose
)
2762 flags
|= TFF_CLASS_KEY_OR_ENUM
;
2763 flags
|= TFF_TEMPLATE_HEADER
;
2766 dump_type (typ
, flags
);
2767 /* If we're printing a type that involves typedefs, also print the
2768 stripped version. But sometimes the stripped version looks
2769 exactly the same, so we don't want it after all. To avoid printing
2770 it in that case, we play ugly obstack games. */
2771 if (typ
&& TYPE_P (typ
) && typ
!= TYPE_CANONICAL (typ
)
2772 && !uses_template_parms (typ
))
2774 int aka_start
; char *p
;
2775 struct obstack
*ob
= pp_base (cxx_pp
)->buffer
->obstack
;
2776 /* Remember the end of the initial dump. */
2777 int len
= obstack_object_size (ob
);
2778 tree aka
= strip_typedefs (typ
);
2779 pp_string (cxx_pp
, " {aka");
2780 pp_cxx_whitespace (cxx_pp
);
2781 /* And remember the start of the aka dump. */
2782 aka_start
= obstack_object_size (ob
);
2783 dump_type (aka
, flags
);
2784 pp_character (cxx_pp
, '}');
2785 p
= (char*)obstack_base (ob
);
2786 /* If they are identical, cut off the aka with a NUL. */
2787 if (memcmp (p
, p
+aka_start
, len
) == 0)
2790 return pp_formatted_text (cxx_pp
);
2794 assop_to_string (enum tree_code p
)
2796 tree id
= assignment_operator_name_info
[(int) p
].identifier
;
2797 return id
? IDENTIFIER_POINTER (id
) : M_("{unknown}");
2801 args_to_string (tree p
, int verbose
)
2805 flags
|= TFF_CLASS_KEY_OR_ENUM
;
2810 if (TYPE_P (TREE_VALUE (p
)))
2811 return type_as_string_translate (p
, flags
);
2814 for (; p
; p
= TREE_CHAIN (p
))
2816 if (TREE_VALUE (p
) == null_node
)
2817 pp_cxx_ws_string (cxx_pp
, "NULL");
2819 dump_type (error_type (TREE_VALUE (p
)), flags
);
2821 pp_separate_with_comma (cxx_pp
);
2823 return pp_formatted_text (cxx_pp
);
2826 /* Pretty-print a deduction substitution (from deduction_tsubst_fntype). P
2827 is a TREE_LIST with purpose the TEMPLATE_DECL, value the template
2831 subst_to_string (tree p
)
2833 tree decl
= TREE_PURPOSE (p
);
2834 tree targs
= TREE_VALUE (p
);
2835 tree tparms
= DECL_TEMPLATE_PARMS (decl
);
2836 int flags
= TFF_DECL_SPECIFIERS
|TFF_TEMPLATE_HEADER
;
2842 dump_template_decl (TREE_PURPOSE (p
), flags
);
2843 pp_cxx_whitespace (cxx_pp
);
2844 pp_cxx_left_bracket (cxx_pp
);
2845 pp_cxx_ws_string (cxx_pp
, M_("with"));
2846 pp_cxx_whitespace (cxx_pp
);
2847 dump_template_bindings (tparms
, targs
, NULL
);
2848 pp_cxx_right_bracket (cxx_pp
);
2849 return pp_formatted_text (cxx_pp
);
2853 cv_to_string (tree p
, int v
)
2856 pp_base (cxx_pp
)->padding
= v
? pp_before
: pp_none
;
2857 pp_cxx_cv_qualifier_seq (cxx_pp
, p
);
2858 return pp_formatted_text (cxx_pp
);
2861 /* Langhook for print_error_function. */
2863 cxx_print_error_function (diagnostic_context
*context
, const char *file
,
2864 diagnostic_info
*diagnostic
)
2866 lhd_print_error_function (context
, file
, diagnostic
);
2867 pp_base_set_prefix (context
->printer
, file
);
2868 maybe_print_instantiation_context (context
);
2872 cp_diagnostic_starter (diagnostic_context
*context
,
2873 diagnostic_info
*diagnostic
)
2875 diagnostic_report_current_module (context
, diagnostic
->location
);
2876 cp_print_error_function (context
, diagnostic
);
2877 maybe_print_instantiation_context (context
);
2878 maybe_print_constexpr_context (context
);
2879 pp_base_set_prefix (context
->printer
, diagnostic_build_prefix (context
,
2884 cp_diagnostic_finalizer (diagnostic_context
*context
,
2885 diagnostic_info
*diagnostic
)
2887 virt_loc_aware_diagnostic_finalizer (context
, diagnostic
);
2888 pp_base_destroy_prefix (context
->printer
);
2891 /* Print current function onto BUFFER, in the process of reporting
2892 a diagnostic message. Called from cp_diagnostic_starter. */
2894 cp_print_error_function (diagnostic_context
*context
,
2895 diagnostic_info
*diagnostic
)
2897 /* If we are in an instantiation context, current_function_decl is likely
2898 to be wrong, so just rely on print_instantiation_full_context. */
2899 if (current_instantiation ())
2901 if (diagnostic_last_function_changed (context
, diagnostic
))
2903 const char *old_prefix
= context
->printer
->prefix
;
2904 const char *file
= LOCATION_FILE (diagnostic
->location
);
2905 tree abstract_origin
= diagnostic_abstract_origin (diagnostic
);
2906 char *new_prefix
= (file
&& abstract_origin
== NULL
)
2907 ? file_name_as_prefix (file
) : NULL
;
2909 pp_base_set_prefix (context
->printer
, new_prefix
);
2911 if (current_function_decl
== NULL
)
2912 pp_base_string (context
->printer
, _("At global scope:"));
2917 if (abstract_origin
)
2919 ao
= BLOCK_ABSTRACT_ORIGIN (abstract_origin
);
2920 while (TREE_CODE (ao
) == BLOCK
2921 && BLOCK_ABSTRACT_ORIGIN (ao
)
2922 && BLOCK_ABSTRACT_ORIGIN (ao
) != ao
)
2923 ao
= BLOCK_ABSTRACT_ORIGIN (ao
);
2924 gcc_assert (TREE_CODE (ao
) == FUNCTION_DECL
);
2928 fndecl
= current_function_decl
;
2930 pp_printf (context
->printer
, function_category (fndecl
),
2931 cxx_printable_name_translate (fndecl
, 2));
2933 while (abstract_origin
)
2936 tree block
= abstract_origin
;
2938 locus
= &BLOCK_SOURCE_LOCATION (block
);
2940 block
= BLOCK_SUPERCONTEXT (block
);
2941 while (block
&& TREE_CODE (block
) == BLOCK
2942 && BLOCK_ABSTRACT_ORIGIN (block
))
2944 ao
= BLOCK_ABSTRACT_ORIGIN (block
);
2946 while (TREE_CODE (ao
) == BLOCK
2947 && BLOCK_ABSTRACT_ORIGIN (ao
)
2948 && BLOCK_ABSTRACT_ORIGIN (ao
) != ao
)
2949 ao
= BLOCK_ABSTRACT_ORIGIN (ao
);
2951 if (TREE_CODE (ao
) == FUNCTION_DECL
)
2956 else if (TREE_CODE (ao
) != BLOCK
)
2959 block
= BLOCK_SUPERCONTEXT (block
);
2962 abstract_origin
= block
;
2965 while (block
&& TREE_CODE (block
) == BLOCK
)
2966 block
= BLOCK_SUPERCONTEXT (block
);
2968 if (block
&& TREE_CODE (block
) == FUNCTION_DECL
)
2970 abstract_origin
= NULL
;
2974 expanded_location s
= expand_location (*locus
);
2975 pp_base_character (context
->printer
, ',');
2976 pp_base_newline (context
->printer
);
2979 if (context
->show_column
&& s
.column
!= 0)
2980 pp_printf (context
->printer
,
2981 _(" inlined from %qs at %s:%d:%d"),
2982 cxx_printable_name_translate (fndecl
, 2),
2983 s
.file
, s
.line
, s
.column
);
2985 pp_printf (context
->printer
,
2986 _(" inlined from %qs at %s:%d"),
2987 cxx_printable_name_translate (fndecl
, 2),
2992 pp_printf (context
->printer
, _(" inlined from %qs"),
2993 cxx_printable_name_translate (fndecl
, 2));
2996 pp_base_character (context
->printer
, ':');
2998 pp_base_newline (context
->printer
);
3000 diagnostic_set_last_function (context
, diagnostic
);
3001 pp_base_destroy_prefix (context
->printer
);
3002 context
->printer
->prefix
= old_prefix
;
3006 /* Returns a description of FUNCTION using standard terminology. The
3007 result is a format string of the form "In CATEGORY %qs". */
3009 function_category (tree fn
)
3011 /* We can get called from the middle-end for diagnostics of function
3012 clones. Make sure we have language specific information before
3013 dereferencing it. */
3014 if (DECL_LANG_SPECIFIC (STRIP_TEMPLATE (fn
))
3015 && DECL_FUNCTION_MEMBER_P (fn
))
3017 if (DECL_STATIC_FUNCTION_P (fn
))
3018 return _("In static member function %qs");
3019 else if (DECL_COPY_CONSTRUCTOR_P (fn
))
3020 return _("In copy constructor %qs");
3021 else if (DECL_CONSTRUCTOR_P (fn
))
3022 return _("In constructor %qs");
3023 else if (DECL_DESTRUCTOR_P (fn
))
3024 return _("In destructor %qs");
3025 else if (LAMBDA_FUNCTION_P (fn
))
3026 return _("In lambda function");
3028 return _("In member function %qs");
3031 return _("In function %qs");
3034 /* Report the full context of a current template instantiation,
3037 print_instantiation_full_context (diagnostic_context
*context
)
3039 struct tinst_level
*p
= current_instantiation ();
3040 location_t location
= input_location
;
3044 pp_verbatim (context
->printer
,
3045 TREE_CODE (p
->decl
) == TREE_LIST
3046 ? _("%s: In substitution of %qS:\n")
3047 : _("%s: In instantiation of %q#D:\n"),
3048 LOCATION_FILE (location
),
3051 location
= p
->locus
;
3055 print_instantiation_partial_context (context
, p
, location
);
3058 /* Helper function of print_instantiation_partial_context() that
3059 prints a single line of instantiation context. */
3062 print_instantiation_partial_context_line (diagnostic_context
*context
,
3063 const struct tinst_level
*t
,
3064 location_t loc
, bool recursive_p
)
3066 expanded_location xloc
;
3067 xloc
= expand_location (loc
);
3069 if (context
->show_column
)
3070 pp_verbatim (context
->printer
, _("%s:%d:%d: "),
3071 xloc
.file
, xloc
.line
, xloc
.column
);
3073 pp_verbatim (context
->printer
, _("%s:%d: "),
3074 xloc
.file
, xloc
.line
);
3078 if (TREE_CODE (t
->decl
) == TREE_LIST
)
3079 pp_verbatim (context
->printer
,
3081 ? _("recursively required by substitution of %qS\n")
3082 : _("required by substitution of %qS\n"),
3085 pp_verbatim (context
->printer
,
3087 ? _("recursively required from %q#D\n")
3088 : _("required from %q#D\n"),
3093 pp_verbatim (context
->printer
,
3095 ? _("recursively required from here")
3096 : _("required from here"));
3100 /* Same as print_instantiation_full_context but less verbose. */
3103 print_instantiation_partial_context (diagnostic_context
*context
,
3104 struct tinst_level
*t0
, location_t loc
)
3106 struct tinst_level
*t
;
3109 location_t prev_loc
= loc
;
3111 for (t
= t0
; t
!= NULL
; t
= t
->next
)
3112 if (prev_loc
!= t
->locus
)
3114 prev_loc
= t
->locus
;
3120 if (template_backtrace_limit
3121 && n_total
> template_backtrace_limit
)
3123 int skip
= n_total
- template_backtrace_limit
;
3124 int head
= template_backtrace_limit
/ 2;
3126 /* Avoid skipping just 1. If so, skip 2. */
3130 head
= (template_backtrace_limit
- 1) / 2;
3133 for (n
= 0; n
< head
; n
++)
3135 gcc_assert (t
!= NULL
);
3136 if (loc
!= t
->locus
)
3137 print_instantiation_partial_context_line (context
, t
, loc
,
3138 /*recursive_p=*/false);
3142 if (t
!= NULL
&& skip
> 0)
3144 expanded_location xloc
;
3145 xloc
= expand_location (loc
);
3146 if (context
->show_column
)
3147 pp_verbatim (context
->printer
,
3148 _("%s:%d:%d: [ skipping %d instantiation contexts, "
3149 "use -ftemplate-backtrace-limit=0 to disable ]\n"),
3150 xloc
.file
, xloc
.line
, xloc
.column
, skip
);
3152 pp_verbatim (context
->printer
,
3153 _("%s:%d: [ skipping %d instantiation contexts, "
3154 "use -ftemplate-backtrace-limit=0 to disable ]\n"),
3155 xloc
.file
, xloc
.line
, skip
);
3160 } while (t
!= NULL
&& --skip
> 0);
3166 while (t
->next
!= NULL
&& t
->locus
== t
->next
->locus
)
3171 print_instantiation_partial_context_line (context
, t
, loc
,
3176 print_instantiation_partial_context_line (context
, NULL
, loc
,
3177 /*recursive_p=*/false);
3178 pp_base_newline (context
->printer
);
3181 /* Called from cp_thing to print the template context for an error. */
3183 maybe_print_instantiation_context (diagnostic_context
*context
)
3185 if (!problematic_instantiation_changed () || current_instantiation () == 0)
3188 record_last_problematic_instantiation ();
3189 print_instantiation_full_context (context
);
3192 /* Report the bare minimum context of a template instantiation. */
3194 print_instantiation_context (void)
3196 print_instantiation_partial_context
3197 (global_dc
, current_instantiation (), input_location
);
3198 pp_base_newline (global_dc
->printer
);
3199 diagnostic_flush_buffer (global_dc
);
3202 /* Report what constexpr call(s) we're trying to expand, if any. */
3205 maybe_print_constexpr_context (diagnostic_context
*context
)
3207 VEC(tree
,heap
) *call_stack
= cx_error_context ();
3211 FOR_EACH_VEC_ELT (tree
, call_stack
, ix
, t
)
3213 expanded_location xloc
= expand_location (EXPR_LOCATION (t
));
3214 const char *s
= expr_as_string (t
, 0);
3215 if (context
->show_column
)
3216 pp_verbatim (context
->printer
,
3217 _("%s:%d:%d: in constexpr expansion of %qs"),
3218 xloc
.file
, xloc
.line
, xloc
.column
, s
);
3220 pp_verbatim (context
->printer
,
3221 _("%s:%d: in constexpr expansion of %qs"),
3222 xloc
.file
, xloc
.line
, s
);
3223 pp_base_newline (context
->printer
);
3227 /* Called from output_format -- during diagnostic message processing --
3228 to handle C++ specific format specifier with the following meanings:
3229 %A function argument-list.
3233 %F function declaration.
3234 %L language as used in extern "lang".
3236 %P function parameter whose position is indicated by an integer.
3237 %Q assignment operator.
3241 cp_printer (pretty_printer
*pp
, text_info
*text
, const char *spec
,
3242 int precision
, bool wide
, bool set_locus
, bool verbose
)
3246 #define next_tree (t = va_arg (*text->args_ptr, tree))
3247 #define next_tcode ((enum tree_code) va_arg (*text->args_ptr, int))
3248 #define next_lang ((enum languages) va_arg (*text->args_ptr, int))
3249 #define next_int va_arg (*text->args_ptr, int)
3251 if (precision
!= 0 || wide
)
3254 if (text
->locus
== NULL
)
3259 case 'A': result
= args_to_string (next_tree
, verbose
); break;
3260 case 'C': result
= code_to_string (next_tcode
); break;
3263 tree temp
= next_tree
;
3265 && DECL_DEBUG_EXPR_IS_FROM (temp
) && DECL_DEBUG_EXPR (temp
))
3267 temp
= DECL_DEBUG_EXPR (temp
);
3270 result
= expr_to_string (temp
);
3274 result
= decl_to_string (temp
, verbose
);
3277 case 'E': result
= expr_to_string (next_tree
); break;
3278 case 'F': result
= fndecl_to_string (next_tree
, verbose
); break;
3279 case 'L': result
= language_to_string (next_lang
); break;
3280 case 'O': result
= op_to_string (next_tcode
); break;
3281 case 'P': result
= parm_to_string (next_int
); break;
3282 case 'Q': result
= assop_to_string (next_tcode
); break;
3283 case 'S': result
= subst_to_string (next_tree
); break;
3284 case 'T': result
= type_to_string (next_tree
, verbose
); break;
3285 case 'V': result
= cv_to_string (next_tree
, verbose
); break;
3288 percent_K_format (text
);
3295 pp_base_string (pp
, result
);
3296 if (set_locus
&& t
!= NULL
)
3297 *text
->locus
= location_of (t
);
3305 /* Warn about the use of C++0x features when appropriate. */
3307 maybe_warn_cpp0x (cpp0x_warn_str str
)
3309 if ((cxx_dialect
== cxx98
) && !in_system_header
)
3310 /* We really want to suppress this warning in system headers,
3311 because libstdc++ uses variadic templates even when we aren't
3315 case CPP0X_INITIALIZER_LISTS
:
3316 pedwarn (input_location
, 0,
3317 "extended initializer lists "
3318 "only available with -std=c++11 or -std=gnu++11");
3320 case CPP0X_EXPLICIT_CONVERSION
:
3321 pedwarn (input_location
, 0,
3322 "explicit conversion operators "
3323 "only available with -std=c++11 or -std=gnu++11");
3325 case CPP0X_VARIADIC_TEMPLATES
:
3326 pedwarn (input_location
, 0,
3327 "variadic templates "
3328 "only available with -std=c++11 or -std=gnu++11");
3330 case CPP0X_LAMBDA_EXPR
:
3331 pedwarn (input_location
, 0,
3332 "lambda expressions "
3333 "only available with -std=c++11 or -std=gnu++11");
3336 pedwarn (input_location
, 0,
3337 "C++0x auto only available with -std=c++11 or -std=gnu++11");
3339 case CPP0X_SCOPED_ENUMS
:
3340 pedwarn (input_location
, 0,
3341 "scoped enums only available with -std=c++11 or -std=gnu++11");
3343 case CPP0X_DEFAULTED_DELETED
:
3344 pedwarn (input_location
, 0,
3345 "defaulted and deleted functions "
3346 "only available with -std=c++11 or -std=gnu++11");
3348 case CPP0X_INLINE_NAMESPACES
:
3349 pedwarn (input_location
, OPT_Wpedantic
,
3350 "inline namespaces "
3351 "only available with -std=c++11 or -std=gnu++11");
3353 case CPP0X_OVERRIDE_CONTROLS
:
3354 pedwarn (input_location
, 0,
3355 "override controls (override/final) "
3356 "only available with -std=c++11 or -std=gnu++11");
3359 pedwarn (input_location
, 0,
3360 "non-static data member initializers "
3361 "only available with -std=c++11 or -std=gnu++11");
3363 case CPP0X_USER_DEFINED_LITERALS
:
3364 pedwarn (input_location
, 0,
3365 "user-defined literals "
3366 "only available with -std=c++11 or -std=gnu++11");
3368 case CPP0X_DELEGATING_CTORS
:
3369 pedwarn (input_location
, 0,
3370 "delegating constructors "
3371 "only available with -std=c++11 or -std=gnu++11");
3378 /* Warn about the use of variadic templates when appropriate. */
3380 maybe_warn_variadic_templates (void)
3382 maybe_warn_cpp0x (CPP0X_VARIADIC_TEMPLATES
);
3386 /* Issue an ISO C++98 pedantic warning at LOCATION, conditional on
3387 option OPT with text GMSGID. Use this function to report
3388 diagnostics for constructs that are invalid C++98, but valid
3391 pedwarn_cxx98 (location_t location
, int opt
, const char *gmsgid
, ...)
3393 diagnostic_info diagnostic
;
3397 va_start (ap
, gmsgid
);
3398 diagnostic_set_info (&diagnostic
, gmsgid
, &ap
, location
,
3399 (cxx_dialect
== cxx98
) ? DK_PEDWARN
: DK_WARNING
);
3400 diagnostic
.option_index
= opt
;
3401 ret
= report_diagnostic (&diagnostic
);
3406 /* Issue a diagnostic that NAME cannot be found in SCOPE. DECL is what
3407 we found when we tried to do the lookup. LOCATION is the location of
3408 the NAME identifier. */
3411 qualified_name_lookup_error (tree scope
, tree name
,
3412 tree decl
, location_t location
)
3414 if (scope
== error_mark_node
)
3415 ; /* We already complained. */
3416 else if (TYPE_P (scope
))
3418 if (!COMPLETE_TYPE_P (scope
))
3419 error_at (location
, "incomplete type %qT used in nested name specifier",
3421 else if (TREE_CODE (decl
) == TREE_LIST
)
3423 error_at (location
, "reference to %<%T::%D%> is ambiguous",
3425 print_candidates (decl
);
3428 error_at (location
, "%qD is not a member of %qT", name
, scope
);
3430 else if (scope
!= global_namespace
)
3432 error_at (location
, "%qD is not a member of %qD", name
, scope
);
3433 suggest_alternatives_for (location
, name
);
3437 error_at (location
, "%<::%D%> has not been declared", name
);
3438 suggest_alternatives_for (location
, name
);