1 /* Tree-dumping functionality for intermediate representation.
2 Copyright (C) 1999-2014 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"
27 #include "tree-dump.h"
29 static void dump_access (dump_info_p
, tree
);
31 static void dump_op (dump_info_p
, tree
);
33 /* Dump a representation of the accessibility information associated
37 dump_access (dump_info_p di
, tree t
)
39 if (TREE_PROTECTED(t
))
40 dump_string_field (di
, "accs", "prot");
41 else if (TREE_PRIVATE(t
))
42 dump_string_field (di
, "accs", "priv");
44 dump_string_field (di
, "accs", "pub");
47 /* Dump a representation of the specific operator for an overloaded
48 operator associated with node t. */
51 dump_op (dump_info_p di
, tree t
)
53 switch (DECL_OVERLOADED_OPERATOR_P (t
)) {
55 dump_string (di
, "new");
58 dump_string (di
, "vecnew");
61 dump_string (di
, "delete");
64 dump_string (di
, "vecdelete");
67 dump_string (di
, "pos");
70 dump_string (di
, "neg");
73 dump_string (di
, "addr");
76 dump_string(di
, "deref");
79 dump_string(di
, "not");
82 dump_string(di
, "lnot");
84 case PREINCREMENT_EXPR
:
85 dump_string(di
, "preinc");
87 case PREDECREMENT_EXPR
:
88 dump_string(di
, "predec");
91 if (DECL_ASSIGNMENT_OPERATOR_P (t
))
92 dump_string (di
, "plusassign");
94 dump_string(di
, "plus");
97 if (DECL_ASSIGNMENT_OPERATOR_P (t
))
98 dump_string (di
, "minusassign");
100 dump_string(di
, "minus");
103 if (DECL_ASSIGNMENT_OPERATOR_P (t
))
104 dump_string (di
, "multassign");
106 dump_string (di
, "mult");
109 if (DECL_ASSIGNMENT_OPERATOR_P (t
))
110 dump_string (di
, "divassign");
112 dump_string (di
, "div");
115 if (DECL_ASSIGNMENT_OPERATOR_P (t
))
116 dump_string (di
, "modassign");
118 dump_string (di
, "mod");
121 if (DECL_ASSIGNMENT_OPERATOR_P (t
))
122 dump_string (di
, "andassign");
124 dump_string (di
, "and");
127 if (DECL_ASSIGNMENT_OPERATOR_P (t
))
128 dump_string (di
, "orassign");
130 dump_string (di
, "or");
133 if (DECL_ASSIGNMENT_OPERATOR_P (t
))
134 dump_string (di
, "xorassign");
136 dump_string (di
, "xor");
139 if (DECL_ASSIGNMENT_OPERATOR_P (t
))
140 dump_string (di
, "lshiftassign");
142 dump_string (di
, "lshift");
145 if (DECL_ASSIGNMENT_OPERATOR_P (t
))
146 dump_string (di
, "rshiftassign");
148 dump_string (di
, "rshift");
151 dump_string (di
, "eq");
154 dump_string (di
, "ne");
157 dump_string (di
, "lt");
160 dump_string (di
, "gt");
163 dump_string (di
, "le");
166 dump_string (di
, "ge");
168 case TRUTH_ANDIF_EXPR
:
169 dump_string (di
, "land");
171 case TRUTH_ORIF_EXPR
:
172 dump_string (di
, "lor");
175 dump_string (di
, "compound");
178 dump_string (di
, "memref");
181 dump_string (di
, "ref");
184 dump_string (di
, "subs");
186 case POSTINCREMENT_EXPR
:
187 dump_string (di
, "postinc");
189 case POSTDECREMENT_EXPR
:
190 dump_string (di
, "postdec");
193 dump_string (di
, "call");
196 if (DECL_ASSIGNMENT_OPERATOR_P (t
))
197 dump_string (di
, "assign");
204 /* Dump information common to statements from STMT. */
207 dump_stmt (dump_info_p di
, const_tree t
)
209 if (EXPR_HAS_LOCATION (t
))
210 dump_int (di
, "line", EXPR_LINENO (t
));
214 cp_dump_tree (void* dump_info
, tree t
)
217 dump_info_p di
= (dump_info_p
) dump_info
;
219 /* Figure out what kind of node this is. */
220 code
= TREE_CODE (t
);
224 if (DECL_LANG_SPECIFIC (t
) && DECL_LANGUAGE (t
) != lang_cplusplus
)
225 dump_string_field (di
, "lang", language_to_string (DECL_LANGUAGE (t
)));
230 case IDENTIFIER_NODE
:
231 if (IDENTIFIER_OPNAME_P (t
))
233 dump_string_field (di
, "note", "operator");
236 else if (IDENTIFIER_TYPENAME_P (t
))
238 dump_child ("tynm", TREE_TYPE (t
));
244 dump_string_field (di
, "note", "ptrmem");
245 dump_child ("ptd", TYPE_PTRMEM_POINTED_TO_TYPE (t
));
246 dump_child ("cls", TYPE_PTRMEM_CLASS_TYPE (t
));
250 if (TYPE_PTRMEMFUNC_P (t
))
252 dump_string_field (di
, "note", "ptrmem");
253 dump_child ("ptd", TYPE_PTRMEM_POINTED_TO_TYPE (t
));
254 dump_child ("cls", TYPE_PTRMEM_CLASS_TYPE (t
));
260 /* Is it a type used as a base? */
261 if (TYPE_CONTEXT (t
) && TREE_CODE (TYPE_CONTEXT (t
)) == TREE_CODE (t
)
262 && CLASSTYPE_AS_BASE (TYPE_CONTEXT (t
)) == t
)
264 dump_child ("bfld", TYPE_CONTEXT (t
));
268 if (! MAYBE_CLASS_TYPE_P (t
))
271 dump_child ("vfld", TYPE_VFIELD (t
));
272 if (CLASSTYPE_TEMPLATE_SPECIALIZATION(t
))
273 dump_string(di
, "spec");
275 if (!dump_flag (di
, TDF_SLIM
, t
) && TYPE_BINFO (t
))
281 for (binfo
= TYPE_BINFO (t
), i
= 0;
282 BINFO_BASE_ITERATE (binfo
, i
, base_binfo
); ++i
)
284 dump_child ("base", BINFO_TYPE (base_binfo
));
285 if (BINFO_VIRTUAL_P (base_binfo
))
286 dump_string_field (di
, "spec", "virt");
287 dump_access (di
, base_binfo
);
294 if (DECL_MUTABLE_P (t
))
295 dump_string_field (di
, "spec", "mutable");
299 if (TREE_CODE (CP_DECL_CONTEXT (t
)) == RECORD_TYPE
)
301 if (TREE_STATIC (t
) && !TREE_PUBLIC (t
))
302 dump_string_field (di
, "link", "static");
306 if (!DECL_THUNK_P (t
))
308 if (DECL_OVERLOADED_OPERATOR_P (t
)) {
309 dump_string_field (di
, "note", "operator");
312 if (DECL_FUNCTION_MEMBER_P (t
))
314 dump_string_field (di
, "note", "member");
317 if (DECL_PURE_VIRTUAL_P (t
))
318 dump_string_field (di
, "spec", "pure");
319 if (DECL_VIRTUAL_P (t
))
320 dump_string_field (di
, "spec", "virt");
321 if (DECL_CONSTRUCTOR_P (t
))
322 dump_string_field (di
, "note", "constructor");
323 if (DECL_DESTRUCTOR_P (t
))
324 dump_string_field (di
, "note", "destructor");
325 if (DECL_CONV_FN_P (t
))
326 dump_string_field (di
, "note", "conversion");
327 if (DECL_GLOBAL_CTOR_P (t
))
328 dump_string_field (di
, "note", "global init");
329 if (DECL_GLOBAL_DTOR_P (t
))
330 dump_string_field (di
, "note", "global fini");
331 if (DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (t
))
332 dump_string_field (di
, "note", "pseudo tmpl");
336 tree virt
= THUNK_VIRTUAL_OFFSET (t
);
338 dump_string_field (di
, "note", "thunk");
339 if (DECL_THIS_THUNK_P (t
))
340 dump_string_field (di
, "note", "this adjusting");
343 dump_string_field (di
, "note", "result adjusting");
345 virt
= BINFO_VPTR_FIELD (virt
);
347 dump_int (di
, "fixd", THUNK_FIXED_OFFSET (t
));
349 dump_int (di
, "virt", tree_to_shwi (virt
));
350 dump_child ("fn", DECL_INITIAL (t
));
355 if (DECL_NAMESPACE_ALIAS (t
))
356 dump_child ("alis", DECL_NAMESPACE_ALIAS (t
));
357 else if (!dump_flag (di
, TDF_SLIM
, t
))
358 dump_child ("dcls", cp_namespace_decls (t
));
362 dump_child ("rslt", DECL_TEMPLATE_RESULT (t
));
363 dump_child ("inst", DECL_TEMPLATE_INSTANTIATIONS (t
));
364 dump_child ("spcs", DECL_TEMPLATE_SPECIALIZATIONS (t
));
365 dump_child ("prms", DECL_TEMPLATE_PARMS (t
));
369 dump_child ("crnt", OVL_CURRENT (t
));
370 dump_child ("chan", OVL_CHAIN (t
));
376 dump_string_field (di
, "note", "cleanup");
377 dump_child ("body", TRY_STMTS (t
));
378 dump_child ("hdlr", TRY_HANDLERS (t
));
383 dump_child ("body", EH_SPEC_STMTS (t
));
384 dump_child ("raises", EH_SPEC_RAISES (t
));
388 dump_child ("clas", PTRMEM_CST_CLASS (t
));
389 dump_child ("mbr", PTRMEM_CST_MEMBER (t
));
393 /* These nodes are unary, but do not have code class `1'. */
394 dump_child ("op 0", TREE_OPERAND (t
, 0));
401 aggr_init_expr_arg_iterator iter
;
402 dump_int (di
, "ctor", AGGR_INIT_VIA_CTOR_P (t
));
403 dump_child ("fn", AGGR_INIT_EXPR_FN (t
));
404 FOR_EACH_AGGR_INIT_EXPR_ARG (arg
, iter
, t
)
407 sprintf (buffer
, "%u", i
);
408 dump_child (buffer
, arg
);
411 dump_child ("decl", AGGR_INIT_EXPR_SLOT (t
));
417 dump_child ("parm", HANDLER_PARMS (t
));
418 dump_child ("body", HANDLER_BODY (t
));
421 case MUST_NOT_THROW_EXPR
:
423 dump_child ("body", TREE_OPERAND (t
, 0));
424 dump_child ("cond", MUST_NOT_THROW_COND (t
));
429 dump_child ("nmsp", USING_STMT_NAMESPACE (t
));
434 dump_child ("decl", CLEANUP_DECL (t
));
435 dump_child ("expr", CLEANUP_EXPR (t
));
436 dump_child ("body", CLEANUP_BODY (t
));
441 dump_child ("cond", IF_COND (t
));
442 dump_child ("then", THEN_CLAUSE (t
));
443 dump_child ("else", ELSE_CLAUSE (t
));
453 dump_child ("body", DO_BODY (t
));
454 dump_child ("cond", DO_COND (t
));
459 dump_child ("init", FOR_INIT_STMT (t
));
460 dump_child ("cond", FOR_COND (t
));
461 dump_child ("expr", FOR_EXPR (t
));
462 dump_child ("body", FOR_BODY (t
));
467 dump_child ("decl", RANGE_FOR_DECL (t
));
468 dump_child ("expr", RANGE_FOR_EXPR (t
));
469 dump_child ("body", RANGE_FOR_BODY (t
));
474 dump_child ("cond", SWITCH_STMT_COND (t
));
475 dump_child ("body", SWITCH_STMT_BODY (t
));
480 dump_child ("cond", WHILE_COND (t
));
481 dump_child ("body", WHILE_BODY (t
));
485 dump_child ("stmt", STMT_EXPR_STMT (t
));
490 dump_child ("expr", EXPR_STMT_EXPR (t
));
497 return c_dump_tree (di
, t
);