1*e4b17023SJohn Marino /* Prints out trees in human readable form.
2*e4b17023SJohn Marino Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998,
3*e4b17023SJohn Marino 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2010
4*e4b17023SJohn Marino Free Software Foundation, Inc.
5*e4b17023SJohn Marino Hacked by Michael Tiemann (tiemann@cygnus.com)
6*e4b17023SJohn Marino
7*e4b17023SJohn Marino This file is part of GCC.
8*e4b17023SJohn Marino
9*e4b17023SJohn Marino GCC is free software; you can redistribute it and/or modify
10*e4b17023SJohn Marino it under the terms of the GNU General Public License as published by
11*e4b17023SJohn Marino the Free Software Foundation; either version 3, or (at your option)
12*e4b17023SJohn Marino any later version.
13*e4b17023SJohn Marino
14*e4b17023SJohn Marino GCC is distributed in the hope that it will be useful,
15*e4b17023SJohn Marino but WITHOUT ANY WARRANTY; without even the implied warranty of
16*e4b17023SJohn Marino MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17*e4b17023SJohn Marino GNU General Public License for more details.
18*e4b17023SJohn Marino
19*e4b17023SJohn Marino You should have received a copy of the GNU General Public License
20*e4b17023SJohn Marino along with GCC; see the file COPYING3. If not see
21*e4b17023SJohn Marino <http://www.gnu.org/licenses/>. */
22*e4b17023SJohn Marino
23*e4b17023SJohn Marino
24*e4b17023SJohn Marino #include "config.h"
25*e4b17023SJohn Marino #include "system.h"
26*e4b17023SJohn Marino #include "coretypes.h"
27*e4b17023SJohn Marino #include "tm.h"
28*e4b17023SJohn Marino #include "tree.h"
29*e4b17023SJohn Marino #include "cp-tree.h"
30*e4b17023SJohn Marino
31*e4b17023SJohn Marino void
cxx_print_decl(FILE * file,tree node,int indent)32*e4b17023SJohn Marino cxx_print_decl (FILE *file, tree node, int indent)
33*e4b17023SJohn Marino {
34*e4b17023SJohn Marino if (TREE_CODE (node) == FIELD_DECL)
35*e4b17023SJohn Marino {
36*e4b17023SJohn Marino if (DECL_MUTABLE_P (node))
37*e4b17023SJohn Marino {
38*e4b17023SJohn Marino indent_to (file, indent + 3);
39*e4b17023SJohn Marino fprintf (file, " mutable ");
40*e4b17023SJohn Marino }
41*e4b17023SJohn Marino return;
42*e4b17023SJohn Marino }
43*e4b17023SJohn Marino
44*e4b17023SJohn Marino if (!CODE_CONTAINS_STRUCT (TREE_CODE (node), TS_DECL_COMMON)
45*e4b17023SJohn Marino || !DECL_LANG_SPECIFIC (node))
46*e4b17023SJohn Marino return;
47*e4b17023SJohn Marino if (TREE_CODE (node) == FUNCTION_DECL)
48*e4b17023SJohn Marino {
49*e4b17023SJohn Marino int flags = TFF_DECL_SPECIFIERS|TFF_RETURN_TYPE
50*e4b17023SJohn Marino |TFF_FUNCTION_DEFAULT_ARGUMENTS|TFF_EXCEPTION_SPECIFICATION ;
51*e4b17023SJohn Marino indent_to (file, indent + 3);
52*e4b17023SJohn Marino fprintf (file, " full-name \"%s\"", decl_as_string (node, flags));
53*e4b17023SJohn Marino }
54*e4b17023SJohn Marino else if (TREE_CODE (node) == TEMPLATE_DECL)
55*e4b17023SJohn Marino {
56*e4b17023SJohn Marino indent_to (file, indent + 3);
57*e4b17023SJohn Marino fprintf (file, " full-name \"%s\"",
58*e4b17023SJohn Marino decl_as_string (node, TFF_TEMPLATE_HEADER));
59*e4b17023SJohn Marino }
60*e4b17023SJohn Marino
61*e4b17023SJohn Marino indent_to (file, indent + 3);
62*e4b17023SJohn Marino if (DECL_EXTERNAL (node) && DECL_NOT_REALLY_EXTERN (node))
63*e4b17023SJohn Marino fprintf (file, " not-really-extern");
64*e4b17023SJohn Marino if (TREE_CODE (node) == FUNCTION_DECL
65*e4b17023SJohn Marino && DECL_PENDING_INLINE_INFO (node))
66*e4b17023SJohn Marino fprintf (file, " pending-inline-info %p",
67*e4b17023SJohn Marino (void *) DECL_PENDING_INLINE_INFO (node));
68*e4b17023SJohn Marino if ((TREE_CODE (node) == FUNCTION_DECL || TREE_CODE (node) == VAR_DECL)
69*e4b17023SJohn Marino && DECL_TEMPLATE_INFO (node))
70*e4b17023SJohn Marino fprintf (file, " template-info %p",
71*e4b17023SJohn Marino (void *) DECL_TEMPLATE_INFO (node));
72*e4b17023SJohn Marino }
73*e4b17023SJohn Marino
74*e4b17023SJohn Marino void
cxx_print_type(FILE * file,tree node,int indent)75*e4b17023SJohn Marino cxx_print_type (FILE *file, tree node, int indent)
76*e4b17023SJohn Marino {
77*e4b17023SJohn Marino switch (TREE_CODE (node))
78*e4b17023SJohn Marino {
79*e4b17023SJohn Marino case TEMPLATE_TYPE_PARM:
80*e4b17023SJohn Marino case TEMPLATE_TEMPLATE_PARM:
81*e4b17023SJohn Marino case BOUND_TEMPLATE_TEMPLATE_PARM:
82*e4b17023SJohn Marino indent_to (file, indent + 3);
83*e4b17023SJohn Marino fprintf (file, "index %d level %d orig_level %d",
84*e4b17023SJohn Marino TEMPLATE_TYPE_IDX (node), TEMPLATE_TYPE_LEVEL (node),
85*e4b17023SJohn Marino TEMPLATE_TYPE_ORIG_LEVEL (node));
86*e4b17023SJohn Marino return;
87*e4b17023SJohn Marino
88*e4b17023SJohn Marino case FUNCTION_TYPE:
89*e4b17023SJohn Marino case METHOD_TYPE:
90*e4b17023SJohn Marino if (TYPE_RAISES_EXCEPTIONS (node))
91*e4b17023SJohn Marino print_node (file, "throws", TYPE_RAISES_EXCEPTIONS (node), indent + 4);
92*e4b17023SJohn Marino return;
93*e4b17023SJohn Marino
94*e4b17023SJohn Marino case RECORD_TYPE:
95*e4b17023SJohn Marino case UNION_TYPE:
96*e4b17023SJohn Marino break;
97*e4b17023SJohn Marino
98*e4b17023SJohn Marino case DECLTYPE_TYPE:
99*e4b17023SJohn Marino print_node (file, "expr", DECLTYPE_TYPE_EXPR (node), indent + 4);
100*e4b17023SJohn Marino return;
101*e4b17023SJohn Marino
102*e4b17023SJohn Marino case TYPENAME_TYPE:
103*e4b17023SJohn Marino print_node (file, "fullname", TYPENAME_TYPE_FULLNAME (node),
104*e4b17023SJohn Marino indent + 4);
105*e4b17023SJohn Marino return;
106*e4b17023SJohn Marino
107*e4b17023SJohn Marino case TYPE_PACK_EXPANSION:
108*e4b17023SJohn Marino print_node (file, "args", PACK_EXPANSION_EXTRA_ARGS (node), indent + 4);
109*e4b17023SJohn Marino return;
110*e4b17023SJohn Marino
111*e4b17023SJohn Marino default:
112*e4b17023SJohn Marino return;
113*e4b17023SJohn Marino }
114*e4b17023SJohn Marino
115*e4b17023SJohn Marino if (TYPE_PTRMEMFUNC_P (node))
116*e4b17023SJohn Marino print_node (file, "ptrmemfunc fn type", TYPE_PTRMEMFUNC_FN_TYPE (node),
117*e4b17023SJohn Marino indent + 4);
118*e4b17023SJohn Marino
119*e4b17023SJohn Marino if (! CLASS_TYPE_P (node))
120*e4b17023SJohn Marino return;
121*e4b17023SJohn Marino
122*e4b17023SJohn Marino indent_to (file, indent + 4);
123*e4b17023SJohn Marino fprintf (file, "full-name \"%s\"",
124*e4b17023SJohn Marino type_as_string (node, TFF_CLASS_KEY_OR_ENUM));
125*e4b17023SJohn Marino
126*e4b17023SJohn Marino indent_to (file, indent + 3);
127*e4b17023SJohn Marino
128*e4b17023SJohn Marino if (TYPE_NEEDS_CONSTRUCTING (node))
129*e4b17023SJohn Marino fputs ( " needs-constructor", file);
130*e4b17023SJohn Marino if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (node))
131*e4b17023SJohn Marino fputs (" needs-destructor", file);
132*e4b17023SJohn Marino if (TYPE_HAS_DEFAULT_CONSTRUCTOR (node))
133*e4b17023SJohn Marino fputs (" X()", file);
134*e4b17023SJohn Marino if (TYPE_HAS_CONVERSION (node))
135*e4b17023SJohn Marino fputs (" has-type-conversion", file);
136*e4b17023SJohn Marino if (TYPE_HAS_COPY_CTOR (node))
137*e4b17023SJohn Marino {
138*e4b17023SJohn Marino if (TYPE_HAS_CONST_COPY_CTOR (node))
139*e4b17023SJohn Marino fputs (" X(constX&)", file);
140*e4b17023SJohn Marino else
141*e4b17023SJohn Marino fputs (" X(X&)", file);
142*e4b17023SJohn Marino }
143*e4b17023SJohn Marino if (TYPE_HAS_NEW_OPERATOR (node))
144*e4b17023SJohn Marino fputs (" new", file);
145*e4b17023SJohn Marino if (TYPE_HAS_ARRAY_NEW_OPERATOR (node))
146*e4b17023SJohn Marino fputs (" new[]", file);
147*e4b17023SJohn Marino if (TYPE_GETS_DELETE (node) & 1)
148*e4b17023SJohn Marino fputs (" delete", file);
149*e4b17023SJohn Marino if (TYPE_GETS_DELETE (node) & 2)
150*e4b17023SJohn Marino fputs (" delete[]", file);
151*e4b17023SJohn Marino if (TYPE_HAS_COPY_ASSIGN (node))
152*e4b17023SJohn Marino fputs (" this=(X&)", file);
153*e4b17023SJohn Marino if (CLASSTYPE_SORTED_FIELDS (node))
154*e4b17023SJohn Marino fprintf (file, " sorted-fields %p",
155*e4b17023SJohn Marino (void *) CLASSTYPE_SORTED_FIELDS (node));
156*e4b17023SJohn Marino
157*e4b17023SJohn Marino if (TREE_CODE (node) == RECORD_TYPE)
158*e4b17023SJohn Marino {
159*e4b17023SJohn Marino if (TYPE_BINFO (node))
160*e4b17023SJohn Marino fprintf (file, " n_parents=%d",
161*e4b17023SJohn Marino BINFO_N_BASE_BINFOS (TYPE_BINFO (node)));
162*e4b17023SJohn Marino else
163*e4b17023SJohn Marino fprintf (file, " no-binfo");
164*e4b17023SJohn Marino
165*e4b17023SJohn Marino fprintf (file, " use_template=%d", CLASSTYPE_USE_TEMPLATE (node));
166*e4b17023SJohn Marino if (CLASSTYPE_INTERFACE_ONLY (node))
167*e4b17023SJohn Marino fprintf (file, " interface-only");
168*e4b17023SJohn Marino if (CLASSTYPE_INTERFACE_UNKNOWN (node))
169*e4b17023SJohn Marino fprintf (file, " interface-unknown");
170*e4b17023SJohn Marino }
171*e4b17023SJohn Marino }
172*e4b17023SJohn Marino
173*e4b17023SJohn Marino
174*e4b17023SJohn Marino static void
cxx_print_binding(FILE * stream,cxx_binding * binding,const char * prefix)175*e4b17023SJohn Marino cxx_print_binding (FILE *stream, cxx_binding *binding, const char *prefix)
176*e4b17023SJohn Marino {
177*e4b17023SJohn Marino fprintf (stream, "%s <%p>",
178*e4b17023SJohn Marino prefix, (void *) binding);
179*e4b17023SJohn Marino }
180*e4b17023SJohn Marino
181*e4b17023SJohn Marino void
cxx_print_identifier(FILE * file,tree node,int indent)182*e4b17023SJohn Marino cxx_print_identifier (FILE *file, tree node, int indent)
183*e4b17023SJohn Marino {
184*e4b17023SJohn Marino if (indent == 0)
185*e4b17023SJohn Marino fprintf (file, " ");
186*e4b17023SJohn Marino else
187*e4b17023SJohn Marino indent_to (file, indent + 4);
188*e4b17023SJohn Marino cxx_print_binding (file, IDENTIFIER_NAMESPACE_BINDINGS (node), "bindings");
189*e4b17023SJohn Marino if (indent == 0)
190*e4b17023SJohn Marino fprintf (file, " ");
191*e4b17023SJohn Marino else
192*e4b17023SJohn Marino indent_to (file, indent + 4);
193*e4b17023SJohn Marino cxx_print_binding (file, IDENTIFIER_BINDING (node), "local bindings");
194*e4b17023SJohn Marino print_node (file, "label", IDENTIFIER_LABEL_VALUE (node), indent + 4);
195*e4b17023SJohn Marino print_node (file, "template", IDENTIFIER_TEMPLATE (node), indent + 4);
196*e4b17023SJohn Marino }
197*e4b17023SJohn Marino
198*e4b17023SJohn Marino void
cxx_print_xnode(FILE * file,tree node,int indent)199*e4b17023SJohn Marino cxx_print_xnode (FILE *file, tree node, int indent)
200*e4b17023SJohn Marino {
201*e4b17023SJohn Marino switch (TREE_CODE (node))
202*e4b17023SJohn Marino {
203*e4b17023SJohn Marino case BASELINK:
204*e4b17023SJohn Marino print_node (file, "functions", BASELINK_FUNCTIONS (node), indent + 4);
205*e4b17023SJohn Marino print_node (file, "binfo", BASELINK_BINFO (node), indent + 4);
206*e4b17023SJohn Marino print_node (file, "access_binfo", BASELINK_ACCESS_BINFO (node),
207*e4b17023SJohn Marino indent + 4);
208*e4b17023SJohn Marino break;
209*e4b17023SJohn Marino case OVERLOAD:
210*e4b17023SJohn Marino print_node (file, "function", OVL_FUNCTION (node), indent+4);
211*e4b17023SJohn Marino print_node (file, "chain", TREE_CHAIN (node), indent+4);
212*e4b17023SJohn Marino break;
213*e4b17023SJohn Marino case TEMPLATE_PARM_INDEX:
214*e4b17023SJohn Marino indent_to (file, indent + 3);
215*e4b17023SJohn Marino fprintf (file, "index %d level %d orig_level %d",
216*e4b17023SJohn Marino TEMPLATE_PARM_IDX (node), TEMPLATE_PARM_LEVEL (node),
217*e4b17023SJohn Marino TEMPLATE_PARM_ORIG_LEVEL (node));
218*e4b17023SJohn Marino break;
219*e4b17023SJohn Marino case TEMPLATE_INFO:
220*e4b17023SJohn Marino print_node (file, "template", TI_TEMPLATE (node), indent+4);
221*e4b17023SJohn Marino print_node (file, "args", TI_ARGS (node), indent+4);
222*e4b17023SJohn Marino if (TI_PENDING_TEMPLATE_FLAG (node))
223*e4b17023SJohn Marino {
224*e4b17023SJohn Marino indent_to (file, indent + 3);
225*e4b17023SJohn Marino fprintf (file, "pending_template");
226*e4b17023SJohn Marino }
227*e4b17023SJohn Marino break;
228*e4b17023SJohn Marino case ARGUMENT_PACK_SELECT:
229*e4b17023SJohn Marino print_node (file, "pack", ARGUMENT_PACK_SELECT_FROM_PACK (node),
230*e4b17023SJohn Marino indent+4);
231*e4b17023SJohn Marino indent_to (file, indent + 3);
232*e4b17023SJohn Marino fprintf (file, "index %d", ARGUMENT_PACK_SELECT_INDEX (node));
233*e4b17023SJohn Marino break;
234*e4b17023SJohn Marino case DEFERRED_NOEXCEPT:
235*e4b17023SJohn Marino print_node (file, "pattern", DEFERRED_NOEXCEPT_PATTERN (node), indent+4);
236*e4b17023SJohn Marino print_node (file, "args", DEFERRED_NOEXCEPT_ARGS (node), indent+4);
237*e4b17023SJohn Marino break;
238*e4b17023SJohn Marino default:
239*e4b17023SJohn Marino break;
240*e4b17023SJohn Marino }
241*e4b17023SJohn Marino }
242