1 /* Call-backs for C++ error reporting.
2 This code is non-reentrant.
3 Copyright (C) 1993, 94-97, 1998, 1999 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 F fndecl_as_string
36 #define L language_as_string
37 #define O op_as_string
38 #define P parm_as_string
39 #define Q assop_as_string
40 #define T type_as_string
41 #define V cv_as_string
43 #define o (cp_printer *) 0
44 cp_printer * cp_printers[256] =
46 /*0 1 2 3 4 5 6 7 8 9 A B C D E F */
47 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x00 */
48 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x10 */
49 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x20 */
50 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x30 */
51 o, A, o, C, D, E, F, o, o, o, o, o, L, o, o, O, /* 0x40 */
52 P, Q, o, o, T, o, V, o, o, o, o, o, o, o, o, o, /* 0x50 */
53 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x60 */
54 o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, o, /* 0x70 */
68 #define obstack_chunk_alloc xmalloc
69 #define obstack_chunk_free free
71 /* Obstack where we build text strings for overloading, etc. */
72 static struct obstack scratch_obstack;
73 static char *scratch_firstobj;
75 # define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
76 # define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
77 # define OB_PUTC2(C1,C2) \
78 (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
79 # define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
80 # define OB_PUTID(ID) \
81 (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \
82 IDENTIFIER_LENGTH (ID)))
83 # define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
84 # define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
85 # define OB_PUTI(CST) do { sprintf (digit_buffer, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT)(CST)); \
86 OB_PUTCP (digit_buffer); } while (0)
87 # define OB_UNPUT(N) obstack_blank (&scratch_obstack, - (N));
89 # define OB_END_TEMPLATE_ID() \
90 ((obstack_next_free (&scratch_obstack) != obstack_base (&scratch_obstack) \
91 && obstack_next_free (&scratch_obstack)[-1] == '>') \
92 ? OB_PUTC2 (' ', '>') : OB_PUTC ('>'))
94 # define NEXT_CODE(t) (TREE_CODE (TREE_TYPE (t)))
96 enum pad { none, before, after };
98 static void dump_type PROTO((tree, int));
99 static void dump_type_real PROTO((tree, int, int));
100 static void dump_simple_decl PROTO((tree, tree, int));
101 static void dump_decl PROTO((tree, int));
102 static void dump_function_decl PROTO((tree, int));
103 static void dump_expr PROTO((tree, int));
104 static void dump_unary_op PROTO((char *, tree, int));
105 static void dump_binary_op PROTO((char *, tree));
106 static void dump_aggr_type PROTO((tree, int, int));
107 static void dump_type_prefix PROTO((tree, int, int));
108 static void dump_type_suffix PROTO((tree, int, int));
109 static void dump_function_name PROTO((tree));
110 static void dump_expr_list PROTO((tree));
111 static void dump_global_iord PROTO((tree));
112 static void dump_qualifiers PROTO((tree, enum pad));
113 static void dump_char PROTO((int));
114 static void dump_parameters PROTO((tree, int, int));
115 static void dump_exception_spec PROTO((tree, int));
116 static char *aggr_variety PROTO((tree));
117 static tree ident_fndecl PROTO((tree));
118 static int interesting_scope_p PROTO((tree));
123 gcc_obstack_init (&scratch_obstack);
124 scratch_firstobj = (char *)obstack_alloc (&scratch_obstack, 0);
127 /* Returns nonzero if SCOPE is something we want to print for random decls. */
130 interesting_scope_p (scope)
133 if (scope == NULL_TREE
134 || scope == global_namespace)
137 return (TREE_CODE (scope) == NAMESPACE_DECL
138 || AGGREGATE_TYPE_P (scope));
142 dump_qualifiers (t, p)
148 if (p == before) OB_PUTC (' ');
149 switch (TYPE_QUALS (t))
151 case TYPE_QUAL_CONST:
155 case TYPE_QUAL_VOLATILE:
156 OB_PUTS ("volatile");
159 case TYPE_QUAL_RESTRICT:
160 OB_PUTS ("__restrict");
163 case TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE:
164 OB_PUTS ("const volatile");
167 case TYPE_QUAL_CONST | TYPE_QUAL_RESTRICT:
168 OB_PUTS ("const __restrict");
171 case TYPE_QUAL_VOLATILE | TYPE_QUAL_RESTRICT:
172 OB_PUTS ("volatile __restrict");
175 case TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE | TYPE_QUAL_RESTRICT:
176 OB_PUTS ("const volatile __restrict");
180 my_friendly_abort (0);
182 if (p == after) OB_PUTC (' ');
186 /* This must be large enough to hold any printed integer or floating-point
188 static char digit_buffer[128];
190 /* Dump into the obstack a human-readable equivalent of TYPE. */
193 dump_type_real (t, v, canonical_name)
195 int v; /* verbose? */
201 if (TYPE_PTRMEMFUNC_P (t))
204 switch (TREE_CODE (t))
211 OB_PUTS ("{unknown type}");
215 /* A list of function parms. */
216 dump_parameters (t, 0, canonical_name);
219 case IDENTIFIER_NODE:
224 dump_type_real (BINFO_TYPE (t), v, canonical_name);
230 if (TYPE_LANG_SPECIFIC (t)
231 && (IS_SIGNATURE_POINTER (t) || IS_SIGNATURE_REFERENCE (t)))
233 dump_qualifiers (t, after);
234 dump_type_real (SIGNATURE_TYPE (t), v, canonical_name);
235 if (IS_SIGNATURE_POINTER (t))
241 dump_aggr_type (t, v, canonical_name);
251 OB_PUTS ("complex ");
252 dump_type_real (TREE_TYPE (t), v, canonical_name);
256 if (!TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)) && TREE_UNSIGNED (t))
257 OB_PUTS ("unsigned ");
258 else if (TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)) && !TREE_UNSIGNED (t))
267 dump_qualifiers (t, after);
268 type = canonical_name ? TYPE_MAIN_VARIANT (t) : t;
269 if (TYPE_NAME (type) && TYPE_IDENTIFIER (type))
270 OB_PUTID (TYPE_IDENTIFIER (type));
272 /* Types like intQI_type_node and friends have no names.
273 These don't come up in user error messages, but it's nice
274 to be able to print them from the debugger. */
275 OB_PUTS ("{anonymous}");
279 case TEMPLATE_TEMPLATE_PARM:
280 if (!TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t))
282 /* For parameters inside template signature. */
283 if (TYPE_IDENTIFIER (t))
284 OB_PUTID (TYPE_IDENTIFIER (t));
286 OB_PUTS ("{anonymous template template parm}");
291 tree args = TYPE_TI_ARGS (t);
292 OB_PUTID (TYPE_IDENTIFIER (t));
294 for (i = 0; i < TREE_VEC_LENGTH (args); i++)
296 tree arg = TREE_VEC_ELT (args, i);
297 if (TREE_CODE_CLASS (TREE_CODE (arg)) == 't'
298 || TREE_CODE (arg) == TEMPLATE_DECL)
299 dump_type_real (arg, 0, canonical_name);
302 if (i < TREE_VEC_LENGTH (args)-1)
305 OB_END_TEMPLATE_ID ();
309 case TEMPLATE_TYPE_PARM:
310 dump_qualifiers (t, after);
311 if (TYPE_IDENTIFIER (t))
312 OB_PUTID (TYPE_IDENTIFIER (t));
314 OB_PUTS ("{anonymous template type parm}");
317 /* This is not always necessary for pointers and such, but doing this
318 reduces code size. */
326 dump_type_prefix (t, v, canonical_name);
327 dump_type_suffix (t, v, canonical_name);
331 OB_PUTS ("typename ");
332 dump_type_real (TYPE_CONTEXT (t), 0, canonical_name);
334 dump_decl (TYPENAME_TYPE_FULLNAME (t), v);
338 OB_PUTS ("__typeof (");
339 dump_expr (TYPE_FIELDS (t), 1);
344 sorry ("`%s' not supported by dump_type",
345 tree_code_name[(int) TREE_CODE (t)]);
353 if (TREE_CODE (t) == ENUMERAL_TYPE)
355 else if (TREE_CODE (t) == UNION_TYPE)
357 else if (TYPE_LANG_SPECIFIC (t) && CLASSTYPE_DECLARED_CLASS (t))
359 else if (TYPE_LANG_SPECIFIC (t) && IS_SIGNATURE (t))
368 int v; /* verbose? */
370 dump_type_real (t, v, 0);
373 /* Print out a class declaration, in the form `class foo'. */
376 dump_aggr_type (t, v, canonical_name)
378 int v; /* verbose? */
382 char *variety = aggr_variety (t);
384 dump_qualifiers (t, after);
392 name = TYPE_NAME (canonical_name ? TYPE_MAIN_VARIANT (t) : t);
394 if (name && CP_DECL_CONTEXT (name) != global_namespace)
396 /* FUNCTION_DECL or RECORD_TYPE */
397 dump_decl (DECL_CONTEXT (name), 0);
401 /* kludge around weird behavior on g++.brendan/line1.C */
402 if (name && TREE_CODE (name) != IDENTIFIER_NODE)
403 name = DECL_NAME (name);
405 if (name == 0 || ANON_AGGRNAME_P (name))
407 OB_PUTS ("{anonymous");
419 /* Dump into the obstack the initial part of the output for a given type.
420 This is necessary when dealing with things like functions returning
423 return type of `int (* fee ())()': pointer -> function -> int. Both
424 pointer (and reference and offset) and function (and member) types must
425 deal with prefix and suffix.
427 Arrays must also do this for DECL nodes, like int a[], and for things like
431 dump_type_prefix (t, v, canonical_name)
433 int v; /* verbosity */
436 if (TYPE_PTRMEMFUNC_P (t))
438 t = TYPE_PTRMEMFUNC_FN_TYPE (t);
442 switch (TREE_CODE (t))
447 tree sub = TREE_TYPE (t);
449 dump_type_prefix (sub, v, canonical_name);
450 /* A tree for a member pointer looks like pointer to offset,
451 so let the OFFSET_TYPE case handle it. */
452 if (!TYPE_PTRMEM_P (t))
454 switch (TREE_CODE (sub))
456 /* We don't want int ( *)() */
466 /* We don't want "char * *" */
467 if (TYPE_QUALS (sub) == TYPE_UNQUALIFIED)
469 /* But we do want "char *const *" */
474 if (TREE_CODE (t) == POINTER_TYPE)
478 dump_qualifiers (t, none);
485 dump_type_prefix (TREE_TYPE (t), v, canonical_name);
486 if (TREE_CODE (t) == OFFSET_TYPE) /* pmfs deal with this in d_t_p */
489 dump_type_real (TYPE_OFFSET_BASETYPE (t), 0, canonical_name);
493 dump_qualifiers (t, none);
496 /* Can only be reached through function pointer -- this would not be
497 correct if FUNCTION_DECLs used it. */
499 dump_type_prefix (TREE_TYPE (t), v, canonical_name);
504 dump_type_prefix (TREE_TYPE (t), v, canonical_name);
506 dump_aggr_type (TYPE_METHOD_BASETYPE (t), 0, canonical_name);
511 dump_type_prefix (TREE_TYPE (t), v, canonical_name);
516 case IDENTIFIER_NODE:
521 case TEMPLATE_TYPE_PARM:
522 case TEMPLATE_TEMPLATE_PARM:
531 dump_type_real (t, v, canonical_name);
535 sorry ("`%s' not supported by dump_type_prefix",
536 tree_code_name[(int) TREE_CODE (t)]);
541 dump_type_suffix (t, v, canonical_name)
543 int v; /* verbose? */
546 if (TYPE_PTRMEMFUNC_P (t))
547 t = TYPE_PTRMEMFUNC_FN_TYPE (t);
549 switch (TREE_CODE (t))
554 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
556 dump_type_suffix (TREE_TYPE (t), v, canonical_name);
559 /* Can only be reached through function pointer */
565 arg = TYPE_ARG_TYPES (t);
566 if (TREE_CODE (t) == METHOD_TYPE)
567 arg = TREE_CHAIN (arg);
569 /* Function pointers don't have default args. Not in standard C++,
570 anyway; they may in g++, but we'll just pretend otherwise. */
571 dump_parameters (arg, 0, canonical_name);
573 if (TREE_CODE (t) == METHOD_TYPE)
575 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t))), before);
576 dump_type_suffix (TREE_TYPE (t), v, canonical_name);
577 dump_exception_spec (TYPE_RAISES_EXCEPTIONS (t), canonical_name);
585 if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (t))) == INTEGER_CST)
586 OB_PUTI (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (t))) + 1);
587 else if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (t))) == MINUS_EXPR)
588 dump_expr (TREE_OPERAND (TYPE_MAX_VALUE (TYPE_DOMAIN (t)), 0), 0);
590 dump_expr (fold (build_binary_op
591 (PLUS_EXPR, TYPE_MAX_VALUE (TYPE_DOMAIN (t)),
592 integer_one_node)), 0);
595 dump_type_suffix (TREE_TYPE (t), v, canonical_name);
600 case IDENTIFIER_NODE:
605 case TEMPLATE_TYPE_PARM:
606 case TEMPLATE_TEMPLATE_PARM:
618 sorry ("`%s' not supported by dump_type_suffix",
619 tree_code_name[(int) TREE_CODE (t)]);
623 /* Return a function declaration which corresponds to the IDENTIFIER_NODE
630 tree n = lookup_name (t, 0);
635 if (TREE_CODE (n) == FUNCTION_DECL)
637 else if (TREE_CODE (n) == TREE_LIST
638 && TREE_CODE (TREE_VALUE (n)) == FUNCTION_DECL)
639 return TREE_VALUE (n);
641 my_friendly_abort (66);
645 #ifndef NO_DOLLAR_IN_LABEL
646 # define GLOBAL_THING "_GLOBAL_$"
648 # ifndef NO_DOT_IN_LABEL
649 # define GLOBAL_THING "_GLOBAL_."
651 # define GLOBAL_THING "_GLOBAL__"
655 #define GLOBAL_IORD_P(NODE) \
656 ! strncmp (IDENTIFIER_POINTER(NODE), GLOBAL_THING, sizeof (GLOBAL_THING) - 1)
662 char *name = IDENTIFIER_POINTER (t);
664 OB_PUTS ("(static ");
665 if (name [sizeof (GLOBAL_THING) - 1] == 'I')
666 OB_PUTS ("initializers");
667 else if (name [sizeof (GLOBAL_THING) - 1] == 'D')
668 OB_PUTS ("destructors");
670 my_friendly_abort (352);
673 OB_PUTCP (input_filename);
678 dump_simple_decl (t, type, v)
685 dump_type_prefix (type, v, 0);
688 if (interesting_scope_p (DECL_CONTEXT (t)))
690 dump_decl (DECL_CONTEXT (t), 0);
694 dump_decl (DECL_NAME (t), v);
698 dump_type_suffix (type, v, 0);
704 int v; /* verbosity */
709 switch (TREE_CODE (t))
712 OB_PUTS (" /* decl error */ ");
717 /* Don't say 'typedef class A' */
718 if (DECL_ARTIFICIAL (t))
720 if (v > 0 && TREE_CODE (TREE_TYPE (t)) == TEMPLATE_TYPE_PARM)
721 /* Say `class T' not just `T'. */
724 dump_type (TREE_TYPE (t), v);
729 OB_PUTS ("typedef ");
730 dump_simple_decl (t, DECL_ORIGINAL_TYPE (t)
731 ? DECL_ORIGINAL_TYPE (t) : TREE_TYPE (t), v);
735 if (DECL_NAME (t) && VTABLE_NAME_P (DECL_NAME (t)))
737 OB_PUTS ("vtable for ");
738 if (TYPE_P (DECL_CONTEXT (t)))
739 dump_type (DECL_CONTEXT (t), v);
741 /* This case can arise with -fno-vtable-thunks. See
742 expand_upcast_fixups. It's not clear what to print
744 OB_PUTS ("{unknown type}");
747 /* else fall through */
750 dump_simple_decl (t, TREE_TYPE (t), v);
754 if (CP_DECL_CONTEXT (t) != global_namespace)
756 dump_decl (DECL_CONTEXT (t), v);
759 if (DECL_NAME (t) == anonymous_namespace_name)
760 OB_PUTS ("{anonymous}");
762 OB_PUTID (DECL_NAME (t));
766 dump_decl (TREE_OPERAND (t, 0), 0);
768 dump_decl (TREE_OPERAND (t, 1), 0);
772 dump_decl (TREE_OPERAND (t, 0), v);
774 dump_decl (TREE_OPERAND (t, 1), v);
778 /* So that we can do dump_decl in dump_aggr_type and have it work for
779 both class and function scope. */
787 my_friendly_abort (69);
790 /* These special cases are duplicated here so that other functions
791 can feed identifiers to cp_error and get them demangled properly. */
792 case IDENTIFIER_NODE:
794 if (DESTRUCTOR_NAME_P (t)
795 && (f = ident_fndecl (t))
796 && DECL_LANGUAGE (f) == lang_cplusplus)
799 dump_decl (DECL_NAME (f), 0);
801 else if (IDENTIFIER_TYPENAME_P (t))
803 OB_PUTS ("operator ");
804 /* Not exactly IDENTIFIER_TYPE_VALUE. */
805 dump_type (TREE_TYPE (t), 0);
808 else if (IDENTIFIER_OPNAME_P (t))
810 char *name_string = operator_name_string (t);
811 OB_PUTS ("operator ");
812 OB_PUTCP (name_string);
824 if (GLOBAL_IORD_P (DECL_ASSEMBLER_NAME (t)))
825 dump_global_iord (DECL_ASSEMBLER_NAME (t));
826 else if (! DECL_LANG_SPECIFIC (t))
827 OB_PUTS ("{internal}");
829 dump_function_decl (t, v);
834 tree orig_args = DECL_TEMPLATE_PARMS (t);
837 for (args = orig_args = nreverse (orig_args);
839 args = TREE_CHAIN (args))
841 int len = TREE_VEC_LENGTH (TREE_VALUE (args));
843 OB_PUTS ("template <");
844 for (i = 0; i < len; i++)
846 tree arg = TREE_VEC_ELT (TREE_VALUE (args), i);
847 tree defval = TREE_PURPOSE (arg);
848 arg = TREE_VALUE (arg);
849 if (TREE_CODE (arg) == TYPE_DECL)
854 OB_PUTID (DECL_NAME (arg));
865 if (TREE_CODE (arg) == TYPE_DECL
866 || TREE_CODE (arg) == TEMPLATE_DECL)
867 dump_type (defval, 1);
869 dump_expr (defval, 1);
876 OB_END_TEMPLATE_ID ();
881 if (TREE_CODE (DECL_TEMPLATE_RESULT (t)) == TYPE_DECL)
882 dump_type (TREE_TYPE (t), v);
883 else if (TREE_CODE (DECL_TEMPLATE_RESULT (t)) == VAR_DECL)
884 dump_decl (DECL_TEMPLATE_RESULT (t), v);
885 else if (TREE_TYPE (t) == NULL_TREE)
886 my_friendly_abort (353);
887 else switch (NEXT_CODE (t))
891 dump_function_decl (t, v);
895 /* This case can occur with some illegal code. */
896 dump_type (TREE_TYPE (t), v);
901 case TEMPLATE_ID_EXPR:
904 tree name = TREE_OPERAND (t, 0);
905 if (is_overloaded_fn (name))
906 name = DECL_NAME (get_first_fn (name));
909 for (args = TREE_OPERAND (t, 1); args; args = TREE_CHAIN (args))
911 if (TREE_CODE_CLASS (TREE_CODE (TREE_VALUE (args))) == 't'
912 || TREE_CODE (TREE_VALUE (args)) == TEMPLATE_DECL)
913 dump_type (TREE_VALUE (args), 0);
915 dump_expr (TREE_VALUE (args), 0);
916 if (TREE_CHAIN (args))
919 OB_END_TEMPLATE_ID ();
924 dump_decl (TREE_OPERAND (t, 0), v);
928 OB_PUTID (DECL_NAME (t));
932 if ((TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == ENUMERAL_TYPE)
933 || (DECL_INITIAL (t) &&
934 TREE_CODE (DECL_INITIAL (t)) == TEMPLATE_PARM_INDEX))
935 dump_simple_decl (t, TREE_TYPE (t), v);
936 else if (DECL_NAME (t))
937 dump_decl (DECL_NAME (t), v);
938 else if (DECL_INITIAL (t))
939 dump_expr (DECL_INITIAL (t), 0);
941 OB_PUTS ("enumerator");
946 dump_type (DECL_INITIAL (t), 0);
948 OB_PUTID (DECL_NAME (t));
952 sorry ("`%s' not supported by dump_decl",
953 tree_code_name[(int) TREE_CODE (t)]);
957 /* Pretty print a function decl. There are several ways we want to print a
958 function declaration. We use V to tell us what.
964 As cp_error can only apply the '#' flag once to give 0 and 1 for V, there
965 is %D which doesn't print the throw specs, and %F which does. */
968 dump_function_decl (t, v)
975 tree cname = NULL_TREE;
977 if (TREE_CODE (t) == TEMPLATE_DECL)
978 t = DECL_TEMPLATE_RESULT (t);
980 name = DECL_ASSEMBLER_NAME (t);
981 fntype = TREE_TYPE (t);
982 parmtypes = TYPE_ARG_TYPES (fntype);
984 /* Friends have DECL_CLASS_CONTEXT set, but not DECL_CONTEXT. */
985 if (DECL_CLASS_SCOPE_P (t))
986 cname = DECL_CLASS_CONTEXT (t);
987 /* this is for partially instantiated template methods */
988 else if (TREE_CODE (fntype) == METHOD_TYPE)
989 cname = TREE_TYPE (TREE_VALUE (parmtypes));
991 /* Print the return type. */
994 if (DECL_STATIC_FUNCTION_P (t))
997 if (! DECL_CONV_FN_P (t)
998 && ! DECL_CONSTRUCTOR_P (t)
999 && ! DECL_DESTRUCTOR_P (t))
1001 dump_type_prefix (TREE_TYPE (fntype), 1, 0);
1006 /* Print the function name. */
1009 dump_type (cname, 0);
1010 OB_PUTC2 (':', ':');
1011 if (TREE_CODE (fntype) == METHOD_TYPE && parmtypes)
1012 parmtypes = TREE_CHAIN (parmtypes);
1013 if (DECL_CONSTRUCTOR_FOR_VBASE_P (t))
1014 /* Skip past "in_charge" identifier. */
1015 parmtypes = TREE_CHAIN (parmtypes);
1017 else if (CP_DECL_CONTEXT (t) != global_namespace)
1019 dump_decl (DECL_CONTEXT (t), 0);
1023 if (DESTRUCTOR_NAME_P (name) && DECL_LANGUAGE (t) == lang_cplusplus)
1024 parmtypes = TREE_CHAIN (parmtypes);
1026 dump_function_name (t);
1028 /* If V is negative, we don't print the argument types. */
1032 dump_parameters (parmtypes, v & 1, 0);
1034 if (v && ! DECL_CONV_FN_P (t))
1035 dump_type_suffix (TREE_TYPE (fntype), 1, 0);
1037 if (TREE_CODE (fntype) == METHOD_TYPE)
1039 if (IS_SIGNATURE (cname))
1040 /* We look at the type pointed to by the `optr' field of `this.' */
1042 (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_VALUE (TYPE_ARG_TYPES (fntype))))), before);
1045 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype))), before);
1049 dump_exception_spec (TYPE_RAISES_EXCEPTIONS (fntype), 0);
1052 /* Print a parameter list. V indicates if we show default values or not. If
1053 these are for a member function, the member object ptr
1054 (and any other hidden args) should have already been removed. */
1057 dump_parameters (parmtypes, v, canonical_name)
1065 for (first = 1; parmtypes != void_list_node;
1066 parmtypes = TREE_CHAIN (parmtypes))
1069 OB_PUTC2 (',', ' ');
1076 dump_type_real (TREE_VALUE (parmtypes), 0, canonical_name);
1078 if (TREE_PURPOSE (parmtypes) && v)
1081 dump_expr (TREE_PURPOSE (parmtypes), 0);
1088 /* Print an exception specification. T is the exception specification. */
1091 dump_exception_spec (t, canonical_name)
1097 OB_PUTS (" throw (");
1098 if (TREE_VALUE (t) != NULL_TREE)
1101 dump_type_real (TREE_VALUE (t), 0, canonical_name);
1105 OB_PUTC2 (',', ' ');
1111 /* Handle the function name for a FUNCTION_DECL node, grokking operators
1112 and destructors properly. */
1115 dump_function_name (t)
1118 tree name = DECL_NAME (t);
1120 if (DECL_DESTRUCTOR_P (t))
1123 dump_decl (name, 0);
1125 else if (DECL_CONV_FN_P (t))
1127 /* This cannot use the hack that the operator's return
1128 type is stashed off of its name because it may be
1129 used for error reporting. In the case of conflicting
1130 declarations, both will have the same name, yet
1131 the types will be different, hence the TREE_TYPE field
1132 of the first name will be clobbered by the second. */
1133 OB_PUTS ("operator ");
1134 dump_type (TREE_TYPE (TREE_TYPE (t)), 0);
1136 else if (IDENTIFIER_OPNAME_P (name))
1138 char *name_string = operator_name_string (name);
1139 OB_PUTS ("operator ");
1140 OB_PUTCP (name_string);
1143 dump_decl (name, 0);
1145 if (DECL_LANG_SPECIFIC (t) && DECL_USE_TEMPLATE (t)
1146 && DECL_TEMPLATE_INFO (t)
1147 && (DECL_TEMPLATE_SPECIALIZATION (t)
1148 || TREE_CODE (DECL_TI_TEMPLATE (t)) != TEMPLATE_DECL
1149 || DECL_TEMPLATE_SPECIALIZATION (DECL_TI_TEMPLATE (t))
1150 || PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t))))
1152 tree args = DECL_TEMPLATE_INFO (t) ? DECL_TI_ARGS (t) : NULL_TREE;
1155 /* Be careful only to print things when we have them, so as not
1156 to crash producing error messages. */
1159 if (TREE_CODE (args) == TREE_LIST)
1164 for (arg = args; arg; arg = TREE_CHAIN (arg))
1166 tree a = TREE_VALUE (arg);
1173 if (TREE_CODE_CLASS (TREE_CODE (a)) == 't'
1174 || TREE_CODE (a) == TEMPLATE_DECL)
1183 else if (TREE_CODE (args) == TREE_VEC)
1188 if (TREE_VEC_LENGTH (args) > 0
1189 && TREE_CODE (TREE_VEC_ELT (args, 0)) == TREE_VEC)
1190 args = TREE_VEC_ELT (args,
1191 TREE_VEC_LENGTH (args) - 1);
1193 for (i = 0; i < TREE_VEC_LENGTH (args); i++)
1195 tree a = TREE_VEC_ELT (args, i);
1202 if (TREE_CODE_CLASS (TREE_CODE (a)) == 't'
1203 || TREE_CODE (a) == TEMPLATE_DECL)
1213 OB_END_TEMPLATE_ID ();
1223 case TARGET_NEWLINE:
1258 sprintf (digit_buffer, "\\%03o", (int) c);
1259 OB_PUTCP (digit_buffer);
1264 /* Print out a list of initializers (subr of dump_expr) */
1272 dump_expr (TREE_VALUE (l), 0);
1274 OB_PUTC2 (',', ' ');
1279 /* Print out an expression */
1284 int nop; /* suppress parens */
1286 switch (TREE_CODE (t))
1294 case NAMESPACE_DECL:
1300 tree type = TREE_TYPE (t);
1301 my_friendly_assert (type != 0, 81);
1303 /* If it's an enum, output its tag, rather than its value. */
1304 if (TREE_CODE (type) == ENUMERAL_TYPE)
1306 char *p = enum_name_string (t, type);
1309 else if (type == boolean_type_node)
1311 if (t == boolean_false_node
1312 || (TREE_INT_CST_LOW (t) == 0
1313 && TREE_INT_CST_HIGH (t) == 0))
1315 else if (t == boolean_true_node)
1318 else if (type == char_type_node)
1321 dump_char (TREE_INT_CST_LOW (t));
1324 else if (TREE_INT_CST_HIGH (t)
1325 != (TREE_INT_CST_LOW (t) >> (HOST_BITS_PER_WIDE_INT - 1)))
1328 if (TREE_INT_CST_HIGH (val) < 0)
1331 val = build_int_2 (~TREE_INT_CST_LOW (val),
1332 -TREE_INT_CST_HIGH (val));
1334 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
1337 static char format[10]; /* "%x%09999x\0" */
1339 sprintf (format, "%%x%%0%dx", HOST_BITS_PER_INT / 4);
1340 sprintf (digit_buffer, format, TREE_INT_CST_HIGH (val),
1341 TREE_INT_CST_LOW (val));
1342 OB_PUTCP (digit_buffer);
1346 OB_PUTI (TREE_INT_CST_LOW (t));
1351 #ifndef REAL_IS_NOT_DOUBLE
1352 sprintf (digit_buffer, "%g", TREE_REAL_CST (t));
1355 unsigned char *p = (unsigned char *) &TREE_REAL_CST (t);
1357 strcpy (digit_buffer, "0x");
1358 for (i = 0; i < sizeof TREE_REAL_CST (t); i++)
1359 sprintf (digit_buffer + 2 + 2*i, "%02x", *p++);
1362 OB_PUTCP (digit_buffer);
1367 dump_type (PTRMEM_CST_CLASS (t), 0);
1369 OB_PUTID (DECL_NAME (PTRMEM_CST_MEMBER (t)));
1374 char *p = TREE_STRING_POINTER (t);
1375 int len = TREE_STRING_LENGTH (t) - 1;
1379 for (i = 0; i < len; i++)
1386 dump_binary_op (",", t);
1391 dump_expr (TREE_OPERAND (t, 0), 0);
1393 dump_expr (TREE_OPERAND (t, 1), 0);
1395 dump_expr (TREE_OPERAND (t, 2), 0);
1400 if (TREE_HAS_CONSTRUCTOR (t))
1403 dump_type (TREE_TYPE (TREE_TYPE (t)), 0);
1407 dump_expr (TREE_OPERAND (t, 0), 0);
1411 case AGGR_INIT_EXPR:
1412 OB_PUTID (TYPE_IDENTIFIER (TREE_TYPE (t)));
1414 if (TREE_OPERAND (t, 1))
1415 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)));
1421 tree fn = TREE_OPERAND (t, 0);
1422 tree args = TREE_OPERAND (t, 1);
1424 if (TREE_CODE (fn) == ADDR_EXPR)
1425 fn = TREE_OPERAND (fn, 0);
1427 if (TREE_TYPE (fn) != NULL_TREE && NEXT_CODE (fn) == METHOD_TYPE)
1429 tree ob = TREE_VALUE (args);
1430 if (TREE_CODE (ob) == ADDR_EXPR)
1432 dump_expr (TREE_OPERAND (ob, 0), 0);
1435 else if (TREE_CODE (ob) != PARM_DECL
1436 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
1439 OB_PUTC2 ('-', '>');
1441 args = TREE_CHAIN (args);
1445 dump_expr_list (args);
1452 tree type = TREE_OPERAND (t, 1);
1453 if (NEW_EXPR_USE_GLOBAL (t))
1456 if (TREE_OPERAND (t, 0))
1459 dump_expr_list (TREE_OPERAND (t, 0));
1462 if (TREE_CODE (type) == ARRAY_REF)
1463 type = build_cplus_array_type
1464 (TREE_OPERAND (type, 0),
1465 build_index_type (size_binop (MINUS_EXPR, TREE_OPERAND (type, 1),
1466 integer_one_node)));
1467 dump_type (type, 0);
1468 if (TREE_OPERAND (t, 2))
1471 dump_expr_list (TREE_OPERAND (t, 2));
1478 /* Note that this only works for G++ target exprs. If somebody
1479 builds a general TARGET_EXPR, there's no way to represent that
1480 it initializes anything other that the parameter slot for the
1481 default argument. Note we may have cleared out the first
1482 operand in expand_expr, so don't go killing ourselves. */
1483 if (TREE_OPERAND (t, 1))
1484 dump_expr (TREE_OPERAND (t, 1), 0);
1491 case TRUNC_DIV_EXPR:
1492 case TRUNC_MOD_EXPR:
1500 case BIT_ANDTC_EXPR:
1501 case TRUTH_ANDIF_EXPR:
1502 case TRUTH_ORIF_EXPR:
1509 dump_binary_op (opname_tab[(int) TREE_CODE (t)], t);
1513 case FLOOR_DIV_EXPR:
1514 case ROUND_DIV_EXPR:
1515 dump_binary_op ("/", t);
1519 case FLOOR_MOD_EXPR:
1520 case ROUND_MOD_EXPR:
1521 dump_binary_op ("%", t);
1526 tree ob = TREE_OPERAND (t, 0);
1527 if (TREE_CODE (ob) == INDIRECT_REF)
1529 ob = TREE_OPERAND (ob, 0);
1530 if (TREE_CODE (ob) != PARM_DECL
1531 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
1534 OB_PUTC2 ('-', '>');
1542 dump_expr (TREE_OPERAND (t, 1), 1);
1547 dump_expr (TREE_OPERAND (t, 0), 0);
1549 dump_expr (TREE_OPERAND (t, 1), 0);
1554 dump_unary_op ("+", t, nop);
1558 if (TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
1559 || TREE_CODE (TREE_OPERAND (t, 0)) == STRING_CST)
1560 dump_expr (TREE_OPERAND (t, 0), 0);
1562 dump_unary_op ("&", t, nop);
1566 if (TREE_HAS_CONSTRUCTOR (t))
1568 t = TREE_OPERAND (t, 0);
1569 my_friendly_assert (TREE_CODE (t) == CALL_EXPR, 237);
1570 dump_expr (TREE_OPERAND (t, 0), 0);
1572 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)));
1577 if (TREE_OPERAND (t,0) != NULL_TREE
1578 && TREE_TYPE (TREE_OPERAND (t, 0))
1579 && NEXT_CODE (TREE_OPERAND (t, 0)) == REFERENCE_TYPE)
1580 dump_expr (TREE_OPERAND (t, 0), nop);
1582 dump_unary_op ("*", t, nop);
1588 case TRUTH_NOT_EXPR:
1589 case PREDECREMENT_EXPR:
1590 case PREINCREMENT_EXPR:
1591 dump_unary_op (opname_tab [(int)TREE_CODE (t)], t, nop);
1594 case POSTDECREMENT_EXPR:
1595 case POSTINCREMENT_EXPR:
1597 dump_expr (TREE_OPERAND (t, 0), 0);
1598 OB_PUTCP (opname_tab[(int)TREE_CODE (t)]);
1602 case NON_LVALUE_EXPR:
1603 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
1604 should be another level of INDIRECT_REF so that I don't have to do
1606 if (TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == POINTER_TYPE)
1608 tree next = TREE_TYPE (TREE_TYPE (t));
1610 while (TREE_CODE (next) == POINTER_TYPE)
1611 next = TREE_TYPE (next);
1613 if (TREE_CODE (next) == FUNCTION_TYPE)
1615 if (!nop) OB_PUTC ('(');
1617 dump_expr (TREE_OPERAND (t, 0), 1);
1618 if (!nop) OB_PUTC (')');
1623 dump_expr (TREE_OPERAND (t, 0), 0);
1627 dump_expr (TREE_OPERAND (t, 0), nop);
1631 if (TREE_TYPE (t) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t)))
1633 tree idx = build_component_ref (t, index_identifier, NULL_TREE, 0);
1635 if (integer_all_onesp (idx))
1637 tree pfn = PFN_FROM_PTRMEMFUNC (t);
1638 dump_unary_op ("&", pfn, 0);
1641 else if (TREE_CODE (idx) == INTEGER_CST
1642 && tree_int_cst_equal (idx, integer_zero_node))
1644 /* A NULL pointer-to-member constant. */
1646 dump_type (TREE_TYPE (t), 0);
1650 else if (TREE_CODE (idx) == INTEGER_CST
1651 && TREE_INT_CST_HIGH (idx) == 0)
1654 unsigned HOST_WIDE_INT n;
1656 t = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t)));
1657 t = TYPE_METHOD_BASETYPE (t);
1658 virtuals = BINFO_VIRTUALS (TYPE_BINFO (TYPE_MAIN_VARIANT (t)));
1660 n = TREE_INT_CST_LOW (idx);
1662 /* Map vtable index back one, to allow for the null pointer to
1666 while (n > 0 && virtuals)
1669 virtuals = TREE_CHAIN (virtuals);
1673 dump_expr (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals)), 0);
1679 dump_expr_list (CONSTRUCTOR_ELTS (t));
1685 tree ob = TREE_OPERAND (t, 0);
1686 if (is_dummy_object (ob))
1688 t = TREE_OPERAND (t, 1);
1689 if (TREE_CODE (t) == FUNCTION_DECL)
1692 else if (BASELINK_P (t))
1693 dump_expr (OVL_CURRENT (TREE_VALUE (t)), 0);
1699 if (TREE_CODE (ob) == INDIRECT_REF)
1701 dump_expr (TREE_OPERAND (ob, 0), 0);
1709 dump_expr (TREE_OPERAND (t, 1), 0);
1714 case TEMPLATE_PARM_INDEX:
1715 dump_decl (TEMPLATE_PARM_DECL (t), -1);
1718 case IDENTIFIER_NODE:
1723 dump_type (TREE_OPERAND (t, 0), 0);
1725 dump_expr (TREE_OPERAND (t, 1), 0);
1729 if (TREE_OPERAND (t, 0) == NULL_TREE
1730 || TREE_CHAIN (TREE_OPERAND (t, 0)))
1732 dump_type (TREE_TYPE (t), 0);
1734 dump_expr_list (TREE_OPERAND (t, 0));
1740 dump_type (TREE_TYPE (t), 0);
1743 dump_expr_list (TREE_OPERAND (t, 0));
1749 OB_PUTID (TREE_OPERAND (t, 0));
1753 dump_expr (TREE_OPERAND (t, 0), nop);
1759 if (TREE_CODE (t) == SIZEOF_EXPR)
1760 OB_PUTS ("sizeof (");
1763 my_friendly_assert (TREE_CODE (t) == ALIGNOF_EXPR, 0);
1764 OB_PUTS ("__alignof__ (");
1766 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t, 0))) == 't')
1767 dump_type (TREE_OPERAND (t, 0), 0);
1769 dump_unary_op ("*", t, 0);
1774 OB_PUTS ("{unparsed}");
1777 case TRY_CATCH_EXPR:
1778 case WITH_CLEANUP_EXPR:
1779 case CLEANUP_POINT_EXPR:
1780 dump_expr (TREE_OPERAND (t, 0), nop);
1783 case TEMPLATE_ID_EXPR:
1788 if (TREE_VALUE (t) && TREE_CODE (TREE_VALUE (t)) == FUNCTION_DECL)
1790 OB_PUTID (DECL_NAME (TREE_VALUE (t)));
1793 /* else fall through */
1795 /* This list is incomplete, but should suffice for now.
1796 It is very important that `sorry' does not call
1797 `report_error_function'. That could cause an infinite loop. */
1799 sorry ("`%s' not supported by dump_expr",
1800 tree_code_name[(int) TREE_CODE (t)]);
1802 /* fall through to ERROR_MARK... */
1804 OB_PUTCP ("{error}");
1810 dump_binary_op (opstring, t)
1815 dump_expr (TREE_OPERAND (t, 0), 1);
1817 OB_PUTCP (opstring);
1819 dump_expr (TREE_OPERAND (t, 1), 1);
1824 dump_unary_op (opstring, t, nop)
1829 if (!nop) OB_PUTC ('(');
1830 OB_PUTCP (opstring);
1831 dump_expr (TREE_OPERAND (t, 0), 1);
1832 if (!nop) OB_PUTC (')');
1835 /* Print a function decl with exception specification included. */
1838 fndecl_as_string (fndecl, print_default_args_p)
1840 int print_default_args_p;
1844 dump_function_decl (fndecl, 2 + print_default_args_p);
1848 return (char *)obstack_base (&scratch_obstack);
1851 /* Same, but handle a _TYPE.
1852 Called from convert_to_reference, mangle_class_name_for_template,
1853 build_unary_op, and GNU_xref_decl. If CANONICAL_NAME is non-zero,
1854 when describing a typedef, we use the name of the type described,
1855 rather than the name of the typedef. */
1858 type_as_string_real (typ, v, canonical_name)
1865 dump_type_real (typ, v, canonical_name);
1869 return (char *)obstack_base (&scratch_obstack);
1874 type_as_string (typ, v)
1878 return type_as_string_real (typ, v, 0);
1882 expr_as_string (decl, v)
1884 int v ATTRIBUTE_UNUSED;
1888 dump_expr (decl, 1);
1892 return (char *)obstack_base (&scratch_obstack);
1895 /* A cross between type_as_string and fndecl_as_string.
1896 Only called from substitute_nice_name. */
1899 decl_as_string (decl, v)
1905 dump_decl (decl, v);
1909 return (char *)obstack_base (&scratch_obstack);
1912 /* Generate the three forms of printable names for lang_printable_name. */
1915 lang_decl_name (decl, v)
1920 return decl_as_string (decl, 1);
1924 if (v == 1 && DECL_CLASS_SCOPE_P (decl))
1927 if (TREE_CODE (decl) == FUNCTION_DECL)
1928 cname = DECL_CLASS_CONTEXT (decl);
1930 cname = DECL_CONTEXT (decl);
1931 dump_type (cname, 0);
1932 OB_PUTC2 (':', ':');
1935 if (TREE_CODE (decl) == FUNCTION_DECL)
1936 dump_function_name (decl);
1938 dump_decl (DECL_NAME (decl), 0);
1942 return (char *)obstack_base (&scratch_obstack);
1950 if (TREE_CODE (t) == PARM_DECL && DECL_CONTEXT (t))
1951 return DECL_SOURCE_FILE (DECL_CONTEXT (t));
1952 else if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
1953 return DECL_SOURCE_FILE (TYPE_MAIN_DECL (t));
1954 else if (TREE_CODE (t) == OVERLOAD)
1955 return DECL_SOURCE_FILE (OVL_FUNCTION (t));
1957 return DECL_SOURCE_FILE (t);
1965 if (TREE_CODE (t) == PARM_DECL && DECL_CONTEXT (t))
1966 line = DECL_SOURCE_LINE (DECL_CONTEXT (t));
1967 if (TREE_CODE (t) == TYPE_DECL && DECL_ARTIFICIAL (t)
1968 && TYPE_MAIN_DECL (TREE_TYPE (t)))
1971 if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
1972 line = DECL_SOURCE_LINE (TYPE_MAIN_DECL (t));
1973 else if (TREE_CODE (t) == OVERLOAD)
1974 line = DECL_SOURCE_LINE (OVL_FUNCTION (t));
1976 line = DECL_SOURCE_LINE (t);
1985 code_as_string (c, v)
1987 int v ATTRIBUTE_UNUSED;
1989 return tree_code_name [c];
1993 language_as_string (c, v)
1995 int v ATTRIBUTE_UNUSED;
2002 case lang_cplusplus:
2009 my_friendly_abort (355);
2014 /* Return the proper printed version of a parameter to a C++ function. */
2017 parm_as_string (p, v)
2019 int v ATTRIBUTE_UNUSED;
2024 sprintf (digit_buffer, "%d", p+1);
2025 return digit_buffer;
2031 int v ATTRIBUTE_UNUSED;
2033 static char buf[] = "operator ";
2038 strcpy (buf + 9, opname_tab [p]);
2043 assop_as_string (p, v)
2045 int v ATTRIBUTE_UNUSED;
2047 static char buf[] = "operator ";
2052 strcpy (buf + 9, assignop_tab [p]);
2057 args_as_string (p, v)
2064 if (TREE_CODE_CLASS (TREE_CODE (TREE_VALUE (p))) == 't')
2065 return type_as_string (p, v);
2068 for (; p; p = TREE_CHAIN (p))
2070 if (TREE_VALUE (p) == null_node)
2073 dump_type (error_type (TREE_VALUE (p)), v);
2078 return (char *)obstack_base (&scratch_obstack);
2084 int v ATTRIBUTE_UNUSED;
2088 dump_qualifiers (p, before);
2092 return (char *)obstack_base (&scratch_obstack);