1 /* Prints out trees in human readable form.
2 Copyright (C) 1992-2020 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 (!CODE_CONTAINS_STRUCT (TREE_CODE (node
), TS_DECL_COMMON
)
42 || !DECL_LANG_SPECIFIC (node
))
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
, "parms", DECL_TEMPLATE_PARMS (node
), indent
+ 4);
55 indent_to (file
, indent
+ 3);
56 fprintf (file
, " full-name \"%s\"",
57 decl_as_string (node
, TFF_TEMPLATE_HEADER
));
60 bool need_indent
= true;
62 if (DECL_EXTERNAL (node
) && DECL_NOT_REALLY_EXTERN (node
))
65 indent_to (file
, indent
+ 3);
66 fprintf (file
, " not-really-extern");
70 if (TREE_CODE (node
) == FUNCTION_DECL
71 && DECL_PENDING_INLINE_INFO (node
))
74 indent_to (file
, indent
+ 3);
75 fprintf (file
, " pending-inline-info %p",
76 (void *) DECL_PENDING_INLINE_INFO (node
));
80 if (VAR_OR_FUNCTION_DECL_P (node
)
81 && DECL_TEMPLATE_INFO (node
))
84 indent_to (file
, indent
+ 3);
85 fprintf (file
, " template-info %p",
86 (void *) DECL_TEMPLATE_INFO (node
));
92 cxx_print_type (FILE *file
, tree node
, int indent
)
94 switch (TREE_CODE (node
))
96 case BOUND_TEMPLATE_TEMPLATE_PARM
:
97 print_node (file
, "args", TYPE_TI_ARGS (node
), indent
+ 4);
100 case TEMPLATE_TYPE_PARM
:
101 case TEMPLATE_TEMPLATE_PARM
:
102 indent_to (file
, indent
+ 3);
103 fprintf (file
, "index %d level %d orig_level %d",
104 TEMPLATE_TYPE_IDX (node
), TEMPLATE_TYPE_LEVEL (node
),
105 TEMPLATE_TYPE_ORIG_LEVEL (node
));
110 if (TYPE_RAISES_EXCEPTIONS (node
))
111 print_node (file
, "throws", TYPE_RAISES_EXCEPTIONS (node
), indent
+ 4);
119 print_node (file
, "expr", DECLTYPE_TYPE_EXPR (node
), indent
+ 4);
123 print_node (file
, "fullname", TYPENAME_TYPE_FULLNAME (node
),
128 print_node (file
, "expr", TYPEOF_TYPE_EXPR (node
), indent
+ 4);
132 if (BASES_DIRECT (node
))
133 fputs (" direct", file
);
134 print_node (file
, "type", BASES_TYPE (node
), indent
+ 4);
137 case TYPE_PACK_EXPANSION
:
138 print_node (file
, "args", PACK_EXPANSION_EXTRA_ARGS (node
), indent
+ 4);
145 if (TYPE_PTRMEMFUNC_P (node
))
146 print_node (file
, "ptrmemfunc fn type", TYPE_PTRMEMFUNC_FN_TYPE (node
),
149 if (! CLASS_TYPE_P (node
))
152 indent_to (file
, indent
+ 4);
153 fprintf (file
, "full-name \"%s\"",
154 type_as_string (node
, TFF_CLASS_KEY_OR_ENUM
));
156 indent_to (file
, indent
+ 3);
158 if (TYPE_NEEDS_CONSTRUCTING (node
))
159 fputs ( " needs-constructor", file
);
160 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (node
))
161 fputs (" needs-destructor", file
);
162 if (TYPE_HAS_DEFAULT_CONSTRUCTOR (node
))
163 fputs (" X()", file
);
164 if (TYPE_HAS_CONVERSION (node
))
165 fputs (" has-type-conversion", file
);
166 if (TYPE_HAS_COPY_CTOR (node
))
168 if (TYPE_HAS_CONST_COPY_CTOR (node
))
169 fputs (" X(constX&)", file
);
171 fputs (" X(X&)", file
);
173 if (TYPE_HAS_NEW_OPERATOR (node
))
174 fputs (" new", file
);
175 if (TYPE_HAS_ARRAY_NEW_OPERATOR (node
))
176 fputs (" new[]", file
);
177 if (TYPE_GETS_DELETE (node
) & 1)
178 fputs (" delete", file
);
179 if (TYPE_GETS_DELETE (node
) & 2)
180 fputs (" delete[]", file
);
181 if (TYPE_HAS_COPY_ASSIGN (node
))
182 fputs (" this=(X&)", file
);
184 if (TREE_CODE (node
) == RECORD_TYPE
)
186 if (TYPE_BINFO (node
))
187 fprintf (file
, " n_parents=%d",
188 BINFO_N_BASE_BINFOS (TYPE_BINFO (node
)));
190 fprintf (file
, " no-binfo");
192 fprintf (file
, " use_template=%d", CLASSTYPE_USE_TEMPLATE (node
));
193 if (CLASSTYPE_INTERFACE_ONLY (node
))
194 fprintf (file
, " interface-only");
195 if (CLASSTYPE_INTERFACE_UNKNOWN (node
))
196 fprintf (file
, " interface-unknown");
201 cxx_print_identifier (FILE *file
, tree node
, int indent
)
206 indent_to (file
, indent
+ 4);
207 fprintf (file
, "%s local bindings <%p>", get_identifier_kind_name (node
),
208 (void *) IDENTIFIER_BINDING (node
));
212 cxx_print_lambda_node (FILE *file
, tree node
, int indent
)
214 if (LAMBDA_EXPR_MUTABLE_P (node
))
215 fprintf (file
, " /mutable");
216 fprintf (file
, " default_capture_mode=[");
217 switch (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (node
))
220 fprintf (file
, "NONE");
223 fprintf (file
, "COPY");
226 fprintf (file
, "CPLD_REFERENCE");
229 fprintf (file
, "??");
232 fprintf (file
, "] ");
233 print_node (file
, "capture_list", LAMBDA_EXPR_CAPTURE_LIST (node
), indent
+ 4);
234 print_node (file
, "this_capture", LAMBDA_EXPR_THIS_CAPTURE (node
), indent
+ 4);
238 cxx_print_xnode (FILE *file
, tree node
, int indent
)
240 switch (TREE_CODE (node
))
243 print_node (file
, "functions", BASELINK_FUNCTIONS (node
), indent
+ 4);
244 print_node (file
, "binfo", BASELINK_BINFO (node
), indent
+ 4);
245 print_node (file
, "access_binfo", BASELINK_ACCESS_BINFO (node
),
247 print_node (file
, "optype", BASELINK_OPTYPE (node
), indent
+ 4);
250 print_node (file
, "function", OVL_FUNCTION (node
), indent
+ 4);
251 print_node (file
, "next", OVL_CHAIN (node
), indent
+ 4);
255 unsigned len
= BINDING_VECTOR_NUM_CLUSTERS (node
);
256 print_node (file
, "name", BINDING_VECTOR_NAME (node
), indent
+ 4);
257 fprintf (file
, " clusters %u, alloc %u", len
,
258 BINDING_VECTOR_ALLOC_CLUSTERS (node
));
259 for (unsigned ix
= 0; ix
!= len
; ix
++)
261 binding_cluster
*cluster
= &BINDING_VECTOR_CLUSTER (node
, ix
);
263 for (unsigned jx
= 0; jx
!= BINDING_VECTOR_SLOTS_PER_CLUSTER
; jx
++)
264 if (cluster
->indices
[jx
].span
)
266 int len
= sprintf (pfx
, "module:%u",
267 cluster
->indices
[jx
].base
);
268 if (cluster
->indices
[jx
].span
> 1)
270 += sprintf (&pfx
[len
], "(+%u)", cluster
->indices
[jx
].span
);
271 len
+= sprintf (&pfx
[len
], " cluster:%u/%u", ix
, jx
);
272 binding_slot
&slot
= cluster
->slots
[jx
];
275 indent_to (file
, indent
+ 4);
276 unsigned lazy
= slot
.get_lazy ();
277 fprintf (file
, "%s snum:%u flags:%d",
278 pfx
, lazy
>> 2, lazy
& 3);
281 print_node (file
, pfx
, slot
, indent
+ 4);
284 indent_to (file
, indent
+ 4);
285 fprintf (file
, "%s NULL", pfx
);
291 case TEMPLATE_PARM_INDEX
:
292 print_node (file
, "decl", TEMPLATE_PARM_DECL (node
), indent
+4);
293 indent_to (file
, indent
+ 3);
294 fprintf (file
, "index %d level %d orig_level %d",
295 TEMPLATE_PARM_IDX (node
), TEMPLATE_PARM_LEVEL (node
),
296 TEMPLATE_PARM_ORIG_LEVEL (node
));
299 print_node (file
, "template", TI_TEMPLATE (node
), indent
+4);
300 print_node (file
, "args", TI_ARGS (node
), indent
+4);
301 if (TI_PENDING_TEMPLATE_FLAG (node
))
303 indent_to (file
, indent
+ 3);
304 fprintf (file
, "pending_template");
307 case CONSTRAINT_INFO
:
309 tree_constraint_info
*cinfo
= (tree_constraint_info
*)node
;
310 if (cinfo
->template_reqs
)
311 print_node (file
, "template_reqs", cinfo
->template_reqs
, indent
+4);
312 if (cinfo
->declarator_reqs
)
313 print_node (file
, "declarator_reqs", cinfo
->declarator_reqs
,
315 print_node (file
, "associated_constr",
316 cinfo
->associated_constr
, indent
+4);
319 case ARGUMENT_PACK_SELECT
:
320 print_node (file
, "pack", ARGUMENT_PACK_SELECT_FROM_PACK (node
),
322 indent_to (file
, indent
+ 3);
323 fprintf (file
, "index %d", ARGUMENT_PACK_SELECT_INDEX (node
));
325 case DEFERRED_NOEXCEPT
:
326 print_node (file
, "pattern", DEFERRED_NOEXCEPT_PATTERN (node
), indent
+4);
327 print_node (file
, "args", DEFERRED_NOEXCEPT_ARGS (node
), indent
+4);
330 indent_to (file
, indent
+4);
331 fprintf (file
, "kind %d", TRAIT_EXPR_KIND (node
));
332 print_node (file
, "type 1", TRAIT_EXPR_TYPE1 (node
), indent
+4);
333 if (TRAIT_EXPR_TYPE2 (node
))
334 print_node (file
, "type 2", TRAIT_EXPR_TYPE2 (node
), indent
+4);
337 cxx_print_lambda_node (file
, node
, indent
);
340 if (location_t loc
= STATIC_ASSERT_SOURCE_LOCATION (node
))
342 expanded_location xloc
= expand_location (loc
);
343 indent_to (file
, indent
+4);
344 fprintf (file
, "%s:%d:%d", xloc
.file
, xloc
.line
, xloc
.column
);
346 print_node (file
, "condition", STATIC_ASSERT_CONDITION (node
), indent
+4);
347 if (tree message
= STATIC_ASSERT_MESSAGE (node
))
348 print_node (file
, "message", message
, indent
+4);
355 /* Print the node NODE on standard error, for debugging. */
358 debug_tree (cp_expr node
)
360 debug_tree (node
.get_value());
364 debug_overload (tree node
)
368 for (lkp_iterator
iter (node
); iter
; ++iter
)
371 auto xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
372 auto fullname
= decl_as_string (decl
, 0);
373 bool using_p
= iter
.using_p ();
374 bool hidden_p
= iter
.hidden_p ();
376 fprintf (file
, "%p:%c%c %s:%d:%d \"%s\"\n", (void *)decl
,
377 hidden_p
? 'H' : '-',
379 xloc
.file
, xloc
.line
, xloc
.column
, fullname
);