1 /* Call-backs for C++ error reporting.
2 This code is non-reentrant.
3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000
4 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 const char *cp_printer ();
31 #define obstack_chunk_alloc xmalloc
32 #define obstack_chunk_free free
34 /* Obstack where we build text strings for overloading, etc. */
35 static struct obstack scratch_obstack
;
36 static char *scratch_firstobj
;
38 # define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0)
39 # define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C)))
40 # define OB_PUTC2(C1,C2) \
41 (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2)))
42 # define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1))
43 # define OB_PUTID(ID) \
44 (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \
45 IDENTIFIER_LENGTH (ID)))
46 # define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S)))
47 # define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0'))
48 # define OB_PUTI(CST) do { sprintf (digit_buffer, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT)(CST)); \
49 OB_PUTCP (digit_buffer); } while (0)
51 # define OB_END_TEMPLATE_ID() \
52 (((obstack_next_free (&scratch_obstack) != obstack_base (&scratch_obstack) \
53 && obstack_next_free (&scratch_obstack)[-1] == '>') \
54 ? OB_PUTC (' ') : (void)0), OB_PUTC ('>'))
56 # define NEXT_CODE(t) (TREE_CODE (TREE_TYPE (t)))
58 enum pad
{ none
, before
, after
};
60 static const char *args_to_string
PARAMS ((tree
, int));
61 static const char *assop_to_string
PARAMS ((enum tree_code
, int));
62 static const char *code_to_string
PARAMS ((enum tree_code
, int));
63 static const char *cv_to_string
PARAMS ((tree
, int));
64 static const char *decl_to_string
PARAMS ((tree
, int));
65 static const char *expr_to_string
PARAMS ((tree
, int));
66 static const char *fndecl_to_string
PARAMS ((tree
, int));
67 static const char *language_to_string
PARAMS ((enum languages
, int));
68 static const char *op_to_string
PARAMS ((enum tree_code
, int));
69 static const char *parm_to_string
PARAMS ((int, int));
70 static const char *type_to_string
PARAMS ((tree
, int));
72 static void dump_type
PARAMS ((tree
, enum tree_string_flags
));
73 static void dump_simple_decl
PARAMS ((tree
, tree
, enum tree_string_flags
));
74 static void dump_decl
PARAMS ((tree
, enum tree_string_flags
));
75 static void dump_template_decl
PARAMS ((tree
, enum tree_string_flags
));
76 static void dump_function_decl
PARAMS ((tree
, enum tree_string_flags
));
77 static void dump_expr
PARAMS ((tree
, enum tree_string_flags
));
78 static void dump_unary_op
PARAMS ((const char *, tree
, enum tree_string_flags
));
79 static void dump_binary_op
PARAMS ((const char *, tree
, enum tree_string_flags
));
80 static void dump_aggr_type
PARAMS ((tree
, enum tree_string_flags
));
81 static enum pad dump_type_prefix
PARAMS ((tree
, enum tree_string_flags
));
82 static void dump_type_suffix
PARAMS ((tree
, enum tree_string_flags
));
83 static void dump_function_name
PARAMS ((tree
, enum tree_string_flags
));
84 static void dump_expr_list
PARAMS ((tree
, enum tree_string_flags
));
85 static void dump_global_iord
PARAMS ((tree
));
86 static enum pad dump_qualifiers
PARAMS ((tree
, enum pad
));
87 static void dump_char
PARAMS ((int));
88 static void dump_parameters
PARAMS ((tree
, enum tree_string_flags
));
89 static void dump_exception_spec
PARAMS ((tree
, enum tree_string_flags
));
90 static const char *aggr_variety
PARAMS ((tree
));
91 static tree ident_fndecl
PARAMS ((tree
));
92 static void dump_template_argument
PARAMS ((tree
, enum tree_string_flags
));
93 static void dump_template_argument_list
PARAMS ((tree
, enum tree_string_flags
));
94 static void dump_template_parameter
PARAMS ((tree
, enum tree_string_flags
));
95 static void dump_template_bindings
PARAMS ((tree
, tree
));
96 static void dump_scope
PARAMS ((tree
, enum tree_string_flags
));
97 static void dump_template_parms
PARAMS ((tree
, int, enum tree_string_flags
));
99 #define A args_to_string
100 #define C code_to_string
101 #define D decl_to_string
102 #define E expr_to_string
103 #define F fndecl_to_string
104 #define L language_to_string
105 #define O op_to_string
106 #define P parm_to_string
107 #define Q assop_to_string
108 #define T type_to_string
109 #define V cv_to_string
111 #define o (cp_printer *) 0
112 cp_printer
* cp_printers
[256] =
114 /*0 1 2 3 4 5 6 7 8 9 A B C D E F */
115 o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, /* 0x00 */
116 o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, /* 0x10 */
117 o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, /* 0x20 */
118 o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, /* 0x30 */
119 o
, A
, o
, C
, D
, E
, F
, o
, o
, o
, o
, o
, L
, o
, o
, O
, /* 0x40 */
120 P
, Q
, o
, o
, T
, o
, V
, o
, o
, o
, o
, o
, o
, o
, o
, o
, /* 0x50 */
121 o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, /* 0x60 */
122 o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, o
, /* 0x70 */
139 gcc_obstack_init (&scratch_obstack
);
140 scratch_firstobj
= (char *)obstack_alloc (&scratch_obstack
, 0);
143 /* Dump a scope, if deemed necessary. */
146 dump_scope (scope
, flags
)
148 enum tree_string_flags flags
;
150 if (scope
== NULL_TREE
)
153 if (TREE_CODE (scope
) == NAMESPACE_DECL
)
155 if (scope
!= global_namespace
)
157 dump_decl (scope
, (flags
& (TS_PEDANTIC_NAME
| TS_FUNC_SCOPE
| TS_CHASE_TYPEDEFS
))
158 | TS_FUNC_NORETURN
| TS_DECL_TYPE
);
161 else if (flags
& TS_PEDANTIC_NAME
)
164 else if (AGGREGATE_TYPE_P (scope
))
166 dump_type (scope
, (flags
& (TS_PEDANTIC_NAME
| TS_FUNC_SCOPE
| TS_CHASE_TYPEDEFS
))
167 | TS_FUNC_NORETURN
| TS_DECL_TYPE
);
170 else if ((flags
& (TS_PEDANTIC_NAME
| TS_FUNC_SCOPE
))
171 && TREE_CODE (scope
) == FUNCTION_DECL
)
173 dump_function_decl (scope
, (flags
& (TS_PEDANTIC_NAME
| TS_FUNC_SCOPE
| TS_CHASE_TYPEDEFS
))
174 | TS_FUNC_NORETURN
| TS_DECL_TYPE
);
179 /* Dump type qualifiers, providing padding as requested. Return an
180 indication of whether we dumped something. */
183 dump_qualifiers (t
, p
)
187 static const int masks
[] =
188 {TYPE_QUAL_CONST
, TYPE_QUAL_VOLATILE
, TYPE_QUAL_RESTRICT
};
189 static const char *const names
[] =
190 {"const", "volatile", "__restrict"};
192 int quals
= TYPE_QUALS (t
);
193 int do_after
= p
== after
;
197 for (ix
= 0; ix
!= 3; ix
++)
198 if (masks
[ix
] & quals
)
203 OB_PUTCP (names
[ix
]);
213 /* This must be large enough to hold any printed integer or floating-point
215 static char digit_buffer
[128];
217 /* Dump the template ARGument under control of FLAGS. */
220 dump_template_argument (arg
, flags
)
222 enum tree_string_flags flags
;
224 if (TREE_CODE_CLASS (TREE_CODE (arg
)) == 't'
225 || TREE_CODE (arg
) == TEMPLATE_DECL
)
226 dump_type (arg
, flags
& ~TS_AGGR_TAGS
);
228 dump_expr (arg
, (flags
| TS_EXPR_PARENS
) & ~TS_AGGR_TAGS
);
231 /* Dump a template-argument-list ARGS (always a TREE_VEC) under control
235 dump_template_argument_list (args
, flags
)
237 enum tree_string_flags flags
;
239 int n
= TREE_VEC_LENGTH (args
);
243 for (i
= 0; i
< n
; ++i
)
247 dump_template_argument (TREE_VEC_ELT (args
, i
), flags
);
252 /* Dump a template parameter PARM (a TREE_LIST) under control of FLAGS. */
255 dump_template_parameter (parm
, flags
)
257 enum tree_string_flags flags
;
259 tree p
= TREE_VALUE (parm
);
260 tree a
= TREE_PURPOSE (parm
);
262 if (TREE_CODE (p
) == TYPE_DECL
)
264 if (flags
& TS_DECL_TYPE
)
270 OB_PUTID (DECL_NAME (p
));
273 else if (DECL_NAME (p
))
274 OB_PUTID (DECL_NAME (p
));
276 OB_PUTS ("{template default argument error}");
279 dump_decl (p
, flags
| TS_DECL_TYPE
);
281 if ((flags
& TS_PARM_DEFAULTS
) && a
!= NULL_TREE
)
284 if (TREE_CODE (a
) == TYPE_DECL
|| TREE_CODE (a
) == TEMPLATE_DECL
)
285 dump_type (a
, flags
& ~TS_CHASE_TYPEDEFS
);
287 dump_expr (a
, flags
| TS_EXPR_PARENS
);
291 /* Dump, under control of FLAGS, a template-parameter-list binding.
292 PARMS is a TREE_LIST of TREE_VEC of TREE_LIST and ARGS is a
296 dump_template_bindings (parms
, args
)
303 tree p
= TREE_VALUE (parms
);
304 int lvl
= TMPL_PARMS_DEPTH (parms
);
308 for (i
= 0; i
< TREE_VEC_LENGTH (p
); ++i
)
310 tree arg
= TMPL_ARG (args
, lvl
, arg_idx
);
314 dump_template_parameter (TREE_VEC_ELT (p
, i
), TS_PLAIN
);
317 dump_template_argument (arg
, TS_PLAIN
);
319 OB_PUTS ("{missing}");
325 parms
= TREE_CHAIN (parms
);
329 /* Dump into the obstack a human-readable equivalent of TYPE. FLAGS
330 controls the format. */
335 enum tree_string_flags flags
;
340 if (TYPE_PTRMEMFUNC_P (t
))
343 switch (TREE_CODE (t
))
346 OB_PUTS ("{unknown type}");
350 /* A list of function parms. */
351 dump_parameters (t
, flags
);
354 case IDENTIFIER_NODE
:
359 dump_type (BINFO_TYPE (t
), flags
);
365 dump_aggr_type (t
, flags
);
369 if (flags
& TS_CHASE_TYPEDEFS
)
371 dump_type (DECL_ORIGINAL_TYPE (t
)
372 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
), flags
);
375 /* else fallthrough */
379 dump_decl (t
, flags
& ~TS_DECL_TYPE
);
383 OB_PUTS ("complex ");
384 dump_type (TREE_TYPE (t
), flags
);
388 if (!TREE_UNSIGNED (TYPE_MAIN_VARIANT (t
)) && TREE_UNSIGNED (t
))
389 OB_PUTS ("unsigned ");
390 else if (TREE_UNSIGNED (TYPE_MAIN_VARIANT (t
)) && !TREE_UNSIGNED (t
))
399 dump_qualifiers (t
, after
);
400 type
= flags
& TS_CHASE_TYPEDEFS
? TYPE_MAIN_VARIANT (t
) : t
;
401 if (TYPE_NAME (type
) && TYPE_IDENTIFIER (type
))
402 OB_PUTID (TYPE_IDENTIFIER (type
));
404 /* Types like intQI_type_node and friends have no names.
405 These don't come up in user error messages, but it's nice
406 to be able to print them from the debugger. */
407 OB_PUTS ("{anonymous}");
411 case TEMPLATE_TEMPLATE_PARM
:
412 if (!TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t
))
414 /* For parameters inside template signature. */
415 if (TYPE_IDENTIFIER (t
))
416 OB_PUTID (TYPE_IDENTIFIER (t
));
418 OB_PUTS ("{anonymous template template parameter}");
422 tree args
= TYPE_TI_ARGS (t
);
423 OB_PUTID (TYPE_IDENTIFIER (t
));
425 dump_template_argument_list (args
, flags
);
426 OB_END_TEMPLATE_ID ();
430 case TEMPLATE_TYPE_PARM
:
431 dump_qualifiers (t
, after
);
432 if (TYPE_IDENTIFIER (t
))
433 OB_PUTID (TYPE_IDENTIFIER (t
));
435 OB_PUTS ("{anonymous template type parameter}");
438 /* This is not always necessary for pointers and such, but doing this
439 reduces code size. */
448 dump_type_prefix (t
, flags
);
449 dump_type_suffix (t
, flags
);
453 OB_PUTS ("typename ");
454 dump_type (TYPE_CONTEXT (t
), flags
);
456 dump_decl (TYPENAME_TYPE_FULLNAME (t
), flags
);
460 OB_PUTS ("__typeof (");
461 dump_expr (TYPE_FIELDS (t
), flags
& ~TS_EXPR_PARENS
);
466 sorry ("`%s' not supported by dump_type",
467 tree_code_name
[(int) TREE_CODE (t
)]);
468 /* Fall through to error. */
471 OB_PUTS ("{type error}");
476 /* Return the name of the supplied aggregate, or enumeral type. */
482 if (TREE_CODE (t
) == ENUMERAL_TYPE
)
484 else if (TREE_CODE (t
) == UNION_TYPE
)
486 else if (TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_DECLARED_CLASS (t
))
492 /* Print out a class declaration T under the control of FLAGS,
493 in the form `class foo'. */
496 dump_aggr_type (t
, flags
)
498 enum tree_string_flags flags
;
501 const char *variety
= aggr_variety (t
);
505 dump_qualifiers (t
, after
);
507 if (flags
& TS_AGGR_TAGS
)
513 if (flags
& TS_CHASE_TYPEDEFS
)
514 t
= TYPE_MAIN_VARIANT (t
);
516 name
= TYPE_NAME (t
);
520 typdef
= !DECL_ARTIFICIAL (name
);
521 tmplate
= !typdef
&& TREE_CODE (t
) != ENUMERAL_TYPE
522 && TYPE_LANG_SPECIFIC (t
) && CLASSTYPE_TEMPLATE_INFO (t
)
523 && (CLASSTYPE_TEMPLATE_SPECIALIZATION (t
)
524 || TREE_CODE (CLASSTYPE_TI_TEMPLATE (t
)) != TEMPLATE_DECL
525 || DECL_TEMPLATE_SPECIALIZATION (CLASSTYPE_TI_TEMPLATE (t
))
526 || PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t
)));
527 dump_scope (CP_DECL_CONTEXT (name
), flags
| TS_FUNC_SCOPE
);
530 /* Because the template names are mangled, we have to locate
531 the most general template, and use that name. */
532 tree tpl
= CLASSTYPE_TI_TEMPLATE (t
);
534 while (DECL_TEMPLATE_INFO (tpl
))
535 tpl
= DECL_TI_TEMPLATE (tpl
);
538 name
= DECL_NAME (name
);
541 if (name
== 0 || ANON_AGGRNAME_P (name
))
543 OB_PUTS ("{anonymous");
544 if (!(flags
& TS_AGGR_TAGS
))
554 dump_template_parms (TYPE_TEMPLATE_INFO (t
),
555 !CLASSTYPE_USE_TEMPLATE (t
),
556 flags
& ~TS_TEMPLATE_PREFIX
);
559 /* Dump into the obstack the initial part of the output for a given type.
560 This is necessary when dealing with things like functions returning
563 return type of `int (* fee ())()': pointer -> function -> int. Both
564 pointer (and reference and offset) and function (and member) types must
565 deal with prefix and suffix.
567 Arrays must also do this for DECL nodes, like int a[], and for things like
570 Return indicates how you should pad an object name after this. I.e. you
571 want to pad non-*, non-& cores, but not pad * or & types. */
574 dump_type_prefix (t
, flags
)
576 enum tree_string_flags flags
;
578 enum pad padding
= before
;
580 if (TYPE_PTRMEMFUNC_P (t
))
582 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
586 switch (TREE_CODE (t
))
591 tree sub
= TREE_TYPE (t
);
593 padding
= dump_type_prefix (sub
, flags
);
594 /* A tree for a member pointer looks like pointer to offset,
595 so let the OFFSET_TYPE case handle it. */
596 if (!TYPE_PTRMEM_P (t
))
600 if (TREE_CODE (sub
) == ARRAY_TYPE
)
602 OB_PUTC ("&*"[TREE_CODE (t
) == POINTER_TYPE
]);
603 padding
= dump_qualifiers (t
, none
);
610 padding
= dump_type_prefix (TREE_TYPE (t
), flags
);
611 if (TREE_CODE (t
) == OFFSET_TYPE
) /* pmfs deal with this in d_t_p */
615 dump_type (TYPE_OFFSET_BASETYPE (t
), flags
);
619 padding
= dump_qualifiers (t
, none
);
622 /* Can only be reached through function pointer -- this would not be
623 correct if FUNCTION_DECLs used it. */
625 padding
= dump_type_prefix (TREE_TYPE (t
), flags
);
633 padding
= dump_type_prefix (TREE_TYPE (t
), flags
);
638 dump_aggr_type (TYPE_METHOD_BASETYPE (t
), flags
);
643 padding
= dump_type_prefix (TREE_TYPE (t
), flags
);
647 case IDENTIFIER_NODE
:
652 case TEMPLATE_TYPE_PARM
:
653 case TEMPLATE_TEMPLATE_PARM
:
662 dump_type (t
, flags
);
667 sorry ("`%s' not supported by dump_type_prefix",
668 tree_code_name
[(int) TREE_CODE (t
)]);
671 OB_PUTS ("{typeprefixerror}");
677 /* Dump the suffix of type T, under control of FLAGS. This is the part
678 which appears after the identifier (or function parms). */
681 dump_type_suffix (t
, flags
)
683 enum tree_string_flags flags
;
685 if (TYPE_PTRMEMFUNC_P (t
))
686 t
= TYPE_PTRMEMFUNC_FN_TYPE (t
);
688 switch (TREE_CODE (t
))
693 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
695 dump_type_suffix (TREE_TYPE (t
), flags
);
698 /* Can only be reached through function pointer */
704 arg
= TYPE_ARG_TYPES (t
);
705 if (TREE_CODE (t
) == METHOD_TYPE
)
706 arg
= TREE_CHAIN (arg
);
708 /* Function pointers don't have default args. Not in standard C++,
709 anyway; they may in g++, but we'll just pretend otherwise. */
710 dump_parameters (arg
, flags
& ~TS_PARM_DEFAULTS
);
712 if (TREE_CODE (t
) == METHOD_TYPE
)
714 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t
))), before
);
715 dump_type_suffix (TREE_TYPE (t
), flags
);
716 dump_exception_spec (TYPE_RAISES_EXCEPTIONS (t
), flags
);
724 if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (t
))) == INTEGER_CST
)
725 OB_PUTI (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (t
))) + 1);
726 else if (TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (t
))) == MINUS_EXPR
)
727 dump_expr (TREE_OPERAND (TYPE_MAX_VALUE (TYPE_DOMAIN (t
)), 0),
728 flags
& ~TS_EXPR_PARENS
);
730 dump_expr (fold (build_binary_op
731 (PLUS_EXPR
, TYPE_MAX_VALUE (TYPE_DOMAIN (t
)),
733 flags
& ~TS_EXPR_PARENS
);
736 dump_type_suffix (TREE_TYPE (t
), flags
);
740 case IDENTIFIER_NODE
:
745 case TEMPLATE_TYPE_PARM
:
746 case TEMPLATE_TEMPLATE_PARM
:
758 sorry ("`%s' not supported by dump_type_suffix",
759 tree_code_name
[(int) TREE_CODE (t
)]);
762 /* Don't mark it here, we should have already done in
768 /* Return a function declaration which corresponds to the IDENTIFIER_NODE
775 tree n
= lookup_name (t
, 0);
780 if (TREE_CODE (n
) == FUNCTION_DECL
)
782 else if (TREE_CODE (n
) == TREE_LIST
783 && TREE_CODE (TREE_VALUE (n
)) == FUNCTION_DECL
)
784 return TREE_VALUE (n
);
786 my_friendly_abort (66);
790 #ifndef NO_DOLLAR_IN_LABEL
791 # define GLOBAL_THING "_GLOBAL_$"
793 # ifndef NO_DOT_IN_LABEL
794 # define GLOBAL_THING "_GLOBAL_."
796 # define GLOBAL_THING "_GLOBAL__"
800 #define GLOBAL_IORD_P(NODE) \
801 ! strncmp (IDENTIFIER_POINTER(NODE), GLOBAL_THING, sizeof (GLOBAL_THING) - 1)
807 const char *name
= IDENTIFIER_POINTER (t
);
809 OB_PUTS ("(static ");
810 if (name
[sizeof (GLOBAL_THING
) - 1] == 'I')
811 OB_PUTS ("initializers");
812 else if (name
[sizeof (GLOBAL_THING
) - 1] == 'D')
813 OB_PUTS ("destructors");
815 my_friendly_abort (352);
818 OB_PUTCP (input_filename
);
823 dump_simple_decl (t
, type
, flags
)
826 enum tree_string_flags flags
;
828 if (flags
& TS_DECL_TYPE
)
830 if (dump_type_prefix (type
, flags
) != none
)
833 if (!DECL_INITIAL (t
) || TREE_CODE (DECL_INITIAL (t
)) != TEMPLATE_PARM_INDEX
)
834 dump_scope (CP_DECL_CONTEXT (t
), flags
);
836 dump_decl (DECL_NAME (t
), flags
);
838 OB_PUTS ("{anonymous}");
839 if (flags
& TS_DECL_TYPE
)
840 dump_type_suffix (type
, flags
);
843 /* Dump a human readable string for the decl T under control of FLAGS. */
848 enum tree_string_flags flags
;
853 switch (TREE_CODE (t
))
857 /* Don't say 'typedef class A' */
858 if (DECL_ARTIFICIAL (t
))
860 if ((flags
& TS_DECL_TYPE
)
861 && TREE_CODE (TREE_TYPE (t
)) == TEMPLATE_TYPE_PARM
)
862 /* Say `class T' not just `T'. */
865 dump_type (TREE_TYPE (t
), flags
);
869 if (flags
& TS_DECORATE
)
870 OB_PUTS ("typedef ");
871 dump_simple_decl (t
, DECL_ORIGINAL_TYPE (t
)
872 ? DECL_ORIGINAL_TYPE (t
) : TREE_TYPE (t
),
877 if (DECL_NAME (t
) && VTABLE_NAME_P (DECL_NAME (t
)))
879 OB_PUTS ("vtable for ");
880 if (TYPE_P (DECL_CONTEXT (t
)))
881 dump_type (DECL_CONTEXT (t
), flags
);
883 /* This case can arise with -fno-vtable-thunks. See
884 expand_upcast_fixups. It's not clear what to print
886 OB_PUTS ("{unknown type}");
889 /* else fall through */
892 dump_simple_decl (t
, TREE_TYPE (t
), flags
);
896 OB_PUTS ("{return} ");
897 dump_simple_decl (t
, TREE_TYPE (t
), flags
);
901 dump_scope (CP_DECL_CONTEXT (t
), flags
);
902 if (DECL_NAME (t
) == anonymous_namespace_name
)
903 OB_PUTS ("{unnamed}");
905 OB_PUTID (DECL_NAME (t
));
909 dump_decl (TREE_OPERAND (t
, 0), flags
& ~TS_DECL_TYPE
);
911 dump_decl (TREE_OPERAND (t
, 1), flags
);
915 dump_decl (TREE_OPERAND (t
, 0), flags
);
917 dump_decl (TREE_OPERAND (t
, 1), flags
);
921 /* So that we can do dump_decl on an aggr type. */
925 dump_type (t
, flags
);
929 my_friendly_abort (69);
932 /* These special cases are duplicated here so that other functions
933 can feed identifiers to cp_error and get them demangled properly. */
934 case IDENTIFIER_NODE
:
936 if (DESTRUCTOR_NAME_P (t
)
937 && (f
= ident_fndecl (t
))
938 && DECL_LANGUAGE (f
) == lang_cplusplus
)
941 dump_decl (DECL_NAME (f
), flags
);
943 else if (IDENTIFIER_TYPENAME_P (t
))
945 OB_PUTS ("operator ");
946 /* Not exactly IDENTIFIER_TYPE_VALUE. */
947 dump_type (TREE_TYPE (t
), flags
);
950 else if (IDENTIFIER_OPNAME_P (t
))
952 const char *name_string
= operator_name_string (t
);
953 OB_PUTS ("operator");
954 if (ISALPHA (name_string
[0]))
956 OB_PUTCP (name_string
);
968 if (GLOBAL_IORD_P (DECL_ASSEMBLER_NAME (t
)))
969 dump_global_iord (DECL_ASSEMBLER_NAME (t
));
970 else if (! DECL_LANG_SPECIFIC (t
))
971 OB_PUTS ("{internal}");
972 else if (flags
& TS_PEDANTIC_NAME
)
973 dump_function_decl (t
, flags
| TS_FUNC_NORETURN
| TS_DECL_TYPE
);
975 dump_function_decl (t
, flags
);
979 if (flags
& TS_PEDANTIC_NAME
)
980 dump_template_decl (t
, flags
| TS_FUNC_NORETURN
| TS_DECL_TYPE
);
982 dump_template_decl (t
, flags
);
985 case TEMPLATE_ID_EXPR
:
988 tree name
= TREE_OPERAND (t
, 0);
989 if (is_overloaded_fn (name
))
990 name
= DECL_NAME (get_first_fn (name
));
991 dump_decl (name
, flags
);
993 for (args
= TREE_OPERAND (t
, 1); args
; args
= TREE_CHAIN (args
))
995 dump_template_argument (TREE_VALUE (args
), flags
);
996 if (TREE_CHAIN (args
))
999 OB_END_TEMPLATE_ID ();
1004 dump_decl (TREE_OPERAND (t
, 0), flags
);
1008 OB_PUTID (DECL_NAME (t
));
1012 if ((TREE_TYPE (t
) != NULL_TREE
&& NEXT_CODE (t
) == ENUMERAL_TYPE
)
1013 || (DECL_INITIAL (t
) &&
1014 TREE_CODE (DECL_INITIAL (t
)) == TEMPLATE_PARM_INDEX
))
1015 dump_simple_decl (t
, TREE_TYPE (t
), flags
);
1016 else if (DECL_NAME (t
))
1017 dump_decl (DECL_NAME (t
), flags
);
1018 else if (DECL_INITIAL (t
))
1019 dump_expr (DECL_INITIAL (t
), flags
| TS_EXPR_PARENS
);
1021 OB_PUTS ("enumerator");
1026 dump_type (DECL_INITIAL (t
), flags
);
1028 OB_PUTID (DECL_NAME (t
));
1032 sorry ("`%s' not supported by dump_decl",
1033 tree_code_name
[(int) TREE_CODE (t
)]);
1034 /* Fallthrough to error. */
1037 OB_PUTS ("{declaration error}");
1042 /* Dump a template declaration T under control of FLAGS. This means the
1043 'template <...> leaders plus the 'class X' or 'void fn(...)' part. */
1046 dump_template_decl (t
, flags
)
1048 enum tree_string_flags flags
;
1050 tree orig_parms
= DECL_TEMPLATE_PARMS (t
);
1054 if (flags
& TS_TEMPLATE_PREFIX
)
1056 for (parms
= orig_parms
= nreverse (orig_parms
);
1058 parms
= TREE_CHAIN (parms
))
1060 tree inner_parms
= INNERMOST_TEMPLATE_PARMS (parms
);
1061 int len
= TREE_VEC_LENGTH (inner_parms
);
1063 OB_PUTS ("template <");
1064 for (i
= 0; i
< len
; i
++)
1068 dump_template_parameter (TREE_VEC_ELT (inner_parms
, i
), flags
);
1070 OB_END_TEMPLATE_ID ();
1073 nreverse(orig_parms
);
1074 /* If we've shown the template<args> prefix, we'd better show the
1076 flags
|= TS_DECL_TYPE
;
1078 if (TREE_CODE (DECL_TEMPLATE_RESULT (t
)) == TYPE_DECL
)
1079 dump_type (TREE_TYPE (t
),
1080 ((flags
& ~TS_AGGR_TAGS
) | TS_TEMPLATE_PLAIN
1081 | (flags
& TS_DECL_TYPE
? TS_AGGR_TAGS
: 0)));
1082 else if (TREE_CODE (DECL_TEMPLATE_RESULT (t
)) == VAR_DECL
)
1083 dump_decl (DECL_TEMPLATE_RESULT (t
), flags
| TS_TEMPLATE_PLAIN
);
1084 else if (TREE_TYPE (t
) == NULL_TREE
)
1085 my_friendly_abort (353);
1087 switch (NEXT_CODE (t
))
1091 dump_function_decl (t
, flags
| TS_TEMPLATE_PLAIN
);
1094 /* This case can occur with some illegal code. */
1095 dump_type (TREE_TYPE (t
),
1096 (flags
& ~TS_AGGR_TAGS
) | TS_TEMPLATE_PLAIN
1097 | (flags
& TS_DECL_TYPE
? TS_AGGR_TAGS
: 0));
1101 /* Pretty print a function decl. There are several ways we want to print a
1102 function declaration. The TS_FUNC bits in FLAGS tells us how to behave.
1103 As cp_error can only apply the '#' flag once to give 0 and 1 for V, there
1104 is %D which doesn't print the throw specs, and %F which does. */
1107 dump_function_decl (t
, flags
)
1109 enum tree_string_flags flags
;
1113 tree cname
= NULL_TREE
;
1114 tree template_args
= NULL_TREE
;
1115 tree template_parms
= NULL_TREE
;
1116 int show_return
= !(flags
& TS_FUNC_NORETURN
) && (flags
& TS_DECL_TYPE
);
1118 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1119 t
= DECL_TEMPLATE_RESULT (t
);
1121 /* Pretty print template instantiations only. */
1122 if (DECL_USE_TEMPLATE (t
) && DECL_TEMPLATE_INFO (t
))
1124 template_args
= DECL_TI_ARGS (t
);
1125 t
= most_general_template (t
);
1126 if (TREE_CODE (t
) == TEMPLATE_DECL
)
1127 template_parms
= DECL_TEMPLATE_PARMS (t
);
1130 fntype
= TREE_TYPE (t
);
1131 parmtypes
= TYPE_ARG_TYPES (fntype
);
1133 if (DECL_CLASS_SCOPE_P (t
))
1134 cname
= DECL_CONTEXT (t
);
1135 /* this is for partially instantiated template methods */
1136 else if (TREE_CODE (fntype
) == METHOD_TYPE
)
1137 cname
= TREE_TYPE (TREE_VALUE (parmtypes
));
1139 if (!(flags
& TS_DECORATE
))
1141 else if (DECL_STATIC_FUNCTION_P (t
))
1142 OB_PUTS ("static ");
1143 else if (TYPE_POLYMORPHIC_P (t
))
1144 OB_PUTS ("virtual ");
1146 /* Print the return type? */
1148 show_return
= !DECL_CONV_FN_P (t
) && !DECL_CONSTRUCTOR_P (t
)
1149 && !DECL_DESTRUCTOR_P (t
);
1152 if (dump_type_prefix (TREE_TYPE (fntype
), flags
) != none
)
1156 /* Print the function name. */
1159 dump_type (cname
, flags
);
1163 dump_scope (CP_DECL_CONTEXT (t
), flags
);
1165 dump_function_name (t
, flags
);
1167 if (!(flags
& TS_DECL_TYPE
))
1169 if (TREE_CODE (fntype
) == METHOD_TYPE
&& parmtypes
)
1170 /* Skip "this" parameter. */
1171 parmtypes
= TREE_CHAIN (parmtypes
);
1173 if (DECL_DESTRUCTOR_P (t
) || DECL_CONSTRUCTOR_FOR_VBASE_P (t
))
1174 /* Skip past "in_charge" identifier. */
1175 parmtypes
= TREE_CHAIN (parmtypes
);
1177 dump_parameters (parmtypes
, flags
);
1180 dump_type_suffix (TREE_TYPE (fntype
), flags
);
1182 if (TREE_CODE (fntype
) == METHOD_TYPE
)
1183 dump_qualifiers (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype
))),
1186 if (flags
& TS_FUNC_THROW
)
1187 dump_exception_spec (TYPE_RAISES_EXCEPTIONS (fntype
), flags
);
1189 /* If T is a template instantiation, dump the parameter binding. */
1190 if (template_parms
!= NULL_TREE
&& template_args
!= NULL_TREE
)
1192 OB_PUTS (" [with ");
1193 dump_template_bindings (template_parms
, template_args
);
1198 /* Print a parameter list. If this is for a member function, the
1199 member object ptr (and any other hidden args) should have
1200 already been removed. */
1203 dump_parameters (parmtypes
, flags
)
1205 enum tree_string_flags flags
;
1210 for (first
= 1; parmtypes
!= void_list_node
;
1211 parmtypes
= TREE_CHAIN (parmtypes
))
1221 dump_type (TREE_VALUE (parmtypes
), flags
);
1223 if ((flags
& TS_PARM_DEFAULTS
) && TREE_PURPOSE (parmtypes
))
1226 dump_expr (TREE_PURPOSE (parmtypes
), flags
| TS_EXPR_PARENS
);
1233 /* Print an exception specification. T is the exception specification. */
1236 dump_exception_spec (t
, flags
)
1238 enum tree_string_flags flags
;
1242 OB_PUTS (" throw (");
1243 if (TREE_VALUE (t
) != NULL_TREE
)
1246 dump_type (TREE_VALUE (t
), flags
);
1256 /* Handle the function name for a FUNCTION_DECL node, grokking operators
1257 and destructors properly. */
1260 dump_function_name (t
, flags
)
1262 enum tree_string_flags flags
;
1264 tree name
= DECL_NAME (t
);
1266 if (DECL_DESTRUCTOR_P (t
))
1269 dump_decl (name
, TS_PLAIN
);
1271 else if (DECL_CONV_FN_P (t
))
1273 /* This cannot use the hack that the operator's return
1274 type is stashed off of its name because it may be
1275 used for error reporting. In the case of conflicting
1276 declarations, both will have the same name, yet
1277 the types will be different, hence the TREE_TYPE field
1278 of the first name will be clobbered by the second. */
1279 OB_PUTS ("operator ");
1280 dump_type (TREE_TYPE (TREE_TYPE (t
)), flags
);
1282 else if (IDENTIFIER_OPNAME_P (name
))
1284 const char *name_string
= operator_name_string (name
);
1285 OB_PUTS ("operator");
1286 if (ISALPHA (name_string
[0]))
1288 OB_PUTCP (name_string
);
1291 dump_decl (name
, flags
);
1293 if (DECL_LANG_SPECIFIC (t
) && DECL_TEMPLATE_INFO (t
)
1294 && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t
)
1295 && (DECL_TEMPLATE_SPECIALIZATION (t
)
1296 || TREE_CODE (DECL_TI_TEMPLATE (t
)) != TEMPLATE_DECL
1297 || DECL_TEMPLATE_SPECIALIZATION (DECL_TI_TEMPLATE (t
))
1298 || PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t
))))
1299 dump_template_parms (DECL_TEMPLATE_INFO (t
), !DECL_USE_TEMPLATE (t
), flags
);
1302 /* Dump the template parameters from the template info INFO under control of
1303 FLAGS. PRIMARY indicates whether this is a primary template decl, or
1304 specialization (partial or complete). For partial specializations we show
1305 the specialized parameter values. For a primary template we show no
1309 dump_template_parms (info
, primary
, flags
)
1312 enum tree_string_flags flags
;
1314 tree args
= info
? TI_ARGS (info
) : NULL_TREE
;
1316 if (primary
&& flags
& TS_TEMPLATE_PLAIN
)
1318 flags
&= ~(TS_AGGR_TAGS
| TS_TEMPLATE_PLAIN
);
1321 /* Be careful only to print things when we have them, so as not
1322 to crash producing error messages. */
1323 if (args
&& !primary
)
1329 if (TREE_CODE (args
) == TREE_VEC
)
1331 if (TREE_VEC_LENGTH (args
) > 0
1332 && TREE_CODE (TREE_VEC_ELT (args
, 0)) == TREE_VEC
)
1333 args
= TREE_VEC_ELT (args
, TREE_VEC_LENGTH (args
) - 1);
1335 len
= TREE_VEC_LENGTH (args
);
1337 else if (TREE_CODE (args
) == TREE_LIST
)
1339 while (ix
!= len
&& args
)
1344 arg
= TREE_VEC_ELT (args
, ix
);
1349 arg
= TREE_VALUE (args
);
1350 args
= TREE_CHAIN (args
);
1356 OB_PUTS ("{template parameter error}");
1358 dump_template_argument (arg
, flags
);
1364 tree tpl
= TI_TEMPLATE (info
);
1365 tree parms
= DECL_TEMPLATE_PARMS (tpl
);
1368 parms
= TREE_CODE (parms
) == TREE_LIST
? TREE_VALUE (parms
) : NULL_TREE
;
1369 len
= parms
? TREE_VEC_LENGTH (parms
) : 0;
1371 for (ix
= 0; ix
!= len
; ix
++)
1373 tree parm
= TREE_VALUE (TREE_VEC_ELT (parms
, ix
));
1378 dump_decl (parm
, flags
& ~TS_DECL_TYPE
);
1381 OB_END_TEMPLATE_ID ();
1390 case TARGET_NEWLINE
:
1425 sprintf (digit_buffer
, "\\%03o", (int) c
);
1426 OB_PUTCP (digit_buffer
);
1431 /* Print out a list of initializers (subr of dump_expr) */
1434 dump_expr_list (l
, flags
)
1436 enum tree_string_flags flags
;
1440 dump_expr (TREE_VALUE (l
), flags
| TS_EXPR_PARENS
);
1447 /* Print out an expression E under control of FLAGS. */
1450 dump_expr (t
, flags
)
1452 enum tree_string_flags flags
;
1454 switch (TREE_CODE (t
))
1462 case NAMESPACE_DECL
:
1464 dump_decl (t
, flags
& ~TS_DECL_TYPE
);
1469 tree type
= TREE_TYPE (t
);
1470 my_friendly_assert (type
!= 0, 81);
1472 /* If it's an enum, output its tag, rather than its value. */
1473 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1475 const char *p
= enum_name_string (t
, type
);
1478 else if (type
== boolean_type_node
)
1480 if (t
== boolean_false_node
1481 || (TREE_INT_CST_LOW (t
) == 0
1482 && TREE_INT_CST_HIGH (t
) == 0))
1484 else if (t
== boolean_true_node
)
1487 else if (type
== char_type_node
)
1490 dump_char (TREE_INT_CST_LOW (t
));
1493 else if ((unsigned HOST_WIDE_INT
) TREE_INT_CST_HIGH (t
)
1494 != (TREE_INT_CST_LOW (t
) >> (HOST_BITS_PER_WIDE_INT
- 1)))
1498 if (tree_int_cst_sgn (val
) < 0)
1501 val
= build_int_2 (~TREE_INT_CST_LOW (val
),
1502 -TREE_INT_CST_HIGH (val
));
1504 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
1507 static char format
[10]; /* "%x%09999x\0" */
1509 sprintf (format
, "%%x%%0%dx", HOST_BITS_PER_INT
/ 4);
1510 sprintf (digit_buffer
, format
, TREE_INT_CST_HIGH (val
),
1511 TREE_INT_CST_LOW (val
));
1512 OB_PUTCP (digit_buffer
);
1516 OB_PUTI (TREE_INT_CST_LOW (t
));
1521 #ifndef REAL_IS_NOT_DOUBLE
1522 sprintf (digit_buffer
, "%g", TREE_REAL_CST (t
));
1525 const unsigned char *p
= (const unsigned char *) &TREE_REAL_CST (t
);
1527 strcpy (digit_buffer
, "0x");
1528 for (i
= 0; i
< sizeof TREE_REAL_CST (t
); i
++)
1529 sprintf (digit_buffer
+ 2 + 2*i
, "%02x", *p
++);
1532 OB_PUTCP (digit_buffer
);
1537 dump_type (PTRMEM_CST_CLASS (t
), flags
);
1539 OB_PUTID (DECL_NAME (PTRMEM_CST_MEMBER (t
)));
1544 const char *p
= TREE_STRING_POINTER (t
);
1545 int len
= TREE_STRING_LENGTH (t
) - 1;
1549 for (i
= 0; i
< len
; i
++)
1557 dump_expr (TREE_OPERAND (t
, 0), flags
| TS_EXPR_PARENS
);
1559 dump_expr (TREE_OPERAND (t
, 1), flags
| TS_EXPR_PARENS
);
1565 dump_expr (TREE_OPERAND (t
, 0), flags
| TS_EXPR_PARENS
);
1567 dump_expr (TREE_OPERAND (t
, 1), flags
| TS_EXPR_PARENS
);
1569 dump_expr (TREE_OPERAND (t
, 2), flags
| TS_EXPR_PARENS
);
1574 if (TREE_HAS_CONSTRUCTOR (t
))
1577 dump_type (TREE_TYPE (TREE_TYPE (t
)), flags
);
1581 dump_expr (TREE_OPERAND (t
, 0), flags
| TS_EXPR_PARENS
);
1585 case AGGR_INIT_EXPR
:
1587 tree fn
= NULL_TREE
;
1589 if (TREE_CODE (TREE_OPERAND (t
, 0)) == ADDR_EXPR
)
1590 fn
= TREE_OPERAND (TREE_OPERAND (t
, 0), 0);
1592 if (fn
&& TREE_CODE (fn
) == FUNCTION_DECL
)
1594 if (DECL_CONSTRUCTOR_P (fn
))
1595 OB_PUTID (TYPE_IDENTIFIER (TREE_TYPE (t
)));
1600 dump_expr (TREE_OPERAND (t
, 0), 0);
1603 if (TREE_OPERAND (t
, 1))
1604 dump_expr_list (TREE_CHAIN (TREE_OPERAND (t
, 1)), flags
);
1610 tree fn
= TREE_OPERAND (t
, 0);
1611 tree args
= TREE_OPERAND (t
, 1);
1613 if (TREE_CODE (fn
) == ADDR_EXPR
)
1614 fn
= TREE_OPERAND (fn
, 0);
1616 if (TREE_TYPE (fn
) != NULL_TREE
&& NEXT_CODE (fn
) == METHOD_TYPE
)
1618 tree ob
= TREE_VALUE (args
);
1619 if (TREE_CODE (ob
) == ADDR_EXPR
)
1621 dump_expr (TREE_OPERAND (ob
, 0), flags
| TS_EXPR_PARENS
);
1624 else if (TREE_CODE (ob
) != PARM_DECL
1625 || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob
)), "this"))
1627 dump_expr (ob
, flags
| TS_EXPR_PARENS
);
1630 args
= TREE_CHAIN (args
);
1632 dump_expr (fn
, flags
| TS_EXPR_PARENS
);
1634 dump_expr_list (args
, flags
);
1641 tree type
= TREE_OPERAND (t
, 1);
1642 if (NEW_EXPR_USE_GLOBAL (t
))
1645 if (TREE_OPERAND (t
, 0))
1648 dump_expr_list (TREE_OPERAND (t
, 0), flags
);
1651 if (TREE_CODE (type
) == ARRAY_REF
)
1652 type
= build_cplus_array_type
1653 (TREE_OPERAND (type
, 0),
1654 build_index_type (fold (build (MINUS_EXPR
, integer_type_node
,
1655 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
))
2151 dump_type (CP_DECL_CONTEXT (decl
), TS_PLAIN
);
2155 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2156 dump_function_name (decl
, TS_PLAIN
);
2158 dump_decl (DECL_NAME (decl
), TS_PLAIN
);
2162 return (char *)obstack_base (&scratch_obstack
);
2169 if (TREE_CODE (t
) == PARM_DECL
&& DECL_CONTEXT (t
))
2170 return DECL_SOURCE_FILE (DECL_CONTEXT (t
));
2171 else if (TREE_CODE_CLASS (TREE_CODE (t
)) == 't')
2172 return DECL_SOURCE_FILE (TYPE_MAIN_DECL (t
));
2173 else if (TREE_CODE (t
) == OVERLOAD
)
2174 return DECL_SOURCE_FILE (OVL_FUNCTION (t
));
2176 return DECL_SOURCE_FILE (t
);
2184 if (TREE_CODE (t
) == PARM_DECL
&& DECL_CONTEXT (t
))
2185 line
= DECL_SOURCE_LINE (DECL_CONTEXT (t
));
2186 if (TREE_CODE (t
) == TYPE_DECL
&& DECL_ARTIFICIAL (t
)
2187 && TYPE_MAIN_DECL (TREE_TYPE (t
)))
2190 if (TREE_CODE_CLASS (TREE_CODE (t
)) == 't')
2191 line
= DECL_SOURCE_LINE (TYPE_MAIN_DECL (t
));
2192 else if (TREE_CODE (t
) == OVERLOAD
)
2193 line
= DECL_SOURCE_LINE (OVL_FUNCTION (t
));
2195 line
= DECL_SOURCE_LINE (t
);
2203 /* Now the interfaces from cp_error et al to dump_type et al. Each takes an
2204 on/off VERBOSE flag and supply the appropriate TS_ flags to a dump_
2208 decl_to_string (decl
, verbose
)
2212 enum tree_string_flags flags
= 0;
2214 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == RECORD_TYPE
2215 || TREE_CODE (decl
) == UNION_TYPE
|| TREE_CODE (decl
) == ENUMERAL_TYPE
)
2216 flags
= TS_AGGR_TAGS
;
2218 flags
|= TS_DECL_TYPE
| TS_DECORATE
| TS_PARM_DEFAULTS
;
2219 else if (TREE_CODE (decl
) == FUNCTION_DECL
)
2220 flags
|= TS_DECL_TYPE
| TS_FUNC_NORETURN
;
2221 flags
|= TS_TEMPLATE_PREFIX
;
2225 dump_decl (decl
, flags
);
2229 return (char *)obstack_base (&scratch_obstack
);
2233 expr_to_string (decl
, verbose
)
2235 int verbose ATTRIBUTE_UNUSED
;
2239 dump_expr (decl
, 0);
2243 return (char *)obstack_base (&scratch_obstack
);
2247 fndecl_to_string (fndecl
, verbose
)
2251 enum tree_string_flags flags
;
2253 flags
= TS_FUNC_THROW
| TS_DECL_TYPE
;
2255 flags
|= TS_PARM_DEFAULTS
;
2258 dump_decl (fndecl
, flags
);
2262 return (char *)obstack_base (&scratch_obstack
);
2267 code_to_string (c
, v
)
2269 int v ATTRIBUTE_UNUSED
;
2271 return tree_code_name
[c
];
2275 language_to_string (c
, v
)
2277 int v ATTRIBUTE_UNUSED
;
2284 case lang_cplusplus
:
2291 my_friendly_abort (355);
2296 /* Return the proper printed version of a parameter to a C++ function. */
2299 parm_to_string (p
, v
)
2301 int v ATTRIBUTE_UNUSED
;
2306 sprintf (digit_buffer
, "%d", p
+1);
2307 return digit_buffer
;
2313 int v ATTRIBUTE_UNUSED
;
2315 static char buf
[] = "operator ";
2320 strcpy (buf
+ 8, opname_tab
[p
]);
2325 type_to_string (typ
, verbose
)
2329 enum tree_string_flags flags
;
2333 flags
|= TS_AGGR_TAGS
;
2334 flags
|= TS_TEMPLATE_PREFIX
;
2338 dump_type (typ
, flags
);
2342 return (char *)obstack_base (&scratch_obstack
);
2346 assop_to_string (p
, v
)
2348 int v ATTRIBUTE_UNUSED
;
2350 static char buf
[] = "operator ";
2355 strcpy (buf
+ 9, assignop_tab
[p
]);
2360 args_to_string (p
, verbose
)
2364 enum tree_string_flags flags
= 0;
2366 flags
|= TS_AGGR_TAGS
;
2371 if (TREE_CODE_CLASS (TREE_CODE (TREE_VALUE (p
))) == 't')
2372 return type_as_string (p
, flags
);
2375 for (; p
; p
= TREE_CHAIN (p
))
2377 if (TREE_VALUE (p
) == null_node
)
2380 dump_type (error_type (TREE_VALUE (p
)), flags
);
2385 return (char *)obstack_base (&scratch_obstack
);
2391 int v ATTRIBUTE_UNUSED
;
2395 dump_qualifiers (p
, before
);
2399 return (char *)obstack_base (&scratch_obstack
);