]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/cp/ptree.c
Correct a function pre/postcondition [PR102403].
[thirdparty/gcc.git] / gcc / cp / ptree.c
CommitLineData
8d08fdba 1/* Prints out trees in human readable form.
99dee823 2 Copyright (C) 1992-2021 Free Software Foundation, Inc.
8d08fdba
MS
3 Hacked by Michael Tiemann (tiemann@cygnus.com)
4
f5adbb8d 5This file is part of GCC.
8d08fdba 6
f5adbb8d 7GCC is free software; you can redistribute it and/or modify
8d08fdba 8it under the terms of the GNU General Public License as published by
e77f031d 9the Free Software Foundation; either version 3, or (at your option)
8d08fdba
MS
10any later version.
11
f5adbb8d 12GCC is distributed in the hope that it will be useful,
8d08fdba
MS
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
e77f031d
NC
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
8d08fdba
MS
20
21
22#include "config.h"
8d052bc7 23#include "system.h"
4977bab6 24#include "coretypes.h"
8d08fdba 25#include "cp-tree.h"
2adfab87 26#include "print-tree.h"
8d08fdba
MS
27
28void
848eed92 29cxx_print_decl (FILE *file, tree node, int indent)
8d08fdba 30{
721c3b42 31 if (TREE_CODE (node) == FIELD_DECL)
8d08fdba 32 {
721c3b42
MM
33 if (DECL_MUTABLE_P (node))
34 {
35 indent_to (file, indent + 3);
36 fprintf (file, " mutable ");
37 }
38 return;
8d08fdba 39 }
721c3b42 40
326eda4b
DB
41 if (!CODE_CONTAINS_STRUCT (TREE_CODE (node), TS_DECL_COMMON)
42 || !DECL_LANG_SPECIFIC (node))
8d08fdba 43 return;
31dbaab5 44
fba1b95f
JM
45 if (TREE_CODE (node) == FUNCTION_DECL)
46 {
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));
51 }
52 else if (TREE_CODE (node) == TEMPLATE_DECL)
53 {
0856b5d7 54 print_node (file, "parms", DECL_TEMPLATE_PARMS (node), indent + 4);
fba1b95f
JM
55 indent_to (file, indent + 3);
56 fprintf (file, " full-name \"%s\"",
57 decl_as_string (node, TFF_TEMPLATE_HEADER));
58 }
59
9b837af4
NS
60 bool need_indent = true;
61
a44a753a
JM
62 tree ntnode = STRIP_TEMPLATE (node);
63 if (TREE_CODE (ntnode) == FUNCTION_DECL
64 || TREE_CODE (ntnode) == VAR_DECL
65 || TREE_CODE (ntnode) == TYPE_DECL
66 || TREE_CODE (ntnode) == CONCEPT_DECL
67 || TREE_CODE (ntnode) == NAMESPACE_DECL)
8c60696b
NS
68 {
69 unsigned m = 0;
a44a753a
JM
70 if (DECL_LANG_SPECIFIC (ntnode) && DECL_MODULE_IMPORT_P (ntnode))
71 m = get_importing_module (ntnode, true);
8c60696b
NS
72
73 if (const char *name = m == ~0u ? "" : module_name (m, true))
74 {
75 if (need_indent)
76 indent_to (file, indent + 3);
77 fprintf (file, " module %d:%s", m, name);
78 need_indent = false;
79 }
80
a44a753a 81 if (DECL_LANG_SPECIFIC (ntnode) && DECL_MODULE_PURVIEW_P (ntnode))
8c60696b
NS
82 {
83 if (need_indent)
84 indent_to (file, indent + 3);
85 fprintf (file, " purview");
86 need_indent = false;
87 }
88 }
89
90 if (DECL_MODULE_EXPORT_P (node))
91 {
92 if (need_indent)
93 indent_to (file, indent + 3);
94 fprintf (file, " exported");
95 need_indent = false;
96 }
97
fba1b95f 98 if (DECL_EXTERNAL (node) && DECL_NOT_REALLY_EXTERN (node))
9b837af4
NS
99 {
100 if (need_indent)
101 indent_to (file, indent + 3);
102 fprintf (file, " not-really-extern");
103 need_indent = false;
104 }
105
f90cdf34
MT
106 if (TREE_CODE (node) == FUNCTION_DECL
107 && DECL_PENDING_INLINE_INFO (node))
9b837af4
NS
108 {
109 if (need_indent)
110 indent_to (file, indent + 3);
111 fprintf (file, " pending-inline-info %p",
112 (void *) DECL_PENDING_INLINE_INFO (node));
113 need_indent = false;
114 }
115
cb6da767 116 if (VAR_OR_FUNCTION_DECL_P (node)
da8a66fc 117 && DECL_TEMPLATE_INFO (node))
9b837af4
NS
118 {
119 if (need_indent)
120 indent_to (file, indent + 3);
121 fprintf (file, " template-info %p",
122 (void *) DECL_TEMPLATE_INFO (node));
123 need_indent = false;
124 }
8d08fdba
MS
125}
126
127void
848eed92 128cxx_print_type (FILE *file, tree node, int indent)
8d08fdba 129{
f3e4d63c 130 switch (TREE_CODE (node))
8d08fdba 131 {
0856b5d7
JM
132 case BOUND_TEMPLATE_TEMPLATE_PARM:
133 print_node (file, "args", TYPE_TI_ARGS (node), indent + 4);
134 gcc_fallthrough ();
135
f3e4d63c
JM
136 case TEMPLATE_TYPE_PARM:
137 case TEMPLATE_TEMPLATE_PARM:
f84b4be9 138 indent_to (file, indent + 3);
30bcc028 139 fprintf (file, "index %d level %d orig_level %d",
90ff44cf
KG
140 TEMPLATE_TYPE_IDX (node), TEMPLATE_TYPE_LEVEL (node),
141 TEMPLATE_TYPE_ORIG_LEVEL (node));
8d08fdba 142 return;
f3e4d63c
JM
143
144 case FUNCTION_TYPE:
145 case METHOD_TYPE:
146 if (TYPE_RAISES_EXCEPTIONS (node))
147 print_node (file, "throws", TYPE_RAISES_EXCEPTIONS (node), indent + 4);
148 return;
149
eb5c3f05
JM
150 case RECORD_TYPE:
151 case UNION_TYPE:
152 break;
153
301ea094
JM
154 case DECLTYPE_TYPE:
155 print_node (file, "expr", DECLTYPE_TYPE_EXPR (node), indent + 4);
156 return;
157
a0dc5e4a
JM
158 case TYPENAME_TYPE:
159 print_node (file, "fullname", TYPENAME_TYPE_FULLNAME (node),
160 indent + 4);
161 return;
162
5f809982
NS
163 case TYPEOF_TYPE:
164 print_node (file, "expr", TYPEOF_TYPE_EXPR (node), indent + 4);
165 return;
166
167 case BASES:
168 if (BASES_DIRECT (node))
169 fputs (" direct", file);
170 print_node (file, "type", BASES_TYPE (node), indent + 4);
171 return;
172
c67dd256 173 case TYPE_PACK_EXPANSION:
5b759cdc 174 print_node (file, "pattern", PACK_EXPANSION_PATTERN (node), indent + 4);
c67dd256
JM
175 print_node (file, "args", PACK_EXPANSION_EXTRA_ARGS (node), indent + 4);
176 return;
177
f3e4d63c
JM
178 default:
179 return;
8d08fdba
MS
180 }
181
f3e4d63c
JM
182 if (TYPE_PTRMEMFUNC_P (node))
183 print_node (file, "ptrmemfunc fn type", TYPE_PTRMEMFUNC_FN_TYPE (node),
184 indent + 4);
185
829fd7e0 186 if (! CLASS_TYPE_P (node))
8d08fdba
MS
187 return;
188
b97e8a14
JM
189 indent_to (file, indent + 4);
190 fprintf (file, "full-name \"%s\"",
191 type_as_string (node, TFF_CLASS_KEY_OR_ENUM));
192
8d08fdba
MS
193 indent_to (file, indent + 3);
194
195 if (TYPE_NEEDS_CONSTRUCTING (node))
fba1b95f 196 fputs ( " needs-constructor", file);
834c6dff 197 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (node))
8d08fdba 198 fputs (" needs-destructor", file);
8d08fdba
MS
199 if (TYPE_HAS_DEFAULT_CONSTRUCTOR (node))
200 fputs (" X()", file);
201 if (TYPE_HAS_CONVERSION (node))
202 fputs (" has-type-conversion", file);
066ec0a4 203 if (TYPE_HAS_COPY_CTOR (node))
8d08fdba 204 {
066ec0a4 205 if (TYPE_HAS_CONST_COPY_CTOR (node))
8d08fdba
MS
206 fputs (" X(constX&)", file);
207 else
208 fputs (" X(X&)", file);
209 }
834c6dff 210 if (TYPE_HAS_NEW_OPERATOR (node))
a28e3c7f 211 fputs (" new", file);
834c6dff 212 if (TYPE_HAS_ARRAY_NEW_OPERATOR (node))
a28e3c7f
MS
213 fputs (" new[]", file);
214 if (TYPE_GETS_DELETE (node) & 1)
215 fputs (" delete", file);
216 if (TYPE_GETS_DELETE (node) & 2)
217 fputs (" delete[]", file);
066ec0a4 218 if (TYPE_HAS_COPY_ASSIGN (node))
8d08fdba 219 fputs (" this=(X&)", file);
8d08fdba
MS
220
221 if (TREE_CODE (node) == RECORD_TYPE)
222 {
cad7e87b
NS
223 if (TYPE_BINFO (node))
224 fprintf (file, " n_parents=%d",
225 BINFO_N_BASE_BINFOS (TYPE_BINFO (node)));
226 else
227 fprintf (file, " no-binfo");
c8094d83 228
8d08fdba
MS
229 fprintf (file, " use_template=%d", CLASSTYPE_USE_TEMPLATE (node));
230 if (CLASSTYPE_INTERFACE_ONLY (node))
231 fprintf (file, " interface-only");
232 if (CLASSTYPE_INTERFACE_UNKNOWN (node))
233 fprintf (file, " interface-unknown");
8d08fdba
MS
234 }
235}
236
237void
848eed92 238cxx_print_identifier (FILE *file, tree node, int indent)
8d08fdba 239{
dd4f41c3
ILT
240 if (indent == 0)
241 fprintf (file, " ");
242 else
a0dc5e4a 243 indent_to (file, indent + 4);
84c0088f
NS
244 fprintf (file, "%s local bindings <%p>", get_identifier_kind_name (node),
245 (void *) IDENTIFIER_BINDING (node));
8d08fdba 246}
30394414 247
a78cbe29
AH
248void
249cxx_print_lambda_node (FILE *file, tree node, int indent)
250{
251 if (LAMBDA_EXPR_MUTABLE_P (node))
252 fprintf (file, " /mutable");
253 fprintf (file, " default_capture_mode=[");
254 switch (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (node))
255 {
256 case CPLD_NONE:
257 fprintf (file, "NONE");
258 break;
259 case CPLD_COPY:
260 fprintf (file, "COPY");
261 break;
262 case CPLD_REFERENCE:
263 fprintf (file, "CPLD_REFERENCE");
264 break;
265 default:
266 fprintf (file, "??");
267 break;
268 }
269 fprintf (file, "] ");
270 print_node (file, "capture_list", LAMBDA_EXPR_CAPTURE_LIST (node), indent + 4);
271 print_node (file, "this_capture", LAMBDA_EXPR_THIS_CAPTURE (node), indent + 4);
a78cbe29
AH
272}
273
30394414 274void
848eed92 275cxx_print_xnode (FILE *file, tree node, int indent)
30394414
JM
276{
277 switch (TREE_CODE (node))
278 {
d85d3d57
MM
279 case BASELINK:
280 print_node (file, "functions", BASELINK_FUNCTIONS (node), indent + 4);
281 print_node (file, "binfo", BASELINK_BINFO (node), indent + 4);
3db45ab5 282 print_node (file, "access_binfo", BASELINK_ACCESS_BINFO (node),
d85d3d57 283 indent + 4);
66ce8ff7 284 print_node (file, "optype", BASELINK_OPTYPE (node), indent + 4);
d85d3d57 285 break;
2c73f9f5 286 case OVERLOAD:
31dbaab5
NS
287 print_node (file, "function", OVL_FUNCTION (node), indent + 4);
288 print_node (file, "next", OVL_CHAIN (node), indent + 4);
08362e16 289 break;
05f7a2af
NS
290 case BINDING_VECTOR:
291 {
292 unsigned len = BINDING_VECTOR_NUM_CLUSTERS (node);
293 print_node (file, "name", BINDING_VECTOR_NAME (node), indent + 4);
294 fprintf (file, " clusters %u, alloc %u", len,
295 BINDING_VECTOR_ALLOC_CLUSTERS (node));
296 for (unsigned ix = 0; ix != len; ix++)
297 {
298 binding_cluster *cluster = &BINDING_VECTOR_CLUSTER (node, ix);
744ca1bf 299 char pfx[24];
05f7a2af
NS
300 for (unsigned jx = 0; jx != BINDING_VECTOR_SLOTS_PER_CLUSTER; jx++)
301 if (cluster->indices[jx].span)
302 {
303 int len = sprintf (pfx, "module:%u",
304 cluster->indices[jx].base);
305 if (cluster->indices[jx].span > 1)
744ca1bf
NS
306 len += sprintf (&pfx[len], "(+%u)",
307 cluster->indices[jx].span);
05f7a2af
NS
308 len += sprintf (&pfx[len], " cluster:%u/%u", ix, jx);
309 binding_slot &slot = cluster->slots[jx];
310 if (slot.is_lazy ())
311 {
312 indent_to (file, indent + 4);
313 unsigned lazy = slot.get_lazy ();
5f27a9f9 314 fprintf (file, "%s snum:%u", pfx, lazy);
05f7a2af
NS
315 }
316 else if (slot)
317 print_node (file, pfx, slot, indent + 4);
318 else
319 {
320 indent_to (file, indent + 4);
321 fprintf (file, "%s NULL", pfx);
322 }
323 }
324 }
325 }
326 break;
f94ae2f5 327 case TEMPLATE_PARM_INDEX:
a7564a05 328 print_node (file, "decl", TEMPLATE_PARM_DECL (node), indent+4);
f94ae2f5 329 indent_to (file, indent + 3);
30bcc028 330 fprintf (file, "index %d level %d orig_level %d",
90ff44cf
KG
331 TEMPLATE_PARM_IDX (node), TEMPLATE_PARM_LEVEL (node),
332 TEMPLATE_PARM_ORIG_LEVEL (node));
f94ae2f5 333 break;
f25669da
JM
334 case TEMPLATE_INFO:
335 print_node (file, "template", TI_TEMPLATE (node), indent+4);
336 print_node (file, "args", TI_ARGS (node), indent+4);
337 if (TI_PENDING_TEMPLATE_FLAG (node))
338 {
339 indent_to (file, indent + 3);
340 fprintf (file, "pending_template");
341 }
342 break;
971e17ff
AS
343 case CONSTRAINT_INFO:
344 {
345 tree_constraint_info *cinfo = (tree_constraint_info *)node;
346 if (cinfo->template_reqs)
347 print_node (file, "template_reqs", cinfo->template_reqs, indent+4);
348 if (cinfo->declarator_reqs)
349 print_node (file, "declarator_reqs", cinfo->declarator_reqs,
350 indent+4);
351 print_node (file, "associated_constr",
352 cinfo->associated_constr, indent+4);
971e17ff
AS
353 break;
354 }
f03a5402
JM
355 case ARGUMENT_PACK_SELECT:
356 print_node (file, "pack", ARGUMENT_PACK_SELECT_FROM_PACK (node),
357 indent+4);
358 indent_to (file, indent + 3);
359 fprintf (file, "index %d", ARGUMENT_PACK_SELECT_INDEX (node));
360 break;
10261728
JM
361 case DEFERRED_NOEXCEPT:
362 print_node (file, "pattern", DEFERRED_NOEXCEPT_PATTERN (node), indent+4);
363 print_node (file, "args", DEFERRED_NOEXCEPT_ARGS (node), indent+4);
364 break;
80f1c14d
JM
365 case TRAIT_EXPR:
366 indent_to (file, indent+4);
367 fprintf (file, "kind %d", TRAIT_EXPR_KIND (node));
368 print_node (file, "type 1", TRAIT_EXPR_TYPE1 (node), indent+4);
369 if (TRAIT_EXPR_TYPE2 (node))
370 print_node (file, "type 2", TRAIT_EXPR_TYPE2 (node), indent+4);
371 break;
a78cbe29
AH
372 case LAMBDA_EXPR:
373 cxx_print_lambda_node (file, node, indent);
374 break;
e5ccab83
JM
375 case STATIC_ASSERT:
376 if (location_t loc = STATIC_ASSERT_SOURCE_LOCATION (node))
377 {
378 expanded_location xloc = expand_location (loc);
379 indent_to (file, indent+4);
380 fprintf (file, "%s:%d:%d", xloc.file, xloc.line, xloc.column);
381 }
382 print_node (file, "condition", STATIC_ASSERT_CONDITION (node), indent+4);
383 if (tree message = STATIC_ASSERT_MESSAGE (node))
384 print_node (file, "message", message, indent+4);
385 break;
30394414
JM
386 default:
387 break;
388 }
389}
3a4219ca
JM
390
391/* Print the node NODE on standard error, for debugging. */
392
393DEBUG_FUNCTION void
394debug_tree (cp_expr node)
395{
396 debug_tree (node.get_value());
397}
31128144
NS
398
399DEBUG_FUNCTION void
400debug_overload (tree node)
401{
402 FILE *file = stdout;
403
404 for (lkp_iterator iter (node); iter; ++iter)
405 {
406 tree decl = *iter;
407 auto xloc = expand_location (DECL_SOURCE_LOCATION (decl));
408 auto fullname = decl_as_string (decl, 0);
d13c0ae8
NS
409 bool using_p = iter.using_p ();
410 bool hidden_p = iter.hidden_p ();
31128144 411
d13c0ae8
NS
412 fprintf (file, "%p:%c%c %s:%d:%d \"%s\"\n", (void *)decl,
413 hidden_p ? 'H' : '-',
414 using_p ? 'U' : '-',
31128144
NS
415 xloc.file, xloc.line, xloc.column, fullname);
416 }
417}