1 /* Subroutines common to both C and C++ pretty-printers.
2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
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
231 pp_c_type_qualifier_list (c_pretty_printer
*pp
, tree t
)
235 if (!t
|| t
== error_mark_node
)
241 qualifiers
= TYPE_QUALS (t
);
242 if (qualifiers
& TYPE_QUAL_CONST
)
243 pp_c_cv_qualifier (pp
, "const");
244 if (qualifiers
& TYPE_QUAL_VOLATILE
)
245 pp_c_cv_qualifier (pp
, "volatile");
246 if (qualifiers
& TYPE_QUAL_RESTRICT
)
247 pp_c_cv_qualifier (pp
, flag_isoc99
? "restrict" : "__restrict__");
251 * type-qualifier-list(opt)
252 * type-qualifier-list(opt) pointer */
255 pp_c_pointer (c_pretty_printer
*pp
, tree t
)
257 if (!TYPE_P (t
) && TREE_CODE (t
) != TYPE_DECL
)
259 switch (TREE_CODE (t
))
262 /* It is easier to handle C++ reference types here. */
264 if (TREE_CODE (TREE_TYPE (t
)) == POINTER_TYPE
)
265 pp_c_pointer (pp
, TREE_TYPE (t
));
266 if (TREE_CODE (t
) == POINTER_TYPE
)
270 pp_c_type_qualifier_list (pp
, t
);
273 /* ??? This node is now in GENERIC and so shouldn't be here. But
274 we'll fix that later. */
276 pp_declaration (pp
, DECL_EXPR_DECL (t
));
277 pp_needs_newline (pp
) = true;
281 pp_unsupported_tree (pp
, t
);
298 struct-or-union-specifier
303 simple-type-specifier:
308 pp_c_type_specifier (c_pretty_printer
*pp
, tree t
)
310 const enum tree_code code
= TREE_CODE (t
);
314 pp_c_ws_string (pp
, M_("<type-error>"));
317 case IDENTIFIER_NODE
:
318 pp_c_tree_decl_identifier (pp
, t
);
325 case FIXED_POINT_TYPE
:
329 pp_c_type_specifier (pp
, t
);
333 int prec
= TYPE_PRECISION (t
);
334 if (ALL_FIXED_POINT_MODE_P (TYPE_MODE (t
)))
335 t
= c_common_type_for_mode (TYPE_MODE (t
), TYPE_SATURATING (t
));
337 t
= c_common_type_for_mode (TYPE_MODE (t
), TYPE_UNSIGNED (t
));
340 pp_c_type_specifier (pp
, t
);
341 if (TYPE_PRECISION (t
) != prec
)
344 pp_decimal_int (pp
, prec
);
352 pp_string (pp
, (TYPE_UNSIGNED (t
)
353 ? M_("<unnamed-unsigned:")
354 : M_("<unnamed-signed:")));
357 pp_string (pp
, M_("<unnamed-float:"));
359 case FIXED_POINT_TYPE
:
360 pp_string (pp
, M_("<unnamed-fixed:"));
365 pp_decimal_int (pp
, prec
);
373 pp_id_expression (pp
, t
);
375 pp_c_ws_string (pp
, M_("<typedef-error>"));
381 if (code
== UNION_TYPE
)
382 pp_c_ws_string (pp
, "union");
383 else if (code
== RECORD_TYPE
)
384 pp_c_ws_string (pp
, "struct");
385 else if (code
== ENUMERAL_TYPE
)
386 pp_c_ws_string (pp
, "enum");
388 pp_c_ws_string (pp
, M_("<tag-error>"));
391 pp_id_expression (pp
, TYPE_NAME (t
));
393 pp_c_ws_string (pp
, M_("<anonymous>"));
397 pp_unsupported_tree (pp
, t
);
402 /* specifier-qualifier-list:
403 type-specifier specifier-qualifier-list-opt
404 type-qualifier specifier-qualifier-list-opt
407 Implementation note: Because of the non-linearities in array or
408 function declarations, this routine prints not just the
409 specifier-qualifier-list of such entities or types of such entities,
410 but also the 'pointer' production part of their declarators. The
411 remaining part is done by pp_declarator or pp_c_abstract_declarator. */
414 pp_c_specifier_qualifier_list (c_pretty_printer
*pp
, tree t
)
416 const enum tree_code code
= TREE_CODE (t
);
418 if (TREE_CODE (t
) != POINTER_TYPE
)
419 pp_c_type_qualifier_list (pp
, t
);
425 /* Get the types-specifier of this type. */
426 tree pointee
= strip_pointer_operator (TREE_TYPE (t
));
427 pp_c_specifier_qualifier_list (pp
, pointee
);
428 if (TREE_CODE (pointee
) == ARRAY_TYPE
429 || TREE_CODE (pointee
) == FUNCTION_TYPE
)
431 pp_c_whitespace (pp
);
432 pp_c_left_paren (pp
);
434 else if (!c_dialect_cxx ())
435 pp_c_whitespace (pp
);
436 pp_ptr_operator (pp
, t
);
442 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
447 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
448 if (code
== COMPLEX_TYPE
)
449 pp_c_ws_string (pp
, flag_isoc99
? "_Complex" : "__complex__");
450 else if (code
== VECTOR_TYPE
)
451 pp_c_ws_string (pp
, "__vector__");
455 pp_simple_type_specifier (pp
, t
);
460 /* parameter-type-list:
465 parameter-declaration
466 parameter-list , parameter-declaration
468 parameter-declaration:
469 declaration-specifiers declarator
470 declaration-specifiers abstract-declarator(opt) */
473 pp_c_parameter_type_list (c_pretty_printer
*pp
, tree t
)
475 bool want_parm_decl
= DECL_P (t
) && !(pp
->flags
& pp_c_flag_abstract
);
476 tree parms
= want_parm_decl
? DECL_ARGUMENTS (t
) : TYPE_ARG_TYPES (t
);
477 pp_c_left_paren (pp
);
478 if (parms
== void_list_node
)
479 pp_c_ws_string (pp
, "void");
483 for ( ; parms
&& parms
!= void_list_node
; parms
= TREE_CHAIN (parms
))
486 pp_separate_with (pp
, ',');
488 pp_declaration_specifiers
489 (pp
, want_parm_decl
? parms
: TREE_VALUE (parms
));
491 pp_declarator (pp
, parms
);
493 pp_abstract_declarator (pp
, TREE_VALUE (parms
));
496 pp_c_right_paren (pp
);
499 /* abstract-declarator:
501 pointer(opt) direct-abstract-declarator */
504 pp_c_abstract_declarator (c_pretty_printer
*pp
, tree t
)
506 if (TREE_CODE (t
) == POINTER_TYPE
)
508 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
509 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
510 pp_c_right_paren (pp
);
514 pp_direct_abstract_declarator (pp
, t
);
517 /* direct-abstract-declarator:
518 ( abstract-declarator )
519 direct-abstract-declarator(opt) [ assignment-expression(opt) ]
520 direct-abstract-declarator(opt) [ * ]
521 direct-abstract-declarator(opt) ( parameter-type-list(opt) ) */
524 pp_c_direct_abstract_declarator (c_pretty_printer
*pp
, tree t
)
526 switch (TREE_CODE (t
))
529 pp_abstract_declarator (pp
, t
);
533 pp_c_parameter_type_list (pp
, t
);
534 pp_direct_abstract_declarator (pp
, TREE_TYPE (t
));
538 pp_c_left_bracket (pp
);
539 if (TYPE_DOMAIN (t
) && TYPE_MAX_VALUE (TYPE_DOMAIN (t
)))
541 tree maxval
= TYPE_MAX_VALUE (TYPE_DOMAIN (t
));
542 tree type
= TREE_TYPE (maxval
);
544 if (host_integerp (maxval
, 0))
545 pp_wide_integer (pp
, tree_low_cst (maxval
, 0) + 1);
547 pp_expression (pp
, fold_build2 (PLUS_EXPR
, type
, maxval
,
548 build_int_cst (type
, 1)));
550 pp_c_right_bracket (pp
);
551 pp_direct_abstract_declarator (pp
, TREE_TYPE (t
));
554 case IDENTIFIER_NODE
:
559 case FIXED_POINT_TYPE
:
569 pp_unsupported_tree (pp
, t
);
575 specifier-qualifier-list abstract-declarator(opt) */
578 pp_c_type_id (c_pretty_printer
*pp
, tree t
)
580 pp_c_specifier_qualifier_list (pp
, t
);
581 pp_abstract_declarator (pp
, t
);
584 /* storage-class-specifier:
592 pp_c_storage_class_specifier (c_pretty_printer
*pp
, tree t
)
594 if (TREE_CODE (t
) == TYPE_DECL
)
595 pp_c_ws_string (pp
, "typedef");
598 if (DECL_REGISTER (t
))
599 pp_c_ws_string (pp
, "register");
600 else if (TREE_STATIC (t
) && TREE_CODE (t
) == VAR_DECL
)
601 pp_c_ws_string (pp
, "static");
605 /* function-specifier:
609 pp_c_function_specifier (c_pretty_printer
*pp
, tree t
)
611 if (TREE_CODE (t
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (t
))
612 pp_c_ws_string (pp
, "inline");
615 /* declaration-specifiers:
616 storage-class-specifier declaration-specifiers(opt)
617 type-specifier declaration-specifiers(opt)
618 type-qualifier declaration-specifiers(opt)
619 function-specifier declaration-specifiers(opt) */
622 pp_c_declaration_specifiers (c_pretty_printer
*pp
, tree t
)
624 pp_storage_class_specifier (pp
, t
);
625 pp_function_specifier (pp
, t
);
626 pp_c_specifier_qualifier_list (pp
, DECL_P (t
) ? TREE_TYPE (t
) : t
);
632 direct-declarator [ type-qualifier-list(opt) assignment-expression(opt) ]
633 direct-declarator [ static type-qualifier-list(opt) assignment-expression(opt)]
634 direct-declarator [ type-qualifier-list static assignment-expression ]
635 direct-declarator [ type-qualifier-list * ]
636 direct-declarator ( parameter-type-list )
637 direct-declarator ( identifier-list(opt) ) */
640 pp_c_direct_declarator (c_pretty_printer
*pp
, tree t
)
642 switch (TREE_CODE (t
))
649 pp_c_space_for_pointer_operator (pp
, TREE_TYPE (t
));
650 pp_c_tree_decl_identifier (pp
, t
);
655 pp_abstract_declarator (pp
, TREE_TYPE (t
));
659 pp_parameter_list (pp
, t
);
660 pp_abstract_declarator (pp
, TREE_TYPE (t
));
664 pp_c_space_for_pointer_operator (pp
, TREE_TYPE (TREE_TYPE (t
)));
665 pp_c_tree_decl_identifier (pp
, t
);
666 if (pp_c_base (pp
)->flags
& pp_c_flag_abstract
)
667 pp_abstract_declarator (pp
, TREE_TYPE (t
));
670 pp_parameter_list (pp
, t
);
671 pp_abstract_declarator (pp
, TREE_TYPE (TREE_TYPE (t
)));
677 case FIXED_POINT_TYPE
:
684 pp_unsupported_tree (pp
, t
);
691 pointer(opt) direct-declarator */
694 pp_c_declarator (c_pretty_printer
*pp
, tree t
)
696 switch (TREE_CODE (t
))
700 case FIXED_POINT_TYPE
:
713 pp_direct_declarator (pp
, t
);
718 pp_unsupported_tree (pp
, t
);
724 declaration-specifiers init-declarator-list(opt) ; */
727 pp_c_declaration (c_pretty_printer
*pp
, tree t
)
729 pp_declaration_specifiers (pp
, t
);
730 pp_c_init_declarator (pp
, t
);
733 /* Pretty-print ATTRIBUTES using GNU C extension syntax. */
736 pp_c_attributes (c_pretty_printer
*pp
, tree attributes
)
738 if (attributes
== NULL_TREE
)
741 pp_c_ws_string (pp
, "__attribute__");
742 pp_c_left_paren (pp
);
743 pp_c_left_paren (pp
);
744 for (; attributes
!= NULL_TREE
; attributes
= TREE_CHAIN (attributes
))
746 pp_tree_identifier (pp
, TREE_PURPOSE (attributes
));
747 if (TREE_VALUE (attributes
))
748 pp_c_call_argument_list (pp
, TREE_VALUE (attributes
));
750 if (TREE_CHAIN (attributes
))
751 pp_separate_with (pp
, ',');
753 pp_c_right_paren (pp
);
754 pp_c_right_paren (pp
);
757 /* function-definition:
758 declaration-specifiers declarator compound-statement */
761 pp_c_function_definition (c_pretty_printer
*pp
, tree t
)
763 pp_declaration_specifiers (pp
, t
);
764 pp_declarator (pp
, t
);
765 pp_needs_newline (pp
) = true;
766 pp_statement (pp
, DECL_SAVED_TREE (t
));
774 /* Print out a c-char. This is called solely for characters which are
775 in the *target* execution character set. We ought to convert them
776 back to the *host* execution character set before printing, but we
777 have no way to do this at present. A decent compromise is to print
778 all characters as if they were in the host execution character set,
779 and not attempt to recover any named escape characters, but render
780 all unprintables as octal escapes. If the host and target character
781 sets are the same, this produces relatively readable output. If they
782 are not the same, strings may appear as gibberish, but that's okay
783 (in fact, it may well be what the reader wants, e.g. if they are looking
784 to see if conversion to the target character set happened correctly).
786 A special case: we need to prefix \, ", and ' with backslashes. It is
787 correct to do so for the *host*'s \, ", and ', because the rest of the
788 file appears in the host character set. */
791 pp_c_char (c_pretty_printer
*pp
, int c
)
797 case '\\': pp_string (pp
, "\\\\"); break;
798 case '\'': pp_string (pp
, "\\\'"); break;
799 case '\"': pp_string (pp
, "\\\""); break;
800 default: pp_character (pp
, c
);
804 pp_scalar (pp
, "\\%03o", (unsigned) c
);
807 /* Print out a STRING literal. */
810 pp_c_string_literal (c_pretty_printer
*pp
, tree s
)
812 const char *p
= TREE_STRING_POINTER (s
);
813 int n
= TREE_STRING_LENGTH (s
) - 1;
816 for (i
= 0; i
< n
; ++i
)
817 pp_c_char (pp
, p
[i
]);
821 /* Pretty-print an INTEGER literal. */
824 pp_c_integer_constant (c_pretty_printer
*pp
, tree i
)
826 tree type
= TREE_TYPE (i
);
828 if (TREE_INT_CST_HIGH (i
) == 0)
829 pp_wide_integer (pp
, TREE_INT_CST_LOW (i
));
832 unsigned HOST_WIDE_INT low
= TREE_INT_CST_LOW (i
);
833 HOST_WIDE_INT high
= TREE_INT_CST_HIGH (i
);
834 if (tree_int_cst_sgn (i
) < 0)
836 pp_character (pp
, '-');
840 sprintf (pp_buffer (pp
)->digit_buffer
, HOST_WIDE_INT_PRINT_DOUBLE_HEX
,
841 (unsigned HOST_WIDE_INT
) high
, (unsigned HOST_WIDE_INT
) low
);
842 pp_string (pp
, pp_buffer (pp
)->digit_buffer
);
844 if (TYPE_UNSIGNED (type
))
845 pp_character (pp
, 'u');
846 if (type
== long_integer_type_node
|| type
== long_unsigned_type_node
)
847 pp_character (pp
, 'l');
848 else if (type
== long_long_integer_type_node
849 || type
== long_long_unsigned_type_node
)
850 pp_string (pp
, "ll");
853 /* Print out a CHARACTER literal. */
856 pp_c_character_constant (c_pretty_printer
*pp
, tree c
)
858 tree type
= TREE_TYPE (c
);
859 if (type
== wchar_type_node
)
860 pp_character (pp
, 'L');
862 if (host_integerp (c
, TYPE_UNSIGNED (type
)))
863 pp_c_char (pp
, tree_low_cst (c
, TYPE_UNSIGNED (type
)));
865 pp_scalar (pp
, "\\x%x", (unsigned) TREE_INT_CST_LOW (c
));
869 /* Print out a BOOLEAN literal. */
872 pp_c_bool_constant (c_pretty_printer
*pp
, tree b
)
874 if (b
== boolean_false_node
)
876 if (c_dialect_cxx ())
877 pp_c_ws_string (pp
, "false");
878 else if (flag_isoc99
)
879 pp_c_ws_string (pp
, "_False");
881 pp_unsupported_tree (pp
, b
);
883 else if (b
== boolean_true_node
)
885 if (c_dialect_cxx ())
886 pp_c_ws_string (pp
, "true");
887 else if (flag_isoc99
)
888 pp_c_ws_string (pp
, "_True");
890 pp_unsupported_tree (pp
, b
);
892 else if (TREE_CODE (b
) == INTEGER_CST
)
893 pp_c_integer_constant (pp
, b
);
895 pp_unsupported_tree (pp
, b
);
898 /* Attempt to print out an ENUMERATOR. Return true on success. Else return
899 false; that means the value was obtained by a cast, in which case
900 print out the type-id part of the cast-expression -- the casted value
901 is then printed by pp_c_integer_literal. */
904 pp_c_enumeration_constant (c_pretty_printer
*pp
, tree e
)
906 bool value_is_named
= true;
907 tree type
= TREE_TYPE (e
);
910 /* Find the name of this constant. */
911 for (value
= TYPE_VALUES (type
);
912 value
!= NULL_TREE
&& !tree_int_cst_equal (TREE_VALUE (value
), e
);
913 value
= TREE_CHAIN (value
))
916 if (value
!= NULL_TREE
)
917 pp_id_expression (pp
, TREE_PURPOSE (value
));
920 /* Value must have been cast. */
921 pp_c_type_cast (pp
, type
);
922 value_is_named
= false;
925 return value_is_named
;
928 /* Print out a REAL value as a decimal-floating-constant. */
931 pp_c_floating_constant (c_pretty_printer
*pp
, tree r
)
933 real_to_decimal (pp_buffer (pp
)->digit_buffer
, &TREE_REAL_CST (r
),
934 sizeof (pp_buffer (pp
)->digit_buffer
), 0, 1);
935 pp_string (pp
, pp_buffer(pp
)->digit_buffer
);
936 if (TREE_TYPE (r
) == float_type_node
)
937 pp_character (pp
, 'f');
938 else if (TREE_TYPE (r
) == long_double_type_node
)
939 pp_character (pp
, 'l');
940 else if (TREE_TYPE (r
) == dfloat128_type_node
)
941 pp_string (pp
, "dl");
942 else if (TREE_TYPE (r
) == dfloat64_type_node
)
943 pp_string (pp
, "dd");
944 else if (TREE_TYPE (r
) == dfloat32_type_node
)
945 pp_string (pp
, "df");
948 /* Print out a FIXED value as a decimal-floating-constant. */
951 pp_c_fixed_constant (c_pretty_printer
*pp
, tree r
)
953 fixed_to_decimal (pp_buffer (pp
)->digit_buffer
, &TREE_FIXED_CST (r
),
954 sizeof (pp_buffer (pp
)->digit_buffer
));
955 pp_string (pp
, pp_buffer(pp
)->digit_buffer
);
958 /* Pretty-print a compound literal expression. GNU extensions include
962 pp_c_compound_literal (c_pretty_printer
*pp
, tree e
)
964 tree type
= TREE_TYPE (e
);
965 pp_c_type_cast (pp
, type
);
967 switch (TREE_CODE (type
))
974 pp_c_brace_enclosed_initializer_list (pp
, e
);
978 pp_unsupported_tree (pp
, e
);
983 /* Pretty-print a COMPLEX_EXPR expression. */
986 pp_c_complex_expr (c_pretty_printer
*pp
, tree e
)
988 /* Handle a few common special cases, otherwise fallback
989 to printing it as compound literal. */
990 tree type
= TREE_TYPE (e
);
991 tree realexpr
= TREE_OPERAND (e
, 0);
992 tree imagexpr
= TREE_OPERAND (e
, 1);
994 /* Cast of an COMPLEX_TYPE expression to a different COMPLEX_TYPE. */
995 if (TREE_CODE (realexpr
) == NOP_EXPR
996 && TREE_CODE (imagexpr
) == NOP_EXPR
997 && TREE_TYPE (realexpr
) == TREE_TYPE (type
)
998 && TREE_TYPE (imagexpr
) == TREE_TYPE (type
)
999 && TREE_CODE (TREE_OPERAND (realexpr
, 0)) == REALPART_EXPR
1000 && TREE_CODE (TREE_OPERAND (imagexpr
, 0)) == IMAGPART_EXPR
1001 && TREE_OPERAND (TREE_OPERAND (realexpr
, 0), 0)
1002 == TREE_OPERAND (TREE_OPERAND (imagexpr
, 0), 0))
1004 pp_c_type_cast (pp
, type
);
1005 pp_expression (pp
, TREE_OPERAND (TREE_OPERAND (realexpr
, 0), 0));
1009 /* Cast of an scalar expression to COMPLEX_TYPE. */
1010 if ((integer_zerop (imagexpr
) || real_zerop (imagexpr
))
1011 && TREE_TYPE (realexpr
) == TREE_TYPE (type
))
1013 pp_c_type_cast (pp
, type
);
1014 if (TREE_CODE (realexpr
) == NOP_EXPR
)
1015 realexpr
= TREE_OPERAND (realexpr
, 0);
1016 pp_expression (pp
, realexpr
);
1020 pp_c_compound_literal (pp
, e
);
1026 fixed-point-constant
1027 enumeration-constant
1028 character-constant */
1031 pp_c_constant (c_pretty_printer
*pp
, tree e
)
1033 const enum tree_code code
= TREE_CODE (e
);
1039 tree type
= TREE_TYPE (e
);
1040 if (type
== boolean_type_node
)
1041 pp_c_bool_constant (pp
, e
);
1042 else if (type
== char_type_node
)
1043 pp_c_character_constant (pp
, e
);
1044 else if (TREE_CODE (type
) == ENUMERAL_TYPE
1045 && pp_c_enumeration_constant (pp
, e
))
1048 pp_c_integer_constant (pp
, e
);
1053 pp_c_floating_constant (pp
, e
);
1057 pp_c_fixed_constant (pp
, e
);
1061 pp_c_string_literal (pp
, e
);
1065 /* Sometimes, we are confused and we think a complex literal
1066 is a constant. Such thing is a compound literal which
1067 grammatically belongs to postfix-expr production. */
1068 pp_c_compound_literal (pp
, e
);
1072 pp_unsupported_tree (pp
, e
);
1077 /* Pretty-print a string such as an identifier, without changing its
1078 encoding, preceded by whitespace is necessary. */
1081 pp_c_ws_string (c_pretty_printer
*pp
, const char *str
)
1083 pp_c_maybe_whitespace (pp
);
1084 pp_string (pp
, str
);
1085 pp_base (pp
)->padding
= pp_before
;
1088 /* Pretty-print an IDENTIFIER_NODE, which may contain UTF-8 sequences
1089 that need converting to the locale encoding, preceded by whitespace
1093 pp_c_identifier (c_pretty_printer
*pp
, const char *id
)
1095 pp_c_maybe_whitespace (pp
);
1096 pp_identifier (pp
, id
);
1097 pp_base (pp
)->padding
= pp_before
;
1100 /* Pretty-print a C primary-expression.
1108 pp_c_primary_expression (c_pretty_printer
*pp
, tree e
)
1110 switch (TREE_CODE (e
))
1118 pp_c_tree_decl_identifier (pp
, e
);
1121 case IDENTIFIER_NODE
:
1122 pp_c_tree_identifier (pp
, e
);
1126 pp_c_ws_string (pp
, M_("<erroneous-expression>"));
1130 pp_c_ws_string (pp
, M_("<return-value>"));
1137 pp_c_constant (pp
, e
);
1141 pp_c_ws_string (pp
, "__builtin_memcpy");
1142 pp_c_left_paren (pp
);
1144 pp_primary_expression (pp
, TREE_OPERAND (e
, 0));
1145 pp_separate_with (pp
, ',');
1147 pp_initializer (pp
, TREE_OPERAND (e
, 1));
1148 if (TREE_OPERAND (e
, 2))
1150 pp_separate_with (pp
, ',');
1151 pp_c_expression (pp
, TREE_OPERAND (e
, 2));
1153 pp_c_right_paren (pp
);
1157 /* FIXME: Make sure we won't get into an infinite loop. */
1158 pp_c_left_paren (pp
);
1159 pp_expression (pp
, e
);
1160 pp_c_right_paren (pp
);
1165 /* Print out a C initializer -- also support C compound-literals.
1167 assignment-expression:
1168 { initializer-list }
1169 { initializer-list , } */
1172 pp_c_initializer (c_pretty_printer
*pp
, tree e
)
1174 if (TREE_CODE (e
) == CONSTRUCTOR
)
1175 pp_c_brace_enclosed_initializer_list (pp
, e
);
1177 pp_expression (pp
, e
);
1182 declarator = initializer */
1185 pp_c_init_declarator (c_pretty_printer
*pp
, tree t
)
1187 pp_declarator (pp
, t
);
1188 /* We don't want to output function definitions here. There are handled
1189 elsewhere (and the syntactic form is bogus anyway). */
1190 if (TREE_CODE (t
) != FUNCTION_DECL
&& DECL_INITIAL (t
))
1192 tree init
= DECL_INITIAL (t
);
1193 /* This C++ bit is handled here because it is easier to do so.
1194 In templates, the C++ parser builds a TREE_LIST for a
1195 direct-initialization; the TREE_PURPOSE is the variable to
1196 initialize and the TREE_VALUE is the initializer. */
1197 if (TREE_CODE (init
) == TREE_LIST
)
1199 pp_c_left_paren (pp
);
1200 pp_expression (pp
, TREE_VALUE (init
));
1201 pp_right_paren (pp
);
1208 pp_c_initializer (pp
, init
);
1213 /* initializer-list:
1214 designation(opt) initializer
1215 initializer-list , designation(opt) initializer
1222 designator-list designator
1225 [ constant-expression ]
1229 pp_c_initializer_list (c_pretty_printer
*pp
, tree e
)
1231 tree type
= TREE_TYPE (e
);
1232 const enum tree_code code
= TREE_CODE (type
);
1234 if (TREE_CODE (e
) == CONSTRUCTOR
)
1236 pp_c_constructor_elts (pp
, CONSTRUCTOR_ELTS (e
));
1246 tree init
= TREE_OPERAND (e
, 0);
1247 for (; init
!= NULL_TREE
; init
= TREE_CHAIN (init
))
1249 if (code
== RECORD_TYPE
|| code
== UNION_TYPE
)
1252 pp_c_primary_expression (pp
, TREE_PURPOSE (init
));
1256 pp_c_left_bracket (pp
);
1257 if (TREE_PURPOSE (init
))
1258 pp_c_constant (pp
, TREE_PURPOSE (init
));
1259 pp_c_right_bracket (pp
);
1261 pp_c_whitespace (pp
);
1263 pp_c_whitespace (pp
);
1264 pp_initializer (pp
, TREE_VALUE (init
));
1265 if (TREE_CHAIN (init
))
1266 pp_separate_with (pp
, ',');
1272 if (TREE_CODE (e
) == VECTOR_CST
)
1273 pp_c_expression_list (pp
, TREE_VECTOR_CST_ELTS (e
));
1279 if (TREE_CODE (e
) == COMPLEX_CST
|| TREE_CODE (e
) == COMPLEX_EXPR
)
1281 const bool cst
= TREE_CODE (e
) == COMPLEX_CST
;
1282 pp_expression (pp
, cst
? TREE_REALPART (e
) : TREE_OPERAND (e
, 0));
1283 pp_separate_with (pp
, ',');
1284 pp_expression (pp
, cst
? TREE_IMAGPART (e
) : TREE_OPERAND (e
, 1));
1294 pp_unsupported_tree (pp
, type
);
1297 /* Pretty-print a brace-enclosed initializer-list. */
1300 pp_c_brace_enclosed_initializer_list (c_pretty_printer
*pp
, tree l
)
1302 pp_c_left_brace (pp
);
1303 pp_c_initializer_list (pp
, l
);
1304 pp_c_right_brace (pp
);
1308 /* This is a convenient function, used to bridge gap between C and C++
1315 pp_c_id_expression (c_pretty_printer
*pp
, tree t
)
1317 switch (TREE_CODE (t
))
1326 pp_c_tree_decl_identifier (pp
, t
);
1329 case IDENTIFIER_NODE
:
1330 pp_c_tree_identifier (pp
, t
);
1334 pp_unsupported_tree (pp
, t
);
1339 /* postfix-expression:
1341 postfix-expression [ expression ]
1342 postfix-expression ( argument-expression-list(opt) )
1343 postfix-expression . identifier
1344 postfix-expression -> identifier
1345 postfix-expression ++
1346 postfix-expression --
1347 ( type-name ) { initializer-list }
1348 ( type-name ) { initializer-list , } */
1351 pp_c_postfix_expression (c_pretty_printer
*pp
, tree e
)
1353 enum tree_code code
= TREE_CODE (e
);
1356 case POSTINCREMENT_EXPR
:
1357 case POSTDECREMENT_EXPR
:
1358 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1359 pp_string (pp
, code
== POSTINCREMENT_EXPR
? "++" : "--");
1363 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1364 pp_c_left_bracket (pp
);
1365 pp_expression (pp
, TREE_OPERAND (e
, 1));
1366 pp_c_right_bracket (pp
);
1371 call_expr_arg_iterator iter
;
1373 pp_postfix_expression (pp
, CALL_EXPR_FN (e
));
1374 pp_c_left_paren (pp
);
1375 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, e
)
1377 pp_expression (pp
, arg
);
1378 if (more_call_expr_args_p (&iter
))
1379 pp_separate_with (pp
, ',');
1381 pp_c_right_paren (pp
);
1385 case UNORDERED_EXPR
:
1386 pp_c_ws_string (pp
, flag_isoc99
1388 : "__builtin_isunordered");
1392 pp_c_ws_string (pp
, flag_isoc99
1394 : "!__builtin_isunordered");
1398 pp_c_ws_string (pp
, flag_isoc99
1400 : "!__builtin_isgreaterequal");
1404 pp_c_ws_string (pp
, flag_isoc99
1406 : "!__builtin_isgreater");
1410 pp_c_ws_string (pp
, flag_isoc99
1412 : "!__builtin_islessequal");
1416 pp_c_ws_string (pp
, flag_isoc99
1418 : "!__builtin_isless");
1422 pp_c_ws_string (pp
, flag_isoc99
1424 : "!__builtin_islessgreater");
1428 pp_c_ws_string (pp
, flag_isoc99
1430 : "__builtin_islessgreater");
1434 pp_c_left_paren (pp
);
1435 pp_expression (pp
, TREE_OPERAND (e
, 0));
1436 pp_separate_with (pp
, ',');
1437 pp_expression (pp
, TREE_OPERAND (e
, 1));
1438 pp_c_right_paren (pp
);
1442 pp_c_ws_string (pp
, "__builtin_abs");
1443 pp_c_left_paren (pp
);
1444 pp_expression (pp
, TREE_OPERAND (e
, 0));
1445 pp_c_right_paren (pp
);
1450 tree object
= TREE_OPERAND (e
, 0);
1451 if (TREE_CODE (object
) == INDIRECT_REF
)
1453 pp_postfix_expression (pp
, TREE_OPERAND (object
, 0));
1458 pp_postfix_expression (pp
, object
);
1461 pp_expression (pp
, TREE_OPERAND (e
, 1));
1467 tree type
= TREE_TYPE (e
);
1469 type
= signed_or_unsigned_type_for (TYPE_UNSIGNED (type
), type
);
1471 && tree_int_cst_equal (TYPE_SIZE (type
), TREE_OPERAND (e
, 1)))
1473 HOST_WIDE_INT bitpos
= tree_low_cst (TREE_OPERAND (e
, 2), 0);
1474 HOST_WIDE_INT size
= tree_low_cst (TYPE_SIZE (type
), 0);
1475 if ((bitpos
% size
) == 0)
1477 pp_c_left_paren (pp
);
1478 pp_c_left_paren (pp
);
1479 pp_type_id (pp
, type
);
1481 pp_c_right_paren (pp
);
1482 pp_c_ampersand (pp
);
1483 pp_expression (pp
, TREE_OPERAND (e
, 0));
1484 pp_c_right_paren (pp
);
1485 pp_c_left_bracket (pp
);
1486 pp_wide_integer (pp
, bitpos
/ size
);
1487 pp_c_right_bracket (pp
);
1491 pp_unsupported_tree (pp
, e
);
1497 pp_c_compound_literal (pp
, e
);
1501 pp_c_complex_expr (pp
, e
);
1504 case COMPOUND_LITERAL_EXPR
:
1505 e
= DECL_INITIAL (COMPOUND_LITERAL_EXPR_DECL (e
));
1508 pp_initializer (pp
, e
);
1512 pp_c_ws_string (pp
, "__builtin_va_arg");
1513 pp_c_left_paren (pp
);
1514 pp_assignment_expression (pp
, TREE_OPERAND (e
, 0));
1515 pp_separate_with (pp
, ',');
1516 pp_type_id (pp
, TREE_TYPE (e
));
1517 pp_c_right_paren (pp
);
1521 if (TREE_CODE (TREE_OPERAND (e
, 0)) == FUNCTION_DECL
)
1523 pp_c_id_expression (pp
, TREE_OPERAND (e
, 0));
1526 /* else fall through. */
1529 pp_primary_expression (pp
, e
);
1534 /* Print out an expression-list; E is expected to be a TREE_LIST. */
1537 pp_c_expression_list (c_pretty_printer
*pp
, tree e
)
1539 for (; e
!= NULL_TREE
; e
= TREE_CHAIN (e
))
1541 pp_expression (pp
, TREE_VALUE (e
));
1543 pp_separate_with (pp
, ',');
1547 /* Print out V, which contains the elements of a constructor. */
1550 pp_c_constructor_elts (c_pretty_printer
*pp
, VEC(constructor_elt
,gc
) *v
)
1552 unsigned HOST_WIDE_INT ix
;
1555 FOR_EACH_CONSTRUCTOR_VALUE (v
, ix
, value
)
1557 pp_expression (pp
, value
);
1558 if (ix
!= VEC_length (constructor_elt
, v
) - 1)
1559 pp_separate_with (pp
, ',');
1563 /* Print out an expression-list in parens, as if it were the argument
1564 list to a function. */
1567 pp_c_call_argument_list (c_pretty_printer
*pp
, tree t
)
1569 pp_c_left_paren (pp
);
1570 if (t
&& TREE_CODE (t
) == TREE_LIST
)
1571 pp_c_expression_list (pp
, t
);
1572 pp_c_right_paren (pp
);
1575 /* unary-expression:
1579 unary-operator cast-expression
1580 sizeof unary-expression
1583 unary-operator: one of
1588 __alignof__ unary-expression
1589 __alignof__ ( type-id )
1590 __real__ unary-expression
1591 __imag__ unary-expression */
1594 pp_c_unary_expression (c_pretty_printer
*pp
, tree e
)
1596 enum tree_code code
= TREE_CODE (e
);
1599 case PREINCREMENT_EXPR
:
1600 case PREDECREMENT_EXPR
:
1601 pp_string (pp
, code
== PREINCREMENT_EXPR
? "++" : "--");
1602 pp_c_unary_expression (pp
, TREE_OPERAND (e
, 0));
1609 case TRUTH_NOT_EXPR
:
1611 /* String literal are used by address. */
1612 if (code
== ADDR_EXPR
&& TREE_CODE (TREE_OPERAND (e
, 0)) != STRING_CST
)
1614 else if (code
== INDIRECT_REF
)
1616 else if (code
== NEGATE_EXPR
)
1618 else if (code
== BIT_NOT_EXPR
|| code
== CONJ_EXPR
)
1620 else if (code
== TRUTH_NOT_EXPR
)
1621 pp_exclamation (pp
);
1622 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 0));
1627 pp_c_ws_string (pp
, code
== REALPART_EXPR
? "__real__" : "__imag__");
1628 pp_c_whitespace (pp
);
1629 pp_unary_expression (pp
, TREE_OPERAND (e
, 0));
1633 pp_postfix_expression (pp
, e
);
1640 ( type-name ) cast-expression */
1643 pp_c_cast_expression (c_pretty_printer
*pp
, tree e
)
1645 switch (TREE_CODE (e
))
1648 case FIX_TRUNC_EXPR
:
1650 case VIEW_CONVERT_EXPR
:
1651 pp_c_type_cast (pp
, TREE_TYPE (e
));
1652 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 0));
1656 pp_unary_expression (pp
, e
);
1660 /* multiplicative-expression:
1662 multiplicative-expression * cast-expression
1663 multiplicative-expression / cast-expression
1664 multiplicative-expression % cast-expression */
1667 pp_c_multiplicative_expression (c_pretty_printer
*pp
, tree e
)
1669 enum tree_code code
= TREE_CODE (e
);
1673 case TRUNC_DIV_EXPR
:
1674 case TRUNC_MOD_EXPR
:
1675 pp_multiplicative_expression (pp
, TREE_OPERAND (e
, 0));
1676 pp_c_whitespace (pp
);
1677 if (code
== MULT_EXPR
)
1679 else if (code
== TRUNC_DIV_EXPR
)
1683 pp_c_whitespace (pp
);
1684 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 1));
1688 pp_c_cast_expression (pp
, e
);
1693 /* additive-expression:
1694 multiplicative-expression
1695 additive-expression + multiplicative-expression
1696 additive-expression - multiplicative-expression */
1699 pp_c_additive_expression (c_pretty_printer
*pp
, tree e
)
1701 enum tree_code code
= TREE_CODE (e
);
1704 case POINTER_PLUS_EXPR
:
1707 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 0));
1708 pp_c_whitespace (pp
);
1709 if (code
== PLUS_EXPR
|| code
== POINTER_PLUS_EXPR
)
1713 pp_c_whitespace (pp
);
1714 pp_multiplicative_expression (pp
, TREE_OPERAND (e
, 1));
1718 pp_multiplicative_expression (pp
, e
);
1723 /* additive-expression:
1725 shift-expression << additive-expression
1726 shift-expression >> additive-expression */
1729 pp_c_shift_expression (c_pretty_printer
*pp
, tree e
)
1731 enum tree_code code
= TREE_CODE (e
);
1736 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 0));
1737 pp_c_whitespace (pp
);
1738 pp_string (pp
, code
== LSHIFT_EXPR
? "<<" : ">>");
1739 pp_c_whitespace (pp
);
1740 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 1));
1744 pp_c_additive_expression (pp
, e
);
1748 /* relational-expression:
1750 relational-expression < shift-expression
1751 relational-expression > shift-expression
1752 relational-expression <= shift-expression
1753 relational-expression >= shift-expression */
1756 pp_c_relational_expression (c_pretty_printer
*pp
, tree e
)
1758 enum tree_code code
= TREE_CODE (e
);
1765 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 0));
1766 pp_c_whitespace (pp
);
1767 if (code
== LT_EXPR
)
1769 else if (code
== GT_EXPR
)
1771 else if (code
== LE_EXPR
)
1772 pp_string (pp
, "<=");
1773 else if (code
== GE_EXPR
)
1774 pp_string (pp
, ">=");
1775 pp_c_whitespace (pp
);
1776 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 1));
1780 pp_c_shift_expression (pp
, e
);
1785 /* equality-expression:
1786 relational-expression
1787 equality-expression == relational-expression
1788 equality-equality != relational-expression */
1791 pp_c_equality_expression (c_pretty_printer
*pp
, tree e
)
1793 enum tree_code code
= TREE_CODE (e
);
1798 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 0));
1799 pp_c_whitespace (pp
);
1800 pp_string (pp
, code
== EQ_EXPR
? "==" : "!=");
1801 pp_c_whitespace (pp
);
1802 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 1));
1806 pp_c_relational_expression (pp
, e
);
1813 AND-expression & equality-equality */
1816 pp_c_and_expression (c_pretty_printer
*pp
, tree e
)
1818 if (TREE_CODE (e
) == BIT_AND_EXPR
)
1820 pp_c_and_expression (pp
, TREE_OPERAND (e
, 0));
1821 pp_c_whitespace (pp
);
1823 pp_c_whitespace (pp
);
1824 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 1));
1827 pp_c_equality_expression (pp
, e
);
1830 /* exclusive-OR-expression:
1832 exclusive-OR-expression ^ AND-expression */
1835 pp_c_exclusive_or_expression (c_pretty_printer
*pp
, tree e
)
1837 if (TREE_CODE (e
) == BIT_XOR_EXPR
1838 || TREE_CODE (e
) == TRUTH_XOR_EXPR
)
1840 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
1841 if (TREE_CODE (e
) == BIT_XOR_EXPR
)
1842 pp_c_maybe_whitespace (pp
);
1844 pp_c_whitespace (pp
);
1846 pp_c_whitespace (pp
);
1847 pp_c_and_expression (pp
, TREE_OPERAND (e
, 1));
1850 pp_c_and_expression (pp
, e
);
1853 /* inclusive-OR-expression:
1854 exclusive-OR-expression
1855 inclusive-OR-expression | exclusive-OR-expression */
1858 pp_c_inclusive_or_expression (c_pretty_printer
*pp
, tree e
)
1860 if (TREE_CODE (e
) == BIT_IOR_EXPR
)
1862 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
1863 pp_c_whitespace (pp
);
1865 pp_c_whitespace (pp
);
1866 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
1869 pp_c_exclusive_or_expression (pp
, e
);
1872 /* logical-AND-expression:
1873 inclusive-OR-expression
1874 logical-AND-expression && inclusive-OR-expression */
1877 pp_c_logical_and_expression (c_pretty_printer
*pp
, tree e
)
1879 if (TREE_CODE (e
) == TRUTH_ANDIF_EXPR
1880 || TREE_CODE (e
) == TRUTH_AND_EXPR
)
1882 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 0));
1883 pp_c_whitespace (pp
);
1884 pp_string (pp
, "&&");
1885 pp_c_whitespace (pp
);
1886 pp_c_inclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
1889 pp_c_inclusive_or_expression (pp
, e
);
1892 /* logical-OR-expression:
1893 logical-AND-expression
1894 logical-OR-expression || logical-AND-expression */
1897 pp_c_logical_or_expression (c_pretty_printer
*pp
, tree e
)
1899 if (TREE_CODE (e
) == TRUTH_ORIF_EXPR
1900 || TREE_CODE (e
) == TRUTH_OR_EXPR
)
1902 pp_c_logical_or_expression (pp
, TREE_OPERAND (e
, 0));
1903 pp_c_whitespace (pp
);
1904 pp_string (pp
, "||");
1905 pp_c_whitespace (pp
);
1906 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 1));
1909 pp_c_logical_and_expression (pp
, e
);
1912 /* conditional-expression:
1913 logical-OR-expression
1914 logical-OR-expression ? expression : conditional-expression */
1917 pp_c_conditional_expression (c_pretty_printer
*pp
, tree e
)
1919 if (TREE_CODE (e
) == COND_EXPR
)
1921 pp_c_logical_or_expression (pp
, TREE_OPERAND (e
, 0));
1922 pp_c_whitespace (pp
);
1924 pp_c_whitespace (pp
);
1925 pp_expression (pp
, TREE_OPERAND (e
, 1));
1926 pp_c_whitespace (pp
);
1928 pp_c_whitespace (pp
);
1929 pp_c_conditional_expression (pp
, TREE_OPERAND (e
, 2));
1932 pp_c_logical_or_expression (pp
, e
);
1936 /* assignment-expression:
1937 conditional-expression
1938 unary-expression assignment-operator assignment-expression
1940 assignment-expression: one of
1941 = *= /= %= += -= >>= <<= &= ^= |= */
1944 pp_c_assignment_expression (c_pretty_printer
*pp
, tree e
)
1946 if (TREE_CODE (e
) == MODIFY_EXPR
1947 || TREE_CODE (e
) == INIT_EXPR
)
1949 pp_c_unary_expression (pp
, TREE_OPERAND (e
, 0));
1950 pp_c_whitespace (pp
);
1953 pp_c_expression (pp
, TREE_OPERAND (e
, 1));
1956 pp_c_conditional_expression (pp
, e
);
1960 assignment-expression
1961 expression , assignment-expression
1963 Implementation note: instead of going through the usual recursion
1964 chain, I take the liberty of dispatching nodes to the appropriate
1965 functions. This makes some redundancy, but it worths it. That also
1966 prevents a possible infinite recursion between pp_c_primary_expression ()
1967 and pp_c_expression (). */
1970 pp_c_expression (c_pretty_printer
*pp
, tree e
)
1972 switch (TREE_CODE (e
))
1975 pp_c_integer_constant (pp
, e
);
1979 pp_c_floating_constant (pp
, e
);
1983 pp_c_fixed_constant (pp
, e
);
1987 pp_c_string_literal (pp
, e
);
1990 case IDENTIFIER_NODE
:
1999 pp_primary_expression (pp
, e
);
2002 case POSTINCREMENT_EXPR
:
2003 case POSTDECREMENT_EXPR
:
2012 case UNORDERED_EXPR
:
2021 case COMPOUND_LITERAL_EXPR
:
2023 pp_postfix_expression (pp
, e
);
2031 case TRUTH_NOT_EXPR
:
2032 case PREINCREMENT_EXPR
:
2033 case PREDECREMENT_EXPR
:
2036 pp_c_unary_expression (pp
, e
);
2040 case FIX_TRUNC_EXPR
:
2042 case VIEW_CONVERT_EXPR
:
2043 pp_c_cast_expression (pp
, e
);
2047 case TRUNC_MOD_EXPR
:
2048 case TRUNC_DIV_EXPR
:
2049 pp_multiplicative_expression (pp
, e
);
2054 pp_c_shift_expression (pp
, e
);
2061 pp_c_relational_expression (pp
, e
);
2065 pp_c_and_expression (pp
, e
);
2069 case TRUTH_XOR_EXPR
:
2070 pp_c_exclusive_or_expression (pp
, e
);
2074 pp_c_inclusive_or_expression (pp
, e
);
2077 case TRUTH_ANDIF_EXPR
:
2078 case TRUTH_AND_EXPR
:
2079 pp_c_logical_and_expression (pp
, e
);
2082 case TRUTH_ORIF_EXPR
:
2084 pp_c_logical_or_expression (pp
, e
);
2089 pp_c_equality_expression (pp
, e
);
2093 pp_conditional_expression (pp
, e
);
2096 case POINTER_PLUS_EXPR
:
2099 pp_c_additive_expression (pp
, e
);
2104 pp_assignment_expression (pp
, e
);
2108 pp_c_left_paren (pp
);
2109 pp_expression (pp
, TREE_OPERAND (e
, 0));
2110 pp_separate_with (pp
, ',');
2111 pp_assignment_expression (pp
, TREE_OPERAND (e
, 1));
2112 pp_c_right_paren (pp
);
2115 case NON_LVALUE_EXPR
:
2117 pp_expression (pp
, TREE_OPERAND (e
, 0));
2121 pp_postfix_expression (pp
, TREE_OPERAND (e
, 1));
2126 /* We don't yet have a way of dumping statements in a
2127 human-readable format. */
2128 pp_string (pp
, "({...})");
2132 pp_unsupported_tree (pp
, e
);
2142 pp_c_statement (c_pretty_printer
*pp
, tree stmt
)
2147 if (pp_needs_newline (pp
))
2148 pp_newline_and_indent (pp
, 0);
2150 dump_generic_node (pp_base (pp
), stmt
, pp_indentation (pp
), 0, true);
2154 /* Initialize the PRETTY-PRINTER for handling C codes. */
2157 pp_c_pretty_printer_init (c_pretty_printer
*pp
)
2159 pp
->offset_list
= 0;
2161 pp
->declaration
= pp_c_declaration
;
2162 pp
->declaration_specifiers
= pp_c_declaration_specifiers
;
2163 pp
->declarator
= pp_c_declarator
;
2164 pp
->direct_declarator
= pp_c_direct_declarator
;
2165 pp
->type_specifier_seq
= pp_c_specifier_qualifier_list
;
2166 pp
->abstract_declarator
= pp_c_abstract_declarator
;
2167 pp
->direct_abstract_declarator
= pp_c_direct_abstract_declarator
;
2168 pp
->ptr_operator
= pp_c_pointer
;
2169 pp
->parameter_list
= pp_c_parameter_type_list
;
2170 pp
->type_id
= pp_c_type_id
;
2171 pp
->simple_type_specifier
= pp_c_type_specifier
;
2172 pp
->function_specifier
= pp_c_function_specifier
;
2173 pp
->storage_class_specifier
= pp_c_storage_class_specifier
;
2175 pp
->statement
= pp_c_statement
;
2177 pp
->constant
= pp_c_constant
;
2178 pp
->id_expression
= pp_c_id_expression
;
2179 pp
->primary_expression
= pp_c_primary_expression
;
2180 pp
->postfix_expression
= pp_c_postfix_expression
;
2181 pp
->unary_expression
= pp_c_unary_expression
;
2182 pp
->initializer
= pp_c_initializer
;
2183 pp
->multiplicative_expression
= pp_c_multiplicative_expression
;
2184 pp
->conditional_expression
= pp_c_conditional_expression
;
2185 pp
->assignment_expression
= pp_c_assignment_expression
;
2186 pp
->expression
= pp_c_expression
;
2190 /* Print the tree T in full, on file FILE. */
2193 print_c_tree (FILE *file
, tree t
)
2195 static c_pretty_printer pp_rec
;
2196 static bool initialized
= 0;
2197 c_pretty_printer
*pp
= &pp_rec
;
2202 pp_construct (pp_base (pp
), NULL
, 0);
2203 pp_c_pretty_printer_init (pp
);
2204 pp_needs_newline (pp
) = true;
2206 pp_base (pp
)->buffer
->stream
= file
;
2208 pp_statement (pp
, t
);
2214 /* Print the tree T in full, on stderr. */
2217 debug_c_tree (tree t
)
2219 print_c_tree (stderr
, t
);
2220 fputc ('\n', stderr
);
2223 /* Output the DECL_NAME of T. If T has no DECL_NAME, output a string made
2224 up of T's memory address. */
2227 pp_c_tree_decl_identifier (c_pretty_printer
*pp
, tree t
)
2231 gcc_assert (DECL_P (t
));
2234 name
= IDENTIFIER_POINTER (DECL_NAME (t
));
2237 static char xname
[8];
2238 sprintf (xname
, "<U%4x>", ((unsigned)((unsigned long)(t
) & 0xffff)));
2242 pp_c_identifier (pp
, name
);