* config/sh/sh.c (sh_gimplify_va_arg_expr): Don't call
[official-gcc.git] / gcc / tree-pretty-print.c
blobf2f5a220018285a558dc823c2a820314faa53cb5
1 /* Pretty formatting of GENERIC trees in C syntax.
2 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
3 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 "output.h"
28 #include "tree-pretty-print.h"
29 #include "hashtab.h"
30 #include "tree-flow.h"
31 #include "langhooks.h"
32 #include "tree-iterator.h"
33 #include "tree-chrec.h"
34 #include "tree-pass.h"
35 #include "value-prof.h"
36 #include "predict.h"
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 tree-pass.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_flush (&buffer);
140 /* Print tree T, and its successors, on file FILE. FLAGS specifies details
141 to show in the dump. See TDF_* in tree-pass.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_flush (&buffer);
157 /* Print a single expression T on file FILE. FLAGS specifies details to show
158 in the dump. See TDF_* in tree-pass.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);
167 /* Dump the name of a _DECL node and its DECL_UID if TDF_UID is set
168 in FLAGS. */
170 static void
171 dump_decl_name (pretty_printer *buffer, tree node, int flags)
173 if (DECL_NAME (node))
175 if ((flags & TDF_ASMNAME) && DECL_ASSEMBLER_NAME_SET_P (node))
176 pp_tree_identifier (buffer, DECL_ASSEMBLER_NAME (node));
177 else
178 pp_tree_identifier (buffer, DECL_NAME (node));
180 if ((flags & TDF_UID) || DECL_NAME (node) == NULL_TREE)
182 if (TREE_CODE (node) == LABEL_DECL && LABEL_DECL_UID (node) != -1)
183 pp_printf (buffer, "L.%d", (int) LABEL_DECL_UID (node));
184 else if (TREE_CODE (node) == DEBUG_EXPR_DECL)
186 if (flags & TDF_NOUID)
187 pp_string (buffer, "D#xxxx");
188 else
189 pp_printf (buffer, "D#%i", DEBUG_TEMP_UID (node));
191 else
193 char c = TREE_CODE (node) == CONST_DECL ? 'C' : 'D';
194 if (flags & TDF_NOUID)
195 pp_printf (buffer, "%c.xxxx", c);
196 else
197 pp_printf (buffer, "%c.%u", c, DECL_UID (node));
200 if ((flags & TDF_ALIAS) && DECL_PT_UID (node) != DECL_UID (node))
202 if (flags & TDF_NOUID)
203 pp_printf (buffer, "ptD.xxxx");
204 else
205 pp_printf (buffer, "ptD.%u", DECL_PT_UID (node));
209 /* Like the above, but used for pretty printing function calls. */
211 static void
212 dump_function_name (pretty_printer *buffer, tree node, int flags)
214 if (TREE_CODE (node) == NOP_EXPR)
215 node = TREE_OPERAND (node, 0);
216 if (DECL_NAME (node) && (flags & TDF_ASMNAME) == 0)
217 pp_string (buffer, lang_hooks.decl_printable_name (node, 1));
218 else
219 dump_decl_name (buffer, node, flags);
222 /* Dump a function declaration. NODE is the FUNCTION_TYPE. BUFFER, SPC and
223 FLAGS are as in dump_generic_node. */
225 static void
226 dump_function_declaration (pretty_printer *buffer, tree node,
227 int spc, int flags)
229 bool wrote_arg = false;
230 tree arg;
232 pp_space (buffer);
233 pp_character (buffer, '(');
235 /* Print the argument types. */
236 arg = TYPE_ARG_TYPES (node);
237 while (arg && arg != void_list_node && arg != error_mark_node)
239 if (wrote_arg)
241 pp_character (buffer, ',');
242 pp_space (buffer);
244 wrote_arg = true;
245 dump_generic_node (buffer, TREE_VALUE (arg), spc, flags, false);
246 arg = TREE_CHAIN (arg);
249 /* Drop the trailing void_type_node if we had any previous argument. */
250 if (arg == void_list_node && !wrote_arg)
251 pp_string (buffer, "void");
252 /* Properly dump vararg function types. */
253 else if (!arg && wrote_arg)
254 pp_string (buffer, ", ...");
255 /* Avoid printing any arg for unprototyped functions. */
257 pp_character (buffer, ')');
260 /* Dump the domain associated with an array. */
262 static void
263 dump_array_domain (pretty_printer *buffer, tree domain, int spc, int flags)
265 pp_character (buffer, '[');
266 if (domain)
268 tree min = TYPE_MIN_VALUE (domain);
269 tree max = TYPE_MAX_VALUE (domain);
271 if (min && max
272 && integer_zerop (min)
273 && host_integerp (max, 0))
274 pp_wide_integer (buffer, TREE_INT_CST_LOW (max) + 1);
275 else
277 if (min)
278 dump_generic_node (buffer, min, spc, flags, false);
279 pp_character (buffer, ':');
280 if (max)
281 dump_generic_node (buffer, max, spc, flags, false);
284 else
285 pp_string (buffer, "<unknown>");
286 pp_character (buffer, ']');
290 /* Dump OpenMP clause CLAUSE. BUFFER, CLAUSE, SPC and FLAGS are as in
291 dump_generic_node. */
293 static void
294 dump_omp_clause (pretty_printer *buffer, tree clause, int spc, int flags)
296 const char *name;
298 switch (OMP_CLAUSE_CODE (clause))
300 case OMP_CLAUSE_PRIVATE:
301 name = "private";
302 goto print_remap;
303 case OMP_CLAUSE_SHARED:
304 name = "shared";
305 goto print_remap;
306 case OMP_CLAUSE_FIRSTPRIVATE:
307 name = "firstprivate";
308 goto print_remap;
309 case OMP_CLAUSE_LASTPRIVATE:
310 name = "lastprivate";
311 goto print_remap;
312 case OMP_CLAUSE_COPYIN:
313 name = "copyin";
314 goto print_remap;
315 case OMP_CLAUSE_COPYPRIVATE:
316 name = "copyprivate";
317 goto print_remap;
318 print_remap:
319 pp_string (buffer, name);
320 pp_character (buffer, '(');
321 dump_generic_node (buffer, OMP_CLAUSE_DECL (clause),
322 spc, flags, false);
323 pp_character (buffer, ')');
324 break;
326 case OMP_CLAUSE_REDUCTION:
327 pp_string (buffer, "reduction(");
328 pp_string (buffer, op_symbol_code (OMP_CLAUSE_REDUCTION_CODE (clause)));
329 pp_character (buffer, ':');
330 dump_generic_node (buffer, OMP_CLAUSE_DECL (clause),
331 spc, flags, false);
332 pp_character (buffer, ')');
333 break;
335 case OMP_CLAUSE_IF:
336 pp_string (buffer, "if(");
337 dump_generic_node (buffer, OMP_CLAUSE_IF_EXPR (clause),
338 spc, flags, false);
339 pp_character (buffer, ')');
340 break;
342 case OMP_CLAUSE_NUM_THREADS:
343 pp_string (buffer, "num_threads(");
344 dump_generic_node (buffer, OMP_CLAUSE_NUM_THREADS_EXPR (clause),
345 spc, flags, false);
346 pp_character (buffer, ')');
347 break;
349 case OMP_CLAUSE_NOWAIT:
350 pp_string (buffer, "nowait");
351 break;
352 case OMP_CLAUSE_ORDERED:
353 pp_string (buffer, "ordered");
354 break;
356 case OMP_CLAUSE_DEFAULT:
357 pp_string (buffer, "default(");
358 switch (OMP_CLAUSE_DEFAULT_KIND (clause))
360 case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
361 break;
362 case OMP_CLAUSE_DEFAULT_SHARED:
363 pp_string (buffer, "shared");
364 break;
365 case OMP_CLAUSE_DEFAULT_NONE:
366 pp_string (buffer, "none");
367 break;
368 case OMP_CLAUSE_DEFAULT_PRIVATE:
369 pp_string (buffer, "private");
370 break;
371 case OMP_CLAUSE_DEFAULT_FIRSTPRIVATE:
372 pp_string (buffer, "firstprivate");
373 break;
374 default:
375 gcc_unreachable ();
377 pp_character (buffer, ')');
378 break;
380 case OMP_CLAUSE_SCHEDULE:
381 pp_string (buffer, "schedule(");
382 switch (OMP_CLAUSE_SCHEDULE_KIND (clause))
384 case OMP_CLAUSE_SCHEDULE_STATIC:
385 pp_string (buffer, "static");
386 break;
387 case OMP_CLAUSE_SCHEDULE_DYNAMIC:
388 pp_string (buffer, "dynamic");
389 break;
390 case OMP_CLAUSE_SCHEDULE_GUIDED:
391 pp_string (buffer, "guided");
392 break;
393 case OMP_CLAUSE_SCHEDULE_RUNTIME:
394 pp_string (buffer, "runtime");
395 break;
396 case OMP_CLAUSE_SCHEDULE_AUTO:
397 pp_string (buffer, "auto");
398 break;
399 default:
400 gcc_unreachable ();
402 if (OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clause))
404 pp_character (buffer, ',');
405 dump_generic_node (buffer,
406 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clause),
407 spc, flags, false);
409 pp_character (buffer, ')');
410 break;
412 case OMP_CLAUSE_UNTIED:
413 pp_string (buffer, "untied");
414 break;
416 case OMP_CLAUSE_COLLAPSE:
417 pp_string (buffer, "collapse(");
418 dump_generic_node (buffer,
419 OMP_CLAUSE_COLLAPSE_EXPR (clause),
420 spc, flags, false);
421 pp_character (buffer, ')');
422 break;
424 default:
425 /* Should never happen. */
426 dump_generic_node (buffer, clause, spc, flags, false);
427 break;
432 /* Dump the list of OpenMP clauses. BUFFER, SPC and FLAGS are as in
433 dump_generic_node. */
435 void
436 dump_omp_clauses (pretty_printer *buffer, tree clause, int spc, int flags)
438 if (clause == NULL)
439 return;
441 pp_space (buffer);
442 while (1)
444 dump_omp_clause (buffer, clause, spc, flags);
445 clause = OMP_CLAUSE_CHAIN (clause);
446 if (clause == NULL)
447 return;
448 pp_space (buffer);
453 /* Dump location LOC to BUFFER. */
455 static void
456 dump_location (pretty_printer *buffer, location_t loc)
458 expanded_location xloc = expand_location (loc);
460 pp_character (buffer, '[');
461 if (xloc.file)
463 pp_string (buffer, xloc.file);
464 pp_string (buffer, " : ");
466 pp_decimal_int (buffer, xloc.line);
467 pp_string (buffer, "] ");
471 /* Dump lexical block BLOCK. BUFFER, SPC and FLAGS are as in
472 dump_generic_node. */
474 static void
475 dump_block_node (pretty_printer *buffer, tree block, int spc, int flags)
477 tree t;
479 pp_printf (buffer, "BLOCK #%d ", BLOCK_NUMBER (block));
481 if (flags & TDF_ADDRESS)
482 pp_printf (buffer, "[%p] ", (void *) block);
484 if (BLOCK_ABSTRACT (block))
485 pp_string (buffer, "[abstract] ");
487 if (TREE_ASM_WRITTEN (block))
488 pp_string (buffer, "[written] ");
490 if (flags & TDF_SLIM)
491 return;
493 if (BLOCK_SOURCE_LOCATION (block))
494 dump_location (buffer, BLOCK_SOURCE_LOCATION (block));
496 newline_and_indent (buffer, spc + 2);
498 if (BLOCK_SUPERCONTEXT (block))
500 pp_string (buffer, "SUPERCONTEXT: ");
501 dump_generic_node (buffer, BLOCK_SUPERCONTEXT (block), 0,
502 flags | TDF_SLIM, false);
503 newline_and_indent (buffer, spc + 2);
506 if (BLOCK_SUBBLOCKS (block))
508 pp_string (buffer, "SUBBLOCKS: ");
509 for (t = BLOCK_SUBBLOCKS (block); t; t = BLOCK_CHAIN (t))
511 dump_generic_node (buffer, t, 0, flags | TDF_SLIM, false);
512 pp_string (buffer, " ");
514 newline_and_indent (buffer, spc + 2);
517 if (BLOCK_CHAIN (block))
519 pp_string (buffer, "SIBLINGS: ");
520 for (t = BLOCK_CHAIN (block); t; t = BLOCK_CHAIN (t))
522 dump_generic_node (buffer, t, 0, flags | TDF_SLIM, false);
523 pp_string (buffer, " ");
525 newline_and_indent (buffer, spc + 2);
528 if (BLOCK_VARS (block))
530 pp_string (buffer, "VARS: ");
531 for (t = BLOCK_VARS (block); t; t = TREE_CHAIN (t))
533 dump_generic_node (buffer, t, 0, flags, false);
534 pp_string (buffer, " ");
536 newline_and_indent (buffer, spc + 2);
539 if (VEC_length (tree, BLOCK_NONLOCALIZED_VARS (block)) > 0)
541 unsigned i;
542 VEC(tree,gc) *nlv = BLOCK_NONLOCALIZED_VARS (block);
544 pp_string (buffer, "NONLOCALIZED_VARS: ");
545 FOR_EACH_VEC_ELT (tree, nlv, i, t)
547 dump_generic_node (buffer, t, 0, flags, false);
548 pp_string (buffer, " ");
550 newline_and_indent (buffer, spc + 2);
553 if (BLOCK_ABSTRACT_ORIGIN (block))
555 pp_string (buffer, "ABSTRACT_ORIGIN: ");
556 dump_generic_node (buffer, BLOCK_ABSTRACT_ORIGIN (block), 0,
557 flags | TDF_SLIM, false);
558 newline_and_indent (buffer, spc + 2);
561 if (BLOCK_FRAGMENT_ORIGIN (block))
563 pp_string (buffer, "FRAGMENT_ORIGIN: ");
564 dump_generic_node (buffer, BLOCK_FRAGMENT_ORIGIN (block), 0,
565 flags | TDF_SLIM, false);
566 newline_and_indent (buffer, spc + 2);
569 if (BLOCK_FRAGMENT_CHAIN (block))
571 pp_string (buffer, "FRAGMENT_CHAIN: ");
572 for (t = BLOCK_FRAGMENT_CHAIN (block); t; t = BLOCK_FRAGMENT_CHAIN (t))
574 dump_generic_node (buffer, t, 0, flags | TDF_SLIM, false);
575 pp_string (buffer, " ");
577 newline_and_indent (buffer, spc + 2);
582 /* Dump the node NODE on the pretty_printer BUFFER, SPC spaces of
583 indent. FLAGS specifies details to show in the dump (see TDF_* in
584 tree-pass.h). If IS_STMT is true, the object printed is considered
585 to be a statement and it is terminated by ';' if appropriate. */
588 dump_generic_node (pretty_printer *buffer, tree node, int spc, int flags,
589 bool is_stmt)
591 tree type;
592 tree op0, op1;
593 const char *str;
594 bool is_expr;
596 if (node == NULL_TREE)
597 return spc;
599 is_expr = EXPR_P (node);
601 if (is_stmt && (flags & TDF_STMTADDR))
602 pp_printf (buffer, "<&%p> ", (void *)node);
604 if ((flags & TDF_LINENO) && EXPR_HAS_LOCATION (node))
605 dump_location (buffer, EXPR_LOCATION (node));
607 switch (TREE_CODE (node))
609 case ERROR_MARK:
610 pp_string (buffer, "<<< error >>>");
611 break;
613 case IDENTIFIER_NODE:
614 pp_tree_identifier (buffer, node);
615 break;
617 case TREE_LIST:
618 while (node && node != error_mark_node)
620 if (TREE_PURPOSE (node))
622 dump_generic_node (buffer, TREE_PURPOSE (node), spc, flags, false);
623 pp_space (buffer);
625 dump_generic_node (buffer, TREE_VALUE (node), spc, flags, false);
626 node = TREE_CHAIN (node);
627 if (node && TREE_CODE (node) == TREE_LIST)
629 pp_character (buffer, ',');
630 pp_space (buffer);
633 break;
635 case TREE_BINFO:
636 dump_generic_node (buffer, BINFO_TYPE (node), spc, flags, false);
637 break;
639 case TREE_VEC:
641 size_t i;
642 if (TREE_VEC_LENGTH (node) > 0)
644 size_t len = TREE_VEC_LENGTH (node);
645 for (i = 0; i < len - 1; i++)
647 dump_generic_node (buffer, TREE_VEC_ELT (node, i), spc, flags,
648 false);
649 pp_character (buffer, ',');
650 pp_space (buffer);
652 dump_generic_node (buffer, TREE_VEC_ELT (node, len - 1), spc,
653 flags, false);
656 break;
658 case VOID_TYPE:
659 case INTEGER_TYPE:
660 case REAL_TYPE:
661 case FIXED_POINT_TYPE:
662 case COMPLEX_TYPE:
663 case VECTOR_TYPE:
664 case ENUMERAL_TYPE:
665 case BOOLEAN_TYPE:
667 unsigned int quals = TYPE_QUALS (node);
668 enum tree_code_class tclass;
670 if (quals & TYPE_QUAL_CONST)
671 pp_string (buffer, "const ");
672 else if (quals & TYPE_QUAL_VOLATILE)
673 pp_string (buffer, "volatile ");
674 else if (quals & TYPE_QUAL_RESTRICT)
675 pp_string (buffer, "restrict ");
677 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
679 pp_string (buffer, "<address-space-");
680 pp_decimal_int (buffer, TYPE_ADDR_SPACE (node));
681 pp_string (buffer, "> ");
684 tclass = TREE_CODE_CLASS (TREE_CODE (node));
686 if (tclass == tcc_declaration)
688 if (DECL_NAME (node))
689 dump_decl_name (buffer, node, flags);
690 else
691 pp_string (buffer, "<unnamed type decl>");
693 else if (tclass == tcc_type)
695 if (TYPE_NAME (node))
697 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
698 pp_tree_identifier (buffer, TYPE_NAME (node));
699 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
700 && DECL_NAME (TYPE_NAME (node)))
701 dump_decl_name (buffer, TYPE_NAME (node), flags);
702 else
703 pp_string (buffer, "<unnamed type>");
705 else if (TREE_CODE (node) == VECTOR_TYPE)
707 pp_string (buffer, "vector");
708 pp_character (buffer, '(');
709 pp_wide_integer (buffer, TYPE_VECTOR_SUBPARTS (node));
710 pp_string (buffer, ") ");
711 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
713 else if (TREE_CODE (node) == INTEGER_TYPE)
715 pp_string (buffer, (TYPE_UNSIGNED (node)
716 ? "<unnamed-unsigned:"
717 : "<unnamed-signed:"));
718 pp_decimal_int (buffer, TYPE_PRECISION (node));
719 pp_string (buffer, ">");
721 else if (TREE_CODE (node) == COMPLEX_TYPE)
723 pp_string (buffer, "__complex__ ");
724 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
726 else if (TREE_CODE (node) == REAL_TYPE)
728 pp_string (buffer, "<float:");
729 pp_decimal_int (buffer, TYPE_PRECISION (node));
730 pp_string (buffer, ">");
732 else if (TREE_CODE (node) == FIXED_POINT_TYPE)
734 pp_string (buffer, "<fixed-point-");
735 pp_string (buffer, TYPE_SATURATING (node) ? "sat:" : "nonsat:");
736 pp_decimal_int (buffer, TYPE_PRECISION (node));
737 pp_string (buffer, ">");
739 else if (TREE_CODE (node) == VOID_TYPE)
740 pp_string (buffer, "void");
741 else
742 pp_string (buffer, "<unnamed type>");
744 break;
747 case POINTER_TYPE:
748 case REFERENCE_TYPE:
749 str = (TREE_CODE (node) == POINTER_TYPE ? "*" : "&");
751 if (TREE_TYPE (node) == NULL)
753 pp_string (buffer, str);
754 pp_string (buffer, "<null type>");
756 else if (TREE_CODE (TREE_TYPE (node)) == FUNCTION_TYPE)
758 tree fnode = TREE_TYPE (node);
760 dump_generic_node (buffer, TREE_TYPE (fnode), spc, flags, false);
761 pp_space (buffer);
762 pp_character (buffer, '(');
763 pp_string (buffer, str);
764 if (TYPE_NAME (node) && DECL_NAME (TYPE_NAME (node)))
765 dump_decl_name (buffer, TYPE_NAME (node), flags);
766 else if (flags & TDF_NOUID)
767 pp_printf (buffer, "<Txxxx>");
768 else
769 pp_printf (buffer, "<T%x>", TYPE_UID (node));
771 pp_character (buffer, ')');
772 dump_function_declaration (buffer, fnode, spc, flags);
774 else
776 unsigned int quals = TYPE_QUALS (node);
778 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
779 pp_space (buffer);
780 pp_string (buffer, str);
782 if (quals & TYPE_QUAL_CONST)
783 pp_string (buffer, " const");
784 if (quals & TYPE_QUAL_VOLATILE)
785 pp_string (buffer, " volatile");
786 if (quals & TYPE_QUAL_RESTRICT)
787 pp_string (buffer, " restrict");
789 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (node)))
791 pp_string (buffer, " <address-space-");
792 pp_decimal_int (buffer, TYPE_ADDR_SPACE (node));
793 pp_string (buffer, ">");
796 if (TYPE_REF_CAN_ALIAS_ALL (node))
797 pp_string (buffer, " {ref-all}");
799 break;
801 case OFFSET_TYPE:
802 NIY;
803 break;
805 case MEM_REF:
807 if (integer_zerop (TREE_OPERAND (node, 1))
808 /* Dump the types of INTEGER_CSTs explicitly, for we can't
809 infer them and MEM_ATTR caching will share MEM_REFs
810 with differently-typed op0s. */
811 && TREE_CODE (TREE_OPERAND (node, 0)) != INTEGER_CST
812 /* Same pointer types, but ignoring POINTER_TYPE vs.
813 REFERENCE_TYPE. */
814 && (TREE_TYPE (TREE_TYPE (TREE_OPERAND (node, 0)))
815 == TREE_TYPE (TREE_TYPE (TREE_OPERAND (node, 1))))
816 && (TYPE_MODE (TREE_TYPE (TREE_OPERAND (node, 0)))
817 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (node, 1))))
818 && (TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (node, 0)))
819 == TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (node, 1))))
820 /* Same value types ignoring qualifiers. */
821 && (TYPE_MAIN_VARIANT (TREE_TYPE (node))
822 == TYPE_MAIN_VARIANT
823 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (node, 1))))))
825 if (TREE_CODE (TREE_OPERAND (node, 0)) != ADDR_EXPR)
827 pp_string (buffer, "*");
828 dump_generic_node (buffer, TREE_OPERAND (node, 0),
829 spc, flags, false);
831 else
832 dump_generic_node (buffer,
833 TREE_OPERAND (TREE_OPERAND (node, 0), 0),
834 spc, flags, false);
836 else
838 tree ptype;
840 pp_string (buffer, "MEM[");
841 pp_string (buffer, "(");
842 ptype = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (node, 1)));
843 dump_generic_node (buffer, ptype,
844 spc, flags | TDF_SLIM, false);
845 pp_string (buffer, ")");
846 dump_generic_node (buffer, TREE_OPERAND (node, 0),
847 spc, flags, false);
848 if (!integer_zerop (TREE_OPERAND (node, 1)))
850 pp_string (buffer, " + ");
851 dump_generic_node (buffer, TREE_OPERAND (node, 1),
852 spc, flags, false);
854 pp_string (buffer, "]");
856 break;
859 case TARGET_MEM_REF:
861 const char *sep = "";
862 tree tmp;
864 pp_string (buffer, "MEM[");
866 if (TREE_CODE (TMR_BASE (node)) == ADDR_EXPR)
868 pp_string (buffer, sep);
869 sep = ", ";
870 pp_string (buffer, "symbol: ");
871 dump_generic_node (buffer, TREE_OPERAND (TMR_BASE (node), 0),
872 spc, flags, false);
874 else
876 pp_string (buffer, sep);
877 sep = ", ";
878 pp_string (buffer, "base: ");
879 dump_generic_node (buffer, TMR_BASE (node), spc, flags, false);
881 tmp = TMR_INDEX2 (node);
882 if (tmp)
884 pp_string (buffer, sep);
885 sep = ", ";
886 pp_string (buffer, "base: ");
887 dump_generic_node (buffer, tmp, spc, flags, false);
889 tmp = TMR_INDEX (node);
890 if (tmp)
892 pp_string (buffer, sep);
893 sep = ", ";
894 pp_string (buffer, "index: ");
895 dump_generic_node (buffer, tmp, spc, flags, false);
897 tmp = TMR_STEP (node);
898 if (tmp)
900 pp_string (buffer, sep);
901 sep = ", ";
902 pp_string (buffer, "step: ");
903 dump_generic_node (buffer, tmp, spc, flags, false);
905 tmp = TMR_OFFSET (node);
906 if (tmp)
908 pp_string (buffer, sep);
909 sep = ", ";
910 pp_string (buffer, "offset: ");
911 dump_generic_node (buffer, tmp, spc, flags, false);
913 pp_string (buffer, "]");
915 break;
917 case ARRAY_TYPE:
919 tree tmp;
921 /* Print the innermost component type. */
922 for (tmp = TREE_TYPE (node); TREE_CODE (tmp) == ARRAY_TYPE;
923 tmp = TREE_TYPE (tmp))
925 dump_generic_node (buffer, tmp, spc, flags, false);
927 /* Print the dimensions. */
928 for (tmp = node; TREE_CODE (tmp) == ARRAY_TYPE; tmp = TREE_TYPE (tmp))
929 dump_array_domain (buffer, TYPE_DOMAIN (tmp), spc, flags);
930 break;
933 case RECORD_TYPE:
934 case UNION_TYPE:
935 case QUAL_UNION_TYPE:
937 unsigned int quals = TYPE_QUALS (node);
939 if (quals & TYPE_QUAL_CONST)
940 pp_string (buffer, "const ");
941 if (quals & TYPE_QUAL_VOLATILE)
942 pp_string (buffer, "volatile ");
944 /* Print the name of the structure. */
945 if (TREE_CODE (node) == RECORD_TYPE)
946 pp_string (buffer, "struct ");
947 else if (TREE_CODE (node) == UNION_TYPE)
948 pp_string (buffer, "union ");
950 if (TYPE_NAME (node))
951 dump_generic_node (buffer, TYPE_NAME (node), spc, flags, false);
952 else if (!(flags & TDF_SLIM))
953 /* FIXME: If we eliminate the 'else' above and attempt
954 to show the fields for named types, we may get stuck
955 following a cycle of pointers to structs. The alleged
956 self-reference check in print_struct_decl will not detect
957 cycles involving more than one pointer or struct type. */
958 print_struct_decl (buffer, node, spc, flags);
959 break;
962 case LANG_TYPE:
963 NIY;
964 break;
966 case INTEGER_CST:
967 if (TREE_CODE (TREE_TYPE (node)) == POINTER_TYPE)
969 /* In the case of a pointer, one may want to divide by the
970 size of the pointed-to type. Unfortunately, this not
971 straightforward. The C front-end maps expressions
973 (int *) 5
974 int *p; (p + 5)
976 in such a way that the two INTEGER_CST nodes for "5" have
977 different values but identical types. In the latter
978 case, the 5 is multiplied by sizeof (int) in c-common.c
979 (pointer_int_sum) to convert it to a byte address, and
980 yet the type of the node is left unchanged. Argh. What
981 is consistent though is that the number value corresponds
982 to bytes (UNITS) offset.
984 NB: Neither of the following divisors can be trivially
985 used to recover the original literal:
987 TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (node)))
988 TYPE_PRECISION (TREE_TYPE (TREE_TYPE (node))) */
989 pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
990 pp_string (buffer, "B"); /* pseudo-unit */
992 else if (! host_integerp (node, 0))
994 tree val = node;
995 unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (val);
996 HOST_WIDE_INT high = TREE_INT_CST_HIGH (val);
998 if (tree_int_cst_sgn (val) < 0)
1000 pp_character (buffer, '-');
1001 high = ~high + !low;
1002 low = -low;
1004 /* Would "%x%0*x" or "%x%*0x" get zero-padding on all
1005 systems? */
1006 sprintf (pp_buffer (buffer)->digit_buffer,
1007 HOST_WIDE_INT_PRINT_DOUBLE_HEX,
1008 (unsigned HOST_WIDE_INT) high, low);
1009 pp_string (buffer, pp_buffer (buffer)->digit_buffer);
1011 else
1012 pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
1013 break;
1015 case REAL_CST:
1016 /* Code copied from print_node. */
1018 REAL_VALUE_TYPE d;
1019 if (TREE_OVERFLOW (node))
1020 pp_string (buffer, " overflow");
1022 #if !defined(REAL_IS_NOT_DOUBLE) || defined(REAL_ARITHMETIC)
1023 d = TREE_REAL_CST (node);
1024 if (REAL_VALUE_ISINF (d))
1025 pp_string (buffer, REAL_VALUE_NEGATIVE (d) ? " -Inf" : " Inf");
1026 else if (REAL_VALUE_ISNAN (d))
1027 pp_string (buffer, " Nan");
1028 else
1030 char string[100];
1031 real_to_decimal (string, &d, sizeof (string), 0, 1);
1032 pp_string (buffer, string);
1034 #else
1036 HOST_WIDE_INT i;
1037 unsigned char *p = (unsigned char *) &TREE_REAL_CST (node);
1038 pp_string (buffer, "0x");
1039 for (i = 0; i < sizeof TREE_REAL_CST (node); i++)
1040 output_formatted_integer (buffer, "%02x", *p++);
1042 #endif
1043 break;
1046 case FIXED_CST:
1048 char string[100];
1049 fixed_to_decimal (string, TREE_FIXED_CST_PTR (node), sizeof (string));
1050 pp_string (buffer, string);
1051 break;
1054 case COMPLEX_CST:
1055 pp_string (buffer, "__complex__ (");
1056 dump_generic_node (buffer, TREE_REALPART (node), spc, flags, false);
1057 pp_string (buffer, ", ");
1058 dump_generic_node (buffer, TREE_IMAGPART (node), spc, flags, false);
1059 pp_string (buffer, ")");
1060 break;
1062 case STRING_CST:
1063 pp_string (buffer, "\"");
1064 pretty_print_string (buffer, TREE_STRING_POINTER (node));
1065 pp_string (buffer, "\"");
1066 break;
1068 case VECTOR_CST:
1070 tree elt;
1071 pp_string (buffer, "{ ");
1072 for (elt = TREE_VECTOR_CST_ELTS (node); elt; elt = TREE_CHAIN (elt))
1074 dump_generic_node (buffer, TREE_VALUE (elt), spc, flags, false);
1075 if (TREE_CHAIN (elt))
1076 pp_string (buffer, ", ");
1078 pp_string (buffer, " }");
1080 break;
1082 case FUNCTION_TYPE:
1083 case METHOD_TYPE:
1084 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1085 pp_space (buffer);
1086 if (TREE_CODE (node) == METHOD_TYPE)
1088 if (TYPE_METHOD_BASETYPE (node))
1089 dump_decl_name (buffer, TYPE_NAME (TYPE_METHOD_BASETYPE (node)),
1090 flags);
1091 else
1092 pp_string (buffer, "<null method basetype>");
1093 pp_string (buffer, "::");
1095 if (TYPE_NAME (node) && DECL_NAME (TYPE_NAME (node)))
1096 dump_decl_name (buffer, TYPE_NAME (node), flags);
1097 else if (flags & TDF_NOUID)
1098 pp_printf (buffer, "<Txxxx>");
1099 else
1100 pp_printf (buffer, "<T%x>", TYPE_UID (node));
1101 dump_function_declaration (buffer, node, spc, flags);
1102 break;
1104 case FUNCTION_DECL:
1105 case CONST_DECL:
1106 dump_decl_name (buffer, node, flags);
1107 break;
1109 case LABEL_DECL:
1110 if (DECL_NAME (node))
1111 dump_decl_name (buffer, node, flags);
1112 else if (LABEL_DECL_UID (node) != -1)
1113 pp_printf (buffer, "<L%d>", (int) LABEL_DECL_UID (node));
1114 else
1116 if (flags & TDF_NOUID)
1117 pp_string (buffer, "<D.xxxx>");
1118 else
1119 pp_printf (buffer, "<D.%u>", DECL_UID (node));
1121 break;
1123 case TYPE_DECL:
1124 if (DECL_IS_BUILTIN (node))
1126 /* Don't print the declaration of built-in types. */
1127 break;
1129 if (DECL_NAME (node))
1130 dump_decl_name (buffer, node, flags);
1131 else if (TYPE_NAME (TREE_TYPE (node)) != node)
1133 if ((TREE_CODE (TREE_TYPE (node)) == RECORD_TYPE
1134 || TREE_CODE (TREE_TYPE (node)) == UNION_TYPE)
1135 && TYPE_METHODS (TREE_TYPE (node)))
1137 /* The type is a c++ class: all structures have at least
1138 4 methods. */
1139 pp_string (buffer, "class ");
1140 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1142 else
1144 pp_string (buffer,
1145 (TREE_CODE (TREE_TYPE (node)) == UNION_TYPE
1146 ? "union" : "struct "));
1147 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1150 else
1151 pp_string (buffer, "<anon>");
1152 break;
1154 case VAR_DECL:
1155 case PARM_DECL:
1156 case FIELD_DECL:
1157 case DEBUG_EXPR_DECL:
1158 case NAMESPACE_DECL:
1159 dump_decl_name (buffer, node, flags);
1160 break;
1162 case RESULT_DECL:
1163 pp_string (buffer, "<retval>");
1164 break;
1166 case COMPONENT_REF:
1167 op0 = TREE_OPERAND (node, 0);
1168 str = ".";
1169 if (op0
1170 && (TREE_CODE (op0) == INDIRECT_REF
1171 || (TREE_CODE (op0) == MEM_REF
1172 && TREE_CODE (TREE_OPERAND (op0, 0)) != ADDR_EXPR
1173 && integer_zerop (TREE_OPERAND (op0, 1))
1174 /* Dump the types of INTEGER_CSTs explicitly, for we
1175 can't infer them and MEM_ATTR caching will share
1176 MEM_REFs with differently-typed op0s. */
1177 && TREE_CODE (TREE_OPERAND (op0, 0)) != INTEGER_CST
1178 /* Same pointer types, but ignoring POINTER_TYPE vs.
1179 REFERENCE_TYPE. */
1180 && (TREE_TYPE (TREE_TYPE (TREE_OPERAND (op0, 0)))
1181 == TREE_TYPE (TREE_TYPE (TREE_OPERAND (op0, 1))))
1182 && (TYPE_MODE (TREE_TYPE (TREE_OPERAND (op0, 0)))
1183 == TYPE_MODE (TREE_TYPE (TREE_OPERAND (op0, 1))))
1184 && (TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (op0, 0)))
1185 == TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (op0, 1))))
1186 /* Same value types ignoring qualifiers. */
1187 && (TYPE_MAIN_VARIANT (TREE_TYPE (op0))
1188 == TYPE_MAIN_VARIANT
1189 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (op0, 1))))))))
1191 op0 = TREE_OPERAND (op0, 0);
1192 str = "->";
1194 if (op_prio (op0) < op_prio (node))
1195 pp_character (buffer, '(');
1196 dump_generic_node (buffer, op0, spc, flags, false);
1197 if (op_prio (op0) < op_prio (node))
1198 pp_character (buffer, ')');
1199 pp_string (buffer, str);
1200 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1201 op0 = component_ref_field_offset (node);
1202 if (op0 && TREE_CODE (op0) != INTEGER_CST)
1204 pp_string (buffer, "{off: ");
1205 dump_generic_node (buffer, op0, spc, flags, false);
1206 pp_character (buffer, '}');
1208 break;
1210 case BIT_FIELD_REF:
1211 pp_string (buffer, "BIT_FIELD_REF <");
1212 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1213 pp_string (buffer, ", ");
1214 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1215 pp_string (buffer, ", ");
1216 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
1217 pp_string (buffer, ">");
1218 break;
1220 case ARRAY_REF:
1221 case ARRAY_RANGE_REF:
1222 op0 = TREE_OPERAND (node, 0);
1223 if (op_prio (op0) < op_prio (node))
1224 pp_character (buffer, '(');
1225 dump_generic_node (buffer, op0, spc, flags, false);
1226 if (op_prio (op0) < op_prio (node))
1227 pp_character (buffer, ')');
1228 pp_character (buffer, '[');
1229 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1230 if (TREE_CODE (node) == ARRAY_RANGE_REF)
1231 pp_string (buffer, " ...");
1232 pp_character (buffer, ']');
1234 op0 = array_ref_low_bound (node);
1235 op1 = array_ref_element_size (node);
1237 if (!integer_zerop (op0)
1238 || TREE_OPERAND (node, 2)
1239 || TREE_OPERAND (node, 3))
1241 pp_string (buffer, "{lb: ");
1242 dump_generic_node (buffer, op0, spc, flags, false);
1243 pp_string (buffer, " sz: ");
1244 dump_generic_node (buffer, op1, spc, flags, false);
1245 pp_character (buffer, '}');
1247 break;
1249 case CONSTRUCTOR:
1251 unsigned HOST_WIDE_INT ix;
1252 tree field, val;
1253 bool is_struct_init = FALSE;
1254 pp_character (buffer, '{');
1255 if (TREE_CODE (TREE_TYPE (node)) == RECORD_TYPE
1256 || TREE_CODE (TREE_TYPE (node)) == UNION_TYPE)
1257 is_struct_init = TRUE;
1258 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (node), ix, field, val)
1260 if (field && is_struct_init)
1262 pp_character (buffer, '.');
1263 dump_generic_node (buffer, field, spc, flags, false);
1264 pp_string (buffer, "=");
1266 if (val && TREE_CODE (val) == ADDR_EXPR)
1267 if (TREE_CODE (TREE_OPERAND (val, 0)) == FUNCTION_DECL)
1268 val = TREE_OPERAND (val, 0);
1269 if (val && TREE_CODE (val) == FUNCTION_DECL)
1270 dump_decl_name (buffer, val, flags);
1271 else
1272 dump_generic_node (buffer, val, spc, flags, false);
1273 if (ix != VEC_length (constructor_elt, CONSTRUCTOR_ELTS (node)) - 1)
1275 pp_character (buffer, ',');
1276 pp_space (buffer);
1279 pp_character (buffer, '}');
1281 break;
1283 case COMPOUND_EXPR:
1285 tree *tp;
1286 if (flags & TDF_SLIM)
1288 pp_string (buffer, "<COMPOUND_EXPR>");
1289 break;
1292 dump_generic_node (buffer, TREE_OPERAND (node, 0),
1293 spc, flags, !(flags & TDF_SLIM));
1294 if (flags & TDF_SLIM)
1295 newline_and_indent (buffer, spc);
1296 else
1298 pp_character (buffer, ',');
1299 pp_space (buffer);
1302 for (tp = &TREE_OPERAND (node, 1);
1303 TREE_CODE (*tp) == COMPOUND_EXPR;
1304 tp = &TREE_OPERAND (*tp, 1))
1306 dump_generic_node (buffer, TREE_OPERAND (*tp, 0),
1307 spc, flags, !(flags & TDF_SLIM));
1308 if (flags & TDF_SLIM)
1309 newline_and_indent (buffer, spc);
1310 else
1312 pp_character (buffer, ',');
1313 pp_space (buffer);
1317 dump_generic_node (buffer, *tp, spc, flags, !(flags & TDF_SLIM));
1319 break;
1321 case STATEMENT_LIST:
1323 tree_stmt_iterator si;
1324 bool first = true;
1326 if (flags & TDF_SLIM)
1328 pp_string (buffer, "<STATEMENT_LIST>");
1329 break;
1332 for (si = tsi_start (node); !tsi_end_p (si); tsi_next (&si))
1334 if (!first)
1335 newline_and_indent (buffer, spc);
1336 else
1337 first = false;
1338 dump_generic_node (buffer, tsi_stmt (si), spc, flags, true);
1341 break;
1343 case MODIFY_EXPR:
1344 case INIT_EXPR:
1345 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags,
1346 false);
1347 pp_space (buffer);
1348 pp_character (buffer, '=');
1349 if (TREE_CODE (node) == MODIFY_EXPR
1350 && MOVE_NONTEMPORAL (node))
1351 pp_string (buffer, "{nt}");
1352 pp_space (buffer);
1353 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags,
1354 false);
1355 break;
1357 case TARGET_EXPR:
1358 pp_string (buffer, "TARGET_EXPR <");
1359 dump_generic_node (buffer, TARGET_EXPR_SLOT (node), spc, flags, false);
1360 pp_character (buffer, ',');
1361 pp_space (buffer);
1362 dump_generic_node (buffer, TARGET_EXPR_INITIAL (node), spc, flags, false);
1363 pp_character (buffer, '>');
1364 break;
1366 case DECL_EXPR:
1367 print_declaration (buffer, DECL_EXPR_DECL (node), spc, flags);
1368 is_stmt = false;
1369 break;
1371 case COND_EXPR:
1372 if (TREE_TYPE (node) == NULL || TREE_TYPE (node) == void_type_node)
1374 pp_string (buffer, "if (");
1375 dump_generic_node (buffer, COND_EXPR_COND (node), spc, flags, false);
1376 pp_character (buffer, ')');
1377 /* The lowered cond_exprs should always be printed in full. */
1378 if (COND_EXPR_THEN (node)
1379 && (IS_EMPTY_STMT (COND_EXPR_THEN (node))
1380 || TREE_CODE (COND_EXPR_THEN (node)) == GOTO_EXPR)
1381 && COND_EXPR_ELSE (node)
1382 && (IS_EMPTY_STMT (COND_EXPR_ELSE (node))
1383 || TREE_CODE (COND_EXPR_ELSE (node)) == GOTO_EXPR))
1385 pp_space (buffer);
1386 dump_generic_node (buffer, COND_EXPR_THEN (node),
1387 0, flags, true);
1388 if (!IS_EMPTY_STMT (COND_EXPR_ELSE (node)))
1390 pp_string (buffer, " else ");
1391 dump_generic_node (buffer, COND_EXPR_ELSE (node),
1392 0, flags, true);
1395 else if (!(flags & TDF_SLIM))
1397 /* Output COND_EXPR_THEN. */
1398 if (COND_EXPR_THEN (node))
1400 newline_and_indent (buffer, spc+2);
1401 pp_character (buffer, '{');
1402 newline_and_indent (buffer, spc+4);
1403 dump_generic_node (buffer, COND_EXPR_THEN (node), spc+4,
1404 flags, true);
1405 newline_and_indent (buffer, spc+2);
1406 pp_character (buffer, '}');
1409 /* Output COND_EXPR_ELSE. */
1410 if (COND_EXPR_ELSE (node)
1411 && !IS_EMPTY_STMT (COND_EXPR_ELSE (node)))
1413 newline_and_indent (buffer, spc);
1414 pp_string (buffer, "else");
1415 newline_and_indent (buffer, spc+2);
1416 pp_character (buffer, '{');
1417 newline_and_indent (buffer, spc+4);
1418 dump_generic_node (buffer, COND_EXPR_ELSE (node), spc+4,
1419 flags, true);
1420 newline_and_indent (buffer, spc+2);
1421 pp_character (buffer, '}');
1424 is_expr = false;
1426 else
1428 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1429 pp_space (buffer);
1430 pp_character (buffer, '?');
1431 pp_space (buffer);
1432 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1433 pp_space (buffer);
1434 pp_character (buffer, ':');
1435 pp_space (buffer);
1436 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
1438 break;
1440 case BIND_EXPR:
1441 pp_character (buffer, '{');
1442 if (!(flags & TDF_SLIM))
1444 if (BIND_EXPR_VARS (node))
1446 pp_newline (buffer);
1448 for (op0 = BIND_EXPR_VARS (node); op0; op0 = DECL_CHAIN (op0))
1450 print_declaration (buffer, op0, spc+2, flags);
1451 pp_newline (buffer);
1455 newline_and_indent (buffer, spc+2);
1456 dump_generic_node (buffer, BIND_EXPR_BODY (node), spc+2, flags, true);
1457 newline_and_indent (buffer, spc);
1458 pp_character (buffer, '}');
1460 is_expr = false;
1461 break;
1463 case CALL_EXPR:
1464 print_call_name (buffer, CALL_EXPR_FN (node), flags);
1466 /* Print parameters. */
1467 pp_space (buffer);
1468 pp_character (buffer, '(');
1470 tree arg;
1471 call_expr_arg_iterator iter;
1472 FOR_EACH_CALL_EXPR_ARG (arg, iter, node)
1474 dump_generic_node (buffer, arg, spc, flags, false);
1475 if (more_call_expr_args_p (&iter))
1477 pp_character (buffer, ',');
1478 pp_space (buffer);
1482 if (CALL_EXPR_VA_ARG_PACK (node))
1484 if (call_expr_nargs (node) > 0)
1486 pp_character (buffer, ',');
1487 pp_space (buffer);
1489 pp_string (buffer, "__builtin_va_arg_pack ()");
1491 pp_character (buffer, ')');
1493 op1 = CALL_EXPR_STATIC_CHAIN (node);
1494 if (op1)
1496 pp_string (buffer, " [static-chain: ");
1497 dump_generic_node (buffer, op1, spc, flags, false);
1498 pp_character (buffer, ']');
1501 if (CALL_EXPR_RETURN_SLOT_OPT (node))
1502 pp_string (buffer, " [return slot optimization]");
1503 if (CALL_EXPR_TAILCALL (node))
1504 pp_string (buffer, " [tail call]");
1505 break;
1507 case WITH_CLEANUP_EXPR:
1508 NIY;
1509 break;
1511 case CLEANUP_POINT_EXPR:
1512 pp_string (buffer, "<<cleanup_point ");
1513 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1514 pp_string (buffer, ">>");
1515 break;
1517 case PLACEHOLDER_EXPR:
1518 pp_string (buffer, "<PLACEHOLDER_EXPR ");
1519 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1520 pp_character (buffer, '>');
1521 break;
1523 /* Binary arithmetic and logic expressions. */
1524 case WIDEN_SUM_EXPR:
1525 case WIDEN_MULT_EXPR:
1526 case MULT_EXPR:
1527 case PLUS_EXPR:
1528 case POINTER_PLUS_EXPR:
1529 case MINUS_EXPR:
1530 case TRUNC_DIV_EXPR:
1531 case CEIL_DIV_EXPR:
1532 case FLOOR_DIV_EXPR:
1533 case ROUND_DIV_EXPR:
1534 case TRUNC_MOD_EXPR:
1535 case CEIL_MOD_EXPR:
1536 case FLOOR_MOD_EXPR:
1537 case ROUND_MOD_EXPR:
1538 case RDIV_EXPR:
1539 case EXACT_DIV_EXPR:
1540 case LSHIFT_EXPR:
1541 case RSHIFT_EXPR:
1542 case LROTATE_EXPR:
1543 case RROTATE_EXPR:
1544 case VEC_LSHIFT_EXPR:
1545 case VEC_RSHIFT_EXPR:
1546 case BIT_IOR_EXPR:
1547 case BIT_XOR_EXPR:
1548 case BIT_AND_EXPR:
1549 case TRUTH_ANDIF_EXPR:
1550 case TRUTH_ORIF_EXPR:
1551 case TRUTH_AND_EXPR:
1552 case TRUTH_OR_EXPR:
1553 case TRUTH_XOR_EXPR:
1554 case LT_EXPR:
1555 case LE_EXPR:
1556 case GT_EXPR:
1557 case GE_EXPR:
1558 case EQ_EXPR:
1559 case NE_EXPR:
1560 case UNLT_EXPR:
1561 case UNLE_EXPR:
1562 case UNGT_EXPR:
1563 case UNGE_EXPR:
1564 case UNEQ_EXPR:
1565 case LTGT_EXPR:
1566 case ORDERED_EXPR:
1567 case UNORDERED_EXPR:
1569 const char *op = op_symbol (node);
1570 op0 = TREE_OPERAND (node, 0);
1571 op1 = TREE_OPERAND (node, 1);
1573 /* When the operands are expressions with less priority,
1574 keep semantics of the tree representation. */
1575 if (op_prio (op0) <= op_prio (node))
1577 pp_character (buffer, '(');
1578 dump_generic_node (buffer, op0, spc, flags, false);
1579 pp_character (buffer, ')');
1581 else
1582 dump_generic_node (buffer, op0, spc, flags, false);
1584 pp_space (buffer);
1585 pp_string (buffer, op);
1586 pp_space (buffer);
1588 /* When the operands are expressions with less priority,
1589 keep semantics of the tree representation. */
1590 if (op_prio (op1) <= op_prio (node))
1592 pp_character (buffer, '(');
1593 dump_generic_node (buffer, op1, spc, flags, false);
1594 pp_character (buffer, ')');
1596 else
1597 dump_generic_node (buffer, op1, spc, flags, false);
1599 break;
1601 /* Unary arithmetic and logic expressions. */
1602 case NEGATE_EXPR:
1603 case BIT_NOT_EXPR:
1604 case TRUTH_NOT_EXPR:
1605 case ADDR_EXPR:
1606 case PREDECREMENT_EXPR:
1607 case PREINCREMENT_EXPR:
1608 case INDIRECT_REF:
1609 if (TREE_CODE (node) == ADDR_EXPR
1610 && (TREE_CODE (TREE_OPERAND (node, 0)) == STRING_CST
1611 || TREE_CODE (TREE_OPERAND (node, 0)) == FUNCTION_DECL))
1612 ; /* Do not output '&' for strings and function pointers. */
1613 else
1614 pp_string (buffer, op_symbol (node));
1616 if (op_prio (TREE_OPERAND (node, 0)) < op_prio (node))
1618 pp_character (buffer, '(');
1619 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1620 pp_character (buffer, ')');
1622 else
1623 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1624 break;
1626 case POSTDECREMENT_EXPR:
1627 case POSTINCREMENT_EXPR:
1628 if (op_prio (TREE_OPERAND (node, 0)) < op_prio (node))
1630 pp_character (buffer, '(');
1631 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1632 pp_character (buffer, ')');
1634 else
1635 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1636 pp_string (buffer, op_symbol (node));
1637 break;
1639 case MIN_EXPR:
1640 pp_string (buffer, "MIN_EXPR <");
1641 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1642 pp_string (buffer, ", ");
1643 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1644 pp_character (buffer, '>');
1645 break;
1647 case MAX_EXPR:
1648 pp_string (buffer, "MAX_EXPR <");
1649 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1650 pp_string (buffer, ", ");
1651 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1652 pp_character (buffer, '>');
1653 break;
1655 case ABS_EXPR:
1656 pp_string (buffer, "ABS_EXPR <");
1657 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1658 pp_character (buffer, '>');
1659 break;
1661 case RANGE_EXPR:
1662 NIY;
1663 break;
1665 case ADDR_SPACE_CONVERT_EXPR:
1666 case FIXED_CONVERT_EXPR:
1667 case FIX_TRUNC_EXPR:
1668 case FLOAT_EXPR:
1669 CASE_CONVERT:
1670 type = TREE_TYPE (node);
1671 op0 = TREE_OPERAND (node, 0);
1672 if (type != TREE_TYPE (op0))
1674 pp_character (buffer, '(');
1675 dump_generic_node (buffer, type, spc, flags, false);
1676 pp_string (buffer, ") ");
1678 if (op_prio (op0) < op_prio (node))
1679 pp_character (buffer, '(');
1680 dump_generic_node (buffer, op0, spc, flags, false);
1681 if (op_prio (op0) < op_prio (node))
1682 pp_character (buffer, ')');
1683 break;
1685 case VIEW_CONVERT_EXPR:
1686 pp_string (buffer, "VIEW_CONVERT_EXPR<");
1687 dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
1688 pp_string (buffer, ">(");
1689 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1690 pp_character (buffer, ')');
1691 break;
1693 case PAREN_EXPR:
1694 pp_string (buffer, "((");
1695 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1696 pp_string (buffer, "))");
1697 break;
1699 case NON_LVALUE_EXPR:
1700 pp_string (buffer, "NON_LVALUE_EXPR <");
1701 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1702 pp_character (buffer, '>');
1703 break;
1705 case SAVE_EXPR:
1706 pp_string (buffer, "SAVE_EXPR <");
1707 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1708 pp_character (buffer, '>');
1709 break;
1711 case COMPLEX_EXPR:
1712 pp_string (buffer, "COMPLEX_EXPR <");
1713 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1714 pp_string (buffer, ", ");
1715 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1716 pp_string (buffer, ">");
1717 break;
1719 case CONJ_EXPR:
1720 pp_string (buffer, "CONJ_EXPR <");
1721 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1722 pp_string (buffer, ">");
1723 break;
1725 case REALPART_EXPR:
1726 pp_string (buffer, "REALPART_EXPR <");
1727 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1728 pp_string (buffer, ">");
1729 break;
1731 case IMAGPART_EXPR:
1732 pp_string (buffer, "IMAGPART_EXPR <");
1733 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1734 pp_string (buffer, ">");
1735 break;
1737 case VA_ARG_EXPR:
1738 pp_string (buffer, "VA_ARG_EXPR <");
1739 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1740 pp_string (buffer, ">");
1741 break;
1743 case TRY_FINALLY_EXPR:
1744 case TRY_CATCH_EXPR:
1745 pp_string (buffer, "try");
1746 newline_and_indent (buffer, spc+2);
1747 pp_string (buffer, "{");
1748 newline_and_indent (buffer, spc+4);
1749 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc+4, flags, true);
1750 newline_and_indent (buffer, spc+2);
1751 pp_string (buffer, "}");
1752 newline_and_indent (buffer, spc);
1753 pp_string (buffer,
1754 (TREE_CODE (node) == TRY_CATCH_EXPR) ? "catch" : "finally");
1755 newline_and_indent (buffer, spc+2);
1756 pp_string (buffer, "{");
1757 newline_and_indent (buffer, spc+4);
1758 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc+4, flags, true);
1759 newline_and_indent (buffer, spc+2);
1760 pp_string (buffer, "}");
1761 is_expr = false;
1762 break;
1764 case CATCH_EXPR:
1765 pp_string (buffer, "catch (");
1766 dump_generic_node (buffer, CATCH_TYPES (node), spc+2, flags, false);
1767 pp_string (buffer, ")");
1768 newline_and_indent (buffer, spc+2);
1769 pp_string (buffer, "{");
1770 newline_and_indent (buffer, spc+4);
1771 dump_generic_node (buffer, CATCH_BODY (node), spc+4, flags, true);
1772 newline_and_indent (buffer, spc+2);
1773 pp_string (buffer, "}");
1774 is_expr = false;
1775 break;
1777 case EH_FILTER_EXPR:
1778 pp_string (buffer, "<<<eh_filter (");
1779 dump_generic_node (buffer, EH_FILTER_TYPES (node), spc+2, flags, false);
1780 pp_string (buffer, ")>>>");
1781 newline_and_indent (buffer, spc+2);
1782 pp_string (buffer, "{");
1783 newline_and_indent (buffer, spc+4);
1784 dump_generic_node (buffer, EH_FILTER_FAILURE (node), spc+4, flags, true);
1785 newline_and_indent (buffer, spc+2);
1786 pp_string (buffer, "}");
1787 is_expr = false;
1788 break;
1790 case LABEL_EXPR:
1791 op0 = TREE_OPERAND (node, 0);
1792 /* If this is for break or continue, don't bother printing it. */
1793 if (DECL_NAME (op0))
1795 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1796 if (strcmp (name, "break") == 0
1797 || strcmp (name, "continue") == 0)
1798 break;
1800 dump_generic_node (buffer, op0, spc, flags, false);
1801 pp_character (buffer, ':');
1802 if (DECL_NONLOCAL (op0))
1803 pp_string (buffer, " [non-local]");
1804 break;
1806 case LOOP_EXPR:
1807 pp_string (buffer, "while (1)");
1808 if (!(flags & TDF_SLIM))
1810 newline_and_indent (buffer, spc+2);
1811 pp_character (buffer, '{');
1812 newline_and_indent (buffer, spc+4);
1813 dump_generic_node (buffer, LOOP_EXPR_BODY (node), spc+4, flags, true);
1814 newline_and_indent (buffer, spc+2);
1815 pp_character (buffer, '}');
1817 is_expr = false;
1818 break;
1820 case PREDICT_EXPR:
1821 pp_string (buffer, "// predicted ");
1822 if (PREDICT_EXPR_OUTCOME (node))
1823 pp_string (buffer, "likely by ");
1824 else
1825 pp_string (buffer, "unlikely by ");
1826 pp_string (buffer, predictor_name (PREDICT_EXPR_PREDICTOR (node)));
1827 pp_string (buffer, " predictor.");
1828 break;
1830 case RETURN_EXPR:
1831 pp_string (buffer, "return");
1832 op0 = TREE_OPERAND (node, 0);
1833 if (op0)
1835 pp_space (buffer);
1836 if (TREE_CODE (op0) == MODIFY_EXPR)
1837 dump_generic_node (buffer, TREE_OPERAND (op0, 1),
1838 spc, flags, false);
1839 else
1840 dump_generic_node (buffer, op0, spc, flags, false);
1842 break;
1844 case EXIT_EXPR:
1845 pp_string (buffer, "if (");
1846 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1847 pp_string (buffer, ") break");
1848 break;
1850 case SWITCH_EXPR:
1851 pp_string (buffer, "switch (");
1852 dump_generic_node (buffer, SWITCH_COND (node), spc, flags, false);
1853 pp_character (buffer, ')');
1854 if (!(flags & TDF_SLIM))
1856 newline_and_indent (buffer, spc+2);
1857 pp_character (buffer, '{');
1858 if (SWITCH_BODY (node))
1860 newline_and_indent (buffer, spc+4);
1861 dump_generic_node (buffer, SWITCH_BODY (node), spc+4, flags,
1862 true);
1864 else
1866 tree vec = SWITCH_LABELS (node);
1867 size_t i, n = TREE_VEC_LENGTH (vec);
1868 for (i = 0; i < n; ++i)
1870 tree elt = TREE_VEC_ELT (vec, i);
1871 newline_and_indent (buffer, spc+4);
1872 if (elt)
1874 dump_generic_node (buffer, elt, spc+4, flags, false);
1875 pp_string (buffer, " goto ");
1876 dump_generic_node (buffer, CASE_LABEL (elt), spc+4,
1877 flags, true);
1878 pp_semicolon (buffer);
1880 else
1881 pp_string (buffer, "case ???: goto ???;");
1884 newline_and_indent (buffer, spc+2);
1885 pp_character (buffer, '}');
1887 is_expr = false;
1888 break;
1890 case GOTO_EXPR:
1891 op0 = GOTO_DESTINATION (node);
1892 if (TREE_CODE (op0) != SSA_NAME && DECL_P (op0) && DECL_NAME (op0))
1894 const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
1895 if (strcmp (name, "break") == 0
1896 || strcmp (name, "continue") == 0)
1898 pp_string (buffer, name);
1899 break;
1902 pp_string (buffer, "goto ");
1903 dump_generic_node (buffer, op0, spc, flags, false);
1904 break;
1906 case ASM_EXPR:
1907 pp_string (buffer, "__asm__");
1908 if (ASM_VOLATILE_P (node))
1909 pp_string (buffer, " __volatile__");
1910 pp_character (buffer, '(');
1911 dump_generic_node (buffer, ASM_STRING (node), spc, flags, false);
1912 pp_character (buffer, ':');
1913 dump_generic_node (buffer, ASM_OUTPUTS (node), spc, flags, false);
1914 pp_character (buffer, ':');
1915 dump_generic_node (buffer, ASM_INPUTS (node), spc, flags, false);
1916 if (ASM_CLOBBERS (node))
1918 pp_character (buffer, ':');
1919 dump_generic_node (buffer, ASM_CLOBBERS (node), spc, flags, false);
1921 pp_string (buffer, ")");
1922 break;
1924 case CASE_LABEL_EXPR:
1925 if (CASE_LOW (node) && CASE_HIGH (node))
1927 pp_string (buffer, "case ");
1928 dump_generic_node (buffer, CASE_LOW (node), spc, flags, false);
1929 pp_string (buffer, " ... ");
1930 dump_generic_node (buffer, CASE_HIGH (node), spc, flags, false);
1932 else if (CASE_LOW (node))
1934 pp_string (buffer, "case ");
1935 dump_generic_node (buffer, CASE_LOW (node), spc, flags, false);
1937 else
1938 pp_string (buffer, "default");
1939 pp_character (buffer, ':');
1940 break;
1942 case OBJ_TYPE_REF:
1943 pp_string (buffer, "OBJ_TYPE_REF(");
1944 dump_generic_node (buffer, OBJ_TYPE_REF_EXPR (node), spc, flags, false);
1945 pp_character (buffer, ';');
1946 dump_generic_node (buffer, OBJ_TYPE_REF_OBJECT (node), spc, flags, false);
1947 pp_character (buffer, '-');
1948 pp_character (buffer, '>');
1949 dump_generic_node (buffer, OBJ_TYPE_REF_TOKEN (node), spc, flags, false);
1950 pp_character (buffer, ')');
1951 break;
1953 case SSA_NAME:
1954 dump_generic_node (buffer, SSA_NAME_VAR (node), spc, flags, false);
1955 pp_string (buffer, "_");
1956 pp_decimal_int (buffer, SSA_NAME_VERSION (node));
1957 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (node))
1958 pp_string (buffer, "(ab)");
1959 else if (SSA_NAME_IS_DEFAULT_DEF (node))
1960 pp_string (buffer, "(D)");
1961 break;
1963 case WITH_SIZE_EXPR:
1964 pp_string (buffer, "WITH_SIZE_EXPR <");
1965 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
1966 pp_string (buffer, ", ");
1967 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
1968 pp_string (buffer, ">");
1969 break;
1971 case ASSERT_EXPR:
1972 pp_string (buffer, "ASSERT_EXPR <");
1973 dump_generic_node (buffer, ASSERT_EXPR_VAR (node), spc, flags, false);
1974 pp_string (buffer, ", ");
1975 dump_generic_node (buffer, ASSERT_EXPR_COND (node), spc, flags, false);
1976 pp_string (buffer, ">");
1977 break;
1979 case SCEV_KNOWN:
1980 pp_string (buffer, "scev_known");
1981 break;
1983 case SCEV_NOT_KNOWN:
1984 pp_string (buffer, "scev_not_known");
1985 break;
1987 case POLYNOMIAL_CHREC:
1988 pp_string (buffer, "{");
1989 dump_generic_node (buffer, CHREC_LEFT (node), spc, flags, false);
1990 pp_string (buffer, ", +, ");
1991 dump_generic_node (buffer, CHREC_RIGHT (node), spc, flags, false);
1992 pp_string (buffer, "}_");
1993 dump_generic_node (buffer, CHREC_VAR (node), spc, flags, false);
1994 is_stmt = false;
1995 break;
1997 case REALIGN_LOAD_EXPR:
1998 pp_string (buffer, "REALIGN_LOAD <");
1999 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2000 pp_string (buffer, ", ");
2001 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2002 pp_string (buffer, ", ");
2003 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2004 pp_string (buffer, ">");
2005 break;
2007 case VEC_COND_EXPR:
2008 pp_string (buffer, " VEC_COND_EXPR < ");
2009 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2010 pp_string (buffer, " , ");
2011 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2012 pp_string (buffer, " , ");
2013 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2014 pp_string (buffer, " > ");
2015 break;
2017 case DOT_PROD_EXPR:
2018 pp_string (buffer, " DOT_PROD_EXPR < ");
2019 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2020 pp_string (buffer, ", ");
2021 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2022 pp_string (buffer, ", ");
2023 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2024 pp_string (buffer, " > ");
2025 break;
2027 case WIDEN_MULT_PLUS_EXPR:
2028 pp_string (buffer, " WIDEN_MULT_PLUS_EXPR < ");
2029 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2030 pp_string (buffer, ", ");
2031 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2032 pp_string (buffer, ", ");
2033 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2034 pp_string (buffer, " > ");
2035 break;
2037 case WIDEN_MULT_MINUS_EXPR:
2038 pp_string (buffer, " WIDEN_MULT_MINUS_EXPR < ");
2039 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2040 pp_string (buffer, ", ");
2041 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2042 pp_string (buffer, ", ");
2043 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2044 pp_string (buffer, " > ");
2045 break;
2047 case FMA_EXPR:
2048 pp_string (buffer, " FMA_EXPR < ");
2049 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2050 pp_string (buffer, ", ");
2051 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2052 pp_string (buffer, ", ");
2053 dump_generic_node (buffer, TREE_OPERAND (node, 2), spc, flags, false);
2054 pp_string (buffer, " > ");
2055 break;
2057 case OMP_PARALLEL:
2058 pp_string (buffer, "#pragma omp parallel");
2059 dump_omp_clauses (buffer, OMP_PARALLEL_CLAUSES (node), spc, flags);
2061 dump_omp_body:
2062 if (!(flags & TDF_SLIM) && OMP_BODY (node))
2064 newline_and_indent (buffer, spc + 2);
2065 pp_character (buffer, '{');
2066 newline_and_indent (buffer, spc + 4);
2067 dump_generic_node (buffer, OMP_BODY (node), spc + 4, flags, false);
2068 newline_and_indent (buffer, spc + 2);
2069 pp_character (buffer, '}');
2071 is_expr = false;
2072 break;
2074 case OMP_TASK:
2075 pp_string (buffer, "#pragma omp task");
2076 dump_omp_clauses (buffer, OMP_TASK_CLAUSES (node), spc, flags);
2077 goto dump_omp_body;
2079 case OMP_FOR:
2080 pp_string (buffer, "#pragma omp for");
2081 dump_omp_clauses (buffer, OMP_FOR_CLAUSES (node), spc, flags);
2083 if (!(flags & TDF_SLIM))
2085 int i;
2087 if (OMP_FOR_PRE_BODY (node))
2089 newline_and_indent (buffer, spc + 2);
2090 pp_character (buffer, '{');
2091 spc += 4;
2092 newline_and_indent (buffer, spc);
2093 dump_generic_node (buffer, OMP_FOR_PRE_BODY (node),
2094 spc, flags, false);
2096 spc -= 2;
2097 for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (node)); i++)
2099 spc += 2;
2100 newline_and_indent (buffer, spc);
2101 pp_string (buffer, "for (");
2102 dump_generic_node (buffer, TREE_VEC_ELT (OMP_FOR_INIT (node), i),
2103 spc, flags, false);
2104 pp_string (buffer, "; ");
2105 dump_generic_node (buffer, TREE_VEC_ELT (OMP_FOR_COND (node), i),
2106 spc, flags, false);
2107 pp_string (buffer, "; ");
2108 dump_generic_node (buffer, TREE_VEC_ELT (OMP_FOR_INCR (node), i),
2109 spc, flags, false);
2110 pp_string (buffer, ")");
2112 if (OMP_FOR_BODY (node))
2114 newline_and_indent (buffer, spc + 2);
2115 pp_character (buffer, '{');
2116 newline_and_indent (buffer, spc + 4);
2117 dump_generic_node (buffer, OMP_FOR_BODY (node), spc + 4, flags,
2118 false);
2119 newline_and_indent (buffer, spc + 2);
2120 pp_character (buffer, '}');
2122 spc -= 2 * TREE_VEC_LENGTH (OMP_FOR_INIT (node)) - 2;
2123 if (OMP_FOR_PRE_BODY (node))
2125 spc -= 4;
2126 newline_and_indent (buffer, spc + 2);
2127 pp_character (buffer, '}');
2130 is_expr = false;
2131 break;
2133 case OMP_SECTIONS:
2134 pp_string (buffer, "#pragma omp sections");
2135 dump_omp_clauses (buffer, OMP_SECTIONS_CLAUSES (node), spc, flags);
2136 goto dump_omp_body;
2138 case OMP_SECTION:
2139 pp_string (buffer, "#pragma omp section");
2140 goto dump_omp_body;
2142 case OMP_MASTER:
2143 pp_string (buffer, "#pragma omp master");
2144 goto dump_omp_body;
2146 case OMP_ORDERED:
2147 pp_string (buffer, "#pragma omp ordered");
2148 goto dump_omp_body;
2150 case OMP_CRITICAL:
2151 pp_string (buffer, "#pragma omp critical");
2152 if (OMP_CRITICAL_NAME (node))
2154 pp_space (buffer);
2155 pp_character (buffer, '(');
2156 dump_generic_node (buffer, OMP_CRITICAL_NAME (node), spc,
2157 flags, false);
2158 pp_character (buffer, ')');
2160 goto dump_omp_body;
2162 case OMP_ATOMIC:
2163 pp_string (buffer, "#pragma omp atomic");
2164 newline_and_indent (buffer, spc + 2);
2165 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2166 pp_space (buffer);
2167 pp_character (buffer, '=');
2168 pp_space (buffer);
2169 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2170 break;
2172 case OMP_SINGLE:
2173 pp_string (buffer, "#pragma omp single");
2174 dump_omp_clauses (buffer, OMP_SINGLE_CLAUSES (node), spc, flags);
2175 goto dump_omp_body;
2177 case OMP_CLAUSE:
2178 dump_omp_clause (buffer, node, spc, flags);
2179 is_expr = false;
2180 break;
2182 case REDUC_MAX_EXPR:
2183 pp_string (buffer, " REDUC_MAX_EXPR < ");
2184 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2185 pp_string (buffer, " > ");
2186 break;
2188 case REDUC_MIN_EXPR:
2189 pp_string (buffer, " REDUC_MIN_EXPR < ");
2190 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2191 pp_string (buffer, " > ");
2192 break;
2194 case REDUC_PLUS_EXPR:
2195 pp_string (buffer, " REDUC_PLUS_EXPR < ");
2196 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2197 pp_string (buffer, " > ");
2198 break;
2200 case VEC_WIDEN_MULT_HI_EXPR:
2201 pp_string (buffer, " VEC_WIDEN_MULT_HI_EXPR < ");
2202 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2203 pp_string (buffer, ", ");
2204 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2205 pp_string (buffer, " > ");
2206 break;
2208 case VEC_WIDEN_MULT_LO_EXPR:
2209 pp_string (buffer, " VEC_WIDEN_MULT_LO_EXPR < ");
2210 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2211 pp_string (buffer, ", ");
2212 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2213 pp_string (buffer, " > ");
2214 break;
2216 case VEC_UNPACK_HI_EXPR:
2217 pp_string (buffer, " VEC_UNPACK_HI_EXPR < ");
2218 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2219 pp_string (buffer, " > ");
2220 break;
2222 case VEC_UNPACK_LO_EXPR:
2223 pp_string (buffer, " VEC_UNPACK_LO_EXPR < ");
2224 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2225 pp_string (buffer, " > ");
2226 break;
2228 case VEC_UNPACK_FLOAT_HI_EXPR:
2229 pp_string (buffer, " VEC_UNPACK_FLOAT_HI_EXPR < ");
2230 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2231 pp_string (buffer, " > ");
2232 break;
2234 case VEC_UNPACK_FLOAT_LO_EXPR:
2235 pp_string (buffer, " VEC_UNPACK_FLOAT_LO_EXPR < ");
2236 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2237 pp_string (buffer, " > ");
2238 break;
2240 case VEC_PACK_TRUNC_EXPR:
2241 pp_string (buffer, " VEC_PACK_TRUNC_EXPR < ");
2242 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2243 pp_string (buffer, ", ");
2244 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2245 pp_string (buffer, " > ");
2246 break;
2248 case VEC_PACK_SAT_EXPR:
2249 pp_string (buffer, " VEC_PACK_SAT_EXPR < ");
2250 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2251 pp_string (buffer, ", ");
2252 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2253 pp_string (buffer, " > ");
2254 break;
2256 case VEC_PACK_FIX_TRUNC_EXPR:
2257 pp_string (buffer, " VEC_PACK_FIX_TRUNC_EXPR < ");
2258 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2259 pp_string (buffer, ", ");
2260 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2261 pp_string (buffer, " > ");
2262 break;
2264 case BLOCK:
2265 dump_block_node (buffer, node, spc, flags);
2266 break;
2268 case VEC_EXTRACT_EVEN_EXPR:
2269 pp_string (buffer, " VEC_EXTRACT_EVEN_EXPR < ");
2270 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2271 pp_string (buffer, ", ");
2272 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2273 pp_string (buffer, " > ");
2274 break;
2276 case VEC_EXTRACT_ODD_EXPR:
2277 pp_string (buffer, " VEC_EXTRACT_ODD_EXPR < ");
2278 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2279 pp_string (buffer, ", ");
2280 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2281 pp_string (buffer, " > ");
2282 break;
2284 case VEC_INTERLEAVE_HIGH_EXPR:
2285 pp_string (buffer, " VEC_INTERLEAVE_HIGH_EXPR < ");
2286 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2287 pp_string (buffer, ", ");
2288 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2289 pp_string (buffer, " > ");
2290 break;
2292 case VEC_INTERLEAVE_LOW_EXPR:
2293 pp_string (buffer, " VEC_INTERLEAVE_LOW_EXPR < ");
2294 dump_generic_node (buffer, TREE_OPERAND (node, 0), spc, flags, false);
2295 pp_string (buffer, ", ");
2296 dump_generic_node (buffer, TREE_OPERAND (node, 1), spc, flags, false);
2297 pp_string (buffer, " > ");
2298 break;
2300 default:
2301 NIY;
2304 if (is_stmt && is_expr)
2305 pp_semicolon (buffer);
2307 /* If we're building a diagnostic, the formatted text will be written
2308 into BUFFER's stream by the caller; otherwise, write it now. */
2309 if (!(flags & TDF_DIAGNOSTIC))
2310 pp_write_text_to_stream (buffer);
2312 return spc;
2315 /* Print the declaration of a variable. */
2317 void
2318 print_declaration (pretty_printer *buffer, tree t, int spc, int flags)
2320 INDENT (spc);
2322 if (TREE_CODE (t) == TYPE_DECL)
2323 pp_string (buffer, "typedef ");
2325 if (CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_DECL_WRTL) && DECL_REGISTER (t))
2326 pp_string (buffer, "register ");
2328 if (TREE_PUBLIC (t) && DECL_EXTERNAL (t))
2329 pp_string (buffer, "extern ");
2330 else if (TREE_STATIC (t))
2331 pp_string (buffer, "static ");
2333 /* Print the type and name. */
2334 if (TREE_TYPE (t) && TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
2336 tree tmp;
2338 /* Print array's type. */
2339 tmp = TREE_TYPE (t);
2340 while (TREE_CODE (TREE_TYPE (tmp)) == ARRAY_TYPE)
2341 tmp = TREE_TYPE (tmp);
2342 dump_generic_node (buffer, TREE_TYPE (tmp), spc, flags, false);
2344 /* Print variable's name. */
2345 pp_space (buffer);
2346 dump_generic_node (buffer, t, spc, flags, false);
2348 /* Print the dimensions. */
2349 tmp = TREE_TYPE (t);
2350 while (TREE_CODE (tmp) == ARRAY_TYPE)
2352 dump_array_domain (buffer, TYPE_DOMAIN (tmp), spc, flags);
2353 tmp = TREE_TYPE (tmp);
2356 else if (TREE_CODE (t) == FUNCTION_DECL)
2358 dump_generic_node (buffer, TREE_TYPE (TREE_TYPE (t)), spc, flags, false);
2359 pp_space (buffer);
2360 dump_decl_name (buffer, t, flags);
2361 dump_function_declaration (buffer, TREE_TYPE (t), spc, flags);
2363 else
2365 /* Print type declaration. */
2366 dump_generic_node (buffer, TREE_TYPE (t), spc, flags, false);
2368 /* Print variable's name. */
2369 pp_space (buffer);
2370 dump_generic_node (buffer, t, spc, flags, false);
2373 if (TREE_CODE (t) == VAR_DECL && DECL_HARD_REGISTER (t))
2375 pp_string (buffer, " __asm__ ");
2376 pp_character (buffer, '(');
2377 dump_generic_node (buffer, DECL_ASSEMBLER_NAME (t), spc, flags, false);
2378 pp_character (buffer, ')');
2381 /* The initial value of a function serves to determine whether the function
2382 is declared or defined. So the following does not apply to function
2383 nodes. */
2384 if (TREE_CODE (t) != FUNCTION_DECL)
2386 /* Print the initial value. */
2387 if (DECL_INITIAL (t))
2389 pp_space (buffer);
2390 pp_character (buffer, '=');
2391 pp_space (buffer);
2392 dump_generic_node (buffer, DECL_INITIAL (t), spc, flags, false);
2396 if (TREE_CODE (t) == VAR_DECL && DECL_HAS_VALUE_EXPR_P (t))
2398 pp_string (buffer, " [value-expr: ");
2399 dump_generic_node (buffer, DECL_VALUE_EXPR (t), spc, flags, false);
2400 pp_character (buffer, ']');
2403 pp_character (buffer, ';');
2407 /* Prints a structure: name, fields, and methods.
2408 FIXME: Still incomplete. */
2410 static void
2411 print_struct_decl (pretty_printer *buffer, const_tree node, int spc, int flags)
2413 /* Print the name of the structure. */
2414 if (TYPE_NAME (node))
2416 INDENT (spc);
2417 if (TREE_CODE (node) == RECORD_TYPE)
2418 pp_string (buffer, "struct ");
2419 else if ((TREE_CODE (node) == UNION_TYPE
2420 || TREE_CODE (node) == QUAL_UNION_TYPE))
2421 pp_string (buffer, "union ");
2423 dump_generic_node (buffer, TYPE_NAME (node), spc, 0, false);
2426 /* Print the contents of the structure. */
2427 pp_newline (buffer);
2428 INDENT (spc);
2429 pp_character (buffer, '{');
2430 pp_newline (buffer);
2432 /* Print the fields of the structure. */
2434 tree tmp;
2435 tmp = TYPE_FIELDS (node);
2436 while (tmp)
2438 /* Avoid to print recursively the structure. */
2439 /* FIXME : Not implemented correctly...,
2440 what about the case when we have a cycle in the contain graph? ...
2441 Maybe this could be solved by looking at the scope in which the
2442 structure was declared. */
2443 if (TREE_TYPE (tmp) != node
2444 && (TREE_CODE (TREE_TYPE (tmp)) != POINTER_TYPE
2445 || TREE_TYPE (TREE_TYPE (tmp)) != node))
2447 print_declaration (buffer, tmp, spc+2, flags);
2448 pp_newline (buffer);
2450 tmp = DECL_CHAIN (tmp);
2453 INDENT (spc);
2454 pp_character (buffer, '}');
2457 /* Return the priority of the operator CODE.
2459 From lowest to highest precedence with either left-to-right (L-R)
2460 or right-to-left (R-L) associativity]:
2462 1 [L-R] ,
2463 2 [R-L] = += -= *= /= %= &= ^= |= <<= >>=
2464 3 [R-L] ?:
2465 4 [L-R] ||
2466 5 [L-R] &&
2467 6 [L-R] |
2468 7 [L-R] ^
2469 8 [L-R] &
2470 9 [L-R] == !=
2471 10 [L-R] < <= > >=
2472 11 [L-R] << >>
2473 12 [L-R] + -
2474 13 [L-R] * / %
2475 14 [R-L] ! ~ ++ -- + - * & (type) sizeof
2476 15 [L-R] fn() [] -> .
2478 unary +, - and * have higher precedence than the corresponding binary
2479 operators. */
2482 op_code_prio (enum tree_code code)
2484 switch (code)
2486 case TREE_LIST:
2487 case COMPOUND_EXPR:
2488 case BIND_EXPR:
2489 return 1;
2491 case MODIFY_EXPR:
2492 case INIT_EXPR:
2493 return 2;
2495 case COND_EXPR:
2496 return 3;
2498 case TRUTH_OR_EXPR:
2499 case TRUTH_ORIF_EXPR:
2500 return 4;
2502 case TRUTH_AND_EXPR:
2503 case TRUTH_ANDIF_EXPR:
2504 return 5;
2506 case BIT_IOR_EXPR:
2507 return 6;
2509 case BIT_XOR_EXPR:
2510 case TRUTH_XOR_EXPR:
2511 return 7;
2513 case BIT_AND_EXPR:
2514 return 8;
2516 case EQ_EXPR:
2517 case NE_EXPR:
2518 return 9;
2520 case UNLT_EXPR:
2521 case UNLE_EXPR:
2522 case UNGT_EXPR:
2523 case UNGE_EXPR:
2524 case UNEQ_EXPR:
2525 case LTGT_EXPR:
2526 case ORDERED_EXPR:
2527 case UNORDERED_EXPR:
2528 case LT_EXPR:
2529 case LE_EXPR:
2530 case GT_EXPR:
2531 case GE_EXPR:
2532 return 10;
2534 case LSHIFT_EXPR:
2535 case RSHIFT_EXPR:
2536 case LROTATE_EXPR:
2537 case RROTATE_EXPR:
2538 return 11;
2540 case WIDEN_SUM_EXPR:
2541 case PLUS_EXPR:
2542 case POINTER_PLUS_EXPR:
2543 case MINUS_EXPR:
2544 return 12;
2546 case VEC_WIDEN_MULT_HI_EXPR:
2547 case VEC_WIDEN_MULT_LO_EXPR:
2548 case WIDEN_MULT_EXPR:
2549 case DOT_PROD_EXPR:
2550 case WIDEN_MULT_PLUS_EXPR:
2551 case WIDEN_MULT_MINUS_EXPR:
2552 case MULT_EXPR:
2553 case TRUNC_DIV_EXPR:
2554 case CEIL_DIV_EXPR:
2555 case FLOOR_DIV_EXPR:
2556 case ROUND_DIV_EXPR:
2557 case RDIV_EXPR:
2558 case EXACT_DIV_EXPR:
2559 case TRUNC_MOD_EXPR:
2560 case CEIL_MOD_EXPR:
2561 case FLOOR_MOD_EXPR:
2562 case ROUND_MOD_EXPR:
2563 case FMA_EXPR:
2564 return 13;
2566 case TRUTH_NOT_EXPR:
2567 case BIT_NOT_EXPR:
2568 case POSTINCREMENT_EXPR:
2569 case POSTDECREMENT_EXPR:
2570 case PREINCREMENT_EXPR:
2571 case PREDECREMENT_EXPR:
2572 case NEGATE_EXPR:
2573 case INDIRECT_REF:
2574 case ADDR_EXPR:
2575 case FLOAT_EXPR:
2576 CASE_CONVERT:
2577 case FIX_TRUNC_EXPR:
2578 case TARGET_EXPR:
2579 return 14;
2581 case CALL_EXPR:
2582 case ARRAY_REF:
2583 case ARRAY_RANGE_REF:
2584 case COMPONENT_REF:
2585 return 15;
2587 /* Special expressions. */
2588 case MIN_EXPR:
2589 case MAX_EXPR:
2590 case ABS_EXPR:
2591 case REALPART_EXPR:
2592 case IMAGPART_EXPR:
2593 case REDUC_MAX_EXPR:
2594 case REDUC_MIN_EXPR:
2595 case REDUC_PLUS_EXPR:
2596 case VEC_LSHIFT_EXPR:
2597 case VEC_RSHIFT_EXPR:
2598 case VEC_UNPACK_HI_EXPR:
2599 case VEC_UNPACK_LO_EXPR:
2600 case VEC_UNPACK_FLOAT_HI_EXPR:
2601 case VEC_UNPACK_FLOAT_LO_EXPR:
2602 case VEC_PACK_TRUNC_EXPR:
2603 case VEC_PACK_SAT_EXPR:
2604 return 16;
2606 default:
2607 /* Return an arbitrarily high precedence to avoid surrounding single
2608 VAR_DECLs in ()s. */
2609 return 9999;
2613 /* Return the priority of the operator OP. */
2616 op_prio (const_tree op)
2618 enum tree_code code;
2620 if (op == NULL)
2621 return 9999;
2623 code = TREE_CODE (op);
2624 if (code == SAVE_EXPR || code == NON_LVALUE_EXPR)
2625 return op_prio (TREE_OPERAND (op, 0));
2627 return op_code_prio (code);
2630 /* Return the symbol associated with operator CODE. */
2632 const char *
2633 op_symbol_code (enum tree_code code)
2635 switch (code)
2637 case MODIFY_EXPR:
2638 return "=";
2640 case TRUTH_OR_EXPR:
2641 case TRUTH_ORIF_EXPR:
2642 return "||";
2644 case TRUTH_AND_EXPR:
2645 case TRUTH_ANDIF_EXPR:
2646 return "&&";
2648 case BIT_IOR_EXPR:
2649 return "|";
2651 case TRUTH_XOR_EXPR:
2652 case BIT_XOR_EXPR:
2653 return "^";
2655 case ADDR_EXPR:
2656 case BIT_AND_EXPR:
2657 return "&";
2659 case ORDERED_EXPR:
2660 return "ord";
2661 case UNORDERED_EXPR:
2662 return "unord";
2664 case EQ_EXPR:
2665 return "==";
2666 case UNEQ_EXPR:
2667 return "u==";
2669 case NE_EXPR:
2670 return "!=";
2672 case LT_EXPR:
2673 return "<";
2674 case UNLT_EXPR:
2675 return "u<";
2677 case LE_EXPR:
2678 return "<=";
2679 case UNLE_EXPR:
2680 return "u<=";
2682 case GT_EXPR:
2683 return ">";
2684 case UNGT_EXPR:
2685 return "u>";
2687 case GE_EXPR:
2688 return ">=";
2689 case UNGE_EXPR:
2690 return "u>=";
2692 case LTGT_EXPR:
2693 return "<>";
2695 case LSHIFT_EXPR:
2696 return "<<";
2698 case RSHIFT_EXPR:
2699 return ">>";
2701 case LROTATE_EXPR:
2702 return "r<<";
2704 case RROTATE_EXPR:
2705 return "r>>";
2707 case VEC_LSHIFT_EXPR:
2708 return "v<<";
2710 case VEC_RSHIFT_EXPR:
2711 return "v>>";
2713 case POINTER_PLUS_EXPR:
2714 return "+";
2716 case PLUS_EXPR:
2717 return "+";
2719 case REDUC_PLUS_EXPR:
2720 return "r+";
2722 case WIDEN_SUM_EXPR:
2723 return "w+";
2725 case WIDEN_MULT_EXPR:
2726 return "w*";
2728 case NEGATE_EXPR:
2729 case MINUS_EXPR:
2730 return "-";
2732 case BIT_NOT_EXPR:
2733 return "~";
2735 case TRUTH_NOT_EXPR:
2736 return "!";
2738 case MULT_EXPR:
2739 case INDIRECT_REF:
2740 return "*";
2742 case TRUNC_DIV_EXPR:
2743 case RDIV_EXPR:
2744 return "/";
2746 case CEIL_DIV_EXPR:
2747 return "/[cl]";
2749 case FLOOR_DIV_EXPR:
2750 return "/[fl]";
2752 case ROUND_DIV_EXPR:
2753 return "/[rd]";
2755 case EXACT_DIV_EXPR:
2756 return "/[ex]";
2758 case TRUNC_MOD_EXPR:
2759 return "%";
2761 case CEIL_MOD_EXPR:
2762 return "%[cl]";
2764 case FLOOR_MOD_EXPR:
2765 return "%[fl]";
2767 case ROUND_MOD_EXPR:
2768 return "%[rd]";
2770 case PREDECREMENT_EXPR:
2771 return " --";
2773 case PREINCREMENT_EXPR:
2774 return " ++";
2776 case POSTDECREMENT_EXPR:
2777 return "-- ";
2779 case POSTINCREMENT_EXPR:
2780 return "++ ";
2782 case MAX_EXPR:
2783 return "max";
2785 case MIN_EXPR:
2786 return "min";
2788 default:
2789 return "<<< ??? >>>";
2793 /* Return the symbol associated with operator OP. */
2795 static const char *
2796 op_symbol (const_tree op)
2798 return op_symbol_code (TREE_CODE (op));
2801 /* Prints the name of a call. NODE is the CALL_EXPR_FN of a CALL_EXPR or
2802 the gimple_call_fn of a GIMPLE_CALL. */
2804 void
2805 print_call_name (pretty_printer *buffer, tree node, int flags)
2807 tree op0 = node;
2809 if (TREE_CODE (op0) == NON_LVALUE_EXPR)
2810 op0 = TREE_OPERAND (op0, 0);
2812 again:
2813 switch (TREE_CODE (op0))
2815 case VAR_DECL:
2816 case PARM_DECL:
2817 case FUNCTION_DECL:
2818 dump_function_name (buffer, op0, flags);
2819 break;
2821 case ADDR_EXPR:
2822 case INDIRECT_REF:
2823 case NOP_EXPR:
2824 op0 = TREE_OPERAND (op0, 0);
2825 goto again;
2827 case COND_EXPR:
2828 pp_string (buffer, "(");
2829 dump_generic_node (buffer, TREE_OPERAND (op0, 0), 0, flags, false);
2830 pp_string (buffer, ") ? ");
2831 dump_generic_node (buffer, TREE_OPERAND (op0, 1), 0, flags, false);
2832 pp_string (buffer, " : ");
2833 dump_generic_node (buffer, TREE_OPERAND (op0, 2), 0, flags, false);
2834 break;
2836 case ARRAY_REF:
2837 if (TREE_CODE (TREE_OPERAND (op0, 0)) == VAR_DECL)
2838 dump_function_name (buffer, TREE_OPERAND (op0, 0), flags);
2839 else
2840 dump_generic_node (buffer, op0, 0, flags, false);
2841 break;
2843 case MEM_REF:
2844 if (integer_zerop (TREE_OPERAND (op0, 1)))
2846 op0 = TREE_OPERAND (op0, 0);
2847 goto again;
2849 /* Fallthru. */
2850 case COMPONENT_REF:
2851 case SSA_NAME:
2852 case OBJ_TYPE_REF:
2853 dump_generic_node (buffer, op0, 0, flags, false);
2854 break;
2856 default:
2857 NIY;
2861 /* Parses the string STR and replaces new-lines by '\n', tabs by '\t', ... */
2863 static void
2864 pretty_print_string (pretty_printer *buffer, const char *str)
2866 if (str == NULL)
2867 return;
2869 while (*str)
2871 switch (str[0])
2873 case '\b':
2874 pp_string (buffer, "\\b");
2875 break;
2877 case '\f':
2878 pp_string (buffer, "\\f");
2879 break;
2881 case '\n':
2882 pp_string (buffer, "\\n");
2883 break;
2885 case '\r':
2886 pp_string (buffer, "\\r");
2887 break;
2889 case '\t':
2890 pp_string (buffer, "\\t");
2891 break;
2893 case '\v':
2894 pp_string (buffer, "\\v");
2895 break;
2897 case '\\':
2898 pp_string (buffer, "\\\\");
2899 break;
2901 case '\"':
2902 pp_string (buffer, "\\\"");
2903 break;
2905 case '\'':
2906 pp_string (buffer, "\\'");
2907 break;
2909 /* No need to handle \0; the loop terminates on \0. */
2911 case '\1':
2912 pp_string (buffer, "\\1");
2913 break;
2915 case '\2':
2916 pp_string (buffer, "\\2");
2917 break;
2919 case '\3':
2920 pp_string (buffer, "\\3");
2921 break;
2923 case '\4':
2924 pp_string (buffer, "\\4");
2925 break;
2927 case '\5':
2928 pp_string (buffer, "\\5");
2929 break;
2931 case '\6':
2932 pp_string (buffer, "\\6");
2933 break;
2935 case '\7':
2936 pp_string (buffer, "\\7");
2937 break;
2939 default:
2940 pp_character (buffer, str[0]);
2941 break;
2943 str++;
2947 static void
2948 maybe_init_pretty_print (FILE *file)
2950 if (!initialized)
2952 pp_construct (&buffer, /* prefix */NULL, /* line-width */0);
2953 pp_needs_newline (&buffer) = true;
2954 pp_translate_identifiers (&buffer) = false;
2955 initialized = 1;
2958 buffer.buffer->stream = file;
2961 static void
2962 newline_and_indent (pretty_printer *buffer, int spc)
2964 pp_newline (buffer);
2965 INDENT (spc);
2968 /* Handle a %K format for TEXT. Separate from default_tree_printer so
2969 it can also be used in front ends.
2970 %K: a statement, from which EXPR_LOCATION and TREE_BLOCK will be recorded.
2973 void
2974 percent_K_format (text_info *text)
2976 tree t = va_arg (*text->args_ptr, tree), block;
2977 gcc_assert (text->locus != NULL);
2978 *text->locus = EXPR_LOCATION (t);
2979 gcc_assert (pp_ti_abstract_origin (text) != NULL);
2980 block = TREE_BLOCK (t);
2981 *pp_ti_abstract_origin (text) = NULL;
2982 while (block
2983 && TREE_CODE (block) == BLOCK
2984 && BLOCK_ABSTRACT_ORIGIN (block))
2986 tree ao = BLOCK_ABSTRACT_ORIGIN (block);
2988 while (TREE_CODE (ao) == BLOCK
2989 && BLOCK_ABSTRACT_ORIGIN (ao)
2990 && BLOCK_ABSTRACT_ORIGIN (ao) != ao)
2991 ao = BLOCK_ABSTRACT_ORIGIN (ao);
2993 if (TREE_CODE (ao) == FUNCTION_DECL)
2995 *pp_ti_abstract_origin (text) = block;
2996 break;
2998 block = BLOCK_SUPERCONTEXT (block);
3002 /* Print the identifier ID to PRETTY-PRINTER. */
3004 void
3005 pp_base_tree_identifier (pretty_printer *pp, tree id)
3007 if (pp_translate_identifiers (pp))
3009 const char *text = identifier_to_locale (IDENTIFIER_POINTER (id));
3010 pp_append_text (pp, text, text + strlen (text));
3012 else
3013 pp_append_text (pp, IDENTIFIER_POINTER (id),
3014 IDENTIFIER_POINTER (id) + IDENTIFIER_LENGTH (id));