1 /* Subroutines common to both C and C++ pretty-printers.
2 Copyright (C) 2002 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"
31 static void pp_c_char
PARAMS ((c_pretty_printer
, int));
32 static void pp_c_character_literal
PARAMS ((c_pretty_printer
, tree
));
33 static void pp_c_bool_literal
PARAMS ((c_pretty_printer
, tree
));
34 static bool pp_c_enumerator
PARAMS ((c_pretty_printer
, tree
));
35 static void pp_c_integer_literal
PARAMS ((c_pretty_printer
, tree
));
36 static void pp_c_real_literal
PARAMS ((c_pretty_printer
, tree
));
37 static void pp_c_string_literal
PARAMS ((c_pretty_printer
, tree
));
39 static void pp_c_primary_expression
PARAMS ((c_pretty_printer
, tree
));
41 /* postfix-expression */
42 static void pp_c_initializer_list
PARAMS ((c_pretty_printer
, tree
));
44 static void pp_c_unary_expression
PARAMS ((c_pretty_printer
, tree
));
45 static void pp_c_multiplicative_expression
PARAMS ((c_pretty_printer
, tree
));
46 static void pp_c_additive_expression
PARAMS ((c_pretty_printer
, tree
));
47 static void pp_c_shift_expression
PARAMS ((c_pretty_printer
, tree
));
48 static void pp_c_relational_expression
PARAMS ((c_pretty_printer
, tree
));
49 static void pp_c_equality_expression
PARAMS ((c_pretty_printer
, tree
));
50 static void pp_c_and_expression
PARAMS ((c_pretty_printer
, tree
));
51 static void pp_c_exclusive_or_expression
PARAMS ((c_pretty_printer
,
53 static void pp_c_inclusive_or_expression
PARAMS ((c_pretty_printer
,
55 static void pp_c_logical_and_expression
PARAMS ((c_pretty_printer
, tree
));
56 static void pp_c_conditional_expression
PARAMS ((c_pretty_printer
, tree
));
57 static void pp_c_assignment_expression
PARAMS ((c_pretty_printer
, tree
));
60 static void pp_c_declaration_specifiers
PARAMS ((c_pretty_printer
, tree
));
61 static void pp_c_init_declarator
PARAMS ((c_pretty_printer
, tree
));
62 static void pp_c_declarator
PARAMS ((c_pretty_printer
, tree
));
63 static void pp_c_direct_declarator
PARAMS ((c_pretty_printer
, tree
));
64 static void pp_c_abstract_declarator
PARAMS ((c_pretty_printer
, tree
));
65 static void pp_c_specifier_qualifier_list
PARAMS ((c_pretty_printer
, tree
));
66 static void pp_c_simple_type_specifier
PARAMS ((c_pretty_printer
, tree
));
67 static void pp_c_parameter_declaration
PARAMS ((c_pretty_printer
, tree
));
68 static void pp_c_type_id
PARAMS ((c_pretty_printer
, tree
));
69 static void pp_c_storage_class_specifier
PARAMS ((c_pretty_printer
, tree
));
70 static void pp_c_function_specifier
PARAMS ((c_pretty_printer
, tree
));
75 /* Print out CV-qualifiers. Take care of possible extensions. */
77 pp_c_cv_qualifier (ppi
, cv
)
81 if (cv
& TYPE_QUAL_CONST
)
82 pp_c_identifier (ppi
, "const");
83 if (cv
& TYPE_QUAL_VOLATILE
)
84 pp_c_identifier (ppi
, "volatile");
85 if (cv
& TYPE_QUAL_RESTRICT
)
86 pp_c_identifier (ppi
, flag_isoc99
? "restrict" : "__restrict__");
90 pp_c_simple_type_specifier (ppi
, t
)
94 const enum tree_code code
= TREE_CODE (t
);
98 pp_c_identifier (ppi
, "<type-error>");
103 pp_c_identifier (ppi
, "<unkown-type>");
107 case IDENTIFIER_NODE
:
108 pp_c_tree_identifier (ppi
, t
);
116 pp_c_tree_identifier (ppi
, DECL_NAME (t
));
121 pp_c_simple_type_specifier (ppi
, TYPE_MAIN_VARIANT (TREE_TYPE (t
)));
122 if (code
== COMPLEX_TYPE
)
123 pp_c_identifier (ppi
, flag_isoc99
? "_Complex" : "__complex__");
124 else if (code
== VECTOR_TYPE
)
125 pp_c_identifier (ppi
, "__vector__");
130 pp_c_tree_identifier (ppi
, DECL_NAME (t
));
132 pp_c_identifier (ppi
, "<typedef-error>");
138 if (code
== UNION_TYPE
)
139 pp_c_identifier (ppi
, "union");
140 else if (code
== RECORD_TYPE
)
141 pp_c_identifier (ppi
, "struct");
142 else if (code
== ENUMERAL_TYPE
)
143 pp_c_identifier (ppi
, "enum");
145 pp_c_identifier (ppi
, "<tag-error>");
148 pp_c_tree_identifier (ppi
, TYPE_NAME (t
));
150 pp_c_identifier (ppi
, "<anonymous>");
154 pp_unsupported_tree (ppi
, t
);
159 pp_c_specifier_qualifier_list (ppi
, t
)
160 c_pretty_printer ppi
;
163 pp_c_simple_type_specifier (ppi
, TYPE_MAIN_VARIANT (TREE_TYPE (t
)));
164 pp_c_cv_qualifier (ppi
, TYPE_QUALS (t
));
168 pp_c_abstract_declarator (ppi
, t
)
169 c_pretty_printer ppi
;
172 pp_unsupported_tree (ppi
, t
);
177 pp_c_type_id (ppi
, t
)
178 c_pretty_printer ppi
;
181 pp_c_specifier_qualifier_list (ppi
, t
);
182 pp_c_abstract_declarator (ppi
, t
);
186 pp_c_storage_class_specifier (pp
, t
)
190 if (TREE_CODE (t
) == TYPE_DECL
)
191 pp_c_identifier (pp
, "typedef");
192 else if (DECL_REGISTER (t
))
193 pp_c_identifier (pp
, "register");
197 pp_c_function_specifier (pp
, t
)
201 if (TREE_CODE (t
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (t
))
202 pp_c_identifier (pp
, "inline");
206 pp_c_declaration_specifiers (pp
, t
)
210 pp_c_storage_class_specifier (pp
, t
);
211 pp_c_function_specifier (pp
, t
);
212 pp_type_specifier (pp
, TYPE_MAIN_VARIANT (TREE_TYPE (t
)));
213 pp_c_cv_qualifier (pp
, TYPE_QUALS (TREE_TYPE (t
)));
217 pp_c_direct_declarator (pp
, t
)
221 pp_unsupported_tree (pp
, t
);
225 pp_c_declarator (pp
, t
)
229 pp_unsupported_tree (pp
, t
);
233 pp_c_init_declarator (pp
, t
)
237 pp_declarator (pp
, t
);
238 if (DECL_INITIAL (t
))
243 pp_c_initializer (pp
, DECL_INITIAL (t
));
248 pp_c_declaration (pp
, t
)
252 pp_declaration_specifiers (pp
, t
);
253 pp_c_init_declarator (pp
, t
);
257 pp_c_parameter_declaration (pp
, t
)
261 pp_unsupported_tree (pp
, t
);
264 /* Pretty-print ATTRIBUTES using GNU C extension syntax. */
266 pp_c_attributes (pp
, attributes
)
270 if (attributes
== NULL_TREE
)
273 pp_c_identifier (pp
, "__attribute__");
274 pp_c_left_paren (pp
);
275 pp_c_left_paren (pp
);
276 for (; attributes
!= NULL_TREE
; attributes
= TREE_CHAIN (attributes
))
278 pp_tree_identifier (pp
, TREE_PURPOSE (attributes
));
279 if (TREE_VALUE (attributes
))
281 pp_c_left_paren (pp
);
282 pp_c_expression_list (pp
, TREE_VALUE (attributes
));
283 pp_c_right_paren (pp
);
286 if (TREE_CHAIN (attributes
))
287 pp_separate_with (pp
, ',');
289 pp_c_right_paren (pp
);
290 pp_c_right_paren (pp
);
296 /* Print out a c-char. */
299 c_pretty_printer ppi
;
305 pp_identifier (ppi
, "\\n");
308 pp_identifier (ppi
, "\\t");
311 pp_identifier (ppi
, "\\v");
314 pp_identifier (ppi
, "\\b");
317 pp_identifier (ppi
, "\\r");
320 pp_identifier (ppi
, "\\f");
323 pp_identifier (ppi
, "\\a");
326 pp_identifier (ppi
, "\\\\");
329 pp_identifier (ppi
, "\\'");
332 pp_identifier (ppi
, "\\\"");
336 pp_character (ppi
, c
);
338 pp_format_scalar (ppi
, "\\%03o", (unsigned) c
);
343 /* Print out a STRING literal. */
345 pp_c_string_literal (ppi
, s
)
346 c_pretty_printer ppi
;
349 const char *p
= TREE_STRING_POINTER (s
);
350 int n
= TREE_STRING_LENGTH (s
) - 1;
352 pp_doublequote (ppi
);
353 for (i
= 0; i
< n
; ++i
)
354 pp_c_char (ppi
, p
[i
]);
355 pp_doublequote (ppi
);
358 /* Print out a CHARACTER literal. */
360 pp_c_character_literal (ppi
, c
)
361 c_pretty_printer ppi
;
365 pp_c_char (ppi
, tree_low_cst (c
, 0));
369 /* Print out a BOOLEAN literal. */
371 pp_c_bool_literal (ppi
, b
)
372 c_pretty_printer ppi
;
375 if (b
== boolean_false_node
|| integer_zerop (b
))
377 if (c_language
== clk_cplusplus
)
378 pp_c_identifier (ppi
, "false");
379 else if (c_language
== clk_c
&& flag_isoc99
)
380 pp_c_identifier (ppi
, "_False");
382 pp_unsupported_tree (ppi
, b
);
384 else if (b
== boolean_true_node
)
386 if (c_language
== clk_cplusplus
)
387 pp_c_identifier (ppi
, "true");
388 else if (c_language
== clk_c
&& flag_isoc99
)
389 pp_c_identifier (ppi
, "_True");
391 pp_unsupported_tree (ppi
, b
);
394 pp_unsupported_tree (ppi
, b
);
397 /* Attempt to print out an ENUMERATOR. Return true on success. Else return
398 false; that means the value was obtained by a cast, in which case
399 print out the type-id part of the cast-expression -- the casted value
400 is then printed by pp_c_integer_literal. */
402 pp_c_enumerator (ppi
, e
)
403 c_pretty_printer ppi
;
406 tree type
= TREE_TYPE (e
);
409 /* Find the name of this constant. */
410 for (value
= TYPE_VALUES (type
);
411 value
!= NULL_TREE
&& !tree_int_cst_equal (TREE_VALUE (value
), e
);
412 value
= TREE_CHAIN (value
))
415 if (value
!= NULL_TREE
)
416 pp_c_tree_identifier (ppi
, TREE_PURPOSE (value
));
419 /* Value must have been cast. */
420 pp_c_left_paren (ppi
);
421 pp_type_id (ppi
, type
);
422 pp_c_right_paren (ppi
);
429 /* Print out an INTEGER constant value. */
431 pp_c_integer_literal (ppi
, i
)
432 c_pretty_printer ppi
;
435 tree type
= TREE_TYPE (i
);
437 if (type
== boolean_type_node
)
438 pp_c_bool_literal (ppi
, i
);
439 else if (type
== char_type_node
)
440 pp_c_character_literal (ppi
, i
);
441 else if (TREE_CODE (type
) == ENUMERAL_TYPE
442 && pp_c_enumerator (ppi
, i
))
446 if (host_integerp (i
, 0))
447 pp_wide_integer (ppi
, TREE_INT_CST_LOW (i
));
450 if (tree_int_cst_sgn (i
) < 0)
452 static char format
[10]; /* "%x%09999x\0" */
454 sprintf (format
, "%%x%%0%dx", HOST_BITS_PER_INT
/ 4);
456 pp_c_char (ppi
, '-');
457 i
= build_int_2 (-TREE_INT_CST_LOW (i
),
458 ~TREE_INT_CST_HIGH (i
) + !TREE_INT_CST_LOW (i
));
459 sprintf (pp_buffer (ppi
)->digit_buffer
, format
,
460 TREE_INT_CST_HIGH (i
), TREE_INT_CST_LOW (i
));
461 pp_identifier (ppi
, pp_buffer (ppi
)->digit_buffer
);
468 /* Print out a REAL value. */
470 pp_c_real_literal (ppi
, r
)
471 c_pretty_printer ppi
;
474 real_to_decimal (pp_buffer (ppi
)->digit_buffer
, &TREE_REAL_CST (r
),
475 sizeof (pp_buffer (ppi
)->digit_buffer
), 0, 1);
476 pp_identifier (ppi
, pp_buffer(ppi
)->digit_buffer
);
481 pp_c_literal (ppi
, e
)
482 c_pretty_printer ppi
;
485 switch (TREE_CODE (e
))
488 pp_c_integer_literal (ppi
, e
);
492 pp_c_real_literal (ppi
, e
);
496 pp_c_string_literal (ppi
, e
);
500 pp_unsupported_tree (ppi
, e
);
505 /* Pretty-print a C primary-expression. */
507 pp_c_primary_expression (ppi
, e
)
508 c_pretty_printer ppi
;
511 switch (TREE_CODE (e
))
521 case IDENTIFIER_NODE
:
522 pp_c_tree_identifier (ppi
, e
);
526 pp_c_identifier (ppi
, "<erroneous-expression>");
530 pp_c_identifier (ppi
, "<return-value>");
536 pp_c_literal (ppi
, e
);
540 pp_c_left_paren (ppi
);
541 pp_c_identifier (ppi
, "__builtin_memcpy");
542 pp_c_left_paren (ppi
);
544 pp_c_primary_expression (ppi
, TREE_OPERAND (e
, 0));
545 pp_separate_with (ppi
, ',');
547 pp_initializer (ppi
, TREE_OPERAND (e
, 1));
548 if (TREE_OPERAND (e
, 2))
550 pp_separate_with (ppi
, ',');
551 pp_c_expression (ppi
, TREE_OPERAND (e
, 2));
553 pp_c_right_paren (ppi
);
556 pp_c_left_paren (ppi
);
557 pp_statement (ppi
, STMT_EXPR_STMT (e
));
558 pp_c_right_paren (ppi
);
562 /* Make sure this call won't cause any infinite loop. */
563 pp_c_left_paren (ppi
);
564 pp_c_expression (ppi
, e
);
565 pp_c_right_paren (ppi
);
570 /* Print out a C initializer -- also support C compound-literals. */
572 pp_c_initializer (ppi
, e
)
573 c_pretty_printer ppi
;
576 if (TREE_CODE (e
) == CONSTRUCTOR
)
578 enum tree_code code
= TREE_CODE (TREE_TYPE (e
));
579 if (code
== RECORD_TYPE
|| code
== UNION_TYPE
|| code
== ARRAY_TYPE
)
582 pp_c_initializer_list (ppi
, e
);
583 pp_right_brace (ppi
);
586 pp_unsupported_tree (ppi
, TREE_OPERAND (e
, 1));
589 pp_assignment_expression (ppi
, e
);
593 pp_c_initializer_list (ppi
, e
)
594 c_pretty_printer ppi
;
597 tree type
= TREE_TYPE (e
);
598 const enum tree_code code
= TREE_CODE (type
);
600 if (code
== RECORD_TYPE
|| code
== UNION_TYPE
|| code
== ARRAY_TYPE
)
602 tree init
= TREE_OPERAND (e
, 1);
603 for (; init
!= NULL_TREE
; init
= TREE_CHAIN (init
))
605 if (code
== RECORD_TYPE
|| code
== UNION_TYPE
)
608 pp_c_primary_expression (ppi
, TREE_PURPOSE (init
));
612 pp_c_left_bracket (ppi
);
613 if (TREE_PURPOSE (init
))
614 pp_c_literal (ppi
, TREE_PURPOSE (init
));
615 pp_c_right_bracket (ppi
);
617 pp_c_whitespace (ppi
);
619 pp_c_whitespace (ppi
);
620 pp_initializer (ppi
, TREE_VALUE (init
));
621 if (TREE_CHAIN (init
))
622 pp_separate_with (ppi
, ',');
626 pp_unsupported_tree (ppi
, type
);
630 pp_c_postfix_expression (ppi
, e
)
631 c_pretty_printer ppi
;
634 enum tree_code code
= TREE_CODE (e
);
637 case POSTINCREMENT_EXPR
:
638 case POSTDECREMENT_EXPR
:
639 pp_postfix_expression (ppi
, TREE_OPERAND (e
, 0));
640 pp_identifier (ppi
, code
== POSTINCREMENT_EXPR
? "++" : "--");
644 pp_postfix_expression (ppi
, TREE_OPERAND (e
, 0));
649 pp_postfix_expression (ppi
, TREE_OPERAND (e
, 0));
650 pp_c_left_bracket (ppi
);
651 pp_c_expression (ppi
, TREE_OPERAND (e
, 1));
652 pp_c_right_bracket (ppi
);
656 pp_postfix_expression (ppi
, TREE_OPERAND (e
, 0));
657 pp_c_left_paren (ppi
);
658 pp_c_expression_list (ppi
, TREE_OPERAND (e
, 1));
659 pp_c_right_paren (ppi
);
664 pp_c_identifier (ppi
,
665 code
== ABS_EXPR
? "__builtin_abs" : "__builtin_ffs");
666 pp_c_left_paren (ppi
);
667 pp_c_expression (ppi
, TREE_OPERAND (e
, 0));
668 pp_c_right_paren (ppi
);
673 tree object
= TREE_OPERAND (e
, 0);
674 if (TREE_CODE (object
) == INDIRECT_REF
)
676 pp_postfix_expression (ppi
, TREE_OPERAND (object
, 0));
681 pp_postfix_expression (ppi
, object
);
684 pp_c_expression (ppi
, TREE_OPERAND (e
, 1));
691 pp_c_left_paren (ppi
);
692 pp_type_id (ppi
, TREE_TYPE (e
));
693 pp_c_right_paren (ppi
);
696 if (code
== COMPLEX_CST
)
698 pp_c_expression (ppi
, TREE_REALPART (e
));
699 pp_separate_with (ppi
, ',');
700 pp_c_expression (ppi
, TREE_IMAGPART (e
));
702 else if (code
== VECTOR_CST
)
703 pp_c_expression_list (ppi
, TREE_VECTOR_CST_ELTS (e
));
704 else if (code
== COMPLEX_EXPR
)
706 pp_c_expression (ppi
, TREE_OPERAND (e
, 0));
707 pp_separate_with (ppi
, ',');
708 pp_c_expression (ppi
, TREE_OPERAND (e
, 1));
711 pp_right_brace (ppi
);
714 case COMPOUND_LITERAL_EXPR
:
715 e
= DECL_INITIAL (e
);
718 pp_initializer (ppi
, e
);
724 pp_identifier (ppi
, "__location__");
725 pp_right_paren (ppi
);
729 pp_identifier (ppi
, "file");
732 pp_c_whitespace (ppi
);
733 pp_c_expression (ppi
, SRCLOC_FILE (e
));
734 pp_separate_with (ppi
, ',');
736 pp_identifier (ppi
, "line");
739 pp_c_whitespace (ppi
);
740 pp_c_expression (ppi
, SRCLOC_LINE (e
));
741 pp_right_brace (ppi
);
746 pp_c_identifier (ppi
, "__builtin_va_arg");
747 pp_c_left_paren (ppi
);
748 pp_assignment_expression (ppi
, TREE_OPERAND (e
, 0));
749 pp_separate_with (ppi
, ',');
750 pp_type_id (ppi
, TREE_TYPE (e
));
751 pp_c_right_paren (ppi
);
755 pp_primary_expression (ppi
, e
);
760 /* Print out an expression-list; E is expected to be a TREE_LIST */
762 pp_c_expression_list (ppi
, e
)
763 c_pretty_printer ppi
;
766 for (; e
!= NULL_TREE
; e
= TREE_CHAIN (e
))
768 pp_c_assignment_expression (ppi
, TREE_VALUE (e
));
770 pp_separate_with (ppi
, ',');
775 pp_c_unary_expression (ppi
, e
)
776 c_pretty_printer ppi
;
779 enum tree_code code
= TREE_CODE (e
);
782 case PREINCREMENT_EXPR
:
783 case PREDECREMENT_EXPR
:
784 pp_identifier (ppi
, code
== PREINCREMENT_EXPR
? "++" : "--");
785 pp_c_unary_expression (ppi
, TREE_OPERAND (e
, 0));
795 if (code
== ADDR_EXPR
)
797 else if (code
== INDIRECT_REF
)
799 else if (code
== NEGATE_EXPR
)
801 else if (code
== BIT_NOT_EXPR
|| code
== CONJ_EXPR
)
803 else if (code
== TRUTH_NOT_EXPR
)
804 pp_exclamation (ppi
);
805 pp_c_cast_expression (ppi
, TREE_OPERAND (e
, 0));
810 pp_c_identifier (ppi
, code
== SIZEOF_EXPR
? "sizeof" : "__alignof__");
811 pp_c_whitespace (ppi
);
812 if (TYPE_P (TREE_OPERAND (e
, 0)))
814 pp_c_left_paren (ppi
);
815 pp_type_id (ppi
, TREE_OPERAND (e
, 0));
816 pp_c_right_paren (ppi
);
819 pp_c_unary_expression (ppi
, TREE_OPERAND (e
, 0));
824 pp_c_identifier (ppi
, code
== REALPART_EXPR
? "__real__" : "__imag__");
825 pp_c_whitespace (ppi
);
826 pp_unary_expression (ppi
, TREE_OPERAND (e
, 0));
830 pp_postfix_expression (ppi
, e
);
836 pp_c_cast_expression (ppi
, e
)
837 c_pretty_printer ppi
;
840 if (TREE_CODE (e
) == CONVERT_EXPR
|| TREE_CODE (e
) == FLOAT_EXPR
)
842 pp_c_left_paren (ppi
);
843 pp_type_id (ppi
, TREE_TYPE (e
));
844 pp_c_right_paren (ppi
);
845 pp_c_cast_expression (ppi
, TREE_OPERAND (e
, 0));
848 pp_unary_expression (ppi
, e
);
852 pp_c_multiplicative_expression (ppi
, e
)
853 c_pretty_printer ppi
;
856 enum tree_code code
= TREE_CODE (e
);
862 pp_c_multiplicative_expression (ppi
, TREE_OPERAND (e
, 0));
863 pp_c_whitespace (ppi
);
864 if (code
== MULT_EXPR
)
866 else if (code
== TRUNC_DIV_EXPR
)
870 pp_c_whitespace (ppi
);
871 pp_c_cast_expression (ppi
, TREE_OPERAND (e
, 1));
875 pp_c_cast_expression (ppi
, e
);
881 pp_c_additive_expression (ppi
, e
)
882 c_pretty_printer ppi
;
885 enum tree_code code
= TREE_CODE (e
);
890 pp_c_additive_expression (ppi
, TREE_OPERAND (e
, 0));
891 pp_c_whitespace (ppi
);
892 if (code
== PLUS_EXPR
)
896 pp_c_whitespace (ppi
);
897 pp_multiplicative_expression (ppi
, TREE_OPERAND (e
, 1));
901 pp_multiplicative_expression (ppi
, e
);
907 pp_c_shift_expression (ppi
, e
)
908 c_pretty_printer ppi
;
911 enum tree_code code
= TREE_CODE (e
);
916 pp_c_shift_expression (ppi
, TREE_OPERAND (e
, 0));
917 pp_c_whitespace (ppi
);
918 pp_identifier (ppi
, code
== LSHIFT_EXPR
? "<<" : ">>");
919 pp_c_whitespace (ppi
);
920 pp_c_additive_expression (ppi
, TREE_OPERAND (e
, 1));
924 pp_c_additive_expression (ppi
, e
);
929 pp_c_relational_expression (ppi
, e
)
930 c_pretty_printer ppi
;
933 enum tree_code code
= TREE_CODE (e
);
940 pp_c_relational_expression (ppi
, TREE_OPERAND (e
, 0));
941 pp_c_whitespace (ppi
);
944 else if (code
== GT_EXPR
)
946 else if (code
== LE_EXPR
)
947 pp_identifier (ppi
, "<=");
948 else if (code
== GE_EXPR
)
949 pp_identifier (ppi
, ">=");
950 pp_c_whitespace (ppi
);
951 pp_c_shift_expression (ppi
, TREE_OPERAND (e
, 1));
955 pp_c_shift_expression (ppi
, e
);
961 pp_c_equality_expression (ppi
, e
)
962 c_pretty_printer ppi
;
965 enum tree_code code
= TREE_CODE (e
);
970 pp_c_equality_expression (ppi
, TREE_OPERAND (e
, 0));
971 pp_c_maybe_whitespace (ppi
);
972 pp_identifier (ppi
, code
== EQ_EXPR
? "==" : "!=");
973 pp_c_whitespace (ppi
);
974 pp_c_relational_expression (ppi
, TREE_OPERAND (e
, 1));
978 pp_c_relational_expression (ppi
, e
);
984 pp_c_and_expression (ppi
, e
)
985 c_pretty_printer ppi
;
988 if (TREE_CODE (e
) == BIT_AND_EXPR
)
990 pp_c_and_expression (ppi
, TREE_OPERAND (e
, 0));
991 pp_c_maybe_whitespace (ppi
);
993 pp_c_whitespace (ppi
);
994 pp_c_equality_expression (ppi
, TREE_OPERAND (e
, 1));
997 pp_c_equality_expression (ppi
, e
);
1001 pp_c_exclusive_or_expression (ppi
, e
)
1002 c_pretty_printer ppi
;
1005 if (TREE_CODE (e
) == BIT_XOR_EXPR
)
1007 pp_c_exclusive_or_expression (ppi
, TREE_OPERAND (e
, 0));
1008 pp_c_maybe_whitespace (ppi
);
1010 pp_c_whitespace (ppi
);
1011 pp_c_and_expression (ppi
, TREE_OPERAND (e
, 1));
1014 pp_c_and_expression (ppi
, e
);
1018 pp_c_inclusive_or_expression (ppi
, e
)
1019 c_pretty_printer ppi
;
1022 if (TREE_CODE (e
) == BIT_IOR_EXPR
)
1024 pp_c_exclusive_or_expression (ppi
, TREE_OPERAND (e
, 0));
1025 pp_c_maybe_whitespace (ppi
);
1027 pp_c_whitespace (ppi
);
1028 pp_c_exclusive_or_expression (ppi
, TREE_OPERAND (e
, 1));
1031 pp_c_exclusive_or_expression (ppi
, e
);
1035 pp_c_logical_and_expression (ppi
, e
)
1036 c_pretty_printer ppi
;
1039 if (TREE_CODE (e
) == TRUTH_ANDIF_EXPR
)
1041 pp_c_logical_and_expression (ppi
, TREE_OPERAND (e
, 0));
1042 pp_c_maybe_whitespace (ppi
);
1043 pp_identifier (ppi
, "&&");
1044 pp_c_whitespace (ppi
);
1045 pp_c_inclusive_or_expression (ppi
, TREE_OPERAND (e
, 1));
1048 pp_c_inclusive_or_expression (ppi
, e
);
1052 pp_c_logical_or_expression (ppi
, e
)
1053 c_pretty_printer ppi
;
1056 if (TREE_CODE (e
) == TRUTH_ORIF_EXPR
)
1058 pp_c_logical_or_expression (ppi
, TREE_OPERAND (e
, 0));
1059 pp_c_maybe_whitespace (ppi
);
1060 pp_identifier (ppi
, "||");
1061 pp_c_whitespace (ppi
);
1062 pp_c_logical_and_expression (ppi
, TREE_OPERAND (e
, 1));
1065 pp_c_logical_and_expression (ppi
, e
);
1069 pp_c_conditional_expression (ppi
, e
)
1070 c_pretty_printer ppi
;
1073 if (TREE_CODE (e
) == COND_EXPR
)
1075 pp_c_logical_or_expression (ppi
, TREE_OPERAND (e
, 0));
1076 pp_c_maybe_whitespace (ppi
);
1078 pp_c_whitespace (ppi
);
1079 pp_c_expression (ppi
, TREE_OPERAND (e
, 1));
1080 pp_c_maybe_whitespace (ppi
);
1082 pp_c_whitespace (ppi
);
1083 pp_c_conditional_expression (ppi
, TREE_OPERAND (e
, 2));
1086 pp_c_logical_or_expression (ppi
, e
);
1090 /* Pretty-print a C assignment-expression. */
1092 pp_c_assignment_expression (ppi
, e
)
1093 c_pretty_printer ppi
;
1096 if (TREE_CODE (e
) == MODIFY_EXPR
|| TREE_CODE (e
) == INIT_EXPR
)
1098 pp_c_unary_expression (ppi
, TREE_OPERAND (e
, 0));
1099 pp_c_maybe_whitespace (ppi
);
1101 pp_whitespace (ppi
);
1102 pp_c_assignment_expression (ppi
, TREE_OPERAND (e
, 1));
1105 pp_c_conditional_expression (ppi
, e
);
1108 /* Pretty-print an expression. */
1110 pp_c_expression (ppi
, e
)
1111 c_pretty_printer ppi
;
1114 switch (TREE_CODE (e
))
1117 pp_c_integer_literal (ppi
, e
);
1121 pp_c_real_literal (ppi
, e
);
1125 pp_c_string_literal (ppi
, e
);
1138 pp_c_primary_expression (ppi
, e
);
1141 case POSTINCREMENT_EXPR
:
1142 case POSTDECREMENT_EXPR
:
1152 case COMPOUND_LITERAL_EXPR
:
1155 pp_c_postfix_expression (ppi
, e
);
1163 case TRUTH_NOT_EXPR
:
1164 case PREINCREMENT_EXPR
:
1165 case PREDECREMENT_EXPR
:
1170 pp_c_unary_expression (ppi
, e
);
1175 pp_c_cast_expression (ppi
, e
);
1179 case TRUNC_MOD_EXPR
:
1180 case TRUNC_DIV_EXPR
:
1181 pp_c_multiplicative_expression (ppi
, e
);
1186 pp_c_shift_expression (ppi
, e
);
1193 pp_c_relational_expression (ppi
, e
);
1197 pp_c_and_expression (ppi
, e
);
1201 pp_c_exclusive_or_expression (ppi
, e
);
1205 pp_c_inclusive_or_expression (ppi
, e
);
1208 case TRUTH_ANDIF_EXPR
:
1209 pp_c_logical_and_expression (ppi
, e
);
1212 case TRUTH_ORIF_EXPR
:
1213 pp_c_logical_or_expression (ppi
, e
);
1217 pp_c_conditional_expression (ppi
, e
);
1222 pp_c_assignment_expression (ppi
, e
);
1226 pp_c_expression (ppi
, TREE_OPERAND (e
, 0));
1230 pp_c_left_paren (ppi
);
1231 pp_c_expression (ppi
, TREE_OPERAND (e
, 0));
1232 pp_separate_with (ppi
, ',');
1233 pp_assignment_expression (ppi
, TREE_OPERAND (e
, 1));
1234 pp_c_right_paren (ppi
);
1239 pp_unsupported_tree (ppi
, e
);
1247 pp_c_statement (ppi
, stmt
)
1248 c_pretty_printer ppi
;
1251 const enum tree_code code
= TREE_CODE (stmt
);
1257 if (code
== LABEL_STMT
)
1258 pp_tree_identifier (ppi
, DECL_NAME (LABEL_STMT_LABEL (stmt
)));
1259 else if (code
== LABEL_STMT
)
1261 if (CASE_LOW (stmt
) == NULL_TREE
)
1262 pp_identifier (ppi
, "default");
1265 pp_c_identifier (ppi
, "case");
1266 pp_c_whitespace (ppi
);
1267 pp_conditional_expression (ppi
, CASE_LOW (stmt
));
1268 if (CASE_HIGH (stmt
))
1270 pp_identifier (ppi
, "...");
1271 pp_conditional_expression (ppi
, CASE_HIGH (stmt
));
1276 pp_newline_and_indent (ppi
, 3);
1280 pp_left_brace (ppi
);
1281 pp_newline_and_indent (ppi
, 3);
1282 for (stmt
= COMPOUND_BODY (stmt
); stmt
; stmt
= TREE_CHAIN (stmt
))
1283 pp_c_statement (ppi
, stmt
);
1284 pp_newline_and_indent (ppi
, -3);
1285 pp_right_brace (ppi
);
1292 pp_c_expression (ppi
, code
== EXPR_STMT
1293 ? EXPR_STMT_EXPR (stmt
)
1294 : CLEANUP_EXPR (stmt
));
1300 pp_c_identifier (ppi
, "if");
1301 pp_whitespace (ppi
);
1302 pp_c_left_paren (ppi
);
1303 pp_c_expression (ppi
, IF_COND (stmt
));
1304 pp_right_paren (ppi
);
1305 pp_newline_and_indent (ppi
, 3);
1306 pp_statement (ppi
, THEN_CLAUSE (stmt
));
1307 pp_newline_and_indent (ppi
, -3);
1308 if (ELSE_CLAUSE (stmt
))
1310 tree else_clause
= ELSE_CLAUSE (stmt
);
1311 pp_c_identifier (ppi
, "else");
1312 if (TREE_CODE (else_clause
) == IF_STMT
)
1313 pp_c_whitespace (ppi
);
1315 pp_newline_and_indent (ppi
, 3);
1316 pp_statement (ppi
, else_clause
);
1317 if (TREE_CODE (else_clause
) != IF_STMT
)
1318 pp_newline_and_indent (ppi
, -3);
1324 pp_c_identifier (ppi
, "switch");
1325 pp_whitespace (ppi
);
1326 pp_c_left_paren (ppi
);
1327 pp_c_expression (ppi
, SWITCH_COND (stmt
));
1328 pp_right_paren (ppi
);
1329 pp_newline_and_indent (ppi
, 3);
1330 pp_statement (ppi
, SWITCH_BODY (stmt
));
1331 pp_newline_and_indent (ppi
, -3);
1335 pp_c_identifier (ppi
, "while");
1336 pp_whitespace (ppi
);
1337 pp_c_left_paren (ppi
);
1338 pp_c_expression (ppi
, WHILE_COND (stmt
));
1339 pp_right_paren (ppi
);
1340 pp_newline_and_indent (ppi
, 3);
1341 pp_statement (ppi
, WHILE_BODY (stmt
));
1342 pp_newline_and_indent (ppi
, -3);
1346 pp_c_identifier (ppi
, "do");
1347 pp_newline_and_indent (ppi
, 3);
1348 pp_statement (ppi
, DO_BODY (stmt
));
1349 pp_newline_and_indent (ppi
, -3);
1350 pp_c_identifier (ppi
, "while");
1351 pp_whitespace (ppi
);
1352 pp_c_left_paren (ppi
);
1353 pp_c_expression (ppi
, DO_COND (stmt
));
1354 pp_c_right_paren (ppi
);
1360 pp_c_identifier (ppi
, "for");
1361 pp_whitespace (ppi
);
1362 pp_c_left_paren (ppi
);
1363 pp_statement (ppi
, FOR_INIT_STMT (stmt
));
1364 pp_c_whitespace (ppi
);
1365 if (FOR_COND (stmt
))
1366 pp_c_expression (ppi
, FOR_COND (stmt
));
1368 pp_c_whitespace (ppi
);
1369 if (FOR_EXPR (stmt
))
1370 pp_c_expression (ppi
, FOR_EXPR (stmt
));
1371 pp_right_paren (ppi
);
1372 pp_newline_and_indent (ppi
, 3);
1373 pp_statement (ppi
, FOR_BODY (stmt
));
1374 pp_newline_and_indent (ppi
, -3);
1380 pp_identifier (ppi
, code
== BREAK_STMT
? "break" : "continue");
1388 tree e
= code
== RETURN_STMT
1389 ? RETURN_STMT_EXPR (stmt
)
1390 : GOTO_DESTINATION (stmt
);
1393 pp_c_identifier (ppi
, code
== RETURN_STMT
? "return" : "goto");
1395 pp_c_expression (ppi
, e
);
1402 if (!SCOPE_NULLIFIED_P (stmt
) && SCOPE_NO_CLEANUPS_P (stmt
))
1404 if (SCOPE_BEGIN_P (stmt
))
1406 pp_left_brace (ppi
);
1407 pp_newline_and_indent (ppi
, 3);
1409 else if (SCOPE_END_P (stmt
))
1411 pp_right_brace (ppi
);
1412 pp_newline_and_indent (ppi
, -3);
1418 pp_declaration (ppi
, DECL_STMT_DECL (stmt
));
1425 bool has_volatile_p
= ASM_VOLATILE_P (stmt
);
1426 bool is_extended
= has_volatile_p
|| ASM_INPUTS (stmt
)
1427 || ASM_OUTPUTS (stmt
) || ASM_CLOBBERS (stmt
);
1428 pp_c_identifier (ppi
, is_extended
? "__asm__" : "asm");
1430 pp_c_identifier (ppi
, "__volatile__");
1431 pp_whitespace (ppi
);
1432 pp_c_left_paren (ppi
);
1433 pp_c_string_literal (ppi
, ASM_STRING (stmt
));
1436 pp_whitespace (ppi
);
1437 pp_separate_with (ppi
, ':');
1438 if (ASM_OUTPUTS (stmt
))
1439 pp_c_expression (ppi
, ASM_OUTPUTS (stmt
));
1440 pp_whitespace (ppi
);
1441 pp_separate_with (ppi
, ':');
1442 if (ASM_INPUTS (stmt
))
1443 pp_c_expression (ppi
, ASM_INPUTS (stmt
));
1444 pp_whitespace (ppi
);
1445 pp_separate_with (ppi
, ':');
1446 if (ASM_CLOBBERS (stmt
))
1447 pp_c_expression (ppi
, ASM_CLOBBERS (stmt
));
1449 pp_right_paren (ppi
);
1455 pp_c_identifier (ppi
, "__FILE__");
1456 pp_whitespace (ppi
);
1458 pp_c_whitespace (ppi
);
1459 pp_c_identifier (ppi
, FILE_STMT_FILENAME (stmt
));
1465 pp_unsupported_tree (ppi
, stmt
);
1471 /* Initialize the PRETTY-PRINTER for handling C codes. */
1473 pp_c_pretty_printer_init (pp
)
1474 c_pretty_printer pp
;
1476 pp
->offset_list
= 0;
1478 pp
->declaration
= pp_c_declaration
;
1479 pp
->declaration_specifiers
= pp_c_declaration_specifiers
;
1480 pp
->type_specifier
= pp_c_simple_type_specifier
;
1481 pp
->declarator
= pp_c_declarator
;
1482 pp
->direct_declarator
= pp_c_direct_declarator
;
1483 pp
->parameter_declaration
= pp_c_parameter_declaration
;
1484 pp
->type_id
= pp_c_type_id
;
1486 pp
->statement
= pp_c_statement
;
1488 pp
->primary_expression
= pp_c_primary_expression
;
1489 pp
->postfix_expression
= pp_c_postfix_expression
;
1490 pp
->unary_expression
= pp_c_unary_expression
;
1491 pp
->initializer
= pp_c_initializer
;
1492 pp
->multiplicative_expression
= pp_c_multiplicative_expression
;
1493 pp
->conditional_expression
= pp_c_conditional_expression
;
1494 pp
->assignment_expression
= pp_c_assignment_expression
;