* friend.c (make_friend_class): Handle template template parameters.
[official-gcc.git] / gcc / tree-pretty-print.c
blob8bd483a3a0e412fa1bd637d16f681d277be32b93
1 /* Pretty formatting of GENERIC trees in C syntax.
2 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
3 2011 Free Software Foundation, Inc.
4 Adapted from c-pretty-print.c by Diego Novillo <dnovillo@redhat.com>
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "tree.h"
27 #include "tree-pretty-print.h"
28 #include "hashtab.h"
29 #include "tree-flow.h"
30 #include "langhooks.h"
31 #include "tree-iterator.h"
32 #include "tree-chrec.h"
33 #include "dumpfile.h"
34 #include "value-prof.h"
35 #include "predict.h"
37 /* Local functions, macros and variables. */
38 static const char *op_symbol (const_tree);
39 static void pretty_print_string (pretty_printer *, const char*);
40 static void newline_and_indent (pretty_printer *, int);
41 static void maybe_init_pretty_print (FILE *);
42 static void print_struct_decl (pretty_printer *, const_tree, int, int);
43 static void do_niy (pretty_printer *, const_tree);
45 #define INDENT(SPACE) do { \
46 int i; for (i = 0; i<SPACE; i++) pp_space (buffer); } while (0)
48 #define NIY do_niy(buffer,node)
50 static pretty_printer buffer;
51 static int initialized = 0;
53 /* Try to print something for an unknown tree code. */
55 static void
56 do_niy (pretty_printer *buffer, const_tree node)
58 int i, len;
60 pp_string (buffer, "<<< Unknown tree: ");
61 pp_string (buffer, tree_code_name[(int) TREE_CODE (node)]);
63 if (EXPR_P (node))
65 len = TREE_OPERAND_LENGTH (node);
66 for (i = 0; i < len; ++i)
68 newline_and_indent (buffer, 2);
69 dump_generic_node (buffer, TREE_OPERAND (node, i), 2, 0, false);
73 pp_string (buffer, " >>>");
76 /* Debugging function to print out a generic expression. */
78 DEBUG_FUNCTION void
79 debug_generic_expr (tree t)
81 print_generic_expr (stderr, t, TDF_VOPS|TDF_MEMSYMS);
82 fprintf (stderr, "\n");
85 /* Debugging function to print out a generic statement. */
87 DEBUG_FUNCTION void
88 debug_generic_stmt (tree t)
90 print_generic_stmt (stderr, t, TDF_VOPS|TDF_MEMSYMS);
91 fprintf (stderr, "\n");
94 /* Debugging function to print out a chain of trees . */
96 DEBUG_FUNCTION void
97 debug_tree_chain (tree t)
99 struct pointer_set_t *seen = pointer_set_create ();
101 while (t)
103 print_generic_expr (stderr, t, TDF_VOPS|TDF_MEMSYMS|TDF_UID);
104 fprintf (stderr, " ");
105 t = TREE_CHAIN (t);
106 if (pointer_set_insert (seen, t))
108 fprintf (stderr, "... [cycled back to ");
109 print_generic_expr (stderr, t, TDF_VOPS|TDF_MEMSYMS|TDF_UID);
110 fprintf (stderr, "]");
111 break;
114 fprintf (stderr, "\n");
116 pointer_set_destroy (seen);
119 /* Prints declaration DECL to the FILE with details specified by FLAGS. */
120 void
121 print_generic_decl (FILE *file, tree decl, int flags)
123 maybe_init_pretty_print (file);
124 print_declaration (&buffer, decl, 2, flags);
125 pp_write_text_to_stream (&buffer);
128 /* Print tree T, and its successors, on file FILE. FLAGS specifies details
129 to show in the dump. See TDF_* in dumpfile.h. */
131 void
132 print_generic_stmt (FILE *file, tree t, int flags)
134 maybe_init_pretty_print (file);
135 dump_generic_node (&buffer, t, 0, flags, true);
136 pp_newline_and_flush (&buffer);
139 /* Print tree T, and its successors, on file FILE. FLAGS specifies details
140 to show in the dump. See TDF_* in dumpfile.h. The output is indented by
141 INDENT spaces. */
143 void
144 print_generic_stmt_indented (FILE *file, tree t, int flags, int indent)
146 int i;
148 maybe_init_pretty_print (file);
150 for (i = 0; i < indent; i++)
151 pp_space (&buffer);
152 dump_generic_node (&buffer, t, indent, flags, true);
153 pp_newline_and_flush (&buffer);
156 /* Print a single expression T on file FILE. FLAGS specifies details to show
157 in the dump. See TDF_* in dumpfile.h. */
159 void
160 print_generic_expr (FILE *file, tree t, int flags)
162 maybe_init_pretty_print (file);
163 dump_generic_node (&buffer, t, 0, flags, false);
166 /* Dump the name of a _DECL node and its DECL_UID if TDF_UID is set
167 in FLAGS. */
169 static void
170 dump_decl_name (pretty_printer *buffer, tree node, int flags)
172 if (DECL_NAME (node))
174 if ((flags & TDF_ASMNAME) && DECL_ASSEMBLER_NAME_SET_P (node))
175 pp_tree_identifier (buffer, DECL_ASSEMBLER_NAME (node));
176 else
177 pp_tree_identifier (buffer, DECL_NAME (node));
179 if ((flags & TDF_UID) || DECL_NAME (node) == NULL_TREE)
181 if (TREE_CODE (node) == LABEL_DECL && LABEL_DECL_UID (node) != -1)
182 pp_printf (buffer, "L.%d", (int) LABEL_DECL_UID (node));
183 else if (TREE_CODE (node) == DEBUG_EXPR_DECL)
185 if (flags & TDF_NOUID)
186 pp_string (buffer, "D#xxxx");
187 else
188 pp_printf (buffer, "D#%i", DEBUG_TEMP_UID (node));
190 else
192 char c = TREE_CODE (node) == CONST_DECL ? 'C' : 'D';
193 if (flags & TDF_NOUID)
194 pp_printf (buffer, "%c.xxxx", c);
195 else
196 pp_printf (buffer, "%c.%u", c, DECL_UID (node));
199 if ((flags & TDF_ALIAS) && DECL_PT_UID (node) != DECL_UID (node))
201 if (flags & TDF_NOUID)
202 pp_printf (buffer, "ptD.xxxx");
203 else
204 pp_printf (buffer, "ptD.%u", DECL_PT_UID (node));
208 /* Like the above, but used for pretty printing function calls. */
210 static void
211 dump_function_name (pretty_printer *buffer, tree node, int flags)
213 if (TREE_CODE (node) == NOP_EXPR)
214 node = TREE_OPERAND (node, 0);
215 if (DECL_NAME (node) && (flags & TDF_ASMNAME) == 0)
216 pp_string (buffer, lang_hooks.decl_printable_name (node, 1));
217 else
218 dump_decl_name (buffer, node, flags);
221 /* Dump a function declaration. NODE is the FUNCTION_TYPE. BUFFER, SPC and
222 FLAGS are as in dump_generic_node. */
224 static void
225 dump_function_declaration (pretty_printer *buffer, tree node,
226 int spc, int flags)
228 bool wrote_arg = false;
229 tree arg;
231 pp_space (buffer);
232 pp_character (buffer, '(');
234 /* Print the argument types. */
235 arg = TYPE_ARG_TYPES (node);
236 while (arg && arg != void_list_node && arg != error_mark_node)
238 if (wrote_arg)
240 pp_character (buffer, ',');
241 pp_space (buffer);
243 wrote_arg = true;
244 dump_generic_node (buffer, TREE_VALUE (arg), spc, flags, false);
245 arg = TREE_CHAIN (arg);
248 /* Drop the trailing void_type_node if we had any previous argument. */
249 if (arg == void_list_node && !wrote_arg)
250 pp_string (buffer, "void");
251 /* Properly dump vararg function types. */
252 else if (!arg && wrote_arg)
253 pp_string (buffer, ", ...");
254 /* Avoid printing any arg for unprototyped functions. */
256 pp_character (buffer, ')');
259 /* Dump the domain associated with an array. */
261 static void
262 dump_array_domain (pretty_printer *buffer, tree domain, int spc, int flags)
264 pp_character (buffer, '[');
265 if (domain)
267 tree min = TYPE_MIN_VALUE (domain);
268 tree max = TYPE_MAX_VALUE (domain);
270 if (min && max
271 && integer_zerop (min)
272 && host_integerp (max, 0))
273 pp_wide_integer (buffer, TREE_INT_CST_LOW (max) + 1);
274 else
276 if (min)
277 dump_generic_node (buffer, min, spc, flags, false);
278 pp_character (buffer, ':');
279 if (max)
280 dump_generic_node (buffer, max, spc, flags, false);
283 else
284 pp_string (buffer, "<unknown>");
285 pp_character (buffer, ']');
289 /* Dump OpenMP clause CLAUSE. BUFFER, CLAUSE, SPC and FLAGS are as in
290 dump_generic_node. */
292 static void
293 dump_omp_clause (pretty_printer *buffer, tree clause, int spc, int flags)
295 const char *name;
297 switch (OMP_CLAUSE_CODE (clause))
299 case OMP_CLAUSE_PRIVATE:
300 name = "private";
301 goto print_remap;
302 case OMP_CLAUSE_SHARED:
303 name = "shared";
304 goto print_remap;
305 case OMP_CLAUSE_FIRSTPRIVATE:
306 name = "firstprivate";
307 goto print_remap;
308 case OMP_CLAUSE_LASTPRIVATE:
309 name = "lastprivate";
310 goto print_remap;
311 case OMP_CLAUSE_COPYIN:
312 name = "copyin";
313 goto print_remap;
314 case OMP_CLAUSE_COPYPRIVATE:
315 name = "copyprivate";
316 goto print_remap;
317 print_remap:
318 pp_string (buffer, name);
319 pp_character (buffer, '(');
320 dump_generic_node (buffer, OMP_CLAUSE_DECL (clause),
321 spc, flags, false);
322 pp_character (buffer, ')');
323 break;
325 case OMP_CLAUSE_REDUCTION:
326 pp_string (buffer, "reduction(");
327 pp_string (buffer, op_symbol_code (OMP_CLAUSE_REDUCTION_CODE (clause)));
328 pp_character (buffer, ':');
329 dump_generic_node (buffer, OMP_CLAUSE_DECL (clause),
330 spc, flags, false);
331 pp_character (buffer, ')');
332 break;
334 case OMP_CLAUSE_IF:
335 pp_string (buffer, "if(");
336 dump_generic_node (buffer, OMP_CLAUSE_IF_EXPR (clause),
337 spc, flags, false);
338 pp_character (buffer, ')');
339 break;
341 case OMP_CLAUSE_NUM_THREADS:
342 pp_string (buffer, "num_threads(");
343 dump_generic_node (buffer, OMP_CLAUSE_NUM_THREADS_EXPR (clause),
344 spc, flags, false);
345 pp_character (buffer, ')');
346 break;
348 case OMP_CLAUSE_NOWAIT:
349 pp_string (buffer, "nowait");
350 break;
351 case OMP_CLAUSE_ORDERED:
352 pp_string (buffer, "ordered");
353 break;
355 case OMP_CLAUSE_DEFAULT:
356 pp_string (buffer, "default(");
357 switch (OMP_CLAUSE_DEFAULT_KIND (clause))
359 case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
360 break;
361 case OMP_CLAUSE_DEFAULT_SHARED:
362 pp_string (buffer, "shared");
363 break;
364 case OMP_CLAUSE_DEFAULT_NONE:
365 pp_string (buffer, "none");
366 break;
367 case OMP_CLAUSE_DEFAULT_PRIVATE:
368 pp_string (buffer, "private");
369 break;
370 case OMP_CLAUSE_DEFAULT_FIRSTPRIVATE:
371 pp_string (buffer, "firstprivate");
372 break;
373 default:
374 gcc_unreachable ();
376 pp_character (buffer, ')');
377 break;
379 case OMP_CLAUSE_SCHEDULE:
380 pp_string (buffer, "schedule(");
381 switch (OMP_CLAUSE_SCHEDULE_KIND (clause))
383 case OMP_CLAUSE_SCHEDULE_STATIC:
384 pp_string (buffer, "static");
385 break;
386 case OMP_CLAUSE_SCHEDULE_DYNAMIC:
387 pp_string (buffer, "dynamic");
388 break;
389 case OMP_CLAUSE_SCHEDULE_GUIDED:
390 pp_string (buffer, "guided");
391 break;
392 case OMP_CLAUSE_SCHEDULE_RUNTIME:
393 pp_string (buffer, "runtime");
394 break;
395 case OMP_CLAUSE_SCHEDULE_AUTO:
396 pp_string (buffer, "auto");
397 break;
398 default:
399 gcc_unreachable ();
401 if (OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clause))
403 pp_character (buffer, ',');
404 dump_generic_node (buffer,
405 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clause),
406 spc, flags, false);
408 pp_character (buffer, ')');
409 break;
411 case OMP_CLAUSE_UNTIED:
412 pp_string (buffer, "untied");
413 break;
415 case OMP_CLAUSE_COLLAPSE:
416 pp_string (buffer, "collapse(");
417 dump_generic_node (buffer,
418 OMP_CLAUSE_COLLAPSE_EXPR (clause),
419 spc, flags, false);
420 pp_character (buffer, ')');
421 break;
423 case OMP_CLAUSE_FINAL:
424 pp_string (buffer, "final(");
425 dump_generic_node (buffer, OMP_CLAUSE_FINAL_EXPR (clause),
426 spc, flags, false);
427 pp_character (buffer, ')');
428 break;
430 case OMP_CLAUSE_MERGEABLE:
431 pp_string (buffer, "mergeable");
432 break;
434 default:
435 /* Should never happen. */
436 dump_generic_node (buffer, clause, spc, flags, false);
437 break;
442 /* Dump the list of OpenMP clauses. BUFFER, SPC and FLAGS are as in
443 dump_generic_node. */
445 void
446 dump_omp_clauses (pretty_printer *buffer, tree clause, int spc, int flags)
448 if (clause == NULL)
449 return;
451 pp_space (buffer);
452 while (1)
454 dump_omp_clause (buffer, clause, spc, flags);
455 clause = OMP_CLAUSE_CHAIN (clause);
456 if (clause == NULL)
457 return;
458 pp_space (buffer);
463 /* Dump location LOC to BUFFER. */
465 static void
466 dump_location (pretty_printer *buffer, location_t loc)
468 expanded_location xloc = expand_location (loc);
470 pp_character (buffer, '[');
471 if (xloc.file)
473 pp_string (buffer, xloc.file);
474 pp_string (buffer, " : ");
476 pp_decimal_int (buffer, xloc.line);
477 pp_string (buffer, "] ");
481 /* Dump lexical block BLOCK. BUFFER, SPC and FLAGS are as in
482 dump_generic_node. */
484 static void
485 dump_block_node (pretty_printer *buffer, tree block, int spc, int flags)
487 tree t;
489 pp_printf (buffer, "BLOCK #%d ", BLOCK_NUMBER (block));
491 if (flags & TDF_ADDRESS)
492 pp_printf (buffer, "[%p] ", (void *) block);
494 if (BLOCK_ABSTRACT (block))
495 pp_string (buffer, "[abstract] ");
497 if (TREE_ASM_WRITTEN (block))
498 pp_string (buffer, "[written] ");
500 if (flags & TDF_SLIM)
501 return;
503 if (BLOCK_SOURCE_LOCATION (block))
504 dump_location (buffer, BLOCK_SOURCE_LOCATION (block));
506 newline_and_indent (buffer, spc + 2);
508 if (BLOCK_SUPERCONTEXT (block))
510 pp_string (buffer, "SUPERCONTEXT: ");
511 dump_generic_node (buffer, BLOCK_SUPERCONTEXT (block), 0,
512 flags | TDF_SLIM, false);
513 newline_and_indent (buffer, spc + 2);
516 if (BLOCK_SUBBLOCKS (block))
518 pp_string (buffer, "SUBBLOCKS: ");
519 for (t = BLOCK_SUBBLOCKS (block); t; t = BLOCK_CHAIN (t))
521 dump_generic_node (buffer, t, 0, flags | TDF_SLIM, false);
522 pp_string (buffer, " ");
524 newline_and_indent (buffer, spc + 2);
527 if (BLOCK_CHAIN (block))
529 pp_string (buffer, "SIBLINGS: ");
530 for (t = BLOCK_CHAIN (block); t; t = BLOCK_CHAIN (t))
532 dump_generic_node (buffer, t, 0, flags | TDF_SLIM, false);
533 pp_string (buffer, " ");
535 newline_and_indent (buffer, spc + 2);
538 if (BLOCK_VARS (block))
540 pp_string (buffer, "VARS: ");
541 for (t = BLOCK_VARS (block); t; t = TREE_CHAIN (t))
543 dump_generic_node (buffer, t, 0, flags, false);
544 pp_string (buffer, " ");
546 newline_and_indent (buffer, spc + 2);
549 if (VEC_length (tree, BLOCK_NONLOCALIZED_VARS (block)) > 0)
551 unsigned i;
552 VEC(tree,gc) *nlv = BLOCK_NONLOCALIZED_VARS (block);
554 pp_string (buffer, "NONLOCALIZED_VARS: ");
555 FOR_EACH_VEC_ELT (tree, nlv, i, t)
557 dump_generic_node (buffer, t, 0, flags, false);
558 pp_string (buffer, " ");
560 newline_and_indent (buffer, spc + 2);
563 if (BLOCK_ABSTRACT_ORIGIN (block))
565 pp_string (buffer, "ABSTRACT_ORIGIN: ");
566 dump_generic_node (buffer, BLOCK_ABSTRACT_ORIGIN (block), 0,
567 flags | TDF_SLIM, false);
568 newline_and_indent (buffer, spc + 2);
571 if (BLOCK_FRAGMENT_ORIGIN (block))
573 pp_string (buffer, "FRAGMENT_ORIGIN: ");
574 dump_generic_node (buffer, BLOCK_FRAGMENT_ORIGIN (block), 0,
575 flags | TDF_SLIM, false);
576 newline_and_indent (buffer, spc + 2);
579 if (BLOCK_FRAGMENT_CHAIN (block))
581 pp_string (buffer, "FRAGMENT_CHAIN: ");
582 for (t = BLOCK_FRAGMENT_CHAIN (block); t; t = BLOCK_FRAGMENT_CHAIN (t))
584 dump_generic_node (buffer, t, 0, flags | TDF_SLIM, false);
585 pp_string (buffer, " ");
587 newline_and_indent (buffer, spc + 2);
592 /* Dump the node NODE on the pretty_printer BUFFER, SPC spaces of
593 indent. FLAGS specifies details to show in the dump (see TDF_* in
594 dumpfile.h). If IS_STMT is true, the object printed is considered
595 to be a statement and it is terminated by ';' if appropriate. */
598 dump_generic_node (pretty_printer *buffer, tree node, int spc, int flags,
599 bool is_stmt)
601 tree type;
602 tree op0, op1;
603 const char *str;
604 bool is_expr;
605 enum tree_code code;
607 if (node == NULL_TREE)
608 return spc;
610 is_expr = EXPR_P (node);
612 if (is_stmt && (flags & TDF_STMTADDR))
613 pp_printf (buffer, "<&%p> ", (void *)node);
615 if ((flags & TDF_LINENO) && EXPR_HAS_LOCATION (node))
616 dump_location (buffer, EXPR_LOCATION (node));
618 code = TREE_CODE (node);
619 switch (code)
621 case ERROR_MARK:
622 pp_string (buffer, "<<< error >>>");
623 break;
625 case IDENTIFIER_NODE:
626 pp_tree_identifier (buffer, node);
627 break;
629 case TREE_LIST:
630 while (node && node != error_mark_node)
632 if (TREE_PURPOSE (node))
634 dump_generic_node (buffer, TREE_PURPOSE (node), spc, flags, false);
635 pp_space (buffer);
637 dump_generic_node (buffer, TREE_VALUE (node), spc, flags, false);
638 node = TREE_CHAIN (node);
639 if (node && TREE_CODE (node) == TREE_LIST)
641 pp_character (buffer, ',');
642 pp_space (buffer);
645 break;
647 case TREE_BINFO:
648 dump_generic_node (buffer, BINFO_TYPE (node), spc, flags, false);
649 break;
651 case TREE_VEC:
653 size_t i;
654 if (TREE_VEC_LENGTH (node) > 0)
656 size_t len = TREE_VEC_LENGTH (node);
657 for (i = 0; i < len - 1; i++)
659 dump_generic_node (buffer, TREE_VEC_ELT (node, i), spc, flags,
660 false);
661 pp_character (buffer, ',');
662 pp_space (buffer);
664 dump_generic_node (buffer, TREE_VEC_ELT (node, len - 1), spc,
665 flags, false);
668 break;
670 case VOID_TYPE:
671 case INTEGER_TYPE:
672 case REAL_TYPE:
673 case FIXED_POINT_TYPE:
674 case COMPLEX_TYPE:
675 case VECTOR_TYPE:
676 case ENUMERAL_TYPE:
677 case BOOLEAN_TYPE:
679 unsigned int quals = TYPE_QUALS (node);
680 enum tree_code_class tclass;
682 if (quals & TYPE_QUAL_CONST)
683 pp_string (buffer, "const ");
684 else if (quals & TYPE_QUAL_VOLATILE)
685 pp_string (buffer, "volatile ");
686 else if (quals & TYPE_QUAL_RESTRICT)
687 pp_string (buffer, "restrict ");
689 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
691 pp_string (buffer, "<address-space-");
692 pp_decimal_int (buffer, TYPE_ADDR_SPACE (node));
693 pp_string (buffer, "> ");
696 tclass = TREE_CODE_CLASS (TREE_CODE (node));
698 if (tclass == tcc_declaration)
700 if (DECL_NAME (node))
701 dump_decl_name (buffer, node, flags);
702 else
703 pp_string (buffer, "<unnamed type decl>");
705 else if (tclass == tcc_type)
707 if (TYPE_NAME (node))
709 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
710 pp_tree_identifier (buffer, TYPE_NAME (node));
711 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
712 && DECL_NAME (TYPE_NAME (node)))
713 dump_decl_name (buffer, TYPE_NAME (node), flags);
714 else
715 pp_string (buffer, "<unnamed type>");
717 else if (TREE_CODE (node) == VECTOR_TYPE)
719 pp_string (buffer, "vector");
720 pp_character (buffer, '(');
721 pp_wide_integer (buffer, TYPE_VECTOR_SUBPARTS (node));
722 pp_string (buffer, ") ");
723 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
725 else if (TREE_CODE (node) == INTEGER_TYPE)
727 if (TYPE_PRECISION (node) == CHAR_TYPE_SIZE)
728 pp_string (buffer, (TYPE_UNSIGNED (node)
729 ? "unsigned char"
730 : "signed char"));
731 else if (TYPE_PRECISION (node) == SHORT_TYPE_SIZE)
732 pp_string (buffer, (TYPE_UNSIGNED (node)
733 ? "unsigned short"
734 : "signed short"));
735 else if (TYPE_PRECISION (node) == INT_TYPE_SIZE)
736 pp_string (buffer, (TYPE_UNSIGNED (node)
737 ? "unsigned int"
738 : "signed int"));
739 else if (TYPE_PRECISION (node) == LONG_TYPE_SIZE)
740 pp_string (buffer, (TYPE_UNSIGNED (node)
741 ? "unsigned long"
742 : "signed long"));
743 else if (TYPE_PRECISION (node) == LONG_LONG_TYPE_SIZE)
744 pp_string (buffer, (TYPE_UNSIGNED (node)
745 ? "unsigned long long"
746 : "signed long long"));
747 else if (TYPE_PRECISION (node) >= CHAR_TYPE_SIZE
748 && exact_log2 (TYPE_PRECISION (node)) != -1)
750 pp_string (buffer, (TYPE_UNSIGNED (node) ? "uint" : "int"));
751 pp_decimal_int (buffer, TYPE_PRECISION (node));
752 pp_string (buffer, "_t");
754 else
756 pp_string (buffer, (TYPE_UNSIGNED (node)
757 ? "<unnamed-unsigned:"
758 : "<unnamed-signed:"));
759 pp_decimal_int (buffer, TYPE_PRECISION (node));
760 pp_string (buffer, ">");
763 else if (TREE_CODE (node) == COMPLEX_TYPE)
765 pp_string (buffer, "__complex__ ");
766 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
768 else if (TREE_CODE (node) == REAL_TYPE)
770 pp_string (buffer, "<float:");
771 pp_decimal_int (buffer, TYPE_PRECISION (node));
772 pp_string (buffer, ">");
774 else if (TREE_CODE (node) == FIXED_POINT_TYPE)
776 pp_string (buffer, "<fixed-point-");
777 pp_string (buffer, TYPE_SATURATING (node) ? "sat:" : "nonsat:");
778 pp_decimal_int (buffer, TYPE_PRECISION (node));
779 pp_string (buffer, ">");
781 else if (TREE_CODE (node) == VOID_TYPE)
782 pp_string (buffer, "void");
783 else
784 pp_string (buffer, "<unnamed type>");
786 break;
789 case POINTER_TYPE:
790 case REFERENCE_TYPE:
791 str = (TREE_CODE (node) == POINTER_TYPE ? "*" : "&");
793 if (TREE_TYPE (node) == NULL)
795 pp_string (buffer, str);
796 pp_string (buffer, "<null type>");
798 else if (TREE_CODE (TREE_TYPE (node)) == FUNCTION_TYPE)
800 tree fnode = TREE_TYPE (node);
802 dump_generic_node (buffer, TREE_TYPE (fnode), spc, flags, false);
803 pp_space (buffer);
804 pp_character (buffer, '(');
805 pp_string (buffer, str);
806 if (TYPE_NAME (node) && DECL_NAME (TYPE_NAME (node)))
807 dump_decl_name (buffer, TYPE_NAME (node), flags);
808 else if (flags & TDF_NOUID)
809 pp_printf (buffer, "<Txxxx>");
810 else
811 pp_printf (buffer, "<T%x>", TYPE_UID (node));
813 pp_character (buffer, ')');
814 dump_function_declaration (buffer, fnode, spc, flags);
816 else
818 unsigned int quals = TYPE_QUALS (node);
820 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
821 pp_space (buffer);
822 pp_string (buffer, str);
824 if (quals & TYPE_QUAL_CONST)
825 pp_string (buffer, " const");
826 if (quals & TYPE_QUAL_VOLATILE)
827 pp_string (buffer, " volatile");
828 if (quals & TYPE_QUAL_RESTRICT)
829 pp_string (buffer, " restrict");
831 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
833 pp_string (buffer, " <address-space-");
834 pp_decimal_int (buffer, TYPE_ADDR_SPACE (node));
835 pp_string (buffer, ">");
838 if (TYPE_REF_CAN_ALIAS_ALL (node))
839 pp_string (buffer, " {ref-all}");
841 break;
843 case OFFSET_TYPE:
844 NIY;
845 break;
847 case MEM_REF:
849 if (integer_zerop (TREE_OPERAND (node, 1))
850 /* Dump the types of INTEGER_CSTs explicitly, for we can't
851 infer them and MEM_ATTR caching will share MEM_REFs
852 with differently-typed op0s. */
853 && TREE_CODE (TREE_OPERAND (node, 0)) != INTEGER_CST
854 /* Released SSA_NAMES have no TREE_TYPE. */
855 && TREE_TYPE (TREE_OPERAND (node, 0)) != NULL_TREE
856 /* Same pointer types, but ignoring POINTER_TYPE vs.
857 REFERENCE_TYPE. */
858 && (TREE_TYPE (TREE_TYPE (TREE_OPERAND (node, 0)))
859 == TREE_TYPE (TREE_TYPE (TREE_OPERAND (node, 1))))
860 && (TYPE_MODE (TREE_TYPE (TREE_OPERAND (node, 0)))
861 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (node, 1))))
862 && (TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (node, 0)))
863 == TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (node, 1))))
864 /* Same value types ignoring qualifiers. */
865 && (TYPE_MAIN_VARIANT (TREE_TYPE (node))
866 == TYPE_MAIN_VARIANT
867 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (node, 1))))))
869 if (TREE_CODE (TREE_OPERAND (node, 0)) != ADDR_EXPR)
871 pp_string (buffer, "*");
872 dump_generic_node (buffer, TREE_OPERAND (node, 0),
873 spc, flags, false);
875 else
876 dump_generic_node (buffer,
877 TREE_OPERAND (TREE_OPERAND (node, 0), 0),
878 spc, flags, false);
880 else
882 tree ptype;
884 pp_string (buffer, "MEM[");
885 pp_string (buffer, "(");
886 ptype = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (node, 1)));
887 dump_generic_node (buffer, ptype,
888 spc, flags | TDF_SLIM, false);
889 pp_string (buffer, ")");
890 dump_generic_node (buffer, TREE_OPERAND (node, 0),
891 spc, flags, false);
892 if (!integer_zerop (TREE_OPERAND (node, 1)))
894 pp_string (buffer, " + ");
895 dump_generic_node (buffer, TREE_OPERAND (node, 1),
896 spc, flags, false);
898 pp_string (buffer, "]");
900 break;
903 case TARGET_MEM_REF:
905 const char *sep = "";
906 tree tmp;
908 pp_string (buffer, "MEM[");
910 if (TREE_CODE (TMR_BASE (node)) == ADDR_EXPR)
912 pp_string (buffer, sep);
913 sep = ", ";
914 pp_string (buffer, "symbol: ");
915 dump_generic_node (buffer, TREE_OPERAND (TMR_BASE (node), 0),
916 spc, flags, false);
918 else
920 pp_string (buffer, sep);
921 sep = ", ";
922 pp_string (buffer, "base: ");
923 dump_generic_node (buffer, TMR_BASE (node), spc, flags, false);
925 tmp = TMR_INDEX2 (node);
926 if (tmp)
928 pp_string (buffer, sep);
929 sep = ", ";
930 pp_string (buffer, "base: ");
931 dump_generic_node (buffer, tmp, spc, flags, false);
933 tmp = TMR_INDEX (node);
934 if (tmp)
936 pp_string (buffer, sep);
937 sep = ", ";
938 pp_string (buffer, "index: ");
939 dump_generic_node (buffer, tmp, spc, flags, false);
941 tmp = TMR_STEP (node);
942 if (tmp)
944 pp_string (buffer, sep);
945 sep = ", ";
946 pp_string (buffer, "step: ");
947 dump_generic_node (buffer, tmp, spc, flags, false);
949 tmp = TMR_OFFSET (node);
950 if (tmp)
952 pp_string (buffer, sep);
953 sep = ", ";
954 pp_string (buffer, "offset: ");
955 dump_generic_node (buffer, tmp, spc, flags, false);
957 pp_string (buffer, "]");
959 break;
961 case ARRAY_TYPE:
963 tree tmp;
965 /* Print the innermost component type. */
966 for (tmp = TREE_TYPE (node); TREE_CODE (tmp) == ARRAY_TYPE;
967 tmp = TREE_TYPE (tmp))
969 dump_generic_node (buffer, tmp, spc, flags, false);
971 /* Print the dimensions. */
972 for (tmp = node; TREE_CODE (tmp) == ARRAY_TYPE; tmp = TREE_TYPE (tmp))
973 dump_array_domain (buffer, TYPE_DOMAIN (tmp), spc, flags);
974 break;
977 case RECORD_TYPE:
978 case UNION_TYPE:
979 case QUAL_UNION_TYPE:
981 unsigned int quals = TYPE_QUALS (node);
983 if (quals & TYPE_QUAL_CONST)
984 pp_string (buffer, "const ");
985 if (quals & TYPE_QUAL_VOLATILE)
986 pp_string (buffer, "volatile ");
988 /* Print the name of the structure. */
989 if (TREE_CODE (node) == RECORD_TYPE)
990 pp_string (buffer, "struct ");
991 else if (TREE_CODE (node) == UNION_TYPE)
992 pp_string (buffer, "union ");
994 if (TYPE_NAME (node))
995 dump_generic_node (buffer, TYPE_NAME (node), spc, flags, false);
996 else if (!(flags & TDF_SLIM))
997 /* FIXME: If we eliminate the 'else' above and attempt
998 to show the fields for named types, we may get stuck
999 following a cycle of pointers to structs. The alleged
1000 self-reference check in print_struct_decl will not detect
1001 cycles involving more than one pointer or struct type. */
1002 print_struct_decl (buffer, node, spc, flags);
1003 break;
1006 case LANG_TYPE:
1007 NIY;
1008 break;
1010 case INTEGER_CST:
1011 if (TREE_CODE (TREE_TYPE (node)) == POINTER_TYPE)
1013 /* In the case of a pointer, one may want to divide by the
1014 size of the pointed-to type. Unfortunately, this not
1015 straightforward. The C front-end maps expressions
1017 (int *) 5
1018 int *p; (p + 5)
1020 in such a way that the two INTEGER_CST nodes for "5" have
1021 different values but identical types. In the latter
1022 case, the 5 is multiplied by sizeof (int) in c-common.c
1023 (pointer_int_sum) to convert it to a byte address, and
1024 yet the type of the node is left unchanged. Argh. What
1025 is consistent though is that the number value corresponds
1026 to bytes (UNITS) offset.
1028 NB: Neither of the following divisors can be trivially
1029 used to recover the original literal:
1031 TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (node)))
1032 TYPE_PRECISION (TREE_TYPE (TREE_TYPE (node))) */
1033 pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
1034 pp_string (buffer, "B"); /* pseudo-unit */
1036 else if (host_integerp (node, 0))
1037 pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
1038 else if (host_integerp (node, 1))
1039 pp_unsigned_wide_integer (buffer, TREE_INT_CST_LOW (node));
1040 else
1042 tree val = node;
1043 unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (val);
1044 HOST_WIDE_INT high = TREE_INT_CST_HIGH (val);
1046 if (tree_int_cst_sgn (val) < 0)
1048 pp_character (buffer, '-');
1049 high = ~high + !low;
1050 low = -low;
1052 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
1053 systems? */
1054 sprintf (pp_buffer (buffer)->digit_buffer,
1055 HOST_WIDE_INT_PRINT_DOUBLE_HEX,
1056 (unsigned HOST_WIDE_INT) high, low);
1057 pp_string (buffer, pp_buffer (buffer)->digit_buffer);
1059 break;
1061 case REAL_CST:
1062 /* Code copied from print_node. */
1064 REAL_VALUE_TYPE d;
1065 if (TREE_OVERFLOW (node))
1066 pp_string (buffer, " overflow");
1068 #if !defined(REAL_IS_NOT_DOUBLE) || defined(REAL_ARITHMETIC)
1069 d = TREE_REAL_CST (node);
1070 if (REAL_VALUE_ISINF (d))
1071 pp_string (buffer, REAL_VALUE_NEGATIVE (d) ? " -Inf" : " Inf");
1072 else if (REAL_VALUE_ISNAN (d))
1073 pp_string (buffer, " Nan");
1074 else
1076 char string[100];
1077 real_to_decimal (string, &d, sizeof (string), 0, 1);
1078 pp_string (buffer, string);
1080 #else
1082 HOST_WIDE_INT i;
1083 unsigned char *p = (unsigned char *) &TREE_REAL_CST (node);
1084 pp_string (buffer, "0x");
1085 for (i = 0; i < sizeof TREE_REAL_CST (node); i++)
1086 output_formatted_integer (buffer, "%02x", *p++);
1088 #endif
1089 break;
1092 case FIXED_CST:
1094 char string[100];
1095 fixed_to_decimal (string, TREE_FIXED_CST_PTR (node), sizeof (string));
1096 pp_string (buffer, string);
1097 break;
1100 case COMPLEX_CST:
1101 pp_string (buffer, "__complex__ (");
1102 dump_generic_node (buffer, TREE_REALPART (node), spc, flags, false);
1103 pp_string (buffer, ", ");
1104 dump_generic_node (buffer, TREE_IMAGPART (node), spc, flags, false);
1105 pp_string (buffer, ")");
1106 break;
1108 case STRING_CST:
1109 pp_string (buffer, "\"");
1110 pretty_print_string (buffer, TREE_STRING_POINTER (node));
1111 pp_string (buffer, "\"");
1112 break;
1114 case VECTOR_CST:
1116 unsigned i;
1117 pp_string (buffer, "{ ");
1118 for (i = 0; i < VECTOR_CST_NELTS (node); ++i)
1120 if (i != 0)
1121 pp_string (buffer, ", ");
1122 dump_generic_node (buffer, VECTOR_CST_ELT (node, i),
1123 spc, flags, false);
1125 pp_string (buffer, " }");
1127 break;
1129 case FUNCTION_TYPE:
1130 case METHOD_TYPE:
1131 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1132 pp_space (buffer);
1133 if (TREE_CODE (node) == METHOD_TYPE)
1135 if (TYPE_METHOD_BASETYPE (node))
1136 dump_decl_name (buffer, TYPE_NAME (TYPE_METHOD_BASETYPE (node)),
1137 flags);
1138 else
1139 pp_string (buffer, "<null method basetype>");
1140 pp_string (buffer, "::");
1142 if (TYPE_NAME (node) && DECL_NAME (TYPE_NAME (node)))
1143 dump_decl_name (buffer, TYPE_NAME (node), flags);
1144 else if (flags & TDF_NOUID)
1145 pp_printf (buffer, "<Txxxx>");
1146 else
1147 pp_printf (buffer, "<T%x>", TYPE_UID (node));
1148 dump_function_declaration (buffer, node, spc, flags);
1149 break;
1151 case FUNCTION_DECL:
1152 case CONST_DECL:
1153 dump_decl_name (buffer, node, flags);
1154 break;
1156 case LABEL_DECL:
1157 if (DECL_NAME (node))
1158 dump_decl_name (buffer, node, flags);
1159 else if (LABEL_DECL_UID (node) != -1)
1160 pp_printf (buffer, "<L%d>", (int) LABEL_DECL_UID (node));
1161 else
1163 if (flags & TDF_NOUID)
1164 pp_string (buffer, "<D.xxxx>");
1165 else
1166 pp_printf (buffer, "<D.%u>", DECL_UID (node));
1168 break;
1170 case TYPE_DECL:
1171 if (DECL_IS_BUILTIN (node))
1173 /* Don't print the declaration of built-in types. */
1174 break;
1176 if (DECL_NAME (node))
1177 dump_decl_name (buffer, node, flags);
1178 else if (TYPE_NAME (TREE_TYPE (node)) != node)
1180 if ((TREE_CODE (TREE_TYPE (node)) == RECORD_TYPE
1181 || TREE_CODE (TREE_TYPE (node)) == UNION_TYPE)
1182 && TYPE_METHODS (TREE_TYPE (node)))
1184 /* The type is a c++ class: all structures have at least
1185 4 methods. */
1186 pp_string (buffer, "class ");
1187 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1189 else
1191 pp_string (buffer,
1192 (TREE_CODE (TREE_TYPE (node)) == UNION_TYPE
1193 ? "union" : "struct "));
1194 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1197 else
1198 pp_string (buffer, "<anon>");
1199 break;
1201 case VAR_DECL:
1202 case PARM_DECL:
1203 case FIELD_DECL:
1204 case DEBUG_EXPR_DECL:
1205 case NAMESPACE_DECL:
1206 dump_decl_name (buffer, node, flags);
1207 break;
1209 case RESULT_DECL:
1210 pp_string (buffer, "<retval>");
1211 break;
1213 case COMPONENT_REF:
1214 op0 = TREE_OPERAND (node, 0);
1215 str = ".";
1216 if (op0
1217 && (TREE_CODE (op0) == INDIRECT_REF
1218 || (TREE_CODE (op0) == MEM_REF
1219 && TREE_CODE (TREE_OPERAND (op0, 0)) != ADDR_EXPR
1220 && integer_zerop (TREE_OPERAND (op0, 1))
1221 /* Dump the types of INTEGER_CSTs explicitly, for we
1222 can't infer them and MEM_ATTR caching will share
1223 MEM_REFs with differently-typed op0s. */
1224 && TREE_CODE (TREE_OPERAND (op0, 0)) != INTEGER_CST
1225 /* Released SSA_NAMES have no TREE_TYPE. */
1226 && TREE_TYPE (TREE_OPERAND (op0, 0)) != NULL_TREE
1227 /* Same pointer types, but ignoring POINTER_TYPE vs.
1228 REFERENCE_TYPE. */
1229 && (TREE_TYPE (TREE_TYPE (TREE_OPERAND (op0, 0)))
1230 == TREE_TYPE (TREE_TYPE (TREE_OPERAND (op0, 1))))
1231 && (TYPE_MODE (TREE_TYPE (TREE_OPERAND (op0, 0)))
1232 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (op0, 1))))
1233 && (TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (op0, 0)))
1234 == TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (op0, 1))))
1235 /* Same value types ignoring qualifiers. */
1236 && (TYPE_MAIN_VARIANT (TREE_TYPE (op0))
1237 == TYPE_MAIN_VARIANT
1238 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (op0, 1))))))))
1240 op0 = TREE_OPERAND (op0, 0);
1241 str = "->";
1243 if (op_prio (op0) < op_prio (node))
1244 pp_character (buffer, '(');
1245 dump_generic_node (buffer, op0, spc, flags, false);
1246 if (op_prio (op0) < op_prio (node))
1247 pp_character (buffer, ')');
1248 pp_string (buffer, str);
1249 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1250 op0 = component_ref_field_offset (node);
1251 if (op0 && TREE_CODE (op0) != INTEGER_CST)
1253 pp_string (buffer, "{off: ");
1254 dump_generic_node (buffer, op0, spc, flags, false);
1255 pp_character (buffer, '}');
1257 break;
1259 case BIT_FIELD_REF:
1260 pp_string (buffer, "BIT_FIELD_REF <");
1261 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1262 pp_string (buffer, ", ");
1263 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1264 pp_string (buffer, ", ");
1265 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
1266 pp_string (buffer, ">");
1267 break;
1269 case ARRAY_REF:
1270 case ARRAY_RANGE_REF:
1271 op0 = TREE_OPERAND (node, 0);
1272 if (op_prio (op0) < op_prio (node))
1273 pp_character (buffer, '(');
1274 dump_generic_node (buffer, op0, spc, flags, false);
1275 if (op_prio (op0) < op_prio (node))
1276 pp_character (buffer, ')');
1277 pp_character (buffer, '[');
1278 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1279 if (TREE_CODE (node) == ARRAY_RANGE_REF)
1280 pp_string (buffer, " ...");
1281 pp_character (buffer, ']');
1283 op0 = array_ref_low_bound (node);
1284 op1 = array_ref_element_size (node);
1286 if (!integer_zerop (op0)
1287 || TREE_OPERAND (node, 2)
1288 || TREE_OPERAND (node, 3))
1290 pp_string (buffer, "{lb: ");
1291 dump_generic_node (buffer, op0, spc, flags, false);
1292 pp_string (buffer, " sz: ");
1293 dump_generic_node (buffer, op1, spc, flags, false);
1294 pp_character (buffer, '}');
1296 break;
1298 case CONSTRUCTOR:
1300 unsigned HOST_WIDE_INT ix;
1301 tree field, val;
1302 bool is_struct_init = false;
1303 bool is_array_init = false;
1304 double_int curidx = double_int_zero;
1305 pp_character (buffer, '{');
1306 if (TREE_CLOBBER_P (node))
1307 pp_string (buffer, "CLOBBER");
1308 else if (TREE_CODE (TREE_TYPE (node)) == RECORD_TYPE
1309 || TREE_CODE (TREE_TYPE (node)) == UNION_TYPE)
1310 is_struct_init = true;
1311 else if (TREE_CODE (TREE_TYPE (node)) == ARRAY_TYPE
1312 && TYPE_DOMAIN (TREE_TYPE (node))
1313 && TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (node)))
1314 && TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (node))))
1315 == INTEGER_CST)
1317 tree minv = TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (node)));
1318 is_array_init = true;
1319 curidx = tree_to_double_int (minv);
1321 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (node), ix, field, val)
1323 if (field)
1325 if (is_struct_init)
1327 pp_character (buffer, '.');
1328 dump_generic_node (buffer, field, spc, flags, false);
1329 pp_character (buffer, '=');
1331 else if (is_array_init
1332 && (TREE_CODE (field) != INTEGER_CST
1333 || !double_int_equal_p (tree_to_double_int (field),
1334 curidx)))
1336 pp_character (buffer, '[');
1337 if (TREE_CODE (field) == RANGE_EXPR)
1339 dump_generic_node (buffer, TREE_OPERAND (field, 0), spc,
1340 flags, false);
1341 pp_string (buffer, " ... ");
1342 dump_generic_node (buffer, TREE_OPERAND (field, 1), spc,
1343 flags, false);
1344 if (TREE_CODE (TREE_OPERAND (field, 1)) == INTEGER_CST)
1345 curidx = tree_to_double_int (TREE_OPERAND (field, 1));
1347 else
1348 dump_generic_node (buffer, field, spc, flags, false);
1349 if (TREE_CODE (field) == INTEGER_CST)
1350 curidx = tree_to_double_int (field);
1351 pp_string (buffer, "]=");
1354 if (is_array_init)
1355 curidx = double_int_add (curidx, double_int_one);
1356 if (val && TREE_CODE (val) == ADDR_EXPR)
1357 if (TREE_CODE (TREE_OPERAND (val, 0)) == FUNCTION_DECL)
1358 val = TREE_OPERAND (val, 0);
1359 if (val && TREE_CODE (val) == FUNCTION_DECL)
1360 dump_decl_name (buffer, val, flags);
1361 else
1362 dump_generic_node (buffer, val, spc, flags, false);
1363 if (ix != VEC_length (constructor_elt, CONSTRUCTOR_ELTS (node)) - 1)
1365 pp_character (buffer, ',');
1366 pp_space (buffer);
1369 pp_character (buffer, '}');
1371 break;
1373 case COMPOUND_EXPR:
1375 tree *tp;
1376 if (flags & TDF_SLIM)
1378 pp_string (buffer, "<COMPOUND_EXPR>");
1379 break;
1382 dump_generic_node (buffer, TREE_OPERAND (node, 0),
1383 spc, flags, !(flags & TDF_SLIM));
1384 if (flags & TDF_SLIM)
1385 newline_and_indent (buffer, spc);
1386 else
1388 pp_character (buffer, ',');
1389 pp_space (buffer);
1392 for (tp = &TREE_OPERAND (node, 1);
1393 TREE_CODE (*tp) == COMPOUND_EXPR;
1394 tp = &TREE_OPERAND (*tp, 1))
1396 dump_generic_node (buffer, TREE_OPERAND (*tp, 0),
1397 spc, flags, !(flags & TDF_SLIM));
1398 if (flags & TDF_SLIM)
1399 newline_and_indent (buffer, spc);
1400 else
1402 pp_character (buffer, ',');
1403 pp_space (buffer);
1407 dump_generic_node (buffer, *tp, spc, flags, !(flags & TDF_SLIM));
1409 break;
1411 case STATEMENT_LIST:
1413 tree_stmt_iterator si;
1414 bool first = true;
1416 if (flags & TDF_SLIM)
1418 pp_string (buffer, "<STATEMENT_LIST>");
1419 break;
1422 for (si = tsi_start (node); !tsi_end_p (si); tsi_next (&si))
1424 if (!first)
1425 newline_and_indent (buffer, spc);
1426 else
1427 first = false;
1428 dump_generic_node (buffer, tsi_stmt (si), spc, flags, true);
1431 break;
1433 case MODIFY_EXPR:
1434 case INIT_EXPR:
1435 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags,
1436 false);
1437 pp_space (buffer);
1438 pp_character (buffer, '=');
1439 if (TREE_CODE (node) == MODIFY_EXPR
1440 && MOVE_NONTEMPORAL (node))
1441 pp_string (buffer, "{nt}");
1442 pp_space (buffer);
1443 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags,
1444 false);
1445 break;
1447 case TARGET_EXPR:
1448 pp_string (buffer, "TARGET_EXPR <");
1449 dump_generic_node (buffer, TARGET_EXPR_SLOT (node), spc, flags, false);
1450 pp_character (buffer, ',');
1451 pp_space (buffer);
1452 dump_generic_node (buffer, TARGET_EXPR_INITIAL (node), spc, flags, false);
1453 pp_character (buffer, '>');
1454 break;
1456 case DECL_EXPR:
1457 print_declaration (buffer, DECL_EXPR_DECL (node), spc, flags);
1458 is_stmt = false;
1459 break;
1461 case COND_EXPR:
1462 if (TREE_TYPE (node) == NULL || TREE_TYPE (node) == void_type_node)
1464 pp_string (buffer, "if (");
1465 dump_generic_node (buffer, COND_EXPR_COND (node), spc, flags, false);
1466 pp_character (buffer, ')');
1467 /* The lowered cond_exprs should always be printed in full. */
1468 if (COND_EXPR_THEN (node)
1469 && (IS_EMPTY_STMT (COND_EXPR_THEN (node))
1470 || TREE_CODE (COND_EXPR_THEN (node)) == GOTO_EXPR)
1471 && COND_EXPR_ELSE (node)
1472 && (IS_EMPTY_STMT (COND_EXPR_ELSE (node))
1473 || TREE_CODE (COND_EXPR_ELSE (node)) == GOTO_EXPR))
1475 pp_space (buffer);
1476 dump_generic_node (buffer, COND_EXPR_THEN (node),
1477 0, flags, true);
1478 if (!IS_EMPTY_STMT (COND_EXPR_ELSE (node)))
1480 pp_string (buffer, " else ");
1481 dump_generic_node (buffer, COND_EXPR_ELSE (node),
1482 0, flags, true);
1485 else if (!(flags & TDF_SLIM))
1487 /* Output COND_EXPR_THEN. */
1488 if (COND_EXPR_THEN (node))
1490 newline_and_indent (buffer, spc+2);
1491 pp_character (buffer, '{');
1492 newline_and_indent (buffer, spc+4);
1493 dump_generic_node (buffer, COND_EXPR_THEN (node), spc+4,
1494 flags, true);
1495 newline_and_indent (buffer, spc+2);
1496 pp_character (buffer, '}');
1499 /* Output COND_EXPR_ELSE. */
1500 if (COND_EXPR_ELSE (node)
1501 && !IS_EMPTY_STMT (COND_EXPR_ELSE (node)))
1503 newline_and_indent (buffer, spc);
1504 pp_string (buffer, "else");
1505 newline_and_indent (buffer, spc+2);
1506 pp_character (buffer, '{');
1507 newline_and_indent (buffer, spc+4);
1508 dump_generic_node (buffer, COND_EXPR_ELSE (node), spc+4,
1509 flags, true);
1510 newline_and_indent (buffer, spc+2);
1511 pp_character (buffer, '}');
1514 is_expr = false;
1516 else
1518 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1519 pp_space (buffer);
1520 pp_character (buffer, '?');
1521 pp_space (buffer);
1522 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1523 pp_space (buffer);
1524 pp_character (buffer, ':');
1525 pp_space (buffer);
1526 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
1528 break;
1530 case BIND_EXPR:
1531 pp_character (buffer, '{');
1532 if (!(flags & TDF_SLIM))
1534 if (BIND_EXPR_VARS (node))
1536 pp_newline (buffer);
1538 for (op0 = BIND_EXPR_VARS (node); op0; op0 = DECL_CHAIN (op0))
1540 print_declaration (buffer, op0, spc+2, flags);
1541 pp_newline (buffer);
1545 newline_and_indent (buffer, spc+2);
1546 dump_generic_node (buffer, BIND_EXPR_BODY (node), spc+2, flags, true);
1547 newline_and_indent (buffer, spc);
1548 pp_character (buffer, '}');
1550 is_expr = false;
1551 break;
1553 case CALL_EXPR:
1554 print_call_name (buffer, CALL_EXPR_FN (node), flags);
1556 /* Print parameters. */
1557 pp_space (buffer);
1558 pp_character (buffer, '(');
1560 tree arg;
1561 call_expr_arg_iterator iter;
1562 FOR_EACH_CALL_EXPR_ARG (arg, iter, node)
1564 dump_generic_node (buffer, arg, spc, flags, false);
1565 if (more_call_expr_args_p (&iter))
1567 pp_character (buffer, ',');
1568 pp_space (buffer);
1572 if (CALL_EXPR_VA_ARG_PACK (node))
1574 if (call_expr_nargs (node) > 0)
1576 pp_character (buffer, ',');
1577 pp_space (buffer);
1579 pp_string (buffer, "__builtin_va_arg_pack ()");
1581 pp_character (buffer, ')');
1583 op1 = CALL_EXPR_STATIC_CHAIN (node);
1584 if (op1)
1586 pp_string (buffer, " [static-chain: ");
1587 dump_generic_node (buffer, op1, spc, flags, false);
1588 pp_character (buffer, ']');
1591 if (CALL_EXPR_RETURN_SLOT_OPT (node))
1592 pp_string (buffer, " [return slot optimization]");
1593 if (CALL_EXPR_TAILCALL (node))
1594 pp_string (buffer, " [tail call]");
1595 break;
1597 case WITH_CLEANUP_EXPR:
1598 NIY;
1599 break;
1601 case CLEANUP_POINT_EXPR:
1602 pp_string (buffer, "<<cleanup_point ");
1603 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1604 pp_string (buffer, ">>");
1605 break;
1607 case PLACEHOLDER_EXPR:
1608 pp_string (buffer, "<PLACEHOLDER_EXPR ");
1609 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1610 pp_character (buffer, '>');
1611 break;
1613 /* Binary arithmetic and logic expressions. */
1614 case WIDEN_SUM_EXPR:
1615 case WIDEN_MULT_EXPR:
1616 case MULT_EXPR:
1617 case MULT_HIGHPART_EXPR:
1618 case PLUS_EXPR:
1619 case POINTER_PLUS_EXPR:
1620 case MINUS_EXPR:
1621 case TRUNC_DIV_EXPR:
1622 case CEIL_DIV_EXPR:
1623 case FLOOR_DIV_EXPR:
1624 case ROUND_DIV_EXPR:
1625 case TRUNC_MOD_EXPR:
1626 case CEIL_MOD_EXPR:
1627 case FLOOR_MOD_EXPR:
1628 case ROUND_MOD_EXPR:
1629 case RDIV_EXPR:
1630 case EXACT_DIV_EXPR:
1631 case LSHIFT_EXPR:
1632 case RSHIFT_EXPR:
1633 case LROTATE_EXPR:
1634 case RROTATE_EXPR:
1635 case VEC_LSHIFT_EXPR:
1636 case VEC_RSHIFT_EXPR:
1637 case WIDEN_LSHIFT_EXPR:
1638 case BIT_IOR_EXPR:
1639 case BIT_XOR_EXPR:
1640 case BIT_AND_EXPR:
1641 case TRUTH_ANDIF_EXPR:
1642 case TRUTH_ORIF_EXPR:
1643 case TRUTH_AND_EXPR:
1644 case TRUTH_OR_EXPR:
1645 case TRUTH_XOR_EXPR:
1646 case LT_EXPR:
1647 case LE_EXPR:
1648 case GT_EXPR:
1649 case GE_EXPR:
1650 case EQ_EXPR:
1651 case NE_EXPR:
1652 case UNLT_EXPR:
1653 case UNLE_EXPR:
1654 case UNGT_EXPR:
1655 case UNGE_EXPR:
1656 case UNEQ_EXPR:
1657 case LTGT_EXPR:
1658 case ORDERED_EXPR:
1659 case UNORDERED_EXPR:
1661 const char *op = op_symbol (node);
1662 op0 = TREE_OPERAND (node, 0);
1663 op1 = TREE_OPERAND (node, 1);
1665 /* When the operands are expressions with less priority,
1666 keep semantics of the tree representation. */
1667 if (op_prio (op0) <= op_prio (node))
1669 pp_character (buffer, '(');
1670 dump_generic_node (buffer, op0, spc, flags, false);
1671 pp_character (buffer, ')');
1673 else
1674 dump_generic_node (buffer, op0, spc, flags, false);
1676 pp_space (buffer);
1677 pp_string (buffer, op);
1678 pp_space (buffer);
1680 /* When the operands are expressions with less priority,
1681 keep semantics of the tree representation. */
1682 if (op_prio (op1) <= op_prio (node))
1684 pp_character (buffer, '(');
1685 dump_generic_node (buffer, op1, spc, flags, false);
1686 pp_character (buffer, ')');
1688 else
1689 dump_generic_node (buffer, op1, spc, flags, false);
1691 break;
1693 /* Unary arithmetic and logic expressions. */
1694 case NEGATE_EXPR:
1695 case BIT_NOT_EXPR:
1696 case TRUTH_NOT_EXPR:
1697 case ADDR_EXPR:
1698 case PREDECREMENT_EXPR:
1699 case PREINCREMENT_EXPR:
1700 case INDIRECT_REF:
1701 if (TREE_CODE (node) == ADDR_EXPR
1702 && (TREE_CODE (TREE_OPERAND (node, 0)) == STRING_CST
1703 || TREE_CODE (TREE_OPERAND (node, 0)) == FUNCTION_DECL))
1704 ; /* Do not output '&' for strings and function pointers. */
1705 else
1706 pp_string (buffer, op_symbol (node));
1708 if (op_prio (TREE_OPERAND (node, 0)) < op_prio (node))
1710 pp_character (buffer, '(');
1711 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1712 pp_character (buffer, ')');
1714 else
1715 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1716 break;
1718 case POSTDECREMENT_EXPR:
1719 case POSTINCREMENT_EXPR:
1720 if (op_prio (TREE_OPERAND (node, 0)) < op_prio (node))
1722 pp_character (buffer, '(');
1723 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1724 pp_character (buffer, ')');
1726 else
1727 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1728 pp_string (buffer, op_symbol (node));
1729 break;
1731 case MIN_EXPR:
1732 pp_string (buffer, "MIN_EXPR <");
1733 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1734 pp_string (buffer, ", ");
1735 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1736 pp_character (buffer, '>');
1737 break;
1739 case MAX_EXPR:
1740 pp_string (buffer, "MAX_EXPR <");
1741 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1742 pp_string (buffer, ", ");
1743 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1744 pp_character (buffer, '>');
1745 break;
1747 case ABS_EXPR:
1748 pp_string (buffer, "ABS_EXPR <");
1749 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1750 pp_character (buffer, '>');
1751 break;
1753 case RANGE_EXPR:
1754 NIY;
1755 break;
1757 case ADDR_SPACE_CONVERT_EXPR:
1758 case FIXED_CONVERT_EXPR:
1759 case FIX_TRUNC_EXPR:
1760 case FLOAT_EXPR:
1761 CASE_CONVERT:
1762 type = TREE_TYPE (node);
1763 op0 = TREE_OPERAND (node, 0);
1764 if (type != TREE_TYPE (op0))
1766 pp_character (buffer, '(');
1767 dump_generic_node (buffer, type, spc, flags, false);
1768 pp_string (buffer, ") ");
1770 if (op_prio (op0) < op_prio (node))
1771 pp_character (buffer, '(');
1772 dump_generic_node (buffer, op0, spc, flags, false);
1773 if (op_prio (op0) < op_prio (node))
1774 pp_character (buffer, ')');
1775 break;
1777 case VIEW_CONVERT_EXPR:
1778 pp_string (buffer, "VIEW_CONVERT_EXPR<");
1779 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1780 pp_string (buffer, ">(");
1781 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1782 pp_character (buffer, ')');
1783 break;
1785 case PAREN_EXPR:
1786 pp_string (buffer, "((");
1787 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1788 pp_string (buffer, "))");
1789 break;
1791 case NON_LVALUE_EXPR:
1792 pp_string (buffer, "NON_LVALUE_EXPR <");
1793 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1794 pp_character (buffer, '>');
1795 break;
1797 case SAVE_EXPR:
1798 pp_string (buffer, "SAVE_EXPR <");
1799 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1800 pp_character (buffer, '>');
1801 break;
1803 case COMPLEX_EXPR:
1804 pp_string (buffer, "COMPLEX_EXPR <");
1805 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1806 pp_string (buffer, ", ");
1807 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1808 pp_string (buffer, ">");
1809 break;
1811 case CONJ_EXPR:
1812 pp_string (buffer, "CONJ_EXPR <");
1813 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1814 pp_string (buffer, ">");
1815 break;
1817 case REALPART_EXPR:
1818 pp_string (buffer, "REALPART_EXPR <");
1819 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1820 pp_string (buffer, ">");
1821 break;
1823 case IMAGPART_EXPR:
1824 pp_string (buffer, "IMAGPART_EXPR <");
1825 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1826 pp_string (buffer, ">");
1827 break;
1829 case VA_ARG_EXPR:
1830 pp_string (buffer, "VA_ARG_EXPR <");
1831 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1832 pp_string (buffer, ">");
1833 break;
1835 case TRY_FINALLY_EXPR:
1836 case TRY_CATCH_EXPR:
1837 pp_string (buffer, "try");
1838 newline_and_indent (buffer, spc+2);
1839 pp_string (buffer, "{");
1840 newline_and_indent (buffer, spc+4);
1841 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc+4, flags, true);
1842 newline_and_indent (buffer, spc+2);
1843 pp_string (buffer, "}");
1844 newline_and_indent (buffer, spc);
1845 pp_string (buffer,
1846 (TREE_CODE (node) == TRY_CATCH_EXPR) ? "catch" : "finally");
1847 newline_and_indent (buffer, spc+2);
1848 pp_string (buffer, "{");
1849 newline_and_indent (buffer, spc+4);
1850 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc+4, flags, true);
1851 newline_and_indent (buffer, spc+2);
1852 pp_string (buffer, "}");
1853 is_expr = false;
1854 break;
1856 case CATCH_EXPR:
1857 pp_string (buffer, "catch (");
1858 dump_generic_node (buffer, CATCH_TYPES (node), spc+2, flags, false);
1859 pp_string (buffer, ")");
1860 newline_and_indent (buffer, spc+2);
1861 pp_string (buffer, "{");
1862 newline_and_indent (buffer, spc+4);
1863 dump_generic_node (buffer, CATCH_BODY (node), spc+4, flags, true);
1864 newline_and_indent (buffer, spc+2);
1865 pp_string (buffer, "}");
1866 is_expr = false;
1867 break;
1869 case EH_FILTER_EXPR:
1870 pp_string (buffer, "<<<eh_filter (");
1871 dump_generic_node (buffer, EH_FILTER_TYPES (node), spc+2, flags, false);
1872 pp_string (buffer, ")>>>");
1873 newline_and_indent (buffer, spc+2);
1874 pp_string (buffer, "{");
1875 newline_and_indent (buffer, spc+4);
1876 dump_generic_node (buffer, EH_FILTER_FAILURE (node), spc+4, flags, true);
1877 newline_and_indent (buffer, spc+2);
1878 pp_string (buffer, "}");
1879 is_expr = false;
1880 break;
1882 case LABEL_EXPR:
1883 op0 = TREE_OPERAND (node, 0);
1884 /* If this is for break or continue, don't bother printing it. */
1885 if (DECL_NAME (op0))
1887 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1888 if (strcmp (name, "break") == 0
1889 || strcmp (name, "continue") == 0)
1890 break;
1892 dump_generic_node (buffer, op0, spc, flags, false);
1893 pp_character (buffer, ':');
1894 if (DECL_NONLOCAL (op0))
1895 pp_string (buffer, " [non-local]");
1896 break;
1898 case LOOP_EXPR:
1899 pp_string (buffer, "while (1)");
1900 if (!(flags & TDF_SLIM))
1902 newline_and_indent (buffer, spc+2);
1903 pp_character (buffer, '{');
1904 newline_and_indent (buffer, spc+4);
1905 dump_generic_node (buffer, LOOP_EXPR_BODY (node), spc+4, flags, true);
1906 newline_and_indent (buffer, spc+2);
1907 pp_character (buffer, '}');
1909 is_expr = false;
1910 break;
1912 case PREDICT_EXPR:
1913 pp_string (buffer, "// predicted ");
1914 if (PREDICT_EXPR_OUTCOME (node))
1915 pp_string (buffer, "likely by ");
1916 else
1917 pp_string (buffer, "unlikely by ");
1918 pp_string (buffer, predictor_name (PREDICT_EXPR_PREDICTOR (node)));
1919 pp_string (buffer, " predictor.");
1920 break;
1922 case RETURN_EXPR:
1923 pp_string (buffer, "return");
1924 op0 = TREE_OPERAND (node, 0);
1925 if (op0)
1927 pp_space (buffer);
1928 if (TREE_CODE (op0) == MODIFY_EXPR)
1929 dump_generic_node (buffer, TREE_OPERAND (op0, 1),
1930 spc, flags, false);
1931 else
1932 dump_generic_node (buffer, op0, spc, flags, false);
1934 break;
1936 case EXIT_EXPR:
1937 pp_string (buffer, "if (");
1938 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1939 pp_string (buffer, ") break");
1940 break;
1942 case SWITCH_EXPR:
1943 pp_string (buffer, "switch (");
1944 dump_generic_node (buffer, SWITCH_COND (node), spc, flags, false);
1945 pp_character (buffer, ')');
1946 if (!(flags & TDF_SLIM))
1948 newline_and_indent (buffer, spc+2);
1949 pp_character (buffer, '{');
1950 if (SWITCH_BODY (node))
1952 newline_and_indent (buffer, spc+4);
1953 dump_generic_node (buffer, SWITCH_BODY (node), spc+4, flags,
1954 true);
1956 else
1958 tree vec = SWITCH_LABELS (node);
1959 size_t i, n = TREE_VEC_LENGTH (vec);
1960 for (i = 0; i < n; ++i)
1962 tree elt = TREE_VEC_ELT (vec, i);
1963 newline_and_indent (buffer, spc+4);
1964 if (elt)
1966 dump_generic_node (buffer, elt, spc+4, flags, false);
1967 pp_string (buffer, " goto ");
1968 dump_generic_node (buffer, CASE_LABEL (elt), spc+4,
1969 flags, true);
1970 pp_semicolon (buffer);
1972 else
1973 pp_string (buffer, "case ???: goto ???;");
1976 newline_and_indent (buffer, spc+2);
1977 pp_character (buffer, '}');
1979 is_expr = false;
1980 break;
1982 case GOTO_EXPR:
1983 op0 = GOTO_DESTINATION (node);
1984 if (TREE_CODE (op0) != SSA_NAME && DECL_P (op0) && DECL_NAME (op0))
1986 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1987 if (strcmp (name, "break") == 0
1988 || strcmp (name, "continue") == 0)
1990 pp_string (buffer, name);
1991 break;
1994 pp_string (buffer, "goto ");
1995 dump_generic_node (buffer, op0, spc, flags, false);
1996 break;
1998 case ASM_EXPR:
1999 pp_string (buffer, "__asm__");
2000 if (ASM_VOLATILE_P (node))
2001 pp_string (buffer, " __volatile__");
2002 pp_character (buffer, '(');
2003 dump_generic_node (buffer, ASM_STRING (node), spc, flags, false);
2004 pp_character (buffer, ':');
2005 dump_generic_node (buffer, ASM_OUTPUTS (node), spc, flags, false);
2006 pp_character (buffer, ':');
2007 dump_generic_node (buffer, ASM_INPUTS (node), spc, flags, false);
2008 if (ASM_CLOBBERS (node))
2010 pp_character (buffer, ':');
2011 dump_generic_node (buffer, ASM_CLOBBERS (node), spc, flags, false);
2013 pp_string (buffer, ")");
2014 break;
2016 case CASE_LABEL_EXPR:
2017 if (CASE_LOW (node) && CASE_HIGH (node))
2019 pp_string (buffer, "case ");
2020 dump_generic_node (buffer, CASE_LOW (node), spc, flags, false);
2021 pp_string (buffer, " ... ");
2022 dump_generic_node (buffer, CASE_HIGH (node), spc, flags, false);
2024 else if (CASE_LOW (node))
2026 pp_string (buffer, "case ");
2027 dump_generic_node (buffer, CASE_LOW (node), spc, flags, false);
2029 else
2030 pp_string (buffer, "default");
2031 pp_character (buffer, ':');
2032 break;
2034 case OBJ_TYPE_REF:
2035 pp_string (buffer, "OBJ_TYPE_REF(");
2036 dump_generic_node (buffer, OBJ_TYPE_REF_EXPR (node), spc, flags, false);
2037 pp_character (buffer, ';');
2038 dump_generic_node (buffer, OBJ_TYPE_REF_OBJECT (node), spc, flags, false);
2039 pp_character (buffer, '-');
2040 pp_character (buffer, '>');
2041 dump_generic_node (buffer, OBJ_TYPE_REF_TOKEN (node), spc, flags, false);
2042 pp_character (buffer, ')');
2043 break;
2045 case SSA_NAME:
2046 if (SSA_NAME_IDENTIFIER (node))
2047 dump_generic_node (buffer, SSA_NAME_IDENTIFIER (node),
2048 spc, flags, false);
2049 pp_string (buffer, "_");
2050 pp_decimal_int (buffer, SSA_NAME_VERSION (node));
2051 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (node))
2052 pp_string (buffer, "(ab)");
2053 else if (SSA_NAME_IS_DEFAULT_DEF (node))
2054 pp_string (buffer, "(D)");
2055 break;
2057 case WITH_SIZE_EXPR:
2058 pp_string (buffer, "WITH_SIZE_EXPR <");
2059 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2060 pp_string (buffer, ", ");
2061 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2062 pp_string (buffer, ">");
2063 break;
2065 case ASSERT_EXPR:
2066 pp_string (buffer, "ASSERT_EXPR <");
2067 dump_generic_node (buffer, ASSERT_EXPR_VAR (node), spc, flags, false);
2068 pp_string (buffer, ", ");
2069 dump_generic_node (buffer, ASSERT_EXPR_COND (node), spc, flags, false);
2070 pp_string (buffer, ">");
2071 break;
2073 case SCEV_KNOWN:
2074 pp_string (buffer, "scev_known");
2075 break;
2077 case SCEV_NOT_KNOWN:
2078 pp_string (buffer, "scev_not_known");
2079 break;
2081 case POLYNOMIAL_CHREC:
2082 pp_string (buffer, "{");
2083 dump_generic_node (buffer, CHREC_LEFT (node), spc, flags, false);
2084 pp_string (buffer, ", +, ");
2085 dump_generic_node (buffer, CHREC_RIGHT (node), spc, flags, false);
2086 pp_string (buffer, "}_");
2087 dump_generic_node (buffer, CHREC_VAR (node), spc, flags, false);
2088 is_stmt = false;
2089 break;
2091 case REALIGN_LOAD_EXPR:
2092 pp_string (buffer, "REALIGN_LOAD <");
2093 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2094 pp_string (buffer, ", ");
2095 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2096 pp_string (buffer, ", ");
2097 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2098 pp_string (buffer, ">");
2099 break;
2101 case VEC_COND_EXPR:
2102 pp_string (buffer, " VEC_COND_EXPR < ");
2103 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2104 pp_string (buffer, " , ");
2105 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2106 pp_string (buffer, " , ");
2107 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2108 pp_string (buffer, " > ");
2109 break;
2111 case VEC_PERM_EXPR:
2112 pp_string (buffer, " VEC_PERM_EXPR < ");
2113 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2114 pp_string (buffer, " , ");
2115 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2116 pp_string (buffer, " , ");
2117 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2118 pp_string (buffer, " > ");
2119 break;
2121 case DOT_PROD_EXPR:
2122 pp_string (buffer, " DOT_PROD_EXPR < ");
2123 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2124 pp_string (buffer, ", ");
2125 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2126 pp_string (buffer, ", ");
2127 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2128 pp_string (buffer, " > ");
2129 break;
2131 case WIDEN_MULT_PLUS_EXPR:
2132 pp_string (buffer, " WIDEN_MULT_PLUS_EXPR < ");
2133 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2134 pp_string (buffer, ", ");
2135 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2136 pp_string (buffer, ", ");
2137 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2138 pp_string (buffer, " > ");
2139 break;
2141 case WIDEN_MULT_MINUS_EXPR:
2142 pp_string (buffer, " WIDEN_MULT_MINUS_EXPR < ");
2143 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2144 pp_string (buffer, ", ");
2145 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2146 pp_string (buffer, ", ");
2147 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2148 pp_string (buffer, " > ");
2149 break;
2151 case FMA_EXPR:
2152 pp_string (buffer, " FMA_EXPR < ");
2153 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2154 pp_string (buffer, ", ");
2155 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2156 pp_string (buffer, ", ");
2157 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2158 pp_string (buffer, " > ");
2159 break;
2161 case OMP_PARALLEL:
2162 pp_string (buffer, "#pragma omp parallel");
2163 dump_omp_clauses (buffer, OMP_PARALLEL_CLAUSES (node), spc, flags);
2165 dump_omp_body:
2166 if (!(flags & TDF_SLIM) && OMP_BODY (node))
2168 newline_and_indent (buffer, spc + 2);
2169 pp_character (buffer, '{');
2170 newline_and_indent (buffer, spc + 4);
2171 dump_generic_node (buffer, OMP_BODY (node), spc + 4, flags, false);
2172 newline_and_indent (buffer, spc + 2);
2173 pp_character (buffer, '}');
2175 is_expr = false;
2176 break;
2178 case OMP_TASK:
2179 pp_string (buffer, "#pragma omp task");
2180 dump_omp_clauses (buffer, OMP_TASK_CLAUSES (node), spc, flags);
2181 goto dump_omp_body;
2183 case OMP_FOR:
2184 pp_string (buffer, "#pragma omp for");
2185 dump_omp_clauses (buffer, OMP_FOR_CLAUSES (node), spc, flags);
2187 if (!(flags & TDF_SLIM))
2189 int i;
2191 if (OMP_FOR_PRE_BODY (node))
2193 newline_and_indent (buffer, spc + 2);
2194 pp_character (buffer, '{');
2195 spc += 4;
2196 newline_and_indent (buffer, spc);
2197 dump_generic_node (buffer, OMP_FOR_PRE_BODY (node),
2198 spc, flags, false);
2200 spc -= 2;
2201 for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (node)); i++)
2203 spc += 2;
2204 newline_and_indent (buffer, spc);
2205 pp_string (buffer, "for (");
2206 dump_generic_node (buffer, TREE_VEC_ELT (OMP_FOR_INIT (node), i),
2207 spc, flags, false);
2208 pp_string (buffer, "; ");
2209 dump_generic_node (buffer, TREE_VEC_ELT (OMP_FOR_COND (node), i),
2210 spc, flags, false);
2211 pp_string (buffer, "; ");
2212 dump_generic_node (buffer, TREE_VEC_ELT (OMP_FOR_INCR (node), i),
2213 spc, flags, false);
2214 pp_string (buffer, ")");
2216 if (OMP_FOR_BODY (node))
2218 newline_and_indent (buffer, spc + 2);
2219 pp_character (buffer, '{');
2220 newline_and_indent (buffer, spc + 4);
2221 dump_generic_node (buffer, OMP_FOR_BODY (node), spc + 4, flags,
2222 false);
2223 newline_and_indent (buffer, spc + 2);
2224 pp_character (buffer, '}');
2226 spc -= 2 * TREE_VEC_LENGTH (OMP_FOR_INIT (node)) - 2;
2227 if (OMP_FOR_PRE_BODY (node))
2229 spc -= 4;
2230 newline_and_indent (buffer, spc + 2);
2231 pp_character (buffer, '}');
2234 is_expr = false;
2235 break;
2237 case OMP_SECTIONS:
2238 pp_string (buffer, "#pragma omp sections");
2239 dump_omp_clauses (buffer, OMP_SECTIONS_CLAUSES (node), spc, flags);
2240 goto dump_omp_body;
2242 case OMP_SECTION:
2243 pp_string (buffer, "#pragma omp section");
2244 goto dump_omp_body;
2246 case OMP_MASTER:
2247 pp_string (buffer, "#pragma omp master");
2248 goto dump_omp_body;
2250 case OMP_ORDERED:
2251 pp_string (buffer, "#pragma omp ordered");
2252 goto dump_omp_body;
2254 case OMP_CRITICAL:
2255 pp_string (buffer, "#pragma omp critical");
2256 if (OMP_CRITICAL_NAME (node))
2258 pp_space (buffer);
2259 pp_character (buffer, '(');
2260 dump_generic_node (buffer, OMP_CRITICAL_NAME (node), spc,
2261 flags, false);
2262 pp_character (buffer, ')');
2264 goto dump_omp_body;
2266 case OMP_ATOMIC:
2267 pp_string (buffer, "#pragma omp atomic");
2268 newline_and_indent (buffer, spc + 2);
2269 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2270 pp_space (buffer);
2271 pp_character (buffer, '=');
2272 pp_space (buffer);
2273 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2274 break;
2276 case OMP_ATOMIC_READ:
2277 pp_string (buffer, "#pragma omp atomic read");
2278 newline_and_indent (buffer, spc + 2);
2279 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2280 pp_space (buffer);
2281 break;
2283 case OMP_ATOMIC_CAPTURE_OLD:
2284 case OMP_ATOMIC_CAPTURE_NEW:
2285 pp_string (buffer, "#pragma omp atomic capture");
2286 newline_and_indent (buffer, spc + 2);
2287 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2288 pp_space (buffer);
2289 pp_character (buffer, '=');
2290 pp_space (buffer);
2291 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2292 break;
2294 case OMP_SINGLE:
2295 pp_string (buffer, "#pragma omp single");
2296 dump_omp_clauses (buffer, OMP_SINGLE_CLAUSES (node), spc, flags);
2297 goto dump_omp_body;
2299 case OMP_CLAUSE:
2300 dump_omp_clause (buffer, node, spc, flags);
2301 is_expr = false;
2302 break;
2304 case TRANSACTION_EXPR:
2305 if (TRANSACTION_EXPR_OUTER (node))
2306 pp_string (buffer, "__transaction_atomic [[outer]]");
2307 else if (TRANSACTION_EXPR_RELAXED (node))
2308 pp_string (buffer, "__transaction_relaxed");
2309 else
2310 pp_string (buffer, "__transaction_atomic");
2311 if (!(flags & TDF_SLIM) && TRANSACTION_EXPR_BODY (node))
2313 newline_and_indent (buffer, spc);
2314 pp_character (buffer, '{');
2315 newline_and_indent (buffer, spc + 2);
2316 dump_generic_node (buffer, TRANSACTION_EXPR_BODY (node),
2317 spc + 2, flags, false);
2318 newline_and_indent (buffer, spc);
2319 pp_character (buffer, '}');
2321 is_expr = false;
2322 break;
2324 case REDUC_MAX_EXPR:
2325 pp_string (buffer, " REDUC_MAX_EXPR < ");
2326 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2327 pp_string (buffer, " > ");
2328 break;
2330 case REDUC_MIN_EXPR:
2331 pp_string (buffer, " REDUC_MIN_EXPR < ");
2332 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2333 pp_string (buffer, " > ");
2334 break;
2336 case REDUC_PLUS_EXPR:
2337 pp_string (buffer, " REDUC_PLUS_EXPR < ");
2338 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2339 pp_string (buffer, " > ");
2340 break;
2342 case VEC_WIDEN_MULT_HI_EXPR:
2343 case VEC_WIDEN_MULT_LO_EXPR:
2344 case VEC_WIDEN_MULT_EVEN_EXPR:
2345 case VEC_WIDEN_MULT_ODD_EXPR:
2346 case VEC_WIDEN_LSHIFT_HI_EXPR:
2347 case VEC_WIDEN_LSHIFT_LO_EXPR:
2348 pp_character (buffer, ' ');
2349 for (str = tree_code_name [code]; *str; str++)
2350 pp_character (buffer, TOUPPER (*str));
2351 pp_string (buffer, " < ");
2352 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2353 pp_string (buffer, ", ");
2354 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2355 pp_string (buffer, " > ");
2356 break;
2358 case VEC_UNPACK_HI_EXPR:
2359 pp_string (buffer, " VEC_UNPACK_HI_EXPR < ");
2360 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2361 pp_string (buffer, " > ");
2362 break;
2364 case VEC_UNPACK_LO_EXPR:
2365 pp_string (buffer, " VEC_UNPACK_LO_EXPR < ");
2366 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2367 pp_string (buffer, " > ");
2368 break;
2370 case VEC_UNPACK_FLOAT_HI_EXPR:
2371 pp_string (buffer, " VEC_UNPACK_FLOAT_HI_EXPR < ");
2372 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2373 pp_string (buffer, " > ");
2374 break;
2376 case VEC_UNPACK_FLOAT_LO_EXPR:
2377 pp_string (buffer, " VEC_UNPACK_FLOAT_LO_EXPR < ");
2378 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2379 pp_string (buffer, " > ");
2380 break;
2382 case VEC_PACK_TRUNC_EXPR:
2383 pp_string (buffer, " VEC_PACK_TRUNC_EXPR < ");
2384 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2385 pp_string (buffer, ", ");
2386 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2387 pp_string (buffer, " > ");
2388 break;
2390 case VEC_PACK_SAT_EXPR:
2391 pp_string (buffer, " VEC_PACK_SAT_EXPR < ");
2392 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2393 pp_string (buffer, ", ");
2394 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2395 pp_string (buffer, " > ");
2396 break;
2398 case VEC_PACK_FIX_TRUNC_EXPR:
2399 pp_string (buffer, " VEC_PACK_FIX_TRUNC_EXPR < ");
2400 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2401 pp_string (buffer, ", ");
2402 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2403 pp_string (buffer, " > ");
2404 break;
2406 case BLOCK:
2407 dump_block_node (buffer, node, spc, flags);
2408 break;
2410 default:
2411 NIY;
2414 if (is_stmt && is_expr)
2415 pp_semicolon (buffer);
2417 /* If we're building a diagnostic, the formatted text will be written
2418 into BUFFER's stream by the caller; otherwise, write it now. */
2419 if (!(flags & TDF_DIAGNOSTIC))
2420 pp_write_text_to_stream (buffer);
2422 return spc;
2425 /* Print the declaration of a variable. */
2427 void
2428 print_declaration (pretty_printer *buffer, tree t, int spc, int flags)
2430 INDENT (spc);
2432 if (TREE_CODE (t) == TYPE_DECL)
2433 pp_string (buffer, "typedef ");
2435 if (CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_DECL_WRTL) && DECL_REGISTER (t))
2436 pp_string (buffer, "register ");
2438 if (TREE_PUBLIC (t) && DECL_EXTERNAL (t))
2439 pp_string (buffer, "extern ");
2440 else if (TREE_STATIC (t))
2441 pp_string (buffer, "static ");
2443 /* Print the type and name. */
2444 if (TREE_TYPE (t) && TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
2446 tree tmp;
2448 /* Print array's type. */
2449 tmp = TREE_TYPE (t);
2450 while (TREE_CODE (TREE_TYPE (tmp)) == ARRAY_TYPE)
2451 tmp = TREE_TYPE (tmp);
2452 dump_generic_node (buffer, TREE_TYPE (tmp), spc, flags, false);
2454 /* Print variable's name. */
2455 pp_space (buffer);
2456 dump_generic_node (buffer, t, spc, flags, false);
2458 /* Print the dimensions. */
2459 tmp = TREE_TYPE (t);
2460 while (TREE_CODE (tmp) == ARRAY_TYPE)
2462 dump_array_domain (buffer, TYPE_DOMAIN (tmp), spc, flags);
2463 tmp = TREE_TYPE (tmp);
2466 else if (TREE_CODE (t) == FUNCTION_DECL)
2468 dump_generic_node (buffer, TREE_TYPE (TREE_TYPE (t)), spc, flags, false);
2469 pp_space (buffer);
2470 dump_decl_name (buffer, t, flags);
2471 dump_function_declaration (buffer, TREE_TYPE (t), spc, flags);
2473 else
2475 /* Print type declaration. */
2476 dump_generic_node (buffer, TREE_TYPE (t), spc, flags, false);
2478 /* Print variable's name. */
2479 pp_space (buffer);
2480 dump_generic_node (buffer, t, spc, flags, false);
2483 if (TREE_CODE (t) == VAR_DECL && DECL_HARD_REGISTER (t))
2485 pp_string (buffer, " __asm__ ");
2486 pp_character (buffer, '(');
2487 dump_generic_node (buffer, DECL_ASSEMBLER_NAME (t), spc, flags, false);
2488 pp_character (buffer, ')');
2491 /* The initial value of a function serves to determine whether the function
2492 is declared or defined. So the following does not apply to function
2493 nodes. */
2494 if (TREE_CODE (t) != FUNCTION_DECL)
2496 /* Print the initial value. */
2497 if (DECL_INITIAL (t))
2499 pp_space (buffer);
2500 pp_character (buffer, '=');
2501 pp_space (buffer);
2502 dump_generic_node (buffer, DECL_INITIAL (t), spc, flags, false);
2506 if (TREE_CODE (t) == VAR_DECL && DECL_HAS_VALUE_EXPR_P (t))
2508 pp_string (buffer, " [value-expr: ");
2509 dump_generic_node (buffer, DECL_VALUE_EXPR (t), spc, flags, false);
2510 pp_character (buffer, ']');
2513 pp_character (buffer, ';');
2517 /* Prints a structure: name, fields, and methods.
2518 FIXME: Still incomplete. */
2520 static void
2521 print_struct_decl (pretty_printer *buffer, const_tree node, int spc, int flags)
2523 /* Print the name of the structure. */
2524 if (TYPE_NAME (node))
2526 INDENT (spc);
2527 if (TREE_CODE (node) == RECORD_TYPE)
2528 pp_string (buffer, "struct ");
2529 else if ((TREE_CODE (node) == UNION_TYPE
2530 || TREE_CODE (node) == QUAL_UNION_TYPE))
2531 pp_string (buffer, "union ");
2533 dump_generic_node (buffer, TYPE_NAME (node), spc, 0, false);
2536 /* Print the contents of the structure. */
2537 pp_newline (buffer);
2538 INDENT (spc);
2539 pp_character (buffer, '{');
2540 pp_newline (buffer);
2542 /* Print the fields of the structure. */
2544 tree tmp;
2545 tmp = TYPE_FIELDS (node);
2546 while (tmp)
2548 /* Avoid to print recursively the structure. */
2549 /* FIXME : Not implemented correctly...,
2550 what about the case when we have a cycle in the contain graph? ...
2551 Maybe this could be solved by looking at the scope in which the
2552 structure was declared. */
2553 if (TREE_TYPE (tmp) != node
2554 && (TREE_CODE (TREE_TYPE (tmp)) != POINTER_TYPE
2555 || TREE_TYPE (TREE_TYPE (tmp)) != node))
2557 print_declaration (buffer, tmp, spc+2, flags);
2558 pp_newline (buffer);
2560 tmp = DECL_CHAIN (tmp);
2563 INDENT (spc);
2564 pp_character (buffer, '}');
2567 /* Return the priority of the operator CODE.
2569 From lowest to highest precedence with either left-to-right (L-R)
2570 or right-to-left (R-L) associativity]:
2572 1 [L-R] ,
2573 2 [R-L] = += -= *= /= %= &= ^= |= <<= >>=
2574 3 [R-L] ?:
2575 4 [L-R] ||
2576 5 [L-R] &&
2577 6 [L-R] |
2578 7 [L-R] ^
2579 8 [L-R] &
2580 9 [L-R] == !=
2581 10 [L-R] < <= > >=
2582 11 [L-R] << >>
2583 12 [L-R] + -
2584 13 [L-R] * / %
2585 14 [R-L] ! ~ ++ -- + - * & (type) sizeof
2586 15 [L-R] fn() [] -> .
2588 unary +, - and * have higher precedence than the corresponding binary
2589 operators. */
2592 op_code_prio (enum tree_code code)
2594 switch (code)
2596 case TREE_LIST:
2597 case COMPOUND_EXPR:
2598 case BIND_EXPR:
2599 return 1;
2601 case MODIFY_EXPR:
2602 case INIT_EXPR:
2603 return 2;
2605 case COND_EXPR:
2606 return 3;
2608 case TRUTH_OR_EXPR:
2609 case TRUTH_ORIF_EXPR:
2610 return 4;
2612 case TRUTH_AND_EXPR:
2613 case TRUTH_ANDIF_EXPR:
2614 return 5;
2616 case BIT_IOR_EXPR:
2617 return 6;
2619 case BIT_XOR_EXPR:
2620 case TRUTH_XOR_EXPR:
2621 return 7;
2623 case BIT_AND_EXPR:
2624 return 8;
2626 case EQ_EXPR:
2627 case NE_EXPR:
2628 return 9;
2630 case UNLT_EXPR:
2631 case UNLE_EXPR:
2632 case UNGT_EXPR:
2633 case UNGE_EXPR:
2634 case UNEQ_EXPR:
2635 case LTGT_EXPR:
2636 case ORDERED_EXPR:
2637 case UNORDERED_EXPR:
2638 case LT_EXPR:
2639 case LE_EXPR:
2640 case GT_EXPR:
2641 case GE_EXPR:
2642 return 10;
2644 case LSHIFT_EXPR:
2645 case RSHIFT_EXPR:
2646 case LROTATE_EXPR:
2647 case RROTATE_EXPR:
2648 case VEC_WIDEN_LSHIFT_HI_EXPR:
2649 case VEC_WIDEN_LSHIFT_LO_EXPR:
2650 case WIDEN_LSHIFT_EXPR:
2651 return 11;
2653 case WIDEN_SUM_EXPR:
2654 case PLUS_EXPR:
2655 case POINTER_PLUS_EXPR:
2656 case MINUS_EXPR:
2657 return 12;
2659 case VEC_WIDEN_MULT_HI_EXPR:
2660 case VEC_WIDEN_MULT_LO_EXPR:
2661 case WIDEN_MULT_EXPR:
2662 case DOT_PROD_EXPR:
2663 case WIDEN_MULT_PLUS_EXPR:
2664 case WIDEN_MULT_MINUS_EXPR:
2665 case MULT_EXPR:
2666 case MULT_HIGHPART_EXPR:
2667 case TRUNC_DIV_EXPR:
2668 case CEIL_DIV_EXPR:
2669 case FLOOR_DIV_EXPR:
2670 case ROUND_DIV_EXPR:
2671 case RDIV_EXPR:
2672 case EXACT_DIV_EXPR:
2673 case TRUNC_MOD_EXPR:
2674 case CEIL_MOD_EXPR:
2675 case FLOOR_MOD_EXPR:
2676 case ROUND_MOD_EXPR:
2677 case FMA_EXPR:
2678 return 13;
2680 case TRUTH_NOT_EXPR:
2681 case BIT_NOT_EXPR:
2682 case POSTINCREMENT_EXPR:
2683 case POSTDECREMENT_EXPR:
2684 case PREINCREMENT_EXPR:
2685 case PREDECREMENT_EXPR:
2686 case NEGATE_EXPR:
2687 case INDIRECT_REF:
2688 case ADDR_EXPR:
2689 case FLOAT_EXPR:
2690 CASE_CONVERT:
2691 case FIX_TRUNC_EXPR:
2692 case TARGET_EXPR:
2693 return 14;
2695 case CALL_EXPR:
2696 case ARRAY_REF:
2697 case ARRAY_RANGE_REF:
2698 case COMPONENT_REF:
2699 return 15;
2701 /* Special expressions. */
2702 case MIN_EXPR:
2703 case MAX_EXPR:
2704 case ABS_EXPR:
2705 case REALPART_EXPR:
2706 case IMAGPART_EXPR:
2707 case REDUC_MAX_EXPR:
2708 case REDUC_MIN_EXPR:
2709 case REDUC_PLUS_EXPR:
2710 case VEC_LSHIFT_EXPR:
2711 case VEC_RSHIFT_EXPR:
2712 case VEC_UNPACK_HI_EXPR:
2713 case VEC_UNPACK_LO_EXPR:
2714 case VEC_UNPACK_FLOAT_HI_EXPR:
2715 case VEC_UNPACK_FLOAT_LO_EXPR:
2716 case VEC_PACK_TRUNC_EXPR:
2717 case VEC_PACK_SAT_EXPR:
2718 return 16;
2720 default:
2721 /* Return an arbitrarily high precedence to avoid surrounding single
2722 VAR_DECLs in ()s. */
2723 return 9999;
2727 /* Return the priority of the operator OP. */
2730 op_prio (const_tree op)
2732 enum tree_code code;
2734 if (op == NULL)
2735 return 9999;
2737 code = TREE_CODE (op);
2738 if (code == SAVE_EXPR || code == NON_LVALUE_EXPR)
2739 return op_prio (TREE_OPERAND (op, 0));
2741 return op_code_prio (code);
2744 /* Return the symbol associated with operator CODE. */
2746 const char *
2747 op_symbol_code (enum tree_code code)
2749 switch (code)
2751 case MODIFY_EXPR:
2752 return "=";
2754 case TRUTH_OR_EXPR:
2755 case TRUTH_ORIF_EXPR:
2756 return "||";
2758 case TRUTH_AND_EXPR:
2759 case TRUTH_ANDIF_EXPR:
2760 return "&&";
2762 case BIT_IOR_EXPR:
2763 return "|";
2765 case TRUTH_XOR_EXPR:
2766 case BIT_XOR_EXPR:
2767 return "^";
2769 case ADDR_EXPR:
2770 case BIT_AND_EXPR:
2771 return "&";
2773 case ORDERED_EXPR:
2774 return "ord";
2775 case UNORDERED_EXPR:
2776 return "unord";
2778 case EQ_EXPR:
2779 return "==";
2780 case UNEQ_EXPR:
2781 return "u==";
2783 case NE_EXPR:
2784 return "!=";
2786 case LT_EXPR:
2787 return "<";
2788 case UNLT_EXPR:
2789 return "u<";
2791 case LE_EXPR:
2792 return "<=";
2793 case UNLE_EXPR:
2794 return "u<=";
2796 case GT_EXPR:
2797 return ">";
2798 case UNGT_EXPR:
2799 return "u>";
2801 case GE_EXPR:
2802 return ">=";
2803 case UNGE_EXPR:
2804 return "u>=";
2806 case LTGT_EXPR:
2807 return "<>";
2809 case LSHIFT_EXPR:
2810 return "<<";
2812 case RSHIFT_EXPR:
2813 return ">>";
2815 case LROTATE_EXPR:
2816 return "r<<";
2818 case RROTATE_EXPR:
2819 return "r>>";
2821 case VEC_LSHIFT_EXPR:
2822 return "v<<";
2824 case VEC_RSHIFT_EXPR:
2825 return "v>>";
2827 case WIDEN_LSHIFT_EXPR:
2828 return "w<<";
2830 case POINTER_PLUS_EXPR:
2831 return "+";
2833 case PLUS_EXPR:
2834 return "+";
2836 case REDUC_PLUS_EXPR:
2837 return "r+";
2839 case WIDEN_SUM_EXPR:
2840 return "w+";
2842 case WIDEN_MULT_EXPR:
2843 return "w*";
2845 case MULT_HIGHPART_EXPR:
2846 return "h*";
2848 case NEGATE_EXPR:
2849 case MINUS_EXPR:
2850 return "-";
2852 case BIT_NOT_EXPR:
2853 return "~";
2855 case TRUTH_NOT_EXPR:
2856 return "!";
2858 case MULT_EXPR:
2859 case INDIRECT_REF:
2860 return "*";
2862 case TRUNC_DIV_EXPR:
2863 case RDIV_EXPR:
2864 return "/";
2866 case CEIL_DIV_EXPR:
2867 return "/[cl]";
2869 case FLOOR_DIV_EXPR:
2870 return "/[fl]";
2872 case ROUND_DIV_EXPR:
2873 return "/[rd]";
2875 case EXACT_DIV_EXPR:
2876 return "/[ex]";
2878 case TRUNC_MOD_EXPR:
2879 return "%";
2881 case CEIL_MOD_EXPR:
2882 return "%[cl]";
2884 case FLOOR_MOD_EXPR:
2885 return "%[fl]";
2887 case ROUND_MOD_EXPR:
2888 return "%[rd]";
2890 case PREDECREMENT_EXPR:
2891 return " --";
2893 case PREINCREMENT_EXPR:
2894 return " ++";
2896 case POSTDECREMENT_EXPR:
2897 return "-- ";
2899 case POSTINCREMENT_EXPR:
2900 return "++ ";
2902 case MAX_EXPR:
2903 return "max";
2905 case MIN_EXPR:
2906 return "min";
2908 default:
2909 return "<<< ??? >>>";
2913 /* Return the symbol associated with operator OP. */
2915 static const char *
2916 op_symbol (const_tree op)
2918 return op_symbol_code (TREE_CODE (op));
2921 /* Prints the name of a call. NODE is the CALL_EXPR_FN of a CALL_EXPR or
2922 the gimple_call_fn of a GIMPLE_CALL. */
2924 void
2925 print_call_name (pretty_printer *buffer, tree node, int flags)
2927 tree op0 = node;
2929 if (TREE_CODE (op0) == NON_LVALUE_EXPR)
2930 op0 = TREE_OPERAND (op0, 0);
2932 again:
2933 switch (TREE_CODE (op0))
2935 case VAR_DECL:
2936 case PARM_DECL:
2937 case FUNCTION_DECL:
2938 dump_function_name (buffer, op0, flags);
2939 break;
2941 case ADDR_EXPR:
2942 case INDIRECT_REF:
2943 case NOP_EXPR:
2944 op0 = TREE_OPERAND (op0, 0);
2945 goto again;
2947 case COND_EXPR:
2948 pp_string (buffer, "(");
2949 dump_generic_node (buffer, TREE_OPERAND (op0, 0), 0, flags, false);
2950 pp_string (buffer, ") ? ");
2951 dump_generic_node (buffer, TREE_OPERAND (op0, 1), 0, flags, false);
2952 pp_string (buffer, " : ");
2953 dump_generic_node (buffer, TREE_OPERAND (op0, 2), 0, flags, false);
2954 break;
2956 case ARRAY_REF:
2957 if (TREE_CODE (TREE_OPERAND (op0, 0)) == VAR_DECL)
2958 dump_function_name (buffer, TREE_OPERAND (op0, 0), flags);
2959 else
2960 dump_generic_node (buffer, op0, 0, flags, false);
2961 break;
2963 case MEM_REF:
2964 if (integer_zerop (TREE_OPERAND (op0, 1)))
2966 op0 = TREE_OPERAND (op0, 0);
2967 goto again;
2969 /* Fallthru. */
2970 case COMPONENT_REF:
2971 case SSA_NAME:
2972 case OBJ_TYPE_REF:
2973 dump_generic_node (buffer, op0, 0, flags, false);
2974 break;
2976 default:
2977 NIY;
2981 /* Parses the string STR and replaces new-lines by '\n', tabs by '\t', ... */
2983 static void
2984 pretty_print_string (pretty_printer *buffer, const char *str)
2986 if (str == NULL)
2987 return;
2989 while (*str)
2991 switch (str[0])
2993 case '\b':
2994 pp_string (buffer, "\\b");
2995 break;
2997 case '\f':
2998 pp_string (buffer, "\\f");
2999 break;
3001 case '\n':
3002 pp_string (buffer, "\\n");
3003 break;
3005 case '\r':
3006 pp_string (buffer, "\\r");
3007 break;
3009 case '\t':
3010 pp_string (buffer, "\\t");
3011 break;
3013 case '\v':
3014 pp_string (buffer, "\\v");
3015 break;
3017 case '\\':
3018 pp_string (buffer, "\\\\");
3019 break;
3021 case '\"':
3022 pp_string (buffer, "\\\"");
3023 break;
3025 case '\'':
3026 pp_string (buffer, "\\'");
3027 break;
3029 /* No need to handle \0; the loop terminates on \0. */
3031 case '\1':
3032 pp_string (buffer, "\\1");
3033 break;
3035 case '\2':
3036 pp_string (buffer, "\\2");
3037 break;
3039 case '\3':
3040 pp_string (buffer, "\\3");
3041 break;
3043 case '\4':
3044 pp_string (buffer, "\\4");
3045 break;
3047 case '\5':
3048 pp_string (buffer, "\\5");
3049 break;
3051 case '\6':
3052 pp_string (buffer, "\\6");
3053 break;
3055 case '\7':
3056 pp_string (buffer, "\\7");
3057 break;
3059 default:
3060 pp_character (buffer, str[0]);
3061 break;
3063 str++;
3067 static void
3068 maybe_init_pretty_print (FILE *file)
3070 if (!initialized)
3072 pp_construct (&buffer, /* prefix */NULL, /* line-width */0);
3073 pp_needs_newline (&buffer) = true;
3074 pp_translate_identifiers (&buffer) = false;
3075 initialized = 1;
3078 buffer.buffer->stream = file;
3081 static void
3082 newline_and_indent (pretty_printer *buffer, int spc)
3084 pp_newline (buffer);
3085 INDENT (spc);
3088 /* Handle a %K format for TEXT. Separate from default_tree_printer so
3089 it can also be used in front ends.
3090 %K: a statement, from which EXPR_LOCATION and TREE_BLOCK will be recorded.
3093 void
3094 percent_K_format (text_info *text)
3096 tree t = va_arg (*text->args_ptr, tree), block;
3097 gcc_assert (text->locus != NULL);
3098 *text->locus = EXPR_LOCATION (t);
3099 gcc_assert (pp_ti_abstract_origin (text) != NULL);
3100 block = TREE_BLOCK (t);
3101 *pp_ti_abstract_origin (text) = NULL;
3102 while (block
3103 && TREE_CODE (block) == BLOCK
3104 && BLOCK_ABSTRACT_ORIGIN (block))
3106 tree ao = BLOCK_ABSTRACT_ORIGIN (block);
3108 while (TREE_CODE (ao) == BLOCK
3109 && BLOCK_ABSTRACT_ORIGIN (ao)
3110 && BLOCK_ABSTRACT_ORIGIN (ao) != ao)
3111 ao = BLOCK_ABSTRACT_ORIGIN (ao);
3113 if (TREE_CODE (ao) == FUNCTION_DECL)
3115 *pp_ti_abstract_origin (text) = block;
3116 break;
3118 block = BLOCK_SUPERCONTEXT (block);
3122 /* Print the identifier ID to PRETTY-PRINTER. */
3124 void
3125 pp_base_tree_identifier (pretty_printer *pp, tree id)
3127 if (pp_translate_identifiers (pp))
3129 const char *text = identifier_to_locale (IDENTIFIER_POINTER (id));
3130 pp_append_text (pp, text, text + strlen (text));
3132 else
3133 pp_append_text (pp, IDENTIFIER_POINTER (id),
3134 IDENTIFIER_POINTER (id) + IDENTIFIER_LENGTH (id));
3137 /* A helper function that is used to dump function information before the
3138 function dump. */
3140 void
3141 dump_function_header (FILE *dump_file, tree fdecl, int flags)
3143 const char *dname, *aname;
3144 struct cgraph_node *node = cgraph_get_node (fdecl);
3145 struct function *fun = DECL_STRUCT_FUNCTION (fdecl);
3147 dname = lang_hooks.decl_printable_name (fdecl, 2);
3149 if (DECL_ASSEMBLER_NAME_SET_P (fdecl))
3150 aname = (IDENTIFIER_POINTER
3151 (DECL_ASSEMBLER_NAME (fdecl)));
3152 else
3153 aname = "<unset-asm-name>";
3155 fprintf (dump_file, "\n;; Function %s (%s, funcdef_no=%d",
3156 dname, aname, fun->funcdef_no);
3157 if (!(flags & TDF_NOUID))
3158 fprintf (dump_file, ", decl_uid=%d", DECL_UID (fdecl));
3159 if (node)
3161 fprintf (dump_file, ", cgraph_uid=%d)%s\n\n", node->uid,
3162 node->frequency == NODE_FREQUENCY_HOT
3163 ? " (hot)"
3164 : node->frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED
3165 ? " (unlikely executed)"
3166 : node->frequency == NODE_FREQUENCY_EXECUTED_ONCE
3167 ? " (executed once)"
3168 : "");
3170 else
3171 fprintf (dump_file, ")\n\n");