1 /* Subroutines common to both C and C++ pretty-printers.
2 Copyright (C) 2002-2014 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 "stor-layout.h"
29 #include "c-pretty-print.h"
30 #include "tree-pretty-print.h"
31 #include "tree-iterator.h"
32 #include "diagnostic.h"
33 #include "wide-int-print.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
);
174 bool previous
= false;
179 /* The C programming language does not have references, but it is much
180 simpler to handle those here rather than going through the same
181 logic in the C++ pretty-printer. */
182 if (p
!= NULL
&& (*p
== '*' || *p
== '&'))
183 pp_c_whitespace (pp
);
185 if (qualifiers
& TYPE_QUAL_ATOMIC
)
187 pp_c_ws_string (pp
, "_Atomic");
191 if (qualifiers
& TYPE_QUAL_CONST
)
194 pp_c_whitespace (pp
);
195 pp_c_ws_string (pp
, func_type
? "__attribute__((const))" : "const");
199 if (qualifiers
& TYPE_QUAL_VOLATILE
)
202 pp_c_whitespace (pp
);
203 pp_c_ws_string (pp
, func_type
? "__attribute__((noreturn))" : "volatile");
207 if (qualifiers
& TYPE_QUAL_RESTRICT
)
210 pp_c_whitespace (pp
);
211 pp_c_ws_string (pp
, (flag_isoc99
&& !c_dialect_cxx ()
212 ? "restrict" : "__restrict__"));
216 /* Pretty-print T using the type-cast notation '( type-name )'. */
219 pp_c_type_cast (c_pretty_printer
*pp
, tree t
)
221 pp_c_left_paren (pp
);
223 pp_c_right_paren (pp
);
226 /* We're about to pretty-print a pointer type as indicated by T.
227 Output a whitespace, if needed, preparing for subsequent output. */
230 pp_c_space_for_pointer_operator (c_pretty_printer
*pp
, tree t
)
232 if (POINTER_TYPE_P (t
))
234 tree pointee
= strip_pointer_operator (TREE_TYPE (t
));
235 if (TREE_CODE (pointee
) != ARRAY_TYPE
236 && TREE_CODE (pointee
) != FUNCTION_TYPE
)
237 pp_c_whitespace (pp
);
244 /* C++ cv-qualifiers are called type-qualifiers in C. Print out the
245 cv-qualifiers of T. If T is a declaration then it is the cv-qualifier
246 of its type. Take care of possible extensions.
250 type-qualifier-list type-qualifier
255 __restrict__ -- GNU C
256 address-space-qualifier -- GNU C
260 address-space-qualifier:
261 identifier -- GNU C */
264 pp_c_type_qualifier_list (c_pretty_printer
*pp
, tree t
)
268 if (!t
|| t
== error_mark_node
)
274 qualifiers
= TYPE_QUALS (t
);
275 pp_c_cv_qualifiers (pp
, qualifiers
,
276 TREE_CODE (t
) == FUNCTION_TYPE
);
278 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (t
)))
280 const char *as
= c_addr_space_name (TYPE_ADDR_SPACE (t
));
281 pp_c_identifier (pp
, as
);
286 * type-qualifier-list(opt)
287 * type-qualifier-list(opt) pointer */
290 pp_c_pointer (c_pretty_printer
*pp
, tree t
)
292 if (!TYPE_P (t
) && TREE_CODE (t
) != TYPE_DECL
)
294 switch (TREE_CODE (t
))
297 /* It is easier to handle C++ reference types here. */
299 if (TREE_CODE (TREE_TYPE (t
)) == POINTER_TYPE
)
300 pp_c_pointer (pp
, TREE_TYPE (t
));
301 if (TREE_CODE (t
) == POINTER_TYPE
)
305 pp_c_type_qualifier_list (pp
, t
);
308 /* ??? This node is now in GENERIC and so shouldn't be here. But
309 we'll fix that later. */
311 pp
->declaration (DECL_EXPR_DECL (t
));
312 pp_needs_newline (pp
) = true;
316 pp_unsupported_tree (pp
, t
);
320 /* simple-type-specifier:
336 struct-or-union-specifier
341 simple-type-specifier:
346 c_pretty_printer::simple_type_specifier (tree t
)
348 const enum tree_code code
= TREE_CODE (t
);
352 translate_string ("<type-error>");
355 case IDENTIFIER_NODE
:
356 pp_c_identifier (this, IDENTIFIER_POINTER (t
));
363 case FIXED_POINT_TYPE
:
367 simple_type_specifier (t
);
371 int prec
= TYPE_PRECISION (t
);
372 if (ALL_FIXED_POINT_MODE_P (TYPE_MODE (t
)))
373 t
= c_common_type_for_mode (TYPE_MODE (t
), TYPE_SATURATING (t
));
375 t
= c_common_type_for_mode (TYPE_MODE (t
), TYPE_UNSIGNED (t
));
378 simple_type_specifier (t
);
379 if (TYPE_PRECISION (t
) != prec
)
382 pp_decimal_int (this, prec
);
390 translate_string (TYPE_UNSIGNED (t
)
391 ? "<unnamed-unsigned:"
392 : "<unnamed-signed:");
395 translate_string ("<unnamed-float:");
397 case FIXED_POINT_TYPE
:
398 translate_string ("<unnamed-fixed:");
403 pp_decimal_int (this, prec
);
413 translate_string ("<typedef-error>");
419 if (TYPE_NAME (t
) && TREE_CODE (TYPE_NAME (t
)) == TYPE_DECL
)
420 /* Don't decorate the type if this is a typedef name. */;
421 else if (code
== UNION_TYPE
)
422 pp_c_ws_string (this, "union");
423 else if (code
== RECORD_TYPE
)
424 pp_c_ws_string (this, "struct");
425 else if (code
== ENUMERAL_TYPE
)
426 pp_c_ws_string (this, "enum");
428 translate_string ("<tag-error>");
431 id_expression (TYPE_NAME (t
));
433 translate_string ("<anonymous>");
437 pp_unsupported_tree (this, t
);
442 /* specifier-qualifier-list:
443 type-specifier specifier-qualifier-list-opt
444 type-qualifier specifier-qualifier-list-opt
447 Implementation note: Because of the non-linearities in array or
448 function declarations, this routine prints not just the
449 specifier-qualifier-list of such entities or types of such entities,
450 but also the 'pointer' production part of their declarators. The
451 remaining part is done by declarator() or abstract_declarator(). */
454 pp_c_specifier_qualifier_list (c_pretty_printer
*pp
, tree t
)
456 const enum tree_code code
= TREE_CODE (t
);
458 if (!(pp
->flags
& pp_c_flag_gnu_v3
) && code
!= POINTER_TYPE
)
459 pp_c_type_qualifier_list (pp
, t
);
465 /* Get the types-specifier of this type. */
466 tree pointee
= strip_pointer_operator (TREE_TYPE (t
));
467 pp_c_specifier_qualifier_list (pp
, pointee
);
468 if (TREE_CODE (pointee
) == ARRAY_TYPE
469 || TREE_CODE (pointee
) == FUNCTION_TYPE
)
471 pp_c_whitespace (pp
);
472 pp_c_left_paren (pp
);
473 pp_c_attributes_display (pp
, TYPE_ATTRIBUTES (pointee
));
475 else if (!c_dialect_cxx ())
476 pp_c_whitespace (pp
);
477 pp_ptr_operator (pp
, t
);
483 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
488 if (code
== COMPLEX_TYPE
)
489 pp_c_ws_string (pp
, (flag_isoc99
&& !c_dialect_cxx ()
490 ? "_Complex" : "__complex__"));
491 else if (code
== VECTOR_TYPE
)
493 pp_c_ws_string (pp
, "__vector");
494 pp_c_left_paren (pp
);
495 pp_wide_integer (pp
, TYPE_VECTOR_SUBPARTS (t
));
496 pp_c_right_paren (pp
);
497 pp_c_whitespace (pp
);
499 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
503 pp
->simple_type_specifier (t
);
506 if ((pp
->flags
& pp_c_flag_gnu_v3
) && code
!= POINTER_TYPE
)
507 pp_c_type_qualifier_list (pp
, t
);
510 /* parameter-type-list:
515 parameter-declaration
516 parameter-list , parameter-declaration
518 parameter-declaration:
519 declaration-specifiers declarator
520 declaration-specifiers abstract-declarator(opt) */
523 pp_c_parameter_type_list (c_pretty_printer
*pp
, tree t
)
525 bool want_parm_decl
= DECL_P (t
) && !(pp
->flags
& pp_c_flag_abstract
);
526 tree parms
= want_parm_decl
? DECL_ARGUMENTS (t
) : TYPE_ARG_TYPES (t
);
527 pp_c_left_paren (pp
);
528 if (parms
== void_list_node
)
529 pp_c_ws_string (pp
, "void");
533 for ( ; parms
&& parms
!= void_list_node
; parms
= TREE_CHAIN (parms
))
536 pp_separate_with (pp
, ',');
538 pp
->declaration_specifiers
539 (want_parm_decl
? parms
: TREE_VALUE (parms
));
541 pp
->declarator (parms
);
543 pp
->abstract_declarator (TREE_VALUE (parms
));
546 pp_c_right_paren (pp
);
549 /* abstract-declarator:
551 pointer(opt) direct-abstract-declarator */
554 c_pretty_printer::abstract_declarator (tree t
)
556 if (TREE_CODE (t
) == POINTER_TYPE
)
558 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
559 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
560 pp_c_right_paren (this);
564 direct_abstract_declarator (t
);
567 /* direct-abstract-declarator:
568 ( abstract-declarator )
569 direct-abstract-declarator(opt) [ assignment-expression(opt) ]
570 direct-abstract-declarator(opt) [ * ]
571 direct-abstract-declarator(opt) ( parameter-type-list(opt) ) */
574 c_pretty_printer::direct_abstract_declarator (tree t
)
576 switch (TREE_CODE (t
))
579 abstract_declarator (t
);
583 pp_c_parameter_type_list (this, t
);
584 direct_abstract_declarator (TREE_TYPE (t
));
588 pp_c_left_bracket (this);
589 if (TYPE_DOMAIN (t
) && TYPE_MAX_VALUE (TYPE_DOMAIN (t
)))
591 tree maxval
= TYPE_MAX_VALUE (TYPE_DOMAIN (t
));
592 tree type
= TREE_TYPE (maxval
);
594 if (tree_fits_shwi_p (maxval
))
595 pp_wide_integer (this, tree_to_shwi (maxval
) + 1);
597 expression (fold_build2 (PLUS_EXPR
, type
, maxval
,
598 build_int_cst (type
, 1)));
600 pp_c_right_bracket (this);
601 direct_abstract_declarator (TREE_TYPE (t
));
604 case IDENTIFIER_NODE
:
609 case FIXED_POINT_TYPE
:
619 pp_unsupported_tree (this, t
);
625 specifier-qualifier-list abstract-declarator(opt) */
628 c_pretty_printer::type_id (tree t
)
630 pp_c_specifier_qualifier_list (this, t
);
631 abstract_declarator (t
);
634 /* storage-class-specifier:
642 c_pretty_printer::storage_class_specifier (tree t
)
644 if (TREE_CODE (t
) == TYPE_DECL
)
645 pp_c_ws_string (this, "typedef");
648 if (DECL_REGISTER (t
))
649 pp_c_ws_string (this, "register");
650 else if (TREE_STATIC (t
) && TREE_CODE (t
) == VAR_DECL
)
651 pp_c_ws_string (this, "static");
655 /* function-specifier:
659 c_pretty_printer::function_specifier (tree t
)
661 if (TREE_CODE (t
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (t
))
662 pp_c_ws_string (this, "inline");
665 /* declaration-specifiers:
666 storage-class-specifier declaration-specifiers(opt)
667 type-specifier declaration-specifiers(opt)
668 type-qualifier declaration-specifiers(opt)
669 function-specifier declaration-specifiers(opt) */
672 c_pretty_printer::declaration_specifiers (tree t
)
674 storage_class_specifier (t
);
675 function_specifier (t
);
676 pp_c_specifier_qualifier_list (this, DECL_P (t
) ? TREE_TYPE (t
) : t
);
682 direct-declarator [ type-qualifier-list(opt) assignment-expression(opt) ]
683 direct-declarator [ static type-qualifier-list(opt) assignment-expression(opt)]
684 direct-declarator [ type-qualifier-list static assignment-expression ]
685 direct-declarator [ type-qualifier-list * ]
686 direct-declarator ( parameter-type-list )
687 direct-declarator ( identifier-list(opt) ) */
690 c_pretty_printer::direct_declarator (tree t
)
692 switch (TREE_CODE (t
))
699 pp_c_space_for_pointer_operator (this, TREE_TYPE (t
));
700 pp_c_tree_decl_identifier (this, t
);
705 abstract_declarator (TREE_TYPE (t
));
709 pp_parameter_list (this, t
);
710 abstract_declarator (TREE_TYPE (t
));
714 pp_c_space_for_pointer_operator (this, TREE_TYPE (TREE_TYPE (t
)));
715 pp_c_tree_decl_identifier (this, t
);
716 if (flags
& pp_c_flag_abstract
)
717 abstract_declarator (TREE_TYPE (t
));
720 pp_parameter_list (this, t
);
721 abstract_declarator (TREE_TYPE (TREE_TYPE (t
)));
727 case FIXED_POINT_TYPE
:
734 pp_unsupported_tree (this, t
);
741 pointer(opt) direct-declarator */
744 c_pretty_printer::declarator (tree t
)
746 switch (TREE_CODE (t
))
750 case FIXED_POINT_TYPE
:
763 direct_declarator (t
);
768 pp_unsupported_tree (this, t
);
774 declaration-specifiers init-declarator-list(opt) ; */
777 c_pretty_printer::declaration (tree t
)
779 declaration_specifiers (t
);
780 pp_c_init_declarator (this, t
);
783 /* Pretty-print ATTRIBUTES using GNU C extension syntax. */
786 pp_c_attributes (c_pretty_printer
*pp
, tree attributes
)
788 if (attributes
== NULL_TREE
)
791 pp_c_ws_string (pp
, "__attribute__");
792 pp_c_left_paren (pp
);
793 pp_c_left_paren (pp
);
794 for (; attributes
!= NULL_TREE
; attributes
= TREE_CHAIN (attributes
))
796 pp_tree_identifier (pp
, TREE_PURPOSE (attributes
));
797 if (TREE_VALUE (attributes
))
798 pp_c_call_argument_list (pp
, TREE_VALUE (attributes
));
800 if (TREE_CHAIN (attributes
))
801 pp_separate_with (pp
, ',');
803 pp_c_right_paren (pp
);
804 pp_c_right_paren (pp
);
807 /* Pretty-print ATTRIBUTES using GNU C extension syntax for attributes
808 marked to be displayed on disgnostic. */
811 pp_c_attributes_display (c_pretty_printer
*pp
, tree a
)
813 bool is_first
= true;
818 for (; a
!= NULL_TREE
; a
= TREE_CHAIN (a
))
820 const struct attribute_spec
*as
;
821 as
= lookup_attribute_spec (TREE_PURPOSE (a
));
822 if (!as
|| as
->affects_type_identity
== false)
826 pp_c_ws_string (pp
, "__attribute__");
827 pp_c_left_paren (pp
);
828 pp_c_left_paren (pp
);
833 pp_separate_with (pp
, ',');
835 pp_tree_identifier (pp
, TREE_PURPOSE (a
));
837 pp_c_call_argument_list (pp
, TREE_VALUE (a
));
842 pp_c_right_paren (pp
);
843 pp_c_right_paren (pp
);
844 pp_c_whitespace (pp
);
848 /* function-definition:
849 declaration-specifiers declarator compound-statement */
852 pp_c_function_definition (c_pretty_printer
*pp
, tree t
)
854 pp
->declaration_specifiers (t
);
856 pp_needs_newline (pp
) = true;
857 pp
->statement (DECL_SAVED_TREE (t
));
858 pp_newline_and_flush (pp
);
864 /* Print out a c-char. This is called solely for characters which are
865 in the *target* execution character set. We ought to convert them
866 back to the *host* execution character set before printing, but we
867 have no way to do this at present. A decent compromise is to print
868 all characters as if they were in the host execution character set,
869 and not attempt to recover any named escape characters, but render
870 all unprintables as octal escapes. If the host and target character
871 sets are the same, this produces relatively readable output. If they
872 are not the same, strings may appear as gibberish, but that's okay
873 (in fact, it may well be what the reader wants, e.g. if they are looking
874 to see if conversion to the target character set happened correctly).
876 A special case: we need to prefix \, ", and ' with backslashes. It is
877 correct to do so for the *host*'s \, ", and ', because the rest of the
878 file appears in the host character set. */
881 pp_c_char (c_pretty_printer
*pp
, int c
)
887 case '\\': pp_string (pp
, "\\\\"); break;
888 case '\'': pp_string (pp
, "\\\'"); break;
889 case '\"': pp_string (pp
, "\\\""); break;
890 default: pp_character (pp
, c
);
894 pp_scalar (pp
, "\\%03o", (unsigned) c
);
897 /* Print out a STRING literal. */
900 pp_c_string_literal (c_pretty_printer
*pp
, tree s
)
902 const char *p
= TREE_STRING_POINTER (s
);
903 int n
= TREE_STRING_LENGTH (s
) - 1;
906 for (i
= 0; i
< n
; ++i
)
907 pp_c_char (pp
, p
[i
]);
911 /* Pretty-print a VOID_CST (void_node). */
914 pp_c_void_constant (c_pretty_printer
*pp
)
916 pp_c_type_cast (pp
, void_type_node
);
920 /* Pretty-print an INTEGER literal. */
923 pp_c_integer_constant (c_pretty_printer
*pp
, tree i
)
927 /* We are going to compare the type of I to other types using
928 pointer comparison so we need to use its canonical type. */
930 TYPE_CANONICAL (TREE_TYPE (i
))
931 ? TYPE_CANONICAL (TREE_TYPE (i
))
934 if (tree_fits_shwi_p (i
))
935 pp_wide_integer (pp
, tree_to_shwi (i
));
936 else if (tree_fits_uhwi_p (i
))
937 pp_unsigned_wide_integer (pp
, tree_to_uhwi (i
));
942 if (wi::lt_p (i
, 0, TYPE_SIGN (TREE_TYPE (i
))))
947 print_hex (wi
, pp_buffer (pp
)->digit_buffer
);
948 pp_string (pp
, pp_buffer (pp
)->digit_buffer
);
950 if (TYPE_UNSIGNED (type
))
951 pp_character (pp
, 'u');
952 if (type
== long_integer_type_node
|| type
== long_unsigned_type_node
)
953 pp_character (pp
, 'l');
954 else if (type
== long_long_integer_type_node
955 || type
== long_long_unsigned_type_node
)
956 pp_string (pp
, "ll");
957 else for (idx
= 0; idx
< NUM_INT_N_ENTS
; idx
++)
958 if (int_n_enabled_p
[idx
])
961 if (type
== int_n_trees
[idx
].signed_type
962 || type
== int_n_trees
[idx
].unsigned_type
)
964 sprintf (buf
, "I%d", int_n_data
[idx
].bitsize
);
970 /* Print out a CHARACTER literal. */
973 pp_c_character_constant (c_pretty_printer
*pp
, tree c
)
976 pp_c_char (pp
, (unsigned) TREE_INT_CST_LOW (c
));
980 /* Print out a BOOLEAN literal. */
983 pp_c_bool_constant (c_pretty_printer
*pp
, tree b
)
985 if (b
== boolean_false_node
)
987 if (c_dialect_cxx ())
988 pp_c_ws_string (pp
, "false");
989 else if (flag_isoc99
)
990 pp_c_ws_string (pp
, "_False");
992 pp_unsupported_tree (pp
, b
);
994 else if (b
== boolean_true_node
)
996 if (c_dialect_cxx ())
997 pp_c_ws_string (pp
, "true");
998 else if (flag_isoc99
)
999 pp_c_ws_string (pp
, "_True");
1001 pp_unsupported_tree (pp
, b
);
1003 else if (TREE_CODE (b
) == INTEGER_CST
)
1004 pp_c_integer_constant (pp
, b
);
1006 pp_unsupported_tree (pp
, b
);
1009 /* Attempt to print out an ENUMERATOR. Return true on success. Else return
1010 false; that means the value was obtained by a cast, in which case
1011 print out the type-id part of the cast-expression -- the casted value
1012 is then printed by pp_c_integer_literal. */
1015 pp_c_enumeration_constant (c_pretty_printer
*pp
, tree e
)
1017 bool value_is_named
= true;
1018 tree type
= TREE_TYPE (e
);
1021 /* Find the name of this constant. */
1022 for (value
= TYPE_VALUES (type
);
1023 value
!= NULL_TREE
&& !tree_int_cst_equal (TREE_VALUE (value
), e
);
1024 value
= TREE_CHAIN (value
))
1027 if (value
!= NULL_TREE
)
1028 pp
->id_expression (TREE_PURPOSE (value
));
1031 /* Value must have been cast. */
1032 pp_c_type_cast (pp
, type
);
1033 value_is_named
= false;
1036 return value_is_named
;
1039 /* Print out a REAL value as a decimal-floating-constant. */
1042 pp_c_floating_constant (c_pretty_printer
*pp
, tree r
)
1044 const struct real_format
*fmt
1045 = REAL_MODE_FORMAT (TYPE_MODE (TREE_TYPE (r
)));
1047 REAL_VALUE_TYPE floating_cst
= TREE_REAL_CST (r
);
1048 bool is_decimal
= floating_cst
.decimal
;
1050 /* See ISO C++ WG N1822. Note: The fraction 643/2136 approximates
1051 log10(2) to 7 significant digits. */
1052 int max_digits10
= 2 + (is_decimal
? fmt
->p
: fmt
->p
* 643L / 2136);
1054 real_to_decimal (pp_buffer (pp
)->digit_buffer
, &TREE_REAL_CST (r
),
1055 sizeof (pp_buffer (pp
)->digit_buffer
),
1058 pp_string (pp
, pp_buffer(pp
)->digit_buffer
);
1059 if (TREE_TYPE (r
) == float_type_node
)
1060 pp_character (pp
, 'f');
1061 else if (TREE_TYPE (r
) == long_double_type_node
)
1062 pp_character (pp
, 'l');
1063 else if (TREE_TYPE (r
) == dfloat128_type_node
)
1064 pp_string (pp
, "dl");
1065 else if (TREE_TYPE (r
) == dfloat64_type_node
)
1066 pp_string (pp
, "dd");
1067 else if (TREE_TYPE (r
) == dfloat32_type_node
)
1068 pp_string (pp
, "df");
1071 /* Print out a FIXED value as a decimal-floating-constant. */
1074 pp_c_fixed_constant (c_pretty_printer
*pp
, tree r
)
1076 fixed_to_decimal (pp_buffer (pp
)->digit_buffer
, &TREE_FIXED_CST (r
),
1077 sizeof (pp_buffer (pp
)->digit_buffer
));
1078 pp_string (pp
, pp_buffer(pp
)->digit_buffer
);
1081 /* Pretty-print a compound literal expression. GNU extensions include
1082 vector constants. */
1085 pp_c_compound_literal (c_pretty_printer
*pp
, tree e
)
1087 tree type
= TREE_TYPE (e
);
1088 pp_c_type_cast (pp
, type
);
1090 switch (TREE_CODE (type
))
1097 pp_c_brace_enclosed_initializer_list (pp
, e
);
1101 pp_unsupported_tree (pp
, e
);
1106 /* Pretty-print a COMPLEX_EXPR expression. */
1109 pp_c_complex_expr (c_pretty_printer
*pp
, tree e
)
1111 /* Handle a few common special cases, otherwise fallback
1112 to printing it as compound literal. */
1113 tree type
= TREE_TYPE (e
);
1114 tree realexpr
= TREE_OPERAND (e
, 0);
1115 tree imagexpr
= TREE_OPERAND (e
, 1);
1117 /* Cast of an COMPLEX_TYPE expression to a different COMPLEX_TYPE. */
1118 if (TREE_CODE (realexpr
) == NOP_EXPR
1119 && TREE_CODE (imagexpr
) == NOP_EXPR
1120 && TREE_TYPE (realexpr
) == TREE_TYPE (type
)
1121 && TREE_TYPE (imagexpr
) == TREE_TYPE (type
)
1122 && TREE_CODE (TREE_OPERAND (realexpr
, 0)) == REALPART_EXPR
1123 && TREE_CODE (TREE_OPERAND (imagexpr
, 0)) == IMAGPART_EXPR
1124 && TREE_OPERAND (TREE_OPERAND (realexpr
, 0), 0)
1125 == TREE_OPERAND (TREE_OPERAND (imagexpr
, 0), 0))
1127 pp_c_type_cast (pp
, type
);
1128 pp
->expression (TREE_OPERAND (TREE_OPERAND (realexpr
, 0), 0));
1132 /* Cast of an scalar expression to COMPLEX_TYPE. */
1133 if ((integer_zerop (imagexpr
) || real_zerop (imagexpr
))
1134 && TREE_TYPE (realexpr
) == TREE_TYPE (type
))
1136 pp_c_type_cast (pp
, type
);
1137 if (TREE_CODE (realexpr
) == NOP_EXPR
)
1138 realexpr
= TREE_OPERAND (realexpr
, 0);
1139 pp
->expression (realexpr
);
1143 pp_c_compound_literal (pp
, e
);
1149 fixed-point-constant
1150 enumeration-constant
1151 character-constant */
1154 c_pretty_printer::constant (tree e
)
1156 const enum tree_code code
= TREE_CODE (e
);
1161 pp_c_void_constant (this);
1166 tree type
= TREE_TYPE (e
);
1167 if (type
== boolean_type_node
)
1168 pp_c_bool_constant (this, e
);
1169 else if (type
== char_type_node
)
1170 pp_c_character_constant (this, e
);
1171 else if (TREE_CODE (type
) == ENUMERAL_TYPE
1172 && pp_c_enumeration_constant (this, e
))
1175 pp_c_integer_constant (this, e
);
1180 pp_c_floating_constant (this, e
);
1184 pp_c_fixed_constant (this, e
);
1188 pp_c_string_literal (this, e
);
1192 /* Sometimes, we are confused and we think a complex literal
1193 is a constant. Such thing is a compound literal which
1194 grammatically belongs to postfix-expr production. */
1195 pp_c_compound_literal (this, e
);
1199 pp_unsupported_tree (this, e
);
1204 /* Pretty-print a string such as an identifier, without changing its
1205 encoding, preceded by whitespace is necessary. */
1208 pp_c_ws_string (c_pretty_printer
*pp
, const char *str
)
1210 pp_c_maybe_whitespace (pp
);
1211 pp_string (pp
, str
);
1212 pp
->padding
= pp_before
;
1216 c_pretty_printer::translate_string (const char *gmsgid
)
1218 if (pp_translate_identifiers (this))
1219 pp_c_ws_string (this, _(gmsgid
));
1221 pp_c_ws_string (this, gmsgid
);
1224 /* Pretty-print an IDENTIFIER_NODE, which may contain UTF-8 sequences
1225 that need converting to the locale encoding, preceded by whitespace
1229 pp_c_identifier (c_pretty_printer
*pp
, const char *id
)
1231 pp_c_maybe_whitespace (pp
);
1232 pp_identifier (pp
, id
);
1233 pp
->padding
= pp_before
;
1236 /* Pretty-print a C primary-expression.
1244 c_pretty_printer::primary_expression (tree e
)
1246 switch (TREE_CODE (e
))
1254 pp_c_tree_decl_identifier (this, e
);
1257 case IDENTIFIER_NODE
:
1258 pp_c_tree_identifier (this, e
);
1262 translate_string ("<erroneous-expression>");
1266 translate_string ("<return-value>");
1278 pp_c_ws_string (this, "__builtin_memcpy");
1279 pp_c_left_paren (this);
1280 pp_ampersand (this);
1281 primary_expression (TREE_OPERAND (e
, 0));
1282 pp_separate_with (this, ',');
1283 pp_ampersand (this);
1284 initializer (TREE_OPERAND (e
, 1));
1285 if (TREE_OPERAND (e
, 2))
1287 pp_separate_with (this, ',');
1288 expression (TREE_OPERAND (e
, 2));
1290 pp_c_right_paren (this);
1294 /* FIXME: Make sure we won't get into an infinite loop. */
1295 pp_c_left_paren (this);
1297 pp_c_right_paren (this);
1302 /* Print out a C initializer -- also support C compound-literals.
1304 assignment-expression:
1305 { initializer-list }
1306 { initializer-list , } */
1309 c_pretty_printer::initializer (tree e
)
1311 if (TREE_CODE (e
) == CONSTRUCTOR
)
1312 pp_c_brace_enclosed_initializer_list (this, e
);
1319 declarator = initializer */
1322 pp_c_init_declarator (c_pretty_printer
*pp
, tree t
)
1325 /* We don't want to output function definitions here. There are handled
1326 elsewhere (and the syntactic form is bogus anyway). */
1327 if (TREE_CODE (t
) != FUNCTION_DECL
&& DECL_INITIAL (t
))
1329 tree init
= DECL_INITIAL (t
);
1330 /* This C++ bit is handled here because it is easier to do so.
1331 In templates, the C++ parser builds a TREE_LIST for a
1332 direct-initialization; the TREE_PURPOSE is the variable to
1333 initialize and the TREE_VALUE is the initializer. */
1334 if (TREE_CODE (init
) == TREE_LIST
)
1336 pp_c_left_paren (pp
);
1337 pp
->expression (TREE_VALUE (init
));
1338 pp_right_paren (pp
);
1345 pp
->initializer (init
);
1350 /* initializer-list:
1351 designation(opt) initializer
1352 initializer-list , designation(opt) initializer
1359 designator-list designator
1362 [ constant-expression ]
1366 pp_c_initializer_list (c_pretty_printer
*pp
, tree e
)
1368 tree type
= TREE_TYPE (e
);
1369 const enum tree_code code
= TREE_CODE (type
);
1371 if (TREE_CODE (e
) == CONSTRUCTOR
)
1373 pp_c_constructor_elts (pp
, CONSTRUCTOR_ELTS (e
));
1383 tree init
= TREE_OPERAND (e
, 0);
1384 for (; init
!= NULL_TREE
; init
= TREE_CHAIN (init
))
1386 if (code
== RECORD_TYPE
|| code
== UNION_TYPE
)
1389 pp
->primary_expression (TREE_PURPOSE (init
));
1393 pp_c_left_bracket (pp
);
1394 if (TREE_PURPOSE (init
))
1395 pp
->constant (TREE_PURPOSE (init
));
1396 pp_c_right_bracket (pp
);
1398 pp_c_whitespace (pp
);
1400 pp_c_whitespace (pp
);
1401 pp
->initializer (TREE_VALUE (init
));
1402 if (TREE_CHAIN (init
))
1403 pp_separate_with (pp
, ',');
1409 if (TREE_CODE (e
) == VECTOR_CST
)
1412 for (i
= 0; i
< VECTOR_CST_NELTS (e
); ++i
)
1415 pp_separate_with (pp
, ',');
1416 pp
->expression (VECTOR_CST_ELT (e
, i
));
1424 if (TREE_CODE (e
) == COMPLEX_CST
|| TREE_CODE (e
) == COMPLEX_EXPR
)
1426 const bool cst
= TREE_CODE (e
) == COMPLEX_CST
;
1427 pp
->expression (cst
? TREE_REALPART (e
) : TREE_OPERAND (e
, 0));
1428 pp_separate_with (pp
, ',');
1429 pp
->expression (cst
? TREE_IMAGPART (e
) : TREE_OPERAND (e
, 1));
1439 pp_unsupported_tree (pp
, type
);
1442 /* Pretty-print a brace-enclosed initializer-list. */
1445 pp_c_brace_enclosed_initializer_list (c_pretty_printer
*pp
, tree l
)
1447 pp_c_left_brace (pp
);
1448 pp_c_initializer_list (pp
, l
);
1449 pp_c_right_brace (pp
);
1453 /* This is a convenient function, used to bridge gap between C and C++
1460 c_pretty_printer::id_expression (tree t
)
1462 switch (TREE_CODE (t
))
1471 pp_c_tree_decl_identifier (this, t
);
1474 case IDENTIFIER_NODE
:
1475 pp_c_tree_identifier (this, t
);
1479 pp_unsupported_tree (this, t
);
1484 /* postfix-expression:
1486 postfix-expression [ expression ]
1487 postfix-expression ( argument-expression-list(opt) )
1488 postfix-expression . identifier
1489 postfix-expression -> identifier
1490 postfix-expression ++
1491 postfix-expression --
1492 ( type-name ) { initializer-list }
1493 ( type-name ) { initializer-list , } */
1496 c_pretty_printer::postfix_expression (tree e
)
1498 enum tree_code code
= TREE_CODE (e
);
1501 case POSTINCREMENT_EXPR
:
1502 case POSTDECREMENT_EXPR
:
1503 postfix_expression (TREE_OPERAND (e
, 0));
1504 pp_string (this, code
== POSTINCREMENT_EXPR
? "++" : "--");
1508 postfix_expression (TREE_OPERAND (e
, 0));
1509 pp_c_left_bracket (this);
1510 expression (TREE_OPERAND (e
, 1));
1511 pp_c_right_bracket (this);
1514 case ARRAY_NOTATION_REF
:
1515 postfix_expression (ARRAY_NOTATION_ARRAY (e
));
1516 pp_c_left_bracket (this);
1517 expression (ARRAY_NOTATION_START (e
));
1519 expression (ARRAY_NOTATION_LENGTH (e
));
1521 expression (ARRAY_NOTATION_STRIDE (e
));
1522 pp_c_right_bracket (this);
1527 call_expr_arg_iterator iter
;
1529 postfix_expression (CALL_EXPR_FN (e
));
1530 pp_c_left_paren (this);
1531 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, e
)
1534 if (more_call_expr_args_p (&iter
))
1535 pp_separate_with (this, ',');
1537 pp_c_right_paren (this);
1541 case UNORDERED_EXPR
:
1542 pp_c_ws_string (this, flag_isoc99
1544 : "__builtin_isunordered");
1548 pp_c_ws_string (this, flag_isoc99
1550 : "!__builtin_isunordered");
1554 pp_c_ws_string (this, flag_isoc99
1556 : "!__builtin_isgreaterequal");
1560 pp_c_ws_string (this, flag_isoc99
1562 : "!__builtin_isgreater");
1566 pp_c_ws_string (this, flag_isoc99
1568 : "!__builtin_islessequal");
1572 pp_c_ws_string (this, flag_isoc99
1574 : "!__builtin_isless");
1578 pp_c_ws_string (this, flag_isoc99
1580 : "!__builtin_islessgreater");
1584 pp_c_ws_string (this, flag_isoc99
1586 : "__builtin_islessgreater");
1590 pp_c_left_paren (this);
1591 expression (TREE_OPERAND (e
, 0));
1592 pp_separate_with (this, ',');
1593 expression (TREE_OPERAND (e
, 1));
1594 pp_c_right_paren (this);
1598 pp_c_ws_string (this, "__builtin_abs");
1599 pp_c_left_paren (this);
1600 expression (TREE_OPERAND (e
, 0));
1601 pp_c_right_paren (this);
1606 tree object
= TREE_OPERAND (e
, 0);
1607 if (TREE_CODE (object
) == INDIRECT_REF
)
1609 postfix_expression (TREE_OPERAND (object
, 0));
1614 postfix_expression (object
);
1617 expression (TREE_OPERAND (e
, 1));
1623 tree type
= TREE_TYPE (e
);
1625 type
= signed_or_unsigned_type_for (TYPE_UNSIGNED (type
), type
);
1627 && tree_int_cst_equal (TYPE_SIZE (type
), TREE_OPERAND (e
, 1)))
1629 HOST_WIDE_INT bitpos
= tree_to_shwi (TREE_OPERAND (e
, 2));
1630 HOST_WIDE_INT size
= tree_to_shwi (TYPE_SIZE (type
));
1631 if ((bitpos
% size
) == 0)
1633 pp_c_left_paren (this);
1634 pp_c_left_paren (this);
1637 pp_c_right_paren (this);
1638 pp_c_ampersand (this);
1639 expression (TREE_OPERAND (e
, 0));
1640 pp_c_right_paren (this);
1641 pp_c_left_bracket (this);
1642 pp_wide_integer (this, bitpos
/ size
);
1643 pp_c_right_bracket (this);
1647 pp_unsupported_tree (this, e
);
1657 pp_c_compound_literal (this, e
);
1661 pp_c_complex_expr (this, e
);
1664 case COMPOUND_LITERAL_EXPR
:
1665 e
= DECL_INITIAL (COMPOUND_LITERAL_EXPR_DECL (e
));
1672 pp_c_ws_string (this, "__builtin_va_arg");
1673 pp_c_left_paren (this);
1674 assignment_expression (TREE_OPERAND (e
, 0));
1675 pp_separate_with (this, ',');
1676 type_id (TREE_TYPE (e
));
1677 pp_c_right_paren (this);
1681 if (TREE_CODE (TREE_OPERAND (e
, 0)) == FUNCTION_DECL
)
1683 id_expression (TREE_OPERAND (e
, 0));
1686 /* else fall through. */
1689 primary_expression (e
);
1694 /* Print out an expression-list; E is expected to be a TREE_LIST. */
1697 pp_c_expression_list (c_pretty_printer
*pp
, tree e
)
1699 for (; e
!= NULL_TREE
; e
= TREE_CHAIN (e
))
1701 pp
->expression (TREE_VALUE (e
));
1703 pp_separate_with (pp
, ',');
1707 /* Print out V, which contains the elements of a constructor. */
1710 pp_c_constructor_elts (c_pretty_printer
*pp
, vec
<constructor_elt
, va_gc
> *v
)
1712 unsigned HOST_WIDE_INT ix
;
1715 FOR_EACH_CONSTRUCTOR_VALUE (v
, ix
, value
)
1717 pp
->expression (value
);
1718 if (ix
!= vec_safe_length (v
) - 1)
1719 pp_separate_with (pp
, ',');
1723 /* Print out an expression-list in parens, as if it were the argument
1724 list to a function. */
1727 pp_c_call_argument_list (c_pretty_printer
*pp
, tree t
)
1729 pp_c_left_paren (pp
);
1730 if (t
&& TREE_CODE (t
) == TREE_LIST
)
1731 pp_c_expression_list (pp
, t
);
1732 pp_c_right_paren (pp
);
1735 /* unary-expression:
1739 unary-operator cast-expression
1740 sizeof unary-expression
1743 unary-operator: one of
1748 __alignof__ unary-expression
1749 __alignof__ ( type-id )
1750 __real__ unary-expression
1751 __imag__ unary-expression */
1754 c_pretty_printer::unary_expression (tree e
)
1756 enum tree_code code
= TREE_CODE (e
);
1759 case PREINCREMENT_EXPR
:
1760 case PREDECREMENT_EXPR
:
1761 pp_string (this, code
== PREINCREMENT_EXPR
? "++" : "--");
1762 unary_expression (TREE_OPERAND (e
, 0));
1769 case TRUTH_NOT_EXPR
:
1771 /* String literal are used by address. */
1772 if (code
== ADDR_EXPR
&& TREE_CODE (TREE_OPERAND (e
, 0)) != STRING_CST
)
1773 pp_ampersand (this);
1774 else if (code
== INDIRECT_REF
)
1776 else if (code
== NEGATE_EXPR
)
1778 else if (code
== BIT_NOT_EXPR
|| code
== CONJ_EXPR
)
1779 pp_complement (this);
1780 else if (code
== TRUTH_NOT_EXPR
)
1781 pp_exclamation (this);
1782 pp_c_cast_expression (this, TREE_OPERAND (e
, 0));
1786 if (TREE_CODE (TREE_OPERAND (e
, 0)) == ADDR_EXPR
1787 && integer_zerop (TREE_OPERAND (e
, 1)))
1788 expression (TREE_OPERAND (TREE_OPERAND (e
, 0), 0));
1792 if (!integer_zerop (TREE_OPERAND (e
, 1)))
1794 pp_c_left_paren (this);
1795 if (!integer_onep (TYPE_SIZE_UNIT
1796 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (e
, 0))))))
1797 pp_c_type_cast (this, ptr_type_node
);
1799 pp_c_cast_expression (this, TREE_OPERAND (e
, 0));
1800 if (!integer_zerop (TREE_OPERAND (e
, 1)))
1803 pp_c_integer_constant (this,
1804 fold_convert (ssizetype
,
1805 TREE_OPERAND (e
, 1)));
1806 pp_c_right_paren (this);
1813 pp_c_ws_string (this, code
== REALPART_EXPR
? "__real__" : "__imag__");
1814 pp_c_whitespace (this);
1815 unary_expression (TREE_OPERAND (e
, 0));
1819 postfix_expression (e
);
1826 ( type-name ) cast-expression */
1829 pp_c_cast_expression (c_pretty_printer
*pp
, tree e
)
1831 switch (TREE_CODE (e
))
1834 case FIX_TRUNC_EXPR
:
1836 case VIEW_CONVERT_EXPR
:
1837 pp_c_type_cast (pp
, TREE_TYPE (e
));
1838 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 0));
1842 pp
->unary_expression (e
);
1846 /* multiplicative-expression:
1848 multiplicative-expression * cast-expression
1849 multiplicative-expression / cast-expression
1850 multiplicative-expression % cast-expression */
1853 c_pretty_printer::multiplicative_expression (tree e
)
1855 enum tree_code code
= TREE_CODE (e
);
1859 case TRUNC_DIV_EXPR
:
1860 case TRUNC_MOD_EXPR
:
1861 multiplicative_expression (TREE_OPERAND (e
, 0));
1862 pp_c_whitespace (this);
1863 if (code
== MULT_EXPR
)
1865 else if (code
== TRUNC_DIV_EXPR
)
1869 pp_c_whitespace (this);
1870 pp_c_cast_expression (this, TREE_OPERAND (e
, 1));
1874 pp_c_cast_expression (this, e
);
1879 /* additive-expression:
1880 multiplicative-expression
1881 additive-expression + multiplicative-expression
1882 additive-expression - multiplicative-expression */
1885 pp_c_additive_expression (c_pretty_printer
*pp
, tree e
)
1887 enum tree_code code
= TREE_CODE (e
);
1890 case POINTER_PLUS_EXPR
:
1893 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 0));
1894 pp_c_whitespace (pp
);
1895 if (code
== PLUS_EXPR
|| code
== POINTER_PLUS_EXPR
)
1899 pp_c_whitespace (pp
);
1900 pp
->multiplicative_expression (TREE_OPERAND (e
, 1));
1904 pp
->multiplicative_expression (e
);
1909 /* additive-expression:
1911 shift-expression << additive-expression
1912 shift-expression >> additive-expression */
1915 pp_c_shift_expression (c_pretty_printer
*pp
, tree e
)
1917 enum tree_code code
= TREE_CODE (e
);
1922 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 0));
1923 pp_c_whitespace (pp
);
1924 pp_string (pp
, code
== LSHIFT_EXPR
? "<<" : ">>");
1925 pp_c_whitespace (pp
);
1926 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 1));
1930 pp_c_additive_expression (pp
, e
);
1934 /* relational-expression:
1936 relational-expression < shift-expression
1937 relational-expression > shift-expression
1938 relational-expression <= shift-expression
1939 relational-expression >= shift-expression */
1942 pp_c_relational_expression (c_pretty_printer
*pp
, tree e
)
1944 enum tree_code code
= TREE_CODE (e
);
1951 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 0));
1952 pp_c_whitespace (pp
);
1953 if (code
== LT_EXPR
)
1955 else if (code
== GT_EXPR
)
1957 else if (code
== LE_EXPR
)
1959 else if (code
== GE_EXPR
)
1960 pp_greater_equal (pp
);
1961 pp_c_whitespace (pp
);
1962 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 1));
1966 pp_c_shift_expression (pp
, e
);
1971 /* equality-expression:
1972 relational-expression
1973 equality-expression == relational-expression
1974 equality-equality != relational-expression */
1977 pp_c_equality_expression (c_pretty_printer
*pp
, tree e
)
1979 enum tree_code code
= TREE_CODE (e
);
1984 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 0));
1985 pp_c_whitespace (pp
);
1986 pp_string (pp
, code
== EQ_EXPR
? "==" : "!=");
1987 pp_c_whitespace (pp
);
1988 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 1));
1992 pp_c_relational_expression (pp
, e
);
1999 AND-expression & equality-equality */
2002 pp_c_and_expression (c_pretty_printer
*pp
, tree e
)
2004 if (TREE_CODE (e
) == BIT_AND_EXPR
)
2006 pp_c_and_expression (pp
, TREE_OPERAND (e
, 0));
2007 pp_c_whitespace (pp
);
2009 pp_c_whitespace (pp
);
2010 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 1));
2013 pp_c_equality_expression (pp
, e
);
2016 /* exclusive-OR-expression:
2018 exclusive-OR-expression ^ AND-expression */
2021 pp_c_exclusive_or_expression (c_pretty_printer
*pp
, tree e
)
2023 if (TREE_CODE (e
) == BIT_XOR_EXPR
2024 || TREE_CODE (e
) == TRUTH_XOR_EXPR
)
2026 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
2027 if (TREE_CODE (e
) == BIT_XOR_EXPR
)
2028 pp_c_maybe_whitespace (pp
);
2030 pp_c_whitespace (pp
);
2032 pp_c_whitespace (pp
);
2033 pp_c_and_expression (pp
, TREE_OPERAND (e
, 1));
2036 pp_c_and_expression (pp
, e
);
2039 /* inclusive-OR-expression:
2040 exclusive-OR-expression
2041 inclusive-OR-expression | exclusive-OR-expression */
2044 pp_c_inclusive_or_expression (c_pretty_printer
*pp
, tree e
)
2046 if (TREE_CODE (e
) == BIT_IOR_EXPR
)
2048 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
2049 pp_c_whitespace (pp
);
2051 pp_c_whitespace (pp
);
2052 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
2055 pp_c_exclusive_or_expression (pp
, e
);
2058 /* logical-AND-expression:
2059 inclusive-OR-expression
2060 logical-AND-expression && inclusive-OR-expression */
2063 pp_c_logical_and_expression (c_pretty_printer
*pp
, tree e
)
2065 if (TREE_CODE (e
) == TRUTH_ANDIF_EXPR
2066 || TREE_CODE (e
) == TRUTH_AND_EXPR
)
2068 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 0));
2069 pp_c_whitespace (pp
);
2070 pp_ampersand_ampersand (pp
);
2071 pp_c_whitespace (pp
);
2072 pp_c_inclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
2075 pp_c_inclusive_or_expression (pp
, e
);
2078 /* logical-OR-expression:
2079 logical-AND-expression
2080 logical-OR-expression || logical-AND-expression */
2083 pp_c_logical_or_expression (c_pretty_printer
*pp
, tree e
)
2085 if (TREE_CODE (e
) == TRUTH_ORIF_EXPR
2086 || TREE_CODE (e
) == TRUTH_OR_EXPR
)
2088 pp_c_logical_or_expression (pp
, TREE_OPERAND (e
, 0));
2089 pp_c_whitespace (pp
);
2091 pp_c_whitespace (pp
);
2092 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 1));
2095 pp_c_logical_and_expression (pp
, e
);
2098 /* conditional-expression:
2099 logical-OR-expression
2100 logical-OR-expression ? expression : conditional-expression */
2103 c_pretty_printer::conditional_expression (tree e
)
2105 if (TREE_CODE (e
) == COND_EXPR
)
2107 pp_c_logical_or_expression (this, TREE_OPERAND (e
, 0));
2108 pp_c_whitespace (this);
2110 pp_c_whitespace (this);
2111 expression (TREE_OPERAND (e
, 1));
2112 pp_c_whitespace (this);
2114 pp_c_whitespace (this);
2115 conditional_expression (TREE_OPERAND (e
, 2));
2118 pp_c_logical_or_expression (this, e
);
2122 /* assignment-expression:
2123 conditional-expression
2124 unary-expression assignment-operator assignment-expression
2126 assignment-expression: one of
2127 = *= /= %= += -= >>= <<= &= ^= |= */
2130 c_pretty_printer::assignment_expression (tree e
)
2132 if (TREE_CODE (e
) == MODIFY_EXPR
2133 || TREE_CODE (e
) == INIT_EXPR
)
2135 unary_expression (TREE_OPERAND (e
, 0));
2136 pp_c_whitespace (this);
2139 expression (TREE_OPERAND (e
, 1));
2142 conditional_expression (e
);
2146 assignment-expression
2147 expression , assignment-expression
2149 Implementation note: instead of going through the usual recursion
2150 chain, I take the liberty of dispatching nodes to the appropriate
2151 functions. This makes some redundancy, but it worths it. That also
2152 prevents a possible infinite recursion between primary_expression ()
2153 and expression (). */
2156 c_pretty_printer::expression (tree e
)
2158 switch (TREE_CODE (e
))
2161 pp_c_void_constant (this);
2165 pp_c_integer_constant (this, e
);
2169 pp_c_floating_constant (this, e
);
2173 pp_c_fixed_constant (this, e
);
2177 pp_c_string_literal (this, e
);
2180 case IDENTIFIER_NODE
:
2189 primary_expression (e
);
2193 if (SSA_NAME_VAR (e
)
2194 && !DECL_ARTIFICIAL (SSA_NAME_VAR (e
)))
2195 expression (SSA_NAME_VAR (e
));
2197 translate_string ("<unknown>");
2200 case POSTINCREMENT_EXPR
:
2201 case POSTDECREMENT_EXPR
:
2203 case ARRAY_NOTATION_REF
:
2211 case UNORDERED_EXPR
:
2220 case COMPOUND_LITERAL_EXPR
:
2222 postfix_expression (e
);
2231 case TRUTH_NOT_EXPR
:
2232 case PREINCREMENT_EXPR
:
2233 case PREDECREMENT_EXPR
:
2236 unary_expression (e
);
2240 case FIX_TRUNC_EXPR
:
2242 case VIEW_CONVERT_EXPR
:
2243 pp_c_cast_expression (this, e
);
2247 case TRUNC_MOD_EXPR
:
2248 case TRUNC_DIV_EXPR
:
2249 multiplicative_expression (e
);
2254 pp_c_shift_expression (this, e
);
2261 pp_c_relational_expression (this, e
);
2265 pp_c_and_expression (this, e
);
2269 case TRUTH_XOR_EXPR
:
2270 pp_c_exclusive_or_expression (this, e
);
2274 pp_c_inclusive_or_expression (this, e
);
2277 case TRUTH_ANDIF_EXPR
:
2278 case TRUTH_AND_EXPR
:
2279 pp_c_logical_and_expression (this, e
);
2282 case TRUTH_ORIF_EXPR
:
2284 pp_c_logical_or_expression (this, e
);
2289 pp_c_equality_expression (this, e
);
2293 conditional_expression (e
);
2296 case POINTER_PLUS_EXPR
:
2299 pp_c_additive_expression (this, e
);
2304 assignment_expression (e
);
2308 pp_c_left_paren (this);
2309 expression (TREE_OPERAND (e
, 0));
2310 pp_separate_with (this, ',');
2311 assignment_expression (TREE_OPERAND (e
, 1));
2312 pp_c_right_paren (this);
2315 case NON_LVALUE_EXPR
:
2317 expression (TREE_OPERAND (e
, 0));
2321 postfix_expression (TREE_OPERAND (e
, 1));
2326 /* We don't yet have a way of dumping statements in a
2327 human-readable format. */
2328 pp_string (this, "({...})");
2331 case C_MAYBE_CONST_EXPR
:
2332 expression (C_MAYBE_CONST_EXPR_EXPR (e
));
2336 pp_unsupported_tree (this, e
);
2346 c_pretty_printer::statement (tree stmt
)
2351 if (pp_needs_newline (this))
2352 pp_newline_and_indent (this, 0);
2354 dump_generic_node (this, stmt
, pp_indentation (this), 0, true);
2358 /* Initialize the PRETTY-PRINTER for handling C codes. */
2360 c_pretty_printer::c_pretty_printer ()
2361 : pretty_printer (),
2365 type_specifier_seq
= pp_c_specifier_qualifier_list
;
2366 ptr_operator
= pp_c_pointer
;
2367 parameter_list
= pp_c_parameter_type_list
;
2371 /* Print the tree T in full, on file FILE. */
2374 print_c_tree (FILE *file
, tree t
)
2376 c_pretty_printer pp
;
2378 pp_needs_newline (&pp
) = true;
2379 pp
.buffer
->stream
= file
;
2381 pp_newline_and_flush (&pp
);
2384 /* Print the tree T in full, on stderr. */
2387 debug_c_tree (tree t
)
2389 print_c_tree (stderr
, t
);
2390 fputc ('\n', stderr
);
2393 /* Output the DECL_NAME of T. If T has no DECL_NAME, output a string made
2394 up of T's memory address. */
2397 pp_c_tree_decl_identifier (c_pretty_printer
*pp
, tree t
)
2401 gcc_assert (DECL_P (t
));
2404 name
= IDENTIFIER_POINTER (DECL_NAME (t
));
2407 static char xname
[8];
2408 sprintf (xname
, "<U%4x>", ((unsigned)((uintptr_t)(t
) & 0xffff)));
2412 pp_c_identifier (pp
, name
);