1 /* Call-backs for C++ error reporting.
2 This code is non-reentrant.
3 Copyright (C) 1993, 94-97, 1998 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 o (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 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x00 */
47 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x10 */
48 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x20 */
49 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x30 */
50 o, A, o, C, D, E, o, o, o, o, o, o, L, o, o, O, /* 0x40 */
51 P, Q, o, o, T, o, V, o, o, o, o, o, o, o, o, o, /* 0x50 */
52 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x60 */
53 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 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, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT)(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_type_real PROTO((tree, int, int));
93 static void dump_simple_decl PROTO((tree, tree, int));
94 static void dump_decl PROTO((tree, int));
95 static void dump_function_decl PROTO((tree, int));
96 static void dump_expr PROTO((tree, int));
97 static void dump_unary_op PROTO((char *, tree, int));
98 static void dump_binary_op PROTO((char *, tree));
99 static void dump_aggr_type PROTO((tree, int, int));
100 static void dump_type_prefix PROTO((tree, int, int));
101 static void dump_type_suffix PROTO((tree, int, int));
102 static void dump_function_name PROTO((tree));
103 static void dump_expr_list PROTO((tree));
104 static void dump_global_iord PROTO((tree));
105 static void dump_qualifiers PROTO((tree, enum pad));
106 static void dump_char PROTO((int));
107 static char *aggr_variety PROTO((tree));
108 static tree ident_fndecl PROTO((tree));
113 gcc_obstack_init (&scratch_obstack);
114 scratch_firstobj = (char *)obstack_alloc (&scratch_obstack, 0);
118 dump_qualifiers (t, p)
124 if (p == before) OB_PUTC (' ');
125 switch (TYPE_QUALS (t))
127 case TYPE_QUAL_CONST:
131 case TYPE_QUAL_VOLATILE:
132 OB_PUTS ("volatile");
135 case TYPE_QUAL_RESTRICT:
136 OB_PUTS ("__restrict");
139 case TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE:
140 OB_PUTS ("const volatile");
143 case TYPE_QUAL_CONST | TYPE_QUAL_RESTRICT:
144 OB_PUTS ("const __restrict");
147 case TYPE_QUAL_VOLATILE | TYPE_QUAL_RESTRICT:
148 OB_PUTS ("volatile __restrict");
151 case TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE | TYPE_QUAL_RESTRICT:
152 OB_PUTS ("const volatile __restrict");
156 my_friendly_abort (0);
158 if (p == after) OB_PUTC (' ');
162 /* This must be large enough to hold any printed integer or floating-point
164 static char digit_buffer[128];
166 /* Dump into the obstack a human-readable equivalent of TYPE. */
169 dump_type_real (t, v, canonical_name)
171 int v; /* verbose? */
177 if (TYPE_PTRMEMFUNC_P (t))
180 switch (TREE_CODE (t))
187 OB_PUTS ("{unknown type}");
191 /* i.e. function taking no arguments */
192 if (t != void_list_node)
194 dump_type_real (TREE_VALUE (t), v, canonical_name);
195 /* Can this happen other than for default arguments? */
196 if (TREE_PURPOSE (t) && v)
199 dump_expr (TREE_PURPOSE (t), 0);
203 if (TREE_CHAIN (t) != void_list_node)
206 dump_type_real (TREE_CHAIN (t), v, canonical_name);
209 else OB_PUTS (" ...");
213 case IDENTIFIER_NODE:
218 dump_type_real (BINFO_TYPE (t), v, canonical_name);
224 if (TYPE_LANG_SPECIFIC (t)
225 && (IS_SIGNATURE_POINTER (t) || IS_SIGNATURE_REFERENCE (t)))
227 dump_qualifiers (t, after);
228 dump_type_real (SIGNATURE_TYPE (t), v, canonical_name);
229 if (IS_SIGNATURE_POINTER (t))
235 dump_aggr_type (t, v, canonical_name);
245 OB_PUTS ("complex ");
246 dump_type_real (TREE_TYPE (t), v, canonical_name);
250 if (!TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)) && TREE_UNSIGNED (t))
251 OB_PUTS ("unsigned ");
252 else if (TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)) && !TREE_UNSIGNED (t))
261 dump_qualifiers (t, after);
262 type = canonical_name ? TYPE_MAIN_VARIANT (t) : t;
263 if (TYPE_NAME (type) && TYPE_IDENTIFIER (type))
264 OB_PUTID (TYPE_IDENTIFIER (type));
266 /* Types like intQI_type_node and friends have no names.
267 These don't come up in user error messages, but it's nice
268 to be able to print them from the debugger. */
269 OB_PUTS ("{anonymous}");
273 case TEMPLATE_TEMPLATE_PARM:
274 if (!TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t))
276 /* For parameters inside template signature. */
277 if (TYPE_IDENTIFIER (t))
278 OB_PUTID (TYPE_IDENTIFIER (t));
280 OB_PUTS ("{anonymous template template parm}");
285 tree args = TYPE_TI_ARGS (t);
286 OB_PUTID (TYPE_IDENTIFIER (t));
288 for (i = 0; i < TREE_VEC_LENGTH (args); i++)
290 tree arg = TREE_VEC_ELT (args, i);
291 if (TREE_CODE_CLASS (TREE_CODE (arg)) == 't'
292 || TREE_CODE (arg) == TEMPLATE_DECL)
293 dump_type_real (arg, 0, canonical_name);
296 if (i < TREE_VEC_LENGTH (args)-1)
303 case TEMPLATE_TYPE_PARM:
304 dump_qualifiers (t, after);
305 if (TYPE_IDENTIFIER (t))
306 OB_PUTID (TYPE_IDENTIFIER (t));
308 OB_PUTS ("{anonymous template type parm}");
311 /* This is not always necessary for pointers and such, but doing this
312 reduces code size. */
320 dump_type_prefix (t, v, canonical_name);
321 dump_type_suffix (t, v, canonical_name);
325 OB_PUTS ("typename ");
326 dump_type_real (TYPE_CONTEXT (t), 0, canonical_name);
328 OB_PUTID (TYPE_IDENTIFIER (t));
332 OB_PUTS ("__typeof (");
333 dump_expr (TYPE_FIELDS (t), 1);
338 sorry ("`%s' not supported by dump_type",
339 tree_code_name[(int) TREE_CODE (t)]);
347 if (TREE_CODE (t) == ENUMERAL_TYPE)
349 else if (TREE_CODE (t) == UNION_TYPE)
351 else if (TYPE_LANG_SPECIFIC (t) && CLASSTYPE_DECLARED_CLASS (t))
353 else if (TYPE_LANG_SPECIFIC (t) && IS_SIGNATURE (t))
362 int v; /* verbose? */
364 dump_type_real (t, v, 0);
367 /* Print out a class declaration, in the form `class foo'. */
370 dump_aggr_type (t, v, canonical_name)
372 int v; /* verbose? */
376 char *variety = aggr_variety (t);
378 dump_qualifiers (t, after);
386 name = TYPE_NAME (canonical_name ? TYPE_MAIN_VARIANT (t) : t);
388 if (name && CP_DECL_CONTEXT (name) != global_namespace)
390 /* FUNCTION_DECL or RECORD_TYPE */
391 dump_decl (DECL_CONTEXT (name), 0);
395 /* kludge around weird behavior on g++.brendan/line1.C */
396 if (name && TREE_CODE (name) != IDENTIFIER_NODE)
397 name = DECL_NAME (name);
399 if (name == 0 || ANON_AGGRNAME_P (name))
401 OB_PUTS ("{anonymous");
413 /* Dump into the obstack the initial part of the output for a given type.
414 This is necessary when dealing with things like functions returning
417 return type of `int (* fee ())()': pointer -> function -> int. Both
418 pointer (and reference and offset) and function (and member) types must
419 deal with prefix and suffix.
421 Arrays must also do this for DECL nodes, like int a[], and for things like
425 dump_type_prefix (t, v, canonical_name)
427 int v; /* verbosity */
430 if (TYPE_PTRMEMFUNC_P (t))
432 t = TYPE_PTRMEMFUNC_FN_TYPE (t);
436 switch (TREE_CODE (t))
441 tree sub = TREE_TYPE (t);
443 dump_type_prefix (sub, v, canonical_name);
444 /* A tree for a member pointer looks like pointer to offset,
445 so let the OFFSET_TYPE case handle it. */
446 if (!TYPE_PTRMEM_P (t))
448 switch (TREE_CODE (sub))
450 /* We don't want int ( *)() */
460 /* We don't want "char * *" */
461 if (TYPE_QUALS (sub) == TYPE_UNQUALIFIED)
463 /* But we do want "char *const *" */
468 if (TREE_CODE (t) == POINTER_TYPE)
472 dump_qualifiers (t, none);
479 dump_type_prefix (TREE_TYPE (t), v, canonical_name);
480 if (TREE_CODE (t) == OFFSET_TYPE) /* pmfs deal with this in d_t_p */
483 dump_type_real (TYPE_OFFSET_BASETYPE (t), 0, canonical_name);
487 dump_qualifiers (t, none);
490 /* Can only be reached through function pointer -- this would not be
491 correct if FUNCTION_DECLs used it. */
493 dump_type_prefix (TREE_TYPE (t), v, canonical_name);
498 dump_type_prefix (TREE_TYPE (t), v, canonical_name);
500 dump_aggr_type (TYPE_METHOD_BASETYPE (t), 0, canonical_name);
505 dump_type_prefix (TREE_TYPE (t), v, canonical_name);
510 case IDENTIFIER_NODE:
515 case TEMPLATE_TYPE_PARM:
516 case TEMPLATE_TEMPLATE_PARM:
525 dump_type_real (t, v, canonical_name);
529 sorry ("`%s' not supported by dump_type_prefix",
530 tree_code_name[(int) TREE_CODE (t)]);
535 dump_type_suffix (t, v, canonical_name)
537 int v; /* verbose? */
540 if (TYPE_PTRMEMFUNC_P (t))
541 t = TYPE_PTRMEMFUNC_FN_TYPE (t);
543 switch (TREE_CODE (t))
548 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
550 dump_type_suffix (TREE_TYPE (t), v, canonical_name);
553 /* Can only be reached through function pointer */
559 arg = TYPE_ARG_TYPES (t);
560 if (TREE_CODE (t) == METHOD_TYPE)
561 arg = TREE_CHAIN (arg);
568 if (TREE_CODE (t) == METHOD_TYPE)
570 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t))), before);
571 dump_type_suffix (TREE_TYPE (t), v, canonical_name);
579 if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (t))) == INTEGER_CST)
580 OB_PUTI (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (t))) + 1);
581 else if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (t))) == MINUS_EXPR)
582 dump_expr (TREE_OPERAND (TYPE_MAX_VALUE (TYPE_DOMAIN (t)), 0), 0);
584 dump_expr (fold (build_binary_op
585 (PLUS_EXPR, TYPE_MAX_VALUE (TYPE_DOMAIN (t)),
586 integer_one_node, 1)), 0);
589 dump_type_suffix (TREE_TYPE (t), v, canonical_name);
594 case IDENTIFIER_NODE:
599 case TEMPLATE_TYPE_PARM:
600 case TEMPLATE_TEMPLATE_PARM:
612 sorry ("`%s' not supported by dump_type_suffix",
613 tree_code_name[(int) TREE_CODE (t)]);
617 /* Return a function declaration which corresponds to the IDENTIFIER_NODE
624 tree n = lookup_name (t, 0);
629 if (TREE_CODE (n) == FUNCTION_DECL)
631 else if (TREE_CODE (n) == TREE_LIST
632 && TREE_CODE (TREE_VALUE (n)) == FUNCTION_DECL)
633 return TREE_VALUE (n);
635 my_friendly_abort (66);
639 #ifndef NO_DOLLAR_IN_LABEL
640 # define GLOBAL_THING "_GLOBAL_$"
642 # ifndef NO_DOT_IN_LABEL
643 # define GLOBAL_THING "_GLOBAL_."
645 # define GLOBAL_THING "_GLOBAL__"
649 #define GLOBAL_IORD_P(NODE) \
650 ! strncmp (IDENTIFIER_POINTER(NODE), GLOBAL_THING, sizeof (GLOBAL_THING) - 1)
656 char *name = IDENTIFIER_POINTER (t);
658 OB_PUTS ("(static ");
659 if (name [sizeof (GLOBAL_THING) - 1] == 'I')
660 OB_PUTS ("initializers");
661 else if (name [sizeof (GLOBAL_THING) - 1] == 'D')
662 OB_PUTS ("destructors");
664 my_friendly_abort (352);
667 OB_PUTCP (input_filename);
672 dump_simple_decl (t, type, v)
679 dump_type_prefix (type, v, 0);
682 if (CP_DECL_CONTEXT (t) != global_namespace)
684 dump_decl (DECL_CONTEXT (t), 0);
688 dump_decl (DECL_NAME (t), v);
692 dump_type_suffix (type, v, 0);
698 int v; /* verbosity */
703 switch (TREE_CODE (t))
706 OB_PUTS (" /* decl error */ ");
711 /* Don't say 'typedef class A' */
712 if (DECL_ARTIFICIAL (t))
714 if (v > 0 && TREE_CODE (TREE_TYPE (t)) == TEMPLATE_TYPE_PARM)
715 /* Say `class T' not just `T'. */
718 dump_type (TREE_TYPE (t), v);
723 OB_PUTS ("typedef ");
724 dump_simple_decl (t, DECL_ORIGINAL_TYPE (t)
725 ? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t), v);
729 if (DECL_NAME (t) && VTABLE_NAME_P (DECL_NAME (t)))
731 OB_PUTS ("vtable for ");
732 if (TYPE_P (DECL_CONTEXT (t)))
733 dump_type (DECL_CONTEXT (t), v);
735 /* This case can arise with -fno-vtable-thunks. See
736 expand_upcast_fixups. It's not clear what to print
738 OB_PUTS ("{unknown type}");
741 /* else fall through */
744 dump_simple_decl (t, TREE_TYPE (t), v);
748 if (CP_DECL_CONTEXT (t) != global_namespace)
750 dump_decl (DECL_CONTEXT (t), v);
753 if (DECL_NAME (t) == anonymous_namespace_name)
754 OB_PUTS ("{anonymous}");
756 OB_PUTID (DECL_NAME (t));
760 dump_decl (TREE_OPERAND (t, 0), 0);
762 dump_decl (TREE_OPERAND (t, 1), 0);
766 dump_decl (TREE_OPERAND (t, 0), v);
768 dump_decl (TREE_OPERAND (t, 1), v);
772 /* So that we can do dump_decl in dump_aggr_type and have it work for
773 both class and function scope. */
781 my_friendly_abort (69);
784 /* These special cases are duplicated here so that other functions
785 can feed identifiers to cp_error and get them demangled properly. */
786 case IDENTIFIER_NODE:
788 if (DESTRUCTOR_NAME_P (t)
789 && (f = ident_fndecl (t))
790 && DECL_LANGUAGE (f) == lang_cplusplus)
793 dump_decl (DECL_NAME (f), 0);
795 else if (IDENTIFIER_TYPENAME_P (t))
797 OB_PUTS ("operator ");
798 /* Not exactly IDENTIFIER_TYPE_VALUE. */
799 dump_type (TREE_TYPE (t), 0);
802 else if (IDENTIFIER_OPNAME_P (t))
804 char *name_string = operator_name_string (t);
805 OB_PUTS ("operator ");
806 OB_PUTCP (name_string);
814 if (GLOBAL_IORD_P (DECL_ASSEMBLER_NAME (t)))
815 dump_global_iord (DECL_ASSEMBLER_NAME (t));
816 else if (! DECL_LANG_SPECIFIC (t))
817 OB_PUTS ("{internal}");
819 dump_function_decl (t, v);
824 tree orig_args = DECL_TEMPLATE_PARMS (t);
827 for (args = orig_args = nreverse (orig_args);
829 args = TREE_CHAIN (args))
831 int len = TREE_VEC_LENGTH (TREE_VALUE (args));
833 OB_PUTS ("template <");
834 for (i = 0; i < len; i++)
836 tree arg = TREE_VEC_ELT (TREE_VALUE (args), i);
837 tree defval = TREE_PURPOSE (arg);
838 arg = TREE_VALUE (arg);
839 if (TREE_CODE (arg) == TYPE_DECL)
844 OB_PUTID (DECL_NAME (arg));
855 if (TREE_CODE (arg) == TYPE_DECL
856 || TREE_CODE (arg) == TEMPLATE_DECL)
857 dump_type (defval, 1);
859 dump_expr (defval, 1);
870 if (TREE_CODE (DECL_TEMPLATE_RESULT (t)) == TYPE_DECL)
871 dump_type (TREE_TYPE (t), v);
872 else if (TREE_CODE (DECL_TEMPLATE_RESULT (t)) == VAR_DECL)
873 dump_decl (DECL_TEMPLATE_RESULT (t), v);
874 else if (TREE_TYPE (t) == NULL_TREE)
875 my_friendly_abort (353);
876 else switch (NEXT_CODE (t))
880 dump_function_decl (t, v);
884 /* This case can occur with some illegal code. */
885 dump_type (TREE_TYPE (t), v);
890 case TEMPLATE_ID_EXPR:
893 tree name = TREE_OPERAND (t, 0);
894 if (is_overloaded_fn (name))
895 name = DECL_NAME (get_first_fn (name));
898 for (args = TREE_OPERAND (t, 1); args; args = TREE_CHAIN (args))
900 if (TREE_CODE_CLASS (TREE_CODE (TREE_VALUE (args))) == 't'
901 || TREE_CODE (TREE_VALUE (args)) == TEMPLATE_DECL)
902 dump_type (TREE_VALUE (args), 0);
904 dump_expr (TREE_VALUE (args), 0);
905 if (TREE_CHAIN (args))
913 dump_decl (TREE_OPERAND (t, 0), v);
917 OB_PUTID (DECL_NAME (t));
921 if ((TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == ENUMERAL_TYPE)
922 || (DECL_INITIAL (t) &&
923 TREE_CODE (DECL_INITIAL (t)) == TEMPLATE_PARM_INDEX))
924 dump_simple_decl (t, TREE_TYPE (t), v);
925 else if (DECL_NAME (t))
926 dump_decl (DECL_NAME (t), v);
927 else if (DECL_INITIAL (t))
928 dump_expr (DECL_INITIAL (t), 0);
930 OB_PUTS ("enumerator");
935 dump_type (DECL_INITIAL (t), 0);
937 OB_PUTID (DECL_NAME (t));
941 sorry ("`%s' not supported by dump_decl",
942 tree_code_name[(int) TREE_CODE (t)]);
946 /* Pretty printing for announce_function. T is the declaration of the
947 function we are interested in seeing. V is non-zero if we should print
948 the type that this function returns. */
951 dump_function_decl (t, v)
958 tree cname = NULL_TREE;
960 if (TREE_CODE (t) == TEMPLATE_DECL)
961 t = DECL_TEMPLATE_RESULT (t);
963 name = DECL_ASSEMBLER_NAME (t);
964 fntype = TREE_TYPE (t);
965 parmtypes = TYPE_ARG_TYPES (fntype);
967 /* Friends have DECL_CLASS_CONTEXT set, but not DECL_CONTEXT. */
968 if (DECL_CLASS_SCOPE_P (t))
969 cname = DECL_CLASS_CONTEXT (t);
970 /* this is for partially instantiated template methods */
971 else if (TREE_CODE (fntype) == METHOD_TYPE)
972 cname = TREE_TYPE (TREE_VALUE (parmtypes));
978 if (DECL_STATIC_FUNCTION_P (t))
981 if (! DECL_CONV_FN_P (t)
982 && ! DECL_CONSTRUCTOR_P (t)
983 && ! DECL_DESTRUCTOR_P (t))
985 dump_type_prefix (TREE_TYPE (fntype), 1, 0);
992 dump_type (cname, 0);
994 if (TREE_CODE (fntype) == METHOD_TYPE && parmtypes)
995 parmtypes = TREE_CHAIN (parmtypes);
996 if (DECL_CONSTRUCTOR_FOR_VBASE_P (t))
997 /* Skip past "in_charge" identifier. */
998 parmtypes = TREE_CHAIN (parmtypes);
1000 else if (CP_DECL_CONTEXT (t) != global_namespace)
1002 dump_decl (DECL_CONTEXT (t), 0);
1006 if (DESTRUCTOR_NAME_P (name) && DECL_LANGUAGE (t) == lang_cplusplus)
1007 parmtypes = TREE_CHAIN (parmtypes);
1009 dump_function_name (t);
1014 dump_type (parmtypes, v);
1020 if (v && ! DECL_CONV_FN_P (t))
1021 dump_type_suffix (TREE_TYPE (fntype), 1, 0);
1023 if (TREE_CODE (fntype) == METHOD_TYPE)
1025 if (IS_SIGNATURE (cname))
1026 /* We look at the type pointed to by the `optr' field of `this.' */
1028 (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_VALUE (TYPE_ARG_TYPES (fntype))))), before);
1031 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype))), before);
1035 /* Handle the function name for a FUNCTION_DECL node, grokking operators
1036 and destructors properly. */
1039 dump_function_name (t)
1042 tree name = DECL_NAME (t);
1044 if (DECL_DESTRUCTOR_P (t))
1047 dump_decl (name, 0);
1049 else if (DECL_CONV_FN_P (t))
1051 /* This cannot use the hack that the operator's return
1052 type is stashed off of its name because it may be
1053 used for error reporting. In the case of conflicting
1054 declarations, both will have the same name, yet
1055 the types will be different, hence the TREE_TYPE field
1056 of the first name will be clobbered by the second. */
1057 OB_PUTS ("operator ");
1058 dump_type (TREE_TYPE (TREE_TYPE (t)), 0);
1060 else if (IDENTIFIER_OPNAME_P (name))
1062 char *name_string = operator_name_string (name);
1063 OB_PUTS ("operator ");
1064 OB_PUTCP (name_string);
1067 dump_decl (name, 0);
1069 if (DECL_LANG_SPECIFIC (t) && DECL_USE_TEMPLATE (t)
1070 && DECL_TEMPLATE_INFO (t)
1071 && (DECL_TEMPLATE_SPECIALIZATION (t)
1072 || TREE_CODE (DECL_TI_TEMPLATE (t)) != TEMPLATE_DECL
1073 || DECL_TEMPLATE_SPECIALIZATION (DECL_TI_TEMPLATE (t))
1074 || PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t))))
1076 tree args = DECL_TEMPLATE_INFO (t) ? DECL_TI_ARGS (t) : NULL_TREE;
1079 /* Be careful only to print things when we have them, so as not
1080 to crash producing error messages. */
1083 if (TREE_CODE (args) == TREE_LIST)
1088 for (arg = args; arg; arg = TREE_CHAIN (arg))
1090 tree a = TREE_VALUE (arg);
1097 if (TREE_CODE_CLASS (TREE_CODE (a)) == 't'
1098 || TREE_CODE (a) == TEMPLATE_DECL)
1107 else if (TREE_CODE (args) == TREE_VEC)
1112 if (TREE_VEC_LENGTH (args) > 0
1113 && TREE_CODE (TREE_VEC_ELT (args, 0)) == TREE_VEC)
1114 args = TREE_VEC_ELT (args,
1115 TREE_VEC_LENGTH (args) - 1);
1117 for (i = 0; i < TREE_VEC_LENGTH (args); i++)
1119 tree a = TREE_VEC_ELT (args, i);
1126 if (TREE_CODE_CLASS (TREE_CODE (a)) == 't'
1127 || TREE_CODE (a) == TEMPLATE_DECL)
1147 case TARGET_NEWLINE:
1182 sprintf (digit_buffer, "\\%03o", (int) c);
1183 OB_PUTCP (digit_buffer);
1188 /* Print out a list of initializers (subr of dump_expr) */
1196 dump_expr (TREE_VALUE (l), 0);
1198 OB_PUTC2 (',', ' ');
1203 /* Print out an expression */
1208 int nop; /* suppress parens */
1210 switch (TREE_CODE (t))
1218 case NAMESPACE_DECL:
1224 tree type = TREE_TYPE (t);
1225 my_friendly_assert (type != 0, 81);
1227 /* If it's an enum, output its tag, rather than its value. */
1228 if (TREE_CODE (type) == ENUMERAL_TYPE)
1230 char *p = enum_name_string (t, type);
1233 else if (type == boolean_type_node)
1235 if (t == boolean_false_node
1236 || (TREE_INT_CST_LOW (t) == 0
1237 && TREE_INT_CST_HIGH (t) == 0))
1239 else if (t == boolean_true_node)
1242 else if (type == char_type_node)
1245 dump_char (TREE_INT_CST_LOW (t));
1248 else if (TREE_INT_CST_HIGH (t)
1249 != (TREE_INT_CST_LOW (t) >> (HOST_BITS_PER_WIDE_INT - 1)))
1252 if (TREE_INT_CST_HIGH (val) < 0)
1255 val = build_int_2 (~TREE_INT_CST_LOW (val),
1256 -TREE_INT_CST_HIGH (val));
1258 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
1261 static char format[10]; /* "%x%09999x\0" */
1263 sprintf (format, "%%x%%0%dx", HOST_BITS_PER_INT / 4);
1264 sprintf (digit_buffer, format, TREE_INT_CST_HIGH (val),
1265 TREE_INT_CST_LOW (val));
1266 OB_PUTCP (digit_buffer);
1270 OB_PUTI (TREE_INT_CST_LOW (t));
1275 #ifndef REAL_IS_NOT_DOUBLE
1276 sprintf (digit_buffer, "%g", TREE_REAL_CST (t));
1279 unsigned char *p = (unsigned char *) &TREE_REAL_CST (t);
1281 strcpy (digit_buffer, "0x");
1282 for (i = 0; i < sizeof TREE_REAL_CST (t); i++)
1283 sprintf (digit_buffer + 2 + 2*i, "%02x", *p++);
1286 OB_PUTCP (digit_buffer);
1291 dump_type (PTRMEM_CST_CLASS (t), 0);
1293 OB_PUTID (DECL_NAME (PTRMEM_CST_MEMBER (t)));
1298 char *p = TREE_STRING_POINTER (t);
1299 int len = TREE_STRING_LENGTH (t) - 1;
1303 for (i = 0; i < len; i++)
1310 dump_binary_op (",", t);
1315 dump_expr (TREE_OPERAND (t, 0), 0);
1317 dump_expr (TREE_OPERAND (t, 1), 0);
1319 dump_expr (TREE_OPERAND (t, 2), 0);
1324 if (TREE_HAS_CONSTRUCTOR (t))
1327 dump_type (TREE_TYPE (TREE_TYPE (t)), 0);
1328 PARM_DECL_EXPR (t) = 1;
1332 dump_expr (TREE_OPERAND (t, 0), 0);
1336 case AGGR_INIT_EXPR:
1337 OB_PUTID (TYPE_IDENTIFIER (TREE_TYPE (t)));
1339 if (TREE_OPERAND (t, 1))
1340 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)));
1346 tree fn = TREE_OPERAND (t, 0);
1347 tree args = TREE_OPERAND (t, 1);
1349 if (TREE_CODE (fn) == ADDR_EXPR)
1350 fn = TREE_OPERAND (fn, 0);
1352 if (TREE_TYPE (fn) != NULL_TREE && NEXT_CODE (fn) == METHOD_TYPE)
1354 tree ob = TREE_VALUE (args);
1355 if (TREE_CODE (ob) == ADDR_EXPR)
1357 dump_expr (TREE_OPERAND (ob, 0), 0);
1360 else if (TREE_CODE (ob) != PARM_DECL
1361 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
1364 OB_PUTC2 ('-', '>');
1366 args = TREE_CHAIN (args);
1370 dump_expr_list (args);
1377 tree type = TREE_OPERAND (t, 1);
1378 if (NEW_EXPR_USE_GLOBAL (t))
1381 if (TREE_OPERAND (t, 0))
1384 dump_expr_list (TREE_OPERAND (t, 0));
1387 if (TREE_CODE (type) == ARRAY_REF)
1388 type = build_cplus_array_type
1389 (TREE_OPERAND (type, 0),
1390 build_index_type (size_binop (MINUS_EXPR, TREE_OPERAND (type, 1),
1391 integer_one_node)));
1392 dump_type (type, 0);
1393 if (TREE_OPERAND (t, 2))
1396 dump_expr_list (TREE_OPERAND (t, 2));
1403 /* Note that this only works for G++ target exprs. If somebody
1404 builds a general TARGET_EXPR, there's no way to represent that
1405 it initializes anything other that the parameter slot for the
1406 default argument. Note we may have cleared out the first
1407 operand in expand_expr, so don't go killing ourselves. */
1408 if (TREE_OPERAND (t, 1))
1409 dump_expr (TREE_OPERAND (t, 1), 0);
1416 case TRUNC_DIV_EXPR:
1417 case TRUNC_MOD_EXPR:
1425 case BIT_ANDTC_EXPR:
1426 case TRUTH_ANDIF_EXPR:
1427 case TRUTH_ORIF_EXPR:
1434 dump_binary_op (opname_tab[(int) TREE_CODE (t)], t);
1438 case FLOOR_DIV_EXPR:
1439 case ROUND_DIV_EXPR:
1440 dump_binary_op ("/", t);
1444 case FLOOR_MOD_EXPR:
1445 case ROUND_MOD_EXPR:
1446 dump_binary_op ("%", t);
1451 tree ob = TREE_OPERAND (t, 0);
1452 if (TREE_CODE (ob) == INDIRECT_REF)
1454 ob = TREE_OPERAND (ob, 0);
1455 if (TREE_CODE (ob) != PARM_DECL
1456 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
1459 OB_PUTC2 ('-', '>');
1467 dump_expr (TREE_OPERAND (t, 1), 1);
1472 dump_expr (TREE_OPERAND (t, 0), 0);
1474 dump_expr (TREE_OPERAND (t, 1), 0);
1479 dump_unary_op ("+", t, nop);
1483 if (TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
1484 || TREE_CODE (TREE_OPERAND (t, 0)) == STRING_CST)
1485 dump_expr (TREE_OPERAND (t, 0), 0);
1487 dump_unary_op ("&", t, nop);
1491 if (TREE_HAS_CONSTRUCTOR (t))
1493 t = TREE_OPERAND (t, 0);
1494 my_friendly_assert (TREE_CODE (t) == CALL_EXPR, 237);
1495 dump_expr (TREE_OPERAND (t, 0), 0);
1497 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)));
1502 if (TREE_OPERAND (t,0) != NULL_TREE
1503 && NEXT_CODE (TREE_OPERAND (t, 0)) == REFERENCE_TYPE)
1504 dump_expr (TREE_OPERAND (t, 0), nop);
1506 dump_unary_op ("*", t, nop);
1512 case TRUTH_NOT_EXPR:
1513 case PREDECREMENT_EXPR:
1514 case PREINCREMENT_EXPR:
1515 dump_unary_op (opname_tab [(int)TREE_CODE (t)], t, nop);
1518 case POSTDECREMENT_EXPR:
1519 case POSTINCREMENT_EXPR:
1521 dump_expr (TREE_OPERAND (t, 0), 0);
1522 OB_PUTCP (opname_tab[(int)TREE_CODE (t)]);
1526 case NON_LVALUE_EXPR:
1527 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
1528 should be another level of INDIRECT_REF so that I don't have to do
1530 if (TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == POINTER_TYPE)
1532 tree next = TREE_TYPE (TREE_TYPE (t));
1534 while (TREE_CODE (next) == POINTER_TYPE)
1535 next = TREE_TYPE (next);
1537 if (TREE_CODE (next) == FUNCTION_TYPE)
1539 if (!nop) OB_PUTC ('(');
1541 dump_expr (TREE_OPERAND (t, 0), 1);
1542 if (!nop) OB_PUTC (')');
1547 dump_expr (TREE_OPERAND (t, 0), 0);
1551 dump_expr (TREE_OPERAND (t, 0), nop);
1555 if (TREE_TYPE (t) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t)))
1557 tree idx = build_component_ref (t, index_identifier, NULL_TREE, 0);
1559 if (integer_all_onesp (idx))
1561 tree pfn = PFN_FROM_PTRMEMFUNC (t);
1565 if (TREE_CODE (idx) == INTEGER_CST
1566 && TREE_INT_CST_HIGH (idx) == 0)
1569 unsigned HOST_WIDE_INT n;
1571 t = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t)));
1572 t = TYPE_METHOD_BASETYPE (t);
1573 virtuals = BINFO_VIRTUALS (TYPE_BINFO (TYPE_MAIN_VARIANT (t)));
1575 n = TREE_INT_CST_LOW (idx);
1577 /* Map vtable index back one, to allow for the null pointer to
1581 while (n > 0 && virtuals)
1584 virtuals = TREE_CHAIN (virtuals);
1588 dump_expr (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals)), 0);
1594 dump_expr_list (CONSTRUCTOR_ELTS (t));
1600 tree ob = TREE_OPERAND (t, 0);
1601 if (is_dummy_object (ob))
1603 if (TREE_CODE (TREE_OPERAND (t, 1)) == FUNCTION_DECL)
1605 dump_expr (TREE_OPERAND (t, 1), 0);
1607 dump_decl (TREE_OPERAND (t, 1), 0);
1611 dump_expr (TREE_OPERAND (t, 0), 0);
1613 dump_expr (TREE_OPERAND (t, 1), 0);
1618 case TEMPLATE_PARM_INDEX:
1619 dump_decl (TEMPLATE_PARM_DECL (t), -1);
1622 case IDENTIFIER_NODE:
1627 dump_type (TREE_OPERAND (t, 0), 0);
1629 dump_expr (TREE_OPERAND (t, 1), 0);
1633 if (TREE_OPERAND (t, 0) == NULL_TREE
1634 || TREE_CHAIN (TREE_OPERAND (t, 0)))
1636 dump_type (TREE_TYPE (t), 0);
1638 dump_expr_list (TREE_OPERAND (t, 0));
1644 dump_type (TREE_TYPE (t), 0);
1647 dump_expr_list (TREE_OPERAND (t, 0));
1653 OB_PUTID (TREE_OPERAND (t, 0));
1657 dump_expr (TREE_OPERAND (t, 0), nop);
1663 if (TREE_CODE (t) == SIZEOF_EXPR)
1664 OB_PUTS ("sizeof (");
1667 my_friendly_assert (TREE_CODE (t) == ALIGNOF_EXPR, 0);
1668 OB_PUTS ("__alignof__ (");
1670 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t, 0))) == 't')
1671 dump_type (TREE_OPERAND (t, 0), 0);
1673 dump_unary_op ("*", t, 0);
1678 OB_PUTS ("{unparsed}");
1681 case TRY_CATCH_EXPR:
1682 case WITH_CLEANUP_EXPR:
1683 case CLEANUP_POINT_EXPR:
1684 dump_expr (TREE_OPERAND (t, 0), nop);
1688 if (TREE_VALUE (t) && TREE_CODE (TREE_VALUE (t)) == FUNCTION_DECL)
1690 OB_PUTID (DECL_NAME (TREE_VALUE (t)));
1693 /* else fall through */
1695 /* This list is incomplete, but should suffice for now.
1696 It is very important that `sorry' does not call
1697 `report_error_function'. That could cause an infinite loop. */
1699 sorry ("`%s' not supported by dump_expr",
1700 tree_code_name[(int) TREE_CODE (t)]);
1702 /* fall through to ERROR_MARK... */
1704 OB_PUTCP ("{error}");
1710 dump_binary_op (opstring, t)
1715 dump_expr (TREE_OPERAND (t, 0), 1);
1717 OB_PUTCP (opstring);
1719 dump_expr (TREE_OPERAND (t, 1), 1);
1724 dump_unary_op (opstring, t, nop)
1729 if (!nop) OB_PUTC ('(');
1730 OB_PUTCP (opstring);
1731 dump_expr (TREE_OPERAND (t, 0), 1);
1732 if (!nop) OB_PUTC (')');
1736 fndecl_as_string (fndecl, print_ret_type_p)
1738 int print_ret_type_p;
1740 return decl_as_string (fndecl, print_ret_type_p);
1743 /* Same, but handle a _TYPE.
1744 Called from convert_to_reference, mangle_class_name_for_template,
1745 build_unary_op, and GNU_xref_decl. If CANONICAL_NAME is non-zero,
1746 when describing a typedef, we use the name of the type described,
1747 rather than the name of the typedef. */
1750 type_as_string_real (typ, v, canonical_name)
1757 dump_type_real (typ, v, canonical_name);
1761 return (char *)obstack_base (&scratch_obstack);
1766 type_as_string (typ, v)
1770 return type_as_string_real (typ, v, 0);
1774 expr_as_string (decl, v)
1776 int v ATTRIBUTE_UNUSED;
1780 dump_expr (decl, 1);
1784 return (char *)obstack_base (&scratch_obstack);
1787 /* A cross between type_as_string and fndecl_as_string.
1788 Only called from substitute_nice_name. */
1791 decl_as_string (decl, v)
1797 dump_decl (decl, v);
1801 return (char *)obstack_base (&scratch_obstack);
1804 /* Generate the three forms of printable names for lang_printable_name. */
1807 lang_decl_name (decl, v)
1812 return decl_as_string (decl, 1);
1816 if (v == 1 && DECL_CLASS_SCOPE_P (decl))
1819 if (TREE_CODE (decl) == FUNCTION_DECL)
1820 cname = DECL_CLASS_CONTEXT (decl);
1822 cname = DECL_CONTEXT (decl);
1823 dump_type (cname, 0);
1824 OB_PUTC2 (':', ':');
1827 if (TREE_CODE (decl) == FUNCTION_DECL)
1828 dump_function_name (decl);
1830 dump_decl (DECL_NAME (decl), 0);
1834 return (char *)obstack_base (&scratch_obstack);
1842 if (TREE_CODE (t) == PARM_DECL && DECL_CONTEXT (t))
1843 return DECL_SOURCE_FILE (DECL_CONTEXT (t));
1844 else if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
1845 return DECL_SOURCE_FILE (TYPE_MAIN_DECL (t));
1847 return DECL_SOURCE_FILE (t);
1855 if (TREE_CODE (t) == PARM_DECL && DECL_CONTEXT (t))
1856 line = DECL_SOURCE_LINE (DECL_CONTEXT (t));
1857 if (TREE_CODE (t) == TYPE_DECL && DECL_ARTIFICIAL (t)
1858 && TYPE_MAIN_DECL (TREE_TYPE (t)))
1861 if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
1862 line = DECL_SOURCE_LINE (TYPE_MAIN_DECL (t));
1864 line = DECL_SOURCE_LINE (t);
1873 code_as_string (c, v)
1875 int v ATTRIBUTE_UNUSED;
1877 return tree_code_name [c];
1881 language_as_string (c, v)
1883 int v ATTRIBUTE_UNUSED;
1890 case lang_cplusplus:
1897 my_friendly_abort (355);
1902 /* Return the proper printed version of a parameter to a C++ function. */
1905 parm_as_string (p, v)
1907 int v ATTRIBUTE_UNUSED;
1912 sprintf (digit_buffer, "%d", p+1);
1913 return digit_buffer;
1919 int v ATTRIBUTE_UNUSED;
1921 static char buf[] = "operator ";
1926 strcpy (buf + 9, opname_tab [p]);
1931 assop_as_string (p, v)
1933 int v ATTRIBUTE_UNUSED;
1935 static char buf[] = "operator ";
1940 strcpy (buf + 9, assignop_tab [p]);
1945 args_as_string (p, v)
1952 if (TREE_CODE_CLASS (TREE_CODE (TREE_VALUE (p))) == 't')
1953 return type_as_string (p, v);
1956 for (; p; p = TREE_CHAIN (p))
1958 if (TREE_VALUE (p) == null_node)
1961 dump_type (error_type (TREE_VALUE (p)), v);
1966 return (char *)obstack_base (&scratch_obstack);
1972 int v ATTRIBUTE_UNUSED;
1976 dump_qualifiers (p, before);
1980 return (char *)obstack_base (&scratch_obstack);