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"
26 #include "c-pretty-print.h"
27 #include "diagnostic.h"
29 #include "stor-layout.h"
32 #include "tree-pretty-print.h"
33 #include "tree-iterator.h"
35 /* The pretty-printer code is primarily designed to closely follow
36 (GNU) C and C++ grammars. That is to be contrasted with spaghetti
37 codes we used to have in the past. Following a structured
38 approach (preferably the official grammars) is believed to make it
39 much easier to add extensions and nifty pretty-printing effects that
40 takes expression or declaration contexts into account. */
43 #define pp_c_maybe_whitespace(PP) \
45 if ((PP)->padding == pp_before) \
46 pp_c_whitespace (PP); \
50 static void pp_c_char (c_pretty_printer
*, int);
52 /* postfix-expression */
53 static void pp_c_initializer_list (c_pretty_printer
*, tree
);
54 static void pp_c_brace_enclosed_initializer_list (c_pretty_printer
*, tree
);
56 static void pp_c_additive_expression (c_pretty_printer
*, tree
);
57 static void pp_c_shift_expression (c_pretty_printer
*, tree
);
58 static void pp_c_relational_expression (c_pretty_printer
*, tree
);
59 static void pp_c_equality_expression (c_pretty_printer
*, tree
);
60 static void pp_c_and_expression (c_pretty_printer
*, tree
);
61 static void pp_c_exclusive_or_expression (c_pretty_printer
*, tree
);
62 static void pp_c_inclusive_or_expression (c_pretty_printer
*, tree
);
63 static void pp_c_logical_and_expression (c_pretty_printer
*, tree
);
68 /* Helper functions. */
71 pp_c_whitespace (c_pretty_printer
*pp
)
74 pp
->padding
= pp_none
;
78 pp_c_left_paren (c_pretty_printer
*pp
)
81 pp
->padding
= pp_none
;
85 pp_c_right_paren (c_pretty_printer
*pp
)
88 pp
->padding
= pp_none
;
92 pp_c_left_brace (c_pretty_printer
*pp
)
95 pp
->padding
= pp_none
;
99 pp_c_right_brace (c_pretty_printer
*pp
)
102 pp
->padding
= pp_none
;
106 pp_c_left_bracket (c_pretty_printer
*pp
)
108 pp_left_bracket (pp
);
109 pp
->padding
= pp_none
;
113 pp_c_right_bracket (c_pretty_printer
*pp
)
115 pp_right_bracket (pp
);
116 pp
->padding
= pp_none
;
120 pp_c_dot (c_pretty_printer
*pp
)
123 pp
->padding
= pp_none
;
127 pp_c_ampersand (c_pretty_printer
*pp
)
130 pp
->padding
= pp_none
;
134 pp_c_star (c_pretty_printer
*pp
)
137 pp
->padding
= pp_none
;
141 pp_c_arrow (c_pretty_printer
*pp
)
144 pp
->padding
= pp_none
;
148 pp_c_semicolon (c_pretty_printer
*pp
)
151 pp
->padding
= pp_none
;
155 pp_c_complement (c_pretty_printer
*pp
)
158 pp
->padding
= pp_none
;
162 pp_c_exclamation (c_pretty_printer
*pp
)
165 pp
->padding
= pp_none
;
168 /* Print out the external representation of QUALIFIERS. */
171 pp_c_cv_qualifiers (c_pretty_printer
*pp
, int qualifiers
, bool func_type
)
173 const char *p
= pp_last_position_in_text (pp
);
178 /* The C programming language does not have references, but it is much
179 simpler to handle those here rather than going through the same
180 logic in the C++ pretty-printer. */
181 if (p
!= NULL
&& (*p
== '*' || *p
== '&'))
182 pp_c_whitespace (pp
);
184 if (qualifiers
& TYPE_QUAL_ATOMIC
)
185 pp_c_ws_string (pp
, "_Atomic");
186 if (qualifiers
& TYPE_QUAL_CONST
)
187 pp_c_ws_string (pp
, func_type
? "__attribute__((const))" : "const");
188 if (qualifiers
& TYPE_QUAL_VOLATILE
)
189 pp_c_ws_string (pp
, func_type
? "__attribute__((noreturn))" : "volatile");
190 if (qualifiers
& TYPE_QUAL_RESTRICT
)
191 pp_c_ws_string (pp
, (flag_isoc99
&& !c_dialect_cxx ()
192 ? "restrict" : "__restrict__"));
195 /* Pretty-print T using the type-cast notation '( type-name )'. */
198 pp_c_type_cast (c_pretty_printer
*pp
, tree t
)
200 pp_c_left_paren (pp
);
202 pp_c_right_paren (pp
);
205 /* We're about to pretty-print a pointer type as indicated by T.
206 Output a whitespace, if needed, preparing for subsequent output. */
209 pp_c_space_for_pointer_operator (c_pretty_printer
*pp
, tree t
)
211 if (POINTER_TYPE_P (t
))
213 tree pointee
= strip_pointer_operator (TREE_TYPE (t
));
214 if (TREE_CODE (pointee
) != ARRAY_TYPE
215 && TREE_CODE (pointee
) != FUNCTION_TYPE
)
216 pp_c_whitespace (pp
);
223 /* C++ cv-qualifiers are called type-qualifiers in C. Print out the
224 cv-qualifiers of T. If T is a declaration then it is the cv-qualifier
225 of its type. Take care of possible extensions.
229 type-qualifier-list type-qualifier
234 __restrict__ -- GNU C
235 address-space-qualifier -- GNU C
239 address-space-qualifier:
240 identifier -- GNU C */
243 pp_c_type_qualifier_list (c_pretty_printer
*pp
, tree t
)
247 if (!t
|| t
== error_mark_node
)
253 qualifiers
= TYPE_QUALS (t
);
254 pp_c_cv_qualifiers (pp
, qualifiers
,
255 TREE_CODE (t
) == FUNCTION_TYPE
);
257 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (t
)))
259 const char *as
= c_addr_space_name (TYPE_ADDR_SPACE (t
));
260 pp_c_identifier (pp
, as
);
265 * type-qualifier-list(opt)
266 * type-qualifier-list(opt) pointer */
269 pp_c_pointer (c_pretty_printer
*pp
, tree t
)
271 if (!TYPE_P (t
) && TREE_CODE (t
) != TYPE_DECL
)
273 switch (TREE_CODE (t
))
276 /* It is easier to handle C++ reference types here. */
278 if (TREE_CODE (TREE_TYPE (t
)) == POINTER_TYPE
)
279 pp_c_pointer (pp
, TREE_TYPE (t
));
280 if (TREE_CODE (t
) == POINTER_TYPE
)
284 pp_c_type_qualifier_list (pp
, t
);
287 /* ??? This node is now in GENERIC and so shouldn't be here. But
288 we'll fix that later. */
290 pp
->declaration (DECL_EXPR_DECL (t
));
291 pp_needs_newline (pp
) = true;
295 pp_unsupported_tree (pp
, t
);
299 /* simple-type-specifier:
315 struct-or-union-specifier
320 simple-type-specifier:
325 c_pretty_printer::simple_type_specifier (tree t
)
327 const enum tree_code code
= TREE_CODE (t
);
331 translate_string ("<type-error>");
334 case IDENTIFIER_NODE
:
335 pp_c_identifier (this, IDENTIFIER_POINTER (t
));
342 case FIXED_POINT_TYPE
:
346 simple_type_specifier (t
);
350 int prec
= TYPE_PRECISION (t
);
351 if (ALL_FIXED_POINT_MODE_P (TYPE_MODE (t
)))
352 t
= c_common_type_for_mode (TYPE_MODE (t
), TYPE_SATURATING (t
));
354 t
= c_common_type_for_mode (TYPE_MODE (t
), TYPE_UNSIGNED (t
));
357 simple_type_specifier (t
);
358 if (TYPE_PRECISION (t
) != prec
)
361 pp_decimal_int (this, prec
);
369 translate_string (TYPE_UNSIGNED (t
)
370 ? "<unnamed-unsigned:"
371 : "<unnamed-signed:");
374 translate_string ("<unnamed-float:");
376 case FIXED_POINT_TYPE
:
377 translate_string ("<unnamed-fixed:");
382 pp_decimal_int (this, prec
);
392 translate_string ("<typedef-error>");
398 if (TYPE_NAME (t
) && TREE_CODE (TYPE_NAME (t
)) == TYPE_DECL
)
399 /* Don't decorate the type if this is a typedef name. */;
400 else if (code
== UNION_TYPE
)
401 pp_c_ws_string (this, "union");
402 else if (code
== RECORD_TYPE
)
403 pp_c_ws_string (this, "struct");
404 else if (code
== ENUMERAL_TYPE
)
405 pp_c_ws_string (this, "enum");
407 translate_string ("<tag-error>");
410 id_expression (TYPE_NAME (t
));
412 translate_string ("<anonymous>");
416 pp_unsupported_tree (this, t
);
421 /* specifier-qualifier-list:
422 type-specifier specifier-qualifier-list-opt
423 type-qualifier specifier-qualifier-list-opt
426 Implementation note: Because of the non-linearities in array or
427 function declarations, this routine prints not just the
428 specifier-qualifier-list of such entities or types of such entities,
429 but also the 'pointer' production part of their declarators. The
430 remaining part is done by declarator() or abstract_declarator(). */
433 pp_c_specifier_qualifier_list (c_pretty_printer
*pp
, tree t
)
435 const enum tree_code code
= TREE_CODE (t
);
437 if (!(pp
->flags
& pp_c_flag_gnu_v3
) && code
!= POINTER_TYPE
)
438 pp_c_type_qualifier_list (pp
, t
);
444 /* Get the types-specifier of this type. */
445 tree pointee
= strip_pointer_operator (TREE_TYPE (t
));
446 pp_c_specifier_qualifier_list (pp
, pointee
);
447 if (TREE_CODE (pointee
) == ARRAY_TYPE
448 || TREE_CODE (pointee
) == FUNCTION_TYPE
)
450 pp_c_whitespace (pp
);
451 pp_c_left_paren (pp
);
452 pp_c_attributes_display (pp
, TYPE_ATTRIBUTES (pointee
));
454 else if (!c_dialect_cxx ())
455 pp_c_whitespace (pp
);
456 pp_ptr_operator (pp
, t
);
462 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
467 if (code
== COMPLEX_TYPE
)
468 pp_c_ws_string (pp
, (flag_isoc99
&& !c_dialect_cxx ()
469 ? "_Complex" : "__complex__"));
470 else if (code
== VECTOR_TYPE
)
472 pp_c_ws_string (pp
, "__vector");
473 pp_c_left_paren (pp
);
474 pp_wide_integer (pp
, TYPE_VECTOR_SUBPARTS (t
));
475 pp_c_right_paren (pp
);
476 pp_c_whitespace (pp
);
478 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
482 pp
->simple_type_specifier (t
);
485 if ((pp
->flags
& pp_c_flag_gnu_v3
) && code
!= POINTER_TYPE
)
486 pp_c_type_qualifier_list (pp
, t
);
489 /* parameter-type-list:
494 parameter-declaration
495 parameter-list , parameter-declaration
497 parameter-declaration:
498 declaration-specifiers declarator
499 declaration-specifiers abstract-declarator(opt) */
502 pp_c_parameter_type_list (c_pretty_printer
*pp
, tree t
)
504 bool want_parm_decl
= DECL_P (t
) && !(pp
->flags
& pp_c_flag_abstract
);
505 tree parms
= want_parm_decl
? DECL_ARGUMENTS (t
) : TYPE_ARG_TYPES (t
);
506 pp_c_left_paren (pp
);
507 if (parms
== void_list_node
)
508 pp_c_ws_string (pp
, "void");
512 for ( ; parms
&& parms
!= void_list_node
; parms
= TREE_CHAIN (parms
))
515 pp_separate_with (pp
, ',');
517 pp
->declaration_specifiers
518 (want_parm_decl
? parms
: TREE_VALUE (parms
));
520 pp
->declarator (parms
);
522 pp
->abstract_declarator (TREE_VALUE (parms
));
525 pp_c_right_paren (pp
);
528 /* abstract-declarator:
530 pointer(opt) direct-abstract-declarator */
533 c_pretty_printer::abstract_declarator (tree t
)
535 if (TREE_CODE (t
) == POINTER_TYPE
)
537 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
538 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
539 pp_c_right_paren (this);
543 direct_abstract_declarator (t
);
546 /* direct-abstract-declarator:
547 ( abstract-declarator )
548 direct-abstract-declarator(opt) [ assignment-expression(opt) ]
549 direct-abstract-declarator(opt) [ * ]
550 direct-abstract-declarator(opt) ( parameter-type-list(opt) ) */
553 c_pretty_printer::direct_abstract_declarator (tree t
)
555 switch (TREE_CODE (t
))
558 abstract_declarator (t
);
562 pp_c_parameter_type_list (this, t
);
563 direct_abstract_declarator (TREE_TYPE (t
));
567 pp_c_left_bracket (this);
568 if (TYPE_DOMAIN (t
) && TYPE_MAX_VALUE (TYPE_DOMAIN (t
)))
570 tree maxval
= TYPE_MAX_VALUE (TYPE_DOMAIN (t
));
571 tree type
= TREE_TYPE (maxval
);
573 if (tree_fits_shwi_p (maxval
))
574 pp_wide_integer (this, tree_to_shwi (maxval
) + 1);
576 expression (fold_build2 (PLUS_EXPR
, type
, maxval
,
577 build_int_cst (type
, 1)));
579 pp_c_right_bracket (this);
580 direct_abstract_declarator (TREE_TYPE (t
));
583 case IDENTIFIER_NODE
:
588 case FIXED_POINT_TYPE
:
598 pp_unsupported_tree (this, t
);
604 specifier-qualifier-list abstract-declarator(opt) */
607 c_pretty_printer::type_id (tree t
)
609 pp_c_specifier_qualifier_list (this, t
);
610 abstract_declarator (t
);
613 /* storage-class-specifier:
621 c_pretty_printer::storage_class_specifier (tree t
)
623 if (TREE_CODE (t
) == TYPE_DECL
)
624 pp_c_ws_string (this, "typedef");
627 if (DECL_REGISTER (t
))
628 pp_c_ws_string (this, "register");
629 else if (TREE_STATIC (t
) && VAR_P (t
))
630 pp_c_ws_string (this, "static");
634 /* function-specifier:
638 c_pretty_printer::function_specifier (tree t
)
640 if (TREE_CODE (t
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (t
))
641 pp_c_ws_string (this, "inline");
644 /* declaration-specifiers:
645 storage-class-specifier declaration-specifiers(opt)
646 type-specifier declaration-specifiers(opt)
647 type-qualifier declaration-specifiers(opt)
648 function-specifier declaration-specifiers(opt) */
651 c_pretty_printer::declaration_specifiers (tree t
)
653 storage_class_specifier (t
);
654 function_specifier (t
);
655 pp_c_specifier_qualifier_list (this, DECL_P (t
) ? TREE_TYPE (t
) : t
);
661 direct-declarator [ type-qualifier-list(opt) assignment-expression(opt) ]
662 direct-declarator [ static type-qualifier-list(opt) assignment-expression(opt)]
663 direct-declarator [ type-qualifier-list static assignment-expression ]
664 direct-declarator [ type-qualifier-list * ]
665 direct-declarator ( parameter-type-list )
666 direct-declarator ( identifier-list(opt) ) */
669 c_pretty_printer::direct_declarator (tree t
)
671 switch (TREE_CODE (t
))
678 pp_c_space_for_pointer_operator (this, TREE_TYPE (t
));
679 pp_c_tree_decl_identifier (this, t
);
684 abstract_declarator (TREE_TYPE (t
));
688 pp_parameter_list (this, t
);
689 abstract_declarator (TREE_TYPE (t
));
693 pp_c_space_for_pointer_operator (this, TREE_TYPE (TREE_TYPE (t
)));
694 pp_c_tree_decl_identifier (this, t
);
695 if (flags
& pp_c_flag_abstract
)
696 abstract_declarator (TREE_TYPE (t
));
699 pp_parameter_list (this, t
);
700 abstract_declarator (TREE_TYPE (TREE_TYPE (t
)));
706 case FIXED_POINT_TYPE
:
713 pp_unsupported_tree (this, t
);
720 pointer(opt) direct-declarator */
723 c_pretty_printer::declarator (tree t
)
725 switch (TREE_CODE (t
))
729 case FIXED_POINT_TYPE
:
742 direct_declarator (t
);
747 pp_unsupported_tree (this, t
);
753 declaration-specifiers init-declarator-list(opt) ; */
756 c_pretty_printer::declaration (tree t
)
758 declaration_specifiers (t
);
759 pp_c_init_declarator (this, t
);
762 /* Pretty-print ATTRIBUTES using GNU C extension syntax. */
765 pp_c_attributes (c_pretty_printer
*pp
, tree attributes
)
767 if (attributes
== NULL_TREE
)
770 pp_c_ws_string (pp
, "__attribute__");
771 pp_c_left_paren (pp
);
772 pp_c_left_paren (pp
);
773 for (; attributes
!= NULL_TREE
; attributes
= TREE_CHAIN (attributes
))
775 pp_tree_identifier (pp
, TREE_PURPOSE (attributes
));
776 if (TREE_VALUE (attributes
))
777 pp_c_call_argument_list (pp
, TREE_VALUE (attributes
));
779 if (TREE_CHAIN (attributes
))
780 pp_separate_with (pp
, ',');
782 pp_c_right_paren (pp
);
783 pp_c_right_paren (pp
);
786 /* Pretty-print ATTRIBUTES using GNU C extension syntax for attributes
787 marked to be displayed on disgnostic. */
790 pp_c_attributes_display (c_pretty_printer
*pp
, tree a
)
792 bool is_first
= true;
797 for (; a
!= NULL_TREE
; a
= TREE_CHAIN (a
))
799 const struct attribute_spec
*as
;
800 as
= lookup_attribute_spec (TREE_PURPOSE (a
));
801 if (!as
|| as
->affects_type_identity
== false)
804 && !strcmp ("transaction_safe", as
->name
))
805 /* In C++ transaction_safe is printed at the end of the declarator. */
809 pp_c_ws_string (pp
, "__attribute__");
810 pp_c_left_paren (pp
);
811 pp_c_left_paren (pp
);
816 pp_separate_with (pp
, ',');
818 pp_tree_identifier (pp
, TREE_PURPOSE (a
));
820 pp_c_call_argument_list (pp
, TREE_VALUE (a
));
825 pp_c_right_paren (pp
);
826 pp_c_right_paren (pp
);
827 pp_c_whitespace (pp
);
831 /* function-definition:
832 declaration-specifiers declarator compound-statement */
835 pp_c_function_definition (c_pretty_printer
*pp
, tree t
)
837 pp
->declaration_specifiers (t
);
839 pp_needs_newline (pp
) = true;
840 pp
->statement (DECL_SAVED_TREE (t
));
841 pp_newline_and_flush (pp
);
847 /* Print out a c-char. This is called solely for characters which are
848 in the *target* execution character set. We ought to convert them
849 back to the *host* execution character set before printing, but we
850 have no way to do this at present. A decent compromise is to print
851 all characters as if they were in the host execution character set,
852 and not attempt to recover any named escape characters, but render
853 all unprintables as octal escapes. If the host and target character
854 sets are the same, this produces relatively readable output. If they
855 are not the same, strings may appear as gibberish, but that's okay
856 (in fact, it may well be what the reader wants, e.g. if they are looking
857 to see if conversion to the target character set happened correctly).
859 A special case: we need to prefix \, ", and ' with backslashes. It is
860 correct to do so for the *host*'s \, ", and ', because the rest of the
861 file appears in the host character set. */
864 pp_c_char (c_pretty_printer
*pp
, int c
)
870 case '\\': pp_string (pp
, "\\\\"); break;
871 case '\'': pp_string (pp
, "\\\'"); break;
872 case '\"': pp_string (pp
, "\\\""); break;
873 default: pp_character (pp
, c
);
877 pp_scalar (pp
, "\\%03o", (unsigned) c
);
880 /* Print out a STRING literal. */
883 pp_c_string_literal (c_pretty_printer
*pp
, tree s
)
885 const char *p
= TREE_STRING_POINTER (s
);
886 int n
= TREE_STRING_LENGTH (s
) - 1;
889 for (i
= 0; i
< n
; ++i
)
890 pp_c_char (pp
, p
[i
]);
894 /* Pretty-print a VOID_CST (void_node). */
897 pp_c_void_constant (c_pretty_printer
*pp
)
899 pp_c_type_cast (pp
, void_type_node
);
903 /* Pretty-print an INTEGER literal. */
906 pp_c_integer_constant (c_pretty_printer
*pp
, tree i
)
910 /* We are going to compare the type of I to other types using
911 pointer comparison so we need to use its canonical type. */
913 TYPE_CANONICAL (TREE_TYPE (i
))
914 ? TYPE_CANONICAL (TREE_TYPE (i
))
917 if (tree_fits_shwi_p (i
))
918 pp_wide_integer (pp
, tree_to_shwi (i
));
919 else if (tree_fits_uhwi_p (i
))
920 pp_unsigned_wide_integer (pp
, tree_to_uhwi (i
));
925 if (wi::lt_p (i
, 0, TYPE_SIGN (TREE_TYPE (i
))))
930 print_hex (wi
, pp_buffer (pp
)->digit_buffer
);
931 pp_string (pp
, pp_buffer (pp
)->digit_buffer
);
933 if (TYPE_UNSIGNED (type
))
934 pp_character (pp
, 'u');
935 if (type
== long_integer_type_node
|| type
== long_unsigned_type_node
)
936 pp_character (pp
, 'l');
937 else if (type
== long_long_integer_type_node
938 || type
== long_long_unsigned_type_node
)
939 pp_string (pp
, "ll");
940 else for (idx
= 0; idx
< NUM_INT_N_ENTS
; idx
++)
941 if (int_n_enabled_p
[idx
])
944 if (type
== int_n_trees
[idx
].signed_type
945 || type
== int_n_trees
[idx
].unsigned_type
)
947 sprintf (buf
, "I%d", int_n_data
[idx
].bitsize
);
953 /* Print out a CHARACTER literal. */
956 pp_c_character_constant (c_pretty_printer
*pp
, tree c
)
959 pp_c_char (pp
, (unsigned) TREE_INT_CST_LOW (c
));
963 /* Print out a BOOLEAN literal. */
966 pp_c_bool_constant (c_pretty_printer
*pp
, tree b
)
968 if (b
== boolean_false_node
)
970 if (c_dialect_cxx ())
971 pp_c_ws_string (pp
, "false");
972 else if (flag_isoc99
)
973 pp_c_ws_string (pp
, "_False");
975 pp_unsupported_tree (pp
, b
);
977 else if (b
== boolean_true_node
)
979 if (c_dialect_cxx ())
980 pp_c_ws_string (pp
, "true");
981 else if (flag_isoc99
)
982 pp_c_ws_string (pp
, "_True");
984 pp_unsupported_tree (pp
, b
);
986 else if (TREE_CODE (b
) == INTEGER_CST
)
987 pp_c_integer_constant (pp
, b
);
989 pp_unsupported_tree (pp
, b
);
992 /* Attempt to print out an ENUMERATOR. Return true on success. Else return
993 false; that means the value was obtained by a cast, in which case
994 print out the type-id part of the cast-expression -- the casted value
995 is then printed by pp_c_integer_literal. */
998 pp_c_enumeration_constant (c_pretty_printer
*pp
, tree e
)
1000 bool value_is_named
= true;
1001 tree type
= TREE_TYPE (e
);
1004 /* Find the name of this constant. */
1005 for (value
= TYPE_VALUES (type
);
1006 value
!= NULL_TREE
&& !tree_int_cst_equal (TREE_VALUE (value
), e
);
1007 value
= TREE_CHAIN (value
))
1010 if (value
!= NULL_TREE
)
1011 pp
->id_expression (TREE_PURPOSE (value
));
1014 /* Value must have been cast. */
1015 pp_c_type_cast (pp
, type
);
1016 value_is_named
= false;
1019 return value_is_named
;
1022 /* Print out a REAL value as a decimal-floating-constant. */
1025 pp_c_floating_constant (c_pretty_printer
*pp
, tree r
)
1027 const struct real_format
*fmt
1028 = REAL_MODE_FORMAT (TYPE_MODE (TREE_TYPE (r
)));
1030 REAL_VALUE_TYPE floating_cst
= TREE_REAL_CST (r
);
1031 bool is_decimal
= floating_cst
.decimal
;
1033 /* See ISO C++ WG N1822. Note: The fraction 643/2136 approximates
1034 log10(2) to 7 significant digits. */
1035 int max_digits10
= 2 + (is_decimal
? fmt
->p
: fmt
->p
* 643L / 2136);
1037 real_to_decimal (pp_buffer (pp
)->digit_buffer
, &TREE_REAL_CST (r
),
1038 sizeof (pp_buffer (pp
)->digit_buffer
),
1041 pp_string (pp
, pp_buffer(pp
)->digit_buffer
);
1042 if (TREE_TYPE (r
) == float_type_node
)
1043 pp_character (pp
, 'f');
1044 else if (TREE_TYPE (r
) == long_double_type_node
)
1045 pp_character (pp
, 'l');
1046 else if (TREE_TYPE (r
) == dfloat128_type_node
)
1047 pp_string (pp
, "dl");
1048 else if (TREE_TYPE (r
) == dfloat64_type_node
)
1049 pp_string (pp
, "dd");
1050 else if (TREE_TYPE (r
) == dfloat32_type_node
)
1051 pp_string (pp
, "df");
1054 /* Print out a FIXED value as a decimal-floating-constant. */
1057 pp_c_fixed_constant (c_pretty_printer
*pp
, tree r
)
1059 fixed_to_decimal (pp_buffer (pp
)->digit_buffer
, &TREE_FIXED_CST (r
),
1060 sizeof (pp_buffer (pp
)->digit_buffer
));
1061 pp_string (pp
, pp_buffer(pp
)->digit_buffer
);
1064 /* Pretty-print a compound literal expression. GNU extensions include
1065 vector constants. */
1068 pp_c_compound_literal (c_pretty_printer
*pp
, tree e
)
1070 tree type
= TREE_TYPE (e
);
1071 pp_c_type_cast (pp
, type
);
1073 switch (TREE_CODE (type
))
1080 pp_c_brace_enclosed_initializer_list (pp
, e
);
1084 pp_unsupported_tree (pp
, e
);
1089 /* Pretty-print a COMPLEX_EXPR expression. */
1092 pp_c_complex_expr (c_pretty_printer
*pp
, tree e
)
1094 /* Handle a few common special cases, otherwise fallback
1095 to printing it as compound literal. */
1096 tree type
= TREE_TYPE (e
);
1097 tree realexpr
= TREE_OPERAND (e
, 0);
1098 tree imagexpr
= TREE_OPERAND (e
, 1);
1100 /* Cast of an COMPLEX_TYPE expression to a different COMPLEX_TYPE. */
1101 if (TREE_CODE (realexpr
) == NOP_EXPR
1102 && TREE_CODE (imagexpr
) == NOP_EXPR
1103 && TREE_TYPE (realexpr
) == TREE_TYPE (type
)
1104 && TREE_TYPE (imagexpr
) == TREE_TYPE (type
)
1105 && TREE_CODE (TREE_OPERAND (realexpr
, 0)) == REALPART_EXPR
1106 && TREE_CODE (TREE_OPERAND (imagexpr
, 0)) == IMAGPART_EXPR
1107 && TREE_OPERAND (TREE_OPERAND (realexpr
, 0), 0)
1108 == TREE_OPERAND (TREE_OPERAND (imagexpr
, 0), 0))
1110 pp_c_type_cast (pp
, type
);
1111 pp
->expression (TREE_OPERAND (TREE_OPERAND (realexpr
, 0), 0));
1115 /* Cast of an scalar expression to COMPLEX_TYPE. */
1116 if ((integer_zerop (imagexpr
) || real_zerop (imagexpr
))
1117 && TREE_TYPE (realexpr
) == TREE_TYPE (type
))
1119 pp_c_type_cast (pp
, type
);
1120 if (TREE_CODE (realexpr
) == NOP_EXPR
)
1121 realexpr
= TREE_OPERAND (realexpr
, 0);
1122 pp
->expression (realexpr
);
1126 pp_c_compound_literal (pp
, e
);
1132 fixed-point-constant
1133 enumeration-constant
1134 character-constant */
1137 c_pretty_printer::constant (tree e
)
1139 const enum tree_code code
= TREE_CODE (e
);
1144 pp_c_void_constant (this);
1149 tree type
= TREE_TYPE (e
);
1150 if (type
== boolean_type_node
)
1151 pp_c_bool_constant (this, e
);
1152 else if (type
== char_type_node
)
1153 pp_c_character_constant (this, e
);
1154 else if (TREE_CODE (type
) == ENUMERAL_TYPE
1155 && pp_c_enumeration_constant (this, e
))
1158 pp_c_integer_constant (this, e
);
1163 pp_c_floating_constant (this, e
);
1167 pp_c_fixed_constant (this, e
);
1171 pp_c_string_literal (this, e
);
1175 /* Sometimes, we are confused and we think a complex literal
1176 is a constant. Such thing is a compound literal which
1177 grammatically belongs to postfix-expr production. */
1178 pp_c_compound_literal (this, e
);
1182 pp_unsupported_tree (this, e
);
1187 /* Pretty-print a string such as an identifier, without changing its
1188 encoding, preceded by whitespace is necessary. */
1191 pp_c_ws_string (c_pretty_printer
*pp
, const char *str
)
1193 pp_c_maybe_whitespace (pp
);
1194 pp_string (pp
, str
);
1195 pp
->padding
= pp_before
;
1199 c_pretty_printer::translate_string (const char *gmsgid
)
1201 if (pp_translate_identifiers (this))
1202 pp_c_ws_string (this, _(gmsgid
));
1204 pp_c_ws_string (this, gmsgid
);
1207 /* Pretty-print an IDENTIFIER_NODE, which may contain UTF-8 sequences
1208 that need converting to the locale encoding, preceded by whitespace
1212 pp_c_identifier (c_pretty_printer
*pp
, const char *id
)
1214 pp_c_maybe_whitespace (pp
);
1215 pp_identifier (pp
, id
);
1216 pp
->padding
= pp_before
;
1219 /* Pretty-print a C primary-expression.
1227 c_pretty_printer::primary_expression (tree e
)
1229 switch (TREE_CODE (e
))
1237 pp_c_tree_decl_identifier (this, e
);
1240 case IDENTIFIER_NODE
:
1241 pp_c_tree_identifier (this, e
);
1245 translate_string ("<erroneous-expression>");
1249 translate_string ("<return-value>");
1261 pp_c_ws_string (this, "__builtin_memcpy");
1262 pp_c_left_paren (this);
1263 pp_ampersand (this);
1264 primary_expression (TREE_OPERAND (e
, 0));
1265 pp_separate_with (this, ',');
1266 pp_ampersand (this);
1267 initializer (TREE_OPERAND (e
, 1));
1268 if (TREE_OPERAND (e
, 2))
1270 pp_separate_with (this, ',');
1271 expression (TREE_OPERAND (e
, 2));
1273 pp_c_right_paren (this);
1277 /* FIXME: Make sure we won't get into an infinite loop. */
1278 pp_c_left_paren (this);
1280 pp_c_right_paren (this);
1285 /* Print out a C initializer -- also support C compound-literals.
1287 assignment-expression:
1288 { initializer-list }
1289 { initializer-list , } */
1292 c_pretty_printer::initializer (tree e
)
1294 if (TREE_CODE (e
) == CONSTRUCTOR
)
1295 pp_c_brace_enclosed_initializer_list (this, e
);
1302 declarator = initializer */
1305 pp_c_init_declarator (c_pretty_printer
*pp
, tree t
)
1308 /* We don't want to output function definitions here. There are handled
1309 elsewhere (and the syntactic form is bogus anyway). */
1310 if (TREE_CODE (t
) != FUNCTION_DECL
&& DECL_INITIAL (t
))
1312 tree init
= DECL_INITIAL (t
);
1313 /* This C++ bit is handled here because it is easier to do so.
1314 In templates, the C++ parser builds a TREE_LIST for a
1315 direct-initialization; the TREE_PURPOSE is the variable to
1316 initialize and the TREE_VALUE is the initializer. */
1317 if (TREE_CODE (init
) == TREE_LIST
)
1319 pp_c_left_paren (pp
);
1320 pp
->expression (TREE_VALUE (init
));
1321 pp_right_paren (pp
);
1328 pp
->initializer (init
);
1333 /* initializer-list:
1334 designation(opt) initializer
1335 initializer-list , designation(opt) initializer
1342 designator-list designator
1345 [ constant-expression ]
1349 pp_c_initializer_list (c_pretty_printer
*pp
, tree e
)
1351 tree type
= TREE_TYPE (e
);
1352 const enum tree_code code
= TREE_CODE (type
);
1354 if (TREE_CODE (e
) == CONSTRUCTOR
)
1356 pp_c_constructor_elts (pp
, CONSTRUCTOR_ELTS (e
));
1366 tree init
= TREE_OPERAND (e
, 0);
1367 for (; init
!= NULL_TREE
; init
= TREE_CHAIN (init
))
1369 if (code
== RECORD_TYPE
|| code
== UNION_TYPE
)
1372 pp
->primary_expression (TREE_PURPOSE (init
));
1376 pp_c_left_bracket (pp
);
1377 if (TREE_PURPOSE (init
))
1378 pp
->constant (TREE_PURPOSE (init
));
1379 pp_c_right_bracket (pp
);
1381 pp_c_whitespace (pp
);
1383 pp_c_whitespace (pp
);
1384 pp
->initializer (TREE_VALUE (init
));
1385 if (TREE_CHAIN (init
))
1386 pp_separate_with (pp
, ',');
1392 if (TREE_CODE (e
) == VECTOR_CST
)
1395 for (i
= 0; i
< VECTOR_CST_NELTS (e
); ++i
)
1398 pp_separate_with (pp
, ',');
1399 pp
->expression (VECTOR_CST_ELT (e
, i
));
1407 if (TREE_CODE (e
) == COMPLEX_CST
|| TREE_CODE (e
) == COMPLEX_EXPR
)
1409 const bool cst
= TREE_CODE (e
) == COMPLEX_CST
;
1410 pp
->expression (cst
? TREE_REALPART (e
) : TREE_OPERAND (e
, 0));
1411 pp_separate_with (pp
, ',');
1412 pp
->expression (cst
? TREE_IMAGPART (e
) : TREE_OPERAND (e
, 1));
1422 pp_unsupported_tree (pp
, type
);
1425 /* Pretty-print a brace-enclosed initializer-list. */
1428 pp_c_brace_enclosed_initializer_list (c_pretty_printer
*pp
, tree l
)
1430 pp_c_left_brace (pp
);
1431 pp_c_initializer_list (pp
, l
);
1432 pp_c_right_brace (pp
);
1436 /* This is a convenient function, used to bridge gap between C and C++
1443 c_pretty_printer::id_expression (tree t
)
1445 switch (TREE_CODE (t
))
1454 pp_c_tree_decl_identifier (this, t
);
1457 case IDENTIFIER_NODE
:
1458 pp_c_tree_identifier (this, t
);
1462 pp_unsupported_tree (this, t
);
1467 /* postfix-expression:
1469 postfix-expression [ expression ]
1470 postfix-expression ( argument-expression-list(opt) )
1471 postfix-expression . identifier
1472 postfix-expression -> identifier
1473 postfix-expression ++
1474 postfix-expression --
1475 ( type-name ) { initializer-list }
1476 ( type-name ) { initializer-list , } */
1479 c_pretty_printer::postfix_expression (tree e
)
1481 enum tree_code code
= TREE_CODE (e
);
1484 case POSTINCREMENT_EXPR
:
1485 case POSTDECREMENT_EXPR
:
1486 postfix_expression (TREE_OPERAND (e
, 0));
1487 pp_string (this, code
== POSTINCREMENT_EXPR
? "++" : "--");
1491 postfix_expression (TREE_OPERAND (e
, 0));
1492 pp_c_left_bracket (this);
1493 expression (TREE_OPERAND (e
, 1));
1494 pp_c_right_bracket (this);
1497 case ARRAY_NOTATION_REF
:
1498 postfix_expression (ARRAY_NOTATION_ARRAY (e
));
1499 pp_c_left_bracket (this);
1500 expression (ARRAY_NOTATION_START (e
));
1502 expression (ARRAY_NOTATION_LENGTH (e
));
1504 expression (ARRAY_NOTATION_STRIDE (e
));
1505 pp_c_right_bracket (this);
1510 call_expr_arg_iterator iter
;
1512 postfix_expression (CALL_EXPR_FN (e
));
1513 pp_c_left_paren (this);
1514 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, e
)
1517 if (more_call_expr_args_p (&iter
))
1518 pp_separate_with (this, ',');
1520 pp_c_right_paren (this);
1524 case UNORDERED_EXPR
:
1525 pp_c_ws_string (this, flag_isoc99
1527 : "__builtin_isunordered");
1531 pp_c_ws_string (this, flag_isoc99
1533 : "!__builtin_isunordered");
1537 pp_c_ws_string (this, flag_isoc99
1539 : "!__builtin_isgreaterequal");
1543 pp_c_ws_string (this, flag_isoc99
1545 : "!__builtin_isgreater");
1549 pp_c_ws_string (this, flag_isoc99
1551 : "!__builtin_islessequal");
1555 pp_c_ws_string (this, flag_isoc99
1557 : "!__builtin_isless");
1561 pp_c_ws_string (this, flag_isoc99
1563 : "!__builtin_islessgreater");
1567 pp_c_ws_string (this, flag_isoc99
1569 : "__builtin_islessgreater");
1573 pp_c_left_paren (this);
1574 expression (TREE_OPERAND (e
, 0));
1575 pp_separate_with (this, ',');
1576 expression (TREE_OPERAND (e
, 1));
1577 pp_c_right_paren (this);
1581 pp_c_ws_string (this, "__builtin_abs");
1582 pp_c_left_paren (this);
1583 expression (TREE_OPERAND (e
, 0));
1584 pp_c_right_paren (this);
1589 tree object
= TREE_OPERAND (e
, 0);
1590 if (INDIRECT_REF_P (object
))
1592 postfix_expression (TREE_OPERAND (object
, 0));
1597 postfix_expression (object
);
1600 expression (TREE_OPERAND (e
, 1));
1606 tree type
= TREE_TYPE (e
);
1608 type
= signed_or_unsigned_type_for (TYPE_UNSIGNED (type
), type
);
1610 && tree_int_cst_equal (TYPE_SIZE (type
), TREE_OPERAND (e
, 1)))
1612 HOST_WIDE_INT bitpos
= tree_to_shwi (TREE_OPERAND (e
, 2));
1613 HOST_WIDE_INT size
= tree_to_shwi (TYPE_SIZE (type
));
1614 if ((bitpos
% size
) == 0)
1616 pp_c_left_paren (this);
1617 pp_c_left_paren (this);
1620 pp_c_right_paren (this);
1621 pp_c_ampersand (this);
1622 expression (TREE_OPERAND (e
, 0));
1623 pp_c_right_paren (this);
1624 pp_c_left_bracket (this);
1625 pp_wide_integer (this, bitpos
/ size
);
1626 pp_c_right_bracket (this);
1630 pp_unsupported_tree (this, e
);
1640 pp_c_compound_literal (this, e
);
1644 pp_c_complex_expr (this, e
);
1647 case COMPOUND_LITERAL_EXPR
:
1648 e
= DECL_INITIAL (COMPOUND_LITERAL_EXPR_DECL (e
));
1655 pp_c_ws_string (this, "__builtin_va_arg");
1656 pp_c_left_paren (this);
1657 assignment_expression (TREE_OPERAND (e
, 0));
1658 pp_separate_with (this, ',');
1659 type_id (TREE_TYPE (e
));
1660 pp_c_right_paren (this);
1664 if (TREE_CODE (TREE_OPERAND (e
, 0)) == FUNCTION_DECL
)
1666 id_expression (TREE_OPERAND (e
, 0));
1669 /* else fall through. */
1672 primary_expression (e
);
1677 /* Print out an expression-list; E is expected to be a TREE_LIST. */
1680 pp_c_expression_list (c_pretty_printer
*pp
, tree e
)
1682 for (; e
!= NULL_TREE
; e
= TREE_CHAIN (e
))
1684 pp
->expression (TREE_VALUE (e
));
1686 pp_separate_with (pp
, ',');
1690 /* Print out V, which contains the elements of a constructor. */
1693 pp_c_constructor_elts (c_pretty_printer
*pp
, vec
<constructor_elt
, va_gc
> *v
)
1695 unsigned HOST_WIDE_INT ix
;
1698 FOR_EACH_CONSTRUCTOR_VALUE (v
, ix
, value
)
1700 pp
->expression (value
);
1701 if (ix
!= vec_safe_length (v
) - 1)
1702 pp_separate_with (pp
, ',');
1706 /* Print out an expression-list in parens, as if it were the argument
1707 list to a function. */
1710 pp_c_call_argument_list (c_pretty_printer
*pp
, tree t
)
1712 pp_c_left_paren (pp
);
1713 if (t
&& TREE_CODE (t
) == TREE_LIST
)
1714 pp_c_expression_list (pp
, t
);
1715 pp_c_right_paren (pp
);
1718 /* unary-expression:
1722 unary-operator cast-expression
1723 sizeof unary-expression
1726 unary-operator: one of
1731 __alignof__ unary-expression
1732 __alignof__ ( type-id )
1733 __real__ unary-expression
1734 __imag__ unary-expression */
1737 c_pretty_printer::unary_expression (tree e
)
1739 enum tree_code code
= TREE_CODE (e
);
1742 case PREINCREMENT_EXPR
:
1743 case PREDECREMENT_EXPR
:
1744 pp_string (this, code
== PREINCREMENT_EXPR
? "++" : "--");
1745 unary_expression (TREE_OPERAND (e
, 0));
1752 case TRUTH_NOT_EXPR
:
1754 /* String literal are used by address. */
1755 if (code
== ADDR_EXPR
&& TREE_CODE (TREE_OPERAND (e
, 0)) != STRING_CST
)
1756 pp_ampersand (this);
1757 else if (code
== INDIRECT_REF
)
1759 tree type
= TREE_TYPE (TREE_OPERAND (e
, 0));
1760 if (type
&& TREE_CODE (type
) == REFERENCE_TYPE
)
1761 /* Reference decay is implicit, don't print anything. */;
1765 else if (code
== NEGATE_EXPR
)
1767 else if (code
== BIT_NOT_EXPR
|| code
== CONJ_EXPR
)
1768 pp_complement (this);
1769 else if (code
== TRUTH_NOT_EXPR
)
1770 pp_exclamation (this);
1771 pp_c_cast_expression (this, TREE_OPERAND (e
, 0));
1775 if (TREE_CODE (TREE_OPERAND (e
, 0)) == ADDR_EXPR
1776 && integer_zerop (TREE_OPERAND (e
, 1)))
1777 expression (TREE_OPERAND (TREE_OPERAND (e
, 0), 0));
1781 if (!integer_zerop (TREE_OPERAND (e
, 1)))
1783 pp_c_left_paren (this);
1784 if (!integer_onep (TYPE_SIZE_UNIT
1785 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (e
, 0))))))
1786 pp_c_type_cast (this, ptr_type_node
);
1788 pp_c_cast_expression (this, TREE_OPERAND (e
, 0));
1789 if (!integer_zerop (TREE_OPERAND (e
, 1)))
1792 pp_c_integer_constant (this,
1793 fold_convert (ssizetype
,
1794 TREE_OPERAND (e
, 1)));
1795 pp_c_right_paren (this);
1802 pp_c_ws_string (this, code
== REALPART_EXPR
? "__real__" : "__imag__");
1803 pp_c_whitespace (this);
1804 unary_expression (TREE_OPERAND (e
, 0));
1808 postfix_expression (e
);
1815 ( type-name ) cast-expression */
1818 pp_c_cast_expression (c_pretty_printer
*pp
, tree e
)
1820 switch (TREE_CODE (e
))
1823 case FIX_TRUNC_EXPR
:
1825 case VIEW_CONVERT_EXPR
:
1826 pp_c_type_cast (pp
, TREE_TYPE (e
));
1827 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 0));
1831 pp
->unary_expression (e
);
1835 /* multiplicative-expression:
1837 multiplicative-expression * cast-expression
1838 multiplicative-expression / cast-expression
1839 multiplicative-expression % cast-expression */
1842 c_pretty_printer::multiplicative_expression (tree e
)
1844 enum tree_code code
= TREE_CODE (e
);
1848 case TRUNC_DIV_EXPR
:
1849 case TRUNC_MOD_EXPR
:
1850 multiplicative_expression (TREE_OPERAND (e
, 0));
1851 pp_c_whitespace (this);
1852 if (code
== MULT_EXPR
)
1854 else if (code
== TRUNC_DIV_EXPR
)
1858 pp_c_whitespace (this);
1859 pp_c_cast_expression (this, TREE_OPERAND (e
, 1));
1863 pp_c_cast_expression (this, e
);
1868 /* additive-expression:
1869 multiplicative-expression
1870 additive-expression + multiplicative-expression
1871 additive-expression - multiplicative-expression */
1874 pp_c_additive_expression (c_pretty_printer
*pp
, tree e
)
1876 enum tree_code code
= TREE_CODE (e
);
1879 case POINTER_PLUS_EXPR
:
1882 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 0));
1883 pp_c_whitespace (pp
);
1884 if (code
== PLUS_EXPR
|| code
== POINTER_PLUS_EXPR
)
1888 pp_c_whitespace (pp
);
1889 pp
->multiplicative_expression (TREE_OPERAND (e
, 1));
1893 pp
->multiplicative_expression (e
);
1898 /* additive-expression:
1900 shift-expression << additive-expression
1901 shift-expression >> additive-expression */
1904 pp_c_shift_expression (c_pretty_printer
*pp
, tree e
)
1906 enum tree_code code
= TREE_CODE (e
);
1911 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 0));
1912 pp_c_whitespace (pp
);
1913 pp_string (pp
, code
== LSHIFT_EXPR
? "<<" : ">>");
1914 pp_c_whitespace (pp
);
1915 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 1));
1919 pp_c_additive_expression (pp
, e
);
1923 /* relational-expression:
1925 relational-expression < shift-expression
1926 relational-expression > shift-expression
1927 relational-expression <= shift-expression
1928 relational-expression >= shift-expression */
1931 pp_c_relational_expression (c_pretty_printer
*pp
, tree e
)
1933 enum tree_code code
= TREE_CODE (e
);
1940 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 0));
1941 pp_c_whitespace (pp
);
1942 if (code
== LT_EXPR
)
1944 else if (code
== GT_EXPR
)
1946 else if (code
== LE_EXPR
)
1948 else if (code
== GE_EXPR
)
1949 pp_greater_equal (pp
);
1950 pp_c_whitespace (pp
);
1951 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 1));
1955 pp_c_shift_expression (pp
, e
);
1960 /* equality-expression:
1961 relational-expression
1962 equality-expression == relational-expression
1963 equality-equality != relational-expression */
1966 pp_c_equality_expression (c_pretty_printer
*pp
, tree e
)
1968 enum tree_code code
= TREE_CODE (e
);
1973 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 0));
1974 pp_c_whitespace (pp
);
1975 pp_string (pp
, code
== EQ_EXPR
? "==" : "!=");
1976 pp_c_whitespace (pp
);
1977 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 1));
1981 pp_c_relational_expression (pp
, e
);
1988 AND-expression & equality-equality */
1991 pp_c_and_expression (c_pretty_printer
*pp
, tree e
)
1993 if (TREE_CODE (e
) == BIT_AND_EXPR
)
1995 pp_c_and_expression (pp
, TREE_OPERAND (e
, 0));
1996 pp_c_whitespace (pp
);
1998 pp_c_whitespace (pp
);
1999 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 1));
2002 pp_c_equality_expression (pp
, e
);
2005 /* exclusive-OR-expression:
2007 exclusive-OR-expression ^ AND-expression */
2010 pp_c_exclusive_or_expression (c_pretty_printer
*pp
, tree e
)
2012 if (TREE_CODE (e
) == BIT_XOR_EXPR
2013 || TREE_CODE (e
) == TRUTH_XOR_EXPR
)
2015 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
2016 if (TREE_CODE (e
) == BIT_XOR_EXPR
)
2017 pp_c_maybe_whitespace (pp
);
2019 pp_c_whitespace (pp
);
2021 pp_c_whitespace (pp
);
2022 pp_c_and_expression (pp
, TREE_OPERAND (e
, 1));
2025 pp_c_and_expression (pp
, e
);
2028 /* inclusive-OR-expression:
2029 exclusive-OR-expression
2030 inclusive-OR-expression | exclusive-OR-expression */
2033 pp_c_inclusive_or_expression (c_pretty_printer
*pp
, tree e
)
2035 if (TREE_CODE (e
) == BIT_IOR_EXPR
)
2037 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
2038 pp_c_whitespace (pp
);
2040 pp_c_whitespace (pp
);
2041 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
2044 pp_c_exclusive_or_expression (pp
, e
);
2047 /* logical-AND-expression:
2048 inclusive-OR-expression
2049 logical-AND-expression && inclusive-OR-expression */
2052 pp_c_logical_and_expression (c_pretty_printer
*pp
, tree e
)
2054 if (TREE_CODE (e
) == TRUTH_ANDIF_EXPR
2055 || TREE_CODE (e
) == TRUTH_AND_EXPR
)
2057 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 0));
2058 pp_c_whitespace (pp
);
2059 pp_ampersand_ampersand (pp
);
2060 pp_c_whitespace (pp
);
2061 pp_c_inclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
2064 pp_c_inclusive_or_expression (pp
, e
);
2067 /* logical-OR-expression:
2068 logical-AND-expression
2069 logical-OR-expression || logical-AND-expression */
2072 pp_c_logical_or_expression (c_pretty_printer
*pp
, tree e
)
2074 if (TREE_CODE (e
) == TRUTH_ORIF_EXPR
2075 || TREE_CODE (e
) == TRUTH_OR_EXPR
)
2077 pp_c_logical_or_expression (pp
, TREE_OPERAND (e
, 0));
2078 pp_c_whitespace (pp
);
2080 pp_c_whitespace (pp
);
2081 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 1));
2084 pp_c_logical_and_expression (pp
, e
);
2087 /* conditional-expression:
2088 logical-OR-expression
2089 logical-OR-expression ? expression : conditional-expression */
2092 c_pretty_printer::conditional_expression (tree e
)
2094 if (TREE_CODE (e
) == COND_EXPR
)
2096 pp_c_logical_or_expression (this, TREE_OPERAND (e
, 0));
2097 pp_c_whitespace (this);
2099 pp_c_whitespace (this);
2100 expression (TREE_OPERAND (e
, 1));
2101 pp_c_whitespace (this);
2103 pp_c_whitespace (this);
2104 conditional_expression (TREE_OPERAND (e
, 2));
2107 pp_c_logical_or_expression (this, e
);
2111 /* assignment-expression:
2112 conditional-expression
2113 unary-expression assignment-operator assignment-expression
2115 assignment-expression: one of
2116 = *= /= %= += -= >>= <<= &= ^= |= */
2119 c_pretty_printer::assignment_expression (tree e
)
2121 if (TREE_CODE (e
) == MODIFY_EXPR
2122 || TREE_CODE (e
) == INIT_EXPR
)
2124 unary_expression (TREE_OPERAND (e
, 0));
2125 pp_c_whitespace (this);
2128 expression (TREE_OPERAND (e
, 1));
2131 conditional_expression (e
);
2135 assignment-expression
2136 expression , assignment-expression
2138 Implementation note: instead of going through the usual recursion
2139 chain, I take the liberty of dispatching nodes to the appropriate
2140 functions. This makes some redundancy, but it worths it. That also
2141 prevents a possible infinite recursion between primary_expression ()
2142 and expression (). */
2145 c_pretty_printer::expression (tree e
)
2147 switch (TREE_CODE (e
))
2150 pp_c_void_constant (this);
2154 pp_c_integer_constant (this, e
);
2158 pp_c_floating_constant (this, e
);
2162 pp_c_fixed_constant (this, e
);
2166 pp_c_string_literal (this, e
);
2169 case IDENTIFIER_NODE
:
2178 primary_expression (e
);
2182 if (SSA_NAME_VAR (e
)
2183 && !DECL_ARTIFICIAL (SSA_NAME_VAR (e
)))
2184 expression (SSA_NAME_VAR (e
));
2186 translate_string ("<unknown>");
2189 case POSTINCREMENT_EXPR
:
2190 case POSTDECREMENT_EXPR
:
2192 case ARRAY_NOTATION_REF
:
2200 case UNORDERED_EXPR
:
2209 case COMPOUND_LITERAL_EXPR
:
2211 postfix_expression (e
);
2220 case TRUTH_NOT_EXPR
:
2221 case PREINCREMENT_EXPR
:
2222 case PREDECREMENT_EXPR
:
2225 unary_expression (e
);
2229 case FIX_TRUNC_EXPR
:
2231 case VIEW_CONVERT_EXPR
:
2232 pp_c_cast_expression (this, e
);
2236 case TRUNC_MOD_EXPR
:
2237 case TRUNC_DIV_EXPR
:
2238 multiplicative_expression (e
);
2243 pp_c_shift_expression (this, e
);
2250 pp_c_relational_expression (this, e
);
2254 pp_c_and_expression (this, e
);
2258 case TRUTH_XOR_EXPR
:
2259 pp_c_exclusive_or_expression (this, e
);
2263 pp_c_inclusive_or_expression (this, e
);
2266 case TRUTH_ANDIF_EXPR
:
2267 case TRUTH_AND_EXPR
:
2268 pp_c_logical_and_expression (this, e
);
2271 case TRUTH_ORIF_EXPR
:
2273 pp_c_logical_or_expression (this, e
);
2278 pp_c_equality_expression (this, e
);
2282 conditional_expression (e
);
2285 case POINTER_PLUS_EXPR
:
2288 pp_c_additive_expression (this, e
);
2293 assignment_expression (e
);
2297 pp_c_left_paren (this);
2298 expression (TREE_OPERAND (e
, 0));
2299 pp_separate_with (this, ',');
2300 assignment_expression (TREE_OPERAND (e
, 1));
2301 pp_c_right_paren (this);
2304 case NON_LVALUE_EXPR
:
2306 expression (TREE_OPERAND (e
, 0));
2310 postfix_expression (TREE_OPERAND (e
, 1));
2315 /* We don't yet have a way of dumping statements in a
2316 human-readable format. */
2317 pp_string (this, "({...})");
2320 case C_MAYBE_CONST_EXPR
:
2321 expression (C_MAYBE_CONST_EXPR_EXPR (e
));
2325 pp_unsupported_tree (this, e
);
2335 c_pretty_printer::statement (tree stmt
)
2340 if (pp_needs_newline (this))
2341 pp_newline_and_indent (this, 0);
2343 dump_generic_node (this, stmt
, pp_indentation (this), 0, true);
2347 /* Initialize the PRETTY-PRINTER for handling C codes. */
2349 c_pretty_printer::c_pretty_printer ()
2350 : pretty_printer (),
2354 type_specifier_seq
= pp_c_specifier_qualifier_list
;
2355 ptr_operator
= pp_c_pointer
;
2356 parameter_list
= pp_c_parameter_type_list
;
2360 /* Print the tree T in full, on file FILE. */
2363 print_c_tree (FILE *file
, tree t
)
2365 c_pretty_printer pp
;
2367 pp_needs_newline (&pp
) = true;
2368 pp
.buffer
->stream
= file
;
2370 pp_newline_and_flush (&pp
);
2373 /* Print the tree T in full, on stderr. */
2376 debug_c_tree (tree t
)
2378 print_c_tree (stderr
, t
);
2379 fputc ('\n', stderr
);
2382 /* Output the DECL_NAME of T. If T has no DECL_NAME, output a string made
2383 up of T's memory address. */
2386 pp_c_tree_decl_identifier (c_pretty_printer
*pp
, tree t
)
2390 gcc_assert (DECL_P (t
));
2393 name
= IDENTIFIER_POINTER (DECL_NAME (t
));
2396 static char xname
[8];
2397 sprintf (xname
, "<U%4x>", ((unsigned)((uintptr_t)(t
) & 0xffff)));
2401 pp_c_identifier (pp
, name
);