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
;
149 /* Print out the external representation of CV-QUALIFIER. */
152 pp_c_cv_qualifier (c_pretty_printer
*pp
, const char *cv
)
154 const char *p
= pp_last_position_in_text (pp
);
155 /* The C programming language does not have references, but it is much
156 simpler to handle those here rather than going through the same
157 logic in the C++ pretty-printer. */
158 if (p
!= NULL
&& (*p
== '*' || *p
== '&'))
159 pp_c_whitespace (pp
);
160 pp_c_identifier (pp
, cv
);
163 /* Pretty-print T using the type-cast notation '( type-name )'. */
166 pp_c_type_cast (c_pretty_printer
*pp
, tree t
)
168 pp_c_left_paren (pp
);
170 pp_c_right_paren (pp
);
173 /* We're about to pretty-print a pointer type as indicated by T.
174 Output a whitespace, if needed, preparing for subsequent output. */
177 pp_c_space_for_pointer_operator (c_pretty_printer
*pp
, tree t
)
179 if (POINTER_TYPE_P (t
))
181 tree pointee
= strip_pointer_operator (TREE_TYPE (t
));
182 if (TREE_CODE (pointee
) != ARRAY_TYPE
183 && TREE_CODE (pointee
) != FUNCTION_TYPE
)
184 pp_c_whitespace (pp
);
191 /* C++ cv-qualifiers are called type-qualifiers in C. Print out the
192 cv-qualifiers of T. If T is a declaration then it is the cv-qualifier
193 of its type. Take care of possible extensions.
197 type-qualifier-list type-qualifier
202 __restrict__ -- GNU C
206 pp_c_type_qualifier_list (c_pretty_printer
*pp
, tree t
)
213 qualifiers
= TYPE_QUALS (t
);
214 if (qualifiers
& TYPE_QUAL_CONST
)
215 pp_c_cv_qualifier (pp
, "const");
216 if (qualifiers
& TYPE_QUAL_VOLATILE
)
217 pp_c_cv_qualifier (pp
, "volatile");
218 if (qualifiers
& TYPE_QUAL_RESTRICT
)
219 pp_c_cv_qualifier (pp
, flag_isoc99
? "restrict" : "__restrict__");
223 * type-qualifier-list(opt)
224 * type-qualifier-list(opt) pointer */
227 pp_c_pointer (c_pretty_printer
*pp
, tree t
)
229 if (!TYPE_P (t
) && TREE_CODE (t
) != TYPE_DECL
)
231 switch (TREE_CODE (t
))
234 /* It is easier to handle C++ reference types here. */
236 if (TREE_CODE (TREE_TYPE (t
)) == POINTER_TYPE
)
237 pp_c_pointer (pp
, TREE_TYPE (t
));
238 if (TREE_CODE (t
) == POINTER_TYPE
)
242 pp_c_type_qualifier_list (pp
, t
);
246 pp_unsupported_tree (pp
, t
);
263 struct-or-union-specifier
268 simple-type-specifier:
273 pp_c_type_specifier (c_pretty_printer
*pp
, tree t
)
275 const enum tree_code code
= TREE_CODE (t
);
279 pp_c_identifier (pp
, "<type-error>");
282 case IDENTIFIER_NODE
:
283 pp_c_tree_identifier (pp
, t
);
294 t
= c_common_type_for_mode (TYPE_MODE (t
), TYPE_UNSIGNED (t
));
295 pp_c_type_specifier (pp
, t
);
300 pp_id_expression (pp
, t
);
302 pp_c_identifier (pp
, "<typedef-error>");
308 if (code
== UNION_TYPE
)
309 pp_c_identifier (pp
, "union");
310 else if (code
== RECORD_TYPE
)
311 pp_c_identifier (pp
, "struct");
312 else if (code
== ENUMERAL_TYPE
)
313 pp_c_identifier (pp
, "enum");
315 pp_c_identifier (pp
, "<tag-error>");
318 pp_id_expression (pp
, TYPE_NAME (t
));
320 pp_c_identifier (pp
, "<anonymous>");
324 pp_unsupported_tree (pp
, t
);
329 /* specifier-qualifier-list:
330 type-specifier specifier-qualifier-list-opt
331 type-qualifier specifier-qualifier-list-opt
334 Implementation note: Because of the non-linearities in array or
335 function declarations, this routine prints not just the
336 specifier-qualifier-list of such entities or types of such entities,
337 but also the 'pointer' production part of their declarators. The
338 remaining part is done by pp_declarator or pp_c_abstract_declarator. */
341 pp_c_specifier_qualifier_list (c_pretty_printer
*pp
, tree t
)
343 const enum tree_code code
= TREE_CODE (t
);
345 if (TREE_CODE (t
) != POINTER_TYPE
)
346 pp_c_type_qualifier_list (pp
, t
);
352 /* Get the types-specifier of this type. */
353 tree pointee
= strip_pointer_operator (TREE_TYPE (t
));
354 pp_c_specifier_qualifier_list (pp
, pointee
);
355 if (TREE_CODE (pointee
) == ARRAY_TYPE
356 || TREE_CODE (pointee
) == FUNCTION_TYPE
)
358 pp_c_whitespace (pp
);
359 pp_c_left_paren (pp
);
361 pp_ptr_operator (pp
, t
);
367 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
372 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
373 if (code
== COMPLEX_TYPE
)
374 pp_c_identifier (pp
, flag_isoc99
? "_Complex" : "__complex__");
375 else if (code
== VECTOR_TYPE
)
376 pp_c_identifier (pp
, "__vector__");
380 pp_simple_type_specifier (pp
, t
);
385 /* parameter-type-list:
390 parameter-declaration
391 parameter-list , parameter-declaration
393 parameter-declaration:
394 declaration-specifiers declarator
395 declaration-specifiers abstract-declarator(opt) */
398 pp_c_parameter_type_list (c_pretty_printer
*pp
, tree t
)
400 bool want_parm_decl
= DECL_P (t
) && !(pp
->flags
& pp_c_flag_abstract
);
401 tree parms
= want_parm_decl
? DECL_ARGUMENTS (t
) : TYPE_ARG_TYPES (t
);
402 pp_c_left_paren (pp
);
403 if (parms
== void_list_node
)
404 pp_c_identifier (pp
, "void");
408 for ( ; parms
&& parms
!= void_list_node
; parms
= TREE_CHAIN (parms
))
411 pp_separate_with (pp
, ',');
413 pp_declaration_specifiers
414 (pp
, want_parm_decl
? parms
: TREE_VALUE (parms
));
416 pp_declarator (pp
, parms
);
418 pp_abstract_declarator (pp
, TREE_VALUE (parms
));
421 pp_c_right_paren (pp
);
424 /* abstract-declarator:
426 pointer(opt) direct-abstract-declarator */
429 pp_c_abstract_declarator (c_pretty_printer
*pp
, tree t
)
431 if (TREE_CODE (t
) == POINTER_TYPE
)
433 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
434 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
435 pp_c_right_paren (pp
);
439 pp_direct_abstract_declarator (pp
, t
);
442 /* direct-abstract-declarator:
443 ( abstract-declarator )
444 direct-abstract-declarator(opt) [ assignment-expression(opt) ]
445 direct-abstract-declarator(opt) [ * ]
446 direct-abstract-declarator(opt) ( parameter-type-list(opt) ) */
449 pp_c_direct_abstract_declarator (c_pretty_printer
*pp
, tree t
)
451 switch (TREE_CODE (t
))
454 pp_abstract_declarator (pp
, t
);
458 pp_c_parameter_type_list (pp
, t
);
459 pp_direct_abstract_declarator (pp
, TREE_TYPE (t
));
463 pp_c_left_bracket (pp
);
465 pp_expression (pp
, TYPE_MAX_VALUE (TYPE_DOMAIN (t
)));
466 pp_c_right_bracket (pp
);
467 pp_direct_abstract_declarator (pp
, TREE_TYPE (t
));
470 case IDENTIFIER_NODE
:
484 pp_unsupported_tree (pp
, t
);
490 specifier-qualifier-list abstract-declarator(opt) */
493 pp_c_type_id (c_pretty_printer
*pp
, tree t
)
495 pp_c_specifier_qualifier_list (pp
, t
);
496 pp_abstract_declarator (pp
, t
);
499 /* storage-class-specifier:
507 pp_c_storage_class_specifier (c_pretty_printer
*pp
, tree t
)
509 if (TREE_CODE (t
) == TYPE_DECL
)
510 pp_c_identifier (pp
, "typedef");
513 if (DECL_REGISTER (t
))
514 pp_c_identifier (pp
, "register");
515 else if (TREE_STATIC (t
) && TREE_CODE (t
) == VAR_DECL
)
516 pp_c_identifier (pp
, "static");
520 /* function-specifier:
524 pp_c_function_specifier (c_pretty_printer
*pp
, tree t
)
526 if (TREE_CODE (t
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (t
))
527 pp_c_identifier (pp
, "inline");
530 /* declaration-specifiers:
531 storage-class-specifier declaration-specifiers(opt)
532 type-specifier declaration-specifiers(opt)
533 type-qualifier declaration-specifiers(opt)
534 function-specifier declaration-specifiers(opt) */
537 pp_c_declaration_specifiers (c_pretty_printer
*pp
, tree t
)
539 pp_storage_class_specifier (pp
, t
);
540 pp_function_specifier (pp
, t
);
541 pp_c_specifier_qualifier_list (pp
, DECL_P (t
) ? TREE_TYPE (t
) : t
);
547 direct-declarator [ type-qualifier-list(opt) assignment-expression(opt) ]
548 direct-declarator [ static type-qualifier-list(opt) assignment-expression(opt)]
549 direct-declarator [ type-qualifier-list static assignment-expression ]
550 direct-declarator [ type-qualifier-list * ]
551 direct-declarator ( parameter-type-list )
552 direct-declarator ( identifier-list(opt) ) */
555 pp_c_direct_declarator (c_pretty_printer
*pp
, tree t
)
557 switch (TREE_CODE (t
))
566 pp_c_space_for_pointer_operator (pp
, TREE_TYPE (t
));
567 pp_c_tree_identifier (pp
, DECL_NAME (t
));
571 pp_abstract_declarator (pp
, TREE_TYPE (t
));
575 pp_parameter_list (pp
, t
);
576 pp_abstract_declarator (pp
, TREE_TYPE (t
));
580 pp_c_space_for_pointer_operator (pp
, TREE_TYPE (TREE_TYPE (t
)));
581 pp_c_tree_identifier (pp
, DECL_NAME (t
));
582 if (pp_c_base (pp
)->flags
& pp_c_flag_abstract
)
583 pp_abstract_declarator (pp
, TREE_TYPE (t
));
586 pp_parameter_list (pp
, t
);
587 pp_abstract_declarator (pp
, TREE_TYPE (TREE_TYPE (t
)));
599 pp_unsupported_tree (pp
, t
);
606 pointer(opt) direct-declarator */
609 pp_c_declarator (c_pretty_printer
*pp
, tree t
)
611 switch (TREE_CODE (t
))
627 pp_direct_declarator (pp
, t
);
632 pp_unsupported_tree (pp
, t
);
638 declaration-specifiers init-declarator-list(opt) ; */
641 pp_c_declaration (c_pretty_printer
*pp
, tree t
)
643 pp_declaration_specifiers (pp
, t
);
644 pp_c_init_declarator (pp
, t
);
647 /* Pretty-print ATTRIBUTES using GNU C extension syntax. */
650 pp_c_attributes (c_pretty_printer
*pp
, tree attributes
)
652 if (attributes
== NULL_TREE
)
655 pp_c_identifier (pp
, "__attribute__");
656 pp_c_left_paren (pp
);
657 pp_c_left_paren (pp
);
658 for (; attributes
!= NULL_TREE
; attributes
= TREE_CHAIN (attributes
))
660 pp_tree_identifier (pp
, TREE_PURPOSE (attributes
));
661 if (TREE_VALUE (attributes
))
662 pp_c_call_argument_list (pp
, TREE_VALUE (attributes
));
664 if (TREE_CHAIN (attributes
))
665 pp_separate_with (pp
, ',');
667 pp_c_right_paren (pp
);
668 pp_c_right_paren (pp
);
671 /* function-definition:
672 declaration-specifiers declarator compound-statement */
675 pp_c_function_definition (c_pretty_printer
*pp
, tree t
)
677 pp_declaration_specifiers (pp
, t
);
678 pp_declarator (pp
, t
);
679 pp_needs_newline (pp
) = true;
680 pp_statement (pp
, DECL_SAVED_TREE (t
));
688 /* Print out a c-char. */
691 pp_c_char (c_pretty_printer
*pp
, int c
)
696 pp_string (pp
, "\\n");
699 pp_string (pp
, "\\t");
702 pp_string (pp
, "\\v");
705 pp_string (pp
, "\\b");
708 pp_string (pp
, "\\r");
711 pp_string (pp
, "\\f");
714 pp_string (pp
, "\\a");
717 pp_string (pp
, "\\\\");
720 pp_string (pp
, "\\'");
723 pp_string (pp
, "\\\"");
727 pp_character (pp
, c
);
729 pp_scalar (pp
, "\\%03o", (unsigned) c
);
734 /* Print out a STRING literal. */
737 pp_c_string_literal (c_pretty_printer
*pp
, tree s
)
739 const char *p
= TREE_STRING_POINTER (s
);
740 int n
= TREE_STRING_LENGTH (s
) - 1;
743 for (i
= 0; i
< n
; ++i
)
744 pp_c_char (pp
, p
[i
]);
748 /* Pretty-print an INTEGER literal. */
751 pp_c_integer_constant (c_pretty_printer
*pp
, tree i
)
753 tree type
= TREE_TYPE (i
);
755 if (TREE_INT_CST_HIGH (i
) == 0)
756 pp_wide_integer (pp
, TREE_INT_CST_LOW (i
));
759 if (tree_int_cst_sgn (i
) < 0)
762 i
= build_int_2 (-TREE_INT_CST_LOW (i
),
763 ~TREE_INT_CST_HIGH (i
) + !TREE_INT_CST_LOW (i
));
765 sprintf (pp_buffer (pp
)->digit_buffer
,
766 HOST_WIDE_INT_PRINT_DOUBLE_HEX
,
767 TREE_INT_CST_HIGH (i
), TREE_INT_CST_LOW (i
));
768 pp_string (pp
, pp_buffer (pp
)->digit_buffer
);
770 if (TYPE_UNSIGNED (type
))
771 pp_character (pp
, 'u');
772 if (type
== long_integer_type_node
|| type
== long_unsigned_type_node
)
773 pp_character (pp
, 'l');
774 else if (type
== long_long_integer_type_node
775 || type
== long_long_unsigned_type_node
)
776 pp_string (pp
, "ll");
779 /* Print out a CHARACTER literal. */
782 pp_c_character_constant (c_pretty_printer
*pp
, tree c
)
784 tree type
= TREE_TYPE (c
);
785 if (type
== wchar_type_node
)
786 pp_character (pp
, 'L');
788 if (host_integerp (c
, TYPE_UNSIGNED (type
)))
789 pp_c_char (pp
, tree_low_cst (c
, TYPE_UNSIGNED (type
)));
791 pp_scalar (pp
, "\\x%x", (unsigned) TREE_INT_CST_LOW (c
));
795 /* Print out a BOOLEAN literal. */
798 pp_c_bool_constant (c_pretty_printer
*pp
, tree b
)
800 if (b
== boolean_false_node
)
802 if (c_dialect_cxx ())
803 pp_c_identifier (pp
, "false");
804 else if (flag_isoc99
)
805 pp_c_identifier (pp
, "_False");
807 pp_unsupported_tree (pp
, b
);
809 else if (b
== boolean_true_node
)
811 if (c_dialect_cxx ())
812 pp_c_identifier (pp
, "true");
813 else if (flag_isoc99
)
814 pp_c_identifier (pp
, "_True");
816 pp_unsupported_tree (pp
, b
);
818 else if (TREE_CODE (b
) == INTEGER_CST
)
819 pp_c_integer_constant (pp
, b
);
821 pp_unsupported_tree (pp
, b
);
824 /* Attempt to print out an ENUMERATOR. Return true on success. Else return
825 false; that means the value was obtained by a cast, in which case
826 print out the type-id part of the cast-expression -- the casted value
827 is then printed by pp_c_integer_literal. */
830 pp_c_enumeration_constant (c_pretty_printer
*pp
, tree e
)
832 bool value_is_named
= true;
833 tree type
= TREE_TYPE (e
);
836 /* Find the name of this constant. */
837 for (value
= TYPE_VALUES (type
);
838 value
!= NULL_TREE
&& !tree_int_cst_equal (TREE_VALUE (value
), e
);
839 value
= TREE_CHAIN (value
))
842 if (value
!= NULL_TREE
)
843 pp_id_expression (pp
, TREE_PURPOSE (value
));
846 /* Value must have been cast. */
847 pp_c_type_cast (pp
, type
);
848 value_is_named
= false;
851 return value_is_named
;
854 /* Print out a REAL value as a decimal-floating-constant. */
857 pp_c_floating_constant (c_pretty_printer
*pp
, tree r
)
859 real_to_decimal (pp_buffer (pp
)->digit_buffer
, &TREE_REAL_CST (r
),
860 sizeof (pp_buffer (pp
)->digit_buffer
), 0, 1);
861 pp_string (pp
, pp_buffer(pp
)->digit_buffer
);
862 if (TREE_TYPE (r
) == float_type_node
)
863 pp_character (pp
, 'f');
864 else if (TREE_TYPE (r
) == long_double_type_node
)
865 pp_character (pp
, 'l');
868 /* Pretty-print a compound literal expression. GNU extensions include
872 pp_c_compound_literal (c_pretty_printer
*pp
, tree e
)
874 tree type
= TREE_TYPE (e
);
875 pp_c_type_cast (pp
, type
);
877 switch (TREE_CODE (type
))
884 pp_c_brace_enclosed_initializer_list (pp
, e
);
888 pp_unsupported_tree (pp
, e
);
897 character-constant */
900 pp_c_constant (c_pretty_printer
*pp
, tree e
)
902 const enum tree_code code
= TREE_CODE (e
);
908 tree type
= TREE_TYPE (e
);
909 if (type
== boolean_type_node
)
910 pp_c_bool_constant (pp
, e
);
911 else if (type
== char_type_node
)
912 pp_c_character_constant (pp
, e
);
913 else if (TREE_CODE (type
) == ENUMERAL_TYPE
914 && pp_c_enumeration_constant (pp
, e
))
917 pp_c_integer_constant (pp
, e
);
922 pp_c_floating_constant (pp
, e
);
926 pp_c_string_literal (pp
, e
);
930 pp_unsupported_tree (pp
, e
);
935 /* Pretty-print an IDENTIFIER_NODE, preceded by whitespace is necessary. */
938 pp_c_identifier (c_pretty_printer
*pp
, const char *id
)
940 pp_c_maybe_whitespace (pp
);
941 pp_identifier (pp
, id
);
942 pp_base (pp
)->padding
= pp_before
;
945 /* Pretty-print a C primary-expression.
953 pp_c_primary_expression (c_pretty_printer
*pp
, tree e
)
955 switch (TREE_CODE (e
))
965 case IDENTIFIER_NODE
:
966 pp_c_tree_identifier (pp
, e
);
970 pp_c_identifier (pp
, "<erroneous-expression>");
974 pp_c_identifier (pp
, "<return-value>");
980 pp_c_constant (pp
, e
);
984 pp_c_left_paren (pp
);
985 pp_statement (pp
, STMT_EXPR_STMT (e
));
986 pp_c_right_paren (pp
);
990 /* FIXME: Make sure we won't get into an infinie loop. */
991 pp_c_left_paren (pp
);
992 pp_expression (pp
, e
);
993 pp_c_right_paren (pp
);
998 /* Print out a C initializer -- also support C compound-literals.
1000 assignment-expression:
1001 { initializer-list }
1002 { initializer-list , } */
1005 pp_c_initializer (c_pretty_printer
*pp
, tree e
)
1007 if (TREE_CODE (e
) == CONSTRUCTOR
)
1009 enum tree_code code
= TREE_CODE (TREE_TYPE (e
));
1010 if (code
== RECORD_TYPE
|| code
== UNION_TYPE
|| code
== ARRAY_TYPE
)
1011 pp_c_brace_enclosed_initializer_list (pp
, e
);
1013 pp_unsupported_tree (pp
, TREE_OPERAND (e
, 1));
1016 pp_expression (pp
, e
);
1021 declarator = initializer */
1024 pp_c_init_declarator (c_pretty_printer
*pp
, tree t
)
1026 pp_declarator (pp
, t
);
1027 /* We don't want to output function definitions here. There are handled
1028 elsewhere (and the syntactic form is bogus anyway). */
1029 if (TREE_CODE (t
) != FUNCTION_DECL
&& DECL_INITIAL (t
))
1031 tree init
= DECL_INITIAL (t
);
1032 /* This C++ bit is handled here because it is easier to do so.
1033 In templates, the C++ parser builds a TREE_LIST for a
1034 direct-initialization; the TREE_PURPOSE is the variable to
1035 initialize and the TREE_VALUE is the initializer. */
1036 if (TREE_CODE (init
) == TREE_LIST
)
1038 pp_c_left_paren (pp
);
1039 pp_expression (pp
, TREE_VALUE (init
));
1040 pp_right_paren (pp
);
1047 pp_c_initializer (pp
, init
);
1052 /* initializer-list:
1053 designation(opt) initializer
1054 initializer-list , designation(opt) initializer
1061 designator-list designator
1064 [ constant-expression ]
1068 pp_c_initializer_list (c_pretty_printer
*pp
, tree e
)
1070 tree type
= TREE_TYPE (e
);
1071 const enum tree_code code
= TREE_CODE (type
);
1079 tree init
= TREE_OPERAND (e
, 0);
1080 for (; init
!= NULL_TREE
; init
= TREE_CHAIN (init
))
1082 if (code
== RECORD_TYPE
|| code
== UNION_TYPE
)
1085 pp_c_primary_expression (pp
, TREE_PURPOSE (init
));
1089 pp_c_left_bracket (pp
);
1090 if (TREE_PURPOSE (init
))
1091 pp_c_constant (pp
, TREE_PURPOSE (init
));
1092 pp_c_right_bracket (pp
);
1094 pp_c_whitespace (pp
);
1096 pp_c_whitespace (pp
);
1097 pp_initializer (pp
, TREE_VALUE (init
));
1098 if (TREE_CHAIN (init
))
1099 pp_separate_with (pp
, ',');
1105 pp_c_expression_list (pp
, TREE_VECTOR_CST_ELTS (e
));
1110 const bool cst
= TREE_CODE (e
) == COMPLEX_CST
;
1111 pp_expression (pp
, cst
? TREE_REALPART (e
) : TREE_OPERAND (e
, 0));
1112 pp_separate_with (pp
, ',');
1113 pp_expression (pp
, cst
? TREE_IMAGPART (e
) : TREE_OPERAND (e
, 1));
1118 pp_unsupported_tree (pp
, type
);
1123 /* Pretty-print a brace-enclosed initializer-list. */
1126 pp_c_brace_enclosed_initializer_list (c_pretty_printer
*pp
, tree l
)
1128 pp_c_left_brace (pp
);
1129 pp_c_initializer_list (pp
, l
);
1130 pp_c_right_brace (pp
);
1134 /* This is a convenient function, used to bridge gap between C and C++
1141 pp_c_id_expression (c_pretty_printer
*pp
, tree t
)
1143 switch (TREE_CODE (t
))
1153 case IDENTIFIER_NODE
:
1154 pp_c_tree_identifier (pp
, t
);
1158 pp_unsupported_tree (pp
, t
);
1163 /* postfix-expression:
1165 postfix-expression [ expression ]
1166 postfix-expression ( argument-expression-list(opt) )
1167 postfix-expression . identifier
1168 postfix-expression -> identifier
1169 postfix-expression ++
1170 postfix-expression --
1171 ( type-name ) { initializer-list }
1172 ( type-name ) { initializer-list , } */
1175 pp_c_postfix_expression (c_pretty_printer
*pp
, tree e
)
1177 enum tree_code code
= TREE_CODE (e
);
1180 case POSTINCREMENT_EXPR
:
1181 case POSTDECREMENT_EXPR
:
1182 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1183 pp_identifier (pp
, code
== POSTINCREMENT_EXPR
? "++" : "--");
1187 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1192 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1193 pp_c_left_bracket (pp
);
1194 pp_expression (pp
, TREE_OPERAND (e
, 1));
1195 pp_c_right_bracket (pp
);
1199 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1200 pp_c_call_argument_list (pp
, TREE_OPERAND (e
, 1));
1204 pp_c_identifier (pp
, "__builtin_abs");
1205 pp_c_left_paren (pp
);
1206 pp_expression (pp
, TREE_OPERAND (e
, 0));
1207 pp_c_right_paren (pp
);
1212 tree object
= TREE_OPERAND (e
, 0);
1213 if (TREE_CODE (object
) == INDIRECT_REF
)
1215 pp_postfix_expression (pp
, TREE_OPERAND (object
, 0));
1220 pp_postfix_expression (pp
, object
);
1223 pp_expression (pp
, TREE_OPERAND (e
, 1));
1230 pp_c_compound_literal (pp
, e
);
1233 case COMPOUND_LITERAL_EXPR
:
1234 e
= DECL_INITIAL (COMPOUND_LITERAL_EXPR_DECL (e
));
1237 pp_initializer (pp
, e
);
1241 pp_c_identifier (pp
, "__builtin_va_arg");
1242 pp_c_left_paren (pp
);
1243 pp_assignment_expression (pp
, TREE_OPERAND (e
, 0));
1244 pp_separate_with (pp
, ',');
1245 pp_type_id (pp
, TREE_TYPE (e
));
1246 pp_c_right_paren (pp
);
1250 if (TREE_CODE (TREE_OPERAND (e
, 0)) == FUNCTION_DECL
)
1252 pp_c_id_expression (pp
, TREE_OPERAND (e
, 0));
1255 /* else fall through. */
1258 pp_primary_expression (pp
, e
);
1263 /* Print out an expression-list; E is expected to be a TREE_LIST. */
1266 pp_c_expression_list (c_pretty_printer
*pp
, tree e
)
1268 for (; e
!= NULL_TREE
; e
= TREE_CHAIN (e
))
1270 pp_expression (pp
, TREE_VALUE (e
));
1272 pp_separate_with (pp
, ',');
1276 /* Print out an expression-list in parens, as in a function call. */
1279 pp_c_call_argument_list (c_pretty_printer
*pp
, tree t
)
1281 pp_c_left_paren (pp
);
1282 if (t
&& TREE_CODE (t
) == TREE_LIST
)
1283 pp_c_expression_list (pp
, t
);
1284 pp_c_right_paren (pp
);
1287 /* unary-expression:
1291 unary-operator cast-expression
1292 sizeof unary-expression
1295 unary-operator: one of
1300 __alignof__ unary-expression
1301 __alignof__ ( type-id )
1302 __real__ unary-expression
1303 __imag__ unary-expression */
1306 pp_c_unary_expression (c_pretty_printer
*pp
, tree e
)
1308 enum tree_code code
= TREE_CODE (e
);
1311 case PREINCREMENT_EXPR
:
1312 case PREDECREMENT_EXPR
:
1313 pp_identifier (pp
, code
== PREINCREMENT_EXPR
? "++" : "--");
1314 pp_c_unary_expression (pp
, TREE_OPERAND (e
, 0));
1321 case TRUTH_NOT_EXPR
:
1323 /* String literal are used by address. */
1324 if (code
== ADDR_EXPR
&& TREE_CODE (TREE_OPERAND (e
, 0)) != STRING_CST
)
1326 else if (code
== INDIRECT_REF
)
1328 else if (code
== NEGATE_EXPR
)
1330 else if (code
== BIT_NOT_EXPR
|| code
== CONJ_EXPR
)
1332 else if (code
== TRUTH_NOT_EXPR
)
1333 pp_exclamation (pp
);
1334 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 0));
1339 pp_c_identifier (pp
, code
== SIZEOF_EXPR
? "sizeof" : "__alignof__");
1340 pp_c_whitespace (pp
);
1341 if (TYPE_P (TREE_OPERAND (e
, 0)))
1342 pp_c_type_cast (pp
, TREE_OPERAND (e
, 0));
1344 pp_unary_expression (pp
, TREE_OPERAND (e
, 0));
1349 pp_c_identifier (pp
, code
== REALPART_EXPR
? "__real__" : "__imag__");
1350 pp_c_whitespace (pp
);
1351 pp_unary_expression (pp
, TREE_OPERAND (e
, 0));
1355 pp_postfix_expression (pp
, e
);
1362 ( type-name ) cast-expression */
1365 pp_c_cast_expression (c_pretty_printer
*pp
, tree e
)
1367 switch (TREE_CODE (e
))
1370 case FIX_TRUNC_EXPR
:
1372 pp_c_type_cast (pp
, TREE_TYPE (e
));
1373 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 0));
1377 pp_unary_expression (pp
, e
);
1381 /* multiplicative-expression:
1383 multiplicative-expression * cast-expression
1384 multiplicative-expression / cast-expression
1385 multiplicative-expression % cast-expression */
1388 pp_c_multiplicative_expression (c_pretty_printer
*pp
, tree e
)
1390 enum tree_code code
= TREE_CODE (e
);
1394 case TRUNC_DIV_EXPR
:
1395 case TRUNC_MOD_EXPR
:
1396 pp_multiplicative_expression (pp
, TREE_OPERAND (e
, 0));
1397 pp_c_whitespace (pp
);
1398 if (code
== MULT_EXPR
)
1400 else if (code
== TRUNC_DIV_EXPR
)
1404 pp_c_whitespace (pp
);
1405 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 1));
1409 pp_c_cast_expression (pp
, e
);
1414 /* additive-expression:
1415 multiplicative-expression
1416 additive-expression + multiplicative-expression
1417 additive-expression - multiplicative-expression */
1420 pp_c_additive_expression (c_pretty_printer
*pp
, tree e
)
1422 enum tree_code code
= TREE_CODE (e
);
1427 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 0));
1428 pp_c_whitespace (pp
);
1429 if (code
== PLUS_EXPR
)
1433 pp_c_whitespace (pp
);
1434 pp_multiplicative_expression (pp
, TREE_OPERAND (e
, 1));
1438 pp_multiplicative_expression (pp
, e
);
1443 /* additive-expression:
1445 shift-expression << additive-expression
1446 shift-expression >> additive-expression */
1449 pp_c_shift_expression (c_pretty_printer
*pp
, tree e
)
1451 enum tree_code code
= TREE_CODE (e
);
1456 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 0));
1457 pp_c_whitespace (pp
);
1458 pp_identifier (pp
, code
== LSHIFT_EXPR
? "<<" : ">>");
1459 pp_c_whitespace (pp
);
1460 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 1));
1464 pp_c_additive_expression (pp
, e
);
1468 /* relational-expression:
1470 relational-expression < shift-expression
1471 relational-expression > shift-expression
1472 relational-expression <= shift-expression
1473 relational-expression >= shift-expression */
1476 pp_c_relational_expression (c_pretty_printer
*pp
, tree e
)
1478 enum tree_code code
= TREE_CODE (e
);
1485 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 0));
1486 pp_c_whitespace (pp
);
1487 if (code
== LT_EXPR
)
1489 else if (code
== GT_EXPR
)
1491 else if (code
== LE_EXPR
)
1492 pp_identifier (pp
, "<=");
1493 else if (code
== GE_EXPR
)
1494 pp_identifier (pp
, ">=");
1495 pp_c_whitespace (pp
);
1496 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 1));
1500 pp_c_shift_expression (pp
, e
);
1505 /* equality-expression:
1506 relational-expression
1507 equality-expression == relational-expression
1508 equality-equality != relational-expression */
1511 pp_c_equality_expression (c_pretty_printer
*pp
, tree e
)
1513 enum tree_code code
= TREE_CODE (e
);
1518 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 0));
1519 pp_c_whitespace (pp
);
1520 pp_identifier (pp
, code
== EQ_EXPR
? "==" : "!=");
1521 pp_c_whitespace (pp
);
1522 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 1));
1526 pp_c_relational_expression (pp
, e
);
1533 AND-expression & equality-equality */
1536 pp_c_and_expression (c_pretty_printer
*pp
, tree e
)
1538 if (TREE_CODE (e
) == BIT_AND_EXPR
)
1540 pp_c_and_expression (pp
, TREE_OPERAND (e
, 0));
1541 pp_c_whitespace (pp
);
1543 pp_c_whitespace (pp
);
1544 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 1));
1547 pp_c_equality_expression (pp
, e
);
1550 /* exclusive-OR-expression:
1552 exclusive-OR-expression ^ AND-expression */
1555 pp_c_exclusive_or_expression (c_pretty_printer
*pp
, tree e
)
1557 if (TREE_CODE (e
) == BIT_XOR_EXPR
)
1559 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
1560 pp_c_maybe_whitespace (pp
);
1562 pp_c_whitespace (pp
);
1563 pp_c_and_expression (pp
, TREE_OPERAND (e
, 1));
1566 pp_c_and_expression (pp
, e
);
1569 /* inclusive-OR-expression:
1570 exclusive-OR-expression
1571 inclusive-OR-expression | exclusive-OR-expression */
1574 pp_c_inclusive_or_expression (c_pretty_printer
*pp
, tree e
)
1576 if (TREE_CODE (e
) == BIT_IOR_EXPR
)
1578 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
1579 pp_c_whitespace (pp
);
1581 pp_c_whitespace (pp
);
1582 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
1585 pp_c_exclusive_or_expression (pp
, e
);
1588 /* logical-AND-expression:
1589 inclusive-OR-expression
1590 logical-AND-expression && inclusive-OR-expression */
1593 pp_c_logical_and_expression (c_pretty_printer
*pp
, tree e
)
1595 if (TREE_CODE (e
) == TRUTH_ANDIF_EXPR
)
1597 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 0));
1598 pp_c_whitespace (pp
);
1599 pp_identifier (pp
, "&&");
1600 pp_c_whitespace (pp
);
1601 pp_c_inclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
1604 pp_c_inclusive_or_expression (pp
, e
);
1607 /* logical-OR-expression:
1608 logical-AND-expression
1609 logical-OR-expression || logical-AND-expression */
1612 pp_c_logical_or_expression (c_pretty_printer
*pp
, tree e
)
1614 if (TREE_CODE (e
) == TRUTH_ORIF_EXPR
)
1616 pp_c_logical_or_expression (pp
, TREE_OPERAND (e
, 0));
1617 pp_c_whitespace (pp
);
1618 pp_identifier (pp
, "||");
1619 pp_c_whitespace (pp
);
1620 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 1));
1623 pp_c_logical_and_expression (pp
, e
);
1626 /* conditional-expression:
1627 logical-OR-expression
1628 logical-OR-expression ? expression : conditional-expression */
1631 pp_c_conditional_expression (c_pretty_printer
*pp
, tree e
)
1633 if (TREE_CODE (e
) == COND_EXPR
)
1635 pp_c_logical_or_expression (pp
, TREE_OPERAND (e
, 0));
1636 pp_c_whitespace (pp
);
1638 pp_c_whitespace (pp
);
1639 pp_expression (pp
, TREE_OPERAND (e
, 1));
1640 pp_c_whitespace (pp
);
1642 pp_c_whitespace (pp
);
1643 pp_c_conditional_expression (pp
, TREE_OPERAND (e
, 2));
1646 pp_c_logical_or_expression (pp
, e
);
1650 /* assignment-expression:
1651 conditional-expression
1652 unary-expression assignment-operator assignment-expression
1654 assignment-expression: one of
1655 = *= /= %= += -= >>= <<= &= ^= |= */
1658 pp_c_assignment_expression (c_pretty_printer
*pp
, tree e
)
1660 if (TREE_CODE (e
) == MODIFY_EXPR
|| TREE_CODE (e
) == INIT_EXPR
)
1662 pp_c_unary_expression (pp
, TREE_OPERAND (e
, 0));
1663 pp_c_whitespace (pp
);
1666 pp_c_expression (pp
, TREE_OPERAND (e
, 1));
1669 pp_c_conditional_expression (pp
, e
);
1673 assignment-expression
1674 expression , assignment-expression
1676 Implementation note: instead of going through the usual recursion
1677 chain, I take the liberty of dispatching nodes to the appropriate
1678 functions. This makes some redundancy, but it worths it. That also
1679 prevents a possible infinite recursion between pp_c_primary_expression ()
1680 and pp_c_expression (). */
1683 pp_c_expression (c_pretty_printer
*pp
, tree e
)
1685 switch (TREE_CODE (e
))
1688 pp_c_integer_constant (pp
, e
);
1692 pp_c_floating_constant (pp
, e
);
1696 pp_c_string_literal (pp
, e
);
1699 case IDENTIFIER_NODE
:
1709 pp_primary_expression (pp
, e
);
1712 case POSTINCREMENT_EXPR
:
1713 case POSTDECREMENT_EXPR
:
1723 case COMPOUND_LITERAL_EXPR
:
1725 pp_postfix_expression (pp
, e
);
1733 case TRUTH_NOT_EXPR
:
1734 case PREINCREMENT_EXPR
:
1735 case PREDECREMENT_EXPR
:
1740 pp_c_unary_expression (pp
, e
);
1744 case FIX_TRUNC_EXPR
:
1746 pp_c_cast_expression (pp
, e
);
1750 case TRUNC_MOD_EXPR
:
1751 case TRUNC_DIV_EXPR
:
1752 pp_multiplicative_expression (pp
, e
);
1757 pp_c_shift_expression (pp
, e
);
1764 pp_c_relational_expression (pp
, e
);
1768 pp_c_and_expression (pp
, e
);
1772 pp_c_exclusive_or_expression (pp
, e
);
1776 pp_c_inclusive_or_expression (pp
, e
);
1779 case TRUTH_ANDIF_EXPR
:
1780 pp_c_logical_and_expression (pp
, e
);
1783 case TRUTH_ORIF_EXPR
:
1784 pp_c_logical_or_expression (pp
, e
);
1789 pp_c_equality_expression (pp
, e
);
1793 pp_conditional_expression (pp
, e
);
1798 pp_c_additive_expression (pp
, e
);
1803 pp_assignment_expression (pp
, e
);
1807 pp_c_left_paren (pp
);
1808 pp_expression (pp
, TREE_OPERAND (e
, 0));
1809 pp_separate_with (pp
, ',');
1810 pp_assignment_expression (pp
, TREE_OPERAND (e
, 1));
1811 pp_c_right_paren (pp
);
1815 case NON_LVALUE_EXPR
:
1818 pp_expression (pp
, TREE_OPERAND (e
, 0));
1822 pp_postfix_expression (pp
, TREE_OPERAND (e
, 1));
1826 pp_unsupported_tree (pp
, e
);
1838 expression-statement
1844 pp_c_statement (c_pretty_printer
*pp
, tree stmt
)
1846 enum tree_code code
;
1851 code
= TREE_CODE (stmt
);
1854 /* labeled-statement:
1855 identifier : statement
1856 case constant-expression : statement
1857 default : statement */
1860 if (pp_needs_newline (pp
))
1861 pp_newline_and_indent (pp
, -3);
1863 pp_indentation (pp
) -= 3;
1864 if (code
== LABEL_STMT
)
1865 pp_tree_identifier (pp
, DECL_NAME (LABEL_STMT_LABEL (stmt
)));
1866 else if (code
== CASE_LABEL
)
1868 if (CASE_LOW (stmt
) == NULL_TREE
)
1869 pp_identifier (pp
, "default");
1872 pp_c_identifier (pp
, "case");
1873 pp_c_whitespace (pp
);
1874 pp_conditional_expression (pp
, CASE_LOW (stmt
));
1875 if (CASE_HIGH (stmt
))
1877 pp_identifier (pp
, "...");
1878 pp_conditional_expression (pp
, CASE_HIGH (stmt
));
1883 pp_indentation (pp
) += 3;
1884 pp_needs_newline (pp
) = true;
1887 /* compound-statement:
1888 { block-item-list(opt) }
1892 block-item-list block-item
1898 if (pp_needs_newline (pp
))
1899 pp_newline_and_indent (pp
, 0);
1900 pp_c_left_brace (pp
);
1901 pp_newline_and_indent (pp
, 3);
1902 for (stmt
= COMPOUND_BODY (stmt
); stmt
; stmt
= TREE_CHAIN (stmt
))
1903 pp_statement (pp
, stmt
);
1904 pp_newline_and_indent (pp
, -3);
1905 pp_c_right_brace (pp
);
1906 pp_needs_newline (pp
) = true;
1909 /* expression-statement:
1910 expression(opt) ; */
1913 if (pp_needs_newline (pp
))
1914 pp_newline_and_indent (pp
, 0);
1916 tree e
= code
== EXPR_STMT
1917 ? EXPR_STMT_EXPR (stmt
)
1918 : CLEANUP_EXPR (stmt
);
1920 pp_expression (pp
, e
);
1922 pp_c_semicolon (pp
);
1923 pp_needs_newline (pp
) = true;
1926 /* selection-statement:
1927 if ( expression ) statement
1928 if ( expression ) statement else statement
1929 switch ( expression ) statement */
1931 if (pp_needs_newline (pp
))
1932 pp_newline_and_indent (pp
, 0);
1933 pp_c_identifier (pp
, "if");
1934 pp_c_whitespace (pp
);
1935 pp_c_left_paren (pp
);
1936 pp_expression (pp
, IF_COND (stmt
));
1937 pp_c_right_paren (pp
);
1938 pp_newline_and_indent (pp
, 3);
1939 pp_statement (pp
, THEN_CLAUSE (stmt
));
1940 pp_newline_and_indent (pp
, -3);
1941 if (ELSE_CLAUSE (stmt
))
1943 tree else_clause
= ELSE_CLAUSE (stmt
);
1944 pp_c_identifier (pp
, "else");
1945 if (TREE_CODE (else_clause
) == IF_STMT
)
1946 pp_c_whitespace (pp
);
1948 pp_newline_and_indent (pp
, 3);
1949 pp_statement (pp
, else_clause
);
1950 if (TREE_CODE (else_clause
) != IF_STMT
)
1951 pp_newline_and_indent (pp
, -3);
1956 if (pp_needs_newline (pp
))
1957 pp_newline_and_indent (pp
, 0);
1958 pp_c_identifier (pp
, "switch");
1960 pp_c_left_paren (pp
);
1961 pp_expression (pp
, SWITCH_COND (stmt
));
1962 pp_c_right_paren (pp
);
1963 pp_indentation (pp
) += 3;
1964 pp_needs_newline (pp
) = true;
1965 pp_statement (pp
, SWITCH_BODY (stmt
));
1966 pp_newline_and_indent (pp
, -3);
1969 /* iteration-statement:
1970 while ( expression ) statement
1971 do statement while ( expression ) ;
1972 for ( expression(opt) ; expression(opt) ; expression(opt) ) statement
1973 for ( declaration expression(opt) ; expression(opt) ) statement */
1975 if (pp_needs_newline (pp
))
1976 pp_newline_and_indent (pp
, 0);
1977 pp_c_identifier (pp
, "while");
1979 pp_c_left_paren (pp
);
1980 pp_expression (pp
, WHILE_COND (stmt
));
1981 pp_c_right_paren (pp
);
1982 pp_newline_and_indent (pp
, 3);
1983 pp_statement (pp
, WHILE_BODY (stmt
));
1984 pp_indentation (pp
) -= 3;
1985 pp_needs_newline (pp
) = true;
1989 if (pp_needs_newline (pp
))
1990 pp_newline_and_indent (pp
, 0);
1991 pp_c_identifier (pp
, "do");
1992 pp_newline_and_indent (pp
, 3);
1993 pp_statement (pp
, DO_BODY (stmt
));
1994 pp_newline_and_indent (pp
, -3);
1995 pp_c_identifier (pp
, "while");
1997 pp_c_left_paren (pp
);
1998 pp_expression (pp
, DO_COND (stmt
));
1999 pp_c_right_paren (pp
);
2000 pp_c_semicolon (pp
);
2001 pp_needs_newline (pp
) = true;
2005 if (pp_needs_newline (pp
))
2006 pp_newline_and_indent (pp
, 0);
2007 pp_c_identifier (pp
, "for");
2009 pp_c_left_paren (pp
);
2010 if (FOR_INIT_STMT (stmt
))
2011 pp_statement (pp
, FOR_INIT_STMT (stmt
));
2013 pp_c_semicolon (pp
);
2014 pp_needs_newline (pp
) = false;
2015 pp_c_whitespace (pp
);
2016 if (FOR_COND (stmt
))
2017 pp_expression (pp
, FOR_COND (stmt
));
2018 pp_c_semicolon (pp
);
2019 pp_needs_newline (pp
) = false;
2020 pp_c_whitespace (pp
);
2021 if (FOR_EXPR (stmt
))
2022 pp_expression (pp
, FOR_EXPR (stmt
));
2023 pp_c_right_paren (pp
);
2024 pp_newline_and_indent (pp
, 3);
2025 pp_statement (pp
, FOR_BODY (stmt
));
2026 pp_indentation (pp
) -= 3;
2027 pp_needs_newline (pp
) = true;
2033 return expression(opt) ; */
2036 if (pp_needs_newline (pp
))
2037 pp_newline_and_indent (pp
, 0);
2038 pp_identifier (pp
, code
== BREAK_STMT
? "break" : "continue");
2039 pp_c_semicolon (pp
);
2040 pp_needs_newline (pp
) = true;
2046 tree e
= code
== RETURN_STMT
2047 ? RETURN_STMT_EXPR (stmt
)
2048 : GOTO_DESTINATION (stmt
);
2049 if (pp_needs_newline (pp
))
2050 pp_newline_and_indent (pp
, 0);
2051 pp_c_identifier (pp
, code
== RETURN_STMT
? "return" : "goto");
2052 pp_c_whitespace (pp
);
2055 if (TREE_CODE (e
) == INIT_EXPR
2056 && TREE_CODE (TREE_OPERAND (e
, 0)) == RESULT_DECL
)
2057 e
= TREE_OPERAND (e
, 1);
2058 pp_expression (pp
, e
);
2060 pp_c_semicolon (pp
);
2061 pp_needs_newline (pp
) = true;
2066 if (!SCOPE_NULLIFIED_P (stmt
) && SCOPE_NO_CLEANUPS_P (stmt
))
2069 if (pp_needs_newline (pp
))
2070 pp_newline_and_indent (pp
, 0);
2071 if (SCOPE_BEGIN_P (stmt
))
2076 else if (SCOPE_END_P (stmt
))
2078 pp_right_brace (pp
);
2081 pp_indentation (pp
) += i
;
2082 pp_needs_newline (pp
) = true;
2087 if (pp_needs_newline (pp
))
2088 pp_newline_and_indent (pp
, 0);
2089 pp_declaration (pp
, DECL_STMT_DECL (stmt
));
2090 pp_needs_newline (pp
) = true;
2095 bool has_volatile_p
= ASM_VOLATILE_P (stmt
);
2096 bool is_extended
= has_volatile_p
|| ASM_INPUTS (stmt
)
2097 || ASM_OUTPUTS (stmt
) || ASM_CLOBBERS (stmt
);
2098 pp_c_identifier (pp
, is_extended
? "__asm__" : "asm");
2100 pp_c_identifier (pp
, "__volatile__");
2102 pp_c_left_paren (pp
);
2103 pp_c_string_literal (pp
, ASM_STRING (stmt
));
2107 pp_separate_with (pp
, ':');
2108 if (ASM_OUTPUTS (stmt
))
2109 pp_expression (pp
, ASM_OUTPUTS (stmt
));
2111 pp_separate_with (pp
, ':');
2112 if (ASM_INPUTS (stmt
))
2113 pp_expression (pp
, ASM_INPUTS (stmt
));
2115 pp_separate_with (pp
, ':');
2116 if (ASM_CLOBBERS (stmt
))
2117 pp_expression (pp
, ASM_CLOBBERS (stmt
));
2119 pp_c_right_paren (pp
);
2125 pp_c_identifier (pp
, "__FILE__");
2128 pp_c_whitespace (pp
);
2129 pp_c_identifier (pp
, FILE_STMT_FILENAME (stmt
));
2130 pp_c_semicolon (pp
);
2131 pp_needs_newline (pp
) = true;
2135 pp_unsupported_tree (pp
, stmt
);
2140 /* Initialize the PRETTY-PRINTER for handling C codes. */
2143 pp_c_pretty_printer_init (c_pretty_printer
*pp
)
2145 pp
->offset_list
= 0;
2147 pp
->declaration
= pp_c_declaration
;
2148 pp
->declaration_specifiers
= pp_c_declaration_specifiers
;
2149 pp
->declarator
= pp_c_declarator
;
2150 pp
->direct_declarator
= pp_c_direct_declarator
;
2151 pp
->type_specifier_seq
= pp_c_specifier_qualifier_list
;
2152 pp
->abstract_declarator
= pp_c_abstract_declarator
;
2153 pp
->direct_abstract_declarator
= pp_c_direct_abstract_declarator
;
2154 pp
->ptr_operator
= pp_c_pointer
;
2155 pp
->parameter_list
= pp_c_parameter_type_list
;
2156 pp
->type_id
= pp_c_type_id
;
2157 pp
->simple_type_specifier
= pp_c_type_specifier
;
2158 pp
->function_specifier
= pp_c_function_specifier
;
2159 pp
->storage_class_specifier
= pp_c_storage_class_specifier
;
2161 pp
->statement
= pp_c_statement
;
2163 pp
->id_expression
= pp_c_id_expression
;
2164 pp
->primary_expression
= pp_c_primary_expression
;
2165 pp
->postfix_expression
= pp_c_postfix_expression
;
2166 pp
->unary_expression
= pp_c_unary_expression
;
2167 pp
->initializer
= pp_c_initializer
;
2168 pp
->multiplicative_expression
= pp_c_multiplicative_expression
;
2169 pp
->conditional_expression
= pp_c_conditional_expression
;
2170 pp
->assignment_expression
= pp_c_assignment_expression
;
2171 pp
->expression
= pp_c_expression
;