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,
4 2003 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
24 #include "coretypes.h"
31 #include "diagnostic.h"
32 #include "langhooks-def.h"
34 enum pad
{ none
, before
, after
};
36 #define sorry_for_unsupported_tree(T) \
37 sorry ("`%s' not supported by %s", tree_code_name[(int) TREE_CODE (T)], \
40 #define print_scope_operator(BUFFER) output_add_string ((BUFFER), "::")
41 #define print_left_paren(BUFFER) output_add_character ((BUFFER), '(')
42 #define print_right_paren(BUFFER) output_add_character ((BUFFER), ')')
43 #define print_left_bracket(BUFFER) output_add_character ((BUFFER), '[')
44 #define print_right_bracket(BUFFER) output_add_character ((BUFFER), ']')
45 #define print_template_argument_list_start(BUFFER) \
46 print_non_consecutive_character ((BUFFER), '<')
47 #define print_template_argument_list_end(BUFFER) \
48 print_non_consecutive_character ((BUFFER), '>')
49 #define print_tree_identifier(BUFFER, TID) \
50 output_add_string ((BUFFER), IDENTIFIER_POINTER (TID))
51 #define print_identifier(BUFFER, ID) output_add_string ((BUFFER), (ID))
52 #define separate_with_comma(BUFFER) output_add_string ((BUFFER), ", ")
54 /* The global buffer where we dump everything. It is there only for
55 transitional purpose. It is expected, in the near future, to be
56 completely removed. */
57 static output_buffer scratch_buffer_rec
;
58 static output_buffer
*scratch_buffer
= &scratch_buffer_rec
;
60 # define NEXT_CODE(T) (TREE_CODE (TREE_TYPE (T)))
62 #define reinit_global_formatting_buffer() \
63 output_clear_message_text (scratch_buffer)
65 static const char *args_to_string (tree
, int);
66 static const char *assop_to_string (enum tree_code
);
67 static const char *code_to_string (enum tree_code
);
68 static const char *cv_to_string (tree
, int);
69 static const char *decl_to_string (tree
, int);
70 static const char *expr_to_string (tree
);
71 static const char *fndecl_to_string (tree
, int);
72 static const char *op_to_string (enum tree_code
);
73 static const char *parm_to_string (int);
74 static const char *type_to_string (tree
, int);
76 static void dump_type (tree
, int);
77 static void dump_typename (tree
, int);
78 static void dump_simple_decl (tree
, tree
, int);
79 static void dump_decl (tree
, int);
80 static void dump_template_decl (tree
, int);
81 static void dump_function_decl (tree
, int);
82 static void dump_expr (tree
, int);
83 static void dump_unary_op (const char *, tree
, int);
84 static void dump_binary_op (const char *, tree
, int);
85 static void dump_aggr_type (tree
, int);
86 static enum pad
dump_type_prefix (tree
, int);
87 static void dump_type_suffix (tree
, int);
88 static void dump_function_name (tree
, int);
89 static void dump_expr_list (tree
, int);
90 static void dump_global_iord (tree
);
91 static enum pad
dump_qualifiers (tree
, enum pad
);
92 static void dump_char (int);
93 static void dump_parameters (tree
, int);
94 static void dump_exception_spec (tree
, int);
95 static const char *class_key_or_enum (tree
);
96 static void dump_template_argument (tree
, int);
97 static void dump_template_argument_list (tree
, int);
98 static void dump_template_parameter (tree
, int);
99 static void dump_template_bindings (tree
, tree
);
100 static void dump_scope (tree
, int);
101 static void dump_template_parms (tree
, int, int);
103 static const char *function_category (tree
);
104 static void maybe_print_instantiation_context (diagnostic_context
*);
105 static void print_instantiation_full_context (diagnostic_context
*);
106 static void print_instantiation_partial_context (diagnostic_context
*,
108 static void cp_diagnostic_starter (diagnostic_context
*, diagnostic_info
*);
109 static void cp_diagnostic_finalizer (diagnostic_context
*, diagnostic_info
*);
110 static void cp_print_error_function (diagnostic_context
*, diagnostic_info
*);
112 static bool cp_printer (output_buffer
*, text_info
*);
113 static void print_non_consecutive_character (output_buffer
*, int);
114 static tree
locate_error (const char *, va_list);
115 static location_t
location_of (tree
);
120 diagnostic_starter (global_dc
) = cp_diagnostic_starter
;
121 diagnostic_finalizer (global_dc
) = cp_diagnostic_finalizer
;
122 diagnostic_format_decoder (global_dc
) = cp_printer
;
124 init_output_buffer (scratch_buffer
, /* prefix */NULL
, /* line-width */0);
127 /* Dump a scope, if deemed necessary. */
130 dump_scope (tree scope
, int flags
)
132 int f
= ~TFF_RETURN_TYPE
& (flags
& (TFF_SCOPE
| TFF_CHASE_TYPEDEF
));
134 if (scope
== NULL_TREE
)
137 if (TREE_CODE (scope
) == NAMESPACE_DECL
)
139 if (scope
!= global_namespace
)
141 dump_decl (scope
, f
);
142 print_scope_operator (scratch_buffer
);
145 else if (AGGREGATE_TYPE_P (scope
))
147 dump_type (scope
, f
);
148 print_scope_operator (scratch_buffer
);
150 else if ((flags
& TFF_SCOPE
) && TREE_CODE (scope
) == FUNCTION_DECL
)
152 dump_function_decl (scope
, f
);
153 print_scope_operator (scratch_buffer
);
157 /* Dump type qualifiers, providing padding as requested. Return an
158 indication of whether we dumped something. */
161 dump_qualifiers (tree t
, enum pad p
)
163 static const int masks
[] =
164 {TYPE_QUAL_CONST
, TYPE_QUAL_VOLATILE
, TYPE_QUAL_RESTRICT
};
165 static const char *const names
[] =
166 {"const", "volatile", "__restrict"};
168 int quals
= TYPE_QUALS (t
);
169 int do_after
= p
== after
;
173 for (ix
= 0; ix
!= 3; ix
++)
174 if (masks
[ix
] & quals
)
177 output_add_space (scratch_buffer
);
179 print_identifier (scratch_buffer
, names
[ix
]);
182 output_add_space (scratch_buffer
);
189 /* Dump the template ARGument under control of FLAGS. */
192 dump_template_argument (tree arg
, int flags
)
194 if (TYPE_P (arg
) || TREE_CODE (arg
) == TEMPLATE_DECL
)
195 dump_type (arg
, flags
& ~TFF_CLASS_KEY_OR_ENUM
);
197 dump_expr (arg
, (flags
| TFF_EXPR_IN_PARENS
) & ~TFF_CLASS_KEY_OR_ENUM
);
200 /* Dump a template-argument-list ARGS (always a TREE_VEC) under control
204 dump_template_argument_list (tree args
, int flags
)
206 int n
= TREE_VEC_LENGTH (args
);
210 for (i
= 0; i
< n
; ++i
)
213 separate_with_comma (scratch_buffer
);
214 dump_template_argument (TREE_VEC_ELT (args
, i
), flags
);
219 /* Dump a template parameter PARM (a TREE_LIST) under control of FLAGS. */
222 dump_template_parameter (tree parm
, int flags
)
224 tree p
= TREE_VALUE (parm
);
225 tree a
= TREE_PURPOSE (parm
);
227 if (TREE_CODE (p
) == TYPE_DECL
)
229 if (flags
& TFF_DECL_SPECIFIERS
)
231 print_identifier (scratch_buffer
, "class");
234 output_add_space (scratch_buffer
);
235 print_tree_identifier (scratch_buffer
, DECL_NAME (p
));
238 else if (DECL_NAME (p
))
239 print_tree_identifier (scratch_buffer
, DECL_NAME (p
));
241 print_identifier (scratch_buffer
, "{template default argument error}");
244 dump_decl (p
, flags
| TFF_DECL_SPECIFIERS
);
246 if ((flags
& TFF_FUNCTION_DEFAULT_ARGUMENTS
) && a
!= NULL_TREE
)
248 output_add_string (scratch_buffer
, " = ");
249 if (TREE_CODE (p
) == TYPE_DECL
|| TREE_CODE (p
) == TEMPLATE_DECL
)
250 dump_type (a
, flags
& ~TFF_CHASE_TYPEDEF
);
252 dump_expr (a
, flags
| TFF_EXPR_IN_PARENS
);
256 /* Dump, under control of FLAGS, a template-parameter-list binding.
257 PARMS is a TREE_LIST of TREE_VEC of TREE_LIST and ARGS is a
261 dump_template_bindings (tree parms
, tree args
)
267 tree p
= TREE_VALUE (parms
);
268 int lvl
= TMPL_PARMS_DEPTH (parms
);
272 for (i
= 0; i
< TREE_VEC_LENGTH (p
); ++i
)
274 tree arg
= NULL_TREE
;
276 /* Don't crash if we had an invalid argument list. */
277 if (TMPL_ARGS_DEPTH (args
) >= lvl
)
279 tree lvl_args
= TMPL_ARGS_LEVEL (args
, lvl
);
280 if (NUM_TMPL_ARGS (lvl_args
) > arg_idx
)
281 arg
= TREE_VEC_ELT (lvl_args
, arg_idx
);
285 separate_with_comma (scratch_buffer
);
286 dump_template_parameter (TREE_VEC_ELT (p
, i
), TFF_PLAIN_IDENTIFIER
);
287 output_add_string (scratch_buffer
, " = ");
289 dump_template_argument (arg
, TFF_PLAIN_IDENTIFIER
);
291 print_identifier (scratch_buffer
, "<missing>");
297 parms
= TREE_CHAIN (parms
);
301 /* Dump a human-readable equivalent of TYPE. FLAGS controls the
305 dump_type (tree t
, int flags
)
310 if (TYPE_PTRMEMFUNC_P (t
))
313 switch (TREE_CODE (t
))
316 print_identifier (scratch_buffer
, "<unknown type>");
320 /* A list of function parms. */
321 dump_parameters (t
, flags
);
324 case IDENTIFIER_NODE
:
325 print_tree_identifier (scratch_buffer
, t
);
329 dump_type (BINFO_TYPE (t
), flags
);
335 dump_aggr_type (t
, flags
);
339 if (flags
& TFF_CHASE_TYPEDEF
)
341 dump_type (DECL_ORIGINAL_TYPE (t
)
342 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
), flags
);
345 /* else fallthrough */
349 dump_decl (t
, flags
& ~TFF_DECL_SPECIFIERS
);
353 output_add_string (scratch_buffer
, "__complex__ ");
354 dump_type (TREE_TYPE (t
), flags
);
358 output_add_string (scratch_buffer
, "__vector__ ");
360 /* The subtype of a VECTOR_TYPE is something like intQI_type_node,
361 which has no name and is not very useful for diagnostics. So
362 look up the equivalent C type and print its name. */
363 tree elt
= TREE_TYPE (t
);
364 elt
= c_common_type_for_mode (TYPE_MODE (elt
), TREE_UNSIGNED (elt
));
365 dump_type (elt
, flags
);
370 if (!TREE_UNSIGNED (TYPE_MAIN_VARIANT (t
)) && TREE_UNSIGNED (t
))
371 output_add_string (scratch_buffer
, "unsigned ");
372 else if (TREE_UNSIGNED (TYPE_MAIN_VARIANT (t
)) && !TREE_UNSIGNED (t
))
373 output_add_string (scratch_buffer
, "signed ");
381 dump_qualifiers (t
, after
);
382 type
= flags
& TFF_CHASE_TYPEDEF
? TYPE_MAIN_VARIANT (t
) : t
;
383 if (TYPE_NAME (type
) && TYPE_IDENTIFIER (type
))
384 print_tree_identifier (scratch_buffer
, TYPE_IDENTIFIER (type
));
386 /* Types like intQI_type_node and friends have no names.
387 These don't come up in user error messages, but it's nice
388 to be able to print them from the debugger. */
389 print_identifier (scratch_buffer
, "<anonymous>");
393 case TEMPLATE_TEMPLATE_PARM
:
394 /* For parameters inside template signature. */
395 if (TYPE_IDENTIFIER (t
))
396 print_tree_identifier (scratch_buffer
, TYPE_IDENTIFIER (t
));
399 (scratch_buffer
, "<anonymous template template parameter>");
402 case BOUND_TEMPLATE_TEMPLATE_PARM
:
404 tree args
= TYPE_TI_ARGS (t
);
405 print_tree_identifier (scratch_buffer
, TYPE_IDENTIFIER (t
));
406 print_template_argument_list_start (scratch_buffer
);
407 dump_template_argument_list (args
, flags
);
408 print_template_argument_list_end (scratch_buffer
);
412 case TEMPLATE_TYPE_PARM
:
413 dump_qualifiers (t
, after
);
414 if (TYPE_IDENTIFIER (t
))
415 print_tree_identifier (scratch_buffer
, TYPE_IDENTIFIER (t
));
418 (scratch_buffer
, "<anonymous template type parameter>");
421 /* This is not always necessary for pointers and such, but doing this
422 reduces code size. */
431 dump_type_prefix (t
, flags
);
432 dump_type_suffix (t
, flags
);
436 dump_qualifiers (t
, after
);
437 output_add_string (scratch_buffer
, "typename ");
438 dump_typename (t
, flags
);
441 case UNBOUND_CLASS_TEMPLATE
:
442 dump_type (TYPE_CONTEXT (t
), flags
);
443 print_scope_operator (scratch_buffer
);
444 print_identifier (scratch_buffer
, "template ");
445 dump_type (DECL_NAME (TYPE_NAME (t
)), flags
);
449 output_add_string (scratch_buffer
, "__typeof (");
450 dump_expr (TYPE_FIELDS (t
), flags
& ~TFF_EXPR_IN_PARENS
);
451 print_right_paren (scratch_buffer
);
455 sorry_for_unsupported_tree (t
);
456 /* Fall through to error. */
459 print_identifier (scratch_buffer
, "<type error>");
464 /* Dump a TYPENAME_TYPE. We need to notice when the context is itself
468 dump_typename (tree t
, int flags
)
470 tree ctx
= TYPE_CONTEXT (t
);
472 if (TREE_CODE (ctx
) == TYPENAME_TYPE
)
473 dump_typename (ctx
, flags
);
475 dump_type (ctx
, flags
& ~TFF_CLASS_KEY_OR_ENUM
);
476 print_scope_operator (scratch_buffer
);
477 dump_decl (TYPENAME_TYPE_FULLNAME (t
), flags
);
480 /* Return the name of the supplied aggregate, or enumeral type. */
483 class_key_or_enum (tree t
)
485 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
487 else if (TREE_CODE (t
) == UNION_TYPE
)
489 else if (TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_DECLARED_CLASS (t
))
495 /* Print out a class declaration T under the control of FLAGS,
496 in the form `class foo'. */
499 dump_aggr_type (tree t
, int flags
)
502 const char *variety
= class_key_or_enum (t
);
506 dump_qualifiers (t
, after
);
508 if (flags
& TFF_CLASS_KEY_OR_ENUM
)
510 print_identifier (scratch_buffer
, variety
);
511 output_add_space (scratch_buffer
);
514 if (flags
& TFF_CHASE_TYPEDEF
)
515 t
= TYPE_MAIN_VARIANT (t
);
517 name
= TYPE_NAME (t
);
521 typdef
= !DECL_ARTIFICIAL (name
);
522 tmplate
= !typdef
&& TREE_CODE (t
) != ENUMERAL_TYPE
523 && TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_TEMPLATE_INFO (t
)
524 && (CLASSTYPE_TEMPLATE_SPECIALIZATION (t
)
525 || TREE_CODE (CLASSTYPE_TI_TEMPLATE (t
)) != TEMPLATE_DECL
526 || DECL_TEMPLATE_SPECIALIZATION (CLASSTYPE_TI_TEMPLATE (t
))
527 || PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t
)));
528 dump_scope (CP_DECL_CONTEXT (name
), flags
| TFF_SCOPE
);
531 /* Because the template names are mangled, we have to locate
532 the most general template, and use that name. */
533 tree tpl
= CLASSTYPE_TI_TEMPLATE (t
);
535 while (DECL_TEMPLATE_INFO (tpl
))
536 tpl
= DECL_TI_TEMPLATE (tpl
);
539 name
= DECL_NAME (name
);
542 if (name
== 0 || ANON_AGGRNAME_P (name
))
544 if (flags
& TFF_CLASS_KEY_OR_ENUM
)
545 print_identifier (scratch_buffer
, "<anonymous>");
547 output_printf (scratch_buffer
, "<anonymous %s>", variety
);
550 print_tree_identifier (scratch_buffer
, name
);
552 dump_template_parms (TYPE_TEMPLATE_INFO (t
),
553 !CLASSTYPE_USE_TEMPLATE (t
),
554 flags
& ~TFF_TEMPLATE_HEADER
);
557 /* Dump into the obstack the initial part of the output for a given type.
558 This is necessary when dealing with things like functions returning
561 return type of `int (* fee ())()': pointer -> function -> int. Both
562 pointer (and reference and offset) and function (and member) types must
563 deal with prefix and suffix.
565 Arrays must also do this for DECL nodes, like int a[], and for things like
568 Return indicates how you should pad an object name after this. I.e. you
569 want to pad non-*, non-& cores, but not pad * or & types. */
572 dump_type_prefix (tree t
, int flags
)
574 enum pad padding
= before
;
576 if (TYPE_PTRMEMFUNC_P (t
))
578 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
582 switch (TREE_CODE (t
))
587 tree sub
= TREE_TYPE (t
);
589 padding
= dump_type_prefix (sub
, flags
);
590 /* A tree for a member pointer looks like pointer to offset,
591 so let the OFFSET_TYPE case handle it. */
592 if (!TYPE_PTRMEM_P (t
))
594 if (TREE_CODE (sub
) == ARRAY_TYPE
)
596 output_add_space (scratch_buffer
);
597 print_left_paren (scratch_buffer
);
600 (scratch_buffer
, "&*"[TREE_CODE (t
) == POINTER_TYPE
]);
601 padding
= dump_qualifiers (t
, before
);
608 padding
= dump_type_prefix (TREE_TYPE (t
), flags
);
609 if (TREE_CODE (t
) == OFFSET_TYPE
) /* pmfs deal with this in d_t_p */
612 output_add_space (scratch_buffer
);
613 dump_type (TYPE_OFFSET_BASETYPE (t
), flags
);
614 print_scope_operator (scratch_buffer
);
616 output_add_character (scratch_buffer
, '*');
617 padding
= dump_qualifiers (t
, none
);
620 /* Can only be reached through function pointer -- this would not be
621 correct if FUNCTION_DECLs used it. */
623 padding
= dump_type_prefix (TREE_TYPE (t
), flags
);
625 output_add_space (scratch_buffer
);
626 print_left_paren (scratch_buffer
);
631 padding
= dump_type_prefix (TREE_TYPE (t
), flags
);
633 output_add_space (scratch_buffer
);
634 print_left_paren (scratch_buffer
);
636 dump_aggr_type (TYPE_METHOD_BASETYPE (t
), flags
);
637 print_scope_operator (scratch_buffer
);
641 padding
= dump_type_prefix (TREE_TYPE (t
), flags
);
645 case IDENTIFIER_NODE
:
650 case TEMPLATE_TYPE_PARM
:
651 case TEMPLATE_TEMPLATE_PARM
:
652 case BOUND_TEMPLATE_TEMPLATE_PARM
:
663 dump_type (t
, flags
);
668 sorry_for_unsupported_tree (t
);
671 print_identifier (scratch_buffer
, "<typeprefixerror>");
677 /* Dump the suffix of type T, under control of FLAGS. This is the part
678 which appears after the identifier (or function parms). */
681 dump_type_suffix (tree t
, int flags
)
683 if (TYPE_PTRMEMFUNC_P (t
))
684 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
686 switch (TREE_CODE (t
))
691 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
692 print_right_paren (scratch_buffer
);
693 dump_type_suffix (TREE_TYPE (t
), flags
);
696 /* Can only be reached through function pointer */
701 print_right_paren (scratch_buffer
);
702 arg
= TYPE_ARG_TYPES (t
);
703 if (TREE_CODE (t
) == METHOD_TYPE
)
704 arg
= TREE_CHAIN (arg
);
706 /* Function pointers don't have default args. Not in standard C++,
707 anyway; they may in g++, but we'll just pretend otherwise. */
708 dump_parameters (arg
, flags
& ~TFF_FUNCTION_DEFAULT_ARGUMENTS
);
710 if (TREE_CODE (t
) == METHOD_TYPE
)
712 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t
))), before
);
713 dump_exception_spec (TYPE_RAISES_EXCEPTIONS (t
), flags
);
714 dump_type_suffix (TREE_TYPE (t
), flags
);
719 print_left_bracket (scratch_buffer
);
722 if (host_integerp (TYPE_MAX_VALUE (TYPE_DOMAIN (t
)), 0))
723 output_host_wide_integer
725 tree_low_cst (TYPE_MAX_VALUE (TYPE_DOMAIN (t
)), 0) + 1);
726 else if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (t
))) == MINUS_EXPR
)
727 dump_expr (TREE_OPERAND (TYPE_MAX_VALUE (TYPE_DOMAIN (t
)), 0),
728 flags
& ~TFF_EXPR_IN_PARENS
);
730 dump_expr (fold (cp_build_binary_op
731 (PLUS_EXPR
, TYPE_MAX_VALUE (TYPE_DOMAIN (t
)),
733 flags
& ~TFF_EXPR_IN_PARENS
);
735 print_right_bracket (scratch_buffer
);
736 dump_type_suffix (TREE_TYPE (t
), flags
);
740 case IDENTIFIER_NODE
:
745 case TEMPLATE_TYPE_PARM
:
746 case TEMPLATE_TEMPLATE_PARM
:
747 case BOUND_TEMPLATE_TEMPLATE_PARM
:
761 sorry_for_unsupported_tree (t
);
763 /* Don't mark it here, we should have already done in
770 dump_global_iord (tree t
)
772 const char *p
= NULL
;
774 if (DECL_GLOBAL_CTOR_P (t
))
776 else if (DECL_GLOBAL_DTOR_P (t
))
781 output_printf (scratch_buffer
, "(static %s for %s)", p
, input_filename
);
785 dump_simple_decl (tree t
, tree type
, int flags
)
787 if (flags
& TFF_DECL_SPECIFIERS
)
789 if (dump_type_prefix (type
, flags
) != none
)
790 output_add_space (scratch_buffer
);
792 if (!DECL_INITIAL (t
) || TREE_CODE (DECL_INITIAL (t
)) != TEMPLATE_PARM_INDEX
)
793 dump_scope (CP_DECL_CONTEXT (t
), flags
);
795 dump_decl (DECL_NAME (t
), flags
);
797 print_identifier (scratch_buffer
, "<anonymous>");
798 if (flags
& TFF_DECL_SPECIFIERS
)
799 dump_type_suffix (type
, flags
);
802 /* Dump a human readable string for the decl T under control of FLAGS. */
805 dump_decl (tree t
, int flags
)
810 switch (TREE_CODE (t
))
814 /* Don't say 'typedef class A' */
815 if (DECL_ARTIFICIAL (t
))
817 if ((flags
& TFF_DECL_SPECIFIERS
)
818 && TREE_CODE (TREE_TYPE (t
)) == TEMPLATE_TYPE_PARM
)
819 /* Say `class T' not just `T'. */
820 output_add_string (scratch_buffer
, "class ");
822 dump_type (TREE_TYPE (t
), flags
);
826 if (flags
& TFF_DECL_SPECIFIERS
)
827 output_add_string (scratch_buffer
, "typedef ");
828 dump_simple_decl (t
, DECL_ORIGINAL_TYPE (t
)
829 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
),
834 if (DECL_NAME (t
) && VTABLE_NAME_P (DECL_NAME (t
)))
836 output_add_string (scratch_buffer
, "vtable for ");
837 my_friendly_assert (TYPE_P (DECL_CONTEXT (t
)), 20010720);
838 dump_type (DECL_CONTEXT (t
), flags
);
841 /* else fall through */
844 dump_simple_decl (t
, TREE_TYPE (t
), flags
);
848 output_add_string (scratch_buffer
, "<return value> ");
849 dump_simple_decl (t
, TREE_TYPE (t
), flags
);
853 dump_scope (CP_DECL_CONTEXT (t
), flags
);
854 if (DECL_NAME (t
) == anonymous_namespace_name
)
855 print_identifier (scratch_buffer
, "<unnamed>");
857 print_tree_identifier (scratch_buffer
, DECL_NAME (t
));
861 dump_decl (TREE_OPERAND (t
, 0), flags
& ~TFF_DECL_SPECIFIERS
);
862 print_scope_operator (scratch_buffer
);
863 dump_decl (TREE_OPERAND (t
, 1), flags
);
867 dump_decl (TREE_OPERAND (t
, 0), flags
);
868 print_left_bracket (scratch_buffer
);
869 dump_decl (TREE_OPERAND (t
, 1), flags
);
870 print_right_bracket (scratch_buffer
);
873 /* So that we can do dump_decl on an aggr type. */
877 dump_type (t
, flags
);
881 /* This is a pseudo destructor call which has not been folded into
882 a PSEUDO_DTOR_EXPR yet. */
883 output_add_character (scratch_buffer
, '~');
884 dump_type (TREE_OPERAND (t
, 0), flags
);
891 /* These special cases are duplicated here so that other functions
892 can feed identifiers to error and get them demangled properly. */
893 case IDENTIFIER_NODE
:
894 if (IDENTIFIER_TYPENAME_P (t
))
896 output_add_string (scratch_buffer
, "operator ");
897 /* Not exactly IDENTIFIER_TYPE_VALUE. */
898 dump_type (TREE_TYPE (t
), flags
);
902 print_tree_identifier (scratch_buffer
, t
);
909 if (DECL_CLASS_SCOPE_P (t
))
911 dump_type (DECL_CONTEXT (t
), flags
);
912 output_add_string (scratch_buffer
, "::");
914 else if (DECL_CONTEXT (t
))
916 dump_decl (DECL_CONTEXT (t
), flags
);
917 output_add_string (scratch_buffer
, "::");
919 dump_decl (DECL_NAME (t
), flags
);
923 /* If there's only one function, just treat it like an ordinary
929 if (DECL_GLOBAL_CTOR_P (t
) || DECL_GLOBAL_DTOR_P (t
))
930 dump_global_iord (t
);
931 else if (! DECL_LANG_SPECIFIC (t
))
932 print_identifier (scratch_buffer
, "<internal>");
934 dump_function_decl (t
, flags
);
938 dump_template_decl (t
, flags
);
941 case TEMPLATE_ID_EXPR
:
944 tree name
= TREE_OPERAND (t
, 0);
945 if (is_overloaded_fn (name
))
946 name
= DECL_NAME (get_first_fn (name
));
947 dump_decl (name
, flags
);
948 print_template_argument_list_start (scratch_buffer
);
949 for (args
= TREE_OPERAND (t
, 1); args
; args
= TREE_CHAIN (args
))
951 dump_template_argument (TREE_VALUE (args
), flags
);
952 if (TREE_CHAIN (args
))
953 separate_with_comma (scratch_buffer
);
955 print_template_argument_list_end (scratch_buffer
);
960 dump_decl (TREE_OPERAND (t
, 0), flags
);
964 print_tree_identifier (scratch_buffer
, DECL_NAME (t
));
968 if ((TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == ENUMERAL_TYPE
)
969 || (DECL_INITIAL (t
) &&
970 TREE_CODE (DECL_INITIAL (t
)) == TEMPLATE_PARM_INDEX
))
971 dump_simple_decl (t
, TREE_TYPE (t
), flags
);
972 else if (DECL_NAME (t
))
973 dump_decl (DECL_NAME (t
), flags
);
974 else if (DECL_INITIAL (t
))
975 dump_expr (DECL_INITIAL (t
), flags
| TFF_EXPR_IN_PARENS
);
977 print_identifier (scratch_buffer
, "<enumerator>");
981 output_add_string (scratch_buffer
, "using ");
982 dump_type (DECL_INITIAL (t
), flags
);
983 print_scope_operator (scratch_buffer
);
984 dump_decl (DECL_NAME (t
), flags
);
988 dump_decl (BASELINK_FUNCTIONS (t
), flags
);
992 sorry_for_unsupported_tree (t
);
993 /* Fallthrough to error. */
996 print_identifier (scratch_buffer
, "<declaration error>");
1001 /* Dump a template declaration T under control of FLAGS. This means the
1002 'template <...> leaders plus the 'class X' or 'void fn(...)' part. */
1005 dump_template_decl (tree t
, int flags
)
1007 tree orig_parms
= DECL_TEMPLATE_PARMS (t
);
1011 if (flags
& TFF_TEMPLATE_HEADER
)
1013 for (parms
= orig_parms
= nreverse (orig_parms
);
1015 parms
= TREE_CHAIN (parms
))
1017 tree inner_parms
= INNERMOST_TEMPLATE_PARMS (parms
);
1018 int len
= TREE_VEC_LENGTH (inner_parms
);
1020 output_add_string (scratch_buffer
, "template<");
1022 /* If we've shown the template prefix, we'd better show the
1023 parameters' and decl's type too. */
1024 flags
|= TFF_DECL_SPECIFIERS
;
1026 for (i
= 0; i
< len
; i
++)
1029 separate_with_comma (scratch_buffer
);
1030 dump_template_parameter (TREE_VEC_ELT (inner_parms
, i
), flags
);
1032 print_template_argument_list_end (scratch_buffer
);
1033 output_add_space (scratch_buffer
);
1035 nreverse(orig_parms
);
1037 if (DECL_TEMPLATE_TEMPLATE_PARM_P (t
))
1038 /* Say `template<arg> class TT' not just `template<arg> TT'. */
1039 output_add_string (scratch_buffer
, "class ");
1042 if (TREE_CODE (DECL_TEMPLATE_RESULT (t
)) == TYPE_DECL
)
1043 dump_type (TREE_TYPE (t
),
1044 ((flags
& ~TFF_CLASS_KEY_OR_ENUM
) | TFF_TEMPLATE_NAME
1045 | (flags
& TFF_DECL_SPECIFIERS
? TFF_CLASS_KEY_OR_ENUM
: 0)));
1046 else if (TREE_CODE (DECL_TEMPLATE_RESULT (t
)) == VAR_DECL
)
1047 dump_decl (DECL_TEMPLATE_RESULT (t
), flags
| TFF_TEMPLATE_NAME
);
1048 else if (TREE_TYPE (t
) == NULL_TREE
)
1051 switch (NEXT_CODE (t
))
1055 dump_function_decl (t
, flags
| TFF_TEMPLATE_NAME
);
1058 /* This case can occur with some invalid code. */
1059 dump_type (TREE_TYPE (t
),
1060 (flags
& ~TFF_CLASS_KEY_OR_ENUM
) | TFF_TEMPLATE_NAME
1061 | (flags
& TFF_DECL_SPECIFIERS
? TFF_CLASS_KEY_OR_ENUM
: 0));
1065 /* Pretty print a function decl. There are several ways we want to print a
1066 function declaration. The TFF_ bits in FLAGS tells us how to behave.
1067 As error can only apply the '#' flag once to give 0 and 1 for V, there
1068 is %D which doesn't print the throw specs, and %F which does. */
1071 dump_function_decl (tree t
, int flags
)
1075 tree cname
= NULL_TREE
;
1076 tree template_args
= NULL_TREE
;
1077 tree template_parms
= NULL_TREE
;
1078 int show_return
= flags
& TFF_RETURN_TYPE
|| flags
& TFF_DECL_SPECIFIERS
;
1080 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1081 t
= DECL_TEMPLATE_RESULT (t
);
1083 /* Pretty print template instantiations only. */
1084 if (DECL_USE_TEMPLATE (t
) && DECL_TEMPLATE_INFO (t
))
1088 template_args
= DECL_TI_ARGS (t
);
1089 tmpl
= most_general_template (t
);
1090 if (tmpl
&& TREE_CODE (tmpl
) == TEMPLATE_DECL
)
1092 template_parms
= DECL_TEMPLATE_PARMS (tmpl
);
1097 fntype
= TREE_TYPE (t
);
1098 parmtypes
= FUNCTION_FIRST_USER_PARMTYPE (t
);
1100 if (DECL_CLASS_SCOPE_P (t
))
1101 cname
= DECL_CONTEXT (t
);
1102 /* this is for partially instantiated template methods */
1103 else if (TREE_CODE (fntype
) == METHOD_TYPE
)
1104 cname
= TREE_TYPE (TREE_VALUE (parmtypes
));
1106 if (!(flags
& TFF_DECL_SPECIFIERS
))
1108 else if (DECL_STATIC_FUNCTION_P (t
))
1109 print_identifier (scratch_buffer
, "static ");
1110 else if (DECL_VIRTUAL_P (t
))
1111 print_identifier (scratch_buffer
, "virtual ");
1113 /* Print the return type? */
1115 show_return
= !DECL_CONV_FN_P (t
) && !DECL_CONSTRUCTOR_P (t
)
1116 && !DECL_DESTRUCTOR_P (t
);
1119 dump_type_prefix (TREE_TYPE (fntype
), flags
);
1120 output_add_space (scratch_buffer
);
1123 /* Print the function name. */
1126 dump_type (cname
, flags
);
1127 print_scope_operator (scratch_buffer
);
1130 dump_scope (CP_DECL_CONTEXT (t
), flags
);
1132 dump_function_name (t
, flags
);
1136 dump_parameters (parmtypes
, flags
);
1138 if (TREE_CODE (fntype
) == METHOD_TYPE
)
1139 dump_qualifiers (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype
))),
1142 if (flags
& TFF_EXCEPTION_SPECIFICATION
)
1143 dump_exception_spec (TYPE_RAISES_EXCEPTIONS (fntype
), flags
);
1146 dump_type_suffix (TREE_TYPE (fntype
), flags
);
1149 /* If T is a template instantiation, dump the parameter binding. */
1150 if (template_parms
!= NULL_TREE
&& template_args
!= NULL_TREE
)
1152 output_add_string (scratch_buffer
, " [with ");
1153 dump_template_bindings (template_parms
, template_args
);
1154 print_right_bracket (scratch_buffer
);
1158 /* Print a parameter list. If this is for a member function, the
1159 member object ptr (and any other hidden args) should have
1160 already been removed. */
1163 dump_parameters (tree parmtypes
, int flags
)
1167 print_left_paren (scratch_buffer
);
1169 for (first
= 1; parmtypes
!= void_list_node
;
1170 parmtypes
= TREE_CHAIN (parmtypes
))
1173 separate_with_comma (scratch_buffer
);
1177 print_identifier (scratch_buffer
, "...");
1180 dump_type (TREE_VALUE (parmtypes
), flags
);
1182 if ((flags
& TFF_FUNCTION_DEFAULT_ARGUMENTS
) && TREE_PURPOSE (parmtypes
))
1184 output_add_string (scratch_buffer
, " = ");
1185 dump_expr (TREE_PURPOSE (parmtypes
), flags
| TFF_EXPR_IN_PARENS
);
1189 print_right_paren (scratch_buffer
);
1192 /* Print an exception specification. T is the exception specification. */
1195 dump_exception_spec (tree t
, int flags
)
1199 output_add_string (scratch_buffer
, " throw (");
1200 if (TREE_VALUE (t
) != NULL_TREE
)
1203 dump_type (TREE_VALUE (t
), flags
);
1207 separate_with_comma (scratch_buffer
);
1209 print_right_paren (scratch_buffer
);
1213 /* Handle the function name for a FUNCTION_DECL node, grokking operators
1214 and destructors properly. */
1217 dump_function_name (tree t
, int flags
)
1219 tree name
= DECL_NAME (t
);
1221 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1222 t
= DECL_TEMPLATE_RESULT (t
);
1224 /* Don't let the user see __comp_ctor et al. */
1225 if (DECL_CONSTRUCTOR_P (t
)
1226 || DECL_DESTRUCTOR_P (t
))
1227 name
= constructor_name (DECL_CONTEXT (t
));
1229 if (DECL_DESTRUCTOR_P (t
))
1231 output_add_character (scratch_buffer
, '~');
1232 dump_decl (name
, TFF_PLAIN_IDENTIFIER
);
1234 else if (DECL_CONV_FN_P (t
))
1236 /* This cannot use the hack that the operator's return
1237 type is stashed off of its name because it may be
1238 used for error reporting. In the case of conflicting
1239 declarations, both will have the same name, yet
1240 the types will be different, hence the TREE_TYPE field
1241 of the first name will be clobbered by the second. */
1242 output_add_string (scratch_buffer
, "operator ");
1243 dump_type (TREE_TYPE (TREE_TYPE (t
)), flags
);
1245 else if (IDENTIFIER_OPNAME_P (name
))
1246 print_tree_identifier (scratch_buffer
, name
);
1248 dump_decl (name
, flags
);
1250 if (DECL_LANG_SPECIFIC (t
) && DECL_TEMPLATE_INFO (t
)
1251 && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t
)
1252 && (DECL_TEMPLATE_SPECIALIZATION (t
)
1253 || TREE_CODE (DECL_TI_TEMPLATE (t
)) != TEMPLATE_DECL
1254 || DECL_TEMPLATE_SPECIALIZATION (DECL_TI_TEMPLATE (t
))
1255 || PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t
))))
1256 dump_template_parms (DECL_TEMPLATE_INFO (t
), !DECL_USE_TEMPLATE (t
), flags
);
1259 /* Dump the template parameters from the template info INFO under control of
1260 FLAGS. PRIMARY indicates whether this is a primary template decl, or
1261 specialization (partial or complete). For partial specializations we show
1262 the specialized parameter values. For a primary template we show no
1266 dump_template_parms (tree info
, int primary
, int flags
)
1268 tree args
= info
? TI_ARGS (info
) : NULL_TREE
;
1270 if (primary
&& flags
& TFF_TEMPLATE_NAME
)
1272 flags
&= ~(TFF_CLASS_KEY_OR_ENUM
| TFF_TEMPLATE_NAME
);
1273 print_template_argument_list_start (scratch_buffer
);
1275 /* Be careful only to print things when we have them, so as not
1276 to crash producing error messages. */
1277 if (args
&& !primary
)
1283 if (TREE_CODE (args
) == TREE_VEC
)
1285 if (TREE_VEC_LENGTH (args
) > 0
1286 && TREE_CODE (TREE_VEC_ELT (args
, 0)) == TREE_VEC
)
1287 args
= TREE_VEC_ELT (args
, TREE_VEC_LENGTH (args
) - 1);
1289 len
= TREE_VEC_LENGTH (args
);
1291 else if (TREE_CODE (args
) == TREE_LIST
)
1293 while (ix
!= len
&& args
)
1298 arg
= TREE_VEC_ELT (args
, ix
);
1303 arg
= TREE_VALUE (args
);
1304 args
= TREE_CHAIN (args
);
1307 separate_with_comma (scratch_buffer
);
1310 print_identifier (scratch_buffer
, "<template parameter error>");
1312 dump_template_argument (arg
, flags
);
1318 tree tpl
= TI_TEMPLATE (info
);
1319 tree parms
= DECL_TEMPLATE_PARMS (tpl
);
1322 parms
= TREE_CODE (parms
) == TREE_LIST
? TREE_VALUE (parms
) : NULL_TREE
;
1323 len
= parms
? TREE_VEC_LENGTH (parms
) : 0;
1325 for (ix
= 0; ix
!= len
; ix
++)
1327 tree parm
= TREE_VALUE (TREE_VEC_ELT (parms
, ix
));
1330 separate_with_comma (scratch_buffer
);
1332 dump_decl (parm
, flags
& ~TFF_DECL_SPECIFIERS
);
1335 print_template_argument_list_end (scratch_buffer
);
1343 case TARGET_NEWLINE
:
1344 output_add_string (scratch_buffer
, "\\n");
1347 output_add_string (scratch_buffer
, "\\t");
1350 output_add_string (scratch_buffer
, "\\v");
1353 output_add_string (scratch_buffer
, "\\b");
1356 output_add_string (scratch_buffer
, "\\r");
1359 output_add_string (scratch_buffer
, "\\f");
1362 output_add_string (scratch_buffer
, "\\a");
1365 output_add_string (scratch_buffer
, "\\\\");
1368 output_add_string (scratch_buffer
, "\\'");
1371 output_add_string (scratch_buffer
, "\\\"");
1375 output_add_character (scratch_buffer
, c
);
1377 output_formatted_scalar (scratch_buffer
, "\\%03o", (unsigned) c
);
1382 /* Print out a list of initializers (subr of dump_expr) */
1385 dump_expr_list (tree l
, int flags
)
1389 dump_expr (TREE_VALUE (l
), flags
| TFF_EXPR_IN_PARENS
);
1392 separate_with_comma (scratch_buffer
);
1396 /* Print out an expression E under control of FLAGS. */
1399 dump_expr (tree t
, int flags
)
1404 switch (TREE_CODE (t
))
1412 case NAMESPACE_DECL
:
1414 case IDENTIFIER_NODE
:
1415 dump_decl (t
, flags
& ~TFF_DECL_SPECIFIERS
);
1420 tree type
= TREE_TYPE (t
);
1421 my_friendly_assert (type
!= 0, 81);
1423 /* If it's an enum, output its tag, rather than its value. */
1424 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1426 tree values
= TYPE_VALUES (type
);
1429 values
= TREE_CHAIN (values
))
1430 if (tree_int_cst_equal (TREE_VALUE (values
), t
))
1434 print_tree_identifier (scratch_buffer
, TREE_PURPOSE (values
));
1437 /* Value must have been cast. */
1438 print_left_paren (scratch_buffer
);
1439 dump_type (type
, flags
);
1440 print_right_paren (scratch_buffer
);
1444 else if (type
== boolean_type_node
)
1446 if (t
== boolean_false_node
|| integer_zerop (t
))
1447 print_identifier (scratch_buffer
, "false");
1448 else if (t
== boolean_true_node
)
1449 print_identifier (scratch_buffer
, "true");
1451 else if (type
== char_type_node
)
1453 output_add_character (scratch_buffer
, '\'');
1454 if (host_integerp (t
, TREE_UNSIGNED (type
)))
1455 dump_char (tree_low_cst (t
, TREE_UNSIGNED (type
)));
1457 output_printf (scratch_buffer
, "\\x%x",
1458 (unsigned int) TREE_INT_CST_LOW (t
));
1459 output_add_character (scratch_buffer
, '\'');
1464 if (! host_integerp (t
, 0))
1468 if (tree_int_cst_sgn (val
) < 0)
1470 output_add_character (scratch_buffer
, '-');
1471 val
= build_int_2 (-TREE_INT_CST_LOW (val
),
1472 ~TREE_INT_CST_HIGH (val
)
1473 + !TREE_INT_CST_LOW (val
));
1475 sprintf (scratch_buffer
->digit_buffer
,
1476 HOST_WIDE_INT_PRINT_DOUBLE_HEX
,
1477 TREE_INT_CST_HIGH (val
), TREE_INT_CST_LOW (val
));
1479 (scratch_buffer
, scratch_buffer
->digit_buffer
);
1482 output_host_wide_integer (scratch_buffer
, TREE_INT_CST_LOW (t
));
1488 real_to_decimal (scratch_buffer
->digit_buffer
, &TREE_REAL_CST (t
),
1489 sizeof (scratch_buffer
->digit_buffer
), 0, 1);
1490 output_add_string (scratch_buffer
, scratch_buffer
->digit_buffer
);
1494 output_add_character (scratch_buffer
, '&');
1495 dump_type (PTRMEM_CST_CLASS (t
), flags
);
1496 print_scope_operator (scratch_buffer
);
1497 print_tree_identifier
1498 (scratch_buffer
, DECL_NAME (PTRMEM_CST_MEMBER (t
)));
1503 const char *p
= TREE_STRING_POINTER (t
);
1504 int len
= TREE_STRING_LENGTH (t
) - 1;
1507 output_add_character (scratch_buffer
, '\"');
1508 for (i
= 0; i
< len
; i
++)
1510 output_add_character (scratch_buffer
, '\"');
1515 print_left_paren (scratch_buffer
);
1516 /* Within templates, a COMPOUND_EXPR has only one operand,
1517 containing a TREE_LIST of the two operands. */
1518 if (TREE_CODE (TREE_OPERAND (t
, 0)) == TREE_LIST
)
1520 if (TREE_OPERAND (t
, 1))
1522 dump_expr_list (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
1526 dump_expr (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
1527 separate_with_comma (scratch_buffer
);
1528 dump_expr (TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
1530 print_right_paren (scratch_buffer
);
1534 print_left_paren (scratch_buffer
);
1535 dump_expr (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
1536 output_add_string (scratch_buffer
, " ? ");
1537 dump_expr (TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
1538 output_add_string (scratch_buffer
, " : ");
1539 dump_expr (TREE_OPERAND (t
, 2), flags
| TFF_EXPR_IN_PARENS
);
1540 print_right_paren (scratch_buffer
);
1544 if (TREE_HAS_CONSTRUCTOR (t
))
1546 output_add_string (scratch_buffer
, "new ");
1547 dump_type (TREE_TYPE (TREE_TYPE (t
)), flags
);
1551 dump_expr (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
1555 case AGGR_INIT_EXPR
:
1557 tree fn
= NULL_TREE
;
1559 if (TREE_CODE (TREE_OPERAND (t
, 0)) == ADDR_EXPR
)
1560 fn
= TREE_OPERAND (TREE_OPERAND (t
, 0), 0);
1562 if (fn
&& TREE_CODE (fn
) == FUNCTION_DECL
)
1564 if (DECL_CONSTRUCTOR_P (fn
))
1565 print_tree_identifier
1566 (scratch_buffer
, TYPE_IDENTIFIER (TREE_TYPE (t
)));
1571 dump_expr (TREE_OPERAND (t
, 0), 0);
1573 print_left_paren (scratch_buffer
);
1574 if (TREE_OPERAND (t
, 1))
1575 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t
, 1)), flags
);
1576 print_right_paren (scratch_buffer
);
1581 tree fn
= TREE_OPERAND (t
, 0);
1582 tree args
= TREE_OPERAND (t
, 1);
1584 if (TREE_CODE (fn
) == ADDR_EXPR
)
1585 fn
= TREE_OPERAND (fn
, 0);
1587 if (TREE_TYPE (fn
) != NULL_TREE
&& NEXT_CODE (fn
) == METHOD_TYPE
)
1589 tree ob
= TREE_VALUE (args
);
1590 if (TREE_CODE (ob
) == ADDR_EXPR
)
1592 dump_expr (TREE_OPERAND (ob
, 0), flags
| TFF_EXPR_IN_PARENS
);
1593 output_add_character (scratch_buffer
, '.');
1595 else if (TREE_CODE (ob
) != PARM_DECL
1596 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob
)), "this"))
1598 dump_expr (ob
, flags
| TFF_EXPR_IN_PARENS
);
1599 output_add_string (scratch_buffer
, "->");
1601 args
= TREE_CHAIN (args
);
1603 dump_expr (fn
, flags
| TFF_EXPR_IN_PARENS
);
1604 print_left_paren (scratch_buffer
);
1605 dump_expr_list (args
, flags
);
1606 print_right_paren (scratch_buffer
);
1612 tree type
= TREE_OPERAND (t
, 1);
1613 tree init
= TREE_OPERAND (t
, 2);
1614 if (NEW_EXPR_USE_GLOBAL (t
))
1615 print_scope_operator (scratch_buffer
);
1616 output_add_string (scratch_buffer
, "new ");
1617 if (TREE_OPERAND (t
, 0))
1619 print_left_paren (scratch_buffer
);
1620 dump_expr_list (TREE_OPERAND (t
, 0), flags
);
1621 output_add_string (scratch_buffer
, ") ");
1623 if (TREE_CODE (type
) == ARRAY_REF
)
1624 type
= build_cplus_array_type
1625 (TREE_OPERAND (type
, 0),
1626 build_index_type (fold (build (MINUS_EXPR
, integer_type_node
,
1627 TREE_OPERAND (type
, 1),
1628 integer_one_node
))));
1629 dump_type (type
, flags
);
1632 print_left_paren (scratch_buffer
);
1633 if (TREE_CODE (init
) == TREE_LIST
)
1634 dump_expr_list (init
, flags
);
1635 else if (init
== void_zero_node
)
1636 /* This representation indicates an empty initializer,
1637 e.g.: "new int()". */
1640 dump_expr (init
, flags
);
1641 print_right_paren (scratch_buffer
);
1647 /* Note that this only works for G++ target exprs. If somebody
1648 builds a general TARGET_EXPR, there's no way to represent that
1649 it initializes anything other that the parameter slot for the
1650 default argument. Note we may have cleared out the first
1651 operand in expand_expr, so don't go killing ourselves. */
1652 if (TREE_OPERAND (t
, 1))
1653 dump_expr (TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
1661 case TRUNC_DIV_EXPR
:
1662 case TRUNC_MOD_EXPR
:
1670 case BIT_ANDTC_EXPR
:
1671 case TRUTH_ANDIF_EXPR
:
1672 case TRUTH_ORIF_EXPR
:
1679 case EXACT_DIV_EXPR
:
1680 dump_binary_op (operator_name_info
[(int) TREE_CODE (t
)].name
, t
, flags
);
1684 case FLOOR_DIV_EXPR
:
1685 case ROUND_DIV_EXPR
:
1686 dump_binary_op ("/", t
, flags
);
1690 case FLOOR_MOD_EXPR
:
1691 case ROUND_MOD_EXPR
:
1692 dump_binary_op ("%", t
, flags
);
1697 tree ob
= TREE_OPERAND (t
, 0);
1698 if (TREE_CODE (ob
) == INDIRECT_REF
)
1700 ob
= TREE_OPERAND (ob
, 0);
1701 if (TREE_CODE (ob
) != PARM_DECL
1702 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob
)), "this"))
1704 dump_expr (ob
, flags
| TFF_EXPR_IN_PARENS
);
1705 output_add_string (scratch_buffer
, "->");
1710 dump_expr (ob
, flags
| TFF_EXPR_IN_PARENS
);
1711 output_add_character (scratch_buffer
, '.');
1713 dump_expr (TREE_OPERAND (t
, 1), flags
& ~TFF_EXPR_IN_PARENS
);
1718 dump_expr (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
1719 print_left_bracket (scratch_buffer
);
1720 dump_expr (TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
1721 print_right_bracket (scratch_buffer
);
1725 if (TREE_TYPE (t
) && VOID_TYPE_P (TREE_TYPE (t
)))
1727 print_left_paren (scratch_buffer
);
1728 dump_type (TREE_TYPE (t
), flags
);
1729 print_right_paren (scratch_buffer
);
1730 dump_expr (TREE_OPERAND (t
, 0), flags
);
1733 dump_unary_op ("+", t
, flags
);
1737 if (TREE_CODE (TREE_OPERAND (t
, 0)) == FUNCTION_DECL
1738 || TREE_CODE (TREE_OPERAND (t
, 0)) == STRING_CST
1739 /* An ADDR_EXPR can have reference type. In that case, we
1740 shouldn't print the `&' doing so indicates to the user
1741 that the expression has pointer type. */
1743 && TREE_CODE (TREE_TYPE (t
)) == REFERENCE_TYPE
))
1744 dump_expr (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
1746 dump_unary_op ("&", t
, flags
);
1750 if (TREE_HAS_CONSTRUCTOR (t
))
1752 t
= TREE_OPERAND (t
, 0);
1753 my_friendly_assert (TREE_CODE (t
) == CALL_EXPR
, 237);
1754 dump_expr (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
1755 print_left_paren (scratch_buffer
);
1756 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t
, 1)), flags
);
1757 print_right_paren (scratch_buffer
);
1761 if (TREE_OPERAND (t
,0) != NULL_TREE
1762 && TREE_TYPE (TREE_OPERAND (t
, 0))
1763 && NEXT_CODE (TREE_OPERAND (t
, 0)) == REFERENCE_TYPE
)
1764 dump_expr (TREE_OPERAND (t
, 0), flags
);
1766 dump_unary_op ("*", t
, flags
);
1772 case TRUTH_NOT_EXPR
:
1773 case PREDECREMENT_EXPR
:
1774 case PREINCREMENT_EXPR
:
1775 dump_unary_op (operator_name_info
[(int)TREE_CODE (t
)].name
, t
, flags
);
1778 case POSTDECREMENT_EXPR
:
1779 case POSTINCREMENT_EXPR
:
1780 print_left_paren (scratch_buffer
);
1781 dump_expr (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
1783 (scratch_buffer
, operator_name_info
[(int)TREE_CODE (t
)].name
);
1784 print_right_paren (scratch_buffer
);
1787 case NON_LVALUE_EXPR
:
1788 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
1789 should be another level of INDIRECT_REF so that I don't have to do
1791 if (TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == POINTER_TYPE
)
1793 tree next
= TREE_TYPE (TREE_TYPE (t
));
1795 while (TREE_CODE (next
) == POINTER_TYPE
)
1796 next
= TREE_TYPE (next
);
1798 if (TREE_CODE (next
) == FUNCTION_TYPE
)
1800 if (flags
& TFF_EXPR_IN_PARENS
)
1801 print_left_paren (scratch_buffer
);
1802 output_add_character (scratch_buffer
, '*');
1803 dump_expr (TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
1804 if (flags
& TFF_EXPR_IN_PARENS
)
1805 print_right_paren (scratch_buffer
);
1810 dump_expr (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
1814 dump_expr (TREE_OPERAND (t
, 0), flags
);
1817 case EXPR_WITH_FILE_LOCATION
:
1818 dump_expr (EXPR_WFL_NODE (t
), flags
);
1822 if (TREE_TYPE (t
) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t
)))
1824 tree idx
= build_ptrmemfunc_access_expr (t
, pfn_identifier
);
1826 if (integer_zerop (idx
))
1828 /* A NULL pointer-to-member constant. */
1829 output_add_string (scratch_buffer
, "((");
1830 dump_type (TREE_TYPE (t
), flags
);
1831 output_add_string (scratch_buffer
, ") 0)");
1834 else if (host_integerp (idx
, 0))
1837 unsigned HOST_WIDE_INT n
;
1839 t
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t
)));
1840 t
= TYPE_METHOD_BASETYPE (t
);
1841 virtuals
= TYPE_BINFO_VIRTUALS (TYPE_MAIN_VARIANT (t
));
1843 n
= tree_low_cst (idx
, 0);
1845 /* Map vtable index back one, to allow for the null pointer to
1849 while (n
> 0 && virtuals
)
1852 virtuals
= TREE_CHAIN (virtuals
);
1856 dump_expr (BV_FN (virtuals
),
1857 flags
| TFF_EXPR_IN_PARENS
);
1862 if (TREE_TYPE (t
) && !CONSTRUCTOR_ELTS (t
))
1864 dump_type (TREE_TYPE (t
), 0);
1865 output_add_character (scratch_buffer
, '(');
1866 output_add_character (scratch_buffer
, ')');
1870 output_add_character (scratch_buffer
, '{');
1871 dump_expr_list (CONSTRUCTOR_ELTS (t
), flags
);
1872 output_add_character (scratch_buffer
, '}');
1879 tree ob
= TREE_OPERAND (t
, 0);
1880 if (is_dummy_object (ob
))
1882 t
= TREE_OPERAND (t
, 1);
1883 if (TREE_CODE (t
) == FUNCTION_DECL
)
1885 dump_expr (t
, flags
| TFF_EXPR_IN_PARENS
);
1886 else if (BASELINK_P (t
))
1887 dump_expr (OVL_CURRENT (BASELINK_FUNCTIONS (t
)),
1888 flags
| TFF_EXPR_IN_PARENS
);
1890 dump_decl (t
, flags
);
1894 if (TREE_CODE (ob
) == INDIRECT_REF
)
1896 dump_expr (TREE_OPERAND (ob
, 0), flags
| TFF_EXPR_IN_PARENS
);
1897 output_add_string (scratch_buffer
, "->*");
1901 dump_expr (ob
, flags
| TFF_EXPR_IN_PARENS
);
1902 output_add_string (scratch_buffer
, ".*");
1904 dump_expr (TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
1909 case TEMPLATE_PARM_INDEX
:
1910 dump_decl (TEMPLATE_PARM_DECL (t
), flags
& ~TFF_DECL_SPECIFIERS
);
1914 dump_type (TREE_OPERAND (t
, 0), flags
);
1915 print_scope_operator (scratch_buffer
);
1916 dump_expr (TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
1920 if (TREE_OPERAND (t
, 0) == NULL_TREE
1921 || TREE_CHAIN (TREE_OPERAND (t
, 0)))
1923 dump_type (TREE_TYPE (t
), flags
);
1924 print_left_paren (scratch_buffer
);
1925 dump_expr_list (TREE_OPERAND (t
, 0), flags
);
1926 print_right_paren (scratch_buffer
);
1930 print_left_paren (scratch_buffer
);
1931 dump_type (TREE_TYPE (t
), flags
);
1932 output_add_string (scratch_buffer
, ")(");
1933 dump_expr_list (TREE_OPERAND (t
, 0), flags
);
1934 print_right_paren (scratch_buffer
);
1938 case STATIC_CAST_EXPR
:
1939 output_add_string (scratch_buffer
, "static_cast<");
1941 case REINTERPRET_CAST_EXPR
:
1942 output_add_string (scratch_buffer
, "reinterpret_cast<");
1944 case CONST_CAST_EXPR
:
1945 output_add_string (scratch_buffer
, "const_cast<");
1947 case DYNAMIC_CAST_EXPR
:
1948 output_add_string (scratch_buffer
, "dynamic_cast<");
1950 dump_type (TREE_TYPE (t
), flags
);
1951 output_add_string (scratch_buffer
, ">(");
1952 dump_expr (TREE_OPERAND (t
, 0), flags
);
1953 print_right_paren (scratch_buffer
);
1957 print_tree_identifier (scratch_buffer
, TREE_OPERAND (t
, 0));
1961 dump_expr (TREE_OPERAND (t
, 0), flags
);
1962 output_add_string (scratch_buffer
, "->");
1967 if (TREE_CODE (t
) == SIZEOF_EXPR
)
1968 output_add_string (scratch_buffer
, "sizeof (");
1971 my_friendly_assert (TREE_CODE (t
) == ALIGNOF_EXPR
, 0);
1972 output_add_string (scratch_buffer
, "__alignof__ (");
1974 if (TYPE_P (TREE_OPERAND (t
, 0)))
1975 dump_type (TREE_OPERAND (t
, 0), flags
);
1977 dump_expr (TREE_OPERAND (t
, 0), flags
);
1978 print_right_paren (scratch_buffer
);
1982 print_identifier (scratch_buffer
, "<unparsed>");
1985 case TRY_CATCH_EXPR
:
1986 case WITH_CLEANUP_EXPR
:
1987 case CLEANUP_POINT_EXPR
:
1988 dump_expr (TREE_OPERAND (t
, 0), flags
);
1991 case PSEUDO_DTOR_EXPR
:
1992 dump_expr (TREE_OPERAND (t
, 2), flags
);
1993 output_add_character (scratch_buffer
, '.');
1994 dump_type (TREE_OPERAND (t
, 0), flags
);
1995 output_add_string (scratch_buffer
, "::~");
1996 dump_type (TREE_OPERAND (t
, 1), flags
);
1999 case TEMPLATE_ID_EXPR
:
2000 dump_decl (t
, flags
);
2004 /* We don't yet have a way of dumping statements in a
2005 human-readable format. */
2006 output_add_string (scratch_buffer
, "({...})");
2010 output_add_character (scratch_buffer
, '{');
2011 dump_expr (TREE_OPERAND (t
, 1), flags
& ~TFF_EXPR_IN_PARENS
);
2012 output_add_character (scratch_buffer
, '}');
2016 output_add_string (scratch_buffer
, "while (1) { ");
2017 dump_expr (TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2018 output_add_character (scratch_buffer
, '}');
2022 output_add_string (scratch_buffer
, "if (");
2023 dump_expr (TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2024 output_add_string (scratch_buffer
, ") break; ");
2028 dump_expr (get_first_fn (t
), flags
& ~TFF_EXPR_IN_PARENS
);
2031 /* else fall through */
2033 /* This list is incomplete, but should suffice for now.
2034 It is very important that `sorry' does not call
2035 `report_error_function'. That could cause an infinite loop. */
2037 sorry_for_unsupported_tree (t
);
2038 /* fall through to ERROR_MARK... */
2040 print_identifier (scratch_buffer
, "<expression error>");
2046 dump_binary_op (const char *opstring
, tree t
, int flags
)
2048 print_left_paren (scratch_buffer
);
2049 dump_expr (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2050 output_add_space (scratch_buffer
);
2052 print_identifier (scratch_buffer
, opstring
);
2054 print_identifier (scratch_buffer
, "<unknown operator>");
2055 output_add_space (scratch_buffer
);
2056 dump_expr (TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2057 print_right_paren (scratch_buffer
);
2061 dump_unary_op (const char *opstring
, tree t
, int flags
)
2063 if (flags
& TFF_EXPR_IN_PARENS
)
2064 print_left_paren (scratch_buffer
);
2065 print_identifier (scratch_buffer
, opstring
);
2066 dump_expr (TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2067 if (flags
& TFF_EXPR_IN_PARENS
)
2068 print_right_paren (scratch_buffer
);
2071 /* Exported interface to stringifying types, exprs and decls under TFF_*
2075 type_as_string (tree typ
, int flags
)
2077 reinit_global_formatting_buffer ();
2079 dump_type (typ
, flags
);
2081 return output_finalize_message (scratch_buffer
);
2085 expr_as_string (tree decl
, int flags
)
2087 reinit_global_formatting_buffer ();
2089 dump_expr (decl
, flags
);
2091 return output_finalize_message (scratch_buffer
);
2095 decl_as_string (tree decl
, int flags
)
2097 reinit_global_formatting_buffer ();
2099 dump_decl (decl
, flags
);
2101 return output_finalize_message (scratch_buffer
);
2105 context_as_string (tree context
, int flags
)
2107 reinit_global_formatting_buffer ();
2109 dump_scope (context
, flags
);
2111 return output_finalize_message (scratch_buffer
);
2114 /* Generate the three forms of printable names for cxx_printable_name. */
2117 lang_decl_name (tree decl
, int v
)
2120 return decl_as_string (decl
, TFF_DECL_SPECIFIERS
);
2122 reinit_global_formatting_buffer ();
2124 if (v
== 1 && DECL_CLASS_SCOPE_P (decl
))
2126 dump_type (CP_DECL_CONTEXT (decl
), TFF_PLAIN_IDENTIFIER
);
2127 print_scope_operator (scratch_buffer
);
2130 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2131 dump_function_name (decl
, TFF_PLAIN_IDENTIFIER
);
2133 dump_decl (DECL_NAME (decl
), TFF_PLAIN_IDENTIFIER
);
2135 return output_finalize_message (scratch_buffer
);
2139 location_of (tree t
)
2141 if (TREE_CODE (t
) == PARM_DECL
&& DECL_CONTEXT (t
))
2142 t
= DECL_CONTEXT (t
);
2143 else if (TYPE_P (t
))
2144 t
= TYPE_MAIN_DECL (t
);
2145 else if (TREE_CODE (t
) == OVERLOAD
)
2146 t
= OVL_FUNCTION (t
);
2148 return DECL_SOURCE_LOCATION (t
);
2151 /* Now the interfaces from error et al to dump_type et al. Each takes an
2152 on/off VERBOSE flag and supply the appropriate TFF_ flags to a dump_
2156 decl_to_string (tree decl
, int verbose
)
2160 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == RECORD_TYPE
2161 || TREE_CODE (decl
) == UNION_TYPE
|| TREE_CODE (decl
) == ENUMERAL_TYPE
)
2162 flags
= TFF_CLASS_KEY_OR_ENUM
;
2164 flags
|= TFF_DECL_SPECIFIERS
| TFF_FUNCTION_DEFAULT_ARGUMENTS
;
2165 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
2166 flags
|= TFF_DECL_SPECIFIERS
| TFF_RETURN_TYPE
;
2167 flags
|= TFF_TEMPLATE_HEADER
;
2169 reinit_global_formatting_buffer ();
2171 dump_decl (decl
, flags
);
2173 return output_finalize_message (scratch_buffer
);
2177 expr_to_string (tree decl
)
2179 reinit_global_formatting_buffer ();
2181 dump_expr (decl
, 0);
2183 return output_finalize_message (scratch_buffer
);
2187 fndecl_to_string (tree fndecl
, int verbose
)
2191 flags
= TFF_EXCEPTION_SPECIFICATION
| TFF_DECL_SPECIFIERS
;
2193 flags
|= TFF_FUNCTION_DEFAULT_ARGUMENTS
;
2194 reinit_global_formatting_buffer ();
2196 dump_decl (fndecl
, flags
);
2198 return output_finalize_message (scratch_buffer
);
2203 code_to_string (enum tree_code c
)
2205 return tree_code_name
[c
];
2209 language_to_string (enum languages c
)
2216 case lang_cplusplus
:
2228 /* Return the proper printed version of a parameter to a C++ function. */
2231 parm_to_string (int p
)
2233 reinit_global_formatting_buffer ();
2236 output_add_string (scratch_buffer
, "'this'");
2238 output_decimal (scratch_buffer
, p
+ 1);
2240 return output_finalize_message (scratch_buffer
);
2244 op_to_string (enum tree_code p
)
2248 id
= operator_name_info
[(int) p
].identifier
;
2249 return id
? IDENTIFIER_POINTER (id
) : "<unknown>";
2253 type_to_string (tree typ
, int verbose
)
2259 flags
|= TFF_CLASS_KEY_OR_ENUM
;
2260 flags
|= TFF_TEMPLATE_HEADER
;
2262 reinit_global_formatting_buffer ();
2264 dump_type (typ
, flags
);
2266 return output_finalize_message (scratch_buffer
);
2270 assop_to_string (enum tree_code p
)
2274 id
= assignment_operator_name_info
[(int) p
].identifier
;
2275 return id
? IDENTIFIER_POINTER (id
) : "{unknown}";
2279 args_to_string (tree p
, int verbose
)
2283 flags
|= TFF_CLASS_KEY_OR_ENUM
;
2288 if (TYPE_P (TREE_VALUE (p
)))
2289 return type_as_string (p
, flags
);
2291 reinit_global_formatting_buffer ();
2292 for (; p
; p
= TREE_CHAIN (p
))
2294 if (TREE_VALUE (p
) == null_node
)
2295 print_identifier (scratch_buffer
, "NULL");
2297 dump_type (error_type (TREE_VALUE (p
)), flags
);
2299 separate_with_comma (scratch_buffer
);
2301 return output_finalize_message (scratch_buffer
);
2305 cv_to_string (tree p
, int v
)
2307 reinit_global_formatting_buffer ();
2309 dump_qualifiers (p
, v
? before
: none
);
2311 return output_finalize_message (scratch_buffer
);
2314 /* Langhook for print_error_function. */
2316 cxx_print_error_function (diagnostic_context
*context
, const char *file
)
2318 lhd_print_error_function (context
, file
);
2319 output_set_prefix (&context
->buffer
, file
);
2320 maybe_print_instantiation_context (context
);
2324 cp_diagnostic_starter (diagnostic_context
*context
,
2325 diagnostic_info
*diagnostic
)
2327 diagnostic_report_current_module (context
);
2328 cp_print_error_function (context
, diagnostic
);
2329 maybe_print_instantiation_context (context
);
2330 output_set_prefix (&context
->buffer
, diagnostic_build_prefix (diagnostic
));
2334 cp_diagnostic_finalizer (diagnostic_context
*context
,
2335 diagnostic_info
*diagnostic ATTRIBUTE_UNUSED
)
2337 output_destroy_prefix (&context
->buffer
);
2340 /* Print current function onto BUFFER, in the process of reporting
2341 a diagnostic message. Called from cp_diagnostic_starter. */
2343 cp_print_error_function (diagnostic_context
*context
,
2344 diagnostic_info
*diagnostic
)
2346 if (diagnostic_last_function_changed (context
))
2348 const char *old_prefix
= output_prefix (&context
->buffer
);
2349 char *new_prefix
= diagnostic
->location
.file
2350 ? file_name_as_prefix (diagnostic
->location
.file
)
2353 output_set_prefix (&context
->buffer
, new_prefix
);
2355 if (current_function_decl
== NULL
)
2356 output_add_string (&context
->buffer
, "At global scope:");
2358 output_printf (&context
->buffer
, "In %s `%s':",
2359 function_category (current_function_decl
),
2360 cxx_printable_name (current_function_decl
, 2));
2361 output_add_newline (&context
->buffer
);
2363 diagnostic_set_last_function (context
);
2364 output_destroy_prefix (&context
->buffer
);
2365 context
->buffer
.state
.prefix
= old_prefix
;
2369 /* Returns a description of FUNCTION using standard terminology. */
2371 function_category (tree fn
)
2373 if (DECL_FUNCTION_MEMBER_P (fn
))
2375 if (DECL_STATIC_FUNCTION_P (fn
))
2376 return "static member function";
2377 else if (DECL_COPY_CONSTRUCTOR_P (fn
))
2378 return "copy constructor";
2379 else if (DECL_CONSTRUCTOR_P (fn
))
2380 return "constructor";
2381 else if (DECL_DESTRUCTOR_P (fn
))
2382 return "destructor";
2384 return "member function";
2390 /* Report the full context of a current template instantiation,
2393 print_instantiation_full_context (diagnostic_context
*context
)
2395 tree p
= current_instantiation ();
2396 location_t location
= input_location
;
2400 if (current_function_decl
!= TINST_DECL (p
)
2401 && current_function_decl
!= NULL_TREE
)
2402 /* We can get here during the processing of some synthesized
2403 method. Then, TINST_DECL (p) will be the function that's causing
2408 if (current_function_decl
== TINST_DECL (p
))
2409 /* Avoid redundancy with the the "In function" line. */;
2411 output_verbatim (&context
->buffer
,
2412 "%s: In instantiation of `%s':\n", location
.file
,
2413 decl_as_string (TINST_DECL (p
),
2414 TFF_DECL_SPECIFIERS
| TFF_RETURN_TYPE
));
2416 location
.line
= TINST_LINE (p
);
2417 location
.file
= TINST_FILE (p
);
2422 print_instantiation_partial_context (context
, p
, location
);
2425 /* Same as above but less verbose. */
2427 print_instantiation_partial_context (diagnostic_context
*context
,
2428 tree t
, location_t loc
)
2430 for (; t
; t
= TREE_CHAIN (t
))
2433 (&context
->buffer
, "%s:%d: instantiated from `%s'\n",
2435 decl_as_string (TINST_DECL (t
),
2436 TFF_DECL_SPECIFIERS
| TFF_RETURN_TYPE
));
2437 loc
.line
= TINST_LINE (t
);
2438 loc
.file
= TINST_FILE (t
);
2440 output_verbatim (&context
->buffer
, "%s:%d: instantiated from here\n",
2441 loc
.file
, loc
.line
);
2444 /* Called from cp_thing to print the template context for an error. */
2446 maybe_print_instantiation_context (diagnostic_context
*context
)
2448 if (!problematic_instantiation_changed () || current_instantiation () == 0)
2451 record_last_problematic_instantiation ();
2452 print_instantiation_full_context (context
);
2455 /* Report the bare minimum context of a template instantiation. */
2457 print_instantiation_context (void)
2459 print_instantiation_partial_context
2460 (global_dc
, current_instantiation (), input_location
);
2461 diagnostic_flush_buffer (global_dc
);
2464 /* Called from output_format -- during diagnostic message processing --
2465 to handle C++ specific format specifier with the following meanings:
2466 %A function argument-list.
2470 %F function declaration.
2471 %L language as used in extern "lang".
2473 %P function parameter whose position is indicated by an integer.
2474 %Q assignment operator.
2478 cp_printer (output_buffer
*buffer
, text_info
*text
)
2482 #define next_tree va_arg (*text->args_ptr, tree)
2483 #define next_tcode va_arg (*text->args_ptr, enum tree_code)
2484 #define next_lang va_arg (*text->args_ptr, enum languages)
2485 #define next_int va_arg (*text->args_ptr, int)
2487 if (*text
->format_spec
== '+')
2488 ++text
->format_spec
;
2489 if (*text
->format_spec
== '#')
2492 ++text
->format_spec
;
2495 switch (*text
->format_spec
)
2497 case 'A': result
= args_to_string (next_tree
, verbose
); break;
2498 case 'C': result
= code_to_string (next_tcode
); break;
2499 case 'D': result
= decl_to_string (next_tree
, verbose
); break;
2500 case 'E': result
= expr_to_string (next_tree
); break;
2501 case 'F': result
= fndecl_to_string (next_tree
, verbose
); break;
2502 case 'L': result
= language_to_string (next_lang
); break;
2503 case 'O': result
= op_to_string (next_tcode
); break;
2504 case 'P': result
= parm_to_string (next_int
); break;
2505 case 'Q': result
= assop_to_string (next_tcode
); break;
2506 case 'T': result
= type_to_string (next_tree
, verbose
); break;
2507 case 'V': result
= cv_to_string (next_tree
, verbose
); break;
2513 output_add_string (buffer
, result
);
2522 print_non_consecutive_character (output_buffer
*buffer
, int c
)
2524 const char *p
= output_last_position (buffer
);
2526 if (p
!= NULL
&& *p
== c
)
2527 output_add_space (buffer
);
2528 output_add_character (buffer
, c
);
2531 /* These are temporary wrapper functions which handle the historic
2532 behavior of cp_*_at. */
2535 locate_error (const char *msgid
, va_list ap
)
2541 for (f
= msgid
; *f
; f
++)
2554 /* Just ignore these possibilities. */
2557 case 'd': (void) va_arg (ap
, int); break;
2558 case 's': (void) va_arg (ap
, char *); break;
2559 case 'L': (void) va_arg (ap
, enum languages
); break;
2562 case 'Q': (void) va_arg (ap
, enum tree_code
); break;
2564 /* These take a tree, which may be where the error is
2572 t
= va_arg (ap
, tree
);
2578 errorcount
= 0; /* damn ICE suppression */
2579 internal_error ("unexpected letter `%c' in locate_error\n", *f
);
2585 here
= va_arg (ap
, tree
);
2592 cp_error_at (const char *msgid
, ...)
2595 diagnostic_info diagnostic
;
2598 va_start (ap
, msgid
);
2599 here
= locate_error (msgid
, ap
);
2602 va_start (ap
, msgid
);
2603 diagnostic_set_info (&diagnostic
, msgid
, &ap
,
2604 location_of (here
), DK_ERROR
);
2605 report_diagnostic (&diagnostic
);
2610 cp_warning_at (const char *msgid
, ...)
2613 diagnostic_info diagnostic
;
2616 va_start (ap
, msgid
);
2617 here
= locate_error (msgid
, ap
);
2620 va_start (ap
, msgid
);
2621 diagnostic_set_info (&diagnostic
, msgid
, &ap
,
2622 location_of (here
), DK_WARNING
);
2623 report_diagnostic (&diagnostic
);
2628 cp_pedwarn_at (const char *msgid
, ...)
2631 diagnostic_info diagnostic
;
2634 va_start (ap
, msgid
);
2635 here
= locate_error (msgid
, ap
);
2638 va_start (ap
, msgid
);
2639 diagnostic_set_info (&diagnostic
, msgid
, &ap
,
2640 location_of (here
), pedantic_error_kind());
2641 report_diagnostic (&diagnostic
);