1 /* Subroutines common to both C and C++ pretty-printers.
2 Copyright (C) 2002, 2003, 2004, 2005 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 2, 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 COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 #include "coretypes.h"
27 #include "c-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_base (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_multiplicative_expression (c_pretty_printer
*, tree
);
54 static void pp_c_additive_expression (c_pretty_printer
*, tree
);
55 static void pp_c_shift_expression (c_pretty_printer
*, tree
);
56 static void pp_c_relational_expression (c_pretty_printer
*, tree
);
57 static void pp_c_equality_expression (c_pretty_printer
*, tree
);
58 static void pp_c_and_expression (c_pretty_printer
*, tree
);
59 static void pp_c_exclusive_or_expression (c_pretty_printer
*, tree
);
60 static void pp_c_inclusive_or_expression (c_pretty_printer
*, tree
);
61 static void pp_c_logical_and_expression (c_pretty_printer
*, tree
);
62 static void pp_c_conditional_expression (c_pretty_printer
*, tree
);
63 static void pp_c_assignment_expression (c_pretty_printer
*, tree
);
68 /* Helper functions. */
71 pp_c_whitespace (c_pretty_printer
*pp
)
74 pp_base (pp
)->padding
= pp_none
;
78 pp_c_left_paren (c_pretty_printer
*pp
)
81 pp_base (pp
)->padding
= pp_none
;
85 pp_c_right_paren (c_pretty_printer
*pp
)
88 pp_base (pp
)->padding
= pp_none
;
92 pp_c_left_brace (c_pretty_printer
*pp
)
95 pp_base (pp
)->padding
= pp_none
;
99 pp_c_right_brace (c_pretty_printer
*pp
)
102 pp_base (pp
)->padding
= pp_none
;
106 pp_c_left_bracket (c_pretty_printer
*pp
)
108 pp_left_bracket (pp
);
109 pp_base (pp
)->padding
= pp_none
;
113 pp_c_right_bracket (c_pretty_printer
*pp
)
115 pp_right_bracket (pp
);
116 pp_base (pp
)->padding
= pp_none
;
120 pp_c_dot (c_pretty_printer
*pp
)
123 pp_base (pp
)->padding
= pp_none
;
127 pp_c_ampersand (c_pretty_printer
*pp
)
130 pp_base (pp
)->padding
= pp_none
;
134 pp_c_star (c_pretty_printer
*pp
)
137 pp_base (pp
)->padding
= pp_none
;
141 pp_c_arrow (c_pretty_printer
*pp
)
144 pp_base (pp
)->padding
= pp_none
;
148 pp_c_semicolon (c_pretty_printer
*pp
)
151 pp_base (pp
)->padding
= pp_none
;
155 pp_c_complement (c_pretty_printer
*pp
)
158 pp_base (pp
)->padding
= pp_none
;
162 pp_c_exclamation (c_pretty_printer
*pp
)
165 pp_base (pp
)->padding
= pp_none
;
168 /* Print out the external representation of CV-QUALIFIER. */
171 pp_c_cv_qualifier (c_pretty_printer
*pp
, const char *cv
)
173 const char *p
= pp_last_position_in_text (pp
);
174 /* The C programming language does not have references, but it is much
175 simpler to handle those here rather than going through the same
176 logic in the C++ pretty-printer. */
177 if (p
!= NULL
&& (*p
== '*' || *p
== '&'))
178 pp_c_whitespace (pp
);
179 pp_c_identifier (pp
, cv
);
182 /* Pretty-print T using the type-cast notation '( type-name )'. */
185 pp_c_type_cast (c_pretty_printer
*pp
, tree t
)
187 pp_c_left_paren (pp
);
189 pp_c_right_paren (pp
);
192 /* We're about to pretty-print a pointer type as indicated by T.
193 Output a whitespace, if needed, preparing for subsequent output. */
196 pp_c_space_for_pointer_operator (c_pretty_printer
*pp
, tree t
)
198 if (POINTER_TYPE_P (t
))
200 tree pointee
= strip_pointer_operator (TREE_TYPE (t
));
201 if (TREE_CODE (pointee
) != ARRAY_TYPE
202 && TREE_CODE (pointee
) != FUNCTION_TYPE
)
203 pp_c_whitespace (pp
);
210 /* C++ cv-qualifiers are called type-qualifiers in C. Print out the
211 cv-qualifiers of T. If T is a declaration then it is the cv-qualifier
212 of its type. Take care of possible extensions.
216 type-qualifier-list type-qualifier
221 __restrict__ -- GNU C
225 pp_c_type_qualifier_list (c_pretty_printer
*pp
, tree t
)
232 qualifiers
= TYPE_QUALS (t
);
233 if (qualifiers
& TYPE_QUAL_CONST
)
234 pp_c_cv_qualifier (pp
, "const");
235 if (qualifiers
& TYPE_QUAL_VOLATILE
)
236 pp_c_cv_qualifier (pp
, "volatile");
237 if (qualifiers
& TYPE_QUAL_RESTRICT
)
238 pp_c_cv_qualifier (pp
, flag_isoc99
? "restrict" : "__restrict__");
242 * type-qualifier-list(opt)
243 * type-qualifier-list(opt) pointer */
246 pp_c_pointer (c_pretty_printer
*pp
, tree t
)
248 if (!TYPE_P (t
) && TREE_CODE (t
) != TYPE_DECL
)
250 switch (TREE_CODE (t
))
253 /* It is easier to handle C++ reference types here. */
255 if (TREE_CODE (TREE_TYPE (t
)) == POINTER_TYPE
)
256 pp_c_pointer (pp
, TREE_TYPE (t
));
257 if (TREE_CODE (t
) == POINTER_TYPE
)
261 pp_c_type_qualifier_list (pp
, t
);
264 /* ??? This node is now in GENERIC and so shouldn't be here. But
265 we'll fix that later. */
267 pp_declaration (pp
, DECL_EXPR_DECL (t
));
268 pp_needs_newline (pp
) = true;
272 pp_unsupported_tree (pp
, t
);
289 struct-or-union-specifier
294 simple-type-specifier:
299 pp_c_type_specifier (c_pretty_printer
*pp
, tree t
)
301 const enum tree_code code
= TREE_CODE (t
);
305 pp_c_identifier (pp
, "<type-error>");
308 case IDENTIFIER_NODE
:
309 pp_c_tree_decl_identifier (pp
, t
);
320 pp_c_type_specifier (pp
, t
);
324 int prec
= TYPE_PRECISION (t
);
325 t
= c_common_type_for_mode (TYPE_MODE (t
), TYPE_UNSIGNED (t
));
328 pp_c_type_specifier (pp
, t
);
329 if (TYPE_PRECISION (t
) != prec
)
332 pp_decimal_int (pp
, prec
);
340 pp_string (pp
, (TYPE_UNSIGNED (t
)
341 ? "<unnamed-unsigned:"
342 : "<unnamed-signed:"));
345 pp_string (pp
, "<unnamed-float:");
350 pp_decimal_int (pp
, prec
);
358 pp_id_expression (pp
, t
);
360 pp_c_identifier (pp
, "<typedef-error>");
366 if (code
== UNION_TYPE
)
367 pp_c_identifier (pp
, "union");
368 else if (code
== RECORD_TYPE
)
369 pp_c_identifier (pp
, "struct");
370 else if (code
== ENUMERAL_TYPE
)
371 pp_c_identifier (pp
, "enum");
373 pp_c_identifier (pp
, "<tag-error>");
376 pp_id_expression (pp
, TYPE_NAME (t
));
378 pp_c_identifier (pp
, "<anonymous>");
382 pp_unsupported_tree (pp
, t
);
387 /* specifier-qualifier-list:
388 type-specifier specifier-qualifier-list-opt
389 type-qualifier specifier-qualifier-list-opt
392 Implementation note: Because of the non-linearities in array or
393 function declarations, this routine prints not just the
394 specifier-qualifier-list of such entities or types of such entities,
395 but also the 'pointer' production part of their declarators. The
396 remaining part is done by pp_declarator or pp_c_abstract_declarator. */
399 pp_c_specifier_qualifier_list (c_pretty_printer
*pp
, tree t
)
401 const enum tree_code code
= TREE_CODE (t
);
403 if (TREE_CODE (t
) != POINTER_TYPE
)
404 pp_c_type_qualifier_list (pp
, t
);
410 /* Get the types-specifier of this type. */
411 tree pointee
= strip_pointer_operator (TREE_TYPE (t
));
412 pp_c_specifier_qualifier_list (pp
, pointee
);
413 if (TREE_CODE (pointee
) == ARRAY_TYPE
414 || TREE_CODE (pointee
) == FUNCTION_TYPE
)
416 pp_c_whitespace (pp
);
417 pp_c_left_paren (pp
);
419 else if (!c_dialect_cxx ())
420 pp_c_whitespace (pp
);
421 pp_ptr_operator (pp
, t
);
427 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
432 pp_c_specifier_qualifier_list (pp
, TREE_TYPE (t
));
433 if (code
== COMPLEX_TYPE
)
434 pp_c_identifier (pp
, flag_isoc99
? "_Complex" : "__complex__");
435 else if (code
== VECTOR_TYPE
)
436 pp_c_identifier (pp
, "__vector__");
440 pp_simple_type_specifier (pp
, t
);
445 /* parameter-type-list:
450 parameter-declaration
451 parameter-list , parameter-declaration
453 parameter-declaration:
454 declaration-specifiers declarator
455 declaration-specifiers abstract-declarator(opt) */
458 pp_c_parameter_type_list (c_pretty_printer
*pp
, tree t
)
460 bool want_parm_decl
= DECL_P (t
) && !(pp
->flags
& pp_c_flag_abstract
);
461 tree parms
= want_parm_decl
? DECL_ARGUMENTS (t
) : TYPE_ARG_TYPES (t
);
462 pp_c_left_paren (pp
);
463 if (parms
== void_list_node
)
464 pp_c_identifier (pp
, "void");
468 for ( ; parms
&& parms
!= void_list_node
; parms
= TREE_CHAIN (parms
))
471 pp_separate_with (pp
, ',');
473 pp_declaration_specifiers
474 (pp
, want_parm_decl
? parms
: TREE_VALUE (parms
));
476 pp_declarator (pp
, parms
);
478 pp_abstract_declarator (pp
, TREE_VALUE (parms
));
481 pp_c_right_paren (pp
);
484 /* abstract-declarator:
486 pointer(opt) direct-abstract-declarator */
489 pp_c_abstract_declarator (c_pretty_printer
*pp
, tree t
)
491 if (TREE_CODE (t
) == POINTER_TYPE
)
493 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
494 || TREE_CODE (TREE_TYPE (t
)) == FUNCTION_TYPE
)
495 pp_c_right_paren (pp
);
499 pp_direct_abstract_declarator (pp
, t
);
502 /* direct-abstract-declarator:
503 ( abstract-declarator )
504 direct-abstract-declarator(opt) [ assignment-expression(opt) ]
505 direct-abstract-declarator(opt) [ * ]
506 direct-abstract-declarator(opt) ( parameter-type-list(opt) ) */
509 pp_c_direct_abstract_declarator (c_pretty_printer
*pp
, tree t
)
511 switch (TREE_CODE (t
))
514 pp_abstract_declarator (pp
, t
);
518 pp_c_parameter_type_list (pp
, t
);
519 pp_direct_abstract_declarator (pp
, TREE_TYPE (t
));
523 pp_c_left_bracket (pp
);
524 if (TYPE_DOMAIN (t
) && TYPE_MAX_VALUE (TYPE_DOMAIN (t
)))
525 pp_expression (pp
, TYPE_MAX_VALUE (TYPE_DOMAIN (t
)));
526 pp_c_right_bracket (pp
);
527 pp_direct_abstract_declarator (pp
, TREE_TYPE (t
));
530 case IDENTIFIER_NODE
:
544 pp_unsupported_tree (pp
, t
);
550 specifier-qualifier-list abstract-declarator(opt) */
553 pp_c_type_id (c_pretty_printer
*pp
, tree t
)
555 pp_c_specifier_qualifier_list (pp
, t
);
556 pp_abstract_declarator (pp
, t
);
559 /* storage-class-specifier:
567 pp_c_storage_class_specifier (c_pretty_printer
*pp
, tree t
)
569 if (TREE_CODE (t
) == TYPE_DECL
)
570 pp_c_identifier (pp
, "typedef");
573 if (DECL_REGISTER (t
))
574 pp_c_identifier (pp
, "register");
575 else if (TREE_STATIC (t
) && TREE_CODE (t
) == VAR_DECL
)
576 pp_c_identifier (pp
, "static");
580 /* function-specifier:
584 pp_c_function_specifier (c_pretty_printer
*pp
, tree t
)
586 if (TREE_CODE (t
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (t
))
587 pp_c_identifier (pp
, "inline");
590 /* declaration-specifiers:
591 storage-class-specifier declaration-specifiers(opt)
592 type-specifier declaration-specifiers(opt)
593 type-qualifier declaration-specifiers(opt)
594 function-specifier declaration-specifiers(opt) */
597 pp_c_declaration_specifiers (c_pretty_printer
*pp
, tree t
)
599 pp_storage_class_specifier (pp
, t
);
600 pp_function_specifier (pp
, t
);
601 pp_c_specifier_qualifier_list (pp
, DECL_P (t
) ? TREE_TYPE (t
) : t
);
607 direct-declarator [ type-qualifier-list(opt) assignment-expression(opt) ]
608 direct-declarator [ static type-qualifier-list(opt) assignment-expression(opt)]
609 direct-declarator [ type-qualifier-list static assignment-expression ]
610 direct-declarator [ type-qualifier-list * ]
611 direct-declarator ( parameter-type-list )
612 direct-declarator ( identifier-list(opt) ) */
615 pp_c_direct_declarator (c_pretty_printer
*pp
, tree t
)
617 switch (TREE_CODE (t
))
624 pp_c_space_for_pointer_operator (pp
, TREE_TYPE (t
));
625 pp_c_tree_decl_identifier (pp
, t
);
630 pp_abstract_declarator (pp
, TREE_TYPE (t
));
634 pp_parameter_list (pp
, t
);
635 pp_abstract_declarator (pp
, TREE_TYPE (t
));
639 pp_c_space_for_pointer_operator (pp
, TREE_TYPE (TREE_TYPE (t
)));
640 pp_c_tree_decl_identifier (pp
, t
);
641 if (pp_c_base (pp
)->flags
& pp_c_flag_abstract
)
642 pp_abstract_declarator (pp
, TREE_TYPE (t
));
645 pp_parameter_list (pp
, t
);
646 pp_abstract_declarator (pp
, TREE_TYPE (TREE_TYPE (t
)));
658 pp_unsupported_tree (pp
, t
);
665 pointer(opt) direct-declarator */
668 pp_c_declarator (c_pretty_printer
*pp
, tree t
)
670 switch (TREE_CODE (t
))
686 pp_direct_declarator (pp
, t
);
691 pp_unsupported_tree (pp
, t
);
697 declaration-specifiers init-declarator-list(opt) ; */
700 pp_c_declaration (c_pretty_printer
*pp
, tree t
)
702 pp_declaration_specifiers (pp
, t
);
703 pp_c_init_declarator (pp
, t
);
706 /* Pretty-print ATTRIBUTES using GNU C extension syntax. */
709 pp_c_attributes (c_pretty_printer
*pp
, tree attributes
)
711 if (attributes
== NULL_TREE
)
714 pp_c_identifier (pp
, "__attribute__");
715 pp_c_left_paren (pp
);
716 pp_c_left_paren (pp
);
717 for (; attributes
!= NULL_TREE
; attributes
= TREE_CHAIN (attributes
))
719 pp_tree_identifier (pp
, TREE_PURPOSE (attributes
));
720 if (TREE_VALUE (attributes
))
721 pp_c_call_argument_list (pp
, TREE_VALUE (attributes
));
723 if (TREE_CHAIN (attributes
))
724 pp_separate_with (pp
, ',');
726 pp_c_right_paren (pp
);
727 pp_c_right_paren (pp
);
730 /* function-definition:
731 declaration-specifiers declarator compound-statement */
734 pp_c_function_definition (c_pretty_printer
*pp
, tree t
)
736 pp_declaration_specifiers (pp
, t
);
737 pp_declarator (pp
, t
);
738 pp_needs_newline (pp
) = true;
739 pp_statement (pp
, DECL_SAVED_TREE (t
));
747 /* Print out a c-char. This is called solely for characters which are
748 in the *target* execution character set. We ought to convert them
749 back to the *host* execution character set before printing, but we
750 have no way to do this at present. A decent compromise is to print
751 all characters as if they were in the host execution character set,
752 and not attempt to recover any named escape characters, but render
753 all unprintables as octal escapes. If the host and target character
754 sets are the same, this produces relatively readable output. If they
755 are not the same, strings may appear as gibberish, but that's okay
756 (in fact, it may well be what the reader wants, e.g. if they are looking
757 to see if conversion to the target character set happened correctly).
759 A special case: we need to prefix \, ", and ' with backslashes. It is
760 correct to do so for the *host*'s \, ", and ', because the rest of the
761 file appears in the host character set. */
764 pp_c_char (c_pretty_printer
*pp
, int c
)
770 case '\\': pp_string (pp
, "\\\\"); break;
771 case '\'': pp_string (pp
, "\\\'"); break;
772 case '\"': pp_string (pp
, "\\\""); break;
773 default: pp_character (pp
, c
);
777 pp_scalar (pp
, "\\%03o", (unsigned) c
);
780 /* Print out a STRING literal. */
783 pp_c_string_literal (c_pretty_printer
*pp
, tree s
)
785 const char *p
= TREE_STRING_POINTER (s
);
786 int n
= TREE_STRING_LENGTH (s
) - 1;
789 for (i
= 0; i
< n
; ++i
)
790 pp_c_char (pp
, p
[i
]);
794 /* Pretty-print an INTEGER literal. */
797 pp_c_integer_constant (c_pretty_printer
*pp
, tree i
)
799 tree type
= TREE_TYPE (i
);
801 if (TREE_INT_CST_HIGH (i
) == 0)
802 pp_wide_integer (pp
, TREE_INT_CST_LOW (i
));
805 if (tree_int_cst_sgn (i
) < 0)
807 pp_character (pp
, '-');
808 i
= build_int_cst_wide (NULL_TREE
,
809 -TREE_INT_CST_LOW (i
),
810 ~TREE_INT_CST_HIGH (i
)
811 + !TREE_INT_CST_LOW (i
));
813 sprintf (pp_buffer (pp
)->digit_buffer
,
814 HOST_WIDE_INT_PRINT_DOUBLE_HEX
,
815 TREE_INT_CST_HIGH (i
), TREE_INT_CST_LOW (i
));
816 pp_string (pp
, pp_buffer (pp
)->digit_buffer
);
818 if (TYPE_UNSIGNED (type
))
819 pp_character (pp
, 'u');
820 if (type
== long_integer_type_node
|| type
== long_unsigned_type_node
)
821 pp_character (pp
, 'l');
822 else if (type
== long_long_integer_type_node
823 || type
== long_long_unsigned_type_node
)
824 pp_string (pp
, "ll");
827 /* Print out a CHARACTER literal. */
830 pp_c_character_constant (c_pretty_printer
*pp
, tree c
)
832 tree type
= TREE_TYPE (c
);
833 if (type
== wchar_type_node
)
834 pp_character (pp
, 'L');
836 if (host_integerp (c
, TYPE_UNSIGNED (type
)))
837 pp_c_char (pp
, tree_low_cst (c
, TYPE_UNSIGNED (type
)));
839 pp_scalar (pp
, "\\x%x", (unsigned) TREE_INT_CST_LOW (c
));
843 /* Print out a BOOLEAN literal. */
846 pp_c_bool_constant (c_pretty_printer
*pp
, tree b
)
848 if (b
== boolean_false_node
)
850 if (c_dialect_cxx ())
851 pp_c_identifier (pp
, "false");
852 else if (flag_isoc99
)
853 pp_c_identifier (pp
, "_False");
855 pp_unsupported_tree (pp
, b
);
857 else if (b
== boolean_true_node
)
859 if (c_dialect_cxx ())
860 pp_c_identifier (pp
, "true");
861 else if (flag_isoc99
)
862 pp_c_identifier (pp
, "_True");
864 pp_unsupported_tree (pp
, b
);
866 else if (TREE_CODE (b
) == INTEGER_CST
)
867 pp_c_integer_constant (pp
, b
);
869 pp_unsupported_tree (pp
, b
);
872 /* Attempt to print out an ENUMERATOR. Return true on success. Else return
873 false; that means the value was obtained by a cast, in which case
874 print out the type-id part of the cast-expression -- the casted value
875 is then printed by pp_c_integer_literal. */
878 pp_c_enumeration_constant (c_pretty_printer
*pp
, tree e
)
880 bool value_is_named
= true;
881 tree type
= TREE_TYPE (e
);
884 /* Find the name of this constant. */
885 for (value
= TYPE_VALUES (type
);
886 value
!= NULL_TREE
&& !tree_int_cst_equal (TREE_VALUE (value
), e
);
887 value
= TREE_CHAIN (value
))
890 if (value
!= NULL_TREE
)
891 pp_id_expression (pp
, TREE_PURPOSE (value
));
894 /* Value must have been cast. */
895 pp_c_type_cast (pp
, type
);
896 value_is_named
= false;
899 return value_is_named
;
902 /* Print out a REAL value as a decimal-floating-constant. */
905 pp_c_floating_constant (c_pretty_printer
*pp
, tree r
)
907 real_to_decimal (pp_buffer (pp
)->digit_buffer
, &TREE_REAL_CST (r
),
908 sizeof (pp_buffer (pp
)->digit_buffer
), 0, 1);
909 pp_string (pp
, pp_buffer(pp
)->digit_buffer
);
910 if (TREE_TYPE (r
) == float_type_node
)
911 pp_character (pp
, 'f');
912 else if (TREE_TYPE (r
) == long_double_type_node
)
913 pp_character (pp
, 'l');
916 /* Pretty-print a compound literal expression. GNU extensions include
920 pp_c_compound_literal (c_pretty_printer
*pp
, tree e
)
922 tree type
= TREE_TYPE (e
);
923 pp_c_type_cast (pp
, type
);
925 switch (TREE_CODE (type
))
932 pp_c_brace_enclosed_initializer_list (pp
, e
);
936 pp_unsupported_tree (pp
, e
);
945 character-constant */
948 pp_c_constant (c_pretty_printer
*pp
, tree e
)
950 const enum tree_code code
= TREE_CODE (e
);
956 tree type
= TREE_TYPE (e
);
957 if (type
== boolean_type_node
)
958 pp_c_bool_constant (pp
, e
);
959 else if (type
== char_type_node
)
960 pp_c_character_constant (pp
, e
);
961 else if (TREE_CODE (type
) == ENUMERAL_TYPE
962 && pp_c_enumeration_constant (pp
, e
))
965 pp_c_integer_constant (pp
, e
);
970 pp_c_floating_constant (pp
, e
);
974 pp_c_string_literal (pp
, e
);
978 pp_unsupported_tree (pp
, e
);
983 /* Pretty-print an IDENTIFIER_NODE, preceded by whitespace is necessary. */
986 pp_c_identifier (c_pretty_printer
*pp
, const char *id
)
988 pp_c_maybe_whitespace (pp
);
989 pp_identifier (pp
, id
);
990 pp_base (pp
)->padding
= pp_before
;
993 /* Pretty-print a C primary-expression.
1001 pp_c_primary_expression (c_pretty_printer
*pp
, tree e
)
1003 switch (TREE_CODE (e
))
1011 pp_c_tree_decl_identifier (pp
, e
);
1014 case IDENTIFIER_NODE
:
1015 pp_c_tree_identifier (pp
, e
);
1019 pp_c_identifier (pp
, "<erroneous-expression>");
1023 pp_c_identifier (pp
, "<return-value>");
1029 pp_c_constant (pp
, e
);
1033 pp_c_identifier (pp
, "__builtin_memcpy");
1034 pp_c_left_paren (pp
);
1036 pp_primary_expression (pp
, TREE_OPERAND (e
, 0));
1037 pp_separate_with (pp
, ',');
1039 pp_initializer (pp
, TREE_OPERAND (e
, 1));
1040 if (TREE_OPERAND (e
, 2))
1042 pp_separate_with (pp
, ',');
1043 pp_c_expression (pp
, TREE_OPERAND (e
, 2));
1045 pp_c_right_paren (pp
);
1049 pp_c_left_paren (pp
);
1050 pp_statement (pp
, STMT_EXPR_STMT (e
));
1051 pp_c_right_paren (pp
);
1055 /* FIXME: Make sure we won't get into an infinie loop. */
1056 pp_c_left_paren (pp
);
1057 pp_expression (pp
, e
);
1058 pp_c_right_paren (pp
);
1063 /* Print out a C initializer -- also support C compound-literals.
1065 assignment-expression:
1066 { initializer-list }
1067 { initializer-list , } */
1070 pp_c_initializer (c_pretty_printer
*pp
, tree e
)
1072 if (TREE_CODE (e
) == CONSTRUCTOR
)
1073 pp_c_brace_enclosed_initializer_list (pp
, e
);
1075 pp_expression (pp
, e
);
1080 declarator = initializer */
1083 pp_c_init_declarator (c_pretty_printer
*pp
, tree t
)
1085 pp_declarator (pp
, t
);
1086 /* We don't want to output function definitions here. There are handled
1087 elsewhere (and the syntactic form is bogus anyway). */
1088 if (TREE_CODE (t
) != FUNCTION_DECL
&& DECL_INITIAL (t
))
1090 tree init
= DECL_INITIAL (t
);
1091 /* This C++ bit is handled here because it is easier to do so.
1092 In templates, the C++ parser builds a TREE_LIST for a
1093 direct-initialization; the TREE_PURPOSE is the variable to
1094 initialize and the TREE_VALUE is the initializer. */
1095 if (TREE_CODE (init
) == TREE_LIST
)
1097 pp_c_left_paren (pp
);
1098 pp_expression (pp
, TREE_VALUE (init
));
1099 pp_right_paren (pp
);
1106 pp_c_initializer (pp
, init
);
1111 /* initializer-list:
1112 designation(opt) initializer
1113 initializer-list , designation(opt) initializer
1120 designator-list designator
1123 [ constant-expression ]
1127 pp_c_initializer_list (c_pretty_printer
*pp
, tree e
)
1129 tree type
= TREE_TYPE (e
);
1130 const enum tree_code code
= TREE_CODE (type
);
1138 tree init
= TREE_OPERAND (e
, 0);
1139 for (; init
!= NULL_TREE
; init
= TREE_CHAIN (init
))
1141 if (code
== RECORD_TYPE
|| code
== UNION_TYPE
)
1144 pp_c_primary_expression (pp
, TREE_PURPOSE (init
));
1148 pp_c_left_bracket (pp
);
1149 if (TREE_PURPOSE (init
))
1150 pp_c_constant (pp
, TREE_PURPOSE (init
));
1151 pp_c_right_bracket (pp
);
1153 pp_c_whitespace (pp
);
1155 pp_c_whitespace (pp
);
1156 pp_initializer (pp
, TREE_VALUE (init
));
1157 if (TREE_CHAIN (init
))
1158 pp_separate_with (pp
, ',');
1164 if (TREE_CODE (e
) == VECTOR_CST
)
1165 pp_c_expression_list (pp
, TREE_VECTOR_CST_ELTS (e
));
1166 else if (TREE_CODE (e
) == CONSTRUCTOR
)
1167 pp_c_expression_list (pp
, CONSTRUCTOR_ELTS (e
));
1173 if (TREE_CODE (e
) == CONSTRUCTOR
)
1174 pp_c_expression_list (pp
, CONSTRUCTOR_ELTS (e
));
1175 else if (TREE_CODE (e
) == COMPLEX_CST
|| TREE_CODE (e
) == COMPLEX_EXPR
)
1177 const bool cst
= TREE_CODE (e
) == COMPLEX_CST
;
1178 pp_expression (pp
, cst
? TREE_REALPART (e
) : TREE_OPERAND (e
, 0));
1179 pp_separate_with (pp
, ',');
1180 pp_expression (pp
, cst
? TREE_IMAGPART (e
) : TREE_OPERAND (e
, 1));
1190 pp_unsupported_tree (pp
, type
);
1193 /* Pretty-print a brace-enclosed initializer-list. */
1196 pp_c_brace_enclosed_initializer_list (c_pretty_printer
*pp
, tree l
)
1198 pp_c_left_brace (pp
);
1199 pp_c_initializer_list (pp
, l
);
1200 pp_c_right_brace (pp
);
1204 /* This is a convenient function, used to bridge gap between C and C++
1211 pp_c_id_expression (c_pretty_printer
*pp
, tree t
)
1213 switch (TREE_CODE (t
))
1222 pp_c_tree_decl_identifier (pp
, t
);
1225 case IDENTIFIER_NODE
:
1226 pp_c_tree_identifier (pp
, t
);
1230 pp_unsupported_tree (pp
, t
);
1235 /* postfix-expression:
1237 postfix-expression [ expression ]
1238 postfix-expression ( argument-expression-list(opt) )
1239 postfix-expression . identifier
1240 postfix-expression -> identifier
1241 postfix-expression ++
1242 postfix-expression --
1243 ( type-name ) { initializer-list }
1244 ( type-name ) { initializer-list , } */
1247 pp_c_postfix_expression (c_pretty_printer
*pp
, tree e
)
1249 enum tree_code code
= TREE_CODE (e
);
1252 case POSTINCREMENT_EXPR
:
1253 case POSTDECREMENT_EXPR
:
1254 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1255 pp_identifier (pp
, code
== POSTINCREMENT_EXPR
? "++" : "--");
1259 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1264 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1265 pp_c_left_bracket (pp
);
1266 pp_expression (pp
, TREE_OPERAND (e
, 1));
1267 pp_c_right_bracket (pp
);
1271 pp_postfix_expression (pp
, TREE_OPERAND (e
, 0));
1272 pp_c_call_argument_list (pp
, TREE_OPERAND (e
, 1));
1275 case UNORDERED_EXPR
:
1276 pp_c_identifier (pp
, flag_isoc99
1278 : "__builtin_isunordered");
1282 pp_c_identifier (pp
, flag_isoc99
1284 : "!__builtin_isunordered");
1288 pp_c_identifier (pp
, flag_isoc99
1290 : "!__builtin_isgreaterequal");
1294 pp_c_identifier (pp
, flag_isoc99
1296 : "!__builtin_isgreater");
1300 pp_c_identifier (pp
, flag_isoc99
1302 : "!__builtin_islessequal");
1306 pp_c_identifier (pp
, flag_isoc99
1308 : "!__builtin_isless");
1312 pp_c_identifier (pp
, flag_isoc99
1314 : "!__builtin_islessgreater");
1318 pp_c_identifier (pp
, flag_isoc99
1320 : "__builtin_islessgreater");
1324 pp_c_left_paren (pp
);
1325 pp_expression (pp
, TREE_OPERAND (e
, 0));
1326 pp_separate_with (pp
, ',');
1327 pp_expression (pp
, TREE_OPERAND (e
, 1));
1328 pp_c_right_paren (pp
);
1332 pp_c_identifier (pp
, "__builtin_abs");
1333 pp_c_left_paren (pp
);
1334 pp_expression (pp
, TREE_OPERAND (e
, 0));
1335 pp_c_right_paren (pp
);
1340 tree object
= TREE_OPERAND (e
, 0);
1341 if (TREE_CODE (object
) == INDIRECT_REF
)
1343 pp_postfix_expression (pp
, TREE_OPERAND (object
, 0));
1348 pp_postfix_expression (pp
, object
);
1351 pp_expression (pp
, TREE_OPERAND (e
, 1));
1358 pp_c_compound_literal (pp
, e
);
1361 case COMPOUND_LITERAL_EXPR
:
1362 e
= DECL_INITIAL (COMPOUND_LITERAL_EXPR_DECL (e
));
1365 pp_initializer (pp
, e
);
1369 pp_c_identifier (pp
, "__builtin_va_arg");
1370 pp_c_left_paren (pp
);
1371 pp_assignment_expression (pp
, TREE_OPERAND (e
, 0));
1372 pp_separate_with (pp
, ',');
1373 pp_type_id (pp
, TREE_TYPE (e
));
1374 pp_c_right_paren (pp
);
1378 if (TREE_CODE (TREE_OPERAND (e
, 0)) == FUNCTION_DECL
)
1380 pp_c_id_expression (pp
, TREE_OPERAND (e
, 0));
1383 /* else fall through. */
1386 pp_primary_expression (pp
, e
);
1391 /* Print out an expression-list; E is expected to be a TREE_LIST. */
1394 pp_c_expression_list (c_pretty_printer
*pp
, tree e
)
1396 for (; e
!= NULL_TREE
; e
= TREE_CHAIN (e
))
1398 pp_expression (pp
, TREE_VALUE (e
));
1400 pp_separate_with (pp
, ',');
1404 /* Print out an expression-list in parens, as in a function call. */
1407 pp_c_call_argument_list (c_pretty_printer
*pp
, tree t
)
1409 pp_c_left_paren (pp
);
1410 if (t
&& TREE_CODE (t
) == TREE_LIST
)
1411 pp_c_expression_list (pp
, t
);
1412 pp_c_right_paren (pp
);
1415 /* unary-expression:
1419 unary-operator cast-expression
1420 sizeof unary-expression
1423 unary-operator: one of
1428 __alignof__ unary-expression
1429 __alignof__ ( type-id )
1430 __real__ unary-expression
1431 __imag__ unary-expression */
1434 pp_c_unary_expression (c_pretty_printer
*pp
, tree e
)
1436 enum tree_code code
= TREE_CODE (e
);
1439 case PREINCREMENT_EXPR
:
1440 case PREDECREMENT_EXPR
:
1441 pp_identifier (pp
, code
== PREINCREMENT_EXPR
? "++" : "--");
1442 pp_c_unary_expression (pp
, TREE_OPERAND (e
, 0));
1449 case TRUTH_NOT_EXPR
:
1451 /* String literal are used by address. */
1452 if (code
== ADDR_EXPR
&& TREE_CODE (TREE_OPERAND (e
, 0)) != STRING_CST
)
1454 else if (code
== INDIRECT_REF
)
1456 else if (code
== NEGATE_EXPR
)
1458 else if (code
== BIT_NOT_EXPR
|| code
== CONJ_EXPR
)
1460 else if (code
== TRUTH_NOT_EXPR
)
1461 pp_exclamation (pp
);
1462 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 0));
1467 pp_c_identifier (pp
, code
== SIZEOF_EXPR
? "sizeof" : "__alignof__");
1468 pp_c_whitespace (pp
);
1469 if (TYPE_P (TREE_OPERAND (e
, 0)))
1470 pp_c_type_cast (pp
, TREE_OPERAND (e
, 0));
1472 pp_unary_expression (pp
, TREE_OPERAND (e
, 0));
1477 pp_c_identifier (pp
, code
== REALPART_EXPR
? "__real__" : "__imag__");
1478 pp_c_whitespace (pp
);
1479 pp_unary_expression (pp
, TREE_OPERAND (e
, 0));
1483 pp_postfix_expression (pp
, e
);
1490 ( type-name ) cast-expression */
1493 pp_c_cast_expression (c_pretty_printer
*pp
, tree e
)
1495 switch (TREE_CODE (e
))
1498 case FIX_TRUNC_EXPR
:
1500 pp_c_type_cast (pp
, TREE_TYPE (e
));
1501 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 0));
1505 pp_unary_expression (pp
, e
);
1509 /* multiplicative-expression:
1511 multiplicative-expression * cast-expression
1512 multiplicative-expression / cast-expression
1513 multiplicative-expression % cast-expression */
1516 pp_c_multiplicative_expression (c_pretty_printer
*pp
, tree e
)
1518 enum tree_code code
= TREE_CODE (e
);
1522 case TRUNC_DIV_EXPR
:
1523 case TRUNC_MOD_EXPR
:
1524 pp_multiplicative_expression (pp
, TREE_OPERAND (e
, 0));
1525 pp_c_whitespace (pp
);
1526 if (code
== MULT_EXPR
)
1528 else if (code
== TRUNC_DIV_EXPR
)
1532 pp_c_whitespace (pp
);
1533 pp_c_cast_expression (pp
, TREE_OPERAND (e
, 1));
1537 pp_c_cast_expression (pp
, e
);
1542 /* additive-expression:
1543 multiplicative-expression
1544 additive-expression + multiplicative-expression
1545 additive-expression - multiplicative-expression */
1548 pp_c_additive_expression (c_pretty_printer
*pp
, tree e
)
1550 enum tree_code code
= TREE_CODE (e
);
1555 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 0));
1556 pp_c_whitespace (pp
);
1557 if (code
== PLUS_EXPR
)
1561 pp_c_whitespace (pp
);
1562 pp_multiplicative_expression (pp
, TREE_OPERAND (e
, 1));
1566 pp_multiplicative_expression (pp
, e
);
1571 /* additive-expression:
1573 shift-expression << additive-expression
1574 shift-expression >> additive-expression */
1577 pp_c_shift_expression (c_pretty_printer
*pp
, tree e
)
1579 enum tree_code code
= TREE_CODE (e
);
1584 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 0));
1585 pp_c_whitespace (pp
);
1586 pp_identifier (pp
, code
== LSHIFT_EXPR
? "<<" : ">>");
1587 pp_c_whitespace (pp
);
1588 pp_c_additive_expression (pp
, TREE_OPERAND (e
, 1));
1592 pp_c_additive_expression (pp
, e
);
1596 /* relational-expression:
1598 relational-expression < shift-expression
1599 relational-expression > shift-expression
1600 relational-expression <= shift-expression
1601 relational-expression >= shift-expression */
1604 pp_c_relational_expression (c_pretty_printer
*pp
, tree e
)
1606 enum tree_code code
= TREE_CODE (e
);
1613 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 0));
1614 pp_c_whitespace (pp
);
1615 if (code
== LT_EXPR
)
1617 else if (code
== GT_EXPR
)
1619 else if (code
== LE_EXPR
)
1620 pp_identifier (pp
, "<=");
1621 else if (code
== GE_EXPR
)
1622 pp_identifier (pp
, ">=");
1623 pp_c_whitespace (pp
);
1624 pp_c_shift_expression (pp
, TREE_OPERAND (e
, 1));
1628 pp_c_shift_expression (pp
, e
);
1633 /* equality-expression:
1634 relational-expression
1635 equality-expression == relational-expression
1636 equality-equality != relational-expression */
1639 pp_c_equality_expression (c_pretty_printer
*pp
, tree e
)
1641 enum tree_code code
= TREE_CODE (e
);
1646 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 0));
1647 pp_c_whitespace (pp
);
1648 pp_identifier (pp
, code
== EQ_EXPR
? "==" : "!=");
1649 pp_c_whitespace (pp
);
1650 pp_c_relational_expression (pp
, TREE_OPERAND (e
, 1));
1654 pp_c_relational_expression (pp
, e
);
1661 AND-expression & equality-equality */
1664 pp_c_and_expression (c_pretty_printer
*pp
, tree e
)
1666 if (TREE_CODE (e
) == BIT_AND_EXPR
)
1668 pp_c_and_expression (pp
, TREE_OPERAND (e
, 0));
1669 pp_c_whitespace (pp
);
1671 pp_c_whitespace (pp
);
1672 pp_c_equality_expression (pp
, TREE_OPERAND (e
, 1));
1675 pp_c_equality_expression (pp
, e
);
1678 /* exclusive-OR-expression:
1680 exclusive-OR-expression ^ AND-expression */
1683 pp_c_exclusive_or_expression (c_pretty_printer
*pp
, tree e
)
1685 if (TREE_CODE (e
) == BIT_XOR_EXPR
)
1687 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
1688 pp_c_maybe_whitespace (pp
);
1690 pp_c_whitespace (pp
);
1691 pp_c_and_expression (pp
, TREE_OPERAND (e
, 1));
1694 pp_c_and_expression (pp
, e
);
1697 /* inclusive-OR-expression:
1698 exclusive-OR-expression
1699 inclusive-OR-expression | exclusive-OR-expression */
1702 pp_c_inclusive_or_expression (c_pretty_printer
*pp
, tree e
)
1704 if (TREE_CODE (e
) == BIT_IOR_EXPR
)
1706 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 0));
1707 pp_c_whitespace (pp
);
1709 pp_c_whitespace (pp
);
1710 pp_c_exclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
1713 pp_c_exclusive_or_expression (pp
, e
);
1716 /* logical-AND-expression:
1717 inclusive-OR-expression
1718 logical-AND-expression && inclusive-OR-expression */
1721 pp_c_logical_and_expression (c_pretty_printer
*pp
, tree e
)
1723 if (TREE_CODE (e
) == TRUTH_ANDIF_EXPR
)
1725 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 0));
1726 pp_c_whitespace (pp
);
1727 pp_identifier (pp
, "&&");
1728 pp_c_whitespace (pp
);
1729 pp_c_inclusive_or_expression (pp
, TREE_OPERAND (e
, 1));
1732 pp_c_inclusive_or_expression (pp
, e
);
1735 /* logical-OR-expression:
1736 logical-AND-expression
1737 logical-OR-expression || logical-AND-expression */
1740 pp_c_logical_or_expression (c_pretty_printer
*pp
, tree e
)
1742 if (TREE_CODE (e
) == TRUTH_ORIF_EXPR
)
1744 pp_c_logical_or_expression (pp
, TREE_OPERAND (e
, 0));
1745 pp_c_whitespace (pp
);
1746 pp_identifier (pp
, "||");
1747 pp_c_whitespace (pp
);
1748 pp_c_logical_and_expression (pp
, TREE_OPERAND (e
, 1));
1751 pp_c_logical_and_expression (pp
, e
);
1754 /* conditional-expression:
1755 logical-OR-expression
1756 logical-OR-expression ? expression : conditional-expression */
1759 pp_c_conditional_expression (c_pretty_printer
*pp
, tree e
)
1761 if (TREE_CODE (e
) == COND_EXPR
)
1763 pp_c_logical_or_expression (pp
, TREE_OPERAND (e
, 0));
1764 pp_c_whitespace (pp
);
1766 pp_c_whitespace (pp
);
1767 pp_expression (pp
, TREE_OPERAND (e
, 1));
1768 pp_c_whitespace (pp
);
1770 pp_c_whitespace (pp
);
1771 pp_c_conditional_expression (pp
, TREE_OPERAND (e
, 2));
1774 pp_c_logical_or_expression (pp
, e
);
1778 /* assignment-expression:
1779 conditional-expression
1780 unary-expression assignment-operator assignment-expression
1782 assignment-expression: one of
1783 = *= /= %= += -= >>= <<= &= ^= |= */
1786 pp_c_assignment_expression (c_pretty_printer
*pp
, tree e
)
1788 if (TREE_CODE (e
) == MODIFY_EXPR
|| TREE_CODE (e
) == INIT_EXPR
)
1790 pp_c_unary_expression (pp
, TREE_OPERAND (e
, 0));
1791 pp_c_whitespace (pp
);
1794 pp_c_expression (pp
, TREE_OPERAND (e
, 1));
1797 pp_c_conditional_expression (pp
, e
);
1801 assignment-expression
1802 expression , assignment-expression
1804 Implementation note: instead of going through the usual recursion
1805 chain, I take the liberty of dispatching nodes to the appropriate
1806 functions. This makes some redundancy, but it worths it. That also
1807 prevents a possible infinite recursion between pp_c_primary_expression ()
1808 and pp_c_expression (). */
1811 pp_c_expression (c_pretty_printer
*pp
, tree e
)
1813 switch (TREE_CODE (e
))
1816 pp_c_integer_constant (pp
, e
);
1820 pp_c_floating_constant (pp
, e
);
1824 pp_c_string_literal (pp
, e
);
1827 case IDENTIFIER_NODE
:
1837 pp_primary_expression (pp
, e
);
1840 case POSTINCREMENT_EXPR
:
1841 case POSTDECREMENT_EXPR
:
1850 case UNORDERED_EXPR
:
1859 case COMPOUND_LITERAL_EXPR
:
1861 pp_postfix_expression (pp
, e
);
1869 case TRUTH_NOT_EXPR
:
1870 case PREINCREMENT_EXPR
:
1871 case PREDECREMENT_EXPR
:
1876 pp_c_unary_expression (pp
, e
);
1880 case FIX_TRUNC_EXPR
:
1882 pp_c_cast_expression (pp
, e
);
1886 case TRUNC_MOD_EXPR
:
1887 case TRUNC_DIV_EXPR
:
1888 pp_multiplicative_expression (pp
, e
);
1893 pp_c_shift_expression (pp
, e
);
1900 pp_c_relational_expression (pp
, e
);
1904 pp_c_and_expression (pp
, e
);
1908 pp_c_exclusive_or_expression (pp
, e
);
1912 pp_c_inclusive_or_expression (pp
, e
);
1915 case TRUTH_ANDIF_EXPR
:
1916 pp_c_logical_and_expression (pp
, e
);
1919 case TRUTH_ORIF_EXPR
:
1920 pp_c_logical_or_expression (pp
, e
);
1925 pp_c_equality_expression (pp
, e
);
1929 pp_conditional_expression (pp
, e
);
1934 pp_c_additive_expression (pp
, e
);
1939 pp_assignment_expression (pp
, e
);
1943 pp_c_left_paren (pp
);
1944 pp_expression (pp
, TREE_OPERAND (e
, 0));
1945 pp_separate_with (pp
, ',');
1946 pp_assignment_expression (pp
, TREE_OPERAND (e
, 1));
1947 pp_c_right_paren (pp
);
1951 case NON_LVALUE_EXPR
:
1953 pp_expression (pp
, TREE_OPERAND (e
, 0));
1957 pp_postfix_expression (pp
, TREE_OPERAND (e
, 1));
1961 pp_unsupported_tree (pp
, e
);
1973 expression-statement
1979 pp_c_statement (c_pretty_printer
*pp
, tree stmt
)
1981 enum tree_code code
;
1986 if (pp_needs_newline (pp
))
1987 pp_newline_and_indent (pp
, 0);
1989 code
= TREE_CODE (stmt
);
1992 /* expression-statement:
1993 expression(opt) ; */
1995 pp_expression (pp
, EXPR_STMT_EXPR (stmt
));
1996 pp_c_semicolon (pp
);
1997 pp_needs_newline (pp
) = true;
2001 pp_c_identifier (pp
, "switch");
2003 pp_c_left_paren (pp
);
2004 pp_expression (pp
, SWITCH_COND (stmt
));
2005 pp_c_right_paren (pp
);
2006 pp_indentation (pp
) += 3;
2007 pp_needs_newline (pp
) = true;
2008 pp_statement (pp
, SWITCH_BODY (stmt
));
2009 pp_newline_and_indent (pp
, -3);
2012 /* iteration-statement:
2013 while ( expression ) statement
2014 do statement while ( expression ) ;
2015 for ( expression(opt) ; expression(opt) ; expression(opt) ) statement
2016 for ( declaration expression(opt) ; expression(opt) ) statement */
2018 pp_c_identifier (pp
, "while");
2020 pp_c_left_paren (pp
);
2021 pp_expression (pp
, WHILE_COND (stmt
));
2022 pp_c_right_paren (pp
);
2023 pp_newline_and_indent (pp
, 3);
2024 pp_statement (pp
, WHILE_BODY (stmt
));
2025 pp_indentation (pp
) -= 3;
2026 pp_needs_newline (pp
) = true;
2030 pp_c_identifier (pp
, "do");
2031 pp_newline_and_indent (pp
, 3);
2032 pp_statement (pp
, DO_BODY (stmt
));
2033 pp_newline_and_indent (pp
, -3);
2034 pp_c_identifier (pp
, "while");
2036 pp_c_left_paren (pp
);
2037 pp_expression (pp
, DO_COND (stmt
));
2038 pp_c_right_paren (pp
);
2039 pp_c_semicolon (pp
);
2040 pp_needs_newline (pp
) = true;
2044 pp_c_identifier (pp
, "for");
2046 pp_c_left_paren (pp
);
2047 if (FOR_INIT_STMT (stmt
))
2048 pp_statement (pp
, FOR_INIT_STMT (stmt
));
2050 pp_c_semicolon (pp
);
2051 pp_needs_newline (pp
) = false;
2052 pp_c_whitespace (pp
);
2053 if (FOR_COND (stmt
))
2054 pp_expression (pp
, FOR_COND (stmt
));
2055 pp_c_semicolon (pp
);
2056 pp_needs_newline (pp
) = false;
2057 pp_c_whitespace (pp
);
2058 if (FOR_EXPR (stmt
))
2059 pp_expression (pp
, FOR_EXPR (stmt
));
2060 pp_c_right_paren (pp
);
2061 pp_newline_and_indent (pp
, 3);
2062 pp_statement (pp
, FOR_BODY (stmt
));
2063 pp_indentation (pp
) -= 3;
2064 pp_needs_newline (pp
) = true;
2070 return expression(opt) ; */
2073 pp_identifier (pp
, code
== BREAK_STMT
? "break" : "continue");
2074 pp_c_semicolon (pp
);
2075 pp_needs_newline (pp
) = true;
2079 dump_generic_node (pp_base (pp
), stmt
, pp_indentation (pp
), 0, true);
2085 /* Initialize the PRETTY-PRINTER for handling C codes. */
2088 pp_c_pretty_printer_init (c_pretty_printer
*pp
)
2090 pp
->offset_list
= 0;
2092 pp
->declaration
= pp_c_declaration
;
2093 pp
->declaration_specifiers
= pp_c_declaration_specifiers
;
2094 pp
->declarator
= pp_c_declarator
;
2095 pp
->direct_declarator
= pp_c_direct_declarator
;
2096 pp
->type_specifier_seq
= pp_c_specifier_qualifier_list
;
2097 pp
->abstract_declarator
= pp_c_abstract_declarator
;
2098 pp
->direct_abstract_declarator
= pp_c_direct_abstract_declarator
;
2099 pp
->ptr_operator
= pp_c_pointer
;
2100 pp
->parameter_list
= pp_c_parameter_type_list
;
2101 pp
->type_id
= pp_c_type_id
;
2102 pp
->simple_type_specifier
= pp_c_type_specifier
;
2103 pp
->function_specifier
= pp_c_function_specifier
;
2104 pp
->storage_class_specifier
= pp_c_storage_class_specifier
;
2106 pp
->statement
= pp_c_statement
;
2108 pp
->id_expression
= pp_c_id_expression
;
2109 pp
->primary_expression
= pp_c_primary_expression
;
2110 pp
->postfix_expression
= pp_c_postfix_expression
;
2111 pp
->unary_expression
= pp_c_unary_expression
;
2112 pp
->initializer
= pp_c_initializer
;
2113 pp
->multiplicative_expression
= pp_c_multiplicative_expression
;
2114 pp
->conditional_expression
= pp_c_conditional_expression
;
2115 pp
->assignment_expression
= pp_c_assignment_expression
;
2116 pp
->expression
= pp_c_expression
;
2120 /* Print the tree T in full, on file FILE. */
2123 print_c_tree (FILE *file
, tree t
)
2125 static c_pretty_printer pp_rec
;
2126 static bool initialized
= 0;
2127 c_pretty_printer
*pp
= &pp_rec
;
2132 pp_construct (pp_base (pp
), NULL
, 0);
2133 pp_c_pretty_printer_init (pp
);
2134 pp_needs_newline (pp
) = true;
2136 pp_base (pp
)->buffer
->stream
= file
;
2138 pp_statement (pp
, t
);
2144 /* Print the tree T in full, on stderr. */
2147 debug_c_tree (tree t
)
2149 print_c_tree (stderr
, t
);
2150 fputc ('\n', stderr
);
2153 /* Output the DECL_NAME of T. If T has no DECL_NAME, output a string made
2154 up of T's memory address. */
2157 pp_c_tree_decl_identifier (c_pretty_printer
*pp
, tree t
)
2161 gcc_assert (DECL_P (t
));
2164 name
= IDENTIFIER_POINTER (DECL_NAME (t
));
2167 static char xname
[8];
2168 sprintf (xname
, "<U%4x>", ((unsigned)((unsigned long)(t
) & 0xffff)));
2172 pp_c_identifier (pp
, name
);