1 /* Subroutines common to both C and C++ pretty-printers.
2 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
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 && !c_dialect_cxx ()
209 ? "restrict" : "__restrict__"));
213 /* Pretty-print T using the type-cast notation '( type-name )'. */
216 pp_c_type_cast (c_pretty_printer *pp, tree t)
218 pp_c_left_paren (pp);
220 pp_c_right_paren (pp);
223 /* We're about to pretty-print a pointer type as indicated by T.
224 Output a whitespace, if needed, preparing for subsequent output. */
227 pp_c_space_for_pointer_operator (c_pretty_printer *pp, tree t)
229 if (POINTER_TYPE_P (t))
231 tree pointee = strip_pointer_operator (TREE_TYPE (t));
232 if (TREE_CODE (pointee) != ARRAY_TYPE
233 && TREE_CODE (pointee) != FUNCTION_TYPE)
234 pp_c_whitespace (pp);
241 /* C++ cv-qualifiers are called type-qualifiers in C. Print out the
242 cv-qualifiers of T. If T is a declaration then it is the cv-qualifier
243 of its type. Take care of possible extensions.
247 type-qualifier-list type-qualifier
252 __restrict__ -- GNU C
253 address-space-qualifier -- GNU C
256 address-space-qualifier:
257 identifier -- GNU C */
260 pp_c_type_qualifier_list (c_pretty_printer *pp, tree t)
264 if (!t || t == error_mark_node)
270 qualifiers = TYPE_QUALS (t);
271 pp_c_cv_qualifiers (pp, qualifiers,
272 TREE_CODE (t) == FUNCTION_TYPE);
274 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (t)))
276 const char *as = c_addr_space_name (TYPE_ADDR_SPACE (t));
277 pp_c_identifier (pp, as);
282 * type-qualifier-list(opt)
283 * type-qualifier-list(opt) pointer */
286 pp_c_pointer (c_pretty_printer *pp, tree t)
288 if (!TYPE_P (t) && TREE_CODE (t) != TYPE_DECL)
290 switch (TREE_CODE (t))
293 /* It is easier to handle C++ reference types here. */
295 if (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE)
296 pp_c_pointer (pp, TREE_TYPE (t));
297 if (TREE_CODE (t) == POINTER_TYPE)
301 pp_c_type_qualifier_list (pp, t);
304 /* ??? This node is now in GENERIC and so shouldn't be here. But
305 we'll fix that later. */
307 pp_declaration (pp, DECL_EXPR_DECL (t));
308 pp_needs_newline (pp) = true;
312 pp_unsupported_tree (pp, t);
329 struct-or-union-specifier
334 simple-type-specifier:
339 pp_c_type_specifier (c_pretty_printer *pp, tree t)
341 const enum tree_code code = TREE_CODE (t);
345 pp_c_ws_string (pp, M_("<type-error>"));
348 case IDENTIFIER_NODE:
349 pp_c_identifier (pp, IDENTIFIER_POINTER (t));
356 case FIXED_POINT_TYPE:
360 pp_c_type_specifier (pp, t);
364 int prec = TYPE_PRECISION (t);
365 if (ALL_FIXED_POINT_MODE_P (TYPE_MODE (t)))
366 t = c_common_type_for_mode (TYPE_MODE (t), TYPE_SATURATING (t));
368 t = c_common_type_for_mode (TYPE_MODE (t), TYPE_UNSIGNED (t));
371 pp_c_type_specifier (pp, t);
372 if (TYPE_PRECISION (t) != prec)
375 pp_decimal_int (pp, prec);
383 pp_string (pp, (TYPE_UNSIGNED (t)
384 ? M_("<unnamed-unsigned:")
385 : M_("<unnamed-signed:")));
388 pp_string (pp, M_("<unnamed-float:"));
390 case FIXED_POINT_TYPE:
391 pp_string (pp, M_("<unnamed-fixed:"));
396 pp_decimal_int (pp, prec);
404 pp_id_expression (pp, t);
406 pp_c_ws_string (pp, M_("<typedef-error>"));
412 if (code == UNION_TYPE)
413 pp_c_ws_string (pp, "union");
414 else if (code == RECORD_TYPE)
415 pp_c_ws_string (pp, "struct");
416 else if (code == ENUMERAL_TYPE)
417 pp_c_ws_string (pp, "enum");
419 pp_c_ws_string (pp, M_("<tag-error>"));
422 pp_id_expression (pp, TYPE_NAME (t));
424 pp_c_ws_string (pp, M_("<anonymous>"));
428 pp_unsupported_tree (pp, t);
433 /* specifier-qualifier-list:
434 type-specifier specifier-qualifier-list-opt
435 type-qualifier specifier-qualifier-list-opt
438 Implementation note: Because of the non-linearities in array or
439 function declarations, this routine prints not just the
440 specifier-qualifier-list of such entities or types of such entities,
441 but also the 'pointer' production part of their declarators. The
442 remaining part is done by pp_declarator or pp_c_abstract_declarator. */
445 pp_c_specifier_qualifier_list (c_pretty_printer *pp, tree t)
447 const enum tree_code code = TREE_CODE (t);
449 if (TREE_CODE (t) != POINTER_TYPE)
450 pp_c_type_qualifier_list (pp, t);
456 /* Get the types-specifier of this type. */
457 tree pointee = strip_pointer_operator (TREE_TYPE (t));
458 pp_c_specifier_qualifier_list (pp, pointee);
459 if (TREE_CODE (pointee) == ARRAY_TYPE
460 || TREE_CODE (pointee) == FUNCTION_TYPE)
462 pp_c_whitespace (pp);
463 pp_c_left_paren (pp);
464 pp_c_attributes_display (pp, TYPE_ATTRIBUTES (pointee));
466 else if (!c_dialect_cxx ())
467 pp_c_whitespace (pp);
468 pp_ptr_operator (pp, t);
474 pp_c_specifier_qualifier_list (pp, TREE_TYPE (t));
479 if (code == COMPLEX_TYPE)
480 pp_c_ws_string (pp, (flag_isoc99 && !c_dialect_cxx ()
481 ? "_Complex" : "__complex__"));
482 else if (code == VECTOR_TYPE)
484 pp_c_ws_string (pp, "__vector");
485 pp_c_left_paren (pp);
486 pp_wide_integer (pp, TYPE_VECTOR_SUBPARTS (t));
487 pp_c_right_paren (pp);
488 pp_c_whitespace (pp);
490 pp_c_specifier_qualifier_list (pp, TREE_TYPE (t));
494 pp_simple_type_specifier (pp, t);
499 /* parameter-type-list:
504 parameter-declaration
505 parameter-list , parameter-declaration
507 parameter-declaration:
508 declaration-specifiers declarator
509 declaration-specifiers abstract-declarator(opt) */
512 pp_c_parameter_type_list (c_pretty_printer *pp, tree t)
514 bool want_parm_decl = DECL_P (t) && !(pp->flags & pp_c_flag_abstract);
515 tree parms = want_parm_decl ? DECL_ARGUMENTS (t) : TYPE_ARG_TYPES (t);
516 pp_c_left_paren (pp);
517 if (parms == void_list_node)
518 pp_c_ws_string (pp, "void");
522 for ( ; parms && parms != void_list_node; parms = TREE_CHAIN (parms))
525 pp_separate_with (pp, ',');
527 pp_declaration_specifiers
528 (pp, want_parm_decl ? parms : TREE_VALUE (parms));
530 pp_declarator (pp, parms);
532 pp_abstract_declarator (pp, TREE_VALUE (parms));
535 pp_c_right_paren (pp);
538 /* abstract-declarator:
540 pointer(opt) direct-abstract-declarator */
543 pp_c_abstract_declarator (c_pretty_printer *pp, tree t)
545 if (TREE_CODE (t) == POINTER_TYPE)
547 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE
548 || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
549 pp_c_right_paren (pp);
553 pp_direct_abstract_declarator (pp, t);
556 /* direct-abstract-declarator:
557 ( abstract-declarator )
558 direct-abstract-declarator(opt) [ assignment-expression(opt) ]
559 direct-abstract-declarator(opt) [ * ]
560 direct-abstract-declarator(opt) ( parameter-type-list(opt) ) */
563 pp_c_direct_abstract_declarator (c_pretty_printer *pp, tree t)
565 switch (TREE_CODE (t))
568 pp_abstract_declarator (pp, t);
572 pp_c_parameter_type_list (pp, t);
573 pp_direct_abstract_declarator (pp, TREE_TYPE (t));
577 pp_c_left_bracket (pp);
578 if (TYPE_DOMAIN (t) && TYPE_MAX_VALUE (TYPE_DOMAIN (t)))
580 tree maxval = TYPE_MAX_VALUE (TYPE_DOMAIN (t));
581 tree type = TREE_TYPE (maxval);
583 if (host_integerp (maxval, 0))
584 pp_wide_integer (pp, tree_low_cst (maxval, 0) + 1);
586 pp_expression (pp, fold_build2 (PLUS_EXPR, type, maxval,
587 build_int_cst (type, 1)));
589 pp_c_right_bracket (pp);
590 pp_direct_abstract_declarator (pp, TREE_TYPE (t));
593 case IDENTIFIER_NODE:
598 case FIXED_POINT_TYPE:
608 pp_unsupported_tree (pp, t);
614 specifier-qualifier-list abstract-declarator(opt) */
617 pp_c_type_id (c_pretty_printer *pp, tree t)
619 pp_c_specifier_qualifier_list (pp, t);
620 pp_abstract_declarator (pp, t);
623 /* storage-class-specifier:
631 pp_c_storage_class_specifier (c_pretty_printer *pp, tree t)
633 if (TREE_CODE (t) == TYPE_DECL)
634 pp_c_ws_string (pp, "typedef");
637 if (DECL_REGISTER (t))
638 pp_c_ws_string (pp, "register");
639 else if (TREE_STATIC (t) && TREE_CODE (t) == VAR_DECL)
640 pp_c_ws_string (pp, "static");
644 /* function-specifier:
648 pp_c_function_specifier (c_pretty_printer *pp, tree t)
650 if (TREE_CODE (t) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (t))
651 pp_c_ws_string (pp, "inline");
654 /* declaration-specifiers:
655 storage-class-specifier declaration-specifiers(opt)
656 type-specifier declaration-specifiers(opt)
657 type-qualifier declaration-specifiers(opt)
658 function-specifier declaration-specifiers(opt) */
661 pp_c_declaration_specifiers (c_pretty_printer *pp, tree t)
663 pp_storage_class_specifier (pp, t);
664 pp_function_specifier (pp, t);
665 pp_c_specifier_qualifier_list (pp, DECL_P (t) ? TREE_TYPE (t) : t);
671 direct-declarator [ type-qualifier-list(opt) assignment-expression(opt) ]
672 direct-declarator [ static type-qualifier-list(opt) assignment-expression(opt)]
673 direct-declarator [ type-qualifier-list static assignment-expression ]
674 direct-declarator [ type-qualifier-list * ]
675 direct-declarator ( parameter-type-list )
676 direct-declarator ( identifier-list(opt) ) */
679 pp_c_direct_declarator (c_pretty_printer *pp, tree t)
681 switch (TREE_CODE (t))
688 pp_c_space_for_pointer_operator (pp, TREE_TYPE (t));
689 pp_c_tree_decl_identifier (pp, t);
694 pp_abstract_declarator (pp, TREE_TYPE (t));
698 pp_parameter_list (pp, t);
699 pp_abstract_declarator (pp, TREE_TYPE (t));
703 pp_c_space_for_pointer_operator (pp, TREE_TYPE (TREE_TYPE (t)));
704 pp_c_tree_decl_identifier (pp, t);
705 if (pp_c_base (pp)->flags & pp_c_flag_abstract)
706 pp_abstract_declarator (pp, TREE_TYPE (t));
709 pp_parameter_list (pp, t);
710 pp_abstract_declarator (pp, TREE_TYPE (TREE_TYPE (t)));
716 case FIXED_POINT_TYPE:
723 pp_unsupported_tree (pp, t);
730 pointer(opt) direct-declarator */
733 pp_c_declarator (c_pretty_printer *pp, tree t)
735 switch (TREE_CODE (t))
739 case FIXED_POINT_TYPE:
752 pp_direct_declarator (pp, t);
757 pp_unsupported_tree (pp, t);
763 declaration-specifiers init-declarator-list(opt) ; */
766 pp_c_declaration (c_pretty_printer *pp, tree t)
768 pp_declaration_specifiers (pp, t);
769 pp_c_init_declarator (pp, t);
772 /* Pretty-print ATTRIBUTES using GNU C extension syntax. */
775 pp_c_attributes (c_pretty_printer *pp, tree attributes)
777 if (attributes == NULL_TREE)
780 pp_c_ws_string (pp, "__attribute__");
781 pp_c_left_paren (pp);
782 pp_c_left_paren (pp);
783 for (; attributes != NULL_TREE; attributes = TREE_CHAIN (attributes))
785 pp_tree_identifier (pp, TREE_PURPOSE (attributes));
786 if (TREE_VALUE (attributes))
787 pp_c_call_argument_list (pp, TREE_VALUE (attributes));
789 if (TREE_CHAIN (attributes))
790 pp_separate_with (pp, ',');
792 pp_c_right_paren (pp);
793 pp_c_right_paren (pp);
796 /* Pretty-print ATTRIBUTES using GNU C extension syntax for attributes
797 marked to be displayed on disgnostic. */
800 pp_c_attributes_display (c_pretty_printer *pp, tree a)
802 bool is_first = true;
807 for (; a != NULL_TREE; a = TREE_CHAIN (a))
809 const struct attribute_spec *as;
810 as = lookup_attribute_spec (TREE_PURPOSE (a));
811 if (!as || as->affects_type_identity == false)
815 pp_c_ws_string (pp, "__attribute__");
816 pp_c_left_paren (pp);
817 pp_c_left_paren (pp);
822 pp_separate_with (pp, ',');
824 pp_tree_identifier (pp, TREE_PURPOSE (a));
826 pp_c_call_argument_list (pp, TREE_VALUE (a));
831 pp_c_right_paren (pp);
832 pp_c_right_paren (pp);
833 pp_c_whitespace (pp);
837 /* function-definition:
838 declaration-specifiers declarator compound-statement */
841 pp_c_function_definition (c_pretty_printer *pp, tree t)
843 pp_declaration_specifiers (pp, t);
844 pp_declarator (pp, t);
845 pp_needs_newline (pp) = true;
846 pp_statement (pp, DECL_SAVED_TREE (t));
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)
923 pp_character (pp, '-');
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_base (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_base (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)
1375 pp_c_expression_list (pp, TREE_VECTOR_CST_ELTS (e));
1381 if (TREE_CODE (e) == COMPLEX_CST || TREE_CODE (e) == COMPLEX_EXPR)
1383 const bool cst = TREE_CODE (e) == COMPLEX_CST;
1384 pp_expression (pp, cst ? TREE_REALPART (e) : TREE_OPERAND (e, 0));
1385 pp_separate_with (pp, ',');
1386 pp_expression (pp, cst ? TREE_IMAGPART (e) : TREE_OPERAND (e, 1));
1396 pp_unsupported_tree (pp, type);
1399 /* Pretty-print a brace-enclosed initializer-list. */
1402 pp_c_brace_enclosed_initializer_list (c_pretty_printer *pp, tree l)
1404 pp_c_left_brace (pp);
1405 pp_c_initializer_list (pp, l);
1406 pp_c_right_brace (pp);
1410 /* This is a convenient function, used to bridge gap between C and C++
1417 pp_c_id_expression (c_pretty_printer *pp, tree t)
1419 switch (TREE_CODE (t))
1428 pp_c_tree_decl_identifier (pp, t);
1431 case IDENTIFIER_NODE:
1432 pp_c_tree_identifier (pp, t);
1436 pp_unsupported_tree (pp, t);
1441 /* postfix-expression:
1443 postfix-expression [ expression ]
1444 postfix-expression ( argument-expression-list(opt) )
1445 postfix-expression . identifier
1446 postfix-expression -> identifier
1447 postfix-expression ++
1448 postfix-expression --
1449 ( type-name ) { initializer-list }
1450 ( type-name ) { initializer-list , } */
1453 pp_c_postfix_expression (c_pretty_printer *pp, tree e)
1455 enum tree_code code = TREE_CODE (e);
1458 case POSTINCREMENT_EXPR:
1459 case POSTDECREMENT_EXPR:
1460 pp_postfix_expression (pp, TREE_OPERAND (e, 0));
1461 pp_string (pp, code == POSTINCREMENT_EXPR ? "++" : "--");
1465 pp_postfix_expression (pp, TREE_OPERAND (e, 0));
1466 pp_c_left_bracket (pp);
1467 pp_expression (pp, TREE_OPERAND (e, 1));
1468 pp_c_right_bracket (pp);
1473 call_expr_arg_iterator iter;
1475 pp_postfix_expression (pp, CALL_EXPR_FN (e));
1476 pp_c_left_paren (pp);
1477 FOR_EACH_CALL_EXPR_ARG (arg, iter, e)
1479 pp_expression (pp, arg);
1480 if (more_call_expr_args_p (&iter))
1481 pp_separate_with (pp, ',');
1483 pp_c_right_paren (pp);
1487 case UNORDERED_EXPR:
1488 pp_c_ws_string (pp, flag_isoc99
1490 : "__builtin_isunordered");
1494 pp_c_ws_string (pp, flag_isoc99
1496 : "!__builtin_isunordered");
1500 pp_c_ws_string (pp, flag_isoc99
1502 : "!__builtin_isgreaterequal");
1506 pp_c_ws_string (pp, flag_isoc99
1508 : "!__builtin_isgreater");
1512 pp_c_ws_string (pp, flag_isoc99
1514 : "!__builtin_islessequal");
1518 pp_c_ws_string (pp, flag_isoc99
1520 : "!__builtin_isless");
1524 pp_c_ws_string (pp, flag_isoc99
1526 : "!__builtin_islessgreater");
1530 pp_c_ws_string (pp, flag_isoc99
1532 : "__builtin_islessgreater");
1536 pp_c_left_paren (pp);
1537 pp_expression (pp, TREE_OPERAND (e, 0));
1538 pp_separate_with (pp, ',');
1539 pp_expression (pp, TREE_OPERAND (e, 1));
1540 pp_c_right_paren (pp);
1544 pp_c_ws_string (pp, "__builtin_abs");
1545 pp_c_left_paren (pp);
1546 pp_expression (pp, TREE_OPERAND (e, 0));
1547 pp_c_right_paren (pp);
1552 tree object = TREE_OPERAND (e, 0);
1553 if (TREE_CODE (object) == INDIRECT_REF)
1555 pp_postfix_expression (pp, TREE_OPERAND (object, 0));
1560 pp_postfix_expression (pp, object);
1563 pp_expression (pp, TREE_OPERAND (e, 1));
1569 tree type = TREE_TYPE (e);
1571 type = signed_or_unsigned_type_for (TYPE_UNSIGNED (type), type);
1573 && tree_int_cst_equal (TYPE_SIZE (type), TREE_OPERAND (e, 1)))
1575 HOST_WIDE_INT bitpos = tree_low_cst (TREE_OPERAND (e, 2), 0);
1576 HOST_WIDE_INT size = tree_low_cst (TYPE_SIZE (type), 0);
1577 if ((bitpos % size) == 0)
1579 pp_c_left_paren (pp);
1580 pp_c_left_paren (pp);
1581 pp_type_id (pp, type);
1583 pp_c_right_paren (pp);
1584 pp_c_ampersand (pp);
1585 pp_expression (pp, TREE_OPERAND (e, 0));
1586 pp_c_right_paren (pp);
1587 pp_c_left_bracket (pp);
1588 pp_wide_integer (pp, bitpos / size);
1589 pp_c_right_bracket (pp);
1593 pp_unsupported_tree (pp, e);
1598 pp_c_expression (pp, e);
1603 pp_c_compound_literal (pp, e);
1607 pp_c_complex_expr (pp, e);
1610 case COMPOUND_LITERAL_EXPR:
1611 e = DECL_INITIAL (COMPOUND_LITERAL_EXPR_DECL (e));
1614 pp_initializer (pp, e);
1618 pp_c_ws_string (pp, "__builtin_va_arg");
1619 pp_c_left_paren (pp);
1620 pp_assignment_expression (pp, TREE_OPERAND (e, 0));
1621 pp_separate_with (pp, ',');
1622 pp_type_id (pp, TREE_TYPE (e));
1623 pp_c_right_paren (pp);
1627 if (TREE_CODE (TREE_OPERAND (e, 0)) == FUNCTION_DECL)
1629 pp_c_id_expression (pp, TREE_OPERAND (e, 0));
1632 /* else fall through. */
1635 pp_primary_expression (pp, e);
1640 /* Print out an expression-list; E is expected to be a TREE_LIST. */
1643 pp_c_expression_list (c_pretty_printer *pp, tree e)
1645 for (; e != NULL_TREE; e = TREE_CHAIN (e))
1647 pp_expression (pp, TREE_VALUE (e));
1649 pp_separate_with (pp, ',');
1653 /* Print out V, which contains the elements of a constructor. */
1656 pp_c_constructor_elts (c_pretty_printer *pp, VEC(constructor_elt,gc) *v)
1658 unsigned HOST_WIDE_INT ix;
1661 FOR_EACH_CONSTRUCTOR_VALUE (v, ix, value)
1663 pp_expression (pp, value);
1664 if (ix != VEC_length (constructor_elt, v) - 1)
1665 pp_separate_with (pp, ',');
1669 /* Print out an expression-list in parens, as if it were the argument
1670 list to a function. */
1673 pp_c_call_argument_list (c_pretty_printer *pp, tree t)
1675 pp_c_left_paren (pp);
1676 if (t && TREE_CODE (t) == TREE_LIST)
1677 pp_c_expression_list (pp, t);
1678 pp_c_right_paren (pp);
1681 /* unary-expression:
1685 unary-operator cast-expression
1686 sizeof unary-expression
1689 unary-operator: one of
1694 __alignof__ unary-expression
1695 __alignof__ ( type-id )
1696 __real__ unary-expression
1697 __imag__ unary-expression */
1700 pp_c_unary_expression (c_pretty_printer *pp, tree e)
1702 enum tree_code code = TREE_CODE (e);
1705 case PREINCREMENT_EXPR:
1706 case PREDECREMENT_EXPR:
1707 pp_string (pp, code == PREINCREMENT_EXPR ? "++" : "--");
1708 pp_c_unary_expression (pp, TREE_OPERAND (e, 0));
1715 case TRUTH_NOT_EXPR:
1717 /* String literal are used by address. */
1718 if (code == ADDR_EXPR && TREE_CODE (TREE_OPERAND (e, 0)) != STRING_CST)
1720 else if (code == INDIRECT_REF)
1722 else if (code == NEGATE_EXPR)
1724 else if (code == BIT_NOT_EXPR || code == CONJ_EXPR)
1726 else if (code == TRUTH_NOT_EXPR)
1727 pp_exclamation (pp);
1728 pp_c_cast_expression (pp, TREE_OPERAND (e, 0));
1732 if (TREE_CODE (TREE_OPERAND (e, 0)) == ADDR_EXPR
1733 && integer_zerop (TREE_OPERAND (e, 1)))
1734 pp_c_expression (pp, TREE_OPERAND (TREE_OPERAND (e, 0), 0));
1738 if (!integer_zerop (TREE_OPERAND (e, 1)))
1740 pp_c_left_paren (pp);
1741 if (!integer_onep (TYPE_SIZE_UNIT
1742 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (e, 0))))))
1743 pp_c_type_cast (pp, ptr_type_node);
1745 pp_c_cast_expression (pp, TREE_OPERAND (e, 0));
1746 if (!integer_zerop (TREE_OPERAND (e, 1)))
1749 pp_c_integer_constant (pp,
1750 fold_convert (ssizetype,
1751 TREE_OPERAND (e, 1)));
1752 pp_c_right_paren (pp);
1759 pp_c_ws_string (pp, code == REALPART_EXPR ? "__real__" : "__imag__");
1760 pp_c_whitespace (pp);
1761 pp_unary_expression (pp, TREE_OPERAND (e, 0));
1765 pp_postfix_expression (pp, e);
1772 ( type-name ) cast-expression */
1775 pp_c_cast_expression (c_pretty_printer *pp, tree e)
1777 switch (TREE_CODE (e))
1780 case FIX_TRUNC_EXPR:
1782 case VIEW_CONVERT_EXPR:
1783 pp_c_type_cast (pp, TREE_TYPE (e));
1784 pp_c_cast_expression (pp, TREE_OPERAND (e, 0));
1788 pp_unary_expression (pp, e);
1792 /* multiplicative-expression:
1794 multiplicative-expression * cast-expression
1795 multiplicative-expression / cast-expression
1796 multiplicative-expression % cast-expression */
1799 pp_c_multiplicative_expression (c_pretty_printer *pp, tree e)
1801 enum tree_code code = TREE_CODE (e);
1805 case TRUNC_DIV_EXPR:
1806 case TRUNC_MOD_EXPR:
1807 pp_multiplicative_expression (pp, TREE_OPERAND (e, 0));
1808 pp_c_whitespace (pp);
1809 if (code == MULT_EXPR)
1811 else if (code == TRUNC_DIV_EXPR)
1815 pp_c_whitespace (pp);
1816 pp_c_cast_expression (pp, TREE_OPERAND (e, 1));
1820 pp_c_cast_expression (pp, e);
1825 /* additive-expression:
1826 multiplicative-expression
1827 additive-expression + multiplicative-expression
1828 additive-expression - multiplicative-expression */
1831 pp_c_additive_expression (c_pretty_printer *pp, tree e)
1833 enum tree_code code = TREE_CODE (e);
1836 case POINTER_PLUS_EXPR:
1839 pp_c_additive_expression (pp, TREE_OPERAND (e, 0));
1840 pp_c_whitespace (pp);
1841 if (code == PLUS_EXPR || code == POINTER_PLUS_EXPR)
1845 pp_c_whitespace (pp);
1846 pp_multiplicative_expression (pp, TREE_OPERAND (e, 1));
1850 pp_multiplicative_expression (pp, e);
1855 /* additive-expression:
1857 shift-expression << additive-expression
1858 shift-expression >> additive-expression */
1861 pp_c_shift_expression (c_pretty_printer *pp, tree e)
1863 enum tree_code code = TREE_CODE (e);
1868 pp_c_shift_expression (pp, TREE_OPERAND (e, 0));
1869 pp_c_whitespace (pp);
1870 pp_string (pp, code == LSHIFT_EXPR ? "<<" : ">>");
1871 pp_c_whitespace (pp);
1872 pp_c_additive_expression (pp, TREE_OPERAND (e, 1));
1876 pp_c_additive_expression (pp, e);
1880 /* relational-expression:
1882 relational-expression < shift-expression
1883 relational-expression > shift-expression
1884 relational-expression <= shift-expression
1885 relational-expression >= shift-expression */
1888 pp_c_relational_expression (c_pretty_printer *pp, tree e)
1890 enum tree_code code = TREE_CODE (e);
1897 pp_c_relational_expression (pp, TREE_OPERAND (e, 0));
1898 pp_c_whitespace (pp);
1899 if (code == LT_EXPR)
1901 else if (code == GT_EXPR)
1903 else if (code == LE_EXPR)
1904 pp_string (pp, "<=");
1905 else if (code == GE_EXPR)
1906 pp_string (pp, ">=");
1907 pp_c_whitespace (pp);
1908 pp_c_shift_expression (pp, TREE_OPERAND (e, 1));
1912 pp_c_shift_expression (pp, e);
1917 /* equality-expression:
1918 relational-expression
1919 equality-expression == relational-expression
1920 equality-equality != relational-expression */
1923 pp_c_equality_expression (c_pretty_printer *pp, tree e)
1925 enum tree_code code = TREE_CODE (e);
1930 pp_c_equality_expression (pp, TREE_OPERAND (e, 0));
1931 pp_c_whitespace (pp);
1932 pp_string (pp, code == EQ_EXPR ? "==" : "!=");
1933 pp_c_whitespace (pp);
1934 pp_c_relational_expression (pp, TREE_OPERAND (e, 1));
1938 pp_c_relational_expression (pp, e);
1945 AND-expression & equality-equality */
1948 pp_c_and_expression (c_pretty_printer *pp, tree e)
1950 if (TREE_CODE (e) == BIT_AND_EXPR)
1952 pp_c_and_expression (pp, TREE_OPERAND (e, 0));
1953 pp_c_whitespace (pp);
1955 pp_c_whitespace (pp);
1956 pp_c_equality_expression (pp, TREE_OPERAND (e, 1));
1959 pp_c_equality_expression (pp, e);
1962 /* exclusive-OR-expression:
1964 exclusive-OR-expression ^ AND-expression */
1967 pp_c_exclusive_or_expression (c_pretty_printer *pp, tree e)
1969 if (TREE_CODE (e) == BIT_XOR_EXPR
1970 || TREE_CODE (e) == TRUTH_XOR_EXPR)
1972 pp_c_exclusive_or_expression (pp, TREE_OPERAND (e, 0));
1973 if (TREE_CODE (e) == BIT_XOR_EXPR)
1974 pp_c_maybe_whitespace (pp);
1976 pp_c_whitespace (pp);
1978 pp_c_whitespace (pp);
1979 pp_c_and_expression (pp, TREE_OPERAND (e, 1));
1982 pp_c_and_expression (pp, e);
1985 /* inclusive-OR-expression:
1986 exclusive-OR-expression
1987 inclusive-OR-expression | exclusive-OR-expression */
1990 pp_c_inclusive_or_expression (c_pretty_printer *pp, tree e)
1992 if (TREE_CODE (e) == BIT_IOR_EXPR)
1994 pp_c_exclusive_or_expression (pp, TREE_OPERAND (e, 0));
1995 pp_c_whitespace (pp);
1997 pp_c_whitespace (pp);
1998 pp_c_exclusive_or_expression (pp, TREE_OPERAND (e, 1));
2001 pp_c_exclusive_or_expression (pp, e);
2004 /* logical-AND-expression:
2005 inclusive-OR-expression
2006 logical-AND-expression && inclusive-OR-expression */
2009 pp_c_logical_and_expression (c_pretty_printer *pp, tree e)
2011 if (TREE_CODE (e) == TRUTH_ANDIF_EXPR
2012 || TREE_CODE (e) == TRUTH_AND_EXPR)
2014 pp_c_logical_and_expression (pp, TREE_OPERAND (e, 0));
2015 pp_c_whitespace (pp);
2016 pp_string (pp, "&&");
2017 pp_c_whitespace (pp);
2018 pp_c_inclusive_or_expression (pp, TREE_OPERAND (e, 1));
2021 pp_c_inclusive_or_expression (pp, e);
2024 /* logical-OR-expression:
2025 logical-AND-expression
2026 logical-OR-expression || logical-AND-expression */
2029 pp_c_logical_or_expression (c_pretty_printer *pp, tree e)
2031 if (TREE_CODE (e) == TRUTH_ORIF_EXPR
2032 || TREE_CODE (e) == TRUTH_OR_EXPR)
2034 pp_c_logical_or_expression (pp, TREE_OPERAND (e, 0));
2035 pp_c_whitespace (pp);
2036 pp_string (pp, "||");
2037 pp_c_whitespace (pp);
2038 pp_c_logical_and_expression (pp, TREE_OPERAND (e, 1));
2041 pp_c_logical_and_expression (pp, e);
2044 /* conditional-expression:
2045 logical-OR-expression
2046 logical-OR-expression ? expression : conditional-expression */
2049 pp_c_conditional_expression (c_pretty_printer *pp, tree e)
2051 if (TREE_CODE (e) == COND_EXPR)
2053 pp_c_logical_or_expression (pp, TREE_OPERAND (e, 0));
2054 pp_c_whitespace (pp);
2056 pp_c_whitespace (pp);
2057 pp_expression (pp, TREE_OPERAND (e, 1));
2058 pp_c_whitespace (pp);
2060 pp_c_whitespace (pp);
2061 pp_c_conditional_expression (pp, TREE_OPERAND (e, 2));
2064 pp_c_logical_or_expression (pp, e);
2068 /* assignment-expression:
2069 conditional-expression
2070 unary-expression assignment-operator assignment-expression
2072 assignment-expression: one of
2073 = *= /= %= += -= >>= <<= &= ^= |= */
2076 pp_c_assignment_expression (c_pretty_printer *pp, tree e)
2078 if (TREE_CODE (e) == MODIFY_EXPR
2079 || TREE_CODE (e) == INIT_EXPR)
2081 pp_c_unary_expression (pp, TREE_OPERAND (e, 0));
2082 pp_c_whitespace (pp);
2085 pp_c_expression (pp, TREE_OPERAND (e, 1));
2088 pp_c_conditional_expression (pp, e);
2092 assignment-expression
2093 expression , assignment-expression
2095 Implementation note: instead of going through the usual recursion
2096 chain, I take the liberty of dispatching nodes to the appropriate
2097 functions. This makes some redundancy, but it worths it. That also
2098 prevents a possible infinite recursion between pp_c_primary_expression ()
2099 and pp_c_expression (). */
2102 pp_c_expression (c_pretty_printer *pp, tree e)
2104 switch (TREE_CODE (e))
2107 pp_c_integer_constant (pp, e);
2111 pp_c_floating_constant (pp, e);
2115 pp_c_fixed_constant (pp, e);
2119 pp_c_string_literal (pp, e);
2122 case IDENTIFIER_NODE:
2131 pp_primary_expression (pp, e);
2135 if (!DECL_ARTIFICIAL (SSA_NAME_VAR (e)))
2136 pp_c_expression (pp, SSA_NAME_VAR (e));
2138 pp_c_ws_string (pp, M_("<unknown>"));
2141 case POSTINCREMENT_EXPR:
2142 case POSTDECREMENT_EXPR:
2151 case UNORDERED_EXPR:
2160 case COMPOUND_LITERAL_EXPR:
2162 pp_postfix_expression (pp, e);
2171 case TRUTH_NOT_EXPR:
2172 case PREINCREMENT_EXPR:
2173 case PREDECREMENT_EXPR:
2176 pp_c_unary_expression (pp, e);
2180 case FIX_TRUNC_EXPR:
2182 case VIEW_CONVERT_EXPR:
2183 pp_c_cast_expression (pp, e);
2187 case TRUNC_MOD_EXPR:
2188 case TRUNC_DIV_EXPR:
2189 pp_multiplicative_expression (pp, e);
2194 pp_c_shift_expression (pp, e);
2201 pp_c_relational_expression (pp, e);
2205 pp_c_and_expression (pp, e);
2209 case TRUTH_XOR_EXPR:
2210 pp_c_exclusive_or_expression (pp, e);
2214 pp_c_inclusive_or_expression (pp, e);
2217 case TRUTH_ANDIF_EXPR:
2218 case TRUTH_AND_EXPR:
2219 pp_c_logical_and_expression (pp, e);
2222 case TRUTH_ORIF_EXPR:
2224 pp_c_logical_or_expression (pp, e);
2229 pp_c_equality_expression (pp, e);
2233 pp_conditional_expression (pp, e);
2236 case POINTER_PLUS_EXPR:
2239 pp_c_additive_expression (pp, e);
2244 pp_assignment_expression (pp, e);
2248 pp_c_left_paren (pp);
2249 pp_expression (pp, TREE_OPERAND (e, 0));
2250 pp_separate_with (pp, ',');
2251 pp_assignment_expression (pp, TREE_OPERAND (e, 1));
2252 pp_c_right_paren (pp);
2255 case NON_LVALUE_EXPR:
2257 pp_expression (pp, TREE_OPERAND (e, 0));
2261 pp_postfix_expression (pp, TREE_OPERAND (e, 1));
2266 /* We don't yet have a way of dumping statements in a
2267 human-readable format. */
2268 pp_string (pp, "({...})");
2271 case C_MAYBE_CONST_EXPR:
2272 pp_c_expression (pp, C_MAYBE_CONST_EXPR_EXPR (e));
2276 pp_unsupported_tree (pp, e);
2286 pp_c_statement (c_pretty_printer *pp, tree stmt)
2291 if (pp_needs_newline (pp))
2292 pp_newline_and_indent (pp, 0);
2294 dump_generic_node (pp_base (pp), stmt, pp_indentation (pp), 0, true);
2298 /* Initialize the PRETTY-PRINTER for handling C codes. */
2301 pp_c_pretty_printer_init (c_pretty_printer *pp)
2303 pp->offset_list = 0;
2305 pp->declaration = pp_c_declaration;
2306 pp->declaration_specifiers = pp_c_declaration_specifiers;
2307 pp->declarator = pp_c_declarator;
2308 pp->direct_declarator = pp_c_direct_declarator;
2309 pp->type_specifier_seq = pp_c_specifier_qualifier_list;
2310 pp->abstract_declarator = pp_c_abstract_declarator;
2311 pp->direct_abstract_declarator = pp_c_direct_abstract_declarator;
2312 pp->ptr_operator = pp_c_pointer;
2313 pp->parameter_list = pp_c_parameter_type_list;
2314 pp->type_id = pp_c_type_id;
2315 pp->simple_type_specifier = pp_c_type_specifier;
2316 pp->function_specifier = pp_c_function_specifier;
2317 pp->storage_class_specifier = pp_c_storage_class_specifier;
2319 pp->statement = pp_c_statement;
2321 pp->constant = pp_c_constant;
2322 pp->id_expression = pp_c_id_expression;
2323 pp->primary_expression = pp_c_primary_expression;
2324 pp->postfix_expression = pp_c_postfix_expression;
2325 pp->unary_expression = pp_c_unary_expression;
2326 pp->initializer = pp_c_initializer;
2327 pp->multiplicative_expression = pp_c_multiplicative_expression;
2328 pp->conditional_expression = pp_c_conditional_expression;
2329 pp->assignment_expression = pp_c_assignment_expression;
2330 pp->expression = pp_c_expression;
2334 /* Print the tree T in full, on file FILE. */
2337 print_c_tree (FILE *file, tree t)
2339 static c_pretty_printer pp_rec;
2340 static bool initialized = 0;
2341 c_pretty_printer *pp = &pp_rec;
2346 pp_construct (pp_base (pp), NULL, 0);
2347 pp_c_pretty_printer_init (pp);
2348 pp_needs_newline (pp) = true;
2350 pp_base (pp)->buffer->stream = file;
2352 pp_statement (pp, t);
2358 /* Print the tree T in full, on stderr. */
2361 debug_c_tree (tree t)
2363 print_c_tree (stderr, t);
2364 fputc ('\n', stderr);
2367 /* Output the DECL_NAME of T. If T has no DECL_NAME, output a string made
2368 up of T's memory address. */
2371 pp_c_tree_decl_identifier (c_pretty_printer *pp, tree t)
2375 gcc_assert (DECL_P (t));
2378 name = IDENTIFIER_POINTER (DECL_NAME (t));
2381 static char xname[8];
2382 sprintf (xname, "<U%4x>", ((unsigned)((uintptr_t)(t) & 0xffff)));
2386 pp_c_identifier (pp, name);