1 /* Subroutines common to both C and C++ pretty-printers.
2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc.
4 Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
24 #include "coretypes.h"
28 #include "c-pretty-print.h"
29 #include "tree-pretty-print.h"
30 #include "tree-iterator.h"
31 #include "diagnostic.h"
33 /* Translate if being used for diagnostics, but not for dump files or
35 #define M_(msgid) (pp_translate_identifiers (pp) ? _(msgid) : (msgid))
37 /* The pretty-printer code is primarily designed to closely follow
38 (GNU) C and C++ grammars. That is to be contrasted with spaghetti
39 codes we used to have in the past. Following a structured
40 approach (preferably the official grammars) is believed to make it
41 much easier to add extensions and nifty pretty-printing effects that
42 takes expression or declaration contexts into account. */
45 #define pp_c_maybe_whitespace(PP) \
47 if (pp_base (PP)->padding == pp_before) \
48 pp_c_whitespace (PP); \
52 static void pp_c_char (c_pretty_printer *, int);
54 /* postfix-expression */
55 static void pp_c_initializer_list (c_pretty_printer *, tree);
56 static void pp_c_brace_enclosed_initializer_list (c_pretty_printer *, tree);
58 static void pp_c_multiplicative_expression (c_pretty_printer *, tree);
59 static void pp_c_additive_expression (c_pretty_printer *, tree);
60 static void pp_c_shift_expression (c_pretty_printer *, tree);
61 static void pp_c_relational_expression (c_pretty_printer *, tree);
62 static void pp_c_equality_expression (c_pretty_printer *, tree);
63 static void pp_c_and_expression (c_pretty_printer *, tree);
64 static void pp_c_exclusive_or_expression (c_pretty_printer *, tree);
65 static void pp_c_inclusive_or_expression (c_pretty_printer *, tree);
66 static void pp_c_logical_and_expression (c_pretty_printer *, tree);
67 static void pp_c_conditional_expression (c_pretty_printer *, tree);
68 static void pp_c_assignment_expression (c_pretty_printer *, tree);
73 /* Helper functions. */
76 pp_c_whitespace (c_pretty_printer *pp)
79 pp_base (pp)->padding = pp_none;
83 pp_c_left_paren (c_pretty_printer *pp)
86 pp_base (pp)->padding = pp_none;
90 pp_c_right_paren (c_pretty_printer *pp)
93 pp_base (pp)->padding = pp_none;
97 pp_c_left_brace (c_pretty_printer *pp)
100 pp_base (pp)->padding = pp_none;
104 pp_c_right_brace (c_pretty_printer *pp)
107 pp_base (pp)->padding = pp_none;
111 pp_c_left_bracket (c_pretty_printer *pp)
113 pp_left_bracket (pp);
114 pp_base (pp)->padding = pp_none;
118 pp_c_right_bracket (c_pretty_printer *pp)
120 pp_right_bracket (pp);
121 pp_base (pp)->padding = pp_none;
125 pp_c_dot (c_pretty_printer *pp)
128 pp_base (pp)->padding = pp_none;
132 pp_c_ampersand (c_pretty_printer *pp)
135 pp_base (pp)->padding = pp_none;
139 pp_c_star (c_pretty_printer *pp)
142 pp_base (pp)->padding = pp_none;
146 pp_c_arrow (c_pretty_printer *pp)
149 pp_base (pp)->padding = pp_none;
153 pp_c_semicolon (c_pretty_printer *pp)
156 pp_base (pp)->padding = pp_none;
160 pp_c_complement (c_pretty_printer *pp)
163 pp_base (pp)->padding = pp_none;
167 pp_c_exclamation (c_pretty_printer *pp)
170 pp_base (pp)->padding = pp_none;
173 /* Print out the external representation of QUALIFIERS. */
176 pp_c_cv_qualifiers (c_pretty_printer *pp, int qualifiers, bool func_type)
178 const char *p = pp_last_position_in_text (pp);
179 bool previous = false;
184 /* The C programming language does not have references, but it is much
185 simpler to handle those here rather than going through the same
186 logic in the C++ pretty-printer. */
187 if (p != NULL && (*p == '*' || *p == '&'))
188 pp_c_whitespace (pp);
190 if (qualifiers & TYPE_QUAL_CONST)
192 pp_c_ws_string (pp, func_type ? "__attribute__((const))" : "const");
196 if (qualifiers & TYPE_QUAL_VOLATILE)
199 pp_c_whitespace (pp);
200 pp_c_ws_string (pp, func_type ? "__attribute__((noreturn))" : "volatile");
204 if (qualifiers & TYPE_QUAL_RESTRICT)
207 pp_c_whitespace (pp);
208 pp_c_ws_string (pp, flag_isoc99 ? "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_tree_decl_identifier (pp, 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 (TREE_CODE (t) != 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 ? "_Complex" : "__complex__");
480 else if (code == VECTOR_TYPE)
482 pp_c_ws_string (pp, "__vector");
483 pp_c_left_paren (pp);
484 pp_wide_integer (pp, TYPE_VECTOR_SUBPARTS (t));
485 pp_c_right_paren (pp);
486 pp_c_whitespace (pp);
488 pp_c_specifier_qualifier_list (pp, TREE_TYPE (t));
492 pp_simple_type_specifier (pp, t);
497 /* parameter-type-list:
502 parameter-declaration
503 parameter-list , parameter-declaration
505 parameter-declaration:
506 declaration-specifiers declarator
507 declaration-specifiers abstract-declarator(opt) */
510 pp_c_parameter_type_list (c_pretty_printer *pp, tree t)
512 bool want_parm_decl = DECL_P (t) && !(pp->flags & pp_c_flag_abstract);
513 tree parms = want_parm_decl ? DECL_ARGUMENTS (t) : TYPE_ARG_TYPES (t);
514 pp_c_left_paren (pp);
515 if (parms == void_list_node)
516 pp_c_ws_string (pp, "void");
520 for ( ; parms && parms != void_list_node; parms = TREE_CHAIN (parms))
523 pp_separate_with (pp, ',');
525 pp_declaration_specifiers
526 (pp, want_parm_decl ? parms : TREE_VALUE (parms));
528 pp_declarator (pp, parms);
530 pp_abstract_declarator (pp, TREE_VALUE (parms));
533 pp_c_right_paren (pp);
536 /* abstract-declarator:
538 pointer(opt) direct-abstract-declarator */
541 pp_c_abstract_declarator (c_pretty_printer *pp, tree t)
543 if (TREE_CODE (t) == POINTER_TYPE)
545 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE
546 || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
547 pp_c_right_paren (pp);
551 pp_direct_abstract_declarator (pp, t);
554 /* direct-abstract-declarator:
555 ( abstract-declarator )
556 direct-abstract-declarator(opt) [ assignment-expression(opt) ]
557 direct-abstract-declarator(opt) [ * ]
558 direct-abstract-declarator(opt) ( parameter-type-list(opt) ) */
561 pp_c_direct_abstract_declarator (c_pretty_printer *pp, tree t)
563 switch (TREE_CODE (t))
566 pp_abstract_declarator (pp, t);
570 pp_c_parameter_type_list (pp, t);
571 pp_direct_abstract_declarator (pp, TREE_TYPE (t));
575 pp_c_left_bracket (pp);
576 if (TYPE_DOMAIN (t) && TYPE_MAX_VALUE (TYPE_DOMAIN (t)))
578 tree maxval = TYPE_MAX_VALUE (TYPE_DOMAIN (t));
579 tree type = TREE_TYPE (maxval);
581 if (host_integerp (maxval, 0))
582 pp_wide_integer (pp, tree_low_cst (maxval, 0) + 1);
584 pp_expression (pp, fold_build2 (PLUS_EXPR, type, maxval,
585 build_int_cst (type, 1)));
587 pp_c_right_bracket (pp);
588 pp_direct_abstract_declarator (pp, TREE_TYPE (t));
591 case IDENTIFIER_NODE:
596 case FIXED_POINT_TYPE:
606 pp_unsupported_tree (pp, t);
612 specifier-qualifier-list abstract-declarator(opt) */
615 pp_c_type_id (c_pretty_printer *pp, tree t)
617 pp_c_specifier_qualifier_list (pp, t);
618 pp_abstract_declarator (pp, t);
621 /* storage-class-specifier:
629 pp_c_storage_class_specifier (c_pretty_printer *pp, tree t)
631 if (TREE_CODE (t) == TYPE_DECL)
632 pp_c_ws_string (pp, "typedef");
635 if (DECL_REGISTER (t))
636 pp_c_ws_string (pp, "register");
637 else if (TREE_STATIC (t) && TREE_CODE (t) == VAR_DECL)
638 pp_c_ws_string (pp, "static");
642 /* function-specifier:
646 pp_c_function_specifier (c_pretty_printer *pp, tree t)
648 if (TREE_CODE (t) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (t))
649 pp_c_ws_string (pp, "inline");
652 /* declaration-specifiers:
653 storage-class-specifier declaration-specifiers(opt)
654 type-specifier declaration-specifiers(opt)
655 type-qualifier declaration-specifiers(opt)
656 function-specifier declaration-specifiers(opt) */
659 pp_c_declaration_specifiers (c_pretty_printer *pp, tree t)
661 pp_storage_class_specifier (pp, t);
662 pp_function_specifier (pp, t);
663 pp_c_specifier_qualifier_list (pp, DECL_P (t) ? TREE_TYPE (t) : t);
669 direct-declarator [ type-qualifier-list(opt) assignment-expression(opt) ]
670 direct-declarator [ static type-qualifier-list(opt) assignment-expression(opt)]
671 direct-declarator [ type-qualifier-list static assignment-expression ]
672 direct-declarator [ type-qualifier-list * ]
673 direct-declarator ( parameter-type-list )
674 direct-declarator ( identifier-list(opt) ) */
677 pp_c_direct_declarator (c_pretty_printer *pp, tree t)
679 switch (TREE_CODE (t))
686 pp_c_space_for_pointer_operator (pp, TREE_TYPE (t));
687 pp_c_tree_decl_identifier (pp, t);
692 pp_abstract_declarator (pp, TREE_TYPE (t));
696 pp_parameter_list (pp, t);
697 pp_abstract_declarator (pp, TREE_TYPE (t));
701 pp_c_space_for_pointer_operator (pp, TREE_TYPE (TREE_TYPE (t)));
702 pp_c_tree_decl_identifier (pp, t);
703 if (pp_c_base (pp)->flags & pp_c_flag_abstract)
704 pp_abstract_declarator (pp, TREE_TYPE (t));
707 pp_parameter_list (pp, t);
708 pp_abstract_declarator (pp, TREE_TYPE (TREE_TYPE (t)));
714 case FIXED_POINT_TYPE:
721 pp_unsupported_tree (pp, t);
728 pointer(opt) direct-declarator */
731 pp_c_declarator (c_pretty_printer *pp, tree t)
733 switch (TREE_CODE (t))
737 case FIXED_POINT_TYPE:
750 pp_direct_declarator (pp, t);
755 pp_unsupported_tree (pp, t);
761 declaration-specifiers init-declarator-list(opt) ; */
764 pp_c_declaration (c_pretty_printer *pp, tree t)
766 pp_declaration_specifiers (pp, t);
767 pp_c_init_declarator (pp, t);
770 /* Pretty-print ATTRIBUTES using GNU C extension syntax. */
773 pp_c_attributes (c_pretty_printer *pp, tree attributes)
775 if (attributes == NULL_TREE)
778 pp_c_ws_string (pp, "__attribute__");
779 pp_c_left_paren (pp);
780 pp_c_left_paren (pp);
781 for (; attributes != NULL_TREE; attributes = TREE_CHAIN (attributes))
783 pp_tree_identifier (pp, TREE_PURPOSE (attributes));
784 if (TREE_VALUE (attributes))
785 pp_c_call_argument_list (pp, TREE_VALUE (attributes));
787 if (TREE_CHAIN (attributes))
788 pp_separate_with (pp, ',');
790 pp_c_right_paren (pp);
791 pp_c_right_paren (pp);
794 /* Pretty-print ATTRIBUTES using GNU C extension syntax for attributes
795 marked to be displayed on disgnostic. */
798 pp_c_attributes_display (c_pretty_printer *pp, tree a)
800 bool is_first = true;
805 for (; a != NULL_TREE; a = TREE_CHAIN (a))
807 const struct attribute_spec *as;
808 as = lookup_attribute_spec (TREE_PURPOSE (a));
809 if (!as || as->affects_type_identity == false)
813 pp_c_ws_string (pp, "__attribute__");
814 pp_c_left_paren (pp);
815 pp_c_left_paren (pp);
820 pp_separate_with (pp, ',');
822 pp_tree_identifier (pp, TREE_PURPOSE (a));
824 pp_c_call_argument_list (pp, TREE_VALUE (a));
829 pp_c_right_paren (pp);
830 pp_c_right_paren (pp);
831 pp_c_whitespace (pp);
835 /* function-definition:
836 declaration-specifiers declarator compound-statement */
839 pp_c_function_definition (c_pretty_printer *pp, tree t)
841 pp_declaration_specifiers (pp, t);
842 pp_declarator (pp, t);
843 pp_needs_newline (pp) = true;
844 pp_statement (pp, DECL_SAVED_TREE (t));
852 /* Print out a c-char. This is called solely for characters which are
853 in the *target* execution character set. We ought to convert them
854 back to the *host* execution character set before printing, but we
855 have no way to do this at present. A decent compromise is to print
856 all characters as if they were in the host execution character set,
857 and not attempt to recover any named escape characters, but render
858 all unprintables as octal escapes. If the host and target character
859 sets are the same, this produces relatively readable output. If they
860 are not the same, strings may appear as gibberish, but that's okay
861 (in fact, it may well be what the reader wants, e.g. if they are looking
862 to see if conversion to the target character set happened correctly).
864 A special case: we need to prefix \, ", and ' with backslashes. It is
865 correct to do so for the *host*'s \, ", and ', because the rest of the
866 file appears in the host character set. */
869 pp_c_char (c_pretty_printer *pp, int c)
875 case '\\': pp_string (pp, "\\\\"); break;
876 case '\'': pp_string (pp, "\\\'"); break;
877 case '\"': pp_string (pp, "\\\""); break;
878 default: pp_character (pp, c);
882 pp_scalar (pp, "\\%03o", (unsigned) c);
885 /* Print out a STRING literal. */
888 pp_c_string_literal (c_pretty_printer *pp, tree s)
890 const char *p = TREE_STRING_POINTER (s);
891 int n = TREE_STRING_LENGTH (s) - 1;
894 for (i = 0; i < n; ++i)
895 pp_c_char (pp, p[i]);
899 /* Pretty-print an INTEGER literal. */
902 pp_c_integer_constant (c_pretty_printer *pp, tree i)
904 tree type = TREE_TYPE (i);
906 if (TREE_INT_CST_HIGH (i) == 0)
907 pp_wide_integer (pp, TREE_INT_CST_LOW (i));
910 unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (i);
911 HOST_WIDE_INT high = TREE_INT_CST_HIGH (i);
912 if (tree_int_cst_sgn (i) < 0)
914 pp_character (pp, '-');
918 sprintf (pp_buffer (pp)->digit_buffer, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
919 (unsigned HOST_WIDE_INT) high, (unsigned HOST_WIDE_INT) low);
920 pp_string (pp, pp_buffer (pp)->digit_buffer);
922 if (TYPE_UNSIGNED (type))
923 pp_character (pp, 'u');
924 if (type == long_integer_type_node || type == long_unsigned_type_node)
925 pp_character (pp, 'l');
926 else if (type == long_long_integer_type_node
927 || type == long_long_unsigned_type_node)
928 pp_string (pp, "ll");
929 else if (type == int128_integer_type_node
930 || type == int128_unsigned_type_node)
931 pp_string (pp, "I128");
934 /* Print out a CHARACTER literal. */
937 pp_c_character_constant (c_pretty_printer *pp, tree c)
939 tree type = TREE_TYPE (c);
940 if (type == wchar_type_node)
941 pp_character (pp, 'L');
943 if (host_integerp (c, TYPE_UNSIGNED (type)))
944 pp_c_char (pp, tree_low_cst (c, TYPE_UNSIGNED (type)));
946 pp_scalar (pp, "\\x%x", (unsigned) TREE_INT_CST_LOW (c));
950 /* Print out a BOOLEAN literal. */
953 pp_c_bool_constant (c_pretty_printer *pp, tree b)
955 if (b == boolean_false_node)
957 if (c_dialect_cxx ())
958 pp_c_ws_string (pp, "false");
959 else if (flag_isoc99)
960 pp_c_ws_string (pp, "_False");
962 pp_unsupported_tree (pp, b);
964 else if (b == boolean_true_node)
966 if (c_dialect_cxx ())
967 pp_c_ws_string (pp, "true");
968 else if (flag_isoc99)
969 pp_c_ws_string (pp, "_True");
971 pp_unsupported_tree (pp, b);
973 else if (TREE_CODE (b) == INTEGER_CST)
974 pp_c_integer_constant (pp, b);
976 pp_unsupported_tree (pp, b);
979 /* Attempt to print out an ENUMERATOR. Return true on success. Else return
980 false; that means the value was obtained by a cast, in which case
981 print out the type-id part of the cast-expression -- the casted value
982 is then printed by pp_c_integer_literal. */
985 pp_c_enumeration_constant (c_pretty_printer *pp, tree e)
987 bool value_is_named = true;
988 tree type = TREE_TYPE (e);
991 /* Find the name of this constant. */
992 for (value = TYPE_VALUES (type);
993 value != NULL_TREE && !tree_int_cst_equal (TREE_VALUE (value), e);
994 value = TREE_CHAIN (value))
997 if (value != NULL_TREE)
998 pp_id_expression (pp, TREE_PURPOSE (value));
1001 /* Value must have been cast. */
1002 pp_c_type_cast (pp, type);
1003 value_is_named = false;
1006 return value_is_named;
1009 /* Print out a REAL value as a decimal-floating-constant. */
1012 pp_c_floating_constant (c_pretty_printer *pp, tree r)
1014 real_to_decimal (pp_buffer (pp)->digit_buffer, &TREE_REAL_CST (r),
1015 sizeof (pp_buffer (pp)->digit_buffer), 0, 1);
1016 pp_string (pp, pp_buffer(pp)->digit_buffer);
1017 if (TREE_TYPE (r) == float_type_node)
1018 pp_character (pp, 'f');
1019 else if (TREE_TYPE (r) == long_double_type_node)
1020 pp_character (pp, 'l');
1021 else if (TREE_TYPE (r) == dfloat128_type_node)
1022 pp_string (pp, "dl");
1023 else if (TREE_TYPE (r) == dfloat64_type_node)
1024 pp_string (pp, "dd");
1025 else if (TREE_TYPE (r) == dfloat32_type_node)
1026 pp_string (pp, "df");
1029 /* Print out a FIXED value as a decimal-floating-constant. */
1032 pp_c_fixed_constant (c_pretty_printer *pp, tree r)
1034 fixed_to_decimal (pp_buffer (pp)->digit_buffer, &TREE_FIXED_CST (r),
1035 sizeof (pp_buffer (pp)->digit_buffer));
1036 pp_string (pp, pp_buffer(pp)->digit_buffer);
1039 /* Pretty-print a compound literal expression. GNU extensions include
1040 vector constants. */
1043 pp_c_compound_literal (c_pretty_printer *pp, tree e)
1045 tree type = TREE_TYPE (e);
1046 pp_c_type_cast (pp, type);
1048 switch (TREE_CODE (type))
1055 pp_c_brace_enclosed_initializer_list (pp, e);
1059 pp_unsupported_tree (pp, e);
1064 /* Pretty-print a COMPLEX_EXPR expression. */
1067 pp_c_complex_expr (c_pretty_printer *pp, tree e)
1069 /* Handle a few common special cases, otherwise fallback
1070 to printing it as compound literal. */
1071 tree type = TREE_TYPE (e);
1072 tree realexpr = TREE_OPERAND (e, 0);
1073 tree imagexpr = TREE_OPERAND (e, 1);
1075 /* Cast of an COMPLEX_TYPE expression to a different COMPLEX_TYPE. */
1076 if (TREE_CODE (realexpr) == NOP_EXPR
1077 && TREE_CODE (imagexpr) == NOP_EXPR
1078 && TREE_TYPE (realexpr) == TREE_TYPE (type)
1079 && TREE_TYPE (imagexpr) == TREE_TYPE (type)
1080 && TREE_CODE (TREE_OPERAND (realexpr, 0)) == REALPART_EXPR
1081 && TREE_CODE (TREE_OPERAND (imagexpr, 0)) == IMAGPART_EXPR
1082 && TREE_OPERAND (TREE_OPERAND (realexpr, 0), 0)
1083 == TREE_OPERAND (TREE_OPERAND (imagexpr, 0), 0))
1085 pp_c_type_cast (pp, type);
1086 pp_expression (pp, TREE_OPERAND (TREE_OPERAND (realexpr, 0), 0));
1090 /* Cast of an scalar expression to COMPLEX_TYPE. */
1091 if ((integer_zerop (imagexpr) || real_zerop (imagexpr))
1092 && TREE_TYPE (realexpr) == TREE_TYPE (type))
1094 pp_c_type_cast (pp, type);
1095 if (TREE_CODE (realexpr) == NOP_EXPR)
1096 realexpr = TREE_OPERAND (realexpr, 0);
1097 pp_expression (pp, realexpr);
1101 pp_c_compound_literal (pp, e);
1107 fixed-point-constant
1108 enumeration-constant
1109 character-constant */
1112 pp_c_constant (c_pretty_printer *pp, tree e)
1114 const enum tree_code code = TREE_CODE (e);
1120 tree type = TREE_TYPE (e);
1121 if (type == boolean_type_node)
1122 pp_c_bool_constant (pp, e);
1123 else if (type == char_type_node)
1124 pp_c_character_constant (pp, e);
1125 else if (TREE_CODE (type) == ENUMERAL_TYPE
1126 && pp_c_enumeration_constant (pp, e))
1129 pp_c_integer_constant (pp, e);
1134 pp_c_floating_constant (pp, e);
1138 pp_c_fixed_constant (pp, e);
1142 pp_c_string_literal (pp, e);
1146 /* Sometimes, we are confused and we think a complex literal
1147 is a constant. Such thing is a compound literal which
1148 grammatically belongs to postfix-expr production. */
1149 pp_c_compound_literal (pp, e);
1153 pp_unsupported_tree (pp, e);
1158 /* Pretty-print a string such as an identifier, without changing its
1159 encoding, preceded by whitespace is necessary. */
1162 pp_c_ws_string (c_pretty_printer *pp, const char *str)
1164 pp_c_maybe_whitespace (pp);
1165 pp_string (pp, str);
1166 pp_base (pp)->padding = pp_before;
1169 /* Pretty-print an IDENTIFIER_NODE, which may contain UTF-8 sequences
1170 that need converting to the locale encoding, preceded by whitespace
1174 pp_c_identifier (c_pretty_printer *pp, const char *id)
1176 pp_c_maybe_whitespace (pp);
1177 pp_identifier (pp, id);
1178 pp_base (pp)->padding = pp_before;
1181 /* Pretty-print a C primary-expression.
1189 pp_c_primary_expression (c_pretty_printer *pp, tree e)
1191 switch (TREE_CODE (e))
1199 pp_c_tree_decl_identifier (pp, e);
1202 case IDENTIFIER_NODE:
1203 pp_c_tree_identifier (pp, e);
1207 pp_c_ws_string (pp, M_("<erroneous-expression>"));
1211 pp_c_ws_string (pp, M_("<return-value>"));
1218 pp_c_constant (pp, e);
1222 pp_c_ws_string (pp, "__builtin_memcpy");
1223 pp_c_left_paren (pp);
1225 pp_primary_expression (pp, TREE_OPERAND (e, 0));
1226 pp_separate_with (pp, ',');
1228 pp_initializer (pp, TREE_OPERAND (e, 1));
1229 if (TREE_OPERAND (e, 2))
1231 pp_separate_with (pp, ',');
1232 pp_c_expression (pp, TREE_OPERAND (e, 2));
1234 pp_c_right_paren (pp);
1238 /* FIXME: Make sure we won't get into an infinite loop. */
1239 pp_c_left_paren (pp);
1240 pp_expression (pp, e);
1241 pp_c_right_paren (pp);
1246 /* Print out a C initializer -- also support C compound-literals.
1248 assignment-expression:
1249 { initializer-list }
1250 { initializer-list , } */
1253 pp_c_initializer (c_pretty_printer *pp, tree e)
1255 if (TREE_CODE (e) == CONSTRUCTOR)
1256 pp_c_brace_enclosed_initializer_list (pp, e);
1258 pp_expression (pp, e);
1263 declarator = initializer */
1266 pp_c_init_declarator (c_pretty_printer *pp, tree t)
1268 pp_declarator (pp, t);
1269 /* We don't want to output function definitions here. There are handled
1270 elsewhere (and the syntactic form is bogus anyway). */
1271 if (TREE_CODE (t) != FUNCTION_DECL && DECL_INITIAL (t))
1273 tree init = DECL_INITIAL (t);
1274 /* This C++ bit is handled here because it is easier to do so.
1275 In templates, the C++ parser builds a TREE_LIST for a
1276 direct-initialization; the TREE_PURPOSE is the variable to
1277 initialize and the TREE_VALUE is the initializer. */
1278 if (TREE_CODE (init) == TREE_LIST)
1280 pp_c_left_paren (pp);
1281 pp_expression (pp, TREE_VALUE (init));
1282 pp_right_paren (pp);
1289 pp_c_initializer (pp, init);
1294 /* initializer-list:
1295 designation(opt) initializer
1296 initializer-list , designation(opt) initializer
1303 designator-list designator
1306 [ constant-expression ]
1310 pp_c_initializer_list (c_pretty_printer *pp, tree e)
1312 tree type = TREE_TYPE (e);
1313 const enum tree_code code = TREE_CODE (type);
1315 if (TREE_CODE (e) == CONSTRUCTOR)
1317 pp_c_constructor_elts (pp, CONSTRUCTOR_ELTS (e));
1327 tree init = TREE_OPERAND (e, 0);
1328 for (; init != NULL_TREE; init = TREE_CHAIN (init))
1330 if (code == RECORD_TYPE || code == UNION_TYPE)
1333 pp_c_primary_expression (pp, TREE_PURPOSE (init));
1337 pp_c_left_bracket (pp);
1338 if (TREE_PURPOSE (init))
1339 pp_c_constant (pp, TREE_PURPOSE (init));
1340 pp_c_right_bracket (pp);
1342 pp_c_whitespace (pp);
1344 pp_c_whitespace (pp);
1345 pp_initializer (pp, TREE_VALUE (init));
1346 if (TREE_CHAIN (init))
1347 pp_separate_with (pp, ',');
1353 if (TREE_CODE (e) == VECTOR_CST)
1354 pp_c_expression_list (pp, TREE_VECTOR_CST_ELTS (e));
1360 if (TREE_CODE (e) == COMPLEX_CST || TREE_CODE (e) == COMPLEX_EXPR)
1362 const bool cst = TREE_CODE (e) == COMPLEX_CST;
1363 pp_expression (pp, cst ? TREE_REALPART (e) : TREE_OPERAND (e, 0));
1364 pp_separate_with (pp, ',');
1365 pp_expression (pp, cst ? TREE_IMAGPART (e) : TREE_OPERAND (e, 1));
1375 pp_unsupported_tree (pp, type);
1378 /* Pretty-print a brace-enclosed initializer-list. */
1381 pp_c_brace_enclosed_initializer_list (c_pretty_printer *pp, tree l)
1383 pp_c_left_brace (pp);
1384 pp_c_initializer_list (pp, l);
1385 pp_c_right_brace (pp);
1389 /* This is a convenient function, used to bridge gap between C and C++
1396 pp_c_id_expression (c_pretty_printer *pp, tree t)
1398 switch (TREE_CODE (t))
1407 pp_c_tree_decl_identifier (pp, t);
1410 case IDENTIFIER_NODE:
1411 pp_c_tree_identifier (pp, t);
1415 pp_unsupported_tree (pp, t);
1420 /* postfix-expression:
1422 postfix-expression [ expression ]
1423 postfix-expression ( argument-expression-list(opt) )
1424 postfix-expression . identifier
1425 postfix-expression -> identifier
1426 postfix-expression ++
1427 postfix-expression --
1428 ( type-name ) { initializer-list }
1429 ( type-name ) { initializer-list , } */
1432 pp_c_postfix_expression (c_pretty_printer *pp, tree e)
1434 enum tree_code code = TREE_CODE (e);
1437 case POSTINCREMENT_EXPR:
1438 case POSTDECREMENT_EXPR:
1439 pp_postfix_expression (pp, TREE_OPERAND (e, 0));
1440 pp_string (pp, code == POSTINCREMENT_EXPR ? "++" : "--");
1444 pp_postfix_expression (pp, TREE_OPERAND (e, 0));
1445 pp_c_left_bracket (pp);
1446 pp_expression (pp, TREE_OPERAND (e, 1));
1447 pp_c_right_bracket (pp);
1452 call_expr_arg_iterator iter;
1454 pp_postfix_expression (pp, CALL_EXPR_FN (e));
1455 pp_c_left_paren (pp);
1456 FOR_EACH_CALL_EXPR_ARG (arg, iter, e)
1458 pp_expression (pp, arg);
1459 if (more_call_expr_args_p (&iter))
1460 pp_separate_with (pp, ',');
1462 pp_c_right_paren (pp);
1466 case UNORDERED_EXPR:
1467 pp_c_ws_string (pp, flag_isoc99
1469 : "__builtin_isunordered");
1473 pp_c_ws_string (pp, flag_isoc99
1475 : "!__builtin_isunordered");
1479 pp_c_ws_string (pp, flag_isoc99
1481 : "!__builtin_isgreaterequal");
1485 pp_c_ws_string (pp, flag_isoc99
1487 : "!__builtin_isgreater");
1491 pp_c_ws_string (pp, flag_isoc99
1493 : "!__builtin_islessequal");
1497 pp_c_ws_string (pp, flag_isoc99
1499 : "!__builtin_isless");
1503 pp_c_ws_string (pp, flag_isoc99
1505 : "!__builtin_islessgreater");
1509 pp_c_ws_string (pp, flag_isoc99
1511 : "__builtin_islessgreater");
1515 pp_c_left_paren (pp);
1516 pp_expression (pp, TREE_OPERAND (e, 0));
1517 pp_separate_with (pp, ',');
1518 pp_expression (pp, TREE_OPERAND (e, 1));
1519 pp_c_right_paren (pp);
1523 pp_c_ws_string (pp, "__builtin_abs");
1524 pp_c_left_paren (pp);
1525 pp_expression (pp, TREE_OPERAND (e, 0));
1526 pp_c_right_paren (pp);
1531 tree object = TREE_OPERAND (e, 0);
1532 if (TREE_CODE (object) == INDIRECT_REF)
1534 pp_postfix_expression (pp, TREE_OPERAND (object, 0));
1539 pp_postfix_expression (pp, object);
1542 pp_expression (pp, TREE_OPERAND (e, 1));
1548 tree type = TREE_TYPE (e);
1550 type = signed_or_unsigned_type_for (TYPE_UNSIGNED (type), type);
1552 && tree_int_cst_equal (TYPE_SIZE (type), TREE_OPERAND (e, 1)))
1554 HOST_WIDE_INT bitpos = tree_low_cst (TREE_OPERAND (e, 2), 0);
1555 HOST_WIDE_INT size = tree_low_cst (TYPE_SIZE (type), 0);
1556 if ((bitpos % size) == 0)
1558 pp_c_left_paren (pp);
1559 pp_c_left_paren (pp);
1560 pp_type_id (pp, type);
1562 pp_c_right_paren (pp);
1563 pp_c_ampersand (pp);
1564 pp_expression (pp, TREE_OPERAND (e, 0));
1565 pp_c_right_paren (pp);
1566 pp_c_left_bracket (pp);
1567 pp_wide_integer (pp, bitpos / size);
1568 pp_c_right_bracket (pp);
1572 pp_unsupported_tree (pp, e);
1577 pp_c_expression (pp, e);
1582 pp_c_compound_literal (pp, e);
1586 pp_c_complex_expr (pp, e);
1589 case COMPOUND_LITERAL_EXPR:
1590 e = DECL_INITIAL (COMPOUND_LITERAL_EXPR_DECL (e));
1593 pp_initializer (pp, e);
1597 pp_c_ws_string (pp, "__builtin_va_arg");
1598 pp_c_left_paren (pp);
1599 pp_assignment_expression (pp, TREE_OPERAND (e, 0));
1600 pp_separate_with (pp, ',');
1601 pp_type_id (pp, TREE_TYPE (e));
1602 pp_c_right_paren (pp);
1606 if (TREE_CODE (TREE_OPERAND (e, 0)) == FUNCTION_DECL)
1608 pp_c_id_expression (pp, TREE_OPERAND (e, 0));
1611 /* else fall through. */
1614 pp_primary_expression (pp, e);
1619 /* Print out an expression-list; E is expected to be a TREE_LIST. */
1622 pp_c_expression_list (c_pretty_printer *pp, tree e)
1624 for (; e != NULL_TREE; e = TREE_CHAIN (e))
1626 pp_expression (pp, TREE_VALUE (e));
1628 pp_separate_with (pp, ',');
1632 /* Print out V, which contains the elements of a constructor. */
1635 pp_c_constructor_elts (c_pretty_printer *pp, VEC(constructor_elt,gc) *v)
1637 unsigned HOST_WIDE_INT ix;
1640 FOR_EACH_CONSTRUCTOR_VALUE (v, ix, value)
1642 pp_expression (pp, value);
1643 if (ix != VEC_length (constructor_elt, v) - 1)
1644 pp_separate_with (pp, ',');
1648 /* Print out an expression-list in parens, as if it were the argument
1649 list to a function. */
1652 pp_c_call_argument_list (c_pretty_printer *pp, tree t)
1654 pp_c_left_paren (pp);
1655 if (t && TREE_CODE (t) == TREE_LIST)
1656 pp_c_expression_list (pp, t);
1657 pp_c_right_paren (pp);
1660 /* unary-expression:
1664 unary-operator cast-expression
1665 sizeof unary-expression
1668 unary-operator: one of
1673 __alignof__ unary-expression
1674 __alignof__ ( type-id )
1675 __real__ unary-expression
1676 __imag__ unary-expression */
1679 pp_c_unary_expression (c_pretty_printer *pp, tree e)
1681 enum tree_code code = TREE_CODE (e);
1684 case PREINCREMENT_EXPR:
1685 case PREDECREMENT_EXPR:
1686 pp_string (pp, code == PREINCREMENT_EXPR ? "++" : "--");
1687 pp_c_unary_expression (pp, TREE_OPERAND (e, 0));
1694 case TRUTH_NOT_EXPR:
1696 /* String literal are used by address. */
1697 if (code == ADDR_EXPR && TREE_CODE (TREE_OPERAND (e, 0)) != STRING_CST)
1699 else if (code == INDIRECT_REF)
1701 else if (code == NEGATE_EXPR)
1703 else if (code == BIT_NOT_EXPR || code == CONJ_EXPR)
1705 else if (code == TRUTH_NOT_EXPR)
1706 pp_exclamation (pp);
1707 pp_c_cast_expression (pp, TREE_OPERAND (e, 0));
1711 if (TREE_CODE (TREE_OPERAND (e, 0)) == ADDR_EXPR
1712 && integer_zerop (TREE_OPERAND (e, 1)))
1713 pp_c_expression (pp, TREE_OPERAND (TREE_OPERAND (e, 0), 0));
1717 if (!integer_zerop (TREE_OPERAND (e, 1)))
1719 pp_c_left_paren (pp);
1720 if (!integer_onep (TYPE_SIZE_UNIT
1721 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (e, 0))))))
1722 pp_c_type_cast (pp, ptr_type_node);
1724 pp_c_cast_expression (pp, TREE_OPERAND (e, 0));
1725 if (!integer_zerop (TREE_OPERAND (e, 1)))
1728 pp_c_integer_constant (pp,
1729 fold_convert (ssizetype,
1730 TREE_OPERAND (e, 1)));
1731 pp_c_right_paren (pp);
1738 pp_c_ws_string (pp, code == REALPART_EXPR ? "__real__" : "__imag__");
1739 pp_c_whitespace (pp);
1740 pp_unary_expression (pp, TREE_OPERAND (e, 0));
1744 pp_postfix_expression (pp, e);
1751 ( type-name ) cast-expression */
1754 pp_c_cast_expression (c_pretty_printer *pp, tree e)
1756 switch (TREE_CODE (e))
1759 case FIX_TRUNC_EXPR:
1761 case VIEW_CONVERT_EXPR:
1762 pp_c_type_cast (pp, TREE_TYPE (e));
1763 pp_c_cast_expression (pp, TREE_OPERAND (e, 0));
1767 pp_unary_expression (pp, e);
1771 /* multiplicative-expression:
1773 multiplicative-expression * cast-expression
1774 multiplicative-expression / cast-expression
1775 multiplicative-expression % cast-expression */
1778 pp_c_multiplicative_expression (c_pretty_printer *pp, tree e)
1780 enum tree_code code = TREE_CODE (e);
1784 case TRUNC_DIV_EXPR:
1785 case TRUNC_MOD_EXPR:
1786 pp_multiplicative_expression (pp, TREE_OPERAND (e, 0));
1787 pp_c_whitespace (pp);
1788 if (code == MULT_EXPR)
1790 else if (code == TRUNC_DIV_EXPR)
1794 pp_c_whitespace (pp);
1795 pp_c_cast_expression (pp, TREE_OPERAND (e, 1));
1799 pp_c_cast_expression (pp, e);
1804 /* additive-expression:
1805 multiplicative-expression
1806 additive-expression + multiplicative-expression
1807 additive-expression - multiplicative-expression */
1810 pp_c_additive_expression (c_pretty_printer *pp, tree e)
1812 enum tree_code code = TREE_CODE (e);
1815 case POINTER_PLUS_EXPR:
1818 pp_c_additive_expression (pp, TREE_OPERAND (e, 0));
1819 pp_c_whitespace (pp);
1820 if (code == PLUS_EXPR || code == POINTER_PLUS_EXPR)
1824 pp_c_whitespace (pp);
1825 pp_multiplicative_expression (pp, TREE_OPERAND (e, 1));
1829 pp_multiplicative_expression (pp, e);
1834 /* additive-expression:
1836 shift-expression << additive-expression
1837 shift-expression >> additive-expression */
1840 pp_c_shift_expression (c_pretty_printer *pp, tree e)
1842 enum tree_code code = TREE_CODE (e);
1847 pp_c_shift_expression (pp, TREE_OPERAND (e, 0));
1848 pp_c_whitespace (pp);
1849 pp_string (pp, code == LSHIFT_EXPR ? "<<" : ">>");
1850 pp_c_whitespace (pp);
1851 pp_c_additive_expression (pp, TREE_OPERAND (e, 1));
1855 pp_c_additive_expression (pp, e);
1859 /* relational-expression:
1861 relational-expression < shift-expression
1862 relational-expression > shift-expression
1863 relational-expression <= shift-expression
1864 relational-expression >= shift-expression */
1867 pp_c_relational_expression (c_pretty_printer *pp, tree e)
1869 enum tree_code code = TREE_CODE (e);
1876 pp_c_relational_expression (pp, TREE_OPERAND (e, 0));
1877 pp_c_whitespace (pp);
1878 if (code == LT_EXPR)
1880 else if (code == GT_EXPR)
1882 else if (code == LE_EXPR)
1883 pp_string (pp, "<=");
1884 else if (code == GE_EXPR)
1885 pp_string (pp, ">=");
1886 pp_c_whitespace (pp);
1887 pp_c_shift_expression (pp, TREE_OPERAND (e, 1));
1891 pp_c_shift_expression (pp, e);
1896 /* equality-expression:
1897 relational-expression
1898 equality-expression == relational-expression
1899 equality-equality != relational-expression */
1902 pp_c_equality_expression (c_pretty_printer *pp, tree e)
1904 enum tree_code code = TREE_CODE (e);
1909 pp_c_equality_expression (pp, TREE_OPERAND (e, 0));
1910 pp_c_whitespace (pp);
1911 pp_string (pp, code == EQ_EXPR ? "==" : "!=");
1912 pp_c_whitespace (pp);
1913 pp_c_relational_expression (pp, TREE_OPERAND (e, 1));
1917 pp_c_relational_expression (pp, e);
1924 AND-expression & equality-equality */
1927 pp_c_and_expression (c_pretty_printer *pp, tree e)
1929 if (TREE_CODE (e) == BIT_AND_EXPR)
1931 pp_c_and_expression (pp, TREE_OPERAND (e, 0));
1932 pp_c_whitespace (pp);
1934 pp_c_whitespace (pp);
1935 pp_c_equality_expression (pp, TREE_OPERAND (e, 1));
1938 pp_c_equality_expression (pp, e);
1941 /* exclusive-OR-expression:
1943 exclusive-OR-expression ^ AND-expression */
1946 pp_c_exclusive_or_expression (c_pretty_printer *pp, tree e)
1948 if (TREE_CODE (e) == BIT_XOR_EXPR
1949 || TREE_CODE (e) == TRUTH_XOR_EXPR)
1951 pp_c_exclusive_or_expression (pp, TREE_OPERAND (e, 0));
1952 if (TREE_CODE (e) == BIT_XOR_EXPR)
1953 pp_c_maybe_whitespace (pp);
1955 pp_c_whitespace (pp);
1957 pp_c_whitespace (pp);
1958 pp_c_and_expression (pp, TREE_OPERAND (e, 1));
1961 pp_c_and_expression (pp, e);
1964 /* inclusive-OR-expression:
1965 exclusive-OR-expression
1966 inclusive-OR-expression | exclusive-OR-expression */
1969 pp_c_inclusive_or_expression (c_pretty_printer *pp, tree e)
1971 if (TREE_CODE (e) == BIT_IOR_EXPR)
1973 pp_c_exclusive_or_expression (pp, TREE_OPERAND (e, 0));
1974 pp_c_whitespace (pp);
1976 pp_c_whitespace (pp);
1977 pp_c_exclusive_or_expression (pp, TREE_OPERAND (e, 1));
1980 pp_c_exclusive_or_expression (pp, e);
1983 /* logical-AND-expression:
1984 inclusive-OR-expression
1985 logical-AND-expression && inclusive-OR-expression */
1988 pp_c_logical_and_expression (c_pretty_printer *pp, tree e)
1990 if (TREE_CODE (e) == TRUTH_ANDIF_EXPR
1991 || TREE_CODE (e) == TRUTH_AND_EXPR)
1993 pp_c_logical_and_expression (pp, TREE_OPERAND (e, 0));
1994 pp_c_whitespace (pp);
1995 pp_string (pp, "&&");
1996 pp_c_whitespace (pp);
1997 pp_c_inclusive_or_expression (pp, TREE_OPERAND (e, 1));
2000 pp_c_inclusive_or_expression (pp, e);
2003 /* logical-OR-expression:
2004 logical-AND-expression
2005 logical-OR-expression || logical-AND-expression */
2008 pp_c_logical_or_expression (c_pretty_printer *pp, tree e)
2010 if (TREE_CODE (e) == TRUTH_ORIF_EXPR
2011 || TREE_CODE (e) == TRUTH_OR_EXPR)
2013 pp_c_logical_or_expression (pp, TREE_OPERAND (e, 0));
2014 pp_c_whitespace (pp);
2015 pp_string (pp, "||");
2016 pp_c_whitespace (pp);
2017 pp_c_logical_and_expression (pp, TREE_OPERAND (e, 1));
2020 pp_c_logical_and_expression (pp, e);
2023 /* conditional-expression:
2024 logical-OR-expression
2025 logical-OR-expression ? expression : conditional-expression */
2028 pp_c_conditional_expression (c_pretty_printer *pp, tree e)
2030 if (TREE_CODE (e) == COND_EXPR)
2032 pp_c_logical_or_expression (pp, TREE_OPERAND (e, 0));
2033 pp_c_whitespace (pp);
2035 pp_c_whitespace (pp);
2036 pp_expression (pp, TREE_OPERAND (e, 1));
2037 pp_c_whitespace (pp);
2039 pp_c_whitespace (pp);
2040 pp_c_conditional_expression (pp, TREE_OPERAND (e, 2));
2043 pp_c_logical_or_expression (pp, e);
2047 /* assignment-expression:
2048 conditional-expression
2049 unary-expression assignment-operator assignment-expression
2051 assignment-expression: one of
2052 = *= /= %= += -= >>= <<= &= ^= |= */
2055 pp_c_assignment_expression (c_pretty_printer *pp, tree e)
2057 if (TREE_CODE (e) == MODIFY_EXPR
2058 || TREE_CODE (e) == INIT_EXPR)
2060 pp_c_unary_expression (pp, TREE_OPERAND (e, 0));
2061 pp_c_whitespace (pp);
2064 pp_c_expression (pp, TREE_OPERAND (e, 1));
2067 pp_c_conditional_expression (pp, e);
2071 assignment-expression
2072 expression , assignment-expression
2074 Implementation note: instead of going through the usual recursion
2075 chain, I take the liberty of dispatching nodes to the appropriate
2076 functions. This makes some redundancy, but it worths it. That also
2077 prevents a possible infinite recursion between pp_c_primary_expression ()
2078 and pp_c_expression (). */
2081 pp_c_expression (c_pretty_printer *pp, tree e)
2083 switch (TREE_CODE (e))
2086 pp_c_integer_constant (pp, e);
2090 pp_c_floating_constant (pp, e);
2094 pp_c_fixed_constant (pp, e);
2098 pp_c_string_literal (pp, e);
2101 case IDENTIFIER_NODE:
2110 pp_primary_expression (pp, e);
2113 case POSTINCREMENT_EXPR:
2114 case POSTDECREMENT_EXPR:
2123 case UNORDERED_EXPR:
2132 case COMPOUND_LITERAL_EXPR:
2134 pp_postfix_expression (pp, e);
2143 case TRUTH_NOT_EXPR:
2144 case PREINCREMENT_EXPR:
2145 case PREDECREMENT_EXPR:
2148 pp_c_unary_expression (pp, e);
2152 case FIX_TRUNC_EXPR:
2154 case VIEW_CONVERT_EXPR:
2155 pp_c_cast_expression (pp, e);
2159 case TRUNC_MOD_EXPR:
2160 case TRUNC_DIV_EXPR:
2161 pp_multiplicative_expression (pp, e);
2166 pp_c_shift_expression (pp, e);
2173 pp_c_relational_expression (pp, e);
2177 pp_c_and_expression (pp, e);
2181 case TRUTH_XOR_EXPR:
2182 pp_c_exclusive_or_expression (pp, e);
2186 pp_c_inclusive_or_expression (pp, e);
2189 case TRUTH_ANDIF_EXPR:
2190 case TRUTH_AND_EXPR:
2191 pp_c_logical_and_expression (pp, e);
2194 case TRUTH_ORIF_EXPR:
2196 pp_c_logical_or_expression (pp, e);
2201 pp_c_equality_expression (pp, e);
2205 pp_conditional_expression (pp, e);
2208 case POINTER_PLUS_EXPR:
2211 pp_c_additive_expression (pp, e);
2216 pp_assignment_expression (pp, e);
2220 pp_c_left_paren (pp);
2221 pp_expression (pp, TREE_OPERAND (e, 0));
2222 pp_separate_with (pp, ',');
2223 pp_assignment_expression (pp, TREE_OPERAND (e, 1));
2224 pp_c_right_paren (pp);
2227 case NON_LVALUE_EXPR:
2229 pp_expression (pp, TREE_OPERAND (e, 0));
2233 pp_postfix_expression (pp, TREE_OPERAND (e, 1));
2238 /* We don't yet have a way of dumping statements in a
2239 human-readable format. */
2240 pp_string (pp, "({...})");
2243 case C_MAYBE_CONST_EXPR:
2244 pp_c_expression (pp, C_MAYBE_CONST_EXPR_EXPR (e));
2248 pp_unsupported_tree (pp, e);
2258 pp_c_statement (c_pretty_printer *pp, tree stmt)
2263 if (pp_needs_newline (pp))
2264 pp_newline_and_indent (pp, 0);
2266 dump_generic_node (pp_base (pp), stmt, pp_indentation (pp), 0, true);
2270 /* Initialize the PRETTY-PRINTER for handling C codes. */
2273 pp_c_pretty_printer_init (c_pretty_printer *pp)
2275 pp->offset_list = 0;
2277 pp->declaration = pp_c_declaration;
2278 pp->declaration_specifiers = pp_c_declaration_specifiers;
2279 pp->declarator = pp_c_declarator;
2280 pp->direct_declarator = pp_c_direct_declarator;
2281 pp->type_specifier_seq = pp_c_specifier_qualifier_list;
2282 pp->abstract_declarator = pp_c_abstract_declarator;
2283 pp->direct_abstract_declarator = pp_c_direct_abstract_declarator;
2284 pp->ptr_operator = pp_c_pointer;
2285 pp->parameter_list = pp_c_parameter_type_list;
2286 pp->type_id = pp_c_type_id;
2287 pp->simple_type_specifier = pp_c_type_specifier;
2288 pp->function_specifier = pp_c_function_specifier;
2289 pp->storage_class_specifier = pp_c_storage_class_specifier;
2291 pp->statement = pp_c_statement;
2293 pp->constant = pp_c_constant;
2294 pp->id_expression = pp_c_id_expression;
2295 pp->primary_expression = pp_c_primary_expression;
2296 pp->postfix_expression = pp_c_postfix_expression;
2297 pp->unary_expression = pp_c_unary_expression;
2298 pp->initializer = pp_c_initializer;
2299 pp->multiplicative_expression = pp_c_multiplicative_expression;
2300 pp->conditional_expression = pp_c_conditional_expression;
2301 pp->assignment_expression = pp_c_assignment_expression;
2302 pp->expression = pp_c_expression;
2306 /* Print the tree T in full, on file FILE. */
2309 print_c_tree (FILE *file, tree t)
2311 static c_pretty_printer pp_rec;
2312 static bool initialized = 0;
2313 c_pretty_printer *pp = &pp_rec;
2318 pp_construct (pp_base (pp), NULL, 0);
2319 pp_c_pretty_printer_init (pp);
2320 pp_needs_newline (pp) = true;
2322 pp_base (pp)->buffer->stream = file;
2324 pp_statement (pp, t);
2330 /* Print the tree T in full, on stderr. */
2333 debug_c_tree (tree t)
2335 print_c_tree (stderr, t);
2336 fputc ('\n', stderr);
2339 /* Output the DECL_NAME of T. If T has no DECL_NAME, output a string made
2340 up of T's memory address. */
2343 pp_c_tree_decl_identifier (c_pretty_printer *pp, tree t)
2347 gcc_assert (DECL_P (t));
2350 name = IDENTIFIER_POINTER (DECL_NAME (t));
2353 static char xname[8];
2354 sprintf (xname, "<U%4x>", ((unsigned)((uintptr_t)(t) & 0xffff)));
2358 pp_c_identifier (pp, name);