1 /* Subroutines common to both C and C++ pretty-printers.
2 Copyright (C) 2002-2016 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"
24 #include "c-pretty-print.h"
25 #include "diagnostic.h"
26 #include "stor-layout.h"
29 #include "tree-pretty-print.h"
31 /* The pretty-printer code is primarily designed to closely follow
32 (GNU) C and C++ grammars. That is to be contrasted with spaghetti
33 codes we used to have in the past. Following a structured
34 approach (preferably the official grammars) is believed to make it
35 much easier to add extensions and nifty pretty-printing effects that
36 takes expression or declaration contexts into account. */
39 #define pp_c_maybe_whitespace(PP) \
41 if ((PP)->padding == pp_before) \
42 pp_c_whitespace (PP); \
46 static void pp_c_char (c_pretty_printer
*, int);
48 /* postfix-expression */
49 static void pp_c_initializer_list (c_pretty_printer
*, tree
);
50 static void pp_c_brace_enclosed_initializer_list (c_pretty_printer
*, tree
);
52 static void pp_c_additive_expression (c_pretty_printer
*, tree
);
53 static void pp_c_shift_expression (c_pretty_printer
*, tree
);
54 static void pp_c_relational_expression (c_pretty_printer
*, tree
);
55 static void pp_c_equality_expression (c_pretty_printer
*, tree
);
56 static void pp_c_and_expression (c_pretty_printer
*, tree
);
57 static void pp_c_exclusive_or_expression (c_pretty_printer
*, tree
);
58 static void pp_c_inclusive_or_expression (c_pretty_printer
*, tree
);
59 static void pp_c_logical_and_expression (c_pretty_printer
*, tree
);
64 /* Helper functions. */
67 pp_c_whitespace (c_pretty_printer
*pp
)
70 pp
->padding
= pp_none
;
74 pp_c_left_paren (c_pretty_printer
*pp
)
77 pp
->padding
= pp_none
;
81 pp_c_right_paren (c_pretty_printer
*pp
)
84 pp
->padding
= pp_none
;
88 pp_c_left_brace (c_pretty_printer
*pp
)
91 pp
->padding
= pp_none
;
95 pp_c_right_brace (c_pretty_printer
*pp
)
98 pp
->padding
= pp_none
;
102 pp_c_left_bracket (c_pretty_printer
*pp
)
104 pp_left_bracket (pp
);
105 pp
->padding
= pp_none
;
109 pp_c_right_bracket (c_pretty_printer
*pp
)
111 pp_right_bracket (pp
);
112 pp
->padding
= pp_none
;
116 pp_c_dot (c_pretty_printer
*pp
)
119 pp
->padding
= pp_none
;
123 pp_c_ampersand (c_pretty_printer
*pp
)
126 pp
->padding
= pp_none
;
130 pp_c_star (c_pretty_printer
*pp
)
133 pp
->padding
= pp_none
;
137 pp_c_arrow (c_pretty_printer
*pp
)
140 pp
->padding
= pp_none
;
144 pp_c_semicolon (c_pretty_printer
*pp
)
147 pp
->padding
= pp_none
;
151 pp_c_complement (c_pretty_printer
*pp
)
154 pp
->padding
= pp_none
;
158 pp_c_exclamation (c_pretty_printer
*pp
)
161 pp
->padding
= pp_none
;
164 /* Print out the external representation of QUALIFIERS. */
167 pp_c_cv_qualifiers (c_pretty_printer
*pp
, int qualifiers
, bool func_type
)
169 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
);
180 if (qualifiers
& TYPE_QUAL_ATOMIC
)
181 pp_c_ws_string (pp
, "_Atomic");
182 if (qualifiers
& TYPE_QUAL_CONST
)
183 pp_c_ws_string (pp
, func_type
? "__attribute__((const))" : "const");
184 if (qualifiers
& TYPE_QUAL_VOLATILE
)
185 pp_c_ws_string (pp
, func_type
? "__attribute__((noreturn))" : "volatile");
186 if (qualifiers
& TYPE_QUAL_RESTRICT
)
187 pp_c_ws_string (pp
, (flag_isoc99
&& !c_dialect_cxx ()
188 ? "restrict" : "__restrict__"));
191 /* Pretty-print T using the type-cast notation '( type-name )'. */
194 pp_c_type_cast (c_pretty_printer
*pp
, tree t
)
196 pp_c_left_paren (pp
);
198 pp_c_right_paren (pp
);
201 /* We're about to pretty-print a pointer type as indicated by T.
202 Output a whitespace, if needed, preparing for subsequent output. */
205 pp_c_space_for_pointer_operator (c_pretty_printer
*pp
, tree t
)
207 if (POINTER_TYPE_P (t
))
209 tree pointee
= strip_pointer_operator (TREE_TYPE (t
));
210 if (TREE_CODE (pointee
) != ARRAY_TYPE
211 && TREE_CODE (pointee
) != FUNCTION_TYPE
)
212 pp_c_whitespace (pp
);
219 /* C++ cv-qualifiers are called type-qualifiers in C. Print out the
220 cv-qualifiers of T. If T is a declaration then it is the cv-qualifier
221 of its type. Take care of possible extensions.
225 type-qualifier-list type-qualifier
230 __restrict__ -- GNU C
231 address-space-qualifier -- GNU C
235 address-space-qualifier:
236 identifier -- GNU C */
239 pp_c_type_qualifier_list (c_pretty_printer
*pp
, tree t
)
243 if (!t
|| t
== error_mark_node
)
249 qualifiers
= TYPE_QUALS (t
);
250 pp_c_cv_qualifiers (pp
, qualifiers
,
251 TREE_CODE (t
) == FUNCTION_TYPE
);
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 (DECL_EXPR_DECL (t
));
287 pp_needs_newline (pp
) = true;
291 pp_unsupported_tree (pp
, t
);
295 /* simple-type-specifier:
311 struct-or-union-specifier
316 simple-type-specifier:
321 c_pretty_printer::simple_type_specifier (tree t
)
323 const enum tree_code code
= TREE_CODE (t
);
327 translate_string ("<type-error>");
330 case IDENTIFIER_NODE
:
331 pp_c_identifier (this, IDENTIFIER_POINTER (t
));
338 case FIXED_POINT_TYPE
:
342 simple_type_specifier (t
);
346 int prec
= TYPE_PRECISION (t
);
347 if (ALL_FIXED_POINT_MODE_P (TYPE_MODE (t
)))
348 t
= c_common_type_for_mode (TYPE_MODE (t
), TYPE_SATURATING (t
));
350 t
= c_common_type_for_mode (TYPE_MODE (t
), TYPE_UNSIGNED (t
));
353 simple_type_specifier (t
);
354 if (TYPE_PRECISION (t
) != prec
)
357 pp_decimal_int (this, prec
);
365 translate_string (TYPE_UNSIGNED (t
)
366 ? "<unnamed-unsigned:"
367 : "<unnamed-signed:");
370 translate_string ("<unnamed-float:");
372 case FIXED_POINT_TYPE
:
373 translate_string ("<unnamed-fixed:");
378 pp_decimal_int (this, prec
);
388 translate_string ("<typedef-error>");
394 if (TYPE_NAME (t
) && TREE_CODE (TYPE_NAME (t
)) == TYPE_DECL
)
395 /* Don't decorate the type if this is a typedef name. */;
396 else if (code
== UNION_TYPE
)
397 pp_c_ws_string (this, "union");
398 else if (code
== RECORD_TYPE
)
399 pp_c_ws_string (this, "struct");
400 else if (code
== ENUMERAL_TYPE
)
401 pp_c_ws_string (this, "enum");
403 translate_string ("<tag-error>");
406 id_expression (TYPE_NAME (t
));
408 translate_string ("<anonymous>");
412 pp_unsupported_tree (this, t
);
417 /* specifier-qualifier-list:
418 type-specifier specifier-qualifier-list-opt
419 type-qualifier specifier-qualifier-list-opt
422 Implementation note: Because of the non-linearities in array or
423 function declarations, this routine prints not just the
424 specifier-qualifier-list of such entities or types of such entities,
425 but also the 'pointer' production part of their declarators. The
426 remaining part is done by declarator() or abstract_declarator(). */
429 pp_c_specifier_qualifier_list (c_pretty_printer
*pp
, tree t
)
431 const enum tree_code code
= TREE_CODE (t
);
433 if (!(pp
->flags
& pp_c_flag_gnu_v3
) && code
!= POINTER_TYPE
)
434 pp_c_type_qualifier_list (pp
, t
);
440 /* Get the types-specifier of this type. */
441 tree pointee
= strip_pointer_operator (TREE_TYPE (t
));
442 pp_c_specifier_qualifier_list (pp
, pointee
);
443 if (TREE_CODE (pointee
) == ARRAY_TYPE
444 || TREE_CODE (pointee
) == FUNCTION_TYPE
)
446 pp_c_whitespace (pp
);
447 pp_c_left_paren (pp
);
448 pp_c_attributes_display (pp
, TYPE_ATTRIBUTES (pointee
));
450 else if (!c_dialect_cxx ())
451 pp_c_whitespace (pp
);
452 pp_ptr_operator (pp
, t
);
458 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
463 if (code
== COMPLEX_TYPE
)
464 pp_c_ws_string (pp
, (flag_isoc99
&& !c_dialect_cxx ()
465 ? "_Complex" : "__complex__"));
466 else if (code
== VECTOR_TYPE
)
468 pp_c_ws_string (pp
, "__vector");
469 pp_c_left_paren (pp
);
470 pp_wide_integer (pp
, TYPE_VECTOR_SUBPARTS (t
));
471 pp_c_right_paren (pp
);
472 pp_c_whitespace (pp
);
474 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
478 pp
->simple_type_specifier (t
);
481 if ((pp
->flags
& pp_c_flag_gnu_v3
) && code
!= POINTER_TYPE
)
482 pp_c_type_qualifier_list (pp
, t
);
485 /* parameter-type-list:
490 parameter-declaration
491 parameter-list , parameter-declaration
493 parameter-declaration:
494 declaration-specifiers declarator
495 declaration-specifiers abstract-declarator(opt) */
498 pp_c_parameter_type_list (c_pretty_printer
*pp
, tree t
)
500 bool want_parm_decl
= DECL_P (t
) && !(pp
->flags
& pp_c_flag_abstract
);
501 tree parms
= want_parm_decl
? DECL_ARGUMENTS (t
) : TYPE_ARG_TYPES (t
);
502 pp_c_left_paren (pp
);
503 if (parms
== void_list_node
)
504 pp_c_ws_string (pp
, "void");
508 for ( ; parms
&& parms
!= void_list_node
; parms
= TREE_CHAIN (parms
))
511 pp_separate_with (pp
, ',');
513 pp
->declaration_specifiers
514 (want_parm_decl
? parms
: TREE_VALUE (parms
));
516 pp
->declarator (parms
);
518 pp
->abstract_declarator (TREE_VALUE (parms
));
521 pp_c_right_paren (pp
);
524 /* abstract-declarator:
526 pointer(opt) direct-abstract-declarator */
529 c_pretty_printer::abstract_declarator (tree t
)
531 if (TREE_CODE (t
) == POINTER_TYPE
)
533 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
534 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
535 pp_c_right_paren (this);
539 direct_abstract_declarator (t
);
542 /* direct-abstract-declarator:
543 ( abstract-declarator )
544 direct-abstract-declarator(opt) [ assignment-expression(opt) ]
545 direct-abstract-declarator(opt) [ * ]
546 direct-abstract-declarator(opt) ( parameter-type-list(opt) ) */
549 c_pretty_printer::direct_abstract_declarator (tree t
)
551 switch (TREE_CODE (t
))
554 abstract_declarator (t
);
558 pp_c_parameter_type_list (this, t
);
559 direct_abstract_declarator (TREE_TYPE (t
));
563 pp_c_left_bracket (this);
564 if (TYPE_DOMAIN (t
) && TYPE_MAX_VALUE (TYPE_DOMAIN (t
)))
566 tree maxval
= TYPE_MAX_VALUE (TYPE_DOMAIN (t
));
567 tree type
= TREE_TYPE (maxval
);
569 if (tree_fits_shwi_p (maxval
))
570 pp_wide_integer (this, tree_to_shwi (maxval
) + 1);
572 expression (fold_build2 (PLUS_EXPR
, type
, maxval
,
573 build_int_cst (type
, 1)));
575 pp_c_right_bracket (this);
576 direct_abstract_declarator (TREE_TYPE (t
));
579 case IDENTIFIER_NODE
:
584 case FIXED_POINT_TYPE
:
594 pp_unsupported_tree (this, t
);
600 specifier-qualifier-list abstract-declarator(opt) */
603 c_pretty_printer::type_id (tree t
)
605 pp_c_specifier_qualifier_list (this, t
);
606 abstract_declarator (t
);
609 /* storage-class-specifier:
617 c_pretty_printer::storage_class_specifier (tree t
)
619 if (TREE_CODE (t
) == TYPE_DECL
)
620 pp_c_ws_string (this, "typedef");
623 if (DECL_REGISTER (t
))
624 pp_c_ws_string (this, "register");
625 else if (TREE_STATIC (t
) && VAR_P (t
))
626 pp_c_ws_string (this, "static");
630 /* function-specifier:
634 c_pretty_printer::function_specifier (tree t
)
636 if (TREE_CODE (t
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (t
))
637 pp_c_ws_string (this, "inline");
640 /* declaration-specifiers:
641 storage-class-specifier declaration-specifiers(opt)
642 type-specifier declaration-specifiers(opt)
643 type-qualifier declaration-specifiers(opt)
644 function-specifier declaration-specifiers(opt) */
647 c_pretty_printer::declaration_specifiers (tree t
)
649 storage_class_specifier (t
);
650 function_specifier (t
);
651 pp_c_specifier_qualifier_list (this, DECL_P (t
) ? TREE_TYPE (t
) : t
);
657 direct-declarator [ type-qualifier-list(opt) assignment-expression(opt) ]
658 direct-declarator [ static type-qualifier-list(opt) assignment-expression(opt)]
659 direct-declarator [ type-qualifier-list static assignment-expression ]
660 direct-declarator [ type-qualifier-list * ]
661 direct-declarator ( parameter-type-list )
662 direct-declarator ( identifier-list(opt) ) */
665 c_pretty_printer::direct_declarator (tree t
)
667 switch (TREE_CODE (t
))
674 pp_c_space_for_pointer_operator (this, TREE_TYPE (t
));
675 pp_c_tree_decl_identifier (this, t
);
680 abstract_declarator (TREE_TYPE (t
));
684 pp_parameter_list (this, t
);
685 abstract_declarator (TREE_TYPE (t
));
689 pp_c_space_for_pointer_operator (this, TREE_TYPE (TREE_TYPE (t
)));
690 pp_c_tree_decl_identifier (this, t
);
691 if (flags
& pp_c_flag_abstract
)
692 abstract_declarator (TREE_TYPE (t
));
695 pp_parameter_list (this, t
);
696 abstract_declarator (TREE_TYPE (TREE_TYPE (t
)));
702 case FIXED_POINT_TYPE
:
709 pp_unsupported_tree (this, t
);
716 pointer(opt) direct-declarator */
719 c_pretty_printer::declarator (tree t
)
721 switch (TREE_CODE (t
))
725 case FIXED_POINT_TYPE
:
738 direct_declarator (t
);
743 pp_unsupported_tree (this, t
);
749 declaration-specifiers init-declarator-list(opt) ; */
752 c_pretty_printer::declaration (tree t
)
754 declaration_specifiers (t
);
755 pp_c_init_declarator (this, t
);
758 /* Pretty-print ATTRIBUTES using GNU C extension syntax. */
761 pp_c_attributes (c_pretty_printer
*pp
, tree attributes
)
763 if (attributes
== NULL_TREE
)
766 pp_c_ws_string (pp
, "__attribute__");
767 pp_c_left_paren (pp
);
768 pp_c_left_paren (pp
);
769 for (; attributes
!= NULL_TREE
; attributes
= TREE_CHAIN (attributes
))
771 pp_tree_identifier (pp
, TREE_PURPOSE (attributes
));
772 if (TREE_VALUE (attributes
))
773 pp_c_call_argument_list (pp
, TREE_VALUE (attributes
));
775 if (TREE_CHAIN (attributes
))
776 pp_separate_with (pp
, ',');
778 pp_c_right_paren (pp
);
779 pp_c_right_paren (pp
);
782 /* Pretty-print ATTRIBUTES using GNU C extension syntax for attributes
783 marked to be displayed on disgnostic. */
786 pp_c_attributes_display (c_pretty_printer
*pp
, tree a
)
788 bool is_first
= true;
793 for (; a
!= NULL_TREE
; a
= TREE_CHAIN (a
))
795 const struct attribute_spec
*as
;
796 as
= lookup_attribute_spec (TREE_PURPOSE (a
));
797 if (!as
|| as
->affects_type_identity
== false)
800 && !strcmp ("transaction_safe", as
->name
))
801 /* In C++ transaction_safe is printed at the end of the declarator. */
805 pp_c_ws_string (pp
, "__attribute__");
806 pp_c_left_paren (pp
);
807 pp_c_left_paren (pp
);
812 pp_separate_with (pp
, ',');
814 pp_tree_identifier (pp
, TREE_PURPOSE (a
));
816 pp_c_call_argument_list (pp
, TREE_VALUE (a
));
821 pp_c_right_paren (pp
);
822 pp_c_right_paren (pp
);
823 pp_c_whitespace (pp
);
827 /* function-definition:
828 declaration-specifiers declarator compound-statement */
831 pp_c_function_definition (c_pretty_printer
*pp
, tree t
)
833 pp
->declaration_specifiers (t
);
835 pp_needs_newline (pp
) = true;
836 pp
->statement (DECL_SAVED_TREE (t
));
837 pp_newline_and_flush (pp
);
843 /* Print out a c-char. This is called solely for characters which are
844 in the *target* execution character set. We ought to convert them
845 back to the *host* execution character set before printing, but we
846 have no way to do this at present. A decent compromise is to print
847 all characters as if they were in the host execution character set,
848 and not attempt to recover any named escape characters, but render
849 all unprintables as octal escapes. If the host and target character
850 sets are the same, this produces relatively readable output. If they
851 are not the same, strings may appear as gibberish, but that's okay
852 (in fact, it may well be what the reader wants, e.g. if they are looking
853 to see if conversion to the target character set happened correctly).
855 A special case: we need to prefix \, ", and ' with backslashes. It is
856 correct to do so for the *host*'s \, ", and ', because the rest of the
857 file appears in the host character set. */
860 pp_c_char (c_pretty_printer
*pp
, int c
)
866 case '\\': pp_string (pp
, "\\\\"); break;
867 case '\'': pp_string (pp
, "\\\'"); break;
868 case '\"': pp_string (pp
, "\\\""); break;
869 default: pp_character (pp
, c
);
873 pp_scalar (pp
, "\\%03o", (unsigned) c
);
876 /* Print out a STRING literal. */
879 pp_c_string_literal (c_pretty_printer
*pp
, tree s
)
881 const char *p
= TREE_STRING_POINTER (s
);
882 int n
= TREE_STRING_LENGTH (s
) - 1;
885 for (i
= 0; i
< n
; ++i
)
886 pp_c_char (pp
, p
[i
]);
890 /* Pretty-print a VOID_CST (void_node). */
893 pp_c_void_constant (c_pretty_printer
*pp
)
895 pp_c_type_cast (pp
, void_type_node
);
899 /* Pretty-print an INTEGER literal. */
902 pp_c_integer_constant (c_pretty_printer
*pp
, tree i
)
906 /* We are going to compare the type of I to other types using
907 pointer comparison so we need to use its canonical type. */
909 TYPE_CANONICAL (TREE_TYPE (i
))
910 ? TYPE_CANONICAL (TREE_TYPE (i
))
913 if (tree_fits_shwi_p (i
))
914 pp_wide_integer (pp
, tree_to_shwi (i
));
915 else if (tree_fits_uhwi_p (i
))
916 pp_unsigned_wide_integer (pp
, tree_to_uhwi (i
));
921 if (wi::lt_p (i
, 0, TYPE_SIGN (TREE_TYPE (i
))))
926 print_hex (wi
, pp_buffer (pp
)->digit_buffer
);
927 pp_string (pp
, pp_buffer (pp
)->digit_buffer
);
929 if (TYPE_UNSIGNED (type
))
930 pp_character (pp
, 'u');
931 if (type
== long_integer_type_node
|| type
== long_unsigned_type_node
)
932 pp_character (pp
, 'l');
933 else if (type
== long_long_integer_type_node
934 || type
== long_long_unsigned_type_node
)
935 pp_string (pp
, "ll");
936 else for (idx
= 0; idx
< NUM_INT_N_ENTS
; idx
++)
937 if (int_n_enabled_p
[idx
])
940 if (type
== int_n_trees
[idx
].signed_type
941 || type
== int_n_trees
[idx
].unsigned_type
)
943 sprintf (buf
, "I%d", int_n_data
[idx
].bitsize
);
949 /* Print out a CHARACTER literal. */
952 pp_c_character_constant (c_pretty_printer
*pp
, tree c
)
955 pp_c_char (pp
, (unsigned) TREE_INT_CST_LOW (c
));
959 /* Print out a BOOLEAN literal. */
962 pp_c_bool_constant (c_pretty_printer
*pp
, tree b
)
964 if (b
== boolean_false_node
)
966 if (c_dialect_cxx ())
967 pp_c_ws_string (pp
, "false");
968 else if (flag_isoc99
)
969 pp_c_ws_string (pp
, "_False");
971 pp_unsupported_tree (pp
, b
);
973 else if (b
== boolean_true_node
)
975 if (c_dialect_cxx ())
976 pp_c_ws_string (pp
, "true");
977 else if (flag_isoc99
)
978 pp_c_ws_string (pp
, "_True");
980 pp_unsupported_tree (pp
, b
);
982 else if (TREE_CODE (b
) == INTEGER_CST
)
983 pp_c_integer_constant (pp
, b
);
985 pp_unsupported_tree (pp
, b
);
988 /* Attempt to print out an ENUMERATOR. Return true on success. Else return
989 false; that means the value was obtained by a cast, in which case
990 print out the type-id part of the cast-expression -- the casted value
991 is then printed by pp_c_integer_literal. */
994 pp_c_enumeration_constant (c_pretty_printer
*pp
, tree e
)
996 bool value_is_named
= true;
997 tree type
= TREE_TYPE (e
);
1000 /* Find the name of this constant. */
1001 for (value
= TYPE_VALUES (type
);
1002 value
!= NULL_TREE
&& !tree_int_cst_equal (TREE_VALUE (value
), e
);
1003 value
= TREE_CHAIN (value
))
1006 if (value
!= NULL_TREE
)
1007 pp
->id_expression (TREE_PURPOSE (value
));
1010 /* Value must have been cast. */
1011 pp_c_type_cast (pp
, type
);
1012 value_is_named
= false;
1015 return value_is_named
;
1018 /* Print out a REAL value as a decimal-floating-constant. */
1021 pp_c_floating_constant (c_pretty_printer
*pp
, tree r
)
1023 const struct real_format
*fmt
1024 = REAL_MODE_FORMAT (TYPE_MODE (TREE_TYPE (r
)));
1026 REAL_VALUE_TYPE floating_cst
= TREE_REAL_CST (r
);
1027 bool is_decimal
= floating_cst
.decimal
;
1029 /* See ISO C++ WG N1822. Note: The fraction 643/2136 approximates
1030 log10(2) to 7 significant digits. */
1031 int max_digits10
= 2 + (is_decimal
? fmt
->p
: fmt
->p
* 643L / 2136);
1033 real_to_decimal (pp_buffer (pp
)->digit_buffer
, &TREE_REAL_CST (r
),
1034 sizeof (pp_buffer (pp
)->digit_buffer
),
1037 pp_string (pp
, pp_buffer(pp
)->digit_buffer
);
1038 if (TREE_TYPE (r
) == float_type_node
)
1039 pp_character (pp
, 'f');
1040 else if (TREE_TYPE (r
) == long_double_type_node
)
1041 pp_character (pp
, 'l');
1042 else if (TREE_TYPE (r
) == dfloat128_type_node
)
1043 pp_string (pp
, "dl");
1044 else if (TREE_TYPE (r
) == dfloat64_type_node
)
1045 pp_string (pp
, "dd");
1046 else if (TREE_TYPE (r
) == dfloat32_type_node
)
1047 pp_string (pp
, "df");
1050 /* Print out a FIXED value as a decimal-floating-constant. */
1053 pp_c_fixed_constant (c_pretty_printer
*pp
, tree r
)
1055 fixed_to_decimal (pp_buffer (pp
)->digit_buffer
, &TREE_FIXED_CST (r
),
1056 sizeof (pp_buffer (pp
)->digit_buffer
));
1057 pp_string (pp
, pp_buffer(pp
)->digit_buffer
);
1060 /* Pretty-print a compound literal expression. GNU extensions include
1061 vector constants. */
1064 pp_c_compound_literal (c_pretty_printer
*pp
, tree e
)
1066 tree type
= TREE_TYPE (e
);
1067 pp_c_type_cast (pp
, type
);
1069 switch (TREE_CODE (type
))
1076 pp_c_brace_enclosed_initializer_list (pp
, e
);
1080 pp_unsupported_tree (pp
, e
);
1085 /* Pretty-print a COMPLEX_EXPR expression. */
1088 pp_c_complex_expr (c_pretty_printer
*pp
, tree e
)
1090 /* Handle a few common special cases, otherwise fallback
1091 to printing it as compound literal. */
1092 tree type
= TREE_TYPE (e
);
1093 tree realexpr
= TREE_OPERAND (e
, 0);
1094 tree imagexpr
= TREE_OPERAND (e
, 1);
1096 /* Cast of an COMPLEX_TYPE expression to a different COMPLEX_TYPE. */
1097 if (TREE_CODE (realexpr
) == NOP_EXPR
1098 && TREE_CODE (imagexpr
) == NOP_EXPR
1099 && TREE_TYPE (realexpr
) == TREE_TYPE (type
)
1100 && TREE_TYPE (imagexpr
) == TREE_TYPE (type
)
1101 && TREE_CODE (TREE_OPERAND (realexpr
, 0)) == REALPART_EXPR
1102 && TREE_CODE (TREE_OPERAND (imagexpr
, 0)) == IMAGPART_EXPR
1103 && TREE_OPERAND (TREE_OPERAND (realexpr
, 0), 0)
1104 == TREE_OPERAND (TREE_OPERAND (imagexpr
, 0), 0))
1106 pp_c_type_cast (pp
, type
);
1107 pp
->expression (TREE_OPERAND (TREE_OPERAND (realexpr
, 0), 0));
1111 /* Cast of an scalar expression to COMPLEX_TYPE. */
1112 if ((integer_zerop (imagexpr
) || real_zerop (imagexpr
))
1113 && TREE_TYPE (realexpr
) == TREE_TYPE (type
))
1115 pp_c_type_cast (pp
, type
);
1116 if (TREE_CODE (realexpr
) == NOP_EXPR
)
1117 realexpr
= TREE_OPERAND (realexpr
, 0);
1118 pp
->expression (realexpr
);
1122 pp_c_compound_literal (pp
, e
);
1128 fixed-point-constant
1129 enumeration-constant
1130 character-constant */
1133 c_pretty_printer::constant (tree e
)
1135 const enum tree_code code
= TREE_CODE (e
);
1140 pp_c_void_constant (this);
1145 tree type
= TREE_TYPE (e
);
1146 if (type
== boolean_type_node
)
1147 pp_c_bool_constant (this, e
);
1148 else if (type
== char_type_node
)
1149 pp_c_character_constant (this, e
);
1150 else if (TREE_CODE (type
) == ENUMERAL_TYPE
1151 && pp_c_enumeration_constant (this, e
))
1154 pp_c_integer_constant (this, e
);
1159 pp_c_floating_constant (this, e
);
1163 pp_c_fixed_constant (this, e
);
1167 pp_c_string_literal (this, e
);
1171 /* Sometimes, we are confused and we think a complex literal
1172 is a constant. Such thing is a compound literal which
1173 grammatically belongs to postfix-expr production. */
1174 pp_c_compound_literal (this, e
);
1178 pp_unsupported_tree (this, e
);
1183 /* Pretty-print a string such as an identifier, without changing its
1184 encoding, preceded by whitespace is necessary. */
1187 pp_c_ws_string (c_pretty_printer
*pp
, const char *str
)
1189 pp_c_maybe_whitespace (pp
);
1190 pp_string (pp
, str
);
1191 pp
->padding
= pp_before
;
1195 c_pretty_printer::translate_string (const char *gmsgid
)
1197 if (pp_translate_identifiers (this))
1198 pp_c_ws_string (this, _(gmsgid
));
1200 pp_c_ws_string (this, gmsgid
);
1203 /* Pretty-print an IDENTIFIER_NODE, which may contain UTF-8 sequences
1204 that need converting to the locale encoding, preceded by whitespace
1208 pp_c_identifier (c_pretty_printer
*pp
, const char *id
)
1210 pp_c_maybe_whitespace (pp
);
1211 pp_identifier (pp
, id
);
1212 pp
->padding
= pp_before
;
1215 /* Pretty-print a C primary-expression.
1223 c_pretty_printer::primary_expression (tree e
)
1225 switch (TREE_CODE (e
))
1233 pp_c_tree_decl_identifier (this, e
);
1236 case IDENTIFIER_NODE
:
1237 pp_c_tree_identifier (this, e
);
1241 translate_string ("<erroneous-expression>");
1245 translate_string ("<return-value>");
1257 pp_c_ws_string (this, "__builtin_memcpy");
1258 pp_c_left_paren (this);
1259 pp_ampersand (this);
1260 primary_expression (TREE_OPERAND (e
, 0));
1261 pp_separate_with (this, ',');
1262 pp_ampersand (this);
1263 initializer (TREE_OPERAND (e
, 1));
1264 if (TREE_OPERAND (e
, 2))
1266 pp_separate_with (this, ',');
1267 expression (TREE_OPERAND (e
, 2));
1269 pp_c_right_paren (this);
1273 /* FIXME: Make sure we won't get into an infinite loop. */
1274 pp_c_left_paren (this);
1276 pp_c_right_paren (this);
1281 /* Print out a C initializer -- also support C compound-literals.
1283 assignment-expression:
1284 { initializer-list }
1285 { initializer-list , } */
1288 c_pretty_printer::initializer (tree e
)
1290 if (TREE_CODE (e
) == CONSTRUCTOR
)
1291 pp_c_brace_enclosed_initializer_list (this, e
);
1298 declarator = initializer */
1301 pp_c_init_declarator (c_pretty_printer
*pp
, tree t
)
1304 /* We don't want to output function definitions here. There are handled
1305 elsewhere (and the syntactic form is bogus anyway). */
1306 if (TREE_CODE (t
) != FUNCTION_DECL
&& DECL_INITIAL (t
))
1308 tree init
= DECL_INITIAL (t
);
1309 /* This C++ bit is handled here because it is easier to do so.
1310 In templates, the C++ parser builds a TREE_LIST for a
1311 direct-initialization; the TREE_PURPOSE is the variable to
1312 initialize and the TREE_VALUE is the initializer. */
1313 if (TREE_CODE (init
) == TREE_LIST
)
1315 pp_c_left_paren (pp
);
1316 pp
->expression (TREE_VALUE (init
));
1317 pp_right_paren (pp
);
1324 pp
->initializer (init
);
1329 /* initializer-list:
1330 designation(opt) initializer
1331 initializer-list , designation(opt) initializer
1338 designator-list designator
1341 [ constant-expression ]
1345 pp_c_initializer_list (c_pretty_printer
*pp
, tree e
)
1347 tree type
= TREE_TYPE (e
);
1348 const enum tree_code code
= TREE_CODE (type
);
1350 if (TREE_CODE (e
) == CONSTRUCTOR
)
1352 pp_c_constructor_elts (pp
, CONSTRUCTOR_ELTS (e
));
1362 tree init
= TREE_OPERAND (e
, 0);
1363 for (; init
!= NULL_TREE
; init
= TREE_CHAIN (init
))
1365 if (code
== RECORD_TYPE
|| code
== UNION_TYPE
)
1368 pp
->primary_expression (TREE_PURPOSE (init
));
1372 pp_c_left_bracket (pp
);
1373 if (TREE_PURPOSE (init
))
1374 pp
->constant (TREE_PURPOSE (init
));
1375 pp_c_right_bracket (pp
);
1377 pp_c_whitespace (pp
);
1379 pp_c_whitespace (pp
);
1380 pp
->initializer (TREE_VALUE (init
));
1381 if (TREE_CHAIN (init
))
1382 pp_separate_with (pp
, ',');
1388 if (TREE_CODE (e
) == VECTOR_CST
)
1391 for (i
= 0; i
< VECTOR_CST_NELTS (e
); ++i
)
1394 pp_separate_with (pp
, ',');
1395 pp
->expression (VECTOR_CST_ELT (e
, i
));
1403 if (TREE_CODE (e
) == COMPLEX_CST
|| TREE_CODE (e
) == COMPLEX_EXPR
)
1405 const bool cst
= TREE_CODE (e
) == COMPLEX_CST
;
1406 pp
->expression (cst
? TREE_REALPART (e
) : TREE_OPERAND (e
, 0));
1407 pp_separate_with (pp
, ',');
1408 pp
->expression (cst
? TREE_IMAGPART (e
) : TREE_OPERAND (e
, 1));
1418 pp_unsupported_tree (pp
, type
);
1421 /* Pretty-print a brace-enclosed initializer-list. */
1424 pp_c_brace_enclosed_initializer_list (c_pretty_printer
*pp
, tree l
)
1426 pp_c_left_brace (pp
);
1427 pp_c_initializer_list (pp
, l
);
1428 pp_c_right_brace (pp
);
1432 /* This is a convenient function, used to bridge gap between C and C++
1439 c_pretty_printer::id_expression (tree t
)
1441 switch (TREE_CODE (t
))
1450 pp_c_tree_decl_identifier (this, t
);
1453 case IDENTIFIER_NODE
:
1454 pp_c_tree_identifier (this, t
);
1458 pp_unsupported_tree (this, t
);
1463 /* postfix-expression:
1465 postfix-expression [ expression ]
1466 postfix-expression ( argument-expression-list(opt) )
1467 postfix-expression . identifier
1468 postfix-expression -> identifier
1469 postfix-expression ++
1470 postfix-expression --
1471 ( type-name ) { initializer-list }
1472 ( type-name ) { initializer-list , } */
1475 c_pretty_printer::postfix_expression (tree e
)
1477 enum tree_code code
= TREE_CODE (e
);
1480 case POSTINCREMENT_EXPR
:
1481 case POSTDECREMENT_EXPR
:
1482 postfix_expression (TREE_OPERAND (e
, 0));
1483 pp_string (this, code
== POSTINCREMENT_EXPR
? "++" : "--");
1487 postfix_expression (TREE_OPERAND (e
, 0));
1488 pp_c_left_bracket (this);
1489 expression (TREE_OPERAND (e
, 1));
1490 pp_c_right_bracket (this);
1493 case ARRAY_NOTATION_REF
:
1494 postfix_expression (ARRAY_NOTATION_ARRAY (e
));
1495 pp_c_left_bracket (this);
1496 expression (ARRAY_NOTATION_START (e
));
1498 expression (ARRAY_NOTATION_LENGTH (e
));
1500 expression (ARRAY_NOTATION_STRIDE (e
));
1501 pp_c_right_bracket (this);
1506 call_expr_arg_iterator iter
;
1508 postfix_expression (CALL_EXPR_FN (e
));
1509 pp_c_left_paren (this);
1510 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, e
)
1513 if (more_call_expr_args_p (&iter
))
1514 pp_separate_with (this, ',');
1516 pp_c_right_paren (this);
1520 case UNORDERED_EXPR
:
1521 pp_c_ws_string (this, flag_isoc99
1523 : "__builtin_isunordered");
1527 pp_c_ws_string (this, flag_isoc99
1529 : "!__builtin_isunordered");
1533 pp_c_ws_string (this, flag_isoc99
1535 : "!__builtin_isgreaterequal");
1539 pp_c_ws_string (this, flag_isoc99
1541 : "!__builtin_isgreater");
1545 pp_c_ws_string (this, flag_isoc99
1547 : "!__builtin_islessequal");
1551 pp_c_ws_string (this, flag_isoc99
1553 : "!__builtin_isless");
1557 pp_c_ws_string (this, flag_isoc99
1559 : "!__builtin_islessgreater");
1563 pp_c_ws_string (this, flag_isoc99
1565 : "__builtin_islessgreater");
1569 pp_c_left_paren (this);
1570 expression (TREE_OPERAND (e
, 0));
1571 pp_separate_with (this, ',');
1572 expression (TREE_OPERAND (e
, 1));
1573 pp_c_right_paren (this);
1577 pp_c_ws_string (this, "__builtin_abs");
1578 pp_c_left_paren (this);
1579 expression (TREE_OPERAND (e
, 0));
1580 pp_c_right_paren (this);
1585 tree object
= TREE_OPERAND (e
, 0);
1586 if (INDIRECT_REF_P (object
))
1588 postfix_expression (TREE_OPERAND (object
, 0));
1593 postfix_expression (object
);
1596 expression (TREE_OPERAND (e
, 1));
1602 tree type
= TREE_TYPE (e
);
1604 type
= signed_or_unsigned_type_for (TYPE_UNSIGNED (type
), type
);
1606 && tree_int_cst_equal (TYPE_SIZE (type
), TREE_OPERAND (e
, 1)))
1608 HOST_WIDE_INT bitpos
= tree_to_shwi (TREE_OPERAND (e
, 2));
1609 HOST_WIDE_INT size
= tree_to_shwi (TYPE_SIZE (type
));
1610 if ((bitpos
% size
) == 0)
1612 pp_c_left_paren (this);
1613 pp_c_left_paren (this);
1616 pp_c_right_paren (this);
1617 pp_c_ampersand (this);
1618 expression (TREE_OPERAND (e
, 0));
1619 pp_c_right_paren (this);
1620 pp_c_left_bracket (this);
1621 pp_wide_integer (this, bitpos
/ size
);
1622 pp_c_right_bracket (this);
1626 pp_unsupported_tree (this, e
);
1636 pp_c_compound_literal (this, e
);
1640 pp_c_complex_expr (this, e
);
1643 case COMPOUND_LITERAL_EXPR
:
1644 e
= DECL_INITIAL (COMPOUND_LITERAL_EXPR_DECL (e
));
1651 pp_c_ws_string (this, "__builtin_va_arg");
1652 pp_c_left_paren (this);
1653 assignment_expression (TREE_OPERAND (e
, 0));
1654 pp_separate_with (this, ',');
1655 type_id (TREE_TYPE (e
));
1656 pp_c_right_paren (this);
1660 if (TREE_CODE (TREE_OPERAND (e
, 0)) == FUNCTION_DECL
)
1662 id_expression (TREE_OPERAND (e
, 0));
1665 /* else fall through. */
1668 primary_expression (e
);
1673 /* Print out an expression-list; E is expected to be a TREE_LIST. */
1676 pp_c_expression_list (c_pretty_printer
*pp
, tree e
)
1678 for (; e
!= NULL_TREE
; e
= TREE_CHAIN (e
))
1680 pp
->expression (TREE_VALUE (e
));
1682 pp_separate_with (pp
, ',');
1686 /* Print out V, which contains the elements of a constructor. */
1689 pp_c_constructor_elts (c_pretty_printer
*pp
, vec
<constructor_elt
, va_gc
> *v
)
1691 unsigned HOST_WIDE_INT ix
;
1694 FOR_EACH_CONSTRUCTOR_VALUE (v
, ix
, value
)
1696 pp
->expression (value
);
1697 if (ix
!= vec_safe_length (v
) - 1)
1698 pp_separate_with (pp
, ',');
1702 /* Print out an expression-list in parens, as if it were the argument
1703 list to a function. */
1706 pp_c_call_argument_list (c_pretty_printer
*pp
, tree t
)
1708 pp_c_left_paren (pp
);
1709 if (t
&& TREE_CODE (t
) == TREE_LIST
)
1710 pp_c_expression_list (pp
, t
);
1711 pp_c_right_paren (pp
);
1714 /* unary-expression:
1718 unary-operator cast-expression
1719 sizeof unary-expression
1722 unary-operator: one of
1727 __alignof__ unary-expression
1728 __alignof__ ( type-id )
1729 __real__ unary-expression
1730 __imag__ unary-expression */
1733 c_pretty_printer::unary_expression (tree e
)
1735 enum tree_code code
= TREE_CODE (e
);
1738 case PREINCREMENT_EXPR
:
1739 case PREDECREMENT_EXPR
:
1740 pp_string (this, code
== PREINCREMENT_EXPR
? "++" : "--");
1741 unary_expression (TREE_OPERAND (e
, 0));
1748 case TRUTH_NOT_EXPR
:
1750 /* String literal are used by address. */
1751 if (code
== ADDR_EXPR
&& TREE_CODE (TREE_OPERAND (e
, 0)) != STRING_CST
)
1752 pp_ampersand (this);
1753 else if (code
== INDIRECT_REF
)
1755 tree type
= TREE_TYPE (TREE_OPERAND (e
, 0));
1756 if (type
&& TREE_CODE (type
) == REFERENCE_TYPE
)
1757 /* Reference decay is implicit, don't print anything. */;
1761 else if (code
== NEGATE_EXPR
)
1763 else if (code
== BIT_NOT_EXPR
|| code
== CONJ_EXPR
)
1764 pp_complement (this);
1765 else if (code
== TRUTH_NOT_EXPR
)
1766 pp_exclamation (this);
1767 pp_c_cast_expression (this, TREE_OPERAND (e
, 0));
1771 if (TREE_CODE (TREE_OPERAND (e
, 0)) == ADDR_EXPR
1772 && integer_zerop (TREE_OPERAND (e
, 1)))
1773 expression (TREE_OPERAND (TREE_OPERAND (e
, 0), 0));
1777 if (!integer_zerop (TREE_OPERAND (e
, 1)))
1779 pp_c_left_paren (this);
1780 if (!integer_onep (TYPE_SIZE_UNIT
1781 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (e
, 0))))))
1782 pp_c_type_cast (this, ptr_type_node
);
1784 pp_c_cast_expression (this, TREE_OPERAND (e
, 0));
1785 if (!integer_zerop (TREE_OPERAND (e
, 1)))
1788 pp_c_integer_constant (this,
1789 fold_convert (ssizetype
,
1790 TREE_OPERAND (e
, 1)));
1791 pp_c_right_paren (this);
1798 pp_c_ws_string (this, code
== REALPART_EXPR
? "__real__" : "__imag__");
1799 pp_c_whitespace (this);
1800 unary_expression (TREE_OPERAND (e
, 0));
1804 postfix_expression (e
);
1811 ( type-name ) cast-expression */
1814 pp_c_cast_expression (c_pretty_printer
*pp
, tree e
)
1816 switch (TREE_CODE (e
))
1819 case FIX_TRUNC_EXPR
:
1821 case VIEW_CONVERT_EXPR
:
1822 pp_c_type_cast (pp
, TREE_TYPE (e
));
1823 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 0));
1827 pp
->unary_expression (e
);
1831 /* multiplicative-expression:
1833 multiplicative-expression * cast-expression
1834 multiplicative-expression / cast-expression
1835 multiplicative-expression % cast-expression */
1838 c_pretty_printer::multiplicative_expression (tree e
)
1840 enum tree_code code
= TREE_CODE (e
);
1844 case TRUNC_DIV_EXPR
:
1845 case TRUNC_MOD_EXPR
:
1846 multiplicative_expression (TREE_OPERAND (e
, 0));
1847 pp_c_whitespace (this);
1848 if (code
== MULT_EXPR
)
1850 else if (code
== TRUNC_DIV_EXPR
)
1854 pp_c_whitespace (this);
1855 pp_c_cast_expression (this, TREE_OPERAND (e
, 1));
1859 pp_c_cast_expression (this, e
);
1864 /* additive-expression:
1865 multiplicative-expression
1866 additive-expression + multiplicative-expression
1867 additive-expression - multiplicative-expression */
1870 pp_c_additive_expression (c_pretty_printer
*pp
, tree e
)
1872 enum tree_code code
= TREE_CODE (e
);
1875 case POINTER_PLUS_EXPR
:
1878 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 0));
1879 pp_c_whitespace (pp
);
1880 if (code
== PLUS_EXPR
|| code
== POINTER_PLUS_EXPR
)
1884 pp_c_whitespace (pp
);
1885 pp
->multiplicative_expression (TREE_OPERAND (e
, 1));
1889 pp
->multiplicative_expression (e
);
1894 /* additive-expression:
1896 shift-expression << additive-expression
1897 shift-expression >> additive-expression */
1900 pp_c_shift_expression (c_pretty_printer
*pp
, tree e
)
1902 enum tree_code code
= TREE_CODE (e
);
1907 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 0));
1908 pp_c_whitespace (pp
);
1909 pp_string (pp
, code
== LSHIFT_EXPR
? "<<" : ">>");
1910 pp_c_whitespace (pp
);
1911 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 1));
1915 pp_c_additive_expression (pp
, e
);
1919 /* relational-expression:
1921 relational-expression < shift-expression
1922 relational-expression > shift-expression
1923 relational-expression <= shift-expression
1924 relational-expression >= shift-expression */
1927 pp_c_relational_expression (c_pretty_printer
*pp
, tree e
)
1929 enum tree_code code
= TREE_CODE (e
);
1936 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 0));
1937 pp_c_whitespace (pp
);
1938 if (code
== LT_EXPR
)
1940 else if (code
== GT_EXPR
)
1942 else if (code
== LE_EXPR
)
1944 else if (code
== GE_EXPR
)
1945 pp_greater_equal (pp
);
1946 pp_c_whitespace (pp
);
1947 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 1));
1951 pp_c_shift_expression (pp
, e
);
1956 /* equality-expression:
1957 relational-expression
1958 equality-expression == relational-expression
1959 equality-equality != relational-expression */
1962 pp_c_equality_expression (c_pretty_printer
*pp
, tree e
)
1964 enum tree_code code
= TREE_CODE (e
);
1969 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 0));
1970 pp_c_whitespace (pp
);
1971 pp_string (pp
, code
== EQ_EXPR
? "==" : "!=");
1972 pp_c_whitespace (pp
);
1973 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 1));
1977 pp_c_relational_expression (pp
, e
);
1984 AND-expression & equality-equality */
1987 pp_c_and_expression (c_pretty_printer
*pp
, tree e
)
1989 if (TREE_CODE (e
) == BIT_AND_EXPR
)
1991 pp_c_and_expression (pp
, TREE_OPERAND (e
, 0));
1992 pp_c_whitespace (pp
);
1994 pp_c_whitespace (pp
);
1995 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 1));
1998 pp_c_equality_expression (pp
, e
);
2001 /* exclusive-OR-expression:
2003 exclusive-OR-expression ^ AND-expression */
2006 pp_c_exclusive_or_expression (c_pretty_printer
*pp
, tree e
)
2008 if (TREE_CODE (e
) == BIT_XOR_EXPR
2009 || TREE_CODE (e
) == TRUTH_XOR_EXPR
)
2011 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
2012 if (TREE_CODE (e
) == BIT_XOR_EXPR
)
2013 pp_c_maybe_whitespace (pp
);
2015 pp_c_whitespace (pp
);
2017 pp_c_whitespace (pp
);
2018 pp_c_and_expression (pp
, TREE_OPERAND (e
, 1));
2021 pp_c_and_expression (pp
, e
);
2024 /* inclusive-OR-expression:
2025 exclusive-OR-expression
2026 inclusive-OR-expression | exclusive-OR-expression */
2029 pp_c_inclusive_or_expression (c_pretty_printer
*pp
, tree e
)
2031 if (TREE_CODE (e
) == BIT_IOR_EXPR
)
2033 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
2034 pp_c_whitespace (pp
);
2036 pp_c_whitespace (pp
);
2037 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
2040 pp_c_exclusive_or_expression (pp
, e
);
2043 /* logical-AND-expression:
2044 inclusive-OR-expression
2045 logical-AND-expression && inclusive-OR-expression */
2048 pp_c_logical_and_expression (c_pretty_printer
*pp
, tree e
)
2050 if (TREE_CODE (e
) == TRUTH_ANDIF_EXPR
2051 || TREE_CODE (e
) == TRUTH_AND_EXPR
)
2053 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 0));
2054 pp_c_whitespace (pp
);
2055 pp_ampersand_ampersand (pp
);
2056 pp_c_whitespace (pp
);
2057 pp_c_inclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
2060 pp_c_inclusive_or_expression (pp
, e
);
2063 /* logical-OR-expression:
2064 logical-AND-expression
2065 logical-OR-expression || logical-AND-expression */
2068 pp_c_logical_or_expression (c_pretty_printer
*pp
, tree e
)
2070 if (TREE_CODE (e
) == TRUTH_ORIF_EXPR
2071 || TREE_CODE (e
) == TRUTH_OR_EXPR
)
2073 pp_c_logical_or_expression (pp
, TREE_OPERAND (e
, 0));
2074 pp_c_whitespace (pp
);
2076 pp_c_whitespace (pp
);
2077 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 1));
2080 pp_c_logical_and_expression (pp
, e
);
2083 /* conditional-expression:
2084 logical-OR-expression
2085 logical-OR-expression ? expression : conditional-expression */
2088 c_pretty_printer::conditional_expression (tree e
)
2090 if (TREE_CODE (e
) == COND_EXPR
)
2092 pp_c_logical_or_expression (this, TREE_OPERAND (e
, 0));
2093 pp_c_whitespace (this);
2095 pp_c_whitespace (this);
2096 expression (TREE_OPERAND (e
, 1));
2097 pp_c_whitespace (this);
2099 pp_c_whitespace (this);
2100 conditional_expression (TREE_OPERAND (e
, 2));
2103 pp_c_logical_or_expression (this, e
);
2107 /* assignment-expression:
2108 conditional-expression
2109 unary-expression assignment-operator assignment-expression
2111 assignment-expression: one of
2112 = *= /= %= += -= >>= <<= &= ^= |= */
2115 c_pretty_printer::assignment_expression (tree e
)
2117 if (TREE_CODE (e
) == MODIFY_EXPR
2118 || TREE_CODE (e
) == INIT_EXPR
)
2120 unary_expression (TREE_OPERAND (e
, 0));
2121 pp_c_whitespace (this);
2124 expression (TREE_OPERAND (e
, 1));
2127 conditional_expression (e
);
2131 assignment-expression
2132 expression , assignment-expression
2134 Implementation note: instead of going through the usual recursion
2135 chain, I take the liberty of dispatching nodes to the appropriate
2136 functions. This makes some redundancy, but it worths it. That also
2137 prevents a possible infinite recursion between primary_expression ()
2138 and expression (). */
2141 c_pretty_printer::expression (tree e
)
2143 switch (TREE_CODE (e
))
2146 pp_c_void_constant (this);
2150 pp_c_integer_constant (this, e
);
2154 pp_c_floating_constant (this, e
);
2158 pp_c_fixed_constant (this, e
);
2162 pp_c_string_literal (this, e
);
2165 case IDENTIFIER_NODE
:
2174 primary_expression (e
);
2178 if (SSA_NAME_VAR (e
)
2179 && !DECL_ARTIFICIAL (SSA_NAME_VAR (e
)))
2180 expression (SSA_NAME_VAR (e
));
2182 translate_string ("<unknown>");
2185 case POSTINCREMENT_EXPR
:
2186 case POSTDECREMENT_EXPR
:
2188 case ARRAY_NOTATION_REF
:
2196 case UNORDERED_EXPR
:
2205 case COMPOUND_LITERAL_EXPR
:
2207 postfix_expression (e
);
2216 case TRUTH_NOT_EXPR
:
2217 case PREINCREMENT_EXPR
:
2218 case PREDECREMENT_EXPR
:
2221 unary_expression (e
);
2225 case FIX_TRUNC_EXPR
:
2227 case VIEW_CONVERT_EXPR
:
2228 pp_c_cast_expression (this, e
);
2232 case TRUNC_MOD_EXPR
:
2233 case TRUNC_DIV_EXPR
:
2234 multiplicative_expression (e
);
2239 pp_c_shift_expression (this, e
);
2246 pp_c_relational_expression (this, e
);
2250 pp_c_and_expression (this, e
);
2254 case TRUTH_XOR_EXPR
:
2255 pp_c_exclusive_or_expression (this, e
);
2259 pp_c_inclusive_or_expression (this, e
);
2262 case TRUTH_ANDIF_EXPR
:
2263 case TRUTH_AND_EXPR
:
2264 pp_c_logical_and_expression (this, e
);
2267 case TRUTH_ORIF_EXPR
:
2269 pp_c_logical_or_expression (this, e
);
2274 pp_c_equality_expression (this, e
);
2278 conditional_expression (e
);
2281 case POINTER_PLUS_EXPR
:
2284 pp_c_additive_expression (this, e
);
2289 assignment_expression (e
);
2293 pp_c_left_paren (this);
2294 expression (TREE_OPERAND (e
, 0));
2295 pp_separate_with (this, ',');
2296 assignment_expression (TREE_OPERAND (e
, 1));
2297 pp_c_right_paren (this);
2300 case NON_LVALUE_EXPR
:
2302 expression (TREE_OPERAND (e
, 0));
2306 postfix_expression (TREE_OPERAND (e
, 1));
2311 /* We don't yet have a way of dumping statements in a
2312 human-readable format. */
2313 pp_string (this, "({...})");
2316 case C_MAYBE_CONST_EXPR
:
2317 expression (C_MAYBE_CONST_EXPR_EXPR (e
));
2321 pp_unsupported_tree (this, e
);
2331 c_pretty_printer::statement (tree stmt
)
2336 if (pp_needs_newline (this))
2337 pp_newline_and_indent (this, 0);
2339 dump_generic_node (this, stmt
, pp_indentation (this), 0, true);
2343 /* Initialize the PRETTY-PRINTER for handling C codes. */
2345 c_pretty_printer::c_pretty_printer ()
2346 : pretty_printer (),
2350 type_specifier_seq
= pp_c_specifier_qualifier_list
;
2351 ptr_operator
= pp_c_pointer
;
2352 parameter_list
= pp_c_parameter_type_list
;
2356 /* Print the tree T in full, on file FILE. */
2359 print_c_tree (FILE *file
, tree t
)
2361 c_pretty_printer pp
;
2363 pp_needs_newline (&pp
) = true;
2364 pp
.buffer
->stream
= file
;
2366 pp_newline_and_flush (&pp
);
2369 /* Print the tree T in full, on stderr. */
2372 debug_c_tree (tree t
)
2374 print_c_tree (stderr
, t
);
2375 fputc ('\n', stderr
);
2378 /* Output the DECL_NAME of T. If T has no DECL_NAME, output a string made
2379 up of T's memory address. */
2382 pp_c_tree_decl_identifier (c_pretty_printer
*pp
, tree t
)
2386 gcc_assert (DECL_P (t
));
2389 name
= IDENTIFIER_POINTER (DECL_NAME (t
));
2392 static char xname
[8];
2393 sprintf (xname
, "<U%4x>", ((unsigned)((uintptr_t)(t
) & 0xffff)));
2397 pp_c_identifier (pp
, name
);