Concretize gimple_cond_set_{lhs|rhs}
[official-gcc.git] / gcc / cp / dump.c
blob70b047a9072f094952889d9cc1c8168d90200343
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)
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 "tm.h"
25 #include "tree.h"
26 #include "cp-tree.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
34 with T. */
36 static void
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");
43 else
44 dump_string_field (di, "accs", "pub");
47 /* Dump a representation of the specific operator for an overloaded
48 operator associated with node t. */
50 static void
51 dump_op (dump_info_p di, tree t)
53 switch (DECL_OVERLOADED_OPERATOR_P (t)) {
54 case NEW_EXPR:
55 dump_string (di, "new");
56 break;
57 case VEC_NEW_EXPR:
58 dump_string (di, "vecnew");
59 break;
60 case DELETE_EXPR:
61 dump_string (di, "delete");
62 break;
63 case VEC_DELETE_EXPR:
64 dump_string (di, "vecdelete");
65 break;
66 case UNARY_PLUS_EXPR:
67 dump_string (di, "pos");
68 break;
69 case NEGATE_EXPR:
70 dump_string (di, "neg");
71 break;
72 case ADDR_EXPR:
73 dump_string (di, "addr");
74 break;
75 case INDIRECT_REF:
76 dump_string(di, "deref");
77 break;
78 case BIT_NOT_EXPR:
79 dump_string(di, "not");
80 break;
81 case TRUTH_NOT_EXPR:
82 dump_string(di, "lnot");
83 break;
84 case PREINCREMENT_EXPR:
85 dump_string(di, "preinc");
86 break;
87 case PREDECREMENT_EXPR:
88 dump_string(di, "predec");
89 break;
90 case PLUS_EXPR:
91 if (DECL_ASSIGNMENT_OPERATOR_P (t))
92 dump_string (di, "plusassign");
93 else
94 dump_string(di, "plus");
95 break;
96 case MINUS_EXPR:
97 if (DECL_ASSIGNMENT_OPERATOR_P (t))
98 dump_string (di, "minusassign");
99 else
100 dump_string(di, "minus");
101 break;
102 case MULT_EXPR:
103 if (DECL_ASSIGNMENT_OPERATOR_P (t))
104 dump_string (di, "multassign");
105 else
106 dump_string (di, "mult");
107 break;
108 case TRUNC_DIV_EXPR:
109 if (DECL_ASSIGNMENT_OPERATOR_P (t))
110 dump_string (di, "divassign");
111 else
112 dump_string (di, "div");
113 break;
114 case TRUNC_MOD_EXPR:
115 if (DECL_ASSIGNMENT_OPERATOR_P (t))
116 dump_string (di, "modassign");
117 else
118 dump_string (di, "mod");
119 break;
120 case BIT_AND_EXPR:
121 if (DECL_ASSIGNMENT_OPERATOR_P (t))
122 dump_string (di, "andassign");
123 else
124 dump_string (di, "and");
125 break;
126 case BIT_IOR_EXPR:
127 if (DECL_ASSIGNMENT_OPERATOR_P (t))
128 dump_string (di, "orassign");
129 else
130 dump_string (di, "or");
131 break;
132 case BIT_XOR_EXPR:
133 if (DECL_ASSIGNMENT_OPERATOR_P (t))
134 dump_string (di, "xorassign");
135 else
136 dump_string (di, "xor");
137 break;
138 case LSHIFT_EXPR:
139 if (DECL_ASSIGNMENT_OPERATOR_P (t))
140 dump_string (di, "lshiftassign");
141 else
142 dump_string (di, "lshift");
143 break;
144 case RSHIFT_EXPR:
145 if (DECL_ASSIGNMENT_OPERATOR_P (t))
146 dump_string (di, "rshiftassign");
147 else
148 dump_string (di, "rshift");
149 break;
150 case EQ_EXPR:
151 dump_string (di, "eq");
152 break;
153 case NE_EXPR:
154 dump_string (di, "ne");
155 break;
156 case LT_EXPR:
157 dump_string (di, "lt");
158 break;
159 case GT_EXPR:
160 dump_string (di, "gt");
161 break;
162 case LE_EXPR:
163 dump_string (di, "le");
164 break;
165 case GE_EXPR:
166 dump_string (di, "ge");
167 break;
168 case TRUTH_ANDIF_EXPR:
169 dump_string (di, "land");
170 break;
171 case TRUTH_ORIF_EXPR:
172 dump_string (di, "lor");
173 break;
174 case COMPOUND_EXPR:
175 dump_string (di, "compound");
176 break;
177 case MEMBER_REF:
178 dump_string (di, "memref");
179 break;
180 case COMPONENT_REF:
181 dump_string (di, "ref");
182 break;
183 case ARRAY_REF:
184 dump_string (di, "subs");
185 break;
186 case POSTINCREMENT_EXPR:
187 dump_string (di, "postinc");
188 break;
189 case POSTDECREMENT_EXPR:
190 dump_string (di, "postdec");
191 break;
192 case CALL_EXPR:
193 dump_string (di, "call");
194 break;
195 case NOP_EXPR:
196 if (DECL_ASSIGNMENT_OPERATOR_P (t))
197 dump_string (di, "assign");
198 break;
199 default:
200 break;
204 /* Dump information common to statements from STMT. */
206 static void
207 dump_stmt (dump_info_p di, const_tree t)
209 if (EXPR_HAS_LOCATION (t))
210 dump_int (di, "line", EXPR_LINENO (t));
213 bool
214 cp_dump_tree (void* dump_info, tree t)
216 enum tree_code code;
217 dump_info_p di = (dump_info_p) dump_info;
219 /* Figure out what kind of node this is. */
220 code = TREE_CODE (t);
222 if (DECL_P (t))
224 if (DECL_LANG_SPECIFIC (t) && DECL_LANGUAGE (t) != lang_cplusplus)
225 dump_string_field (di, "lang", language_to_string (DECL_LANGUAGE (t)));
228 switch (code)
230 case IDENTIFIER_NODE:
231 if (IDENTIFIER_OPNAME_P (t))
233 dump_string_field (di, "note", "operator");
234 return true;
236 else if (IDENTIFIER_TYPENAME_P (t))
238 dump_child ("tynm", TREE_TYPE (t));
239 return true;
241 break;
243 case OFFSET_TYPE:
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));
247 return true;
249 case RECORD_TYPE:
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));
255 return true;
257 /* Fall through. */
259 case UNION_TYPE:
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));
265 return true;
268 if (! MAYBE_CLASS_TYPE_P (t))
269 break;
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))
277 int i;
278 tree binfo;
279 tree base_binfo;
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);
290 break;
292 case FIELD_DECL:
293 dump_access (di, t);
294 if (DECL_MUTABLE_P (t))
295 dump_string_field (di, "spec", "mutable");
296 break;
298 case VAR_DECL:
299 if (TREE_CODE (CP_DECL_CONTEXT (t)) == RECORD_TYPE)
300 dump_access (di, t);
301 if (TREE_STATIC (t) && !TREE_PUBLIC (t))
302 dump_string_field (di, "link", "static");
303 break;
305 case FUNCTION_DECL:
306 if (!DECL_THUNK_P (t))
308 if (DECL_OVERLOADED_OPERATOR_P (t)) {
309 dump_string_field (di, "note", "operator");
310 dump_op (di, t);
312 if (DECL_FUNCTION_MEMBER_P (t))
314 dump_string_field (di, "note", "member");
315 dump_access (di, t);
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");
334 else
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");
341 else
343 dump_string_field (di, "note", "result adjusting");
344 if (virt)
345 virt = BINFO_VPTR_FIELD (virt);
347 dump_int (di, "fixd", THUNK_FIXED_OFFSET (t));
348 if (virt)
349 dump_int (di, "virt", tree_to_shwi (virt));
350 dump_child ("fn", DECL_INITIAL (t));
352 break;
354 case NAMESPACE_DECL:
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));
359 break;
361 case TEMPLATE_DECL:
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));
366 break;
368 case OVERLOAD:
369 dump_child ("crnt", OVL_CURRENT (t));
370 dump_child ("chan", OVL_CHAIN (t));
371 break;
373 case TRY_BLOCK:
374 dump_stmt (di, t);
375 if (CLEANUP_P (t))
376 dump_string_field (di, "note", "cleanup");
377 dump_child ("body", TRY_STMTS (t));
378 dump_child ("hdlr", TRY_HANDLERS (t));
379 break;
381 case EH_SPEC_BLOCK:
382 dump_stmt (di, t);
383 dump_child ("body", EH_SPEC_STMTS (t));
384 dump_child ("raises", EH_SPEC_RAISES (t));
385 break;
387 case PTRMEM_CST:
388 dump_child ("clas", PTRMEM_CST_CLASS (t));
389 dump_child ("mbr", PTRMEM_CST_MEMBER (t));
390 break;
392 case THROW_EXPR:
393 /* These nodes are unary, but do not have code class `1'. */
394 dump_child ("op 0", TREE_OPERAND (t, 0));
395 break;
397 case AGGR_INIT_EXPR:
399 int i = 0;
400 tree arg;
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)
406 char buffer[32];
407 sprintf (buffer, "%u", i);
408 dump_child (buffer, arg);
409 i++;
411 dump_child ("decl", AGGR_INIT_EXPR_SLOT (t));
413 break;
415 case HANDLER:
416 dump_stmt (di, t);
417 dump_child ("parm", HANDLER_PARMS (t));
418 dump_child ("body", HANDLER_BODY (t));
419 break;
421 case MUST_NOT_THROW_EXPR:
422 dump_stmt (di, t);
423 dump_child ("body", TREE_OPERAND (t, 0));
424 dump_child ("cond", MUST_NOT_THROW_COND (t));
425 break;
427 case USING_STMT:
428 dump_stmt (di, t);
429 dump_child ("nmsp", USING_STMT_NAMESPACE (t));
430 break;
432 case CLEANUP_STMT:
433 dump_stmt (di, t);
434 dump_child ("decl", CLEANUP_DECL (t));
435 dump_child ("expr", CLEANUP_EXPR (t));
436 dump_child ("body", CLEANUP_BODY (t));
437 break;
439 case IF_STMT:
440 dump_stmt (di, t);
441 dump_child ("cond", IF_COND (t));
442 dump_child ("then", THEN_CLAUSE (t));
443 dump_child ("else", ELSE_CLAUSE (t));
444 break;
446 case BREAK_STMT:
447 case CONTINUE_STMT:
448 dump_stmt (di, t);
449 break;
451 case DO_STMT:
452 dump_stmt (di, t);
453 dump_child ("body", DO_BODY (t));
454 dump_child ("cond", DO_COND (t));
455 break;
457 case FOR_STMT:
458 dump_stmt (di, 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));
463 break;
465 case RANGE_FOR_STMT:
466 dump_stmt (di, 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));
470 break;
472 case SWITCH_STMT:
473 dump_stmt (di, t);
474 dump_child ("cond", SWITCH_STMT_COND (t));
475 dump_child ("body", SWITCH_STMT_BODY (t));
476 break;
478 case WHILE_STMT:
479 dump_stmt (di, t);
480 dump_child ("cond", WHILE_COND (t));
481 dump_child ("body", WHILE_BODY (t));
482 break;
484 case STMT_EXPR:
485 dump_child ("stmt", STMT_EXPR_STMT (t));
486 break;
488 case EXPR_STMT:
489 dump_stmt (di, t);
490 dump_child ("expr", EXPR_STMT_EXPR (t));
491 break;
493 default:
494 break;
497 return c_dump_tree (di, t);