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_type_real PROTO((tree, int, int));
93 static void dump_decl PROTO((tree, int));
94 static void dump_function_decl PROTO((tree, int));
95 static void dump_expr PROTO((tree, int));
96 static void dump_unary_op PROTO((char *, tree, int));
97 static void dump_binary_op PROTO((char *, tree));
98 static void dump_aggr_type PROTO((tree, int, int));
99 static void dump_type_prefix PROTO((tree, int, int));
100 static void dump_type_suffix PROTO((tree, int, int));
101 static void dump_function_name PROTO((tree));
102 static void dump_expr_list PROTO((tree));
103 static void dump_global_iord PROTO((tree));
104 static void dump_readonly_or_volatile PROTO((tree, enum pad));
105 static void dump_char PROTO((int));
106 static char *aggr_variety PROTO((tree));
107 static tree ident_fndecl PROTO((tree));
112 gcc_obstack_init (&scratch_obstack);
113 scratch_firstobj = (char *)obstack_alloc (&scratch_obstack, 0);
117 dump_readonly_or_volatile (t, p)
121 if (TYPE_READONLY (t) || TYPE_VOLATILE (t))
123 if (p == before) OB_PUTC (' ');
124 if (TYPE_READONLY (t))
126 if (TYPE_READONLY (t) && TYPE_VOLATILE (t))
128 if (TYPE_VOLATILE (t))
129 OB_PUTS ("volatile");
130 if (p == after) OB_PUTC (' ');
134 /* This must be large enough to hold any printed integer or floating-point
136 static char digit_buffer[128];
138 /* Dump into the obstack a human-readable equivalent of TYPE. */
141 dump_type_real (t, v, canonical_name)
143 int v; /* verbose? */
149 if (TYPE_PTRMEMFUNC_P (t))
152 switch (TREE_CODE (t))
159 OB_PUTS ("{unknown type}");
163 /* i.e. function taking no arguments */
164 if (t != void_list_node)
166 dump_type_real (TREE_VALUE (t), v, canonical_name);
167 /* Can this happen other than for default arguments? */
168 if (TREE_PURPOSE (t) && v)
171 dump_expr (TREE_PURPOSE (t), 0);
175 if (TREE_CHAIN (t) != void_list_node)
178 dump_type_real (TREE_CHAIN (t), v, canonical_name);
181 else OB_PUTS (" ...");
185 case IDENTIFIER_NODE:
190 dump_type_real (BINFO_TYPE (t), v, canonical_name);
196 if (TYPE_LANG_SPECIFIC (t)
197 && (IS_SIGNATURE_POINTER (t) || IS_SIGNATURE_REFERENCE (t)))
199 if (TYPE_READONLY (t) | TYPE_VOLATILE (t))
200 dump_readonly_or_volatile (t, after);
201 dump_type_real (SIGNATURE_TYPE (t), v, canonical_name);
202 if (IS_SIGNATURE_POINTER (t))
208 dump_aggr_type (t, v, canonical_name);
217 OB_PUTS ("complex ");
218 dump_type_real (TREE_TYPE (t), v, canonical_name);
222 if (!TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)) && TREE_UNSIGNED (t))
223 OB_PUTS ("unsigned ");
224 else if (TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)) && !TREE_UNSIGNED (t))
231 dump_readonly_or_volatile (t, after);
232 OB_PUTID (TYPE_IDENTIFIER (canonical_name ? TYPE_MAIN_VARIANT (t) : t));
235 case TEMPLATE_TEMPLATE_PARM:
236 if (!CLASSTYPE_TEMPLATE_INFO (t))
238 /* For parameters inside template signature. */
239 if (TYPE_IDENTIFIER (t))
240 OB_PUTID (TYPE_IDENTIFIER (t));
242 OB_PUTS ("{anonymous template template parm}");
247 tree args = CLASSTYPE_TI_ARGS (t);
248 OB_PUTID (TYPE_IDENTIFIER (t));
250 for (i = 0; i < TREE_VEC_LENGTH (args); i++)
252 tree arg = TREE_VEC_ELT (args, i);
253 if (TREE_CODE_CLASS (TREE_CODE (arg)) == 't'
254 || TREE_CODE (arg) == TEMPLATE_DECL)
255 dump_type_real (arg, 0, canonical_name);
258 if (i < TREE_VEC_LENGTH (args)-1)
265 case TEMPLATE_TYPE_PARM:
266 dump_readonly_or_volatile (t, after);
267 if (TYPE_IDENTIFIER (t))
268 OB_PUTID (TYPE_IDENTIFIER (t));
270 OB_PUTS ("{anonymous template type parm}");
273 /* This is not always necessary for pointers and such, but doing this
274 reduces code size. */
282 dump_type_prefix (t, v, canonical_name);
283 dump_type_suffix (t, v, canonical_name);
287 OB_PUTS ("typename ");
288 dump_type_real (TYPE_CONTEXT (t), 0, canonical_name);
290 OB_PUTID (TYPE_IDENTIFIER (t));
294 sorry ("`%s' not supported by dump_type",
295 tree_code_name[(int) TREE_CODE (t)]);
303 if (TREE_CODE (t) == ENUMERAL_TYPE)
305 else if (TREE_CODE (t) == UNION_TYPE)
307 else if (TYPE_LANG_SPECIFIC (t) && CLASSTYPE_DECLARED_CLASS (t))
309 else if (TYPE_LANG_SPECIFIC (t) && IS_SIGNATURE (t))
318 int v; /* verbose? */
320 dump_type_real (t, v, 0);
323 /* Print out a class declaration, in the form `class foo'. */
326 dump_aggr_type (t, v, canonical_name)
328 int v; /* verbose? */
332 char *variety = aggr_variety (t);
334 dump_readonly_or_volatile (t, after);
342 name = TYPE_NAME (canonical_name ? TYPE_MAIN_VARIANT (t) : t);
344 if (name && DECL_CONTEXT (name))
346 /* FUNCTION_DECL or RECORD_TYPE */
347 dump_decl (DECL_CONTEXT (name), 0);
351 /* kludge around weird behavior on g++.brendan/line1.C */
352 if (name && TREE_CODE (name) != IDENTIFIER_NODE)
353 name = DECL_NAME (name);
355 if (name == 0 || ANON_AGGRNAME_P (name))
357 OB_PUTS ("{anonymous");
369 /* Dump into the obstack the initial part of the output for a given type.
370 This is necessary when dealing with things like functions returning
373 return type of `int (* fee ())()': pointer -> function -> int. Both
374 pointer (and reference and offset) and function (and member) types must
375 deal with prefix and suffix.
377 Arrays must also do this for DECL nodes, like int a[], and for things like
381 dump_type_prefix (t, v, canonical_name)
383 int v; /* verbosity */
386 if (TYPE_PTRMEMFUNC_P (t))
388 t = TYPE_PTRMEMFUNC_FN_TYPE (t);
392 switch (TREE_CODE (t))
396 tree sub = TREE_TYPE (t);
398 dump_type_prefix (sub, v, canonical_name);
399 /* A tree for a member pointer looks like pointer to offset,
400 so let the OFFSET_TYPE case handle it. */
401 if (TREE_CODE (sub) != OFFSET_TYPE)
403 switch (TREE_CODE (sub))
405 /* We don't want int ( *)() */
415 /* We don't want "char * *" */
416 if (! (TYPE_READONLY (sub) || TYPE_VOLATILE (sub)))
418 /* But we do want "char *const *" */
424 dump_readonly_or_volatile (t, none);
431 tree sub = TREE_TYPE (t);
432 dump_type_prefix (sub, v, canonical_name);
434 switch (TREE_CODE (sub))
441 /* We don't want "char * &" */
442 if (! (TYPE_READONLY (sub) || TYPE_VOLATILE (sub)))
444 /* But we do want "char *const &" */
451 dump_readonly_or_volatile (t, none);
456 dump_type_prefix (TREE_TYPE (t), v, canonical_name);
457 if (TREE_CODE (t) == OFFSET_TYPE) /* pmfs deal with this in d_t_p */
460 dump_type_real (TYPE_OFFSET_BASETYPE (t), 0, canonical_name);
464 dump_readonly_or_volatile (t, none);
467 /* Can only be reached through function pointer -- this would not be
468 correct if FUNCTION_DECLs used it. */
470 dump_type_prefix (TREE_TYPE (t), v, canonical_name);
475 dump_type_prefix (TREE_TYPE (t), v, canonical_name);
477 dump_aggr_type (TYPE_METHOD_BASETYPE (t), 0, canonical_name);
482 dump_type_prefix (TREE_TYPE (t), v, canonical_name);
487 case IDENTIFIER_NODE:
492 case TEMPLATE_TYPE_PARM:
493 case TEMPLATE_TEMPLATE_PARM:
502 dump_type_real (t, v, canonical_name);
506 sorry ("`%s' not supported by dump_type_prefix",
507 tree_code_name[(int) TREE_CODE (t)]);
512 dump_type_suffix (t, v, canonical_name)
514 int v; /* verbose? */
517 if (TYPE_PTRMEMFUNC_P (t))
518 t = TYPE_PTRMEMFUNC_FN_TYPE (t);
520 switch (TREE_CODE (t))
525 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
527 dump_type_suffix (TREE_TYPE (t), v, canonical_name);
530 /* Can only be reached through function pointer */
536 arg = TYPE_ARG_TYPES (t);
537 if (TREE_CODE (t) == METHOD_TYPE)
538 arg = TREE_CHAIN (arg);
545 if (TREE_CODE (t) == METHOD_TYPE)
546 dump_readonly_or_volatile
547 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t))), before);
548 dump_type_suffix (TREE_TYPE (t), v, canonical_name);
556 if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (t))) == INTEGER_CST)
557 OB_PUTI (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (t))) + 1);
558 else if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (t))) == MINUS_EXPR)
559 dump_expr (TREE_OPERAND (TYPE_MAX_VALUE (TYPE_DOMAIN (t)), 0), 0);
561 dump_expr (fold (build_binary_op
562 (PLUS_EXPR, TYPE_MAX_VALUE (TYPE_DOMAIN (t)),
563 integer_one_node, 1)), 0);
566 dump_type_suffix (TREE_TYPE (t), v, canonical_name);
571 case IDENTIFIER_NODE:
576 case TEMPLATE_TYPE_PARM:
577 case TEMPLATE_TEMPLATE_PARM:
589 sorry ("`%s' not supported by dump_type_suffix",
590 tree_code_name[(int) TREE_CODE (t)]);
594 /* Return a function declaration which corresponds to the IDENTIFIER_NODE
601 tree n = lookup_name (t, 0);
606 if (TREE_CODE (n) == FUNCTION_DECL)
608 else if (TREE_CODE (n) == TREE_LIST
609 && TREE_CODE (TREE_VALUE (n)) == FUNCTION_DECL)
610 return TREE_VALUE (n);
612 my_friendly_abort (66);
616 #ifndef NO_DOLLAR_IN_LABEL
617 # define GLOBAL_THING "_GLOBAL_$"
619 # ifndef NO_DOT_IN_LABEL
620 # define GLOBAL_THING "_GLOBAL_."
622 # define GLOBAL_THING "_GLOBAL__"
626 #define GLOBAL_IORD_P(NODE) \
627 ! strncmp (IDENTIFIER_POINTER(NODE), GLOBAL_THING, sizeof (GLOBAL_THING) - 1)
633 char *name = IDENTIFIER_POINTER (t);
635 OB_PUTS ("(static ");
636 if (name [sizeof (GLOBAL_THING) - 1] == 'I')
637 OB_PUTS ("initializers");
638 else if (name [sizeof (GLOBAL_THING) - 1] == 'D')
639 OB_PUTS ("destructors");
641 my_friendly_abort (352);
644 OB_PUTCP (input_filename);
651 int v; /* verbosity */
656 switch (TREE_CODE (t))
659 OB_PUTS (" /* decl error */ ");
664 /* Don't say 'typedef class A' */
665 if (DECL_ARTIFICIAL (t))
667 if (v > 0 && TREE_CODE (TREE_TYPE (t)) == TEMPLATE_TYPE_PARM)
668 /* Say `class T' not just `T'. */
671 dump_type (TREE_TYPE (t), v);
676 OB_PUTS ("typedef ");
681 if (DECL_NAME (t) && VTABLE_NAME_P (DECL_NAME (t)))
683 OB_PUTS ("vtable for ");
684 dump_type (DECL_CONTEXT (t), v);
687 /* else fall through */
693 dump_type_prefix (TREE_TYPE (t), v, 0);
695 dump_readonly_or_volatile (t, after);
697 /* DECL_CLASS_CONTEXT isn't being set in some cases. Hmm... */
699 && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (t))) == 't')
701 dump_type (DECL_CONTEXT (t), 0);
705 dump_decl (DECL_NAME (t), v);
709 dump_type_suffix (TREE_TYPE (t), v, 0);
713 if (DECL_NAMESPACE (t) != global_namespace)
715 dump_decl (DECL_NAMESPACE (t), v);
718 OB_PUTID (DECL_NAME (t));
722 dump_decl (TREE_OPERAND (t, 0), v);
724 dump_decl (TREE_OPERAND (t, 1), v);
728 /* So that we can do dump_decl in dump_aggr_type and have it work for
729 both class and function scope. */
737 my_friendly_abort (69);
740 /* These special cases are duplicated here so that other functions
741 can feed identifiers to cp_error and get them demangled properly. */
742 case IDENTIFIER_NODE:
744 if (DESTRUCTOR_NAME_P (t)
745 && (f = ident_fndecl (t))
746 && DECL_LANGUAGE (f) == lang_cplusplus)
749 dump_decl (DECL_NAME (f), 0);
751 else if (IDENTIFIER_TYPENAME_P (t))
753 OB_PUTS ("operator ");
754 /* Not exactly IDENTIFIER_TYPE_VALUE. */
755 dump_type (TREE_TYPE (t), 0);
758 else if (IDENTIFIER_OPNAME_P (t))
760 char *name_string = operator_name_string (t);
761 OB_PUTS ("operator ");
762 OB_PUTCP (name_string);
770 if (GLOBAL_IORD_P (DECL_ASSEMBLER_NAME (t)))
771 dump_global_iord (DECL_ASSEMBLER_NAME (t));
772 else if (! DECL_LANG_SPECIFIC (t))
773 OB_PUTS ("{internal}");
775 dump_function_decl (t, v);
780 tree orig_args = DECL_TEMPLATE_PARMS (t);
783 for (args = orig_args = nreverse (orig_args);
785 args = TREE_CHAIN (args))
787 int len = TREE_VEC_LENGTH (TREE_VALUE (args));
789 OB_PUTS ("template <");
790 for (i = 0; i < len; i++)
792 tree arg = TREE_VEC_ELT (TREE_VALUE (args), i);
793 tree defval = TREE_PURPOSE (arg);
794 arg = TREE_VALUE (arg);
795 if (TREE_CODE (arg) == TYPE_DECL)
800 OB_PUTID (DECL_NAME (arg));
811 if (TREE_CODE (arg) == TYPE_DECL
812 || TREE_CODE (arg) == TEMPLATE_DECL)
813 dump_type (defval, 1);
815 dump_expr (defval, 1);
826 if (TREE_CODE (DECL_TEMPLATE_RESULT (t)) == TYPE_DECL)
827 dump_type (TREE_TYPE (t), v);
828 else if (TREE_TYPE (t) == NULL_TREE)
829 my_friendly_abort (353);
830 else switch (NEXT_CODE (t))
834 dump_function_decl (t, v);
838 /* This case can occur with some illegal code. */
839 dump_type (TREE_TYPE (t), v);
844 case TEMPLATE_ID_EXPR:
847 tree name = TREE_OPERAND (t, 0);
848 if (is_overloaded_fn (name))
849 name = DECL_NAME (get_first_fn (name));
852 for (args = TREE_OPERAND (t, 1); args; args = TREE_CHAIN (args))
854 if (TREE_CODE_CLASS (TREE_CODE (TREE_VALUE (args))) == 't'
855 || TREE_CODE (TREE_VALUE (args)) == TEMPLATE_DECL)
856 dump_type (TREE_VALUE (args), 0);
858 dump_expr (TREE_VALUE (args), 0);
859 if (TREE_CHAIN (args))
867 OB_PUTID (TREE_OPERAND (t, 0));
871 OB_PUTID (DECL_NAME (t));
875 if ((TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == ENUMERAL_TYPE)
876 || (DECL_INITIAL (t) &&
877 TREE_CODE (DECL_INITIAL (t)) == TEMPLATE_PARM_INDEX))
879 else if (DECL_NAME (t))
880 dump_decl (DECL_NAME (t), v);
881 else if (DECL_INITIAL (t))
882 dump_expr (DECL_INITIAL (t), 0);
884 OB_PUTS ("enumerator");
889 dump_type (DECL_INITIAL (t), 0);
891 OB_PUTID (DECL_NAME (t));
895 sorry ("`%s' not supported by dump_decl",
896 tree_code_name[(int) TREE_CODE (t)]);
900 /* Pretty printing for announce_function. T is the declaration of the
901 function we are interested in seeing. V is non-zero if we should print
902 the type that this function returns. */
905 dump_function_decl (t, v)
912 tree cname = NULL_TREE;
914 if (TREE_CODE (t) == TEMPLATE_DECL)
915 t = DECL_TEMPLATE_RESULT (t);
917 name = DECL_ASSEMBLER_NAME (t);
918 fntype = TREE_TYPE (t);
919 parmtypes = TYPE_ARG_TYPES (fntype);
921 /* Friends have DECL_CLASS_CONTEXT set, but not DECL_CONTEXT. */
922 if (DECL_CONTEXT (t))
923 cname = DECL_CLASS_CONTEXT (t);
924 /* this is for partially instantiated template methods */
925 else if (TREE_CODE (fntype) == METHOD_TYPE)
926 cname = TREE_TYPE (TREE_VALUE (parmtypes));
932 if (DECL_STATIC_FUNCTION_P (t))
935 if (! IDENTIFIER_TYPENAME_P (name)
936 && ! DECL_CONSTRUCTOR_P (t)
937 && ! DESTRUCTOR_NAME_P (name))
939 dump_type_prefix (TREE_TYPE (fntype), 1, 0);
946 dump_type (cname, 0);
948 if (TREE_CODE (fntype) == METHOD_TYPE && parmtypes)
949 parmtypes = TREE_CHAIN (parmtypes);
950 if (DECL_CONSTRUCTOR_FOR_VBASE_P (t))
951 /* Skip past "in_charge" identifier. */
952 parmtypes = TREE_CHAIN (parmtypes);
955 if (DESTRUCTOR_NAME_P (name) && DECL_LANGUAGE (t) == lang_cplusplus)
956 parmtypes = TREE_CHAIN (parmtypes);
958 dump_function_name (t);
963 dump_type (parmtypes, v);
969 if (v && ! IDENTIFIER_TYPENAME_P (name))
970 dump_type_suffix (TREE_TYPE (fntype), 1, 0);
972 if (TREE_CODE (fntype) == METHOD_TYPE)
974 if (IS_SIGNATURE (cname))
975 /* We look at the type pointed to by the `optr' field of `this.' */
976 dump_readonly_or_volatile
977 (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_VALUE (TYPE_ARG_TYPES (fntype))))), before);
979 dump_readonly_or_volatile
980 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype))), before);
984 /* Handle the function name for a FUNCTION_DECL node, grokking operators
985 and destructors properly. */
988 dump_function_name (t)
991 tree name = DECL_NAME (t);
993 /* There ought to be a better way to find out whether or not something is
995 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (t))
996 && DECL_LANGUAGE (t) == lang_cplusplus)
1001 else if (IDENTIFIER_TYPENAME_P (name))
1003 /* This cannot use the hack that the operator's return
1004 type is stashed off of its name because it may be
1005 used for error reporting. In the case of conflicting
1006 declarations, both will have the same name, yet
1007 the types will be different, hence the TREE_TYPE field
1008 of the first name will be clobbered by the second. */
1009 OB_PUTS ("operator ");
1010 dump_type (TREE_TYPE (TREE_TYPE (t)), 0);
1012 else if (IDENTIFIER_OPNAME_P (name))
1014 char *name_string = operator_name_string (name);
1015 OB_PUTS ("operator ");
1016 OB_PUTCP (name_string);
1019 dump_decl (name, 0);
1021 if (DECL_LANG_SPECIFIC (t) && DECL_USE_TEMPLATE (t))
1023 tree args = DECL_TEMPLATE_INFO (t) ? DECL_TI_ARGS (t) : NULL_TREE;
1025 if (args != NULL_TREE
1026 && DECL_CONTEXT (t) != NULL_TREE
1027 && uses_template_parms (DECL_CONTEXT (t))
1028 /* This next clause checks that there is only one level of
1029 template arguments. In that case, they are the
1030 arguments for the class context. */
1031 && (TREE_CODE (args) == TREE_LIST
1032 || (TREE_CODE (args) == TREE_VEC
1033 && TREE_VEC_ELT (args, 0) != NULL_TREE
1034 && TREE_CODE (TREE_VEC_ELT (args, 0)) != TREE_VEC)))
1035 /* We have something like this:
1037 template <class T> struct S { void f(); };
1039 and we are printing S<int>::f(). This is a template
1040 instantiation, but we don't print anything after the f. */
1046 /* Be careful only to print things when we have them, so as not
1047 to crash producing error messages. */
1050 if (TREE_CODE (args) == TREE_LIST)
1055 for (arg = args; arg; arg = TREE_CHAIN (arg))
1057 tree a = TREE_VALUE (arg);
1064 if (TREE_CODE_CLASS (TREE_CODE (a)) == 't'
1065 || TREE_CODE (a) == TEMPLATE_DECL)
1074 else if (TREE_CODE (args) == TREE_VEC)
1079 if (TREE_VEC_LENGTH (args) > 0
1080 && TREE_CODE (TREE_VEC_ELT (args, 0)) == TREE_VEC)
1081 args = TREE_VEC_ELT (args,
1082 TREE_VEC_LENGTH (args) - 1);
1084 for (i = 0; i < TREE_VEC_LENGTH (args); i++)
1086 tree a = TREE_VEC_ELT (args, i);
1093 if (TREE_CODE_CLASS (TREE_CODE (a)) == 't'
1094 || TREE_CODE (a) == TEMPLATE_DECL)
1115 case TARGET_NEWLINE:
1150 sprintf (digit_buffer, "\\%03o", (int) c);
1151 OB_PUTCP (digit_buffer);
1156 /* Print out a list of initializers (subr of dump_expr) */
1164 dump_expr (TREE_VALUE (l), 0);
1166 OB_PUTC2 (',', ' ');
1171 /* Print out an expression */
1176 int nop; /* suppress parens */
1178 switch (TREE_CODE (t))
1191 tree type = TREE_TYPE (t);
1192 my_friendly_assert (type != 0, 81);
1194 /* If it's an enum, output its tag, rather than its value. */
1195 if (TREE_CODE (type) == ENUMERAL_TYPE)
1197 char *p = enum_name_string (t, type);
1200 else if (type == boolean_type_node)
1202 if (t == boolean_false_node
1203 || (TREE_INT_CST_LOW (t) == 0
1204 && TREE_INT_CST_HIGH (t) == 0))
1206 else if (t == boolean_true_node)
1209 else if (type == char_type_node)
1212 dump_char (TREE_INT_CST_LOW (t));
1215 else if (TREE_INT_CST_HIGH (t)
1216 != (TREE_INT_CST_LOW (t) >> (HOST_BITS_PER_WIDE_INT - 1)))
1219 if (TREE_INT_CST_HIGH (val) < 0)
1222 val = build_int_2 (~TREE_INT_CST_LOW (val),
1223 -TREE_INT_CST_HIGH (val));
1225 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
1228 static char format[10]; /* "%x%09999x\0" */
1230 sprintf (format, "%%x%%0%dx", HOST_BITS_PER_INT / 4);
1231 sprintf (digit_buffer, format, TREE_INT_CST_HIGH (val),
1232 TREE_INT_CST_LOW (val));
1233 OB_PUTCP (digit_buffer);
1237 OB_PUTI (TREE_INT_CST_LOW (t));
1242 #ifndef REAL_IS_NOT_DOUBLE
1243 sprintf (digit_buffer, "%g", TREE_REAL_CST (t));
1246 unsigned char *p = (unsigned char *) &TREE_REAL_CST (t);
1248 strcpy (digit_buffer, "0x");
1249 for (i = 0; i < sizeof TREE_REAL_CST (t); i++)
1250 sprintf (digit_buffer + 2 + 2*i, "%02x", *p++);
1253 OB_PUTCP (digit_buffer);
1258 char *p = TREE_STRING_POINTER (t);
1259 int len = TREE_STRING_LENGTH (t) - 1;
1263 for (i = 0; i < len; i++)
1270 dump_binary_op (",", t);
1275 dump_expr (TREE_OPERAND (t, 0), 0);
1277 dump_expr (TREE_OPERAND (t, 1), 0);
1279 dump_expr (TREE_OPERAND (t, 2), 0);
1284 if (TREE_HAS_CONSTRUCTOR (t))
1287 dump_type (TREE_TYPE (TREE_TYPE (t)), 0);
1288 PARM_DECL_EXPR (t) = 1;
1292 dump_expr (TREE_OPERAND (t, 0), 0);
1296 case AGGR_INIT_EXPR:
1297 OB_PUTID (TYPE_IDENTIFIER (TREE_TYPE (t)));
1299 if (TREE_OPERAND (t, 1))
1300 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)));
1306 tree fn = TREE_OPERAND (t, 0);
1307 tree args = TREE_OPERAND (t, 1);
1309 if (TREE_CODE (fn) == ADDR_EXPR)
1310 fn = TREE_OPERAND (fn, 0);
1312 if (TREE_TYPE (fn) != NULL_TREE && NEXT_CODE (fn) == METHOD_TYPE)
1314 tree ob = TREE_VALUE (args);
1315 if (TREE_CODE (ob) == ADDR_EXPR)
1317 dump_expr (TREE_OPERAND (ob, 0), 0);
1320 else if (TREE_CODE (ob) != PARM_DECL
1321 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
1324 OB_PUTC2 ('-', '>');
1326 args = TREE_CHAIN (args);
1330 dump_expr_list (args);
1336 /* Note that this only works for G++ target exprs. If somebody
1337 builds a general TARGET_EXPR, there's no way to represent that
1338 it initializes anything other that the parameter slot for the
1339 default argument. Note we may have cleared out the first
1340 operand in expand_expr, so don't go killing ourselves. */
1341 if (TREE_OPERAND (t, 1))
1342 dump_expr (TREE_OPERAND (t, 1), 0);
1349 case TRUNC_DIV_EXPR:
1350 case TRUNC_MOD_EXPR:
1358 case BIT_ANDTC_EXPR:
1359 case TRUTH_ANDIF_EXPR:
1360 case TRUTH_ORIF_EXPR:
1367 dump_binary_op (opname_tab[(int) TREE_CODE (t)], t);
1371 case FLOOR_DIV_EXPR:
1372 case ROUND_DIV_EXPR:
1373 dump_binary_op ("/", t);
1377 case FLOOR_MOD_EXPR:
1378 case ROUND_MOD_EXPR:
1379 dump_binary_op ("%", t);
1384 tree ob = TREE_OPERAND (t, 0);
1385 if (TREE_CODE (ob) == INDIRECT_REF)
1387 ob = TREE_OPERAND (ob, 0);
1388 if (TREE_CODE (ob) != PARM_DECL
1389 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
1392 OB_PUTC2 ('-', '>');
1400 dump_expr (TREE_OPERAND (t, 1), 1);
1405 dump_expr (TREE_OPERAND (t, 0), 0);
1407 dump_expr (TREE_OPERAND (t, 1), 0);
1412 dump_unary_op ("+", t, nop);
1416 if (TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL
1417 || TREE_CODE (TREE_OPERAND (t, 0)) == STRING_CST)
1418 dump_expr (TREE_OPERAND (t, 0), 0);
1420 dump_unary_op ("&", t, nop);
1424 if (TREE_HAS_CONSTRUCTOR (t))
1426 t = TREE_OPERAND (t, 0);
1427 my_friendly_assert (TREE_CODE (t) == CALL_EXPR, 237);
1428 dump_expr (TREE_OPERAND (t, 0), 0);
1430 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1)));
1435 if (TREE_OPERAND (t,0) != NULL_TREE
1436 && NEXT_CODE (TREE_OPERAND (t, 0)) == REFERENCE_TYPE)
1437 dump_expr (TREE_OPERAND (t, 0), nop);
1439 dump_unary_op ("*", t, nop);
1445 case TRUTH_NOT_EXPR:
1446 case PREDECREMENT_EXPR:
1447 case PREINCREMENT_EXPR:
1448 dump_unary_op (opname_tab [(int)TREE_CODE (t)], t, nop);
1451 case POSTDECREMENT_EXPR:
1452 case POSTINCREMENT_EXPR:
1454 dump_expr (TREE_OPERAND (t, 0), 0);
1455 OB_PUTCP (opname_tab[(int)TREE_CODE (t)]);
1459 case NON_LVALUE_EXPR:
1460 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
1461 should be another level of INDIRECT_REF so that I don't have to do
1463 if (TREE_TYPE (t) != NULL_TREE && NEXT_CODE (t) == POINTER_TYPE)
1465 tree next = TREE_TYPE (TREE_TYPE (t));
1467 while (TREE_CODE (next) == POINTER_TYPE)
1468 next = TREE_TYPE (next);
1470 if (TREE_CODE (next) == FUNCTION_TYPE)
1472 if (!nop) OB_PUTC ('(');
1474 dump_expr (TREE_OPERAND (t, 0), 1);
1475 if (!nop) OB_PUTC (')');
1480 dump_expr (TREE_OPERAND (t, 0), 0);
1484 dump_expr (TREE_OPERAND (t, 0), nop);
1488 if (TREE_TYPE (t) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t)))
1490 tree idx = build_component_ref (t, index_identifier, NULL_TREE, 0);
1492 if (integer_all_onesp (idx))
1494 tree pfn = PFN_FROM_PTRMEMFUNC (t);
1498 if (TREE_CODE (idx) == INTEGER_CST
1499 && TREE_INT_CST_HIGH (idx) == 0)
1502 unsigned HOST_WIDE_INT n;
1504 t = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t)));
1505 t = TYPE_METHOD_BASETYPE (t);
1506 virtuals = BINFO_VIRTUALS (TYPE_BINFO (TYPE_MAIN_VARIANT (t)));
1508 n = TREE_INT_CST_LOW (idx);
1510 /* Map vtable index back one, to allow for the null pointer to
1514 while (n > 0 && virtuals)
1517 virtuals = TREE_CHAIN (virtuals);
1521 dump_expr (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals)), 0);
1527 dump_expr_list (CONSTRUCTOR_ELTS (t));
1533 tree ob = TREE_OPERAND (t, 0);
1534 if (TREE_CODE (ob) == NOP_EXPR
1535 && TREE_OPERAND (ob, 0) == error_mark_node
1536 && TREE_CODE (TREE_OPERAND (t, 1)) == FUNCTION_DECL)
1538 dump_expr (TREE_OPERAND (t, 1), 0);
1541 dump_expr (TREE_OPERAND (t, 0), 0);
1543 dump_expr (TREE_OPERAND (t, 1), 0);
1548 case TEMPLATE_PARM_INDEX:
1549 dump_decl (TEMPLATE_PARM_DECL (t), -1);
1552 case IDENTIFIER_NODE:
1557 dump_type (TREE_OPERAND (t, 0), 0);
1559 dump_expr (TREE_OPERAND (t, 1), 0);
1563 if (TREE_OPERAND (t, 0) == NULL_TREE
1564 || TREE_CHAIN (TREE_OPERAND (t, 0)))
1566 dump_type (TREE_TYPE (t), 0);
1568 dump_expr_list (TREE_OPERAND (t, 0));
1574 dump_type (TREE_TYPE (t), 0);
1577 dump_expr_list (TREE_OPERAND (t, 0));
1583 OB_PUTID (TREE_OPERAND (t, 0));
1588 if (TREE_CODE (t) == SIZEOF_EXPR)
1589 OB_PUTS ("sizeof (");
1592 my_friendly_assert (TREE_CODE (t) == ALIGNOF_EXPR, 0);
1593 OB_PUTS ("__alignof__ (");
1595 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t, 0))) == 't')
1596 dump_type (TREE_OPERAND (t, 0), 0);
1598 dump_unary_op ("*", t, 0);
1603 OB_PUTS ("{unparsed}");
1606 case TRY_CATCH_EXPR:
1607 case WITH_CLEANUP_EXPR:
1608 case CLEANUP_POINT_EXPR:
1609 dump_expr (TREE_OPERAND (t, 0), nop);
1613 if (TREE_VALUE (t) && TREE_CODE (TREE_VALUE (t)) == FUNCTION_DECL)
1615 OB_PUTID (DECL_NAME (TREE_VALUE (t)));
1618 /* else fall through */
1620 /* This list is incomplete, but should suffice for now.
1621 It is very important that `sorry' does not call
1622 `report_error_function'. That could cause an infinite loop. */
1624 sorry ("`%s' not supported by dump_expr",
1625 tree_code_name[(int) TREE_CODE (t)]);
1627 /* fall through to ERROR_MARK... */
1629 OB_PUTCP ("{error}");
1635 dump_binary_op (opstring, t)
1640 dump_expr (TREE_OPERAND (t, 0), 1);
1642 OB_PUTCP (opstring);
1644 dump_expr (TREE_OPERAND (t, 1), 1);
1649 dump_unary_op (opstring, t, nop)
1654 if (!nop) OB_PUTC ('(');
1655 OB_PUTCP (opstring);
1656 dump_expr (TREE_OPERAND (t, 0), 1);
1657 if (!nop) OB_PUTC (')');
1661 fndecl_as_string (fndecl, print_ret_type_p)
1663 int print_ret_type_p;
1665 return decl_as_string (fndecl, print_ret_type_p);
1668 /* Same, but handle a _TYPE.
1669 Called from convert_to_reference, mangle_class_name_for_template,
1670 build_unary_op, and GNU_xref_decl. If CANONICAL_NAME is non-zero,
1671 when describing a typedef, we use the name of the type described,
1672 rather than the name of the typedef. */
1675 type_as_string_real (typ, v, canonical_name)
1682 dump_type_real (typ, v, canonical_name);
1686 return (char *)obstack_base (&scratch_obstack);
1691 type_as_string (typ, v)
1695 return type_as_string_real (typ, v, 0);
1699 expr_as_string (decl, v)
1705 dump_expr (decl, 1);
1709 return (char *)obstack_base (&scratch_obstack);
1712 /* A cross between type_as_string and fndecl_as_string.
1713 Only called from substitute_nice_name. */
1716 decl_as_string (decl, v)
1722 dump_decl (decl, v);
1726 return (char *)obstack_base (&scratch_obstack);
1729 /* Generate the three forms of printable names for lang_printable_name. */
1732 lang_decl_name (decl, v)
1737 return decl_as_string (decl, 1);
1741 if (v == 1 && DECL_CONTEXT (decl)
1742 && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (decl))) == 't')
1745 if (TREE_CODE (decl) == FUNCTION_DECL)
1746 cname = DECL_CLASS_CONTEXT (decl);
1748 cname = DECL_CONTEXT (decl);
1749 dump_type (cname, 0);
1750 OB_PUTC2 (':', ':');
1753 if (TREE_CODE (decl) == FUNCTION_DECL)
1754 dump_function_name (decl);
1756 dump_decl (DECL_NAME (decl), 0);
1760 return (char *)obstack_base (&scratch_obstack);
1768 if (TREE_CODE (t) == PARM_DECL)
1769 return DECL_SOURCE_FILE (DECL_CONTEXT (t));
1770 else if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
1771 return DECL_SOURCE_FILE (TYPE_MAIN_DECL (t));
1773 return DECL_SOURCE_FILE (t);
1781 if (TREE_CODE (t) == PARM_DECL)
1782 line = DECL_SOURCE_LINE (DECL_CONTEXT (t));
1783 if (TREE_CODE (t) == TYPE_DECL && DECL_ARTIFICIAL (t))
1786 if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
1787 line = DECL_SOURCE_LINE (TYPE_MAIN_DECL (t));
1789 line = DECL_SOURCE_LINE (t);
1798 code_as_string (c, v)
1802 return tree_code_name [c];
1806 language_as_string (c, v)
1815 case lang_cplusplus:
1819 my_friendly_abort (355);
1824 /* Return the proper printed version of a parameter to a C++ function. */
1827 parm_as_string (p, v)
1833 sprintf (digit_buffer, "%d", p+1);
1834 return digit_buffer;
1842 static char buf[] = "operator ";
1847 strcpy (buf + 9, opname_tab [p]);
1852 assop_as_string (p, v)
1856 static char buf[] = "operator ";
1861 strcpy (buf + 9, assignop_tab [p]);
1866 args_as_string (p, v)
1873 if (TREE_CODE_CLASS (TREE_CODE (TREE_VALUE (p))) == 't')
1874 return type_as_string (p, v);
1877 for (; p; p = TREE_CHAIN (p))
1879 if (TREE_VALUE (p) == null_node)
1882 dump_type (error_type (TREE_VALUE (p)), v);
1887 return (char *)obstack_base (&scratch_obstack);
1897 dump_readonly_or_volatile (p, before);
1901 return (char *)obstack_base (&scratch_obstack);