1 /* Call-backs for C++ error reporting.
2 This code is non-reentrant.
3 Copyright (C) 1993, 1994, 1995, 1996 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. */
29 typedef char* cp_printer ();
31 #define A args_as_string
32 #define C code_as_string
33 #define D decl_as_string
34 #define E expr_as_string
35 #define L language_as_string
36 #define O op_as_string
37 #define P parm_as_string
38 #define Q assop_as_string
39 #define T type_as_string
40 #define V cv_as_string
42 #define _ (cp_printer *) 0
43 cp_printer
* cp_printers
[256] =
45 /*0 1 2 3 4 5 6 7 8 9 A B C D E F */
46 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0x00 */
47 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0x10 */
48 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0x20 */
49 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0x30 */
50 _
, A
, _
, C
, D
, E
, _
, _
, _
, _
, _
, _
, L
, _
, _
, O
, /* 0x40 */
51 P
, Q
, _
, _
, T
, _
, V
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0x50 */
52 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0x60 */
53 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0x70 */
66 #define obstack_chunk_alloc xmalloc
67 #define obstack_chunk_free free
69 /* Obstack where we build text strings for overloading, etc. */
70 static struct obstack scratch_obstack
;
71 static char *scratch_firstobj
;
73 # define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
74 # define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
75 # define OB_PUTC2(C1,C2) \
76 (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
77 # define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
78 # define OB_PUTID(ID) \
79 (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \
80 IDENTIFIER_LENGTH (ID)))
81 # define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
82 # define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
83 # define OB_PUTI(CST) do { sprintf (digit_buffer, "%d", (CST)); \
84 OB_PUTCP (digit_buffer); } while (0)
85 # define OB_UNPUT(N) obstack_blank (&scratch_obstack, - (N));
87 # define NEXT_CODE(t) (TREE_CODE (TREE_TYPE (t)))
89 enum pad
{ none
, before
, after
};
91 static void dump_type
PROTO((tree
, int));
92 static void dump_decl
PROTO((tree
, int));
93 static void dump_function_decl
PROTO((tree
, int));
94 static void dump_expr
PROTO((tree
, int));
95 static void dump_unary_op
PROTO((char *, tree
, int));
96 static void dump_binary_op
PROTO((char *, tree
));
97 static void dump_aggr_type
PROTO((tree
, int));
98 static void dump_type_prefix
PROTO((tree
, int));
99 static void dump_type_suffix
PROTO((tree
, int));
100 static void dump_function_name
PROTO((tree
));
101 static void dump_expr_list
PROTO((tree
));
102 static void dump_global_iord
PROTO((tree
));
103 static void dump_readonly_or_volatile
PROTO((tree
, enum pad
));
104 static void dump_char
PROTO((char));
105 static char *aggr_variety
PROTO((tree
));
106 static tree ident_fndecl
PROTO((tree
));
111 gcc_obstack_init (&scratch_obstack
);
112 scratch_firstobj
= (char *)obstack_alloc (&scratch_obstack
, 0);
116 dump_readonly_or_volatile (t
, p
)
120 if (TYPE_READONLY (t
) || TYPE_VOLATILE (t
))
122 if (p
== before
) OB_PUTC (' ');
123 if (TYPE_READONLY (t
))
125 if (TYPE_READONLY (t
) && TYPE_VOLATILE (t
))
127 if (TYPE_VOLATILE (t
))
128 OB_PUTS ("volatile");
129 if (p
== after
) OB_PUTC (' ');
133 /* This must be large enough to hold any printed integer or floating-point
135 static char digit_buffer
[128];
137 /* Dump into the obstack a human-readable equivalent of TYPE. */
142 int v
; /* verbose? */
147 if (TYPE_PTRMEMFUNC_P (t
))
150 switch (TREE_CODE (t
))
157 OB_PUTS ("{unknown type}");
161 /* i.e. function taking no arguments */
162 if (t
!= void_list_node
)
164 dump_type (TREE_VALUE (t
), v
);
165 /* Can this happen other than for default arguments? */
166 if (TREE_PURPOSE (t
) && v
)
169 dump_expr (TREE_PURPOSE (t
), 0);
173 if (TREE_CHAIN (t
) != void_list_node
)
176 dump_type (TREE_CHAIN (t
), v
);
179 else OB_PUTS (" ...");
183 case IDENTIFIER_NODE
:
188 dump_type (BINFO_TYPE (t
), v
);
194 if (TYPE_LANG_SPECIFIC (t
)
195 && (IS_SIGNATURE_POINTER (t
) || IS_SIGNATURE_REFERENCE (t
)))
197 if (TYPE_READONLY (t
) | TYPE_VOLATILE (t
))
198 dump_readonly_or_volatile (t
, after
);
199 dump_type (SIGNATURE_TYPE (t
), v
);
200 if (IS_SIGNATURE_POINTER (t
))
206 dump_aggr_type (t
, v
);
214 OB_PUTS ("complex ");
215 dump_type (TREE_TYPE (t
), v
);
219 if (!TREE_UNSIGNED (TYPE_MAIN_VARIANT (t
)) && TREE_UNSIGNED (t
))
220 OB_PUTS ("unsigned ");
221 else if (TREE_UNSIGNED (TYPE_MAIN_VARIANT (t
)) && !TREE_UNSIGNED (t
))
228 dump_readonly_or_volatile (t
, after
);
229 OB_PUTID (TYPE_IDENTIFIER (t
));
232 case TEMPLATE_TYPE_PARM
:
233 dump_readonly_or_volatile (t
, after
);
234 if (TYPE_IDENTIFIER (t
))
235 OB_PUTID (TYPE_IDENTIFIER (t
));
237 OB_PUTS ("{anonymous template type parm}");
240 /* This is not always necessary for pointers and such, but doing this
241 reduces code size. */
249 dump_type_prefix (t
, v
);
250 dump_type_suffix (t
, v
);
254 OB_PUTS ("typename ");
255 dump_type (TYPE_CONTEXT (t
), 0);
257 OB_PUTID (TYPE_IDENTIFIER (t
));
261 sorry ("`%s' not supported by dump_type",
262 tree_code_name
[(int) TREE_CODE (t
)]);
270 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
272 else if (TREE_CODE (t
) == UNION_TYPE
)
274 else if (TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_DECLARED_CLASS (t
))
276 else if (TYPE_LANG_SPECIFIC (t
) && IS_SIGNATURE (t
))
282 /* Print out a class declaration, in the form `class foo'. */
285 dump_aggr_type (t
, v
)
287 int v
; /* verbose? */
290 char *variety
= aggr_variety (t
);
292 dump_readonly_or_volatile (t
, after
);
300 name
= TYPE_NAME (t
);
302 if (name
&& DECL_CONTEXT (name
))
304 /* FUNCTION_DECL or RECORD_TYPE */
305 dump_decl (DECL_CONTEXT (name
), 0);
309 /* kludge around weird behavior on g++.brendan/line1.C */
310 if (name
&& TREE_CODE (name
) != IDENTIFIER_NODE
)
311 name
= DECL_NAME (name
);
313 if (name
== 0 || ANON_AGGRNAME_P (name
))
315 OB_PUTS ("{anonymous");
327 /* Dump into the obstack the initial part of the output for a given type.
328 This is necessary when dealing with things like functions returning
331 return type of `int (* fee ())()': pointer -> function -> int. Both
332 pointer (and reference and offset) and function (and member) types must
333 deal with prefix and suffix.
335 Arrays must also do this for DECL nodes, like int a[], and for things like
339 dump_type_prefix (t
, v
)
341 int v
; /* verbosity */
343 if (TYPE_PTRMEMFUNC_P (t
))
345 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
349 switch (TREE_CODE (t
))
353 tree sub
= TREE_TYPE (t
);
355 dump_type_prefix (sub
, v
);
356 /* A tree for a member pointer looks like pointer to offset,
357 so let the OFFSET_TYPE case handle it. */
358 if (TREE_CODE (sub
) != OFFSET_TYPE
)
360 switch (TREE_CODE (sub
))
362 /* We don't want int ( *)() */
372 /* We don't want "char * *" */
373 if (! (TYPE_READONLY (sub
) || TYPE_VOLATILE (sub
)))
375 /* But we do want "char *const *" */
381 dump_readonly_or_volatile (t
, none
);
388 tree sub
= TREE_TYPE (t
);
389 dump_type_prefix (sub
, v
);
391 switch (TREE_CODE (sub
))
398 /* We don't want "char * &" */
399 if (! (TYPE_READONLY (sub
) || TYPE_VOLATILE (sub
)))
401 /* But we do want "char *const &" */
408 dump_readonly_or_volatile (t
, none
);
413 dump_type_prefix (TREE_TYPE (t
), v
);
414 if (TREE_CODE (t
) == OFFSET_TYPE
) /* pmfs deal with this in d_t_p */
417 dump_type (TYPE_OFFSET_BASETYPE (t
), 0);
421 dump_readonly_or_volatile (t
, none
);
424 /* Can only be reached through function pointer -- this would not be
425 correct if FUNCTION_DECLs used it. */
427 dump_type_prefix (TREE_TYPE (t
), v
);
432 dump_type_prefix (TREE_TYPE (t
), v
);
434 dump_aggr_type (TYPE_METHOD_BASETYPE (t
), 0);
439 dump_type_prefix (TREE_TYPE (t
), v
);
444 case IDENTIFIER_NODE
:
449 case TEMPLATE_TYPE_PARM
:
462 sorry ("`%s' not supported by dump_type_prefix",
463 tree_code_name
[(int) TREE_CODE (t
)]);
468 dump_type_suffix (t
, v
)
470 int v
; /* verbose? */
472 if (TYPE_PTRMEMFUNC_P (t
))
473 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
475 switch (TREE_CODE (t
))
480 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
482 dump_type_suffix (TREE_TYPE (t
), v
);
485 /* Can only be reached through function pointer */
491 arg
= TYPE_ARG_TYPES (t
);
492 if (TREE_CODE (t
) == METHOD_TYPE
)
493 arg
= TREE_CHAIN (arg
);
500 if (TREE_CODE (t
) == METHOD_TYPE
)
501 dump_readonly_or_volatile
502 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t
))), before
);
503 dump_type_suffix (TREE_TYPE (t
), v
);
511 if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (t
))) == INTEGER_CST
)
512 OB_PUTI (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (t
))) + 1);
513 else if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (t
))) == MINUS_EXPR
)
514 dump_expr (TREE_OPERAND (TYPE_MAX_VALUE (TYPE_DOMAIN (t
)), 0), 0);
516 dump_expr (fold (build_binary_op
517 (PLUS_EXPR
, TYPE_MAX_VALUE (TYPE_DOMAIN (t
)),
518 integer_one_node
, 1)), 0);
521 dump_type_suffix (TREE_TYPE (t
), v
);
526 case IDENTIFIER_NODE
:
531 case TEMPLATE_TYPE_PARM
:
543 sorry ("`%s' not supported by dump_type_suffix",
544 tree_code_name
[(int) TREE_CODE (t
)]);
548 /* Return a function declaration which corresponds to the IDENTIFIER_NODE
555 tree n
= lookup_name (t
, 0);
560 if (TREE_CODE (n
) == FUNCTION_DECL
)
562 else if (TREE_CODE (n
) == TREE_LIST
563 && TREE_CODE (TREE_VALUE (n
)) == FUNCTION_DECL
)
564 return TREE_VALUE (n
);
566 my_friendly_abort (66);
570 #ifndef NO_DOLLAR_IN_LABEL
571 # define GLOBAL_THING "_GLOBAL_$"
573 # ifndef NO_DOT_IN_LABEL
574 # define GLOBAL_THING "_GLOBAL_."
576 # define GLOBAL_THING "_GLOBAL__"
580 #define GLOBAL_IORD_P(NODE) \
581 ! strncmp (IDENTIFIER_POINTER(NODE), GLOBAL_THING, sizeof (GLOBAL_THING) - 1)
587 char *name
= IDENTIFIER_POINTER (t
);
589 OB_PUTS ("(static ");
590 if (name
[sizeof (GLOBAL_THING
) - 1] == 'I')
591 OB_PUTS ("initializers");
592 else if (name
[sizeof (GLOBAL_THING
) - 1] == 'D')
593 OB_PUTS ("destructors");
595 my_friendly_abort (352);
598 OB_PUTCP (input_filename
);
605 int v
; /* verbosity */
610 switch (TREE_CODE (t
))
613 OB_PUTS (" /* decl error */ ");
618 /* Don't say 'typedef class A' */
619 if (DECL_ARTIFICIAL (t
))
621 dump_type (TREE_TYPE (t
), v
);
626 OB_PUTS ("typedef ");
631 if (DECL_NAME (t
) && VTABLE_NAME_P (DECL_NAME (t
)))
633 OB_PUTS ("vtable for ");
634 dump_type (DECL_CONTEXT (t
), v
);
637 /* else fall through */
643 dump_type_prefix (TREE_TYPE (t
), v
);
645 dump_readonly_or_volatile (t
, after
);
647 /* DECL_CLASS_CONTEXT isn't being set in some cases. Hmm... */
649 && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (t
))) == 't')
651 dump_type (DECL_CONTEXT (t
), 0);
655 dump_decl (DECL_NAME (t
), v
);
659 dump_type_suffix (TREE_TYPE (t
), v
);
663 OB_PUTID (DECL_NAME (t
));
667 dump_decl (TREE_OPERAND (t
, 0), v
);
669 dump_decl (TREE_OPERAND (t
, 1), v
);
673 /* So that we can do dump_decl in dump_aggr_type and have it work for
674 both class and function scope. */
682 my_friendly_abort (69);
685 /* These special cases are duplicated here so that other functions
686 can feed identifiers to cp_error and get them demangled properly. */
687 case IDENTIFIER_NODE
:
689 if (DESTRUCTOR_NAME_P (t
)
690 && (f
= ident_fndecl (t
))
691 && DECL_LANGUAGE (f
) == lang_cplusplus
)
694 dump_decl (DECL_NAME (f
), 0);
696 else if (IDENTIFIER_TYPENAME_P (t
))
698 OB_PUTS ("operator ");
699 /* Not exactly IDENTIFIER_TYPE_VALUE. */
700 dump_type (TREE_TYPE (t
), 0);
703 else if (IDENTIFIER_OPNAME_P (t
))
705 char *name_string
= operator_name_string (t
);
706 OB_PUTS ("operator ");
707 OB_PUTCP (name_string
);
715 if (GLOBAL_IORD_P (DECL_ASSEMBLER_NAME (t
)))
716 dump_global_iord (DECL_ASSEMBLER_NAME (t
));
717 else if (! DECL_LANG_SPECIFIC (t
))
718 OB_PUTS ("{internal}");
720 dump_function_decl (t
, v
);
725 tree orig_args
= DECL_TEMPLATE_PARMS (t
);
728 for (args
= orig_args
= nreverse (orig_args
);
730 args
= TREE_CHAIN (args
))
732 int len
= TREE_VEC_LENGTH (TREE_VALUE (args
));
734 OB_PUTS ("template <");
735 for (i
= 0; i
< len
; i
++)
737 tree arg
= TREE_VEC_ELT (TREE_VALUE (args
), i
);
738 tree defval
= TREE_PURPOSE (arg
);
739 arg
= TREE_VALUE (arg
);
740 if (TREE_CODE (arg
) == TYPE_DECL
)
743 OB_PUTID (DECL_NAME (arg
));
751 dump_decl (defval
, 1);
762 if (TREE_CODE (DECL_TEMPLATE_RESULT (t
)) == TYPE_DECL
)
763 dump_type (TREE_TYPE (t
), v
);
764 else if (TREE_TYPE (t
) == NULL_TREE
)
765 my_friendly_abort (353);
766 else switch (NEXT_CODE (t
))
770 dump_function_decl (t
, v
);
774 my_friendly_abort (353);
780 OB_PUTID (DECL_NAME (t
));
784 if ((TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == ENUMERAL_TYPE
)
785 || TREE_CODE (DECL_INITIAL (t
)) == TEMPLATE_CONST_PARM
)
788 dump_expr (DECL_INITIAL (t
), 0);
793 dump_type (DECL_INITIAL (t
), 0);
795 OB_PUTID (DECL_NAME (t
));
799 sorry ("`%s' not supported by dump_decl",
800 tree_code_name
[(int) TREE_CODE (t
)]);
804 /* Pretty printing for announce_function. T is the declaration of the
805 function we are interested in seeing. V is non-zero if we should print
806 the type that this function returns. */
809 dump_function_decl (t
, v
)
816 tree cname
= NULL_TREE
;
818 if (TREE_CODE (t
) == TEMPLATE_DECL
)
819 t
= DECL_TEMPLATE_RESULT (t
);
821 name
= DECL_ASSEMBLER_NAME (t
);
822 fntype
= TREE_TYPE (t
);
823 parmtypes
= TYPE_ARG_TYPES (fntype
);
825 /* Friends have DECL_CLASS_CONTEXT set, but not DECL_CONTEXT. */
826 if (DECL_CONTEXT (t
))
827 cname
= DECL_CLASS_CONTEXT (t
);
828 /* this is for partially instantiated template methods */
829 else if (TREE_CODE (fntype
) == METHOD_TYPE
)
830 cname
= TREE_TYPE (TREE_VALUE (parmtypes
));
836 if (DECL_STATIC_FUNCTION_P (t
))
839 if (! IDENTIFIER_TYPENAME_P (name
)
840 && ! DECL_CONSTRUCTOR_P (t
)
841 && ! DESTRUCTOR_NAME_P (name
))
843 dump_type_prefix (TREE_TYPE (fntype
), 1);
850 dump_type (cname
, 0);
852 if (TREE_CODE (fntype
) == METHOD_TYPE
&& parmtypes
)
853 parmtypes
= TREE_CHAIN (parmtypes
);
854 if (DECL_CONSTRUCTOR_FOR_VBASE_P (t
))
855 /* Skip past "in_charge" identifier. */
856 parmtypes
= TREE_CHAIN (parmtypes
);
859 if (DESTRUCTOR_NAME_P (name
) && DECL_LANGUAGE (t
) == lang_cplusplus
)
860 parmtypes
= TREE_CHAIN (parmtypes
);
862 dump_function_name (t
);
867 dump_type (parmtypes
, v
);
873 if (v
&& ! IDENTIFIER_TYPENAME_P (name
))
874 dump_type_suffix (TREE_TYPE (fntype
), 1);
876 if (TREE_CODE (fntype
) == METHOD_TYPE
)
878 if (IS_SIGNATURE (cname
))
879 /* We look at the type pointed to by the `optr' field of `this.' */
880 dump_readonly_or_volatile
881 (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_VALUE (TYPE_ARG_TYPES (fntype
))))), before
);
883 dump_readonly_or_volatile
884 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype
))), before
);
888 /* Handle the function name for a FUNCTION_DECL node, grokking operators
889 and destructors properly. */
892 dump_function_name (t
)
895 tree name
= DECL_NAME (t
);
897 /* There ought to be a better way to find out whether or not something is
899 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (t
))
900 && DECL_LANGUAGE (t
) == lang_cplusplus
)
905 else if (IDENTIFIER_TYPENAME_P (name
))
907 /* This cannot use the hack that the operator's return
908 type is stashed off of its name because it may be
909 used for error reporting. In the case of conflicting
910 declarations, both will have the same name, yet
911 the types will be different, hence the TREE_TYPE field
912 of the first name will be clobbered by the second. */
913 OB_PUTS ("operator ");
914 dump_type (TREE_TYPE (TREE_TYPE (t
)), 0);
916 else if (IDENTIFIER_OPNAME_P (name
))
918 char *name_string
= operator_name_string (name
);
919 OB_PUTS ("operator ");
920 OB_PUTCP (name_string
);
967 sprintf (digit_buffer
, "\\%03o", (int) c
);
968 OB_PUTCP (digit_buffer
);
973 /* Print out a list of initializers (subr of dump_expr) */
981 dump_expr (TREE_VALUE (l
), 0);
988 /* Print out an expression */
993 int nop
; /* suppress parens */
995 switch (TREE_CODE (t
))
1008 tree type
= TREE_TYPE (t
);
1009 my_friendly_assert (type
!= 0, 81);
1011 /* If it's an enum, output its tag, rather than its value. */
1012 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1014 char *p
= enum_name_string (t
, type
);
1017 else if (type
== boolean_type_node
)
1019 if (t
== boolean_false_node
1020 || (TREE_INT_CST_LOW (t
) == 0
1021 && TREE_INT_CST_HIGH (t
) == 0))
1023 else if (t
== boolean_true_node
)
1026 else if (type
== char_type_node
)
1029 dump_char (TREE_INT_CST_LOW (t
));
1032 else if (TREE_INT_CST_HIGH (t
)
1033 != (TREE_INT_CST_LOW (t
) >> (HOST_BITS_PER_WIDE_INT
- 1)))
1036 if (TREE_INT_CST_HIGH (val
) < 0)
1039 val
= build_int_2 (~TREE_INT_CST_LOW (val
),
1040 -TREE_INT_CST_HIGH (val
));
1042 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
1045 static char format
[10]; /* "%x%09999x\0" */
1047 sprintf (format
, "%%x%%0%dx", HOST_BITS_PER_INT
/ 4);
1048 sprintf (digit_buffer
, format
, TREE_INT_CST_HIGH (val
),
1049 TREE_INT_CST_LOW (val
));
1050 OB_PUTCP (digit_buffer
);
1054 OB_PUTI (TREE_INT_CST_LOW (t
));
1059 #ifndef REAL_IS_NOT_DOUBLE
1060 sprintf (digit_buffer
, "%g", TREE_REAL_CST (t
));
1063 unsigned char *p
= (unsigned char *) &TREE_REAL_CST (t
);
1065 strcpy (digit_buffer
, "0x");
1066 for (i
= 0; i
< sizeof TREE_REAL_CST (t
); i
++)
1067 sprintf (digit_buffer
+ 2 + 2*i
, "%02x", *p
++);
1070 OB_PUTCP (digit_buffer
);
1075 char *p
= TREE_STRING_POINTER (t
);
1076 int len
= TREE_STRING_LENGTH (t
) - 1;
1080 for (i
= 0; i
< len
; i
++)
1087 dump_binary_op (",", t
);
1092 dump_expr (TREE_OPERAND (t
, 0), 0);
1094 dump_expr (TREE_OPERAND (t
, 1), 0);
1096 dump_expr (TREE_OPERAND (t
, 2), 0);
1101 if (TREE_HAS_CONSTRUCTOR (t
))
1104 dump_type (TREE_TYPE (TREE_TYPE (t
)), 0);
1105 PARM_DECL_EXPR (t
) = 1;
1109 dump_expr (TREE_OPERAND (t
, 0), 0);
1114 OB_PUTID (TYPE_IDENTIFIER (TREE_TYPE (t
)));
1116 if (TREE_OPERAND (t
, 1))
1117 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t
, 1)));
1123 tree fn
= TREE_OPERAND (t
, 0);
1124 tree args
= TREE_OPERAND (t
, 1);
1126 if (TREE_CODE (fn
) == ADDR_EXPR
)
1127 fn
= TREE_OPERAND (fn
, 0);
1129 if (TREE_TYPE (fn
) != NULL_TREE
&& NEXT_CODE (fn
) == METHOD_TYPE
)
1131 tree ob
= TREE_VALUE (args
);
1132 if (TREE_CODE (ob
) == ADDR_EXPR
)
1134 dump_expr (TREE_OPERAND (ob
, 0), 0);
1137 else if (TREE_CODE (ob
) != PARM_DECL
1138 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob
)), "this"))
1141 OB_PUTC2 ('-', '>');
1143 args
= TREE_CHAIN (args
);
1147 dump_expr_list (args
);
1153 /* Note that this only works for G++ target exprs. If somebody
1154 builds a general TARGET_EXPR, there's no way to represent that
1155 it initializes anything other that the parameter slot for the
1156 default argument. Note we may have cleared out the first
1157 operand in expand_expr, so don't go killing ourselves. */
1158 if (TREE_OPERAND (t
, 1))
1159 dump_expr (TREE_OPERAND (t
, 1), 0);
1166 case TRUNC_DIV_EXPR
:
1167 case TRUNC_MOD_EXPR
:
1175 case BIT_ANDTC_EXPR
:
1176 case TRUTH_ANDIF_EXPR
:
1177 case TRUTH_ORIF_EXPR
:
1184 dump_binary_op (opname_tab
[(int) TREE_CODE (t
)], t
);
1188 case FLOOR_DIV_EXPR
:
1189 case ROUND_DIV_EXPR
:
1190 dump_binary_op ("/", t
);
1194 case FLOOR_MOD_EXPR
:
1195 case ROUND_MOD_EXPR
:
1196 dump_binary_op ("%", t
);
1201 tree ob
= TREE_OPERAND (t
, 0);
1202 if (TREE_CODE (ob
) == INDIRECT_REF
)
1204 ob
= TREE_OPERAND (ob
, 0);
1205 if (TREE_CODE (ob
) != PARM_DECL
1206 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob
)), "this"))
1209 OB_PUTC2 ('-', '>');
1217 dump_expr (TREE_OPERAND (t
, 1), 1);
1222 dump_expr (TREE_OPERAND (t
, 0), 0);
1224 dump_expr (TREE_OPERAND (t
, 1), 0);
1229 dump_unary_op ("+", t
, nop
);
1233 if (TREE_CODE (TREE_OPERAND (t
, 0)) == FUNCTION_DECL
1234 || TREE_CODE (TREE_OPERAND (t
, 0)) == STRING_CST
)
1235 dump_expr (TREE_OPERAND (t
, 0), 0);
1237 dump_unary_op ("&", t
, nop
);
1241 if (TREE_HAS_CONSTRUCTOR (t
))
1243 t
= TREE_OPERAND (t
, 0);
1244 my_friendly_assert (TREE_CODE (t
) == CALL_EXPR
, 237);
1245 dump_expr (TREE_OPERAND (t
, 0), 0);
1247 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t
, 1)));
1252 if (TREE_OPERAND (t
,0) != NULL_TREE
1253 && NEXT_CODE (TREE_OPERAND (t
, 0)) == REFERENCE_TYPE
)
1254 dump_expr (TREE_OPERAND (t
, 0), nop
);
1256 dump_unary_op ("*", t
, nop
);
1262 case TRUTH_NOT_EXPR
:
1263 case PREDECREMENT_EXPR
:
1264 case PREINCREMENT_EXPR
:
1265 dump_unary_op (opname_tab
[(int)TREE_CODE (t
)], t
, nop
);
1268 case POSTDECREMENT_EXPR
:
1269 case POSTINCREMENT_EXPR
:
1271 dump_expr (TREE_OPERAND (t
, 0), 0);
1272 OB_PUTCP (opname_tab
[(int)TREE_CODE (t
)]);
1276 case NON_LVALUE_EXPR
:
1277 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
1278 should be another level of INDIRECT_REF so that I don't have to do
1280 if (TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == POINTER_TYPE
)
1282 tree next
= TREE_TYPE (TREE_TYPE (t
));
1284 while (TREE_CODE (next
) == POINTER_TYPE
)
1285 next
= TREE_TYPE (next
);
1287 if (TREE_CODE (next
) == FUNCTION_TYPE
)
1289 if (!nop
) OB_PUTC ('(');
1291 dump_expr (TREE_OPERAND (t
, 0), 1);
1292 if (!nop
) OB_PUTC (')');
1297 dump_expr (TREE_OPERAND (t
, 0), 0);
1301 dump_expr (TREE_OPERAND (t
, 0), nop
);
1305 if (TREE_TYPE (t
) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t
)))
1307 tree idx
= build_component_ref (t
, index_identifier
, NULL_TREE
, 0);
1309 if (integer_all_onesp (idx
))
1311 tree pfn
= PFN_FROM_PTRMEMFUNC (t
);
1315 if (TREE_CODE (idx
) == INTEGER_CST
1316 && TREE_INT_CST_HIGH (idx
) == 0)
1319 unsigned HOST_WIDE_INT n
;
1321 t
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t
)));
1322 t
= TYPE_METHOD_BASETYPE (t
);
1323 virtuals
= BINFO_VIRTUALS (TYPE_BINFO (TYPE_MAIN_VARIANT (t
)));
1325 n
= TREE_INT_CST_LOW (idx
);
1327 /* Map vtable index back one, to allow for the null pointer to
1331 while (n
> 0 && virtuals
)
1334 virtuals
= TREE_CHAIN (virtuals
);
1338 dump_expr (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals
)), 0);
1344 dump_expr_list (CONSTRUCTOR_ELTS (t
));
1350 tree ob
= TREE_OPERAND (t
, 0);
1351 if (TREE_CODE (ob
) == NOP_EXPR
1352 && TREE_OPERAND (ob
, 0) == error_mark_node
1353 && TREE_CODE (TREE_OPERAND (t
, 1)) == FUNCTION_DECL
)
1355 dump_expr (TREE_OPERAND (t
, 1), 0);
1358 dump_expr (TREE_OPERAND (t
, 0), 0);
1360 dump_expr (TREE_OPERAND (t
, 1), 0);
1365 case TEMPLATE_CONST_PARM
:
1366 if (current_template_parms
)
1372 for (parms
= current_template_parms
;
1374 parms
= TREE_CHAIN (parms
))
1377 r
= TREE_VEC_ELT (TREE_VALUE (parms
),
1378 TEMPLATE_CONST_IDX (t
));
1379 dump_decl (TREE_VALUE (r
), -1);
1383 OB_PUTS ("<tparm ");
1384 OB_PUTI (TEMPLATE_CONST_IDX (t
));
1389 case IDENTIFIER_NODE
:
1394 dump_type (TREE_OPERAND (t
, 0), 0);
1396 dump_expr (TREE_OPERAND (t
, 1), 0);
1400 if (TREE_OPERAND (t
, 0) == NULL_TREE
1401 || TREE_CHAIN (TREE_OPERAND (t
, 0)))
1403 dump_type (TREE_TYPE (t
), 0);
1405 dump_expr_list (TREE_OPERAND (t
, 0));
1411 dump_type (TREE_TYPE (t
), 0);
1414 dump_expr_list (TREE_OPERAND (t
, 0));
1420 OB_PUTID (TREE_OPERAND (t
, 0));
1424 OB_PUTS ("sizeof (");
1425 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t
, 0))) == 't')
1426 dump_type (TREE_OPERAND (t
, 0), 0);
1428 dump_unary_op ("*", t
, 0);
1433 OB_PUTS ("{unparsed}");
1437 if (TREE_VALUE (t
) && TREE_CODE (TREE_VALUE (t
)) == FUNCTION_DECL
)
1439 OB_PUTID (DECL_NAME (TREE_VALUE (t
)));
1442 /* else fall through */
1444 /* This list is incomplete, but should suffice for now.
1445 It is very important that `sorry' does not call
1446 `report_error_function'. That could cause an infinite loop. */
1448 sorry ("`%s' not supported by dump_expr",
1449 tree_code_name
[(int) TREE_CODE (t
)]);
1451 /* fall through to ERROR_MARK... */
1454 OB_PUTCP ("{error}");
1460 dump_binary_op (opstring
, t
)
1465 dump_expr (TREE_OPERAND (t
, 0), 1);
1467 OB_PUTCP (opstring
);
1469 dump_expr (TREE_OPERAND (t
, 1), 1);
1474 dump_unary_op (opstring
, t
, nop
)
1479 if (!nop
) OB_PUTC ('(');
1480 OB_PUTCP (opstring
);
1481 dump_expr (TREE_OPERAND (t
, 0), 1);
1482 if (!nop
) OB_PUTC (')');
1486 fndecl_as_string (fndecl
, print_ret_type_p
)
1488 int print_ret_type_p
;
1490 return decl_as_string (fndecl
, print_ret_type_p
);
1493 /* Same, but handtype a _TYPE.
1494 Called from convert_to_reference, mangle_class_name_for_template,
1495 build_unary_op, and GNU_xref_decl. */
1498 type_as_string (typ
, v
)
1508 return (char *)obstack_base (&scratch_obstack
);
1512 expr_as_string (decl
, v
)
1518 dump_expr (decl
, 1);
1522 return (char *)obstack_base (&scratch_obstack
);
1525 /* A cross between type_as_string and fndecl_as_string.
1526 Only called from substitute_nice_name. */
1529 decl_as_string (decl
, v
)
1535 dump_decl (decl
, v
);
1539 return (char *)obstack_base (&scratch_obstack
);
1542 /* Generate the three forms of printable names for lang_printable_name. */
1545 lang_decl_name (decl
, v
)
1550 return decl_as_string (decl
, 1);
1554 if (v
== 1 && DECL_CONTEXT (decl
)
1555 && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (decl
))) == 't')
1558 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1559 cname
= DECL_CLASS_CONTEXT (decl
);
1561 cname
= DECL_CONTEXT (decl
);
1562 dump_type (cname
, 0);
1563 OB_PUTC2 (':', ':');
1566 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1567 dump_function_name (decl
);
1569 dump_decl (DECL_NAME (decl
), 0);
1573 return (char *)obstack_base (&scratch_obstack
);
1581 if (TREE_CODE (t
) == PARM_DECL
)
1582 return DECL_SOURCE_FILE (DECL_CONTEXT (t
));
1583 else if (TREE_CODE_CLASS (TREE_CODE (t
)) == 't')
1584 return DECL_SOURCE_FILE (TYPE_MAIN_DECL (t
));
1586 return DECL_SOURCE_FILE (t
);
1594 if (TREE_CODE (t
) == PARM_DECL
)
1595 line
= DECL_SOURCE_LINE (DECL_CONTEXT (t
));
1596 if (TREE_CODE (t
) == TYPE_DECL
&& DECL_ARTIFICIAL (t
))
1599 if (TREE_CODE_CLASS (TREE_CODE (t
)) == 't')
1600 line
= DECL_SOURCE_LINE (TYPE_MAIN_DECL (t
));
1602 line
= DECL_SOURCE_LINE (t
);
1611 code_as_string (c
, v
)
1615 return tree_code_name
[c
];
1619 language_as_string (c
, v
)
1628 case lang_cplusplus
:
1632 my_friendly_abort (355);
1637 /* Return the proper printed version of a parameter to a C++ function. */
1640 parm_as_string (p
, v
)
1646 sprintf (digit_buffer
, "%d", p
+1);
1647 return digit_buffer
;
1655 static char buf
[] = "operator ";
1660 strcpy (buf
+ 9, opname_tab
[p
]);
1665 assop_as_string (p
, v
)
1669 static char buf
[] = "operator ";
1674 strcpy (buf
+ 9, assignop_tab
[p
]);
1679 args_as_string (p
, v
)
1686 if (TREE_CODE_CLASS (TREE_CODE (TREE_VALUE (p
))) == 't')
1687 return type_as_string (p
, v
);
1690 for (; p
; p
= TREE_CHAIN (p
))
1692 dump_type (error_type (TREE_VALUE (p
)), v
);
1697 return (char *)obstack_base (&scratch_obstack
);
1707 dump_readonly_or_volatile (p
, before
);
1711 return (char *)obstack_base (&scratch_obstack
);