1 /* Subroutines common to both C and C++ pretty-printers.
2 Copyright (C) 2002-2015 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"
29 #include "stor-layout.h"
32 #include "c-pretty-print.h"
33 #include "tree-pretty-print.h"
34 #include "tree-iterator.h"
35 #include "diagnostic.h"
36 #include "wide-int-print.h"
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)->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_additive_expression (c_pretty_printer
*, tree
);
60 static void pp_c_shift_expression (c_pretty_printer
*, tree
);
61 static void pp_c_relational_expression (c_pretty_printer
*, tree
);
62 static void pp_c_equality_expression (c_pretty_printer
*, tree
);
63 static void pp_c_and_expression (c_pretty_printer
*, tree
);
64 static void pp_c_exclusive_or_expression (c_pretty_printer
*, tree
);
65 static void pp_c_inclusive_or_expression (c_pretty_printer
*, tree
);
66 static void pp_c_logical_and_expression (c_pretty_printer
*, tree
);
71 /* Helper functions. */
74 pp_c_whitespace (c_pretty_printer
*pp
)
77 pp
->padding
= pp_none
;
81 pp_c_left_paren (c_pretty_printer
*pp
)
84 pp
->padding
= pp_none
;
88 pp_c_right_paren (c_pretty_printer
*pp
)
91 pp
->padding
= pp_none
;
95 pp_c_left_brace (c_pretty_printer
*pp
)
98 pp
->padding
= pp_none
;
102 pp_c_right_brace (c_pretty_printer
*pp
)
105 pp
->padding
= pp_none
;
109 pp_c_left_bracket (c_pretty_printer
*pp
)
111 pp_left_bracket (pp
);
112 pp
->padding
= pp_none
;
116 pp_c_right_bracket (c_pretty_printer
*pp
)
118 pp_right_bracket (pp
);
119 pp
->padding
= pp_none
;
123 pp_c_dot (c_pretty_printer
*pp
)
126 pp
->padding
= pp_none
;
130 pp_c_ampersand (c_pretty_printer
*pp
)
133 pp
->padding
= pp_none
;
137 pp_c_star (c_pretty_printer
*pp
)
140 pp
->padding
= pp_none
;
144 pp_c_arrow (c_pretty_printer
*pp
)
147 pp
->padding
= pp_none
;
151 pp_c_semicolon (c_pretty_printer
*pp
)
154 pp
->padding
= pp_none
;
158 pp_c_complement (c_pretty_printer
*pp
)
161 pp
->padding
= pp_none
;
165 pp_c_exclamation (c_pretty_printer
*pp
)
168 pp
->padding
= pp_none
;
171 /* Print out the external representation of QUALIFIERS. */
174 pp_c_cv_qualifiers (c_pretty_printer
*pp
, int qualifiers
, bool func_type
)
176 const char *p
= pp_last_position_in_text (pp
);
177 bool previous
= false;
182 /* The C programming language does not have references, but it is much
183 simpler to handle those here rather than going through the same
184 logic in the C++ pretty-printer. */
185 if (p
!= NULL
&& (*p
== '*' || *p
== '&'))
186 pp_c_whitespace (pp
);
188 if (qualifiers
& TYPE_QUAL_ATOMIC
)
190 pp_c_ws_string (pp
, "_Atomic");
194 if (qualifiers
& TYPE_QUAL_CONST
)
197 pp_c_whitespace (pp
);
198 pp_c_ws_string (pp
, func_type
? "__attribute__((const))" : "const");
202 if (qualifiers
& TYPE_QUAL_VOLATILE
)
205 pp_c_whitespace (pp
);
206 pp_c_ws_string (pp
, func_type
? "__attribute__((noreturn))" : "volatile");
210 if (qualifiers
& TYPE_QUAL_RESTRICT
)
213 pp_c_whitespace (pp
);
214 pp_c_ws_string (pp
, (flag_isoc99
&& !c_dialect_cxx ()
215 ? "restrict" : "__restrict__"));
219 /* Pretty-print T using the type-cast notation '( type-name )'. */
222 pp_c_type_cast (c_pretty_printer
*pp
, tree t
)
224 pp_c_left_paren (pp
);
226 pp_c_right_paren (pp
);
229 /* We're about to pretty-print a pointer type as indicated by T.
230 Output a whitespace, if needed, preparing for subsequent output. */
233 pp_c_space_for_pointer_operator (c_pretty_printer
*pp
, tree t
)
235 if (POINTER_TYPE_P (t
))
237 tree pointee
= strip_pointer_operator (TREE_TYPE (t
));
238 if (TREE_CODE (pointee
) != ARRAY_TYPE
239 && TREE_CODE (pointee
) != FUNCTION_TYPE
)
240 pp_c_whitespace (pp
);
247 /* C++ cv-qualifiers are called type-qualifiers in C. Print out the
248 cv-qualifiers of T. If T is a declaration then it is the cv-qualifier
249 of its type. Take care of possible extensions.
253 type-qualifier-list type-qualifier
258 __restrict__ -- GNU C
259 address-space-qualifier -- GNU C
263 address-space-qualifier:
264 identifier -- GNU C */
267 pp_c_type_qualifier_list (c_pretty_printer
*pp
, tree t
)
271 if (!t
|| t
== error_mark_node
)
277 qualifiers
= TYPE_QUALS (t
);
278 pp_c_cv_qualifiers (pp
, qualifiers
,
279 TREE_CODE (t
) == FUNCTION_TYPE
);
281 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (t
)))
283 const char *as
= c_addr_space_name (TYPE_ADDR_SPACE (t
));
284 pp_c_identifier (pp
, as
);
289 * type-qualifier-list(opt)
290 * type-qualifier-list(opt) pointer */
293 pp_c_pointer (c_pretty_printer
*pp
, tree t
)
295 if (!TYPE_P (t
) && TREE_CODE (t
) != TYPE_DECL
)
297 switch (TREE_CODE (t
))
300 /* It is easier to handle C++ reference types here. */
302 if (TREE_CODE (TREE_TYPE (t
)) == POINTER_TYPE
)
303 pp_c_pointer (pp
, TREE_TYPE (t
));
304 if (TREE_CODE (t
) == POINTER_TYPE
)
308 pp_c_type_qualifier_list (pp
, t
);
311 /* ??? This node is now in GENERIC and so shouldn't be here. But
312 we'll fix that later. */
314 pp
->declaration (DECL_EXPR_DECL (t
));
315 pp_needs_newline (pp
) = true;
319 pp_unsupported_tree (pp
, t
);
323 /* simple-type-specifier:
339 struct-or-union-specifier
344 simple-type-specifier:
349 c_pretty_printer::simple_type_specifier (tree t
)
351 const enum tree_code code
= TREE_CODE (t
);
355 translate_string ("<type-error>");
358 case IDENTIFIER_NODE
:
359 pp_c_identifier (this, IDENTIFIER_POINTER (t
));
366 case FIXED_POINT_TYPE
:
370 simple_type_specifier (t
);
374 int prec
= TYPE_PRECISION (t
);
375 if (ALL_FIXED_POINT_MODE_P (TYPE_MODE (t
)))
376 t
= c_common_type_for_mode (TYPE_MODE (t
), TYPE_SATURATING (t
));
378 t
= c_common_type_for_mode (TYPE_MODE (t
), TYPE_UNSIGNED (t
));
381 simple_type_specifier (t
);
382 if (TYPE_PRECISION (t
) != prec
)
385 pp_decimal_int (this, prec
);
393 translate_string (TYPE_UNSIGNED (t
)
394 ? "<unnamed-unsigned:"
395 : "<unnamed-signed:");
398 translate_string ("<unnamed-float:");
400 case FIXED_POINT_TYPE
:
401 translate_string ("<unnamed-fixed:");
406 pp_decimal_int (this, prec
);
416 translate_string ("<typedef-error>");
422 if (TYPE_NAME (t
) && TREE_CODE (TYPE_NAME (t
)) == TYPE_DECL
)
423 /* Don't decorate the type if this is a typedef name. */;
424 else if (code
== UNION_TYPE
)
425 pp_c_ws_string (this, "union");
426 else if (code
== RECORD_TYPE
)
427 pp_c_ws_string (this, "struct");
428 else if (code
== ENUMERAL_TYPE
)
429 pp_c_ws_string (this, "enum");
431 translate_string ("<tag-error>");
434 id_expression (TYPE_NAME (t
));
436 translate_string ("<anonymous>");
440 pp_unsupported_tree (this, t
);
445 /* specifier-qualifier-list:
446 type-specifier specifier-qualifier-list-opt
447 type-qualifier specifier-qualifier-list-opt
450 Implementation note: Because of the non-linearities in array or
451 function declarations, this routine prints not just the
452 specifier-qualifier-list of such entities or types of such entities,
453 but also the 'pointer' production part of their declarators. The
454 remaining part is done by declarator() or abstract_declarator(). */
457 pp_c_specifier_qualifier_list (c_pretty_printer
*pp
, tree t
)
459 const enum tree_code code
= TREE_CODE (t
);
461 if (!(pp
->flags
& pp_c_flag_gnu_v3
) && code
!= POINTER_TYPE
)
462 pp_c_type_qualifier_list (pp
, t
);
468 /* Get the types-specifier of this type. */
469 tree pointee
= strip_pointer_operator (TREE_TYPE (t
));
470 pp_c_specifier_qualifier_list (pp
, pointee
);
471 if (TREE_CODE (pointee
) == ARRAY_TYPE
472 || TREE_CODE (pointee
) == FUNCTION_TYPE
)
474 pp_c_whitespace (pp
);
475 pp_c_left_paren (pp
);
476 pp_c_attributes_display (pp
, TYPE_ATTRIBUTES (pointee
));
478 else if (!c_dialect_cxx ())
479 pp_c_whitespace (pp
);
480 pp_ptr_operator (pp
, t
);
486 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
491 if (code
== COMPLEX_TYPE
)
492 pp_c_ws_string (pp
, (flag_isoc99
&& !c_dialect_cxx ()
493 ? "_Complex" : "__complex__"));
494 else if (code
== VECTOR_TYPE
)
496 pp_c_ws_string (pp
, "__vector");
497 pp_c_left_paren (pp
);
498 pp_wide_integer (pp
, TYPE_VECTOR_SUBPARTS (t
));
499 pp_c_right_paren (pp
);
500 pp_c_whitespace (pp
);
502 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
506 pp
->simple_type_specifier (t
);
509 if ((pp
->flags
& pp_c_flag_gnu_v3
) && code
!= POINTER_TYPE
)
510 pp_c_type_qualifier_list (pp
, t
);
513 /* parameter-type-list:
518 parameter-declaration
519 parameter-list , parameter-declaration
521 parameter-declaration:
522 declaration-specifiers declarator
523 declaration-specifiers abstract-declarator(opt) */
526 pp_c_parameter_type_list (c_pretty_printer
*pp
, tree t
)
528 bool want_parm_decl
= DECL_P (t
) && !(pp
->flags
& pp_c_flag_abstract
);
529 tree parms
= want_parm_decl
? DECL_ARGUMENTS (t
) : TYPE_ARG_TYPES (t
);
530 pp_c_left_paren (pp
);
531 if (parms
== void_list_node
)
532 pp_c_ws_string (pp
, "void");
536 for ( ; parms
&& parms
!= void_list_node
; parms
= TREE_CHAIN (parms
))
539 pp_separate_with (pp
, ',');
541 pp
->declaration_specifiers
542 (want_parm_decl
? parms
: TREE_VALUE (parms
));
544 pp
->declarator (parms
);
546 pp
->abstract_declarator (TREE_VALUE (parms
));
549 pp_c_right_paren (pp
);
552 /* abstract-declarator:
554 pointer(opt) direct-abstract-declarator */
557 c_pretty_printer::abstract_declarator (tree t
)
559 if (TREE_CODE (t
) == POINTER_TYPE
)
561 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
562 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
563 pp_c_right_paren (this);
567 direct_abstract_declarator (t
);
570 /* direct-abstract-declarator:
571 ( abstract-declarator )
572 direct-abstract-declarator(opt) [ assignment-expression(opt) ]
573 direct-abstract-declarator(opt) [ * ]
574 direct-abstract-declarator(opt) ( parameter-type-list(opt) ) */
577 c_pretty_printer::direct_abstract_declarator (tree t
)
579 switch (TREE_CODE (t
))
582 abstract_declarator (t
);
586 pp_c_parameter_type_list (this, t
);
587 direct_abstract_declarator (TREE_TYPE (t
));
591 pp_c_left_bracket (this);
592 if (TYPE_DOMAIN (t
) && TYPE_MAX_VALUE (TYPE_DOMAIN (t
)))
594 tree maxval
= TYPE_MAX_VALUE (TYPE_DOMAIN (t
));
595 tree type
= TREE_TYPE (maxval
);
597 if (tree_fits_shwi_p (maxval
))
598 pp_wide_integer (this, tree_to_shwi (maxval
) + 1);
600 expression (fold_build2 (PLUS_EXPR
, type
, maxval
,
601 build_int_cst (type
, 1)));
603 pp_c_right_bracket (this);
604 direct_abstract_declarator (TREE_TYPE (t
));
607 case IDENTIFIER_NODE
:
612 case FIXED_POINT_TYPE
:
622 pp_unsupported_tree (this, t
);
628 specifier-qualifier-list abstract-declarator(opt) */
631 c_pretty_printer::type_id (tree t
)
633 pp_c_specifier_qualifier_list (this, t
);
634 abstract_declarator (t
);
637 /* storage-class-specifier:
645 c_pretty_printer::storage_class_specifier (tree t
)
647 if (TREE_CODE (t
) == TYPE_DECL
)
648 pp_c_ws_string (this, "typedef");
651 if (DECL_REGISTER (t
))
652 pp_c_ws_string (this, "register");
653 else if (TREE_STATIC (t
) && VAR_P (t
))
654 pp_c_ws_string (this, "static");
658 /* function-specifier:
662 c_pretty_printer::function_specifier (tree t
)
664 if (TREE_CODE (t
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (t
))
665 pp_c_ws_string (this, "inline");
668 /* declaration-specifiers:
669 storage-class-specifier declaration-specifiers(opt)
670 type-specifier declaration-specifiers(opt)
671 type-qualifier declaration-specifiers(opt)
672 function-specifier declaration-specifiers(opt) */
675 c_pretty_printer::declaration_specifiers (tree t
)
677 storage_class_specifier (t
);
678 function_specifier (t
);
679 pp_c_specifier_qualifier_list (this, DECL_P (t
) ? TREE_TYPE (t
) : t
);
685 direct-declarator [ type-qualifier-list(opt) assignment-expression(opt) ]
686 direct-declarator [ static type-qualifier-list(opt) assignment-expression(opt)]
687 direct-declarator [ type-qualifier-list static assignment-expression ]
688 direct-declarator [ type-qualifier-list * ]
689 direct-declarator ( parameter-type-list )
690 direct-declarator ( identifier-list(opt) ) */
693 c_pretty_printer::direct_declarator (tree t
)
695 switch (TREE_CODE (t
))
702 pp_c_space_for_pointer_operator (this, TREE_TYPE (t
));
703 pp_c_tree_decl_identifier (this, t
);
708 abstract_declarator (TREE_TYPE (t
));
712 pp_parameter_list (this, t
);
713 abstract_declarator (TREE_TYPE (t
));
717 pp_c_space_for_pointer_operator (this, TREE_TYPE (TREE_TYPE (t
)));
718 pp_c_tree_decl_identifier (this, t
);
719 if (flags
& pp_c_flag_abstract
)
720 abstract_declarator (TREE_TYPE (t
));
723 pp_parameter_list (this, t
);
724 abstract_declarator (TREE_TYPE (TREE_TYPE (t
)));
730 case FIXED_POINT_TYPE
:
737 pp_unsupported_tree (this, t
);
744 pointer(opt) direct-declarator */
747 c_pretty_printer::declarator (tree t
)
749 switch (TREE_CODE (t
))
753 case FIXED_POINT_TYPE
:
766 direct_declarator (t
);
771 pp_unsupported_tree (this, t
);
777 declaration-specifiers init-declarator-list(opt) ; */
780 c_pretty_printer::declaration (tree t
)
782 declaration_specifiers (t
);
783 pp_c_init_declarator (this, t
);
786 /* Pretty-print ATTRIBUTES using GNU C extension syntax. */
789 pp_c_attributes (c_pretty_printer
*pp
, tree attributes
)
791 if (attributes
== NULL_TREE
)
794 pp_c_ws_string (pp
, "__attribute__");
795 pp_c_left_paren (pp
);
796 pp_c_left_paren (pp
);
797 for (; attributes
!= NULL_TREE
; attributes
= TREE_CHAIN (attributes
))
799 pp_tree_identifier (pp
, TREE_PURPOSE (attributes
));
800 if (TREE_VALUE (attributes
))
801 pp_c_call_argument_list (pp
, TREE_VALUE (attributes
));
803 if (TREE_CHAIN (attributes
))
804 pp_separate_with (pp
, ',');
806 pp_c_right_paren (pp
);
807 pp_c_right_paren (pp
);
810 /* Pretty-print ATTRIBUTES using GNU C extension syntax for attributes
811 marked to be displayed on disgnostic. */
814 pp_c_attributes_display (c_pretty_printer
*pp
, tree a
)
816 bool is_first
= true;
821 for (; a
!= NULL_TREE
; a
= TREE_CHAIN (a
))
823 const struct attribute_spec
*as
;
824 as
= lookup_attribute_spec (TREE_PURPOSE (a
));
825 if (!as
|| as
->affects_type_identity
== false)
829 pp_c_ws_string (pp
, "__attribute__");
830 pp_c_left_paren (pp
);
831 pp_c_left_paren (pp
);
836 pp_separate_with (pp
, ',');
838 pp_tree_identifier (pp
, TREE_PURPOSE (a
));
840 pp_c_call_argument_list (pp
, TREE_VALUE (a
));
845 pp_c_right_paren (pp
);
846 pp_c_right_paren (pp
);
847 pp_c_whitespace (pp
);
851 /* function-definition:
852 declaration-specifiers declarator compound-statement */
855 pp_c_function_definition (c_pretty_printer
*pp
, tree t
)
857 pp
->declaration_specifiers (t
);
859 pp_needs_newline (pp
) = true;
860 pp
->statement (DECL_SAVED_TREE (t
));
861 pp_newline_and_flush (pp
);
867 /* Print out a c-char. This is called solely for characters which are
868 in the *target* execution character set. We ought to convert them
869 back to the *host* execution character set before printing, but we
870 have no way to do this at present. A decent compromise is to print
871 all characters as if they were in the host execution character set,
872 and not attempt to recover any named escape characters, but render
873 all unprintables as octal escapes. If the host and target character
874 sets are the same, this produces relatively readable output. If they
875 are not the same, strings may appear as gibberish, but that's okay
876 (in fact, it may well be what the reader wants, e.g. if they are looking
877 to see if conversion to the target character set happened correctly).
879 A special case: we need to prefix \, ", and ' with backslashes. It is
880 correct to do so for the *host*'s \, ", and ', because the rest of the
881 file appears in the host character set. */
884 pp_c_char (c_pretty_printer
*pp
, int c
)
890 case '\\': pp_string (pp
, "\\\\"); break;
891 case '\'': pp_string (pp
, "\\\'"); break;
892 case '\"': pp_string (pp
, "\\\""); break;
893 default: pp_character (pp
, c
);
897 pp_scalar (pp
, "\\%03o", (unsigned) c
);
900 /* Print out a STRING literal. */
903 pp_c_string_literal (c_pretty_printer
*pp
, tree s
)
905 const char *p
= TREE_STRING_POINTER (s
);
906 int n
= TREE_STRING_LENGTH (s
) - 1;
909 for (i
= 0; i
< n
; ++i
)
910 pp_c_char (pp
, p
[i
]);
914 /* Pretty-print a VOID_CST (void_node). */
917 pp_c_void_constant (c_pretty_printer
*pp
)
919 pp_c_type_cast (pp
, void_type_node
);
923 /* Pretty-print an INTEGER literal. */
926 pp_c_integer_constant (c_pretty_printer
*pp
, tree i
)
930 /* We are going to compare the type of I to other types using
931 pointer comparison so we need to use its canonical type. */
933 TYPE_CANONICAL (TREE_TYPE (i
))
934 ? TYPE_CANONICAL (TREE_TYPE (i
))
937 if (tree_fits_shwi_p (i
))
938 pp_wide_integer (pp
, tree_to_shwi (i
));
939 else if (tree_fits_uhwi_p (i
))
940 pp_unsigned_wide_integer (pp
, tree_to_uhwi (i
));
945 if (wi::lt_p (i
, 0, TYPE_SIGN (TREE_TYPE (i
))))
950 print_hex (wi
, pp_buffer (pp
)->digit_buffer
);
951 pp_string (pp
, pp_buffer (pp
)->digit_buffer
);
953 if (TYPE_UNSIGNED (type
))
954 pp_character (pp
, 'u');
955 if (type
== long_integer_type_node
|| type
== long_unsigned_type_node
)
956 pp_character (pp
, 'l');
957 else if (type
== long_long_integer_type_node
958 || type
== long_long_unsigned_type_node
)
959 pp_string (pp
, "ll");
960 else for (idx
= 0; idx
< NUM_INT_N_ENTS
; idx
++)
961 if (int_n_enabled_p
[idx
])
964 if (type
== int_n_trees
[idx
].signed_type
965 || type
== int_n_trees
[idx
].unsigned_type
)
967 sprintf (buf
, "I%d", int_n_data
[idx
].bitsize
);
973 /* Print out a CHARACTER literal. */
976 pp_c_character_constant (c_pretty_printer
*pp
, tree c
)
979 pp_c_char (pp
, (unsigned) TREE_INT_CST_LOW (c
));
983 /* Print out a BOOLEAN literal. */
986 pp_c_bool_constant (c_pretty_printer
*pp
, tree b
)
988 if (b
== boolean_false_node
)
990 if (c_dialect_cxx ())
991 pp_c_ws_string (pp
, "false");
992 else if (flag_isoc99
)
993 pp_c_ws_string (pp
, "_False");
995 pp_unsupported_tree (pp
, b
);
997 else if (b
== boolean_true_node
)
999 if (c_dialect_cxx ())
1000 pp_c_ws_string (pp
, "true");
1001 else if (flag_isoc99
)
1002 pp_c_ws_string (pp
, "_True");
1004 pp_unsupported_tree (pp
, b
);
1006 else if (TREE_CODE (b
) == INTEGER_CST
)
1007 pp_c_integer_constant (pp
, b
);
1009 pp_unsupported_tree (pp
, b
);
1012 /* Attempt to print out an ENUMERATOR. Return true on success. Else return
1013 false; that means the value was obtained by a cast, in which case
1014 print out the type-id part of the cast-expression -- the casted value
1015 is then printed by pp_c_integer_literal. */
1018 pp_c_enumeration_constant (c_pretty_printer
*pp
, tree e
)
1020 bool value_is_named
= true;
1021 tree type
= TREE_TYPE (e
);
1024 /* Find the name of this constant. */
1025 for (value
= TYPE_VALUES (type
);
1026 value
!= NULL_TREE
&& !tree_int_cst_equal (TREE_VALUE (value
), e
);
1027 value
= TREE_CHAIN (value
))
1030 if (value
!= NULL_TREE
)
1031 pp
->id_expression (TREE_PURPOSE (value
));
1034 /* Value must have been cast. */
1035 pp_c_type_cast (pp
, type
);
1036 value_is_named
= false;
1039 return value_is_named
;
1042 /* Print out a REAL value as a decimal-floating-constant. */
1045 pp_c_floating_constant (c_pretty_printer
*pp
, tree r
)
1047 const struct real_format
*fmt
1048 = REAL_MODE_FORMAT (TYPE_MODE (TREE_TYPE (r
)));
1050 REAL_VALUE_TYPE floating_cst
= TREE_REAL_CST (r
);
1051 bool is_decimal
= floating_cst
.decimal
;
1053 /* See ISO C++ WG N1822. Note: The fraction 643/2136 approximates
1054 log10(2) to 7 significant digits. */
1055 int max_digits10
= 2 + (is_decimal
? fmt
->p
: fmt
->p
* 643L / 2136);
1057 real_to_decimal (pp_buffer (pp
)->digit_buffer
, &TREE_REAL_CST (r
),
1058 sizeof (pp_buffer (pp
)->digit_buffer
),
1061 pp_string (pp
, pp_buffer(pp
)->digit_buffer
);
1062 if (TREE_TYPE (r
) == float_type_node
)
1063 pp_character (pp
, 'f');
1064 else if (TREE_TYPE (r
) == long_double_type_node
)
1065 pp_character (pp
, 'l');
1066 else if (TREE_TYPE (r
) == dfloat128_type_node
)
1067 pp_string (pp
, "dl");
1068 else if (TREE_TYPE (r
) == dfloat64_type_node
)
1069 pp_string (pp
, "dd");
1070 else if (TREE_TYPE (r
) == dfloat32_type_node
)
1071 pp_string (pp
, "df");
1074 /* Print out a FIXED value as a decimal-floating-constant. */
1077 pp_c_fixed_constant (c_pretty_printer
*pp
, tree r
)
1079 fixed_to_decimal (pp_buffer (pp
)->digit_buffer
, &TREE_FIXED_CST (r
),
1080 sizeof (pp_buffer (pp
)->digit_buffer
));
1081 pp_string (pp
, pp_buffer(pp
)->digit_buffer
);
1084 /* Pretty-print a compound literal expression. GNU extensions include
1085 vector constants. */
1088 pp_c_compound_literal (c_pretty_printer
*pp
, tree e
)
1090 tree type
= TREE_TYPE (e
);
1091 pp_c_type_cast (pp
, type
);
1093 switch (TREE_CODE (type
))
1100 pp_c_brace_enclosed_initializer_list (pp
, e
);
1104 pp_unsupported_tree (pp
, e
);
1109 /* Pretty-print a COMPLEX_EXPR expression. */
1112 pp_c_complex_expr (c_pretty_printer
*pp
, tree e
)
1114 /* Handle a few common special cases, otherwise fallback
1115 to printing it as compound literal. */
1116 tree type
= TREE_TYPE (e
);
1117 tree realexpr
= TREE_OPERAND (e
, 0);
1118 tree imagexpr
= TREE_OPERAND (e
, 1);
1120 /* Cast of an COMPLEX_TYPE expression to a different COMPLEX_TYPE. */
1121 if (TREE_CODE (realexpr
) == NOP_EXPR
1122 && TREE_CODE (imagexpr
) == NOP_EXPR
1123 && TREE_TYPE (realexpr
) == TREE_TYPE (type
)
1124 && TREE_TYPE (imagexpr
) == TREE_TYPE (type
)
1125 && TREE_CODE (TREE_OPERAND (realexpr
, 0)) == REALPART_EXPR
1126 && TREE_CODE (TREE_OPERAND (imagexpr
, 0)) == IMAGPART_EXPR
1127 && TREE_OPERAND (TREE_OPERAND (realexpr
, 0), 0)
1128 == TREE_OPERAND (TREE_OPERAND (imagexpr
, 0), 0))
1130 pp_c_type_cast (pp
, type
);
1131 pp
->expression (TREE_OPERAND (TREE_OPERAND (realexpr
, 0), 0));
1135 /* Cast of an scalar expression to COMPLEX_TYPE. */
1136 if ((integer_zerop (imagexpr
) || real_zerop (imagexpr
))
1137 && TREE_TYPE (realexpr
) == TREE_TYPE (type
))
1139 pp_c_type_cast (pp
, type
);
1140 if (TREE_CODE (realexpr
) == NOP_EXPR
)
1141 realexpr
= TREE_OPERAND (realexpr
, 0);
1142 pp
->expression (realexpr
);
1146 pp_c_compound_literal (pp
, e
);
1152 fixed-point-constant
1153 enumeration-constant
1154 character-constant */
1157 c_pretty_printer::constant (tree e
)
1159 const enum tree_code code
= TREE_CODE (e
);
1164 pp_c_void_constant (this);
1169 tree type
= TREE_TYPE (e
);
1170 if (type
== boolean_type_node
)
1171 pp_c_bool_constant (this, e
);
1172 else if (type
== char_type_node
)
1173 pp_c_character_constant (this, e
);
1174 else if (TREE_CODE (type
) == ENUMERAL_TYPE
1175 && pp_c_enumeration_constant (this, e
))
1178 pp_c_integer_constant (this, e
);
1183 pp_c_floating_constant (this, e
);
1187 pp_c_fixed_constant (this, e
);
1191 pp_c_string_literal (this, e
);
1195 /* Sometimes, we are confused and we think a complex literal
1196 is a constant. Such thing is a compound literal which
1197 grammatically belongs to postfix-expr production. */
1198 pp_c_compound_literal (this, e
);
1202 pp_unsupported_tree (this, e
);
1207 /* Pretty-print a string such as an identifier, without changing its
1208 encoding, preceded by whitespace is necessary. */
1211 pp_c_ws_string (c_pretty_printer
*pp
, const char *str
)
1213 pp_c_maybe_whitespace (pp
);
1214 pp_string (pp
, str
);
1215 pp
->padding
= pp_before
;
1219 c_pretty_printer::translate_string (const char *gmsgid
)
1221 if (pp_translate_identifiers (this))
1222 pp_c_ws_string (this, _(gmsgid
));
1224 pp_c_ws_string (this, gmsgid
);
1227 /* Pretty-print an IDENTIFIER_NODE, which may contain UTF-8 sequences
1228 that need converting to the locale encoding, preceded by whitespace
1232 pp_c_identifier (c_pretty_printer
*pp
, const char *id
)
1234 pp_c_maybe_whitespace (pp
);
1235 pp_identifier (pp
, id
);
1236 pp
->padding
= pp_before
;
1239 /* Pretty-print a C primary-expression.
1247 c_pretty_printer::primary_expression (tree e
)
1249 switch (TREE_CODE (e
))
1257 pp_c_tree_decl_identifier (this, e
);
1260 case IDENTIFIER_NODE
:
1261 pp_c_tree_identifier (this, e
);
1265 translate_string ("<erroneous-expression>");
1269 translate_string ("<return-value>");
1281 pp_c_ws_string (this, "__builtin_memcpy");
1282 pp_c_left_paren (this);
1283 pp_ampersand (this);
1284 primary_expression (TREE_OPERAND (e
, 0));
1285 pp_separate_with (this, ',');
1286 pp_ampersand (this);
1287 initializer (TREE_OPERAND (e
, 1));
1288 if (TREE_OPERAND (e
, 2))
1290 pp_separate_with (this, ',');
1291 expression (TREE_OPERAND (e
, 2));
1293 pp_c_right_paren (this);
1297 /* FIXME: Make sure we won't get into an infinite loop. */
1298 pp_c_left_paren (this);
1300 pp_c_right_paren (this);
1305 /* Print out a C initializer -- also support C compound-literals.
1307 assignment-expression:
1308 { initializer-list }
1309 { initializer-list , } */
1312 c_pretty_printer::initializer (tree e
)
1314 if (TREE_CODE (e
) == CONSTRUCTOR
)
1315 pp_c_brace_enclosed_initializer_list (this, e
);
1322 declarator = initializer */
1325 pp_c_init_declarator (c_pretty_printer
*pp
, tree t
)
1328 /* We don't want to output function definitions here. There are handled
1329 elsewhere (and the syntactic form is bogus anyway). */
1330 if (TREE_CODE (t
) != FUNCTION_DECL
&& DECL_INITIAL (t
))
1332 tree init
= DECL_INITIAL (t
);
1333 /* This C++ bit is handled here because it is easier to do so.
1334 In templates, the C++ parser builds a TREE_LIST for a
1335 direct-initialization; the TREE_PURPOSE is the variable to
1336 initialize and the TREE_VALUE is the initializer. */
1337 if (TREE_CODE (init
) == TREE_LIST
)
1339 pp_c_left_paren (pp
);
1340 pp
->expression (TREE_VALUE (init
));
1341 pp_right_paren (pp
);
1348 pp
->initializer (init
);
1353 /* initializer-list:
1354 designation(opt) initializer
1355 initializer-list , designation(opt) initializer
1362 designator-list designator
1365 [ constant-expression ]
1369 pp_c_initializer_list (c_pretty_printer
*pp
, tree e
)
1371 tree type
= TREE_TYPE (e
);
1372 const enum tree_code code
= TREE_CODE (type
);
1374 if (TREE_CODE (e
) == CONSTRUCTOR
)
1376 pp_c_constructor_elts (pp
, CONSTRUCTOR_ELTS (e
));
1386 tree init
= TREE_OPERAND (e
, 0);
1387 for (; init
!= NULL_TREE
; init
= TREE_CHAIN (init
))
1389 if (code
== RECORD_TYPE
|| code
== UNION_TYPE
)
1392 pp
->primary_expression (TREE_PURPOSE (init
));
1396 pp_c_left_bracket (pp
);
1397 if (TREE_PURPOSE (init
))
1398 pp
->constant (TREE_PURPOSE (init
));
1399 pp_c_right_bracket (pp
);
1401 pp_c_whitespace (pp
);
1403 pp_c_whitespace (pp
);
1404 pp
->initializer (TREE_VALUE (init
));
1405 if (TREE_CHAIN (init
))
1406 pp_separate_with (pp
, ',');
1412 if (TREE_CODE (e
) == VECTOR_CST
)
1415 for (i
= 0; i
< VECTOR_CST_NELTS (e
); ++i
)
1418 pp_separate_with (pp
, ',');
1419 pp
->expression (VECTOR_CST_ELT (e
, i
));
1427 if (TREE_CODE (e
) == COMPLEX_CST
|| TREE_CODE (e
) == COMPLEX_EXPR
)
1429 const bool cst
= TREE_CODE (e
) == COMPLEX_CST
;
1430 pp
->expression (cst
? TREE_REALPART (e
) : TREE_OPERAND (e
, 0));
1431 pp_separate_with (pp
, ',');
1432 pp
->expression (cst
? TREE_IMAGPART (e
) : TREE_OPERAND (e
, 1));
1442 pp_unsupported_tree (pp
, type
);
1445 /* Pretty-print a brace-enclosed initializer-list. */
1448 pp_c_brace_enclosed_initializer_list (c_pretty_printer
*pp
, tree l
)
1450 pp_c_left_brace (pp
);
1451 pp_c_initializer_list (pp
, l
);
1452 pp_c_right_brace (pp
);
1456 /* This is a convenient function, used to bridge gap between C and C++
1463 c_pretty_printer::id_expression (tree t
)
1465 switch (TREE_CODE (t
))
1474 pp_c_tree_decl_identifier (this, t
);
1477 case IDENTIFIER_NODE
:
1478 pp_c_tree_identifier (this, t
);
1482 pp_unsupported_tree (this, t
);
1487 /* postfix-expression:
1489 postfix-expression [ expression ]
1490 postfix-expression ( argument-expression-list(opt) )
1491 postfix-expression . identifier
1492 postfix-expression -> identifier
1493 postfix-expression ++
1494 postfix-expression --
1495 ( type-name ) { initializer-list }
1496 ( type-name ) { initializer-list , } */
1499 c_pretty_printer::postfix_expression (tree e
)
1501 enum tree_code code
= TREE_CODE (e
);
1504 case POSTINCREMENT_EXPR
:
1505 case POSTDECREMENT_EXPR
:
1506 postfix_expression (TREE_OPERAND (e
, 0));
1507 pp_string (this, code
== POSTINCREMENT_EXPR
? "++" : "--");
1511 postfix_expression (TREE_OPERAND (e
, 0));
1512 pp_c_left_bracket (this);
1513 expression (TREE_OPERAND (e
, 1));
1514 pp_c_right_bracket (this);
1517 case ARRAY_NOTATION_REF
:
1518 postfix_expression (ARRAY_NOTATION_ARRAY (e
));
1519 pp_c_left_bracket (this);
1520 expression (ARRAY_NOTATION_START (e
));
1522 expression (ARRAY_NOTATION_LENGTH (e
));
1524 expression (ARRAY_NOTATION_STRIDE (e
));
1525 pp_c_right_bracket (this);
1530 call_expr_arg_iterator iter
;
1532 postfix_expression (CALL_EXPR_FN (e
));
1533 pp_c_left_paren (this);
1534 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, e
)
1537 if (more_call_expr_args_p (&iter
))
1538 pp_separate_with (this, ',');
1540 pp_c_right_paren (this);
1544 case UNORDERED_EXPR
:
1545 pp_c_ws_string (this, flag_isoc99
1547 : "__builtin_isunordered");
1551 pp_c_ws_string (this, flag_isoc99
1553 : "!__builtin_isunordered");
1557 pp_c_ws_string (this, flag_isoc99
1559 : "!__builtin_isgreaterequal");
1563 pp_c_ws_string (this, flag_isoc99
1565 : "!__builtin_isgreater");
1569 pp_c_ws_string (this, flag_isoc99
1571 : "!__builtin_islessequal");
1575 pp_c_ws_string (this, flag_isoc99
1577 : "!__builtin_isless");
1581 pp_c_ws_string (this, flag_isoc99
1583 : "!__builtin_islessgreater");
1587 pp_c_ws_string (this, flag_isoc99
1589 : "__builtin_islessgreater");
1593 pp_c_left_paren (this);
1594 expression (TREE_OPERAND (e
, 0));
1595 pp_separate_with (this, ',');
1596 expression (TREE_OPERAND (e
, 1));
1597 pp_c_right_paren (this);
1601 pp_c_ws_string (this, "__builtin_abs");
1602 pp_c_left_paren (this);
1603 expression (TREE_OPERAND (e
, 0));
1604 pp_c_right_paren (this);
1609 tree object
= TREE_OPERAND (e
, 0);
1610 if (INDIRECT_REF_P (object
))
1612 postfix_expression (TREE_OPERAND (object
, 0));
1617 postfix_expression (object
);
1620 expression (TREE_OPERAND (e
, 1));
1626 tree type
= TREE_TYPE (e
);
1628 type
= signed_or_unsigned_type_for (TYPE_UNSIGNED (type
), type
);
1630 && tree_int_cst_equal (TYPE_SIZE (type
), TREE_OPERAND (e
, 1)))
1632 HOST_WIDE_INT bitpos
= tree_to_shwi (TREE_OPERAND (e
, 2));
1633 HOST_WIDE_INT size
= tree_to_shwi (TYPE_SIZE (type
));
1634 if ((bitpos
% size
) == 0)
1636 pp_c_left_paren (this);
1637 pp_c_left_paren (this);
1640 pp_c_right_paren (this);
1641 pp_c_ampersand (this);
1642 expression (TREE_OPERAND (e
, 0));
1643 pp_c_right_paren (this);
1644 pp_c_left_bracket (this);
1645 pp_wide_integer (this, bitpos
/ size
);
1646 pp_c_right_bracket (this);
1650 pp_unsupported_tree (this, e
);
1660 pp_c_compound_literal (this, e
);
1664 pp_c_complex_expr (this, e
);
1667 case COMPOUND_LITERAL_EXPR
:
1668 e
= DECL_INITIAL (COMPOUND_LITERAL_EXPR_DECL (e
));
1675 pp_c_ws_string (this, "__builtin_va_arg");
1676 pp_c_left_paren (this);
1677 assignment_expression (TREE_OPERAND (e
, 0));
1678 pp_separate_with (this, ',');
1679 type_id (TREE_TYPE (e
));
1680 pp_c_right_paren (this);
1684 if (TREE_CODE (TREE_OPERAND (e
, 0)) == FUNCTION_DECL
)
1686 id_expression (TREE_OPERAND (e
, 0));
1689 /* else fall through. */
1692 primary_expression (e
);
1697 /* Print out an expression-list; E is expected to be a TREE_LIST. */
1700 pp_c_expression_list (c_pretty_printer
*pp
, tree e
)
1702 for (; e
!= NULL_TREE
; e
= TREE_CHAIN (e
))
1704 pp
->expression (TREE_VALUE (e
));
1706 pp_separate_with (pp
, ',');
1710 /* Print out V, which contains the elements of a constructor. */
1713 pp_c_constructor_elts (c_pretty_printer
*pp
, vec
<constructor_elt
, va_gc
> *v
)
1715 unsigned HOST_WIDE_INT ix
;
1718 FOR_EACH_CONSTRUCTOR_VALUE (v
, ix
, value
)
1720 pp
->expression (value
);
1721 if (ix
!= vec_safe_length (v
) - 1)
1722 pp_separate_with (pp
, ',');
1726 /* Print out an expression-list in parens, as if it were the argument
1727 list to a function. */
1730 pp_c_call_argument_list (c_pretty_printer
*pp
, tree t
)
1732 pp_c_left_paren (pp
);
1733 if (t
&& TREE_CODE (t
) == TREE_LIST
)
1734 pp_c_expression_list (pp
, t
);
1735 pp_c_right_paren (pp
);
1738 /* unary-expression:
1742 unary-operator cast-expression
1743 sizeof unary-expression
1746 unary-operator: one of
1751 __alignof__ unary-expression
1752 __alignof__ ( type-id )
1753 __real__ unary-expression
1754 __imag__ unary-expression */
1757 c_pretty_printer::unary_expression (tree e
)
1759 enum tree_code code
= TREE_CODE (e
);
1762 case PREINCREMENT_EXPR
:
1763 case PREDECREMENT_EXPR
:
1764 pp_string (this, code
== PREINCREMENT_EXPR
? "++" : "--");
1765 unary_expression (TREE_OPERAND (e
, 0));
1772 case TRUTH_NOT_EXPR
:
1774 /* String literal are used by address. */
1775 if (code
== ADDR_EXPR
&& TREE_CODE (TREE_OPERAND (e
, 0)) != STRING_CST
)
1776 pp_ampersand (this);
1777 else if (code
== INDIRECT_REF
)
1779 else if (code
== NEGATE_EXPR
)
1781 else if (code
== BIT_NOT_EXPR
|| code
== CONJ_EXPR
)
1782 pp_complement (this);
1783 else if (code
== TRUTH_NOT_EXPR
)
1784 pp_exclamation (this);
1785 pp_c_cast_expression (this, TREE_OPERAND (e
, 0));
1789 if (TREE_CODE (TREE_OPERAND (e
, 0)) == ADDR_EXPR
1790 && integer_zerop (TREE_OPERAND (e
, 1)))
1791 expression (TREE_OPERAND (TREE_OPERAND (e
, 0), 0));
1795 if (!integer_zerop (TREE_OPERAND (e
, 1)))
1797 pp_c_left_paren (this);
1798 if (!integer_onep (TYPE_SIZE_UNIT
1799 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (e
, 0))))))
1800 pp_c_type_cast (this, ptr_type_node
);
1802 pp_c_cast_expression (this, TREE_OPERAND (e
, 0));
1803 if (!integer_zerop (TREE_OPERAND (e
, 1)))
1806 pp_c_integer_constant (this,
1807 fold_convert (ssizetype
,
1808 TREE_OPERAND (e
, 1)));
1809 pp_c_right_paren (this);
1816 pp_c_ws_string (this, code
== REALPART_EXPR
? "__real__" : "__imag__");
1817 pp_c_whitespace (this);
1818 unary_expression (TREE_OPERAND (e
, 0));
1822 postfix_expression (e
);
1829 ( type-name ) cast-expression */
1832 pp_c_cast_expression (c_pretty_printer
*pp
, tree e
)
1834 switch (TREE_CODE (e
))
1837 case FIX_TRUNC_EXPR
:
1839 case VIEW_CONVERT_EXPR
:
1840 pp_c_type_cast (pp
, TREE_TYPE (e
));
1841 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 0));
1845 pp
->unary_expression (e
);
1849 /* multiplicative-expression:
1851 multiplicative-expression * cast-expression
1852 multiplicative-expression / cast-expression
1853 multiplicative-expression % cast-expression */
1856 c_pretty_printer::multiplicative_expression (tree e
)
1858 enum tree_code code
= TREE_CODE (e
);
1862 case TRUNC_DIV_EXPR
:
1863 case TRUNC_MOD_EXPR
:
1864 multiplicative_expression (TREE_OPERAND (e
, 0));
1865 pp_c_whitespace (this);
1866 if (code
== MULT_EXPR
)
1868 else if (code
== TRUNC_DIV_EXPR
)
1872 pp_c_whitespace (this);
1873 pp_c_cast_expression (this, TREE_OPERAND (e
, 1));
1877 pp_c_cast_expression (this, e
);
1882 /* additive-expression:
1883 multiplicative-expression
1884 additive-expression + multiplicative-expression
1885 additive-expression - multiplicative-expression */
1888 pp_c_additive_expression (c_pretty_printer
*pp
, tree e
)
1890 enum tree_code code
= TREE_CODE (e
);
1893 case POINTER_PLUS_EXPR
:
1896 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 0));
1897 pp_c_whitespace (pp
);
1898 if (code
== PLUS_EXPR
|| code
== POINTER_PLUS_EXPR
)
1902 pp_c_whitespace (pp
);
1903 pp
->multiplicative_expression (TREE_OPERAND (e
, 1));
1907 pp
->multiplicative_expression (e
);
1912 /* additive-expression:
1914 shift-expression << additive-expression
1915 shift-expression >> additive-expression */
1918 pp_c_shift_expression (c_pretty_printer
*pp
, tree e
)
1920 enum tree_code code
= TREE_CODE (e
);
1925 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 0));
1926 pp_c_whitespace (pp
);
1927 pp_string (pp
, code
== LSHIFT_EXPR
? "<<" : ">>");
1928 pp_c_whitespace (pp
);
1929 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 1));
1933 pp_c_additive_expression (pp
, e
);
1937 /* relational-expression:
1939 relational-expression < shift-expression
1940 relational-expression > shift-expression
1941 relational-expression <= shift-expression
1942 relational-expression >= shift-expression */
1945 pp_c_relational_expression (c_pretty_printer
*pp
, tree e
)
1947 enum tree_code code
= TREE_CODE (e
);
1954 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 0));
1955 pp_c_whitespace (pp
);
1956 if (code
== LT_EXPR
)
1958 else if (code
== GT_EXPR
)
1960 else if (code
== LE_EXPR
)
1962 else if (code
== GE_EXPR
)
1963 pp_greater_equal (pp
);
1964 pp_c_whitespace (pp
);
1965 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 1));
1969 pp_c_shift_expression (pp
, e
);
1974 /* equality-expression:
1975 relational-expression
1976 equality-expression == relational-expression
1977 equality-equality != relational-expression */
1980 pp_c_equality_expression (c_pretty_printer
*pp
, tree e
)
1982 enum tree_code code
= TREE_CODE (e
);
1987 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 0));
1988 pp_c_whitespace (pp
);
1989 pp_string (pp
, code
== EQ_EXPR
? "==" : "!=");
1990 pp_c_whitespace (pp
);
1991 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 1));
1995 pp_c_relational_expression (pp
, e
);
2002 AND-expression & equality-equality */
2005 pp_c_and_expression (c_pretty_printer
*pp
, tree e
)
2007 if (TREE_CODE (e
) == BIT_AND_EXPR
)
2009 pp_c_and_expression (pp
, TREE_OPERAND (e
, 0));
2010 pp_c_whitespace (pp
);
2012 pp_c_whitespace (pp
);
2013 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 1));
2016 pp_c_equality_expression (pp
, e
);
2019 /* exclusive-OR-expression:
2021 exclusive-OR-expression ^ AND-expression */
2024 pp_c_exclusive_or_expression (c_pretty_printer
*pp
, tree e
)
2026 if (TREE_CODE (e
) == BIT_XOR_EXPR
2027 || TREE_CODE (e
) == TRUTH_XOR_EXPR
)
2029 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
2030 if (TREE_CODE (e
) == BIT_XOR_EXPR
)
2031 pp_c_maybe_whitespace (pp
);
2033 pp_c_whitespace (pp
);
2035 pp_c_whitespace (pp
);
2036 pp_c_and_expression (pp
, TREE_OPERAND (e
, 1));
2039 pp_c_and_expression (pp
, e
);
2042 /* inclusive-OR-expression:
2043 exclusive-OR-expression
2044 inclusive-OR-expression | exclusive-OR-expression */
2047 pp_c_inclusive_or_expression (c_pretty_printer
*pp
, tree e
)
2049 if (TREE_CODE (e
) == BIT_IOR_EXPR
)
2051 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
2052 pp_c_whitespace (pp
);
2054 pp_c_whitespace (pp
);
2055 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
2058 pp_c_exclusive_or_expression (pp
, e
);
2061 /* logical-AND-expression:
2062 inclusive-OR-expression
2063 logical-AND-expression && inclusive-OR-expression */
2066 pp_c_logical_and_expression (c_pretty_printer
*pp
, tree e
)
2068 if (TREE_CODE (e
) == TRUTH_ANDIF_EXPR
2069 || TREE_CODE (e
) == TRUTH_AND_EXPR
)
2071 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 0));
2072 pp_c_whitespace (pp
);
2073 pp_ampersand_ampersand (pp
);
2074 pp_c_whitespace (pp
);
2075 pp_c_inclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
2078 pp_c_inclusive_or_expression (pp
, e
);
2081 /* logical-OR-expression:
2082 logical-AND-expression
2083 logical-OR-expression || logical-AND-expression */
2086 pp_c_logical_or_expression (c_pretty_printer
*pp
, tree e
)
2088 if (TREE_CODE (e
) == TRUTH_ORIF_EXPR
2089 || TREE_CODE (e
) == TRUTH_OR_EXPR
)
2091 pp_c_logical_or_expression (pp
, TREE_OPERAND (e
, 0));
2092 pp_c_whitespace (pp
);
2094 pp_c_whitespace (pp
);
2095 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 1));
2098 pp_c_logical_and_expression (pp
, e
);
2101 /* conditional-expression:
2102 logical-OR-expression
2103 logical-OR-expression ? expression : conditional-expression */
2106 c_pretty_printer::conditional_expression (tree e
)
2108 if (TREE_CODE (e
) == COND_EXPR
)
2110 pp_c_logical_or_expression (this, TREE_OPERAND (e
, 0));
2111 pp_c_whitespace (this);
2113 pp_c_whitespace (this);
2114 expression (TREE_OPERAND (e
, 1));
2115 pp_c_whitespace (this);
2117 pp_c_whitespace (this);
2118 conditional_expression (TREE_OPERAND (e
, 2));
2121 pp_c_logical_or_expression (this, e
);
2125 /* assignment-expression:
2126 conditional-expression
2127 unary-expression assignment-operator assignment-expression
2129 assignment-expression: one of
2130 = *= /= %= += -= >>= <<= &= ^= |= */
2133 c_pretty_printer::assignment_expression (tree e
)
2135 if (TREE_CODE (e
) == MODIFY_EXPR
2136 || TREE_CODE (e
) == INIT_EXPR
)
2138 unary_expression (TREE_OPERAND (e
, 0));
2139 pp_c_whitespace (this);
2142 expression (TREE_OPERAND (e
, 1));
2145 conditional_expression (e
);
2149 assignment-expression
2150 expression , assignment-expression
2152 Implementation note: instead of going through the usual recursion
2153 chain, I take the liberty of dispatching nodes to the appropriate
2154 functions. This makes some redundancy, but it worths it. That also
2155 prevents a possible infinite recursion between primary_expression ()
2156 and expression (). */
2159 c_pretty_printer::expression (tree e
)
2161 switch (TREE_CODE (e
))
2164 pp_c_void_constant (this);
2168 pp_c_integer_constant (this, e
);
2172 pp_c_floating_constant (this, e
);
2176 pp_c_fixed_constant (this, e
);
2180 pp_c_string_literal (this, e
);
2183 case IDENTIFIER_NODE
:
2192 primary_expression (e
);
2196 if (SSA_NAME_VAR (e
)
2197 && !DECL_ARTIFICIAL (SSA_NAME_VAR (e
)))
2198 expression (SSA_NAME_VAR (e
));
2200 translate_string ("<unknown>");
2203 case POSTINCREMENT_EXPR
:
2204 case POSTDECREMENT_EXPR
:
2206 case ARRAY_NOTATION_REF
:
2214 case UNORDERED_EXPR
:
2223 case COMPOUND_LITERAL_EXPR
:
2225 postfix_expression (e
);
2234 case TRUTH_NOT_EXPR
:
2235 case PREINCREMENT_EXPR
:
2236 case PREDECREMENT_EXPR
:
2239 unary_expression (e
);
2243 case FIX_TRUNC_EXPR
:
2245 case VIEW_CONVERT_EXPR
:
2246 pp_c_cast_expression (this, e
);
2250 case TRUNC_MOD_EXPR
:
2251 case TRUNC_DIV_EXPR
:
2252 multiplicative_expression (e
);
2257 pp_c_shift_expression (this, e
);
2264 pp_c_relational_expression (this, e
);
2268 pp_c_and_expression (this, e
);
2272 case TRUTH_XOR_EXPR
:
2273 pp_c_exclusive_or_expression (this, e
);
2277 pp_c_inclusive_or_expression (this, e
);
2280 case TRUTH_ANDIF_EXPR
:
2281 case TRUTH_AND_EXPR
:
2282 pp_c_logical_and_expression (this, e
);
2285 case TRUTH_ORIF_EXPR
:
2287 pp_c_logical_or_expression (this, e
);
2292 pp_c_equality_expression (this, e
);
2296 conditional_expression (e
);
2299 case POINTER_PLUS_EXPR
:
2302 pp_c_additive_expression (this, e
);
2307 assignment_expression (e
);
2311 pp_c_left_paren (this);
2312 expression (TREE_OPERAND (e
, 0));
2313 pp_separate_with (this, ',');
2314 assignment_expression (TREE_OPERAND (e
, 1));
2315 pp_c_right_paren (this);
2318 case NON_LVALUE_EXPR
:
2320 expression (TREE_OPERAND (e
, 0));
2324 postfix_expression (TREE_OPERAND (e
, 1));
2329 /* We don't yet have a way of dumping statements in a
2330 human-readable format. */
2331 pp_string (this, "({...})");
2334 case C_MAYBE_CONST_EXPR
:
2335 expression (C_MAYBE_CONST_EXPR_EXPR (e
));
2339 pp_unsupported_tree (this, e
);
2349 c_pretty_printer::statement (tree stmt
)
2354 if (pp_needs_newline (this))
2355 pp_newline_and_indent (this, 0);
2357 dump_generic_node (this, stmt
, pp_indentation (this), 0, true);
2361 /* Initialize the PRETTY-PRINTER for handling C codes. */
2363 c_pretty_printer::c_pretty_printer ()
2364 : pretty_printer (),
2368 type_specifier_seq
= pp_c_specifier_qualifier_list
;
2369 ptr_operator
= pp_c_pointer
;
2370 parameter_list
= pp_c_parameter_type_list
;
2374 /* Print the tree T in full, on file FILE. */
2377 print_c_tree (FILE *file
, tree t
)
2379 c_pretty_printer pp
;
2381 pp_needs_newline (&pp
) = true;
2382 pp
.buffer
->stream
= file
;
2384 pp_newline_and_flush (&pp
);
2387 /* Print the tree T in full, on stderr. */
2390 debug_c_tree (tree t
)
2392 print_c_tree (stderr
, t
);
2393 fputc ('\n', stderr
);
2396 /* Output the DECL_NAME of T. If T has no DECL_NAME, output a string made
2397 up of T's memory address. */
2400 pp_c_tree_decl_identifier (c_pretty_printer
*pp
, tree t
)
2404 gcc_assert (DECL_P (t
));
2407 name
= IDENTIFIER_POINTER (DECL_NAME (t
));
2410 static char xname
[8];
2411 sprintf (xname
, "<U%4x>", ((unsigned)((uintptr_t)(t
) & 0xffff)));
2415 pp_c_identifier (pp
, name
);