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"
31 #include "langhooks-def.h"
33 enum pad
{ none
, before
, after
};
35 #define sorry_for_unsupported_tree(T) \
36 sorry ("`%s' not supported by %s", tree_code_name[(int) TREE_CODE (T)], \
39 #define print_scope_operator(BUFFER) output_add_string ((BUFFER), "::")
40 #define print_left_paren(BUFFER) output_add_character ((BUFFER), '(')
41 #define print_right_paren(BUFFER) output_add_character ((BUFFER), ')')
42 #define print_left_bracket(BUFFER) output_add_character ((BUFFER), '[')
43 #define print_right_bracket(BUFFER) output_add_character ((BUFFER), ']')
44 #define print_template_argument_list_start(BUFFER) \
45 print_non_consecutive_character ((BUFFER), '<')
46 #define print_template_argument_list_end(BUFFER) \
47 print_non_consecutive_character ((BUFFER), '>')
48 #define print_whitespace(BUFFER, TFI) \
50 output_add_space (BUFFER); \
51 put_whitespace (TFI) = none; \
53 #define print_tree_identifier(BUFFER, TID) \
54 output_add_string ((BUFFER), IDENTIFIER_POINTER (TID))
55 #define print_identifier(BUFFER, ID) output_add_string ((BUFFER), (ID))
56 #define separate_with_comma(BUFFER) output_add_string ((BUFFER), ", ")
58 /* The global buffer where we dump everything. It is there only for
59 transitional purpose. It is expected, in the near future, to be
60 completely removed. */
61 static output_buffer scratch_buffer_rec
;
62 static output_buffer
*scratch_buffer
= &scratch_buffer_rec
;
64 # define NEXT_CODE(T) (TREE_CODE (TREE_TYPE (T)))
66 #define reinit_global_formatting_buffer() \
67 output_clear_message_text (scratch_buffer)
69 static const char *args_to_string
PARAMS ((tree
, int));
70 static const char *assop_to_string
PARAMS ((enum tree_code
, int));
71 static const char *code_to_string
PARAMS ((enum tree_code
, int));
72 static const char *cv_to_string
PARAMS ((tree
, int));
73 static const char *decl_to_string
PARAMS ((tree
, int));
74 static const char *expr_to_string
PARAMS ((tree
, int));
75 static const char *fndecl_to_string
PARAMS ((tree
, int));
76 static const char *op_to_string
PARAMS ((enum tree_code
, int));
77 static const char *parm_to_string
PARAMS ((int, int));
78 static const char *type_to_string
PARAMS ((tree
, int));
80 static void dump_type
PARAMS ((tree
, int));
81 static void dump_typename
PARAMS ((tree
, int));
82 static void dump_simple_decl
PARAMS ((tree
, tree
, int));
83 static void dump_decl
PARAMS ((tree
, int));
84 static void dump_template_decl
PARAMS ((tree
, int));
85 static void dump_function_decl
PARAMS ((tree
, int));
86 static void dump_expr
PARAMS ((tree
, int));
87 static void dump_unary_op
PARAMS ((const char *, tree
, int));
88 static void dump_binary_op
PARAMS ((const char *, tree
, int));
89 static void dump_aggr_type
PARAMS ((tree
, int));
90 static enum pad dump_type_prefix
PARAMS ((tree
, int));
91 static void dump_type_suffix
PARAMS ((tree
, int));
92 static void dump_function_name
PARAMS ((tree
, int));
93 static void dump_expr_list
PARAMS ((tree
, int));
94 static void dump_global_iord
PARAMS ((tree
));
95 static enum pad dump_qualifiers
PARAMS ((tree
, enum pad
));
96 static void dump_char
PARAMS ((int));
97 static void dump_parameters
PARAMS ((tree
, int));
98 static void dump_exception_spec
PARAMS ((tree
, int));
99 static const char *class_key_or_enum
PARAMS ((tree
));
100 static void dump_template_argument
PARAMS ((tree
, int));
101 static void dump_template_argument_list
PARAMS ((tree
, int));
102 static void dump_template_parameter
PARAMS ((tree
, int));
103 static void dump_template_bindings
PARAMS ((tree
, tree
));
104 static void dump_scope
PARAMS ((tree
, int));
105 static void dump_template_parms
PARAMS ((tree
, int, int));
107 static const char *function_category
PARAMS ((tree
));
108 static void maybe_print_instantiation_context
PARAMS ((output_buffer
*));
109 static void print_instantiation_full_context
PARAMS ((output_buffer
*));
110 static void print_instantiation_partial_context
PARAMS ((output_buffer
*, tree
,
112 static void cp_diagnostic_starter
PARAMS ((output_buffer
*,
113 diagnostic_context
*));
114 static void cp_diagnostic_finalizer
PARAMS ((output_buffer
*,
115 diagnostic_context
*));
116 static void cp_print_error_function
PARAMS ((output_buffer
*,
117 diagnostic_context
*));
119 static int cp_printer
PARAMS ((output_buffer
*));
120 static void print_non_consecutive_character
PARAMS ((output_buffer
*, int));
121 static void print_integer
PARAMS ((output_buffer
*, HOST_WIDE_INT
));
122 static tree locate_error
PARAMS ((const char *, va_list));
127 diagnostic_starter (global_dc
) = cp_diagnostic_starter
;
128 diagnostic_finalizer (global_dc
) = cp_diagnostic_finalizer
;
129 diagnostic_format_decoder (global_dc
) = cp_printer
;
131 init_output_buffer (scratch_buffer
, /* prefix */NULL
, /* line-width */0);
134 /* Dump a scope, if deemed necessary. */
137 dump_scope (scope
, flags
)
141 int f
= ~TFF_RETURN_TYPE
& (flags
& (TFF_SCOPE
| TFF_CHASE_TYPEDEF
));
143 if (scope
== NULL_TREE
)
146 if (TREE_CODE (scope
) == NAMESPACE_DECL
)
148 if (scope
!= global_namespace
)
150 dump_decl (scope
, f
);
151 print_scope_operator (scratch_buffer
);
154 else if (AGGREGATE_TYPE_P (scope
))
156 dump_type (scope
, f
);
157 print_scope_operator (scratch_buffer
);
159 else if ((flags
& TFF_SCOPE
) && TREE_CODE (scope
) == FUNCTION_DECL
)
161 dump_function_decl (scope
, f
);
162 print_scope_operator (scratch_buffer
);
166 /* Dump type qualifiers, providing padding as requested. Return an
167 indication of whether we dumped something. */
170 dump_qualifiers (t
, p
)
174 static const int masks
[] =
175 {TYPE_QUAL_CONST
, TYPE_QUAL_VOLATILE
, TYPE_QUAL_RESTRICT
};
176 static const char *const names
[] =
177 {"const", "volatile", "__restrict"};
179 int quals
= TYPE_QUALS (t
);
180 int do_after
= p
== after
;
184 for (ix
= 0; ix
!= 3; ix
++)
185 if (masks
[ix
] & quals
)
188 output_add_space (scratch_buffer
);
190 print_identifier (scratch_buffer
, names
[ix
]);
193 output_add_space (scratch_buffer
);
200 /* This must be large enough to hold any printed integer or floating-point
202 static char digit_buffer
[128];
204 /* Dump the template ARGument under control of FLAGS. */
207 dump_template_argument (arg
, flags
)
211 if (TYPE_P (arg
) || TREE_CODE (arg
) == TEMPLATE_DECL
)
212 dump_type (arg
, flags
& ~TFF_CLASS_KEY_OR_ENUM
);
214 dump_expr (arg
, (flags
| TFF_EXPR_IN_PARENS
) & ~TFF_CLASS_KEY_OR_ENUM
);
217 /* Dump a template-argument-list ARGS (always a TREE_VEC) under control
221 dump_template_argument_list (args
, flags
)
225 int n
= TREE_VEC_LENGTH (args
);
229 for (i
= 0; i
< n
; ++i
)
232 separate_with_comma (scratch_buffer
);
233 dump_template_argument (TREE_VEC_ELT (args
, i
), flags
);
238 /* Dump a template parameter PARM (a TREE_LIST) under control of FLAGS. */
241 dump_template_parameter (parm
, flags
)
245 tree p
= TREE_VALUE (parm
);
246 tree a
= TREE_PURPOSE (parm
);
248 if (TREE_CODE (p
) == TYPE_DECL
)
250 if (flags
& TFF_DECL_SPECIFIERS
)
252 print_identifier (scratch_buffer
, "class");
255 output_add_space (scratch_buffer
);
256 print_tree_identifier (scratch_buffer
, DECL_NAME (p
));
259 else if (DECL_NAME (p
))
260 print_tree_identifier (scratch_buffer
, DECL_NAME (p
));
262 print_identifier (scratch_buffer
, "{template default argument error}");
265 dump_decl (p
, flags
| TFF_DECL_SPECIFIERS
);
267 if ((flags
& TFF_FUNCTION_DEFAULT_ARGUMENTS
) && a
!= NULL_TREE
)
269 output_add_string (scratch_buffer
, " = ");
270 if (TREE_CODE (p
) == TYPE_DECL
|| TREE_CODE (p
) == TEMPLATE_DECL
)
271 dump_type (a
, flags
& ~TFF_CHASE_TYPEDEF
);
273 dump_expr (a
, flags
| TFF_EXPR_IN_PARENS
);
277 /* Dump, under control of FLAGS, a template-parameter-list binding.
278 PARMS is a TREE_LIST of TREE_VEC of TREE_LIST and ARGS is a
282 dump_template_bindings (parms
, args
)
289 tree p
= TREE_VALUE (parms
);
290 int lvl
= TMPL_PARMS_DEPTH (parms
);
294 for (i
= 0; i
< TREE_VEC_LENGTH (p
); ++i
)
296 tree arg
= NULL_TREE
;
298 /* Don't crash if we had an invalid argument list. */
299 if (TMPL_ARGS_DEPTH (args
) >= lvl
)
301 tree lvl_args
= TMPL_ARGS_LEVEL (args
, lvl
);
302 if (NUM_TMPL_ARGS (lvl_args
) > arg_idx
)
303 arg
= TREE_VEC_ELT (lvl_args
, arg_idx
);
307 separate_with_comma (scratch_buffer
);
308 dump_template_parameter (TREE_VEC_ELT (p
, i
), TFF_PLAIN_IDENTIFIER
);
309 output_add_string (scratch_buffer
, " = ");
311 dump_template_argument (arg
, TFF_PLAIN_IDENTIFIER
);
313 print_identifier (scratch_buffer
, "<missing>");
319 parms
= TREE_CHAIN (parms
);
323 /* Dump into the obstack a human-readable equivalent of TYPE. FLAGS
324 controls the format. */
334 if (TYPE_PTRMEMFUNC_P (t
))
337 switch (TREE_CODE (t
))
340 print_identifier (scratch_buffer
, "<unknown type>");
344 /* A list of function parms. */
345 dump_parameters (t
, flags
);
348 case IDENTIFIER_NODE
:
349 print_tree_identifier (scratch_buffer
, t
);
353 dump_type (BINFO_TYPE (t
), flags
);
359 dump_aggr_type (t
, flags
);
363 if (flags
& TFF_CHASE_TYPEDEF
)
365 dump_type (DECL_ORIGINAL_TYPE (t
)
366 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
), flags
);
369 /* else fallthrough */
373 dump_decl (t
, flags
& ~TFF_DECL_SPECIFIERS
);
377 output_add_string (scratch_buffer
, "__complex__ ");
378 dump_type (TREE_TYPE (t
), flags
);
382 output_add_string (scratch_buffer
, "vector ");
384 /* The subtype of a VECTOR_TYPE is something like intQI_type_node,
385 which has no name and is not very useful for diagnostics. So
386 look up the equivalent C type and print its name. */
387 tree elt
= TREE_TYPE (t
);
388 elt
= c_common_type_for_mode (TYPE_MODE (elt
), TREE_UNSIGNED (elt
));
389 dump_type (elt
, flags
);
394 if (!TREE_UNSIGNED (TYPE_MAIN_VARIANT (t
)) && TREE_UNSIGNED (t
))
395 output_add_string (scratch_buffer
, "unsigned ");
396 else if (TREE_UNSIGNED (TYPE_MAIN_VARIANT (t
)) && !TREE_UNSIGNED (t
))
397 output_add_string (scratch_buffer
, "signed ");
405 dump_qualifiers (t
, after
);
406 type
= flags
& TFF_CHASE_TYPEDEF
? TYPE_MAIN_VARIANT (t
) : t
;
407 if (TYPE_NAME (type
) && TYPE_IDENTIFIER (type
))
408 print_tree_identifier (scratch_buffer
, TYPE_IDENTIFIER (type
));
410 /* Types like intQI_type_node and friends have no names.
411 These don't come up in user error messages, but it's nice
412 to be able to print them from the debugger. */
413 print_identifier (scratch_buffer
, "<anonymous>");
417 case TEMPLATE_TEMPLATE_PARM
:
418 /* For parameters inside template signature. */
419 if (TYPE_IDENTIFIER (t
))
420 print_tree_identifier (scratch_buffer
, TYPE_IDENTIFIER (t
));
423 (scratch_buffer
, "<anonymous template template parameter>");
426 case BOUND_TEMPLATE_TEMPLATE_PARM
:
428 tree args
= TYPE_TI_ARGS (t
);
429 print_tree_identifier (scratch_buffer
, TYPE_IDENTIFIER (t
));
430 print_template_argument_list_start (scratch_buffer
);
431 dump_template_argument_list (args
, flags
);
432 print_template_argument_list_end (scratch_buffer
);
436 case TEMPLATE_TYPE_PARM
:
437 dump_qualifiers (t
, after
);
438 if (TYPE_IDENTIFIER (t
))
439 print_tree_identifier (scratch_buffer
, TYPE_IDENTIFIER (t
));
442 (scratch_buffer
, "<anonymous template type parameter>");
445 /* This is not always necessary for pointers and such, but doing this
446 reduces code size. */
455 dump_type_prefix (t
, flags
);
456 dump_type_suffix (t
, flags
);
460 if (!IMPLICIT_TYPENAME_P (t
))
461 output_add_string (scratch_buffer
, "typename ");
462 dump_typename (t
, flags
);
465 case UNBOUND_CLASS_TEMPLATE
:
466 dump_type (TYPE_CONTEXT (t
), flags
);
467 print_scope_operator (scratch_buffer
);
468 print_identifier (scratch_buffer
, "template ");
469 dump_type (DECL_NAME (TYPE_NAME (t
)), flags
);
473 output_add_string (scratch_buffer
, "__typeof (");
474 dump_expr (TYPE_FIELDS (t
), flags
& ~TFF_EXPR_IN_PARENS
);
475 print_left_paren (scratch_buffer
);
479 sorry_for_unsupported_tree (t
);
480 /* Fall through to error. */
483 print_identifier (scratch_buffer
, "<type error>");
488 /* Dump a TYPENAME_TYPE. We need to notice when the context is itself
492 dump_typename (t
, flags
)
496 tree ctx
= TYPE_CONTEXT (t
);
498 if (TREE_CODE (ctx
) == TYPENAME_TYPE
)
499 dump_typename (ctx
, flags
);
501 dump_type (ctx
, flags
& ~TFF_CLASS_KEY_OR_ENUM
);
502 print_scope_operator (scratch_buffer
);
503 dump_decl (TYPENAME_TYPE_FULLNAME (t
), flags
);
506 /* Return the name of the supplied aggregate, or enumeral type. */
509 class_key_or_enum (t
)
512 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
514 else if (TREE_CODE (t
) == UNION_TYPE
)
516 else if (TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_DECLARED_CLASS (t
))
522 /* Print out a class declaration T under the control of FLAGS,
523 in the form `class foo'. */
526 dump_aggr_type (t
, flags
)
531 const char *variety
= class_key_or_enum (t
);
535 dump_qualifiers (t
, after
);
537 if (flags
& TFF_CLASS_KEY_OR_ENUM
)
539 print_identifier (scratch_buffer
, variety
);
540 output_add_space (scratch_buffer
);
543 if (flags
& TFF_CHASE_TYPEDEF
)
544 t
= TYPE_MAIN_VARIANT (t
);
546 name
= TYPE_NAME (t
);
550 typdef
= !DECL_ARTIFICIAL (name
);
551 tmplate
= !typdef
&& TREE_CODE (t
) != ENUMERAL_TYPE
552 && TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_TEMPLATE_INFO (t
)
553 && (CLASSTYPE_TEMPLATE_SPECIALIZATION (t
)
554 || TREE_CODE (CLASSTYPE_TI_TEMPLATE (t
)) != TEMPLATE_DECL
555 || DECL_TEMPLATE_SPECIALIZATION (CLASSTYPE_TI_TEMPLATE (t
))
556 || PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t
)));
557 dump_scope (CP_DECL_CONTEXT (name
), flags
| TFF_SCOPE
);
560 /* Because the template names are mangled, we have to locate
561 the most general template, and use that name. */
562 tree tpl
= CLASSTYPE_TI_TEMPLATE (t
);
564 while (DECL_TEMPLATE_INFO (tpl
))
565 tpl
= DECL_TI_TEMPLATE (tpl
);
568 name
= DECL_NAME (name
);
571 if (name
== 0 || ANON_AGGRNAME_P (name
))
573 if (flags
& TFF_CLASS_KEY_OR_ENUM
)
574 print_identifier (scratch_buffer
, "<anonymous>");
576 output_printf (scratch_buffer
, "<anonymous %s>", variety
);
579 print_tree_identifier (scratch_buffer
, name
);
581 dump_template_parms (TYPE_TEMPLATE_INFO (t
),
582 !CLASSTYPE_USE_TEMPLATE (t
),
583 flags
& ~TFF_TEMPLATE_HEADER
);
586 /* Dump into the obstack the initial part of the output for a given type.
587 This is necessary when dealing with things like functions returning
590 return type of `int (* fee ())()': pointer -> function -> int. Both
591 pointer (and reference and offset) and function (and member) types must
592 deal with prefix and suffix.
594 Arrays must also do this for DECL nodes, like int a[], and for things like
597 Return indicates how you should pad an object name after this. I.e. you
598 want to pad non-*, non-& cores, but not pad * or & types. */
601 dump_type_prefix (t
, flags
)
605 enum pad padding
= before
;
607 if (TYPE_PTRMEMFUNC_P (t
))
609 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
613 switch (TREE_CODE (t
))
618 tree sub
= TREE_TYPE (t
);
620 padding
= dump_type_prefix (sub
, flags
);
621 /* A tree for a member pointer looks like pointer to offset,
622 so let the OFFSET_TYPE case handle it. */
623 if (!TYPE_PTRMEM_P (t
))
625 if (TREE_CODE (sub
) == ARRAY_TYPE
)
627 output_add_space (scratch_buffer
);
628 print_left_paren (scratch_buffer
);
631 (scratch_buffer
, "&*"[TREE_CODE (t
) == POINTER_TYPE
]);
632 padding
= dump_qualifiers (t
, before
);
639 padding
= dump_type_prefix (TREE_TYPE (t
), flags
);
640 if (TREE_CODE (t
) == OFFSET_TYPE
) /* pmfs deal with this in d_t_p */
643 output_add_space (scratch_buffer
);
644 dump_type (TYPE_OFFSET_BASETYPE (t
), flags
);
645 print_scope_operator (scratch_buffer
);
647 output_add_character (scratch_buffer
, '*');
648 padding
= dump_qualifiers (t
, none
);
651 /* Can only be reached through function pointer -- this would not be
652 correct if FUNCTION_DECLs used it. */
654 padding
= dump_type_prefix (TREE_TYPE (t
), flags
);
656 output_add_space (scratch_buffer
);
657 print_left_paren (scratch_buffer
);
662 padding
= dump_type_prefix (TREE_TYPE (t
), flags
);
664 output_add_space (scratch_buffer
);
665 print_left_paren (scratch_buffer
);
667 dump_aggr_type (TYPE_METHOD_BASETYPE (t
), flags
);
668 print_scope_operator (scratch_buffer
);
672 padding
= dump_type_prefix (TREE_TYPE (t
), flags
);
676 case IDENTIFIER_NODE
:
681 case TEMPLATE_TYPE_PARM
:
682 case TEMPLATE_TEMPLATE_PARM
:
683 case BOUND_TEMPLATE_TEMPLATE_PARM
:
693 dump_type (t
, flags
);
698 sorry_for_unsupported_tree (t
);
701 print_identifier (scratch_buffer
, "<typeprefixerror>");
707 /* Dump the suffix of type T, under control of FLAGS. This is the part
708 which appears after the identifier (or function parms). */
711 dump_type_suffix (t
, flags
)
715 if (TYPE_PTRMEMFUNC_P (t
))
716 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
718 switch (TREE_CODE (t
))
723 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
724 print_right_paren (scratch_buffer
);
725 dump_type_suffix (TREE_TYPE (t
), flags
);
728 /* Can only be reached through function pointer */
733 print_right_paren (scratch_buffer
);
734 arg
= TYPE_ARG_TYPES (t
);
735 if (TREE_CODE (t
) == METHOD_TYPE
)
736 arg
= TREE_CHAIN (arg
);
738 /* Function pointers don't have default args. Not in standard C++,
739 anyway; they may in g++, but we'll just pretend otherwise. */
740 dump_parameters (arg
, flags
& ~TFF_FUNCTION_DEFAULT_ARGUMENTS
);
742 if (TREE_CODE (t
) == METHOD_TYPE
)
744 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t
))), before
);
745 dump_exception_spec (TYPE_RAISES_EXCEPTIONS (t
), flags
);
746 dump_type_suffix (TREE_TYPE (t
), flags
);
751 print_left_bracket (scratch_buffer
);
754 if (host_integerp (TYPE_MAX_VALUE (TYPE_DOMAIN (t
)), 0))
757 tree_low_cst (TYPE_MAX_VALUE (TYPE_DOMAIN (t
)), 0) + 1);
758 else if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (t
))) == MINUS_EXPR
)
759 dump_expr (TREE_OPERAND (TYPE_MAX_VALUE (TYPE_DOMAIN (t
)), 0),
760 flags
& ~TFF_EXPR_IN_PARENS
);
762 dump_expr (fold (cp_build_binary_op
763 (PLUS_EXPR
, TYPE_MAX_VALUE (TYPE_DOMAIN (t
)),
765 flags
& ~TFF_EXPR_IN_PARENS
);
767 print_right_bracket (scratch_buffer
);
768 dump_type_suffix (TREE_TYPE (t
), flags
);
772 case IDENTIFIER_NODE
:
777 case TEMPLATE_TYPE_PARM
:
778 case TEMPLATE_TEMPLATE_PARM
:
779 case BOUND_TEMPLATE_TEMPLATE_PARM
:
792 sorry_for_unsupported_tree (t
);
794 /* Don't mark it here, we should have already done in
804 const char *p
= NULL
;
806 if (DECL_GLOBAL_CTOR_P (t
))
808 else if (DECL_GLOBAL_DTOR_P (t
))
813 output_printf (scratch_buffer
, "(static %s for %s)", p
, input_filename
);
817 dump_simple_decl (t
, type
, flags
)
822 if (flags
& TFF_DECL_SPECIFIERS
)
824 if (dump_type_prefix (type
, flags
) != none
)
825 output_add_space (scratch_buffer
);
827 if (!DECL_INITIAL (t
) || TREE_CODE (DECL_INITIAL (t
)) != TEMPLATE_PARM_INDEX
)
828 dump_scope (CP_DECL_CONTEXT (t
), flags
);
830 dump_decl (DECL_NAME (t
), flags
);
832 print_identifier (scratch_buffer
, "<anonymous>");
833 if (flags
& TFF_DECL_SPECIFIERS
)
834 dump_type_suffix (type
, flags
);
837 /* Dump a human readable string for the decl T under control of FLAGS. */
847 switch (TREE_CODE (t
))
851 /* Don't say 'typedef class A' */
852 if (DECL_ARTIFICIAL (t
))
854 if ((flags
& TFF_DECL_SPECIFIERS
)
855 && TREE_CODE (TREE_TYPE (t
)) == TEMPLATE_TYPE_PARM
)
856 /* Say `class T' not just `T'. */
857 output_add_string (scratch_buffer
, "class ");
859 dump_type (TREE_TYPE (t
), flags
);
863 if (flags
& TFF_DECL_SPECIFIERS
)
864 output_add_string (scratch_buffer
, "typedef ");
865 dump_simple_decl (t
, DECL_ORIGINAL_TYPE (t
)
866 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
),
871 if (DECL_NAME (t
) && VTABLE_NAME_P (DECL_NAME (t
)))
873 output_add_string (scratch_buffer
, "vtable for ");
874 my_friendly_assert (TYPE_P (DECL_CONTEXT (t
)), 20010720);
875 dump_type (DECL_CONTEXT (t
), flags
);
878 /* else fall through */
881 dump_simple_decl (t
, TREE_TYPE (t
), flags
);
885 output_add_string (scratch_buffer
, "<return value> ");
886 dump_simple_decl (t
, TREE_TYPE (t
), flags
);
890 dump_scope (CP_DECL_CONTEXT (t
), flags
);
891 if (DECL_NAME (t
) == anonymous_namespace_name
)
892 print_identifier (scratch_buffer
, "<unnamed>");
894 print_tree_identifier (scratch_buffer
, DECL_NAME (t
));
898 dump_decl (TREE_OPERAND (t
, 0), flags
& ~TFF_DECL_SPECIFIERS
);
899 print_scope_operator (scratch_buffer
);
900 dump_decl (TREE_OPERAND (t
, 1), flags
);
904 dump_decl (TREE_OPERAND (t
, 0), flags
);
905 print_left_bracket (scratch_buffer
);
906 dump_decl (TREE_OPERAND (t
, 1), flags
);
907 print_right_bracket (scratch_buffer
);
910 /* So that we can do dump_decl on an aggr type. */
914 dump_type (t
, flags
);
921 /* These special cases are duplicated here so that other functions
922 can feed identifiers to error and get them demangled properly. */
923 case IDENTIFIER_NODE
:
924 if (IDENTIFIER_TYPENAME_P (t
))
926 output_add_string (scratch_buffer
, "operator ");
927 /* Not exactly IDENTIFIER_TYPE_VALUE. */
928 dump_type (TREE_TYPE (t
), flags
);
932 print_tree_identifier (scratch_buffer
, t
);
940 if (DECL_GLOBAL_CTOR_P (t
) || DECL_GLOBAL_DTOR_P (t
))
941 dump_global_iord (t
);
942 else if (! DECL_LANG_SPECIFIC (t
))
943 print_identifier (scratch_buffer
, "<internal>");
945 dump_function_decl (t
, flags
);
949 dump_template_decl (t
, flags
);
952 case TEMPLATE_ID_EXPR
:
955 tree name
= TREE_OPERAND (t
, 0);
956 if (is_overloaded_fn (name
))
957 name
= DECL_NAME (get_first_fn (name
));
958 dump_decl (name
, flags
);
959 print_template_argument_list_start (scratch_buffer
);
960 for (args
= TREE_OPERAND (t
, 1); args
; args
= TREE_CHAIN (args
))
962 dump_template_argument (TREE_VALUE (args
), flags
);
963 if (TREE_CHAIN (args
))
964 separate_with_comma (scratch_buffer
);
966 print_template_argument_list_end (scratch_buffer
);
971 dump_decl (TREE_OPERAND (t
, 0), flags
);
975 print_tree_identifier (scratch_buffer
, DECL_NAME (t
));
979 if ((TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == ENUMERAL_TYPE
)
980 || (DECL_INITIAL (t
) &&
981 TREE_CODE (DECL_INITIAL (t
)) == TEMPLATE_PARM_INDEX
))
982 dump_simple_decl (t
, TREE_TYPE (t
), flags
);
983 else if (DECL_NAME (t
))
984 dump_decl (DECL_NAME (t
), flags
);
985 else if (DECL_INITIAL (t
))
986 dump_expr (DECL_INITIAL (t
), flags
| TFF_EXPR_IN_PARENS
);
988 print_identifier (scratch_buffer
, "enumerator");
992 output_add_string (scratch_buffer
, "using ");
993 dump_type (DECL_INITIAL (t
), flags
);
994 print_scope_operator (scratch_buffer
);
995 print_tree_identifier (scratch_buffer
, DECL_NAME (t
));
999 sorry_for_unsupported_tree (t
);
1000 /* Fallthrough to error. */
1003 print_identifier (scratch_buffer
, "<declaration error>");
1008 /* Dump a template declaration T under control of FLAGS. This means the
1009 'template <...> leaders plus the 'class X' or 'void fn(...)' part. */
1012 dump_template_decl (t
, flags
)
1016 tree orig_parms
= DECL_TEMPLATE_PARMS (t
);
1020 if (flags
& TFF_TEMPLATE_HEADER
)
1022 for (parms
= orig_parms
= nreverse (orig_parms
);
1024 parms
= TREE_CHAIN (parms
))
1026 tree inner_parms
= INNERMOST_TEMPLATE_PARMS (parms
);
1027 int len
= TREE_VEC_LENGTH (inner_parms
);
1029 output_add_string (scratch_buffer
, "template<");
1031 /* If we've shown the template prefix, we'd better show the
1032 parameters' and decl's type too. */
1033 flags
|= TFF_DECL_SPECIFIERS
;
1035 for (i
= 0; i
< len
; i
++)
1038 separate_with_comma (scratch_buffer
);
1039 dump_template_parameter (TREE_VEC_ELT (inner_parms
, i
), flags
);
1041 print_template_argument_list_end (scratch_buffer
);
1042 output_add_space (scratch_buffer
);
1044 nreverse(orig_parms
);
1046 if (DECL_TEMPLATE_TEMPLATE_PARM_P (t
))
1047 /* Say `template<arg> class TT' not just `template<arg> TT'. */
1048 output_add_string (scratch_buffer
, "class ");
1051 if (TREE_CODE (DECL_TEMPLATE_RESULT (t
)) == TYPE_DECL
)
1052 dump_type (TREE_TYPE (t
),
1053 ((flags
& ~TFF_CLASS_KEY_OR_ENUM
) | TFF_TEMPLATE_NAME
1054 | (flags
& TFF_DECL_SPECIFIERS
? TFF_CLASS_KEY_OR_ENUM
: 0)));
1055 else if (TREE_CODE (DECL_TEMPLATE_RESULT (t
)) == VAR_DECL
)
1056 dump_decl (DECL_TEMPLATE_RESULT (t
), flags
| TFF_TEMPLATE_NAME
);
1057 else if (TREE_TYPE (t
) == NULL_TREE
)
1060 switch (NEXT_CODE (t
))
1064 dump_function_decl (t
, flags
| TFF_TEMPLATE_NAME
);
1067 /* This case can occur with some illegal code. */
1068 dump_type (TREE_TYPE (t
),
1069 (flags
& ~TFF_CLASS_KEY_OR_ENUM
) | TFF_TEMPLATE_NAME
1070 | (flags
& TFF_DECL_SPECIFIERS
? TFF_CLASS_KEY_OR_ENUM
: 0));
1074 /* Pretty print a function decl. There are several ways we want to print a
1075 function declaration. The TFF_ bits in FLAGS tells us how to behave.
1076 As error can only apply the '#' flag once to give 0 and 1 for V, there
1077 is %D which doesn't print the throw specs, and %F which does. */
1080 dump_function_decl (t
, flags
)
1086 tree cname
= NULL_TREE
;
1087 tree template_args
= NULL_TREE
;
1088 tree template_parms
= NULL_TREE
;
1089 int show_return
= flags
& TFF_RETURN_TYPE
|| flags
& TFF_DECL_SPECIFIERS
;
1091 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1092 t
= DECL_TEMPLATE_RESULT (t
);
1094 /* Pretty print template instantiations only. */
1095 if (DECL_USE_TEMPLATE (t
) && DECL_TEMPLATE_INFO (t
))
1099 template_args
= DECL_TI_ARGS (t
);
1100 tmpl
= most_general_template (t
);
1101 if (tmpl
&& TREE_CODE (tmpl
) == TEMPLATE_DECL
)
1103 template_parms
= DECL_TEMPLATE_PARMS (tmpl
);
1108 fntype
= TREE_TYPE (t
);
1109 parmtypes
= FUNCTION_FIRST_USER_PARMTYPE (t
);
1111 if (DECL_CLASS_SCOPE_P (t
))
1112 cname
= DECL_CONTEXT (t
);
1113 /* this is for partially instantiated template methods */
1114 else if (TREE_CODE (fntype
) == METHOD_TYPE
)
1115 cname
= TREE_TYPE (TREE_VALUE (parmtypes
));
1117 if (!(flags
& TFF_DECL_SPECIFIERS
))
1119 else if (DECL_STATIC_FUNCTION_P (t
))
1120 print_identifier (scratch_buffer
, "static ");
1121 else if (DECL_VIRTUAL_P (t
))
1122 print_identifier (scratch_buffer
, "virtual ");
1124 /* Print the return type? */
1126 show_return
= !DECL_CONV_FN_P (t
) && !DECL_CONSTRUCTOR_P (t
)
1127 && !DECL_DESTRUCTOR_P (t
);
1130 dump_type_prefix (TREE_TYPE (fntype
), flags
);
1131 output_add_space (scratch_buffer
);
1134 /* Print the function name. */
1137 dump_type (cname
, flags
);
1138 print_scope_operator (scratch_buffer
);
1141 dump_scope (CP_DECL_CONTEXT (t
), flags
);
1143 dump_function_name (t
, flags
);
1147 dump_parameters (parmtypes
, flags
);
1149 if (TREE_CODE (fntype
) == METHOD_TYPE
)
1150 dump_qualifiers (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype
))),
1153 if (flags
& TFF_EXCEPTION_SPECIFICATION
)
1154 dump_exception_spec (TYPE_RAISES_EXCEPTIONS (fntype
), flags
);
1157 dump_type_suffix (TREE_TYPE (fntype
), flags
);
1160 /* If T is a template instantiation, dump the parameter binding. */
1161 if (template_parms
!= NULL_TREE
&& template_args
!= NULL_TREE
)
1163 output_add_string (scratch_buffer
, " [with ");
1164 dump_template_bindings (template_parms
, template_args
);
1165 print_right_bracket (scratch_buffer
);
1169 /* Print a parameter list. If this is for a member function, the
1170 member object ptr (and any other hidden args) should have
1171 already been removed. */
1174 dump_parameters (parmtypes
, flags
)
1180 print_left_paren (scratch_buffer
);
1182 for (first
= 1; parmtypes
!= void_list_node
;
1183 parmtypes
= TREE_CHAIN (parmtypes
))
1186 separate_with_comma (scratch_buffer
);
1190 print_identifier (scratch_buffer
, "...");
1193 dump_type (TREE_VALUE (parmtypes
), flags
);
1195 if ((flags
& TFF_FUNCTION_DEFAULT_ARGUMENTS
) && TREE_PURPOSE (parmtypes
))
1197 output_add_string (scratch_buffer
, " = ");
1198 dump_expr (TREE_PURPOSE (parmtypes
), flags
| TFF_EXPR_IN_PARENS
);
1202 print_right_paren (scratch_buffer
);
1205 /* Print an exception specification. T is the exception specification. */
1208 dump_exception_spec (t
, flags
)
1214 output_add_string (scratch_buffer
, " throw (");
1215 if (TREE_VALUE (t
) != NULL_TREE
)
1218 dump_type (TREE_VALUE (t
), flags
);
1222 separate_with_comma (scratch_buffer
);
1224 print_right_paren (scratch_buffer
);
1228 /* Handle the function name for a FUNCTION_DECL node, grokking operators
1229 and destructors properly. */
1232 dump_function_name (t
, flags
)
1236 tree name
= DECL_NAME (t
);
1238 /* Don't let the user see __comp_ctor et al. */
1239 if (DECL_CONSTRUCTOR_P (t
)
1240 || DECL_DESTRUCTOR_P (t
))
1241 name
= constructor_name (DECL_CONTEXT (t
));
1243 if (DECL_DESTRUCTOR_P (t
))
1245 output_add_character (scratch_buffer
, '~');
1246 dump_decl (name
, TFF_PLAIN_IDENTIFIER
);
1248 else if (DECL_CONV_FN_P (t
))
1250 /* This cannot use the hack that the operator's return
1251 type is stashed off of its name because it may be
1252 used for error reporting. In the case of conflicting
1253 declarations, both will have the same name, yet
1254 the types will be different, hence the TREE_TYPE field
1255 of the first name will be clobbered by the second. */
1256 output_add_string (scratch_buffer
, "operator ");
1257 dump_type (TREE_TYPE (TREE_TYPE (t
)), flags
);
1259 else if (IDENTIFIER_OPNAME_P (name
))
1260 print_tree_identifier (scratch_buffer
, name
);
1262 dump_decl (name
, flags
);
1264 if (DECL_LANG_SPECIFIC (t
) && DECL_TEMPLATE_INFO (t
)
1265 && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t
)
1266 && (DECL_TEMPLATE_SPECIALIZATION (t
)
1267 || TREE_CODE (DECL_TI_TEMPLATE (t
)) != TEMPLATE_DECL
1268 || DECL_TEMPLATE_SPECIALIZATION (DECL_TI_TEMPLATE (t
))
1269 || PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t
))))
1270 dump_template_parms (DECL_TEMPLATE_INFO (t
), !DECL_USE_TEMPLATE (t
), flags
);
1273 /* Dump the template parameters from the template info INFO under control of
1274 FLAGS. PRIMARY indicates whether this is a primary template decl, or
1275 specialization (partial or complete). For partial specializations we show
1276 the specialized parameter values. For a primary template we show no
1280 dump_template_parms (info
, primary
, flags
)
1285 tree args
= info
? TI_ARGS (info
) : NULL_TREE
;
1287 if (primary
&& flags
& TFF_TEMPLATE_NAME
)
1289 flags
&= ~(TFF_CLASS_KEY_OR_ENUM
| TFF_TEMPLATE_NAME
);
1290 print_template_argument_list_start (scratch_buffer
);
1292 /* Be careful only to print things when we have them, so as not
1293 to crash producing error messages. */
1294 if (args
&& !primary
)
1300 if (TREE_CODE (args
) == TREE_VEC
)
1302 if (TREE_VEC_LENGTH (args
) > 0
1303 && TREE_CODE (TREE_VEC_ELT (args
, 0)) == TREE_VEC
)
1304 args
= TREE_VEC_ELT (args
, TREE_VEC_LENGTH (args
) - 1);
1306 len
= TREE_VEC_LENGTH (args
);
1308 else if (TREE_CODE (args
) == TREE_LIST
)
1310 while (ix
!= len
&& args
)
1315 arg
= TREE_VEC_ELT (args
, ix
);
1320 arg
= TREE_VALUE (args
);
1321 args
= TREE_CHAIN (args
);
1324 separate_with_comma (scratch_buffer
);
1327 print_identifier (scratch_buffer
, "<template parameter error>");
1329 dump_template_argument (arg
, flags
);
1335 tree tpl
= TI_TEMPLATE (info
);
1336 tree parms
= DECL_TEMPLATE_PARMS (tpl
);
1339 parms
= TREE_CODE (parms
) == TREE_LIST
? TREE_VALUE (parms
) : NULL_TREE
;
1340 len
= parms
? TREE_VEC_LENGTH (parms
) : 0;
1342 for (ix
= 0; ix
!= len
; ix
++)
1344 tree parm
= TREE_VALUE (TREE_VEC_ELT (parms
, ix
));
1347 separate_with_comma (scratch_buffer
);
1349 dump_decl (parm
, flags
& ~TFF_DECL_SPECIFIERS
);
1352 print_template_argument_list_end (scratch_buffer
);
1361 case TARGET_NEWLINE
:
1362 output_add_string (scratch_buffer
, "\\n");
1365 output_add_string (scratch_buffer
, "\\t");
1368 output_add_string (scratch_buffer
, "\\v");
1371 output_add_string (scratch_buffer
, "\\b");
1374 output_add_string (scratch_buffer
, "\\r");
1377 output_add_string (scratch_buffer
, "\\f");
1380 output_add_string (scratch_buffer
, "\\a");
1383 output_add_string (scratch_buffer
, "\\\\");
1386 output_add_string (scratch_buffer
, "\\'");
1389 output_add_string (scratch_buffer
, "\\\"");
1393 output_add_character (scratch_buffer
, c
);
1396 sprintf (digit_buffer
, "\\%03o", (int) c
);
1397 output_add_string (scratch_buffer
, digit_buffer
);
1402 /* Print out a list of initializers (subr of dump_expr) */
1405 dump_expr_list (l
, flags
)
1411 dump_expr (TREE_VALUE (l
), flags
| TFF_EXPR_IN_PARENS
);
1414 separate_with_comma (scratch_buffer
);
1418 /* Print out an expression E under control of FLAGS. */
1421 dump_expr (t
, flags
)
1425 switch (TREE_CODE (t
))
1433 case NAMESPACE_DECL
:
1435 dump_decl (t
, flags
& ~TFF_DECL_SPECIFIERS
);
1440 tree type
= TREE_TYPE (t
);
1441 my_friendly_assert (type
!= 0, 81);
1443 /* If it's an enum, output its tag, rather than its value. */
1444 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1446 tree values
= TYPE_VALUES (type
);
1449 values
= TREE_CHAIN (values
))
1450 if (tree_int_cst_equal (TREE_VALUE (values
), t
))
1454 print_tree_identifier (scratch_buffer
, TREE_PURPOSE (values
));
1457 /* Value must have been cast. */
1458 print_left_paren (scratch_buffer
);
1459 dump_type (type
, flags
);
1460 print_right_paren (scratch_buffer
);
1464 else if (type
== boolean_type_node
)
1466 if (t
== boolean_false_node
|| integer_zerop (t
))
1467 print_identifier (scratch_buffer
, "false");
1468 else if (t
== boolean_true_node
)
1469 print_identifier (scratch_buffer
, "true");
1471 else if (type
== char_type_node
)
1473 output_add_character (scratch_buffer
, '\'');
1474 dump_char (tree_low_cst (t
, 0));
1475 output_add_character (scratch_buffer
, '\'');
1480 if (! host_integerp (t
, 0))
1484 if (tree_int_cst_sgn (val
) < 0)
1486 output_add_character (scratch_buffer
, '-');
1487 val
= build_int_2 (-TREE_INT_CST_LOW (val
),
1488 ~TREE_INT_CST_HIGH (val
)
1489 + !TREE_INT_CST_LOW (val
));
1491 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
1494 static char format
[10]; /* "%x%09999x\0" */
1496 sprintf (format
, "%%x%%0%dx", HOST_BITS_PER_INT
/ 4);
1497 sprintf (digit_buffer
, format
, TREE_INT_CST_HIGH (val
),
1498 TREE_INT_CST_LOW (val
));
1499 output_add_string (scratch_buffer
, digit_buffer
);
1503 print_integer (scratch_buffer
, TREE_INT_CST_LOW (t
));
1510 const unsigned char *p
= (const unsigned char *) &TREE_REAL_CST (t
);
1512 strcpy (digit_buffer
, "0x");
1513 for (i
= 0; i
< sizeof TREE_REAL_CST (t
); i
++)
1514 sprintf (digit_buffer
+ 2 + 2*i
, "%02x", *p
++);
1516 output_add_string (scratch_buffer
, digit_buffer
);
1520 output_add_character (scratch_buffer
, '&');
1521 dump_type (PTRMEM_CST_CLASS (t
), flags
);
1522 print_scope_operator (scratch_buffer
);
1523 print_tree_identifier
1524 (scratch_buffer
, DECL_NAME (PTRMEM_CST_MEMBER (t
)));
1529 const char *p
= TREE_STRING_POINTER (t
);
1530 int len
= TREE_STRING_LENGTH (t
) - 1;
1533 output_add_character (scratch_buffer
, '\"');
1534 for (i
= 0; i
< len
; i
++)
1536 output_add_character (scratch_buffer
, '\"');
1541 print_left_paren (scratch_buffer
);
1542 dump_expr (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
1543 separate_with_comma (scratch_buffer
);
1544 dump_expr (TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
1545 print_right_paren (scratch_buffer
);
1549 print_left_paren (scratch_buffer
);
1550 dump_expr (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
1551 output_add_string (scratch_buffer
, " ? ");
1552 dump_expr (TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
1553 output_add_string (scratch_buffer
, " : ");
1554 dump_expr (TREE_OPERAND (t
, 2), flags
| TFF_EXPR_IN_PARENS
);
1555 print_right_paren (scratch_buffer
);
1559 if (TREE_HAS_CONSTRUCTOR (t
))
1561 output_add_string (scratch_buffer
, "new ");
1562 dump_type (TREE_TYPE (TREE_TYPE (t
)), flags
);
1566 dump_expr (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
1570 case AGGR_INIT_EXPR
:
1572 tree fn
= NULL_TREE
;
1574 if (TREE_CODE (TREE_OPERAND (t
, 0)) == ADDR_EXPR
)
1575 fn
= TREE_OPERAND (TREE_OPERAND (t
, 0), 0);
1577 if (fn
&& TREE_CODE (fn
) == FUNCTION_DECL
)
1579 if (DECL_CONSTRUCTOR_P (fn
))
1580 print_tree_identifier
1581 (scratch_buffer
, TYPE_IDENTIFIER (TREE_TYPE (t
)));
1586 dump_expr (TREE_OPERAND (t
, 0), 0);
1588 print_left_paren (scratch_buffer
);
1589 if (TREE_OPERAND (t
, 1))
1590 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t
, 1)), flags
);
1591 print_right_paren (scratch_buffer
);
1596 tree fn
= TREE_OPERAND (t
, 0);
1597 tree args
= TREE_OPERAND (t
, 1);
1599 if (TREE_CODE (fn
) == ADDR_EXPR
)
1600 fn
= TREE_OPERAND (fn
, 0);
1602 if (TREE_TYPE (fn
) != NULL_TREE
&& NEXT_CODE (fn
) == METHOD_TYPE
)
1604 tree ob
= TREE_VALUE (args
);
1605 if (TREE_CODE (ob
) == ADDR_EXPR
)
1607 dump_expr (TREE_OPERAND (ob
, 0), flags
| TFF_EXPR_IN_PARENS
);
1608 output_add_character (scratch_buffer
, '.');
1610 else if (TREE_CODE (ob
) != PARM_DECL
1611 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob
)), "this"))
1613 dump_expr (ob
, flags
| TFF_EXPR_IN_PARENS
);
1614 output_add_string (scratch_buffer
, "->");
1616 args
= TREE_CHAIN (args
);
1618 dump_expr (fn
, flags
| TFF_EXPR_IN_PARENS
);
1619 print_left_paren (scratch_buffer
);
1620 dump_expr_list (args
, flags
);
1621 print_right_paren (scratch_buffer
);
1627 tree type
= TREE_OPERAND (t
, 1);
1628 if (NEW_EXPR_USE_GLOBAL (t
))
1629 print_scope_operator (scratch_buffer
);
1630 output_add_string (scratch_buffer
, "new ");
1631 if (TREE_OPERAND (t
, 0))
1633 print_left_paren (scratch_buffer
);
1634 dump_expr_list (TREE_OPERAND (t
, 0), flags
);
1635 output_add_string (scratch_buffer
, ") ");
1637 if (TREE_CODE (type
) == ARRAY_REF
)
1638 type
= build_cplus_array_type
1639 (TREE_OPERAND (type
, 0),
1640 build_index_type (fold (build (MINUS_EXPR
, integer_type_node
,
1641 TREE_OPERAND (type
, 1),
1642 integer_one_node
))));
1643 dump_type (type
, flags
);
1644 if (TREE_OPERAND (t
, 2))
1646 print_left_paren (scratch_buffer
);
1647 dump_expr_list (TREE_OPERAND (t
, 2), flags
);
1648 print_right_paren (scratch_buffer
);
1654 /* Note that this only works for G++ target exprs. If somebody
1655 builds a general TARGET_EXPR, there's no way to represent that
1656 it initializes anything other that the parameter slot for the
1657 default argument. Note we may have cleared out the first
1658 operand in expand_expr, so don't go killing ourselves. */
1659 if (TREE_OPERAND (t
, 1))
1660 dump_expr (TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
1668 case TRUNC_DIV_EXPR
:
1669 case TRUNC_MOD_EXPR
:
1677 case BIT_ANDTC_EXPR
:
1678 case TRUTH_ANDIF_EXPR
:
1679 case TRUTH_ORIF_EXPR
:
1686 case EXACT_DIV_EXPR
:
1687 dump_binary_op (operator_name_info
[(int) TREE_CODE (t
)].name
, t
, flags
);
1691 case FLOOR_DIV_EXPR
:
1692 case ROUND_DIV_EXPR
:
1693 dump_binary_op ("/", t
, flags
);
1697 case FLOOR_MOD_EXPR
:
1698 case ROUND_MOD_EXPR
:
1699 dump_binary_op ("%", t
, flags
);
1704 tree ob
= TREE_OPERAND (t
, 0);
1705 if (TREE_CODE (ob
) == INDIRECT_REF
)
1707 ob
= TREE_OPERAND (ob
, 0);
1708 if (TREE_CODE (ob
) != PARM_DECL
1709 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob
)), "this"))
1711 dump_expr (ob
, flags
| TFF_EXPR_IN_PARENS
);
1712 output_add_string (scratch_buffer
, "->");
1717 dump_expr (ob
, flags
| TFF_EXPR_IN_PARENS
);
1718 output_add_character (scratch_buffer
, '.');
1720 dump_expr (TREE_OPERAND (t
, 1), flags
& ~TFF_EXPR_IN_PARENS
);
1725 dump_expr (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
1726 print_left_bracket (scratch_buffer
);
1727 dump_expr (TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
1728 print_right_bracket (scratch_buffer
);
1732 if (TREE_TYPE (t
) && VOID_TYPE_P (TREE_TYPE (t
)))
1734 print_left_paren (scratch_buffer
);
1735 dump_type (TREE_TYPE (t
), flags
);
1736 print_right_paren (scratch_buffer
);
1737 dump_expr (TREE_OPERAND (t
, 0), flags
);
1740 dump_unary_op ("+", t
, flags
);
1744 if (TREE_CODE (TREE_OPERAND (t
, 0)) == FUNCTION_DECL
1745 || TREE_CODE (TREE_OPERAND (t
, 0)) == STRING_CST
1746 /* An ADDR_EXPR can have reference type. In that case, we
1747 shouldn't print the `&' doing so indicates to the user
1748 that the expression has pointer type. */
1750 && TREE_CODE (TREE_TYPE (t
)) == REFERENCE_TYPE
))
1751 dump_expr (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
1753 dump_unary_op ("&", t
, flags
);
1757 if (TREE_HAS_CONSTRUCTOR (t
))
1759 t
= TREE_OPERAND (t
, 0);
1760 my_friendly_assert (TREE_CODE (t
) == CALL_EXPR
, 237);
1761 dump_expr (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
1762 print_left_paren (scratch_buffer
);
1763 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t
, 1)), flags
);
1764 print_right_paren (scratch_buffer
);
1768 if (TREE_OPERAND (t
,0) != NULL_TREE
1769 && TREE_TYPE (TREE_OPERAND (t
, 0))
1770 && NEXT_CODE (TREE_OPERAND (t
, 0)) == REFERENCE_TYPE
)
1771 dump_expr (TREE_OPERAND (t
, 0), flags
);
1773 dump_unary_op ("*", t
, flags
);
1779 case TRUTH_NOT_EXPR
:
1780 case PREDECREMENT_EXPR
:
1781 case PREINCREMENT_EXPR
:
1782 dump_unary_op (operator_name_info
[(int)TREE_CODE (t
)].name
, t
, flags
);
1785 case POSTDECREMENT_EXPR
:
1786 case POSTINCREMENT_EXPR
:
1787 print_left_paren (scratch_buffer
);
1788 dump_expr (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
1790 (scratch_buffer
, operator_name_info
[(int)TREE_CODE (t
)].name
);
1791 print_right_paren (scratch_buffer
);
1794 case NON_LVALUE_EXPR
:
1795 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
1796 should be another level of INDIRECT_REF so that I don't have to do
1798 if (TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == POINTER_TYPE
)
1800 tree next
= TREE_TYPE (TREE_TYPE (t
));
1802 while (TREE_CODE (next
) == POINTER_TYPE
)
1803 next
= TREE_TYPE (next
);
1805 if (TREE_CODE (next
) == FUNCTION_TYPE
)
1807 if (flags
& TFF_EXPR_IN_PARENS
)
1808 print_left_paren (scratch_buffer
);
1809 output_add_character (scratch_buffer
, '*');
1810 dump_expr (TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
1811 if (flags
& TFF_EXPR_IN_PARENS
)
1812 print_right_paren (scratch_buffer
);
1817 dump_expr (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
1821 dump_expr (TREE_OPERAND (t
, 0), flags
);
1824 case EXPR_WITH_FILE_LOCATION
:
1825 dump_expr (EXPR_WFL_NODE (t
), flags
);
1829 if (TREE_TYPE (t
) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t
)))
1831 tree idx
= build_component_ref (t
, pfn_identifier
, NULL_TREE
, 0);
1833 if (integer_zerop (idx
))
1835 /* A NULL pointer-to-member constant. */
1836 output_add_string (scratch_buffer
, "((");
1837 dump_type (TREE_TYPE (t
), flags
);
1838 output_add_string (scratch_buffer
, ") 0)");
1841 else if (host_integerp (idx
, 0))
1844 unsigned HOST_WIDE_INT n
;
1846 t
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t
)));
1847 t
= TYPE_METHOD_BASETYPE (t
);
1848 virtuals
= TYPE_BINFO_VIRTUALS (TYPE_MAIN_VARIANT (t
));
1850 n
= tree_low_cst (idx
, 0);
1852 /* Map vtable index back one, to allow for the null pointer to
1856 while (n
> 0 && virtuals
)
1859 virtuals
= TREE_CHAIN (virtuals
);
1863 dump_expr (BV_FN (virtuals
),
1864 flags
| TFF_EXPR_IN_PARENS
);
1869 output_add_character (scratch_buffer
, '{');
1870 dump_expr_list (CONSTRUCTOR_ELTS (t
), flags
);
1871 output_add_character (scratch_buffer
, '}');
1876 tree ob
= TREE_OPERAND (t
, 0);
1877 if (is_dummy_object (ob
))
1879 t
= TREE_OPERAND (t
, 1);
1880 if (TREE_CODE (t
) == FUNCTION_DECL
)
1882 dump_expr (t
, flags
| TFF_EXPR_IN_PARENS
);
1883 else if (BASELINK_P (t
))
1884 dump_expr (OVL_CURRENT (TREE_VALUE (t
)), flags
| TFF_EXPR_IN_PARENS
);
1886 dump_decl (t
, flags
);
1890 if (TREE_CODE (ob
) == INDIRECT_REF
)
1892 dump_expr (TREE_OPERAND (ob
, 0), flags
| TFF_EXPR_IN_PARENS
);
1893 output_add_string (scratch_buffer
, "->*");
1897 dump_expr (ob
, flags
| TFF_EXPR_IN_PARENS
);
1898 output_add_string (scratch_buffer
, ".*");
1900 dump_expr (TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
1905 case TEMPLATE_PARM_INDEX
:
1906 dump_decl (TEMPLATE_PARM_DECL (t
), flags
& ~TFF_DECL_SPECIFIERS
);
1909 case IDENTIFIER_NODE
:
1910 print_tree_identifier (scratch_buffer
, t
);
1914 dump_type (TREE_OPERAND (t
, 0), flags
);
1915 print_scope_operator (scratch_buffer
);
1916 dump_expr (TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
1920 if (TREE_OPERAND (t
, 0) == NULL_TREE
1921 || TREE_CHAIN (TREE_OPERAND (t
, 0)))
1923 dump_type (TREE_TYPE (t
), flags
);
1924 print_left_paren (scratch_buffer
);
1925 dump_expr_list (TREE_OPERAND (t
, 0), flags
);
1926 print_right_paren (scratch_buffer
);
1930 print_left_paren (scratch_buffer
);
1931 dump_type (TREE_TYPE (t
), flags
);
1932 output_add_string (scratch_buffer
, ")(");
1933 dump_expr_list (TREE_OPERAND (t
, 0), flags
);
1934 print_right_paren (scratch_buffer
);
1938 case STATIC_CAST_EXPR
:
1939 output_add_string (scratch_buffer
, "static_cast<");
1941 case REINTERPRET_CAST_EXPR
:
1942 output_add_string (scratch_buffer
, "reinterpret_cast<");
1944 case CONST_CAST_EXPR
:
1945 output_add_string (scratch_buffer
, "const_cast<");
1947 case DYNAMIC_CAST_EXPR
:
1948 output_add_string (scratch_buffer
, "dynamic_cast<");
1950 dump_type (TREE_TYPE (t
), flags
);
1951 output_add_string (scratch_buffer
, ">(");
1952 dump_expr (TREE_OPERAND (t
, 0), flags
);
1953 print_right_paren (scratch_buffer
);
1957 print_tree_identifier (scratch_buffer
, TREE_OPERAND (t
, 0));
1961 dump_expr (TREE_OPERAND (t
, 0), flags
);
1962 output_add_string (scratch_buffer
, "->");
1967 if (TREE_CODE (t
) == SIZEOF_EXPR
)
1968 output_add_string (scratch_buffer
, "sizeof (");
1971 my_friendly_assert (TREE_CODE (t
) == ALIGNOF_EXPR
, 0);
1972 output_add_string (scratch_buffer
, "__alignof__ (");
1974 if (TYPE_P (TREE_OPERAND (t
, 0)))
1975 dump_type (TREE_OPERAND (t
, 0), flags
);
1977 dump_unary_op ("*", t
, flags
| TFF_EXPR_IN_PARENS
);
1978 print_right_paren (scratch_buffer
);
1982 print_identifier (scratch_buffer
, "<unparsed>");
1985 case TRY_CATCH_EXPR
:
1986 case WITH_CLEANUP_EXPR
:
1987 case CLEANUP_POINT_EXPR
:
1988 dump_expr (TREE_OPERAND (t
, 0), flags
);
1991 case PSEUDO_DTOR_EXPR
:
1992 dump_expr (TREE_OPERAND (t
, 2), flags
);
1993 output_add_character (scratch_buffer
, '.');
1994 dump_type (TREE_OPERAND (t
, 0), flags
);
1995 output_add_string (scratch_buffer
, "::~");
1996 dump_type (TREE_OPERAND (t
, 1), flags
);
1999 case TEMPLATE_ID_EXPR
:
2000 dump_decl (t
, flags
);
2004 /* We don't yet have a way of dumping statements in a
2005 human-readable format. */
2006 output_add_string (scratch_buffer
, "({...})");
2010 output_add_character (scratch_buffer
, '{');
2011 dump_expr (TREE_OPERAND (t
, 1), flags
& ~TFF_EXPR_IN_PARENS
);
2012 output_add_character (scratch_buffer
, '}');
2016 output_add_string (scratch_buffer
, "while (1) { ");
2017 dump_expr (TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2018 output_add_character (scratch_buffer
, '}');
2022 output_add_string (scratch_buffer
, "if (");
2023 dump_expr (TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2024 output_add_string (scratch_buffer
, ") break; ");
2028 if (TREE_VALUE (t
) && TREE_CODE (TREE_VALUE (t
)) == FUNCTION_DECL
)
2030 print_tree_identifier (scratch_buffer
, DECL_NAME (TREE_VALUE (t
)));
2033 /* else fall through */
2035 /* This list is incomplete, but should suffice for now.
2036 It is very important that `sorry' does not call
2037 `report_error_function'. That could cause an infinite loop. */
2039 sorry_for_unsupported_tree (t
);
2040 /* fall through to ERROR_MARK... */
2042 print_identifier (scratch_buffer
, "<expression error>");
2048 dump_binary_op (opstring
, t
, flags
)
2049 const char *opstring
;
2053 print_left_paren (scratch_buffer
);
2054 dump_expr (TREE_OPERAND (t
, 0), flags
| TFF_EXPR_IN_PARENS
);
2055 output_add_space (scratch_buffer
);
2057 print_identifier (scratch_buffer
, opstring
);
2059 print_identifier (scratch_buffer
, "<unknown operator>");
2060 output_add_space (scratch_buffer
);
2061 dump_expr (TREE_OPERAND (t
, 1), flags
| TFF_EXPR_IN_PARENS
);
2062 print_right_paren (scratch_buffer
);
2066 dump_unary_op (opstring
, t
, flags
)
2067 const char *opstring
;
2071 if (flags
& TFF_EXPR_IN_PARENS
)
2072 print_left_paren (scratch_buffer
);
2073 print_identifier (scratch_buffer
, opstring
);
2074 dump_expr (TREE_OPERAND (t
, 0), flags
& ~TFF_EXPR_IN_PARENS
);
2075 if (flags
& TFF_EXPR_IN_PARENS
)
2076 print_right_paren (scratch_buffer
);
2079 /* Exported interface to stringifying types, exprs and decls under TFF_*
2083 type_as_string (typ
, flags
)
2087 reinit_global_formatting_buffer ();
2089 dump_type (typ
, flags
);
2091 return output_finalize_message (scratch_buffer
);
2095 expr_as_string (decl
, flags
)
2099 reinit_global_formatting_buffer ();
2101 dump_expr (decl
, flags
);
2103 return output_finalize_message (scratch_buffer
);
2107 decl_as_string (decl
, flags
)
2111 reinit_global_formatting_buffer ();
2113 dump_decl (decl
, flags
);
2115 return output_finalize_message (scratch_buffer
);
2119 context_as_string (context
, flags
)
2123 reinit_global_formatting_buffer ();
2125 dump_scope (context
, flags
);
2127 return output_finalize_message (scratch_buffer
);
2130 /* Generate the three forms of printable names for cxx_printable_name. */
2133 lang_decl_name (decl
, v
)
2138 return decl_as_string (decl
, TFF_DECL_SPECIFIERS
);
2140 reinit_global_formatting_buffer ();
2142 if (v
== 1 && DECL_CLASS_SCOPE_P (decl
))
2144 dump_type (CP_DECL_CONTEXT (decl
), TFF_PLAIN_IDENTIFIER
);
2145 print_scope_operator (scratch_buffer
);
2148 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2149 dump_function_name (decl
, TFF_PLAIN_IDENTIFIER
);
2151 dump_decl (DECL_NAME (decl
), TFF_PLAIN_IDENTIFIER
);
2153 return output_finalize_message (scratch_buffer
);
2160 if (TREE_CODE (t
) == PARM_DECL
&& DECL_CONTEXT (t
))
2161 return DECL_SOURCE_FILE (DECL_CONTEXT (t
));
2162 else if (TYPE_P (t
))
2163 return DECL_SOURCE_FILE (TYPE_MAIN_DECL (t
));
2164 else if (TREE_CODE (t
) == OVERLOAD
)
2165 return DECL_SOURCE_FILE (OVL_FUNCTION (t
));
2167 return DECL_SOURCE_FILE (t
);
2175 if (TREE_CODE (t
) == PARM_DECL
&& DECL_CONTEXT (t
))
2176 line
= DECL_SOURCE_LINE (DECL_CONTEXT (t
));
2177 if (TREE_CODE (t
) == TYPE_DECL
&& DECL_ARTIFICIAL (t
)
2178 && TYPE_MAIN_DECL (TREE_TYPE (t
)))
2182 line
= DECL_SOURCE_LINE (TYPE_MAIN_DECL (t
));
2183 else if (TREE_CODE (t
) == OVERLOAD
)
2184 line
= DECL_SOURCE_LINE (OVL_FUNCTION (t
));
2186 line
= DECL_SOURCE_LINE (t
);
2194 /* Now the interfaces from error et al to dump_type et al. Each takes an
2195 on/off VERBOSE flag and supply the appropriate TFF_ flags to a dump_
2199 decl_to_string (decl
, verbose
)
2205 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == RECORD_TYPE
2206 || TREE_CODE (decl
) == UNION_TYPE
|| TREE_CODE (decl
) == ENUMERAL_TYPE
)
2207 flags
= TFF_CLASS_KEY_OR_ENUM
;
2209 flags
|= TFF_DECL_SPECIFIERS
| TFF_FUNCTION_DEFAULT_ARGUMENTS
;
2210 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
2211 flags
|= TFF_DECL_SPECIFIERS
| TFF_RETURN_TYPE
;
2212 flags
|= TFF_TEMPLATE_HEADER
;
2214 reinit_global_formatting_buffer ();
2216 dump_decl (decl
, flags
);
2218 return output_finalize_message (scratch_buffer
);
2222 expr_to_string (decl
, verbose
)
2224 int verbose ATTRIBUTE_UNUSED
;
2226 reinit_global_formatting_buffer ();
2228 dump_expr (decl
, 0);
2230 return output_finalize_message (scratch_buffer
);
2234 fndecl_to_string (fndecl
, verbose
)
2240 flags
= TFF_EXCEPTION_SPECIFICATION
| TFF_DECL_SPECIFIERS
;
2242 flags
|= TFF_FUNCTION_DEFAULT_ARGUMENTS
;
2243 reinit_global_formatting_buffer ();
2245 dump_decl (fndecl
, flags
);
2247 return output_finalize_message (scratch_buffer
);
2252 code_to_string (c
, v
)
2254 int v ATTRIBUTE_UNUSED
;
2256 return tree_code_name
[c
];
2260 language_to_string (c
, v
)
2262 int v ATTRIBUTE_UNUSED
;
2269 case lang_cplusplus
:
2281 /* Return the proper printed version of a parameter to a C++ function. */
2284 parm_to_string (p
, v
)
2286 int v ATTRIBUTE_UNUSED
;
2291 sprintf (digit_buffer
, "%d", p
+1);
2292 return digit_buffer
;
2298 int v ATTRIBUTE_UNUSED
;
2302 id
= operator_name_info
[(int) p
].identifier
;
2303 return id
? IDENTIFIER_POINTER (id
) : "{unknown}";
2307 type_to_string (typ
, verbose
)
2315 flags
|= TFF_CLASS_KEY_OR_ENUM
;
2316 flags
|= TFF_TEMPLATE_HEADER
;
2318 reinit_global_formatting_buffer ();
2320 dump_type (typ
, flags
);
2322 return output_finalize_message (scratch_buffer
);
2326 assop_to_string (p
, v
)
2328 int v ATTRIBUTE_UNUSED
;
2332 id
= assignment_operator_name_info
[(int) p
].identifier
;
2333 return id
? IDENTIFIER_POINTER (id
) : "{unknown}";
2337 args_to_string (p
, verbose
)
2343 flags
|= TFF_CLASS_KEY_OR_ENUM
;
2348 if (TYPE_P (TREE_VALUE (p
)))
2349 return type_as_string (p
, flags
);
2351 reinit_global_formatting_buffer ();
2352 for (; p
; p
= TREE_CHAIN (p
))
2354 if (TREE_VALUE (p
) == null_node
)
2355 print_identifier (scratch_buffer
, "NULL");
2357 dump_type (error_type (TREE_VALUE (p
)), flags
);
2359 separate_with_comma (scratch_buffer
);
2361 return output_finalize_message (scratch_buffer
);
2369 reinit_global_formatting_buffer ();
2371 dump_qualifiers (p
, v
? before
: none
);
2373 return output_finalize_message (scratch_buffer
);
2376 /* Langhook for print_error_function. */
2378 cxx_print_error_function (context
, file
)
2379 diagnostic_context
*context
;
2384 lhd_print_error_function (context
, file
);
2385 os
= diagnostic_state (context
);
2386 output_set_prefix ((output_buffer
*)context
, file
);
2387 maybe_print_instantiation_context ((output_buffer
*)context
);
2388 diagnostic_state (context
) = os
;
2392 cp_diagnostic_starter (buffer
, dc
)
2393 output_buffer
*buffer
;
2394 diagnostic_context
*dc
;
2396 report_problematic_module (buffer
);
2397 cp_print_error_function (buffer
, dc
);
2398 maybe_print_instantiation_context (buffer
);
2399 output_set_prefix (buffer
,
2400 context_as_prefix (diagnostic_file_location (dc
),
2401 diagnostic_line_location (dc
),
2402 diagnostic_is_warning (dc
)));
2406 cp_diagnostic_finalizer (buffer
, dc
)
2407 output_buffer
*buffer
;
2408 diagnostic_context
*dc
__attribute__ ((__unused__
));
2410 output_destroy_prefix (buffer
);
2413 /* Print current function onto BUFFER, in the process of reporting
2414 a diagnostic message. Called from cp_diagnostic_starter. */
2416 cp_print_error_function (buffer
, dc
)
2417 output_buffer
*buffer
;
2418 diagnostic_context
*dc
;
2420 if (error_function_changed ())
2422 char *prefix
= diagnostic_file_location (dc
)
2423 ? file_name_as_prefix (diagnostic_file_location (dc
))
2427 os
= output_buffer_state (buffer
);
2428 output_set_prefix (buffer
, prefix
);
2430 if (current_function_decl
== NULL
)
2431 output_add_string (buffer
, "At global scope:");
2434 (buffer
, "In %s `%s':", function_category (current_function_decl
),
2435 cxx_printable_name (current_function_decl
, 2));
2436 output_add_newline (buffer
);
2438 record_last_error_function ();
2439 output_destroy_prefix (buffer
);
2440 output_buffer_state (buffer
) = os
;
2444 /* Returns a description of FUNCTION using standard terminology. */
2446 function_category (fn
)
2449 if (DECL_FUNCTION_MEMBER_P (fn
))
2451 if (DECL_STATIC_FUNCTION_P (fn
))
2452 return "static member function";
2453 else if (DECL_COPY_CONSTRUCTOR_P (fn
))
2454 return "copy constructor";
2455 else if (DECL_CONSTRUCTOR_P (fn
))
2456 return "constructor";
2457 else if (DECL_DESTRUCTOR_P (fn
))
2458 return "destructor";
2460 return "member function";
2466 /* Report the full context of a current template instantiation,
2469 print_instantiation_full_context (buffer
)
2470 output_buffer
*buffer
;
2472 tree p
= current_instantiation ();
2474 const char *file
= input_filename
;
2478 if (current_function_decl
!= TINST_DECL (p
)
2479 && current_function_decl
!= NULL_TREE
)
2480 /* We can get here during the processing of some synthesized
2481 method. Then, TINST_DECL (p) will be the function that's causing
2486 if (current_function_decl
== TINST_DECL (p
))
2487 /* Avoid redundancy with the the "In function" line. */;
2489 output_verbatim (buffer
, "%s: In instantiation of `%s':\n", file
,
2490 decl_as_string (TINST_DECL (p
),
2491 TFF_DECL_SPECIFIERS
| TFF_RETURN_TYPE
));
2493 line
= TINST_LINE (p
);
2494 file
= TINST_FILE (p
);
2499 print_instantiation_partial_context (buffer
, p
, file
, line
);
2502 /* Same as above but less verbose. */
2504 print_instantiation_partial_context (buffer
, t
, file
, line
)
2505 output_buffer
*buffer
;
2510 for (; t
; t
= TREE_CHAIN (t
))
2513 (buffer
, "%s:%d: instantiated from `%s'\n", file
, line
,
2514 decl_as_string (TINST_DECL (t
), TFF_DECL_SPECIFIERS
| TFF_RETURN_TYPE
));
2515 line
= TINST_LINE (t
);
2516 file
= TINST_FILE (t
);
2518 output_verbatim (buffer
, "%s:%d: instantiated from here\n", file
, line
);
2521 /* Called from cp_thing to print the template context for an error. */
2523 maybe_print_instantiation_context (buffer
)
2524 output_buffer
*buffer
;
2526 if (!problematic_instantiation_changed () || current_instantiation () == 0)
2529 record_last_problematic_instantiation ();
2530 print_instantiation_full_context (buffer
);
2533 /* Report the bare minimum context of a template instantiation. */
2535 print_instantiation_context ()
2537 print_instantiation_partial_context
2538 (diagnostic_buffer
, current_instantiation (), input_filename
, lineno
);
2539 flush_diagnostic_buffer ();
2542 /* Called from output_format -- during diagnostic message processing --
2543 to handle C++ specific format specifier with the following meanings:
2544 %A function argument-list.
2548 %F function declaration.
2549 %L language as used in extern "lang".
2551 %P function parameter whose position is indicated by an integer.
2552 %Q assignment operator.
2557 output_buffer
*buffer
;
2561 #define next_tree va_arg (output_buffer_format_args (buffer), tree)
2562 #define next_tcode va_arg (output_buffer_format_args (buffer), enum tree_code)
2563 #define next_lang va_arg (output_buffer_format_args (buffer), enum languages)
2564 #define next_int va_arg (output_buffer_format_args (buffer), int)
2566 if (*output_buffer_text_cursor (buffer
) == '+')
2567 ++output_buffer_text_cursor (buffer
);
2568 if (*output_buffer_text_cursor (buffer
) == '#')
2571 ++output_buffer_text_cursor (buffer
);
2574 switch (*output_buffer_text_cursor (buffer
))
2576 case 'A': result
= args_to_string (next_tree
, verbose
); break;
2577 case 'C': result
= code_to_string (next_tcode
, verbose
); break;
2578 case 'D': result
= decl_to_string (next_tree
, verbose
); break;
2579 case 'E': result
= expr_to_string (next_tree
, verbose
); break;
2580 case 'F': result
= fndecl_to_string (next_tree
, verbose
); break;
2581 case 'L': result
= language_to_string (next_lang
, verbose
); break;
2582 case 'O': result
= op_to_string (next_tcode
, verbose
); break;
2583 case 'P': result
= parm_to_string (next_int
, verbose
); break;
2584 case 'Q': result
= assop_to_string (next_tcode
, verbose
); break;
2585 case 'T': result
= type_to_string (next_tree
, verbose
); break;
2586 case 'V': result
= cv_to_string (next_tree
, verbose
); break;
2592 output_add_string (buffer
, result
);
2601 print_integer (buffer
, i
)
2602 output_buffer
*buffer
;
2605 sprintf (digit_buffer
, HOST_WIDE_INT_PRINT_DEC
, (HOST_WIDE_INT
) i
);
2606 output_add_string (buffer
, digit_buffer
);
2610 print_non_consecutive_character (buffer
, c
)
2611 output_buffer
*buffer
;
2614 const char *p
= output_last_position (buffer
);
2616 if (p
!= NULL
&& *p
== c
)
2617 output_add_space (buffer
);
2618 output_add_character (buffer
, c
);
2621 /* These are temporary wrapper functions which handle the historic
2622 behavior of cp_*_at. */
2625 locate_error (msgid
, ap
)
2633 for (f
= msgid
; *f
; f
++)
2646 /* Just ignore these possibilities. */
2648 case 'd': (void) va_arg (ap
, int); break;
2649 case 's': (void) va_arg (ap
, char *); break;
2650 case 'L': (void) va_arg (ap
, enum languages
); break;
2653 case 'Q': (void) va_arg (ap
, enum tree_code
); break;
2655 /* These take a tree, which may be where the error is
2664 t
= va_arg (ap
, tree
);
2670 errorcount
= 0; /* damn ICE suppression */
2671 internal_error ("unexpected letter `%c' in locate_error\n", *f
);
2677 here
= va_arg (ap
, tree
);
2684 cp_error_at
VPARAMS ((const char *msgid
, ...))
2687 diagnostic_context dc
;
2689 VA_OPEN (ap
, msgid
);
2690 VA_FIXEDARG (ap
, const char *, msgid
);
2691 here
= locate_error (msgid
, ap
);
2694 VA_OPEN (ap
, msgid
);
2695 VA_FIXEDARG (ap
, const char *, msgid
);
2697 set_diagnostic_context (&dc
, msgid
, &ap
,
2699 cp_line_of (here
), /* warning = */ 0);
2700 report_diagnostic (&dc
);
2705 cp_warning_at
VPARAMS ((const char *msgid
, ...))
2708 diagnostic_context dc
;
2710 VA_OPEN (ap
, msgid
);
2711 VA_FIXEDARG (ap
, const char *, msgid
);
2712 here
= locate_error (msgid
, ap
);
2715 VA_OPEN (ap
, msgid
);
2716 VA_FIXEDARG (ap
, const char *, msgid
);
2718 set_diagnostic_context (&dc
, msgid
, &ap
,
2720 cp_line_of (here
), /* warning = */ 1);
2721 report_diagnostic (&dc
);
2726 cp_pedwarn_at
VPARAMS ((const char *msgid
, ...))
2729 diagnostic_context dc
;
2731 VA_OPEN (ap
, msgid
);
2732 VA_FIXEDARG (ap
, const char *, msgid
);
2733 here
= locate_error (msgid
, ap
);
2736 VA_OPEN (ap
, msgid
);
2737 VA_FIXEDARG (ap
, const char *, msgid
);
2739 set_diagnostic_context (&dc
, msgid
, &ap
,
2742 /* warning = */ !flag_pedantic_errors
);
2743 report_diagnostic (&dc
);