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 "diagnostic.h"
31 /* The pretty-printer code is primarily designed to closely follow
32 (GNU) C and C++ grammars. That is to be contrasted with spaghetti
33 codes we used to have in the past. Following a structured
34 approach (preferably the official grammars) is believed to make it
35 much easier to add extensions and nifty pretty-printing effects that
36 takes expression or declaration contexts into account. */
39 #define pp_c_maybe_whitespace(PP) \
41 if (pp_base (PP)->padding == pp_before) \
42 pp_c_whitespace (PP); \
46 static void pp_c_char (c_pretty_printer
*, int);
48 /* postfix-expression */
49 static void pp_c_initializer_list (c_pretty_printer
*, tree
);
50 static void pp_c_brace_enclosed_initializer_list (c_pretty_printer
*, tree
);
52 static void pp_c_multiplicative_expression (c_pretty_printer
*, tree
);
53 static void pp_c_additive_expression (c_pretty_printer
*, tree
);
54 static void pp_c_shift_expression (c_pretty_printer
*, tree
);
55 static void pp_c_relational_expression (c_pretty_printer
*, tree
);
56 static void pp_c_equality_expression (c_pretty_printer
*, tree
);
57 static void pp_c_and_expression (c_pretty_printer
*, tree
);
58 static void pp_c_exclusive_or_expression (c_pretty_printer
*, tree
);
59 static void pp_c_inclusive_or_expression (c_pretty_printer
*, tree
);
60 static void pp_c_logical_and_expression (c_pretty_printer
*, tree
);
61 static void pp_c_conditional_expression (c_pretty_printer
*, tree
);
62 static void pp_c_assignment_expression (c_pretty_printer
*, tree
);
67 /* Helper functions. */
70 pp_c_whitespace (c_pretty_printer
*pp
)
73 pp_base (pp
)->padding
= pp_none
;
77 pp_c_left_paren (c_pretty_printer
*pp
)
80 pp_base (pp
)->padding
= pp_none
;
84 pp_c_right_paren (c_pretty_printer
*pp
)
87 pp_base (pp
)->padding
= pp_none
;
91 pp_c_left_brace (c_pretty_printer
*pp
)
94 pp_base (pp
)->padding
= pp_none
;
98 pp_c_right_brace (c_pretty_printer
*pp
)
101 pp_base (pp
)->padding
= pp_none
;
105 pp_c_left_bracket (c_pretty_printer
*pp
)
107 pp_left_bracket (pp
);
108 pp_base (pp
)->padding
= pp_none
;
112 pp_c_right_bracket (c_pretty_printer
*pp
)
114 pp_right_bracket (pp
);
115 pp_base (pp
)->padding
= pp_none
;
119 pp_c_dot (c_pretty_printer
*pp
)
122 pp_base (pp
)->padding
= pp_none
;
126 pp_c_ampersand (c_pretty_printer
*pp
)
129 pp_base (pp
)->padding
= pp_none
;
133 pp_c_star (c_pretty_printer
*pp
)
136 pp_base (pp
)->padding
= pp_none
;
140 pp_c_arrow (c_pretty_printer
*pp
)
143 pp_base (pp
)->padding
= pp_none
;
147 pp_c_semicolon (c_pretty_printer
*pp
)
150 pp_base (pp
)->padding
= pp_none
;
154 pp_c_complement (c_pretty_printer
*pp
)
157 pp_base (pp
)->padding
= pp_none
;
161 pp_c_exclamation (c_pretty_printer
*pp
)
164 pp_base (pp
)->padding
= pp_none
;
167 /* Print out the external representation of CV-QUALIFIER. */
170 pp_c_cv_qualifier (c_pretty_printer
*pp
, const char *cv
)
172 const char *p
= pp_last_position_in_text (pp
);
173 /* The C programming language does not have references, but it is much
174 simpler to handle those here rather than going through the same
175 logic in the C++ pretty-printer. */
176 if (p
!= NULL
&& (*p
== '*' || *p
== '&'))
177 pp_c_whitespace (pp
);
178 pp_c_identifier (pp
, cv
);
181 /* Pretty-print T using the type-cast notation '( type-name )'. */
184 pp_c_type_cast (c_pretty_printer
*pp
, tree t
)
186 pp_c_left_paren (pp
);
188 pp_c_right_paren (pp
);
191 /* We're about to pretty-print a pointer type as indicated by T.
192 Output a whitespace, if needed, preparing for subsequent output. */
195 pp_c_space_for_pointer_operator (c_pretty_printer
*pp
, tree t
)
197 if (POINTER_TYPE_P (t
))
199 tree pointee
= strip_pointer_operator (TREE_TYPE (t
));
200 if (TREE_CODE (pointee
) != ARRAY_TYPE
201 && TREE_CODE (pointee
) != FUNCTION_TYPE
)
202 pp_c_whitespace (pp
);
209 /* C++ cv-qualifiers are called type-qualifiers in C. Print out the
210 cv-qualifiers of T. If T is a declaration then it is the cv-qualifier
211 of its type. Take care of possible extensions.
215 type-qualifier-list type-qualifier
220 __restrict__ -- GNU C
224 pp_c_type_qualifier_list (c_pretty_printer
*pp
, tree t
)
231 qualifiers
= TYPE_QUALS (t
);
232 if (qualifiers
& TYPE_QUAL_CONST
)
233 pp_c_cv_qualifier (pp
, "const");
234 if (qualifiers
& TYPE_QUAL_VOLATILE
)
235 pp_c_cv_qualifier (pp
, "volatile");
236 if (qualifiers
& TYPE_QUAL_RESTRICT
)
237 pp_c_cv_qualifier (pp
, flag_isoc99
? "restrict" : "__restrict__");
241 * type-qualifier-list(opt)
242 * type-qualifier-list(opt) pointer */
245 pp_c_pointer (c_pretty_printer
*pp
, tree t
)
247 if (!TYPE_P (t
) && TREE_CODE (t
) != TYPE_DECL
)
249 switch (TREE_CODE (t
))
252 /* It is easier to handle C++ reference types here. */
254 if (TREE_CODE (TREE_TYPE (t
)) == POINTER_TYPE
)
255 pp_c_pointer (pp
, TREE_TYPE (t
));
256 if (TREE_CODE (t
) == POINTER_TYPE
)
260 pp_c_type_qualifier_list (pp
, t
);
264 pp_unsupported_tree (pp
, t
);
281 struct-or-union-specifier
286 simple-type-specifier:
291 pp_c_type_specifier (c_pretty_printer
*pp
, tree t
)
293 const enum tree_code code
= TREE_CODE (t
);
297 pp_c_identifier (pp
, "<type-error>");
300 case IDENTIFIER_NODE
:
301 pp_c_tree_decl_identifier (pp
, t
);
312 t
= c_common_type_for_mode (TYPE_MODE (t
), TYPE_UNSIGNED (t
));
313 pp_c_type_specifier (pp
, t
);
318 pp_id_expression (pp
, t
);
320 pp_c_identifier (pp
, "<typedef-error>");
326 if (code
== UNION_TYPE
)
327 pp_c_identifier (pp
, "union");
328 else if (code
== RECORD_TYPE
)
329 pp_c_identifier (pp
, "struct");
330 else if (code
== ENUMERAL_TYPE
)
331 pp_c_identifier (pp
, "enum");
333 pp_c_identifier (pp
, "<tag-error>");
336 pp_id_expression (pp
, TYPE_NAME (t
));
338 pp_c_identifier (pp
, "<anonymous>");
342 pp_unsupported_tree (pp
, t
);
347 /* specifier-qualifier-list:
348 type-specifier specifier-qualifier-list-opt
349 type-qualifier specifier-qualifier-list-opt
352 Implementation note: Because of the non-linearities in array or
353 function declarations, this routine prints not just the
354 specifier-qualifier-list of such entities or types of such entities,
355 but also the 'pointer' production part of their declarators. The
356 remaining part is done by pp_declarator or pp_c_abstract_declarator. */
359 pp_c_specifier_qualifier_list (c_pretty_printer
*pp
, tree t
)
361 const enum tree_code code
= TREE_CODE (t
);
363 if (TREE_CODE (t
) != POINTER_TYPE
)
364 pp_c_type_qualifier_list (pp
, t
);
370 /* Get the types-specifier of this type. */
371 tree pointee
= strip_pointer_operator (TREE_TYPE (t
));
372 pp_c_specifier_qualifier_list (pp
, pointee
);
373 if (TREE_CODE (pointee
) == ARRAY_TYPE
374 || TREE_CODE (pointee
) == FUNCTION_TYPE
)
376 pp_c_whitespace (pp
);
377 pp_c_left_paren (pp
);
379 pp_ptr_operator (pp
, t
);
385 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
390 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
391 if (code
== COMPLEX_TYPE
)
392 pp_c_identifier (pp
, flag_isoc99
? "_Complex" : "__complex__");
393 else if (code
== VECTOR_TYPE
)
394 pp_c_identifier (pp
, "__vector__");
398 pp_simple_type_specifier (pp
, t
);
403 /* parameter-type-list:
408 parameter-declaration
409 parameter-list , parameter-declaration
411 parameter-declaration:
412 declaration-specifiers declarator
413 declaration-specifiers abstract-declarator(opt) */
416 pp_c_parameter_type_list (c_pretty_printer
*pp
, tree t
)
418 bool want_parm_decl
= DECL_P (t
) && !(pp
->flags
& pp_c_flag_abstract
);
419 tree parms
= want_parm_decl
? DECL_ARGUMENTS (t
) : TYPE_ARG_TYPES (t
);
420 pp_c_left_paren (pp
);
421 if (parms
== void_list_node
)
422 pp_c_identifier (pp
, "void");
426 for ( ; parms
&& parms
!= void_list_node
; parms
= TREE_CHAIN (parms
))
429 pp_separate_with (pp
, ',');
431 pp_declaration_specifiers
432 (pp
, want_parm_decl
? parms
: TREE_VALUE (parms
));
434 pp_declarator (pp
, parms
);
436 pp_abstract_declarator (pp
, TREE_VALUE (parms
));
439 pp_c_right_paren (pp
);
442 /* abstract-declarator:
444 pointer(opt) direct-abstract-declarator */
447 pp_c_abstract_declarator (c_pretty_printer
*pp
, tree t
)
449 if (TREE_CODE (t
) == POINTER_TYPE
)
451 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
452 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
453 pp_c_right_paren (pp
);
457 pp_direct_abstract_declarator (pp
, t
);
460 /* direct-abstract-declarator:
461 ( abstract-declarator )
462 direct-abstract-declarator(opt) [ assignment-expression(opt) ]
463 direct-abstract-declarator(opt) [ * ]
464 direct-abstract-declarator(opt) ( parameter-type-list(opt) ) */
467 pp_c_direct_abstract_declarator (c_pretty_printer
*pp
, tree t
)
469 switch (TREE_CODE (t
))
472 pp_abstract_declarator (pp
, t
);
476 pp_c_parameter_type_list (pp
, t
);
477 pp_direct_abstract_declarator (pp
, TREE_TYPE (t
));
481 pp_c_left_bracket (pp
);
483 pp_expression (pp
, TYPE_MAX_VALUE (TYPE_DOMAIN (t
)));
484 pp_c_right_bracket (pp
);
485 pp_direct_abstract_declarator (pp
, TREE_TYPE (t
));
488 case IDENTIFIER_NODE
:
502 pp_unsupported_tree (pp
, t
);
508 specifier-qualifier-list abstract-declarator(opt) */
511 pp_c_type_id (c_pretty_printer
*pp
, tree t
)
513 pp_c_specifier_qualifier_list (pp
, t
);
514 pp_abstract_declarator (pp
, t
);
517 /* storage-class-specifier:
525 pp_c_storage_class_specifier (c_pretty_printer
*pp
, tree t
)
527 if (TREE_CODE (t
) == TYPE_DECL
)
528 pp_c_identifier (pp
, "typedef");
531 if (DECL_REGISTER (t
))
532 pp_c_identifier (pp
, "register");
533 else if (TREE_STATIC (t
) && TREE_CODE (t
) == VAR_DECL
)
534 pp_c_identifier (pp
, "static");
538 /* function-specifier:
542 pp_c_function_specifier (c_pretty_printer
*pp
, tree t
)
544 if (TREE_CODE (t
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (t
))
545 pp_c_identifier (pp
, "inline");
548 /* declaration-specifiers:
549 storage-class-specifier declaration-specifiers(opt)
550 type-specifier declaration-specifiers(opt)
551 type-qualifier declaration-specifiers(opt)
552 function-specifier declaration-specifiers(opt) */
555 pp_c_declaration_specifiers (c_pretty_printer
*pp
, tree t
)
557 pp_storage_class_specifier (pp
, t
);
558 pp_function_specifier (pp
, t
);
559 pp_c_specifier_qualifier_list (pp
, DECL_P (t
) ? TREE_TYPE (t
) : t
);
565 direct-declarator [ type-qualifier-list(opt) assignment-expression(opt) ]
566 direct-declarator [ static type-qualifier-list(opt) assignment-expression(opt)]
567 direct-declarator [ type-qualifier-list static assignment-expression ]
568 direct-declarator [ type-qualifier-list * ]
569 direct-declarator ( parameter-type-list )
570 direct-declarator ( identifier-list(opt) ) */
573 pp_c_direct_declarator (c_pretty_printer
*pp
, tree t
)
575 switch (TREE_CODE (t
))
582 pp_c_space_for_pointer_operator (pp
, TREE_TYPE (t
));
583 pp_c_tree_decl_identifier (pp
, t
);
588 pp_abstract_declarator (pp
, TREE_TYPE (t
));
592 pp_parameter_list (pp
, t
);
593 pp_abstract_declarator (pp
, TREE_TYPE (t
));
597 pp_c_space_for_pointer_operator (pp
, TREE_TYPE (TREE_TYPE (t
)));
598 pp_c_tree_decl_identifier (pp
, t
);
599 if (pp_c_base (pp
)->flags
& pp_c_flag_abstract
)
600 pp_abstract_declarator (pp
, TREE_TYPE (t
));
603 pp_parameter_list (pp
, t
);
604 pp_abstract_declarator (pp
, TREE_TYPE (TREE_TYPE (t
)));
616 pp_unsupported_tree (pp
, t
);
623 pointer(opt) direct-declarator */
626 pp_c_declarator (c_pretty_printer
*pp
, tree t
)
628 switch (TREE_CODE (t
))
644 pp_direct_declarator (pp
, t
);
649 pp_unsupported_tree (pp
, t
);
655 declaration-specifiers init-declarator-list(opt) ; */
658 pp_c_declaration (c_pretty_printer
*pp
, tree t
)
660 pp_declaration_specifiers (pp
, t
);
661 pp_c_init_declarator (pp
, t
);
664 /* Pretty-print ATTRIBUTES using GNU C extension syntax. */
667 pp_c_attributes (c_pretty_printer
*pp
, tree attributes
)
669 if (attributes
== NULL_TREE
)
672 pp_c_identifier (pp
, "__attribute__");
673 pp_c_left_paren (pp
);
674 pp_c_left_paren (pp
);
675 for (; attributes
!= NULL_TREE
; attributes
= TREE_CHAIN (attributes
))
677 pp_tree_identifier (pp
, TREE_PURPOSE (attributes
));
678 if (TREE_VALUE (attributes
))
679 pp_c_call_argument_list (pp
, TREE_VALUE (attributes
));
681 if (TREE_CHAIN (attributes
))
682 pp_separate_with (pp
, ',');
684 pp_c_right_paren (pp
);
685 pp_c_right_paren (pp
);
688 /* function-definition:
689 declaration-specifiers declarator compound-statement */
692 pp_c_function_definition (c_pretty_printer
*pp
, tree t
)
694 pp_declaration_specifiers (pp
, t
);
695 pp_declarator (pp
, t
);
696 pp_needs_newline (pp
) = true;
697 pp_statement (pp
, DECL_SAVED_TREE (t
));
705 /* Print out a c-char. */
708 pp_c_char (c_pretty_printer
*pp
, int c
)
713 pp_string (pp
, "\\n");
716 pp_string (pp
, "\\t");
719 pp_string (pp
, "\\v");
722 pp_string (pp
, "\\b");
725 pp_string (pp
, "\\r");
728 pp_string (pp
, "\\f");
731 pp_string (pp
, "\\a");
734 pp_string (pp
, "\\\\");
737 pp_string (pp
, "\\'");
740 pp_string (pp
, "\\\"");
744 pp_character (pp
, c
);
746 pp_scalar (pp
, "\\%03o", (unsigned) c
);
751 /* Print out a STRING literal. */
754 pp_c_string_literal (c_pretty_printer
*pp
, tree s
)
756 const char *p
= TREE_STRING_POINTER (s
);
757 int n
= TREE_STRING_LENGTH (s
) - 1;
760 for (i
= 0; i
< n
; ++i
)
761 pp_c_char (pp
, p
[i
]);
765 /* Pretty-print an INTEGER literal. */
768 pp_c_integer_constant (c_pretty_printer
*pp
, tree i
)
770 tree type
= TREE_TYPE (i
);
772 if (TREE_INT_CST_HIGH (i
) == 0)
773 pp_wide_integer (pp
, TREE_INT_CST_LOW (i
));
776 if (tree_int_cst_sgn (i
) < 0)
779 i
= build_int_2 (-TREE_INT_CST_LOW (i
),
780 ~TREE_INT_CST_HIGH (i
) + !TREE_INT_CST_LOW (i
));
782 sprintf (pp_buffer (pp
)->digit_buffer
,
783 HOST_WIDE_INT_PRINT_DOUBLE_HEX
,
784 TREE_INT_CST_HIGH (i
), TREE_INT_CST_LOW (i
));
785 pp_string (pp
, pp_buffer (pp
)->digit_buffer
);
787 if (TYPE_UNSIGNED (type
))
788 pp_character (pp
, 'u');
789 if (type
== long_integer_type_node
|| type
== long_unsigned_type_node
)
790 pp_character (pp
, 'l');
791 else if (type
== long_long_integer_type_node
792 || type
== long_long_unsigned_type_node
)
793 pp_string (pp
, "ll");
796 /* Print out a CHARACTER literal. */
799 pp_c_character_constant (c_pretty_printer
*pp
, tree c
)
801 tree type
= TREE_TYPE (c
);
802 if (type
== wchar_type_node
)
803 pp_character (pp
, 'L');
805 if (host_integerp (c
, TYPE_UNSIGNED (type
)))
806 pp_c_char (pp
, tree_low_cst (c
, TYPE_UNSIGNED (type
)));
808 pp_scalar (pp
, "\\x%x", (unsigned) TREE_INT_CST_LOW (c
));
812 /* Print out a BOOLEAN literal. */
815 pp_c_bool_constant (c_pretty_printer
*pp
, tree b
)
817 if (b
== boolean_false_node
)
819 if (c_dialect_cxx ())
820 pp_c_identifier (pp
, "false");
821 else if (flag_isoc99
)
822 pp_c_identifier (pp
, "_False");
824 pp_unsupported_tree (pp
, b
);
826 else if (b
== boolean_true_node
)
828 if (c_dialect_cxx ())
829 pp_c_identifier (pp
, "true");
830 else if (flag_isoc99
)
831 pp_c_identifier (pp
, "_True");
833 pp_unsupported_tree (pp
, b
);
835 else if (TREE_CODE (b
) == INTEGER_CST
)
836 pp_c_integer_constant (pp
, b
);
838 pp_unsupported_tree (pp
, b
);
841 /* Attempt to print out an ENUMERATOR. Return true on success. Else return
842 false; that means the value was obtained by a cast, in which case
843 print out the type-id part of the cast-expression -- the casted value
844 is then printed by pp_c_integer_literal. */
847 pp_c_enumeration_constant (c_pretty_printer
*pp
, tree e
)
849 bool value_is_named
= true;
850 tree type
= TREE_TYPE (e
);
853 /* Find the name of this constant. */
854 for (value
= TYPE_VALUES (type
);
855 value
!= NULL_TREE
&& !tree_int_cst_equal (TREE_VALUE (value
), e
);
856 value
= TREE_CHAIN (value
))
859 if (value
!= NULL_TREE
)
860 pp_id_expression (pp
, TREE_PURPOSE (value
));
863 /* Value must have been cast. */
864 pp_c_type_cast (pp
, type
);
865 value_is_named
= false;
868 return value_is_named
;
871 /* Print out a REAL value as a decimal-floating-constant. */
874 pp_c_floating_constant (c_pretty_printer
*pp
, tree r
)
876 real_to_decimal (pp_buffer (pp
)->digit_buffer
, &TREE_REAL_CST (r
),
877 sizeof (pp_buffer (pp
)->digit_buffer
), 0, 1);
878 pp_string (pp
, pp_buffer(pp
)->digit_buffer
);
879 if (TREE_TYPE (r
) == float_type_node
)
880 pp_character (pp
, 'f');
881 else if (TREE_TYPE (r
) == long_double_type_node
)
882 pp_character (pp
, 'l');
885 /* Pretty-print a compound literal expression. GNU extensions include
889 pp_c_compound_literal (c_pretty_printer
*pp
, tree e
)
891 tree type
= TREE_TYPE (e
);
892 pp_c_type_cast (pp
, type
);
894 switch (TREE_CODE (type
))
901 pp_c_brace_enclosed_initializer_list (pp
, e
);
905 pp_unsupported_tree (pp
, e
);
914 character-constant */
917 pp_c_constant (c_pretty_printer
*pp
, tree e
)
919 const enum tree_code code
= TREE_CODE (e
);
925 tree type
= TREE_TYPE (e
);
926 if (type
== boolean_type_node
)
927 pp_c_bool_constant (pp
, e
);
928 else if (type
== char_type_node
)
929 pp_c_character_constant (pp
, e
);
930 else if (TREE_CODE (type
) == ENUMERAL_TYPE
931 && pp_c_enumeration_constant (pp
, e
))
934 pp_c_integer_constant (pp
, e
);
939 pp_c_floating_constant (pp
, e
);
943 pp_c_string_literal (pp
, e
);
947 pp_unsupported_tree (pp
, e
);
952 /* Pretty-print an IDENTIFIER_NODE, preceded by whitespace is necessary. */
955 pp_c_identifier (c_pretty_printer
*pp
, const char *id
)
957 pp_c_maybe_whitespace (pp
);
958 pp_identifier (pp
, id
);
959 pp_base (pp
)->padding
= pp_before
;
962 /* Pretty-print a C primary-expression.
970 pp_c_primary_expression (c_pretty_printer
*pp
, tree e
)
972 switch (TREE_CODE (e
))
980 pp_c_tree_decl_identifier (pp
, e
);
983 case IDENTIFIER_NODE
:
984 pp_c_tree_identifier (pp
, e
);
988 pp_c_identifier (pp
, "<erroneous-expression>");
992 pp_c_identifier (pp
, "<return-value>");
998 pp_c_constant (pp
, e
);
1002 pp_c_identifier (pp
, "__builtin_memcpy");
1003 pp_c_left_paren (pp
);
1005 pp_primary_expression (pp
, TREE_OPERAND (e
, 0));
1006 pp_separate_with (pp
, ',');
1008 pp_initializer (pp
, TREE_OPERAND (e
, 1));
1009 if (TREE_OPERAND (e
, 2))
1011 pp_separate_with (pp
, ',');
1012 pp_c_expression (pp
, TREE_OPERAND (e
, 2));
1014 pp_c_right_paren (pp
);
1018 pp_c_left_paren (pp
);
1019 pp_statement (pp
, STMT_EXPR_STMT (e
));
1020 pp_c_right_paren (pp
);
1024 /* FIXME: Make sure we won't get into an infinie loop. */
1025 pp_c_left_paren (pp
);
1026 pp_expression (pp
, e
);
1027 pp_c_right_paren (pp
);
1032 /* Print out a C initializer -- also support C compound-literals.
1034 assignment-expression:
1035 { initializer-list }
1036 { initializer-list , } */
1039 pp_c_initializer (c_pretty_printer
*pp
, tree e
)
1041 if (TREE_CODE (e
) == CONSTRUCTOR
)
1042 pp_c_brace_enclosed_initializer_list (pp
, e
);
1044 pp_expression (pp
, e
);
1049 declarator = initializer */
1052 pp_c_init_declarator (c_pretty_printer
*pp
, tree t
)
1054 pp_declarator (pp
, t
);
1055 /* We don't want to output function definitions here. There are handled
1056 elsewhere (and the syntactic form is bogus anyway). */
1057 if (TREE_CODE (t
) != FUNCTION_DECL
&& DECL_INITIAL (t
))
1059 tree init
= DECL_INITIAL (t
);
1060 /* This C++ bit is handled here because it is easier to do so.
1061 In templates, the C++ parser builds a TREE_LIST for a
1062 direct-initialization; the TREE_PURPOSE is the variable to
1063 initialize and the TREE_VALUE is the initializer. */
1064 if (TREE_CODE (init
) == TREE_LIST
)
1066 pp_c_left_paren (pp
);
1067 pp_expression (pp
, TREE_VALUE (init
));
1068 pp_right_paren (pp
);
1075 pp_c_initializer (pp
, init
);
1080 /* initializer-list:
1081 designation(opt) initializer
1082 initializer-list , designation(opt) initializer
1089 designator-list designator
1092 [ constant-expression ]
1096 pp_c_initializer_list (c_pretty_printer
*pp
, tree e
)
1098 tree type
= TREE_TYPE (e
);
1099 const enum tree_code code
= TREE_CODE (type
);
1107 tree init
= TREE_OPERAND (e
, 0);
1108 for (; init
!= NULL_TREE
; init
= TREE_CHAIN (init
))
1110 if (code
== RECORD_TYPE
|| code
== UNION_TYPE
)
1113 pp_c_primary_expression (pp
, TREE_PURPOSE (init
));
1117 pp_c_left_bracket (pp
);
1118 if (TREE_PURPOSE (init
))
1119 pp_c_constant (pp
, TREE_PURPOSE (init
));
1120 pp_c_right_bracket (pp
);
1122 pp_c_whitespace (pp
);
1124 pp_c_whitespace (pp
);
1125 pp_initializer (pp
, TREE_VALUE (init
));
1126 if (TREE_CHAIN (init
))
1127 pp_separate_with (pp
, ',');
1133 if (TREE_CODE (e
) == VECTOR_CST
)
1134 pp_c_expression_list (pp
, TREE_VECTOR_CST_ELTS (e
));
1135 else if (TREE_CODE (e
) == CONSTRUCTOR
)
1136 pp_c_expression_list (pp
, CONSTRUCTOR_ELTS (e
));
1142 if (TREE_CODE (e
) == CONSTRUCTOR
)
1143 pp_c_expression_list (pp
, CONSTRUCTOR_ELTS (e
));
1144 else if (TREE_CODE (e
) == COMPLEX_CST
|| TREE_CODE (e
) == COMPLEX_EXPR
)
1146 const bool cst
= TREE_CODE (e
) == COMPLEX_CST
;
1147 pp_expression (pp
, cst
? TREE_REALPART (e
) : TREE_OPERAND (e
, 0));
1148 pp_separate_with (pp
, ',');
1149 pp_expression (pp
, cst
? TREE_IMAGPART (e
) : TREE_OPERAND (e
, 1));
1159 pp_unsupported_tree (pp
, type
);
1162 /* Pretty-print a brace-enclosed initializer-list. */
1165 pp_c_brace_enclosed_initializer_list (c_pretty_printer
*pp
, tree l
)
1167 pp_c_left_brace (pp
);
1168 pp_c_initializer_list (pp
, l
);
1169 pp_c_right_brace (pp
);
1173 /* This is a convenient function, used to bridge gap between C and C++
1180 pp_c_id_expression (c_pretty_printer
*pp
, tree t
)
1182 switch (TREE_CODE (t
))
1191 pp_c_tree_decl_identifier (pp
, t
);
1194 case IDENTIFIER_NODE
:
1195 pp_c_tree_identifier (pp
, t
);
1199 pp_unsupported_tree (pp
, t
);
1204 /* postfix-expression:
1206 postfix-expression [ expression ]
1207 postfix-expression ( argument-expression-list(opt) )
1208 postfix-expression . identifier
1209 postfix-expression -> identifier
1210 postfix-expression ++
1211 postfix-expression --
1212 ( type-name ) { initializer-list }
1213 ( type-name ) { initializer-list , } */
1216 pp_c_postfix_expression (c_pretty_printer
*pp
, tree e
)
1218 enum tree_code code
= TREE_CODE (e
);
1221 case POSTINCREMENT_EXPR
:
1222 case POSTDECREMENT_EXPR
:
1223 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1224 pp_identifier (pp
, code
== POSTINCREMENT_EXPR
? "++" : "--");
1228 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1233 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1234 pp_c_left_bracket (pp
);
1235 pp_expression (pp
, TREE_OPERAND (e
, 1));
1236 pp_c_right_bracket (pp
);
1240 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1241 pp_c_call_argument_list (pp
, TREE_OPERAND (e
, 1));
1245 pp_c_identifier (pp
, "__builtin_abs");
1246 pp_c_left_paren (pp
);
1247 pp_expression (pp
, TREE_OPERAND (e
, 0));
1248 pp_c_right_paren (pp
);
1253 tree object
= TREE_OPERAND (e
, 0);
1254 if (TREE_CODE (object
) == INDIRECT_REF
)
1256 pp_postfix_expression (pp
, TREE_OPERAND (object
, 0));
1261 pp_postfix_expression (pp
, object
);
1264 pp_expression (pp
, TREE_OPERAND (e
, 1));
1271 pp_c_compound_literal (pp
, e
);
1274 case COMPOUND_LITERAL_EXPR
:
1275 e
= DECL_INITIAL (COMPOUND_LITERAL_EXPR_DECL (e
));
1278 pp_initializer (pp
, e
);
1282 pp_c_identifier (pp
, "__builtin_va_arg");
1283 pp_c_left_paren (pp
);
1284 pp_assignment_expression (pp
, TREE_OPERAND (e
, 0));
1285 pp_separate_with (pp
, ',');
1286 pp_type_id (pp
, TREE_TYPE (e
));
1287 pp_c_right_paren (pp
);
1291 if (TREE_CODE (TREE_OPERAND (e
, 0)) == FUNCTION_DECL
)
1293 pp_c_id_expression (pp
, TREE_OPERAND (e
, 0));
1296 /* else fall through. */
1299 pp_primary_expression (pp
, e
);
1304 /* Print out an expression-list; E is expected to be a TREE_LIST. */
1307 pp_c_expression_list (c_pretty_printer
*pp
, tree e
)
1309 for (; e
!= NULL_TREE
; e
= TREE_CHAIN (e
))
1311 pp_expression (pp
, TREE_VALUE (e
));
1313 pp_separate_with (pp
, ',');
1317 /* Print out an expression-list in parens, as in a function call. */
1320 pp_c_call_argument_list (c_pretty_printer
*pp
, tree t
)
1322 pp_c_left_paren (pp
);
1323 if (t
&& TREE_CODE (t
) == TREE_LIST
)
1324 pp_c_expression_list (pp
, t
);
1325 pp_c_right_paren (pp
);
1328 /* unary-expression:
1332 unary-operator cast-expression
1333 sizeof unary-expression
1336 unary-operator: one of
1341 __alignof__ unary-expression
1342 __alignof__ ( type-id )
1343 __real__ unary-expression
1344 __imag__ unary-expression */
1347 pp_c_unary_expression (c_pretty_printer
*pp
, tree e
)
1349 enum tree_code code
= TREE_CODE (e
);
1352 case PREINCREMENT_EXPR
:
1353 case PREDECREMENT_EXPR
:
1354 pp_identifier (pp
, code
== PREINCREMENT_EXPR
? "++" : "--");
1355 pp_c_unary_expression (pp
, TREE_OPERAND (e
, 0));
1362 case TRUTH_NOT_EXPR
:
1364 /* String literal are used by address. */
1365 if (code
== ADDR_EXPR
&& TREE_CODE (TREE_OPERAND (e
, 0)) != STRING_CST
)
1367 else if (code
== INDIRECT_REF
)
1369 else if (code
== NEGATE_EXPR
)
1371 else if (code
== BIT_NOT_EXPR
|| code
== CONJ_EXPR
)
1373 else if (code
== TRUTH_NOT_EXPR
)
1374 pp_exclamation (pp
);
1375 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 0));
1380 pp_c_identifier (pp
, code
== SIZEOF_EXPR
? "sizeof" : "__alignof__");
1381 pp_c_whitespace (pp
);
1382 if (TYPE_P (TREE_OPERAND (e
, 0)))
1383 pp_c_type_cast (pp
, TREE_OPERAND (e
, 0));
1385 pp_unary_expression (pp
, TREE_OPERAND (e
, 0));
1390 pp_c_identifier (pp
, code
== REALPART_EXPR
? "__real__" : "__imag__");
1391 pp_c_whitespace (pp
);
1392 pp_unary_expression (pp
, TREE_OPERAND (e
, 0));
1396 pp_postfix_expression (pp
, e
);
1403 ( type-name ) cast-expression */
1406 pp_c_cast_expression (c_pretty_printer
*pp
, tree e
)
1408 switch (TREE_CODE (e
))
1411 case FIX_TRUNC_EXPR
:
1413 pp_c_type_cast (pp
, TREE_TYPE (e
));
1414 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 0));
1418 pp_unary_expression (pp
, e
);
1422 /* multiplicative-expression:
1424 multiplicative-expression * cast-expression
1425 multiplicative-expression / cast-expression
1426 multiplicative-expression % cast-expression */
1429 pp_c_multiplicative_expression (c_pretty_printer
*pp
, tree e
)
1431 enum tree_code code
= TREE_CODE (e
);
1435 case TRUNC_DIV_EXPR
:
1436 case TRUNC_MOD_EXPR
:
1437 pp_multiplicative_expression (pp
, TREE_OPERAND (e
, 0));
1438 pp_c_whitespace (pp
);
1439 if (code
== MULT_EXPR
)
1441 else if (code
== TRUNC_DIV_EXPR
)
1445 pp_c_whitespace (pp
);
1446 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 1));
1450 pp_c_cast_expression (pp
, e
);
1455 /* additive-expression:
1456 multiplicative-expression
1457 additive-expression + multiplicative-expression
1458 additive-expression - multiplicative-expression */
1461 pp_c_additive_expression (c_pretty_printer
*pp
, tree e
)
1463 enum tree_code code
= TREE_CODE (e
);
1468 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 0));
1469 pp_c_whitespace (pp
);
1470 if (code
== PLUS_EXPR
)
1474 pp_c_whitespace (pp
);
1475 pp_multiplicative_expression (pp
, TREE_OPERAND (e
, 1));
1479 pp_multiplicative_expression (pp
, e
);
1484 /* additive-expression:
1486 shift-expression << additive-expression
1487 shift-expression >> additive-expression */
1490 pp_c_shift_expression (c_pretty_printer
*pp
, tree e
)
1492 enum tree_code code
= TREE_CODE (e
);
1497 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 0));
1498 pp_c_whitespace (pp
);
1499 pp_identifier (pp
, code
== LSHIFT_EXPR
? "<<" : ">>");
1500 pp_c_whitespace (pp
);
1501 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 1));
1505 pp_c_additive_expression (pp
, e
);
1509 /* relational-expression:
1511 relational-expression < shift-expression
1512 relational-expression > shift-expression
1513 relational-expression <= shift-expression
1514 relational-expression >= shift-expression */
1517 pp_c_relational_expression (c_pretty_printer
*pp
, tree e
)
1519 enum tree_code code
= TREE_CODE (e
);
1526 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 0));
1527 pp_c_whitespace (pp
);
1528 if (code
== LT_EXPR
)
1530 else if (code
== GT_EXPR
)
1532 else if (code
== LE_EXPR
)
1533 pp_identifier (pp
, "<=");
1534 else if (code
== GE_EXPR
)
1535 pp_identifier (pp
, ">=");
1536 pp_c_whitespace (pp
);
1537 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 1));
1541 pp_c_shift_expression (pp
, e
);
1546 /* equality-expression:
1547 relational-expression
1548 equality-expression == relational-expression
1549 equality-equality != relational-expression */
1552 pp_c_equality_expression (c_pretty_printer
*pp
, tree e
)
1554 enum tree_code code
= TREE_CODE (e
);
1559 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 0));
1560 pp_c_whitespace (pp
);
1561 pp_identifier (pp
, code
== EQ_EXPR
? "==" : "!=");
1562 pp_c_whitespace (pp
);
1563 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 1));
1567 pp_c_relational_expression (pp
, e
);
1574 AND-expression & equality-equality */
1577 pp_c_and_expression (c_pretty_printer
*pp
, tree e
)
1579 if (TREE_CODE (e
) == BIT_AND_EXPR
)
1581 pp_c_and_expression (pp
, TREE_OPERAND (e
, 0));
1582 pp_c_whitespace (pp
);
1584 pp_c_whitespace (pp
);
1585 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 1));
1588 pp_c_equality_expression (pp
, e
);
1591 /* exclusive-OR-expression:
1593 exclusive-OR-expression ^ AND-expression */
1596 pp_c_exclusive_or_expression (c_pretty_printer
*pp
, tree e
)
1598 if (TREE_CODE (e
) == BIT_XOR_EXPR
)
1600 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
1601 pp_c_maybe_whitespace (pp
);
1603 pp_c_whitespace (pp
);
1604 pp_c_and_expression (pp
, TREE_OPERAND (e
, 1));
1607 pp_c_and_expression (pp
, e
);
1610 /* inclusive-OR-expression:
1611 exclusive-OR-expression
1612 inclusive-OR-expression | exclusive-OR-expression */
1615 pp_c_inclusive_or_expression (c_pretty_printer
*pp
, tree e
)
1617 if (TREE_CODE (e
) == BIT_IOR_EXPR
)
1619 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
1620 pp_c_whitespace (pp
);
1622 pp_c_whitespace (pp
);
1623 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
1626 pp_c_exclusive_or_expression (pp
, e
);
1629 /* logical-AND-expression:
1630 inclusive-OR-expression
1631 logical-AND-expression && inclusive-OR-expression */
1634 pp_c_logical_and_expression (c_pretty_printer
*pp
, tree e
)
1636 if (TREE_CODE (e
) == TRUTH_ANDIF_EXPR
)
1638 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 0));
1639 pp_c_whitespace (pp
);
1640 pp_identifier (pp
, "&&");
1641 pp_c_whitespace (pp
);
1642 pp_c_inclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
1645 pp_c_inclusive_or_expression (pp
, e
);
1648 /* logical-OR-expression:
1649 logical-AND-expression
1650 logical-OR-expression || logical-AND-expression */
1653 pp_c_logical_or_expression (c_pretty_printer
*pp
, tree e
)
1655 if (TREE_CODE (e
) == TRUTH_ORIF_EXPR
)
1657 pp_c_logical_or_expression (pp
, TREE_OPERAND (e
, 0));
1658 pp_c_whitespace (pp
);
1659 pp_identifier (pp
, "||");
1660 pp_c_whitespace (pp
);
1661 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 1));
1664 pp_c_logical_and_expression (pp
, e
);
1667 /* conditional-expression:
1668 logical-OR-expression
1669 logical-OR-expression ? expression : conditional-expression */
1672 pp_c_conditional_expression (c_pretty_printer
*pp
, tree e
)
1674 if (TREE_CODE (e
) == COND_EXPR
)
1676 pp_c_logical_or_expression (pp
, TREE_OPERAND (e
, 0));
1677 pp_c_whitespace (pp
);
1679 pp_c_whitespace (pp
);
1680 pp_expression (pp
, TREE_OPERAND (e
, 1));
1681 pp_c_whitespace (pp
);
1683 pp_c_whitespace (pp
);
1684 pp_c_conditional_expression (pp
, TREE_OPERAND (e
, 2));
1687 pp_c_logical_or_expression (pp
, e
);
1691 /* assignment-expression:
1692 conditional-expression
1693 unary-expression assignment-operator assignment-expression
1695 assignment-expression: one of
1696 = *= /= %= += -= >>= <<= &= ^= |= */
1699 pp_c_assignment_expression (c_pretty_printer
*pp
, tree e
)
1701 if (TREE_CODE (e
) == MODIFY_EXPR
|| TREE_CODE (e
) == INIT_EXPR
)
1703 pp_c_unary_expression (pp
, TREE_OPERAND (e
, 0));
1704 pp_c_whitespace (pp
);
1707 pp_c_expression (pp
, TREE_OPERAND (e
, 1));
1710 pp_c_conditional_expression (pp
, e
);
1714 assignment-expression
1715 expression , assignment-expression
1717 Implementation note: instead of going through the usual recursion
1718 chain, I take the liberty of dispatching nodes to the appropriate
1719 functions. This makes some redundancy, but it worths it. That also
1720 prevents a possible infinite recursion between pp_c_primary_expression ()
1721 and pp_c_expression (). */
1724 pp_c_expression (c_pretty_printer
*pp
, tree e
)
1726 switch (TREE_CODE (e
))
1729 pp_c_integer_constant (pp
, e
);
1733 pp_c_floating_constant (pp
, e
);
1737 pp_c_string_literal (pp
, e
);
1740 case IDENTIFIER_NODE
:
1750 pp_primary_expression (pp
, e
);
1753 case POSTINCREMENT_EXPR
:
1754 case POSTDECREMENT_EXPR
:
1764 case COMPOUND_LITERAL_EXPR
:
1766 pp_postfix_expression (pp
, e
);
1774 case TRUTH_NOT_EXPR
:
1775 case PREINCREMENT_EXPR
:
1776 case PREDECREMENT_EXPR
:
1781 pp_c_unary_expression (pp
, e
);
1785 case FIX_TRUNC_EXPR
:
1787 pp_c_cast_expression (pp
, e
);
1791 case TRUNC_MOD_EXPR
:
1792 case TRUNC_DIV_EXPR
:
1793 pp_multiplicative_expression (pp
, e
);
1798 pp_c_shift_expression (pp
, e
);
1805 pp_c_relational_expression (pp
, e
);
1809 pp_c_and_expression (pp
, e
);
1813 pp_c_exclusive_or_expression (pp
, e
);
1817 pp_c_inclusive_or_expression (pp
, e
);
1820 case TRUTH_ANDIF_EXPR
:
1821 pp_c_logical_and_expression (pp
, e
);
1824 case TRUTH_ORIF_EXPR
:
1825 pp_c_logical_or_expression (pp
, e
);
1830 pp_c_equality_expression (pp
, e
);
1834 pp_conditional_expression (pp
, e
);
1839 pp_c_additive_expression (pp
, e
);
1844 pp_assignment_expression (pp
, e
);
1848 pp_c_left_paren (pp
);
1849 pp_expression (pp
, TREE_OPERAND (e
, 0));
1850 pp_separate_with (pp
, ',');
1851 pp_assignment_expression (pp
, TREE_OPERAND (e
, 1));
1852 pp_c_right_paren (pp
);
1856 case NON_LVALUE_EXPR
:
1859 pp_expression (pp
, TREE_OPERAND (e
, 0));
1863 pp_postfix_expression (pp
, TREE_OPERAND (e
, 1));
1867 pp_unsupported_tree (pp
, e
);
1879 expression-statement
1885 pp_c_statement (c_pretty_printer
*pp
, tree stmt
)
1887 enum tree_code code
;
1892 code
= TREE_CODE (stmt
);
1895 /* labeled-statement:
1896 identifier : statement
1897 case constant-expression : statement
1898 default : statement */
1901 if (pp_needs_newline (pp
))
1902 pp_newline_and_indent (pp
, -3);
1904 pp_indentation (pp
) -= 3;
1905 if (code
== LABEL_STMT
)
1906 pp_c_tree_decl_identifier (pp
, LABEL_STMT_LABEL (stmt
));
1907 else if (code
== CASE_LABEL
)
1909 if (CASE_LOW (stmt
) == NULL_TREE
)
1910 pp_identifier (pp
, "default");
1913 pp_c_identifier (pp
, "case");
1914 pp_c_whitespace (pp
);
1915 pp_conditional_expression (pp
, CASE_LOW (stmt
));
1916 if (CASE_HIGH (stmt
))
1918 pp_identifier (pp
, "...");
1919 pp_conditional_expression (pp
, CASE_HIGH (stmt
));
1924 pp_indentation (pp
) += 3;
1925 pp_needs_newline (pp
) = true;
1928 /* compound-statement:
1929 { block-item-list(opt) }
1933 block-item-list block-item
1939 if (pp_needs_newline (pp
))
1940 pp_newline_and_indent (pp
, 0);
1941 pp_c_left_brace (pp
);
1942 pp_newline_and_indent (pp
, 3);
1943 for (stmt
= COMPOUND_BODY (stmt
); stmt
; stmt
= TREE_CHAIN (stmt
))
1944 pp_statement (pp
, stmt
);
1945 pp_newline_and_indent (pp
, -3);
1946 pp_c_right_brace (pp
);
1947 pp_needs_newline (pp
) = true;
1950 /* expression-statement:
1951 expression(opt) ; */
1954 if (pp_needs_newline (pp
))
1955 pp_newline_and_indent (pp
, 0);
1957 tree e
= code
== EXPR_STMT
1958 ? EXPR_STMT_EXPR (stmt
)
1959 : CLEANUP_EXPR (stmt
);
1961 pp_expression (pp
, e
);
1963 pp_c_semicolon (pp
);
1964 pp_needs_newline (pp
) = true;
1967 /* selection-statement:
1968 if ( expression ) statement
1969 if ( expression ) statement else statement
1970 switch ( expression ) statement */
1972 if (pp_needs_newline (pp
))
1973 pp_newline_and_indent (pp
, 0);
1974 pp_c_identifier (pp
, "if");
1975 pp_c_whitespace (pp
);
1976 pp_c_left_paren (pp
);
1977 pp_expression (pp
, IF_COND (stmt
));
1978 pp_c_right_paren (pp
);
1979 pp_newline_and_indent (pp
, 3);
1980 pp_statement (pp
, THEN_CLAUSE (stmt
));
1981 pp_newline_and_indent (pp
, -3);
1982 if (ELSE_CLAUSE (stmt
))
1984 tree else_clause
= ELSE_CLAUSE (stmt
);
1985 pp_c_identifier (pp
, "else");
1986 if (TREE_CODE (else_clause
) == IF_STMT
)
1987 pp_c_whitespace (pp
);
1989 pp_newline_and_indent (pp
, 3);
1990 pp_statement (pp
, else_clause
);
1991 if (TREE_CODE (else_clause
) != IF_STMT
)
1992 pp_newline_and_indent (pp
, -3);
1997 if (pp_needs_newline (pp
))
1998 pp_newline_and_indent (pp
, 0);
1999 pp_c_identifier (pp
, "switch");
2001 pp_c_left_paren (pp
);
2002 pp_expression (pp
, SWITCH_COND (stmt
));
2003 pp_c_right_paren (pp
);
2004 pp_indentation (pp
) += 3;
2005 pp_needs_newline (pp
) = true;
2006 pp_statement (pp
, SWITCH_BODY (stmt
));
2007 pp_newline_and_indent (pp
, -3);
2010 /* iteration-statement:
2011 while ( expression ) statement
2012 do statement while ( expression ) ;
2013 for ( expression(opt) ; expression(opt) ; expression(opt) ) statement
2014 for ( declaration expression(opt) ; expression(opt) ) statement */
2016 if (pp_needs_newline (pp
))
2017 pp_newline_and_indent (pp
, 0);
2018 pp_c_identifier (pp
, "while");
2020 pp_c_left_paren (pp
);
2021 pp_expression (pp
, WHILE_COND (stmt
));
2022 pp_c_right_paren (pp
);
2023 pp_newline_and_indent (pp
, 3);
2024 pp_statement (pp
, WHILE_BODY (stmt
));
2025 pp_indentation (pp
) -= 3;
2026 pp_needs_newline (pp
) = true;
2030 if (pp_needs_newline (pp
))
2031 pp_newline_and_indent (pp
, 0);
2032 pp_c_identifier (pp
, "do");
2033 pp_newline_and_indent (pp
, 3);
2034 pp_statement (pp
, DO_BODY (stmt
));
2035 pp_newline_and_indent (pp
, -3);
2036 pp_c_identifier (pp
, "while");
2038 pp_c_left_paren (pp
);
2039 pp_expression (pp
, DO_COND (stmt
));
2040 pp_c_right_paren (pp
);
2041 pp_c_semicolon (pp
);
2042 pp_needs_newline (pp
) = true;
2046 if (pp_needs_newline (pp
))
2047 pp_newline_and_indent (pp
, 0);
2048 pp_c_identifier (pp
, "for");
2050 pp_c_left_paren (pp
);
2051 if (FOR_INIT_STMT (stmt
))
2052 pp_statement (pp
, FOR_INIT_STMT (stmt
));
2054 pp_c_semicolon (pp
);
2055 pp_needs_newline (pp
) = false;
2056 pp_c_whitespace (pp
);
2057 if (FOR_COND (stmt
))
2058 pp_expression (pp
, FOR_COND (stmt
));
2059 pp_c_semicolon (pp
);
2060 pp_needs_newline (pp
) = false;
2061 pp_c_whitespace (pp
);
2062 if (FOR_EXPR (stmt
))
2063 pp_expression (pp
, FOR_EXPR (stmt
));
2064 pp_c_right_paren (pp
);
2065 pp_newline_and_indent (pp
, 3);
2066 pp_statement (pp
, FOR_BODY (stmt
));
2067 pp_indentation (pp
) -= 3;
2068 pp_needs_newline (pp
) = true;
2074 return expression(opt) ; */
2077 if (pp_needs_newline (pp
))
2078 pp_newline_and_indent (pp
, 0);
2079 pp_identifier (pp
, code
== BREAK_STMT
? "break" : "continue");
2080 pp_c_semicolon (pp
);
2081 pp_needs_newline (pp
) = true;
2087 tree e
= code
== RETURN_STMT
2088 ? RETURN_STMT_EXPR (stmt
)
2089 : GOTO_DESTINATION (stmt
);
2090 if (pp_needs_newline (pp
))
2091 pp_newline_and_indent (pp
, 0);
2092 pp_c_identifier (pp
, code
== RETURN_STMT
? "return" : "goto");
2093 pp_c_whitespace (pp
);
2096 if (TREE_CODE (e
) == INIT_EXPR
2097 && TREE_CODE (TREE_OPERAND (e
, 0)) == RESULT_DECL
)
2098 e
= TREE_OPERAND (e
, 1);
2099 pp_expression (pp
, e
);
2101 pp_c_semicolon (pp
);
2102 pp_needs_newline (pp
) = true;
2107 if (!SCOPE_NULLIFIED_P (stmt
) && SCOPE_NO_CLEANUPS_P (stmt
))
2110 if (pp_needs_newline (pp
))
2111 pp_newline_and_indent (pp
, 0);
2112 if (SCOPE_BEGIN_P (stmt
))
2117 else if (SCOPE_END_P (stmt
))
2119 pp_right_brace (pp
);
2122 pp_indentation (pp
) += i
;
2123 pp_needs_newline (pp
) = true;
2128 if (pp_needs_newline (pp
))
2129 pp_newline_and_indent (pp
, 0);
2130 pp_declaration (pp
, DECL_STMT_DECL (stmt
));
2131 pp_needs_newline (pp
) = true;
2136 bool has_volatile_p
= ASM_VOLATILE_P (stmt
);
2137 bool is_extended
= has_volatile_p
|| ASM_INPUTS (stmt
)
2138 || ASM_OUTPUTS (stmt
) || ASM_CLOBBERS (stmt
);
2139 pp_c_identifier (pp
, is_extended
? "__asm__" : "asm");
2141 pp_c_identifier (pp
, "__volatile__");
2143 pp_c_left_paren (pp
);
2144 pp_c_string_literal (pp
, ASM_STRING (stmt
));
2148 pp_separate_with (pp
, ':');
2149 if (ASM_OUTPUTS (stmt
))
2150 pp_expression (pp
, ASM_OUTPUTS (stmt
));
2152 pp_separate_with (pp
, ':');
2153 if (ASM_INPUTS (stmt
))
2154 pp_expression (pp
, ASM_INPUTS (stmt
));
2156 pp_separate_with (pp
, ':');
2157 if (ASM_CLOBBERS (stmt
))
2158 pp_expression (pp
, ASM_CLOBBERS (stmt
));
2160 pp_c_right_paren (pp
);
2166 pp_unsupported_tree (pp
, stmt
);
2171 /* Initialize the PRETTY-PRINTER for handling C codes. */
2174 pp_c_pretty_printer_init (c_pretty_printer
*pp
)
2176 pp
->offset_list
= 0;
2178 pp
->declaration
= pp_c_declaration
;
2179 pp
->declaration_specifiers
= pp_c_declaration_specifiers
;
2180 pp
->declarator
= pp_c_declarator
;
2181 pp
->direct_declarator
= pp_c_direct_declarator
;
2182 pp
->type_specifier_seq
= pp_c_specifier_qualifier_list
;
2183 pp
->abstract_declarator
= pp_c_abstract_declarator
;
2184 pp
->direct_abstract_declarator
= pp_c_direct_abstract_declarator
;
2185 pp
->ptr_operator
= pp_c_pointer
;
2186 pp
->parameter_list
= pp_c_parameter_type_list
;
2187 pp
->type_id
= pp_c_type_id
;
2188 pp
->simple_type_specifier
= pp_c_type_specifier
;
2189 pp
->function_specifier
= pp_c_function_specifier
;
2190 pp
->storage_class_specifier
= pp_c_storage_class_specifier
;
2192 pp
->statement
= pp_c_statement
;
2194 pp
->id_expression
= pp_c_id_expression
;
2195 pp
->primary_expression
= pp_c_primary_expression
;
2196 pp
->postfix_expression
= pp_c_postfix_expression
;
2197 pp
->unary_expression
= pp_c_unary_expression
;
2198 pp
->initializer
= pp_c_initializer
;
2199 pp
->multiplicative_expression
= pp_c_multiplicative_expression
;
2200 pp
->conditional_expression
= pp_c_conditional_expression
;
2201 pp
->assignment_expression
= pp_c_assignment_expression
;
2202 pp
->expression
= pp_c_expression
;
2206 /* Print the tree T in full, on file FILE. */
2209 print_c_tree (FILE *file
, tree t
)
2211 static c_pretty_printer pp_rec
;
2212 static bool initialized
= 0;
2213 c_pretty_printer
*pp
= &pp_rec
;
2218 pp_construct (pp_base (pp
), NULL
, 0);
2219 pp_c_pretty_printer_init (pp
);
2220 pp_needs_newline (pp
) = true;
2222 pp_base (pp
)->buffer
->stream
= file
;
2224 pp_statement (pp
, t
);
2230 /* Print the tree T in full, on stderr. */
2233 debug_c_tree (tree t
)
2235 print_c_tree (stderr
, t
);
2236 fputc ('\n', stderr
);
2239 /* Output the DECL_NAME of T. If T has no DECL_NAME, output a string made
2240 up of T's memory address. */
2243 pp_c_tree_decl_identifier (c_pretty_printer
*pp
, tree t
)
2251 name
= IDENTIFIER_POINTER (DECL_NAME (t
));
2254 static char xname
[8];
2255 sprintf (xname
, "<U%4x>", ((unsigned)((unsigned long)(t
) & 0xffff)));
2259 pp_c_identifier (pp
, name
);