1 /* Call-backs for C++ error reporting.
2 This code is non-reentrant.
3 Copyright (C) 1993, 1994, 1995 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
38 #define V cv_as_string
40 #define _ (cp_printer *) 0
41 cp_printer
* cp_printers
[256] =
43 /*0 1 2 3 4 5 6 7 8 9 A B C D E F */
44 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0x00 */
45 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0x10 */
46 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0x20 */
47 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0x30 */
48 _
, A
, _
, C
, D
, E
, _
, _
, _
, _
, _
, _
, L
, _
, _
, O
, /* 0x40 */
49 P
, _
, _
, _
, T
, _
, V
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0x50 */
50 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0x60 */
51 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0x70 */
63 #define obstack_chunk_alloc xmalloc
64 #define obstack_chunk_free free
66 /* Obstack where we build text strings for overloading, etc. */
67 static struct obstack scratch_obstack
;
68 static char *scratch_firstobj
;
70 # define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
71 # define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
72 # define OB_PUTC2(C1,C2) \
73 (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
74 # define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
75 # define OB_PUTID(ID) \
76 (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \
77 IDENTIFIER_LENGTH (ID)))
78 # define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
79 # define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
80 # define OB_PUTI(CST) do { sprintf (digit_buffer, "%d", (CST)); \
81 OB_PUTCP (digit_buffer); } while (0)
82 # define OB_UNPUT(N) obstack_blank (&scratch_obstack, - (N));
84 # define NEXT_CODE(t) (TREE_CODE (TREE_TYPE (t)))
86 static void dump_type (), dump_decl (), dump_function_decl ();
87 static void dump_expr (), dump_unary_op (), dump_binary_op ();
88 static void dump_aggr_type (), dump_type_prefix (), dump_type_suffix ();
89 static void dump_function_name ();
94 gcc_obstack_init (&scratch_obstack
);
95 scratch_firstobj
= (char *)obstack_alloc (&scratch_obstack
, 0);
98 enum pad
{ none
, before
, after
};
101 dump_readonly_or_volatile (t
, p
)
105 if (TYPE_READONLY (t
) || TYPE_VOLATILE (t
))
107 if (p
== before
) OB_PUTC (' ');
108 if (TYPE_READONLY (t
))
110 if (TYPE_READONLY (t
) && TYPE_VOLATILE (t
))
112 if (TYPE_VOLATILE (t
))
113 OB_PUTS ("volatile");
114 if (p
== after
) OB_PUTC (' ');
118 /* This must be large enough to hold any printed integer or floating-point
120 static char digit_buffer
[128];
122 /* Dump into the obstack a human-readable equivalent of TYPE. */
126 int v
; /* verbose? */
131 if (TYPE_PTRMEMFUNC_P (t
))
134 switch (TREE_CODE (t
))
141 OB_PUTS ("{unknown type}");
145 /* i.e. function taking no arguments */
146 if (t
!= void_list_node
)
148 dump_type (TREE_VALUE (t
), v
);
149 /* Can this happen other than for default arguments? */
150 if (TREE_PURPOSE (t
) && v
)
153 dump_expr (TREE_PURPOSE (t
));
157 if (TREE_CHAIN (t
) != void_list_node
)
160 dump_type (TREE_CHAIN (t
), v
);
163 else OB_PUTS (" ...");
167 case IDENTIFIER_NODE
:
172 dump_type (BINFO_TYPE (t
), v
);
178 if (TYPE_LANG_SPECIFIC (t
)
179 && (IS_SIGNATURE_POINTER (t
) || IS_SIGNATURE_REFERENCE (t
)))
181 if (TYPE_READONLY (t
) | TYPE_VOLATILE (t
))
182 dump_readonly_or_volatile (t
);
183 dump_type (SIGNATURE_TYPE (t
), v
);
184 if (IS_SIGNATURE_POINTER (t
))
190 dump_aggr_type (t
, v
);
198 if (!TREE_UNSIGNED (TYPE_MAIN_VARIANT (t
)) && TREE_UNSIGNED (t
))
199 OB_PUTS ("unsigned ");
200 else if (TREE_UNSIGNED (TYPE_MAIN_VARIANT (t
)) && !TREE_UNSIGNED (t
))
207 dump_readonly_or_volatile (t
, after
);
208 OB_PUTID (TYPE_IDENTIFIER (t
));
211 case TEMPLATE_TYPE_PARM
:
212 OB_PUTID (TYPE_IDENTIFIER (t
));
215 case UNINSTANTIATED_P_TYPE
:
216 OB_PUTID (DECL_NAME (UPT_TEMPLATE (t
)));
220 /* This is not always necessary for pointers and such, but doing this
221 reduces code size. */
229 dump_type_prefix (t
, v
);
230 dump_type_suffix (t
, v
);
234 sorry ("`%s' not supported by dump_type",
235 tree_code_name
[(int) TREE_CODE (t
)]);
243 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
245 else if (TREE_CODE (t
) == UNION_TYPE
)
247 else if (TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_DECLARED_CLASS (t
))
249 else if (TYPE_LANG_SPECIFIC (t
) && IS_SIGNATURE (t
))
255 /* Print out a class declaration, in the form `class foo'. */
257 dump_aggr_type (t
, v
)
259 int v
; /* verbose? */
262 char *variety
= aggr_variety (t
);
264 dump_readonly_or_volatile (t
, after
);
272 name
= TYPE_NAME (t
);
274 if (name
&& DECL_CONTEXT (name
))
276 /* FUNCTION_DECL or RECORD_TYPE */
277 dump_decl (DECL_CONTEXT (name
), 0);
281 /* kludge around weird behavior on g++.brendan/line1.C */
282 if (name
&& TREE_CODE (name
) != IDENTIFIER_NODE
)
283 name
= DECL_NAME (name
);
285 if (name
== 0 || ANON_AGGRNAME_P (name
))
287 OB_PUTS ("{anonymous");
299 /* Dump into the obstack the initial part of the output for a given type.
300 This is necessary when dealing with things like functions returning
303 return type of `int (* fee ())()': pointer -> function -> int. Both
304 pointer (and reference and offset) and function (and member) types must
305 deal with prefix and suffix.
307 Arrays must also do this for DECL nodes, like int a[], and for things like
311 dump_type_prefix (t
, v
)
313 int v
; /* verbosity */
315 if (TYPE_PTRMEMFUNC_P (t
))
317 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
321 switch (TREE_CODE (t
))
325 tree sub
= TREE_TYPE (t
);
327 dump_type_prefix (sub
, v
);
328 /* A tree for a member pointer looks like pointer to offset,
329 so let the OFFSET_TYPE case handle it. */
330 if (TREE_CODE (sub
) != OFFSET_TYPE
)
332 switch (TREE_CODE (sub
))
334 /* We don't want int ( *)() */
344 /* We don't want "char * *" */
345 if (! (TYPE_READONLY (sub
) || TYPE_VOLATILE (sub
)))
347 /* But we do want "char *const *" */
353 dump_readonly_or_volatile (t
, none
);
360 tree sub
= TREE_TYPE (t
);
361 dump_type_prefix (sub
, v
);
363 switch (TREE_CODE (sub
))
370 /* We don't want "char * &" */
371 if (! (TYPE_READONLY (sub
) || TYPE_VOLATILE (sub
)))
373 /* But we do want "char *const &" */
380 dump_readonly_or_volatile (t
, none
);
385 dump_type_prefix (TREE_TYPE (t
), v
);
386 if (TREE_CODE (t
) == OFFSET_TYPE
) /* pmfs deal with this in d_t_p */
389 dump_type (TYPE_OFFSET_BASETYPE (t
), 0);
393 dump_readonly_or_volatile (t
, none
);
396 /* Can only be reached through function pointer -- this would not be
397 correct if FUNCTION_DECLs used it. */
399 dump_type_prefix (TREE_TYPE (t
), v
);
404 dump_type_prefix (TREE_TYPE (t
), v
);
406 dump_aggr_type (TYPE_METHOD_BASETYPE (t
), 0);
411 dump_type_prefix (TREE_TYPE (t
), v
);
416 case IDENTIFIER_NODE
:
421 case TEMPLATE_TYPE_PARM
:
425 case UNINSTANTIATED_P_TYPE
:
433 sorry ("`%s' not supported by dump_type_prefix",
434 tree_code_name
[(int) TREE_CODE (t
)]);
439 dump_type_suffix (t
, v
)
441 int v
; /* verbose? */
443 if (TYPE_PTRMEMFUNC_P (t
))
444 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
446 switch (TREE_CODE (t
))
451 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
453 dump_type_suffix (TREE_TYPE (t
), v
);
456 /* Can only be reached through function pointer */
462 arg
= TYPE_ARG_TYPES (t
);
463 if (TREE_CODE (t
) == METHOD_TYPE
)
464 arg
= TREE_CHAIN (arg
);
471 if (TREE_CODE (t
) == METHOD_TYPE
)
472 dump_readonly_or_volatile
473 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t
))), before
);
474 dump_type_suffix (TREE_TYPE (t
), v
);
481 OB_PUTI (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (t
))) + 1);
483 dump_type_suffix (TREE_TYPE (t
), v
);
488 case IDENTIFIER_NODE
:
493 case TEMPLATE_TYPE_PARM
:
497 case UNINSTANTIATED_P_TYPE
:
504 sorry ("`%s' not supported by dump_type_suffix",
505 tree_code_name
[(int) TREE_CODE (t
)]);
509 /* Return a function declaration which corresponds to the IDENTIFIER_NODE
515 tree n
= lookup_name (t
, 0);
520 if (TREE_CODE (n
) == FUNCTION_DECL
)
522 else if (TREE_CODE (n
) == TREE_LIST
523 && TREE_CODE (TREE_VALUE (n
)) == FUNCTION_DECL
)
524 return TREE_VALUE (n
);
526 my_friendly_abort (66);
530 #ifndef NO_DOLLAR_IN_LABEL
531 # define GLOBAL_THING "_GLOBAL_$"
533 # ifndef NO_DOT_IN_LABEL
534 # define GLOBAL_THING "_GLOBAL_."
536 # define GLOBAL_THING "_GLOBAL__"
540 #define GLOBAL_IORD_P(NODE) \
541 !strncmp(IDENTIFIER_POINTER(NODE),GLOBAL_THING,sizeof(GLOBAL_THING)-1)
547 char *name
= IDENTIFIER_POINTER (t
);
549 OB_PUTS ("(static ");
550 if (name
[sizeof (GLOBAL_THING
) - 1] == 'I')
551 OB_PUTS ("initializers");
552 else if (name
[sizeof (GLOBAL_THING
) - 1] == 'D')
553 OB_PUTS ("destructors");
555 my_friendly_abort (352);
558 OB_PUTCP (input_filename
);
565 int v
; /* verbosity */
570 switch (TREE_CODE (t
))
573 OB_PUTS (" /* decl error */ ");
578 /* Don't say 'typedef class A' */
579 tree type
= TREE_TYPE (t
);
580 if (((IS_AGGR_TYPE (type
) && ! TYPE_PTRMEMFUNC_P (type
))
581 || TREE_CODE (type
) == ENUMERAL_TYPE
)
582 && type
== TYPE_MAIN_VARIANT (type
))
589 OB_PUTS ("typedef ");
594 if (DECL_NAME (t
) && VTABLE_NAME_P (DECL_NAME (t
)))
596 OB_PUTS ("vtable for ");
597 dump_type (DECL_CONTEXT (t
), v
);
600 /* else fall through */
606 dump_type_prefix (TREE_TYPE (t
), v
);
608 dump_readonly_or_volatile (t
, after
);
610 /* DECL_CLASS_CONTEXT isn't being set in some cases. Hmm... */
612 && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (t
))) == 't')
614 dump_type (DECL_CONTEXT (t
), 0);
618 dump_decl (DECL_NAME (t
), v
);
622 dump_type_suffix (TREE_TYPE (t
), v
);
626 OB_PUTID (DECL_NAME (t
));
630 dump_decl (TREE_OPERAND (t
, 0), v
);
632 dump_decl (TREE_OPERAND (t
, 1), v
);
636 /* So that we can do dump_decl in dump_aggr_type and have it work for
637 both class and function scope. */
645 my_friendly_abort (69);
648 /* These special cases are duplicated here so that other functions
649 can feed identifiers to cp_error and get them demangled properly. */
650 case IDENTIFIER_NODE
:
652 if (DESTRUCTOR_NAME_P (t
)
653 && (f
= ident_fndecl (t
))
654 && DECL_LANGUAGE (f
) == lang_cplusplus
)
657 dump_decl (DECL_NAME (f
), 0);
659 else if (IDENTIFIER_TYPENAME_P (t
))
661 OB_PUTS ("operator ");
662 /* Not exactly IDENTIFIER_TYPE_VALUE. */
663 dump_type (TREE_TYPE (t
), 0);
666 else if (IDENTIFIER_OPNAME_P (t
))
668 char *name_string
= operator_name_string (t
);
669 OB_PUTS ("operator ");
670 OB_PUTCP (name_string
);
678 if (GLOBAL_IORD_P (DECL_ASSEMBLER_NAME (t
)))
679 dump_global_iord (DECL_ASSEMBLER_NAME (t
));
681 dump_function_decl (t
, v
);
686 tree args
= DECL_TEMPLATE_PARMS (t
);
687 int i
, len
= args
? TREE_VEC_LENGTH (args
) : 0;
688 OB_PUTS ("template <");
689 for (i
= 0; i
< len
; i
++)
691 tree arg
= TREE_VEC_ELT (args
, i
);
692 tree defval
= TREE_PURPOSE (arg
);
693 arg
= TREE_VALUE (arg
);
694 if (TREE_CODE (arg
) == TYPE_DECL
)
697 OB_PUTID (DECL_NAME (arg
));
705 dump_decl (defval
, 1);
714 if (DECL_TEMPLATE_IS_CLASS (t
))
717 OB_PUTID (DECL_NAME (t
));
719 else switch (NEXT_CODE (t
))
723 dump_function_decl (t
, v
);
727 my_friendly_abort (353);
733 OB_PUTID (DECL_NAME (t
));
737 if (NEXT_CODE (t
) == ENUMERAL_TYPE
)
740 dump_expr (DECL_INITIAL (t
), 0);
744 sorry ("`%s' not supported by dump_decl",
745 tree_code_name
[(int) TREE_CODE (t
)]);
749 /* Pretty printing for announce_function. T is the declaration of the
750 function we are interested in seeing. V is non-zero if we should print
751 the type that this function returns. */
754 dump_function_decl (t
, v
)
758 tree name
= DECL_ASSEMBLER_NAME (t
);
759 tree fntype
= TREE_TYPE (t
);
760 tree parmtypes
= TYPE_ARG_TYPES (fntype
);
761 tree cname
= NULL_TREE
;
763 /* Friends have DECL_CLASS_CONTEXT set, but not DECL_CONTEXT. */
764 if (DECL_CONTEXT (t
))
765 cname
= DECL_CLASS_CONTEXT (t
);
766 /* this is for partially instantiated template methods */
767 else if (TREE_CODE (fntype
) == METHOD_TYPE
)
768 cname
= TREE_TYPE (TREE_VALUE (parmtypes
));
774 if (DECL_STATIC_FUNCTION_P (t
))
777 if (! IDENTIFIER_TYPENAME_P (name
)
778 && ! DECL_CONSTRUCTOR_P (t
)
779 && ! DESTRUCTOR_NAME_P (name
))
781 dump_type_prefix (TREE_TYPE (fntype
), 1);
788 dump_type (cname
, 0);
790 if (TREE_CODE (fntype
) == METHOD_TYPE
&& parmtypes
)
791 parmtypes
= TREE_CHAIN (parmtypes
);
792 if (DECL_CONSTRUCTOR_FOR_VBASE_P (t
))
793 /* Skip past "in_charge" identifier. */
794 parmtypes
= TREE_CHAIN (parmtypes
);
797 if (DESTRUCTOR_NAME_P (name
) && DECL_LANGUAGE (t
) == lang_cplusplus
)
798 parmtypes
= TREE_CHAIN (parmtypes
);
800 dump_function_name (t
);
805 dump_type (parmtypes
, v
);
811 if (v
&& ! IDENTIFIER_TYPENAME_P (name
))
812 dump_type_suffix (TREE_TYPE (fntype
), 1);
814 if (TREE_CODE (fntype
) == METHOD_TYPE
)
816 if (IS_SIGNATURE (cname
))
817 /* We look at the type pointed to by the `optr' field of `this.' */
818 dump_readonly_or_volatile
819 (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_VALUE (TYPE_ARG_TYPES (fntype
))))), before
);
821 dump_readonly_or_volatile
822 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype
))), before
);
826 /* Handle the function name for a FUNCTION_DECL node, grokking operators
827 and destructors properly. */
829 dump_function_name (t
)
832 tree name
= DECL_NAME (t
);
834 /* There ought to be a better way to find out whether or not something is
836 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (t
))
837 && DECL_LANGUAGE (t
) == lang_cplusplus
)
842 else if (IDENTIFIER_TYPENAME_P (name
))
844 /* This cannot use the hack that the operator's return
845 type is stashed off of its name because it may be
846 used for error reporting. In the case of conflicting
847 declarations, both will have the same name, yet
848 the types will be different, hence the TREE_TYPE field
849 of the first name will be clobbered by the second. */
850 OB_PUTS ("operator ");
851 dump_type (TREE_TYPE (TREE_TYPE (t
)), 0);
853 else if (IDENTIFIER_OPNAME_P (name
))
855 char *name_string
= operator_name_string (name
);
856 OB_PUTS ("operator ");
857 OB_PUTCP (name_string
);
904 sprintf (digit_buffer
, "\\%03o", (int) c
);
905 OB_PUTCP (digit_buffer
);
910 /* Print out a list of initializers (subr of dump_expr) */
917 dump_expr (TREE_VALUE (l
), 0);
924 /* Print out an expression */
928 int nop
; /* suppress parens */
930 switch (TREE_CODE (t
))
942 tree type
= TREE_TYPE (t
);
943 my_friendly_assert (type
!= 0, 81);
945 /* If it's an enum, output its tag, rather than its value. */
946 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
948 char *p
= enum_name_string (t
, type
);
951 else if (type
== boolean_type_node
)
953 if (t
== boolean_false_node
954 || (TREE_INT_CST_LOW (t
) == 0
955 && TREE_INT_CST_HIGH (t
) == 0))
957 else if (t
== boolean_true_node
)
960 else if (type
== char_type_node
)
963 dump_char (TREE_INT_CST_LOW (t
));
966 else if (TREE_INT_CST_HIGH (t
)
967 != (TREE_INT_CST_LOW (t
) >> (HOST_BITS_PER_WIDE_INT
- 1)))
970 if (TREE_INT_CST_HIGH (val
) < 0)
973 val
= build_int_2 (~TREE_INT_CST_LOW (val
),
974 -TREE_INT_CST_HIGH (val
));
976 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
979 static char format
[10]; /* "%x%09999x\0" */
981 sprintf (format
, "%%x%%0%dx", HOST_BITS_PER_INT
/ 4);
982 sprintf (digit_buffer
, format
, TREE_INT_CST_HIGH (val
),
983 TREE_INT_CST_LOW (val
));
984 OB_PUTCP (digit_buffer
);
988 OB_PUTI (TREE_INT_CST_LOW (t
));
993 #ifndef REAL_IS_NOT_DOUBLE
994 sprintf (digit_buffer
, "%g", TREE_REAL_CST (t
));
997 unsigned char *p
= (unsigned char *) &TREE_REAL_CST (t
);
999 strcpy (digit_buffer
, "0x");
1000 for (i
= 0; i
< sizeof TREE_REAL_CST (t
); i
++)
1001 sprintf (digit_buffer
+ 2 + 2*i
, "%02x", *p
++);
1004 OB_PUTCP (digit_buffer
);
1009 char *p
= TREE_STRING_POINTER (t
);
1010 int len
= TREE_STRING_LENGTH (t
) - 1;
1014 for (i
= 0; i
< len
; i
++)
1021 dump_binary_op (",", t
);
1026 dump_expr (TREE_OPERAND (t
, 0), 0);
1028 dump_expr (TREE_OPERAND (t
, 1), 0);
1030 dump_expr (TREE_OPERAND (t
, 2), 0);
1035 if (TREE_HAS_CONSTRUCTOR (t
))
1038 dump_type (TREE_TYPE (TREE_TYPE (t
)), 0);
1039 PARM_DECL_EXPR (t
) = 1;
1043 dump_expr (TREE_OPERAND (t
, 0), 0);
1048 OB_PUTID (TYPE_IDENTIFIER (TREE_TYPE (t
)));
1050 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t
, 1)));
1056 tree fn
= TREE_OPERAND (t
, 0);
1057 tree args
= TREE_OPERAND (t
, 1);
1059 if (TREE_CODE (fn
) == ADDR_EXPR
)
1060 fn
= TREE_OPERAND (fn
, 0);
1062 if (NEXT_CODE (fn
) == METHOD_TYPE
)
1064 tree ob
= TREE_VALUE (args
);
1065 if (TREE_CODE (ob
) == ADDR_EXPR
)
1067 dump_expr (TREE_OPERAND (ob
, 0), 0);
1070 else if (TREE_CODE (ob
) != PARM_DECL
1071 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob
)), "this"))
1074 OB_PUTC2 ('-', '>');
1076 args
= TREE_CHAIN (args
);
1080 dump_expr_list (args
);
1085 case WITH_CLEANUP_EXPR
:
1086 /* Note that this only works for G++ cleanups. If somebody
1087 builds a general cleanup, there's no way to represent it. */
1088 dump_expr (TREE_OPERAND (t
, 0), 0);
1092 /* Note that this only works for G++ target exprs. If somebody
1093 builds a general TARGET_EXPR, there's no way to represent that
1094 it initializes anything other that the parameter slot for the
1095 default argument. Note we may have cleared out the first
1096 operand in expand_expr, so don't go killing ourselves. */
1097 if (TREE_OPERAND (t
, 1))
1098 dump_expr (TREE_OPERAND (t
, 1), 0);
1105 case TRUNC_DIV_EXPR
:
1106 case TRUNC_MOD_EXPR
:
1114 case BIT_ANDTC_EXPR
:
1115 case TRUTH_ANDIF_EXPR
:
1116 case TRUTH_ORIF_EXPR
:
1123 dump_binary_op (opname_tab
[(int) TREE_CODE (t
)], t
);
1127 case FLOOR_DIV_EXPR
:
1128 case ROUND_DIV_EXPR
:
1129 dump_binary_op ("/", t
);
1133 case FLOOR_MOD_EXPR
:
1134 case ROUND_MOD_EXPR
:
1135 dump_binary_op ("%", t
);
1140 tree ob
= TREE_OPERAND (t
, 0);
1141 if (TREE_CODE (ob
) == INDIRECT_REF
)
1143 ob
= TREE_OPERAND (ob
, 0);
1144 if (TREE_CODE (ob
) != PARM_DECL
1145 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob
)), "this"))
1148 OB_PUTC2 ('-', '>');
1156 dump_expr (TREE_OPERAND (t
, 1), 1);
1161 dump_expr (TREE_OPERAND (t
, 0), 0);
1163 dump_expr (TREE_OPERAND (t
, 1), 0);
1168 dump_unary_op ("+", t
, nop
);
1172 if (TREE_CODE (TREE_OPERAND (t
, 0)) == FUNCTION_DECL
1173 || TREE_CODE (TREE_OPERAND (t
, 0)) == STRING_CST
)
1174 dump_expr (TREE_OPERAND (t
, 0), 0);
1176 dump_unary_op ("&", t
, nop
);
1180 if (TREE_HAS_CONSTRUCTOR (t
))
1182 t
= TREE_OPERAND (t
, 0);
1183 my_friendly_assert (TREE_CODE (t
) == CALL_EXPR
, 237);
1184 dump_expr (TREE_OPERAND (t
, 0), 0);
1186 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t
, 1)));
1191 if (NEXT_CODE (TREE_OPERAND (t
, 0)) == REFERENCE_TYPE
)
1192 dump_expr (TREE_OPERAND (t
, 0), nop
);
1194 dump_unary_op ("*", t
, nop
);
1200 case TRUTH_NOT_EXPR
:
1201 case PREDECREMENT_EXPR
:
1202 case PREINCREMENT_EXPR
:
1203 dump_unary_op (opname_tab
[(int)TREE_CODE (t
)], t
, nop
);
1206 case POSTDECREMENT_EXPR
:
1207 case POSTINCREMENT_EXPR
:
1209 dump_expr (TREE_OPERAND (t
, 0), 0);
1210 OB_PUTCP (opname_tab
[(int)TREE_CODE (t
)]);
1214 case NON_LVALUE_EXPR
:
1215 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
1216 should be another level of INDIRECT_REF so that I don't have to do
1218 if (NEXT_CODE (t
) == POINTER_TYPE
)
1220 tree next
= TREE_TYPE (TREE_TYPE (t
));
1222 while (TREE_CODE (next
) == POINTER_TYPE
)
1223 next
= TREE_TYPE (next
);
1225 if (TREE_CODE (next
) == FUNCTION_TYPE
)
1227 if (!nop
) OB_PUTC ('(');
1229 dump_expr (TREE_OPERAND (t
, 0), 1);
1230 if (!nop
) OB_PUTC (')');
1235 dump_expr (TREE_OPERAND (t
, 0), 0);
1239 dump_expr (TREE_OPERAND (t
, 0), nop
);
1244 dump_expr_list (CONSTRUCTOR_ELTS (t
), 0);
1250 tree ob
= TREE_OPERAND (t
, 0);
1251 if (TREE_CODE (ob
) == NOP_EXPR
1252 && TREE_OPERAND (ob
, 0) == error_mark_node
1253 && TREE_CODE (TREE_OPERAND (t
, 1)) == FUNCTION_DECL
)
1255 dump_expr (TREE_OPERAND (t
, 1), 0);
1258 sorry ("operand of OFFSET_REF not understood");
1265 if (TREE_VALUE (t
) && TREE_CODE (TREE_VALUE (t
)) == FUNCTION_DECL
)
1267 OB_PUTID (DECL_NAME (TREE_VALUE (t
)));
1270 /* else fall through */
1272 /* This list is incomplete, but should suffice for now.
1273 It is very important that `sorry' does not call
1274 `report_error_function'. That could cause an infinite loop. */
1276 sorry ("`%s' not supported by dump_expr",
1277 tree_code_name
[(int) TREE_CODE (t
)]);
1279 /* fall through to ERROR_MARK... */
1282 OB_PUTCP ("{error}");
1288 dump_binary_op (opstring
, t
)
1293 dump_expr (TREE_OPERAND (t
, 0), 1);
1295 OB_PUTCP (opstring
);
1297 dump_expr (TREE_OPERAND (t
, 1), 1);
1302 dump_unary_op (opstring
, t
, nop
)
1307 if (!nop
) OB_PUTC ('(');
1308 OB_PUTCP (opstring
);
1309 dump_expr (TREE_OPERAND (t
, 0), 1);
1310 if (!nop
) OB_PUTC (')');
1314 fndecl_as_string (cname
, fndecl
, print_ret_type_p
)
1316 int print_ret_type_p
;
1318 return decl_as_string (fndecl
, print_ret_type_p
);
1321 /* Same, but handtype a _TYPE.
1322 Called from convert_to_reference, mangle_class_name_for_template,
1323 build_unary_op, and GNU_xref_decl. */
1325 type_as_string (typ
, v
)
1335 return (char *)obstack_base (&scratch_obstack
);
1339 expr_as_string (decl
, v
)
1345 dump_expr (decl
, 1);
1349 return (char *)obstack_base (&scratch_obstack
);
1352 /* A cross between type_as_string and fndecl_as_string.
1353 Only called from substitute_nice_name. */
1355 decl_as_string (decl
, v
)
1361 dump_decl (decl
, v
);
1365 return (char *)obstack_base (&scratch_obstack
);
1372 if (TREE_CODE (t
) == PARM_DECL
)
1373 return DECL_SOURCE_FILE (DECL_CONTEXT (t
));
1374 else if (TREE_CODE_CLASS (TREE_CODE (t
)) == 't')
1375 return DECL_SOURCE_FILE (TYPE_NAME (t
));
1377 return DECL_SOURCE_FILE (t
);
1385 if (TREE_CODE (t
) == PARM_DECL
)
1386 line
= DECL_SOURCE_LINE (DECL_CONTEXT (t
));
1387 if (TREE_CODE (t
) == TYPE_DECL
&& DECL_ARTIFICIAL (t
))
1390 if (TREE_CODE_CLASS (TREE_CODE (t
)) == 't')
1392 if (IS_AGGR_TYPE (t
))
1393 line
= CLASSTYPE_SOURCE_LINE (t
);
1395 line
= DECL_SOURCE_LINE (TYPE_NAME (t
));
1398 line
= DECL_SOURCE_LINE (t
);
1407 code_as_string (c
, v
)
1411 return tree_code_name
[c
];
1415 language_as_string (c
, v
)
1424 case lang_cplusplus
:
1428 my_friendly_abort (355);
1433 /* Return the proper printed version of a parameter to a C++ function. */
1435 parm_as_string (p
, v
)
1441 sprintf (digit_buffer
, "%d", p
+1);
1442 return digit_buffer
;
1450 static char buf
[] = "operator ";
1455 strcpy (buf
+ 9, opname_tab
[p
]);
1460 args_as_string (p
, v
)
1467 return type_as_string (p
, v
);
1477 dump_readonly_or_volatile (p
, before
);
1481 return (char *)obstack_base (&scratch_obstack
);