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"
30 /* The pretty-printer code is primarily designed to closely follow
31 (GNU) C and C++ grammars. That is to be contrasted with spaghetti
32 codes we used to have in the past. Following a structured
33 approach (preferaably the official grammars) is believed to make it
34 much easier o add extensions and nifty pretty-printing effects that
35 takes expresssion or declaration contexts into account. */
38 static void pp_c_char (c_pretty_printer, int);
39 static void pp_c_character_literal (c_pretty_printer, tree);
40 static void pp_c_bool_literal (c_pretty_printer, tree);
41 static bool pp_c_enumerator (c_pretty_printer, tree);
42 static void pp_c_integer_literal (c_pretty_printer, tree);
43 static void pp_c_real_literal (c_pretty_printer, tree);
44 static void pp_c_string_literal (c_pretty_printer, tree);
46 static void pp_c_primary_expression (c_pretty_printer, tree);
48 /* postfix-expression */
49 static void pp_c_initializer_list (c_pretty_printer, tree);
51 static void pp_c_unary_expression (c_pretty_printer, tree);
52 static void pp_c_multiplicative_expression (c_pretty_printer, tree);
53 static void pp_c_additive_expression (c_pretty_printer, tree);
54 static void pp_c_shift_expression (c_pretty_printer, tree);
55 static void pp_c_relational_expression (c_pretty_printer, tree);
56 static void pp_c_equality_expression (c_pretty_printer, tree);
57 static void pp_c_and_expression (c_pretty_printer, tree);
58 static void pp_c_exclusive_or_expression (c_pretty_printer, tree);
59 static void pp_c_inclusive_or_expression (c_pretty_printer, tree);
60 static void pp_c_logical_and_expression (c_pretty_printer, tree);
61 static void pp_c_conditional_expression (c_pretty_printer, tree);
62 static void pp_c_assignment_expression (c_pretty_printer, tree);
65 static void pp_c_declaration_specifiers (c_pretty_printer, tree);
66 static void pp_c_init_declarator (c_pretty_printer, tree);
67 static void pp_c_declarator (c_pretty_printer, tree);
68 static void pp_c_direct_declarator (c_pretty_printer, tree);
69 static void pp_c_abstract_declarator (c_pretty_printer, tree);
70 static void pp_c_specifier_qualifier_list (c_pretty_printer, tree);
71 static void pp_c_simple_type_specifier (c_pretty_printer, tree);
72 static void pp_c_parameter_declaration (c_pretty_printer, tree);
73 static void pp_c_type_id (c_pretty_printer, tree);
74 static void pp_c_storage_class_specifier (c_pretty_printer, tree);
75 static void pp_c_function_specifier (c_pretty_printer, tree);
81 /* Print out CV-qualifiers. Take care of possible extensions.
88 pp_c_cv_qualifier (c_pretty_printer ppi, int cv)
90 if (cv & TYPE_QUAL_CONST)
91 pp_c_identifier (ppi, "const");
92 if (cv & TYPE_QUAL_VOLATILE)
93 pp_c_identifier (ppi, "volatile");
94 if (cv & TYPE_QUAL_RESTRICT)
95 pp_c_identifier (ppi, flag_isoc99 ? "restrict" : "__restrict__");
99 simple-type-specifier:
115 simple-type-specifier:
119 pp_c_simple_type_specifier (c_pretty_printer ppi, tree t)
121 const enum tree_code code = TREE_CODE (t);
125 pp_c_identifier (ppi, "<type-error>");
130 pp_c_identifier (ppi, "<unkown-type>");
134 case IDENTIFIER_NODE:
135 pp_c_tree_identifier (ppi, t);
143 pp_c_tree_identifier (ppi, DECL_NAME (t));
148 pp_c_simple_type_specifier (ppi, TYPE_MAIN_VARIANT (TREE_TYPE (t)));
149 if (code == COMPLEX_TYPE)
150 pp_c_identifier (ppi, flag_isoc99 ? "_Complex" : "__complex__");
151 else if (code == VECTOR_TYPE)
152 pp_c_identifier (ppi, "__vector__");
157 pp_c_tree_identifier (ppi, DECL_NAME (t));
159 pp_c_identifier (ppi, "<typedef-error>");
165 if (code == UNION_TYPE)
166 pp_c_identifier (ppi, "union");
167 else if (code == RECORD_TYPE)
168 pp_c_identifier (ppi, "struct");
169 else if (code == ENUMERAL_TYPE)
170 pp_c_identifier (ppi, "enum");
172 pp_c_identifier (ppi, "<tag-error>");
175 pp_c_tree_identifier (ppi, TYPE_NAME (t));
177 pp_c_identifier (ppi, "<anonymous>");
181 pp_unsupported_tree (ppi, t);
185 /* specifier-qualifier-list:
186 type-specifier specifier-qualifier-list-opt
187 cv-qualifier specifier-qualifier-list-opt */
189 pp_c_specifier_qualifier_list (c_pretty_printer ppi, tree t)
191 pp_c_simple_type_specifier (ppi, TYPE_MAIN_VARIANT (TREE_TYPE (t)));
192 pp_c_cv_qualifier (ppi, TYPE_QUALS (t));
196 pp_c_abstract_declarator (c_pretty_printer ppi, tree t)
198 pp_unsupported_tree (ppi, t);
203 pp_c_type_id (c_pretty_printer ppi, tree t)
205 pp_c_specifier_qualifier_list (ppi, t);
206 pp_c_abstract_declarator (ppi, t);
210 pp_c_storage_class_specifier (c_pretty_printer pp, tree t)
212 if (TREE_CODE (t) == TYPE_DECL)
213 pp_c_identifier (pp, "typedef");
214 else if (DECL_REGISTER (t))
215 pp_c_identifier (pp, "register");
219 pp_c_function_specifier (c_pretty_printer pp, tree t)
221 if (TREE_CODE (t) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (t))
222 pp_c_identifier (pp, "inline");
226 pp_c_declaration_specifiers (c_pretty_printer pp, tree t)
228 pp_c_storage_class_specifier (pp, t);
229 pp_c_function_specifier (pp, t);
230 pp_type_specifier (pp, TYPE_MAIN_VARIANT (TREE_TYPE (t)));
231 pp_c_cv_qualifier (pp, TYPE_QUALS (TREE_TYPE (t)));
235 pp_c_direct_declarator (c_pretty_printer pp, tree t)
237 pp_unsupported_tree (pp, t);
241 pp_c_declarator (c_pretty_printer pp, tree t)
243 pp_unsupported_tree (pp, t);
247 pp_c_init_declarator (c_pretty_printer pp, tree t)
249 pp_declarator (pp, t);
250 if (DECL_INITIAL (t))
255 pp_c_initializer (pp, DECL_INITIAL (t));
260 pp_c_declaration (c_pretty_printer pp, tree t)
262 pp_declaration_specifiers (pp, t);
263 pp_c_init_declarator (pp, t);
267 pp_c_parameter_declaration (c_pretty_printer pp, tree t)
269 pp_unsupported_tree (pp, t);
272 /* Pretty-print ATTRIBUTES using GNU C extension syntax. */
274 pp_c_attributes (c_pretty_printer pp, tree attributes)
276 if (attributes == NULL_TREE)
279 pp_c_identifier (pp, "__attribute__");
280 pp_c_left_paren (pp);
281 pp_c_left_paren (pp);
282 for (; attributes != NULL_TREE; attributes = TREE_CHAIN (attributes))
284 pp_tree_identifier (pp, TREE_PURPOSE (attributes));
285 if (TREE_VALUE (attributes))
287 pp_c_left_paren (pp);
288 pp_c_expression_list (pp, TREE_VALUE (attributes));
289 pp_c_right_paren (pp);
292 if (TREE_CHAIN (attributes))
293 pp_separate_with (pp, ',');
295 pp_c_right_paren (pp);
296 pp_c_right_paren (pp);
302 /* Print out a c-char. */
304 pp_c_char (c_pretty_printer ppi, int c)
309 pp_identifier (ppi, "\\n");
312 pp_identifier (ppi, "\\t");
315 pp_identifier (ppi, "\\v");
318 pp_identifier (ppi, "\\b");
321 pp_identifier (ppi, "\\r");
324 pp_identifier (ppi, "\\f");
327 pp_identifier (ppi, "\\a");
330 pp_identifier (ppi, "\\\\");
333 pp_identifier (ppi, "\\'");
336 pp_identifier (ppi, "\\\"");
340 pp_character (ppi, c);
342 pp_scalar (ppi, "\\%03o", (unsigned) c);
347 /* Print out a STRING literal. */
349 pp_c_string_literal (c_pretty_printer ppi, tree s)
351 const char *p = TREE_STRING_POINTER (s);
352 int n = TREE_STRING_LENGTH (s) - 1;
354 pp_doublequote (ppi);
355 for (i = 0; i < n; ++i)
356 pp_c_char (ppi, p[i]);
357 pp_doublequote (ppi);
360 /* Print out a CHARACTER literal. */
362 pp_c_character_literal (c_pretty_printer ppi, tree c)
365 pp_c_char (ppi, tree_low_cst (c, 0));
369 /* Print out a BOOLEAN literal. */
371 pp_c_bool_literal (c_pretty_printer ppi, tree b)
373 if (b == boolean_false_node || integer_zerop (b))
375 if (c_dialect_cxx ())
376 pp_c_identifier (ppi, "false");
377 else if (flag_isoc99)
378 pp_c_identifier (ppi, "_False");
380 pp_unsupported_tree (ppi, b);
382 else if (b == boolean_true_node)
384 if (c_dialect_cxx ())
385 pp_c_identifier (ppi, "true");
386 else if (flag_isoc99)
387 pp_c_identifier (ppi, "_True");
389 pp_unsupported_tree (ppi, b);
392 pp_unsupported_tree (ppi, b);
395 /* Attempt to print out an ENUMERATOR. Return true on success. Else return
396 false; that means the value was obtained by a cast, in which case
397 print out the type-id part of the cast-expression -- the casted value
398 is then printed by pp_c_integer_literal. */
400 pp_c_enumerator (c_pretty_printer ppi, tree e)
402 tree type = TREE_TYPE (e);
405 /* Find the name of this constant. */
406 for (value = TYPE_VALUES (type);
407 value != NULL_TREE && !tree_int_cst_equal (TREE_VALUE (value), e);
408 value = TREE_CHAIN (value))
411 if (value != NULL_TREE)
412 pp_c_tree_identifier (ppi, TREE_PURPOSE (value));
415 /* Value must have been cast. */
416 pp_c_left_paren (ppi);
417 pp_type_id (ppi, type);
418 pp_c_right_paren (ppi);
425 /* Print out an INTEGER constant value. */
427 pp_c_integer_literal (c_pretty_printer ppi, tree i)
429 tree type = TREE_TYPE (i);
431 if (type == boolean_type_node)
432 pp_c_bool_literal (ppi, i);
433 else if (type == char_type_node)
434 pp_c_character_literal (ppi, i);
435 else if (TREE_CODE (type) == ENUMERAL_TYPE
436 && pp_c_enumerator (ppi, i))
440 if (host_integerp (i, 0))
441 pp_wide_integer (ppi, TREE_INT_CST_LOW (i));
444 if (tree_int_cst_sgn (i) < 0)
446 pp_c_char (ppi, '-');
447 i = build_int_2 (-TREE_INT_CST_LOW (i),
448 ~TREE_INT_CST_HIGH (i) + !TREE_INT_CST_LOW (i));
449 sprintf (pp_buffer (ppi)->digit_buffer,
450 HOST_WIDE_INT_PRINT_DOUBLE_HEX,
451 TREE_INT_CST_HIGH (i), TREE_INT_CST_LOW (i));
452 pp_identifier (ppi, pp_buffer (ppi)->digit_buffer);
459 /* Print out a REAL value. */
461 pp_c_real_literal (c_pretty_printer ppi, tree r)
463 real_to_decimal (pp_buffer (ppi)->digit_buffer, &TREE_REAL_CST (r),
464 sizeof (pp_buffer (ppi)->digit_buffer), 0, 1);
465 pp_identifier (ppi, pp_buffer(ppi)->digit_buffer);
470 pp_c_literal (c_pretty_printer ppi, tree e)
472 switch (TREE_CODE (e))
475 pp_c_integer_literal (ppi, e);
479 pp_c_real_literal (ppi, e);
483 pp_c_string_literal (ppi, e);
487 pp_unsupported_tree (ppi, e);
492 /* Pretty-print a C primary-expression. */
494 pp_c_primary_expression (c_pretty_printer ppi, tree e)
496 switch (TREE_CODE (e))
506 case IDENTIFIER_NODE:
507 pp_c_tree_identifier (ppi, e);
511 pp_c_identifier (ppi, "<erroneous-expression>");
515 pp_c_identifier (ppi, "<return-value>");
521 pp_c_literal (ppi, e);
525 pp_c_left_paren (ppi);
526 pp_c_identifier (ppi, "__builtin_memcpy");
527 pp_c_left_paren (ppi);
529 pp_c_primary_expression (ppi, TREE_OPERAND (e, 0));
530 pp_separate_with (ppi, ',');
532 pp_initializer (ppi, TREE_OPERAND (e, 1));
533 if (TREE_OPERAND (e, 2))
535 pp_separate_with (ppi, ',');
536 pp_c_expression (ppi, TREE_OPERAND (e, 2));
538 pp_c_right_paren (ppi);
541 pp_c_left_paren (ppi);
542 pp_statement (ppi, STMT_EXPR_STMT (e));
543 pp_c_right_paren (ppi);
547 /* Make sure this call won't cause any infinite loop. */
548 pp_c_left_paren (ppi);
549 pp_c_expression (ppi, e);
550 pp_c_right_paren (ppi);
555 /* Print out a C initializer -- also support C compound-literals. */
557 pp_c_initializer (c_pretty_printer ppi, tree e)
559 if (TREE_CODE (e) == CONSTRUCTOR)
561 enum tree_code code = TREE_CODE (TREE_TYPE (e));
562 if (code == RECORD_TYPE || code == UNION_TYPE || code == ARRAY_TYPE)
565 pp_c_initializer_list (ppi, e);
566 pp_right_brace (ppi);
569 pp_unsupported_tree (ppi, TREE_OPERAND (e, 1));
572 pp_assignment_expression (ppi, e);
576 pp_c_initializer_list (c_pretty_printer ppi, tree e)
578 tree type = TREE_TYPE (e);
579 const enum tree_code code = TREE_CODE (type);
581 if (code == RECORD_TYPE || code == UNION_TYPE || code == ARRAY_TYPE)
583 tree init = TREE_OPERAND (e, 1);
584 for (; init != NULL_TREE; init = TREE_CHAIN (init))
586 if (code == RECORD_TYPE || code == UNION_TYPE)
589 pp_c_primary_expression (ppi, TREE_PURPOSE (init));
593 pp_c_left_bracket (ppi);
594 if (TREE_PURPOSE (init))
595 pp_c_literal (ppi, TREE_PURPOSE (init));
596 pp_c_right_bracket (ppi);
598 pp_c_whitespace (ppi);
600 pp_c_whitespace (ppi);
601 pp_initializer (ppi, TREE_VALUE (init));
602 if (TREE_CHAIN (init))
603 pp_separate_with (ppi, ',');
607 pp_unsupported_tree (ppi, type);
611 pp_c_postfix_expression (c_pretty_printer ppi, tree e)
613 enum tree_code code = TREE_CODE (e);
616 case POSTINCREMENT_EXPR:
617 case POSTDECREMENT_EXPR:
618 pp_postfix_expression (ppi, TREE_OPERAND (e, 0));
619 pp_identifier (ppi, code == POSTINCREMENT_EXPR ? "++" : "--");
623 pp_postfix_expression (ppi, TREE_OPERAND (e, 0));
628 pp_postfix_expression (ppi, TREE_OPERAND (e, 0));
629 pp_c_left_bracket (ppi);
630 pp_c_expression (ppi, TREE_OPERAND (e, 1));
631 pp_c_right_bracket (ppi);
635 pp_postfix_expression (ppi, TREE_OPERAND (e, 0));
636 pp_c_left_paren (ppi);
637 pp_c_expression_list (ppi, TREE_OPERAND (e, 1));
638 pp_c_right_paren (ppi);
643 pp_c_identifier (ppi,
644 code == ABS_EXPR ? "__builtin_abs" : "__builtin_ffs");
645 pp_c_left_paren (ppi);
646 pp_c_expression (ppi, TREE_OPERAND (e, 0));
647 pp_c_right_paren (ppi);
652 tree object = TREE_OPERAND (e, 0);
653 if (TREE_CODE (object) == INDIRECT_REF)
655 pp_postfix_expression (ppi, TREE_OPERAND (object, 0));
660 pp_postfix_expression (ppi, object);
663 pp_c_expression (ppi, TREE_OPERAND (e, 1));
670 pp_c_left_paren (ppi);
671 pp_type_id (ppi, TREE_TYPE (e));
672 pp_c_right_paren (ppi);
675 if (code == COMPLEX_CST)
677 pp_c_expression (ppi, TREE_REALPART (e));
678 pp_separate_with (ppi, ',');
679 pp_c_expression (ppi, TREE_IMAGPART (e));
681 else if (code == VECTOR_CST)
682 pp_c_expression_list (ppi, TREE_VECTOR_CST_ELTS (e));
683 else if (code == COMPLEX_EXPR)
685 pp_c_expression (ppi, TREE_OPERAND (e, 0));
686 pp_separate_with (ppi, ',');
687 pp_c_expression (ppi, TREE_OPERAND (e, 1));
690 pp_right_brace (ppi);
693 case COMPOUND_LITERAL_EXPR:
694 e = DECL_INITIAL (e);
697 pp_initializer (ppi, e);
701 pp_c_identifier (ppi, "__builtin_va_arg");
702 pp_c_left_paren (ppi);
703 pp_assignment_expression (ppi, TREE_OPERAND (e, 0));
704 pp_separate_with (ppi, ',');
705 pp_type_id (ppi, TREE_TYPE (e));
706 pp_c_right_paren (ppi);
710 pp_primary_expression (ppi, e);
715 /* Print out an expression-list; E is expected to be a TREE_LIST */
717 pp_c_expression_list (c_pretty_printer ppi, tree e)
719 for (; e != NULL_TREE; e = TREE_CHAIN (e))
721 pp_c_assignment_expression (ppi, TREE_VALUE (e));
723 pp_separate_with (ppi, ',');
731 unary-operator cast-expression
732 sizeof unary-expression
735 unary-operator: one of
740 __alignof__ unary-expression
741 __alignof__ ( type-id )
742 __real__ unary-expression
743 __imag__ unary-expression */
745 pp_c_unary_expression (c_pretty_printer ppi, tree e)
747 enum tree_code code = TREE_CODE (e);
750 case PREINCREMENT_EXPR:
751 case PREDECREMENT_EXPR:
752 pp_identifier (ppi, code == PREINCREMENT_EXPR ? "++" : "--");
753 pp_c_unary_expression (ppi, TREE_OPERAND (e, 0));
762 if (code == ADDR_EXPR)
764 else if (code == INDIRECT_REF)
766 else if (code == NEGATE_EXPR)
768 else if (code == BIT_NOT_EXPR || code == CONJ_EXPR)
770 else if (code == TRUTH_NOT_EXPR)
771 pp_exclamation (ppi);
772 pp_c_cast_expression (ppi, TREE_OPERAND (e, 0));
777 pp_c_identifier (ppi, code == SIZEOF_EXPR ? "sizeof" : "__alignof__");
778 pp_c_whitespace (ppi);
779 if (TYPE_P (TREE_OPERAND (e, 0)))
781 pp_c_left_paren (ppi);
782 pp_type_id (ppi, TREE_OPERAND (e, 0));
783 pp_c_right_paren (ppi);
786 pp_c_unary_expression (ppi, TREE_OPERAND (e, 0));
791 pp_c_identifier (ppi, code == REALPART_EXPR ? "__real__" : "__imag__");
792 pp_c_whitespace (ppi);
793 pp_unary_expression (ppi, TREE_OPERAND (e, 0));
797 pp_postfix_expression (ppi, e);
803 pp_c_cast_expression (c_pretty_printer ppi, tree e)
805 if (TREE_CODE (e) == CONVERT_EXPR || TREE_CODE (e) == FLOAT_EXPR)
807 pp_c_left_paren (ppi);
808 pp_type_id (ppi, TREE_TYPE (e));
809 pp_c_right_paren (ppi);
810 pp_c_cast_expression (ppi, TREE_OPERAND (e, 0));
813 pp_unary_expression (ppi, e);
817 pp_c_multiplicative_expression (c_pretty_printer ppi, tree e)
819 enum tree_code code = TREE_CODE (e);
825 pp_c_multiplicative_expression (ppi, TREE_OPERAND (e, 0));
826 pp_c_whitespace (ppi);
827 if (code == MULT_EXPR)
829 else if (code == TRUNC_DIV_EXPR)
833 pp_c_whitespace (ppi);
834 pp_c_cast_expression (ppi, TREE_OPERAND (e, 1));
838 pp_c_cast_expression (ppi, e);
844 pp_c_additive_expression (c_pretty_printer ppi, tree e)
846 enum tree_code code = TREE_CODE (e);
851 pp_c_additive_expression (ppi, TREE_OPERAND (e, 0));
852 pp_c_whitespace (ppi);
853 if (code == PLUS_EXPR)
857 pp_c_whitespace (ppi);
858 pp_multiplicative_expression (ppi, TREE_OPERAND (e, 1));
862 pp_multiplicative_expression (ppi, e);
868 pp_c_shift_expression (c_pretty_printer ppi, tree e)
870 enum tree_code code = TREE_CODE (e);
875 pp_c_shift_expression (ppi, TREE_OPERAND (e, 0));
876 pp_c_whitespace (ppi);
877 pp_identifier (ppi, code == LSHIFT_EXPR ? "<<" : ">>");
878 pp_c_whitespace (ppi);
879 pp_c_additive_expression (ppi, TREE_OPERAND (e, 1));
883 pp_c_additive_expression (ppi, e);
888 pp_c_relational_expression (c_pretty_printer ppi, tree e)
890 enum tree_code code = TREE_CODE (e);
897 pp_c_relational_expression (ppi, TREE_OPERAND (e, 0));
898 pp_c_whitespace (ppi);
901 else if (code == GT_EXPR)
903 else if (code == LE_EXPR)
904 pp_identifier (ppi, "<=");
905 else if (code == GE_EXPR)
906 pp_identifier (ppi, ">=");
907 pp_c_whitespace (ppi);
908 pp_c_shift_expression (ppi, TREE_OPERAND (e, 1));
912 pp_c_shift_expression (ppi, e);
918 pp_c_equality_expression (c_pretty_printer ppi, tree e)
920 enum tree_code code = TREE_CODE (e);
925 pp_c_equality_expression (ppi, TREE_OPERAND (e, 0));
926 pp_c_maybe_whitespace (ppi);
927 pp_identifier (ppi, code == EQ_EXPR ? "==" : "!=");
928 pp_c_whitespace (ppi);
929 pp_c_relational_expression (ppi, TREE_OPERAND (e, 1));
933 pp_c_relational_expression (ppi, e);
939 pp_c_and_expression (c_pretty_printer ppi, tree e)
941 if (TREE_CODE (e) == BIT_AND_EXPR)
943 pp_c_and_expression (ppi, TREE_OPERAND (e, 0));
944 pp_c_maybe_whitespace (ppi);
946 pp_c_whitespace (ppi);
947 pp_c_equality_expression (ppi, TREE_OPERAND (e, 1));
950 pp_c_equality_expression (ppi, e);
954 pp_c_exclusive_or_expression (c_pretty_printer ppi, tree e)
956 if (TREE_CODE (e) == BIT_XOR_EXPR)
958 pp_c_exclusive_or_expression (ppi, TREE_OPERAND (e, 0));
959 pp_c_maybe_whitespace (ppi);
961 pp_c_whitespace (ppi);
962 pp_c_and_expression (ppi, TREE_OPERAND (e, 1));
965 pp_c_and_expression (ppi, e);
969 pp_c_inclusive_or_expression (c_pretty_printer ppi, tree e)
971 if (TREE_CODE (e) == BIT_IOR_EXPR)
973 pp_c_exclusive_or_expression (ppi, TREE_OPERAND (e, 0));
974 pp_c_maybe_whitespace (ppi);
976 pp_c_whitespace (ppi);
977 pp_c_exclusive_or_expression (ppi, TREE_OPERAND (e, 1));
980 pp_c_exclusive_or_expression (ppi, e);
984 pp_c_logical_and_expression (c_pretty_printer ppi, tree e)
986 if (TREE_CODE (e) == TRUTH_ANDIF_EXPR)
988 pp_c_logical_and_expression (ppi, TREE_OPERAND (e, 0));
989 pp_c_maybe_whitespace (ppi);
990 pp_identifier (ppi, "&&");
991 pp_c_whitespace (ppi);
992 pp_c_inclusive_or_expression (ppi, TREE_OPERAND (e, 1));
995 pp_c_inclusive_or_expression (ppi, e);
999 pp_c_logical_or_expression (c_pretty_printer ppi, tree e)
1001 if (TREE_CODE (e) == TRUTH_ORIF_EXPR)
1003 pp_c_logical_or_expression (ppi, TREE_OPERAND (e, 0));
1004 pp_c_maybe_whitespace (ppi);
1005 pp_identifier (ppi, "||");
1006 pp_c_whitespace (ppi);
1007 pp_c_logical_and_expression (ppi, TREE_OPERAND (e, 1));
1010 pp_c_logical_and_expression (ppi, e);
1014 pp_c_conditional_expression (c_pretty_printer ppi, tree e)
1016 if (TREE_CODE (e) == COND_EXPR)
1018 pp_c_logical_or_expression (ppi, TREE_OPERAND (e, 0));
1019 pp_c_maybe_whitespace (ppi);
1021 pp_c_whitespace (ppi);
1022 pp_c_expression (ppi, TREE_OPERAND (e, 1));
1023 pp_c_maybe_whitespace (ppi);
1025 pp_c_whitespace (ppi);
1026 pp_c_conditional_expression (ppi, TREE_OPERAND (e, 2));
1029 pp_c_logical_or_expression (ppi, e);
1033 /* Pretty-print a C assignment-expression. */
1035 pp_c_assignment_expression (c_pretty_printer ppi, tree e)
1037 if (TREE_CODE (e) == MODIFY_EXPR || TREE_CODE (e) == INIT_EXPR)
1039 pp_c_unary_expression (ppi, TREE_OPERAND (e, 0));
1040 pp_c_maybe_whitespace (ppi);
1043 pp_c_assignment_expression (ppi, TREE_OPERAND (e, 1));
1046 pp_c_conditional_expression (ppi, e);
1049 /* Pretty-print an expression. */
1051 pp_c_expression (c_pretty_printer ppi, tree e)
1053 switch (TREE_CODE (e))
1056 pp_c_integer_literal (ppi, e);
1060 pp_c_real_literal (ppi, e);
1064 pp_c_string_literal (ppi, e);
1077 pp_c_primary_expression (ppi, e);
1080 case POSTINCREMENT_EXPR:
1081 case POSTDECREMENT_EXPR:
1091 case COMPOUND_LITERAL_EXPR:
1094 pp_c_postfix_expression (ppi, e);
1102 case TRUTH_NOT_EXPR:
1103 case PREINCREMENT_EXPR:
1104 case PREDECREMENT_EXPR:
1109 pp_c_unary_expression (ppi, e);
1114 pp_c_cast_expression (ppi, e);
1118 case TRUNC_MOD_EXPR:
1119 case TRUNC_DIV_EXPR:
1120 pp_c_multiplicative_expression (ppi, e);
1125 pp_c_shift_expression (ppi, e);
1132 pp_c_relational_expression (ppi, e);
1136 pp_c_and_expression (ppi, e);
1140 pp_c_exclusive_or_expression (ppi, e);
1144 pp_c_inclusive_or_expression (ppi, e);
1147 case TRUTH_ANDIF_EXPR:
1148 pp_c_logical_and_expression (ppi, e);
1151 case TRUTH_ORIF_EXPR:
1152 pp_c_logical_or_expression (ppi, e);
1156 pp_c_conditional_expression (ppi, e);
1161 pp_c_assignment_expression (ppi, e);
1165 pp_c_expression (ppi, TREE_OPERAND (e, 0));
1169 pp_c_left_paren (ppi);
1170 pp_c_expression (ppi, TREE_OPERAND (e, 0));
1171 pp_separate_with (ppi, ',');
1172 pp_assignment_expression (ppi, TREE_OPERAND (e, 1));
1173 pp_c_right_paren (ppi);
1178 pp_unsupported_tree (ppi, e);
1186 pp_c_statement (c_pretty_printer ppi, tree stmt)
1188 const enum tree_code code = TREE_CODE (stmt);
1194 if (code == LABEL_STMT)
1195 pp_tree_identifier (ppi, DECL_NAME (LABEL_STMT_LABEL (stmt)));
1196 else if (code == LABEL_STMT)
1198 if (CASE_LOW (stmt) == NULL_TREE)
1199 pp_identifier (ppi, "default");
1202 pp_c_identifier (ppi, "case");
1203 pp_c_whitespace (ppi);
1204 pp_conditional_expression (ppi, CASE_LOW (stmt));
1205 if (CASE_HIGH (stmt))
1207 pp_identifier (ppi, "...");
1208 pp_conditional_expression (ppi, CASE_HIGH (stmt));
1213 pp_newline_and_indent (ppi, 3);
1217 pp_left_brace (ppi);
1218 pp_newline_and_indent (ppi, 3);
1219 for (stmt = COMPOUND_BODY (stmt); stmt; stmt = TREE_CHAIN (stmt))
1220 pp_c_statement (ppi, stmt);
1221 pp_newline_and_indent (ppi, -3);
1222 pp_right_brace (ppi);
1229 pp_c_expression (ppi, code == EXPR_STMT
1230 ? EXPR_STMT_EXPR (stmt)
1231 : CLEANUP_EXPR (stmt));
1237 pp_c_identifier (ppi, "if");
1239 pp_c_left_paren (ppi);
1240 pp_c_expression (ppi, IF_COND (stmt));
1241 pp_right_paren (ppi);
1242 pp_newline_and_indent (ppi, 3);
1243 pp_statement (ppi, THEN_CLAUSE (stmt));
1244 pp_newline_and_indent (ppi, -3);
1245 if (ELSE_CLAUSE (stmt))
1247 tree else_clause = ELSE_CLAUSE (stmt);
1248 pp_c_identifier (ppi, "else");
1249 if (TREE_CODE (else_clause) == IF_STMT)
1250 pp_c_whitespace (ppi);
1252 pp_newline_and_indent (ppi, 3);
1253 pp_statement (ppi, else_clause);
1254 if (TREE_CODE (else_clause) != IF_STMT)
1255 pp_newline_and_indent (ppi, -3);
1261 pp_c_identifier (ppi, "switch");
1263 pp_c_left_paren (ppi);
1264 pp_c_expression (ppi, SWITCH_COND (stmt));
1265 pp_right_paren (ppi);
1266 pp_newline_and_indent (ppi, 3);
1267 pp_statement (ppi, SWITCH_BODY (stmt));
1268 pp_newline_and_indent (ppi, -3);
1272 pp_c_identifier (ppi, "while");
1274 pp_c_left_paren (ppi);
1275 pp_c_expression (ppi, WHILE_COND (stmt));
1276 pp_right_paren (ppi);
1277 pp_newline_and_indent (ppi, 3);
1278 pp_statement (ppi, WHILE_BODY (stmt));
1279 pp_newline_and_indent (ppi, -3);
1283 pp_c_identifier (ppi, "do");
1284 pp_newline_and_indent (ppi, 3);
1285 pp_statement (ppi, DO_BODY (stmt));
1286 pp_newline_and_indent (ppi, -3);
1287 pp_c_identifier (ppi, "while");
1289 pp_c_left_paren (ppi);
1290 pp_c_expression (ppi, DO_COND (stmt));
1291 pp_c_right_paren (ppi);
1297 pp_c_identifier (ppi, "for");
1299 pp_c_left_paren (ppi);
1300 pp_statement (ppi, FOR_INIT_STMT (stmt));
1301 pp_c_whitespace (ppi);
1302 if (FOR_COND (stmt))
1303 pp_c_expression (ppi, FOR_COND (stmt));
1305 pp_c_whitespace (ppi);
1306 if (FOR_EXPR (stmt))
1307 pp_c_expression (ppi, FOR_EXPR (stmt));
1308 pp_right_paren (ppi);
1309 pp_newline_and_indent (ppi, 3);
1310 pp_statement (ppi, FOR_BODY (stmt));
1311 pp_newline_and_indent (ppi, -3);
1317 pp_identifier (ppi, code == BREAK_STMT ? "break" : "continue");
1325 tree e = code == RETURN_STMT
1326 ? RETURN_STMT_EXPR (stmt)
1327 : GOTO_DESTINATION (stmt);
1330 pp_c_identifier (ppi, code == RETURN_STMT ? "return" : "goto");
1332 pp_c_expression (ppi, e);
1339 if (!SCOPE_NULLIFIED_P (stmt) && SCOPE_NO_CLEANUPS_P (stmt))
1341 if (SCOPE_BEGIN_P (stmt))
1343 pp_left_brace (ppi);
1344 pp_newline_and_indent (ppi, 3);
1346 else if (SCOPE_END_P (stmt))
1348 pp_right_brace (ppi);
1349 pp_newline_and_indent (ppi, -3);
1355 pp_declaration (ppi, DECL_STMT_DECL (stmt));
1362 bool has_volatile_p = ASM_VOLATILE_P (stmt);
1363 bool is_extended = has_volatile_p || ASM_INPUTS (stmt)
1364 || ASM_OUTPUTS (stmt) || ASM_CLOBBERS (stmt);
1365 pp_c_identifier (ppi, is_extended ? "__asm__" : "asm");
1367 pp_c_identifier (ppi, "__volatile__");
1369 pp_c_left_paren (ppi);
1370 pp_c_string_literal (ppi, ASM_STRING (stmt));
1374 pp_separate_with (ppi, ':');
1375 if (ASM_OUTPUTS (stmt))
1376 pp_c_expression (ppi, ASM_OUTPUTS (stmt));
1378 pp_separate_with (ppi, ':');
1379 if (ASM_INPUTS (stmt))
1380 pp_c_expression (ppi, ASM_INPUTS (stmt));
1382 pp_separate_with (ppi, ':');
1383 if (ASM_CLOBBERS (stmt))
1384 pp_c_expression (ppi, ASM_CLOBBERS (stmt));
1386 pp_right_paren (ppi);
1392 pp_c_identifier (ppi, "__FILE__");
1395 pp_c_whitespace (ppi);
1396 pp_c_identifier (ppi, FILE_STMT_FILENAME (stmt));
1402 pp_unsupported_tree (ppi, stmt);
1408 /* Initialize the PRETTY-PRINTER for handling C codes. */
1410 pp_c_pretty_printer_init (c_pretty_printer pp)
1412 pp->offset_list = 0;
1414 pp->declaration = pp_c_declaration;
1415 pp->declaration_specifiers = pp_c_declaration_specifiers;
1416 pp->type_specifier = pp_c_simple_type_specifier;
1417 pp->declarator = pp_c_declarator;
1418 pp->direct_declarator = pp_c_direct_declarator;
1419 pp->parameter_declaration = pp_c_parameter_declaration;
1420 pp->type_id = pp_c_type_id;
1422 pp->statement = pp_c_statement;
1424 pp->primary_expression = pp_c_primary_expression;
1425 pp->postfix_expression = pp_c_postfix_expression;
1426 pp->unary_expression = pp_c_unary_expression;
1427 pp->initializer = pp_c_initializer;
1428 pp->multiplicative_expression = pp_c_multiplicative_expression;
1429 pp->conditional_expression = pp_c_conditional_expression;
1430 pp->assignment_expression = pp_c_assignment_expression;