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);
745 dump_type (DECL_INITIAL (t
), 0);
747 OB_PUTID (DECL_NAME (t
));
751 sorry ("`%s' not supported by dump_decl",
752 tree_code_name
[(int) TREE_CODE (t
)]);
756 /* Pretty printing for announce_function. T is the declaration of the
757 function we are interested in seeing. V is non-zero if we should print
758 the type that this function returns. */
761 dump_function_decl (t
, v
)
765 tree name
= DECL_ASSEMBLER_NAME (t
);
766 tree fntype
= TREE_TYPE (t
);
767 tree parmtypes
= TYPE_ARG_TYPES (fntype
);
768 tree cname
= NULL_TREE
;
770 /* Friends have DECL_CLASS_CONTEXT set, but not DECL_CONTEXT. */
771 if (DECL_CONTEXT (t
))
772 cname
= DECL_CLASS_CONTEXT (t
);
773 /* this is for partially instantiated template methods */
774 else if (TREE_CODE (fntype
) == METHOD_TYPE
)
775 cname
= TREE_TYPE (TREE_VALUE (parmtypes
));
781 if (DECL_STATIC_FUNCTION_P (t
))
784 if (! IDENTIFIER_TYPENAME_P (name
)
785 && ! DECL_CONSTRUCTOR_P (t
)
786 && ! DESTRUCTOR_NAME_P (name
))
788 dump_type_prefix (TREE_TYPE (fntype
), 1);
795 dump_type (cname
, 0);
797 if (TREE_CODE (fntype
) == METHOD_TYPE
&& parmtypes
)
798 parmtypes
= TREE_CHAIN (parmtypes
);
799 if (DECL_CONSTRUCTOR_FOR_VBASE_P (t
))
800 /* Skip past "in_charge" identifier. */
801 parmtypes
= TREE_CHAIN (parmtypes
);
804 if (DESTRUCTOR_NAME_P (name
) && DECL_LANGUAGE (t
) == lang_cplusplus
)
805 parmtypes
= TREE_CHAIN (parmtypes
);
807 dump_function_name (t
);
812 dump_type (parmtypes
, v
);
818 if (v
&& ! IDENTIFIER_TYPENAME_P (name
))
819 dump_type_suffix (TREE_TYPE (fntype
), 1);
821 if (TREE_CODE (fntype
) == METHOD_TYPE
)
823 if (IS_SIGNATURE (cname
))
824 /* We look at the type pointed to by the `optr' field of `this.' */
825 dump_readonly_or_volatile
826 (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_VALUE (TYPE_ARG_TYPES (fntype
))))), before
);
828 dump_readonly_or_volatile
829 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype
))), before
);
833 /* Handle the function name for a FUNCTION_DECL node, grokking operators
834 and destructors properly. */
836 dump_function_name (t
)
839 tree name
= DECL_NAME (t
);
841 /* There ought to be a better way to find out whether or not something is
843 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (t
))
844 && DECL_LANGUAGE (t
) == lang_cplusplus
)
849 else if (IDENTIFIER_TYPENAME_P (name
))
851 /* This cannot use the hack that the operator's return
852 type is stashed off of its name because it may be
853 used for error reporting. In the case of conflicting
854 declarations, both will have the same name, yet
855 the types will be different, hence the TREE_TYPE field
856 of the first name will be clobbered by the second. */
857 OB_PUTS ("operator ");
858 dump_type (TREE_TYPE (TREE_TYPE (t
)), 0);
860 else if (IDENTIFIER_OPNAME_P (name
))
862 char *name_string
= operator_name_string (name
);
863 OB_PUTS ("operator ");
864 OB_PUTCP (name_string
);
911 sprintf (digit_buffer
, "\\%03o", (int) c
);
912 OB_PUTCP (digit_buffer
);
917 /* Print out a list of initializers (subr of dump_expr) */
924 dump_expr (TREE_VALUE (l
), 0);
931 /* Print out an expression */
935 int nop
; /* suppress parens */
937 switch (TREE_CODE (t
))
949 tree type
= TREE_TYPE (t
);
950 my_friendly_assert (type
!= 0, 81);
952 /* If it's an enum, output its tag, rather than its value. */
953 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
955 char *p
= enum_name_string (t
, type
);
958 else if (type
== boolean_type_node
)
960 if (t
== boolean_false_node
961 || (TREE_INT_CST_LOW (t
) == 0
962 && TREE_INT_CST_HIGH (t
) == 0))
964 else if (t
== boolean_true_node
)
967 else if (type
== char_type_node
)
970 dump_char (TREE_INT_CST_LOW (t
));
973 else if (TREE_INT_CST_HIGH (t
)
974 != (TREE_INT_CST_LOW (t
) >> (HOST_BITS_PER_WIDE_INT
- 1)))
977 if (TREE_INT_CST_HIGH (val
) < 0)
980 val
= build_int_2 (~TREE_INT_CST_LOW (val
),
981 -TREE_INT_CST_HIGH (val
));
983 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
986 static char format
[10]; /* "%x%09999x\0" */
988 sprintf (format
, "%%x%%0%dx", HOST_BITS_PER_INT
/ 4);
989 sprintf (digit_buffer
, format
, TREE_INT_CST_HIGH (val
),
990 TREE_INT_CST_LOW (val
));
991 OB_PUTCP (digit_buffer
);
995 OB_PUTI (TREE_INT_CST_LOW (t
));
1000 #ifndef REAL_IS_NOT_DOUBLE
1001 sprintf (digit_buffer
, "%g", TREE_REAL_CST (t
));
1004 unsigned char *p
= (unsigned char *) &TREE_REAL_CST (t
);
1006 strcpy (digit_buffer
, "0x");
1007 for (i
= 0; i
< sizeof TREE_REAL_CST (t
); i
++)
1008 sprintf (digit_buffer
+ 2 + 2*i
, "%02x", *p
++);
1011 OB_PUTCP (digit_buffer
);
1016 char *p
= TREE_STRING_POINTER (t
);
1017 int len
= TREE_STRING_LENGTH (t
) - 1;
1021 for (i
= 0; i
< len
; i
++)
1028 dump_binary_op (",", t
);
1033 dump_expr (TREE_OPERAND (t
, 0), 0);
1035 dump_expr (TREE_OPERAND (t
, 1), 0);
1037 dump_expr (TREE_OPERAND (t
, 2), 0);
1042 if (TREE_HAS_CONSTRUCTOR (t
))
1045 dump_type (TREE_TYPE (TREE_TYPE (t
)), 0);
1046 PARM_DECL_EXPR (t
) = 1;
1050 dump_expr (TREE_OPERAND (t
, 0), 0);
1055 OB_PUTID (TYPE_IDENTIFIER (TREE_TYPE (t
)));
1057 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t
, 1)));
1063 tree fn
= TREE_OPERAND (t
, 0);
1064 tree args
= TREE_OPERAND (t
, 1);
1066 if (TREE_CODE (fn
) == ADDR_EXPR
)
1067 fn
= TREE_OPERAND (fn
, 0);
1069 if (NEXT_CODE (fn
) == METHOD_TYPE
)
1071 tree ob
= TREE_VALUE (args
);
1072 if (TREE_CODE (ob
) == ADDR_EXPR
)
1074 dump_expr (TREE_OPERAND (ob
, 0), 0);
1077 else if (TREE_CODE (ob
) != PARM_DECL
1078 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob
)), "this"))
1081 OB_PUTC2 ('-', '>');
1083 args
= TREE_CHAIN (args
);
1087 dump_expr_list (args
);
1093 /* Note that this only works for G++ target exprs. If somebody
1094 builds a general TARGET_EXPR, there's no way to represent that
1095 it initializes anything other that the parameter slot for the
1096 default argument. Note we may have cleared out the first
1097 operand in expand_expr, so don't go killing ourselves. */
1098 if (TREE_OPERAND (t
, 1))
1099 dump_expr (TREE_OPERAND (t
, 1), 0);
1106 case TRUNC_DIV_EXPR
:
1107 case TRUNC_MOD_EXPR
:
1115 case BIT_ANDTC_EXPR
:
1116 case TRUTH_ANDIF_EXPR
:
1117 case TRUTH_ORIF_EXPR
:
1124 dump_binary_op (opname_tab
[(int) TREE_CODE (t
)], t
);
1128 case FLOOR_DIV_EXPR
:
1129 case ROUND_DIV_EXPR
:
1130 dump_binary_op ("/", t
);
1134 case FLOOR_MOD_EXPR
:
1135 case ROUND_MOD_EXPR
:
1136 dump_binary_op ("%", t
);
1141 tree ob
= TREE_OPERAND (t
, 0);
1142 if (TREE_CODE (ob
) == INDIRECT_REF
)
1144 ob
= TREE_OPERAND (ob
, 0);
1145 if (TREE_CODE (ob
) != PARM_DECL
1146 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob
)), "this"))
1149 OB_PUTC2 ('-', '>');
1157 dump_expr (TREE_OPERAND (t
, 1), 1);
1162 dump_expr (TREE_OPERAND (t
, 0), 0);
1164 dump_expr (TREE_OPERAND (t
, 1), 0);
1169 dump_unary_op ("+", t
, nop
);
1173 if (TREE_CODE (TREE_OPERAND (t
, 0)) == FUNCTION_DECL
1174 || TREE_CODE (TREE_OPERAND (t
, 0)) == STRING_CST
)
1175 dump_expr (TREE_OPERAND (t
, 0), 0);
1177 dump_unary_op ("&", t
, nop
);
1181 if (TREE_HAS_CONSTRUCTOR (t
))
1183 t
= TREE_OPERAND (t
, 0);
1184 my_friendly_assert (TREE_CODE (t
) == CALL_EXPR
, 237);
1185 dump_expr (TREE_OPERAND (t
, 0), 0);
1187 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t
, 1)));
1192 if (NEXT_CODE (TREE_OPERAND (t
, 0)) == REFERENCE_TYPE
)
1193 dump_expr (TREE_OPERAND (t
, 0), nop
);
1195 dump_unary_op ("*", t
, nop
);
1201 case TRUTH_NOT_EXPR
:
1202 case PREDECREMENT_EXPR
:
1203 case PREINCREMENT_EXPR
:
1204 dump_unary_op (opname_tab
[(int)TREE_CODE (t
)], t
, nop
);
1207 case POSTDECREMENT_EXPR
:
1208 case POSTINCREMENT_EXPR
:
1210 dump_expr (TREE_OPERAND (t
, 0), 0);
1211 OB_PUTCP (opname_tab
[(int)TREE_CODE (t
)]);
1215 case NON_LVALUE_EXPR
:
1216 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
1217 should be another level of INDIRECT_REF so that I don't have to do
1219 if (NEXT_CODE (t
) == POINTER_TYPE
)
1221 tree next
= TREE_TYPE (TREE_TYPE (t
));
1223 while (TREE_CODE (next
) == POINTER_TYPE
)
1224 next
= TREE_TYPE (next
);
1226 if (TREE_CODE (next
) == FUNCTION_TYPE
)
1228 if (!nop
) OB_PUTC ('(');
1230 dump_expr (TREE_OPERAND (t
, 0), 1);
1231 if (!nop
) OB_PUTC (')');
1236 dump_expr (TREE_OPERAND (t
, 0), 0);
1240 dump_expr (TREE_OPERAND (t
, 0), nop
);
1245 dump_expr_list (CONSTRUCTOR_ELTS (t
), 0);
1251 tree ob
= TREE_OPERAND (t
, 0);
1252 if (TREE_CODE (ob
) == NOP_EXPR
1253 && TREE_OPERAND (ob
, 0) == error_mark_node
1254 && TREE_CODE (TREE_OPERAND (t
, 1)) == FUNCTION_DECL
)
1256 dump_expr (TREE_OPERAND (t
, 1), 0);
1259 sorry ("operand of OFFSET_REF not understood");
1266 if (TREE_VALUE (t
) && TREE_CODE (TREE_VALUE (t
)) == FUNCTION_DECL
)
1268 OB_PUTID (DECL_NAME (TREE_VALUE (t
)));
1271 /* else fall through */
1273 /* This list is incomplete, but should suffice for now.
1274 It is very important that `sorry' does not call
1275 `report_error_function'. That could cause an infinite loop. */
1277 sorry ("`%s' not supported by dump_expr",
1278 tree_code_name
[(int) TREE_CODE (t
)]);
1280 /* fall through to ERROR_MARK... */
1283 OB_PUTCP ("{error}");
1289 dump_binary_op (opstring
, t
)
1294 dump_expr (TREE_OPERAND (t
, 0), 1);
1296 OB_PUTCP (opstring
);
1298 dump_expr (TREE_OPERAND (t
, 1), 1);
1303 dump_unary_op (opstring
, t
, nop
)
1308 if (!nop
) OB_PUTC ('(');
1309 OB_PUTCP (opstring
);
1310 dump_expr (TREE_OPERAND (t
, 0), 1);
1311 if (!nop
) OB_PUTC (')');
1315 fndecl_as_string (cname
, fndecl
, print_ret_type_p
)
1317 int print_ret_type_p
;
1319 return decl_as_string (fndecl
, print_ret_type_p
);
1322 /* Same, but handtype a _TYPE.
1323 Called from convert_to_reference, mangle_class_name_for_template,
1324 build_unary_op, and GNU_xref_decl. */
1326 type_as_string (typ
, v
)
1336 return (char *)obstack_base (&scratch_obstack
);
1340 expr_as_string (decl
, v
)
1346 dump_expr (decl
, 1);
1350 return (char *)obstack_base (&scratch_obstack
);
1353 /* A cross between type_as_string and fndecl_as_string.
1354 Only called from substitute_nice_name. */
1356 decl_as_string (decl
, v
)
1362 dump_decl (decl
, v
);
1366 return (char *)obstack_base (&scratch_obstack
);
1373 if (TREE_CODE (t
) == PARM_DECL
)
1374 return DECL_SOURCE_FILE (DECL_CONTEXT (t
));
1375 else if (TREE_CODE_CLASS (TREE_CODE (t
)) == 't')
1376 return DECL_SOURCE_FILE (TYPE_NAME (t
));
1378 return DECL_SOURCE_FILE (t
);
1386 if (TREE_CODE (t
) == PARM_DECL
)
1387 line
= DECL_SOURCE_LINE (DECL_CONTEXT (t
));
1388 if (TREE_CODE (t
) == TYPE_DECL
&& DECL_ARTIFICIAL (t
))
1391 if (TREE_CODE_CLASS (TREE_CODE (t
)) == 't')
1393 if (IS_AGGR_TYPE (t
))
1394 line
= CLASSTYPE_SOURCE_LINE (t
);
1396 line
= DECL_SOURCE_LINE (TYPE_NAME (t
));
1399 line
= DECL_SOURCE_LINE (t
);
1408 code_as_string (c
, v
)
1412 return tree_code_name
[c
];
1416 language_as_string (c
, v
)
1425 case lang_cplusplus
:
1429 my_friendly_abort (355);
1434 /* Return the proper printed version of a parameter to a C++ function. */
1436 parm_as_string (p
, v
)
1442 sprintf (digit_buffer
, "%d", p
+1);
1443 return digit_buffer
;
1451 static char buf
[] = "operator ";
1456 strcpy (buf
+ 9, opname_tab
[p
]);
1461 args_as_string (p
, v
)
1468 return type_as_string (p
, v
);
1478 dump_readonly_or_volatile (p
, before
);
1482 return (char *)obstack_base (&scratch_obstack
);