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"
29 #include "tree-iterator.h"
30 #include "diagnostic.h"
32 /* The pretty-printer code is primarily designed to closely follow
33 (GNU) C and C++ grammars. That is to be contrasted with spaghetti
34 codes we used to have in the past. Following a structured
35 approach (preferably the official grammars) is believed to make it
36 much easier to add extensions and nifty pretty-printing effects that
37 takes expression or declaration contexts into account. */
40 #define pp_c_maybe_whitespace(PP) \
42 if (pp_base (PP)->padding == pp_before) \
43 pp_c_whitespace (PP); \
47 static void pp_c_char (c_pretty_printer
*, int);
49 /* postfix-expression */
50 static void pp_c_initializer_list (c_pretty_printer
*, tree
);
51 static void pp_c_brace_enclosed_initializer_list (c_pretty_printer
*, tree
);
53 static void pp_c_multiplicative_expression (c_pretty_printer
*, tree
);
54 static void pp_c_additive_expression (c_pretty_printer
*, tree
);
55 static void pp_c_shift_expression (c_pretty_printer
*, tree
);
56 static void pp_c_relational_expression (c_pretty_printer
*, tree
);
57 static void pp_c_equality_expression (c_pretty_printer
*, tree
);
58 static void pp_c_and_expression (c_pretty_printer
*, tree
);
59 static void pp_c_exclusive_or_expression (c_pretty_printer
*, tree
);
60 static void pp_c_inclusive_or_expression (c_pretty_printer
*, tree
);
61 static void pp_c_logical_and_expression (c_pretty_printer
*, tree
);
62 static void pp_c_conditional_expression (c_pretty_printer
*, tree
);
63 static void pp_c_assignment_expression (c_pretty_printer
*, tree
);
68 /* Helper functions. */
71 pp_c_whitespace (c_pretty_printer
*pp
)
74 pp_base (pp
)->padding
= pp_none
;
78 pp_c_left_paren (c_pretty_printer
*pp
)
81 pp_base (pp
)->padding
= pp_none
;
85 pp_c_right_paren (c_pretty_printer
*pp
)
88 pp_base (pp
)->padding
= pp_none
;
92 pp_c_left_brace (c_pretty_printer
*pp
)
95 pp_base (pp
)->padding
= pp_none
;
99 pp_c_right_brace (c_pretty_printer
*pp
)
102 pp_base (pp
)->padding
= pp_none
;
106 pp_c_left_bracket (c_pretty_printer
*pp
)
108 pp_left_bracket (pp
);
109 pp_base (pp
)->padding
= pp_none
;
113 pp_c_right_bracket (c_pretty_printer
*pp
)
115 pp_right_bracket (pp
);
116 pp_base (pp
)->padding
= pp_none
;
120 pp_c_dot (c_pretty_printer
*pp
)
123 pp_base (pp
)->padding
= pp_none
;
127 pp_c_ampersand (c_pretty_printer
*pp
)
130 pp_base (pp
)->padding
= pp_none
;
134 pp_c_star (c_pretty_printer
*pp
)
137 pp_base (pp
)->padding
= pp_none
;
141 pp_c_arrow (c_pretty_printer
*pp
)
144 pp_base (pp
)->padding
= pp_none
;
148 pp_c_semicolon (c_pretty_printer
*pp
)
151 pp_base (pp
)->padding
= pp_none
;
155 pp_c_complement (c_pretty_printer
*pp
)
158 pp_base (pp
)->padding
= pp_none
;
162 pp_c_exclamation (c_pretty_printer
*pp
)
165 pp_base (pp
)->padding
= pp_none
;
168 /* Print out the external representation of CV-QUALIFIER. */
171 pp_c_cv_qualifier (c_pretty_printer
*pp
, const char *cv
)
173 const char *p
= pp_last_position_in_text (pp
);
174 /* The C programming language does not have references, but it is much
175 simpler to handle those here rather than going through the same
176 logic in the C++ pretty-printer. */
177 if (p
!= NULL
&& (*p
== '*' || *p
== '&'))
178 pp_c_whitespace (pp
);
179 pp_c_identifier (pp
, cv
);
182 /* Pretty-print T using the type-cast notation '( type-name )'. */
185 pp_c_type_cast (c_pretty_printer
*pp
, tree t
)
187 pp_c_left_paren (pp
);
189 pp_c_right_paren (pp
);
192 /* We're about to pretty-print a pointer type as indicated by T.
193 Output a whitespace, if needed, preparing for subsequent output. */
196 pp_c_space_for_pointer_operator (c_pretty_printer
*pp
, tree t
)
198 if (POINTER_TYPE_P (t
))
200 tree pointee
= strip_pointer_operator (TREE_TYPE (t
));
201 if (TREE_CODE (pointee
) != ARRAY_TYPE
202 && TREE_CODE (pointee
) != FUNCTION_TYPE
)
203 pp_c_whitespace (pp
);
210 /* C++ cv-qualifiers are called type-qualifiers in C. Print out the
211 cv-qualifiers of T. If T is a declaration then it is the cv-qualifier
212 of its type. Take care of possible extensions.
216 type-qualifier-list type-qualifier
221 __restrict__ -- GNU C
225 pp_c_type_qualifier_list (c_pretty_printer
*pp
, tree t
)
232 qualifiers
= TYPE_QUALS (t
);
233 if (qualifiers
& TYPE_QUAL_CONST
)
234 pp_c_cv_qualifier (pp
, "const");
235 if (qualifiers
& TYPE_QUAL_VOLATILE
)
236 pp_c_cv_qualifier (pp
, "volatile");
237 if (qualifiers
& TYPE_QUAL_RESTRICT
)
238 pp_c_cv_qualifier (pp
, flag_isoc99
? "restrict" : "__restrict__");
242 * type-qualifier-list(opt)
243 * type-qualifier-list(opt) pointer */
246 pp_c_pointer (c_pretty_printer
*pp
, tree t
)
248 if (!TYPE_P (t
) && TREE_CODE (t
) != TYPE_DECL
)
250 switch (TREE_CODE (t
))
253 /* It is easier to handle C++ reference types here. */
255 if (TREE_CODE (TREE_TYPE (t
)) == POINTER_TYPE
)
256 pp_c_pointer (pp
, TREE_TYPE (t
));
257 if (TREE_CODE (t
) == POINTER_TYPE
)
261 pp_c_type_qualifier_list (pp
, t
);
265 pp_unsupported_tree (pp
, t
);
282 struct-or-union-specifier
287 simple-type-specifier:
292 pp_c_type_specifier (c_pretty_printer
*pp
, tree t
)
294 const enum tree_code code
= TREE_CODE (t
);
298 pp_c_identifier (pp
, "<type-error>");
301 case IDENTIFIER_NODE
:
302 pp_c_tree_decl_identifier (pp
, t
);
313 t
= c_common_type_for_mode (TYPE_MODE (t
), TYPE_UNSIGNED (t
));
314 pp_c_type_specifier (pp
, t
);
319 pp_id_expression (pp
, t
);
321 pp_c_identifier (pp
, "<typedef-error>");
327 if (code
== UNION_TYPE
)
328 pp_c_identifier (pp
, "union");
329 else if (code
== RECORD_TYPE
)
330 pp_c_identifier (pp
, "struct");
331 else if (code
== ENUMERAL_TYPE
)
332 pp_c_identifier (pp
, "enum");
334 pp_c_identifier (pp
, "<tag-error>");
337 pp_id_expression (pp
, TYPE_NAME (t
));
339 pp_c_identifier (pp
, "<anonymous>");
343 pp_unsupported_tree (pp
, t
);
348 /* specifier-qualifier-list:
349 type-specifier specifier-qualifier-list-opt
350 type-qualifier specifier-qualifier-list-opt
353 Implementation note: Because of the non-linearities in array or
354 function declarations, this routine prints not just the
355 specifier-qualifier-list of such entities or types of such entities,
356 but also the 'pointer' production part of their declarators. The
357 remaining part is done by pp_declarator or pp_c_abstract_declarator. */
360 pp_c_specifier_qualifier_list (c_pretty_printer
*pp
, tree t
)
362 const enum tree_code code
= TREE_CODE (t
);
364 if (TREE_CODE (t
) != POINTER_TYPE
)
365 pp_c_type_qualifier_list (pp
, t
);
371 /* Get the types-specifier of this type. */
372 tree pointee
= strip_pointer_operator (TREE_TYPE (t
));
373 pp_c_specifier_qualifier_list (pp
, pointee
);
374 if (TREE_CODE (pointee
) == ARRAY_TYPE
375 || TREE_CODE (pointee
) == FUNCTION_TYPE
)
377 pp_c_whitespace (pp
);
378 pp_c_left_paren (pp
);
380 pp_ptr_operator (pp
, t
);
386 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
391 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
392 if (code
== COMPLEX_TYPE
)
393 pp_c_identifier (pp
, flag_isoc99
? "_Complex" : "__complex__");
394 else if (code
== VECTOR_TYPE
)
395 pp_c_identifier (pp
, "__vector__");
399 pp_simple_type_specifier (pp
, t
);
404 /* parameter-type-list:
409 parameter-declaration
410 parameter-list , parameter-declaration
412 parameter-declaration:
413 declaration-specifiers declarator
414 declaration-specifiers abstract-declarator(opt) */
417 pp_c_parameter_type_list (c_pretty_printer
*pp
, tree t
)
419 bool want_parm_decl
= DECL_P (t
) && !(pp
->flags
& pp_c_flag_abstract
);
420 tree parms
= want_parm_decl
? DECL_ARGUMENTS (t
) : TYPE_ARG_TYPES (t
);
421 pp_c_left_paren (pp
);
422 if (parms
== void_list_node
)
423 pp_c_identifier (pp
, "void");
427 for ( ; parms
&& parms
!= void_list_node
; parms
= TREE_CHAIN (parms
))
430 pp_separate_with (pp
, ',');
432 pp_declaration_specifiers
433 (pp
, want_parm_decl
? parms
: TREE_VALUE (parms
));
435 pp_declarator (pp
, parms
);
437 pp_abstract_declarator (pp
, TREE_VALUE (parms
));
440 pp_c_right_paren (pp
);
443 /* abstract-declarator:
445 pointer(opt) direct-abstract-declarator */
448 pp_c_abstract_declarator (c_pretty_printer
*pp
, tree t
)
450 if (TREE_CODE (t
) == POINTER_TYPE
)
452 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
453 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
454 pp_c_right_paren (pp
);
458 pp_direct_abstract_declarator (pp
, t
);
461 /* direct-abstract-declarator:
462 ( abstract-declarator )
463 direct-abstract-declarator(opt) [ assignment-expression(opt) ]
464 direct-abstract-declarator(opt) [ * ]
465 direct-abstract-declarator(opt) ( parameter-type-list(opt) ) */
468 pp_c_direct_abstract_declarator (c_pretty_printer
*pp
, tree t
)
470 switch (TREE_CODE (t
))
473 pp_abstract_declarator (pp
, t
);
477 pp_c_parameter_type_list (pp
, t
);
478 pp_direct_abstract_declarator (pp
, TREE_TYPE (t
));
482 pp_c_left_bracket (pp
);
484 pp_expression (pp
, TYPE_MAX_VALUE (TYPE_DOMAIN (t
)));
485 pp_c_right_bracket (pp
);
486 pp_direct_abstract_declarator (pp
, TREE_TYPE (t
));
489 case IDENTIFIER_NODE
:
503 pp_unsupported_tree (pp
, t
);
509 specifier-qualifier-list abstract-declarator(opt) */
512 pp_c_type_id (c_pretty_printer
*pp
, tree t
)
514 pp_c_specifier_qualifier_list (pp
, t
);
515 pp_abstract_declarator (pp
, t
);
518 /* storage-class-specifier:
526 pp_c_storage_class_specifier (c_pretty_printer
*pp
, tree t
)
528 if (TREE_CODE (t
) == TYPE_DECL
)
529 pp_c_identifier (pp
, "typedef");
532 if (DECL_REGISTER (t
))
533 pp_c_identifier (pp
, "register");
534 else if (TREE_STATIC (t
) && TREE_CODE (t
) == VAR_DECL
)
535 pp_c_identifier (pp
, "static");
539 /* function-specifier:
543 pp_c_function_specifier (c_pretty_printer
*pp
, tree t
)
545 if (TREE_CODE (t
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (t
))
546 pp_c_identifier (pp
, "inline");
549 /* declaration-specifiers:
550 storage-class-specifier declaration-specifiers(opt)
551 type-specifier declaration-specifiers(opt)
552 type-qualifier declaration-specifiers(opt)
553 function-specifier declaration-specifiers(opt) */
556 pp_c_declaration_specifiers (c_pretty_printer
*pp
, tree t
)
558 pp_storage_class_specifier (pp
, t
);
559 pp_function_specifier (pp
, t
);
560 pp_c_specifier_qualifier_list (pp
, DECL_P (t
) ? TREE_TYPE (t
) : t
);
566 direct-declarator [ type-qualifier-list(opt) assignment-expression(opt) ]
567 direct-declarator [ static type-qualifier-list(opt) assignment-expression(opt)]
568 direct-declarator [ type-qualifier-list static assignment-expression ]
569 direct-declarator [ type-qualifier-list * ]
570 direct-declarator ( parameter-type-list )
571 direct-declarator ( identifier-list(opt) ) */
574 pp_c_direct_declarator (c_pretty_printer
*pp
, tree t
)
576 switch (TREE_CODE (t
))
583 pp_c_space_for_pointer_operator (pp
, TREE_TYPE (t
));
584 pp_c_tree_decl_identifier (pp
, t
);
589 pp_abstract_declarator (pp
, TREE_TYPE (t
));
593 pp_parameter_list (pp
, t
);
594 pp_abstract_declarator (pp
, TREE_TYPE (t
));
598 pp_c_space_for_pointer_operator (pp
, TREE_TYPE (TREE_TYPE (t
)));
599 pp_c_tree_decl_identifier (pp
, t
);
600 if (pp_c_base (pp
)->flags
& pp_c_flag_abstract
)
601 pp_abstract_declarator (pp
, TREE_TYPE (t
));
604 pp_parameter_list (pp
, t
);
605 pp_abstract_declarator (pp
, TREE_TYPE (TREE_TYPE (t
)));
617 pp_unsupported_tree (pp
, t
);
624 pointer(opt) direct-declarator */
627 pp_c_declarator (c_pretty_printer
*pp
, tree t
)
629 switch (TREE_CODE (t
))
645 pp_direct_declarator (pp
, t
);
650 pp_unsupported_tree (pp
, t
);
656 declaration-specifiers init-declarator-list(opt) ; */
659 pp_c_declaration (c_pretty_printer
*pp
, tree t
)
661 pp_declaration_specifiers (pp
, t
);
662 pp_c_init_declarator (pp
, t
);
665 /* Pretty-print ATTRIBUTES using GNU C extension syntax. */
668 pp_c_attributes (c_pretty_printer
*pp
, tree attributes
)
670 if (attributes
== NULL_TREE
)
673 pp_c_identifier (pp
, "__attribute__");
674 pp_c_left_paren (pp
);
675 pp_c_left_paren (pp
);
676 for (; attributes
!= NULL_TREE
; attributes
= TREE_CHAIN (attributes
))
678 pp_tree_identifier (pp
, TREE_PURPOSE (attributes
));
679 if (TREE_VALUE (attributes
))
680 pp_c_call_argument_list (pp
, TREE_VALUE (attributes
));
682 if (TREE_CHAIN (attributes
))
683 pp_separate_with (pp
, ',');
685 pp_c_right_paren (pp
);
686 pp_c_right_paren (pp
);
689 /* function-definition:
690 declaration-specifiers declarator compound-statement */
693 pp_c_function_definition (c_pretty_printer
*pp
, tree t
)
695 pp_declaration_specifiers (pp
, t
);
696 pp_declarator (pp
, t
);
697 pp_needs_newline (pp
) = true;
698 pp_statement (pp
, DECL_SAVED_TREE (t
));
706 /* Print out a c-char. */
709 pp_c_char (c_pretty_printer
*pp
, int c
)
714 pp_string (pp
, "\\n");
717 pp_string (pp
, "\\t");
720 pp_string (pp
, "\\v");
723 pp_string (pp
, "\\b");
726 pp_string (pp
, "\\r");
729 pp_string (pp
, "\\f");
732 pp_string (pp
, "\\a");
735 pp_string (pp
, "\\\\");
738 pp_string (pp
, "\\'");
741 pp_string (pp
, "\\\"");
745 pp_character (pp
, c
);
747 pp_scalar (pp
, "\\%03o", (unsigned) c
);
752 /* Print out a STRING literal. */
755 pp_c_string_literal (c_pretty_printer
*pp
, tree s
)
757 const char *p
= TREE_STRING_POINTER (s
);
758 int n
= TREE_STRING_LENGTH (s
) - 1;
761 for (i
= 0; i
< n
; ++i
)
762 pp_c_char (pp
, p
[i
]);
766 /* Pretty-print an INTEGER literal. */
769 pp_c_integer_constant (c_pretty_printer
*pp
, tree i
)
771 tree type
= TREE_TYPE (i
);
773 if (TREE_INT_CST_HIGH (i
) == 0)
774 pp_wide_integer (pp
, TREE_INT_CST_LOW (i
));
777 if (tree_int_cst_sgn (i
) < 0)
780 i
= build_int_2 (-TREE_INT_CST_LOW (i
),
781 ~TREE_INT_CST_HIGH (i
) + !TREE_INT_CST_LOW (i
));
783 sprintf (pp_buffer (pp
)->digit_buffer
,
784 HOST_WIDE_INT_PRINT_DOUBLE_HEX
,
785 TREE_INT_CST_HIGH (i
), TREE_INT_CST_LOW (i
));
786 pp_string (pp
, pp_buffer (pp
)->digit_buffer
);
788 if (TYPE_UNSIGNED (type
))
789 pp_character (pp
, 'u');
790 if (type
== long_integer_type_node
|| type
== long_unsigned_type_node
)
791 pp_character (pp
, 'l');
792 else if (type
== long_long_integer_type_node
793 || type
== long_long_unsigned_type_node
)
794 pp_string (pp
, "ll");
797 /* Print out a CHARACTER literal. */
800 pp_c_character_constant (c_pretty_printer
*pp
, tree c
)
802 tree type
= TREE_TYPE (c
);
803 if (type
== wchar_type_node
)
804 pp_character (pp
, 'L');
806 if (host_integerp (c
, TYPE_UNSIGNED (type
)))
807 pp_c_char (pp
, tree_low_cst (c
, TYPE_UNSIGNED (type
)));
809 pp_scalar (pp
, "\\x%x", (unsigned) TREE_INT_CST_LOW (c
));
813 /* Print out a BOOLEAN literal. */
816 pp_c_bool_constant (c_pretty_printer
*pp
, tree b
)
818 if (b
== boolean_false_node
)
820 if (c_dialect_cxx ())
821 pp_c_identifier (pp
, "false");
822 else if (flag_isoc99
)
823 pp_c_identifier (pp
, "_False");
825 pp_unsupported_tree (pp
, b
);
827 else if (b
== boolean_true_node
)
829 if (c_dialect_cxx ())
830 pp_c_identifier (pp
, "true");
831 else if (flag_isoc99
)
832 pp_c_identifier (pp
, "_True");
834 pp_unsupported_tree (pp
, b
);
836 else if (TREE_CODE (b
) == INTEGER_CST
)
837 pp_c_integer_constant (pp
, b
);
839 pp_unsupported_tree (pp
, b
);
842 /* Attempt to print out an ENUMERATOR. Return true on success. Else return
843 false; that means the value was obtained by a cast, in which case
844 print out the type-id part of the cast-expression -- the casted value
845 is then printed by pp_c_integer_literal. */
848 pp_c_enumeration_constant (c_pretty_printer
*pp
, tree e
)
850 bool value_is_named
= true;
851 tree type
= TREE_TYPE (e
);
854 /* Find the name of this constant. */
855 for (value
= TYPE_VALUES (type
);
856 value
!= NULL_TREE
&& !tree_int_cst_equal (TREE_VALUE (value
), e
);
857 value
= TREE_CHAIN (value
))
860 if (value
!= NULL_TREE
)
861 pp_id_expression (pp
, TREE_PURPOSE (value
));
864 /* Value must have been cast. */
865 pp_c_type_cast (pp
, type
);
866 value_is_named
= false;
869 return value_is_named
;
872 /* Print out a REAL value as a decimal-floating-constant. */
875 pp_c_floating_constant (c_pretty_printer
*pp
, tree r
)
877 real_to_decimal (pp_buffer (pp
)->digit_buffer
, &TREE_REAL_CST (r
),
878 sizeof (pp_buffer (pp
)->digit_buffer
), 0, 1);
879 pp_string (pp
, pp_buffer(pp
)->digit_buffer
);
880 if (TREE_TYPE (r
) == float_type_node
)
881 pp_character (pp
, 'f');
882 else if (TREE_TYPE (r
) == long_double_type_node
)
883 pp_character (pp
, 'l');
886 /* Pretty-print a compound literal expression. GNU extensions include
890 pp_c_compound_literal (c_pretty_printer
*pp
, tree e
)
892 tree type
= TREE_TYPE (e
);
893 pp_c_type_cast (pp
, type
);
895 switch (TREE_CODE (type
))
902 pp_c_brace_enclosed_initializer_list (pp
, e
);
906 pp_unsupported_tree (pp
, e
);
915 character-constant */
918 pp_c_constant (c_pretty_printer
*pp
, tree e
)
920 const enum tree_code code
= TREE_CODE (e
);
926 tree type
= TREE_TYPE (e
);
927 if (type
== boolean_type_node
)
928 pp_c_bool_constant (pp
, e
);
929 else if (type
== char_type_node
)
930 pp_c_character_constant (pp
, e
);
931 else if (TREE_CODE (type
) == ENUMERAL_TYPE
932 && pp_c_enumeration_constant (pp
, e
))
935 pp_c_integer_constant (pp
, e
);
940 pp_c_floating_constant (pp
, e
);
944 pp_c_string_literal (pp
, e
);
948 pp_unsupported_tree (pp
, e
);
953 /* Pretty-print an IDENTIFIER_NODE, preceded by whitespace is necessary. */
956 pp_c_identifier (c_pretty_printer
*pp
, const char *id
)
958 pp_c_maybe_whitespace (pp
);
959 pp_identifier (pp
, id
);
960 pp_base (pp
)->padding
= pp_before
;
963 /* Pretty-print a C primary-expression.
971 pp_c_primary_expression (c_pretty_printer
*pp
, tree e
)
973 switch (TREE_CODE (e
))
981 pp_c_tree_decl_identifier (pp
, e
);
984 case IDENTIFIER_NODE
:
985 pp_c_tree_identifier (pp
, e
);
989 pp_c_identifier (pp
, "<erroneous-expression>");
993 pp_c_identifier (pp
, "<return-value>");
999 pp_c_constant (pp
, e
);
1003 pp_c_identifier (pp
, "__builtin_memcpy");
1004 pp_c_left_paren (pp
);
1006 pp_primary_expression (pp
, TREE_OPERAND (e
, 0));
1007 pp_separate_with (pp
, ',');
1009 pp_initializer (pp
, TREE_OPERAND (e
, 1));
1010 if (TREE_OPERAND (e
, 2))
1012 pp_separate_with (pp
, ',');
1013 pp_c_expression (pp
, TREE_OPERAND (e
, 2));
1015 pp_c_right_paren (pp
);
1019 pp_c_left_paren (pp
);
1020 pp_statement (pp
, STMT_EXPR_STMT (e
));
1021 pp_c_right_paren (pp
);
1025 /* FIXME: Make sure we won't get into an infinie loop. */
1026 pp_c_left_paren (pp
);
1027 pp_expression (pp
, e
);
1028 pp_c_right_paren (pp
);
1033 /* Print out a C initializer -- also support C compound-literals.
1035 assignment-expression:
1036 { initializer-list }
1037 { initializer-list , } */
1040 pp_c_initializer (c_pretty_printer
*pp
, tree e
)
1042 if (TREE_CODE (e
) == CONSTRUCTOR
)
1043 pp_c_brace_enclosed_initializer_list (pp
, e
);
1045 pp_expression (pp
, e
);
1050 declarator = initializer */
1053 pp_c_init_declarator (c_pretty_printer
*pp
, tree t
)
1055 pp_declarator (pp
, t
);
1056 /* We don't want to output function definitions here. There are handled
1057 elsewhere (and the syntactic form is bogus anyway). */
1058 if (TREE_CODE (t
) != FUNCTION_DECL
&& DECL_INITIAL (t
))
1060 tree init
= DECL_INITIAL (t
);
1061 /* This C++ bit is handled here because it is easier to do so.
1062 In templates, the C++ parser builds a TREE_LIST for a
1063 direct-initialization; the TREE_PURPOSE is the variable to
1064 initialize and the TREE_VALUE is the initializer. */
1065 if (TREE_CODE (init
) == TREE_LIST
)
1067 pp_c_left_paren (pp
);
1068 pp_expression (pp
, TREE_VALUE (init
));
1069 pp_right_paren (pp
);
1076 pp_c_initializer (pp
, init
);
1081 /* initializer-list:
1082 designation(opt) initializer
1083 initializer-list , designation(opt) initializer
1090 designator-list designator
1093 [ constant-expression ]
1097 pp_c_initializer_list (c_pretty_printer
*pp
, tree e
)
1099 tree type
= TREE_TYPE (e
);
1100 const enum tree_code code
= TREE_CODE (type
);
1108 tree init
= TREE_OPERAND (e
, 0);
1109 for (; init
!= NULL_TREE
; init
= TREE_CHAIN (init
))
1111 if (code
== RECORD_TYPE
|| code
== UNION_TYPE
)
1114 pp_c_primary_expression (pp
, TREE_PURPOSE (init
));
1118 pp_c_left_bracket (pp
);
1119 if (TREE_PURPOSE (init
))
1120 pp_c_constant (pp
, TREE_PURPOSE (init
));
1121 pp_c_right_bracket (pp
);
1123 pp_c_whitespace (pp
);
1125 pp_c_whitespace (pp
);
1126 pp_initializer (pp
, TREE_VALUE (init
));
1127 if (TREE_CHAIN (init
))
1128 pp_separate_with (pp
, ',');
1134 if (TREE_CODE (e
) == VECTOR_CST
)
1135 pp_c_expression_list (pp
, TREE_VECTOR_CST_ELTS (e
));
1136 else if (TREE_CODE (e
) == CONSTRUCTOR
)
1137 pp_c_expression_list (pp
, CONSTRUCTOR_ELTS (e
));
1143 if (TREE_CODE (e
) == CONSTRUCTOR
)
1144 pp_c_expression_list (pp
, CONSTRUCTOR_ELTS (e
));
1145 else if (TREE_CODE (e
) == COMPLEX_CST
|| TREE_CODE (e
) == COMPLEX_EXPR
)
1147 const bool cst
= TREE_CODE (e
) == COMPLEX_CST
;
1148 pp_expression (pp
, cst
? TREE_REALPART (e
) : TREE_OPERAND (e
, 0));
1149 pp_separate_with (pp
, ',');
1150 pp_expression (pp
, cst
? TREE_IMAGPART (e
) : TREE_OPERAND (e
, 1));
1160 pp_unsupported_tree (pp
, type
);
1163 /* Pretty-print a brace-enclosed initializer-list. */
1166 pp_c_brace_enclosed_initializer_list (c_pretty_printer
*pp
, tree l
)
1168 pp_c_left_brace (pp
);
1169 pp_c_initializer_list (pp
, l
);
1170 pp_c_right_brace (pp
);
1174 /* This is a convenient function, used to bridge gap between C and C++
1181 pp_c_id_expression (c_pretty_printer
*pp
, tree t
)
1183 switch (TREE_CODE (t
))
1192 pp_c_tree_decl_identifier (pp
, t
);
1195 case IDENTIFIER_NODE
:
1196 pp_c_tree_identifier (pp
, t
);
1200 pp_unsupported_tree (pp
, t
);
1205 /* postfix-expression:
1207 postfix-expression [ expression ]
1208 postfix-expression ( argument-expression-list(opt) )
1209 postfix-expression . identifier
1210 postfix-expression -> identifier
1211 postfix-expression ++
1212 postfix-expression --
1213 ( type-name ) { initializer-list }
1214 ( type-name ) { initializer-list , } */
1217 pp_c_postfix_expression (c_pretty_printer
*pp
, tree e
)
1219 enum tree_code code
= TREE_CODE (e
);
1222 case POSTINCREMENT_EXPR
:
1223 case POSTDECREMENT_EXPR
:
1224 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1225 pp_identifier (pp
, code
== POSTINCREMENT_EXPR
? "++" : "--");
1229 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1234 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1235 pp_c_left_bracket (pp
);
1236 pp_expression (pp
, TREE_OPERAND (e
, 1));
1237 pp_c_right_bracket (pp
);
1241 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1242 pp_c_call_argument_list (pp
, TREE_OPERAND (e
, 1));
1246 pp_c_identifier (pp
, "__builtin_abs");
1247 pp_c_left_paren (pp
);
1248 pp_expression (pp
, TREE_OPERAND (e
, 0));
1249 pp_c_right_paren (pp
);
1254 tree object
= TREE_OPERAND (e
, 0);
1255 if (TREE_CODE (object
) == INDIRECT_REF
)
1257 pp_postfix_expression (pp
, TREE_OPERAND (object
, 0));
1262 pp_postfix_expression (pp
, object
);
1265 pp_expression (pp
, TREE_OPERAND (e
, 1));
1272 pp_c_compound_literal (pp
, e
);
1275 case COMPOUND_LITERAL_EXPR
:
1276 e
= DECL_INITIAL (COMPOUND_LITERAL_EXPR_DECL (e
));
1279 pp_initializer (pp
, e
);
1283 pp_c_identifier (pp
, "__builtin_va_arg");
1284 pp_c_left_paren (pp
);
1285 pp_assignment_expression (pp
, TREE_OPERAND (e
, 0));
1286 pp_separate_with (pp
, ',');
1287 pp_type_id (pp
, TREE_TYPE (e
));
1288 pp_c_right_paren (pp
);
1292 if (TREE_CODE (TREE_OPERAND (e
, 0)) == FUNCTION_DECL
)
1294 pp_c_id_expression (pp
, TREE_OPERAND (e
, 0));
1297 /* else fall through. */
1300 pp_primary_expression (pp
, e
);
1305 /* Print out an expression-list; E is expected to be a TREE_LIST. */
1308 pp_c_expression_list (c_pretty_printer
*pp
, tree e
)
1310 for (; e
!= NULL_TREE
; e
= TREE_CHAIN (e
))
1312 pp_expression (pp
, TREE_VALUE (e
));
1314 pp_separate_with (pp
, ',');
1318 /* Print out an expression-list in parens, as in a function call. */
1321 pp_c_call_argument_list (c_pretty_printer
*pp
, tree t
)
1323 pp_c_left_paren (pp
);
1324 if (t
&& TREE_CODE (t
) == TREE_LIST
)
1325 pp_c_expression_list (pp
, t
);
1326 pp_c_right_paren (pp
);
1329 /* unary-expression:
1333 unary-operator cast-expression
1334 sizeof unary-expression
1337 unary-operator: one of
1342 __alignof__ unary-expression
1343 __alignof__ ( type-id )
1344 __real__ unary-expression
1345 __imag__ unary-expression */
1348 pp_c_unary_expression (c_pretty_printer
*pp
, tree e
)
1350 enum tree_code code
= TREE_CODE (e
);
1353 case PREINCREMENT_EXPR
:
1354 case PREDECREMENT_EXPR
:
1355 pp_identifier (pp
, code
== PREINCREMENT_EXPR
? "++" : "--");
1356 pp_c_unary_expression (pp
, TREE_OPERAND (e
, 0));
1363 case TRUTH_NOT_EXPR
:
1365 /* String literal are used by address. */
1366 if (code
== ADDR_EXPR
&& TREE_CODE (TREE_OPERAND (e
, 0)) != STRING_CST
)
1368 else if (code
== INDIRECT_REF
)
1370 else if (code
== NEGATE_EXPR
)
1372 else if (code
== BIT_NOT_EXPR
|| code
== CONJ_EXPR
)
1374 else if (code
== TRUTH_NOT_EXPR
)
1375 pp_exclamation (pp
);
1376 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 0));
1381 pp_c_identifier (pp
, code
== SIZEOF_EXPR
? "sizeof" : "__alignof__");
1382 pp_c_whitespace (pp
);
1383 if (TYPE_P (TREE_OPERAND (e
, 0)))
1384 pp_c_type_cast (pp
, TREE_OPERAND (e
, 0));
1386 pp_unary_expression (pp
, TREE_OPERAND (e
, 0));
1391 pp_c_identifier (pp
, code
== REALPART_EXPR
? "__real__" : "__imag__");
1392 pp_c_whitespace (pp
);
1393 pp_unary_expression (pp
, TREE_OPERAND (e
, 0));
1397 pp_postfix_expression (pp
, e
);
1404 ( type-name ) cast-expression */
1407 pp_c_cast_expression (c_pretty_printer
*pp
, tree e
)
1409 switch (TREE_CODE (e
))
1412 case FIX_TRUNC_EXPR
:
1414 pp_c_type_cast (pp
, TREE_TYPE (e
));
1415 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 0));
1419 pp_unary_expression (pp
, e
);
1423 /* multiplicative-expression:
1425 multiplicative-expression * cast-expression
1426 multiplicative-expression / cast-expression
1427 multiplicative-expression % cast-expression */
1430 pp_c_multiplicative_expression (c_pretty_printer
*pp
, tree e
)
1432 enum tree_code code
= TREE_CODE (e
);
1436 case TRUNC_DIV_EXPR
:
1437 case TRUNC_MOD_EXPR
:
1438 pp_multiplicative_expression (pp
, TREE_OPERAND (e
, 0));
1439 pp_c_whitespace (pp
);
1440 if (code
== MULT_EXPR
)
1442 else if (code
== TRUNC_DIV_EXPR
)
1446 pp_c_whitespace (pp
);
1447 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 1));
1451 pp_c_cast_expression (pp
, e
);
1456 /* additive-expression:
1457 multiplicative-expression
1458 additive-expression + multiplicative-expression
1459 additive-expression - multiplicative-expression */
1462 pp_c_additive_expression (c_pretty_printer
*pp
, tree e
)
1464 enum tree_code code
= TREE_CODE (e
);
1469 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 0));
1470 pp_c_whitespace (pp
);
1471 if (code
== PLUS_EXPR
)
1475 pp_c_whitespace (pp
);
1476 pp_multiplicative_expression (pp
, TREE_OPERAND (e
, 1));
1480 pp_multiplicative_expression (pp
, e
);
1485 /* additive-expression:
1487 shift-expression << additive-expression
1488 shift-expression >> additive-expression */
1491 pp_c_shift_expression (c_pretty_printer
*pp
, tree e
)
1493 enum tree_code code
= TREE_CODE (e
);
1498 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 0));
1499 pp_c_whitespace (pp
);
1500 pp_identifier (pp
, code
== LSHIFT_EXPR
? "<<" : ">>");
1501 pp_c_whitespace (pp
);
1502 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 1));
1506 pp_c_additive_expression (pp
, e
);
1510 /* relational-expression:
1512 relational-expression < shift-expression
1513 relational-expression > shift-expression
1514 relational-expression <= shift-expression
1515 relational-expression >= shift-expression */
1518 pp_c_relational_expression (c_pretty_printer
*pp
, tree e
)
1520 enum tree_code code
= TREE_CODE (e
);
1527 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 0));
1528 pp_c_whitespace (pp
);
1529 if (code
== LT_EXPR
)
1531 else if (code
== GT_EXPR
)
1533 else if (code
== LE_EXPR
)
1534 pp_identifier (pp
, "<=");
1535 else if (code
== GE_EXPR
)
1536 pp_identifier (pp
, ">=");
1537 pp_c_whitespace (pp
);
1538 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 1));
1542 pp_c_shift_expression (pp
, e
);
1547 /* equality-expression:
1548 relational-expression
1549 equality-expression == relational-expression
1550 equality-equality != relational-expression */
1553 pp_c_equality_expression (c_pretty_printer
*pp
, tree e
)
1555 enum tree_code code
= TREE_CODE (e
);
1560 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 0));
1561 pp_c_whitespace (pp
);
1562 pp_identifier (pp
, code
== EQ_EXPR
? "==" : "!=");
1563 pp_c_whitespace (pp
);
1564 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 1));
1568 pp_c_relational_expression (pp
, e
);
1575 AND-expression & equality-equality */
1578 pp_c_and_expression (c_pretty_printer
*pp
, tree e
)
1580 if (TREE_CODE (e
) == BIT_AND_EXPR
)
1582 pp_c_and_expression (pp
, TREE_OPERAND (e
, 0));
1583 pp_c_whitespace (pp
);
1585 pp_c_whitespace (pp
);
1586 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 1));
1589 pp_c_equality_expression (pp
, e
);
1592 /* exclusive-OR-expression:
1594 exclusive-OR-expression ^ AND-expression */
1597 pp_c_exclusive_or_expression (c_pretty_printer
*pp
, tree e
)
1599 if (TREE_CODE (e
) == BIT_XOR_EXPR
)
1601 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
1602 pp_c_maybe_whitespace (pp
);
1604 pp_c_whitespace (pp
);
1605 pp_c_and_expression (pp
, TREE_OPERAND (e
, 1));
1608 pp_c_and_expression (pp
, e
);
1611 /* inclusive-OR-expression:
1612 exclusive-OR-expression
1613 inclusive-OR-expression | exclusive-OR-expression */
1616 pp_c_inclusive_or_expression (c_pretty_printer
*pp
, tree e
)
1618 if (TREE_CODE (e
) == BIT_IOR_EXPR
)
1620 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
1621 pp_c_whitespace (pp
);
1623 pp_c_whitespace (pp
);
1624 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
1627 pp_c_exclusive_or_expression (pp
, e
);
1630 /* logical-AND-expression:
1631 inclusive-OR-expression
1632 logical-AND-expression && inclusive-OR-expression */
1635 pp_c_logical_and_expression (c_pretty_printer
*pp
, tree e
)
1637 if (TREE_CODE (e
) == TRUTH_ANDIF_EXPR
)
1639 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 0));
1640 pp_c_whitespace (pp
);
1641 pp_identifier (pp
, "&&");
1642 pp_c_whitespace (pp
);
1643 pp_c_inclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
1646 pp_c_inclusive_or_expression (pp
, e
);
1649 /* logical-OR-expression:
1650 logical-AND-expression
1651 logical-OR-expression || logical-AND-expression */
1654 pp_c_logical_or_expression (c_pretty_printer
*pp
, tree e
)
1656 if (TREE_CODE (e
) == TRUTH_ORIF_EXPR
)
1658 pp_c_logical_or_expression (pp
, TREE_OPERAND (e
, 0));
1659 pp_c_whitespace (pp
);
1660 pp_identifier (pp
, "||");
1661 pp_c_whitespace (pp
);
1662 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 1));
1665 pp_c_logical_and_expression (pp
, e
);
1668 /* conditional-expression:
1669 logical-OR-expression
1670 logical-OR-expression ? expression : conditional-expression */
1673 pp_c_conditional_expression (c_pretty_printer
*pp
, tree e
)
1675 if (TREE_CODE (e
) == COND_EXPR
)
1677 pp_c_logical_or_expression (pp
, TREE_OPERAND (e
, 0));
1678 pp_c_whitespace (pp
);
1680 pp_c_whitespace (pp
);
1681 pp_expression (pp
, TREE_OPERAND (e
, 1));
1682 pp_c_whitespace (pp
);
1684 pp_c_whitespace (pp
);
1685 pp_c_conditional_expression (pp
, TREE_OPERAND (e
, 2));
1688 pp_c_logical_or_expression (pp
, e
);
1692 /* assignment-expression:
1693 conditional-expression
1694 unary-expression assignment-operator assignment-expression
1696 assignment-expression: one of
1697 = *= /= %= += -= >>= <<= &= ^= |= */
1700 pp_c_assignment_expression (c_pretty_printer
*pp
, tree e
)
1702 if (TREE_CODE (e
) == MODIFY_EXPR
|| TREE_CODE (e
) == INIT_EXPR
)
1704 pp_c_unary_expression (pp
, TREE_OPERAND (e
, 0));
1705 pp_c_whitespace (pp
);
1708 pp_c_expression (pp
, TREE_OPERAND (e
, 1));
1711 pp_c_conditional_expression (pp
, e
);
1715 assignment-expression
1716 expression , assignment-expression
1718 Implementation note: instead of going through the usual recursion
1719 chain, I take the liberty of dispatching nodes to the appropriate
1720 functions. This makes some redundancy, but it worths it. That also
1721 prevents a possible infinite recursion between pp_c_primary_expression ()
1722 and pp_c_expression (). */
1725 pp_c_expression (c_pretty_printer
*pp
, tree e
)
1727 switch (TREE_CODE (e
))
1730 pp_c_integer_constant (pp
, e
);
1734 pp_c_floating_constant (pp
, e
);
1738 pp_c_string_literal (pp
, e
);
1741 case IDENTIFIER_NODE
:
1751 pp_primary_expression (pp
, e
);
1754 case POSTINCREMENT_EXPR
:
1755 case POSTDECREMENT_EXPR
:
1765 case COMPOUND_LITERAL_EXPR
:
1767 pp_postfix_expression (pp
, e
);
1775 case TRUTH_NOT_EXPR
:
1776 case PREINCREMENT_EXPR
:
1777 case PREDECREMENT_EXPR
:
1782 pp_c_unary_expression (pp
, e
);
1786 case FIX_TRUNC_EXPR
:
1788 pp_c_cast_expression (pp
, e
);
1792 case TRUNC_MOD_EXPR
:
1793 case TRUNC_DIV_EXPR
:
1794 pp_multiplicative_expression (pp
, e
);
1799 pp_c_shift_expression (pp
, e
);
1806 pp_c_relational_expression (pp
, e
);
1810 pp_c_and_expression (pp
, e
);
1814 pp_c_exclusive_or_expression (pp
, e
);
1818 pp_c_inclusive_or_expression (pp
, e
);
1821 case TRUTH_ANDIF_EXPR
:
1822 pp_c_logical_and_expression (pp
, e
);
1825 case TRUTH_ORIF_EXPR
:
1826 pp_c_logical_or_expression (pp
, e
);
1831 pp_c_equality_expression (pp
, e
);
1835 pp_conditional_expression (pp
, e
);
1840 pp_c_additive_expression (pp
, e
);
1845 pp_assignment_expression (pp
, e
);
1849 pp_c_left_paren (pp
);
1850 pp_expression (pp
, TREE_OPERAND (e
, 0));
1851 pp_separate_with (pp
, ',');
1852 pp_assignment_expression (pp
, TREE_OPERAND (e
, 1));
1853 pp_c_right_paren (pp
);
1857 case NON_LVALUE_EXPR
:
1860 pp_expression (pp
, TREE_OPERAND (e
, 0));
1864 pp_postfix_expression (pp
, TREE_OPERAND (e
, 1));
1868 pp_unsupported_tree (pp
, e
);
1880 expression-statement
1886 pp_c_statement (c_pretty_printer
*pp
, tree stmt
)
1888 enum tree_code code
;
1893 code
= TREE_CODE (stmt
);
1896 case STATEMENT_LIST
:
1898 tree_stmt_iterator tsi
;
1900 if (pp_needs_newline (pp
))
1901 pp_newline_and_indent (pp
, 0);
1902 pp_c_left_brace (pp
);
1903 pp_newline_and_indent (pp
, 3);
1904 for (tsi
= tsi_start (stmt
); !tsi_end_p (tsi
); tsi_next (&tsi
))
1905 pp_statement (pp
, tsi_stmt (tsi
));
1906 pp_newline_and_indent (pp
, -3);
1907 pp_c_right_brace (pp
);
1908 pp_needs_newline (pp
) = true;
1912 /* compound-statement:
1913 { block-item-list(opt) }
1917 block-item-list block-item
1923 if (pp_needs_newline (pp
))
1924 pp_newline_and_indent (pp
, 0);
1925 pp_c_left_brace (pp
);
1926 pp_newline_and_indent (pp
, 3);
1927 pp_statement (pp
, COMPOUND_BODY (stmt
));
1928 pp_newline_and_indent (pp
, -3);
1929 pp_c_right_brace (pp
);
1930 pp_needs_newline (pp
) = true;
1933 /* expression-statement:
1934 expression(opt) ; */
1937 if (pp_needs_newline (pp
))
1938 pp_newline_and_indent (pp
, 0);
1940 tree e
= code
== EXPR_STMT
1941 ? EXPR_STMT_EXPR (stmt
)
1942 : CLEANUP_EXPR (stmt
);
1944 pp_expression (pp
, e
);
1946 pp_c_semicolon (pp
);
1947 pp_needs_newline (pp
) = true;
1950 /* selection-statement:
1951 if ( expression ) statement
1952 if ( expression ) statement else statement
1953 switch ( expression ) statement */
1955 if (pp_needs_newline (pp
))
1956 pp_newline_and_indent (pp
, 0);
1957 pp_c_identifier (pp
, "if");
1958 pp_c_whitespace (pp
);
1959 pp_c_left_paren (pp
);
1960 pp_expression (pp
, IF_COND (stmt
));
1961 pp_c_right_paren (pp
);
1962 pp_newline_and_indent (pp
, 3);
1963 pp_statement (pp
, THEN_CLAUSE (stmt
));
1964 pp_newline_and_indent (pp
, -3);
1965 if (ELSE_CLAUSE (stmt
))
1967 tree else_clause
= ELSE_CLAUSE (stmt
);
1968 pp_c_identifier (pp
, "else");
1969 if (TREE_CODE (else_clause
) == IF_STMT
)
1970 pp_c_whitespace (pp
);
1972 pp_newline_and_indent (pp
, 3);
1973 pp_statement (pp
, else_clause
);
1974 if (TREE_CODE (else_clause
) != IF_STMT
)
1975 pp_newline_and_indent (pp
, -3);
1980 if (pp_needs_newline (pp
))
1981 pp_newline_and_indent (pp
, 0);
1982 pp_c_identifier (pp
, "switch");
1984 pp_c_left_paren (pp
);
1985 pp_expression (pp
, SWITCH_COND (stmt
));
1986 pp_c_right_paren (pp
);
1987 pp_indentation (pp
) += 3;
1988 pp_needs_newline (pp
) = true;
1989 pp_statement (pp
, SWITCH_BODY (stmt
));
1990 pp_newline_and_indent (pp
, -3);
1993 /* iteration-statement:
1994 while ( expression ) statement
1995 do statement while ( expression ) ;
1996 for ( expression(opt) ; expression(opt) ; expression(opt) ) statement
1997 for ( declaration expression(opt) ; expression(opt) ) statement */
1999 if (pp_needs_newline (pp
))
2000 pp_newline_and_indent (pp
, 0);
2001 pp_c_identifier (pp
, "while");
2003 pp_c_left_paren (pp
);
2004 pp_expression (pp
, WHILE_COND (stmt
));
2005 pp_c_right_paren (pp
);
2006 pp_newline_and_indent (pp
, 3);
2007 pp_statement (pp
, WHILE_BODY (stmt
));
2008 pp_indentation (pp
) -= 3;
2009 pp_needs_newline (pp
) = true;
2013 if (pp_needs_newline (pp
))
2014 pp_newline_and_indent (pp
, 0);
2015 pp_c_identifier (pp
, "do");
2016 pp_newline_and_indent (pp
, 3);
2017 pp_statement (pp
, DO_BODY (stmt
));
2018 pp_newline_and_indent (pp
, -3);
2019 pp_c_identifier (pp
, "while");
2021 pp_c_left_paren (pp
);
2022 pp_expression (pp
, DO_COND (stmt
));
2023 pp_c_right_paren (pp
);
2024 pp_c_semicolon (pp
);
2025 pp_needs_newline (pp
) = true;
2029 if (pp_needs_newline (pp
))
2030 pp_newline_and_indent (pp
, 0);
2031 pp_c_identifier (pp
, "for");
2033 pp_c_left_paren (pp
);
2034 if (FOR_INIT_STMT (stmt
))
2035 pp_statement (pp
, FOR_INIT_STMT (stmt
));
2037 pp_c_semicolon (pp
);
2038 pp_needs_newline (pp
) = false;
2039 pp_c_whitespace (pp
);
2040 if (FOR_COND (stmt
))
2041 pp_expression (pp
, FOR_COND (stmt
));
2042 pp_c_semicolon (pp
);
2043 pp_needs_newline (pp
) = false;
2044 pp_c_whitespace (pp
);
2045 if (FOR_EXPR (stmt
))
2046 pp_expression (pp
, FOR_EXPR (stmt
));
2047 pp_c_right_paren (pp
);
2048 pp_newline_and_indent (pp
, 3);
2049 pp_statement (pp
, FOR_BODY (stmt
));
2050 pp_indentation (pp
) -= 3;
2051 pp_needs_newline (pp
) = true;
2057 return expression(opt) ; */
2060 if (pp_needs_newline (pp
))
2061 pp_newline_and_indent (pp
, 0);
2062 pp_identifier (pp
, code
== BREAK_STMT
? "break" : "continue");
2063 pp_c_semicolon (pp
);
2064 pp_needs_newline (pp
) = true;
2069 tree e
= RETURN_STMT_EXPR (stmt
);
2070 if (pp_needs_newline (pp
))
2071 pp_newline_and_indent (pp
, 0);
2072 pp_c_identifier (pp
, "return");
2073 pp_c_whitespace (pp
);
2076 if (TREE_CODE (e
) == INIT_EXPR
2077 && TREE_CODE (TREE_OPERAND (e
, 0)) == RESULT_DECL
)
2078 e
= TREE_OPERAND (e
, 1);
2079 pp_expression (pp
, e
);
2081 pp_c_semicolon (pp
);
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;
2094 pp_unsupported_tree (pp
, stmt
);
2099 /* Initialize the PRETTY-PRINTER for handling C codes. */
2102 pp_c_pretty_printer_init (c_pretty_printer
*pp
)
2104 pp
->offset_list
= 0;
2106 pp
->declaration
= pp_c_declaration
;
2107 pp
->declaration_specifiers
= pp_c_declaration_specifiers
;
2108 pp
->declarator
= pp_c_declarator
;
2109 pp
->direct_declarator
= pp_c_direct_declarator
;
2110 pp
->type_specifier_seq
= pp_c_specifier_qualifier_list
;
2111 pp
->abstract_declarator
= pp_c_abstract_declarator
;
2112 pp
->direct_abstract_declarator
= pp_c_direct_abstract_declarator
;
2113 pp
->ptr_operator
= pp_c_pointer
;
2114 pp
->parameter_list
= pp_c_parameter_type_list
;
2115 pp
->type_id
= pp_c_type_id
;
2116 pp
->simple_type_specifier
= pp_c_type_specifier
;
2117 pp
->function_specifier
= pp_c_function_specifier
;
2118 pp
->storage_class_specifier
= pp_c_storage_class_specifier
;
2120 pp
->statement
= pp_c_statement
;
2122 pp
->id_expression
= pp_c_id_expression
;
2123 pp
->primary_expression
= pp_c_primary_expression
;
2124 pp
->postfix_expression
= pp_c_postfix_expression
;
2125 pp
->unary_expression
= pp_c_unary_expression
;
2126 pp
->initializer
= pp_c_initializer
;
2127 pp
->multiplicative_expression
= pp_c_multiplicative_expression
;
2128 pp
->conditional_expression
= pp_c_conditional_expression
;
2129 pp
->assignment_expression
= pp_c_assignment_expression
;
2130 pp
->expression
= pp_c_expression
;
2134 /* Print the tree T in full, on file FILE. */
2137 print_c_tree (FILE *file
, tree t
)
2139 static c_pretty_printer pp_rec
;
2140 static bool initialized
= 0;
2141 c_pretty_printer
*pp
= &pp_rec
;
2146 pp_construct (pp_base (pp
), NULL
, 0);
2147 pp_c_pretty_printer_init (pp
);
2148 pp_needs_newline (pp
) = true;
2150 pp_base (pp
)->buffer
->stream
= file
;
2152 pp_statement (pp
, t
);
2158 /* Print the tree T in full, on stderr. */
2161 debug_c_tree (tree t
)
2163 print_c_tree (stderr
, t
);
2164 fputc ('\n', stderr
);
2167 /* Output the DECL_NAME of T. If T has no DECL_NAME, output a string made
2168 up of T's memory address. */
2171 pp_c_tree_decl_identifier (c_pretty_printer
*pp
, tree t
)
2179 name
= IDENTIFIER_POINTER (DECL_NAME (t
));
2182 static char xname
[8];
2183 sprintf (xname
, "<U%4x>", ((unsigned)((unsigned long)(t
) & 0xffff)));
2187 pp_c_identifier (pp
, name
);