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); \
45 #define pp_c_left_bracket(PP) \
47 pp_left_bracket (PP); \
48 pp_base (PP)->padding = pp_none; \
51 #define pp_c_right_bracket(PP) \
53 pp_right_bracket (PP); \
54 pp_base (PP)->padding = pp_none; \
57 #define pp_c_star(PP) \
60 pp_base (PP)->padding = pp_none; \
64 static void pp_c_char (c_pretty_printer
*, int);
66 /* postfix-expression */
67 static void pp_c_initializer_list (c_pretty_printer
*, tree
);
68 static void pp_c_brace_enclosed_initializer_list (c_pretty_printer
*, tree
);
70 static void pp_c_multiplicative_expression (c_pretty_printer
*, tree
);
71 static void pp_c_additive_expression (c_pretty_printer
*, tree
);
72 static void pp_c_shift_expression (c_pretty_printer
*, tree
);
73 static void pp_c_relational_expression (c_pretty_printer
*, tree
);
74 static void pp_c_equality_expression (c_pretty_printer
*, tree
);
75 static void pp_c_and_expression (c_pretty_printer
*, tree
);
76 static void pp_c_exclusive_or_expression (c_pretty_printer
*, tree
);
77 static void pp_c_inclusive_or_expression (c_pretty_printer
*, tree
);
78 static void pp_c_logical_and_expression (c_pretty_printer
*, tree
);
79 static void pp_c_conditional_expression (c_pretty_printer
*, tree
);
80 static void pp_c_assignment_expression (c_pretty_printer
*, tree
);
85 /* Helper functions. */
88 pp_c_whitespace (c_pretty_printer
*pp
)
91 pp_base (pp
)->padding
= pp_none
;
95 pp_c_left_paren (c_pretty_printer
*pp
)
98 pp_base (pp
)->padding
= pp_none
;
102 pp_c_right_paren (c_pretty_printer
*pp
)
105 pp_base (pp
)->padding
= pp_none
;
109 pp_c_left_brace (c_pretty_printer
*pp
)
112 pp_base (pp
)->padding
= pp_none
;
116 pp_c_right_brace (c_pretty_printer
*pp
)
119 pp_base (pp
)->padding
= pp_none
;
123 pp_c_dot (c_pretty_printer
*pp
)
126 pp_base (pp
)->padding
= pp_none
;
130 pp_c_ampersand (c_pretty_printer
*pp
)
133 pp_base (pp
)->padding
= pp_none
;
137 pp_c_arrow (c_pretty_printer
*pp
)
140 pp_base (pp
)->padding
= pp_none
;
144 pp_c_semicolon (c_pretty_printer
*pp
)
147 pp_base (pp
)->padding
= pp_none
;
150 /* Print out the external representation of CV-QUALIFIER. */
153 pp_c_cv_qualifier (c_pretty_printer
*pp
, const char *cv
)
155 const char *p
= pp_last_position_in_text (pp
);
156 /* The C programming language does not have references, but it is much
157 simpler to handle those here rather than going through the same
158 logic in the C++ pretty-printer. */
159 if (p
!= NULL
&& (*p
== '*' || *p
== '&'))
160 pp_c_whitespace (pp
);
161 pp_c_identifier (pp
, cv
);
164 /* Pretty-print T using the type-cast notation '( type-name )'. */
167 pp_c_type_cast (c_pretty_printer
*pp
, tree t
)
169 pp_c_left_paren (pp
);
171 pp_c_right_paren (pp
);
174 /* We're about to pretty-print a pointer type as indicated by T.
175 Output a whitespace, if needed, preparing for subsequent output. */
178 pp_c_space_for_pointer_operator (c_pretty_printer
*pp
, tree t
)
180 if (POINTER_TYPE_P (t
))
182 tree pointee
= strip_pointer_operator (TREE_TYPE (t
));
183 if (TREE_CODE (pointee
) != ARRAY_TYPE
184 && TREE_CODE (pointee
) != FUNCTION_TYPE
)
185 pp_c_whitespace (pp
);
192 /* C++ cv-qualifiers are called type-qualifiers in C. Print out the
193 cv-qualifiers of T. If T is a declaration then it is the cv-qualifier
194 of its type. Take care of possible extensions.
198 type-qualifier-list type-qualifier
203 __restrict__ -- GNU C
207 pp_c_type_qualifier_list (c_pretty_printer
*pp
, tree t
)
214 qualifiers
= TYPE_QUALS (t
);
215 if (qualifiers
& TYPE_QUAL_CONST
)
216 pp_c_cv_qualifier (pp
, "const");
217 if (qualifiers
& TYPE_QUAL_VOLATILE
)
218 pp_c_cv_qualifier (pp
, "volatile");
219 if (qualifiers
& TYPE_QUAL_RESTRICT
)
220 pp_c_cv_qualifier (pp
, flag_isoc99
? "restrict" : "__restrict__");
224 * type-qualifier-list(opt)
225 * type-qualifier-list(opt) pointer */
228 pp_c_pointer (c_pretty_printer
*pp
, tree t
)
230 if (!TYPE_P (t
) && TREE_CODE (t
) != TYPE_DECL
)
232 switch (TREE_CODE (t
))
235 /* It is easier to handle C++ reference types here. */
237 if (TREE_CODE (TREE_TYPE (t
)) == POINTER_TYPE
)
238 pp_c_pointer (pp
, TREE_TYPE (t
));
239 if (TREE_CODE (t
) == POINTER_TYPE
)
243 pp_c_type_qualifier_list (pp
, t
);
247 pp_unsupported_tree (pp
, t
);
264 struct-or-union-specifier
269 simple-type-specifier:
274 pp_c_type_specifier (c_pretty_printer
*pp
, tree t
)
276 const enum tree_code code
= TREE_CODE (t
);
280 pp_c_identifier (pp
, "<type-error>");
283 case IDENTIFIER_NODE
:
284 pp_c_tree_decl_identifier (pp
, t
);
295 t
= c_common_type_for_mode (TYPE_MODE (t
), TYPE_UNSIGNED (t
));
296 pp_c_type_specifier (pp
, t
);
301 pp_id_expression (pp
, t
);
303 pp_c_identifier (pp
, "<typedef-error>");
309 if (code
== UNION_TYPE
)
310 pp_c_identifier (pp
, "union");
311 else if (code
== RECORD_TYPE
)
312 pp_c_identifier (pp
, "struct");
313 else if (code
== ENUMERAL_TYPE
)
314 pp_c_identifier (pp
, "enum");
316 pp_c_identifier (pp
, "<tag-error>");
319 pp_id_expression (pp
, TYPE_NAME (t
));
321 pp_c_identifier (pp
, "<anonymous>");
325 pp_unsupported_tree (pp
, t
);
330 /* specifier-qualifier-list:
331 type-specifier specifier-qualifier-list-opt
332 type-qualifier specifier-qualifier-list-opt
335 Implementation note: Because of the non-linearities in array or
336 function declarations, this routine prints not just the
337 specifier-qualifier-list of such entities or types of such entities,
338 but also the 'pointer' production part of their declarators. The
339 remaining part is done by pp_declarator or pp_c_abstract_declarator. */
342 pp_c_specifier_qualifier_list (c_pretty_printer
*pp
, tree t
)
344 const enum tree_code code
= TREE_CODE (t
);
346 if (TREE_CODE (t
) != POINTER_TYPE
)
347 pp_c_type_qualifier_list (pp
, t
);
353 /* Get the types-specifier of this type. */
354 tree pointee
= strip_pointer_operator (TREE_TYPE (t
));
355 pp_c_specifier_qualifier_list (pp
, pointee
);
356 if (TREE_CODE (pointee
) == ARRAY_TYPE
357 || TREE_CODE (pointee
) == FUNCTION_TYPE
)
359 pp_c_whitespace (pp
);
360 pp_c_left_paren (pp
);
362 pp_ptr_operator (pp
, t
);
368 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
373 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
374 if (code
== COMPLEX_TYPE
)
375 pp_c_identifier (pp
, flag_isoc99
? "_Complex" : "__complex__");
376 else if (code
== VECTOR_TYPE
)
377 pp_c_identifier (pp
, "__vector__");
381 pp_simple_type_specifier (pp
, t
);
386 /* parameter-type-list:
391 parameter-declaration
392 parameter-list , parameter-declaration
394 parameter-declaration:
395 declaration-specifiers declarator
396 declaration-specifiers abstract-declarator(opt) */
399 pp_c_parameter_type_list (c_pretty_printer
*pp
, tree t
)
401 bool want_parm_decl
= DECL_P (t
) && !(pp
->flags
& pp_c_flag_abstract
);
402 tree parms
= want_parm_decl
? DECL_ARGUMENTS (t
) : TYPE_ARG_TYPES (t
);
403 pp_c_left_paren (pp
);
404 if (parms
== void_list_node
)
405 pp_c_identifier (pp
, "void");
409 for ( ; parms
&& parms
!= void_list_node
; parms
= TREE_CHAIN (parms
))
412 pp_separate_with (pp
, ',');
414 pp_declaration_specifiers
415 (pp
, want_parm_decl
? parms
: TREE_VALUE (parms
));
417 pp_declarator (pp
, parms
);
419 pp_abstract_declarator (pp
, TREE_VALUE (parms
));
422 pp_c_right_paren (pp
);
425 /* abstract-declarator:
427 pointer(opt) direct-abstract-declarator */
430 pp_c_abstract_declarator (c_pretty_printer
*pp
, tree t
)
432 if (TREE_CODE (t
) == POINTER_TYPE
)
434 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
435 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
436 pp_c_right_paren (pp
);
440 pp_direct_abstract_declarator (pp
, t
);
443 /* direct-abstract-declarator:
444 ( abstract-declarator )
445 direct-abstract-declarator(opt) [ assignment-expression(opt) ]
446 direct-abstract-declarator(opt) [ * ]
447 direct-abstract-declarator(opt) ( parameter-type-list(opt) ) */
450 pp_c_direct_abstract_declarator (c_pretty_printer
*pp
, tree t
)
452 switch (TREE_CODE (t
))
455 pp_abstract_declarator (pp
, t
);
459 pp_c_parameter_type_list (pp
, t
);
460 pp_direct_abstract_declarator (pp
, TREE_TYPE (t
));
464 pp_c_left_bracket (pp
);
466 pp_expression (pp
, TYPE_MAX_VALUE (TYPE_DOMAIN (t
)));
467 pp_c_right_bracket (pp
);
468 pp_direct_abstract_declarator (pp
, TREE_TYPE (t
));
471 case IDENTIFIER_NODE
:
485 pp_unsupported_tree (pp
, t
);
491 specifier-qualifier-list abstract-declarator(opt) */
494 pp_c_type_id (c_pretty_printer
*pp
, tree t
)
496 pp_c_specifier_qualifier_list (pp
, t
);
497 pp_abstract_declarator (pp
, t
);
500 /* storage-class-specifier:
508 pp_c_storage_class_specifier (c_pretty_printer
*pp
, tree t
)
510 if (TREE_CODE (t
) == TYPE_DECL
)
511 pp_c_identifier (pp
, "typedef");
514 if (DECL_REGISTER (t
))
515 pp_c_identifier (pp
, "register");
516 else if (TREE_STATIC (t
) && TREE_CODE (t
) == VAR_DECL
)
517 pp_c_identifier (pp
, "static");
521 /* function-specifier:
525 pp_c_function_specifier (c_pretty_printer
*pp
, tree t
)
527 if (TREE_CODE (t
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (t
))
528 pp_c_identifier (pp
, "inline");
531 /* declaration-specifiers:
532 storage-class-specifier declaration-specifiers(opt)
533 type-specifier declaration-specifiers(opt)
534 type-qualifier declaration-specifiers(opt)
535 function-specifier declaration-specifiers(opt) */
538 pp_c_declaration_specifiers (c_pretty_printer
*pp
, tree t
)
540 pp_storage_class_specifier (pp
, t
);
541 pp_function_specifier (pp
, t
);
542 pp_c_specifier_qualifier_list (pp
, DECL_P (t
) ? TREE_TYPE (t
) : t
);
548 direct-declarator [ type-qualifier-list(opt) assignment-expression(opt) ]
549 direct-declarator [ static type-qualifier-list(opt) assignment-expression(opt)]
550 direct-declarator [ type-qualifier-list static assignment-expression ]
551 direct-declarator [ type-qualifier-list * ]
552 direct-declarator ( parameter-type-list )
553 direct-declarator ( identifier-list(opt) ) */
556 pp_c_direct_declarator (c_pretty_printer
*pp
, tree t
)
558 switch (TREE_CODE (t
))
565 pp_c_space_for_pointer_operator (pp
, TREE_TYPE (t
));
566 pp_c_tree_decl_identifier (pp
, 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_decl_identifier (pp
, 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
))
963 pp_c_tree_decl_identifier (pp
, e
);
966 case IDENTIFIER_NODE
:
967 pp_c_tree_identifier (pp
, e
);
971 pp_c_identifier (pp
, "<erroneous-expression>");
975 pp_c_identifier (pp
, "<return-value>");
981 pp_c_constant (pp
, e
);
985 pp_c_identifier (pp
, "__builtin_memcpy");
986 pp_c_left_paren (pp
);
988 pp_primary_expression (pp
, TREE_OPERAND (e
, 0));
989 pp_separate_with (pp
, ',');
991 pp_initializer (pp
, TREE_OPERAND (e
, 1));
992 if (TREE_OPERAND (e
, 2))
994 pp_separate_with (pp
, ',');
995 pp_c_expression (pp
, TREE_OPERAND (e
, 2));
997 pp_c_right_paren (pp
);
1001 pp_c_left_paren (pp
);
1002 pp_statement (pp
, STMT_EXPR_STMT (e
));
1003 pp_c_right_paren (pp
);
1007 /* FIXME: Make sure we won't get into an infinie loop. */
1008 pp_c_left_paren (pp
);
1009 pp_expression (pp
, e
);
1010 pp_c_right_paren (pp
);
1015 /* Print out a C initializer -- also support C compound-literals.
1017 assignment-expression:
1018 { initializer-list }
1019 { initializer-list , } */
1022 pp_c_initializer (c_pretty_printer
*pp
, tree e
)
1024 if (TREE_CODE (e
) == CONSTRUCTOR
)
1025 pp_c_brace_enclosed_initializer_list (pp
, e
);
1027 pp_expression (pp
, e
);
1032 declarator = initializer */
1035 pp_c_init_declarator (c_pretty_printer
*pp
, tree t
)
1037 pp_declarator (pp
, t
);
1038 /* We don't want to output function definitions here. There are handled
1039 elsewhere (and the syntactic form is bogus anyway). */
1040 if (TREE_CODE (t
) != FUNCTION_DECL
&& DECL_INITIAL (t
))
1042 tree init
= DECL_INITIAL (t
);
1043 /* This C++ bit is handled here because it is easier to do so.
1044 In templates, the C++ parser builds a TREE_LIST for a
1045 direct-initialization; the TREE_PURPOSE is the variable to
1046 initialize and the TREE_VALUE is the initializer. */
1047 if (TREE_CODE (init
) == TREE_LIST
)
1049 pp_c_left_paren (pp
);
1050 pp_expression (pp
, TREE_VALUE (init
));
1051 pp_right_paren (pp
);
1058 pp_c_initializer (pp
, init
);
1063 /* initializer-list:
1064 designation(opt) initializer
1065 initializer-list , designation(opt) initializer
1072 designator-list designator
1075 [ constant-expression ]
1079 pp_c_initializer_list (c_pretty_printer
*pp
, tree e
)
1081 tree type
= TREE_TYPE (e
);
1082 const enum tree_code code
= TREE_CODE (type
);
1090 tree init
= TREE_OPERAND (e
, 0);
1091 for (; init
!= NULL_TREE
; init
= TREE_CHAIN (init
))
1093 if (code
== RECORD_TYPE
|| code
== UNION_TYPE
)
1096 pp_c_primary_expression (pp
, TREE_PURPOSE (init
));
1100 pp_c_left_bracket (pp
);
1101 if (TREE_PURPOSE (init
))
1102 pp_c_constant (pp
, TREE_PURPOSE (init
));
1103 pp_c_right_bracket (pp
);
1105 pp_c_whitespace (pp
);
1107 pp_c_whitespace (pp
);
1108 pp_initializer (pp
, TREE_VALUE (init
));
1109 if (TREE_CHAIN (init
))
1110 pp_separate_with (pp
, ',');
1116 if (TREE_CODE (e
) == VECTOR_CST
)
1117 pp_c_expression_list (pp
, TREE_VECTOR_CST_ELTS (e
));
1118 else if (TREE_CODE (e
) == CONSTRUCTOR
)
1119 pp_c_expression_list (pp
, CONSTRUCTOR_ELTS (e
));
1125 if (TREE_CODE (e
) == CONSTRUCTOR
)
1126 pp_c_expression_list (pp
, CONSTRUCTOR_ELTS (e
));
1127 else if (TREE_CODE (e
) == COMPLEX_CST
|| TREE_CODE (e
) == COMPLEX_EXPR
)
1129 const bool cst
= TREE_CODE (e
) == COMPLEX_CST
;
1130 pp_expression (pp
, cst
? TREE_REALPART (e
) : TREE_OPERAND (e
, 0));
1131 pp_separate_with (pp
, ',');
1132 pp_expression (pp
, cst
? TREE_IMAGPART (e
) : TREE_OPERAND (e
, 1));
1142 pp_unsupported_tree (pp
, type
);
1145 /* Pretty-print a brace-enclosed initializer-list. */
1148 pp_c_brace_enclosed_initializer_list (c_pretty_printer
*pp
, tree l
)
1150 pp_c_left_brace (pp
);
1151 pp_c_initializer_list (pp
, l
);
1152 pp_c_right_brace (pp
);
1156 /* This is a convenient function, used to bridge gap between C and C++
1163 pp_c_id_expression (c_pretty_printer
*pp
, tree t
)
1165 switch (TREE_CODE (t
))
1174 pp_c_tree_decl_identifier (pp
, t
);
1177 case IDENTIFIER_NODE
:
1178 pp_c_tree_identifier (pp
, t
);
1182 pp_unsupported_tree (pp
, t
);
1187 /* postfix-expression:
1189 postfix-expression [ expression ]
1190 postfix-expression ( argument-expression-list(opt) )
1191 postfix-expression . identifier
1192 postfix-expression -> identifier
1193 postfix-expression ++
1194 postfix-expression --
1195 ( type-name ) { initializer-list }
1196 ( type-name ) { initializer-list , } */
1199 pp_c_postfix_expression (c_pretty_printer
*pp
, tree e
)
1201 enum tree_code code
= TREE_CODE (e
);
1204 case POSTINCREMENT_EXPR
:
1205 case POSTDECREMENT_EXPR
:
1206 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1207 pp_identifier (pp
, code
== POSTINCREMENT_EXPR
? "++" : "--");
1211 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1216 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1217 pp_c_left_bracket (pp
);
1218 pp_expression (pp
, TREE_OPERAND (e
, 1));
1219 pp_c_right_bracket (pp
);
1223 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1224 pp_c_call_argument_list (pp
, TREE_OPERAND (e
, 1));
1228 pp_c_identifier (pp
, "__builtin_abs");
1229 pp_c_left_paren (pp
);
1230 pp_expression (pp
, TREE_OPERAND (e
, 0));
1231 pp_c_right_paren (pp
);
1236 tree object
= TREE_OPERAND (e
, 0);
1237 if (TREE_CODE (object
) == INDIRECT_REF
)
1239 pp_postfix_expression (pp
, TREE_OPERAND (object
, 0));
1244 pp_postfix_expression (pp
, object
);
1247 pp_expression (pp
, TREE_OPERAND (e
, 1));
1254 pp_c_compound_literal (pp
, e
);
1257 case COMPOUND_LITERAL_EXPR
:
1258 e
= DECL_INITIAL (COMPOUND_LITERAL_EXPR_DECL (e
));
1261 pp_initializer (pp
, e
);
1265 pp_c_identifier (pp
, "__builtin_va_arg");
1266 pp_c_left_paren (pp
);
1267 pp_assignment_expression (pp
, TREE_OPERAND (e
, 0));
1268 pp_separate_with (pp
, ',');
1269 pp_type_id (pp
, TREE_TYPE (e
));
1270 pp_c_right_paren (pp
);
1274 if (TREE_CODE (TREE_OPERAND (e
, 0)) == FUNCTION_DECL
)
1276 pp_c_id_expression (pp
, TREE_OPERAND (e
, 0));
1279 /* else fall through. */
1282 pp_primary_expression (pp
, e
);
1287 /* Print out an expression-list; E is expected to be a TREE_LIST. */
1290 pp_c_expression_list (c_pretty_printer
*pp
, tree e
)
1292 for (; e
!= NULL_TREE
; e
= TREE_CHAIN (e
))
1294 pp_expression (pp
, TREE_VALUE (e
));
1296 pp_separate_with (pp
, ',');
1300 /* Print out an expression-list in parens, as in a function call. */
1303 pp_c_call_argument_list (c_pretty_printer
*pp
, tree t
)
1305 pp_c_left_paren (pp
);
1306 if (t
&& TREE_CODE (t
) == TREE_LIST
)
1307 pp_c_expression_list (pp
, t
);
1308 pp_c_right_paren (pp
);
1311 /* unary-expression:
1315 unary-operator cast-expression
1316 sizeof unary-expression
1319 unary-operator: one of
1324 __alignof__ unary-expression
1325 __alignof__ ( type-id )
1326 __real__ unary-expression
1327 __imag__ unary-expression */
1330 pp_c_unary_expression (c_pretty_printer
*pp
, tree e
)
1332 enum tree_code code
= TREE_CODE (e
);
1335 case PREINCREMENT_EXPR
:
1336 case PREDECREMENT_EXPR
:
1337 pp_identifier (pp
, code
== PREINCREMENT_EXPR
? "++" : "--");
1338 pp_c_unary_expression (pp
, TREE_OPERAND (e
, 0));
1345 case TRUTH_NOT_EXPR
:
1347 /* String literal are used by address. */
1348 if (code
== ADDR_EXPR
&& TREE_CODE (TREE_OPERAND (e
, 0)) != STRING_CST
)
1350 else if (code
== INDIRECT_REF
)
1352 else if (code
== NEGATE_EXPR
)
1354 else if (code
== BIT_NOT_EXPR
|| code
== CONJ_EXPR
)
1356 else if (code
== TRUTH_NOT_EXPR
)
1357 pp_exclamation (pp
);
1358 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 0));
1363 pp_c_identifier (pp
, code
== SIZEOF_EXPR
? "sizeof" : "__alignof__");
1364 pp_c_whitespace (pp
);
1365 if (TYPE_P (TREE_OPERAND (e
, 0)))
1366 pp_c_type_cast (pp
, TREE_OPERAND (e
, 0));
1368 pp_unary_expression (pp
, TREE_OPERAND (e
, 0));
1373 pp_c_identifier (pp
, code
== REALPART_EXPR
? "__real__" : "__imag__");
1374 pp_c_whitespace (pp
);
1375 pp_unary_expression (pp
, TREE_OPERAND (e
, 0));
1379 pp_postfix_expression (pp
, e
);
1386 ( type-name ) cast-expression */
1389 pp_c_cast_expression (c_pretty_printer
*pp
, tree e
)
1391 switch (TREE_CODE (e
))
1394 case FIX_TRUNC_EXPR
:
1396 pp_c_type_cast (pp
, TREE_TYPE (e
));
1397 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 0));
1401 pp_unary_expression (pp
, e
);
1405 /* multiplicative-expression:
1407 multiplicative-expression * cast-expression
1408 multiplicative-expression / cast-expression
1409 multiplicative-expression % cast-expression */
1412 pp_c_multiplicative_expression (c_pretty_printer
*pp
, tree e
)
1414 enum tree_code code
= TREE_CODE (e
);
1418 case TRUNC_DIV_EXPR
:
1419 case TRUNC_MOD_EXPR
:
1420 pp_multiplicative_expression (pp
, TREE_OPERAND (e
, 0));
1421 pp_c_whitespace (pp
);
1422 if (code
== MULT_EXPR
)
1424 else if (code
== TRUNC_DIV_EXPR
)
1428 pp_c_whitespace (pp
);
1429 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 1));
1433 pp_c_cast_expression (pp
, e
);
1438 /* additive-expression:
1439 multiplicative-expression
1440 additive-expression + multiplicative-expression
1441 additive-expression - multiplicative-expression */
1444 pp_c_additive_expression (c_pretty_printer
*pp
, tree e
)
1446 enum tree_code code
= TREE_CODE (e
);
1451 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 0));
1452 pp_c_whitespace (pp
);
1453 if (code
== PLUS_EXPR
)
1457 pp_c_whitespace (pp
);
1458 pp_multiplicative_expression (pp
, TREE_OPERAND (e
, 1));
1462 pp_multiplicative_expression (pp
, e
);
1467 /* additive-expression:
1469 shift-expression << additive-expression
1470 shift-expression >> additive-expression */
1473 pp_c_shift_expression (c_pretty_printer
*pp
, tree e
)
1475 enum tree_code code
= TREE_CODE (e
);
1480 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 0));
1481 pp_c_whitespace (pp
);
1482 pp_identifier (pp
, code
== LSHIFT_EXPR
? "<<" : ">>");
1483 pp_c_whitespace (pp
);
1484 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 1));
1488 pp_c_additive_expression (pp
, e
);
1492 /* relational-expression:
1494 relational-expression < shift-expression
1495 relational-expression > shift-expression
1496 relational-expression <= shift-expression
1497 relational-expression >= shift-expression */
1500 pp_c_relational_expression (c_pretty_printer
*pp
, tree e
)
1502 enum tree_code code
= TREE_CODE (e
);
1509 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 0));
1510 pp_c_whitespace (pp
);
1511 if (code
== LT_EXPR
)
1513 else if (code
== GT_EXPR
)
1515 else if (code
== LE_EXPR
)
1516 pp_identifier (pp
, "<=");
1517 else if (code
== GE_EXPR
)
1518 pp_identifier (pp
, ">=");
1519 pp_c_whitespace (pp
);
1520 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 1));
1524 pp_c_shift_expression (pp
, e
);
1529 /* equality-expression:
1530 relational-expression
1531 equality-expression == relational-expression
1532 equality-equality != relational-expression */
1535 pp_c_equality_expression (c_pretty_printer
*pp
, tree e
)
1537 enum tree_code code
= TREE_CODE (e
);
1542 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 0));
1543 pp_c_whitespace (pp
);
1544 pp_identifier (pp
, code
== EQ_EXPR
? "==" : "!=");
1545 pp_c_whitespace (pp
);
1546 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 1));
1550 pp_c_relational_expression (pp
, e
);
1557 AND-expression & equality-equality */
1560 pp_c_and_expression (c_pretty_printer
*pp
, tree e
)
1562 if (TREE_CODE (e
) == BIT_AND_EXPR
)
1564 pp_c_and_expression (pp
, TREE_OPERAND (e
, 0));
1565 pp_c_whitespace (pp
);
1567 pp_c_whitespace (pp
);
1568 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 1));
1571 pp_c_equality_expression (pp
, e
);
1574 /* exclusive-OR-expression:
1576 exclusive-OR-expression ^ AND-expression */
1579 pp_c_exclusive_or_expression (c_pretty_printer
*pp
, tree e
)
1581 if (TREE_CODE (e
) == BIT_XOR_EXPR
)
1583 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
1584 pp_c_maybe_whitespace (pp
);
1586 pp_c_whitespace (pp
);
1587 pp_c_and_expression (pp
, TREE_OPERAND (e
, 1));
1590 pp_c_and_expression (pp
, e
);
1593 /* inclusive-OR-expression:
1594 exclusive-OR-expression
1595 inclusive-OR-expression | exclusive-OR-expression */
1598 pp_c_inclusive_or_expression (c_pretty_printer
*pp
, tree e
)
1600 if (TREE_CODE (e
) == BIT_IOR_EXPR
)
1602 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
1603 pp_c_whitespace (pp
);
1605 pp_c_whitespace (pp
);
1606 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
1609 pp_c_exclusive_or_expression (pp
, e
);
1612 /* logical-AND-expression:
1613 inclusive-OR-expression
1614 logical-AND-expression && inclusive-OR-expression */
1617 pp_c_logical_and_expression (c_pretty_printer
*pp
, tree e
)
1619 if (TREE_CODE (e
) == TRUTH_ANDIF_EXPR
)
1621 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 0));
1622 pp_c_whitespace (pp
);
1623 pp_identifier (pp
, "&&");
1624 pp_c_whitespace (pp
);
1625 pp_c_inclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
1628 pp_c_inclusive_or_expression (pp
, e
);
1631 /* logical-OR-expression:
1632 logical-AND-expression
1633 logical-OR-expression || logical-AND-expression */
1636 pp_c_logical_or_expression (c_pretty_printer
*pp
, tree e
)
1638 if (TREE_CODE (e
) == TRUTH_ORIF_EXPR
)
1640 pp_c_logical_or_expression (pp
, TREE_OPERAND (e
, 0));
1641 pp_c_whitespace (pp
);
1642 pp_identifier (pp
, "||");
1643 pp_c_whitespace (pp
);
1644 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 1));
1647 pp_c_logical_and_expression (pp
, e
);
1650 /* conditional-expression:
1651 logical-OR-expression
1652 logical-OR-expression ? expression : conditional-expression */
1655 pp_c_conditional_expression (c_pretty_printer
*pp
, tree e
)
1657 if (TREE_CODE (e
) == COND_EXPR
)
1659 pp_c_logical_or_expression (pp
, TREE_OPERAND (e
, 0));
1660 pp_c_whitespace (pp
);
1662 pp_c_whitespace (pp
);
1663 pp_expression (pp
, TREE_OPERAND (e
, 1));
1664 pp_c_whitespace (pp
);
1666 pp_c_whitespace (pp
);
1667 pp_c_conditional_expression (pp
, TREE_OPERAND (e
, 2));
1670 pp_c_logical_or_expression (pp
, e
);
1674 /* assignment-expression:
1675 conditional-expression
1676 unary-expression assignment-operator assignment-expression
1678 assignment-expression: one of
1679 = *= /= %= += -= >>= <<= &= ^= |= */
1682 pp_c_assignment_expression (c_pretty_printer
*pp
, tree e
)
1684 if (TREE_CODE (e
) == MODIFY_EXPR
|| TREE_CODE (e
) == INIT_EXPR
)
1686 pp_c_unary_expression (pp
, TREE_OPERAND (e
, 0));
1687 pp_c_whitespace (pp
);
1690 pp_c_expression (pp
, TREE_OPERAND (e
, 1));
1693 pp_c_conditional_expression (pp
, e
);
1697 assignment-expression
1698 expression , assignment-expression
1700 Implementation note: instead of going through the usual recursion
1701 chain, I take the liberty of dispatching nodes to the appropriate
1702 functions. This makes some redundancy, but it worths it. That also
1703 prevents a possible infinite recursion between pp_c_primary_expression ()
1704 and pp_c_expression (). */
1707 pp_c_expression (c_pretty_printer
*pp
, tree e
)
1709 switch (TREE_CODE (e
))
1712 pp_c_integer_constant (pp
, e
);
1716 pp_c_floating_constant (pp
, e
);
1720 pp_c_string_literal (pp
, e
);
1723 case IDENTIFIER_NODE
:
1733 pp_primary_expression (pp
, e
);
1736 case POSTINCREMENT_EXPR
:
1737 case POSTDECREMENT_EXPR
:
1747 case COMPOUND_LITERAL_EXPR
:
1749 pp_postfix_expression (pp
, e
);
1757 case TRUTH_NOT_EXPR
:
1758 case PREINCREMENT_EXPR
:
1759 case PREDECREMENT_EXPR
:
1764 pp_c_unary_expression (pp
, e
);
1768 case FIX_TRUNC_EXPR
:
1770 pp_c_cast_expression (pp
, e
);
1774 case TRUNC_MOD_EXPR
:
1775 case TRUNC_DIV_EXPR
:
1776 pp_multiplicative_expression (pp
, e
);
1781 pp_c_shift_expression (pp
, e
);
1788 pp_c_relational_expression (pp
, e
);
1792 pp_c_and_expression (pp
, e
);
1796 pp_c_exclusive_or_expression (pp
, e
);
1800 pp_c_inclusive_or_expression (pp
, e
);
1803 case TRUTH_ANDIF_EXPR
:
1804 pp_c_logical_and_expression (pp
, e
);
1807 case TRUTH_ORIF_EXPR
:
1808 pp_c_logical_or_expression (pp
, e
);
1813 pp_c_equality_expression (pp
, e
);
1817 pp_conditional_expression (pp
, e
);
1822 pp_c_additive_expression (pp
, e
);
1827 pp_assignment_expression (pp
, e
);
1831 pp_c_left_paren (pp
);
1832 pp_expression (pp
, TREE_OPERAND (e
, 0));
1833 pp_separate_with (pp
, ',');
1834 pp_assignment_expression (pp
, TREE_OPERAND (e
, 1));
1835 pp_c_right_paren (pp
);
1839 case NON_LVALUE_EXPR
:
1842 pp_expression (pp
, TREE_OPERAND (e
, 0));
1846 pp_postfix_expression (pp
, TREE_OPERAND (e
, 1));
1850 pp_unsupported_tree (pp
, e
);
1862 expression-statement
1868 pp_c_statement (c_pretty_printer
*pp
, tree stmt
)
1870 enum tree_code code
;
1875 code
= TREE_CODE (stmt
);
1878 /* labeled-statement:
1879 identifier : statement
1880 case constant-expression : statement
1881 default : statement */
1884 if (pp_needs_newline (pp
))
1885 pp_newline_and_indent (pp
, -3);
1887 pp_indentation (pp
) -= 3;
1888 if (code
== LABEL_STMT
)
1889 pp_c_tree_decl_identifier (pp
, LABEL_STMT_LABEL (stmt
));
1890 else if (code
== CASE_LABEL
)
1892 if (CASE_LOW (stmt
) == NULL_TREE
)
1893 pp_identifier (pp
, "default");
1896 pp_c_identifier (pp
, "case");
1897 pp_c_whitespace (pp
);
1898 pp_conditional_expression (pp
, CASE_LOW (stmt
));
1899 if (CASE_HIGH (stmt
))
1901 pp_identifier (pp
, "...");
1902 pp_conditional_expression (pp
, CASE_HIGH (stmt
));
1907 pp_indentation (pp
) += 3;
1908 pp_needs_newline (pp
) = true;
1911 /* compound-statement:
1912 { block-item-list(opt) }
1916 block-item-list block-item
1922 if (pp_needs_newline (pp
))
1923 pp_newline_and_indent (pp
, 0);
1924 pp_c_left_brace (pp
);
1925 pp_newline_and_indent (pp
, 3);
1926 for (stmt
= COMPOUND_BODY (stmt
); stmt
; stmt
= TREE_CHAIN (stmt
))
1927 pp_statement (pp
, 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;
2070 tree e
= code
== RETURN_STMT
2071 ? RETURN_STMT_EXPR (stmt
)
2072 : GOTO_DESTINATION (stmt
);
2073 if (pp_needs_newline (pp
))
2074 pp_newline_and_indent (pp
, 0);
2075 pp_c_identifier (pp
, code
== RETURN_STMT
? "return" : "goto");
2076 pp_c_whitespace (pp
);
2079 if (TREE_CODE (e
) == INIT_EXPR
2080 && TREE_CODE (TREE_OPERAND (e
, 0)) == RESULT_DECL
)
2081 e
= TREE_OPERAND (e
, 1);
2082 pp_expression (pp
, e
);
2084 pp_c_semicolon (pp
);
2085 pp_needs_newline (pp
) = true;
2090 if (!SCOPE_NULLIFIED_P (stmt
) && SCOPE_NO_CLEANUPS_P (stmt
))
2093 if (pp_needs_newline (pp
))
2094 pp_newline_and_indent (pp
, 0);
2095 if (SCOPE_BEGIN_P (stmt
))
2100 else if (SCOPE_END_P (stmt
))
2102 pp_right_brace (pp
);
2105 pp_indentation (pp
) += i
;
2106 pp_needs_newline (pp
) = true;
2111 if (pp_needs_newline (pp
))
2112 pp_newline_and_indent (pp
, 0);
2113 pp_declaration (pp
, DECL_STMT_DECL (stmt
));
2114 pp_needs_newline (pp
) = true;
2119 bool has_volatile_p
= ASM_VOLATILE_P (stmt
);
2120 bool is_extended
= has_volatile_p
|| ASM_INPUTS (stmt
)
2121 || ASM_OUTPUTS (stmt
) || ASM_CLOBBERS (stmt
);
2122 pp_c_identifier (pp
, is_extended
? "__asm__" : "asm");
2124 pp_c_identifier (pp
, "__volatile__");
2126 pp_c_left_paren (pp
);
2127 pp_c_string_literal (pp
, ASM_STRING (stmt
));
2131 pp_separate_with (pp
, ':');
2132 if (ASM_OUTPUTS (stmt
))
2133 pp_expression (pp
, ASM_OUTPUTS (stmt
));
2135 pp_separate_with (pp
, ':');
2136 if (ASM_INPUTS (stmt
))
2137 pp_expression (pp
, ASM_INPUTS (stmt
));
2139 pp_separate_with (pp
, ':');
2140 if (ASM_CLOBBERS (stmt
))
2141 pp_expression (pp
, ASM_CLOBBERS (stmt
));
2143 pp_c_right_paren (pp
);
2149 pp_unsupported_tree (pp
, stmt
);
2154 /* Initialize the PRETTY-PRINTER for handling C codes. */
2157 pp_c_pretty_printer_init (c_pretty_printer
*pp
)
2159 pp
->offset_list
= 0;
2161 pp
->declaration
= pp_c_declaration
;
2162 pp
->declaration_specifiers
= pp_c_declaration_specifiers
;
2163 pp
->declarator
= pp_c_declarator
;
2164 pp
->direct_declarator
= pp_c_direct_declarator
;
2165 pp
->type_specifier_seq
= pp_c_specifier_qualifier_list
;
2166 pp
->abstract_declarator
= pp_c_abstract_declarator
;
2167 pp
->direct_abstract_declarator
= pp_c_direct_abstract_declarator
;
2168 pp
->ptr_operator
= pp_c_pointer
;
2169 pp
->parameter_list
= pp_c_parameter_type_list
;
2170 pp
->type_id
= pp_c_type_id
;
2171 pp
->simple_type_specifier
= pp_c_type_specifier
;
2172 pp
->function_specifier
= pp_c_function_specifier
;
2173 pp
->storage_class_specifier
= pp_c_storage_class_specifier
;
2175 pp
->statement
= pp_c_statement
;
2177 pp
->id_expression
= pp_c_id_expression
;
2178 pp
->primary_expression
= pp_c_primary_expression
;
2179 pp
->postfix_expression
= pp_c_postfix_expression
;
2180 pp
->unary_expression
= pp_c_unary_expression
;
2181 pp
->initializer
= pp_c_initializer
;
2182 pp
->multiplicative_expression
= pp_c_multiplicative_expression
;
2183 pp
->conditional_expression
= pp_c_conditional_expression
;
2184 pp
->assignment_expression
= pp_c_assignment_expression
;
2185 pp
->expression
= pp_c_expression
;
2189 /* Print the tree T in full, on file FILE. */
2192 print_c_tree (FILE *file
, tree t
)
2194 static c_pretty_printer pp_rec
;
2195 static bool initialized
= 0;
2196 c_pretty_printer
*pp
= &pp_rec
;
2201 pp_construct (pp_base (pp
), NULL
, 0);
2202 pp_c_pretty_printer_init (pp
);
2203 pp_needs_newline (pp
) = true;
2205 pp_base (pp
)->buffer
->stream
= file
;
2207 pp_statement (pp
, t
);
2213 /* Print the tree T in full, on stderr. */
2216 debug_c_tree (tree t
)
2218 print_c_tree (stderr
, t
);
2219 fputc ('\n', stderr
);
2222 /* Output the DECL_NAME of T. If T has no DECL_NAME, output a string made
2223 up of T's memory address. */
2226 pp_c_tree_decl_identifier (c_pretty_printer
*pp
, tree t
)
2234 name
= IDENTIFIER_POINTER (DECL_NAME (t
));
2237 static char xname
[8];
2238 sprintf (xname
, "<U%4x>", ((unsigned)((unsigned long)(t
) & 0xffff)));
2242 pp_c_identifier (pp
, name
);