1 /* Call-backs for C++ error reporting.
2 This code is non-reentrant.
3 Copyright (C) 1993 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 T type_as_string
39 #define _ (cp_printer *) 0
40 cp_printer
* cp_printers
[256] =
42 /*0 1 2 3 4 5 6 7 8 9 A B C D E F */
43 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0x00 */
44 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0x10 */
45 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0x20 */
46 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0x30 */
47 _
, A
, _
, C
, D
, E
, _
, _
, _
, _
, _
, _
, L
, _
, _
, O
, /* 0x40 */
48 P
, _
, _
, _
, T
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0x50 */
49 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0x60 */
50 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0x70 */
61 #define obstack_chunk_alloc xmalloc
62 #define obstack_chunk_free free
64 /* Obstack where we build text strings for overloading, etc. */
65 static struct obstack scratch_obstack
;
66 static char *scratch_firstobj
;
68 # define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
69 # define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
70 # define OB_PUTC2(C1,C2) \
71 (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
72 # define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
73 # define OB_PUTID(ID) \
74 (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \
75 IDENTIFIER_LENGTH (ID)))
76 # define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
77 # define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
78 # define OB_PUTI(CST) do { sprintf (digit_buffer, "%d", (CST)); \
79 OB_PUTCP (digit_buffer); } while (0)
80 # define OB_UNPUT(N) obstack_blank (&scratch_obstack, - (N));
82 # define NEXT_CODE(t) (TREE_CODE (TREE_TYPE (t)))
84 static void dump_type (), dump_decl (), dump_function_decl ();
85 static void dump_expr (), dump_unary_op (), dump_binary_op ();
86 static void dump_aggr_type (), dump_type_prefix (), dump_type_suffix ();
87 static void dump_function_name ();
92 gcc_obstack_init (&scratch_obstack
);
93 scratch_firstobj
= (char *)obstack_alloc (&scratch_obstack
, 0);
96 enum pad
{ none
, before
, after
};
99 dump_readonly_or_volatile (t
, p
)
103 if (TYPE_READONLY (t
) || TYPE_VOLATILE (t
))
105 if (p
== before
) OB_PUTC (' ');
106 if (TYPE_READONLY (t
))
108 if (TYPE_READONLY (t
) && TYPE_VOLATILE (t
))
110 if (TYPE_VOLATILE (t
))
111 OB_PUTS ("volatile");
112 if (p
== after
) OB_PUTC (' ');
116 /* This must be large enough to hold any printed integer or floating-point
118 static char digit_buffer
[128];
120 /* Dump into the obstack a human-readable equivalent of TYPE. */
124 int v
; /* verbose? */
129 if (TYPE_PTRMEMFUNC_P (t
))
132 switch (TREE_CODE (t
))
139 OB_PUTS ("{unknown type}");
143 /* i.e. function taking no arguments */
144 if (t
!= void_list_node
)
146 dump_type (TREE_VALUE (t
), v
);
147 /* Can this happen other than for default arguments? */
148 if (TREE_PURPOSE (t
) && v
)
151 dump_expr (TREE_PURPOSE (t
));
155 if (TREE_CHAIN (t
) != void_list_node
)
158 dump_type (TREE_CHAIN (t
), v
);
161 else OB_PUTS (" ...");
165 case IDENTIFIER_NODE
:
170 dump_type (BINFO_TYPE (t
), v
);
176 if (TYPE_LANG_SPECIFIC (t
)
177 && (IS_SIGNATURE_POINTER (t
) || IS_SIGNATURE_REFERENCE (t
)))
179 if (TYPE_READONLY (t
) | TYPE_VOLATILE (t
))
180 dump_readonly_or_volatile (t
);
181 dump_type (SIGNATURE_TYPE (t
), v
);
182 if (IS_SIGNATURE_POINTER (t
))
188 dump_aggr_type (t
, v
);
196 if (!TREE_UNSIGNED (TYPE_MAIN_VARIANT (t
)) && TREE_UNSIGNED (t
))
197 OB_PUTS ("unsigned ");
198 else if (TREE_UNSIGNED (TYPE_MAIN_VARIANT (t
)) && !TREE_UNSIGNED (t
))
205 dump_readonly_or_volatile (t
, after
);
206 OB_PUTID (TYPE_IDENTIFIER (t
));
209 case TEMPLATE_TYPE_PARM
:
210 OB_PUTID (TYPE_IDENTIFIER (t
));
213 case UNINSTANTIATED_P_TYPE
:
214 OB_PUTID (DECL_NAME (UPT_TEMPLATE (t
)));
218 /* This is not always necessary for pointers and such, but doing this
219 reduces code size. */
227 dump_type_prefix (t
, v
);
228 dump_type_suffix (t
, v
);
232 sorry ("`%s' not supported by dump_type",
233 tree_code_name
[(int) TREE_CODE (t
)]);
241 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
243 else if (TREE_CODE (t
) == UNION_TYPE
)
245 else if (TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_DECLARED_CLASS (t
))
247 else if (TYPE_LANG_SPECIFIC (t
) && IS_SIGNATURE (t
))
253 /* Print out a class declaration, in the form `class foo'. */
255 dump_aggr_type (t
, v
)
257 int v
; /* verbose? */
260 char *variety
= aggr_variety (t
);
262 dump_readonly_or_volatile (t
, after
);
270 name
= TYPE_NAME (t
);
272 if (DECL_CONTEXT (name
))
274 /* FUNCTION_DECL or RECORD_TYPE */
275 dump_decl (DECL_CONTEXT (name
), 0);
279 /* kludge around weird behavior on g++.brendan/line1.C */
280 if (TREE_CODE (name
) != IDENTIFIER_NODE
)
281 name
= DECL_NAME (name
);
283 if (ANON_AGGRNAME_P (name
))
285 OB_PUTS ("{anonymous");
297 /* Dump into the obstack the initial part of the output for a given type.
298 This is necessary when dealing with things like functions returning
301 return type of `int (* fee ())()': pointer -> function -> int. Both
302 pointer (and reference and offset) and function (and member) types must
303 deal with prefix and suffix.
305 Arrays must also do this for DECL nodes, like int a[], and for things like
309 dump_type_prefix (t
, v
)
311 int v
; /* verbosity */
313 if (TYPE_PTRMEMFUNC_P (t
))
315 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
319 switch (TREE_CODE (t
))
323 tree sub
= TREE_TYPE (t
);
325 dump_type_prefix (sub
, v
);
326 /* A tree for a member pointer looks like pointer to offset,
327 so let the OFFSET_TYPE case handle it. */
328 if (TREE_CODE (sub
) != OFFSET_TYPE
)
330 switch (TREE_CODE (sub
))
332 /* We don't want int ( *)() */
342 /* We don't want "char * *" */
343 if (! (TYPE_READONLY (sub
) || TYPE_VOLATILE (sub
)))
345 /* But we do want "char *const *" */
351 dump_readonly_or_volatile (t
, none
);
358 tree sub
= TREE_TYPE (t
);
359 dump_type_prefix (sub
, v
);
361 switch (TREE_CODE (sub
))
368 /* We don't want "char * &" */
369 if (! (TYPE_READONLY (sub
) || TYPE_VOLATILE (sub
)))
371 /* But we do want "char *const &" */
378 dump_readonly_or_volatile (t
, none
);
383 dump_type_prefix (TREE_TYPE (t
), v
);
384 if (TREE_CODE (t
) == OFFSET_TYPE
) /* pmfs deal with this in d_t_p */
387 dump_type (TYPE_OFFSET_BASETYPE (t
), 0);
391 dump_readonly_or_volatile (t
, none
);
394 /* Can only be reached through function pointer -- this would not be
395 correct if FUNCTION_DECLs used it. */
397 dump_type_prefix (TREE_TYPE (t
), v
);
402 dump_type_prefix (TREE_TYPE (t
), v
);
404 dump_aggr_type (TYPE_METHOD_BASETYPE (t
), 0);
409 dump_type_prefix (TREE_TYPE (t
), v
);
414 case IDENTIFIER_NODE
:
419 case TEMPLATE_TYPE_PARM
:
423 case UNINSTANTIATED_P_TYPE
:
431 sorry ("`%s' not supported by dump_type_prefix",
432 tree_code_name
[(int) TREE_CODE (t
)]);
437 dump_type_suffix (t
, v
)
439 int v
; /* verbose? */
441 if (TYPE_PTRMEMFUNC_P (t
))
442 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
444 switch (TREE_CODE (t
))
449 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
451 dump_type_suffix (TREE_TYPE (t
), v
);
454 /* Can only be reached through function pointer */
460 arg
= TYPE_ARG_TYPES (t
);
461 if (TREE_CODE (t
) == METHOD_TYPE
)
462 arg
= TREE_CHAIN (arg
);
469 if (TREE_CODE (t
) == METHOD_TYPE
)
470 dump_readonly_or_volatile
471 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t
))), before
);
472 dump_type_suffix (TREE_TYPE (t
), v
);
479 OB_PUTI (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (t
))) + 1);
481 dump_type_suffix (TREE_TYPE (t
), v
);
486 case IDENTIFIER_NODE
:
491 case TEMPLATE_TYPE_PARM
:
495 case UNINSTANTIATED_P_TYPE
:
502 sorry ("`%s' not supported by dump_type_suffix",
503 tree_code_name
[(int) TREE_CODE (t
)]);
507 /* Return a function declaration which corresponds to the IDENTIFIER_NODE
513 tree n
= lookup_name (t
, 0);
515 if (TREE_CODE (n
) == FUNCTION_DECL
)
517 else if (TREE_CODE (n
) == TREE_LIST
518 && TREE_CODE (TREE_VALUE (n
)) == FUNCTION_DECL
)
519 return TREE_VALUE (n
);
521 my_friendly_abort (66);
525 #ifndef NO_DOLLAR_IN_LABEL
526 # define GLOBAL_THING "_GLOBAL_$"
528 # ifndef NO_DOT_IN_LABEL
529 # define GLOBAL_THING "_GLOBAL_."
531 # define GLOBAL_THING "_GLOBAL__"
535 #define GLOBAL_IORD_P(NODE) \
536 !strncmp(IDENTIFIER_POINTER(NODE),GLOBAL_THING,sizeof(GLOBAL_THING)-1)
542 char *name
= IDENTIFIER_POINTER (t
);
544 OB_PUTS ("(static ");
545 if (name
[sizeof (GLOBAL_THING
) - 1] == 'I')
546 OB_PUTS ("initializers");
547 else if (name
[sizeof (GLOBAL_THING
) - 1] == 'D')
548 OB_PUTS ("destructors");
550 my_friendly_abort (352);
553 OB_PUTCP (input_filename
);
560 int v
; /* verbosity */
565 switch (TREE_CODE (t
))
568 OB_PUTS (" /* decl error */ ");
573 /* Don't say 'typedef class A' */
574 tree type
= TREE_TYPE (t
);
575 if (((IS_AGGR_TYPE (type
) && ! TYPE_PTRMEMFUNC_P (type
))
576 || TREE_CODE (type
) == ENUMERAL_TYPE
)
577 && type
== TYPE_MAIN_VARIANT (type
))
584 OB_PUTS ("typedef ");
589 if (DECL_NAME (t
) && VTABLE_NAME_P (DECL_NAME (t
)))
591 OB_PUTS ("vtable for ");
592 dump_type (DECL_CONTEXT (t
), v
);
595 /* else fall through */
601 dump_type_prefix (TREE_TYPE (t
), v
);
603 dump_readonly_or_volatile (t
, after
);
605 /* DECL_CLASS_CONTEXT isn't being set in some cases. Hmm... */
607 && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (t
))) == 't')
609 dump_type (DECL_CONTEXT (t
), 0);
613 dump_decl (DECL_NAME (t
), v
);
617 dump_type_suffix (TREE_TYPE (t
), v
);
621 OB_PUTID (DECL_NAME (t
));
625 dump_decl (TREE_OPERAND (t
, 0), v
);
627 dump_decl (TREE_OPERAND (t
, 1), v
);
631 /* So that we can do dump_decl in dump_aggr_type and have it work for
632 both class and function scope. */
640 my_friendly_abort (69);
643 /* These special cases are duplicated here so that other functions
644 can feed identifiers to cp_error and get them demangled properly. */
645 case IDENTIFIER_NODE
:
646 if (DESTRUCTOR_NAME_P (t
))
649 dump_decl (DECL_NAME (ident_fndecl (t
)), 0);
651 else if (IDENTIFIER_TYPENAME_P (t
))
653 OB_PUTS ("operator ");
654 /* Not exactly IDENTIFIER_TYPE_VALUE. */
655 dump_type (TREE_TYPE (t
), 0);
658 else if (IDENTIFIER_OPNAME_P (t
))
660 char *name_string
= operator_name_string (t
);
661 OB_PUTS ("operator ");
662 OB_PUTCP (name_string
);
669 if (GLOBAL_IORD_P (DECL_ASSEMBLER_NAME (t
)))
670 dump_global_iord (DECL_ASSEMBLER_NAME (t
));
672 dump_function_decl (t
, v
);
677 tree args
= DECL_TEMPLATE_PARMS (t
);
678 int i
, len
= args
? TREE_VEC_LENGTH (args
) : 0;
679 OB_PUTS ("template <");
680 for (i
= 0; i
< len
; i
++)
682 tree arg
= TREE_VEC_ELT (args
, i
);
683 tree defval
= TREE_PURPOSE (arg
);
684 arg
= TREE_VALUE (arg
);
685 if (TREE_CODE (arg
) == TYPE_DECL
)
688 OB_PUTID (DECL_NAME (arg
));
696 dump_decl (defval
, 1);
705 if (DECL_TEMPLATE_IS_CLASS (t
))
708 OB_PUTID (DECL_NAME (t
));
710 else switch (NEXT_CODE (t
))
714 dump_function_decl (t
, v
);
718 my_friendly_abort (353);
724 OB_PUTID (DECL_NAME (t
));
728 if (NEXT_CODE (t
) == ENUMERAL_TYPE
)
731 dump_expr (DECL_INITIAL (t
), 0);
735 sorry ("`%s' not supported by dump_decl",
736 tree_code_name
[(int) TREE_CODE (t
)]);
740 /* Pretty printing for announce_function. T is the declaration of the
741 function we are interested in seeing. V is non-zero if we should print
742 the type that this function returns. */
745 dump_function_decl (t
, v
)
749 tree name
= DECL_ASSEMBLER_NAME (t
);
750 tree fntype
= TREE_TYPE (t
);
751 tree parmtypes
= TYPE_ARG_TYPES (fntype
);
752 tree cname
= NULL_TREE
;
754 /* Friends have DECL_CLASS_CONTEXT set, but not DECL_CONTEXT. */
755 if (DECL_CONTEXT (t
))
756 cname
= DECL_CLASS_CONTEXT (t
);
757 /* this is for partially instantiated template methods */
758 else if (TREE_CODE (fntype
) == METHOD_TYPE
)
759 cname
= TREE_TYPE (TREE_VALUE (parmtypes
));
765 if (DECL_STATIC_FUNCTION_P (t
))
768 if (! IDENTIFIER_TYPENAME_P (name
)
769 && ! DECL_CONSTRUCTOR_P (t
)
770 && ! DESTRUCTOR_NAME_P (name
))
772 dump_type_prefix (TREE_TYPE (fntype
), 1);
779 dump_type (cname
, 0);
781 if (TREE_CODE (fntype
) == METHOD_TYPE
&& parmtypes
)
782 parmtypes
= TREE_CHAIN (parmtypes
);
783 if (DECL_CONSTRUCTOR_FOR_VBASE_P (t
))
784 /* Skip past "in_charge" identifier. */
785 parmtypes
= TREE_CHAIN (parmtypes
);
788 if (DESTRUCTOR_NAME_P (name
))
789 parmtypes
= TREE_CHAIN (parmtypes
);
791 dump_function_name (t
);
796 dump_type (parmtypes
, v
);
802 if (v
&& ! IDENTIFIER_TYPENAME_P (name
))
803 dump_type_suffix (TREE_TYPE (fntype
), 1);
805 if (TREE_CODE (fntype
) == METHOD_TYPE
)
807 if (IS_SIGNATURE (cname
))
808 /* We look at the type pointed to by the `optr' field of `this.' */
809 dump_readonly_or_volatile
810 (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_VALUE (TYPE_ARG_TYPES (fntype
))))), before
);
812 dump_readonly_or_volatile
813 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype
))), before
);
817 /* Handle the function name for a FUNCTION_DECL node, grokking operators
818 and destructors properly. */
820 dump_function_name (t
)
823 tree name
= DECL_NAME (t
);
825 /* There ought to be a better way to find out whether or not something is
827 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (t
)))
832 else if (IDENTIFIER_TYPENAME_P (name
))
834 /* This cannot use the hack that the operator's return
835 type is stashed off of its name because it may be
836 used for error reporting. In the case of conflicting
837 declarations, both will have the same name, yet
838 the types will be different, hence the TREE_TYPE field
839 of the first name will be clobbered by the second. */
840 OB_PUTS ("operator ");
841 dump_type (TREE_TYPE (TREE_TYPE (t
)), 0);
843 else if (IDENTIFIER_OPNAME_P (name
))
845 char *name_string
= operator_name_string (name
);
846 OB_PUTS ("operator ");
847 OB_PUTCP (name_string
);
894 sprintf (digit_buffer
, "\\%03o", (int) c
);
895 OB_PUTCP (digit_buffer
);
900 /* Print out a list of initializers (subr of dump_expr) */
907 dump_expr (TREE_VALUE (l
), 0);
914 /* Print out an expression */
918 int nop
; /* suppress parens */
920 switch (TREE_CODE (t
))
932 tree type
= TREE_TYPE (t
);
933 my_friendly_assert (type
!= 0, 81);
935 /* If it's an enum, output its tag, rather than its value. */
936 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
938 char *p
= enum_name_string (t
, type
);
941 else if (type
== boolean_type_node
)
943 if (t
== boolean_false_node
)
945 else if (t
== boolean_true_node
)
948 my_friendly_abort (366);
950 else if (type
== char_type_node
)
953 dump_char (TREE_INT_CST_LOW (t
));
956 else if (TREE_INT_CST_HIGH (t
)
957 != (TREE_INT_CST_LOW (t
) >> (HOST_BITS_PER_WIDE_INT
- 1)))
960 if (TREE_INT_CST_HIGH (val
) < 0)
963 val
= build_int_2 (~TREE_INT_CST_LOW (val
),
964 -TREE_INT_CST_HIGH (val
));
966 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
969 static char format
[10]; /* "%x%09999x\0" */
971 sprintf (format
, "%%x%%0%dx", HOST_BITS_PER_INT
/ 4);
972 sprintf (digit_buffer
, format
, TREE_INT_CST_HIGH (val
),
973 TREE_INT_CST_LOW (val
));
974 OB_PUTCP (digit_buffer
);
978 OB_PUTI (TREE_INT_CST_LOW (t
));
983 #ifndef REAL_IS_NOT_DOUBLE
984 sprintf (digit_buffer
, "%g", TREE_REAL_CST (t
));
987 unsigned char *p
= (unsigned char *) &TREE_REAL_CST (t
);
989 strcpy (digit_buffer
, "0x");
990 for (i
= 0; i
< sizeof TREE_REAL_CST (t
); i
++)
991 sprintf (digit_buffer
+ 2 + 2*i
, "%02x", *p
++);
994 OB_PUTCP (digit_buffer
);
999 char *p
= TREE_STRING_POINTER (t
);
1000 int len
= TREE_STRING_LENGTH (t
) - 1;
1004 for (i
= 0; i
< len
; i
++)
1011 dump_binary_op (",", t
);
1016 dump_expr (TREE_OPERAND (t
, 0), 0);
1018 dump_expr (TREE_OPERAND (t
, 1), 0);
1020 dump_expr (TREE_OPERAND (t
, 2), 0);
1025 if (TREE_HAS_CONSTRUCTOR (t
))
1028 dump_type (TREE_TYPE (TREE_TYPE (t
)), 0);
1029 PARM_DECL_EXPR (t
) = 1;
1033 dump_expr (TREE_OPERAND (t
, 0), 0);
1038 OB_PUTID (TYPE_IDENTIFIER (TREE_TYPE (t
)));
1040 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t
, 1)));
1046 tree fn
= TREE_OPERAND (t
, 0);
1047 tree args
= TREE_OPERAND (t
, 1);
1049 if (TREE_CODE (fn
) == ADDR_EXPR
)
1050 fn
= TREE_OPERAND (fn
, 0);
1052 if (NEXT_CODE (fn
) == METHOD_TYPE
)
1054 tree ob
= TREE_VALUE (args
);
1055 if (TREE_CODE (ob
) == ADDR_EXPR
)
1057 dump_expr (TREE_OPERAND (ob
, 0), 0);
1060 else if (TREE_CODE (ob
) != PARM_DECL
1061 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob
)), "this"))
1064 OB_PUTC2 ('-', '>');
1066 args
= TREE_CHAIN (args
);
1070 dump_expr_list (args
);
1075 case WITH_CLEANUP_EXPR
:
1076 /* Note that this only works for G++ cleanups. If somebody
1077 builds a general cleanup, there's no way to represent it. */
1078 dump_expr (TREE_OPERAND (t
, 0), 0);
1082 /* Note that this only works for G++ target exprs. If somebody
1083 builds a general TARGET_EXPR, there's no way to represent that
1084 it initializes anything other that the parameter slot for the
1085 default argument. Note we may have cleared out the first
1086 operand in expand_expr, so don't go killing ourselves. */
1087 if (TREE_OPERAND (t
, 1))
1088 dump_expr (TREE_OPERAND (t
, 1), 0);
1095 case TRUNC_DIV_EXPR
:
1096 case TRUNC_MOD_EXPR
:
1104 case BIT_ANDTC_EXPR
:
1105 case TRUTH_ANDIF_EXPR
:
1106 case TRUTH_ORIF_EXPR
:
1113 dump_binary_op (opname_tab
[(int) TREE_CODE (t
)], t
);
1117 case FLOOR_DIV_EXPR
:
1118 case ROUND_DIV_EXPR
:
1119 dump_binary_op ("/", t
);
1123 case FLOOR_MOD_EXPR
:
1124 case ROUND_MOD_EXPR
:
1125 dump_binary_op ("%", t
);
1130 tree ob
= TREE_OPERAND (t
, 0);
1131 if (TREE_CODE (ob
) == INDIRECT_REF
)
1133 ob
= TREE_OPERAND (ob
, 0);
1134 if (TREE_CODE (ob
) != PARM_DECL
1135 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob
)), "this"))
1138 OB_PUTC2 ('-', '>');
1146 dump_expr (TREE_OPERAND (t
, 1), 1);
1151 dump_expr (TREE_OPERAND (t
, 0), 0);
1153 dump_expr (TREE_OPERAND (t
, 1), 0);
1158 dump_unary_op ("+", t
, nop
);
1162 if (TREE_CODE (TREE_OPERAND (t
, 0)) == FUNCTION_DECL
1163 || TREE_CODE (TREE_OPERAND (t
, 0)) == STRING_CST
)
1164 dump_expr (TREE_OPERAND (t
, 0), 0);
1166 dump_unary_op ("&", t
, nop
);
1170 if (TREE_HAS_CONSTRUCTOR (t
))
1172 t
= TREE_OPERAND (t
, 0);
1173 my_friendly_assert (TREE_CODE (t
) == CALL_EXPR
, 237);
1174 dump_expr (TREE_OPERAND (t
, 0), 0);
1176 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t
, 1)));
1181 if (NEXT_CODE (TREE_OPERAND (t
, 0)) == REFERENCE_TYPE
)
1182 dump_expr (TREE_OPERAND (t
, 0), nop
);
1184 dump_unary_op ("*", t
, nop
);
1190 case TRUTH_NOT_EXPR
:
1191 case PREDECREMENT_EXPR
:
1192 case PREINCREMENT_EXPR
:
1193 dump_unary_op (opname_tab
[(int)TREE_CODE (t
)], t
, nop
);
1196 case POSTDECREMENT_EXPR
:
1197 case POSTINCREMENT_EXPR
:
1199 dump_expr (TREE_OPERAND (t
, 0), 0);
1200 OB_PUTCP (opname_tab
[(int)TREE_CODE (t
)]);
1204 case NON_LVALUE_EXPR
:
1205 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
1206 should be another level of INDIRECT_REF so that I don't have to do
1208 if (NEXT_CODE (t
) == POINTER_TYPE
)
1210 tree next
= TREE_TYPE (TREE_TYPE (t
));
1212 while (TREE_CODE (next
) == POINTER_TYPE
)
1213 next
= TREE_TYPE (next
);
1215 if (TREE_CODE (next
) == FUNCTION_TYPE
)
1217 if (!nop
) OB_PUTC ('(');
1219 dump_expr (TREE_OPERAND (t
, 0), 1);
1220 if (!nop
) OB_PUTC (')');
1225 dump_expr (TREE_OPERAND (t
, 0), 0);
1229 dump_expr (TREE_OPERAND (t
, 0), nop
);
1234 dump_expr_list (CONSTRUCTOR_ELTS (t
), 0);
1240 tree ob
= TREE_OPERAND (t
, 0);
1241 if (TREE_CODE (ob
) == NOP_EXPR
1242 && TREE_OPERAND (ob
, 0) == error_mark_node
1243 && TREE_CODE (TREE_OPERAND (t
, 1)) == FUNCTION_DECL
)
1245 dump_expr (TREE_OPERAND (t
, 1), 0);
1248 sorry ("operand of OFFSET_REF not understood");
1255 if (TREE_VALUE (t
) && TREE_CODE (TREE_VALUE (t
)) == FUNCTION_DECL
)
1257 OB_PUTID (DECL_NAME (TREE_VALUE (t
)));
1260 /* else fall through */
1262 /* This list is incomplete, but should suffice for now.
1263 It is very important that `sorry' does not call
1264 `report_error_function'. That could cause an infinite loop. */
1266 sorry ("`%s' not supported by dump_expr",
1267 tree_code_name
[(int) TREE_CODE (t
)]);
1269 /* fall through to ERROR_MARK... */
1272 OB_PUTCP ("{error}");
1278 dump_binary_op (opstring
, t
)
1283 dump_expr (TREE_OPERAND (t
, 0), 1);
1285 OB_PUTCP (opstring
);
1287 dump_expr (TREE_OPERAND (t
, 1), 1);
1292 dump_unary_op (opstring
, t
, nop
)
1297 if (!nop
) OB_PUTC ('(');
1298 OB_PUTCP (opstring
);
1299 dump_expr (TREE_OPERAND (t
, 0), 1);
1300 if (!nop
) OB_PUTC (')');
1304 fndecl_as_string (cname
, fndecl
, print_ret_type_p
)
1306 int print_ret_type_p
;
1308 return decl_as_string (fndecl
, print_ret_type_p
);
1311 /* Same, but handtype a _TYPE.
1312 Called from convert_to_reference, mangle_class_name_for_template,
1313 build_unary_op, and GNU_xref_decl. */
1315 type_as_string (typ
, v
)
1325 return (char *)obstack_base (&scratch_obstack
);
1329 expr_as_string (decl
, v
)
1335 dump_expr (decl
, 1);
1339 return (char *)obstack_base (&scratch_obstack
);
1342 /* A cross between type_as_string and fndecl_as_string.
1343 Only called from substitute_nice_name. */
1345 decl_as_string (decl
, v
)
1351 dump_decl (decl
, v
);
1355 return (char *)obstack_base (&scratch_obstack
);
1362 if (TREE_CODE (t
) == PARM_DECL
)
1363 return DECL_SOURCE_FILE (DECL_CONTEXT (t
));
1364 else if (TREE_CODE_CLASS (TREE_CODE (t
)) == 't')
1365 return DECL_SOURCE_FILE (TYPE_NAME (t
));
1367 return DECL_SOURCE_FILE (t
);
1375 if (TREE_CODE (t
) == PARM_DECL
)
1376 line
= DECL_SOURCE_LINE (DECL_CONTEXT (t
));
1377 if (TREE_CODE (t
) == TYPE_DECL
&& DECL_ARTIFICIAL (t
))
1380 if (TREE_CODE_CLASS (TREE_CODE (t
)) == 't')
1382 if (IS_AGGR_TYPE (t
))
1383 line
= CLASSTYPE_SOURCE_LINE (t
);
1385 line
= DECL_SOURCE_LINE (TYPE_NAME (t
));
1388 line
= DECL_SOURCE_LINE (t
);
1397 code_as_string (c
, v
)
1401 return tree_code_name
[c
];
1405 language_as_string (c
, v
)
1414 case lang_cplusplus
:
1418 my_friendly_abort (355);
1423 /* Return the proper printed version of a parameter to a C++ function. */
1425 parm_as_string (p
, v
)
1431 sprintf (digit_buffer
, "%d", p
+1);
1432 return digit_buffer
;
1440 static char buf
[] = "operator ";
1445 strcpy (buf
+ 9, opname_tab
[p
]);
1450 args_as_string (p
, v
)
1457 return type_as_string (p
, v
);