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
);
464 else if (!c_dialect_cxx ())
465 pp_c_whitespace (pp
);
466 pp_ptr_operator (pp
, t
);
472 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
477 if (code
== COMPLEX_TYPE
)
478 pp_c_ws_string (pp
, flag_isoc99
? "_Complex" : "__complex__");
479 else if (code
== VECTOR_TYPE
)
481 pp_c_ws_string (pp
, "__vector");
482 pp_c_left_paren (pp
);
483 pp_wide_integer (pp
, TYPE_VECTOR_SUBPARTS (t
));
484 pp_c_right_paren (pp
);
485 pp_c_whitespace (pp
);
487 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
491 pp_simple_type_specifier (pp
, t
);
496 /* parameter-type-list:
501 parameter-declaration
502 parameter-list , parameter-declaration
504 parameter-declaration:
505 declaration-specifiers declarator
506 declaration-specifiers abstract-declarator(opt) */
509 pp_c_parameter_type_list (c_pretty_printer
*pp
, tree t
)
511 bool want_parm_decl
= DECL_P (t
) && !(pp
->flags
& pp_c_flag_abstract
);
512 tree parms
= want_parm_decl
? DECL_ARGUMENTS (t
) : TYPE_ARG_TYPES (t
);
513 pp_c_left_paren (pp
);
514 if (parms
== void_list_node
)
515 pp_c_ws_string (pp
, "void");
519 for ( ; parms
&& parms
!= void_list_node
; parms
= TREE_CHAIN (parms
))
522 pp_separate_with (pp
, ',');
524 pp_declaration_specifiers
525 (pp
, want_parm_decl
? parms
: TREE_VALUE (parms
));
527 pp_declarator (pp
, parms
);
529 pp_abstract_declarator (pp
, TREE_VALUE (parms
));
532 pp_c_right_paren (pp
);
535 /* abstract-declarator:
537 pointer(opt) direct-abstract-declarator */
540 pp_c_abstract_declarator (c_pretty_printer
*pp
, tree t
)
542 if (TREE_CODE (t
) == POINTER_TYPE
)
544 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
545 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
546 pp_c_right_paren (pp
);
550 pp_direct_abstract_declarator (pp
, t
);
553 /* direct-abstract-declarator:
554 ( abstract-declarator )
555 direct-abstract-declarator(opt) [ assignment-expression(opt) ]
556 direct-abstract-declarator(opt) [ * ]
557 direct-abstract-declarator(opt) ( parameter-type-list(opt) ) */
560 pp_c_direct_abstract_declarator (c_pretty_printer
*pp
, tree t
)
562 switch (TREE_CODE (t
))
565 pp_abstract_declarator (pp
, t
);
569 pp_c_parameter_type_list (pp
, t
);
570 pp_direct_abstract_declarator (pp
, TREE_TYPE (t
));
574 pp_c_left_bracket (pp
);
575 if (TYPE_DOMAIN (t
) && TYPE_MAX_VALUE (TYPE_DOMAIN (t
)))
577 tree maxval
= TYPE_MAX_VALUE (TYPE_DOMAIN (t
));
578 tree type
= TREE_TYPE (maxval
);
580 if (host_integerp (maxval
, 0))
581 pp_wide_integer (pp
, tree_low_cst (maxval
, 0) + 1);
583 pp_expression (pp
, fold_build2 (PLUS_EXPR
, type
, maxval
,
584 build_int_cst (type
, 1)));
586 pp_c_right_bracket (pp
);
587 pp_direct_abstract_declarator (pp
, TREE_TYPE (t
));
590 case IDENTIFIER_NODE
:
595 case FIXED_POINT_TYPE
:
605 pp_unsupported_tree (pp
, t
);
611 specifier-qualifier-list abstract-declarator(opt) */
614 pp_c_type_id (c_pretty_printer
*pp
, tree t
)
616 pp_c_specifier_qualifier_list (pp
, t
);
617 pp_abstract_declarator (pp
, t
);
620 /* storage-class-specifier:
628 pp_c_storage_class_specifier (c_pretty_printer
*pp
, tree t
)
630 if (TREE_CODE (t
) == TYPE_DECL
)
631 pp_c_ws_string (pp
, "typedef");
634 if (DECL_REGISTER (t
))
635 pp_c_ws_string (pp
, "register");
636 else if (TREE_STATIC (t
) && TREE_CODE (t
) == VAR_DECL
)
637 pp_c_ws_string (pp
, "static");
641 /* function-specifier:
645 pp_c_function_specifier (c_pretty_printer
*pp
, tree t
)
647 if (TREE_CODE (t
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (t
))
648 pp_c_ws_string (pp
, "inline");
651 /* declaration-specifiers:
652 storage-class-specifier declaration-specifiers(opt)
653 type-specifier declaration-specifiers(opt)
654 type-qualifier declaration-specifiers(opt)
655 function-specifier declaration-specifiers(opt) */
658 pp_c_declaration_specifiers (c_pretty_printer
*pp
, tree t
)
660 pp_storage_class_specifier (pp
, t
);
661 pp_function_specifier (pp
, t
);
662 pp_c_specifier_qualifier_list (pp
, DECL_P (t
) ? TREE_TYPE (t
) : t
);
668 direct-declarator [ type-qualifier-list(opt) assignment-expression(opt) ]
669 direct-declarator [ static type-qualifier-list(opt) assignment-expression(opt)]
670 direct-declarator [ type-qualifier-list static assignment-expression ]
671 direct-declarator [ type-qualifier-list * ]
672 direct-declarator ( parameter-type-list )
673 direct-declarator ( identifier-list(opt) ) */
676 pp_c_direct_declarator (c_pretty_printer
*pp
, tree t
)
678 switch (TREE_CODE (t
))
685 pp_c_space_for_pointer_operator (pp
, TREE_TYPE (t
));
686 pp_c_tree_decl_identifier (pp
, t
);
691 pp_abstract_declarator (pp
, TREE_TYPE (t
));
695 pp_parameter_list (pp
, t
);
696 pp_abstract_declarator (pp
, TREE_TYPE (t
));
700 pp_c_space_for_pointer_operator (pp
, TREE_TYPE (TREE_TYPE (t
)));
701 pp_c_tree_decl_identifier (pp
, t
);
702 if (pp_c_base (pp
)->flags
& pp_c_flag_abstract
)
703 pp_abstract_declarator (pp
, TREE_TYPE (t
));
706 pp_parameter_list (pp
, t
);
707 pp_abstract_declarator (pp
, TREE_TYPE (TREE_TYPE (t
)));
713 case FIXED_POINT_TYPE
:
720 pp_unsupported_tree (pp
, t
);
727 pointer(opt) direct-declarator */
730 pp_c_declarator (c_pretty_printer
*pp
, tree t
)
732 switch (TREE_CODE (t
))
736 case FIXED_POINT_TYPE
:
749 pp_direct_declarator (pp
, t
);
754 pp_unsupported_tree (pp
, t
);
760 declaration-specifiers init-declarator-list(opt) ; */
763 pp_c_declaration (c_pretty_printer
*pp
, tree t
)
765 pp_declaration_specifiers (pp
, t
);
766 pp_c_init_declarator (pp
, t
);
769 /* Pretty-print ATTRIBUTES using GNU C extension syntax. */
772 pp_c_attributes (c_pretty_printer
*pp
, tree attributes
)
774 if (attributes
== NULL_TREE
)
777 pp_c_ws_string (pp
, "__attribute__");
778 pp_c_left_paren (pp
);
779 pp_c_left_paren (pp
);
780 for (; attributes
!= NULL_TREE
; attributes
= TREE_CHAIN (attributes
))
782 pp_tree_identifier (pp
, TREE_PURPOSE (attributes
));
783 if (TREE_VALUE (attributes
))
784 pp_c_call_argument_list (pp
, TREE_VALUE (attributes
));
786 if (TREE_CHAIN (attributes
))
787 pp_separate_with (pp
, ',');
789 pp_c_right_paren (pp
);
790 pp_c_right_paren (pp
);
793 /* function-definition:
794 declaration-specifiers declarator compound-statement */
797 pp_c_function_definition (c_pretty_printer
*pp
, tree t
)
799 pp_declaration_specifiers (pp
, t
);
800 pp_declarator (pp
, t
);
801 pp_needs_newline (pp
) = true;
802 pp_statement (pp
, DECL_SAVED_TREE (t
));
810 /* Print out a c-char. This is called solely for characters which are
811 in the *target* execution character set. We ought to convert them
812 back to the *host* execution character set before printing, but we
813 have no way to do this at present. A decent compromise is to print
814 all characters as if they were in the host execution character set,
815 and not attempt to recover any named escape characters, but render
816 all unprintables as octal escapes. If the host and target character
817 sets are the same, this produces relatively readable output. If they
818 are not the same, strings may appear as gibberish, but that's okay
819 (in fact, it may well be what the reader wants, e.g. if they are looking
820 to see if conversion to the target character set happened correctly).
822 A special case: we need to prefix \, ", and ' with backslashes. It is
823 correct to do so for the *host*'s \, ", and ', because the rest of the
824 file appears in the host character set. */
827 pp_c_char (c_pretty_printer
*pp
, int c
)
833 case '\\': pp_string (pp
, "\\\\"); break;
834 case '\'': pp_string (pp
, "\\\'"); break;
835 case '\"': pp_string (pp
, "\\\""); break;
836 default: pp_character (pp
, c
);
840 pp_scalar (pp
, "\\%03o", (unsigned) c
);
843 /* Print out a STRING literal. */
846 pp_c_string_literal (c_pretty_printer
*pp
, tree s
)
848 const char *p
= TREE_STRING_POINTER (s
);
849 int n
= TREE_STRING_LENGTH (s
) - 1;
852 for (i
= 0; i
< n
; ++i
)
853 pp_c_char (pp
, p
[i
]);
857 /* Pretty-print an INTEGER literal. */
860 pp_c_integer_constant (c_pretty_printer
*pp
, tree i
)
862 tree type
= TREE_TYPE (i
);
864 if (TREE_INT_CST_HIGH (i
) == 0)
865 pp_wide_integer (pp
, TREE_INT_CST_LOW (i
));
868 unsigned HOST_WIDE_INT low
= TREE_INT_CST_LOW (i
);
869 HOST_WIDE_INT high
= TREE_INT_CST_HIGH (i
);
870 if (tree_int_cst_sgn (i
) < 0)
872 pp_character (pp
, '-');
876 sprintf (pp_buffer (pp
)->digit_buffer
, HOST_WIDE_INT_PRINT_DOUBLE_HEX
,
877 (unsigned HOST_WIDE_INT
) high
, (unsigned HOST_WIDE_INT
) low
);
878 pp_string (pp
, pp_buffer (pp
)->digit_buffer
);
880 if (TYPE_UNSIGNED (type
))
881 pp_character (pp
, 'u');
882 if (type
== long_integer_type_node
|| type
== long_unsigned_type_node
)
883 pp_character (pp
, 'l');
884 else if (type
== long_long_integer_type_node
885 || type
== long_long_unsigned_type_node
)
886 pp_string (pp
, "ll");
887 else if (type
== int128_integer_type_node
888 || type
== int128_unsigned_type_node
)
889 pp_string (pp
, "I128");
892 /* Print out a CHARACTER literal. */
895 pp_c_character_constant (c_pretty_printer
*pp
, tree c
)
897 tree type
= TREE_TYPE (c
);
898 if (type
== wchar_type_node
)
899 pp_character (pp
, 'L');
901 if (host_integerp (c
, TYPE_UNSIGNED (type
)))
902 pp_c_char (pp
, tree_low_cst (c
, TYPE_UNSIGNED (type
)));
904 pp_scalar (pp
, "\\x%x", (unsigned) TREE_INT_CST_LOW (c
));
908 /* Print out a BOOLEAN literal. */
911 pp_c_bool_constant (c_pretty_printer
*pp
, tree b
)
913 if (b
== boolean_false_node
)
915 if (c_dialect_cxx ())
916 pp_c_ws_string (pp
, "false");
917 else if (flag_isoc99
)
918 pp_c_ws_string (pp
, "_False");
920 pp_unsupported_tree (pp
, b
);
922 else if (b
== boolean_true_node
)
924 if (c_dialect_cxx ())
925 pp_c_ws_string (pp
, "true");
926 else if (flag_isoc99
)
927 pp_c_ws_string (pp
, "_True");
929 pp_unsupported_tree (pp
, b
);
931 else if (TREE_CODE (b
) == INTEGER_CST
)
932 pp_c_integer_constant (pp
, b
);
934 pp_unsupported_tree (pp
, b
);
937 /* Attempt to print out an ENUMERATOR. Return true on success. Else return
938 false; that means the value was obtained by a cast, in which case
939 print out the type-id part of the cast-expression -- the casted value
940 is then printed by pp_c_integer_literal. */
943 pp_c_enumeration_constant (c_pretty_printer
*pp
, tree e
)
945 bool value_is_named
= true;
946 tree type
= TREE_TYPE (e
);
949 /* Find the name of this constant. */
950 for (value
= TYPE_VALUES (type
);
951 value
!= NULL_TREE
&& !tree_int_cst_equal (TREE_VALUE (value
), e
);
952 value
= TREE_CHAIN (value
))
955 if (value
!= NULL_TREE
)
956 pp_id_expression (pp
, TREE_PURPOSE (value
));
959 /* Value must have been cast. */
960 pp_c_type_cast (pp
, type
);
961 value_is_named
= false;
964 return value_is_named
;
967 /* Print out a REAL value as a decimal-floating-constant. */
970 pp_c_floating_constant (c_pretty_printer
*pp
, tree r
)
972 real_to_decimal (pp_buffer (pp
)->digit_buffer
, &TREE_REAL_CST (r
),
973 sizeof (pp_buffer (pp
)->digit_buffer
), 0, 1);
974 pp_string (pp
, pp_buffer(pp
)->digit_buffer
);
975 if (TREE_TYPE (r
) == float_type_node
)
976 pp_character (pp
, 'f');
977 else if (TREE_TYPE (r
) == long_double_type_node
)
978 pp_character (pp
, 'l');
979 else if (TREE_TYPE (r
) == dfloat128_type_node
)
980 pp_string (pp
, "dl");
981 else if (TREE_TYPE (r
) == dfloat64_type_node
)
982 pp_string (pp
, "dd");
983 else if (TREE_TYPE (r
) == dfloat32_type_node
)
984 pp_string (pp
, "df");
987 /* Print out a FIXED value as a decimal-floating-constant. */
990 pp_c_fixed_constant (c_pretty_printer
*pp
, tree r
)
992 fixed_to_decimal (pp_buffer (pp
)->digit_buffer
, &TREE_FIXED_CST (r
),
993 sizeof (pp_buffer (pp
)->digit_buffer
));
994 pp_string (pp
, pp_buffer(pp
)->digit_buffer
);
997 /* Pretty-print a compound literal expression. GNU extensions include
1001 pp_c_compound_literal (c_pretty_printer
*pp
, tree e
)
1003 tree type
= TREE_TYPE (e
);
1004 pp_c_type_cast (pp
, type
);
1006 switch (TREE_CODE (type
))
1013 pp_c_brace_enclosed_initializer_list (pp
, e
);
1017 pp_unsupported_tree (pp
, e
);
1022 /* Pretty-print a COMPLEX_EXPR expression. */
1025 pp_c_complex_expr (c_pretty_printer
*pp
, tree e
)
1027 /* Handle a few common special cases, otherwise fallback
1028 to printing it as compound literal. */
1029 tree type
= TREE_TYPE (e
);
1030 tree realexpr
= TREE_OPERAND (e
, 0);
1031 tree imagexpr
= TREE_OPERAND (e
, 1);
1033 /* Cast of an COMPLEX_TYPE expression to a different COMPLEX_TYPE. */
1034 if (TREE_CODE (realexpr
) == NOP_EXPR
1035 && TREE_CODE (imagexpr
) == NOP_EXPR
1036 && TREE_TYPE (realexpr
) == TREE_TYPE (type
)
1037 && TREE_TYPE (imagexpr
) == TREE_TYPE (type
)
1038 && TREE_CODE (TREE_OPERAND (realexpr
, 0)) == REALPART_EXPR
1039 && TREE_CODE (TREE_OPERAND (imagexpr
, 0)) == IMAGPART_EXPR
1040 && TREE_OPERAND (TREE_OPERAND (realexpr
, 0), 0)
1041 == TREE_OPERAND (TREE_OPERAND (imagexpr
, 0), 0))
1043 pp_c_type_cast (pp
, type
);
1044 pp_expression (pp
, TREE_OPERAND (TREE_OPERAND (realexpr
, 0), 0));
1048 /* Cast of an scalar expression to COMPLEX_TYPE. */
1049 if ((integer_zerop (imagexpr
) || real_zerop (imagexpr
))
1050 && TREE_TYPE (realexpr
) == TREE_TYPE (type
))
1052 pp_c_type_cast (pp
, type
);
1053 if (TREE_CODE (realexpr
) == NOP_EXPR
)
1054 realexpr
= TREE_OPERAND (realexpr
, 0);
1055 pp_expression (pp
, realexpr
);
1059 pp_c_compound_literal (pp
, e
);
1065 fixed-point-constant
1066 enumeration-constant
1067 character-constant */
1070 pp_c_constant (c_pretty_printer
*pp
, tree e
)
1072 const enum tree_code code
= TREE_CODE (e
);
1078 tree type
= TREE_TYPE (e
);
1079 if (type
== boolean_type_node
)
1080 pp_c_bool_constant (pp
, e
);
1081 else if (type
== char_type_node
)
1082 pp_c_character_constant (pp
, e
);
1083 else if (TREE_CODE (type
) == ENUMERAL_TYPE
1084 && pp_c_enumeration_constant (pp
, e
))
1087 pp_c_integer_constant (pp
, e
);
1092 pp_c_floating_constant (pp
, e
);
1096 pp_c_fixed_constant (pp
, e
);
1100 pp_c_string_literal (pp
, e
);
1104 /* Sometimes, we are confused and we think a complex literal
1105 is a constant. Such thing is a compound literal which
1106 grammatically belongs to postfix-expr production. */
1107 pp_c_compound_literal (pp
, e
);
1111 pp_unsupported_tree (pp
, e
);
1116 /* Pretty-print a string such as an identifier, without changing its
1117 encoding, preceded by whitespace is necessary. */
1120 pp_c_ws_string (c_pretty_printer
*pp
, const char *str
)
1122 pp_c_maybe_whitespace (pp
);
1123 pp_string (pp
, str
);
1124 pp_base (pp
)->padding
= pp_before
;
1127 /* Pretty-print an IDENTIFIER_NODE, which may contain UTF-8 sequences
1128 that need converting to the locale encoding, preceded by whitespace
1132 pp_c_identifier (c_pretty_printer
*pp
, const char *id
)
1134 pp_c_maybe_whitespace (pp
);
1135 pp_identifier (pp
, id
);
1136 pp_base (pp
)->padding
= pp_before
;
1139 /* Pretty-print a C primary-expression.
1147 pp_c_primary_expression (c_pretty_printer
*pp
, tree e
)
1149 switch (TREE_CODE (e
))
1157 pp_c_tree_decl_identifier (pp
, e
);
1160 case IDENTIFIER_NODE
:
1161 pp_c_tree_identifier (pp
, e
);
1165 pp_c_ws_string (pp
, M_("<erroneous-expression>"));
1169 pp_c_ws_string (pp
, M_("<return-value>"));
1176 pp_c_constant (pp
, e
);
1180 pp_c_ws_string (pp
, "__builtin_memcpy");
1181 pp_c_left_paren (pp
);
1183 pp_primary_expression (pp
, TREE_OPERAND (e
, 0));
1184 pp_separate_with (pp
, ',');
1186 pp_initializer (pp
, TREE_OPERAND (e
, 1));
1187 if (TREE_OPERAND (e
, 2))
1189 pp_separate_with (pp
, ',');
1190 pp_c_expression (pp
, TREE_OPERAND (e
, 2));
1192 pp_c_right_paren (pp
);
1196 /* FIXME: Make sure we won't get into an infinite loop. */
1197 pp_c_left_paren (pp
);
1198 pp_expression (pp
, e
);
1199 pp_c_right_paren (pp
);
1204 /* Print out a C initializer -- also support C compound-literals.
1206 assignment-expression:
1207 { initializer-list }
1208 { initializer-list , } */
1211 pp_c_initializer (c_pretty_printer
*pp
, tree e
)
1213 if (TREE_CODE (e
) == CONSTRUCTOR
)
1214 pp_c_brace_enclosed_initializer_list (pp
, e
);
1216 pp_expression (pp
, e
);
1221 declarator = initializer */
1224 pp_c_init_declarator (c_pretty_printer
*pp
, tree t
)
1226 pp_declarator (pp
, t
);
1227 /* We don't want to output function definitions here. There are handled
1228 elsewhere (and the syntactic form is bogus anyway). */
1229 if (TREE_CODE (t
) != FUNCTION_DECL
&& DECL_INITIAL (t
))
1231 tree init
= DECL_INITIAL (t
);
1232 /* This C++ bit is handled here because it is easier to do so.
1233 In templates, the C++ parser builds a TREE_LIST for a
1234 direct-initialization; the TREE_PURPOSE is the variable to
1235 initialize and the TREE_VALUE is the initializer. */
1236 if (TREE_CODE (init
) == TREE_LIST
)
1238 pp_c_left_paren (pp
);
1239 pp_expression (pp
, TREE_VALUE (init
));
1240 pp_right_paren (pp
);
1247 pp_c_initializer (pp
, init
);
1252 /* initializer-list:
1253 designation(opt) initializer
1254 initializer-list , designation(opt) initializer
1261 designator-list designator
1264 [ constant-expression ]
1268 pp_c_initializer_list (c_pretty_printer
*pp
, tree e
)
1270 tree type
= TREE_TYPE (e
);
1271 const enum tree_code code
= TREE_CODE (type
);
1273 if (TREE_CODE (e
) == CONSTRUCTOR
)
1275 pp_c_constructor_elts (pp
, CONSTRUCTOR_ELTS (e
));
1285 tree init
= TREE_OPERAND (e
, 0);
1286 for (; init
!= NULL_TREE
; init
= TREE_CHAIN (init
))
1288 if (code
== RECORD_TYPE
|| code
== UNION_TYPE
)
1291 pp_c_primary_expression (pp
, TREE_PURPOSE (init
));
1295 pp_c_left_bracket (pp
);
1296 if (TREE_PURPOSE (init
))
1297 pp_c_constant (pp
, TREE_PURPOSE (init
));
1298 pp_c_right_bracket (pp
);
1300 pp_c_whitespace (pp
);
1302 pp_c_whitespace (pp
);
1303 pp_initializer (pp
, TREE_VALUE (init
));
1304 if (TREE_CHAIN (init
))
1305 pp_separate_with (pp
, ',');
1311 if (TREE_CODE (e
) == VECTOR_CST
)
1312 pp_c_expression_list (pp
, TREE_VECTOR_CST_ELTS (e
));
1318 if (TREE_CODE (e
) == COMPLEX_CST
|| TREE_CODE (e
) == COMPLEX_EXPR
)
1320 const bool cst
= TREE_CODE (e
) == COMPLEX_CST
;
1321 pp_expression (pp
, cst
? TREE_REALPART (e
) : TREE_OPERAND (e
, 0));
1322 pp_separate_with (pp
, ',');
1323 pp_expression (pp
, cst
? TREE_IMAGPART (e
) : TREE_OPERAND (e
, 1));
1333 pp_unsupported_tree (pp
, type
);
1336 /* Pretty-print a brace-enclosed initializer-list. */
1339 pp_c_brace_enclosed_initializer_list (c_pretty_printer
*pp
, tree l
)
1341 pp_c_left_brace (pp
);
1342 pp_c_initializer_list (pp
, l
);
1343 pp_c_right_brace (pp
);
1347 /* This is a convenient function, used to bridge gap between C and C++
1354 pp_c_id_expression (c_pretty_printer
*pp
, tree t
)
1356 switch (TREE_CODE (t
))
1365 pp_c_tree_decl_identifier (pp
, t
);
1368 case IDENTIFIER_NODE
:
1369 pp_c_tree_identifier (pp
, t
);
1373 pp_unsupported_tree (pp
, t
);
1378 /* postfix-expression:
1380 postfix-expression [ expression ]
1381 postfix-expression ( argument-expression-list(opt) )
1382 postfix-expression . identifier
1383 postfix-expression -> identifier
1384 postfix-expression ++
1385 postfix-expression --
1386 ( type-name ) { initializer-list }
1387 ( type-name ) { initializer-list , } */
1390 pp_c_postfix_expression (c_pretty_printer
*pp
, tree e
)
1392 enum tree_code code
= TREE_CODE (e
);
1395 case POSTINCREMENT_EXPR
:
1396 case POSTDECREMENT_EXPR
:
1397 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1398 pp_string (pp
, code
== POSTINCREMENT_EXPR
? "++" : "--");
1402 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1403 pp_c_left_bracket (pp
);
1404 pp_expression (pp
, TREE_OPERAND (e
, 1));
1405 pp_c_right_bracket (pp
);
1410 call_expr_arg_iterator iter
;
1412 pp_postfix_expression (pp
, CALL_EXPR_FN (e
));
1413 pp_c_left_paren (pp
);
1414 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, e
)
1416 pp_expression (pp
, arg
);
1417 if (more_call_expr_args_p (&iter
))
1418 pp_separate_with (pp
, ',');
1420 pp_c_right_paren (pp
);
1424 case UNORDERED_EXPR
:
1425 pp_c_ws_string (pp
, flag_isoc99
1427 : "__builtin_isunordered");
1431 pp_c_ws_string (pp
, flag_isoc99
1433 : "!__builtin_isunordered");
1437 pp_c_ws_string (pp
, flag_isoc99
1439 : "!__builtin_isgreaterequal");
1443 pp_c_ws_string (pp
, flag_isoc99
1445 : "!__builtin_isgreater");
1449 pp_c_ws_string (pp
, flag_isoc99
1451 : "!__builtin_islessequal");
1455 pp_c_ws_string (pp
, flag_isoc99
1457 : "!__builtin_isless");
1461 pp_c_ws_string (pp
, flag_isoc99
1463 : "!__builtin_islessgreater");
1467 pp_c_ws_string (pp
, flag_isoc99
1469 : "__builtin_islessgreater");
1473 pp_c_left_paren (pp
);
1474 pp_expression (pp
, TREE_OPERAND (e
, 0));
1475 pp_separate_with (pp
, ',');
1476 pp_expression (pp
, TREE_OPERAND (e
, 1));
1477 pp_c_right_paren (pp
);
1481 pp_c_ws_string (pp
, "__builtin_abs");
1482 pp_c_left_paren (pp
);
1483 pp_expression (pp
, TREE_OPERAND (e
, 0));
1484 pp_c_right_paren (pp
);
1489 tree object
= TREE_OPERAND (e
, 0);
1490 if (TREE_CODE (object
) == INDIRECT_REF
)
1492 pp_postfix_expression (pp
, TREE_OPERAND (object
, 0));
1497 pp_postfix_expression (pp
, object
);
1500 pp_expression (pp
, TREE_OPERAND (e
, 1));
1506 tree type
= TREE_TYPE (e
);
1508 type
= signed_or_unsigned_type_for (TYPE_UNSIGNED (type
), type
);
1510 && tree_int_cst_equal (TYPE_SIZE (type
), TREE_OPERAND (e
, 1)))
1512 HOST_WIDE_INT bitpos
= tree_low_cst (TREE_OPERAND (e
, 2), 0);
1513 HOST_WIDE_INT size
= tree_low_cst (TYPE_SIZE (type
), 0);
1514 if ((bitpos
% size
) == 0)
1516 pp_c_left_paren (pp
);
1517 pp_c_left_paren (pp
);
1518 pp_type_id (pp
, type
);
1520 pp_c_right_paren (pp
);
1521 pp_c_ampersand (pp
);
1522 pp_expression (pp
, TREE_OPERAND (e
, 0));
1523 pp_c_right_paren (pp
);
1524 pp_c_left_bracket (pp
);
1525 pp_wide_integer (pp
, bitpos
/ size
);
1526 pp_c_right_bracket (pp
);
1530 pp_unsupported_tree (pp
, e
);
1536 pp_c_compound_literal (pp
, e
);
1540 pp_c_complex_expr (pp
, e
);
1543 case COMPOUND_LITERAL_EXPR
:
1544 e
= DECL_INITIAL (COMPOUND_LITERAL_EXPR_DECL (e
));
1547 pp_initializer (pp
, e
);
1551 pp_c_ws_string (pp
, "__builtin_va_arg");
1552 pp_c_left_paren (pp
);
1553 pp_assignment_expression (pp
, TREE_OPERAND (e
, 0));
1554 pp_separate_with (pp
, ',');
1555 pp_type_id (pp
, TREE_TYPE (e
));
1556 pp_c_right_paren (pp
);
1560 if (TREE_CODE (TREE_OPERAND (e
, 0)) == FUNCTION_DECL
)
1562 pp_c_id_expression (pp
, TREE_OPERAND (e
, 0));
1565 /* else fall through. */
1568 pp_primary_expression (pp
, e
);
1573 /* Print out an expression-list; E is expected to be a TREE_LIST. */
1576 pp_c_expression_list (c_pretty_printer
*pp
, tree e
)
1578 for (; e
!= NULL_TREE
; e
= TREE_CHAIN (e
))
1580 pp_expression (pp
, TREE_VALUE (e
));
1582 pp_separate_with (pp
, ',');
1586 /* Print out V, which contains the elements of a constructor. */
1589 pp_c_constructor_elts (c_pretty_printer
*pp
, VEC(constructor_elt
,gc
) *v
)
1591 unsigned HOST_WIDE_INT ix
;
1594 FOR_EACH_CONSTRUCTOR_VALUE (v
, ix
, value
)
1596 pp_expression (pp
, value
);
1597 if (ix
!= VEC_length (constructor_elt
, v
) - 1)
1598 pp_separate_with (pp
, ',');
1602 /* Print out an expression-list in parens, as if it were the argument
1603 list to a function. */
1606 pp_c_call_argument_list (c_pretty_printer
*pp
, tree t
)
1608 pp_c_left_paren (pp
);
1609 if (t
&& TREE_CODE (t
) == TREE_LIST
)
1610 pp_c_expression_list (pp
, t
);
1611 pp_c_right_paren (pp
);
1614 /* unary-expression:
1618 unary-operator cast-expression
1619 sizeof unary-expression
1622 unary-operator: one of
1627 __alignof__ unary-expression
1628 __alignof__ ( type-id )
1629 __real__ unary-expression
1630 __imag__ unary-expression */
1633 pp_c_unary_expression (c_pretty_printer
*pp
, tree e
)
1635 enum tree_code code
= TREE_CODE (e
);
1638 case PREINCREMENT_EXPR
:
1639 case PREDECREMENT_EXPR
:
1640 pp_string (pp
, code
== PREINCREMENT_EXPR
? "++" : "--");
1641 pp_c_unary_expression (pp
, TREE_OPERAND (e
, 0));
1648 case TRUTH_NOT_EXPR
:
1650 /* String literal are used by address. */
1651 if (code
== ADDR_EXPR
&& TREE_CODE (TREE_OPERAND (e
, 0)) != STRING_CST
)
1653 else if (code
== INDIRECT_REF
)
1655 else if (code
== NEGATE_EXPR
)
1657 else if (code
== BIT_NOT_EXPR
|| code
== CONJ_EXPR
)
1659 else if (code
== TRUTH_NOT_EXPR
)
1660 pp_exclamation (pp
);
1661 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 0));
1666 pp_c_ws_string (pp
, code
== REALPART_EXPR
? "__real__" : "__imag__");
1667 pp_c_whitespace (pp
);
1668 pp_unary_expression (pp
, TREE_OPERAND (e
, 0));
1672 pp_postfix_expression (pp
, e
);
1679 ( type-name ) cast-expression */
1682 pp_c_cast_expression (c_pretty_printer
*pp
, tree e
)
1684 switch (TREE_CODE (e
))
1687 case FIX_TRUNC_EXPR
:
1689 case VIEW_CONVERT_EXPR
:
1690 pp_c_type_cast (pp
, TREE_TYPE (e
));
1691 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 0));
1695 pp_unary_expression (pp
, e
);
1699 /* multiplicative-expression:
1701 multiplicative-expression * cast-expression
1702 multiplicative-expression / cast-expression
1703 multiplicative-expression % cast-expression */
1706 pp_c_multiplicative_expression (c_pretty_printer
*pp
, tree e
)
1708 enum tree_code code
= TREE_CODE (e
);
1712 case TRUNC_DIV_EXPR
:
1713 case TRUNC_MOD_EXPR
:
1714 pp_multiplicative_expression (pp
, TREE_OPERAND (e
, 0));
1715 pp_c_whitespace (pp
);
1716 if (code
== MULT_EXPR
)
1718 else if (code
== TRUNC_DIV_EXPR
)
1722 pp_c_whitespace (pp
);
1723 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 1));
1727 pp_c_cast_expression (pp
, e
);
1732 /* additive-expression:
1733 multiplicative-expression
1734 additive-expression + multiplicative-expression
1735 additive-expression - multiplicative-expression */
1738 pp_c_additive_expression (c_pretty_printer
*pp
, tree e
)
1740 enum tree_code code
= TREE_CODE (e
);
1743 case POINTER_PLUS_EXPR
:
1746 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 0));
1747 pp_c_whitespace (pp
);
1748 if (code
== PLUS_EXPR
|| code
== POINTER_PLUS_EXPR
)
1752 pp_c_whitespace (pp
);
1753 pp_multiplicative_expression (pp
, TREE_OPERAND (e
, 1));
1757 pp_multiplicative_expression (pp
, e
);
1762 /* additive-expression:
1764 shift-expression << additive-expression
1765 shift-expression >> additive-expression */
1768 pp_c_shift_expression (c_pretty_printer
*pp
, tree e
)
1770 enum tree_code code
= TREE_CODE (e
);
1775 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 0));
1776 pp_c_whitespace (pp
);
1777 pp_string (pp
, code
== LSHIFT_EXPR
? "<<" : ">>");
1778 pp_c_whitespace (pp
);
1779 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 1));
1783 pp_c_additive_expression (pp
, e
);
1787 /* relational-expression:
1789 relational-expression < shift-expression
1790 relational-expression > shift-expression
1791 relational-expression <= shift-expression
1792 relational-expression >= shift-expression */
1795 pp_c_relational_expression (c_pretty_printer
*pp
, tree e
)
1797 enum tree_code code
= TREE_CODE (e
);
1804 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 0));
1805 pp_c_whitespace (pp
);
1806 if (code
== LT_EXPR
)
1808 else if (code
== GT_EXPR
)
1810 else if (code
== LE_EXPR
)
1811 pp_string (pp
, "<=");
1812 else if (code
== GE_EXPR
)
1813 pp_string (pp
, ">=");
1814 pp_c_whitespace (pp
);
1815 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 1));
1819 pp_c_shift_expression (pp
, e
);
1824 /* equality-expression:
1825 relational-expression
1826 equality-expression == relational-expression
1827 equality-equality != relational-expression */
1830 pp_c_equality_expression (c_pretty_printer
*pp
, tree e
)
1832 enum tree_code code
= TREE_CODE (e
);
1837 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 0));
1838 pp_c_whitespace (pp
);
1839 pp_string (pp
, code
== EQ_EXPR
? "==" : "!=");
1840 pp_c_whitespace (pp
);
1841 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 1));
1845 pp_c_relational_expression (pp
, e
);
1852 AND-expression & equality-equality */
1855 pp_c_and_expression (c_pretty_printer
*pp
, tree e
)
1857 if (TREE_CODE (e
) == BIT_AND_EXPR
)
1859 pp_c_and_expression (pp
, TREE_OPERAND (e
, 0));
1860 pp_c_whitespace (pp
);
1862 pp_c_whitespace (pp
);
1863 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 1));
1866 pp_c_equality_expression (pp
, e
);
1869 /* exclusive-OR-expression:
1871 exclusive-OR-expression ^ AND-expression */
1874 pp_c_exclusive_or_expression (c_pretty_printer
*pp
, tree e
)
1876 if (TREE_CODE (e
) == BIT_XOR_EXPR
1877 || TREE_CODE (e
) == TRUTH_XOR_EXPR
)
1879 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
1880 if (TREE_CODE (e
) == BIT_XOR_EXPR
)
1881 pp_c_maybe_whitespace (pp
);
1883 pp_c_whitespace (pp
);
1885 pp_c_whitespace (pp
);
1886 pp_c_and_expression (pp
, TREE_OPERAND (e
, 1));
1889 pp_c_and_expression (pp
, e
);
1892 /* inclusive-OR-expression:
1893 exclusive-OR-expression
1894 inclusive-OR-expression | exclusive-OR-expression */
1897 pp_c_inclusive_or_expression (c_pretty_printer
*pp
, tree e
)
1899 if (TREE_CODE (e
) == BIT_IOR_EXPR
)
1901 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
1902 pp_c_whitespace (pp
);
1904 pp_c_whitespace (pp
);
1905 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
1908 pp_c_exclusive_or_expression (pp
, e
);
1911 /* logical-AND-expression:
1912 inclusive-OR-expression
1913 logical-AND-expression && inclusive-OR-expression */
1916 pp_c_logical_and_expression (c_pretty_printer
*pp
, tree e
)
1918 if (TREE_CODE (e
) == TRUTH_ANDIF_EXPR
1919 || TREE_CODE (e
) == TRUTH_AND_EXPR
)
1921 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 0));
1922 pp_c_whitespace (pp
);
1923 pp_string (pp
, "&&");
1924 pp_c_whitespace (pp
);
1925 pp_c_inclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
1928 pp_c_inclusive_or_expression (pp
, e
);
1931 /* logical-OR-expression:
1932 logical-AND-expression
1933 logical-OR-expression || logical-AND-expression */
1936 pp_c_logical_or_expression (c_pretty_printer
*pp
, tree e
)
1938 if (TREE_CODE (e
) == TRUTH_ORIF_EXPR
1939 || TREE_CODE (e
) == TRUTH_OR_EXPR
)
1941 pp_c_logical_or_expression (pp
, TREE_OPERAND (e
, 0));
1942 pp_c_whitespace (pp
);
1943 pp_string (pp
, "||");
1944 pp_c_whitespace (pp
);
1945 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 1));
1948 pp_c_logical_and_expression (pp
, e
);
1951 /* conditional-expression:
1952 logical-OR-expression
1953 logical-OR-expression ? expression : conditional-expression */
1956 pp_c_conditional_expression (c_pretty_printer
*pp
, tree e
)
1958 if (TREE_CODE (e
) == COND_EXPR
)
1960 pp_c_logical_or_expression (pp
, TREE_OPERAND (e
, 0));
1961 pp_c_whitespace (pp
);
1963 pp_c_whitespace (pp
);
1964 pp_expression (pp
, TREE_OPERAND (e
, 1));
1965 pp_c_whitespace (pp
);
1967 pp_c_whitespace (pp
);
1968 pp_c_conditional_expression (pp
, TREE_OPERAND (e
, 2));
1971 pp_c_logical_or_expression (pp
, e
);
1975 /* assignment-expression:
1976 conditional-expression
1977 unary-expression assignment-operator assignment-expression
1979 assignment-expression: one of
1980 = *= /= %= += -= >>= <<= &= ^= |= */
1983 pp_c_assignment_expression (c_pretty_printer
*pp
, tree e
)
1985 if (TREE_CODE (e
) == MODIFY_EXPR
1986 || TREE_CODE (e
) == INIT_EXPR
)
1988 pp_c_unary_expression (pp
, TREE_OPERAND (e
, 0));
1989 pp_c_whitespace (pp
);
1992 pp_c_expression (pp
, TREE_OPERAND (e
, 1));
1995 pp_c_conditional_expression (pp
, e
);
1999 assignment-expression
2000 expression , assignment-expression
2002 Implementation note: instead of going through the usual recursion
2003 chain, I take the liberty of dispatching nodes to the appropriate
2004 functions. This makes some redundancy, but it worths it. That also
2005 prevents a possible infinite recursion between pp_c_primary_expression ()
2006 and pp_c_expression (). */
2009 pp_c_expression (c_pretty_printer
*pp
, tree e
)
2011 switch (TREE_CODE (e
))
2014 pp_c_integer_constant (pp
, e
);
2018 pp_c_floating_constant (pp
, e
);
2022 pp_c_fixed_constant (pp
, e
);
2026 pp_c_string_literal (pp
, e
);
2029 case IDENTIFIER_NODE
:
2038 pp_primary_expression (pp
, e
);
2041 case POSTINCREMENT_EXPR
:
2042 case POSTDECREMENT_EXPR
:
2051 case UNORDERED_EXPR
:
2060 case COMPOUND_LITERAL_EXPR
:
2062 pp_postfix_expression (pp
, e
);
2070 case TRUTH_NOT_EXPR
:
2071 case PREINCREMENT_EXPR
:
2072 case PREDECREMENT_EXPR
:
2075 pp_c_unary_expression (pp
, e
);
2079 case FIX_TRUNC_EXPR
:
2081 case VIEW_CONVERT_EXPR
:
2082 pp_c_cast_expression (pp
, e
);
2086 case TRUNC_MOD_EXPR
:
2087 case TRUNC_DIV_EXPR
:
2088 pp_multiplicative_expression (pp
, e
);
2093 pp_c_shift_expression (pp
, e
);
2100 pp_c_relational_expression (pp
, e
);
2104 pp_c_and_expression (pp
, e
);
2108 case TRUTH_XOR_EXPR
:
2109 pp_c_exclusive_or_expression (pp
, e
);
2113 pp_c_inclusive_or_expression (pp
, e
);
2116 case TRUTH_ANDIF_EXPR
:
2117 case TRUTH_AND_EXPR
:
2118 pp_c_logical_and_expression (pp
, e
);
2121 case TRUTH_ORIF_EXPR
:
2123 pp_c_logical_or_expression (pp
, e
);
2128 pp_c_equality_expression (pp
, e
);
2132 pp_conditional_expression (pp
, e
);
2135 case POINTER_PLUS_EXPR
:
2138 pp_c_additive_expression (pp
, e
);
2143 pp_assignment_expression (pp
, e
);
2147 pp_c_left_paren (pp
);
2148 pp_expression (pp
, TREE_OPERAND (e
, 0));
2149 pp_separate_with (pp
, ',');
2150 pp_assignment_expression (pp
, TREE_OPERAND (e
, 1));
2151 pp_c_right_paren (pp
);
2154 case NON_LVALUE_EXPR
:
2156 pp_expression (pp
, TREE_OPERAND (e
, 0));
2160 pp_postfix_expression (pp
, TREE_OPERAND (e
, 1));
2165 /* We don't yet have a way of dumping statements in a
2166 human-readable format. */
2167 pp_string (pp
, "({...})");
2171 pp_unsupported_tree (pp
, e
);
2181 pp_c_statement (c_pretty_printer
*pp
, tree stmt
)
2186 if (pp_needs_newline (pp
))
2187 pp_newline_and_indent (pp
, 0);
2189 dump_generic_node (pp_base (pp
), stmt
, pp_indentation (pp
), 0, true);
2193 /* Initialize the PRETTY-PRINTER for handling C codes. */
2196 pp_c_pretty_printer_init (c_pretty_printer
*pp
)
2198 pp
->offset_list
= 0;
2200 pp
->declaration
= pp_c_declaration
;
2201 pp
->declaration_specifiers
= pp_c_declaration_specifiers
;
2202 pp
->declarator
= pp_c_declarator
;
2203 pp
->direct_declarator
= pp_c_direct_declarator
;
2204 pp
->type_specifier_seq
= pp_c_specifier_qualifier_list
;
2205 pp
->abstract_declarator
= pp_c_abstract_declarator
;
2206 pp
->direct_abstract_declarator
= pp_c_direct_abstract_declarator
;
2207 pp
->ptr_operator
= pp_c_pointer
;
2208 pp
->parameter_list
= pp_c_parameter_type_list
;
2209 pp
->type_id
= pp_c_type_id
;
2210 pp
->simple_type_specifier
= pp_c_type_specifier
;
2211 pp
->function_specifier
= pp_c_function_specifier
;
2212 pp
->storage_class_specifier
= pp_c_storage_class_specifier
;
2214 pp
->statement
= pp_c_statement
;
2216 pp
->constant
= pp_c_constant
;
2217 pp
->id_expression
= pp_c_id_expression
;
2218 pp
->primary_expression
= pp_c_primary_expression
;
2219 pp
->postfix_expression
= pp_c_postfix_expression
;
2220 pp
->unary_expression
= pp_c_unary_expression
;
2221 pp
->initializer
= pp_c_initializer
;
2222 pp
->multiplicative_expression
= pp_c_multiplicative_expression
;
2223 pp
->conditional_expression
= pp_c_conditional_expression
;
2224 pp
->assignment_expression
= pp_c_assignment_expression
;
2225 pp
->expression
= pp_c_expression
;
2229 /* Print the tree T in full, on file FILE. */
2232 print_c_tree (FILE *file
, tree t
)
2234 static c_pretty_printer pp_rec
;
2235 static bool initialized
= 0;
2236 c_pretty_printer
*pp
= &pp_rec
;
2241 pp_construct (pp_base (pp
), NULL
, 0);
2242 pp_c_pretty_printer_init (pp
);
2243 pp_needs_newline (pp
) = true;
2245 pp_base (pp
)->buffer
->stream
= file
;
2247 pp_statement (pp
, t
);
2253 /* Print the tree T in full, on stderr. */
2256 debug_c_tree (tree t
)
2258 print_c_tree (stderr
, t
);
2259 fputc ('\n', stderr
);
2262 /* Output the DECL_NAME of T. If T has no DECL_NAME, output a string made
2263 up of T's memory address. */
2266 pp_c_tree_decl_identifier (c_pretty_printer
*pp
, tree t
)
2270 gcc_assert (DECL_P (t
));
2273 name
= IDENTIFIER_POINTER (DECL_NAME (t
));
2276 static char xname
[8];
2277 sprintf (xname
, "<U%4x>", ((unsigned)((uintptr_t)(t
) & 0xffff)));
2281 pp_c_identifier (pp
, name
);