* ptree.c (cxx_print_lambda_node): New.
[official-gcc.git] / gcc / cp / ptree.c
blob2d0b584e7ab1b3004dbd766ae6d987fe34c99c30
1 /* Prints out trees in human readable form.
2 Copyright (C) 1992-2015 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 "hash-set.h"
27 #include "machmode.h"
28 #include "vec.h"
29 #include "double-int.h"
30 #include "input.h"
31 #include "alias.h"
32 #include "symtab.h"
33 #include "wide-int.h"
34 #include "inchash.h"
35 #include "tree.h"
36 #include "print-tree.h"
37 #include "cp-tree.h"
39 void
40 cxx_print_decl (FILE *file, tree node, int indent)
42 if (TREE_CODE (node) == FIELD_DECL)
44 if (DECL_MUTABLE_P (node))
46 indent_to (file, indent + 3);
47 fprintf (file, " mutable ");
49 return;
52 if (!CODE_CONTAINS_STRUCT (TREE_CODE (node), TS_DECL_COMMON)
53 || !DECL_LANG_SPECIFIC (node))
54 return;
55 if (TREE_CODE (node) == FUNCTION_DECL)
57 int flags = TFF_DECL_SPECIFIERS|TFF_RETURN_TYPE
58 |TFF_FUNCTION_DEFAULT_ARGUMENTS|TFF_EXCEPTION_SPECIFICATION ;
59 indent_to (file, indent + 3);
60 fprintf (file, " full-name \"%s\"", decl_as_string (node, flags));
62 else if (TREE_CODE (node) == TEMPLATE_DECL)
64 indent_to (file, indent + 3);
65 fprintf (file, " full-name \"%s\"",
66 decl_as_string (node, TFF_TEMPLATE_HEADER));
69 indent_to (file, indent + 3);
70 if (DECL_EXTERNAL (node) && DECL_NOT_REALLY_EXTERN (node))
71 fprintf (file, " not-really-extern");
72 if (TREE_CODE (node) == FUNCTION_DECL
73 && DECL_PENDING_INLINE_INFO (node))
74 fprintf (file, " pending-inline-info %p",
75 (void *) DECL_PENDING_INLINE_INFO (node));
76 if (VAR_OR_FUNCTION_DECL_P (node)
77 && DECL_TEMPLATE_INFO (node))
78 fprintf (file, " template-info %p",
79 (void *) DECL_TEMPLATE_INFO (node));
82 void
83 cxx_print_type (FILE *file, tree node, int indent)
85 switch (TREE_CODE (node))
87 case TEMPLATE_TYPE_PARM:
88 case TEMPLATE_TEMPLATE_PARM:
89 case BOUND_TEMPLATE_TEMPLATE_PARM:
90 indent_to (file, indent + 3);
91 fprintf (file, "index %d level %d orig_level %d",
92 TEMPLATE_TYPE_IDX (node), TEMPLATE_TYPE_LEVEL (node),
93 TEMPLATE_TYPE_ORIG_LEVEL (node));
94 return;
96 case FUNCTION_TYPE:
97 case METHOD_TYPE:
98 if (TYPE_RAISES_EXCEPTIONS (node))
99 print_node (file, "throws", TYPE_RAISES_EXCEPTIONS (node), indent + 4);
100 return;
102 case RECORD_TYPE:
103 case UNION_TYPE:
104 break;
106 case DECLTYPE_TYPE:
107 print_node (file, "expr", DECLTYPE_TYPE_EXPR (node), indent + 4);
108 return;
110 case TYPENAME_TYPE:
111 print_node (file, "fullname", TYPENAME_TYPE_FULLNAME (node),
112 indent + 4);
113 return;
115 case TYPE_PACK_EXPANSION:
116 print_node (file, "args", PACK_EXPANSION_EXTRA_ARGS (node), indent + 4);
117 return;
119 default:
120 return;
123 if (TYPE_PTRMEMFUNC_P (node))
124 print_node (file, "ptrmemfunc fn type", TYPE_PTRMEMFUNC_FN_TYPE (node),
125 indent + 4);
127 if (! CLASS_TYPE_P (node))
128 return;
130 indent_to (file, indent + 4);
131 fprintf (file, "full-name \"%s\"",
132 type_as_string (node, TFF_CLASS_KEY_OR_ENUM));
134 indent_to (file, indent + 3);
136 if (TYPE_NEEDS_CONSTRUCTING (node))
137 fputs ( " needs-constructor", file);
138 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (node))
139 fputs (" needs-destructor", file);
140 if (TYPE_HAS_DEFAULT_CONSTRUCTOR (node))
141 fputs (" X()", file);
142 if (TYPE_HAS_CONVERSION (node))
143 fputs (" has-type-conversion", file);
144 if (TYPE_HAS_COPY_CTOR (node))
146 if (TYPE_HAS_CONST_COPY_CTOR (node))
147 fputs (" X(constX&)", file);
148 else
149 fputs (" X(X&)", file);
151 if (TYPE_HAS_NEW_OPERATOR (node))
152 fputs (" new", file);
153 if (TYPE_HAS_ARRAY_NEW_OPERATOR (node))
154 fputs (" new[]", file);
155 if (TYPE_GETS_DELETE (node) & 1)
156 fputs (" delete", file);
157 if (TYPE_GETS_DELETE (node) & 2)
158 fputs (" delete[]", file);
159 if (TYPE_HAS_COPY_ASSIGN (node))
160 fputs (" this=(X&)", file);
161 if (CLASSTYPE_SORTED_FIELDS (node))
162 fprintf (file, " sorted-fields %p",
163 (void *) CLASSTYPE_SORTED_FIELDS (node));
165 if (TREE_CODE (node) == RECORD_TYPE)
167 if (TYPE_BINFO (node))
168 fprintf (file, " n_parents=%d",
169 BINFO_N_BASE_BINFOS (TYPE_BINFO (node)));
170 else
171 fprintf (file, " no-binfo");
173 fprintf (file, " use_template=%d", CLASSTYPE_USE_TEMPLATE (node));
174 if (CLASSTYPE_INTERFACE_ONLY (node))
175 fprintf (file, " interface-only");
176 if (CLASSTYPE_INTERFACE_UNKNOWN (node))
177 fprintf (file, " interface-unknown");
182 static void
183 cxx_print_binding (FILE *stream, cxx_binding *binding, const char *prefix)
185 fprintf (stream, "%s <%p>",
186 prefix, (void *) binding);
189 void
190 cxx_print_identifier (FILE *file, tree node, int indent)
192 if (indent == 0)
193 fprintf (file, " ");
194 else
195 indent_to (file, indent + 4);
196 cxx_print_binding (file, IDENTIFIER_NAMESPACE_BINDINGS (node), "bindings");
197 if (indent == 0)
198 fprintf (file, " ");
199 else
200 indent_to (file, indent + 4);
201 cxx_print_binding (file, IDENTIFIER_BINDING (node), "local bindings");
202 print_node (file, "label", IDENTIFIER_LABEL_VALUE (node), indent + 4);
203 print_node (file, "template", IDENTIFIER_TEMPLATE (node), indent + 4);
206 void
207 cxx_print_lambda_node (FILE *file, tree node, int indent)
209 if (LAMBDA_EXPR_MUTABLE_P (node))
210 fprintf (file, " /mutable");
211 fprintf (file, " default_capture_mode=[");
212 switch (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (node))
214 case CPLD_NONE:
215 fprintf (file, "NONE");
216 break;
217 case CPLD_COPY:
218 fprintf (file, "COPY");
219 break;
220 case CPLD_REFERENCE:
221 fprintf (file, "CPLD_REFERENCE");
222 break;
223 default:
224 fprintf (file, "??");
225 break;
227 fprintf (file, "] ");
228 print_node (file, "capture_list", LAMBDA_EXPR_CAPTURE_LIST (node), indent + 4);
229 print_node (file, "this_capture", LAMBDA_EXPR_THIS_CAPTURE (node), indent + 4);
230 print_node (file, "return_type", LAMBDA_EXPR_RETURN_TYPE (node), indent + 4);
231 print_node (file, "closure", LAMBDA_EXPR_CLOSURE (node), indent + 4);
234 void
235 cxx_print_xnode (FILE *file, tree node, int indent)
237 switch (TREE_CODE (node))
239 case BASELINK:
240 print_node (file, "functions", BASELINK_FUNCTIONS (node), indent + 4);
241 print_node (file, "binfo", BASELINK_BINFO (node), indent + 4);
242 print_node (file, "access_binfo", BASELINK_ACCESS_BINFO (node),
243 indent + 4);
244 break;
245 case OVERLOAD:
246 print_node (file, "function", OVL_FUNCTION (node), indent+4);
247 print_node (file, "chain", TREE_CHAIN (node), indent+4);
248 break;
249 case TEMPLATE_PARM_INDEX:
250 indent_to (file, indent + 3);
251 fprintf (file, "index %d level %d orig_level %d",
252 TEMPLATE_PARM_IDX (node), TEMPLATE_PARM_LEVEL (node),
253 TEMPLATE_PARM_ORIG_LEVEL (node));
254 break;
255 case TEMPLATE_INFO:
256 print_node (file, "template", TI_TEMPLATE (node), indent+4);
257 print_node (file, "args", TI_ARGS (node), indent+4);
258 if (TI_PENDING_TEMPLATE_FLAG (node))
260 indent_to (file, indent + 3);
261 fprintf (file, "pending_template");
263 break;
264 case ARGUMENT_PACK_SELECT:
265 print_node (file, "pack", ARGUMENT_PACK_SELECT_FROM_PACK (node),
266 indent+4);
267 indent_to (file, indent + 3);
268 fprintf (file, "index %d", ARGUMENT_PACK_SELECT_INDEX (node));
269 break;
270 case DEFERRED_NOEXCEPT:
271 print_node (file, "pattern", DEFERRED_NOEXCEPT_PATTERN (node), indent+4);
272 print_node (file, "args", DEFERRED_NOEXCEPT_ARGS (node), indent+4);
273 break;
274 case LAMBDA_EXPR:
275 cxx_print_lambda_node (file, node, indent);
276 break;
277 default:
278 break;