1 /* Subroutines common to both C and C++ pretty-printers.
2 Copyright (C) 2002 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 PARAMS ((c_pretty_printer, int));
32 static void pp_c_character_literal PARAMS ((c_pretty_printer, tree));
33 static void pp_c_bool_literal PARAMS ((c_pretty_printer, tree));
34 static bool pp_c_enumerator PARAMS ((c_pretty_printer, tree));
35 static void pp_c_integer_literal PARAMS ((c_pretty_printer, tree));
36 static void pp_c_real_literal PARAMS ((c_pretty_printer, tree));
37 static void pp_c_string_literal PARAMS ((c_pretty_printer, tree));
39 static void pp_c_primary_expression PARAMS ((c_pretty_printer, tree));
41 /* postfix-expression */
42 static void pp_c_initializer_list PARAMS ((c_pretty_printer, tree));
44 static void pp_c_unary_expression PARAMS ((c_pretty_printer, tree));
45 static void pp_c_multiplicative_expression PARAMS ((c_pretty_printer, tree));
46 static void pp_c_additive_expression PARAMS ((c_pretty_printer, tree));
47 static void pp_c_shift_expression PARAMS ((c_pretty_printer, tree));
48 static void pp_c_relational_expression PARAMS ((c_pretty_printer, tree));
49 static void pp_c_equality_expression PARAMS ((c_pretty_printer, tree));
50 static void pp_c_and_expression PARAMS ((c_pretty_printer, tree));
51 static void pp_c_exclusive_or_expression PARAMS ((c_pretty_printer,
53 static void pp_c_inclusive_or_expression PARAMS ((c_pretty_printer,
55 static void pp_c_logical_and_expression PARAMS ((c_pretty_printer, tree));
56 static void pp_c_conditional_expression PARAMS ((c_pretty_printer, tree));
57 static void pp_c_assignment_expression PARAMS ((c_pretty_printer, tree));
60 static void pp_c_declaration_specifiers PARAMS ((c_pretty_printer, tree));
61 static void pp_c_init_declarator PARAMS ((c_pretty_printer, tree));
62 static void pp_c_declarator PARAMS ((c_pretty_printer, tree));
63 static void pp_c_direct_declarator PARAMS ((c_pretty_printer, tree));
64 static void pp_c_abstract_declarator PARAMS ((c_pretty_printer, tree));
65 static void pp_c_specifier_qualifier_list PARAMS ((c_pretty_printer, tree));
66 static void pp_c_simple_type_specifier PARAMS ((c_pretty_printer, tree));
67 static void pp_c_parameter_declaration PARAMS ((c_pretty_printer, tree));
68 static void pp_c_type_id PARAMS ((c_pretty_printer, tree));
69 static void pp_c_storage_class_specifier PARAMS ((c_pretty_printer, tree));
70 static void pp_c_function_specifier PARAMS ((c_pretty_printer, tree));
75 /* Print out CV-qualifiers. Take care of possible extensions. */
77 pp_c_cv_qualifier (ppi, cv)
81 if (cv & TYPE_QUAL_CONST)
82 pp_c_identifier (ppi, "const");
83 if (cv & TYPE_QUAL_VOLATILE)
84 pp_c_identifier (ppi, "volatile");
85 if (cv & TYPE_QUAL_RESTRICT)
86 pp_c_identifier (ppi, flag_isoc99 ? "restrict" : "__restrict__");
90 pp_c_simple_type_specifier (ppi, t)
94 const enum tree_code code = TREE_CODE (t);
98 pp_c_identifier (ppi, "<type-error>");
103 pp_c_identifier (ppi, "<unkown-type>");
107 case IDENTIFIER_NODE:
108 pp_c_tree_identifier (ppi, t);
116 pp_c_tree_identifier (ppi, DECL_NAME (t));
121 pp_c_simple_type_specifier (ppi, TYPE_MAIN_VARIANT (TREE_TYPE (t)));
122 if (code == COMPLEX_TYPE)
123 pp_c_identifier (ppi, flag_isoc99 ? "_Complex" : "__complex__");
124 else if (code == VECTOR_TYPE)
125 pp_c_identifier (ppi, "__vector__");
130 pp_c_tree_identifier (ppi, DECL_NAME (t));
132 pp_c_identifier (ppi, "<typedef-error>");
138 if (code == UNION_TYPE)
139 pp_c_identifier (ppi, "union");
140 else if (code == RECORD_TYPE)
141 pp_c_identifier (ppi, "struct");
142 else if (code == ENUMERAL_TYPE)
143 pp_c_identifier (ppi, "enum");
145 pp_c_identifier (ppi, "<tag-error>");
148 pp_c_tree_identifier (ppi, TYPE_NAME (t));
150 pp_c_identifier (ppi, "<anonymous>");
154 pp_unsupported_tree (ppi, t);
159 pp_c_specifier_qualifier_list (ppi, t)
160 c_pretty_printer ppi;
163 pp_c_simple_type_specifier (ppi, TYPE_MAIN_VARIANT (TREE_TYPE (t)));
164 pp_c_cv_qualifier (ppi, TYPE_QUALS (t));
168 pp_c_abstract_declarator (ppi, t)
169 c_pretty_printer ppi;
172 pp_unsupported_tree (ppi, t);
177 pp_c_type_id (ppi, t)
178 c_pretty_printer ppi;
181 pp_c_specifier_qualifier_list (ppi, t);
182 pp_c_abstract_declarator (ppi, t);
186 pp_c_storage_class_specifier (pp, t)
190 if (TREE_CODE (t) == TYPE_DECL)
191 pp_c_identifier (pp, "typedef");
192 else if (DECL_REGISTER (t))
193 pp_c_identifier (pp, "register");
197 pp_c_function_specifier (pp, t)
201 if (TREE_CODE (t) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (t))
202 pp_c_identifier (pp, "inline");
206 pp_c_declaration_specifiers (pp, t)
210 pp_c_storage_class_specifier (pp, t);
211 pp_c_function_specifier (pp, t);
212 pp_type_specifier (pp, TYPE_MAIN_VARIANT (TREE_TYPE (t)));
213 pp_c_cv_qualifier (pp, TYPE_QUALS (TREE_TYPE (t)));
217 pp_c_direct_declarator (pp, t)
221 pp_unsupported_tree (pp, t);
225 pp_c_declarator (pp, t)
229 pp_unsupported_tree (pp, t);
233 pp_c_init_declarator (pp, t)
237 pp_declarator (pp, t);
238 if (DECL_INITIAL (t))
243 pp_c_initializer (pp, DECL_INITIAL (t));
248 pp_c_declaration (pp, t)
252 pp_declaration_specifiers (pp, t);
253 pp_c_init_declarator (pp, t);
257 pp_c_parameter_declaration (pp, t)
261 pp_unsupported_tree (pp, t);
264 /* Pretty-print ATTRIBUTES using GNU C extension syntax. */
266 pp_c_attributes (pp, attributes)
270 if (attributes == NULL_TREE)
273 pp_c_identifier (pp, "__attribute__");
274 pp_c_left_paren (pp);
275 pp_c_left_paren (pp);
276 for (; attributes != NULL_TREE; attributes = TREE_CHAIN (attributes))
278 pp_tree_identifier (pp, TREE_PURPOSE (attributes));
279 if (TREE_VALUE (attributes))
281 pp_c_left_paren (pp);
282 pp_c_expression_list (pp, TREE_VALUE (attributes));
283 pp_c_right_paren (pp);
286 if (TREE_CHAIN (attributes))
287 pp_separate_with (pp, ',');
289 pp_c_right_paren (pp);
290 pp_c_right_paren (pp);
296 /* Print out a c-char. */
299 c_pretty_printer ppi;
305 pp_identifier (ppi, "\\n");
308 pp_identifier (ppi, "\\t");
311 pp_identifier (ppi, "\\v");
314 pp_identifier (ppi, "\\b");
317 pp_identifier (ppi, "\\r");
320 pp_identifier (ppi, "\\f");
323 pp_identifier (ppi, "\\a");
326 pp_identifier (ppi, "\\\\");
329 pp_identifier (ppi, "\\'");
332 pp_identifier (ppi, "\\\"");
336 pp_character (ppi, c);
338 pp_format_scalar (ppi, "\\%03o", (unsigned) c);
343 /* Print out a STRING literal. */
345 pp_c_string_literal (ppi, s)
346 c_pretty_printer ppi;
349 const char *p = TREE_STRING_POINTER (s);
350 int n = TREE_STRING_LENGTH (s) - 1;
352 pp_doublequote (ppi);
353 for (i = 0; i < n; ++i)
354 pp_c_char (ppi, p[i]);
355 pp_doublequote (ppi);
358 /* Print out a CHARACTER literal. */
360 pp_c_character_literal (ppi, c)
361 c_pretty_printer ppi;
365 pp_c_char (ppi, tree_low_cst (c, 0));
369 /* Print out a BOOLEAN literal. */
371 pp_c_bool_literal (ppi, b)
372 c_pretty_printer ppi;
375 if (b == boolean_false_node || integer_zerop (b))
377 if (c_language == clk_cplusplus)
378 pp_c_identifier (ppi, "false");
379 else if (c_language == clk_c && flag_isoc99)
380 pp_c_identifier (ppi, "_False");
382 pp_unsupported_tree (ppi, b);
384 else if (b == boolean_true_node)
386 if (c_language == clk_cplusplus)
387 pp_c_identifier (ppi, "true");
388 else if (c_language == clk_c && flag_isoc99)
389 pp_c_identifier (ppi, "_True");
391 pp_unsupported_tree (ppi, b);
394 pp_unsupported_tree (ppi, b);
397 /* Attempt to print out an ENUMERATOR. Return true on success. Else return
398 false; that means the value was obtained by a cast, in which case
399 print out the type-id part of the cast-expression -- the casted value
400 is then printed by pp_c_integer_literal. */
402 pp_c_enumerator (ppi, e)
403 c_pretty_printer ppi;
406 tree type = TREE_TYPE (e);
409 /* Find the name of this constant. */
410 for (value = TYPE_VALUES (type);
411 value != NULL_TREE && !tree_int_cst_equal (TREE_VALUE (value), e);
412 value = TREE_CHAIN (value))
415 if (value != NULL_TREE)
416 pp_c_tree_identifier (ppi, TREE_PURPOSE (value));
419 /* Value must have been cast. */
420 pp_c_left_paren (ppi);
421 pp_type_id (ppi, type);
422 pp_c_right_paren (ppi);
429 /* Print out an INTEGER constant value. */
431 pp_c_integer_literal (ppi, i)
432 c_pretty_printer ppi;
435 tree type = TREE_TYPE (i);
437 if (type == boolean_type_node)
438 pp_c_bool_literal (ppi, i);
439 else if (type == char_type_node)
440 pp_c_character_literal (ppi, i);
441 else if (TREE_CODE (type) == ENUMERAL_TYPE
442 && pp_c_enumerator (ppi, i))
446 if (host_integerp (i, 0))
447 pp_wide_integer (ppi, TREE_INT_CST_LOW (i));
450 if (tree_int_cst_sgn (i) < 0)
452 pp_c_char (ppi, '-');
453 i = build_int_2 (-TREE_INT_CST_LOW (i),
454 ~TREE_INT_CST_HIGH (i) + !TREE_INT_CST_LOW (i));
455 sprintf (pp_buffer (ppi)->digit_buffer,
456 HOST_WIDE_INT_PRINT_DOUBLE_HEX,
457 TREE_INT_CST_HIGH (i), TREE_INT_CST_LOW (i));
458 pp_identifier (ppi, pp_buffer (ppi)->digit_buffer);
465 /* Print out a REAL value. */
467 pp_c_real_literal (ppi, r)
468 c_pretty_printer ppi;
471 real_to_decimal (pp_buffer (ppi)->digit_buffer, &TREE_REAL_CST (r),
472 sizeof (pp_buffer (ppi)->digit_buffer), 0, 1);
473 pp_identifier (ppi, pp_buffer(ppi)->digit_buffer);
478 pp_c_literal (ppi, e)
479 c_pretty_printer ppi;
482 switch (TREE_CODE (e))
485 pp_c_integer_literal (ppi, e);
489 pp_c_real_literal (ppi, e);
493 pp_c_string_literal (ppi, e);
497 pp_unsupported_tree (ppi, e);
502 /* Pretty-print a C primary-expression. */
504 pp_c_primary_expression (ppi, e)
505 c_pretty_printer ppi;
508 switch (TREE_CODE (e))
518 case IDENTIFIER_NODE:
519 pp_c_tree_identifier (ppi, e);
523 pp_c_identifier (ppi, "<erroneous-expression>");
527 pp_c_identifier (ppi, "<return-value>");
533 pp_c_literal (ppi, e);
537 pp_c_left_paren (ppi);
538 pp_c_identifier (ppi, "__builtin_memcpy");
539 pp_c_left_paren (ppi);
541 pp_c_primary_expression (ppi, TREE_OPERAND (e, 0));
542 pp_separate_with (ppi, ',');
544 pp_initializer (ppi, TREE_OPERAND (e, 1));
545 if (TREE_OPERAND (e, 2))
547 pp_separate_with (ppi, ',');
548 pp_c_expression (ppi, TREE_OPERAND (e, 2));
550 pp_c_right_paren (ppi);
553 pp_c_left_paren (ppi);
554 pp_statement (ppi, STMT_EXPR_STMT (e));
555 pp_c_right_paren (ppi);
559 /* Make sure this call won't cause any infinite loop. */
560 pp_c_left_paren (ppi);
561 pp_c_expression (ppi, e);
562 pp_c_right_paren (ppi);
567 /* Print out a C initializer -- also support C compound-literals. */
569 pp_c_initializer (ppi, e)
570 c_pretty_printer ppi;
573 if (TREE_CODE (e) == CONSTRUCTOR)
575 enum tree_code code = TREE_CODE (TREE_TYPE (e));
576 if (code == RECORD_TYPE || code == UNION_TYPE || code == ARRAY_TYPE)
579 pp_c_initializer_list (ppi, e);
580 pp_right_brace (ppi);
583 pp_unsupported_tree (ppi, TREE_OPERAND (e, 1));
586 pp_assignment_expression (ppi, e);
590 pp_c_initializer_list (ppi, e)
591 c_pretty_printer ppi;
594 tree type = TREE_TYPE (e);
595 const enum tree_code code = TREE_CODE (type);
597 if (code == RECORD_TYPE || code == UNION_TYPE || code == ARRAY_TYPE)
599 tree init = TREE_OPERAND (e, 1);
600 for (; init != NULL_TREE; init = TREE_CHAIN (init))
602 if (code == RECORD_TYPE || code == UNION_TYPE)
605 pp_c_primary_expression (ppi, TREE_PURPOSE (init));
609 pp_c_left_bracket (ppi);
610 if (TREE_PURPOSE (init))
611 pp_c_literal (ppi, TREE_PURPOSE (init));
612 pp_c_right_bracket (ppi);
614 pp_c_whitespace (ppi);
616 pp_c_whitespace (ppi);
617 pp_initializer (ppi, TREE_VALUE (init));
618 if (TREE_CHAIN (init))
619 pp_separate_with (ppi, ',');
623 pp_unsupported_tree (ppi, type);
627 pp_c_postfix_expression (ppi, e)
628 c_pretty_printer ppi;
631 enum tree_code code = TREE_CODE (e);
634 case POSTINCREMENT_EXPR:
635 case POSTDECREMENT_EXPR:
636 pp_postfix_expression (ppi, TREE_OPERAND (e, 0));
637 pp_identifier (ppi, code == POSTINCREMENT_EXPR ? "++" : "--");
641 pp_postfix_expression (ppi, TREE_OPERAND (e, 0));
646 pp_postfix_expression (ppi, TREE_OPERAND (e, 0));
647 pp_c_left_bracket (ppi);
648 pp_c_expression (ppi, TREE_OPERAND (e, 1));
649 pp_c_right_bracket (ppi);
653 pp_postfix_expression (ppi, TREE_OPERAND (e, 0));
654 pp_c_left_paren (ppi);
655 pp_c_expression_list (ppi, TREE_OPERAND (e, 1));
656 pp_c_right_paren (ppi);
661 pp_c_identifier (ppi,
662 code == ABS_EXPR ? "__builtin_abs" : "__builtin_ffs");
663 pp_c_left_paren (ppi);
664 pp_c_expression (ppi, TREE_OPERAND (e, 0));
665 pp_c_right_paren (ppi);
670 tree object = TREE_OPERAND (e, 0);
671 if (TREE_CODE (object) == INDIRECT_REF)
673 pp_postfix_expression (ppi, TREE_OPERAND (object, 0));
678 pp_postfix_expression (ppi, object);
681 pp_c_expression (ppi, TREE_OPERAND (e, 1));
688 pp_c_left_paren (ppi);
689 pp_type_id (ppi, TREE_TYPE (e));
690 pp_c_right_paren (ppi);
693 if (code == COMPLEX_CST)
695 pp_c_expression (ppi, TREE_REALPART (e));
696 pp_separate_with (ppi, ',');
697 pp_c_expression (ppi, TREE_IMAGPART (e));
699 else if (code == VECTOR_CST)
700 pp_c_expression_list (ppi, TREE_VECTOR_CST_ELTS (e));
701 else if (code == COMPLEX_EXPR)
703 pp_c_expression (ppi, TREE_OPERAND (e, 0));
704 pp_separate_with (ppi, ',');
705 pp_c_expression (ppi, TREE_OPERAND (e, 1));
708 pp_right_brace (ppi);
711 case COMPOUND_LITERAL_EXPR:
712 e = DECL_INITIAL (e);
715 pp_initializer (ppi, e);
719 pp_c_identifier (ppi, "__builtin_va_arg");
720 pp_c_left_paren (ppi);
721 pp_assignment_expression (ppi, TREE_OPERAND (e, 0));
722 pp_separate_with (ppi, ',');
723 pp_type_id (ppi, TREE_TYPE (e));
724 pp_c_right_paren (ppi);
728 pp_primary_expression (ppi, e);
733 /* Print out an expression-list; E is expected to be a TREE_LIST */
735 pp_c_expression_list (ppi, e)
736 c_pretty_printer ppi;
739 for (; e != NULL_TREE; e = TREE_CHAIN (e))
741 pp_c_assignment_expression (ppi, TREE_VALUE (e));
743 pp_separate_with (ppi, ',');
748 pp_c_unary_expression (ppi, e)
749 c_pretty_printer ppi;
752 enum tree_code code = TREE_CODE (e);
755 case PREINCREMENT_EXPR:
756 case PREDECREMENT_EXPR:
757 pp_identifier (ppi, code == PREINCREMENT_EXPR ? "++" : "--");
758 pp_c_unary_expression (ppi, TREE_OPERAND (e, 0));
768 if (code == ADDR_EXPR)
770 else if (code == INDIRECT_REF)
772 else if (code == NEGATE_EXPR)
774 else if (code == BIT_NOT_EXPR || code == CONJ_EXPR)
776 else if (code == TRUTH_NOT_EXPR)
777 pp_exclamation (ppi);
778 pp_c_cast_expression (ppi, TREE_OPERAND (e, 0));
783 pp_c_identifier (ppi, code == SIZEOF_EXPR ? "sizeof" : "__alignof__");
784 pp_c_whitespace (ppi);
785 if (TYPE_P (TREE_OPERAND (e, 0)))
787 pp_c_left_paren (ppi);
788 pp_type_id (ppi, TREE_OPERAND (e, 0));
789 pp_c_right_paren (ppi);
792 pp_c_unary_expression (ppi, TREE_OPERAND (e, 0));
797 pp_c_identifier (ppi, code == REALPART_EXPR ? "__real__" : "__imag__");
798 pp_c_whitespace (ppi);
799 pp_unary_expression (ppi, TREE_OPERAND (e, 0));
803 pp_postfix_expression (ppi, e);
809 pp_c_cast_expression (ppi, e)
810 c_pretty_printer ppi;
813 if (TREE_CODE (e) == CONVERT_EXPR || TREE_CODE (e) == FLOAT_EXPR)
815 pp_c_left_paren (ppi);
816 pp_type_id (ppi, TREE_TYPE (e));
817 pp_c_right_paren (ppi);
818 pp_c_cast_expression (ppi, TREE_OPERAND (e, 0));
821 pp_unary_expression (ppi, e);
825 pp_c_multiplicative_expression (ppi, e)
826 c_pretty_printer ppi;
829 enum tree_code code = TREE_CODE (e);
835 pp_c_multiplicative_expression (ppi, TREE_OPERAND (e, 0));
836 pp_c_whitespace (ppi);
837 if (code == MULT_EXPR)
839 else if (code == TRUNC_DIV_EXPR)
843 pp_c_whitespace (ppi);
844 pp_c_cast_expression (ppi, TREE_OPERAND (e, 1));
848 pp_c_cast_expression (ppi, e);
854 pp_c_additive_expression (ppi, e)
855 c_pretty_printer ppi;
858 enum tree_code code = TREE_CODE (e);
863 pp_c_additive_expression (ppi, TREE_OPERAND (e, 0));
864 pp_c_whitespace (ppi);
865 if (code == PLUS_EXPR)
869 pp_c_whitespace (ppi);
870 pp_multiplicative_expression (ppi, TREE_OPERAND (e, 1));
874 pp_multiplicative_expression (ppi, e);
880 pp_c_shift_expression (ppi, e)
881 c_pretty_printer ppi;
884 enum tree_code code = TREE_CODE (e);
889 pp_c_shift_expression (ppi, TREE_OPERAND (e, 0));
890 pp_c_whitespace (ppi);
891 pp_identifier (ppi, code == LSHIFT_EXPR ? "<<" : ">>");
892 pp_c_whitespace (ppi);
893 pp_c_additive_expression (ppi, TREE_OPERAND (e, 1));
897 pp_c_additive_expression (ppi, e);
902 pp_c_relational_expression (ppi, e)
903 c_pretty_printer ppi;
906 enum tree_code code = TREE_CODE (e);
913 pp_c_relational_expression (ppi, TREE_OPERAND (e, 0));
914 pp_c_whitespace (ppi);
917 else if (code == GT_EXPR)
919 else if (code == LE_EXPR)
920 pp_identifier (ppi, "<=");
921 else if (code == GE_EXPR)
922 pp_identifier (ppi, ">=");
923 pp_c_whitespace (ppi);
924 pp_c_shift_expression (ppi, TREE_OPERAND (e, 1));
928 pp_c_shift_expression (ppi, e);
934 pp_c_equality_expression (ppi, e)
935 c_pretty_printer ppi;
938 enum tree_code code = TREE_CODE (e);
943 pp_c_equality_expression (ppi, TREE_OPERAND (e, 0));
944 pp_c_maybe_whitespace (ppi);
945 pp_identifier (ppi, code == EQ_EXPR ? "==" : "!=");
946 pp_c_whitespace (ppi);
947 pp_c_relational_expression (ppi, TREE_OPERAND (e, 1));
951 pp_c_relational_expression (ppi, e);
957 pp_c_and_expression (ppi, e)
958 c_pretty_printer ppi;
961 if (TREE_CODE (e) == BIT_AND_EXPR)
963 pp_c_and_expression (ppi, TREE_OPERAND (e, 0));
964 pp_c_maybe_whitespace (ppi);
966 pp_c_whitespace (ppi);
967 pp_c_equality_expression (ppi, TREE_OPERAND (e, 1));
970 pp_c_equality_expression (ppi, e);
974 pp_c_exclusive_or_expression (ppi, e)
975 c_pretty_printer ppi;
978 if (TREE_CODE (e) == BIT_XOR_EXPR)
980 pp_c_exclusive_or_expression (ppi, TREE_OPERAND (e, 0));
981 pp_c_maybe_whitespace (ppi);
983 pp_c_whitespace (ppi);
984 pp_c_and_expression (ppi, TREE_OPERAND (e, 1));
987 pp_c_and_expression (ppi, e);
991 pp_c_inclusive_or_expression (ppi, e)
992 c_pretty_printer ppi;
995 if (TREE_CODE (e) == BIT_IOR_EXPR)
997 pp_c_exclusive_or_expression (ppi, TREE_OPERAND (e, 0));
998 pp_c_maybe_whitespace (ppi);
1000 pp_c_whitespace (ppi);
1001 pp_c_exclusive_or_expression (ppi, TREE_OPERAND (e, 1));
1004 pp_c_exclusive_or_expression (ppi, e);
1008 pp_c_logical_and_expression (ppi, e)
1009 c_pretty_printer ppi;
1012 if (TREE_CODE (e) == TRUTH_ANDIF_EXPR)
1014 pp_c_logical_and_expression (ppi, TREE_OPERAND (e, 0));
1015 pp_c_maybe_whitespace (ppi);
1016 pp_identifier (ppi, "&&");
1017 pp_c_whitespace (ppi);
1018 pp_c_inclusive_or_expression (ppi, TREE_OPERAND (e, 1));
1021 pp_c_inclusive_or_expression (ppi, e);
1025 pp_c_logical_or_expression (ppi, e)
1026 c_pretty_printer ppi;
1029 if (TREE_CODE (e) == TRUTH_ORIF_EXPR)
1031 pp_c_logical_or_expression (ppi, TREE_OPERAND (e, 0));
1032 pp_c_maybe_whitespace (ppi);
1033 pp_identifier (ppi, "||");
1034 pp_c_whitespace (ppi);
1035 pp_c_logical_and_expression (ppi, TREE_OPERAND (e, 1));
1038 pp_c_logical_and_expression (ppi, e);
1042 pp_c_conditional_expression (ppi, e)
1043 c_pretty_printer ppi;
1046 if (TREE_CODE (e) == COND_EXPR)
1048 pp_c_logical_or_expression (ppi, TREE_OPERAND (e, 0));
1049 pp_c_maybe_whitespace (ppi);
1051 pp_c_whitespace (ppi);
1052 pp_c_expression (ppi, TREE_OPERAND (e, 1));
1053 pp_c_maybe_whitespace (ppi);
1055 pp_c_whitespace (ppi);
1056 pp_c_conditional_expression (ppi, TREE_OPERAND (e, 2));
1059 pp_c_logical_or_expression (ppi, e);
1063 /* Pretty-print a C assignment-expression. */
1065 pp_c_assignment_expression (ppi, e)
1066 c_pretty_printer ppi;
1069 if (TREE_CODE (e) == MODIFY_EXPR || TREE_CODE (e) == INIT_EXPR)
1071 pp_c_unary_expression (ppi, TREE_OPERAND (e, 0));
1072 pp_c_maybe_whitespace (ppi);
1074 pp_whitespace (ppi);
1075 pp_c_assignment_expression (ppi, TREE_OPERAND (e, 1));
1078 pp_c_conditional_expression (ppi, e);
1081 /* Pretty-print an expression. */
1083 pp_c_expression (ppi, e)
1084 c_pretty_printer ppi;
1087 switch (TREE_CODE (e))
1090 pp_c_integer_literal (ppi, e);
1094 pp_c_real_literal (ppi, e);
1098 pp_c_string_literal (ppi, e);
1111 pp_c_primary_expression (ppi, e);
1114 case POSTINCREMENT_EXPR:
1115 case POSTDECREMENT_EXPR:
1125 case COMPOUND_LITERAL_EXPR:
1128 pp_c_postfix_expression (ppi, e);
1136 case TRUTH_NOT_EXPR:
1137 case PREINCREMENT_EXPR:
1138 case PREDECREMENT_EXPR:
1143 pp_c_unary_expression (ppi, e);
1148 pp_c_cast_expression (ppi, e);
1152 case TRUNC_MOD_EXPR:
1153 case TRUNC_DIV_EXPR:
1154 pp_c_multiplicative_expression (ppi, e);
1159 pp_c_shift_expression (ppi, e);
1166 pp_c_relational_expression (ppi, e);
1170 pp_c_and_expression (ppi, e);
1174 pp_c_exclusive_or_expression (ppi, e);
1178 pp_c_inclusive_or_expression (ppi, e);
1181 case TRUTH_ANDIF_EXPR:
1182 pp_c_logical_and_expression (ppi, e);
1185 case TRUTH_ORIF_EXPR:
1186 pp_c_logical_or_expression (ppi, e);
1190 pp_c_conditional_expression (ppi, e);
1195 pp_c_assignment_expression (ppi, e);
1199 pp_c_expression (ppi, TREE_OPERAND (e, 0));
1203 pp_c_left_paren (ppi);
1204 pp_c_expression (ppi, TREE_OPERAND (e, 0));
1205 pp_separate_with (ppi, ',');
1206 pp_assignment_expression (ppi, TREE_OPERAND (e, 1));
1207 pp_c_right_paren (ppi);
1212 pp_unsupported_tree (ppi, e);
1220 pp_c_statement (ppi, stmt)
1221 c_pretty_printer ppi;
1224 const enum tree_code code = TREE_CODE (stmt);
1230 if (code == LABEL_STMT)
1231 pp_tree_identifier (ppi, DECL_NAME (LABEL_STMT_LABEL (stmt)));
1232 else if (code == LABEL_STMT)
1234 if (CASE_LOW (stmt) == NULL_TREE)
1235 pp_identifier (ppi, "default");
1238 pp_c_identifier (ppi, "case");
1239 pp_c_whitespace (ppi);
1240 pp_conditional_expression (ppi, CASE_LOW (stmt));
1241 if (CASE_HIGH (stmt))
1243 pp_identifier (ppi, "...");
1244 pp_conditional_expression (ppi, CASE_HIGH (stmt));
1249 pp_newline_and_indent (ppi, 3);
1253 pp_left_brace (ppi);
1254 pp_newline_and_indent (ppi, 3);
1255 for (stmt = COMPOUND_BODY (stmt); stmt; stmt = TREE_CHAIN (stmt))
1256 pp_c_statement (ppi, stmt);
1257 pp_newline_and_indent (ppi, -3);
1258 pp_right_brace (ppi);
1265 pp_c_expression (ppi, code == EXPR_STMT
1266 ? EXPR_STMT_EXPR (stmt)
1267 : CLEANUP_EXPR (stmt));
1273 pp_c_identifier (ppi, "if");
1274 pp_whitespace (ppi);
1275 pp_c_left_paren (ppi);
1276 pp_c_expression (ppi, IF_COND (stmt));
1277 pp_right_paren (ppi);
1278 pp_newline_and_indent (ppi, 3);
1279 pp_statement (ppi, THEN_CLAUSE (stmt));
1280 pp_newline_and_indent (ppi, -3);
1281 if (ELSE_CLAUSE (stmt))
1283 tree else_clause = ELSE_CLAUSE (stmt);
1284 pp_c_identifier (ppi, "else");
1285 if (TREE_CODE (else_clause) == IF_STMT)
1286 pp_c_whitespace (ppi);
1288 pp_newline_and_indent (ppi, 3);
1289 pp_statement (ppi, else_clause);
1290 if (TREE_CODE (else_clause) != IF_STMT)
1291 pp_newline_and_indent (ppi, -3);
1297 pp_c_identifier (ppi, "switch");
1298 pp_whitespace (ppi);
1299 pp_c_left_paren (ppi);
1300 pp_c_expression (ppi, SWITCH_COND (stmt));
1301 pp_right_paren (ppi);
1302 pp_newline_and_indent (ppi, 3);
1303 pp_statement (ppi, SWITCH_BODY (stmt));
1304 pp_newline_and_indent (ppi, -3);
1308 pp_c_identifier (ppi, "while");
1309 pp_whitespace (ppi);
1310 pp_c_left_paren (ppi);
1311 pp_c_expression (ppi, WHILE_COND (stmt));
1312 pp_right_paren (ppi);
1313 pp_newline_and_indent (ppi, 3);
1314 pp_statement (ppi, WHILE_BODY (stmt));
1315 pp_newline_and_indent (ppi, -3);
1319 pp_c_identifier (ppi, "do");
1320 pp_newline_and_indent (ppi, 3);
1321 pp_statement (ppi, DO_BODY (stmt));
1322 pp_newline_and_indent (ppi, -3);
1323 pp_c_identifier (ppi, "while");
1324 pp_whitespace (ppi);
1325 pp_c_left_paren (ppi);
1326 pp_c_expression (ppi, DO_COND (stmt));
1327 pp_c_right_paren (ppi);
1333 pp_c_identifier (ppi, "for");
1334 pp_whitespace (ppi);
1335 pp_c_left_paren (ppi);
1336 pp_statement (ppi, FOR_INIT_STMT (stmt));
1337 pp_c_whitespace (ppi);
1338 if (FOR_COND (stmt))
1339 pp_c_expression (ppi, FOR_COND (stmt));
1341 pp_c_whitespace (ppi);
1342 if (FOR_EXPR (stmt))
1343 pp_c_expression (ppi, FOR_EXPR (stmt));
1344 pp_right_paren (ppi);
1345 pp_newline_and_indent (ppi, 3);
1346 pp_statement (ppi, FOR_BODY (stmt));
1347 pp_newline_and_indent (ppi, -3);
1353 pp_identifier (ppi, code == BREAK_STMT ? "break" : "continue");
1361 tree e = code == RETURN_STMT
1362 ? RETURN_STMT_EXPR (stmt)
1363 : GOTO_DESTINATION (stmt);
1366 pp_c_identifier (ppi, code == RETURN_STMT ? "return" : "goto");
1368 pp_c_expression (ppi, e);
1375 if (!SCOPE_NULLIFIED_P (stmt) && SCOPE_NO_CLEANUPS_P (stmt))
1377 if (SCOPE_BEGIN_P (stmt))
1379 pp_left_brace (ppi);
1380 pp_newline_and_indent (ppi, 3);
1382 else if (SCOPE_END_P (stmt))
1384 pp_right_brace (ppi);
1385 pp_newline_and_indent (ppi, -3);
1391 pp_declaration (ppi, DECL_STMT_DECL (stmt));
1398 bool has_volatile_p = ASM_VOLATILE_P (stmt);
1399 bool is_extended = has_volatile_p || ASM_INPUTS (stmt)
1400 || ASM_OUTPUTS (stmt) || ASM_CLOBBERS (stmt);
1401 pp_c_identifier (ppi, is_extended ? "__asm__" : "asm");
1403 pp_c_identifier (ppi, "__volatile__");
1404 pp_whitespace (ppi);
1405 pp_c_left_paren (ppi);
1406 pp_c_string_literal (ppi, ASM_STRING (stmt));
1409 pp_whitespace (ppi);
1410 pp_separate_with (ppi, ':');
1411 if (ASM_OUTPUTS (stmt))
1412 pp_c_expression (ppi, ASM_OUTPUTS (stmt));
1413 pp_whitespace (ppi);
1414 pp_separate_with (ppi, ':');
1415 if (ASM_INPUTS (stmt))
1416 pp_c_expression (ppi, ASM_INPUTS (stmt));
1417 pp_whitespace (ppi);
1418 pp_separate_with (ppi, ':');
1419 if (ASM_CLOBBERS (stmt))
1420 pp_c_expression (ppi, ASM_CLOBBERS (stmt));
1422 pp_right_paren (ppi);
1428 pp_c_identifier (ppi, "__FILE__");
1429 pp_whitespace (ppi);
1431 pp_c_whitespace (ppi);
1432 pp_c_identifier (ppi, FILE_STMT_FILENAME (stmt));
1438 pp_unsupported_tree (ppi, stmt);
1444 /* Initialize the PRETTY-PRINTER for handling C codes. */
1446 pp_c_pretty_printer_init (pp)
1447 c_pretty_printer pp;
1449 pp->offset_list = 0;
1451 pp->declaration = pp_c_declaration;
1452 pp->declaration_specifiers = pp_c_declaration_specifiers;
1453 pp->type_specifier = pp_c_simple_type_specifier;
1454 pp->declarator = pp_c_declarator;
1455 pp->direct_declarator = pp_c_direct_declarator;
1456 pp->parameter_declaration = pp_c_parameter_declaration;
1457 pp->type_id = pp_c_type_id;
1459 pp->statement = pp_c_statement;
1461 pp->primary_expression = pp_c_primary_expression;
1462 pp->postfix_expression = pp_c_postfix_expression;
1463 pp->unary_expression = pp_c_unary_expression;
1464 pp->initializer = pp_c_initializer;
1465 pp->multiplicative_expression = pp_c_multiplicative_expression;
1466 pp->conditional_expression = pp_c_conditional_expression;
1467 pp->assignment_expression = pp_c_assignment_expression;