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
);
43 static void pp_c_primary_expression (c_pretty_printer
, tree
);
45 /* postfix-expression */
46 static void pp_c_initializer_list (c_pretty_printer
, tree
);
48 static void pp_c_unary_expression (c_pretty_printer
, tree
);
49 static void pp_c_multiplicative_expression (c_pretty_printer
, tree
);
50 static void pp_c_additive_expression (c_pretty_printer
, tree
);
51 static void pp_c_shift_expression (c_pretty_printer
, tree
);
52 static void pp_c_relational_expression (c_pretty_printer
, tree
);
53 static void pp_c_equality_expression (c_pretty_printer
, tree
);
54 static void pp_c_and_expression (c_pretty_printer
, tree
);
55 static void pp_c_exclusive_or_expression (c_pretty_printer
, tree
);
56 static void pp_c_inclusive_or_expression (c_pretty_printer
, tree
);
57 static void pp_c_logical_and_expression (c_pretty_printer
, tree
);
58 static void pp_c_conditional_expression (c_pretty_printer
, tree
);
59 static void pp_c_assignment_expression (c_pretty_printer
, tree
);
62 static void pp_c_declaration_specifiers (c_pretty_printer
, tree
);
63 static void pp_c_init_declarator (c_pretty_printer
, tree
);
64 static void pp_c_declarator (c_pretty_printer
, tree
);
65 static void pp_c_direct_declarator (c_pretty_printer
, tree
);
66 static void pp_c_abstract_declarator (c_pretty_printer
, tree
);
67 static void pp_c_specifier_qualifier_list (c_pretty_printer
, tree
);
68 static void pp_c_simple_type_specifier (c_pretty_printer
, tree
);
69 static void pp_c_parameter_declaration (c_pretty_printer
, tree
);
70 static void pp_c_type_id (c_pretty_printer
, tree
);
71 static void pp_c_storage_class_specifier (c_pretty_printer
, tree
);
72 static void pp_c_function_specifier (c_pretty_printer
, tree
);
78 /* Print out CV-qualifiers. Take care of possible extensions.
85 pp_c_cv_qualifier (c_pretty_printer ppi
, int cv
)
87 if (cv
& TYPE_QUAL_CONST
)
88 pp_c_identifier (ppi
, "const");
89 if (cv
& TYPE_QUAL_VOLATILE
)
90 pp_c_identifier (ppi
, "volatile");
91 if (cv
& TYPE_QUAL_RESTRICT
)
92 pp_c_identifier (ppi
, flag_isoc99
? "restrict" : "__restrict__");
96 simple-type-specifier:
112 simple-type-specifier:
116 pp_c_simple_type_specifier (c_pretty_printer ppi
, tree t
)
118 const enum tree_code code
= TREE_CODE (t
);
122 pp_c_identifier (ppi
, "<type-error>");
127 pp_c_identifier (ppi
, "<unkown-type>");
131 case IDENTIFIER_NODE
:
132 pp_c_tree_identifier (ppi
, t
);
140 pp_c_tree_identifier (ppi
, DECL_NAME (t
));
145 pp_c_simple_type_specifier (ppi
, TYPE_MAIN_VARIANT (TREE_TYPE (t
)));
146 if (code
== COMPLEX_TYPE
)
147 pp_c_identifier (ppi
, flag_isoc99
? "_Complex" : "__complex__");
148 else if (code
== VECTOR_TYPE
)
149 pp_c_identifier (ppi
, "__vector__");
154 pp_c_tree_identifier (ppi
, DECL_NAME (t
));
156 pp_c_identifier (ppi
, "<typedef-error>");
162 if (code
== UNION_TYPE
)
163 pp_c_identifier (ppi
, "union");
164 else if (code
== RECORD_TYPE
)
165 pp_c_identifier (ppi
, "struct");
166 else if (code
== ENUMERAL_TYPE
)
167 pp_c_identifier (ppi
, "enum");
169 pp_c_identifier (ppi
, "<tag-error>");
172 pp_c_tree_identifier (ppi
, TYPE_NAME (t
));
174 pp_c_identifier (ppi
, "<anonymous>");
178 pp_unsupported_tree (ppi
, t
);
182 /* specifier-qualifier-list:
183 type-specifier specifier-qualifier-list-opt
184 cv-qualifier specifier-qualifier-list-opt */
186 pp_c_specifier_qualifier_list (c_pretty_printer ppi
, tree t
)
188 pp_c_simple_type_specifier (ppi
, TYPE_MAIN_VARIANT (TREE_TYPE (t
)));
189 pp_c_cv_qualifier (ppi
, TYPE_QUALS (t
));
193 pp_c_abstract_declarator (c_pretty_printer ppi
, tree t
)
195 pp_unsupported_tree (ppi
, t
);
200 pp_c_type_id (c_pretty_printer ppi
, tree t
)
202 pp_c_specifier_qualifier_list (ppi
, t
);
203 pp_c_abstract_declarator (ppi
, t
);
207 pp_c_storage_class_specifier (c_pretty_printer pp
, tree t
)
209 if (TREE_CODE (t
) == TYPE_DECL
)
210 pp_c_identifier (pp
, "typedef");
211 else if (DECL_REGISTER (t
))
212 pp_c_identifier (pp
, "register");
216 pp_c_function_specifier (c_pretty_printer pp
, tree t
)
218 if (TREE_CODE (t
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (t
))
219 pp_c_identifier (pp
, "inline");
223 pp_c_declaration_specifiers (c_pretty_printer pp
, tree t
)
225 pp_c_storage_class_specifier (pp
, t
);
226 pp_c_function_specifier (pp
, t
);
227 pp_type_specifier (pp
, TYPE_MAIN_VARIANT (TREE_TYPE (t
)));
228 pp_c_cv_qualifier (pp
, TYPE_QUALS (TREE_TYPE (t
)));
232 pp_c_direct_declarator (c_pretty_printer pp
, tree t
)
234 pp_unsupported_tree (pp
, t
);
238 pp_c_declarator (c_pretty_printer pp
, tree t
)
240 pp_unsupported_tree (pp
, t
);
244 pp_c_init_declarator (c_pretty_printer pp
, tree t
)
246 pp_declarator (pp
, t
);
247 if (DECL_INITIAL (t
))
252 pp_c_initializer (pp
, DECL_INITIAL (t
));
257 pp_c_declaration (c_pretty_printer pp
, tree t
)
259 pp_declaration_specifiers (pp
, t
);
260 pp_c_init_declarator (pp
, t
);
264 pp_c_parameter_declaration (c_pretty_printer pp
, tree t
)
266 pp_unsupported_tree (pp
, t
);
269 /* Pretty-print ATTRIBUTES using GNU C extension syntax. */
271 pp_c_attributes (c_pretty_printer pp
, tree attributes
)
273 if (attributes
== NULL_TREE
)
276 pp_c_identifier (pp
, "__attribute__");
277 pp_c_left_paren (pp
);
278 pp_c_left_paren (pp
);
279 for (; attributes
!= NULL_TREE
; attributes
= TREE_CHAIN (attributes
))
281 pp_tree_identifier (pp
, TREE_PURPOSE (attributes
));
282 if (TREE_VALUE (attributes
))
284 pp_c_left_paren (pp
);
285 pp_c_expression_list (pp
, TREE_VALUE (attributes
));
286 pp_c_right_paren (pp
);
289 if (TREE_CHAIN (attributes
))
290 pp_separate_with (pp
, ',');
292 pp_c_right_paren (pp
);
293 pp_c_right_paren (pp
);
299 /* Print out a c-char. */
301 pp_c_char (c_pretty_printer ppi
, int c
)
306 pp_string (ppi
, "\\n");
309 pp_string (ppi
, "\\t");
312 pp_string (ppi
, "\\v");
315 pp_string (ppi
, "\\b");
318 pp_string (ppi
, "\\r");
321 pp_string (ppi
, "\\f");
324 pp_string (ppi
, "\\a");
327 pp_string (ppi
, "\\\\");
330 pp_string (ppi
, "\\'");
333 pp_string (ppi
, "\\\"");
337 pp_character (ppi
, c
);
339 pp_scalar (ppi
, "\\%03o", (unsigned) c
);
344 /* Print out a STRING literal. */
346 pp_c_string_literal (c_pretty_printer ppi
, tree s
)
348 const char *p
= TREE_STRING_POINTER (s
);
349 int n
= TREE_STRING_LENGTH (s
) - 1;
351 pp_doublequote (ppi
);
352 for (i
= 0; i
< n
; ++i
)
353 pp_c_char (ppi
, p
[i
]);
354 pp_doublequote (ppi
);
357 /* Print out a CHARACTER literal. */
359 pp_c_character_literal (c_pretty_printer ppi
, tree c
)
361 tree type
= TREE_TYPE (c
);
363 if (host_integerp (c
, TREE_UNSIGNED (type
)))
364 pp_c_char (ppi
, tree_low_cst (c
, TREE_UNSIGNED (type
)));
366 pp_scalar (ppi
, "\\x%x", (unsigned) TREE_INT_CST_LOW (c
));
370 /* Print out a BOOLEAN literal. */
372 pp_c_bool_literal (c_pretty_printer ppi
, tree b
)
374 if (b
== boolean_false_node
|| integer_zerop (b
))
376 if (c_dialect_cxx ())
377 pp_c_identifier (ppi
, "false");
378 else if (flag_isoc99
)
379 pp_c_identifier (ppi
, "_False");
381 pp_unsupported_tree (ppi
, b
);
383 else if (b
== boolean_true_node
)
385 if (c_dialect_cxx ())
386 pp_c_identifier (ppi
, "true");
387 else if (flag_isoc99
)
388 pp_c_identifier (ppi
, "_True");
390 pp_unsupported_tree (ppi
, b
);
393 pp_unsupported_tree (ppi
, b
);
396 /* Attempt to print out an ENUMERATOR. Return true on success. Else return
397 false; that means the value was obtained by a cast, in which case
398 print out the type-id part of the cast-expression -- the casted value
399 is then printed by pp_c_integer_literal. */
401 pp_c_enumerator (c_pretty_printer ppi
, tree e
)
403 tree type
= TREE_TYPE (e
);
406 /* Find the name of this constant. */
407 for (value
= TYPE_VALUES (type
);
408 value
!= NULL_TREE
&& !tree_int_cst_equal (TREE_VALUE (value
), e
);
409 value
= TREE_CHAIN (value
))
412 if (value
!= NULL_TREE
)
413 pp_c_tree_identifier (ppi
, TREE_PURPOSE (value
));
416 /* Value must have been cast. */
417 pp_c_left_paren (ppi
);
418 pp_type_id (ppi
, type
);
419 pp_c_right_paren (ppi
);
426 /* Print out an INTEGER constant value. */
428 pp_c_integer_literal (c_pretty_printer ppi
, tree i
)
430 tree type
= TREE_TYPE (i
);
432 if (type
== boolean_type_node
)
433 pp_c_bool_literal (ppi
, i
);
434 else if (type
== char_type_node
)
435 pp_c_character_literal (ppi
, i
);
436 else if (TREE_CODE (type
) == ENUMERAL_TYPE
437 && pp_c_enumerator (ppi
, i
))
441 if (host_integerp (i
, 0))
442 pp_wide_integer (ppi
, TREE_INT_CST_LOW (i
));
445 if (tree_int_cst_sgn (i
) < 0)
447 pp_c_char (ppi
, '-');
448 i
= build_int_2 (-TREE_INT_CST_LOW (i
),
449 ~TREE_INT_CST_HIGH (i
) + !TREE_INT_CST_LOW (i
));
450 sprintf (pp_buffer (ppi
)->digit_buffer
,
451 HOST_WIDE_INT_PRINT_DOUBLE_HEX
,
452 TREE_INT_CST_HIGH (i
), TREE_INT_CST_LOW (i
));
453 pp_string (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_string (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
;