1 /* Tree-dumping functionality for intermediate representation.
2 Copyright (C) 1999-2015 Free Software Foundation, Inc.
3 Written by Mark Mitchell <mark@codesourcery.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/>. */
23 #include "coretypes.h"
25 #include "tree-dump.h"
27 static void dump_access (dump_info_p
, tree
);
29 static void dump_op (dump_info_p
, tree
);
31 /* Dump a representation of the accessibility information associated
35 dump_access (dump_info_p di
, tree t
)
37 if (TREE_PROTECTED(t
))
38 dump_string_field (di
, "accs", "prot");
39 else if (TREE_PRIVATE(t
))
40 dump_string_field (di
, "accs", "priv");
42 dump_string_field (di
, "accs", "pub");
45 /* Dump a representation of the specific operator for an overloaded
46 operator associated with node t. */
49 dump_op (dump_info_p di
, tree t
)
51 switch (DECL_OVERLOADED_OPERATOR_P (t
)) {
53 dump_string (di
, "new");
56 dump_string (di
, "vecnew");
59 dump_string (di
, "delete");
62 dump_string (di
, "vecdelete");
65 dump_string (di
, "pos");
68 dump_string (di
, "neg");
71 dump_string (di
, "addr");
74 dump_string(di
, "deref");
77 dump_string(di
, "not");
80 dump_string(di
, "lnot");
82 case PREINCREMENT_EXPR
:
83 dump_string(di
, "preinc");
85 case PREDECREMENT_EXPR
:
86 dump_string(di
, "predec");
89 if (DECL_ASSIGNMENT_OPERATOR_P (t
))
90 dump_string (di
, "plusassign");
92 dump_string(di
, "plus");
95 if (DECL_ASSIGNMENT_OPERATOR_P (t
))
96 dump_string (di
, "minusassign");
98 dump_string(di
, "minus");
101 if (DECL_ASSIGNMENT_OPERATOR_P (t
))
102 dump_string (di
, "multassign");
104 dump_string (di
, "mult");
107 if (DECL_ASSIGNMENT_OPERATOR_P (t
))
108 dump_string (di
, "divassign");
110 dump_string (di
, "div");
113 if (DECL_ASSIGNMENT_OPERATOR_P (t
))
114 dump_string (di
, "modassign");
116 dump_string (di
, "mod");
119 if (DECL_ASSIGNMENT_OPERATOR_P (t
))
120 dump_string (di
, "andassign");
122 dump_string (di
, "and");
125 if (DECL_ASSIGNMENT_OPERATOR_P (t
))
126 dump_string (di
, "orassign");
128 dump_string (di
, "or");
131 if (DECL_ASSIGNMENT_OPERATOR_P (t
))
132 dump_string (di
, "xorassign");
134 dump_string (di
, "xor");
137 if (DECL_ASSIGNMENT_OPERATOR_P (t
))
138 dump_string (di
, "lshiftassign");
140 dump_string (di
, "lshift");
143 if (DECL_ASSIGNMENT_OPERATOR_P (t
))
144 dump_string (di
, "rshiftassign");
146 dump_string (di
, "rshift");
149 dump_string (di
, "eq");
152 dump_string (di
, "ne");
155 dump_string (di
, "lt");
158 dump_string (di
, "gt");
161 dump_string (di
, "le");
164 dump_string (di
, "ge");
166 case TRUTH_ANDIF_EXPR
:
167 dump_string (di
, "land");
169 case TRUTH_ORIF_EXPR
:
170 dump_string (di
, "lor");
173 dump_string (di
, "compound");
176 dump_string (di
, "memref");
179 dump_string (di
, "ref");
182 dump_string (di
, "subs");
184 case POSTINCREMENT_EXPR
:
185 dump_string (di
, "postinc");
187 case POSTDECREMENT_EXPR
:
188 dump_string (di
, "postdec");
191 dump_string (di
, "call");
194 if (DECL_ASSIGNMENT_OPERATOR_P (t
))
195 dump_string (di
, "assign");
202 /* Dump information common to statements from STMT. */
205 dump_stmt (dump_info_p di
, const_tree t
)
207 if (EXPR_HAS_LOCATION (t
))
208 dump_int (di
, "line", EXPR_LINENO (t
));
212 cp_dump_tree (void* dump_info
, tree t
)
215 dump_info_p di
= (dump_info_p
) dump_info
;
217 /* Figure out what kind of node this is. */
218 code
= TREE_CODE (t
);
222 if (DECL_LANG_SPECIFIC (t
) && DECL_LANGUAGE (t
) != lang_cplusplus
)
223 dump_string_field (di
, "lang", language_to_string (DECL_LANGUAGE (t
)));
228 case IDENTIFIER_NODE
:
229 if (IDENTIFIER_OPNAME_P (t
))
231 dump_string_field (di
, "note", "operator");
234 else if (IDENTIFIER_TYPENAME_P (t
))
236 dump_child ("tynm", TREE_TYPE (t
));
242 dump_string_field (di
, "note", "ptrmem");
243 dump_child ("ptd", TYPE_PTRMEM_POINTED_TO_TYPE (t
));
244 dump_child ("cls", TYPE_PTRMEM_CLASS_TYPE (t
));
248 if (TYPE_PTRMEMFUNC_P (t
))
250 dump_string_field (di
, "note", "ptrmem");
251 dump_child ("ptd", TYPE_PTRMEM_POINTED_TO_TYPE (t
));
252 dump_child ("cls", TYPE_PTRMEM_CLASS_TYPE (t
));
258 /* Is it a type used as a base? */
259 if (TYPE_CONTEXT (t
) && TREE_CODE (TYPE_CONTEXT (t
)) == TREE_CODE (t
)
260 && CLASSTYPE_AS_BASE (TYPE_CONTEXT (t
)) == t
)
262 dump_child ("bfld", TYPE_CONTEXT (t
));
266 if (! MAYBE_CLASS_TYPE_P (t
))
269 dump_child ("vfld", TYPE_VFIELD (t
));
270 if (CLASSTYPE_TEMPLATE_SPECIALIZATION(t
))
271 dump_string(di
, "spec");
273 if (!dump_flag (di
, TDF_SLIM
, t
) && TYPE_BINFO (t
))
279 for (binfo
= TYPE_BINFO (t
), i
= 0;
280 BINFO_BASE_ITERATE (binfo
, i
, base_binfo
); ++i
)
282 dump_child ("base", BINFO_TYPE (base_binfo
));
283 if (BINFO_VIRTUAL_P (base_binfo
))
284 dump_string_field (di
, "spec", "virt");
285 dump_access (di
, base_binfo
);
292 if (DECL_MUTABLE_P (t
))
293 dump_string_field (di
, "spec", "mutable");
297 if (TREE_CODE (CP_DECL_CONTEXT (t
)) == RECORD_TYPE
)
299 if (TREE_STATIC (t
) && !TREE_PUBLIC (t
))
300 dump_string_field (di
, "link", "static");
304 if (!DECL_THUNK_P (t
))
306 if (DECL_OVERLOADED_OPERATOR_P (t
)) {
307 dump_string_field (di
, "note", "operator");
310 if (DECL_FUNCTION_MEMBER_P (t
))
312 dump_string_field (di
, "note", "member");
315 if (DECL_PURE_VIRTUAL_P (t
))
316 dump_string_field (di
, "spec", "pure");
317 if (DECL_VIRTUAL_P (t
))
318 dump_string_field (di
, "spec", "virt");
319 if (DECL_CONSTRUCTOR_P (t
))
320 dump_string_field (di
, "note", "constructor");
321 if (DECL_DESTRUCTOR_P (t
))
322 dump_string_field (di
, "note", "destructor");
323 if (DECL_CONV_FN_P (t
))
324 dump_string_field (di
, "note", "conversion");
325 if (DECL_GLOBAL_CTOR_P (t
))
326 dump_string_field (di
, "note", "global init");
327 if (DECL_GLOBAL_DTOR_P (t
))
328 dump_string_field (di
, "note", "global fini");
329 if (DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t
))
330 dump_string_field (di
, "note", "pseudo tmpl");
334 tree virt
= THUNK_VIRTUAL_OFFSET (t
);
336 dump_string_field (di
, "note", "thunk");
337 if (DECL_THIS_THUNK_P (t
))
338 dump_string_field (di
, "note", "this adjusting");
341 dump_string_field (di
, "note", "result adjusting");
343 virt
= BINFO_VPTR_FIELD (virt
);
345 dump_int (di
, "fixd", THUNK_FIXED_OFFSET (t
));
347 dump_int (di
, "virt", tree_to_shwi (virt
));
348 dump_child ("fn", DECL_INITIAL (t
));
353 if (DECL_NAMESPACE_ALIAS (t
))
354 dump_child ("alis", DECL_NAMESPACE_ALIAS (t
));
355 else if (!dump_flag (di
, TDF_SLIM
, t
))
356 dump_child ("dcls", cp_namespace_decls (t
));
360 dump_child ("rslt", DECL_TEMPLATE_RESULT (t
));
361 dump_child ("inst", DECL_TEMPLATE_INSTANTIATIONS (t
));
362 dump_child ("spcs", DECL_TEMPLATE_SPECIALIZATIONS (t
));
363 dump_child ("prms", DECL_TEMPLATE_PARMS (t
));
367 dump_child ("crnt", OVL_CURRENT (t
));
368 dump_child ("chan", OVL_CHAIN (t
));
374 dump_string_field (di
, "note", "cleanup");
375 dump_child ("body", TRY_STMTS (t
));
376 dump_child ("hdlr", TRY_HANDLERS (t
));
381 dump_child ("body", EH_SPEC_STMTS (t
));
382 dump_child ("raises", EH_SPEC_RAISES (t
));
386 dump_child ("clas", PTRMEM_CST_CLASS (t
));
387 dump_child ("mbr", PTRMEM_CST_MEMBER (t
));
391 /* These nodes are unary, but do not have code class `1'. */
392 dump_child ("op 0", TREE_OPERAND (t
, 0));
399 aggr_init_expr_arg_iterator iter
;
400 dump_int (di
, "ctor", AGGR_INIT_VIA_CTOR_P (t
));
401 dump_child ("fn", AGGR_INIT_EXPR_FN (t
));
402 FOR_EACH_AGGR_INIT_EXPR_ARG (arg
, iter
, t
)
405 sprintf (buffer
, "%u", i
);
406 dump_child (buffer
, arg
);
409 dump_child ("decl", AGGR_INIT_EXPR_SLOT (t
));
415 dump_child ("parm", HANDLER_PARMS (t
));
416 dump_child ("body", HANDLER_BODY (t
));
419 case MUST_NOT_THROW_EXPR
:
421 dump_child ("body", TREE_OPERAND (t
, 0));
422 dump_child ("cond", MUST_NOT_THROW_COND (t
));
427 dump_child ("nmsp", USING_STMT_NAMESPACE (t
));
432 dump_child ("decl", CLEANUP_DECL (t
));
433 dump_child ("expr", CLEANUP_EXPR (t
));
434 dump_child ("body", CLEANUP_BODY (t
));
439 dump_child ("cond", IF_COND (t
));
440 dump_child ("then", THEN_CLAUSE (t
));
441 dump_child ("else", ELSE_CLAUSE (t
));
451 dump_child ("body", DO_BODY (t
));
452 dump_child ("cond", DO_COND (t
));
457 dump_child ("init", FOR_INIT_STMT (t
));
458 dump_child ("cond", FOR_COND (t
));
459 dump_child ("expr", FOR_EXPR (t
));
460 dump_child ("body", FOR_BODY (t
));
465 dump_child ("decl", RANGE_FOR_DECL (t
));
466 dump_child ("expr", RANGE_FOR_EXPR (t
));
467 dump_child ("body", RANGE_FOR_BODY (t
));
472 dump_child ("cond", SWITCH_STMT_COND (t
));
473 dump_child ("body", SWITCH_STMT_BODY (t
));
478 dump_child ("cond", WHILE_COND (t
));
479 dump_child ("body", WHILE_BODY (t
));
483 dump_child ("stmt", STMT_EXPR_STMT (t
));
488 dump_child ("expr", EXPR_STMT_EXPR (t
));
495 return c_dump_tree (di
, t
);