1 /* Subroutines common to both C and C++ pretty-printers.
2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 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 3, 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 COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
26 #include "fixed-value.h"
27 #include "c-pretty-print.h"
29 #include "tree-iterator.h"
30 #include "diagnostic.h"
32 /* The pretty-printer code is primarily designed to closely follow
33 (GNU) C and C++ grammars. That is to be contrasted with spaghetti
34 codes we used to have in the past. Following a structured
35 approach (preferably the official grammars) is believed to make it
36 much easier to add extensions and nifty pretty-printing effects that
37 takes expression or declaration contexts into account. */
40 #define pp_c_maybe_whitespace(PP) \
42 if (pp_base (PP)->padding == pp_before) \
43 pp_c_whitespace (PP); \
47 static void pp_c_char (c_pretty_printer
*, int);
49 /* postfix-expression */
50 static void pp_c_initializer_list (c_pretty_printer
*, tree
);
51 static void pp_c_brace_enclosed_initializer_list (c_pretty_printer
*, tree
);
53 static void pp_c_multiplicative_expression (c_pretty_printer
*, tree
);
54 static void pp_c_additive_expression (c_pretty_printer
*, tree
);
55 static void pp_c_shift_expression (c_pretty_printer
*, tree
);
56 static void pp_c_relational_expression (c_pretty_printer
*, tree
);
57 static void pp_c_equality_expression (c_pretty_printer
*, tree
);
58 static void pp_c_and_expression (c_pretty_printer
*, tree
);
59 static void pp_c_exclusive_or_expression (c_pretty_printer
*, tree
);
60 static void pp_c_inclusive_or_expression (c_pretty_printer
*, tree
);
61 static void pp_c_logical_and_expression (c_pretty_printer
*, tree
);
62 static void pp_c_conditional_expression (c_pretty_printer
*, tree
);
63 static void pp_c_assignment_expression (c_pretty_printer
*, tree
);
68 /* Helper functions. */
71 pp_c_whitespace (c_pretty_printer
*pp
)
74 pp_base (pp
)->padding
= pp_none
;
78 pp_c_left_paren (c_pretty_printer
*pp
)
81 pp_base (pp
)->padding
= pp_none
;
85 pp_c_right_paren (c_pretty_printer
*pp
)
88 pp_base (pp
)->padding
= pp_none
;
92 pp_c_left_brace (c_pretty_printer
*pp
)
95 pp_base (pp
)->padding
= pp_none
;
99 pp_c_right_brace (c_pretty_printer
*pp
)
102 pp_base (pp
)->padding
= pp_none
;
106 pp_c_left_bracket (c_pretty_printer
*pp
)
108 pp_left_bracket (pp
);
109 pp_base (pp
)->padding
= pp_none
;
113 pp_c_right_bracket (c_pretty_printer
*pp
)
115 pp_right_bracket (pp
);
116 pp_base (pp
)->padding
= pp_none
;
120 pp_c_dot (c_pretty_printer
*pp
)
123 pp_base (pp
)->padding
= pp_none
;
127 pp_c_ampersand (c_pretty_printer
*pp
)
130 pp_base (pp
)->padding
= pp_none
;
134 pp_c_star (c_pretty_printer
*pp
)
137 pp_base (pp
)->padding
= pp_none
;
141 pp_c_arrow (c_pretty_printer
*pp
)
144 pp_base (pp
)->padding
= pp_none
;
148 pp_c_semicolon (c_pretty_printer
*pp
)
151 pp_base (pp
)->padding
= pp_none
;
155 pp_c_complement (c_pretty_printer
*pp
)
158 pp_base (pp
)->padding
= pp_none
;
162 pp_c_exclamation (c_pretty_printer
*pp
)
165 pp_base (pp
)->padding
= pp_none
;
168 /* Print out the external representation of CV-QUALIFIER. */
171 pp_c_cv_qualifier (c_pretty_printer
*pp
, const char *cv
)
173 const char *p
= pp_last_position_in_text (pp
);
174 /* The C programming language does not have references, but it is much
175 simpler to handle those here rather than going through the same
176 logic in the C++ pretty-printer. */
177 if (p
!= NULL
&& (*p
== '*' || *p
== '&'))
178 pp_c_whitespace (pp
);
179 pp_c_identifier (pp
, cv
);
182 /* Pretty-print T using the type-cast notation '( type-name )'. */
185 pp_c_type_cast (c_pretty_printer
*pp
, tree t
)
187 pp_c_left_paren (pp
);
189 pp_c_right_paren (pp
);
192 /* We're about to pretty-print a pointer type as indicated by T.
193 Output a whitespace, if needed, preparing for subsequent output. */
196 pp_c_space_for_pointer_operator (c_pretty_printer
*pp
, tree t
)
198 if (POINTER_TYPE_P (t
))
200 tree pointee
= strip_pointer_operator (TREE_TYPE (t
));
201 if (TREE_CODE (pointee
) != ARRAY_TYPE
202 && TREE_CODE (pointee
) != FUNCTION_TYPE
)
203 pp_c_whitespace (pp
);
210 /* C++ cv-qualifiers are called type-qualifiers in C. Print out the
211 cv-qualifiers of T. If T is a declaration then it is the cv-qualifier
212 of its type. Take care of possible extensions.
216 type-qualifier-list type-qualifier
221 __restrict__ -- GNU C
225 pp_c_type_qualifier_list (c_pretty_printer
*pp
, tree t
)
232 qualifiers
= TYPE_QUALS (t
);
233 if (qualifiers
& TYPE_QUAL_CONST
)
234 pp_c_cv_qualifier (pp
, "const");
235 if (qualifiers
& TYPE_QUAL_VOLATILE
)
236 pp_c_cv_qualifier (pp
, "volatile");
237 if (qualifiers
& TYPE_QUAL_RESTRICT
)
238 pp_c_cv_qualifier (pp
, flag_isoc99
? "restrict" : "__restrict__");
242 * type-qualifier-list(opt)
243 * type-qualifier-list(opt) pointer */
246 pp_c_pointer (c_pretty_printer
*pp
, tree t
)
248 if (!TYPE_P (t
) && TREE_CODE (t
) != TYPE_DECL
)
250 switch (TREE_CODE (t
))
253 /* It is easier to handle C++ reference types here. */
255 if (TREE_CODE (TREE_TYPE (t
)) == POINTER_TYPE
)
256 pp_c_pointer (pp
, TREE_TYPE (t
));
257 if (TREE_CODE (t
) == POINTER_TYPE
)
261 pp_c_type_qualifier_list (pp
, t
);
264 /* ??? This node is now in GENERIC and so shouldn't be here. But
265 we'll fix that later. */
267 pp_declaration (pp
, DECL_EXPR_DECL (t
));
268 pp_needs_newline (pp
) = true;
272 pp_unsupported_tree (pp
, t
);
289 struct-or-union-specifier
294 simple-type-specifier:
299 pp_c_type_specifier (c_pretty_printer
*pp
, tree t
)
301 const enum tree_code code
= TREE_CODE (t
);
305 pp_c_identifier (pp
, "<type-error>");
308 case IDENTIFIER_NODE
:
309 pp_c_tree_decl_identifier (pp
, t
);
316 case FIXED_POINT_TYPE
:
320 pp_c_type_specifier (pp
, t
);
324 int prec
= TYPE_PRECISION (t
);
325 if (ALL_FIXED_POINT_MODE_P (TYPE_MODE (t
)))
326 t
= c_common_type_for_mode (TYPE_MODE (t
), TYPE_SATURATING (t
));
328 t
= c_common_type_for_mode (TYPE_MODE (t
), TYPE_UNSIGNED (t
));
331 pp_c_type_specifier (pp
, t
);
332 if (TYPE_PRECISION (t
) != prec
)
335 pp_decimal_int (pp
, prec
);
343 pp_string (pp
, (TYPE_UNSIGNED (t
)
344 ? "<unnamed-unsigned:"
345 : "<unnamed-signed:"));
348 pp_string (pp
, "<unnamed-float:");
350 case FIXED_POINT_TYPE
:
351 pp_string (pp
, "<unnamed-fixed:");
356 pp_decimal_int (pp
, prec
);
364 pp_id_expression (pp
, t
);
366 pp_c_identifier (pp
, "<typedef-error>");
372 if (code
== UNION_TYPE
)
373 pp_c_identifier (pp
, "union");
374 else if (code
== RECORD_TYPE
)
375 pp_c_identifier (pp
, "struct");
376 else if (code
== ENUMERAL_TYPE
)
377 pp_c_identifier (pp
, "enum");
379 pp_c_identifier (pp
, "<tag-error>");
382 pp_id_expression (pp
, TYPE_NAME (t
));
384 pp_c_identifier (pp
, "<anonymous>");
388 pp_unsupported_tree (pp
, t
);
393 /* specifier-qualifier-list:
394 type-specifier specifier-qualifier-list-opt
395 type-qualifier specifier-qualifier-list-opt
398 Implementation note: Because of the non-linearities in array or
399 function declarations, this routine prints not just the
400 specifier-qualifier-list of such entities or types of such entities,
401 but also the 'pointer' production part of their declarators. The
402 remaining part is done by pp_declarator or pp_c_abstract_declarator. */
405 pp_c_specifier_qualifier_list (c_pretty_printer
*pp
, tree t
)
407 const enum tree_code code
= TREE_CODE (t
);
409 if (TREE_CODE (t
) != POINTER_TYPE
)
410 pp_c_type_qualifier_list (pp
, t
);
416 /* Get the types-specifier of this type. */
417 tree pointee
= strip_pointer_operator (TREE_TYPE (t
));
418 pp_c_specifier_qualifier_list (pp
, pointee
);
419 if (TREE_CODE (pointee
) == ARRAY_TYPE
420 || TREE_CODE (pointee
) == FUNCTION_TYPE
)
422 pp_c_whitespace (pp
);
423 pp_c_left_paren (pp
);
425 else if (!c_dialect_cxx ())
426 pp_c_whitespace (pp
);
427 pp_ptr_operator (pp
, t
);
433 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
438 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
439 if (code
== COMPLEX_TYPE
)
440 pp_c_identifier (pp
, flag_isoc99
? "_Complex" : "__complex__");
441 else if (code
== VECTOR_TYPE
)
442 pp_c_identifier (pp
, "__vector__");
446 pp_simple_type_specifier (pp
, t
);
451 /* parameter-type-list:
456 parameter-declaration
457 parameter-list , parameter-declaration
459 parameter-declaration:
460 declaration-specifiers declarator
461 declaration-specifiers abstract-declarator(opt) */
464 pp_c_parameter_type_list (c_pretty_printer
*pp
, tree t
)
466 bool want_parm_decl
= DECL_P (t
) && !(pp
->flags
& pp_c_flag_abstract
);
467 tree parms
= want_parm_decl
? DECL_ARGUMENTS (t
) : TYPE_ARG_TYPES (t
);
468 pp_c_left_paren (pp
);
469 if (parms
== void_list_node
)
470 pp_c_identifier (pp
, "void");
474 for ( ; parms
&& parms
!= void_list_node
; parms
= TREE_CHAIN (parms
))
477 pp_separate_with (pp
, ',');
479 pp_declaration_specifiers
480 (pp
, want_parm_decl
? parms
: TREE_VALUE (parms
));
482 pp_declarator (pp
, parms
);
484 pp_abstract_declarator (pp
, TREE_VALUE (parms
));
487 pp_c_right_paren (pp
);
490 /* abstract-declarator:
492 pointer(opt) direct-abstract-declarator */
495 pp_c_abstract_declarator (c_pretty_printer
*pp
, tree t
)
497 if (TREE_CODE (t
) == POINTER_TYPE
)
499 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
500 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
501 pp_c_right_paren (pp
);
505 pp_direct_abstract_declarator (pp
, t
);
508 /* direct-abstract-declarator:
509 ( abstract-declarator )
510 direct-abstract-declarator(opt) [ assignment-expression(opt) ]
511 direct-abstract-declarator(opt) [ * ]
512 direct-abstract-declarator(opt) ( parameter-type-list(opt) ) */
515 pp_c_direct_abstract_declarator (c_pretty_printer
*pp
, tree t
)
517 switch (TREE_CODE (t
))
520 pp_abstract_declarator (pp
, t
);
524 pp_c_parameter_type_list (pp
, t
);
525 pp_direct_abstract_declarator (pp
, TREE_TYPE (t
));
529 pp_c_left_bracket (pp
);
530 if (TYPE_DOMAIN (t
) && TYPE_MAX_VALUE (TYPE_DOMAIN (t
)))
532 tree maxval
= TYPE_MAX_VALUE (TYPE_DOMAIN (t
));
533 tree type
= TREE_TYPE (maxval
);
535 if (host_integerp (maxval
, 0))
536 pp_wide_integer (pp
, tree_low_cst (maxval
, 0) + 1);
538 pp_expression (pp
, fold_build2 (PLUS_EXPR
, type
, maxval
,
539 build_int_cst (type
, 1)));
541 pp_c_right_bracket (pp
);
542 pp_direct_abstract_declarator (pp
, TREE_TYPE (t
));
545 case IDENTIFIER_NODE
:
550 case FIXED_POINT_TYPE
:
560 pp_unsupported_tree (pp
, t
);
566 specifier-qualifier-list abstract-declarator(opt) */
569 pp_c_type_id (c_pretty_printer
*pp
, tree t
)
571 pp_c_specifier_qualifier_list (pp
, t
);
572 pp_abstract_declarator (pp
, t
);
575 /* storage-class-specifier:
583 pp_c_storage_class_specifier (c_pretty_printer
*pp
, tree t
)
585 if (TREE_CODE (t
) == TYPE_DECL
)
586 pp_c_identifier (pp
, "typedef");
589 if (DECL_REGISTER (t
))
590 pp_c_identifier (pp
, "register");
591 else if (TREE_STATIC (t
) && TREE_CODE (t
) == VAR_DECL
)
592 pp_c_identifier (pp
, "static");
596 /* function-specifier:
600 pp_c_function_specifier (c_pretty_printer
*pp
, tree t
)
602 if (TREE_CODE (t
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (t
))
603 pp_c_identifier (pp
, "inline");
606 /* declaration-specifiers:
607 storage-class-specifier declaration-specifiers(opt)
608 type-specifier declaration-specifiers(opt)
609 type-qualifier declaration-specifiers(opt)
610 function-specifier declaration-specifiers(opt) */
613 pp_c_declaration_specifiers (c_pretty_printer
*pp
, tree t
)
615 pp_storage_class_specifier (pp
, t
);
616 pp_function_specifier (pp
, t
);
617 pp_c_specifier_qualifier_list (pp
, DECL_P (t
) ? TREE_TYPE (t
) : t
);
623 direct-declarator [ type-qualifier-list(opt) assignment-expression(opt) ]
624 direct-declarator [ static type-qualifier-list(opt) assignment-expression(opt)]
625 direct-declarator [ type-qualifier-list static assignment-expression ]
626 direct-declarator [ type-qualifier-list * ]
627 direct-declarator ( parameter-type-list )
628 direct-declarator ( identifier-list(opt) ) */
631 pp_c_direct_declarator (c_pretty_printer
*pp
, tree t
)
633 switch (TREE_CODE (t
))
640 pp_c_space_for_pointer_operator (pp
, TREE_TYPE (t
));
641 pp_c_tree_decl_identifier (pp
, t
);
646 pp_abstract_declarator (pp
, TREE_TYPE (t
));
650 pp_parameter_list (pp
, t
);
651 pp_abstract_declarator (pp
, TREE_TYPE (t
));
655 pp_c_space_for_pointer_operator (pp
, TREE_TYPE (TREE_TYPE (t
)));
656 pp_c_tree_decl_identifier (pp
, t
);
657 if (pp_c_base (pp
)->flags
& pp_c_flag_abstract
)
658 pp_abstract_declarator (pp
, TREE_TYPE (t
));
661 pp_parameter_list (pp
, t
);
662 pp_abstract_declarator (pp
, TREE_TYPE (TREE_TYPE (t
)));
668 case FIXED_POINT_TYPE
:
675 pp_unsupported_tree (pp
, t
);
682 pointer(opt) direct-declarator */
685 pp_c_declarator (c_pretty_printer
*pp
, tree t
)
687 switch (TREE_CODE (t
))
691 case FIXED_POINT_TYPE
:
704 pp_direct_declarator (pp
, t
);
709 pp_unsupported_tree (pp
, t
);
715 declaration-specifiers init-declarator-list(opt) ; */
718 pp_c_declaration (c_pretty_printer
*pp
, tree t
)
720 pp_declaration_specifiers (pp
, t
);
721 pp_c_init_declarator (pp
, t
);
724 /* Pretty-print ATTRIBUTES using GNU C extension syntax. */
727 pp_c_attributes (c_pretty_printer
*pp
, tree attributes
)
729 if (attributes
== NULL_TREE
)
732 pp_c_identifier (pp
, "__attribute__");
733 pp_c_left_paren (pp
);
734 pp_c_left_paren (pp
);
735 for (; attributes
!= NULL_TREE
; attributes
= TREE_CHAIN (attributes
))
737 pp_tree_identifier (pp
, TREE_PURPOSE (attributes
));
738 if (TREE_VALUE (attributes
))
739 pp_c_call_argument_list (pp
, TREE_VALUE (attributes
));
741 if (TREE_CHAIN (attributes
))
742 pp_separate_with (pp
, ',');
744 pp_c_right_paren (pp
);
745 pp_c_right_paren (pp
);
748 /* function-definition:
749 declaration-specifiers declarator compound-statement */
752 pp_c_function_definition (c_pretty_printer
*pp
, tree t
)
754 pp_declaration_specifiers (pp
, t
);
755 pp_declarator (pp
, t
);
756 pp_needs_newline (pp
) = true;
757 pp_statement (pp
, DECL_SAVED_TREE (t
));
765 /* Print out a c-char. This is called solely for characters which are
766 in the *target* execution character set. We ought to convert them
767 back to the *host* execution character set before printing, but we
768 have no way to do this at present. A decent compromise is to print
769 all characters as if they were in the host execution character set,
770 and not attempt to recover any named escape characters, but render
771 all unprintables as octal escapes. If the host and target character
772 sets are the same, this produces relatively readable output. If they
773 are not the same, strings may appear as gibberish, but that's okay
774 (in fact, it may well be what the reader wants, e.g. if they are looking
775 to see if conversion to the target character set happened correctly).
777 A special case: we need to prefix \, ", and ' with backslashes. It is
778 correct to do so for the *host*'s \, ", and ', because the rest of the
779 file appears in the host character set. */
782 pp_c_char (c_pretty_printer
*pp
, int c
)
788 case '\\': pp_string (pp
, "\\\\"); break;
789 case '\'': pp_string (pp
, "\\\'"); break;
790 case '\"': pp_string (pp
, "\\\""); break;
791 default: pp_character (pp
, c
);
795 pp_scalar (pp
, "\\%03o", (unsigned) c
);
798 /* Print out a STRING literal. */
801 pp_c_string_literal (c_pretty_printer
*pp
, tree s
)
803 const char *p
= TREE_STRING_POINTER (s
);
804 int n
= TREE_STRING_LENGTH (s
) - 1;
807 for (i
= 0; i
< n
; ++i
)
808 pp_c_char (pp
, p
[i
]);
812 /* Pretty-print an INTEGER literal. */
815 pp_c_integer_constant (c_pretty_printer
*pp
, tree i
)
817 tree type
= TREE_TYPE (i
);
819 if (TREE_INT_CST_HIGH (i
) == 0)
820 pp_wide_integer (pp
, TREE_INT_CST_LOW (i
));
823 unsigned HOST_WIDE_INT low
= TREE_INT_CST_LOW (i
);
824 HOST_WIDE_INT high
= TREE_INT_CST_HIGH (i
);
825 if (tree_int_cst_sgn (i
) < 0)
827 pp_character (pp
, '-');
831 sprintf (pp_buffer (pp
)->digit_buffer
,
832 HOST_WIDE_INT_PRINT_DOUBLE_HEX
, high
, low
);
833 pp_string (pp
, pp_buffer (pp
)->digit_buffer
);
835 if (TYPE_UNSIGNED (type
))
836 pp_character (pp
, 'u');
837 if (type
== long_integer_type_node
|| type
== long_unsigned_type_node
)
838 pp_character (pp
, 'l');
839 else if (type
== long_long_integer_type_node
840 || type
== long_long_unsigned_type_node
)
841 pp_string (pp
, "ll");
844 /* Print out a CHARACTER literal. */
847 pp_c_character_constant (c_pretty_printer
*pp
, tree c
)
849 tree type
= TREE_TYPE (c
);
850 if (type
== wchar_type_node
)
851 pp_character (pp
, 'L');
853 if (host_integerp (c
, TYPE_UNSIGNED (type
)))
854 pp_c_char (pp
, tree_low_cst (c
, TYPE_UNSIGNED (type
)));
856 pp_scalar (pp
, "\\x%x", (unsigned) TREE_INT_CST_LOW (c
));
860 /* Print out a BOOLEAN literal. */
863 pp_c_bool_constant (c_pretty_printer
*pp
, tree b
)
865 if (b
== boolean_false_node
)
867 if (c_dialect_cxx ())
868 pp_c_identifier (pp
, "false");
869 else if (flag_isoc99
)
870 pp_c_identifier (pp
, "_False");
872 pp_unsupported_tree (pp
, b
);
874 else if (b
== boolean_true_node
)
876 if (c_dialect_cxx ())
877 pp_c_identifier (pp
, "true");
878 else if (flag_isoc99
)
879 pp_c_identifier (pp
, "_True");
881 pp_unsupported_tree (pp
, b
);
883 else if (TREE_CODE (b
) == INTEGER_CST
)
884 pp_c_integer_constant (pp
, b
);
886 pp_unsupported_tree (pp
, b
);
889 /* Attempt to print out an ENUMERATOR. Return true on success. Else return
890 false; that means the value was obtained by a cast, in which case
891 print out the type-id part of the cast-expression -- the casted value
892 is then printed by pp_c_integer_literal. */
895 pp_c_enumeration_constant (c_pretty_printer
*pp
, tree e
)
897 bool value_is_named
= true;
898 tree type
= TREE_TYPE (e
);
901 /* Find the name of this constant. */
902 for (value
= TYPE_VALUES (type
);
903 value
!= NULL_TREE
&& !tree_int_cst_equal (TREE_VALUE (value
), e
);
904 value
= TREE_CHAIN (value
))
907 if (value
!= NULL_TREE
)
908 pp_id_expression (pp
, TREE_PURPOSE (value
));
911 /* Value must have been cast. */
912 pp_c_type_cast (pp
, type
);
913 value_is_named
= false;
916 return value_is_named
;
919 /* Print out a REAL value as a decimal-floating-constant. */
922 pp_c_floating_constant (c_pretty_printer
*pp
, tree r
)
924 real_to_decimal (pp_buffer (pp
)->digit_buffer
, &TREE_REAL_CST (r
),
925 sizeof (pp_buffer (pp
)->digit_buffer
), 0, 1);
926 pp_string (pp
, pp_buffer(pp
)->digit_buffer
);
927 if (TREE_TYPE (r
) == float_type_node
)
928 pp_character (pp
, 'f');
929 else if (TREE_TYPE (r
) == long_double_type_node
)
930 pp_character (pp
, 'l');
931 else if (TREE_TYPE (r
) == dfloat128_type_node
)
932 pp_string (pp
, "dl");
933 else if (TREE_TYPE (r
) == dfloat64_type_node
)
934 pp_string (pp
, "dd");
935 else if (TREE_TYPE (r
) == dfloat32_type_node
)
936 pp_string (pp
, "df");
939 /* Print out a FIXED value as a decimal-floating-constant. */
942 pp_c_fixed_constant (c_pretty_printer
*pp
, tree r
)
944 fixed_to_decimal (pp_buffer (pp
)->digit_buffer
, &TREE_FIXED_CST (r
),
945 sizeof (pp_buffer (pp
)->digit_buffer
));
946 pp_string (pp
, pp_buffer(pp
)->digit_buffer
);
949 /* Pretty-print a compound literal expression. GNU extensions include
953 pp_c_compound_literal (c_pretty_printer
*pp
, tree e
)
955 tree type
= TREE_TYPE (e
);
956 pp_c_type_cast (pp
, type
);
958 switch (TREE_CODE (type
))
965 pp_c_brace_enclosed_initializer_list (pp
, e
);
969 pp_unsupported_tree (pp
, e
);
979 character-constant */
982 pp_c_constant (c_pretty_printer
*pp
, tree e
)
984 const enum tree_code code
= TREE_CODE (e
);
990 tree type
= TREE_TYPE (e
);
991 if (type
== boolean_type_node
)
992 pp_c_bool_constant (pp
, e
);
993 else if (type
== char_type_node
)
994 pp_c_character_constant (pp
, e
);
995 else if (TREE_CODE (type
) == ENUMERAL_TYPE
996 && pp_c_enumeration_constant (pp
, e
))
999 pp_c_integer_constant (pp
, e
);
1004 pp_c_floating_constant (pp
, e
);
1008 pp_c_fixed_constant (pp
, e
);
1012 pp_c_string_literal (pp
, e
);
1016 /* Sometimes, we are confused and we think a complex literal
1017 is a constant. Such thing is a compound literal which
1018 grammatically belongs to postifx-expr production. */
1019 pp_c_compound_literal (pp
, e
);
1023 pp_unsupported_tree (pp
, e
);
1028 /* Pretty-print an IDENTIFIER_NODE, preceded by whitespace is necessary. */
1031 pp_c_identifier (c_pretty_printer
*pp
, const char *id
)
1033 pp_c_maybe_whitespace (pp
);
1034 pp_identifier (pp
, id
);
1035 pp_base (pp
)->padding
= pp_before
;
1038 /* Pretty-print a C primary-expression.
1046 pp_c_primary_expression (c_pretty_printer
*pp
, tree e
)
1048 switch (TREE_CODE (e
))
1056 pp_c_tree_decl_identifier (pp
, e
);
1059 case IDENTIFIER_NODE
:
1060 pp_c_tree_identifier (pp
, e
);
1064 pp_c_identifier (pp
, "<erroneous-expression>");
1068 pp_c_identifier (pp
, "<return-value>");
1075 pp_c_constant (pp
, e
);
1079 pp_c_identifier (pp
, "__builtin_memcpy");
1080 pp_c_left_paren (pp
);
1082 pp_primary_expression (pp
, TREE_OPERAND (e
, 0));
1083 pp_separate_with (pp
, ',');
1085 pp_initializer (pp
, TREE_OPERAND (e
, 1));
1086 if (TREE_OPERAND (e
, 2))
1088 pp_separate_with (pp
, ',');
1089 pp_c_expression (pp
, TREE_OPERAND (e
, 2));
1091 pp_c_right_paren (pp
);
1095 /* FIXME: Make sure we won't get into an infinie loop. */
1096 pp_c_left_paren (pp
);
1097 pp_expression (pp
, e
);
1098 pp_c_right_paren (pp
);
1103 /* Print out a C initializer -- also support C compound-literals.
1105 assignment-expression:
1106 { initializer-list }
1107 { initializer-list , } */
1110 pp_c_initializer (c_pretty_printer
*pp
, tree e
)
1112 if (TREE_CODE (e
) == CONSTRUCTOR
)
1113 pp_c_brace_enclosed_initializer_list (pp
, e
);
1115 pp_expression (pp
, e
);
1120 declarator = initializer */
1123 pp_c_init_declarator (c_pretty_printer
*pp
, tree t
)
1125 pp_declarator (pp
, t
);
1126 /* We don't want to output function definitions here. There are handled
1127 elsewhere (and the syntactic form is bogus anyway). */
1128 if (TREE_CODE (t
) != FUNCTION_DECL
&& DECL_INITIAL (t
))
1130 tree init
= DECL_INITIAL (t
);
1131 /* This C++ bit is handled here because it is easier to do so.
1132 In templates, the C++ parser builds a TREE_LIST for a
1133 direct-initialization; the TREE_PURPOSE is the variable to
1134 initialize and the TREE_VALUE is the initializer. */
1135 if (TREE_CODE (init
) == TREE_LIST
)
1137 pp_c_left_paren (pp
);
1138 pp_expression (pp
, TREE_VALUE (init
));
1139 pp_right_paren (pp
);
1146 pp_c_initializer (pp
, init
);
1151 /* initializer-list:
1152 designation(opt) initializer
1153 initializer-list , designation(opt) initializer
1160 designator-list designator
1163 [ constant-expression ]
1167 pp_c_initializer_list (c_pretty_printer
*pp
, tree e
)
1169 tree type
= TREE_TYPE (e
);
1170 const enum tree_code code
= TREE_CODE (type
);
1178 tree init
= TREE_OPERAND (e
, 0);
1179 for (; init
!= NULL_TREE
; init
= TREE_CHAIN (init
))
1181 if (code
== RECORD_TYPE
|| code
== UNION_TYPE
)
1184 pp_c_primary_expression (pp
, TREE_PURPOSE (init
));
1188 pp_c_left_bracket (pp
);
1189 if (TREE_PURPOSE (init
))
1190 pp_c_constant (pp
, TREE_PURPOSE (init
));
1191 pp_c_right_bracket (pp
);
1193 pp_c_whitespace (pp
);
1195 pp_c_whitespace (pp
);
1196 pp_initializer (pp
, TREE_VALUE (init
));
1197 if (TREE_CHAIN (init
))
1198 pp_separate_with (pp
, ',');
1204 if (TREE_CODE (e
) == VECTOR_CST
)
1205 pp_c_expression_list (pp
, TREE_VECTOR_CST_ELTS (e
));
1206 else if (TREE_CODE (e
) == CONSTRUCTOR
)
1207 pp_c_constructor_elts (pp
, CONSTRUCTOR_ELTS (e
));
1213 if (TREE_CODE (e
) == CONSTRUCTOR
)
1214 pp_c_constructor_elts (pp
, CONSTRUCTOR_ELTS (e
));
1215 else if (TREE_CODE (e
) == COMPLEX_CST
|| TREE_CODE (e
) == COMPLEX_EXPR
)
1217 const bool cst
= TREE_CODE (e
) == COMPLEX_CST
;
1218 pp_expression (pp
, cst
? TREE_REALPART (e
) : TREE_OPERAND (e
, 0));
1219 pp_separate_with (pp
, ',');
1220 pp_expression (pp
, cst
? TREE_IMAGPART (e
) : TREE_OPERAND (e
, 1));
1230 pp_unsupported_tree (pp
, type
);
1233 /* Pretty-print a brace-enclosed initializer-list. */
1236 pp_c_brace_enclosed_initializer_list (c_pretty_printer
*pp
, tree l
)
1238 pp_c_left_brace (pp
);
1239 pp_c_initializer_list (pp
, l
);
1240 pp_c_right_brace (pp
);
1244 /* This is a convenient function, used to bridge gap between C and C++
1251 pp_c_id_expression (c_pretty_printer
*pp
, tree t
)
1253 switch (TREE_CODE (t
))
1262 pp_c_tree_decl_identifier (pp
, t
);
1265 case IDENTIFIER_NODE
:
1266 pp_c_tree_identifier (pp
, t
);
1270 pp_unsupported_tree (pp
, t
);
1275 /* postfix-expression:
1277 postfix-expression [ expression ]
1278 postfix-expression ( argument-expression-list(opt) )
1279 postfix-expression . identifier
1280 postfix-expression -> identifier
1281 postfix-expression ++
1282 postfix-expression --
1283 ( type-name ) { initializer-list }
1284 ( type-name ) { initializer-list , } */
1287 pp_c_postfix_expression (c_pretty_printer
*pp
, tree e
)
1289 enum tree_code code
= TREE_CODE (e
);
1292 case POSTINCREMENT_EXPR
:
1293 case POSTDECREMENT_EXPR
:
1294 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1295 pp_identifier (pp
, code
== POSTINCREMENT_EXPR
? "++" : "--");
1299 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1300 pp_c_left_bracket (pp
);
1301 pp_expression (pp
, TREE_OPERAND (e
, 1));
1302 pp_c_right_bracket (pp
);
1307 call_expr_arg_iterator iter
;
1309 pp_postfix_expression (pp
, CALL_EXPR_FN (e
));
1310 pp_c_left_paren (pp
);
1311 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, e
)
1313 pp_expression (pp
, arg
);
1314 if (more_call_expr_args_p (&iter
))
1315 pp_separate_with (pp
, ',');
1317 pp_c_right_paren (pp
);
1321 case UNORDERED_EXPR
:
1322 pp_c_identifier (pp
, flag_isoc99
1324 : "__builtin_isunordered");
1328 pp_c_identifier (pp
, flag_isoc99
1330 : "!__builtin_isunordered");
1334 pp_c_identifier (pp
, flag_isoc99
1336 : "!__builtin_isgreaterequal");
1340 pp_c_identifier (pp
, flag_isoc99
1342 : "!__builtin_isgreater");
1346 pp_c_identifier (pp
, flag_isoc99
1348 : "!__builtin_islessequal");
1352 pp_c_identifier (pp
, flag_isoc99
1354 : "!__builtin_isless");
1358 pp_c_identifier (pp
, flag_isoc99
1360 : "!__builtin_islessgreater");
1364 pp_c_identifier (pp
, flag_isoc99
1366 : "__builtin_islessgreater");
1370 pp_c_left_paren (pp
);
1371 pp_expression (pp
, TREE_OPERAND (e
, 0));
1372 pp_separate_with (pp
, ',');
1373 pp_expression (pp
, TREE_OPERAND (e
, 1));
1374 pp_c_right_paren (pp
);
1378 pp_c_identifier (pp
, "__builtin_abs");
1379 pp_c_left_paren (pp
);
1380 pp_expression (pp
, TREE_OPERAND (e
, 0));
1381 pp_c_right_paren (pp
);
1386 tree object
= TREE_OPERAND (e
, 0);
1387 if (TREE_CODE (object
) == INDIRECT_REF
)
1389 pp_postfix_expression (pp
, TREE_OPERAND (object
, 0));
1394 pp_postfix_expression (pp
, object
);
1397 pp_expression (pp
, TREE_OPERAND (e
, 1));
1404 pp_c_compound_literal (pp
, e
);
1407 case COMPOUND_LITERAL_EXPR
:
1408 e
= DECL_INITIAL (COMPOUND_LITERAL_EXPR_DECL (e
));
1411 pp_initializer (pp
, e
);
1415 pp_c_identifier (pp
, "__builtin_va_arg");
1416 pp_c_left_paren (pp
);
1417 pp_assignment_expression (pp
, TREE_OPERAND (e
, 0));
1418 pp_separate_with (pp
, ',');
1419 pp_type_id (pp
, TREE_TYPE (e
));
1420 pp_c_right_paren (pp
);
1424 if (TREE_CODE (TREE_OPERAND (e
, 0)) == FUNCTION_DECL
)
1426 pp_c_id_expression (pp
, TREE_OPERAND (e
, 0));
1429 /* else fall through. */
1432 pp_primary_expression (pp
, e
);
1437 /* Print out an expression-list; E is expected to be a TREE_LIST. */
1440 pp_c_expression_list (c_pretty_printer
*pp
, tree e
)
1442 for (; e
!= NULL_TREE
; e
= TREE_CHAIN (e
))
1444 pp_expression (pp
, TREE_VALUE (e
));
1446 pp_separate_with (pp
, ',');
1450 /* Print out V, which contains the elements of a constructor. */
1453 pp_c_constructor_elts (c_pretty_printer
*pp
, VEC(constructor_elt
,gc
) *v
)
1455 unsigned HOST_WIDE_INT ix
;
1458 FOR_EACH_CONSTRUCTOR_VALUE (v
, ix
, value
)
1460 pp_expression (pp
, value
);
1461 if (ix
!= VEC_length (constructor_elt
, v
) - 1)
1462 pp_separate_with (pp
, ',');
1466 /* Print out an expression-list in parens, as if it were the argument
1467 list to a function. */
1470 pp_c_call_argument_list (c_pretty_printer
*pp
, tree t
)
1472 pp_c_left_paren (pp
);
1473 if (t
&& TREE_CODE (t
) == TREE_LIST
)
1474 pp_c_expression_list (pp
, t
);
1475 pp_c_right_paren (pp
);
1478 /* unary-expression:
1482 unary-operator cast-expression
1483 sizeof unary-expression
1486 unary-operator: one of
1491 __alignof__ unary-expression
1492 __alignof__ ( type-id )
1493 __real__ unary-expression
1494 __imag__ unary-expression */
1497 pp_c_unary_expression (c_pretty_printer
*pp
, tree e
)
1499 enum tree_code code
= TREE_CODE (e
);
1502 case PREINCREMENT_EXPR
:
1503 case PREDECREMENT_EXPR
:
1504 pp_identifier (pp
, code
== PREINCREMENT_EXPR
? "++" : "--");
1505 pp_c_unary_expression (pp
, TREE_OPERAND (e
, 0));
1512 case TRUTH_NOT_EXPR
:
1514 /* String literal are used by address. */
1515 if (code
== ADDR_EXPR
&& TREE_CODE (TREE_OPERAND (e
, 0)) != STRING_CST
)
1517 else if (code
== INDIRECT_REF
)
1519 else if (code
== NEGATE_EXPR
)
1521 else if (code
== BIT_NOT_EXPR
|| code
== CONJ_EXPR
)
1523 else if (code
== TRUTH_NOT_EXPR
)
1524 pp_exclamation (pp
);
1525 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 0));
1530 pp_c_identifier (pp
, code
== REALPART_EXPR
? "__real__" : "__imag__");
1531 pp_c_whitespace (pp
);
1532 pp_unary_expression (pp
, TREE_OPERAND (e
, 0));
1536 pp_postfix_expression (pp
, e
);
1543 ( type-name ) cast-expression */
1546 pp_c_cast_expression (c_pretty_printer
*pp
, tree e
)
1548 switch (TREE_CODE (e
))
1551 case FIX_TRUNC_EXPR
:
1554 pp_c_type_cast (pp
, TREE_TYPE (e
));
1555 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 0));
1559 pp_unary_expression (pp
, e
);
1563 /* multiplicative-expression:
1565 multiplicative-expression * cast-expression
1566 multiplicative-expression / cast-expression
1567 multiplicative-expression % cast-expression */
1570 pp_c_multiplicative_expression (c_pretty_printer
*pp
, tree e
)
1572 enum tree_code code
= TREE_CODE (e
);
1576 case TRUNC_DIV_EXPR
:
1577 case TRUNC_MOD_EXPR
:
1578 pp_multiplicative_expression (pp
, TREE_OPERAND (e
, 0));
1579 pp_c_whitespace (pp
);
1580 if (code
== MULT_EXPR
)
1582 else if (code
== TRUNC_DIV_EXPR
)
1586 pp_c_whitespace (pp
);
1587 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 1));
1591 pp_c_cast_expression (pp
, e
);
1596 /* additive-expression:
1597 multiplicative-expression
1598 additive-expression + multiplicative-expression
1599 additive-expression - multiplicative-expression */
1602 pp_c_additive_expression (c_pretty_printer
*pp
, tree e
)
1604 enum tree_code code
= TREE_CODE (e
);
1607 case POINTER_PLUS_EXPR
:
1610 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 0));
1611 pp_c_whitespace (pp
);
1612 if (code
== PLUS_EXPR
|| code
== POINTER_PLUS_EXPR
)
1616 pp_c_whitespace (pp
);
1617 pp_multiplicative_expression (pp
, TREE_OPERAND (e
, 1));
1621 pp_multiplicative_expression (pp
, e
);
1626 /* additive-expression:
1628 shift-expression << additive-expression
1629 shift-expression >> additive-expression */
1632 pp_c_shift_expression (c_pretty_printer
*pp
, tree e
)
1634 enum tree_code code
= TREE_CODE (e
);
1639 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 0));
1640 pp_c_whitespace (pp
);
1641 pp_identifier (pp
, code
== LSHIFT_EXPR
? "<<" : ">>");
1642 pp_c_whitespace (pp
);
1643 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 1));
1647 pp_c_additive_expression (pp
, e
);
1651 /* relational-expression:
1653 relational-expression < shift-expression
1654 relational-expression > shift-expression
1655 relational-expression <= shift-expression
1656 relational-expression >= shift-expression */
1659 pp_c_relational_expression (c_pretty_printer
*pp
, tree e
)
1661 enum tree_code code
= TREE_CODE (e
);
1668 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 0));
1669 pp_c_whitespace (pp
);
1670 if (code
== LT_EXPR
)
1672 else if (code
== GT_EXPR
)
1674 else if (code
== LE_EXPR
)
1675 pp_identifier (pp
, "<=");
1676 else if (code
== GE_EXPR
)
1677 pp_identifier (pp
, ">=");
1678 pp_c_whitespace (pp
);
1679 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 1));
1683 pp_c_shift_expression (pp
, e
);
1688 /* equality-expression:
1689 relational-expression
1690 equality-expression == relational-expression
1691 equality-equality != relational-expression */
1694 pp_c_equality_expression (c_pretty_printer
*pp
, tree e
)
1696 enum tree_code code
= TREE_CODE (e
);
1701 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 0));
1702 pp_c_whitespace (pp
);
1703 pp_identifier (pp
, code
== EQ_EXPR
? "==" : "!=");
1704 pp_c_whitespace (pp
);
1705 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 1));
1709 pp_c_relational_expression (pp
, e
);
1716 AND-expression & equality-equality */
1719 pp_c_and_expression (c_pretty_printer
*pp
, tree e
)
1721 if (TREE_CODE (e
) == BIT_AND_EXPR
)
1723 pp_c_and_expression (pp
, TREE_OPERAND (e
, 0));
1724 pp_c_whitespace (pp
);
1726 pp_c_whitespace (pp
);
1727 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 1));
1730 pp_c_equality_expression (pp
, e
);
1733 /* exclusive-OR-expression:
1735 exclusive-OR-expression ^ AND-expression */
1738 pp_c_exclusive_or_expression (c_pretty_printer
*pp
, tree e
)
1740 if (TREE_CODE (e
) == BIT_XOR_EXPR
)
1742 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
1743 pp_c_maybe_whitespace (pp
);
1745 pp_c_whitespace (pp
);
1746 pp_c_and_expression (pp
, TREE_OPERAND (e
, 1));
1749 pp_c_and_expression (pp
, e
);
1752 /* inclusive-OR-expression:
1753 exclusive-OR-expression
1754 inclusive-OR-expression | exclusive-OR-expression */
1757 pp_c_inclusive_or_expression (c_pretty_printer
*pp
, tree e
)
1759 if (TREE_CODE (e
) == BIT_IOR_EXPR
)
1761 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
1762 pp_c_whitespace (pp
);
1764 pp_c_whitespace (pp
);
1765 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
1768 pp_c_exclusive_or_expression (pp
, e
);
1771 /* logical-AND-expression:
1772 inclusive-OR-expression
1773 logical-AND-expression && inclusive-OR-expression */
1776 pp_c_logical_and_expression (c_pretty_printer
*pp
, tree e
)
1778 if (TREE_CODE (e
) == TRUTH_ANDIF_EXPR
)
1780 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 0));
1781 pp_c_whitespace (pp
);
1782 pp_identifier (pp
, "&&");
1783 pp_c_whitespace (pp
);
1784 pp_c_inclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
1787 pp_c_inclusive_or_expression (pp
, e
);
1790 /* logical-OR-expression:
1791 logical-AND-expression
1792 logical-OR-expression || logical-AND-expression */
1795 pp_c_logical_or_expression (c_pretty_printer
*pp
, tree e
)
1797 if (TREE_CODE (e
) == TRUTH_ORIF_EXPR
)
1799 pp_c_logical_or_expression (pp
, TREE_OPERAND (e
, 0));
1800 pp_c_whitespace (pp
);
1801 pp_identifier (pp
, "||");
1802 pp_c_whitespace (pp
);
1803 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 1));
1806 pp_c_logical_and_expression (pp
, e
);
1809 /* conditional-expression:
1810 logical-OR-expression
1811 logical-OR-expression ? expression : conditional-expression */
1814 pp_c_conditional_expression (c_pretty_printer
*pp
, tree e
)
1816 if (TREE_CODE (e
) == COND_EXPR
)
1818 pp_c_logical_or_expression (pp
, TREE_OPERAND (e
, 0));
1819 pp_c_whitespace (pp
);
1821 pp_c_whitespace (pp
);
1822 pp_expression (pp
, TREE_OPERAND (e
, 1));
1823 pp_c_whitespace (pp
);
1825 pp_c_whitespace (pp
);
1826 pp_c_conditional_expression (pp
, TREE_OPERAND (e
, 2));
1829 pp_c_logical_or_expression (pp
, e
);
1833 /* assignment-expression:
1834 conditional-expression
1835 unary-expression assignment-operator assignment-expression
1837 assignment-expression: one of
1838 = *= /= %= += -= >>= <<= &= ^= |= */
1841 pp_c_assignment_expression (c_pretty_printer
*pp
, tree e
)
1843 if (TREE_CODE (e
) == MODIFY_EXPR
1844 || TREE_CODE (e
) == GIMPLE_MODIFY_STMT
1845 || TREE_CODE (e
) == INIT_EXPR
)
1847 pp_c_unary_expression (pp
, GENERIC_TREE_OPERAND (e
, 0));
1848 pp_c_whitespace (pp
);
1851 pp_c_expression (pp
, GENERIC_TREE_OPERAND (e
, 1));
1854 pp_c_conditional_expression (pp
, e
);
1858 assignment-expression
1859 expression , assignment-expression
1861 Implementation note: instead of going through the usual recursion
1862 chain, I take the liberty of dispatching nodes to the appropriate
1863 functions. This makes some redundancy, but it worths it. That also
1864 prevents a possible infinite recursion between pp_c_primary_expression ()
1865 and pp_c_expression (). */
1868 pp_c_expression (c_pretty_printer
*pp
, tree e
)
1870 switch (TREE_CODE (e
))
1873 pp_c_integer_constant (pp
, e
);
1877 pp_c_floating_constant (pp
, e
);
1881 pp_c_fixed_constant (pp
, e
);
1885 pp_c_string_literal (pp
, e
);
1888 case IDENTIFIER_NODE
:
1897 pp_primary_expression (pp
, e
);
1900 case POSTINCREMENT_EXPR
:
1901 case POSTDECREMENT_EXPR
:
1909 case UNORDERED_EXPR
:
1918 case COMPOUND_LITERAL_EXPR
:
1920 pp_postfix_expression (pp
, e
);
1928 case TRUTH_NOT_EXPR
:
1929 case PREINCREMENT_EXPR
:
1930 case PREDECREMENT_EXPR
:
1933 pp_c_unary_expression (pp
, e
);
1937 case FIX_TRUNC_EXPR
:
1940 pp_c_cast_expression (pp
, e
);
1944 case TRUNC_MOD_EXPR
:
1945 case TRUNC_DIV_EXPR
:
1946 pp_multiplicative_expression (pp
, e
);
1951 pp_c_shift_expression (pp
, e
);
1958 pp_c_relational_expression (pp
, e
);
1962 pp_c_and_expression (pp
, e
);
1966 pp_c_exclusive_or_expression (pp
, e
);
1970 pp_c_inclusive_or_expression (pp
, e
);
1973 case TRUTH_ANDIF_EXPR
:
1974 pp_c_logical_and_expression (pp
, e
);
1977 case TRUTH_ORIF_EXPR
:
1978 pp_c_logical_or_expression (pp
, e
);
1983 pp_c_equality_expression (pp
, e
);
1987 pp_conditional_expression (pp
, e
);
1990 case POINTER_PLUS_EXPR
:
1993 pp_c_additive_expression (pp
, e
);
1997 case GIMPLE_MODIFY_STMT
:
1999 pp_assignment_expression (pp
, e
);
2003 pp_c_left_paren (pp
);
2004 pp_expression (pp
, TREE_OPERAND (e
, 0));
2005 pp_separate_with (pp
, ',');
2006 pp_assignment_expression (pp
, TREE_OPERAND (e
, 1));
2007 pp_c_right_paren (pp
);
2010 case NON_LVALUE_EXPR
:
2012 pp_expression (pp
, TREE_OPERAND (e
, 0));
2016 pp_postfix_expression (pp
, TREE_OPERAND (e
, 1));
2020 pp_unsupported_tree (pp
, e
);
2030 pp_c_statement (c_pretty_printer
*pp
, tree stmt
)
2035 if (pp_needs_newline (pp
))
2036 pp_newline_and_indent (pp
, 0);
2038 dump_generic_node (pp_base (pp
), stmt
, pp_indentation (pp
), 0, true);
2042 /* Initialize the PRETTY-PRINTER for handling C codes. */
2045 pp_c_pretty_printer_init (c_pretty_printer
*pp
)
2047 pp
->offset_list
= 0;
2049 pp
->declaration
= pp_c_declaration
;
2050 pp
->declaration_specifiers
= pp_c_declaration_specifiers
;
2051 pp
->declarator
= pp_c_declarator
;
2052 pp
->direct_declarator
= pp_c_direct_declarator
;
2053 pp
->type_specifier_seq
= pp_c_specifier_qualifier_list
;
2054 pp
->abstract_declarator
= pp_c_abstract_declarator
;
2055 pp
->direct_abstract_declarator
= pp_c_direct_abstract_declarator
;
2056 pp
->ptr_operator
= pp_c_pointer
;
2057 pp
->parameter_list
= pp_c_parameter_type_list
;
2058 pp
->type_id
= pp_c_type_id
;
2059 pp
->simple_type_specifier
= pp_c_type_specifier
;
2060 pp
->function_specifier
= pp_c_function_specifier
;
2061 pp
->storage_class_specifier
= pp_c_storage_class_specifier
;
2063 pp
->statement
= pp_c_statement
;
2065 pp
->constant
= pp_c_constant
;
2066 pp
->id_expression
= pp_c_id_expression
;
2067 pp
->primary_expression
= pp_c_primary_expression
;
2068 pp
->postfix_expression
= pp_c_postfix_expression
;
2069 pp
->unary_expression
= pp_c_unary_expression
;
2070 pp
->initializer
= pp_c_initializer
;
2071 pp
->multiplicative_expression
= pp_c_multiplicative_expression
;
2072 pp
->conditional_expression
= pp_c_conditional_expression
;
2073 pp
->assignment_expression
= pp_c_assignment_expression
;
2074 pp
->expression
= pp_c_expression
;
2078 /* Print the tree T in full, on file FILE. */
2081 print_c_tree (FILE *file
, tree t
)
2083 static c_pretty_printer pp_rec
;
2084 static bool initialized
= 0;
2085 c_pretty_printer
*pp
= &pp_rec
;
2090 pp_construct (pp_base (pp
), NULL
, 0);
2091 pp_c_pretty_printer_init (pp
);
2092 pp_needs_newline (pp
) = true;
2094 pp_base (pp
)->buffer
->stream
= file
;
2096 pp_statement (pp
, t
);
2102 /* Print the tree T in full, on stderr. */
2105 debug_c_tree (tree t
)
2107 print_c_tree (stderr
, t
);
2108 fputc ('\n', stderr
);
2111 /* Output the DECL_NAME of T. If T has no DECL_NAME, output a string made
2112 up of T's memory address. */
2115 pp_c_tree_decl_identifier (c_pretty_printer
*pp
, tree t
)
2119 gcc_assert (DECL_P (t
));
2122 name
= IDENTIFIER_POINTER (DECL_NAME (t
));
2125 static char xname
[8];
2126 sprintf (xname
, "<U%4x>", ((unsigned)((unsigned long)(t
) & 0xffff)));
2130 pp_c_identifier (pp
, name
);