Some fixes for profile test cases for autofdo
[official-gcc.git] / gcc / cp / dump.c
blob12c25492e957b25a71abeb5d91630e1f10e5caed
1 /* Tree-dumping functionality for intermediate representation.
2 Copyright (C) 1999-2016 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)
10 any later version.
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/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "cp-tree.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
32 with T. */
34 static void
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");
41 else
42 dump_string_field (di, "accs", "pub");
45 /* Dump a representation of the specific operator for an overloaded
46 operator associated with node t. */
48 static void
49 dump_op (dump_info_p di, tree t)
51 switch (DECL_OVERLOADED_OPERATOR_P (t)) {
52 case NEW_EXPR:
53 dump_string (di, "new");
54 break;
55 case VEC_NEW_EXPR:
56 dump_string (di, "vecnew");
57 break;
58 case DELETE_EXPR:
59 dump_string (di, "delete");
60 break;
61 case VEC_DELETE_EXPR:
62 dump_string (di, "vecdelete");
63 break;
64 case UNARY_PLUS_EXPR:
65 dump_string (di, "pos");
66 break;
67 case NEGATE_EXPR:
68 dump_string (di, "neg");
69 break;
70 case ADDR_EXPR:
71 dump_string (di, "addr");
72 break;
73 case INDIRECT_REF:
74 dump_string(di, "deref");
75 break;
76 case BIT_NOT_EXPR:
77 dump_string(di, "not");
78 break;
79 case TRUTH_NOT_EXPR:
80 dump_string(di, "lnot");
81 break;
82 case PREINCREMENT_EXPR:
83 dump_string(di, "preinc");
84 break;
85 case PREDECREMENT_EXPR:
86 dump_string(di, "predec");
87 break;
88 case PLUS_EXPR:
89 if (DECL_ASSIGNMENT_OPERATOR_P (t))
90 dump_string (di, "plusassign");
91 else
92 dump_string(di, "plus");
93 break;
94 case MINUS_EXPR:
95 if (DECL_ASSIGNMENT_OPERATOR_P (t))
96 dump_string (di, "minusassign");
97 else
98 dump_string(di, "minus");
99 break;
100 case MULT_EXPR:
101 if (DECL_ASSIGNMENT_OPERATOR_P (t))
102 dump_string (di, "multassign");
103 else
104 dump_string (di, "mult");
105 break;
106 case TRUNC_DIV_EXPR:
107 if (DECL_ASSIGNMENT_OPERATOR_P (t))
108 dump_string (di, "divassign");
109 else
110 dump_string (di, "div");
111 break;
112 case TRUNC_MOD_EXPR:
113 if (DECL_ASSIGNMENT_OPERATOR_P (t))
114 dump_string (di, "modassign");
115 else
116 dump_string (di, "mod");
117 break;
118 case BIT_AND_EXPR:
119 if (DECL_ASSIGNMENT_OPERATOR_P (t))
120 dump_string (di, "andassign");
121 else
122 dump_string (di, "and");
123 break;
124 case BIT_IOR_EXPR:
125 if (DECL_ASSIGNMENT_OPERATOR_P (t))
126 dump_string (di, "orassign");
127 else
128 dump_string (di, "or");
129 break;
130 case BIT_XOR_EXPR:
131 if (DECL_ASSIGNMENT_OPERATOR_P (t))
132 dump_string (di, "xorassign");
133 else
134 dump_string (di, "xor");
135 break;
136 case LSHIFT_EXPR:
137 if (DECL_ASSIGNMENT_OPERATOR_P (t))
138 dump_string (di, "lshiftassign");
139 else
140 dump_string (di, "lshift");
141 break;
142 case RSHIFT_EXPR:
143 if (DECL_ASSIGNMENT_OPERATOR_P (t))
144 dump_string (di, "rshiftassign");
145 else
146 dump_string (di, "rshift");
147 break;
148 case EQ_EXPR:
149 dump_string (di, "eq");
150 break;
151 case NE_EXPR:
152 dump_string (di, "ne");
153 break;
154 case LT_EXPR:
155 dump_string (di, "lt");
156 break;
157 case GT_EXPR:
158 dump_string (di, "gt");
159 break;
160 case LE_EXPR:
161 dump_string (di, "le");
162 break;
163 case GE_EXPR:
164 dump_string (di, "ge");
165 break;
166 case TRUTH_ANDIF_EXPR:
167 dump_string (di, "land");
168 break;
169 case TRUTH_ORIF_EXPR:
170 dump_string (di, "lor");
171 break;
172 case COMPOUND_EXPR:
173 dump_string (di, "compound");
174 break;
175 case MEMBER_REF:
176 dump_string (di, "memref");
177 break;
178 case COMPONENT_REF:
179 dump_string (di, "ref");
180 break;
181 case ARRAY_REF:
182 dump_string (di, "subs");
183 break;
184 case POSTINCREMENT_EXPR:
185 dump_string (di, "postinc");
186 break;
187 case POSTDECREMENT_EXPR:
188 dump_string (di, "postdec");
189 break;
190 case CALL_EXPR:
191 dump_string (di, "call");
192 break;
193 case NOP_EXPR:
194 if (DECL_ASSIGNMENT_OPERATOR_P (t))
195 dump_string (di, "assign");
196 break;
197 default:
198 break;
202 /* Dump information common to statements from STMT. */
204 static void
205 dump_stmt (dump_info_p di, const_tree t)
207 if (EXPR_HAS_LOCATION (t))
208 dump_int (di, "line", EXPR_LINENO (t));
211 bool
212 cp_dump_tree (void* dump_info, tree t)
214 enum tree_code code;
215 dump_info_p di = (dump_info_p) dump_info;
217 /* Figure out what kind of node this is. */
218 code = TREE_CODE (t);
220 if (DECL_P (t))
222 if (DECL_LANG_SPECIFIC (t) && DECL_LANGUAGE (t) != lang_cplusplus)
223 dump_string_field (di, "lang", language_to_string (DECL_LANGUAGE (t)));
226 switch (code)
228 case IDENTIFIER_NODE:
229 if (IDENTIFIER_OPNAME_P (t))
231 dump_string_field (di, "note", "operator");
232 return true;
234 else if (IDENTIFIER_TYPENAME_P (t))
236 dump_child ("tynm", TREE_TYPE (t));
237 return true;
239 break;
241 case OFFSET_TYPE:
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));
245 return true;
247 case RECORD_TYPE:
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));
253 return true;
255 /* Fall through. */
257 case UNION_TYPE:
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));
263 return true;
266 if (! MAYBE_CLASS_TYPE_P (t))
267 break;
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))
275 int i;
276 tree binfo;
277 tree base_binfo;
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);
288 break;
290 case FIELD_DECL:
291 dump_access (di, t);
292 if (DECL_MUTABLE_P (t))
293 dump_string_field (di, "spec", "mutable");
294 break;
296 case VAR_DECL:
297 if (TREE_CODE (CP_DECL_CONTEXT (t)) == RECORD_TYPE)
298 dump_access (di, t);
299 if (TREE_STATIC (t) && !TREE_PUBLIC (t))
300 dump_string_field (di, "link", "static");
301 break;
303 case FUNCTION_DECL:
304 if (!DECL_THUNK_P (t))
306 if (DECL_OVERLOADED_OPERATOR_P (t)) {
307 dump_string_field (di, "note", "operator");
308 dump_op (di, t);
310 if (DECL_FUNCTION_MEMBER_P (t))
312 dump_string_field (di, "note", "member");
313 dump_access (di, t);
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");
332 else
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");
339 else
341 dump_string_field (di, "note", "result adjusting");
342 if (virt)
343 virt = BINFO_VPTR_FIELD (virt);
345 dump_int (di, "fixd", THUNK_FIXED_OFFSET (t));
346 if (virt)
347 dump_int (di, "virt", tree_to_shwi (virt));
348 dump_child ("fn", DECL_INITIAL (t));
350 break;
352 case NAMESPACE_DECL:
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));
357 break;
359 case TEMPLATE_DECL:
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));
364 break;
366 case OVERLOAD:
367 dump_child ("crnt", OVL_CURRENT (t));
368 dump_child ("chan", OVL_CHAIN (t));
369 break;
371 case TRY_BLOCK:
372 dump_stmt (di, t);
373 if (CLEANUP_P (t))
374 dump_string_field (di, "note", "cleanup");
375 dump_child ("body", TRY_STMTS (t));
376 dump_child ("hdlr", TRY_HANDLERS (t));
377 break;
379 case EH_SPEC_BLOCK:
380 dump_stmt (di, t);
381 dump_child ("body", EH_SPEC_STMTS (t));
382 dump_child ("raises", EH_SPEC_RAISES (t));
383 break;
385 case PTRMEM_CST:
386 dump_child ("clas", PTRMEM_CST_CLASS (t));
387 dump_child ("mbr", PTRMEM_CST_MEMBER (t));
388 break;
390 case THROW_EXPR:
391 /* These nodes are unary, but do not have code class `1'. */
392 dump_child ("op 0", TREE_OPERAND (t, 0));
393 break;
395 case AGGR_INIT_EXPR:
397 int i = 0;
398 tree arg;
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)
404 char buffer[32];
405 sprintf (buffer, "%u", i);
406 dump_child (buffer, arg);
407 i++;
409 dump_child ("decl", AGGR_INIT_EXPR_SLOT (t));
411 break;
413 case HANDLER:
414 dump_stmt (di, t);
415 dump_child ("parm", HANDLER_PARMS (t));
416 dump_child ("body", HANDLER_BODY (t));
417 break;
419 case MUST_NOT_THROW_EXPR:
420 dump_stmt (di, t);
421 dump_child ("body", TREE_OPERAND (t, 0));
422 dump_child ("cond", MUST_NOT_THROW_COND (t));
423 break;
425 case USING_STMT:
426 dump_stmt (di, t);
427 dump_child ("nmsp", USING_STMT_NAMESPACE (t));
428 break;
430 case CLEANUP_STMT:
431 dump_stmt (di, t);
432 dump_child ("decl", CLEANUP_DECL (t));
433 dump_child ("expr", CLEANUP_EXPR (t));
434 dump_child ("body", CLEANUP_BODY (t));
435 break;
437 case IF_STMT:
438 dump_stmt (di, t);
439 dump_child ("cond", IF_COND (t));
440 dump_child ("then", THEN_CLAUSE (t));
441 dump_child ("else", ELSE_CLAUSE (t));
442 break;
444 case BREAK_STMT:
445 case CONTINUE_STMT:
446 dump_stmt (di, t);
447 break;
449 case DO_STMT:
450 dump_stmt (di, t);
451 dump_child ("body", DO_BODY (t));
452 dump_child ("cond", DO_COND (t));
453 break;
455 case FOR_STMT:
456 dump_stmt (di, 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));
461 break;
463 case RANGE_FOR_STMT:
464 dump_stmt (di, 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));
468 break;
470 case SWITCH_STMT:
471 dump_stmt (di, t);
472 dump_child ("cond", SWITCH_STMT_COND (t));
473 dump_child ("body", SWITCH_STMT_BODY (t));
474 break;
476 case WHILE_STMT:
477 dump_stmt (di, t);
478 dump_child ("cond", WHILE_COND (t));
479 dump_child ("body", WHILE_BODY (t));
480 break;
482 case STMT_EXPR:
483 dump_child ("stmt", STMT_EXPR_STMT (t));
484 break;
486 case EXPR_STMT:
487 dump_stmt (di, t);
488 dump_child ("expr", EXPR_STMT_EXPR (t));
489 break;
491 default:
492 break;
495 return c_dump_tree (di, t);