1 /* Subroutines common to both C and C++ pretty-printers.
2 Copyright (C) 2002, 2003, 2004 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 (preferably the official grammars) is believed to make it
34 much easier to add extensions and nifty pretty-printing effects that
35 takes expression or declaration contexts into account. */
38 #define pp_c_maybe_whitespace(PP) \
40 if (pp_base (PP)->padding == pp_before) \
41 pp_c_whitespace (PP); \
44 #define pp_c_left_bracket(PP) \
46 pp_left_bracket (PP); \
47 pp_base (PP)->padding = pp_none; \
50 #define pp_c_right_bracket(PP) \
52 pp_right_bracket (PP); \
53 pp_base (PP)->padding = pp_none; \
56 #define pp_c_star(PP) \
59 pp_base (PP)->padding = pp_none; \
63 static void pp_c_char (c_pretty_printer
*, int);
65 /* postfix-expression */
66 static void pp_c_initializer_list (c_pretty_printer
*, tree
);
67 static void pp_c_brace_enclosed_initializer_list (c_pretty_printer
*, tree
);
69 static void pp_c_multiplicative_expression (c_pretty_printer
*, tree
);
70 static void pp_c_additive_expression (c_pretty_printer
*, tree
);
71 static void pp_c_shift_expression (c_pretty_printer
*, tree
);
72 static void pp_c_relational_expression (c_pretty_printer
*, tree
);
73 static void pp_c_equality_expression (c_pretty_printer
*, tree
);
74 static void pp_c_and_expression (c_pretty_printer
*, tree
);
75 static void pp_c_exclusive_or_expression (c_pretty_printer
*, tree
);
76 static void pp_c_inclusive_or_expression (c_pretty_printer
*, tree
);
77 static void pp_c_logical_and_expression (c_pretty_printer
*, tree
);
78 static void pp_c_conditional_expression (c_pretty_printer
*, tree
);
79 static void pp_c_assignment_expression (c_pretty_printer
*, tree
);
84 /* Helper functions. */
87 pp_c_whitespace (c_pretty_printer
*pp
)
90 pp_base (pp
)->padding
= pp_none
;
94 pp_c_left_paren (c_pretty_printer
*pp
)
97 pp_base (pp
)->padding
= pp_none
;
101 pp_c_right_paren (c_pretty_printer
*pp
)
104 pp_base (pp
)->padding
= pp_none
;
108 pp_c_left_brace (c_pretty_printer
*pp
)
111 pp_base (pp
)->padding
= pp_none
;
115 pp_c_right_brace (c_pretty_printer
*pp
)
118 pp_base (pp
)->padding
= pp_none
;
122 pp_c_dot (c_pretty_printer
*pp
)
125 pp_base (pp
)->padding
= pp_none
;
129 pp_c_ampersand (c_pretty_printer
*pp
)
132 pp_base (pp
)->padding
= pp_none
;
136 pp_c_arrow (c_pretty_printer
*pp
)
139 pp_base (pp
)->padding
= pp_none
;
143 pp_c_semicolon(c_pretty_printer
*pp
)
146 pp_base (pp
)->padding
= pp_none
;
150 pp_c_cv_qualifier (c_pretty_printer
*pp
, const char *cv
)
152 const char *p
= pp_last_position_in_text (pp
);
153 if (p
!= NULL
&& *p
== '*')
154 pp_c_whitespace (pp
);
155 pp_c_identifier (pp
, cv
);
158 /* Pretty-print T using the type-cast notation '( type-name )'. */
161 pp_c_type_cast (c_pretty_printer
*pp
, tree t
)
163 pp_c_left_paren (pp
);
165 pp_c_right_paren (pp
);
169 pp_c_space_for_pointer_operator (c_pretty_printer
*pp
, tree t
)
171 if (POINTER_TYPE_P (t
))
173 tree pointee
= strip_pointer_operator (TREE_TYPE (t
));
174 if (TREE_CODE (pointee
) != ARRAY_TYPE
175 && TREE_CODE (pointee
) != FUNCTION_TYPE
)
176 pp_c_whitespace (pp
);
183 /* C++ cv-qualifiers are called type-qualifiers in C. Print out the
184 cv-qualifiers of T. If T is a declaration then it is the cv-qualifier
185 of its type. Take care of possible extensions.
189 type-qualifier-list type-qualifier
194 __restrict__ -- GNU C
198 pp_c_type_qualifier_list (c_pretty_printer
*pp
, tree t
)
205 qualifiers
= TYPE_QUALS (t
);
206 if (qualifiers
& TYPE_QUAL_CONST
)
207 pp_c_cv_qualifier (pp
, "const");
208 if (qualifiers
& TYPE_QUAL_VOLATILE
)
209 pp_c_cv_qualifier (pp
, "volatile");
210 if (qualifiers
& TYPE_QUAL_RESTRICT
)
211 pp_c_cv_qualifier (pp
, flag_isoc99
? "restrict" : "__restrict__");
215 * type-qualifier-list(opt)
216 * type-qualifier-list(opt) pointer */
219 pp_c_pointer (c_pretty_printer
*pp
, tree t
)
221 if (!TYPE_P (t
) && TREE_CODE (t
) != TYPE_DECL
)
223 switch (TREE_CODE (t
))
226 /* It is easier to handle C++ reference types here. */
228 if (TREE_CODE (TREE_TYPE (t
)) == POINTER_TYPE
)
229 pp_c_pointer (pp
, TREE_TYPE (t
));
230 if (TREE_CODE (t
) == POINTER_TYPE
)
234 pp_c_type_qualifier_list (pp
, t
);
238 pp_unsupported_tree (pp
, t
);
255 struct-or-union-specifier
260 simple-type-specifier:
265 pp_c_type_specifier (c_pretty_printer
*pp
, tree t
)
267 const enum tree_code code
= TREE_CODE (t
);
271 pp_c_identifier (pp
, "<type-error>");
274 case IDENTIFIER_NODE
:
275 pp_c_tree_identifier (pp
, t
);
286 t
= c_common_type_for_mode (TYPE_MODE (t
), TREE_UNSIGNED (t
));
287 pp_c_type_specifier (pp
, t
);
292 pp_id_expression (pp
, t
);
294 pp_c_identifier (pp
, "<typedef-error>");
300 if (code
== UNION_TYPE
)
301 pp_c_identifier (pp
, "union");
302 else if (code
== RECORD_TYPE
)
303 pp_c_identifier (pp
, "struct");
304 else if (code
== ENUMERAL_TYPE
)
305 pp_c_identifier (pp
, "enum");
307 pp_c_identifier (pp
, "<tag-error>");
310 pp_id_expression (pp
, TYPE_NAME (t
));
312 pp_c_identifier (pp
, "<anonymous>");
316 pp_unsupported_tree (pp
, t
);
321 /* specifier-qualifier-list:
322 type-specifier specifier-qualifier-list-opt
323 type-qualifier specifier-qualifier-list-opt
326 Implementation note: Because of the non-linearities in array or
327 function declarations, this routine prints not just the
328 specifier-qualifier-list of such entities or types of such entities,
329 but also the 'pointer' production part of their declarators. The
330 remaining part is done by pp_declarator or pp_c_abstract_declarator. */
333 pp_c_specifier_qualifier_list (c_pretty_printer
*pp
, tree t
)
335 const enum tree_code code
= TREE_CODE (t
);
337 if (TREE_CODE (t
) != POINTER_TYPE
)
338 pp_c_type_qualifier_list (pp
, t
);
344 /* Get the types-specifier of this type. */
345 tree pointee
= strip_pointer_operator (TREE_TYPE (t
));
346 pp_c_specifier_qualifier_list (pp
, pointee
);
347 if (TREE_CODE (pointee
) == ARRAY_TYPE
348 || TREE_CODE (pointee
) == FUNCTION_TYPE
)
350 pp_c_whitespace (pp
);
351 pp_c_left_paren (pp
);
353 pp_ptr_operator (pp
, t
);
359 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
364 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
365 if (code
== COMPLEX_TYPE
)
366 pp_c_identifier (pp
, flag_isoc99
? "_Complex" : "__complex__");
367 else if (code
== VECTOR_TYPE
)
368 pp_c_identifier (pp
, "__vector__");
372 pp_simple_type_specifier (pp
, t
);
377 /* parameter-type-list:
382 parameter-declaration
383 parameter-list , parameter-declaration
385 parameter-declaration:
386 declaration-specifiers declarator
387 declaration-specifiers abstract-declarator(opt) */
390 pp_c_parameter_type_list (c_pretty_printer
*pp
, tree t
)
392 bool want_parm_decl
= DECL_P (t
) && !(pp
->flags
& pp_c_flag_abstract
);
393 tree parms
= want_parm_decl
? DECL_ARGUMENTS (t
) : TYPE_ARG_TYPES (t
);
394 pp_c_left_paren (pp
);
395 if (parms
== void_list_node
)
396 pp_c_identifier (pp
, "void");
400 for ( ; parms
&& parms
!= void_list_node
; parms
= TREE_CHAIN (parms
))
403 pp_separate_with (pp
, ',');
405 pp_declaration_specifiers
406 (pp
, want_parm_decl
? parms
: TREE_VALUE (parms
));
408 pp_declarator (pp
, parms
);
410 pp_abstract_declarator (pp
, TREE_VALUE (parms
));
413 pp_c_right_paren (pp
);
416 /* abstract-declarator:
418 pointer(opt) direct-abstract-declarator */
421 pp_c_abstract_declarator (c_pretty_printer
*pp
, tree t
)
423 if (TREE_CODE (t
) == POINTER_TYPE
)
425 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
426 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
427 pp_c_right_paren (pp
);
431 pp_direct_abstract_declarator (pp
, t
);
434 /* direct-abstract-declarator:
435 ( abstract-declarator )
436 direct-abstract-declarator(opt) [ assignment-expression(opt) ]
437 direct-abstract-declarator(opt) [ * ]
438 direct-abstract-declarator(opt) ( parameter-type-list(opt) ) */
441 pp_c_direct_abstract_declarator (c_pretty_printer
*pp
, tree t
)
443 switch (TREE_CODE (t
))
446 pp_abstract_declarator (pp
, t
);
450 pp_c_parameter_type_list (pp
, t
);
451 pp_direct_abstract_declarator (pp
, TREE_TYPE (t
));
455 pp_c_left_bracket (pp
);
457 pp_expression (pp
, TYPE_MAX_VALUE (TYPE_DOMAIN (t
)));
458 pp_c_right_bracket (pp
);
459 pp_direct_abstract_declarator (pp
, TREE_TYPE (t
));
462 case IDENTIFIER_NODE
:
476 pp_unsupported_tree (pp
, t
);
482 specifier-qualifier-list abstract-declarator(opt) */
485 pp_c_type_id (c_pretty_printer
*pp
, tree t
)
487 pp_c_specifier_qualifier_list (pp
, t
);
488 pp_abstract_declarator (pp
, t
);
491 /* storage-class-specifier:
499 pp_c_storage_class_specifier (c_pretty_printer
*pp
, tree t
)
501 if (TREE_CODE (t
) == TYPE_DECL
)
502 pp_c_identifier (pp
, "typedef");
505 if (DECL_REGISTER (t
))
506 pp_c_identifier (pp
, "register");
507 else if (TREE_STATIC (t
) && TREE_CODE (t
) == VAR_DECL
)
508 pp_c_identifier (pp
, "static");
512 /* function-specifier:
516 pp_c_function_specifier (c_pretty_printer
*pp
, tree t
)
518 if (TREE_CODE (t
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (t
))
519 pp_c_identifier (pp
, "inline");
522 /* declaration-specifiers:
523 storage-class-specifier declaration-specifiers(opt)
524 type-specifier declaration-specifiers(opt)
525 type-qualifier declaration-specifiers(opt)
526 function-specifier declaration-specifiers(opt) */
529 pp_c_declaration_specifiers (c_pretty_printer
*pp
, tree t
)
531 pp_storage_class_specifier (pp
, t
);
532 pp_function_specifier (pp
, t
);
533 pp_c_specifier_qualifier_list (pp
, DECL_P (t
) ? TREE_TYPE (t
) : t
);
539 direct-declarator [ type-qualifier-list(opt) assignment-expression(opt) ]
540 direct-declarator [ static type-qualifier-list(opt) assignment-expression(opt)]
541 direct-declarator [ type-qualifier-list static assignment-expression ]
542 direct-declarator [ type-qualifier-list * ]
543 direct-declarator ( parameter-type-list )
544 direct-declarator ( identifier-list(opt) ) */
547 pp_c_direct_declarator (c_pretty_printer
*pp
, tree t
)
549 switch (TREE_CODE (t
))
558 pp_c_space_for_pointer_operator (pp
, TREE_TYPE (t
));
559 pp_c_tree_identifier (pp
, DECL_NAME (t
));
563 pp_abstract_declarator (pp
, TREE_TYPE (t
));
567 pp_parameter_list (pp
, t
);
568 pp_abstract_declarator (pp
, TREE_TYPE (t
));
572 pp_c_space_for_pointer_operator (pp
, TREE_TYPE (TREE_TYPE (t
)));
573 pp_c_tree_identifier (pp
, DECL_NAME (t
));
574 if (pp_c_base (pp
)->flags
& pp_c_flag_abstract
)
575 pp_abstract_declarator (pp
, TREE_TYPE (t
));
578 pp_parameter_list (pp
, t
);
579 pp_abstract_declarator (pp
, TREE_TYPE (TREE_TYPE (t
)));
591 pp_unsupported_tree (pp
, t
);
598 pointer(opt) direct-declarator */
601 pp_c_declarator (c_pretty_printer
*pp
, tree t
)
603 switch (TREE_CODE (t
))
619 pp_direct_declarator (pp
, t
);
624 pp_unsupported_tree (pp
, t
);
630 declaration-specifiers init-declarator-list(opt) ; */
633 pp_c_declaration (c_pretty_printer
*pp
, tree t
)
635 pp_declaration_specifiers (pp
, t
);
636 pp_c_init_declarator (pp
, t
);
639 /* Pretty-print ATTRIBUTES using GNU C extension syntax. */
642 pp_c_attributes (c_pretty_printer
*pp
, tree attributes
)
644 if (attributes
== NULL_TREE
)
647 pp_c_identifier (pp
, "__attribute__");
648 pp_c_left_paren (pp
);
649 pp_c_left_paren (pp
);
650 for (; attributes
!= NULL_TREE
; attributes
= TREE_CHAIN (attributes
))
652 pp_tree_identifier (pp
, TREE_PURPOSE (attributes
));
653 if (TREE_VALUE (attributes
))
654 pp_c_call_argument_list (pp
, TREE_VALUE (attributes
));
656 if (TREE_CHAIN (attributes
))
657 pp_separate_with (pp
, ',');
659 pp_c_right_paren (pp
);
660 pp_c_right_paren (pp
);
663 /* function-definition:
664 declaration-specifiers declarator compound-statement */
667 pp_c_function_definition (c_pretty_printer
*pp
, tree t
)
669 pp_declaration_specifiers (pp
, t
);
670 pp_declarator (pp
, t
);
671 pp_needs_newline (pp
) = true;
672 pp_statement (pp
, DECL_SAVED_TREE (t
));
680 /* Print out a c-char. */
683 pp_c_char (c_pretty_printer
*pp
, int c
)
688 pp_string (pp
, "\\n");
691 pp_string (pp
, "\\t");
694 pp_string (pp
, "\\v");
697 pp_string (pp
, "\\b");
700 pp_string (pp
, "\\r");
703 pp_string (pp
, "\\f");
706 pp_string (pp
, "\\a");
709 pp_string (pp
, "\\\\");
712 pp_string (pp
, "\\'");
715 pp_string (pp
, "\\\"");
719 pp_character (pp
, c
);
721 pp_scalar (pp
, "\\%03o", (unsigned) c
);
726 /* Print out a STRING literal. */
729 pp_c_string_literal (c_pretty_printer
*pp
, tree s
)
731 const char *p
= TREE_STRING_POINTER (s
);
732 int n
= TREE_STRING_LENGTH (s
) - 1;
735 for (i
= 0; i
< n
; ++i
)
736 pp_c_char (pp
, p
[i
]);
741 pp_c_integer_constant (c_pretty_printer
*pp
, tree i
)
743 tree type
= TREE_TYPE (i
);
745 if (TREE_INT_CST_HIGH (i
) == 0)
746 pp_wide_integer (pp
, TREE_INT_CST_LOW (i
));
749 if (tree_int_cst_sgn (i
) < 0)
752 i
= build_int_2 (-TREE_INT_CST_LOW (i
),
753 ~TREE_INT_CST_HIGH (i
) + !TREE_INT_CST_LOW (i
));
755 sprintf (pp_buffer (pp
)->digit_buffer
,
756 HOST_WIDE_INT_PRINT_DOUBLE_HEX
,
757 TREE_INT_CST_HIGH (i
), TREE_INT_CST_LOW (i
));
758 pp_string (pp
, pp_buffer (pp
)->digit_buffer
);
760 if (TREE_UNSIGNED (type
))
761 pp_character (pp
, 'u');
762 if (type
== long_integer_type_node
|| type
== long_unsigned_type_node
)
763 pp_character (pp
, 'l');
764 else if (type
== long_long_integer_type_node
765 || type
== long_long_unsigned_type_node
)
766 pp_string (pp
, "ll");
769 /* Print out a CHARACTER literal. */
772 pp_c_character_constant (c_pretty_printer
*pp
, tree c
)
774 tree type
= TREE_TYPE (c
);
775 if (type
== wchar_type_node
)
776 pp_character (pp
, 'L');
778 if (host_integerp (c
, TREE_UNSIGNED (type
)))
779 pp_c_char (pp
, tree_low_cst (c
, TREE_UNSIGNED (type
)));
781 pp_scalar (pp
, "\\x%x", (unsigned) TREE_INT_CST_LOW (c
));
785 /* Print out a BOOLEAN literal. */
788 pp_c_bool_constant (c_pretty_printer
*pp
, tree b
)
790 if (b
== boolean_false_node
)
792 if (c_dialect_cxx ())
793 pp_c_identifier (pp
, "false");
794 else if (flag_isoc99
)
795 pp_c_identifier (pp
, "_False");
797 pp_unsupported_tree (pp
, b
);
799 else if (b
== boolean_true_node
)
801 if (c_dialect_cxx ())
802 pp_c_identifier (pp
, "true");
803 else if (flag_isoc99
)
804 pp_c_identifier (pp
, "_True");
806 pp_unsupported_tree (pp
, b
);
808 else if (TREE_CODE (b
) == INTEGER_CST
)
809 pp_c_integer_constant (pp
, b
);
811 pp_unsupported_tree (pp
, b
);
814 /* Attempt to print out an ENUMERATOR. Return true on success. Else return
815 false; that means the value was obtained by a cast, in which case
816 print out the type-id part of the cast-expression -- the casted value
817 is then printed by pp_c_integer_literal. */
820 pp_c_enumeration_constant (c_pretty_printer
*pp
, tree e
)
822 bool value_is_named
= true;
823 tree type
= TREE_TYPE (e
);
826 /* Find the name of this constant. */
827 for (value
= TYPE_VALUES (type
);
828 value
!= NULL_TREE
&& !tree_int_cst_equal (TREE_VALUE (value
), e
);
829 value
= TREE_CHAIN (value
))
832 if (value
!= NULL_TREE
)
833 pp_id_expression (pp
, TREE_PURPOSE (value
));
836 /* Value must have been cast. */
837 pp_c_type_cast (pp
, type
);
838 value_is_named
= false;
841 return value_is_named
;
844 /* Print out a REAL value as a decimal-floating-constant. */
847 pp_c_floating_constant (c_pretty_printer
*pp
, tree r
)
849 real_to_decimal (pp_buffer (pp
)->digit_buffer
, &TREE_REAL_CST (r
),
850 sizeof (pp_buffer (pp
)->digit_buffer
), 0, 1);
851 pp_string (pp
, pp_buffer(pp
)->digit_buffer
);
852 if (TREE_TYPE (r
) == float_type_node
)
853 pp_character (pp
, 'f');
854 else if (TREE_TYPE (r
) == long_double_type_node
)
855 pp_character (pp
, 'l');
858 /* Pretty-print a compound literal expression. GNU extensions include
862 pp_c_compound_literal (c_pretty_printer
*pp
, tree e
)
864 tree type
= TREE_TYPE (e
);
865 pp_c_type_cast (pp
, type
);
867 switch (TREE_CODE (type
))
874 pp_c_brace_enclosed_initializer_list (pp
, e
);
878 pp_unsupported_tree (pp
, e
);
887 character-constant */
890 pp_c_constant (c_pretty_printer
*pp
, tree e
)
892 const enum tree_code code
= TREE_CODE (e
);
898 tree type
= TREE_TYPE (e
);
899 if (type
== boolean_type_node
)
900 pp_c_bool_constant (pp
, e
);
901 else if (type
== char_type_node
)
902 pp_c_character_constant (pp
, e
);
903 else if (TREE_CODE (type
) == ENUMERAL_TYPE
904 && pp_c_enumeration_constant (pp
, e
))
907 pp_c_integer_constant (pp
, e
);
912 pp_c_floating_constant (pp
, e
);
916 pp_c_string_literal (pp
, e
);
920 pp_unsupported_tree (pp
, e
);
926 pp_c_identifier (c_pretty_printer
*pp
, const char *id
)
928 pp_c_maybe_whitespace (pp
);
929 pp_identifier (pp
, id
);
930 pp_base (pp
)->padding
= pp_before
;
933 /* Pretty-print a C primary-expression.
941 pp_c_primary_expression (c_pretty_printer
*pp
, tree e
)
943 switch (TREE_CODE (e
))
953 case IDENTIFIER_NODE
:
954 pp_c_tree_identifier (pp
, e
);
958 pp_c_identifier (pp
, "<erroneous-expression>");
962 pp_c_identifier (pp
, "<return-value>");
968 pp_c_constant (pp
, e
);
972 pp_c_left_paren (pp
);
973 pp_statement (pp
, STMT_EXPR_STMT (e
));
974 pp_c_right_paren (pp
);
978 /* FIXME: Make sure we won't get into an infinie loop. */
979 pp_c_left_paren (pp
);
980 pp_expression (pp
, e
);
981 pp_c_right_paren (pp
);
986 /* Print out a C initializer -- also support C compound-literals.
988 assignment-expression:
990 { initializer-list , } */
993 pp_c_initializer (c_pretty_printer
*pp
, tree e
)
995 if (TREE_CODE (e
) == CONSTRUCTOR
)
997 enum tree_code code
= TREE_CODE (TREE_TYPE (e
));
998 if (code
== RECORD_TYPE
|| code
== UNION_TYPE
|| code
== ARRAY_TYPE
)
999 pp_c_brace_enclosed_initializer_list (pp
, e
);
1001 pp_unsupported_tree (pp
, TREE_OPERAND (e
, 1));
1004 pp_expression (pp
, e
);
1009 declarator = initializer */
1012 pp_c_init_declarator (c_pretty_printer
*pp
, tree t
)
1014 pp_declarator (pp
, t
);
1015 if (DECL_INITIAL (t
))
1017 tree init
= DECL_INITIAL (t
);
1018 /* This C++ bit is handled here because it is easier to do so.
1019 In templates, the C++ parser builds a TREE_LIST for a
1020 direct-initialization; the TREE_PURPOSE is the variable to
1021 initialize and the TREE_VALUE is the initializer. */
1022 if (TREE_CODE (init
) == TREE_LIST
)
1024 pp_c_left_paren (pp
);
1025 pp_expression (pp
, TREE_VALUE (init
));
1026 pp_right_paren (pp
);
1033 pp_c_initializer (pp
, init
);
1038 /* initializer-list:
1039 designation(opt) initializer
1040 initializer-list , designation(opt) initializer
1047 designator-list designator
1050 [ constant-expression ]
1054 pp_c_initializer_list (c_pretty_printer
*pp
, tree e
)
1056 tree type
= TREE_TYPE (e
);
1057 const enum tree_code code
= TREE_CODE (type
);
1065 tree init
= TREE_OPERAND (e
, 0);
1066 for (; init
!= NULL_TREE
; init
= TREE_CHAIN (init
))
1068 if (code
== RECORD_TYPE
|| code
== UNION_TYPE
)
1071 pp_c_primary_expression (pp
, TREE_PURPOSE (init
));
1075 pp_c_left_bracket (pp
);
1076 if (TREE_PURPOSE (init
))
1077 pp_c_constant (pp
, TREE_PURPOSE (init
));
1078 pp_c_right_bracket (pp
);
1080 pp_c_whitespace (pp
);
1082 pp_c_whitespace (pp
);
1083 pp_initializer (pp
, TREE_VALUE (init
));
1084 if (TREE_CHAIN (init
))
1085 pp_separate_with (pp
, ',');
1091 pp_c_expression_list (pp
, TREE_VECTOR_CST_ELTS (e
));
1096 const bool cst
= TREE_CODE (e
) == COMPLEX_CST
;
1097 pp_expression (pp
, cst
? TREE_REALPART (e
) : TREE_OPERAND (e
, 0));
1098 pp_separate_with (pp
, ',');
1099 pp_expression (pp
, cst
? TREE_IMAGPART (e
) : TREE_OPERAND (e
, 1));
1104 pp_unsupported_tree (pp
, type
);
1109 /* Pretty-print a brace-enclosed initializer-list. */
1112 pp_c_brace_enclosed_initializer_list (c_pretty_printer
*pp
, tree l
)
1114 pp_c_left_brace (pp
);
1115 pp_c_initializer_list (pp
, l
);
1116 pp_c_right_brace (pp
);
1120 /* This is a convenient function, used to bridge gap between C and C++
1127 pp_c_id_expression (c_pretty_printer
*pp
, tree t
)
1129 switch (TREE_CODE (t
))
1139 case IDENTIFIER_NODE
:
1140 pp_c_tree_identifier (pp
, t
);
1144 pp_unsupported_tree (pp
, t
);
1149 /* postfix-expression:
1151 postfix-expression [ expression ]
1152 postfix-expression ( argument-expression-list(opt) )
1153 postfix-expression . identifier
1154 postfix-expression -> identifier
1155 postfix-expression ++
1156 postfix-expression --
1157 ( type-name ) { initializer-list }
1158 ( type-name ) { initializer-list , } */
1161 pp_c_postfix_expression (c_pretty_printer
*pp
, tree e
)
1163 enum tree_code code
= TREE_CODE (e
);
1166 case POSTINCREMENT_EXPR
:
1167 case POSTDECREMENT_EXPR
:
1168 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1169 pp_identifier (pp
, code
== POSTINCREMENT_EXPR
? "++" : "--");
1173 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1178 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1179 pp_c_left_bracket (pp
);
1180 pp_expression (pp
, TREE_OPERAND (e
, 1));
1181 pp_c_right_bracket (pp
);
1185 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1186 pp_c_call_argument_list (pp
, TREE_OPERAND (e
, 1));
1190 pp_c_identifier (pp
, "__builtin_abs");
1191 pp_c_left_paren (pp
);
1192 pp_expression (pp
, TREE_OPERAND (e
, 0));
1193 pp_c_right_paren (pp
);
1198 tree object
= TREE_OPERAND (e
, 0);
1199 if (TREE_CODE (object
) == INDIRECT_REF
)
1201 pp_postfix_expression (pp
, TREE_OPERAND (object
, 0));
1206 pp_postfix_expression (pp
, object
);
1209 pp_expression (pp
, TREE_OPERAND (e
, 1));
1216 pp_c_compound_literal (pp
, e
);
1219 case COMPOUND_LITERAL_EXPR
:
1220 e
= DECL_INITIAL (COMPOUND_LITERAL_EXPR_DECL (e
));
1223 pp_initializer (pp
, e
);
1227 pp_c_identifier (pp
, "__builtin_va_arg");
1228 pp_c_left_paren (pp
);
1229 pp_assignment_expression (pp
, TREE_OPERAND (e
, 0));
1230 pp_separate_with (pp
, ',');
1231 pp_type_id (pp
, TREE_TYPE (e
));
1232 pp_c_right_paren (pp
);
1236 if (TREE_CODE (TREE_OPERAND (e
, 0)) == FUNCTION_DECL
)
1238 pp_c_id_expression (pp
, TREE_OPERAND (e
, 0));
1241 /* else fall through. */
1244 pp_primary_expression (pp
, e
);
1249 /* Print out an expression-list; E is expected to be a TREE_LIST. */
1252 pp_c_expression_list (c_pretty_printer
*pp
, tree e
)
1254 for (; e
!= NULL_TREE
; e
= TREE_CHAIN (e
))
1256 pp_expression (pp
, TREE_VALUE (e
));
1258 pp_separate_with (pp
, ',');
1262 /* Print out an expression-list in parens, as in a function call. */
1265 pp_c_call_argument_list (c_pretty_printer
*pp
, tree t
)
1267 pp_c_left_paren (pp
);
1268 if (t
&& TREE_CODE (t
) == TREE_LIST
)
1269 pp_c_expression_list (pp
, t
);
1270 pp_c_right_paren (pp
);
1273 /* unary-expression:
1277 unary-operator cast-expression
1278 sizeof unary-expression
1281 unary-operator: one of
1286 __alignof__ unary-expression
1287 __alignof__ ( type-id )
1288 __real__ unary-expression
1289 __imag__ unary-expression */
1292 pp_c_unary_expression (c_pretty_printer
*pp
, tree e
)
1294 enum tree_code code
= TREE_CODE (e
);
1297 case PREINCREMENT_EXPR
:
1298 case PREDECREMENT_EXPR
:
1299 pp_identifier (pp
, code
== PREINCREMENT_EXPR
? "++" : "--");
1300 pp_c_unary_expression (pp
, TREE_OPERAND (e
, 0));
1307 case TRUTH_NOT_EXPR
:
1309 /* String literal are used by address. */
1310 if (code
== ADDR_EXPR
&& TREE_CODE (TREE_OPERAND (e
, 0)) != STRING_CST
)
1312 else if (code
== INDIRECT_REF
)
1314 else if (code
== NEGATE_EXPR
)
1316 else if (code
== BIT_NOT_EXPR
|| code
== CONJ_EXPR
)
1318 else if (code
== TRUTH_NOT_EXPR
)
1319 pp_exclamation (pp
);
1320 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 0));
1325 pp_c_identifier (pp
, code
== SIZEOF_EXPR
? "sizeof" : "__alignof__");
1326 pp_c_whitespace (pp
);
1327 if (TYPE_P (TREE_OPERAND (e
, 0)))
1328 pp_c_type_cast (pp
, TREE_OPERAND (e
, 0));
1330 pp_unary_expression (pp
, TREE_OPERAND (e
, 0));
1335 pp_c_identifier (pp
, code
== REALPART_EXPR
? "__real__" : "__imag__");
1336 pp_c_whitespace (pp
);
1337 pp_unary_expression (pp
, TREE_OPERAND (e
, 0));
1341 pp_postfix_expression (pp
, e
);
1348 ( type-name ) cast-expression */
1351 pp_c_cast_expression (c_pretty_printer
*pp
, tree e
)
1353 switch (TREE_CODE (e
))
1356 case FIX_TRUNC_EXPR
:
1358 pp_c_type_cast (pp
, TREE_TYPE (e
));
1359 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 0));
1363 pp_unary_expression (pp
, e
);
1367 /* multiplicative-expression:
1369 multiplicative-expression * cast-expression
1370 multiplicative-expression / cast-expression
1371 multiplicative-expression % cast-expression */
1374 pp_c_multiplicative_expression (c_pretty_printer
*pp
, tree e
)
1376 enum tree_code code
= TREE_CODE (e
);
1380 case TRUNC_DIV_EXPR
:
1381 case TRUNC_MOD_EXPR
:
1382 pp_multiplicative_expression (pp
, TREE_OPERAND (e
, 0));
1383 pp_c_whitespace (pp
);
1384 if (code
== MULT_EXPR
)
1386 else if (code
== TRUNC_DIV_EXPR
)
1390 pp_c_whitespace (pp
);
1391 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 1));
1395 pp_c_cast_expression (pp
, e
);
1400 /* additive-expression:
1401 multiplicative-expression
1402 additive-expression + multiplicative-expression
1403 additive-expression - multiplicative-expression */
1406 pp_c_additive_expression (c_pretty_printer
*pp
, tree e
)
1408 enum tree_code code
= TREE_CODE (e
);
1413 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 0));
1414 pp_c_whitespace (pp
);
1415 if (code
== PLUS_EXPR
)
1419 pp_c_whitespace (pp
);
1420 pp_multiplicative_expression (pp
, TREE_OPERAND (e
, 1));
1424 pp_multiplicative_expression (pp
, e
);
1429 /* additive-expression:
1431 shift-expression << additive-expression
1432 shift-expression >> additive-expression */
1435 pp_c_shift_expression (c_pretty_printer
*pp
, tree e
)
1437 enum tree_code code
= TREE_CODE (e
);
1442 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 0));
1443 pp_c_whitespace (pp
);
1444 pp_identifier (pp
, code
== LSHIFT_EXPR
? "<<" : ">>");
1445 pp_c_whitespace (pp
);
1446 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 1));
1450 pp_c_additive_expression (pp
, e
);
1454 /* relational-expression:
1456 relational-expression < shift-expression
1457 relational-expression > shift-expression
1458 relational-expression <= shift-expression
1459 relational-expression >= shift-expression */
1462 pp_c_relational_expression (c_pretty_printer
*pp
, tree e
)
1464 enum tree_code code
= TREE_CODE (e
);
1471 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 0));
1472 pp_c_whitespace (pp
);
1473 if (code
== LT_EXPR
)
1475 else if (code
== GT_EXPR
)
1477 else if (code
== LE_EXPR
)
1478 pp_identifier (pp
, "<=");
1479 else if (code
== GE_EXPR
)
1480 pp_identifier (pp
, ">=");
1481 pp_c_whitespace (pp
);
1482 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 1));
1486 pp_c_shift_expression (pp
, e
);
1491 /* equality-expression:
1492 relational-expression
1493 equality-expression == relational-expression
1494 equality-equality != relational-expression */
1497 pp_c_equality_expression (c_pretty_printer
*pp
, tree e
)
1499 enum tree_code code
= TREE_CODE (e
);
1504 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 0));
1505 pp_c_whitespace (pp
);
1506 pp_identifier (pp
, code
== EQ_EXPR
? "==" : "!=");
1507 pp_c_whitespace (pp
);
1508 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 1));
1512 pp_c_relational_expression (pp
, e
);
1519 AND-expression & equality-equality */
1522 pp_c_and_expression (c_pretty_printer
*pp
, tree e
)
1524 if (TREE_CODE (e
) == BIT_AND_EXPR
)
1526 pp_c_and_expression (pp
, TREE_OPERAND (e
, 0));
1527 pp_c_whitespace (pp
);
1529 pp_c_whitespace (pp
);
1530 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 1));
1533 pp_c_equality_expression (pp
, e
);
1536 /* exclusive-OR-expression:
1538 exclusive-OR-expression ^ AND-expression */
1541 pp_c_exclusive_or_expression (c_pretty_printer
*pp
, tree e
)
1543 if (TREE_CODE (e
) == BIT_XOR_EXPR
)
1545 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
1546 pp_c_maybe_whitespace (pp
);
1548 pp_c_whitespace (pp
);
1549 pp_c_and_expression (pp
, TREE_OPERAND (e
, 1));
1552 pp_c_and_expression (pp
, e
);
1555 /* inclusive-OR-expression:
1556 exclusive-OR-expression
1557 inclusive-OR-expression | exclusive-OR-expression */
1560 pp_c_inclusive_or_expression (c_pretty_printer
*pp
, tree e
)
1562 if (TREE_CODE (e
) == BIT_IOR_EXPR
)
1564 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
1565 pp_c_whitespace (pp
);
1567 pp_c_whitespace (pp
);
1568 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
1571 pp_c_exclusive_or_expression (pp
, e
);
1574 /* logical-AND-expression:
1575 inclusive-OR-expression
1576 logical-AND-expression && inclusive-OR-expression */
1579 pp_c_logical_and_expression (c_pretty_printer
*pp
, tree e
)
1581 if (TREE_CODE (e
) == TRUTH_ANDIF_EXPR
)
1583 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 0));
1584 pp_c_whitespace (pp
);
1585 pp_identifier (pp
, "&&");
1586 pp_c_whitespace (pp
);
1587 pp_c_inclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
1590 pp_c_inclusive_or_expression (pp
, e
);
1593 /* logical-OR-expression:
1594 logical-AND-expression
1595 logical-OR-expression || logical-AND-expression */
1598 pp_c_logical_or_expression (c_pretty_printer
*pp
, tree e
)
1600 if (TREE_CODE (e
) == TRUTH_ORIF_EXPR
)
1602 pp_c_logical_or_expression (pp
, TREE_OPERAND (e
, 0));
1603 pp_c_whitespace (pp
);
1604 pp_identifier (pp
, "||");
1605 pp_c_whitespace (pp
);
1606 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 1));
1609 pp_c_logical_and_expression (pp
, e
);
1612 /* conditional-expression:
1613 logical-OR-expression
1614 logical-OR-expression ? expression : conditional-expression */
1617 pp_c_conditional_expression (c_pretty_printer
*pp
, tree e
)
1619 if (TREE_CODE (e
) == COND_EXPR
)
1621 pp_c_logical_or_expression (pp
, TREE_OPERAND (e
, 0));
1622 pp_c_whitespace (pp
);
1624 pp_c_whitespace (pp
);
1625 pp_expression (pp
, TREE_OPERAND (e
, 1));
1626 pp_c_whitespace (pp
);
1628 pp_c_whitespace (pp
);
1629 pp_c_conditional_expression (pp
, TREE_OPERAND (e
, 2));
1632 pp_c_logical_or_expression (pp
, e
);
1636 /* assignment-expression:
1637 conditional-expression
1638 unary-expression assignment-operator assignment-expression
1640 assignment-expression: one of
1641 = *= /= %= += -= >>= <<= &= ^= |= */
1644 pp_c_assignment_expression (c_pretty_printer
*pp
, tree e
)
1646 if (TREE_CODE (e
) == MODIFY_EXPR
|| TREE_CODE (e
) == INIT_EXPR
)
1648 pp_c_unary_expression (pp
, TREE_OPERAND (e
, 0));
1649 pp_c_whitespace (pp
);
1652 pp_c_expression (pp
, TREE_OPERAND (e
, 1));
1655 pp_c_conditional_expression (pp
, e
);
1659 assignment-expression
1660 expression , assignment-expression
1662 Implementation note: instead of going through the usual recursion
1663 chain, I take the liberty of dispatching nodes to the appropriate
1664 functions. This makes some redundancy, but it worths it. That also
1665 prevents a possible infinite recursion between pp_c_primary_expression ()
1666 and pp_c_expression (). */
1669 pp_c_expression (c_pretty_printer
*pp
, tree e
)
1671 switch (TREE_CODE (e
))
1674 pp_c_integer_constant (pp
, e
);
1678 pp_c_floating_constant (pp
, e
);
1682 pp_c_string_literal (pp
, e
);
1685 case IDENTIFIER_NODE
:
1695 pp_primary_expression (pp
, e
);
1698 case POSTINCREMENT_EXPR
:
1699 case POSTDECREMENT_EXPR
:
1709 case COMPOUND_LITERAL_EXPR
:
1711 pp_postfix_expression (pp
, e
);
1719 case TRUTH_NOT_EXPR
:
1720 case PREINCREMENT_EXPR
:
1721 case PREDECREMENT_EXPR
:
1726 pp_c_unary_expression (pp
, e
);
1730 case FIX_TRUNC_EXPR
:
1732 pp_c_cast_expression (pp
, e
);
1736 case TRUNC_MOD_EXPR
:
1737 case TRUNC_DIV_EXPR
:
1738 pp_multiplicative_expression (pp
, e
);
1743 pp_c_shift_expression (pp
, e
);
1750 pp_c_relational_expression (pp
, e
);
1754 pp_c_and_expression (pp
, e
);
1758 pp_c_exclusive_or_expression (pp
, e
);
1762 pp_c_inclusive_or_expression (pp
, e
);
1765 case TRUTH_ANDIF_EXPR
:
1766 pp_c_logical_and_expression (pp
, e
);
1769 case TRUTH_ORIF_EXPR
:
1770 pp_c_logical_or_expression (pp
, e
);
1775 pp_c_equality_expression (pp
, e
);
1779 pp_conditional_expression (pp
, e
);
1784 pp_c_additive_expression (pp
, e
);
1789 pp_assignment_expression (pp
, e
);
1793 pp_c_left_paren (pp
);
1794 pp_expression (pp
, TREE_OPERAND (e
, 0));
1795 pp_separate_with (pp
, ',');
1796 pp_assignment_expression (pp
, TREE_OPERAND (e
, 1));
1797 pp_c_right_paren (pp
);
1801 case NON_LVALUE_EXPR
:
1804 pp_expression (pp
, TREE_OPERAND (e
, 0));
1808 pp_postfix_expression (pp
, TREE_OPERAND (e
, 1));
1812 pp_unsupported_tree (pp
, e
);
1824 expression-statement
1830 pp_c_statement (c_pretty_printer
*pp
, tree stmt
)
1832 enum tree_code code
;
1837 code
= TREE_CODE (stmt
);
1840 /* labeled-statement:
1841 identifier : statement
1842 case constant-expression : statement
1843 default : statement */
1846 if (pp_needs_newline (pp
))
1847 pp_newline_and_indent (pp
, -3);
1849 pp_indentation (pp
) -= 3;
1850 if (code
== LABEL_STMT
)
1851 pp_tree_identifier (pp
, DECL_NAME (LABEL_STMT_LABEL (stmt
)));
1852 else if (code
== CASE_LABEL
)
1854 if (CASE_LOW (stmt
) == NULL_TREE
)
1855 pp_identifier (pp
, "default");
1858 pp_c_identifier (pp
, "case");
1859 pp_c_whitespace (pp
);
1860 pp_conditional_expression (pp
, CASE_LOW (stmt
));
1861 if (CASE_HIGH (stmt
))
1863 pp_identifier (pp
, "...");
1864 pp_conditional_expression (pp
, CASE_HIGH (stmt
));
1869 pp_indentation (pp
) += 3;
1870 pp_needs_newline (pp
) = true;
1873 /* compound-statement:
1874 { block-item-list(opt) }
1878 block-item-list block-item
1884 if (pp_needs_newline (pp
))
1885 pp_newline_and_indent (pp
, 0);
1886 pp_c_left_brace (pp
);
1887 pp_newline_and_indent (pp
, 3);
1888 for (stmt
= COMPOUND_BODY (stmt
); stmt
; stmt
= TREE_CHAIN (stmt
))
1889 pp_statement (pp
, stmt
);
1890 pp_newline_and_indent (pp
, -3);
1891 pp_c_right_brace (pp
);
1892 pp_needs_newline (pp
) = true;
1895 /* expression-statement:
1896 expression(opt) ; */
1899 if (pp_needs_newline (pp
))
1900 pp_newline_and_indent (pp
, 0);
1902 tree e
= code
== EXPR_STMT
1903 ? EXPR_STMT_EXPR (stmt
)
1904 : CLEANUP_EXPR (stmt
);
1906 pp_expression (pp
, e
);
1908 pp_c_semicolon (pp
);
1909 pp_needs_newline (pp
) = true;
1912 /* selection-statement:
1913 if ( expression ) statement
1914 if ( expression ) statement else statement
1915 switch ( expression ) statement */
1917 if (pp_needs_newline (pp
))
1918 pp_newline_and_indent (pp
, 0);
1919 pp_c_identifier (pp
, "if");
1920 pp_c_whitespace (pp
);
1921 pp_c_left_paren (pp
);
1922 pp_expression (pp
, IF_COND (stmt
));
1923 pp_c_right_paren (pp
);
1924 pp_newline_and_indent (pp
, 3);
1925 pp_statement (pp
, THEN_CLAUSE (stmt
));
1926 pp_newline_and_indent (pp
, -3);
1927 if (ELSE_CLAUSE (stmt
))
1929 tree else_clause
= ELSE_CLAUSE (stmt
);
1930 pp_c_identifier (pp
, "else");
1931 if (TREE_CODE (else_clause
) == IF_STMT
)
1932 pp_c_whitespace (pp
);
1934 pp_newline_and_indent (pp
, 3);
1935 pp_statement (pp
, else_clause
);
1936 if (TREE_CODE (else_clause
) != IF_STMT
)
1937 pp_newline_and_indent (pp
, -3);
1942 if (pp_needs_newline (pp
))
1943 pp_newline_and_indent (pp
, 0);
1944 pp_c_identifier (pp
, "switch");
1946 pp_c_left_paren (pp
);
1947 pp_expression (pp
, SWITCH_COND (stmt
));
1948 pp_c_right_paren (pp
);
1949 pp_indentation (pp
) += 3;
1950 pp_needs_newline (pp
) = true;
1951 pp_statement (pp
, SWITCH_BODY (stmt
));
1952 pp_newline_and_indent (pp
, -3);
1955 /* iteration-statement:
1956 while ( expression ) statement
1957 do statement while ( expression ) ;
1958 for ( expression(opt) ; expression(opt) ; expression(opt) ) statement
1959 for ( declaration expression(opt) ; expression(opt) ) statement */
1961 if (pp_needs_newline (pp
))
1962 pp_newline_and_indent (pp
, 0);
1963 pp_c_identifier (pp
, "while");
1965 pp_c_left_paren (pp
);
1966 pp_expression (pp
, WHILE_COND (stmt
));
1967 pp_c_right_paren (pp
);
1968 pp_newline_and_indent (pp
, 3);
1969 pp_statement (pp
, WHILE_BODY (stmt
));
1970 pp_indentation (pp
) -= 3;
1971 pp_needs_newline (pp
) = true;
1975 if (pp_needs_newline (pp
))
1976 pp_newline_and_indent (pp
, 0);
1977 pp_c_identifier (pp
, "do");
1978 pp_newline_and_indent (pp
, 3);
1979 pp_statement (pp
, DO_BODY (stmt
));
1980 pp_newline_and_indent (pp
, -3);
1981 pp_c_identifier (pp
, "while");
1983 pp_c_left_paren (pp
);
1984 pp_expression (pp
, DO_COND (stmt
));
1985 pp_c_right_paren (pp
);
1986 pp_c_semicolon (pp
);
1987 pp_needs_newline (pp
) = true;
1991 if (pp_needs_newline (pp
))
1992 pp_newline_and_indent (pp
, 0);
1993 pp_c_identifier (pp
, "for");
1995 pp_c_left_paren (pp
);
1996 if (FOR_INIT_STMT (stmt
))
1997 pp_statement (pp
, FOR_INIT_STMT (stmt
));
1999 pp_c_semicolon (pp
);
2000 pp_needs_newline (pp
) = false;
2001 pp_c_whitespace (pp
);
2002 if (FOR_COND (stmt
))
2003 pp_expression (pp
, FOR_COND (stmt
));
2004 pp_c_semicolon (pp
);
2005 pp_needs_newline (pp
) = false;
2006 pp_c_whitespace (pp
);
2007 if (FOR_EXPR (stmt
))
2008 pp_expression (pp
, FOR_EXPR (stmt
));
2009 pp_c_right_paren (pp
);
2010 pp_newline_and_indent (pp
, 3);
2011 pp_statement (pp
, FOR_BODY (stmt
));
2012 pp_indentation (pp
) -= 3;
2013 pp_needs_newline (pp
) = true;
2019 return expression(opt) ; */
2022 if (pp_needs_newline (pp
))
2023 pp_newline_and_indent (pp
, 0);
2024 pp_identifier (pp
, code
== BREAK_STMT
? "break" : "continue");
2025 pp_c_semicolon (pp
);
2026 pp_needs_newline (pp
) = true;
2032 tree e
= code
== RETURN_STMT
2033 ? RETURN_STMT_EXPR (stmt
)
2034 : GOTO_DESTINATION (stmt
);
2035 if (pp_needs_newline (pp
))
2036 pp_newline_and_indent (pp
, 0);
2037 pp_c_identifier (pp
, code
== RETURN_STMT
? "return" : "goto");
2038 pp_c_whitespace (pp
);
2041 if (TREE_CODE (e
) == INIT_EXPR
2042 && TREE_CODE (TREE_OPERAND (e
, 0)) == RESULT_DECL
)
2043 e
= TREE_OPERAND (e
, 1);
2044 pp_expression (pp
, e
);
2046 pp_c_semicolon (pp
);
2047 pp_needs_newline (pp
) = true;
2052 if (!SCOPE_NULLIFIED_P (stmt
) && SCOPE_NO_CLEANUPS_P (stmt
))
2055 if (pp_needs_newline (pp
))
2056 pp_newline_and_indent (pp
, 0);
2057 if (SCOPE_BEGIN_P (stmt
))
2062 else if (SCOPE_END_P (stmt
))
2064 pp_right_brace (pp
);
2067 pp_indentation (pp
) += i
;
2068 pp_needs_newline (pp
) = true;
2073 if (pp_needs_newline (pp
))
2074 pp_newline_and_indent (pp
, 0);
2075 pp_declaration (pp
, DECL_STMT_DECL (stmt
));
2076 pp_needs_newline (pp
) = true;
2081 bool has_volatile_p
= ASM_VOLATILE_P (stmt
);
2082 bool is_extended
= has_volatile_p
|| ASM_INPUTS (stmt
)
2083 || ASM_OUTPUTS (stmt
) || ASM_CLOBBERS (stmt
);
2084 pp_c_identifier (pp
, is_extended
? "__asm__" : "asm");
2086 pp_c_identifier (pp
, "__volatile__");
2088 pp_c_left_paren (pp
);
2089 pp_c_string_literal (pp
, ASM_STRING (stmt
));
2093 pp_separate_with (pp
, ':');
2094 if (ASM_OUTPUTS (stmt
))
2095 pp_expression (pp
, ASM_OUTPUTS (stmt
));
2097 pp_separate_with (pp
, ':');
2098 if (ASM_INPUTS (stmt
))
2099 pp_expression (pp
, ASM_INPUTS (stmt
));
2101 pp_separate_with (pp
, ':');
2102 if (ASM_CLOBBERS (stmt
))
2103 pp_expression (pp
, ASM_CLOBBERS (stmt
));
2105 pp_c_right_paren (pp
);
2111 pp_c_identifier (pp
, "__FILE__");
2114 pp_c_whitespace (pp
);
2115 pp_c_identifier (pp
, FILE_STMT_FILENAME (stmt
));
2116 pp_c_semicolon (pp
);
2117 pp_needs_newline (pp
) = true;
2121 pp_unsupported_tree (pp
, stmt
);
2126 /* Initialize the PRETTY-PRINTER for handling C codes. */
2129 pp_c_pretty_printer_init (c_pretty_printer
*pp
)
2131 pp
->offset_list
= 0;
2133 pp
->declaration
= pp_c_declaration
;
2134 pp
->declaration_specifiers
= pp_c_declaration_specifiers
;
2135 pp
->declarator
= pp_c_declarator
;
2136 pp
->direct_declarator
= pp_c_direct_declarator
;
2137 pp
->type_specifier_seq
= pp_c_specifier_qualifier_list
;
2138 pp
->abstract_declarator
= pp_c_abstract_declarator
;
2139 pp
->direct_abstract_declarator
= pp_c_direct_abstract_declarator
;
2140 pp
->ptr_operator
= pp_c_pointer
;
2141 pp
->parameter_list
= pp_c_parameter_type_list
;
2142 pp
->type_id
= pp_c_type_id
;
2143 pp
->simple_type_specifier
= pp_c_type_specifier
;
2144 pp
->function_specifier
= pp_c_function_specifier
;
2145 pp
->storage_class_specifier
= pp_c_storage_class_specifier
;
2147 pp
->statement
= pp_c_statement
;
2149 pp
->id_expression
= pp_c_id_expression
;
2150 pp
->primary_expression
= pp_c_primary_expression
;
2151 pp
->postfix_expression
= pp_c_postfix_expression
;
2152 pp
->unary_expression
= pp_c_unary_expression
;
2153 pp
->initializer
= pp_c_initializer
;
2154 pp
->multiplicative_expression
= pp_c_multiplicative_expression
;
2155 pp
->conditional_expression
= pp_c_conditional_expression
;
2156 pp
->assignment_expression
= pp_c_assignment_expression
;
2157 pp
->expression
= pp_c_expression
;