1 /* Call-backs for C++ error reporting.
2 This code is non-reentrant.
3 Copyright (C) 1993, 94, 95, 96, 97, 98, 99, 2000
4 Free Software Foundation, Inc.
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
30 typedef const char *cp_printer ();
32 #define obstack_chunk_alloc xmalloc
33 #define obstack_chunk_free free
35 /* Obstack where we build text strings for overloading, etc. */
36 static struct obstack scratch_obstack
;
37 static char *scratch_firstobj
;
39 # define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
40 # define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
41 # define OB_PUTC2(C1,C2) \
42 (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
43 # define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
44 # define OB_PUTID(ID) \
45 (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \
46 IDENTIFIER_LENGTH (ID)))
47 # define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
48 # define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
49 # define OB_PUTI(CST) do { sprintf (digit_buffer, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT)(CST)); \
50 OB_PUTCP (digit_buffer); } while (0)
52 # define OB_END_TEMPLATE_ID() \
53 (((obstack_next_free (&scratch_obstack) != obstack_base (&scratch_obstack) \
54 && obstack_next_free (&scratch_obstack)[-1] == '>') \
55 ? OB_PUTC (' ') : (void)0), OB_PUTC ('>'))
57 # define NEXT_CODE(t) (TREE_CODE (TREE_TYPE (t)))
59 enum pad
{ none
, before
, after
};
61 static const char *args_to_string
PARAMS ((tree
, int));
62 static const char *assop_to_string
PARAMS ((enum tree_code
, int));
63 static const char *code_to_string
PARAMS ((enum tree_code
, int));
64 static const char *cv_to_string
PARAMS ((tree
, int));
65 static const char *decl_to_string
PARAMS ((tree
, int));
66 static const char *expr_to_string
PARAMS ((tree
, int));
67 static const char *fndecl_to_string
PARAMS ((tree
, int));
68 static const char *language_to_string
PARAMS ((enum languages
, int));
69 static const char *op_to_string
PARAMS ((enum tree_code
, int));
70 static const char *parm_to_string
PARAMS ((int, int));
71 static const char *type_to_string
PARAMS ((tree
, int));
73 static void dump_type
PARAMS ((tree
, enum tree_string_flags
));
74 static void dump_simple_decl
PARAMS ((tree
, tree
, enum tree_string_flags
));
75 static void dump_decl
PARAMS ((tree
, enum tree_string_flags
));
76 static void dump_template_decl
PARAMS ((tree
, enum tree_string_flags
));
77 static void dump_function_decl
PARAMS ((tree
, enum tree_string_flags
));
78 static void dump_expr
PARAMS ((tree
, enum tree_string_flags
));
79 static void dump_unary_op
PARAMS ((const char *, tree
, enum tree_string_flags
));
80 static void dump_binary_op
PARAMS ((const char *, tree
, enum tree_string_flags
));
81 static void dump_aggr_type
PARAMS ((tree
, enum tree_string_flags
));
82 static enum pad dump_type_prefix
PARAMS ((tree
, enum tree_string_flags
));
83 static void dump_type_suffix
PARAMS ((tree
, enum tree_string_flags
));
84 static void dump_function_name
PARAMS ((tree
, enum tree_string_flags
));
85 static void dump_expr_list
PARAMS ((tree
, enum tree_string_flags
));
86 static void dump_global_iord
PARAMS ((tree
));
87 static enum pad dump_qualifiers
PARAMS ((tree
, enum pad
));
88 static void dump_char
PARAMS ((int));
89 static void dump_parameters
PARAMS ((tree
, enum tree_string_flags
));
90 static void dump_exception_spec
PARAMS ((tree
, enum tree_string_flags
));
91 static const char *aggr_variety
PARAMS ((tree
));
92 static tree ident_fndecl
PARAMS ((tree
));
93 static void dump_template_argument
PARAMS ((tree
, enum tree_string_flags
));
94 static void dump_template_argument_list
PARAMS ((tree
, enum tree_string_flags
));
95 static void dump_template_parameter
PARAMS ((tree
, enum tree_string_flags
));
96 static void dump_template_bindings
PARAMS ((tree
, tree
));
97 static void dump_scope
PARAMS ((tree
, enum tree_string_flags
));
98 static void dump_template_parms
PARAMS ((tree
, int, enum tree_string_flags
));
100 #define A args_to_string
101 #define C code_to_string
102 #define D decl_to_string
103 #define E expr_to_string
104 #define F fndecl_to_string
105 #define L language_to_string
106 #define O op_to_string
107 #define P parm_to_string
108 #define Q assop_to_string
109 #define T type_to_string
110 #define V cv_to_string
112 #define o (cp_printer *) 0
113 cp_printer
* cp_printers
[256] =
115 /*0 1 2 3 4 5 6 7 8 9 A B C D E F */
116 o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, /* 0x00 */
117 o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, /* 0x10 */
118 o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, /* 0x20 */
119 o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, /* 0x30 */
120 o
, A
, o
, C
, D
, E
, F
, o
, o
, o
, o
, o
, L
, o
, o
, O
, /* 0x40 */
121 P
, Q
, o
, o
, T
, o
, V
, o
, o
, o
, o
, o
, o
, o
, o
, o
, /* 0x50 */
122 o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, /* 0x60 */
123 o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, /* 0x70 */
140 gcc_obstack_init (&scratch_obstack
);
141 scratch_firstobj
= (char *)obstack_alloc (&scratch_obstack
, 0);
144 /* Dump a scope, if deemed necessary. */
147 dump_scope (scope
, flags
)
149 enum tree_string_flags flags
;
151 if (scope
== NULL_TREE
)
154 if (TREE_CODE (scope
) == NAMESPACE_DECL
)
156 if (scope
!= global_namespace
)
158 dump_decl (scope
, (flags
& (TS_PEDANTIC_NAME
| TS_FUNC_SCOPE
| TS_CHASE_TYPEDEFS
))
159 | TS_FUNC_NORETURN
| TS_DECL_TYPE
);
162 else if (flags
& TS_PEDANTIC_NAME
)
165 else if (AGGREGATE_TYPE_P (scope
))
167 dump_type (scope
, (flags
& (TS_PEDANTIC_NAME
| TS_FUNC_SCOPE
| TS_CHASE_TYPEDEFS
))
168 | TS_FUNC_NORETURN
| TS_DECL_TYPE
);
171 else if ((flags
& (TS_PEDANTIC_NAME
| TS_FUNC_SCOPE
))
172 && TREE_CODE (scope
) == FUNCTION_DECL
)
174 dump_function_decl (scope
, (flags
& (TS_PEDANTIC_NAME
| TS_FUNC_SCOPE
| TS_CHASE_TYPEDEFS
))
175 | TS_FUNC_NORETURN
| TS_DECL_TYPE
);
180 /* Dump type qualifiers, providing padding as requested. Return an
181 indication of whether we dumped something. */
184 dump_qualifiers (t
, p
)
188 static const int masks
[] =
189 {TYPE_QUAL_CONST
, TYPE_QUAL_VOLATILE
, TYPE_QUAL_RESTRICT
};
190 static const char *const names
[] =
191 {"const", "volatile", "__restrict"};
193 int quals
= TYPE_QUALS (t
);
194 int do_after
= p
== after
;
198 for (ix
= 0; ix
!= 3; ix
++)
199 if (masks
[ix
] & quals
)
204 OB_PUTCP (names
[ix
]);
214 /* This must be large enough to hold any printed integer or floating-point
216 static char digit_buffer
[128];
218 /* Dump the template ARGument under control of FLAGS. */
221 dump_template_argument (arg
, flags
)
223 enum tree_string_flags flags
;
225 if (TREE_CODE_CLASS (TREE_CODE (arg
)) == 't'
226 || TREE_CODE (arg
) == TEMPLATE_DECL
)
227 dump_type (arg
, flags
& ~TS_AGGR_TAGS
);
229 dump_expr (arg
, (flags
| TS_EXPR_PARENS
) & ~TS_AGGR_TAGS
);
232 /* Dump a template-argument-list ARGS (always a TREE_VEC) under control
236 dump_template_argument_list (args
, flags
)
238 enum tree_string_flags flags
;
240 int n
= TREE_VEC_LENGTH (args
);
244 for (i
= 0; i
< n
; ++i
)
248 dump_template_argument (TREE_VEC_ELT (args
, i
), flags
);
253 /* Dump a template parameter PARM (a TREE_LIST) under control of FLAGS. */
256 dump_template_parameter (parm
, flags
)
258 enum tree_string_flags flags
;
260 tree p
= TREE_VALUE (parm
);
261 tree a
= TREE_PURPOSE (parm
);
263 if (TREE_CODE (p
) == TYPE_DECL
)
265 if (flags
& TS_DECL_TYPE
)
271 OB_PUTID (DECL_NAME (p
));
274 else if (DECL_NAME (p
))
275 OB_PUTID (DECL_NAME (p
));
277 OB_PUTS ("{template default argument error}");
280 dump_decl (p
, flags
| TS_DECL_TYPE
);
282 if ((flags
& TS_PARM_DEFAULTS
) && a
!= NULL_TREE
)
285 if (TREE_CODE (a
) == TYPE_DECL
|| TREE_CODE (a
) == TEMPLATE_DECL
)
286 dump_type (a
, flags
& ~TS_CHASE_TYPEDEFS
);
288 dump_expr (a
, flags
| TS_EXPR_PARENS
);
292 /* Dump, under control of FLAGS, a template-parameter-list binding.
293 PARMS is a TREE_LIST of TREE_VEC of TREE_LIST and ARGS is a
297 dump_template_bindings (parms
, args
)
304 tree p
= TREE_VALUE (parms
);
305 int lvl
= TMPL_PARMS_DEPTH (parms
);
309 for (i
= 0; i
< TREE_VEC_LENGTH (p
); ++i
)
311 tree arg
= TMPL_ARG (args
, lvl
, arg_idx
);
315 dump_template_parameter (TREE_VEC_ELT (p
, i
), TS_PLAIN
);
318 dump_template_argument (arg
, TS_PLAIN
);
320 OB_PUTS ("{missing}");
326 parms
= TREE_CHAIN (parms
);
330 /* Dump into the obstack a human-readable equivalent of TYPE. FLAGS
331 controls the format. */
336 enum tree_string_flags flags
;
341 if (TYPE_PTRMEMFUNC_P (t
))
344 switch (TREE_CODE (t
))
347 OB_PUTS ("{unknown type}");
351 /* A list of function parms. */
352 dump_parameters (t
, flags
);
355 case IDENTIFIER_NODE
:
360 dump_type (BINFO_TYPE (t
), flags
);
366 dump_aggr_type (t
, flags
);
370 if (flags
& TS_CHASE_TYPEDEFS
)
372 dump_type (DECL_ORIGINAL_TYPE (t
)
373 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
), flags
);
376 /* else fallthrough */
380 dump_decl (t
, flags
& ~TS_DECL_TYPE
);
384 OB_PUTS ("complex ");
385 dump_type (TREE_TYPE (t
), flags
);
389 if (!TREE_UNSIGNED (TYPE_MAIN_VARIANT (t
)) && TREE_UNSIGNED (t
))
390 OB_PUTS ("unsigned ");
391 else if (TREE_UNSIGNED (TYPE_MAIN_VARIANT (t
)) && !TREE_UNSIGNED (t
))
400 dump_qualifiers (t
, after
);
401 type
= flags
& TS_CHASE_TYPEDEFS
? TYPE_MAIN_VARIANT (t
) : t
;
402 if (TYPE_NAME (type
) && TYPE_IDENTIFIER (type
))
403 OB_PUTID (TYPE_IDENTIFIER (type
));
405 /* Types like intQI_type_node and friends have no names.
406 These don't come up in user error messages, but it's nice
407 to be able to print them from the debugger. */
408 OB_PUTS ("{anonymous}");
412 case TEMPLATE_TEMPLATE_PARM
:
413 if (!TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t
))
415 /* For parameters inside template signature. */
416 if (TYPE_IDENTIFIER (t
))
417 OB_PUTID (TYPE_IDENTIFIER (t
));
419 OB_PUTS ("{anonymous template template parameter}");
423 tree args
= TYPE_TI_ARGS (t
);
424 OB_PUTID (TYPE_IDENTIFIER (t
));
426 dump_template_argument_list (args
, flags
);
427 OB_END_TEMPLATE_ID ();
431 case TEMPLATE_TYPE_PARM
:
432 dump_qualifiers (t
, after
);
433 if (TYPE_IDENTIFIER (t
))
434 OB_PUTID (TYPE_IDENTIFIER (t
));
436 OB_PUTS ("{anonymous template type parameter}");
439 /* This is not always necessary for pointers and such, but doing this
440 reduces code size. */
449 dump_type_prefix (t
, flags
);
450 dump_type_suffix (t
, flags
);
454 OB_PUTS ("typename ");
455 dump_type (TYPE_CONTEXT (t
), flags
);
457 dump_decl (TYPENAME_TYPE_FULLNAME (t
), flags
);
461 OB_PUTS ("__typeof (");
462 dump_expr (TYPE_FIELDS (t
), flags
& ~TS_EXPR_PARENS
);
467 sorry ("`%s' not supported by dump_type",
468 tree_code_name
[(int) TREE_CODE (t
)]);
469 /* Fall through to error. */
472 OB_PUTS ("{type error}");
477 /* Return the name of the supplied aggregate, or enumeral type. */
483 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
485 else if (TREE_CODE (t
) == UNION_TYPE
)
487 else if (TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_DECLARED_CLASS (t
))
493 /* Print out a class declaration T under the control of FLAGS,
494 in the form `class foo'. */
497 dump_aggr_type (t
, flags
)
499 enum tree_string_flags flags
;
502 const char *variety
= aggr_variety (t
);
506 dump_qualifiers (t
, after
);
508 if (flags
& TS_AGGR_TAGS
)
514 if (flags
& TS_CHASE_TYPEDEFS
)
515 t
= TYPE_MAIN_VARIANT (t
);
517 name
= TYPE_NAME (t
);
521 typdef
= !DECL_ARTIFICIAL (name
);
522 tmplate
= !typdef
&& TREE_CODE (t
) != ENUMERAL_TYPE
523 && TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_TEMPLATE_INFO (t
)
524 && (CLASSTYPE_TEMPLATE_SPECIALIZATION (t
)
525 || TREE_CODE (CLASSTYPE_TI_TEMPLATE (t
)) != TEMPLATE_DECL
526 || DECL_TEMPLATE_SPECIALIZATION (CLASSTYPE_TI_TEMPLATE (t
))
527 || PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t
)));
528 dump_scope (CP_DECL_CONTEXT (name
), flags
| TS_FUNC_SCOPE
);
531 /* Because the template names are mangled, we have to locate
532 the most general template, and use that name. */
533 tree tpl
= CLASSTYPE_TI_TEMPLATE (t
);
535 while (DECL_TEMPLATE_INFO (tpl
))
536 tpl
= DECL_TI_TEMPLATE (tpl
);
539 name
= DECL_NAME (name
);
542 if (name
== 0 || ANON_AGGRNAME_P (name
))
544 OB_PUTS ("{anonymous");
545 if (!(flags
& TS_AGGR_TAGS
))
555 dump_template_parms (TYPE_TEMPLATE_INFO (t
),
556 !CLASSTYPE_USE_TEMPLATE (t
),
557 flags
& ~TS_TEMPLATE_PREFIX
);
560 /* Dump into the obstack the initial part of the output for a given type.
561 This is necessary when dealing with things like functions returning
564 return type of `int (* fee ())()': pointer -> function -> int. Both
565 pointer (and reference and offset) and function (and member) types must
566 deal with prefix and suffix.
568 Arrays must also do this for DECL nodes, like int a[], and for things like
571 Return indicates how you should pad an object name after this. I.e. you
572 want to pad non-*, non-& cores, but not pad * or & types. */
575 dump_type_prefix (t
, flags
)
577 enum tree_string_flags flags
;
579 enum pad padding
= before
;
581 if (TYPE_PTRMEMFUNC_P (t
))
583 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
587 switch (TREE_CODE (t
))
592 tree sub
= TREE_TYPE (t
);
594 padding
= dump_type_prefix (sub
, flags
);
595 /* A tree for a member pointer looks like pointer to offset,
596 so let the OFFSET_TYPE case handle it. */
597 if (!TYPE_PTRMEM_P (t
))
601 if (TREE_CODE (sub
) == ARRAY_TYPE
)
603 OB_PUTC ("&*"[TREE_CODE (t
) == POINTER_TYPE
]);
604 padding
= dump_qualifiers (t
, none
);
611 padding
= dump_type_prefix (TREE_TYPE (t
), flags
);
612 if (TREE_CODE (t
) == OFFSET_TYPE
) /* pmfs deal with this in d_t_p */
616 dump_type (TYPE_OFFSET_BASETYPE (t
), flags
);
620 padding
= dump_qualifiers (t
, none
);
623 /* Can only be reached through function pointer -- this would not be
624 correct if FUNCTION_DECLs used it. */
626 padding
= dump_type_prefix (TREE_TYPE (t
), flags
);
634 padding
= dump_type_prefix (TREE_TYPE (t
), flags
);
639 dump_aggr_type (TYPE_METHOD_BASETYPE (t
), flags
);
644 padding
= dump_type_prefix (TREE_TYPE (t
), flags
);
648 case IDENTIFIER_NODE
:
653 case TEMPLATE_TYPE_PARM
:
654 case TEMPLATE_TEMPLATE_PARM
:
663 dump_type (t
, flags
);
668 sorry ("`%s' not supported by dump_type_prefix",
669 tree_code_name
[(int) TREE_CODE (t
)]);
672 OB_PUTS ("{typeprefixerror}");
678 /* Dump the suffix of type T, under control of FLAGS. This is the part
679 which appears after the identifier (or function parms). */
682 dump_type_suffix (t
, flags
)
684 enum tree_string_flags flags
;
686 if (TYPE_PTRMEMFUNC_P (t
))
687 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
689 switch (TREE_CODE (t
))
694 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
696 dump_type_suffix (TREE_TYPE (t
), flags
);
699 /* Can only be reached through function pointer */
705 arg
= TYPE_ARG_TYPES (t
);
706 if (TREE_CODE (t
) == METHOD_TYPE
)
707 arg
= TREE_CHAIN (arg
);
709 /* Function pointers don't have default args. Not in standard C++,
710 anyway; they may in g++, but we'll just pretend otherwise. */
711 dump_parameters (arg
, flags
& ~TS_PARM_DEFAULTS
);
713 if (TREE_CODE (t
) == METHOD_TYPE
)
715 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t
))), before
);
716 dump_type_suffix (TREE_TYPE (t
), flags
);
717 dump_exception_spec (TYPE_RAISES_EXCEPTIONS (t
), flags
);
725 if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (t
))) == INTEGER_CST
)
726 OB_PUTI (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (t
))) + 1);
727 else if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (t
))) == MINUS_EXPR
)
728 dump_expr (TREE_OPERAND (TYPE_MAX_VALUE (TYPE_DOMAIN (t
)), 0),
729 flags
& ~TS_EXPR_PARENS
);
731 dump_expr (fold (build_binary_op
732 (PLUS_EXPR
, TYPE_MAX_VALUE (TYPE_DOMAIN (t
)),
734 flags
& ~TS_EXPR_PARENS
);
737 dump_type_suffix (TREE_TYPE (t
), flags
);
741 case IDENTIFIER_NODE
:
746 case TEMPLATE_TYPE_PARM
:
747 case TEMPLATE_TEMPLATE_PARM
:
759 sorry ("`%s' not supported by dump_type_suffix",
760 tree_code_name
[(int) TREE_CODE (t
)]);
763 /* Don't mark it here, we should have already done in
769 /* Return a function declaration which corresponds to the IDENTIFIER_NODE
776 tree n
= lookup_name (t
, 0);
781 if (TREE_CODE (n
) == FUNCTION_DECL
)
783 else if (TREE_CODE (n
) == TREE_LIST
784 && TREE_CODE (TREE_VALUE (n
)) == FUNCTION_DECL
)
785 return TREE_VALUE (n
);
787 my_friendly_abort (66);
791 #ifndef NO_DOLLAR_IN_LABEL
792 # define GLOBAL_THING "_GLOBAL_$"
794 # ifndef NO_DOT_IN_LABEL
795 # define GLOBAL_THING "_GLOBAL_."
797 # define GLOBAL_THING "_GLOBAL__"
801 #define GLOBAL_IORD_P(NODE) \
802 ! strncmp (IDENTIFIER_POINTER(NODE), GLOBAL_THING, sizeof (GLOBAL_THING) - 1)
808 const char *name
= IDENTIFIER_POINTER (t
);
810 OB_PUTS ("(static ");
811 if (name
[sizeof (GLOBAL_THING
) - 1] == 'I')
812 OB_PUTS ("initializers");
813 else if (name
[sizeof (GLOBAL_THING
) - 1] == 'D')
814 OB_PUTS ("destructors");
816 my_friendly_abort (352);
819 OB_PUTCP (input_filename
);
824 dump_simple_decl (t
, type
, flags
)
827 enum tree_string_flags flags
;
829 if (flags
& TS_DECL_TYPE
)
831 if (dump_type_prefix (type
, flags
) != none
)
834 if (!DECL_INITIAL (t
) || TREE_CODE (DECL_INITIAL (t
)) != TEMPLATE_PARM_INDEX
)
835 dump_scope (CP_DECL_CONTEXT (t
), flags
);
837 dump_decl (DECL_NAME (t
), flags
);
839 OB_PUTS ("{anonymous}");
840 if (flags
& TS_DECL_TYPE
)
841 dump_type_suffix (type
, flags
);
844 /* Dump a human readable string for the decl T under control of FLAGS. */
849 enum tree_string_flags flags
;
854 switch (TREE_CODE (t
))
858 /* Don't say 'typedef class A' */
859 if (DECL_ARTIFICIAL (t
))
861 if ((flags
& TS_DECL_TYPE
)
862 && TREE_CODE (TREE_TYPE (t
)) == TEMPLATE_TYPE_PARM
)
863 /* Say `class T' not just `T'. */
866 dump_type (TREE_TYPE (t
), flags
);
870 if (flags
& TS_DECORATE
)
871 OB_PUTS ("typedef ");
872 dump_simple_decl (t
, DECL_ORIGINAL_TYPE (t
)
873 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
),
878 if (DECL_NAME (t
) && VTABLE_NAME_P (DECL_NAME (t
)))
880 OB_PUTS ("vtable for ");
881 if (TYPE_P (DECL_CONTEXT (t
)))
882 dump_type (DECL_CONTEXT (t
), flags
);
884 /* This case can arise with -fno-vtable-thunks. See
885 expand_upcast_fixups. It's not clear what to print
887 OB_PUTS ("{unknown type}");
890 /* else fall through */
893 dump_simple_decl (t
, TREE_TYPE (t
), flags
);
897 OB_PUTS ("{return} ");
898 dump_simple_decl (t
, TREE_TYPE (t
), flags
);
902 dump_scope (CP_DECL_CONTEXT (t
), flags
);
903 if (DECL_NAME (t
) == anonymous_namespace_name
)
904 OB_PUTS ("{unnamed}");
906 OB_PUTID (DECL_NAME (t
));
910 dump_decl (TREE_OPERAND (t
, 0), flags
& ~TS_DECL_TYPE
);
912 dump_decl (TREE_OPERAND (t
, 1), flags
);
916 dump_decl (TREE_OPERAND (t
, 0), flags
);
918 dump_decl (TREE_OPERAND (t
, 1), flags
);
922 /* So that we can do dump_decl on an aggr type. */
926 dump_type (t
, flags
);
930 my_friendly_abort (69);
933 /* These special cases are duplicated here so that other functions
934 can feed identifiers to cp_error and get them demangled properly. */
935 case IDENTIFIER_NODE
:
937 if (DESTRUCTOR_NAME_P (t
)
938 && (f
= ident_fndecl (t
))
939 && DECL_LANGUAGE (f
) == lang_cplusplus
)
942 dump_decl (DECL_NAME (f
), flags
);
944 else if (IDENTIFIER_TYPENAME_P (t
))
946 OB_PUTS ("operator ");
947 /* Not exactly IDENTIFIER_TYPE_VALUE. */
948 dump_type (TREE_TYPE (t
), flags
);
951 else if (IDENTIFIER_OPNAME_P (t
))
953 const char *name_string
= operator_name_string (t
);
954 OB_PUTS ("operator");
955 if (ISALPHA (name_string
[0]))
957 OB_PUTCP (name_string
);
969 if (GLOBAL_IORD_P (DECL_ASSEMBLER_NAME (t
)))
970 dump_global_iord (DECL_ASSEMBLER_NAME (t
));
971 else if (! DECL_LANG_SPECIFIC (t
))
972 OB_PUTS ("{internal}");
973 else if (flags
& TS_PEDANTIC_NAME
)
974 dump_function_decl (t
, flags
| TS_FUNC_NORETURN
| TS_DECL_TYPE
);
976 dump_function_decl (t
, flags
);
980 if (flags
& TS_PEDANTIC_NAME
)
981 dump_template_decl (t
, flags
| TS_FUNC_NORETURN
| TS_DECL_TYPE
);
983 dump_template_decl (t
, flags
);
986 case TEMPLATE_ID_EXPR
:
989 tree name
= TREE_OPERAND (t
, 0);
990 if (is_overloaded_fn (name
))
991 name
= DECL_NAME (get_first_fn (name
));
992 dump_decl (name
, flags
);
994 for (args
= TREE_OPERAND (t
, 1); args
; args
= TREE_CHAIN (args
))
996 dump_template_argument (TREE_VALUE (args
), flags
);
997 if (TREE_CHAIN (args
))
1000 OB_END_TEMPLATE_ID ();
1005 dump_decl (TREE_OPERAND (t
, 0), flags
);
1009 OB_PUTID (DECL_NAME (t
));
1013 if ((TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == ENUMERAL_TYPE
)
1014 || (DECL_INITIAL (t
) &&
1015 TREE_CODE (DECL_INITIAL (t
)) == TEMPLATE_PARM_INDEX
))
1016 dump_simple_decl (t
, TREE_TYPE (t
), flags
);
1017 else if (DECL_NAME (t
))
1018 dump_decl (DECL_NAME (t
), flags
);
1019 else if (DECL_INITIAL (t
))
1020 dump_expr (DECL_INITIAL (t
), flags
| TS_EXPR_PARENS
);
1022 OB_PUTS ("enumerator");
1027 dump_type (DECL_INITIAL (t
), flags
);
1029 OB_PUTID (DECL_NAME (t
));
1033 sorry ("`%s' not supported by dump_decl",
1034 tree_code_name
[(int) TREE_CODE (t
)]);
1035 /* Fallthrough to error. */
1038 OB_PUTS ("{declaration error}");
1043 /* Dump a template declaration T under control of FLAGS. This means the
1044 'template <...> leaders plus the 'class X' or 'void fn(...)' part. */
1047 dump_template_decl (t
, flags
)
1049 enum tree_string_flags flags
;
1051 tree orig_parms
= DECL_TEMPLATE_PARMS (t
);
1055 if (flags
& TS_TEMPLATE_PREFIX
)
1057 for (parms
= orig_parms
= nreverse (orig_parms
);
1059 parms
= TREE_CHAIN (parms
))
1061 tree inner_parms
= INNERMOST_TEMPLATE_PARMS (parms
);
1062 int len
= TREE_VEC_LENGTH (inner_parms
);
1064 OB_PUTS ("template <");
1065 for (i
= 0; i
< len
; i
++)
1069 dump_template_parameter (TREE_VEC_ELT (inner_parms
, i
), flags
);
1071 OB_END_TEMPLATE_ID ();
1074 nreverse(orig_parms
);
1075 /* If we've shown the template<args> prefix, we'd better show the
1077 flags
|= TS_DECL_TYPE
;
1079 if (TREE_CODE (DECL_TEMPLATE_RESULT (t
)) == TYPE_DECL
)
1080 dump_type (TREE_TYPE (t
),
1081 ((flags
& ~TS_AGGR_TAGS
) | TS_TEMPLATE_PLAIN
1082 | (flags
& TS_DECL_TYPE
? TS_AGGR_TAGS
: 0)));
1083 else if (TREE_CODE (DECL_TEMPLATE_RESULT (t
)) == VAR_DECL
)
1084 dump_decl (DECL_TEMPLATE_RESULT (t
), flags
| TS_TEMPLATE_PLAIN
);
1085 else if (TREE_TYPE (t
) == NULL_TREE
)
1086 my_friendly_abort (353);
1088 switch (NEXT_CODE (t
))
1092 dump_function_decl (t
, flags
| TS_TEMPLATE_PLAIN
);
1095 /* This case can occur with some illegal code. */
1096 dump_type (TREE_TYPE (t
),
1097 (flags
& ~TS_AGGR_TAGS
) | TS_TEMPLATE_PLAIN
1098 | (flags
& TS_DECL_TYPE
? TS_AGGR_TAGS
: 0));
1102 /* Pretty print a function decl. There are several ways we want to print a
1103 function declaration. The TS_FUNC bits in FLAGS tells us how to behave.
1104 As cp_error can only apply the '#' flag once to give 0 and 1 for V, there
1105 is %D which doesn't print the throw specs, and %F which does. */
1108 dump_function_decl (t
, flags
)
1110 enum tree_string_flags flags
;
1114 tree cname
= NULL_TREE
;
1115 tree template_args
= NULL_TREE
;
1116 tree template_parms
= NULL_TREE
;
1117 int show_return
= !(flags
& TS_FUNC_NORETURN
) && (flags
& TS_DECL_TYPE
);
1119 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1120 t
= DECL_TEMPLATE_RESULT (t
);
1122 /* Pretty print template instantiations only. */
1123 if (DECL_USE_TEMPLATE (t
) && DECL_TEMPLATE_INFO (t
))
1125 template_args
= DECL_TI_ARGS (t
);
1126 t
= most_general_template (t
);
1127 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1128 template_parms
= DECL_TEMPLATE_PARMS (t
);
1131 fntype
= TREE_TYPE (t
);
1132 parmtypes
= TYPE_ARG_TYPES (fntype
);
1134 /* Friends have DECL_CLASS_CONTEXT set, but not DECL_CONTEXT. */
1135 if (DECL_CLASS_SCOPE_P (t
))
1136 cname
= DECL_CLASS_CONTEXT (t
);
1137 /* this is for partially instantiated template methods */
1138 else if (TREE_CODE (fntype
) == METHOD_TYPE
)
1139 cname
= TREE_TYPE (TREE_VALUE (parmtypes
));
1141 if (!(flags
& TS_DECORATE
))
1143 else if (DECL_STATIC_FUNCTION_P (t
))
1144 OB_PUTS ("static ");
1145 else if (TYPE_POLYMORPHIC_P (t
))
1146 OB_PUTS ("virtual ");
1148 /* Print the return type? */
1150 show_return
= !DECL_CONV_FN_P (t
) && !DECL_CONSTRUCTOR_P (t
)
1151 && !DECL_DESTRUCTOR_P (t
);
1154 if (dump_type_prefix (TREE_TYPE (fntype
), flags
) != none
)
1158 /* Print the function name. */
1161 dump_type (cname
, flags
);
1165 dump_scope (CP_DECL_CONTEXT (t
), flags
);
1167 dump_function_name (t
, flags
);
1169 if (!(flags
& TS_DECL_TYPE
))
1171 if (TREE_CODE (fntype
) == METHOD_TYPE
&& parmtypes
)
1172 /* Skip "this" parameter. */
1173 parmtypes
= TREE_CHAIN (parmtypes
);
1175 if (DECL_DESTRUCTOR_P (t
) || DECL_CONSTRUCTOR_FOR_VBASE_P (t
))
1176 /* Skip past "in_charge" identifier. */
1177 parmtypes
= TREE_CHAIN (parmtypes
);
1179 dump_parameters (parmtypes
, flags
);
1182 dump_type_suffix (TREE_TYPE (fntype
), flags
);
1184 if (TREE_CODE (fntype
) == METHOD_TYPE
)
1185 dump_qualifiers (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype
))),
1188 if (flags
& TS_FUNC_THROW
)
1189 dump_exception_spec (TYPE_RAISES_EXCEPTIONS (fntype
), flags
);
1191 /* If T is a template instantiation, dump the parameter binding. */
1192 if (template_parms
!= NULL_TREE
&& template_args
!= NULL_TREE
)
1194 OB_PUTS (" [with ");
1195 dump_template_bindings (template_parms
, template_args
);
1200 /* Print a parameter list. If this is for a member function, the
1201 member object ptr (and any other hidden args) should have
1202 already been removed. */
1205 dump_parameters (parmtypes
, flags
)
1207 enum tree_string_flags flags
;
1212 for (first
= 1; parmtypes
!= void_list_node
;
1213 parmtypes
= TREE_CHAIN (parmtypes
))
1223 dump_type (TREE_VALUE (parmtypes
), flags
);
1225 if ((flags
& TS_PARM_DEFAULTS
) && TREE_PURPOSE (parmtypes
))
1228 dump_expr (TREE_PURPOSE (parmtypes
), flags
| TS_EXPR_PARENS
);
1235 /* Print an exception specification. T is the exception specification. */
1238 dump_exception_spec (t
, flags
)
1240 enum tree_string_flags flags
;
1244 OB_PUTS (" throw (");
1245 if (TREE_VALUE (t
) != NULL_TREE
)
1248 dump_type (TREE_VALUE (t
), flags
);
1258 /* Handle the function name for a FUNCTION_DECL node, grokking operators
1259 and destructors properly. */
1262 dump_function_name (t
, flags
)
1264 enum tree_string_flags flags
;
1266 tree name
= DECL_NAME (t
);
1268 if (DECL_DESTRUCTOR_P (t
))
1271 dump_decl (name
, TS_PLAIN
);
1273 else if (DECL_CONV_FN_P (t
))
1275 /* This cannot use the hack that the operator's return
1276 type is stashed off of its name because it may be
1277 used for error reporting. In the case of conflicting
1278 declarations, both will have the same name, yet
1279 the types will be different, hence the TREE_TYPE field
1280 of the first name will be clobbered by the second. */
1281 OB_PUTS ("operator ");
1282 dump_type (TREE_TYPE (TREE_TYPE (t
)), flags
);
1284 else if (IDENTIFIER_OPNAME_P (name
))
1286 const char *name_string
= operator_name_string (name
);
1287 OB_PUTS ("operator");
1288 if (ISALPHA (name_string
[0]))
1290 OB_PUTCP (name_string
);
1293 dump_decl (name
, flags
);
1295 if (DECL_LANG_SPECIFIC (t
) && DECL_TEMPLATE_INFO (t
)
1296 && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t
)
1297 && (DECL_TEMPLATE_SPECIALIZATION (t
)
1298 || TREE_CODE (DECL_TI_TEMPLATE (t
)) != TEMPLATE_DECL
1299 || DECL_TEMPLATE_SPECIALIZATION (DECL_TI_TEMPLATE (t
))
1300 || PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t
))))
1301 dump_template_parms (DECL_TEMPLATE_INFO (t
), !DECL_USE_TEMPLATE (t
), flags
);
1304 /* Dump the template parameters from the template info INFO under control of
1305 FLAGS. PRIMARY indicates whether this is a primary template decl, or
1306 specialization (partial or complete). For partial specializations we show
1307 the specialized parameter values. For a primary template we show no
1311 dump_template_parms (info
, primary
, flags
)
1314 enum tree_string_flags flags
;
1316 tree args
= info
? TI_ARGS (info
) : NULL_TREE
;
1318 if (primary
&& flags
& TS_TEMPLATE_PLAIN
)
1320 flags
&= ~(TS_AGGR_TAGS
| TS_TEMPLATE_PLAIN
);
1323 /* Be careful only to print things when we have them, so as not
1324 to crash producing error messages. */
1325 if (args
&& !primary
)
1331 if (TREE_CODE (args
) == TREE_VEC
)
1333 if (TREE_VEC_LENGTH (args
) > 0
1334 && TREE_CODE (TREE_VEC_ELT (args
, 0)) == TREE_VEC
)
1335 args
= TREE_VEC_ELT (args
, TREE_VEC_LENGTH (args
) - 1);
1337 len
= TREE_VEC_LENGTH (args
);
1339 else if (TREE_CODE (args
) == TREE_LIST
)
1341 while (ix
!= len
&& args
)
1346 arg
= TREE_VEC_ELT (args
, ix
);
1351 arg
= TREE_VALUE (args
);
1352 args
= TREE_CHAIN (args
);
1358 OB_PUTS ("{template parameter error}");
1360 dump_template_argument (arg
, flags
);
1366 tree tpl
= TI_TEMPLATE (info
);
1367 tree parms
= DECL_TEMPLATE_PARMS (tpl
);
1370 parms
= TREE_CODE (parms
) == TREE_LIST
? TREE_VALUE (parms
) : NULL_TREE
;
1371 len
= parms
? TREE_VEC_LENGTH (parms
) : 0;
1373 for (ix
= 0; ix
!= len
; ix
++)
1375 tree parm
= TREE_VALUE (TREE_VEC_ELT (parms
, ix
));
1380 dump_decl (parm
, flags
& ~TS_DECL_TYPE
);
1383 OB_END_TEMPLATE_ID ();
1392 case TARGET_NEWLINE
:
1427 sprintf (digit_buffer
, "\\%03o", (int) c
);
1428 OB_PUTCP (digit_buffer
);
1433 /* Print out a list of initializers (subr of dump_expr) */
1436 dump_expr_list (l
, flags
)
1438 enum tree_string_flags flags
;
1442 dump_expr (TREE_VALUE (l
), flags
| TS_EXPR_PARENS
);
1449 /* Print out an expression E under control of FLAGS. */
1452 dump_expr (t
, flags
)
1454 enum tree_string_flags flags
;
1456 switch (TREE_CODE (t
))
1464 case NAMESPACE_DECL
:
1466 dump_decl (t
, flags
& ~TS_DECL_TYPE
);
1471 tree type
= TREE_TYPE (t
);
1472 my_friendly_assert (type
!= 0, 81);
1474 /* If it's an enum, output its tag, rather than its value. */
1475 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1477 const char *p
= enum_name_string (t
, type
);
1480 else if (type
== boolean_type_node
)
1482 if (t
== boolean_false_node
1483 || (TREE_INT_CST_LOW (t
) == 0
1484 && TREE_INT_CST_HIGH (t
) == 0))
1486 else if (t
== boolean_true_node
)
1489 else if (type
== char_type_node
)
1492 dump_char (TREE_INT_CST_LOW (t
));
1495 else if (TREE_INT_CST_HIGH (t
)
1496 != (TREE_INT_CST_LOW (t
) >> (HOST_BITS_PER_WIDE_INT
- 1)))
1499 if (TREE_INT_CST_HIGH (val
) < 0)
1502 val
= build_int_2 (~TREE_INT_CST_LOW (val
),
1503 -TREE_INT_CST_HIGH (val
));
1505 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
1508 static char format
[10]; /* "%x%09999x\0" */
1510 sprintf (format
, "%%x%%0%dx", HOST_BITS_PER_INT
/ 4);
1511 sprintf (digit_buffer
, format
, TREE_INT_CST_HIGH (val
),
1512 TREE_INT_CST_LOW (val
));
1513 OB_PUTCP (digit_buffer
);
1517 OB_PUTI (TREE_INT_CST_LOW (t
));
1522 #ifndef REAL_IS_NOT_DOUBLE
1523 sprintf (digit_buffer
, "%g", TREE_REAL_CST (t
));
1526 const unsigned char *p
= (const unsigned char *) &TREE_REAL_CST (t
);
1528 strcpy (digit_buffer
, "0x");
1529 for (i
= 0; i
< sizeof TREE_REAL_CST (t
); i
++)
1530 sprintf (digit_buffer
+ 2 + 2*i
, "%02x", *p
++);
1533 OB_PUTCP (digit_buffer
);
1538 dump_type (PTRMEM_CST_CLASS (t
), flags
);
1540 OB_PUTID (DECL_NAME (PTRMEM_CST_MEMBER (t
)));
1545 const char *p
= TREE_STRING_POINTER (t
);
1546 int len
= TREE_STRING_LENGTH (t
) - 1;
1550 for (i
= 0; i
< len
; i
++)
1558 dump_expr (TREE_OPERAND (t
, 0), flags
| TS_EXPR_PARENS
);
1560 dump_expr (TREE_OPERAND (t
, 1), flags
| TS_EXPR_PARENS
);
1566 dump_expr (TREE_OPERAND (t
, 0), flags
| TS_EXPR_PARENS
);
1568 dump_expr (TREE_OPERAND (t
, 1), flags
| TS_EXPR_PARENS
);
1570 dump_expr (TREE_OPERAND (t
, 2), flags
| TS_EXPR_PARENS
);
1575 if (TREE_HAS_CONSTRUCTOR (t
))
1578 dump_type (TREE_TYPE (TREE_TYPE (t
)), flags
);
1582 dump_expr (TREE_OPERAND (t
, 0), flags
| TS_EXPR_PARENS
);
1586 case AGGR_INIT_EXPR
:
1588 tree fn
= NULL_TREE
;
1590 if (TREE_CODE (TREE_OPERAND (t
, 0)) == ADDR_EXPR
)
1591 fn
= TREE_OPERAND (TREE_OPERAND (t
, 0), 0);
1593 if (fn
&& TREE_CODE (fn
) == FUNCTION_DECL
)
1595 if (DECL_CONSTRUCTOR_P (fn
))
1596 OB_PUTID (TYPE_IDENTIFIER (TREE_TYPE (t
)));
1601 dump_expr (TREE_OPERAND (t
, 0), 0);
1604 if (TREE_OPERAND (t
, 1))
1605 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t
, 1)), flags
);
1611 tree fn
= TREE_OPERAND (t
, 0);
1612 tree args
= TREE_OPERAND (t
, 1);
1614 if (TREE_CODE (fn
) == ADDR_EXPR
)
1615 fn
= TREE_OPERAND (fn
, 0);
1617 if (TREE_TYPE (fn
) != NULL_TREE
&& NEXT_CODE (fn
) == METHOD_TYPE
)
1619 tree ob
= TREE_VALUE (args
);
1620 if (TREE_CODE (ob
) == ADDR_EXPR
)
1622 dump_expr (TREE_OPERAND (ob
, 0), flags
| TS_EXPR_PARENS
);
1625 else if (TREE_CODE (ob
) != PARM_DECL
1626 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob
)), "this"))
1628 dump_expr (ob
, flags
| TS_EXPR_PARENS
);
1631 args
= TREE_CHAIN (args
);
1633 dump_expr (fn
, flags
| TS_EXPR_PARENS
);
1635 dump_expr_list (args
, flags
);
1642 tree type
= TREE_OPERAND (t
, 1);
1643 if (NEW_EXPR_USE_GLOBAL (t
))
1646 if (TREE_OPERAND (t
, 0))
1649 dump_expr_list (TREE_OPERAND (t
, 0), flags
);
1652 if (TREE_CODE (type
) == ARRAY_REF
)
1653 type
= build_cplus_array_type
1654 (TREE_OPERAND (type
, 0),
1655 build_index_type (size_binop (MINUS_EXPR
, TREE_OPERAND (type
, 1),
1656 integer_one_node
)));
1657 dump_type (type
, flags
);
1658 if (TREE_OPERAND (t
, 2))
1661 dump_expr_list (TREE_OPERAND (t
, 2), flags
);
1668 /* Note that this only works for G++ target exprs. If somebody
1669 builds a general TARGET_EXPR, there's no way to represent that
1670 it initializes anything other that the parameter slot for the
1671 default argument. Note we may have cleared out the first
1672 operand in expand_expr, so don't go killing ourselves. */
1673 if (TREE_OPERAND (t
, 1))
1674 dump_expr (TREE_OPERAND (t
, 1), flags
| TS_EXPR_PARENS
);
1682 case TRUNC_DIV_EXPR
:
1683 case TRUNC_MOD_EXPR
:
1691 case BIT_ANDTC_EXPR
:
1692 case TRUTH_ANDIF_EXPR
:
1693 case TRUTH_ORIF_EXPR
:
1700 case EXACT_DIV_EXPR
:
1701 dump_binary_op (opname_tab
[(int) TREE_CODE (t
)], t
, flags
);
1705 case FLOOR_DIV_EXPR
:
1706 case ROUND_DIV_EXPR
:
1707 dump_binary_op ("/", t
, flags
);
1711 case FLOOR_MOD_EXPR
:
1712 case ROUND_MOD_EXPR
:
1713 dump_binary_op ("%", t
, flags
);
1718 tree ob
= TREE_OPERAND (t
, 0);
1719 if (TREE_CODE (ob
) == INDIRECT_REF
)
1721 ob
= TREE_OPERAND (ob
, 0);
1722 if (TREE_CODE (ob
) != PARM_DECL
1723 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob
)), "this"))
1725 dump_expr (ob
, flags
| TS_EXPR_PARENS
);
1731 dump_expr (ob
, flags
| TS_EXPR_PARENS
);
1734 dump_expr (TREE_OPERAND (t
, 1), flags
& ~TS_EXPR_PARENS
);
1739 dump_expr (TREE_OPERAND (t
, 0), flags
| TS_EXPR_PARENS
);
1741 dump_expr (TREE_OPERAND (t
, 1), flags
| TS_EXPR_PARENS
);
1746 if (same_type_p (TREE_TYPE (t
), void_type_node
))
1749 dump_expr (TREE_OPERAND (t
, 0), flags
);
1752 dump_unary_op ("+", t
, flags
);
1756 if (TREE_CODE (TREE_OPERAND (t
, 0)) == FUNCTION_DECL
1757 || TREE_CODE (TREE_OPERAND (t
, 0)) == STRING_CST
)
1758 dump_expr (TREE_OPERAND (t
, 0), flags
| TS_EXPR_PARENS
);
1760 dump_unary_op ("&", t
, flags
);
1764 if (TREE_HAS_CONSTRUCTOR (t
))
1766 t
= TREE_OPERAND (t
, 0);
1767 my_friendly_assert (TREE_CODE (t
) == CALL_EXPR
, 237);
1768 dump_expr (TREE_OPERAND (t
, 0), flags
| TS_EXPR_PARENS
);
1770 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t
, 1)), flags
);
1775 if (TREE_OPERAND (t
,0) != NULL_TREE
1776 && TREE_TYPE (TREE_OPERAND (t
, 0))
1777 && NEXT_CODE (TREE_OPERAND (t
, 0)) == REFERENCE_TYPE
)
1778 dump_expr (TREE_OPERAND (t
, 0), flags
);
1780 dump_unary_op ("*", t
, flags
);
1786 case TRUTH_NOT_EXPR
:
1787 case PREDECREMENT_EXPR
:
1788 case PREINCREMENT_EXPR
:
1789 dump_unary_op (opname_tab
[(int)TREE_CODE (t
)], t
, flags
);
1792 case POSTDECREMENT_EXPR
:
1793 case POSTINCREMENT_EXPR
:
1795 dump_expr (TREE_OPERAND (t
, 0), flags
| TS_EXPR_PARENS
);
1796 OB_PUTCP (opname_tab
[(int)TREE_CODE (t
)]);
1800 case NON_LVALUE_EXPR
:
1801 /* FIXME: This is a KLUDGE workaround for a parsing problem. There
1802 should be another level of INDIRECT_REF so that I don't have to do
1804 if (TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == POINTER_TYPE
)
1806 tree next
= TREE_TYPE (TREE_TYPE (t
));
1808 while (TREE_CODE (next
) == POINTER_TYPE
)
1809 next
= TREE_TYPE (next
);
1811 if (TREE_CODE (next
) == FUNCTION_TYPE
)
1813 if (flags
& TS_EXPR_PARENS
)
1816 dump_expr (TREE_OPERAND (t
, 0), flags
& ~TS_EXPR_PARENS
);
1817 if (flags
& TS_EXPR_PARENS
)
1823 dump_expr (TREE_OPERAND (t
, 0), flags
| TS_EXPR_PARENS
);
1827 dump_expr (TREE_OPERAND (t
, 0), flags
);
1830 case EXPR_WITH_FILE_LOCATION
:
1831 dump_expr (EXPR_WFL_NODE (t
), flags
);
1835 if (TREE_TYPE (t
) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t
)))
1837 tree idx
= build_component_ref (t
, index_identifier
, NULL_TREE
, 0);
1839 if (integer_all_onesp (idx
))
1841 tree pfn
= PFN_FROM_PTRMEMFUNC (t
);
1842 dump_unary_op ("&", pfn
, flags
| TS_EXPR_PARENS
);
1845 else if (TREE_CODE (idx
) == INTEGER_CST
1846 && tree_int_cst_equal (idx
, integer_zero_node
))
1848 /* A NULL pointer-to-member constant. */
1850 dump_type (TREE_TYPE (t
), flags
);
1854 else if (TREE_CODE (idx
) == INTEGER_CST
1855 && TREE_INT_CST_HIGH (idx
) == 0)
1858 unsigned HOST_WIDE_INT n
;
1860 t
= TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t
)));
1861 t
= TYPE_METHOD_BASETYPE (t
);
1862 virtuals
= TYPE_BINFO_VIRTUALS (TYPE_MAIN_VARIANT (t
));
1864 n
= TREE_INT_CST_LOW (idx
);
1866 /* Map vtable index back one, to allow for the null pointer to
1870 while (n
> 0 && virtuals
)
1873 virtuals
= TREE_CHAIN (virtuals
);
1877 dump_expr (TREE_VALUE (virtuals
),
1878 flags
| TS_EXPR_PARENS
);
1884 dump_expr_list (CONSTRUCTOR_ELTS (t
), flags
);
1890 tree ob
= TREE_OPERAND (t
, 0);
1891 if (is_dummy_object (ob
))
1893 t
= TREE_OPERAND (t
, 1);
1894 if (TREE_CODE (t
) == FUNCTION_DECL
)
1896 dump_expr (t
, flags
| TS_EXPR_PARENS
);
1897 else if (BASELINK_P (t
))
1898 dump_expr (OVL_CURRENT (TREE_VALUE (t
)), flags
| TS_EXPR_PARENS
);
1900 dump_decl (t
, flags
);
1904 if (TREE_CODE (ob
) == INDIRECT_REF
)
1906 dump_expr (TREE_OPERAND (ob
, 0), flags
| TS_EXPR_PARENS
);
1911 dump_expr (ob
, flags
| TS_EXPR_PARENS
);
1914 dump_expr (TREE_OPERAND (t
, 1), flags
| TS_EXPR_PARENS
);
1919 case TEMPLATE_PARM_INDEX
:
1920 dump_decl (TEMPLATE_PARM_DECL (t
), flags
& ~TS_DECL_TYPE
);
1923 case IDENTIFIER_NODE
:
1928 dump_type (TREE_OPERAND (t
, 0), flags
);
1930 dump_expr (TREE_OPERAND (t
, 1), flags
| TS_EXPR_PARENS
);
1934 if (TREE_OPERAND (t
, 0) == NULL_TREE
1935 || TREE_CHAIN (TREE_OPERAND (t
, 0)))
1937 dump_type (TREE_TYPE (t
), flags
);
1939 dump_expr_list (TREE_OPERAND (t
, 0), flags
);
1945 dump_type (TREE_TYPE (t
), flags
);
1948 dump_expr_list (TREE_OPERAND (t
, 0), flags
);
1954 OB_PUTID (TREE_OPERAND (t
, 0));
1958 dump_expr (TREE_OPERAND (t
, 0), flags
);
1964 if (TREE_CODE (t
) == SIZEOF_EXPR
)
1965 OB_PUTS ("sizeof (");
1968 my_friendly_assert (TREE_CODE (t
) == ALIGNOF_EXPR
, 0);
1969 OB_PUTS ("__alignof__ (");
1971 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t
, 0))) == 't')
1972 dump_type (TREE_OPERAND (t
, 0), flags
);
1974 dump_unary_op ("*", t
, flags
| TS_EXPR_PARENS
);
1979 OB_PUTS ("{unparsed}");
1982 case TRY_CATCH_EXPR
:
1983 case WITH_CLEANUP_EXPR
:
1984 case CLEANUP_POINT_EXPR
:
1985 dump_expr (TREE_OPERAND (t
, 0), flags
);
1988 case PSEUDO_DTOR_EXPR
:
1989 dump_expr (TREE_OPERAND (t
, 2), flags
);
1991 dump_type (TREE_OPERAND (t
, 0), flags
);
1993 dump_type (TREE_OPERAND (t
, 1), flags
);
1996 case TEMPLATE_ID_EXPR
:
1997 dump_decl (t
, flags
);
2001 /* We don't yet have a way of dumping statements in a
2002 human-readable format. */
2003 OB_PUTS ("{ ... }");
2008 dump_expr (TREE_OPERAND (t
, 1), flags
& ~TS_EXPR_PARENS
);
2013 OB_PUTS ("while (1) { ");
2014 dump_expr (TREE_OPERAND (t
, 0), flags
& ~TS_EXPR_PARENS
);
2020 dump_expr (TREE_OPERAND (t
, 0), flags
& ~TS_EXPR_PARENS
);
2021 OB_PUTS (") break; ");
2025 if (TREE_VALUE (t
) && TREE_CODE (TREE_VALUE (t
)) == FUNCTION_DECL
)
2027 OB_PUTID (DECL_NAME (TREE_VALUE (t
)));
2030 /* else fall through */
2032 /* This list is incomplete, but should suffice for now.
2033 It is very important that `sorry' does not call
2034 `report_error_function'. That could cause an infinite loop. */
2036 sorry ("`%s' not supported by dump_expr",
2037 tree_code_name
[(int) TREE_CODE (t
)]);
2039 /* fall through to ERROR_MARK... */
2041 OB_PUTCP ("{expression error}");
2047 dump_binary_op (opstring
, t
, flags
)
2048 const char *opstring
;
2050 enum tree_string_flags flags
;
2053 dump_expr (TREE_OPERAND (t
, 0), flags
| TS_EXPR_PARENS
);
2056 OB_PUTCP (opstring
);
2058 OB_PUTS ("<unknown operator>");
2060 dump_expr (TREE_OPERAND (t
, 1), flags
| TS_EXPR_PARENS
);
2065 dump_unary_op (opstring
, t
, flags
)
2066 const char *opstring
;
2068 enum tree_string_flags flags
;
2070 if (flags
& TS_EXPR_PARENS
)
2072 OB_PUTCP (opstring
);
2073 dump_expr (TREE_OPERAND (t
, 0), flags
& ~TS_EXPR_PARENS
);
2074 if (flags
& TS_EXPR_PARENS
)
2078 /* Exported interface to stringifying types, exprs and decls under TS_*
2082 type_as_string (typ
, flags
)
2084 enum tree_string_flags flags
;
2088 dump_type (typ
, flags
);
2092 return (char *)obstack_base (&scratch_obstack
);
2096 expr_as_string (decl
, flags
)
2098 enum tree_string_flags flags
;
2102 dump_expr (decl
, flags
);
2106 return (char *)obstack_base (&scratch_obstack
);
2110 decl_as_string (decl
, flags
)
2112 enum tree_string_flags flags
;
2116 dump_decl (decl
, flags
);
2120 return (char *)obstack_base (&scratch_obstack
);
2124 context_as_string (context
, flags
)
2126 enum tree_string_flags flags
;
2130 dump_scope (context
, flags
);
2134 return (char *)obstack_base (&scratch_obstack
);
2137 /* Generate the three forms of printable names for lang_printable_name. */
2140 lang_decl_name (decl
, v
)
2145 return decl_as_string (decl
, TS_DECL_TYPE
);
2149 if (v
== 1 && DECL_CLASS_SCOPE_P (decl
))
2152 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2153 cname
= DECL_CLASS_CONTEXT (decl
);
2155 cname
= DECL_CONTEXT (decl
);
2156 dump_type (cname
, TS_PLAIN
);
2160 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2161 dump_function_name (decl
, TS_PLAIN
);
2163 dump_decl (DECL_NAME (decl
), TS_PLAIN
);
2167 return (char *)obstack_base (&scratch_obstack
);
2174 if (TREE_CODE (t
) == PARM_DECL
&& DECL_CONTEXT (t
))
2175 return DECL_SOURCE_FILE (DECL_CONTEXT (t
));
2176 else if (TREE_CODE_CLASS (TREE_CODE (t
)) == 't')
2177 return DECL_SOURCE_FILE (TYPE_MAIN_DECL (t
));
2178 else if (TREE_CODE (t
) == OVERLOAD
)
2179 return DECL_SOURCE_FILE (OVL_FUNCTION (t
));
2181 return DECL_SOURCE_FILE (t
);
2189 if (TREE_CODE (t
) == PARM_DECL
&& DECL_CONTEXT (t
))
2190 line
= DECL_SOURCE_LINE (DECL_CONTEXT (t
));
2191 if (TREE_CODE (t
) == TYPE_DECL
&& DECL_ARTIFICIAL (t
)
2192 && TYPE_MAIN_DECL (TREE_TYPE (t
)))
2195 if (TREE_CODE_CLASS (TREE_CODE (t
)) == 't')
2196 line
= DECL_SOURCE_LINE (TYPE_MAIN_DECL (t
));
2197 else if (TREE_CODE (t
) == OVERLOAD
)
2198 line
= DECL_SOURCE_LINE (OVL_FUNCTION (t
));
2200 line
= DECL_SOURCE_LINE (t
);
2208 /* Now the interfaces from cp_error et al to dump_type et al. Each takes an
2209 on/off VERBOSE flag and supply the appropriate TS_ flags to a dump_
2213 decl_to_string (decl
, verbose
)
2217 enum tree_string_flags flags
= 0;
2219 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == RECORD_TYPE
2220 || TREE_CODE (decl
) == UNION_TYPE
|| TREE_CODE (decl
) == ENUMERAL_TYPE
)
2221 flags
= TS_AGGR_TAGS
;
2223 flags
|= TS_DECL_TYPE
| TS_DECORATE
| TS_PARM_DEFAULTS
;
2224 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
2225 flags
|= TS_DECL_TYPE
| TS_FUNC_NORETURN
;
2226 flags
|= TS_TEMPLATE_PREFIX
;
2230 dump_decl (decl
, flags
);
2234 return (char *)obstack_base (&scratch_obstack
);
2238 expr_to_string (decl
, verbose
)
2240 int verbose ATTRIBUTE_UNUSED
;
2244 dump_expr (decl
, 0);
2248 return (char *)obstack_base (&scratch_obstack
);
2252 fndecl_to_string (fndecl
, verbose
)
2256 enum tree_string_flags flags
;
2258 flags
= TS_FUNC_THROW
| TS_DECL_TYPE
;
2260 flags
|= TS_PARM_DEFAULTS
;
2263 dump_decl (fndecl
, flags
);
2267 return (char *)obstack_base (&scratch_obstack
);
2272 code_to_string (c
, v
)
2274 int v ATTRIBUTE_UNUSED
;
2276 return tree_code_name
[c
];
2280 language_to_string (c
, v
)
2282 int v ATTRIBUTE_UNUSED
;
2289 case lang_cplusplus
:
2296 my_friendly_abort (355);
2301 /* Return the proper printed version of a parameter to a C++ function. */
2304 parm_to_string (p
, v
)
2306 int v ATTRIBUTE_UNUSED
;
2311 sprintf (digit_buffer
, "%d", p
+1);
2312 return digit_buffer
;
2318 int v ATTRIBUTE_UNUSED
;
2320 static char buf
[] = "operator ";
2325 strcpy (buf
+ 8, opname_tab
[p
]);
2330 type_to_string (typ
, verbose
)
2334 enum tree_string_flags flags
;
2338 flags
|= TS_AGGR_TAGS
;
2339 flags
|= TS_TEMPLATE_PREFIX
;
2343 dump_type (typ
, flags
);
2347 return (char *)obstack_base (&scratch_obstack
);
2351 assop_to_string (p
, v
)
2353 int v ATTRIBUTE_UNUSED
;
2355 static char buf
[] = "operator ";
2360 strcpy (buf
+ 9, assignop_tab
[p
]);
2365 args_to_string (p
, verbose
)
2369 enum tree_string_flags flags
= 0;
2371 flags
|= TS_AGGR_TAGS
;
2376 if (TREE_CODE_CLASS (TREE_CODE (TREE_VALUE (p
))) == 't')
2377 return type_as_string (p
, flags
);
2380 for (; p
; p
= TREE_CHAIN (p
))
2382 if (TREE_VALUE (p
) == null_node
)
2385 dump_type (error_type (TREE_VALUE (p
)), flags
);
2390 return (char *)obstack_base (&scratch_obstack
);
2396 int v ATTRIBUTE_UNUSED
;
2400 dump_qualifiers (p
, before
);
2404 return (char *)obstack_base (&scratch_obstack
);