1 /* Subroutines common to both C and C++ pretty-printers.
2 Copyright (C) 2002, 2003 Free Software Foundation, Inc.
3 Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 #include "coretypes.h"
27 #include "c-pretty-print.h"
31 static void pp_c_char (c_pretty_printer, int);
32 static void pp_c_character_literal (c_pretty_printer, tree);
33 static void pp_c_bool_literal (c_pretty_printer, tree);
34 static bool pp_c_enumerator (c_pretty_printer, tree);
35 static void pp_c_integer_literal (c_pretty_printer, tree);
36 static void pp_c_real_literal (c_pretty_printer, tree);
37 static void pp_c_string_literal (c_pretty_printer, tree);
39 static void pp_c_primary_expression (c_pretty_printer, tree);
41 /* postfix-expression */
42 static void pp_c_initializer_list (c_pretty_printer, tree);
44 static void pp_c_unary_expression (c_pretty_printer, tree);
45 static void pp_c_multiplicative_expression (c_pretty_printer, tree);
46 static void pp_c_additive_expression (c_pretty_printer, tree);
47 static void pp_c_shift_expression (c_pretty_printer, tree);
48 static void pp_c_relational_expression (c_pretty_printer, tree);
49 static void pp_c_equality_expression (c_pretty_printer, tree);
50 static void pp_c_and_expression (c_pretty_printer, tree);
51 static void pp_c_exclusive_or_expression (c_pretty_printer, tree);
52 static void pp_c_inclusive_or_expression (c_pretty_printer, tree);
53 static void pp_c_logical_and_expression (c_pretty_printer, tree);
54 static void pp_c_conditional_expression (c_pretty_printer, tree);
55 static void pp_c_assignment_expression (c_pretty_printer, tree);
58 static void pp_c_declaration_specifiers (c_pretty_printer, tree);
59 static void pp_c_init_declarator (c_pretty_printer, tree);
60 static void pp_c_declarator (c_pretty_printer, tree);
61 static void pp_c_direct_declarator (c_pretty_printer, tree);
62 static void pp_c_abstract_declarator (c_pretty_printer, tree);
63 static void pp_c_specifier_qualifier_list (c_pretty_printer, tree);
64 static void pp_c_simple_type_specifier (c_pretty_printer, tree);
65 static void pp_c_parameter_declaration (c_pretty_printer, tree);
66 static void pp_c_type_id (c_pretty_printer, tree);
67 static void pp_c_storage_class_specifier (c_pretty_printer, tree);
68 static void pp_c_function_specifier (c_pretty_printer, tree);
73 /* Print out CV-qualifiers. Take care of possible extensions. */
75 pp_c_cv_qualifier (c_pretty_printer ppi, int cv)
77 if (cv & TYPE_QUAL_CONST)
78 pp_c_identifier (ppi, "const");
79 if (cv & TYPE_QUAL_VOLATILE)
80 pp_c_identifier (ppi, "volatile");
81 if (cv & TYPE_QUAL_RESTRICT)
82 pp_c_identifier (ppi, flag_isoc99 ? "restrict" : "__restrict__");
86 pp_c_simple_type_specifier (c_pretty_printer ppi, tree t)
88 const enum tree_code code = TREE_CODE (t);
92 pp_c_identifier (ppi, "<type-error>");
97 pp_c_identifier (ppi, "<unkown-type>");
101 case IDENTIFIER_NODE:
102 pp_c_tree_identifier (ppi, t);
110 pp_c_tree_identifier (ppi, DECL_NAME (t));
115 pp_c_simple_type_specifier (ppi, TYPE_MAIN_VARIANT (TREE_TYPE (t)));
116 if (code == COMPLEX_TYPE)
117 pp_c_identifier (ppi, flag_isoc99 ? "_Complex" : "__complex__");
118 else if (code == VECTOR_TYPE)
119 pp_c_identifier (ppi, "__vector__");
124 pp_c_tree_identifier (ppi, DECL_NAME (t));
126 pp_c_identifier (ppi, "<typedef-error>");
132 if (code == UNION_TYPE)
133 pp_c_identifier (ppi, "union");
134 else if (code == RECORD_TYPE)
135 pp_c_identifier (ppi, "struct");
136 else if (code == ENUMERAL_TYPE)
137 pp_c_identifier (ppi, "enum");
139 pp_c_identifier (ppi, "<tag-error>");
142 pp_c_tree_identifier (ppi, TYPE_NAME (t));
144 pp_c_identifier (ppi, "<anonymous>");
148 pp_unsupported_tree (ppi, t);
153 pp_c_specifier_qualifier_list (c_pretty_printer ppi, tree t)
155 pp_c_simple_type_specifier (ppi, TYPE_MAIN_VARIANT (TREE_TYPE (t)));
156 pp_c_cv_qualifier (ppi, TYPE_QUALS (t));
160 pp_c_abstract_declarator (c_pretty_printer ppi, tree t)
162 pp_unsupported_tree (ppi, t);
167 pp_c_type_id (c_pretty_printer ppi, tree t)
169 pp_c_specifier_qualifier_list (ppi, t);
170 pp_c_abstract_declarator (ppi, t);
174 pp_c_storage_class_specifier (c_pretty_printer pp, tree t)
176 if (TREE_CODE (t) == TYPE_DECL)
177 pp_c_identifier (pp, "typedef");
178 else if (DECL_REGISTER (t))
179 pp_c_identifier (pp, "register");
183 pp_c_function_specifier (c_pretty_printer pp, tree t)
185 if (TREE_CODE (t) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (t))
186 pp_c_identifier (pp, "inline");
190 pp_c_declaration_specifiers (c_pretty_printer pp, tree t)
192 pp_c_storage_class_specifier (pp, t);
193 pp_c_function_specifier (pp, t);
194 pp_type_specifier (pp, TYPE_MAIN_VARIANT (TREE_TYPE (t)));
195 pp_c_cv_qualifier (pp, TYPE_QUALS (TREE_TYPE (t)));
199 pp_c_direct_declarator (c_pretty_printer pp, tree t)
201 pp_unsupported_tree (pp, t);
205 pp_c_declarator (c_pretty_printer pp, tree t)
207 pp_unsupported_tree (pp, t);
211 pp_c_init_declarator (c_pretty_printer pp, tree t)
213 pp_declarator (pp, t);
214 if (DECL_INITIAL (t))
219 pp_c_initializer (pp, DECL_INITIAL (t));
224 pp_c_declaration (c_pretty_printer pp, tree t)
226 pp_declaration_specifiers (pp, t);
227 pp_c_init_declarator (pp, t);
231 pp_c_parameter_declaration (c_pretty_printer pp, tree t)
233 pp_unsupported_tree (pp, t);
236 /* Pretty-print ATTRIBUTES using GNU C extension syntax. */
238 pp_c_attributes (c_pretty_printer pp, tree attributes)
240 if (attributes == NULL_TREE)
243 pp_c_identifier (pp, "__attribute__");
244 pp_c_left_paren (pp);
245 pp_c_left_paren (pp);
246 for (; attributes != NULL_TREE; attributes = TREE_CHAIN (attributes))
248 pp_tree_identifier (pp, TREE_PURPOSE (attributes));
249 if (TREE_VALUE (attributes))
251 pp_c_left_paren (pp);
252 pp_c_expression_list (pp, TREE_VALUE (attributes));
253 pp_c_right_paren (pp);
256 if (TREE_CHAIN (attributes))
257 pp_separate_with (pp, ',');
259 pp_c_right_paren (pp);
260 pp_c_right_paren (pp);
266 /* Print out a c-char. */
268 pp_c_char (c_pretty_printer ppi, int c)
273 pp_identifier (ppi, "\\n");
276 pp_identifier (ppi, "\\t");
279 pp_identifier (ppi, "\\v");
282 pp_identifier (ppi, "\\b");
285 pp_identifier (ppi, "\\r");
288 pp_identifier (ppi, "\\f");
291 pp_identifier (ppi, "\\a");
294 pp_identifier (ppi, "\\\\");
297 pp_identifier (ppi, "\\'");
300 pp_identifier (ppi, "\\\"");
304 pp_character (ppi, c);
306 pp_format_scalar (ppi, "\\%03o", (unsigned) c);
311 /* Print out a STRING literal. */
313 pp_c_string_literal (c_pretty_printer ppi, tree s)
315 const char *p = TREE_STRING_POINTER (s);
316 int n = TREE_STRING_LENGTH (s) - 1;
318 pp_doublequote (ppi);
319 for (i = 0; i < n; ++i)
320 pp_c_char (ppi, p[i]);
321 pp_doublequote (ppi);
324 /* Print out a CHARACTER literal. */
326 pp_c_character_literal (c_pretty_printer ppi, tree c)
329 pp_c_char (ppi, tree_low_cst (c, 0));
333 /* Print out a BOOLEAN literal. */
335 pp_c_bool_literal (c_pretty_printer ppi, tree b)
337 if (b == boolean_false_node || integer_zerop (b))
339 if (c_language == clk_cplusplus)
340 pp_c_identifier (ppi, "false");
341 else if (c_language == clk_c && flag_isoc99)
342 pp_c_identifier (ppi, "_False");
344 pp_unsupported_tree (ppi, b);
346 else if (b == boolean_true_node)
348 if (c_language == clk_cplusplus)
349 pp_c_identifier (ppi, "true");
350 else if (c_language == clk_c && flag_isoc99)
351 pp_c_identifier (ppi, "_True");
353 pp_unsupported_tree (ppi, b);
356 pp_unsupported_tree (ppi, b);
359 /* Attempt to print out an ENUMERATOR. Return true on success. Else return
360 false; that means the value was obtained by a cast, in which case
361 print out the type-id part of the cast-expression -- the casted value
362 is then printed by pp_c_integer_literal. */
364 pp_c_enumerator (c_pretty_printer ppi, tree e)
366 tree type = TREE_TYPE (e);
369 /* Find the name of this constant. */
370 for (value = TYPE_VALUES (type);
371 value != NULL_TREE && !tree_int_cst_equal (TREE_VALUE (value), e);
372 value = TREE_CHAIN (value))
375 if (value != NULL_TREE)
376 pp_c_tree_identifier (ppi, TREE_PURPOSE (value));
379 /* Value must have been cast. */
380 pp_c_left_paren (ppi);
381 pp_type_id (ppi, type);
382 pp_c_right_paren (ppi);
389 /* Print out an INTEGER constant value. */
391 pp_c_integer_literal (c_pretty_printer ppi, tree i)
393 tree type = TREE_TYPE (i);
395 if (type == boolean_type_node)
396 pp_c_bool_literal (ppi, i);
397 else if (type == char_type_node)
398 pp_c_character_literal (ppi, i);
399 else if (TREE_CODE (type) == ENUMERAL_TYPE
400 && pp_c_enumerator (ppi, i))
404 if (host_integerp (i, 0))
405 pp_wide_integer (ppi, TREE_INT_CST_LOW (i));
408 if (tree_int_cst_sgn (i) < 0)
410 pp_c_char (ppi, '-');
411 i = build_int_2 (-TREE_INT_CST_LOW (i),
412 ~TREE_INT_CST_HIGH (i) + !TREE_INT_CST_LOW (i));
413 sprintf (pp_buffer (ppi)->digit_buffer,
414 HOST_WIDE_INT_PRINT_DOUBLE_HEX,
415 TREE_INT_CST_HIGH (i), TREE_INT_CST_LOW (i));
416 pp_identifier (ppi, pp_buffer (ppi)->digit_buffer);
423 /* Print out a REAL value. */
425 pp_c_real_literal (c_pretty_printer ppi, tree r)
427 real_to_decimal (pp_buffer (ppi)->digit_buffer, &TREE_REAL_CST (r),
428 sizeof (pp_buffer (ppi)->digit_buffer), 0, 1);
429 pp_identifier (ppi, pp_buffer(ppi)->digit_buffer);
434 pp_c_literal (c_pretty_printer ppi, tree e)
436 switch (TREE_CODE (e))
439 pp_c_integer_literal (ppi, e);
443 pp_c_real_literal (ppi, e);
447 pp_c_string_literal (ppi, e);
451 pp_unsupported_tree (ppi, e);
456 /* Pretty-print a C primary-expression. */
458 pp_c_primary_expression (c_pretty_printer ppi, tree e)
460 switch (TREE_CODE (e))
470 case IDENTIFIER_NODE:
471 pp_c_tree_identifier (ppi, e);
475 pp_c_identifier (ppi, "<erroneous-expression>");
479 pp_c_identifier (ppi, "<return-value>");
485 pp_c_literal (ppi, e);
489 pp_c_left_paren (ppi);
490 pp_c_identifier (ppi, "__builtin_memcpy");
491 pp_c_left_paren (ppi);
493 pp_c_primary_expression (ppi, TREE_OPERAND (e, 0));
494 pp_separate_with (ppi, ',');
496 pp_initializer (ppi, TREE_OPERAND (e, 1));
497 if (TREE_OPERAND (e, 2))
499 pp_separate_with (ppi, ',');
500 pp_c_expression (ppi, TREE_OPERAND (e, 2));
502 pp_c_right_paren (ppi);
505 pp_c_left_paren (ppi);
506 pp_statement (ppi, STMT_EXPR_STMT (e));
507 pp_c_right_paren (ppi);
511 /* Make sure this call won't cause any infinite loop. */
512 pp_c_left_paren (ppi);
513 pp_c_expression (ppi, e);
514 pp_c_right_paren (ppi);
519 /* Print out a C initializer -- also support C compound-literals. */
521 pp_c_initializer (c_pretty_printer ppi, tree e)
523 if (TREE_CODE (e) == CONSTRUCTOR)
525 enum tree_code code = TREE_CODE (TREE_TYPE (e));
526 if (code == RECORD_TYPE || code == UNION_TYPE || code == ARRAY_TYPE)
529 pp_c_initializer_list (ppi, e);
530 pp_right_brace (ppi);
533 pp_unsupported_tree (ppi, TREE_OPERAND (e, 1));
536 pp_assignment_expression (ppi, e);
540 pp_c_initializer_list (c_pretty_printer ppi, tree e)
542 tree type = TREE_TYPE (e);
543 const enum tree_code code = TREE_CODE (type);
545 if (code == RECORD_TYPE || code == UNION_TYPE || code == ARRAY_TYPE)
547 tree init = TREE_OPERAND (e, 1);
548 for (; init != NULL_TREE; init = TREE_CHAIN (init))
550 if (code == RECORD_TYPE || code == UNION_TYPE)
553 pp_c_primary_expression (ppi, TREE_PURPOSE (init));
557 pp_c_left_bracket (ppi);
558 if (TREE_PURPOSE (init))
559 pp_c_literal (ppi, TREE_PURPOSE (init));
560 pp_c_right_bracket (ppi);
562 pp_c_whitespace (ppi);
564 pp_c_whitespace (ppi);
565 pp_initializer (ppi, TREE_VALUE (init));
566 if (TREE_CHAIN (init))
567 pp_separate_with (ppi, ',');
571 pp_unsupported_tree (ppi, type);
575 pp_c_postfix_expression (c_pretty_printer ppi, tree e)
577 enum tree_code code = TREE_CODE (e);
580 case POSTINCREMENT_EXPR:
581 case POSTDECREMENT_EXPR:
582 pp_postfix_expression (ppi, TREE_OPERAND (e, 0));
583 pp_identifier (ppi, code == POSTINCREMENT_EXPR ? "++" : "--");
587 pp_postfix_expression (ppi, TREE_OPERAND (e, 0));
592 pp_postfix_expression (ppi, TREE_OPERAND (e, 0));
593 pp_c_left_bracket (ppi);
594 pp_c_expression (ppi, TREE_OPERAND (e, 1));
595 pp_c_right_bracket (ppi);
599 pp_postfix_expression (ppi, TREE_OPERAND (e, 0));
600 pp_c_left_paren (ppi);
601 pp_c_expression_list (ppi, TREE_OPERAND (e, 1));
602 pp_c_right_paren (ppi);
607 pp_c_identifier (ppi,
608 code == ABS_EXPR ? "__builtin_abs" : "__builtin_ffs");
609 pp_c_left_paren (ppi);
610 pp_c_expression (ppi, TREE_OPERAND (e, 0));
611 pp_c_right_paren (ppi);
616 tree object = TREE_OPERAND (e, 0);
617 if (TREE_CODE (object) == INDIRECT_REF)
619 pp_postfix_expression (ppi, TREE_OPERAND (object, 0));
624 pp_postfix_expression (ppi, object);
627 pp_c_expression (ppi, TREE_OPERAND (e, 1));
634 pp_c_left_paren (ppi);
635 pp_type_id (ppi, TREE_TYPE (e));
636 pp_c_right_paren (ppi);
639 if (code == COMPLEX_CST)
641 pp_c_expression (ppi, TREE_REALPART (e));
642 pp_separate_with (ppi, ',');
643 pp_c_expression (ppi, TREE_IMAGPART (e));
645 else if (code == VECTOR_CST)
646 pp_c_expression_list (ppi, TREE_VECTOR_CST_ELTS (e));
647 else if (code == COMPLEX_EXPR)
649 pp_c_expression (ppi, TREE_OPERAND (e, 0));
650 pp_separate_with (ppi, ',');
651 pp_c_expression (ppi, TREE_OPERAND (e, 1));
654 pp_right_brace (ppi);
657 case COMPOUND_LITERAL_EXPR:
658 e = DECL_INITIAL (e);
661 pp_initializer (ppi, e);
665 pp_c_identifier (ppi, "__builtin_va_arg");
666 pp_c_left_paren (ppi);
667 pp_assignment_expression (ppi, TREE_OPERAND (e, 0));
668 pp_separate_with (ppi, ',');
669 pp_type_id (ppi, TREE_TYPE (e));
670 pp_c_right_paren (ppi);
674 pp_primary_expression (ppi, e);
679 /* Print out an expression-list; E is expected to be a TREE_LIST */
681 pp_c_expression_list (c_pretty_printer ppi, tree e)
683 for (; e != NULL_TREE; e = TREE_CHAIN (e))
685 pp_c_assignment_expression (ppi, TREE_VALUE (e));
687 pp_separate_with (ppi, ',');
692 pp_c_unary_expression (c_pretty_printer ppi, tree e)
694 enum tree_code code = TREE_CODE (e);
697 case PREINCREMENT_EXPR:
698 case PREDECREMENT_EXPR:
699 pp_identifier (ppi, code == PREINCREMENT_EXPR ? "++" : "--");
700 pp_c_unary_expression (ppi, TREE_OPERAND (e, 0));
710 if (code == ADDR_EXPR)
712 else if (code == INDIRECT_REF)
714 else if (code == NEGATE_EXPR)
716 else if (code == BIT_NOT_EXPR || code == CONJ_EXPR)
718 else if (code == TRUTH_NOT_EXPR)
719 pp_exclamation (ppi);
720 pp_c_cast_expression (ppi, TREE_OPERAND (e, 0));
725 pp_c_identifier (ppi, code == SIZEOF_EXPR ? "sizeof" : "__alignof__");
726 pp_c_whitespace (ppi);
727 if (TYPE_P (TREE_OPERAND (e, 0)))
729 pp_c_left_paren (ppi);
730 pp_type_id (ppi, TREE_OPERAND (e, 0));
731 pp_c_right_paren (ppi);
734 pp_c_unary_expression (ppi, TREE_OPERAND (e, 0));
739 pp_c_identifier (ppi, code == REALPART_EXPR ? "__real__" : "__imag__");
740 pp_c_whitespace (ppi);
741 pp_unary_expression (ppi, TREE_OPERAND (e, 0));
745 pp_postfix_expression (ppi, e);
751 pp_c_cast_expression (c_pretty_printer ppi, tree e)
753 if (TREE_CODE (e) == CONVERT_EXPR || TREE_CODE (e) == FLOAT_EXPR)
755 pp_c_left_paren (ppi);
756 pp_type_id (ppi, TREE_TYPE (e));
757 pp_c_right_paren (ppi);
758 pp_c_cast_expression (ppi, TREE_OPERAND (e, 0));
761 pp_unary_expression (ppi, e);
765 pp_c_multiplicative_expression (c_pretty_printer ppi, tree e)
767 enum tree_code code = TREE_CODE (e);
773 pp_c_multiplicative_expression (ppi, TREE_OPERAND (e, 0));
774 pp_c_whitespace (ppi);
775 if (code == MULT_EXPR)
777 else if (code == TRUNC_DIV_EXPR)
781 pp_c_whitespace (ppi);
782 pp_c_cast_expression (ppi, TREE_OPERAND (e, 1));
786 pp_c_cast_expression (ppi, e);
792 pp_c_additive_expression (c_pretty_printer ppi, tree e)
794 enum tree_code code = TREE_CODE (e);
799 pp_c_additive_expression (ppi, TREE_OPERAND (e, 0));
800 pp_c_whitespace (ppi);
801 if (code == PLUS_EXPR)
805 pp_c_whitespace (ppi);
806 pp_multiplicative_expression (ppi, TREE_OPERAND (e, 1));
810 pp_multiplicative_expression (ppi, e);
816 pp_c_shift_expression (c_pretty_printer ppi, tree e)
818 enum tree_code code = TREE_CODE (e);
823 pp_c_shift_expression (ppi, TREE_OPERAND (e, 0));
824 pp_c_whitespace (ppi);
825 pp_identifier (ppi, code == LSHIFT_EXPR ? "<<" : ">>");
826 pp_c_whitespace (ppi);
827 pp_c_additive_expression (ppi, TREE_OPERAND (e, 1));
831 pp_c_additive_expression (ppi, e);
836 pp_c_relational_expression (c_pretty_printer ppi, tree e)
838 enum tree_code code = TREE_CODE (e);
845 pp_c_relational_expression (ppi, TREE_OPERAND (e, 0));
846 pp_c_whitespace (ppi);
849 else if (code == GT_EXPR)
851 else if (code == LE_EXPR)
852 pp_identifier (ppi, "<=");
853 else if (code == GE_EXPR)
854 pp_identifier (ppi, ">=");
855 pp_c_whitespace (ppi);
856 pp_c_shift_expression (ppi, TREE_OPERAND (e, 1));
860 pp_c_shift_expression (ppi, e);
866 pp_c_equality_expression (c_pretty_printer ppi, tree e)
868 enum tree_code code = TREE_CODE (e);
873 pp_c_equality_expression (ppi, TREE_OPERAND (e, 0));
874 pp_c_maybe_whitespace (ppi);
875 pp_identifier (ppi, code == EQ_EXPR ? "==" : "!=");
876 pp_c_whitespace (ppi);
877 pp_c_relational_expression (ppi, TREE_OPERAND (e, 1));
881 pp_c_relational_expression (ppi, e);
887 pp_c_and_expression (c_pretty_printer ppi, tree e)
889 if (TREE_CODE (e) == BIT_AND_EXPR)
891 pp_c_and_expression (ppi, TREE_OPERAND (e, 0));
892 pp_c_maybe_whitespace (ppi);
894 pp_c_whitespace (ppi);
895 pp_c_equality_expression (ppi, TREE_OPERAND (e, 1));
898 pp_c_equality_expression (ppi, e);
902 pp_c_exclusive_or_expression (c_pretty_printer ppi, tree e)
904 if (TREE_CODE (e) == BIT_XOR_EXPR)
906 pp_c_exclusive_or_expression (ppi, TREE_OPERAND (e, 0));
907 pp_c_maybe_whitespace (ppi);
909 pp_c_whitespace (ppi);
910 pp_c_and_expression (ppi, TREE_OPERAND (e, 1));
913 pp_c_and_expression (ppi, e);
917 pp_c_inclusive_or_expression (c_pretty_printer ppi, tree e)
919 if (TREE_CODE (e) == BIT_IOR_EXPR)
921 pp_c_exclusive_or_expression (ppi, TREE_OPERAND (e, 0));
922 pp_c_maybe_whitespace (ppi);
924 pp_c_whitespace (ppi);
925 pp_c_exclusive_or_expression (ppi, TREE_OPERAND (e, 1));
928 pp_c_exclusive_or_expression (ppi, e);
932 pp_c_logical_and_expression (c_pretty_printer ppi, tree e)
934 if (TREE_CODE (e) == TRUTH_ANDIF_EXPR)
936 pp_c_logical_and_expression (ppi, TREE_OPERAND (e, 0));
937 pp_c_maybe_whitespace (ppi);
938 pp_identifier (ppi, "&&");
939 pp_c_whitespace (ppi);
940 pp_c_inclusive_or_expression (ppi, TREE_OPERAND (e, 1));
943 pp_c_inclusive_or_expression (ppi, e);
947 pp_c_logical_or_expression (c_pretty_printer ppi, tree e)
949 if (TREE_CODE (e) == TRUTH_ORIF_EXPR)
951 pp_c_logical_or_expression (ppi, TREE_OPERAND (e, 0));
952 pp_c_maybe_whitespace (ppi);
953 pp_identifier (ppi, "||");
954 pp_c_whitespace (ppi);
955 pp_c_logical_and_expression (ppi, TREE_OPERAND (e, 1));
958 pp_c_logical_and_expression (ppi, e);
962 pp_c_conditional_expression (c_pretty_printer ppi, tree e)
964 if (TREE_CODE (e) == COND_EXPR)
966 pp_c_logical_or_expression (ppi, TREE_OPERAND (e, 0));
967 pp_c_maybe_whitespace (ppi);
969 pp_c_whitespace (ppi);
970 pp_c_expression (ppi, TREE_OPERAND (e, 1));
971 pp_c_maybe_whitespace (ppi);
973 pp_c_whitespace (ppi);
974 pp_c_conditional_expression (ppi, TREE_OPERAND (e, 2));
977 pp_c_logical_or_expression (ppi, e);
981 /* Pretty-print a C assignment-expression. */
983 pp_c_assignment_expression (c_pretty_printer ppi, tree e)
985 if (TREE_CODE (e) == MODIFY_EXPR || TREE_CODE (e) == INIT_EXPR)
987 pp_c_unary_expression (ppi, TREE_OPERAND (e, 0));
988 pp_c_maybe_whitespace (ppi);
991 pp_c_assignment_expression (ppi, TREE_OPERAND (e, 1));
994 pp_c_conditional_expression (ppi, e);
997 /* Pretty-print an expression. */
999 pp_c_expression (c_pretty_printer ppi, tree e)
1001 switch (TREE_CODE (e))
1004 pp_c_integer_literal (ppi, e);
1008 pp_c_real_literal (ppi, e);
1012 pp_c_string_literal (ppi, e);
1025 pp_c_primary_expression (ppi, e);
1028 case POSTINCREMENT_EXPR:
1029 case POSTDECREMENT_EXPR:
1039 case COMPOUND_LITERAL_EXPR:
1042 pp_c_postfix_expression (ppi, e);
1050 case TRUTH_NOT_EXPR:
1051 case PREINCREMENT_EXPR:
1052 case PREDECREMENT_EXPR:
1057 pp_c_unary_expression (ppi, e);
1062 pp_c_cast_expression (ppi, e);
1066 case TRUNC_MOD_EXPR:
1067 case TRUNC_DIV_EXPR:
1068 pp_c_multiplicative_expression (ppi, e);
1073 pp_c_shift_expression (ppi, e);
1080 pp_c_relational_expression (ppi, e);
1084 pp_c_and_expression (ppi, e);
1088 pp_c_exclusive_or_expression (ppi, e);
1092 pp_c_inclusive_or_expression (ppi, e);
1095 case TRUTH_ANDIF_EXPR:
1096 pp_c_logical_and_expression (ppi, e);
1099 case TRUTH_ORIF_EXPR:
1100 pp_c_logical_or_expression (ppi, e);
1104 pp_c_conditional_expression (ppi, e);
1109 pp_c_assignment_expression (ppi, e);
1113 pp_c_expression (ppi, TREE_OPERAND (e, 0));
1117 pp_c_left_paren (ppi);
1118 pp_c_expression (ppi, TREE_OPERAND (e, 0));
1119 pp_separate_with (ppi, ',');
1120 pp_assignment_expression (ppi, TREE_OPERAND (e, 1));
1121 pp_c_right_paren (ppi);
1126 pp_unsupported_tree (ppi, e);
1134 pp_c_statement (c_pretty_printer ppi, tree stmt)
1136 const enum tree_code code = TREE_CODE (stmt);
1142 if (code == LABEL_STMT)
1143 pp_tree_identifier (ppi, DECL_NAME (LABEL_STMT_LABEL (stmt)));
1144 else if (code == LABEL_STMT)
1146 if (CASE_LOW (stmt) == NULL_TREE)
1147 pp_identifier (ppi, "default");
1150 pp_c_identifier (ppi, "case");
1151 pp_c_whitespace (ppi);
1152 pp_conditional_expression (ppi, CASE_LOW (stmt));
1153 if (CASE_HIGH (stmt))
1155 pp_identifier (ppi, "...");
1156 pp_conditional_expression (ppi, CASE_HIGH (stmt));
1161 pp_newline_and_indent (ppi, 3);
1165 pp_left_brace (ppi);
1166 pp_newline_and_indent (ppi, 3);
1167 for (stmt = COMPOUND_BODY (stmt); stmt; stmt = TREE_CHAIN (stmt))
1168 pp_c_statement (ppi, stmt);
1169 pp_newline_and_indent (ppi, -3);
1170 pp_right_brace (ppi);
1177 pp_c_expression (ppi, code == EXPR_STMT
1178 ? EXPR_STMT_EXPR (stmt)
1179 : CLEANUP_EXPR (stmt));
1185 pp_c_identifier (ppi, "if");
1186 pp_whitespace (ppi);
1187 pp_c_left_paren (ppi);
1188 pp_c_expression (ppi, IF_COND (stmt));
1189 pp_right_paren (ppi);
1190 pp_newline_and_indent (ppi, 3);
1191 pp_statement (ppi, THEN_CLAUSE (stmt));
1192 pp_newline_and_indent (ppi, -3);
1193 if (ELSE_CLAUSE (stmt))
1195 tree else_clause = ELSE_CLAUSE (stmt);
1196 pp_c_identifier (ppi, "else");
1197 if (TREE_CODE (else_clause) == IF_STMT)
1198 pp_c_whitespace (ppi);
1200 pp_newline_and_indent (ppi, 3);
1201 pp_statement (ppi, else_clause);
1202 if (TREE_CODE (else_clause) != IF_STMT)
1203 pp_newline_and_indent (ppi, -3);
1209 pp_c_identifier (ppi, "switch");
1210 pp_whitespace (ppi);
1211 pp_c_left_paren (ppi);
1212 pp_c_expression (ppi, SWITCH_COND (stmt));
1213 pp_right_paren (ppi);
1214 pp_newline_and_indent (ppi, 3);
1215 pp_statement (ppi, SWITCH_BODY (stmt));
1216 pp_newline_and_indent (ppi, -3);
1220 pp_c_identifier (ppi, "while");
1221 pp_whitespace (ppi);
1222 pp_c_left_paren (ppi);
1223 pp_c_expression (ppi, WHILE_COND (stmt));
1224 pp_right_paren (ppi);
1225 pp_newline_and_indent (ppi, 3);
1226 pp_statement (ppi, WHILE_BODY (stmt));
1227 pp_newline_and_indent (ppi, -3);
1231 pp_c_identifier (ppi, "do");
1232 pp_newline_and_indent (ppi, 3);
1233 pp_statement (ppi, DO_BODY (stmt));
1234 pp_newline_and_indent (ppi, -3);
1235 pp_c_identifier (ppi, "while");
1236 pp_whitespace (ppi);
1237 pp_c_left_paren (ppi);
1238 pp_c_expression (ppi, DO_COND (stmt));
1239 pp_c_right_paren (ppi);
1245 pp_c_identifier (ppi, "for");
1246 pp_whitespace (ppi);
1247 pp_c_left_paren (ppi);
1248 pp_statement (ppi, FOR_INIT_STMT (stmt));
1249 pp_c_whitespace (ppi);
1250 if (FOR_COND (stmt))
1251 pp_c_expression (ppi, FOR_COND (stmt));
1253 pp_c_whitespace (ppi);
1254 if (FOR_EXPR (stmt))
1255 pp_c_expression (ppi, FOR_EXPR (stmt));
1256 pp_right_paren (ppi);
1257 pp_newline_and_indent (ppi, 3);
1258 pp_statement (ppi, FOR_BODY (stmt));
1259 pp_newline_and_indent (ppi, -3);
1265 pp_identifier (ppi, code == BREAK_STMT ? "break" : "continue");
1273 tree e = code == RETURN_STMT
1274 ? RETURN_STMT_EXPR (stmt)
1275 : GOTO_DESTINATION (stmt);
1278 pp_c_identifier (ppi, code == RETURN_STMT ? "return" : "goto");
1280 pp_c_expression (ppi, e);
1287 if (!SCOPE_NULLIFIED_P (stmt) && SCOPE_NO_CLEANUPS_P (stmt))
1289 if (SCOPE_BEGIN_P (stmt))
1291 pp_left_brace (ppi);
1292 pp_newline_and_indent (ppi, 3);
1294 else if (SCOPE_END_P (stmt))
1296 pp_right_brace (ppi);
1297 pp_newline_and_indent (ppi, -3);
1303 pp_declaration (ppi, DECL_STMT_DECL (stmt));
1310 bool has_volatile_p = ASM_VOLATILE_P (stmt);
1311 bool is_extended = has_volatile_p || ASM_INPUTS (stmt)
1312 || ASM_OUTPUTS (stmt) || ASM_CLOBBERS (stmt);
1313 pp_c_identifier (ppi, is_extended ? "__asm__" : "asm");
1315 pp_c_identifier (ppi, "__volatile__");
1316 pp_whitespace (ppi);
1317 pp_c_left_paren (ppi);
1318 pp_c_string_literal (ppi, ASM_STRING (stmt));
1321 pp_whitespace (ppi);
1322 pp_separate_with (ppi, ':');
1323 if (ASM_OUTPUTS (stmt))
1324 pp_c_expression (ppi, ASM_OUTPUTS (stmt));
1325 pp_whitespace (ppi);
1326 pp_separate_with (ppi, ':');
1327 if (ASM_INPUTS (stmt))
1328 pp_c_expression (ppi, ASM_INPUTS (stmt));
1329 pp_whitespace (ppi);
1330 pp_separate_with (ppi, ':');
1331 if (ASM_CLOBBERS (stmt))
1332 pp_c_expression (ppi, ASM_CLOBBERS (stmt));
1334 pp_right_paren (ppi);
1340 pp_c_identifier (ppi, "__FILE__");
1341 pp_whitespace (ppi);
1343 pp_c_whitespace (ppi);
1344 pp_c_identifier (ppi, FILE_STMT_FILENAME (stmt));
1350 pp_unsupported_tree (ppi, stmt);
1356 /* Initialize the PRETTY-PRINTER for handling C codes. */
1358 pp_c_pretty_printer_init (c_pretty_printer pp)
1360 pp->offset_list = 0;
1362 pp->declaration = pp_c_declaration;
1363 pp->declaration_specifiers = pp_c_declaration_specifiers;
1364 pp->type_specifier = pp_c_simple_type_specifier;
1365 pp->declarator = pp_c_declarator;
1366 pp->direct_declarator = pp_c_direct_declarator;
1367 pp->parameter_declaration = pp_c_parameter_declaration;
1368 pp->type_id = pp_c_type_id;
1370 pp->statement = pp_c_statement;
1372 pp->primary_expression = pp_c_primary_expression;
1373 pp->postfix_expression = pp_c_postfix_expression;
1374 pp->unary_expression = pp_c_unary_expression;
1375 pp->initializer = pp_c_initializer;
1376 pp->multiplicative_expression = pp_c_multiplicative_expression;
1377 pp->conditional_expression = pp_c_conditional_expression;
1378 pp->assignment_expression = pp_c_assignment_expression;