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. */
28 typedef char* cp_printer ();
30 #define A args_as_string
31 #define C code_as_string
32 #define D decl_as_string
33 #define E expr_as_string
34 #define L language_as_string
35 #define O op_as_string
36 #define P parm_as_string
37 #define Q assop_as_string
38 #define T type_as_string
39 #define V cv_as_string
41 #define _ (cp_printer *) 0
42 cp_printer * cp_printers[256] =
44 /*0 1 2 3 4 5 6 7 8 9 A B C D E F */
45 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x00 */
46 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x10 */
47 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x20 */
48 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x30 */
49 _, A, _, C, D, E, _, _, _, _, _, _, L, _, _, O, /* 0x40 */
50 P, Q, _, _, T, _, V, _, _, _, _, _, _, _, _, _, /* 0x50 */
51 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x60 */
52 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x70 */
65 #define obstack_chunk_alloc xmalloc
66 #define obstack_chunk_free free
68 /* Obstack where we build text strings for overloading, etc. */
69 static struct obstack scratch_obstack;
70 static char *scratch_firstobj;
72 # define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
73 # define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
74 # define OB_PUTC2(C1,C2) \
75 (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
76 # define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
77 # define OB_PUTID(ID) \
78 (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \
79 IDENTIFIER_LENGTH (ID)))
80 # define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
81 # define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
82 # define OB_PUTI(CST) do { sprintf (digit_buffer, "%d", (CST)); \
83 OB_PUTCP (digit_buffer); } while (0)
84 # define OB_UNPUT(N) obstack_blank (&scratch_obstack, - (N));
86 # define NEXT_CODE(t) (TREE_CODE (TREE_TYPE (t)))
88 static void dump_type (), dump_decl (), dump_function_decl ();
89 static void dump_expr (), dump_unary_op (), dump_binary_op ();
90 static void dump_aggr_type (), dump_type_prefix (), dump_type_suffix ();
91 static void dump_function_name ();
96 gcc_obstack_init (&scratch_obstack);
97 scratch_firstobj = (char *)obstack_alloc (&scratch_obstack, 0);
100 enum pad { none, before, after };
103 dump_readonly_or_volatile (t, p)
107 if (TYPE_READONLY (t) || TYPE_VOLATILE (t))
109 if (p == before) OB_PUTC (' ');
110 if (TYPE_READONLY (t))
112 if (TYPE_READONLY (t) && TYPE_VOLATILE (t))
114 if (TYPE_VOLATILE (t))
115 OB_PUTS ("volatile");
116 if (p == after) OB_PUTC (' ');
120 /* This must be large enough to hold any printed integer or floating-point
122 static char digit_buffer[128];
124 /* Dump into the obstack a human-readable equivalent of TYPE. */
129 int v; /* verbose? */
134 if (TYPE_PTRMEMFUNC_P (t))
137 switch (TREE_CODE (t))
144 OB_PUTS ("{unknown type}");
148 /* i.e. function taking no arguments */
149 if (t != void_list_node)
151 dump_type (TREE_VALUE (t), v);
152 /* Can this happen other than for default arguments? */
153 if (TREE_PURPOSE (t) && v)
156 dump_expr (TREE_PURPOSE (t));
160 if (TREE_CHAIN (t) != void_list_node)
163 dump_type (TREE_CHAIN (t), v);
166 else OB_PUTS (" ...");
170 case IDENTIFIER_NODE:
175 dump_type (BINFO_TYPE (t), v);
181 if (TYPE_LANG_SPECIFIC (t)
182 && (IS_SIGNATURE_POINTER (t) || IS_SIGNATURE_REFERENCE (t)))
184 if (TYPE_READONLY (t) | TYPE_VOLATILE (t))
185 dump_readonly_or_volatile (t);
186 dump_type (SIGNATURE_TYPE (t), v);
187 if (IS_SIGNATURE_POINTER (t))
193 dump_aggr_type (t, v);
201 if (!TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)) && TREE_UNSIGNED (t))
202 OB_PUTS ("unsigned ");
203 else if (TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)) && !TREE_UNSIGNED (t))
210 dump_readonly_or_volatile (t, after);
211 OB_PUTID (TYPE_IDENTIFIER (t));
214 case TEMPLATE_TYPE_PARM:
215 if (TYPE_IDENTIFIER (t))
216 OB_PUTID (TYPE_IDENTIFIER (t));
218 OB_PUTS ("{anonymous template type parm}");
221 /* This is not always necessary for pointers and such, but doing this
222 reduces code size. */
230 dump_type_prefix (t, v);
231 dump_type_suffix (t, v);
235 OB_PUTS ("typename ");
236 dump_type (TYPE_CONTEXT (t), 0);
238 OB_PUTID (TYPE_IDENTIFIER (t));
242 sorry ("`%s' not supported by dump_type",
243 tree_code_name[(int) TREE_CODE (t)]);
251 if (TREE_CODE (t) == ENUMERAL_TYPE)
253 else if (TREE_CODE (t) == UNION_TYPE)
255 else if (TYPE_LANG_SPECIFIC (t) && CLASSTYPE_DECLARED_CLASS (t))
257 else if (TYPE_LANG_SPECIFIC (t) && IS_SIGNATURE (t))
263 /* Print out a class declaration, in the form `class foo'. */
266 dump_aggr_type (t, v)
268 int v; /* verbose? */
271 char *variety = aggr_variety (t);
273 dump_readonly_or_volatile (t, after);
281 name = TYPE_NAME (t);
283 if (name && DECL_CONTEXT (name))
285 /* FUNCTION_DECL or RECORD_TYPE */
286 dump_decl (DECL_CONTEXT (name), 0);
290 /* kludge around weird behavior on g++.brendan/line1.C */
291 if (name && TREE_CODE (name) != IDENTIFIER_NODE)
292 name = DECL_NAME (name);
294 if (name == 0 || ANON_AGGRNAME_P (name))
296 OB_PUTS ("{anonymous");
308 /* Dump into the obstack the initial part of the output for a given type.
309 This is necessary when dealing with things like functions returning
312 return type of `int (* fee ())()': pointer -> function -> int. Both
313 pointer (and reference and offset) and function (and member) types must
314 deal with prefix and suffix.
316 Arrays must also do this for DECL nodes, like int a[], and for things like
320 dump_type_prefix (t, v)
322 int v; /* verbosity */
324 if (TYPE_PTRMEMFUNC_P (t))
326 t = TYPE_PTRMEMFUNC_FN_TYPE (t);
330 switch (TREE_CODE (t))
334 tree sub = TREE_TYPE (t);
336 dump_type_prefix (sub, v);
337 /* A tree for a member pointer looks like pointer to offset,
338 so let the OFFSET_TYPE case handle it. */
339 if (TREE_CODE (sub) != OFFSET_TYPE)
341 switch (TREE_CODE (sub))
343 /* We don't want int ( *)() */
353 /* We don't want "char * *" */
354 if (! (TYPE_READONLY (sub) || TYPE_VOLATILE (sub)))
356 /* But we do want "char *const *" */
362 dump_readonly_or_volatile (t, none);
369 tree sub = TREE_TYPE (t);
370 dump_type_prefix (sub, v);
372 switch (TREE_CODE (sub))
379 /* We don't want "char * &" */
380 if (! (TYPE_READONLY (sub) || TYPE_VOLATILE (sub)))
382 /* But we do want "char *const &" */
389 dump_readonly_or_volatile (t, none);
394 dump_type_prefix (TREE_TYPE (t), v);
395 if (TREE_CODE (t) == OFFSET_TYPE) /* pmfs deal with this in d_t_p */
398 dump_type (TYPE_OFFSET_BASETYPE (t), 0);
402 dump_readonly_or_volatile (t, none);
405 /* Can only be reached through function pointer -- this would not be
406 correct if FUNCTION_DECLs used it. */
408 dump_type_prefix (TREE_TYPE (t), v);
413 dump_type_prefix (TREE_TYPE (t), v);
415 dump_aggr_type (TYPE_METHOD_BASETYPE (t), 0);
420 dump_type_prefix (TREE_TYPE (t), v);
425 case IDENTIFIER_NODE:
430 case TEMPLATE_TYPE_PARM:
442 sorry ("`%s' not supported by dump_type_prefix",
443 tree_code_name[(int) TREE_CODE (t)]);
448 dump_type_suffix (t, v)
450 int v; /* verbose? */
452 if (TYPE_PTRMEMFUNC_P (t))
453 t = TYPE_PTRMEMFUNC_FN_TYPE (t);
455 switch (TREE_CODE (t))
460 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
462 dump_type_suffix (TREE_TYPE (t), v);
465 /* Can only be reached through function pointer */
471 arg = TYPE_ARG_TYPES (t);
472 if (TREE_CODE (t) == METHOD_TYPE)
473 arg = TREE_CHAIN (arg);
480 if (TREE_CODE (t) == METHOD_TYPE)
481 dump_readonly_or_volatile
482 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t))), before);
483 dump_type_suffix (TREE_TYPE (t), v);
491 if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (t))) == INTEGER_CST)
492 OB_PUTI (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (t))) + 1);
493 else if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (t))) == MINUS_EXPR)
494 dump_expr (TREE_OPERAND (TYPE_MAX_VALUE (TYPE_DOMAIN (t)), 0), 0);
496 dump_expr (fold (build_binary_op
497 (PLUS_EXPR, TYPE_MAX_VALUE (TYPE_DOMAIN (t)),
498 integer_one_node, 1)), 0);
501 dump_type_suffix (TREE_TYPE (t), v);
506 case IDENTIFIER_NODE:
511 case TEMPLATE_TYPE_PARM:
522 sorry ("`%s' not supported by dump_type_suffix",
523 tree_code_name[(int) TREE_CODE (t)]);
527 /* Return a function declaration which corresponds to the IDENTIFIER_NODE
534 tree n = lookup_name (t, 0);
539 if (TREE_CODE (n) == FUNCTION_DECL)
541 else if (TREE_CODE (n) == TREE_LIST
542 && TREE_CODE (TREE_VALUE (n)) == FUNCTION_DECL)
543 return TREE_VALUE (n);
545 my_friendly_abort (66);
549 #ifndef NO_DOLLAR_IN_LABEL
550 # define GLOBAL_THING "_GLOBAL_$"
552 # ifndef NO_DOT_IN_LABEL
553 # define GLOBAL_THING "_GLOBAL_."
555 # define GLOBAL_THING "_GLOBAL__"
559 #define GLOBAL_IORD_P(NODE) \
560 ! strncmp (IDENTIFIER_POINTER(NODE), GLOBAL_THING, sizeof (GLOBAL_THING) - 1)
566 char *name = IDENTIFIER_POINTER (t);
568 OB_PUTS ("(static ");
569 if (name [sizeof (GLOBAL_THING) - 1] == 'I')
570 OB_PUTS ("initializers");
571 else if (name [sizeof (GLOBAL_THING) - 1] == 'D')
572 OB_PUTS ("destructors");
574 my_friendly_abort (352);
577 OB_PUTCP (input_filename);
584 int v; /* verbosity */
589 switch (TREE_CODE (t))
592 OB_PUTS (" /* decl error */ ");
597 /* Don't say 'typedef class A' */
598 if (DECL_ARTIFICIAL (t))
600 dump_type (TREE_TYPE (t), v);
605 OB_PUTS ("typedef ");
610 if (DECL_NAME (t) && VTABLE_NAME_P (DECL_NAME (t)))
612 OB_PUTS ("vtable for ");
613 dump_type (DECL_CONTEXT (t), v);
616 /* else fall through */
622 dump_type_prefix (TREE_TYPE (t), v);
624 dump_readonly_or_volatile (t, after);
626 /* DECL_CLASS_CONTEXT isn't being set in some cases. Hmm... */
628 && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (t))) == 't')
630 dump_type (DECL_CONTEXT (t), 0);
634 dump_decl (DECL_NAME (t), v);
638 dump_type_suffix (TREE_TYPE (t), v);
642 OB_PUTID (DECL_NAME (t));
646 dump_decl (TREE_OPERAND (t, 0), v);
648 dump_decl (TREE_OPERAND (t, 1), v);
652 /* So that we can do dump_decl in dump_aggr_type and have it work for
653 both class and function scope. */
661 my_friendly_abort (69);
664 /* These special cases are duplicated here so that other functions
665 can feed identifiers to cp_error and get them demangled properly. */
666 case IDENTIFIER_NODE:
668 if (DESTRUCTOR_NAME_P (t)
669 && (f = ident_fndecl (t))
670 && DECL_LANGUAGE (f) == lang_cplusplus)
673 dump_decl (DECL_NAME (f), 0);
675 else if (IDENTIFIER_TYPENAME_P (t))
677 OB_PUTS ("operator ");
678 /* Not exactly IDENTIFIER_TYPE_VALUE. */
679 dump_type (TREE_TYPE (t), 0);
682 else if (IDENTIFIER_OPNAME_P (t))
684 char *name_string = operator_name_string (t);
685 OB_PUTS ("operator ");
686 OB_PUTCP (name_string);
694 if (GLOBAL_IORD_P (DECL_ASSEMBLER_NAME (t)))
695 dump_global_iord (DECL_ASSEMBLER_NAME (t));
697 dump_function_decl (t, v);
702 tree args = DECL_TEMPLATE_PARMS (t);
703 int i, len = args ? TREE_VEC_LENGTH (args) : 0;
704 OB_PUTS ("template <");
705 for (i = 0; i < len; i++)
707 tree arg = TREE_VEC_ELT (args, i);
708 tree defval = TREE_PURPOSE (arg);
709 arg = TREE_VALUE (arg);
710 if (TREE_CODE (arg) == TYPE_DECL)
713 OB_PUTID (DECL_NAME (arg));
721 dump_decl (defval, 1);
730 if (TREE_CODE (DECL_TEMPLATE_RESULT (t)) == TYPE_DECL)
731 dump_type (TREE_TYPE (t), v);
732 else if (TREE_TYPE (t) == NULL_TREE)
733 my_friendly_abort (353);
734 else switch (NEXT_CODE (t))
738 dump_function_decl (t, v);
742 my_friendly_abort (353);
748 OB_PUTID (DECL_NAME (t));
752 if ((TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == ENUMERAL_TYPE)
753 || TREE_CODE (DECL_INITIAL (t)) == TEMPLATE_CONST_PARM)
756 dump_expr (DECL_INITIAL (t), 0);
761 dump_type (DECL_INITIAL (t), 0);
763 OB_PUTID (DECL_NAME (t));
767 sorry ("`%s' not supported by dump_decl",
768 tree_code_name[(int) TREE_CODE (t)]);
772 /* Pretty printing for announce_function. T is the declaration of the
773 function we are interested in seeing. V is non-zero if we should print
774 the type that this function returns. */
777 dump_function_decl (t, v)
781 tree name = DECL_ASSEMBLER_NAME (t);
782 tree fntype = TREE_TYPE (t);
783 tree parmtypes = TYPE_ARG_TYPES (fntype);
784 tree cname = NULL_TREE;
786 /* Friends have DECL_CLASS_CONTEXT set, but not DECL_CONTEXT. */
787 if (DECL_CONTEXT (t))
788 cname = DECL_CLASS_CONTEXT (t);
789 /* this is for partially instantiated template methods */
790 else if (TREE_CODE (fntype) == METHOD_TYPE)
791 cname = TREE_TYPE (TREE_VALUE (parmtypes));
797 if (DECL_STATIC_FUNCTION_P (t))
800 if (! IDENTIFIER_TYPENAME_P (name)
801 && ! DECL_CONSTRUCTOR_P (t)
802 && ! DESTRUCTOR_NAME_P (name))
804 dump_type_prefix (TREE_TYPE (fntype), 1);
811 dump_type (cname, 0);
813 if (TREE_CODE (fntype) == METHOD_TYPE && parmtypes)
814 parmtypes = TREE_CHAIN (parmtypes);
815 if (DECL_CONSTRUCTOR_FOR_VBASE_P (t))
816 /* Skip past "in_charge" identifier. */
817 parmtypes = TREE_CHAIN (parmtypes);
820 if (DESTRUCTOR_NAME_P (name) && DECL_LANGUAGE (t) == lang_cplusplus)
821 parmtypes = TREE_CHAIN (parmtypes);
823 dump_function_name (t);
828 dump_type (parmtypes, v);
834 if (v && ! IDENTIFIER_TYPENAME_P (name))
835 dump_type_suffix (TREE_TYPE (fntype), 1);
837 if (TREE_CODE (fntype) == METHOD_TYPE)
839 if (IS_SIGNATURE (cname))
840 /* We look at the type pointed to by the `optr' field of `this.' */
841 dump_readonly_or_volatile
842 (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_VALUE (TYPE_ARG_TYPES (fntype))))), before);
844 dump_readonly_or_volatile
845 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype))), before);
849 /* Handle the function name for a FUNCTION_DECL node, grokking operators
850 and destructors properly. */
853 dump_function_name (t)
856 tree name = DECL_NAME (t);
858 /* There ought to be a better way to find out whether or not something is
860 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (t))
861 && DECL_LANGUAGE (t) == lang_cplusplus)
866 else if (IDENTIFIER_TYPENAME_P (name))
868 /* This cannot use the hack that the operator's return
869 type is stashed off of its name because it may be
870 used for error reporting. In the case of conflicting
871 declarations, both will have the same name, yet
872 the types will be different, hence the TREE_TYPE field
873 of the first name will be clobbered by the second. */
874 OB_PUTS ("operator ");
875 dump_type (TREE_TYPE (TREE_TYPE (t)), 0);
877 else if (IDENTIFIER_OPNAME_P (name))
879 char *name_string = operator_name_string (name);
880 OB_PUTS ("operator ");
881 OB_PUTCP (name_string);
928 sprintf (digit_buffer, "\\%03o", (int) c);
929 OB_PUTCP (digit_buffer);
934 /* Print out a list of initializers (subr of dump_expr) */
942 dump_expr (TREE_VALUE (l), 0);
949 /* Print out an expression */
954 int nop; /* suppress parens */
956 switch (TREE_CODE (t))
969 tree type = TREE_TYPE (t);
970 my_friendly_assert (type != 0, 81);
972 /* If it's an enum, output its tag, rather than its value. */
973 if (TREE_CODE (type) == ENUMERAL_TYPE)
975 char *p = enum_name_string (t, type);
978 else if (type == boolean_type_node)
980 if (t == boolean_false_node
981 || (TREE_INT_CST_LOW (t) == 0
982 && TREE_INT_CST_HIGH (t) == 0))
984 else if (t == boolean_true_node)
987 else if (type == char_type_node)
990 dump_char (TREE_INT_CST_LOW (t));
993 else if (TREE_INT_CST_HIGH (t)
994 != (TREE_INT_CST_LOW (t) >> (HOST_BITS_PER_WIDE_INT - 1)))
997 if (TREE_INT_CST_HIGH (val) < 0)
1000 val = build_int_2 (~TREE_INT_CST_LOW (val),
1001 -TREE_INT_CST_HIGH (val));
1003 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
1006 static char format[10]; /* "%x%09999x\0" */
1008 sprintf (format, "%%x%%0%dx", HOST_BITS_PER_INT / 4);
1009 sprintf (digit_buffer, format, TREE_INT_CST_HIGH (val),
1010 TREE_INT_CST_LOW (val));
1011 OB_PUTCP (digit_buffer);
1015 OB_PUTI (TREE_INT_CST_LOW (t));
1020 #ifndef REAL_IS_NOT_DOUBLE
1021 sprintf (digit_buffer, "%g", TREE_REAL_CST (t));
1024 unsigned char *p = (unsigned char *) &TREE_REAL_CST (t);
1026 strcpy (digit_buffer, "0x");
1027 for (i = 0; i < sizeof TREE_REAL_CST (t); i++)
1028 sprintf (digit_buffer + 2 + 2*i, "%02x", *p++);
1031 OB_PUTCP (digit_buffer);
1036 char *p = TREE_STRING_POINTER (t);
1037 int len = TREE_STRING_LENGTH (t) - 1;
1041 for (i = 0; i < len; i++)
1048 dump_binary_op (",", t);
1053 dump_expr (TREE_OPERAND (t, 0), 0);
1055 dump_expr (TREE_OPERAND (t, 1), 0);
1057 dump_expr (TREE_OPERAND (t, 2), 0);
1062 if (TREE_HAS_CONSTRUCTOR (t))
1065 dump_type (TREE_TYPE (TREE_TYPE (t)), 0);
1066 PARM_DECL_EXPR (t) = 1;
1070 dump_expr (TREE_OPERAND (t, 0), 0);
1075 OB_PUTID (TYPE_IDENTIFIER (TREE_TYPE (t)));
1077 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)));
1083 tree fn = TREE_OPERAND (t, 0);
1084 tree args = TREE_OPERAND (t, 1);
1086 if (TREE_CODE (fn) == ADDR_EXPR)
1087 fn = TREE_OPERAND (fn, 0);
1089 if (TREE_TYPE (fn) != NULL_TREE && NEXT_CODE (fn) == METHOD_TYPE)
1091 tree ob = TREE_VALUE (args);
1092 if (TREE_CODE (ob) == ADDR_EXPR)
1094 dump_expr (TREE_OPERAND (ob, 0), 0);
1097 else if (TREE_CODE (ob) != PARM_DECL
1098 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
1101 OB_PUTC2 ('-', '>');
1103 args = TREE_CHAIN (args);
1107 dump_expr_list (args);
1113 /* Note that this only works for G++ target exprs. If somebody
1114 builds a general TARGET_EXPR, there's no way to represent that
1115 it initializes anything other that the parameter slot for the
1116 default argument. Note we may have cleared out the first
1117 operand in expand_expr, so don't go killing ourselves. */
1118 if (TREE_OPERAND (t, 1))
1119 dump_expr (TREE_OPERAND (t, 1), 0);
1126 case TRUNC_DIV_EXPR:
1127 case TRUNC_MOD_EXPR:
1135 case BIT_ANDTC_EXPR:
1136 case TRUTH_ANDIF_EXPR:
1137 case TRUTH_ORIF_EXPR:
1144 dump_binary_op (opname_tab[(int) TREE_CODE (t)], t);
1148 case FLOOR_DIV_EXPR:
1149 case ROUND_DIV_EXPR:
1150 dump_binary_op ("/", t);
1154 case FLOOR_MOD_EXPR:
1155 case ROUND_MOD_EXPR:
1156 dump_binary_op ("%", t);
1161 tree ob = TREE_OPERAND (t, 0);
1162 if (TREE_CODE (ob) == INDIRECT_REF)
1164 ob = TREE_OPERAND (ob, 0);
1165 if (TREE_CODE (ob) != PARM_DECL
1166 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
1169 OB_PUTC2 ('-', '>');
1177 dump_expr (TREE_OPERAND (t, 1), 1);
1182 dump_expr (TREE_OPERAND (t, 0), 0);
1184 dump_expr (TREE_OPERAND (t, 1), 0);
1189 dump_unary_op ("+", t, nop);
1193 if (TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
1194 || TREE_CODE (TREE_OPERAND (t, 0)) == STRING_CST)
1195 dump_expr (TREE_OPERAND (t, 0), 0);
1197 dump_unary_op ("&", t, nop);
1201 if (TREE_HAS_CONSTRUCTOR (t))
1203 t = TREE_OPERAND (t, 0);
1204 my_friendly_assert (TREE_CODE (t) == CALL_EXPR, 237);
1205 dump_expr (TREE_OPERAND (t, 0), 0);
1207 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)));
1212 if (TREE_OPERAND (t,0) != NULL_TREE
1213 && NEXT_CODE (TREE_OPERAND (t, 0)) == REFERENCE_TYPE)
1214 dump_expr (TREE_OPERAND (t, 0), nop);
1216 dump_unary_op ("*", t, nop);
1222 case TRUTH_NOT_EXPR:
1223 case PREDECREMENT_EXPR:
1224 case PREINCREMENT_EXPR:
1225 dump_unary_op (opname_tab [(int)TREE_CODE (t)], t, nop);
1228 case POSTDECREMENT_EXPR:
1229 case POSTINCREMENT_EXPR:
1231 dump_expr (TREE_OPERAND (t, 0), 0);
1232 OB_PUTCP (opname_tab[(int)TREE_CODE (t)]);
1236 case NON_LVALUE_EXPR:
1237 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
1238 should be another level of INDIRECT_REF so that I don't have to do
1240 if (TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == POINTER_TYPE)
1242 tree next = TREE_TYPE (TREE_TYPE (t));
1244 while (TREE_CODE (next) == POINTER_TYPE)
1245 next = TREE_TYPE (next);
1247 if (TREE_CODE (next) == FUNCTION_TYPE)
1249 if (!nop) OB_PUTC ('(');
1251 dump_expr (TREE_OPERAND (t, 0), 1);
1252 if (!nop) OB_PUTC (')');
1257 dump_expr (TREE_OPERAND (t, 0), 0);
1261 dump_expr (TREE_OPERAND (t, 0), nop);
1266 dump_expr_list (CONSTRUCTOR_ELTS (t));
1272 tree ob = TREE_OPERAND (t, 0);
1273 if (TREE_CODE (ob) == NOP_EXPR
1274 && TREE_OPERAND (ob, 0) == error_mark_node
1275 && TREE_CODE (TREE_OPERAND (t, 1)) == FUNCTION_DECL)
1277 dump_expr (TREE_OPERAND (t, 1), 0);
1280 dump_expr (TREE_OPERAND (t, 0), 0);
1282 dump_expr (TREE_OPERAND (t, 1), 0);
1287 case TEMPLATE_CONST_PARM:
1289 tree r = TREE_VEC_ELT (TREE_VALUE (current_template_parms),
1290 TEMPLATE_CONST_IDX (t));
1291 dump_decl (TREE_VALUE (r), -1);
1295 case IDENTIFIER_NODE:
1300 dump_type (TREE_OPERAND (t, 0), 0);
1302 dump_expr (TREE_OPERAND (t, 1), 0);
1306 if (TREE_OPERAND (t, 0) == NULL_TREE
1307 || TREE_CHAIN (TREE_OPERAND (t, 0)))
1309 dump_type (TREE_TYPE (t), 0);
1311 dump_expr_list (TREE_OPERAND (t, 0));
1317 dump_type (TREE_TYPE (t), 0);
1320 dump_expr_list (TREE_OPERAND (t, 0));
1326 OB_PUTID (TREE_OPERAND (t, 0));
1330 OB_PUTS ("sizeof (");
1331 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t, 0))) == 't')
1332 dump_type (TREE_OPERAND (t, 0), 0);
1334 dump_unary_op ("*", t, 0);
1339 if (TREE_VALUE (t) && TREE_CODE (TREE_VALUE (t)) == FUNCTION_DECL)
1341 OB_PUTID (DECL_NAME (TREE_VALUE (t)));
1344 /* else fall through */
1346 /* This list is incomplete, but should suffice for now.
1347 It is very important that `sorry' does not call
1348 `report_error_function'. That could cause an infinite loop. */
1350 sorry ("`%s' not supported by dump_expr",
1351 tree_code_name[(int) TREE_CODE (t)]);
1353 /* fall through to ERROR_MARK... */
1356 OB_PUTCP ("{error}");
1362 dump_binary_op (opstring, t)
1367 dump_expr (TREE_OPERAND (t, 0), 1);
1369 OB_PUTCP (opstring);
1371 dump_expr (TREE_OPERAND (t, 1), 1);
1376 dump_unary_op (opstring, t, nop)
1381 if (!nop) OB_PUTC ('(');
1382 OB_PUTCP (opstring);
1383 dump_expr (TREE_OPERAND (t, 0), 1);
1384 if (!nop) OB_PUTC (')');
1388 fndecl_as_string (fndecl, print_ret_type_p)
1390 int print_ret_type_p;
1392 return decl_as_string (fndecl, print_ret_type_p);
1395 /* Same, but handtype a _TYPE.
1396 Called from convert_to_reference, mangle_class_name_for_template,
1397 build_unary_op, and GNU_xref_decl. */
1400 type_as_string (typ, v)
1410 return (char *)obstack_base (&scratch_obstack);
1414 expr_as_string (decl, v)
1420 dump_expr (decl, 1);
1424 return (char *)obstack_base (&scratch_obstack);
1427 /* A cross between type_as_string and fndecl_as_string.
1428 Only called from substitute_nice_name. */
1431 decl_as_string (decl, v)
1437 dump_decl (decl, v);
1441 return (char *)obstack_base (&scratch_obstack);
1448 if (TREE_CODE (t) == PARM_DECL)
1449 return DECL_SOURCE_FILE (DECL_CONTEXT (t));
1450 else if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
1451 return DECL_SOURCE_FILE (TYPE_NAME (t));
1453 return DECL_SOURCE_FILE (t);
1461 if (TREE_CODE (t) == PARM_DECL)
1462 line = DECL_SOURCE_LINE (DECL_CONTEXT (t));
1463 if (TREE_CODE (t) == TYPE_DECL && DECL_ARTIFICIAL (t))
1466 if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
1467 line = DECL_SOURCE_LINE (TYPE_NAME (t));
1469 line = DECL_SOURCE_LINE (t);
1478 code_as_string (c, v)
1482 return tree_code_name [c];
1486 language_as_string (c, v)
1495 case lang_cplusplus:
1499 my_friendly_abort (355);
1504 /* Return the proper printed version of a parameter to a C++ function. */
1507 parm_as_string (p, v)
1513 sprintf (digit_buffer, "%d", p+1);
1514 return digit_buffer;
1522 static char buf[] = "operator ";
1527 strcpy (buf + 9, opname_tab [p]);
1532 assop_as_string (p, v)
1536 static char buf[] = "operator ";
1541 strcpy (buf + 9, assignop_tab [p]);
1546 args_as_string (p, v)
1553 if (TREE_CODE_CLASS (TREE_CODE (TREE_VALUE (p))) == 't')
1554 return type_as_string (p, v);
1557 for (; p; p = TREE_CHAIN (p))
1559 dump_type (error_type (TREE_VALUE (p)), v);
1564 return (char *)obstack_base (&scratch_obstack);
1574 dump_readonly_or_volatile (p, before);
1578 return (char *)obstack_base (&scratch_obstack);