1 /* Subroutines common to both C and C++ pretty-printers.
2 Copyright (C) 2002-2013 Free Software Foundation, Inc.
3 Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
27 #include "c-pretty-print.h"
28 #include "tree-pretty-print.h"
29 #include "tree-iterator.h"
30 #include "diagnostic.h"
32 /* The pretty-printer code is primarily designed to closely follow
33 (GNU) C and C++ grammars. That is to be contrasted with spaghetti
34 codes we used to have in the past. Following a structured
35 approach (preferably the official grammars) is believed to make it
36 much easier to add extensions and nifty pretty-printing effects that
37 takes expression or declaration contexts into account. */
40 #define pp_c_maybe_whitespace(PP) \
42 if ((PP)->padding == pp_before) \
43 pp_c_whitespace (PP); \
47 static void pp_c_char (c_pretty_printer
*, int);
49 /* postfix-expression */
50 static void pp_c_initializer_list (c_pretty_printer
*, tree
);
51 static void pp_c_brace_enclosed_initializer_list (c_pretty_printer
*, tree
);
53 static void pp_c_additive_expression (c_pretty_printer
*, tree
);
54 static void pp_c_shift_expression (c_pretty_printer
*, tree
);
55 static void pp_c_relational_expression (c_pretty_printer
*, tree
);
56 static void pp_c_equality_expression (c_pretty_printer
*, tree
);
57 static void pp_c_and_expression (c_pretty_printer
*, tree
);
58 static void pp_c_exclusive_or_expression (c_pretty_printer
*, tree
);
59 static void pp_c_inclusive_or_expression (c_pretty_printer
*, tree
);
60 static void pp_c_logical_and_expression (c_pretty_printer
*, tree
);
65 /* Helper functions. */
68 pp_c_whitespace (c_pretty_printer
*pp
)
71 pp
->padding
= pp_none
;
75 pp_c_left_paren (c_pretty_printer
*pp
)
78 pp
->padding
= pp_none
;
82 pp_c_right_paren (c_pretty_printer
*pp
)
85 pp
->padding
= pp_none
;
89 pp_c_left_brace (c_pretty_printer
*pp
)
92 pp
->padding
= pp_none
;
96 pp_c_right_brace (c_pretty_printer
*pp
)
99 pp
->padding
= pp_none
;
103 pp_c_left_bracket (c_pretty_printer
*pp
)
105 pp_left_bracket (pp
);
106 pp
->padding
= pp_none
;
110 pp_c_right_bracket (c_pretty_printer
*pp
)
112 pp_right_bracket (pp
);
113 pp
->padding
= pp_none
;
117 pp_c_dot (c_pretty_printer
*pp
)
120 pp
->padding
= pp_none
;
124 pp_c_ampersand (c_pretty_printer
*pp
)
127 pp
->padding
= pp_none
;
131 pp_c_star (c_pretty_printer
*pp
)
134 pp
->padding
= pp_none
;
138 pp_c_arrow (c_pretty_printer
*pp
)
141 pp
->padding
= pp_none
;
145 pp_c_semicolon (c_pretty_printer
*pp
)
148 pp
->padding
= pp_none
;
152 pp_c_complement (c_pretty_printer
*pp
)
155 pp
->padding
= pp_none
;
159 pp_c_exclamation (c_pretty_printer
*pp
)
162 pp
->padding
= pp_none
;
165 /* Print out the external representation of QUALIFIERS. */
168 pp_c_cv_qualifiers (c_pretty_printer
*pp
, int qualifiers
, bool func_type
)
170 const char *p
= pp_last_position_in_text (pp
);
171 bool previous
= false;
176 /* The C programming language does not have references, but it is much
177 simpler to handle those here rather than going through the same
178 logic in the C++ pretty-printer. */
179 if (p
!= NULL
&& (*p
== '*' || *p
== '&'))
180 pp_c_whitespace (pp
);
182 if (qualifiers
& TYPE_QUAL_ATOMIC
)
184 pp_c_ws_string (pp
, "_Atomic");
188 if (qualifiers
& TYPE_QUAL_CONST
)
191 pp_c_whitespace (pp
);
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
257 address-space-qualifier:
258 identifier -- GNU C */
261 pp_c_type_qualifier_list (c_pretty_printer
*pp
, tree t
)
265 if (!t
|| t
== error_mark_node
)
271 qualifiers
= TYPE_QUALS (t
);
272 pp_c_cv_qualifiers (pp
, qualifiers
,
273 TREE_CODE (t
) == FUNCTION_TYPE
);
275 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (t
)))
277 const char *as
= c_addr_space_name (TYPE_ADDR_SPACE (t
));
278 pp_c_identifier (pp
, as
);
283 * type-qualifier-list(opt)
284 * type-qualifier-list(opt) pointer */
287 pp_c_pointer (c_pretty_printer
*pp
, tree t
)
289 if (!TYPE_P (t
) && TREE_CODE (t
) != TYPE_DECL
)
291 switch (TREE_CODE (t
))
294 /* It is easier to handle C++ reference types here. */
296 if (TREE_CODE (TREE_TYPE (t
)) == POINTER_TYPE
)
297 pp_c_pointer (pp
, TREE_TYPE (t
));
298 if (TREE_CODE (t
) == POINTER_TYPE
)
302 pp_c_type_qualifier_list (pp
, t
);
305 /* ??? This node is now in GENERIC and so shouldn't be here. But
306 we'll fix that later. */
308 pp
->declaration (DECL_EXPR_DECL (t
));
309 pp_needs_newline (pp
) = true;
313 pp_unsupported_tree (pp
, t
);
317 /* simple-type-specifier:
333 struct-or-union-specifier
338 simple-type-specifier:
343 c_pretty_printer::simple_type_specifier (tree t
)
345 const enum tree_code code
= TREE_CODE (t
);
349 translate_string ("<type-error>");
352 case IDENTIFIER_NODE
:
353 pp_c_identifier (this, IDENTIFIER_POINTER (t
));
360 case FIXED_POINT_TYPE
:
364 simple_type_specifier (t
);
368 int prec
= TYPE_PRECISION (t
);
369 if (ALL_FIXED_POINT_MODE_P (TYPE_MODE (t
)))
370 t
= c_common_type_for_mode (TYPE_MODE (t
), TYPE_SATURATING (t
));
372 t
= c_common_type_for_mode (TYPE_MODE (t
), TYPE_UNSIGNED (t
));
375 simple_type_specifier (t
);
376 if (TYPE_PRECISION (t
) != prec
)
379 pp_decimal_int (this, prec
);
387 translate_string (TYPE_UNSIGNED (t
)
388 ? "<unnamed-unsigned:"
389 : "<unnamed-signed:");
392 translate_string ("<unnamed-float:");
394 case FIXED_POINT_TYPE
:
395 translate_string ("<unnamed-fixed:");
400 pp_decimal_int (this, prec
);
410 translate_string ("<typedef-error>");
416 if (code
== UNION_TYPE
)
417 pp_c_ws_string (this, "union");
418 else if (code
== RECORD_TYPE
)
419 pp_c_ws_string (this, "struct");
420 else if (code
== ENUMERAL_TYPE
)
421 pp_c_ws_string (this, "enum");
423 translate_string ("<tag-error>");
426 id_expression (TYPE_NAME (t
));
428 translate_string ("<anonymous>");
432 pp_unsupported_tree (this, t
);
437 /* specifier-qualifier-list:
438 type-specifier specifier-qualifier-list-opt
439 type-qualifier specifier-qualifier-list-opt
442 Implementation note: Because of the non-linearities in array or
443 function declarations, this routine prints not just the
444 specifier-qualifier-list of such entities or types of such entities,
445 but also the 'pointer' production part of their declarators. The
446 remaining part is done by declarator() or abstract_declarator(). */
449 pp_c_specifier_qualifier_list (c_pretty_printer
*pp
, tree t
)
451 const enum tree_code code
= TREE_CODE (t
);
453 if (!(pp
->flags
& pp_c_flag_gnu_v3
) && code
!= POINTER_TYPE
)
454 pp_c_type_qualifier_list (pp
, t
);
460 /* Get the types-specifier of this type. */
461 tree pointee
= strip_pointer_operator (TREE_TYPE (t
));
462 pp_c_specifier_qualifier_list (pp
, pointee
);
463 if (TREE_CODE (pointee
) == ARRAY_TYPE
464 || TREE_CODE (pointee
) == FUNCTION_TYPE
)
466 pp_c_whitespace (pp
);
467 pp_c_left_paren (pp
);
468 pp_c_attributes_display (pp
, TYPE_ATTRIBUTES (pointee
));
470 else if (!c_dialect_cxx ())
471 pp_c_whitespace (pp
);
472 pp_ptr_operator (pp
, t
);
478 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
483 if (code
== COMPLEX_TYPE
)
484 pp_c_ws_string (pp
, (flag_isoc99
&& !c_dialect_cxx ()
485 ? "_Complex" : "__complex__"));
486 else if (code
== VECTOR_TYPE
)
488 pp_c_ws_string (pp
, "__vector");
489 pp_c_left_paren (pp
);
490 pp_wide_integer (pp
, TYPE_VECTOR_SUBPARTS (t
));
491 pp_c_right_paren (pp
);
492 pp_c_whitespace (pp
);
494 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
498 pp
->simple_type_specifier (t
);
501 if ((pp
->flags
& pp_c_flag_gnu_v3
) && code
!= POINTER_TYPE
)
502 pp_c_type_qualifier_list (pp
, t
);
505 /* parameter-type-list:
510 parameter-declaration
511 parameter-list , parameter-declaration
513 parameter-declaration:
514 declaration-specifiers declarator
515 declaration-specifiers abstract-declarator(opt) */
518 pp_c_parameter_type_list (c_pretty_printer
*pp
, tree t
)
520 bool want_parm_decl
= DECL_P (t
) && !(pp
->flags
& pp_c_flag_abstract
);
521 tree parms
= want_parm_decl
? DECL_ARGUMENTS (t
) : TYPE_ARG_TYPES (t
);
522 pp_c_left_paren (pp
);
523 if (parms
== void_list_node
)
524 pp_c_ws_string (pp
, "void");
528 for ( ; parms
&& parms
!= void_list_node
; parms
= TREE_CHAIN (parms
))
531 pp_separate_with (pp
, ',');
533 pp
->declaration_specifiers
534 (want_parm_decl
? parms
: TREE_VALUE (parms
));
536 pp
->declarator (parms
);
538 pp
->abstract_declarator (TREE_VALUE (parms
));
541 pp_c_right_paren (pp
);
544 /* abstract-declarator:
546 pointer(opt) direct-abstract-declarator */
549 c_pretty_printer::abstract_declarator (tree t
)
551 if (TREE_CODE (t
) == POINTER_TYPE
)
553 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
554 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
555 pp_c_right_paren (this);
559 direct_abstract_declarator (t
);
562 /* direct-abstract-declarator:
563 ( abstract-declarator )
564 direct-abstract-declarator(opt) [ assignment-expression(opt) ]
565 direct-abstract-declarator(opt) [ * ]
566 direct-abstract-declarator(opt) ( parameter-type-list(opt) ) */
569 c_pretty_printer::direct_abstract_declarator (tree t
)
571 switch (TREE_CODE (t
))
574 abstract_declarator (t
);
578 pp_c_parameter_type_list (this, t
);
579 direct_abstract_declarator (TREE_TYPE (t
));
583 pp_c_left_bracket (this);
584 if (TYPE_DOMAIN (t
) && TYPE_MAX_VALUE (TYPE_DOMAIN (t
)))
586 tree maxval
= TYPE_MAX_VALUE (TYPE_DOMAIN (t
));
587 tree type
= TREE_TYPE (maxval
);
589 if (host_integerp (maxval
, 0))
590 pp_wide_integer (this, tree_low_cst (maxval
, 0) + 1);
592 expression (fold_build2 (PLUS_EXPR
, type
, maxval
,
593 build_int_cst (type
, 1)));
595 pp_c_right_bracket (this);
596 direct_abstract_declarator (TREE_TYPE (t
));
599 case IDENTIFIER_NODE
:
604 case FIXED_POINT_TYPE
:
614 pp_unsupported_tree (this, t
);
620 specifier-qualifier-list abstract-declarator(opt) */
623 c_pretty_printer::type_id (tree t
)
625 pp_c_specifier_qualifier_list (this, t
);
626 abstract_declarator (t
);
629 /* storage-class-specifier:
637 c_pretty_printer::storage_class_specifier (tree t
)
639 if (TREE_CODE (t
) == TYPE_DECL
)
640 pp_c_ws_string (this, "typedef");
643 if (DECL_REGISTER (t
))
644 pp_c_ws_string (this, "register");
645 else if (TREE_STATIC (t
) && TREE_CODE (t
) == VAR_DECL
)
646 pp_c_ws_string (this, "static");
650 /* function-specifier:
654 c_pretty_printer::function_specifier (tree t
)
656 if (TREE_CODE (t
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (t
))
657 pp_c_ws_string (this, "inline");
660 /* declaration-specifiers:
661 storage-class-specifier declaration-specifiers(opt)
662 type-specifier declaration-specifiers(opt)
663 type-qualifier declaration-specifiers(opt)
664 function-specifier declaration-specifiers(opt) */
667 c_pretty_printer::declaration_specifiers (tree t
)
669 storage_class_specifier (t
);
670 function_specifier (t
);
671 pp_c_specifier_qualifier_list (this, DECL_P (t
) ? TREE_TYPE (t
) : t
);
677 direct-declarator [ type-qualifier-list(opt) assignment-expression(opt) ]
678 direct-declarator [ static type-qualifier-list(opt) assignment-expression(opt)]
679 direct-declarator [ type-qualifier-list static assignment-expression ]
680 direct-declarator [ type-qualifier-list * ]
681 direct-declarator ( parameter-type-list )
682 direct-declarator ( identifier-list(opt) ) */
685 c_pretty_printer::direct_declarator (tree t
)
687 switch (TREE_CODE (t
))
694 pp_c_space_for_pointer_operator (this, TREE_TYPE (t
));
695 pp_c_tree_decl_identifier (this, t
);
700 abstract_declarator (TREE_TYPE (t
));
704 pp_parameter_list (this, t
);
705 abstract_declarator (TREE_TYPE (t
));
709 pp_c_space_for_pointer_operator (this, TREE_TYPE (TREE_TYPE (t
)));
710 pp_c_tree_decl_identifier (this, t
);
711 if (flags
& pp_c_flag_abstract
)
712 abstract_declarator (TREE_TYPE (t
));
715 pp_parameter_list (this, t
);
716 abstract_declarator (TREE_TYPE (TREE_TYPE (t
)));
722 case FIXED_POINT_TYPE
:
729 pp_unsupported_tree (this, t
);
736 pointer(opt) direct-declarator */
739 c_pretty_printer::declarator (tree t
)
741 switch (TREE_CODE (t
))
745 case FIXED_POINT_TYPE
:
758 direct_declarator (t
);
763 pp_unsupported_tree (this, t
);
769 declaration-specifiers init-declarator-list(opt) ; */
772 c_pretty_printer::declaration (tree t
)
774 declaration_specifiers (t
);
775 pp_c_init_declarator (this, t
);
778 /* Pretty-print ATTRIBUTES using GNU C extension syntax. */
781 pp_c_attributes (c_pretty_printer
*pp
, tree attributes
)
783 if (attributes
== NULL_TREE
)
786 pp_c_ws_string (pp
, "__attribute__");
787 pp_c_left_paren (pp
);
788 pp_c_left_paren (pp
);
789 for (; attributes
!= NULL_TREE
; attributes
= TREE_CHAIN (attributes
))
791 pp_tree_identifier (pp
, TREE_PURPOSE (attributes
));
792 if (TREE_VALUE (attributes
))
793 pp_c_call_argument_list (pp
, TREE_VALUE (attributes
));
795 if (TREE_CHAIN (attributes
))
796 pp_separate_with (pp
, ',');
798 pp_c_right_paren (pp
);
799 pp_c_right_paren (pp
);
802 /* Pretty-print ATTRIBUTES using GNU C extension syntax for attributes
803 marked to be displayed on disgnostic. */
806 pp_c_attributes_display (c_pretty_printer
*pp
, tree a
)
808 bool is_first
= true;
813 for (; a
!= NULL_TREE
; a
= TREE_CHAIN (a
))
815 const struct attribute_spec
*as
;
816 as
= lookup_attribute_spec (TREE_PURPOSE (a
));
817 if (!as
|| as
->affects_type_identity
== false)
821 pp_c_ws_string (pp
, "__attribute__");
822 pp_c_left_paren (pp
);
823 pp_c_left_paren (pp
);
828 pp_separate_with (pp
, ',');
830 pp_tree_identifier (pp
, TREE_PURPOSE (a
));
832 pp_c_call_argument_list (pp
, TREE_VALUE (a
));
837 pp_c_right_paren (pp
);
838 pp_c_right_paren (pp
);
839 pp_c_whitespace (pp
);
843 /* function-definition:
844 declaration-specifiers declarator compound-statement */
847 pp_c_function_definition (c_pretty_printer
*pp
, tree t
)
849 pp
->declaration_specifiers (t
);
851 pp_needs_newline (pp
) = true;
852 pp
->statement (DECL_SAVED_TREE (t
));
853 pp_newline_and_flush (pp
);
859 /* Print out a c-char. This is called solely for characters which are
860 in the *target* execution character set. We ought to convert them
861 back to the *host* execution character set before printing, but we
862 have no way to do this at present. A decent compromise is to print
863 all characters as if they were in the host execution character set,
864 and not attempt to recover any named escape characters, but render
865 all unprintables as octal escapes. If the host and target character
866 sets are the same, this produces relatively readable output. If they
867 are not the same, strings may appear as gibberish, but that's okay
868 (in fact, it may well be what the reader wants, e.g. if they are looking
869 to see if conversion to the target character set happened correctly).
871 A special case: we need to prefix \, ", and ' with backslashes. It is
872 correct to do so for the *host*'s \, ", and ', because the rest of the
873 file appears in the host character set. */
876 pp_c_char (c_pretty_printer
*pp
, int c
)
882 case '\\': pp_string (pp
, "\\\\"); break;
883 case '\'': pp_string (pp
, "\\\'"); break;
884 case '\"': pp_string (pp
, "\\\""); break;
885 default: pp_character (pp
, c
);
889 pp_scalar (pp
, "\\%03o", (unsigned) c
);
892 /* Print out a STRING literal. */
895 pp_c_string_literal (c_pretty_printer
*pp
, tree s
)
897 const char *p
= TREE_STRING_POINTER (s
);
898 int n
= TREE_STRING_LENGTH (s
) - 1;
901 for (i
= 0; i
< n
; ++i
)
902 pp_c_char (pp
, p
[i
]);
906 /* Pretty-print an INTEGER literal. */
909 pp_c_integer_constant (c_pretty_printer
*pp
, tree i
)
911 /* We are going to compare the type of I to other types using
912 pointer comparison so we need to use its canonical type. */
914 TYPE_CANONICAL (TREE_TYPE (i
))
915 ? TYPE_CANONICAL (TREE_TYPE (i
))
918 if (host_integerp (i
, 0))
919 pp_wide_integer (pp
, TREE_INT_CST_LOW (i
));
920 else if (host_integerp (i
, 1))
921 pp_unsigned_wide_integer (pp
, TREE_INT_CST_LOW (i
));
924 unsigned HOST_WIDE_INT low
= TREE_INT_CST_LOW (i
);
925 HOST_WIDE_INT high
= TREE_INT_CST_HIGH (i
);
926 if (tree_int_cst_sgn (i
) < 0)
932 sprintf (pp_buffer (pp
)->digit_buffer
, HOST_WIDE_INT_PRINT_DOUBLE_HEX
,
933 (unsigned HOST_WIDE_INT
) high
, (unsigned HOST_WIDE_INT
) low
);
934 pp_string (pp
, pp_buffer (pp
)->digit_buffer
);
936 if (TYPE_UNSIGNED (type
))
937 pp_character (pp
, 'u');
938 if (type
== long_integer_type_node
|| type
== long_unsigned_type_node
)
939 pp_character (pp
, 'l');
940 else if (type
== long_long_integer_type_node
941 || type
== long_long_unsigned_type_node
)
942 pp_string (pp
, "ll");
943 else if (type
== int128_integer_type_node
944 || type
== int128_unsigned_type_node
)
945 pp_string (pp
, "I128");
948 /* Print out a CHARACTER literal. */
951 pp_c_character_constant (c_pretty_printer
*pp
, tree c
)
954 pp_c_char (pp
, (unsigned) TREE_INT_CST_LOW (c
));
958 /* Print out a BOOLEAN literal. */
961 pp_c_bool_constant (c_pretty_printer
*pp
, tree b
)
963 if (b
== boolean_false_node
)
965 if (c_dialect_cxx ())
966 pp_c_ws_string (pp
, "false");
967 else if (flag_isoc99
)
968 pp_c_ws_string (pp
, "_False");
970 pp_unsupported_tree (pp
, b
);
972 else if (b
== boolean_true_node
)
974 if (c_dialect_cxx ())
975 pp_c_ws_string (pp
, "true");
976 else if (flag_isoc99
)
977 pp_c_ws_string (pp
, "_True");
979 pp_unsupported_tree (pp
, b
);
981 else if (TREE_CODE (b
) == INTEGER_CST
)
982 pp_c_integer_constant (pp
, b
);
984 pp_unsupported_tree (pp
, b
);
987 /* Attempt to print out an ENUMERATOR. Return true on success. Else return
988 false; that means the value was obtained by a cast, in which case
989 print out the type-id part of the cast-expression -- the casted value
990 is then printed by pp_c_integer_literal. */
993 pp_c_enumeration_constant (c_pretty_printer
*pp
, tree e
)
995 bool value_is_named
= true;
996 tree type
= TREE_TYPE (e
);
999 /* Find the name of this constant. */
1000 for (value
= TYPE_VALUES (type
);
1001 value
!= NULL_TREE
&& !tree_int_cst_equal (TREE_VALUE (value
), e
);
1002 value
= TREE_CHAIN (value
))
1005 if (value
!= NULL_TREE
)
1006 pp
->id_expression (TREE_PURPOSE (value
));
1009 /* Value must have been cast. */
1010 pp_c_type_cast (pp
, type
);
1011 value_is_named
= false;
1014 return value_is_named
;
1017 /* Print out a REAL value as a decimal-floating-constant. */
1020 pp_c_floating_constant (c_pretty_printer
*pp
, tree r
)
1022 const struct real_format
*fmt
1023 = REAL_MODE_FORMAT (TYPE_MODE (TREE_TYPE (r
)));
1025 REAL_VALUE_TYPE floating_cst
= TREE_REAL_CST (r
);
1026 bool is_decimal
= floating_cst
.decimal
;
1028 /* See ISO C++ WG N1822. Note: The fraction 643/2136 approximates
1029 log10(2) to 7 significant digits. */
1030 int max_digits10
= 2 + (is_decimal
? fmt
->p
: fmt
->p
* 643L / 2136);
1032 real_to_decimal (pp_buffer (pp
)->digit_buffer
, &TREE_REAL_CST (r
),
1033 sizeof (pp_buffer (pp
)->digit_buffer
),
1036 pp_string (pp
, pp_buffer(pp
)->digit_buffer
);
1037 if (TREE_TYPE (r
) == float_type_node
)
1038 pp_character (pp
, 'f');
1039 else if (TREE_TYPE (r
) == long_double_type_node
)
1040 pp_character (pp
, 'l');
1041 else if (TREE_TYPE (r
) == dfloat128_type_node
)
1042 pp_string (pp
, "dl");
1043 else if (TREE_TYPE (r
) == dfloat64_type_node
)
1044 pp_string (pp
, "dd");
1045 else if (TREE_TYPE (r
) == dfloat32_type_node
)
1046 pp_string (pp
, "df");
1049 /* Print out a FIXED value as a decimal-floating-constant. */
1052 pp_c_fixed_constant (c_pretty_printer
*pp
, tree r
)
1054 fixed_to_decimal (pp_buffer (pp
)->digit_buffer
, &TREE_FIXED_CST (r
),
1055 sizeof (pp_buffer (pp
)->digit_buffer
));
1056 pp_string (pp
, pp_buffer(pp
)->digit_buffer
);
1059 /* Pretty-print a compound literal expression. GNU extensions include
1060 vector constants. */
1063 pp_c_compound_literal (c_pretty_printer
*pp
, tree e
)
1065 tree type
= TREE_TYPE (e
);
1066 pp_c_type_cast (pp
, type
);
1068 switch (TREE_CODE (type
))
1075 pp_c_brace_enclosed_initializer_list (pp
, e
);
1079 pp_unsupported_tree (pp
, e
);
1084 /* Pretty-print a COMPLEX_EXPR expression. */
1087 pp_c_complex_expr (c_pretty_printer
*pp
, tree e
)
1089 /* Handle a few common special cases, otherwise fallback
1090 to printing it as compound literal. */
1091 tree type
= TREE_TYPE (e
);
1092 tree realexpr
= TREE_OPERAND (e
, 0);
1093 tree imagexpr
= TREE_OPERAND (e
, 1);
1095 /* Cast of an COMPLEX_TYPE expression to a different COMPLEX_TYPE. */
1096 if (TREE_CODE (realexpr
) == NOP_EXPR
1097 && TREE_CODE (imagexpr
) == NOP_EXPR
1098 && TREE_TYPE (realexpr
) == TREE_TYPE (type
)
1099 && TREE_TYPE (imagexpr
) == TREE_TYPE (type
)
1100 && TREE_CODE (TREE_OPERAND (realexpr
, 0)) == REALPART_EXPR
1101 && TREE_CODE (TREE_OPERAND (imagexpr
, 0)) == IMAGPART_EXPR
1102 && TREE_OPERAND (TREE_OPERAND (realexpr
, 0), 0)
1103 == TREE_OPERAND (TREE_OPERAND (imagexpr
, 0), 0))
1105 pp_c_type_cast (pp
, type
);
1106 pp
->expression (TREE_OPERAND (TREE_OPERAND (realexpr
, 0), 0));
1110 /* Cast of an scalar expression to COMPLEX_TYPE. */
1111 if ((integer_zerop (imagexpr
) || real_zerop (imagexpr
))
1112 && TREE_TYPE (realexpr
) == TREE_TYPE (type
))
1114 pp_c_type_cast (pp
, type
);
1115 if (TREE_CODE (realexpr
) == NOP_EXPR
)
1116 realexpr
= TREE_OPERAND (realexpr
, 0);
1117 pp
->expression (realexpr
);
1121 pp_c_compound_literal (pp
, e
);
1127 fixed-point-constant
1128 enumeration-constant
1129 character-constant */
1132 c_pretty_printer::constant (tree e
)
1134 const enum tree_code code
= TREE_CODE (e
);
1140 tree type
= TREE_TYPE (e
);
1141 if (type
== boolean_type_node
)
1142 pp_c_bool_constant (this, e
);
1143 else if (type
== char_type_node
)
1144 pp_c_character_constant (this, e
);
1145 else if (TREE_CODE (type
) == ENUMERAL_TYPE
1146 && pp_c_enumeration_constant (this, e
))
1149 pp_c_integer_constant (this, e
);
1154 pp_c_floating_constant (this, e
);
1158 pp_c_fixed_constant (this, e
);
1162 pp_c_string_literal (this, e
);
1166 /* Sometimes, we are confused and we think a complex literal
1167 is a constant. Such thing is a compound literal which
1168 grammatically belongs to postfix-expr production. */
1169 pp_c_compound_literal (this, e
);
1173 pp_unsupported_tree (this, e
);
1178 /* Pretty-print a string such as an identifier, without changing its
1179 encoding, preceded by whitespace is necessary. */
1182 pp_c_ws_string (c_pretty_printer
*pp
, const char *str
)
1184 pp_c_maybe_whitespace (pp
);
1185 pp_string (pp
, str
);
1186 pp
->padding
= pp_before
;
1190 c_pretty_printer::translate_string (const char *gmsgid
)
1192 if (pp_translate_identifiers (this))
1193 pp_c_ws_string (this, _(gmsgid
));
1195 pp_c_ws_string (this, gmsgid
);
1198 /* Pretty-print an IDENTIFIER_NODE, which may contain UTF-8 sequences
1199 that need converting to the locale encoding, preceded by whitespace
1203 pp_c_identifier (c_pretty_printer
*pp
, const char *id
)
1205 pp_c_maybe_whitespace (pp
);
1206 pp_identifier (pp
, id
);
1207 pp
->padding
= pp_before
;
1210 /* Pretty-print a C primary-expression.
1218 c_pretty_printer::primary_expression (tree e
)
1220 switch (TREE_CODE (e
))
1228 pp_c_tree_decl_identifier (this, e
);
1231 case IDENTIFIER_NODE
:
1232 pp_c_tree_identifier (this, e
);
1236 translate_string ("<erroneous-expression>");
1240 translate_string ("<return-value>");
1251 pp_c_ws_string (this, "__builtin_memcpy");
1252 pp_c_left_paren (this);
1253 pp_ampersand (this);
1254 primary_expression (TREE_OPERAND (e
, 0));
1255 pp_separate_with (this, ',');
1256 pp_ampersand (this);
1257 initializer (TREE_OPERAND (e
, 1));
1258 if (TREE_OPERAND (e
, 2))
1260 pp_separate_with (this, ',');
1261 expression (TREE_OPERAND (e
, 2));
1263 pp_c_right_paren (this);
1267 /* FIXME: Make sure we won't get into an infinite loop. */
1268 pp_c_left_paren (this);
1270 pp_c_right_paren (this);
1275 /* Print out a C initializer -- also support C compound-literals.
1277 assignment-expression:
1278 { initializer-list }
1279 { initializer-list , } */
1282 c_pretty_printer::initializer (tree e
)
1284 if (TREE_CODE (e
) == CONSTRUCTOR
)
1285 pp_c_brace_enclosed_initializer_list (this, e
);
1292 declarator = initializer */
1295 pp_c_init_declarator (c_pretty_printer
*pp
, tree t
)
1298 /* We don't want to output function definitions here. There are handled
1299 elsewhere (and the syntactic form is bogus anyway). */
1300 if (TREE_CODE (t
) != FUNCTION_DECL
&& DECL_INITIAL (t
))
1302 tree init
= DECL_INITIAL (t
);
1303 /* This C++ bit is handled here because it is easier to do so.
1304 In templates, the C++ parser builds a TREE_LIST for a
1305 direct-initialization; the TREE_PURPOSE is the variable to
1306 initialize and the TREE_VALUE is the initializer. */
1307 if (TREE_CODE (init
) == TREE_LIST
)
1309 pp_c_left_paren (pp
);
1310 pp
->expression (TREE_VALUE (init
));
1311 pp_right_paren (pp
);
1318 pp
->initializer (init
);
1323 /* initializer-list:
1324 designation(opt) initializer
1325 initializer-list , designation(opt) initializer
1332 designator-list designator
1335 [ constant-expression ]
1339 pp_c_initializer_list (c_pretty_printer
*pp
, tree e
)
1341 tree type
= TREE_TYPE (e
);
1342 const enum tree_code code
= TREE_CODE (type
);
1344 if (TREE_CODE (e
) == CONSTRUCTOR
)
1346 pp_c_constructor_elts (pp
, CONSTRUCTOR_ELTS (e
));
1356 tree init
= TREE_OPERAND (e
, 0);
1357 for (; init
!= NULL_TREE
; init
= TREE_CHAIN (init
))
1359 if (code
== RECORD_TYPE
|| code
== UNION_TYPE
)
1362 pp
->primary_expression (TREE_PURPOSE (init
));
1366 pp_c_left_bracket (pp
);
1367 if (TREE_PURPOSE (init
))
1368 pp
->constant (TREE_PURPOSE (init
));
1369 pp_c_right_bracket (pp
);
1371 pp_c_whitespace (pp
);
1373 pp_c_whitespace (pp
);
1374 pp
->initializer (TREE_VALUE (init
));
1375 if (TREE_CHAIN (init
))
1376 pp_separate_with (pp
, ',');
1382 if (TREE_CODE (e
) == VECTOR_CST
)
1385 for (i
= 0; i
< VECTOR_CST_NELTS (e
); ++i
)
1388 pp_separate_with (pp
, ',');
1389 pp
->expression (VECTOR_CST_ELT (e
, i
));
1397 if (TREE_CODE (e
) == COMPLEX_CST
|| TREE_CODE (e
) == COMPLEX_EXPR
)
1399 const bool cst
= TREE_CODE (e
) == COMPLEX_CST
;
1400 pp
->expression (cst
? TREE_REALPART (e
) : TREE_OPERAND (e
, 0));
1401 pp_separate_with (pp
, ',');
1402 pp
->expression (cst
? TREE_IMAGPART (e
) : TREE_OPERAND (e
, 1));
1412 pp_unsupported_tree (pp
, type
);
1415 /* Pretty-print a brace-enclosed initializer-list. */
1418 pp_c_brace_enclosed_initializer_list (c_pretty_printer
*pp
, tree l
)
1420 pp_c_left_brace (pp
);
1421 pp_c_initializer_list (pp
, l
);
1422 pp_c_right_brace (pp
);
1426 /* This is a convenient function, used to bridge gap between C and C++
1433 c_pretty_printer::id_expression (tree t
)
1435 switch (TREE_CODE (t
))
1444 pp_c_tree_decl_identifier (this, t
);
1447 case IDENTIFIER_NODE
:
1448 pp_c_tree_identifier (this, t
);
1452 pp_unsupported_tree (this, t
);
1457 /* postfix-expression:
1459 postfix-expression [ expression ]
1460 postfix-expression ( argument-expression-list(opt) )
1461 postfix-expression . identifier
1462 postfix-expression -> identifier
1463 postfix-expression ++
1464 postfix-expression --
1465 ( type-name ) { initializer-list }
1466 ( type-name ) { initializer-list , } */
1469 c_pretty_printer::postfix_expression (tree e
)
1471 enum tree_code code
= TREE_CODE (e
);
1474 case POSTINCREMENT_EXPR
:
1475 case POSTDECREMENT_EXPR
:
1476 postfix_expression (TREE_OPERAND (e
, 0));
1477 pp_string (this, code
== POSTINCREMENT_EXPR
? "++" : "--");
1481 postfix_expression (TREE_OPERAND (e
, 0));
1482 pp_c_left_bracket (this);
1483 expression (TREE_OPERAND (e
, 1));
1484 pp_c_right_bracket (this);
1487 case ARRAY_NOTATION_REF
:
1488 postfix_expression (ARRAY_NOTATION_ARRAY (e
));
1489 pp_c_left_bracket (this);
1490 expression (ARRAY_NOTATION_START (e
));
1492 expression (ARRAY_NOTATION_LENGTH (e
));
1494 expression (ARRAY_NOTATION_STRIDE (e
));
1495 pp_c_right_bracket (this);
1500 call_expr_arg_iterator iter
;
1502 postfix_expression (CALL_EXPR_FN (e
));
1503 pp_c_left_paren (this);
1504 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, e
)
1507 if (more_call_expr_args_p (&iter
))
1508 pp_separate_with (this, ',');
1510 pp_c_right_paren (this);
1514 case UNORDERED_EXPR
:
1515 pp_c_ws_string (this, flag_isoc99
1517 : "__builtin_isunordered");
1521 pp_c_ws_string (this, flag_isoc99
1523 : "!__builtin_isunordered");
1527 pp_c_ws_string (this, flag_isoc99
1529 : "!__builtin_isgreaterequal");
1533 pp_c_ws_string (this, flag_isoc99
1535 : "!__builtin_isgreater");
1539 pp_c_ws_string (this, flag_isoc99
1541 : "!__builtin_islessequal");
1545 pp_c_ws_string (this, flag_isoc99
1547 : "!__builtin_isless");
1551 pp_c_ws_string (this, flag_isoc99
1553 : "!__builtin_islessgreater");
1557 pp_c_ws_string (this, flag_isoc99
1559 : "__builtin_islessgreater");
1563 pp_c_left_paren (this);
1564 expression (TREE_OPERAND (e
, 0));
1565 pp_separate_with (this, ',');
1566 expression (TREE_OPERAND (e
, 1));
1567 pp_c_right_paren (this);
1571 pp_c_ws_string (this, "__builtin_abs");
1572 pp_c_left_paren (this);
1573 expression (TREE_OPERAND (e
, 0));
1574 pp_c_right_paren (this);
1579 tree object
= TREE_OPERAND (e
, 0);
1580 if (TREE_CODE (object
) == INDIRECT_REF
)
1582 postfix_expression (TREE_OPERAND (object
, 0));
1587 postfix_expression (object
);
1590 expression (TREE_OPERAND (e
, 1));
1596 tree type
= TREE_TYPE (e
);
1598 type
= signed_or_unsigned_type_for (TYPE_UNSIGNED (type
), type
);
1600 && tree_int_cst_equal (TYPE_SIZE (type
), TREE_OPERAND (e
, 1)))
1602 HOST_WIDE_INT bitpos
= tree_low_cst (TREE_OPERAND (e
, 2), 0);
1603 HOST_WIDE_INT size
= tree_low_cst (TYPE_SIZE (type
), 0);
1604 if ((bitpos
% size
) == 0)
1606 pp_c_left_paren (this);
1607 pp_c_left_paren (this);
1610 pp_c_right_paren (this);
1611 pp_c_ampersand (this);
1612 expression (TREE_OPERAND (e
, 0));
1613 pp_c_right_paren (this);
1614 pp_c_left_bracket (this);
1615 pp_wide_integer (this, bitpos
/ size
);
1616 pp_c_right_bracket (this);
1620 pp_unsupported_tree (this, e
);
1630 pp_c_compound_literal (this, e
);
1634 pp_c_complex_expr (this, e
);
1637 case COMPOUND_LITERAL_EXPR
:
1638 e
= DECL_INITIAL (COMPOUND_LITERAL_EXPR_DECL (e
));
1645 pp_c_ws_string (this, "__builtin_va_arg");
1646 pp_c_left_paren (this);
1647 assignment_expression (TREE_OPERAND (e
, 0));
1648 pp_separate_with (this, ',');
1649 type_id (TREE_TYPE (e
));
1650 pp_c_right_paren (this);
1654 if (TREE_CODE (TREE_OPERAND (e
, 0)) == FUNCTION_DECL
)
1656 id_expression (TREE_OPERAND (e
, 0));
1659 /* else fall through. */
1662 primary_expression (e
);
1667 /* Print out an expression-list; E is expected to be a TREE_LIST. */
1670 pp_c_expression_list (c_pretty_printer
*pp
, tree e
)
1672 for (; e
!= NULL_TREE
; e
= TREE_CHAIN (e
))
1674 pp
->expression (TREE_VALUE (e
));
1676 pp_separate_with (pp
, ',');
1680 /* Print out V, which contains the elements of a constructor. */
1683 pp_c_constructor_elts (c_pretty_printer
*pp
, vec
<constructor_elt
, va_gc
> *v
)
1685 unsigned HOST_WIDE_INT ix
;
1688 FOR_EACH_CONSTRUCTOR_VALUE (v
, ix
, value
)
1690 pp
->expression (value
);
1691 if (ix
!= vec_safe_length (v
) - 1)
1692 pp_separate_with (pp
, ',');
1696 /* Print out an expression-list in parens, as if it were the argument
1697 list to a function. */
1700 pp_c_call_argument_list (c_pretty_printer
*pp
, tree t
)
1702 pp_c_left_paren (pp
);
1703 if (t
&& TREE_CODE (t
) == TREE_LIST
)
1704 pp_c_expression_list (pp
, t
);
1705 pp_c_right_paren (pp
);
1708 /* unary-expression:
1712 unary-operator cast-expression
1713 sizeof unary-expression
1716 unary-operator: one of
1721 __alignof__ unary-expression
1722 __alignof__ ( type-id )
1723 __real__ unary-expression
1724 __imag__ unary-expression */
1727 c_pretty_printer::unary_expression (tree e
)
1729 enum tree_code code
= TREE_CODE (e
);
1732 case PREINCREMENT_EXPR
:
1733 case PREDECREMENT_EXPR
:
1734 pp_string (this, code
== PREINCREMENT_EXPR
? "++" : "--");
1735 unary_expression (TREE_OPERAND (e
, 0));
1742 case TRUTH_NOT_EXPR
:
1744 /* String literal are used by address. */
1745 if (code
== ADDR_EXPR
&& TREE_CODE (TREE_OPERAND (e
, 0)) != STRING_CST
)
1746 pp_ampersand (this);
1747 else if (code
== INDIRECT_REF
)
1749 else if (code
== NEGATE_EXPR
)
1751 else if (code
== BIT_NOT_EXPR
|| code
== CONJ_EXPR
)
1752 pp_complement (this);
1753 else if (code
== TRUTH_NOT_EXPR
)
1754 pp_exclamation (this);
1755 pp_c_cast_expression (this, TREE_OPERAND (e
, 0));
1759 if (TREE_CODE (TREE_OPERAND (e
, 0)) == ADDR_EXPR
1760 && integer_zerop (TREE_OPERAND (e
, 1)))
1761 expression (TREE_OPERAND (TREE_OPERAND (e
, 0), 0));
1765 if (!integer_zerop (TREE_OPERAND (e
, 1)))
1767 pp_c_left_paren (this);
1768 if (!integer_onep (TYPE_SIZE_UNIT
1769 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (e
, 0))))))
1770 pp_c_type_cast (this, ptr_type_node
);
1772 pp_c_cast_expression (this, TREE_OPERAND (e
, 0));
1773 if (!integer_zerop (TREE_OPERAND (e
, 1)))
1776 pp_c_integer_constant (this,
1777 fold_convert (ssizetype
,
1778 TREE_OPERAND (e
, 1)));
1779 pp_c_right_paren (this);
1786 pp_c_ws_string (this, code
== REALPART_EXPR
? "__real__" : "__imag__");
1787 pp_c_whitespace (this);
1788 unary_expression (TREE_OPERAND (e
, 0));
1792 postfix_expression (e
);
1799 ( type-name ) cast-expression */
1802 pp_c_cast_expression (c_pretty_printer
*pp
, tree e
)
1804 switch (TREE_CODE (e
))
1807 case FIX_TRUNC_EXPR
:
1809 case VIEW_CONVERT_EXPR
:
1810 pp_c_type_cast (pp
, TREE_TYPE (e
));
1811 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 0));
1815 pp
->unary_expression (e
);
1819 /* multiplicative-expression:
1821 multiplicative-expression * cast-expression
1822 multiplicative-expression / cast-expression
1823 multiplicative-expression % cast-expression */
1826 c_pretty_printer::multiplicative_expression (tree e
)
1828 enum tree_code code
= TREE_CODE (e
);
1832 case TRUNC_DIV_EXPR
:
1833 case TRUNC_MOD_EXPR
:
1834 multiplicative_expression (TREE_OPERAND (e
, 0));
1835 pp_c_whitespace (this);
1836 if (code
== MULT_EXPR
)
1838 else if (code
== TRUNC_DIV_EXPR
)
1842 pp_c_whitespace (this);
1843 pp_c_cast_expression (this, TREE_OPERAND (e
, 1));
1847 pp_c_cast_expression (this, e
);
1852 /* additive-expression:
1853 multiplicative-expression
1854 additive-expression + multiplicative-expression
1855 additive-expression - multiplicative-expression */
1858 pp_c_additive_expression (c_pretty_printer
*pp
, tree e
)
1860 enum tree_code code
= TREE_CODE (e
);
1863 case POINTER_PLUS_EXPR
:
1866 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 0));
1867 pp_c_whitespace (pp
);
1868 if (code
== PLUS_EXPR
|| code
== POINTER_PLUS_EXPR
)
1872 pp_c_whitespace (pp
);
1873 pp
->multiplicative_expression (TREE_OPERAND (e
, 1));
1877 pp
->multiplicative_expression (e
);
1882 /* additive-expression:
1884 shift-expression << additive-expression
1885 shift-expression >> additive-expression */
1888 pp_c_shift_expression (c_pretty_printer
*pp
, tree e
)
1890 enum tree_code code
= TREE_CODE (e
);
1895 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 0));
1896 pp_c_whitespace (pp
);
1897 pp_string (pp
, code
== LSHIFT_EXPR
? "<<" : ">>");
1898 pp_c_whitespace (pp
);
1899 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 1));
1903 pp_c_additive_expression (pp
, e
);
1907 /* relational-expression:
1909 relational-expression < shift-expression
1910 relational-expression > shift-expression
1911 relational-expression <= shift-expression
1912 relational-expression >= shift-expression */
1915 pp_c_relational_expression (c_pretty_printer
*pp
, tree e
)
1917 enum tree_code code
= TREE_CODE (e
);
1924 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 0));
1925 pp_c_whitespace (pp
);
1926 if (code
== LT_EXPR
)
1928 else if (code
== GT_EXPR
)
1930 else if (code
== LE_EXPR
)
1932 else if (code
== GE_EXPR
)
1933 pp_greater_equal (pp
);
1934 pp_c_whitespace (pp
);
1935 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 1));
1939 pp_c_shift_expression (pp
, e
);
1944 /* equality-expression:
1945 relational-expression
1946 equality-expression == relational-expression
1947 equality-equality != relational-expression */
1950 pp_c_equality_expression (c_pretty_printer
*pp
, tree e
)
1952 enum tree_code code
= TREE_CODE (e
);
1957 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 0));
1958 pp_c_whitespace (pp
);
1959 pp_string (pp
, code
== EQ_EXPR
? "==" : "!=");
1960 pp_c_whitespace (pp
);
1961 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 1));
1965 pp_c_relational_expression (pp
, e
);
1972 AND-expression & equality-equality */
1975 pp_c_and_expression (c_pretty_printer
*pp
, tree e
)
1977 if (TREE_CODE (e
) == BIT_AND_EXPR
)
1979 pp_c_and_expression (pp
, TREE_OPERAND (e
, 0));
1980 pp_c_whitespace (pp
);
1982 pp_c_whitespace (pp
);
1983 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 1));
1986 pp_c_equality_expression (pp
, e
);
1989 /* exclusive-OR-expression:
1991 exclusive-OR-expression ^ AND-expression */
1994 pp_c_exclusive_or_expression (c_pretty_printer
*pp
, tree e
)
1996 if (TREE_CODE (e
) == BIT_XOR_EXPR
1997 || TREE_CODE (e
) == TRUTH_XOR_EXPR
)
1999 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
2000 if (TREE_CODE (e
) == BIT_XOR_EXPR
)
2001 pp_c_maybe_whitespace (pp
);
2003 pp_c_whitespace (pp
);
2005 pp_c_whitespace (pp
);
2006 pp_c_and_expression (pp
, TREE_OPERAND (e
, 1));
2009 pp_c_and_expression (pp
, e
);
2012 /* inclusive-OR-expression:
2013 exclusive-OR-expression
2014 inclusive-OR-expression | exclusive-OR-expression */
2017 pp_c_inclusive_or_expression (c_pretty_printer
*pp
, tree e
)
2019 if (TREE_CODE (e
) == BIT_IOR_EXPR
)
2021 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
2022 pp_c_whitespace (pp
);
2024 pp_c_whitespace (pp
);
2025 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
2028 pp_c_exclusive_or_expression (pp
, e
);
2031 /* logical-AND-expression:
2032 inclusive-OR-expression
2033 logical-AND-expression && inclusive-OR-expression */
2036 pp_c_logical_and_expression (c_pretty_printer
*pp
, tree e
)
2038 if (TREE_CODE (e
) == TRUTH_ANDIF_EXPR
2039 || TREE_CODE (e
) == TRUTH_AND_EXPR
)
2041 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 0));
2042 pp_c_whitespace (pp
);
2043 pp_ampersand_ampersand (pp
);
2044 pp_c_whitespace (pp
);
2045 pp_c_inclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
2048 pp_c_inclusive_or_expression (pp
, e
);
2051 /* logical-OR-expression:
2052 logical-AND-expression
2053 logical-OR-expression || logical-AND-expression */
2056 pp_c_logical_or_expression (c_pretty_printer
*pp
, tree e
)
2058 if (TREE_CODE (e
) == TRUTH_ORIF_EXPR
2059 || TREE_CODE (e
) == TRUTH_OR_EXPR
)
2061 pp_c_logical_or_expression (pp
, TREE_OPERAND (e
, 0));
2062 pp_c_whitespace (pp
);
2064 pp_c_whitespace (pp
);
2065 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 1));
2068 pp_c_logical_and_expression (pp
, e
);
2071 /* conditional-expression:
2072 logical-OR-expression
2073 logical-OR-expression ? expression : conditional-expression */
2076 c_pretty_printer::conditional_expression (tree e
)
2078 if (TREE_CODE (e
) == COND_EXPR
)
2080 pp_c_logical_or_expression (this, TREE_OPERAND (e
, 0));
2081 pp_c_whitespace (this);
2083 pp_c_whitespace (this);
2084 expression (TREE_OPERAND (e
, 1));
2085 pp_c_whitespace (this);
2087 pp_c_whitespace (this);
2088 conditional_expression (TREE_OPERAND (e
, 2));
2091 pp_c_logical_or_expression (this, e
);
2095 /* assignment-expression:
2096 conditional-expression
2097 unary-expression assignment-operator assignment-expression
2099 assignment-expression: one of
2100 = *= /= %= += -= >>= <<= &= ^= |= */
2103 c_pretty_printer::assignment_expression (tree e
)
2105 if (TREE_CODE (e
) == MODIFY_EXPR
2106 || TREE_CODE (e
) == INIT_EXPR
)
2108 unary_expression (TREE_OPERAND (e
, 0));
2109 pp_c_whitespace (this);
2112 expression (TREE_OPERAND (e
, 1));
2115 conditional_expression (e
);
2119 assignment-expression
2120 expression , assignment-expression
2122 Implementation note: instead of going through the usual recursion
2123 chain, I take the liberty of dispatching nodes to the appropriate
2124 functions. This makes some redundancy, but it worths it. That also
2125 prevents a possible infinite recursion between primary_expression ()
2126 and expression (). */
2129 c_pretty_printer::expression (tree e
)
2131 switch (TREE_CODE (e
))
2134 pp_c_integer_constant (this, e
);
2138 pp_c_floating_constant (this, e
);
2142 pp_c_fixed_constant (this, e
);
2146 pp_c_string_literal (this, e
);
2149 case IDENTIFIER_NODE
:
2158 primary_expression (e
);
2162 if (SSA_NAME_VAR (e
)
2163 && !DECL_ARTIFICIAL (SSA_NAME_VAR (e
)))
2164 expression (SSA_NAME_VAR (e
));
2166 translate_string ("<unknown>");
2169 case POSTINCREMENT_EXPR
:
2170 case POSTDECREMENT_EXPR
:
2172 case ARRAY_NOTATION_REF
:
2180 case UNORDERED_EXPR
:
2189 case COMPOUND_LITERAL_EXPR
:
2191 postfix_expression (e
);
2200 case TRUTH_NOT_EXPR
:
2201 case PREINCREMENT_EXPR
:
2202 case PREDECREMENT_EXPR
:
2205 unary_expression (e
);
2209 case FIX_TRUNC_EXPR
:
2211 case VIEW_CONVERT_EXPR
:
2212 pp_c_cast_expression (this, e
);
2216 case TRUNC_MOD_EXPR
:
2217 case TRUNC_DIV_EXPR
:
2218 multiplicative_expression (e
);
2223 pp_c_shift_expression (this, e
);
2230 pp_c_relational_expression (this, e
);
2234 pp_c_and_expression (this, e
);
2238 case TRUTH_XOR_EXPR
:
2239 pp_c_exclusive_or_expression (this, e
);
2243 pp_c_inclusive_or_expression (this, e
);
2246 case TRUTH_ANDIF_EXPR
:
2247 case TRUTH_AND_EXPR
:
2248 pp_c_logical_and_expression (this, e
);
2251 case TRUTH_ORIF_EXPR
:
2253 pp_c_logical_or_expression (this, e
);
2258 pp_c_equality_expression (this, e
);
2262 conditional_expression (e
);
2265 case POINTER_PLUS_EXPR
:
2268 pp_c_additive_expression (this, e
);
2273 assignment_expression (e
);
2277 pp_c_left_paren (this);
2278 expression (TREE_OPERAND (e
, 0));
2279 pp_separate_with (this, ',');
2280 assignment_expression (TREE_OPERAND (e
, 1));
2281 pp_c_right_paren (this);
2284 case NON_LVALUE_EXPR
:
2286 expression (TREE_OPERAND (e
, 0));
2290 postfix_expression (TREE_OPERAND (e
, 1));
2295 /* We don't yet have a way of dumping statements in a
2296 human-readable format. */
2297 pp_string (this, "({...})");
2300 case C_MAYBE_CONST_EXPR
:
2301 expression (C_MAYBE_CONST_EXPR_EXPR (e
));
2305 pp_unsupported_tree (this, e
);
2315 c_pretty_printer::statement (tree stmt
)
2320 if (pp_needs_newline (this))
2321 pp_newline_and_indent (this, 0);
2323 dump_generic_node (this, stmt
, pp_indentation (this), 0, true);
2327 /* Initialize the PRETTY-PRINTER for handling C codes. */
2329 c_pretty_printer::c_pretty_printer ()
2330 : pretty_printer (),
2334 type_specifier_seq
= pp_c_specifier_qualifier_list
;
2335 ptr_operator
= pp_c_pointer
;
2336 parameter_list
= pp_c_parameter_type_list
;
2340 /* Print the tree T in full, on file FILE. */
2343 print_c_tree (FILE *file
, tree t
)
2345 c_pretty_printer pp
;
2347 pp_needs_newline (&pp
) = true;
2348 pp
.buffer
->stream
= file
;
2350 pp_newline_and_flush (&pp
);
2353 /* Print the tree T in full, on stderr. */
2356 debug_c_tree (tree t
)
2358 print_c_tree (stderr
, t
);
2359 fputc ('\n', stderr
);
2362 /* Output the DECL_NAME of T. If T has no DECL_NAME, output a string made
2363 up of T's memory address. */
2366 pp_c_tree_decl_identifier (c_pretty_printer
*pp
, tree t
)
2370 gcc_assert (DECL_P (t
));
2373 name
= IDENTIFIER_POINTER (DECL_NAME (t
));
2376 static char xname
[8];
2377 sprintf (xname
, "<U%4x>", ((unsigned)((uintptr_t)(t
) & 0xffff)));
2381 pp_c_identifier (pp
, name
);