1 /* Subroutines common to both C and C++ pretty-printers.
2 Copyright (C) 2002-2015 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"
28 #include "stor-layout.h"
31 #include "c-pretty-print.h"
32 #include "tree-pretty-print.h"
33 #include "tree-iterator.h"
34 #include "diagnostic.h"
35 #include "wide-int-print.h"
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)->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_additive_expression (c_pretty_printer
*, tree
);
59 static void pp_c_shift_expression (c_pretty_printer
*, tree
);
60 static void pp_c_relational_expression (c_pretty_printer
*, tree
);
61 static void pp_c_equality_expression (c_pretty_printer
*, tree
);
62 static void pp_c_and_expression (c_pretty_printer
*, tree
);
63 static void pp_c_exclusive_or_expression (c_pretty_printer
*, tree
);
64 static void pp_c_inclusive_or_expression (c_pretty_printer
*, tree
);
65 static void pp_c_logical_and_expression (c_pretty_printer
*, tree
);
70 /* Helper functions. */
73 pp_c_whitespace (c_pretty_printer
*pp
)
76 pp
->padding
= pp_none
;
80 pp_c_left_paren (c_pretty_printer
*pp
)
83 pp
->padding
= pp_none
;
87 pp_c_right_paren (c_pretty_printer
*pp
)
90 pp
->padding
= pp_none
;
94 pp_c_left_brace (c_pretty_printer
*pp
)
97 pp
->padding
= pp_none
;
101 pp_c_right_brace (c_pretty_printer
*pp
)
104 pp
->padding
= pp_none
;
108 pp_c_left_bracket (c_pretty_printer
*pp
)
110 pp_left_bracket (pp
);
111 pp
->padding
= pp_none
;
115 pp_c_right_bracket (c_pretty_printer
*pp
)
117 pp_right_bracket (pp
);
118 pp
->padding
= pp_none
;
122 pp_c_dot (c_pretty_printer
*pp
)
125 pp
->padding
= pp_none
;
129 pp_c_ampersand (c_pretty_printer
*pp
)
132 pp
->padding
= pp_none
;
136 pp_c_star (c_pretty_printer
*pp
)
139 pp
->padding
= pp_none
;
143 pp_c_arrow (c_pretty_printer
*pp
)
146 pp
->padding
= pp_none
;
150 pp_c_semicolon (c_pretty_printer
*pp
)
153 pp
->padding
= pp_none
;
157 pp_c_complement (c_pretty_printer
*pp
)
160 pp
->padding
= pp_none
;
164 pp_c_exclamation (c_pretty_printer
*pp
)
167 pp
->padding
= pp_none
;
170 /* Print out the external representation of QUALIFIERS. */
173 pp_c_cv_qualifiers (c_pretty_printer
*pp
, int qualifiers
, bool func_type
)
175 const char *p
= pp_last_position_in_text (pp
);
180 /* The C programming language does not have references, but it is much
181 simpler to handle those here rather than going through the same
182 logic in the C++ pretty-printer. */
183 if (p
!= NULL
&& (*p
== '*' || *p
== '&'))
184 pp_c_whitespace (pp
);
186 if (qualifiers
& TYPE_QUAL_ATOMIC
)
187 pp_c_ws_string (pp
, "_Atomic");
188 if (qualifiers
& TYPE_QUAL_CONST
)
189 pp_c_ws_string (pp
, func_type
? "__attribute__((const))" : "const");
190 if (qualifiers
& TYPE_QUAL_VOLATILE
)
191 pp_c_ws_string (pp
, func_type
? "__attribute__((noreturn))" : "volatile");
192 if (qualifiers
& TYPE_QUAL_RESTRICT
)
193 pp_c_ws_string (pp
, (flag_isoc99
&& !c_dialect_cxx ()
194 ? "restrict" : "__restrict__"));
197 /* Pretty-print T using the type-cast notation '( type-name )'. */
200 pp_c_type_cast (c_pretty_printer
*pp
, tree t
)
202 pp_c_left_paren (pp
);
204 pp_c_right_paren (pp
);
207 /* We're about to pretty-print a pointer type as indicated by T.
208 Output a whitespace, if needed, preparing for subsequent output. */
211 pp_c_space_for_pointer_operator (c_pretty_printer
*pp
, tree t
)
213 if (POINTER_TYPE_P (t
))
215 tree pointee
= strip_pointer_operator (TREE_TYPE (t
));
216 if (TREE_CODE (pointee
) != ARRAY_TYPE
217 && TREE_CODE (pointee
) != FUNCTION_TYPE
)
218 pp_c_whitespace (pp
);
225 /* C++ cv-qualifiers are called type-qualifiers in C. Print out the
226 cv-qualifiers of T. If T is a declaration then it is the cv-qualifier
227 of its type. Take care of possible extensions.
231 type-qualifier-list type-qualifier
236 __restrict__ -- GNU C
237 address-space-qualifier -- GNU C
241 address-space-qualifier:
242 identifier -- GNU C */
245 pp_c_type_qualifier_list (c_pretty_printer
*pp
, tree t
)
249 if (!t
|| t
== error_mark_node
)
255 qualifiers
= TYPE_QUALS (t
);
256 pp_c_cv_qualifiers (pp
, qualifiers
,
257 TREE_CODE (t
) == FUNCTION_TYPE
);
259 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (t
)))
261 const char *as
= c_addr_space_name (TYPE_ADDR_SPACE (t
));
262 pp_c_identifier (pp
, as
);
267 * type-qualifier-list(opt)
268 * type-qualifier-list(opt) pointer */
271 pp_c_pointer (c_pretty_printer
*pp
, tree t
)
273 if (!TYPE_P (t
) && TREE_CODE (t
) != TYPE_DECL
)
275 switch (TREE_CODE (t
))
278 /* It is easier to handle C++ reference types here. */
280 if (TREE_CODE (TREE_TYPE (t
)) == POINTER_TYPE
)
281 pp_c_pointer (pp
, TREE_TYPE (t
));
282 if (TREE_CODE (t
) == POINTER_TYPE
)
286 pp_c_type_qualifier_list (pp
, t
);
289 /* ??? This node is now in GENERIC and so shouldn't be here. But
290 we'll fix that later. */
292 pp
->declaration (DECL_EXPR_DECL (t
));
293 pp_needs_newline (pp
) = true;
297 pp_unsupported_tree (pp
, t
);
301 /* simple-type-specifier:
317 struct-or-union-specifier
322 simple-type-specifier:
327 c_pretty_printer::simple_type_specifier (tree t
)
329 const enum tree_code code
= TREE_CODE (t
);
333 translate_string ("<type-error>");
336 case IDENTIFIER_NODE
:
337 pp_c_identifier (this, IDENTIFIER_POINTER (t
));
344 case FIXED_POINT_TYPE
:
348 simple_type_specifier (t
);
352 int prec
= TYPE_PRECISION (t
);
353 if (ALL_FIXED_POINT_MODE_P (TYPE_MODE (t
)))
354 t
= c_common_type_for_mode (TYPE_MODE (t
), TYPE_SATURATING (t
));
356 t
= c_common_type_for_mode (TYPE_MODE (t
), TYPE_UNSIGNED (t
));
359 simple_type_specifier (t
);
360 if (TYPE_PRECISION (t
) != prec
)
363 pp_decimal_int (this, prec
);
371 translate_string (TYPE_UNSIGNED (t
)
372 ? "<unnamed-unsigned:"
373 : "<unnamed-signed:");
376 translate_string ("<unnamed-float:");
378 case FIXED_POINT_TYPE
:
379 translate_string ("<unnamed-fixed:");
384 pp_decimal_int (this, prec
);
394 translate_string ("<typedef-error>");
400 if (TYPE_NAME (t
) && TREE_CODE (TYPE_NAME (t
)) == TYPE_DECL
)
401 /* Don't decorate the type if this is a typedef name. */;
402 else if (code
== UNION_TYPE
)
403 pp_c_ws_string (this, "union");
404 else if (code
== RECORD_TYPE
)
405 pp_c_ws_string (this, "struct");
406 else if (code
== ENUMERAL_TYPE
)
407 pp_c_ws_string (this, "enum");
409 translate_string ("<tag-error>");
412 id_expression (TYPE_NAME (t
));
414 translate_string ("<anonymous>");
418 pp_unsupported_tree (this, t
);
423 /* specifier-qualifier-list:
424 type-specifier specifier-qualifier-list-opt
425 type-qualifier specifier-qualifier-list-opt
428 Implementation note: Because of the non-linearities in array or
429 function declarations, this routine prints not just the
430 specifier-qualifier-list of such entities or types of such entities,
431 but also the 'pointer' production part of their declarators. The
432 remaining part is done by declarator() or abstract_declarator(). */
435 pp_c_specifier_qualifier_list (c_pretty_printer
*pp
, tree t
)
437 const enum tree_code code
= TREE_CODE (t
);
439 if (!(pp
->flags
& pp_c_flag_gnu_v3
) && code
!= POINTER_TYPE
)
440 pp_c_type_qualifier_list (pp
, t
);
446 /* Get the types-specifier of this type. */
447 tree pointee
= strip_pointer_operator (TREE_TYPE (t
));
448 pp_c_specifier_qualifier_list (pp
, pointee
);
449 if (TREE_CODE (pointee
) == ARRAY_TYPE
450 || TREE_CODE (pointee
) == FUNCTION_TYPE
)
452 pp_c_whitespace (pp
);
453 pp_c_left_paren (pp
);
454 pp_c_attributes_display (pp
, TYPE_ATTRIBUTES (pointee
));
456 else if (!c_dialect_cxx ())
457 pp_c_whitespace (pp
);
458 pp_ptr_operator (pp
, t
);
464 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
469 if (code
== COMPLEX_TYPE
)
470 pp_c_ws_string (pp
, (flag_isoc99
&& !c_dialect_cxx ()
471 ? "_Complex" : "__complex__"));
472 else if (code
== VECTOR_TYPE
)
474 pp_c_ws_string (pp
, "__vector");
475 pp_c_left_paren (pp
);
476 pp_wide_integer (pp
, TYPE_VECTOR_SUBPARTS (t
));
477 pp_c_right_paren (pp
);
478 pp_c_whitespace (pp
);
480 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
484 pp
->simple_type_specifier (t
);
487 if ((pp
->flags
& pp_c_flag_gnu_v3
) && code
!= POINTER_TYPE
)
488 pp_c_type_qualifier_list (pp
, t
);
491 /* parameter-type-list:
496 parameter-declaration
497 parameter-list , parameter-declaration
499 parameter-declaration:
500 declaration-specifiers declarator
501 declaration-specifiers abstract-declarator(opt) */
504 pp_c_parameter_type_list (c_pretty_printer
*pp
, tree t
)
506 bool want_parm_decl
= DECL_P (t
) && !(pp
->flags
& pp_c_flag_abstract
);
507 tree parms
= want_parm_decl
? DECL_ARGUMENTS (t
) : TYPE_ARG_TYPES (t
);
508 pp_c_left_paren (pp
);
509 if (parms
== void_list_node
)
510 pp_c_ws_string (pp
, "void");
514 for ( ; parms
&& parms
!= void_list_node
; parms
= TREE_CHAIN (parms
))
517 pp_separate_with (pp
, ',');
519 pp
->declaration_specifiers
520 (want_parm_decl
? parms
: TREE_VALUE (parms
));
522 pp
->declarator (parms
);
524 pp
->abstract_declarator (TREE_VALUE (parms
));
527 pp_c_right_paren (pp
);
530 /* abstract-declarator:
532 pointer(opt) direct-abstract-declarator */
535 c_pretty_printer::abstract_declarator (tree t
)
537 if (TREE_CODE (t
) == POINTER_TYPE
)
539 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
540 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
541 pp_c_right_paren (this);
545 direct_abstract_declarator (t
);
548 /* direct-abstract-declarator:
549 ( abstract-declarator )
550 direct-abstract-declarator(opt) [ assignment-expression(opt) ]
551 direct-abstract-declarator(opt) [ * ]
552 direct-abstract-declarator(opt) ( parameter-type-list(opt) ) */
555 c_pretty_printer::direct_abstract_declarator (tree t
)
557 switch (TREE_CODE (t
))
560 abstract_declarator (t
);
564 pp_c_parameter_type_list (this, t
);
565 direct_abstract_declarator (TREE_TYPE (t
));
569 pp_c_left_bracket (this);
570 if (TYPE_DOMAIN (t
) && TYPE_MAX_VALUE (TYPE_DOMAIN (t
)))
572 tree maxval
= TYPE_MAX_VALUE (TYPE_DOMAIN (t
));
573 tree type
= TREE_TYPE (maxval
);
575 if (tree_fits_shwi_p (maxval
))
576 pp_wide_integer (this, tree_to_shwi (maxval
) + 1);
578 expression (fold_build2 (PLUS_EXPR
, type
, maxval
,
579 build_int_cst (type
, 1)));
581 pp_c_right_bracket (this);
582 direct_abstract_declarator (TREE_TYPE (t
));
585 case IDENTIFIER_NODE
:
590 case FIXED_POINT_TYPE
:
600 pp_unsupported_tree (this, t
);
606 specifier-qualifier-list abstract-declarator(opt) */
609 c_pretty_printer::type_id (tree t
)
611 pp_c_specifier_qualifier_list (this, t
);
612 abstract_declarator (t
);
615 /* storage-class-specifier:
623 c_pretty_printer::storage_class_specifier (tree t
)
625 if (TREE_CODE (t
) == TYPE_DECL
)
626 pp_c_ws_string (this, "typedef");
629 if (DECL_REGISTER (t
))
630 pp_c_ws_string (this, "register");
631 else if (TREE_STATIC (t
) && VAR_P (t
))
632 pp_c_ws_string (this, "static");
636 /* function-specifier:
640 c_pretty_printer::function_specifier (tree t
)
642 if (TREE_CODE (t
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (t
))
643 pp_c_ws_string (this, "inline");
646 /* declaration-specifiers:
647 storage-class-specifier declaration-specifiers(opt)
648 type-specifier declaration-specifiers(opt)
649 type-qualifier declaration-specifiers(opt)
650 function-specifier declaration-specifiers(opt) */
653 c_pretty_printer::declaration_specifiers (tree t
)
655 storage_class_specifier (t
);
656 function_specifier (t
);
657 pp_c_specifier_qualifier_list (this, DECL_P (t
) ? TREE_TYPE (t
) : t
);
663 direct-declarator [ type-qualifier-list(opt) assignment-expression(opt) ]
664 direct-declarator [ static type-qualifier-list(opt) assignment-expression(opt)]
665 direct-declarator [ type-qualifier-list static assignment-expression ]
666 direct-declarator [ type-qualifier-list * ]
667 direct-declarator ( parameter-type-list )
668 direct-declarator ( identifier-list(opt) ) */
671 c_pretty_printer::direct_declarator (tree t
)
673 switch (TREE_CODE (t
))
680 pp_c_space_for_pointer_operator (this, TREE_TYPE (t
));
681 pp_c_tree_decl_identifier (this, t
);
686 abstract_declarator (TREE_TYPE (t
));
690 pp_parameter_list (this, t
);
691 abstract_declarator (TREE_TYPE (t
));
695 pp_c_space_for_pointer_operator (this, TREE_TYPE (TREE_TYPE (t
)));
696 pp_c_tree_decl_identifier (this, t
);
697 if (flags
& pp_c_flag_abstract
)
698 abstract_declarator (TREE_TYPE (t
));
701 pp_parameter_list (this, t
);
702 abstract_declarator (TREE_TYPE (TREE_TYPE (t
)));
708 case FIXED_POINT_TYPE
:
715 pp_unsupported_tree (this, t
);
722 pointer(opt) direct-declarator */
725 c_pretty_printer::declarator (tree t
)
727 switch (TREE_CODE (t
))
731 case FIXED_POINT_TYPE
:
744 direct_declarator (t
);
749 pp_unsupported_tree (this, t
);
755 declaration-specifiers init-declarator-list(opt) ; */
758 c_pretty_printer::declaration (tree t
)
760 declaration_specifiers (t
);
761 pp_c_init_declarator (this, t
);
764 /* Pretty-print ATTRIBUTES using GNU C extension syntax. */
767 pp_c_attributes (c_pretty_printer
*pp
, tree attributes
)
769 if (attributes
== NULL_TREE
)
772 pp_c_ws_string (pp
, "__attribute__");
773 pp_c_left_paren (pp
);
774 pp_c_left_paren (pp
);
775 for (; attributes
!= NULL_TREE
; attributes
= TREE_CHAIN (attributes
))
777 pp_tree_identifier (pp
, TREE_PURPOSE (attributes
));
778 if (TREE_VALUE (attributes
))
779 pp_c_call_argument_list (pp
, TREE_VALUE (attributes
));
781 if (TREE_CHAIN (attributes
))
782 pp_separate_with (pp
, ',');
784 pp_c_right_paren (pp
);
785 pp_c_right_paren (pp
);
788 /* Pretty-print ATTRIBUTES using GNU C extension syntax for attributes
789 marked to be displayed on disgnostic. */
792 pp_c_attributes_display (c_pretty_printer
*pp
, tree a
)
794 bool is_first
= true;
799 for (; a
!= NULL_TREE
; a
= TREE_CHAIN (a
))
801 const struct attribute_spec
*as
;
802 as
= lookup_attribute_spec (TREE_PURPOSE (a
));
803 if (!as
|| as
->affects_type_identity
== false)
806 && !strcmp ("transaction_safe", as
->name
))
807 /* In C++ transaction_safe is printed at the end of the declarator. */
811 pp_c_ws_string (pp
, "__attribute__");
812 pp_c_left_paren (pp
);
813 pp_c_left_paren (pp
);
818 pp_separate_with (pp
, ',');
820 pp_tree_identifier (pp
, TREE_PURPOSE (a
));
822 pp_c_call_argument_list (pp
, TREE_VALUE (a
));
827 pp_c_right_paren (pp
);
828 pp_c_right_paren (pp
);
829 pp_c_whitespace (pp
);
833 /* function-definition:
834 declaration-specifiers declarator compound-statement */
837 pp_c_function_definition (c_pretty_printer
*pp
, tree t
)
839 pp
->declaration_specifiers (t
);
841 pp_needs_newline (pp
) = true;
842 pp
->statement (DECL_SAVED_TREE (t
));
843 pp_newline_and_flush (pp
);
849 /* Print out a c-char. This is called solely for characters which are
850 in the *target* execution character set. We ought to convert them
851 back to the *host* execution character set before printing, but we
852 have no way to do this at present. A decent compromise is to print
853 all characters as if they were in the host execution character set,
854 and not attempt to recover any named escape characters, but render
855 all unprintables as octal escapes. If the host and target character
856 sets are the same, this produces relatively readable output. If they
857 are not the same, strings may appear as gibberish, but that's okay
858 (in fact, it may well be what the reader wants, e.g. if they are looking
859 to see if conversion to the target character set happened correctly).
861 A special case: we need to prefix \, ", and ' with backslashes. It is
862 correct to do so for the *host*'s \, ", and ', because the rest of the
863 file appears in the host character set. */
866 pp_c_char (c_pretty_printer
*pp
, int c
)
872 case '\\': pp_string (pp
, "\\\\"); break;
873 case '\'': pp_string (pp
, "\\\'"); break;
874 case '\"': pp_string (pp
, "\\\""); break;
875 default: pp_character (pp
, c
);
879 pp_scalar (pp
, "\\%03o", (unsigned) c
);
882 /* Print out a STRING literal. */
885 pp_c_string_literal (c_pretty_printer
*pp
, tree s
)
887 const char *p
= TREE_STRING_POINTER (s
);
888 int n
= TREE_STRING_LENGTH (s
) - 1;
891 for (i
= 0; i
< n
; ++i
)
892 pp_c_char (pp
, p
[i
]);
896 /* Pretty-print a VOID_CST (void_node). */
899 pp_c_void_constant (c_pretty_printer
*pp
)
901 pp_c_type_cast (pp
, void_type_node
);
905 /* Pretty-print an INTEGER literal. */
908 pp_c_integer_constant (c_pretty_printer
*pp
, tree i
)
912 /* We are going to compare the type of I to other types using
913 pointer comparison so we need to use its canonical type. */
915 TYPE_CANONICAL (TREE_TYPE (i
))
916 ? TYPE_CANONICAL (TREE_TYPE (i
))
919 if (tree_fits_shwi_p (i
))
920 pp_wide_integer (pp
, tree_to_shwi (i
));
921 else if (tree_fits_uhwi_p (i
))
922 pp_unsigned_wide_integer (pp
, tree_to_uhwi (i
));
927 if (wi::lt_p (i
, 0, TYPE_SIGN (TREE_TYPE (i
))))
932 print_hex (wi
, pp_buffer (pp
)->digit_buffer
);
933 pp_string (pp
, pp_buffer (pp
)->digit_buffer
);
935 if (TYPE_UNSIGNED (type
))
936 pp_character (pp
, 'u');
937 if (type
== long_integer_type_node
|| type
== long_unsigned_type_node
)
938 pp_character (pp
, 'l');
939 else if (type
== long_long_integer_type_node
940 || type
== long_long_unsigned_type_node
)
941 pp_string (pp
, "ll");
942 else for (idx
= 0; idx
< NUM_INT_N_ENTS
; idx
++)
943 if (int_n_enabled_p
[idx
])
946 if (type
== int_n_trees
[idx
].signed_type
947 || type
== int_n_trees
[idx
].unsigned_type
)
949 sprintf (buf
, "I%d", int_n_data
[idx
].bitsize
);
955 /* Print out a CHARACTER literal. */
958 pp_c_character_constant (c_pretty_printer
*pp
, tree c
)
961 pp_c_char (pp
, (unsigned) TREE_INT_CST_LOW (c
));
965 /* Print out a BOOLEAN literal. */
968 pp_c_bool_constant (c_pretty_printer
*pp
, tree b
)
970 if (b
== boolean_false_node
)
972 if (c_dialect_cxx ())
973 pp_c_ws_string (pp
, "false");
974 else if (flag_isoc99
)
975 pp_c_ws_string (pp
, "_False");
977 pp_unsupported_tree (pp
, b
);
979 else if (b
== boolean_true_node
)
981 if (c_dialect_cxx ())
982 pp_c_ws_string (pp
, "true");
983 else if (flag_isoc99
)
984 pp_c_ws_string (pp
, "_True");
986 pp_unsupported_tree (pp
, b
);
988 else if (TREE_CODE (b
) == INTEGER_CST
)
989 pp_c_integer_constant (pp
, b
);
991 pp_unsupported_tree (pp
, b
);
994 /* Attempt to print out an ENUMERATOR. Return true on success. Else return
995 false; that means the value was obtained by a cast, in which case
996 print out the type-id part of the cast-expression -- the casted value
997 is then printed by pp_c_integer_literal. */
1000 pp_c_enumeration_constant (c_pretty_printer
*pp
, tree e
)
1002 bool value_is_named
= true;
1003 tree type
= TREE_TYPE (e
);
1006 /* Find the name of this constant. */
1007 for (value
= TYPE_VALUES (type
);
1008 value
!= NULL_TREE
&& !tree_int_cst_equal (TREE_VALUE (value
), e
);
1009 value
= TREE_CHAIN (value
))
1012 if (value
!= NULL_TREE
)
1013 pp
->id_expression (TREE_PURPOSE (value
));
1016 /* Value must have been cast. */
1017 pp_c_type_cast (pp
, type
);
1018 value_is_named
= false;
1021 return value_is_named
;
1024 /* Print out a REAL value as a decimal-floating-constant. */
1027 pp_c_floating_constant (c_pretty_printer
*pp
, tree r
)
1029 const struct real_format
*fmt
1030 = REAL_MODE_FORMAT (TYPE_MODE (TREE_TYPE (r
)));
1032 REAL_VALUE_TYPE floating_cst
= TREE_REAL_CST (r
);
1033 bool is_decimal
= floating_cst
.decimal
;
1035 /* See ISO C++ WG N1822. Note: The fraction 643/2136 approximates
1036 log10(2) to 7 significant digits. */
1037 int max_digits10
= 2 + (is_decimal
? fmt
->p
: fmt
->p
* 643L / 2136);
1039 real_to_decimal (pp_buffer (pp
)->digit_buffer
, &TREE_REAL_CST (r
),
1040 sizeof (pp_buffer (pp
)->digit_buffer
),
1043 pp_string (pp
, pp_buffer(pp
)->digit_buffer
);
1044 if (TREE_TYPE (r
) == float_type_node
)
1045 pp_character (pp
, 'f');
1046 else if (TREE_TYPE (r
) == long_double_type_node
)
1047 pp_character (pp
, 'l');
1048 else if (TREE_TYPE (r
) == dfloat128_type_node
)
1049 pp_string (pp
, "dl");
1050 else if (TREE_TYPE (r
) == dfloat64_type_node
)
1051 pp_string (pp
, "dd");
1052 else if (TREE_TYPE (r
) == dfloat32_type_node
)
1053 pp_string (pp
, "df");
1056 /* Print out a FIXED value as a decimal-floating-constant. */
1059 pp_c_fixed_constant (c_pretty_printer
*pp
, tree r
)
1061 fixed_to_decimal (pp_buffer (pp
)->digit_buffer
, &TREE_FIXED_CST (r
),
1062 sizeof (pp_buffer (pp
)->digit_buffer
));
1063 pp_string (pp
, pp_buffer(pp
)->digit_buffer
);
1066 /* Pretty-print a compound literal expression. GNU extensions include
1067 vector constants. */
1070 pp_c_compound_literal (c_pretty_printer
*pp
, tree e
)
1072 tree type
= TREE_TYPE (e
);
1073 pp_c_type_cast (pp
, type
);
1075 switch (TREE_CODE (type
))
1082 pp_c_brace_enclosed_initializer_list (pp
, e
);
1086 pp_unsupported_tree (pp
, e
);
1091 /* Pretty-print a COMPLEX_EXPR expression. */
1094 pp_c_complex_expr (c_pretty_printer
*pp
, tree e
)
1096 /* Handle a few common special cases, otherwise fallback
1097 to printing it as compound literal. */
1098 tree type
= TREE_TYPE (e
);
1099 tree realexpr
= TREE_OPERAND (e
, 0);
1100 tree imagexpr
= TREE_OPERAND (e
, 1);
1102 /* Cast of an COMPLEX_TYPE expression to a different COMPLEX_TYPE. */
1103 if (TREE_CODE (realexpr
) == NOP_EXPR
1104 && TREE_CODE (imagexpr
) == NOP_EXPR
1105 && TREE_TYPE (realexpr
) == TREE_TYPE (type
)
1106 && TREE_TYPE (imagexpr
) == TREE_TYPE (type
)
1107 && TREE_CODE (TREE_OPERAND (realexpr
, 0)) == REALPART_EXPR
1108 && TREE_CODE (TREE_OPERAND (imagexpr
, 0)) == IMAGPART_EXPR
1109 && TREE_OPERAND (TREE_OPERAND (realexpr
, 0), 0)
1110 == TREE_OPERAND (TREE_OPERAND (imagexpr
, 0), 0))
1112 pp_c_type_cast (pp
, type
);
1113 pp
->expression (TREE_OPERAND (TREE_OPERAND (realexpr
, 0), 0));
1117 /* Cast of an scalar expression to COMPLEX_TYPE. */
1118 if ((integer_zerop (imagexpr
) || real_zerop (imagexpr
))
1119 && TREE_TYPE (realexpr
) == TREE_TYPE (type
))
1121 pp_c_type_cast (pp
, type
);
1122 if (TREE_CODE (realexpr
) == NOP_EXPR
)
1123 realexpr
= TREE_OPERAND (realexpr
, 0);
1124 pp
->expression (realexpr
);
1128 pp_c_compound_literal (pp
, e
);
1134 fixed-point-constant
1135 enumeration-constant
1136 character-constant */
1139 c_pretty_printer::constant (tree e
)
1141 const enum tree_code code
= TREE_CODE (e
);
1146 pp_c_void_constant (this);
1151 tree type
= TREE_TYPE (e
);
1152 if (type
== boolean_type_node
)
1153 pp_c_bool_constant (this, e
);
1154 else if (type
== char_type_node
)
1155 pp_c_character_constant (this, e
);
1156 else if (TREE_CODE (type
) == ENUMERAL_TYPE
1157 && pp_c_enumeration_constant (this, e
))
1160 pp_c_integer_constant (this, e
);
1165 pp_c_floating_constant (this, e
);
1169 pp_c_fixed_constant (this, e
);
1173 pp_c_string_literal (this, e
);
1177 /* Sometimes, we are confused and we think a complex literal
1178 is a constant. Such thing is a compound literal which
1179 grammatically belongs to postfix-expr production. */
1180 pp_c_compound_literal (this, e
);
1184 pp_unsupported_tree (this, e
);
1189 /* Pretty-print a string such as an identifier, without changing its
1190 encoding, preceded by whitespace is necessary. */
1193 pp_c_ws_string (c_pretty_printer
*pp
, const char *str
)
1195 pp_c_maybe_whitespace (pp
);
1196 pp_string (pp
, str
);
1197 pp
->padding
= pp_before
;
1201 c_pretty_printer::translate_string (const char *gmsgid
)
1203 if (pp_translate_identifiers (this))
1204 pp_c_ws_string (this, _(gmsgid
));
1206 pp_c_ws_string (this, gmsgid
);
1209 /* Pretty-print an IDENTIFIER_NODE, which may contain UTF-8 sequences
1210 that need converting to the locale encoding, preceded by whitespace
1214 pp_c_identifier (c_pretty_printer
*pp
, const char *id
)
1216 pp_c_maybe_whitespace (pp
);
1217 pp_identifier (pp
, id
);
1218 pp
->padding
= pp_before
;
1221 /* Pretty-print a C primary-expression.
1229 c_pretty_printer::primary_expression (tree e
)
1231 switch (TREE_CODE (e
))
1239 pp_c_tree_decl_identifier (this, e
);
1242 case IDENTIFIER_NODE
:
1243 pp_c_tree_identifier (this, e
);
1247 translate_string ("<erroneous-expression>");
1251 translate_string ("<return-value>");
1263 pp_c_ws_string (this, "__builtin_memcpy");
1264 pp_c_left_paren (this);
1265 pp_ampersand (this);
1266 primary_expression (TREE_OPERAND (e
, 0));
1267 pp_separate_with (this, ',');
1268 pp_ampersand (this);
1269 initializer (TREE_OPERAND (e
, 1));
1270 if (TREE_OPERAND (e
, 2))
1272 pp_separate_with (this, ',');
1273 expression (TREE_OPERAND (e
, 2));
1275 pp_c_right_paren (this);
1279 /* FIXME: Make sure we won't get into an infinite loop. */
1280 pp_c_left_paren (this);
1282 pp_c_right_paren (this);
1287 /* Print out a C initializer -- also support C compound-literals.
1289 assignment-expression:
1290 { initializer-list }
1291 { initializer-list , } */
1294 c_pretty_printer::initializer (tree e
)
1296 if (TREE_CODE (e
) == CONSTRUCTOR
)
1297 pp_c_brace_enclosed_initializer_list (this, e
);
1304 declarator = initializer */
1307 pp_c_init_declarator (c_pretty_printer
*pp
, tree t
)
1310 /* We don't want to output function definitions here. There are handled
1311 elsewhere (and the syntactic form is bogus anyway). */
1312 if (TREE_CODE (t
) != FUNCTION_DECL
&& DECL_INITIAL (t
))
1314 tree init
= DECL_INITIAL (t
);
1315 /* This C++ bit is handled here because it is easier to do so.
1316 In templates, the C++ parser builds a TREE_LIST for a
1317 direct-initialization; the TREE_PURPOSE is the variable to
1318 initialize and the TREE_VALUE is the initializer. */
1319 if (TREE_CODE (init
) == TREE_LIST
)
1321 pp_c_left_paren (pp
);
1322 pp
->expression (TREE_VALUE (init
));
1323 pp_right_paren (pp
);
1330 pp
->initializer (init
);
1335 /* initializer-list:
1336 designation(opt) initializer
1337 initializer-list , designation(opt) initializer
1344 designator-list designator
1347 [ constant-expression ]
1351 pp_c_initializer_list (c_pretty_printer
*pp
, tree e
)
1353 tree type
= TREE_TYPE (e
);
1354 const enum tree_code code
= TREE_CODE (type
);
1356 if (TREE_CODE (e
) == CONSTRUCTOR
)
1358 pp_c_constructor_elts (pp
, CONSTRUCTOR_ELTS (e
));
1368 tree init
= TREE_OPERAND (e
, 0);
1369 for (; init
!= NULL_TREE
; init
= TREE_CHAIN (init
))
1371 if (code
== RECORD_TYPE
|| code
== UNION_TYPE
)
1374 pp
->primary_expression (TREE_PURPOSE (init
));
1378 pp_c_left_bracket (pp
);
1379 if (TREE_PURPOSE (init
))
1380 pp
->constant (TREE_PURPOSE (init
));
1381 pp_c_right_bracket (pp
);
1383 pp_c_whitespace (pp
);
1385 pp_c_whitespace (pp
);
1386 pp
->initializer (TREE_VALUE (init
));
1387 if (TREE_CHAIN (init
))
1388 pp_separate_with (pp
, ',');
1394 if (TREE_CODE (e
) == VECTOR_CST
)
1397 for (i
= 0; i
< VECTOR_CST_NELTS (e
); ++i
)
1400 pp_separate_with (pp
, ',');
1401 pp
->expression (VECTOR_CST_ELT (e
, i
));
1409 if (TREE_CODE (e
) == COMPLEX_CST
|| TREE_CODE (e
) == COMPLEX_EXPR
)
1411 const bool cst
= TREE_CODE (e
) == COMPLEX_CST
;
1412 pp
->expression (cst
? TREE_REALPART (e
) : TREE_OPERAND (e
, 0));
1413 pp_separate_with (pp
, ',');
1414 pp
->expression (cst
? TREE_IMAGPART (e
) : TREE_OPERAND (e
, 1));
1424 pp_unsupported_tree (pp
, type
);
1427 /* Pretty-print a brace-enclosed initializer-list. */
1430 pp_c_brace_enclosed_initializer_list (c_pretty_printer
*pp
, tree l
)
1432 pp_c_left_brace (pp
);
1433 pp_c_initializer_list (pp
, l
);
1434 pp_c_right_brace (pp
);
1438 /* This is a convenient function, used to bridge gap between C and C++
1445 c_pretty_printer::id_expression (tree t
)
1447 switch (TREE_CODE (t
))
1456 pp_c_tree_decl_identifier (this, t
);
1459 case IDENTIFIER_NODE
:
1460 pp_c_tree_identifier (this, t
);
1464 pp_unsupported_tree (this, t
);
1469 /* postfix-expression:
1471 postfix-expression [ expression ]
1472 postfix-expression ( argument-expression-list(opt) )
1473 postfix-expression . identifier
1474 postfix-expression -> identifier
1475 postfix-expression ++
1476 postfix-expression --
1477 ( type-name ) { initializer-list }
1478 ( type-name ) { initializer-list , } */
1481 c_pretty_printer::postfix_expression (tree e
)
1483 enum tree_code code
= TREE_CODE (e
);
1486 case POSTINCREMENT_EXPR
:
1487 case POSTDECREMENT_EXPR
:
1488 postfix_expression (TREE_OPERAND (e
, 0));
1489 pp_string (this, code
== POSTINCREMENT_EXPR
? "++" : "--");
1493 postfix_expression (TREE_OPERAND (e
, 0));
1494 pp_c_left_bracket (this);
1495 expression (TREE_OPERAND (e
, 1));
1496 pp_c_right_bracket (this);
1499 case ARRAY_NOTATION_REF
:
1500 postfix_expression (ARRAY_NOTATION_ARRAY (e
));
1501 pp_c_left_bracket (this);
1502 expression (ARRAY_NOTATION_START (e
));
1504 expression (ARRAY_NOTATION_LENGTH (e
));
1506 expression (ARRAY_NOTATION_STRIDE (e
));
1507 pp_c_right_bracket (this);
1512 call_expr_arg_iterator iter
;
1514 postfix_expression (CALL_EXPR_FN (e
));
1515 pp_c_left_paren (this);
1516 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, e
)
1519 if (more_call_expr_args_p (&iter
))
1520 pp_separate_with (this, ',');
1522 pp_c_right_paren (this);
1526 case UNORDERED_EXPR
:
1527 pp_c_ws_string (this, flag_isoc99
1529 : "__builtin_isunordered");
1533 pp_c_ws_string (this, flag_isoc99
1535 : "!__builtin_isunordered");
1539 pp_c_ws_string (this, flag_isoc99
1541 : "!__builtin_isgreaterequal");
1545 pp_c_ws_string (this, flag_isoc99
1547 : "!__builtin_isgreater");
1551 pp_c_ws_string (this, flag_isoc99
1553 : "!__builtin_islessequal");
1557 pp_c_ws_string (this, flag_isoc99
1559 : "!__builtin_isless");
1563 pp_c_ws_string (this, flag_isoc99
1565 : "!__builtin_islessgreater");
1569 pp_c_ws_string (this, flag_isoc99
1571 : "__builtin_islessgreater");
1575 pp_c_left_paren (this);
1576 expression (TREE_OPERAND (e
, 0));
1577 pp_separate_with (this, ',');
1578 expression (TREE_OPERAND (e
, 1));
1579 pp_c_right_paren (this);
1583 pp_c_ws_string (this, "__builtin_abs");
1584 pp_c_left_paren (this);
1585 expression (TREE_OPERAND (e
, 0));
1586 pp_c_right_paren (this);
1591 tree object
= TREE_OPERAND (e
, 0);
1592 if (INDIRECT_REF_P (object
))
1594 postfix_expression (TREE_OPERAND (object
, 0));
1599 postfix_expression (object
);
1602 expression (TREE_OPERAND (e
, 1));
1608 tree type
= TREE_TYPE (e
);
1610 type
= signed_or_unsigned_type_for (TYPE_UNSIGNED (type
), type
);
1612 && tree_int_cst_equal (TYPE_SIZE (type
), TREE_OPERAND (e
, 1)))
1614 HOST_WIDE_INT bitpos
= tree_to_shwi (TREE_OPERAND (e
, 2));
1615 HOST_WIDE_INT size
= tree_to_shwi (TYPE_SIZE (type
));
1616 if ((bitpos
% size
) == 0)
1618 pp_c_left_paren (this);
1619 pp_c_left_paren (this);
1622 pp_c_right_paren (this);
1623 pp_c_ampersand (this);
1624 expression (TREE_OPERAND (e
, 0));
1625 pp_c_right_paren (this);
1626 pp_c_left_bracket (this);
1627 pp_wide_integer (this, bitpos
/ size
);
1628 pp_c_right_bracket (this);
1632 pp_unsupported_tree (this, e
);
1642 pp_c_compound_literal (this, e
);
1646 pp_c_complex_expr (this, e
);
1649 case COMPOUND_LITERAL_EXPR
:
1650 e
= DECL_INITIAL (COMPOUND_LITERAL_EXPR_DECL (e
));
1657 pp_c_ws_string (this, "__builtin_va_arg");
1658 pp_c_left_paren (this);
1659 assignment_expression (TREE_OPERAND (e
, 0));
1660 pp_separate_with (this, ',');
1661 type_id (TREE_TYPE (e
));
1662 pp_c_right_paren (this);
1666 if (TREE_CODE (TREE_OPERAND (e
, 0)) == FUNCTION_DECL
)
1668 id_expression (TREE_OPERAND (e
, 0));
1671 /* else fall through. */
1674 primary_expression (e
);
1679 /* Print out an expression-list; E is expected to be a TREE_LIST. */
1682 pp_c_expression_list (c_pretty_printer
*pp
, tree e
)
1684 for (; e
!= NULL_TREE
; e
= TREE_CHAIN (e
))
1686 pp
->expression (TREE_VALUE (e
));
1688 pp_separate_with (pp
, ',');
1692 /* Print out V, which contains the elements of a constructor. */
1695 pp_c_constructor_elts (c_pretty_printer
*pp
, vec
<constructor_elt
, va_gc
> *v
)
1697 unsigned HOST_WIDE_INT ix
;
1700 FOR_EACH_CONSTRUCTOR_VALUE (v
, ix
, value
)
1702 pp
->expression (value
);
1703 if (ix
!= vec_safe_length (v
) - 1)
1704 pp_separate_with (pp
, ',');
1708 /* Print out an expression-list in parens, as if it were the argument
1709 list to a function. */
1712 pp_c_call_argument_list (c_pretty_printer
*pp
, tree t
)
1714 pp_c_left_paren (pp
);
1715 if (t
&& TREE_CODE (t
) == TREE_LIST
)
1716 pp_c_expression_list (pp
, t
);
1717 pp_c_right_paren (pp
);
1720 /* unary-expression:
1724 unary-operator cast-expression
1725 sizeof unary-expression
1728 unary-operator: one of
1733 __alignof__ unary-expression
1734 __alignof__ ( type-id )
1735 __real__ unary-expression
1736 __imag__ unary-expression */
1739 c_pretty_printer::unary_expression (tree e
)
1741 enum tree_code code
= TREE_CODE (e
);
1744 case PREINCREMENT_EXPR
:
1745 case PREDECREMENT_EXPR
:
1746 pp_string (this, code
== PREINCREMENT_EXPR
? "++" : "--");
1747 unary_expression (TREE_OPERAND (e
, 0));
1754 case TRUTH_NOT_EXPR
:
1756 /* String literal are used by address. */
1757 if (code
== ADDR_EXPR
&& TREE_CODE (TREE_OPERAND (e
, 0)) != STRING_CST
)
1758 pp_ampersand (this);
1759 else if (code
== INDIRECT_REF
)
1761 tree type
= TREE_TYPE (TREE_OPERAND (e
, 0));
1762 if (type
&& TREE_CODE (type
) == REFERENCE_TYPE
)
1763 /* Reference decay is implicit, don't print anything. */;
1767 else if (code
== NEGATE_EXPR
)
1769 else if (code
== BIT_NOT_EXPR
|| code
== CONJ_EXPR
)
1770 pp_complement (this);
1771 else if (code
== TRUTH_NOT_EXPR
)
1772 pp_exclamation (this);
1773 pp_c_cast_expression (this, TREE_OPERAND (e
, 0));
1777 if (TREE_CODE (TREE_OPERAND (e
, 0)) == ADDR_EXPR
1778 && integer_zerop (TREE_OPERAND (e
, 1)))
1779 expression (TREE_OPERAND (TREE_OPERAND (e
, 0), 0));
1783 if (!integer_zerop (TREE_OPERAND (e
, 1)))
1785 pp_c_left_paren (this);
1786 if (!integer_onep (TYPE_SIZE_UNIT
1787 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (e
, 0))))))
1788 pp_c_type_cast (this, ptr_type_node
);
1790 pp_c_cast_expression (this, TREE_OPERAND (e
, 0));
1791 if (!integer_zerop (TREE_OPERAND (e
, 1)))
1794 pp_c_integer_constant (this,
1795 fold_convert (ssizetype
,
1796 TREE_OPERAND (e
, 1)));
1797 pp_c_right_paren (this);
1804 pp_c_ws_string (this, code
== REALPART_EXPR
? "__real__" : "__imag__");
1805 pp_c_whitespace (this);
1806 unary_expression (TREE_OPERAND (e
, 0));
1810 postfix_expression (e
);
1817 ( type-name ) cast-expression */
1820 pp_c_cast_expression (c_pretty_printer
*pp
, tree e
)
1822 switch (TREE_CODE (e
))
1825 case FIX_TRUNC_EXPR
:
1827 case VIEW_CONVERT_EXPR
:
1828 pp_c_type_cast (pp
, TREE_TYPE (e
));
1829 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 0));
1833 pp
->unary_expression (e
);
1837 /* multiplicative-expression:
1839 multiplicative-expression * cast-expression
1840 multiplicative-expression / cast-expression
1841 multiplicative-expression % cast-expression */
1844 c_pretty_printer::multiplicative_expression (tree e
)
1846 enum tree_code code
= TREE_CODE (e
);
1850 case TRUNC_DIV_EXPR
:
1851 case TRUNC_MOD_EXPR
:
1852 multiplicative_expression (TREE_OPERAND (e
, 0));
1853 pp_c_whitespace (this);
1854 if (code
== MULT_EXPR
)
1856 else if (code
== TRUNC_DIV_EXPR
)
1860 pp_c_whitespace (this);
1861 pp_c_cast_expression (this, TREE_OPERAND (e
, 1));
1865 pp_c_cast_expression (this, e
);
1870 /* additive-expression:
1871 multiplicative-expression
1872 additive-expression + multiplicative-expression
1873 additive-expression - multiplicative-expression */
1876 pp_c_additive_expression (c_pretty_printer
*pp
, tree e
)
1878 enum tree_code code
= TREE_CODE (e
);
1881 case POINTER_PLUS_EXPR
:
1884 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 0));
1885 pp_c_whitespace (pp
);
1886 if (code
== PLUS_EXPR
|| code
== POINTER_PLUS_EXPR
)
1890 pp_c_whitespace (pp
);
1891 pp
->multiplicative_expression (TREE_OPERAND (e
, 1));
1895 pp
->multiplicative_expression (e
);
1900 /* additive-expression:
1902 shift-expression << additive-expression
1903 shift-expression >> additive-expression */
1906 pp_c_shift_expression (c_pretty_printer
*pp
, tree e
)
1908 enum tree_code code
= TREE_CODE (e
);
1913 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 0));
1914 pp_c_whitespace (pp
);
1915 pp_string (pp
, code
== LSHIFT_EXPR
? "<<" : ">>");
1916 pp_c_whitespace (pp
);
1917 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 1));
1921 pp_c_additive_expression (pp
, e
);
1925 /* relational-expression:
1927 relational-expression < shift-expression
1928 relational-expression > shift-expression
1929 relational-expression <= shift-expression
1930 relational-expression >= shift-expression */
1933 pp_c_relational_expression (c_pretty_printer
*pp
, tree e
)
1935 enum tree_code code
= TREE_CODE (e
);
1942 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 0));
1943 pp_c_whitespace (pp
);
1944 if (code
== LT_EXPR
)
1946 else if (code
== GT_EXPR
)
1948 else if (code
== LE_EXPR
)
1950 else if (code
== GE_EXPR
)
1951 pp_greater_equal (pp
);
1952 pp_c_whitespace (pp
);
1953 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 1));
1957 pp_c_shift_expression (pp
, e
);
1962 /* equality-expression:
1963 relational-expression
1964 equality-expression == relational-expression
1965 equality-equality != relational-expression */
1968 pp_c_equality_expression (c_pretty_printer
*pp
, tree e
)
1970 enum tree_code code
= TREE_CODE (e
);
1975 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 0));
1976 pp_c_whitespace (pp
);
1977 pp_string (pp
, code
== EQ_EXPR
? "==" : "!=");
1978 pp_c_whitespace (pp
);
1979 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 1));
1983 pp_c_relational_expression (pp
, e
);
1990 AND-expression & equality-equality */
1993 pp_c_and_expression (c_pretty_printer
*pp
, tree e
)
1995 if (TREE_CODE (e
) == BIT_AND_EXPR
)
1997 pp_c_and_expression (pp
, TREE_OPERAND (e
, 0));
1998 pp_c_whitespace (pp
);
2000 pp_c_whitespace (pp
);
2001 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 1));
2004 pp_c_equality_expression (pp
, e
);
2007 /* exclusive-OR-expression:
2009 exclusive-OR-expression ^ AND-expression */
2012 pp_c_exclusive_or_expression (c_pretty_printer
*pp
, tree e
)
2014 if (TREE_CODE (e
) == BIT_XOR_EXPR
2015 || TREE_CODE (e
) == TRUTH_XOR_EXPR
)
2017 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
2018 if (TREE_CODE (e
) == BIT_XOR_EXPR
)
2019 pp_c_maybe_whitespace (pp
);
2021 pp_c_whitespace (pp
);
2023 pp_c_whitespace (pp
);
2024 pp_c_and_expression (pp
, TREE_OPERAND (e
, 1));
2027 pp_c_and_expression (pp
, e
);
2030 /* inclusive-OR-expression:
2031 exclusive-OR-expression
2032 inclusive-OR-expression | exclusive-OR-expression */
2035 pp_c_inclusive_or_expression (c_pretty_printer
*pp
, tree e
)
2037 if (TREE_CODE (e
) == BIT_IOR_EXPR
)
2039 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
2040 pp_c_whitespace (pp
);
2042 pp_c_whitespace (pp
);
2043 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
2046 pp_c_exclusive_or_expression (pp
, e
);
2049 /* logical-AND-expression:
2050 inclusive-OR-expression
2051 logical-AND-expression && inclusive-OR-expression */
2054 pp_c_logical_and_expression (c_pretty_printer
*pp
, tree e
)
2056 if (TREE_CODE (e
) == TRUTH_ANDIF_EXPR
2057 || TREE_CODE (e
) == TRUTH_AND_EXPR
)
2059 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 0));
2060 pp_c_whitespace (pp
);
2061 pp_ampersand_ampersand (pp
);
2062 pp_c_whitespace (pp
);
2063 pp_c_inclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
2066 pp_c_inclusive_or_expression (pp
, e
);
2069 /* logical-OR-expression:
2070 logical-AND-expression
2071 logical-OR-expression || logical-AND-expression */
2074 pp_c_logical_or_expression (c_pretty_printer
*pp
, tree e
)
2076 if (TREE_CODE (e
) == TRUTH_ORIF_EXPR
2077 || TREE_CODE (e
) == TRUTH_OR_EXPR
)
2079 pp_c_logical_or_expression (pp
, TREE_OPERAND (e
, 0));
2080 pp_c_whitespace (pp
);
2082 pp_c_whitespace (pp
);
2083 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 1));
2086 pp_c_logical_and_expression (pp
, e
);
2089 /* conditional-expression:
2090 logical-OR-expression
2091 logical-OR-expression ? expression : conditional-expression */
2094 c_pretty_printer::conditional_expression (tree e
)
2096 if (TREE_CODE (e
) == COND_EXPR
)
2098 pp_c_logical_or_expression (this, TREE_OPERAND (e
, 0));
2099 pp_c_whitespace (this);
2101 pp_c_whitespace (this);
2102 expression (TREE_OPERAND (e
, 1));
2103 pp_c_whitespace (this);
2105 pp_c_whitespace (this);
2106 conditional_expression (TREE_OPERAND (e
, 2));
2109 pp_c_logical_or_expression (this, e
);
2113 /* assignment-expression:
2114 conditional-expression
2115 unary-expression assignment-operator assignment-expression
2117 assignment-expression: one of
2118 = *= /= %= += -= >>= <<= &= ^= |= */
2121 c_pretty_printer::assignment_expression (tree e
)
2123 if (TREE_CODE (e
) == MODIFY_EXPR
2124 || TREE_CODE (e
) == INIT_EXPR
)
2126 unary_expression (TREE_OPERAND (e
, 0));
2127 pp_c_whitespace (this);
2130 expression (TREE_OPERAND (e
, 1));
2133 conditional_expression (e
);
2137 assignment-expression
2138 expression , assignment-expression
2140 Implementation note: instead of going through the usual recursion
2141 chain, I take the liberty of dispatching nodes to the appropriate
2142 functions. This makes some redundancy, but it worths it. That also
2143 prevents a possible infinite recursion between primary_expression ()
2144 and expression (). */
2147 c_pretty_printer::expression (tree e
)
2149 switch (TREE_CODE (e
))
2152 pp_c_void_constant (this);
2156 pp_c_integer_constant (this, e
);
2160 pp_c_floating_constant (this, e
);
2164 pp_c_fixed_constant (this, e
);
2168 pp_c_string_literal (this, e
);
2171 case IDENTIFIER_NODE
:
2180 primary_expression (e
);
2184 if (SSA_NAME_VAR (e
)
2185 && !DECL_ARTIFICIAL (SSA_NAME_VAR (e
)))
2186 expression (SSA_NAME_VAR (e
));
2188 translate_string ("<unknown>");
2191 case POSTINCREMENT_EXPR
:
2192 case POSTDECREMENT_EXPR
:
2194 case ARRAY_NOTATION_REF
:
2202 case UNORDERED_EXPR
:
2211 case COMPOUND_LITERAL_EXPR
:
2213 postfix_expression (e
);
2222 case TRUTH_NOT_EXPR
:
2223 case PREINCREMENT_EXPR
:
2224 case PREDECREMENT_EXPR
:
2227 unary_expression (e
);
2231 case FIX_TRUNC_EXPR
:
2233 case VIEW_CONVERT_EXPR
:
2234 pp_c_cast_expression (this, e
);
2238 case TRUNC_MOD_EXPR
:
2239 case TRUNC_DIV_EXPR
:
2240 multiplicative_expression (e
);
2245 pp_c_shift_expression (this, e
);
2252 pp_c_relational_expression (this, e
);
2256 pp_c_and_expression (this, e
);
2260 case TRUTH_XOR_EXPR
:
2261 pp_c_exclusive_or_expression (this, e
);
2265 pp_c_inclusive_or_expression (this, e
);
2268 case TRUTH_ANDIF_EXPR
:
2269 case TRUTH_AND_EXPR
:
2270 pp_c_logical_and_expression (this, e
);
2273 case TRUTH_ORIF_EXPR
:
2275 pp_c_logical_or_expression (this, e
);
2280 pp_c_equality_expression (this, e
);
2284 conditional_expression (e
);
2287 case POINTER_PLUS_EXPR
:
2290 pp_c_additive_expression (this, e
);
2295 assignment_expression (e
);
2299 pp_c_left_paren (this);
2300 expression (TREE_OPERAND (e
, 0));
2301 pp_separate_with (this, ',');
2302 assignment_expression (TREE_OPERAND (e
, 1));
2303 pp_c_right_paren (this);
2306 case NON_LVALUE_EXPR
:
2308 expression (TREE_OPERAND (e
, 0));
2312 postfix_expression (TREE_OPERAND (e
, 1));
2317 /* We don't yet have a way of dumping statements in a
2318 human-readable format. */
2319 pp_string (this, "({...})");
2322 case C_MAYBE_CONST_EXPR
:
2323 expression (C_MAYBE_CONST_EXPR_EXPR (e
));
2327 pp_unsupported_tree (this, e
);
2337 c_pretty_printer::statement (tree stmt
)
2342 if (pp_needs_newline (this))
2343 pp_newline_and_indent (this, 0);
2345 dump_generic_node (this, stmt
, pp_indentation (this), 0, true);
2349 /* Initialize the PRETTY-PRINTER for handling C codes. */
2351 c_pretty_printer::c_pretty_printer ()
2352 : pretty_printer (),
2356 type_specifier_seq
= pp_c_specifier_qualifier_list
;
2357 ptr_operator
= pp_c_pointer
;
2358 parameter_list
= pp_c_parameter_type_list
;
2362 /* Print the tree T in full, on file FILE. */
2365 print_c_tree (FILE *file
, tree t
)
2367 c_pretty_printer pp
;
2369 pp_needs_newline (&pp
) = true;
2370 pp
.buffer
->stream
= file
;
2372 pp_newline_and_flush (&pp
);
2375 /* Print the tree T in full, on stderr. */
2378 debug_c_tree (tree t
)
2380 print_c_tree (stderr
, t
);
2381 fputc ('\n', stderr
);
2384 /* Output the DECL_NAME of T. If T has no DECL_NAME, output a string made
2385 up of T's memory address. */
2388 pp_c_tree_decl_identifier (c_pretty_printer
*pp
, tree t
)
2392 gcc_assert (DECL_P (t
));
2395 name
= IDENTIFIER_POINTER (DECL_NAME (t
));
2398 static char xname
[8];
2399 sprintf (xname
, "<U%4x>", ((unsigned)((uintptr_t)(t
) & 0xffff)));
2403 pp_c_identifier (pp
, name
);