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"
27 #include "c-pretty-print.h"
28 #include "tree-pretty-print.h"
29 #include "tree-iterator.h"
30 #include "diagnostic.h"
32 /* Translate if being used for diagnostics, but not for dump files or
34 #define M_(msgid) (pp_translate_identifiers (pp) ? _(msgid) : (msgid))
36 /* The pretty-printer code is primarily designed to closely follow
37 (GNU) C and C++ grammars. That is to be contrasted with spaghetti
38 codes we used to have in the past. Following a structured
39 approach (preferably the official grammars) is believed to make it
40 much easier to add extensions and nifty pretty-printing effects that
41 takes expression or declaration contexts into account. */
44 #define pp_c_maybe_whitespace(PP) \
46 if ((PP)->padding == pp_before) \
47 pp_c_whitespace (PP); \
51 static void pp_c_char (c_pretty_printer *, int);
53 /* postfix-expression */
54 static void pp_c_initializer_list (c_pretty_printer *, tree);
55 static void pp_c_brace_enclosed_initializer_list (c_pretty_printer *, tree);
57 static void pp_c_multiplicative_expression (c_pretty_printer *, tree);
58 static void pp_c_additive_expression (c_pretty_printer *, tree);
59 static void pp_c_shift_expression (c_pretty_printer *, tree);
60 static void pp_c_relational_expression (c_pretty_printer *, tree);
61 static void pp_c_equality_expression (c_pretty_printer *, tree);
62 static void pp_c_and_expression (c_pretty_printer *, tree);
63 static void pp_c_exclusive_or_expression (c_pretty_printer *, tree);
64 static void pp_c_inclusive_or_expression (c_pretty_printer *, tree);
65 static void pp_c_logical_and_expression (c_pretty_printer *, tree);
66 static void pp_c_conditional_expression (c_pretty_printer *, tree);
67 static void pp_c_assignment_expression (c_pretty_printer *, tree);
72 /* Helper functions. */
75 pp_c_whitespace (c_pretty_printer *pp)
78 pp->padding = pp_none;
82 pp_c_left_paren (c_pretty_printer *pp)
85 pp->padding = pp_none;
89 pp_c_right_paren (c_pretty_printer *pp)
92 pp->padding = pp_none;
96 pp_c_left_brace (c_pretty_printer *pp)
99 pp->padding = pp_none;
103 pp_c_right_brace (c_pretty_printer *pp)
106 pp->padding = pp_none;
110 pp_c_left_bracket (c_pretty_printer *pp)
112 pp_left_bracket (pp);
113 pp->padding = pp_none;
117 pp_c_right_bracket (c_pretty_printer *pp)
119 pp_right_bracket (pp);
120 pp->padding = pp_none;
124 pp_c_dot (c_pretty_printer *pp)
127 pp->padding = pp_none;
131 pp_c_ampersand (c_pretty_printer *pp)
134 pp->padding = pp_none;
138 pp_c_star (c_pretty_printer *pp)
141 pp->padding = pp_none;
145 pp_c_arrow (c_pretty_printer *pp)
148 pp->padding = pp_none;
152 pp_c_semicolon (c_pretty_printer *pp)
155 pp->padding = pp_none;
159 pp_c_complement (c_pretty_printer *pp)
162 pp->padding = pp_none;
166 pp_c_exclamation (c_pretty_printer *pp)
169 pp->padding = pp_none;
172 /* Print out the external representation of QUALIFIERS. */
175 pp_c_cv_qualifiers (c_pretty_printer *pp, int qualifiers, bool func_type)
177 const char *p = pp_last_position_in_text (pp);
178 bool previous = false;
183 /* The C programming language does not have references, but it is much
184 simpler to handle those here rather than going through the same
185 logic in the C++ pretty-printer. */
186 if (p != NULL && (*p == '*' || *p == '&'))
187 pp_c_whitespace (pp);
189 if (qualifiers & TYPE_QUAL_CONST)
191 pp_c_ws_string (pp, func_type ? "__attribute__((const))" : "const");
195 if (qualifiers & TYPE_QUAL_VOLATILE)
198 pp_c_whitespace (pp);
199 pp_c_ws_string (pp, func_type ? "__attribute__((noreturn))" : "volatile");
203 if (qualifiers & TYPE_QUAL_RESTRICT)
206 pp_c_whitespace (pp);
207 pp_c_ws_string (pp, (flag_isoc99 && !c_dialect_cxx ()
208 ? "restrict" : "__restrict__"));
212 /* Pretty-print T using the type-cast notation '( type-name )'. */
215 pp_c_type_cast (c_pretty_printer *pp, tree t)
217 pp_c_left_paren (pp);
219 pp_c_right_paren (pp);
222 /* We're about to pretty-print a pointer type as indicated by T.
223 Output a whitespace, if needed, preparing for subsequent output. */
226 pp_c_space_for_pointer_operator (c_pretty_printer *pp, tree t)
228 if (POINTER_TYPE_P (t))
230 tree pointee = strip_pointer_operator (TREE_TYPE (t));
231 if (TREE_CODE (pointee) != ARRAY_TYPE
232 && TREE_CODE (pointee) != FUNCTION_TYPE)
233 pp_c_whitespace (pp);
240 /* C++ cv-qualifiers are called type-qualifiers in C. Print out the
241 cv-qualifiers of T. If T is a declaration then it is the cv-qualifier
242 of its type. Take care of possible extensions.
246 type-qualifier-list type-qualifier
251 __restrict__ -- GNU C
252 address-space-qualifier -- GNU C
255 address-space-qualifier:
256 identifier -- GNU C */
259 pp_c_type_qualifier_list (c_pretty_printer *pp, tree t)
263 if (!t || t == error_mark_node)
269 qualifiers = TYPE_QUALS (t);
270 pp_c_cv_qualifiers (pp, qualifiers,
271 TREE_CODE (t) == FUNCTION_TYPE);
273 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (t)))
275 const char *as = c_addr_space_name (TYPE_ADDR_SPACE (t));
276 pp_c_identifier (pp, as);
281 * type-qualifier-list(opt)
282 * type-qualifier-list(opt) pointer */
285 pp_c_pointer (c_pretty_printer *pp, tree t)
287 if (!TYPE_P (t) && TREE_CODE (t) != TYPE_DECL)
289 switch (TREE_CODE (t))
292 /* It is easier to handle C++ reference types here. */
294 if (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE)
295 pp_c_pointer (pp, TREE_TYPE (t));
296 if (TREE_CODE (t) == POINTER_TYPE)
300 pp_c_type_qualifier_list (pp, t);
303 /* ??? This node is now in GENERIC and so shouldn't be here. But
304 we'll fix that later. */
306 pp_declaration (pp, DECL_EXPR_DECL (t));
307 pp_needs_newline (pp) = true;
311 pp_unsupported_tree (pp, t);
328 struct-or-union-specifier
333 simple-type-specifier:
338 pp_c_type_specifier (c_pretty_printer *pp, tree t)
340 const enum tree_code code = TREE_CODE (t);
344 pp_c_ws_string (pp, M_("<type-error>"));
347 case IDENTIFIER_NODE:
348 pp_c_identifier (pp, IDENTIFIER_POINTER (t));
355 case FIXED_POINT_TYPE:
359 pp_c_type_specifier (pp, t);
363 int prec = TYPE_PRECISION (t);
364 if (ALL_FIXED_POINT_MODE_P (TYPE_MODE (t)))
365 t = c_common_type_for_mode (TYPE_MODE (t), TYPE_SATURATING (t));
367 t = c_common_type_for_mode (TYPE_MODE (t), TYPE_UNSIGNED (t));
370 pp_c_type_specifier (pp, t);
371 if (TYPE_PRECISION (t) != prec)
374 pp_decimal_int (pp, prec);
382 pp_string (pp, (TYPE_UNSIGNED (t)
383 ? M_("<unnamed-unsigned:")
384 : M_("<unnamed-signed:")));
387 pp_string (pp, M_("<unnamed-float:"));
389 case FIXED_POINT_TYPE:
390 pp_string (pp, M_("<unnamed-fixed:"));
395 pp_decimal_int (pp, prec);
403 pp_id_expression (pp, t);
405 pp_c_ws_string (pp, M_("<typedef-error>"));
411 if (code == UNION_TYPE)
412 pp_c_ws_string (pp, "union");
413 else if (code == RECORD_TYPE)
414 pp_c_ws_string (pp, "struct");
415 else if (code == ENUMERAL_TYPE)
416 pp_c_ws_string (pp, "enum");
418 pp_c_ws_string (pp, M_("<tag-error>"));
421 pp_id_expression (pp, TYPE_NAME (t));
423 pp_c_ws_string (pp, M_("<anonymous>"));
427 pp_unsupported_tree (pp, t);
432 /* specifier-qualifier-list:
433 type-specifier specifier-qualifier-list-opt
434 type-qualifier specifier-qualifier-list-opt
437 Implementation note: Because of the non-linearities in array or
438 function declarations, this routine prints not just the
439 specifier-qualifier-list of such entities or types of such entities,
440 but also the 'pointer' production part of their declarators. The
441 remaining part is done by pp_declarator or pp_c_abstract_declarator. */
444 pp_c_specifier_qualifier_list (c_pretty_printer *pp, tree t)
446 const enum tree_code code = TREE_CODE (t);
448 if (!(pp->flags & pp_c_flag_gnu_v3) && code != POINTER_TYPE)
449 pp_c_type_qualifier_list (pp, t);
455 /* Get the types-specifier of this type. */
456 tree pointee = strip_pointer_operator (TREE_TYPE (t));
457 pp_c_specifier_qualifier_list (pp, pointee);
458 if (TREE_CODE (pointee) == ARRAY_TYPE
459 || TREE_CODE (pointee) == FUNCTION_TYPE)
461 pp_c_whitespace (pp);
462 pp_c_left_paren (pp);
463 pp_c_attributes_display (pp, TYPE_ATTRIBUTES (pointee));
465 else if (!c_dialect_cxx ())
466 pp_c_whitespace (pp);
467 pp_ptr_operator (pp, t);
473 pp_c_specifier_qualifier_list (pp, TREE_TYPE (t));
478 if (code == COMPLEX_TYPE)
479 pp_c_ws_string (pp, (flag_isoc99 && !c_dialect_cxx ()
480 ? "_Complex" : "__complex__"));
481 else if (code == VECTOR_TYPE)
483 pp_c_ws_string (pp, "__vector");
484 pp_c_left_paren (pp);
485 pp_wide_integer (pp, TYPE_VECTOR_SUBPARTS (t));
486 pp_c_right_paren (pp);
487 pp_c_whitespace (pp);
489 pp_c_specifier_qualifier_list (pp, TREE_TYPE (t));
493 pp_simple_type_specifier (pp, t);
496 if ((pp->flags & pp_c_flag_gnu_v3) && code != POINTER_TYPE)
497 pp_c_type_qualifier_list (pp, t);
500 /* parameter-type-list:
505 parameter-declaration
506 parameter-list , parameter-declaration
508 parameter-declaration:
509 declaration-specifiers declarator
510 declaration-specifiers abstract-declarator(opt) */
513 pp_c_parameter_type_list (c_pretty_printer *pp, tree t)
515 bool want_parm_decl = DECL_P (t) && !(pp->flags & pp_c_flag_abstract);
516 tree parms = want_parm_decl ? DECL_ARGUMENTS (t) : TYPE_ARG_TYPES (t);
517 pp_c_left_paren (pp);
518 if (parms == void_list_node)
519 pp_c_ws_string (pp, "void");
523 for ( ; parms && parms != void_list_node; parms = TREE_CHAIN (parms))
526 pp_separate_with (pp, ',');
528 pp_declaration_specifiers
529 (pp, want_parm_decl ? parms : TREE_VALUE (parms));
531 pp_declarator (pp, parms);
533 pp_abstract_declarator (pp, TREE_VALUE (parms));
536 pp_c_right_paren (pp);
539 /* abstract-declarator:
541 pointer(opt) direct-abstract-declarator */
544 pp_c_abstract_declarator (c_pretty_printer *pp, tree t)
546 if (TREE_CODE (t) == POINTER_TYPE)
548 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE
549 || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
550 pp_c_right_paren (pp);
554 pp_direct_abstract_declarator (pp, t);
557 /* direct-abstract-declarator:
558 ( abstract-declarator )
559 direct-abstract-declarator(opt) [ assignment-expression(opt) ]
560 direct-abstract-declarator(opt) [ * ]
561 direct-abstract-declarator(opt) ( parameter-type-list(opt) ) */
564 pp_c_direct_abstract_declarator (c_pretty_printer *pp, tree t)
566 switch (TREE_CODE (t))
569 pp_abstract_declarator (pp, t);
573 pp_c_parameter_type_list (pp, t);
574 pp_direct_abstract_declarator (pp, TREE_TYPE (t));
578 pp_c_left_bracket (pp);
579 if (TYPE_DOMAIN (t) && TYPE_MAX_VALUE (TYPE_DOMAIN (t)))
581 tree maxval = TYPE_MAX_VALUE (TYPE_DOMAIN (t));
582 tree type = TREE_TYPE (maxval);
584 if (host_integerp (maxval, 0))
585 pp_wide_integer (pp, tree_low_cst (maxval, 0) + 1);
587 pp_expression (pp, fold_build2 (PLUS_EXPR, type, maxval,
588 build_int_cst (type, 1)));
590 pp_c_right_bracket (pp);
591 pp_direct_abstract_declarator (pp, TREE_TYPE (t));
594 case IDENTIFIER_NODE:
599 case FIXED_POINT_TYPE:
609 pp_unsupported_tree (pp, t);
615 specifier-qualifier-list abstract-declarator(opt) */
618 pp_c_type_id (c_pretty_printer *pp, tree t)
620 pp_c_specifier_qualifier_list (pp, t);
621 pp_abstract_declarator (pp, t);
624 /* storage-class-specifier:
632 pp_c_storage_class_specifier (c_pretty_printer *pp, tree t)
634 if (TREE_CODE (t) == TYPE_DECL)
635 pp_c_ws_string (pp, "typedef");
638 if (DECL_REGISTER (t))
639 pp_c_ws_string (pp, "register");
640 else if (TREE_STATIC (t) && TREE_CODE (t) == VAR_DECL)
641 pp_c_ws_string (pp, "static");
645 /* function-specifier:
649 pp_c_function_specifier (c_pretty_printer *pp, tree t)
651 if (TREE_CODE (t) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (t))
652 pp_c_ws_string (pp, "inline");
655 /* declaration-specifiers:
656 storage-class-specifier declaration-specifiers(opt)
657 type-specifier declaration-specifiers(opt)
658 type-qualifier declaration-specifiers(opt)
659 function-specifier declaration-specifiers(opt) */
662 pp_c_declaration_specifiers (c_pretty_printer *pp, tree t)
664 pp_storage_class_specifier (pp, t);
665 pp_function_specifier (pp, t);
666 pp_c_specifier_qualifier_list (pp, DECL_P (t) ? TREE_TYPE (t) : t);
672 direct-declarator [ type-qualifier-list(opt) assignment-expression(opt) ]
673 direct-declarator [ static type-qualifier-list(opt) assignment-expression(opt)]
674 direct-declarator [ type-qualifier-list static assignment-expression ]
675 direct-declarator [ type-qualifier-list * ]
676 direct-declarator ( parameter-type-list )
677 direct-declarator ( identifier-list(opt) ) */
680 pp_c_direct_declarator (c_pretty_printer *pp, tree t)
682 switch (TREE_CODE (t))
689 pp_c_space_for_pointer_operator (pp, TREE_TYPE (t));
690 pp_c_tree_decl_identifier (pp, t);
695 pp_abstract_declarator (pp, TREE_TYPE (t));
699 pp_parameter_list (pp, t);
700 pp_abstract_declarator (pp, TREE_TYPE (t));
704 pp_c_space_for_pointer_operator (pp, TREE_TYPE (TREE_TYPE (t)));
705 pp_c_tree_decl_identifier (pp, t);
706 if (pp->flags & pp_c_flag_abstract)
707 pp_abstract_declarator (pp, TREE_TYPE (t));
710 pp_parameter_list (pp, t);
711 pp_abstract_declarator (pp, TREE_TYPE (TREE_TYPE (t)));
717 case FIXED_POINT_TYPE:
724 pp_unsupported_tree (pp, t);
731 pointer(opt) direct-declarator */
734 pp_c_declarator (c_pretty_printer *pp, tree t)
736 switch (TREE_CODE (t))
740 case FIXED_POINT_TYPE:
753 pp_direct_declarator (pp, t);
758 pp_unsupported_tree (pp, t);
764 declaration-specifiers init-declarator-list(opt) ; */
767 pp_c_declaration (c_pretty_printer *pp, tree t)
769 pp_declaration_specifiers (pp, t);
770 pp_c_init_declarator (pp, t);
773 /* Pretty-print ATTRIBUTES using GNU C extension syntax. */
776 pp_c_attributes (c_pretty_printer *pp, tree attributes)
778 if (attributes == NULL_TREE)
781 pp_c_ws_string (pp, "__attribute__");
782 pp_c_left_paren (pp);
783 pp_c_left_paren (pp);
784 for (; attributes != NULL_TREE; attributes = TREE_CHAIN (attributes))
786 pp_tree_identifier (pp, TREE_PURPOSE (attributes));
787 if (TREE_VALUE (attributes))
788 pp_c_call_argument_list (pp, TREE_VALUE (attributes));
790 if (TREE_CHAIN (attributes))
791 pp_separate_with (pp, ',');
793 pp_c_right_paren (pp);
794 pp_c_right_paren (pp);
797 /* Pretty-print ATTRIBUTES using GNU C extension syntax for attributes
798 marked to be displayed on disgnostic. */
801 pp_c_attributes_display (c_pretty_printer *pp, tree a)
803 bool is_first = true;
808 for (; a != NULL_TREE; a = TREE_CHAIN (a))
810 const struct attribute_spec *as;
811 as = lookup_attribute_spec (TREE_PURPOSE (a));
812 if (!as || as->affects_type_identity == false)
816 pp_c_ws_string (pp, "__attribute__");
817 pp_c_left_paren (pp);
818 pp_c_left_paren (pp);
823 pp_separate_with (pp, ',');
825 pp_tree_identifier (pp, TREE_PURPOSE (a));
827 pp_c_call_argument_list (pp, TREE_VALUE (a));
832 pp_c_right_paren (pp);
833 pp_c_right_paren (pp);
834 pp_c_whitespace (pp);
838 /* function-definition:
839 declaration-specifiers declarator compound-statement */
842 pp_c_function_definition (c_pretty_printer *pp, tree t)
844 pp_declaration_specifiers (pp, t);
845 pp_declarator (pp, t);
846 pp_needs_newline (pp) = true;
847 pp_statement (pp, DECL_SAVED_TREE (t));
848 pp_newline_and_flush (pp);
854 /* Print out a c-char. This is called solely for characters which are
855 in the *target* execution character set. We ought to convert them
856 back to the *host* execution character set before printing, but we
857 have no way to do this at present. A decent compromise is to print
858 all characters as if they were in the host execution character set,
859 and not attempt to recover any named escape characters, but render
860 all unprintables as octal escapes. If the host and target character
861 sets are the same, this produces relatively readable output. If they
862 are not the same, strings may appear as gibberish, but that's okay
863 (in fact, it may well be what the reader wants, e.g. if they are looking
864 to see if conversion to the target character set happened correctly).
866 A special case: we need to prefix \, ", and ' with backslashes. It is
867 correct to do so for the *host*'s \, ", and ', because the rest of the
868 file appears in the host character set. */
871 pp_c_char (c_pretty_printer *pp, int c)
877 case '\\': pp_string (pp, "\\\\"); break;
878 case '\'': pp_string (pp, "\\\'"); break;
879 case '\"': pp_string (pp, "\\\""); break;
880 default: pp_character (pp, c);
884 pp_scalar (pp, "\\%03o", (unsigned) c);
887 /* Print out a STRING literal. */
890 pp_c_string_literal (c_pretty_printer *pp, tree s)
892 const char *p = TREE_STRING_POINTER (s);
893 int n = TREE_STRING_LENGTH (s) - 1;
896 for (i = 0; i < n; ++i)
897 pp_c_char (pp, p[i]);
901 /* Pretty-print an INTEGER literal. */
904 pp_c_integer_constant (c_pretty_printer *pp, tree i)
906 /* We are going to compare the type of I to other types using
907 pointer comparison so we need to use its canonical type. */
909 TYPE_CANONICAL (TREE_TYPE (i))
910 ? TYPE_CANONICAL (TREE_TYPE (i))
913 if (host_integerp (i, 0))
914 pp_wide_integer (pp, TREE_INT_CST_LOW (i));
915 else if (host_integerp (i, 1))
916 pp_unsigned_wide_integer (pp, TREE_INT_CST_LOW (i));
919 unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (i);
920 HOST_WIDE_INT high = TREE_INT_CST_HIGH (i);
921 if (tree_int_cst_sgn (i) < 0)
927 sprintf (pp_buffer (pp)->digit_buffer, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
928 (unsigned HOST_WIDE_INT) high, (unsigned HOST_WIDE_INT) low);
929 pp_string (pp, pp_buffer (pp)->digit_buffer);
931 if (TYPE_UNSIGNED (type))
932 pp_character (pp, 'u');
933 if (type == long_integer_type_node || type == long_unsigned_type_node)
934 pp_character (pp, 'l');
935 else if (type == long_long_integer_type_node
936 || type == long_long_unsigned_type_node)
937 pp_string (pp, "ll");
938 else if (type == int128_integer_type_node
939 || type == int128_unsigned_type_node)
940 pp_string (pp, "I128");
943 /* Print out a CHARACTER literal. */
946 pp_c_character_constant (c_pretty_printer *pp, tree c)
948 tree type = TREE_TYPE (c);
949 if (type == wchar_type_node)
950 pp_character (pp, 'L');
952 if (host_integerp (c, TYPE_UNSIGNED (type)))
953 pp_c_char (pp, tree_low_cst (c, TYPE_UNSIGNED (type)));
955 pp_scalar (pp, "\\x%x", (unsigned) TREE_INT_CST_LOW (c));
959 /* Print out a BOOLEAN literal. */
962 pp_c_bool_constant (c_pretty_printer *pp, tree b)
964 if (b == boolean_false_node)
966 if (c_dialect_cxx ())
967 pp_c_ws_string (pp, "false");
968 else if (flag_isoc99)
969 pp_c_ws_string (pp, "_False");
971 pp_unsupported_tree (pp, b);
973 else if (b == boolean_true_node)
975 if (c_dialect_cxx ())
976 pp_c_ws_string (pp, "true");
977 else if (flag_isoc99)
978 pp_c_ws_string (pp, "_True");
980 pp_unsupported_tree (pp, b);
982 else if (TREE_CODE (b) == INTEGER_CST)
983 pp_c_integer_constant (pp, b);
985 pp_unsupported_tree (pp, b);
988 /* Attempt to print out an ENUMERATOR. Return true on success. Else return
989 false; that means the value was obtained by a cast, in which case
990 print out the type-id part of the cast-expression -- the casted value
991 is then printed by pp_c_integer_literal. */
994 pp_c_enumeration_constant (c_pretty_printer *pp, tree e)
996 bool value_is_named = true;
997 tree type = TREE_TYPE (e);
1000 /* Find the name of this constant. */
1001 for (value = TYPE_VALUES (type);
1002 value != NULL_TREE && !tree_int_cst_equal (TREE_VALUE (value), e);
1003 value = TREE_CHAIN (value))
1006 if (value != NULL_TREE)
1007 pp_id_expression (pp, TREE_PURPOSE (value));
1010 /* Value must have been cast. */
1011 pp_c_type_cast (pp, type);
1012 value_is_named = false;
1015 return value_is_named;
1018 /* Print out a REAL value as a decimal-floating-constant. */
1021 pp_c_floating_constant (c_pretty_printer *pp, tree r)
1023 const struct real_format *fmt
1024 = REAL_MODE_FORMAT (TYPE_MODE (TREE_TYPE (r)));
1026 REAL_VALUE_TYPE floating_cst = TREE_REAL_CST (r);
1027 bool is_decimal = floating_cst.decimal;
1029 /* See ISO C++ WG N1822. Note: The fraction 643/2136 approximates
1030 log10(2) to 7 significant digits. */
1031 int max_digits10 = 2 + (is_decimal ? fmt->p : fmt->p * 643L / 2136);
1033 real_to_decimal (pp_buffer (pp)->digit_buffer, &TREE_REAL_CST (r),
1034 sizeof (pp_buffer (pp)->digit_buffer),
1037 pp_string (pp, pp_buffer(pp)->digit_buffer);
1038 if (TREE_TYPE (r) == float_type_node)
1039 pp_character (pp, 'f');
1040 else if (TREE_TYPE (r) == long_double_type_node)
1041 pp_character (pp, 'l');
1042 else if (TREE_TYPE (r) == dfloat128_type_node)
1043 pp_string (pp, "dl");
1044 else if (TREE_TYPE (r) == dfloat64_type_node)
1045 pp_string (pp, "dd");
1046 else if (TREE_TYPE (r) == dfloat32_type_node)
1047 pp_string (pp, "df");
1050 /* Print out a FIXED value as a decimal-floating-constant. */
1053 pp_c_fixed_constant (c_pretty_printer *pp, tree r)
1055 fixed_to_decimal (pp_buffer (pp)->digit_buffer, &TREE_FIXED_CST (r),
1056 sizeof (pp_buffer (pp)->digit_buffer));
1057 pp_string (pp, pp_buffer(pp)->digit_buffer);
1060 /* Pretty-print a compound literal expression. GNU extensions include
1061 vector constants. */
1064 pp_c_compound_literal (c_pretty_printer *pp, tree e)
1066 tree type = TREE_TYPE (e);
1067 pp_c_type_cast (pp, type);
1069 switch (TREE_CODE (type))
1076 pp_c_brace_enclosed_initializer_list (pp, e);
1080 pp_unsupported_tree (pp, e);
1085 /* Pretty-print a COMPLEX_EXPR expression. */
1088 pp_c_complex_expr (c_pretty_printer *pp, tree e)
1090 /* Handle a few common special cases, otherwise fallback
1091 to printing it as compound literal. */
1092 tree type = TREE_TYPE (e);
1093 tree realexpr = TREE_OPERAND (e, 0);
1094 tree imagexpr = TREE_OPERAND (e, 1);
1096 /* Cast of an COMPLEX_TYPE expression to a different COMPLEX_TYPE. */
1097 if (TREE_CODE (realexpr) == NOP_EXPR
1098 && TREE_CODE (imagexpr) == NOP_EXPR
1099 && TREE_TYPE (realexpr) == TREE_TYPE (type)
1100 && TREE_TYPE (imagexpr) == TREE_TYPE (type)
1101 && TREE_CODE (TREE_OPERAND (realexpr, 0)) == REALPART_EXPR
1102 && TREE_CODE (TREE_OPERAND (imagexpr, 0)) == IMAGPART_EXPR
1103 && TREE_OPERAND (TREE_OPERAND (realexpr, 0), 0)
1104 == TREE_OPERAND (TREE_OPERAND (imagexpr, 0), 0))
1106 pp_c_type_cast (pp, type);
1107 pp_expression (pp, TREE_OPERAND (TREE_OPERAND (realexpr, 0), 0));
1111 /* Cast of an scalar expression to COMPLEX_TYPE. */
1112 if ((integer_zerop (imagexpr) || real_zerop (imagexpr))
1113 && TREE_TYPE (realexpr) == TREE_TYPE (type))
1115 pp_c_type_cast (pp, type);
1116 if (TREE_CODE (realexpr) == NOP_EXPR)
1117 realexpr = TREE_OPERAND (realexpr, 0);
1118 pp_expression (pp, realexpr);
1122 pp_c_compound_literal (pp, e);
1128 fixed-point-constant
1129 enumeration-constant
1130 character-constant */
1133 pp_c_constant (c_pretty_printer *pp, tree e)
1135 const enum tree_code code = TREE_CODE (e);
1141 tree type = TREE_TYPE (e);
1142 if (type == boolean_type_node)
1143 pp_c_bool_constant (pp, e);
1144 else if (type == char_type_node)
1145 pp_c_character_constant (pp, e);
1146 else if (TREE_CODE (type) == ENUMERAL_TYPE
1147 && pp_c_enumeration_constant (pp, e))
1150 pp_c_integer_constant (pp, e);
1155 pp_c_floating_constant (pp, e);
1159 pp_c_fixed_constant (pp, e);
1163 pp_c_string_literal (pp, e);
1167 /* Sometimes, we are confused and we think a complex literal
1168 is a constant. Such thing is a compound literal which
1169 grammatically belongs to postfix-expr production. */
1170 pp_c_compound_literal (pp, e);
1174 pp_unsupported_tree (pp, e);
1179 /* Pretty-print a string such as an identifier, without changing its
1180 encoding, preceded by whitespace is necessary. */
1183 pp_c_ws_string (c_pretty_printer *pp, const char *str)
1185 pp_c_maybe_whitespace (pp);
1186 pp_string (pp, str);
1187 pp->padding = pp_before;
1190 /* Pretty-print an IDENTIFIER_NODE, which may contain UTF-8 sequences
1191 that need converting to the locale encoding, preceded by whitespace
1195 pp_c_identifier (c_pretty_printer *pp, const char *id)
1197 pp_c_maybe_whitespace (pp);
1198 pp_identifier (pp, id);
1199 pp->padding = pp_before;
1202 /* Pretty-print a C primary-expression.
1210 pp_c_primary_expression (c_pretty_printer *pp, tree e)
1212 switch (TREE_CODE (e))
1220 pp_c_tree_decl_identifier (pp, e);
1223 case IDENTIFIER_NODE:
1224 pp_c_tree_identifier (pp, e);
1228 pp_c_ws_string (pp, M_("<erroneous-expression>"));
1232 pp_c_ws_string (pp, M_("<return-value>"));
1239 pp_c_constant (pp, e);
1243 pp_c_ws_string (pp, "__builtin_memcpy");
1244 pp_c_left_paren (pp);
1246 pp_primary_expression (pp, TREE_OPERAND (e, 0));
1247 pp_separate_with (pp, ',');
1249 pp_initializer (pp, TREE_OPERAND (e, 1));
1250 if (TREE_OPERAND (e, 2))
1252 pp_separate_with (pp, ',');
1253 pp_c_expression (pp, TREE_OPERAND (e, 2));
1255 pp_c_right_paren (pp);
1259 /* FIXME: Make sure we won't get into an infinite loop. */
1260 pp_c_left_paren (pp);
1261 pp_expression (pp, e);
1262 pp_c_right_paren (pp);
1267 /* Print out a C initializer -- also support C compound-literals.
1269 assignment-expression:
1270 { initializer-list }
1271 { initializer-list , } */
1274 pp_c_initializer (c_pretty_printer *pp, tree e)
1276 if (TREE_CODE (e) == CONSTRUCTOR)
1277 pp_c_brace_enclosed_initializer_list (pp, e);
1279 pp_expression (pp, e);
1284 declarator = initializer */
1287 pp_c_init_declarator (c_pretty_printer *pp, tree t)
1289 pp_declarator (pp, t);
1290 /* We don't want to output function definitions here. There are handled
1291 elsewhere (and the syntactic form is bogus anyway). */
1292 if (TREE_CODE (t) != FUNCTION_DECL && DECL_INITIAL (t))
1294 tree init = DECL_INITIAL (t);
1295 /* This C++ bit is handled here because it is easier to do so.
1296 In templates, the C++ parser builds a TREE_LIST for a
1297 direct-initialization; the TREE_PURPOSE is the variable to
1298 initialize and the TREE_VALUE is the initializer. */
1299 if (TREE_CODE (init) == TREE_LIST)
1301 pp_c_left_paren (pp);
1302 pp_expression (pp, TREE_VALUE (init));
1303 pp_right_paren (pp);
1310 pp_c_initializer (pp, init);
1315 /* initializer-list:
1316 designation(opt) initializer
1317 initializer-list , designation(opt) initializer
1324 designator-list designator
1327 [ constant-expression ]
1331 pp_c_initializer_list (c_pretty_printer *pp, tree e)
1333 tree type = TREE_TYPE (e);
1334 const enum tree_code code = TREE_CODE (type);
1336 if (TREE_CODE (e) == CONSTRUCTOR)
1338 pp_c_constructor_elts (pp, CONSTRUCTOR_ELTS (e));
1348 tree init = TREE_OPERAND (e, 0);
1349 for (; init != NULL_TREE; init = TREE_CHAIN (init))
1351 if (code == RECORD_TYPE || code == UNION_TYPE)
1354 pp_c_primary_expression (pp, TREE_PURPOSE (init));
1358 pp_c_left_bracket (pp);
1359 if (TREE_PURPOSE (init))
1360 pp_c_constant (pp, TREE_PURPOSE (init));
1361 pp_c_right_bracket (pp);
1363 pp_c_whitespace (pp);
1365 pp_c_whitespace (pp);
1366 pp_initializer (pp, TREE_VALUE (init));
1367 if (TREE_CHAIN (init))
1368 pp_separate_with (pp, ',');
1374 if (TREE_CODE (e) == VECTOR_CST)
1377 for (i = 0; i < VECTOR_CST_NELTS (e); ++i)
1380 pp_separate_with (pp, ',');
1381 pp_expression (pp, VECTOR_CST_ELT (e, i));
1389 if (TREE_CODE (e) == COMPLEX_CST || TREE_CODE (e) == COMPLEX_EXPR)
1391 const bool cst = TREE_CODE (e) == COMPLEX_CST;
1392 pp_expression (pp, cst ? TREE_REALPART (e) : TREE_OPERAND (e, 0));
1393 pp_separate_with (pp, ',');
1394 pp_expression (pp, cst ? TREE_IMAGPART (e) : TREE_OPERAND (e, 1));
1404 pp_unsupported_tree (pp, type);
1407 /* Pretty-print a brace-enclosed initializer-list. */
1410 pp_c_brace_enclosed_initializer_list (c_pretty_printer *pp, tree l)
1412 pp_c_left_brace (pp);
1413 pp_c_initializer_list (pp, l);
1414 pp_c_right_brace (pp);
1418 /* This is a convenient function, used to bridge gap between C and C++
1425 pp_c_id_expression (c_pretty_printer *pp, tree t)
1427 switch (TREE_CODE (t))
1436 pp_c_tree_decl_identifier (pp, t);
1439 case IDENTIFIER_NODE:
1440 pp_c_tree_identifier (pp, t);
1444 pp_unsupported_tree (pp, t);
1449 /* postfix-expression:
1451 postfix-expression [ expression ]
1452 postfix-expression ( argument-expression-list(opt) )
1453 postfix-expression . identifier
1454 postfix-expression -> identifier
1455 postfix-expression ++
1456 postfix-expression --
1457 ( type-name ) { initializer-list }
1458 ( type-name ) { initializer-list , } */
1461 pp_c_postfix_expression (c_pretty_printer *pp, tree e)
1463 enum tree_code code = TREE_CODE (e);
1466 case POSTINCREMENT_EXPR:
1467 case POSTDECREMENT_EXPR:
1468 pp_postfix_expression (pp, TREE_OPERAND (e, 0));
1469 pp_string (pp, code == POSTINCREMENT_EXPR ? "++" : "--");
1473 pp_postfix_expression (pp, TREE_OPERAND (e, 0));
1474 pp_c_left_bracket (pp);
1475 pp_expression (pp, TREE_OPERAND (e, 1));
1476 pp_c_right_bracket (pp);
1479 case ARRAY_NOTATION_REF:
1480 pp_postfix_expression (pp, ARRAY_NOTATION_ARRAY (e));
1481 pp_c_left_bracket (pp);
1482 pp_expression (pp, ARRAY_NOTATION_START (e));
1484 pp_expression (pp, ARRAY_NOTATION_LENGTH (e));
1486 pp_expression (pp, ARRAY_NOTATION_STRIDE (e));
1487 pp_c_right_bracket (pp);
1492 call_expr_arg_iterator iter;
1494 pp_postfix_expression (pp, CALL_EXPR_FN (e));
1495 pp_c_left_paren (pp);
1496 FOR_EACH_CALL_EXPR_ARG (arg, iter, e)
1498 pp_expression (pp, arg);
1499 if (more_call_expr_args_p (&iter))
1500 pp_separate_with (pp, ',');
1502 pp_c_right_paren (pp);
1506 case UNORDERED_EXPR:
1507 pp_c_ws_string (pp, flag_isoc99
1509 : "__builtin_isunordered");
1513 pp_c_ws_string (pp, flag_isoc99
1515 : "!__builtin_isunordered");
1519 pp_c_ws_string (pp, flag_isoc99
1521 : "!__builtin_isgreaterequal");
1525 pp_c_ws_string (pp, flag_isoc99
1527 : "!__builtin_isgreater");
1531 pp_c_ws_string (pp, flag_isoc99
1533 : "!__builtin_islessequal");
1537 pp_c_ws_string (pp, flag_isoc99
1539 : "!__builtin_isless");
1543 pp_c_ws_string (pp, flag_isoc99
1545 : "!__builtin_islessgreater");
1549 pp_c_ws_string (pp, flag_isoc99
1551 : "__builtin_islessgreater");
1555 pp_c_left_paren (pp);
1556 pp_expression (pp, TREE_OPERAND (e, 0));
1557 pp_separate_with (pp, ',');
1558 pp_expression (pp, TREE_OPERAND (e, 1));
1559 pp_c_right_paren (pp);
1563 pp_c_ws_string (pp, "__builtin_abs");
1564 pp_c_left_paren (pp);
1565 pp_expression (pp, TREE_OPERAND (e, 0));
1566 pp_c_right_paren (pp);
1571 tree object = TREE_OPERAND (e, 0);
1572 if (TREE_CODE (object) == INDIRECT_REF)
1574 pp_postfix_expression (pp, TREE_OPERAND (object, 0));
1579 pp_postfix_expression (pp, object);
1582 pp_expression (pp, TREE_OPERAND (e, 1));
1588 tree type = TREE_TYPE (e);
1590 type = signed_or_unsigned_type_for (TYPE_UNSIGNED (type), type);
1592 && tree_int_cst_equal (TYPE_SIZE (type), TREE_OPERAND (e, 1)))
1594 HOST_WIDE_INT bitpos = tree_low_cst (TREE_OPERAND (e, 2), 0);
1595 HOST_WIDE_INT size = tree_low_cst (TYPE_SIZE (type), 0);
1596 if ((bitpos % size) == 0)
1598 pp_c_left_paren (pp);
1599 pp_c_left_paren (pp);
1600 pp_type_id (pp, type);
1602 pp_c_right_paren (pp);
1603 pp_c_ampersand (pp);
1604 pp_expression (pp, TREE_OPERAND (e, 0));
1605 pp_c_right_paren (pp);
1606 pp_c_left_bracket (pp);
1607 pp_wide_integer (pp, bitpos / size);
1608 pp_c_right_bracket (pp);
1612 pp_unsupported_tree (pp, e);
1617 pp_c_expression (pp, e);
1622 pp_c_compound_literal (pp, e);
1626 pp_c_complex_expr (pp, e);
1629 case COMPOUND_LITERAL_EXPR:
1630 e = DECL_INITIAL (COMPOUND_LITERAL_EXPR_DECL (e));
1633 pp_initializer (pp, e);
1637 pp_c_ws_string (pp, "__builtin_va_arg");
1638 pp_c_left_paren (pp);
1639 pp_assignment_expression (pp, TREE_OPERAND (e, 0));
1640 pp_separate_with (pp, ',');
1641 pp_type_id (pp, TREE_TYPE (e));
1642 pp_c_right_paren (pp);
1646 if (TREE_CODE (TREE_OPERAND (e, 0)) == FUNCTION_DECL)
1648 pp_c_id_expression (pp, TREE_OPERAND (e, 0));
1651 /* else fall through. */
1654 pp_primary_expression (pp, e);
1659 /* Print out an expression-list; E is expected to be a TREE_LIST. */
1662 pp_c_expression_list (c_pretty_printer *pp, tree e)
1664 for (; e != NULL_TREE; e = TREE_CHAIN (e))
1666 pp_expression (pp, TREE_VALUE (e));
1668 pp_separate_with (pp, ',');
1672 /* Print out V, which contains the elements of a constructor. */
1675 pp_c_constructor_elts (c_pretty_printer *pp, vec<constructor_elt, va_gc> *v)
1677 unsigned HOST_WIDE_INT ix;
1680 FOR_EACH_CONSTRUCTOR_VALUE (v, ix, value)
1682 pp_expression (pp, value);
1683 if (ix != vec_safe_length (v) - 1)
1684 pp_separate_with (pp, ',');
1688 /* Print out an expression-list in parens, as if it were the argument
1689 list to a function. */
1692 pp_c_call_argument_list (c_pretty_printer *pp, tree t)
1694 pp_c_left_paren (pp);
1695 if (t && TREE_CODE (t) == TREE_LIST)
1696 pp_c_expression_list (pp, t);
1697 pp_c_right_paren (pp);
1700 /* unary-expression:
1704 unary-operator cast-expression
1705 sizeof unary-expression
1708 unary-operator: one of
1713 __alignof__ unary-expression
1714 __alignof__ ( type-id )
1715 __real__ unary-expression
1716 __imag__ unary-expression */
1719 pp_c_unary_expression (c_pretty_printer *pp, tree e)
1721 enum tree_code code = TREE_CODE (e);
1724 case PREINCREMENT_EXPR:
1725 case PREDECREMENT_EXPR:
1726 pp_string (pp, code == PREINCREMENT_EXPR ? "++" : "--");
1727 pp_c_unary_expression (pp, TREE_OPERAND (e, 0));
1734 case TRUTH_NOT_EXPR:
1736 /* String literal are used by address. */
1737 if (code == ADDR_EXPR && TREE_CODE (TREE_OPERAND (e, 0)) != STRING_CST)
1739 else if (code == INDIRECT_REF)
1741 else if (code == NEGATE_EXPR)
1743 else if (code == BIT_NOT_EXPR || code == CONJ_EXPR)
1745 else if (code == TRUTH_NOT_EXPR)
1746 pp_exclamation (pp);
1747 pp_c_cast_expression (pp, TREE_OPERAND (e, 0));
1751 if (TREE_CODE (TREE_OPERAND (e, 0)) == ADDR_EXPR
1752 && integer_zerop (TREE_OPERAND (e, 1)))
1753 pp_c_expression (pp, TREE_OPERAND (TREE_OPERAND (e, 0), 0));
1757 if (!integer_zerop (TREE_OPERAND (e, 1)))
1759 pp_c_left_paren (pp);
1760 if (!integer_onep (TYPE_SIZE_UNIT
1761 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (e, 0))))))
1762 pp_c_type_cast (pp, ptr_type_node);
1764 pp_c_cast_expression (pp, TREE_OPERAND (e, 0));
1765 if (!integer_zerop (TREE_OPERAND (e, 1)))
1768 pp_c_integer_constant (pp,
1769 fold_convert (ssizetype,
1770 TREE_OPERAND (e, 1)));
1771 pp_c_right_paren (pp);
1778 pp_c_ws_string (pp, code == REALPART_EXPR ? "__real__" : "__imag__");
1779 pp_c_whitespace (pp);
1780 pp_unary_expression (pp, TREE_OPERAND (e, 0));
1784 pp_postfix_expression (pp, e);
1791 ( type-name ) cast-expression */
1794 pp_c_cast_expression (c_pretty_printer *pp, tree e)
1796 switch (TREE_CODE (e))
1799 case FIX_TRUNC_EXPR:
1801 case VIEW_CONVERT_EXPR:
1802 pp_c_type_cast (pp, TREE_TYPE (e));
1803 pp_c_cast_expression (pp, TREE_OPERAND (e, 0));
1807 pp_unary_expression (pp, e);
1811 /* multiplicative-expression:
1813 multiplicative-expression * cast-expression
1814 multiplicative-expression / cast-expression
1815 multiplicative-expression % cast-expression */
1818 pp_c_multiplicative_expression (c_pretty_printer *pp, tree e)
1820 enum tree_code code = TREE_CODE (e);
1824 case TRUNC_DIV_EXPR:
1825 case TRUNC_MOD_EXPR:
1826 pp_multiplicative_expression (pp, TREE_OPERAND (e, 0));
1827 pp_c_whitespace (pp);
1828 if (code == MULT_EXPR)
1830 else if (code == TRUNC_DIV_EXPR)
1834 pp_c_whitespace (pp);
1835 pp_c_cast_expression (pp, TREE_OPERAND (e, 1));
1839 pp_c_cast_expression (pp, e);
1844 /* additive-expression:
1845 multiplicative-expression
1846 additive-expression + multiplicative-expression
1847 additive-expression - multiplicative-expression */
1850 pp_c_additive_expression (c_pretty_printer *pp, tree e)
1852 enum tree_code code = TREE_CODE (e);
1855 case POINTER_PLUS_EXPR:
1858 pp_c_additive_expression (pp, TREE_OPERAND (e, 0));
1859 pp_c_whitespace (pp);
1860 if (code == PLUS_EXPR || code == POINTER_PLUS_EXPR)
1864 pp_c_whitespace (pp);
1865 pp_multiplicative_expression (pp, TREE_OPERAND (e, 1));
1869 pp_multiplicative_expression (pp, e);
1874 /* additive-expression:
1876 shift-expression << additive-expression
1877 shift-expression >> additive-expression */
1880 pp_c_shift_expression (c_pretty_printer *pp, tree e)
1882 enum tree_code code = TREE_CODE (e);
1887 pp_c_shift_expression (pp, TREE_OPERAND (e, 0));
1888 pp_c_whitespace (pp);
1889 pp_string (pp, code == LSHIFT_EXPR ? "<<" : ">>");
1890 pp_c_whitespace (pp);
1891 pp_c_additive_expression (pp, TREE_OPERAND (e, 1));
1895 pp_c_additive_expression (pp, e);
1899 /* relational-expression:
1901 relational-expression < shift-expression
1902 relational-expression > shift-expression
1903 relational-expression <= shift-expression
1904 relational-expression >= shift-expression */
1907 pp_c_relational_expression (c_pretty_printer *pp, tree e)
1909 enum tree_code code = TREE_CODE (e);
1916 pp_c_relational_expression (pp, TREE_OPERAND (e, 0));
1917 pp_c_whitespace (pp);
1918 if (code == LT_EXPR)
1920 else if (code == GT_EXPR)
1922 else if (code == LE_EXPR)
1924 else if (code == GE_EXPR)
1925 pp_greater_equal (pp);
1926 pp_c_whitespace (pp);
1927 pp_c_shift_expression (pp, TREE_OPERAND (e, 1));
1931 pp_c_shift_expression (pp, e);
1936 /* equality-expression:
1937 relational-expression
1938 equality-expression == relational-expression
1939 equality-equality != relational-expression */
1942 pp_c_equality_expression (c_pretty_printer *pp, tree e)
1944 enum tree_code code = TREE_CODE (e);
1949 pp_c_equality_expression (pp, TREE_OPERAND (e, 0));
1950 pp_c_whitespace (pp);
1951 pp_string (pp, code == EQ_EXPR ? "==" : "!=");
1952 pp_c_whitespace (pp);
1953 pp_c_relational_expression (pp, TREE_OPERAND (e, 1));
1957 pp_c_relational_expression (pp, e);
1964 AND-expression & equality-equality */
1967 pp_c_and_expression (c_pretty_printer *pp, tree e)
1969 if (TREE_CODE (e) == BIT_AND_EXPR)
1971 pp_c_and_expression (pp, TREE_OPERAND (e, 0));
1972 pp_c_whitespace (pp);
1974 pp_c_whitespace (pp);
1975 pp_c_equality_expression (pp, TREE_OPERAND (e, 1));
1978 pp_c_equality_expression (pp, e);
1981 /* exclusive-OR-expression:
1983 exclusive-OR-expression ^ AND-expression */
1986 pp_c_exclusive_or_expression (c_pretty_printer *pp, tree e)
1988 if (TREE_CODE (e) == BIT_XOR_EXPR
1989 || TREE_CODE (e) == TRUTH_XOR_EXPR)
1991 pp_c_exclusive_or_expression (pp, TREE_OPERAND (e, 0));
1992 if (TREE_CODE (e) == BIT_XOR_EXPR)
1993 pp_c_maybe_whitespace (pp);
1995 pp_c_whitespace (pp);
1997 pp_c_whitespace (pp);
1998 pp_c_and_expression (pp, TREE_OPERAND (e, 1));
2001 pp_c_and_expression (pp, e);
2004 /* inclusive-OR-expression:
2005 exclusive-OR-expression
2006 inclusive-OR-expression | exclusive-OR-expression */
2009 pp_c_inclusive_or_expression (c_pretty_printer *pp, tree e)
2011 if (TREE_CODE (e) == BIT_IOR_EXPR)
2013 pp_c_exclusive_or_expression (pp, TREE_OPERAND (e, 0));
2014 pp_c_whitespace (pp);
2016 pp_c_whitespace (pp);
2017 pp_c_exclusive_or_expression (pp, TREE_OPERAND (e, 1));
2020 pp_c_exclusive_or_expression (pp, e);
2023 /* logical-AND-expression:
2024 inclusive-OR-expression
2025 logical-AND-expression && inclusive-OR-expression */
2028 pp_c_logical_and_expression (c_pretty_printer *pp, tree e)
2030 if (TREE_CODE (e) == TRUTH_ANDIF_EXPR
2031 || TREE_CODE (e) == TRUTH_AND_EXPR)
2033 pp_c_logical_and_expression (pp, TREE_OPERAND (e, 0));
2034 pp_c_whitespace (pp);
2035 pp_ampersand_ampersand (pp);
2036 pp_c_whitespace (pp);
2037 pp_c_inclusive_or_expression (pp, TREE_OPERAND (e, 1));
2040 pp_c_inclusive_or_expression (pp, e);
2043 /* logical-OR-expression:
2044 logical-AND-expression
2045 logical-OR-expression || logical-AND-expression */
2048 pp_c_logical_or_expression (c_pretty_printer *pp, tree e)
2050 if (TREE_CODE (e) == TRUTH_ORIF_EXPR
2051 || TREE_CODE (e) == TRUTH_OR_EXPR)
2053 pp_c_logical_or_expression (pp, TREE_OPERAND (e, 0));
2054 pp_c_whitespace (pp);
2056 pp_c_whitespace (pp);
2057 pp_c_logical_and_expression (pp, TREE_OPERAND (e, 1));
2060 pp_c_logical_and_expression (pp, e);
2063 /* conditional-expression:
2064 logical-OR-expression
2065 logical-OR-expression ? expression : conditional-expression */
2068 pp_c_conditional_expression (c_pretty_printer *pp, tree e)
2070 if (TREE_CODE (e) == COND_EXPR)
2072 pp_c_logical_or_expression (pp, TREE_OPERAND (e, 0));
2073 pp_c_whitespace (pp);
2075 pp_c_whitespace (pp);
2076 pp_expression (pp, TREE_OPERAND (e, 1));
2077 pp_c_whitespace (pp);
2079 pp_c_whitespace (pp);
2080 pp_c_conditional_expression (pp, TREE_OPERAND (e, 2));
2083 pp_c_logical_or_expression (pp, e);
2087 /* assignment-expression:
2088 conditional-expression
2089 unary-expression assignment-operator assignment-expression
2091 assignment-expression: one of
2092 = *= /= %= += -= >>= <<= &= ^= |= */
2095 pp_c_assignment_expression (c_pretty_printer *pp, tree e)
2097 if (TREE_CODE (e) == MODIFY_EXPR
2098 || TREE_CODE (e) == INIT_EXPR)
2100 pp_c_unary_expression (pp, TREE_OPERAND (e, 0));
2101 pp_c_whitespace (pp);
2104 pp_c_expression (pp, TREE_OPERAND (e, 1));
2107 pp_c_conditional_expression (pp, e);
2111 assignment-expression
2112 expression , assignment-expression
2114 Implementation note: instead of going through the usual recursion
2115 chain, I take the liberty of dispatching nodes to the appropriate
2116 functions. This makes some redundancy, but it worths it. That also
2117 prevents a possible infinite recursion between pp_c_primary_expression ()
2118 and pp_c_expression (). */
2121 pp_c_expression (c_pretty_printer *pp, tree e)
2123 switch (TREE_CODE (e))
2126 pp_c_integer_constant (pp, e);
2130 pp_c_floating_constant (pp, e);
2134 pp_c_fixed_constant (pp, e);
2138 pp_c_string_literal (pp, e);
2141 case IDENTIFIER_NODE:
2150 pp_primary_expression (pp, e);
2154 if (SSA_NAME_VAR (e)
2155 && !DECL_ARTIFICIAL (SSA_NAME_VAR (e)))
2156 pp_c_expression (pp, SSA_NAME_VAR (e));
2158 pp_c_ws_string (pp, M_("<unknown>"));
2161 case POSTINCREMENT_EXPR:
2162 case POSTDECREMENT_EXPR:
2164 case ARRAY_NOTATION_REF:
2172 case UNORDERED_EXPR:
2181 case COMPOUND_LITERAL_EXPR:
2183 pp_postfix_expression (pp, e);
2192 case TRUTH_NOT_EXPR:
2193 case PREINCREMENT_EXPR:
2194 case PREDECREMENT_EXPR:
2197 pp_c_unary_expression (pp, e);
2201 case FIX_TRUNC_EXPR:
2203 case VIEW_CONVERT_EXPR:
2204 pp_c_cast_expression (pp, e);
2208 case TRUNC_MOD_EXPR:
2209 case TRUNC_DIV_EXPR:
2210 pp_multiplicative_expression (pp, e);
2215 pp_c_shift_expression (pp, e);
2222 pp_c_relational_expression (pp, e);
2226 pp_c_and_expression (pp, e);
2230 case TRUTH_XOR_EXPR:
2231 pp_c_exclusive_or_expression (pp, e);
2235 pp_c_inclusive_or_expression (pp, e);
2238 case TRUTH_ANDIF_EXPR:
2239 case TRUTH_AND_EXPR:
2240 pp_c_logical_and_expression (pp, e);
2243 case TRUTH_ORIF_EXPR:
2245 pp_c_logical_or_expression (pp, e);
2250 pp_c_equality_expression (pp, e);
2254 pp_conditional_expression (pp, e);
2257 case POINTER_PLUS_EXPR:
2260 pp_c_additive_expression (pp, e);
2265 pp_assignment_expression (pp, e);
2269 pp_c_left_paren (pp);
2270 pp_expression (pp, TREE_OPERAND (e, 0));
2271 pp_separate_with (pp, ',');
2272 pp_assignment_expression (pp, TREE_OPERAND (e, 1));
2273 pp_c_right_paren (pp);
2276 case NON_LVALUE_EXPR:
2278 pp_expression (pp, TREE_OPERAND (e, 0));
2282 pp_postfix_expression (pp, TREE_OPERAND (e, 1));
2287 /* We don't yet have a way of dumping statements in a
2288 human-readable format. */
2289 pp_string (pp, "({...})");
2292 case C_MAYBE_CONST_EXPR:
2293 pp_c_expression (pp, C_MAYBE_CONST_EXPR_EXPR (e));
2297 pp_unsupported_tree (pp, e);
2307 pp_c_statement (c_pretty_printer *pp, tree stmt)
2312 if (pp_needs_newline (pp))
2313 pp_newline_and_indent (pp, 0);
2315 dump_generic_node (pp, stmt, pp_indentation (pp), 0, true);
2319 /* Initialize the PRETTY-PRINTER for handling C codes. */
2321 c_pretty_printer::c_pretty_printer ()
2326 declaration = pp_c_declaration;
2327 declaration_specifiers = pp_c_declaration_specifiers;
2328 declarator = pp_c_declarator;
2329 direct_declarator = pp_c_direct_declarator;
2330 type_specifier_seq = pp_c_specifier_qualifier_list;
2331 abstract_declarator = pp_c_abstract_declarator;
2332 direct_abstract_declarator = pp_c_direct_abstract_declarator;
2333 ptr_operator = pp_c_pointer;
2334 parameter_list = pp_c_parameter_type_list;
2335 type_id = pp_c_type_id;
2336 simple_type_specifier = pp_c_type_specifier;
2337 function_specifier = pp_c_function_specifier;
2338 storage_class_specifier = pp_c_storage_class_specifier;
2340 statement = pp_c_statement;
2342 constant = pp_c_constant;
2343 id_expression = pp_c_id_expression;
2344 primary_expression = pp_c_primary_expression;
2345 postfix_expression = pp_c_postfix_expression;
2346 unary_expression = pp_c_unary_expression;
2347 initializer = pp_c_initializer;
2348 multiplicative_expression = pp_c_multiplicative_expression;
2349 conditional_expression = pp_c_conditional_expression;
2350 assignment_expression = pp_c_assignment_expression;
2351 expression = pp_c_expression;
2355 /* Print the tree T in full, on file FILE. */
2358 print_c_tree (FILE *file, tree t)
2360 c_pretty_printer pp;
2362 pp_needs_newline (&pp) = true;
2363 pp.buffer->stream = file;
2364 pp_statement (&pp, t);
2365 pp_newline_and_flush (&pp);
2368 /* Print the tree T in full, on stderr. */
2371 debug_c_tree (tree t)
2373 print_c_tree (stderr, t);
2374 fputc ('\n', stderr);
2377 /* Output the DECL_NAME of T. If T has no DECL_NAME, output a string made
2378 up of T's memory address. */
2381 pp_c_tree_decl_identifier (c_pretty_printer *pp, tree t)
2385 gcc_assert (DECL_P (t));
2388 name = IDENTIFIER_POINTER (DECL_NAME (t));
2391 static char xname[8];
2392 sprintf (xname, "<U%4x>", ((unsigned)((uintptr_t)(t) & 0xffff)));
2396 pp_c_identifier (pp, name);