c-objc-common.c (c_tree_printer): Tidy.
[official-gcc.git] / gcc / tree-pretty-print.c
blob69e400607271d459f6f5769492be13d9d76cb985
1 /* Pretty formatting of GENERIC trees in C syntax.
2 Copyright (C) 2001-2013 Free Software Foundation, Inc.
3 Adapted from c-pretty-print.c by Diego Novillo <dnovillo@redhat.com>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 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 "tree-pretty-print.h"
27 #include "hashtab.h"
28 #include "tree-flow.h"
29 #include "langhooks.h"
30 #include "tree-iterator.h"
31 #include "tree-chrec.h"
32 #include "dumpfile.h"
33 #include "value-prof.h"
34 #include "predict.h"
36 #include <new> // For placement-new.
38 /* Local functions, macros and variables. */
39 static const char *op_symbol (const_tree);
40 static void pretty_print_string (pretty_printer *, const char*);
41 static void newline_and_indent (pretty_printer *, int);
42 static void maybe_init_pretty_print (FILE *);
43 static void print_struct_decl (pretty_printer *, const_tree, int, int);
44 static void do_niy (pretty_printer *, const_tree);
46 #define INDENT(SPACE) do { \
47 int i; for (i = 0; i<SPACE; i++) pp_space (buffer); } while (0)
49 #define NIY do_niy(buffer,node)
51 static pretty_printer buffer;
52 static int initialized = 0;
54 /* Try to print something for an unknown tree code. */
56 static void
57 do_niy (pretty_printer *buffer, const_tree node)
59 int i, len;
61 pp_string (buffer, "<<< Unknown tree: ");
62 pp_string (buffer, tree_code_name[(int) TREE_CODE (node)]);
64 if (EXPR_P (node))
66 len = TREE_OPERAND_LENGTH (node);
67 for (i = 0; i < len; ++i)
69 newline_and_indent (buffer, 2);
70 dump_generic_node (buffer, TREE_OPERAND (node, i), 2, 0, false);
74 pp_string (buffer, " >>>");
77 /* Debugging function to print out a generic expression. */
79 DEBUG_FUNCTION void
80 debug_generic_expr (tree t)
82 print_generic_expr (stderr, t, TDF_VOPS|TDF_MEMSYMS);
83 fprintf (stderr, "\n");
86 /* Debugging function to print out a generic statement. */
88 DEBUG_FUNCTION void
89 debug_generic_stmt (tree t)
91 print_generic_stmt (stderr, t, TDF_VOPS|TDF_MEMSYMS);
92 fprintf (stderr, "\n");
95 /* Debugging function to print out a chain of trees . */
97 DEBUG_FUNCTION void
98 debug_tree_chain (tree t)
100 struct pointer_set_t *seen = pointer_set_create ();
102 while (t)
104 print_generic_expr (stderr, t, TDF_VOPS|TDF_MEMSYMS|TDF_UID);
105 fprintf (stderr, " ");
106 t = TREE_CHAIN (t);
107 if (pointer_set_insert (seen, t))
109 fprintf (stderr, "... [cycled back to ");
110 print_generic_expr (stderr, t, TDF_VOPS|TDF_MEMSYMS|TDF_UID);
111 fprintf (stderr, "]");
112 break;
115 fprintf (stderr, "\n");
117 pointer_set_destroy (seen);
120 /* Prints declaration DECL to the FILE with details specified by FLAGS. */
121 void
122 print_generic_decl (FILE *file, tree decl, int flags)
124 maybe_init_pretty_print (file);
125 print_declaration (&buffer, decl, 2, flags);
126 pp_write_text_to_stream (&buffer);
129 /* Print tree T, and its successors, on file FILE. FLAGS specifies details
130 to show in the dump. See TDF_* in dumpfile.h. */
132 void
133 print_generic_stmt (FILE *file, tree t, int flags)
135 maybe_init_pretty_print (file);
136 dump_generic_node (&buffer, t, 0, flags, true);
137 pp_newline_and_flush (&buffer);
140 /* Print tree T, and its successors, on file FILE. FLAGS specifies details
141 to show in the dump. See TDF_* in dumpfile.h. The output is indented by
142 INDENT spaces. */
144 void
145 print_generic_stmt_indented (FILE *file, tree t, int flags, int indent)
147 int i;
149 maybe_init_pretty_print (file);
151 for (i = 0; i < indent; i++)
152 pp_space (&buffer);
153 dump_generic_node (&buffer, t, indent, flags, true);
154 pp_newline_and_flush (&buffer);
157 /* Print a single expression T on file FILE. FLAGS specifies details to show
158 in the dump. See TDF_* in dumpfile.h. */
160 void
161 print_generic_expr (FILE *file, tree t, int flags)
163 maybe_init_pretty_print (file);
164 dump_generic_node (&buffer, t, 0, flags, false);
165 pp_flush (&buffer);
168 /* Dump the name of a _DECL node and its DECL_UID if TDF_UID is set
169 in FLAGS. */
171 static void
172 dump_decl_name (pretty_printer *buffer, tree node, int flags)
174 if (DECL_NAME (node))
176 if ((flags & TDF_ASMNAME) && DECL_ASSEMBLER_NAME_SET_P (node))
177 pp_tree_identifier (buffer, DECL_ASSEMBLER_NAME (node));
178 else
179 pp_tree_identifier (buffer, DECL_NAME (node));
181 if ((flags & TDF_UID) || DECL_NAME (node) == NULL_TREE)
183 if (TREE_CODE (node) == LABEL_DECL && LABEL_DECL_UID (node) != -1)
184 pp_printf (buffer, "L.%d", (int) LABEL_DECL_UID (node));
185 else if (TREE_CODE (node) == DEBUG_EXPR_DECL)
187 if (flags & TDF_NOUID)
188 pp_string (buffer, "D#xxxx");
189 else
190 pp_printf (buffer, "D#%i", DEBUG_TEMP_UID (node));
192 else
194 char c = TREE_CODE (node) == CONST_DECL ? 'C' : 'D';
195 if (flags & TDF_NOUID)
196 pp_printf (buffer, "%c.xxxx", c);
197 else
198 pp_printf (buffer, "%c.%u", c, DECL_UID (node));
201 if ((flags & TDF_ALIAS) && DECL_PT_UID (node) != DECL_UID (node))
203 if (flags & TDF_NOUID)
204 pp_printf (buffer, "ptD.xxxx");
205 else
206 pp_printf (buffer, "ptD.%u", DECL_PT_UID (node));
210 /* Like the above, but used for pretty printing function calls. */
212 static void
213 dump_function_name (pretty_printer *buffer, tree node, int flags)
215 if (TREE_CODE (node) == NOP_EXPR)
216 node = TREE_OPERAND (node, 0);
217 if (DECL_NAME (node) && (flags & TDF_ASMNAME) == 0)
218 pp_string (buffer, lang_hooks.decl_printable_name (node, 1));
219 else
220 dump_decl_name (buffer, node, flags);
223 /* Dump a function declaration. NODE is the FUNCTION_TYPE. BUFFER, SPC and
224 FLAGS are as in dump_generic_node. */
226 static void
227 dump_function_declaration (pretty_printer *buffer, tree node,
228 int spc, int flags)
230 bool wrote_arg = false;
231 tree arg;
233 pp_space (buffer);
234 pp_left_paren (buffer);
236 /* Print the argument types. */
237 arg = TYPE_ARG_TYPES (node);
238 while (arg && arg != void_list_node && arg != error_mark_node)
240 if (wrote_arg)
242 pp_comma (buffer);
243 pp_space (buffer);
245 wrote_arg = true;
246 dump_generic_node (buffer, TREE_VALUE (arg), spc, flags, false);
247 arg = TREE_CHAIN (arg);
250 /* Drop the trailing void_type_node if we had any previous argument. */
251 if (arg == void_list_node && !wrote_arg)
252 pp_string (buffer, "void");
253 /* Properly dump vararg function types. */
254 else if (!arg && wrote_arg)
255 pp_string (buffer, ", ...");
256 /* Avoid printing any arg for unprototyped functions. */
258 pp_right_paren (buffer);
261 /* Dump the domain associated with an array. */
263 static void
264 dump_array_domain (pretty_printer *buffer, tree domain, int spc, int flags)
266 pp_left_bracket (buffer);
267 if (domain)
269 tree min = TYPE_MIN_VALUE (domain);
270 tree max = TYPE_MAX_VALUE (domain);
272 if (min && max
273 && integer_zerop (min)
274 && host_integerp (max, 0))
275 pp_wide_integer (buffer, TREE_INT_CST_LOW (max) + 1);
276 else
278 if (min)
279 dump_generic_node (buffer, min, spc, flags, false);
280 pp_colon (buffer);
281 if (max)
282 dump_generic_node (buffer, max, spc, flags, false);
285 else
286 pp_string (buffer, "<unknown>");
287 pp_right_bracket (buffer);
291 /* Dump OpenMP clause CLAUSE. BUFFER, CLAUSE, SPC and FLAGS are as in
292 dump_generic_node. */
294 static void
295 dump_omp_clause (pretty_printer *buffer, tree clause, int spc, int flags)
297 const char *name;
299 switch (OMP_CLAUSE_CODE (clause))
301 case OMP_CLAUSE_PRIVATE:
302 name = "private";
303 goto print_remap;
304 case OMP_CLAUSE_SHARED:
305 name = "shared";
306 goto print_remap;
307 case OMP_CLAUSE_FIRSTPRIVATE:
308 name = "firstprivate";
309 goto print_remap;
310 case OMP_CLAUSE_LASTPRIVATE:
311 name = "lastprivate";
312 goto print_remap;
313 case OMP_CLAUSE_COPYIN:
314 name = "copyin";
315 goto print_remap;
316 case OMP_CLAUSE_COPYPRIVATE:
317 name = "copyprivate";
318 goto print_remap;
319 case OMP_CLAUSE_UNIFORM:
320 name = "uniform";
321 goto print_remap;
322 print_remap:
323 pp_string (buffer, name);
324 pp_left_paren (buffer);
325 dump_generic_node (buffer, OMP_CLAUSE_DECL (clause),
326 spc, flags, false);
327 pp_right_paren (buffer);
328 break;
330 case OMP_CLAUSE_REDUCTION:
331 pp_string (buffer, "reduction(");
332 pp_string (buffer, op_symbol_code (OMP_CLAUSE_REDUCTION_CODE (clause)));
333 pp_colon (buffer);
334 dump_generic_node (buffer, OMP_CLAUSE_DECL (clause),
335 spc, flags, false);
336 pp_right_paren (buffer);
337 break;
339 case OMP_CLAUSE_IF:
340 pp_string (buffer, "if(");
341 dump_generic_node (buffer, OMP_CLAUSE_IF_EXPR (clause),
342 spc, flags, false);
343 pp_right_paren (buffer);
344 break;
346 case OMP_CLAUSE_NUM_THREADS:
347 pp_string (buffer, "num_threads(");
348 dump_generic_node (buffer, OMP_CLAUSE_NUM_THREADS_EXPR (clause),
349 spc, flags, false);
350 pp_right_paren (buffer);
351 break;
353 case OMP_CLAUSE_NOWAIT:
354 pp_string (buffer, "nowait");
355 break;
356 case OMP_CLAUSE_ORDERED:
357 pp_string (buffer, "ordered");
358 break;
360 case OMP_CLAUSE_DEFAULT:
361 pp_string (buffer, "default(");
362 switch (OMP_CLAUSE_DEFAULT_KIND (clause))
364 case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
365 break;
366 case OMP_CLAUSE_DEFAULT_SHARED:
367 pp_string (buffer, "shared");
368 break;
369 case OMP_CLAUSE_DEFAULT_NONE:
370 pp_string (buffer, "none");
371 break;
372 case OMP_CLAUSE_DEFAULT_PRIVATE:
373 pp_string (buffer, "private");
374 break;
375 case OMP_CLAUSE_DEFAULT_FIRSTPRIVATE:
376 pp_string (buffer, "firstprivate");
377 break;
378 default:
379 gcc_unreachable ();
381 pp_right_paren (buffer);
382 break;
384 case OMP_CLAUSE_SCHEDULE:
385 pp_string (buffer, "schedule(");
386 switch (OMP_CLAUSE_SCHEDULE_KIND (clause))
388 case OMP_CLAUSE_SCHEDULE_STATIC:
389 pp_string (buffer, "static");
390 break;
391 case OMP_CLAUSE_SCHEDULE_DYNAMIC:
392 pp_string (buffer, "dynamic");
393 break;
394 case OMP_CLAUSE_SCHEDULE_GUIDED:
395 pp_string (buffer, "guided");
396 break;
397 case OMP_CLAUSE_SCHEDULE_RUNTIME:
398 pp_string (buffer, "runtime");
399 break;
400 case OMP_CLAUSE_SCHEDULE_AUTO:
401 pp_string (buffer, "auto");
402 break;
403 default:
404 gcc_unreachable ();
406 if (OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clause))
408 pp_comma (buffer);
409 dump_generic_node (buffer,
410 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clause),
411 spc, flags, false);
413 pp_right_paren (buffer);
414 break;
416 case OMP_CLAUSE_UNTIED:
417 pp_string (buffer, "untied");
418 break;
420 case OMP_CLAUSE_COLLAPSE:
421 pp_string (buffer, "collapse(");
422 dump_generic_node (buffer,
423 OMP_CLAUSE_COLLAPSE_EXPR (clause),
424 spc, flags, false);
425 pp_right_paren (buffer);
426 break;
428 case OMP_CLAUSE_FINAL:
429 pp_string (buffer, "final(");
430 dump_generic_node (buffer, OMP_CLAUSE_FINAL_EXPR (clause),
431 spc, flags, false);
432 pp_right_paren (buffer);
433 break;
435 case OMP_CLAUSE_MERGEABLE:
436 pp_string (buffer, "mergeable");
437 break;
439 case OMP_CLAUSE_LINEAR:
440 pp_string (buffer, "linear(");
441 dump_generic_node (buffer, OMP_CLAUSE_DECL (clause),
442 spc, flags, false);
443 pp_character (buffer, ':');
444 dump_generic_node (buffer, OMP_CLAUSE_LINEAR_STEP (clause),
445 spc, flags, false);
446 pp_character (buffer, ')');
447 break;
449 case OMP_CLAUSE_SAFELEN:
450 pp_string (buffer, "safelen(");
451 dump_generic_node (buffer, OMP_CLAUSE_SAFELEN_EXPR (clause),
452 spc, flags, false);
453 pp_character (buffer, ')');
454 break;
456 case OMP_CLAUSE__SIMDUID_:
457 pp_string (buffer, "_simduid_(");
458 dump_generic_node (buffer, OMP_CLAUSE__SIMDUID__DECL (clause),
459 spc, flags, false);
460 pp_character (buffer, ')');
461 break;
463 default:
464 /* Should never happen. */
465 dump_generic_node (buffer, clause, spc, flags, false);
466 break;
471 /* Dump the list of OpenMP clauses. BUFFER, SPC and FLAGS are as in
472 dump_generic_node. */
474 void
475 dump_omp_clauses (pretty_printer *buffer, tree clause, int spc, int flags)
477 if (clause == NULL)
478 return;
480 pp_space (buffer);
481 while (1)
483 dump_omp_clause (buffer, clause, spc, flags);
484 clause = OMP_CLAUSE_CHAIN (clause);
485 if (clause == NULL)
486 return;
487 pp_space (buffer);
492 /* Dump location LOC to BUFFER. */
494 static void
495 dump_location (pretty_printer *buffer, location_t loc)
497 expanded_location xloc = expand_location (loc);
499 pp_left_bracket (buffer);
500 if (xloc.file)
502 pp_string (buffer, xloc.file);
503 pp_string (buffer, " : ");
505 pp_decimal_int (buffer, xloc.line);
506 pp_string (buffer, "] ");
510 /* Dump lexical block BLOCK. BUFFER, SPC and FLAGS are as in
511 dump_generic_node. */
513 static void
514 dump_block_node (pretty_printer *buffer, tree block, int spc, int flags)
516 tree t;
518 pp_printf (buffer, "BLOCK #%d ", BLOCK_NUMBER (block));
520 if (flags & TDF_ADDRESS)
521 pp_printf (buffer, "[%p] ", (void *) block);
523 if (BLOCK_ABSTRACT (block))
524 pp_string (buffer, "[abstract] ");
526 if (TREE_ASM_WRITTEN (block))
527 pp_string (buffer, "[written] ");
529 if (flags & TDF_SLIM)
530 return;
532 if (BLOCK_SOURCE_LOCATION (block))
533 dump_location (buffer, BLOCK_SOURCE_LOCATION (block));
535 newline_and_indent (buffer, spc + 2);
537 if (BLOCK_SUPERCONTEXT (block))
539 pp_string (buffer, "SUPERCONTEXT: ");
540 dump_generic_node (buffer, BLOCK_SUPERCONTEXT (block), 0,
541 flags | TDF_SLIM, false);
542 newline_and_indent (buffer, spc + 2);
545 if (BLOCK_SUBBLOCKS (block))
547 pp_string (buffer, "SUBBLOCKS: ");
548 for (t = BLOCK_SUBBLOCKS (block); t; t = BLOCK_CHAIN (t))
550 dump_generic_node (buffer, t, 0, flags | TDF_SLIM, false);
551 pp_space (buffer);
553 newline_and_indent (buffer, spc + 2);
556 if (BLOCK_CHAIN (block))
558 pp_string (buffer, "SIBLINGS: ");
559 for (t = BLOCK_CHAIN (block); t; t = BLOCK_CHAIN (t))
561 dump_generic_node (buffer, t, 0, flags | TDF_SLIM, false);
562 pp_space (buffer);
564 newline_and_indent (buffer, spc + 2);
567 if (BLOCK_VARS (block))
569 pp_string (buffer, "VARS: ");
570 for (t = BLOCK_VARS (block); t; t = TREE_CHAIN (t))
572 dump_generic_node (buffer, t, 0, flags, false);
573 pp_space (buffer);
575 newline_and_indent (buffer, spc + 2);
578 if (vec_safe_length (BLOCK_NONLOCALIZED_VARS (block)) > 0)
580 unsigned i;
581 vec<tree, va_gc> *nlv = BLOCK_NONLOCALIZED_VARS (block);
583 pp_string (buffer, "NONLOCALIZED_VARS: ");
584 FOR_EACH_VEC_ELT (*nlv, i, t)
586 dump_generic_node (buffer, t, 0, flags, false);
587 pp_space (buffer);
589 newline_and_indent (buffer, spc + 2);
592 if (BLOCK_ABSTRACT_ORIGIN (block))
594 pp_string (buffer, "ABSTRACT_ORIGIN: ");
595 dump_generic_node (buffer, BLOCK_ABSTRACT_ORIGIN (block), 0,
596 flags | TDF_SLIM, false);
597 newline_and_indent (buffer, spc + 2);
600 if (BLOCK_FRAGMENT_ORIGIN (block))
602 pp_string (buffer, "FRAGMENT_ORIGIN: ");
603 dump_generic_node (buffer, BLOCK_FRAGMENT_ORIGIN (block), 0,
604 flags | TDF_SLIM, false);
605 newline_and_indent (buffer, spc + 2);
608 if (BLOCK_FRAGMENT_CHAIN (block))
610 pp_string (buffer, "FRAGMENT_CHAIN: ");
611 for (t = BLOCK_FRAGMENT_CHAIN (block); t; t = BLOCK_FRAGMENT_CHAIN (t))
613 dump_generic_node (buffer, t, 0, flags | TDF_SLIM, false);
614 pp_space (buffer);
616 newline_and_indent (buffer, spc + 2);
621 /* Dump the node NODE on the pretty_printer BUFFER, SPC spaces of
622 indent. FLAGS specifies details to show in the dump (see TDF_* in
623 dumpfile.h). If IS_STMT is true, the object printed is considered
624 to be a statement and it is terminated by ';' if appropriate. */
627 dump_generic_node (pretty_printer *buffer, tree node, int spc, int flags,
628 bool is_stmt)
630 tree type;
631 tree op0, op1;
632 const char *str;
633 bool is_expr;
634 enum tree_code code;
636 if (node == NULL_TREE)
637 return spc;
639 is_expr = EXPR_P (node);
641 if (is_stmt && (flags & TDF_STMTADDR))
642 pp_printf (buffer, "<&%p> ", (void *)node);
644 if ((flags & TDF_LINENO) && EXPR_HAS_LOCATION (node))
645 dump_location (buffer, EXPR_LOCATION (node));
647 code = TREE_CODE (node);
648 switch (code)
650 case ERROR_MARK:
651 pp_string (buffer, "<<< error >>>");
652 break;
654 case IDENTIFIER_NODE:
655 pp_tree_identifier (buffer, node);
656 break;
658 case TREE_LIST:
659 while (node && node != error_mark_node)
661 if (TREE_PURPOSE (node))
663 dump_generic_node (buffer, TREE_PURPOSE (node), spc, flags, false);
664 pp_space (buffer);
666 dump_generic_node (buffer, TREE_VALUE (node), spc, flags, false);
667 node = TREE_CHAIN (node);
668 if (node && TREE_CODE (node) == TREE_LIST)
670 pp_comma (buffer);
671 pp_space (buffer);
674 break;
676 case TREE_BINFO:
677 dump_generic_node (buffer, BINFO_TYPE (node), spc, flags, false);
678 break;
680 case TREE_VEC:
682 size_t i;
683 if (TREE_VEC_LENGTH (node) > 0)
685 size_t len = TREE_VEC_LENGTH (node);
686 for (i = 0; i < len - 1; i++)
688 dump_generic_node (buffer, TREE_VEC_ELT (node, i), spc, flags,
689 false);
690 pp_comma (buffer);
691 pp_space (buffer);
693 dump_generic_node (buffer, TREE_VEC_ELT (node, len - 1), spc,
694 flags, false);
697 break;
699 case VOID_TYPE:
700 case INTEGER_TYPE:
701 case REAL_TYPE:
702 case FIXED_POINT_TYPE:
703 case COMPLEX_TYPE:
704 case VECTOR_TYPE:
705 case ENUMERAL_TYPE:
706 case BOOLEAN_TYPE:
708 unsigned int quals = TYPE_QUALS (node);
709 enum tree_code_class tclass;
711 if (quals & TYPE_QUAL_CONST)
712 pp_string (buffer, "const ");
713 else if (quals & TYPE_QUAL_VOLATILE)
714 pp_string (buffer, "volatile ");
715 else if (quals & TYPE_QUAL_RESTRICT)
716 pp_string (buffer, "restrict ");
718 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
720 pp_string (buffer, "<address-space-");
721 pp_decimal_int (buffer, TYPE_ADDR_SPACE (node));
722 pp_string (buffer, "> ");
725 tclass = TREE_CODE_CLASS (TREE_CODE (node));
727 if (tclass == tcc_declaration)
729 if (DECL_NAME (node))
730 dump_decl_name (buffer, node, flags);
731 else
732 pp_string (buffer, "<unnamed type decl>");
734 else if (tclass == tcc_type)
736 if (TYPE_NAME (node))
738 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
739 pp_tree_identifier (buffer, TYPE_NAME (node));
740 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
741 && DECL_NAME (TYPE_NAME (node)))
742 dump_decl_name (buffer, TYPE_NAME (node), flags);
743 else
744 pp_string (buffer, "<unnamed type>");
746 else if (TREE_CODE (node) == VECTOR_TYPE)
748 pp_string (buffer, "vector");
749 pp_left_paren (buffer);
750 pp_wide_integer (buffer, TYPE_VECTOR_SUBPARTS (node));
751 pp_string (buffer, ") ");
752 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
754 else if (TREE_CODE (node) == INTEGER_TYPE)
756 if (TYPE_PRECISION (node) == CHAR_TYPE_SIZE)
757 pp_string (buffer, (TYPE_UNSIGNED (node)
758 ? "unsigned char"
759 : "signed char"));
760 else if (TYPE_PRECISION (node) == SHORT_TYPE_SIZE)
761 pp_string (buffer, (TYPE_UNSIGNED (node)
762 ? "unsigned short"
763 : "signed short"));
764 else if (TYPE_PRECISION (node) == INT_TYPE_SIZE)
765 pp_string (buffer, (TYPE_UNSIGNED (node)
766 ? "unsigned int"
767 : "signed int"));
768 else if (TYPE_PRECISION (node) == LONG_TYPE_SIZE)
769 pp_string (buffer, (TYPE_UNSIGNED (node)
770 ? "unsigned long"
771 : "signed long"));
772 else if (TYPE_PRECISION (node) == LONG_LONG_TYPE_SIZE)
773 pp_string (buffer, (TYPE_UNSIGNED (node)
774 ? "unsigned long long"
775 : "signed long long"));
776 else if (TYPE_PRECISION (node) >= CHAR_TYPE_SIZE
777 && exact_log2 (TYPE_PRECISION (node)) != -1)
779 pp_string (buffer, (TYPE_UNSIGNED (node) ? "uint" : "int"));
780 pp_decimal_int (buffer, TYPE_PRECISION (node));
781 pp_string (buffer, "_t");
783 else
785 pp_string (buffer, (TYPE_UNSIGNED (node)
786 ? "<unnamed-unsigned:"
787 : "<unnamed-signed:"));
788 pp_decimal_int (buffer, TYPE_PRECISION (node));
789 pp_greater (buffer);
792 else if (TREE_CODE (node) == COMPLEX_TYPE)
794 pp_string (buffer, "__complex__ ");
795 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
797 else if (TREE_CODE (node) == REAL_TYPE)
799 pp_string (buffer, "<float:");
800 pp_decimal_int (buffer, TYPE_PRECISION (node));
801 pp_greater (buffer);
803 else if (TREE_CODE (node) == FIXED_POINT_TYPE)
805 pp_string (buffer, "<fixed-point-");
806 pp_string (buffer, TYPE_SATURATING (node) ? "sat:" : "nonsat:");
807 pp_decimal_int (buffer, TYPE_PRECISION (node));
808 pp_greater (buffer);
810 else if (TREE_CODE (node) == VOID_TYPE)
811 pp_string (buffer, "void");
812 else
813 pp_string (buffer, "<unnamed type>");
815 break;
818 case POINTER_TYPE:
819 case REFERENCE_TYPE:
820 str = (TREE_CODE (node) == POINTER_TYPE ? "*" : "&");
822 if (TREE_TYPE (node) == NULL)
824 pp_string (buffer, str);
825 pp_string (buffer, "<null type>");
827 else if (TREE_CODE (TREE_TYPE (node)) == FUNCTION_TYPE)
829 tree fnode = TREE_TYPE (node);
831 dump_generic_node (buffer, TREE_TYPE (fnode), spc, flags, false);
832 pp_space (buffer);
833 pp_left_paren (buffer);
834 pp_string (buffer, str);
835 if (TYPE_NAME (node) && DECL_NAME (TYPE_NAME (node)))
836 dump_decl_name (buffer, TYPE_NAME (node), flags);
837 else if (flags & TDF_NOUID)
838 pp_printf (buffer, "<Txxxx>");
839 else
840 pp_printf (buffer, "<T%x>", TYPE_UID (node));
842 pp_right_paren (buffer);
843 dump_function_declaration (buffer, fnode, spc, flags);
845 else
847 unsigned int quals = TYPE_QUALS (node);
849 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
850 pp_space (buffer);
851 pp_string (buffer, str);
853 if (quals & TYPE_QUAL_CONST)
854 pp_string (buffer, " const");
855 if (quals & TYPE_QUAL_VOLATILE)
856 pp_string (buffer, " volatile");
857 if (quals & TYPE_QUAL_RESTRICT)
858 pp_string (buffer, " restrict");
860 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
862 pp_string (buffer, " <address-space-");
863 pp_decimal_int (buffer, TYPE_ADDR_SPACE (node));
864 pp_greater (buffer);
867 if (TYPE_REF_CAN_ALIAS_ALL (node))
868 pp_string (buffer, " {ref-all}");
870 break;
872 case OFFSET_TYPE:
873 NIY;
874 break;
876 case MEM_REF:
878 if (integer_zerop (TREE_OPERAND (node, 1))
879 /* Dump the types of INTEGER_CSTs explicitly, for we can't
880 infer them and MEM_ATTR caching will share MEM_REFs
881 with differently-typed op0s. */
882 && TREE_CODE (TREE_OPERAND (node, 0)) != INTEGER_CST
883 /* Released SSA_NAMES have no TREE_TYPE. */
884 && TREE_TYPE (TREE_OPERAND (node, 0)) != NULL_TREE
885 /* Same pointer types, but ignoring POINTER_TYPE vs.
886 REFERENCE_TYPE. */
887 && (TREE_TYPE (TREE_TYPE (TREE_OPERAND (node, 0)))
888 == TREE_TYPE (TREE_TYPE (TREE_OPERAND (node, 1))))
889 && (TYPE_MODE (TREE_TYPE (TREE_OPERAND (node, 0)))
890 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (node, 1))))
891 && (TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (node, 0)))
892 == TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (node, 1))))
893 /* Same value types ignoring qualifiers. */
894 && (TYPE_MAIN_VARIANT (TREE_TYPE (node))
895 == TYPE_MAIN_VARIANT
896 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (node, 1))))))
898 if (TREE_CODE (TREE_OPERAND (node, 0)) != ADDR_EXPR)
900 pp_star (buffer);
901 dump_generic_node (buffer, TREE_OPERAND (node, 0),
902 spc, flags, false);
904 else
905 dump_generic_node (buffer,
906 TREE_OPERAND (TREE_OPERAND (node, 0), 0),
907 spc, flags, false);
909 else
911 tree ptype;
913 pp_string (buffer, "MEM[");
914 pp_left_paren (buffer);
915 ptype = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (node, 1)));
916 dump_generic_node (buffer, ptype,
917 spc, flags | TDF_SLIM, false);
918 pp_right_paren (buffer);
919 dump_generic_node (buffer, TREE_OPERAND (node, 0),
920 spc, flags, false);
921 if (!integer_zerop (TREE_OPERAND (node, 1)))
923 pp_string (buffer, " + ");
924 dump_generic_node (buffer, TREE_OPERAND (node, 1),
925 spc, flags, false);
927 pp_right_bracket (buffer);
929 break;
932 case TARGET_MEM_REF:
934 const char *sep = "";
935 tree tmp;
937 pp_string (buffer, "MEM[");
939 if (TREE_CODE (TMR_BASE (node)) == ADDR_EXPR)
941 pp_string (buffer, sep);
942 sep = ", ";
943 pp_string (buffer, "symbol: ");
944 dump_generic_node (buffer, TREE_OPERAND (TMR_BASE (node), 0),
945 spc, flags, false);
947 else
949 pp_string (buffer, sep);
950 sep = ", ";
951 pp_string (buffer, "base: ");
952 dump_generic_node (buffer, TMR_BASE (node), spc, flags, false);
954 tmp = TMR_INDEX2 (node);
955 if (tmp)
957 pp_string (buffer, sep);
958 sep = ", ";
959 pp_string (buffer, "base: ");
960 dump_generic_node (buffer, tmp, spc, flags, false);
962 tmp = TMR_INDEX (node);
963 if (tmp)
965 pp_string (buffer, sep);
966 sep = ", ";
967 pp_string (buffer, "index: ");
968 dump_generic_node (buffer, tmp, spc, flags, false);
970 tmp = TMR_STEP (node);
971 if (tmp)
973 pp_string (buffer, sep);
974 sep = ", ";
975 pp_string (buffer, "step: ");
976 dump_generic_node (buffer, tmp, spc, flags, false);
978 tmp = TMR_OFFSET (node);
979 if (tmp)
981 pp_string (buffer, sep);
982 sep = ", ";
983 pp_string (buffer, "offset: ");
984 dump_generic_node (buffer, tmp, spc, flags, false);
986 pp_right_bracket (buffer);
988 break;
990 case ARRAY_TYPE:
992 tree tmp;
994 /* Print the innermost component type. */
995 for (tmp = TREE_TYPE (node); TREE_CODE (tmp) == ARRAY_TYPE;
996 tmp = TREE_TYPE (tmp))
998 dump_generic_node (buffer, tmp, spc, flags, false);
1000 /* Print the dimensions. */
1001 for (tmp = node; TREE_CODE (tmp) == ARRAY_TYPE; tmp = TREE_TYPE (tmp))
1002 dump_array_domain (buffer, TYPE_DOMAIN (tmp), spc, flags);
1003 break;
1006 case RECORD_TYPE:
1007 case UNION_TYPE:
1008 case QUAL_UNION_TYPE:
1010 unsigned int quals = TYPE_QUALS (node);
1012 if (quals & TYPE_QUAL_CONST)
1013 pp_string (buffer, "const ");
1014 if (quals & TYPE_QUAL_VOLATILE)
1015 pp_string (buffer, "volatile ");
1017 /* Print the name of the structure. */
1018 if (TREE_CODE (node) == RECORD_TYPE)
1019 pp_string (buffer, "struct ");
1020 else if (TREE_CODE (node) == UNION_TYPE)
1021 pp_string (buffer, "union ");
1023 if (TYPE_NAME (node))
1024 dump_generic_node (buffer, TYPE_NAME (node), spc, flags, false);
1025 else if (!(flags & TDF_SLIM))
1026 /* FIXME: If we eliminate the 'else' above and attempt
1027 to show the fields for named types, we may get stuck
1028 following a cycle of pointers to structs. The alleged
1029 self-reference check in print_struct_decl will not detect
1030 cycles involving more than one pointer or struct type. */
1031 print_struct_decl (buffer, node, spc, flags);
1032 break;
1035 case LANG_TYPE:
1036 NIY;
1037 break;
1039 case INTEGER_CST:
1040 if (TREE_CODE (TREE_TYPE (node)) == POINTER_TYPE)
1042 /* In the case of a pointer, one may want to divide by the
1043 size of the pointed-to type. Unfortunately, this not
1044 straightforward. The C front-end maps expressions
1046 (int *) 5
1047 int *p; (p + 5)
1049 in such a way that the two INTEGER_CST nodes for "5" have
1050 different values but identical types. In the latter
1051 case, the 5 is multiplied by sizeof (int) in c-common.c
1052 (pointer_int_sum) to convert it to a byte address, and
1053 yet the type of the node is left unchanged. Argh. What
1054 is consistent though is that the number value corresponds
1055 to bytes (UNITS) offset.
1057 NB: Neither of the following divisors can be trivially
1058 used to recover the original literal:
1060 TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (node)))
1061 TYPE_PRECISION (TREE_TYPE (TREE_TYPE (node))) */
1062 pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
1063 pp_string (buffer, "B"); /* pseudo-unit */
1065 else if (host_integerp (node, 0))
1066 pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
1067 else if (host_integerp (node, 1))
1068 pp_unsigned_wide_integer (buffer, TREE_INT_CST_LOW (node));
1069 else
1071 tree val = node;
1072 unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (val);
1073 HOST_WIDE_INT high = TREE_INT_CST_HIGH (val);
1075 if (tree_int_cst_sgn (val) < 0)
1077 pp_minus (buffer);
1078 high = ~high + !low;
1079 low = -low;
1081 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
1082 systems? */
1083 sprintf (pp_buffer (buffer)->digit_buffer,
1084 HOST_WIDE_INT_PRINT_DOUBLE_HEX,
1085 (unsigned HOST_WIDE_INT) high, low);
1086 pp_string (buffer, pp_buffer (buffer)->digit_buffer);
1088 break;
1090 case REAL_CST:
1091 /* Code copied from print_node. */
1093 REAL_VALUE_TYPE d;
1094 if (TREE_OVERFLOW (node))
1095 pp_string (buffer, " overflow");
1097 #if !defined(REAL_IS_NOT_DOUBLE) || defined(REAL_ARITHMETIC)
1098 d = TREE_REAL_CST (node);
1099 if (REAL_VALUE_ISINF (d))
1100 pp_string (buffer, REAL_VALUE_NEGATIVE (d) ? " -Inf" : " Inf");
1101 else if (REAL_VALUE_ISNAN (d))
1102 pp_string (buffer, " Nan");
1103 else
1105 char string[100];
1106 real_to_decimal (string, &d, sizeof (string), 0, 1);
1107 pp_string (buffer, string);
1109 #else
1111 HOST_WIDE_INT i;
1112 unsigned char *p = (unsigned char *) &TREE_REAL_CST (node);
1113 pp_string (buffer, "0x");
1114 for (i = 0; i < sizeof TREE_REAL_CST (node); i++)
1115 output_formatted_integer (buffer, "%02x", *p++);
1117 #endif
1118 break;
1121 case FIXED_CST:
1123 char string[100];
1124 fixed_to_decimal (string, TREE_FIXED_CST_PTR (node), sizeof (string));
1125 pp_string (buffer, string);
1126 break;
1129 case COMPLEX_CST:
1130 pp_string (buffer, "__complex__ (");
1131 dump_generic_node (buffer, TREE_REALPART (node), spc, flags, false);
1132 pp_string (buffer, ", ");
1133 dump_generic_node (buffer, TREE_IMAGPART (node), spc, flags, false);
1134 pp_right_paren (buffer);
1135 break;
1137 case STRING_CST:
1138 pp_string (buffer, "\"");
1139 pretty_print_string (buffer, TREE_STRING_POINTER (node));
1140 pp_string (buffer, "\"");
1141 break;
1143 case VECTOR_CST:
1145 unsigned i;
1146 pp_string (buffer, "{ ");
1147 for (i = 0; i < VECTOR_CST_NELTS (node); ++i)
1149 if (i != 0)
1150 pp_string (buffer, ", ");
1151 dump_generic_node (buffer, VECTOR_CST_ELT (node, i),
1152 spc, flags, false);
1154 pp_string (buffer, " }");
1156 break;
1158 case FUNCTION_TYPE:
1159 case METHOD_TYPE:
1160 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1161 pp_space (buffer);
1162 if (TREE_CODE (node) == METHOD_TYPE)
1164 if (TYPE_METHOD_BASETYPE (node))
1165 dump_decl_name (buffer, TYPE_NAME (TYPE_METHOD_BASETYPE (node)),
1166 flags);
1167 else
1168 pp_string (buffer, "<null method basetype>");
1169 pp_colon_colon (buffer);
1171 if (TYPE_NAME (node) && DECL_NAME (TYPE_NAME (node)))
1172 dump_decl_name (buffer, TYPE_NAME (node), flags);
1173 else if (flags & TDF_NOUID)
1174 pp_printf (buffer, "<Txxxx>");
1175 else
1176 pp_printf (buffer, "<T%x>", TYPE_UID (node));
1177 dump_function_declaration (buffer, node, spc, flags);
1178 break;
1180 case FUNCTION_DECL:
1181 case CONST_DECL:
1182 dump_decl_name (buffer, node, flags);
1183 break;
1185 case LABEL_DECL:
1186 if (DECL_NAME (node))
1187 dump_decl_name (buffer, node, flags);
1188 else if (LABEL_DECL_UID (node) != -1)
1189 pp_printf (buffer, "<L%d>", (int) LABEL_DECL_UID (node));
1190 else
1192 if (flags & TDF_NOUID)
1193 pp_string (buffer, "<D.xxxx>");
1194 else
1195 pp_printf (buffer, "<D.%u>", DECL_UID (node));
1197 break;
1199 case TYPE_DECL:
1200 if (DECL_IS_BUILTIN (node))
1202 /* Don't print the declaration of built-in types. */
1203 break;
1205 if (DECL_NAME (node))
1206 dump_decl_name (buffer, node, flags);
1207 else if (TYPE_NAME (TREE_TYPE (node)) != node)
1209 if ((TREE_CODE (TREE_TYPE (node)) == RECORD_TYPE
1210 || TREE_CODE (TREE_TYPE (node)) == UNION_TYPE)
1211 && TYPE_METHODS (TREE_TYPE (node)))
1213 /* The type is a c++ class: all structures have at least
1214 4 methods. */
1215 pp_string (buffer, "class ");
1216 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1218 else
1220 pp_string (buffer,
1221 (TREE_CODE (TREE_TYPE (node)) == UNION_TYPE
1222 ? "union" : "struct "));
1223 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1226 else
1227 pp_string (buffer, "<anon>");
1228 break;
1230 case VAR_DECL:
1231 case PARM_DECL:
1232 case FIELD_DECL:
1233 case DEBUG_EXPR_DECL:
1234 case NAMESPACE_DECL:
1235 dump_decl_name (buffer, node, flags);
1236 break;
1238 case RESULT_DECL:
1239 pp_string (buffer, "<retval>");
1240 break;
1242 case COMPONENT_REF:
1243 op0 = TREE_OPERAND (node, 0);
1244 str = ".";
1245 if (op0
1246 && (TREE_CODE (op0) == INDIRECT_REF
1247 || (TREE_CODE (op0) == MEM_REF
1248 && TREE_CODE (TREE_OPERAND (op0, 0)) != ADDR_EXPR
1249 && integer_zerop (TREE_OPERAND (op0, 1))
1250 /* Dump the types of INTEGER_CSTs explicitly, for we
1251 can't infer them and MEM_ATTR caching will share
1252 MEM_REFs with differently-typed op0s. */
1253 && TREE_CODE (TREE_OPERAND (op0, 0)) != INTEGER_CST
1254 /* Released SSA_NAMES have no TREE_TYPE. */
1255 && TREE_TYPE (TREE_OPERAND (op0, 0)) != NULL_TREE
1256 /* Same pointer types, but ignoring POINTER_TYPE vs.
1257 REFERENCE_TYPE. */
1258 && (TREE_TYPE (TREE_TYPE (TREE_OPERAND (op0, 0)))
1259 == TREE_TYPE (TREE_TYPE (TREE_OPERAND (op0, 1))))
1260 && (TYPE_MODE (TREE_TYPE (TREE_OPERAND (op0, 0)))
1261 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (op0, 1))))
1262 && (TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (op0, 0)))
1263 == TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (op0, 1))))
1264 /* Same value types ignoring qualifiers. */
1265 && (TYPE_MAIN_VARIANT (TREE_TYPE (op0))
1266 == TYPE_MAIN_VARIANT
1267 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (op0, 1))))))))
1269 op0 = TREE_OPERAND (op0, 0);
1270 str = "->";
1272 if (op_prio (op0) < op_prio (node))
1273 pp_left_paren (buffer);
1274 dump_generic_node (buffer, op0, spc, flags, false);
1275 if (op_prio (op0) < op_prio (node))
1276 pp_right_paren (buffer);
1277 pp_string (buffer, str);
1278 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1279 op0 = component_ref_field_offset (node);
1280 if (op0 && TREE_CODE (op0) != INTEGER_CST)
1282 pp_string (buffer, "{off: ");
1283 dump_generic_node (buffer, op0, spc, flags, false);
1284 pp_right_brace (buffer);
1286 break;
1288 case BIT_FIELD_REF:
1289 pp_string (buffer, "BIT_FIELD_REF <");
1290 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1291 pp_string (buffer, ", ");
1292 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1293 pp_string (buffer, ", ");
1294 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
1295 pp_greater (buffer);
1296 break;
1298 case ARRAY_REF:
1299 case ARRAY_RANGE_REF:
1300 op0 = TREE_OPERAND (node, 0);
1301 if (op_prio (op0) < op_prio (node))
1302 pp_left_paren (buffer);
1303 dump_generic_node (buffer, op0, spc, flags, false);
1304 if (op_prio (op0) < op_prio (node))
1305 pp_right_paren (buffer);
1306 pp_left_bracket (buffer);
1307 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1308 if (TREE_CODE (node) == ARRAY_RANGE_REF)
1309 pp_string (buffer, " ...");
1310 pp_right_bracket (buffer);
1312 op0 = array_ref_low_bound (node);
1313 op1 = array_ref_element_size (node);
1315 if (!integer_zerop (op0)
1316 || TREE_OPERAND (node, 2)
1317 || TREE_OPERAND (node, 3))
1319 pp_string (buffer, "{lb: ");
1320 dump_generic_node (buffer, op0, spc, flags, false);
1321 pp_string (buffer, " sz: ");
1322 dump_generic_node (buffer, op1, spc, flags, false);
1323 pp_right_brace (buffer);
1325 break;
1327 case CONSTRUCTOR:
1329 unsigned HOST_WIDE_INT ix;
1330 tree field, val;
1331 bool is_struct_init = false;
1332 bool is_array_init = false;
1333 double_int curidx = double_int_zero;
1334 pp_left_brace (buffer);
1335 if (TREE_CLOBBER_P (node))
1336 pp_string (buffer, "CLOBBER");
1337 else if (TREE_CODE (TREE_TYPE (node)) == RECORD_TYPE
1338 || TREE_CODE (TREE_TYPE (node)) == UNION_TYPE)
1339 is_struct_init = true;
1340 else if (TREE_CODE (TREE_TYPE (node)) == ARRAY_TYPE
1341 && TYPE_DOMAIN (TREE_TYPE (node))
1342 && TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (node)))
1343 && TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (node))))
1344 == INTEGER_CST)
1346 tree minv = TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (node)));
1347 is_array_init = true;
1348 curidx = tree_to_double_int (minv);
1350 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (node), ix, field, val)
1352 if (field)
1354 if (is_struct_init)
1356 pp_dot (buffer);
1357 dump_generic_node (buffer, field, spc, flags, false);
1358 pp_equal (buffer);
1360 else if (is_array_init
1361 && (TREE_CODE (field) != INTEGER_CST
1362 || tree_to_double_int (field) != curidx))
1364 pp_left_bracket (buffer);
1365 if (TREE_CODE (field) == RANGE_EXPR)
1367 dump_generic_node (buffer, TREE_OPERAND (field, 0), spc,
1368 flags, false);
1369 pp_string (buffer, " ... ");
1370 dump_generic_node (buffer, TREE_OPERAND (field, 1), spc,
1371 flags, false);
1372 if (TREE_CODE (TREE_OPERAND (field, 1)) == INTEGER_CST)
1373 curidx = tree_to_double_int (TREE_OPERAND (field, 1));
1375 else
1376 dump_generic_node (buffer, field, spc, flags, false);
1377 if (TREE_CODE (field) == INTEGER_CST)
1378 curidx = tree_to_double_int (field);
1379 pp_string (buffer, "]=");
1382 if (is_array_init)
1383 curidx += double_int_one;
1384 if (val && TREE_CODE (val) == ADDR_EXPR)
1385 if (TREE_CODE (TREE_OPERAND (val, 0)) == FUNCTION_DECL)
1386 val = TREE_OPERAND (val, 0);
1387 if (val && TREE_CODE (val) == FUNCTION_DECL)
1388 dump_decl_name (buffer, val, flags);
1389 else
1390 dump_generic_node (buffer, val, spc, flags, false);
1391 if (ix != vec_safe_length (CONSTRUCTOR_ELTS (node)) - 1)
1393 pp_comma (buffer);
1394 pp_space (buffer);
1397 pp_right_brace (buffer);
1399 break;
1401 case COMPOUND_EXPR:
1403 tree *tp;
1404 if (flags & TDF_SLIM)
1406 pp_string (buffer, "<COMPOUND_EXPR>");
1407 break;
1410 dump_generic_node (buffer, TREE_OPERAND (node, 0),
1411 spc, flags, !(flags & TDF_SLIM));
1412 if (flags & TDF_SLIM)
1413 newline_and_indent (buffer, spc);
1414 else
1416 pp_comma (buffer);
1417 pp_space (buffer);
1420 for (tp = &TREE_OPERAND (node, 1);
1421 TREE_CODE (*tp) == COMPOUND_EXPR;
1422 tp = &TREE_OPERAND (*tp, 1))
1424 dump_generic_node (buffer, TREE_OPERAND (*tp, 0),
1425 spc, flags, !(flags & TDF_SLIM));
1426 if (flags & TDF_SLIM)
1427 newline_and_indent (buffer, spc);
1428 else
1430 pp_comma (buffer);
1431 pp_space (buffer);
1435 dump_generic_node (buffer, *tp, spc, flags, !(flags & TDF_SLIM));
1437 break;
1439 case STATEMENT_LIST:
1441 tree_stmt_iterator si;
1442 bool first = true;
1444 if (flags & TDF_SLIM)
1446 pp_string (buffer, "<STATEMENT_LIST>");
1447 break;
1450 for (si = tsi_start (node); !tsi_end_p (si); tsi_next (&si))
1452 if (!first)
1453 newline_and_indent (buffer, spc);
1454 else
1455 first = false;
1456 dump_generic_node (buffer, tsi_stmt (si), spc, flags, true);
1459 break;
1461 case MODIFY_EXPR:
1462 case INIT_EXPR:
1463 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags,
1464 false);
1465 pp_space (buffer);
1466 pp_equal (buffer);
1467 pp_space (buffer);
1468 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags,
1469 false);
1470 break;
1472 case TARGET_EXPR:
1473 pp_string (buffer, "TARGET_EXPR <");
1474 dump_generic_node (buffer, TARGET_EXPR_SLOT (node), spc, flags, false);
1475 pp_comma (buffer);
1476 pp_space (buffer);
1477 dump_generic_node (buffer, TARGET_EXPR_INITIAL (node), spc, flags, false);
1478 pp_greater (buffer);
1479 break;
1481 case DECL_EXPR:
1482 print_declaration (buffer, DECL_EXPR_DECL (node), spc, flags);
1483 is_stmt = false;
1484 break;
1486 case COND_EXPR:
1487 if (TREE_TYPE (node) == NULL || TREE_TYPE (node) == void_type_node)
1489 pp_string (buffer, "if (");
1490 dump_generic_node (buffer, COND_EXPR_COND (node), spc, flags, false);
1491 pp_right_paren (buffer);
1492 /* The lowered cond_exprs should always be printed in full. */
1493 if (COND_EXPR_THEN (node)
1494 && (IS_EMPTY_STMT (COND_EXPR_THEN (node))
1495 || TREE_CODE (COND_EXPR_THEN (node)) == GOTO_EXPR)
1496 && COND_EXPR_ELSE (node)
1497 && (IS_EMPTY_STMT (COND_EXPR_ELSE (node))
1498 || TREE_CODE (COND_EXPR_ELSE (node)) == GOTO_EXPR))
1500 pp_space (buffer);
1501 dump_generic_node (buffer, COND_EXPR_THEN (node),
1502 0, flags, true);
1503 if (!IS_EMPTY_STMT (COND_EXPR_ELSE (node)))
1505 pp_string (buffer, " else ");
1506 dump_generic_node (buffer, COND_EXPR_ELSE (node),
1507 0, flags, true);
1510 else if (!(flags & TDF_SLIM))
1512 /* Output COND_EXPR_THEN. */
1513 if (COND_EXPR_THEN (node))
1515 newline_and_indent (buffer, spc+2);
1516 pp_left_brace (buffer);
1517 newline_and_indent (buffer, spc+4);
1518 dump_generic_node (buffer, COND_EXPR_THEN (node), spc+4,
1519 flags, true);
1520 newline_and_indent (buffer, spc+2);
1521 pp_right_brace (buffer);
1524 /* Output COND_EXPR_ELSE. */
1525 if (COND_EXPR_ELSE (node)
1526 && !IS_EMPTY_STMT (COND_EXPR_ELSE (node)))
1528 newline_and_indent (buffer, spc);
1529 pp_string (buffer, "else");
1530 newline_and_indent (buffer, spc+2);
1531 pp_left_brace (buffer);
1532 newline_and_indent (buffer, spc+4);
1533 dump_generic_node (buffer, COND_EXPR_ELSE (node), spc+4,
1534 flags, true);
1535 newline_and_indent (buffer, spc+2);
1536 pp_right_brace (buffer);
1539 is_expr = false;
1541 else
1543 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1544 pp_space (buffer);
1545 pp_question (buffer);
1546 pp_space (buffer);
1547 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1548 pp_space (buffer);
1549 pp_colon (buffer);
1550 pp_space (buffer);
1551 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
1553 break;
1555 case BIND_EXPR:
1556 pp_left_brace (buffer);
1557 if (!(flags & TDF_SLIM))
1559 if (BIND_EXPR_VARS (node))
1561 pp_newline (buffer);
1563 for (op0 = BIND_EXPR_VARS (node); op0; op0 = DECL_CHAIN (op0))
1565 print_declaration (buffer, op0, spc+2, flags);
1566 pp_newline (buffer);
1570 newline_and_indent (buffer, spc+2);
1571 dump_generic_node (buffer, BIND_EXPR_BODY (node), spc+2, flags, true);
1572 newline_and_indent (buffer, spc);
1573 pp_right_brace (buffer);
1575 is_expr = false;
1576 break;
1578 case CALL_EXPR:
1579 print_call_name (buffer, CALL_EXPR_FN (node), flags);
1581 /* Print parameters. */
1582 pp_space (buffer);
1583 pp_left_paren (buffer);
1585 tree arg;
1586 call_expr_arg_iterator iter;
1587 FOR_EACH_CALL_EXPR_ARG (arg, iter, node)
1589 dump_generic_node (buffer, arg, spc, flags, false);
1590 if (more_call_expr_args_p (&iter))
1592 pp_comma (buffer);
1593 pp_space (buffer);
1597 if (CALL_EXPR_VA_ARG_PACK (node))
1599 if (call_expr_nargs (node) > 0)
1601 pp_comma (buffer);
1602 pp_space (buffer);
1604 pp_string (buffer, "__builtin_va_arg_pack ()");
1606 pp_right_paren (buffer);
1608 op1 = CALL_EXPR_STATIC_CHAIN (node);
1609 if (op1)
1611 pp_string (buffer, " [static-chain: ");
1612 dump_generic_node (buffer, op1, spc, flags, false);
1613 pp_right_bracket (buffer);
1616 if (CALL_EXPR_RETURN_SLOT_OPT (node))
1617 pp_string (buffer, " [return slot optimization]");
1618 if (CALL_EXPR_TAILCALL (node))
1619 pp_string (buffer, " [tail call]");
1620 break;
1622 case WITH_CLEANUP_EXPR:
1623 NIY;
1624 break;
1626 case CLEANUP_POINT_EXPR:
1627 pp_string (buffer, "<<cleanup_point ");
1628 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1629 pp_string (buffer, ">>");
1630 break;
1632 case PLACEHOLDER_EXPR:
1633 pp_string (buffer, "<PLACEHOLDER_EXPR ");
1634 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1635 pp_greater (buffer);
1636 break;
1638 /* Binary arithmetic and logic expressions. */
1639 case WIDEN_SUM_EXPR:
1640 case WIDEN_MULT_EXPR:
1641 case MULT_EXPR:
1642 case MULT_HIGHPART_EXPR:
1643 case PLUS_EXPR:
1644 case POINTER_PLUS_EXPR:
1645 case MINUS_EXPR:
1646 case TRUNC_DIV_EXPR:
1647 case CEIL_DIV_EXPR:
1648 case FLOOR_DIV_EXPR:
1649 case ROUND_DIV_EXPR:
1650 case TRUNC_MOD_EXPR:
1651 case CEIL_MOD_EXPR:
1652 case FLOOR_MOD_EXPR:
1653 case ROUND_MOD_EXPR:
1654 case RDIV_EXPR:
1655 case EXACT_DIV_EXPR:
1656 case LSHIFT_EXPR:
1657 case RSHIFT_EXPR:
1658 case LROTATE_EXPR:
1659 case RROTATE_EXPR:
1660 case VEC_LSHIFT_EXPR:
1661 case VEC_RSHIFT_EXPR:
1662 case WIDEN_LSHIFT_EXPR:
1663 case BIT_IOR_EXPR:
1664 case BIT_XOR_EXPR:
1665 case BIT_AND_EXPR:
1666 case TRUTH_ANDIF_EXPR:
1667 case TRUTH_ORIF_EXPR:
1668 case TRUTH_AND_EXPR:
1669 case TRUTH_OR_EXPR:
1670 case TRUTH_XOR_EXPR:
1671 case LT_EXPR:
1672 case LE_EXPR:
1673 case GT_EXPR:
1674 case GE_EXPR:
1675 case EQ_EXPR:
1676 case NE_EXPR:
1677 case UNLT_EXPR:
1678 case UNLE_EXPR:
1679 case UNGT_EXPR:
1680 case UNGE_EXPR:
1681 case UNEQ_EXPR:
1682 case LTGT_EXPR:
1683 case ORDERED_EXPR:
1684 case UNORDERED_EXPR:
1686 const char *op = op_symbol (node);
1687 op0 = TREE_OPERAND (node, 0);
1688 op1 = TREE_OPERAND (node, 1);
1690 /* When the operands are expressions with less priority,
1691 keep semantics of the tree representation. */
1692 if (op_prio (op0) <= op_prio (node))
1694 pp_left_paren (buffer);
1695 dump_generic_node (buffer, op0, spc, flags, false);
1696 pp_right_paren (buffer);
1698 else
1699 dump_generic_node (buffer, op0, spc, flags, false);
1701 pp_space (buffer);
1702 pp_string (buffer, op);
1703 pp_space (buffer);
1705 /* When the operands are expressions with less priority,
1706 keep semantics of the tree representation. */
1707 if (op_prio (op1) <= op_prio (node))
1709 pp_left_paren (buffer);
1710 dump_generic_node (buffer, op1, spc, flags, false);
1711 pp_right_paren (buffer);
1713 else
1714 dump_generic_node (buffer, op1, spc, flags, false);
1716 break;
1718 /* Unary arithmetic and logic expressions. */
1719 case NEGATE_EXPR:
1720 case BIT_NOT_EXPR:
1721 case TRUTH_NOT_EXPR:
1722 case ADDR_EXPR:
1723 case PREDECREMENT_EXPR:
1724 case PREINCREMENT_EXPR:
1725 case INDIRECT_REF:
1726 if (TREE_CODE (node) == ADDR_EXPR
1727 && (TREE_CODE (TREE_OPERAND (node, 0)) == STRING_CST
1728 || TREE_CODE (TREE_OPERAND (node, 0)) == FUNCTION_DECL))
1729 ; /* Do not output '&' for strings and function pointers. */
1730 else
1731 pp_string (buffer, op_symbol (node));
1733 if (op_prio (TREE_OPERAND (node, 0)) < op_prio (node))
1735 pp_left_paren (buffer);
1736 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1737 pp_right_paren (buffer);
1739 else
1740 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1741 break;
1743 case POSTDECREMENT_EXPR:
1744 case POSTINCREMENT_EXPR:
1745 if (op_prio (TREE_OPERAND (node, 0)) < op_prio (node))
1747 pp_left_paren (buffer);
1748 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1749 pp_right_paren (buffer);
1751 else
1752 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1753 pp_string (buffer, op_symbol (node));
1754 break;
1756 case MIN_EXPR:
1757 pp_string (buffer, "MIN_EXPR <");
1758 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1759 pp_string (buffer, ", ");
1760 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1761 pp_greater (buffer);
1762 break;
1764 case MAX_EXPR:
1765 pp_string (buffer, "MAX_EXPR <");
1766 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1767 pp_string (buffer, ", ");
1768 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1769 pp_greater (buffer);
1770 break;
1772 case ABS_EXPR:
1773 pp_string (buffer, "ABS_EXPR <");
1774 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1775 pp_greater (buffer);
1776 break;
1778 case RANGE_EXPR:
1779 NIY;
1780 break;
1782 case ADDR_SPACE_CONVERT_EXPR:
1783 case FIXED_CONVERT_EXPR:
1784 case FIX_TRUNC_EXPR:
1785 case FLOAT_EXPR:
1786 CASE_CONVERT:
1787 type = TREE_TYPE (node);
1788 op0 = TREE_OPERAND (node, 0);
1789 if (type != TREE_TYPE (op0))
1791 pp_left_paren (buffer);
1792 dump_generic_node (buffer, type, spc, flags, false);
1793 pp_string (buffer, ") ");
1795 if (op_prio (op0) < op_prio (node))
1796 pp_left_paren (buffer);
1797 dump_generic_node (buffer, op0, spc, flags, false);
1798 if (op_prio (op0) < op_prio (node))
1799 pp_right_paren (buffer);
1800 break;
1802 case VIEW_CONVERT_EXPR:
1803 pp_string (buffer, "VIEW_CONVERT_EXPR<");
1804 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1805 pp_string (buffer, ">(");
1806 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1807 pp_right_paren (buffer);
1808 break;
1810 case PAREN_EXPR:
1811 pp_string (buffer, "((");
1812 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1813 pp_string (buffer, "))");
1814 break;
1816 case NON_LVALUE_EXPR:
1817 pp_string (buffer, "NON_LVALUE_EXPR <");
1818 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1819 pp_greater (buffer);
1820 break;
1822 case SAVE_EXPR:
1823 pp_string (buffer, "SAVE_EXPR <");
1824 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1825 pp_greater (buffer);
1826 break;
1828 case COMPLEX_EXPR:
1829 pp_string (buffer, "COMPLEX_EXPR <");
1830 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1831 pp_string (buffer, ", ");
1832 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1833 pp_greater (buffer);
1834 break;
1836 case CONJ_EXPR:
1837 pp_string (buffer, "CONJ_EXPR <");
1838 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1839 pp_greater (buffer);
1840 break;
1842 case REALPART_EXPR:
1843 pp_string (buffer, "REALPART_EXPR <");
1844 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1845 pp_greater (buffer);
1846 break;
1848 case IMAGPART_EXPR:
1849 pp_string (buffer, "IMAGPART_EXPR <");
1850 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1851 pp_greater (buffer);
1852 break;
1854 case VA_ARG_EXPR:
1855 pp_string (buffer, "VA_ARG_EXPR <");
1856 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1857 pp_greater (buffer);
1858 break;
1860 case TRY_FINALLY_EXPR:
1861 case TRY_CATCH_EXPR:
1862 pp_string (buffer, "try");
1863 newline_and_indent (buffer, spc+2);
1864 pp_left_brace (buffer);
1865 newline_and_indent (buffer, spc+4);
1866 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc+4, flags, true);
1867 newline_and_indent (buffer, spc+2);
1868 pp_right_brace (buffer);
1869 newline_and_indent (buffer, spc);
1870 pp_string (buffer,
1871 (TREE_CODE (node) == TRY_CATCH_EXPR) ? "catch" : "finally");
1872 newline_and_indent (buffer, spc+2);
1873 pp_left_brace (buffer);
1874 newline_and_indent (buffer, spc+4);
1875 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc+4, flags, true);
1876 newline_and_indent (buffer, spc+2);
1877 pp_right_brace (buffer);
1878 is_expr = false;
1879 break;
1881 case CATCH_EXPR:
1882 pp_string (buffer, "catch (");
1883 dump_generic_node (buffer, CATCH_TYPES (node), spc+2, flags, false);
1884 pp_right_paren (buffer);
1885 newline_and_indent (buffer, spc+2);
1886 pp_left_brace (buffer);
1887 newline_and_indent (buffer, spc+4);
1888 dump_generic_node (buffer, CATCH_BODY (node), spc+4, flags, true);
1889 newline_and_indent (buffer, spc+2);
1890 pp_right_brace (buffer);
1891 is_expr = false;
1892 break;
1894 case EH_FILTER_EXPR:
1895 pp_string (buffer, "<<<eh_filter (");
1896 dump_generic_node (buffer, EH_FILTER_TYPES (node), spc+2, flags, false);
1897 pp_string (buffer, ")>>>");
1898 newline_and_indent (buffer, spc+2);
1899 pp_left_brace (buffer);
1900 newline_and_indent (buffer, spc+4);
1901 dump_generic_node (buffer, EH_FILTER_FAILURE (node), spc+4, flags, true);
1902 newline_and_indent (buffer, spc+2);
1903 pp_right_brace (buffer);
1904 is_expr = false;
1905 break;
1907 case LABEL_EXPR:
1908 op0 = TREE_OPERAND (node, 0);
1909 /* If this is for break or continue, don't bother printing it. */
1910 if (DECL_NAME (op0))
1912 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1913 if (strcmp (name, "break") == 0
1914 || strcmp (name, "continue") == 0)
1915 break;
1917 dump_generic_node (buffer, op0, spc, flags, false);
1918 pp_colon (buffer);
1919 if (DECL_NONLOCAL (op0))
1920 pp_string (buffer, " [non-local]");
1921 break;
1923 case LOOP_EXPR:
1924 pp_string (buffer, "while (1)");
1925 if (!(flags & TDF_SLIM))
1927 newline_and_indent (buffer, spc+2);
1928 pp_left_brace (buffer);
1929 newline_and_indent (buffer, spc+4);
1930 dump_generic_node (buffer, LOOP_EXPR_BODY (node), spc+4, flags, true);
1931 newline_and_indent (buffer, spc+2);
1932 pp_right_brace (buffer);
1934 is_expr = false;
1935 break;
1937 case PREDICT_EXPR:
1938 pp_string (buffer, "// predicted ");
1939 if (PREDICT_EXPR_OUTCOME (node))
1940 pp_string (buffer, "likely by ");
1941 else
1942 pp_string (buffer, "unlikely by ");
1943 pp_string (buffer, predictor_name (PREDICT_EXPR_PREDICTOR (node)));
1944 pp_string (buffer, " predictor.");
1945 break;
1947 case RETURN_EXPR:
1948 pp_string (buffer, "return");
1949 op0 = TREE_OPERAND (node, 0);
1950 if (op0)
1952 pp_space (buffer);
1953 if (TREE_CODE (op0) == MODIFY_EXPR)
1954 dump_generic_node (buffer, TREE_OPERAND (op0, 1),
1955 spc, flags, false);
1956 else
1957 dump_generic_node (buffer, op0, spc, flags, false);
1959 break;
1961 case EXIT_EXPR:
1962 pp_string (buffer, "if (");
1963 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1964 pp_string (buffer, ") break");
1965 break;
1967 case SWITCH_EXPR:
1968 pp_string (buffer, "switch (");
1969 dump_generic_node (buffer, SWITCH_COND (node), spc, flags, false);
1970 pp_right_paren (buffer);
1971 if (!(flags & TDF_SLIM))
1973 newline_and_indent (buffer, spc+2);
1974 pp_left_brace (buffer);
1975 if (SWITCH_BODY (node))
1977 newline_and_indent (buffer, spc+4);
1978 dump_generic_node (buffer, SWITCH_BODY (node), spc+4, flags,
1979 true);
1981 else
1983 tree vec = SWITCH_LABELS (node);
1984 size_t i, n = TREE_VEC_LENGTH (vec);
1985 for (i = 0; i < n; ++i)
1987 tree elt = TREE_VEC_ELT (vec, i);
1988 newline_and_indent (buffer, spc+4);
1989 if (elt)
1991 dump_generic_node (buffer, elt, spc+4, flags, false);
1992 pp_string (buffer, " goto ");
1993 dump_generic_node (buffer, CASE_LABEL (elt), spc+4,
1994 flags, true);
1995 pp_semicolon (buffer);
1997 else
1998 pp_string (buffer, "case ???: goto ???;");
2001 newline_and_indent (buffer, spc+2);
2002 pp_right_brace (buffer);
2004 is_expr = false;
2005 break;
2007 case GOTO_EXPR:
2008 op0 = GOTO_DESTINATION (node);
2009 if (TREE_CODE (op0) != SSA_NAME && DECL_P (op0) && DECL_NAME (op0))
2011 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
2012 if (strcmp (name, "break") == 0
2013 || strcmp (name, "continue") == 0)
2015 pp_string (buffer, name);
2016 break;
2019 pp_string (buffer, "goto ");
2020 dump_generic_node (buffer, op0, spc, flags, false);
2021 break;
2023 case ASM_EXPR:
2024 pp_string (buffer, "__asm__");
2025 if (ASM_VOLATILE_P (node))
2026 pp_string (buffer, " __volatile__");
2027 pp_left_paren (buffer);
2028 dump_generic_node (buffer, ASM_STRING (node), spc, flags, false);
2029 pp_colon (buffer);
2030 dump_generic_node (buffer, ASM_OUTPUTS (node), spc, flags, false);
2031 pp_colon (buffer);
2032 dump_generic_node (buffer, ASM_INPUTS (node), spc, flags, false);
2033 if (ASM_CLOBBERS (node))
2035 pp_colon (buffer);
2036 dump_generic_node (buffer, ASM_CLOBBERS (node), spc, flags, false);
2038 pp_right_paren (buffer);
2039 break;
2041 case CASE_LABEL_EXPR:
2042 if (CASE_LOW (node) && CASE_HIGH (node))
2044 pp_string (buffer, "case ");
2045 dump_generic_node (buffer, CASE_LOW (node), spc, flags, false);
2046 pp_string (buffer, " ... ");
2047 dump_generic_node (buffer, CASE_HIGH (node), spc, flags, false);
2049 else if (CASE_LOW (node))
2051 pp_string (buffer, "case ");
2052 dump_generic_node (buffer, CASE_LOW (node), spc, flags, false);
2054 else
2055 pp_string (buffer, "default");
2056 pp_colon (buffer);
2057 break;
2059 case OBJ_TYPE_REF:
2060 pp_string (buffer, "OBJ_TYPE_REF(");
2061 dump_generic_node (buffer, OBJ_TYPE_REF_EXPR (node), spc, flags, false);
2062 pp_semicolon (buffer);
2063 dump_generic_node (buffer, OBJ_TYPE_REF_OBJECT (node), spc, flags, false);
2064 pp_arrow (buffer);
2065 dump_generic_node (buffer, OBJ_TYPE_REF_TOKEN (node), spc, flags, false);
2066 pp_right_paren (buffer);
2067 break;
2069 case SSA_NAME:
2070 if (SSA_NAME_IDENTIFIER (node))
2071 dump_generic_node (buffer, SSA_NAME_IDENTIFIER (node),
2072 spc, flags, false);
2073 pp_underscore (buffer);
2074 pp_decimal_int (buffer, SSA_NAME_VERSION (node));
2075 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (node))
2076 pp_string (buffer, "(ab)");
2077 else if (SSA_NAME_IS_DEFAULT_DEF (node))
2078 pp_string (buffer, "(D)");
2079 break;
2081 case WITH_SIZE_EXPR:
2082 pp_string (buffer, "WITH_SIZE_EXPR <");
2083 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2084 pp_string (buffer, ", ");
2085 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2086 pp_greater (buffer);
2087 break;
2089 case ASSERT_EXPR:
2090 pp_string (buffer, "ASSERT_EXPR <");
2091 dump_generic_node (buffer, ASSERT_EXPR_VAR (node), spc, flags, false);
2092 pp_string (buffer, ", ");
2093 dump_generic_node (buffer, ASSERT_EXPR_COND (node), spc, flags, false);
2094 pp_greater (buffer);
2095 break;
2097 case SCEV_KNOWN:
2098 pp_string (buffer, "scev_known");
2099 break;
2101 case SCEV_NOT_KNOWN:
2102 pp_string (buffer, "scev_not_known");
2103 break;
2105 case POLYNOMIAL_CHREC:
2106 pp_left_brace (buffer);
2107 dump_generic_node (buffer, CHREC_LEFT (node), spc, flags, false);
2108 pp_string (buffer, ", +, ");
2109 dump_generic_node (buffer, CHREC_RIGHT (node), spc, flags, false);
2110 pp_string (buffer, "}_");
2111 dump_generic_node (buffer, CHREC_VAR (node), spc, flags, false);
2112 is_stmt = false;
2113 break;
2115 case REALIGN_LOAD_EXPR:
2116 pp_string (buffer, "REALIGN_LOAD <");
2117 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2118 pp_string (buffer, ", ");
2119 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2120 pp_string (buffer, ", ");
2121 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2122 pp_greater (buffer);
2123 break;
2125 case VEC_COND_EXPR:
2126 pp_string (buffer, " VEC_COND_EXPR < ");
2127 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2128 pp_string (buffer, " , ");
2129 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2130 pp_string (buffer, " , ");
2131 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2132 pp_string (buffer, " > ");
2133 break;
2135 case VEC_PERM_EXPR:
2136 pp_string (buffer, " VEC_PERM_EXPR < ");
2137 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2138 pp_string (buffer, " , ");
2139 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2140 pp_string (buffer, " , ");
2141 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2142 pp_string (buffer, " > ");
2143 break;
2145 case DOT_PROD_EXPR:
2146 pp_string (buffer, " DOT_PROD_EXPR < ");
2147 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2148 pp_string (buffer, ", ");
2149 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2150 pp_string (buffer, ", ");
2151 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2152 pp_string (buffer, " > ");
2153 break;
2155 case WIDEN_MULT_PLUS_EXPR:
2156 pp_string (buffer, " WIDEN_MULT_PLUS_EXPR < ");
2157 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2158 pp_string (buffer, ", ");
2159 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2160 pp_string (buffer, ", ");
2161 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2162 pp_string (buffer, " > ");
2163 break;
2165 case WIDEN_MULT_MINUS_EXPR:
2166 pp_string (buffer, " WIDEN_MULT_MINUS_EXPR < ");
2167 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2168 pp_string (buffer, ", ");
2169 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2170 pp_string (buffer, ", ");
2171 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2172 pp_string (buffer, " > ");
2173 break;
2175 case FMA_EXPR:
2176 pp_string (buffer, " FMA_EXPR < ");
2177 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2178 pp_string (buffer, ", ");
2179 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2180 pp_string (buffer, ", ");
2181 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2182 pp_string (buffer, " > ");
2183 break;
2185 case OMP_PARALLEL:
2186 pp_string (buffer, "#pragma omp parallel");
2187 dump_omp_clauses (buffer, OMP_PARALLEL_CLAUSES (node), spc, flags);
2189 dump_omp_body:
2190 if (!(flags & TDF_SLIM) && OMP_BODY (node))
2192 newline_and_indent (buffer, spc + 2);
2193 pp_left_brace (buffer);
2194 newline_and_indent (buffer, spc + 4);
2195 dump_generic_node (buffer, OMP_BODY (node), spc + 4, flags, false);
2196 newline_and_indent (buffer, spc + 2);
2197 pp_right_brace (buffer);
2199 is_expr = false;
2200 break;
2202 case OMP_TASK:
2203 pp_string (buffer, "#pragma omp task");
2204 dump_omp_clauses (buffer, OMP_TASK_CLAUSES (node), spc, flags);
2205 goto dump_omp_body;
2207 case OMP_FOR:
2208 pp_string (buffer, "#pragma omp for");
2209 goto dump_omp_loop;
2211 case OMP_SIMD:
2212 pp_string (buffer, "#pragma omp simd");
2213 goto dump_omp_loop;
2215 dump_omp_loop:
2216 dump_omp_clauses (buffer, OMP_FOR_CLAUSES (node), spc, flags);
2218 if (!(flags & TDF_SLIM))
2220 int i;
2222 if (OMP_FOR_PRE_BODY (node))
2224 newline_and_indent (buffer, spc + 2);
2225 pp_left_brace (buffer);
2226 spc += 4;
2227 newline_and_indent (buffer, spc);
2228 dump_generic_node (buffer, OMP_FOR_PRE_BODY (node),
2229 spc, flags, false);
2231 spc -= 2;
2232 for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (node)); i++)
2234 spc += 2;
2235 newline_and_indent (buffer, spc);
2236 pp_string (buffer, "for (");
2237 dump_generic_node (buffer, TREE_VEC_ELT (OMP_FOR_INIT (node), i),
2238 spc, flags, false);
2239 pp_string (buffer, "; ");
2240 dump_generic_node (buffer, TREE_VEC_ELT (OMP_FOR_COND (node), i),
2241 spc, flags, false);
2242 pp_string (buffer, "; ");
2243 dump_generic_node (buffer, TREE_VEC_ELT (OMP_FOR_INCR (node), i),
2244 spc, flags, false);
2245 pp_right_paren (buffer);
2247 if (OMP_FOR_BODY (node))
2249 newline_and_indent (buffer, spc + 2);
2250 pp_left_brace (buffer);
2251 newline_and_indent (buffer, spc + 4);
2252 dump_generic_node (buffer, OMP_FOR_BODY (node), spc + 4, flags,
2253 false);
2254 newline_and_indent (buffer, spc + 2);
2255 pp_right_brace (buffer);
2257 spc -= 2 * TREE_VEC_LENGTH (OMP_FOR_INIT (node)) - 2;
2258 if (OMP_FOR_PRE_BODY (node))
2260 spc -= 4;
2261 newline_and_indent (buffer, spc + 2);
2262 pp_right_brace (buffer);
2265 is_expr = false;
2266 break;
2268 case OMP_SECTIONS:
2269 pp_string (buffer, "#pragma omp sections");
2270 dump_omp_clauses (buffer, OMP_SECTIONS_CLAUSES (node), spc, flags);
2271 goto dump_omp_body;
2273 case OMP_SECTION:
2274 pp_string (buffer, "#pragma omp section");
2275 goto dump_omp_body;
2277 case OMP_MASTER:
2278 pp_string (buffer, "#pragma omp master");
2279 goto dump_omp_body;
2281 case OMP_ORDERED:
2282 pp_string (buffer, "#pragma omp ordered");
2283 goto dump_omp_body;
2285 case OMP_CRITICAL:
2286 pp_string (buffer, "#pragma omp critical");
2287 if (OMP_CRITICAL_NAME (node))
2289 pp_space (buffer);
2290 pp_left_paren (buffer);
2291 dump_generic_node (buffer, OMP_CRITICAL_NAME (node), spc,
2292 flags, false);
2293 pp_right_paren (buffer);
2295 goto dump_omp_body;
2297 case OMP_ATOMIC:
2298 pp_string (buffer, "#pragma omp atomic");
2299 newline_and_indent (buffer, spc + 2);
2300 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2301 pp_space (buffer);
2302 pp_equal (buffer);
2303 pp_space (buffer);
2304 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2305 break;
2307 case OMP_ATOMIC_READ:
2308 pp_string (buffer, "#pragma omp atomic read");
2309 newline_and_indent (buffer, spc + 2);
2310 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2311 pp_space (buffer);
2312 break;
2314 case OMP_ATOMIC_CAPTURE_OLD:
2315 case OMP_ATOMIC_CAPTURE_NEW:
2316 pp_string (buffer, "#pragma omp atomic capture");
2317 newline_and_indent (buffer, spc + 2);
2318 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2319 pp_space (buffer);
2320 pp_equal (buffer);
2321 pp_space (buffer);
2322 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2323 break;
2325 case OMP_SINGLE:
2326 pp_string (buffer, "#pragma omp single");
2327 dump_omp_clauses (buffer, OMP_SINGLE_CLAUSES (node), spc, flags);
2328 goto dump_omp_body;
2330 case OMP_CLAUSE:
2331 dump_omp_clause (buffer, node, spc, flags);
2332 is_expr = false;
2333 break;
2335 case TRANSACTION_EXPR:
2336 if (TRANSACTION_EXPR_OUTER (node))
2337 pp_string (buffer, "__transaction_atomic [[outer]]");
2338 else if (TRANSACTION_EXPR_RELAXED (node))
2339 pp_string (buffer, "__transaction_relaxed");
2340 else
2341 pp_string (buffer, "__transaction_atomic");
2342 if (!(flags & TDF_SLIM) && TRANSACTION_EXPR_BODY (node))
2344 newline_and_indent (buffer, spc);
2345 pp_left_brace (buffer);
2346 newline_and_indent (buffer, spc + 2);
2347 dump_generic_node (buffer, TRANSACTION_EXPR_BODY (node),
2348 spc + 2, flags, false);
2349 newline_and_indent (buffer, spc);
2350 pp_right_brace (buffer);
2352 is_expr = false;
2353 break;
2355 case REDUC_MAX_EXPR:
2356 pp_string (buffer, " REDUC_MAX_EXPR < ");
2357 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2358 pp_string (buffer, " > ");
2359 break;
2361 case REDUC_MIN_EXPR:
2362 pp_string (buffer, " REDUC_MIN_EXPR < ");
2363 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2364 pp_string (buffer, " > ");
2365 break;
2367 case REDUC_PLUS_EXPR:
2368 pp_string (buffer, " REDUC_PLUS_EXPR < ");
2369 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2370 pp_string (buffer, " > ");
2371 break;
2373 case VEC_WIDEN_MULT_HI_EXPR:
2374 case VEC_WIDEN_MULT_LO_EXPR:
2375 case VEC_WIDEN_MULT_EVEN_EXPR:
2376 case VEC_WIDEN_MULT_ODD_EXPR:
2377 case VEC_WIDEN_LSHIFT_HI_EXPR:
2378 case VEC_WIDEN_LSHIFT_LO_EXPR:
2379 pp_space (buffer);
2380 for (str = tree_code_name [code]; *str; str++)
2381 pp_character (buffer, TOUPPER (*str));
2382 pp_string (buffer, " < ");
2383 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2384 pp_string (buffer, ", ");
2385 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2386 pp_string (buffer, " > ");
2387 break;
2389 case VEC_UNPACK_HI_EXPR:
2390 pp_string (buffer, " VEC_UNPACK_HI_EXPR < ");
2391 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2392 pp_string (buffer, " > ");
2393 break;
2395 case VEC_UNPACK_LO_EXPR:
2396 pp_string (buffer, " VEC_UNPACK_LO_EXPR < ");
2397 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2398 pp_string (buffer, " > ");
2399 break;
2401 case VEC_UNPACK_FLOAT_HI_EXPR:
2402 pp_string (buffer, " VEC_UNPACK_FLOAT_HI_EXPR < ");
2403 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2404 pp_string (buffer, " > ");
2405 break;
2407 case VEC_UNPACK_FLOAT_LO_EXPR:
2408 pp_string (buffer, " VEC_UNPACK_FLOAT_LO_EXPR < ");
2409 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2410 pp_string (buffer, " > ");
2411 break;
2413 case VEC_PACK_TRUNC_EXPR:
2414 pp_string (buffer, " VEC_PACK_TRUNC_EXPR < ");
2415 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2416 pp_string (buffer, ", ");
2417 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2418 pp_string (buffer, " > ");
2419 break;
2421 case VEC_PACK_SAT_EXPR:
2422 pp_string (buffer, " VEC_PACK_SAT_EXPR < ");
2423 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2424 pp_string (buffer, ", ");
2425 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2426 pp_string (buffer, " > ");
2427 break;
2429 case VEC_PACK_FIX_TRUNC_EXPR:
2430 pp_string (buffer, " VEC_PACK_FIX_TRUNC_EXPR < ");
2431 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2432 pp_string (buffer, ", ");
2433 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2434 pp_string (buffer, " > ");
2435 break;
2437 case BLOCK:
2438 dump_block_node (buffer, node, spc, flags);
2439 break;
2441 default:
2442 NIY;
2445 if (is_stmt && is_expr)
2446 pp_semicolon (buffer);
2448 return spc;
2451 /* Print the declaration of a variable. */
2453 void
2454 print_declaration (pretty_printer *buffer, tree t, int spc, int flags)
2456 INDENT (spc);
2458 if (TREE_CODE (t) == TYPE_DECL)
2459 pp_string (buffer, "typedef ");
2461 if (CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_DECL_WRTL) && DECL_REGISTER (t))
2462 pp_string (buffer, "register ");
2464 if (TREE_PUBLIC (t) && DECL_EXTERNAL (t))
2465 pp_string (buffer, "extern ");
2466 else if (TREE_STATIC (t))
2467 pp_string (buffer, "static ");
2469 /* Print the type and name. */
2470 if (TREE_TYPE (t) && TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
2472 tree tmp;
2474 /* Print array's type. */
2475 tmp = TREE_TYPE (t);
2476 while (TREE_CODE (TREE_TYPE (tmp)) == ARRAY_TYPE)
2477 tmp = TREE_TYPE (tmp);
2478 dump_generic_node (buffer, TREE_TYPE (tmp), spc, flags, false);
2480 /* Print variable's name. */
2481 pp_space (buffer);
2482 dump_generic_node (buffer, t, spc, flags, false);
2484 /* Print the dimensions. */
2485 tmp = TREE_TYPE (t);
2486 while (TREE_CODE (tmp) == ARRAY_TYPE)
2488 dump_array_domain (buffer, TYPE_DOMAIN (tmp), spc, flags);
2489 tmp = TREE_TYPE (tmp);
2492 else if (TREE_CODE (t) == FUNCTION_DECL)
2494 dump_generic_node (buffer, TREE_TYPE (TREE_TYPE (t)), spc, flags, false);
2495 pp_space (buffer);
2496 dump_decl_name (buffer, t, flags);
2497 dump_function_declaration (buffer, TREE_TYPE (t), spc, flags);
2499 else
2501 /* Print type declaration. */
2502 dump_generic_node (buffer, TREE_TYPE (t), spc, flags, false);
2504 /* Print variable's name. */
2505 pp_space (buffer);
2506 dump_generic_node (buffer, t, spc, flags, false);
2509 if (TREE_CODE (t) == VAR_DECL && DECL_HARD_REGISTER (t))
2511 pp_string (buffer, " __asm__ ");
2512 pp_left_paren (buffer);
2513 dump_generic_node (buffer, DECL_ASSEMBLER_NAME (t), spc, flags, false);
2514 pp_right_paren (buffer);
2517 /* The initial value of a function serves to determine whether the function
2518 is declared or defined. So the following does not apply to function
2519 nodes. */
2520 if (TREE_CODE (t) != FUNCTION_DECL)
2522 /* Print the initial value. */
2523 if (DECL_INITIAL (t))
2525 pp_space (buffer);
2526 pp_equal (buffer);
2527 pp_space (buffer);
2528 dump_generic_node (buffer, DECL_INITIAL (t), spc, flags, false);
2532 if (TREE_CODE (t) == VAR_DECL && DECL_HAS_VALUE_EXPR_P (t))
2534 pp_string (buffer, " [value-expr: ");
2535 dump_generic_node (buffer, DECL_VALUE_EXPR (t), spc, flags, false);
2536 pp_right_bracket (buffer);
2539 pp_semicolon (buffer);
2543 /* Prints a structure: name, fields, and methods.
2544 FIXME: Still incomplete. */
2546 static void
2547 print_struct_decl (pretty_printer *buffer, const_tree node, int spc, int flags)
2549 /* Print the name of the structure. */
2550 if (TYPE_NAME (node))
2552 INDENT (spc);
2553 if (TREE_CODE (node) == RECORD_TYPE)
2554 pp_string (buffer, "struct ");
2555 else if ((TREE_CODE (node) == UNION_TYPE
2556 || TREE_CODE (node) == QUAL_UNION_TYPE))
2557 pp_string (buffer, "union ");
2559 dump_generic_node (buffer, TYPE_NAME (node), spc, 0, false);
2562 /* Print the contents of the structure. */
2563 pp_newline (buffer);
2564 INDENT (spc);
2565 pp_left_brace (buffer);
2566 pp_newline (buffer);
2568 /* Print the fields of the structure. */
2570 tree tmp;
2571 tmp = TYPE_FIELDS (node);
2572 while (tmp)
2574 /* Avoid to print recursively the structure. */
2575 /* FIXME : Not implemented correctly...,
2576 what about the case when we have a cycle in the contain graph? ...
2577 Maybe this could be solved by looking at the scope in which the
2578 structure was declared. */
2579 if (TREE_TYPE (tmp) != node
2580 && (TREE_CODE (TREE_TYPE (tmp)) != POINTER_TYPE
2581 || TREE_TYPE (TREE_TYPE (tmp)) != node))
2583 print_declaration (buffer, tmp, spc+2, flags);
2584 pp_newline (buffer);
2586 tmp = DECL_CHAIN (tmp);
2589 INDENT (spc);
2590 pp_right_brace (buffer);
2593 /* Return the priority of the operator CODE.
2595 From lowest to highest precedence with either left-to-right (L-R)
2596 or right-to-left (R-L) associativity]:
2598 1 [L-R] ,
2599 2 [R-L] = += -= *= /= %= &= ^= |= <<= >>=
2600 3 [R-L] ?:
2601 4 [L-R] ||
2602 5 [L-R] &&
2603 6 [L-R] |
2604 7 [L-R] ^
2605 8 [L-R] &
2606 9 [L-R] == !=
2607 10 [L-R] < <= > >=
2608 11 [L-R] << >>
2609 12 [L-R] + -
2610 13 [L-R] * / %
2611 14 [R-L] ! ~ ++ -- + - * & (type) sizeof
2612 15 [L-R] fn() [] -> .
2614 unary +, - and * have higher precedence than the corresponding binary
2615 operators. */
2618 op_code_prio (enum tree_code code)
2620 switch (code)
2622 case TREE_LIST:
2623 case COMPOUND_EXPR:
2624 case BIND_EXPR:
2625 return 1;
2627 case MODIFY_EXPR:
2628 case INIT_EXPR:
2629 return 2;
2631 case COND_EXPR:
2632 return 3;
2634 case TRUTH_OR_EXPR:
2635 case TRUTH_ORIF_EXPR:
2636 return 4;
2638 case TRUTH_AND_EXPR:
2639 case TRUTH_ANDIF_EXPR:
2640 return 5;
2642 case BIT_IOR_EXPR:
2643 return 6;
2645 case BIT_XOR_EXPR:
2646 case TRUTH_XOR_EXPR:
2647 return 7;
2649 case BIT_AND_EXPR:
2650 return 8;
2652 case EQ_EXPR:
2653 case NE_EXPR:
2654 return 9;
2656 case UNLT_EXPR:
2657 case UNLE_EXPR:
2658 case UNGT_EXPR:
2659 case UNGE_EXPR:
2660 case UNEQ_EXPR:
2661 case LTGT_EXPR:
2662 case ORDERED_EXPR:
2663 case UNORDERED_EXPR:
2664 case LT_EXPR:
2665 case LE_EXPR:
2666 case GT_EXPR:
2667 case GE_EXPR:
2668 return 10;
2670 case LSHIFT_EXPR:
2671 case RSHIFT_EXPR:
2672 case LROTATE_EXPR:
2673 case RROTATE_EXPR:
2674 case VEC_WIDEN_LSHIFT_HI_EXPR:
2675 case VEC_WIDEN_LSHIFT_LO_EXPR:
2676 case WIDEN_LSHIFT_EXPR:
2677 return 11;
2679 case WIDEN_SUM_EXPR:
2680 case PLUS_EXPR:
2681 case POINTER_PLUS_EXPR:
2682 case MINUS_EXPR:
2683 return 12;
2685 case VEC_WIDEN_MULT_HI_EXPR:
2686 case VEC_WIDEN_MULT_LO_EXPR:
2687 case WIDEN_MULT_EXPR:
2688 case DOT_PROD_EXPR:
2689 case WIDEN_MULT_PLUS_EXPR:
2690 case WIDEN_MULT_MINUS_EXPR:
2691 case MULT_EXPR:
2692 case MULT_HIGHPART_EXPR:
2693 case TRUNC_DIV_EXPR:
2694 case CEIL_DIV_EXPR:
2695 case FLOOR_DIV_EXPR:
2696 case ROUND_DIV_EXPR:
2697 case RDIV_EXPR:
2698 case EXACT_DIV_EXPR:
2699 case TRUNC_MOD_EXPR:
2700 case CEIL_MOD_EXPR:
2701 case FLOOR_MOD_EXPR:
2702 case ROUND_MOD_EXPR:
2703 case FMA_EXPR:
2704 return 13;
2706 case TRUTH_NOT_EXPR:
2707 case BIT_NOT_EXPR:
2708 case POSTINCREMENT_EXPR:
2709 case POSTDECREMENT_EXPR:
2710 case PREINCREMENT_EXPR:
2711 case PREDECREMENT_EXPR:
2712 case NEGATE_EXPR:
2713 case INDIRECT_REF:
2714 case ADDR_EXPR:
2715 case FLOAT_EXPR:
2716 CASE_CONVERT:
2717 case FIX_TRUNC_EXPR:
2718 case TARGET_EXPR:
2719 return 14;
2721 case CALL_EXPR:
2722 case ARRAY_REF:
2723 case ARRAY_RANGE_REF:
2724 case COMPONENT_REF:
2725 return 15;
2727 /* Special expressions. */
2728 case MIN_EXPR:
2729 case MAX_EXPR:
2730 case ABS_EXPR:
2731 case REALPART_EXPR:
2732 case IMAGPART_EXPR:
2733 case REDUC_MAX_EXPR:
2734 case REDUC_MIN_EXPR:
2735 case REDUC_PLUS_EXPR:
2736 case VEC_LSHIFT_EXPR:
2737 case VEC_RSHIFT_EXPR:
2738 case VEC_UNPACK_HI_EXPR:
2739 case VEC_UNPACK_LO_EXPR:
2740 case VEC_UNPACK_FLOAT_HI_EXPR:
2741 case VEC_UNPACK_FLOAT_LO_EXPR:
2742 case VEC_PACK_TRUNC_EXPR:
2743 case VEC_PACK_SAT_EXPR:
2744 return 16;
2746 default:
2747 /* Return an arbitrarily high precedence to avoid surrounding single
2748 VAR_DECLs in ()s. */
2749 return 9999;
2753 /* Return the priority of the operator OP. */
2756 op_prio (const_tree op)
2758 enum tree_code code;
2760 if (op == NULL)
2761 return 9999;
2763 code = TREE_CODE (op);
2764 if (code == SAVE_EXPR || code == NON_LVALUE_EXPR)
2765 return op_prio (TREE_OPERAND (op, 0));
2767 return op_code_prio (code);
2770 /* Return the symbol associated with operator CODE. */
2772 const char *
2773 op_symbol_code (enum tree_code code)
2775 switch (code)
2777 case MODIFY_EXPR:
2778 return "=";
2780 case TRUTH_OR_EXPR:
2781 case TRUTH_ORIF_EXPR:
2782 return "||";
2784 case TRUTH_AND_EXPR:
2785 case TRUTH_ANDIF_EXPR:
2786 return "&&";
2788 case BIT_IOR_EXPR:
2789 return "|";
2791 case TRUTH_XOR_EXPR:
2792 case BIT_XOR_EXPR:
2793 return "^";
2795 case ADDR_EXPR:
2796 case BIT_AND_EXPR:
2797 return "&";
2799 case ORDERED_EXPR:
2800 return "ord";
2801 case UNORDERED_EXPR:
2802 return "unord";
2804 case EQ_EXPR:
2805 return "==";
2806 case UNEQ_EXPR:
2807 return "u==";
2809 case NE_EXPR:
2810 return "!=";
2812 case LT_EXPR:
2813 return "<";
2814 case UNLT_EXPR:
2815 return "u<";
2817 case LE_EXPR:
2818 return "<=";
2819 case UNLE_EXPR:
2820 return "u<=";
2822 case GT_EXPR:
2823 return ">";
2824 case UNGT_EXPR:
2825 return "u>";
2827 case GE_EXPR:
2828 return ">=";
2829 case UNGE_EXPR:
2830 return "u>=";
2832 case LTGT_EXPR:
2833 return "<>";
2835 case LSHIFT_EXPR:
2836 return "<<";
2838 case RSHIFT_EXPR:
2839 return ">>";
2841 case LROTATE_EXPR:
2842 return "r<<";
2844 case RROTATE_EXPR:
2845 return "r>>";
2847 case VEC_LSHIFT_EXPR:
2848 return "v<<";
2850 case VEC_RSHIFT_EXPR:
2851 return "v>>";
2853 case WIDEN_LSHIFT_EXPR:
2854 return "w<<";
2856 case POINTER_PLUS_EXPR:
2857 return "+";
2859 case PLUS_EXPR:
2860 return "+";
2862 case REDUC_PLUS_EXPR:
2863 return "r+";
2865 case WIDEN_SUM_EXPR:
2866 return "w+";
2868 case WIDEN_MULT_EXPR:
2869 return "w*";
2871 case MULT_HIGHPART_EXPR:
2872 return "h*";
2874 case NEGATE_EXPR:
2875 case MINUS_EXPR:
2876 return "-";
2878 case BIT_NOT_EXPR:
2879 return "~";
2881 case TRUTH_NOT_EXPR:
2882 return "!";
2884 case MULT_EXPR:
2885 case INDIRECT_REF:
2886 return "*";
2888 case TRUNC_DIV_EXPR:
2889 case RDIV_EXPR:
2890 return "/";
2892 case CEIL_DIV_EXPR:
2893 return "/[cl]";
2895 case FLOOR_DIV_EXPR:
2896 return "/[fl]";
2898 case ROUND_DIV_EXPR:
2899 return "/[rd]";
2901 case EXACT_DIV_EXPR:
2902 return "/[ex]";
2904 case TRUNC_MOD_EXPR:
2905 return "%";
2907 case CEIL_MOD_EXPR:
2908 return "%[cl]";
2910 case FLOOR_MOD_EXPR:
2911 return "%[fl]";
2913 case ROUND_MOD_EXPR:
2914 return "%[rd]";
2916 case PREDECREMENT_EXPR:
2917 return " --";
2919 case PREINCREMENT_EXPR:
2920 return " ++";
2922 case POSTDECREMENT_EXPR:
2923 return "-- ";
2925 case POSTINCREMENT_EXPR:
2926 return "++ ";
2928 case MAX_EXPR:
2929 return "max";
2931 case MIN_EXPR:
2932 return "min";
2934 default:
2935 return "<<< ??? >>>";
2939 /* Return the symbol associated with operator OP. */
2941 static const char *
2942 op_symbol (const_tree op)
2944 return op_symbol_code (TREE_CODE (op));
2947 /* Prints the name of a call. NODE is the CALL_EXPR_FN of a CALL_EXPR or
2948 the gimple_call_fn of a GIMPLE_CALL. */
2950 void
2951 print_call_name (pretty_printer *buffer, tree node, int flags)
2953 tree op0 = node;
2955 if (TREE_CODE (op0) == NON_LVALUE_EXPR)
2956 op0 = TREE_OPERAND (op0, 0);
2958 again:
2959 switch (TREE_CODE (op0))
2961 case VAR_DECL:
2962 case PARM_DECL:
2963 case FUNCTION_DECL:
2964 dump_function_name (buffer, op0, flags);
2965 break;
2967 case ADDR_EXPR:
2968 case INDIRECT_REF:
2969 case NOP_EXPR:
2970 op0 = TREE_OPERAND (op0, 0);
2971 goto again;
2973 case COND_EXPR:
2974 pp_left_paren (buffer);
2975 dump_generic_node (buffer, TREE_OPERAND (op0, 0), 0, flags, false);
2976 pp_string (buffer, ") ? ");
2977 dump_generic_node (buffer, TREE_OPERAND (op0, 1), 0, flags, false);
2978 pp_string (buffer, " : ");
2979 dump_generic_node (buffer, TREE_OPERAND (op0, 2), 0, flags, false);
2980 break;
2982 case ARRAY_REF:
2983 if (TREE_CODE (TREE_OPERAND (op0, 0)) == VAR_DECL)
2984 dump_function_name (buffer, TREE_OPERAND (op0, 0), flags);
2985 else
2986 dump_generic_node (buffer, op0, 0, flags, false);
2987 break;
2989 case MEM_REF:
2990 if (integer_zerop (TREE_OPERAND (op0, 1)))
2992 op0 = TREE_OPERAND (op0, 0);
2993 goto again;
2995 /* Fallthru. */
2996 case COMPONENT_REF:
2997 case SSA_NAME:
2998 case OBJ_TYPE_REF:
2999 dump_generic_node (buffer, op0, 0, flags, false);
3000 break;
3002 default:
3003 NIY;
3007 /* Parses the string STR and replaces new-lines by '\n', tabs by '\t', ... */
3009 static void
3010 pretty_print_string (pretty_printer *buffer, const char *str)
3012 if (str == NULL)
3013 return;
3015 while (*str)
3017 switch (str[0])
3019 case '\b':
3020 pp_string (buffer, "\\b");
3021 break;
3023 case '\f':
3024 pp_string (buffer, "\\f");
3025 break;
3027 case '\n':
3028 pp_string (buffer, "\\n");
3029 break;
3031 case '\r':
3032 pp_string (buffer, "\\r");
3033 break;
3035 case '\t':
3036 pp_string (buffer, "\\t");
3037 break;
3039 case '\v':
3040 pp_string (buffer, "\\v");
3041 break;
3043 case '\\':
3044 pp_string (buffer, "\\\\");
3045 break;
3047 case '\"':
3048 pp_string (buffer, "\\\"");
3049 break;
3051 case '\'':
3052 pp_string (buffer, "\\'");
3053 break;
3055 /* No need to handle \0; the loop terminates on \0. */
3057 case '\1':
3058 pp_string (buffer, "\\1");
3059 break;
3061 case '\2':
3062 pp_string (buffer, "\\2");
3063 break;
3065 case '\3':
3066 pp_string (buffer, "\\3");
3067 break;
3069 case '\4':
3070 pp_string (buffer, "\\4");
3071 break;
3073 case '\5':
3074 pp_string (buffer, "\\5");
3075 break;
3077 case '\6':
3078 pp_string (buffer, "\\6");
3079 break;
3081 case '\7':
3082 pp_string (buffer, "\\7");
3083 break;
3085 default:
3086 pp_character (buffer, str[0]);
3087 break;
3089 str++;
3093 static void
3094 maybe_init_pretty_print (FILE *file)
3096 if (!initialized)
3098 new (&buffer) pretty_printer ();
3099 pp_needs_newline (&buffer) = true;
3100 pp_translate_identifiers (&buffer) = false;
3101 initialized = 1;
3104 buffer.buffer->stream = file;
3107 static void
3108 newline_and_indent (pretty_printer *buffer, int spc)
3110 pp_newline (buffer);
3111 INDENT (spc);
3114 /* Handle a %K format for TEXT. Separate from default_tree_printer so
3115 it can also be used in front ends.
3116 %K: a statement, from which EXPR_LOCATION and TREE_BLOCK will be recorded.
3119 void
3120 percent_K_format (text_info *text)
3122 tree t = va_arg (*text->args_ptr, tree), block;
3123 gcc_assert (text->locus != NULL);
3124 *text->locus = EXPR_LOCATION (t);
3125 gcc_assert (pp_ti_abstract_origin (text) != NULL);
3126 block = TREE_BLOCK (t);
3127 *pp_ti_abstract_origin (text) = NULL;
3128 while (block
3129 && TREE_CODE (block) == BLOCK
3130 && BLOCK_ABSTRACT_ORIGIN (block))
3132 tree ao = BLOCK_ABSTRACT_ORIGIN (block);
3134 while (TREE_CODE (ao) == BLOCK
3135 && BLOCK_ABSTRACT_ORIGIN (ao)
3136 && BLOCK_ABSTRACT_ORIGIN (ao) != ao)
3137 ao = BLOCK_ABSTRACT_ORIGIN (ao);
3139 if (TREE_CODE (ao) == FUNCTION_DECL)
3141 *pp_ti_abstract_origin (text) = block;
3142 break;
3144 block = BLOCK_SUPERCONTEXT (block);
3148 /* Print the identifier ID to PRETTY-PRINTER. */
3150 void
3151 pp_tree_identifier (pretty_printer *pp, tree id)
3153 if (pp_translate_identifiers (pp))
3155 const char *text = identifier_to_locale (IDENTIFIER_POINTER (id));
3156 pp_append_text (pp, text, text + strlen (text));
3158 else
3159 pp_append_text (pp, IDENTIFIER_POINTER (id),
3160 IDENTIFIER_POINTER (id) + IDENTIFIER_LENGTH (id));
3163 /* A helper function that is used to dump function information before the
3164 function dump. */
3166 void
3167 dump_function_header (FILE *dump_file, tree fdecl, int flags)
3169 const char *dname, *aname;
3170 struct cgraph_node *node = cgraph_get_node (fdecl);
3171 struct function *fun = DECL_STRUCT_FUNCTION (fdecl);
3173 dname = lang_hooks.decl_printable_name (fdecl, 2);
3175 if (DECL_ASSEMBLER_NAME_SET_P (fdecl))
3176 aname = (IDENTIFIER_POINTER
3177 (DECL_ASSEMBLER_NAME (fdecl)));
3178 else
3179 aname = "<unset-asm-name>";
3181 fprintf (dump_file, "\n;; Function %s (%s, funcdef_no=%d",
3182 dname, aname, fun->funcdef_no);
3183 if (!(flags & TDF_NOUID))
3184 fprintf (dump_file, ", decl_uid=%d", DECL_UID (fdecl));
3185 if (node)
3187 fprintf (dump_file, ", symbol_order=%d)%s\n\n", node->symbol.order,
3188 node->frequency == NODE_FREQUENCY_HOT
3189 ? " (hot)"
3190 : node->frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED
3191 ? " (unlikely executed)"
3192 : node->frequency == NODE_FREQUENCY_EXECUTED_ONCE
3193 ? " (executed once)"
3194 : "");
3196 else
3197 fprintf (dump_file, ")\n\n");