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. */
32 typedef char* cp_printer ();
34 #define A args_as_string
35 #define C code_as_string
36 #define D decl_as_string
37 #define E expr_as_string
38 #define L language_as_string
39 #define O op_as_string
40 #define P parm_as_string
41 #define Q assop_as_string
42 #define T type_as_string
43 #define V cv_as_string
45 #define _ (cp_printer *) 0
46 cp_printer
* cp_printers
[256] =
48 /*0 1 2 3 4 5 6 7 8 9 A B C D E F */
49 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0x00 */
50 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0x10 */
51 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0x20 */
52 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0x30 */
53 _
, A
, _
, C
, D
, E
, _
, _
, _
, _
, _
, _
, L
, _
, _
, O
, /* 0x40 */
54 P
, Q
, _
, _
, T
, _
, V
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0x50 */
55 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0x60 */
56 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0x70 */
69 #define obstack_chunk_alloc xmalloc
70 #define obstack_chunk_free free
72 /* Obstack where we build text strings for overloading, etc. */
73 static struct obstack scratch_obstack
;
74 static char *scratch_firstobj
;
76 # define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
77 # define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
78 # define OB_PUTC2(C1,C2) \
79 (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
80 # define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
81 # define OB_PUTID(ID) \
82 (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \
83 IDENTIFIER_LENGTH (ID)))
84 # define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
85 # define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
86 # define OB_PUTI(CST) do { sprintf (digit_buffer, "%d", (CST)); \
87 OB_PUTCP (digit_buffer); } while (0)
88 # define OB_UNPUT(N) obstack_blank (&scratch_obstack, - (N));
90 # define NEXT_CODE(t) (TREE_CODE (TREE_TYPE (t)))
92 enum pad
{ none
, before
, after
};
94 static void dump_type
PROTO((tree
, int));
95 static void dump_decl
PROTO((tree
, int));
96 static void dump_function_decl
PROTO((tree
, int));
97 static void dump_expr
PROTO((tree
, int));
98 static void dump_unary_op
PROTO((char *, tree
, int));
99 static void dump_binary_op
PROTO((char *, tree
));
100 static void dump_aggr_type
PROTO((tree
, int));
101 static void dump_type_prefix
PROTO((tree
, int));
102 static void dump_type_suffix
PROTO((tree
, int));
103 static void dump_function_name
PROTO((tree
));
104 static void dump_expr_list
PROTO((tree
));
105 static void dump_global_iord
PROTO((tree
));
106 static void dump_readonly_or_volatile
PROTO((tree
, enum pad
));
107 static void dump_char
PROTO((int));
108 static char *aggr_variety
PROTO((tree
));
109 static tree ident_fndecl
PROTO((tree
));
114 gcc_obstack_init (&scratch_obstack
);
115 scratch_firstobj
= (char *)obstack_alloc (&scratch_obstack
, 0);
119 dump_readonly_or_volatile (t
, p
)
123 if (TYPE_READONLY (t
) || TYPE_VOLATILE (t
))
125 if (p
== before
) OB_PUTC (' ');
126 if (TYPE_READONLY (t
))
128 if (TYPE_READONLY (t
) && TYPE_VOLATILE (t
))
130 if (TYPE_VOLATILE (t
))
131 OB_PUTS ("volatile");
132 if (p
== after
) OB_PUTC (' ');
136 /* This must be large enough to hold any printed integer or floating-point
138 static char digit_buffer
[128];
140 /* Dump into the obstack a human-readable equivalent of TYPE. */
145 int v
; /* verbose? */
150 if (TYPE_PTRMEMFUNC_P (t
))
153 switch (TREE_CODE (t
))
160 OB_PUTS ("{unknown type}");
164 /* i.e. function taking no arguments */
165 if (t
!= void_list_node
)
167 dump_type (TREE_VALUE (t
), v
);
168 /* Can this happen other than for default arguments? */
169 if (TREE_PURPOSE (t
) && v
)
172 dump_expr (TREE_PURPOSE (t
), 0);
176 if (TREE_CHAIN (t
) != void_list_node
)
179 dump_type (TREE_CHAIN (t
), v
);
182 else OB_PUTS (" ...");
186 case IDENTIFIER_NODE
:
191 dump_type (BINFO_TYPE (t
), v
);
197 if (TYPE_LANG_SPECIFIC (t
)
198 && (IS_SIGNATURE_POINTER (t
) || IS_SIGNATURE_REFERENCE (t
)))
200 if (TYPE_READONLY (t
) | TYPE_VOLATILE (t
))
201 dump_readonly_or_volatile (t
, after
);
202 dump_type (SIGNATURE_TYPE (t
), v
);
203 if (IS_SIGNATURE_POINTER (t
))
209 dump_aggr_type (t
, v
);
218 OB_PUTS ("complex ");
219 dump_type (TREE_TYPE (t
), v
);
223 if (!TREE_UNSIGNED (TYPE_MAIN_VARIANT (t
)) && TREE_UNSIGNED (t
))
224 OB_PUTS ("unsigned ");
225 else if (TREE_UNSIGNED (TYPE_MAIN_VARIANT (t
)) && !TREE_UNSIGNED (t
))
232 dump_readonly_or_volatile (t
, after
);
233 OB_PUTID (TYPE_IDENTIFIER (t
));
236 case TEMPLATE_TEMPLATE_PARM
:
237 if (!CLASSTYPE_TEMPLATE_INFO (t
))
239 /* For parameters inside template signature. */
240 if (TYPE_IDENTIFIER (t
))
241 OB_PUTID (TYPE_IDENTIFIER (t
));
243 OB_PUTS ("{anonymous template template parm}");
248 tree args
= CLASSTYPE_TI_ARGS (t
);
249 OB_PUTID (TYPE_IDENTIFIER (t
));
251 for (i
= 0; i
< TREE_VEC_LENGTH (args
); i
++)
253 tree arg
= TREE_VEC_ELT (args
, i
);
254 if (TREE_CODE_CLASS (TREE_CODE (arg
)) == 't'
255 || TREE_CODE (arg
) == TEMPLATE_DECL
)
259 if (i
< TREE_VEC_LENGTH (args
)-1)
266 case TEMPLATE_TYPE_PARM
:
267 dump_readonly_or_volatile (t
, after
);
268 if (TYPE_IDENTIFIER (t
))
269 OB_PUTID (TYPE_IDENTIFIER (t
));
271 OB_PUTS ("{anonymous template type parm}");
274 /* This is not always necessary for pointers and such, but doing this
275 reduces code size. */
283 dump_type_prefix (t
, v
);
284 dump_type_suffix (t
, v
);
288 OB_PUTS ("typename ");
289 dump_type (TYPE_CONTEXT (t
), 0);
291 OB_PUTID (TYPE_IDENTIFIER (t
));
295 sorry ("`%s' not supported by dump_type",
296 tree_code_name
[(int) TREE_CODE (t
)]);
304 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
306 else if (TREE_CODE (t
) == UNION_TYPE
)
308 else if (TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_DECLARED_CLASS (t
))
310 else if (TYPE_LANG_SPECIFIC (t
) && IS_SIGNATURE (t
))
316 /* Print out a class declaration, in the form `class foo'. */
319 dump_aggr_type (t
, v
)
321 int v
; /* verbose? */
324 char *variety
= aggr_variety (t
);
326 dump_readonly_or_volatile (t
, after
);
334 name
= TYPE_NAME (t
);
336 if (name
&& DECL_CONTEXT (name
))
338 /* FUNCTION_DECL or RECORD_TYPE */
339 dump_decl (DECL_CONTEXT (name
), 0);
343 /* kludge around weird behavior on g++.brendan/line1.C */
344 if (name
&& TREE_CODE (name
) != IDENTIFIER_NODE
)
345 name
= DECL_NAME (name
);
347 if (name
== 0 || ANON_AGGRNAME_P (name
))
349 OB_PUTS ("{anonymous");
361 /* Dump into the obstack the initial part of the output for a given type.
362 This is necessary when dealing with things like functions returning
365 return type of `int (* fee ())()': pointer -> function -> int. Both
366 pointer (and reference and offset) and function (and member) types must
367 deal with prefix and suffix.
369 Arrays must also do this for DECL nodes, like int a[], and for things like
373 dump_type_prefix (t
, v
)
375 int v
; /* verbosity */
377 if (TYPE_PTRMEMFUNC_P (t
))
379 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
383 switch (TREE_CODE (t
))
387 tree sub
= TREE_TYPE (t
);
389 dump_type_prefix (sub
, v
);
390 /* A tree for a member pointer looks like pointer to offset,
391 so let the OFFSET_TYPE case handle it. */
392 if (TREE_CODE (sub
) != OFFSET_TYPE
)
394 switch (TREE_CODE (sub
))
396 /* We don't want int ( *)() */
406 /* We don't want "char * *" */
407 if (! (TYPE_READONLY (sub
) || TYPE_VOLATILE (sub
)))
409 /* But we do want "char *const *" */
415 dump_readonly_or_volatile (t
, none
);
422 tree sub
= TREE_TYPE (t
);
423 dump_type_prefix (sub
, v
);
425 switch (TREE_CODE (sub
))
432 /* We don't want "char * &" */
433 if (! (TYPE_READONLY (sub
) || TYPE_VOLATILE (sub
)))
435 /* But we do want "char *const &" */
442 dump_readonly_or_volatile (t
, none
);
447 dump_type_prefix (TREE_TYPE (t
), v
);
448 if (TREE_CODE (t
) == OFFSET_TYPE
) /* pmfs deal with this in d_t_p */
451 dump_type (TYPE_OFFSET_BASETYPE (t
), 0);
455 dump_readonly_or_volatile (t
, none
);
458 /* Can only be reached through function pointer -- this would not be
459 correct if FUNCTION_DECLs used it. */
461 dump_type_prefix (TREE_TYPE (t
), v
);
466 dump_type_prefix (TREE_TYPE (t
), v
);
468 dump_aggr_type (TYPE_METHOD_BASETYPE (t
), 0);
473 dump_type_prefix (TREE_TYPE (t
), v
);
478 case IDENTIFIER_NODE
:
483 case TEMPLATE_TYPE_PARM
:
484 case TEMPLATE_TEMPLATE_PARM
:
497 sorry ("`%s' not supported by dump_type_prefix",
498 tree_code_name
[(int) TREE_CODE (t
)]);
503 dump_type_suffix (t
, v
)
505 int v
; /* verbose? */
507 if (TYPE_PTRMEMFUNC_P (t
))
508 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
510 switch (TREE_CODE (t
))
515 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
517 dump_type_suffix (TREE_TYPE (t
), v
);
520 /* Can only be reached through function pointer */
526 arg
= TYPE_ARG_TYPES (t
);
527 if (TREE_CODE (t
) == METHOD_TYPE
)
528 arg
= TREE_CHAIN (arg
);
535 if (TREE_CODE (t
) == METHOD_TYPE
)
536 dump_readonly_or_volatile
537 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t
))), before
);
538 dump_type_suffix (TREE_TYPE (t
), v
);
546 if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (t
))) == INTEGER_CST
)
547 OB_PUTI (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (t
))) + 1);
548 else if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (t
))) == MINUS_EXPR
)
549 dump_expr (TREE_OPERAND (TYPE_MAX_VALUE (TYPE_DOMAIN (t
)), 0), 0);
551 dump_expr (fold (build_binary_op
552 (PLUS_EXPR
, TYPE_MAX_VALUE (TYPE_DOMAIN (t
)),
553 integer_one_node
, 1)), 0);
556 dump_type_suffix (TREE_TYPE (t
), v
);
561 case IDENTIFIER_NODE
:
566 case TEMPLATE_TYPE_PARM
:
567 case TEMPLATE_TEMPLATE_PARM
:
579 sorry ("`%s' not supported by dump_type_suffix",
580 tree_code_name
[(int) TREE_CODE (t
)]);
584 /* Return a function declaration which corresponds to the IDENTIFIER_NODE
591 tree n
= lookup_name (t
, 0);
596 if (TREE_CODE (n
) == FUNCTION_DECL
)
598 else if (TREE_CODE (n
) == TREE_LIST
599 && TREE_CODE (TREE_VALUE (n
)) == FUNCTION_DECL
)
600 return TREE_VALUE (n
);
602 my_friendly_abort (66);
606 #ifndef NO_DOLLAR_IN_LABEL
607 # define GLOBAL_THING "_GLOBAL_$"
609 # ifndef NO_DOT_IN_LABEL
610 # define GLOBAL_THING "_GLOBAL_."
612 # define GLOBAL_THING "_GLOBAL__"
616 #define GLOBAL_IORD_P(NODE) \
617 ! strncmp (IDENTIFIER_POINTER(NODE), GLOBAL_THING, sizeof (GLOBAL_THING) - 1)
623 char *name
= IDENTIFIER_POINTER (t
);
625 OB_PUTS ("(static ");
626 if (name
[sizeof (GLOBAL_THING
) - 1] == 'I')
627 OB_PUTS ("initializers");
628 else if (name
[sizeof (GLOBAL_THING
) - 1] == 'D')
629 OB_PUTS ("destructors");
631 my_friendly_abort (352);
634 OB_PUTCP (input_filename
);
641 int v
; /* verbosity */
646 switch (TREE_CODE (t
))
649 OB_PUTS (" /* decl error */ ");
654 /* Don't say 'typedef class A' */
655 if (DECL_ARTIFICIAL (t
))
657 dump_type (TREE_TYPE (t
), v
);
662 OB_PUTS ("typedef ");
667 if (DECL_NAME (t
) && VTABLE_NAME_P (DECL_NAME (t
)))
669 OB_PUTS ("vtable for ");
670 dump_type (DECL_CONTEXT (t
), v
);
673 /* else fall through */
679 dump_type_prefix (TREE_TYPE (t
), v
);
681 dump_readonly_or_volatile (t
, after
);
683 /* DECL_CLASS_CONTEXT isn't being set in some cases. Hmm... */
685 && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (t
))) == 't')
687 dump_type (DECL_CONTEXT (t
), 0);
691 dump_decl (DECL_NAME (t
), v
);
695 dump_type_suffix (TREE_TYPE (t
), v
);
699 OB_PUTID (DECL_NAME (t
));
703 dump_decl (TREE_OPERAND (t
, 0), v
);
705 dump_decl (TREE_OPERAND (t
, 1), v
);
709 /* So that we can do dump_decl in dump_aggr_type and have it work for
710 both class and function scope. */
718 my_friendly_abort (69);
721 /* These special cases are duplicated here so that other functions
722 can feed identifiers to cp_error and get them demangled properly. */
723 case IDENTIFIER_NODE
:
725 if (DESTRUCTOR_NAME_P (t
)
726 && (f
= ident_fndecl (t
))
727 && DECL_LANGUAGE (f
) == lang_cplusplus
)
730 dump_decl (DECL_NAME (f
), 0);
732 else if (IDENTIFIER_TYPENAME_P (t
))
734 OB_PUTS ("operator ");
735 /* Not exactly IDENTIFIER_TYPE_VALUE. */
736 dump_type (TREE_TYPE (t
), 0);
739 else if (IDENTIFIER_OPNAME_P (t
))
741 char *name_string
= operator_name_string (t
);
742 OB_PUTS ("operator ");
743 OB_PUTCP (name_string
);
751 if (GLOBAL_IORD_P (DECL_ASSEMBLER_NAME (t
)))
752 dump_global_iord (DECL_ASSEMBLER_NAME (t
));
753 else if (! DECL_LANG_SPECIFIC (t
))
754 OB_PUTS ("{internal}");
756 dump_function_decl (t
, v
);
761 tree orig_args
= DECL_TEMPLATE_PARMS (t
);
764 for (args
= orig_args
= nreverse (orig_args
);
766 args
= TREE_CHAIN (args
))
768 int len
= TREE_VEC_LENGTH (TREE_VALUE (args
));
770 OB_PUTS ("template <");
771 for (i
= 0; i
< len
; i
++)
773 tree arg
= TREE_VEC_ELT (TREE_VALUE (args
), i
);
774 tree defval
= TREE_PURPOSE (arg
);
775 arg
= TREE_VALUE (arg
);
776 if (TREE_CODE (arg
) == TYPE_DECL
)
781 OB_PUTID (DECL_NAME (arg
));
792 if (TREE_CODE (arg
) == TYPE_DECL
)
793 dump_type (defval
, 1);
795 dump_decl (defval
, 1);
806 if (TREE_CODE (DECL_TEMPLATE_RESULT (t
)) == TYPE_DECL
)
807 dump_type (TREE_TYPE (t
), v
);
808 else if (TREE_TYPE (t
) == NULL_TREE
)
809 my_friendly_abort (353);
810 else switch (NEXT_CODE (t
))
814 dump_function_decl (t
, v
);
818 /* This case can occur with some illegal code. */
819 dump_type (TREE_TYPE (t
), v
);
824 case TEMPLATE_ID_EXPR
:
827 tree name
= TREE_OPERAND (t
, 0);
828 if (is_overloaded_fn (name
))
829 name
= DECL_NAME (get_first_fn (name
));
832 for (args
= TREE_OPERAND (t
, 1); args
; args
= TREE_CHAIN (args
))
834 if (TREE_CODE_CLASS (TREE_CODE (TREE_VALUE (args
))) == 't'
835 || TREE_CODE (TREE_VALUE (args
)) == TEMPLATE_DECL
)
836 dump_type (TREE_VALUE (args
), 0);
838 dump_expr (TREE_VALUE (args
), 0);
839 if (TREE_CHAIN (args
))
847 OB_PUTID (TREE_OPERAND (t
, 0));
851 OB_PUTID (DECL_NAME (t
));
855 if ((TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == ENUMERAL_TYPE
)
856 || (DECL_INITIAL (t
) &&
857 TREE_CODE (DECL_INITIAL (t
)) == TEMPLATE_CONST_PARM
))
859 else if (DECL_NAME (t
))
860 dump_decl (DECL_NAME (t
), v
);
861 else if (DECL_INITIAL (t
))
862 dump_expr (DECL_INITIAL (t
), 0);
864 OB_PUTS ("enumerator");
869 dump_type (DECL_INITIAL (t
), 0);
871 OB_PUTID (DECL_NAME (t
));
875 sorry ("`%s' not supported by dump_decl",
876 tree_code_name
[(int) TREE_CODE (t
)]);
880 /* Pretty printing for announce_function. T is the declaration of the
881 function we are interested in seeing. V is non-zero if we should print
882 the type that this function returns. */
885 dump_function_decl (t
, v
)
892 tree cname
= NULL_TREE
;
894 if (TREE_CODE (t
) == TEMPLATE_DECL
)
895 t
= DECL_TEMPLATE_RESULT (t
);
897 name
= DECL_ASSEMBLER_NAME (t
);
898 fntype
= TREE_TYPE (t
);
899 parmtypes
= TYPE_ARG_TYPES (fntype
);
901 /* Friends have DECL_CLASS_CONTEXT set, but not DECL_CONTEXT. */
902 if (DECL_CONTEXT (t
))
903 cname
= DECL_CLASS_CONTEXT (t
);
904 /* this is for partially instantiated template methods */
905 else if (TREE_CODE (fntype
) == METHOD_TYPE
)
906 cname
= TREE_TYPE (TREE_VALUE (parmtypes
));
912 if (DECL_STATIC_FUNCTION_P (t
))
915 if (! IDENTIFIER_TYPENAME_P (name
)
916 && ! DECL_CONSTRUCTOR_P (t
)
917 && ! DESTRUCTOR_NAME_P (name
))
919 dump_type_prefix (TREE_TYPE (fntype
), 1);
926 dump_type (cname
, 0);
928 if (TREE_CODE (fntype
) == METHOD_TYPE
&& parmtypes
)
929 parmtypes
= TREE_CHAIN (parmtypes
);
930 if (DECL_CONSTRUCTOR_FOR_VBASE_P (t
))
931 /* Skip past "in_charge" identifier. */
932 parmtypes
= TREE_CHAIN (parmtypes
);
935 if (DESTRUCTOR_NAME_P (name
) && DECL_LANGUAGE (t
) == lang_cplusplus
)
936 parmtypes
= TREE_CHAIN (parmtypes
);
938 dump_function_name (t
);
943 dump_type (parmtypes
, v
);
949 if (v
&& ! IDENTIFIER_TYPENAME_P (name
))
950 dump_type_suffix (TREE_TYPE (fntype
), 1);
952 if (TREE_CODE (fntype
) == METHOD_TYPE
)
954 if (IS_SIGNATURE (cname
))
955 /* We look at the type pointed to by the `optr' field of `this.' */
956 dump_readonly_or_volatile
957 (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_VALUE (TYPE_ARG_TYPES (fntype
))))), before
);
959 dump_readonly_or_volatile
960 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype
))), before
);
964 /* Handle the function name for a FUNCTION_DECL node, grokking operators
965 and destructors properly. */
968 dump_function_name (t
)
971 tree name
= DECL_NAME (t
);
973 /* There ought to be a better way to find out whether or not something is
975 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (t
))
976 && DECL_LANGUAGE (t
) == lang_cplusplus
)
981 else if (IDENTIFIER_TYPENAME_P (name
))
983 /* This cannot use the hack that the operator's return
984 type is stashed off of its name because it may be
985 used for error reporting. In the case of conflicting
986 declarations, both will have the same name, yet
987 the types will be different, hence the TREE_TYPE field
988 of the first name will be clobbered by the second. */
989 OB_PUTS ("operator ");
990 dump_type (TREE_TYPE (TREE_TYPE (t
)), 0);
992 else if (IDENTIFIER_OPNAME_P (name
))
994 char *name_string
= operator_name_string (name
);
995 OB_PUTS ("operator ");
996 OB_PUTCP (name_string
);
1001 if (DECL_LANG_SPECIFIC (t
) && DECL_USE_TEMPLATE (t
))
1003 tree args
= DECL_TEMPLATE_INFO (t
) ? DECL_TI_ARGS (t
) : NULL_TREE
;
1005 if (args
!= NULL_TREE
1006 && DECL_CONTEXT (t
) != NULL_TREE
1007 && uses_template_parms (DECL_CONTEXT (t
))
1008 /* This next clause checks that there is only one level of
1009 template arguments. In that case, they are the
1010 arguments for the class context. */
1011 && (TREE_CODE (args
) == TREE_LIST
1012 || (TREE_CODE (args
) == TREE_VEC
1013 && TREE_VEC_ELT (args
, 0) != NULL_TREE
1014 && TREE_CODE (TREE_VEC_ELT (args
, 0)) != TREE_VEC
)))
1015 /* We have something like this:
1017 template <class T> struct S { void f(); };
1019 and we are printing S<int>::f(). This is a template
1020 instantiation, but we don't print anything after the f. */
1026 /* Be careful only to print things when we have them, so as not
1027 to crash producing error messages. */
1030 if (TREE_CODE (args
) == TREE_LIST
)
1035 for (arg
= args
; arg
; arg
= TREE_CHAIN (arg
))
1037 tree a
= TREE_VALUE (arg
);
1044 if (TREE_CODE_CLASS (TREE_CODE (a
)) == 't'
1045 || TREE_CODE (a
) == TEMPLATE_DECL
)
1054 else if (TREE_CODE (args
) == TREE_VEC
)
1059 if (TREE_VEC_LENGTH (args
) > 0
1060 && TREE_CODE (TREE_VEC_ELT (args
, 0)) == TREE_VEC
)
1061 args
= TREE_VEC_ELT (args
,
1062 TREE_VEC_LENGTH (args
) - 1);
1064 for (i
= 0; i
< TREE_VEC_LENGTH (args
); i
++)
1066 tree a
= TREE_VEC_ELT (args
, i
);
1073 if (TREE_CODE_CLASS (TREE_CODE (a
)) == 't'
1074 || TREE_CODE (a
) == TEMPLATE_DECL
)
1095 case TARGET_NEWLINE
:
1130 sprintf (digit_buffer
, "\\%03o", (int) c
);
1131 OB_PUTCP (digit_buffer
);
1136 /* Print out a list of initializers (subr of dump_expr) */
1144 dump_expr (TREE_VALUE (l
), 0);
1146 OB_PUTC2 (',', ' ');
1151 /* Print out an expression */
1156 int nop
; /* suppress parens */
1158 switch (TREE_CODE (t
))
1171 tree type
= TREE_TYPE (t
);
1172 my_friendly_assert (type
!= 0, 81);
1174 /* If it's an enum, output its tag, rather than its value. */
1175 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1177 char *p
= enum_name_string (t
, type
);
1180 else if (type
== boolean_type_node
)
1182 if (t
== boolean_false_node
1183 || (TREE_INT_CST_LOW (t
) == 0
1184 && TREE_INT_CST_HIGH (t
) == 0))
1186 else if (t
== boolean_true_node
)
1189 else if (type
== char_type_node
)
1192 dump_char (TREE_INT_CST_LOW (t
));
1195 else if (TREE_INT_CST_HIGH (t
)
1196 != (TREE_INT_CST_LOW (t
) >> (HOST_BITS_PER_WIDE_INT
- 1)))
1199 if (TREE_INT_CST_HIGH (val
) < 0)
1202 val
= build_int_2 (~TREE_INT_CST_LOW (val
),
1203 -TREE_INT_CST_HIGH (val
));
1205 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
1208 static char format
[10]; /* "%x%09999x\0" */
1210 sprintf (format
, "%%x%%0%dx", HOST_BITS_PER_INT
/ 4);
1211 sprintf (digit_buffer
, format
, TREE_INT_CST_HIGH (val
),
1212 TREE_INT_CST_LOW (val
));
1213 OB_PUTCP (digit_buffer
);
1217 OB_PUTI (TREE_INT_CST_LOW (t
));
1222 #ifndef REAL_IS_NOT_DOUBLE
1223 sprintf (digit_buffer
, "%g", TREE_REAL_CST (t
));
1226 unsigned char *p
= (unsigned char *) &TREE_REAL_CST (t
);
1228 strcpy (digit_buffer
, "0x");
1229 for (i
= 0; i
< sizeof TREE_REAL_CST (t
); i
++)
1230 sprintf (digit_buffer
+ 2 + 2*i
, "%02x", *p
++);
1233 OB_PUTCP (digit_buffer
);
1238 char *p
= TREE_STRING_POINTER (t
);
1239 int len
= TREE_STRING_LENGTH (t
) - 1;
1243 for (i
= 0; i
< len
; i
++)
1250 dump_binary_op (",", t
);
1255 dump_expr (TREE_OPERAND (t
, 0), 0);
1257 dump_expr (TREE_OPERAND (t
, 1), 0);
1259 dump_expr (TREE_OPERAND (t
, 2), 0);
1264 if (TREE_HAS_CONSTRUCTOR (t
))
1267 dump_type (TREE_TYPE (TREE_TYPE (t
)), 0);
1268 PARM_DECL_EXPR (t
) = 1;
1272 dump_expr (TREE_OPERAND (t
, 0), 0);
1276 case AGGR_INIT_EXPR
:
1277 OB_PUTID (TYPE_IDENTIFIER (TREE_TYPE (t
)));
1279 if (TREE_OPERAND (t
, 1))
1280 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t
, 1)));
1286 tree fn
= TREE_OPERAND (t
, 0);
1287 tree args
= TREE_OPERAND (t
, 1);
1289 if (TREE_CODE (fn
) == ADDR_EXPR
)
1290 fn
= TREE_OPERAND (fn
, 0);
1292 if (TREE_TYPE (fn
) != NULL_TREE
&& NEXT_CODE (fn
) == METHOD_TYPE
)
1294 tree ob
= TREE_VALUE (args
);
1295 if (TREE_CODE (ob
) == ADDR_EXPR
)
1297 dump_expr (TREE_OPERAND (ob
, 0), 0);
1300 else if (TREE_CODE (ob
) != PARM_DECL
1301 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob
)), "this"))
1304 OB_PUTC2 ('-', '>');
1306 args
= TREE_CHAIN (args
);
1310 dump_expr_list (args
);
1316 /* Note that this only works for G++ target exprs. If somebody
1317 builds a general TARGET_EXPR, there's no way to represent that
1318 it initializes anything other that the parameter slot for the
1319 default argument. Note we may have cleared out the first
1320 operand in expand_expr, so don't go killing ourselves. */
1321 if (TREE_OPERAND (t
, 1))
1322 dump_expr (TREE_OPERAND (t
, 1), 0);
1329 case TRUNC_DIV_EXPR
:
1330 case TRUNC_MOD_EXPR
:
1338 case BIT_ANDTC_EXPR
:
1339 case TRUTH_ANDIF_EXPR
:
1340 case TRUTH_ORIF_EXPR
:
1347 dump_binary_op (opname_tab
[(int) TREE_CODE (t
)], t
);
1351 case FLOOR_DIV_EXPR
:
1352 case ROUND_DIV_EXPR
:
1353 dump_binary_op ("/", t
);
1357 case FLOOR_MOD_EXPR
:
1358 case ROUND_MOD_EXPR
:
1359 dump_binary_op ("%", t
);
1364 tree ob
= TREE_OPERAND (t
, 0);
1365 if (TREE_CODE (ob
) == INDIRECT_REF
)
1367 ob
= TREE_OPERAND (ob
, 0);
1368 if (TREE_CODE (ob
) != PARM_DECL
1369 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob
)), "this"))
1372 OB_PUTC2 ('-', '>');
1380 dump_expr (TREE_OPERAND (t
, 1), 1);
1385 dump_expr (TREE_OPERAND (t
, 0), 0);
1387 dump_expr (TREE_OPERAND (t
, 1), 0);
1392 dump_unary_op ("+", t
, nop
);
1396 if (TREE_CODE (TREE_OPERAND (t
, 0)) == FUNCTION_DECL
1397 || TREE_CODE (TREE_OPERAND (t
, 0)) == STRING_CST
)
1398 dump_expr (TREE_OPERAND (t
, 0), 0);
1400 dump_unary_op ("&", t
, nop
);
1404 if (TREE_HAS_CONSTRUCTOR (t
))
1406 t
= TREE_OPERAND (t
, 0);
1407 my_friendly_assert (TREE_CODE (t
) == CALL_EXPR
, 237);
1408 dump_expr (TREE_OPERAND (t
, 0), 0);
1410 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t
, 1)));
1415 if (TREE_OPERAND (t
,0) != NULL_TREE
1416 && NEXT_CODE (TREE_OPERAND (t
, 0)) == REFERENCE_TYPE
)
1417 dump_expr (TREE_OPERAND (t
, 0), nop
);
1419 dump_unary_op ("*", t
, nop
);
1425 case TRUTH_NOT_EXPR
:
1426 case PREDECREMENT_EXPR
:
1427 case PREINCREMENT_EXPR
:
1428 dump_unary_op (opname_tab
[(int)TREE_CODE (t
)], t
, nop
);
1431 case POSTDECREMENT_EXPR
:
1432 case POSTINCREMENT_EXPR
:
1434 dump_expr (TREE_OPERAND (t
, 0), 0);
1435 OB_PUTCP (opname_tab
[(int)TREE_CODE (t
)]);
1439 case NON_LVALUE_EXPR
:
1440 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
1441 should be another level of INDIRECT_REF so that I don't have to do
1443 if (TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == POINTER_TYPE
)
1445 tree next
= TREE_TYPE (TREE_TYPE (t
));
1447 while (TREE_CODE (next
) == POINTER_TYPE
)
1448 next
= TREE_TYPE (next
);
1450 if (TREE_CODE (next
) == FUNCTION_TYPE
)
1452 if (!nop
) OB_PUTC ('(');
1454 dump_expr (TREE_OPERAND (t
, 0), 1);
1455 if (!nop
) OB_PUTC (')');
1460 dump_expr (TREE_OPERAND (t
, 0), 0);
1464 dump_expr (TREE_OPERAND (t
, 0), nop
);
1468 if (TREE_TYPE (t
) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t
)))
1470 tree idx
= build_component_ref (t
, index_identifier
, NULL_TREE
, 0);
1472 if (integer_all_onesp (idx
))
1474 tree pfn
= PFN_FROM_PTRMEMFUNC (t
);
1478 if (TREE_CODE (idx
) == INTEGER_CST
1479 && TREE_INT_CST_HIGH (idx
) == 0)
1482 unsigned HOST_WIDE_INT n
;
1484 t
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t
)));
1485 t
= TYPE_METHOD_BASETYPE (t
);
1486 virtuals
= BINFO_VIRTUALS (TYPE_BINFO (TYPE_MAIN_VARIANT (t
)));
1488 n
= TREE_INT_CST_LOW (idx
);
1490 /* Map vtable index back one, to allow for the null pointer to
1494 while (n
> 0 && virtuals
)
1497 virtuals
= TREE_CHAIN (virtuals
);
1501 dump_expr (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals
)), 0);
1507 dump_expr_list (CONSTRUCTOR_ELTS (t
));
1513 tree ob
= TREE_OPERAND (t
, 0);
1514 if (TREE_CODE (ob
) == NOP_EXPR
1515 && TREE_OPERAND (ob
, 0) == error_mark_node
1516 && TREE_CODE (TREE_OPERAND (t
, 1)) == FUNCTION_DECL
)
1518 dump_expr (TREE_OPERAND (t
, 1), 0);
1521 dump_expr (TREE_OPERAND (t
, 0), 0);
1523 dump_expr (TREE_OPERAND (t
, 1), 0);
1528 case TEMPLATE_CONST_PARM
:
1530 int l
= current_template_parms
?
1531 list_length (current_template_parms
) : 0;
1533 if (l
>= TEMPLATE_CONST_LEVEL (t
))
1536 tree parms
= current_template_parms
;
1539 for (i
= 0; i
< l
- TEMPLATE_CONST_LEVEL (t
); ++i
)
1541 parms
= TREE_CHAIN (parms
);
1542 my_friendly_assert (parms
!= NULL_TREE
, 0);
1545 r
= TREE_VEC_ELT (TREE_VALUE (parms
),
1546 TEMPLATE_CONST_IDX (t
));
1547 dump_decl (TREE_VALUE (r
), -1);
1551 OB_PUTS ("<tparm ");
1552 OB_PUTI (TEMPLATE_CONST_IDX (t
));
1558 case IDENTIFIER_NODE
:
1563 dump_type (TREE_OPERAND (t
, 0), 0);
1565 dump_expr (TREE_OPERAND (t
, 1), 0);
1569 if (TREE_OPERAND (t
, 0) == NULL_TREE
1570 || TREE_CHAIN (TREE_OPERAND (t
, 0)))
1572 dump_type (TREE_TYPE (t
), 0);
1574 dump_expr_list (TREE_OPERAND (t
, 0));
1580 dump_type (TREE_TYPE (t
), 0);
1583 dump_expr_list (TREE_OPERAND (t
, 0));
1589 OB_PUTID (TREE_OPERAND (t
, 0));
1594 if (TREE_CODE (t
) == SIZEOF_EXPR
)
1595 OB_PUTS ("sizeof (");
1598 my_friendly_assert (TREE_CODE (t
) == ALIGNOF_EXPR
, 0);
1599 OB_PUTS ("__alignof__ (");
1601 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t
, 0))) == 't')
1602 dump_type (TREE_OPERAND (t
, 0), 0);
1604 dump_unary_op ("*", t
, 0);
1609 OB_PUTS ("{unparsed}");
1612 case TRY_CATCH_EXPR
:
1613 case WITH_CLEANUP_EXPR
:
1614 case CLEANUP_POINT_EXPR
:
1615 dump_expr (TREE_OPERAND (t
, 0), nop
);
1619 if (TREE_VALUE (t
) && TREE_CODE (TREE_VALUE (t
)) == FUNCTION_DECL
)
1621 OB_PUTID (DECL_NAME (TREE_VALUE (t
)));
1624 /* else fall through */
1626 /* This list is incomplete, but should suffice for now.
1627 It is very important that `sorry' does not call
1628 `report_error_function'. That could cause an infinite loop. */
1630 sorry ("`%s' not supported by dump_expr",
1631 tree_code_name
[(int) TREE_CODE (t
)]);
1633 /* fall through to ERROR_MARK... */
1635 OB_PUTCP ("{error}");
1641 dump_binary_op (opstring
, t
)
1646 dump_expr (TREE_OPERAND (t
, 0), 1);
1648 OB_PUTCP (opstring
);
1650 dump_expr (TREE_OPERAND (t
, 1), 1);
1655 dump_unary_op (opstring
, t
, nop
)
1660 if (!nop
) OB_PUTC ('(');
1661 OB_PUTCP (opstring
);
1662 dump_expr (TREE_OPERAND (t
, 0), 1);
1663 if (!nop
) OB_PUTC (')');
1667 fndecl_as_string (fndecl
, print_ret_type_p
)
1669 int print_ret_type_p
;
1671 return decl_as_string (fndecl
, print_ret_type_p
);
1674 /* Same, but handle a _TYPE.
1675 Called from convert_to_reference, mangle_class_name_for_template,
1676 build_unary_op, and GNU_xref_decl. */
1679 type_as_string (typ
, v
)
1689 return (char *)obstack_base (&scratch_obstack
);
1693 expr_as_string (decl
, v
)
1699 dump_expr (decl
, 1);
1703 return (char *)obstack_base (&scratch_obstack
);
1706 /* A cross between type_as_string and fndecl_as_string.
1707 Only called from substitute_nice_name. */
1710 decl_as_string (decl
, v
)
1716 dump_decl (decl
, v
);
1720 return (char *)obstack_base (&scratch_obstack
);
1723 /* Generate the three forms of printable names for lang_printable_name. */
1726 lang_decl_name (decl
, v
)
1731 return decl_as_string (decl
, 1);
1735 if (v
== 1 && DECL_CONTEXT (decl
)
1736 && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (decl
))) == 't')
1739 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1740 cname
= DECL_CLASS_CONTEXT (decl
);
1742 cname
= DECL_CONTEXT (decl
);
1743 dump_type (cname
, 0);
1744 OB_PUTC2 (':', ':');
1747 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1748 dump_function_name (decl
);
1750 dump_decl (DECL_NAME (decl
), 0);
1754 return (char *)obstack_base (&scratch_obstack
);
1762 if (TREE_CODE (t
) == PARM_DECL
)
1763 return DECL_SOURCE_FILE (DECL_CONTEXT (t
));
1764 else if (TREE_CODE_CLASS (TREE_CODE (t
)) == 't')
1765 return DECL_SOURCE_FILE (TYPE_MAIN_DECL (t
));
1767 return DECL_SOURCE_FILE (t
);
1775 if (TREE_CODE (t
) == PARM_DECL
)
1776 line
= DECL_SOURCE_LINE (DECL_CONTEXT (t
));
1777 if (TREE_CODE (t
) == TYPE_DECL
&& DECL_ARTIFICIAL (t
))
1780 if (TREE_CODE_CLASS (TREE_CODE (t
)) == 't')
1781 line
= DECL_SOURCE_LINE (TYPE_MAIN_DECL (t
));
1783 line
= DECL_SOURCE_LINE (t
);
1792 code_as_string (c
, v
)
1796 return tree_code_name
[c
];
1800 language_as_string (c
, v
)
1809 case lang_cplusplus
:
1813 my_friendly_abort (355);
1818 /* Return the proper printed version of a parameter to a C++ function. */
1821 parm_as_string (p
, v
)
1827 sprintf (digit_buffer
, "%d", p
+1);
1828 return digit_buffer
;
1836 static char buf
[] = "operator ";
1841 strcpy (buf
+ 9, opname_tab
[p
]);
1846 assop_as_string (p
, v
)
1850 static char buf
[] = "operator ";
1855 strcpy (buf
+ 9, assignop_tab
[p
]);
1860 args_as_string (p
, v
)
1867 if (TREE_CODE_CLASS (TREE_CODE (TREE_VALUE (p
))) == 't')
1868 return type_as_string (p
, v
);
1871 for (; p
; p
= TREE_CHAIN (p
))
1873 if (TREE_VALUE (p
) == null_node
)
1876 dump_type (error_type (TREE_VALUE (p
)), v
);
1881 return (char *)obstack_base (&scratch_obstack
);
1891 dump_readonly_or_volatile (p
, before
);
1895 return (char *)obstack_base (&scratch_obstack
);