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((int));
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);
779 case TEMPLATE_ID_EXPR:
782 dump_type (TREE_OPERAND (t, 0), v);
784 for (args = TREE_OPERAND (t, 1); args; args = TREE_CHAIN (args))
786 if (TREE_CODE_CLASS (TREE_CODE (TREE_VALUE (args))) == 't')
787 dump_type (TREE_VALUE (args), 0);
789 dump_expr (TREE_VALUE (args), 0);
790 if (TREE_CHAIN (args))
798 OB_PUTID (DECL_NAME (t));
802 if ((TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == ENUMERAL_TYPE)
803 || (DECL_INITIAL (t) &&
804 TREE_CODE (DECL_INITIAL (t)) == TEMPLATE_CONST_PARM))
806 else if (DECL_INITIAL (t))
807 dump_expr (DECL_INITIAL (t), 0);
809 OB_PUTS ("enumerator");
814 dump_type (DECL_INITIAL (t), 0);
816 OB_PUTID (DECL_NAME (t));
820 sorry ("`%s' not supported by dump_decl",
821 tree_code_name[(int) TREE_CODE (t)]);
825 /* Pretty printing for announce_function. T is the declaration of the
826 function we are interested in seeing. V is non-zero if we should print
827 the type that this function returns. */
830 dump_function_decl (t, v)
837 tree cname = NULL_TREE;
839 if (TREE_CODE (t) == TEMPLATE_DECL)
840 t = DECL_TEMPLATE_RESULT (t);
842 name = DECL_ASSEMBLER_NAME (t);
843 fntype = TREE_TYPE (t);
844 parmtypes = TYPE_ARG_TYPES (fntype);
846 /* Friends have DECL_CLASS_CONTEXT set, but not DECL_CONTEXT. */
847 if (DECL_CONTEXT (t))
848 cname = DECL_CLASS_CONTEXT (t);
849 /* this is for partially instantiated template methods */
850 else if (TREE_CODE (fntype) == METHOD_TYPE)
851 cname = TREE_TYPE (TREE_VALUE (parmtypes));
857 if (DECL_STATIC_FUNCTION_P (t))
860 if (! IDENTIFIER_TYPENAME_P (name)
861 && ! DECL_CONSTRUCTOR_P (t)
862 && ! DESTRUCTOR_NAME_P (name))
864 dump_type_prefix (TREE_TYPE (fntype), 1);
871 dump_type (cname, 0);
873 if (TREE_CODE (fntype) == METHOD_TYPE && parmtypes)
874 parmtypes = TREE_CHAIN (parmtypes);
875 if (DECL_CONSTRUCTOR_FOR_VBASE_P (t))
876 /* Skip past "in_charge" identifier. */
877 parmtypes = TREE_CHAIN (parmtypes);
880 if (DESTRUCTOR_NAME_P (name) && DECL_LANGUAGE (t) == lang_cplusplus)
881 parmtypes = TREE_CHAIN (parmtypes);
883 dump_function_name (t);
888 dump_type (parmtypes, v);
894 if (v && ! IDENTIFIER_TYPENAME_P (name))
895 dump_type_suffix (TREE_TYPE (fntype), 1);
897 if (TREE_CODE (fntype) == METHOD_TYPE)
899 if (IS_SIGNATURE (cname))
900 /* We look at the type pointed to by the `optr' field of `this.' */
901 dump_readonly_or_volatile
902 (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_VALUE (TYPE_ARG_TYPES (fntype))))), before);
904 dump_readonly_or_volatile
905 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype))), before);
909 /* Handle the function name for a FUNCTION_DECL node, grokking operators
910 and destructors properly. */
913 dump_function_name (t)
916 tree name = DECL_NAME (t);
918 /* There ought to be a better way to find out whether or not something is
920 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (t))
921 && DECL_LANGUAGE (t) == lang_cplusplus)
926 else if (IDENTIFIER_TYPENAME_P (name))
928 /* This cannot use the hack that the operator's return
929 type is stashed off of its name because it may be
930 used for error reporting. In the case of conflicting
931 declarations, both will have the same name, yet
932 the types will be different, hence the TREE_TYPE field
933 of the first name will be clobbered by the second. */
934 OB_PUTS ("operator ");
935 dump_type (TREE_TYPE (TREE_TYPE (t)), 0);
937 else if (IDENTIFIER_OPNAME_P (name))
939 char *name_string = operator_name_string (name);
940 OB_PUTS ("operator ");
941 OB_PUTCP (name_string);
946 if (DECL_LANG_SPECIFIC (t)
947 && (DECL_TEMPLATE_SPECIALIZATION (t) || DECL_IMPLICIT_INSTANTIATION (t))
948 && (DECL_CLASS_CONTEXT (t) == NULL_TREE || is_member_template (t)))
950 tree args = DECL_TEMPLATE_INFO (t)
951 ? DECL_TI_ARGS (t) : NULL_TREE;
955 /* Be careful only to print things when we have them, so as not
956 to crash producing error messages. */
959 if (TREE_CODE (args) == TREE_LIST)
964 for (arg = args; arg; arg = TREE_CHAIN (arg))
966 tree a = TREE_VALUE (arg);
973 if (TREE_CODE_CLASS (TREE_CODE (a)) == 't')
982 else if (TREE_CODE (args) == TREE_VEC)
987 if (TREE_VEC_LENGTH (args) > 0
988 && TREE_CODE (TREE_VEC_ELT (args, 0)) == TREE_VEC)
989 args = TREE_VEC_ELT (args, 0);
991 for (i = 0; i < TREE_VEC_LENGTH (args); i++)
993 tree a = TREE_VEC_ELT (args, i);
1000 if (TREE_CODE_CLASS (TREE_CODE (a)) == 't')
1020 case TARGET_NEWLINE:
1055 sprintf (digit_buffer, "\\%03o", (int) c);
1056 OB_PUTCP (digit_buffer);
1061 /* Print out a list of initializers (subr of dump_expr) */
1069 dump_expr (TREE_VALUE (l), 0);
1071 OB_PUTC2 (',', ' ');
1076 /* Print out an expression */
1081 int nop; /* suppress parens */
1083 switch (TREE_CODE (t))
1096 tree type = TREE_TYPE (t);
1097 my_friendly_assert (type != 0, 81);
1099 /* If it's an enum, output its tag, rather than its value. */
1100 if (TREE_CODE (type) == ENUMERAL_TYPE)
1102 char *p = enum_name_string (t, type);
1105 else if (type == boolean_type_node)
1107 if (t == boolean_false_node
1108 || (TREE_INT_CST_LOW (t) == 0
1109 && TREE_INT_CST_HIGH (t) == 0))
1111 else if (t == boolean_true_node)
1114 else if (type == char_type_node)
1117 dump_char (TREE_INT_CST_LOW (t));
1120 else if (TREE_INT_CST_HIGH (t)
1121 != (TREE_INT_CST_LOW (t) >> (HOST_BITS_PER_WIDE_INT - 1)))
1124 if (TREE_INT_CST_HIGH (val) < 0)
1127 val = build_int_2 (~TREE_INT_CST_LOW (val),
1128 -TREE_INT_CST_HIGH (val));
1130 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
1133 static char format[10]; /* "%x%09999x\0" */
1135 sprintf (format, "%%x%%0%dx", HOST_BITS_PER_INT / 4);
1136 sprintf (digit_buffer, format, TREE_INT_CST_HIGH (val),
1137 TREE_INT_CST_LOW (val));
1138 OB_PUTCP (digit_buffer);
1142 OB_PUTI (TREE_INT_CST_LOW (t));
1147 #ifndef REAL_IS_NOT_DOUBLE
1148 sprintf (digit_buffer, "%g", TREE_REAL_CST (t));
1151 unsigned char *p = (unsigned char *) &TREE_REAL_CST (t);
1153 strcpy (digit_buffer, "0x");
1154 for (i = 0; i < sizeof TREE_REAL_CST (t); i++)
1155 sprintf (digit_buffer + 2 + 2*i, "%02x", *p++);
1158 OB_PUTCP (digit_buffer);
1163 char *p = TREE_STRING_POINTER (t);
1164 int len = TREE_STRING_LENGTH (t) - 1;
1168 for (i = 0; i < len; i++)
1175 dump_binary_op (",", t);
1180 dump_expr (TREE_OPERAND (t, 0), 0);
1182 dump_expr (TREE_OPERAND (t, 1), 0);
1184 dump_expr (TREE_OPERAND (t, 2), 0);
1189 if (TREE_HAS_CONSTRUCTOR (t))
1192 dump_type (TREE_TYPE (TREE_TYPE (t)), 0);
1193 PARM_DECL_EXPR (t) = 1;
1197 dump_expr (TREE_OPERAND (t, 0), 0);
1202 OB_PUTID (TYPE_IDENTIFIER (TREE_TYPE (t)));
1204 if (TREE_OPERAND (t, 1))
1205 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)));
1211 tree fn = TREE_OPERAND (t, 0);
1212 tree args = TREE_OPERAND (t, 1);
1214 if (TREE_CODE (fn) == ADDR_EXPR)
1215 fn = TREE_OPERAND (fn, 0);
1217 if (TREE_TYPE (fn) != NULL_TREE && NEXT_CODE (fn) == METHOD_TYPE)
1219 tree ob = TREE_VALUE (args);
1220 if (TREE_CODE (ob) == ADDR_EXPR)
1222 dump_expr (TREE_OPERAND (ob, 0), 0);
1225 else if (TREE_CODE (ob) != PARM_DECL
1226 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
1229 OB_PUTC2 ('-', '>');
1231 args = TREE_CHAIN (args);
1235 dump_expr_list (args);
1241 /* Note that this only works for G++ target exprs. If somebody
1242 builds a general TARGET_EXPR, there's no way to represent that
1243 it initializes anything other that the parameter slot for the
1244 default argument. Note we may have cleared out the first
1245 operand in expand_expr, so don't go killing ourselves. */
1246 if (TREE_OPERAND (t, 1))
1247 dump_expr (TREE_OPERAND (t, 1), 0);
1254 case TRUNC_DIV_EXPR:
1255 case TRUNC_MOD_EXPR:
1263 case BIT_ANDTC_EXPR:
1264 case TRUTH_ANDIF_EXPR:
1265 case TRUTH_ORIF_EXPR:
1272 dump_binary_op (opname_tab[(int) TREE_CODE (t)], t);
1276 case FLOOR_DIV_EXPR:
1277 case ROUND_DIV_EXPR:
1278 dump_binary_op ("/", t);
1282 case FLOOR_MOD_EXPR:
1283 case ROUND_MOD_EXPR:
1284 dump_binary_op ("%", t);
1289 tree ob = TREE_OPERAND (t, 0);
1290 if (TREE_CODE (ob) == INDIRECT_REF)
1292 ob = TREE_OPERAND (ob, 0);
1293 if (TREE_CODE (ob) != PARM_DECL
1294 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
1297 OB_PUTC2 ('-', '>');
1305 dump_expr (TREE_OPERAND (t, 1), 1);
1310 dump_expr (TREE_OPERAND (t, 0), 0);
1312 dump_expr (TREE_OPERAND (t, 1), 0);
1317 dump_unary_op ("+", t, nop);
1321 if (TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
1322 || TREE_CODE (TREE_OPERAND (t, 0)) == STRING_CST)
1323 dump_expr (TREE_OPERAND (t, 0), 0);
1325 dump_unary_op ("&", t, nop);
1329 if (TREE_HAS_CONSTRUCTOR (t))
1331 t = TREE_OPERAND (t, 0);
1332 my_friendly_assert (TREE_CODE (t) == CALL_EXPR, 237);
1333 dump_expr (TREE_OPERAND (t, 0), 0);
1335 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)));
1340 if (TREE_OPERAND (t,0) != NULL_TREE
1341 && NEXT_CODE (TREE_OPERAND (t, 0)) == REFERENCE_TYPE)
1342 dump_expr (TREE_OPERAND (t, 0), nop);
1344 dump_unary_op ("*", t, nop);
1350 case TRUTH_NOT_EXPR:
1351 case PREDECREMENT_EXPR:
1352 case PREINCREMENT_EXPR:
1353 dump_unary_op (opname_tab [(int)TREE_CODE (t)], t, nop);
1356 case POSTDECREMENT_EXPR:
1357 case POSTINCREMENT_EXPR:
1359 dump_expr (TREE_OPERAND (t, 0), 0);
1360 OB_PUTCP (opname_tab[(int)TREE_CODE (t)]);
1364 case NON_LVALUE_EXPR:
1365 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
1366 should be another level of INDIRECT_REF so that I don't have to do
1368 if (TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == POINTER_TYPE)
1370 tree next = TREE_TYPE (TREE_TYPE (t));
1372 while (TREE_CODE (next) == POINTER_TYPE)
1373 next = TREE_TYPE (next);
1375 if (TREE_CODE (next) == FUNCTION_TYPE)
1377 if (!nop) OB_PUTC ('(');
1379 dump_expr (TREE_OPERAND (t, 0), 1);
1380 if (!nop) OB_PUTC (')');
1385 dump_expr (TREE_OPERAND (t, 0), 0);
1389 dump_expr (TREE_OPERAND (t, 0), nop);
1393 if (TREE_TYPE (t) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t)))
1395 tree idx = build_component_ref (t, index_identifier, NULL_TREE, 0);
1397 if (integer_all_onesp (idx))
1399 tree pfn = PFN_FROM_PTRMEMFUNC (t);
1403 if (TREE_CODE (idx) == INTEGER_CST
1404 && TREE_INT_CST_HIGH (idx) == 0)
1407 unsigned HOST_WIDE_INT n;
1409 t = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t)));
1410 t = TYPE_METHOD_BASETYPE (t);
1411 virtuals = BINFO_VIRTUALS (TYPE_BINFO (TYPE_MAIN_VARIANT (t)));
1413 n = TREE_INT_CST_LOW (idx);
1415 /* Map vtable index back one, to allow for the null pointer to
1419 while (n > 0 && virtuals)
1422 virtuals = TREE_CHAIN (virtuals);
1426 dump_expr (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals)), 0);
1432 dump_expr_list (CONSTRUCTOR_ELTS (t));
1438 tree ob = TREE_OPERAND (t, 0);
1439 if (TREE_CODE (ob) == NOP_EXPR
1440 && TREE_OPERAND (ob, 0) == error_mark_node
1441 && TREE_CODE (TREE_OPERAND (t, 1)) == FUNCTION_DECL)
1443 dump_expr (TREE_OPERAND (t, 1), 0);
1446 dump_expr (TREE_OPERAND (t, 0), 0);
1448 dump_expr (TREE_OPERAND (t, 1), 0);
1453 case TEMPLATE_CONST_PARM:
1455 int l = current_template_parms ?
1456 list_length (current_template_parms) : 0;
1458 if (l >= TEMPLATE_CONST_LEVEL (t))
1461 tree parms = current_template_parms;
1464 for (i = 0; i < l - TEMPLATE_CONST_LEVEL (t); ++i)
1466 parms = TREE_CHAIN (parms);
1467 my_friendly_assert (parms != NULL_TREE, 0);
1470 r = TREE_VEC_ELT (TREE_VALUE (parms),
1471 TEMPLATE_CONST_IDX (t));
1472 dump_decl (TREE_VALUE (r), -1);
1476 OB_PUTS ("<tparm ");
1477 OB_PUTI (TEMPLATE_CONST_IDX (t));
1483 case IDENTIFIER_NODE:
1488 dump_type (TREE_OPERAND (t, 0), 0);
1490 dump_expr (TREE_OPERAND (t, 1), 0);
1494 if (TREE_OPERAND (t, 0) == NULL_TREE
1495 || TREE_CHAIN (TREE_OPERAND (t, 0)))
1497 dump_type (TREE_TYPE (t), 0);
1499 dump_expr_list (TREE_OPERAND (t, 0));
1505 dump_type (TREE_TYPE (t), 0);
1508 dump_expr_list (TREE_OPERAND (t, 0));
1514 OB_PUTID (TREE_OPERAND (t, 0));
1518 OB_PUTS ("sizeof (");
1519 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t, 0))) == 't')
1520 dump_type (TREE_OPERAND (t, 0), 0);
1522 dump_unary_op ("*", t, 0);
1527 OB_PUTS ("{unparsed}");
1531 if (TREE_VALUE (t) && TREE_CODE (TREE_VALUE (t)) == FUNCTION_DECL)
1533 OB_PUTID (DECL_NAME (TREE_VALUE (t)));
1536 /* else fall through */
1538 /* This list is incomplete, but should suffice for now.
1539 It is very important that `sorry' does not call
1540 `report_error_function'. That could cause an infinite loop. */
1542 sorry ("`%s' not supported by dump_expr",
1543 tree_code_name[(int) TREE_CODE (t)]);
1545 /* fall through to ERROR_MARK... */
1548 OB_PUTCP ("{error}");
1554 dump_binary_op (opstring, t)
1559 dump_expr (TREE_OPERAND (t, 0), 1);
1561 OB_PUTCP (opstring);
1563 dump_expr (TREE_OPERAND (t, 1), 1);
1568 dump_unary_op (opstring, t, nop)
1573 if (!nop) OB_PUTC ('(');
1574 OB_PUTCP (opstring);
1575 dump_expr (TREE_OPERAND (t, 0), 1);
1576 if (!nop) OB_PUTC (')');
1580 fndecl_as_string (fndecl, print_ret_type_p)
1582 int print_ret_type_p;
1584 return decl_as_string (fndecl, print_ret_type_p);
1587 /* Same, but handtype a _TYPE.
1588 Called from convert_to_reference, mangle_class_name_for_template,
1589 build_unary_op, and GNU_xref_decl. */
1592 type_as_string (typ, v)
1602 return (char *)obstack_base (&scratch_obstack);
1606 expr_as_string (decl, v)
1612 dump_expr (decl, 1);
1616 return (char *)obstack_base (&scratch_obstack);
1619 /* A cross between type_as_string and fndecl_as_string.
1620 Only called from substitute_nice_name. */
1623 decl_as_string (decl, v)
1629 dump_decl (decl, v);
1633 return (char *)obstack_base (&scratch_obstack);
1636 /* Generate the three forms of printable names for lang_printable_name. */
1639 lang_decl_name (decl, v)
1644 return decl_as_string (decl, 1);
1648 if (v == 1 && DECL_CONTEXT (decl)
1649 && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (decl))) == 't')
1652 if (TREE_CODE (decl) == FUNCTION_DECL)
1653 cname = DECL_CLASS_CONTEXT (decl);
1655 cname = DECL_CONTEXT (decl);
1656 dump_type (cname, 0);
1657 OB_PUTC2 (':', ':');
1660 if (TREE_CODE (decl) == FUNCTION_DECL)
1661 dump_function_name (decl);
1663 dump_decl (DECL_NAME (decl), 0);
1667 return (char *)obstack_base (&scratch_obstack);
1675 if (TREE_CODE (t) == PARM_DECL)
1676 return DECL_SOURCE_FILE (DECL_CONTEXT (t));
1677 else if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
1678 return DECL_SOURCE_FILE (TYPE_MAIN_DECL (t));
1680 return DECL_SOURCE_FILE (t);
1688 if (TREE_CODE (t) == PARM_DECL)
1689 line = DECL_SOURCE_LINE (DECL_CONTEXT (t));
1690 if (TREE_CODE (t) == TYPE_DECL && DECL_ARTIFICIAL (t))
1693 if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
1694 line = DECL_SOURCE_LINE (TYPE_MAIN_DECL (t));
1696 line = DECL_SOURCE_LINE (t);
1705 code_as_string (c, v)
1709 return tree_code_name [c];
1713 language_as_string (c, v)
1722 case lang_cplusplus:
1726 my_friendly_abort (355);
1731 /* Return the proper printed version of a parameter to a C++ function. */
1734 parm_as_string (p, v)
1740 sprintf (digit_buffer, "%d", p+1);
1741 return digit_buffer;
1749 static char buf[] = "operator ";
1754 strcpy (buf + 9, opname_tab [p]);
1759 assop_as_string (p, v)
1763 static char buf[] = "operator ";
1768 strcpy (buf + 9, assignop_tab [p]);
1773 args_as_string (p, v)
1780 if (TREE_CODE_CLASS (TREE_CODE (TREE_VALUE (p))) == 't')
1781 return type_as_string (p, v);
1784 for (; p; p = TREE_CHAIN (p))
1786 if (TREE_VALUE (p) == null_node)
1789 dump_type (error_type (TREE_VALUE (p)), v);
1794 return (char *)obstack_base (&scratch_obstack);
1804 dump_readonly_or_volatile (p, before);
1808 return (char *)obstack_base (&scratch_obstack);