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);
253 case TEMPLATE_PARM_INDEX
:
254 print_node (file
, "decl", TEMPLATE_PARM_DECL (node
), indent
+4);
255 indent_to (file
, indent
+ 3);
256 fprintf (file
, "index %d level %d orig_level %d",
257 TEMPLATE_PARM_IDX (node
), TEMPLATE_PARM_LEVEL (node
),
258 TEMPLATE_PARM_ORIG_LEVEL (node
));
261 print_node (file
, "template", TI_TEMPLATE (node
), indent
+4);
262 print_node (file
, "args", TI_ARGS (node
), indent
+4);
263 if (TI_PENDING_TEMPLATE_FLAG (node
))
265 indent_to (file
, indent
+ 3);
266 fprintf (file
, "pending_template");
269 case CONSTRAINT_INFO
:
271 tree_constraint_info
*cinfo
= (tree_constraint_info
*)node
;
272 if (cinfo
->template_reqs
)
273 print_node (file
, "template_reqs", cinfo
->template_reqs
, indent
+4);
274 if (cinfo
->declarator_reqs
)
275 print_node (file
, "declarator_reqs", cinfo
->declarator_reqs
,
277 print_node (file
, "associated_constr",
278 cinfo
->associated_constr
, indent
+4);
281 case ARGUMENT_PACK_SELECT
:
282 print_node (file
, "pack", ARGUMENT_PACK_SELECT_FROM_PACK (node
),
284 indent_to (file
, indent
+ 3);
285 fprintf (file
, "index %d", ARGUMENT_PACK_SELECT_INDEX (node
));
287 case DEFERRED_NOEXCEPT
:
288 print_node (file
, "pattern", DEFERRED_NOEXCEPT_PATTERN (node
), indent
+4);
289 print_node (file
, "args", DEFERRED_NOEXCEPT_ARGS (node
), indent
+4);
292 indent_to (file
, indent
+4);
293 fprintf (file
, "kind %d", TRAIT_EXPR_KIND (node
));
294 print_node (file
, "type 1", TRAIT_EXPR_TYPE1 (node
), indent
+4);
295 if (TRAIT_EXPR_TYPE2 (node
))
296 print_node (file
, "type 2", TRAIT_EXPR_TYPE2 (node
), indent
+4);
299 cxx_print_lambda_node (file
, node
, indent
);
302 if (location_t loc
= STATIC_ASSERT_SOURCE_LOCATION (node
))
304 expanded_location xloc
= expand_location (loc
);
305 indent_to (file
, indent
+4);
306 fprintf (file
, "%s:%d:%d", xloc
.file
, xloc
.line
, xloc
.column
);
308 print_node (file
, "condition", STATIC_ASSERT_CONDITION (node
), indent
+4);
309 if (tree message
= STATIC_ASSERT_MESSAGE (node
))
310 print_node (file
, "message", message
, indent
+4);
317 /* Print the node NODE on standard error, for debugging. */
320 debug_tree (cp_expr node
)
322 debug_tree (node
.get_value());
326 debug_overload (tree node
)
330 for (lkp_iterator
iter (node
); iter
; ++iter
)
333 auto xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
334 auto fullname
= decl_as_string (decl
, 0);
335 bool using_p
= iter
.using_p ();
336 bool hidden_p
= iter
.hidden_p ();
338 fprintf (file
, "%p:%c%c %s:%d:%d \"%s\"\n", (void *)decl
,
339 hidden_p
? 'H' : '-',
341 xloc
.file
, xloc
.line
, xloc
.column
, fullname
);