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 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC 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 GNU CC 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 GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
30 #include "diagnostic.h"
32 enum pad { none, before, after };
34 #define sorry_for_unsupported_tree(T) \
35 sorry ("`%s' not supported by %s", tree_code_name[(int) TREE_CODE (T)], \
38 #define print_scope_operator(BUFFER) output_add_string ((BUFFER), "::")
39 #define print_left_paren(BUFFER) output_add_character ((BUFFER), '(')
40 #define print_right_paren(BUFFER) output_add_character ((BUFFER), ')')
41 #define print_left_bracket(BUFFER) output_add_character ((BUFFER), '[')
42 #define print_right_bracket(BUFFER) output_add_character ((BUFFER), ']')
43 #define print_template_argument_list_start(BUFFER) \
44 print_non_consecutive_character ((BUFFER), '<')
45 #define print_template_argument_list_end(BUFFER) \
46 print_non_consecutive_character ((BUFFER), '>')
47 #define print_whitespace(BUFFER, TFI) \
49 output_add_space (BUFFER); \
50 put_whitespace (TFI) = none; \
52 #define print_tree_identifier(BUFFER, TID) \
53 output_add_string ((BUFFER), IDENTIFIER_POINTER (TID))
54 #define print_identifier(BUFFER, ID) output_add_string ((BUFFER), (ID))
55 #define separate_with_comma(BUFFER) output_add_string ((BUFFER), ", ")
57 /* The global buffer where we dump everything. It is there only for
58 transitional purpose. It is expected, in the near future, to be
59 completely removed. */
60 static output_buffer scratch_buffer_rec;
61 static output_buffer *scratch_buffer = &scratch_buffer_rec;
63 # define NEXT_CODE(T) (TREE_CODE (TREE_TYPE (T)))
65 #define reinit_global_formatting_buffer() \
66 output_clear_message_text (scratch_buffer)
68 static const char *args_to_string PARAMS ((tree, int));
69 static const char *assop_to_string PARAMS ((enum tree_code, int));
70 static const char *code_to_string PARAMS ((enum tree_code, int));
71 static const char *cv_to_string PARAMS ((tree, int));
72 static const char *decl_to_string PARAMS ((tree, int));
73 static const char *expr_to_string PARAMS ((tree, int));
74 static const char *fndecl_to_string PARAMS ((tree, int));
75 static const char *op_to_string PARAMS ((enum tree_code, int));
76 static const char *parm_to_string PARAMS ((int, int));
77 static const char *type_to_string PARAMS ((tree, int));
79 static void dump_type PARAMS ((tree, int));
80 static void dump_typename PARAMS ((tree, int));
81 static void dump_simple_decl PARAMS ((tree, tree, int));
82 static void dump_decl PARAMS ((tree, int));
83 static void dump_template_decl PARAMS ((tree, int));
84 static void dump_function_decl PARAMS ((tree, int));
85 static void dump_expr PARAMS ((tree, int));
86 static void dump_unary_op PARAMS ((const char *, tree, int));
87 static void dump_binary_op PARAMS ((const char *, tree, int));
88 static void dump_aggr_type PARAMS ((tree, int));
89 static enum pad dump_type_prefix PARAMS ((tree, int));
90 static void dump_type_suffix PARAMS ((tree, int));
91 static void dump_function_name PARAMS ((tree, int));
92 static void dump_expr_list PARAMS ((tree, int));
93 static void dump_global_iord PARAMS ((tree));
94 static enum pad dump_qualifiers PARAMS ((tree, enum pad));
95 static void dump_char PARAMS ((int));
96 static void dump_parameters PARAMS ((tree, int));
97 static void dump_exception_spec PARAMS ((tree, int));
98 static const char *class_key_or_enum PARAMS ((tree));
99 static void dump_template_argument PARAMS ((tree, int));
100 static void dump_template_argument_list PARAMS ((tree, int));
101 static void dump_template_parameter PARAMS ((tree, int));
102 static void dump_template_bindings PARAMS ((tree, tree));
103 static void dump_scope PARAMS ((tree, int));
104 static void dump_template_parms PARAMS ((tree, int, int));
106 static const char *function_category PARAMS ((tree));
107 static void lang_print_error_function PARAMS ((diagnostic_context *,
109 static void maybe_print_instantiation_context PARAMS ((output_buffer *));
110 static void print_instantiation_full_context PARAMS ((output_buffer *));
111 static void print_instantiation_partial_context PARAMS ((output_buffer *, tree,
113 static void cp_diagnostic_starter PARAMS ((output_buffer *,
114 diagnostic_context *));
115 static void cp_diagnostic_finalizer PARAMS ((output_buffer *,
116 diagnostic_context *));
117 static void cp_print_error_function PARAMS ((output_buffer *,
118 diagnostic_context *));
120 static int cp_printer PARAMS ((output_buffer *));
121 static void print_non_consecutive_character PARAMS ((output_buffer *, int));
122 static void print_integer PARAMS ((output_buffer *, HOST_WIDE_INT));
123 static tree locate_error PARAMS ((const char *, va_list));
128 print_error_function = lang_print_error_function;
129 diagnostic_starter (global_dc) = cp_diagnostic_starter;
130 diagnostic_finalizer (global_dc) = cp_diagnostic_finalizer;
131 diagnostic_format_decoder (global_dc) = cp_printer;
133 init_output_buffer (scratch_buffer, /* prefix */NULL, /* line-width */0);
136 /* Dump a scope, if deemed necessary. */
139 dump_scope (scope, flags)
143 int f = ~TFF_RETURN_TYPE & (TFF_DECL_SPECIFIERS
144 | (flags & (TFF_SCOPE | TFF_CHASE_TYPEDEF)));
146 if (scope == NULL_TREE)
149 if (TREE_CODE (scope) == NAMESPACE_DECL)
151 if (scope != global_namespace)
153 dump_decl (scope, f);
154 print_scope_operator (scratch_buffer);
157 else if (AGGREGATE_TYPE_P (scope))
159 dump_type (scope, f);
160 print_scope_operator (scratch_buffer);
162 else if ((flags & TFF_SCOPE) && TREE_CODE (scope) == FUNCTION_DECL)
164 dump_function_decl (scope, f);
165 print_scope_operator (scratch_buffer);
169 /* Dump type qualifiers, providing padding as requested. Return an
170 indication of whether we dumped something. */
173 dump_qualifiers (t, p)
177 static const int masks[] =
178 {TYPE_QUAL_CONST, TYPE_QUAL_VOLATILE, TYPE_QUAL_RESTRICT};
179 static const char *const names[] =
180 {"const", "volatile", "__restrict"};
182 int quals = TYPE_QUALS (t);
183 int do_after = p == after;
187 for (ix = 0; ix != 3; ix++)
188 if (masks[ix] & quals)
191 output_add_space (scratch_buffer);
193 print_identifier (scratch_buffer, names[ix]);
196 output_add_space (scratch_buffer);
203 /* This must be large enough to hold any printed integer or floating-point
205 static char digit_buffer[128];
207 /* Dump the template ARGument under control of FLAGS. */
210 dump_template_argument (arg, flags)
214 if (TYPE_P (arg) || TREE_CODE (arg) == TEMPLATE_DECL)
215 dump_type (arg, flags & ~TFF_CLASS_KEY_OR_ENUM);
217 dump_expr (arg, (flags | TFF_EXPR_IN_PARENS) & ~TFF_CLASS_KEY_OR_ENUM);
220 /* Dump a template-argument-list ARGS (always a TREE_VEC) under control
224 dump_template_argument_list (args, flags)
228 int n = TREE_VEC_LENGTH (args);
232 for (i = 0; i< n; ++i)
235 separate_with_comma (scratch_buffer);
236 dump_template_argument (TREE_VEC_ELT (args, i), flags);
241 /* Dump a template parameter PARM (a TREE_LIST) under control of FLAGS. */
244 dump_template_parameter (parm, flags)
248 tree p = TREE_VALUE (parm);
249 tree a = TREE_PURPOSE (parm);
251 if (TREE_CODE (p) == TYPE_DECL)
253 if (flags & TFF_DECL_SPECIFIERS)
255 print_identifier (scratch_buffer, "class");
258 output_add_space (scratch_buffer);
259 print_tree_identifier (scratch_buffer, DECL_NAME (p));
262 else if (DECL_NAME (p))
263 print_tree_identifier (scratch_buffer, DECL_NAME (p));
265 print_identifier (scratch_buffer, "{template default argument error}");
268 dump_decl (p, flags | TFF_DECL_SPECIFIERS);
270 if ((flags & TFF_FUNCTION_DEFAULT_ARGUMENTS) && a != NULL_TREE)
272 output_add_string (scratch_buffer, " = ");
273 if (TREE_CODE (p) == TYPE_DECL || TREE_CODE (p) == TEMPLATE_DECL)
274 dump_type (a, flags & ~TFF_CHASE_TYPEDEF);
276 dump_expr (a, flags | TFF_EXPR_IN_PARENS);
280 /* Dump, under control of FLAGS, a template-parameter-list binding.
281 PARMS is a TREE_LIST of TREE_VEC of TREE_LIST and ARGS is a
285 dump_template_bindings (parms, args)
292 tree p = TREE_VALUE (parms);
293 int lvl = TMPL_PARMS_DEPTH (parms);
297 for (i = 0; i < TREE_VEC_LENGTH (p); ++i)
299 tree arg = NULL_TREE;
301 /* Don't crash if we had an invalid argument list. */
302 if (TMPL_ARGS_DEPTH (args) >= lvl)
304 tree lvl_args = TMPL_ARGS_LEVEL (args, lvl);
305 if (NUM_TMPL_ARGS (lvl_args) > arg_idx)
306 arg = TREE_VEC_ELT (lvl_args, arg_idx);
310 separate_with_comma (scratch_buffer);
311 dump_template_parameter (TREE_VEC_ELT (p, i), TFF_PLAIN_IDENTIFIER);
312 output_add_string (scratch_buffer, " = ");
314 dump_template_argument (arg, TFF_PLAIN_IDENTIFIER);
316 print_identifier (scratch_buffer, "<missing>");
322 parms = TREE_CHAIN (parms);
326 /* Dump into the obstack a human-readable equivalent of TYPE. FLAGS
327 controls the format. */
337 if (TYPE_PTRMEMFUNC_P (t))
340 switch (TREE_CODE (t))
343 print_identifier (scratch_buffer, "<unknown type>");
347 /* A list of function parms. */
348 dump_parameters (t, flags);
351 case IDENTIFIER_NODE:
352 print_tree_identifier (scratch_buffer, t);
356 dump_type (BINFO_TYPE (t), flags);
362 dump_aggr_type (t, flags);
366 if (flags & TFF_CHASE_TYPEDEF)
368 dump_type (DECL_ORIGINAL_TYPE (t)
369 ? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t), flags);
372 /* else fallthrough */
376 dump_decl (t, flags & ~TFF_DECL_SPECIFIERS);
380 output_add_string (scratch_buffer, "__complex__ ");
381 dump_type (TREE_TYPE (t), flags);
385 output_add_string (scratch_buffer, "vector ");
386 dump_type (TREE_TYPE (t), flags);
390 if (!TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)) && TREE_UNSIGNED (t))
391 output_add_string (scratch_buffer, "unsigned ");
392 else if (TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)) && !TREE_UNSIGNED (t))
393 output_add_string (scratch_buffer, "signed ");
401 dump_qualifiers (t, after);
402 type = flags & TFF_CHASE_TYPEDEF ? TYPE_MAIN_VARIANT (t) : t;
403 if (TYPE_NAME (type) && TYPE_IDENTIFIER (type))
404 print_tree_identifier (scratch_buffer, TYPE_IDENTIFIER (type));
406 /* Types like intQI_type_node and friends have no names.
407 These don't come up in user error messages, but it's nice
408 to be able to print them from the debugger. */
409 print_identifier (scratch_buffer, "<anonymous>");
413 case TEMPLATE_TEMPLATE_PARM:
414 /* For parameters inside template signature. */
415 if (TYPE_IDENTIFIER (t))
416 print_tree_identifier (scratch_buffer, TYPE_IDENTIFIER (t));
419 (scratch_buffer, "<anonymous template template parameter>");
422 case BOUND_TEMPLATE_TEMPLATE_PARM:
424 tree args = TYPE_TI_ARGS (t);
425 print_tree_identifier (scratch_buffer, TYPE_IDENTIFIER (t));
426 print_template_argument_list_start (scratch_buffer);
427 dump_template_argument_list (args, flags);
428 print_template_argument_list_end (scratch_buffer);
432 case TEMPLATE_TYPE_PARM:
433 dump_qualifiers (t, after);
434 if (TYPE_IDENTIFIER (t))
435 print_tree_identifier (scratch_buffer, TYPE_IDENTIFIER (t));
438 (scratch_buffer, "<anonymous template type parameter>");
441 /* This is not always necessary for pointers and such, but doing this
442 reduces code size. */
451 dump_type_prefix (t, flags);
452 dump_type_suffix (t, flags);
456 output_add_string (scratch_buffer, "typename ");
457 dump_typename (t, flags);
460 case UNBOUND_CLASS_TEMPLATE:
461 dump_type (TYPE_CONTEXT (t), flags);
462 print_scope_operator (scratch_buffer);
463 print_identifier (scratch_buffer, "template ");
464 dump_type (DECL_NAME (TYPE_NAME (t)), flags);
468 output_add_string (scratch_buffer, "__typeof (");
469 dump_expr (TYPE_FIELDS (t), flags & ~TFF_EXPR_IN_PARENS);
470 print_left_paren (scratch_buffer);
474 sorry_for_unsupported_tree (t);
475 /* Fall through to error. */
478 print_identifier (scratch_buffer, "<type error>");
483 /* Dump a TYPENAME_TYPE. We need to notice when the context is itself
487 dump_typename (t, flags)
491 tree ctx = TYPE_CONTEXT (t);
493 if (TREE_CODE (ctx) == TYPENAME_TYPE)
494 dump_typename (ctx, flags);
496 dump_type (ctx, flags & ~TFF_CLASS_KEY_OR_ENUM);
497 print_scope_operator (scratch_buffer);
498 dump_decl (TYPENAME_TYPE_FULLNAME (t), flags);
501 /* Return the name of the supplied aggregate, or enumeral type. */
504 class_key_or_enum (t)
507 if (TREE_CODE (t) == ENUMERAL_TYPE)
509 else if (TREE_CODE (t) == UNION_TYPE)
511 else if (TYPE_LANG_SPECIFIC (t) && CLASSTYPE_DECLARED_CLASS (t))
517 /* Print out a class declaration T under the control of FLAGS,
518 in the form `class foo'. */
521 dump_aggr_type (t, flags)
526 const char *variety = class_key_or_enum (t);
530 dump_qualifiers (t, after);
532 if (flags & TFF_CLASS_KEY_OR_ENUM)
534 print_identifier (scratch_buffer, variety);
535 output_add_space (scratch_buffer);
538 if (flags & TFF_CHASE_TYPEDEF)
539 t = TYPE_MAIN_VARIANT (t);
541 name = TYPE_NAME (t);
545 typdef = !DECL_ARTIFICIAL (name);
546 tmplate = !typdef && TREE_CODE (t) != ENUMERAL_TYPE
547 && TYPE_LANG_SPECIFIC (t) && CLASSTYPE_TEMPLATE_INFO (t)
548 && (CLASSTYPE_TEMPLATE_SPECIALIZATION (t)
549 || TREE_CODE (CLASSTYPE_TI_TEMPLATE (t)) != TEMPLATE_DECL
550 || DECL_TEMPLATE_SPECIALIZATION (CLASSTYPE_TI_TEMPLATE (t))
551 || PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t)));
552 dump_scope (CP_DECL_CONTEXT (name), flags | TFF_SCOPE);
555 /* Because the template names are mangled, we have to locate
556 the most general template, and use that name. */
557 tree tpl = CLASSTYPE_TI_TEMPLATE (t);
559 while (DECL_TEMPLATE_INFO (tpl))
560 tpl = DECL_TI_TEMPLATE (tpl);
563 name = DECL_NAME (name);
566 if (name == 0 || ANON_AGGRNAME_P (name))
568 if (flags & TFF_CLASS_KEY_OR_ENUM)
569 print_identifier (scratch_buffer, "<anonymous>");
571 output_printf (scratch_buffer, "<anonymous %s>", variety);
574 print_tree_identifier (scratch_buffer, name);
576 dump_template_parms (TYPE_TEMPLATE_INFO (t),
577 !CLASSTYPE_USE_TEMPLATE (t),
578 flags & ~TFF_TEMPLATE_HEADER);
581 /* Dump into the obstack the initial part of the output for a given type.
582 This is necessary when dealing with things like functions returning
585 return type of `int (* fee ())()': pointer -> function -> int. Both
586 pointer (and reference and offset) and function (and member) types must
587 deal with prefix and suffix.
589 Arrays must also do this for DECL nodes, like int a[], and for things like
592 Return indicates how you should pad an object name after this. I.e. you
593 want to pad non-*, non-& cores, but not pad * or & types. */
596 dump_type_prefix (t, flags)
600 enum pad padding = before;
602 if (TYPE_PTRMEMFUNC_P (t))
604 t = TYPE_PTRMEMFUNC_FN_TYPE (t);
608 switch (TREE_CODE (t))
613 tree sub = TREE_TYPE (t);
615 padding = dump_type_prefix (sub, flags);
616 /* A tree for a member pointer looks like pointer to offset,
617 so let the OFFSET_TYPE case handle it. */
618 if (!TYPE_PTRMEM_P (t))
620 if (TREE_CODE (sub) == ARRAY_TYPE)
622 output_add_space (scratch_buffer);
623 print_left_paren (scratch_buffer);
626 (scratch_buffer, "&*"[TREE_CODE (t) == POINTER_TYPE]);
627 padding = dump_qualifiers (t, before);
634 padding = dump_type_prefix (TREE_TYPE (t), flags);
635 if (TREE_CODE (t) == OFFSET_TYPE) /* pmfs deal with this in d_t_p */
638 output_add_space (scratch_buffer);
639 dump_type (TYPE_OFFSET_BASETYPE (t), flags);
640 print_scope_operator (scratch_buffer);
642 output_add_character (scratch_buffer, '*');
643 padding = dump_qualifiers (t, none);
646 /* Can only be reached through function pointer -- this would not be
647 correct if FUNCTION_DECLs used it. */
649 padding = dump_type_prefix (TREE_TYPE (t), flags);
651 output_add_space (scratch_buffer);
652 print_left_paren (scratch_buffer);
657 padding = dump_type_prefix (TREE_TYPE (t), flags);
659 output_add_space (scratch_buffer);
660 print_left_paren (scratch_buffer);
662 dump_aggr_type (TYPE_METHOD_BASETYPE (t), flags);
663 print_scope_operator (scratch_buffer);
667 padding = dump_type_prefix (TREE_TYPE (t), flags);
671 case IDENTIFIER_NODE:
676 case TEMPLATE_TYPE_PARM:
677 case TEMPLATE_TEMPLATE_PARM:
678 case BOUND_TEMPLATE_TEMPLATE_PARM:
688 dump_type (t, flags);
693 sorry_for_unsupported_tree (t);
696 print_identifier (scratch_buffer, "<typeprefixerror>");
702 /* Dump the suffix of type T, under control of FLAGS. This is the part
703 which appears after the identifier (or function parms). */
706 dump_type_suffix (t, flags)
710 if (TYPE_PTRMEMFUNC_P (t))
711 t = TYPE_PTRMEMFUNC_FN_TYPE (t);
713 switch (TREE_CODE (t))
718 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
719 print_right_paren (scratch_buffer);
720 dump_type_suffix (TREE_TYPE (t), flags);
723 /* Can only be reached through function pointer */
728 print_right_paren (scratch_buffer);
729 arg = TYPE_ARG_TYPES (t);
730 if (TREE_CODE (t) == METHOD_TYPE)
731 arg = TREE_CHAIN (arg);
733 /* Function pointers don't have default args. Not in standard C++,
734 anyway; they may in g++, but we'll just pretend otherwise. */
735 dump_parameters (arg, flags & ~TFF_FUNCTION_DEFAULT_ARGUMENTS);
737 if (TREE_CODE (t) == METHOD_TYPE)
739 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t))), before);
740 dump_exception_spec (TYPE_RAISES_EXCEPTIONS (t), flags);
741 dump_type_suffix (TREE_TYPE (t), flags);
746 print_left_bracket (scratch_buffer);
749 if (host_integerp (TYPE_MAX_VALUE (TYPE_DOMAIN (t)), 0))
752 tree_low_cst (TYPE_MAX_VALUE (TYPE_DOMAIN (t)), 0) + 1);
753 else if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (t))) == MINUS_EXPR)
754 dump_expr (TREE_OPERAND (TYPE_MAX_VALUE (TYPE_DOMAIN (t)), 0),
755 flags & ~TFF_EXPR_IN_PARENS);
757 dump_expr (fold (cp_build_binary_op
758 (PLUS_EXPR, TYPE_MAX_VALUE (TYPE_DOMAIN (t)),
760 flags & ~TFF_EXPR_IN_PARENS);
762 print_right_bracket (scratch_buffer);
763 dump_type_suffix (TREE_TYPE (t), flags);
767 case IDENTIFIER_NODE:
772 case TEMPLATE_TYPE_PARM:
773 case TEMPLATE_TEMPLATE_PARM:
774 case BOUND_TEMPLATE_TEMPLATE_PARM:
787 sorry_for_unsupported_tree (t);
789 /* Don't mark it here, we should have already done in
799 const char *p = NULL;
801 if (DECL_GLOBAL_CTOR_P (t))
803 else if (DECL_GLOBAL_DTOR_P (t))
808 output_printf (scratch_buffer, "(static %s for %s)", p, input_filename);
812 dump_simple_decl (t, type, flags)
817 if (flags & TFF_DECL_SPECIFIERS)
819 if (dump_type_prefix (type, flags) != none)
820 output_add_space (scratch_buffer);
822 if (!DECL_INITIAL (t) || TREE_CODE (DECL_INITIAL (t)) != TEMPLATE_PARM_INDEX)
823 dump_scope (CP_DECL_CONTEXT (t), flags);
825 dump_decl (DECL_NAME (t), flags);
827 print_identifier (scratch_buffer, "<anonymous>");
828 if (flags & TFF_DECL_SPECIFIERS)
829 dump_type_suffix (type, flags);
832 /* Dump a human readable string for the decl T under control of FLAGS. */
842 switch (TREE_CODE (t))
846 /* Don't say 'typedef class A' */
847 if (DECL_ARTIFICIAL (t))
849 if ((flags & TFF_DECL_SPECIFIERS)
850 && TREE_CODE (TREE_TYPE (t)) == TEMPLATE_TYPE_PARM)
851 /* Say `class T' not just `T'. */
852 output_add_string (scratch_buffer, "class ");
854 dump_type (TREE_TYPE (t), flags);
858 if (flags & TFF_DECL_SPECIFIERS)
859 output_add_string (scratch_buffer, "typedef ");
860 dump_simple_decl (t, DECL_ORIGINAL_TYPE (t)
861 ? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t),
866 if (DECL_NAME (t) && VTABLE_NAME_P (DECL_NAME (t)))
868 output_add_string (scratch_buffer, "vtable for ");
869 my_friendly_assert (TYPE_P (DECL_CONTEXT (t)), 20010720);
870 dump_type (DECL_CONTEXT (t), flags);
873 /* else fall through */
876 dump_simple_decl (t, TREE_TYPE (t), flags);
880 output_add_string (scratch_buffer, "<return value> ");
881 dump_simple_decl (t, TREE_TYPE (t), flags);
885 dump_scope (CP_DECL_CONTEXT (t), flags);
886 if (DECL_NAME (t) == anonymous_namespace_name)
887 print_identifier (scratch_buffer, "<unnamed>");
889 print_tree_identifier (scratch_buffer, DECL_NAME (t));
893 dump_decl (TREE_OPERAND (t, 0), flags & ~TFF_DECL_SPECIFIERS);
894 print_scope_operator (scratch_buffer);
895 dump_decl (TREE_OPERAND (t, 1), flags);
899 dump_decl (TREE_OPERAND (t, 0), flags);
900 print_left_bracket (scratch_buffer);
901 dump_decl (TREE_OPERAND (t, 1), flags);
902 print_right_bracket (scratch_buffer);
905 /* So that we can do dump_decl on an aggr type. */
909 dump_type (t, flags);
916 /* These special cases are duplicated here so that other functions
917 can feed identifiers to error and get them demangled properly. */
918 case IDENTIFIER_NODE:
919 if (IDENTIFIER_TYPENAME_P (t))
921 output_add_string (scratch_buffer, "operator ");
922 /* Not exactly IDENTIFIER_TYPE_VALUE. */
923 dump_type (TREE_TYPE (t), flags);
927 print_tree_identifier (scratch_buffer, t);
935 if (DECL_GLOBAL_CTOR_P (t) || DECL_GLOBAL_DTOR_P (t))
936 dump_global_iord (t);
937 else if (! DECL_LANG_SPECIFIC (t))
938 print_identifier (scratch_buffer, "<internal>");
940 dump_function_decl (t, flags);
944 dump_template_decl (t, flags);
947 case TEMPLATE_ID_EXPR:
950 tree name = TREE_OPERAND (t, 0);
951 if (is_overloaded_fn (name))
952 name = DECL_NAME (get_first_fn (name));
953 dump_decl (name, flags);
954 print_template_argument_list_start (scratch_buffer);
955 for (args = TREE_OPERAND (t, 1); args; args = TREE_CHAIN (args))
957 dump_template_argument (TREE_VALUE (args), flags);
958 if (TREE_CHAIN (args))
959 separate_with_comma (scratch_buffer);
961 print_template_argument_list_end (scratch_buffer);
966 dump_decl (TREE_OPERAND (t, 0), flags);
970 print_tree_identifier (scratch_buffer, DECL_NAME (t));
974 if ((TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == ENUMERAL_TYPE)
975 || (DECL_INITIAL (t) &&
976 TREE_CODE (DECL_INITIAL (t)) == TEMPLATE_PARM_INDEX))
977 dump_simple_decl (t, TREE_TYPE (t), flags);
978 else if (DECL_NAME (t))
979 dump_decl (DECL_NAME (t), flags);
980 else if (DECL_INITIAL (t))
981 dump_expr (DECL_INITIAL (t), flags | TFF_EXPR_IN_PARENS);
983 print_identifier (scratch_buffer, "enumerator");
987 output_add_string (scratch_buffer, "using ");
988 dump_type (DECL_INITIAL (t), flags);
989 print_scope_operator (scratch_buffer);
990 print_tree_identifier (scratch_buffer, DECL_NAME (t));
994 sorry_for_unsupported_tree (t);
995 /* Fallthrough to error. */
998 print_identifier (scratch_buffer, "<declaration error>");
1003 /* Dump a template declaration T under control of FLAGS. This means the
1004 'template <...> leaders plus the 'class X' or 'void fn(...)' part. */
1007 dump_template_decl (t, flags)
1011 tree orig_parms = DECL_TEMPLATE_PARMS (t);
1015 if (flags & TFF_TEMPLATE_HEADER)
1017 for (parms = orig_parms = nreverse (orig_parms);
1019 parms = TREE_CHAIN (parms))
1021 tree inner_parms = INNERMOST_TEMPLATE_PARMS (parms);
1022 int len = TREE_VEC_LENGTH (inner_parms);
1024 output_add_string (scratch_buffer, "template<");
1026 /* If we've shown the template prefix, we'd better show the
1027 parameters' and decl's type too. */
1028 flags |= TFF_DECL_SPECIFIERS;
1030 for (i = 0; i < len; i++)
1033 separate_with_comma (scratch_buffer);
1034 dump_template_parameter (TREE_VEC_ELT (inner_parms, i), flags);
1036 print_template_argument_list_end (scratch_buffer);
1037 output_add_space (scratch_buffer);
1039 nreverse(orig_parms);
1041 if (DECL_TEMPLATE_TEMPLATE_PARM_P (t))
1042 /* Say `template<arg> class TT' not just `template<arg> TT'. */
1043 output_add_string (scratch_buffer, "class ");
1046 if (TREE_CODE (DECL_TEMPLATE_RESULT (t)) == TYPE_DECL)
1047 dump_type (TREE_TYPE (t),
1048 ((flags & ~TFF_CLASS_KEY_OR_ENUM) | TFF_TEMPLATE_NAME
1049 | (flags & TFF_DECL_SPECIFIERS ? TFF_CLASS_KEY_OR_ENUM : 0)));
1050 else if (TREE_CODE (DECL_TEMPLATE_RESULT (t)) == VAR_DECL)
1051 dump_decl (DECL_TEMPLATE_RESULT (t), flags | TFF_TEMPLATE_NAME);
1052 else if (TREE_TYPE (t) == NULL_TREE)
1055 switch (NEXT_CODE (t))
1059 dump_function_decl (t, flags | TFF_TEMPLATE_NAME);
1062 /* This case can occur with some illegal code. */
1063 dump_type (TREE_TYPE (t),
1064 (flags & ~TFF_CLASS_KEY_OR_ENUM) | TFF_TEMPLATE_NAME
1065 | (flags & TFF_DECL_SPECIFIERS ? TFF_CLASS_KEY_OR_ENUM : 0));
1069 /* Pretty print a function decl. There are several ways we want to print a
1070 function declaration. The TFF_ bits in FLAGS tells us how to behave.
1071 As error can only apply the '#' flag once to give 0 and 1 for V, there
1072 is %D which doesn't print the throw specs, and %F which does. */
1075 dump_function_decl (t, flags)
1081 tree cname = NULL_TREE;
1082 tree template_args = NULL_TREE;
1083 tree template_parms = NULL_TREE;
1084 int show_return = flags & TFF_RETURN_TYPE || flags & TFF_DECL_SPECIFIERS;
1086 if (TREE_CODE (t) == TEMPLATE_DECL)
1087 t = DECL_TEMPLATE_RESULT (t);
1089 /* Pretty print template instantiations only. */
1090 if (DECL_USE_TEMPLATE (t) && DECL_TEMPLATE_INFO (t))
1094 template_args = DECL_TI_ARGS (t);
1095 tmpl = most_general_template (t);
1096 if (tmpl && TREE_CODE (tmpl) == TEMPLATE_DECL)
1098 template_parms = DECL_TEMPLATE_PARMS (tmpl);
1103 fntype = TREE_TYPE (t);
1104 parmtypes = FUNCTION_FIRST_USER_PARMTYPE (t);
1106 if (DECL_CLASS_SCOPE_P (t))
1107 cname = DECL_CONTEXT (t);
1108 /* this is for partially instantiated template methods */
1109 else if (TREE_CODE (fntype) == METHOD_TYPE)
1110 cname = TREE_TYPE (TREE_VALUE (parmtypes));
1112 if (!(flags & TFF_DECL_SPECIFIERS))
1114 else if (DECL_STATIC_FUNCTION_P (t))
1115 print_identifier (scratch_buffer, "static ");
1116 else if (DECL_VIRTUAL_P (t))
1117 print_identifier (scratch_buffer, "virtual ");
1119 /* Print the return type? */
1121 show_return = !DECL_CONV_FN_P (t) && !DECL_CONSTRUCTOR_P (t)
1122 && !DECL_DESTRUCTOR_P (t);
1125 dump_type_prefix (TREE_TYPE (fntype), flags);
1126 output_add_space (scratch_buffer);
1129 /* Print the function name. */
1132 dump_type (cname, flags);
1133 print_scope_operator (scratch_buffer);
1136 dump_scope (CP_DECL_CONTEXT (t), flags);
1138 dump_function_name (t, flags);
1140 if (flags & TFF_DECL_SPECIFIERS)
1142 dump_parameters (parmtypes, flags);
1144 if (TREE_CODE (fntype) == METHOD_TYPE)
1145 dump_qualifiers (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype))),
1148 if (flags & TFF_EXCEPTION_SPECIFICATION)
1149 dump_exception_spec (TYPE_RAISES_EXCEPTIONS (fntype), flags);
1152 dump_type_suffix (TREE_TYPE (fntype), flags);
1155 /* If T is a template instantiation, dump the parameter binding. */
1156 if (template_parms != NULL_TREE && template_args != NULL_TREE)
1158 output_add_string (scratch_buffer, " [with ");
1159 dump_template_bindings (template_parms, template_args);
1160 print_right_bracket (scratch_buffer);
1164 /* Print a parameter list. If this is for a member function, the
1165 member object ptr (and any other hidden args) should have
1166 already been removed. */
1169 dump_parameters (parmtypes, flags)
1175 print_left_paren (scratch_buffer);
1177 for (first = 1; parmtypes != void_list_node;
1178 parmtypes = TREE_CHAIN (parmtypes))
1181 separate_with_comma (scratch_buffer);
1185 print_identifier (scratch_buffer, "...");
1188 dump_type (TREE_VALUE (parmtypes), flags);
1190 if ((flags & TFF_FUNCTION_DEFAULT_ARGUMENTS) && TREE_PURPOSE (parmtypes))
1192 output_add_string (scratch_buffer, " = ");
1193 dump_expr (TREE_PURPOSE (parmtypes), flags | TFF_EXPR_IN_PARENS);
1197 print_right_paren (scratch_buffer);
1200 /* Print an exception specification. T is the exception specification. */
1203 dump_exception_spec (t, flags)
1209 output_add_string (scratch_buffer, " throw (");
1210 if (TREE_VALUE (t) != NULL_TREE)
1213 dump_type (TREE_VALUE (t), flags);
1217 separate_with_comma (scratch_buffer);
1219 print_right_paren (scratch_buffer);
1223 /* Handle the function name for a FUNCTION_DECL node, grokking operators
1224 and destructors properly. */
1227 dump_function_name (t, flags)
1231 tree name = DECL_NAME (t);
1233 /* Don't let the user see __comp_ctor et al. */
1234 if (DECL_CONSTRUCTOR_P (t)
1235 || DECL_DESTRUCTOR_P (t))
1236 name = constructor_name (DECL_CONTEXT (t));
1238 if (DECL_DESTRUCTOR_P (t))
1240 output_add_character (scratch_buffer, '~');
1241 dump_decl (name, TFF_PLAIN_IDENTIFIER);
1243 else if (DECL_CONV_FN_P (t))
1245 /* This cannot use the hack that the operator's return
1246 type is stashed off of its name because it may be
1247 used for error reporting. In the case of conflicting
1248 declarations, both will have the same name, yet
1249 the types will be different, hence the TREE_TYPE field
1250 of the first name will be clobbered by the second. */
1251 output_add_string (scratch_buffer, "operator ");
1252 dump_type (TREE_TYPE (TREE_TYPE (t)), flags);
1254 else if (IDENTIFIER_OPNAME_P (name))
1255 print_tree_identifier (scratch_buffer, name);
1257 dump_decl (name, flags);
1259 if (DECL_LANG_SPECIFIC (t) && DECL_TEMPLATE_INFO (t)
1260 && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t)
1261 && (DECL_TEMPLATE_SPECIALIZATION (t)
1262 || TREE_CODE (DECL_TI_TEMPLATE (t)) != TEMPLATE_DECL
1263 || DECL_TEMPLATE_SPECIALIZATION (DECL_TI_TEMPLATE (t))
1264 || PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t))))
1265 dump_template_parms (DECL_TEMPLATE_INFO (t), !DECL_USE_TEMPLATE (t), flags);
1268 /* Dump the template parameters from the template info INFO under control of
1269 FLAGS. PRIMARY indicates whether this is a primary template decl, or
1270 specialization (partial or complete). For partial specializations we show
1271 the specialized parameter values. For a primary template we show no
1275 dump_template_parms (info, primary, flags)
1280 tree args = info ? TI_ARGS (info) : NULL_TREE;
1282 if (primary && flags & TFF_TEMPLATE_NAME)
1284 flags &= ~(TFF_CLASS_KEY_OR_ENUM | TFF_TEMPLATE_NAME);
1285 print_template_argument_list_start (scratch_buffer);
1287 /* Be careful only to print things when we have them, so as not
1288 to crash producing error messages. */
1289 if (args && !primary)
1295 if (TREE_CODE (args) == TREE_VEC)
1297 if (TREE_VEC_LENGTH (args) > 0
1298 && TREE_CODE (TREE_VEC_ELT (args, 0)) == TREE_VEC)
1299 args = TREE_VEC_ELT (args, TREE_VEC_LENGTH (args) - 1);
1301 len = TREE_VEC_LENGTH (args);
1303 else if (TREE_CODE (args) == TREE_LIST)
1305 while (ix != len && args)
1310 arg = TREE_VEC_ELT (args, ix);
1315 arg = TREE_VALUE (args);
1316 args = TREE_CHAIN (args);
1319 separate_with_comma (scratch_buffer);
1322 print_identifier (scratch_buffer, "<template parameter error>");
1324 dump_template_argument (arg, flags);
1330 tree tpl = TI_TEMPLATE (info);
1331 tree parms = DECL_TEMPLATE_PARMS (tpl);
1334 parms = TREE_CODE (parms) == TREE_LIST ? TREE_VALUE (parms) : NULL_TREE;
1335 len = parms ? TREE_VEC_LENGTH (parms) : 0;
1337 for (ix = 0; ix != len; ix++)
1339 tree parm = TREE_VALUE (TREE_VEC_ELT (parms, ix));
1342 separate_with_comma (scratch_buffer);
1344 dump_decl (parm, flags & ~TFF_DECL_SPECIFIERS);
1347 print_template_argument_list_end (scratch_buffer);
1356 case TARGET_NEWLINE:
1357 output_add_string (scratch_buffer, "\\n");
1360 output_add_string (scratch_buffer, "\\t");
1363 output_add_string (scratch_buffer, "\\v");
1366 output_add_string (scratch_buffer, "\\b");
1369 output_add_string (scratch_buffer, "\\r");
1372 output_add_string (scratch_buffer, "\\f");
1375 output_add_string (scratch_buffer, "\\a");
1378 output_add_string (scratch_buffer, "\\\\");
1381 output_add_string (scratch_buffer, "\\'");
1384 output_add_string (scratch_buffer, "\\\"");
1388 output_add_character (scratch_buffer, c);
1391 sprintf (digit_buffer, "\\%03o", (int) c);
1392 output_add_string (scratch_buffer, digit_buffer);
1397 /* Print out a list of initializers (subr of dump_expr) */
1400 dump_expr_list (l, flags)
1406 dump_expr (TREE_VALUE (l), flags | TFF_EXPR_IN_PARENS);
1409 separate_with_comma (scratch_buffer);
1413 /* Print out an expression E under control of FLAGS. */
1416 dump_expr (t, flags)
1420 switch (TREE_CODE (t))
1428 case NAMESPACE_DECL:
1430 dump_decl (t, flags & ~TFF_DECL_SPECIFIERS);
1435 tree type = TREE_TYPE (t);
1436 my_friendly_assert (type != 0, 81);
1438 /* If it's an enum, output its tag, rather than its value. */
1439 if (TREE_CODE (type) == ENUMERAL_TYPE)
1441 tree values = TYPE_VALUES (type);
1444 values = TREE_CHAIN (values))
1445 if (tree_int_cst_equal (TREE_VALUE (values), t))
1449 print_tree_identifier (scratch_buffer, TREE_PURPOSE (values));
1452 /* Value must have been cast. */
1453 print_left_paren (scratch_buffer);
1454 dump_type (type, flags);
1455 print_right_paren (scratch_buffer);
1459 else if (type == boolean_type_node)
1461 if (t == boolean_false_node || integer_zerop (t))
1462 print_identifier (scratch_buffer, "false");
1463 else if (t == boolean_true_node)
1464 print_identifier (scratch_buffer, "true");
1466 else if (type == char_type_node)
1468 output_add_character (scratch_buffer, '\'');
1469 dump_char (tree_low_cst (t, 0));
1470 output_add_character (scratch_buffer, '\'');
1475 if (! host_integerp (t, 0))
1479 if (tree_int_cst_sgn (val) < 0)
1481 output_add_character (scratch_buffer, '-');
1482 val = build_int_2 (-TREE_INT_CST_LOW (val),
1483 ~TREE_INT_CST_HIGH (val)
1484 + !TREE_INT_CST_LOW (val));
1486 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
1489 static char format[10]; /* "%x%09999x\0" */
1491 sprintf (format, "%%x%%0%dx", HOST_BITS_PER_INT / 4);
1492 sprintf (digit_buffer, format, TREE_INT_CST_HIGH (val),
1493 TREE_INT_CST_LOW (val));
1494 output_add_string (scratch_buffer, digit_buffer);
1498 print_integer (scratch_buffer, TREE_INT_CST_LOW (t));
1504 #ifndef REAL_IS_NOT_DOUBLE
1505 sprintf (digit_buffer, "%g", TREE_REAL_CST (t));
1508 const unsigned char *p = (const unsigned char *) &TREE_REAL_CST (t);
1510 strcpy (digit_buffer, "0x");
1511 for (i = 0; i < sizeof TREE_REAL_CST (t); i++)
1512 sprintf (digit_buffer + 2 + 2*i, "%02x", *p++);
1515 output_add_string (scratch_buffer, digit_buffer);
1519 output_add_character (scratch_buffer, '&');
1520 dump_type (PTRMEM_CST_CLASS (t), flags);
1521 print_scope_operator (scratch_buffer);
1522 print_tree_identifier
1523 (scratch_buffer, DECL_NAME (PTRMEM_CST_MEMBER (t)));
1528 const char *p = TREE_STRING_POINTER (t);
1529 int len = TREE_STRING_LENGTH (t) - 1;
1532 output_add_character (scratch_buffer, '\"');
1533 for (i = 0; i < len; i++)
1535 output_add_character (scratch_buffer, '\"');
1540 print_left_paren (scratch_buffer);
1541 dump_expr (TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
1542 separate_with_comma (scratch_buffer);
1543 dump_expr (TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS);
1544 print_right_paren (scratch_buffer);
1548 print_left_paren (scratch_buffer);
1549 dump_expr (TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
1550 output_add_string (scratch_buffer, " ? ");
1551 dump_expr (TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS);
1552 output_add_string (scratch_buffer, " : ");
1553 dump_expr (TREE_OPERAND (t, 2), flags | TFF_EXPR_IN_PARENS);
1554 print_right_paren (scratch_buffer);
1558 if (TREE_HAS_CONSTRUCTOR (t))
1560 output_add_string (scratch_buffer, "new ");
1561 dump_type (TREE_TYPE (TREE_TYPE (t)), flags);
1565 dump_expr (TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
1569 case AGGR_INIT_EXPR:
1571 tree fn = NULL_TREE;
1573 if (TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR)
1574 fn = TREE_OPERAND (TREE_OPERAND (t, 0), 0);
1576 if (fn && TREE_CODE (fn) == FUNCTION_DECL)
1578 if (DECL_CONSTRUCTOR_P (fn))
1579 print_tree_identifier
1580 (scratch_buffer, TYPE_IDENTIFIER (TREE_TYPE (t)));
1585 dump_expr (TREE_OPERAND (t, 0), 0);
1587 print_left_paren (scratch_buffer);
1588 if (TREE_OPERAND (t, 1))
1589 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)), flags);
1590 print_right_paren (scratch_buffer);
1595 tree fn = TREE_OPERAND (t, 0);
1596 tree args = TREE_OPERAND (t, 1);
1598 if (TREE_CODE (fn) == ADDR_EXPR)
1599 fn = TREE_OPERAND (fn, 0);
1601 if (TREE_TYPE (fn) != NULL_TREE && NEXT_CODE (fn) == METHOD_TYPE)
1603 tree ob = TREE_VALUE (args);
1604 if (TREE_CODE (ob) == ADDR_EXPR)
1606 dump_expr (TREE_OPERAND (ob, 0), flags | TFF_EXPR_IN_PARENS);
1607 output_add_character (scratch_buffer, '.');
1609 else if (TREE_CODE (ob) != PARM_DECL
1610 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
1612 dump_expr (ob, flags | TFF_EXPR_IN_PARENS);
1613 output_add_string (scratch_buffer, "->");
1615 args = TREE_CHAIN (args);
1617 dump_expr (fn, flags | TFF_EXPR_IN_PARENS);
1618 print_left_paren (scratch_buffer);
1619 dump_expr_list (args, flags);
1620 print_right_paren (scratch_buffer);
1626 tree type = TREE_OPERAND (t, 1);
1627 if (NEW_EXPR_USE_GLOBAL (t))
1628 print_scope_operator (scratch_buffer);
1629 output_add_string (scratch_buffer, "new ");
1630 if (TREE_OPERAND (t, 0))
1632 print_left_paren (scratch_buffer);
1633 dump_expr_list (TREE_OPERAND (t, 0), flags);
1634 output_add_string (scratch_buffer, ") ");
1636 if (TREE_CODE (type) == ARRAY_REF)
1637 type = build_cplus_array_type
1638 (TREE_OPERAND (type, 0),
1639 build_index_type (fold (build (MINUS_EXPR, integer_type_node,
1640 TREE_OPERAND (type, 1),
1641 integer_one_node))));
1642 dump_type (type, flags);
1643 if (TREE_OPERAND (t, 2))
1645 print_left_paren (scratch_buffer);
1646 dump_expr_list (TREE_OPERAND (t, 2), flags);
1647 print_right_paren (scratch_buffer);
1653 /* Note that this only works for G++ target exprs. If somebody
1654 builds a general TARGET_EXPR, there's no way to represent that
1655 it initializes anything other that the parameter slot for the
1656 default argument. Note we may have cleared out the first
1657 operand in expand_expr, so don't go killing ourselves. */
1658 if (TREE_OPERAND (t, 1))
1659 dump_expr (TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS);
1667 case TRUNC_DIV_EXPR:
1668 case TRUNC_MOD_EXPR:
1676 case BIT_ANDTC_EXPR:
1677 case TRUTH_ANDIF_EXPR:
1678 case TRUTH_ORIF_EXPR:
1685 case EXACT_DIV_EXPR:
1686 dump_binary_op (operator_name_info[(int) TREE_CODE (t)].name, t, flags);
1690 case FLOOR_DIV_EXPR:
1691 case ROUND_DIV_EXPR:
1692 dump_binary_op ("/", t, flags);
1696 case FLOOR_MOD_EXPR:
1697 case ROUND_MOD_EXPR:
1698 dump_binary_op ("%", t, flags);
1703 tree ob = TREE_OPERAND (t, 0);
1704 if (TREE_CODE (ob) == INDIRECT_REF)
1706 ob = TREE_OPERAND (ob, 0);
1707 if (TREE_CODE (ob) != PARM_DECL
1708 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
1710 dump_expr (ob, flags | TFF_EXPR_IN_PARENS);
1711 output_add_string (scratch_buffer, "->");
1716 dump_expr (ob, flags | TFF_EXPR_IN_PARENS);
1717 output_add_character (scratch_buffer, '.');
1719 dump_expr (TREE_OPERAND (t, 1), flags & ~TFF_EXPR_IN_PARENS);
1724 dump_expr (TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
1725 print_left_bracket (scratch_buffer);
1726 dump_expr (TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS);
1727 print_right_bracket (scratch_buffer);
1731 if (VOID_TYPE_P (TREE_TYPE (t)))
1733 print_left_paren (scratch_buffer);
1734 dump_type (TREE_TYPE (t), flags);
1735 print_right_paren (scratch_buffer);
1736 dump_expr (TREE_OPERAND (t, 0), flags);
1739 dump_unary_op ("+", t, flags);
1743 if (TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
1744 || TREE_CODE (TREE_OPERAND (t, 0)) == STRING_CST
1745 /* An ADDR_EXPR can have reference type. In that case, we
1746 shouldn't print the `&' doing so indicates to the user
1747 that the expression has pointer type. */
1749 && TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE))
1750 dump_expr (TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
1752 dump_unary_op ("&", t, flags);
1756 if (TREE_HAS_CONSTRUCTOR (t))
1758 t = TREE_OPERAND (t, 0);
1759 my_friendly_assert (TREE_CODE (t) == CALL_EXPR, 237);
1760 dump_expr (TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
1761 print_left_paren (scratch_buffer);
1762 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)), flags);
1763 print_right_paren (scratch_buffer);
1767 if (TREE_OPERAND (t,0) != NULL_TREE
1768 && TREE_TYPE (TREE_OPERAND (t, 0))
1769 && NEXT_CODE (TREE_OPERAND (t, 0)) == REFERENCE_TYPE)
1770 dump_expr (TREE_OPERAND (t, 0), flags);
1772 dump_unary_op ("*", t, flags);
1778 case TRUTH_NOT_EXPR:
1779 case PREDECREMENT_EXPR:
1780 case PREINCREMENT_EXPR:
1781 dump_unary_op (operator_name_info [(int)TREE_CODE (t)].name, t, flags);
1784 case POSTDECREMENT_EXPR:
1785 case POSTINCREMENT_EXPR:
1786 print_left_paren (scratch_buffer);
1787 dump_expr (TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
1789 (scratch_buffer, operator_name_info[(int)TREE_CODE (t)].name);
1790 print_right_paren (scratch_buffer);
1793 case NON_LVALUE_EXPR:
1794 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
1795 should be another level of INDIRECT_REF so that I don't have to do
1797 if (TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == POINTER_TYPE)
1799 tree next = TREE_TYPE (TREE_TYPE (t));
1801 while (TREE_CODE (next) == POINTER_TYPE)
1802 next = TREE_TYPE (next);
1804 if (TREE_CODE (next) == FUNCTION_TYPE)
1806 if (flags & TFF_EXPR_IN_PARENS)
1807 print_left_paren (scratch_buffer);
1808 output_add_character (scratch_buffer, '*');
1809 dump_expr (TREE_OPERAND (t, 0), flags & ~TFF_EXPR_IN_PARENS);
1810 if (flags & TFF_EXPR_IN_PARENS)
1811 print_right_paren (scratch_buffer);
1816 dump_expr (TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
1820 dump_expr (TREE_OPERAND (t, 0), flags);
1823 case EXPR_WITH_FILE_LOCATION:
1824 dump_expr (EXPR_WFL_NODE (t), flags);
1828 if (TREE_TYPE (t) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t)))
1830 tree idx = build_component_ref (t, pfn_identifier, NULL_TREE, 0);
1832 if (integer_zerop (idx))
1834 /* A NULL pointer-to-member constant. */
1835 output_add_string (scratch_buffer, "((");
1836 dump_type (TREE_TYPE (t), flags);
1837 output_add_string (scratch_buffer, ") 0)");
1840 else if (host_integerp (idx, 0))
1843 unsigned HOST_WIDE_INT n;
1845 t = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t)));
1846 t = TYPE_METHOD_BASETYPE (t);
1847 virtuals = TYPE_BINFO_VIRTUALS (TYPE_MAIN_VARIANT (t));
1849 n = tree_low_cst (idx, 0);
1851 /* Map vtable index back one, to allow for the null pointer to
1855 while (n > 0 && virtuals)
1858 virtuals = TREE_CHAIN (virtuals);
1862 dump_expr (BV_FN (virtuals),
1863 flags | TFF_EXPR_IN_PARENS);
1868 output_add_character (scratch_buffer, '{');
1869 dump_expr_list (CONSTRUCTOR_ELTS (t), flags);
1870 output_add_character (scratch_buffer, '}');
1875 tree ob = TREE_OPERAND (t, 0);
1876 if (is_dummy_object (ob))
1878 t = TREE_OPERAND (t, 1);
1879 if (TREE_CODE (t) == FUNCTION_DECL)
1881 dump_expr (t, flags | TFF_EXPR_IN_PARENS);
1882 else if (BASELINK_P (t))
1883 dump_expr (OVL_CURRENT (TREE_VALUE (t)), flags | TFF_EXPR_IN_PARENS);
1885 dump_decl (t, flags);
1889 if (TREE_CODE (ob) == INDIRECT_REF)
1891 dump_expr (TREE_OPERAND (ob, 0), flags | TFF_EXPR_IN_PARENS);
1892 output_add_string (scratch_buffer, "->*");
1896 dump_expr (ob, flags | TFF_EXPR_IN_PARENS);
1897 output_add_string (scratch_buffer, ".*");
1899 dump_expr (TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS);
1904 case TEMPLATE_PARM_INDEX:
1905 dump_decl (TEMPLATE_PARM_DECL (t), flags & ~TFF_DECL_SPECIFIERS);
1908 case IDENTIFIER_NODE:
1909 print_tree_identifier (scratch_buffer, t);
1913 dump_type (TREE_OPERAND (t, 0), flags);
1914 print_scope_operator (scratch_buffer);
1915 dump_expr (TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS);
1919 if (TREE_OPERAND (t, 0) == NULL_TREE
1920 || TREE_CHAIN (TREE_OPERAND (t, 0)))
1922 dump_type (TREE_TYPE (t), flags);
1923 print_left_paren (scratch_buffer);
1924 dump_expr_list (TREE_OPERAND (t, 0), flags);
1925 print_right_paren (scratch_buffer);
1929 print_left_paren (scratch_buffer);
1930 dump_type (TREE_TYPE (t), flags);
1931 output_add_string (scratch_buffer, ")(");
1932 dump_expr_list (TREE_OPERAND (t, 0), flags);
1933 print_right_paren (scratch_buffer);
1937 case STATIC_CAST_EXPR:
1938 output_add_string (scratch_buffer, "static_cast<");
1940 case REINTERPRET_CAST_EXPR:
1941 output_add_string (scratch_buffer, "reinterpret_cast<");
1943 case CONST_CAST_EXPR:
1944 output_add_string (scratch_buffer, "const_cast<");
1946 case DYNAMIC_CAST_EXPR:
1947 output_add_string (scratch_buffer, "dynamic_cast<");
1949 dump_type (TREE_TYPE (t), flags);
1950 output_add_string (scratch_buffer, ">(");
1951 dump_expr (TREE_OPERAND (t, 0), flags);
1952 print_right_paren (scratch_buffer);
1956 print_tree_identifier (scratch_buffer, TREE_OPERAND (t, 0));
1960 dump_expr (TREE_OPERAND (t, 0), flags);
1961 output_add_string (scratch_buffer, "->");
1966 if (TREE_CODE (t) == SIZEOF_EXPR)
1967 output_add_string (scratch_buffer, "sizeof (");
1970 my_friendly_assert (TREE_CODE (t) == ALIGNOF_EXPR, 0);
1971 output_add_string (scratch_buffer, "__alignof__ (");
1973 if (TYPE_P (TREE_OPERAND (t, 0)))
1974 dump_type (TREE_OPERAND (t, 0), flags);
1976 dump_unary_op ("*", t, flags | TFF_EXPR_IN_PARENS);
1977 print_right_paren (scratch_buffer);
1981 print_identifier (scratch_buffer, "<unparsed>");
1984 case TRY_CATCH_EXPR:
1985 case WITH_CLEANUP_EXPR:
1986 case CLEANUP_POINT_EXPR:
1987 dump_expr (TREE_OPERAND (t, 0), flags);
1990 case PSEUDO_DTOR_EXPR:
1991 dump_expr (TREE_OPERAND (t, 2), flags);
1992 output_add_character (scratch_buffer, '.');
1993 dump_type (TREE_OPERAND (t, 0), flags);
1994 output_add_string (scratch_buffer, "::~");
1995 dump_type (TREE_OPERAND (t, 1), flags);
1998 case TEMPLATE_ID_EXPR:
1999 dump_decl (t, flags);
2003 /* We don't yet have a way of dumping statements in a
2004 human-readable format. */
2005 output_add_string (scratch_buffer, "({...})");
2009 output_add_character (scratch_buffer, '{');
2010 dump_expr (TREE_OPERAND (t, 1), flags & ~TFF_EXPR_IN_PARENS);
2011 output_add_character (scratch_buffer, '}');
2015 output_add_string (scratch_buffer, "while (1) { ");
2016 dump_expr (TREE_OPERAND (t, 0), flags & ~TFF_EXPR_IN_PARENS);
2017 output_add_character (scratch_buffer, '}');
2021 output_add_string (scratch_buffer, "if (");
2022 dump_expr (TREE_OPERAND (t, 0), flags & ~TFF_EXPR_IN_PARENS);
2023 output_add_string (scratch_buffer, ") break; ");
2027 if (TREE_VALUE (t) && TREE_CODE (TREE_VALUE (t)) == FUNCTION_DECL)
2029 print_tree_identifier (scratch_buffer, DECL_NAME (TREE_VALUE (t)));
2032 /* else fall through */
2034 /* This list is incomplete, but should suffice for now.
2035 It is very important that `sorry' does not call
2036 `report_error_function'. That could cause an infinite loop. */
2038 sorry_for_unsupported_tree (t);
2039 /* fall through to ERROR_MARK... */
2041 print_identifier (scratch_buffer, "<expression error>");
2047 dump_binary_op (opstring, t, flags)
2048 const char *opstring;
2052 print_left_paren (scratch_buffer);
2053 dump_expr (TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
2054 output_add_space (scratch_buffer);
2056 print_identifier (scratch_buffer, opstring);
2058 print_identifier (scratch_buffer, "<unknown operator>");
2059 output_add_space (scratch_buffer);
2060 dump_expr (TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS);
2061 print_right_paren (scratch_buffer);
2065 dump_unary_op (opstring, t, flags)
2066 const char *opstring;
2070 if (flags & TFF_EXPR_IN_PARENS)
2071 print_left_paren (scratch_buffer);
2072 print_identifier (scratch_buffer, opstring);
2073 dump_expr (TREE_OPERAND (t, 0), flags & ~TFF_EXPR_IN_PARENS);
2074 if (flags & TFF_EXPR_IN_PARENS)
2075 print_right_paren (scratch_buffer);
2078 /* Exported interface to stringifying types, exprs and decls under TFF_*
2082 type_as_string (typ, flags)
2086 reinit_global_formatting_buffer ();
2088 dump_type (typ, flags);
2090 return output_finalize_message (scratch_buffer);
2094 expr_as_string (decl, flags)
2098 reinit_global_formatting_buffer ();
2100 dump_expr (decl, flags);
2102 return output_finalize_message (scratch_buffer);
2106 decl_as_string (decl, flags)
2110 reinit_global_formatting_buffer ();
2112 dump_decl (decl, flags);
2114 return output_finalize_message (scratch_buffer);
2118 context_as_string (context, flags)
2122 reinit_global_formatting_buffer ();
2124 dump_scope (context, flags);
2126 return output_finalize_message (scratch_buffer);
2129 /* Generate the three forms of printable names for lang_printable_name. */
2132 lang_decl_name (decl, v)
2137 return decl_as_string (decl, TFF_DECL_SPECIFIERS);
2139 reinit_global_formatting_buffer ();
2141 if (v == 1 && DECL_CLASS_SCOPE_P (decl))
2143 dump_type (CP_DECL_CONTEXT (decl), TFF_PLAIN_IDENTIFIER);
2144 print_scope_operator (scratch_buffer);
2147 if (TREE_CODE (decl) == FUNCTION_DECL)
2148 dump_function_name (decl, TFF_PLAIN_IDENTIFIER);
2150 dump_decl (DECL_NAME (decl), TFF_PLAIN_IDENTIFIER);
2152 return output_finalize_message (scratch_buffer);
2159 if (TREE_CODE (t) == PARM_DECL && DECL_CONTEXT (t))
2160 return DECL_SOURCE_FILE (DECL_CONTEXT (t));
2161 else if (TYPE_P (t))
2162 return DECL_SOURCE_FILE (TYPE_MAIN_DECL (t));
2163 else if (TREE_CODE (t) == OVERLOAD)
2164 return DECL_SOURCE_FILE (OVL_FUNCTION (t));
2166 return DECL_SOURCE_FILE (t);
2174 if (TREE_CODE (t) == PARM_DECL && DECL_CONTEXT (t))
2175 line = DECL_SOURCE_LINE (DECL_CONTEXT (t));
2176 if (TREE_CODE (t) == TYPE_DECL && DECL_ARTIFICIAL (t)
2177 && TYPE_MAIN_DECL (TREE_TYPE (t)))
2181 line = DECL_SOURCE_LINE (TYPE_MAIN_DECL (t));
2182 else if (TREE_CODE (t) == OVERLOAD)
2183 line = DECL_SOURCE_LINE (OVL_FUNCTION (t));
2185 line = DECL_SOURCE_LINE (t);
2193 /* Now the interfaces from error et al to dump_type et al. Each takes an
2194 on/off VERBOSE flag and supply the appropriate TFF_ flags to a dump_
2198 decl_to_string (decl, verbose)
2204 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == RECORD_TYPE
2205 || TREE_CODE (decl) == UNION_TYPE || TREE_CODE (decl) == ENUMERAL_TYPE)
2206 flags = TFF_CLASS_KEY_OR_ENUM;
2208 flags |= TFF_DECL_SPECIFIERS | TFF_FUNCTION_DEFAULT_ARGUMENTS;
2209 else if (TREE_CODE (decl) == FUNCTION_DECL)
2210 flags |= TFF_DECL_SPECIFIERS | TFF_RETURN_TYPE;
2211 flags |= TFF_TEMPLATE_HEADER;
2213 reinit_global_formatting_buffer ();
2215 dump_decl (decl, flags);
2217 return output_finalize_message (scratch_buffer);
2221 expr_to_string (decl, verbose)
2223 int verbose ATTRIBUTE_UNUSED;
2225 reinit_global_formatting_buffer ();
2227 dump_expr (decl, 0);
2229 return output_finalize_message (scratch_buffer);
2233 fndecl_to_string (fndecl, verbose)
2239 flags = TFF_EXCEPTION_SPECIFICATION | TFF_DECL_SPECIFIERS;
2241 flags |= TFF_FUNCTION_DEFAULT_ARGUMENTS;
2242 reinit_global_formatting_buffer ();
2244 dump_decl (fndecl, flags);
2246 return output_finalize_message (scratch_buffer);
2251 code_to_string (c, v)
2253 int v ATTRIBUTE_UNUSED;
2255 return tree_code_name [c];
2259 language_to_string (c, v)
2261 int v ATTRIBUTE_UNUSED;
2268 case lang_cplusplus:
2280 /* Return the proper printed version of a parameter to a C++ function. */
2283 parm_to_string (p, v)
2285 int v ATTRIBUTE_UNUSED;
2290 sprintf (digit_buffer, "%d", p+1);
2291 return digit_buffer;
2297 int v ATTRIBUTE_UNUSED;
2301 id = operator_name_info[(int) p].identifier;
2302 return id ? IDENTIFIER_POINTER (id) : "{unknown}";
2306 type_to_string (typ, verbose)
2314 flags |= TFF_CLASS_KEY_OR_ENUM;
2315 flags |= TFF_TEMPLATE_HEADER;
2317 reinit_global_formatting_buffer ();
2319 dump_type (typ, flags);
2321 return output_finalize_message (scratch_buffer);
2325 assop_to_string (p, v)
2327 int v ATTRIBUTE_UNUSED;
2331 id = assignment_operator_name_info[(int) p].identifier;
2332 return id ? IDENTIFIER_POINTER (id) : "{unknown}";
2336 args_to_string (p, verbose)
2342 flags |= TFF_CLASS_KEY_OR_ENUM;
2347 if (TYPE_P (TREE_VALUE (p)))
2348 return type_as_string (p, flags);
2350 reinit_global_formatting_buffer ();
2351 for (; p; p = TREE_CHAIN (p))
2353 if (TREE_VALUE (p) == null_node)
2354 print_identifier (scratch_buffer, "NULL");
2356 dump_type (error_type (TREE_VALUE (p)), flags);
2358 separate_with_comma (scratch_buffer);
2360 return output_finalize_message (scratch_buffer);
2368 reinit_global_formatting_buffer ();
2370 dump_qualifiers (p, v ? before : none);
2372 return output_finalize_message (scratch_buffer);
2376 lang_print_error_function (context, file)
2377 diagnostic_context *context;
2382 default_print_error_function (context, file);
2383 os = output_buffer_state (context);
2384 output_set_prefix ((output_buffer *)context, file);
2385 maybe_print_instantiation_context ((output_buffer *)context);
2386 output_buffer_state (context) = os;
2390 cp_diagnostic_starter (buffer, dc)
2391 output_buffer *buffer;
2392 diagnostic_context *dc;
2394 report_problematic_module (buffer);
2395 cp_print_error_function (buffer, dc);
2396 maybe_print_instantiation_context (buffer);
2397 output_set_prefix (buffer,
2398 context_as_prefix (diagnostic_file_location (dc),
2399 diagnostic_line_location (dc),
2400 diagnostic_is_warning (dc)));
2404 cp_diagnostic_finalizer (buffer, dc)
2405 output_buffer *buffer;
2406 diagnostic_context *dc __attribute__ ((__unused__));
2408 output_destroy_prefix (buffer);
2411 /* Print current function onto BUFFER, in the process of reporting
2412 a diagnostic message. Called from cp_diagnostic_starter. */
2414 cp_print_error_function (buffer, dc)
2415 output_buffer *buffer;
2416 diagnostic_context *dc;
2418 if (error_function_changed ())
2420 char *prefix = diagnostic_file_location (dc)
2421 ? file_name_as_prefix (diagnostic_file_location (dc))
2425 os = output_buffer_state (buffer);
2426 output_set_prefix (buffer, prefix);
2428 if (current_function_decl == NULL)
2429 output_add_string (buffer, "At global scope:");
2432 (buffer, "In %s `%s':", function_category (current_function_decl),
2433 (*decl_printable_name) (current_function_decl, 2));
2434 output_add_newline (buffer);
2436 record_last_error_function ();
2437 output_destroy_prefix (buffer);
2438 output_buffer_state (buffer) = os;
2442 /* Returns a description of FUNCTION using standard terminology. */
2444 function_category (fn)
2447 if (DECL_FUNCTION_MEMBER_P (fn))
2449 if (DECL_STATIC_FUNCTION_P (fn))
2450 return "static member function";
2451 else if (DECL_COPY_CONSTRUCTOR_P (fn))
2452 return "copy constructor";
2453 else if (DECL_CONSTRUCTOR_P (fn))
2454 return "constructor";
2455 else if (DECL_DESTRUCTOR_P (fn))
2456 return "destructor";
2458 return "member function";
2464 /* Report the full context of a current template instantiation,
2467 print_instantiation_full_context (buffer)
2468 output_buffer *buffer;
2470 tree p = current_instantiation ();
2472 const char *file = input_filename;
2476 if (current_function_decl != TINST_DECL (p)
2477 && current_function_decl != NULL_TREE)
2478 /* We can get here during the processing of some synthesized
2479 method. Then, TINST_DECL (p) will be the function that's causing
2484 if (current_function_decl == TINST_DECL (p))
2485 /* Avoid redundancy with the the "In function" line. */;
2487 output_verbatim (buffer, "%s: In instantiation of `%s':\n", file,
2488 decl_as_string (TINST_DECL (p),
2489 TFF_DECL_SPECIFIERS | TFF_RETURN_TYPE));
2491 line = TINST_LINE (p);
2492 file = TINST_FILE (p);
2497 print_instantiation_partial_context (buffer, p, file, line);
2500 /* Same as above but less verbose. */
2502 print_instantiation_partial_context (buffer, t, file, line)
2503 output_buffer *buffer;
2508 for (; t; t = TREE_CHAIN (t))
2511 (buffer, "%s:%d: instantiated from `%s'\n", file, line,
2512 decl_as_string (TINST_DECL (t), TFF_DECL_SPECIFIERS | TFF_RETURN_TYPE));
2513 line = TINST_LINE (t);
2514 file = TINST_FILE (t);
2516 output_verbatim (buffer, "%s:%d: instantiated from here\n", file, line);
2519 /* Called from cp_thing to print the template context for an error. */
2521 maybe_print_instantiation_context (buffer)
2522 output_buffer *buffer;
2524 if (!problematic_instantiation_changed () || current_instantiation () == 0)
2527 record_last_problematic_instantiation ();
2528 print_instantiation_full_context (buffer);
2531 /* Report the bare minimum context of a template instantiation. */
2533 print_instantiation_context ()
2535 print_instantiation_partial_context
2536 (diagnostic_buffer, current_instantiation (), input_filename, lineno);
2537 flush_diagnostic_buffer ();
2540 /* Called from output_format -- during diagnostic message processing --
2541 to handle C++ specific format specifier with the following meanings:
2542 %A function argument-list.
2546 %F function declaration.
2547 %L language as used in extern "lang".
2549 %P function parameter whose position is indicated by an integer.
2550 %Q assignment operator.
2555 output_buffer *buffer;
2559 #define next_tree va_arg (output_buffer_format_args (buffer), tree)
2560 #define next_tcode va_arg (output_buffer_format_args (buffer), enum tree_code)
2561 #define next_lang va_arg (output_buffer_format_args (buffer), enum languages)
2562 #define next_int va_arg (output_buffer_format_args (buffer), int)
2564 if (*output_buffer_text_cursor (buffer) == '+')
2565 ++output_buffer_text_cursor (buffer);
2566 if (*output_buffer_text_cursor (buffer) == '#')
2569 ++output_buffer_text_cursor (buffer);
2572 switch (*output_buffer_text_cursor (buffer))
2574 case 'A': result = args_to_string (next_tree, verbose); break;
2575 case 'C': result = code_to_string (next_tcode, verbose); break;
2576 case 'D': result = decl_to_string (next_tree, verbose); break;
2577 case 'E': result = expr_to_string (next_tree, verbose); break;
2578 case 'F': result = fndecl_to_string (next_tree, verbose); break;
2579 case 'L': result = language_to_string (next_lang, verbose); break;
2580 case 'O': result = op_to_string (next_tcode, verbose); break;
2581 case 'P': result = parm_to_string (next_int, verbose); break;
2582 case 'Q': result = assop_to_string (next_tcode, verbose); break;
2583 case 'T': result = type_to_string (next_tree, verbose); break;
2584 case 'V': result = cv_to_string (next_tree, verbose); break;
2590 output_add_string (buffer, result);
2599 print_integer (buffer, i)
2600 output_buffer *buffer;
2603 sprintf (digit_buffer, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT) i);
2604 output_add_string (buffer, digit_buffer);
2608 print_non_consecutive_character (buffer, c)
2609 output_buffer *buffer;
2612 const char *p = output_last_position (buffer);
2614 if (p != NULL && *p == c)
2615 output_add_space (buffer);
2616 output_add_character (buffer, c);
2619 /* These are temporary wrapper functions which handle the historic
2620 behavior of cp_*_at. */
2623 locate_error (msgid, ap)
2631 for (f = msgid; *f; f++)
2644 /* Just ignore these possibilities. */
2646 case 'd': (void) va_arg (ap, int); break;
2647 case 's': (void) va_arg (ap, char *); break;
2648 case 'L': (void) va_arg (ap, enum languages); break;
2651 case 'Q': (void) va_arg (ap, enum tree_code); break;
2653 /* These take a tree, which may be where the error is
2662 t = va_arg (ap, tree);
2668 errorcount = 0; /* damn ICE suppression */
2669 internal_error ("unexpected letter `%c' in locate_error\n", *f);
2675 here = va_arg (ap, tree);
2682 cp_error_at VPARAMS ((const char *msgid, ...))
2685 diagnostic_context dc;
2687 VA_OPEN (ap, msgid);
2688 VA_FIXEDARG (ap, const char *, msgid);
2689 here = locate_error (msgid, ap);
2692 VA_OPEN (ap, msgid);
2693 VA_FIXEDARG (ap, const char *, msgid);
2695 set_diagnostic_context (&dc, msgid, &ap,
2697 cp_line_of (here), /* warning = */ 0);
2698 report_diagnostic (&dc);
2703 cp_warning_at VPARAMS ((const char *msgid, ...))
2706 diagnostic_context dc;
2708 VA_OPEN (ap, msgid);
2709 VA_FIXEDARG (ap, const char *, msgid);
2710 here = locate_error (msgid, ap);
2713 VA_OPEN (ap, msgid);
2714 VA_FIXEDARG (ap, const char *, msgid);
2716 set_diagnostic_context (&dc, msgid, &ap,
2718 cp_line_of (here), /* warning = */ 1);
2719 report_diagnostic (&dc);
2724 cp_pedwarn_at VPARAMS ((const char *msgid, ...))
2727 diagnostic_context dc;
2729 VA_OPEN (ap, msgid);
2730 VA_FIXEDARG (ap, const char *, msgid);
2731 here = locate_error (msgid, ap);
2734 VA_OPEN (ap, msgid);
2735 VA_FIXEDARG (ap, const char *, msgid);
2737 set_diagnostic_context (&dc, msgid, &ap,
2740 /* warning = */ !flag_pedantic_errors);
2741 report_diagnostic (&dc);