1 /* Prints out trees in human readable form.
2 Copyright (C) 1992-2025 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)
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/>. */
24 #include "coretypes.h"
26 #include "print-tree.h"
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 ");
41 if (TREE_CODE (node
) == FUNCTION_DECL
)
43 int flags
= TFF_DECL_SPECIFIERS
|TFF_RETURN_TYPE
44 |TFF_FUNCTION_DEFAULT_ARGUMENTS
|TFF_EXCEPTION_SPECIFICATION
;
45 indent_to (file
, indent
+ 3);
46 fprintf (file
, " full-name \"%s\"", decl_as_string (node
, flags
));
48 else if (TREE_CODE (node
) == TEMPLATE_DECL
)
50 print_node (file
, "result", DECL_TEMPLATE_RESULT (node
), indent
+ 4);
51 print_node (file
, "parms", DECL_TEMPLATE_PARMS (node
), indent
+ 4);
52 indent_to (file
, indent
+ 3);
53 fprintf (file
, " full-name \"%s\"",
54 decl_as_string (node
, TFF_TEMPLATE_HEADER
));
57 bool need_indent
= true;
59 tree ntnode
= STRIP_TEMPLATE (node
);
60 if (TREE_CODE (ntnode
) == FUNCTION_DECL
61 || TREE_CODE (ntnode
) == VAR_DECL
62 || TREE_CODE (ntnode
) == TYPE_DECL
63 || TREE_CODE (ntnode
) == CONCEPT_DECL
64 || TREE_CODE (ntnode
) == NAMESPACE_DECL
)
67 if (DECL_LANG_SPECIFIC (ntnode
) && DECL_MODULE_IMPORT_P (ntnode
))
68 m
= get_importing_module (ntnode
, true);
70 if (const char *name
= m
== ~0u ? "" : module_name (m
, true))
73 indent_to (file
, indent
+ 3);
74 fprintf (file
, " module %d:%s", m
, name
);
78 if (DECL_LANG_SPECIFIC (ntnode
))
80 if (DECL_MODULE_PURVIEW_P (ntnode
))
83 indent_to (file
, indent
+ 3);
84 fprintf (file
, " purview");
87 if (DECL_MODULE_ATTACH_P (ntnode
))
90 indent_to (file
, indent
+ 3);
91 fprintf (file
, " attached");
97 if (DECL_MODULE_EXPORT_P (node
))
100 indent_to (file
, indent
+ 3);
101 fprintf (file
, " exported");
105 if (!CODE_CONTAINS_STRUCT (TREE_CODE (node
), TS_DECL_COMMON
)
106 || !DECL_LANG_SPECIFIC (node
))
109 if (DECL_EXTERNAL (node
) && DECL_NOT_REALLY_EXTERN (node
))
112 indent_to (file
, indent
+ 3);
113 fprintf (file
, " not-really-extern");
117 if (TREE_CODE (node
) == FUNCTION_DECL
118 && DECL_PENDING_INLINE_INFO (node
))
121 indent_to (file
, indent
+ 3);
122 fprintf (file
, " pending-inline-info %p",
123 (void *) DECL_PENDING_INLINE_INFO (node
));
127 if ((VAR_OR_FUNCTION_DECL_P (node
)
128 || TREE_CODE (node
) == FIELD_DECL
129 || TREE_CODE (node
) == TYPE_DECL
130 || TREE_CODE (node
) == CONCEPT_DECL
131 || TREE_CODE (node
) == TEMPLATE_DECL
)
132 && DECL_TEMPLATE_INFO (node
))
134 print_node (file
, "template-info", DECL_TEMPLATE_INFO (node
),
136 indent_to (file
, indent
+ 3);
137 fprintf (file
, " use_template=%d", DECL_USE_TEMPLATE (node
));
142 cxx_print_type (FILE *file
, tree node
, int indent
)
144 if (tree ti
= TYPE_TEMPLATE_INFO (node
))
145 print_node (file
, "template-info", ti
, indent
+ 4);
147 switch (TREE_CODE (node
))
149 case BOUND_TEMPLATE_TEMPLATE_PARM
:
150 case TEMPLATE_TYPE_PARM
:
151 case TEMPLATE_TEMPLATE_PARM
:
152 print_node (file
, "tpi", TEMPLATE_TYPE_PARM_INDEX (node
), indent
+ 4);
157 if (TYPE_RAISES_EXCEPTIONS (node
))
158 print_node (file
, "throws", TYPE_RAISES_EXCEPTIONS (node
), indent
+ 4);
166 print_node (file
, "expr", DECLTYPE_TYPE_EXPR (node
), indent
+ 4);
169 case DEPENDENT_OPERATOR_TYPE
:
170 print_node (file
, "saved_lookups",
171 DEPENDENT_OPERATOR_TYPE_SAVED_LOOKUPS (node
),
176 print_node (file
, "fullname", TYPENAME_TYPE_FULLNAME (node
),
181 print_node (file
, "expr", TYPEOF_TYPE_EXPR (node
), indent
+ 4);
185 if (BASES_DIRECT (node
))
186 fputs (" direct", file
);
187 print_node (file
, "type", BASES_TYPE (node
), indent
+ 4);
190 case TYPE_PACK_EXPANSION
:
191 print_node (file
, "pattern", PACK_EXPANSION_PATTERN (node
), indent
+ 4);
192 print_node (file
, "args", PACK_EXPANSION_EXTRA_ARGS (node
), indent
+ 4);
195 case PACK_INDEX_TYPE
:
196 print_node (file
, "pack", PACK_INDEX_PACK (node
), indent
+ 4);
197 print_node (file
, "index", PACK_INDEX_INDEX (node
), indent
+ 4);
204 if (TYPE_PTRMEMFUNC_P (node
))
205 print_node (file
, "ptrmemfunc fn type", TYPE_PTRMEMFUNC_FN_TYPE (node
),
208 if (! CLASS_TYPE_P (node
))
211 indent_to (file
, indent
+ 4);
212 fprintf (file
, "full-name \"%s\"",
213 type_as_string (node
, TFF_CLASS_KEY_OR_ENUM
));
215 indent_to (file
, indent
+ 3);
217 if (TYPE_NEEDS_CONSTRUCTING (node
))
218 fputs ( " needs-constructor", file
);
219 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (node
))
220 fputs (" needs-destructor", file
);
221 if (TYPE_HAS_DEFAULT_CONSTRUCTOR (node
))
222 fputs (" X()", file
);
223 if (TYPE_HAS_CONVERSION (node
))
224 fputs (" has-type-conversion", file
);
225 if (TYPE_HAS_COPY_CTOR (node
))
227 if (TYPE_HAS_CONST_COPY_CTOR (node
))
228 fputs (" X(constX&)", file
);
230 fputs (" X(X&)", file
);
232 if (TYPE_HAS_NEW_OPERATOR (node
))
233 fputs (" new", file
);
234 if (TYPE_HAS_ARRAY_NEW_OPERATOR (node
))
235 fputs (" new[]", file
);
236 if (TYPE_GETS_DELETE (node
) & 1)
237 fputs (" delete", file
);
238 if (TYPE_GETS_DELETE (node
) & 2)
239 fputs (" delete[]", file
);
240 if (TYPE_HAS_COPY_ASSIGN (node
))
241 fputs (" this=(X&)", file
);
243 if (TREE_CODE (node
) == RECORD_TYPE
)
245 if (TYPE_BINFO (node
))
246 fprintf (file
, " n_parents=%d",
247 BINFO_N_BASE_BINFOS (TYPE_BINFO (node
)));
249 fprintf (file
, " no-binfo");
251 fprintf (file
, " use_template=%d", CLASSTYPE_USE_TEMPLATE (node
));
252 if (CLASSTYPE_INTERFACE_ONLY (node
))
253 fprintf (file
, " interface-only");
254 if (CLASSTYPE_INTERFACE_UNKNOWN (node
))
255 fprintf (file
, " interface-unknown");
260 cxx_print_identifier (FILE *file
, tree node
, int indent
)
265 indent_to (file
, indent
+ 4);
266 fprintf (file
, "%s local bindings <%p>", get_identifier_kind_name (node
),
267 (void *) IDENTIFIER_BINDING (node
));
271 cxx_print_lambda_node (FILE *file
, tree node
, int indent
)
273 fprintf (file
, " default_capture_mode=[");
274 switch (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (node
))
277 fprintf (file
, "NONE");
280 fprintf (file
, "COPY");
283 fprintf (file
, "CPLD_REFERENCE");
286 fprintf (file
, "??");
289 fprintf (file
, "] ");
290 print_node (file
, "capture_list", LAMBDA_EXPR_CAPTURE_LIST (node
), indent
+ 4);
291 print_node (file
, "this_capture", LAMBDA_EXPR_THIS_CAPTURE (node
), indent
+ 4);
295 cxx_print_xnode (FILE *file
, tree node
, int indent
)
297 switch (TREE_CODE (node
))
300 print_node (file
, "functions", BASELINK_FUNCTIONS (node
), indent
+ 4);
301 print_node (file
, "binfo", BASELINK_BINFO (node
), indent
+ 4);
302 print_node (file
, "access_binfo", BASELINK_ACCESS_BINFO (node
),
304 print_node (file
, "optype", BASELINK_OPTYPE (node
), indent
+ 4);
307 print_node (file
, "function", OVL_FUNCTION (node
), indent
+ 4);
308 print_node (file
, "next", OVL_CHAIN (node
), indent
+ 4);
312 unsigned len
= BINDING_VECTOR_NUM_CLUSTERS (node
);
313 print_node (file
, "name", BINDING_VECTOR_NAME (node
), indent
+ 4);
314 fprintf (file
, " clusters %u, alloc %u", len
,
315 BINDING_VECTOR_ALLOC_CLUSTERS (node
));
316 for (unsigned ix
= 0; ix
!= len
; ix
++)
318 binding_cluster
*cluster
= &BINDING_VECTOR_CLUSTER (node
, ix
);
320 for (unsigned jx
= 0; jx
!= BINDING_VECTOR_SLOTS_PER_CLUSTER
; jx
++)
321 if (cluster
->indices
[jx
].span
)
323 int len
= sprintf (pfx
, "module:%u",
324 cluster
->indices
[jx
].base
);
325 if (cluster
->indices
[jx
].span
> 1)
326 len
+= sprintf (&pfx
[len
], "(+%u)",
327 cluster
->indices
[jx
].span
);
328 len
+= sprintf (&pfx
[len
], " cluster:%u/%u", ix
, jx
);
329 binding_slot
&slot
= cluster
->slots
[jx
];
332 indent_to (file
, indent
+ 4);
333 unsigned lazy
= slot
.get_lazy ();
334 fprintf (file
, "%s snum:%u", pfx
, lazy
);
337 print_node (file
, pfx
, slot
, indent
+ 4);
340 indent_to (file
, indent
+ 4);
341 fprintf (file
, "%s NULL", pfx
);
347 case TEMPLATE_PARM_INDEX
:
348 print_node (file
, "decl", TEMPLATE_PARM_DECL (node
), indent
+4);
349 indent_to (file
, indent
+ 3);
350 fprintf (file
, "index %d level %d orig_level %d",
351 TEMPLATE_PARM_IDX (node
), TEMPLATE_PARM_LEVEL (node
),
352 TEMPLATE_PARM_ORIG_LEVEL (node
));
355 print_node (file
, "template", TI_TEMPLATE (node
), indent
+4);
356 print_node (file
, "args", TI_ARGS (node
), indent
+4);
357 if (TI_TEMPLATE (node
)
358 && PRIMARY_TEMPLATE_P (TI_TEMPLATE (node
)))
359 print_node (file
, "partial", TI_PARTIAL_INFO (node
), indent
+4);
360 if (TI_PENDING_TEMPLATE_FLAG (node
))
362 indent_to (file
, indent
+ 3);
363 fprintf (file
, "pending_template");
366 case CONSTRAINT_INFO
:
368 tree_constraint_info
*cinfo
= (tree_constraint_info
*)node
;
369 if (cinfo
->template_reqs
)
370 print_node (file
, "template_reqs", cinfo
->template_reqs
, indent
+4);
371 if (cinfo
->declarator_reqs
)
372 print_node (file
, "declarator_reqs", cinfo
->declarator_reqs
,
374 print_node (file
, "associated_constr",
375 cinfo
->associated_constr
, indent
+4);
378 case ARGUMENT_PACK_SELECT
:
379 print_node (file
, "pack", ARGUMENT_PACK_SELECT_FROM_PACK (node
),
381 indent_to (file
, indent
+ 3);
382 fprintf (file
, "index %d", ARGUMENT_PACK_SELECT_INDEX (node
));
384 case DEFERRED_NOEXCEPT
:
385 print_node (file
, "pattern", DEFERRED_NOEXCEPT_PATTERN (node
), indent
+4);
386 print_node (file
, "args", DEFERRED_NOEXCEPT_ARGS (node
), indent
+4);
389 indent_to (file
, indent
+4);
390 fprintf (file
, "kind %d", TRAIT_EXPR_KIND (node
));
391 print_node (file
, "type 1", TRAIT_EXPR_TYPE1 (node
), indent
+4);
392 if (TRAIT_EXPR_TYPE2 (node
))
393 print_node (file
, "type 2", TRAIT_EXPR_TYPE2 (node
), indent
+4);
396 cxx_print_lambda_node (file
, node
, indent
);
399 if (location_t loc
= STATIC_ASSERT_SOURCE_LOCATION (node
))
401 expanded_location xloc
= expand_location (loc
);
402 indent_to (file
, indent
+4);
403 fprintf (file
, "%s:%d:%d", xloc
.file
, xloc
.line
, xloc
.column
);
405 print_node (file
, "condition", STATIC_ASSERT_CONDITION (node
), indent
+4);
406 if (tree message
= STATIC_ASSERT_MESSAGE (node
))
407 print_node (file
, "message", message
, indent
+4);
410 print_node (file
, "member", PTRMEM_CST_MEMBER (node
), indent
+4);
417 /* Print the node NODE on standard error, for debugging. */
420 debug_tree (cp_expr node
)
422 debug_tree (node
.get_value());
426 debug_overload (tree node
)
430 for (lkp_iterator
iter (node
); iter
; ++iter
)
433 auto xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
434 auto fullname
= decl_as_string (decl
, 0);
435 bool using_p
= iter
.using_p ();
436 bool hidden_p
= iter
.hidden_p ();
438 fprintf (file
, "%p:%c%c %s:%d:%d \"%s\"\n", (void *)decl
,
439 hidden_p
? 'H' : '-',
441 xloc
.file
, xloc
.line
, xloc
.column
, fullname
);