Require target lra in gcc.c-torture/compile/asmgoto-6.c
[official-gcc.git] / gcc / cp / ptree.cc
blob33af7b81f5875410dbfe399de3b7d8d69fd52b39
1 /* Prints out trees in human readable form.
2 Copyright (C) 1992-2023 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 "cp-tree.h"
26 #include "print-tree.h"
28 void
29 cxx_print_decl (FILE *file, tree node, int indent)
31 if (TREE_CODE (node) == FIELD_DECL)
33 if (DECL_MUTABLE_P (node))
35 indent_to (file, indent + 3);
36 fprintf (file, " mutable ");
38 return;
41 if (!CODE_CONTAINS_STRUCT (TREE_CODE (node), TS_DECL_COMMON)
42 || !DECL_LANG_SPECIFIC (node))
43 return;
45 if (TREE_CODE (node) == FUNCTION_DECL)
47 int flags = TFF_DECL_SPECIFIERS|TFF_RETURN_TYPE
48 |TFF_FUNCTION_DEFAULT_ARGUMENTS|TFF_EXCEPTION_SPECIFICATION ;
49 indent_to (file, indent + 3);
50 fprintf (file, " full-name \"%s\"", decl_as_string (node, flags));
52 else if (TREE_CODE (node) == TEMPLATE_DECL)
54 print_node (file, "result", DECL_TEMPLATE_RESULT (node), indent + 4);
55 print_node (file, "parms", DECL_TEMPLATE_PARMS (node), indent + 4);
56 indent_to (file, indent + 3);
57 fprintf (file, " full-name \"%s\"",
58 decl_as_string (node, TFF_TEMPLATE_HEADER));
61 bool need_indent = true;
63 tree ntnode = STRIP_TEMPLATE (node);
64 if (TREE_CODE (ntnode) == FUNCTION_DECL
65 || TREE_CODE (ntnode) == VAR_DECL
66 || TREE_CODE (ntnode) == TYPE_DECL
67 || TREE_CODE (ntnode) == CONCEPT_DECL
68 || TREE_CODE (ntnode) == NAMESPACE_DECL)
70 unsigned m = 0;
71 if (DECL_LANG_SPECIFIC (ntnode) && DECL_MODULE_IMPORT_P (ntnode))
72 m = get_importing_module (ntnode, true);
74 if (const char *name = m == ~0u ? "" : module_name (m, true))
76 if (need_indent)
77 indent_to (file, indent + 3);
78 fprintf (file, " module %d:%s", m, name);
79 need_indent = false;
82 if (DECL_LANG_SPECIFIC (ntnode))
84 if (DECL_MODULE_PURVIEW_P (ntnode))
86 if (need_indent)
87 indent_to (file, indent + 3);
88 fprintf (file, " purview");
89 need_indent = false;
91 if (DECL_MODULE_ATTACH_P (ntnode))
93 if (need_indent)
94 indent_to (file, indent + 3);
95 fprintf (file, " attached");
96 need_indent = false;
101 if (DECL_MODULE_EXPORT_P (node))
103 if (need_indent)
104 indent_to (file, indent + 3);
105 fprintf (file, " exported");
106 need_indent = false;
109 if (DECL_EXTERNAL (node) && DECL_NOT_REALLY_EXTERN (node))
111 if (need_indent)
112 indent_to (file, indent + 3);
113 fprintf (file, " not-really-extern");
114 need_indent = false;
117 if (TREE_CODE (node) == FUNCTION_DECL
118 && DECL_PENDING_INLINE_INFO (node))
120 if (need_indent)
121 indent_to (file, indent + 3);
122 fprintf (file, " pending-inline-info %p",
123 (void *) DECL_PENDING_INLINE_INFO (node));
124 need_indent = false;
127 if (VAR_OR_FUNCTION_DECL_P (node)
128 && DECL_TEMPLATE_INFO (node))
129 print_node (file, "template-info", DECL_TEMPLATE_INFO (node),
130 indent + 4);
133 void
134 cxx_print_type (FILE *file, tree node, int indent)
136 switch (TREE_CODE (node))
138 case BOUND_TEMPLATE_TEMPLATE_PARM:
139 print_node (file, "args", TYPE_TI_ARGS (node), indent + 4);
140 gcc_fallthrough ();
142 case TEMPLATE_TYPE_PARM:
143 case TEMPLATE_TEMPLATE_PARM:
144 indent_to (file, indent + 3);
145 fprintf (file, "index %d level %d orig_level %d",
146 TEMPLATE_TYPE_IDX (node), TEMPLATE_TYPE_LEVEL (node),
147 TEMPLATE_TYPE_ORIG_LEVEL (node));
148 return;
150 case FUNCTION_TYPE:
151 case METHOD_TYPE:
152 if (TYPE_RAISES_EXCEPTIONS (node))
153 print_node (file, "throws", TYPE_RAISES_EXCEPTIONS (node), indent + 4);
154 return;
156 case RECORD_TYPE:
157 case UNION_TYPE:
158 break;
160 case DECLTYPE_TYPE:
161 print_node (file, "expr", DECLTYPE_TYPE_EXPR (node), indent + 4);
162 return;
164 case DEPENDENT_OPERATOR_TYPE:
165 print_node (file, "saved_lookups",
166 DEPENDENT_OPERATOR_TYPE_SAVED_LOOKUPS (node),
167 indent + 4);
168 return;
170 case TYPENAME_TYPE:
171 print_node (file, "fullname", TYPENAME_TYPE_FULLNAME (node),
172 indent + 4);
173 return;
175 case TYPEOF_TYPE:
176 print_node (file, "expr", TYPEOF_TYPE_EXPR (node), indent + 4);
177 return;
179 case BASES:
180 if (BASES_DIRECT (node))
181 fputs (" direct", file);
182 print_node (file, "type", BASES_TYPE (node), indent + 4);
183 return;
185 case TYPE_PACK_EXPANSION:
186 print_node (file, "pattern", PACK_EXPANSION_PATTERN (node), indent + 4);
187 print_node (file, "args", PACK_EXPANSION_EXTRA_ARGS (node), indent + 4);
188 return;
190 default:
191 return;
194 if (TYPE_PTRMEMFUNC_P (node))
195 print_node (file, "ptrmemfunc fn type", TYPE_PTRMEMFUNC_FN_TYPE (node),
196 indent + 4);
198 if (! CLASS_TYPE_P (node))
199 return;
201 indent_to (file, indent + 4);
202 fprintf (file, "full-name \"%s\"",
203 type_as_string (node, TFF_CLASS_KEY_OR_ENUM));
205 indent_to (file, indent + 3);
207 if (TYPE_NEEDS_CONSTRUCTING (node))
208 fputs ( " needs-constructor", file);
209 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (node))
210 fputs (" needs-destructor", file);
211 if (TYPE_HAS_DEFAULT_CONSTRUCTOR (node))
212 fputs (" X()", file);
213 if (TYPE_HAS_CONVERSION (node))
214 fputs (" has-type-conversion", file);
215 if (TYPE_HAS_COPY_CTOR (node))
217 if (TYPE_HAS_CONST_COPY_CTOR (node))
218 fputs (" X(constX&)", file);
219 else
220 fputs (" X(X&)", file);
222 if (TYPE_HAS_NEW_OPERATOR (node))
223 fputs (" new", file);
224 if (TYPE_HAS_ARRAY_NEW_OPERATOR (node))
225 fputs (" new[]", file);
226 if (TYPE_GETS_DELETE (node) & 1)
227 fputs (" delete", file);
228 if (TYPE_GETS_DELETE (node) & 2)
229 fputs (" delete[]", file);
230 if (TYPE_HAS_COPY_ASSIGN (node))
231 fputs (" this=(X&)", file);
233 if (TREE_CODE (node) == RECORD_TYPE)
235 if (TYPE_BINFO (node))
236 fprintf (file, " n_parents=%d",
237 BINFO_N_BASE_BINFOS (TYPE_BINFO (node)));
238 else
239 fprintf (file, " no-binfo");
241 fprintf (file, " use_template=%d", CLASSTYPE_USE_TEMPLATE (node));
242 if (CLASSTYPE_INTERFACE_ONLY (node))
243 fprintf (file, " interface-only");
244 if (CLASSTYPE_INTERFACE_UNKNOWN (node))
245 fprintf (file, " interface-unknown");
249 void
250 cxx_print_identifier (FILE *file, tree node, int indent)
252 if (indent == 0)
253 fprintf (file, " ");
254 else
255 indent_to (file, indent + 4);
256 fprintf (file, "%s local bindings <%p>", get_identifier_kind_name (node),
257 (void *) IDENTIFIER_BINDING (node));
260 void
261 cxx_print_lambda_node (FILE *file, tree node, int indent)
263 if (LAMBDA_EXPR_MUTABLE_P (node))
264 fprintf (file, " /mutable");
265 fprintf (file, " default_capture_mode=[");
266 switch (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (node))
268 case CPLD_NONE:
269 fprintf (file, "NONE");
270 break;
271 case CPLD_COPY:
272 fprintf (file, "COPY");
273 break;
274 case CPLD_REFERENCE:
275 fprintf (file, "CPLD_REFERENCE");
276 break;
277 default:
278 fprintf (file, "??");
279 break;
281 fprintf (file, "] ");
282 print_node (file, "capture_list", LAMBDA_EXPR_CAPTURE_LIST (node), indent + 4);
283 print_node (file, "this_capture", LAMBDA_EXPR_THIS_CAPTURE (node), indent + 4);
286 void
287 cxx_print_xnode (FILE *file, tree node, int indent)
289 switch (TREE_CODE (node))
291 case BASELINK:
292 print_node (file, "functions", BASELINK_FUNCTIONS (node), indent + 4);
293 print_node (file, "binfo", BASELINK_BINFO (node), indent + 4);
294 print_node (file, "access_binfo", BASELINK_ACCESS_BINFO (node),
295 indent + 4);
296 print_node (file, "optype", BASELINK_OPTYPE (node), indent + 4);
297 break;
298 case OVERLOAD:
299 print_node (file, "function", OVL_FUNCTION (node), indent + 4);
300 print_node (file, "next", OVL_CHAIN (node), indent + 4);
301 break;
302 case BINDING_VECTOR:
304 unsigned len = BINDING_VECTOR_NUM_CLUSTERS (node);
305 print_node (file, "name", BINDING_VECTOR_NAME (node), indent + 4);
306 fprintf (file, " clusters %u, alloc %u", len,
307 BINDING_VECTOR_ALLOC_CLUSTERS (node));
308 for (unsigned ix = 0; ix != len; ix++)
310 binding_cluster *cluster = &BINDING_VECTOR_CLUSTER (node, ix);
311 char pfx[32];
312 for (unsigned jx = 0; jx != BINDING_VECTOR_SLOTS_PER_CLUSTER; jx++)
313 if (cluster->indices[jx].span)
315 int len = sprintf (pfx, "module:%u",
316 cluster->indices[jx].base);
317 if (cluster->indices[jx].span > 1)
318 len += sprintf (&pfx[len], "(+%u)",
319 cluster->indices[jx].span);
320 len += sprintf (&pfx[len], " cluster:%u/%u", ix, jx);
321 binding_slot &slot = cluster->slots[jx];
322 if (slot.is_lazy ())
324 indent_to (file, indent + 4);
325 unsigned lazy = slot.get_lazy ();
326 fprintf (file, "%s snum:%u", pfx, lazy);
328 else if (slot)
329 print_node (file, pfx, slot, indent + 4);
330 else
332 indent_to (file, indent + 4);
333 fprintf (file, "%s NULL", pfx);
338 break;
339 case TEMPLATE_PARM_INDEX:
340 print_node (file, "decl", TEMPLATE_PARM_DECL (node), indent+4);
341 indent_to (file, indent + 3);
342 fprintf (file, "index %d level %d orig_level %d",
343 TEMPLATE_PARM_IDX (node), TEMPLATE_PARM_LEVEL (node),
344 TEMPLATE_PARM_ORIG_LEVEL (node));
345 break;
346 case TEMPLATE_INFO:
347 print_node (file, "template", TI_TEMPLATE (node), indent+4);
348 print_node (file, "args", TI_ARGS (node), indent+4);
349 if (TI_TEMPLATE (node)
350 && PRIMARY_TEMPLATE_P (TI_TEMPLATE (node)))
351 print_node (file, "partial", TI_PARTIAL_INFO (node), indent+4);
352 if (TI_PENDING_TEMPLATE_FLAG (node))
354 indent_to (file, indent + 3);
355 fprintf (file, "pending_template");
357 break;
358 case CONSTRAINT_INFO:
360 tree_constraint_info *cinfo = (tree_constraint_info *)node;
361 if (cinfo->template_reqs)
362 print_node (file, "template_reqs", cinfo->template_reqs, indent+4);
363 if (cinfo->declarator_reqs)
364 print_node (file, "declarator_reqs", cinfo->declarator_reqs,
365 indent+4);
366 print_node (file, "associated_constr",
367 cinfo->associated_constr, indent+4);
368 break;
370 case ARGUMENT_PACK_SELECT:
371 print_node (file, "pack", ARGUMENT_PACK_SELECT_FROM_PACK (node),
372 indent+4);
373 indent_to (file, indent + 3);
374 fprintf (file, "index %d", ARGUMENT_PACK_SELECT_INDEX (node));
375 break;
376 case DEFERRED_NOEXCEPT:
377 print_node (file, "pattern", DEFERRED_NOEXCEPT_PATTERN (node), indent+4);
378 print_node (file, "args", DEFERRED_NOEXCEPT_ARGS (node), indent+4);
379 break;
380 case TRAIT_EXPR:
381 indent_to (file, indent+4);
382 fprintf (file, "kind %d", TRAIT_EXPR_KIND (node));
383 print_node (file, "type 1", TRAIT_EXPR_TYPE1 (node), indent+4);
384 if (TRAIT_EXPR_TYPE2 (node))
385 print_node (file, "type 2", TRAIT_EXPR_TYPE2 (node), indent+4);
386 break;
387 case LAMBDA_EXPR:
388 cxx_print_lambda_node (file, node, indent);
389 break;
390 case STATIC_ASSERT:
391 if (location_t loc = STATIC_ASSERT_SOURCE_LOCATION (node))
393 expanded_location xloc = expand_location (loc);
394 indent_to (file, indent+4);
395 fprintf (file, "%s:%d:%d", xloc.file, xloc.line, xloc.column);
397 print_node (file, "condition", STATIC_ASSERT_CONDITION (node), indent+4);
398 if (tree message = STATIC_ASSERT_MESSAGE (node))
399 print_node (file, "message", message, indent+4);
400 break;
401 case PTRMEM_CST:
402 print_node (file, "member", PTRMEM_CST_MEMBER (node), indent+4);
403 break;
404 default:
405 break;
409 /* Print the node NODE on standard error, for debugging. */
411 DEBUG_FUNCTION void
412 debug_tree (cp_expr node)
414 debug_tree (node.get_value());
417 DEBUG_FUNCTION void
418 debug_overload (tree node)
420 FILE *file = stdout;
422 for (lkp_iterator iter (node); iter; ++iter)
424 tree decl = *iter;
425 auto xloc = expand_location (DECL_SOURCE_LOCATION (decl));
426 auto fullname = decl_as_string (decl, 0);
427 bool using_p = iter.using_p ();
428 bool hidden_p = iter.hidden_p ();
430 fprintf (file, "%p:%c%c %s:%d:%d \"%s\"\n", (void *)decl,
431 hidden_p ? 'H' : '-',
432 using_p ? 'U' : '-',
433 xloc.file, xloc.line, xloc.column, fullname);