1 /* Subroutines common to both C and C++ pretty-printers.
2 Copyright (C) 2002-2013 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"
34 /* The pretty-printer code is primarily designed to closely follow
35 (GNU) C and C++ grammars. That is to be contrasted with spaghetti
36 codes we used to have in the past. Following a structured
37 approach (preferably the official grammars) is believed to make it
38 much easier to add extensions and nifty pretty-printing effects that
39 takes expression or declaration contexts into account. */
42 #define pp_c_maybe_whitespace(PP) \
44 if ((PP)->padding == pp_before) \
45 pp_c_whitespace (PP); \
49 static void pp_c_char (c_pretty_printer
*, int);
51 /* postfix-expression */
52 static void pp_c_initializer_list (c_pretty_printer
*, tree
);
53 static void pp_c_brace_enclosed_initializer_list (c_pretty_printer
*, tree
);
55 static void pp_c_additive_expression (c_pretty_printer
*, tree
);
56 static void pp_c_shift_expression (c_pretty_printer
*, tree
);
57 static void pp_c_relational_expression (c_pretty_printer
*, tree
);
58 static void pp_c_equality_expression (c_pretty_printer
*, tree
);
59 static void pp_c_and_expression (c_pretty_printer
*, tree
);
60 static void pp_c_exclusive_or_expression (c_pretty_printer
*, tree
);
61 static void pp_c_inclusive_or_expression (c_pretty_printer
*, tree
);
62 static void pp_c_logical_and_expression (c_pretty_printer
*, tree
);
67 /* Helper functions. */
70 pp_c_whitespace (c_pretty_printer
*pp
)
73 pp
->padding
= pp_none
;
77 pp_c_left_paren (c_pretty_printer
*pp
)
80 pp
->padding
= pp_none
;
84 pp_c_right_paren (c_pretty_printer
*pp
)
87 pp
->padding
= pp_none
;
91 pp_c_left_brace (c_pretty_printer
*pp
)
94 pp
->padding
= pp_none
;
98 pp_c_right_brace (c_pretty_printer
*pp
)
101 pp
->padding
= pp_none
;
105 pp_c_left_bracket (c_pretty_printer
*pp
)
107 pp_left_bracket (pp
);
108 pp
->padding
= pp_none
;
112 pp_c_right_bracket (c_pretty_printer
*pp
)
114 pp_right_bracket (pp
);
115 pp
->padding
= pp_none
;
119 pp_c_dot (c_pretty_printer
*pp
)
122 pp
->padding
= pp_none
;
126 pp_c_ampersand (c_pretty_printer
*pp
)
129 pp
->padding
= pp_none
;
133 pp_c_star (c_pretty_printer
*pp
)
136 pp
->padding
= pp_none
;
140 pp_c_arrow (c_pretty_printer
*pp
)
143 pp
->padding
= pp_none
;
147 pp_c_semicolon (c_pretty_printer
*pp
)
150 pp
->padding
= pp_none
;
154 pp_c_complement (c_pretty_printer
*pp
)
157 pp
->padding
= pp_none
;
161 pp_c_exclamation (c_pretty_printer
*pp
)
164 pp
->padding
= pp_none
;
167 /* Print out the external representation of QUALIFIERS. */
170 pp_c_cv_qualifiers (c_pretty_printer
*pp
, int qualifiers
, bool func_type
)
172 const char *p
= pp_last_position_in_text (pp
);
173 bool previous
= false;
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
)
186 pp_c_ws_string (pp
, "_Atomic");
190 if (qualifiers
& TYPE_QUAL_CONST
)
193 pp_c_whitespace (pp
);
194 pp_c_ws_string (pp
, func_type
? "__attribute__((const))" : "const");
198 if (qualifiers
& TYPE_QUAL_VOLATILE
)
201 pp_c_whitespace (pp
);
202 pp_c_ws_string (pp
, func_type
? "__attribute__((noreturn))" : "volatile");
206 if (qualifiers
& TYPE_QUAL_RESTRICT
)
209 pp_c_whitespace (pp
);
210 pp_c_ws_string (pp
, (flag_isoc99
&& !c_dialect_cxx ()
211 ? "restrict" : "__restrict__"));
215 /* Pretty-print T using the type-cast notation '( type-name )'. */
218 pp_c_type_cast (c_pretty_printer
*pp
, tree t
)
220 pp_c_left_paren (pp
);
222 pp_c_right_paren (pp
);
225 /* We're about to pretty-print a pointer type as indicated by T.
226 Output a whitespace, if needed, preparing for subsequent output. */
229 pp_c_space_for_pointer_operator (c_pretty_printer
*pp
, tree t
)
231 if (POINTER_TYPE_P (t
))
233 tree pointee
= strip_pointer_operator (TREE_TYPE (t
));
234 if (TREE_CODE (pointee
) != ARRAY_TYPE
235 && TREE_CODE (pointee
) != FUNCTION_TYPE
)
236 pp_c_whitespace (pp
);
243 /* C++ cv-qualifiers are called type-qualifiers in C. Print out the
244 cv-qualifiers of T. If T is a declaration then it is the cv-qualifier
245 of its type. Take care of possible extensions.
249 type-qualifier-list type-qualifier
254 __restrict__ -- GNU C
255 address-space-qualifier -- GNU C
259 address-space-qualifier:
260 identifier -- GNU C */
263 pp_c_type_qualifier_list (c_pretty_printer
*pp
, tree t
)
267 if (!t
|| t
== error_mark_node
)
273 qualifiers
= TYPE_QUALS (t
);
274 pp_c_cv_qualifiers (pp
, qualifiers
,
275 TREE_CODE (t
) == FUNCTION_TYPE
);
277 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (t
)))
279 const char *as
= c_addr_space_name (TYPE_ADDR_SPACE (t
));
280 pp_c_identifier (pp
, as
);
285 * type-qualifier-list(opt)
286 * type-qualifier-list(opt) pointer */
289 pp_c_pointer (c_pretty_printer
*pp
, tree t
)
291 if (!TYPE_P (t
) && TREE_CODE (t
) != TYPE_DECL
)
293 switch (TREE_CODE (t
))
296 /* It is easier to handle C++ reference types here. */
298 if (TREE_CODE (TREE_TYPE (t
)) == POINTER_TYPE
)
299 pp_c_pointer (pp
, TREE_TYPE (t
));
300 if (TREE_CODE (t
) == POINTER_TYPE
)
304 pp_c_type_qualifier_list (pp
, t
);
307 /* ??? This node is now in GENERIC and so shouldn't be here. But
308 we'll fix that later. */
310 pp
->declaration (DECL_EXPR_DECL (t
));
311 pp_needs_newline (pp
) = true;
315 pp_unsupported_tree (pp
, t
);
319 /* simple-type-specifier:
335 struct-or-union-specifier
340 simple-type-specifier:
345 c_pretty_printer::simple_type_specifier (tree t
)
347 const enum tree_code code
= TREE_CODE (t
);
351 translate_string ("<type-error>");
354 case IDENTIFIER_NODE
:
355 pp_c_identifier (this, IDENTIFIER_POINTER (t
));
362 case FIXED_POINT_TYPE
:
366 simple_type_specifier (t
);
370 int prec
= TYPE_PRECISION (t
);
371 if (ALL_FIXED_POINT_MODE_P (TYPE_MODE (t
)))
372 t
= c_common_type_for_mode (TYPE_MODE (t
), TYPE_SATURATING (t
));
374 t
= c_common_type_for_mode (TYPE_MODE (t
), TYPE_UNSIGNED (t
));
377 simple_type_specifier (t
);
378 if (TYPE_PRECISION (t
) != prec
)
381 pp_decimal_int (this, prec
);
389 translate_string (TYPE_UNSIGNED (t
)
390 ? "<unnamed-unsigned:"
391 : "<unnamed-signed:");
394 translate_string ("<unnamed-float:");
396 case FIXED_POINT_TYPE
:
397 translate_string ("<unnamed-fixed:");
402 pp_decimal_int (this, prec
);
412 translate_string ("<typedef-error>");
418 if (code
== UNION_TYPE
)
419 pp_c_ws_string (this, "union");
420 else if (code
== RECORD_TYPE
)
421 pp_c_ws_string (this, "struct");
422 else if (code
== ENUMERAL_TYPE
)
423 pp_c_ws_string (this, "enum");
425 translate_string ("<tag-error>");
428 id_expression (TYPE_NAME (t
));
430 translate_string ("<anonymous>");
434 pp_unsupported_tree (this, t
);
439 /* specifier-qualifier-list:
440 type-specifier specifier-qualifier-list-opt
441 type-qualifier specifier-qualifier-list-opt
444 Implementation note: Because of the non-linearities in array or
445 function declarations, this routine prints not just the
446 specifier-qualifier-list of such entities or types of such entities,
447 but also the 'pointer' production part of their declarators. The
448 remaining part is done by declarator() or abstract_declarator(). */
451 pp_c_specifier_qualifier_list (c_pretty_printer
*pp
, tree t
)
453 const enum tree_code code
= TREE_CODE (t
);
455 if (!(pp
->flags
& pp_c_flag_gnu_v3
) && code
!= POINTER_TYPE
)
456 pp_c_type_qualifier_list (pp
, t
);
462 /* Get the types-specifier of this type. */
463 tree pointee
= strip_pointer_operator (TREE_TYPE (t
));
464 pp_c_specifier_qualifier_list (pp
, pointee
);
465 if (TREE_CODE (pointee
) == ARRAY_TYPE
466 || TREE_CODE (pointee
) == FUNCTION_TYPE
)
468 pp_c_whitespace (pp
);
469 pp_c_left_paren (pp
);
470 pp_c_attributes_display (pp
, TYPE_ATTRIBUTES (pointee
));
472 else if (!c_dialect_cxx ())
473 pp_c_whitespace (pp
);
474 pp_ptr_operator (pp
, t
);
480 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
485 if (code
== COMPLEX_TYPE
)
486 pp_c_ws_string (pp
, (flag_isoc99
&& !c_dialect_cxx ()
487 ? "_Complex" : "__complex__"));
488 else if (code
== VECTOR_TYPE
)
490 pp_c_ws_string (pp
, "__vector");
491 pp_c_left_paren (pp
);
492 pp_wide_integer (pp
, TYPE_VECTOR_SUBPARTS (t
));
493 pp_c_right_paren (pp
);
494 pp_c_whitespace (pp
);
496 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
500 pp
->simple_type_specifier (t
);
503 if ((pp
->flags
& pp_c_flag_gnu_v3
) && code
!= POINTER_TYPE
)
504 pp_c_type_qualifier_list (pp
, t
);
507 /* parameter-type-list:
512 parameter-declaration
513 parameter-list , parameter-declaration
515 parameter-declaration:
516 declaration-specifiers declarator
517 declaration-specifiers abstract-declarator(opt) */
520 pp_c_parameter_type_list (c_pretty_printer
*pp
, tree t
)
522 bool want_parm_decl
= DECL_P (t
) && !(pp
->flags
& pp_c_flag_abstract
);
523 tree parms
= want_parm_decl
? DECL_ARGUMENTS (t
) : TYPE_ARG_TYPES (t
);
524 pp_c_left_paren (pp
);
525 if (parms
== void_list_node
)
526 pp_c_ws_string (pp
, "void");
530 for ( ; parms
&& parms
!= void_list_node
; parms
= TREE_CHAIN (parms
))
533 pp_separate_with (pp
, ',');
535 pp
->declaration_specifiers
536 (want_parm_decl
? parms
: TREE_VALUE (parms
));
538 pp
->declarator (parms
);
540 pp
->abstract_declarator (TREE_VALUE (parms
));
543 pp_c_right_paren (pp
);
546 /* abstract-declarator:
548 pointer(opt) direct-abstract-declarator */
551 c_pretty_printer::abstract_declarator (tree t
)
553 if (TREE_CODE (t
) == POINTER_TYPE
)
555 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
556 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
557 pp_c_right_paren (this);
561 direct_abstract_declarator (t
);
564 /* direct-abstract-declarator:
565 ( abstract-declarator )
566 direct-abstract-declarator(opt) [ assignment-expression(opt) ]
567 direct-abstract-declarator(opt) [ * ]
568 direct-abstract-declarator(opt) ( parameter-type-list(opt) ) */
571 c_pretty_printer::direct_abstract_declarator (tree t
)
573 switch (TREE_CODE (t
))
576 abstract_declarator (t
);
580 pp_c_parameter_type_list (this, t
);
581 direct_abstract_declarator (TREE_TYPE (t
));
585 pp_c_left_bracket (this);
586 if (TYPE_DOMAIN (t
) && TYPE_MAX_VALUE (TYPE_DOMAIN (t
)))
588 tree maxval
= TYPE_MAX_VALUE (TYPE_DOMAIN (t
));
589 tree type
= TREE_TYPE (maxval
);
591 if (tree_fits_shwi_p (maxval
))
592 pp_wide_integer (this, tree_to_shwi (maxval
) + 1);
594 expression (fold_build2 (PLUS_EXPR
, type
, maxval
,
595 build_int_cst (type
, 1)));
597 pp_c_right_bracket (this);
598 direct_abstract_declarator (TREE_TYPE (t
));
601 case IDENTIFIER_NODE
:
606 case FIXED_POINT_TYPE
:
616 pp_unsupported_tree (this, t
);
622 specifier-qualifier-list abstract-declarator(opt) */
625 c_pretty_printer::type_id (tree t
)
627 pp_c_specifier_qualifier_list (this, t
);
628 abstract_declarator (t
);
631 /* storage-class-specifier:
639 c_pretty_printer::storage_class_specifier (tree t
)
641 if (TREE_CODE (t
) == TYPE_DECL
)
642 pp_c_ws_string (this, "typedef");
645 if (DECL_REGISTER (t
))
646 pp_c_ws_string (this, "register");
647 else if (TREE_STATIC (t
) && TREE_CODE (t
) == VAR_DECL
)
648 pp_c_ws_string (this, "static");
652 /* function-specifier:
656 c_pretty_printer::function_specifier (tree t
)
658 if (TREE_CODE (t
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (t
))
659 pp_c_ws_string (this, "inline");
662 /* declaration-specifiers:
663 storage-class-specifier declaration-specifiers(opt)
664 type-specifier declaration-specifiers(opt)
665 type-qualifier declaration-specifiers(opt)
666 function-specifier declaration-specifiers(opt) */
669 c_pretty_printer::declaration_specifiers (tree t
)
671 storage_class_specifier (t
);
672 function_specifier (t
);
673 pp_c_specifier_qualifier_list (this, DECL_P (t
) ? TREE_TYPE (t
) : t
);
679 direct-declarator [ type-qualifier-list(opt) assignment-expression(opt) ]
680 direct-declarator [ static type-qualifier-list(opt) assignment-expression(opt)]
681 direct-declarator [ type-qualifier-list static assignment-expression ]
682 direct-declarator [ type-qualifier-list * ]
683 direct-declarator ( parameter-type-list )
684 direct-declarator ( identifier-list(opt) ) */
687 c_pretty_printer::direct_declarator (tree t
)
689 switch (TREE_CODE (t
))
696 pp_c_space_for_pointer_operator (this, TREE_TYPE (t
));
697 pp_c_tree_decl_identifier (this, t
);
702 abstract_declarator (TREE_TYPE (t
));
706 pp_parameter_list (this, t
);
707 abstract_declarator (TREE_TYPE (t
));
711 pp_c_space_for_pointer_operator (this, TREE_TYPE (TREE_TYPE (t
)));
712 pp_c_tree_decl_identifier (this, t
);
713 if (flags
& pp_c_flag_abstract
)
714 abstract_declarator (TREE_TYPE (t
));
717 pp_parameter_list (this, t
);
718 abstract_declarator (TREE_TYPE (TREE_TYPE (t
)));
724 case FIXED_POINT_TYPE
:
731 pp_unsupported_tree (this, t
);
738 pointer(opt) direct-declarator */
741 c_pretty_printer::declarator (tree t
)
743 switch (TREE_CODE (t
))
747 case FIXED_POINT_TYPE
:
760 direct_declarator (t
);
765 pp_unsupported_tree (this, t
);
771 declaration-specifiers init-declarator-list(opt) ; */
774 c_pretty_printer::declaration (tree t
)
776 declaration_specifiers (t
);
777 pp_c_init_declarator (this, t
);
780 /* Pretty-print ATTRIBUTES using GNU C extension syntax. */
783 pp_c_attributes (c_pretty_printer
*pp
, tree attributes
)
785 if (attributes
== NULL_TREE
)
788 pp_c_ws_string (pp
, "__attribute__");
789 pp_c_left_paren (pp
);
790 pp_c_left_paren (pp
);
791 for (; attributes
!= NULL_TREE
; attributes
= TREE_CHAIN (attributes
))
793 pp_tree_identifier (pp
, TREE_PURPOSE (attributes
));
794 if (TREE_VALUE (attributes
))
795 pp_c_call_argument_list (pp
, TREE_VALUE (attributes
));
797 if (TREE_CHAIN (attributes
))
798 pp_separate_with (pp
, ',');
800 pp_c_right_paren (pp
);
801 pp_c_right_paren (pp
);
804 /* Pretty-print ATTRIBUTES using GNU C extension syntax for attributes
805 marked to be displayed on disgnostic. */
808 pp_c_attributes_display (c_pretty_printer
*pp
, tree a
)
810 bool is_first
= true;
815 for (; a
!= NULL_TREE
; a
= TREE_CHAIN (a
))
817 const struct attribute_spec
*as
;
818 as
= lookup_attribute_spec (TREE_PURPOSE (a
));
819 if (!as
|| as
->affects_type_identity
== false)
823 pp_c_ws_string (pp
, "__attribute__");
824 pp_c_left_paren (pp
);
825 pp_c_left_paren (pp
);
830 pp_separate_with (pp
, ',');
832 pp_tree_identifier (pp
, TREE_PURPOSE (a
));
834 pp_c_call_argument_list (pp
, TREE_VALUE (a
));
839 pp_c_right_paren (pp
);
840 pp_c_right_paren (pp
);
841 pp_c_whitespace (pp
);
845 /* function-definition:
846 declaration-specifiers declarator compound-statement */
849 pp_c_function_definition (c_pretty_printer
*pp
, tree t
)
851 pp
->declaration_specifiers (t
);
853 pp_needs_newline (pp
) = true;
854 pp
->statement (DECL_SAVED_TREE (t
));
855 pp_newline_and_flush (pp
);
861 /* Print out a c-char. This is called solely for characters which are
862 in the *target* execution character set. We ought to convert them
863 back to the *host* execution character set before printing, but we
864 have no way to do this at present. A decent compromise is to print
865 all characters as if they were in the host execution character set,
866 and not attempt to recover any named escape characters, but render
867 all unprintables as octal escapes. If the host and target character
868 sets are the same, this produces relatively readable output. If they
869 are not the same, strings may appear as gibberish, but that's okay
870 (in fact, it may well be what the reader wants, e.g. if they are looking
871 to see if conversion to the target character set happened correctly).
873 A special case: we need to prefix \, ", and ' with backslashes. It is
874 correct to do so for the *host*'s \, ", and ', because the rest of the
875 file appears in the host character set. */
878 pp_c_char (c_pretty_printer
*pp
, int c
)
884 case '\\': pp_string (pp
, "\\\\"); break;
885 case '\'': pp_string (pp
, "\\\'"); break;
886 case '\"': pp_string (pp
, "\\\""); break;
887 default: pp_character (pp
, c
);
891 pp_scalar (pp
, "\\%03o", (unsigned) c
);
894 /* Print out a STRING literal. */
897 pp_c_string_literal (c_pretty_printer
*pp
, tree s
)
899 const char *p
= TREE_STRING_POINTER (s
);
900 int n
= TREE_STRING_LENGTH (s
) - 1;
903 for (i
= 0; i
< n
; ++i
)
904 pp_c_char (pp
, p
[i
]);
908 /* Pretty-print an INTEGER literal. */
911 pp_c_integer_constant (c_pretty_printer
*pp
, tree i
)
913 /* We are going to compare the type of I to other types using
914 pointer comparison so we need to use its canonical type. */
916 TYPE_CANONICAL (TREE_TYPE (i
))
917 ? TYPE_CANONICAL (TREE_TYPE (i
))
920 if (tree_fits_shwi_p (i
))
921 pp_wide_integer (pp
, tree_to_shwi (i
));
922 else if (tree_fits_uhwi_p (i
))
923 pp_unsigned_wide_integer (pp
, tree_to_uhwi (i
));
926 unsigned HOST_WIDE_INT low
= TREE_INT_CST_LOW (i
);
927 HOST_WIDE_INT high
= TREE_INT_CST_HIGH (i
);
928 if (tree_int_cst_sgn (i
) < 0)
934 sprintf (pp_buffer (pp
)->digit_buffer
, HOST_WIDE_INT_PRINT_DOUBLE_HEX
,
935 (unsigned HOST_WIDE_INT
) high
, (unsigned HOST_WIDE_INT
) low
);
936 pp_string (pp
, pp_buffer (pp
)->digit_buffer
);
938 if (TYPE_UNSIGNED (type
))
939 pp_character (pp
, 'u');
940 if (type
== long_integer_type_node
|| type
== long_unsigned_type_node
)
941 pp_character (pp
, 'l');
942 else if (type
== long_long_integer_type_node
943 || type
== long_long_unsigned_type_node
)
944 pp_string (pp
, "ll");
945 else if (type
== int128_integer_type_node
946 || type
== int128_unsigned_type_node
)
947 pp_string (pp
, "I128");
950 /* Print out a CHARACTER literal. */
953 pp_c_character_constant (c_pretty_printer
*pp
, tree c
)
956 pp_c_char (pp
, (unsigned) TREE_INT_CST_LOW (c
));
960 /* Print out a BOOLEAN literal. */
963 pp_c_bool_constant (c_pretty_printer
*pp
, tree b
)
965 if (b
== boolean_false_node
)
967 if (c_dialect_cxx ())
968 pp_c_ws_string (pp
, "false");
969 else if (flag_isoc99
)
970 pp_c_ws_string (pp
, "_False");
972 pp_unsupported_tree (pp
, b
);
974 else if (b
== boolean_true_node
)
976 if (c_dialect_cxx ())
977 pp_c_ws_string (pp
, "true");
978 else if (flag_isoc99
)
979 pp_c_ws_string (pp
, "_True");
981 pp_unsupported_tree (pp
, b
);
983 else if (TREE_CODE (b
) == INTEGER_CST
)
984 pp_c_integer_constant (pp
, b
);
986 pp_unsupported_tree (pp
, b
);
989 /* Attempt to print out an ENUMERATOR. Return true on success. Else return
990 false; that means the value was obtained by a cast, in which case
991 print out the type-id part of the cast-expression -- the casted value
992 is then printed by pp_c_integer_literal. */
995 pp_c_enumeration_constant (c_pretty_printer
*pp
, tree e
)
997 bool value_is_named
= true;
998 tree type
= TREE_TYPE (e
);
1001 /* Find the name of this constant. */
1002 for (value
= TYPE_VALUES (type
);
1003 value
!= NULL_TREE
&& !tree_int_cst_equal (TREE_VALUE (value
), e
);
1004 value
= TREE_CHAIN (value
))
1007 if (value
!= NULL_TREE
)
1008 pp
->id_expression (TREE_PURPOSE (value
));
1011 /* Value must have been cast. */
1012 pp_c_type_cast (pp
, type
);
1013 value_is_named
= false;
1016 return value_is_named
;
1019 /* Print out a REAL value as a decimal-floating-constant. */
1022 pp_c_floating_constant (c_pretty_printer
*pp
, tree r
)
1024 const struct real_format
*fmt
1025 = REAL_MODE_FORMAT (TYPE_MODE (TREE_TYPE (r
)));
1027 REAL_VALUE_TYPE floating_cst
= TREE_REAL_CST (r
);
1028 bool is_decimal
= floating_cst
.decimal
;
1030 /* See ISO C++ WG N1822. Note: The fraction 643/2136 approximates
1031 log10(2) to 7 significant digits. */
1032 int max_digits10
= 2 + (is_decimal
? fmt
->p
: fmt
->p
* 643L / 2136);
1034 real_to_decimal (pp_buffer (pp
)->digit_buffer
, &TREE_REAL_CST (r
),
1035 sizeof (pp_buffer (pp
)->digit_buffer
),
1038 pp_string (pp
, pp_buffer(pp
)->digit_buffer
);
1039 if (TREE_TYPE (r
) == float_type_node
)
1040 pp_character (pp
, 'f');
1041 else if (TREE_TYPE (r
) == long_double_type_node
)
1042 pp_character (pp
, 'l');
1043 else if (TREE_TYPE (r
) == dfloat128_type_node
)
1044 pp_string (pp
, "dl");
1045 else if (TREE_TYPE (r
) == dfloat64_type_node
)
1046 pp_string (pp
, "dd");
1047 else if (TREE_TYPE (r
) == dfloat32_type_node
)
1048 pp_string (pp
, "df");
1051 /* Print out a FIXED value as a decimal-floating-constant. */
1054 pp_c_fixed_constant (c_pretty_printer
*pp
, tree r
)
1056 fixed_to_decimal (pp_buffer (pp
)->digit_buffer
, &TREE_FIXED_CST (r
),
1057 sizeof (pp_buffer (pp
)->digit_buffer
));
1058 pp_string (pp
, pp_buffer(pp
)->digit_buffer
);
1061 /* Pretty-print a compound literal expression. GNU extensions include
1062 vector constants. */
1065 pp_c_compound_literal (c_pretty_printer
*pp
, tree e
)
1067 tree type
= TREE_TYPE (e
);
1068 pp_c_type_cast (pp
, type
);
1070 switch (TREE_CODE (type
))
1077 pp_c_brace_enclosed_initializer_list (pp
, e
);
1081 pp_unsupported_tree (pp
, e
);
1086 /* Pretty-print a COMPLEX_EXPR expression. */
1089 pp_c_complex_expr (c_pretty_printer
*pp
, tree e
)
1091 /* Handle a few common special cases, otherwise fallback
1092 to printing it as compound literal. */
1093 tree type
= TREE_TYPE (e
);
1094 tree realexpr
= TREE_OPERAND (e
, 0);
1095 tree imagexpr
= TREE_OPERAND (e
, 1);
1097 /* Cast of an COMPLEX_TYPE expression to a different COMPLEX_TYPE. */
1098 if (TREE_CODE (realexpr
) == NOP_EXPR
1099 && TREE_CODE (imagexpr
) == NOP_EXPR
1100 && TREE_TYPE (realexpr
) == TREE_TYPE (type
)
1101 && TREE_TYPE (imagexpr
) == TREE_TYPE (type
)
1102 && TREE_CODE (TREE_OPERAND (realexpr
, 0)) == REALPART_EXPR
1103 && TREE_CODE (TREE_OPERAND (imagexpr
, 0)) == IMAGPART_EXPR
1104 && TREE_OPERAND (TREE_OPERAND (realexpr
, 0), 0)
1105 == TREE_OPERAND (TREE_OPERAND (imagexpr
, 0), 0))
1107 pp_c_type_cast (pp
, type
);
1108 pp
->expression (TREE_OPERAND (TREE_OPERAND (realexpr
, 0), 0));
1112 /* Cast of an scalar expression to COMPLEX_TYPE. */
1113 if ((integer_zerop (imagexpr
) || real_zerop (imagexpr
))
1114 && TREE_TYPE (realexpr
) == TREE_TYPE (type
))
1116 pp_c_type_cast (pp
, type
);
1117 if (TREE_CODE (realexpr
) == NOP_EXPR
)
1118 realexpr
= TREE_OPERAND (realexpr
, 0);
1119 pp
->expression (realexpr
);
1123 pp_c_compound_literal (pp
, e
);
1129 fixed-point-constant
1130 enumeration-constant
1131 character-constant */
1134 c_pretty_printer::constant (tree e
)
1136 const enum tree_code code
= TREE_CODE (e
);
1142 tree type
= TREE_TYPE (e
);
1143 if (type
== boolean_type_node
)
1144 pp_c_bool_constant (this, e
);
1145 else if (type
== char_type_node
)
1146 pp_c_character_constant (this, e
);
1147 else if (TREE_CODE (type
) == ENUMERAL_TYPE
1148 && pp_c_enumeration_constant (this, e
))
1151 pp_c_integer_constant (this, e
);
1156 pp_c_floating_constant (this, e
);
1160 pp_c_fixed_constant (this, e
);
1164 pp_c_string_literal (this, e
);
1168 /* Sometimes, we are confused and we think a complex literal
1169 is a constant. Such thing is a compound literal which
1170 grammatically belongs to postfix-expr production. */
1171 pp_c_compound_literal (this, e
);
1175 pp_unsupported_tree (this, e
);
1180 /* Pretty-print a string such as an identifier, without changing its
1181 encoding, preceded by whitespace is necessary. */
1184 pp_c_ws_string (c_pretty_printer
*pp
, const char *str
)
1186 pp_c_maybe_whitespace (pp
);
1187 pp_string (pp
, str
);
1188 pp
->padding
= pp_before
;
1192 c_pretty_printer::translate_string (const char *gmsgid
)
1194 if (pp_translate_identifiers (this))
1195 pp_c_ws_string (this, _(gmsgid
));
1197 pp_c_ws_string (this, gmsgid
);
1200 /* Pretty-print an IDENTIFIER_NODE, which may contain UTF-8 sequences
1201 that need converting to the locale encoding, preceded by whitespace
1205 pp_c_identifier (c_pretty_printer
*pp
, const char *id
)
1207 pp_c_maybe_whitespace (pp
);
1208 pp_identifier (pp
, id
);
1209 pp
->padding
= pp_before
;
1212 /* Pretty-print a C primary-expression.
1220 c_pretty_printer::primary_expression (tree e
)
1222 switch (TREE_CODE (e
))
1230 pp_c_tree_decl_identifier (this, e
);
1233 case IDENTIFIER_NODE
:
1234 pp_c_tree_identifier (this, e
);
1238 translate_string ("<erroneous-expression>");
1242 translate_string ("<return-value>");
1253 pp_c_ws_string (this, "__builtin_memcpy");
1254 pp_c_left_paren (this);
1255 pp_ampersand (this);
1256 primary_expression (TREE_OPERAND (e
, 0));
1257 pp_separate_with (this, ',');
1258 pp_ampersand (this);
1259 initializer (TREE_OPERAND (e
, 1));
1260 if (TREE_OPERAND (e
, 2))
1262 pp_separate_with (this, ',');
1263 expression (TREE_OPERAND (e
, 2));
1265 pp_c_right_paren (this);
1269 /* FIXME: Make sure we won't get into an infinite loop. */
1270 pp_c_left_paren (this);
1272 pp_c_right_paren (this);
1277 /* Print out a C initializer -- also support C compound-literals.
1279 assignment-expression:
1280 { initializer-list }
1281 { initializer-list , } */
1284 c_pretty_printer::initializer (tree e
)
1286 if (TREE_CODE (e
) == CONSTRUCTOR
)
1287 pp_c_brace_enclosed_initializer_list (this, e
);
1294 declarator = initializer */
1297 pp_c_init_declarator (c_pretty_printer
*pp
, tree t
)
1300 /* We don't want to output function definitions here. There are handled
1301 elsewhere (and the syntactic form is bogus anyway). */
1302 if (TREE_CODE (t
) != FUNCTION_DECL
&& DECL_INITIAL (t
))
1304 tree init
= DECL_INITIAL (t
);
1305 /* This C++ bit is handled here because it is easier to do so.
1306 In templates, the C++ parser builds a TREE_LIST for a
1307 direct-initialization; the TREE_PURPOSE is the variable to
1308 initialize and the TREE_VALUE is the initializer. */
1309 if (TREE_CODE (init
) == TREE_LIST
)
1311 pp_c_left_paren (pp
);
1312 pp
->expression (TREE_VALUE (init
));
1313 pp_right_paren (pp
);
1320 pp
->initializer (init
);
1325 /* initializer-list:
1326 designation(opt) initializer
1327 initializer-list , designation(opt) initializer
1334 designator-list designator
1337 [ constant-expression ]
1341 pp_c_initializer_list (c_pretty_printer
*pp
, tree e
)
1343 tree type
= TREE_TYPE (e
);
1344 const enum tree_code code
= TREE_CODE (type
);
1346 if (TREE_CODE (e
) == CONSTRUCTOR
)
1348 pp_c_constructor_elts (pp
, CONSTRUCTOR_ELTS (e
));
1358 tree init
= TREE_OPERAND (e
, 0);
1359 for (; init
!= NULL_TREE
; init
= TREE_CHAIN (init
))
1361 if (code
== RECORD_TYPE
|| code
== UNION_TYPE
)
1364 pp
->primary_expression (TREE_PURPOSE (init
));
1368 pp_c_left_bracket (pp
);
1369 if (TREE_PURPOSE (init
))
1370 pp
->constant (TREE_PURPOSE (init
));
1371 pp_c_right_bracket (pp
);
1373 pp_c_whitespace (pp
);
1375 pp_c_whitespace (pp
);
1376 pp
->initializer (TREE_VALUE (init
));
1377 if (TREE_CHAIN (init
))
1378 pp_separate_with (pp
, ',');
1384 if (TREE_CODE (e
) == VECTOR_CST
)
1387 for (i
= 0; i
< VECTOR_CST_NELTS (e
); ++i
)
1390 pp_separate_with (pp
, ',');
1391 pp
->expression (VECTOR_CST_ELT (e
, i
));
1399 if (TREE_CODE (e
) == COMPLEX_CST
|| TREE_CODE (e
) == COMPLEX_EXPR
)
1401 const bool cst
= TREE_CODE (e
) == COMPLEX_CST
;
1402 pp
->expression (cst
? TREE_REALPART (e
) : TREE_OPERAND (e
, 0));
1403 pp_separate_with (pp
, ',');
1404 pp
->expression (cst
? TREE_IMAGPART (e
) : TREE_OPERAND (e
, 1));
1414 pp_unsupported_tree (pp
, type
);
1417 /* Pretty-print a brace-enclosed initializer-list. */
1420 pp_c_brace_enclosed_initializer_list (c_pretty_printer
*pp
, tree l
)
1422 pp_c_left_brace (pp
);
1423 pp_c_initializer_list (pp
, l
);
1424 pp_c_right_brace (pp
);
1428 /* This is a convenient function, used to bridge gap between C and C++
1435 c_pretty_printer::id_expression (tree t
)
1437 switch (TREE_CODE (t
))
1446 pp_c_tree_decl_identifier (this, t
);
1449 case IDENTIFIER_NODE
:
1450 pp_c_tree_identifier (this, t
);
1454 pp_unsupported_tree (this, t
);
1459 /* postfix-expression:
1461 postfix-expression [ expression ]
1462 postfix-expression ( argument-expression-list(opt) )
1463 postfix-expression . identifier
1464 postfix-expression -> identifier
1465 postfix-expression ++
1466 postfix-expression --
1467 ( type-name ) { initializer-list }
1468 ( type-name ) { initializer-list , } */
1471 c_pretty_printer::postfix_expression (tree e
)
1473 enum tree_code code
= TREE_CODE (e
);
1476 case POSTINCREMENT_EXPR
:
1477 case POSTDECREMENT_EXPR
:
1478 postfix_expression (TREE_OPERAND (e
, 0));
1479 pp_string (this, code
== POSTINCREMENT_EXPR
? "++" : "--");
1483 postfix_expression (TREE_OPERAND (e
, 0));
1484 pp_c_left_bracket (this);
1485 expression (TREE_OPERAND (e
, 1));
1486 pp_c_right_bracket (this);
1489 case ARRAY_NOTATION_REF
:
1490 postfix_expression (ARRAY_NOTATION_ARRAY (e
));
1491 pp_c_left_bracket (this);
1492 expression (ARRAY_NOTATION_START (e
));
1494 expression (ARRAY_NOTATION_LENGTH (e
));
1496 expression (ARRAY_NOTATION_STRIDE (e
));
1497 pp_c_right_bracket (this);
1502 call_expr_arg_iterator iter
;
1504 postfix_expression (CALL_EXPR_FN (e
));
1505 pp_c_left_paren (this);
1506 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, e
)
1509 if (more_call_expr_args_p (&iter
))
1510 pp_separate_with (this, ',');
1512 pp_c_right_paren (this);
1516 case UNORDERED_EXPR
:
1517 pp_c_ws_string (this, flag_isoc99
1519 : "__builtin_isunordered");
1523 pp_c_ws_string (this, flag_isoc99
1525 : "!__builtin_isunordered");
1529 pp_c_ws_string (this, flag_isoc99
1531 : "!__builtin_isgreaterequal");
1535 pp_c_ws_string (this, flag_isoc99
1537 : "!__builtin_isgreater");
1541 pp_c_ws_string (this, flag_isoc99
1543 : "!__builtin_islessequal");
1547 pp_c_ws_string (this, flag_isoc99
1549 : "!__builtin_isless");
1553 pp_c_ws_string (this, flag_isoc99
1555 : "!__builtin_islessgreater");
1559 pp_c_ws_string (this, flag_isoc99
1561 : "__builtin_islessgreater");
1565 pp_c_left_paren (this);
1566 expression (TREE_OPERAND (e
, 0));
1567 pp_separate_with (this, ',');
1568 expression (TREE_OPERAND (e
, 1));
1569 pp_c_right_paren (this);
1573 pp_c_ws_string (this, "__builtin_abs");
1574 pp_c_left_paren (this);
1575 expression (TREE_OPERAND (e
, 0));
1576 pp_c_right_paren (this);
1581 tree object
= TREE_OPERAND (e
, 0);
1582 if (TREE_CODE (object
) == INDIRECT_REF
)
1584 postfix_expression (TREE_OPERAND (object
, 0));
1589 postfix_expression (object
);
1592 expression (TREE_OPERAND (e
, 1));
1598 tree type
= TREE_TYPE (e
);
1600 type
= signed_or_unsigned_type_for (TYPE_UNSIGNED (type
), type
);
1602 && tree_int_cst_equal (TYPE_SIZE (type
), TREE_OPERAND (e
, 1)))
1604 HOST_WIDE_INT bitpos
= tree_to_shwi (TREE_OPERAND (e
, 2));
1605 HOST_WIDE_INT size
= tree_to_shwi (TYPE_SIZE (type
));
1606 if ((bitpos
% size
) == 0)
1608 pp_c_left_paren (this);
1609 pp_c_left_paren (this);
1612 pp_c_right_paren (this);
1613 pp_c_ampersand (this);
1614 expression (TREE_OPERAND (e
, 0));
1615 pp_c_right_paren (this);
1616 pp_c_left_bracket (this);
1617 pp_wide_integer (this, bitpos
/ size
);
1618 pp_c_right_bracket (this);
1622 pp_unsupported_tree (this, e
);
1632 pp_c_compound_literal (this, e
);
1636 pp_c_complex_expr (this, e
);
1639 case COMPOUND_LITERAL_EXPR
:
1640 e
= DECL_INITIAL (COMPOUND_LITERAL_EXPR_DECL (e
));
1647 pp_c_ws_string (this, "__builtin_va_arg");
1648 pp_c_left_paren (this);
1649 assignment_expression (TREE_OPERAND (e
, 0));
1650 pp_separate_with (this, ',');
1651 type_id (TREE_TYPE (e
));
1652 pp_c_right_paren (this);
1656 if (TREE_CODE (TREE_OPERAND (e
, 0)) == FUNCTION_DECL
)
1658 id_expression (TREE_OPERAND (e
, 0));
1661 /* else fall through. */
1664 primary_expression (e
);
1669 /* Print out an expression-list; E is expected to be a TREE_LIST. */
1672 pp_c_expression_list (c_pretty_printer
*pp
, tree e
)
1674 for (; e
!= NULL_TREE
; e
= TREE_CHAIN (e
))
1676 pp
->expression (TREE_VALUE (e
));
1678 pp_separate_with (pp
, ',');
1682 /* Print out V, which contains the elements of a constructor. */
1685 pp_c_constructor_elts (c_pretty_printer
*pp
, vec
<constructor_elt
, va_gc
> *v
)
1687 unsigned HOST_WIDE_INT ix
;
1690 FOR_EACH_CONSTRUCTOR_VALUE (v
, ix
, value
)
1692 pp
->expression (value
);
1693 if (ix
!= vec_safe_length (v
) - 1)
1694 pp_separate_with (pp
, ',');
1698 /* Print out an expression-list in parens, as if it were the argument
1699 list to a function. */
1702 pp_c_call_argument_list (c_pretty_printer
*pp
, tree t
)
1704 pp_c_left_paren (pp
);
1705 if (t
&& TREE_CODE (t
) == TREE_LIST
)
1706 pp_c_expression_list (pp
, t
);
1707 pp_c_right_paren (pp
);
1710 /* unary-expression:
1714 unary-operator cast-expression
1715 sizeof unary-expression
1718 unary-operator: one of
1723 __alignof__ unary-expression
1724 __alignof__ ( type-id )
1725 __real__ unary-expression
1726 __imag__ unary-expression */
1729 c_pretty_printer::unary_expression (tree e
)
1731 enum tree_code code
= TREE_CODE (e
);
1734 case PREINCREMENT_EXPR
:
1735 case PREDECREMENT_EXPR
:
1736 pp_string (this, code
== PREINCREMENT_EXPR
? "++" : "--");
1737 unary_expression (TREE_OPERAND (e
, 0));
1744 case TRUTH_NOT_EXPR
:
1746 /* String literal are used by address. */
1747 if (code
== ADDR_EXPR
&& TREE_CODE (TREE_OPERAND (e
, 0)) != STRING_CST
)
1748 pp_ampersand (this);
1749 else if (code
== INDIRECT_REF
)
1751 else if (code
== NEGATE_EXPR
)
1753 else if (code
== BIT_NOT_EXPR
|| code
== CONJ_EXPR
)
1754 pp_complement (this);
1755 else if (code
== TRUTH_NOT_EXPR
)
1756 pp_exclamation (this);
1757 pp_c_cast_expression (this, TREE_OPERAND (e
, 0));
1761 if (TREE_CODE (TREE_OPERAND (e
, 0)) == ADDR_EXPR
1762 && integer_zerop (TREE_OPERAND (e
, 1)))
1763 expression (TREE_OPERAND (TREE_OPERAND (e
, 0), 0));
1767 if (!integer_zerop (TREE_OPERAND (e
, 1)))
1769 pp_c_left_paren (this);
1770 if (!integer_onep (TYPE_SIZE_UNIT
1771 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (e
, 0))))))
1772 pp_c_type_cast (this, ptr_type_node
);
1774 pp_c_cast_expression (this, TREE_OPERAND (e
, 0));
1775 if (!integer_zerop (TREE_OPERAND (e
, 1)))
1778 pp_c_integer_constant (this,
1779 fold_convert (ssizetype
,
1780 TREE_OPERAND (e
, 1)));
1781 pp_c_right_paren (this);
1788 pp_c_ws_string (this, code
== REALPART_EXPR
? "__real__" : "__imag__");
1789 pp_c_whitespace (this);
1790 unary_expression (TREE_OPERAND (e
, 0));
1794 postfix_expression (e
);
1801 ( type-name ) cast-expression */
1804 pp_c_cast_expression (c_pretty_printer
*pp
, tree e
)
1806 switch (TREE_CODE (e
))
1809 case FIX_TRUNC_EXPR
:
1811 case VIEW_CONVERT_EXPR
:
1812 pp_c_type_cast (pp
, TREE_TYPE (e
));
1813 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 0));
1817 pp
->unary_expression (e
);
1821 /* multiplicative-expression:
1823 multiplicative-expression * cast-expression
1824 multiplicative-expression / cast-expression
1825 multiplicative-expression % cast-expression */
1828 c_pretty_printer::multiplicative_expression (tree e
)
1830 enum tree_code code
= TREE_CODE (e
);
1834 case TRUNC_DIV_EXPR
:
1835 case TRUNC_MOD_EXPR
:
1836 multiplicative_expression (TREE_OPERAND (e
, 0));
1837 pp_c_whitespace (this);
1838 if (code
== MULT_EXPR
)
1840 else if (code
== TRUNC_DIV_EXPR
)
1844 pp_c_whitespace (this);
1845 pp_c_cast_expression (this, TREE_OPERAND (e
, 1));
1849 pp_c_cast_expression (this, e
);
1854 /* additive-expression:
1855 multiplicative-expression
1856 additive-expression + multiplicative-expression
1857 additive-expression - multiplicative-expression */
1860 pp_c_additive_expression (c_pretty_printer
*pp
, tree e
)
1862 enum tree_code code
= TREE_CODE (e
);
1865 case POINTER_PLUS_EXPR
:
1868 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 0));
1869 pp_c_whitespace (pp
);
1870 if (code
== PLUS_EXPR
|| code
== POINTER_PLUS_EXPR
)
1874 pp_c_whitespace (pp
);
1875 pp
->multiplicative_expression (TREE_OPERAND (e
, 1));
1879 pp
->multiplicative_expression (e
);
1884 /* additive-expression:
1886 shift-expression << additive-expression
1887 shift-expression >> additive-expression */
1890 pp_c_shift_expression (c_pretty_printer
*pp
, tree e
)
1892 enum tree_code code
= TREE_CODE (e
);
1897 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 0));
1898 pp_c_whitespace (pp
);
1899 pp_string (pp
, code
== LSHIFT_EXPR
? "<<" : ">>");
1900 pp_c_whitespace (pp
);
1901 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 1));
1905 pp_c_additive_expression (pp
, e
);
1909 /* relational-expression:
1911 relational-expression < shift-expression
1912 relational-expression > shift-expression
1913 relational-expression <= shift-expression
1914 relational-expression >= shift-expression */
1917 pp_c_relational_expression (c_pretty_printer
*pp
, tree e
)
1919 enum tree_code code
= TREE_CODE (e
);
1926 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 0));
1927 pp_c_whitespace (pp
);
1928 if (code
== LT_EXPR
)
1930 else if (code
== GT_EXPR
)
1932 else if (code
== LE_EXPR
)
1934 else if (code
== GE_EXPR
)
1935 pp_greater_equal (pp
);
1936 pp_c_whitespace (pp
);
1937 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 1));
1941 pp_c_shift_expression (pp
, e
);
1946 /* equality-expression:
1947 relational-expression
1948 equality-expression == relational-expression
1949 equality-equality != relational-expression */
1952 pp_c_equality_expression (c_pretty_printer
*pp
, tree e
)
1954 enum tree_code code
= TREE_CODE (e
);
1959 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 0));
1960 pp_c_whitespace (pp
);
1961 pp_string (pp
, code
== EQ_EXPR
? "==" : "!=");
1962 pp_c_whitespace (pp
);
1963 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 1));
1967 pp_c_relational_expression (pp
, e
);
1974 AND-expression & equality-equality */
1977 pp_c_and_expression (c_pretty_printer
*pp
, tree e
)
1979 if (TREE_CODE (e
) == BIT_AND_EXPR
)
1981 pp_c_and_expression (pp
, TREE_OPERAND (e
, 0));
1982 pp_c_whitespace (pp
);
1984 pp_c_whitespace (pp
);
1985 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 1));
1988 pp_c_equality_expression (pp
, e
);
1991 /* exclusive-OR-expression:
1993 exclusive-OR-expression ^ AND-expression */
1996 pp_c_exclusive_or_expression (c_pretty_printer
*pp
, tree e
)
1998 if (TREE_CODE (e
) == BIT_XOR_EXPR
1999 || TREE_CODE (e
) == TRUTH_XOR_EXPR
)
2001 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
2002 if (TREE_CODE (e
) == BIT_XOR_EXPR
)
2003 pp_c_maybe_whitespace (pp
);
2005 pp_c_whitespace (pp
);
2007 pp_c_whitespace (pp
);
2008 pp_c_and_expression (pp
, TREE_OPERAND (e
, 1));
2011 pp_c_and_expression (pp
, e
);
2014 /* inclusive-OR-expression:
2015 exclusive-OR-expression
2016 inclusive-OR-expression | exclusive-OR-expression */
2019 pp_c_inclusive_or_expression (c_pretty_printer
*pp
, tree e
)
2021 if (TREE_CODE (e
) == BIT_IOR_EXPR
)
2023 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
2024 pp_c_whitespace (pp
);
2026 pp_c_whitespace (pp
);
2027 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
2030 pp_c_exclusive_or_expression (pp
, e
);
2033 /* logical-AND-expression:
2034 inclusive-OR-expression
2035 logical-AND-expression && inclusive-OR-expression */
2038 pp_c_logical_and_expression (c_pretty_printer
*pp
, tree e
)
2040 if (TREE_CODE (e
) == TRUTH_ANDIF_EXPR
2041 || TREE_CODE (e
) == TRUTH_AND_EXPR
)
2043 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 0));
2044 pp_c_whitespace (pp
);
2045 pp_ampersand_ampersand (pp
);
2046 pp_c_whitespace (pp
);
2047 pp_c_inclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
2050 pp_c_inclusive_or_expression (pp
, e
);
2053 /* logical-OR-expression:
2054 logical-AND-expression
2055 logical-OR-expression || logical-AND-expression */
2058 pp_c_logical_or_expression (c_pretty_printer
*pp
, tree e
)
2060 if (TREE_CODE (e
) == TRUTH_ORIF_EXPR
2061 || TREE_CODE (e
) == TRUTH_OR_EXPR
)
2063 pp_c_logical_or_expression (pp
, TREE_OPERAND (e
, 0));
2064 pp_c_whitespace (pp
);
2066 pp_c_whitespace (pp
);
2067 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 1));
2070 pp_c_logical_and_expression (pp
, e
);
2073 /* conditional-expression:
2074 logical-OR-expression
2075 logical-OR-expression ? expression : conditional-expression */
2078 c_pretty_printer::conditional_expression (tree e
)
2080 if (TREE_CODE (e
) == COND_EXPR
)
2082 pp_c_logical_or_expression (this, TREE_OPERAND (e
, 0));
2083 pp_c_whitespace (this);
2085 pp_c_whitespace (this);
2086 expression (TREE_OPERAND (e
, 1));
2087 pp_c_whitespace (this);
2089 pp_c_whitespace (this);
2090 conditional_expression (TREE_OPERAND (e
, 2));
2093 pp_c_logical_or_expression (this, e
);
2097 /* assignment-expression:
2098 conditional-expression
2099 unary-expression assignment-operator assignment-expression
2101 assignment-expression: one of
2102 = *= /= %= += -= >>= <<= &= ^= |= */
2105 c_pretty_printer::assignment_expression (tree e
)
2107 if (TREE_CODE (e
) == MODIFY_EXPR
2108 || TREE_CODE (e
) == INIT_EXPR
)
2110 unary_expression (TREE_OPERAND (e
, 0));
2111 pp_c_whitespace (this);
2114 expression (TREE_OPERAND (e
, 1));
2117 conditional_expression (e
);
2121 assignment-expression
2122 expression , assignment-expression
2124 Implementation note: instead of going through the usual recursion
2125 chain, I take the liberty of dispatching nodes to the appropriate
2126 functions. This makes some redundancy, but it worths it. That also
2127 prevents a possible infinite recursion between primary_expression ()
2128 and expression (). */
2131 c_pretty_printer::expression (tree e
)
2133 switch (TREE_CODE (e
))
2136 pp_c_integer_constant (this, e
);
2140 pp_c_floating_constant (this, e
);
2144 pp_c_fixed_constant (this, e
);
2148 pp_c_string_literal (this, e
);
2151 case IDENTIFIER_NODE
:
2160 primary_expression (e
);
2164 if (SSA_NAME_VAR (e
)
2165 && !DECL_ARTIFICIAL (SSA_NAME_VAR (e
)))
2166 expression (SSA_NAME_VAR (e
));
2168 translate_string ("<unknown>");
2171 case POSTINCREMENT_EXPR
:
2172 case POSTDECREMENT_EXPR
:
2174 case ARRAY_NOTATION_REF
:
2182 case UNORDERED_EXPR
:
2191 case COMPOUND_LITERAL_EXPR
:
2193 postfix_expression (e
);
2202 case TRUTH_NOT_EXPR
:
2203 case PREINCREMENT_EXPR
:
2204 case PREDECREMENT_EXPR
:
2207 unary_expression (e
);
2211 case FIX_TRUNC_EXPR
:
2213 case VIEW_CONVERT_EXPR
:
2214 pp_c_cast_expression (this, e
);
2218 case TRUNC_MOD_EXPR
:
2219 case TRUNC_DIV_EXPR
:
2220 multiplicative_expression (e
);
2225 pp_c_shift_expression (this, e
);
2232 pp_c_relational_expression (this, e
);
2236 pp_c_and_expression (this, e
);
2240 case TRUTH_XOR_EXPR
:
2241 pp_c_exclusive_or_expression (this, e
);
2245 pp_c_inclusive_or_expression (this, e
);
2248 case TRUTH_ANDIF_EXPR
:
2249 case TRUTH_AND_EXPR
:
2250 pp_c_logical_and_expression (this, e
);
2253 case TRUTH_ORIF_EXPR
:
2255 pp_c_logical_or_expression (this, e
);
2260 pp_c_equality_expression (this, e
);
2264 conditional_expression (e
);
2267 case POINTER_PLUS_EXPR
:
2270 pp_c_additive_expression (this, e
);
2275 assignment_expression (e
);
2279 pp_c_left_paren (this);
2280 expression (TREE_OPERAND (e
, 0));
2281 pp_separate_with (this, ',');
2282 assignment_expression (TREE_OPERAND (e
, 1));
2283 pp_c_right_paren (this);
2286 case NON_LVALUE_EXPR
:
2288 expression (TREE_OPERAND (e
, 0));
2292 postfix_expression (TREE_OPERAND (e
, 1));
2297 /* We don't yet have a way of dumping statements in a
2298 human-readable format. */
2299 pp_string (this, "({...})");
2302 case C_MAYBE_CONST_EXPR
:
2303 expression (C_MAYBE_CONST_EXPR_EXPR (e
));
2307 pp_unsupported_tree (this, e
);
2317 c_pretty_printer::statement (tree stmt
)
2322 if (pp_needs_newline (this))
2323 pp_newline_and_indent (this, 0);
2325 dump_generic_node (this, stmt
, pp_indentation (this), 0, true);
2329 /* Initialize the PRETTY-PRINTER for handling C codes. */
2331 c_pretty_printer::c_pretty_printer ()
2332 : pretty_printer (),
2336 type_specifier_seq
= pp_c_specifier_qualifier_list
;
2337 ptr_operator
= pp_c_pointer
;
2338 parameter_list
= pp_c_parameter_type_list
;
2342 /* Print the tree T in full, on file FILE. */
2345 print_c_tree (FILE *file
, tree t
)
2347 c_pretty_printer pp
;
2349 pp_needs_newline (&pp
) = true;
2350 pp
.buffer
->stream
= file
;
2352 pp_newline_and_flush (&pp
);
2355 /* Print the tree T in full, on stderr. */
2358 debug_c_tree (tree t
)
2360 print_c_tree (stderr
, t
);
2361 fputc ('\n', stderr
);
2364 /* Output the DECL_NAME of T. If T has no DECL_NAME, output a string made
2365 up of T's memory address. */
2368 pp_c_tree_decl_identifier (c_pretty_printer
*pp
, tree t
)
2372 gcc_assert (DECL_P (t
));
2375 name
= IDENTIFIER_POINTER (DECL_NAME (t
));
2378 static char xname
[8];
2379 sprintf (xname
, "<U%4x>", ((unsigned)((uintptr_t)(t
) & 0xffff)));
2383 pp_c_identifier (pp
, name
);