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 & (flags & (TFF_SCOPE | TFF_CHASE_TYPEDEF));
145 if (scope == NULL_TREE)
148 if (TREE_CODE (scope) == NAMESPACE_DECL)
150 if (scope != global_namespace)
152 dump_decl (scope, f);
153 print_scope_operator (scratch_buffer);
156 else if (AGGREGATE_TYPE_P (scope))
158 dump_type (scope, f);
159 print_scope_operator (scratch_buffer);
161 else if ((flags & TFF_SCOPE) && TREE_CODE (scope) == FUNCTION_DECL)
163 dump_function_decl (scope, f);
164 print_scope_operator (scratch_buffer);
168 /* Dump type qualifiers, providing padding as requested. Return an
169 indication of whether we dumped something. */
172 dump_qualifiers (t, p)
176 static const int masks[] =
177 {TYPE_QUAL_CONST, TYPE_QUAL_VOLATILE, TYPE_QUAL_RESTRICT};
178 static const char *const names[] =
179 {"const", "volatile", "__restrict"};
181 int quals = TYPE_QUALS (t);
182 int do_after = p == after;
186 for (ix = 0; ix != 3; ix++)
187 if (masks[ix] & quals)
190 output_add_space (scratch_buffer);
192 print_identifier (scratch_buffer, names[ix]);
195 output_add_space (scratch_buffer);
202 /* This must be large enough to hold any printed integer or floating-point
204 static char digit_buffer[128];
206 /* Dump the template ARGument under control of FLAGS. */
209 dump_template_argument (arg, flags)
213 if (TYPE_P (arg) || TREE_CODE (arg) == TEMPLATE_DECL)
214 dump_type (arg, flags & ~TFF_CLASS_KEY_OR_ENUM);
216 dump_expr (arg, (flags | TFF_EXPR_IN_PARENS) & ~TFF_CLASS_KEY_OR_ENUM);
219 /* Dump a template-argument-list ARGS (always a TREE_VEC) under control
223 dump_template_argument_list (args, flags)
227 int n = TREE_VEC_LENGTH (args);
231 for (i = 0; i< n; ++i)
234 separate_with_comma (scratch_buffer);
235 dump_template_argument (TREE_VEC_ELT (args, i), flags);
240 /* Dump a template parameter PARM (a TREE_LIST) under control of FLAGS. */
243 dump_template_parameter (parm, flags)
247 tree p = TREE_VALUE (parm);
248 tree a = TREE_PURPOSE (parm);
250 if (TREE_CODE (p) == TYPE_DECL)
252 if (flags & TFF_DECL_SPECIFIERS)
254 print_identifier (scratch_buffer, "class");
257 output_add_space (scratch_buffer);
258 print_tree_identifier (scratch_buffer, DECL_NAME (p));
261 else if (DECL_NAME (p))
262 print_tree_identifier (scratch_buffer, DECL_NAME (p));
264 print_identifier (scratch_buffer, "{template default argument error}");
267 dump_decl (p, flags | TFF_DECL_SPECIFIERS);
269 if ((flags & TFF_FUNCTION_DEFAULT_ARGUMENTS) && a != NULL_TREE)
271 output_add_string (scratch_buffer, " = ");
272 if (TREE_CODE (p) == TYPE_DECL || TREE_CODE (p) == TEMPLATE_DECL)
273 dump_type (a, flags & ~TFF_CHASE_TYPEDEF);
275 dump_expr (a, flags | TFF_EXPR_IN_PARENS);
279 /* Dump, under control of FLAGS, a template-parameter-list binding.
280 PARMS is a TREE_LIST of TREE_VEC of TREE_LIST and ARGS is a
284 dump_template_bindings (parms, args)
291 tree p = TREE_VALUE (parms);
292 int lvl = TMPL_PARMS_DEPTH (parms);
296 for (i = 0; i < TREE_VEC_LENGTH (p); ++i)
298 tree arg = NULL_TREE;
300 /* Don't crash if we had an invalid argument list. */
301 if (TMPL_ARGS_DEPTH (args) >= lvl)
303 tree lvl_args = TMPL_ARGS_LEVEL (args, lvl);
304 if (NUM_TMPL_ARGS (lvl_args) > arg_idx)
305 arg = TREE_VEC_ELT (lvl_args, arg_idx);
309 separate_with_comma (scratch_buffer);
310 dump_template_parameter (TREE_VEC_ELT (p, i), TFF_PLAIN_IDENTIFIER);
311 output_add_string (scratch_buffer, " = ");
313 dump_template_argument (arg, TFF_PLAIN_IDENTIFIER);
315 print_identifier (scratch_buffer, "<missing>");
321 parms = TREE_CHAIN (parms);
325 /* Dump into the obstack a human-readable equivalent of TYPE. FLAGS
326 controls the format. */
336 if (TYPE_PTRMEMFUNC_P (t))
339 switch (TREE_CODE (t))
342 print_identifier (scratch_buffer, "<unknown type>");
346 /* A list of function parms. */
347 dump_parameters (t, flags);
350 case IDENTIFIER_NODE:
351 print_tree_identifier (scratch_buffer, t);
355 dump_type (BINFO_TYPE (t), flags);
361 dump_aggr_type (t, flags);
365 if (flags & TFF_CHASE_TYPEDEF)
367 dump_type (DECL_ORIGINAL_TYPE (t)
368 ? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t), flags);
371 /* else fallthrough */
375 dump_decl (t, flags & ~TFF_DECL_SPECIFIERS);
379 output_add_string (scratch_buffer, "__complex__ ");
380 dump_type (TREE_TYPE (t), flags);
384 output_add_string (scratch_buffer, "vector ");
386 /* The subtype of a VECTOR_TYPE is something like intQI_type_node,
387 which has no name and is not very useful for diagnostics. So
388 look up the equivalent C type and print its name. */
389 tree elt = TREE_TYPE (t);
390 elt = type_for_mode (TYPE_MODE (elt), TREE_UNSIGNED (elt));
391 dump_type (elt, flags);
396 if (!TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)) && TREE_UNSIGNED (t))
397 output_add_string (scratch_buffer, "unsigned ");
398 else if (TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)) && !TREE_UNSIGNED (t))
399 output_add_string (scratch_buffer, "signed ");
407 dump_qualifiers (t, after);
408 type = flags & TFF_CHASE_TYPEDEF ? TYPE_MAIN_VARIANT (t) : t;
409 if (TYPE_NAME (type) && TYPE_IDENTIFIER (type))
410 print_tree_identifier (scratch_buffer, TYPE_IDENTIFIER (type));
412 /* Types like intQI_type_node and friends have no names.
413 These don't come up in user error messages, but it's nice
414 to be able to print them from the debugger. */
415 print_identifier (scratch_buffer, "<anonymous>");
419 case TEMPLATE_TEMPLATE_PARM:
420 /* For parameters inside template signature. */
421 if (TYPE_IDENTIFIER (t))
422 print_tree_identifier (scratch_buffer, TYPE_IDENTIFIER (t));
425 (scratch_buffer, "<anonymous template template parameter>");
428 case BOUND_TEMPLATE_TEMPLATE_PARM:
430 tree args = TYPE_TI_ARGS (t);
431 print_tree_identifier (scratch_buffer, TYPE_IDENTIFIER (t));
432 print_template_argument_list_start (scratch_buffer);
433 dump_template_argument_list (args, flags);
434 print_template_argument_list_end (scratch_buffer);
438 case TEMPLATE_TYPE_PARM:
439 dump_qualifiers (t, after);
440 if (TYPE_IDENTIFIER (t))
441 print_tree_identifier (scratch_buffer, TYPE_IDENTIFIER (t));
444 (scratch_buffer, "<anonymous template type parameter>");
447 /* This is not always necessary for pointers and such, but doing this
448 reduces code size. */
457 dump_type_prefix (t, flags);
458 dump_type_suffix (t, flags);
462 output_add_string (scratch_buffer, "typename ");
463 dump_typename (t, flags);
466 case UNBOUND_CLASS_TEMPLATE:
467 dump_type (TYPE_CONTEXT (t), flags);
468 print_scope_operator (scratch_buffer);
469 print_identifier (scratch_buffer, "template ");
470 dump_type (DECL_NAME (TYPE_NAME (t)), flags);
474 output_add_string (scratch_buffer, "__typeof (");
475 dump_expr (TYPE_FIELDS (t), flags & ~TFF_EXPR_IN_PARENS);
476 print_left_paren (scratch_buffer);
480 sorry_for_unsupported_tree (t);
481 /* Fall through to error. */
484 print_identifier (scratch_buffer, "<type error>");
489 /* Dump a TYPENAME_TYPE. We need to notice when the context is itself
493 dump_typename (t, flags)
497 tree ctx = TYPE_CONTEXT (t);
499 if (TREE_CODE (ctx) == TYPENAME_TYPE)
500 dump_typename (ctx, flags);
502 dump_type (ctx, flags & ~TFF_CLASS_KEY_OR_ENUM);
503 print_scope_operator (scratch_buffer);
504 dump_decl (TYPENAME_TYPE_FULLNAME (t), flags);
507 /* Return the name of the supplied aggregate, or enumeral type. */
510 class_key_or_enum (t)
513 if (TREE_CODE (t) == ENUMERAL_TYPE)
515 else if (TREE_CODE (t) == UNION_TYPE)
517 else if (TYPE_LANG_SPECIFIC (t) && CLASSTYPE_DECLARED_CLASS (t))
523 /* Print out a class declaration T under the control of FLAGS,
524 in the form `class foo'. */
527 dump_aggr_type (t, flags)
532 const char *variety = class_key_or_enum (t);
536 dump_qualifiers (t, after);
538 if (flags & TFF_CLASS_KEY_OR_ENUM)
540 print_identifier (scratch_buffer, variety);
541 output_add_space (scratch_buffer);
544 if (flags & TFF_CHASE_TYPEDEF)
545 t = TYPE_MAIN_VARIANT (t);
547 name = TYPE_NAME (t);
551 typdef = !DECL_ARTIFICIAL (name);
552 tmplate = !typdef && TREE_CODE (t) != ENUMERAL_TYPE
553 && TYPE_LANG_SPECIFIC (t) && CLASSTYPE_TEMPLATE_INFO (t)
554 && (CLASSTYPE_TEMPLATE_SPECIALIZATION (t)
555 || TREE_CODE (CLASSTYPE_TI_TEMPLATE (t)) != TEMPLATE_DECL
556 || DECL_TEMPLATE_SPECIALIZATION (CLASSTYPE_TI_TEMPLATE (t))
557 || PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t)));
558 dump_scope (CP_DECL_CONTEXT (name), flags | TFF_SCOPE);
561 /* Because the template names are mangled, we have to locate
562 the most general template, and use that name. */
563 tree tpl = CLASSTYPE_TI_TEMPLATE (t);
565 while (DECL_TEMPLATE_INFO (tpl))
566 tpl = DECL_TI_TEMPLATE (tpl);
569 name = DECL_NAME (name);
572 if (name == 0 || ANON_AGGRNAME_P (name))
574 if (flags & TFF_CLASS_KEY_OR_ENUM)
575 print_identifier (scratch_buffer, "<anonymous>");
577 output_printf (scratch_buffer, "<anonymous %s>", variety);
580 print_tree_identifier (scratch_buffer, name);
582 dump_template_parms (TYPE_TEMPLATE_INFO (t),
583 !CLASSTYPE_USE_TEMPLATE (t),
584 flags & ~TFF_TEMPLATE_HEADER);
587 /* Dump into the obstack the initial part of the output for a given type.
588 This is necessary when dealing with things like functions returning
591 return type of `int (* fee ())()': pointer -> function -> int. Both
592 pointer (and reference and offset) and function (and member) types must
593 deal with prefix and suffix.
595 Arrays must also do this for DECL nodes, like int a[], and for things like
598 Return indicates how you should pad an object name after this. I.e. you
599 want to pad non-*, non-& cores, but not pad * or & types. */
602 dump_type_prefix (t, flags)
606 enum pad padding = before;
608 if (TYPE_PTRMEMFUNC_P (t))
610 t = TYPE_PTRMEMFUNC_FN_TYPE (t);
614 switch (TREE_CODE (t))
619 tree sub = TREE_TYPE (t);
621 padding = dump_type_prefix (sub, flags);
622 /* A tree for a member pointer looks like pointer to offset,
623 so let the OFFSET_TYPE case handle it. */
624 if (!TYPE_PTRMEM_P (t))
626 if (TREE_CODE (sub) == ARRAY_TYPE)
628 output_add_space (scratch_buffer);
629 print_left_paren (scratch_buffer);
632 (scratch_buffer, "&*"[TREE_CODE (t) == POINTER_TYPE]);
633 padding = dump_qualifiers (t, before);
640 padding = dump_type_prefix (TREE_TYPE (t), flags);
641 if (TREE_CODE (t) == OFFSET_TYPE) /* pmfs deal with this in d_t_p */
644 output_add_space (scratch_buffer);
645 dump_type (TYPE_OFFSET_BASETYPE (t), flags);
646 print_scope_operator (scratch_buffer);
648 output_add_character (scratch_buffer, '*');
649 padding = dump_qualifiers (t, none);
652 /* Can only be reached through function pointer -- this would not be
653 correct if FUNCTION_DECLs used it. */
655 padding = dump_type_prefix (TREE_TYPE (t), flags);
657 output_add_space (scratch_buffer);
658 print_left_paren (scratch_buffer);
663 padding = dump_type_prefix (TREE_TYPE (t), flags);
665 output_add_space (scratch_buffer);
666 print_left_paren (scratch_buffer);
668 dump_aggr_type (TYPE_METHOD_BASETYPE (t), flags);
669 print_scope_operator (scratch_buffer);
673 padding = dump_type_prefix (TREE_TYPE (t), flags);
677 case IDENTIFIER_NODE:
682 case TEMPLATE_TYPE_PARM:
683 case TEMPLATE_TEMPLATE_PARM:
684 case BOUND_TEMPLATE_TEMPLATE_PARM:
694 dump_type (t, flags);
699 sorry_for_unsupported_tree (t);
702 print_identifier (scratch_buffer, "<typeprefixerror>");
708 /* Dump the suffix of type T, under control of FLAGS. This is the part
709 which appears after the identifier (or function parms). */
712 dump_type_suffix (t, flags)
716 if (TYPE_PTRMEMFUNC_P (t))
717 t = TYPE_PTRMEMFUNC_FN_TYPE (t);
719 switch (TREE_CODE (t))
724 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
725 print_right_paren (scratch_buffer);
726 dump_type_suffix (TREE_TYPE (t), flags);
729 /* Can only be reached through function pointer */
734 print_right_paren (scratch_buffer);
735 arg = TYPE_ARG_TYPES (t);
736 if (TREE_CODE (t) == METHOD_TYPE)
737 arg = TREE_CHAIN (arg);
739 /* Function pointers don't have default args. Not in standard C++,
740 anyway; they may in g++, but we'll just pretend otherwise. */
741 dump_parameters (arg, flags & ~TFF_FUNCTION_DEFAULT_ARGUMENTS);
743 if (TREE_CODE (t) == METHOD_TYPE)
745 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t))), before);
746 dump_exception_spec (TYPE_RAISES_EXCEPTIONS (t), flags);
747 dump_type_suffix (TREE_TYPE (t), flags);
752 print_left_bracket (scratch_buffer);
755 if (host_integerp (TYPE_MAX_VALUE (TYPE_DOMAIN (t)), 0))
758 tree_low_cst (TYPE_MAX_VALUE (TYPE_DOMAIN (t)), 0) + 1);
759 else if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (t))) == MINUS_EXPR)
760 dump_expr (TREE_OPERAND (TYPE_MAX_VALUE (TYPE_DOMAIN (t)), 0),
761 flags & ~TFF_EXPR_IN_PARENS);
763 dump_expr (fold (cp_build_binary_op
764 (PLUS_EXPR, TYPE_MAX_VALUE (TYPE_DOMAIN (t)),
766 flags & ~TFF_EXPR_IN_PARENS);
768 print_right_bracket (scratch_buffer);
769 dump_type_suffix (TREE_TYPE (t), flags);
773 case IDENTIFIER_NODE:
778 case TEMPLATE_TYPE_PARM:
779 case TEMPLATE_TEMPLATE_PARM:
780 case BOUND_TEMPLATE_TEMPLATE_PARM:
793 sorry_for_unsupported_tree (t);
795 /* Don't mark it here, we should have already done in
805 const char *p = NULL;
807 if (DECL_GLOBAL_CTOR_P (t))
809 else if (DECL_GLOBAL_DTOR_P (t))
814 output_printf (scratch_buffer, "(static %s for %s)", p, input_filename);
818 dump_simple_decl (t, type, flags)
823 if (flags & TFF_DECL_SPECIFIERS)
825 if (dump_type_prefix (type, flags) != none)
826 output_add_space (scratch_buffer);
828 if (!DECL_INITIAL (t) || TREE_CODE (DECL_INITIAL (t)) != TEMPLATE_PARM_INDEX)
829 dump_scope (CP_DECL_CONTEXT (t), flags);
831 dump_decl (DECL_NAME (t), flags);
833 print_identifier (scratch_buffer, "<anonymous>");
834 if (flags & TFF_DECL_SPECIFIERS)
835 dump_type_suffix (type, flags);
838 /* Dump a human readable string for the decl T under control of FLAGS. */
848 switch (TREE_CODE (t))
852 /* Don't say 'typedef class A' */
853 if (DECL_ARTIFICIAL (t))
855 if ((flags & TFF_DECL_SPECIFIERS)
856 && TREE_CODE (TREE_TYPE (t)) == TEMPLATE_TYPE_PARM)
857 /* Say `class T' not just `T'. */
858 output_add_string (scratch_buffer, "class ");
860 dump_type (TREE_TYPE (t), flags);
864 if (flags & TFF_DECL_SPECIFIERS)
865 output_add_string (scratch_buffer, "typedef ");
866 dump_simple_decl (t, DECL_ORIGINAL_TYPE (t)
867 ? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t),
872 if (DECL_NAME (t) && VTABLE_NAME_P (DECL_NAME (t)))
874 output_add_string (scratch_buffer, "vtable for ");
875 my_friendly_assert (TYPE_P (DECL_CONTEXT (t)), 20010720);
876 dump_type (DECL_CONTEXT (t), flags);
879 /* else fall through */
882 dump_simple_decl (t, TREE_TYPE (t), flags);
886 output_add_string (scratch_buffer, "<return value> ");
887 dump_simple_decl (t, TREE_TYPE (t), flags);
891 dump_scope (CP_DECL_CONTEXT (t), flags);
892 if (DECL_NAME (t) == anonymous_namespace_name)
893 print_identifier (scratch_buffer, "<unnamed>");
895 print_tree_identifier (scratch_buffer, DECL_NAME (t));
899 dump_decl (TREE_OPERAND (t, 0), flags & ~TFF_DECL_SPECIFIERS);
900 print_scope_operator (scratch_buffer);
901 dump_decl (TREE_OPERAND (t, 1), flags);
905 dump_decl (TREE_OPERAND (t, 0), flags);
906 print_left_bracket (scratch_buffer);
907 dump_decl (TREE_OPERAND (t, 1), flags);
908 print_right_bracket (scratch_buffer);
911 /* So that we can do dump_decl on an aggr type. */
915 dump_type (t, flags);
922 /* These special cases are duplicated here so that other functions
923 can feed identifiers to error and get them demangled properly. */
924 case IDENTIFIER_NODE:
925 if (IDENTIFIER_TYPENAME_P (t))
927 output_add_string (scratch_buffer, "operator ");
928 /* Not exactly IDENTIFIER_TYPE_VALUE. */
929 dump_type (TREE_TYPE (t), flags);
933 print_tree_identifier (scratch_buffer, t);
941 if (DECL_GLOBAL_CTOR_P (t) || DECL_GLOBAL_DTOR_P (t))
942 dump_global_iord (t);
943 else if (! DECL_LANG_SPECIFIC (t))
944 print_identifier (scratch_buffer, "<internal>");
946 dump_function_decl (t, flags);
950 dump_template_decl (t, flags);
953 case TEMPLATE_ID_EXPR:
956 tree name = TREE_OPERAND (t, 0);
957 if (is_overloaded_fn (name))
958 name = DECL_NAME (get_first_fn (name));
959 dump_decl (name, flags);
960 print_template_argument_list_start (scratch_buffer);
961 for (args = TREE_OPERAND (t, 1); args; args = TREE_CHAIN (args))
963 dump_template_argument (TREE_VALUE (args), flags);
964 if (TREE_CHAIN (args))
965 separate_with_comma (scratch_buffer);
967 print_template_argument_list_end (scratch_buffer);
972 dump_decl (TREE_OPERAND (t, 0), flags);
976 print_tree_identifier (scratch_buffer, DECL_NAME (t));
980 if ((TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == ENUMERAL_TYPE)
981 || (DECL_INITIAL (t) &&
982 TREE_CODE (DECL_INITIAL (t)) == TEMPLATE_PARM_INDEX))
983 dump_simple_decl (t, TREE_TYPE (t), flags);
984 else if (DECL_NAME (t))
985 dump_decl (DECL_NAME (t), flags);
986 else if (DECL_INITIAL (t))
987 dump_expr (DECL_INITIAL (t), flags | TFF_EXPR_IN_PARENS);
989 print_identifier (scratch_buffer, "enumerator");
993 output_add_string (scratch_buffer, "using ");
994 dump_type (DECL_INITIAL (t), flags);
995 print_scope_operator (scratch_buffer);
996 print_tree_identifier (scratch_buffer, DECL_NAME (t));
1000 sorry_for_unsupported_tree (t);
1001 /* Fallthrough to error. */
1004 print_identifier (scratch_buffer, "<declaration error>");
1009 /* Dump a template declaration T under control of FLAGS. This means the
1010 'template <...> leaders plus the 'class X' or 'void fn(...)' part. */
1013 dump_template_decl (t, flags)
1017 tree orig_parms = DECL_TEMPLATE_PARMS (t);
1021 if (flags & TFF_TEMPLATE_HEADER)
1023 for (parms = orig_parms = nreverse (orig_parms);
1025 parms = TREE_CHAIN (parms))
1027 tree inner_parms = INNERMOST_TEMPLATE_PARMS (parms);
1028 int len = TREE_VEC_LENGTH (inner_parms);
1030 output_add_string (scratch_buffer, "template<");
1032 /* If we've shown the template prefix, we'd better show the
1033 parameters' and decl's type too. */
1034 flags |= TFF_DECL_SPECIFIERS;
1036 for (i = 0; i < len; i++)
1039 separate_with_comma (scratch_buffer);
1040 dump_template_parameter (TREE_VEC_ELT (inner_parms, i), flags);
1042 print_template_argument_list_end (scratch_buffer);
1043 output_add_space (scratch_buffer);
1045 nreverse(orig_parms);
1047 if (DECL_TEMPLATE_TEMPLATE_PARM_P (t))
1048 /* Say `template<arg> class TT' not just `template<arg> TT'. */
1049 output_add_string (scratch_buffer, "class ");
1052 if (TREE_CODE (DECL_TEMPLATE_RESULT (t)) == TYPE_DECL)
1053 dump_type (TREE_TYPE (t),
1054 ((flags & ~TFF_CLASS_KEY_OR_ENUM) | TFF_TEMPLATE_NAME
1055 | (flags & TFF_DECL_SPECIFIERS ? TFF_CLASS_KEY_OR_ENUM : 0)));
1056 else if (TREE_CODE (DECL_TEMPLATE_RESULT (t)) == VAR_DECL)
1057 dump_decl (DECL_TEMPLATE_RESULT (t), flags | TFF_TEMPLATE_NAME);
1058 else if (TREE_TYPE (t) == NULL_TREE)
1061 switch (NEXT_CODE (t))
1065 dump_function_decl (t, flags | TFF_TEMPLATE_NAME);
1068 /* This case can occur with some illegal code. */
1069 dump_type (TREE_TYPE (t),
1070 (flags & ~TFF_CLASS_KEY_OR_ENUM) | TFF_TEMPLATE_NAME
1071 | (flags & TFF_DECL_SPECIFIERS ? TFF_CLASS_KEY_OR_ENUM : 0));
1075 /* Pretty print a function decl. There are several ways we want to print a
1076 function declaration. The TFF_ bits in FLAGS tells us how to behave.
1077 As error can only apply the '#' flag once to give 0 and 1 for V, there
1078 is %D which doesn't print the throw specs, and %F which does. */
1081 dump_function_decl (t, flags)
1087 tree cname = NULL_TREE;
1088 tree template_args = NULL_TREE;
1089 tree template_parms = NULL_TREE;
1090 int show_return = flags & TFF_RETURN_TYPE || flags & TFF_DECL_SPECIFIERS;
1092 if (TREE_CODE (t) == TEMPLATE_DECL)
1093 t = DECL_TEMPLATE_RESULT (t);
1095 /* Pretty print template instantiations only. */
1096 if (DECL_USE_TEMPLATE (t) && DECL_TEMPLATE_INFO (t))
1100 template_args = DECL_TI_ARGS (t);
1101 tmpl = most_general_template (t);
1102 if (tmpl && TREE_CODE (tmpl) == TEMPLATE_DECL)
1104 template_parms = DECL_TEMPLATE_PARMS (tmpl);
1109 fntype = TREE_TYPE (t);
1110 parmtypes = FUNCTION_FIRST_USER_PARMTYPE (t);
1112 if (DECL_CLASS_SCOPE_P (t))
1113 cname = DECL_CONTEXT (t);
1114 /* this is for partially instantiated template methods */
1115 else if (TREE_CODE (fntype) == METHOD_TYPE)
1116 cname = TREE_TYPE (TREE_VALUE (parmtypes));
1118 if (!(flags & TFF_DECL_SPECIFIERS))
1120 else if (DECL_STATIC_FUNCTION_P (t))
1121 print_identifier (scratch_buffer, "static ");
1122 else if (DECL_VIRTUAL_P (t))
1123 print_identifier (scratch_buffer, "virtual ");
1125 /* Print the return type? */
1127 show_return = !DECL_CONV_FN_P (t) && !DECL_CONSTRUCTOR_P (t)
1128 && !DECL_DESTRUCTOR_P (t);
1131 dump_type_prefix (TREE_TYPE (fntype), flags);
1132 output_add_space (scratch_buffer);
1135 /* Print the function name. */
1138 dump_type (cname, flags);
1139 print_scope_operator (scratch_buffer);
1142 dump_scope (CP_DECL_CONTEXT (t), flags);
1144 dump_function_name (t, flags);
1148 dump_parameters (parmtypes, flags);
1150 if (TREE_CODE (fntype) == METHOD_TYPE)
1151 dump_qualifiers (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype))),
1154 if (flags & TFF_EXCEPTION_SPECIFICATION)
1155 dump_exception_spec (TYPE_RAISES_EXCEPTIONS (fntype), flags);
1158 dump_type_suffix (TREE_TYPE (fntype), flags);
1161 /* If T is a template instantiation, dump the parameter binding. */
1162 if (template_parms != NULL_TREE && template_args != NULL_TREE)
1164 output_add_string (scratch_buffer, " [with ");
1165 dump_template_bindings (template_parms, template_args);
1166 print_right_bracket (scratch_buffer);
1170 /* Print a parameter list. If this is for a member function, the
1171 member object ptr (and any other hidden args) should have
1172 already been removed. */
1175 dump_parameters (parmtypes, flags)
1181 print_left_paren (scratch_buffer);
1183 for (first = 1; parmtypes != void_list_node;
1184 parmtypes = TREE_CHAIN (parmtypes))
1187 separate_with_comma (scratch_buffer);
1191 print_identifier (scratch_buffer, "...");
1194 dump_type (TREE_VALUE (parmtypes), flags);
1196 if ((flags & TFF_FUNCTION_DEFAULT_ARGUMENTS) && TREE_PURPOSE (parmtypes))
1198 output_add_string (scratch_buffer, " = ");
1199 dump_expr (TREE_PURPOSE (parmtypes), flags | TFF_EXPR_IN_PARENS);
1203 print_right_paren (scratch_buffer);
1206 /* Print an exception specification. T is the exception specification. */
1209 dump_exception_spec (t, flags)
1215 output_add_string (scratch_buffer, " throw (");
1216 if (TREE_VALUE (t) != NULL_TREE)
1219 dump_type (TREE_VALUE (t), flags);
1223 separate_with_comma (scratch_buffer);
1225 print_right_paren (scratch_buffer);
1229 /* Handle the function name for a FUNCTION_DECL node, grokking operators
1230 and destructors properly. */
1233 dump_function_name (t, flags)
1237 tree name = DECL_NAME (t);
1239 /* Don't let the user see __comp_ctor et al. */
1240 if (DECL_CONSTRUCTOR_P (t)
1241 || DECL_DESTRUCTOR_P (t))
1242 name = constructor_name (DECL_CONTEXT (t));
1244 if (DECL_DESTRUCTOR_P (t))
1246 output_add_character (scratch_buffer, '~');
1247 dump_decl (name, TFF_PLAIN_IDENTIFIER);
1249 else if (DECL_CONV_FN_P (t))
1251 /* This cannot use the hack that the operator's return
1252 type is stashed off of its name because it may be
1253 used for error reporting. In the case of conflicting
1254 declarations, both will have the same name, yet
1255 the types will be different, hence the TREE_TYPE field
1256 of the first name will be clobbered by the second. */
1257 output_add_string (scratch_buffer, "operator ");
1258 dump_type (TREE_TYPE (TREE_TYPE (t)), flags);
1260 else if (IDENTIFIER_OPNAME_P (name))
1261 print_tree_identifier (scratch_buffer, name);
1263 dump_decl (name, flags);
1265 if (DECL_LANG_SPECIFIC (t) && DECL_TEMPLATE_INFO (t)
1266 && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t)
1267 && (DECL_TEMPLATE_SPECIALIZATION (t)
1268 || TREE_CODE (DECL_TI_TEMPLATE (t)) != TEMPLATE_DECL
1269 || DECL_TEMPLATE_SPECIALIZATION (DECL_TI_TEMPLATE (t))
1270 || PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t))))
1271 dump_template_parms (DECL_TEMPLATE_INFO (t), !DECL_USE_TEMPLATE (t), flags);
1274 /* Dump the template parameters from the template info INFO under control of
1275 FLAGS. PRIMARY indicates whether this is a primary template decl, or
1276 specialization (partial or complete). For partial specializations we show
1277 the specialized parameter values. For a primary template we show no
1281 dump_template_parms (info, primary, flags)
1286 tree args = info ? TI_ARGS (info) : NULL_TREE;
1288 if (primary && flags & TFF_TEMPLATE_NAME)
1290 flags &= ~(TFF_CLASS_KEY_OR_ENUM | TFF_TEMPLATE_NAME);
1291 print_template_argument_list_start (scratch_buffer);
1293 /* Be careful only to print things when we have them, so as not
1294 to crash producing error messages. */
1295 if (args && !primary)
1301 if (TREE_CODE (args) == TREE_VEC)
1303 if (TREE_VEC_LENGTH (args) > 0
1304 && TREE_CODE (TREE_VEC_ELT (args, 0)) == TREE_VEC)
1305 args = TREE_VEC_ELT (args, TREE_VEC_LENGTH (args) - 1);
1307 len = TREE_VEC_LENGTH (args);
1309 else if (TREE_CODE (args) == TREE_LIST)
1311 while (ix != len && args)
1316 arg = TREE_VEC_ELT (args, ix);
1321 arg = TREE_VALUE (args);
1322 args = TREE_CHAIN (args);
1325 separate_with_comma (scratch_buffer);
1328 print_identifier (scratch_buffer, "<template parameter error>");
1330 dump_template_argument (arg, flags);
1336 tree tpl = TI_TEMPLATE (info);
1337 tree parms = DECL_TEMPLATE_PARMS (tpl);
1340 parms = TREE_CODE (parms) == TREE_LIST ? TREE_VALUE (parms) : NULL_TREE;
1341 len = parms ? TREE_VEC_LENGTH (parms) : 0;
1343 for (ix = 0; ix != len; ix++)
1345 tree parm = TREE_VALUE (TREE_VEC_ELT (parms, ix));
1348 separate_with_comma (scratch_buffer);
1350 dump_decl (parm, flags & ~TFF_DECL_SPECIFIERS);
1353 print_template_argument_list_end (scratch_buffer);
1362 case TARGET_NEWLINE:
1363 output_add_string (scratch_buffer, "\\n");
1366 output_add_string (scratch_buffer, "\\t");
1369 output_add_string (scratch_buffer, "\\v");
1372 output_add_string (scratch_buffer, "\\b");
1375 output_add_string (scratch_buffer, "\\r");
1378 output_add_string (scratch_buffer, "\\f");
1381 output_add_string (scratch_buffer, "\\a");
1384 output_add_string (scratch_buffer, "\\\\");
1387 output_add_string (scratch_buffer, "\\'");
1390 output_add_string (scratch_buffer, "\\\"");
1394 output_add_character (scratch_buffer, c);
1397 sprintf (digit_buffer, "\\%03o", (int) c);
1398 output_add_string (scratch_buffer, digit_buffer);
1403 /* Print out a list of initializers (subr of dump_expr) */
1406 dump_expr_list (l, flags)
1412 dump_expr (TREE_VALUE (l), flags | TFF_EXPR_IN_PARENS);
1415 separate_with_comma (scratch_buffer);
1419 /* Print out an expression E under control of FLAGS. */
1422 dump_expr (t, flags)
1426 switch (TREE_CODE (t))
1434 case NAMESPACE_DECL:
1436 dump_decl (t, flags & ~TFF_DECL_SPECIFIERS);
1441 tree type = TREE_TYPE (t);
1442 my_friendly_assert (type != 0, 81);
1444 /* If it's an enum, output its tag, rather than its value. */
1445 if (TREE_CODE (type) == ENUMERAL_TYPE)
1447 tree values = TYPE_VALUES (type);
1450 values = TREE_CHAIN (values))
1451 if (tree_int_cst_equal (TREE_VALUE (values), t))
1455 print_tree_identifier (scratch_buffer, TREE_PURPOSE (values));
1458 /* Value must have been cast. */
1459 print_left_paren (scratch_buffer);
1460 dump_type (type, flags);
1461 print_right_paren (scratch_buffer);
1465 else if (type == boolean_type_node)
1467 if (t == boolean_false_node || integer_zerop (t))
1468 print_identifier (scratch_buffer, "false");
1469 else if (t == boolean_true_node)
1470 print_identifier (scratch_buffer, "true");
1472 else if (type == char_type_node)
1474 output_add_character (scratch_buffer, '\'');
1475 dump_char (tree_low_cst (t, 0));
1476 output_add_character (scratch_buffer, '\'');
1481 if (! host_integerp (t, 0))
1485 if (tree_int_cst_sgn (val) < 0)
1487 output_add_character (scratch_buffer, '-');
1488 val = build_int_2 (-TREE_INT_CST_LOW (val),
1489 ~TREE_INT_CST_HIGH (val)
1490 + !TREE_INT_CST_LOW (val));
1492 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
1495 static char format[10]; /* "%x%09999x\0" */
1497 sprintf (format, "%%x%%0%dx", HOST_BITS_PER_INT / 4);
1498 sprintf (digit_buffer, format, TREE_INT_CST_HIGH (val),
1499 TREE_INT_CST_LOW (val));
1500 output_add_string (scratch_buffer, digit_buffer);
1504 print_integer (scratch_buffer, TREE_INT_CST_LOW (t));
1510 #ifndef REAL_IS_NOT_DOUBLE
1511 sprintf (digit_buffer, "%g", TREE_REAL_CST (t));
1514 const unsigned char *p = (const unsigned char *) &TREE_REAL_CST (t);
1516 strcpy (digit_buffer, "0x");
1517 for (i = 0; i < sizeof TREE_REAL_CST (t); i++)
1518 sprintf (digit_buffer + 2 + 2*i, "%02x", *p++);
1521 output_add_string (scratch_buffer, digit_buffer);
1525 output_add_character (scratch_buffer, '&');
1526 dump_type (PTRMEM_CST_CLASS (t), flags);
1527 print_scope_operator (scratch_buffer);
1528 print_tree_identifier
1529 (scratch_buffer, DECL_NAME (PTRMEM_CST_MEMBER (t)));
1534 const char *p = TREE_STRING_POINTER (t);
1535 int len = TREE_STRING_LENGTH (t) - 1;
1538 output_add_character (scratch_buffer, '\"');
1539 for (i = 0; i < len; i++)
1541 output_add_character (scratch_buffer, '\"');
1546 print_left_paren (scratch_buffer);
1547 dump_expr (TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
1548 separate_with_comma (scratch_buffer);
1549 dump_expr (TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS);
1550 print_right_paren (scratch_buffer);
1554 print_left_paren (scratch_buffer);
1555 dump_expr (TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
1556 output_add_string (scratch_buffer, " ? ");
1557 dump_expr (TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS);
1558 output_add_string (scratch_buffer, " : ");
1559 dump_expr (TREE_OPERAND (t, 2), flags | TFF_EXPR_IN_PARENS);
1560 print_right_paren (scratch_buffer);
1564 if (TREE_HAS_CONSTRUCTOR (t))
1566 output_add_string (scratch_buffer, "new ");
1567 dump_type (TREE_TYPE (TREE_TYPE (t)), flags);
1571 dump_expr (TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
1575 case AGGR_INIT_EXPR:
1577 tree fn = NULL_TREE;
1579 if (TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR)
1580 fn = TREE_OPERAND (TREE_OPERAND (t, 0), 0);
1582 if (fn && TREE_CODE (fn) == FUNCTION_DECL)
1584 if (DECL_CONSTRUCTOR_P (fn))
1585 print_tree_identifier
1586 (scratch_buffer, TYPE_IDENTIFIER (TREE_TYPE (t)));
1591 dump_expr (TREE_OPERAND (t, 0), 0);
1593 print_left_paren (scratch_buffer);
1594 if (TREE_OPERAND (t, 1))
1595 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)), flags);
1596 print_right_paren (scratch_buffer);
1601 tree fn = TREE_OPERAND (t, 0);
1602 tree args = TREE_OPERAND (t, 1);
1604 if (TREE_CODE (fn) == ADDR_EXPR)
1605 fn = TREE_OPERAND (fn, 0);
1607 if (TREE_TYPE (fn) != NULL_TREE && NEXT_CODE (fn) == METHOD_TYPE)
1609 tree ob = TREE_VALUE (args);
1610 if (TREE_CODE (ob) == ADDR_EXPR)
1612 dump_expr (TREE_OPERAND (ob, 0), flags | TFF_EXPR_IN_PARENS);
1613 output_add_character (scratch_buffer, '.');
1615 else if (TREE_CODE (ob) != PARM_DECL
1616 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
1618 dump_expr (ob, flags | TFF_EXPR_IN_PARENS);
1619 output_add_string (scratch_buffer, "->");
1621 args = TREE_CHAIN (args);
1623 dump_expr (fn, flags | TFF_EXPR_IN_PARENS);
1624 print_left_paren (scratch_buffer);
1625 dump_expr_list (args, flags);
1626 print_right_paren (scratch_buffer);
1632 tree type = TREE_OPERAND (t, 1);
1633 if (NEW_EXPR_USE_GLOBAL (t))
1634 print_scope_operator (scratch_buffer);
1635 output_add_string (scratch_buffer, "new ");
1636 if (TREE_OPERAND (t, 0))
1638 print_left_paren (scratch_buffer);
1639 dump_expr_list (TREE_OPERAND (t, 0), flags);
1640 output_add_string (scratch_buffer, ") ");
1642 if (TREE_CODE (type) == ARRAY_REF)
1643 type = build_cplus_array_type
1644 (TREE_OPERAND (type, 0),
1645 build_index_type (fold (build (MINUS_EXPR, integer_type_node,
1646 TREE_OPERAND (type, 1),
1647 integer_one_node))));
1648 dump_type (type, flags);
1649 if (TREE_OPERAND (t, 2))
1651 print_left_paren (scratch_buffer);
1652 dump_expr_list (TREE_OPERAND (t, 2), flags);
1653 print_right_paren (scratch_buffer);
1659 /* Note that this only works for G++ target exprs. If somebody
1660 builds a general TARGET_EXPR, there's no way to represent that
1661 it initializes anything other that the parameter slot for the
1662 default argument. Note we may have cleared out the first
1663 operand in expand_expr, so don't go killing ourselves. */
1664 if (TREE_OPERAND (t, 1))
1665 dump_expr (TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS);
1673 case TRUNC_DIV_EXPR:
1674 case TRUNC_MOD_EXPR:
1682 case BIT_ANDTC_EXPR:
1683 case TRUTH_ANDIF_EXPR:
1684 case TRUTH_ORIF_EXPR:
1691 case EXACT_DIV_EXPR:
1692 dump_binary_op (operator_name_info[(int) TREE_CODE (t)].name, t, flags);
1696 case FLOOR_DIV_EXPR:
1697 case ROUND_DIV_EXPR:
1698 dump_binary_op ("/", t, flags);
1702 case FLOOR_MOD_EXPR:
1703 case ROUND_MOD_EXPR:
1704 dump_binary_op ("%", t, flags);
1709 tree ob = TREE_OPERAND (t, 0);
1710 if (TREE_CODE (ob) == INDIRECT_REF)
1712 ob = TREE_OPERAND (ob, 0);
1713 if (TREE_CODE (ob) != PARM_DECL
1714 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
1716 dump_expr (ob, flags | TFF_EXPR_IN_PARENS);
1717 output_add_string (scratch_buffer, "->");
1722 dump_expr (ob, flags | TFF_EXPR_IN_PARENS);
1723 output_add_character (scratch_buffer, '.');
1725 dump_expr (TREE_OPERAND (t, 1), flags & ~TFF_EXPR_IN_PARENS);
1730 dump_expr (TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
1731 print_left_bracket (scratch_buffer);
1732 dump_expr (TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS);
1733 print_right_bracket (scratch_buffer);
1737 if (VOID_TYPE_P (TREE_TYPE (t)))
1739 print_left_paren (scratch_buffer);
1740 dump_type (TREE_TYPE (t), flags);
1741 print_right_paren (scratch_buffer);
1742 dump_expr (TREE_OPERAND (t, 0), flags);
1745 dump_unary_op ("+", t, flags);
1749 if (TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
1750 || TREE_CODE (TREE_OPERAND (t, 0)) == STRING_CST
1751 /* An ADDR_EXPR can have reference type. In that case, we
1752 shouldn't print the `&' doing so indicates to the user
1753 that the expression has pointer type. */
1755 && TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE))
1756 dump_expr (TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
1758 dump_unary_op ("&", t, flags);
1762 if (TREE_HAS_CONSTRUCTOR (t))
1764 t = TREE_OPERAND (t, 0);
1765 my_friendly_assert (TREE_CODE (t) == CALL_EXPR, 237);
1766 dump_expr (TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
1767 print_left_paren (scratch_buffer);
1768 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)), flags);
1769 print_right_paren (scratch_buffer);
1773 if (TREE_OPERAND (t,0) != NULL_TREE
1774 && TREE_TYPE (TREE_OPERAND (t, 0))
1775 && NEXT_CODE (TREE_OPERAND (t, 0)) == REFERENCE_TYPE)
1776 dump_expr (TREE_OPERAND (t, 0), flags);
1778 dump_unary_op ("*", t, flags);
1784 case TRUTH_NOT_EXPR:
1785 case PREDECREMENT_EXPR:
1786 case PREINCREMENT_EXPR:
1787 dump_unary_op (operator_name_info [(int)TREE_CODE (t)].name, t, flags);
1790 case POSTDECREMENT_EXPR:
1791 case POSTINCREMENT_EXPR:
1792 print_left_paren (scratch_buffer);
1793 dump_expr (TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
1795 (scratch_buffer, operator_name_info[(int)TREE_CODE (t)].name);
1796 print_right_paren (scratch_buffer);
1799 case NON_LVALUE_EXPR:
1800 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
1801 should be another level of INDIRECT_REF so that I don't have to do
1803 if (TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == POINTER_TYPE)
1805 tree next = TREE_TYPE (TREE_TYPE (t));
1807 while (TREE_CODE (next) == POINTER_TYPE)
1808 next = TREE_TYPE (next);
1810 if (TREE_CODE (next) == FUNCTION_TYPE)
1812 if (flags & TFF_EXPR_IN_PARENS)
1813 print_left_paren (scratch_buffer);
1814 output_add_character (scratch_buffer, '*');
1815 dump_expr (TREE_OPERAND (t, 0), flags & ~TFF_EXPR_IN_PARENS);
1816 if (flags & TFF_EXPR_IN_PARENS)
1817 print_right_paren (scratch_buffer);
1822 dump_expr (TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
1826 dump_expr (TREE_OPERAND (t, 0), flags);
1829 case EXPR_WITH_FILE_LOCATION:
1830 dump_expr (EXPR_WFL_NODE (t), flags);
1834 if (TREE_TYPE (t) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t)))
1836 tree idx = build_component_ref (t, pfn_identifier, NULL_TREE, 0);
1838 if (integer_zerop (idx))
1840 /* A NULL pointer-to-member constant. */
1841 output_add_string (scratch_buffer, "((");
1842 dump_type (TREE_TYPE (t), flags);
1843 output_add_string (scratch_buffer, ") 0)");
1846 else if (host_integerp (idx, 0))
1849 unsigned HOST_WIDE_INT n;
1851 t = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t)));
1852 t = TYPE_METHOD_BASETYPE (t);
1853 virtuals = TYPE_BINFO_VIRTUALS (TYPE_MAIN_VARIANT (t));
1855 n = tree_low_cst (idx, 0);
1857 /* Map vtable index back one, to allow for the null pointer to
1861 while (n > 0 && virtuals)
1864 virtuals = TREE_CHAIN (virtuals);
1868 dump_expr (BV_FN (virtuals),
1869 flags | TFF_EXPR_IN_PARENS);
1874 output_add_character (scratch_buffer, '{');
1875 dump_expr_list (CONSTRUCTOR_ELTS (t), flags);
1876 output_add_character (scratch_buffer, '}');
1881 tree ob = TREE_OPERAND (t, 0);
1882 if (is_dummy_object (ob))
1884 t = TREE_OPERAND (t, 1);
1885 if (TREE_CODE (t) == FUNCTION_DECL)
1887 dump_expr (t, flags | TFF_EXPR_IN_PARENS);
1888 else if (BASELINK_P (t))
1889 dump_expr (OVL_CURRENT (TREE_VALUE (t)), flags | TFF_EXPR_IN_PARENS);
1891 dump_decl (t, flags);
1895 if (TREE_CODE (ob) == INDIRECT_REF)
1897 dump_expr (TREE_OPERAND (ob, 0), flags | TFF_EXPR_IN_PARENS);
1898 output_add_string (scratch_buffer, "->*");
1902 dump_expr (ob, flags | TFF_EXPR_IN_PARENS);
1903 output_add_string (scratch_buffer, ".*");
1905 dump_expr (TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS);
1910 case TEMPLATE_PARM_INDEX:
1911 dump_decl (TEMPLATE_PARM_DECL (t), flags & ~TFF_DECL_SPECIFIERS);
1914 case IDENTIFIER_NODE:
1915 print_tree_identifier (scratch_buffer, t);
1919 dump_type (TREE_OPERAND (t, 0), flags);
1920 print_scope_operator (scratch_buffer);
1921 dump_expr (TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS);
1925 if (TREE_OPERAND (t, 0) == NULL_TREE
1926 || TREE_CHAIN (TREE_OPERAND (t, 0)))
1928 dump_type (TREE_TYPE (t), flags);
1929 print_left_paren (scratch_buffer);
1930 dump_expr_list (TREE_OPERAND (t, 0), flags);
1931 print_right_paren (scratch_buffer);
1935 print_left_paren (scratch_buffer);
1936 dump_type (TREE_TYPE (t), flags);
1937 output_add_string (scratch_buffer, ")(");
1938 dump_expr_list (TREE_OPERAND (t, 0), flags);
1939 print_right_paren (scratch_buffer);
1943 case STATIC_CAST_EXPR:
1944 output_add_string (scratch_buffer, "static_cast<");
1946 case REINTERPRET_CAST_EXPR:
1947 output_add_string (scratch_buffer, "reinterpret_cast<");
1949 case CONST_CAST_EXPR:
1950 output_add_string (scratch_buffer, "const_cast<");
1952 case DYNAMIC_CAST_EXPR:
1953 output_add_string (scratch_buffer, "dynamic_cast<");
1955 dump_type (TREE_TYPE (t), flags);
1956 output_add_string (scratch_buffer, ">(");
1957 dump_expr (TREE_OPERAND (t, 0), flags);
1958 print_right_paren (scratch_buffer);
1962 print_tree_identifier (scratch_buffer, TREE_OPERAND (t, 0));
1966 dump_expr (TREE_OPERAND (t, 0), flags);
1967 output_add_string (scratch_buffer, "->");
1972 if (TREE_CODE (t) == SIZEOF_EXPR)
1973 output_add_string (scratch_buffer, "sizeof (");
1976 my_friendly_assert (TREE_CODE (t) == ALIGNOF_EXPR, 0);
1977 output_add_string (scratch_buffer, "__alignof__ (");
1979 if (TYPE_P (TREE_OPERAND (t, 0)))
1980 dump_type (TREE_OPERAND (t, 0), flags);
1982 dump_unary_op ("*", t, flags | TFF_EXPR_IN_PARENS);
1983 print_right_paren (scratch_buffer);
1987 print_identifier (scratch_buffer, "<unparsed>");
1990 case TRY_CATCH_EXPR:
1991 case WITH_CLEANUP_EXPR:
1992 case CLEANUP_POINT_EXPR:
1993 dump_expr (TREE_OPERAND (t, 0), flags);
1996 case PSEUDO_DTOR_EXPR:
1997 dump_expr (TREE_OPERAND (t, 2), flags);
1998 output_add_character (scratch_buffer, '.');
1999 dump_type (TREE_OPERAND (t, 0), flags);
2000 output_add_string (scratch_buffer, "::~");
2001 dump_type (TREE_OPERAND (t, 1), flags);
2004 case TEMPLATE_ID_EXPR:
2005 dump_decl (t, flags);
2009 /* We don't yet have a way of dumping statements in a
2010 human-readable format. */
2011 output_add_string (scratch_buffer, "({...})");
2015 output_add_character (scratch_buffer, '{');
2016 dump_expr (TREE_OPERAND (t, 1), flags & ~TFF_EXPR_IN_PARENS);
2017 output_add_character (scratch_buffer, '}');
2021 output_add_string (scratch_buffer, "while (1) { ");
2022 dump_expr (TREE_OPERAND (t, 0), flags & ~TFF_EXPR_IN_PARENS);
2023 output_add_character (scratch_buffer, '}');
2027 output_add_string (scratch_buffer, "if (");
2028 dump_expr (TREE_OPERAND (t, 0), flags & ~TFF_EXPR_IN_PARENS);
2029 output_add_string (scratch_buffer, ") break; ");
2033 if (TREE_VALUE (t) && TREE_CODE (TREE_VALUE (t)) == FUNCTION_DECL)
2035 print_tree_identifier (scratch_buffer, DECL_NAME (TREE_VALUE (t)));
2038 /* else fall through */
2040 /* This list is incomplete, but should suffice for now.
2041 It is very important that `sorry' does not call
2042 `report_error_function'. That could cause an infinite loop. */
2044 sorry_for_unsupported_tree (t);
2045 /* fall through to ERROR_MARK... */
2047 print_identifier (scratch_buffer, "<expression error>");
2053 dump_binary_op (opstring, t, flags)
2054 const char *opstring;
2058 print_left_paren (scratch_buffer);
2059 dump_expr (TREE_OPERAND (t, 0), flags | TFF_EXPR_IN_PARENS);
2060 output_add_space (scratch_buffer);
2062 print_identifier (scratch_buffer, opstring);
2064 print_identifier (scratch_buffer, "<unknown operator>");
2065 output_add_space (scratch_buffer);
2066 dump_expr (TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS);
2067 print_right_paren (scratch_buffer);
2071 dump_unary_op (opstring, t, flags)
2072 const char *opstring;
2076 if (flags & TFF_EXPR_IN_PARENS)
2077 print_left_paren (scratch_buffer);
2078 print_identifier (scratch_buffer, opstring);
2079 dump_expr (TREE_OPERAND (t, 0), flags & ~TFF_EXPR_IN_PARENS);
2080 if (flags & TFF_EXPR_IN_PARENS)
2081 print_right_paren (scratch_buffer);
2084 /* Exported interface to stringifying types, exprs and decls under TFF_*
2088 type_as_string (typ, flags)
2092 reinit_global_formatting_buffer ();
2094 dump_type (typ, flags);
2096 return output_finalize_message (scratch_buffer);
2100 expr_as_string (decl, flags)
2104 reinit_global_formatting_buffer ();
2106 dump_expr (decl, flags);
2108 return output_finalize_message (scratch_buffer);
2112 decl_as_string (decl, flags)
2116 reinit_global_formatting_buffer ();
2118 dump_decl (decl, flags);
2120 return output_finalize_message (scratch_buffer);
2124 context_as_string (context, flags)
2128 reinit_global_formatting_buffer ();
2130 dump_scope (context, flags);
2132 return output_finalize_message (scratch_buffer);
2135 /* Generate the three forms of printable names for lang_printable_name. */
2138 lang_decl_name (decl, v)
2143 return decl_as_string (decl, TFF_DECL_SPECIFIERS);
2145 reinit_global_formatting_buffer ();
2147 if (v == 1 && DECL_CLASS_SCOPE_P (decl))
2149 dump_type (CP_DECL_CONTEXT (decl), TFF_PLAIN_IDENTIFIER);
2150 print_scope_operator (scratch_buffer);
2153 if (TREE_CODE (decl) == FUNCTION_DECL)
2154 dump_function_name (decl, TFF_PLAIN_IDENTIFIER);
2156 dump_decl (DECL_NAME (decl), TFF_PLAIN_IDENTIFIER);
2158 return output_finalize_message (scratch_buffer);
2165 if (TREE_CODE (t) == PARM_DECL && DECL_CONTEXT (t))
2166 return DECL_SOURCE_FILE (DECL_CONTEXT (t));
2167 else if (TYPE_P (t))
2168 return DECL_SOURCE_FILE (TYPE_MAIN_DECL (t));
2169 else if (TREE_CODE (t) == OVERLOAD)
2170 return DECL_SOURCE_FILE (OVL_FUNCTION (t));
2172 return DECL_SOURCE_FILE (t);
2180 if (TREE_CODE (t) == PARM_DECL && DECL_CONTEXT (t))
2181 line = DECL_SOURCE_LINE (DECL_CONTEXT (t));
2182 if (TREE_CODE (t) == TYPE_DECL && DECL_ARTIFICIAL (t)
2183 && TYPE_MAIN_DECL (TREE_TYPE (t)))
2187 line = DECL_SOURCE_LINE (TYPE_MAIN_DECL (t));
2188 else if (TREE_CODE (t) == OVERLOAD)
2189 line = DECL_SOURCE_LINE (OVL_FUNCTION (t));
2191 line = DECL_SOURCE_LINE (t);
2199 /* Now the interfaces from error et al to dump_type et al. Each takes an
2200 on/off VERBOSE flag and supply the appropriate TFF_ flags to a dump_
2204 decl_to_string (decl, verbose)
2210 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == RECORD_TYPE
2211 || TREE_CODE (decl) == UNION_TYPE || TREE_CODE (decl) == ENUMERAL_TYPE)
2212 flags = TFF_CLASS_KEY_OR_ENUM;
2214 flags |= TFF_DECL_SPECIFIERS | TFF_FUNCTION_DEFAULT_ARGUMENTS;
2215 else if (TREE_CODE (decl) == FUNCTION_DECL)
2216 flags |= TFF_DECL_SPECIFIERS | TFF_RETURN_TYPE;
2217 flags |= TFF_TEMPLATE_HEADER;
2219 reinit_global_formatting_buffer ();
2221 dump_decl (decl, flags);
2223 return output_finalize_message (scratch_buffer);
2227 expr_to_string (decl, verbose)
2229 int verbose ATTRIBUTE_UNUSED;
2231 reinit_global_formatting_buffer ();
2233 dump_expr (decl, 0);
2235 return output_finalize_message (scratch_buffer);
2239 fndecl_to_string (fndecl, verbose)
2245 flags = TFF_EXCEPTION_SPECIFICATION | TFF_DECL_SPECIFIERS;
2247 flags |= TFF_FUNCTION_DEFAULT_ARGUMENTS;
2248 reinit_global_formatting_buffer ();
2250 dump_decl (fndecl, flags);
2252 return output_finalize_message (scratch_buffer);
2257 code_to_string (c, v)
2259 int v ATTRIBUTE_UNUSED;
2261 return tree_code_name [c];
2265 language_to_string (c, v)
2267 int v ATTRIBUTE_UNUSED;
2274 case lang_cplusplus:
2286 /* Return the proper printed version of a parameter to a C++ function. */
2289 parm_to_string (p, v)
2291 int v ATTRIBUTE_UNUSED;
2296 sprintf (digit_buffer, "%d", p+1);
2297 return digit_buffer;
2303 int v ATTRIBUTE_UNUSED;
2307 id = operator_name_info[(int) p].identifier;
2308 return id ? IDENTIFIER_POINTER (id) : "{unknown}";
2312 type_to_string (typ, verbose)
2320 flags |= TFF_CLASS_KEY_OR_ENUM;
2321 flags |= TFF_TEMPLATE_HEADER;
2323 reinit_global_formatting_buffer ();
2325 dump_type (typ, flags);
2327 return output_finalize_message (scratch_buffer);
2331 assop_to_string (p, v)
2333 int v ATTRIBUTE_UNUSED;
2337 id = assignment_operator_name_info[(int) p].identifier;
2338 return id ? IDENTIFIER_POINTER (id) : "{unknown}";
2342 args_to_string (p, verbose)
2348 flags |= TFF_CLASS_KEY_OR_ENUM;
2353 if (TYPE_P (TREE_VALUE (p)))
2354 return type_as_string (p, flags);
2356 reinit_global_formatting_buffer ();
2357 for (; p; p = TREE_CHAIN (p))
2359 if (TREE_VALUE (p) == null_node)
2360 print_identifier (scratch_buffer, "NULL");
2362 dump_type (error_type (TREE_VALUE (p)), flags);
2364 separate_with_comma (scratch_buffer);
2366 return output_finalize_message (scratch_buffer);
2374 reinit_global_formatting_buffer ();
2376 dump_qualifiers (p, v ? before : none);
2378 return output_finalize_message (scratch_buffer);
2382 lang_print_error_function (context, file)
2383 diagnostic_context *context;
2388 default_print_error_function (context, file);
2389 os = output_buffer_state (context);
2390 output_set_prefix ((output_buffer *)context, file);
2391 maybe_print_instantiation_context ((output_buffer *)context);
2392 output_buffer_state (context) = os;
2396 cp_diagnostic_starter (buffer, dc)
2397 output_buffer *buffer;
2398 diagnostic_context *dc;
2400 report_problematic_module (buffer);
2401 cp_print_error_function (buffer, dc);
2402 maybe_print_instantiation_context (buffer);
2403 output_set_prefix (buffer,
2404 context_as_prefix (diagnostic_file_location (dc),
2405 diagnostic_line_location (dc),
2406 diagnostic_is_warning (dc)));
2410 cp_diagnostic_finalizer (buffer, dc)
2411 output_buffer *buffer;
2412 diagnostic_context *dc __attribute__ ((__unused__));
2414 output_destroy_prefix (buffer);
2417 /* Print current function onto BUFFER, in the process of reporting
2418 a diagnostic message. Called from cp_diagnostic_starter. */
2420 cp_print_error_function (buffer, dc)
2421 output_buffer *buffer;
2422 diagnostic_context *dc;
2424 if (error_function_changed ())
2426 char *prefix = diagnostic_file_location (dc)
2427 ? file_name_as_prefix (diagnostic_file_location (dc))
2431 os = output_buffer_state (buffer);
2432 output_set_prefix (buffer, prefix);
2434 if (current_function_decl == NULL)
2435 output_add_string (buffer, "At global scope:");
2438 (buffer, "In %s `%s':", function_category (current_function_decl),
2439 (*decl_printable_name) (current_function_decl, 2));
2440 output_add_newline (buffer);
2442 record_last_error_function ();
2443 output_destroy_prefix (buffer);
2444 output_buffer_state (buffer) = os;
2448 /* Returns a description of FUNCTION using standard terminology. */
2450 function_category (fn)
2453 if (DECL_FUNCTION_MEMBER_P (fn))
2455 if (DECL_STATIC_FUNCTION_P (fn))
2456 return "static member function";
2457 else if (DECL_COPY_CONSTRUCTOR_P (fn))
2458 return "copy constructor";
2459 else if (DECL_CONSTRUCTOR_P (fn))
2460 return "constructor";
2461 else if (DECL_DESTRUCTOR_P (fn))
2462 return "destructor";
2464 return "member function";
2470 /* Report the full context of a current template instantiation,
2473 print_instantiation_full_context (buffer)
2474 output_buffer *buffer;
2476 tree p = current_instantiation ();
2478 const char *file = input_filename;
2482 if (current_function_decl != TINST_DECL (p)
2483 && current_function_decl != NULL_TREE)
2484 /* We can get here during the processing of some synthesized
2485 method. Then, TINST_DECL (p) will be the function that's causing
2490 if (current_function_decl == TINST_DECL (p))
2491 /* Avoid redundancy with the the "In function" line. */;
2493 output_verbatim (buffer, "%s: In instantiation of `%s':\n", file,
2494 decl_as_string (TINST_DECL (p),
2495 TFF_DECL_SPECIFIERS | TFF_RETURN_TYPE));
2497 line = TINST_LINE (p);
2498 file = TINST_FILE (p);
2503 print_instantiation_partial_context (buffer, p, file, line);
2506 /* Same as above but less verbose. */
2508 print_instantiation_partial_context (buffer, t, file, line)
2509 output_buffer *buffer;
2514 for (; t; t = TREE_CHAIN (t))
2517 (buffer, "%s:%d: instantiated from `%s'\n", file, line,
2518 decl_as_string (TINST_DECL (t), TFF_DECL_SPECIFIERS | TFF_RETURN_TYPE));
2519 line = TINST_LINE (t);
2520 file = TINST_FILE (t);
2522 output_verbatim (buffer, "%s:%d: instantiated from here\n", file, line);
2525 /* Called from cp_thing to print the template context for an error. */
2527 maybe_print_instantiation_context (buffer)
2528 output_buffer *buffer;
2530 if (!problematic_instantiation_changed () || current_instantiation () == 0)
2533 record_last_problematic_instantiation ();
2534 print_instantiation_full_context (buffer);
2537 /* Report the bare minimum context of a template instantiation. */
2539 print_instantiation_context ()
2541 print_instantiation_partial_context
2542 (diagnostic_buffer, current_instantiation (), input_filename, lineno);
2543 flush_diagnostic_buffer ();
2546 /* Called from output_format -- during diagnostic message processing --
2547 to handle C++ specific format specifier with the following meanings:
2548 %A function argument-list.
2552 %F function declaration.
2553 %L language as used in extern "lang".
2555 %P function parameter whose position is indicated by an integer.
2556 %Q assignment operator.
2561 output_buffer *buffer;
2565 #define next_tree va_arg (output_buffer_format_args (buffer), tree)
2566 #define next_tcode va_arg (output_buffer_format_args (buffer), enum tree_code)
2567 #define next_lang va_arg (output_buffer_format_args (buffer), enum languages)
2568 #define next_int va_arg (output_buffer_format_args (buffer), int)
2570 if (*output_buffer_text_cursor (buffer) == '+')
2571 ++output_buffer_text_cursor (buffer);
2572 if (*output_buffer_text_cursor (buffer) == '#')
2575 ++output_buffer_text_cursor (buffer);
2578 switch (*output_buffer_text_cursor (buffer))
2580 case 'A': result = args_to_string (next_tree, verbose); break;
2581 case 'C': result = code_to_string (next_tcode, verbose); break;
2582 case 'D': result = decl_to_string (next_tree, verbose); break;
2583 case 'E': result = expr_to_string (next_tree, verbose); break;
2584 case 'F': result = fndecl_to_string (next_tree, verbose); break;
2585 case 'L': result = language_to_string (next_lang, verbose); break;
2586 case 'O': result = op_to_string (next_tcode, verbose); break;
2587 case 'P': result = parm_to_string (next_int, verbose); break;
2588 case 'Q': result = assop_to_string (next_tcode, verbose); break;
2589 case 'T': result = type_to_string (next_tree, verbose); break;
2590 case 'V': result = cv_to_string (next_tree, verbose); break;
2596 output_add_string (buffer, result);
2605 print_integer (buffer, i)
2606 output_buffer *buffer;
2609 sprintf (digit_buffer, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT) i);
2610 output_add_string (buffer, digit_buffer);
2614 print_non_consecutive_character (buffer, c)
2615 output_buffer *buffer;
2618 const char *p = output_last_position (buffer);
2620 if (p != NULL && *p == c)
2621 output_add_space (buffer);
2622 output_add_character (buffer, c);
2625 /* These are temporary wrapper functions which handle the historic
2626 behavior of cp_*_at. */
2629 locate_error (msgid, ap)
2637 for (f = msgid; *f; f++)
2650 /* Just ignore these possibilities. */
2652 case 'd': (void) va_arg (ap, int); break;
2653 case 's': (void) va_arg (ap, char *); break;
2654 case 'L': (void) va_arg (ap, enum languages); break;
2657 case 'Q': (void) va_arg (ap, enum tree_code); break;
2659 /* These take a tree, which may be where the error is
2668 t = va_arg (ap, tree);
2674 errorcount = 0; /* damn ICE suppression */
2675 internal_error ("unexpected letter `%c' in locate_error\n", *f);
2681 here = va_arg (ap, tree);
2688 cp_error_at VPARAMS ((const char *msgid, ...))
2691 diagnostic_context dc;
2693 VA_OPEN (ap, msgid);
2694 VA_FIXEDARG (ap, const char *, msgid);
2695 here = locate_error (msgid, ap);
2698 VA_OPEN (ap, msgid);
2699 VA_FIXEDARG (ap, const char *, msgid);
2701 set_diagnostic_context (&dc, msgid, &ap,
2703 cp_line_of (here), /* warning = */ 0);
2704 report_diagnostic (&dc);
2709 cp_warning_at VPARAMS ((const char *msgid, ...))
2712 diagnostic_context dc;
2714 VA_OPEN (ap, msgid);
2715 VA_FIXEDARG (ap, const char *, msgid);
2716 here = locate_error (msgid, ap);
2719 VA_OPEN (ap, msgid);
2720 VA_FIXEDARG (ap, const char *, msgid);
2722 set_diagnostic_context (&dc, msgid, &ap,
2724 cp_line_of (here), /* warning = */ 1);
2725 report_diagnostic (&dc);
2730 cp_pedwarn_at VPARAMS ((const char *msgid, ...))
2733 diagnostic_context dc;
2735 VA_OPEN (ap, msgid);
2736 VA_FIXEDARG (ap, const char *, msgid);
2737 here = locate_error (msgid, ap);
2740 VA_OPEN (ap, msgid);
2741 VA_FIXEDARG (ap, const char *, msgid);
2743 set_diagnostic_context (&dc, msgid, &ap,
2746 /* warning = */ !flag_pedantic_errors);
2747 report_diagnostic (&dc);