* xvasprintf.c: New file.
[official-gcc.git] / gcc / cp / ptree.c
blobe99f386acc04f68e2f67ef16dbdba511496f0839
1 /* Prints out trees in human readable form.
2 Copyright (C) 1992-2014 Free Software Foundation, Inc.
3 Hacked by Michael Tiemann (tiemann@cygnus.com)
5 This file is part of GCC.
7 GCC 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 3, or (at your option)
10 any later version.
12 GCC 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 GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "tree.h"
27 #include "print-tree.h"
28 #include "cp-tree.h"
30 void
31 cxx_print_decl (FILE *file, tree node, int indent)
33 if (TREE_CODE (node) == FIELD_DECL)
35 if (DECL_MUTABLE_P (node))
37 indent_to (file, indent + 3);
38 fprintf (file, " mutable ");
40 return;
43 if (!CODE_CONTAINS_STRUCT (TREE_CODE (node), TS_DECL_COMMON)
44 || !DECL_LANG_SPECIFIC (node))
45 return;
46 if (TREE_CODE (node) == FUNCTION_DECL)
48 int flags = TFF_DECL_SPECIFIERS|TFF_RETURN_TYPE
49 |TFF_FUNCTION_DEFAULT_ARGUMENTS|TFF_EXCEPTION_SPECIFICATION ;
50 indent_to (file, indent + 3);
51 fprintf (file, " full-name \"%s\"", decl_as_string (node, flags));
53 else if (TREE_CODE (node) == TEMPLATE_DECL)
55 indent_to (file, indent + 3);
56 fprintf (file, " full-name \"%s\"",
57 decl_as_string (node, TFF_TEMPLATE_HEADER));
60 indent_to (file, indent + 3);
61 if (DECL_EXTERNAL (node) && DECL_NOT_REALLY_EXTERN (node))
62 fprintf (file, " not-really-extern");
63 if (TREE_CODE (node) == FUNCTION_DECL
64 && DECL_PENDING_INLINE_INFO (node))
65 fprintf (file, " pending-inline-info %p",
66 (void *) DECL_PENDING_INLINE_INFO (node));
67 if (VAR_OR_FUNCTION_DECL_P (node)
68 && DECL_TEMPLATE_INFO (node))
69 fprintf (file, " template-info %p",
70 (void *) DECL_TEMPLATE_INFO (node));
73 void
74 cxx_print_type (FILE *file, tree node, int indent)
76 switch (TREE_CODE (node))
78 case TEMPLATE_TYPE_PARM:
79 case TEMPLATE_TEMPLATE_PARM:
80 case BOUND_TEMPLATE_TEMPLATE_PARM:
81 indent_to (file, indent + 3);
82 fprintf (file, "index %d level %d orig_level %d",
83 TEMPLATE_TYPE_IDX (node), TEMPLATE_TYPE_LEVEL (node),
84 TEMPLATE_TYPE_ORIG_LEVEL (node));
85 return;
87 case FUNCTION_TYPE:
88 case METHOD_TYPE:
89 if (TYPE_RAISES_EXCEPTIONS (node))
90 print_node (file, "throws", TYPE_RAISES_EXCEPTIONS (node), indent + 4);
91 return;
93 case RECORD_TYPE:
94 case UNION_TYPE:
95 break;
97 case DECLTYPE_TYPE:
98 print_node (file, "expr", DECLTYPE_TYPE_EXPR (node), indent + 4);
99 return;
101 case TYPENAME_TYPE:
102 print_node (file, "fullname", TYPENAME_TYPE_FULLNAME (node),
103 indent + 4);
104 return;
106 case TYPE_PACK_EXPANSION:
107 print_node (file, "args", PACK_EXPANSION_EXTRA_ARGS (node), indent + 4);
108 return;
110 default:
111 return;
114 if (TYPE_PTRMEMFUNC_P (node))
115 print_node (file, "ptrmemfunc fn type", TYPE_PTRMEMFUNC_FN_TYPE (node),
116 indent + 4);
118 if (! CLASS_TYPE_P (node))
119 return;
121 indent_to (file, indent + 4);
122 fprintf (file, "full-name \"%s\"",
123 type_as_string (node, TFF_CLASS_KEY_OR_ENUM));
125 indent_to (file, indent + 3);
127 if (TYPE_NEEDS_CONSTRUCTING (node))
128 fputs ( " needs-constructor", file);
129 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (node))
130 fputs (" needs-destructor", file);
131 if (TYPE_HAS_DEFAULT_CONSTRUCTOR (node))
132 fputs (" X()", file);
133 if (TYPE_HAS_CONVERSION (node))
134 fputs (" has-type-conversion", file);
135 if (TYPE_HAS_COPY_CTOR (node))
137 if (TYPE_HAS_CONST_COPY_CTOR (node))
138 fputs (" X(constX&)", file);
139 else
140 fputs (" X(X&)", file);
142 if (TYPE_HAS_NEW_OPERATOR (node))
143 fputs (" new", file);
144 if (TYPE_HAS_ARRAY_NEW_OPERATOR (node))
145 fputs (" new[]", file);
146 if (TYPE_GETS_DELETE (node) & 1)
147 fputs (" delete", file);
148 if (TYPE_GETS_DELETE (node) & 2)
149 fputs (" delete[]", file);
150 if (TYPE_HAS_COPY_ASSIGN (node))
151 fputs (" this=(X&)", file);
152 if (CLASSTYPE_SORTED_FIELDS (node))
153 fprintf (file, " sorted-fields %p",
154 (void *) CLASSTYPE_SORTED_FIELDS (node));
156 if (TREE_CODE (node) == RECORD_TYPE)
158 if (TYPE_BINFO (node))
159 fprintf (file, " n_parents=%d",
160 BINFO_N_BASE_BINFOS (TYPE_BINFO (node)));
161 else
162 fprintf (file, " no-binfo");
164 fprintf (file, " use_template=%d", CLASSTYPE_USE_TEMPLATE (node));
165 if (CLASSTYPE_INTERFACE_ONLY (node))
166 fprintf (file, " interface-only");
167 if (CLASSTYPE_INTERFACE_UNKNOWN (node))
168 fprintf (file, " interface-unknown");
173 static void
174 cxx_print_binding (FILE *stream, cxx_binding *binding, const char *prefix)
176 fprintf (stream, "%s <%p>",
177 prefix, (void *) binding);
180 void
181 cxx_print_identifier (FILE *file, tree node, int indent)
183 if (indent == 0)
184 fprintf (file, " ");
185 else
186 indent_to (file, indent + 4);
187 cxx_print_binding (file, IDENTIFIER_NAMESPACE_BINDINGS (node), "bindings");
188 if (indent == 0)
189 fprintf (file, " ");
190 else
191 indent_to (file, indent + 4);
192 cxx_print_binding (file, IDENTIFIER_BINDING (node), "local bindings");
193 print_node (file, "label", IDENTIFIER_LABEL_VALUE (node), indent + 4);
194 print_node (file, "template", IDENTIFIER_TEMPLATE (node), indent + 4);
197 void
198 cxx_print_xnode (FILE *file, tree node, int indent)
200 switch (TREE_CODE (node))
202 case BASELINK:
203 print_node (file, "functions", BASELINK_FUNCTIONS (node), indent + 4);
204 print_node (file, "binfo", BASELINK_BINFO (node), indent + 4);
205 print_node (file, "access_binfo", BASELINK_ACCESS_BINFO (node),
206 indent + 4);
207 break;
208 case OVERLOAD:
209 print_node (file, "function", OVL_FUNCTION (node), indent+4);
210 print_node (file, "chain", TREE_CHAIN (node), indent+4);
211 break;
212 case TEMPLATE_PARM_INDEX:
213 indent_to (file, indent + 3);
214 fprintf (file, "index %d level %d orig_level %d",
215 TEMPLATE_PARM_IDX (node), TEMPLATE_PARM_LEVEL (node),
216 TEMPLATE_PARM_ORIG_LEVEL (node));
217 break;
218 case TEMPLATE_INFO:
219 print_node (file, "template", TI_TEMPLATE (node), indent+4);
220 print_node (file, "args", TI_ARGS (node), indent+4);
221 if (TI_PENDING_TEMPLATE_FLAG (node))
223 indent_to (file, indent + 3);
224 fprintf (file, "pending_template");
226 break;
227 case ARGUMENT_PACK_SELECT:
228 print_node (file, "pack", ARGUMENT_PACK_SELECT_FROM_PACK (node),
229 indent+4);
230 indent_to (file, indent + 3);
231 fprintf (file, "index %d", ARGUMENT_PACK_SELECT_INDEX (node));
232 break;
233 case DEFERRED_NOEXCEPT:
234 print_node (file, "pattern", DEFERRED_NOEXCEPT_PATTERN (node), indent+4);
235 print_node (file, "args", DEFERRED_NOEXCEPT_ARGS (node), indent+4);
236 break;
237 default:
238 break;