1 /* Subroutines common to both C and C++ pretty-printers.
2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc.
4 Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
24 #include "coretypes.h"
27 #include "fixed-value.h"
29 #include "c-pretty-print.h"
31 #include "tree-iterator.h"
32 #include "diagnostic.h"
34 /* Translate if being used for diagnostics, but not for dump files or
36 #define M_(msgid) (pp_translate_identifiers (pp) ? _(msgid) : (msgid))
38 /* The pretty-printer code is primarily designed to closely follow
39 (GNU) C and C++ grammars. That is to be contrasted with spaghetti
40 codes we used to have in the past. Following a structured
41 approach (preferably the official grammars) is believed to make it
42 much easier to add extensions and nifty pretty-printing effects that
43 takes expression or declaration contexts into account. */
46 #define pp_c_maybe_whitespace(PP) \
48 if (pp_base (PP)->padding == pp_before) \
49 pp_c_whitespace (PP); \
53 static void pp_c_char (c_pretty_printer
*, int);
55 /* postfix-expression */
56 static void pp_c_initializer_list (c_pretty_printer
*, tree
);
57 static void pp_c_brace_enclosed_initializer_list (c_pretty_printer
*, tree
);
59 static void pp_c_multiplicative_expression (c_pretty_printer
*, tree
);
60 static void pp_c_additive_expression (c_pretty_printer
*, tree
);
61 static void pp_c_shift_expression (c_pretty_printer
*, tree
);
62 static void pp_c_relational_expression (c_pretty_printer
*, tree
);
63 static void pp_c_equality_expression (c_pretty_printer
*, tree
);
64 static void pp_c_and_expression (c_pretty_printer
*, tree
);
65 static void pp_c_exclusive_or_expression (c_pretty_printer
*, tree
);
66 static void pp_c_inclusive_or_expression (c_pretty_printer
*, tree
);
67 static void pp_c_logical_and_expression (c_pretty_printer
*, tree
);
68 static void pp_c_conditional_expression (c_pretty_printer
*, tree
);
69 static void pp_c_assignment_expression (c_pretty_printer
*, tree
);
74 /* Helper functions. */
77 pp_c_whitespace (c_pretty_printer
*pp
)
80 pp_base (pp
)->padding
= pp_none
;
84 pp_c_left_paren (c_pretty_printer
*pp
)
87 pp_base (pp
)->padding
= pp_none
;
91 pp_c_right_paren (c_pretty_printer
*pp
)
94 pp_base (pp
)->padding
= pp_none
;
98 pp_c_left_brace (c_pretty_printer
*pp
)
101 pp_base (pp
)->padding
= pp_none
;
105 pp_c_right_brace (c_pretty_printer
*pp
)
108 pp_base (pp
)->padding
= pp_none
;
112 pp_c_left_bracket (c_pretty_printer
*pp
)
114 pp_left_bracket (pp
);
115 pp_base (pp
)->padding
= pp_none
;
119 pp_c_right_bracket (c_pretty_printer
*pp
)
121 pp_right_bracket (pp
);
122 pp_base (pp
)->padding
= pp_none
;
126 pp_c_dot (c_pretty_printer
*pp
)
129 pp_base (pp
)->padding
= pp_none
;
133 pp_c_ampersand (c_pretty_printer
*pp
)
136 pp_base (pp
)->padding
= pp_none
;
140 pp_c_star (c_pretty_printer
*pp
)
143 pp_base (pp
)->padding
= pp_none
;
147 pp_c_arrow (c_pretty_printer
*pp
)
150 pp_base (pp
)->padding
= pp_none
;
154 pp_c_semicolon (c_pretty_printer
*pp
)
157 pp_base (pp
)->padding
= pp_none
;
161 pp_c_complement (c_pretty_printer
*pp
)
164 pp_base (pp
)->padding
= pp_none
;
168 pp_c_exclamation (c_pretty_printer
*pp
)
171 pp_base (pp
)->padding
= pp_none
;
174 /* Print out the external representation of CV-QUALIFIER. */
177 pp_c_cv_qualifier (c_pretty_printer
*pp
, const char *cv
)
179 const char *p
= pp_last_position_in_text (pp
);
180 /* The C programming language does not have references, but it is much
181 simpler to handle those here rather than going through the same
182 logic in the C++ pretty-printer. */
183 if (p
!= NULL
&& (*p
== '*' || *p
== '&'))
184 pp_c_whitespace (pp
);
185 pp_c_ws_string (pp
, cv
);
188 /* Pretty-print T using the type-cast notation '( type-name )'. */
191 pp_c_type_cast (c_pretty_printer
*pp
, tree t
)
193 pp_c_left_paren (pp
);
195 pp_c_right_paren (pp
);
198 /* We're about to pretty-print a pointer type as indicated by T.
199 Output a whitespace, if needed, preparing for subsequent output. */
202 pp_c_space_for_pointer_operator (c_pretty_printer
*pp
, tree t
)
204 if (POINTER_TYPE_P (t
))
206 tree pointee
= strip_pointer_operator (TREE_TYPE (t
));
207 if (TREE_CODE (pointee
) != ARRAY_TYPE
208 && TREE_CODE (pointee
) != FUNCTION_TYPE
)
209 pp_c_whitespace (pp
);
216 /* C++ cv-qualifiers are called type-qualifiers in C. Print out the
217 cv-qualifiers of T. If T is a declaration then it is the cv-qualifier
218 of its type. Take care of possible extensions.
222 type-qualifier-list type-qualifier
227 __restrict__ -- GNU C
228 address-space-qualifier -- GNU C
231 address-space-qualifier:
232 identifier -- GNU C */
235 pp_c_type_qualifier_list (c_pretty_printer
*pp
, tree t
)
239 if (!t
|| t
== error_mark_node
)
245 qualifiers
= TYPE_QUALS (t
);
246 if (qualifiers
& TYPE_QUAL_CONST
)
247 pp_c_cv_qualifier (pp
, "const");
248 if (qualifiers
& TYPE_QUAL_VOLATILE
)
249 pp_c_cv_qualifier (pp
, "volatile");
250 if (qualifiers
& TYPE_QUAL_RESTRICT
)
251 pp_c_cv_qualifier (pp
, flag_isoc99
? "restrict" : "__restrict__");
253 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (t
)))
255 const char *as
= c_addr_space_name (TYPE_ADDR_SPACE (t
));
256 pp_c_identifier (pp
, as
);
261 * type-qualifier-list(opt)
262 * type-qualifier-list(opt) pointer */
265 pp_c_pointer (c_pretty_printer
*pp
, tree t
)
267 if (!TYPE_P (t
) && TREE_CODE (t
) != TYPE_DECL
)
269 switch (TREE_CODE (t
))
272 /* It is easier to handle C++ reference types here. */
274 if (TREE_CODE (TREE_TYPE (t
)) == POINTER_TYPE
)
275 pp_c_pointer (pp
, TREE_TYPE (t
));
276 if (TREE_CODE (t
) == POINTER_TYPE
)
280 pp_c_type_qualifier_list (pp
, t
);
283 /* ??? This node is now in GENERIC and so shouldn't be here. But
284 we'll fix that later. */
286 pp_declaration (pp
, DECL_EXPR_DECL (t
));
287 pp_needs_newline (pp
) = true;
291 pp_unsupported_tree (pp
, t
);
308 struct-or-union-specifier
313 simple-type-specifier:
318 pp_c_type_specifier (c_pretty_printer
*pp
, tree t
)
320 const enum tree_code code
= TREE_CODE (t
);
324 pp_c_ws_string (pp
, M_("<type-error>"));
327 case IDENTIFIER_NODE
:
328 pp_c_tree_decl_identifier (pp
, t
);
335 case FIXED_POINT_TYPE
:
339 pp_c_type_specifier (pp
, t
);
343 int prec
= TYPE_PRECISION (t
);
344 if (ALL_FIXED_POINT_MODE_P (TYPE_MODE (t
)))
345 t
= c_common_type_for_mode (TYPE_MODE (t
), TYPE_SATURATING (t
));
347 t
= c_common_type_for_mode (TYPE_MODE (t
), TYPE_UNSIGNED (t
));
350 pp_c_type_specifier (pp
, t
);
351 if (TYPE_PRECISION (t
) != prec
)
354 pp_decimal_int (pp
, prec
);
362 pp_string (pp
, (TYPE_UNSIGNED (t
)
363 ? M_("<unnamed-unsigned:")
364 : M_("<unnamed-signed:")));
367 pp_string (pp
, M_("<unnamed-float:"));
369 case FIXED_POINT_TYPE
:
370 pp_string (pp
, M_("<unnamed-fixed:"));
375 pp_decimal_int (pp
, prec
);
383 pp_id_expression (pp
, t
);
385 pp_c_ws_string (pp
, M_("<typedef-error>"));
391 if (code
== UNION_TYPE
)
392 pp_c_ws_string (pp
, "union");
393 else if (code
== RECORD_TYPE
)
394 pp_c_ws_string (pp
, "struct");
395 else if (code
== ENUMERAL_TYPE
)
396 pp_c_ws_string (pp
, "enum");
398 pp_c_ws_string (pp
, M_("<tag-error>"));
401 pp_id_expression (pp
, TYPE_NAME (t
));
403 pp_c_ws_string (pp
, M_("<anonymous>"));
407 pp_unsupported_tree (pp
, t
);
412 /* specifier-qualifier-list:
413 type-specifier specifier-qualifier-list-opt
414 type-qualifier specifier-qualifier-list-opt
417 Implementation note: Because of the non-linearities in array or
418 function declarations, this routine prints not just the
419 specifier-qualifier-list of such entities or types of such entities,
420 but also the 'pointer' production part of their declarators. The
421 remaining part is done by pp_declarator or pp_c_abstract_declarator. */
424 pp_c_specifier_qualifier_list (c_pretty_printer
*pp
, tree t
)
426 const enum tree_code code
= TREE_CODE (t
);
428 if (TREE_CODE (t
) != POINTER_TYPE
)
429 pp_c_type_qualifier_list (pp
, t
);
435 /* Get the types-specifier of this type. */
436 tree pointee
= strip_pointer_operator (TREE_TYPE (t
));
437 pp_c_specifier_qualifier_list (pp
, pointee
);
438 if (TREE_CODE (pointee
) == ARRAY_TYPE
439 || TREE_CODE (pointee
) == FUNCTION_TYPE
)
441 pp_c_whitespace (pp
);
442 pp_c_left_paren (pp
);
444 else if (!c_dialect_cxx ())
445 pp_c_whitespace (pp
);
446 pp_ptr_operator (pp
, t
);
452 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
457 if (code
== COMPLEX_TYPE
)
458 pp_c_ws_string (pp
, flag_isoc99
? "_Complex" : "__complex__");
459 else if (code
== VECTOR_TYPE
)
461 pp_c_ws_string (pp
, "__vector");
462 pp_c_left_paren (pp
);
463 pp_wide_integer (pp
, TYPE_VECTOR_SUBPARTS (t
));
464 pp_c_right_paren (pp
);
465 pp_c_whitespace (pp
);
467 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
471 pp_simple_type_specifier (pp
, t
);
476 /* parameter-type-list:
481 parameter-declaration
482 parameter-list , parameter-declaration
484 parameter-declaration:
485 declaration-specifiers declarator
486 declaration-specifiers abstract-declarator(opt) */
489 pp_c_parameter_type_list (c_pretty_printer
*pp
, tree t
)
491 bool want_parm_decl
= DECL_P (t
) && !(pp
->flags
& pp_c_flag_abstract
);
492 tree parms
= want_parm_decl
? DECL_ARGUMENTS (t
) : TYPE_ARG_TYPES (t
);
493 pp_c_left_paren (pp
);
494 if (parms
== void_list_node
)
495 pp_c_ws_string (pp
, "void");
499 for ( ; parms
&& parms
!= void_list_node
; parms
= TREE_CHAIN (parms
))
502 pp_separate_with (pp
, ',');
504 pp_declaration_specifiers
505 (pp
, want_parm_decl
? parms
: TREE_VALUE (parms
));
507 pp_declarator (pp
, parms
);
509 pp_abstract_declarator (pp
, TREE_VALUE (parms
));
512 pp_c_right_paren (pp
);
515 /* abstract-declarator:
517 pointer(opt) direct-abstract-declarator */
520 pp_c_abstract_declarator (c_pretty_printer
*pp
, tree t
)
522 if (TREE_CODE (t
) == POINTER_TYPE
)
524 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
525 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
526 pp_c_right_paren (pp
);
530 pp_direct_abstract_declarator (pp
, t
);
533 /* direct-abstract-declarator:
534 ( abstract-declarator )
535 direct-abstract-declarator(opt) [ assignment-expression(opt) ]
536 direct-abstract-declarator(opt) [ * ]
537 direct-abstract-declarator(opt) ( parameter-type-list(opt) ) */
540 pp_c_direct_abstract_declarator (c_pretty_printer
*pp
, tree t
)
542 switch (TREE_CODE (t
))
545 pp_abstract_declarator (pp
, t
);
549 pp_c_parameter_type_list (pp
, t
);
550 pp_direct_abstract_declarator (pp
, TREE_TYPE (t
));
554 pp_c_left_bracket (pp
);
555 if (TYPE_DOMAIN (t
) && TYPE_MAX_VALUE (TYPE_DOMAIN (t
)))
557 tree maxval
= TYPE_MAX_VALUE (TYPE_DOMAIN (t
));
558 tree type
= TREE_TYPE (maxval
);
560 if (host_integerp (maxval
, 0))
561 pp_wide_integer (pp
, tree_low_cst (maxval
, 0) + 1);
563 pp_expression (pp
, fold_build2 (PLUS_EXPR
, type
, maxval
,
564 build_int_cst (type
, 1)));
566 pp_c_right_bracket (pp
);
567 pp_direct_abstract_declarator (pp
, TREE_TYPE (t
));
570 case IDENTIFIER_NODE
:
575 case FIXED_POINT_TYPE
:
585 pp_unsupported_tree (pp
, t
);
591 specifier-qualifier-list abstract-declarator(opt) */
594 pp_c_type_id (c_pretty_printer
*pp
, tree t
)
596 pp_c_specifier_qualifier_list (pp
, t
);
597 pp_abstract_declarator (pp
, t
);
600 /* storage-class-specifier:
608 pp_c_storage_class_specifier (c_pretty_printer
*pp
, tree t
)
610 if (TREE_CODE (t
) == TYPE_DECL
)
611 pp_c_ws_string (pp
, "typedef");
614 if (DECL_REGISTER (t
))
615 pp_c_ws_string (pp
, "register");
616 else if (TREE_STATIC (t
) && TREE_CODE (t
) == VAR_DECL
)
617 pp_c_ws_string (pp
, "static");
621 /* function-specifier:
625 pp_c_function_specifier (c_pretty_printer
*pp
, tree t
)
627 if (TREE_CODE (t
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (t
))
628 pp_c_ws_string (pp
, "inline");
631 /* declaration-specifiers:
632 storage-class-specifier declaration-specifiers(opt)
633 type-specifier declaration-specifiers(opt)
634 type-qualifier declaration-specifiers(opt)
635 function-specifier declaration-specifiers(opt) */
638 pp_c_declaration_specifiers (c_pretty_printer
*pp
, tree t
)
640 pp_storage_class_specifier (pp
, t
);
641 pp_function_specifier (pp
, t
);
642 pp_c_specifier_qualifier_list (pp
, DECL_P (t
) ? TREE_TYPE (t
) : t
);
648 direct-declarator [ type-qualifier-list(opt) assignment-expression(opt) ]
649 direct-declarator [ static type-qualifier-list(opt) assignment-expression(opt)]
650 direct-declarator [ type-qualifier-list static assignment-expression ]
651 direct-declarator [ type-qualifier-list * ]
652 direct-declarator ( parameter-type-list )
653 direct-declarator ( identifier-list(opt) ) */
656 pp_c_direct_declarator (c_pretty_printer
*pp
, tree t
)
658 switch (TREE_CODE (t
))
665 pp_c_space_for_pointer_operator (pp
, TREE_TYPE (t
));
666 pp_c_tree_decl_identifier (pp
, t
);
671 pp_abstract_declarator (pp
, TREE_TYPE (t
));
675 pp_parameter_list (pp
, t
);
676 pp_abstract_declarator (pp
, TREE_TYPE (t
));
680 pp_c_space_for_pointer_operator (pp
, TREE_TYPE (TREE_TYPE (t
)));
681 pp_c_tree_decl_identifier (pp
, t
);
682 if (pp_c_base (pp
)->flags
& pp_c_flag_abstract
)
683 pp_abstract_declarator (pp
, TREE_TYPE (t
));
686 pp_parameter_list (pp
, t
);
687 pp_abstract_declarator (pp
, TREE_TYPE (TREE_TYPE (t
)));
693 case FIXED_POINT_TYPE
:
700 pp_unsupported_tree (pp
, t
);
707 pointer(opt) direct-declarator */
710 pp_c_declarator (c_pretty_printer
*pp
, tree t
)
712 switch (TREE_CODE (t
))
716 case FIXED_POINT_TYPE
:
729 pp_direct_declarator (pp
, t
);
734 pp_unsupported_tree (pp
, t
);
740 declaration-specifiers init-declarator-list(opt) ; */
743 pp_c_declaration (c_pretty_printer
*pp
, tree t
)
745 pp_declaration_specifiers (pp
, t
);
746 pp_c_init_declarator (pp
, t
);
749 /* Pretty-print ATTRIBUTES using GNU C extension syntax. */
752 pp_c_attributes (c_pretty_printer
*pp
, tree attributes
)
754 if (attributes
== NULL_TREE
)
757 pp_c_ws_string (pp
, "__attribute__");
758 pp_c_left_paren (pp
);
759 pp_c_left_paren (pp
);
760 for (; attributes
!= NULL_TREE
; attributes
= TREE_CHAIN (attributes
))
762 pp_tree_identifier (pp
, TREE_PURPOSE (attributes
));
763 if (TREE_VALUE (attributes
))
764 pp_c_call_argument_list (pp
, TREE_VALUE (attributes
));
766 if (TREE_CHAIN (attributes
))
767 pp_separate_with (pp
, ',');
769 pp_c_right_paren (pp
);
770 pp_c_right_paren (pp
);
773 /* function-definition:
774 declaration-specifiers declarator compound-statement */
777 pp_c_function_definition (c_pretty_printer
*pp
, tree t
)
779 pp_declaration_specifiers (pp
, t
);
780 pp_declarator (pp
, t
);
781 pp_needs_newline (pp
) = true;
782 pp_statement (pp
, DECL_SAVED_TREE (t
));
790 /* Print out a c-char. This is called solely for characters which are
791 in the *target* execution character set. We ought to convert them
792 back to the *host* execution character set before printing, but we
793 have no way to do this at present. A decent compromise is to print
794 all characters as if they were in the host execution character set,
795 and not attempt to recover any named escape characters, but render
796 all unprintables as octal escapes. If the host and target character
797 sets are the same, this produces relatively readable output. If they
798 are not the same, strings may appear as gibberish, but that's okay
799 (in fact, it may well be what the reader wants, e.g. if they are looking
800 to see if conversion to the target character set happened correctly).
802 A special case: we need to prefix \, ", and ' with backslashes. It is
803 correct to do so for the *host*'s \, ", and ', because the rest of the
804 file appears in the host character set. */
807 pp_c_char (c_pretty_printer
*pp
, int c
)
813 case '\\': pp_string (pp
, "\\\\"); break;
814 case '\'': pp_string (pp
, "\\\'"); break;
815 case '\"': pp_string (pp
, "\\\""); break;
816 default: pp_character (pp
, c
);
820 pp_scalar (pp
, "\\%03o", (unsigned) c
);
823 /* Print out a STRING literal. */
826 pp_c_string_literal (c_pretty_printer
*pp
, tree s
)
828 const char *p
= TREE_STRING_POINTER (s
);
829 int n
= TREE_STRING_LENGTH (s
) - 1;
832 for (i
= 0; i
< n
; ++i
)
833 pp_c_char (pp
, p
[i
]);
837 /* Pretty-print an INTEGER literal. */
840 pp_c_integer_constant (c_pretty_printer
*pp
, tree i
)
842 tree type
= TREE_TYPE (i
);
844 if (TREE_INT_CST_HIGH (i
) == 0)
845 pp_wide_integer (pp
, TREE_INT_CST_LOW (i
));
848 unsigned HOST_WIDE_INT low
= TREE_INT_CST_LOW (i
);
849 HOST_WIDE_INT high
= TREE_INT_CST_HIGH (i
);
850 if (tree_int_cst_sgn (i
) < 0)
852 pp_character (pp
, '-');
856 sprintf (pp_buffer (pp
)->digit_buffer
, HOST_WIDE_INT_PRINT_DOUBLE_HEX
,
857 (unsigned HOST_WIDE_INT
) high
, (unsigned HOST_WIDE_INT
) low
);
858 pp_string (pp
, pp_buffer (pp
)->digit_buffer
);
860 if (TYPE_UNSIGNED (type
))
861 pp_character (pp
, 'u');
862 if (type
== long_integer_type_node
|| type
== long_unsigned_type_node
)
863 pp_character (pp
, 'l');
864 else if (type
== long_long_integer_type_node
865 || type
== long_long_unsigned_type_node
)
866 pp_string (pp
, "ll");
869 /* Print out a CHARACTER literal. */
872 pp_c_character_constant (c_pretty_printer
*pp
, tree c
)
874 tree type
= TREE_TYPE (c
);
875 if (type
== wchar_type_node
)
876 pp_character (pp
, 'L');
878 if (host_integerp (c
, TYPE_UNSIGNED (type
)))
879 pp_c_char (pp
, tree_low_cst (c
, TYPE_UNSIGNED (type
)));
881 pp_scalar (pp
, "\\x%x", (unsigned) TREE_INT_CST_LOW (c
));
885 /* Print out a BOOLEAN literal. */
888 pp_c_bool_constant (c_pretty_printer
*pp
, tree b
)
890 if (b
== boolean_false_node
)
892 if (c_dialect_cxx ())
893 pp_c_ws_string (pp
, "false");
894 else if (flag_isoc99
)
895 pp_c_ws_string (pp
, "_False");
897 pp_unsupported_tree (pp
, b
);
899 else if (b
== boolean_true_node
)
901 if (c_dialect_cxx ())
902 pp_c_ws_string (pp
, "true");
903 else if (flag_isoc99
)
904 pp_c_ws_string (pp
, "_True");
906 pp_unsupported_tree (pp
, b
);
908 else if (TREE_CODE (b
) == INTEGER_CST
)
909 pp_c_integer_constant (pp
, b
);
911 pp_unsupported_tree (pp
, b
);
914 /* Attempt to print out an ENUMERATOR. Return true on success. Else return
915 false; that means the value was obtained by a cast, in which case
916 print out the type-id part of the cast-expression -- the casted value
917 is then printed by pp_c_integer_literal. */
920 pp_c_enumeration_constant (c_pretty_printer
*pp
, tree e
)
922 bool value_is_named
= true;
923 tree type
= TREE_TYPE (e
);
926 /* Find the name of this constant. */
927 for (value
= TYPE_VALUES (type
);
928 value
!= NULL_TREE
&& !tree_int_cst_equal (TREE_VALUE (value
), e
);
929 value
= TREE_CHAIN (value
))
932 if (value
!= NULL_TREE
)
933 pp_id_expression (pp
, TREE_PURPOSE (value
));
936 /* Value must have been cast. */
937 pp_c_type_cast (pp
, type
);
938 value_is_named
= false;
941 return value_is_named
;
944 /* Print out a REAL value as a decimal-floating-constant. */
947 pp_c_floating_constant (c_pretty_printer
*pp
, tree r
)
949 real_to_decimal (pp_buffer (pp
)->digit_buffer
, &TREE_REAL_CST (r
),
950 sizeof (pp_buffer (pp
)->digit_buffer
), 0, 1);
951 pp_string (pp
, pp_buffer(pp
)->digit_buffer
);
952 if (TREE_TYPE (r
) == float_type_node
)
953 pp_character (pp
, 'f');
954 else if (TREE_TYPE (r
) == long_double_type_node
)
955 pp_character (pp
, 'l');
956 else if (TREE_TYPE (r
) == dfloat128_type_node
)
957 pp_string (pp
, "dl");
958 else if (TREE_TYPE (r
) == dfloat64_type_node
)
959 pp_string (pp
, "dd");
960 else if (TREE_TYPE (r
) == dfloat32_type_node
)
961 pp_string (pp
, "df");
964 /* Print out a FIXED value as a decimal-floating-constant. */
967 pp_c_fixed_constant (c_pretty_printer
*pp
, tree r
)
969 fixed_to_decimal (pp_buffer (pp
)->digit_buffer
, &TREE_FIXED_CST (r
),
970 sizeof (pp_buffer (pp
)->digit_buffer
));
971 pp_string (pp
, pp_buffer(pp
)->digit_buffer
);
974 /* Pretty-print a compound literal expression. GNU extensions include
978 pp_c_compound_literal (c_pretty_printer
*pp
, tree e
)
980 tree type
= TREE_TYPE (e
);
981 pp_c_type_cast (pp
, type
);
983 switch (TREE_CODE (type
))
990 pp_c_brace_enclosed_initializer_list (pp
, e
);
994 pp_unsupported_tree (pp
, e
);
999 /* Pretty-print a COMPLEX_EXPR expression. */
1002 pp_c_complex_expr (c_pretty_printer
*pp
, tree e
)
1004 /* Handle a few common special cases, otherwise fallback
1005 to printing it as compound literal. */
1006 tree type
= TREE_TYPE (e
);
1007 tree realexpr
= TREE_OPERAND (e
, 0);
1008 tree imagexpr
= TREE_OPERAND (e
, 1);
1010 /* Cast of an COMPLEX_TYPE expression to a different COMPLEX_TYPE. */
1011 if (TREE_CODE (realexpr
) == NOP_EXPR
1012 && TREE_CODE (imagexpr
) == NOP_EXPR
1013 && TREE_TYPE (realexpr
) == TREE_TYPE (type
)
1014 && TREE_TYPE (imagexpr
) == TREE_TYPE (type
)
1015 && TREE_CODE (TREE_OPERAND (realexpr
, 0)) == REALPART_EXPR
1016 && TREE_CODE (TREE_OPERAND (imagexpr
, 0)) == IMAGPART_EXPR
1017 && TREE_OPERAND (TREE_OPERAND (realexpr
, 0), 0)
1018 == TREE_OPERAND (TREE_OPERAND (imagexpr
, 0), 0))
1020 pp_c_type_cast (pp
, type
);
1021 pp_expression (pp
, TREE_OPERAND (TREE_OPERAND (realexpr
, 0), 0));
1025 /* Cast of an scalar expression to COMPLEX_TYPE. */
1026 if ((integer_zerop (imagexpr
) || real_zerop (imagexpr
))
1027 && TREE_TYPE (realexpr
) == TREE_TYPE (type
))
1029 pp_c_type_cast (pp
, type
);
1030 if (TREE_CODE (realexpr
) == NOP_EXPR
)
1031 realexpr
= TREE_OPERAND (realexpr
, 0);
1032 pp_expression (pp
, realexpr
);
1036 pp_c_compound_literal (pp
, e
);
1042 fixed-point-constant
1043 enumeration-constant
1044 character-constant */
1047 pp_c_constant (c_pretty_printer
*pp
, tree e
)
1049 const enum tree_code code
= TREE_CODE (e
);
1055 tree type
= TREE_TYPE (e
);
1056 if (type
== boolean_type_node
)
1057 pp_c_bool_constant (pp
, e
);
1058 else if (type
== char_type_node
)
1059 pp_c_character_constant (pp
, e
);
1060 else if (TREE_CODE (type
) == ENUMERAL_TYPE
1061 && pp_c_enumeration_constant (pp
, e
))
1064 pp_c_integer_constant (pp
, e
);
1069 pp_c_floating_constant (pp
, e
);
1073 pp_c_fixed_constant (pp
, e
);
1077 pp_c_string_literal (pp
, e
);
1081 /* Sometimes, we are confused and we think a complex literal
1082 is a constant. Such thing is a compound literal which
1083 grammatically belongs to postfix-expr production. */
1084 pp_c_compound_literal (pp
, e
);
1088 pp_unsupported_tree (pp
, e
);
1093 /* Pretty-print a string such as an identifier, without changing its
1094 encoding, preceded by whitespace is necessary. */
1097 pp_c_ws_string (c_pretty_printer
*pp
, const char *str
)
1099 pp_c_maybe_whitespace (pp
);
1100 pp_string (pp
, str
);
1101 pp_base (pp
)->padding
= pp_before
;
1104 /* Pretty-print an IDENTIFIER_NODE, which may contain UTF-8 sequences
1105 that need converting to the locale encoding, preceded by whitespace
1109 pp_c_identifier (c_pretty_printer
*pp
, const char *id
)
1111 pp_c_maybe_whitespace (pp
);
1112 pp_identifier (pp
, id
);
1113 pp_base (pp
)->padding
= pp_before
;
1116 /* Pretty-print a C primary-expression.
1124 pp_c_primary_expression (c_pretty_printer
*pp
, tree e
)
1126 switch (TREE_CODE (e
))
1134 pp_c_tree_decl_identifier (pp
, e
);
1137 case IDENTIFIER_NODE
:
1138 pp_c_tree_identifier (pp
, e
);
1142 pp_c_ws_string (pp
, M_("<erroneous-expression>"));
1146 pp_c_ws_string (pp
, M_("<return-value>"));
1153 pp_c_constant (pp
, e
);
1157 pp_c_ws_string (pp
, "__builtin_memcpy");
1158 pp_c_left_paren (pp
);
1160 pp_primary_expression (pp
, TREE_OPERAND (e
, 0));
1161 pp_separate_with (pp
, ',');
1163 pp_initializer (pp
, TREE_OPERAND (e
, 1));
1164 if (TREE_OPERAND (e
, 2))
1166 pp_separate_with (pp
, ',');
1167 pp_c_expression (pp
, TREE_OPERAND (e
, 2));
1169 pp_c_right_paren (pp
);
1173 /* FIXME: Make sure we won't get into an infinite loop. */
1174 pp_c_left_paren (pp
);
1175 pp_expression (pp
, e
);
1176 pp_c_right_paren (pp
);
1181 /* Print out a C initializer -- also support C compound-literals.
1183 assignment-expression:
1184 { initializer-list }
1185 { initializer-list , } */
1188 pp_c_initializer (c_pretty_printer
*pp
, tree e
)
1190 if (TREE_CODE (e
) == CONSTRUCTOR
)
1191 pp_c_brace_enclosed_initializer_list (pp
, e
);
1193 pp_expression (pp
, e
);
1198 declarator = initializer */
1201 pp_c_init_declarator (c_pretty_printer
*pp
, tree t
)
1203 pp_declarator (pp
, t
);
1204 /* We don't want to output function definitions here. There are handled
1205 elsewhere (and the syntactic form is bogus anyway). */
1206 if (TREE_CODE (t
) != FUNCTION_DECL
&& DECL_INITIAL (t
))
1208 tree init
= DECL_INITIAL (t
);
1209 /* This C++ bit is handled here because it is easier to do so.
1210 In templates, the C++ parser builds a TREE_LIST for a
1211 direct-initialization; the TREE_PURPOSE is the variable to
1212 initialize and the TREE_VALUE is the initializer. */
1213 if (TREE_CODE (init
) == TREE_LIST
)
1215 pp_c_left_paren (pp
);
1216 pp_expression (pp
, TREE_VALUE (init
));
1217 pp_right_paren (pp
);
1224 pp_c_initializer (pp
, init
);
1229 /* initializer-list:
1230 designation(opt) initializer
1231 initializer-list , designation(opt) initializer
1238 designator-list designator
1241 [ constant-expression ]
1245 pp_c_initializer_list (c_pretty_printer
*pp
, tree e
)
1247 tree type
= TREE_TYPE (e
);
1248 const enum tree_code code
= TREE_CODE (type
);
1250 if (TREE_CODE (e
) == CONSTRUCTOR
)
1252 pp_c_constructor_elts (pp
, CONSTRUCTOR_ELTS (e
));
1262 tree init
= TREE_OPERAND (e
, 0);
1263 for (; init
!= NULL_TREE
; init
= TREE_CHAIN (init
))
1265 if (code
== RECORD_TYPE
|| code
== UNION_TYPE
)
1268 pp_c_primary_expression (pp
, TREE_PURPOSE (init
));
1272 pp_c_left_bracket (pp
);
1273 if (TREE_PURPOSE (init
))
1274 pp_c_constant (pp
, TREE_PURPOSE (init
));
1275 pp_c_right_bracket (pp
);
1277 pp_c_whitespace (pp
);
1279 pp_c_whitespace (pp
);
1280 pp_initializer (pp
, TREE_VALUE (init
));
1281 if (TREE_CHAIN (init
))
1282 pp_separate_with (pp
, ',');
1288 if (TREE_CODE (e
) == VECTOR_CST
)
1289 pp_c_expression_list (pp
, TREE_VECTOR_CST_ELTS (e
));
1295 if (TREE_CODE (e
) == COMPLEX_CST
|| TREE_CODE (e
) == COMPLEX_EXPR
)
1297 const bool cst
= TREE_CODE (e
) == COMPLEX_CST
;
1298 pp_expression (pp
, cst
? TREE_REALPART (e
) : TREE_OPERAND (e
, 0));
1299 pp_separate_with (pp
, ',');
1300 pp_expression (pp
, cst
? TREE_IMAGPART (e
) : TREE_OPERAND (e
, 1));
1310 pp_unsupported_tree (pp
, type
);
1313 /* Pretty-print a brace-enclosed initializer-list. */
1316 pp_c_brace_enclosed_initializer_list (c_pretty_printer
*pp
, tree l
)
1318 pp_c_left_brace (pp
);
1319 pp_c_initializer_list (pp
, l
);
1320 pp_c_right_brace (pp
);
1324 /* This is a convenient function, used to bridge gap between C and C++
1331 pp_c_id_expression (c_pretty_printer
*pp
, tree t
)
1333 switch (TREE_CODE (t
))
1342 pp_c_tree_decl_identifier (pp
, t
);
1345 case IDENTIFIER_NODE
:
1346 pp_c_tree_identifier (pp
, t
);
1350 pp_unsupported_tree (pp
, t
);
1355 /* postfix-expression:
1357 postfix-expression [ expression ]
1358 postfix-expression ( argument-expression-list(opt) )
1359 postfix-expression . identifier
1360 postfix-expression -> identifier
1361 postfix-expression ++
1362 postfix-expression --
1363 ( type-name ) { initializer-list }
1364 ( type-name ) { initializer-list , } */
1367 pp_c_postfix_expression (c_pretty_printer
*pp
, tree e
)
1369 enum tree_code code
= TREE_CODE (e
);
1372 case POSTINCREMENT_EXPR
:
1373 case POSTDECREMENT_EXPR
:
1374 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1375 pp_string (pp
, code
== POSTINCREMENT_EXPR
? "++" : "--");
1379 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1380 pp_c_left_bracket (pp
);
1381 pp_expression (pp
, TREE_OPERAND (e
, 1));
1382 pp_c_right_bracket (pp
);
1387 call_expr_arg_iterator iter
;
1389 pp_postfix_expression (pp
, CALL_EXPR_FN (e
));
1390 pp_c_left_paren (pp
);
1391 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, e
)
1393 pp_expression (pp
, arg
);
1394 if (more_call_expr_args_p (&iter
))
1395 pp_separate_with (pp
, ',');
1397 pp_c_right_paren (pp
);
1401 case UNORDERED_EXPR
:
1402 pp_c_ws_string (pp
, flag_isoc99
1404 : "__builtin_isunordered");
1408 pp_c_ws_string (pp
, flag_isoc99
1410 : "!__builtin_isunordered");
1414 pp_c_ws_string (pp
, flag_isoc99
1416 : "!__builtin_isgreaterequal");
1420 pp_c_ws_string (pp
, flag_isoc99
1422 : "!__builtin_isgreater");
1426 pp_c_ws_string (pp
, flag_isoc99
1428 : "!__builtin_islessequal");
1432 pp_c_ws_string (pp
, flag_isoc99
1434 : "!__builtin_isless");
1438 pp_c_ws_string (pp
, flag_isoc99
1440 : "!__builtin_islessgreater");
1444 pp_c_ws_string (pp
, flag_isoc99
1446 : "__builtin_islessgreater");
1450 pp_c_left_paren (pp
);
1451 pp_expression (pp
, TREE_OPERAND (e
, 0));
1452 pp_separate_with (pp
, ',');
1453 pp_expression (pp
, TREE_OPERAND (e
, 1));
1454 pp_c_right_paren (pp
);
1458 pp_c_ws_string (pp
, "__builtin_abs");
1459 pp_c_left_paren (pp
);
1460 pp_expression (pp
, TREE_OPERAND (e
, 0));
1461 pp_c_right_paren (pp
);
1466 tree object
= TREE_OPERAND (e
, 0);
1467 if (TREE_CODE (object
) == INDIRECT_REF
)
1469 pp_postfix_expression (pp
, TREE_OPERAND (object
, 0));
1474 pp_postfix_expression (pp
, object
);
1477 pp_expression (pp
, TREE_OPERAND (e
, 1));
1483 tree type
= TREE_TYPE (e
);
1485 type
= signed_or_unsigned_type_for (TYPE_UNSIGNED (type
), type
);
1487 && tree_int_cst_equal (TYPE_SIZE (type
), TREE_OPERAND (e
, 1)))
1489 HOST_WIDE_INT bitpos
= tree_low_cst (TREE_OPERAND (e
, 2), 0);
1490 HOST_WIDE_INT size
= tree_low_cst (TYPE_SIZE (type
), 0);
1491 if ((bitpos
% size
) == 0)
1493 pp_c_left_paren (pp
);
1494 pp_c_left_paren (pp
);
1495 pp_type_id (pp
, type
);
1497 pp_c_right_paren (pp
);
1498 pp_c_ampersand (pp
);
1499 pp_expression (pp
, TREE_OPERAND (e
, 0));
1500 pp_c_right_paren (pp
);
1501 pp_c_left_bracket (pp
);
1502 pp_wide_integer (pp
, bitpos
/ size
);
1503 pp_c_right_bracket (pp
);
1507 pp_unsupported_tree (pp
, e
);
1513 pp_c_compound_literal (pp
, e
);
1517 pp_c_complex_expr (pp
, e
);
1520 case COMPOUND_LITERAL_EXPR
:
1521 e
= DECL_INITIAL (COMPOUND_LITERAL_EXPR_DECL (e
));
1524 pp_initializer (pp
, e
);
1528 pp_c_ws_string (pp
, "__builtin_va_arg");
1529 pp_c_left_paren (pp
);
1530 pp_assignment_expression (pp
, TREE_OPERAND (e
, 0));
1531 pp_separate_with (pp
, ',');
1532 pp_type_id (pp
, TREE_TYPE (e
));
1533 pp_c_right_paren (pp
);
1537 if (TREE_CODE (TREE_OPERAND (e
, 0)) == FUNCTION_DECL
)
1539 pp_c_id_expression (pp
, TREE_OPERAND (e
, 0));
1542 /* else fall through. */
1545 pp_primary_expression (pp
, e
);
1550 /* Print out an expression-list; E is expected to be a TREE_LIST. */
1553 pp_c_expression_list (c_pretty_printer
*pp
, tree e
)
1555 for (; e
!= NULL_TREE
; e
= TREE_CHAIN (e
))
1557 pp_expression (pp
, TREE_VALUE (e
));
1559 pp_separate_with (pp
, ',');
1563 /* Print out V, which contains the elements of a constructor. */
1566 pp_c_constructor_elts (c_pretty_printer
*pp
, VEC(constructor_elt
,gc
) *v
)
1568 unsigned HOST_WIDE_INT ix
;
1571 FOR_EACH_CONSTRUCTOR_VALUE (v
, ix
, value
)
1573 pp_expression (pp
, value
);
1574 if (ix
!= VEC_length (constructor_elt
, v
) - 1)
1575 pp_separate_with (pp
, ',');
1579 /* Print out an expression-list in parens, as if it were the argument
1580 list to a function. */
1583 pp_c_call_argument_list (c_pretty_printer
*pp
, tree t
)
1585 pp_c_left_paren (pp
);
1586 if (t
&& TREE_CODE (t
) == TREE_LIST
)
1587 pp_c_expression_list (pp
, t
);
1588 pp_c_right_paren (pp
);
1591 /* unary-expression:
1595 unary-operator cast-expression
1596 sizeof unary-expression
1599 unary-operator: one of
1604 __alignof__ unary-expression
1605 __alignof__ ( type-id )
1606 __real__ unary-expression
1607 __imag__ unary-expression */
1610 pp_c_unary_expression (c_pretty_printer
*pp
, tree e
)
1612 enum tree_code code
= TREE_CODE (e
);
1615 case PREINCREMENT_EXPR
:
1616 case PREDECREMENT_EXPR
:
1617 pp_string (pp
, code
== PREINCREMENT_EXPR
? "++" : "--");
1618 pp_c_unary_expression (pp
, TREE_OPERAND (e
, 0));
1625 case TRUTH_NOT_EXPR
:
1627 /* String literal are used by address. */
1628 if (code
== ADDR_EXPR
&& TREE_CODE (TREE_OPERAND (e
, 0)) != STRING_CST
)
1630 else if (code
== INDIRECT_REF
)
1632 else if (code
== NEGATE_EXPR
)
1634 else if (code
== BIT_NOT_EXPR
|| code
== CONJ_EXPR
)
1636 else if (code
== TRUTH_NOT_EXPR
)
1637 pp_exclamation (pp
);
1638 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 0));
1643 pp_c_ws_string (pp
, code
== REALPART_EXPR
? "__real__" : "__imag__");
1644 pp_c_whitespace (pp
);
1645 pp_unary_expression (pp
, TREE_OPERAND (e
, 0));
1649 pp_postfix_expression (pp
, e
);
1656 ( type-name ) cast-expression */
1659 pp_c_cast_expression (c_pretty_printer
*pp
, tree e
)
1661 switch (TREE_CODE (e
))
1664 case FIX_TRUNC_EXPR
:
1666 case VIEW_CONVERT_EXPR
:
1667 pp_c_type_cast (pp
, TREE_TYPE (e
));
1668 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 0));
1672 pp_unary_expression (pp
, e
);
1676 /* multiplicative-expression:
1678 multiplicative-expression * cast-expression
1679 multiplicative-expression / cast-expression
1680 multiplicative-expression % cast-expression */
1683 pp_c_multiplicative_expression (c_pretty_printer
*pp
, tree e
)
1685 enum tree_code code
= TREE_CODE (e
);
1689 case TRUNC_DIV_EXPR
:
1690 case TRUNC_MOD_EXPR
:
1691 pp_multiplicative_expression (pp
, TREE_OPERAND (e
, 0));
1692 pp_c_whitespace (pp
);
1693 if (code
== MULT_EXPR
)
1695 else if (code
== TRUNC_DIV_EXPR
)
1699 pp_c_whitespace (pp
);
1700 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 1));
1704 pp_c_cast_expression (pp
, e
);
1709 /* additive-expression:
1710 multiplicative-expression
1711 additive-expression + multiplicative-expression
1712 additive-expression - multiplicative-expression */
1715 pp_c_additive_expression (c_pretty_printer
*pp
, tree e
)
1717 enum tree_code code
= TREE_CODE (e
);
1720 case POINTER_PLUS_EXPR
:
1723 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 0));
1724 pp_c_whitespace (pp
);
1725 if (code
== PLUS_EXPR
|| code
== POINTER_PLUS_EXPR
)
1729 pp_c_whitespace (pp
);
1730 pp_multiplicative_expression (pp
, TREE_OPERAND (e
, 1));
1734 pp_multiplicative_expression (pp
, e
);
1739 /* additive-expression:
1741 shift-expression << additive-expression
1742 shift-expression >> additive-expression */
1745 pp_c_shift_expression (c_pretty_printer
*pp
, tree e
)
1747 enum tree_code code
= TREE_CODE (e
);
1752 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 0));
1753 pp_c_whitespace (pp
);
1754 pp_string (pp
, code
== LSHIFT_EXPR
? "<<" : ">>");
1755 pp_c_whitespace (pp
);
1756 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 1));
1760 pp_c_additive_expression (pp
, e
);
1764 /* relational-expression:
1766 relational-expression < shift-expression
1767 relational-expression > shift-expression
1768 relational-expression <= shift-expression
1769 relational-expression >= shift-expression */
1772 pp_c_relational_expression (c_pretty_printer
*pp
, tree e
)
1774 enum tree_code code
= TREE_CODE (e
);
1781 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 0));
1782 pp_c_whitespace (pp
);
1783 if (code
== LT_EXPR
)
1785 else if (code
== GT_EXPR
)
1787 else if (code
== LE_EXPR
)
1788 pp_string (pp
, "<=");
1789 else if (code
== GE_EXPR
)
1790 pp_string (pp
, ">=");
1791 pp_c_whitespace (pp
);
1792 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 1));
1796 pp_c_shift_expression (pp
, e
);
1801 /* equality-expression:
1802 relational-expression
1803 equality-expression == relational-expression
1804 equality-equality != relational-expression */
1807 pp_c_equality_expression (c_pretty_printer
*pp
, tree e
)
1809 enum tree_code code
= TREE_CODE (e
);
1814 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 0));
1815 pp_c_whitespace (pp
);
1816 pp_string (pp
, code
== EQ_EXPR
? "==" : "!=");
1817 pp_c_whitespace (pp
);
1818 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 1));
1822 pp_c_relational_expression (pp
, e
);
1829 AND-expression & equality-equality */
1832 pp_c_and_expression (c_pretty_printer
*pp
, tree e
)
1834 if (TREE_CODE (e
) == BIT_AND_EXPR
)
1836 pp_c_and_expression (pp
, TREE_OPERAND (e
, 0));
1837 pp_c_whitespace (pp
);
1839 pp_c_whitespace (pp
);
1840 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 1));
1843 pp_c_equality_expression (pp
, e
);
1846 /* exclusive-OR-expression:
1848 exclusive-OR-expression ^ AND-expression */
1851 pp_c_exclusive_or_expression (c_pretty_printer
*pp
, tree e
)
1853 if (TREE_CODE (e
) == BIT_XOR_EXPR
1854 || TREE_CODE (e
) == TRUTH_XOR_EXPR
)
1856 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
1857 if (TREE_CODE (e
) == BIT_XOR_EXPR
)
1858 pp_c_maybe_whitespace (pp
);
1860 pp_c_whitespace (pp
);
1862 pp_c_whitespace (pp
);
1863 pp_c_and_expression (pp
, TREE_OPERAND (e
, 1));
1866 pp_c_and_expression (pp
, e
);
1869 /* inclusive-OR-expression:
1870 exclusive-OR-expression
1871 inclusive-OR-expression | exclusive-OR-expression */
1874 pp_c_inclusive_or_expression (c_pretty_printer
*pp
, tree e
)
1876 if (TREE_CODE (e
) == BIT_IOR_EXPR
)
1878 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
1879 pp_c_whitespace (pp
);
1881 pp_c_whitespace (pp
);
1882 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
1885 pp_c_exclusive_or_expression (pp
, e
);
1888 /* logical-AND-expression:
1889 inclusive-OR-expression
1890 logical-AND-expression && inclusive-OR-expression */
1893 pp_c_logical_and_expression (c_pretty_printer
*pp
, tree e
)
1895 if (TREE_CODE (e
) == TRUTH_ANDIF_EXPR
1896 || TREE_CODE (e
) == TRUTH_AND_EXPR
)
1898 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 0));
1899 pp_c_whitespace (pp
);
1900 pp_string (pp
, "&&");
1901 pp_c_whitespace (pp
);
1902 pp_c_inclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
1905 pp_c_inclusive_or_expression (pp
, e
);
1908 /* logical-OR-expression:
1909 logical-AND-expression
1910 logical-OR-expression || logical-AND-expression */
1913 pp_c_logical_or_expression (c_pretty_printer
*pp
, tree e
)
1915 if (TREE_CODE (e
) == TRUTH_ORIF_EXPR
1916 || TREE_CODE (e
) == TRUTH_OR_EXPR
)
1918 pp_c_logical_or_expression (pp
, TREE_OPERAND (e
, 0));
1919 pp_c_whitespace (pp
);
1920 pp_string (pp
, "||");
1921 pp_c_whitespace (pp
);
1922 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 1));
1925 pp_c_logical_and_expression (pp
, e
);
1928 /* conditional-expression:
1929 logical-OR-expression
1930 logical-OR-expression ? expression : conditional-expression */
1933 pp_c_conditional_expression (c_pretty_printer
*pp
, tree e
)
1935 if (TREE_CODE (e
) == COND_EXPR
)
1937 pp_c_logical_or_expression (pp
, TREE_OPERAND (e
, 0));
1938 pp_c_whitespace (pp
);
1940 pp_c_whitespace (pp
);
1941 pp_expression (pp
, TREE_OPERAND (e
, 1));
1942 pp_c_whitespace (pp
);
1944 pp_c_whitespace (pp
);
1945 pp_c_conditional_expression (pp
, TREE_OPERAND (e
, 2));
1948 pp_c_logical_or_expression (pp
, e
);
1952 /* assignment-expression:
1953 conditional-expression
1954 unary-expression assignment-operator assignment-expression
1956 assignment-expression: one of
1957 = *= /= %= += -= >>= <<= &= ^= |= */
1960 pp_c_assignment_expression (c_pretty_printer
*pp
, tree e
)
1962 if (TREE_CODE (e
) == MODIFY_EXPR
1963 || TREE_CODE (e
) == INIT_EXPR
)
1965 pp_c_unary_expression (pp
, TREE_OPERAND (e
, 0));
1966 pp_c_whitespace (pp
);
1969 pp_c_expression (pp
, TREE_OPERAND (e
, 1));
1972 pp_c_conditional_expression (pp
, e
);
1976 assignment-expression
1977 expression , assignment-expression
1979 Implementation note: instead of going through the usual recursion
1980 chain, I take the liberty of dispatching nodes to the appropriate
1981 functions. This makes some redundancy, but it worths it. That also
1982 prevents a possible infinite recursion between pp_c_primary_expression ()
1983 and pp_c_expression (). */
1986 pp_c_expression (c_pretty_printer
*pp
, tree e
)
1988 switch (TREE_CODE (e
))
1991 pp_c_integer_constant (pp
, e
);
1995 pp_c_floating_constant (pp
, e
);
1999 pp_c_fixed_constant (pp
, e
);
2003 pp_c_string_literal (pp
, e
);
2006 case IDENTIFIER_NODE
:
2015 pp_primary_expression (pp
, e
);
2018 case POSTINCREMENT_EXPR
:
2019 case POSTDECREMENT_EXPR
:
2028 case UNORDERED_EXPR
:
2037 case COMPOUND_LITERAL_EXPR
:
2039 pp_postfix_expression (pp
, e
);
2047 case TRUTH_NOT_EXPR
:
2048 case PREINCREMENT_EXPR
:
2049 case PREDECREMENT_EXPR
:
2052 pp_c_unary_expression (pp
, e
);
2056 case FIX_TRUNC_EXPR
:
2058 case VIEW_CONVERT_EXPR
:
2059 pp_c_cast_expression (pp
, e
);
2063 case TRUNC_MOD_EXPR
:
2064 case TRUNC_DIV_EXPR
:
2065 pp_multiplicative_expression (pp
, e
);
2070 pp_c_shift_expression (pp
, e
);
2077 pp_c_relational_expression (pp
, e
);
2081 pp_c_and_expression (pp
, e
);
2085 case TRUTH_XOR_EXPR
:
2086 pp_c_exclusive_or_expression (pp
, e
);
2090 pp_c_inclusive_or_expression (pp
, e
);
2093 case TRUTH_ANDIF_EXPR
:
2094 case TRUTH_AND_EXPR
:
2095 pp_c_logical_and_expression (pp
, e
);
2098 case TRUTH_ORIF_EXPR
:
2100 pp_c_logical_or_expression (pp
, e
);
2105 pp_c_equality_expression (pp
, e
);
2109 pp_conditional_expression (pp
, e
);
2112 case POINTER_PLUS_EXPR
:
2115 pp_c_additive_expression (pp
, e
);
2120 pp_assignment_expression (pp
, e
);
2124 pp_c_left_paren (pp
);
2125 pp_expression (pp
, TREE_OPERAND (e
, 0));
2126 pp_separate_with (pp
, ',');
2127 pp_assignment_expression (pp
, TREE_OPERAND (e
, 1));
2128 pp_c_right_paren (pp
);
2131 case NON_LVALUE_EXPR
:
2133 pp_expression (pp
, TREE_OPERAND (e
, 0));
2137 pp_postfix_expression (pp
, TREE_OPERAND (e
, 1));
2142 /* We don't yet have a way of dumping statements in a
2143 human-readable format. */
2144 pp_string (pp
, "({...})");
2148 pp_unsupported_tree (pp
, e
);
2158 pp_c_statement (c_pretty_printer
*pp
, tree stmt
)
2163 if (pp_needs_newline (pp
))
2164 pp_newline_and_indent (pp
, 0);
2166 dump_generic_node (pp_base (pp
), stmt
, pp_indentation (pp
), 0, true);
2170 /* Initialize the PRETTY-PRINTER for handling C codes. */
2173 pp_c_pretty_printer_init (c_pretty_printer
*pp
)
2175 pp
->offset_list
= 0;
2177 pp
->declaration
= pp_c_declaration
;
2178 pp
->declaration_specifiers
= pp_c_declaration_specifiers
;
2179 pp
->declarator
= pp_c_declarator
;
2180 pp
->direct_declarator
= pp_c_direct_declarator
;
2181 pp
->type_specifier_seq
= pp_c_specifier_qualifier_list
;
2182 pp
->abstract_declarator
= pp_c_abstract_declarator
;
2183 pp
->direct_abstract_declarator
= pp_c_direct_abstract_declarator
;
2184 pp
->ptr_operator
= pp_c_pointer
;
2185 pp
->parameter_list
= pp_c_parameter_type_list
;
2186 pp
->type_id
= pp_c_type_id
;
2187 pp
->simple_type_specifier
= pp_c_type_specifier
;
2188 pp
->function_specifier
= pp_c_function_specifier
;
2189 pp
->storage_class_specifier
= pp_c_storage_class_specifier
;
2191 pp
->statement
= pp_c_statement
;
2193 pp
->constant
= pp_c_constant
;
2194 pp
->id_expression
= pp_c_id_expression
;
2195 pp
->primary_expression
= pp_c_primary_expression
;
2196 pp
->postfix_expression
= pp_c_postfix_expression
;
2197 pp
->unary_expression
= pp_c_unary_expression
;
2198 pp
->initializer
= pp_c_initializer
;
2199 pp
->multiplicative_expression
= pp_c_multiplicative_expression
;
2200 pp
->conditional_expression
= pp_c_conditional_expression
;
2201 pp
->assignment_expression
= pp_c_assignment_expression
;
2202 pp
->expression
= pp_c_expression
;
2206 /* Print the tree T in full, on file FILE. */
2209 print_c_tree (FILE *file
, tree t
)
2211 static c_pretty_printer pp_rec
;
2212 static bool initialized
= 0;
2213 c_pretty_printer
*pp
= &pp_rec
;
2218 pp_construct (pp_base (pp
), NULL
, 0);
2219 pp_c_pretty_printer_init (pp
);
2220 pp_needs_newline (pp
) = true;
2222 pp_base (pp
)->buffer
->stream
= file
;
2224 pp_statement (pp
, t
);
2230 /* Print the tree T in full, on stderr. */
2233 debug_c_tree (tree t
)
2235 print_c_tree (stderr
, t
);
2236 fputc ('\n', stderr
);
2239 /* Output the DECL_NAME of T. If T has no DECL_NAME, output a string made
2240 up of T's memory address. */
2243 pp_c_tree_decl_identifier (c_pretty_printer
*pp
, tree t
)
2247 gcc_assert (DECL_P (t
));
2250 name
= IDENTIFIER_POINTER (DECL_NAME (t
));
2253 static char xname
[8];
2254 sprintf (xname
, "<U%4x>", ((unsigned)((uintptr_t)(t
) & 0xffff)));
2258 pp_c_identifier (pp
, name
);