1 /* Call-backs for C++ error reporting.
2 This code is non-reentrant.
3 Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
29 typedef char* cp_printer ();
31 #define A args_as_string
32 #define C code_as_string
33 #define D decl_as_string
34 #define E expr_as_string
35 #define L language_as_string
36 #define O op_as_string
37 #define P parm_as_string
38 #define Q assop_as_string
39 #define T type_as_string
40 #define V cv_as_string
42 #define _ (cp_printer *) 0
43 cp_printer
* cp_printers
[256] =
45 /*0 1 2 3 4 5 6 7 8 9 A B C D E F */
46 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0x00 */
47 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0x10 */
48 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0x20 */
49 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0x30 */
50 _
, A
, _
, C
, D
, E
, _
, _
, _
, _
, _
, _
, L
, _
, _
, O
, /* 0x40 */
51 P
, Q
, _
, _
, T
, _
, V
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0x50 */
52 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0x60 */
53 _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, _
, /* 0x70 */
66 #define obstack_chunk_alloc xmalloc
67 #define obstack_chunk_free free
69 /* Obstack where we build text strings for overloading, etc. */
70 static struct obstack scratch_obstack
;
71 static char *scratch_firstobj
;
73 # define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
74 # define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
75 # define OB_PUTC2(C1,C2) \
76 (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
77 # define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
78 # define OB_PUTID(ID) \
79 (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \
80 IDENTIFIER_LENGTH (ID)))
81 # define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
82 # define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
83 # define OB_PUTI(CST) do { sprintf (digit_buffer, "%d", (CST)); \
84 OB_PUTCP (digit_buffer); } while (0)
85 # define OB_UNPUT(N) obstack_blank (&scratch_obstack, - (N));
87 # define NEXT_CODE(t) (TREE_CODE (TREE_TYPE (t)))
89 enum pad
{ none
, before
, after
};
91 static void dump_type
PROTO((tree
, int));
92 static void dump_decl
PROTO((tree
, int));
93 static void dump_function_decl
PROTO((tree
, int));
94 static void dump_expr
PROTO((tree
, int));
95 static void dump_unary_op
PROTO((char *, tree
, int));
96 static void dump_binary_op
PROTO((char *, tree
));
97 static void dump_aggr_type
PROTO((tree
, int));
98 static void dump_type_prefix
PROTO((tree
, int));
99 static void dump_type_suffix
PROTO((tree
, int));
100 static void dump_function_name
PROTO((tree
));
101 static void dump_expr_list
PROTO((tree
));
102 static void dump_global_iord
PROTO((tree
));
103 static void dump_readonly_or_volatile
PROTO((tree
, enum pad
));
104 static void dump_char
PROTO((int));
105 static char *aggr_variety
PROTO((tree
));
106 static tree ident_fndecl
PROTO((tree
));
111 gcc_obstack_init (&scratch_obstack
);
112 scratch_firstobj
= (char *)obstack_alloc (&scratch_obstack
, 0);
116 dump_readonly_or_volatile (t
, p
)
120 if (TYPE_READONLY (t
) || TYPE_VOLATILE (t
))
122 if (p
== before
) OB_PUTC (' ');
123 if (TYPE_READONLY (t
))
125 if (TYPE_READONLY (t
) && TYPE_VOLATILE (t
))
127 if (TYPE_VOLATILE (t
))
128 OB_PUTS ("volatile");
129 if (p
== after
) OB_PUTC (' ');
133 /* This must be large enough to hold any printed integer or floating-point
135 static char digit_buffer
[128];
137 /* Dump into the obstack a human-readable equivalent of TYPE. */
142 int v
; /* verbose? */
147 if (TYPE_PTRMEMFUNC_P (t
))
150 switch (TREE_CODE (t
))
157 OB_PUTS ("{unknown type}");
161 /* i.e. function taking no arguments */
162 if (t
!= void_list_node
)
164 dump_type (TREE_VALUE (t
), v
);
165 /* Can this happen other than for default arguments? */
166 if (TREE_PURPOSE (t
) && v
)
169 dump_expr (TREE_PURPOSE (t
), 0);
173 if (TREE_CHAIN (t
) != void_list_node
)
176 dump_type (TREE_CHAIN (t
), v
);
179 else OB_PUTS (" ...");
183 case IDENTIFIER_NODE
:
188 dump_type (BINFO_TYPE (t
), v
);
194 if (TYPE_LANG_SPECIFIC (t
)
195 && (IS_SIGNATURE_POINTER (t
) || IS_SIGNATURE_REFERENCE (t
)))
197 if (TYPE_READONLY (t
) | TYPE_VOLATILE (t
))
198 dump_readonly_or_volatile (t
, after
);
199 dump_type (SIGNATURE_TYPE (t
), v
);
200 if (IS_SIGNATURE_POINTER (t
))
206 dump_aggr_type (t
, v
);
215 OB_PUTS ("complex ");
216 dump_type (TREE_TYPE (t
), v
);
220 if (!TREE_UNSIGNED (TYPE_MAIN_VARIANT (t
)) && TREE_UNSIGNED (t
))
221 OB_PUTS ("unsigned ");
222 else if (TREE_UNSIGNED (TYPE_MAIN_VARIANT (t
)) && !TREE_UNSIGNED (t
))
229 dump_readonly_or_volatile (t
, after
);
230 OB_PUTID (TYPE_IDENTIFIER (t
));
233 case TEMPLATE_TEMPLATE_PARM
:
234 if (!CLASSTYPE_TEMPLATE_INFO (t
))
236 /* For parameters inside template signature. */
237 if (TYPE_IDENTIFIER (t
))
238 OB_PUTID (TYPE_IDENTIFIER (t
));
240 OB_PUTS ("{anonymous template template parm}");
245 tree args
= CLASSTYPE_TI_ARGS (t
);
246 OB_PUTID (TYPE_IDENTIFIER (t
));
248 for (i
= 0; i
< TREE_VEC_LENGTH (args
); i
++)
250 tree arg
= TREE_VEC_ELT (args
, i
);
251 if (TREE_CODE_CLASS (TREE_CODE (arg
)) == 't'
252 || TREE_CODE (arg
) == TEMPLATE_DECL
)
256 if (i
< TREE_VEC_LENGTH (args
)-1)
263 case TEMPLATE_TYPE_PARM
:
264 dump_readonly_or_volatile (t
, after
);
265 if (TYPE_IDENTIFIER (t
))
266 OB_PUTID (TYPE_IDENTIFIER (t
));
268 OB_PUTS ("{anonymous template type parm}");
271 /* This is not always necessary for pointers and such, but doing this
272 reduces code size. */
280 dump_type_prefix (t
, v
);
281 dump_type_suffix (t
, v
);
285 OB_PUTS ("typename ");
286 dump_type (TYPE_CONTEXT (t
), 0);
288 OB_PUTID (TYPE_IDENTIFIER (t
));
292 sorry ("`%s' not supported by dump_type",
293 tree_code_name
[(int) TREE_CODE (t
)]);
301 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
303 else if (TREE_CODE (t
) == UNION_TYPE
)
305 else if (TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_DECLARED_CLASS (t
))
307 else if (TYPE_LANG_SPECIFIC (t
) && IS_SIGNATURE (t
))
313 /* Print out a class declaration, in the form `class foo'. */
316 dump_aggr_type (t
, v
)
318 int v
; /* verbose? */
321 char *variety
= aggr_variety (t
);
323 dump_readonly_or_volatile (t
, after
);
331 name
= TYPE_NAME (t
);
333 if (name
&& DECL_CONTEXT (name
))
335 /* FUNCTION_DECL or RECORD_TYPE */
336 dump_decl (DECL_CONTEXT (name
), 0);
340 /* kludge around weird behavior on g++.brendan/line1.C */
341 if (name
&& TREE_CODE (name
) != IDENTIFIER_NODE
)
342 name
= DECL_NAME (name
);
344 if (name
== 0 || ANON_AGGRNAME_P (name
))
346 OB_PUTS ("{anonymous");
358 /* Dump into the obstack the initial part of the output for a given type.
359 This is necessary when dealing with things like functions returning
362 return type of `int (* fee ())()': pointer -> function -> int. Both
363 pointer (and reference and offset) and function (and member) types must
364 deal with prefix and suffix.
366 Arrays must also do this for DECL nodes, like int a[], and for things like
370 dump_type_prefix (t
, v
)
372 int v
; /* verbosity */
374 if (TYPE_PTRMEMFUNC_P (t
))
376 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
380 switch (TREE_CODE (t
))
384 tree sub
= TREE_TYPE (t
);
386 dump_type_prefix (sub
, v
);
387 /* A tree for a member pointer looks like pointer to offset,
388 so let the OFFSET_TYPE case handle it. */
389 if (TREE_CODE (sub
) != OFFSET_TYPE
)
391 switch (TREE_CODE (sub
))
393 /* We don't want int ( *)() */
403 /* We don't want "char * *" */
404 if (! (TYPE_READONLY (sub
) || TYPE_VOLATILE (sub
)))
406 /* But we do want "char *const *" */
412 dump_readonly_or_volatile (t
, none
);
419 tree sub
= TREE_TYPE (t
);
420 dump_type_prefix (sub
, v
);
422 switch (TREE_CODE (sub
))
429 /* We don't want "char * &" */
430 if (! (TYPE_READONLY (sub
) || TYPE_VOLATILE (sub
)))
432 /* But we do want "char *const &" */
439 dump_readonly_or_volatile (t
, none
);
444 dump_type_prefix (TREE_TYPE (t
), v
);
445 if (TREE_CODE (t
) == OFFSET_TYPE
) /* pmfs deal with this in d_t_p */
448 dump_type (TYPE_OFFSET_BASETYPE (t
), 0);
452 dump_readonly_or_volatile (t
, none
);
455 /* Can only be reached through function pointer -- this would not be
456 correct if FUNCTION_DECLs used it. */
458 dump_type_prefix (TREE_TYPE (t
), v
);
463 dump_type_prefix (TREE_TYPE (t
), v
);
465 dump_aggr_type (TYPE_METHOD_BASETYPE (t
), 0);
470 dump_type_prefix (TREE_TYPE (t
), v
);
475 case IDENTIFIER_NODE
:
480 case TEMPLATE_TYPE_PARM
:
481 case TEMPLATE_TEMPLATE_PARM
:
494 sorry ("`%s' not supported by dump_type_prefix",
495 tree_code_name
[(int) TREE_CODE (t
)]);
500 dump_type_suffix (t
, v
)
502 int v
; /* verbose? */
504 if (TYPE_PTRMEMFUNC_P (t
))
505 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
507 switch (TREE_CODE (t
))
512 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
514 dump_type_suffix (TREE_TYPE (t
), v
);
517 /* Can only be reached through function pointer */
523 arg
= TYPE_ARG_TYPES (t
);
524 if (TREE_CODE (t
) == METHOD_TYPE
)
525 arg
= TREE_CHAIN (arg
);
532 if (TREE_CODE (t
) == METHOD_TYPE
)
533 dump_readonly_or_volatile
534 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t
))), before
);
535 dump_type_suffix (TREE_TYPE (t
), v
);
543 if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (t
))) == INTEGER_CST
)
544 OB_PUTI (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (t
))) + 1);
545 else if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (t
))) == MINUS_EXPR
)
546 dump_expr (TREE_OPERAND (TYPE_MAX_VALUE (TYPE_DOMAIN (t
)), 0), 0);
548 dump_expr (fold (build_binary_op
549 (PLUS_EXPR
, TYPE_MAX_VALUE (TYPE_DOMAIN (t
)),
550 integer_one_node
, 1)), 0);
553 dump_type_suffix (TREE_TYPE (t
), v
);
558 case IDENTIFIER_NODE
:
563 case TEMPLATE_TYPE_PARM
:
564 case TEMPLATE_TEMPLATE_PARM
:
576 sorry ("`%s' not supported by dump_type_suffix",
577 tree_code_name
[(int) TREE_CODE (t
)]);
581 /* Return a function declaration which corresponds to the IDENTIFIER_NODE
588 tree n
= lookup_name (t
, 0);
593 if (TREE_CODE (n
) == FUNCTION_DECL
)
595 else if (TREE_CODE (n
) == TREE_LIST
596 && TREE_CODE (TREE_VALUE (n
)) == FUNCTION_DECL
)
597 return TREE_VALUE (n
);
599 my_friendly_abort (66);
603 #ifndef NO_DOLLAR_IN_LABEL
604 # define GLOBAL_THING "_GLOBAL_$"
606 # ifndef NO_DOT_IN_LABEL
607 # define GLOBAL_THING "_GLOBAL_."
609 # define GLOBAL_THING "_GLOBAL__"
613 #define GLOBAL_IORD_P(NODE) \
614 ! strncmp (IDENTIFIER_POINTER(NODE), GLOBAL_THING, sizeof (GLOBAL_THING) - 1)
620 char *name
= IDENTIFIER_POINTER (t
);
622 OB_PUTS ("(static ");
623 if (name
[sizeof (GLOBAL_THING
) - 1] == 'I')
624 OB_PUTS ("initializers");
625 else if (name
[sizeof (GLOBAL_THING
) - 1] == 'D')
626 OB_PUTS ("destructors");
628 my_friendly_abort (352);
631 OB_PUTCP (input_filename
);
638 int v
; /* verbosity */
643 switch (TREE_CODE (t
))
646 OB_PUTS (" /* decl error */ ");
651 /* Don't say 'typedef class A' */
652 if (DECL_ARTIFICIAL (t
))
654 dump_type (TREE_TYPE (t
), v
);
659 OB_PUTS ("typedef ");
664 if (DECL_NAME (t
) && VTABLE_NAME_P (DECL_NAME (t
)))
666 OB_PUTS ("vtable for ");
667 dump_type (DECL_CONTEXT (t
), v
);
670 /* else fall through */
676 dump_type_prefix (TREE_TYPE (t
), v
);
678 dump_readonly_or_volatile (t
, after
);
680 /* DECL_CLASS_CONTEXT isn't being set in some cases. Hmm... */
682 && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (t
))) == 't')
684 dump_type (DECL_CONTEXT (t
), 0);
688 dump_decl (DECL_NAME (t
), v
);
692 dump_type_suffix (TREE_TYPE (t
), v
);
696 OB_PUTID (DECL_NAME (t
));
700 dump_decl (TREE_OPERAND (t
, 0), v
);
702 dump_decl (TREE_OPERAND (t
, 1), v
);
706 /* So that we can do dump_decl in dump_aggr_type and have it work for
707 both class and function scope. */
715 my_friendly_abort (69);
718 /* These special cases are duplicated here so that other functions
719 can feed identifiers to cp_error and get them demangled properly. */
720 case IDENTIFIER_NODE
:
722 if (DESTRUCTOR_NAME_P (t
)
723 && (f
= ident_fndecl (t
))
724 && DECL_LANGUAGE (f
) == lang_cplusplus
)
727 dump_decl (DECL_NAME (f
), 0);
729 else if (IDENTIFIER_TYPENAME_P (t
))
731 OB_PUTS ("operator ");
732 /* Not exactly IDENTIFIER_TYPE_VALUE. */
733 dump_type (TREE_TYPE (t
), 0);
736 else if (IDENTIFIER_OPNAME_P (t
))
738 char *name_string
= operator_name_string (t
);
739 OB_PUTS ("operator ");
740 OB_PUTCP (name_string
);
748 if (GLOBAL_IORD_P (DECL_ASSEMBLER_NAME (t
)))
749 dump_global_iord (DECL_ASSEMBLER_NAME (t
));
750 else if (! DECL_LANG_SPECIFIC (t
))
751 OB_PUTS ("{internal}");
753 dump_function_decl (t
, v
);
758 tree orig_args
= DECL_TEMPLATE_PARMS (t
);
761 for (args
= orig_args
= nreverse (orig_args
);
763 args
= TREE_CHAIN (args
))
765 int len
= TREE_VEC_LENGTH (TREE_VALUE (args
));
767 OB_PUTS ("template <");
768 for (i
= 0; i
< len
; i
++)
770 tree arg
= TREE_VEC_ELT (TREE_VALUE (args
), i
);
771 tree defval
= TREE_PURPOSE (arg
);
772 arg
= TREE_VALUE (arg
);
773 if (TREE_CODE (arg
) == TYPE_DECL
)
778 OB_PUTID (DECL_NAME (arg
));
789 if (TREE_CODE (arg
) == TYPE_DECL
)
790 dump_type (defval
, 1);
792 dump_decl (defval
, 1);
803 if (TREE_CODE (DECL_TEMPLATE_RESULT (t
)) == TYPE_DECL
)
804 dump_type (TREE_TYPE (t
), v
);
805 else if (TREE_TYPE (t
) == NULL_TREE
)
806 my_friendly_abort (353);
807 else switch (NEXT_CODE (t
))
811 dump_function_decl (t
, v
);
815 /* This case can occur with some illegal code. */
816 dump_type (TREE_TYPE (t
), v
);
821 case TEMPLATE_ID_EXPR
:
824 tree name
= TREE_OPERAND (t
, 0);
825 if (is_overloaded_fn (name
))
826 name
= DECL_NAME (get_first_fn (name
));
829 for (args
= TREE_OPERAND (t
, 1); args
; args
= TREE_CHAIN (args
))
831 if (TREE_CODE_CLASS (TREE_CODE (TREE_VALUE (args
))) == 't'
832 || TREE_CODE (TREE_VALUE (args
)) == TEMPLATE_DECL
)
833 dump_type (TREE_VALUE (args
), 0);
835 dump_expr (TREE_VALUE (args
), 0);
836 if (TREE_CHAIN (args
))
844 OB_PUTID (TREE_OPERAND (t
, 0));
848 OB_PUTID (DECL_NAME (t
));
852 if ((TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == ENUMERAL_TYPE
)
853 || (DECL_INITIAL (t
) &&
854 TREE_CODE (DECL_INITIAL (t
)) == TEMPLATE_CONST_PARM
))
856 else if (DECL_NAME (t
))
857 dump_decl (DECL_NAME (t
), v
);
858 else if (DECL_INITIAL (t
))
859 dump_expr (DECL_INITIAL (t
), 0);
861 OB_PUTS ("enumerator");
866 dump_type (DECL_INITIAL (t
), 0);
868 OB_PUTID (DECL_NAME (t
));
872 sorry ("`%s' not supported by dump_decl",
873 tree_code_name
[(int) TREE_CODE (t
)]);
877 /* Pretty printing for announce_function. T is the declaration of the
878 function we are interested in seeing. V is non-zero if we should print
879 the type that this function returns. */
882 dump_function_decl (t
, v
)
889 tree cname
= NULL_TREE
;
891 if (TREE_CODE (t
) == TEMPLATE_DECL
)
892 t
= DECL_TEMPLATE_RESULT (t
);
894 name
= DECL_ASSEMBLER_NAME (t
);
895 fntype
= TREE_TYPE (t
);
896 parmtypes
= TYPE_ARG_TYPES (fntype
);
898 /* Friends have DECL_CLASS_CONTEXT set, but not DECL_CONTEXT. */
899 if (DECL_CONTEXT (t
))
900 cname
= DECL_CLASS_CONTEXT (t
);
901 /* this is for partially instantiated template methods */
902 else if (TREE_CODE (fntype
) == METHOD_TYPE
)
903 cname
= TREE_TYPE (TREE_VALUE (parmtypes
));
909 if (DECL_STATIC_FUNCTION_P (t
))
912 if (! IDENTIFIER_TYPENAME_P (name
)
913 && ! DECL_CONSTRUCTOR_P (t
)
914 && ! DESTRUCTOR_NAME_P (name
))
916 dump_type_prefix (TREE_TYPE (fntype
), 1);
923 dump_type (cname
, 0);
925 if (TREE_CODE (fntype
) == METHOD_TYPE
&& parmtypes
)
926 parmtypes
= TREE_CHAIN (parmtypes
);
927 if (DECL_CONSTRUCTOR_FOR_VBASE_P (t
))
928 /* Skip past "in_charge" identifier. */
929 parmtypes
= TREE_CHAIN (parmtypes
);
932 if (DESTRUCTOR_NAME_P (name
) && DECL_LANGUAGE (t
) == lang_cplusplus
)
933 parmtypes
= TREE_CHAIN (parmtypes
);
935 dump_function_name (t
);
940 dump_type (parmtypes
, v
);
946 if (v
&& ! IDENTIFIER_TYPENAME_P (name
))
947 dump_type_suffix (TREE_TYPE (fntype
), 1);
949 if (TREE_CODE (fntype
) == METHOD_TYPE
)
951 if (IS_SIGNATURE (cname
))
952 /* We look at the type pointed to by the `optr' field of `this.' */
953 dump_readonly_or_volatile
954 (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_VALUE (TYPE_ARG_TYPES (fntype
))))), before
);
956 dump_readonly_or_volatile
957 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype
))), before
);
961 /* Handle the function name for a FUNCTION_DECL node, grokking operators
962 and destructors properly. */
965 dump_function_name (t
)
968 tree name
= DECL_NAME (t
);
970 /* There ought to be a better way to find out whether or not something is
972 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (t
))
973 && DECL_LANGUAGE (t
) == lang_cplusplus
)
978 else if (IDENTIFIER_TYPENAME_P (name
))
980 /* This cannot use the hack that the operator's return
981 type is stashed off of its name because it may be
982 used for error reporting. In the case of conflicting
983 declarations, both will have the same name, yet
984 the types will be different, hence the TREE_TYPE field
985 of the first name will be clobbered by the second. */
986 OB_PUTS ("operator ");
987 dump_type (TREE_TYPE (TREE_TYPE (t
)), 0);
989 else if (IDENTIFIER_OPNAME_P (name
))
991 char *name_string
= operator_name_string (name
);
992 OB_PUTS ("operator ");
993 OB_PUTCP (name_string
);
998 if (DECL_LANG_SPECIFIC (t
) && DECL_USE_TEMPLATE (t
))
1000 tree args
= DECL_TEMPLATE_INFO (t
) ? DECL_TI_ARGS (t
) : NULL_TREE
;
1002 if (args
!= NULL_TREE
1003 && DECL_CONTEXT (t
) != NULL_TREE
1004 && uses_template_parms (DECL_CONTEXT (t
))
1005 /* This next clause checks that there is only one level of
1006 template arguments. In that case, they are the
1007 arguments for the class context. */
1008 && (TREE_CODE (args
) == TREE_LIST
1009 || (TREE_CODE (args
) == TREE_VEC
1010 && TREE_VEC_ELT (args
, 0) != NULL_TREE
1011 && TREE_CODE (TREE_VEC_ELT (args
, 0)) != TREE_VEC
)))
1012 /* We have something like this:
1014 template <class T> struct S { void f(); };
1016 and we are printing S<int>::f(). This is a template
1017 instantiation, but we don't print anything after the f. */
1023 /* Be careful only to print things when we have them, so as not
1024 to crash producing error messages. */
1027 if (TREE_CODE (args
) == TREE_LIST
)
1032 for (arg
= args
; arg
; arg
= TREE_CHAIN (arg
))
1034 tree a
= TREE_VALUE (arg
);
1041 if (TREE_CODE_CLASS (TREE_CODE (a
)) == 't'
1042 || TREE_CODE (a
) == TEMPLATE_DECL
)
1051 else if (TREE_CODE (args
) == TREE_VEC
)
1056 if (TREE_VEC_LENGTH (args
) > 0
1057 && TREE_CODE (TREE_VEC_ELT (args
, 0)) == TREE_VEC
)
1058 args
= TREE_VEC_ELT (args
,
1059 TREE_VEC_LENGTH (args
) - 1);
1061 for (i
= 0; i
< TREE_VEC_LENGTH (args
); i
++)
1063 tree a
= TREE_VEC_ELT (args
, i
);
1070 if (TREE_CODE_CLASS (TREE_CODE (a
)) == 't'
1071 || TREE_CODE (a
) == TEMPLATE_DECL
)
1092 case TARGET_NEWLINE
:
1127 sprintf (digit_buffer
, "\\%03o", (int) c
);
1128 OB_PUTCP (digit_buffer
);
1133 /* Print out a list of initializers (subr of dump_expr) */
1141 dump_expr (TREE_VALUE (l
), 0);
1143 OB_PUTC2 (',', ' ');
1148 /* Print out an expression */
1153 int nop
; /* suppress parens */
1155 switch (TREE_CODE (t
))
1168 tree type
= TREE_TYPE (t
);
1169 my_friendly_assert (type
!= 0, 81);
1171 /* If it's an enum, output its tag, rather than its value. */
1172 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1174 char *p
= enum_name_string (t
, type
);
1177 else if (type
== boolean_type_node
)
1179 if (t
== boolean_false_node
1180 || (TREE_INT_CST_LOW (t
) == 0
1181 && TREE_INT_CST_HIGH (t
) == 0))
1183 else if (t
== boolean_true_node
)
1186 else if (type
== char_type_node
)
1189 dump_char (TREE_INT_CST_LOW (t
));
1192 else if (TREE_INT_CST_HIGH (t
)
1193 != (TREE_INT_CST_LOW (t
) >> (HOST_BITS_PER_WIDE_INT
- 1)))
1196 if (TREE_INT_CST_HIGH (val
) < 0)
1199 val
= build_int_2 (~TREE_INT_CST_LOW (val
),
1200 -TREE_INT_CST_HIGH (val
));
1202 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
1205 static char format
[10]; /* "%x%09999x\0" */
1207 sprintf (format
, "%%x%%0%dx", HOST_BITS_PER_INT
/ 4);
1208 sprintf (digit_buffer
, format
, TREE_INT_CST_HIGH (val
),
1209 TREE_INT_CST_LOW (val
));
1210 OB_PUTCP (digit_buffer
);
1214 OB_PUTI (TREE_INT_CST_LOW (t
));
1219 #ifndef REAL_IS_NOT_DOUBLE
1220 sprintf (digit_buffer
, "%g", TREE_REAL_CST (t
));
1223 unsigned char *p
= (unsigned char *) &TREE_REAL_CST (t
);
1225 strcpy (digit_buffer
, "0x");
1226 for (i
= 0; i
< sizeof TREE_REAL_CST (t
); i
++)
1227 sprintf (digit_buffer
+ 2 + 2*i
, "%02x", *p
++);
1230 OB_PUTCP (digit_buffer
);
1235 char *p
= TREE_STRING_POINTER (t
);
1236 int len
= TREE_STRING_LENGTH (t
) - 1;
1240 for (i
= 0; i
< len
; i
++)
1247 dump_binary_op (",", t
);
1252 dump_expr (TREE_OPERAND (t
, 0), 0);
1254 dump_expr (TREE_OPERAND (t
, 1), 0);
1256 dump_expr (TREE_OPERAND (t
, 2), 0);
1261 if (TREE_HAS_CONSTRUCTOR (t
))
1264 dump_type (TREE_TYPE (TREE_TYPE (t
)), 0);
1265 PARM_DECL_EXPR (t
) = 1;
1269 dump_expr (TREE_OPERAND (t
, 0), 0);
1273 case AGGR_INIT_EXPR
:
1274 OB_PUTID (TYPE_IDENTIFIER (TREE_TYPE (t
)));
1276 if (TREE_OPERAND (t
, 1))
1277 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t
, 1)));
1283 tree fn
= TREE_OPERAND (t
, 0);
1284 tree args
= TREE_OPERAND (t
, 1);
1286 if (TREE_CODE (fn
) == ADDR_EXPR
)
1287 fn
= TREE_OPERAND (fn
, 0);
1289 if (TREE_TYPE (fn
) != NULL_TREE
&& NEXT_CODE (fn
) == METHOD_TYPE
)
1291 tree ob
= TREE_VALUE (args
);
1292 if (TREE_CODE (ob
) == ADDR_EXPR
)
1294 dump_expr (TREE_OPERAND (ob
, 0), 0);
1297 else if (TREE_CODE (ob
) != PARM_DECL
1298 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob
)), "this"))
1301 OB_PUTC2 ('-', '>');
1303 args
= TREE_CHAIN (args
);
1307 dump_expr_list (args
);
1313 /* Note that this only works for G++ target exprs. If somebody
1314 builds a general TARGET_EXPR, there's no way to represent that
1315 it initializes anything other that the parameter slot for the
1316 default argument. Note we may have cleared out the first
1317 operand in expand_expr, so don't go killing ourselves. */
1318 if (TREE_OPERAND (t
, 1))
1319 dump_expr (TREE_OPERAND (t
, 1), 0);
1326 case TRUNC_DIV_EXPR
:
1327 case TRUNC_MOD_EXPR
:
1335 case BIT_ANDTC_EXPR
:
1336 case TRUTH_ANDIF_EXPR
:
1337 case TRUTH_ORIF_EXPR
:
1344 dump_binary_op (opname_tab
[(int) TREE_CODE (t
)], t
);
1348 case FLOOR_DIV_EXPR
:
1349 case ROUND_DIV_EXPR
:
1350 dump_binary_op ("/", t
);
1354 case FLOOR_MOD_EXPR
:
1355 case ROUND_MOD_EXPR
:
1356 dump_binary_op ("%", t
);
1361 tree ob
= TREE_OPERAND (t
, 0);
1362 if (TREE_CODE (ob
) == INDIRECT_REF
)
1364 ob
= TREE_OPERAND (ob
, 0);
1365 if (TREE_CODE (ob
) != PARM_DECL
1366 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob
)), "this"))
1369 OB_PUTC2 ('-', '>');
1377 dump_expr (TREE_OPERAND (t
, 1), 1);
1382 dump_expr (TREE_OPERAND (t
, 0), 0);
1384 dump_expr (TREE_OPERAND (t
, 1), 0);
1389 dump_unary_op ("+", t
, nop
);
1393 if (TREE_CODE (TREE_OPERAND (t
, 0)) == FUNCTION_DECL
1394 || TREE_CODE (TREE_OPERAND (t
, 0)) == STRING_CST
)
1395 dump_expr (TREE_OPERAND (t
, 0), 0);
1397 dump_unary_op ("&", t
, nop
);
1401 if (TREE_HAS_CONSTRUCTOR (t
))
1403 t
= TREE_OPERAND (t
, 0);
1404 my_friendly_assert (TREE_CODE (t
) == CALL_EXPR
, 237);
1405 dump_expr (TREE_OPERAND (t
, 0), 0);
1407 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t
, 1)));
1412 if (TREE_OPERAND (t
,0) != NULL_TREE
1413 && NEXT_CODE (TREE_OPERAND (t
, 0)) == REFERENCE_TYPE
)
1414 dump_expr (TREE_OPERAND (t
, 0), nop
);
1416 dump_unary_op ("*", t
, nop
);
1422 case TRUTH_NOT_EXPR
:
1423 case PREDECREMENT_EXPR
:
1424 case PREINCREMENT_EXPR
:
1425 dump_unary_op (opname_tab
[(int)TREE_CODE (t
)], t
, nop
);
1428 case POSTDECREMENT_EXPR
:
1429 case POSTINCREMENT_EXPR
:
1431 dump_expr (TREE_OPERAND (t
, 0), 0);
1432 OB_PUTCP (opname_tab
[(int)TREE_CODE (t
)]);
1436 case NON_LVALUE_EXPR
:
1437 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
1438 should be another level of INDIRECT_REF so that I don't have to do
1440 if (TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == POINTER_TYPE
)
1442 tree next
= TREE_TYPE (TREE_TYPE (t
));
1444 while (TREE_CODE (next
) == POINTER_TYPE
)
1445 next
= TREE_TYPE (next
);
1447 if (TREE_CODE (next
) == FUNCTION_TYPE
)
1449 if (!nop
) OB_PUTC ('(');
1451 dump_expr (TREE_OPERAND (t
, 0), 1);
1452 if (!nop
) OB_PUTC (')');
1457 dump_expr (TREE_OPERAND (t
, 0), 0);
1461 dump_expr (TREE_OPERAND (t
, 0), nop
);
1465 if (TREE_TYPE (t
) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t
)))
1467 tree idx
= build_component_ref (t
, index_identifier
, NULL_TREE
, 0);
1469 if (integer_all_onesp (idx
))
1471 tree pfn
= PFN_FROM_PTRMEMFUNC (t
);
1475 if (TREE_CODE (idx
) == INTEGER_CST
1476 && TREE_INT_CST_HIGH (idx
) == 0)
1479 unsigned HOST_WIDE_INT n
;
1481 t
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t
)));
1482 t
= TYPE_METHOD_BASETYPE (t
);
1483 virtuals
= BINFO_VIRTUALS (TYPE_BINFO (TYPE_MAIN_VARIANT (t
)));
1485 n
= TREE_INT_CST_LOW (idx
);
1487 /* Map vtable index back one, to allow for the null pointer to
1491 while (n
> 0 && virtuals
)
1494 virtuals
= TREE_CHAIN (virtuals
);
1498 dump_expr (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals
)), 0);
1504 dump_expr_list (CONSTRUCTOR_ELTS (t
));
1510 tree ob
= TREE_OPERAND (t
, 0);
1511 if (TREE_CODE (ob
) == NOP_EXPR
1512 && TREE_OPERAND (ob
, 0) == error_mark_node
1513 && TREE_CODE (TREE_OPERAND (t
, 1)) == FUNCTION_DECL
)
1515 dump_expr (TREE_OPERAND (t
, 1), 0);
1518 dump_expr (TREE_OPERAND (t
, 0), 0);
1520 dump_expr (TREE_OPERAND (t
, 1), 0);
1525 case TEMPLATE_CONST_PARM
:
1527 int l
= current_template_parms
?
1528 list_length (current_template_parms
) : 0;
1530 if (l
>= TEMPLATE_CONST_LEVEL (t
))
1533 tree parms
= current_template_parms
;
1536 for (i
= 0; i
< l
- TEMPLATE_CONST_LEVEL (t
); ++i
)
1538 parms
= TREE_CHAIN (parms
);
1539 my_friendly_assert (parms
!= NULL_TREE
, 0);
1542 r
= TREE_VEC_ELT (TREE_VALUE (parms
),
1543 TEMPLATE_CONST_IDX (t
));
1544 dump_decl (TREE_VALUE (r
), -1);
1548 OB_PUTS ("<tparm ");
1549 OB_PUTI (TEMPLATE_CONST_IDX (t
));
1555 case IDENTIFIER_NODE
:
1560 dump_type (TREE_OPERAND (t
, 0), 0);
1562 dump_expr (TREE_OPERAND (t
, 1), 0);
1566 if (TREE_OPERAND (t
, 0) == NULL_TREE
1567 || TREE_CHAIN (TREE_OPERAND (t
, 0)))
1569 dump_type (TREE_TYPE (t
), 0);
1571 dump_expr_list (TREE_OPERAND (t
, 0));
1577 dump_type (TREE_TYPE (t
), 0);
1580 dump_expr_list (TREE_OPERAND (t
, 0));
1586 OB_PUTID (TREE_OPERAND (t
, 0));
1591 if (TREE_CODE (t
) == SIZEOF_EXPR
)
1592 OB_PUTS ("sizeof (");
1595 my_friendly_assert (TREE_CODE (t
) == ALIGNOF_EXPR
, 0);
1596 OB_PUTS ("__alignof__ (");
1598 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t
, 0))) == 't')
1599 dump_type (TREE_OPERAND (t
, 0), 0);
1601 dump_unary_op ("*", t
, 0);
1606 OB_PUTS ("{unparsed}");
1609 case TRY_CATCH_EXPR
:
1610 case WITH_CLEANUP_EXPR
:
1611 case CLEANUP_POINT_EXPR
:
1612 dump_expr (TREE_OPERAND (t
, 0), nop
);
1616 if (TREE_VALUE (t
) && TREE_CODE (TREE_VALUE (t
)) == FUNCTION_DECL
)
1618 OB_PUTID (DECL_NAME (TREE_VALUE (t
)));
1621 /* else fall through */
1623 /* This list is incomplete, but should suffice for now.
1624 It is very important that `sorry' does not call
1625 `report_error_function'. That could cause an infinite loop. */
1627 sorry ("`%s' not supported by dump_expr",
1628 tree_code_name
[(int) TREE_CODE (t
)]);
1630 /* fall through to ERROR_MARK... */
1633 OB_PUTCP ("{error}");
1639 dump_binary_op (opstring
, t
)
1644 dump_expr (TREE_OPERAND (t
, 0), 1);
1646 OB_PUTCP (opstring
);
1648 dump_expr (TREE_OPERAND (t
, 1), 1);
1653 dump_unary_op (opstring
, t
, nop
)
1658 if (!nop
) OB_PUTC ('(');
1659 OB_PUTCP (opstring
);
1660 dump_expr (TREE_OPERAND (t
, 0), 1);
1661 if (!nop
) OB_PUTC (')');
1665 fndecl_as_string (fndecl
, print_ret_type_p
)
1667 int print_ret_type_p
;
1669 return decl_as_string (fndecl
, print_ret_type_p
);
1672 /* Same, but handle a _TYPE.
1673 Called from convert_to_reference, mangle_class_name_for_template,
1674 build_unary_op, and GNU_xref_decl. */
1677 type_as_string (typ
, v
)
1687 return (char *)obstack_base (&scratch_obstack
);
1691 expr_as_string (decl
, v
)
1697 dump_expr (decl
, 1);
1701 return (char *)obstack_base (&scratch_obstack
);
1704 /* A cross between type_as_string and fndecl_as_string.
1705 Only called from substitute_nice_name. */
1708 decl_as_string (decl
, v
)
1714 dump_decl (decl
, v
);
1718 return (char *)obstack_base (&scratch_obstack
);
1721 /* Generate the three forms of printable names for lang_printable_name. */
1724 lang_decl_name (decl
, v
)
1729 return decl_as_string (decl
, 1);
1733 if (v
== 1 && DECL_CONTEXT (decl
)
1734 && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (decl
))) == 't')
1737 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1738 cname
= DECL_CLASS_CONTEXT (decl
);
1740 cname
= DECL_CONTEXT (decl
);
1741 dump_type (cname
, 0);
1742 OB_PUTC2 (':', ':');
1745 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1746 dump_function_name (decl
);
1748 dump_decl (DECL_NAME (decl
), 0);
1752 return (char *)obstack_base (&scratch_obstack
);
1760 if (TREE_CODE (t
) == PARM_DECL
)
1761 return DECL_SOURCE_FILE (DECL_CONTEXT (t
));
1762 else if (TREE_CODE_CLASS (TREE_CODE (t
)) == 't')
1763 return DECL_SOURCE_FILE (TYPE_MAIN_DECL (t
));
1765 return DECL_SOURCE_FILE (t
);
1773 if (TREE_CODE (t
) == PARM_DECL
)
1774 line
= DECL_SOURCE_LINE (DECL_CONTEXT (t
));
1775 if (TREE_CODE (t
) == TYPE_DECL
&& DECL_ARTIFICIAL (t
))
1778 if (TREE_CODE_CLASS (TREE_CODE (t
)) == 't')
1779 line
= DECL_SOURCE_LINE (TYPE_MAIN_DECL (t
));
1781 line
= DECL_SOURCE_LINE (t
);
1790 code_as_string (c
, v
)
1794 return tree_code_name
[c
];
1798 language_as_string (c
, v
)
1807 case lang_cplusplus
:
1811 my_friendly_abort (355);
1816 /* Return the proper printed version of a parameter to a C++ function. */
1819 parm_as_string (p
, v
)
1825 sprintf (digit_buffer
, "%d", p
+1);
1826 return digit_buffer
;
1834 static char buf
[] = "operator ";
1839 strcpy (buf
+ 9, opname_tab
[p
]);
1844 assop_as_string (p
, v
)
1848 static char buf
[] = "operator ";
1853 strcpy (buf
+ 9, assignop_tab
[p
]);
1858 args_as_string (p
, v
)
1865 if (TREE_CODE_CLASS (TREE_CODE (TREE_VALUE (p
))) == 't')
1866 return type_as_string (p
, v
);
1869 for (; p
; p
= TREE_CHAIN (p
))
1871 if (TREE_VALUE (p
) == null_node
)
1874 dump_type (error_type (TREE_VALUE (p
)), v
);
1879 return (char *)obstack_base (&scratch_obstack
);
1889 dump_readonly_or_volatile (p
, before
);
1893 return (char *)obstack_base (&scratch_obstack
);